akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
 
template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &vec){ os << "["; for (auto v : vec) os << v << ", "; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const deque<T> &vec){ os << "deq["; for (auto v : vec) os << v << ", "; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const set<T> &vec){ os << "{"; for (auto v : vec) os << v << ", "; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_set<T> &vec){ os << "{"; for (auto v : vec) os << v << ", "; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ", "; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ", "; os << "}"; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &pa){ os << "(" << pa.first << ", " << pa.second << ")"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << ": " << v.second << ", "; os << "}"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const unordered_map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << ": " << v.second << ", "; os << "}"; return os; }
template<typename T> void ndarray(vector<T> &vec, int len) { vec.resize(len); }
template<typename T, typename... Args> void ndarray(vector<T> &vec, int len, Args... args) { vec.resize(len); for (auto &v : vec) ndarray(v, args...); }
template<typename T> bool chmax(T &m, const T q) { if (m < q) {m = q; return true;} else return false; }
template<typename T> bool chmin(T &m, const T q) { if (q < m) {m = q; return true;} else return false; }
template<typename T1, typename T2> pair<T1, T2> operator+(const pair<T1, T2> &l, const pair<T1, T2> &r) { return make_pair(l.first + r.first, l.second + r.second); }
template<typename T1, typename T2> pair<T1, T2> operator-(const pair<T1, T2> &l, const pair<T1, T2> &r) { return make_pair(l.first - r.first, l.second - r.second); }
#define f first
#define s second
 
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int len;
    cin >> len;
    int big = 0;
    map<int, int> m;
    for(int i = 0; i < len; i++) {
        int a;
        cin >> a;
        m[a]++;
        m[a - 1]++;
        m[a + 1]++;
        if(m[a] > big) {
            big = m[a];
        }
        if(m[a + 1] > big) {
            big = m[a + 1];
        }
        if(m[a - 1] > big) {
            big = m[a - 1];
        }
    }
    cout << big;
}

Measured memory_bytes: 8020
package main
import (
	"fmt"
)

type Dice struct{
	/*
	こういう感じ
  		 ___
	____|_1_|_______
	|_4_|_2_|_3_|_5_|
		|_6_|
	*/
	Surface []int
}

func (d *Dice)Move(dir string, n int){
	n%=4
	switch dir{
	case "W":
		for i:=0; i<n; i++{
			d.Surface[0], d.Surface[2], d.Surface[5], d.Surface[3] = d.Surface[2], d.Surface[5], d.Surface[3], d.Surface[0]
		}
	case "E":
		for i:=0; i<n; i++{
			d.Surface[0], d.Surface[2], d.Surface[5], d.Surface[3] = d.Surface[3], d.Surface[0], d.Surface[2], d.Surface[5]
		}
	case "N":
		for i:=0; i<n; i++{
			d.Surface[0], d.Surface[4], d.Surface[5], d.Surface[1] = d.Surface[1], d.Surface[0],d.Surface[4], d.Surface[5]
		}
	case "S":
		for i:=0; i<n; i++{
			d.Surface[5], d.Surface[1], d.Surface[0], d.Surface[4] = d.Surface[1], d.Surface[0],d.Surface[4], d.Surface[5]	
		}
	}
}

func (d *Dice)Roll(dir string, n int){
	n%=4	// べつにいらんけど一周したら元にもどるので
	switch dir{
	case "R":
		for i:=0; i<n; i++{
			d.Surface[3], d.Surface[1], d.Surface[2], d.Surface[4] = d.Surface[1], d.Surface[2], d.Surface[4], d.Surface[3]
		}	
	case "L":
		for i:=0; i<n; i++{
			d.Surface[3], d.Surface[1], d.Surface[2], d.Surface[4] = d.Surface[4], d.Surface[3], d.Surface[1], d.Surface[2]
		}
	}
}

func (d *Dice)GetStatus(){
	doc := `              ____
 	 ____|_%02d_|_________
	|_%02d_|_%02d_|_%02d_|_%02d_|
	     |_%02d_|`
	fmt.Printf(doc, d.Surface[0], d.Surface[3], d.Surface[1], d.Surface[2], d.Surface[4], d.Surface[5])
	fmt.Println()
}

func (d *Dice)IsEqual(other_d Dice)(ret bool){
	if len(d.Surface) != len(other_d.Surface){
		return false
	}
	for i, v := range d.Surface{
		if v!=other_d.Surface[i]{
			return false
		}
	}
	return true
}

func main(){
	d1 := Dice{
		make([]int, 6),
	}
	d2 := Dice{
		make([]int, 6),
	}
	for i:=0; i<6; i++{
		var n int
		fmt.Scan(&n)
		d1.Surface[i] = n
	}
	for i:=0; i<6; i++{
		var n int
		fmt.Scan(&n)
		d2.Surface[i] = n
	}
	
	roll_order := []string{"R", "L"}
	direction_order := []string{"N", "W", "E", "S"}
	ans := false
	CHECK:
		// 0から始めているのは「最初から同じ」場合があるため
		for i:=0; i<=2; i++{
			for j:=0; j<=2; j++{
				for _, d := range direction_order{
					for _, r := range roll_order{
						psude_d := new(Dice)
						psude_d.Surface = append([]int{}, d2.Surface...)
						psude_d.Move(d, i)
						psude_d.Roll(r, j)
						if psude_d.IsEqual(d1){
							ans = true
							break CHECK
						}
					}
				}
			}
		}
	if ans{
		fmt.Println("Yes")
	}else{
		fmt.Println("No")
	}
}

func getIndex(ns []int, key int)(id int){
	for idx, v := range ns{
		if v==key{
			id = idx
			break
		}
	}
	return
}


Measured memory_bytes: 1152
#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <stack>
#include <functional>
#include <set>
#include <map>
#include <deque>
#include <cmath>
#define WMAX 10000
#define HMAX 10000

//コメントアウトするとdebug()を実行しない
#define DEBUG

using namespace std;
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

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

struct edge{
  int to,cost;
};

int A,B,C,N,W,H,ans,dp[HMAX][WMAX];
string S;
static const int dx[8] = {0,1,1,1,0,-1,-1,-1},
					dy[8] = {1,1,0,-1,-1,-1,0,1};

