akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <string>
#include <math.h>
using namespace std;
int main() {
  	int zero_c =0;
	long long N;
  long long result=0;
	long long a[5] = {0,0,0,0,0};
  	string tmp;
  long long tmp2=1;
  	cin >> N;
  	for(int i=0;i<N;i++){
      cin >> tmp;

      if(tmp.substr( 0, 1 )=="M"){
        a[0]++;
      }else if(tmp.substr( 0, 1 )=="A"){
        a[1]++;
      }else if(tmp.substr( 0, 1 )=="R"){
        a[2]++;
      }else if(tmp.substr( 0, 1 )=="C"){
        a[3]++;
      }else if(tmp.substr( 0, 1 )=="H"){
        a[4]++;
      }
    }
  
  	for(int i=0;i<5;i++){
      if(a[i]==0){
        zero_c++;
      }
    }
 	if(zero_c>=3){
      cout << 0 << endl;
      return 0;
    }
  
  	for(int i1=0;i1<2;i1++){
      for(int i2=0;i2<2;i2++){
        for(int i3=0;i3<2;i3++){
          for(int i4=0;i4<2;i4++){
            for(int i5=0;i5<2;i5++){
              if(i1+i2+i3+i4+i5==3){
                if(i1==1){
                  tmp2*=a[0];
                }
                if(i2==1){
                  tmp2*=a[1];
                }
                if(i3==1){
                  tmp2*=a[2];
                }
                if(i4==1){
                  tmp2*=a[3];
                }
                if(i5==1){
                  tmp2*=a[4];
                }
                result+=tmp2;
                tmp2=1;
              }
            }
          }
        }
      }
    }
  	
  
  	cout << result << endl;
	return 0;
}


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

using namespace std;

int main() {
    int n;
    cin>>n;
    int arr[n];
    for(int i=0;i<n;i++)
        cin>>arr[i];
    int dp[n+1];
    memset(dp,INT_MAX,sizeof(dp));
    dp[0]=0;
    dp[1]=0;
    for(int i=2;i<=n;i++)
        dp[i] = min(abs(arr[i-1]-arr[i-2])+dp[i-1], abs(arr[i-1]-arr[i-3])+dp[i-2]);
    cout<<dp[n]<<"\n";
}

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

int main(){
  int H, N;
  cin >> H >> N;
  
  priority_queue<int> A;
  for(int i = 0; i < N; i++){
    int a;
    cin >> a;
    A.push(a);
  }
  
  for(int i = 0; i < N; i++){
    H -= A.top();
    A.pop();
  }
  
  if(H <= 0){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
  
}

Measured memory_bytes: 892
#include<cstdio>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#define IOS ios::sync_with_stdio(false),cin.tie(0)
#define REP(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;

vector<int> A;
int N, P;
ll ans;

int main() {
	IOS;
	int t;
	bool a = true;
	cin >> N >> P;
	REP(i, N) {
		cin >> t;
		if (t % 2 == 1)a = false;
	}
	if (a) {
		if (P == 1)ans = 0;
		else ans = pow(2, N);
	}
	else {
		ans = pow(2, N - 1);
	}
	cout << ans << endl;
}


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

using namespace std;

int main(void){
  long long X, Y, Z, W;
  long long S;
  cin >> S;
  X = 1000000000LL;
  W = (S + X - 1LL) / X;
  Y = X * W - S;
  Z = 1LL;
  cout << 0 << " " << 0 << " " << X << " " << Y << " " << Z << " " << W << endl;
  return 0;
}


Measured memory_bytes: 3656
#include <bits/stdc++.h>
using namespace std;
#define NDEBUG
#include <cassert>
 
// ------------------------------------------------------------------------------------------
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
int a, b, c;
int mx, mn;
// vector<int> X;
signed main() {
  cin >> a >> b >> c;
  mx = b;
  mn = a;
  if (a > b) {
      mx = a;
      mn = b;
  }
  while (c > 0) {
    if (a % mn == 0 && b % mn == 0) {
            c = c - 1;
    }
    mn = mn - 1;
  }
  cout << mn+1 << endl;
 
  return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
using P	  = pair<ll, ll>;
using mat = vector<vector<ll>>;
typedef string::const_iterator State;
class ParseError {};

void IOS() { ios::sync_with_stdio(false), cin.tie(0); }

constexpr ll INF = 1e16;
constexpr ll INM = 114514;
constexpr ll MOD = 1e9 + 7;
constexpr ld EPS = 1e-12;

template <typename T>
void dump(T x) { cout << x << endl; }
void dumpf(ld x, int t) { cout << setprecision(t) << fixed << x << endl; }
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
	fill((T *)array, (T *)(array + N), val);
}
inline ll mod(ll a, ll b) {
	if (a > 0) return a % b;
	if (a % b == 0) return 0;
	ll x = -a / b + 1;
	a += x * b;
	return a % b;
}
ll powm(ll a, ll b, ll c) {
	if (b == 0)
		return 1;
	else if (b % 2 == 0) {
		ll d = powm(a, b / 2, c);
		return (d * d) % c;
	} else
		return (a * powm(a, b - 1, c)) % c;
}
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll dx[4] = {1, 0, -1, 0};
ll dy[4] = {0, 1, 0, -1};

int main() {
	IOS();
	string s;
	ll k;
	cin >> s >> k;
	int n = s.size();
	vector<ll> ans;
	ll cnt = 1;
	for (int i = 1; i <= n; i++) {
		while (i < n && s[i] == s[i - 1]) {
			i++;
			cnt++;
		}
		ans.push_back(cnt);
		cnt = 1;
	}	
	ll res = 0;
	for (int i = 1; i < ans.size() - 1; i++) {
		res += ans[i] / 2 * k;
	}
	if (ans.size() == 1) {
		res = ans[0] * k / 2;
	} else if (s[0] != s[n - 1]) {
		res += ans[0] / 2 * k;
		res += ans[ans.size() - 1] / 2 * k;
	} else {
		res += ans[0] / 2;
		res += ans[ans.size() - 1] / 2;
		res += (ans[0] + ans[ans.size() - 1]) / 2 * (k - 1);
	}
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
class Main{
    public static void main(String[] args) {
        Scanner scn=new Scanner(System.in);
        int  x=scn.nextInt();
        int  y=scn.nextInt();
        int  z=scn.nextInt();
        scn.close();
        int answer =0;
        while(true){
            if(answer==0){
                if(y+2*z>x)break;
                answer++;
                x-=y+2*z;
            }else{
                if(y+z>x)break;
                answer++;
                x-=y+z;
            }
        }
        System.out.println(answer);
    }
}

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int n;
  cin >> n;
  
  int l = 1, r = n - 1;
  string ls, rs;
  
  cout << 1 << endl;
  cin >> ls;
  if (ls == "Vacant") return 0;
  
  cout << n - 1 << endl;
  cin >> rs;
  if (rs == "Vacant") return 0;
  
  if (ls != rs) {
    cout << 0 << endl;
    string s;
    cin >> s;
    return 0;
  }
  
  while (true) {
    int mid = (l + r) / 2;
    cout << mid << endl;
    string ms;
    cin >> ms;
    if (ms == "Vacant") return 0;
    if ((mid - l) % 2 == 0 && ms != ls) {
      r = mid;
      rs = ms;
    }
    else if ((mid - l) % 2 == 1 && ms == ls) {
      r = mid;
      rs = ms;
    }
    else if ((r - mid) % 2 == 0 && ms != rs) {
      l = mid;
      ls = ms;
    }
    else if ((r - mid) % 2 == 1 && ms == rs) {
      l = mid;
      ls = ms;
    }
  }
}

Measured memory_bytes: 852
#include <bits/stdc++.h>
#define pi 3.14159
using namespace std;

int main()
 {
 	int a,b,c;
 	cin>>a>>b;
 	c=6-(a+b);
 	cout<<c<<endl;
 	
 	
	 	
 	return 0;
}
 	
 					

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

using namespace std;

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> A(M);
  int sum = 0;
  for(int i = 0; i < M; i++) {
    cin >> A.at(i);
    sum += A.at(i);
  }
  if(N - sum > -1) cout << N - sum << endl;
  else cout << -1 << endl;
}




