akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n,m,i,a[10],w[31];
	while(cin>>n>>m,(n||m)){
		int c=0,u,r;
		while(1){
			for(w[c]=n,i=0;i<c;i++){
				if(w[i]==n){cout<<i<<' '<<w[i]<<' '<<c-i<<endl;goto L;}
			}
		for(i=0;i<m;n/=10,i++)a[i]=n%10;
		sort(a,a+m);
		for(u=r=i=0,c++;i<m;){
			u*=10;
			r*=10;
			r+=a[m-i-1];
			u+=a[i++];
		}n=r-u;}L:;
	}
}

Measured memory_bytes: 3068
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include <cstdlib>
#include <math.h>
#include<algorithm>
#include <map>
using namespace std;


int main(int argc,char** argv)
{

	int a,b;
	cin >> a >> b;
	cout << (a-1)*(b-1) <<endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string> 
#include <vector> 
#include <algorithm> 
#include <utility> 
#include <tuple> 
#include <cstdint> 
#include <cstdio> 
#include <map> 
#include <queue> 
#include <set> 
#include <stack> 
#include <deque> 
#include <unordered_map> 
#include <unordered_set> 
#include <bitset> 
#include <cctype> 
#include <math.h>
using namespace std;

#define int long long
#define endl "\n"
#define fir first
#define sec second
#define fro front
#define m_p make_pair
#define mod 1000000007
#define rep(i,n)  for(int i=0; i<(int) (n); i++)
#define all(v)  v.begin(),v.end()
#define vecin(v) for(int i=0; i<(int)v.size(); i++)cin>>v[i];
using namespace std;

const int MAX = 510000;
const int MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];
int jousu(int x00, int y00) {
	int z00 = 1;
	for (int i = 0; i < y00; i++) {
		z00 *= x00;
	}
	return z00;
}
int keta(int x00) {
	int z00 = x00;
	int w00 = 0;
	while (z00 != 0) {
		z00 /= 10;
		w00++;
	}
	return w00;
}

