akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
      int x = sc.nextInt();
      int y = sc.nextInt();
      int z = sc.nextInt();
      int a;
      int b;
      b = y;
      y = x;
      x = b;
      a = x;
      x = z;
      z = a;
      System.out.println(x+" "+y+" "+z);
	}
}

Measured memory_bytes: 39528
import itertools
 
N=int(input())
P=tuple(map(int,input().split()))
Q=tuple(map(int,input().split()))
nlis=[i for i in range(1,N+1)]
 
j=list(itertools.permutations(nlis))
cp=j.index(P)+1
cq=j.index(Q)+1
print(abs(cp-cq))

Measured memory_bytes: 8052
import java.util.*;

public class Main{
  static int gcd (int a, int b) {return b>0?gcd(b,a%b):a;}

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

    for(int i=0; i<n; i++){
      array[i] = sc.nextInt();
    }

    int ans =0;
    int max_ans = 0;
    int pp;
    int ss;

    int[] l_gcd = new int[n];
    l_gcd[0] = array[0];
    for(int i=1; i<n-1; i++){
      l_gcd[i] = gcd(l_gcd[i-1],array[i]);
    }

    int[] r_gcd = new int[n];
    r_gcd[n-1] = array[n-1];

    for(int i=n-2; i>0; i--){
      r_gcd[i] = gcd(r_gcd[i+1],array[i]);
    }

    if(r_gcd[1]>max_ans){
      max_ans = r_gcd[1];
    }
    for(int i=0; i<n-2; i++){
      ans = gcd(l_gcd[i],r_gcd[i+2]);
      if(ans>max_ans){
        max_ans = ans;
      }
    }
    if(l_gcd[n-2]>max_ans){
      max_ans = l_gcd[n-2];
    }
    System.out.println(max_ans);






  }
}

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

#define int             long long int
#define ff              first
#define ss              second
#define pb              push_back

#define vi              vector <int>
#define pii             pair <int, int>

#define loop(i,s,e)     for(int i=s;i<e;i++)
#define rloop(i,e,s)    for(int i=e;i>=s;i--)
#define mset(a,f)       memset(a,f,sizeof(a))

#define endl            "\n"
#define sz(x)           ((int) x.size())
#define all(p)          p.begin(), p.end()

#define bug(...)        __f (#__VA_ARGS__, __VA_ARGS__)
#define print(a)        for (auto x : a) cout << x << " "; cout << endl
#define Print(a,x,y)    for (int i=x; i<y; i++) cout<< a[i]<< " "; cout << endl



template <typename Arg1>
void __f (const char* name, Arg1&& arg1) { cout << name << " : " << arg1 << endl; }
template <typename Arg1, typename... Args>
void __f (const char* names, Arg1&& arg1, Args&&... args)
{
	const char* comma = strchr (names + 1, ',');
	cout.write (names, comma - names) << " : " << arg1 << " | "; __f (comma + 1, args...);
}

const int N = 200005;


void solve()
{
	string s;
	cin >> s;
	int ans = 0, cnt = 0;
	int n = s.size();
	loop(i, 0, n)
	{
		if (s[i] == 'R') cnt++;
		else cnt = 0;
		ans = max(ans, cnt);
	}
	cout << ans << endl;

}

int32_t main()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

#ifndef ONLINE_JUDGE
	freopen("input.txt",  "r",  stdin);
	freopen("output.txt", "w", stdout);
#endif

	int t = 1;
	//cin >> t;
	while (t--) solve();

	return 0;
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
#define rep(i,n) for (ll i=0;i<(n);++i)
#define rep2(i,a,b) for (ll i=(a);i<(b);++i)
#define debug(x) cout << #x << '=' << x << endl
#define all(v) (v).begin(),(v).end()
const ll MOD=1e9+7;
//const ll MOD=998244353;
const ll INF=1e9;
const ll IINF=1e18;
const double EPS=1e-8;
const double pi=acos(-1);

template<class T> inline bool chmin(T &a,T b){
    if (a>b){a=b; return true;}
    return false;
}
template<class T> inline bool chmax(T &a,T b){
    if (a<b){a=b; return true;}
    return false;
}

const ll MAX_N=2e5+10;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N; cin >> N;
    vector<ll> A(N);
    rep(i,N) cin >> A[i];
    vector<Pll> B(N);
    rep(i,N) B[i]={A[i],i};
    sort(all(B));
    reverse(all(B));
    vector<int> cnt(N);
    rep(i,N) cnt[B[i].second]=i;
    ll ans=0,pw1=1,pw2;
    rep(i,2*N-2) pw1=pw1*2%MOD;
    pw2=pw1*2%MOD;
    rep(i,N) ans=(ans+(pw2+pw1*cnt[i]%MOD)%MOD*A[i]%MOD)%MOD;
    cout << ans << endl;
}

Measured memory_bytes: 5760
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vs=vector<string>;
using msi=map<string,int>;
using mii=map<int,int>;
using psi=pair<string,int>;
using pii=pair<int,int>;
using vlai=valarray<int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define INF 1e9
#define EPS 1e-9
#define MOD ((ll)1e9+7)
void get(){}template<class H,class...T>void get(H&h,T&...t){cin>>h;get(t...);}
template<class T>void geti(T&a){for(auto&_:a)cin>>_;}
template<class T>void getii(T&a){for(auto&_:a)geti(_);}
void put(string d){}template<class H,class...T>void put(string d,H&h,T&...t){cout<<h;if(sizeof...(t))cout<<d;put(d,t...);}
template<class T>void puti(T&a,string d=" "){bool f=1;for(auto&_:a)cout<<(exchange(f,0)?"":d)<<_;cout<<endl;}
template<class T>void putii(T&a,string d=" "){for(auto&_:a)puti(_,d);}
#define dcl(...) ll __VA_ARGS__;get(__VA_ARGS__)
#define dclt(t,...) t __VA_ARGS__;get(__VA_ARGS__)
template<class F,class S>void add(map<F,S>&mp,F f,S s){if(mp.find(f)==mp.end())mp[f]=F();mp[f]+=s;}
 
