akhauriyash/Code-Regression huggingface dataset:
import sys
sys.setrecursionlimit(100000)
N,m,k = [int(x) for x in input().split()]
p = []
q = []
roots = [0]*(N+1)
rootmatome = [0]*(N+1)
tonari = [0]*(N+1)
dame = [0]*(N+1)
for i in range(m):
    p.append(list(map(int, input().split())))
for i in range(k):
    q.append(list(map(int, input().split())))
par = []
for i in range(N+1):
    par.append(i)
def root(x):
    if par[x] == x:
        return x
    par[x] = root(par[x])#この一文で早くなる
    return root(par[x])
def unite(x,y):
    rx = root(x)
    ry = root(y)
    if rx == ry:
        return
    par[rx] = ry
for i in range(m):
    unite(p[i][0],p[i][1])
for i in range(1,N+1):
  roots[i] = root(i)
for i in range(1,N+1):
    rootmatome[roots[i]] += 1
for i in range(m):
    tonari[p[i][0]] += 1
    tonari[p[i][1]] += 1
for i in range(k):
    if roots[q[i][0]] == roots[q[i][1]]:
        dame[q[i][0]] += 1
        dame[q[i][1]] += 1
for i in range(1,N+1):
    print(rootmatome[roots[i]] - tonari[i] - dame[i] - 1,end=" ")          

Measured memory_bytes: 86336
'use strict'

const main = input => {
	const args = input.split('\n').map(arg => arg.split(' '))
	const M = parseInt(args[0][0], 10)
	const D = parseInt(args[0][1], 10)
	let cnt = 0

	for (let m = 1; m <= M; m++) {
		for (let j = 1; j <= D; j++) {
			const d1 = j % 10
			const d10 = Math.floor(j / 10)

			if (d1 >= 2 && d10 >= 2 && (d1 * d10 === m)) {
				cnt++
			}
		}
	}

	console.log(cnt)
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'))


Measured memory_bytes: 22080
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
using namespace std;
int cl(int a, int b) {
	return (a - (a%b)) / b;//b=0だと積む
}
int up(int a, int b) {
	return cl(a + b - 1, b);//b=0だと積む
}
int main() {
	int a, b, n, k;
	cin >> n ;
	while(n!=0){
	int ch = 0; int ans = 0; 
	vector<int> x(n);
	vector<int> y(n);
	vector<int> z(n);
	for (int i = 0; i < n; i++) {
		cin >> x[i] >> y[i];
	}
	for (int i = 0; i < n; i++) {
		z[i]=x[i]+5001*y[i];
	}
	sort(z.begin(), z.end());
	for (int i = 0; i < n; i++) {
		x[i] = z[i] % 5001;
		y[i] = cl(z[i], 5001);
	}
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			int c, d, e,f; int si = 0; int ue = n - 1;
			if (y[i] + (x[j] - x[i]) >= 0 and 5000>= x[i] - (y[j] - y[i]) and x[i] - (y[j] - y[i]) >= 0) {
				c=y[i] + (x[j] - x[i]);
				d=x[i] - (y[j] - y[i]);
				e = c * 5001 + d;
				while (si < ue-1) {
					int na = cl(ue + si, 2);
					if (z[na] < e) {
						si = na;
					}
					else {
						ue = na;
					}
				}
				if (z[ue] == e or z[si] == e) {
					if (c + y[j] >= y[i] and 5000>=d + x[j]-x[i] and d + x[j] >= x[i]) {
						f = (c + y[j] - y[i]) * 5001 + (d + x[j] - x[i]);
						int si = 0; int ue = n - 1;
						while (si < ue - 1) {
							int na = cl(ue + si, 2);
							if (z[na] < f) {
								si = na;
							}
							else {
								ue = na;
							}
						}
						if (z[ue] == f or z[si] == f) {
							ans = max(ans, (x[j] - x[i])*(x[j] - x[i]) + (y[j] - y[i])*(y[j] - y[i]));
						}
					}
				}
			}
		}
	}
	cout << ans<<endl;
	cin >> n;
	}
}



Measured memory_bytes: 3196
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def TUPLE(): return tuple(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7 
#mod = 998244353
from decimal import *
#import numpy as np
#decimal.getcontext().prec = 10

N, M = MAP()
A = [0] + LIST()


A_acc = list(accumulate(A))
r = [a%M for a in A_acc]

ans = 0
for value in Counter(r).values():
	ans += value*(value-1)//2

print(ans)

Measured memory_bytes: 27640
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define REP(i,n) for (ll i = 0; i < (n); ++i)


int main(){
    string s;
    cin >> s;
    ll ans = 0;
    for(char c : s){
        ans += (c == '1');
    }
    cout << ans << endl;
    return 0;
}


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

#define         ll          long long int
#define         IO          ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

ll mx = 0;
ll val[22];
ll cost[22];
ll n;

void back_(ll at, ll x, ll y)
{
    mx = max(mx, x - y);
    if (at == n + 1)    return ;

    back_(at + 1, x + val[at], y + cost[at]);
    back_(at + 1, x, y);

    return ;
}

int main( )
{
    ll i, j;

    cin >> n;
    for (i = 1; i <= n; i++)
        cin >> val[i];
    for (i = 1; i <= n; i++)
        cin >> cost[i];

    back_(0, 0, 0);

    cout << mx << "\n";

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define fo(a,b) for(int a=0;a<b;a++)
 int wari(int a,int b) {
   if(a%b==0)
     return a/b;
   else
     return a/b+1;
 }
 int keta(int a){
  double b=a;
  b=log10(b);
  int c=b;
  return c+1;
 }
 int souwa(int a){
  return a*(a+1)/2;
 }
 int lcm(int a,int b){
  int d=a,e=b,f;
  if(a<b)
    swap(a,b);
  int c,m=1;
  while(m){
    c=a%b;
    if(c==0){
       f=b;
      m--;
    }
    else{
      a=b;
      b=c;
 }
  }
  return d*e/f;
    }
signed main(){
  int a,b,c,d,e;
  cin>>a>>b>>c>>d;
  e=lcm(c,d);
  //cout<<e<<endl;
  a--;
  int f,g,h,i;
  f=b/c-a/c;
  g=b/d-a/d;
  h=b/e-a/e;
  i=f+g-h;
  a++;
  cout<<b-a+1-i<<endl;
}


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

int main(){

  long n;
  cin >>n;
  long p[n];
  for(int i=0; i<n; i++) cin >> p[i];
  
  long minp=p[0];
  long count=0;
  for(long i=0; i<n; i++){
  	if(minp >= p[i]){ count++; minp=p[i];}
  }
  
  cout << count << endl;
  
}

Measured memory_bytes: 1920
let a, b, c = Scanf.scanf " %d %d %d" @@ fun a b c -> a, b, c
let p = if a > b then b * if a > c then c else a else a * if b > c then c else b
let _ = Printf.printf "%d\n" @@ if a * b mod 2 = 0 || c mod 2 = 0 then 0 else p

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
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; }
const ll INF = 1LL << 60;
const int MAX = 1000000010;
const ll MOD = 1000000007;
const double PI = acos(-1);

int main() {
    ll N, k; cin >> N >> k;
    map<ll, ll> m;
    for (int i = 0; i < N; i++) {
        ll a, b; cin >> a >> b;
        m[a] += b;
    }

    ll sum = 0;
    int ans = 0;
    for (auto p : m) {
        int a = p.first;
        ll b = p.second;
        sum += b;
        if (sum >= k) {
            ans = a;
            break;
        }
    }
    cout << ans << endl;
    return 0;
}

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

namespace _0556
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int k = int.Parse(Console.ReadLine());
            for (int i = 0; i < k; i++)
            {
                int[] x = Console.ReadLine().Split().Select(int.Parse).ToArray();
                int min = Math.Min(Math.Min(x[0] - 1, x[1] - 1), Math.Min(n - x[0], n - x[1]));
                Console.WriteLine(min % 3 + 1);
            }
        }
    }
}

