akhauriyash/Code-Regression huggingface dataset:
#include"bits/stdc++.h"
using namespace std;
int main(){
	string a,b,c;
	cin>>a>>b>>c;
	vector<string> x{a,b,c};
	sort(x.rbegin(),x.rend());
	string d="",e=x[2];
	d+=x[0]+x[1];
	cout<<stoi(d)+stoi(e);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll MOD = 1e9 + 7;

template <class T>
T ModuloInverse(T a, T m) {
  T b = m, x = 1, y = 0;
  while (b) {
    T t = a / b;
    a -= t * b;
    x -= t * y;
    std::swap(a, b);
    std::swap(x, y);
  }
  return (m + x % m) % m;
}

ll c(ll n, ll k) {
  ll a = 1, b = 1;
  for (ll i = 0; i < k; i++) {
    a = a * (n - i) % MOD;
    b = b * (i + 1) % MOD;
  }
  return a * ModuloInverse(b, MOD) % MOD;
}

int main() {
  int n, a, b;
  cin >> n >> a >> b;

  ll p = 1;
  for (int i = 0; i < n; i += 32) p = (p << min(32, n - i)) % MOD;
  p = (MOD + p - c(n, a)) % MOD;
  p = (MOD + p - c(n, b)) % MOD;
  p = (MOD + p - 1) % MOD;
  cout << p << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;
 
class Main{
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int m = sc.nextInt();
    int num[] = new int[n];
    for(int i = 0; i < n; i++){
      num[i] = -1;
    }
    for(int i = 0; i < m; i++){
      int s = sc.nextInt()-1;
      int c = sc.nextInt();
      if((s==0&&c==0&&n!=1)||(num[s] != -1&&num[s] != c)){
        System.out.println(-1);
        return;
      } else {
        num[s] = c;
      }
    }
    int ans = 0;
    int ten = 1;
    for(int i = n-1; i >= 0; i--){   
      if(num[i]==-1){
        if(n>1&&i==0){
          num[i]=1;
        } else {
          num[i]=0;
        }
      }
      ans += num[i]*ten;
      ten*=10;
    }
    System.out.println(ans);
  }
}

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

#define ll long long
#define pii pair<int, int>
#define INF 1e18
#define REP(i, n) for (int i=0; i<n; i++)
#define FOR(i, a, b) for (int i=a; i<b; i++)
#define REPD(i, n) for (int i=n-1; i>=0; i--)
#define FORD(i, a, b) for (int i=a; i>=b; i--)
#define vi vector<int>
#define all(v) v.begin(), v.end()
#define print(x) cout << x << endl
#define debug(x) cout << #x << " = "<< x << endl

const double PI=3.141592653589793238462643383279502884197169399375105820974944;

using namespace std;

void solve() {
    int N;
    cin >> N;
    float sum = 0;
    REP(i, N) {
        float A;
        cin >> A;
        sum += 1 / A;
    }
    float ans = 1 / sum;
    cout << fixed << setprecision(10);
    print(ans);

}

signed main() {
    solve();
}


Measured memory_bytes: 256
def solve(sx, sy, tx, ty):
    way1 = "R" * (tx - sx) + "U" * (ty - sy)
    way2 = "L" * (tx - sx) + "D" * (ty - sy)
    way3 = "D" + "R" * (tx - sx + 1) + "U" * (ty - sy+ 1) + "L"
    way4 = "U" + "L" * (tx - sx + 1) + "D" * (ty - sy+ 1) + "R"
    return way1 + way2 + way3 + way4

if __name__ == "__main__":
    sx, sy, tx, ty = map(int, input().split(" "))
    print(solve(sx, sy, tx, ty))


Measured memory_bytes: 3060
#include "bits/stdc++.h"
using namespace std;
int main(void){
  string ans;
  int n[2];
  cin >> n[0] >>n[1];
  for (int i=0;i<2;i++){
    if (n[i] == 1)
      n[i] = 50;
  }
  if (n[0]>n[1])
    ans = "Alice";
  else if (n[0]<n[1])
    ans = "Bob";
  else
    ans = "Draw";
  cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		long sum = 0;
		long tmp = 0;
		
		while(stdIn.hasNext()){
			String a = stdIn.nextLine();
			char[] b = new char[100];
			b = a.toCharArray();
			tmp = 0;
			for(int i=0;i<b.length;i++){
				if(b[i]>='0'&&b[i]<='9'){
					tmp*=10;
					tmp+=b[i]-'0';
				}
				else{
					sum+=tmp;
					tmp=0;
				}
			}
			sum+=tmp;
		}
		System.out.println(sum);
	}
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(int)(n); i++)

using namespace std;
typedef long long LL;
const LL mod=1000000007;

LL modinv(LL x){
	LL m=mod, u=1, v=0;
	while(m){
		LL t=x/m;
		x-=t*m; swap(x,m);
		u-=t*v; swap(u,v);
	}
	u%=mod;
	if(u<0) u+=mod;
	return u;
}

LL modfac(LL n){
	LL x=1;
	rep(i,n){
		x*=(i+1);
		if(x>=mod) x%=mod;
	}
	return x;
}

int main(){
	LL X, Y;
	cin >> X >> Y;
	if((X+Y)%3!=0){
		cout << 0 << endl;
		return 0;
	}
	else{
		LL dif=abs(X-Y);
		LL num=(X+Y)/3;
		if(num<dif){
			cout << 0 << endl;
			return 0;
		}
		LL A=(num+dif)/2, B=(num-dif)/2;
		LL ans=modfac(num);
		rep(i,A){
			ans*=modinv(i+1);
			ans%=mod;
		}
		rep(i,B){
			ans*=modinv(i+1);
			ans%=mod;
		}
		cout << ans << endl;
	}

	return 0;
}

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

Measured memory_bytes: 1808
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#define MAXN 300000
using namespace std;
int prime[MAXN];
bool is_prime[MAXN];
int sum_prime[MAXN];
int sieve(int n){
  int p=0;
  for(int i=0;i<=n;i++) is_prime[i]=true;
  is_prime[0]=is_prime[1]=false;
  for(int i=2;i<=n;i++){
    if(is_prime[i]){
      prime[p++]=i;
      for(int j=2*i;j<=n;j+=i) is_prime[j]=false;
    }
  }
  return p;

}
int main(void){
  int n,i;
  sieve(MAXN);
  for(i=1;i<MAXN;i++){
    sum_prime[i]=sum_prime[i-1]+is_prime[i];
  }
  while(scanf("%d",&n),n){
    printf("%d\n",sum_prime[2*n]-sum_prime[n]);
  }
  return 0;
}

