akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
string s;
int len,pos,bug;
map<string,int> size;
map<string, map<int,int> > a;

int getNum(){
  int res=0;
  while('0'<=s[pos]&&s[pos]<='9')
    res=res*10+(s[pos++]-'0');
  return res;
}

string getName(){
  string res="";
  while(s[pos]!='[')res+=s[pos++];
  return res;
}

int solve1(){
  if('0'<=s[pos]&&s[pos]<='9')
    return getNum();
  string str=getName();
  pos++;
  int id=solve1();
  pos++;
  if(a[str].count(id)==0)bug=1;
  return a[str][id];
}

void solve0(){
  for(int i=0;i<(int)s.size();i++){
    if(s[i]=='['){
      pos=i+1;
      size[s.substr(0,i)]=getNum();
    }
  }
}

int solve(){
  int flg=-1;
  for(int i=0;i<(int)s.size();i++)
    if(s[i]=='=')flg=i;
  
  if(flg==-1){   solve0();  return false;  }
  
  string tmp=s;
  s=tmp.substr(flg+1);
  
  bug=pos=0;
  int res= solve1();
  if(bug)return true;
  
  bug=pos=0;
  s=tmp.substr(0,flg);
  string target=getName();
  pos++;
  int index=solve1();
  if(bug)return true;
  if(size[target]<=index||index<0)return true;
  a[ target ][ index ] = res;
  return false;
}

void init(){
  size.clear();
  a.clear();
}

int main(){
  while(1){
    init();
    int ans=0;
    for(int tc=1;;tc++){
      cin>>s;
      if(tc==1&&s==".")return 0;
      if(s==".")break;
      if(ans)continue;
      if(solve())ans=tc;
    }
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 1260
#include <iostream>
#include <vector>

using namespace std;

inline int Lsb(int num)
{
    return num & -num;
}

class Bit
{
public:
    Bit(int size) : bit_(size + 1, 0) {}

    void Add(int pos)
    {
        while (pos < (int)bit_.size()) {
            bit_[pos] += 1;
            pos += Lsb(pos);
        }
    }

    int Count(int pos) const
    {
        int count = 0;
        while (pos > 0) {
            count += bit_[pos];
            pos -= Lsb(pos);
        }
        return count;
    }

private:
    vector<int> bit_;
};

class Bit2D
{
public:
    Bit2D(int size, int inner_size) : bit_(size + 1, Bit(inner_size)) {}

    void Add(int x, int y)
    {
        while (x < (int)bit_.size()) {
            bit_[x].Add(y);
            x += Lsb(x);
        }
    }

    int Count(int x, int y) const
    {
        int count = 0;
        while (x > 0) {
            count += bit_[x].Count(y);
            x -= Lsb(x);
        }
        return count;
    }

private:
    vector<Bit> bit_;
};

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

    Bit2D bit(n, n);
    for (int i = 0; i < m; i += 1) {
        int left, right;
        cin >> left >> right;
        bit.Add(left, right);
    }

    for (int i = 0; i < q; i += 1) {
        int left, right;
        cin >> left >> right;

        int res = bit.Count(right, right) - bit.Count(left - 1, right);
        cout << res << "\n";
    }
    return 0;
}


Measured memory_bytes: 1920
from collections import defaultdict

MOD = 1000000007


def prime_generator(limit):
    yield 2
    n, h = 3, {}
    while n <= limit:
        m = n
        if n in h:
            b = h[n]
            m += 2 * b
            while m in h:
                m += 2 * b
            h[m] = b
            del h[n]
        else:
            m += 2 * n
            while m in h:
                m += 2 * n
            h[m] = n
            yield n
        n += 2


def solve(n):
    ps = list(prime_generator(n))
    factors = defaultdict(int)
    for i in range(1, n):
        k = i + 1
        for p in ps:
            while k % p == 0:
                k //= p
                factors[p] += 1
            if k == 1:
                break

    ans = 1
    for c in factors.values():
        ans *= c + 1
        ans %= MOD
    return ans


print(solve(int(input())))


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

namespace Contest
{
	class Program
	{
		static void Main()
		{
            var AB = Console.ReadLine().Split().Select(int.Parse);
            int A = AB.First(), B = AB.Last();
            if (AB.Any(item => item % 3 == 0) || AB.Sum() % 3 == 0)
            {
                Console.WriteLine("Possible");
            }
            else
            {
                Console.WriteLine("Impossible");
            }
#if DEBUG
            Console.ReadKey();
#endif
		}
	}
}

Measured memory_bytes: 11348
//{{{
#include<algorithm>
#include<cmath>
#include<deque>
#include<fstream>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<random>
#include<set>
#include<sstream>
#include<sys/time.h>
#include<unordered_map>
#include<unordered_set>
#include<vector>
using ll = long long;
enum : ll { M = 998244353 };
using namespace std;
#ifdef LOCAL
#include"rprint2.hpp"
#else
#define FUNC(name) template <ostream& out = cout, class... T> void name(T&&...){ }
FUNC(printde) FUNC(printdbe) FUNC(printdwe) FUNC(printdu) FUNC(printe) FUNC(printe0);
#endif
template <template <class T, class = std::allocator<T>> class V, class E>
istream& operator >> (istream& in, V<E>& v){ for(auto& e : v){ in >> e; } return in; }
//}}}

ll dp[3002][3002];
int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    dp[a][b] = 1;
    for(int i = a; i <= c; i++){
        for(int j = b; j <= d; j++){
            dp[i][j] += dp[i - 1][j] * j + dp[i][j - 1] * i
                - dp[i - 1][j - 1] * (i - 1) * (j - 1) + M * 3000 * 3000;
            dp[i][j] %= M;
        }
    }
    cout << dp[c][d] << '\n';
}


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