Measured memory_bytes: 3672
#include <iostream>
#include <sstream>
using namespace std;
bool isPalindrome(int n)
{
  stringstream ss;
  ss << n;
  string str;
  ss >> str;
  for(int i=0,j=str.length()-1; i<j; i++,j--){
    if(str[i] != str[j]) return false;
  }
  return true;
}
int main()
{
  int n;
  cin >> n;
  if(isPalindrome(n)){
    cout << n << endl;
    return 0;
  }
  int i=0; 
  for(;;){
    if(n > i && isPalindrome(n-i)){
      cout << n-i << endl;
      break;
    }
    if(isPalindrome(n+i)){
      cout << n+i << endl;
      break;
    }
    i++;
  }
  return 0;
}

Measured memory_bytes: 1220
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int comp(const void *a, const void *b)
{
	return *(int *)a > *(int *)b;
}

ll findNumberOfTriangles(ll arr[], ll n)
{

	qsort(arr, n, sizeof(arr[0]), comp);

	ll count = 0;

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

		int k = i + 2;

		for (int j = i + 1; j < n; ++j)
		{
			while (k < n && arr[i] + arr[j] > arr[k])
				++k;

			if (k > j)
				count += k - j - 1;
		}
	}

	return count;
}

// Driver code
int main()
{
	long long n;
	cin >> n;
	long long a[n];
	for (int i = 0; i < n; i++)
		cin >> a[i];

	cout << findNumberOfTriangles(a, n);

	return 0;
}


Measured memory_bytes: 256
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include<set>
#include<map>
using namespace std;


int main() {
    int a, b;
    cin >> a >> b;
    if(a%500 <= b){
    cout << "Yes";
    }
    else
    {
        cout << "No";
    }
    cout << endl;
}


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

int main(void){
  int A,B,max;
  char str[100],*p;
  
  fgets(str,sizeof(str),stdin);
  p=strtok(str," \n");
  A=atoi(p);
  p=strtok(NULL," \n");
  B=atoi(p);
  
  max=A+B;
  if(max<A-B){
    max=A-B;
  }
  if(max<A*B){
    max=A*B;
  }
  
  printf("%d\n",max);
  
  return 0;
}

Measured memory_bytes: 128
#!/usr/bin python3
# -*- coding: utf-8 -*-
# https://atcoder.jp/contests/atc001/tasks/unionfind_a

class UnionFind():
    def __init__(self, n):                      #初期化
        self.n = n                              # 要素数
        self.parents = [i for i in range(n)]    # 親
        self.ranks = [0] * n                    # 木の深さ
        self.sizes = [1] * n                    # グループの要素数

    def find(self, x):              # 親を出力
        if self.parents[x] == x:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def unite(self, x, y):          # ユニオン
        x = self.find(x)
        y = self.find(y)
        if x == y: return
        if self.ranks[x] > self.ranks[y]:
            x , y = y, x    #yを親にする
        if self.ranks[x] == self.ranks[y]:
                self.ranks[y] += 1
        self.parents[x] = y
        self.sizes[y] += self.sizes[x]

    def same(self, x, y):       #xとyが同じグループかどうか
        return self.find(x) == self.find(y)

    def members(self, x):       #xと同じグループの要素
        root = self.find(x)
        return {i for i in range(self.n) if self.find(i) == root}

    def size(self, x):          #グループの要素数
        return self.sizes[self.find(x)]

    def roots(self):            #親の要素一覧
        return {i for i, x in enumerate(self.parents) if i == x}

    def group_count(self):      #グループの個数
        return len(self.roots())

    def all_group_members(self):      #グループのメンバー一覧
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

################

n, q = map(int, input().split())
uf = UnionFind(n)
for _ in range(q):
    t, a,b = map(int,input().split())
    if t == 0:
        uf.unite(a-1, b-1)
    else:
        print(int(uf.same(a-1,b-1)))


Measured memory_bytes: 19744
MOD = 10**9 + 7
def solve(A):
    N = len(A)
    dp = [1] + [0] * 12
    pwr = 1
    for i in xrange(N-1, -1, -1):
        if A[i] == '?':
            dp2 = [0] * 13
            for k, v in enumerate(dp):
                for d in xrange(10):
                    k2 = (k + d * pwr) % 13
                    dp2[k2] += v
                    dp2[k2] %= MOD
            dp = dp2
        else:
            shift = int(A[i]) * pwr % 13
            dp2 = [0] * 13
            for k, v in enumerate(dp):
                k2 = (k + shift) % 13
                dp2[k2] += v
            dp = dp2
        pwr *= 10
        pwr %= 13
    
    return dp[5] % MOD
        
print solve(raw_input().rstrip())


Measured memory_bytes: 33512
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <queue>
#include <vector>
using namespace std;

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