Measured memory_bytes: 4788
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  string res, s;
  cin >> n;
  res = "Three";
  for(int i=0;i<n;i++){
    cin >> s;
    if(s == "Y"){
      res = "Four";
      break;
    }
  }
  cout << res << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, N) for(int i = 0; i < N; i++)
#define rep2(i, N, a, b) for(int i = a; i < N; i += b)

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

	vector<int64_t> h(N);
	rep(i, N) cin >> h.at(i);
	int64_t minimum = INT64_MAX;
	sort(h.begin(), h.end());
	rep(i, N - K + 1){
		int64_t tmp = h.at(i + K - 1) - h.at(i);
		if (tmp < 0) tmp *= -1;
		minimum = min(minimum, tmp);
	}
	cout << minimum << endl;
}

Measured memory_bytes: 1024
#include<iostream>

using namespace std;

int main(){
  int n;
  cin>>n;
  for(int i=0;i*4<=n;i++){
    for(int j=0;j*7<=n;j++){
      if(i*4+j*7==n){
        cout<<"Yes"<<endl;
        return 0;
      }
    }
  }
  cout<<"No"<<endl;
}


Measured memory_bytes: 256
n = int(input())
a=list(map(int, input().split()))
b=list(map(int, input().split()))
c=list(map(int, input().split()))

s = 0
for i in range(n-1):
  s += b[i]
  if a[i] + 1 == a[i+1]:
    s += c[a[i]-1]
s += b[n-1]
print(s)

Measured memory_bytes: 3060
#include <stdio.h>
#include <vector>
#include <string.h>
#include <algorithm>
#include <map>
#include <string>
#include <deque>

#pragma warning(disable:4996)
int main(void) {
	int a, b;
	scanf("%d %d",&a, &b);

	printf("%d", (a + b) % 24);
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main(){
    int x1,y1,x2,y2;
    cin>>x1>>y1>>x2>>y2;
    for(int i=y1;i<y2;i++)cout<<"U";
    for(int i=x1;i<x2;i++)cout<<"R";
    for(int i=y1;i<y2;i++)cout<<"D";
    for(int i=x1;i<x2;i++)cout<<"L";
    cout<<"L";
    for(int i=y1;i<y2+1;i++)cout<<"U";
    for(int i=x1;i<x2;i++)cout<<"R";
    cout<<"R"<<"D"<<"R";
    for(int i=y1;i<y2+1;i++)cout<<"D";
    for(int i=x1;i<x2;i++)cout<<"L";
    cout<<"L"<<"U";
}

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

#define ll long long int
#define ff(i,a,b) for(ll i = a; i < b; i++)
#define bf(i,b,a) for(ll i = b-1; i >= a; i--)
#define itf(i,a) for(auto i = a.begin(); i != a.end(); i++)
#define itfr(i,a) for(auto i = a.rbegin(); i != a.rend(); i++)
#define MII map<ll,ll> 
#define MCI map<char,ll>
#define MSI map<string,ll>
#define VI vector<ll> 
#define VC vector<char> 
#define VS vector<string> 
#define MP make_pair
#define tc ll t; cin>>t; while(t--)
#define DISPV(v) itf(i,v) cout << *i << ' ';
#define DISPM(m) itf(i,m) cout << i->first << ' ' << i->second << endl;

const int MOD = int(1e9) + 7;

using namespace std;

int main() {
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    ll n;
    cin >> n;
    ll d;
    cin >> d;
    ll cnt = 0;
    ff(i,0,n){
        ll x,y;
        cin >> x >> y;
        if(sqrt(x*x + y*y) <= d)
            cnt++;
    }
    cout << cnt;
}

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

using namespace std;

int main() {
    string str;
    getline(cin, str);

    for (int i = 0; i < str.size(); i++) {
        if (str[i] >= 0x41 &&
            str[i] <= 0x5a) 
        {
            str[i] += 0x20;
        }
        else 
        if( str[i] >= 0x61 &&
            str[i] <= 0x7a)
        {
            str[i] -= 0x20;
        }
    }

    cout << str << endl;

    return 0;
}

Measured memory_bytes: 3088
package main

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

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

// min, max, asub, absなど基本関数
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func asub(a, b int) int {
	if a > b {
		return a - b
	}
	return b - a
}

func abs(a int) int {
	if a >= 0 {
		return a
	}
	return -a
}

func lowerBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] >= x
	})
	return idx
}

func upperBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] > x
	})
	return idx
}
func ch(a byte, R, S, P int) (byte, int) {
	var ret byte
	var pt int
	switch a {
	case 'r':
		ret = 'p'
		pt = P
	case 's':
		ret = 'r'
		pt = R
	case 'p':
		ret = 's'
		pt = S
	}
	return ret, pt
}

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer([]byte{}, 1000000)

	N, K := getInt(), getInt()
	R, S, P := getInt(), getInt(), getInt()
	T := getString()

	a := make([]byte, N)

	ans := 0
	for i := 0; i < N; i++ {
		x, pt := ch(T[i], R, S, P)
		if i-K >= 0 && a[i-K] == x {
			x = ' '
			pt = 0
		}
		a[i] = x
		ans += pt
	}
	out(ans)
}


Measured memory_bytes: 1024
N = 2
M = input()
a = []
for i in range(N):
	a.append(map(int, raw_input().split()))

maxcandy = 0
for i in range(M):
	sumcandy = 0
	for j in range(i+1):
		sumcandy = sumcandy + a[0][j]
	for j in range(i,M):
		sumcandy = sumcandy + a[1][j]
	if maxcandy < sumcandy:
		maxcandy = sumcandy

print maxcandy