void solve(){
	if(A == 2 || B == 2){
		ans = 0;
		return;
	}
	int group[] = {4,6,9,11};
	int x = -1,y = -1;
	for (int i = 0; i < 4; ++i)
	{
		if(A == group[i]){
			x = i;
		}
		if(B == group[i]){
			y = i;
		}
	}
	if((x<0 && y<0) || (x>=0 && y>=0)){
		ans = 1;
	}else{
		ans = 0;
	}

}

void debug(){

}

void answer(){
	if(ans){
		cout << "Yes\n";
	}else{
		cout << "No\n";
	}
}

int main(){
	cin >> A >> B;
	solve();
	#ifdef DEBUG
	debug();
	#endif
	answer();

	return 0;
}

Measured memory_bytes: 256
import sys
from math import sqrt
from collections import Counter, defaultdict, deque

input = sys.stdin.readline
sys.setrecursionlimit(10 ** 6)


def I():
    return int(input())


def MI():
    return map(int, input().split())


def LI():
    return list(MI())


def LIN(n: int):
    return [I() for _ in range(n)]


inf = float("inf")
mod = 10 ** 9 + 7


def main():
    s = input().rstrip()
    if s == "ABC":
        print("ARC")
    else:
        print("ABC")


if __name__ == "__main__":
    main()


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

struct ten{
    vector<int> ko;
    int anss ;
};

int main(){
    int n,q;
    cin>>n>>q;
    vector<ten> tens(n+1);
    int a,b;
    for(int i=0;i<n-1;i++){
        cin>>a>>b;
        tens[min(a,b)].ko.push_back(max(a,b));            
    }
    vector<int> p(q),x(q);
    for(int i=0;i<q;i++){
        cin>>p[i]>>x[i];
        tens[p[i]].anss += x[i];
    }
    for(int i=1;i<=n;i++){
        for(int j=0;j<tens[i].ko.size();j++){
            tens[tens[i].ko[j]].anss += tens[i].anss; 
        }
    }

    for(int i=1;i<=n;i++){
        cout << tens[i].anss;
        if(i==n){
            cout<<endl;
        }else{
            cout<<" ";
        }
    }

}

Measured memory_bytes: 16512
//与えられた数列を逆順に出力するプログラム
#include <stdio.h>
#include <stdlib.h>

int main(void)
{
    //変数定義
    int iSequenceArraySize;     //数列の要素数
    int iSequence;              //数列の要素
    int* paiSequence;           //数列を格納場所を示すポインタ
    int iCount;                 //カウントアップ変数
    
    //変数の初期化
    iSequence = 0;

    //数列の総数を入力
    scanf("%d",&iSequenceArraySize);
    paiSequence = (int*)malloc(sizeof(int) * iSequenceArraySize);
    //数列を配列に格納する
    for (iCount = 0; iCount < iSequenceArraySize; iCount++)
    {
        scanf("%d",&iSequence);
        paiSequence[iCount] = iSequence;
    }
    //格納した数列を逆順に出力する
    for (iCount = iSequenceArraySize - 1; iCount >= 0; iCount--)
    {
        printf("%d",paiSequence[iCount]);
        if (iCount != 0)
        {
            printf(" ");
        }
    }
    printf("\n");
    //free
    free(paiSequence);

    return 0;
}


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

using namespace std;

int main() {
  string s;
  int k;
  cin >> s;
  cin >> k;
  set<string> ss;

  for (int i = 0; i < s.size(); i++) {
      for (int j = 1; j <= k && i + j <= s.size(); j++) {
          ss.insert(s.substr(i, j));
      }
  }
  vector<string> ans;
  for (auto& e : ss) {
      ans.emplace_back(e);
  }
  sort(ans.begin(), ans.end());
  cout << ans[k-1] << endl;
  return 0;
}

Measured memory_bytes: 1920
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include<queue>
using namespace std;
//conversion
//------------------------------------------
inline long long toint(string s) {long long v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}
//typedef
//------------------------------------------
typedef long long ll;
typedef long long LL;
typedef vector<int > vi;
typedef vector<long long > VLL;
typedef vector<long long > vll;
typedef vector<string > ves;
typedef vector<char > vech;

typedef pair<long long , long long> pll;
typedef pair<long long , long long> PLL;
typedef map<ll , ll >mll;
typedef map<int , int >mii;
typedef map<char , int >mci;
typedef map<char , ll >mcl;


//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define VECMAX(x) *max_element(ALL(x))
#define VECMIN(x) *min_element(ALL(x))
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
//#define MULTIPLE(i,n,k) for(int i = (k) ; i<(n) ; i+=k+1)//倍数ループ
//constant
//------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define SIZEOF(x) sizeof(x)/sizeof(x[0])

const long long INF = 100000000000000;
const long long NINF = -100000000000000;




//-------------------------------------------------------------




ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll nCr(ll n, ll r) {

	if (n == 0) { return 0; }
	if (r == 0) { return 1; }
	if (r == 1) { return n; }
	if (n == r) { return 1; }

	if (r > n / 2) { r = n / 2; }

	ll result = 1;
	for (ll i = 1; i <= r; i++) {
		result *= (n - i + 1) / i;
    }
	return(result);
}




int main(){
    LL k; string s;   
    
    ll ans = 0;
    cin>>k;
    REP(i,k){
        REP(j,k){
            REP(l,k){
                ans+=gcd(i+1,gcd(j+1,l+1));
            }
        }
    }

    cout << ans;
    


    return 0;
}







Measured memory_bytes: 3628
from fractions import gcd

T, *L = map(int, open(0).read().split())

for a, b, c, d in zip(*[iter(L)] * 4):
    if a < b or d < b:
        flag = False
    elif c >= b - 1:
        flag =  True
    else:
        g = gcd(b, d)
        flag = (b + a % g - g) <= c

    if flag:
        print("Yes")
    else:
        print("No")


Measured memory_bytes: 5336
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fst first
#define snd second
#define all(cont) cont.begin(), cont.end()
#define foreach(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define fore(i,a,b) for(int i=a,almo5t=b;i<almo5t;++i)
#define SZ(x) ((int)x.size())
#define EPS 1e-9
#define PI acos(-1)
#define MOD 1000000007
#define FIN std::ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
 
const int N = 0;
 
typedef long long int ll;
 
using namespace std;


 
int main(){
    FIN;
    //freopen("../input.txt", "r", stdin);
    double T;cin>>T;
    double circ = 2*T*PI;
    cout<<circ<<"\n"; 
    return 0;
}