int main(){
    int h,v;
    using data=pair<int,int>;
    
    while(cin>>h>>v, h or v){
        int tv[]={-3,-1,1,3};
        int tc[]={v,h,h,v};
        int p10[]={100000000,10000000,1000000,100000,10000,1000,100,10,1};
        array<int,9> a,b;
        geti(a);
        geti(b);
        int sa=0,sb=0;
        for(auto i:a)sa=sa*10+i;
        for(auto i:b)sb=sb*10+i;
    
        unordered_map<int,int> s;

        priority_queue<data> q;
        q.emplace(0,sa);
        
        while(1){
            int cost=q.top().fs;
            int board=q.top().sc;
            q.pop();
            if(board==sb){
                cout<<-cost<<endl;
                break;
            }
            int index=to_string(board).find('0');
            if(index==-1)index=0;
            rep(i,4){
                int fixed=(index+tv[i]+9)%9;
                int next=board;
                int fx=next/p10[fixed]%10;
                next-=p10[fixed]*fx;
                next+=p10[index]*fx;
                if(s.find(next)==s.end() || (s[next]<cost-tc[i] && cost-tc[i]>-5000)){
                    q.emplace(cost-tc[i], next);
                    s[next]=cost-tc[i];
                }
            }
        }
    }
}



Measured memory_bytes: 21344
#include <iostream>
#include <cstdio>
#include <string>
#include <sstream>
#include <algorithm>
#include <math.h>
#include <map>
#include <iomanip>
#include <vector>
#include <queue>

#define REP(i,n) for(int i=0;i<n;i++)
#define PI 3.14159265359

#define INF 1000000;

using namespace std;


int main()
{
	int n, m;
	
	while (scanf("%d %d\n", &n, &m), n && m)
	{
		vector<int> v;
		for (int i=1; i<=n; i++) v.push_back(i);
		vector<int>::iterator it = v.begin();
		while (1 < v.size())
		{
			for (int i=1; it = it == v.end() ? v.begin() : it, i < m; i++)
			{
				it++;
			}
			it = v.erase(it);
		}
		printf("%d\n", v[0]);
	}
	
	/*
    REP(i, 10)
	{
    	cout << i << '\n';
	}
	*/
	
	return 0;
}

Measured memory_bytes: 1224
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
#define yn {puts("Yes");}else{puts("No");}
#define MAX_N 200005

// long version
long long int GCD(long long int x, long long int y){
    if(x>y){
        long long int swap = x;
        x = y;
        y = swap;
    }
    while(true){
        if(y%x==0){
            return x;
        }else{
            long long int amari = y%x;
            y = x;
            x = amari;
        }
    }
}

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

    ll ans = a * b / GCD(a, b);

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


Measured memory_bytes: 256
#include <iostream>

static const int g_buildings = 4;
static const int g_floors = 3;
static const int g_rooms = 10;

void printBuildings(int buildings[g_buildings][g_floors][g_rooms]) {
	for (int building = 0; building < g_buildings; building++) {
		for (int floor = 0; floor < g_floors; floor++) {
			for (int room = 0; room < g_rooms; room++) {
				std::cout << " " << buildings[building][floor][room];
			}
			std::cout << "\n";
		}
		if (building != g_buildings - 1) {
			for (int i = 0; i < 2 * g_rooms; i++) {
				std::cout << "#";
			}
			std::cout << "\n";
		}
	}
}

int main()
{
	int buildings[g_buildings][g_floors][g_rooms] = {};
	int notices;
	std::cin >> notices;

	int b, f, r, v;
	for (int i = 0; i < notices; i++) {
		std::cin >> b >> f >> r >> v;
		buildings[b-1][f-1][r-1] += v;
	}
	printBuildings(buildings);
    return 0;
}



Measured memory_bytes: 3132
#include <algorithm>
#include <cmath>
#include <complex>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
#include <functional>
#include <cstring>
#include <regex>
#include <random>
#include <cassert>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, s, n) for (int i = (s); i < (int)(n); i++)
#define revrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define revrepr(i, s, n) for (int i = (n) - 1; i >= s; i--)
#define debug(x) cerr << #x << ": " << x << "\n"

using ll = long long;
using P = pair<int, int>;

const long long MOD = 1e9+7;

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

template<class T>
istream& operator >>(istream &is, vector<T> &v) {
    for (int i = 0; i < (int)v.size(); i++) cin >> v.at(i);
    return is;
}

template<class T, class U>
ostream& operator <<(ostream &os, pair<T, U> p) {
    cout << '(' << p.first << ", " << p.second << ')';
    return os;
}

template<class T>
void print(const vector<T> &v, const string &delimiter) { rep(i, v.size()) cout << (0 < i ? delimiter : "") << v.at(i); cout << endl; }

template<class T>
void print(const vector<vector<T>> &vv, const string &delimiter) { for (const auto &v: vv) print(v, delimiter); }

//2のべき乗の和に分割
vector<int> f(int n) {
    if (n == 0) return vector<int>(0);
    vector<int> v1(1);
    int b = 1;
    int e = 0;
    while (b * 2 <= n) {
        b *= 2;
        e++;
    }
    v1[0] = e;
    vector<int> v2 = f(n - b);
    for (int v: v2) v1.push_back(v);
    return v1;
}

struct Edge { int from, to, w; };
struct E { int to, w; };

vector<int> ls;
void dfs(int v, int goal, const vector<vector<E>> &graph, int sum = 0) {
    if (v == goal) {
        ls.push_back(sum);
        return;
    }
    for (const E &e: graph[v]) dfs(e.to, goal, graph, sum + e.w);
}

int main() {
    int l;
    cin >> l;
    auto es = f(l);
    int n = es[0] + 1;
    int m = es[0] * 2 + (int)es.size() - 1;
    vector<Edge> edges;
    rep(i, es[0]) {
        edges.push_back(Edge{i + 1, i + 2, 0});
        edges.push_back(Edge{i + 1, i + 2, 1 << i});
        //printf("%d %d %d\n", i + 1, i + 2, 0);
        //printf("%d %d %d\n", i + 1, i + 2, 1 << i);
    }
    int next_w = 1 << es[0];
    repr(i, 1, es.size()) {
        edges.push_back(Edge{es[i] + 1, es[0] + 1, next_w});
        //printf("%d %d %d\n", es[i] + 1, es[0] + 1, next_w);
        next_w += 1 << es[i];
    }
    
    printf("%d %d\n", n, m);
    for(Edge &e: edges) printf("%d %d %d\n", e.from, e.to, e.w);
    
    //vector<vector<E>> graph(n);
    //for(Edge e: edges) graph[e.from - 1].push_back(E{e.to - 1, e.w});
    //dfs(0, n - 1, graph);
    //sort(ls.begin(), ls.end());
    //cout << ls.size() << endl;
    //rep(i, ls.size()) cout << ls[i] << endl;
}

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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define MOD (1000000007)
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

ll a,b,c;