Measured memory_bytes: 9764
n,k=map(int,input().split())
a=list(map(int,input().split()))
base=sum([x for x in a if x>0])
black=sum([-x for x in a[:k] if x<0])
white=sum([x for x in a[:k] if x>0])
ans=max(0,base-min(black,white))
for i in range(k,n):
  if a[i]>0:
    white+=a[i]
  else:
    black-=a[i]
  if a[i-k]>0:
    white-=a[i-k]
  else:
    black+=a[i-k]
  ans=max(ans,base-min(black,white))
  #print(black,white)
print(ans)


Measured memory_bytes: 20048
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    string s;
    cin>>s;
    if(s=="Sunny") cout<<"Cloudy"<<endl;
    if(s=="Cloudy") cout<<"Rainy"<<endl;
    if(s=="Rainy") cout<<"Sunny"<<endl;
}

Measured memory_bytes: 256
//
//  atcoder.cpp
//
//
///
#include <bits/stdc++.h>
#define REP(i, N) for(int i=0; i<N; i++)
using namespace std;

//#include "atcoder.hpp"

long long gcd(long long a, long long b) {
    if (a>b) swap(a,b);
    
    auto r = b % a;
    
    return (r ? gcd(r, a) : a);
}

int main() {
    long long N,  abcde[5];
    
    cin >> N >> abcde[0] >> abcde[1] >> abcde[2] >> abcde[3] >> abcde[4];
    long long least = 0LL, sum10 = 0LL;

    for (long long  i : abcde) {
        sum10 = (long long)ceil((double)(N) / (double)i);
        least = max(least, sum10);
    };
    
     
    cout << least - 1LL + 5LL << endl;

    return 0;
}



Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <iostream>

using namespace std;

const int INF = 0x3f3f3f3f;

int d[10][10];
int m;

void floyd() {
  for (int k = 0; k < m; ++k) {
    for (int i = 0; i < m; ++i) {
      for (int j = 0; j < m; ++j) {
        d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
      }
    }
  }
}


int main() {
  int i, j, a, b, c, n;
  while (scanf("%d", &n) != EOF && n) {
    memset(d, 0x3f, sizeof(d));
    m = 0;
    while (n--) {
      scanf("%d%d%d", &a, &b, &c);
      d[a][b] = d[b][a] = c;
      m = max(m, max(a + 1, b + 1));
    }
    floyd();
    int ans, p, tmp;
    p = 0;
    ans = INF;
    for (i = 0; i < m; ++i) {
      tmp = 0;
      for (j = 0; j < m; ++j) {
        if (i == j) continue;
        tmp += d[i][j];
        if (tmp >= INF) break;
      }
      if (tmp < ans) {
        ans = tmp;
        p = i;
      }
    }
    printf("%d %d\n", p, ans);
  }
  return 0;
}

Measured memory_bytes: 3084
#include <iostream>
#include <algorithm>
#include <vector>
#include <tuple>
#include <set>
using namespace std;
typedef long long ll;

