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

int main() {
	
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	int flag = 0;
	while (true) {
		if (a <= 0 || c <= 0) {
			break;
		}
		if (flag == 0) {
			c = c - b;
			flag = 1;
		}
		else {

			a = a - d;
				flag = 0;
		}

	}
	if (flag) {
		cout << "Yes";
	}
	else {
		cout << "No";
	}
}

Measured memory_bytes: 3636
int main(){
    int n,y,i,j,k;
    scanf("%d%d",&n,&y);
    for(i=0;i<=n;i++)for(j=0;j<=n-i;j++){
        k=n-i-j;
        if(i*1000+j*5000+k*10000==y){
            printf("%d %d %d\n",k,j,i);
            return 0;
        }
    }
    puts("-1 -1 -1");
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int n,m;
  cin >> n >> m;
  int ans=0;
  vector<bool>judge(n+1,true);
  vector<int>cnt(n+1,0);
  for(int i=0;i<m;i++){
    int p;
    string s;
    cin >> p >> s;
    if(s=="WA"&&judge.at(p)){
      cnt.at(p)++;
    }
    if(s=="AC"&&judge.at(p)){
      ans++;
      judge.at(p)=false;
    }
  }
  int count=0;
  for(int i=1;i<=n;i++){
    if(judge.at(i)==false){
      count+=cnt.at(i);
    }
  }
  cout << ans << " " << count << endl;
}

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

using namespace std;

using ll = long long;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<ll> a(n);
  for (auto&& e : a) {
    cin >> e;
  }
  vector<ll> need(n);
  need[0] = a[0];
  ll ans = 0;
  for (int i = 1; i < n; i++) {
    need[i] = max(a[i], need[i - 1]);
    ans += need[i] - a[i];
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 6352
N, C = [int(i) for i in input().split(' ')]

dist = []

for _ in range(C):
    tmp = [int(x) for x in input().split(' ')]
    dist.append(tmp)

color_map = [[0 for _ in range(C)] for _ in range(3)]

for i in range(1, N+1):
    for j, x in enumerate(input().split(' ')):
        j = j+1
        x= int(x)-1

        color_map[(i+j)%3][x] += 1

cost = float('inf')

for c1 in range(C):
    for c2 in range(C):
        if c1 == c2:
            continue
        for c3 in range(C):
            if c1 == c3 or c2 == c3:
                continue
            tmp_cost = 0
            for i in range(C):
                tmp_cost += dist[i][c1] * color_map[0][i]
                tmp_cost += dist[i][c2] * color_map[1][i]
                tmp_cost += dist[i][c3] * color_map[2][i]
            
            cost = min(cost, tmp_cost)
if cost == float('inf'):
    cost = 0
print(cost)

Measured memory_bytes: 3064
#include<cstdio>
#include<cstring>
#include<queue>
using namespace std;
#define INF 1e18
#define N 100005
int n,m,s,t;
long long f=1e15;
long long ans[N];
struct node//学到老，回到老>.< 
{
	struct Edge
	{
		int next;
		int to;
		long long dis;
	}edge[N*2+5];
	
	int cnt;
	int head[N*2],vis[N];
	long long dis[N];
	void add(int from,int to,long long dis)
	{
		edge[++cnt].next=head[from];
		edge[cnt].to=to;
		edge[cnt].dis=dis;
		head[from]=cnt;
	}
	
	queue<int >Q;
	
	void SPFA(int s)
	{
		for(int i=1;i<=n;i++)
		dis[i]=INF;
		memset(vis,0,sizeof vis);
		Q.push(s);
		vis[s]=1;
		dis[s]=0;
		while(!Q.empty())
		{
			int x=Q.front();
			Q.pop();
			vis[x]=0;
			for(int i=head[x];i;i=edge[i].next)
			{
				int to=edge[i].to;
				if(dis[to]>dis[x]+edge[i].dis)
				{
					dis[to]=dis[x]+edge[i].dis;
					if(!vis[to]) Q.push(to),vis[to]=1;
				}
			}
		}
	}
}G1,G2;
int main()
{
	scanf("%d %d %d %d",&n,&m,&s,&t);
	int u,v;
	long long a,b;
	for(int i=1;i<=m;i++)
	{
		scanf("%d %d %lld %lld",&u,&v,&a,&b);
		G1.add(u,v,a);
		G1.add(v,u,a);
		G2.add(u,v,b);
		G2.add(v,u,b);
	}
	G1.SPFA(s);
	G2.SPFA(t);
	ans[n+1]=INF;
	for(int i=n;i>=1;i--)
	ans[i]=min(ans[i+1],G1.dis[i]+G2.dis[i]);
	for(int i=1;i<=n;i++)
	printf("%lld\n",f-ans[i]);
 } 

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

int main() {
  int N, highest = 0, cnt = 0; cin >> N;
  for (int i = 0; i < N; i++) {
    int h; cin >> h;
    if (h >= highest) {
      cnt++;
      highest = h;
    }
  }
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 256
object Main extends App {
  import scala.io.StdIn._

  val n = readInt
  val a = readLine.trim.split(' ').map(_.toInt)

  println(
    (-100 to 100).map(y ⇒ a.map(x ⇒ (x - y) * (x - y)).sum).min
  )
  implicit class Scope[T](val value: T) extends AnyVal {
    @inline
    def let[A](func: T ⇒ A): A = func(value)
    @inline
    def also(func: T ⇒ Unit): T = {
      func(value)
      value
    }
  }
}


Measured memory_bytes: 28232
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <utility>
#include <iostream>
#include <algorithm>
#include <functional>

using namespace std;

#define INF (1 << 30)
#define INFL (1LL << 62)
#define MOD7 1000000007
#define MOD9 1000000009
#define EPS 1e-10

#define ll long long
#define ull unsigned long long
#define all(a) (a).begin(), (a).end()

int main() {
	int a, b;
	cin >> a >> b;
	cout << fixed << setprecision(6);
	cout << a / b << " " << a % b << " " << (double)a / b << endl;

	return 0;
}


Measured memory_bytes: 3280
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力(スペース改行関係なし)
		int a = sc.nextInt();
		int b = sc.nextInt();
      	int c = sc.nextInt();
      	int k = sc.nextInt();
      	int sum = 0;

      	for(int i = 0; i < k ; i++){
        	if(a != 0){
            	sum += 1;
              	a--;
            }else if(b != 0){
            	sum += 0;
              	b--;
            }else{
            	sum -= 1;
              	c--;
            }
        }
			System.out.println(sum);
		
	}
}