void input(){
    cin >> a >> b >> c;
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    input();
    if(a == b && b == c){ 
        if(a%2 && b%2 && c%2){
            cout << 0 << endl;
            return 0;
        }
        cout << -1 << endl;
        return 0;
    }
    ll ans = 0;
    ll aa, bb, cc;
    while(a%2==0 && b%2==0 && c%2==0){
        aa = a;
        bb = b;
        cc = c;
        // cout << a << ' ' << b << ' ' << c << endl;
        a = (bb+cc)/2;
        b = (aa+cc)/2;
        c = (aa+bb)/2;
        ans++;
    }
    // cout << a << ' ' << b << ' ' << c << endl;
    cout << ans << endl;
    return 0;
}

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

void insertionSort( int *a, int n ){
 for( int i=0; i<n; i++ ){
   int v = a[i];
   int j=i-1;
   while( j>=0 && a[j] > v ){
     a[j+1] = a[j];
     j--;
   }
   a[j+1] = v;
   for( int h=0; h<n; h++ ){
       if( h !=n-1 ){
         cout << a[h] << " ";
       }else{
         cout << a[h] << endl;
       }
   }
 }
 return;
}

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

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

 insertionSort( a, n );

 return 0;
}


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

const int INF = 0x3fffffff;
const ll MINF = 0x7fffffffffff;
const ld DINF = numeric_limits<ld>::infinity();
const int MOD = 1000000007;
const int MODD = 998244353;
const ld EPS = 1e-9;
const ld PI = 3.1415926535897932;

template<class T> bool chmin(T &a, const T &b){ if(a > b){ a = b; return 1; } else return 0; }
template<class T> bool chmax(T &a, const T &b){ if(a < b){ a = b; return 1; } else return 0; }
template<class T> auto min(const T& a){ return *min_element(all(a)); }
template<class T> auto max(const T& a){ return *max_element(all(a)); }

ll gcd(ll a, ll b){ while(b){ ll c = b; b = a % b; a = c; } return a; }
ll lcm(ll a, ll b){ if(!a || !b) return 0; return a * b / gcd(a, b); }
ll pow_mod(ll n,ll k,ll m){ll r = 1;for(; k > 0;k >>= 1) {if (k & 1) r = (r * n) % m; n = (n * n) % m;}return r;}

//ここから。
int main(){
    int H,W;
    cin >> H >> W;
    vector<vector<int>> c(10,vector<int> (10));
    rep(i,10)
        rep(j,10) cin >> c[i][j];
    
    vector<vector<int>> A(H,vector<int> (W));
    rep(i,H)
        rep(j,W) cin >> A[i][j];

    rep(k,10)
        rep(i,10)
            rep(j,10) chmin(c[i][j],c[i][k] + c[k][j]);
    
    ll cost = 0;
    rep(i,H){
        rep(j,W){
            if(A[i][j] == -1) continue;
            if(A[i][j] == 1) continue;
            cost += c[A[i][j]][1];
        }
    }
    cout << cost << endl;
}

Measured memory_bytes: 384
def q3():
    import math
    K = int(input())
    ans = 0
    for a in range(1, K+1):
        for b in range(1, K+1):
            for c in range(1, K+1):
                ans += math.gcd(a, math.gcd(b, c))
    print(ans)


if __name__ == '__main__':
    q3()


Measured memory_bytes: 67828
#include <stdio.h>
int main(){
  int a,b,d,r;
  double f;
  scanf("%d%d",&a,&b);
  d=a/b;
  r=a%b;
  f=1.0*a/b;
  printf("%d %d %f\n",d,r,f);
  return 0;
}

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

int isprime(int n) {
  for (int i = 2; i * i <= n; ++i) {
    if (n % i == 0) return false;
  }
  return true;
}

int main() {
  int n;
  cin >> n;
  for (int i = n; ; ++i) {
    if (isprime(i)) {
      cout << i << endl;
      return 0;
    }
  }
}

Measured memory_bytes: 256
use std::io;

fn read_line()-> String {
    let mut s = String::new();
    let _ = io::stdin().read_line(&mut s).unwrap();
    s
}

fn main() {
	let s = read_line().trim().split_whitespace().map(|e|e.parse().unwrap())
	.collect::<Vec<String>>();
	let a = s[0].parse::<i32>().unwrap();
	let b = s[2].parse::<i32>().unwrap();
	if s[1] == "+" {
		println!("{}",a+b);
	}else{
		println!("{}",a-b);
	}
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) (v).begin(),(v).end()
#define out(a) cout << (a) << endl
using namespace std;
using ll = long long;

int n;
vector<int> x(10);
vector<int> y(10);

double dist(int i, int j){
    double dx = x[i] - x[j];
    double dy = y[i] - y[j];
    return pow(dx * dx + dy * dy, 0.5);
}

