akhauriyash/Code-Regression huggingface dataset:
#include <malloc.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

//ABC179D
//ABC179C
//ABC179B
//ABC179A

int main(void) {
  int n, k, i, cou=0, tmp;
  char s[2000], a='es', b='s';
  scanf("%s", s);
  for(i=0; s[i] != '\0'; ++i); //文字数
  printf("%s", s);
  if(s[i-1]=='s') printf("es");
  else  printf("s");
  return 0;
}


Measured memory_bytes: 1736
import math

a,b = map(int,input().split())
x = []
for i in range(a):
    t= list(map(int,input().split()))
    x.append(t)
# print(x)
res = 0
for i in range(a):
    for j in range(i,a):
        if i == j :continue

        s = 0
        # print((x[i],x[j]))
        for k,t in zip(x[i],x[j]):
            p = (k-t)**2
            s+=p
        # print((math.sqrt(s)),int(math.sqrt(s)))
        res += (math.sqrt(s))==int(math.sqrt(s))
print(res)
            

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
struct data{
  double x,y;
}a[10];
struct aa{
  long id,val;
}b[10];
bool cmp(aa u, aa v){
   return u.val < v.val;
}
long n,d[10],f[10];
double res;
double tinh(long i, long j){
  double X = a[i].x - a[j].x;
  double Y = a[i].y - a[j].y;
  return sqrt(X*X+Y*Y);
}
void xuat(){
  for(long i = 1; i <= n; i++){
    b[i].val = f[i];
    b[i].id = i;
  }
  sort(b+1,b+1+n,cmp);
  for(long i = 2; i <= n; i++){
    res += tinh(b[i-1].id,b[i].id);
  }
}
void hoanvi(long s){

  for(long i = 1; i <= n; i++){
    if( d[i] ) continue;
    f[s] = i;
    d[i] = 1;
    if(s == n) xuat();
    else hoanvi(s+1);
    d[i] = 0;
  }

}
int main(){
   cin >> n;
   for(long i = 1; i <= n; i++) cin >> a[i].x >> a[i].y;
   res = 0;
   hoanvi(1);
   double tmp = 1;
   for(long i = 1; i <= n; i++) tmp *= double(i);
   cout << setprecision(10) << fixed << res/tmp;
}


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

ab_list = []
tree_dict = {}
for i in range(N-1):
    a, b = map(int, input().split())
    ab_list.append(a)
    ab_list.append(b)

    if a not in tree_dict:
        tree_dict[a] = [b]
    else:
        tree_dict[a].append(b)

value_list = list(set(ab_list))

px_dict = {}
for i in range(Q):
    p, x = map(int, input().split())
    if p in px_dict:
        px_dict[p] += x
    else:
        px_dict[p] = x

out = ""
for v in value_list:
    if v in px_dict:
        x = px_dict[v]
        if v in tree_dict:
            tree_list = tree_dict[v]
            for t in tree_list:
                if t in px_dict:
                    px_dict[t] += x
                else:
                    px_dict[t] = x
        o = str(px_dict[v])
    else:
        o = str(0)
    out += o + " "

print(out[:-1])

Measured memory_bytes: 90960
N = int(input())
R = []
for i in range(N):
    R.append(input().split())
    R[i].append(0)
R.sort(key=lambda x:(-int(x[1])))

B = []
for i in range(N):
    B.append(input().split())
    B[i].append(0)
B.sort(key=lambda x:(int(x[0]),int(x[1])))

a = 0
for i in range(N):
    for j in range(N):
        if int(R[j][0]) < int(B[i][0]) and int(R[j][1]) < int(B[i][1]) and R[j][2] == 0 and B[i][2] == 0:
            a += 1
            R[j][2] = j+1
            B[i][2] = j+1
            break

print(a)


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

using namespace std;