int main() {
	double n;
	scanf("%lf", &n);
	int ans = 1;
	while (1) {
		if (n <= 3)break;
		n /= 3;
		ans++;
	}
	printf("%d\n",ans);
	return 0;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;

const int inf = numeric_limits<int>::max() /4;
const ll linf = numeric_limits<ll>::max() /4;
const ull ulinf = numeric_limits<ull>::max()/4;
const double pi = acos(-1);
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int dx8[8]={-1,0,1,-1,1,-1,0,1};
const int dy8[8]={-1,-1,-1,0,0,1,1,1};

#define p_queue(i) priority_queue<i> 
#define rp_queue(i) priority_queue<i, vector<i>, greater<i>> 
#define P(p) cout<<(p)<<endl
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define mod(i) ((i)%(ll)(1e9 + 7))
#define divm(a,b) (mod(a * modpow((ll)b,(ll)(1e9+5))))
#define rsort(a,b,c) sort(a, b, greater<c>())
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v) sort(v.end(), v.begin());
#define ft first
#define sd second
#define pb push_back
#define it insert
#define sz(x) ((int)(x).size())
#define lb(a,n,k) (lower_bound(a,a+n,k) - a) 
#define vlb(a,k)  (lower_bound(a.begin(),a.end(),k) - a.begin())
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return