int main(){
    cin >> n;
    for(int i=1; i<=n; i++){
    cin >> x[i];
    cin >> y[i];
}
    vector<int> v(n);
    for (int i = 0; i<n; i++) v[i] = i + 1;
    double sum = 0.0;
    do{
        for(int i=0; i<n-1; i++) sum += dist(v[i], v[i+1]);
    }while (next_permutation(all(v)));
    int Factorial = 1;
    for(int i=2; i<=n; i++) Factorial *= i;
    cout << fixed << setprecision(10) << sum/Factorial << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <stack>
#include <numeric>
#include <algorithm>
#include <stdio.h>
#include <bitset>
#include <limits.h>
#include <complex>
#include <deque>
#include <iomanip>
using namespace std;
#define MM 1000000000
#define MOD MM+7
#define pi pair<int32,int32>
#define pl pair<int64,int64>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
const long double PI = acos(-1);
const long long INF = 1e15;
int dx[8] = {-1,0,1,0,-1,-1,1,1};
int dy[8] = {0,-1,0,1,-1,1,1,-1};
template<typename T>
T GCD(T u,T v){
    return v ? GCD(v,u%v) : u;
}
template<typename T>
T lcm(T x,T y){
    return x*y/GCD(x,y);
}


int main(){
    int n,m; cin >> n;
    int a[1001],b[1001];

    for(int i = 0; i < n; i++) cin >> a[i];

    cin >> m;
    for(int i = 0; i < m; i++) cin >> b[i];

    for(int i = 0; i < min(m,n); i++){
        if (a[i] > b[i]){
            cout << 0 << endl;
            return 0;
        } else if (a[i] < b[i]){
            cout << 1 << endl;
            return 0;
        }
    }
    if (m > n){
        cout << 1 << endl;
    } else {
        cout << 0 << endl;
    } 
}
  




Measured memory_bytes: 3116
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
using namespace std;
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void POSS(T condition){ if(condition) cout << "POSSIBLE" << endl; else cout << "IMPOSSIBLE" << endl; }
template<class T> inline void Poss(T condition){ if(condition) cout << "Possible" << endl; else cout << "Impossible" << endl; }
template<class T> inline void First(T condition){ if(condition) cout << "First" << endl; else cout << "Second" << endl; }
template<class T = string, class U = char>int character_count(T text, U character){ int ans = 0; for(U i: text){ ans += (i == character); } return ans; }
long power(long base, long exponent, long module){ if(exponent % 2){ return power(base, exponent - 1, module) * base % module; }else if(exponent){ long root_ans = power(base, exponent / 2, module); return root_ans * root_ans % module; }else{ return 1; }}
struct position{ int y, x; }; position move_pattern[4] = {{-1, 0}, {0, 1}, {1, 0}, {0, -1}}; // double euclidean(position first, position second){ return sqrt((second.x - first.x) * (second.x - first.x) + (second.y - first.y) * (second.y - first.y)); }
template<class T, class U> string to_string(pair<T, U> x){ return to_string(x.first) + "," + to_string(x.second); }
template<class itr> void array_output(itr start, itr goal){ string ans; for(auto i = start; i != goal; i++){ ans += to_string(*i) + " "; } ans.pop_back(); cout << ans << endl; }
template<class itr> void cins(itr start, itr goal){ for(auto i = start; i != goal; i++){ cin >> (*i); } }
template<class T> T gcd(T a, T b){ if(a && b){ return gcd(min(a, b), max(a, b) % min(a, b)); }else{ return a; }} template<class T> T lcm(T a, T b){ return a / gcd(a, b) * b; }
#define mod long(998244353)
#define all(x) (x).begin(), (x).end()
#define bitcount(n) __builtin_popcountl(long(n))
#define fcout cout << fixed << setprecision(10)
#define highest(x) (63 - __builtin_clzl(x))

int main(){
    int N;
    long X;
    cin >> N >> X;
    long ans;
    cin >> ans;
    ans = abs(X - ans);
    for(int i = 1; i < N; i++){
        long x;
        cin >> x;
        ans = gcd(ans, abs(X - x));
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<iostream> 
#include<bits/stdc++.h> 
using namespace std;
int main(){ 
	ios::sync_with_stdio(false); 
	cin.tie(0); 
	string s,t;
	cin>>s>>t; 
	int m=s.size();
	int n=t.size();
	vector<vector<int>> dp(m+1,vector<int>(n+1)); 
	for(int i=0;i<=m;i++){ 
		for(int j=0;j<=n;j++){ 
			if(i==0 || j==0){ 
				dp[i][j]=0;
			}else if(s.at(i-1)==t.at(j-1)){ 
				dp[i][j]=dp[i-1][j-1]+1;
			}else{
				dp[i][j]=max(dp[i][j-1],dp[i-1][j]); 

			} 
		} 
	}
	int i=m;
	int j=n;
	string lcs="";
	while(i>0 and j>0){ 
		if(s.at(i-1)==t.at(j-1)){
			lcs=s.at(i-1)+lcs;
			i--;
			j--;
		}else{ 
			dp[i-1][j]>dp[i][j-1]?i--:j--;
		}
	}
	cout<<lcs;


	
	return 0;
} 



Measured memory_bytes: 35584
#include<bits/stdc++.h>
#include<cmath>
#define pb push_back
#define ld long double
#define mp make_pair
#define vl vector<ll> 
#define vd vector<double>
#define vld vector<long double>
#define ll long long int
#define pl pair<ll, ll>
#define all(a) a.begin(), a.end()
#define forr(i, n) for(ll i=0; i<n; i++) 
#define forr1(i, n) for(ll i=1; i<=n; i++)
using namespace std;
const ld PI =3.1415926535897923846;
const ll MOD = 1000000007;
const ll N=998244353;
ll power(ll x,ll n){ll res=1;while(n>0){if(n&1) res=res*x%MOD;x=x*x%MOD;n>>=1;}return res;}
ll modinverse(ll a){return power(a, MOD-2);}
void solve()
{
    ll n;
    cin>>n;
    vl d(n);
    forr(i, n)
    {
    	ll x, y;
    	cin>>x>>y;
    	d[i]=(x-y);
    }
    forr(i, n)
    {
    	if(i+2<n&&d[i]==0)
    	{
    		if(d[i+1]==0&&d[i+2]==0)
    		{
    			cout<<"Yes";
    			return;
    		}
    	}
    }
    cout<<"No\n";
}
int main()
{
	#ifndef ONLINE_JUDGE
        // for getting input from input.txt
        freopen("input.txt", "r", stdin);
        // for writing output to output.txt
        freopen("output.txt", "w", stdout);
    #endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll test=1;
    //cin>>test;
    while(test--)
    {
        solve();
    }
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
}

Measured memory_bytes: 3844
n = int(input())
data = []
cnt = 0
while True:
    patt, num = map(str, input().split())
    data.append([patt, num])
    cnt += 1
    if cnt == n:
        break


s = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]
h = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]
c = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]
d = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]
for i in range(len(data)):
    if data[i][0] == 'S':
        s.remove(int(data[i][1]))
    
    elif data[i][0] == 'H':
        h.remove(int(data[i][1]))
    
    elif data[i][0] == "C":
        c.remove(int(data[i][1]))
    
    else:
        d.remove(int(data[i][1]))

for i in range(len(s)):
    print("S", s[i])

for i in range(len(h)):
    print("H", h[i])

for i in range(len(c)):
    print("C", c[i])

for i in range(len(d)):
    print("D", d[i])


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

int main(){
  int N, M;
  cin >> N >> M;
  map<int, int> AC, WA;
  for(int i=0; i<M;i++){
    int p;
    string s;
    cin >> p >> s;
    if(AC.count(p)) continue;
    if(s=="AC"){
      AC.emplace(p, 0);
    }
    if(s=="WA"){
      if(WA.count(p)){
        WA.at(p)+=1;
      }
      if(WA.count(p)==0){
        WA.emplace(p, 1);
      }
    }
  }
  int ac = AC.size();
  int wa=0;
  for(auto a: WA){
    if(AC.count(a.first)){
      wa+=a.second;
    }
  }
  cout << ac << " " << wa << endl;
  return 0;
}

Measured memory_bytes: 4992
# -*- coding:utf-8 -*-
import collections

n = int(input())
sl = input().split()

sl1 = sl[0::2]
sl2 = sl[1::2]
c1 = collections.Counter(sl1)
c2 = collections.Counter(sl2)
mc1k = c1.most_common()[0][0]
mc1v = c1.most_common()[0][1]
mc2k = c2.most_common()[0][0]
mc2v = c2.most_common()[0][1]