int a[2][256];
int main() {
	int n, p = 1e9 + 7;
	cin >> n;
	a[1][255] = 1;
	for (int i = 0; i < n; i++) {
		fill(a[i & 1], a[i & 1] + 256, 0);
		for (int j = 0; j < 1024; j++)
			(a[i & 1][j & 0xff] += a[~i & 1][j >> 2]) %= p;
		for (int j = 0; j < 4; j++) {
			a[i & 1][j * 64 + 9] = 0;
			a[i & 1][j * 64 + 33] = 0;
			a[i & 1][j * 64 + 6] = 0;
			a[i & 1][j * 16 + 9] = 0;
			a[i & 1][j * 4 + 33] = 0;
		}
	}
	int r = 0;
	for (int i = 0; i < 256; i++)
		(r += a[~n & 1][i]) %= p;
	cout << r << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <math.h>
#include <map>
#define MOD 1000000007
typedef long long ll;
using namespace std;

class DisjointSet{
public:
  vector<int> rank,p;

  DisjointSet(){}
  DisjointSet(int size){
    rank.resize(size,0);
    p.resize(size,0);
    for(int i=0;i<size;i++) makeSet(i);
  }

  void makeSet(int x){
    p[x]=x;
    rank[x]=0;
  }

  bool same(int x,int y){
    return findSet(x)==findSet(y);
  }

  void unite(int x,int y){
    link(findSet(x),findSet(y));
  }

  void link(int x,int y){
    if(rank[x]>rank[y]){
      p[y]=x;
    }else{
      p[x]=y;
      if(rank[x]==rank[y]){
        rank[y]++;
      }
    }
  }

  int findSet(int x){
    if(x!=p[x]){
      p[x]=findSet(p[x]);
    }
    return p[x];
  }
};

int main(){
  int n,k,l;
  cin>>n>>k>>l;

  DisjointSet dsa(n);
  DisjointSet dsb(n);
  for(int i=0;i<k;i++){
    int p,q;
    cin>>p>>q;
    p--;
    q--;
    dsa.unite(p,q);
  }
  for(int i=0;i<l;i++){
    int r,s;
    cin>>r>>s;
    r--;
    s--;
    dsb.unite(r,s);
  }

  map<pair<int,int>,int> mp;
  for(int i=0;i<n;i++){
    mp[make_pair(dsa.findSet(i),dsb.findSet(i))]++;
  }

  for(int i=0;i<n;i++){
    cout<<mp[make_pair(dsa.findSet(i),dsb.findSet(i))]<<" ";
  }
  cout<<endl;

  return 0;
}


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

int main() {
    long long int N, D;
    std::cin >> N >> D;

    int count = 0;
    for (int i = 0; i < N; i++) {
        long long int x, y;
        std::cin >> x >> y;
        if (std::sqrt(x * x + y * y) > D) {
        } else {
            count++;
        }
    }
    std::cout << count << std::endl;
}


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

int main() {
    cout<< fixed << setprecision(20);
    int n;
    cin >> n;
    vector<double> x(n), y(n);
    for (int i = 0; i < n; ++i) cin >> x[i] >> y[i];
    vector<int> sample(n);
    for (int i = 0; i < n; ++i) sample[i] = i;
    double sum = 0;
    do for (int i = 0; i < n - 1; ++i) sum += sqrt((x[sample[i]] - x[sample[i + 1]]) * (x[sample[i]] - x[sample[i + 1]]) + (y[sample[i]] - y[sample[i + 1]]) * (y[sample[i]] - y[sample[i + 1]])); while (next_permutation(sample.begin(), sample.end()));
    for (int i = 1; i <= n; ++i) sum /= (double)i;
    cout << sum << endl;
}


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

int main()
{
int N,Y;scanf("%d %d",&N,&Y);
for(int man=0;man<(Y/10000)+1;man++)for(int fsen=0;fsen<((Y-man*10000)/5000)+1;fsen++)
{
  int sen=(Y-man*10000-fsen*5000)/1000;
  if(man+fsen+sen==N&&man*10000+fsen*5000+sen*1000==Y){printf("%d %d %d\n",man,fsen,sen);return 0;}
}
printf("-1 -1 -1\n");
}

Measured memory_bytes: 3808
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.NoSuchElementException;
import java.util.Scanner;

class Main {

    public static void main(String[] args) throws IOException {

        InputStreamReader sr = null;
        Scanner sc = null;
        int datasets = 0;
        List<Integer> list = new ArrayList<Integer>();
        int sum = 0;
        int max = 0;

        try {
            sc = new Scanner(sr = new InputStreamReader(System.in));

            while ((datasets = sc.nextInt()) != 0) {

                for (int i = 1; i <= datasets; i++) {

                    list.add(sc.nextInt());

                }

                max = list.get(0);

                for (int i = 0; i < list.size(); i++) {
                    for (int j = i; j < list.size(); j++) {

                        sum += list.get(j);
                        if (max < sum) {

                            max = sum;

                        }

                    }

                    sum = 0;

                }

                System.out.println(max);
                max = 0;
                list.removeAll(list);

            }

        } catch (NoSuchElementException e) {

        }

        finally {
            sr.close();
            sc.close();
        }

    }

}

Measured memory_bytes: 26524
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <string>
#include <cmath>
#include <iomanip>
#include <numeric>
#include <cmath>
 
using namespace std;
 
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define INF (ll)1e18
#define MOD (ll)1e9 + 7
#define pb push_back
 
void no(){cout<<"No"<<endl;exit(0);}
void yes(){cout<<"Yes"<<endl;exit(0);}
void No(){cout<<"NO"<<endl;exit(0);}
void Yes(){cout<<"YES"<<endl;exit(0);}
 
typedef long long ll;
typedef long long int llt;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;
 
using namespace std;

int ctoi(char c) {
	switch (c) {
		case '0': return 0;
		case '1': return 1;
		case '2': return 2;
		case '3': return 3;
		case '4': return 4;
		case '5': return 5;
		case '6': return 6;
		case '7': return 7;
		case '8': return 8;
		case '9': return 9;
		default: return 0;
	}
}
int main(){
  string s;
  cin>>s;
  int n = s.size();
  int ans=112123123;
  for (int i = 0; i < n-2; i++){
    int a=ctoi(s[i]),b=ctoi(s[i+1]),c=ctoi(s[i+2]);
    ans = min(ans, abs(a*100+b*10+c-753));
  }
  cout<<ans<<endl;
  return 0;
}

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

int main(){
    size_t N, M;
    cin >> N >> M;
    vector<vector<size_t>> edge(N);
    vector<pair<size_t, size_t>> edg(M);
    for(auto& i : edg){
        cin >> i.first >> i.second;
        edge[--i.first].push_back(--i.second);
        edge[i.second].push_back(i.first);
    }
    vector<size_t> ord(N, numeric_limits<size_t>::max()), low(N, numeric_limits<size_t>::max());
    size_t time{0};
    auto dfs = [&ord, &low, &edge, &time](auto f, auto now, auto prev) -> void{
        low[now] = ord[now] = ++time;
        for(const auto& i : edge[now])if(i != prev){
            if(ord[i] > time)f(f, i, now);
            low[now] = min(low[now], low[i]);
        }
    };
    dfs(dfs, 0, 0);
    size_t ans{0};
    for(const auto& i : edg)if(ord[i.first] < low[i.second] || ord[i.second] < low[i.first])++ans;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
use proconio::{input,fastout};

#[fastout]
fn main() {
  input!{x: f64};
  let mut ans = 0;
  let mut m = 100.0f64;
  while m < x {
    ans += 1;
    m = (m * 1.01f64).floor();
  }
  println!("{}", ans);
}

Measured memory_bytes: 2716
MOD = 998244353
#階乗のリストを作成する
N, M, K = map(int, input().split())
frac = [1]
for i in range(N):
    frac.append(frac[i]*(i+1)%MOD)

#上の公式を用いてcombの計算を行う
def comb(n, k, mod):
    a=frac[n]
    b=frac[k]
    c=frac[n-k]
    return (a * pow(b, mod-2, mod) * pow(c, mod-2, mod)) % mod
  
def main():
  ans = [0] * (K+1)
  temp = 1
  for i in range(N):
    if i == 0:
      temp*=M
      temp %= MOD
    else:
      temp *= (M-1)
      temp %= MOD
    if i+1 >= N-K:
      ans[i+1-N+K] = temp
  t_ans = 0
  for i in range(len(ans)):
    key = comb(N-1, i, MOD)
    t_ans += (ans[-1-i]*key)
    t_ans %= MOD
  print(t_ans)
if __name__ == "__main__":
  main()

Measured memory_bytes: 24476
import sys

N = int(input()) - 1
two = False
S = 0
for i in range(N+1):
  a = int(sys.stdin.read(1))
  if not two:
    two = a == 2
  if i & N == i:
    S ^= a-1

if two:
  S &= ~2

print(S)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define inp_out_work ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define testCase    int T; cin>>T; while(T--)
#define fr(i,n) for(int i=0;i<n;i++)
#define fro(i,s,e) for(int i=s;i<=e;i++)
#define endl '\n'
#define debug(P) cout<<#P<<" = "<<P<<endl;
#define pb push_back
#define FILE freopen("in.txt","r",stdin); freopen("out.txt","w",stdout);


using namespace std;

typedef long long ll;

const ll MOD = 1e9 + 7;
const int NAX = 3002;

int dp[NAX][NAX];    //prefix of 1..i such that j is last number

void add(int &x, int y){
    x += y;
    if(x > MOD) x -= MOD;
    if(x < 0) x += MOD;
}

int main(){
    //inp_out_work
    //FILE
    int n;
    string s;
    cin>>n;
    cin>>s;
    dp[1][1] = 1;
    for(int i = 2; i <= n; i++){
        vector<int> cpy(i);
        cpy[0] = dp[i-1][0];

        for(int j = 1; j < i; j++){
                cpy[j] = cpy[j-1] + dp[i-1][j];
                if(cpy[j]>MOD)cpy[j] -= MOD;
        }

        for(int j = 1; j <= i; j++){
            if(s[i-2] == '<'){
                add(dp[i][j], cpy[j-1]);
            }
            else{
               add(dp[i][j], cpy[i-1]-cpy[j-1]);
            }
        }
    }
    int ans = 0;
    for(int i = 1; i <= n; i++)add(ans, dp[n][i]);
    cout<<ans<<endl;
}


Measured memory_bytes: 34176
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        n: usize,
        a: [f64; n],
    }
    let mut ans = 0.0;
    for elm in a {
        ans += 1f64 / elm;
    }
    println!("{}", 1f64 / ans);
}


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