int main(void){
    ll n;
    vector<pair<ll, ll>> v;
    cin >> n;
    for (int i = 0; i < n; i++) {
        ll a, b;
        cin >> a >> b;
        v.emplace_back(b, a);
    }
    sort(v.begin(), v.end());
    
    ll tmp = 0;
    for (int i = 0; i < n; i++) {
        tmp += v[i].second;
        if (tmp > v[i].first) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    
    
}


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

int main(){
  int N; 
  cin >> N;
  double A;  double sum = 0;
  for(int i = 0; i < N; i++){
    cin >> A;
    sum += 1.0/ A;
  }

  printf("%.7f", 1 / sum);
    
}

Measured memory_bytes: 256
import sys
import os
import math
import string

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: x * y / math.gcd(x, y)

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


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    A, B, K = il()
    print(max(0, A-K), max(0, B-(max(0,K-A))))


if __name__ == '__main__':
    main()


Measured memory_bytes: 3832
#include <iostream>
#include "bits/stdc++.h"
using namespace std;
#define print(x) cout<<x<<endl;
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define REP(i,a) for(ll i=0;i<a;i++)
#define jkl ll debug = 0;
#define RREP(i,a) for(ll i=a-1;i>=0;i--)
#define rrep(i,a,b) for(ll i=a-1;i>=b;i--)
#define printall(n,array) {for(ll i=0;i<n;i++){cout<<array[i]<<" ";}cout<<endl;}
#define U() cout<<endl;
#define mp make_pair
typedef long long ll;
typedef pair<ll, ll> Pi;
typedef pair<ll, Pi> V;
typedef vector<ll> VE;
const ll mod = 1e9 + 7; //10^9+7

ll a[52], p[52], b[52];

ll solve(ll level, ll res){
    ll ret = 0;
    if(a[level] == res)return p[level];
    if(res == 0)return 0;
    if(res <= a[level] / 2){
        ret = solve(level-1, res-1);
    }else if(res == a[level] / 2 + 1){
        ret = p[level-1] + 1;
    }else if(res > a[level] / 2 + 1){
        ret = p[level-1] + 1 + solve(level-1, res-a[level-1]-2);
    }
    return ret;
}

int main(){
    ll n, k;
    cin >> n >> k;
    a[0] = 1;
    p[0] = 1;
    b[0] = 0;
    rep(i, 1, n+1){
        a[i] = 2 * a[i-1] + 3;
        p[i] = 2 * p[i-1] + 1;
        b[i] = 2 * b[i-1] + 2;
    }
    ll level = 0;
    while(a[level] < k){level++;}
    print(solve(n, k));
}








Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<vector>
#include<algorithm>
using namespace std;
#define SZ(v) ((int)(v).size())
#define rep(i,n) for(int i=0;i<(n);i++)
#define foreach(it,c) for(__typeof(c.begin()) it=c.begin();it!=c.end();it++)
#define all(v) (v).begin(),(v).end()
typedef long long ll;
typedef unsigned uint;
const int INF=0x3f3f3f3f;
int inline in(){int x=0,c;for(;(uint)((c=getchar())-'0')>=10;)
{if(c=='-')return -in();if(!~c)throw ~0;}do{x=(x<<3)+(x<<1)+(c-'0');}
while((uint)((c=getchar())-'0')<10);return x;}
int n,k,s;
const int Maxs=1e9;
int main(){
	cin>>n>>k>>s;
	if(s==Maxs){
		for(int i=1;i<=k;i++){
			cout<<Maxs<<' ';
		}
		for(int i=k+1;i<=n;i++){
			cout<<1<<' ';
		}
		cout<<endl;
		return 0;
	}
	for(int i=1;i<=k;i++){
		cout<<s<<' ';
	}
	for(int i=k+1;i<=n;i++){
		cout<<Maxs<<' ';
	}
	cout<<endl;
	return 0;
}

Measured memory_bytes: 1280
n = gets.chomp.to_i

a = []
b = []

def el_count(ar)
  h = Hash.new(0)
  ar.each{|e| h[e] += 1}
  h
end

gets.chomp.split.map(&:to_i).each_with_index do |e, i|
  if i.even?
    a.push e
  else
    b.push e
  end
end

acount = el_count(a).sort_by{|k,v| v}
bcount = el_count(b).sort_by{|k,v| v}

if acount.last[0] != bcount.last[0]
  puts n - acount.last[1] - bcount.last[1]
else # same char
  if acount.length == 1
    puts n - acount.last[1]
  else
    puts n - acount.last[1] - [acount[-2][1], bcount[-2][1]].max
  end
end


Measured memory_bytes: 19344
while True:
    h, w = map(int, input().split())

    if h == 0 and w == 0:
        break

    for i in range(h):
        if i == 0 or i == h-1:
            print('#' * w)
        else:
            print('#', end='')
            print('.' * (w-2), end='')
            print('#')
    print()



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

using namespace std;



int main()
{
   ios_base::sync_with_stdio(false);
   cin.tie(NULL);cout.tie(NULL);
   
   int n;
   cin>>n;
   string s[n];
   int i,c1=0,c2=0,c3=0,c4=0;
   for(i=0;i<n;++i)
    {
        cin>>s[i];
        if(s[i]=="AC")
           c1++;
           
        else if(s[i]=="WA")
             c2++;
             
         else if(s[i]=="TLE")
             c3++;
             
         else
           c4++;
    }
    
    cout<<"AC "<<"x "<<c1<<endl;
    cout<<"WA "<<"x "<<c2<<endl;
    cout<<"TLE "<<"x "<<c3<<endl;
    cout<<"RE "<<"x "<<c4<<endl;
    
    
   
     return 0;
}

Measured memory_bytes: 6736
#include <bits/stdc++.h>
#include <math.h>
#define _USE_MATH_DEFINES
using namespace std;

typedef long long ll;

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

    string s;
    int k;

    cin >> k >> s;

    if (s.size() <= k) {
        cout << s << "\n";
    } else {
        cout << s.substr(0, k) << "..." << "\n";
    }
}


Measured memory_bytes: 3632
n = int(input())

words = []
for i in range(n):
  w = input()
  if i == 0:
    words.append(w)
    continue
  if w in words or w[0] != words[-1][-1]:
    print("No")
    break
  else:
    words.append(w)
  if i == n-1:
    print("Yes")

Measured memory_bytes: 3060
#include "bits/stdc++.h"
 
typedef long long ll;
using namespace std;
 
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
const int mod2 = 998244353 ;
const int mod = 1e9 + 7;
void io(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);    
    #ifdef LOCAL
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
        freopen("output.txt", "w", stderr);
    #endif
}
const int N = 1e6 + 5;

int main() {
	io();
	int n;
	cin >> n;
	int a[n];
	for(int i = 0; i < n; i++) {
		cin >> a[i];
		a[i] -= i + 1;

	}
	sort(a, a + n);
	ll sum = 0;
	if(n % 2) {
		for(int i = 0; i < n; i++) {
			sum += abs(a[i] - a[n / 2]);
		}
		cout << sum;
	}
	else {
		ll ans = 1e18;
		int x = a[n / 2] + a[(n / 2) - 1];
		x /= 2;
		for(int i = 0; i < n; i++) {
			sum += abs(a[i] - x);
		}	
		cout << sum;
	}

}



Measured memory_bytes: 1024
#define NDEBUG
NDEBUG


#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cstring>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <memory>
#include <queue>
#include <random>


using namespace std;

template<class T>
using vec = std::vector<T>;


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


#define all(c) c.begin(), c.end()


typedef int64_t i64;


// TC_REMOVE_BEGIN
/// caide keep
bool __hack = std::ios::sync_with_stdio(false);
/// caide keep
auto __hack1 = cin.tie(nullptr);
// TC_REMOVE_END


i64 parseInt64(const string& s) { return stoll(s); }


// Section with adoption of array and vector algorithms.


//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
//
//template <class T> using StdTree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;


template <class T>
inline bool get_bit(T mask, int bit) {
    assert(0 <= bit && bit < numeric_limits<T>::digits);
    return mask & ((T)(1) << bit);
}


namespace template_util {
    

    constexpr int bytecount(uint64_t x) {
        return x ? 1 + bytecount(x >> 8) : 0;
    }