Measured memory_bytes: 35784
#include <bits/stdc++.h>
using namespace std;
#define INF 2000000000
typedef long long int ll;
typedef pair<ll,ll> ii;
typedef pair<ii,ll> iii;
typedef vector<ll> vi;
typedef vector<ii> vii;
#define getbit(n,i) (((n)&(1LL<<(i)))!=0)
#define setbit0(n,i) ((n)&(~(1LL<<(i))))
#define setbit1(n,i) ((n)|(1LL<<(i)))
#define lastone(n) ((n)&(-(n)))
#define read freopen("debug\\in.txt","r",stdin)
#define write freopen("debug\\out.txt","w",stdout)
#define DBG(a) cout<<#a<<" ->->->-> "<<a<<"\n"
#define EN cout<<"\n"
#define fi first
#define se second
#define PI (acos(-1))
#define fastread ios::sync_with_stdio(false);cin.tie(NULL)
#define mod (998244353)
#define asz 300005
template<class T> ostream& operator<<(ostream &s,pair<T,ll> a)
{
    s<<a.fi<<' '<<a.se;
    return s;
}
int main()
{
    fastread;
    priority_queue<ll,vector<ll>,greater<ll>> r,g;
    priority_queue<ll> w;
    ll a,b,x,y,c;
    cin>>a>>b>>x>>y>>c;
    for(int i=0;i<x;i++)
    {
        ll e;
        cin>>e;
        r.push(e);
    }
    for(int i=0;i<y;i++)
    {
        ll e;
        cin>>e;
        g.push(e);
    }
    for(int i=0;i<c;i++)
    {
        ll e;
        cin>>e;
        w.push(e);
    }
    while(r.size()>a)r.pop();
    while(g.size()>b)g.pop();
    while(!w.empty())
    {
        ll u=w.top();
        w.pop();
        if(r.top()>g.top())g.push(u),g.pop();
        else r.push(u),r.pop();
    }
    ll ans=0;
    while(!r.empty())ans+=r.top(),r.pop();
    while(!g.empty())ans+=g.top(),g.pop();
    cout<<ans<<endl;
}

Measured memory_bytes: 3316
<?php

$number = trim(fgets(STDIN));

$count = 0;
for($i=1; $i<=$number; $i++){
	if($i%15==0){
		continue;
	}elseif($i%5==0){
		continue;
	}elseif($i%3==0){
		continue;
	}else{
		$count += $i;
	}
}
echo $count;

Measured memory_bytes: 16164
#include <algorithm>
#include <iostream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <bitset>
#include <complex>
#include <unistd.h>
#include <cassert>
#include <cctype>
#include <random>
#include <time.h>
#include <functional>
#define _USE_MATH_DEFINES
#define _GLIBCXX_DEBUG
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef pair<double, ll> pdlg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
typedef tuple<ll, ll, ll, ll> tlglglglg;
typedef tuple<double, double, double> tddd;
typedef complex<double> xy_t;
typedef vector<ll> vll;
typedef vector< vector<ll> > matrix;
typedef unsigned int uint;
typedef unsigned long long ull;
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;
template <class T> using VVV = V<VV<T>>;
#define REP(i, x, y) for(ll i = (ll)x; i < (ll)y; i++)
#define DREP(i, x, y, d) for(ll i = (ll)x; i < (ll)y; i += (ll)d)
#define PER(i, x, y) for(ll i = (ll)x; i > (ll)y; i--)
#define DPER(i, x, y, d) for(ll i = (ll)x; i > (ll)y; i -= (ll)d)
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
double pi = 3.141592653589793;
ll mod = 1000000007;
int intmax = 2147483647;
int intmin = -2147483648;
ll llmax = 9223372036854775807;
ll llmin = -9223372036854775807;
int iinf = intmax / 8;
ll inf = llmax / 8;
double eps = 1e-12;
void yesno(bool ok, string yes = "Yes", string no = "No") {
    if (ok) {
        cout << yes << endl;
    } else {
        cout << no << endl;
    }
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    if (s == "ABC") {
        cout << "ARC" << endl;
    } else {
        cout << "ABC" << endl;
    }
}


Measured memory_bytes: 3640
from collections import Counter
while 1:
  H = int(input())
  if H == 0:
    exit()
    
  A = [[] for _ in range(5)]
  for i in range(H):
    tmp = list(map(int, input().split()))
    for j in range(5):
      A[j].append(tmp[j])
      
  for j in range(5):
    A[j] = A[j][::-1]
  
  ans = 0
  while 1:
    tmp = ans
    N = min([len(a) for a in A])
    for j in range(N):
      l = Counter([A[i][j] for i in range(5)])
      for k in range(10):
        if l[k] == 5:
          tmp += 5*k
          for i in range(5):
            A[i][j] = 'x'
          break
        elif A[0][j]==A[1][j]==A[2][j]==A[3][j]==k:
          tmp += 4*k
          for i in range(4):
            A[i][j] = 'x'
          break
        elif A[1][j]==A[2][j]==A[3][j]==A[4][j]==k:
          tmp += 4*k
          for i in range(1,5):
            A[i][j] = 'x'
          break
        elif A[0][j]==A[1][j]==A[2][j]==k:
          tmp += 3*k
          for i in range(3):
            A[i][j] = 'x'
          break
        elif A[1][j]==A[2][j]==A[3][j]==k:
          tmp += 3*k
          for i in range(1,4):
            A[i][j] = 'x'
          break
        elif A[2][j]==A[3][j]==A[4][j]==k:
          tmp += 3*k
          for i in range(2,5):
            A[i][j] = 'x'
          break
    if tmp == ans:
      break
    else:
      ans = tmp
      B = [[] for _ in range(5)]
      for i in range(5):
        for a in A[i]:
          if a != 'x':
            B[i].append(a)
      A = B
  print(ans)


Measured memory_bytes: 6016
import math


