akhauriyash/Code-Regression huggingface dataset:
# https://atcoder.jp/contests/agc040/tasks/agc040_a
import sys
# sys.setrecursionlimit(100000)


def input():
    return sys.stdin.readline().strip()


def input_int():
    return int(input())


def input_int_list():
    return [int(i) for i in input().split()]


def main():
    S = input()
    ans = 0
    left = 0
    right = 0
    for i in range(len(S) - 1):
        if S[i] + S[i + 1] == "><":
            right += 1
            tmp = max(left, right)
            ans += tmp
            ans += sum([i for i in range(left)])
            ans += sum([i for i in range(right)])
            right = 0
            left = 0
        else:
            if S[i] == ">":
                right += 1
            elif S[i] == "<":
                left += 1
    else:
        if S[-1] == "<":
            left += 1
        else:
            right += 1
        tmp = max(left, right)
        ans += tmp
        ans += sum([i for i in range(left)])
        ans += sum([i for i in range(right)])
    print(ans)
    return


if __name__ == "__main__":
    main()


Measured memory_bytes: 110144
#include <bits/stdc++.h>
using namespace std;
#define vsort(vec) sort(vec.begin(), vec.end())
#define vreverse(vec) reverse(vec.begin(), vec.end())
using ll =long long;
const ll INF =99999999999;

//最大公約数
ll gcd(ll a, ll b){
   if (a%b==0){
       return(b);
   }else{
       return(gcd(b,a%b));
   }
}
//最小公倍数
ll lcm(ll a, ll b){
   return a*b/gcd(a,b);
}

//素数判定
ll isprime(ll n){
  bool prime=true;
  for(int i=2;i<n;i++){
    if(n%i==0){
      prime=false; break;
    }
  }
if(prime){cout<<n<<" is prime"<<endl;
         }else{cout<<n<<" is not prime"<<endl;}

}
//階乗　20くらいが限界
ll factorial(ll n){
  ll a=1;ll b=n;
  for(int i=0;i<n;i++){
    a*=b;
    b--;
  }
  return a;
}

//組み合わせ　nCr
ll comb(ll a,ll b){
  ll c;
  c=factorial(a)/(factorial(a-b)*factorial(b));
  return c; 
}




//10億7。　　　100000007
//2*2行列 H*W
//vector<vector<int>> vec(H,vector<int>(W));
//for(int i=0;i<H;i++){
//for(int j=0;j<W;j++){
//cin>>vec[i][j];
//  }
//}

//文字列→数列
//string S;int A=atoi(S.c_str());
//数列→文字列
//int A;string S=to_string(A);
//数字判定　isdigit(a)
//pair宣言　pair<int,int> p(5,7);
//ソート　sort(vec.begin(),vec.end());



