akhauriyash/Code-Regression huggingface dataset:
# -*- coding: utf-8 -*-

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
from fractions import gcd
from functools import lru_cache

#############
# Constants #
#############

MOD = 10**9 +7
INF = float('inf')

#############
# Functions #
#############

######INPUT######
def inputI(): return int(input().strip())
def inputS(): return input().strip()
def inputIL(): return list(map(int,input().split()))
def inputSL(): return list(map(str,input().split()))
def inputILs(n): return list(int(input()) for _ in range(n))
def inputSLs(n): return list(input().strip() for _ in range(n))
def inputILL(n): return [list(map(int, input().split())) for _ in range(n)]
def inputSLL(n): return [list(map(str, input().split())) for _ in range(n)]

#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])
    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])
    return arr

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

#############
# Main Code #
#############

T,S = inputSL()
print(S+T)

Measured memory_bytes: 64492
/**********************************************************************************************
******************************AUTHOR:**********************************************************
****************************ASHISH RANJAN******************************************************
***********************************************************************************************/
#include<iostream>
#include<algorithm>
#include<cmath>
#include<chrono>
#include<vector>
#include<string>
#include<cstring>
using namespace std;
using namespace std::chrono;
/*
auto start = high_resolution_clock::now();
auto stop = high_resolution_clock::now();
  auto duration = duration_cast<microseconds>(stop - start); 
  
    cout << "Time taken by function: "
         << duration.count() << " microseconds" << endl;
*/
#define fast() ios_base::sync_with_stdio(false);cin.tie(NULL)
#define ll long long
#define mod 1000000007
#define fr(i,n) for(int i=0;i<(int)n;i++)
#define frs(i,a,b) for(int i = a;i<b;i++)
#define meme(a,b,c) memset(a,b,sizeof(c)); //works only for 0 and -1
int main(){
  fast();
  ll x,k,d;
  cin>>x>>k>>d;
 if(x<0)x = -x;
  if(k<=x/d){cout<<x-(k*d);}
  else {k-=x/d;
    if(k%2==0)cout<<x%d;
       else cout<<d - (x%d);
       }
 return 0;
  
}




Measured memory_bytes: 3608
#include <iostream>
#include <vector>
#include <unordered_map>
#include <map>
#include <algorithm>
#include <set>
#include <unordered_set>
#include <deque>
#include <cmath>
#include <stack>
#include <queue>
#include <string>
#include <locale>
#include <iomanip>

#define nl '\n';

using namespace std;

int a, b, x;

int main(){

    cin >> a >> b;

    x = max(a*b, a-b);
    x = max(x, a+b);

    cout << x;




}

//g++ -std=c++14 comp.cpp -o b; ./b.exe
//g++ -std=c++14 comp.cpp && ./a.out

// char** arr = new char*[r];
// for(long long i = 0; i < r; i++) arr[i] = new char[c];

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N(111);
int a[N], vst[N], cnt[N];
int main() {
	int n;
	scanf("%d", &n);
	for(int i(0); i < n; i++) {
		scanf("%d", &a[i]);
	}
	sort(a, a + n);
	bool flag(true);
	if(a[n - 1] != a[n - 2] || n >= 3 && a[n - 1] == 1) {
		flag = false;
	}
	int d(a[n - 1]);
	for(int i(0); i < n; i++) {
		cnt[a[i]]++;
	}
	if(d % 2 == 0 && cnt[d / 2] >= 2 || d % 2 == 1 && cnt[(d + 1) / 2] >= 3) {
		flag = false;
	}
	for(int i(1); i < d; i++) {
		cnt[max(i, d - i)]--;
	}
	for(int i(1); i < d; i++) {
		if(cnt[max(i, d - i)] < 0) {
			flag = false;
		}
	}
	cout << (flag ? "Possible" : "Impossible") << endl;
}


Measured memory_bytes: 384
#ifdef __LOCAL
  #define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>
using namespace std;
template<typename T> bool chmax(T &a,T b) {if(a<b) {a=b; return true;} return false;}
template<typename T> bool chmin(T &a,T b) {if(a>b) {a=b; return true;} return false;}
#define itn int
#define fi first
#define se second
#define intmax numeric_limits<int>::max()
#define llmax numeric_limits<ll>::max()
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(int)(n);i>=1;i--)
#define all(vec) vec.begin(),vec.end()
#define sortt(vec) sort((vec).begin(),(vec).end())
#define rsort(vec) sort((vec).rbegin(), (vec).rend())
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef tuple<ll,ll,ll> tlll;
typedef tuple<int,int,int> tiii;
const ll mod=1e9+7;
const int inf=1<<30;
const ll lnf=1ll<<60;

ll dp[61][2000010];

int main(){
  itn n; ll k; cin >> n >> k;
  rep(j,n){
    cin >> dp[0][j];
    dp[0][j]--;
  }
  rep(i,60)rep(j,n) dp[i+1][j]=dp[i][dp[i][j]];
  itn v=0;
  for(itn i=60;i>=0;i--){
    if((1ll<<i)<=k){
      v=dp[i][v];
      k-=1ll<<i;
    }
  }
  cout << v+1 << endl;
  
}

Measured memory_bytes: 99164
#include <iostream>
#include <string>
using namespace std;
 
int main()
{
  int n;
  cin >> n;
 
  int a[4] = {};
  for (int i=0; i<n; ++i){
    string s;
    cin >> s;
    if (s == "AC") a[0]++;
    if (s == "WA") a[1]++;
    if (s == "TLE") a[2]++;
    if (s == "RE") a[3]++;
  }

  cout << "AC x " << a[0] << endl;
  cout << "WA x " << a[1] << endl;
  cout << "TLE x " << a[2] << endl;
  cout << "RE x " << a[3] << endl;
  
  return 0;
}


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

#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define MAX 100050

#define ll long long
#define ld long double
#define lli long long int

#define pb emplace_back
#define INF 1000000000000

#define mod 1000000007

// trignometric function always give value in Radians only
#define PI acos(-1) //3.1415926535897932384626433832795028
#define dsin(degree) sin(degree*(PI/180.0))
#define dcos(degree) cos(degree*(PI/180.0))
#define dtan(degree) tan(degree*(PI/180.0))

#define rsin(radian) sin(radian)
#define rcos(radian) cos(radian)
#define rtan(radian) tan(radian)