// ============== Notes =============== //
// common bugs
// - remove reader 
// - fastio
// - int overflow (especially intermediate expressionns)
// - array bounds (indices bigger than MAXN?, is MAXN correct?)
// - special cases (n=1, graph not connected?)
// - re-initialize efficiently between test cases

Measured memory_bytes: 3792
N = int(input())
#葉
A = list(map(int,input().split()))
s = sum(A[1:])
B = [0] * (N+1)
B[0] = 1 - A[0]
for i in range(0,N):
    s -= A[i+1]
    if 2*B[i] < A[i+1]:
        print("-1")
        exit()
    B[i+1] = min(2*B[i]-A[i+1],s)
if B[-1] != 0:
    print("-1")
else:
    print(sum(A)+sum(B))


Measured memory_bytes: 19936
import java.util.Scanner;

/**
 * 素数判定
 * @author nobu
 * @see <a href="http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_1_B&lang=ja">ALDS1_1_B</a>
 */
public class Main {

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

		System.out.println(gcd(x, y));

		sc.close();
	}

	private static int gcd(int x, int y) {
		if (x < y) {
			int tmp = x;
			x = y;
			y = tmp;
		}

		while (0 < y) {
			int r = x % y;
			x = y;
			y = r;
		}

		return x;
	}

}



Measured memory_bytes: 26332
a, b, c, d = [int(v) for v in input().split()]

def gcd(p, q):
    if q > p:
        p, q = q, p
    m = -1
    while m != 0:
        m = p % q
        p, q = q, m
    return p

a = a - 1
lcm = c * d // gcd(d, c)
dc = b//c - a//c
dd = b//d - a//d
dcd = b//lcm - a//lcm
divable = dc + dd - dcd
print(b - a - divable)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int maxm=2e6+5;
char s[maxm];
int n,k;
signed main(){
    cin>>n>>k;
    scanf("%s",s+1);
    int ans=0;
    int cnt=0;
    for(int i=2;i<=n;i++){
        if(s[i]==s[i-1])ans++;
        else cnt++;
    }
    if(cnt%2==0){
        ans+=min(cnt/2,k)*2;
    }else{
        cnt--;
        ans+=min(cnt/2,k)*2;
        k-=cnt/2;
        if(k>0)ans++;
    }
    cout<<ans<<endl;
    return 0;
}


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

struct HitAndBlow
{
    vector<int> cards;

    HitAndBlow(){
        cards = vector<int>(4);
    }

    void board(const HitAndBlow &other) const {
        int hit = 0, blow = 0;
        for (int i = 0; i < cards.size(); i++) {
            if (cards[i] == other.cards[i]) {
                hit++;
                continue;
            }
            for (int j = 0; j < cards.size(); j++)
                if (cards[i] == other.cards[j]) {
                    blow++;
                    break;
                }
        }
        cout << hit << " " << blow << endl;
    }
};

istream &operator >> (istream &is, HitAndBlow &g)
{
    for (int i = 0; i < g.cards.size(); i++)
        is >> g.cards[i];
    return is;
}

int main()
{
    for (HitAndBlow braker, maker; cin >> braker >> maker;)
        maker.board(braker);

    return 0;
}

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

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 rrep(i, n) for(int i = ((int)n - 1); i >= 0; --i)

typedef long long ll;
typedef long double ld;

const ll Inf = 1e18;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(0);
    int n;
    cin >> n;
    vector<vector<ll> > a(n, vector<ll>(n));
    vector<vector<bool> > b(n, vector<bool>(n, true));
    rep (i, n) rep (j, n) cin >> a[i][j];
    ll res = 0;
    rep (k, n) {
        rep (i, n) {
            rep (j, n) {
                if (a[i][j] > a[i][k] + a[k][j]) {
                    cout << -1 << endl;
                    return 0;
                }
                if (a[i][j] == a[i][k] + a[k][j] && i != k && k != j) b[i][j] = false; 
            }
        }
    }
    rep (i, n) FOR (j, i + 1, n) if (b[i][j]) res += a[i][j];
    cout << res << endl;
    
    return 0;
}



Measured memory_bytes: 1024
#include <iostream>
    #include <vector>
    #include <algorithm>
    #include <string>
    using namespace std;
    typedef long long ll;

    int main(){
        bool over = false;
        int N;
        cin >> N;
        vector<ll> A(N);
        const ll LIMIT = 1000000000000000000;
        ll sum = 1;
        for(int i = 0; i < N;i++){
            cin >> A[i];
        }
        sort(A.begin(),A.end());
        
        for(int i = 0; i < N;i++){
            if(A[0] == 0){
                sum = 0;
                break;
            }

            if(sum > LIMIT/A[i]){ // これだとオーバーフローして絶対にsumがMAXを上回ることがない。
                over = true;
                break;
            } else {
                sum *= A[i];
            }
        }

        if(over) cout << -1 << endl;
        else cout << sum << endl;


    }

    // int main(){
    //     bool over = false;
    //     unsigned long long N;
    //     cin >> N;
    //     unsigned long long A[N];
    //     unsigned long long MAX = 1000000000000000000;
    //     unsigned long long sum = 1;
    //     for(unsigned long long i = 0; i < N;i++){
    //         cin >> A[i];
    //     }
        
    //     for(unsigned long long i = 0; i < N;i++){
    //         sum *= A[i];
    //         if(sum > MAX){ // これだとオーバーフローして絶対にsumがMAXを上回ることがない。
    //             over = true;
    //             break;
    //         }
    //     }

    //     if(over) cout << -1 << endl;
    //     else cout << sum << endl;


    // }

Measured memory_bytes: 4024
#include <cstdio>

int main()
{
  int n;
  scanf("%d", &n);
  int ans = 0;
  for (int i = 0; i < n; ++i)
  {
    int a;
    scanf("%d", &a);
    ans += a - 1;
  }
  printf("%d\n", ans);
  return 0;
}

Measured memory_bytes: 128
#include <iostream>

using namespace std;

int keta_num(int n)
{
    int ret = 0;
    while (n != 0) {
        ret += n % 10;
        n = n / 10;
    }
    return ret;
}

int main()
{
    int N;

    cin >> N;

    int keta = keta_num(N);

    cout << ((N % keta == 0) ? "Yes" : "No") << endl;

    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void){
  int i,j,n,q,count=0;
  int S[10000],T[500];
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&S[i]);
  }
  scanf("%d",&q);
  for(i=0;i<q;i++){
    scanf("%d",&T[i]);
  }
  for(i=0;i<q;i++){
    for(j=0;j<n;j++){
      if(S[j]==T[i]){
	count++;
	break;
      }
    }
  }
  printf("%d\n",count);
  return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const int MOD = 1E9 + 9;