int main(){
cout<<fixed<<setprecision(10);
 
int A,B,C;cin>>A>>B>>C;
  bool poor = false;
  if(A==B&&B!=C){poor=true;}
  if(B==C&&C!=A){poor=true;}
  if(C==A&&A!=B){poor=true;}
  
  
  if(poor){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
  
  
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
 
int main() {
  // input
  int n,m;cin >> n >> m;
  vector<int> l(m),r(m);
  for(int i = 0;i < m; i++) cin >> l[i] >> r[i]; 
 
  // compute 
  int ans;
  sort(l.begin(), l.end() ,greater<int>());
  sort(r.begin(), r.end() );
  ans = max((r.at(0) - l.at(0) + 1),0);
  
  // output  
  cout << ans << endl;
  
}

Measured memory_bytes: 4032
#include <iostream> 
#include <sstream> 
#include <iomanip> 
#include <algorithm> 
#include <cmath> 
#include <string> 
#include <vector> 
#include <list> 
#include <queue> 
#include <stack> 
#include <set> 
#include <map> 
#include <bitset> 
#include <numeric> 
#include <climits> 
#include <cfloat> 
using namespace std;

class Point
{
public:
    double x, y, z;
    double length() const{
        return sqrt(x*x + y*y + z*z);
    }
    double dot(const Point& p) const{
        return (x*p.x + y*p.y + z*p.z) / (length() * p.length());
    }
};

int main()
{
    for(;;){
        int n;
        cin >> n;
        if(n == 0)
            return 0;

        vector<Point> s(n);
        for(int i=0; i<n; ++i)
            cin >> s[i].x >> s[i].y >> s[i].z;

        int m;
        cin >> m;

        vector<Point> t(m);
        vector<double> phi(m);
        for(int i=0; i<m; ++i)
            cin >> t[i].x >> t[i].y >> t[i].z >> phi[i];

        vector<bool> seen(n, false);
        for(int i=0; i<n; ++i){
            for(int j=0; j<m; ++j){
                double dot = s[i].dot(t[j]);
                double theta = acos(dot);
                if(theta < phi[j])
                    seen[i] = true;
            }
        }

        int ret = 0;
        for(int i=0; i<n; ++i){
            if(seen[i])
                ++ ret;
        }
        cout << ret << endl;
    }
}

Measured memory_bytes: 984
//Author- VMAX


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_multiset tree<long long , null_type,less_equal<long long >, rb_tree_tag,tree_order_statistics_node_update>
#define ordered_set tree<long long , null_type,less<long long >, rb_tree_tag,tree_order_statistics_node_update>
using namespace std;
#define ll long long int
#define YES cout<<"YES"<<"\n";
#define NO cout<<"NO"<<"\n";
#define ld     long double 
#define yes cout<<"yes"<<"\n";
#define no cout<<"no"<<"\n";
#define No cout<<"No"<<"\n";
#define Yes cout<<"Yes"<<"\n";
#define f(i,a) for(i=0;i<a;i++)
#define fo(i,a) for(i=1;i<=a;i++)
#define fa(i,a) for(auto i:a)
#define r(i,a) for(auto i=a.rbegin();i!=a.rend();i++)
#define en cout<<"\n";
#define ull unsigned long long int
#define o(x) cout<<x<<"\n";
#define o1(x) cout<<x<<" ";
#define pb push_back
#define F first
#define in insert
#define mp make_pair
#define S second
#define pre(n) cout<<fixed<<setprecision(n);
#define      gcd(a,b)    __gcd(a,b)
#define bs            binary_search
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define test ll t;cin>>t;while(t-->0)
const ll Mod = 998244353;
#define mod 1000000007
#define pi 3.14159265358979323846
#define all(x) x.begin(),x.end()
#define re return 0;
// *#######################################################################################*


int main()
{
    fast
    
  
    ll a,b,c,d;
    cin>>a>>b>>c>>d;
    
      double z=(double)(double(a)*double(b));
      pre(6)
      o1(z/2)
ll s=0;
         if(c+c==a&&d+d==b)
         {
             s=1;
         }
        
    o1(s)
    re
}

Measured memory_bytes: 3752
#include "bits/stdc++.h"
#pragma GCC optimize "03"
using namespace std;

#define int long long int
#define pb push_back
#define pii pair<int,int>
#define fi first
#define se second
#define rep(i,a,b) for (int i = a; i < b; ++i)
#define IOS ios::sync_with_stdio(false); cin.tie(NULL);
#ifndef LOCAL
#define dbg(...) ;
#define endl '\n'
#endif

const int inf = 1e15;
const int MOD = 1e9 + 7;
const int N = 2e5 + 5;



signed main(){
    IOS;
    int n, m;
    cin >> n >> m;
    int ans = min(n % m, m - n % m);
    cout << ans << endl;
    return 0;
}

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

using namespace std;

int main()
{
  int N, P[20000];
  int latte[200000], malta[200000];

  cin >> N;
  for(int i = 0; i < N; i++) cin >> P[i];
  for(int i = 0; i < N; i++) latte[i] = (i + 1) * 25000;
  for(int i = 0; i < N; i++) malta[i] = (N - i) * 25000;
  for(int i = 0; i < N; i++) latte[--P[i]] += i;
  for(int i = 0; i < N; i++) cout << latte[i] << " ";
  cout << endl;
  for(int i = 0; i < N; i++) cout << malta[i] << " ";
  cout << endl;
}


Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;

int main(){
    int n; cin >> n;
    string s; cin >> s;
    vi rnum(n+1),wnum(n+1);
    rnum.at(0) = wnum.at(0) = 0;
    for(int ix=0;ix<n;ix++){
        char tmp = s.at(ix);
        if(tmp == 'R'){
            rnum.at(ix+1) = rnum.at(ix) +1;
            wnum.at(ix+1) = wnum.at(ix);
        }
        else{
            wnum.at(ix+1) = wnum.at(ix) +1;
            rnum.at(ix+1) = rnum.at(ix);
        }
    }
    int ans=n+1;
    for(int ix=0;ix<n;ix++){
        ans = min(ans,max(wnum.at(ix),rnum.at(n)-rnum.at(ix+1)));
    }
    cout << ans << endl;
}

Measured memory_bytes: 5164
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,m;
	cin>>n>>m;
	int a[m+1];
	for(int i=0;i<m;i++){
		cin>>a[i];
		n-=a[i];
	}
	if(n<0){
		cout<<"-1";
	}else{
		cout<<n;
	}
	return 0;
} 

Measured memory_bytes: 3660
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define lli long long int
#define ulli unsigned long long int
#define ld long double
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define loop(i,a,b) for(lli i=a;i<b;i++)
#define initialize(array,size,value) for(lli i=0;i<size;i++) array[i]=value
#define couta(array,size) for(lli i=0;i<size;i++) cout<<array[i]<<" "
#define vl vector<lli>
#define vp vector< pair <lli,lli> >
#define sl set<lli>
#define msp multiset < pair < long long , long long > > S;
#define pll pair<lli, lli>
#define mll map<lli, lli>              //for( map<lli, lli>::iterator i=temp.begin();i!=temp.end();i++)cout<<i->fi<<" "<<i->se<<endl;
#define mvl map<lli, vl>
#define umll unordered_map<lli, lli>
#define vt vector<pair<lli, pll >  >
#define vf vector<pair<pll,pll > >
#define qu queue<lli>
#define pq priority_queue<lli>
#define dq deque <lli>
#define ptr vector<lli>::iterator
#define bs(array,x) binary_search(array.begin(),array.end(),x)
#define lb(array,x) lower_bound(array.begin(),array.end(),x)
#define ub(array,x) upper_bound(array.begin(),array.end(),x)
#define nobw(array,i,j) upper_bound(array.begin(), array.end(), j)-lower_bound(array.begin(), array.end(), i) //number of numbers between i & j
#define vc clear()
#define endl '\n'
#define sp system("pause");
#define INF 9223372036854775807
#define MINF -9223372036854775808
typedef tree<pll,null_type,less<pll>,rb_tree_tag,
tree_order_statistics_node_update> indexed_set;
int main()
{
 	ios::sync_with_stdio(0);
    cin.tie(0);
    lli H,W,h,w;
    cin>>H>>W>>h>>w;
    cout<<H*W-h*W-w*H+w*h;
    
    
    
	
	return 0;
}


Measured memory_bytes: 384
n,m = [int(i) for i in input().split()]
p = ['P']*n
k = ['I']*m
al = p+k
ans = 0
for i in range(len(al)):
    for j in range(i+1,len(al)):
        if al[i] == 'I' and al[j]=='I':ans+=1
        if al[i] == 'P' and al[j] == 'P': ans+=1
print(ans)

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

// 最小公倍数を求める
int euqlid (int a, int b){
  int temp;
  temp = a % b;
  if(temp == 0)return b;
  return euqlid(b,temp);
}
ll conbination(ll a,ll b){
  ll u = 1;
  ll d = 1;
  while(b != 0){
    u *= a;
    d *= b;
    a--;
    b--;
  }
  return u / d;
}
int fact(int n){
  if(n == 1)return 1;
  return n * fact(n-1);
  }

int main(){
  int a,b;
  cin >> a >> b;
  cout << (a-1)*(b-1) << endl;
}


Measured memory_bytes: 256
#include <stdio.h>

#include <algorithm>
#include <string>
#include <map>
#include <iostream>
#include <vector>
 
using namespace std;
 
int main(int argc, char** argv) {
  int n;
  cin >> n;
  map<string, int> ms;
  for (int i = 0; i < n; ++i) {
    string s;
    cin >> s;
    if (ms.find(s) != ms.end()) {
      ++ms[s];
    } else {
      ms.insert({s, 1});
    }
  }
  int mx = 0;
  vector<string> ans;
  for (auto m : ms) {
    if (m.second < mx)
      continue;
    if (m.second > mx) {
      ans.clear();
      mx = m.second;
      ans.push_back(m.first);
      continue;
    }
    if (m.second == mx) {
      ans.push_back(m.first);
    }
  }
  sort(ans.begin(), ans.end());
  for (auto ss: ans) {
    cout << ss << endl;
  }
  return 0;
}

Measured memory_bytes: 26868
n = int(input())
w = list(map(int,input().split()))
min = 10000000000
for i in range(n):
    a = sum(w[:i])
    b = sum(w[i:])
    #print(w[:i])
    #print(w[i:])
    if abs(a-b) <= min:
        min = abs(a-b)
print(min)

Measured memory_bytes: 3060
#include<cstdio>
#include<iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<queue>
#include<set>
#include<stack>
#include<cstring>
#include<map>
#include<vector>
#define ll long long int
using namespace std;
int main()
{
   string s;
   cin>>s;
   ll t;
    while((t=s.find("eraser"))!=s.npos)
   {
       s=s.replace(t,6,"");
   }
     while((t=s.find("erase"))!=s.npos)
   {
       s=s.replace(t,5,"");
   }
    while((t=s.find("dreamer"))!=s.npos)
   {
       s=s.replace(t,7,"");
   }
   while((t=s.find("dream"))!=s.npos)
   {
       s=s.replace(t,5,"");
   }
   if(s.length()==0)
    cout<<"YES";
   else
    cout<<"NO";
}


Measured memory_bytes: 640
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>

#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

#include <stdexcept>

using namespace std;

// type alias
using ll = long long;
using ull = unsigned long long;

//conversion
//------------------------------------------
inline int toint(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class t> inline string tostring(t x) { ostringstream sout; sout << x; return sout.str(); }

//debug
#define DUMP(x)  cerr << #x << " = " << (x) << endl
#define DEBUG(x) cerr << #x << " = " << (x) << " (l" << __line__ << ")" << " " << __file__ << endl

inline ll floor(ll a, ull b)
{
	ll llb = b;
	if (a >= 0)
	{
		return a / llb;
	}
	else
	{
		return - ( (-a + llb - 1) / llb);
	}
}

inline ll ceil(ll a, ull b)
{
	ll llb = b;
	if (a >= 0)
	{
		return (a + llb - 1) / llb;
	}
	else
	{
		return - (-a / llb);
	}
}

inline ll getLowestOneBit(ll a)
{
	return a & (-a);
}

inline ll getHighestOneBit(ll a)
{
	while ((a & (a - 1)) != 0)
	{
		a = a & (a - 1);
	}
	return a;
}

inline bool isPower2(ull a)
{
	if (a == 0)
	{
		return false;
	}
	return !(a & (a - 1));
}

inline ll getSpecifiedBit(ll a, unsigned bit)
{
	return (a & (1LL << bit)) >> bit;
}

// computational complexity: o(log(max(a, b))) 
inline ull getGcd(ull a, ull b)
{
	if (b == 0)
	{
		return a;
	}
	return getGcd(b, a % b);
}

template<class Integer>
inline Integer getPower(Integer base, ull exponential)
{
	Integer result = 1;
	while (exponential >= 1)
	{
		if (exponential & 1)
		{
			result = result * base;
		}
		base = base * base;
		exponential >>= 1;
	}

	return result;
}

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

	ll N;
	cin >> N;

	map<ll, ll> countA;
	ll a;
	for (ll i = 0; i < N; ++i)
	{
		cin >> a;
		if (countA.count(a) == 0)
		{
			countA[a] = 0;
		}
		++countA[a];
 	}

	if (countA.count(0) && countA[0] == N)
	{
		cout << "Yes" << endl;
		return 0;
	}

	if (N % 3 == 0)
	{
		ll num = N / 3;
		if (countA.count(0))
		{
			if (countA[0] == num)
			{
				for (auto iter = countA.begin(); iter != countA.end(); ++iter)
				{
					if (iter->first == 0)
					{
						continue;
					}
					if (iter->second == num * 2)
					{
						cout << "Yes" << endl;
						return 0;
					}
					break;
				}
			}
		}
		else
		{
			vector<ll> vals;
			for (auto iter = countA.begin(); iter != countA.end(); ++iter)
			{
				if (iter->second == num)
				{
					vals.emplace_back(iter->first);
					continue;
				}
				break;
			}
			if (vals.size() == 3)
			{
				if ((vals[0] ^ vals[1]) == vals[2])
				{
					cout << "Yes" << endl;
					return 0;
				}
			}
		}
	}

	cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 5120
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b;
    cin>>a>>b;
    if(a>b)
    {
        swap(a,b);
    }
    for(int i=0;i<b;i++)
    {
        cout<<a;
    }
    cout<<endl;
    return 0;
}


Measured memory_bytes: 3560
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll N,M,ans;
int main(){
  	cin>>N>>M;
    if(N>=M/2){
        cout<<M/2<<"\n";
        return 0;
    }
    cout<<(M+2*N)/4<<"\n";
    return 0;
}

Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);

        Problem solver = new Problem();
        solver.solve(0, in, out);
        out.close();
    }

    static class Problem {
        
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int N = in.nextInt();
            int[] stones = new int[N];
            for(int i = 0; i < N; i++)
                stones[i] = in.nextInt();

            int[] dp = new int[N];
            dp[0] = 0;
            dp[1] = Math.abs(stones[1] - stones[0]);

            for(int i = 2; i < N; i++) {
                int jump1 = Math.abs(stones[i] - stones[i - 1]) + dp[i - 1];
                int jump2 = Math.abs(stones[i] - stones[i - 2]) + dp[i - 2];
                dp[i] = Math.min(jump1, jump2);
            }

            out.println(dp[N - 1]);
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}



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