#define REP(i, m, n) for (int i = (m); i < (int)(n); i++)
#define REPS(i, m, n) for (int i = (m); i <= (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define reps(i, n) for (int i = 0; i <= (int)(n); i++)
#define rrep(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define rreps(i, x) for (int i = (int)(x); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
#define fi first
#define se second
typedef long long ll;
typedef pair<int, int> P;
const int inf = INT_MAX;
const ll INF = 1LL << 60;
const ll mod = 1e9 + 7;
const double EPS = 1e-10;
const double PI = acos(-1.0);
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val) { fill( (T*)array, (T*)(array+N), val ); }


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

    int N; cin >> N;
    string S; cin >> S;
    int ns = S.size();
    rep(i, ns) {
        if (char(S[i] + N) - 'A' < 26) {
            cout << char(S[i] + N);
        } else {
            cout << char(S[i] + N - 26);
        }
    }
    cout << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string.h>
#include <algorithm>

const long long INF = __LONG_LONG_MAX__;

using namespace std;

int main() {
    int N, A, B;
    cin >> N;
    cin >> A;
    cin >> B;

    int a, b;
    a = A * N;
    b = B;

    if (a > b) {
        cout << b << endl;
    } else {
        cout << a << endl;
    }

    return 0;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"math"
	"math/bits"
	"os"
	"strconv"
)

func configure(scanner *bufio.Scanner) {
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1000005), 1000005)
}
func getNextString(scanner *bufio.Scanner) string {
	scanned := scanner.Scan()
	if !scanned {
		panic("scan failed")
	}
	return scanner.Text()
}
func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}
func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}
func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}
func main() {
	fp := os.Stdin
	wfp := os.Stdout
	extra := 0
	if os.Getenv("I") == "IronMan" {
		fp, _ = os.Open(os.Getenv("END_GAME"))
		extra = 100
	}
	scanner := bufio.NewScanner(fp)
	configure(scanner)
	writer := bufio.NewWriter(wfp)
	defer func() {
		r := recover()
		if r != nil {
			fmt.Fprintln(writer, r)
		}
		writer.Flush()
	}()
	solve(scanner, writer)
	for i := 0; i < extra; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
}
func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	n := getNextInt(scanner)
	xx := make([]int64, n)
	yy := make([]int64, n)
	pp := make([]int64, n)
	for i := 0; i < n; i++ {
		xx[i] = getNextInt64(scanner)
		yy[i] = getNextInt64(scanner)
		pp[i] = getNextInt64(scanner)
	}
	ns := makeGrid(1<<uint(n), n)
	ew := makeGrid(1<<uint(n), n)
	for i := 0; i < 1<<uint(n); i++ {
		for j := 0; j < n; j++ {
			nsmin := abs(xx[j])
			ewmin := abs(yy[j])
			for k := 0; k < n; k++ {
				if i>>uint(k)&1 == 0 {
					continue
				}
				chmin(&nsmin, abs(xx[j]-xx[k]))
				chmin(&ewmin, abs(yy[j]-yy[k]))
			}
			ns[i][j] = nsmin
			ew[i][j] = ewmin
		}
	}
	ans := make([]int64, n+1)
	for i := 0; i < n+1; i++ {
		ans[i] = math.MaxInt64
	}
	for i := 0; i < 1<<uint(n); i++ {
		c := bits.OnesCount32(uint32(i))
		for j := 0; j < 1<<uint(n-c); j++ {
			a := int64(0)
			ewbit := 0
			x := i
			y := j
			for k := 0; k < n; k++ {
				if x&1 == 0 {
					if y&1 == 1 {
						ewbit = ewbit | (1 << uint(k))
					}
					y >>= 1
				}
				x >>= 1
			}
			for k := 0; k < n; k++ {
				a += min(ns[i][k], ew[ewbit][k]) * pp[k]
			}
			cc := bits.OnesCount32(uint32(j))
			chmin(&ans[c+cc], a)
		}
	}
	for i := 0; i < n+1; i++ {
		fmt.Fprintln(writer, ans[i])
	}
}

func min(a, b int64) int64 {
	if a < b {
		return a
	}
	return b
}
func abs(a int64) int64 {
	return -min(a, -a)
}
func chmin(a *int64, b int64) {
	*a = min(*a, b)
}
func makeGrid(h, w int) [][]int64 {
	index := make([][]int64, h, h)
	data := make([]int64, h*w, h*w)
	for i := 0; i < h; i++ {
		index[i] = data[i*w : (i+1)*w]
	}
	return index
}


Measured memory_bytes: 11412
import java.util.Scanner;

class Main {
	public static void main(String args[]) {
		StringBuilder sb = new StringBuilder();
		Scanner sc = new Scanner(System.in);
		char[] s = sc.next().toCharArray();
		for (int i = 0; i < s.length; i++) {
			if (s[i] == '1') {
				sb.append("9");
			} else if (s[i] == '9') {
				sb.append("1");
			} else {
				sb.append(s[i]);
			}
		}
		System.out.println(sb);
	}
}

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

int main(){
  int i,kotae=0;
  string s;
  cin>>s;
  for(i=0;;i++){
    if(s[i]=='\0'){
      break;
    }
    if(i%2==0&&s[i]=='L'){
      kotae=1;
    }
    if(i%2==1&&s[i]=='R'){
      kotae=1;
    }
  }
  if(kotae){
    cout<<"No";
  }else{
    cout<<"Yes";
  }
}


Measured memory_bytes: 256
mod io{
    use std::io::*;
    pub fn read<T: ::std::str::FromStr>()->T{
        let stdin=stdin();
        let ret=stdin.lock().bytes().map(|c|c.unwrap()as char)
        .skip_while(|c|c.is_whitespace())
        .take_while(|c|!c.is_whitespace())
        .collect::<String>().parse().ok().unwrap();
        ret
    }
}
use io::read;
fn main(){
    println!("{}",((read::<i64>()-2)*(read::<i64>()-2)).abs())
}

Measured memory_bytes: 4352
h,w= map(int,input().split())
ans = h*w

if h % 3 == 0 or h % 3 == 0:
    print(0)
    exit()
for i in range(1,w):
    H1, H2= h//2, -(-h//2)
    check = max(h*i,H2*(w-i),H1*(w-i))
    check2 = min(h*i,H1*(w-i),H2*(w-i))
    ans = min(ans,abs(check-check2))