const int INF = 1<<29; 

int main(){
    int K, X;
    cin >> K >> X;
    for(int i = (X - K + 1); i < X + K; i++){
        cout << i << ' ';
    }
    cout << endl;
}

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

int main(void) {
    int n;
    string s, t;
    cin >> n >> s >> t;
    for (int i = 0; i < n; i++) {
        if (equal(s.begin() + i, s.end(), t.begin())) {
            cout << n + i << endl;
            return 0;
        }
    }
    cout << n * 2 << endl;
}


Measured memory_bytes: 256
// Copyright (C) 2016 __debug.

// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License as
// published by the Free Software Foundation; version 3

// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with this program; If not, see <http://www.gnu.org/licenses/>.


#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cctype>
#include <climits>
#include <cassert>
#include <ctime>
#include <iostream>
#include <fstream>
#include <algorithm>
#include <functional>
#include <string>

#define x first
#define y second
#define MP std::make_pair
#define DEBUG(...) fprintf(stderr, __VA_ARGS__)
#ifdef __linux__
#define getchar getchar_unlocked
#define putchar putchar_unlocked
#endif

typedef long long LL;
typedef std::pair<int, int> Pii;

const int oo = 0x3f3f3f3f;

template<typename T> inline bool chkmax(T &a, T b) { return a < b ? a = b, true : false; }
template<typename T> inline bool chkmin(T &a, T b) { return b < a ? a = b, true : false; }
std::string procStatus()
{
    std::ifstream t("/proc/self/status");
    return std::string(std::istreambuf_iterator<char>(t), std::istreambuf_iterator<char>());
}
template<typename T> T read(T &x)
{
    int f = 1;
    char ch = getchar();
    for (; !isdigit(ch); ch = getchar())
        if (ch == '-')
            f = -1;
    for (x = 0; isdigit(ch); ch = getchar())
        x = 10 * x + ch - '0';
    return x *= f;
}
template<typename T> void write(T x)
{
    if (x == 0) {
        putchar('0');
        return;
    }
    if (x < 0) {
        putchar('-');
        x = -x;
    }
    static char s[20];
    int top = 0;
    for (; x; x /= 10)
        s[++top] = x % 10 + '0';
    while (top)
        putchar(s[top--]);
}
// EOT

const int MAXN = 1e5 + 5;

int N;
char S[MAXN];

void input()
{
    scanf("%s", S + 1);
    N = strlen(S + 1);
}

void solve()
{
    static bool can[MAXN];

    can[0] = true;
    for (int i = 1; i <= N; ++i) {
        if (i >= 5 && S[i - 4] == 'd' && S[i - 3] == 'r' && S[i - 2] == 'e' && S[i - 1] == 'a' && S[i - 0] == 'm')
            can[i] |= can[i - 5];
        if (i >= 5 && S[i - 4] == 'e' && S[i - 3] == 'r' && S[i - 2] == 'a' && S[i - 1] == 's' && S[i - 0] == 'e')
            can[i] |= can[i - 5];
        if (i >= 6 && S[i - 5] == 'e' && S[i - 4] == 'r' && S[i - 3] == 'a' && S[i - 2] == 's' && S[i - 1] == 'e' && S[i] == 'r')
            can[i] |= can[i - 6];
        if (i >= 7 && S[i - 6] == 'd' && S[i - 5] == 'r' && S[i - 4] == 'e' && S[i - 3] == 'a' && S[i - 2] == 'm' && S[i - 1] == 'e' && S[i] == 'r')
            can[i] |= can[i - 7];
    }
    puts(can[N] ? "YES" : "NO");
}

int main()
{
#ifdef __DEBUG
    freopen("C.in", "r", stdin);
    freopen("C.out", "w", stdout);
#endif

    input();
    solve();

    return 0;
}


Measured memory_bytes: 384
#include<stdio.h>

int main(){

  int a , b, c, tmp;

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

  if(a>b){
    tmp = b;
    b = a ;
    a = tmp;
    c = c ;
  }
  if(b>c){
    a = a ;
    tmp = b;
    b = c;
    c = tmp ;
  }
    if(a>b){
    tmp = b;
    b = a ;
    a = tmp;
    c = c ;
  }
    printf("%d %d %d\n",a,b,c);

  return 0;

}
  



Measured memory_bytes: 2048
def makeSet(x):
    p[x] = x
    rank[x] = 0

def union(x, y):
    link(findSet(x), findSet(y))

def link(x, y):
    if rank[x] > rank[y]:
        p[y] = x
    else:
        p[x] = y
        if rank[x] == rank[y]:
            rank[y] += 1

def findSet(x):
    if x != p[x]:
        p[x] = findSet(p[x])
    return p[x]

n,q = map(int, input().split())
p = [0]*n
rank = [0]*n

for x in range(n):
    makeSet(x)

for _ in range(q):
    com, x, y = map(int, input().split())
    if com==0:    
        union(x, y)
    else:
        if findSet(x)==findSet(y):
            print('1')
        else:
            print('0')




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

#define maxn 100010
#define INF 1e15
#define ff first
#define ss second
#define endl '\n'
typedef long long ll;

int n;
ll arr[maxn];

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0); 
  cin >> n;
  for (int i = 1; i <= n; ++i) cin >> arr[i];
  sort(arr + 1, arr + 1 + n);
  for (int i = 1; i < n; i += 2) {
    if (arr[i] <= 0 && arr[i + 1] <= 0) {
      arr[i] *= -1;
      arr[i + 1] *= -1;
    }
    else if (arr[i] < 0 && arr[i + 1] > 0){
      if (llabs(arr[i]) > llabs(arr[i + 1])) {
        arr[i] *= -1;
        arr[i + 1] *= -1;
      }
      break;
    }
    else break;
  }
  ll sum = 0;
  for (int i = 1; i <= n; ++i) sum += arr[i];
  cout << sum << endl;
}


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