int main() {
    int A, B, C, K;
    cin >> A >> B >> C >> K;
    int cnt = 0;
    while (A >= B) {
        B *= 2;
        ++cnt;
    }
    while (B >= C) {
        C *= 2;
        ++cnt;
    }
    if (cnt <= K) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
bool bo[100];
#define ll long long int
int main()
{
	ll a,b,c;
	cin>>a>>b>>c;
	if(a+b==c || b+c==a || a+c==b)
	{
		cout<<"Yes"<<endl;
	}
	else
	{
		cout<<"No"<<endl;
	}
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> P;
const LL mod=1e9+7;
const LL LINF=1LL<<62;
const int INF=1<<17;

int main(){
    int N;
    cin >> N;
    LL A,B;
    cin >> A >> B;
    LL x[N];
    for(int i=0;i<N;i++){
        cin >> x[i];
    }
    LL ans=0;
    for(int i=0;i<N-1;i++){
        ans+=min((x[i+1]-x[i])*A,B);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <limits>
#include <climits>
#include <utility>
#include <algorithm>
#include <numeric>

using namespace std;

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

int main()
{
    int A, B, C, D, E, F;
    cin >> A >> B >> C >> D >> E >> F;

    double max_density = 0.0;
    int max_sugar = 0;
    int max_sugar_water = 100*A;

    for (int i = 0; i <= 30; ++i) {
        int ai = 100*A*i;
        if (ai > F) {
            continue;
        }

        for (int j = 0; j <= 30; ++j) {
            int bj = 100*B*j;
            double a = ai + bj;
            if (a > F) {
                continue;
            }

            for (int k = 0; k <= 3000; ++k) {
                int ck = C*k;
                if (a + ck > F) {
                    continue;
                }

                for (int l = 0; l <= 3000; ++l) {
                    if (i == 0 && j == 0 && k == 0 && l == 0) {
                        continue;
                    }

                    int dl = D*l;
                    double b = ck + dl;
                    if (a + b > F) {
                        continue;
                    }

                    double d = 100 * b / (a + b);

                    if (b > a / 100.0 * E) {
                        continue;
                    }

                    if (d > max_density) {
                        max_density = d;
                        max_sugar_water = a+b;
                        max_sugar = b;
                    }
                }
            }
        }
    }

    cout << max_sugar_water << ' ' << max_sugar << endl;

    return 0;
}


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

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef pair<ii, int> ri3;
#define mp make_pair
#define pb push_back
#define fi first
#define sc second
#define SZ(x) (int)(x).size()
#define ALL(x) begin(x), end(x) 
#define REP(i, n) for (int i = 0; i < n; ++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)

int main() {
    //freopen("in.txt", "r", stdin);
    ios::sync_with_stdio(false);
    cin.tie(0);

    int N, K; cin >> N >> K;
    if (2*K-1 > N) cout << -1;
    else {
        vector<int> a, b, c;
        FOR(i,N,K+N-1) a.push_back(i);
        FOR(i,K,N-1) a.push_back(i);
        for(int i = K+2*N-1; i >= K+N; i -= 2) b.push_back(i);
        for(int i = K+2*N-2; i >= K+N; i -= 2) b.push_back(i);
        RFOR(i,K+3*N-1,K+2*N) c.push_back(i);
        FOR(i,0,N-1){
            cout << a[i] << " " << b[i] << " " << c[i] << '\n';
        }
    }
}



Measured memory_bytes: 3576
N = int(input())
s = input()
t = input()
w = s+t
cnt = 0
if s == t and N <= len(s):
  print(len(s))
  exit()
elif s == t and N > len(s):
  print(len(s+t))
  exit()
cnt1 = 0
for i in range(len(s)):
  if s[-i-1:] == t[:i+1]:
    cnt = i+1
while len(w) > N and cnt > 0:
  t = t[1:]
  w = s + t
  cnt -= 1
print(len(w))

Measured memory_bytes: 3064
#include<iostream>
#include<cmath>

using namespace std;

double sign(double A){
    if(A==0) return 0;
    else return A/abs(A);
}

int main(){
    int a,b,c;
    cin >> a >> b >> c;
    
    if (sign(c-a)!=sign(c-b)){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
}

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

using namespace std;

#define S scanf
#define P printf
#define G getline
#define SZ size()
#define C clear()
#define B begin()
#define F front()
#define T top()
#define E end()
#define EM empty()
#define V vector
#define Q queue
#define DQ deque
#define PQ priority_queue
#define ST stack
#define FI first
#define SE second
#define PI acos(-1)
#define PS push
#define PP pop()
#define PSF push_front
#define PSB push_back
#define PPF pop_front()
#define PPB pop_back()
#define MP make_pair
#define LL long long int
#define ULL unsigned long long int
#define PII pair<int,int>
#define PSI pair<string,int>
#define PIS pair<int,string>
#define PLI pair<long long int,int>
#define PLL pair<long long int,long long int>
#define MII map<int,int>
#define MSI map<string,int>
#define MIS map<int,string>
#define MLI map<long long int,int>
#define FAST() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)





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




int time_cnt;
int ans[200005];
int node_mark[200005];
V<int>adj[200005];
PII discovery_time[200005];

void run_dfs(int node)
{
    if(discovery_time[node].FI)
    {
        return;
    }
    discovery_time[node].FI=++time_cnt;
    node_mark[time_cnt]=node;
    for(int i=0; i<adj[node].SZ; i++)
    {
        run_dfs(adj[node][i]);
    }
    discovery_time[node].SE=time_cnt;
}

int main()
{
    FAST();

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

    int i,n,q,x,y;
    cin >> n >> q;
    for(i=1; i<n; i++)
    {
        cin >> x >> y;
        adj[x].PSB(y);
        adj[y].PSB(x);
    }
    run_dfs(1);
    while(q--)
    {
        cin >> x >> y;
        ans[discovery_time[x].FI]+=y;
        ans[discovery_time[x].SE+1]-=y;
    }
    for(i=1; i<=n; i++)
    {
        ans[i]+=ans[i-1];
    }
    int res[n+2];
    for(i=1; i<=n; i++)
    {
        res[node_mark[i]]=ans[i];
    }
    for(i=1; i<=n; i++)
    {
        cout << res[i] << ' ';
    }
    return 0;
}


Measured memory_bytes: 25856
#include <bits/stdc++.h>
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define debug  freopen("in.txt","r",stdin),freopen("out.txt","w",stdout);
#define pb push_back
#define all(x) x.begin(),x.end()
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int maxn = 1e6+10;
const int maxM = 1e6+10;
const int inf = 0x3f3f3f3f;


int main(){
	// debug;
	ios;

	int x;cin>>x;
	if(x>=30) cout<<"Yes\n";
	else cout<<"No\n";

	
	return 0;
}


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

#define  ll         long long
#define  llu        unsigned long long
#define  mod        1000000007
#define  pi         ((2.0)*acos(0.0))
#define  pb         push_back
#define  pf         push_front
#define  eb         emplace_back
#define  mp         make_pair
#define  all(x)     (x).begin(),(x).end()
#define  X          first
#define  Y          second

/*loop*/
#define  fr(i,m,n)   for(ll i=m;i<n;++i)

/*output shortcuts*/
#define  nl         "\n"
#define  Yes        cout<<"Yes\n"
#define  yes        cout<<"yes\n"
#define  YES        cout<<"YES\n"
#define  No         cout<<"No\n"
#define  no         cout<<"no\n"
#define  NO         cout<<"NO\n"

using namespace std;
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    ll h,w,k=1,p=1;
    cin>>h>>w;
    char a[h][w];

    fr(i,0,h)
    fr(j,0,w)
    cin>>a[i][j];

    ll dp[h][w];
    dp[0][0]=0;

    fr(i,1,h) //1st column
    {
        if(a[i][0]=='#') k=0;
        dp[i][0]=k;
    }
    fr(i,1,w) //1st row
    {
        if(a[0][i]=='#') p=0;
        dp[0][i]=p;
    }

    fr(i,1,h)
    {
        fr(j,1,w)
        {
            if(a[i][j]=='#')
            {
                dp[i][j]=0; continue;
            }
            dp[i][j] = (dp[i-1][j]%mod) + (dp[i][j-1]%mod) ;
        }
    }
/*
    fr(i,0,h)
    { fr(j,0,w)
        cout<<dp[i][j]<<" ";
      cout<<nl;
    }
*/
    cout<<dp[h-1][w-1] % mod<<nl;
return 0;
}



Measured memory_bytes: 12296
n=int(input())
rmax=-10**10
rmin=10**10
lmax=-10**10
lmin=10**10
for i in range(n):
    xi,yi=map(int,input().split())
    rmax=max(rmax,xi+yi)
    rmin=min(rmin,xi+yi)
    lmax=max(lmax,xi-yi)
    lmin=min(lmin,xi-yi)
    
print(max(rmax-rmin,lmax-lmin))

    

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


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

int main () {
  int a,b,c;
  cin >> a >> b >> c;
  
  vector<int>vec = {a, b, c};
  sort(vec.begin(),vec.end());
  
  int s = vec.at(0), t = vec.at(1);
  cout << s+t ;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <algorithm>
#include <math.h>
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
#define INF 999999999
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

using llong = long long;
using namespace std;

int main(){
    string s;
    llong k;
    cin >> k >> s;
    llong sl=s.size();
    if(k>=sl) cout << s << endl;
    else{
        rep(i,k){
            cout << s[i];
        }
        cout << "..." << endl;
    }
}

Measured memory_bytes: 3620
#include <algorithm>
#include <cassert>
#include <cstdio>
#include <iostream>
#include <limits>
#include <random>
#include <utility>
#include <vector>

namespace procon {
class UnionFind {
private:
  struct nodeinfo {
    int par;
    int rank;
    nodeinfo(int par) : par(par), rank(0) {}
  };
  std::vector<nodeinfo> node;

public:
  UnionFind(int n) : node() {
    node.reserve(n);
    for (int i = 0; i < n; ++i) {
      node.push_back(nodeinfo(i));
    }
  }
  int root(int x) {
    if (node[x].par == x) {
      return x;
    }
    return node[x].par = root(node[x].par);
  }
  void unite(int x, int y) {
    x = root(x);
    y = root(y);
    if (x == y) {
      return;
    }
    if (node[x].rank < node[y].rank) {
      node[x].par = y;
    } else {
      node[y].par = x;
      if (node[x].rank == node[y].rank) {
        ++node[x].rank;
      }
    }
  }
  bool is_same_set(int x, int y) { return root(x) == root(y); }
};
}
  
int main(void) {
  int size, n_query;
  std::cin.read((char *)&size, sizeof(int));
  std::cin.read((char *)&n_query, sizeof(int));

  std::vector<uint64_t> query(n_query);
  std::cin.read((char *)query.data(), sizeof(uint64_t) * n_query);

  const int mask = (1 << 30) - 1;

  uint64_t res = 123456789;
  procon::UnionFind uf(size);
  for (uint64_t q : query) {
    const int com = q >> 60;
    const int x = (q >> 30) & mask;
    const int y = (q >> 0) & mask;
    assert(0 <= x && x < size);
    assert(0 <= y && y < size);
    if (com) {
      res = res * 17 + (uf.is_same_set(x, y) ? 1 : 0);
    } else {
      uf.unite(x, y);
    }
  }
  std::cout << res << std::endl;
  return 0;
}



Measured memory_bytes: 88812
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int w = sc.nextInt();
    int h = sc.nextInt();
    int x = sc.nextInt();
    int y = sc.nextInt();
    int r = sc.nextInt();

    if (y + r > h || y - r < 0 || x + r > w || x - r < 0) {
      System.out.println("No");
    } else {
      System.out.println("Yes");
    }
  }
}



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

ll solve() {
    vector<ll> A(5);
    for ( int i = 0; i < 5; i++ ) cin >> A[i];
    ll s = 0, mx = 0;
    for ( int i = 0; i < 5; i++ ) {
        s += (A[i]+10-1)/10*10;
        mx = max(mx, (10-A[i]%10)%10);
    }
    ll ans = s-mx;
    return ans;
}

int main() {
    auto ans = solve();
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 3624
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String n = sc.next();
		int ichinokurai = Integer.parseInt(n.substring(n.length()-1));
		if(ichinokurai ==2 ||ichinokurai ==4 ||ichinokurai ==5 ||
				ichinokurai ==7 ||ichinokurai ==9 ) {
			System.out.println("hon");
		}

		if(ichinokurai ==0 ||ichinokurai ==1 ||ichinokurai ==6 ||
				ichinokurai == 8 ) {
			System.out.println("pon");
		}

		if(ichinokurai ==3) {
			System.out.println("bon");
		}

	}
}

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

int main(){
  char b;
  cin >> b;
  if(b == 'A')cout << "T" << endl;
  else if(b == 'T')cout << "A" << endl;
  else if(b == 'C')cout << "G" << endl;
  else if(b == 'G')cout << "C" << endl;
  return 0;
}

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

int main(){

    size_t n;
    std::cin >> n;

    std::vector<size_t> p(n), q(n), v(n);

    for(auto&& e : p){
        std::cin >> e;
    }

    for(auto&& e : q){
        std::cin >> e;
    }

    std::iota(v.begin(), v.end(), 1);

    size_t a, b, cnt = 0;

    do{
        if(v == p) a = cnt;
        if(v == q) b = cnt;
        cnt++;
    }while(std::next_permutation(v.begin(), v.end()));

    std::cout << std::max(a, b) - std::min(a, b) << std::endl;

    return 0;
}


Measured memory_bytes: 256
/* Manish Pant - insider_pants */

#include <bits/stdc++.h>
using namespace std;
#ifndef ONLINE_JUDGE
    #include "debug.h"
#endif

#define F first
#define S second
#define endl "\n"
#define pb push_back
typedef long long ll;
typedef long double ldob;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

void fast()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}

const int N = 2e5 + 5;
vector<int> v(N);
vector<int> par(N, -1);
vector<bool> vis(N, 0);
vector<int> path;
int special;
ll n, k;

void dfs(int a)
{
    if(vis[v[a]])
    {
        special = v[a];
        return;
    }
    vis[a] = 1;
    path.pb(v[a]);
    par[v[a]] = a;
    dfs(v[a]);
}

void solve()
{
    path.pb(1);
    dfs(1);

    int len = path.size();
    int pos = -1;
    for(int i = 0; i < len; i++)
    {
        if(path[i] == special)
        {
            pos = i;
            break;
        }
    }

    // cout << special << endl;
    // cout << path << endl;

    int first = pos, second = len - pos;

    if(k <= first)
    {
        cout << path[k] << endl;
        return;
    }

    // cout << pos << ' ' <<first << ' ' << second << endl;

    k -= first;
    k %= second;
    // cout << k << endl;

    cout << path[k + first] << endl;
}

int main()
{
    fast();
    cin >> n >> k;
    for(int i = 1; i <= n; i++) cin >> v[i];
    solve();
}

Measured memory_bytes: 5876
#include <bits/stdc++.h>
#define INF 1e18
#define int long long
#define Rep(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) Rep(i, 0, n)
#define all(a) (a).begin(), (a).end()
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;
const int mod = 1000000007;

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

    int n;
    cin >> n;
    n++;
    vector<int> cnt(n, 0);
    Rep(i, 2, n)
    {
        int m = i;
        Rep(j, 2, n) while (m % j == 0) cnt[j]++, m /= j;
    }
    int ans = 0;
    rep(i, n) if (cnt[i] >= 74) ans++;
    rep(i, n) Rep(j, i + 1, n)
    {
        if (cnt[i] >= 14 && cnt[j] >= 4)
            ans++;
        if (cnt[i] >= 4 && cnt[j] >= 14)
            ans++;
        if (cnt[i] >= 24 && cnt[j] >= 2)
            ans++;
        if (cnt[i] >= 2 && cnt[j] >= 24)
            ans++;
    }
    rep(i, n) Rep(j, i + 1, n) Rep(k, j + 1, n)
    {
        if (cnt[i] >= 2 && cnt[j] >= 4 && cnt[k] >= 4)
            ans++;
        if (cnt[i] >= 4 && cnt[j] >= 2 && cnt[k] >= 4)
            ans++;
        if (cnt[i] >= 4 && cnt[j] >= 4 && cnt[k] >= 2)
            ans++;
    }
    cout << ans << endl;
}

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