if mc1k == mc2k:
    mc1ks = len(c1.most_common())
    mc2ks = len(c2.most_common())
    if mc1ks > 1 and mc2ks > 1:
        mc1_2v = c1.most_common()[1][1]
        mc2_2v = c2.most_common()[1][1]
        if mc1_2v > mc2_2v:
            mc1v = mc1_2v
        else:
            mc2v = mc2_2v
    elif mc1ks > 1:
        mc1_2v = c1.most_common()[1][1]
        mc1v = mc1_2v
    elif mc2ks > 1:
        mc2_2v = c2.most_common()[1][1]
        mc2v = mc2_2v
    else:
        mc2v = 0
print(n - mc1v - mc2v)


Measured memory_bytes: 22764
//----------------------------------------------------------------------
#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(void) {
    int n;
    int x, y;
    cin >> n >> x >> y;
    vector<int> ans(n);

    vector<vector<int>> connect;
    connect.resize(n);
    rep(i,n-1) {
        connect[i].push_back(i+1);
        connect[i+1].push_back(i);
    }
    connect[x-1].push_back(y-1);
    connect[y-1].push_back(x-1);

    for(int i = 0; i < n-1; ++i) {
        vector<int> dist(n,-1);
        queue<int> que;
        dist[i] = 0;
        que.push(i);

        while(!que.empty()) {
            int v = que.front();
            que.pop();
            for(int nv : connect[v]) {
                if(dist[nv] != -1 ) continue;
                dist[nv] = dist[v] + 1;
                que.push(nv);
            }
        }
        for(int j = 0; j < n; j++) {
            if(dist[j] != -1 && j > i) {
               ans[dist[j]]++;
            }
        }
    }

    for(int i = 1; i <=n-1; i++) {
        cout << ans[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 384
#include <stdio.h>
#include <string.h>

int main()
{
  char a[200];
  int flag, end = 0;
  scanf("%s", a);
  
  int l = strlen(a);
  while((l >= 2) && (end == 0)){
    l -= 2;
    flag = 0;
    for(int i = 0; i < l/2; i++){
      if(a[i] == a[l/2 + i]) flag++; 
    }
    if(flag == l/2){
      printf("%d\n", 2 * flag);
      end = 1;
    }
  }
  return 0;
}


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

typedef long long ll;
typedef long double ld;

#define pb push_back
#define sort(s) sort(s.begin(),s.end())
#define reverse(s) reverse(s.begin(),s.end())
#define rep(i,n) for(ll (i)=0;(i)<(n);(i)++)

const ll mod = 1e9+7;

//最大公約数
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;
}

//素数判定
bool isPrime(ll x){
    ll i;
    if(x < 2)return 0;
    else if(x == 2) return 1;
    if(x%2 == 0) return 0;
    for(i = 3; i*i <= x; i += 2) if(x%i == 0) return 0;
    return 1;
}

//桁和
int digsum(ll n) {
    int res = 0;
    while(n > 0) {
        res += n%10;
        n /= 10;
    }
    return res;
}

//桁数
int dignum(ll n) {
    int res = 0;
    while(n > 0) {
        res++;
        n /= 10;
    }
    return res;
}

//文字列中の特定の文字カウント
ll stringcount(string s,char c){
    return count(s.cbegin(),s.cend(),c);
}

//階乗
ll ka(ll i){
    ll res=1;
    while(i>0){
        res=res*i;
        i--;
    }
    return res;
}
 
//ncr
ll ncr(ll x,ll y){
    ll a = x;
    ll b = 1;
    if(y>(x/2)){
        y=x-y;
    }
    for(ll i=1;i<y;i++){
        a*=x-i;
        b*=i+1;
    }
    return a/b;
}

//フィボナッチ数列 -92
ll f(ll x){
    ll dp[x+1];
    dp[1]=1;
    dp[2]=1;
    for(ll i=3;i<=x;i++){
        dp[i]=dp[i-1]+dp[i-2];
    }
    return dp[x];
}



int main(){
    int n;
    cin >> n;
    int p[n];
    rep(i,n)cin >> p[i];

    vector<int> ans(n);

    for(int i=0;i<n;i++){
        int x = p[i];
        ans[x-1] = i+1;
    }

    for(int i=0;i<n;i++){
        cout << ans[i] << " ";
    }
    cout << endl;
}

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

#define debug(x) cerr<<#x<<'='<<x<<endl
#define set0(x) memset(x,0,sizeof(x))
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pii;
template<typename T> void read(T &x){
	x = 0;char ch = getchar();ll f = 1;
	while(!isdigit(ch)){if(ch == '-')f*=-1;ch=getchar();}
	while(isdigit(ch)){x = x*10+ch-48;ch=getchar();}x*=f;
}

int n,k,s;
int main() {
	read(n);read(k);read(s);
	for(int i=0;i<k;i++){
		cout<<s<<' ';
	}
	for(int i=0;i<n-k;i++){
		if(s>30000)cout<<s-1<<' ';
		else cout<<s+1<<' ';
	}
	cout<<endl;
	return 0;
}


Measured memory_bytes: 1280
//
// Created by Ellen7ions on 2020/9/28.
//

#include <iostream>
#define oo 0x7fffff

namespace MyNameIsLzz {

    int N, M, X;

    int map[15][15];
    int C[15];
    int val[15];
    int ans = oo;

    void dfs(int cur, int sum) {
        if (cur == N) {
            for (int i = 0; i < M; i++)
                if (val[i] < X)
                    return;
            ans = std::min(ans, sum);
            return;
        }
        for (int i = 0; i < M; i++) val[i] += map[cur][i];
        dfs(cur + 1, sum + C[cur]);
        for (int i = 0; i < M; i++) val[i] -= map[cur][i];

        dfs(cur + 1, sum);
    }

    void solve() {
        std::cin >> N >> M >> X;
        for (int i = 0; i < N; i++) {
            std::cin >> C[i];
            for (int j = 0; j < M; j++) std::cin >> map[i][j];
        }
        dfs(0, 0);
        if (ans != oo)
            std::cout << ans << std::endl;
        else
            std::cout << -1 << std::endl;
    }
}
int main() {
    MyNameIsLzz::solve();
    return 0;
}

Measured memory_bytes: 3600
#include <stdio.h>

int main()
{
	int h,w,i,n;
	
	while(1){
		scanf("%d %d",&h,&w);
		
		if(h == 0 && w == 0) break;
		
		for(i = 0; i < h ; i++){
			for(n=0;n<w;n++)printf("#");
			printf("\n");
		}
			printf("\n");
		}
	
	return 0;
}

Measured memory_bytes: 572
#include <iostream>
#include <stdio.h>
#include <cmath>
using namespace std;

int main(){
    int n;
    cin >> n;
    double x[n]={ };
    double y[n]={ };
    double s[n]={ };
    double s1=0,s2=0,s3=0,ans=0;
    for(int i=0;i<n;i++){
        cin>>x[i];
    }
    for(int i=0;i<n;i++){
        cin>>y[i];
    }
    for(int i=0;i<n;i++){
        s1+=abs(x[i]-y[i]);
        s2+=abs((x[i]-y[i])*(x[i]-y[i]));
        s3+=abs((x[i]-y[i])*(x[i]-y[i])*(x[i]-y[i]));
    }
    printf("%8lf\n",s1);
    printf("%8lf\n",sqrt(s2));
    printf("%8lf\n",pow(s3,1.0/3.0));
    
    for(int i=0;i<n;i++){
        s[i]=abs(x[i]-y[i]);
        if(i==0){
            ans=s[i];
        }
        else if(s[i]>ans){
            ans =s[i];
        }
    }
    printf("%8lf\n",ans);
    return 0;
}


Measured memory_bytes: 3372
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;

int main() {
	pair<pair<string, int>, int> p[110];
	int n; cin >> n;
	string name;
	int t;
	for (int i = 0; i < n; i++) {
		cin >> name >> t;
		p[i] = make_pair(make_pair(name, -t), i);
	}

	sort(p, p + n);

	for (int i = 0; i < n; i++)
		cout << p[i].second + 1 << endl;

	return 0;
}

Measured memory_bytes: 256
A, B = map(int, input().split())
S = list(input())
nums = list(map(str, range(10)))
if S[A] == "-":
    for char in S[:A] + S[A + 1:]:
        if char not in nums:
            print("No")
            break
    else:
        print("Yes")

else:
    print("No")


Measured memory_bytes: 3060
n = int(input())
a = sorted(list(map(int,input().split())),reverse = True)
use = []
flag = -1
for i in range(n):
  if flag == a[i]:
    use.append(a[i])
    flag = -1
  else:
    flag = a[i]
if len(use)<2:
  print(0)
else:
  use.sort(reverse =True)
  print(use[0]*use[1])

Measured memory_bytes: 62704
#include <algorithm>
#include <cmath>
#include <deque>
#include <iostream>
#include <numeric>
#include <sstream>
#include <string>
#include <string.h>
#include <vector>

#define REP(i,x) for(int i{ 0 }; i < (int)(x); i++)
#define REPC(i,x) for(int i{ 0 }; i <= (int)(x); i++)
#define RREP(i,x) for(int i{ (int)(x) - 1 }; i >= 0 ;i--)
#define RREPC(i,x) for(int i{ (int)(x)}; i >= 0; i--)
#define REP1O(i,x) for(int i{ 1 }; i < (int)(x); i++)
#define REP1C(i,x) for(int i{ 1 }; i <= (int)(x); i++)

#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()

using namespace std;

typedef int64_t ll;
typedef pair<int, int> pii;

const int dx[4] = { 1, 0, -1,  0 };
const int dy[4] = { 0, 1,  0, -1 };
const int INTMAX = 2147483647;
const ll LLMAX = 9223372036854775807;

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; }
void SWAP(ll& a, ll& b) { a ^= b; b ^= a; a ^= b; }
void SWAP(int& a, int& b) { a ^= b; b ^= a; a ^= b; }