int main()
{
    int n;
    cin >> n;
    vector<long long> l(n + 1);

    l[0] = 2;
    l[1] = 1;
    int i;
    for (i = 2; i <= n; i++)
    {
        l[i] = l[i - 1] + l[i - 2];
    }
    
    cout << l[n];
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define repr(i,from,to) for(int (i)=(from);(i)<(to);(i)++)
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
// const bool debug=true;
const bool debug=false;
#define DEBUG if(debug==true)
#define all(x) begin((x)), end((x))
#define vprint(x) for(auto a:(x)) cout << x << endl;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll MOD = 1000000007;
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) { a = b; return true;}
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) { a = b; return true;}
    return false;
}


int main(void) {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;cin>>n;
    vector<ll> a(n+1);
    rep(i,n+1) {cin>>a[i];}
    ll sum = 0;
    ll now = 1;
    vector<ll> csum(n+2,0);
    ll budget = 0;
    rep(i,n+1) {
        budget += a[i];
    }
    rep(i,n+1) {
        sum += now;
        if (i < n) {
            if (now < a[i]) {
                cout << -1 << endl;
                return 0;
            }
            now -= a[i];
            budget -= a[i];
            now = min(now * 2, budget);
            // cout << "a[i] : " << a[i] << endl;
    // cout << "now : " << now << endl;
        }
        else {
            if (now != a[i]) {
                cout << -1 << endl;
                return 0;
            }
        }
    }
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 4780
n = int(input())
P = list(map(int, input().split()))
P = [p-1 for p in P]

A=  list(range(1, n+1))
B = list(reversed(range(1, n+1)))

C = [0]*(n+1)
D = [0]*(n+1)
for i in range(n):
    p = P[i]
    C[p] += i+1
    C[n] -= i+1
    D[0] += i+1
    D[p+1] -= i+1
from itertools import accumulate
C = list(accumulate(C))
D = list(accumulate(D))

A_ = [0]*n
B_ = [0]*n
for i in range(n):
    A_[i] = A[i] + C[i]
    B_[i] = B[i] + D[i]

print(*A_)
print(*B_)

Measured memory_bytes: 9460
#include <bits/stdc++.h>
#define REP(i, n, s) for (int i = (s); i < (n); i++)
#define SIZE 1
using namespace std;
typedef long long int LL;
typedef long double LD;

const int MOD = 1e9 + 7;
const int MOD2 = 1e8 * 5 + 4;
const int MAXN = 5002;

int main() {
	int N;
	string S;
	scanf("%d", &N);
	cin >> S;
	int len = S.length();

	LL dp[2][MAXN];
	int idx = 0;
	dp[idx][0] = 1;
	REP(i, N + 1, 1) {
		int _idx = idx;
		idx ^= 1;
		memset(dp[idx], 0, sizeof(dp[idx]));
		dp[idx][0] = (dp[_idx][0] + dp[_idx][1]) % MOD;
		REP(j, i + 1, 1) {
			dp[idx][j] = (2 * dp[_idx][j-1] + dp[_idx][j+1]) % MOD;
		}
	}
	LL res = dp[idx][len];
	REP(i, len, 0) {
		res = (res * MOD2) % MOD;
	}

	cout << res << endl;

	return 0;
}

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

int main() {
  int a, b, c, s = 0;
  cin >> a >> b;
  for(int i = 0; i < a; i++) {
  	cin >> c;
    if(c < b - c) {
      s += c * 2;      
    }else{
      s += (b - c) * 2;
    }
  } 
  cout << s << endl;
}

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


public class Main{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
                
                int N = scan.nextInt();
                int X = scan.nextInt();
                int T = scan.nextInt();               
                
                int minute = N/X;
                int amari = N%X;
                
                if(amari!=0){
                    System.out.println(T*minute+T);
                }else{
                   System.out.println(T*minute); 
                }
        }
}

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

using namespace std;
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))
#define endl "\n"
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){os << "["; for (const auto &v : vec) {os << v << ","; } os << "]"; return os; }
template <typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &p) {os << "(" << p.first << ", " << p.second << ")"; return os;}

void solve() {
    int N, S;
    cin >> N >> S;
    vector<int> A(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
        A[i] -= S;
    }

    vector<map<ll, ll>> dp(N + 1);
    dp[0][0] = 1;
    for(int i = 0; i < N; i++) {
        for(auto e : dp[i]) {
            dp[i + 1][e.first] += dp[i][e.first];
            dp[i + 1][e.first + A[i]] += dp[i][e.first];
        }
    }

    cout << dp[N][0] - 1 << endl;
}

int main() {
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    solve();
    return 0;
}

Measured memory_bytes: 1664
import itertools

N=int(input())
P=list((map(int,input().split())))
Q=list((map(int,input().split())))
cnt=1
for u in itertools.permutations(range(1,N+1)):
    for i in range(N):
        if u[i]==P[i]:
            continue
        else:
            break
    else:
        a=cnt
    for i in range(N):
        if u[i]==Q[i]:
            continue
        else:
            break
    else:
        b=cnt
    cnt+=1
print(abs(a-b))

Measured memory_bytes: 44144
#include <iostream>
#include <stdio.h>
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>
#include <set>
#include <math.h>
#include <utility>
#include <stack>
#include <string.h>
#include <complex>
using namespace std;
const int INF = 1<<29;
const double EPS = 1e-8;

typedef vector<int> vec;
typedef pair<int,int> P;
struct edge{int to,cost;};

struct node{
    int d,c,n;
    bool operator<( const node& right ) const {
        return d == right.d ? c < right.c : d > right.d;
    }
};

int main(){
    while(1){
        int c, n, m, s, goal;
        scanf("%d%d%d%d%d",&c,&n,&m,&s,&goal);
        if(!c)break;
        s--;goal--;

        vector<vector<edge> > g(n);
        for(int i=0;i<m;i++){
            int a, b, f;
            scanf("%d%d%d",&a,&b,&f);
            a--;b--;
            g[a].push_back((edge){b,f});
            g[b].push_back((edge){a,f});
        }

        vector<vec> d(c+1,vec(n,INF));
        d[c][s] = 0;
        priority_queue<node> que;
        que.push((node){0,c,s});

        int ans = INF;
        while(que.size()){
            node p = que.top(); que.pop();
            //printf("n=%d d=%d c=%d\n",p.n,p.d,p.c);
            if(d[p.c][p.n] < p.d) continue;
            if(p.n == goal){
                ans = p.d;
                break;
            }
            for(int i=0;i<g[p.n].size();i++){
                int to = g[p.n][i].to;
                if(p.c > 0){
                    int dist_to_use_c = p.d + g[p.n][i].cost/2;
                    if(d[p.c-1][to] > dist_to_use_c){
                        d[p.c-1][to] = dist_to_use_c;
                        //printf("pushed d=%d c=%d n=%d\n",dist_to_use_c,p.c-1,to);
                        que.push((node){dist_to_use_c,p.c-1,to});
                    }
                }
                int dist_to = p.d + g[p.n][i].cost;
                if(d[p.c][to] > dist_to){
                    d[p.c][to] = dist_to;
                    //printf("pushed d=%d c=%d n=%d\n",dist_to,p.c,to);
                    que.push((node){dist_to,p.c,to});
                }
            }
        }
        cout << ans << endl;
    }

    return 0;
}

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