int main(){
  int N, K;
  cin >> N >> K;
  
  vector<int> P(N);
  for (int i = 0; i < N; i++){
    cin >> P.at(i);
  }
  
  sort(P.begin(), P.end());
  
  int ans = 0;
  for (int i = 0; i < K; i++){
    ans += P.at(i);
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 3616
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		double a=sc.nextDouble();
		double b=sc.nextDouble();
		double C=sc.nextDouble();

		double c=Math.sqrt(Math.pow(a, 2)+Math.pow(b,2)-2*a*b*Math.cos(Math.toRadians(C)));

		double s=a*b*Math.sin(Math.toRadians(C))/2;
		double L=a+b+c;
		double h=b*Math.sin(Math.toRadians(C));

		System.out.printf("%.8f\n",s);
		System.out.printf("%.8f\n",L);
		System.out.printf("%.8f\n",h);

		sc.close();
	}

}



Measured memory_bytes: 28356
#include <bits/stdc++.h>
 
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define ll long long int
#define INF 1000000007
#define llINF 1000000000000000007
// cin.eof() 入力個数の問題
 
int main() {
    int n,y;
    cin>>n>>y;
    rep(i,n+1){
        rep(j,n+1){
            int s=y-1000*i-5000*j;
            if(s>=0&&s%10000==0&&s/10000==n-i-j){
                cout<<s/10000<<" "<<j<<" "<<i<<endl;
                return 0;
            }
        }
    }
    cout<<-1<<" "<<-1<<" "<<-1<<endl;
    return 0;
}


Measured memory_bytes: 3632
#include<stdio.h>
int main() 
{
 int a,b,i,j;
 while(1) {
  scanf("%d%d",&a,&b);
  if(a==0&&b==0){break;}
 for(i=1;i<=a;i++) {
  for(j=1;j<=b;j++) {
   if(i>1&&i<a&&j<b&&j>1)printf(".");
   else printf("#"); }
   printf("\n"); } 
 printf("\n"); } 
 return 0;
} 


Measured memory_bytes: 2056
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <sstream>
#include <map>
#include <set>

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1<<30
#define pb push_back
#define mp make_pair

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

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

	int n;
	cin >> n;

	int ans = 0;
	rep(i, n) {
		string t;
		cin >> t;

		string s2 = "";
		rep(j, 10) s2 += t;

		bool ch = false;
		rep(j, s2.size()-s.size()) {
			bool flag = true;
			rep(k, s.size()) {
				if(s[k] == s2[j+k]) continue;
				flag = false;
			}

			if(flag) ch = true;
		}

		if(ch) ans++;
	}

	cout << ans << endl;

	return 0;
}

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

using namespace std;

#define READ() 	    freopen("in.txt","r",stdin)
#define WRITE()     freopen("out.txt","w",stdout)
#define sf(n) 	    scanf("%d",&n)
#define sl(x)       scanf("%I64d",&x)
#define lsf(n) 	    scanf("%lld", &n)
#define pb(n) 	    push_back(n)
#define EPS 	    1e-10
#define INF         INT_MAX
#define MAX         100010
#define MOD         1000000007
#define LL          long long
#define endl        "\n"
#define pi          2.0*acos(0.0)
#define cnd         tree[idx]
#define lnd         tree[left]
#define rnd         tree[right]
#define callLeft    left,st,mid
#define callRight   right,mid+1,ed

int arr[MAX];
int need[MAX];
bool use[MAX];

int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(0); /// use "\n" instead of endl
//    READ();
//    WRITE();

    memset(use,false,sizeof(use));

    string s;
    cin >> s;
    int k;
    cin >> k;
    int len = s.size();
//    int x = 'z';
//    cout << x << endl;
    for(int i=0;i<len;i++)
    {
        if(s[i] != 'a')need[i] = 'z' - s[i] + 1;
    }

    for(int i=0;i<len;i++)
    {
//        cout << need[i] << " ";
        if(need[i] <= k)
        {
//            inc[i] = need[i];
            use[i] = true;
            k -= need[i];
        }
    }
//    cout << endl;


    if(k > 0)
    {
        if(k < need[len-1])s[len-1] += k;
        else if(k == need[len-1])s[len-1] = 'a';
        else
        {
            s[len-1] = 'a'; //+= need[len-1];
            if(!use[len-1])k -= need[len-1];
            k %= 26;
            s[len-1] += k;
        }
        use[len-1] = false;
    }
    for(int i=0;i<len;i++)
    {
        if(use[i])
        {
            cout << "a";
        }
        else
        {
//            s[i]+=inc[i];
            cout << s[i] ;
        }
    }
    cout << endl;

    return 0;
}


Measured memory_bytes: 1232
#include<cstdio>
#include<cstring>
#include<cmath>
#include<bitset>
#include<iostream>
#include<algorithm>
#include<string>
#include<utility>
#include<tuple>
#include<vector>
#include<list>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<numeric>
#include<functional>
#include<iomanip>
#include<random>