using namespace std;

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

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

		if (bI < a[i] || i == 0)
			a[i] = bI;
	
		a[i + 1] = bI;
	}

	// 総和を求める
	int answer = 0;
	for (int i = 0; i < n; i++)
	{
		answer += a[i];
	}

	cout << answer;

	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <iterator>
#include <cassert>
#include <numeric>
#include <functional>
#include <time.h>
#pragma warning(disable:4996) 

typedef long long ll;
typedef unsigned long long ull;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF  9223300000000000000
#define LINF2 1223300000000000000
#define LINF3 1000000000000
#define INF 2140000000
const long long MOD = 1000000007;
//const long long MOD = 998244353;

using namespace std;


template<class T> class BIT   // 1-indexed (0 is not used)
{
private:
    int num;
    vector<T> bit;
public:
    BIT(int n):bit(vector<T>(n+1, 0)), num(n) {}

    T sum(int i) {   // sum of 1..i
        if (!i) return 0;
        return bit[i] + sum(i-(i&-i));
    }

    void add(int i, T x) {
        if (i > num) return;
        bit[i] += x;
        add(i+(i&-i), x);
    }

    int lower_bound(T x) {
        T res=0;
        int N=1;
        while(N<num) N*=2;
        int i;
        for(i=N/2; i>0; i/=2) {
            if(res+i<num && bit[res+i]<x) {
                x = x - bit[res +i];
                res = res + i;
            }
        }
        return res + 1;
    }
};