#define loop(i,n) for (lli i = 0; i < n; i++)
#define loopitr(xt,vec) for (auto xt : vec)
#define FOR(i,a,b) for (lli i = a; i < b; i+=1)
#define loop_rev(i,n) for (lli i = n-1; i >= 0; i--)
#define FOR_REV(i,a,b) for (lli i = a; i >= b; i--)
#define itr :: iterator it
#define WL(t) while(t --)

#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define sz(x) int(x.size())
#define F first
#define S second

#define mii map<lli,lli>
#define vi vector<lli>
#define vbool vector<bool>
#define seti set<lli>
#define pii pair<lli,lli>
#define pcc pair<char , char>

#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) (a/gcd(a,b))*b
#define abs(x) ((x < 0)?-(x):x)

#define endl '\n'

template <typename T>
void print(T x){cout<<x<<endl;}
template <typename T1, typename T2>
void print2(T1 x,T2 y){cout<<x<<" "<<y<<endl;}
template <typename T1, typename T2,typename T3>
void print3(T1 x, T2 y,T3 z){cout<<x<<" "<<y<<" "<<z<<endl;}

#define scanarr(a,n) for(lli i=0;i<n;i++)    cin>>a[i];
#define scanvector(a,n) for(lli i=0;i<n;i++){ lli x ; cin>>x; a.pb(x);}

#define printarr(a,n) for(lli i=0;i<n;i++)   cout<<a[i]<<" "; cout<<endl;
#define printvector(vec) for(auto xt : vec) cout<<xt<<" ";    cout<<"\n";

#define FD(N) fixed<<setprecision(N)

#define deb(x) cout<<#x<<" "<<x<<endl;



int main(){
	fastio
	lli N,X,T;
	cin>>N>>X>>T;
	lli t=0;
	while(N>0){
		t=t+T;
		N=N-X;
	}
	cout<<t;
	return 0;
}

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

int main(){
  int A, B;
  cin >> A >> B;
  
  int result;
  
  result =  A - B * 2;
  
  if(result < 0) {
    cout << 0 << endl;
  } else {
    cout << result << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
#define yn {puts("Yes");}else{puts("No");}
#define MAX_N 200005

ll mod_pow(ll x, ll n, ll mod){ // x ^ n % mod
    ll res = 1;
    while(n > 0){
        if (n & 1) res = res * x % mod;
        x = x * x % mod;
        n >>= 1;
    }
    return res;
}

int main() {
    int n, p;
    cin >> n >> p;
    string s;
    cin >> s;
    ll ans = 0;
    ll a[n+1] = {};
    rep(i,n){
        a[i] = s[i] - '0';
    }

    if(p == 2 || p == 5){
        rep(i,n){
            if(a[i] % p == 0){
                ans += i + 1;
            }
        }
        cout << ans << endl;
        return 0;
    }


    ll f[n+1] = {};
    ll g[n+1] = {};

    rep(i,n){
        g[i] = a[i] * mod_pow(10, n-1-i, p);
    }
    drep(i,n){
        f[i] = (f[i+1] + g[i]) % p;
    }

    ll b[p+1] = {};
    rep(i,n+1){
        b[f[i]]++;
    }

    rep(i,p+1){
        ans += b[i] * (b[i]-1) / 2;
    }

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




Measured memory_bytes: 5380
#include<cstdio>
#include<cstring>
#include<algorithm>
char s[10000];
int ans=0,ll;
int main()
{
	scanf("%s",s);
	ll=strlen(s);
	for(int i=0;i<ll;i++)
	{
		if(s[i]=='1')
			ans++;
	}
	printf("%d",ans);
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#include <math.h>
#include<iostream>
#include <string>
using namespace std;
typedef long long ll;
#define pb pushback
#define fr(i,n) for(int i=0;i<n;i++)
#define ifr(i,n) for(int i=n-1;i>=0;i--)


int main() {
    string x,y,z;
	cin >> x;
    int ans=700;
  fr(i,3){
    if(x[i]=='o')ans+=100;
  }
      cout << ans << endl;
}


Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder
{

    class Program
    {
        static void Main(string[] args)
        {
            var vals = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
            var T = vals[0];
            var X = vals[1];
            T *= 10000;
            var result = (double)(T / X) / 10000.0;
            Console.WriteLine(result);
        }

    }
}
//A

Measured memory_bytes: 13396
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000
class BIT {
    private:
        int size_;
        vector<int> bit;
    public:
        BIT() {
            size_ = 0;
            bit = vector<int>(0);
        }
        BIT(int size__) {
            size_ = size__;
            bit = vector<int>(1000010, 0);
        }
        int sum(int i) {
            int ret = 0;
            while(i > 0) {
                ret += bit[i];
                i -= i & (-i);
            }
            return ret;
        }
        void add(int i, int x) {
            while(i <= size_) {
                bit[i] += x;
                i += i & (-i);
            }
        }
};

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    string S; cin >> S;
    BIT Bit[26];
    rep(i, 26) Bit[i] = BIT(N);
    rep(i, N) {
        Bit[S[i] - 'a'].add(i + 1, 1);
    }
    int M; cin >> M;
    while(M--) {
        int t;
        cin >> t;
        if (t == 2) {
            int l, r;
            cin >> l >> r;
            int cnt = 0;
            rep(i, 26) {
                if (Bit[i].sum(r) - Bit[i].sum(l - 1) > 0) cnt++;
            }
            cout << cnt << endl;
        } else {
            int k; char c;
            cin >> k >> c;
            Bit[S[k - 1] - 'a'].add(k, -1);
            S[k - 1] = c;
            Bit[c - 'a'].add(k, 1);
        }
    }


    return 0;
}


Measured memory_bytes: 102556
#include <bits/stdc++.h>
using namespace std;
#define INF 0x7fffffff
#define PI acos(-1.0)
#define MOD 2520
#define E 1e-12
#define ll long long
using namespace std;
#define N 150000
int a[N];
int num[N];
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=1; i<=n; i++)
    {
        scanf("%d",&a[i]);
        num[a[i]]++;
    }
    sort(a+1,a+n+1);
    int r=n;
    int ans=0;
    for(int i=1; i<=n; i++)
    {
        if(num[a[i]]>=2)
        {
            if(r<i)
            {
                ans+=(num[a[i]]-1)*2;
            }
            else
            {
                while(num[a[i]]>=2)
               {
                while(num[a[r]]>=2)
                    {
                        num[a[r]]--;
                        num[a[i]]--;
                        ans+=2;
                        if(num[a[i]]==1)
                            break;
                    }
                    r--;
                    if(r<i)
                    {
                        ans+=(num[a[i]]-1)*2;
                        break;
                    }
                }
            }

        }
    }
    cout<<n-ans<<endl;


    return 0;
}



Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (ll i = 0, i##_len = (n); i < i##_len; ++i)
#define xrep(i, a, b) for (ll i = ll(a); i < ll(b); ++i)
using ll = long long;
const ll INF = 100100100;

int main() {
    ll N, Q;
    cin >> N;
    vector<ll> A(N);
    rep(i, N) cin >> A[i];
    cin >> Q;
    vector<ll> B(Q), C(Q);
    rep(i, Q) {
        cin >> B[i];
        cin >> C[i];
    }
    ll sum = 0 ;   
    vector<ll> cntA(10000000, 0);
    for(auto a: A) {
        sum += a;
        cntA[a]++;
    }

    rep(i, Q) {
        ll inc = (C[i]-B[i])*cntA[B[i]];
        cntA[C[i]] += cntA[B[i]];
        cntA[B[i]] = 0;
        sum += inc;
        cout << sum << endl;
    }

    return 0;
}

Measured memory_bytes: 83728
// include
// ------------------------------------------------
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <math.h>

using namespace std;

// func
// ------------------------------------------------
int CalcSumOfDigit(int n);      // 各桁の和を計算する。
int getDigit(int n);            // 数字の桁数を取得する。
string upper(string str);       // 英字を大文字に変換する。
string lower(string str);       // 英字を小文字に変換する。

// define
// ------------------------------------------------
#define all(a)        (a).begin(),(a).end()
#define rall(a)       (a).rbegin(),(a).rend()
#define sz(a)         int((a).size())
#define rep(i,n)      for(int(i)=0;(i)<(n);(i)++)
#define repe(i,n)     for(int(i)=0;(i)<=(n);(i)++)
#define vsort(v)      sort((v).begin(),(v).end())
#define rvsort(v)     sort(rall((v)))
#define vi            vector<int>
#define GCD(a,b)      __gcd((a),(b))
#define LCM(a,b)      (a)/GCD((a),(b))*(b)
#define kiriage(a,b)  ((a)+(b)-1)/(b)

const int INF = 1e9;

typedef long long ll;
typedef unsigned long long ull;

// code
// ------------------------------------------------
int main() {

  ll n;cin >> n;

  vector<pair<ll,ll>> p(n);

  for(ll i = 0; i < n;i++)
  {
    ll a;
    cin >> a;
    p[i].first = i + 1;
    p[i].second = a;
  }

  sort(all(p),[](auto a,auto b)
  {
    return a.second < b.second;
  });

  rep(i,n)
  {
    if(i == 0)
    {
      cout << p[i].first;
    }
    else
    {
      cout << " " << p[i].first;      
    }
  }
  cout << endl;

  return 0;
}
// funcの実体
// ------------------------------------------------
int getDigit(int n)
{
  int i = 1;
  while(1)
  {
    n = n / 10;
    if(n == 1)
      break;
    i++;
  }
  return i;
}
int CalcSumOfDigit(int n)
{
  int s = 0;
  while(n)
  {
    s += n % 10;
    n = n / 10;
  }
  return s;
}

string upper(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(97 <= *itr && *itr <= 122)
    {
      *itr = *itr - 32;
    }
  }
  return str;
}

string lower(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(65 <= *itr && *itr <= 90)
    {
      *itr = *itr + 32;
    }
  }
  return str;
}