#define IOS ios::sync_with_stdio(false),cin.tie(0)
#define REP(i,n) for(int i = 0;i < n;i++)
#define FOR(i,a,b) for(int i = a;i < b;i++)
#define MEM(a,b) memset(a,b,sizeof(a))
#define ALL(x) (x).begin(),(x).end()
#define LMAX 9223372036854775807
#define LMIN -9223372036854775808

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ull, ull> UP;
typedef tuple<int, int, int> T;

struct UnionFind {
	vector<int> data;
	UnionFind(int size) : data(size, -1) {}
	void unionSet(int x, int y) {
		x = root(x), y = root(y);
		if (x != y) {
			if (data[y] < data[x])swap(x, y);
			data[x] += data[y]; data[y] = x;
		}
	}
	bool findSet(int x, int y) {
		return root(x) == root(y);
	}
	int root(int x) {
		return data[x] < 0 ? x : data[x] = root(data[x]);
	}
	int size(int x) {
		return -data[root(x)];
	}
};

ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	int k = a % b;
	if (k == 1)return 1;
	if (k == 0)return b;
	int ans = gcd(b, k);
	return ans;
}
ll digisum(ll a) {
	int sum = 0;
	while (a) {
		sum += a % 10;
		a /= 10;
	}
	return sum;
}
ll countpow(ll a, ll b) {
	int ans = 0;
	if (b == 0)return -1;
	while (1) {
		if (a % b == 0) {
			a /= b;
			ans++;
		}
		else break;
	}
	return ans;
}


int main() {
	IOS;
	int n;
	cin >> n;
	string s = "ABC" + to_string(n);
	cout << s << endl;
}



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

using namespace std;

class UnionFind {
private:
    vector<int> parent;

public:
    UnionFind(int N) : parent(N) {
        for (int i = 0; i < N; i++) {
            parent[i] = i;
        }
    }

    int root(int x) {
        if (parent[x] == x) {
            return x;
        }
        return parent[x] = root(parent[x]);
    }

    void unite(int x, int y) {
        int px = root(x);
        int py = root(y);
        parent[px] = py;
    }

    bool same(int x, int y) {
        return root(x) == root(y);
    }
};