void solve()
{
    int n, Q;
    scanf("%d%d", &n, &Q);
    vector<int> c(n);
    int i;
    for (i = 0; i < n; i++) {
        scanf("%d", &c[i]); c[i]--;
    }
    vector<vector<pair<int, int> > > z(n);    // l->r,i
    for (i = 0; i < Q; i++) {
        int l, r;
        scanf("%d%d", &l, &r); l--;
        z[l].push_back(make_pair(r, i));
    }

    vector<int> table(n, -1);
    BIT<int> bit(n);

    vector<int> prev(n, -1), ne(n,-1);
    for (i = 0; i < n; i++) {
        if (table[c[i]] < 0) {
            table[c[i]] = i;
            bit.add(i+1, 1);
        }
        if (prev[c[i]] >= 0) {
            ne[prev[c[i]]] = i;
        }
        prev[c[i]] = i;
    }    

    vector<int> ans(Q);
    for (i = 0; i < n; i++) {
        vector<pair<int, int> >& v = z[i];
        int k;
        for (k=0; k<(int)v.size(); k++) {
            int rr=v[k].first;
            int id=v[k].second;
            ans[id]=bit.sum(rr);
        }
        assert(table[c[i]] >= 0);
        bit.add(i+1, -1);
        if (ne[i] < 0) {
            ;
        }
        else {
            bit.add(ne[i] + 1, 1);
        }
    }

    for (i = 0; i < Q; i++) {
        printf("%d\n", ans[i]);
    }
    return;
}