Measured memory_bytes: 2432
#include<iostream>
#include<iomanip>
#include<map>
#include<set>
#include<vector>
#include<array>
#include<string>
#include<stack>
#include<queue>
#include<algorithm>
#include<cassert>
#include<functional>
#include<random>
#define int int64_t
#define REP(i, a, b) for (int64_t i = (int64_t)(a); i < (int64_t)(b); i++)
#define rep(i, a) REP(i, 0, a)
#define EACH(i, a) for (auto i: a)
#define ITR(x, a) for (auto x = a.begin(); x != a.end(); x++)
#define ALL(a) (a.begin()), (a.end())
#define HAS(a, x) (a.find(x) != a.end())
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
using namespace std;




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

	int H, W;
	cin >> H >> W;
	vector<vector<int>>p(H, vector<int>(W, 0));
	rep(i, H) {
		string S;
		cin >> S;
		rep(j, W)p[i][j] = S[j] == '#' ? 1 : 0;
	}

	vector<vector<int>>red(H, vector<int>(W, 0));
	vector<vector<int>>blue(H, vector<int>(W, 0));
	rep(i, H)rep(j, W) {
		if (p[i][j]) {
			red[i][j] = 1;
			blue[i][j] = 1;
		}
		else if (j == 0)red[i][j] = 1;
		else if (j + 1 == W)blue[i][j] = 1;
		else if (i % 2 == 0)red[i][j] = 1;
		else blue[i][j] = 1;
	}
	rep(i, H) {
		rep(j, W)cout << (red[i][j] ? "#" : ".");
		cout << endl;
	}
	cout << endl;
	rep(i, H) {
		rep(j, W)cout << (blue[i][j] ? "#" : ".");
		cout << endl;
	}
}

Measured memory_bytes: 6656
#include<stdio.h>
int main(void) {
    int n,x,l[100],i,d[101];
    scanf("%d%d",&n,&x);
    d[0] = 0;
    for(i = 0; i < n; i++){
        scanf("%d",&l[i]);
        d[i+1] = d[i] + l[i];
        if(d[i+1] > x) {break;}
    }
    i ++;
    printf("%d\n", i);
    return 0;
}

Measured memory_bytes: 128
N, M, K = map(int, input().split())

A = list(map(int, input().split()))
B = list(map(int, input().split()))

from collections import deque
d = deque()

buf_K = K
ans = 0
for i in range(N):
    if buf_K >= A[i]:
        buf_K -= A[i]
        d.append(A[i])
        ans += 1
    else:
        break
max_num = ans

for j in range(M):
    if buf_K >= B[j]:
        buf_K -= B[j]
        ans += 1
        if ans > max_num:
            max_num = ans
    else:
        flag = True
        while d:
            buf_K += d.pop()
            ans -= 1
            if buf_K >= B[j]:
                buf_K -= B[j]
                ans += 1
                flag = False
                break
        if flag:
            break

print(max_num)


Measured memory_bytes: 111168
from functools import reduce

def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)

def lcm(a, b):
    return (a * b) // gcd(a, b)

def lcm_list(n):
    return reduce(lcm, n)


n = int(input())
a = list(map(int, input().split()))
m = lcm_list(a) - 1
ans = 0
for i in range(n):
    ans += m % a[i]