int main(void) {
    int N, M;
    cin >> N >> M;
    vector<int> p(N+1);
    for (int i = 1; i <= N; i++) {
        cin >> p[i];
    }

    int x, y;
    UnionFind tree(N+1);
    for (int i = 0; i < M; i++) {
        cin >> x >> y;
        tree.unite(x, y);
    }

    int ans = 0;
    for (int i = 1; i <= N; i++) {
        if (tree.same(i, p[i])) {
            ans++;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>

#define fi first
#define se second
#define pb push_back

using namespace std;

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

    int n, ans = 0;

    cin >> n;

    vector<vector<pair<int, int>>> a(n);

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

        while (val > 0) {
            cin >> x >> y;
            a[i].pb({x - 1, y});
            val--;
        }
    }

    for (int i = 0; i < (1 << n); i++) {
        int c = 0;
        bool good = true;

        for (int j = 0; j < n; j++)
            if ((i >> j) & 1) {
                for (auto each : a[j])
                    good &= (((i >> each.fi) & 1) == each.se);
                c++;
            }

        if (good) ans = max(ans, c);
    }

    cout << ans << "\n";

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define INFTY 10000000000
typedef long long int ll;
const int MOD=1000000007;
using Graph = vector<vector<int>>;
using ipair = pair<ll,ll>;
bool operator< (const ipair a, const ipair b){return a.first < b.first;};
#define rep(i,n) for (int i = 0; i < (n); ++i)
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;}

int main(){
  ll n;
  cin>>n;
  vector<ll> p(100005,0);
  set<ll> a;
  ll ans = 0;
  rep(i,n){
    ll m;cin>>m;
    if(m>n){ans++;continue;}
    p[m]++;
    a.insert(m);
  }
 

  for(ll num:a){
    //cout<<num<<endl;
    if(p[num]<num)ans += p[num];
    if(p[num]>num)ans += p[num]-num;
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 1024
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())


N, K = inpl()
aa = inpl()

ans = []
min_ind_before = -1

for i in range(K+1):
    if i != 0:
        aa[min_ind_before] += 1000

    MIN = min(aa)
    if MIN <= 0:
        print(-1)
        sys.exit()

    min_ind = aa.index(MIN)

    if i != 0:
        aa[min_ind_before] -= 1000

    for j in range(N):
        if j == min_ind or j == min_ind_before:
            continue
        else:
            ans.append(j+1)
            aa[j] -= 1

    ans.append(min_ind+1)
    aa[min_ind] -= 1
    min_ind_before = min_ind




print(len(ans))
print (' '.join(map(str,ans)))


Measured memory_bytes: 4716
S = input()
T = input()
ST = [0 for _ in range(len(S)-len(T)+1)]
for i in range(len(S)-len(T)+1):
  for j in range(len(T)):
    s = S[i+j]
    t = T[j]
    if  s==t:
      ST[i]+=1
print(len(T)-max(ST))

Measured memory_bytes: 9120
#include<stdio.h>

int main(){
  int i, j, n, q, c=0;
  int S[10001], T[501];
  
  scanf("%d",&n);
  for(i=1; i<=n; i++){
    scanf("%d",&S[i]);
  }
  scanf("%d",&q);
  for(i=1; i<=q; i++){
    scanf("%d",&T[i]);
  }
  for(i=1; i<=n; i++){
    for(j=1; j<=n; j++){
      if(i != j && S[i] == S[j]) S[j]=0;
    }
  }

  for(i=1; i<=n; i++){
    if(i>1 && S[i]==0)continue;
    for(j=1; j<=q; j++){
      if(S[i] == T[j]) c++;
    }
  }
  printf("%d\n",c);
  return 0;
}

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

using namespace std;
#define ll long long

#define rep(i, a) for (int (i) = 0; (i) < (int) (a); (i)++)
#define reps(i, a, b) for (int (i) = (int) (a); (i) < (int) (b); (i)++)
#define rrep(i, a) for (int (i) = (int) a-1; (i) >= 0; (i)--)
#define rreps(i, a, b) for (int (i) = (int) (a)-1; (i) >= (int) (b); (i)--)
#define MP(a, b) make_pair((a), (b))
#define PB(a) push_back((a))
#define all(v) (v).begin(), (v).end()
#define PERM(v) next_permutation(all(v))
#define UNIQUE(v) sort(all(v));(v).erase(unique(all(v)), v.end())
#define CIN(type, x) type x;cin >> x
#define TRUE__ "Yes"
#define FALSE__ "No"
#define PRINT(f) if((f)){cout << (TRUE__) << endl;}else{cout << FALSE__ << endl;}

#ifdef LOCAL
#define lcout(a) cout << a;
#define lcoutln(a) cout << a << endl;
#define lcerr(a) cerr << a;
#define lcerrln(a) cerr << a << endl;
#else
#define lcout(a) 
#define lcoutln(a) 
#define lcerr(a) 
#define lcerrln(a) 
#endif

int N;
vector<vector<pair<int, int> > > ans(8);

void rot(vector<pair<int, int> >& ori, vector<pair<int, int> >& to)
{
	rep(i, ori.size()) {
		auto p = ori[i];
		int x = p.first;
		int y = p.second;
		to.PB(MP(y, -x));
	}
}

signed main()
{
	cin >> N;
	while (N) {
		int M;
		cin >> M;
		auto& vt1 = ans[0];
		auto& vt2 = ans[4];
		rep(i, M) {
			CIN(int, x);
			CIN(int, y);
			vt1.PB(MP(x, y));
			vt2.PB(MP(x, y));
		}
		reverse(all(vt2));
		rrep(i,M) {
			vt1[i].first -= vt1[0].first;
			vt1[i].second -= vt1[0].second;
			vt2[i].first -= vt2[0].first;
			vt2[i].second -= vt2[0].second;
		}
		reps(i, 1, 4) {
			rot(ans[i-1], ans[i]);
			rot(ans[i+3], ans[i+4]);
		}
		rep(i, N) {
			cin >> M;
			int ox, oy;
			cin >> ox >> oy;
			vector<pair<int, int> > vv;
			vv.PB(MP(0, 0));
			rep(j, M-1) {
				CIN(int, x);
				CIN(int, y);
				vv.PB(MP(x-ox, y-oy));
			}
			rep(j, 8) {
				int  k = 0;
				int en = (int) ans[j].size();
				if ((int) vv.size() != en) break;
				for (; k < en; k++) {
					if (ans[j][k].first != vv[k].first || ans[j][k].second != vv[k].second) {
						break;
					}
				}
				if (k == en) {
					cout << i+1 << endl;
					break;
				}
			}
		}
		cout << "+++++" << endl;
		rep(i, 8) ans[i].clear();
		cin >> N;
	}
}



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

using namespace std;
#define IO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
typedef long long ll;
const int N=1e5+5;///1e18+5

int n,k;

void solve()
{
    cin>>n>>k;
    int a[n];
    for(int i=1; i<=n; i++)
    {
        cin>>a[i];
    }
    int t=k;
    int t2=k;
    int i,j,c;
    int low_sum=1,high_sum=1;
    for(i=1; i<=n-k; i++)
    {
        if(a[i]<a[i+k])cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
    }

}

int main()
{
   // freopen("input.txt","r",stdin);
    IO;

    int tc=1;
    //cin>>tc;
    while(tc--)
    {
        solve();
    }
    return 0;
}


Measured memory_bytes: 4424
#include<bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); ++i)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
int main(){
  int n,k;
  cin >> n >> k;
  string s;
  cin >> s;
  s[k-1] =tolower(s[k-1]);
  cout << s << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include<algorithm>
#include<math.h>
#include<set>
#include<vector>
using namespace std;
int main(){
int A,B,C,X,Y;
cin>>A>>B>>C>>X>>Y;
int s,t,u;
s = A*X+B*Y;
t = C*max(X,Y)*2;
if(X>=Y)u= C*Y*2+A*(X-Y);
else u= C*X*2+B*(Y-X);
cout<<min(min(s,t),u)<<endl;
}






Measured memory_bytes: 256
#include <iostream>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  int A[110];
  double nume = 1 , deno = 0;
  for (int i; i< N; i++) {
    cin >> A[i];
    nume *= A[i];
  }
  for (int i; i < N; i++) deno += nume / A[i];
  
  cout << nume / deno << endl;  
}


Measured memory_bytes: 256
r, c = gets.split.map(&:to_i)
fld = r.times.map{ gets.split('').map(&:to_i) }
(1...r).each{ |y| fld[y][0] += fld[y-1][0] }
(1...c).each{ |x| fld[0][x] += fld[0][x-1] }
(1...r).each do |y|
  (1...c).each do |x|
    fld[y][x] += [fld[y][x-1], fld[y-1][x]].min
  end
end
p fld[r-1][c-1]

Measured memory_bytes: 8956
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskB {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int a = in.nextInt();
            int ans = (int) Math.pow((int) Math.sqrt(a), 2);
            out.println(ans);
        }

    }
}



Measured memory_bytes: 22100
import Control.Monad

readIntLine :: IO ([Int])
readIntLine = do
    x <- getLine
    return $ map (read :: String -> Int) $ words x

main :: IO ()
main = do
    [n] <- readIntLine
    print $ solve n

fav n s = div n s == mod n s

canBeRem n k
    | mod n k == 0 && fav n s = s
    | otherwise               = 0
         where s = div (n - k) k

allCands x n
    | x * x >= n = []
    | otherwise  = x:(allCands (x+1) n)

solve n = sum $ map (canBeRem n) $ allCands 1 n


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

int a[10];
int main() {
	int n;
	cin >> n;
	rep(k, n) {
		rep(i, 10)scanf("%d", &a[i]);
		rep(i, 1 << 10) {
			stack<int>s[2];
			rep(j, 10)if (s[(i >> j) & 1].empty() || a[j] > s[(i >> j) & 1].top())s[(i >> j) & 1].push(a[j]);
			if (s[0].size() + s[1].size() == 10) { puts("YES"); break; }
			if (i == (1 << 10) - 1)puts("NO");
		}
	}
	return 0;
}



Measured memory_bytes: 3136
import sys
sys.setrecursionlimit(3000000)

n = int(input())

g = [[] * 1 for i in range(n)]

for i in range(n-1):
    a = int(input())
    g[a-1].append(i+1)

def dfs(v):
    childs = []
    for u in g[v]:
        child = dfs(u)
        childs.append(child)
    childs.sort()
    ans = 1
    for child in childs:
        if ans < child:
            ans = child
        ans += 1
    return ans