int main()
{
#if 1
    solve();
#else
    int T;
    scanf("%d", &T);
    int t;
    for (t = 0; t < T; t++) {
        //printf("Case #%d: ", t + 1);
        solve();
    }
#endif
    return 0;
}


Measured memory_bytes: 37084
#include <iostream>
#include <stdio.h>
#include <bits/stdc++.h>
#include <queue>
#include <math.h>
#include <bitset>
#define INF -1000000000000000000
#define N 1000000007
#define ll long long
using namespace std;

int main(){
    ll n;
    cin>>n;
    pair<ll,ll> p[n];
    for(ll i=0; i<n; i++){
        cin>>p[i].first>>p[i].second;
    }
    
    vector<ll> s,t;
    for(ll i=0; i<n; i++){
        ll a=p[i].first+p[i].second;
        s.push_back(a);
        ll b=p[i].first-p[i].second;
        t.push_back(b);
    }
    
    sort(s.begin(),s.end());
    sort(t.begin(),t.end());
    
    ll max=0;
    if(max<s[n-1]-s[0]) max=s[n-1]-s[0];
    if(max<t[n-1]-t[0]) max=t[n-1]-t[0];
    
    cout<<max<<endl;
}

Measured memory_bytes: 9768
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

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

    int n, k;
    cin >> n >> k;

    string s;
    cin >> s;

    int r = n - 1;
    for (int i = 0; i < n - 1; i++) {
        if (s[i] != s[i + 1]) r--;
    }

    cout << min(r + k * 2, n - 1) << endl;

    return 0;
}