int main() {
    string s;
    cin >> s;

    int num = 0;

    for (int i = 0; i < s.size(); i++){
        if (s.at(i) == '+'){
            num++;
        }
        else{
            num--;
        }
    }

    cout << num << endl;
}

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

int main() {
  ios::sync_with_stdio(0); cin.tie(0);
  int n;
  cin >> n;
  vector<int> a(n);
  for(int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  vector<vector<int>> g(n);
  for(int i = 0; i < n - 1; ++i) {
    int u, v;
    cin >> u >> v;
    --u; --v;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  vector<int> ans(n);
  vector<int> lis;
  function<void(int, int)> dfs = [&] (int u, int p) {
    auto it = lower_bound(lis.begin(), lis.end(), a[u]);
    bool pb = false;
    int J = -1, store = -1;
    if(it == lis.end()) {
      lis.push_back(a[u]);
      pb = true;
    } else {
      J = it - lis.begin();
      store = lis[J];
      lis[J] = a[u];
    }
    ans[u] = lis.size();
    for(int v : g[u]) if(v != p) {
      dfs(v, u);
    }
    if(pb) lis.pop_back();
    else lis[J] = store;
  };
  dfs(0, -1);
  for(int i = 0; i < n; ++i) {
    cout << ans[i] << '\n';
  }
}

Measured memory_bytes: 32836
n = int(input())
s = input()

cnt = [[0, 0, 0] for _ in range(n)]

for i in range(n):
    cnt[i][0 if s[i] == 'R' else 1 if s[i] == 'G' else 2] += 1
    if i:
        for j in range(3):
            cnt[i][j] += cnt[i - 1][j]

res = 0
for i in range(1, n):
    for j in range(i + 1, n):
        if s[i] == s[j]: continue
        if s[i] != 'R' and s[j] != 'R':
            res += cnt[i - 1][0]
            if i + i - j >= 0: res -= s[i + i - j] == 'R'
        if s[i] != 'G' and s[j] != 'G':
            res += cnt[i - 1][1]
            if i + i - j >= 0: res -= s[i + i - j] == 'G'
        if s[i] != 'B' and s[j] != 'B':
            res += cnt[i - 1][2]
            if i + i - j >= 0: res -= s[i + i - j] == 'B'

print(res)

Measured memory_bytes: 69636
from collections import Counter

n = int(input())
v = list(map(int, input().split()))
cnt_o = Counter(v[::2]).most_common(2)
cnt_e = Counter(v[1::2]).most_common(2)
cnt_o.append((0, 0))
cnt_e.append((0, 0))

if cnt_o[0][0] != cnt_e[0][0]:
    print(n - cnt_o[0][1] - cnt_e[0][1])
else:
    del1 = cnt_o[0][1] - cnt_o[1][1]
    del2 = cnt_e[0][1] - cnt_e[1][1]
    print(n - cnt_o[0][1] - cnt_e[0][1] + min(del1, del2))

Measured memory_bytes: 15588
#include <stdio.h>
#include <utility>
using namespace std;
void plus(pair<int,int> temp,int dp[],int n,int t){
    temp.first*=t;
    temp.second*=t;
    while(n>=temp.first){
        if(temp.second+dp[n-temp.first]>dp[n])dp[n]=temp.second+dp[n-temp.first];
        n--;
    }
}
int main(){
    int n,m,t,dp[100010],now;
    pair<int,int>temp;
    scanf("%d%d",&n,&m);
    for(int i=0;i<=n;i++)dp[i]=0;
    while(n--){
        scanf("%d%d%d",&temp.second,&temp.first,&t);
        now=1;
        while(now<=t){
            plus(temp,dp,m,now);
            t-=now;
            now*=2;
        }
        if(t>0)plus(temp,dp,m,t);
    }
    printf("%d\n",dp[m]);
}

Measured memory_bytes: 2772
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;

int main(void){
    int time[5];
    int check[5];
    int count = 0;
    int ans = 0;
    for(int i = 0; i < 5; i++){
        cin >> time[i];
        if(time[i]%10==0)
            ans += time[i];
        else if(time[i]%10!=0){
            check[count] = time[i];
            count++;
        }
    }
    
    for(int i = 0; i < count-1; i++){
        for(int j = i+1; j < count; j++)
            if(check[i]%10 < check[j]%10)
                swap(check[i], check[j]);
    }
    for(int i = 0; i < count-1; i++)
        ans += check[i]+10-(check[i]%10);
    
    ans += check[count-1];
    cout << ans << endl;
    return 0;
}


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

signed main(){
	int n,m;cin>>n>>m;
	vector<int>x(n);
	for(auto&& u:x)cin>>u;
	map<int,vector<int>> div;
	for(auto&& u:x)div[u%m].push_back(u);
	int ret=0;
	ret+=div[0].size()/2;
	if(m%2==0)ret+=div[m/2].size()/2;
	for(int i=1;i<=(m-1)/2;i++){
		int x=i,y=m-x;
		int nx=div[x].size(),ny=div[y].size();
		if(nx>ny){swap(x,y);swap(nx,ny);}
		ret+=nx;
		int pr=0;
		map<int,int>cnt;
		for(auto&& u:div[y])cnt[u]++;
		for(auto&& u:cnt)pr+=u.second/2;
		ret+=min((ny-nx)/2,pr);
	}
	cout<<ret<<endl;

}


Measured memory_bytes: 11904
while True:
    # カードを受け取る
    inp = input()
    if inp == "-":
        break
    card = list(inp)
    # シャッフル回数を受け取る
    shuffle = int(input())
    # hを受け取って処理実行
    hsum = 0
    for i in range(shuffle):
        h = int(input())
        hsum += h
    len_card = 0
    len_card = len(card)
    diff = hsum - len_card
    while diff > len_card:
        diff -= len_card
    if hsum > len_card:
        result = card[diff:] + card[:diff]
    else:
        result = card[hsum:] + card[:hsum]
    print("".join(result))
    continue


Measured memory_bytes: 5596
def main():
    """
    a % d + c % d = (a + c) % dだ
    整数の余りを取るのと，整数の各桁の余りを取るのが同じこともあった　→　Digits Parade
    """
    N = int(input())
    X = input()
    t = X.count("1")
    v1, v2 = int(X, 2) % (t+1), int(X, 2) % (t-1) if t != 1 else 0
    for i in range(N):
        ans = 1
        x = 0
        if X[i] == "0":
            # 反転してt+1
            x = v1 + pow(2, N-i-1, t+1)
            x %= t+1
        elif t != 1 and X[i] == "1":
            # 反転してt-1
            x = v2 - pow(2, N-i-1, t-1)
            x %= t-1
        else:
            # t == 1 かつ その"1"を反転するとき
            # 当然X_iは0になる，答えも0
            ans = 0
        while x > 0:
            x %= "{:0b}".format(x).count("1")
            ans += 1
        print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 82892
import sys
sys.setrecursionlimit(10 ** 9)
input = sys.stdin.readline
from itertools import permutations,  combinations, accumulate
from functools import *
from collections import deque, defaultdict, Counter
from heapq import heapify, heappop, heappush, heappushpop
import numpy as np

INF = float('inf')
NIL = - 1

""" Input
S = input().rstrip()
N, A, B = map(int, input().split())
D = [int(input()) for _ in range(N)]
"""
N = int(input())
A = list(map(int, input().split()))

arr = np.array(A)
arr = 1 / arr
print(1 / sum(arr))




# def main():


# if __name__ == '__main__':
#     main()


Measured memory_bytes: 12004
import math
a, b, C =[float(_) for _ in input().split()]
c = math.sqrt(math.pow(a,2)+math.pow(b,2)-2*a*b*math.cos(math.radians(C)))
L = a + b + c
h = b * math.sin(math.radians(C))
S = a * h / 2
print("%f\n%f\n%f" % (S,L,h))


Measured memory_bytes: 5708
#include <bits/stdc++.h>
using namespace std;
int main(void){
    string s;
    cin>>s;
    for (int i=0;i<s.size();i++) {
        if (s[i]=='?') {
            cout<<"D";
        } else {
            cout<<s[i];
        }
    }
    cout<<endl;
}

Measured memory_bytes: 3712
import math
import queue
import bisect
import heapq
import time
import itertools

mod = int(1e9+7)

def swap(a,b):
    return (b,a)

def gcd(a,b): #最大公約数
    if (a<b):
        a,b = swap(a,b)
    if (b==0):
        return a
    else:
        return gcd(b,a%b)

def lcm(a,b): #最小公倍数
    return a/gcd(a,b)*b

def divisors(a): # 約数列挙
    divisors = []
    for i in range(1,int(a**0.5)+1):
        if a%i==0:
            divisors.append(i)
            if i!=a//i:
                divisors.append(a//i)
    return divisors

def is_prime(a): #素数判定
    if a<2:
        return False
    elif a==2:
        return True
    elif a%2==0:
        return False
    sqrt_num = int(a**0.5)
    for i in range(3,sqrt_num+1,2):
        if a%i==0:
            return False
    return True

def prime_num(a): #素数列挙
    pn = [2]
    for i in range(3,int(a**0.5),2):
        prime = True
        for j in pn:
            if i%j==0:
                prime = False
                break
        if prime:
            pn.append(i)
    return pn

def prime_fact(a): #素因数分解
    sqrt = math.sqrt(a)
    res = []
    i = 2
    if is_prime(a):
        res.append(a)
    else:
        while a!=1:
            while a%i==0:
                res.append(i)
                a //= i
            i += 1
    return res

def main():
    x = int(input())
    a = int(input())
    b = int(input())
    x -= a
    x %= b
    print(x)
    return

if __name__=='__main__':
    main()


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

void dfs(int num, map<int, set<int>>& mp, vector<bool>& bmp)
{
    if(bmp[num]) return;
    bmp[num] = true;
    for(auto itr = mp[num].begin(); itr != mp[num].end(); itr++)
    {
        dfs(*itr, mp, bmp);
    }
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N, M;
    cin >> N >> M;
    vector<int> X(M), Y(M), Z(M);
    map<int, set<int>> mp;
    for(int i=0; i<M; i++)
    {
        cin >> X[i] >> Y[i] >> Z[i];
        X[i]--; Y[i]--;
        mp[X[i]].insert(Y[i]);
        mp[Y[i]].insert(X[i]);
    }

    vector<bool> bmp(N, false);
    int cls = 0;
    for(int i=0; i<M; i++)
    {
        if(bmp[X[i]] && bmp[Y[i]]) continue;
        cls++;
        dfs(X[i], mp, bmp);
    }
    int ans = cls;
    for(int i=0; i<N; i++) if(!bmp[i]) ans++;

    cout << ans << endl;

    return 0;
}


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

int main() {
  int A,B,M;
  cin >> A >> B >> M;
  
  vector<int> a(A);
  for (int i = 0; i < A; i++) {
    cin >> a.at(i);
  }
  
  vector<int> b(B);
  for (int i = 0; i < B; i++) {
    cin >> b.at(i);
  }
  
  vector<int> x(M);
  vector<int> y(M);
  vector<int> c(M);
  for (int i = 0; i < M; i++) {
    cin >> x.at(i) >> y.at(i) >> c.at(i);
  }
  
  vector<int> z(M);
  for (int i = 0; i < M; i++) {
    z.at(i) = a.at(x.at(i)-1) + b.at(y.at(i)-1) - c.at(i);
  }
  
  sort(z.begin(), z.end());
  sort(a.begin(), a.end());
  sort(b.begin(), b.end());
  
  if (z.at(0) < a.at(0) + b.at(0)){
    cout << z.at(0) << endl;
  }
  else {
    cout << a.at(0) + b.at(0) << endl;
  }
}
  
  
  
 

Measured memory_bytes: 2560
ans = 0
N = int(input())
a1 = list(map(int, input().split()))
a2 = list(map(int, input().split()))
for i in range(1, N + 1):
    ans = max(ans, sum(a1[0:i]) + sum(a2[i - 1 : N + 1]))

print(ans)


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

int main() {
  int N, L;
  cin >> N >> L;
  int sum = ((N * (N + 1)) / 2) + (L - 1) * N;
  vector<int> A(N);
  vector<int> B(N);
  for (int i = 0; i < N; i++) {
    A[i] = L + i;
    B[i] = A[i];
    if (A[i] < 0) {
      A[i] *= -1;
  }
  }
  sort(A.begin(), A.end());
  if (B[N-1] < 0) {
  cout << sum + A[0] << endl;
  }
  else {
  cout << sum - A[0] << endl;
  }
}
    

Measured memory_bytes: 256
N = int(input())
def to_bit(num,digit = 3,N = 4):
    bit = [0] * digit
    for i in range(digit):
        bit[i] = num % N
        num = int((num - (num % N)) / N)
    bit[0],bit[2] = bit[2],bit[0] 
    return bit

DP_map = [[0] * 64 for _ in range(100)]
'''
A = 0
C = 1
G = 2
T = 3

NG in 3 char
AGC = 0 * 16 + 2 * 4 + 1 * 1 = 9
ACG = 0 * 16 + 1 * 4 + 2 * 1 = 6
GAC = 2 * 16 + 0 * 4 + 1 * 1 = 33
'''
DP_map[0] = [1] * 64
DP_map[0][6] = 0
DP_map[0][9] = 0
DP_map[0][33] = 0

C_NG = [9,33]
for i in range(N - 2):
    for j in range(64):
        bit = to_bit(j)
        now = DP_map[i][j]
        added_A = bit[1] * 16 + bit[2] * 4 + 0
        added_C = bit[1] * 16 + bit[2] * 4 + 1
        added_G = bit[1] * 16 + bit[2] * 4 + 2
        added_T = bit[1] * 16 + bit[2] * 4 + 3
        DP_map[i + 1][added_A] = (DP_map[i + 1][added_A] + now) % (int(1e9 + 7))
        DP_map[i + 1][added_T] = (DP_map[i + 1][added_T] + now) % (int(1e9 + 7))
        if added_G != 6:
            DP_map[i + 1][added_G] = (DP_map[i + 1][added_G] + now) % (int(1e9 + 7))

        if (added_C not in C_NG) and (bit[0] != 0 or (bit[2] != 2 and bit[1] != 2)):
            DP_map[i + 1][added_C] = (DP_map[i + 1][added_C] + now) % (int(1e9 + 7))


#print(DP_map[1])
print(sum(DP_map[N-3]) % (int(1e9 + 7)))



Measured memory_bytes: 41324
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(i=0;i<n;i++)
#define loop(i,a,n) for(i=a;i<n;i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

typedef vector<int> vi;
typedef pair<int,int> pii;

int main(void) {
  int i,j,k,l;
  vector<string> s(8);
  rep(i,8)cin>>s[i];
  rep(k,64){//odd:x even:o 
    int m=0;//num of reversible place
    vector<vi> num(8,vi(8,0));
    int dx[8]={-1,-1, 0, 1, 1, 1, 0,-1};
    int dy[8]={ 0, 1, 1, 1, 0,-1,-1,-1};
    rep(i,8)rep(j,8){
      if(s[i][j]!='.')continue;
      rep(l,8){
	int a=1;
	bool r=false;
	while(1){
	  int nx=i+dx[l]*a;
	  int ny=j+dy[l]*a;
	  if(nx<0 || nx>7 || ny<0 || ny>7 || s[nx][ny]=='.')break;
	  if((k%2 && s[nx][ny]=='o') ||(k%2==0 && s[nx][ny]=='x'))r=true;
	  if((k%2 && s[nx][ny]=='x') ||(k%2==0 && s[nx][ny]=='o')){
	    if(r)num[i][j]+=a-1;
	    break;
	  }
	  a++;
	}
      }
      m=max(m,num[i][j]);
    }
    if(m==0)continue;
    if(k%2){//'x'
      for(i=7;i>=0;i--)for(j=7;j>=0;j--)if(num[i][j]==m){
	    rep(l,8){
	      int a=1;
	      while(1){
		int nx=i+dx[l]*a;
		int ny=j+dy[l]*a;
		if(nx<0 || nx>7 || ny<0 || ny>7 || s[nx][ny]=='.')break;
		if(k%2 && s[nx][ny]=='x'){
		  for(;a>=0;a--)s[i+dx[l]*a][j+dy[l]*a]='x';
		  break;
		}
		a++;
	      }
	    }
	    goto END;
	  }
    }else{//'o'
      rep(i,8)rep(j,8)if(num[i][j]==m){
	    rep(l,8){
	      int a=1;
	      while(1){
		int nx=i+dx[l]*a;
		int ny=j+dy[l]*a;
		if(nx<0 || nx>7 || ny<0 || ny>7 || s[nx][ny]=='.')break;
		if(k%2==0 && s[nx][ny]=='o'){
		  for(;a>=0;a--)s[i+dx[l]*a][j+dy[l]*a]='o';
		  break;
		}
		a++;
	      }
	    }
	    goto END;
	  }
    }
  END:;
  }
  rep(i,8)cout<<s[i]<<endl;
}

Measured memory_bytes: 3180
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> lpair;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define rREP(i,m,n) for(ll i = (m); i >= (n); i--)
#define ALL(c) (c).begin(), (c).end()
#define print(x) cout << (x) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " ";} cout<<endl;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n,m;
    cin >> n >> m;
    cout << max(0, n * (n-1) / 2) + max(0, m * (m-1) / 2) << endl;
    
}




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

int W,H,map[20][20];
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};

void dfs(int x,int y) {
	map[x][y]=0;
	for(int i=0;i<4;i++) {
		int nx=x+dx[i],ny=y+dy[i];
		if(0<=nx&&nx<W&&0<=ny&&ny<H&&map[nx][ny]=='.') dfs(nx,ny);
	}
}

int main() {
	int x,y;
	while(scanf("%d %d",&W,&H),W||H) {
		getchar();
		for(int j=0;j<H;j++) {
			for(int i=0;i<W;i++) {
				map[i][j]=getchar();
				if(map[i][j]=='@') {
					map[i][j]='.';
					x=i,y=j;
				}
			}
			getchar();
		}
		dfs(x,y);
		int ans=0;
		for(int j=0;j<H;j++) {
			for(int i=0;i<W;i++) {
				ans+=!map[i][j];
			}
		}
		printf("%d\n",ans);
	}
}

Measured memory_bytes: 1040