akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (ll i=0;i<(n);i++)
#define REP(i,n) for (ll i=1;i<=(n);i++)
typedef long long ll;

ll inf = 1000000007;

ll mpow(ll a,ll n){
    if(n==0) return 1;
    if(n%2==0){
        ll t = mpow(a,n/2);
        return t*t%inf;
    }
    return a * mpow(a,n-1) % inf;
}

ll combi(ll n, ll r){
    ll ans = 1;
    rep(i,r){
        ans*=(n-i);
        ans%=inf;
    }
    REP(i,r){
        ans*=mpow(i,inf-2);
        ans%=inf;
    }
    return ans;
}


int main() {
    ll n,a,b;
    cin >> n >> a >> b;
    ll ans = mpow(2,n) - 1;
    ans -= combi(n,a);
    if(ans<0) ans+=inf;
    ans -= combi(n,b);
    if(ans<0) ans+=inf;
    cout << ans << endl;
}

Measured memory_bytes: 3588
#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 dp[1001][1001];
int main() {
  int q;
  cin >> q;
  rep(qq, q) {
    string x, y;
    cin >> x >> y;
    int len_x = x.size();
    int len_y = y.size();
    rep(i, len_x) rep(j, len_y) {
      if (x[i] == y[j])
        dp[i + 1][j + 1] = dp[i][j] + 1;
      else
        dp[i + 1][j + 1] = max(dp[i + 1][j], dp[i][j + 1]);
    }
    cout << dp[len_x][len_y] << endl;
  }
  return 0;
}


Measured memory_bytes: 7092
N = int ( input() )
slimes = str( input() )
list_slimes = list( slimes )
while(True):
  counter = 0
  i = 0
  while(i<len(list_slimes)-1):
    if list_slimes[i] == list_slimes[i+1]:
      del list_slimes[i]
      counter += 1
    i += 1
  if counter == 0:
    break

print( len (list_slimes) )

Measured memory_bytes: 4084
import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		long mod = (long) (Math.pow(10, 9)+7);
		int N = sc.nextInt(), K = sc.nextInt();
		int[] NList = new int[N+1];
		for(int i=0;i<N+1;i++) {
			NList[i]=i;
		}
		long[] ruisekiwa = new long[N+1];
		for(int i = 1;i<N+1;i++) {
			ruisekiwa[i]= ruisekiwa[i-1]+NList[i];
		}
		long wa = ruisekiwa[N];
		long ans = 0;
		for(int i= K;i<N+1;i++) {
//			System.out.println(i);
			long min = ruisekiwa[i-1];
			long max = wa-ruisekiwa[N-i];
//			System.out.println(max);
//			System.out.println(min);
			ans += max-min+1;
			ans %= mod;
		}
		System.out.println(ans+1);
	}

}

Measured memory_bytes: 38748
#include <iostream>
#include <cstring>
#include <cstdio>

#define N_MAX 100001

using namespace std;


int main(void){
    char str[N_MAX];
    int N;
    
    scanf("%s",str);
    N = strlen(str);
    
    for(int i = 0 ; i < N - 1 ; i++ ){
        char c1 = str[i];
        char c2 = str[i+1];
        
        if( c1 == c2 ){
            cout << i+1 << " " << i+2 << endl;
            return 0;
        }
    }
    
    for(int i = 0 ; i < N - 2 ; i++ ){
        char c1 = str[i];
        char c2 = str[i+1];
        char c3 = str[i+2];
        
        if( c1 == c2 || c1 == c3 || c2 == c3 ){
            cout << i+1 << " " << i+3 << endl;
            return 0;
        }
    }
    
    cout << "-1 -1" << endl;
    
    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define repi(i, a, b) for (int i = (int)(a) ; i < (int)(b) ; i++)
#define rep(i, n) repi(i, 0, n)
#define SZ(x) ((int)(x).size())
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
// using P = pair<int, int>;
struct Vec{
    double x, y;
};
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;
}
using namespace std;
int main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    // cout << fixed << setprecision(15);
    string s, t;
    cin >> s >> t;
    int sl, tl, cnt, ans = -1;
    sl = s.length();
    tl = t.length();
    rep(i, sl - tl + 1) {
        cnt = 0;
        rep(l, tl) {
            if (s[i + l] == t[l]) cnt++;
        }
        ans = max(ans, cnt);
    }
    cout << tl - ans << endl;
    return 0;
}

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

#define rep(i,a,n) for(int i=a;i<n;++i)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
const int N=2e5+5;
const int inf=2e9;
#define ll long long
map<int,int>p;