Measured memory_bytes: 2568
#define _USE_MATH_DEFINES
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <cstdio>
#include <complex>
#include <numeric>
#include <string.h>
#include <random>
#include <cmath>
#include <unordered_map>
#include <unordered_set>
#include <chrono>
#include <cassert>
#define rep(i,n) for (ll i = 0; i < (ll)n; i++)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<pi, pi> pp;
typedef pair<ll, ll> pl;
double PI = 3.141592653589793238462643383279;
const double EPS = 1e-9;
const ll MOD = 1000000007;
//const ll MOD = 998244353;
const int inf = 1 << 30;
const ll linf = 1LL << 60;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int A, B, M; cin >> A >> B >> M;
    vector<int> a(A), b(B);
    rep(i,A) cin >> a[i];
    rep(i,B) cin >> b[i];
    int ans = 0;
    int ma = inf, mb = inf;
    rep(i,A) ma = min(ma, a[i]);
    rep(i,B) mb = min(mb, b[i]);
    ans = ma+mb;
    rep(i,M) {
        int x, y, c; cin >> x >> y >> c;
        x--; y--;
        ans = min(ans, a[x]+b[y]-c);
    }
    cout << ans << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define ll          long long int
#define pb          push_back
#define pll         pair<ll,ll>
#define pq          priority_queue
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define mod         1000000007
#define inf         INT_MAX-100
#define vl          vector<ll>
#define vvl         vector<vector<ll>>
#define F           first
#define S           second
#define db          double
#define sz(x)       (ll)x.size()
#define fix(n)      cout<<fixed<<setprecision(n)
#define rep(i,a,b)  for(ll i=a;i<b;i++)
//const int N;

void solve()
{
    ll n,wt; cin>>n>>wt;
    ll w[n],v[n];
    rep(i,0,n) cin>>w[i]>>v[i];
    ll k[n+1][wt+1];
    rep(i,0,n+1){
        rep(j,0,wt+1){
            if(i==0||j==0) k[i][j]=0;
            else if(w[i-1]<=j) k[i][j]=max(v[i-1]+k[i-1][j-w[i-1]],k[i-1][j]);
            else k[i][j]=k[i-1][j];
        }
    }
    cout<<k[n][wt];
}
int main()
{
    ll T=1;
    //cin>>T;
    while(T--)
        solve();
}


Measured memory_bytes: 79232
#include <stdio.h>

int main(void){
   int a,b,c,k,i,t=0;

   scanf("%d%d%d%d",&a,&b,&c,&k);

   if(k>0){
      t+=a;
      k-=a;
      if(k<0) {t+=k; k=0;}
   }
   if(k-b>0){
      k-=b;
      t-=c;
      k-=c;
      if(k<0) {t-=k;}
   }

   printf("%d\n",t);
   return 0;
}

Measured memory_bytes: 1728
import itertools

n, m, q = map(int, input().split())
kumi = []
for i in range(q):
    kumii = list(map(int, input().split()))
    kumi.append(kumii)

ans = 0
for a in itertools.combinations_with_replacement(range(1, m+1), n):
    temp = 0
    for i in range(q):
        ai, bi, ci, di = kumi[i]
        ai, bi = ai-1, bi-1
        if a[bi] - a[ai] == ci:
            temp += di
    ans = max(ans, temp)

print(ans)

Measured memory_bytes: 9136
import bisect
import copy
import heapq
import math
import sys
from collections import *
from functools import lru_cache
from itertools import accumulate, combinations, permutations, product
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
sys.setrecursionlimit(500000)
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

a,v=map(int,input().split())
b,w=map(int,input().split())
t=int(input())

if abs(a-b)<=(v-w)*t:
    print("YES")
else:
    print("NO")

Measured memory_bytes: 68204
#include <bits/stdc++.h>
using namespace std;
#define ll long long int 
#define ull unsigned long long int
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define mx *max_element
#define mn *min_element
#define fo(i,n) for(ll i=0;i<n;i++)
#define of(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define sortall(x) sort(all(x))
#define mem(x,p) memset(x,p,sizeof(x))
#define w(t) ll t;cin>>t;while(t--)
#define kk "\n"
const ll mod=1e9+7;
int main()
{
  IOS
  ll k;
  ll a,b;
  cin>>k;
  cin>>a>>b;
  ll f=0;
  for(ll i=a;i<=b;i++)
  {
    if(i%k==0)
    {
      f=1;
      break;
    }
  }
  if(f)
    cout<<"OK";
  else
    cout<<"NG";
  return 0;
}


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

#define vi                 vector<int>
#define mem(dp,a)           memset(dp,a,sizeof dp)
#define sonic               ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define pb(x)               push_back(x)
#define mp(x,y)             make_pair(x,y)
#define itr(it,c)           for(auto const &it : c)
#define all(c)              c.begin(), c.end()
#define ff                  first
#define ss                  second
#define INF                 INT_MAX
#define REPl(i,a,b)          for (ll i=a;i<b;i++)
#define REPi(i,a,b)			for (ll i=a;i<b;i++)
//*******Uer-Defined Functions*********//

//*******Functions end here************//
//*******Main func starts**************//
int main()
{
    sonic;
	int n;
	cin >> n;
	set <string> st;
	for (int i=0;i<n;i++)
	{
		string s;
		cin >> s;
		st.insert(s);
	}
	cout << st.size() << endl;
}
//******Main Ends here****************//



Measured memory_bytes: 19144
def main():
    N = int(input())
    S = input()
    ans = 0
    # password = set()

    # for i in range(N - 2):
    #     for j in range(i + 1, N - 1):
    #         for k in range(10):
    #             if str(k) in S[j + 1:]:
    #                 password.add(S[i] + S[j] + str(k))

    for i in range(10):
        for j in range(10):
            for k in range(10):
                i_index = S.find(str(i))
                j_index = S.find(str(j), i_index + 1)
                k_index = S.find(str(k), j_index + 1)
                if i_index != -1 and j_index != -1 and k_index != -1:
                    ans += 1

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 9272
#include<iostream>
#include<vector>
#include<algorithm> 
#include<iterator> 

using std::cout;
using std::cin;
using std::endl;
using std::vector;

void initStatus(vector<int> &v) {
    int size = v.size();
    for (int i = 0; i < size; i ++) {
        v[i] = size - i;
    }
}

vector<int> change(vector<int> &v, int n, int p, int c) {
    vector<int> v1(p - 1);
    vector<int> v2(c);
    vector<int> v3(n - (p - 1) - c);

    int count_v1 = 0;
    int count_v2 = 0;
    int count_v3 = 0;

    for (int i = 0; i < n; i ++) {
        if (i < p - 1) {
           v1[count_v1] = v[i]; 
           count_v1 ++;
        } else if (i > p + c - 2) {
            v3[count_v3] = v[i];
            count_v3 ++;
        } else {
            v2[count_v2] = v[i];
            count_v2 ++;
        }
    }
        std::copy(v1.begin(),v1.end(),std::back_inserter(v2));
        std::copy(v3.begin(),v3.end(),std::back_inserter(v2));
    return v2;
}