for i in range(1,h):
    w1,w2 = w//2, -(-w//2)
    check = max(w*i,w1*(h-i),w2*(h-i))
    check2 = min(w*i,w1*(h-i),w2*(h-i))
    ans = min(ans,abs(check-check2))
print(min(ans,h,w))

Measured memory_bytes: 3064
import java.util.*;

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

      int a = sc.nextInt();
      String s = sc.next();

      int ans = 0;



      if(a>=3200){
        System.out.println(s);
      }
      else{
        System.out.println("red");
      }

    }
}


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

int main(){
  string S;
  cin>>S;
  if(S.at(0)=='S') cout<<"Cloudy"<<endl;
  else if(S.at(0)=='C') cout<<"Rainy"<<endl;
  else if(S.at(0)=='R') cout<<"Sunny"<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
string s,t;
int a[100005][26];
bool exi[100005];
ll ans;
int cur = -1;
const int inf = 0x7f7f7f7f;
int main()
{
	cin >> s >> t;
	
	if (s.size() == 1)
	{
		for (int i = 0;i < t.size();i++)
		{
			if (t[i] != s[0])
			{
				puts("-1");
				exit(0);
			}
		}
		cout << t.size() << endl;
		exit(0);
	}
	for (int i = 0;i < s.size();i++)
	{
		exi[s[i] - 'a'] = 1;
	}
	memset(a,0x7f,sizeof(a));
	memset(a[0],0,sizeof(a[0]));
	for (int i = s.size() - 2;i >= 0;i--)
	{
		for (int j = 0;j < 26;j++)
		{
		    a[i][j] = a[i + 1][j];
		    if (s[i + 1] == j + 'a')
		        a[i][j] = i + 1;
		}
	}
	if (!exi[t[0] - 'a']) 
	{
	    puts("-1");
		exit(0);
	}
	if (s[0] == t[0]) cur = 0;
	else cur = a[0][t[0] - 'a'];
	for (int i = 1;i < t.size();i++)
	{
		if (!exi[t[i] - 'a'])
		{
	        puts("-1");
		    exit(0);
	    }
		if (a[cur][t[i] - 'a'] == inf) 
		{
			ans++;
			if (s[0] == t[i]) cur = 0;
			else cur = a[0][t[i] - 'a'];
		}
		else
		    cur = a[cur][t[i] - 'a'];
	}
	cout << ans * s.size() + cur + 1 << endl;
	return 0;
}


Measured memory_bytes: 10752
package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	sc.Split(bufio.ScanWords)
	d := nextInt()

	c := make([]int, 26)
	for i := 0; i < 26; i++ {
		c[i] = nextInt()
	}

	s := make([][]int, d)
	for i := 0; i < d; i++ {
		s[i] = make([]int, 26)
		for j := 0; j < 26; j++ {
			s[i][j] = nextInt()
		}
	}

	t := make([]int, d)
	for i := 0; i < d; i++ {
		t[i] = nextInt()
	}

	tmp := make([]int, 26)
	var satis int
	for i := 0; i < d; i++ {
		tk := t[i] - 1
		satis += s[i][tk]

		var nega int
		for k, _ := range tmp {
			if k == tk {
				tmp[k] = 0
			} else {
				tmp[k]++
				nega += tmp[k] * c[k]
			}
		}
		satis -= nega
		fmt.Println(satis)
	}
}

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


Measured memory_bytes: 1924
N = gets.to_i

pf = [0] * (N + 1)
2.upto(N) do |m|
  2.upto(m) do |i|
    next if m == 1
    while m % i == 0
      m /= i
      pf[i] += 1
    end
  end
end

a = pf.count{|k| k >= 74}
b = pf.count{|k| k >= 24}
c = pf.count{|k| k >= 14}
d = pf.count{|k| k >= 4}
e = pf.count{|k| k >= 2}

p a + b * (e - 1) + c * (d - 1) + d * (d - 1) / 2 * (e - 2)

Measured memory_bytes: 1916
M1,D1=map(int,input().split())
M2,D2=map(int,input().split())
if (M1 in [1,3,5,7,8,10] and D1==31) or (M1 in [4,6,9,11] and D1==30) or (M1==2 and D1==28):
    print("1")
else:
    print("0")


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

using namespace std;

#define int long long
#define endl '\n'
#define maxn 100010
const int MOD = 1000000007;

void solve() {
    string s;
    cin >> s;

    if (s.back() == 's')cout << s << "es" << endl;
    else cout << s << 's' << endl;
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int t = 1;
//    cin >> t;

    while (t--)
        solve();
    return 0;
}

Measured memory_bytes: 3656
#include<stdio.h>

int main()
{
    char a[1200],c;
    int i,j=0;
    while((c=getchar())!=EOF){
    a[j]=c;
    j++;
    }
    for(i=0;i<=j;i++){
    if(a[i]>='A'&&a[i]<='Z'){
    a[i]+='a'-'A';
    }else if(a[i]>='a'&&a[i]<='z'){
    a[i]-='a'-'A';
    }
    }
    for(i=0;i<j;i++){
    printf("%c",a[i]);
    }
    return 0;
}


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

public class Main {

	public static void main(String[] args) throws IOException{

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		while(true){
			String str =  br.readLine();
			if(str == null || str == ""){
				break;
			}
			String[] str1Ary = str.split(" ");
			long a = Integer.parseInt(str1Ary[0]);
			long b = Integer.parseInt(str1Ary[1]);
			System.out.println(getGCD(a, b) + " " + getLCM(a, b));
		}
	}

	private static long getGCD(long a, long b){
		long r;
		while ((r = a % b) != 0) {
			a = b;
			b = r;
		}
		return b;
	}

	private static long getLCM(long a, long b) {
		return a * b / getGCD(a, b);
	}
}

Measured memory_bytes: 17092
#include <iostream>
using namespace std;
int main() {
  int n,k;
  cin >> n >> k;
  int ans = 0;
  for (int i = 0; i < n; i++) {
    int h;
    cin >> h;
    if (h >= k) ans++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3644
/*
 * atcoder/abc130/a.cpp
 */

// C++ 14
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstring> // memset
#include <cassert>

using namespace std;

#define ll long long

#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)
template <class T> bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false; }
template <class T> bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false; }