def update(numlist,i):
  if i<0:
    return
  if i==0:
    numlist[i]=numlist[2*i+1]+numlist[2*i+2]
    return
  numlist[i]=numlist[2*i+1]+numlist[2*i+2]
  update(numlist,(i-1)//2)
  return

def find(numlist,x,y,k,minimum,maximum):
  if x>=maximum or y<minimum:
    return 0
  if x<=minimum and maximum-1<=y:
    return numlist[k]
  else:
    L=find(numlist,x,y,k*2+1,minimum,(maximum+minimum)//2)
    R=find(numlist,x,y,k*2+2,(maximum+minimum)//2,maximum)
    return L+R
    
  

n,q=map(int,input().split())
L2n=math.ceil(math.log2(n))
zero=2**(L2n)-1
MAX=2**31-1
numlist=[0]*(2**(L2n+1)-1)
resultlist=[]

for _ in range(0,q):
  com,x,y=map(int,input().split())
  if com:
    resultlist.append(find(numlist,x-1,y-1,0,0,2**L2n))
  else:
    numlist[zero+x-1]+=y
    update(numlist,(zero+x-2)//2)

for x in resultlist:
  print (x)



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

signed
main(){
		int sx,sy,tx,ty;
		cin >> sx >> sy >> tx >> ty;

		string ans = "";
		ans += string(tx-sx, 'R');
		ans += string(ty-sy, 'U');
		ans += string(tx-sx, 'L');
		ans += string(ty-sy, 'D');

		ans += string(1, 'L');
		ans += string(ty-sy+1, 'U');
		ans += string(tx-sx+1, 'R');
		ans += string(1, 'D');

		ans += string(1, 'R');
		ans += string(ty-sy+1, 'D');
		ans += string(tx-sx+1, 'L');
		ans += string(1, 'U');

		cout << ans << endl;
}

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

struct node{
  unsigned int key;
  struct node *next;
  struct node *prev;
};

typedef struct node * NodePointer;

NodePointer nil;

NodePointer listSearch(int key){
  NodePointer x;
  
  x=nil->next; 
  while(x != nil && x->key != key)
    x=x->next; 
  
  return x; 
}

void init(){
  nil = malloc(sizeof(struct node));
  nil->next = nil;
  nil->prev = nil;
}

void printList(){
  NodePointer cur = nil->next;
  int isf = 1;
  while(1){
    if ( cur == nil ) break;
    if ( isf == 0)  printf(" ");
    printf("%d", cur->key);
    cur = cur->next;
    isf = 0;
  }
  printf("\n");
}

void deleteNode(NodePointer t){
  
  t->prev->next = t->next;
  t->next->prev = t->prev;
  free(t);
}

void deleteFirst(){
  NodePointer t = nil->next;
  if ( t == nil ) return;
  deleteNode(t);
}

void deleteLast(){
  NodePointer t;
  t = nil->prev;
  if(t == nil)
    return;
  deleteNode(t);
}

void delete(int key){
  NodePointer k;
  
  k = listSearch(key);
  
  if(k == nil)
    return;
  
  deleteNode(k);
  
}

void insert(int key){
  NodePointer x;
  x = malloc(sizeof(struct node));
  x->key = key;
  
  x->next = nil->next;
  nil->next->prev = x;
  nil->next = x;
  x->prev = nil;
}

int main(){
  int key, n, i;
  int size = 0;
  char com[20];
  int np = 0, nd = 0;
  scanf("%d", &n);
  init();
  for ( i = 0; i < n; i++ ){
    scanf("%s%d", com, &key);
    if ( com[0] == 'i' ) {insert(key); np++; size++;}
    else if ( com[0] == 'd' ) {
      if (strlen(com) > 6){
	if ( com[6] == 'F' ) deleteFirst();
	else if ( com[6] == 'L' ) deleteLast();
      } else {
	delete(key); nd++; 
      }
      size--;
    }
  }
  
  printList();
  return 0;
}

Measured memory_bytes: 31788
n,a,b = map(int,input().split())

h = []
for i in range(n):
    h.append(int(input()))
st,ed = 0,10**9+1
while st<ed-1:
    mid = (st+ed)//2
    #print(mid)
    tmp = 0
    for i in range(n):
        x = h[i]-mid*b
        if x>0:
            tmp+=(x//(a-b))+(x%(a-b)>0)
    if tmp<=mid:
        ed = mid
    else:
        st = mid
print(ed) 


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

#define rep(i,n) for(long long i=0; i<(long long)(n);i++)
#define rep1(i,s,n) for(long long i=s; i<=(long long)(n);i++)
//rep1は「sからnまで」の繰り返し
#define repr(i,s,n) for(long long i=s;i>=(long long)(n);i--)
//reprは「ｓからnまで」の繰り返し

typedef long long ll;

const ll inf = 1e18+7;
const ll mod = 1e9+7;


int main() {
    vector<vector<int>>a(3,vector<int>(3)),b(3,vector<int>(3,0));
    rep(i,3){
        rep(j,3){
            cin>>a[i][j];
        }
    }

    int n;cin>>n;

    rep(i,n){
        int B;cin>>B;
        rep(i,3){
            rep(j,3){
                if(B==a[i][j]){
                    b[i][j]=1;
                }
            }
        }
    }

   bool jdg=false;

   rep(i,3){
        if(b[i][0]==1&&b[i][1]==1&&b[i][2]==1){
            jdg=true;
            break;
       }
   }
   rep(j,3){
       if(b[0][j]==1&&b[1][j]==1&&b[2][j]){
           jdg=true;
           break;
       }
   }
   if(b[0][0]==1&&b[1][1]==1&&b[2][2]==1){
       jdg=true;
   }

   if(b[0][2]==1&&b[1][1]==1&&b[2][0]==1){
       jdg=true;
   }

   if(jdg)cout<<"Yes"<<endl;
   else cout<<"No"<<endl;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)a;i<(int)b;++i)
int main(){
    int n,d,x;cin>>n>>d>>x;
    rep(i,n){
        int a;cin>>a;
        int idx=1;
        while(idx<=d){
            x++;
            idx+=a;
        }
    }
    cout<<x<<endl;
    return 0;
}

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

int main(){
  int n;
  cin >> n;
  int x[n],y[n];
  float dis[n][n];
  for(int i=0;i<n;i++){
      cin >> x[i] >> y[i];
  }
  double ans = 0;
  for(int i=0;i<n;i++){
      for(int j=i+1;j<n;j++){
          ans += sqrt((x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j])); 
      }
  }
  ans = ans*2/n;
  cout << fixed << setprecision(10) << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <string.h>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <stdio.h>
#include <vector>
#include <thread>
#include <atomic>
#include <mutex>
#include <future>
#define int long long
#define endre getchar();getchar();return 0
#define INF 1000000007
using namespace std;
bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return (y, x%y);
}
int lcm(int x, int y) {
	return x * y / gcd(x, y);
}
int kai(int n) {
	if (n == 0)return 1;
	return (kai(n - 1)*n) % INF;
}
int mod_pow(int x, int y, int mod) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x%mod;
		}
		x = x * x%mod;
		y >>= 1;
	}
	return res;
}
int n, a, x[55], dp[105][105][5005], cnt;
signed main() {
	cin >> n >> a;
	for (int i = 0; i < n; i++)cin >> x[i];
	dp[0][0][0] = 1;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j <= i; j++) {
			for (long long k = 0; k < 5000; k++) {
				dp[i + 1][j + 1][k + x[i]] += dp[i][j][k];
				dp[i + 1][j][k] += dp[i][j][k];
			}
		}
	}
	for (int i = 1; i <= n; i++)cnt += dp[n][i][a*i];
	cout << cnt << endl;
	endre;
}