int shuffle(vector<int> &v, int n, int r) {
    int p;
    int c;
    for (int i = 0; i < r; i ++) {
        cin >> p >> c; 
        v = change(v, n, p, c);
    }
}

int main() {
    int n;
    int r;
    cin >> n >> r; 
    while (n != 0 && r != 0) {
        vector<int> v(n);
        initStatus(v);
        shuffle(v, n, r);
        cout << v[0] << endl;
        cin >> n >> r; 
    }
    return 0;
}

Measured memory_bytes: 3000
#include <iostream>
using namespace std;
int w,h,x,y,r;
void solve(){
	cin>>w>>h>>x>>y>>r;
	if(x<=(w-r)&&y<=(h-r)&&x>=r&&y>=r)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
}
int main() {
	solve();
	return 0;
}

Measured memory_bytes: 3080
#include<bits/stdc++.h>
using namespace std;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
#define inf 1000000000000000000
#define rep(i,a,b) for (int i = a; i <= b; i++)
#define f first
#define s second
#define pb push_back
#define mp make_pair

vector<pi> a, b;
vector<pair<ll,ll>>adj[101010];
int n,k;
map<pi, int> m;
priority_queue<pi> q;
bool vis[101010];

int prim(int ss){
ll mst = 0;
q.push({0,1});
while(!q.empty()){
    int t= q.top().s, w=q.top().f;q.pop();
    if(vis[t])continue;
    vis[t]=true;
    mst+=(-1)*w;

    for(auto u : adj[t]){
        if(!vis[u.f]){
            q.push({-u.s,u.f});
        }
    }
}
return mst;
}


int main(){
cin >> n;
for(int i =1; i<=n; i++){
    int x, y;
    cin >> x >> y;
    a.pb({x,y});
    b.pb({y,x});
}
sort(a.begin(), a.end());
sort(b.begin(), b.end());
for(int i =0; i<n-1; i++){
    int x = a[i+1].f - a[i].f;
    adj[i+1].pb({i+2, x});
    adj[i+2].pb({i+1, x});
    m[{a[i].f,a[i].s}]=i+1;
    m[{a[i+1].f,a[i+1].s}]=i+2;
}
for(int i =0; i<n-1; i++){
    int y = b[i+1].f-b[i].f;
    int x1=m[{b[i].s, b[i].f}], x2=m[{b[i+1].s, b[i+1].f}];
    adj[x1].pb({x2,y});
    adj[x2].pb({x1,y});
}
ll ans =prim(1);
cout << ans << endl;

return 0;}


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

Measured memory_bytes: 596
#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>;
const int INF = 1 << 30;
 
int main() {
	ll q, h, s, d, n;
	cin >> q >> h >> s >> d >> n;
	ll pq=8*q, ph=4*h, ps=2*s;
	ll mi = min(pq, min(ph, min(ps, d)));
	
	ll ans= 0;
	if (n%2==0) {
		ans = n / 2 * mi;
	}
	else {
		ans += n / 2 * mi;
		ans += min(q*4, min(h*2, s));
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
# abc099 c

import itertools
from math import factorial
import sys
import heapq
from collections import Counter
from collections import deque
from fractions import gcd
from functools import reduce

sys.setrecursionlimit(4100000)
INF = 1 << 60
MOD = 10 ** 9 + 7

# ここから書き始める
n = int(input())
dp = [INF] * (n + 1)
for i in range(n + 1):
    dp[i] = i
for i in range(n + 1):
    # for l in range(1, i + 1):
    #     dp[i] = min(dp[i], dp[i - l] + l)
    j = 1
    while i - pow(6, j) >= 0:
        dp[i] = min(dp[i], dp[i - pow(6, j)] + 1)
        j += 1
    k = 1
    while i - pow(9, k) >= 0:
        dp[i] = min(dp[i], dp[i - pow(9, k)] + 1)
        k += 1
# print(dp)
print(dp[-1])


Measured memory_bytes: 8956
#include<bits/stdc++.h>
using namespace std;
int min1=10005;
int vis[1005];
int ans;
int main()
{
	int x,n,a;
	cin>>x>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>a;
		vis[a]=1;
	}
	for(int i=-1000;i<=1000;i++)
	{
		if(vis[i]==0)
		{
			if(abs(x-i)<min1)
			{
				min1=abs(x-i);
				ans=i;
			}
		}
	}
	cout<<ans;
}

Measured memory_bytes: 3600
import java.util.Scanner;


public class Main{
	public static void main(String[] args){

		@SuppressWarnings("resource")
		Scanner sc = new Scanner(System.in);
		int i=0;
		int[] stack = new int[10];
		while(sc.hasNext())
		{
			int line = sc.nextInt();

			if(line == 0){
				i--;
				System.out.println(stack[i]);
			}
			else{
				stack[i] = line;
				i++;
			}
		}
	}
}

Measured memory_bytes: 17208
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define len(v) ll(v.size())
#define fi first
#define se second

template <class T>
void cout_vec(const vector<T> &vec){
  for(auto itr:vec) cout<<itr<<' ';
  cout<<endl;
}

typedef pair<ll,ll> P;
const ll mod=1e9+7;
const ll inf=1e15;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin>>n;
  vector<int> a(n);
  bool flag=true;
  rep(i,n){
    cin>>a[i];
    if(a[i]<0) flag=false;
  }
  if(flag){
    cout<<n-1<<endl;
    rep(i,n-1){
      cout<<i+1<<' '<<i+2<<endl;
    }
    return 0;
  }
  auto ma=max_element(begin(a),end(a)),mi=min_element(begin(a),end(a));
  int ans=0;
  cout<<n+n-1<<endl;
  if(abs(*ma)>abs(*mi)){
    int ind=ma-begin(a);
    rep(i,n){
      cout<<ind+1<<' '<<i+1<<endl;
    }
    rep(i,n-1){
      cout<<i+1<<' '<<i+2<<endl;
    }
  }else{
    int ind=mi-begin(a);
    rep(i,n){
      cout<<ind+1<<' '<<i+1<<endl;
    }
    for(int i=n;i>1;i--){
      cout<<i<<' '<<i-1<<endl;
    }
  }
}

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