print(ans)

Measured memory_bytes: 3812
#include <bits/stdc++.h>
using namespace std;
#define all(v) (v).begin(), (v).end()
#define P pair<int,int>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define endl '\n'
#define int long long

struct UnionFind {
    vector<int> Parent;
    vector<int> Size;

    UnionFind(int N) : Parent(N), Size(N,1){
        for(int i = 0; i < N; i++) Parent[i] = i;
    }

    int root(int A) {
        if (Parent[A] == A) return A;
        return Parent[A] = root(Parent[A]);
    }

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

        if (Size[A] < Size[B]) swap(A, B);

        Size[A] += Size[B];
        Parent[B] = A;
        return true;
    }

    bool issame(int A, int B) { //
        return root(A) == root(B);
    }

    int findsize(int A) {
        return Size[root(A)];
    }
};

signed main() {
    int n,m;
    cin >> n >> m;

    UnionFind Tree(n);
    vector<int> a(m), b(m);
    rep(i,m) {
        cin >> a[i] >> b[i];
        a[i]--, b[i]--;
    }

    vector<int> ans(m + 1);
    ans[m] = n * (n - 1) / 2;

    for(int i = m - 1; i >= 0; i--){
        if(Tree.issame(a[i],b[i])) {
            ans[i] = ans[i + 1];
            Tree.merge(a[i],b[i]);
        } else {
            ans[i] = ans[i + 1] - (Tree.findsize(a[i]) * Tree.findsize(b[i]));
            Tree.merge(a[i],b[i]);
        }
    }

    for(int i = 1; i <= m; i++){
        cout << ans[i] << endl;
    }
}


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

int main() {
	long long N;
	cin >> N;
	vector<vector<long long> > V(N);
	for (int i = 0; i < N - 1; i++) {
		long long S, T;
		cin >> S >> T;
		S--, T--;
		V[S].push_back(T);
		V[T].push_back(S);
	}
	long long INF = 1000000000;
	vector<long long> Dist(N, INF);
	queue<long long> Q;
	Dist[0] = 0;
	Q.push(0);
	while (!Q.empty()) {
		long long P = Q.front();
		Q.pop();
		for (int NP : V[P]) {
			if (Dist[NP] == INF) {
				Dist[NP] = Dist[P] + 1;
				Q.push(NP);
			}
		}
	}
	/*
	vector<long long> DC(N + 10, 0);
	for (int i = 0; i < N; i++) {
		DC[Dist[i]]++;
	}
	vector<pair<long long, long long> > COUNT(N, { 0, 0 });
	for (int i = 0; i < N; i++) {
		COUNT[i].second = i;
		if (Dist[i] >= 3) {
			COUNT[i].first += DC[Dist[i] - 3];
		}
		if (Dist[i] >= 1) {
			COUNT[i].first += DC[Dist[i] - 1];
		}
		COUNT[i].first += DC[Dist[i] + 1] + 1;
		COUNT[i].first += DC[Dist[i] + 3];
	}
	sort(COUNT.begin(), COUNT.end(), greater<pair<long long, long long> >());
	*/
	long long Even = 0, Odd = 0;
	for (int i = 0; i < N; i++) {
		if (Dist[i] % 2 == 0) Even++;
		else Odd++;
	}
	long long A = (N + 2) / 3, B = (N + 1) / 3, C = N / 3;
	vector<long long> ANS(N, 0);
	if (Even <= C) {
		long long NA = 1, NB = 2, NC = 3;
		for (int i = 0; i < N; i++) {
			if (Dist[i] % 2 == 0) ANS[i] = NC, NC += 3;
		}
		for (int i = 0; i < N; i++) {
			if (Dist[i] % 2 == 1) {
				if (NA <= N) ANS[i] = NA, NA += 3;
				else if (NB <= N) ANS[i] = NB, NB += 3;
				else ANS[i] = NC, NC += 3;
			}
		}
		for (int i = 0; i < N; i++) {
			cout << ANS[i];
			if (i == N - 1) cout << endl;
			else cout << " ";
		}
		return 0;
	}
	if (Odd <= C) {
		long long NA = 1, NB = 2, NC = 3;
		for (int i = 0; i < N; i++) {
			if (Dist[i] % 2 == 1) ANS[i] = NC, NC += 3;
		}
		for (int i = 0; i < N; i++) {
			if (Dist[i] % 2 == 0) {
				if (NA <= N) ANS[i] = NA, NA += 3;
				else if (NB <= N) ANS[i] = NB, NB += 3;
				else ANS[i] = NC, NC += 3;
			}
		}
		for (int i = 0; i < N; i++) {
			cout << ANS[i];
			if (i == N - 1) cout << endl;
			else cout << " ";
		}
		return 0;
	}
	long long NA = 1, NB = 2, NC = 3;
	for (int i = 0; i < N; i++) {
		if (Dist[i] % 2 == 0) {
			if (NA <= N) ANS[i] = NA, NA += 3;
			else ANS[i] = NC, NC += 3;
		}
		else {
			if (NB <= N) ANS[i] = NB, NB += 3;
			else ANS[i] = NC, NC += 3;
		}
	}
	for (int i = 0; i < N; i++) {
		cout << ANS[i];
		if (i == N - 1) cout << endl;
		else cout << " ";
	}
}

Measured memory_bytes: 18280
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
using st=string;
using ch=char;
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<P> vP;
typedef vector<ch> vc;
typedef vector<vc> vvc;
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
#define ROF(i,a,b) for(ll i=a;i>=b;i--)
#define per(i,a) ROF(i,a,0)
#define pb push_back
const ll MOD=1000000007;
const ll MOD2=998244353;
const ld PI=acos(-1);
const ll INF=1e18;
const ll MXint=1<<32-1;
st abc="abcdefghijklmnopqrstuvwxyz";
st ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
struct edge{ll to,cost;};
struct edge2{ll from,to,cost;};

//[1,n]だけを求めていけばいいよね

const ll MXN=200000;
ll bit[MXN+1],n;

ll sum(int i){
    ll s=0;
    while(i>0){
        s+=bit[i];
        i-=i&(-i);
    }
    return s;
}

void add(int i,int x){
    while(i<=n){
        bit[i]+=x;
        i+=i&(-i);
    }
}