Measured memory_bytes: 121088
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <functional>
#include <map>
#include <iomanip>
#include <math.h> 
#include <stack>
#include <queue>
#include <bitset>
#include <cstdlib>
#include <tuple>
#include <cctype>
#include <ctype.h>
#include <set>
#include <sstream>
#include <time.h>
#include <numeric>
using namespace std;
//#define int long long
#define rep(i,s,n) for(int i = s;i<n;i++)
#define repe(i,s,n) for(int i = s;i<=n;i++)
#define rrep(i,s,n) for(int i = (n)-1;i>=(s);i--)
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define fi first
#define se second
#define chmin(a,b) a=min((a),(b))
#define chmax(a,b) a=max((a),(b))
#define l1 list[index]
#define l2 list[index - 1]
#define l3 list[index + 1]
#define iif(i,j) ((i<0 && j<0) || (i>0 && j>0)) ? true : false 
typedef long long ll;
typedef pair<int, int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
typedef pair<pint, int> P1;
typedef pair<int, pint> P2;
typedef pair<pint, pint> PP;
static const ll maxLL = (ll)1 << 62;
const ll MOD = 1000000007;
const ll INF = 1e18;
const double PI = 3.14159265359;
int ca[12] = { 31,28,31,30,31,30,31,31,30,31,30,31 };

int n, m;
vector<int>plist;

struct MyStruct
{
	vector<int>list;

	MyStruct(int n) {
		for (int i = 0; i < n; i++) {
			//int num = 0;
			list.push_back(i);
		}
	}

	int root(int r) {
		if (list[r] == r) 	return r;
		//root(list[r]);
		return list[r] = root(list[r]);
	}

	bool same(int x, int y) {
	/*	int xx = root(list[x]);
		int yy = root(list[y]);*/
		int xx = root(x);
		int yy = root(y);
		//if (xx == yy)return true;
		return xx == yy;
		//return false;
	}

	void one(int x, int y) {
//		int xx = root(list[x]);
	//	int yy = root(list[y]);
		int xx = root(x);
		int yy = root(y);
		//if (xx == yy)return true;
		list[xx] = list[yy];
	}


};

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

	MyStruct st(n);


	for (int i = 0; i < n; i++) {
		int num;
		cin >> num;
		plist.push_back(num - 1);
	}

	for (int i = 0; i < m; i++) {
		int x, y;
		cin >> x >> y;
		x--; y--;

		st.one(x, y);
	}

	int cnt = 0;

	for (int i = 0; i < n; i++) {
		if (st.same(plist[i], i)) {
			cnt++;
		}
	}

	cout << cnt << endl;


	return 0;
}


Measured memory_bytes: 1400
/*

宣告——
汝身听吾号令，托付吾之命运于汝之剑，
应圣杯之召，若汝遵从此意志此理，回应吧。
在此起誓，吾愿成就世间一切之善行，吾愿诛尽世间一切之恶行。
汝为身缠三大言灵之七天，从抑止之轮显现吧，天秤之守护者！

*/
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cassert>
#include<cmath>
#include<vector>
#include<queue>
#define ll long long
using namespace std;
inline int read(){
	int re=0,flag=1;char ch=getchar();
	while(!isdigit(ch)){
		if(ch=='-') flag=-1;
		ch=getchar();
	}
	while(isdigit(ch)) re=(re<<1)+(re<<3)+ch-'0',ch=getchar();
	return re*flag;
}
int n,m,k,i;
char s[100010],t[100010];
int gcd(int l,int r){
	if(r==0) return l;
	return gcd(r,l%r);
}
int main(){
	n=read();m=read();k=gcd(n,m);
	int nn=n/k,mm=m/k;
	scanf("%s",s);
	scanf("%s",t);
	for(i=0;i<k;i++){
		if(s[nn*i]!=t[mm*i]){puts("-1");return 0;}
	}
	printf("%lld\n",(ll)n/(ll)k*(ll)m);
}

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

const uint64_t MOD = 1e+9 + 7;

std::vector<uint64_t> fact, fact_inv;

void init_fact_vector(uint64_t H, uint64_t W)
{
  fact = std::vector<uint64_t>(H + W, 0);
  fact[0] = 1;
  
  for (uint64_t i = 1; i < H + W; ++i) {
    fact[i] = (i * fact[i - 1]) % MOD;
  }
}

uint64_t bin_pow(uint64_t x, uint64_t y)
{
  if (y == 0) return 1;
  if (y == 1) return x % MOD;
  
  uint64_t t = bin_pow(x, y >> 1);
  uint64_t z = (t * t) % MOD;
  
  if ((y & 1) == 1) {
    z = (z * x) % MOD;
  }
  
  return z;
}

void init_fact_inv_vector(uint64_t H, uint64_t W)
{
  fact_inv = std::vector<uint64_t>(H + W, 0);
  
  for (uint64_t i = 0; i < H + W; ++i) {
    fact_inv[i] = bin_pow(fact[i], MOD - 2);
  }
}

inline uint64_t comb(uint64_t n, uint64_t r)
{
  uint64_t denom = (fact_inv[r] * fact_inv[n - r]) % MOD;
  return (fact[n] * denom) % MOD;
}

inline uint64_t calc(uint64_t H, uint64_t W, uint64_t A, uint64_t B, uint64_t i)
{
  uint64_t x = comb((H - A - 1) + i, i);
  uint64_t y = comb((A - 1) + (W - 1 - i), (W - 1 - i));
  return (x * y) % MOD;
}

int main()
{
  uint64_t H, W, A, B;
  std::cin >> H >> W >> A >> B;
  
  init_fact_vector(H, W);
  
  init_fact_inv_vector(H, W);
  
  uint64_t S = 0;
  for (uint64_t i = B; i < W; ++i) {
    S = (S + calc(H, W, A, B, i)) % MOD;
  }
  std::cout << S << std::endl;
  
  return 0;
}

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

int main(){
    
    while(true){
        int ans = 0;
        int n,x;
        cin >> n >> x;
        if(n == 0 && x == 0)break; 
        for(int i=1;i<=n-2;i++){
            for(int j=i+1;j<=n-1;j++){
                for(int k=j+1;k<=n;k++){
                    if(i+j+k == x) ans++;
                }
            }
        }
        cout << ans << endl;
    }
    
return 0;
}


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

using namespace std;

#define INF 1000000007
#define LINF (1LL << 60)

typedef long long i64;
typedef pair<i64,i64> P;

inline i64 mod(i64 a, i64 m) { return (a % m + m) % m; }

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