#define rep(i,n) for(int i = 0; i < n; i++)
#define REP(i,n) for(int i = 1; i < n; i++)
#define repll(i,n) for(ll i = 0; i < n; i++)
#define REPll(i,n) for(ll i = 1; i < n; i++)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define yesorno(a) printf(a ? "yes\n" : "no\n")
#define YesorNo(a) printf(a ? "Yes\n" : "No\n")
#define YESorNO(a) printf(a ? "YES\n" : "NO\n") 
#define endl "\n"
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
using vi = vector<int>;
using vii = vector<vi>;
using vl = vector<ll>;
using vll = vector<vl>;
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
const int inf = (1<<30)-1;
const ll infll = (1LL<<62)-1;
ll ceil(const ll a, const ll b){return ((a)+(b)-1)/b;}


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

  ll n, y;
  cin >> n >> y;
  for(ll i = 0; i <= n; i++){
    for(ll j = 0; i+j <= n; j++){
      ll k = n - (i+j);
      if(10000*i + 5000*j + 1000*k == y){
        cout << i << " " << j << " " << k << endl;
        return 0;
      }
    }
  }
  cout << -1 << " " << -1 << " " << -1 << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <stack>
#include <utility>
#include <numeric>
#include <algorithm>
#include <functional>
#include <cctype>
#include <complex>
#include <string>
#include <sstream>

using namespace std;

#define all(c) c.begin(),c.end()
#define rall(c) c.rbegin(),c.rend()
#define mp(a,b) make_pair((a),(b))
#define eq ==

typedef long long ll;
typedef complex<double> point;
typedef pair<int,int> pii;


const double EPS = 1e-9;

string maxs(string a,string b){
    while(a.size() >= 1){
        if(a[0] != '0') break;
        a = a.substr(1,a.size()-1);
    }
    while(b.size() >= 1){
        if(b[0] != '0') break;
        b = b.substr(1,b.size()-1);
    }
    if(a.length() > b.length()) return a;
    if(a.length() < b.length()) return b;
    for(int i=0;i<a.length();i++){
        if(a[i] > b[i]) return a;
        if(a[i] < b[i]) return b;
    }
    return a;
}

string choos(string a,string b){
    if(a.length() > b.length()) return a;
    else if(a.length() < b.length()) return b;
    else {
        for(int i=0;i<a.length();i++){
            if(a[i] > b[i]) return a;
            else if(a[i] < b[i]) return b;
        }
        return a;
    }
}
int dx[] = {0,-1};
int dy[] = {-1,0};
int main(){
    while(true){
        int W,H;
        cin >> W >> H;
        if(W == 0) break;
        vector<vector<char> > C(H+2,vector<char>(W+2,'A'));
        vector<vector<string> > memo(H+2,vector<string>(W+2));
        for(int i=1;i<=H;i++){
            for(int j=1;j<=W;j++){
                cin >> C[i][j];
            }
        }
        string ret = "0";
        for(int y=H+1;y>=0;y--){
            for(int x=W+1;x>=0;x--){
                if(memo[y][x] == "" && isdigit(C[y][x])){
                    memo[y][x] = C[y][x];
                    ret = maxs(ret,string(1,C[y][x]));
                }
                if(isdigit(C[y][x])){
                    for(int i=0;i<2;i++){
                        int nx=x+dx[i];
                        int ny=y+dy[i];
                        if(isdigit(C[ny][nx])){
                            memo[ny][nx] = choos(C[ny][nx] + memo[y][x],memo[ny][nx]);
                            ret = maxs(ret,C[ny][nx]+memo[y][x]);
                        }
                    }
                }
            }
        }
        // for(int i=0;i<H+2;i++){
        //     for(int j=0;j<W+2;j++){
        //         cerr << memo[i][j] << " ";
        //     }
        //     cerr << endl;
        // }
        cout << ret << endl;
    }
    return 0;
}

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

public class Main {

  public static void main(String[] args) {
    
    new Main().run();
  }

  public void run() {

    try(BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {

      final int n = Integer.parseInt(br.readLine());
      String op;
      String[] words;
      Tree tree = new Tree();

      for(int i=0,k=0; i<n; i++,k=0){
        words = br.readLine().split(" ");
        op  = words[k++];
        if ( op.equals("insert") ) { 
          tree.insert(Integer.parseInt(words[k++]));
        }
        else {
          tree.dispRoundPath();
        }
      }

    }
    catch(IOException e) {
      System.out.println("IOException!");
    }
  }
}

class Tree {

  static final BTreeNode NIL = new BTreeNode(-1);
  BTreeNode root;
  StringBuilder buf;

  public Tree() {
    root = NIL;
    buf = new StringBuilder();
  }

  public void insert(int val) {
    BTreeNode y = NIL;
    BTreeNode x = root;
    BTreeNode z = new BTreeNode(val);

    while( !x.equals(NIL) ) {
      y = x;
      if( z.key < x.key )
        x = x.left;
      else
        x = x.right;
    }
    z.parent = y;

    if( y.equals(NIL) ){
      root = z;
    }
    else if( z.key < y.key )
      y.left = z;
    else
      y.right = z;
  } 
  void preParse(BTreeNode u) {
    if( !u.equals(NIL) ) {
      buf.append(" ").append(u.key);
      preParse(u.left);
      preParse(u.right);
    }
  }
  void inParse(BTreeNode u) {
    if( !u.equals(NIL) ) {
      inParse(u.left);
      buf.append(" ").append(u.key);
      inParse(u.right);
    }
  }

  void dispRoundPath() {

    inParse(root);
    buf.append("\n");
    preParse(root);
    buf.append("\n");

    System.out.print(buf);
    buf.setLength(0);
  }
}

class BTreeNode {
  int key;
  BTreeNode parent,left,right;

  public BTreeNode(int key) {
    this.key = key;
    this.parent =
    this.left =
    this.right = Tree.NIL;
  }