int H, W, h, w;
void input() {
  cin >> H >> W >> h >> w;
}

void solve() {
  cout << (H*W) - (h*W+H*w-h*w) << endl;
}

int main() {
  // cout.precision(15);
  input();
  solve();
  return 0;
}


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

int main(){
  	int N;
  	cin >> N;
  	vector<int> a(N);
  	for (int i = 0; i < N; i++) cin >> a[i];
  	cout << *max_element(a.begin(), a.end()) - *min_element(a.begin(), a.end()) << endl;
}

Measured memory_bytes: 3580
n = int(input())
A = list(map(int, input().split()))
ans = 1
p = m = 0
c = A[0]
for i in A[1:]:
    if i > c:
        p = 1
    elif i < c:
        m = 1
    if p == 1 and m == 1:
        p = m = 0
        ans += 1
    c = i
print(ans)

Measured memory_bytes: 19812
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <stdio.h>
#include <cmath>
#include <cctype>
#include <map>

const int INT_INF = 1000000000;                 // 10^9
const long long LONG_INF = 1000000000000000000; // 10^18

using namespace std;

int main()
{
    int n;
    cin >> n;
    int sum = 0;
    vector<int> v(n);
    for (int i = 0; i < n; i++)
    {
        cin >> v[i];
        sum += v[i];
    }

    int sub = 0;
    int m = INT_INF;
    for (int i = 0; i < n; i++)
    {
        sub += v[i];
        int temp = abs(sum - (sub * 2));
        m = min(m, temp);
    }

    cout << m << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cmath>
#include <iomanip>
#include <string>

typedef long long ll;
using namespace std;
const int mod = 1000000007;

int main() {
    int N; cin >> N;
    vector<int> v(N);
    iota(v.begin(), v.end(), 1);       // v に 1, 2, ... N を設定
    vector<int> R(N, 0), Q(N, 0);

    for (int j = 0; j < N; j++) {
            cin >> R[j];
    }
    for (int j = 0; j < N; j++) {
            cin >> Q[j];
    }

    int r, q;
    int cnt = 1;
    do {
        if (v == R) r = cnt;
        if (v == Q) q = cnt;
        cnt++;
    } while( next_permutation(v.begin(), v.end()) );     // 次の順列を生成

    cout << abs(r - q) << '\n';
    return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Collections;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.IO;
static class Program{
	const int mod=(int)1e9+7;
	static void Main(){
		Sc sc=new Sc();
		int[] s=sc.Ia;
		Uf uf=new Uf(s[0]+1);
		for(int i = 0;i<s[1];i++) {
			int[] e=sc.Ia;
			uf.Union(e[0],e[1]);
		}
		Console.WriteLine(uf.all-1);
	}
}
public class Uf{
	private int[] arr,hi;
	public int all;
	public Uf(int n){
		arr=new int[n];
		hi=new int[n];
		all=n;
		for(int i=0;i<n;i++){arr[i]=-1;}
	}
	public void Union(int a,int b){
		a=Root(a);
		b=Root(b);
		if(a!=b){
			if(hi[a]<hi[b]){
				int v=b;
				b=a;
				a=v;
			}
			arr[a]+=arr[b];
			hi[a]=Math.Max(hi[a],hi[b]+1);
			arr[b]=a;
			all--;
		}
	}
	public bool Same(int a,int b){return Root(a)==Root(b);}
	public int Total(int a){return -arr[Root(a)];}
	public int Root(int a){return arr[a]<0?a:arr[a]=Root(arr[a]);}
}

public class Sc{
	private string[] a;
	private int n=-1,m=0;
	public int I{get{if(n==-1||n==a.Length-1){n=-1;a=Console.ReadLine().Split();}n++;return int.Parse(a[n]);}}
	public long L{get{if(n==-1||n==a.Length-1){n=-1;a=Console.ReadLine().Split();}n++;return long.Parse(a[n]);}}
	public double D{get{if(n==-1||n==a.Length-1){n=-1;a=Console.ReadLine().Split();}n++;return double.Parse(a[n]);}}
	public string S{get{if(n==-1||n==a.Length-1){n=-1;a=Console.ReadLine().Split();}n++;return a[n];}}
	public int[] Ia{get{if(n!=-1&&n!=a.Length-1){m=n;n=-1;return Array.ConvertAll(a.Skip(m+1).ToArray(),int.Parse);}return Array.ConvertAll(Console.ReadLine().Split(),int.Parse);}}
	public int[] Ia2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),int.Parse);}}
	public long[] La{get{return Array.ConvertAll(Console.ReadLine().Split(),long.Parse);}}
	public long[] La2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),long.Parse);}}
	public double[] Da{get{return Array.ConvertAll(Console.ReadLine().Split(),double.Parse);}}
	public string[] Sa{get{return Console.ReadLine().Split();}}
	public string[] Sa2{get{return ("# "+Console.ReadLine()).Split();}}
}

Measured memory_bytes: 15840
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int n;
ll a[200005];
map<ll,int> mp;