int main() {
    cin >> n;
    vP p(n);
    rep(i,n){
        cin >> p[i].first;
        p[i].second=i;
    }
    sort(p.begin(),p.end());
    vl a(n);
    rep(i,n){
        a[p[i].second]=i+1;
    }
    ll ans=0;
    rep(i,n){
        ans+=i-sum(a[i]);
        add(a[i],1);
    }
    cout << ans << '\n';
}


Measured memory_bytes: 9152
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, S1, S2, S;
  
  cin >> N;
  vector<int> vec(N);

  for (int i = 0; i < N; i++) {
    cin >> vec.at(i);
  }
  
  S = accumulate(vec.begin(), vec.end(), 0);
  for (int i = 0; i < N; i++) {
    S1 = accumulate(vec.begin(), vec.end()-N+i, 0);
    S2 = accumulate(vec.begin()+i, vec.end(), 0);
    S = min(S,abs(S1-S2));
  }
  
  cout << S << endl;

}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <time.h>
#include <stdlib.h>
#include <string>
#include <bitset>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <sstream>
#include <stack>
#include <iomanip>
using namespace std;
#define pb push_back
#define mp make_pair
typedef pair<int,int> pii;
typedef long long ll;
typedef double ld;
typedef vector<int> vi;
#define fi first
#define se second
#define fe first
#define FO(x) {freopen(#x".in","r",stdin);freopen(#x".out","w",stdout);}
#define Edg int M=0,fst[SZ],vb[SZ],nxt[SZ];void ad_de(int a,int b){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;}void adde(int a,int b){ad_de(a,b);ad_de(b,a);}
#define Edgc int M=0,fst[SZ],vb[SZ],nxt[SZ],vc[SZ];void ad_de(int a,int b,int c){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;vc[M]=c;}void adde(int a,int b,int c){ad_de(a,b,c);ad_de(b,a,c);}
#define es(x,e) (int e=fst[x];e;e=nxt[e])
#define esb(x,e,b) (int e=fst[x],b=vb[e];e;e=nxt[e],b=vb[e])
int n,m,k,fb[22][22],s[2][1<<21];
const ll MOD=1e9+7; 
int main()
{
	scanf("%d%d%d",&n,&m,&k); --n;
	for(int i=1,a,b,c;i<=k;++i)
		scanf("%d%d%d",&a,&b,&c),fb[a][b-1]|=1<<(!c);
	s[0][0]=1; int x=0;
	for(int i=1;i<=m;++i)
	{
		for(int j=0;j<n;++j)
		{
			x^=1; memset(s[x],0,sizeof s[x]);
			for(int r=0;r<(1<<n);++r)
			{
				bool a=(r>>j)&1;
				for(int w=a;w<=1;++w)
				{
					if(fb[i][j]&(1<<w)) continue;
					register int g,tt;
					if(w==a) g=r;
					else
					{
						g=r|(1<<j),tt=r>>j;
						if(tt) g^=(tt&-tt)<<j;
					}
					s[x][g]+=s[!x][r];
					(s[x][g]>=MOD)?(s[x][g]-=MOD):0;
				}
			}
		}
	}
	ll ans=0;
	for(int r=0;r<(1<<n);++r) ans+=s[x][r];
	printf("%lld\n",ans%MOD);
}


Measured memory_bytes: 16640
#include<bits/stdc++.h>
using namespace std;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n,k;
    vector<int> v;
    cin>>n>>k;
    for(int i=0;i<n;i++){
        int a;
        cin>>a;
        v.push_back(a);
    }
    for(int i=0;i<n-k;i++){
        if(v[i]<v[i+k]){
            cout<<"Yes\n";
        }else{
            cout<<"No\n";
        }
    }


return 0;

}

//      *   *  *****  *   *  *   *   ****  ****    ****     **  ***
//     *   *  *      **  *  *   *  *      *   *  *        * *  *  *
//    *****  *****  * * *  *   *  *      ****   *       *  *    *
//   *   *      *  *  **  *   *  *      *  *   *       *****  *
//  *   *  *****  *   *   ***    ****  *   *    ****     *   ****

//     ****  *   *  *   *   ***   *   *  *****  *   *
//    *     *   *  *   *  *   *  *   *  *      *   *
//    ***  *****  *   *  *****  * * *  ****   *   *
//      *   *    *   *  *   *  * * *  *      *   *
//  ****   *     ***   *   *   * *   *****   ***


Measured memory_bytes: 4272
#include<bits/stdc++.h>
// Useful constants
#define INF  (int)1e9
#define EPS   1e-9
#define MOD 1000000007ll
#define PI 3.14159
// for input-output
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
// iteration macros: have advantage of auto-casting and not recomputing arguments
#define REP(i, a, b) \
for (int i = int(a); i <= int(b); i++) // a to b, and variable i is local!
#define TRvi(c, it) \
for (vi::iterator it = (c).begin(); it != (c).end(); it++)
#define TRvii(c, it) \
for (vii::iterator it = (c).begin(); it != (c).end(); it++)
#define TRmsi(c, it) \
for (msi::iterator it = (c).begin(); it != (c).end(); it++)
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define setBit(S, j) (S |= (1 << j))
#define clearBit(S, j) (S &= ~(1 << j))
#define toggleBit(S, j) (S ^= (1 << j))
// input macro
#define in(x,n)   for(int e=0;e<n;e++){ll y;cin>>y;x.pb(y);}
//output macro
#define print(x)    for(auto it:x) cout<<it<<' '; cout<<endl;
#define printii(x)  for(auto it:x) cout<<it.F<<' '<<it.S<<'\t';  cout<<endl;
// shortcut for data type
#define ll long long
#define vi vector<ll>
#define vvi vector<vi>
#define ii pair<ll,ll>
#define pll pair<ll,ll>
#define vii vector<ii>
#define vvii vector<vii>
#define viii vector<pair<ii,ll>>
#define pb push_back
#define ppb pop_back
#define eb emplace_back
#define mp make_pair
#define F first
#define S second
#define uset unordered_set
#define umap unordered_map
//--namespace
using namespace std;
//--useful function
ll gcd(ll a, ll b){ll temp;while (b > 0){temp = a%b;a = b;b = temp;} return a;}
ll lcm(ll a, ll b){return a*b/gcd(a,b);}
ll fpow(ll  b, ll exp, ll mod){if(exp == 0) return 1;ll t = fpow(b,exp/2,mod);if(exp&1) return t*t%mod*b%mod;return t*t%mod;}
ll divmod(ll i, ll j, ll mod){i%=mod,j%=mod;return i*fpow(j,mod-2,mod)%mod;}
// --clock funtion
clock_t time_p=clock();
void TimeTaken()
{
    time_p=clock()-time_p;
    cerr<<"Completion time : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";
}
// --solve function
void solve() {

}
//--main function
int main(){
	string S; cin >> S;
	int ans = INF;
	for (int i = 0; i < S.size() - 2; ++i) {
		int tmp = stoi(S.substr(i, 3));
		ans = min(ans, abs(753 - tmp));
	}
	cout << ans << endl;
	return 0;

//   TimeTaken();
}


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