Measured memory_bytes: 512
n = int(input())
x, y = map(int, input().split())
for _ in range(n - 1):
    nx, ny = map(int, input().split())
    mul = max((x + nx - 1) // nx, (y + ny - 1) // ny, 1)
    x = mul * nx
    y = mul * ny
print(x + y)

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

    return 0;

    
}


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

#define rep(i, a, b) for (int i = a; i < (int)(b); ++i)
#define rrep(i, a, b) for (int i = b - 1; i >= (int)(a); --i)

using namespace std;

using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;

double TH = 60 / 180.0 * M_PI;

struct Point {
    double x;
    double y;
    Point(double xx, double yy) : x(xx), y(yy) {}
    Point(const Point& p) {
        x = p.x;
        y = p.y;
    }
};

void print(const Point& p) {
    printf("%2.5f %2.5f\n", p.x, p.y);
}

void koch_curve(const Point& p1, const Point& p2, const int depth) {
    if (depth == 0) { return; }
    Point s((2 * p1.x + p2.x) / 3.0, (2 * p1.y + p2.y) / 3.0);
    Point t((p1.x + 2 * p2.x) / 3.0, (p1.y + 2 * p2.y) / 3.0);
    Point u((t.x - s.x) * cos(TH) - (t.y - s.y) * sin(TH) + s.x, (t.x - s.x) * sin(TH) + (t.y - s.y) * cos(TH) + s.y);

    koch_curve(p1, s, depth - 1);
    print(s);

    koch_curve(s, u, depth - 1);
    print(u);

    koch_curve(u, t, depth - 1);
    print(t);

    koch_curve(t, p2, depth - 1);
}

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

    print(Point(0.0, 0.0));
    koch_curve(Point(0.0, 0.0), Point(100.0, 0.0), n);
    print(Point(100.0, 0.0));

    return 0;
}


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

#define sz(x) int(x.size())
#define pii pair<int, int>
#define Task "abc"
#define For(i, a, b) for(int i = (a), _b = (b); i <= b; ++i)
#define Debug(X) cout << #X << " = " << X << '\n'
#define All(x) (x).begin(), (x).end()
#define mp make_pair

typedef unsigned long long ull;
typedef long long ll;

const int maxn = 1e5 + 10;
const int inf = 0x3f3f3f3f;
const ll mod = 1e9 + 7;

int n, m;
pair<int,int> br[maxn];
int root[maxn];
ll f[maxn];

int getroot(int u){
  return root[u] == u ? u : root[u] = getroot(root[u]);
}

int main(){
  ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0);
//  freopen(Task".inp", "r", stdin);
//  freopen(Task".out", "w", stdout);
  cin >> n >> m;
  for (int i = 0; i < m; ++i){
    int u, v; cin >> u >> v;
    br[i] = mp(u, v);
  }
  for (int i = 1; i <= n; ++i){
    root[i] = i; f[i] = 1;
  }
  ll al = 1ll * n * (n - 1) / 2;
  ll ans = 0;
  vector<ll> res;
  res.push_back(0);
  for (int i = m - 1; i > 0; --i){
    int u = br[i].first, v = br[i].second;
    int ru = getroot(u), rv = getroot(v);
    if (ru == rv){
      res.push_back(ans);
      continue;
    }
    ans -= f[rv] * (f[rv] - 1) / 2;
    ans -= f[ru] * (f[ru] - 1) / 2;
    f[ru] += f[rv]; f[rv] = 0;
    root[rv] = ru;
    ans += f[ru] * (f[ru] - 1) / 2;
    res.push_back(ans);
  }
  reverse(All(res));
  for (auto v : res) cout << al - v << '\n';
}