print(dfs(0)-1)



Measured memory_bytes: 112664
//itp1_5-c
#include <iostream>
using namespace std;

int main(){
 int h,w;
 while(true){
  cin>>h>>w;
  if(h==0 && w==0){
   break;
  }
  for(int i=0;i<h;i++){
   for(int j=0;j<w;j++){
    if((i%2==0 && j%2==0) || (i%2==1 && j%2==1))
     cout<<'#';
    else if((i%2==0 && j%2==1) || (i%2==1 && j%2==0))
     cout<<'.';
   }
   cout<<endl;
  }
  cout<<endl;
 }
 return 0;
}

Measured memory_bytes: 1156
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair< ll, ll > Pi;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<=(n);i++)
#define rep3(i,i0,n) for(int i=i0;i<(n);i++)
#define pb push_back
#define mod 1000000007
const ll INF = 1LL << 60;
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; }
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;}
#define all(x) x.begin(), x.end()
#define mp make_pair
bool compare(Pi a, Pi b) {
    if(a.first != b.first){
        return a.first < b.first;
        
    }else{
        return a.second < b.second;
    }
}


bool In_map(ll y,ll x,ll h,ll w){
    if(y<0 || x<0 || y>=h || x>=w){
        return 0;
    }else{
        return 1;
    }
}
const vector<ll> dx{1,0,-1,0};
const vector<ll> dy{0,1,0,-1};


int main() {
    ll N,D;
    cin >>N>>D;
    ll ans =0;
    rep(i,N){
        ll x,y;
        cin>>x>>y;
        if(x*x+y*y<=D*D){
            ans++;
        }

    }
    
    cout << ans << endl;


    return 0;
    

}

Measured memory_bytes: 3624
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.HashMap;

public class Main {
    public static void main(String[] args){
        try{
            BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
            long  t=Long.parseLong(br.readLine());
            long p=t;
            while(p%5!=0){
                p--;
            }
            long k=p;
            p-=5;
            p=p/5;
            p+=1;
            long sum1=((p)*(5+k))/2;
            p=t;
            while(p%3!=0){
                p--;
            }
            k=p;
            p-=3;
            p=p/3;
            p+=1;
            long sum2=((p)*(k+3))/2;
            p=t;
            while(p%15!=0){
                p--;
            }
            k=p;
            p-=15;
            p=p/15;
            p+=1;
            long sum=((p)*(k+15))/2;
            long ans=((t)*(t+1))/2;
            ans-=(sum1+sum2-sum);
            System.out.println(ans);

        }catch(Exception e){
            System.out.println("KKKK "+e.getMessage());
        }
    }
}


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

const int maxn = 105, maxk = 1e5+5;
const int M = 1e9+7;
int N, K, a[maxn];

void madd(int& a, int b) {
    a += b;
    while (a > M) a -= M;
}

int dp[maxn][maxk];

int main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    cin >> N >> K;
    for (int i = 1; i <= N; i++) {
        cin >> a[i];
    }
    for (int j = 0; j <= a[1]; j++) {
        dp[1][j] = 1;    
    }
    for (int i = 2; i <= N; i++) {
        for (int k = 1; k <= K; k++) {
            madd(dp[i-1][k],dp[i-1][k-1]);
        }
        for (int k = 0; k <= K; k++) {
            dp[i][k] = dp[i-1][k];
            if (k-min(k,a[i]) > 0) dp[i][k] = (dp[i][k] - dp[i-1][k-min(k,a[i])-1] + M) % M;
        }
    }
    int ans = dp[N][K];
    cout << ans << '\n';

    return 0;
}



Measured memory_bytes: 40960
n,a=map(int,raw_input().split())
for x in range(n+1):
    for y in range(n+1):
        z = n-(x+y)
        if a==(10000*x)+(5000*y)+(1000*z) and z >= 0:
            print '%d %d %d' % (x,y,z)
            quit()
print '-1 -1 -1'

Measured memory_bytes: 2692
import java.util.Scanner;

class Main
{
  public static void main(String[] args)
  {
	  int l,w;
	  boolean t=true;
	  Scanner in=new Scanner(System.in);
	  
	  while(t)
      { l=in.nextInt();
	    w=in.nextInt();
		
		if(l==0 && w==0)
		{       
			break;
		}
		
        for(int i=0;i<l;i++)
        {
		    for(int j=0;j<w;j++)
		    {
				if((i+j)%2==0)
			      System.out.print("#");
			    else
				  System.out.print(".");
		    }
		    System.out.println("");
	    }
		System.out.println("");
		
	  }		
	  

    
  }

}

Measured memory_bytes: 33356
#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;

string s;
int n,ans;

int main(){
	cin>>s;
	ans=n=s.length();
	for(int i=0;i<n;i++)
		if(s[i]!=s[i+1])
			ans=min(ans,max(i+1,n-i-1));
	printf("%d",ans);
}

Measured memory_bytes: 512
n, m, x, y = gets.split.map(&:to_i)
xs = gets.split.map(&:to_i).sort
ys = gets.split.map(&:to_i).sort
ans = (x+1..y).to_a.inject(false) { |a, z| a || xs[-1] < z && z <= ys[0] }
puts ans ? "No War" : "War"

Measured memory_bytes: 1788
type tree = Nil | Node of int * tree * tree

let create () = Nil

let insert x t =
  let rec doit = function
    | Nil -> Node (x, Nil, Nil)
    | Node (y, l, r) when x < y -> Node (y, doit l, r)
    | Node (y, l, r) -> Node (y, l, doit r)
  in
  doit t

let preorder f t =
  let rec doit = function
    | Nil -> ()
    | Node (x, l, r) -> (f x; doit l; doit r)
  in
  doit t

let inorder f t =
  let rec doit = function
    | Nil -> ()
    | Node (x, l, r) -> (doit l; f x; doit r)
  in
  doit t

let print t =
  let f e = print_string " "; print_int e in
  inorder f t;
  print_newline ();
  preorder f t;
  print_newline ()

let () =
  let m = read_int () in
  let rec read i t =
    if i < m then
      let op = Scanf.scanf "%s " (fun i -> i) in
      if op = "print" then (print t; read (i + 1) t)
      else read (i + 1) (insert (Scanf.scanf "%d " (fun i -> i)) t)
  in
  read 0 (create ())

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