class D {
	string s;
	int L;
	int ans;
public:
	D()
	{
		cin >> s;
		L = SZ(s);
		ans = INTMAX;
	}
	void solve()
	{

		REP(i, L - 1)
		{
			if (s[i] != s[i + 1])
				chmin(ans, max(i + 1, L - i - 1));
		}

		if (ans == INTMAX)
		{
			cout << L << endl;
		}
		else
			cout << ans << endl;

	}
};


int main()
{
	D solution;
	solution.solve();

	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
const lint mod = 1e6 + 3;
#define all(x) (x).begin(), (x).end()
#define bitcount(n) __builtin_popcountl((lint)(n))
#define fcout cout << fixed << setprecision(15)
#define highest(x) (63 - __builtin_clzl(x))
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T = string, class U = char>int character_count(T text, U character){ int ans = 0; for(U i: text){ ans += (i == character); } return ans; }
lint power(lint base, lint exponent, lint module){ if(exponent % 2){ return power(base, exponent - 1, module) * base % module; }else if(exponent){ lint root_ans = power(base, exponent / 2, module); return root_ans * root_ans % module; }else{ return 1; }}
struct position{ int y, x; }; position mv[4] = {{0, -1}, {1, 0}, {0, 1}, {-1, 0}}; // double euclidean(position first, position second){ return sqrt((second.x - first.x) * (second.x - first.x) + (second.y - first.y) * (second.y - first.y)); }
template<class T, class U> string to_string(pair<T, U> x){ return to_string(x.first) + "," + to_string(x.second); } string to_string(string x){ return x; }
template<class itr> void array_output(itr start, itr goal){ string ans; for(auto i = start; i != goal; i++) ans += to_string(*i) + " "; if(!ans.empty()) ans.pop_back(); cout << ans << endl; }
template<class itr> void cins(itr first, itr last){ for(auto i = first; i != last; i++){ cin >> (*i); } }
template<class T> T gcd(T a, T b){ if(a && b){ return gcd(min(a, b), max(a, b) % min(a, b)); }else{ return a; }} template<class T> T lcm(T a, T b){ return a / gcd(a, b) * b; }
struct combination{ vector<lint> fact, inv; combination(int sz) : fact(sz + 1), inv(sz + 1){ fact[0] = 1; for(int i = 1; i <= sz; i++){ fact[i] = fact[i - 1] * i % mod; } inv[sz] = power(fact[sz], mod - 2, mod); for(int i = sz - 1; i >= 0; i--){ inv[i] = inv[i + 1] * (i + 1) % mod; } } lint C(int p, int q) const{ if(q < 0 || p < q) return 0; return (fact[p] * inv[q] % mod * inv[p - q] % mod); } };
template<class itr> bool next_sequence(itr first, itr last, int max_bound){ itr now = last; while(now != first){ now--; (*now)++; if((*now) == max_bound){ (*now) = 0; }else{ return true; } } return false; }

vector<lint> factorial{1};

int main(){
    int Q;
    cin >> Q;
    for(int i = 1; i <= 1e7; i++){
        lint num = factorial.back() * i % mod;
        factorial.push_back(num);
    }
    for(int i = 0; i < Q; i++){
        lint x, d, n;
        cin >> x >> d >> n;
        if(d == 0){
            cout << power(x, n, mod) << endl;
        }else if(n >= mod){
            cout << 0 << endl;
        }else if(x == 0){
            cout << 0 << endl;
        }else{
            lint empty = x * power(d, mod - 2, mod) % mod;
            cout << factorial[empty + n - 1] * power(factorial[empty - 1], mod - 2, mod) % mod * power(d, n, mod) % mod << endl;
        }
    }
}


Measured memory_bytes: 133340
N=int(input())
S=input()
c = 0
rgb = S.count('R')*S.count('G')*S.count('B')
for i in range(N-2):
  for j in range(i+1, N-1):
    if 2*j - i < N:
      if (S[i] != S[j] and S[i] != S[2*j-i] and S[j] != S[2*j-i]):
        c+=1
print(rgb-c)

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

using namespace std;

using ll = long long;

int main(void) {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n;
    cin >> n;
    vector<pair<string, int>> arr1(n), arr2(n);
    for (int i = 0; i < n; i++) {
        cin >> arr1[i].first;
        arr1[i].second = i;
        arr2[i].first = arr1[i].first;
        arr2[i].second = i;
    }
    // bubble sort
    for (int i = 0; i < n; i++) {
        for (int j = n - 1; j >= i + 1; j--) {
            if (arr1[j].first[1] - '0' < arr1[j - 1].first[1] - '0')
                swap(arr1[j], arr1[j - 1]);            
        }
    }
    bool ok = false;
    for (int i = 0; i < n - 1; i++) {
        if (arr1[i].first[1] == arr1[i + 1].first[1] && arr1[i].second > arr1[i + 1].second) {
            ok = true;
            break;
        }
    }
    for (int i = 0; i < n - 1; i++) cout << arr1[i].first << " ";
    cout << arr1[n - 1].first << '\n';
    if (ok) cout << "Not stable\n";
    else cout << "Stable\n";
    // selection sort
    for (int i = 0; i < n; i++) {
        int mini = i;
        for (int j = i; j < n; j++) {
            if (arr2[j].first[1] < arr2[mini].first[1])
                mini = j;
        }
        swap(arr2[i], arr2[mini]);
    }
    ok = false;
    for (int i = 0; i < n - 1; i++) {
        if (arr2[i].first[1] == arr2[i + 1].first[1] && arr2[i].second > arr2[i + 1].second) {
            ok = true;
            break;
        }                
    }        
    for (int i = 0; i < n - 1; i++) cout << arr2[i].first << " ";
    cout << arr2[n - 1].first << '\n';
    if (ok) cout << "Not stable\n";
    else cout << "Stable\n";
    return 0;
}


Measured memory_bytes: 3200
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rng(i, a, b) for (int i = int(a); i < int(b); i++)
#define rep(i, b) rng(i, 0, b)
#define gnr(i, a, b) for (int i = int(b) - 1; i >= int(a); i--)
#define per(i, b) gnr(i, 0, b)
#define bg begin()
#define ed end()
#define all(x) x.bg, x.ed
#define vi vector<int>
template <class t, class u>
bool chmax(t &a, u b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}
template <class t, class u>
bool chmin(t &a, u b)
{
    if (b < a)
    {
        a = b;
        return true;
    }
    return false;
}

//ll mod = 1000000007;
ll mod = 998244353;
ll powmod(ll a, ll b)
{
    if (b == 0)
    {
        return 1;
    }
    if (b == 1)
    {
        return a;
    }
    else if (b % 2 == 0)
    {
        return powmod((a * a) % mod, b / 2);
    }
    else
    {
        return (a * powmod((a * a) % mod, b / 2)) % mod;
    }
}

signed main()
{
    ll n;
    cin >> n;
    vi v(n);
    int dmax = 0;
    bool f = false;
    rep(i, n)
    {
        int d;
        cin >> d;
        if (i == 0 && d != 0)
        {
            f = true;
        }
        v[d]++;
        chmax(dmax, d);
    }
    if (f)
    {
        cout << 0 << endl;
        return 0;
    }
    if (v[0] > 1)
    {
        cout << 0 << endl;
        return 0;
    }
    ll ans = 1;
    for(int i = 1; i <=dmax;i++)
    {
        ans = ans * powmod(v[i - 1], v[i]) % mod;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3752
N,M = map(int,input().split())
p = [i-1 for i in map(int,input().split())]
swap = []
for j in range(M):
    swap.append([i-1 for i in map(int,input().split())])


# 0からn-1まで
n = N

#初期化
par = []
rank = []
for i in range(n):
    par.append(i) # par[i]==iの時root
    rank.append(0) # 深さ
    
def find(x): # rootの探索&縮約
    if par[x]==x:
        return x
    else:
        par[x]=find(par[x])
        return par[x]

def unite(x,y):
    x = find(x)
    y = find(y)
    if x==y:
        return
    elif rank[x]<rank[y]:
        par[x]=y
    else:
        par[y]=x
        if rank[x]==rank[y]:
            rank[x] += 1

for s in swap:
    unite(s[0],s[1])


def same(x,y):
    return find(x)==find(y)

answer = 0
for i in range(N):
    if same(i,p[i]):
        answer += 1
print(answer)
    

Measured memory_bytes: 31036
#include <stdio.h>

#define MAX 100000

struct TRAMP{
	char mark;
	int number;
};

TRAMP cards[MAX];

struct Node{
	Node(){
		number = 0;
		mark_array_index = 0;
		l_p = r_p = p_p = -1;
	}
	int number, mark_array_index,l_p,r_p,p_p;
	char mark_array[5];
};

class Tree{
public:
	Tree(){
		num_of_nodes = 0;
		nodes = new Node[MAX];
	};
	~Tree(){
		delete[] nodes;
	}
	void push(TRAMP data){
		int t = 0;
		while(true){
			if(num_of_nodes == 0){
				nodes[num_of_nodes].number = data.number;
				nodes[num_of_nodes].mark_array[nodes[num_of_nodes].mark_array_index++] = data.mark;
				num_of_nodes++;
				break;
			}else{
				if(nodes[t].number == data.number){
					nodes[t].mark_array[nodes[t].mark_array_index++] = data.mark;
					break;
				}else if(nodes[t].number > data.number){
					if(nodes[t].l_p == -1){
						nodes[t].l_p = num_of_nodes;
						nodes[num_of_nodes].p_p = t;
						nodes[num_of_nodes].number = data.number;
						nodes[num_of_nodes].mark_array[nodes[num_of_nodes].mark_array_index++] = data.mark;
						num_of_nodes++;
						break;
					}else{
						t = nodes[t].l_p;
					}
				}else{
					if(nodes[t].r_p == -1){
						nodes[t].r_p = num_of_nodes;
						nodes[num_of_nodes].p_p = t;
						nodes[num_of_nodes].number = data.number;
						nodes[num_of_nodes].mark_array[nodes[num_of_nodes].mark_array_index++] = data.mark;
						num_of_nodes++;
						break;
					}else{
						t = nodes[t].r_p;
					}
				}
			}
		}
	}

	bool compare(int cards_index){
		int k = 0,number = cards[cards_index].number,t=0;

		while(true){
			if(nodes[t].number == number)
				break;
			else{
				t = (nodes[t].number > number) ? nodes[t].l_p:nodes[t].r_p;
			}
		}

		while(number == cards[cards_index].number){
			if(cards[cards_index].mark != nodes[t].mark_array[k])
				return false;
			else{
				cards_index++;
				k++;
			}
		}
		return true;
	}

private:
	int num_of_nodes;
	Node* nodes;
};


int n;

int Partition(int left,int right){
	int i = left-1,pivot = cards[right].number;
	TRAMP tmp;
	for(int start = left; start < right; start++){
		if(cards[start].number <= pivot){
				i++;
				tmp = cards[i];
				cards[i] = cards[start];
				cards[start] = tmp;
		}
	}

	tmp = cards[right];
	cards[right] = cards[i+1];
	cards[i+1] = tmp;

	return i+1;
}

void quickSort(int left,int right){
	if(left < right){
		int q = Partition(left,right);
		quickSort(left,q-1);
		quickSort(q+1,right);
	}
}


int main(){

	Tree tree;
	bool stableFLG = true;
	scanf("%d",&n);

	for(int i = 0; i < n; i++){
		scanf("%s %d",&cards[i].mark,&cards[i].number);
		tree.push(cards[i]);
	}

	quickSort(0,n-1);

	int history = 0;
	for(int i = 1; i < n; i++){
		if(cards[history].number != cards[i].number || i == n-1){
			if(!tree.compare(history)){
				stableFLG = false;
				break;
			}else{
				history = i;
			}
		}
	}

	if(stableFLG){
		printf("Stable\n");
	}else{
		printf("Not stable\n");
	}

	for(int i = 0; i < n; i++)	printf("%c %d\n",cards[i].mark,cards[i].number);
}

Measured memory_bytes: 4440
def exp2(n):
	ans = 1
	for i in range(0, n):
		ans = ans * 2
	return ans

S = list(raw_input())
opnumber = exp2(len(S)-1)
ans = 0

for i in range(0, opnumber):
	tmp = i
	numlst = []
	n = S[0]
	for j in range(1, len(S)):
		if tmp%2 == 1:
			numlst.append(int(n))
			n = ''
		n = n + S[j]
		tmp = tmp / 2
	numlst.append(int(n))
	for j in range(0, len(numlst)):
		ans = ans + numlst[j]

print ans

Measured memory_bytes: 2692
#include <iostream>
#include <vector>
#include <string>
using namespace std;
typedef pair<int, int> P;

void solve()
{
	vector<P> Num(9);
	vector<string> str(9);

	for(int i = 0; i < 9; ++i)
	{
		cin >> str[i] >> Num[i].first >> Num[i].second;
	}
	for(int i = 0; i < 9; ++i)
	{
		cout << str[i] << " " << Num[i].first + Num[i].second << " " << Num[i].first * 200 + Num[i].second * 300 << endl;
	}
}

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

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define all(x) begin(x), end(x)
#define dbg(x) cerr << #x << " = " << x << endl
#define _ << ' ' <<
using namespace std;
using ll = long long;
using vi = vector<int>;


int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int x, t;
    cin >> x >> t;
    cout << max(0, x - t);
}


Measured memory_bytes: 256
// inputに入力データ全体が入る
function Main(input) {
	var input = input.split("\n");
	var answer;

	// input = input.map((x) => parseInt(x, 10));

	var hands = {
		a: input[0].split(''),
		b: input[1].split(''),
		c: input[2].split(''),
	};

	var currentPlayer = 'a';

	while (true) {
		currentCard = hands[currentPlayer].shift();

		if (currentCard) {
			currentPlayer = currentCard;
		} else {
			answer = currentPlayer.toUpperCase();
			break;
		}
	}


	// 出力
	console.log(answer);
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 7372
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
const int INF = 1 << 28;
const ll MOD = 1'000'000'007;
template <class T> bool chmax(T &a, const T &b) { return (a < b) ? (a = b, 1) : 0; }
template <class T> bool chmin(T &a, const T &b) { return (b < a) ? (a = b, 1) : 0; }

int main() {
    int a, p;
    cin >> a >> p;
    int ret = a * 3 + p;
    cout << ret / 2 << endl;
    return 0;
}

Measured memory_bytes: 256
import math
A,B,H,M=list(map(int,input().split()))
argH=30*H+(30/60)*M
argM=6*M
sita=math.radians(min(abs(argH-argM),abs(argH-argM)))
ans=math.sqrt(A**2+B**2-2*A*B*(math.cos(sita)))
print(ans)

Measured memory_bytes: 9504
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;

int N,L,R,ans;

int main()
{
	scanf("%d",&N);
	for (int i=1; i<=N; i++)
	{
		scanf("%d %d",&L,&R);
		ans+=R-L+1;
	}
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int,input().split()))
x = min(a)
y = max(a)
ans = 10 ** 12
for i in range(x,y+1):
    m = 0
    for j in a:
        m += (j-i) ** 2
    ans = min(ans,m)
print(ans)

Measured memory_bytes: 9200
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
public class ABC
{
    public static void Main()
    {
        int[] x = Console.ReadLine().Split().Select(int.Parse).ToArray();
        int A = x[0];
        int P = x[1];
        P += A * 3;
        Console.WriteLine(P / 2);

    }
}

Measured memory_bytes: 13268
#n, m = map(int,input().split())
s = int(input())
#ls = list(map(int,input().split()))
#ls = [list(map(int,input().split()))[1:] for i in range(n)]
#s = input()

ls = [s]

def f(n):
  if n%2 == 0:
    return int(n/2)
  elif n%2 == 1:
    return int(3 * n + 1)

for i in range(1000000):
  num = f(ls[i])
  if ls.count(num) == 1:
    print(len(ls)+1)
    quit()
  ls.append(num)

Measured memory_bytes: 3060
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
using namespace std;
const int mod = 1000000007;
#define ll long long

int main()
{
	string s;
	for (int i = 0; i < 3; i++) {
		cin >> s;
		cout << (char)(s[0] - 'a' + 'A');
	}
	cout << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, K;
  cin >> N >> K;
  vector<int> vec(N, 1);
  for(int i = 0; i < K; i++) {
    int d;
    cin >> d;
    for(int j = 0; j < d; j++) {
      int a;
      cin >> a;
      if(vec.at(a - 1) = 1) {
        vec.at(a - 1) *= 10000;
      }
    }
  }
  int sum = 0;
  for(int i = 0; i < N; i++) {
    sum += vec.at(i);
  }
  cout << N - sum / 10000 << endl;
}

Measured memory_bytes: 3636