int main(void){
	scanf("%d",&n);
	ll ans=0;
	for(int i=0;i<n;i++){
		scanf("%lld",&a[i]);
		ans+=mp[i-a[i]];
		mp[a[i]+i]++;
	}
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 27892
import sys


def checkPairs(cards):
  result = {}
  for card in cards:
    if cards.count(card) >= 2:
      result.update({card: cards.count(card)})
  keysNum = len(result.keys())
  values = list(result.values())
  if keysNum == 0:
    return "null"
  elif keysNum == 2:
    if values.count(3) > 0:
      return "full house"
    else:
      return "two pair"
  else:
    if values.count(4) > 0:
      return "four card"
    elif values.count(3) > 0:
      return "three card"
    else:
      return "one pair"


def checkStraight(cards):
  if cards.count(1) > 0:
    if cards[1] == 10 and cards[2] == 11 and cards[3] == 12 and cards[4] == 13:
      return True
  if cards[0] == cards[1] - 1 and cards[1] == cards[2] - 1 and cards[2] == cards[3] - 1 and cards[3] == cards[4] - 1:
    return True
  else:
    return False


for line in sys.stdin:
  try:
    cards = [int(i) for i in line.split(',')]
    cards.sort()
    result = checkPairs(cards)
    if result == "full house" or result == "four card":
      print(result)
    else:
      print("straight" if checkStraight(cards) else result)
  except:
    break

Measured memory_bytes: 5620
from sys import stdin,stdout,setrecursionlimit
from collections import Counter as C
setrecursionlimit(10**6)
M = 1000000007
input = stdin.readline
def write(n,sep="\n"):
	stdout.write(str(n))
	stdout.write(sep)
def gil():
	return list(map(int, input().split()))
	
n,k = gil()
h = gil()

dp = [1e18] * n
dp[0] = 0
for i in range(n):
    for j in range(i+1, i+k+1):
        if j < n:
            dp[j] = min(dp[j], dp[i] + abs(h[i] - h[j]))
#print(dp)
print(dp[n-1])
# Each iteration will consider the following for a state ->
# 1. Does this path get the min cost for this end point (each iteration is treated as
#       an endpoint), when considering the cost for this jump + the cost baggage
#       that this path brings. so that is dp[upto_here] + jump_cost or existing dp[endpoint] 
#       from some previous state.
# 2. Each iteration on i will try to cover all the possible states reachable,
#       while trying to set the min value for each state, as in, see if this state
#       is the best one so far.

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

int main(void){
    int n;
    cin >> n;
    int a[n+1];
    for(int i=1;i<=n;i++){
        int x;
        cin >> x;
        a[x] = i;
    }
    for(int i=1;i<=n;i++){
        cout << a[i] << " ";
    }
    
    
    return 0;
}





Measured memory_bytes: 1152
///////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////
//                       _oo0oo_                         //
//                      o8888888o                        //
//                      88" . "88      ------ hzt1       //
//                      (| -_- |)                        //
//                      0\  =  /0                        //
//                    ___/`---'\___                      //
//                  .' \|     |// '.                     //
//                 / \|||  :  |||// \                    //
//                / _||||| -:- |||||- \                  //
//               |   | \  -  /// |     |                 //
//               | \_|  ''\---/''  |_/ |                 //
//               \  .-\__  '-'  ___/-. /                 //
//             ___'. .'  /--.--\  `. .'___               //
//          ."" '<  `.___\_<|>_/___.' >' "".             //
//         | | :  `- \`.;`\ _ /`;.`/ - ` : | |           //
//         \  \ `_.   \_ __\ /__ _/   .-` /  /           //
//     =====`-.____`.___ \_____/___.-`___.-'=====        //
//                       `=---='                         //
//                                                       //
//                                                       //
//     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~       //
//                                                       //
//                 God-He Bless All.                     //
//           This Code Will Never Explode.               //
//                                                       //
//                                                       //
///////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////
#include<cstdio>
#include<cstring>
#include<cctype>
#include<algorithm>
#include<vector>
#define pb push_back
#define mp make_pair
#define xx first
#define yy second
#define rep(i,a,b) for(int i=(a),i##_end_=(b);i<=i##_end_;i++)
#define dwn(i,a,b) for(int i=(a),i##_end_=(b);i>=i##_end_;i--)
using namespace std;
const int Size=1<<16;
char buffer[Size],*head,*tail;
inline char Getchar() {
    if(head==tail) {
        int l=fread(buffer,1,Size,stdin);
        tail=(head=buffer)+l;
    }
    if(head==tail) return -1;
    return *head++;
}
inline int read() {
    int x=0,f=1;char c=getchar();
    for(;!isdigit(c);c=getchar()) if(c=='-') f=-1;
    for(;isdigit(c);c=getchar()) x=x*10+c-'0';
    return x*f;
}
typedef long long ll;
typedef pair<int,int> pii;
const int maxn=100010;
int n,first[maxn],nxt[maxn<<1],to[maxn<<1],e;
void AddEdge(int u,int v) {
	to[++e]=v;nxt[e]=first[u];first[u]=e;
	to[++e]=u;nxt[e]=first[v];first[v]=e;
}
int dfs(int x,int fa) {
	int res=0;
	for(int i=first[x];i;i=nxt[i]) if(to[i]!=fa) res^=dfs(to[i],x)+1;
	return res;
}
int main() {
	n=read();
	rep(i,2,n) AddEdge(read(),read());
	puts(dfs(1,0)?"Alice":"Bob");
	return 0;
}


Measured memory_bytes: 6784
#include <cstdlib>
#include <iostream>
#include <string>
#include <time.h>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <sstream>
#include <iomanip>
using namespace std;

int main(void) {

	//string s1,s2,s3;
	long long N = 0, K = 0;
	cin >> N >> K;
	long long res=0;

	bool flag = false;

	long long length = 0;
	long long al = (1);
	if (K == 0) {
		res = N*N;
	}
	else {


		for (int b = (K + 1); b <= N; b++) {
			//cout << "K=" <<b << endl;
			while (length < N - K + 1) {
				length += al;
				//cout << res << endl;
				if (length > N - (K - 1)) { flag = true; break; }
				res += al;
				length += K;
				//cout << res << endl;
			}

			if (flag == true) {
				res += al-(length - (N-(K-1)));
				//cout << length - (N - 1) << endl;
				flag = false;
			}

			al++;
			length = 0;
			//cout << res << endl;
		}

		}

		cout << res << endl;

	return 0;




}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
	int n;
  	cin >> n;
  	int k = 1000;
    int ans = 0;
    while(1){
    	if(k < n)
          k += 1000;
        else{
        	ans = k - n;
            break;
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3636
//IOI 2021

#include <bits/stdc++.h>
using namespace std;

#define pb push_back
#define ff first
#define ss second

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

const int MAXN = 2 * 1000 + 17;

ll n, x, a[MAXN], ans;

int main() {
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cin >> n;
	for (int i = 1; i <= 2 * n; i++)
		cin >> a[i];
	sort(a + 1, a + 2 * n + 1);
	for (int i = 1; i <= 2 * n; i += 2)
		ans += a[i];
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
from bisect import bisect_left

N=int(input())
*A,=map(int,input().split())
INF=10**20
G=[[] for _ in range(N)]
ab = [tuple(map(int,input().split())) for _ in range(N-1)]
for a,b in ab:
  G[a-1].append(b-1)
  G[b-1].append(a-1)
  
def dfs(a0):
    seen =[0]*len(G)
    todo = [~a0, a0]
    while todo:
        a = todo.pop()
        if a >= 0:
            seen[a] = 1
            idx = bisect_left(lis,A[a])
            his[a] = (idx,lis[idx])
            lis[idx] = A[a]
            dp[a] = bisect_left(lis,INF)
            for b in G[a]:
                if seen[b]: continue
                todo.append(~b)
                todo.append(b)
        else:
          idx,val = his[~a]
          lis[idx] = val
    return
  
lis = [INF]*N
dp = [0]*N
his = {}
dfs(0)
print(*dp,sep="\n")

Measured memory_bytes: 122164
#include <bits/stdc++.h>
using namespace std;
set<int> se;
int n;
int main()
{
	cin>>n;
	for(int i=0;i<n;i++)
	{
		int a;
		cin>>a;
		se.insert(a);
	}
	cout<<((int)(se.size())==n?"YES\n":"NO\n");
	return 0;
}

Measured memory_bytes: 9600
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return 1;
    }
    return 0;
}
typedef long long int ll;

#define EPS (1e-7)
#define INF (1e9)
#define LLINF (1e18)
#define PI (acos(-1))
#define MOD (1000000007)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

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

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin >> n;
    map<string, ll> mp;
    for (ll i = 0; i < n; i++)
    {
        string s;
        cin >> s;
        sort(ALL(s));
        mp[s]++;
    }
    ll ans = 0;
    for (auto p : mp)
    {
        ans += p.second * (p.second - 1) / 2;
    }
    cout << ans << endl;
}

Measured memory_bytes: 11264
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int X[] = new int[N];
		for(int i=0; i<N; i++) {
			X[i] = sc.nextInt();
		}
		int Y[] = X.clone();
		Arrays.sort(Y);
		for(int i=0; i<N; i++) {
			if(X[i]<Y[N/2]) System.out.println(Y[N/2]);
			else System.out.println(Y[N/2-1]);
		}
		sc.close();
	}

}