int modinv(int a, int m) {
	int b = m, u = 1, v = 0;
	while (b) {
		int t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
int modpow(int a, int n) {
	int res = 1;
	while (n > 0) {
		if (n & 1) res* a% mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}
int gcd(int xx, int yy) {
	int p = xx;
	int q = yy;
	if (q > p)swap(p, q);
	while (p % q != 0) {
		p %= q;
		swap(p, q);
	}
	return q;
}
int lcm(int xx, int yy) {
	return xx * yy / gcd(xx, yy);
}
bool prime(int xx) {
	int a = xx;
	for (int i = 2; i * i <= xx; i++) {
		if (xx % i == 0) {
			return 0;
		}
	}
	return 1;
}
int com(int xx, int yy) {
	int zz = 1;
	for (int i = xx; i > xx - yy; i--) {
		zz *= i;
		zz %= mod;
	}
	for (int i = 1; i <= yy; i++) {
		zz *= modinv(i, mod);
		zz %= mod;
	}
	return zz;
}



signed main() {
	int a,b,n, k,ans=0;
	cin >> n >> k;
	for (int i = k; i < n + 2; i++) {
		a = (i + 1) * i / 2%mod;
		b = (n * 2 + 3 - i) * i / 2%mod;
		ans += b - a + 1;
		ans %= mod;
	}
	if (ans < 0) {
		ans += mod;
	}
	cout << ans << endl;
}



Measured memory_bytes: 3640
#include<math.h>
#include<iostream>
#include <algorithm>
#include <string>
#include<vector>
#include <array>
#include<tuple>
#include<queue>
#include<stack>
#include<iomanip>
#include<bitset>
//AtCoderC++.cpp

using namespace std;

vector<long long> comb = vector<long long>(100 * 100,-1);

long long combination(long long n, long long r) {
	if (n == 1 || n == 0)return 1;
	if (n == r)	return 1;
	else if (r == 0)return 1;
	else if (r == 1)return n;
	else if (comb[100 * (n - 1) + (r - 1)] != -1) return comb[100 * (n - 1) + (r - 1)];
	else {
		auto res = combination(n - 1, r - 1) + combination(n - 1, r);
		comb[100 * (n - 1) + (r - 1)] = res;
		return res;
	}
}


int main() {
	string stand = "";
	string s;
	for (size_t i = 0; i < 3; i++) {
		cin >> s;
		stand += toupper(s[0]);
	}
	cout << stand << endl;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
#include<iostream>
#include<vector>
#include<math.h>
#include<iomanip>
#include<string>
#include<algorithm>
#include<numeric>
#include<utility>
#define ll long long int
#define ss string
#define endl "\n"
using namespace std;
int main()
{
 int a,b,c,d,x,y;
 cin>>a>>b>>c>>d;
 if(c%b==0)
   x=c/b;
 else
   x=c/b+1;
 if(a%d==0)
  y=a/d;
 else
  y=a/d+1;
 if(x<=y)
   cout<<"Yes";
 else
  cout<<"No";

  return 0;
}


Measured memory_bytes: 3560
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cassert>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <unordered_map>
#include <set>
#include <map>
#define INCANT cin.tie(0), cout.tie(0), ios::sync_with_stdio(0), cout << fixed << setprecision(20);
#define rep(i,n) for (int i=0; i<n;++i)
#define ALL(a)  (a).begin(),(a).end()
#define PI 3.14159265358979
typedef long long ll;
using namespace std;
const ll MOD = 1e9+7LL;
const int INF = 2e9;
int N, K;
int l[51];
int main() {
  INCANT;
  cin >> N >> K;
  rep(i, N) cin >> l[i];

  sort(l,l+N, greater<int>());
  int sm=0;
  rep(i, K) sm+=l[i];
  cout << sm << "\n";
  return 0;
}

Measured memory_bytes: 256
x = int(input())
if x >= 1800:
    print('1')
elif x >= 1600:
    print('2')
elif x >= 1400:
    print('3')
elif x >= 1200:
    print('4')
elif x >= 1000:
    print('5')
elif x >= 800:
    print('6')
elif x >= 600:
    print('7')
else:
    print('8')

Measured memory_bytes: 9132
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
using namespace std;
long long n, k; string s;
int main() {
	cin >> n >> k >> s;
	if(k >= log2(n)+2){
		char c = 'z';
		for(char i:s) c = min(c, i);
		for(int i=0;i<n;i++)cout << c; cout << endl;
	}
	else{
		string sc=s;
		reverse(sc.begin(), sc.end());
		s+=sc;
		for(int i=0;i<n+1;i++)sc = min(sc, s.substr(i,n));
		long long p=1, pk;
		for(int i=1;i<sc.size();i++)if(sc[i]==sc[0])p++;else break;
		k--;pk=p;
		for(int i=0;i<k;i++)p*=2;
		if(k==0)cout<<sc<<endl;
		else if(p>=n)for(int i=0;i<n;i++)cout << sc[0];
		else{
			for(int i=0;i<p-pk;i++){sc=sc[0]+sc;sc.pop_back();}
			cout<<sc;
		}
		cout<<endl;
	}
	return 0;
}

Measured memory_bytes: 384
n = int(input())
a_list = list(map(int, input().split()))

def gcd(a,b):
    '''
    3 個以上の値の最大公約数を求めるためには、
    res = 0 と初期化
    各 i に対して res = GCD(res, x[i]) と更新する
    '''
    while b!=0:
        a,b = b,a%b
    return a

ans = gcd(a_list[0],a_list[1])
for i in range(1,n):
    ans = gcd(ans,a_list[i])

print(ans)

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

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}

int main() {
	int x = ri();
	int n = ri();
	for (int i = 0; i < n; i++) x -= ri();
	if (x < 0) x = -1;
	printf("%d\n", x);
	return 0;
}


Measured memory_bytes: 3840
import java.io.IOException;
import java.util.Scanner;

class Main{
    private static final Scanner sc = new Scanner(System.in);
    public static void main(String[] Args) throws IOException{
        final int n = Integer.parseInt(sc.next());
        final dice d[] = new dice[n];
        for(int i = 0; i<n; i++){
            d[i] = new dice();
            for(int j = 0; j<6; j++)
                d[i].face[j] = Integer.parseInt(sc.next());
            for(int j = 0; j<i; j++){
                if(d[i].isSame(d[j])){
                    System.out.println("No");
                    return;
                }
            }
        }
        System.out.println("Yes");
    }
}

class dice{
    public int face[] = new int[6];
    private static final String dir = "EEENWWWSEEENWWWSEEENWWWS";
    public void rotate(char dir){
        int temp;
        switch(dir){
        case 'N':
            temp = face[0];
            face[0] = face[1];
            face[1] = face[5];
            face[5] = face[4];
            face[4] = temp;
            break;
        case 'E':
            temp = face[0];
            face[0] = face[3];
            face[3] = face[5];
            face[5] = face[2];
            face[2] = temp;
            break;
        case 'W':
            temp = face[0];
            face[0] = face[2];
            face[2] = face[5];
            face[5] = face[3];
            face[3] = temp;
            break;
        case 'S':
            temp = face[0];
            face[0] = face[4];
            face[4] = face[5];
            face[5] = face[1];
            face[1] = temp;
            break;
        }
    }
    public boolean equals(dice d){
        for(int i = 0; i<6; i++){
            if(face[i]!=d.face[i]) return false;
        }
        return true;
    }
    public boolean isSame(dice d){
        for(int i = 0; i<24; i++){
            if(this.equals(d)) return true;
            d.rotate(dir.charAt(i));
        }
        return false;
    }
};

Measured memory_bytes: 28760
def g;gets.split.map &:to_i;end
while(n,m=g)[0]>0
e=[c=(0..m).map{|i|([0]+[1e4]*m).rotate -i},c.map{|i|i.dup}]
n.times{a,b,*c=g;i=-1;e.map{|h|h[a][b]=h[b][a]=c[i+=1]}}
r=1..m
r.each{|k|r.each{|i|(i+1..m).each{|j|e.map{|h|h[i][j]>(z=h[i][k]+h[k][j])&&h[i][j]=h[j][i]=z}}}}
g[0].times{a,b,c=g;p e[c][a][b]}
end

Measured memory_bytes: 6492
#include<iostream>
#include<cmath>
using namespace std;
typedef long long ll;

int main()
{
    ll a,b,c,d;
    scanf("%lld %lld %lld",&a,&b,&c);
    if(a+b<c)
    {
        d=c-a-b;
        if(4*a*b<d*d)
        {
            printf("Yes\n");
        }
        else
        {
            printf("No\n");
        }
    }
    else
    {
        printf("No\n");
    }
    
    
    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb pushback
#define fr(i,n) for(int i=0;i<n;i++)
#define fro(i,j,n) for(int i=j;i<n;i++)
#define ifr(i,n) for(int i=n-1;i>=0;i--)


int main() {
    int n;
	cin >> n;
    string s[n];
    int ans=1;
  	int flag=0;
  	int size=0;
    fr(i,n){
      cin >> s[i];
   }
	sort(s,s+n);
    fr(i,n-1){
      if(s[i]!=s[i+1])ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 9852
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <random>

constexpr int N = 200'000;
long long int T[N + 1][3];
long long int divisor[3];
long long int Sum[3];

int main(void){
    int n; std::cin >> n;
    std::string S; std::cin >> S;
    int cnt = 0; for(int i = 0; i < n; ++i) if(S[i] == '1') ++cnt;
    Sum[0] = 0; Sum[1] = 0; Sum[2] = 0;
    divisor[0] = (cnt - 1 > 1) ? cnt - 1 : 1;
    divisor[1] = (cnt     > 1) ? cnt     : 1;
    divisor[2] = cnt + 1;
    for(int i = 0; i < 3; ++i) T[0][i] = 1;
    for(int i = 0; i < n; ++i) for(int p = 0; p < 3; ++p) T[i + 1][p] = T[i][p] * 2 % divisor[p];
    for(int i = 0, j = n - 1; i < n; ++i, --j) if(S[i] == '1'){
        for(int p = 0; p < 3; ++p){
            (Sum[p] += T[j][p]) %= divisor[p];
        }
    }

    for(int i = 0, j = n - 1; i < n; ++i, --j){
        if(S[i] == '1'){
            if(cnt == 1){ std::cout << "0\n"; continue; }
            long long int val = (Sum[0] - T[j][0]) % divisor[0]; if(val < 0) val += divisor[0];
            int res = 1;
            while(val){ val %= __builtin_popcount(val); ++res; }
            std::cout << res << '\n';
        }
        else{
            long long int val = (Sum[2] + T[j][2]) % divisor[2];
            if(val >= divisor[2]) val -= divisor[2];
            int res = 1;
            while(val){ val %= __builtin_popcount(val); ++res; }
            std::cout << res << '\n';
        }
    }
}

Measured memory_bytes: 8412
import java.util.HashMap;
import java.util.Scanner;
import java.util.TreeSet;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		String t = sc.next();
		
		HashMap<Character, TreeSet<Integer>> map = new HashMap<>();
		for (int i=0;i<26;i++) {
			map.put((char)('a'+i), new TreeSet<Integer>());
		}
		
		for (int i=0;i<s.length();i++) {
			map.get(s.charAt(i)).add(i);
		}
		int pos = -1;
		long num = 0;
		for (int i=0;i<t.length();i++) {
			if (map.get(t.charAt(i)).isEmpty()) {
				System.out.println(-1);
				return;
			} else {
				if (map.get(t.charAt(i)).higher(pos) != null) {
					pos = map.get(t.charAt(i)).higher(pos);
				} else {
					num++;
					pos = map.get(t.charAt(i)).first();
				}
			}
		}
		
		
		System.out.println(num*s.length()+pos+1);
	}
}




Measured memory_bytes: 34568
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

# 片方を巨大な連結成分に仕上げる

from scipy.sparse.csgraph import connected_components
from scipy.sparse import csr_matrix
import numpy as np

N,M = map(int,input().split())
A,B = np.array([input().split() for _ in range(M)], dtype=np.int32).reshape(M,2).T

graph = csr_matrix((np.ones(M),(A,B)), (N+1,N+1))

_,comp = connected_components(graph)

comp_size = np.bincount(comp[1:])

x1 = comp_size[comp[1]]
x2 = comp_size[comp[2]]
small = min(x1,x2)

answer = sum(x*(x-1)//2 for x in [small,N-small])
answer -= M
print(answer)

Measured memory_bytes: 48316
m = 998244353
S = map(int, raw_input())
N = len(S)
pr = [0]*(N*2)
pb = [0]*(N*2)
pr[0] = 2-S[0]
pb[0] = S[0]
for i in xrange(1, N):
  pr[i] = pr[i-1]+(2-S[i])
  pb[i] = pb[i-1]+S[i]
for i in xrange(N, N*2):
  pr[i] = pr[i-1]
  pb[i] = pb[i-1]
dp = []
for i in xrange(N*2+1):
  dp.append([0]*(N*2+1))
dp[0][0]=1
for i in xrange(1, N*2+1):
  si = 0
  for b in xrange(i+1):
    r = i-b
    if pr[i-1]<r or pb[i-1]<b:
      continue
    if r>0:
      dp[r][b] = (dp[r][b]+dp[r-1][b]) % m
    if b>0:
      dp[r][b] = (dp[r][b]+dp[r][b-1]) % m
    si = (si+dp[r][b]) % m
print si

Measured memory_bytes: 159004
#include <stdio.h>
int main(){
  int a,b,c,d,e,f,ans = 0;
scanf("%d",&a);
scanf("%d",&b);
scanf("%d",&c);
 
if(a>b){
  d = a;
  a = b;
  b = d;
}
 
if(c<a){
  e = c;
  c = a;
  a = e;
}
 
if(b>c){
  f = c;
  c = b;
  b = f;
}
 
ans = a + b;
 
printf("%d",ans);
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define N 55
#define SIZE 2000005
#define int long long
#define pb push_back
#define x first
#define y second
#define all(v) v.begin(),v.end()
using namespace std;
int n,m,q,a[N],b[N],c[N],d[N],ans = 0;
int ar[N];
void rec(int in, int val){
    if(in==n+1){
        int tmp = 0;
        for(int i=0;i<q;i++){
            if(ar[b[i]]-ar[a[i]]==c[i])tmp += d[i];
        }
        ans = max( ans, tmp);
        return ;
    }
    for(int j=val;j<=m;j++){
        ar[in] = val;
        rec(in+1,j);
    }
}
signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cin>>n>>m>>q;
    for(int i=0;i<q;i++)
        cin>>a[i]>>b[i]>>c[i]>>d[i];
    rec(1,1);
    cout<<ans;
    return 0;
}

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

int main(){
	string s;
  	cin >> s;
  
  	bool ok = true;
  	rep(i, s.size()){
    	if(i % 2 == 0 && s[i] == 'L') ok = false;
        if(i % 2 == 1 && s[i] == 'R') ok = false;  
    }
  
  	if(ok) cout << "Yes" << endl;
  	else cout << "No" << endl;
}

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

int main()
{
	long int n,i,ans=0,num;
	cin>>n;
	vector<int>a;
	for(i=0;i<n;i++)
	{
	    cin>>num;
	    a.push_back(num);
	}
	for(i=0;i<n;i+=2)
	{
	    if(a[i]%2!=0)
	        ans++;
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 3632
def two_int():
    N, K = map(int, input().split())
    return N,K

def one_int():
    return int(input())

def one_str():
    return input()

def many_int():
    return list(map(int, input().split()))
# import sys
# input = sys.stdin.readline

N=one_int()
S=one_str()

head = 0
tail = 0

point=0
for a in S:
    if a =="(":
        point+=1
    else:
        point -=1
    if point<0:
        head += 1
        
        #ここで先頭にカッコをつけるのでその分のポイントは差し引き０
        point += 1


print("("*head + S + abs(point)*")")

Measured memory_bytes: 3064
import sys
INF = 1 << 60
MOD = 10**9 + 7 # 998244353
sys.setrecursionlimit(2147483647)
input = lambda:sys.stdin.readline().rstrip()

class UnionFind(object):
    def __init__(self, n, recursion = False):
        self._par = list(range(n))
        self._size = [1] * n
        self._recursion = recursion

    def root(self, k):
        if self._recursion:
            if k == self._par[k]:
                return k
            self._par[k] = self.root(self._par[k])
            return self._par[k]
        else:
            root = k
            while root != self._par[root]: root = self._par[root]
            while k != root: k, self._par[k] = self._par[k], root
            return root

    def unite(self, i, j):
        i, j = self.root(i), self.root(j)
        if i == j: return False
        if self._size[i] < self._size[j]: i, j = j, i
        self._par[j] = i
        self._size[i] += self._size[j]
        return True

    def is_connected(self, i, j):
        return self.root(i) == self.root(j)

    def size(self, k):
        return self._size[self.root(k)]

def resolve():
    n, m = map(int, input().split())
    uf = UnionFind(n)
    for _ in range(m):
        u, v = map(int, input().split())
        u -= 1; v -= 1
        uf.unite(u, v)

    ans = len(set(uf.root(v) for v in range(n))) - 1
    print(ans)
resolve()

Measured memory_bytes: 81704
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repp(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define repm(i,n) for(int (i)=(n-1);(i)>=0;(i)--)
#define INF (1ll<<60)
#define all(x) (x).begin(),(x).end()
typedef long long lint;
const lint MOD =1000000007;
const lint MAX = 10000000;
using Graph =vector<vector<lint>>;

 
lint fac[MAX], finv[MAX], inv[MAX];

void COMinit() // 二項係数を求める時は前処理としてCOMinit()をする
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (lint i = 2; i < MAX; 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;
    }
}
 
// 二項係数計算
long long COM(lint n, lint k)
{
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

lint primary(lint num)
{
    if (num < 2) return 0;
    else if (num == 2) return 1;
    else if (num % 2 == 0) return 0; // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return 0;
        }
    }

    // 素数である
    return 1;
}
  lint lcm(lint a,lint b){
      return a/__gcd(a,b)*b;
  }
int main(){
lint n,a;
cin>>n>>a;
lint g=0;
if(n%a!=0)g++;
n/=a;

cout<<n+g;
 }


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

#define ll long long int
#define All(a) (a).begin(),(a).end()

// Remember v.shrink_to_fit() when erasing

void solve(){
  ll a,b,c,d,tmp;
  cin >>a>>b>>c>>d;
  tmp=max({a*c,a*d,b*c,b*d});
  cout<<tmp<<endl;



  
  // for(int i=0;i<n;i++){

  //   scanf("%d",&A[i]);
  // }

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

Measured memory_bytes: 3632
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>

#define TABLE_SIZE 22369620

class Dic{
    bool *table;
    int converter(char *str);
public:
    Dic(){table=(bool *)malloc(sizeof(bool)*TABLE_SIZE);memset(table, 0, sizeof(bool)*TABLE_SIZE);}
    void insert(char *str){table[converter(str)] = true;}
    bool find(char *str){return table[converter(str)];}
};

int Dic::converter(char *str){
    int key = 0;
    int len = strlen(str);
    for(int i=0;i<len;i++){
        switch(str[i]){
        case 'A':
            key += pow(4,i);
            break;
        case 'C':
            key += 2 * pow(4,i);
            break;
        case 'G':
            key += 3 * pow(4,i);
            break;
        case 'T':
            key += 4 * pow(4,i);
            break;
        default:
            break;
        }
    }
    return key - 1;
}

int main(){
    int i, n;
    char str[13];
    int bs = 0;
    Dic d;
    scanf("%d",&n);
    bool ans[n];
    for(i=0;i<n;i++){
        scanf("%s",str);
        if(!strcmp(str,"insert")){
            scanf("%s",str);
            d.insert(str);
        }else if(!strcmp(str,"find")){
            scanf("%s",str);
            ans[bs] = d.find(str);
            bs++;
        }
    }
    for(i=0;i<bs;i++){
        if(ans[i])printf("yes\n");
        else printf("no\n");
    }
    return 0;
}



Measured memory_bytes: 4580
package main

import (
	"fmt"
	"sort"
)

func main() {
	var n, m int
	fmt.Scan(&n, &m)
	list := make([]int, m)
	for i:=0; i<m; i++ {
		fmt.Scan(&list[i])
	}
	sort.Ints(list)
	ansl := make([]int, m-1)
	for i:=0; i<m-1; i++ {
		ansl[i] = abs(list[i+1] -list[i])
	}
	sort.Ints(ansl)
	var ans int
	for i:=0; i<len(ansl)-n+1; i++ {
		ans += ansl[i]
	}
	fmt.Println(ans)
}

func abs(n int) int {
	if n < 0 {
		return -n
	}
	return n
}

Measured memory_bytes: 5504
n = int(input())

fx = []

for _ in range(n):
    fx.append(int(input()))
    
maxv = -1000000000
minv = fx[0]
for j in range(1, n):
    maxv = max(maxv, fx[j] - minv)
    minv = min(minv, fx[j])
print(maxv)


Measured memory_bytes: 13588
# https://atcoder.jp/contests/agc003/tasks/agc003_b

enu = enumerate
ra = range
N, *A = map(int, open(0).read().split())
ans = 0


# 先に作れるのは作ったのほうが本当によいのか？←だめ
'''
反例
1...1
2...2
3...1のとき、2同士で先にペアを作る前に上と下に配ったほうがいい
'''
# 1から順にgreedyでは？反例は？なさそう
# ただしカードがないときは作れない(stockが強制的に0になる)ので注意

stock = 0  # or 1
for a in A:
    if a == 0:
        stock = 0
        continue
    a += stock
    ans += a // 2
    stock = a & 1  # %2

print(ans)


Measured memory_bytes: 14092
import sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = 10**20
def I(): return int(input())
def F(): return float(input())
def S(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LS(): return input().split()

def resolve():
    X, A, B = LI()

    if B <= A:
        print('delicious')
    elif A < B <= A + X:
        print('safe')
    else:
        print('dangerous')

if __name__ == '__main__':
    resolve()

Measured memory_bytes: 9060
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <vector>
using namespace std;
#define FOR(__I,__N) for (int __I = 0; __I < __N; ++__I)

typedef long long int64;
typedef pair<int,int> pii;
typedef pair<int64, int64> pll;
typedef double db;
typedef long double ldb;

const int INF = 0x3f3f3f3f;
const int64 INF64 = 0x3f3f3f3f3f3f3f3fLL;

const int MOD = 1000000007;


int solve(){

    int ret = 0;

    return ret;
}


char ans[100];
int main(){
    int64 N;    cin >> N;
    --N;
    if(N == 0)    puts("a");
    else{
        int t = 1;
        int64 p = 26;
        while(N >= p){
            ++t;
            N -= p;
            p *= 26;
        }
        FOR(i,t){
            ans[t-1-i] = N%26+'a';
            N /= 26;
        }
        printf("%s\n",ans);
    }
}





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

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define a first
#define b second
#define sz size()
#define pb(x) push_back(x) 
#define bg begin()
#define ed end()
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(ll i=1;i<=n;i++)
#define mp(x,y) make_pair(x,y)
const ll MOD=1000000007;

ll maxx(ll x,ll y,ll z){
	return max(max(x,y),z);
}
ll minn(ll x,ll y,ll z){
	return min(min(x,y),z);
}
ll gcd(ll x,ll y){
	if(x%y==0) return y;
    else return gcd(y,x%y);
}
ll lcm(ll x,ll y){
	return x*(y/gcd(x,y));
}

//a,b x
int main(){
	ll H,W; cin>>H>>W;
	char s[101][101];
	rep(i,H){
		string tmp; cin>>tmp;
		rep(j,W){
			s[i][j]=tmp[j];
		}
	}
	vector<bool> row(H,true);
	ll cnt=0; 
	rep(i,H){
		rep(j,W){
			if(s[i][j]=='.') cnt++;
		}
		if(cnt==W) row[i]=false;
		cnt=0;
	}
	vector<bool> col(W,true);
	rep(i,W){
		rep(j,H){
			if(s[j][i]=='.') cnt++;
		}
		if(cnt==H) col[i]=false;
		cnt=0;
	}
	for(int i=0;i<H;i++){
		for(int j=0;j<W;j++){
			if(row[i] && col[j]) cout<<s[i][j];
		}
		if(row[i]) cout<<endl;
	}
}

Measured memory_bytes: 256
<?php

class In {

	private $buf = [];
	private $count = 0;
	private $pointer = 0;

	public function nextLine() {
		$ret = '';
		if($this->hasNext()){
			while($this->hasNext()){
				$ret .= $this->next();
			}
		}else{
			$ret = trim(fgets(STDIN));
		}

		return $ret;
	}

	public function next() {
		if(!$this->hasNext()) {
			$str = trim(fgets(STDIN));
			$this->buf = explode(' ',$str);
			$this->count = count($this->buf);
			$this->pointer = 0;
		}

		return $this->buf[$this->pointer++];
	}

	public function hasNext() {
		return $this->pointer < $this->count;
	}

	public function nextInt() {
		return (int)$this->next();
	}

	public function nextDouble() {
		return (double)$this->next();
	}
}

class Out {
	public function println($str = '') {
		echo $str . PHP_EOL;
	}
}

$in = new In();
$out = new Out();

$N = $in->nextInt();
$a = [];
$used = [];
for ($i = 0;$i < $N;$i++) {
	$a[] = $in->nextInt()-1;
	$used[] = false;
}

$cur = 0;
$cnt = 0;
while($used[$cur] === false) {
	$used[$cur] = true;

	if ($cur === 1) {
		$out->println($cnt);
		return;
	}
	$cur = $a[$cur];
	$cnt++;
}

$out->println('-1');

?>


Measured memory_bytes: 14840
import java.util.*; import java.io.*; import java.math.*;
public class Main{
	//Don't have to see. start------------------------------------------
	static class InputIterator{
		ArrayList<String> inputLine = new ArrayList<String>(1024);
		int index = 0; int max; String read;
		InputIterator(){
			BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
			try{
				while((read = br.readLine()) != null){
					inputLine.add(read);
				}
			}catch(IOException e){}
			max = inputLine.size();
		}
		boolean hasNext(){return (index < max);}
		String next(){
			if(hasNext()){
				return inputLine.get(index++);
			}else{
				throw new IndexOutOfBoundsException("There is no more input");
			}
		}
	}
	static HashMap<Integer, String> CONVSTR = new HashMap<Integer, String>();
	static InputIterator ii = new InputIterator();//This class cannot be used in reactive problem.
	static PrintWriter out = new PrintWriter(System.out);
	static void flush(){out.flush();}
	static void myout(Object t){out.println(t);}
	static void myerr(Object t){System.err.print("debug:");System.err.println(t);}
	static String next(){return ii.next();}
	static boolean hasNext(){return ii.hasNext();}
	static int nextInt(){return Integer.parseInt(next());}
	static long nextLong(){return Long.parseLong(next());}
	static double nextDouble(){return Double.parseDouble(next());}
	static ArrayList<String> nextStrArray(){return myconv(next(), 8);}
	static ArrayList<String> nextCharArray(){return myconv(next(), 0);}
	static ArrayList<Integer> nextIntArray(){
		ArrayList<String> input = nextStrArray(); ArrayList<Integer> ret = new ArrayList<Integer>(input.size());
		for(int i = 0; i < input.size(); i++){
			ret.add(Integer.parseInt(input.get(i)));
		}
		return ret;
	}
	static ArrayList<Long> nextLongArray(){
		ArrayList<String> input = nextStrArray(); ArrayList<Long> ret = new ArrayList<Long>(input.size());
		for(int i = 0; i < input.size(); i++){
			ret.add(Long.parseLong(input.get(i)));
		}
		return ret;
	}
	static String myconv(Object list, int no){//only join
		String joinString = CONVSTR.get(no);
		if(list instanceof String[]){
			return String.join(joinString, (String[])list);
		}else if(list instanceof ArrayList){
			return String.join(joinString, (ArrayList)list);
		}else{
			throw new ClassCastException("Don't join");
		}
	}
	static ArrayList<String> myconv(String str, int no){//only split
		String splitString = CONVSTR.get(no);
		return new ArrayList<String>(Arrays.asList(str.split(splitString)));
	}
	public static void main(String[] args){
		CONVSTR.put(8, " "); CONVSTR.put(9, "\n"); CONVSTR.put(0, "");
		solve();flush();
	}
	//Don't have to see. end------------------------------------------
	static void solve(){//Here is the main function
		ArrayList<Integer> one = nextIntArray();
		int A = one.get(0);
		int B = one.get(1);
		int C = one.get(2);
		if(B - A == C - B){
			myout("YES");
		}else{
			myout("NO");
		}
	}
	//Method addition frame start



	//Method addition frame end
}


Measured memory_bytes: 25404
import java.util.LinkedHashSet;
import java.util.Scanner;
import java.util.Set;
import java.util.Stack;

public class Main {

  private static int position = -1;

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

    final int N = scanner.nextInt();
    final long K = scanner.nextLong();
    final int[] A = new int[N + 1];
    for (int i = 1; i <= N; i++) {
      A[i] = scanner.nextInt();
    }

    if (A[1] == 1) {
      System.out.println(1);
      return;
    }

    // 閉路を見つける
    final boolean[] seen = new boolean[N + 1];
    final boolean[] finished = new boolean[N + 1];
    final Stack<Integer> history = new Stack<>();
    position = -1;
    dfs(A, 1, 0, seen, finished, history);

    // 閉路を復元
    final Set<Integer> cycle = new LinkedHashSet<>();
    while (!history.empty()) {
      final int t = history.pop();
      cycle.add(t);
      if (t == position) {
        break;
      }
    }

    if (cycle.contains(1)) {
      final long q = K % cycle.size();
      int ans = 1;
      for (long i = 0; i < q; i++) {
        ans = A[ans];
      }
      System.out.println(ans);
    } else {
      int ans = 1;
      long cnt = 0;

      while (!cycle.contains(ans) && cnt < K) {
        ans = A[ans];
        cnt++;
      }

      if (cnt == K) {
        System.out.println(ans);
        return;
      }

      final long q = (K - cnt) % cycle.size();
      for (long i = 0; i < q; i++) {
        ans = A[ans];
      }

      System.out.println(ans);
    }
  }

  private static void dfs(final int[] A, final int v, final int previousV,
      final boolean[] seen, final boolean[] finished, final Stack<Integer> history) {

    seen[v] = true;
    history.push(v);

    final int nextV = A[v];

    if (v == previousV) {
      return;
    }

    // 完全終了した頂点はスルー
    if (finished[nextV]) {
      return;
    }

    // サイクルを検出
    if (seen[nextV] && !finished[nextV]) {
      position = nextV;
      return;
    }

    // 再帰的に探索
    dfs(A, nextV, v, seen, finished, history);

    // サイクル検出したならば真っ直ぐに抜けていく
    if (position != -1) {
      return;
    }

    history.pop();
    finished[v] = true;
  }
}


Measured memory_bytes: 927260
#include <bits/stdc++.h>
using namespace std;
#define Rep(i,n) for(int i=0;i<(int)(n);i++)
#define For(i,n1,n2) for(int i=(int)(n1);i<(int)(n2);i++)
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define RREP(i,n) for(ll i=((ll)(n)-1);i>=0;i--)
#define FOR(i,n1,n2) for(ll i=(ll)(n1);i<(ll)(n2);i++)
#define RFOR(i,n1,n2) for(ll i=((ll)(n1)-1);i>=(ll)(n2);i--)
#define all(a)  (a).begin(),(a).end()
#define SORT(a) sort((a).begin(),(a).end())
#define oorret 0
#define oor(x) [&](){try{x;} catch(const out_of_range& oor){return oorret;} return x;}()
#define IOS cin.tie(0),ios::sync_with_stdio(false)
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
template<typename T1, typename T2> inline bool chmin(T1& a, T2 b) { if (a > b) { a = b; return 1; }return 0; }
template<typename T1, typename T2> inline bool chmax(T1& a, T2 b) { if (a < b) { a = b; return 1; }return 0; }
template<class Type>struct is_vector : std::false_type {};
template<class ValueType, class Alloc>struct is_vector<std::vector<ValueType, Alloc>> : std::true_type {};
template <typename T> inline ostream& operator << (ostream& out, const vector<T>& v) {
	if (v.empty())return out;
	constexpr bool is_vector_v = is_vector<T>::value;
	if (is_vector_v)for (auto itr = v.begin(); itr != v.end();)out << (*itr), out << ((++itr != v.end()) ? "\n" : "");
	else for (auto itr = v.begin(); itr != v.end();)out << (*itr), out << ((++itr != v.end()) ? " " : "");
	return out;
}
inline void put() {}
template<class T> inline void put(const T& first) { std::cout << first << "\n"; }
template<class T, class... N> inline void put(const T& first, const N& ... rest) { std::cout << first << " "; put(rest...); }
inline void putn() {}
template<class T, class... N> inline void putn(const T& first, const N& ... rest) { std::cout << first << "\n"; putn(rest...); }

template<typename T, typename U>
T gcd(T u, U v) {
	if (u == 0)return v;
	if (v == 0)return u;
	T r;
	while (v) {
		r = u % v;
		u = v;
		v = r;
	}
	return u;
}

int main() {
	IOS;
	int t;
	cin >> t;
	vector<bool> res(t);
	REP(i, t) {
		ll a, b, c, d;
		cin >> a >> b >> c >> d;
		if (a - b < 0 || d < b) {
			res[i] = false;
			continue;
		}
		if (b == d) {
			if (a - b <= c) {
				res[i] = true;
			} else {
				if ((a - c - 1) % b + c + 1 < b) {
					res[i] = false;
				} else {
					res[i] = true;
				}
			}
			continue;
		}
		if (a > c && (a - c - 1) % b + c + 1 < b) {
			res[i] = false;
			continue;
		}
		ll temp = a - b;
		if (a - b > c) {
			temp = (a - c - 1) % b + c + 1 - b;
		}
		ll g = gcd(b, d);
		ll h = (c + 1 - temp + g - 1) / g;
		h = temp + h * g;
		if (h < b) {
			res[i] = false;
		}else{
			res[i] = true;
		}
	}
	REP(i, t) {
		if (res[i]) {
			put("Yes");
		} else {
			put("No");
		}
 	}
	return 0;
}


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


def main():
	Ls = []
	Rs = []
	for i in range(M):
		inputs = list(map(int,input().split()))
		Ls.append(inputs[0])
		Rs.append(inputs[1])

	maxL = max(Ls)
	minR = min(Rs)

	if maxL > minR:
		print(0)
	else:
		print(minR - maxL + 1)

if __name__ == '__main__':
	main()

Measured memory_bytes: 11232
#include <iostream>


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

int gcd(int a, int b, int c) {
    int r{};
    if (a > b) r = gcd(a, b);
    else r = gcd(b, a);
    
    if (c > r) return gcd(c, r);
    else return gcd(r, c);
}

int main() {
    int k{};
    std::cin >> k;
    int result{0};
    for (int h=1; h <= k; ++h)
    for (int i=1; i <= k; ++i)
    for (int j=1; j <= k; ++j) 
        result += gcd(h, i, j);
    
    std::cout<< result << std::endl;
}



Measured memory_bytes: 3164
#include<bits/stdc++.h>
// using namespace std;
typedef long long ll;
const int mod=998244353;
const int N=1e5+5;//,M=2e5+5;
ll n;
int main()
{
    // ios::sync_with_stdio(false);std::cin.tie(0);cout.tie(0);
    // freopen("a.in","r",stdin);
    // while(~scanf("%d",&n)){
    if(true){
    // int T;scanf("%d",&T);for(int tttt=1;tttt<=T;tttt++){
    scanf("%lld",&n);
    ll a=7,ans=1;
    if(n%2==0||n%5==0){
        puts("-1");
        return 0;
    }
    while(a%n){
        ans++;
        a=a*10+7;
        a%=n;
    }
    printf("%lld\n",ans);
    }return 0;
}


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

using namespace std;
using ll=long long;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, a, n) for(int i = (n); i < (a); i++)

int main(){
  cin.tie(nullptr);ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  int n,k;cin>>n>>k;
  int h[n];rep(i,n)cin>>h[i];
  sort(h,h+n);
  int ans=1e9,minh,maxh;
  rep(i,n-k+1){
    minh=h[i];
    maxh=h[i+k-1];
    ans=min(ans,maxh-minh);
    //cout<<ans<<" "<<minh<<" "<<maxh<<endl;
  }
  cout<<ans<<endl;
}


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

typedef long long ll;

int main()
{
    #ifndef ONLINE_JUDGE
            // for getting input from input.txt
            freopen("input.txt", "r", stdin);
            // for writing output to output.txt
            freopen("output.txt", "w", stdout);
    #endif

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    ll n;
    cin>>n;
    double x = 2*(3.14159265358)*n;
    cout<<x<<endl;
    
    return 0;
}

Measured memory_bytes: 3804
#include <iostream>
#include <queue>

using namespace std;

int main(){
    int N, M;
    cin >> N >> M;
    
    vector< vector<int> > jobs(M);
    for(int i = 0; i < N; i++){
        int a, b;
        cin >> a >> b;
        if(a > M){
            continue;
        }else{
            jobs[M-a].push_back(b);
        }
    }

    priority_queue<int> q;
    long long ans = 0;
    for(int i = M-1; i >= 0; i--){
        for(int b : jobs[i]){
            q.push(b);
        }

        if(!q.empty()){
            ans += q.top();
            q.pop();
        }
    }

    cout << ans << endl;


    return 0;
}

Measured memory_bytes: 5504
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#define debug(x) cerr << #x << " = " << x << endl;


#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 110


int main(){
  int n,d,p;
  priority_queue<int> pq;
  
  scanf("%d%d",&n,&d);
  for(int i=0;i<n;i++){
    scanf("%d",&p);
    pq.push(p);
  }

  int ans = 0;
  
  while(pq.size()){
    int q = pq.top();
    pq.pop();

    if(q > d){
      ans += q - d;
    }else{
      break;
    }
  }

  if(ans==0)
    puts("kusoge");
  else
    printf("%d\n",ans);
  
  return 0;
}

Measured memory_bytes: 3292
#include <iostream>
#include <cstring>
#include <string>
using namespace std;
int main(){

        string s;
        int x;
        cin>>s;
        if(s=="SUN"){
            x=7;
        }
        else if(s=="MON"){
            x=6;
        }
        else if(s=="TUE"){
            x=5;
        }
        else if(s=="WED"){
            x=4;
        }
        else if(s=="THU"){
            x=3;
        }
        else if(s=="FRI"){
            x=2;
        }
        else{
            x=1;
        }
     cout<<x;
        return 0;
}

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

public class Main {

	final static long MOD = 1000000007;
	public static String[] Ws = null;
	public static int wsIndx = 0;
	public static BufferedReader in = null;
	public static long cnt=0;
	public static PrintWriter pw = new PrintWriter(System.out);
	public static void main(String[] args) throws Exception {
		solution(args);
		if(in!=null){
			in.close();
		}
		pw.flush();
		pw.close();
	}

	public static void solution(String[] args) throws Exception{
		int K = nextInt();
		int T = nextInt();
		int[] a = nextInts();
		Arrays.sort(a);
		long ans=0;
		int target=T-1;
		int idx=T-2;
		while(idx>=0){
			if(a[target]-a[idx]<=0){
				a[idx]=a[idx]-a[target];
				a[target]=0;
				target=idx;
				idx--;
			}else{
				a[target]=a[target]-a[idx];
				a[idx]=0;
				idx--;
			}
		}
		System.out.println(a[target]==0?a[target]:a[target]-1);
	}

	public static void dfs(int n,int cnt,ArrayList<Integer>[] tree,int parent,int[] set){
		if(n!=parent&&tree[n].size()==1){
			set[n]=cnt;
			return;
		}
		for(int x:tree[n]){
			if(x==parent){
				continue;
			}
			dfs(x,cnt+1,tree,n,set);
		}
	}


	public static void check() throws Exception{
		if(in == null){
			in = new BufferedReader(new InputStreamReader(System.in));
		}
		if(Ws==null || Ws.length<=wsIndx){
			Ws = in.readLine().split(" ");
			wsIndx=0;
		}
	}
	public static int nextInt()throws Exception{
		check();
		return Integer.parseInt(Ws[wsIndx++]);
	}

	public static long nextLong()throws Exception{
		check();
		return Long.parseLong(Ws[wsIndx++]);
	}

	public static String nextString()throws Exception{
		check();
		return Ws[wsIndx++];
	}

	public static int[] nextInts()throws Exception{
		check();
		int[] tmp = new int[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Integer.parseInt(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static long[] nextLongs()throws Exception{
		check();
		long[] tmp = new long[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Long.parseLong(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static String[] nextStrings()throws Exception{
		check();
		wsIndx=Ws.length;
		return Ws;
	}

}



Measured memory_bytes: 21588
def d_equals(N, M, P, S):
    class UnionFind(object):
        def __init__(self, N):
            self.p = list(range(N))  # 初期状態ではi番の頂点の親(parent)はi番
            self.rank = [0] * N  # 初期状態では全頂点がランク0(何もつながってない)
            self.size = [1] * N  # 初期状態ではどの頂点も連結成分の大きさは1

        def find(self, x):  # 頂点xが属する連結成分の代表(根の番号)を求める
            if self.p[x] != x:  # 頂点xの代表は他の頂点だった
                self.p[x] = self.find(self.p[x])  # 経路圧縮(xを代表につなぐ)
            return self.p[x]

        def is_same(self, x, y):  # 頂点x,yは同じ連結成分に属するか？
            return self.find(x) == self.find(y)

        def union(self, x, y):  # x,yを同じ連結成分に属させる
            u = self.find(x)
            v = self.find(y)
            if u == v:  # x,yは既に同じ連結成分に属していた
                return
            if self.rank[u] < self.rank[v]:
                self.p[u] = v  # ランクの大きな方につなげる
                self.size[v] += self.size[u]  # つながっている要素数だけ足す
                self.size[u] = 0  # ランクが小さかった連結成分は「解散」
            else:
                # 上と同様にやる
                self.p[v] = u
                self.size[u] += self.size[v]
                self.size[v] = 0
                if self.rank[u] == self.rank[v]:
                    # 根の分だけ1個「ずれる」
                    self.rank[u] += 1

        def get_size(self, x):  # 頂点xが属する連結成分の大きさ
            return self.size[self.find(x)]

        def show(self):
            return self.p

    ans = 0
    uf = UnionFind(N)
    for a, b in S:
        uf.union(a - 1, b - 1)  # Pのa番とb番は繋がっている(0-indexed)
    for i in range(N):
        if uf.is_same(P[i] - 1, i):
            # 2つが同じ連結成分にあるなら、何回かswapしてp_i=iにできる
            ans += 1
    return ans

N,M = [int(i) for i in input().split()]
P = [int(i) for i in input().split()]
S = [[int(i) for i in input().split()] for j in range(M)]
print(d_equals(N, M, P, S))

Measured memory_bytes: 30668
import numpy as np

n = int(input())
x = [tuple(map(int, input().split())) for _ in range(n)]

def circle(x, y, z):

    ra = np.array(x)
    rb = np.array(y)
    rc = np.array(z)

    A = np.dot(rb-rc,rb-rc)
    B = np.dot(rc-ra,rc-ra)
    C = np.dot(ra-rb,ra-rb)

    T = A*(B+C-A)
    U = B*(C+A-B)
    W = C*(A+B-C)

    rcc = (T*ra + U*rb + W*rc)/(T + U + W)

    return rcc

def dis(a, b, c, d):
    return (a - b)**2 + (c - d)**2

e = 10 ** (-9)
ans = 10 ** 18
for i in range(n):
    for j in range(i+1, n):
        a = x[i]
        b = x[j]
        px, py = (a[0]+b[0])/2, (a[1]+b[1])/2
        r = dis(px, a[0], py, a[1])
        ok = True
        for s, t in x:
            if dis(px, s, py, t) > r + e:
                ok = False
                break
        if ok:
            ans = min(ans, r)

if ans != 10 ** 18:
    print(ans ** (1/2))
    exit()

for i in range(n):
    for j in range(i+1, n):
        for k in range(j+1, n):
            a = x[i]
            b = x[j]
            c = x[k]
            px, py = circle(a, b, c)
            r = dis(px, a[0], py, a[1])
            ok = True
            for s, t in x:
                if dis(px, s, py, t) > r + e:
                    ok = False
                    break
            if ok:
                ans = min(ans, r)

print(ans ** (1/2))

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

using namespace std;
using ll =long long;

#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cerr << #x << " = " << (x) << endl;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
void coY() {cout <<"Yes"<<endl;}
void coN(){cout <<"No"<<endl;}

const ll INF = 1LL << 60;

//Write From this Line

const int mod = 1e9+7;
int main()
{
	ll a, b ,k ;
	cin>> a>> b >>k ;
	int count = 0 ;
	ll div = min(a,k);
	k -= div ;
	a -= div;
	if(k > 0 ){
		b -= min(b,k);
	}
	cout << a << " " << b << endl;


}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(obj) (obj).begin(), (obj).end()
#define bit(n) (1LL << (n))
 
typedef long long ll;

using namespace std;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int d;
  cin>>d;
  
  if(d==25){
    cout<<"Christmas";
  }else if(d==24){
    cout<<"Christmas Eve";
  }else if(d==23){
    cout<<"Christmas Eve Eve";
  }else if(d==22){
    cout<<"Christmas Eve Eve Eve";
  }
    
  return 0;
}

Measured memory_bytes: 256
let x, y = Scanf.scanf " %d %d" @@ fun a b -> a, b
let _ = Printf.printf "%d\n" @@ List.fold_left (fun p r -> p + match r with 1 -> 300000 | 2 -> 200000 | 3 -> 100000 | _ -> 0) 0 [x; y] + if x = 1 && y = 1 then 400000 else 0

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
int n,a[200010],b[200010];
bool check(int now)
{
	for (int i=1;i<=2*n-1;i++)
	  if (a[i]>=now) b[i]=1;else b[i]=0;
	int m=(2*n-1)/2+1;
	int k=-1,Min=1e9;
	for (int i=1;i<=2*n-1;i++)
	  if (i!=1&&b[i]==b[i-1]&&min(abs(i-m)+1,abs(i-1-m)+1)<Min) 
	    Min=min(abs(i-m)+1,abs(i-1-m)+1),k=b[i];
	if (k==-1)
	{
		if (n&1) return b[m];
		else return !b[m];
    }
    return k;
}
int main()
{
	scanf("%d",&n);
	for (int i=1;i<=2*n-1;i++)
	  scanf("%d",&a[i]);
	int l=1,r=2e5;
	while (l+1<r)
	{
		int mid=(l+r)>>1;
		if (check(mid)) l=mid;
		else r=mid-1;
    }
    if (check(r)) printf("%d\n",r);else printf("%d\n",l);
    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define LLINF 9223372036854775807
#define MOD ll(1e9+7)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cerr<<#x<<": "<<x<<endl

const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};

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

    mint total(2);
    total = total.pow(n);
    total -= 1; total + mod;

    mint v1a(1), v1b(1);
    mint v2a(1), v2b(1);
    for(int i = 0; i < a; i++){
        v1a *= (n-i);
        v1b *= (i+1);
    }
    for(int i = 0; i < b; i++){
        v2a *= (n-i);
        v2b *= (i+1);
    }

    cout << (total.x + 2*mod - (v1a*v1b.inv()).x - (v2a*v2b.inv()).x)%mod << endl;


    return 0;

}


Measured memory_bytes: 256
INF = 10**18

N,M = map(int,input().split())
edge = [list(map(int,input().split())) for _ in range(M)]
graph = [[INF for j in range(N)] for i in range(N)]

for i in range(N):
    graph[i][i] = 0

for e in edge:
    graph[e[0]-1][e[1]-1] = e[2]
    graph[e[1]-1][e[0]-1] = e[2]
    
for k in range(N):
    for i in range(N):
        for j in range(N):
            if graph[i][k] != INF and graph[k][j] != INF:
                graph[i][j] = min(graph[i][j],graph[i][k]+graph[k][j])

ans = 0

for e in edge:
    if graph[e[0]-1][e[1]-1] != e[2]:
        ans += 1
        
print(ans)

Measured memory_bytes: 43372
#include<bits/stdc++.h>
using namespace std;
int main(){
  stack<int> t;
  string s;cin>>s;
  int i;
  for(i=0;i<s.size();i++){
    if(s[i]=='B'){
      if(!t.empty()) t.pop();
    }else t.push(s[i]-'0');
  }
  vector<int> v;
  while(!t.empty()) i=t.top(),t.pop(),v.push_back(i);
  reverse(v.begin(),v.end());
  for(i=0;i<v.size();i++) cout << v[i];
  cout << endl;
  return 0;
}


Measured memory_bytes: 384