    template<int N>
    struct bytetype {
        
    };

    
    /// caide keep
    template<uint64_t N>
    struct minimal_uint : bytetype<bytecount(N)> {
    };
}


template<class T>
T next(istream& in) {
    T ret;
    in >> ret;
    return ret;
}


void solve(istream& in, ostream& out) {
  auto s = next<string>(in);
  int gaps = (int)s.length() - 1;
  i64 sum = 0;//parseInt64(s);
  if (gaps) {
    vec<i64> tokens;
    FOR(mask, 1 << gaps) {
      string token;
      FOR(i, gaps) {
        token.push_back(s[i]);
        if (get_bit(mask, i)) {
          tokens.push_back(parseInt64(token));
          token.clear();
        }
      }
      token += s.back();
      tokens.push_back(parseInt64(token));
//      dbg(mask, tokens);
      sum += accumulate(all(tokens), 0LL);
      tokens.clear();
    }

  } else {
    sum = parseInt64(s);
  }

  out << sum << "\n";
}

//#include <fstream>


int main() {
//  ifstream fin("bridges.in");
//  ofstream fout("bridges.out");
    solve(cin, cout);
//  solve(fin, fout);
    return 0;
}



Measured memory_bytes: 256
import java.util.Scanner;

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

    int d = sc.nextInt();
    int t = sc.nextInt();
    int s = sc.nextInt();

    String result = "Yes";

    if(t*s<d) result = "No";

    System.out.print(result);
  }
}


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

typedef long long   signed int LL;
typedef long long unsigned int LU;

#define incID(i, l, r) for(int i = (l)    ; i <  (r); i++)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); i++)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); i--)
#define  inc(i, n) incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define  dec(i, n) decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)

#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))

#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define UB upper_bound
#define LB lower_bound
#define PQ priority_queue

#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
#define  FOR(it, v) for(auto it =  v.begin(); it !=  v.end(); ++it)
#define RFOR(it, v) for(auto it = v.rbegin(); it != v.rend(); ++it)