  @Override
  public boolean equals(Object o) {
    if(o == this) return true;
    if(o == null) return false;
    if(!(o instanceof BTreeNode)) return false;

    BTreeNode node = (BTreeNode)o;
    if(!(this.key == node.key)) return false;

    return true;
  }
}


Measured memory_bytes: 125712
/*
このコード、と～おれ!
Be accepted!
∧＿∧　
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
 　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
		  　　　　　　　　　　(¸.·´ (¸.·'* ☆
					*/

#include <stdio.h>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstring>
#include <vector>
#include <numeric>
#include <iostream>
#include <random>
#include <map>
#include <unordered_map>
#include <queue>

#pragma GCC optimize("Ofast")
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define rep1(i, n) for(int i = 1; i <= (n); ++i)
#define rep2(i, n) for(int i = 2; i < (n); ++i)
#define repr(i, n) for(int i = n; i >= 0; --i)
#define reprm(i, n) for(int i = n - 1; i >= 0; --i)
#define printynl(a) printf(a ? "yes\n" : "no\n")
#define printyn(a) printf(a ? "Yes\n" : "No\n")
#define printYN(a) printf(a ? "YES\n" : "NO\n")
#define printin(a) printf(a ? "possible\n" : "inposible\n")
#define printdb(a) printf("%.50lf\n", a)//少数出力
#define printdbd(a) printf("%.16lf\n", a)//少数出力(桁少なめ)
#define prints(s) printf("%s\n", s.c_str())//string出力
#define all(x) (x).begin(), (x).end()
#define allsum(a, b, c) ((a + b) * c / 2)//等差数列の和、初項,末項,項数
#define pb push_back
#define priq priority_queue
#define rpriq priq<int, vector<int>, greater<int>>
#define deg_to_rad(deg) (((deg)/360.0)*2.0*PI)
#define rad_to_deg(rad) (((rad)/2.0/PI)*360.0)
#define Please return
#define AC 0
#define ushi int
#define tapu main
#define nichia (
#define kunn void
#define wara )

using ll = long long;

const int INF = 1073741823;
const int MINF = -1073741823;
const ll LINF = ll(4661686018427387903);
const ll MOD = 1000000007;
const double PI = acos(-1);

using namespace std;

void scans(string& str) {
	char c;
	scanf("%c", &c);
	if (c == '\n')scanf("%c", &c);//最初の改行対策
	while (c != '\n' && c != -1) {
		str += c;
		scanf("%c", &c);
	}
}

void scanc(char& str) {
	char c;
	scanf("%c", &c);
	if (c == -1)return;
	while (c == '\n') {
		scanf("%c", &c);
	}
	str = c;
}

double acot(double x) {
	return PI / 2 - atan(x);
}

/*-----------------------------------------ここからコード-----------------------------------------*/

int main(){

	int n;
	scanf("%d", &n);
	vector<int> a(n);
	rep(i, n)scanf("%d", &a[i]);
	vector<bool> pushed(n);
	int now = 0, count = 0;
	while (now != 1) {
		now = a[now] - 1;
		if (pushed[now])break;
		pushed[now] = true;
		++count;
	}
	printf("%d\n", now == 1 ? count : -1);
	Please AC;
}


Measured memory_bytes: 640
import math
n, k = map(int,input().split())
g={}
for i in range(n):
    g[i]=[]
for i in range(k):
    a,b= map(int,input().split())
    g[a-1].append(b-1)
    g[b-1].append(a-1)
ans = [-1] * n
queue = [0]
visited = [False] * n
 

while queue:
    x = queue.pop(0)
    for n in g[x]:
        if visited[n] == False: 
            queue.append(n)
            if ans[n] == -1: 
                ans[n] = x
                visited[n] = True
 
if -1 in ans[1:]:
    print('No')
else:
    print('Yes')
    for a in ans[1:]:
        print(a+1)

Measured memory_bytes: 42952
unittest
{
	assert( [ "3", "1 2 3" ].parse.expand.solve == 5 );
	assert( [ "12", "161735902 211047202 430302156 450968417 628894325 707723857 731963982 822804784 880895728 923078537 971407775 982631932" ].parse.expand.solve == 750927044 );
}



import std.conv;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	input.popFront;
	auto xs = input.front.split.to!( long[] );
	return tuple( xs );
}

auto solve( long[] xs )
{
	// 階乗を事前計算
	xs.length.factorialMod;
	
	// xs[i]からxs[i+1]の間をスライム[i-j..i+1)が通る確率を計算
	// xs[i]からxs[i+1]の間をスライム[i-j]が通る確率＝スライム[i-j..i+1)のうちスライム[i-j]が最後に選ばれるパターン÷全パターン
	auto ps = new long[ xs.length.signed ];
	foreach( j; 1L .. ps.length.signed )
	{
		auto p = ( j - 1 ).factorialMod.divMod( j.factorialMod );
		ps[ j ] = ps[ j - 1 ].addMod( p );
	}
	ps.popFront;
	
	// xs[i]からxs[i+1]の間をスライム[0..i+1)が移動するときの距離の総和の期待値を計算して合計
	auto ans = 0L;
	foreach( i, p; ps )
	{
		auto d = xs[ i + 1 ] - xs[ i ];
		ans = ans.addMod( p.mulMod( d ) );
	}
	
	// 期待値を距離の総和に戻したのが答え
	return ans.mulMod( ( xs.length.signed - 1 ).factorialMod );
}

// 足し算
auto addMod( long MOD = 10L ^^ 9 + 7 )( long x, long y )
{
	return ( x + y ) % MOD;
}

// 掛け算
auto mulMod( long MOD = 10L ^^ 9 + 7 )( long x, long y )
{
	return x * y % MOD;
}

// 割り算
auto divMod( long MOD = 10L ^^ 9 + 7 )( long x, long y )
{
	return x * y.powMod!MOD( MOD - 2 ) % MOD;
}

// べき乗
auto powMod( long MOD = 10L ^^ 9 + 7 )( long x, long y )
{
	auto a = 1L;
	for( ; 0 < y; y >>= 1 )
	{
		if( y & 1 ) a = a * x % MOD;
		x = x ^^ 2 % MOD;
	}
	return a;
}

// 階乗
auto factorialMod( long MOD = 10L ^^ 9 + 7 )( long x )
{
	static memo = [ 1L ];
	if( memo.length <= x )
	{
		auto i = memo.length;
		memo.length = x + 1;
		for( ; i <= x; i++ ) memo[ i ] = memo[ i - 1 ] * i % MOD;
	}
	return memo[ x ];
}