Measured memory_bytes: 91160
n, m = map(int, input().split())

ok = [False] * n
wa_cnt = [0] * n
ac_cnt = 0
for i in range(m):
    p, m = input().split()
    if ok[int(p) - 1]:
        continue
    if m == 'WA':
        wa_cnt[int(p) - 1] += 1
    else:
        ac_cnt += 1
        ok[int(p) - 1] = True

ans_wa = 0
for i in range(n):
    if ok[i]:
        ans_wa += wa_cnt[i]

print(ac_cnt, ans_wa)


Measured memory_bytes: 4596
#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<<'\n';
}

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a,b;
    cin>>a>>b;
    cout<<max({a+b,a-b,a*b})<<endl;
}

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

int main() {
  int h, n;
  cin >> h >> n;
  vector<int> vec(n);
  rep(i, n) cin >> vec.at(i);
  int a = 0;
  rep(i, n) a += vec.at(i);
  if(h <= a) cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 640
N, K = [int(v) for v in input().split()]
ab = []
for i in range(N):
    ab.append([int(v) for v in input().split()])

ab.sort()

b_sum = 0
for a, b in ab:
    b_sum += b
    if b_sum >= K:
        print(a)
        break

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

using namespace std;

int N, M;
vector<int> DartsInfo;
//set<int> Total;
vector<int> Total;

int main() {
	int p, totalMax;
	vector<int>::iterator pos;

	while (cin >> N >> M, N) {
		DartsInfo.clear();
		Total.clear();
		DartsInfo.push_back(0);
		for (int i = 0; i < N; ++i) {
			cin >> p;
			DartsInfo.push_back(p);
		}
		for (int i = 0; i <= N; ++i) {
			for (int j = 0; j <= N; ++j) {
				totalMax = DartsInfo[i] + DartsInfo[j];
				if (totalMax > M) {
					continue;
				}
				//Total.insert(totalMax);
				Total.push_back(totalMax);
			}
		}
		sort(Total.begin(), Total.end());
		totalMax = -1;
		for (pos = Total.begin(); pos != Total.end(); ++pos) {
			totalMax = max(totalMax, *pos + *(--upper_bound(Total.begin(), Total.end(), (M - *pos))));
		}
		cout << totalMax << endl;
	}

	return 0;
}


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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

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

    cout<<s[0]<<(s.size()-2)<<s[s.size()-1]<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define faster_io ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define mem(a,b) memset(a,b,sizeof a)
#define F first
#define S second
#define ll long long
#define pb push_back
#define pll pair<ll, ll>
using namespace std;
const ll N = 1e6 + 7, M = 1e5 + 7, mod = 1e9 + 7, inf = 1e18 + 7;
ll tc, n, m, q, a, b, c, d, i, j, k, l, sum, cnt;
ll ar[N];
string s;
vector < ll > vec;

int main()
{
    cin >> n >> m;
    if(n == m)
        cout << "Yes\n";
    else
        cout << "No\n";
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
//#define int ll
using namespace std;
const int md=1000000007;
const int mxn=200005;
int n,m,mx,ans,dp[mxn],f[mxn];
char s[mxn];
inline void add(int&x,int y){
	x+=y;
	if(x>=md)x-=md;
}
signed main(){
	int i,j,t;
	scanf("%d%d",&n,&m);
	scanf("%s",s+1);
	for(i=1;i<=m;++i)if(s[i]!=s[1])break;mx=i-1;
	if(mx==m){
		dp[0]=f[i]=ans=1;
		for(int i=0;i<=n;++i){
			if(i>=2)dp[i]=f[i-2];
			f[i]=(f[i-1]+dp[i])%md;
			if(n-i>1)add(ans,(ll)dp[i]*(n-i)%md);
		}
		printf("%d\n",ans);
		return 0;
	}
	if(n&1)return 0*puts("0");
	if(!(mx&1))++mx;
	for(t=0;i<=m;++i){
		if(s[i]==s[1])++t;
		else{
			if(t&1)mx=min(mx,t);
			t=0;
		}
	}
	n>>=1,mx=mx+1>>1;
	dp[0]=f[0]=1;
	for(i=0;i<=n;++i){
		if(i){
			dp[i]=(md+f[i-1]-(i-mx-1>=0?f[i-mx-1]:0))%md;
			f[i]=(f[i-1]+dp[i])%md;
		}
		if(n-i<=mx) add(ans,(ll)(n-i)*dp[i]*2ll%md);
	}
	printf("%d\n",ans);
}

Measured memory_bytes: 2048
#include<vector>
// 補助関数
template<typename T> T modpow(T x, T p, T M) {
  if(!p) return 1;
  if(p & 1) return (x * modpow(x, p - 1, M)) % M;
  return modpow((x * x) % M, p >> 1, M);
}
// 剰余類
template<typename T, T M = T(1e9 + 7)>
struct ModInt {
  T number;
  ModInt(T n = 0) : number(n % M) {while(number < 0) number += M;}
  // 代入演算
  ModInt& operator+=(const ModInt& m) {return *this = *this + m;}
  ModInt& operator-=(const ModInt& m) {return *this = *this - m;}
  ModInt& operator*=(const ModInt& m) {return *this = *this * m;}
  ModInt& operator/=(const ModInt& m) {return *this = *this / m;}
  ModInt& operator%=(const ModInt& m) {return *this = *this % m;}
  // 二項演算
  friend const ModInt operator+(const ModInt& lhs, const ModInt& rhs) {return lhs.number + rhs.number;}
  friend const ModInt operator-(const ModInt& lhs, const ModInt& rhs) {return lhs.number - rhs.number;}
  friend const ModInt operator*(const ModInt& lhs, const ModInt& rhs) {return lhs.number * rhs.number;}
  friend const ModInt operator/(const ModInt& lhs, const ModInt& rhs) {return lhs.number * modpow(rhs.number, M - 2, M);}
  friend const ModInt operator%(const ModInt& lhs, const ModInt& rhs) {return lhs.number % rhs.number;}
  // 関係演算
  friend bool operator==(const ModInt& lhs, const ModInt& rhs) {return lhs.number == rhs.number;}
  friend bool operator!=(const ModInt& lhs, const ModInt& rhs) {return lhs.number != rhs.number;}
  friend bool operator<=(const ModInt& lhs, const ModInt& rhs) {return lhs.number <= rhs.number;}
  friend bool operator>=(const ModInt& lhs, const ModInt& rhs) {return lhs.number >= rhs.number;}
  friend bool operator<(const ModInt& lhs, const ModInt& rhs) {return lhs.number < rhs.number;}
  friend bool operator>(const ModInt& lhs, const ModInt& rhs) {return lhs.number > rhs.number;}
  // 組み合わせ
  friend ModInt combination(const ModInt& n, const ModInt& r) {
    static std::vector<T> fact{1, 1}, inv{1, 1}, finv{1, 1};
    if(n < r) return 0;
    if(n < 0 || r < 0) return 0;
    while(fact.size() <= n.number) {
      T i = fact.size();
      fact.emplace_back(fact.back() * i % M);
      inv.emplace_back(inv.at(M % i) * (M - M / i) % M);
      finv.emplace_back(finv.back() * inv.back() % M);
    }
    return fact.at(n.number) * (finv.at((n - r).number) * finv.at(r.number) % M) % M;
  }
};
// 入出力ストリーム
#include<iostream>
template<typename T, T M> inline std::istream& operator>>(std::istream& is, ModInt<T, M>& m) {return is >> m.number;}
template<typename T, T M> inline std::ostream& operator<<(std::ostream& os, const ModInt<T, M>& m) {return os << m.number;}

#include<bits/stdc++.h>
using namespace std;

using MI = ModInt<long long, 998244353>;

int main() {
  MI K, N;
  cin >> K >> N;
  for(MI x = 2; x <= 2*K; x += 1) {
    MI p = (K<x ? 2*K+2-x : x).number / 2;
    MI sum;
    for(MI i = 0; i <= p; i += 1) sum += combination(p, i) * combination(K-p+N-i-1, N-i);
    cout << sum << endl;
  }
}


Measured memory_bytes: 384
// Born Sinner
// old but im not that old
// fuck all you hoes get a grip
import java.util.*;
import java.lang.*;
import java.io.*;
import java.math.BigInteger;

public class Main
{
    static class FastReader{
        BufferedReader br;
        StringTokenizer st;
        public FastReader(){
            br = new BufferedReader(new InputStreamReader(System.in));
        }
        String next(){
            while(st == null || !st.hasMoreElements()){
                try{
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e){
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }
        int nextInt(){
            return Integer.parseInt(next());
        }
        long nextLong(){
            return Long.parseLong(next());
        }
        double nextDouble(){
            return Double.parseDouble(next());
        }
        String nextLine(){
            String str = "";
            try{
                str = br.readLine();
            } catch (Exception e){
                e.printStackTrace();
            }
            return str;
        }
    }
    static int modPower(int x, int y, int mod){
        int res = 1;
        x %= mod;
        if(x==0) return 0;
        while(y>0){
            if(y%2==1){
                res = (res*x)%mod;
            }
            y = y>>1;
            x = (x*x)%mod;
        }
        return res;
    }
    static class pair<T1, T2>{
        T1 first;
        T2 second;
        pair(T1 first, T2 second){
            this.first = first;
            this.second = second;
        }
    }
    static int gcd(int a, int b){
        if(b == 0) return a;
        return gcd(b, a%b);
    }

    public static void main (String[] args) throws java.lang.Exception
    {
        FastReader in = new FastReader();
        int n = in.nextInt(), m = in.nextInt();
        Map<Integer, LinkedList<Integer>> g = new HashMap<>();
        for(int i = 0; i < m; i++){
            int x = in.nextInt(), y = in.nextInt();
            if(!g.containsKey(x)) g.put(x, new LinkedList<Integer>());
            if(!g.containsKey(y)) g.put(y, new LinkedList<Integer>());
            g.get(x).add(y);
            g.get(y).add(x);
        }
        boolean[] vis = new boolean[n+1];
        int ans = 0;
        for(int i = 1; i <= n; i++){
            if(vis[i]) continue;
            Queue<Integer> q = new LinkedList<>();
            q.add(i);
            vis[i] = true;
            while(!q.isEmpty()){
                int j = q.remove();
                vis[j] = true;
                if(!g.containsKey(j)) continue;
                for(int k : g.get(j)){
                    if(!vis[k]){
                        q.add(k);
                    }
                }
            }
            ans++;
        }
        System.out.println(ans-1);
    }
}


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

void draw(int, int);

int main() {
    int h, w;
    for (;;) {
        cin >> h >> w;
        if (h == 0 && w == 0)
            return 0;
        draw(h, w);
        cout << endl;
    }
}

void draw(int h, int w) {
    for (int y = 0; y < h; y++) {
        for (int x = 0; x < w; x++)
            cout << '#';
        cout << endl;
    }
}



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

#define REP(i,n) for(int i=0;i<n;i++)
#define EPS (1e-9)
#define INF (1e9 + 1)
#define PI (acos(-1))

ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}

ll lcm(ll a, ll b) {
	ll c = (b / gcd(a, b));
	return c * a;
}

int bekijo(int a, int b) {
	int tmp = 1;
	REP(i, b) tmp *= a;
	return tmp;
}

double N;
double T, A;
double H[1010];

int main() {
	cin >> N >> T >> A;
	REP(i, N) cin >> H[i];
	double ans = INF;
	int index;
	REP(i, N) {
		//abs((T - H[i] * 0.006) - A)とans比べる
		if (abs((T - H[i] * 0.006) - A) < ans)
		{
			ans = abs((T - H[i] * 0.006) - A);
			index = i;
		}
	}
	cout << index + 1 << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
using namespace std;

#ifdef LOCAL
	#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
	#define eprintf(...) 42
#endif

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef long double ld;
#define mp make_pair
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int N = 100100;
int n, m;
vector<int> g[N];
int h[N];

void printEdge(int v, int u) {
	v++;
	u++;
	printf("%d %d\n", v, u);
}

int dfs(int v, int par) {
	int x = -1;
	for (int u : g[v]) {
		if (h[u] != 0) {
			if (h[u] >= h[v] - 1) continue;
			if (x == -1) {
				x = u;
			} else {
				printEdge(v, x);
				printEdge(v, u);
				x = -1;
			}
		} else {
			h[u] = h[v] + 1;
			int z = dfs(u, v);
			if (z == 0) continue;
			if (x == -1) {
				x = u;
			} else {
				printEdge(v, x);
				printEdge(v, u);
				x = -1;
			}
		}
	}
	if (x == -1) return 1;
	printEdge(v, par);
	printEdge(v, x);
	return 0;
}

int main()
{
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);

	scanf("%d%d", &n, &m);
	for (int i = 0; i < m; i++) {
		int v, u;
		scanf("%d%d", &v, &u);
		v--;u--;
		g[v].push_back(u);
		g[u].push_back(v);
	}
	if (m & 1) {
		printf("-1\n");
		return 0;
	}
	h[0] = 1;
//	eprintf("!%d\n", dfs(0, -1));
	if (dfs(0, -1) == 0) throw;

	return 0;
}


Measured memory_bytes: 15104
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
#define bit(n) (1LL << (n))
#define sz(x) ((ll)(x).size())
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int 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() {
  int N;
  cin >> N;
  string S;
  cin >> S;

  int ans = 0;
  rep(i, N - 2) {
    if (S.substr(i, 3) == "ABC")
      ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
string solve(string s){
	if(s=="zyxwvutsrqponmlkjihgfedcba"){
		return "-1";
	}
	if(s.size()<26){
		for(char c='a';c<='z';c++){
			if(s.find(c)==string::npos){
				s+=c;
				return s;
			}
		}
	}
	for(int i=s.size()-1;i>=0;i--){
		for(char c=s[i];c<='z';c++)
		{
			if(s.find(c)==string::npos){
				s[i]=c;
				s=s.substr(0,i+1);
				return s;
			}
		}
		s.erase(s.begin()+i);
	}
}
int main(){
	string s;
	cin>>s;
	cout<<solve(s)<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int isprime[104730] = { 0 };
int main() {

  //  for(int i=4; i<104730; i+=2)
  //    isprime[i]=1;

  isprime[1] = 1;
  for(int i=2; i*i < 104730; i++)
    if(isprime[i] == 0)
      for(int j=2; i*j < 104730; j++)
	isprime[i*j] = 1;

  int n;
  while(1) {
    cin>>n;
    if(!n) break;
    int sum=0;
    for(int i=2;n>0;i++){
      if(isprime[i] == 0) {
	sum += i;
	n--;
      }
    }
    cout<<sum<<endl;
  }
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
#define all(vec) vec.begin(),vec.end()
typedef long long int ll;
typedef pair<ll,ll> P;
const ll MOD=1234567;
const ll INF=1000000010;
const ll LINF=4000000000000000010LL;
const int MAX=310;
const double EPS=1e-3;
int dx[4]={0,1,0,1};
int dy[4]={0,0,1,1};
int main(){
	int n;cin>>n;
	ll a[100010];for(int i=0;i<n;i++)cin>>a[i];
	ll x=0;
	bool f[100010]={false};
	for(int i=0;i<n;i++){
		x^=a[i];
		for(int j=29;j>=0;j--){
			if(a[i]%(1<<j)==0){
				f[j]=true;
				break;
			}
		}
	}
	int ans=0;bool s=false;
	for(int i=29;i>=0;i--){
		bool b=((x&(1<<i))>0);
		if(b!=s){
			ans++;
			s=b;
			if(!f[i]){
				cout<<-1<<endl;
				return 0;
			}
		}
	}
	cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 1152
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		String s = scanner.next();

		if(s.matches("(dream|dreamer|erase|eraser)*")){
			System.out.println("YES");
		}else{
			System.out.println("NO");
		}
	}

}


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


Measured memory_bytes: 3100