Measured memory_bytes: 4212
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define debug(x) cerr << #x << " : " << x << '\n'

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;
typedef string str;
typedef pair<ll, ll> pll;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

const ll Mod = 1000000007LL;
const int Maxn = 2e5 + 10;
const ll Inf = 2242545357980376863LL;
const ll Log = 30;

ll a[Maxn], p[Maxn];

int main(){
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	ll n;
	cin >> n;
	ll s = 0;
	for(int i = 1; i <= n; i++){
		cin >> a[i];
		p[i] = (a[i] >= 0);
		s += p[i];
	}
	if(s == n || s == 0){
		ll mn = 1000000;
		for(int i = 1; i <= n; i++) mn = min(mn, abs(a[i]));
		for(int i = 1; i <= n; i++){
			if(mn == abs(a[i])){
				p[i] = 1-p[i];
				break;
			}
			
		}
	}
	ll i0, i1;
	ll res = 0;
	for(int i = 1; i <= n; i++){
		if(p[i] == 1) i1 = i;
		else i0 = i;	
		res += (p[i] == 1 ? a[i] : -a[i]);
	}
	cout << res << '\n';
	for(int i = 1; i <= n; i++){
		if(i == i1 || i == i0) continue;
		if(p[i] == 1){
			cout << a[i0] << " " << a[i] << '\n';
			a[i0] -= a[i];
		}
		if(p[i] == 0){
			cout << a[i1] << " " << a[i] << '\n';
			a[i1] -= a[i];
		}
	}
	cout << a[i1] << " " << a[i0] << '\n';
	return 0;
}
/*
1
5 1
20 21 22 23 24

1
4 2 
1 2 3 4

2 4 1 3

*/


Measured memory_bytes: 3584
#include <cassert>

#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
//#include <boost/foreach.hpp>
//#include <boost/range/algorithm.hpp>
#define rep(i,j,k) for(int i=(int)j;i<(int)k;i++)
#define ll long long
#define Sort(v) sort(all(v))
#define INF 1000000000
#define END return 0
#define pb push_back
#define se second
#define fi first
#define pb push_back
#define all(v) (v).begin() , (v).end()
#define MP make_pair
#define MOD 1000000007LL
using namespace std;
int day[12]={31,28,31,30,31,30,31,31,30,31,30,31};

int main(){
    int num;
    scanf("%d", &num);

    int i = 1;
    while(true){
        if(i*i>num) break;
        i++;
    }
    cout << (i-1)*(i-1) << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<int,int> P;
const LL mod=998244353;
const LL LINF=1LL<<62;
const int INF=1<<20;


int main(){
    LL a,b;cin >> a >> b;
    a--;
    vector<LL> s(100,0LL);
    for (int i = 0; i < 50; i++) {
        LL t = (1LL<<(i+1));
        s[i]=(max(b%t-((t>>1)-1),0LL)+((t>>1)-max(a%t-((t>>1)-1),0LL)))%2;
        LL y =max(b%t-((t>>1)-1),0LL);
        LL x=((t>>1)-max(a%t-((t>>1)-1),0LL));
    }
    s[0]=((b%4+1)/2+(4-a%4)/2)%2;
    LL ans=0;
    for (int i = 0; i < 50; i++) {
        if(s[i]) ans+=(1LL<<i);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
import java.io.*;
import java.util.*;

public class Main{
	
	public static void main(String[] args){
	
	MyScanner sc = new MyScanner();
	out = new PrintWriter(new BufferedOutputStream(System.out));
	
	/**/
	
	String input = sc.next();
	
	if(input.equals("RSS")){
		System.out.println(1);
	}else if(input.equals("SRS")){
		System.out.println(1);
	}else if(input.equals("SSR")){
		System.out.println(1);
	}else if(input.equals("RRS")){
		System.out.println(2);
	}else if(input.equals("SRR")){
		System.out.println(2);
	}else if(input.equals("RSR")){
		System.out.println(1);
	}else if(input.equals("RRR")){
		System.out.println(3);
	}else{
		System.out.println(0);
	}
	  
	  
	/**/
	 
	 out.close();	
	}
	
	public static PrintWriter out;
	
	public static class MyScanner{
		
		BufferedReader br;
		StringTokenizer st;
		
		public MyScanner(){
			br = new BufferedReader(new InputStreamReader(System.in));
		}
		
		String next() {
          while (st == null || !st.hasMoreElements()) {
              try {
                  st = new StringTokenizer(br.readLine());
              } catch (IOException e) {
                  e.printStackTrace();
              }
          }
          return st.nextToken();
      }
 
      int nextInt() {
          return Integer.parseInt(next());
      }
 
      long nextLong() {
          return Long.parseLong(next());
      }
 
      double nextDouble() {
          return Double.parseDouble(next());
      }
 
      String nextLine(){
          String str = "";
	  try {
	     str = br.readLine();
	  } catch (IOException e) {
	     e.printStackTrace();
	  }
	  return str;
      }

   }
	
}


Measured memory_bytes: 32900
h1, m1, h2, m2, k = map(int, input().split())
h = h2 - h1
if m2 >= m1:
    m = m2 - m1
else:
    m = m2 + 60 - m1
    h -= 1
ans = h * 60 + m - k
if ans <= 0 :
    ans = 0
print(ans)


Measured memory_bytes: 9172
n = int(input())
a = list(map(int, input().split()))
num = 0
for i in a:
    if i%2 == 0:
        t = i
        z = 'YES'
        while z == 'YES':
            if t%2 == 0:
                num += 1
                t /= 2
            else:
                z == 'NO'
                break
print(num)

Measured memory_bytes: 10132