ll modpow(ll i,ll j){ ll tmp=1; while(j){ if(j%2)tmp=mod(tmp*i);i=mod(i*i);j/=2;}return tmp;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

//ll ncr[100][100];
//ll nCr(int n, int r){if(n==r) ret ncr[n][r] = 1; if(r==0) ret ncr[n][r] = 1; if(r==1) ret ncr[n][r] = n;if(ncr[n][r]) ret ncr[n][r]; ret ncr[n][r] = nCr(n-1,r) + nCr(n-1,r-1);}

//ll npr[100][100]={};
//ll nPr(int n,int r){if(npr[n][r])ret npr[n][r];if(r==0)ret npr[n][r] = 1;if(r==1)ret npr[n][r] = n;ret npr[n][r] = n * nPr(n-1,r-1);}

//ll nHr(int n,int r){ret nCr(n+r-1,r);}

///////////////////////////////////////////////////////////////////////////

int a[100005] = {},b[100005] = {},c[100005] = {};

int main(){
	int n;
	cin >> n;
	rep(i,0,n)cin >> a[i];
    rep(i,0,n)cin >> b[i];
    rep(i,0,n)cin >> c[i];

    sort(a,a+n);
    sort(b,b+n);
    sort(c,c+n);
    
    ll ans = 0;
    
    rep(i,0,n){
        ll aa = lb(a,n,b[i]);
        ll cc = n - (upper_bound(c, c+n, b[i]) - c);
        
        ans += aa * cc;  
    }
    P(ans);
	return  0;
}

Measured memory_bytes: 1536
#include<bits/stdc++.h>
#define ll long long
#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define dump(a) (cerr << #a << "=" << (a) << endl)
#define DUMP(list) cout << "{ "; for(auto nth : list){ cout << nth << " "; } cout << "}" << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

const int INF = 1001001001;
using namespace std;

int main(){
    int n, m, l;
    cin >> n >> m >> l;
    vector<vector<int>> dist(n, vector<int>(n, INF));
    rep(i, n) dist[i][i] = 0;
    rep(i, m) {
        int a, b, c;
        cin >> a >> b >> c;
        --a; --b;
        dist[a][b] = dist[b][a] = c;
    }
    rep(k, n)rep(i, n) rep(j, n) chmin(dist[i][j], dist[i][k] + dist[k][j]);
    vector<vector<int>> dist2(n, vector<int>(n, INF));
    rep(i, n) rep(j, n) {
        if (dist[i][j] <= l) dist2[i][j] = 1;
    }
    rep(k, n)rep(i, n) rep(j, n) chmin(dist2[i][j], dist2[i][k] + dist2[k][j]);
    int q;
    cin >> q;
    rep(qi, q) {
        int s, t;
        cin >> s >> t;
        --s; --t;
        int ans = dist2[s][t]-1;
        if (dist2[s][t] == INF) ans = -1;
        cout << ans << endl;
    }
}

Measured memory_bytes: 1280
N = int(input())
A = list(map(int,input().split()))
c = 0
if N%2 == 0:
    for i in range(N//2):
        c += A[2*i+1]
    cm = c
    # print(c)
    for i in range(N//2):
        # print(2*i,2*i+1)
        c += A[2*i]-A[2*i+1]
        cm = max(c,cm)
    print(cm)
else:
    dp = [[0]*(3) for _ in range(N//2)]
    # print(dp)
    # 初期化
    dp[0][0] = A[0]
    dp[0][1] = A[1]
    dp[0][2] = A[2]
    for i in range(0,N//2-1):
        dp[i+1][0] = dp[i][0] + A[2*i+2]
        dp[i+1][1] = max(dp[i][0] + A[2*i+3], dp[i][1] + A[2*i+3])
        dp[i+1][2] = max(dp[i][0] + A[2*i+4], dp[i][1] + A[2*i+4], dp[i][2] + A[2*i+4])
    # print(dp)
    print(max(dp[N//2-1][0],dp[N//2-1][1],dp[N//2-1][2]))


Measured memory_bytes: 42776
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <vector>
#include <iostream>

int main(void) {
  int n, i, ans = 0;
  scanf("%d", &n);
  std::vector <std::pair<int, int> > p1, p2;
  std::vector <std::pair<int, int> >::iterator it;
  for(i = 0; i < n; ++i) {
    int a, b;
    scanf("%d%d", &a, &b);
    std::pair<int, int> p = std::make_pair(a, b); 
    p1.push_back(p);
  }
  for(i = 0; i < n; ++i) {
    int a, b;
    scanf("%d%d", &a, &b);
    std::pair<int, int> p = std::make_pair(a, b); 
    p2.push_back(p);
  }
  std::sort(p1.begin(), p1.end());
  std::sort(p2.begin(), p2.end());
  for(i = 0; i < n; ++i) {
    int max = -1;
    std::vector <std::pair<int, int> >::iterator maxn;
    for(it = p1.begin(); it != p1.end(); ++it) {
      if((*it).first < p2[i].first && (*it).second < p2[i].second && (*it).second > max) max = (*it).second, maxn = it;
    }
    if(max != -1) {
      p1.erase(maxn), ++ans;
      //std::cout << i << "," << maxn - p1.begin() << "\n";
    }
  }
  printf("%d", ans);
  return 0;
}

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


int main() {
    int x,y,z;
	cin >> x>> y>> z;
    string ans;
    if((y*10+z)%4==0)ans="YES";
    else ans = "NO";
      cout << ans << endl;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
    static int[][] m;
    static int[] p;
    static int n;

    public static void main(String[] args) throws IOException {
        BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
        n = Integer.parseInt(bf.readLine());
        p = new int[n+1];
        m = new int[n + 1][n + 1];
        for (int i = 0; i < n; i++) {
            String[] s = bf.readLine().split(" ");
            p[i] = Integer.parseInt(s[0]);
            p[i + 1] = Integer.parseInt(s[1]);
        }
        System.out.println(matrixChainMultiplication());
    }

    private static int matrixChainMultiplication() {
        for (int l = 2; l <= n; l++) {
            ////1~5
            for (int i = 1; i <= n-l+1; i++) {
                //1~5+2-1
                int j=i+l-1;
                m[i][j]=Integer.MAX_VALUE;
                //5~6
                for (int k = i; k < j; k++) {
                    m[i][j] = Math.min(m[i][j],m[i][k]+m[k+1][j]+p[i-1]*p[k]*p[j]);
                }
            }
        }
        return m[1][n];
    }
}


Measured memory_bytes: 24800
import sys
def input(): return sys.stdin.readline().strip()

class UnionFind():
    """
    https://note.nkmk.me/python-union-find/
    DFSの上位互換と考えて良い
    ２要素x, yがpath-connectedかどうかをほぼ定数オーダーで判定する（螺旋本の14.1節参照）
    さらに連結成分の要素数がO(1)で取得可能なように改造してある
    """
    def __init__(self, n):
        """
        要素数をnとして、各ノードを0,1,...,(n-1)の番号で管理する
        parentsは各ノードの属する木の根を表す
        ただし根ノードのparentには(その木のノード数)*(-1)を格納する
        """
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        """
        xの属する木の根を返す
        このとき同時に経路圧縮して、探索途中のノードを全て根に繋ぎ直す
        """
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        """
        x, yのそれぞれ属する木Tx, Tyの根同士を繋ぐ
        このとき木の要素数が小さい方を大きい方に繋ぐ（rankではなくsizeを用いる）
        """
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        """
        xの属する木の要素数を返す
        根の親を要素数の(-1)倍で定めておいたおかげでO(1)で取得可能
        """
        return -self.parents[self.find(x)]

    def same(self, x, y):
        """
        xとyがpath-connectedかを判定する
        """
        return self.find(x) == self.find(y)

    def members(self, x):
        """
        xの属する木の要素を列挙する
        """
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        """
        連結成分の代表元のリストを返す
        """
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        """
        連結成分の個数を返す
        """
        return len(self.roots())

    def all_group_members(self):
         """
         連結成分およびそれぞれの代表元をまとめた辞書を返す
         代表元がキーになってる
         """
         return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        """
        連結成分およびその代表元を出力
        """
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


def main():
    n, m = map(int, input().split())
    tree = UnionFind(n)
    for _ in range(m):
        a, b = map(int, input().split())
        tree.union(a - 1, b - 1)
    print(tree.group_count() - 1)

if __name__ == "__main__":
    main()


Measured memory_bytes: 12932
#include <iostream>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>
#include <queue>
#include <cmath>

using namespace std;

int main() {
    int n;
    int ans = INT_MAX;
    string s;
    cin >> n >> s;
    vector<int> w(n+2,0);
    vector<int> e(n+2,0);

    w[1] = s[0] == 'W';
    e[1] = s[0] == 'E';
    for (int i=1; i<n; i++) w[i+1] = w[i] + (s[i]=='W');
    for (int i=1; i<n; i++) e[i+1] = e[i] + (s[i]=='E');

    for (int i=0; i<n; i++) {
        ans = min(ans, w[i] + e[n]-e[i+1]);
    }

    cout << ans << endl;
}

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

bool binary_search(int data[], int size, int target)
{
  int l=0, r=size; // 左端と右端
  while(r-l>0){
    int mid=(l+r)/2;
    if(target==data[mid])
      return true;
    else if(target < data[mid]) // 中心から小さかったら
      r = mid; //中心を右端に
    else
      l = mid+1;
  }
  return 0;
}

int main()
{
  int n, q;

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

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

  int count = 0;
  for(int i=0; i<q; i++)
    count += binary_search(S, n, T[i]);

  cout << count << endl;

}



Measured memory_bytes: 3664
#include <iostream>
#include <algorithm>
#include <string>
#include <limits.h>
#include <vector>
#include <numeric>

using namespace std;

vector<pair<long long int, long long int>> getPrimeElements(long long int num) {

	long long int firstnum = num;

	vector<pair<long long int, long long int>> result;
	pair<long long int, long long int> wk;

	if (num % 2 == 0) {
		wk.first = 2;
		wk.second = 0;
		while (num % 2 == 0) {
			wk.second++;
			num /= 2;
		}

		result.push_back(wk);
	}

	long long int waru = 3;

	while (true) {

		if (num % waru == 0) {
			wk.first = waru;
			wk.second = 0;
			while (num % waru == 0) {
				wk.second++;
				num /= waru;
			}

			result.push_back(wk);
		}
		waru += 2;

		if (waru * waru > num) break;

	}

	if (num != 1) {
		wk.first = num;
		wk.second = 1;
		result.push_back(wk);

	}

	return result;
}


int getKeta(int num) {

	if (num == 0)return 1;

	int res = 0;

	while (num > 0) {
		num /= 10;
		res++;
	}

	return res;
}

vector<int> bunkai(int num) {

	string str = to_string(num);
	vector<int> res;

	for (int i = 0; i < str.size(); i++) {
		int a = str[i] - '0';
		res.push_back(a);
	}

	return res;

}


int main()
{
    
	string str;
	cin >> str;

	string revstr = str;
	reverse(revstr.begin(), revstr.end());

	int ans = 0;

	for (int i = 0; i < (str.size() + 1)/2; i++) {
		if (str[i] != revstr[i])ans++;



	}


	cout << ans << endl;

	return 0;

}




Measured memory_bytes: 256
import math

N = int(input())

dig = len(str(N))

dig_odd = math.floor(dig / 2)

A = 0

for i in range(dig_odd):
  A += 9 * 10 ** (2 * i)

if dig % 2 == 1 and dig_odd >= 1:
  A += N - (10 ** (dig - 1) - 1)
elif dig == 1:
  A = N
  
print(A)

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

import static java.lang.Math.max;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int a = scanner.nextInt();
        int b = scanner.nextInt();
        int max = max(a+b, a-b);
        max = max(max, a*b);

        System.out.println(max);

    }
}



Measured memory_bytes: 23124
#include<iostream>
#include<string>
#include<algorithm>	
#include<cmath>
using namespace std;
int main() {
	long long n, ans = 0; cin >> n;
	for (int h = 1; h <= sqrt(n); h++) {
		if (n % h == 0) {
			if ((n / h) / 10000000000 > 0) {
				ans = 11;
			}
			else if ((n / h) / 1000000000 > 0) {
				ans = 10;
			}
			else if ((n / h) / 100000000 > 0) {
				ans = 9;
			}
			else if ((n / h) / 10000000 > 0) {
				ans = 8;
			}
			else if ((n / h) / 1000000 > 0) {
				ans = 7;
			}
			else if ((n / h) / 100000 > 0) {
				ans = 6;
			}
			else if ((n / h) / 10000 > 0) {
				ans = 5;
			}
			else if ((n / h) / 1000 > 0) {
				ans = 4;
			}
			else if ((n / h) / 100 > 0) {
				ans = 3;
			}
			else if ((n / h) / 10 > 0) {
				ans = 2;
			}
			else {
				ans = 1;
			}
		}
	}
	cout << ans << endl;
	cin >> n;
}

Measured memory_bytes: 256
/**
*   @Author : MeGA
*   @InitTime :01/24/20 12:23:11
*   @Idea : 
*
*
*
*
*
*
*
**/
#include <bits/stdc++.h>
using namespace std;
int main(){
#ifndef ONLINE_JUDGE
  // freopen("in","r",stdin);
  // freopen("out","w",stdout);
#endif
      int n;
      scanf("%d",&n);
      vector<int>v(n);
      for(int i=0;i<n;i++){
      	scanf("%d",&v[i]);
      }
      int ans=0;
      int sofar=0;
      int prev=2e9;
      for(int i=0;i<n;i++){
          if(prev >= v[i]){
             prev=v[i];
             sofar++;
          }else{
            ans=max(ans,sofar);
            sofar=1;
            prev=v[i];
          }
      }
      ans=max(ans,sofar);
      printf("%d",ans-1==-1?0:ans-1);



}

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

int main(){
	int N,K,X,Y;

	cin>>N>>K>>X>>Y;

	int res = 0;

	for(int i = 0; i < N;i++){
		if(i < K) res += X;
		else res += Y;
	}

	cout<<res<<"\n";
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for(int i=0;i<(int)n;i++)
ll mod=1e9+7;
#define PI acos(-1)
const ll INF = ll(1e18)+1;

int main(){
    int n;ll k;
    cin >> n>> k;
    vector<ll> a(n);
    rep(i,n) cin>>a[i];
    sort(a.begin(), a.end());
    ll l=-INF, r=INF;

    while(l+1<r){
        ll x=(l+r)/2;
        bool ok=[&]{
            ll tot=0;
            rep(i,n){
                if(a[i]<0){
                    int l=-1, r=n;
                    while(l+1<r){
                        int c=(l+r)/2;
                        if(a[c]*a[i]<x) r=c;else l=c;
                    }
                    tot+=n-r;
                }else{
                    int l=-1,r=n;
                    while(l+1<r){
                        int c=(l+r)/2;
                        if(a[c]*a[i]<x) l=c; else r=c;
                    }
                    tot+=r;
                }
                if(a[i]*a[i]<x) tot--;
            }
            tot /=2;
            return tot<k;
        }();
        if(ok) l=x; else r=x;
    }
    cout << l<<endl;
    return 0;
}

Measured memory_bytes: 1792
package main

import (
	"fmt"
	"sort"
)

func main() {
	var n, x, total, a int
	var s []int

	fmt.Scan(&n)

	for i := 0; i < n; i++ {
		fmt.Scan(&x)
		s = append(s, x)
	}

	sort.Sort(sort.Reverse(sort.IntSlice(s)))

	for i, num := range s {
		a = num
		if i == 0 {
			total +=1
		} else {
			if a != s[i-1] {
				total += 1
			}
		}

	}
	fmt.Println(total)
}


Measured memory_bytes: 1856
#include <stdio.h>

int main(){

int r[1000000],i,t,n,j;

  scanf("%d\n",&n);

  for(i=0;i<n;i++){
     scanf("%d\n",&r[i]);
   }
int max,min;
 max = -10000000000;
 min = r[0];

for(j=1;j<n;j++){
if(max<r[j]-min){
 max = r[j]-min;
}
else;

if(min>r[j]){
min = r[j];
}
else;

}


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

return 0;
}



Measured memory_bytes: 2656
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

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

    long N = scanner.nextLong();
    long P = scanner.nextLong();

    if (N == 1) {
      System.out.println(P);
      return;
    }
    int[] primes = primes(1_000_000);
    long max = 1;
    for (int p : primes) {
      long count = 0;
      while (P % p == 0) {
        P /= p;
        count++;
      }
      for (int i = 0; i < count / N; i++) max *= p;
    }
    System.out.println(max);
  }

  public static int[] primes(int n) {
    boolean[] isNotPrime = new boolean[n + 1];
    isNotPrime[0] = isNotPrime[1] = true;
    for (int i = 2; i < Math.sqrt(n); i++) {
      if (!isNotPrime[i]) {
        for (int j = 2; i * j <= n; j++) {
          isNotPrime[i * j] = true;
        }
      }
    }
    final List<Integer> ls = new ArrayList<>();
    for (int i = 2; i <= n; i++) if (!isNotPrime[i]) ls.add(i);
    int[] res = new int[ls.size()];
    for (int i = 0; i < ls.size(); i++) res[i] = ls.get(i);
    return res;
  }
}


Measured memory_bytes: 28116
import java.util.*;

public class Main{
    void solve(){
        Scanner scan = new Scanner(System.in);
        String s = scan.next();
        int out = 0;
        for(int i = 0; i < s.length() - 1; i++){
            if(s.charAt(i) != s.charAt(i + 1)) out++;
        }
        System.out.println(out);
    }


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


Measured memory_bytes: 39172
using System;
using System.Linq;
using System.Collections.Generic;

class Dmondai
{
    static void Main()
    {
        const long Mod= 1000000007;
        var line=Console.ReadLine().Split(' ').Select(x => Int32.Parse(x)).ToArray();
        var H = line[0];
        var W = line[1];
        var K = line[2];

        //縦棒が一つしかない場合は1
        if (W == 1) { Console.WriteLine(1); return; }

        //それぞれの位置の横棒の数を保存する
        var arrayH = new long[W-1];

        //ビット探索
        //横の線のあるなしを全列挙する
        var bitList = new List<string>();
        for (int i=0;i<(1<<(W-1));++i)
        {
            //二進数に変換、
            var value=Convert.ToString((i), 2);
            //空いている桁は0埋めする
            var bit =value.PadLeft(W-1,'0');

            //横棒が二つ続いた場合、処理をスキップさせるためのフラグ
            var isContinue = true;

            //横棒が二つ続くことはないので、その場合を除く
            for (int j=0;j<W-2;++j)
            {
                if (bit[j] == '1' && bit[j + 1] == '1')
                {
                    isContinue = false;
                    break;
                }
            }

            //横棒が二つ続かないパターン（正当なあみだくじ）
            if (isContinue)
            {
                bitList.Add(bit);
                for (int j=0;j<W-1;++j) if (bit[j] == '1') arrayH[j]++;
            }
        }

        //ビットりすと内にある数を保存（横棒のパターン）
        long bitCount = bitList.Count();

        //動的計画法
        //各ポイントにおいて何通りのパターンがあるかを保存し、
        //それを利用しつつ下へ下る
        //保存する器を用意
        //H横棒の数、いま行でどこにいるか、0～H
        //W横棒の数、いま列でどこにいるか、0～W-1
        var ansArray = new long[H+1,W];
        //行のループ
        for (int i=0;i<=H;++i)
        {
            //列のループ
            for (int j=0;j<W;++j)
            {
                if (i == 0)
                {
                    //0,0地点は始点＝1
                    if (j == 0) ansArray[i, j] = 1;
                    else ansArray[i, j] = 0;
                }
                //列が0のとき
                else if (j==0)
                {   
                    //真上
                    var temp = (ansArray[i - 1, j] * (bitCount-arrayH[0])) % Mod;
                    //右
                    temp = (temp + (ansArray[i - 1, j + 1] * arrayH[0])) % Mod;
                    ansArray[i, j] = temp;

                }
                //列がW-1のとき（一番右端）
                else if (j == W - 1)
                {
                    //真上
                    var temp = (ansArray[i - 1, j] * (bitCount - arrayH[W-2])) % Mod;
                    //左
                    temp = (temp + (ansArray[i - 1, j - 1] * arrayH[W-2])) % Mod;
                    ansArray[i, j] = temp;
                }
                //それ以外
                else
                {
                    //真上
                    var temp = (ansArray[i - 1, j] * (bitCount - ( arrayH[j-1] + arrayH[j]) )) % Mod;
                    //左
                    temp = (temp + (ansArray[i - 1, j - 1] * arrayH[j - 1] )) % Mod;
                    //右
                    temp = (temp + (ansArray[i - 1, j + 1] * arrayH[j])) % Mod;
                    ansArray[i, j] = temp;
                }
            }
        }
        Console.WriteLine(ansArray[H,K-1]);

    }
}


Measured memory_bytes: 13396
#include <iostream>

using namespace std;
#define ll long long
int main(){
    int r;
    cin >> r;
    ll ans=0;
    if (r<1200) cout <<"ABC"<<endl;
    else if (r<2800) cout <<"ARC"<<endl;
    else cout <<"AGC"<<endl;

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <iostream>
#include <sstream>
#include <vector>
#include <string>
#include <math.h>
#include <queue>
#include <list>
#include <algorithm>
#include <map>
#include <set>
#include <stack>
#include <ctime>
#include <iomanip>
#include <fstream>
using namespace std;

#define ALL(c) (c).begin(),(c).end()
#define PB push_back
#define IN(x,c) (find(c.begin(),c.end(),x) != (c).end())
#define REP(i,n) for (int i=0;i<(int)(n);i++)
#define FOR(i,a,b) for (int i=(a);i<=(b);i++)
#define INIT(a,v) memset(a,v,sizeof(a))
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
template<class A, class B> A cvt(B x) { stringstream ss; ss<<x; A y; ss>>y; return y; }

#define SPC << " " <<
#define DEBUG(x) cerr << #x << " = "; cerr << x << endl;
#define DEBUG_ITER(x) cerr << #x << " = "; for (auto _ : x) cerr << _ << ' '; cerr << endl;

typedef pair<int,int> PII;
typedef long long int64;
typedef vector<int> VI;

int vis[1000000];

int main() {
	//freopen("test.in","r",stdin);
	int k;
	cin >> k;
	int n=0;
	for (int num=1;;num++) {
		n=(n*10+7)%k;
		if (vis[n]) {
			printf("-1\n");
			return 0;
		}
		vis[n]=1;
		if (n==0) {
			printf("%d\n",num);
			return 0;
		}
	}
	return 0;
}


Measured memory_bytes: 7664
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <tuple>
#include <utility>
#include <set>
using namespace std;
using LLI = long long int;


int main(int argc, char *argv[])
{
    int D;
    cin >> D;

    string s =
        D == 25 ? "Christmas" :
        D == 24 ? "Christmas Eve" :
        D == 23 ?  "Christmas Eve Eve" :
        "Christmas Eve Eve Eve" ;
    
    cout << s;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, e) for(int (i) = 0; (i) < (e); ++(i))
#define FOR(i, b, e) for(int (i) = (b); (i) < (e); ++(i))
#define ALL(c) (c).begin(), (c).end()
#define PRINT(x) cout << (x) << "\n"
using namespace std;
using ll = long long; using pint = pair<int, int>; using pll = pair<ll, ll>;
const long long MOD = 1000000007;

int N;
const int N_MAX = 201;
long long dist[N_MAX][N_MAX];

void floyd(){
    for(int k = 0; k < N; k++){
        for(int i = 0; i < N; i++){
            for(int j = 0; j < N; j++){
                dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
            }
        }
    }
}

ll M, edge[101][101];

signed main(){
    cin >> N >> M;
    ll a, b, c;
    REP(i, N) REP(j, N) edge[i][j] = dist[i][j] = LONG_LONG_MAX / 2;
    REP(i, N) edge[i][i] = dist[i][i] = 0;
    REP(i, M){
        cin >> a >> b >> c;
        a--; b--;
        edge[a][b] = edge[b][a] = dist[a][b] = dist[b][a] = c;
    }
    floyd();
    ll ans = 0;
    REP(i, N - 1){
        FOR(j, i + 1, N){
            if(edge[i][j] < LONG_LONG_MAX / 2 && edge[i][j] > dist[i][j]) ans++;
        }
    }
    PRINT(ans);
    return 0;
}

Measured memory_bytes: 3876
#include <bits/stdc++.h>
using namespace std;
#define forn(i, n) for(int i = 0; i < int(n); i++)
#define fore(i, l, r) for(int i = int(l); i < int(r); i++)
#define pb push_back
#define all(x) x.begin(), x.end()
#define sz(a) int((a).size())
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef pair<int, int> pii;
const int mod = 1e9 + 7;
template<class T, class U> inline void add_self(T &a, U b){a += b;if (a >= mod) a -= mod;if (a < 0) a += mod;}
template<class T, class U> inline void min_self(T &x, U y) { if (y < x) x = y; }
template<class T, class U> inline void max_self(T &x, U y) { if (y > x) x = y; }

#define _deb(x) cout<<x;
void _print() {cerr << "]\n";} template <typename T, typename... V>void _print(T t, V... v) {_deb(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#define deb(x...) cerr << "[" << #x << "] = ["; _print(x)
template <class T, class U> void print_m(const map<T,U> &m, int w=3){if(m.empty()){cout<<"Empty"<<endl; return;}for(auto x: m)cout<<"("<<x.first<<": "<<x.second<<"),"<<endl;cout<<endl;}
template<class T, class U>void debp(const pair<T, U> &pr, bool end_line=1){cout<<"{"<<pr.first<<" "<<pr.second<<"}"; cout<<(end_line ? "\n" : ", ");}
template <class T> void print_vp(const T &vp, int sep_line=0){if(vp.empty()){cout<<"Empty"<<endl; return;}if(!sep_line) cout<<"{ ";for(auto x: vp) debp(x,sep_line);if(!sep_line) cout<<"}\n";cout<<endl;}
template <typename T>void print(const T &v, bool show_index = false){int w = 2;if(show_index){for(int i=0; i<sz(v); i++)cout<<setw(w)<<i<<" ";cout<<endl;}for(auto &el: v) cout<<setw(w)<<el<<" ";cout<<endl;}
template <typename T>void print_vv(const T &vv){if(sz(vv)==0) {cout<<"Empty"<<endl; return;} int w = 3;cout<<setw(w)<<" ";for(int j=0; j<sz(*vv.begin()); j++)cout<<setw(w)<<j<<" ";cout<<endl;int i = 0;for(auto &v: vv){cout<<i++<<" {";for(auto &el: v) cout<<setw(w)<<el<<" ";cout<<"},\n";}cout<<endl;}

int main(){
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    string s, t;
    while(cin>>s>>t){
        int n = sz(s), m = sz(t);
        int mx = m;
        for(int i=0; i+m<=n; ++i){
            int cnt = 0;
            forn(j,m){
                cnt+=(s[i+j]!=t[j]);
            }
            min_self(mx, cnt);
        }
        cout<<mx<<"\n";
    }
    return 0;
}

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

#define Q_MAX 362880
#define N 3
#define N2 9

typedef struct puzzle
{
	int board[N2];
	int space;
	int path;
} Puzzle;

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

Puzzle Q[Q_MAX];
int head, tail, V[Q_MAX];

int empty();
void enq(Puzzle);
Puzzle front();
int check(Puzzle);
int isTarget(Puzzle);
int BFS(Puzzle);
void swap(int *, int *);

int main()
{
	int i, ans;
	Puzzle p;

	for (i = 0; i < N2; i++)
	{
		scanf("%d", &p.board[i]);
		if (p.board[i] == 0)
		{
			p.board[i] = N2;
			p.space = i;
		}
	}

	ans = BFS(p);
	printf("%d\n", ans);

	return 0;
}

int empty()
{
	return head == tail;
}

void enq(Puzzle p)
{
	Q[tail] = p;
	tail = (tail + 1) % Q_MAX;
}

Puzzle front()
{
	Puzzle p;

	p = Q[head];
	head = (head + 1) % Q_MAX;
	return p;
}

int check(Puzzle p)
{
	int i, j, f, count, res = 0;

	for (i = 0, f = 1; i < N2; f *= ++i)
	{
		for (j = 0, count = 0; j < i; j++)
		{
			if (p.board[j] < p.board[i])
				count++;
		}
		res += count * f;
	}
	return res;
}

int isTarget(Puzzle p)
{
	int i;

	for (i = 0; i < N2; i++)
	{
		if (p.board[i] != (i + 1))
			return 0;
	}
	return 1;
}

int BFS(Puzzle q)
{
	int sx, sy, tx, ty, r, tmp;
	int i;
	Puzzle u, v;

	q.path = 0;
	enq(q);
	V[check(q)] = 1;
	while (!empty())
	{
		u = front();
		if (isTarget(u))
			return u.path;
		sx = u.space / N;
		sy = u.space % N;
		for (r = 0; r < 4; r++)
		{
			tx = sx + dx[r];
			ty = sy + dy[r];
			if (tx < 0 || ty < 0 || tx >= N || ty >= N)
				continue;
			v = u;
			tmp = v.board[u.space];
			v.board[u.space] = v.board[tx * N + ty];
			v.board[tx * N + ty] = tmp;
			v.space = tx * N + ty;
			if (!V[check(v)])
			{
				V[check(v)] = 1;
				v.path++;
				enq(v);
			}
		}
	}

	return -1;
}



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

#define scd second
#define fst first
#define mkp make_pair
#define pb push_back

using namespace std;

typedef long long int ll;
typedef vector<int> vint;
typedef vector<ll> vlong;
typedef pair<int,int> pii;
typedef vector<pii> vpii;

int const N=1e5+10;

int main(){
	int n;
	cin>>n;
	vector<int> v(n+1);
	for(int i=1; i<=n; i++){
		cin>>v[i];
	}

	int ans=0;
	for(int i=1; i<=n; i++){
		if(v[i]==i){
			if(i!=n){
				swap(v[i],v[i+1]);
			}else swap(v[i],v[i-1]);
			ans++;
		}
	}

	cout<<ans<<endl;
}

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

int main() {
  int N , M;
  cin >> N >> M;
  int m=2*M;
  vector<int> vec(m);
  
  for (int i=0; i < M ; i++){ //配列を代入
    cin >> vec.at(2*i) >> vec.at(2*i+1);
  }
  
  //for (int i=0; i<m ; i++){
    //cout << vec.at(i) << ' ';
  //}
  
  for (int j=1 ; j<=N ; j++){
    int count =0;
    for (int i=0 ; i < m ; i++){
      if (vec.at(i)==j){
        count ++;
      }
      else{
      }
    }
    cout << count << endl;
  }
}


Measured memory_bytes: 256
n,q=map(int,input().split())
s=list(str(input()))
l=[]
r=[]
ans=0
x=[0]
for i in range(q):
  l1,r1=map(int,input().split())
  l.append(l1)
  r.append(r1)

for j in range(0,n-1):
  if s[j]=="A" and s[j+1]=="C":
    ans+=1
    x.append(ans)
  else:
    x.append(ans)

for k in range(0,q):
  print(x[r[k]-1]-x[l[k]-1])
      
      
      
  
  
  
  


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


int main() {
    int N, x;
    cin >> N >> x;

    vector<int> a(N);
    rep (i,N) {
        cin >> a.at(i);
    }
    sort(a.begin(), a.end());

    int res = 0;
    for (int i = 0; i < N; ++i) {
        if (i == N - 1 && x > a.at(i)) {
            break;
        }

        if (x <= 0) {
            break;
        }
        if (x >= a.at(i)) {
            ++res;
            x -= a.at(i);
        } else {
            break;
        }

    }
    cout << res << endl;


}


Measured memory_bytes: 3632
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <queue>
using namespace std;

int N, n;

struct BIT {
    vector<int> bit;
    int M;
    
    BIT(int M): bit(vector<int>(M + 1)), M(M) { }
    
    int sum(int i) {
        int s = 0;
        while (i > 0) {
            s += bit[i];
            i -= i & -i;
        }
        return s;
    }
    void add(int index, int x) {
        while (index <= M) {
            bit[index] += x;
            index += index & -index;
        }
    }
};

long long inversion_number(vector<int>& A, int Maximum) {  //数列の転倒数
    long long ans = 0;
    int p = 1, n = (int) A.size();
    while (p < Maximum) {
        p = p << 1;
    }
    BIT b(p);
    for (int i = 0; i < n; i++) {
        ans += i - b.sum(A[i]);
        b.add(A[i], 1);
    }
    return ans;
}

bool judge(int x, vector<int>& A) {
    vector<int> S(N + 1);
    S[0] = N + 1;
    long long j = 1ll * N * (N + 1) / 2 / 2;
    for (int i = 0; i < N; i++) {
        if (A[i] < x) {
            S[i + 1] = S[i] - 1;
        } else {
            S[i + 1] = S[i] + 1;
        }
    }
    return inversion_number(S, 2 * N + 1) <= j;
}

int bin_search(int left, int right, vector<int>& A) {
    if (left + 2 > right) {
        return judge(right, A)? right: left;
    }
    
    int mid = (left + right) / 2;
    if (judge(mid, A)) {
        return bin_search(mid, right, A);
    } else {
        return bin_search(left, mid, A);
    }
}

int main() {
    cin >> N;
    vector<int> A(N);
    for (int i = 0; i < N; i++) cin >> A[i];
    
    cout << bin_search(1, 1e9, A) << endl;
}

Measured memory_bytes: 2048
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(n); ++i)
#define repr(i, a, b) for (int i=a; i<(b); ++i)
#define reprev(i, n) for (int i=n-1; i>=0; --i)
#define reprrev(i, a, b) for (int i=b-1; i>=(a); --i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
    cout << fixed << setprecision(10);
    
    string a, b, c; cin >> a >> b >> c;
    int flag = 1;
    queue<int> q;
    q.push(0);
    while (flag) {
        string fs;
        int t = q.front();
        q.pop();
        if (t == 0) {
            // aのターン
            if (a.size()) {
                fs = a[0];
                a.erase(0, 1);
            } else {
                cout << 'A' << endl;
                return 0;
            }
        } else if (t == 1) {
            // bのターン
            if (b.size()) {
                fs = b[0];
                b.erase(0, 1);
            } else {
                cout << 'B' << endl;
                return 0;
            }
        } else {
            // cのターン
            if (c.size()) {
                fs = c[0];
                c.erase(0, 1);
            } else {
                cout << 'C' << endl;
                return 0;
            }
        }

        if (fs[0] == 'a') {
            q.push(0);
        } else if (fs[0] == 'b') {
            q.push(1);
        } else {
            q.push(2);
        }
    }
    return 0;
}

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

#define i64 long long int

i64 fr, to, p1, p2;

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

i64 calc(i64 x) {
	i64 res = x-(x/p1 + x/p2 - x/p1/(p2/gcd(p1, p2)));
	//cout<<res<<endl;
	return res;
}

int main() {
	cin>>fr>>to>>p1>>p2;
	cout<<calc(to) - calc(fr-1)<<endl;
	
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int[] x = new int[5];
		for (int i = 0; i < x.length; ++i) {
			x[i] = sc.nextInt();
		}
		for (int i = 0; i < x.length; ++i) {
			if (x[i] == 0) {
				System.out.println(i + 1);
				return;
			}
		}
	}
}

Measured memory_bytes: 35520
#include <iostream>
#include <vector>
#include <queue>
#include <set>
using namespace std;



int main() {
  int n;
  while(cin >> n) {
    vector<int> g[7];
    int a;
    set<int> se;
    for (int i=0;i<n;++i) {
      cin >> a;
      g[a/10].push_back(a%10);
      g[a%10].push_back(a/10);
      se.insert(a/10);
      se.insert(a%10);
    }
    queue<int> Q;
    Q.push(a/10);
    bool visited[7] = {};
    int ct = 0;
    while(!Q.empty()) {
      int now = Q.front();
      Q.pop();
      if (visited[now]) continue;
      visited[now] = 1;
      ct++;
      for (int i=0;i<g[now].size(); ++i) {
        if (!visited[g[now][i]])
          Q.push(g[now][i]);
      }
    }
    int cnt = 0;
    for (int i=0;i<7;++i) {
      if (g[i].size()%2)
        cnt++;
    }
//    cout << cnt << " "  << ct << endl;
    if (ct == se.size() && (cnt == 0 || cnt == 2)) {
      cout << "Yes" << endl;
    }else
      cout << "No" << endl;
  }
}

Measured memory_bytes: 0
n = int(raw_input())
A = map(int, raw_input().split())
q = int(raw_input())
m = map(int, raw_input().split())

def solve(i, m):
    if m == 0:
        return 1
    if i >= n or m > sum(A):
        return 0
    res = solve(i + 1, m) or solve(i + 1, m - A[i])
    return res
        
for j in range(0, q):
    if solve(0, m[j]):
        print "yes"
    else:
        print "no"

Measured memory_bytes: 6448