template<typename T> bool   setmin(T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool   setmax(T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

// ---- ----

string a, b, c;

int main() {
	cin >> a >> b >> c;	
	
	cout << ((a[a.size() - 1] == b[0] && b[b.size() - 1] == c[0]) ? "YES" : "NO") << endl;
	
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
using namespace std;
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(a) a.begin(),a.end()
#define rall(c) (c).rbegin(),(c).rend()
#define mp make_pair
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll inf=1e9+7;
const ll mod=998244353;
int main(){
    ll n,m;cin>>n>>m;
    cout<<(n+m)*(n+m-1)/2-n*m<<endl;
}

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

using namespace std;

int sX, sY;
int tX, tY;

void repeat(int k, char a)
{
	for(int i = 0 ; i < k ; i++)
		printf("%c",a);
}

int main()
{
	scanf("%d %d",&sX,&sY);
	scanf("%d %d",&tX,&tY);

	repeat( tX - sX , 'R' );
	repeat( tY - sY , 'U' );
	repeat( tX - sX , 'L' );
	repeat( tY - sY , 'D' );

	printf("D");

	repeat( tX - sX + 1 , 'R' );
	repeat( tY - sY + 1 , 'U' );

	printf("L");
	printf("U");

	repeat( tX - sX + 1 , 'L' );
	repeat( tY - sY + 1 , 'D' );

	printf("R");
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define mk make_pair
#define fs first
#define sc second
using namespace std;
typedef long long ll;
typedef long double ld;
int a[100010], b[100010];
struct pnt{
    int x, y;
    pnt(int f, int d){
        x=f;
        y=d;
    }
};
bool operator < (pnt x, pnt y){
    return x.x-y.y>y.x-x.y;
}
vector <pnt> v;
int main(){
    int n;
    while(cin>>n){
        ll ans=0;
        for(int i=0; i<n; ++i){
            scanf("%d%d",a+i,b+i);
            v.push_back(pnt(a[i],b[i]));
        }
        sort(v.begin(), v.end());
        for(int i=0; i<n; ++i){
            if(i%2==0){
                ans+=v[i].x;
            }
            else{
                ans-=v[i].y;
            }
        }
        cout<<ans<<endl;
    }
  return 0;
}




Measured memory_bytes: 1912
#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;
const int maxx=10010;
int pre[maxx];

int find(int x){
	if(pre[x]!=x) x=find(pre[x]);
	return x;
}

int main (){
	for(int i=0;i<maxx;i++) pre[i]=i;
	int n,m;
	cin>>n>>m;
	int com,x,y;
	while(m--){
		cin>>com>>x>>y;
		if(com==0) pre[find(x)]=find(y);
		else if(find(x)==find(y)) cout<<"1"<<endl;
		else cout<<"0"<<endl;
	}
	return 0;
}


Measured memory_bytes: 3152
#include <bits/stdc++.h>
using namespace std;
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  string s;
  cin >> n >> s;
  if (n & 1) return puts("No"), 0; 
  else
  {
    for (int i = 0; i < n/2; ++i)
    {
      if (s[i] != s[i+n/2])
        return puts("No"), 0;
    }
  }
  puts("Yes");

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using ll = long long;
#define int ll
using namespace std;
int N, K;
priority_queue<pair<int, int>> q;
signed main()
{
  cin >> N >> K;
  for (int i = 0; i < N; i++){
    int t, d;
    cin >> t >> d;
    q.push(make_pair(d, t));
  }
  vector<int> c(N + 1, 0);
  ll k = 0, res = 0;
  priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> mi;
  for (int i = 0; i < K; i++){
    auto x = q.top();
    q.pop();
    res += x.first;
    if (c[x.second] == 0){
      k++;
    }
    mi.push(x);
    c[x.second]++;
  }
  ll ma = res + k * k;
  for (int i = k + 1; i < K + 1; i++){
    while (c[mi.top().second] == 1) {
      mi.pop();
    }
    res -= mi.top().first;
    c[mi.top().second]--;
    mi.pop();
    while(!q.empty() && c[q.top().second]){
      q.pop();
    }
    if (q.empty()) {
      break;
    }
    res += q.top().first;
    c[q.top().second]++;
    q.pop();
    ma = max(ma, res + i * i);
  }
  cout << ma << endl;
}


Measured memory_bytes: 5616
#include <bits/stdc++.h>
#include<stdio.h>
int main(){
  int N,M,H[100000]={0};
  int goodH[100000]={0};
  scanf("%d %d",&N,&M);

  for(int i = 0; i < N;i++){
    scanf("%d",&(H[i]));
    goodH[i]=1;
  }
  
  for(int i=0;i<M;i++){
    int a,b;
    scanf("%d %d",&a,&b);
    --a;--b;
    
    if(H[a]>H[b])goodH[b]=0;
    if(H[a]<H[b])goodH[a]=0;
    if(H[a]==H[b]){
      goodH[a]=goodH[b]=0;
    }
  }
  
  int count=0;
  for(int i=0;i<N;i++)
    count+=goodH[i];
  printf("%d\n",count);
  
}

Measured memory_bytes: 4564
#include<stdio.h>
int main(){
  int data[101]={0};
  int i,n,max=0;
  while(scanf("%d",&n)!=EOF){
    data[n]=data[n]+1;
  }
  for(i=1;i<101;i++){
    if(max<data[i]){
      max=data[i];
    }
  }
  for(i=1;i<101;i++){
    if(max==data[i]){
      printf("%d\n",i); 
    }
  } 
  return(0);
}

Measured memory_bytes: 592
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1000005), 1000005)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func getNextUint64(scanner *bufio.Scanner) uint64 {
	i, _ := strconv.ParseUint(getNextString(scanner), 10, 64)
	return i
}

func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}

func main() {
	fp := os.Stdin
	wfp := os.Stdout
	cnt := 0

	if os.Getenv("MASPY") == "ますピ" {
		fp, _ = os.Open(os.Getenv("BEET_THE_HARMONY_OF_PERFECT"))
		cnt = 2
	}
	if os.Getenv("MASPYPY") == "ますピッピ" {
		wfp, _ = os.Create(os.Getenv("NGTKANA_IS_GENIUS10"))
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(wfp)
	solve(scanner, writer)
	for i := 0; i < cnt; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
	writer.Flush()
}

func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	s := getNextString(scanner)
	n := len(s)
	dp := make([]int, n+1)
	dig := 1
	for i := 0; i < n; i++ {
		dp[i+1] = mod(int(s[n-1-i]-'0')*dig + dp[i])
		dig = mod(dig * 10)
	}
	m := map[int]int{}
	for i := 0; i < n+1; i++ {
		m[dp[i]] = m[dp[i]] + 1
	}
	var ans int64
	for _, c := range m {
		ans += int64(c) * int64(c-1) >> 1
	}
	fmt.Fprintln(writer, ans)
}

func mod(x int) int {
	m := 2019

	return (x%m + m) % m
}


Measured memory_bytes: 4032
#include <vector>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>
#include <tuple>
#include <set>
#include <map>
#include <complex>
#include <iomanip>
#include <cmath>
using namespace std;
typedef long long ll;

ll cal(string s){
	ll ans=0;
	ans+=stoll(s);
	for(int i=1;i<(int)s.size();i++)
		ans+=stoll(s.substr(0,i))*(1<<s.size()-i-1)+cal(s.substr(i));
	return ans;
}

int main(){
  string s;
  cin >> s;
  cout << cal(s) << endl;
  return 0;
}

Measured memory_bytes: 256
using System;

class Program
{
    static void Main()
    {
      string[] sarr = Console.ReadLine().Split(" ",StringSplitOptions.RemoveEmptyEntries);
      
      int A = Int32.Parse(sarr[0]);
      int B = Int32.Parse(sarr[1]);
      
      Console.Write(A * B);
    }
}

Measured memory_bytes: 27548
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2")

using namespace std;

#define REP(i, N) for (int i = 0; i < (int)N; i++)
#define FOR(i, a, b) for (int i = a; i < (int)b; i++)
#define ALL(x) (x).begin(), (x).end()
#define INF (1 << 30)
#define LLINF (1LL << 62)
#define DEBUG(...) debug(__LINE__, ":" __VA_ARGS__)

namespace FastIO {
struct Strs {
  char strs[10000 * 4];
  constexpr Strs() : strs() {
    for (int i = 0; i < 10000; ++i) {
      int j = i;
      for (int t = 3; t >= 0; --t) {
        strs[i * 4 + t] = j % 10 + '0';
        j /= 10;
      }
    }
  }
} constexpr strs;
static constexpr size_t buf_size = 1 << 20;
char buf_in[buf_size], buf_out[buf_size];
size_t pt_in = 0, pt_out = 0, tail_in = 0;
inline size_t num_digits(long long x) {
  if (x >= (long long)1e9) return 10;
  if (x >= (long long)1e8) return 9;
  if (x >= (long long)1e7) return 8;
  if (x >= (long long)1e6) return 7;
  if (x >= (long long)1e5) return 6;
  if (x >= (long long)1e4) return 5;
  if (x >= (long long)1e3) return 4;
  if (x >= (long long)1e2) return 3;
  if (x >= (long long)1e1) return 2;
  return 1;
}
inline void load() {
  memcpy(buf_in, buf_in + pt_in, tail_in - pt_in);
  size_t width = tail_in - pt_in;
  tail_in = width + fread(buf_in + width, 1, buf_size - width, stdin);
  pt_in = 0;
}
inline void flush() {
  fwrite(buf_out, 1, pt_out, stdout);
  pt_out = 0;
}
inline void scan(char& c) { c = buf_in[pt_in++]; }
template <class T>
inline void scan(T& x) {
  if (pt_in + 32 > tail_in) load();
  char c;
  bool minus = 0;
  x = 0;
  scan(c);
  while (c >= '0') {
    x = x * 10 + (c & 15);
    scan(c);
  }
  if (minus) x = -x;
}
inline void print(char c) { buf_out[pt_out++] = c; }
template <class T>
inline void print(T x) {
  if (pt_out > buf_size - 32) flush();
  if (x < 0) {
    print('-');
    x = -x;
  }
  size_t digits = num_digits(x);
  int i;
  for (i = pt_out + digits - 4; i > (int)pt_out; i -= 4) {
    memcpy(buf_out + i, strs.strs + (x % 10000) * 4, 4);
    x /= 10000;
  }
  memcpy(buf_out + pt_out, strs.strs + x * 4 + (pt_out - i), 4 + i - pt_out);
  pt_out += digits;
}
inline void print(const char* s) {
  if (pt_out > buf_size - 32) flush();
  for (int i = 0; s[i] != 0; ++i) print(s[i]);
}
template <class T>
inline void println(T x) {
  print(x);
  print('\n');
}
struct SetUp {
  SetUp() { load(); }
  ~SetUp() { flush(); }
} setup;
}  // namespace FastIO

using FastIO::print;
using FastIO::println;
using FastIO::scan;

int main() {
  int N;
  scan(N);
  int mn1 = INF, mx1 = -INF, mn2 = INF, mx2 = -INF;
  REP(i, N) {
    int x, y;
    scan(x);
    scan(y);
    int a = x + y, b = x - y;
    mn1 = min(mn1, a);
    mx1 = max(mx1, a);
    mn2 = min(mn2, b);
    mx2 = max(mx2, b);
  }
  println(max(mx1 - mn1, mx2 - mn2));
  return 0;
}

Measured memory_bytes: 4704
s = input()
k = int(input())

l = [s[i:min(i+k,len(s))] for i in range(len(s))]

l.sort()

count = k
ll = []
flag = True

for x in l:
    if not flag:
        break
    else:
        for i in range(len(x)):
            tmp = x[:i+1]
            if tmp not in ll:
                count -= 1
                if count == 0:
                    print(x[:i+1])
                    flag = False
                else:
                    ll.append(tmp)
            else:
                pass

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

using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(int i=n; i>-1; --i)
#define ALL(a) (a).begin(),(a).end()
#define FILL(a,n,x); REP(i,(n)){ (a)[i]=(x); }
#define CINA(a,n); REP(i,(n)){ cin >> (a)[i]; }
#define FILL2(a,n,m,x); REP(i,(n)){ REP(j,(m)){(a)[i][j]=(x);} }
#define CINA2(a,n,m); REP(i,(n)){ REP(j,(m)){cin >> (a)[i][j];} }
#define Liny "Yes\n"
#define Linn "No\n"
#define LINY "YES\n"
#define LINN "NO\n"

#define umap unordered_map
//cout << setfill('0') << right << setw(4) << 12; // "0012"
int keta(ll x){ if(x<10){return 1;} else{return keta(x/10) + 1;}}
int keta_wa(ll x){ if(x<10){return x;} else{return keta_wa(x/10) + x%10;} }
int ctoi(char c){ return ( (c>='0' && c<='9')? c - '0': 0 );}
int __stoi(string s){ return atoi(s.c_str()); }
ll sum(ll a[],ll N){ return accumulate(a,a+N,0LL);}
ll gcd(ll a,ll b){if(a<b)swap(a,b); return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){if(a<b){swap(a,b);} return a/gcd(a,b)*b;}
template<class T> void chmax(T& a, T b){ if(a<b){a=b;} }
template<class T> void chmin(T& a, T b){ if(a>b){a=b;} }
const ll MOD = 1e9+7;

int main(){
    string s; cin>>s;
    int N = s.size();
    int num[N]; FILL(num,N,1);

    // 右方向に集める //RRxの場合xに送り込める //RLxの場合Rにとどまる
    for(int start=0;start<=1;++start){
        for(int i=start;i<N;i+=2){
            if(s[i]=='R'){
                if(i+1<N){
                    if(s[i+1]=='R'){
                        if(i+2<N){
                            num[i+2] += num[i];
                            num[i] = 0;
                        }else{
                            num[i+1] += num[i];
                            num[i] = 0;
                        }
                    } 
                }
            }
        }
    }
    // 左方向に集める //xLLの場合xに送り込める //xRLの場合Lにとどまる
    for(int start=N-1;start>=N-2;--start){
        for(int i=start;i>=0;i-=2){
            if(s[i]=='L'){
                if(i-1>=0){
                    if(s[i-1]=='L'){
                        if(i-2>=0){
                            num[i-2] += num[i];
                            num[i] = 0;
                        }else{
                            num[i-1] += num[i];
                            num[i] = 0;
                        }   
                    }   
                }   
            }   
        }
    }

    
    REP(i,N){
        if(i<N-1){ printf("%d ",num[i]);}
        else{ printf("%d\n",num[i]); }
    }
    
    
}


Measured memory_bytes: 1024
extern crate core;

use std::io::{self, Read};

#[macro_export]
macro_rules! input {
  ($s:expr=>$($t:tt)*) => {
    let mut lines=$s.split("\n");
    $(
        line_parse!(lines,$t);
    )*
  };
}

macro_rules! line_parse {
  ($lines:expr,($($name:ident:$t:tt)*)) => {
    let mut line=$lines.next().unwrap().split_whitespace();
    $(value_def!(line,$name,$t);)*
  };

  //複数行
  ($lines:expr,{$n:expr;$name:ident:$t:tt}) => {
    values_def!($lines,$n,$name,$t);
  };
}

macro_rules! value_def {
    ($line:expr, $name:ident, $t:tt) => {
        let $name = value!($line, $t);
    };
}

macro_rules! values_def {
    ($lines:expr, $n:expr, $name:ident, $t:tt) => {
        let $name = {
            let mut vec = Vec::new();
            for i in 0..$n {
                let mut next = $lines.next().unwrap().split_whitespace();
                vec.push(value!(next, $t));
            }
            vec
        };
    };
}

macro_rules! value {
  //配列
  ($line:expr,[$t:tt]) => {
    $line.map(|x|{
      let mut iter=::std::iter::once(x);
      value!(iter,$t)
    }).collect::<Vec<_>>()
  };
  //タプル
  ($line:expr,($($t:tt),*)) => {
    ($(value!($line,$t),)*)
  };
  //文字列
  ($line:expr,#) => {
    $line.next().unwrap()
  };
  //単一値
  ($line:expr,$t:ty) => {
    $line.next().unwrap().parse::<$t>().unwrap()
  };
  //インデックス(-1)
  ($line:expr,@) => {
    $line.next().unwrap().parse::<usize>().unwrap()-1
  };
}

fn main() {
    let mut input = String::new();
    io::stdin().read_to_string(&mut input).unwrap();
    let output = solve(input.trim().to_string());
    println!("{}", output);
}

fn solve(input: String) -> String {
    input!(input=>(n:i64));
    if n == 0 {
        "0".to_string()
    } else {
        /*let mut decimal = n;
        let mut binary = String::new();
        let mut base = 1;
        while decimal > 0 {
            binary.push_str(&((decimal % 2) * base).to_string());
            decimal = decimal / 2;
            base *= 10;
        }*/

        let mut n = n;
        let mut s = Vec::new();
        while n != 0 {
            if n % 2 == 0 {
                s.push('0');
                n = n / -2;
            } else {
                s.push('1');
                n = (n - 1) / -2;
            }
        }

        s.reverse();
        s.into_iter().collect::<String>()
    }
}

macro_rules! tests {
    ($($name:ident: $input:expr=>$output:expr,)*) => {
        mod tests {
            $(
                #[test]
                fn $name() {
                    assert_eq!($output.trim().to_string(),super::solve($input.trim().to_string()));
                }
            )*
        }
    }
}

tests! {
    test1: "-9" => "1011",
    test2: "123456789" => "11000101011001101110100010101",
    test3: "0" => "0",
}


Measured memory_bytes: 4352
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>


using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e16;
const ll MOD = 1e9 + 7;

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




int main() {
    ll n;
    cin >> n;
    
    vector<ll> a(n);
    REP(i, n){
        cin >> a[i];
    }
    
    if(a[0] > 0){
        cout << -1 << endl;
        return 0;
    }
    
    ll ans = 0;
    for(int i = 1; i < n; i++){
        if(a[i] <= a[i - 1] + 1){
            if(a[i] != a[i - 1] + 1){
                ans += a[i];
            }
            else{
                ans++;
            }
        }
        else{
            cout << -1 << endl;
            return 0;
        }
    }
    
    cout << ans << endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
const int INF=1145141919,MOD=1e9+7;
const long long LINF=8931145141919364364,LMOD=998244353;
inline long long mod(long long n,long long m){return(n%m+m)%m;}
// const int dx[]={1,0,-1,0,1,1,-1,-1},dy[]={0,-1,0,1,1,-1,-1,1};

long long dp[200010];
long long cnt[200010];
int main(){
    int n; cin>>n;
    vector<int> c;
    int t; cin>>t; c.push_back(t);
    rep(i,n-1){
        int cc; cin>>cc;
        if(c.back()!=cc) c.push_back(cc);
    }
    n=c.size();
    dp[0]=1;
    for(int i=1;i<=n;i++){
        dp[i]+=dp[i-1];
        dp[i]+=cnt[c[i-1]];
        dp[i]%=MOD;
        cnt[c[i-1]]+=dp[i-1];
        cnt[c[i-1]]%=MOD;
    }
    cout<<dp[n]%MOD<<endl;
    return 0;
}


Measured memory_bytes: 4340
#define _USE_MATH_DEFINES

#include <cstdio>
#include <cstdlib>
#include <string.h>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>

using namespace std;

typedef pair<long long int, long long int> P;
long long int INF = 1e18;
long long int MOD = 1000000007;

using namespace std;

#define MAX_V 120000
#define MAX_E 220000

int par[MAX_V];
int rnk[MAX_V];

// n要素で初期化
void init(int n){
	for(int i = 0; i < n; i++){
		par[i] = i;
		rnk[i] = 0;
	}
}

// 木の根を求める
int find(int x){
	if(par[x] == x){
		return x;
	}
	return par[x] = find(par[x]);
}

// xとyの属する集合を併合
void unite(int x, int y){
	int x_par = find(x);
	int y_par = find(y);
	if(x_par == y_par){
		return;
	}
	
	if(rnk[x_par] < rnk[y_par]){
		par[x_par] = y_par;
	}else{
		par[y_par] = x_par;
		if(rnk[x_par] == rnk[y_par]){
			rnk[x_par]++;
		}
	}
}

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

struct edge{
	int u, v;
	long long int cost;
};

bool comp(const edge& e1, const edge& e2){
	return e1.cost < e2.cost;
}

vector<edge> es;
int V, E;

long long int kruskal(){
	sort(es.begin(), es.end(), comp);
	init(V);
	int res = 0;
	int cnt = 0;
	for(int i = 0; i < es.size(); i++){
		edge e = es[i];
		if(!same(e.u, e.v)){
			cnt++;
			unite(e.u, e.v);
			res += e.cost;
		}
	}
	if(cnt < V - 1){
		return INF;
	}
	return res;
}

int main(){
	
	cin >> V >> E;
	
	for(int i = 0; i < E; i++){
		long long int u, v, cost;
		cin >> u >> v >> cost;
		
		edge e;
		e.cost = cost;
		e.v = v;
		e.u = u;
		es.push_back(e);
		e.v = u;
		e.u = v;
		es.push_back(e);
	}
	
	int ans = kruskal();
	
	cout << ans << endl;
	
	return 0;
}


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

using namespace std;

vector<int> common;
vector<int> dp;
int main() {
  int n, k, c=1, maxsofar=0;
  string s;
  cin >> n >> k >> s;
  if(s.at(0)=='0') common.push_back(0);
  for(int a=0; a<s.size()-1; a++) {
    if(s.at(a)!=s.at(a+1)) {
        common.push_back(c);
        c=1;
    }
    else c++;
  }
  common.push_back(c);
  if(s.at(s.size()-1)=='0') common.push_back(0);
  int t = 2*k+1;
  dp.push_back(0);
  for(int a=0; a<t; a++) {
    if(a<common.size())
        dp[0]+=common[a];
  }
  maxsofar=dp[0];
  for(int a=1; a<((int)common.size()-t+1); a++) {
    dp.push_back(dp[a-1]+common[a+t-1]-common[a-1]);
    if(a%2==0)
        maxsofar=max(maxsofar, dp[a]);
  }
  cout << maxsofar;
}


Measured memory_bytes: 1528
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
using ll = long long;
const int INF = 2147483647;
const ll MOD = 1000000007;
// const ll INF = 1000000000000000000LL;

int main(){
    // 入力
    int n,m,k;
    cin >> n >> m >> k;
    vector<ll> a(n);
    vector<ll> b(m);
    rep(i,n) cin >> a[i];
    rep(i,m) cin >> b[i];
    //累積和 
    vector<ll> A(n+1);
    vector<ll> B(m+1);
    for(int i=1;i<=n;i++) A[i] = A[i-1]+a[i-1];
    for(int i=1;i<=m;i++) B[i] = B[i-1]+b[i-1];
    //aを何冊か決め売って、二分探索より
    //読めるbの数を求める
    int ans=0; 
    rep(i,n+1){
        int cnt=0;
        cnt = i;
        ll rm = k-A[i];
        if(rm<0) continue;
        //rmをB[i]で二分
        cnt+=upper_bound(B.begin(),B.end()
        ,rm) - B.begin()-1;
        ans = max(ans,cnt);
    }
    cout << ans << endl;
	return 0;
}

Measured memory_bytes: 9596
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools
import time,random
from decimal import *

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
mod2 = 998244353
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def pe(s): return print(str(s), file=sys.stderr)
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)


def main():
    a = LI()
    t = []
    getcontext().prec = 128
    for c in a:
        t.append(Decimal(c) ** Decimal('0.5'))
    if t[0]+t[1] < t[2]:
        return "Yes"

    return "No"


print(main())





Measured memory_bytes: 5460
#include <bits/stdc++.h>
using namespace std;
#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 rev(i, n) for(int i = (int)(n - 1); i >= 0; i--)
#define rev1(i, n) for(int i = (int)(n); i > 0; i--)
#define pb push_back
#define all(v) (v).begin(), (v).end()
using ll = long long;
using P = pair<int, int>;
/* ------------------------------------------------ */
ll fact(int i) {       //階乗
    if (i == 0) return 1;
    return (fact(i - 1)) * i;
}
ll gcd(ll a, ll b) {        //最大公約数
    if(b == 0) return a;
    return gcd(b, a % b); 
}
ll lcm(ll a, ll b) {      //最小公倍数
    return a * b / gcd(a, b);
}
int keta(ll n) {        //桁数を求める
    if(n == 0) return 1;
    int count = 0;
    while(n != 0) {
        n /= 10;
        count++;
    }
    return count;
}
ll ketasum(ll n) {    //各桁の和
    ll sum = 0;
    while(n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
/* ------------------------------------------------ */

int main() {
    int n, k;
    cin >> n >> k;
    if(n < k) k = n;
    vector<int> h(n);
    ll count = 0;
    rep(i, n) {
        cin >> h[i];
        count += h[i];
    }
    // cout << count << endl;
    sort(all(h));
    reverse(all(h));
    rep(i, k) count -= h[i];
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 4044
input_data = []
m=0
while 1:
	a,b = input().split()

	if int(a) == 0 and int(b) == 0:
		break
	

	elif int(a) <= int(b) :
		m+=1
		input_data.extend([a,b])
	else :
		m+=1
		input_data.extend([b,a])

n=0
			
for i in range(m):
	print(input_data[n],input_data[n+1])
	n+=2

Measured memory_bytes: 8184
#include<stdio.h>
#include<string.h>
int main(void){
int N,T;
char S[10001];
scanf("%d%s", &N, S);
for(int i=0; i<strlen(S); i++){
T=S[i]-'A';
T = (T+N) % 26;
S[i]='A'+T;
}
printf("%s\n", S);
return 0;
}

Measured memory_bytes: 128
macro_rules !input {(source =$s :expr ,$($r :tt ) *) =>{let mut iter =$s .split_whitespace () ;let mut next =||{iter .next () .unwrap () } ;input_inner !{next ,$($r ) *} } ;($($r :tt ) *) =>{let stdin =std ::io ::stdin () ;let mut bytes =std ::io ::Read ::bytes (std ::io ::BufReader ::new (stdin .lock () ) ) ;let mut next =move ||->String {bytes .by_ref () .map (|r |r .unwrap () as char ) .skip_while (|c |c .is_whitespace () ) .take_while (|c |!c .is_whitespace () ) .collect () } ;input_inner !{next ,$($r ) *} } ;}
macro_rules !input_inner {($next :expr ) =>{} ;($next :expr ,) =>{} ;($next :expr ,$var :ident :$t :tt $($r :tt ) *) =>{let $var =read_value !($next ,$t ) ;input_inner !{$next $($r ) *} } ;}
macro_rules !read_value {($next :expr ,($($t :tt ) ,*) ) =>{($(read_value !($next ,$t ) ) ,*) } ;($next :expr ,[$t :tt ;$len :expr ] ) =>{(0 ..$len ) .map (|_ |read_value !($next ,$t ) ) .collect ::<Vec <_ >>() } ;($next :expr ,chars ) =>{read_value !($next ,String ) .chars () .collect ::<Vec <char >>() } ;($next :expr ,usize1 ) =>{read_value !($next ,usize ) -1 } ;($next :expr ,$t :ty ) =>{$next () .parse ::<$t >() .expect ("Parse error" ) } ;}

fn main() {
   input! {
      n: usize,
      _x: [usize; n]
   }
   let mut x: Vec<_> = _x.iter().enumerate().map(|(i, &x)| (x, i)).collect();
   x.sort();
   let mut num = vec![0; n];
   for (j, &(_, i)) in x.iter().enumerate() {
      num[i] = j;
   }
   for i in num {
      if i < n / 2 {
         println!("{}", x[n / 2].0);
      } else {
         println!("{}", x[n / 2 - 1].0);
      }
   }
}


Measured memory_bytes: 16508
object Main{
  def main(args: Array[String]){
    if (sys.env.getOrElse("TEST", "")=="1"){
      println(test());
    }else{
      val input=io.Source.stdin.getLines().mkString("\n");
      println(solve(input).trim());
    }
  }

  def solve(input:String):String={
    if(input.split(' ').map(_.toInt).product % 2 == 1) "Odd" else "Even"
  }

  val tests=List("""3 4""" -> """Even""",
    """1 21""" -> """Odd""");

  def test():String= {
    return tests.map{case (i,o)=>(i.trim(),o.trim())}
      .zipWithIndex.map{
      case ((input,outputExpect),i)=>{
        val output=solve(input).trim();
        s"test${i+1}:"+(if(output==outputExpect){
          "Passed"
        }else{
          s"Failed\nexpect:\n${outputExpect}\noutput:\n${output}"
        })
      }}
      .mkString("\n");
  }
}

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

public class Main {

	public static void main(String[] args) {
       
        Scanner sc = new Scanner(System.in);
        String hoge = sc.next();
        int count = 0;
        for(int i = 0; i < hoge.length(); i++){
            if((i + 1) % 2 != 0){
                if(hoge.charAt(i) != 'R' && hoge.charAt(i) != 'U' && hoge.charAt(i) != 'D'){
                    count++;
                }
            }else{
                if(hoge.charAt(i) != 'L' && hoge.charAt(i) != 'U' && hoge.charAt(i) != 'D'){
                    count++;
                }
            }
        }
        if(count == 0){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
    }     
}

Measured memory_bytes: 23252