akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Linq;
using static Input;

public class Prog
{
    private const int INF = 1000000007;
    private const long INFINITY = 9223372036854775807;
    public static void Main()
    {
        string s = NextString();
        int ans = INF;
        for (char c = 'a'; c <= 'z'; c++)
        {
            if (!s.Contains(c)) continue;
            string t = s;
            int count = 0;
            while (t.Count(v => v == c) != t.Length)
            {
                string nxt = "";
                for (int i = 0; i < t.Length - 1; i++)
                {
                    if (t[i] == c) nxt += c.ToString();
                    else if (t[i + 1] == c) nxt += c.ToString();
                    else nxt += t[i].ToString();
                }
                t = nxt;
                count++;
                //Console.WriteLine(t);
            }
            ans = Math.Min(count, ans);
        }
        Console.WriteLine(ans);
    }
}

public class Input
{
    private static Queue<string> q = new Queue<string>();
    private static void Confirm() { if (q.Count == 0) foreach (var s in Console.ReadLine().Split(' ')) q.Enqueue(s); }
    public static int NextInt() { Confirm(); return int.Parse(q.Dequeue()); }
    public static long NextLong() { Confirm(); return long.Parse(q.Dequeue()); }
    public static string NextString() { Confirm(); return q.Dequeue(); }
    public static double NextDouble() { Confirm(); return double.Parse(q.Dequeue()); }
    public static int[] LineInt() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); }
    public static long[] LineLong() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); }
    public static string[] LineString() { return Console.ReadLine().Split(' ').ToArray(); }
    public static double[] LineDouble() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); }
}


Measured memory_bytes: 17376
#include <stdio.h>