int main () {
  string s;
  cin >> s;
  int i = 1;
  for (; i < s.length(); ++i) {
    if (s[i - 1] == s[i]) {
      cout << "Bad\n";
      break;
    }
  }
  if (i == s.length()) cout << "Good\n";
}


Measured memory_bytes: 256
/*input
RSR
*/
 
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <climits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include <stdint.h>
 
using namespace std;
 
/*******  All Required define Pre-Processors and typedef Constants *******/
#define ar array
#define scd(t) scanf("%d",&t)
#define scld(t) scanf("%ld",&t)
#define sclld(t) scanf("%lld",&t)
#define scc(t) scanf("%c",&t)
#define scs(t) scanf("%s",t)
#define scf(t) scanf("%f",&t)
#define sclf(t) scanf("%lf",&t)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define tests int r; cin >> r; while(r--)
#define MP make_pair
#define PI acos(-1)
typedef pair<int, int> PII;
typedef pair<double, double> PDD;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<PII> VII;
typedef vector<VI> VVI;
typedef map<int,int> MPII;
typedef set<int> SETI;
typedef multiset<int> MSETI;
typedef long int int32;
typedef unsigned long int uint32;
typedef long long int int64;
typedef unsigned long long int  uint64;
#define godspeed ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(0);
 
#define M(x) ((x)%(1000000007))
 
vector<int> adj_list[100010];
bool visited[10010];





int main() {
 	
 	string s;
 	cin>>s;
 	int curr = 0;
 	int ma = 0;
 	rep(i,3){
 		if(s[i]=='R'){
 			curr++;
 			
 		}
 		else{
 			ma = max(curr,ma);
 			curr = 0;
 		}
 	}
 	ma = max(ma,curr);
 	cout<<ma<<endl;


}

 


Measured memory_bytes: 5944
N,M = gets.split.map(&:to_i)
Vector = Struct.new(:x,:y)
n = []
m = []
N.times do
	x,y = gets.split.map(&:to_i)
	n << Vector.new(x,y)
end

M.times do
	x,y = gets.split.map(&:to_i)
	m << Vector.new(x,y)
end

score = Array.new(N){Float::INFINITY}
point = Array.new(N)
N.times do |i|
	M.times do |j|
		tmp = (n[i].x - m[j].x).abs + (n[i].y - m[j].y).abs
		if tmp < score[i]
			score[i] = tmp
			point[i] = j
		end
	end
end

N.times do |i|
	puts point[i]+1
end







Measured memory_bytes: 1788
import java.util.*;

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

      int n = Integer.parseInt(sc.next());

      int[] L = new int[n];
      for(int i=0;i<n;i++){
        L[i] = Integer.parseInt(sc.next());
      }

      Arrays.sort(L);

      int cnt = 0;

      for(int i=0;i<n-2;i++){
        for(int j=i+1;j<n-1;j++){
          for(int k=j+1;k<n;k++){
            boolean a = (L[i]<(L[j]+L[k]));
            boolean b = (L[j]<(L[k]+L[i]));
            boolean c = (L[k]<(L[i]+L[j]));
            if(a && b && c){
              cnt++;
            }
            int sa1=0,sa2=0,sa3=0;
            if(!a){
              sa1 = L[i]-L[j]-L[k];
            }
            if(!b){
              sa2 = L[j]-L[k]-L[i];
            }
            if(!c){
              sa3 = L[k]-L[i]-L[j];
            }
            i += sa1;
            j += sa2;
            k += sa3;
            if(j>=n-1 || i>=n-2){
              break;
            }
          }
          if(i>=n-2){
            break;
          }
        }
      }


      System.out.println(cnt);

    }
}


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

// def
#define debug(x) cout << #x << ": " << x << endl
#define out(x) cout << x << endl
#define repeat(i, a, b) for (int i = (a); i < (b); i++)
#define revrepeat(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define revrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef complex<ld> Point;
typedef vector<vector<int>> Graph;
const int MOD = 1e9 + 7;
const int INF = 1e9;
const int MAX_V = 1e5 + 5;
const int MAX_N = 1e5 + 5;
const double PI = acos(-1);

struct mint {
    // Preparation: MOD is already defined.
    ll value;

    mint(ll value = 0) : value((value % MOD + MOD) % MOD) {}

    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }

    mint pow(mint m) const {
        return pow(m.value);
    }

    mint inv() const {
        ll a = value, b = MOD, u = 1, v = 0;
        while (b) {
            ll t = a / b;
            a -= t * b;
            swap(a, b);
            u -= t * v;
            swap(u, v);
        }
        u %= MOD;
        return u;
    }

    mint &operator+=(const mint a) {
        if ((value += a.value) >= MOD) value -= MOD;
        return *this;
    }
    mint &operator-=(const mint a) {
        if ((value += MOD - a.value) >= MOD) value -= MOD;
        return *this;
    }
    mint &operator*=(const mint a) {
        (value *= a.value) %= MOD;
        return *this;
    }
    mint &operator/=(const mint a) {
        return (*this) *= a.inv();
    }

    mint operator+(const mint a) const {
        mint res(*this);
        return res += a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res -= a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res *= a;
    }
    mint operator/(const mint a) const {
        mint res(*this);
        return res /= a;
    }
};

long modpow(long m, long p) {
    if (p == 0) return 1;
    if (p % 2)
        return m * modpow(m, p - 1) % MOD;
    else {
        long res = modpow(m, p / 2);
        return res * res % MOD;
    }
}

int main() {
    int n;
    cin >> n;
    vector<ll> a(n);
    mint ans = 0;
    rep(i, n) cin >> a[i];
    rep(i, 60) {
        ll cnt_zero = 0;
        ll cnt_one = 0;
        rep(j, n) {
            if ((a[j] >> i) & 1)
                cnt_one++;
            else
                cnt_zero++;
        }
        ll temp = (cnt_one * cnt_zero) % MOD;
        temp = temp * (modpow(2, i) % MOD);
        ans += temp;
        // ans += (cnt_one * cnt_zero) * modpow(2, i);
    }
    out(ans.value);
    return 0;
}


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




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

    long long int a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z;



    cin>>n>>k;
    vector <long long int> v1;
    for(i=0;i<n;i++)
    {
        cin>>a;
        v1.push_back(a);
    }
    sort(v1.begin(),v1.end());
    s=0;
    for(i=0;i<k;i++)
        s+=v1[i];

    cout<<s<<"\n";

    return 0;


}


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