int n, m, l[101010], r[101010];
int d[101010];
void solve(){
	cin >> n >> m;
	for(int i = 0; i < m; i++){
		cin >> l[i] >> r[i];
		d[l[i]]++;
		d[r[i]+1]--;
	}
	
	int cnt = 0;
	for(int i = 0; i <= n; i++){
		d[i+1] += d[i];
		if(d[i] == m) cnt++;
	}
	cout << cnt << endl;
}

int main(){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	int t = 1;
	//cin >> t;
	while(t--){
		solve();
	}
	
	return 0;
}


Measured memory_bytes: 1408
// Problem : A - Not
// Contest : AtCoder - AtCoder Beginner Contest 178
// URL : https://atcoder.jp/contests/abc178/tasks/abc178_a
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define int long long
#define db double
#define mod 1000000007
#define pb push_back
#define pp pair<int,int>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repe(i,a,b) for(int i=a;i<=b;i++)
#define repr(i,a,b) for(int i=b;i>=a;i--)
#define maxn 200005
#define ss second
#define ff first
#define all(a) a.begin(),a.end()
#define lb lower_bound
#define ub upper_bound
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
int inv(int a, int b){
 return 1<a ? b - inv(b%a,a)*b/a : 1;
}
void solve()
{
	int x;
	cin >> x;	
	cout << 1-x;
}
signed main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t=1;
    //cin >> t;
    while(t--)
    solve();
    return 0;
}


Measured memory_bytes: 3636
#include <stdio.h>
#define rep(i, n) for (int i = 0; i < (int) (n); i++)
#define MOD 1000000007
typedef long long ll;

#include <assert.h>
#include <stdio.h>
#include <stdlib.h>

#define SIZE_OF_ARRAY(array)    (sizeof(array)/sizeof(array[0]))

int compareInt(const void* a, const void* b)
{
    int aNum = *(int*)a;
    int bNum = *(int*)b;

    return aNum - bNum;
}

/*
    最頻値を求める

    引数
        array: 対象の配列
        size:  array の要素数
    戻り値
        最頻値
*/
int get_mode(const int* array, size_t size)
{
    assert(array != NULL);
    assert(size > 0);

    // [!] 配列が昇順にソートされていることを前提にしている

    int mode;              // これまでに調べた中での最頻値
    int count_max = 0;     // これまでに調べた登場回数の中で最大のもの

    for (size_t i = 0; i < size; ) {

        int value = array[i];
        int count = 1;
    
        // ソートされているのだから、
        // 同じ値があるとすれば、後続に連続して並んでいるはず。
        // その回数をカウントする。
        for (i = i + 1; i < size; ++i) {
            if (value == array[i]) {
                ++count;
            }
            else {
                // 違う値が登場したら終わり
                break;
            }
        };

        // これまでの最大の登場回数よりも多かったら、更新する
        if (count_max < count) {
            count_max = count;
            mode = value;
        }
    }

    return count_max;
}


int main(){
	int n;
	scanf("%d", &n);
	int a[n * 3];
	rep(i, n) scanf("%d", &a[i]);
	rep(i, n) a[n + i] = a[i] + 1;
	rep(i, n) a[n * 2 + i] = a[i] - 1;
	
	qsort(a, SIZE_OF_ARRAY(a), sizeof(int), compareInt);
	int t = get_mode(a, SIZE_OF_ARRAY(a));
	
	printf("%d", t);
	
	return 0;
}



Measured memory_bytes: 2556
#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define con_input(v) for(auto it=v.begin();it!=v.end();it++){cin>>*it;}
#define con_debug(v) for(auto it=v.begin();it!=v.end();it++){cerr<<*it<<" ";}cerr<<endl;
using namespace std;
template <typename T>T digitsum(T n);
template <typename T>T gcd(T u,T v);
template <typename T>bool isPrime(T n);
template <typename T>vector<pair<T, T>> prime_factor(T n);

int main(){
    long long int n,ans=0,a;
    cin>>n;
    vector<pair<long long int, long long int>> sosu=prime_factor(n);
    rep(i,sosu.size()){
        a=1;
        while(sosu[i].second>=a){
            ans++;
            sosu[i].second-=a;
            a++;
        }
    }
    cout<<ans<<endl;
}

template <typename T>
T digitsum(T n){
    string s=to_string(n);
    T sum=0;
    T d=1;
    for(T e=0;e<s.length();e++){
        sum+=(n/d)%10;d*=10;
    }
    return sum;
}
template <typename T>
T gcd(T u,T v) {
    while ( v != 0) {
        T r = u % v;
        u = v;
        v = r;
    }
    return u;
}
template <typename T>
bool isPrime(T n){
    if(n<=1)return false;
    if(n==2)return true;
    if(n%2==0)return false;
    for(T q=3;q*q<=n;q+=2){
        if(n%q==0)return false;
    }
    return true;
}
template <typename T>
vector<pair<T, T>> prime_factor(T n) {
    vector<pair<T, T>> ret;
    if(n%2==0){
        T tmp = 0;
        while (n % 2 == 0) {
            tmp++;
            n /= 2;
        }
        ret.push_back(make_pair(2, tmp));
    }
    for (T i = 3; i*i <= n; i+=2) {
        if(n%i==0){
            T tmp = 0;
            while (n % i == 0) {
                tmp++;
                n /= i;
            }
            ret.push_back(make_pair( i, tmp));
        }
    }
    if (n != 1) ret.push_back(make_pair(n, 1));
    return ret;
}

Measured memory_bytes: 3636
import sys
sys.setrecursionlimit(10**7)

def dfs(st, depth=0):
    dist[st] = depth
    for to, c in tree[st]:
        if dist[to]>=0:
            continue
        dfs(to, depth+c)


N = int(input())
tree = [[] for _ in range(N)]
dist = [-1]*N

for _ in range(N-1):
    a,b,c = map(int, input().split())
    tree[a-1].append((b-1, c))
    tree[b-1].append((a-1, c))

Q, K = map(int, input().split())
dfs(K-1, 0)
# print(dist)
# print(tree)
for _ in range(Q):
    x, y = map(int, input().split())
    print(dist[x-1]+dist[y-1])

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

#define IOS cin.tie(0);ios_base::sync_with_stdio(false)

#define ll      long long
#define Fi      first
#define Se      second
#define Pb      push_back
#define vi      vector<int>
#define vs      vector<string>
#define vp      vector<pair<int,int>>
#define vvi     vector<vector<int>>
#define vvp     vector<vector<pair<int,int>>>
using Graph  =  vector<vector<int>>; //Caution!! Segmentation Fault!! Don't forget to add +1!

#define sz(x) (int)x.size()
#define all(v) v.begin(),v.end()
#define output_s(s) printf("%s\n",(s).c_str())