int main() {
	int a, b;

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

	if (a > b) {
		printf("%d\n", a + (a - 1));
	}
	else if(a < b){
		printf("%d\n", b + (b - 1));
	}
	else {
		printf("%d\n", a + b);
	}

	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define IOS   ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define test IOS long long t;cin >> t;while(t--)
using namespace std;
typedef long long v99;
const double pi=acos(-1.0);
#define MX 99999
vector<int>v;
map<int,int>mp;
map<int,int>::iterator it;
int gcd(int a,int b){
    if(b==0)return a;
    return (b,a%b);
}
int main()
{
    int n,k;cin>>n>>k;
    int a[n],s=0;
    for(int i=0;i<n;i++)cin>>a[i];
    sort(a,a+n);
    for(int i=0;i<k;i++)s+=a[i];
    cout<<s<<endl;
    return 0;
}



Measured memory_bytes: 3640
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector> 
#include <cstring>
#include <queue>
#include <ctime>
#include <set>
#include <map>
#include <stack>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
const int INF = 10e8;
const int maxM = 1000010;
//const int maxN = 100010;
const int maxN = 10010;

int n,m;
int a[maxN];
int b[maxM];
vector<pii> p;
int main()
{
	scanf("%d %d",&n,&m);
	//p.push_back(pii(-INF,-INF));
	for(int i=1;i<=m;i++)
	{
		int x,y;
		scanf("%d %d",&x,&y);
		p.push_back(pii(x,y));
	}
	sort(p.begin(),p.end());
	stack<pii> S;
	for(int i=0;i<p.size();i++)
	{
		pii Y = p[i];
		while(!S.empty())
		{
			pii X = S.top();
			if(Y.first >= X.first && X.second >= Y.second )
			{
				S.pop();	
			} 
			else
			{
				break;
			}
		}
		S.push(Y);
	}
	vector<pii> w;
	while(!S.empty())
	{
		pii q = S.top();
		S.pop();
		w.push_back(q);
	}
	reverse(w.begin(),w.end());
	int ans = 0;
	int cnt = 0;
	for(int i=0;i<w.size();i++)
	{
		int q1 = w[i].first;
		int q2 = w[i].second;
		if(q1 <= ans) continue;
		else
		{
			ans = q2-1;
			cnt++;
		}
	}
	printf("%d\n",cnt);
	return 0;
}

Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi vector<vector<int> >
#define vvl vector<vector<ll> >
#define vll vector<ll>
#define rep(c, a, b) for(ll c=a;c<b;c++)
#define re(c, b) for(ll c=0;c<b;c++)
#define all(obj) (obj).begin(), (obj).end()
typedef long long int ll;
typedef long double ld;
using namespace std;
int main(int argc, char const *argv[]) {
  ll a, b;std::cin >> a >> b;
  if(a+b==15) std::cout << "+" << '\n';
  else if(a*b==15) std::cout << "*" << '\n';
  else std::cout << "x" << '\n';
}


Measured memory_bytes: 256
N,M=(map(int,input().split()))

C=[input().split() for i in range(N)]
B=[]
for i in C:
    B.append(list(map(int,i)))

B.sort()

k=0
l=0#何番目の店
m=0#その店で買う数
money=0
X=0#持ち数
for a,b in B:
    if(M<=0):
        break
    if(b<=M):
        money+=a*b
    else:
        money+=M*a
    M-=b
print(money)


Measured memory_bytes: 57772
#include<iostream>
#include<cstring>
using namespace std;
int main()
{
    int n,m;
    cin>>n>>m;
    int a[m],b[m];
    int i,j;
    for(i=0;i<m;i++){
        cin>>a[i]>>b[i];
    }
    int cnt[n];
    for(i=0;i<n;i++){
        cnt[i]=0;
    }
    for(i=1;i<=n;i++){
        for(j=0;j<m;j++){
            if(i==a[j]||i==b[j]){
                cnt[i-1]++;
            }
        }
    }
    for(i=0;i<n;i++){
        cout<<cnt[i]<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
//#include <stdlib.h>
#include <string.h>

/* run this program using the console pauser or add your own getch, system("pause") or input loop */
#define MAXSIZE 200001
int main(int argc, char *argv[]) {
//	char res[4];
	char N[MAXSIZE];
	scanf("%s", N);
	
	int i = 0;
	int sum = 0;
	for (i = 0; i < strlen(N); ++i)
	{
		sum = sum + (N[i] - '0');
	}
	if (N[0] - '0' == 0 && strlen(N) == 1) 
	{
		printf("%s", "Yes");
//		return;
	}
	
	 else if (sum % 9 == 0)
	{
		printf("%s", "Yes");
		
//		return;
	}
	else 
	{
		printf("%s", "No");
	}
	
	
	return 0;
}

Measured memory_bytes: 1908
#include<bits/stdc++.h>
using namespace std;
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int i;
	string s;
	cin>>s;
	for(i=0;i<(int)s.size();i++)
	{
		if((i%2==0 && s[i]=='L') || (i%2==1 && s[i]=='R'))
		{
			cout<<"No\n";
			return 0;
		}
	}
	cout<<"Yes\n";
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(void){
  int n,k;
  cin>>n>>k;
  vector<int> a(n);
  for(int i=0;i<n;i++){
    cin>>a[i];
  }
  int count=k;
  int ans=1;
  while(count<n){
    count+=(k-1);
    ++ans;
  }
  cout<<ans<<endl;
  return 0;
}

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

int main() {
  vector<int> arr;

  int N, max1, max2, hozon;
  cin >> N;
  max1 = 0;
  max2 = 0;
  for (int i = 0; i < N; i++) {
    cin >> hozon;
    if (hozon >= max1) {
      max2 = max1;
      max1 = hozon;
    } else if (hozon >= max2) {
      max2 = hozon;
    }
    arr.push_back(hozon);
  }

  for (int i = 0; i < N; i++) {
    if (arr[i] < max1)
      cout << max1 << endl;
    else
      cout << max2 << endl;
  }
  return 0;
}

Measured memory_bytes: 2548
import sys
import itertools
input = sys.stdin.readline
sys.setrecursionlimit(100000)


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


def read_index():
    return map(lambda x: x - 1, map(int, input().split()))


def read_list():
    return list(read_values())


def read_lists(N):
    return [read_list() for n in range(N)]


def functional(N, mod):
    F = [1] * (N + 1)
    for i in range(N):
        F[i + 1] = (i + 1) * F[i] % mod
    return F


INV = dict()
def inv(a, mod):
    if a in INV:
        return INV[a]
    i = pow(a, mod - 2, mod)
    INV[a] = i
    return i 


def C(F, a, b, mod):
    return F[a] * inv(F[a - b], mod) * inv(F[b], mod) % mod 


def main():
    N, K = read_values()
    mod = 10 ** 9 + 7
    F = functional(5 * 10 ** 5, mod)
    res = 0
    if N <= K:
        res = C(F, 2 * N - 1, N - 1, mod)
    else:
        for k in range(K + 1):
            res += C(F, N, k, mod) * C(F, N - 1 , k, mod) % mod
    
    print(res % mod)


if __name__ == "__main__":
    main()

Measured memory_bytes: 46880
// J'aime
// Chemise Blanche

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

#define int long long

#define ii pair<int,int>
#define fi first
#define sc second

#define all(x) (x).begin(),(x).end()
#define dbg(x) cerr << __LINE__ << " > " << #x << " = " << (x) << endl

#define TLE 2e9

void MAIN() {
  int n, T;
  cin >> n >> T;
  int ans = TLE;
  for (int i = 0; i < n; i++) {
    int c, t;
    cin >> c >> t;
    if (t <= T) ans = min(ans, c);
  }
  if (ans == TLE) cout << "TLE" << '\n';
  else cout << ans << '\n';
}

signed main() {
#ifdef _DEBUG
  // freopen("in" , "r", stdin );
  // freopen("out", "w", stdout);
#endif
  ios::sync_with_stdio(0); cin.tie(0);
  int T = 1;
  // cin >> T;
  while (T--) MAIN();
}


Measured memory_bytes: 3652
#include <stdio.h>

int main(void)
{
	int c=0,z,x[9999];
	
	while(1){
		scanf("%d",&x[c]);
		if(x[c] != 0){
			c = c+1;
		}
		else{
			z = c;
			break;
		}
	}
	
	for(c=0; c<z; c++){
		printf("Case %d: %d\n",c+1,x[c]);
	}
	
	return 0;
}

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

int main()
{
    int n;
    cin>>n;
    long long int a[n],b[n];
    for(int i=0;i<n;i++)
        cin>>a[i];
    sort(a,a+n);
    long long int ans=a[n-1];
    int j=n-2,f=0;
    for(int i=2;i<n;i++)
        {
            f++;
            ans=ans+a[j];
            if(f==2)
            {
                f=0;
                j--;
            }
        }
    cout<<ans<<endl;
}


Measured memory_bytes: 5076
#include <iostream>
#include <set>
#include <queue>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstring>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
#include <numeric>

using namespace std;

/*-----------------------------------------------------------------------------
　定義
 -------------------------------------------------------------------------------*/
typedef long long				ll;
#define ALL(x)					(x).begin(),(x).end()
#define REP(i, n)				for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n)			for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define INF						2e9
#define MOD						(1000 * 1000 * 1000 + 7)
#define Ceil(x, n)				(((((x))+((n)-1))/n))		/* Nの倍数に切り上げ割り算 */
#define CeilN(x, n)				(((((x))+((n)-1))/n)*n)		/* Nの倍数に切り上げ */
#define FloorN(x, n)			((x)-(x)%(n))				/* Nの倍数に切り下げ */
#define IsOdd(x)				(((x)&0x01UL) == 0x01UL)			
#define IsEven(x)				(!IsOdd((x)))						
#define M_PI					3.14159265358979323846
typedef pair<ll, ll>			P;

/*-----------------------------------------------------------------------------
　処理
 -----------------------------------------------------------------------------*/
int main()
{
	ll N, D, A;
	cin >> N >> D >> A;
	vector<ll> X(N), H(N);
	REP(i, N) cin >> X[i] >> H[i];

	vector<P> p(N);
	REP(i, N) {
		p[i].first = X[i];
		p[i].second = H[i];
	}
	sort(ALL(p));
	
	ll ans = 0;
	ll ruiseki = 0;
	ll damIdx = 0;
	vector<P> damage(N);
	for (ll i = 0; i < N; i++) {
		P monOne = p[i];
		for (; damIdx < i; damIdx++) { 
			if (damage[damIdx].first < monOne.first) {
				ruiseki -= damage[damIdx].second;
			} else {
				break;
			}
		}
		monOne.second -= ruiseki;
		damage[i].first = monOne.first + 2 * D;
		if (0 < monOne.second) {
			ll cntOne = Ceil(monOne.second, A);
			damage[i].second = A * cntOne;
			ruiseki += A * cntOne;
			ans += cntOne;
		} else {
			damage[i].second = 0;
		}
	}

	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 9600
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		String S = scan.next();
		scan.close();

		int minDistance753 = 999;

		for(int i=0; i<S.length(); i++) {
			int endindex = i+3;
			if(S.length()-1 < i+3) {
				endindex = S.length();
			}
			int X = Integer.parseInt(S.substring(i, endindex));
			int distance753 = Math.abs(X - 753);
			if(distance753 < minDistance753) {
				minDistance753 = distance753;
			}
		}
		System.out.println(minDistance753);
	}

}


Measured memory_bytes: 21972
import scala.collection.mutable

object Main extends App {
  import scala.io.StdIn._


  solve
  def solve: Unit = {
    val Array(n, m, l, k) = readLine.trim.split(' ').map(_.toInt)
    if (n == 0 && m == 0 && l == 0 && k == 0) return
    val rooms = Array.tabulate(n){_ ⇒ Nil:List[Edge]}
    for (_ ← 0 until m){
      val Array(u, v, c) = readLine.trim.split(' ').map(_.toInt)
      rooms(u - 1) ::= Edge(v - 1, c)
      rooms(v - 1) ::= Edge(u - 1, c)
    }
    val Array(start, goal) = readLine.trim.split(' ').map(_.toInt - 1)
    val doragosoNumber = Array.tabulate(n){_ ⇒ -1}
    for (d ← 0 until l){
      doragosoNumber(readInt - 1) = d
    }
    val minCost = Array.tabulate(n){_ ⇒ Array.tabulate(1 << l){_ ⇒ new KthMemo(k)}}
    val queue = mutable.PriorityQueue()(Ordering.by[(Flag, Int, Int), Int](_._3).reverse)
    val firstFlag = new Flag().let(f ⇒ if (doragosoNumber(start) != -1) f.added(doragosoNumber(start)) else f)
    minCost(start)(firstFlag.toInt).setIfAnyGreater(0)
    queue.enqueue((firstFlag, start, 0))
    while (queue.nonEmpty){
      val (flag, current, time) = queue.dequeue()
      if (minCost(current)(flag.toInt).contains(time)) {
        for (Edge(next, cost) ← rooms(current)) {
          if (doragosoNumber(next) != -1 && minCost(next)(flag.added(doragosoNumber(next)).toInt).setIfAnyGreater(time + cost)) {
            queue.enqueue((flag.added(doragosoNumber(next)), next, time + cost))
          }else if (doragosoNumber(next) == -1 && minCost(next)(flag.toInt).setIfAnyGreater(time + cost)) {
            queue.enqueue((flag, next, time + cost))
          }
        }
      }
    }
    val result = minCost(goal)((1 << l) - 1).allValues
    if (result.size < k) println("NA")
    else println(result(k - 1))
    solve
  }
  case class Edge(to: Int, cost: Int)
  class KthMemo(private[this] val size: Int) {
    private[this] val memo: Array[Int] = Array.tabulate(size){_ ⇒ Int.MaxValue}
    private[this] var pushed: Int = 0
    def setIfAnyGreater(value: Int): Boolean = {
      if (pushed < size) {
        memo(pushed) = value
        pushed += 1
        true
      }else {
        Some(memo.indices.maxBy(memo)).filter(i ⇒ memo(i)>value).also(_.foreach(memo(_)=value)).isDefined
      }
    }
    def contains(value: Int): Boolean = memo.contains(value)
    def allValues = (0 until pushed).map(memo).sorted
  }
  class Flag(private[this] val flag: Int = 0) {
    def added(index: Int): Flag = new Flag(flag | (1 << index))
    def isAdded(index: Int): Boolean = if (index >= 0) (flag & (1 << index)) != 0 else false
    def toInt = flag
  }
  implicit class Scope[T](val value: T) extends AnyVal{
    @inline
    def also(@inline func: T ⇒ Unit): T = {
      func(value)
      value
    }
    @inline
    def let[A](func: T ⇒ A): A = func(value)
  }
}


Measured memory_bytes: 599584
#include <cstring>
#include <map>
#include <unordered_map>
#include <string>
#include <list>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <cstdio>
#include <iostream>
#include <set>
#include <unordered_set>
using namespace std;

#define MAX(a,b) (a>b?a:b)
#define MIN(a,b) (a<b?a:b)
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef pair<int, int> pii;

int gi() {
    int a;
    scanf("%d", &a);
    return a;
}

ll gli() {
    ll a;
    scanf("%lld", &a);
    return a;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n = gli();
    ll a = gli();
    ll b = gli();
    if (a > b) {
        ll t = a;
        a = b;
        b = t;
    }
    if ((b-a)%2LL == 0)
        cout << (b-a)/2LL << endl;
    else {
        ll c1 = (a-1+b)/2LL;
        ll c2 = (n-a+n-b+1)/2LL;
        cout << MIN(c1, c2) << endl;
    }

    return 0;
}


Measured memory_bytes: 256
import java.util.*;
import static java.lang.System.*;
public class Main {
	public static void main(String[] args) {
	    Scanner sc = new Scanner(in);
	    String str = sc.next();
	    str = str.replace("/","");
	    String ans =  (Integer.valueOf(str) > 20190430)? "TBD" : "Heisei";
		out.println(ans);
	}
}

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

using namespace std;

typedef long long int lli;

int n, m, sw[10][10] = { 0 }, p[10];
int SW[10] = {0};

int rec(int d) {
    if (d == n) {
        bool allok = true;
        for (int i=0; i<m; i++) {
            int cont = 0;
            for (int j=0; j<n; j++) {
                if (sw[i][j] && SW[j]) cont++;
            }
            if (cont%2 != p[i]) allok = false;
        }

        return allok? 1 : 0;
    }

    int res = 0;
    SW[d] = 0;
    res += rec(d+1);
    SW[d] = 1;
    res += rec(d+1);

    return res;
}

int main() {
    cin >> n >> m;
    int k, s;
    for (int i=0; i<m; i++) {
        cin >> k;
        for (int j=0; j<k; j++) {
            cin >> s;
            sw[i][s-1] = 1;
        }
    }

    for (int i=0; i<m; i++) {
        cin >> p[i];
    }

    cout << rec(0) << endl;

    return 0;
}


Measured memory_bytes: 256
x,n = map(int,input().split())
p = list(map(int,input().split()))
ans = 0
for i in range(0, 100) :
    if ((x-i) not in p):
        ans = x-i
        break
    if ((x+i) not in p):
        ans = x+i
        break
    
print(ans)


Measured memory_bytes: 9208
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;

namespace AtCorder
{
	public class Program
	{
		public static void Main()
		{
			var input = ReadLine().Split();
			int n = int.Parse(input[0]);
			int m = int.Parse(input[1]);
			var list = new List<int[]>();
			for(int i = 0; i<m; i++)
			{
				list.Add(Array.ConvertAll(ReadLine().Split(), int.Parse));
			}
			list = list.OrderBy(x => x[0]).ThenByDescending(x => x[1]).ToList();
			int count = 0;
			int[] p = new int[2] { 0, 0 };
			foreach(var item in list)
			{
				if((p[0] < item[0]  && item[0] < p[1]) || 
					(p[0] < item[1] && item[1] < p[1]))
				{
					p[0] = Math.Min(p[0], item[0]);
					p[1] = Math.Min(p[1], item[1]);
				}
				else
				{
					count++;
					p = item;
				}
			}
			WriteLine(count);
		}
	}
}


Measured memory_bytes: 28616
#include<bits/stdc++.h>
using namespace std ;
 
int main()
{
    int a , b ;
    cin >> a >> b ;
    double x = (a+b)/2.0 ;
    int y = x*10 ;
    int z = (a+b)/2 ;
        
    if (y%10>=5)
        x = z + 1 ;
    else
        x = z ;
    
    cout << x << '\n' ;
    
 
    return 0 ;
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define SZ(X) ((int)(X).size())
#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 RI(X) scanf("%d", &(X))
#define RII(X, Y) scanf("%d%d", &(X), &(Y))
#define RIII(X, Y, Z) scanf("%d%d%d", &(X), &(Y), &(Z))
#define DRI(X) int (X); scanf("%d", &X)
#define DRII(X, Y) int X, Y; scanf("%d%d", &X, &Y)
#define DRIII(X, Y, Z) int X, Y, Z; scanf("%d%d%d", &X, &Y, &Z)
#define RS(X) scanf("%s", (X))
#define CASET int ___T, case_n = 1; scanf("%d ", &___T); while (___T-- > 0)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define PII pair<int,int>
#define VI vector<int>
#define VPII vector<pair<int,int> >
#define PLL pair<long long,long long>
#define VPLL vector<pair<long long,long long> >
#define F first
#define S second
typedef long long LL;
using namespace std;
const int MOD = 1e9+7;
const int SIZE = 1e6+10;
LL an[SIZE],d[SIZE],cc[SIZE];
int main(){
 DRII(N,Q);
 d[Q]=N;
 REP(i,Q)cin>>d[Q-i-1];
 {
  int it=1;
  REPP(i,1,Q+1){
   if(d[i]<d[it-1])d[it++]=d[i];
  }
  Q=it;
  reverse(d,d+Q);
 }
 cc[Q-1]=1;
 for(int i=Q-1;i>0;i--){
  LL me=cc[i];
  int it=i;
  LL now=d[i];
  while(it){
   cc[it-1]+=me*(now/d[it-1]);
   now%=d[it-1];
   it=upper_bound(d,d+it,now)-d;
  }
  an[now]+=me;
 }
 an[d[0]]+=cc[0];
 for(int i=N;i>0;i--)an[i]+=an[i+1];
 REPP(i,1,N+1)cout<<an[i]<<endl;
 return 0;
}

Measured memory_bytes: 4096
#include<iostream>
#include<algorithm>
#include<utility>
#include<vector>
#include<cmath>
using namespace std;

typedef pair<int, int> P;
typedef long long ll;
const int INF = 100000000;

ll gcd( ll a, ll b ){//最大公約数
    ll tmp;
    if( a < b ) { tmp = a; a = b; b = tmp; }
    if( b < 1 ) return -1;

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

ll lcm(ll a, ll b){//最小公倍数
    return a * b / gcd(a, b);
}

ll sosuu(ll x){
    for(int i = 2; i < x; i++){
        if(x % i == 0) return false;
    }

    return true;
}


//入力
int h, w, n;

int main(){

    cin >> h >> w >> n;

    int _max = max(h, w);

    cout << (n + _max - 1) / _max << endl;


    return 0;
}

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

using namespace std;

#define REP(i, n)   for(int i = 0; i < (n); i++)
#define REPS(i, n)  for(int i = 1; i <= (n); i++)
#define RREP(i, n)  for(int i = (n)-1; i >= 0; i--)
#define RREPS(i, n) for(int i = (n); i > 0; i--)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define mp make_pair
#define mt make_tuple
#define pb push_back

using ll  = long long;
using pi  = pair<int, int>;
using pl  = pair<ll, ll>;
using vi  = vector<int>;
using vl  = vector<ll>;
using vs  = vector<string>;
using vb  = vector<bool>;
using vvi = vector<vi>;
using vvl = vector<vl>;

const int MOD = 1e9 + 7;
const int INF = 1e9 + 7;
const ll  INFL = 1e18;
const double PI = 3.141592653589793;
const double EPS = 1e-9;

template<class T> bool chmax(T &a, const T &b) { if(a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if(a > b) { a = b; return true; } return false; }

signed main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    char c; cin >> c;
    char v[] = {'a', 'i', 'u', 'e', 'o'};
    bool ok = false;
    REP(i, 5) if(c == v[i]) ok = true;
    if(ok) cout << "vowel" << endl;
    else cout << "consonant" << endl;
}

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

string erase_back(string s) {
  string t;
  for (int i = 0; i < s.size() - 1; i++) {
    t.push_back(s[i]);
  }
  return t;
}

int main() {
  string s;
  cin >> s;
  string ans;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == '0') ans.push_back('0');
    else if (s[i] == '1') ans.push_back('1');
    else if (s[i] == 'B' && ans.empty() == false) {
      ans = erase_back(ans);
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <cmath>
#include <queue>
#include <deque>
#include <set>
#include <iomanip>
#include <utility>
#define ll long long
#define ld long double
using namespace std;

ll a[100010];

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

int main() {
	int N;
	ll M;
	cin >> N >> M;
	for(int i=0; i<N; ++i) cin >> a[i];
	ll cnt2=0;
	for(int i=0; i<N; ++i){
		ll now=1, choku=a[i];
		while(choku%2==0){
			now *= 2;
			choku /= 2;
		}
		if(i==0) cnt2=now;
		else if(cnt2!=now){
			cout << 0 << endl;
			return 0;
		}
	}
	ll mn=1;
	for(int i=0; i<N; ++i){
		ll g=gcd(mn, a[i]/2);
		mn *= a[i]/(2*g);
		if(mn>M){
			cout << 0 << endl;
			return 0;
		}
	}
	ll ans=1+(M-mn)/(mn*2);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
 
typedef long long ll;
typedef long double ld;
 
#define REP(i,a,n) for(int (i)=(a); (i)<(int)(n); (i)++)
#define rep(i,n) REP(i,0,n)
#define vec vector 



int main(){
  string O, E;
  cin >> O >> E;
  
  rep(i, O.size() + E.size())
    if(i%2 == 0){
      cout << O.at(i/2);
    }else{
      cout << E.at((i-1)/2);
    }
 
}

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

#define rep(i, n) for(int i = 0; i<(n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef long long ll;


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

    if (K == 0) {
        cout << N * N << endl;
        return 0;
    }

    ll ans = 0;
    for (ll i = 1; i <= N; i++) {
        if (i - 1 < K) continue;
        ll cnt = i - 1LL - K + 1LL;
        ans += cnt * (N / i);
        ans += max(0LL, N % i - K + 1);
    }
    cout << ans << endl;
}

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

int funcX(int x)
{
 int r = 0; 
 while (x%2==0) { r++;  x/=2; }
  return r;
}

int main() 
{
  int N;
  cin >> N;
  int t; 
  
  for (int i = 1; i <= N; i++) 
  {
    int A;
    cin >> A;
    int s = funcX(A);
    if (i ==1)  t = s; 
    else t = min(t,s);
   }
  
  cout << t << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <math.h>
#include <vector>
#include <algorithm>
using namespace std;

int main(){
	string s;
	cin >> s;
	int ans = 0;
	for(int i = 0; i < 3; i++){
		if(s.at(i) == '1') ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
///////////////////////////////////////////
const long long int INF = 1LL<<60;
const long long int Mod = 1000000007;
using ll = long long int; using ci = const int;
using vi = vector<int>;  using Vi = vector<long long int>;
using P = pair<int, int>;  using PLL = pair<ll, ll>;
using matrix = vector<vector<ll>>;
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define rp(i,N) for(ll i = 0; i < (ll)N; i++)
#define repi(i,a,b) for(ll i = ll(a); i < ll(b); ++i)
template<class T>bool chmax(T &former, const T &b) { if (former<b) { former=b; return true; } return false; }
template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return true; } return false; }
template<class T>T sqar(T x){ return x*x; }//sqrt(x)は平方根;
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(v[0])>()) //降順でVをソート
#define p_queue(v) priority_queue<v, vector<v>, greater<v> >
template<class T> inline void princ(T x){cout<<x<<" ";}; 
template<class T> inline void print(T x){cout<<x<<"\n";};
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
///////////////////////////////////////////////////////////////////////////////////

void solve(){
    int n,m;
    cin >> n >> m;
    int ctr=0;
    p_queue(P) que;
    rp(i,m){
        int a,b;
        cin >> a >> b;
        if(a<b) swap(a,b);
        que.push(mp(a,b));
    }
    int pos=1;
    while(!que.empty()){
        P p=que.top(); que.pop();
        if(p.second<pos) continue;
        pos=p.first;
        ctr++;
    }
    print(ctr);
    return;
}
int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    std::cout<<std::fixed<<std::setprecision(30);
    solve();
    return 0;
}

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

int main(){
  std::string s;
  std::cin >> s;
  int posA = 0, posZ = s.size() - 1;
  for(int i = 0; i < posZ; i++){
    if(s.at(i) != 'A') continue;
    posA = i;
    break;
  }
  for(int i = posZ; i > posA; i--){
    if(s.at(i) != 'Z') continue;
    posZ = i;
    break;
  }
  std::cout << posZ - posA + 1 << std::endl;
}

Measured memory_bytes: 640
import java.util.*;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = Integer.parseInt(sc.next());
		int[] h = new int[N];
		for (int i=0;i<N;i++) {
			h[i]=Integer.parseInt(sc.next());
		}

		int cnt=0;
		loop:while (true) {
			int left=0;
			for (int i=0;i<N;i++) {
				if (h[i]!=0) {
					left=i;
					break;
				}
				if (i==N-1) {
					break loop;
				}
			}
			for (int i=left;i<N;i++) {
				if (h[i]>0) {
					h[i]--;
					if (i==N-1) {
						cnt++;
					}
				} else if (h[i]==0 || i==N-1) {
					cnt++;
					break;
				}
			}
		}
		System.out.println(cnt);
	}
}

Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  a+=b;c+=d;
  if(a>c)
    cout<<"Left";
  else if(a<c)
    cout<<"Right";
  else
    cout<<"Balanced";
}

Measured memory_bytes: 256
use std::io::Read;
use std::str::SplitWhitespace;
use std::str::FromStr;

pub fn read_stdin() -> String {
    let mut s = String::new();
    ::std::io::stdin().read_to_string(&mut s).unwrap();
    s
}

pub trait Parse<T> {
    fn parse(&mut self) -> T;
}

impl<'a, T> Parse<T> for SplitWhitespace<'a>
where
    T: FromStr,
{
    fn parse(&mut self) -> T {
        let word = self.next().unwrap();
        word.parse().ok().unwrap()
    }
}

fn main() {
    let source = read_stdin();
    let mut iter = source.split_whitespace();
    let s: u32 = iter.parse();

    let is_mmyy = 1 <= s / 100 && s / 100 <= 12;
    let is_yymm = 1 <= s % 100 && s % 100 <= 12;
    let result = match (is_mmyy, is_yymm) {
        (true, true) => "AMBIGUOUS",
        (true, false) => "MMYY",
        (false, true) => "YYMM",
        _ => "NA",
    };

    println!("{}", result);
}


Measured memory_bytes: 4352
#include<stdio.h>


typedef struct{
    char suit;
    int value;
}Card;

void bubblesort(Card A[],int N ){
    int i,j;
    Card n;
    
    
    for(i=0;i<N;i++){
        for(j=N-1;j>=i+1;j--){
            if(A[j].value < A[j-1].value){
                n=A[j];
                A[j]=A[j-1];
                A[j-1]=n;
            }
        }
    }
}

void selectionSort(Card A[],int N){
    int i,j,minj;
    Card n;
    
    for(i=0;i<N;i++){
        minj=i;
        for(j=i;j<N;j++){
            if(A[j].value < A[minj].value){
            minj=j;
            }
        }
    n=A[i];
    A[i]=A[minj];
    A[minj]=n;
    }
}

int handan(Card C1[],Card C2[],int N){
    int i;
    
    for(i=0;i<N;i++){
        if(C1[i].suit!=C2[i].suit){
            return 0;
        }
    }
    return 1;
}

void print(Card A[],int N){
    int i;
    
    for(i=0;i<N;i++){
        if(i>0)printf(" ");
        printf("%c%d",A[i].suit,A[i].value);

    }
    
    printf("\n");
    
}

int main(){
    int n,i;
    Card C1[36],C2[36];
    scanf("%d",&n);
    
    for(i=0;i<n;i++){
        scanf(" %c%d",&C1[i].suit,&C1[i].value);

    }
    
     /*for(i=0;i<n;i++){
     printf("%c%d ",C1[i].suit,C1[i].value);
     }
     putchar('\n');*/
    
    for(i=0;i<n;i++) C2[i]=C1[i];
    
    bubblesort(C1,n);
    selectionSort(C2,n);
    
    print(C1,n);
    printf("Stable\n");
    print(C2,n);
    
    if(handan(C1,C2,n)==1){
        printf("Stable\n");
    }else {
        printf("Not stable\n");
    }
    return 0;
    
}



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

int main(){
    constexpr long MOD = 1000000007;
    long N;
    cin >> N;
    long dp{N % MOD};
    //vector<long> sum(N + 3, (N - 1) % MOD * N % MOD);
    vector<long> sum(4, (N - 1) % MOD * N % MOD);
    sum[0] = 0;
    for(long i = 3; i != N + 3; ++i){
        sum[3] = (sum[2] - 1 + (dp += sum[0])) % MOD;
        swap(sum[1], sum[0]);
        swap(sum[1], sum[2]);
        swap(sum[3], sum[2]);
    }
    cout << dp % MOD << endl;
    return 0;
}

Measured memory_bytes: 256
def main():
    n = int(input())
    a_lst = list(map(int, input().split()))
    number = 1
    count = 0

    for i in range(n):
        if a_lst[i] == number:
            number += 1
        else:
            count += 1

    if 1 not in a_lst:
        count = -1

    print(count)


if __name__ == '__main__':
    main()

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

using namespace std;

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

struct uni
{
  vector<int> data;
  uni(int s) : data(s, -1) { }
  void unite(int x, int y) {
    x = root(x), y = root(y);
    if(x != y) {
      if(data[y] < data[x]) swap(x, y);
      data[x] += data[y]; data[y] = x;
    }
  }
  
  bool same(int x, int y) {
    return root(x) == root(y);
  }
  
  int root(int x) {
    return data[x] < 0 ? x : data[x] = root(data[x]);
  }
};

struct edges {
  int u, v, c;
  bool operator < (const edges& e) const {
    return c < e.c;
  }
};

int const INF = 1<<29;

int main() {
  
  int N, M;
  while(cin >> N >> M && (N|M)) {
    vector<edges> es;
    rep(i, M) {
      int a, b, c;
      cin >> a >> b >> c; a--, b--;
      es.push_back((edges){a, b, c});
    }
    sort(es.begin(), es.end());
    int ret = INF;
    
    for(; (int)es.size() >= N-1;) {
      uni uf(N);
      int last = -1;
      rep(i, es.size()) {
	if(!uf.same(es[i].u, es[i].v)) {
	  uf.unite(es[i].u, es[i].v);
	  last = i;
	}
      }
      rep(i, N) REP(j, i+1, N) {
	if(!uf.same(i, j)) { goto exit; }
      }
      ret = min(ret, es[last].c-es[0].c);
      es.erase(es.begin());
    }
    
  exit:;
    cout << (ret < INF ? ret : -1) << endl;
    
  }
  
  return 0;
}

Measured memory_bytes: 1352
#include <iostream>
#include <algorithm>

using namespace std;

int main()
{
  /******input******/
  int N;
  cin >> N;
  int d[N];
  for( int i = 0; i < N; i++) cin >> d[i];
  /******input******/

  /******count up different diameter******/
  sort(d, d + N);
  int X;
  X = 1;
  for( int j=1; j<N; j++){
    if( d[j-1] != d[j] ) X++;
  }
  /******count up different diameter******/


  cout << X << "\n";

  return 0;
}


Measured memory_bytes: 256
import copy
import math

# a = get_int()
def get_int():
    return int(input())
# a = get_string()
def get_string():
    return input()
# a_list = get_int_list()
def get_int_list():
    return [int(x) for x in input().split()]
# a_list = get_string_list():
def get_string_list():
    return input().split()
# a, b = get_int_multi()
def get_int_multi():
    return map(int, input().split())
# a_list = get_string_char_list()
def get_string_char_list():
    return list(str(input()))
# print("{} {}".format(a, b))
# for num in range(0, a):
# a_list[idx]
# a_list = [0] * a
'''
while (idx < n) and ():

    idx += 1
'''

def main():

    a, b, c, x, y = get_int_multi()
    ans = 100000 * 5000 * 2

    for i in range(0,x+1):

        for ii in (max(0,(x - i) * 2), max(0,(y - i) * 2, (x - i) * 2)):
            price = i * a

            price += ii * c
            cnt_b = max(0, y - (ii // 2))
            price += cnt_b * b
            ans = min(ans, price)

    print(ans)

if __name__ == '__main__':
    main()




Measured memory_bytes: 9220
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (sc.hasNext()) {
            int h = sc.nextInt();
            int w = sc.nextInt();
            if ((h | w) == 0) {
                break;
            }
            int m = h * h + w * w;
            int ah = Integer.MAX_VALUE;
            int aw = Integer.MAX_VALUE;
            int mMin = Integer.MAX_VALUE;

            for (int i = 1; i <= 150; i++) {
                for (int j = i + 1; j <= 150; j++) {
                    int mk = i * i + j * j;
                    if (i == h && j == w) {
                        continue;
                    }
                    if (mk < m || (mk == m && i < h)) {
                        continue;
                    }
                    if (mMin > mk || (mMin == mk && ah > i)) {
                        mMin = mk;
                        ah = i;
                        aw = j;
                    }
                }
            }
            System.out.println(ah + " " + aw);
        }
    }
}

Measured memory_bytes: 27796
import java.io.InputStream;
import java.io.PrintStream;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	InputStream in = System.in;
	PrintStream out = System.out;

	public void _main(String[] args) {
		Scanner sc = new Scanner(in);

		int n = sc.nextInt();
		String[] S = new String[n];
		for (int i = 0; i < n; i++) {
			S[i] = sc.next();
		}

		sc.close();

		int[][] c = new int[n][26];

		for (int i = 0; i < n; i++) {
			for (int j = 0; j < S[i].length(); j++) {
				int ch = S[i].charAt(j) - 'a';
				c[i][ch]++;
			}
		}

		StringBuffer ans = new StringBuffer();

		for (int x = 0; x <= 'z' - 'a'; x++) {
			int num = Integer.MAX_VALUE;
			for (int i = 0; i < n; i++) {
				num = Math.min(num, c[i][x]);
			}

			for (int j = 0; j < num; j++) {
				ans.append((char) (x + 'a'));
			}
		}

		out.println(ans.toString());
	}

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


Measured memory_bytes: 21844
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

int main()
{
    int n, a[300010];
    cin >> n;
    for (int i = 0; i < 3 * n; i++) cin >> a[i];

    sort(a, a + 3 * n);
    reverse(a, a + 3 * n);

    long long ans = 0;
    for (int i = 0; i < 2 * n; i++) {
        cerr << i << " " << a[i] << endl;
        if (i % 2) ans += a[i];
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1408
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <algorithm>
#include <cmath>
#include <ctime>
#include <vector>
#include <queue>
#include <map>
#include <stack>
#include <set>
#include <unordered_set>
using namespace std;
typedef long long LL;
typedef unsigned long long uLL;
#define ms(a, b) memset(a, b, sizeof(a))
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define eps 0.0000000001
#define IOS ios::sync_with_stdio(0);cin.tie(0);
#define random(a, b) rand()*rand()%(b-a+1)+a
const LL INF = 0x3f3f3f3f3f3f3f3f;
const int inf = 0x3f3f3f3f;
const int maxn = 100000 + 10;
const int mod = 1e9+7;
struct node{
    int s, t;
    node(int _s, int _t){
        s = _s;
        t = _t;
    }
    bool operator < (const node &x)const{
        return s < x.s;
    }
};
vector<node> hh[35];
int add[maxn], sum[maxn];
int main() {
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);
#endif
    int N, C, s, t, c;
    cin >> N >> C;
    for(int i = 1;i<=N;i++){
        cin >> s >> t >> c;
        hh[c].pb(node(s, t));
    }
    for(int i = 1;i<=30;i++){
        if(hh[i].size()==0) continue;
        sort(hh[i].begin(), hh[i].end());
        int ss = hh[i][0].s, tt = hh[i][0].t;
        for(int j = 1;j<hh[i].size();j++){
            if(tt==hh[i][j].s){
                tt = hh[i][j].t;
                continue;
            }
            add[ss]++;
            add[tt+1]--;

            ss = hh[i][j].s;
            tt = hh[i][j].t;
        }
        add[ss]++;
        add[tt+1]--;
    }
    int hh = 0;
    for(int i = 0;i<maxn;i++){
        hh += add[i];
        sum[i] += hh;
    }
    int ans = 0;
    for(int i = 0;i<maxn;i++){
        ans = max(ans, sum[i]);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 2304
#include <stdio.h>
#include <stdlib.h>

int ope[101];
char com[100];
int top = 0;

void push(int x) {
  top++;
  ope[top] = x;  
 
}


int pop() {
  top--;
  return ope[top+1];
  
}

  
  

  
int main() {
  int a,b = 0;
  int result;
  int c;
  int d,e;
  
  while(scanf("%s",com) != EOF) {
    
    if(com[0] == '+'){ 
      push(pop() + pop());
    }
    else if(com[0] == '-'){
      d = pop();
      e = pop();
      push(e - d);
    } else if(com[0] == '*') {
      push(pop() * pop());
    }	else {
      push(atoi(com));
    }
    
  }

  printf("%d\n",pop());

  return 0;
  
}

Measured memory_bytes: 548
MOD = 10 ** 9 + 7

n, m = map(int, input().split())
a_s = [int(input()) for _ in range(m)] + [n + 1]
dp = [0 for _ in range(n + 1)]
dp[0] = 1
a_pos = 0
for i in range(1, n + 1):
    if a_s[a_pos] == i:
        a_pos += 1
        continue
    dp[i] = dp[i - 1] + dp[i - 2]
    dp[i] %= MOD
print(dp[-1])


Measured memory_bytes: 13784
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <cmath>
#include <iostream>
using namespace std;

vector<int> p;

class UnionFind {
public:
	vector<size_t> parent;
	vector<size_t> rank;
protected:
	size_t findParent(size_t x) {
		if (parent[x] == x) {
			return x;
		}
		else {
			size_t p = findParent(parent[x]);
			parent[x] = p;
			return p;
		}
	}
public:
	explicit UnionFind(size_t size) {
		parent.reserve(size);
		rank.reserve(size);
		for (size_t i = 0; i < size; i++)
		{
			parent[i] = i;
			rank[i] = 0;
		}
	}
	virtual ~UnionFind() {}
	void unite(size_t x, size_t y) {
		size_t xi = findParent(x);
		size_t yi = findParent(y);
		if (xi == yi) return;
		if (rank[xi] < rank[yi]) {
			parent[xi] = yi;
		}
		else if (rank[xi] > rank[yi]) {
			parent[yi] = xi;
		}
		else {
			parent[yi] = xi;
			rank[xi]++;
		}
	}

	bool isSame(size_t x, size_t y) {
		return findParent(x) == findParent(y);
	}

};

void Equals() {


	int N,M;
	cin >> N >> M;
	p = vector<int>(N,0);
	for (size_t i = 0; i < N; i++)
	{
		cin >> p[i];
	}

	UnionFind uf(N);
	for (size_t i = 0; i < M; i++)
	{
		int x, y;
		cin >> x >> y;
		uf.unite(x - 1, y - 1);
	}
	int res = 0;

	for (size_t i = 0; i < N; i++)
	{
		if (uf.isSame(i, p[i] - 1)) {
			res++;
		}
	}

	cout << res;
}

int main() {
	Equals();
	return 0;
}

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

int main(){
    ll m, d;
    cin >> m >> d;
    ll ans = 0;
    for(ll i = 1; i <= m; ++i){
        for(ll j = 1; j <= d; ++j){
            const auto j1 = j % 10;
            const auto j10 = j / 10;
            if(j1 >= 2 && j10 >= 2 && j1 * j10 == i){
                ans++;
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3640
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <map>

using namespace std;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    map<string, int> m;
    int scr = 0;
    int n;
    string s;
    cin >> n;
    for(int i = 0; i < n; ++i)
    {
        cin >> s;
        ++m[s];
    }
    cin >> n;
    for (int i = 0; i < n; ++i)
    {
        cin >> s;
        --m[s];
    }
    map<string, int>::iterator it;
    for(it = m.begin(); it != m.end(); ++it)
    {
        scr = max(scr, it->second);
    }
    cout << scr << endl;

    return 0;
}

Measured memory_bytes: 256
n = gets.to_i
S = gets.chomp.split('')
n_r = S.count('R')
n_g = S.count('G')
n_b = S.count('B')
ans = 0
(0..n-1).each do |i|
  ((i + 1)..n-1).each do |j|
    next if S[i] == S[j]

    k = (j - i) + j
    next if k > n - 1
    next if S[i] == S[k] || S[j] == S[k]
    ans += 1
  end
end
puts n_r * n_g * n_b - ans

Measured memory_bytes: 14380
using System;
    class Program
    {
        static void Main(string[] args)
        {
            string[] xInputs1 = Console.ReadLine().Split(' ');
            int xItemCount = int.Parse(xInputs1[0]);
            int xSelectedItemMin = int.Parse(xInputs1[1]);
            int xSelectedItemMax = int.Parse(xInputs1[2]);

            long[] xValues = new long[xItemCount];
            string[] xInputs2 = Console.ReadLine().Split(' ');
            for (int i = 0; i < xItemCount; ++i)
            {
                xValues[i] = long.Parse(xInputs2[i]);
            }

            Array.Sort(xValues);
            Array.Reverse(xValues);

            long[] xSelectedValues = new long[xSelectedItemMin];
            Array.Copy(xValues, 0, xSelectedValues, 0, xSelectedItemMin);

            double xAverageMax = Average(xSelectedValues);

            long xThresholdValue = xSelectedValues[xSelectedValues.Length - 1];
            int xThresholdItemCount = CountSameValueItem(xValues, xThresholdValue);
            int xSelectedThresholdItemCount = CountSameValueItem(xSelectedValues, xThresholdValue);

            ulong xSelectPatternCount = CountSelectPattern(xSelectedValues.Length, xThresholdItemCount, xSelectedThresholdItemCount, xSelectedItemMax);

            Console.WriteLine(string.Format("{0:0.000000}", xAverageMax));
            Console.WriteLine(xSelectPatternCount);
        }
        static double Average(long[] xValue)
        {
            long xSum = 0;
            for (int i = 0; i < xValue.Length; ++i)
            {
                xSum += xValue[i];
            }
            return (double)xSum / xValue.Length;
        }
        static int CountSameValueItem(long[] xValues, long xValue)
        {
            int xCount = 0;
            for (int i = 0; i < xValues.Length ; ++i)
            {
                if (xValue == xValues[i])
                {
                    xCount += 1;
                }
            }
            return xCount;
        }
        static ulong CountSelectPattern(int xSelectedItemCount, int xThresholdItemCount, int xSelectedThresholdItemCount,int xSelectedItemMax)
        {
            ulong xCount = 0;
            if (xSelectedItemCount == xSelectedThresholdItemCount)
            {
                for (int i = xSelectedThresholdItemCount; i <= xSelectedItemMax; ++i)
                {
                    xCount += Combination(xThresholdItemCount, i);
                }
            }
            else
            {
                xCount += Combination(xThresholdItemCount, xSelectedThresholdItemCount);
            }
            return xCount;
        }
        static ulong Combination(int n, int r)
        {
            ulong xValue = 1;
            for (int i = 0; i < r; ++i)
            {
                xValue *= (ulong)(n - i);
                xValue /= (ulong)(i + 1);
            }
            return xValue;
        }
    }

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

const int N=100000+50;

signed main(){
    ios::sync_with_stdio(false);
    int h1,m1,h2,m2,k;
    cin>>h1>>m1>>h2>>m2>>k;
    int total=((h2*60)+m2)-((h1*60)+m1);

    total-=k;
    if(total<0){
        total=0;
    }
    cout<<total;
    
}
/*

Mistakes to take care of-

1. For string s, s+=a is similar to appending to s. s = s + a takes O|s| + O|a| time. 
Relevant problem where I made mistake - https://codeforces.com/contest/1326/problem/D2

2. Try using constant value of N to declare arrays, etc. Else you might get hacked / FST.
Relevant problem where I made a mistake - https://codeforces.com/contest/1307/problem/D

3. While exponentiation, avoid modding the exponent. Or mod with mod-1.
Relevant problem where I made a mistake - https://codeforces.com/contest/1332/problem/E

4. modulo operator (%) in c++ returns the sign of the divisor.
Eg. (-1%8) = -1
Relevant problem where I made a mistake - https://codeforces.com/contest/1345/submission/79809463
*/

Measured memory_bytes: 3608
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
int par[100005];
int find(int x){
	return x == par[x]?x:find(par[x]); 
} 
int main(){
	int n,q,i,j;
	while(cin>>n>>q&&(n+q)){
		for(i=1;i<n;i++)
			scanf("%d",&par[i+1]);
			par[1]=1;
			getchar();
			char c ;
			long long ans =0;
			for(i=1;i<=q;i++){
				c=getchar();
				scanf("%d",&j);
				getchar();
				if(c=='M')
				par[j]=j;
				else{
					ans+=(long long)find(j);
				}
			}
			cout<<ans<<endl;
	}
}


Measured memory_bytes: 3524
#include <cstdio>

main(){
     int n,c=0;
     float w,h;
     while(~scanf("%d,%f,%f ",&n,&w,&h)){
	  if(w/h/h >= 25){
	       printf("%d\n", n);
	       c++;
	  }
     }
     if(!c){
	  puts("ツ該ツ督鳴づ按つオ");
     }
}

Measured memory_bytes: 0
N=int(input())
a=[]

for i in range(N):
    yo=list(map(int,input().split()))
    a.append(yo)
#print(a)

a.sort(key=lambda x:x[1])

#print(a)
t=0
k=0
for i in range(N):

    t+=a[i][0]
    if t<= a[i][1]:
        k=k
    else:
        k+=1
if k==0:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 53716
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
using namespace std;
#define rep(i,n) for(int iu=0; i<(n); ++i)

int main(){
    int a;
    string s;
    cin>>a>>s;
    if(a>=3200)cout<<s<<endl;
    else cout<<"red"<<endl;
    return 0;
}

Measured memory_bytes: 256