Measured memory_bytes: 8244
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vs = vector<string>;
using pll = pair<ll, ll>;
using vp = vector<pll>;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define repr(i, a, b) for(ll i = (a); i < (b); i++)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((ll)(x).size())
const ll MOD = 1000000007;
const ll INF = 100000000000000000LL;
inline ll GCD(ll a, ll b){ return b?GCD(b, a % b):a; }
inline ll LCM(ll a, ll b){ return a/GCD(a, b)*b; }
inline ll powint(ll x, ll y){ ll r=1; while(y){ if(y&1) r*=x; x*=x; y>>=1; } return r; }
inline ll powmod(ll x, ll y, ll m = MOD){ ll r=1; while(y){ if(y&1) r*=x; x*=x; r%=m; x%=m; y>>=1; } return r; }
template<class T>bool chmax(T &a, const T &b){ if(a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b){ if(b<a) { a=b; return 1; } return 0; }
#ifdef OJ_LOCAL
#include "dump.hpp"
#else
#define dump(...) ((void)0)
#endif

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    ll n;
    cin >> n;
    vll a(3*n);
    rep(i, 3*n){
        cin >> a[i];
    }
    sort(ALL(a));
    reverse(ALL(a));
    ll ans = 0;
    for(int i = 1; i < 2*n; i += 2){
        ans += a[i];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 2560
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#include<iomanip>
#include<set>
#include<bitset>
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define brep(index,num) for(int index=num-1;index>=0;index--)
#define brep1(index,num) for(int index=num;index>0;index--)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-7
#define mp(a1,a2) make_pair(a1,a2)
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef long long ll;
typedef long double ld;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=(ll)1e+18+1;
int INF=1e+9+1;
int N;
vint adj[200001];
int p[200001];
bool visited[200001]={};
ll a[200001];
int dp[200002];//長さがi+1であるような増加部分列における最終要素の最小値
int addi[200001],before[200001],after[200001];
int ans[200001];
map<pint,int> edgenum;
void dfs(int u,int depth){
	addi[u]=lower_bound(dp,dp+N+1,a[u])-dp;
	before[u]=dp[addi[u]];
	after[u]=a[u];
	dp[addi[u]]=a[u];
	ans[u]=lower_bound(dp,dp+N+1,INF)-dp-1;
	visited[u]=1;
	int flag=0;
	rep(i,adj[u].size()){
		int v=adj[u][i];
		if(visited[v]==0){
			flag=1;
			p[v]=u;
			dfs(v,depth+1);
			dp[addi[v]]=before[v];
		}
	}
}
int main(){
	int u[200001],v[200001];
	scan(N);
	rep(i,N){
		scan(a[i]);
	}
	rep(i,N-1){
		scan(u[i]>>v[i]);
		u[i]--; v[i]--;
		adj[u[i]].push_back(v[i]);
		adj[v[i]].push_back(u[i]);
	}
	fill(dp,dp+N+1,INF);
	dp[0]=-INF;
	p[0]=-1;
	dfs(0,0);
	rep(i,N) prin(ans[i]);
	return 0;
}


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

int wb[100001][3];
int dp[100001][3];

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

    for (int i = 1; i <= N; ++i) {
        cin >> wb[i][0] >> wb[i][1] >> wb[i][2];
    }

    dp[1][0] = wb[1][0];
    dp[1][1] = wb[1][1];
    dp[1][2] = wb[1][2];

    for (int i = 2; i <= N; ++i) {
        for (int w_curr = 0; w_curr < 3; ++w_curr) {
            dp[i][w_curr] = 0;

            for (int w_prev = 0; w_prev < 3; ++w_prev) {
                if (w_curr != w_prev && dp[i][w_curr] < dp[i - 1][w_prev] + wb[i][w_curr]) {
                    dp[i][w_curr] = dp[i - 1][w_prev] + wb[i][w_curr];
                }
            }
        }
    }

    int ans = 0;

    for (int w = 0; w <= 2; ++w) {
        if (ans < dp[N][w]) {
            ans = dp[N][w];
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
int fa[100010];
int num[100010],eme[100010],deg[100010];
void init(int n){
	for(int i=1;i<=n;i++) {
	  fa[i]=i;
	  num[i]=1;
	}
}
int find(int a){ return fa[a]==a?a:fa[a]=find(fa[a]);}
void Union(int a,int b){
	int x1=find(a);
	int x2=find(b);
	if(x1!=x2){
		fa[x1]=x2;
		num[x2]+=num[x1];
	}
}
int main(){
	int n,m,k;
	cin>>n>>m>>k;
	init(n);
	while(m--){
		int u,v;
		cin>>u>>v;
		Union(u,v);
		deg[u]++;
		deg[v]++;
	}
	while(k--){
		int u,v;
		cin>>u>>v;
		if(find(u)==find(v)) {
		eme[u]++;
		eme[v]++;
	 }
  }
	for(int i=1;i<=n;i++){
		cout<<num[find(i)]-deg[i]-eme[i]-1<<'\n';
	}
}


Measured memory_bytes: 2944
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <unordered_map>

using namespace std;

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

template<class T> using vec = vector<T>;
template<class T> using vvec = vector<vector<T>>;

#define REP(i, s, e) for (ll i = s; i < e; ++i)

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

    static int nums[] = { 1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51 };
    int K; cin >> K;
    cout << nums[K - 1] << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a) for(int i = 0; i < (a); i++)
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const int MOD = 1e9 + 7;
#define int long long

int GCD(int m,int n){
	if(n == 0) return m;
	else return GCD(n,m % n);
}

int LCM(int m,int n){
	int g = GCD(m,n);
	return m / g * n;
}

main(){
	int n,m;
	cin >> n >> m;
	string s,t;
	cin >> s >> t;
	int g = GCD(n,m);
	int l = LCM(n,m);
	char mem[100100];
	int j = 0;
	for(int i = 0; i < n; i += (l / m)){
		mem[j] = s[i];
		j++;
	}
	j = 0;
	for(int i = 0; i < m; i += (l / n)){
		if(t[i] != mem[j]){
			cout << -1 << endl;
			return 0;
		}
		j++;
	}
	cout << l << endl;
}


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

#define int long long int
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define lb lower_bound
#define ub upper_bound
#define srt(a) sort(a.begin(),a.end())
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
typedef vector<pair<int,int>> vpii;
#define mxe(a) *max_element(a.begin(),a.end())
#define mne(a) *min_element(a.begin(),a.end())
#define endl '\n'
#define mod 1000000007
#define INF64 1e18
const int N=105;
const int K=100005;
int dp[N][K];
void solve(){
  int n,k;cin>>n>>k;
  vi a(n+1);
  for(int i=1;i<=n;i++)
    cin>>a[i];
  for(int i=0;i<=n;i++)dp[i][0]=1;
  vi pref(k+1,1);
  for(int i=1;i<=n;i++){
    vi p(k+1);
    p[0]=1;
    for(int j=1;j<=k;j++){
      dp[i][j]=(mod+pref[j]-(j-a[i]-1>=0?pref[j-a[i]-1]:0))%mod;
      p[j]=(p[j-1]+dp[i][j])%mod;
    }
    pref=p;
  }
  cout<<dp[n][k];
}

int32_t main(){
  #ifndef ONLINE_JUDGE
   freopen("input.txt","r",stdin);
   freopen("output.txt","w",stdout);
  #endif
  
  ios_base::sync_with_stdio(false);
  cin.tie(0);cout.tie(0);

  int T=1;
  //cin>>T;
  for(int TT=1;TT<=T;TT++){
    solve();
  }
}


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

int main() {
  int n;
  cin >> n;
  
  vector<int> x(n);
  vector<int> y(n);
  for(int i=0; i<n; i++) cin >> x[i] >> y[i];
  
  int fact = 1;
  for(int i=1; i<=n; i++) fact *= i;
  
  //n*(n-1)/2 組合せの数
  //(n-1)*fact 2点を結ぶ経路の総数
  double dist, sum = 0;
  for(int i=0; i<n-1; i++) {
    for(int j=i+1; j<n; j++) {
      dist = sqrt((x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]));
      sum += dist * ((n-1)*fact) / (n*(n-1)/2);
    }
  }
  
  cout << fixed << setprecision(10) << sum/fact << endl;
  return 0;
}


Measured memory_bytes: 3852
import java.util.Scanner;
 
public class Main{
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int a,b,c;
    a = sc.nextInt();
    b = sc.nextInt();
    c = sc.nextInt();
    if(a + b == c || b + c == a || c + a == b){
      System.out.println("Yes");
    }else{
      System.out.println("No");
    }
  }
}

Measured memory_bytes: 9684
#include <bits/stdc++.h>
#define REP(i, a, n) for (long long i = (a); i < (long long)(n); ++i)
#define REPC(i, a, n) for (long long i = (a); i <= (long long)(n); ++i)
#define ALL(t) t.begin(), t.end()
#define RALL(t) t.rbegin(), t.rend()
#define MATINIT(type, row, col, init)                                          \
  vector<vector<type>>(row, vector<type>(col, init));
#define Yes(cond) cout << (cond ? "Yes" : "No") << endl;
#define YES(cond) cout << (cond ? "YES" : "NO") << endl;
using namespace std;
using LL = long long;
using ULL = unsigned long long;
template <class T> using VEC = std::vector<T>;
template <class T> using MAT = std::vector<std::vector<T>>;
void DUMP() { cerr << endl; }
template <class Head, class... Tail> void DUMP(Head &&head, Tail &&... tail) {
  cerr << head << ", ";
  DUMP(std::move(tail)...);
}
template <typename T> ostream &operator<<(ostream &os, vector<T> &vec) {
  os << "{";
  for (auto v : vec)
    os << v << ",";
  os << "}";
  return os;
}
template <typename T> ostream &operator<<(ostream &os, set<T> &s) {
  os << "{";
  for (auto p : s)
    os << p << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, map<T1, T2> &m) {
  os << "{";
  for (auto p : m)
    os << p << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, pair<T1, T2> p) {
  os << "[" << p.first << " " << p.second << "]";
  return os;
}

int main() {
  string S;
  cin>>S;
  map<string, string>m = {{"Rainy", "Sunny"},{"Sunny","Cloudy"}, {"Cloudy", "Rainy"}};
  cout<<m[S]<<endl;

  return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

namespace AtCoderBeginnerContest
{
    public class Program
    {
        public static bool[] memo;

        public static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            var s = Console.ReadLine();


            memo = new bool[n];
            for (int i = 0; i < n; i++)
            {
                memo[i] = false;
            }

            int r = 0;
            int l = 0;

            for (int i = 0; i < s.Length; i++)
            {
                if(s[i] == '(')
                {
                    for (int j = i+1; j < s.Length; j++)
                    {
                        if(s[j] == ')' && memo[j] == false)
                        {
                            memo[i] = true;
                            memo[j] = true;
                            break;
                        }
                    }
                }
            }

            for (int i = 0; i < s.Length; i++)
            {
                if (s[i] == '(' && !memo[i]) r++;
                if (s[i] == ')' && !memo[i]) l++;
            }

            for (int i = 0; i < r; i++)
            {
                s = s + ")";
            }
            for (int i = 0; i < l; i++)
            {
                s = "(" + s;
            }
            Console.WriteLine(s);
        }
    }
}


Measured memory_bytes: 11092
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for (ll i = (a); i < (b); i++)
#define rep2(r, aa, bb) for (ll r = (aa)-1; r >= (bb); r--)
#define be(x) (x.begin(), x.end())
#define pb(t) push_back(t)
#define ll long long
int main()
{
	int a,b, ans=0, d=1;
	cin>>a>>b;
	while(d<b)
	{
		d+=a-1;
		ans++;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <cassert>
#include <functional>

using namespace std;

#define LOG(...) printf(__VA_ARGS__)
//#define LOG(...)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())
#define CLR(a) memset((a), 0 ,sizeof(a))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

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


int main() {
	int n, m, s, g1, g2;
	while (cin >> n >> m >> s >> g1 >> g2, n){
		vector<vector<int>> load(n + 1, vector<int>(n + 1, 100000000));//from back to 
		REP(i, m){
			int b1, b2, c;
			cin >> b1 >> b2 >> c;
			load[b1][b2] = c;
		}

		FOR(i, 1, n + 1)load[i][i] = 0;

		FOR(i, 1, n + 1){
			FOR(j, 1, n + 1){
				FOR(k, 1, n + 1){
					load[j][k] = min(load[j][k], load[j][i] + load[i][k]);
				}
			}
		}
		int ans = 100000000;
		FOR(i, 1, n + 1){
			ans = min(ans,load[s][i]+load[i][g1]+load[i][g2]);
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 3200
S = input()
if S == 'RRR' :
    print(3)
elif S == 'RRS' or S == 'SRR' :
    print(2)
elif S == 'RSS' or S == 'SRS' or S == 'SSR' or S == 'RSR':
    print(1)
else :
    print(0)

Measured memory_bytes: 9028