int main(){
  ll n;
  cin >> n;
  ll a[n+1];
  ll count[n+1] = {0};
  set<ll> st;
  for(ll i=1;i<n+1;i++){
    cin >> a[i];
    st.insert(a[i]);
    count[a[i]]++;
  }

  ll main[n+1] = {0};
  ll sub[n+1] = {0};
  for(auto p : st){
    main[p] = count[p] * (count[p]-1) / 2;
    sub[p] = (count[p]-1) * (count[p]-2) / 2;
  }
  ll sum = 0;
  for(auto p : st){
    sum += main[p];
  }

  for(ll i=1;i<n+1;i++){
    ll ans = sum;
    ans -= main[a[i]];
    ans += sub[a[i]];
    // ans -= count[a[i]] - 1;
    cout << ans << endl;
  }

  return 0;
}

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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repi(i, a, b) for (int i = (a); i < int(b); i++)
#define all(a) (a).begin(), (a).end()
#define bit(b) (1ll << (b))
#define uniq(v) (v).erase(unique(all(v)), (v).end())
#define rsort(v) sort(all(v)); reverse(all(v))

using namespace std;
using i32 = int;
using i64 = long long;
using f80 = long double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void ioinit() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { return a / gcd(a, b) * b; }
inline vi32 plist(i32 n) { vi32 f(n, 1); f[0] = f[1] = 0; repi(i, 2, n) for (int j = i * 2; j < n; j += i) f[j] = 0; return f; }
inline bool isprime(i32 n) { if (n < 2) return 0; for (i32 i = 2; i * i <= n; i++) if (n % i == 0) return 0; return 1; }
template<class T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template<class T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template<class T> inline bool amax(T &x, T y) { if (x >= y) return 0; x = y; return 1; }
template<class T> inline bool amin(T &x, T y) { if (x <= y) return 0; x = y; return 1; }
template<class T> inline T power(T x, i64 n) { T r = 1; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }

template<class T> struct flow {
  struct edge {
    int to;
    T cap;
    int rev;
  };

  int n, s, t;
  vector<vector<edge>> g;
  vector<bool> used;

  flow(int n, int s, int t) : n(n), s(s), t(t) {
    g = vector<vector<edge>>(n);
  }

  void add(int from, int to, T cap) {
    g[from].push_back({ to, cap, (int) g[to].size() });
    g[to].push_back({ from, 0, (int) g[from].size() - 1 });
  }

  T dfs(int v, T f) {
    if (v == t) {
      return f;
    }
    used[v] = true;
    for (auto &e : g[v]) {
      if (used[e.to] || e.cap <= 0) {
        continue;
      }
      T d = dfs(e.to, min(f, e.cap));
      if (d > 0) {
        e.cap -= d;
        g[e.to][e.rev].cap += d;
        return d;
      }
    }
    return 0;
  }

  T max_flow() {
    T sum = 0;
    while (true) {
      used = vector<bool>(n);
      T f = dfs(s, numeric_limits<T>::max());
      if (f == 0) {
        break;
      }
      sum += f;
    }
    return sum;
  }
};