#define rep(i,n)        for(int i=0;i<(int)(n);i++)
#define Rep(i,n,m)      for(int i=(int)(n);i<(int)(m);i++)
#define RepS(i,n,m)     for(int i=(int)(n);i<=(int)(m);i++)
#define RRepS(i,n,m)    for(int i=(int)(n);i>=(int)(m);i--)
#define SRepS(i,n,m)    for(int i=(int)(n);i*i<=(int)(m);i++)
#define RepA(x)         for(auto &item:(x))

void CINT(){} //@shibh308's template
template<class Head,class... Tail> void CINT(Head&& head,Tail&&... tail){cin>>head; CINT(move(tail)...);}    
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)
#define VCIN(x) for(auto &item:x) cin>>item

void OUT(){}
template<class Head,class...Tail> void OUT(Head&& head,Tail&&...tail){cout<<head<<(sizeof...(tail)?" ":"\n"); OUT(move(tail)...);}
#define COUT(...) OUT(__VA_ARGS__)

template<typename TypeInt>TypeInt GCD(TypeInt a,TypeInt b){return a%b==0?b:GCD(b,a%b);} //最大公約数
template<typename TypeInt>TypeInt LCM(TypeInt a,TypeInt b){return a*b/GCD(a,b);} //最小公倍数
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return true;}return false;}
template<class T>bool comp(T a,T b){return abs(a)<abs(b);} //比較関数

void YES(bool f){printf(f?"YES\n":"NO\n");}
void Yes(bool f){printf(f?"Yes\n":"No\n");}
void Possible(bool f){printf(f?"Possible\n":"Impossible\n");}
void POSSIBLE(bool f){printf(f?"POSSIBLE\n":"IMPOSSIBLE\n");}

//----------------------library------------------------//

//const int dx[4]={1,0,-1,0};
//const int dy[4]={0,1,0,-1};
const int dx[8]={1,0,-1,0,1,-1,-1,1};
const int dy[8]={0,1,0,-1,1,1,-1,-1};
const int NMAX = 200;
const int INF = 1e9;
const int MOD = 1e9+7;
bool flag;

//----------------------Global-------------------------//

signed main(){
    CIN(N,M);
    int L=0,R=INF;
    rep(i,M){
        int l,r;
        cin>>l>>r;
        chmax(L,l);
        chmin(R,r);
    }
    int ans;
    if(R>=L)ans=R-L+1;
    else ans=0;
    printf("%d\n",ans);

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define all(x)     		(x).begin(),(x).end()
#define ub    			upper_bound
#define lb 				lower_bound
#define int 			long long
#define endl			'\n'
#define ff              first
#define ss              second
#define ull		unsigned long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define si 				set<int>		
#define mii             map<int,int>
#define umii			unordered_map<int ,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define rep(i,a,n)		for(int i=a;i<n;++i)
#define repd(i,a,n)		for(int i=a;i>n;--i)
#define setbits(x)      __builtin_popcountll(x)
#define zerobits(x)      __builtin_ctzll(x)
#define Mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define deb(x)			cout<<#x <<"="<<x<<endl;
#define deb2(x,y)		cout<<#x<<"="<<x<<"  "<<#y<<"="<<y<<endl;
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
int Pow(int a,int b){int res=1;while(b>0){if(b&1)res*=a;a*=a;b/=2;}return res;}
int MPow(int a,int  b){int res=1;while(b>0){if(b&1)res=(res*a)%Mod;a=(a*a)%Mod;b/=2;}return res%Mod;}
int log(int x){return 64-__builtin_clzll(x)-1;}



void c_p_p()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	//freopen("in.txt", "r", stdin);
	//freopen("out.txt", "w", stdout);
#endif
}
struct Node
{
	int a,b,c,d;
	
};

const int Max=1e5+1;
int Dp[Max];
int Frog(int A[], int n, int k, int i)
{
	if(i==n || i==n-1)
		return Dp[i]=abs(A[i]-A[n]);
	if(Dp[i]==inf)
	{
		rep(j,i+1,min(n+1,i+k+1))
		{
			Dp[i]=min(Dp[i],abs(A[i]-A[j])+Frog(A,n,k,j));
		}
		return Dp[i];

	}
	return Dp[i];
}

int32_t main()
{
	c_p_p();
	int n,k;
	cin>>n>>k;
	rep(i,1,n+1)
	Dp[i]=inf;
	int A[n+1];
	rep(i,1,n+1)
	cin>>A[i];
	cout<<Frog(A,n,k,1);
	return 0;
}
	

Measured memory_bytes: 14560
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < n; i++)
#define int long long
signed main(signed argc, char* argv[]) {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int n;
	cin>>n;
	int before=1e9+7,ans=0;
	rep(i,n){
	    int in;
	    cin>>in;
	    if(before>=in)ans++;
	    before=in;
	}
	cout<<ans<<endl<<n<<endl;
}



Measured memory_bytes: 3216
import java.util.Arrays;
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int[] a = new int[3];
		for (int i = 0; i < 3; i++)
			a[i] = Integer.parseInt(sc.next());
		int c = 0;
		while (true) {
			Arrays.sort(a);
			if (a[0] == a[1] && a[1] == a[2])
				break;
			else if (a[1] == a[2])
				a[0] += 2;
			else {
				a[0]++;
				a[1]++;
			}
			c++;
		}
		System.out.println(c);
	}
}

