akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

#define rep(i,n) for(signed i=0;i<n;++i)
#define int long long
#define str string
#define debg(a) cout<<#a<<":"<<a<<endl;
#define vint vector<signed>
#define all(a) a.begin(),a.end()
#define pb(a) push_back(a)
#define yn(a) cout<<((a)?"Yes":"No")<<endl;
#define YN(a) cout<<((a)?"YES":"NO")<<endl;
#define call(a) for(auto i:(a))cout<<i<<" ";cout<<endl;
#define ENDL printf("\n");
signed main(){
  int n;
  cin>>n;
  int t[n+1],p[n+1],x,y;
  for(int i=1;i<=n;++i){
    cin>>t[i]>>x>>y,p[i]=x+y;
  }
  t[0]=0;p[0]=0;
  bool ans=true;
  rep(i,n+1)if(t[i]<p[i])ans=false;
  int td[n],pd[n];
  for(int i=0;i<n;++i){
    td[i]=abs(t[i]-t[i+1]);
    pd[i]=abs(p[i]-p[i+1]);
  }
  rep(i,n){
    if(td[i]%2!=pd[i]%2)ans=false;
  }
  yn(ans);

  return 0;
}


Measured memory_bytes: 3328
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

#define MAXOP 100
#define NUMBER '0'

int getop(char[]);
void push(double);
double pop(void);

/*逆ポーランド電卓プログラム*/
int main()
{
  int type;
  double op2;
  char s[MAXOP];

  while ((type = getop(s)) != EOF)
  {
    switch (type)
    {
    case NUMBER:
      push(atof(s));
      break;
    case '+':
      push(pop() + pop());
      break;
    case '*':
      push(pop() * pop());
      break;
    case '-':
      op2 = pop();
      push(pop() - op2);
      break;
    case '/':
      op2 = pop();
      if (op2 != 0.0)
        push(pop() / op2);
      else
        printf("error: zero divisor\n");
      break;
    case '\n':
      printf("%.8g\n", pop());
      break;
    default:
      printf("%s", s);
      break;
    }
  }
  return 0;
}

#define MAXVAL 100

int sp = 0;
double val[MAXVAL];

/* push: fを値スタックにプッシュする*/
void push(double f)
{
  if (sp < MAXVAL)
    val[sp++] = f;
  else
    printf("error: stack full, can't push %g\n", f);
}

/* pop: スタックをポップし，一番上の値を返す*/
double pop(void)
{
  if (sp > 0)
    return val[--sp];
  else
  {
    printf("error: stack empty\n");
    return 0.0;
  }
}

#include <ctype.h>

int getch(void);
void ungetch(int);

/* getop:　次の演算子あるいは数値の被演算数をとってくる*/
int getop(char s[])
{
  int i, c;

  while ((s[0] = c = getch()) == ' ' || c == '\t')
    ;
  s[1] = '\0';
  if (!isdigit(c) && c != '.')
    return c; /*　cは数ではない */
  i = 0;
  if (isdigit(c)) /*　整数部を集める　*/
    while (isdigit(s[++i] = c = getch()))
      ;
  if (c == '.') /*　小数部を集める　*/
    while (isdigit(s[++i] = c = getch()))
      ;
  s[i] = '\0';
  if (c != EOF)
    ungetch(c);
  return NUMBER;
}

#define BUFSIZE 100

char buf[BUFSIZE];
int bufp = 0;

int getch(void) /* 1文字を取ってくる */
{
  return (bufp > 0) ? buf[--bufp] : getchar();
}

void ungetch(int c) /* 文字を入力に戻す */
{
  if (bufp >= BUFSIZE)
    printf("ungetch: too many characters\n");
  else
    buf[bufp++] = c;
}


Measured memory_bytes: 2092
import java.util.*;


public class Main {

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

        int N = sc.nextInt();
        int K = sc.nextInt();
        int[] H = new int[N];
        for(int i=0;i<N;i++){
            H[i] = sc.nextInt();
        }

        Arrays.sort(H);

        long ans = 0;

        for(int i=0;i<N-K;i++){
            ans += H[i];
        }
        System.out.println(ans);



    }

}