int main() {
  ioinit();
  int n;
  cin >> n;
  vi32 a(n);
  rep(i, n) cin >> a[i];
  flow<i64> g(n + 2, 0, n + 1);
  rep(i, n) {
    if (a[i] <= 0) {
      g.add(0, i + 1, -a[i]);
    } else {
      g.add(i + 1, n + 1, a[i]);
    }
  }
  reps(i, n) {
    for (int j = i + i; j <= n; j += i) {
      g.add(i, j, numeric_limits<i64>::max());
    }
  }
  i64 ans = 0;
  rep(i, n) ans += max(0, a[i]);
  ans -= g.max_flow();
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define mp make_pair
#define fi first
#define se second
#define puba push_back
#define pufro push_front
#define poba pop_back
#define pofro pop_front

using namespace std;
typedef long long ll;
const ll M=1e9+7;
const double PI=acos(-1);
const double EPS=1e-12;
const ll arrSize=2000005;
ll arr[arrSize];
ll grid[505][505];
int main(){
	int tc=1,kasus=1;
	//scanf("%d",&tc);
	while(tc--){
		int n;
		ll x;
		scanf("%d %lld",&n,&x);
		for(int i=0;i<n;i++){
			scanf("%lld",&arr[i]);
		}
		arr[n]=x;
		sort(arr,arr+n+1);
		ll gg=0;
		for(int i=0;i<n;i++){
			gg=__gcd(gg,arr[i+1]-arr[i]);
		}
		
		printf("%lld\n",gg);
	}
}

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

const int N = 200001;

int n, x, y, a[N], b[N], depth[N], parent[N], escape[N], dist[N];
std::vector<int> tree[N], graph[N];

void prepare(int p, int u) {
  depth[u] = depth[p] + 1, parent[u] = p;
  for (int v : tree[u]) {
    if (v != p) {
      prepare(u, v);
    }
  }
}

int treedist(int a, int b) {
  int d = 0;
  while (d < 3 && a != b) {
    int &u = depth[a] > depth[b] ? a : b;
    d++, u = parent[u];
  }
  return d;
}

int main() {
  scanf("%d%d%d", &n, &x, &y);
  for (int i = 0; i < n - 1; ++i) {
    scanf("%d%d", a + i, b + i);
  }
  for (int i = 0, c, d; i < n - 1; ++i) {
    scanf("%d%d", &c, &d);
    tree[c].push_back(d);
    tree[d].push_back(c);
  }
  depth[0] = -1;
  prepare(0, y);
  for (int i = 0; i < n - 1; ++i) {
    if (treedist(a[i], b[i]) == 3) {
      escape[a[i]] = escape[b[i]] = true;
    } else {
      graph[a[i]].push_back(b[i]);
      graph[b[i]].push_back(a[i]);
    }
  }
  std::vector<int> queue;
  queue.push_back(x);
  memset(dist, -1, sizeof(dist));
  dist[x] = 0;
  int result = 0;
  for (int head = 0; head < static_cast<int>(queue.size()); ++head) {
    int u = queue[head];
    if (dist[u] >= depth[u]) {
      continue;
    }
    if (escape[u]) {
      result = -1;
      break;
    }
    result = std::max(result, depth[u] << 1);
    for (int v : graph[u]) {
      if (dist[v] == -1) {
        dist[v] = dist[u] + 1;
        queue.push_back(v);
      }
    }
  }
  printf("%d\n", result);
}

Measured memory_bytes: 35960
n = int(input())
s = str(input())
l = [i for i in s]
for i in range(n-1):
  t = []
  s = str(input())
  for j in s:
    if j in l:
      t.append(j)
      l.remove(j)
  l = t
  
if l != []:
  l.sort()
  ans = ''.join(l)
  print(ans)

Measured memory_bytes: 9188
#include <iostream>
#include <string>
#include <map>
#include <utility>

using namespace std;
int main(){
	int i,j,n;
	long long ans = 0;
	map<pair<string,string>,long long> l;
	string s;
	cin >> n >> s;
	for(i=0;i<1<<n;i++){
		string r,b;
		for(j=0;j<n;j++){
			if(i&(1LL<<j)){
				r = s[j] + r;
			}else{
				b = s[j] + b;
			}
		}
		l[{r,b}]++;
	}
	for(i=0;i<1<<n;i++){
		string r,b;
		for(j=0;j<n;j++){
			if(i&(1LL<<j)){
				r = r + s[j+n];
			}else{
				b = b + s[j+n];
			}
		}
		ans += l[{b,r}];
	}
	cout << ans << endl;
}

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

//Pathological Paths
public class Main{

	class F{
		int id;
		String name;
		public F(int id, String name) {
			this.id = id;
			this.name = name;
//			System.out.println("Make file:" + name + " ID:" + id);
		}
	}
	
	class D{
		String name;
		D parent;
		List<D> dir;
		List<F> file;
		public D(String name, D parent) {
			this.name = name;
			this.parent = parent;
			dir = new ArrayList<D>();
			file = new ArrayList<F>();
		}
		void add(String[] s, int d, int id){
			if(s.length-1==d){
				file.add(new F(id, s[d])); return;
			}
			for(D v:dir){
				if(v.name.equals(s[d])){
					v.add(s, d+1, id); return;
				}
			}
			D v = new D(s[d], this);
			dir.add(v);
			v.add(s, d+1, id);
		}
		int find(String[] s, int d){
//			System.out.println("S len:" + s.length + " depth:"+d+" cmd:"+s[d]);
			if(d==s.length-1){
				if("".equals(s[d])||".".equals(s[d])){
					for(F f:file){
						if("index.html".equals(f.name))return f.id;
					}
					return -1;
				}
				else if("..".equals(s[d])){
					if(parent==null)return -1;
					for(F f:parent.file){
						if("index.html".equals(f.name))return f.id;
					}
					return -1;
				}
				for(F f:file){
					if(s[d].equals(f.name))return f.id;
				}
				for(D v:dir){
					if(s[d].equals(v.name)){
						for(F f:v.file){
							if("index.html".equals(f.name))return f.id;
						}
					}
				}
				return -1;
			}
			if(".".equals(s[d]))return find(s, d+1);
			if("..".equals(s[d])){
				if(parent==null)return -1;
				return parent.find(s, d+1);
			}
			for(D v:dir){
				if(v.name.equals(s[d])){
					return v.find(s, d+1);
				}
			}
			return -1;
		}
		void dump(){
			System.out.println("Dir:" + name);
			System.out.println("FILES:");
			for(F f:file)System.out.println(f.name);
			System.out.println("DIRS:");
			for(D d:dir)System.out.println(d.name);
			for(D d:dir)d.dump();
		}
	}
	
	void run(){
//		System.out.println(("/ICPC/../ ").split("/").length);
		Scanner sc = new Scanner(System.in);
		for(;;){
			int n = sc.nextInt(), m = sc.nextInt();
			if((n|m)==0)break;
			D root = new D("", null);
			while(n--!=0){
				root.add(sc.next().split("/"), 1, n);
			}
//			root.dump();
			while(m--!=0){
				String s = sc.next();
				boolean f = false;
				if(s.charAt(s.length()-1)=='/'){
					s+=" "; f = true;
				}
				String[] t = s.split("/");
				if(f)t[t.length-1] = "";
				int a = root.find(t, 1);
//				System.out.println("A:" + a);
				s = sc.next();
				f = false;
				if(s.charAt(s.length()-1)=='/'){
					s+=" ";
					f = true;
				}
				t = s.split("/");
				if(f)t[t.length-1] = "";
				int b = root.find(t, 1);
//				System.out.println("B:"+b);
				System.out.println(a==-1||b==-1?"not found":a==b?"yes":"no");
			}
		}
	}
	
	public static void main(String[] args) {
		new Main().run();
	}
}

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

int main(){
	string a, b;
    cin >> a >> b;
    
    if (a.size() > b.size()){
        cout << "GREATER" << endl;
    }
    else if (a.size() == b.size()){
        if (a>b){
        cout << "GREATER" << endl;
        }
        else if (a==b){
            cout << "EQUAL" << endl;
        }
        else if (a<b){
            cout << "LESS" << endl;
        }    
    }
    else if (a.size() < b.size()){
        cout << "LESS" << endl;
    }
}

Measured memory_bytes: 3608
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
#include <string.h>
#include <queue>
using namespace std;

int main() {
	string S;
	bool A[26],ans=true;
	for(int i=0;i<26;i++)A[i]=false;
	cin>>S;
	for(int i=0;i<S.size();++i)
	{
		if(A[S[i]-'a']){
			ans=false;
			break;
		}
		else A[S[i]-'a']=true;
	}
	cout<<(ans?"yes":"no");
}

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

int main(){
  long long int n,a,b,sum=0,x[100001];
  
  cin>>n>>a>>b;

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


  for(int i=0;i<n-1;i++){
    if( (x[i+1]-x[i])*a > b){
      sum+=b;
    }
    else sum+=(x[i+1]-x[i])*a;
  }

  cout<<sum<<endl;
  return 0;
}


Measured memory_bytes: 1024
n = int(input(''))
adl = input('')

a = list(map(int,adl.split(' ')))

number = 0

mod = 1000000007

amari = 0

all_a = 0

for i in range(n):
    all_a = all_a + a[i]

for i in range(n):
    all_a = all_a - a[i]
    number = number + (a[i] * all_a)
    number = number % mod
amari = number % mod
print(amari)


Measured memory_bytes: 92896
#include <iostream>
#include <string>
 
using namespace std;
 
int main(){
  int h, w, cnt = 0;
  string line;
  cin >> h >> w;
  for(int i = 0; i < h; i++){
    cin >> line;
    for(int j = 0; j < w; j++) if(line[j] == '#') cnt++;
  }
  cout << (h + w - 1 - cnt ? "Impossible" : "Possible") << endl;
}

Measured memory_bytes: 256