Measured memory_bytes: 23124
#include <bits/stdc++.h>
using namespace std;
int n, m;
int ans = 0;
pair<int, int>a[100010];
priority_queue<int> q;
int main(){
    int i, j, k;
    cin >> n >> m;
    for(i = 1; i <= n; ++i){
        scanf("%d%d",&a[i].first, &a[i].second);
    }
    sort(a+1, a+1+n);
    int l = 1;
    for(i = m; i >= 1; --i){
        while(l <= n && a[l].first+i-1 <= m)
            q.push(a[l++].second);
        	if(!q.empty()){
			ans+=q.top();
			q.pop();
		}
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1660
N, K = map(int, input().split())
ans = 0
extra = [0]*K
for i in range(1, N+1): extra[i%K] += 1 #extra[X] = Kで割ってXあまる数がN以下に何個あるか

for a in range(K):
    b = (K-a) % K
    c = (K-a) % K

    if (b + c) % K == 0:
        ans += extra[a] * extra[b] * extra[c]
print(ans)


Measured memory_bytes: 66868
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
const int inf = 1e9 + 7;
const ll INF = 1e18;
int mod = 1000000007;
#define abs(x) (x >= 0 ? x : -(x))
#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())
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<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
template<typename T> T pow(T a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
ll modpow(ll a, ll b, ll _mod) { return b ? modpow(a * a % _mod, b / 2, _mod) * (b % 2 ? a : 1) % _mod : 1; }
template<class T> ostream& operator << (ostream& os, const vector<T>& vec) { for (auto &vi: vec) os << vi << " "; return os; }
template<class T, class U> ostream& operator << (ostream& os, const pair<T, U>& p) { os << p.F << " " << p.S; return os; }
template<typename T >inline istream& operator >> (istream& is, vector<T>& v) { rep(j, sz(v)) is >> v[j]; return is; }
template<class T> inline void add(T &a, int b) { a += b; if (a >= mod) a -= mod; }


void solve();

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

  int T;
  // cin >> T;
  T = 1;

  while (T--) {
    solve();
  }
}

void solve() {
  int n, s;
  cin >> n >> s;
  vector<int> a(n);
  cin >> a;

  int mod2 = 998244353;
  vector<vector<int> > dp(n + 1, vector<int>(s + 1));
  dp[0][0] = 1;
  rep(i, n) {
    dp[i + 1] = dp[i];
    dp[i + 1][0]++;
    rep(j, s + 1) {
      if (j + a[i] <= s) (dp[i + 1][j + a[i]] += dp[i][j]) %= mod2;
    }
  }
  int ans = 0;
  rep(i, n + 1) (ans += dp[i][s]) %= mod2;
  cout << ans << endl;
}


Measured memory_bytes: 35584
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bits/stdc++.h>
#include<cmath>
#include<bitset>
#include<queue>
#define ll long long
#define itn int
#define co(ans) cout<<ans<<endl;
#define COYE cout<<"YES"<<endl;
#define COYe cout<<"Yes"<<endl;
#define COye cout<<"yes"<<endl;
#define CONO cout<<"NO"<<endl;
#define CONo cout<<"No"<<endl;
#define COno cout<<"no"<<endl;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n)  FFOR(i,1,n)
#define SORT(V) sort((V).begin(),(V).end())
#define REVERSE(V) reverse((V).begin(),(V).end())
#define INF ((1LL<<62)-(1LL<<31))
#define MOD 1000000007
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
using namespace std;


int main(){
  int N,ans=1;
  cin>>N;
  
  vector<pair<int,int>> L;
  REP(i,N){
    int a,b;
    cin>>a>>b;
    L.push_back(make_pair(a+b,a-b));
  }
  
  SORT(L);
  int t=L[0].first;
  
  for(int i=1; i<N; ++i){
    if(L[i].second>=t){
      t=L[i].first;
      ans++;
    }
  }
  
  co(ans);
  return 0;
}

Measured memory_bytes: 1400
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
#include<iomanip>

#define fast_io ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

using namespace std;

#define debug(x) cout<<(#x)<<"="<<(x)<<", ";
#define debug1(x) debug(x) cout<<'\n';
#define debug2(x1, x2) debug(x1) debug(x2) cout<<'\n';
#define debug3(x1, x2, x3) debug(x1) debug(x2) debug(x3) cout<<'\n';
#define debug4(x1, x2, x3, x4) debug(x1) debug(x2) debug(x3) debug(x4) cout<<'\n';
#define debug5(x1, x2, x3, x4, x5) debug(x1) debug(x2) debug(x3) debug(x4) debug(x5) cout<<'\n';

#define fcout cout<<fixed<<setprecision(15)
#define repp(i,j,k) for(int i=j; i<k; ++i)
#define rep(i,j) repp(i,0,j)
#define rrep(i,j,k) for(int i=j; i>=k; --i)
#define all(x) (x).begin(), (x).end()
#define sort(x) sort(x.begin(), x.end())
#define lb(x,val) lower_bound(x.begin(), x.end(), val)
#define ub(x,val) upper_bound(x.begin(), x.end(), val)
#define pb(x) emplace_back(x);

typedef long long int lli;
typedef pair<int,int> pii;
typedef pair<lli,lli> pll;
typedef vector<int> vi;
typedef vector<lli> vl;
typedef tuple<int, int, lli> tiil;

//const lli M=998244353ll;
const lli M=1000000007ll;
const double D=1.0;

int main(){
fast_io
string s; cin>>s;
if(s[0]==s[2])cout<<"Yes";
else cout<<"No";
 return 0;
}

Measured memory_bytes: 256
n = int(input())
s = list(input())
w = [0 for _ in range(n+1)]
e = [0 for _ in range(n+1)]

for i in range(n):
    if s[i] == "W":
        w[i+1] = w[i]+1
        e[i+1] = e[i]
    else:
        e[i+1] = e[i]+1
        w[i+1] = w[i]
# print(w)
# print(e)
ans = float('inf')
for i in range(n):
    a = w[i+1]
    b = e[n] - e[i+1]
    if s[i] == 'W':
        a-=1

    ans = min(ans,a+b)
    # print(ans,a,b)

print(ans)

Measured memory_bytes: 25828
#!/usr/bin/env python3
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1

s = input()
if s == "ABC":
  print("ARC")
else:
  print("ABC")

Measured memory_bytes: 65496
fn main() {
    let s = std::io::stdin();
    let mut sc = Scanner { stdin: s.lock() };
    let a: usize = sc.read();
    let b: usize = sc.read();
    let c = a - 1;
    let d = b - 1;
    let ans = (d + c - 1) / c;
    println!("{}", ans);
}

pub struct Scanner<R> {
    stdin: R,
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n')
            .take_while(|&b| b != b' ' && b != b'\n')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


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

#define pb push_back
#define loop(i,l,r) for(int i = (l); i < (r); i++)
#define rloop(i,r,l) for(int i = (r-1); i >= (l); i--)
#define refloop(x, v) for(auto& x : (v))
#define exists(m,e) if((m).find(e) != (m).end())
#define nexists(m,e) if((m).find(e) == (m).end())
#define sortaka(v) sort((v).begin(), (v).end())
#define rsort(v) sort((v).rbegin(), (v).rend())
#define lower_bound_index(v, x) (lower_bound((v).begin(), (v).end(), x)-(v).begin()) // returns minimum i s.t v[i] >= x
#define upper_bound_index(v, x) (upper_bound((v).begin(), (v).end(), x)-(v).begin()) // returns minimum i s.t v[i] > x
#define scanint(x) scanf("%d", &(x))
#define scanfloat(x) scanf("%f", &(x))
#define scanll(x) scanf("%lld", &(x))
#define scanchar(x) scanf("%c", &(x))
#define scanstring(x) scanf("%s", &(x))
#define printint(x) printf("%d", x)
#define printfloat(x) printf("%.9f", x)
#define printll(x) printf("%lld", x)
#define printchar(x) printf("%c", x)
#define printstring(x) printf("%s", x)
#define printintnewline(x) printf("%d\n", x)
#define printfloatnewline(x) printf("%.9f\n", x)
#define printllnewline(x) printf("%lld\n", x)
#define printcharnewline(x) printf("%c\n", x)
#define printstringnewline(x) printf("%s\n", x)
#define square(x) ((x)*(x))
#define cube(x) ((x)*(x)*(x))

typedef vector<int> vi;
typedef vector<long long> vl;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef vector<pair<int, int>> vpii;
typedef vector<pair<long long, long long>> vpll;
typedef vector<vector<int>> vvi;
typedef vector<vector<long long>> vvl;
typedef vector<string> vs;
typedef vector<vector<pair<int, int>>> vvpii;
typedef vector<vector<pair<long long, long long>>> vvpll;
typedef map<int,int> mii;
typedef map<string,int> msi;
typedef long long ll;

int main(){
    ios::sync_with_stdio(0);

    static const int N = 1000001;
    vector<ll>numdiv(N);
    loop(i, 1, N){
        for(int j = i; j < N; j+=i){
            numdiv[j]++;
        }
    }

    ll ans = 0;
    int n; cin >> n;
    loop(i, 1, n){
        ans += numdiv[n-i];
    }
    cout<<ans<<endl;
}

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

const int inf = 0x3f3f3f3f;

int main(){
    int N;
    cin >> N;
    
    int x,l;
    vector<pair<int,int>> p(N);
    for(int i=0;i<N;i++){
        cin >> x >> l;
        p.at(i)={x+l,x-l};
    }

    sort(p.begin(),p.end());
    
    int ans=0;
    int boundary=-inf;
    for(int i=0;i<N;i++){
        if(p.at(i).second>=boundary){
            boundary=p.at(i).first;
            ans++;
        }
    }

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

Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
int n,f0,s0;
const int maxn=100005;
vector<int> v[maxn];
int f[maxn],s[maxn];
//bool f0[maxn],s0[maxn];
void bfs(int x,int a[])
{
	queue<int> q;
	q.push(x);
	a[x]=0;
	while(!q.empty())
	{
		int t=q.front();
		q.pop();
		for(int i=0;i<v[t].size();i++)
		{
			int d=v[t][i];
			if(a[d]>a[t]+1)
			{
			a[d]=a[t]+1;
			q.push(d);
		    } 
		}
	}
}
int main()
{
	cin>>n;
	for(int i=1;i<n;i++)
	{
		int x,y;
		cin>>x>>y;
		v[x].push_back(y);
		v[y].push_back(x);
	}
	for(int i=1;i<=n;i++)
	f[i]=s[i]=maxn;
	bfs(1,f);
	bfs(n,s);
	for(int i=1;i<=n;i++)
	{
		if(f[i]<=s[i])
		f0++;
		else s0++;
	}
	if(f0>s0)
	puts("Fennec");
	else puts("Snuke");
	return 0;
}

Measured memory_bytes: 6656
#include <cstdio>
#include <cmath>
#include <iostream>
#include <set>
#include <algorithm>
#include <vector>
#include <map>
#include <cassert>
#include <string>
#include <cstring>
#include <queue>

using namespace std;

#define rep(i,a,b) for(int i = a; i < b; i++)
#define S(x) scanf("%d",&x)
#define S2(x,y) scanf("%d%d",&x,&y)
#define P(x) printf("%d\n",x)
#define all(v) v.begin(),v.end()
#define FF first
#define SS second
#define pb push_back
#define mp make_pair

typedef long long int LL;
typedef pair<int, int > pii;
typedef vector<int > vi;

int A[200005];

int main() {
  int n;
  S(n);
  LL tot = 0;
  rep(i,1,n+1) {
    S(A[i]);
    tot += A[i];
  }

  LL sum = 0;
  LL ans = 2e15;
  rep(i,1,n) {
    sum += A[i];
    ans = min(ans, (LL)abs(sum - tot + sum));
  }
  cout << ans << "\n";
  return 0;
}

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

using namespace std;

const int M = 1e5 + 5;
int n, k, vis[M], ans, dp[M];
vector <int> adj[M], g[M], lf;

int dfs (int u) {
    int &ret = dp[u];
    if (ret != -1) return ret;
    ret = 1;
    for (int i : adj[u]) {
        ret = max (ret, dfs(i)+1);
    }
    return ret;
}

int main () {
    scanf("%d %d", &n, &k);
    while (k--) {
        int x, y;
        cin >> x >> y;
        adj[x].push_back (y);
    }
    memset (dp, -1, sizeof dp);
    for (int i = 1; i <= n; i++) {
        ans = max (ans, dfs(i));
    }
    cout << ans-1;
}
 

Measured memory_bytes: 9856
import sys

group = [None, 0, 2, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0]

x, y = map(int, sys.stdin.readline().split())

def main():
    ans = 'Yes' if group[x] == group[y] else 'No'
    print(ans)

if __name__ ==  '__main__':
    main()

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

using namespace std;

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

    vector<int> v_i(n);
    for (int i = 0; i < n; i++)
        cin >> v_i.at(i);
    
    sort(v_i.begin(), v_i.end());

    double v = v_i.at(0);
    for (int i = 0; i < n - 1; i++)
        v = (v + v_i.at(i + 1)) / 2;

    cout << v << endl;
}

Measured memory_bytes: 3756
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		// 読み込み
		Scanner sc = new Scanner(System.in);
		int X = sc.nextInt();
		int Y = sc.nextInt();
	
		double t = (4*X -Y)/2;
		double k = X - t;
		double ashi_k = (Y - 2 * t)/4; 
		if(t >= 0 && t == (int)t && k == (int)k && ashi_k == (int)ashi_k && k >= 0) {
			System.out.println("Yes");
		}
		else {
			System.out.println("No");;
		}
	}
}

Measured memory_bytes: 27048
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		String line = sc.nextLine();

		int n = Integer.parseInt(line);

		System.out
				.println(n / 3600 + ":" + n % 3600 / 60 + ":" + n % 3600 % 60);

	}

}



Measured memory_bytes: 26144
n, a, b, c = map(int, input().split(' '))
l = []
for i in range(n):
  l.append(int(input()))
  
def func(k, x, y, z):
  if k == n:
    if not x or not y or not z:
      return 10**9
    else:
      return abs(x-a) + abs(y-b) + abs(z-c) - 30
  else:
    p = func(k+1, x, y, z)
    q = func(k+1, x + l[k], y, z) + 10
    r = func(k+1, x, y + l[k], z) + 10
    s = func(k+1, x, y, z + l[k]) + 10
    return min(p, q, r, s)

print(func(0, 0, 0, 0))

Measured memory_bytes: 3064