Measured memory_bytes: 66488
import java.util.*;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int x = sc.nextInt();
        int y = sc.nextInt();

        long ans = Integer.MAX_VALUE;
        for(int i=0;i<=x;i++){
            long now = a*i;
            now += (x-i)*2*c;
            int remB = Math.max(0,y-(x-i));
            now += Math.min(remB*b,remB*2*c);
            ans = Math.min(now,ans);
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 23764
from collections import deque
N,M=map(int,input().split())
to=[[] for _ in range(N)]
for _ in range(M):
  a,b=map(int,input().split())
  to[a-1].append(b-1)
  to[b-1].append(a-1)
q=deque([0])
r=[None]*N
while q:
  x=q.popleft()
  for i in to[x]:
    if r[i] is None:
      q.append(i)
      r[i]=x+1
print("Yes",*r[1:],sep="\n")

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

int main(){
    long long N, T;
    cin >> N >> T;
    long long t[N];
    for(int i =0; i < N; i++){
        cin >> t[i];
    }
    long long ans = N*T;
    for(int i =0; i < N-1; i++){
        if(t[i + 1]- t[i] < T) ans -= T- (t[i+1] - t[i]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 1792
def game(a, b, c):
    decks = {'a': list(a), 'b': list(b), 'c': list(c)}
    player = 'a'
    while decks[player]:
        player = decks[player].pop(0)
    return player.upper()


if __name__ == '__main__':
    deck_a = input()
    deck_b = input()
    deck_c = input()
    print(game(deck_a, deck_b, deck_c))

Measured memory_bytes: 3064
n1,n2,n3,n4 = map(int,input().split())
 
if n1==1 or n2==1 or n3==1 or n4==1:
  if n1==7 or n2==7 or n3==7 or n4==7:
    if n1==9 or n2==9 or n3==9 or n4==9:
      if n1==4 or n2==4 or n3==4 or n4==4:
        print("YES")
      else:
        print("NO")
    else:
      print("NO")
  else:
    print("NO")
else:
  print("NO")

Measured memory_bytes: 3064
#line 1 "a.cpp"
// -----------------------------------
// author   : MatsuTaku
// country  : Japan
// created  : 09/03/20 01:08:28
// -----------------------------------

#include <bits/stdc++.h>
#line 4 "/mnt/c/Users/tkmma/competitive_programming/CPBF/library/include/unionfind.hpp"

class UnionFind {
 private:
  std::vector<int> par_,sz_;

 public:
  explicit UnionFind(size_t size) : par_(size), sz_(size, 1) {
    std::iota(par_.begin(), par_.end(), 0);
  }

  int root(int u) {
    if (u == par_[u])
      return u;
    return par_[u] = root(par_[u]);
  }

  bool are_union(int u, int v) {
    return root(u) == root(v);
  }

  int size_of(int u) {
    return sz_[root(u)];
  }

  bool unite(int u, int v) {
    if (are_union(u,v))
      return false;
    if (size_of(u) < size_of(v))
      std::swap(u,v);
    sz_[root(u)] += size_of(v);
    par_[root(v)] = root(u);
    return true;
  }

};

#line 9 "a.cpp"

using namespace std;
using ll = long long;

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

  int n,k,l; cin>>n>>k>>l;
  UnionFind cr(n), ct(n);
  for (int i = 0; i < k; i++) {
    int p,q; cin>>p>>q; p--; q--;
    cr.unite(p,q);
  }
  for (int i = 0; i < l; i++) {
    int p,q; cin>>p>>q; p--; q--;
    ct.unite(p,q);
  }
  unordered_map<uint64_t,int> id(n);
  for (int i = 0; i < n; i++) {
    id[(uint64_t)cr.root(i) << 32 | ct.root(i)]++;
  }
  for (int i = 0; i < n; i++) {
    cout << id[(uint64_t)cr.root(i) << 32 | ct.root(i)] << " ";
  }
  cout << endl;

  return 0;
}


Measured memory_bytes: 13380
#include <stdio.h>
#include <vector>
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
using namespace std;

typedef long long ll;

int main() {
  int N,T;
  cin>>N>>T;
  int ans = 1e9 + 1;
  for (int i = 0; i < N; i++) {
    int c,t;
    cin>>c>>t;
    if (c < ans && t <= T) {
      ans = c;
    }
  }
  if (ans == 1e9 + 1) cout<<"TLE"<<endl;
  else cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 256
using System;
using System.Linq;//リストの使用
using System.Collections.Generic;
using System.Text;//テキストの高速出力に必要
class Program
{
	static void Main()
	{
		string[] input = Console.ReadLine().Split(' ');
		int n = int.Parse(input[0]);
		int k = int.Parse(input[1]);
		long answer = 0;
    long[] nums = Array.ConvertAll(Console.ReadLine().Split(' '),long.Parse);
    Array.Sort(nums);

    for(int i = 0; i < n-k; i++)
    {
      answer += nums[i];
    }

		Console.WriteLine(answer);
	}
}

Measured memory_bytes: 30812
import sys
sys.setrecursionlimit(500000)

def input():
    return sys.stdin.readline()[:-1]

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

def ii():
    return int(input())

def i2(n):
    tmp = [list(mi()) for i in range(n)]
    return [list(i) for i in zip(*tmp)]


def main():
    O = input()
    E = input()
    ans = ''
    for i in range(len(O)+len(E)):
        if i%2:
            ans += E[i//2]
        else:
            ans += O[i//2]

    print(ans)



if __name__ == '__main__':
    main()


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

int main()
{
    string S, T;

    cin >> S;
    cin >> T;

    if (S.size() == T.size() - 1 &&
        S == T.substr(0, T.size() - 1))
    {
        cout << "Yes";
        return 0;
    }
    cout << "No";

    return 0;
}


Measured memory_bytes: 3588
#include <iostream>

#define Nmax int(1e5 + 1)
using namespace std;

char s[Nmax];
int nr,p;

int main()
{
    ios_base::sync_with_stdio(0);
    cin >> s;
    p = '1' - s[0];
    for(int i = 1; s[i]; ++i)
    {
        if((s[i] - '0') != p)
            nr++,s[i] = p + 48;
        p = '1' - s[i];
    }
    cout << nr;
    return 0;
}


Measured memory_bytes: 384
#include<stdio.h>
int main(){
    long int S[1000000];
    long int c=1,a=0;
    long int N,MIN;
    scanf("%Ld",&N);
    for(a=0;a<N;a++){
      scanf("%Ld",&S[a]);
    }
  MIN=S[0];
  

    for(long int b=1;b<N;b++){
        if(MIN>=S[b]){
            c++;
          MIN=S[b];
        }else{
        }
    }
    printf("%Ld",c);
    return 0;

}


Measured memory_bytes: 3712
import sys
sys.setrecursionlimit(10**9)
INF=10**18
def input():
    return sys.stdin.readline().rstrip()

def main():
    N=int(input())
    S=list(input())
    if N%2==0:
        for i in range(N//2):
            if S[i]!=S[N//2+i]:
                print('No')
                break
        else:
            print('Yes')
    else:
        print('No')

if __name__ == '__main__':
    main()


Measured memory_bytes: 38384
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vin=vector<int>;
using vll=vector<long long>;
using vvin=vector<vector<int>>;
using vvll=vector<vector<long long>>;
using vstr=vector<string>;
using vvstr=vector<vector<string>>;
using vch=vector<char>;
using vvch=vector<vector<char>>;
using vbo=vector<bool>;
using vvbo=vector<vector<bool>>;
using vpii=vector<pair<int,int>>;
using pqsin=priority_queue<int,vector<int>,greater<int>>;
#define mp make_pair
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,s,n) for(int i=(s);i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define decp(n) cout<<fixed<<setprecision((int)n)
#define _GLIBCXX_DEBUG
int main(){
    int r;
    cin>>r;
    decp(10);
    cout<<(double)2*r*3.1415926535<<endl;
}

Measured memory_bytes: 3792
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>

int main() {
  int K;
  scanf("%d", &K);

  std::queue<int> q;
  std::vector<int> v(K, 1<<29);
  v[1] = 1;

  q.emplace(1);
  while (!q.empty()) {
    int i=q.front();
    q.pop();

    int next[2]={(i*10)%K, (i+1)%K};
    for (int j=0; j<=1; ++j) {
      if (v[next[j]] > v[i]+j) {
        v[next[j]] = v[i]+j;
        q.emplace(next[j]);
      }
    }
  }

  printf("%d\n", v[0]);
  return 0;
}


Measured memory_bytes: 768
#include <bits/stdc++.h>
#define ll long long
#define vi vector<int>
#define e "\n"
#define MaRiaMa { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); }
#define fix(n) cout << fixed << setprecision(n);
using namespace std;
int main()
{
	MaRiaMa;
	int n=0, m=0;
	cin >> n;
	int ar[100];
	vector<string>b(100);
	vector<string>r(100);
	multiset<string> bl; multiset<string> re;
	for (int i = 0; i < n; i++)
	{
		cin >> b[i];
		bl.emplace(b[i]);
	}
	cin >> m;
	for (int i = 0; i < m; i++)
	{
		cin >> r[i];
		re.emplace(r[i]);
	}
	for (int i = 0; i <n; i++)
	{
		ar[i] = bl.count(b[i]) - re.count(b[i]);
	}
	if (*max_element(ar, ar + n) < 0)
		cout << "0";
	else
		cout << *max_element(ar, ar + n);
}





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

int main(){
  string S;
  cin>>S;
  int N=S.size();
  int64_t sum=0;

  for(int bit=0;bit<(1<<N-1);++bit){
  string T;
  for(int i=0;i<N-1;++i){
    T.push_back(S[i]);
    if(bit & (1<<i)){
     T.push_back('+');
    }
  }
  T.push_back(S[N-1]);
  int l=0;
  while(l<T.size()){
    int r=l;
    vector<int> v;
    while(r<T.size() && T[r]!='+'){
      int u=T[r]-'0';
      v.push_back(u);
      ++r;
    }
    for(int i=v.size()-1;i>=0;--i){
      sum += (int64_t)pow(10,v.size()-i-1)*v[i];
    }
    l = r+1;
  }
}

  cout<<sum<<endl;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	// abc114 D

	// primes under 100.
	private int[] primes = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97};

	public class PrimeFactorizater {
		
		public PrimeFactorizater(int max) {
		}
		
		public int[] getPrimeCount(int num) {
			int[] counts = new int[primes.length];
			Arrays.fill(counts, 0);

			for (int i=0; i<primes.length; i++) {
				int prime = primes[i];
				while (true) {
					if (num % prime == 0) {
						counts[i]++;
						num = num / prime;
					} else {
						break;
					}
				}
			}
			
			return counts;
		}
	}
	
	public void solve() {
		Scanner in = new Scanner(System.in);
		int N = in.nextInt();
		in.close();

		PrimeFactorizater pf = new PrimeFactorizater(N);
		int[] primesCount = new int[primes.length];
		Arrays.fill(primesCount, 0);
		
		for (int i=1; i<=N; i++) {
			int[] pfRet = pf.getPrimeCount(i);
			for(int j=0; j<pfRet.length; j++) {
				primesCount[j] += pfRet[j];
			}
		}
		
		int[] useCount = new int[primesCount.length];
		Arrays.fill(useCount, 0);
		long result = count(primesCount, useCount, 0);
		
		System.out.println(result);
	}

	private void debugPrint(int[] useCount) {
		String str = "";
		for (int i=0; i<useCount.length; i++) {
			if (useCount[i] > 0) {
				str += primes[i] + "^" + useCount[i] + " * ";
			}
		}
		System.out.println(str);
	}
	
	private long count(int[] primesCount, int[] useCount, int pos) {
		long ret = 0;
		long pattern = getPattern(useCount, pos);
		if (pattern == 75) {
			//debugPrint(useCount);
			return 1;
		} else if (pattern > 75) {
			return 0;
		}
		if (pos >= primesCount.length) {
			return 0;
		} else {
			for (int i=0; i<=primesCount[pos]; i++) {
				useCount[pos] = i;
				ret += count(primesCount, useCount, pos+1);
			}
		}
		return ret;
	}
	
	private long getPattern(int[] useCount, int pos) {
		long pattern = 1;	// count unused all elements instead of factor 1.
		for (int i=0; i<pos; i++) {
			pattern *= useCount[i] + 1;
			if (pattern > 75) {
				return pattern;
			}
		}
		return pattern;
	}
	
	public static void main(String[] args) {
		Main main = new Main();
		main.solve();
	}
}


Measured memory_bytes: 24404
#include<stdio.h>
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include<stack>
#include <queue>
#include<map>
#include <set>
#include<math.h>
using namespace std;
#define int long long
#define ll long long
#define rep(i,n) for(ll i=0;i<n;++i)
#define loop(i,m,n) for(ll i=m;i<n;++i)
#define ggr getchar(); getchar();return 0;
#define pie 3.141592653589793238462643383279
#define elif else if
#define P pair<ll,ll>
const int inf = 1000000007;
int bin(int bina) {
	int ans = 0;
	for (int i = 0; bina > 0; i++)
	{
		ans = ans + (bina % 2) * pow(10, i);
		bina = bina / 2;
	}
	return ans;
}
bool prime(int n) {
	for (ll i = 2; i <= sqrt(n); i++) {
		if (n % i == 0)return false;
	}
	return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x * y / gcd(x, y);
}
int kai(int x) {
	if (x == 0)return 1;
	return kai(x - 1) * x % inf;
}
int mod_pow(int x, int y, int mod) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % mod;
		}
		x = x * x % mod;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	return kai(x)* mod_pow(kai(x - y), inf - 2, inf) % inf * mod_pow(kai(y), inf - 2, inf) % inf;
}

signed main() {
	string s;
	cin >> s;
	int n = s.size();
	int sum=0,ans=0;
	rep(i, n) {
		if (s[i] == 'A')sum++;
		elif(s[i] == 'B' && s[i + 1] == 'C') {
			ans += sum;
			i++;
		}
		else sum = 0;
	}
	cout << ans << endl;
}


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

const int MAX = 310;
const ll INF = 1LL << 50;

ll G[MAX][MAX];
using pll = pair<ll, ll>;

int main(){
    int N, M; ll L;
    cin >> N >> M >> L;

    for(int i = 0; i < MAX; i++){
        for(int j = 0; j < MAX; j++) G[i][j] = INF;
        G[i][i] = 0;
    }
    for(int i = 0; i < M ; i++){
        int a, b; ll c; cin >> a >> b >> c; --a, --b;
        G[a][b] = G[b][a] = c;
    }

    vector<vector<pll> > dist(N, vector<pll>(N, {INF, INF}));
    for(int s = 0; s < N; s++){
        dist[s][s] = {0, 0};
        priority_queue<pair<pll, int>, vector<pair<pll, int> >, greater<pair<pll, int > > > que;
        que.push(make_pair(pll(0, 0), s));
        while(!que.empty()){
            auto p = que.top(); que.pop();

            ll v = p.second;
            ll kaisuu = p.first.first;
            ll used = p.first.second;

            if( p.first > dist[s][v]) continue;
            for(int nv = 0; nv < N; nv++){
                if(nv == v ) continue;
                if(G[v][nv] > L) continue;
                ll nused = used + G[v][nv];
                pll np = {0, 0};
                if(nused > L) np = {kaisuu + 1, G[v][nv]};
                else np = {kaisuu, nused};

                if(chmin(dist[s][nv],  np)) que.push(make_pair(np, nv));
            }
        }
    }

    
    int Q; cin >> Q;
    while(Q--){
        int a, b; cin >> a >> b; a--, b--;

        ll res = dist[a][b].first;
        if(res >= INF) cout << -1 << endl;
        else cout << res << endl;
    }
}

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

int main(){
    int n,l;
  	cin >> n >> l;
    vector<string> s(n);
    rep(i,n) cin >> s[i];
    sort(s.begin(),s.end());
    rep(i,n) cout << s[i];
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
using namespace std;
int main() {
	long long A, B, C, D;
	cin >> A >> B >> C >> D;
	long long a = C, b = D;
	long long  r = a % b;
	long long x = C * D;

	while (r != 0) {
		a = b;
		b = r;
		r = a % b;
	}

	long long CD = x / b;

	long long CCC = (B / C - A / C);
	if (A % C == 0)CCC++;
	long long DDD = (B / D - A / D);
	if (A % D == 0)DDD++;
	long long  CDCDCD = (B / CD - A / CD);
	if (A % CD == 0)CDCDCD++;
	cout << (B - A + 1) - (CCC + DDD - CDCDCD);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define debug(x) cerr << "[(" << __LINE__ << ") " << (#x) << "]: " << x << endl;

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

    int x, y, a, b, c;
    cin >> x >> y >> a >> b >> c;

    vector<pair<int, int>> d(a+b+c);

    int xx;
    for (int i=0; i<a; i++) {
        cin >> xx;
        d[i] = {xx, 0};
    }
    for (int i=0; i<b; i++) {
        cin >> xx;
        d[a+i] = {xx, 1};
    }
    for (int i=0; i<c; i++) {
        cin >> xx;
        d[a+b+i] = {xx, 2};
    }
    sort(d.begin(), d.end());

    ll ans = 0;
    int cnt = 0;
    while (x+y != cnt) {
        auto cur = d.back();
        if (cur.second == 2) {
            ans += cur.first;
            cnt++;
        } else if (cur.second == 1 && y > 0) {
            ans += cur.first;
            y--;
        } else if (cur.second == 0 && x > 0) {
            ans += cur.first;
            x--;
        }
        d.pop_back();
    }
    cout << ans << "\n";
}


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

struct data{
	int t;
	ll p,f;
	data(){}
	data(int tt,ll pp,ll ff){
		t=tt;
		p=pp;
		f=ff;
	}

	bool operator<(const data &d)const{
		if(f==d.f)return p<d.p;
		return f<d.f;
	}
};

struct CHTrick{
	deque<P> lines;
	bool isMonoticX=true;
	CHTrick(bool flag=true){
		isMonoticX=flag;
	}

	bool check(P l1,P l2,P l3){
		return (l3.second-l2.second)*(l2.first-l1.first)>=(l2.second-l1.second)*(l3.first-l2.first);
	}

	void add(ll a,ll b){
		P line(a,b);
		while(lines.size()>=2 && check(*(lines.end()-2),lines.back(),line)){
			lines.pop_back();
		}
		lines.push_back(line);
	}

	ll f(int i,ll x){
		return lines[i].first*x+lines[i].second;
	}
	ll f(P line,ll x){
		return line.first*x+line.second;
	}

	bool comp(ll lv,ll rv){
		return lv<=rv;
	}

	ll get(ll x){
		if(isMonoticX){
			while(lines.size()>=2 && comp(f(0,x),f(1,x))){
				lines.pop_front();
			}
			return f(0,x);
		}else{
			int low=-1,high=lines.size()-1;
			while(high-low>1){
				int mid=(high+low)/2;
				if(comp(f(mid,x),f(mid+1,x)))low=mid;
				else high=mid;
			}
			return f(high,x);
		}
	}
};

int n,T;
data d[4005];

CHTrick dp[4005];

int main(void){
	scanf("%d%d",&n,&T);
	for(int i=0;i<n;i++){
		scanf("%d%lld%lld",&d[i].t,&d[i].p,&d[i].f);
	}
	sort(d,d+n);
	dp[0].add(0,0);
	ll ans=0;
	for(int i=0;i<n;i++){
		for(int j=T-d[i].t;j>=0;j--){
			if(dp[j].lines.size()==0)continue;
			ll v=dp[j].get(d[i].f)+d[i].p-d[i].f*d[i].f;
			if(j==0){
				v+=d[i].f*d[i].f;
			}
			ans=max(v,ans);
			dp[j+d[i].t].add(2LL*d[i].f,v-d[i].f*d[i].f);
		}
	}
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 6292
template<class T> inline void chmin(T & a, T b) { if (a > b) a = b; }

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

void solve() {
	int N; string S; cin >> N >> S;
	int all_e = 0, all_w = 0;
	rep(i, S.size()) {
		if (S[i] == 'E') all_e++;
		else all_w++;
	}

	int res = (int)S.size();
	int cur_e = 0, cur_w = 0;
	int right_e;
	rep(i, S.size()) {
		right_e = all_e - cur_e;
		if (S[i] == 'E') right_e--;
		chmin(res, cur_w + right_e);

		if (S[i] == 'E') cur_e++;
		else cur_w++;
	}
	cout << res << endl;
}

int main(void) {
	solve();
	return 0;
}

Measured memory_bytes: 900
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <random>
#include <chrono>
#include <queue>
#include <ctime>
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
#define fs first
#define sc second
#define INF 1000000000
#define MOD 1000000007
#define EPS 0.00000001

int main() {
    int N, A, B; cin >> N >> A >> B;
    string S; cin >> S;
    int pass = 0;
    int fpass = 0;
    for(int i=0; i<N; i++){
        if(S[i]=='a' && pass < A + B){
            cout << "Yes" << endl;
            pass++;
        }
        else if(S[i]=='b' && pass < A + B && fpass < B){
            cout << "Yes" << endl;
            fpass++;
            pass++;
        }
        else cout << "No" << endl;
    }
    
    return 0;
}



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

using namespace std;

int n,k,a[100009],b[100009],c[100009],mn=1000000,mem[100009][10];

int calc(int d,int item)
{
    if(mem[d][item]!=-1)
    {
        return mem[d][item];
    }
    if(d==n)
        return 0;
    int x=-1,y=-1,z=-1;
    if(item!=1)
    {
        x=a[d]+calc(d+1,1);
    }
    if(item!=2)
    {
        y=b[d]+calc(d+1,2);
    }
    if(item!=3)
    {
        z=c[d]+calc(d+1,3);
    }
    int q=max(x,y);
    //cout<<max(q,z)<<endl;
    return mem[d][item]= max(q,z);
}

int main()
{
    for(int i=0;i<100005;i++)
    {
        for(int j=0;j<9;j++)
        {
            mem[i][j]=-1;
        }
    }
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>a[i]>>b[i]>>c[i];
    }
    cout<<calc(0,0);

    return 0;
}


Measured memory_bytes: 11520
program knight
  implicit none
  integer(8), parameter :: md = 1000000007_8
  integer :: x, y
  integer(8) :: n, k, i, num = 1_8, den = 1_8
  read(*,*) x, y
  if (2*y-x < 0 .or. 2*x-y < 0 .or. mod(x+y,3) /= 0) then
    write(*,'(i0)') 0
    stop
  end if
  n = int((x+y)/3,8)
  k = int((2*y-x)/3,8)
  do i = 1_8, k
    num = mod(num*(n-i+1_8),md)
    den = mod(den*i,md)
  end do
  write(*,'(i0)') mod(num*inv(den),md)
contains
  function inv(n) result(y)
    integer(8), intent(in) :: n
    integer(8) :: a, b, x, y, t, q
    a = modulo(n,md)
    b = md
    x = 0_8
    y = 1_8
    do while (b /= 0_8)
      q = a/b
      t = b
      b = mod(a,b)
      a = t
      t = y
      y = x
      x = t-q*x
    end do
    y = modulo(y,md)
  end
end program knight

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

#define INF 1e9
using namespace std;
using ll = long long;

int main() {

    int n; cin >> n;
    map<string, int> s;
    for (int i = 0; i < n; ++i) {
        string str; cin >> str;
        s[str]++;
    }

    int m; cin >> m;
    map<string, int> t;
    for (int i = 0; i < m; ++i) {
        string str; cin >> str;
        t[str]++;
    }

    ll ans = 0;

    for (auto item : s) {
        ll tmp = item.second - t[item.first];
        ans = max(ans, tmp);
    }

    ans = max(ans, (ll)0);

    cout << ans << endl;
}

Measured memory_bytes: 384
import sys

def main():
    input = sys.stdin.readline
    N, L = map(int, input().split())

    ans = 10**4
    total = 0
    for i in range(N):
        total += L + i
        if abs(L+i) <= abs(ans):
            ans = L + i

    return total - ans


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


Measured memory_bytes: 3060
from collections import deque
X,Y,A,B,C = map(int,input().split())
p = deque(sorted(list(map(int,input().split()))))
q = deque(sorted(list(map(int,input().split()))))
r = deque(sorted(list(map(int,input().split()))))

ans = 0
red,grn = 0,0
for i in range(X+Y):
    pi = 0 if red>=X else p[-1]
    qi = 0 if grn>=Y else q[-1]
    ri = 0 if len(r)<=0 else r[-1]
    if pi>ri and pi>qi:
        ans += p.pop()
        red += 1
    elif qi>ri:
        ans += q.pop()
        grn += 1
    else:
        ans += r.pop()

print(ans)

Measured memory_bytes: 23712
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define all(x) (x).begin(), (x).end()
using ll = long long;
using namespace std;
template <typename T> using vec = std::vector<T>;

int main() {
    int A, B, C;
    cin >> A >> B >> C;
    for(int i=1;i<=100;++i){
        if(A*i%B == C){
            cout << "YES" << endl;
            return 0;
        }
    }
    cout << "NO" << endl;
}


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

using namespace std;
#define rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define pb push_back

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


    stack<char> st;

    for(int i=0;i<s.size();i++){
        if(s[i]=='S'){
            if(st.empty()){
                st.push('S');
            }else if(st.top()=='S'){
                st.push('S');
            }else if(st.top()=='T'){
                st.push('S');
            }

            
        }else if(s[i]=='T'){
            if(st.empty()){
                st.push('T');
            }else if(st.top()=='S'){
                st.pop();
            }else if(st.top()=='T'){
                st.push('T');
            }  
        }
    }
    cout<<st.size()<<endl;
}

Measured memory_bytes: 900
#include <bits/stdc++.h>
 
#define loop(n, i) for(int i=0;i<n;i++)
#define all(v) v.begin(),v.end()
#define HERE cout << "HERE: " << __LINE__ << endl;
#define INSP(v) cout << v << " at " << __LINE__ << endl;

using namespace std;
typedef long long ll;

int main()
{
    int n; cin >> n;
    while (n--) {
        vector<ll> e(9);
        loop (9, i) {
            string s; cin >> s;
            e[i] = stoll(s, nullptr, 16) % (1ll<<32);
        }
        ll ans = 0;
        loop (32, i) {
            ll sum = 0;
            ll mask = (1 << i) - 1;
            loop (8, j) sum += ans ^ (mask & e[j]);
            loop (8, j) sum ^= e[j];
            sum &= (1ll << i);
            ans |= (sum ^ (e[8] & (1ll << i)));
        }
        cout << hex << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 3144
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <random>
#include <tuple>
#include <iomanip>
#include <cstring>

using namespace std;

typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define revrep(i, n) for(ll i = (n-1); i >= 0; i--)
#define pb push_back
#define f first
#define s second
const ll INFL = 1LL << 60;//10^18 = 2^60
const int INF = 1 << 30;//10^9
ll MOD = 1000000007;
//ll MOD  = 998244353;
vector<ll> dy = {0, 0, 1, -1, 1, 1, -1, -1, 0};
vector<ll> dx = {1, -1, 0, 0, 1, -1, 1, -1, 0};

ll max(ll a, ll b){return (a > b) ? a : b;}
ll min(ll a, ll b){return (a < b) ? a : b;}
ll max3(ll a, ll b, ll c){return max(a, max(b, c));};
ll max4(ll a, ll b, ll c, ll d){return max(max(a, b), min(c, d));};
ll min3(ll a, ll b, ll c){return min(a, min(b, c));};
ll min4(ll a, ll b, ll c, ll d){return min(min(a, b), min(c, d));};

ll min5(ll a, ll b, ll c, ll d, ll e){return min(min(a, b), min3(c, d, e));};

ll pow_long(ll x, ll k){
  ll res = 1;
  while(k > 0){
    if(k % 2) res *= x;
    x *= x;
    k /= 2;
  }
  return res;
}
ll pow_mod(ll x, ll k){
  x %= MOD; x += MOD; x %= MOD;
  ll res = 1;
  while(k > 0){
    if(k % 2){
      res *= x; res %= MOD;
    }
    x *= x; x %= MOD;
    k /= 2;
  }
  return res;
}

ll inverse(ll x){return pow_mod(x, MOD - 2);};

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

ll lcm(ll x, ll y){return x / gcd(x, y) * y;};

ll kai_mod(ll x){
  if(x == 0) return 1;
  return x * kai_mod(x-1) % MOD;
}

/*
//コンビネーション
const int MAXcomb = 200010;
ll fac[MAXcomb], finv[MAXcomb], inv[MAXcomb];
//facはn!,finvは1/n!
//invは逆元
void COMinit(){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for(int i = 2; i < MAXcomb; i++){
        fac[i] = fac[i-1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD/i) % MOD;
        finv[i] = finv[i-1] * inv[i] % MOD;
    }
}
ll comb(int n, int k){
    if(n < k) return 0;
    if(n < 0 || k < 0) return 0;
    return fac[n] * finv[k] % MOD * finv[n-k] % MOD;
}
*/

int main(){
  ll L;
  cin >> L;
  vector<ll> A(L);
  rep(i, L) cin >> A[i];
  ll dp[L+1][5];
  rep(i, L+1)rep(j, 5) dp[i][j] = INFL;
  dp[0][0] = 0;
  for(ll i = 1; i <= L; i++){
    ll e = A[i-1] % 2;
    ll o = 1 - e;
    if(A[i-1] == 0){
      e = 2;
      o = 1;
    }
    ll ad0 = dp[i-1][0], ad1 = dp[i-1][1], ad2 = dp[i-1][2], ad3 = dp[i-1][3], ad4 = dp[i-1][4];
    dp[i][0] = ad0 + A[i-1];
    dp[i][1] = min(ad0, ad1) + e;
    dp[i][2] = min3(ad0, ad1, ad2) + o;
    dp[i][3] = min4(ad0, ad1, ad2, ad3) + e;
    dp[i][4] = min5(ad0, ad1, ad2, ad3, ad4) + A[i-1];
  }
  cout << min5(dp[L][0], dp[L][1], dp[L][2], dp[L][3], dp[L][4]) << endl;

}


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

using namespace std;


int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, a;
  priority_queue<int> q;
  while (cin >> n && n) {
    for (int i = 0; i < n; i++) {
      cin >> a;
      q.push(a);
    }
    int found = 0;
    long long int l, r;
    while (q.size() > 1 && found < 2) {
      int p = q.top();
      q.pop();
      if (q.top() == p) {
        q.pop();
        if (found == 0) {
          l = p;
        }
        else {
          r = p;
        }
        found++;
      }
    }
    if (found == 2) cout << l*r << endl;
    else cout << 0 << endl;
  }
  return 0;
}


Measured memory_bytes: 892
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
const int INF = 0x3f3f3f3f;
int main(){
	//IOS;
	int h,a;
	cin>>h>>a;
	if(h%a==0)
	cout<<h/a<<endl;
	else
	{
		cout<<h/a+1<<endl;
	} 
	return 0;
}

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

using namespace std;
typedef long long ll;
typedef pair<ll, ll> p_ll;

template<class T>
void debug(T itr1, T itr2) { auto now = itr1; while(now<itr2) { cout << *now << " "; now++; } cout << endl; }
#define repr(i,from,to) for (int i=(int)from; i<(int)to; i++)
#define all(vec) vec.begin(), vec.end()
#define rep(i,N) repr(i,0,N)
#define per(i,N) for (int i=(int)N-1; i>=0; i--)

const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,30)-1;

vector<ll> fac;
void c_fac(int x=pow(10,6)+10) { fac.resize(x,true); rep(i,x) fac[i] = i ? (fac[i-1]*i)%MOD : 1; }
ll inv(ll a, ll m=MOD) { ll b = m, x = 1, y = 0; while (b!=0) { int d = a/b; a -= b*d; swap(a,b); x -= y*d; swap(x,y); } return (x+m)%m; }
ll nck(ll n, ll k) { return fac[n]*inv(fac[k]*fac[n-k]%MOD)%MOD; }
ll gcd(ll a, ll b) { if (a<b) swap(a,b); return b==0 ? a : gcd(b, a%b); }
ll lcm(ll a, ll b) { return a/gcd(a,b)*b; }


int main() {
  int A, B, M; cin >> A >> B >> M;
  int a[A]; rep(i,A) cin >> a[i];
  int b[B]; rep(i,B) cin >> b[i];
  int x[M], y[M], c[M]; 
  rep(i,M) { cin >> x[i] >> y[i] >> c[i]; x[i]--; y[i]--; }
  int result = INF;
  rep(i,M) result = min(result, a[x[i]]+b[y[i]]-c[i]);
  int ami = INF; rep(i,A) ami = min(ami,a[i]);
  int bmi = INF; rep(i,B) bmi = min(bmi,b[i]);
  result = min(result,ami+bmi);
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 2176
#include<cstdio>
using namespace std;
int main(){
  int a,b,c;
  scanf("%d%d%d",&a,&b,&c);
  if(a>b) a^=b^=a^=b;
  if(b>c) b^=c^=b^=c;
  if(a>b) a^=b^=a^=b;
  if((a==b&&b!=c)||(a!=b&&b==c)) printf("Yes");
  else printf("No");
  return 0;
}

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

using ll = long long;

int main() {
    int N;
    cin >> N;
    vector<vector<int>> A(2, vector<int>(N));
    rep(i, 2) {
        rep(j, N) {
            cin >> A[i][j];
        }
    }
    int ans = A[0][0];
    rep(i, N) {
        ans += A[1][i];
    }
    int s = ans;
    rep(i, N - 1) {
        s = s - A[1][i] + A[0][i + 1];
        ans = max(ans, s);
    }
    cout << ans << "\n";
}

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

using namespace std;

int main(void) {

	int A, B,X;
	cin >> X >> A >> B;
	
	X-=A;
	
	while(X>=B){
	    X-=B;
	}
	
	
    cout << X << endl;
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <map>
#include <algorithm>

using namespace std;

int a[100000];
int b[100000];
int c[200000];
int par[200000];

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

void unite(int x, int y) {
    x = find(x);
    y = find(y);
    
    if (x == y) return;
    
    par[x] = y;
}

int main() {
    int n, suma = 0, sumb = 0, ans = 0, i;
    vector <int> v, w;
    map <int, int> mp;
    
    scanf("%d", &n);
    
    for (i = 0; i < n; i++) {
        scanf("%d", &a[i]);
        
        v.push_back(a[i]);
        suma ^= a[i];
    }
    
    v.push_back(suma);
    
    for (i = 0; i < n; i++) {
        scanf("%d", &b[i]);
        
        w.push_back(b[i]);
        sumb ^= b[i];
    }
    
    w.push_back(sumb);
    
    sort(v.begin(), v.end());
    sort(w.begin(), w.end());
    
    for (i = 0; i < v.size(); i++) {
        if (v[i] != w[i]) {
            puts("-1");
            
            return 0;
        }
    }
    
    for (i = 0; i < n; i++) {
        if (a[i] != b[i]) break;
    }
    
    if (i == n) {
        puts("0");
        
        return 0;
    }
    
    for (i = 0; i < n * 2; i++) par[i] = i;
    
    for (i = 0; i < n; i++) {
        int x, y;
        
        if (a[i] == b[i]) continue;
        
        if (mp.count(a[i])) {
            x = mp[a[i]];
        } else {
            x = mp.size();
            mp[a[i]] = x;
        }
        
        if (mp.count(b[i])) {
            y = mp[b[i]];
        } else {
            y = mp.size();
            mp[b[i]] = y;
        }
        
        unite(x, y);
    }
    
    for (i = 0; i < n * 2; i++) c[find(i)]++;
    
    for (i = 0; i < n; i++) {
        if (a[i] != b[i]) ans++;
    }
    
    for (i = 0; i < n * 2; i++) {
        if (c[i] > 1) ans++;
    }
    
    if (mp.count(suma) && c[find(mp[suma])] > 1) ans--;
    
    printf("%d\n", ans);
    
    return 0;
}


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

int main()
{
	int n;
	cin >> n;
	auto s = set<int>();
	for(auto i = 0; i < n; ++i){
		int d;
		cin >> d;
		s.insert(d);
	}
	cout << s.size() << endl;
	return 0;
}

Measured memory_bytes: 256
# B
n = int(input())
s = str(input())

def count_c(str1, str2):
    s1 = [0] * 26
    s2 = [0] * 26
    count = 0
    for i in list(str1):
        s1[ord(i) - 97] += 1
    for i in list(str2):
        s2[ord(i) - 97] += 1
    for i in range(26):
        if s1[i] > 0 and s2[i] > 0:
            count += 1
    return count
max_c = 0
for i in range(1,n):
    max_c = max(max_c, count_c(s[:i], s[i:]))
print(max_c)

Measured memory_bytes: 3064
def create_array(n: int, r: int, mod, mod2):
    m_ls = [1] * (r + 1)

    for i, j in zip(range(n, 0, -1), range(1, r + 1)):
        m_ls[j] = (m_ls[j - 1] * i * pow(j, mod2, mod)) % mod
    return m_ls


def main():
    n, m, k = map(int, input().split())

    _mod = 998244353
    _mod2 = 998244351

    # res_x = m * ((m-1) ** (n-1-x)) * comb(n-1, x)
    # x:0, 2, ... , k
    # xをk->0とすると(m-1) ** (n-1-x)は少しずつかけていける

    comb_ar = create_array(n-1, k, _mod, _mod2)
    _z = (m - 1) ** (n - 1 - k)
    res = m * _z * comb_ar[k]
    res %= _mod

    if k > 0:
        for x in range(1, k + 1):
            _z *= m - 1
            _z %= _mod
            res += m * _z * comb_ar[k - x]
            res %= _mod

    print(res)


main()


Measured memory_bytes: 16796
#include <stdio.h>
#include <algorithm>
using namespace std;

int main(void) {
  int a[4], i;
  for(i = 0; i < 4; ++i)scanf("%d", &a[i]);
  sort(a, a + 4);
  if(a[0] == a[1] && a[2] == a[3]) printf("yes\n");
  else printf("no\n");
  return 0;
}


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

int main() {
	int n;
	cin>>n;
    ll ele;
    cin>>ele;
    ll gcd = ele;
    n--;
    while(n--)
    {
        cin>>ele;
        gcd = __gcd(gcd,ele);
    }
    cout<<gcd<<endl;
	return 0;
}

Measured memory_bytes: 256
n , m , x = map(int,input().split())
san = []
for i in range(n):
    san.append(list(map(int,input().split())))
ans = 10**8
for b in range(2**n):
    bs = format(b, 'b')
    bs = str(bs).rjust(n,'0')
    one = 0
    p = [0 for i in range(m)]
    for i in range(n):
        if bs[i] == "1":
            one += san[i][0]
            for j in range(1,m+1):
                p[j-1] += san[i][j]
    if min(p) >= x:
        ans = min(ans,one)
if ans == 10**8:
    print(-1)
else:
    print(ans)

Measured memory_bytes: 8988
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <bitset>
#include <cmath>
#include <string>
#define FI first
#define SE second
#define PF push_front
#define PB push_back
#define PPF pop_front
#define PPB pop_back
#define MA make_pair
#define ll long long
#define PA pair<int,int>
#define VE vector<int>
#define VP vector<PA>
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ROF(i,a,b) for(int i=b-1;i>=a;i--)
#define YES(i) cout<<(i?"YES":"NO")<<endl
#define Yes(i) cout<<(i?"Yes":"No")<<endl
using namespace std;
//
const int INF=1e9+7;
const int mod=1e9+7;
//
//
struct poi{
  int X;int Y;int Z;
  bool operator<(const poi&R)const{
    return X==R.X ? Y==R.Y ? Z<R.Z : Y<R.Y : X<R.X;
  }
};
//
//
int N,M;
int P[100000];
VE V[100000];
int f[100000];
void DFS(int now,int mem){
	FOR(i,0,(int)V[now].size()){
		if(f[V[now][i]]!=0){
			continue;
		}else{
			f[V[now][i]]=mem;
			DFS(V[now][i],mem);
		}
	}
}
int main(){
	cin>>N>>M;
	FOR(i,0,N){
		cin>>P[i];
		P[i]--;
	}
	FOR(i,0,M){
		int X,Y;
		cin>>X>>Y;
		X--;Y--;
		V[X].PB(Y);
		V[Y].PB(X);
	}
	int mem=1;
	FOR(i,0,N){
		if(f[i]==0){
			DFS(i,mem);
			mem++;
		}
	}
	int ans=0;
	FOR(i,0,N){
		if(f[i]!=0&&f[P[i]]==f[i]){
			ans++;
		}else if(i==P[i]){
			ans++;
		}
	}
	cout<<ans<<endl;
	return 0;
}


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

using namespace std;
int i,n,j,k,nr;
int a[105];
int main()
{
    cin>>n;
    for(i=1;i<=n;i++)
        cin>>a[i];

    sort(a+1, a+n+1);

    for(i=1;i<=n;i++)
    {
        for(j=i+1;j<=n;j++)
        {
            if(a[j]==a[i])
                continue;

            for(k=j+1;k<=n;k++)
            {
                if(a[k]==a[j])
                    continue;

                if(a[i]+a[j]>a[k])
                {
                    nr++;
                }

            }
        }
    }

    cout<<nr;
    return 0;
}


Measured memory_bytes: 3628
#include<stdio.h>

int n,w[101],s[101];

int min(int x,int y){return x>=y?y:x;}

int main(){
  scanf("%d",&n);
  for(int i=0;i<n;i++){
    scanf("%d",&w[i]);
    s[i]=s[i-1]+w[i];
  }
  for(int i=0;i<=n-1;i++)if(s[i]*2>=s[n-1]){
    printf("%d",min(s[i]*2-s[n-1],s[n-1]-s[i-1]*2));
    break;
  }
  return 0;
}

Measured memory_bytes: 128
fun main(args: Array<String>) {
    val arr = "1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51".split(", ")
    val K = readInputLine().toInt()

    println(arr[K - 1])
}

fun readInputLine(): String {
    return readLine()!!
}


Measured memory_bytes: 37744
#include<iostream>
using namespace std;
static const int MAX = 10000;

int main(){
    int buff[MAX];
    for(int i=0; i<MAX; i++){
        cin >> buff[i];
        if(buff[i] == 0){
            buff[i] = -1;
            break;
        }
    }
    for(int i=0; i<MAX; i++){
        if(buff[i] == -1)break;
        cout << "Case " << i+1 << ": " << buff[i] << endl;
    }
    return 0;
}


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

using namespace std;


#define M_DEBUG if(0)


int main() {
    double n = 0, d = 0;
	cin >> n >> d;
	assert(1 <= n && n <= 20);
	assert(1 <= d && d <= 20);

	// from i-d to i+d -> 一人が守れるのは 2*d+1
	// (2*d+1)*x >= n となる最小のxを求めればよいので
	// ceil(n/(2*d+1))
	M_DEBUG cout << n / (2 * d + 1) << endl;
	cout << (int)ceil(n / (2 * d + 1)) << endl;
	return 0;
}


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

int H;
int T[251];

int getparent(int u) {
	return u / 2;
}

int getleft(int u) {
	return (2 * u <= H ? 2 * u : 0);
}

int getright(int u) {
	return (2 * u + 1 <= H ? 2 * u + 1 : 0);
}

int main() {
	cin >> H;
	for (int i = 1; i <= H; i++)
		cin >> T[i];
	for (int i = 1; i <= H; i++) {
		cout << "node " << i << ": key = " << T[i] << ", ";
		if (getparent(i))
			cout << "parent key = " << T[getparent(i)] << ", ";
		if (getleft(i))
			cout << "left key = " << T[getleft(i)] << ", ";
		if (getright(i))
			cout << "right key = " << T[getright(i)] << ", ";
		cout << endl;
	}
	return 0;
}



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

int main() { 
    int N;
    cin>>N;
    double odd = 0;
    double even = 0;
    for(int i=1;i<=N;++i){
        if(i%2==0) even++;
        else odd++;
    }
    cout<<setprecision(10)<<odd/(odd+even)<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<queue>
using namespace std;
 
#define what_is(x) cout << #x << " is " << x << endl; 
#define PI acos(-1)
#define hell 1000000007
#define HELL 998244353
#define io ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define fix(n) cout << fixed << setprecision(n)
#define mset(a,n) memset(a,n,sizeof a)
#define rep(i,a,b) for (__typeof((b)) i=(a);i<(b);i++)
#define repp(i,a,b,p) for(__typeof((b)) i=(a);i<(b);i+=p)
#define ren(i,a,b) for(__typeof((a)) i=(a);i>=(b);i--)
#define renn(i,a,b,p) for(__typeof((a) i=(a);i>=(b);i-=p)
#define ADD(a,b,c) ((a)%c+(b)%c)%c
#define SUB(a,b,c) ((a)%c-(b)%c+c)%c
#define MUL(a,b,c) (((a)%c)*((b)%c))%c
#define lbd lower_bound
#define ubd upper_bound
#define ll long long
#define ld long double
#define pb push_back
#define fi first
#define se second
#define vll vector<ll>
#define pll pair<ll,ll>
#define vpll vector<pll>
#define all(v) (v).begin(), (v).end()
#define sz(x) (ll)x.size()
// #define out(n) cout<<n<<" "
#define outl(n) cout<<n<<endl
#define bug(n) {outl(n);return;}
#define pii pair<int,int>
#define lim 9223372036854775805
#define ninf -9223372036854775802
#define M 1000000007
#define eps 1e-6
#define MAX 5
#define N 500001
#define db(a) for(auto it:a) {cout<<it<<" ";}cout<<endl;
ll prime[MAX]; 
ll fact[MAX];

const long long INF64 = 1e18;
ll vpow(ll a,ll b,ll p){
    if(b==0)
        return 1;
    if(b==1)
            return a;
    ll temp=vpow(a,b/2,p);
    temp*=temp;
    temp%=p;
    if(b%2==0)
        return temp;
    temp=temp*a;
    temp%=p;
    return temp;
}

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

 
ll inverseMod(ll a,ll b,ll p){
    if(b==0)
        return 1;
    ll temp=vpow(b,p-2,p);
    ll ans=temp*a;
    ans%=p;
    return ans;
}
void sieve() 
{ 
    prime[0] = prime[1] = 1; 
    for (ll i = 2; i < MAX; i++) { 
        if (prime[i] == 0) {
            for (int j = i * 2; j < MAX; j += i) { 
                if (prime[j] == 0) { 
                    prime[j] = i; 
                } 
            } 
            prime[i] = i; 
        } 
    } 
}

void factorial(){
    fact[0]=1;
    fact[1]=1;
    rep(i,2,MAX){
        fact[i]=(fact[i-1]*i);
        // fact[i]%=M;
    }
}
// string s="689";
// // string ans="";
// // string rec(vll &power,ll lvl,ll n,ll tot){
// // 	if(tot+power[lvl]>=n){
// // 		return (string)""+s[(n-tot)/(power[lvl-1])]+rec(power,lvl-1,)
// // 	}
// // 	n%=power[lvl];

// // }
// string recc(ll n){
// 	if(n==0)
// 		return "";
// 	n--;
// 	if(n<3)
// 		return (string )""+s[n];

// 	return (string )""+s[n%3]+recc(n/3);
// }

void solve(ll ttt){
	ll d,t,s;
	cin>>d>>t>>s;
		//double time_req=d/s;
		//what_is(time_req);
	if(t*s>=d){
		cout<<"Yes"<<endl;
	}
	else
		cout<<"No"<<endl;
}

int main(){
    io;
   
    // sieve();
    // factorial();
//#ifndef ONLINE_JUDGE
    //freopen("input1.txt","r",stdin);
    //freopen("output1.txt","w",stdout);
//#endif
    ll t=1;
    //cin>>t;
    fix(12);
    rep(q,1,t+1){
        // cout<<"Case #"<<q<<": ";
         solve(q);
        //solve2();
    }
    return 0;
    
}


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

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

    int n;
    cin >> n;

    vector<int> x(n);
    REP(i, n) cin >> x[i];

    vector<int> tmp(n);
    tmp = x;
    sort(tmp.begin(), tmp.end());

    map<int, int> index;
    REP(i, n)
        index.insert(make_pair(tmp[i], i + 1));

    REP(i, n) {
        if (index[x[i]] <= n / 2) cout << tmp[n / 2] << '\n';
        if (index[x[i]] >= n / 2 + 1) cout << tmp[n / 2 - 1] << '\n';
    }
    return 0;
}


Measured memory_bytes: 12928
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<queue>
#include<deque>
#include<cmath>
#include<map>
#include<unordered_map>
#include<set>
#include<cstring>
#include<iomanip> //cout << fixed << setprecision(15) << x << endl;

using namespace std;
typedef long long ll;
const ll INF = 1e9 + 6;
const ll MOD = 1e9 + 7;
const ll LLINF = 1LL<<60;
//#define P pair<int, int>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
/* -- template -- */

int main() {
    ll N, A, B; cin >> N >> A >> B;
    ll ans = 0;
    if(B > A) swap(A, B);
    if((A - B) % 2 != 0) {
        if(A - 1 > N - B) {
            ans += N - A + 1;
            B += N - A + 1;
            A = N;
        } else {
            ans += B;
            A -= B;
            B = 1;
        }
    }
    ans += (A - B) / 2;
    cout << ans << endl;
}


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

int main ()
{
  int N,a = 0;
  cin >> N;
  int b = N;
  
  while(b > 0){
    a += b % 10;
    b = b / 10;
  }
  
  if(N % a == 0){
    cout << "Yes" << endl;
  }else{
	cout << "No" << endl;
  }
}

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

int main() {
  
  int a;
  cin >> a;
  
  if(a == 25) cout << "Christmas" << endl;
  else if(a == 24) cout << "Christmas Eve" << endl;
  else if(a == 23) cout << "Christmas Eve Eve" << endl;
  else cout << "Christmas Eve Eve Eve" << endl;
  
  
}


Measured memory_bytes: 256