int main(){
    ios::sync_with_stdio(0);
    int a,n,ans=0;
    cin>>n;
    rep(i,0,n){
        cin>>a;
        if(p[a]==1) {
            p[a]=0;
            --ans;
        }
        else{
            p[a]=1;
            ++ans;
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 4992
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0;i < n;i++)
#define REP(i,n,k) for(int i = n;i < k;i++)
#define P(p) cout << (p) << endl;
#define sP(p) cout << setprecision(15) << fixed << p << endl;
#define vi vector<int>
#define printv(v) for(int i = 0;i < v.size();i++)P(v[i]);
#define printt(a,b) cout << a << " " << b << endl; 
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
int dx[] = { 1, -1 , 0 , 0};
int dy[] = { 0,  0,  1, -1};
int MOD = 1e9 + 7;

void solve() {
    int a,b,c;
    cin >> a >> b >> c;
    P(a+b >= c ? "Yes" : "No");
}

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


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

int n,m;
ll num[100005],ans=0;
struct AC{
	int a;
	ll c;
}x[100005];

bool cmp(AC p,AC q){
	return p.c>q.c;
}

int main(void){
	scanf("%d %d",&n,&m);
	for(int i=1;i<=n;i++)
	scanf("%lld",&num[i]),ans+=num[i];
	for(int i=1;i<=m;i++)
	scanf("%d %lld",&x[i].a,&x[i].c);
	sort(x+1,x+1+m,cmp);
	int now=1,ss=1;
	for(int i=2;i<=m;i++){
		if(x[i].c==x[i-1].c)
		x[now].a+=x[i].a,x[i].c=0;
		else
		now=i,ss++;
	}
	sort(x+1,x+1+m,cmp);
	m=ss;
	now=0;
	int i=1;
	sort(num+1,num+1+n);
	while(now<=n){ 
		bool tmp=0;
		for(int j=1;j<=x[i].a;j++)
		if(num[++now]<=x[i].c){
			ans=ans-num[now]+x[i].c;
			if(now==n){
				tmp=1;
				break;
			}
		}
		else{
			tmp=1;
			break;
		}
		i++;
		if(tmp==1)break;
	}
	printf("%lld",ans);
}

Measured memory_bytes: 2560
#include <iostream>
using namespace std;
int main(){
    int N, A;
    cin >> N;
    bool ans = false;
    for(int i=1;i<50000;i++){
        int a = (double) i*1.08;
        if( a == N) {ans = true;A = i;break;}
    }
    if(ans) cout <<A << endl;
    else cout << ":(" << endl;
}

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

int main()
{
    string S, T;
    cin >> S >> T;
    for (int i = 0; i < S.size(); i++)
    {
        bool flag = true;
        for (int j = 0; j < T.size(); j++)
        {
            if (S[j] != T[(i+j)%T.size()]) flag = false;
        }
        if (flag)
        {
            cout << "Yes" << endl; return 0;
        }
    }
    cout << "No" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;
template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}
int main() {
  cin.tie(0);
  cout << fixed << setprecision(10);
  int n, m; cin >> n >> m;
  vector<int> a(n), b(n);
  for(int i=0;i<n;++i) {
    cin >> a[i] >> b[i];
  }
  map<int, priority_queue<int>> mp;
  for(int i=0;i<n;++i) {
    mp[a[i]].push(b[i]);
  }
  priority_queue<P> pq;
  int ans = 0;
  for(int i=1;i<=m;++i) {
    if(!mp[i].empty()) {
      pq.push({mp[i].top(), i});
      mp[i].pop();
    }
    if(pq.empty()) continue;
    int now = pq.top().first, argnow = pq.top().second;
    pq.pop();
    ans += now;
    if(!mp[argnow].empty()) {
      pq.push({mp[argnow].top(), argnow});
      mp[argnow].pop();
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 11648
#include <bits/stdc++.h>
using namespace std;
#define pi pair<int,int>
#define ff first
#define ss second
#define boost ios::sync_with_stdio(false);cin.tie(nullptr)
#define int long long
#include "string"

int32_t main(){
	boost;
	int n;
	cin>>n;
	int a[n];
	map<int,int>mp;
	int sum = 0;
	for(int i=0;i<n;i++){
		cin>>a[i];
		sum += a[i];
		mp[a[i]]++;
	}

	int q;
	cin>>q;
	while(q--){
		int l,r;
		cin>>l>>r;
		sum += mp[l]*(r - l);
		mp[r] += mp[l];
		mp[l] = 0;
		cout<<sum<<endl;
	}				
}

Measured memory_bytes: 10172
s=input()
n=len(s)
if n%2!=0:
  print("No")
else:
  flag=True
  for i in range(0,n,2):
    if s[i]=='h' and s[i+1]=='i':
      continue
    else:
      flag=False
      break
  print("Yes") if flag else print("No")


Measured memory_bytes: 2940
#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>;
void chmax(int &a, int b) { a = max(a,b); }

int dp[2005][2005];

int main() {
	// input 
	int n;
	cin >> n;
	int n3 = 3*n;
	vector<int> A(n3);
	rep(i,n3) {cin >> A[i];--A[i];}
	// init
	int m = n + 1;
	rep(i,m) rep(j,m) dp[i][j] = -1e9;
	// init dp
	auto upd = [&](int i, int j, int x) {
		chmax(dp[i][j],x);
		chmax(dp[j][i],x);
		chmax(dp[i][n],x);
		chmax(dp[n][i],x);
		chmax(dp[n][j],x);
		chmax(dp[j][n],x);
		chmax(dp[n][n],x);
	};
	upd(A[0],A[1],0);

	int base = 0;
	for (int ai=2;ai < n3-1;ai+=3) {
		int x=A[ai],y=A[ai+1],z=A[ai+2];
		if (x == y && y==z) {
			base++;
			continue;
		}
		vector<tuple<int,int,int>> q;
		rep(i,3) {
			{
				rep(a,m) {
					int now = dp[a][n];
					if (y == z) chmax(now,dp[a][y]+1);
					q.emplace_back(a,x,now);
				}
			}
			{
				int now = max(dp[n][n],dp[z][z]+1);
				q.emplace_back(x,y,now);
			}
			swap(x,y); swap(y,z);
		}
		for (auto t:q) {
			int i,j,x;
			tie(i,j,x) = t;
			upd(i,j,x);
		}
	}
	int ans = dp[n][n];
	int l =A[n3-1];
	chmax(ans,dp[l][l]+1);
	ans += base;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 19392
#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;
typedef long long llong;

const int MOD=1000000007;
char S[300111];
int n;

int Reducible(int p)
{
    if (p==0)
        return 2;
    else
        return 1;
}

int difOFFSET=3;

int F[300111][8][3][2];

int expand(int pos,int dif,int badSufDif,int sufPar)
{
    if (badSufDif>Reducible(sufPar))
    {
        int reduce=badSufDif-Reducible(sufPar);

        dif+=reduce;
        badSufDif=Reducible(sufPar);
    }

    if (badSufDif<0)
    {
        badSufDif=0;
        sufPar=0;
    }

    if (dif>4)
        dif=4;

    if (F[pos][dif+difOFFSET][badSufDif][sufPar]!=-1)
        return F[pos][dif+difOFFSET][badSufDif][sufPar];

    if (pos==n) ///Done
    {
        if (dif>0)
            return 1;
        else
            return 0;
    }

    char ch=S[pos+1];
    int ans=0;

    if (ch=='0' || ch=='?')
    {
        ans+=expand(pos+1,dif-1,badSufDif+1,sufPar^1);
    }

    if (ch=='1' || ch=='?')
    {
        ans+=expand(pos+1,dif+1,badSufDif-1,sufPar^1);
    }

    if (ans>=MOD)
        ans-=MOD;

    F[pos][dif+difOFFSET][badSufDif][sufPar]=ans;

    return ans;
}

int main()
{
    int i;

    memset(F,-1,sizeof(F));

    scanf("%s",S+1);
    n=strlen(S+1);

    printf("%d\n",expand(0,0,0,0));

    return 0;
}


Measured memory_bytes: 80256
import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  n,k=LI()

  a=n//k
  n-=(a*k)

  a=n
  b=abs(n-k)
  f1=f2=False
  for i in range(100):
    n=abs(n-k)
    if a==n:
      f1=True
    if b==n:
      f2=True

    if f1 and f2:
      return min(a,b)

# main()
print(main())


Measured memory_bytes: 5704
#include <bits/stdc++.h>
      #define ll  long long int
      #define N 100000
      #define f(i,a,b) for(ll i=(ll)a;i<=(ll)b;i++)
      #define rf(i,a,b) for(ll i=(ll)a;i>=(ll)b;i--)
      #define po pop_back
      #define pb push_back
      #define pp pair<ll,ll>
      #define lb lower_bound
      #define fi first
      #define se second
      #define debug(x) cout << #x << " = " << x << endl
      #define ub upper_bound
      #define ibs ios_base::sync_with_stdio(false)
      #define cti cin.tie(0)
      #define all(x) x.begin(),x.end()
      #define PI 3.14159265
      #define cot cout.tie(0)
      using namespace std;
       /**
        * @author :: Sawlani
        *
        */
        int main()
        {
            ll n;
            cin >>  n;
               string s;
               cin >> s;
               ll ans=0;
        f(i,0,n-2)
        {
            if(s[i]!=s[i+1])
                ans++;


        }
        ans+=1;
        cout <<  ans <<  endl;
        }


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

int main() {
	vector<int> e(3);
	for (int i = 0; i < 3; i++)
		cin >> e.at(i);
	sort(e.begin(), e.end());
	cout << e.at(0)*e.at(1) / 2 << endl;
}


Measured memory_bytes: 256
#include <iostream>
    #include <cmath>
    using namespace std;
     
    int main()
    {
        int a, b, c, k, m, ans;
        cin >> a >> b >> c >> k;
        m = max(max(a,b), c);
        ans = a + b + c - m + m*pow(2,k);
        cout << ans << endl;
        return 0;
    }

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<bitset>
#include<cmath>
#include<complex>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<iterator>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;
typedef long long int ll;
typedef pair<int,int> PI;

int N;
vector<PI> E[100005];
int color[100005];
bool painted[100005];

int main(){
    cin>>N;
    for(int i=0;i<N-1;++i){
        int a,b;
        cin>>a>>b;
        a--,b--;
        E[a].push_back(PI(b,i));
        E[b].push_back(PI(a,i));
    }
    
    int K=0;
    for(int i=0;i<N;++i)K=max((int)E[i].size(),K);
    queue<PI> que;
    que.push(PI(0,-1));
    while(!que.empty()){
        int v=que.front().first;
        int p=que.front().second;
        que.pop();
        if(painted[v])continue;
        int t=0;
        for(auto u:E[v]){
            int to=u.first;
            int id=u.second;
            if(color[id]!=0)continue;
            if(t==p)t++;
            color[id]=t%K+1;
            que.push(PI(to,t%K));
            t++;
        }
        painted[v]=true;
    }
    cout<<K<<endl;
    for(int i=0;i<N-1;++i)cout<<color[i]<<endl;
}

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

int main() {
  int n; cin >> n;
  vector<int> A(n);
  map<int, int> cnt;
  rep(i,n) {
    cin >> A[i];
  }
  rep(i,n) {
    if (A[i] >= 3200) {
      cnt[3200]++;
    } else {
      for (int x = 0; x<=2800; x+=400) {
        if (x <= A[i] && A[i] < x+400) {
          cnt[x]++;
          break;
        }
      }
    }
  }
  int minv,maxv;
  minv = cnt.size();
  maxv = minv;
  if (cnt.count(3200)) {
    if (minv != 1) {
      minv--;
    }
    maxv--;
    maxv += cnt[3200];
  }
  cout << minv << " ";
  cout << maxv << endl;

  return 0;
}


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

bool isPalin(string s, int st, int en)
{
    int i = st, j = en;
    while (i < j)
    {
        if (s[i] != s[j])
            return false;
        i++;
        --j;
    }
    return true;
}
int main()
{
    string s;
    cin >> s;
    int n = s.length();
    if (n & 1 && isPalin(s, 0, n - 1) && isPalin(s, 0, (n - 1) / 2 - 1) && isPalin(s, (n + 3) / 2 - 1, n - 1))
        cout << "Yes" << '\n';
    else
        cout << "No" << '\n';
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1e9;

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  for (int i = 0; i < n; ++i) cin >> a[i];

  for (int i = k; i < n; ++i) {
    if (a[i] > a[i - k])
      cout << "Yes\n";
    else
      cout << "No\n";
  }
}


Measured memory_bytes: 4044
#include <iostream>
#include <vector>
#include <queue>
#include<map>
#include<algorithm>
#include<set>
#define rep(i,n) for(int i = 0;i < n;i++)
#define req(i,n) for(int i = 1; i<=n;i++)
#define ALL(a) a.begin(),a.end()
#define MOD 1000000007
#define B2 100000007
using namespace std;
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T & val) {
    std::fill((T*)array, (T*)(array + N), val);
}
typedef long long int ll;
#define P pair<int,int>
int n,a,ans = 0,c,x,y,t;
string s;
int main() {
    cin >> n; int sk = (n % 2) ?  n : n + 1;
    ans = n * (n + 1) / 2 - n / 2;
    vector<P> an;
    req(i, n) {
        for (int j = i + 1; j <= n; j++) {
            if (i + j == sk) continue;
            an.push_back({ i,j });
        }
    }cout << an.size() << endl;
    for (P i : an) cout << i.first << " " << i.second << endl;
}

Measured memory_bytes: 3700
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define all(x) (x).begin,(x).end()

int main(){
  //グループ0,1,2に各自割り振る
  vector<int> g{0,2,0,1,0,1,0,0,1,0,1,0,2};
  
  int x,y;
  cin >> x >> y;
  if(g[x-1] == g[y-1]){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 3632
import java.io.*;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) throws IOException {
        FastScanner in = new FastScanner();
        int n = in.nextInt();
        int numOdd = 0;
        int numEven = 0;
        int numFour = 0;
        for (int i = 0; i < n; i++) {
            int j = in.nextInt();
            if (j % 4 == 0) {
                numFour++;
            } else if (j % 2 == 0) {
                numEven++;
            } else {
                numOdd++;
            }
        }
        
        boolean good = false;
        if (numEven == 0 && numFour >= numOdd - 1) good = true; else if (numFour >= numOdd) good = true;
        
        if (good) {
            System.out.println("Yes");
        } else System.out.println("No");
    }

    public static class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        public FastScanner(String s) {
            try {
                br = new BufferedReader(new FileReader(s));
            } catch (FileNotFoundException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }

        public FastScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String nextToken() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        String nextLine() {
            st = null;
            try {
                return br.readLine();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            return null;
        }

        int nextInt() {
            return Integer.parseInt(nextToken());
        }

        long nextLong() {
            return Long.parseLong(nextToken());
        }

        double nextDouble() {
            return Double.parseDouble(nextToken());
        }
    }
}


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

bool check_Prime_number(int& N){
    if (N==2) return true;
    if (N<2 | N%2==0) return false;
    int root = sqrt(N);
    for (int j=3; j<=root; j+=2) if (N%j==0) return false;
    return true;
}

int main(){
    int n, m, cnt=0;
    cin >> n;
    bool res;
    for (int i=0;i<n; i++){
        cin >> m;
        res = check_Prime_number(m);
        cnt += res;
    }
    cout << cnt << endl;
}


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

using namespace std;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int N,M,X,A;
	int lc=0,rc=0;
	cin >> N >> M >> X;

	for(int i=0;i<M;i++){
		cin >> A;
		if(A<X) lc++;
		else if(A>X) rc++;
	}
	cout << min(lc,rc) <<"\n";

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <sstream>
#include <unordered_set>
#include <map>
#include <unordered_map>
 
using namespace std;
 
 
int main(int argc, const char * argv[]) {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    map<string, int> testCases;
    string verdicts[4] = {"AC", "WA", "TLE", "RE"};
    
    int t;
    cin >> t;
    
    while (t--) {
        string s;
        cin >> s;
        testCases[s]++;
    }
    
    for (string s: verdicts) {
        cout << s << " x " << testCases[s] << '\n';
    }
    
}


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

using namespace std;
int main(void){
 int N;
  cin >> N;
  vector<int> list(N);
  for (int i=0; i<N; i++){
    cin >> list[i];
  }
  string ans = "APPROVED";
 for (int i=0;i<N; i++){
   if (list[i]%2==0){
     if(list[i]%3==0){
     }else if(list[i]%5==0){
     }else{
       ans = "DENIED";
     }
   }
 }
  cout << ans << endl;
  return 0;
}


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

int main() {
  int P, Q, R;
  cin >> P >> Q >> R;
  
  if (P>=Q){
    if(P<=R){
      cout << P+Q << endl;
    }
     else{
       cout << Q+R << endl;
     }
    }
  
  else{
    if(Q>=R){
      cout << P+R << endl;
    }
    
    else{
      cout << P+Q << endl;
    }
  }
}
    
    

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

const int N = (int)1e6;

pair<int,int> dat[N+5];
int dp[N+5];

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

    for (int i=0; i<N+3; i++) dp[i] = -1;
    dp[0] = 0;
    int res = 0;
    for (int i=1; i<=n; i++) {
        int a,b; scanf("%d %d", &a, &b);
        dat[i] = make_pair(a,b);

        for (int j=t-1+a; j>=a; j--) {
            if (dp[j-a] != -1) {
                dp[j] = max(dp[j], dp[j-a] + b);
                res = max(res, dp[j]);
            }
        }
    }

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

    for (int i=0; i<N+3; i++) dp[i] = -1;
    dp[0] = 0;
    int resa = 0;
    for (int i=1; i<=n; i++) {
        int a = dat[i].first;
        int b = dat[i].second;
        for (int j=t-1+a; j>=a; j--) {
            if (dp[j-a] != -1) {
                dp[j] = max(dp[j], dp[j-a] + b);
                resa = max(resa, dp[j]);
            }
        }
    }
    assert(resa >= res);

    printf("%d\n", resa);
    return 0;
}


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

int main() {
  long long n,ans=0,add=0,two=0,mod=1000000007;
  cin>>n;
  vector<long long> A(n);
  for(int i=0;i<n;i++){
    cin>>A[i];
    add+=A[i];
    add%=mod;
  }
  ans=add*add%mod;
  for (int i = 0; i < n; i++){
		ans -= (long long)A[i] * A[i] % mod;
		if (ans < 0) ans += mod;
  }
  ans *= (mod + 1) / 2;
  ans %= mod;
  cout<<ans<<endl;
}

Measured memory_bytes: 4760
#include <stdio.h>
int main(void){
  int sum[1000],a[1000],b[1000],i,n,count[1000];
  i=0;
  while(scanf("%d %d",&a[i],&b[i])!=EOF){    
    sum[i]=a[i]+b[i];
    i++;
  }
  for(n=0;n<i;n++){
    count[n]=0;
    while(sum[n]>0){
      count[n]++;
      sum[n]=sum[n]/10;
    }
  }
  for(n=0;n<i;n++){
    printf("%d\n",count[n]);
  }
  return(0);
}
  

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

# define C continue;
# define R return

# define D double
# define I insert
# define ll long long
# define ld long double

# define ull unsigned long long
# define ui unsigned int

# define pb push_back
# define pf push_front

# define vi vector < int >
# define vc vector < char >
# define vs vector < string >
# define vb vector < bool >
# define vd vector < D >
# define vll vector < ll >
# define vull vector < ull >
# define vld vector < ld >
# define PQ priority_queue

# define vvi vector < vector < int > >
# define vvb vector < vector < bool > >
# define vvc vector < vector < char > >
# define vvs vector < vs >
# define vvll vector < vector < ll > >
# define vvd vector < vector < D > >
# define vvld vector < vector < ld > >

# define all(v) (v).begin() , (v).end()
# define allrev(v) (v).rbegin() , (v).rend()
# define allcomp(v) v.begin() , v.end() , comp
# define allrevcomp(v) v.rbegin() , v.rend() , comp

# define pii pair < int , int >
# define pll pair < ll , ll >
# define pld pair < ld , ld >
# define pDD pair < D , D >

# define vpld vector < pld >
# define vpii vector < pii >
# define vpll vector < pll >
# define vpDD vector < pDD >

# define vvpii vector < vector < pii > >
# define F first
# define S second
# define mp make_pair

# define dist(a,b,p,q) sqrt((p-a)*(p-a) + (q-b)*(q-b))

# define pp(n) printf("%.10Lf",n);
# define line cout<<"\n";
# define fast ios_base::sync_with_stdio(false) ; cin.tie(0) ; cout.tie(0);

string vow = "aeiou";
int month[] = {-1, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

const int dxhorse[] = {-2, -2, -1, -1, 1, 1, 2, 2};
const int dyhorse[] = {1, -1, 2, -2, 2, -2, 1, -1};

const int dx[] = { -1 , 0 , 1 , 0 } ;
const int dy[] = { 0 , 1 , 0 , -1 } ;

const ld pie = 3.1415926535897932384626 ;
const ll mod = 1e9 + 7 ;

/// Tip : If a and b are positive integers ; we may say - ceil (a/b) = 1 + floor ( (a-1)/b ) .

void solve ( int test_case )
{
    ll d , n ;
    cin >> d >> n ;

    ll s = 0 ;
    for ( int i=0 ; i < n ; i ++ )
    {
        ll t ;
        cin >> t ;

        s += t ;
    }

    ll ans = d - s ;

    if ( ans < 0 ) cout << -1 ;
    else cout << ans ; line ;

}

int main()
{
    int t = 1;
    // cin >> t;

    for ( int i=1 ; i <= t ; i ++ ) solve ( i ) ;
    return 0;
}


Measured memory_bytes: 3624
// #include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <set>
#include <queue>
#include <cstdio>
#include <stack>
#include <list>
using namespace std;
#define rep(i, n) for(int i=0;i<n;i++)
#define irep(i, n) for(int i=n-1;i>=0;i--)
#define lrep(i, n) for(long long i=0;i<n;i++)
typedef long long ll;
typedef vector<long long> llv;
typedef vector<vector<long long> > llvv;
template <class T> T gcd(T n, T m){return m ? gcd(m, n%m):n;}

int main(){
    int n;
    cin>>n;
    string s;cin>>s;
    ll sum=1;
    rep(i,n-1){
        if(s[i] != s[i+1]) sum++;
    }
    cout << sum << endl;
}

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

int main(){
  int n;
  cin >> n;
  double ans;
  if(n % 2) ans = ((double)n+1.0)/2.0;
  else ans = (double)n/2.0;
  ans /= (double)n;
  printf("%.9f\n",ans);
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mp make_pair
#define pb push_back
#define scanVec(vec , n) for(int i = 0; i < n ; i++){ cin>>vec[i];}
#define printVec(vec , n) for(int i = 0; i < n ; i++){ cout<<vec[i]<<" ";}
#define S second
#define F first
const int  MOD = 1e9 + 7;
const int  N = 3005;
long double P[N];
long double dp[N][N];

//  a d f j k  l  ;
int main(){
    ios::sync_with_stdio(0);  cin.tie(0);
    int n;
    cin>>n;
    for(int i = 1 ; i <= n; i++){
        cin>>P[i];
    }
    cout<<endl;
    dp[0][0] = 1.0;
    for(int i = 1 ; i <= n; i++){
        dp[i][0] = dp[i-1][0] * P[i];
    }
    for(int i = 1 ; i <= n; i++){
        dp[0][i] = dp[0][i-1] * (1- P[i]);
    }
    for(int i = 1; i <= n; i++){
        for(int j = 1; i + j <= n; j++){
            dp[i][j] = dp[i-1][j] * P[i+j] + dp[i][j-1] * ((long double)1 - P[i+j]);
        }
    }
    // for(int i = 0; i <= n; i++){
    //     for(int j = 0; j <= n; j++){
    //         cout<<dp[i][j]<<" ";
    //     }
    //     cout<<endl;
    // }
    double res = 0;
    for(int i = n/2 + 1; i <= n; i++){
        res += dp[i][n-i];
    }
    cout<<setprecision(10)<<res<<endl;


    return 0;
}

Measured memory_bytes: 139776
#
# abc067 a
#
import sys
from io import StringIO
import unittest


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """4 5"""
        output = """Possible"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """1 1"""
        output = """Impossible"""
        self.assertIO(input, output)


def resolve():
    A, B = map(int, input().split())
    if A % 3 == 0 or B % 3 == 0 or (A+B) % 3 == 0:
        print("Possible")
    else:
        print("Impossible")


if __name__ == "__main__":
    # unittest.main()
    resolve()


Measured memory_bytes: 16220
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
const int MOD=1e9+7;
  long long ans=1,n,cnt[1005];
int main() {
  int i,j,k;
  cin >> n;
  for(i=2; i<=n; i++) {
    for(j=i,k=2; j>1;) {
      if(j%k==0) {
        j/=k,cnt[k]++;
      }
      else {
        k++;
      }
    }
  }
  for(i=2; i<=n; i++) {
    ans=ans*(cnt[i]+1)%MOD;
  }
  cout << ans << endl;
}


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

using namespace std;
typedef long long ll;
const ll inf = (1 << 30) - 1;
const ll infll = (1LL << 61) - 1;
const ll mod = 1e9 + 7;
#define REP(i, o, n) for (ll i = o; i < n; i++)
#define rep(i, n) REP(i, 0, n)

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

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

void actual() {
    // Resolve the problem.
    string s;
    cin >> s;

    string result = "Yes";
    for (size_t i = 1; i <= s.length(); ++i) {
        if (i % 2 == 0) {
            if (s[i - 1] != 'L' && s[i - 1] != 'U' && s[i - 1] != 'D') {
                result = "No";
            }
        } else {
            if (s[i - 1] != 'R' && s[i - 1] != 'U' && s[i - 1] != 'D') {
                result = "No";
            }
        }

    }
    cout << result << endl;
}

int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    actual();
    return 0;
}


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

int main() {
  int N;
  cin >> N;
  int64_t L0 = 2LL, L1 = 1LL, L2;
  
  for(int i = 0; i < N; i++) {
    L2 = L0 + L1;
    L0 = L1;
    L1 = L2;
  }
  
  cout << L0 << endl;
}

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

public class Main {
	public static void main(String[] args) throws IOException {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt(); 
		int c = sc.nextInt();
		int d = sc.nextInt();
		if(a+b > c+d) System.out.println("Left");
		else if(c+d > a+b) System.out.println("Right"); 
		else System.out.println("Balanced");
	}
}

Measured memory_bytes: 23636
#include "bits/stdc++.h"

using namespace std;
using ll = long long int;

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

	vector<int> R(n + 10), G(n + 10), B(n + 10);
	for (size_t i = 0; i < s.length(); i++)
	{
		R[i + 1] = R[i];
		G[i + 1] = G[i];
		B[i + 1] = B[i];

		switch (s[i])
		{
			case 'R':
				R[i + 1]++;
				break;
			case 'G':
				G[i + 1]++;
				break;
			case 'B':
				B[i + 1]++;
				break;
			default:
				break;
		}
	}

	ll ans = 0;
	for (size_t i = 0; i < s.length(); i++)
	{
		for (size_t j = i + 1; j < s.length(); j++)
		{
			if (s[i] != s[j])
			{
				unordered_set<char> S = { 'R', 'G', 'B' };
				S.erase(s[i]);
				S.erase(s[j]);

				vector<int> *array;
				switch (*S.begin())
				{
					case 'R':
						array = &R;
						break;
					case 'G':
						array = &G;
						break;
					case 'B':
						array = &B;
						break;
					default:
						array = nullptr;
						break;
				}

				int index = j + (j - i);
				ans += (*array)[n] - (*array)[j + 1];
				if (index < s.length() && s[index] == *S.begin())
				{
					ans--;
				}
			}
		}
	}

	cout << ans << endl;
}

Measured memory_bytes: 3632
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
#include<stdio.h>
#include <cstdint>
#include <stdlib.h> 
#include <time.h>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define drep(i,n,m) for(int i = n;i >= m;i--)
#define rrep(i,n) REP(i,1,n+1)
#define all(a) a.begin(), a.end()
#define fi first
#define se second
#define RNG(x, a, n) &((x)[a]), &((x)[n])
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
typedef long long ll;
typedef pair<ll, ll> Pll;
typedef pair<int, int> PII;
typedef vector<ll> Vl;
typedef vector<int> VI;
typedef tuple<int, int, int> TT;
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
#define rall(v) v.rbegin(), v.rend()
#define dmp(x,y) make_pair(x,y)
#define dmt(x, y, z) make_tuple(x, y, z)
#define pb(x) push_back(x)
#define pf(x) push_front(x)
const int MAX = 500000;
const int inf = 1000000007;
const ll mod = 1000000007;
const long double PI = (acos(-1));
const long double EPS = 0.0000000001;

int dx[4] = { 1, 0, -1, 0 };
int dy[4] = { 0, 1, 0, -1 };


int a, b, c, k, ans;

int main() {

	cin >> a >> b >> c >> k;

	if (a >= k) {
		ans = k;
		k -= a;
	}
	else {
		ans = a;
		k -= a;
	}

	if (k > 0) {
		if (b <= k)k -= b;
	}

	if (k > 0) {
		ans -= k;
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1e18

int N, M, Q, ans = 0;
vector<int> a, b, c, d;
void solve(int x, int i, vector<int>& A) {
    if (i == N) {
        int res = 0;
        for (int i = 0; i < Q; i++) {
            if (A[b[i]] - A[a[i]] == c[i]) res += d[i];
        }
        ans = max(ans, res);
        return;
    }

    for (int p = x; p <= M; p++) {
        vector<int> cp = A;
        cp.push_back(x);
        solve(p, i + 1, cp);
    }
}

int main() {
    cin >> N >> M >> Q;
    a.resize(Q);
    b.resize(Q);
    c.resize(Q);
    d.resize(Q);
    for (int i = 0; i < Q; i++) cin >> a[i] >> b[i] >> c[i] >> d[i], a[i]--, b[i]--;
    vector<int> v(0);
    solve(1, 0, v);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3636
from collections import defaultdict
import sys
sys.setrecursionlimit(10**7)
v,e=map(int,input().split())
m=defaultdict(list)

for i in range(e):
    x,y=map(int,input().split())
    m[x].append(y)
dp=defaultdict(lambda:-1)
def longestPath():
    
    def findLongestPath(vtx):
        if(dp[vtx]!=-1):
            return dp[vtx]
        res=0
        for i in m[vtx]:
            res=max(res,1+findLongestPath(i))
        dp[vtx]=res
        return res
        
        
    
    ans=0
    for i in range(1,v+1):
        ans=max(ans,findLongestPath(i))
    
    return ans;

print(longestPath())


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

using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  string s;
  cin >> s;
  set<char> t;
  for (size_t i = 0; i < s.size(); ++i) {
    if (t.find(s[i]) == t.end()) {
      t.insert(s[i]);
    } else {
      cout << "no\n";
      return 0;
    }
  }
  cout << "yes\n";
}


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

struct edge {
	int to;
	ll cost;
	edge(int t, ll c) : to(t), cost(c) {}
};

using pli = pair<ll, int>;

using graph = vector<vector<edge>>;

const ll INF = 1e18;

int main()
{
	int N, M, K, S;
	ll P, Q;
	cin >> N >> M >> K >> S >> P >> Q;
	queue<int> q;
	vector<int> d(N, -1);
	for (int i = 0; i < K; i++) {
		int C;
		cin >> C; C--;
		q.push(C);
		d[C] = 0;
	}
	vector<vector<int>> g(N);
	for (int i = 0; i < M; i++) {
		int A, B;
		cin >> A >> B; A--, B--;
		g[A].push_back(B);
		g[B].push_back(A);
	}
	while (!q.empty()) {
		auto v = q.front(); q.pop();
		if (d[v] == S) continue;
		for (auto to : g[v]) if (d[to] == -1) {
			d[to] = d[v] + 1;
			q.push(to);
		}
	}
	graph G(N);
	for (int i = 0; i < N; i++) if (d[i] != 0) {
		for (auto to : g[i]) if (d[to] != 0) {
			G[i].emplace_back(to, to == N - 1 ? 0 : d[to] == -1 ? P : Q);
		}
	}
	vector<ll> dis(N, INF);
	priority_queue<pli, vector<pli>, greater<>> pq;
	pq.emplace(0, 0);
	while (!pq.empty()) {
		auto p = pq.top(); pq.pop();
		int v = p.second;
		if (dis[v] != INF) continue;
		dis[v] = p.first;
		for (auto e : G[v]) if (dis[e.to] == INF) {
			pq.emplace(p.first + e.cost, e.to);
		}
	}
	cout << dis[N - 1] << endl;
	return 0;
}



Measured memory_bytes: 22444
#include<bits/stdc++.h>
using namespace std;
int R,C;
typedef pair<int, int> P;

char c[50][50];
int inf=100000;
int tek[50][50];
int dx[4]={0,0,1,-1};
int dy[4]={1,-1,0,0};
int tna=0;
queue<P> a;
void route(int y,int x){
    if(y==R-1&&x==C-1) tna=tek[y][x];
    for(int i=0;i<4;i++){
        if(0<=y+dy[i]&&y+dy[i]<R&&0<=x+dx[i]&&x+dx[i]<C&&c[y+dy[i]][x+dx[i]]=='.'&&tek[y+dy[i]][x+dx[i]]==inf){
            a.push({y+dy[i],x+dx[i]});
            tek[y+dy[i]][x+dx[i]]=tek[y][x]+1;
        }        
    }
    if(a.size()!=0){
        P r=a.front();
        a.pop();
        if(!tna) route(r.first,r.second);
    }
}
int main(){
    cin>>R>>C;
    for(int i=0;i<50;i++){
        for(int j=0;j<50;j++) tek[i][j]=inf;
    }
    tek[0][0]=0;
    for(int i=0;i<R;i++){
        for(int j=0;j<C;j++) cin>>c[i][j];
    }
    int black=0;
    for(int i=0;i<R;i++){
        for(int j=0;j<C;j++){
            if(c[i][j]=='#')black++;
        }
    }
    route(0,0);
    if(!tna) cout<<-1<<endl;
    else cout<<R*C-black-tna-1<<endl;
}

Measured memory_bytes: 512
#include<stdio.h>
#include<stdbool.h>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<omp.h>
#define rep(i,n) for(int i=0; i <(n); i++)
int main(){
  int a,b;
  scanf("%d%d",&a,&b);
  if((a+b)>=10){
    printf("error\n");
  }else{
    printf("%d\n",a+b);
  }
  return 0;
}

Measured memory_bytes: 128
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
#include <stdint.h>
#include <string.h>
#include <math.h>

uint32_t p[100000];

struct {
	uint32_t x;
	uint32_t y;
} swapList[100000];

uint32_t ufTree[100000];

static uint32_t getRootIdx(const uint32_t idx) {
	uint32_t nextIdx = idx;
	while (1) {
		if (ufTree[nextIdx] == UINT32_MAX) {
			if (idx != nextIdx) {
				ufTree[idx] = nextIdx;
			}
			return nextIdx;
		}
		nextIdx = ufTree[nextIdx];
	}
}

static void mergeTree(const uint32_t root0, const uint32_t root1) {
	ufTree[root1] = root0;
}

int main(void) {
	uint32_t N, M;

	scanf("%"PRIu32" %"PRIu32"\n", &N, &M);
	for (uint32_t idx = 0; idx < N - 1; idx++) {
		scanf("%"PRIu32" ", &(p[idx]));
		ufTree[idx] = UINT32_MAX;
	}
	scanf("%"PRIu32"\n", &(p[N - 1]));
	ufTree[N - 1] = UINT32_MAX;
	for (uint32_t idx = 0; idx < M - 1; idx++) {
		scanf("%"PRIu32" %"PRIu32"\n", &(swapList[idx].x), &(swapList[idx].y));
	}
	scanf("%"PRIu32" %"PRIu32, &(swapList[M - 1].x), &(swapList[M - 1].y));

	for (uint32_t idx = 0; idx < M; idx++) {
		const uint32_t xRoot = getRootIdx(swapList[idx].x - 1);
		const uint32_t yRoot = getRootIdx(swapList[idx].y - 1);
		if (xRoot != yRoot) {
			mergeTree(xRoot, yRoot);
			continue;
		}
	}

	uint32_t matchCount = 0;
	for (uint32_t idx = 0; idx < N; idx++) {
		if (getRootIdx(idx) == getRootIdx(p[idx] - 1)) {
			matchCount++;
		}
	}

	printf("%"PRIu32, matchCount);

	return 0;
}

Measured memory_bytes: 1664
import java.io.*;
import java.util.StringTokenizer;

class Main{

static final PrintWriter out=new PrintWriter(System.out);

public static void main(String[] args) throws IOException{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String line="";
while((line=br.readLine())!=null&&!line.isEmpty()){
StringTokenizer st1=new StringTokenizer(line);
int w=Integer.parseInt(st1.nextToken());
int h=Integer.parseInt(st1.nextToken());
int n=Integer.parseInt(st1.nextToken());
int[] x=new int[n];
int[] y=new int[n];
for(int i=0;i<n;i++){
line=br.readLine();
StringTokenizer st2=new StringTokenizer(line);
x[i]=Integer.parseInt(st2.nextToken());
y[i]=Integer.parseInt(st2.nextToken());
}
int cnt=0;
for(int i=0;i<n-1;i++){
cnt+=minRoad(x[i],y[i],x[i+1],y[i+1]);
}
out.println(cnt);
out.flush();
}
}
private static int minRoad(int a,int b,int c,int d){
if(a==c) return Math.abs(b-d);
if(b==d) return Math.abs(a-c);
int x=a-c;
int y=b-d;
if(x*y>0){
x=Math.abs(x);
y=Math.abs(y);
return Math.max(x,y);
}
x=Math.abs(x);
y=Math.abs(y);
return x+y;
}
}

Measured memory_bytes: 20220
#include<iostream>

int main(){
  long long n,b,r;
  std::cin>>n>>b>>r;
  long long count=0, rem=0;
  // if(b==0)
  //   std::cout<<0<<std::endl;
  // else if(b+r == n)
  //   std::cout<<b<<std::endl;
  // else{
  //   while(n>=b+r){
  //     count += b;
  //     n -= (b+r);
  //   }
  //   if(n<b)
  //     count +=n;
  //   else
  //     count +=b;
  //   std::cout<<count<<std::endl;
  // }

  count = (n/(b+r))*b;
  rem = n%(b+r);
  rem = std::min(b, rem);
  count += rem;
  std::cout<<count<<std::endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<math.h>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<set>
#include<map>
#define REP(i, N) for(ll i = 0; i < N; ++i)
#define FOR(i, a, b) for(ll i = a; i < b; ++i)
#define ALL(a) (a).begin(),(a).end()
#define pb push_back
#define INF 1000000000
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

vector<bool> d;
vector<vector<ll> > r;

int dfs(int roc) {
	if(d[roc]) return 0;
	int res = 1;
	d[roc] = true;
	REP(i, r[roc].size()) {
		if(!d[r[roc][i]]) {
			res += dfs(r[roc][i]);
		}
	}
	return res;
}

int main(void) {
		ll n, m;
		cin>>n;
		vector<pair<ll, string> > c(n);
		REP(i, n) {
			string gomi;
			ll hoge;
			cin>>gomi>>hoge;
			c[i] = {hoge, gomi};
		}
		sort(ALL(c));
		map<string, ll> s;
		REP(i, n) {
			s[c[i].second] = i;
		}
		d.resize(n);
		REP(i, n) d[i] = false;
		cin>>m;
		r.resize(n);
		REP(i, m) {
			string foo1, foo2;
			cin>>foo1>>foo2;
			r[s[foo1]].pb(s[foo2]);
			r[s[foo2]].pb(s[foo1]);
		}
		ll ans = 0;
		REP(i, n) {
			if(!d[i]) {
			int buf = dfs(i);
			ans += buf * c[i].first;
			}
		}
		cout<<ans<<endl;
	
}

Measured memory_bytes: 3792
nyuuryoku=[]
while True:
	bbb=int(input())
	if bbb==0:	
		break
	a=1000-bbb
	gohyaku=int(a/500)
	hyaku=int((a-(500*gohyaku))/100)
	gojuu=int((a-(500*gohyaku)-(100*hyaku))/50)
	juu=int((a-(500*gohyaku)-(100*hyaku)-(50*gojuu))/10)
	go=int((a-(500*gohyaku)-(100*hyaku)-(50*gojuu)-(juu*10))/5)
	iti=int((a-(500*gohyaku)-(100*hyaku)-(50*gojuu)-(juu*10)-(go*5))/1)
	print(go+gohyaku+gojuu+hyaku+iti+juu)

		


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

int main(){
    int h,w,kk;
    cin>>h>>w>>kk;

    vector<string> arr(h);
    for(int i = 0; i < h; i++) cin>>arr[i];

    int res = INT_MAX;
    for(int x = 0; x < (1<<(h-1)); x++){
        int g = 0;
        vector<int> gr(h);
        for(int i = 0; i < h-1; i++){
            if(x>>i&1) gr[i+1] = gr[i]+1;
            else gr[i+1] = gr[i];
        }

        int ans = __builtin_popcount(x);
        vector<int> cnt(h);        
        bool ok = 1;

        for(int i = 0; i < w; i++){
            vector<int> cnt1(h);
            for(int j = 0; j < h; j++){
               cnt1[gr[j]]+=(arr[j][i]-'0'); 
            }
            for(int j = 0; j < h; j++){
                if(cnt1[j]>kk) ok = 0;
            }
            bool cut = 0;
            for(int j = 0; j < h; j++){
                if(cnt[j]+cnt1[j]>kk) cut = 1;
            }


            if(cut){
                ans++;
               cnt = cnt1; 
            } else {
                for(int j = 0; j < h; j++) cnt[j]+=cnt1[j];
            }
        }
        if(ok){
            res = min(res,ans);
        }
    } 
    cout<<res;
}



Measured memory_bytes: 3632
#include<bits/stdc++.h>
#include<string>
using namespace std;
#define test(t) int t;cin>>t;while(t--)
#define lli long long int
#define pb push_back
#define MAX 1000000007
#define mod 1000000007

const lli infl=0x3f3f3f3f3f3f3f3fLL;

int main()
{  ios_base::sync_with_stdio(false);
	cin.tie(NULL);cout.tie(NULL);
  //test(t)
   {
       lli a,b,c,n,d,x,q,k=0,y,r,i,j,l,sum=0;
      string s;
      cin>>n;
      map<string,int> m;map<string, int>::iterator itr;
      for(int i=0;i<n;i++)
      {cin>>s;
          m[s]++;
      }for (itr = m.begin(); itr != m.end(); ++itr)
      {
          sum++;
      }cout<<sum;
    cout<<endl;
   }




}


Measured memory_bytes: 19252
N = int(input())
A = [int(input()) for _ in range(N)]

m1 = m2 = 0

for x in A:
    if x > m2:
        if x >= m1:
            m1, m2 = x, m1
        else:
            m2 = x

for a in A:
    if a == m1:
        print(m2)
    else:
        print(m1)


Measured memory_bytes: 69080
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
typedef pair<int,int>P;
 
int main() {
  int a;
  cin>>a;
  vector<P>p(a);
  for(int i=0;i<a;i++){
    cin>>p[i].second>>p[i].first;
  }
  sort(p.begin(),p.end());
  ll t=0,tri=0;
  for(int i=0;i<a;i++){
    t+=p[i].second;
    if(t>p[i].first){
      cout<<"No"<<endl;
      tri++;
      break;
    }
  }
  if(tri<1){
  cout<<"Yes"<<endl;
}
}

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

int main() {
  string S;
  cin >> S;
  int res = 1000;
  for (int i = 0; i < S.size()-2; i++) {
    int num = stoi(S.substr(i, 3));
    int sub = abs(753 - num);
    if (sub < res) res = sub;
  }
  cout << res;
}


Measured memory_bytes: 256
import numpy as np

N, X = map(int, input().split())

b = np.empty(N, dtype=int)
l = np.empty(N, dtype=int)
u = np.empty(N, dtype=int)

for n in range(N):
    b[n], l[n], u[n] = map(int, input().split())

c = X * u - b*(u - l)
di = np.argsort(c)[::-1]
c = c[di]
b = b[di]
l = l[di]
u = u[di]
bl = b * l
bsum = bl.sum()

# 累乗和
c_cumsum = np.cumsum(c)
#
c_p = np.searchsorted(c_cumsum, bsum, side='left')

if bsum == c_cumsum[c_p]:
    print((c_p + 1)*X)
    exit(0)

if c_p > 0:
    left = bsum - c_cumsum[c_p - 1]
else:
    left = bsum

ans = np.empty(N, dtype=int)
left1 = left - c[c_p]
ans[:c_p] = np.where(left1 + c[:c_p] <= bl[:c_p], (left1 + c[:c_p] - 1) // l[:c_p] + 1, (left1 + c[:c_p] - bl[:c_p] - 1) // u[:c_p] + b[:c_p] + 1)
ans[c_p:] = np.where(left <= bl[c_p:], (left - 1) // l[c_p:] + 1, (left - bl[c_p:] - 1) // u[c_p:] + b[c_p:] + 1)
ans1 = c_p * X + ans.min()
print(ans1)

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

using namespace std;
const int INF = (1 << 30);
const int N = 100000 + 5;
const double eps = 1e-8;
const int M = 100 + 5;
const int MOD = 1e9;

int a[N];
int main(){
    int n, ans = 0;
    scanf("%d", &n);
    for(int i = 1; i <= n; i++) scanf("%d", &a[i]);

    for(int i = 1; i < n; i++)
        if(a[i] == i) swap(a[i], a[i + 1]), ans++;
    if(a[n] == n) ans++;
    printf("%d\n", ans);
}


Measured memory_bytes: 640
#include <iostream>
using namespace std;
int main()
{
	int a;
	int c = 0;
	cin >> a;
	string b[1000];
	for (int i = 0; i < a; i++) {
		cin >> b[i];
		if (b[i] == "E869120") {
			c++;
		}
	}
	cout << c << endl;
}



Measured memory_bytes: 3296