int main(){
  int n,k;
  int a[100000];
  cin >> n >> k;
  for(int i = 0;i < n;i++){
    cin >> a[i];
  }

  int ans = 1;
  int i = k;
  while(i < n){
    ans++;
    i += (k-1);
  }

  cout << ans << endl;



  return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <fstream>
#include <numeric>
using namespace std;
typedef long long int ll;

#define EPS (1e-7)
#define INF 1e18
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define PI (acos(-1))

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

int main() {
    string s;
    cin >> s;
    for(char c = 'a'; c <= 'z'; c++){
        bool f = false;
        REP(i, s.size()){
            if (s[i] == c) f = true;
        }
        if (f) continue;
        cout << c << endl;
        return 0;
    }
    cout << "None" << endl;
    return 0;
}

Measured memory_bytes: 512
#pragma GCC optimize("Ofast")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>*/
 
#define pll              pair <long long,long long>
#define pb               push_back
#define ll               long long
#define ff               first
#define ss               second
#define D(x)             cerr<<#x " = "<<(x)<<endl
#define vll              vector <ll>
#define IOS              ios_base::sync_with_stdio(0); cin.tie(NULL);
#define endl             '\n'   
using namespace std;
int main()
{
    IOS
 	// freopen("input.txt","r",stdin);
 	// freopen("output.txt","w",stdout);
 	// freopen("error.txt","w",stderr);
 	ll n,m;
 	cin>>n>>m;
 	ll s=0;
 	for(ll i=0;i<m;i++)
 	{
 		ll x;
 		cin>>x;
 		s+=x;
 	}
 	if(s>n)
 	{
 		cout<<-1<<endl;
 	}
 	else
 	{
 		cout<<n-s<<endl;
 	}
    return 0;
}

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

int n,v,u,k,Time,data[101][101],d[101],f[101];

//dfs
void visit(int u){
  int v;
  d[u] = Time++;
 
  for(v = 1; v <= n; v++){
    if(data[u][v]&d[v]==0)
      visit(v);
  }
  f[u] = Time++;
}
 
int main(){
  cin >> n;
  
  //初期化
  Time = 1;
  for(int i = 1; i <= n; i++){
    for(int j = 1; j <= n; j++){
      data[i][j]=0;
      d[j]=0;
      f[j]=0;
    }
  }
  
  //入力
  for(int i = 0; i < n; i++){
    cin >> u >> k;
    for(int j = 0; j < k; j++){
      cin >> v;
      data[u][v]=1;
    }
  }
  
  //dfs
  for(int i = 1;i <= n; i++){
    if(d[i]==0)visit(i);
  }
  
  //出力
  for(int i = 1;i <= n; i++){
    cout << i << " " << d[i] << " " << f[i] << endl;
  }
  
  return 0;
}

Measured memory_bytes: 1204
a, b = map(int, input().split(" "))

df = b - a 

def sumPole(d) :
    psum = 0
    for i in range(0, d + 1) :
        psum += i
        
    return psum

print(int((sumPole(df) + sumPole(df - 1) - a - b) / 2))

Measured memory_bytes: 2940
#B
n = int(input())
a = []
for i in range(n):
    ai = int(input())
    a.append(ai)

cnt = 0
i = 0
while i < n:
    if a[i] >= 2:
        pairs = a[i] // 2
        cnt += pairs
        a[i] -= (pairs * 2)

    elif a[i] == 1:
        if i + 1 >= n:
            break

        if a[i + 1] > 0:
            cnt += 1
            a[i] -= 1
            a[i + 1] -= 1

        else:
            i += 1

    else:
        i += 1

print(cnt)

Measured memory_bytes: 58200
#include <iostream>
// #include <vector>
#include <string>
// #include <algorithm>

using namespace std;

int main(){
    int N;
    string s;
    cin >> N;
    cin >> s;
    int red = 0;
    int blue = 0;
    for(int i = 0; i < N; i++)
    {
        if (s.at(i) == 'R') {
            red++;
        }else if (s.at(i) == 'B') {
            blue++;
        }
    }
    if (red > blue) {
        cout << "Yes" << endl;
    }else
    {
        cout << "No" << endl;
    }
    
    
    
}

Measured memory_bytes: 256
import sys
read = sys.stdin.read
readline = sys.stdin.readline

n,q = map(int, input().split())
ABPX = list(map(int,read().split()))
AB = iter(ABPX[:n+n-2])
PX = iter(ABPX[n+n-2:])

tree = dict()
for a,b in zip(AB,AB):
  if a in tree: tree[a].add(b)
  else: tree[a] = {b}
  if b in tree: tree[b].add(a)
  else: tree[b] = {a}

opr = {i+1:0 for i in range(n)}
for p,x in zip(PX,PX):
  opr[p] += x

stack = [1]
parent = [0] * (n+1)
ans = [0]*n
while stack:
  x = stack.pop()
  ans[x-1] += opr[x]
  for y in tree[x]:
    if y == parent[x]: continue
    parent[y] = x
    stack.append(y)
    ans[y-1] += ans[x-1]

print(*ans)

Measured memory_bytes: 147300
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll n,a[100500],sum;
bool pos,neg,ze;
int main(){
	ios::sync_with_stdio(false);
	cin >> n;
	ze = pos = neg = false;
	for(int i = 1;i <= n;i ++){
		cin >> a[i];
		sum += abs(a[i]);
		if(a[i] > 0) pos = true;
		else if(a[i] < 0) neg = true;
		else ze = true;
	}
	sort(a+1,a+n+1);
	if(ze && !pos && !neg){
		cout << 0 <<endl;
		while(n > 1){
			cout << 0 << ' ' << 0 <<endl;
			n --;
		}
		return 0;
	}
	if(neg && pos || ze){
		cout << sum << endl;
		int st = 2,mm = n;
		while(a[st] <= 0){
			cout << a[n] <<' '<<a[st]<<endl;
			a[n] = a[n]-a[st];
			st ++;
			mm --;
		}
		while(mm > 2){
			cout << a[1] <<' ' <<a[n]<<endl;
			a[1] = a[1] -a[n];
			mm --;
			n --;
		}
		cout << a[st] << ' '<< a[1]<<endl;
	}
	else if(pos){
		cout <<sum-a[1]*2<<endl;
		cout << a[1] <<' '<< a[n] <<endl;
		a[1] = a[1]-a[n];
		n --;
		while(n > 2){
			cout << a[1] <<' ' <<a[n]<<endl;
			a[1] = a[1] -a[n];
			n --;
		}
		cout << a[n] << ' '<< a[1]<<endl;
	}
	else {
		int st = 1;
		cout << sum+2*a[n]<<endl;
		cout << a[n] <<' '<< a[1] <<endl;
		a[n] = a[n]-a[1];
		st ++;
		while(st<n){
			cout << a[n] <<' ' <<a[st]<<endl;
			a[n] = a[n] -a[st];
			st ++;
		}
	}
    return 0;
}


Measured memory_bytes: 2688
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define db double
#define pll pair<ll,ll>
#define pdb pair<db,db>
#define ldb long double
#define clr(x) memset(x,0,sizeof(x))
#define count_bit(x) __builtin_popcount(x)
#define debug(x) cout<<#x<<" :: "<<x<<endl;
#define debug2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<endl;
#define debug3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<endl;
const int size1 = 1e5+7;
const int size2 = 1e4;
const ll mod = 1e9+7;
 
// ll fact[size1];
 
// ll pw(ll x,ll y,ll md)
// {
//     if(y==0)return 1;
//     ll p =pw(x,y/2,md);
//     p = (p*p)%md;
//     if(y%2==1)p = (p*x)%md;
//     return p;
// }
// ll gcd(ll a,ll b)
// {
//  if(b==0)return a;
//  a = a%b;
//  return gcd(b,a);
// }
// ll inverse(ll x,ll mod)
// {
//     return pw(x,mod-2,mod);
// }
// ll ncr(ll n,ll r,ll mod)
// {
//     ll num = fact[n];
//     ll den = (fact[r] * fact[n-r])%mod;
//     den = inverse(den,mod);
 
//     ll ans = (num*den)%mod;
//     return ans;
// }
// vector<ll> adj1[size1];
// vector<ll> adj[size1];
// ll d[size1];
// ll n,m;
// void dikstra(ll s)
// {
//     for(ll i=1;i<=n;i++)d[i]=1e9;
//     d[s] = 0;
//     priority_queue<pll, vector<pll>, greater<pll>> q;
//     q.push({0, s});
//     while(!q.empty())
//     {
//         ll v = q.top().ss;
//         ll d_v = q.top().ff;
//         q.pop();
//         if(d_v!=d[v])continue;
//         for(auto to:adj1[v])
//         {
//             ll len = 1;
//             if(d[v] + len < d[to])
//             {
//                 d[to] = d[v]+len;
//                 q.push({d[to],to});
//             }
//         }
//     }
// }
 
// ll smallestPrimeFactor[size1];
 
// void seive(){
//     clr(smallestPrimeFactor);
 
//     for(ll i=2;i<size1;i++){
//         if(smallestPrimeFactor[i]!=0)continue;
//         smallestPrimeFactor[i] = i;
//         for(ll j=2*i;j<size1;j+=i){
//             smallestPrimeFactor[j]=i;
//         }
//     }    
// }

int main()
{
    //cout<<setprecision(12)<<fixed;
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    
    
    ll T;
    //cin>>T;
    T = 1;
    while(T--)
    {
        //cout<<"Case #"<<cas<<": ";cas++;
        ll x;cin>>x;
        cout<<1-x<<endl;

    }
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define rep2(i,n) for(int i=0;i<=n;i++)
#define repr(i,a,n) for(int i=a;i<n;i++)
#define all(a) a.begin(),a.end()
#define P pair<long long,long long>
#define double long double
#define vector2(a,b,c) vector<vector<int>> a(b/*縦！w*/,vector<int>(c/*横！w*/))
#define INF 1e10
#define MOD 1e9+7
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using Graph = vector<vector<int>>;
signed main(){
  int a;
  cin>>a;
  vector<int> b(a);
  rep(i,a)
    cin>>b[i];
  bool d=true;
  rep(i,a){
  if(b[i]%2==0&&(b[i]%3!=0&&b[i]%5!=0))
    d=false;
  }
  if(d)
    cout<<"APPROVED"<<endl;
    else
      cout<<"DENIED"<<endl;
}


Measured memory_bytes: 256
require 'pp'
a, b = gets.split.map(&:to_i)
ans = []

1.upto(100000) do |n|
  x = (n*0.08).floor
  y = (n*0.1).floor
  if a == x && b == y
    ans << n
  end

end
if ans.empty?
  p -1
  exit
end
p ans.min


Measured memory_bytes: 4092
#include <stdio.h>
#define N 500000

int n,tree[N];

void Swap(int *a,int *b){
  int temp;
  temp=*a;
  *a=*b;
  *b=temp;
}

int LeftC(int i){
  return 2*i;
}

int RightC(int i){
  return 2*i+1;
}

void maxHeapify(int i){
  int l;
  l = LeftC(i);
  int r;
  r = RightC(i);
  int largest;
  if(l <= n && tree[l] > tree[i]) largest = l;
  else largest = i;
  if (r <= n && tree[r] > tree[largest]) largest = r;
  if(largest != i) {
    Swap(&tree[i],&tree[largest]);
    maxHeapify(largest);
  }
}

int main(){
  int i;
  scanf("%d",&n);
  for(i=1;i<=n;i++) scanf("%d",&tree[i]);
  for(i=n/2;i>=1;i--) maxHeapify(i);
  for(i=1;i<=n;i++) printf(" %d",tree[i]);
  printf("\n");
  return 0;
}

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

using namespace std;
using ll = long long;

int main() {
	int N;
	cin >> N;
	vector<int> H(N);
	for (int i = 0; i < N; ++i) { cin >> H[i]; }

	int res = 0;
	int h = H[0];
	for (int i = 0; i < N; ++i) {
		if (H[i] >= h) {
			++res;
			h = H[i];
		}
	}

	cout << res << endl;

	return 0;
}


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

int main()
{
    string s;
    cin >> s;
    int n = s.size();
    int diff = 1000;
    int x;

    for(int i = 0; i <= n-3; i++){
        x = (s[i] - '0') * 100 + (s[i + 1] - '0') * 10 + (s[i + 2] - '0');
        diff = min(diff,abs(x - 753));
    }
    cout << diff << endl;
}

Measured memory_bytes: 256