akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using int64 = long long;
#define int int64
#define rep(i, n) for(int i=0; i<n; i++)
#define FOR(i, a, b) for(int i=a; i<b; i++)
#define SORT(x) sort(x.begin(), x.end())
#define GSORT(x) sort(x.begin(), x.end(), greater<int>())
#define mk make_pair
#define fi first
#define se second
#define pb push_back
#define ALL(x) x.begin(), x.end()
#define V(T) vector<T>
typedef pair<int, int> P;
typedef pair<P, P> PP;
typedef vector<int> vi;
typedef vector<vi> vvi;
int max(int a, int b) {if(b>a) return b; else return a;}
int min(int a, int b) {if(b<a) return b; else return a;}


signed main() {
    string s, t;
    cin >> s >> t;

    t += s;
    cout << t << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <queue>
#include <map>
using namespace std;
typedef long long ll;
const int INF = 1<<30; 
const int MOD = 1e9 + 7;
const int dy[] = {1, 0, -1, 0};
const int dx[] = {0, 1, 0, -1};
int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n; cin >> n;
	int score[n + 1] = {};
	int num[n + 1][3];
	int flag[110][3] = {};
	for(int i = 0; i < n; i++)
	{
		for(int j = 0; j < 3; j++)
		{
			cin >> num[i][j];
			flag[num[i][j]][j]++;
		}
	}
	for(int i = 0; i < n; i++)
	{
		for(int j = 0; j < 3; j++)
		{
			if(flag[num[i][j]][j] == 1) score[i] += num[i][j];
		}
	}
	for(int i = 0; i < n; i++) cout << score[i] << endl;
	return 0;
}




Measured memory_bytes: 3168
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<stack>
#include<queue>
#define INF 0x3f3f3f3f
#define lowbit(x) x & -x
#define lson root<<1,l,mid
#define rson root<<1|1,mid+1,r
using namespace std;
typedef long long ll;
const int mod=1e9+7;
const int N=2e5+5;
ll a[N],b[N];
int main(){
#ifdef Mizp
    freopen("in.txt","r",stdin);
#endif
    int n,m,k;
    scanf("%d%d%d",&n,&m,&k);
    for(int i=1;i<=n;i++){
        scanf("%lld",&a[i]);
        a[i]+=a[i-1];
    }
    for(int i=1;i<=m;i++){
        scanf("%lld",&b[i]);
        b[i]+=b[i-1];
    }
    int cnt=0;
    for(int i=0;i<=n;i++){
        if(a[i]>k)
            break;
        while(m>0&&b[m]>k-a[i]){
            m--;
        }
        cnt=max(cnt,i+m);
    }
    printf("%d\n",cnt);
    return 0;
}


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

int main()
{
    string s;
    cin >> s;
    int n = s.size();
    long long ans = n*(n+1LL)/2+1;
    for(char c='a'; c<='z'; c++){
        int cnt = count(s.begin() ,s.end() ,c);
        ans -= cnt*(cnt+1LL)/2;
    }
    cout << ans << endl;
}


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

using namespace std;

typedef long long ll;
typedef pair<ll, int> P;

int main(){
	int x,n;
	int p[100];
	cin >> x >> n;
	for(int i=0;i<n;i++) cin >> p[i];

	if(n==0){
		cout << x << endl;
	}else{
		int ans = 0;
		for(int i=0;i<=101;i++){
			bool exist = false;
			for(int j=0;j<n;j++){
				if(i==p[j]) exist=true;
			}
			if(!exist){
				if(abs(ans-x)>abs(i-x)) ans = i;
			}
		}
		cout << ans << endl;
	}

	

	return 0;
}

Measured memory_bytes: 3636
# -*- coding: utf-8 -*-
"""
https://beta.atcoder.jp/contests/abc044/tasks/abc044_a

"""
import sys
from sys import stdin
input = stdin.readline


def solve(N, K, X, Y):
    total = 0
    if N > K:
        total += X * K
        total += Y * (N - K)
    else:
        total += X * N
    return total


def main(args):
    N = int(input())
    K = int(input())
    X = int(input())
    Y = int(input())
    ans = solve(N, K, X, Y)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])


Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>

using namespace std;

int X, Y, W, H;

bool check(int y, int x){
  if(y<Y || y>Y+H) return false;
  if(x<X || x>X+W) return false;
  return true;
}

main(){
  int n;
  cin >> n;
  while(n--){
    cin >> X >> Y >> W >> H;
    int neko;
    cin >> neko;
    int ans = 0;
    for(int i=0;i<neko;i++){
      int x, y;
      cin >> x >> y;
      if(check(y, x)) ans++;
    }
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 0
import sys
from bisect import bisect_right

def main():
    s = input()
    t = input()
    
    table = {a : [] for a in 'abcdefghijklmnopqrstuvwxyz'}
    N = len(s)
    
    for idx, a in enumerate(s): table[a].append(idx+1)
    
    length = {a : len(table[a]) for a in 'abcdefghijklmnopqrstuvwxyz'}
    
    loop, idx = 0, 0
    for a in t:
        if not table[a]: 
            print(-1)
            sys.exit()
        
        i = bisect_right(table[a], idx)
        
        if i != length[a]:
            idx = table[a][i]
            if idx == N:
                loop += 1
                idx = 0
        else:
            loop += 1
            idx = table[a][0]
            
    print(loop * len(s) + idx)

if __name__ == '__main__':
    main()

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

int main() {
  int n;
  cin >> n;
  vector<double> list(n);
  for(int i=0;i<n;i++) {
    cin >> list.at(i);
  }
  sort(list.begin(), list.end());
  double ans=(list.at(0)+list.at(1))/2;
  for(int i=2;i<n;i++) {
    ans=(ans+list.at(i))/2;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int n = sc.nextInt();
		int m = sc.nextInt();
		int result =1;
		for(int i=m/n;i>1;i--){
			int amari =m-i*n;
			// System.out.print("今は"+i);
			// System.out.println("amari"+amari);
			if(amari==0||amari%i==0){
				result = i;
				break;
			}
			// System.out.println("result"+result);
		}
		System.out.println(result);
		// System.out.println(result);
	}
}

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

typedef long long int ll;
typedef pair<ll, ll> pll;

#define FOR(i, n, m) for (ll(i) = (m); (i) < (n); ++(i))
#define REP(i, n) FOR(i, n, 0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

int main()
{
    int N;
    cin >> N;
    string S;
    cin >> S;
    int r = 0, b = 0;
    REP(i, N)
    {
        if (S[i] == 'B')
            b++;
        else
            r++;
    }
    if (r > b)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
h,w = map(int,input().split())

maze = [['.']*(w+2)] + [['.'] + list(input()) + ['.'] for i in range(h)] + [['.']*(w+2)]

def kuro(a,b):
    dx = [-1,1,0,0]
    dy = [0,0,-1,1]
    p = 0
    for i in range(4):
        if maze[a+dx[i]][b+dy[i]] == '#':
            p += 1
            maze[a+dx[i]][b+dy[i]] == '.'
    if p == 0:
        return False
    return True




for i in range(1,h+1):
    for j in range(1,w+1):
        if maze[i][j] == '#':
            if kuro(i,j) == False:
                print('No')
                break
    else:
        continue
    break
else:print('Yes')


Measured memory_bytes: 3064
#include <stdio.h>


int main(){
    long long array[100010];
    int n;

    scanf("%d", &n);
    int i;
    for(i = 0; i < n; i++)scanf("%lld", &array[i]);

    int zero = 0;
    for(i = 0; i < n; i++){
        if(array[i] == 0)zero++;
    }
    if(zero > 0){
        printf("0\n");
        return 0;
    }


    long long prod = 1;
    for(i = 0; i < n; i++){
        if(array[i] <= 1000000000000000000 / prod){
            prod *= array[i];
            
        }else{
            printf("-1\n");
            return 0;
        }

    }

    printf("%lld\n", prod);
    return 0;
}

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

#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define repp(i, m, n) for(int i = m, i##_len = (n); i < i##_len; ++i)
#define all(x) (x).begin(), (x).end()
#define clr(ar, val) memset(ar, val, sizeof(ar))
template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair <int,int> P;
typedef long double ld;

int main(void)
{
	int a;
	cin >> a;
	cout << a * a * a << endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){

  int arr[1024];
  int a=0,i,l,m,n,temp;
  int v,j;

  scanf("%d",&n);

  for(i=0;i<n;i++){
    scanf("%d",&arr[i]);
  }

 for(i=0;i<n;i++){
    printf("%d",arr[i]);
    if(i<n-1)printf(" ");
  }
  printf("\n");

  for(i=1;i<=n-1;i++){
    v=arr[i];
    j=i-1;
    while(j>=0 && arr[j]>v){
      arr[j+1]=arr[j];
      j--;
    }
    arr[j+1]=v;

 for(l=0;l<n;l++){
    printf("%d",arr[l]);
    if(l<n-1)printf(" ");
  }
  printf("\n");

  }

  return 0;
}

Measured memory_bytes: 608
#include <iostream>
#include <fstream>
#include <cassert>
#include <typeinfo>
#include <vector>
#include <stack>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <iomanip>
#include <cctype>
#include <random>
#include <complex>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<29;
const ll INF=1ll<<58;
const double pi=acos(-1);
const double eps=1e-7;
const ll mod=1e9+7;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};
const double PI = 4.0*atan(1.0);

string s;

int main(){
	cin>>s;
	int res=0;
	for(int i=0;i<6;i++) res+=s[i]-'0';
	cout<<res<<endl;
}

Measured memory_bytes: 256
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.*;
import java.util.Stack;

public class Main {
	
	public static class FastReader {
		BufferedReader br;
		StringTokenizer st;
	

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

		String next() {
			while (st == null || !st.hasMoreTokens()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (Exception r) {
					r.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());//converts string to integer
		}

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

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

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (Exception r) {
				r.printStackTrace();
			}
			return str;
		}
	}
	
	public static PrintWriter out = new PrintWriter (new BufferedOutputStream(System.out));
   
  // static Scanner sc = new Scanner(System.in);
  
    private final static int mod = (int) (1e9 + 7);
    private final static int N = (int) (1e6);
	public static void main(String[] args) {
	   
	 FastReader sc = new FastReader();
		int n = sc.nextInt();
		int[] h = new int[n];
		for(int i=0;i<n;++i) h[i] = sc.nextInt();
		int[] dp = new int[n];
		dp[0] = 0;
		dp[1] = Math.abs(h[1]-h[0]);
		for(int i=2;i<n;++i) dp[i] =  Math.min(dp[i-1]+Math.abs(h[i]-h[i-1]), dp[i-2] + Math.abs(h[i]-h[i-2]));
		out.print(dp[n-1]);
	 out.close();
    
	}

	private static long pow(long a, int b) {
		if(b == 0) return 1;
		long temp = pow(a,b/2);
		temp = (temp*temp)%mod;
		if((b&1) == 1) temp = (a*temp)%mod;
		return temp;
	}
}

Measured memory_bytes: 31452
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.StringTokenizer;
import java.io.Writer;
import java.io.BufferedReader;
import java.io.InputStream;

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

    static class ASubscribers {
        public void solve(int testNumber, InputReader in, OutputWriter out) {
            int n = in.NextInt(), a = in.NextInt(), b = in.NextInt();
            int max = Math.min(a, b);
            int min = a + b - n;
            min = Math.max(min, 0);
            out.println(max);
            out.println(min);
        }

    }

    static class InputReader {
        BufferedReader reader;
        StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine(), " \t\n\r\f,");
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int NextInt() {
            return Integer.parseInt(next());
        }

    }

    static class OutputWriter extends PrintWriter {
        public OutputWriter(Writer out) {
            super(out);
        }

        public OutputWriter(File file) throws FileNotFoundException {
            super(file);
        }

        public OutputWriter(OutputStream out) {
            super(out);
        }

    }
}



Measured memory_bytes: 21332
#include <bits/stdc++.h>
#define rep(i,a,b) for(ll i=ll(a);i<ll(b);i++)
#define irep(i,a,b) for(ll i=ll(a);i>=ll(b);i--)
#define pb push_back
#define mp make_pair
#define pll pair<ll,ll>
#define F .first
#define S .second 
#define endl "\n"
using ll=long long;
using ld=long double;
using namespace std;
const ll mod=1e9+7;
//ll a[110000];
main(){
  //ll n,k,ans=0;
  //cin>>n;
  //rep(i,0,n)cin>>a[i];
  ll a,b,k;
  cin>>a>>b>>k;
  ll s=k;
  if(a>=k)a-=k;
  else if(a<k){b=max((ll)0,b-(k-a));a=0;}
  cout<<a<<" "<<b;
  
}


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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP0(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REP1(i,n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
#define RREP0(i,n) for(int i=n-1; i>=0; --i)
#define RREP1(i,n) for(int i=n; i>=1; --i)

#define SORT(c) sort((c).begin(),(c).end())
#define whole(f,x,...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x)
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define CLR(a) memset((a), 0 ,sizeof(a))

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

typedef long long LL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;

const int INTINF = 2147483647;
const LL LLINF = 9223372036854775807;
const double EPS = 1e-10;
const double PI  = acos(-1.0);

int gcd(int a,int b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int main(int argc, char const *argv[]) {
  cin.tie(0); ios::sync_with_stdio(false);
  int N,X,x;
  std::cin >> N >> X;
  VI cities; cities.reserve(N+1);

  REP0(i,N){
    std::cin >> x;
    cities.PB(abs(X-x));
  }

  int D;
  if (N>=2) {
    D = gcd(cities[0], cities[1]);
    for (int i = 2; i < N; i++) {
      D = gcd(D, cities[i]);
    }
  }else{
    D = cities[0];
  }
  std::cout << D << '\n';

  return 0;
}


Measured memory_bytes: 640
#include<stdio.h>
int main()
{
    int a,b,sum;
    char op;
    scanf("%d %c %d",&a,&op,&b);
    if(op=='+')
    {
        printf("%d",a+b);
    }
    else if(op=='-')
    {
        printf("%d",a-b);
    }
    return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;

class Main{
    public static void main(String args[]){
        Scanner scan=new Scanner(System.in);
        int n=scan.nextInt();
        int max=-1000001,min=1000001;
        long sum=0;
        int x;
        while(n--!=0){
            x=scan.nextInt();
            if(x>max)max=x;
            if(x<min)min=x;
            sum+=x;
        }
        System.out.println(min+" "+max+" "+sum);
   }
}


Measured memory_bytes: 41500
#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; }

int64_t H,W,K;
vector<string> fi;

int64_t solve() {
    int64_t res = 1 << 29;
    for ( int64_t bit = 0; bit < (1<<(H-1)); ++bit){
        bool gok = true; // そもそも不可能な場合がある
        int64_t N = 0;
        vector<int64_t> ord(H,0);
        for ( int64_t i = 0; i < H-1; ++i){
            if ( !( bit & (1<<i) ) ) {
                ord[i+1] = ord[i];
            } else {
                ord[i+1] = ord[i] + 1;
                ++N;
            }
        }
        int64_t add = 0;
        vector<int64_t> nums(N+1,0);
        for ( int64_t w = 0; w < W; ++w){
            vector<int64_t> one(N+1,0);
            bool ok = true;
            for ( int64_t h = 0; h < H; ++h){
                one[ord[h]] = one[ord[h]] + fi[h][w] - '0';
                nums[ord[h]] = nums[ord[h]] + fi[h][w] - '0';
                if ( one[ord[h]] > K ) gok = false;
                if ( nums[ord[h]] > K ) ok = false;
            }
            if ( !ok ) {
                ++add;
                nums = one;
            }
        }
        if ( gok ) {
            chmin(res,N+add);
        }
    }
    return res;
}

int main() {
    cin >> H >> W >> K;
    fi.resize(H);
    for ( int i = 0; i < H; ++i){
        cin >> fi[i];
    }
    
    cout << solve() << endl;
    
    return 0;
}


Measured memory_bytes: 3596
fun main(args: Array<String>) {
    val n = readLine()!!.toLong()
    val x = mutableListOf(0, 1, 2)
    var count = 0

    while (n >= toValue(x)) {
        if (x.contains(0) && x.contains(1) && x.contains(2)) {
            count += 1
        }
        countUp(x, x.size - 1)
    }

    println(count)
}

fun countUp(list: MutableList<Int>, digit: Int) {
    list[digit] += 1
    if (list[digit] >= 3) {
        list[digit] = 0
        if (digit > 0) {
            countUp(list, digit - 1)
        } else {
            list.add(0)
        }
    }
}

fun toValue(list: List<Int>): Long {
    var result = 0L
    list.forEach {
        result *= 10
        result += when (it) {
            0 -> 3
            1 -> 5
            else -> 7
        }
    }
    return result
}




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

int n, m, k;
long long ans = 0ll;

int gcd(int x, int y) {
	if (x < 0) x = -x;
	if (y < 0) y = -y;
	if (x < y) swap(x, y);
	while (y) {
		int r = x % y;
		x = y, y = r;
	}
	return x;
}
long long solve(int w, int h, int s) {
	long long res = 0ll;
	for (int i = 1; i < h; i++) {
		int i_ = max(i, h - i);
		// We can replace i with i_.
		for (int j = 1; j < w && j <= (2 * s + 3 * h) / i_; j++) {
			int k_min = (s * 2 - i_ * j) / (h - i_);
			k_min = min(k_min, w - 1);
			k_min = max(k_min, 0);
			res += k_min;
			int g = gcd(h - i_, j);
			for (int k = k_min + 1; k < w; k++) {
				if (i_ * j + (h - i_) * k - 3 * h + 2 > (s << 1)) break;
				int twice_n = i_ * j + (h - i_) * k - gcd(i_, k) - g - gcd(h, j - k) + 2;
				if (twice_n <= (s << 1)) res++; 
			}
		}
	}
	return res;
}
int main() {
	scanf("%d%d%d", &n, &m, &k);
	ans = (solve(n, m, k) + solve(m, n, k)) << 1;
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 3840
#define HAVE_STRUCT_TIMESPEC
#include<bits/stdc++.h>
using namespace std;
string s;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n;
    cin>>n;
    cin>>s;
    int cnt=1;
    for(int i=1;i<n;++i)
        if(s[i]!=s[i-1])
            ++cnt;
    cout<<cnt;
    return 0;
}


Measured memory_bytes: 512
//
#if 0

#endif // 0
#include<iostream>
#include<queue>
#define MAX 100
using namespace std;
int matri[MAX][MAX];

int main()
{
    int n;
    int r[MAX];
    queue<int> q;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        r[i]=0;
        for(int j=0;j<n;j++)
            matri[i][j]=0;
    }
    for(int i=0;i<n;i++)
    {
        int u,k;
        cin>>u>>k;
        for(int j=0;j<k;j++)
        {
            int m;
            cin>>m;
            matri[u-1][m-1]=1;
        }
    }
    q.push(0);
    r[0]=0;
    while(!q.empty())
    {
        int t;
        t=q.front();
        q.pop();
        for(int i=0;i<n;i++)
            if(matri[t][i]&&r[i]==0&&i)
            {
                q.push(i);
                r[i]=r[t]+1;
               // cout<<r[i]<<endl;
            }
    }
    for(int i=0;i<n;i++)
    {
        if(r[i]||r[i]==i)
            cout<<i+1<<" "<<r[i]<<endl;
        else
            cout<<i+1<<" -1"<<endl;
    }
    return 0;
}



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

using namespace std;

int main() {
  int a, b, c;
  scanf("%d%d%d", &a, &b, &c);
  for (int it = 0; it < 100; it++) {
    if ((a & 1) || (b & 1) || (c & 1)) {
      printf("%d\n", it);
      return 0;
    }
    int na = (b + c) / 2;
    int nb = (a + c) / 2;
    int nc = (a + b) / 2;
    a = na;
    b = nb;
    c = nc;
  }
  puts("-1");
}


Measured memory_bytes: 256
def main():
    num = int(input())

    b  = format(num, "032b")
    bi = format( ~num & 0b11111111111111111111111111111111, "032b")
    bl = format(num << 1, "032b")
    br = format(num >> 1, "032b")
    
    print(b)
    print(bi)
    if len(bl) > 32:
        print(bl[-32:])
    else:
        print(bl)

    print(br)

main()


Measured memory_bytes: 5612
N=int(input())
S=list(map(int,input().split( )))
S = sorted(S,reverse=True)
tri_num=0
for i in range(N-2):
    j = i+1
    k = N-1
    while k > j:
        if S[i] < S[j] + S[k]:
            tri_num += k-j
            j+=1
        else:
            k-=1
print(tri_num)


Measured memory_bytes: 3188
#include<iostream>
#include<vector>
#include<algorithm>
#include<utility>
using namespace std;

typedef long long ll;

ll w[101], v[101];

int main() {
    ll N, W, std_num, sub_count, max_count = 0;
    vector<ll> a, b, c, d;
    cin >> N >> W;
    for (int i = 0; i < N; i++) {
        cin >> w[i] >> v[i];
    }
    std_num = w[0];
    for (int i = 0; i < N; i++) {
        if (w[i] == std_num) a.push_back(v[i]);
        else if (w[i] == std_num + 1) b.push_back(v[i]);
        else if (w[i] == std_num + 2) c.push_back(v[i]);
        else d.push_back(v[i]);
    }
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    sort(c.begin(), c.end());
    sort(d.begin(), d.end());
    
    reverse(a.begin(), a.end());
    reverse(b.begin(), b.end());
    reverse(c.begin(), c.end());
    reverse(d.begin(), d.end());

    for (int i = 0; i <= a.size(); i++) {
        for (int j = 0; j <= b.size(); j++) {
            for (int k = 0; k <= c.size(); k++) {
                for (int l = 0; l <= d.size(); l++) {
                    if (std_num * i + (std_num + 1) * j + (std_num + 2) * k + (std_num + 3) * l > W) continue;
                    sub_count = 0;
                    for (int m = 0; m < i; m++) sub_count += a[m];
                    for (int m = 0; m < j; m++) sub_count += b[m];
                    for (int m = 0; m < k; m++) sub_count += c[m];
                    for (int m = 0; m < l; m++) sub_count += d[m];
                    if (sub_count > max_count) {
                        max_count = sub_count;
                    }
                }
            }
        }
    }
    cout << max_count << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
#define inf (int)(1e9+7)
#define abs(x) (x >= 0 ? x : -(x))
#define ceil(a, b) a / b + !!(a % b)
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }
// template<typename T> T pow(T a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }


// 約数の列挙 O(√n)
template <typename T>
vector<T> all_divisor_catch(T n) {
    vector<T> res;
    for (T i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            res.push_back(i);
            if (i != n / i) res.push_back(n / i);
        }
    }
    return res;
}

vector<pair<ll, int> > prime_factorize(ll n) { // n <= 10^12も考慮
    ll tmp = n;
    vector<pair<ll, int> > v;
    for (ll i = 2; i * i <= n; ++i) {
        ll cnt = 0;
        while (tmp % i == 0) {
            tmp /= i;
            cnt++;
        }
        if (cnt) v.eb(i, cnt);
    }
    if (tmp != 1) v.eb(tmp, 1);
    return v;
}


int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    /*
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    */
    
    /*
    int a, b, c;
    cin >> a >> b >> c;
    */
    
    /*
    int n;
    cin >> n;
    string s;
    cin >> s;
    */
    
    /*
    int n;
    cin >> n;
    int k;
    cin >> k;
    */
    
    int n, m;
    cin >> n >> m;
    vector<int> a(m);
    vector<int> c[m];
    
    set<int> ss;
    rep(i, m) {
        int b;
        cin >> a[i] >> b;
        rep(j, b) {
            int tmp;
            cin >> tmp;
            c[i].eb(tmp);
            ss.insert(tmp);
        }
    }
    if (sz(ss) != n) {
        cout << -1 << endl;
        return 0;
    }
    
    // dp[i][j] i個鍵みた, 買った宝j, val = 最小円
    // dp[m][1 << n - 1]
    
    int dp[m + 1][1 << n];
    fill_n(*dp, (m + 1) * (1 << n), inf);
    dp[0][0] = 0;
    
    rep(i, m) {
        int nxt = 0;
        rep(k, sz(c[i])) nxt |= (1 << (c[i][k] - 1));
        
        rep(j, 1 << n) { // 1000 * 4000
            if (dp[i][j] == inf) continue;
            chmin(dp[i + 1][j], dp[i][j]);
            
        
            chmin(dp[i + 1][j | nxt], dp[i][j] + a[i]);
        }
    }
    cout << dp[m][(1 << n) - 1] << endl;
    // rep(i, m + 1) { rep(j, 1 << n) cout << dp[i][j] << " "; cout << endl; }
}


Measured memory_bytes: 16384
#include<map>
#include<iostream>
#include<deque>
#include<algorithm>
#include<string>
#include<cctype>
#include<iomanip>
#include<vector>
#include<queue>
#include<math.h>
#include<bitset>
#include<random>
#include<cstdint>
 
using namespace std;
#define REP(i,b,e) for(ll i=(ll)b;i<(ll)e;i++)
#define rep0(i,n) REP(i,0ll,n)
#define rep1(i,n) REP(i,1ll,n+1)
 
#define shosu setprecision(17)
 
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<char,P> Q;
ll longinf=(1ll<<60);
int main(){
      int H,W;
      cin>>H>>W;
      char c[H][W];
      rep0(h,H)rep0(w,W) cin>>c[h][w];
      rep0(h,2*H){
            rep0(w,W) {cout<<c[(h/2)][w];}
            cout<<endl;
      }
      return 0;
}

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

#define rep(i,n) for(ll i=0;i<(n);++i)
#define reps(i,n) for(ll i=1;i<=(n);++i)
using ll = long long;
using str = string;
constexpr long long INF = (1LL<<60);
constexpr long long MOD = (1e9+7);
template<class T>inline bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>inline bool chmin(T &a,const T &b){if(a>b){a=b;return true;}return false;}
inline void dump(){cout<<endl;}
template<class Head,class... Tail>inline void dump(Head&& head, Tail&&... tail){cout<<head<<", ";dump(forward<Tail>(tail)...);}
template<typename T>inline istream &operator>>(istream&input,vector<T>&v){for(auto &elemnt:v)input>>elemnt;return input;}
template<class T>vector<T> make_vector(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto make_vector(size_t a, Ts... ts){return vector<decltype(make_vector<T>(ts...))>(a, make_vector<T>(ts...));}

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

  ll n,m,l;
  cin>>n>>m>>l;
  vector<vector<ll>> dist1 (n,vector<ll>(n,INF));
  vector<vector<ll>> dist2 (n,vector<ll>(n,INF));
  rep(i,m){
    ll a,b,c;
    cin>>a>>b>>c;
    a--;b--;
    chmin(dist1[a][b],c);
    chmin(dist1[b][a],c);
  }
  ll q;
  cin>>q;
  vector<pair<ll,ll>> query;
  rep(i,q){
    ll s,t;
    cin>>s>>t;
    s--;t--;
    query.emplace_back(s,t);
  }

  rep(k,n)rep(i,n)rep(j,n){
    if(dist1[i][k]==INF||dist1[k][j]==INF)continue;
    chmin(dist1[i][j],dist1[i][k]+dist1[k][j]);
  }

  rep(i,n)rep(j,n){
    if(dist1[i][j]<=l)dist2[i][j]=1;
  }

  rep(k,n)rep(i,n)rep(j,n){
    if(dist2[i][k]==INF||dist2[k][j]==INF)continue;
    chmin(dist2[i][j],dist2[i][k]+dist2[k][j]);
  }

  rep(i,q){
    ll s,t;tie(s,t)=query[i];
    if(dist2[s][t]<INF)cout<<(dist2[s][t]-1)<<endl;
    else cout<<(-1)<<endl;
  }

}


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

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		
		int n = stdIn.nextInt(); //n個の町
		
		int a = stdIn.nextInt(); //歩いた時の疲労度
		int b = stdIn.nextInt(); //テレポートによる疲労度
		
		int[]x = new int[n];
		
		for(int i = 0; i < n; i++) {
			x[i] = stdIn.nextInt();
		}
		
		long exhausted = 0;
		
		
		
		for(int i = 0; i < n-1; i++) {
			exhausted += ((x[i+1]-x[i])*(long)a) < b ?  ((x[i+1]-x[i])*(long)a): b;
		}
		System.out.println(exhausted);
		
		
		
		
	}

}


Measured memory_bytes: 49800
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b;
    cin>>a>>b;
    if(b>=0&&a<=0)  cout<<"Zero";
    else if((b>0&&a>0)||(a<0&&(b-a)%2==1))  cout<<"Positive";
    else  cout<<"Negative";
    cout<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll h[100009];
ll dp[100009];
int main() {
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)cin>>h[i];
    dp[1]=0;dp[2]=abs(h[2]-h[1]);
    for(int i=3;i<=n;i++){
        dp[i]=min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]));
    }
    cout<<dp[n]<<endl;
    return 0;
}

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

public class Main {

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

		BufferedReader input = new BufferedReader(new InputStreamReader(System.in));

		// ???????????\???????????????????????°??????????¨??????????????????????
		int digits_sum = 0;

		while (true) {

			// ???????????\???
			String num = input.readLine();

			// ????????????????????????
			if (num.equals("0")) {

				break;

			}

			// int???????????????????????\????????????String????????°?????§????´?
			char[] digits_number_array = num.toCharArray();

			// ?????????????????°?????????????????????
			int d_line_num = digits_number_array.length;

			// ?????????sum????¶????????????????
			digits_sum = 0;

			// ??\??????????????°?????????????????????????¶???????????????????
			for (int digits_number_spot = 0; digits_number_spot < d_line_num; digits_number_spot++) {

				// char???int??????????????¨??§????¶??????????????????????
				int digits_num = Character.getNumericValue(digits_number_array[digits_number_spot]);


				// ???????????°???????¶???????????????????
				digits_sum += digits_num;

			}

			System.out.println(digits_sum);

		}

	}

}

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

int main(){
  string S, T;
  cin >> S >> T;
  int count = 0;
  
  rep(i, 3){
    if(S[i] == T[i]) count++;
  }
  
  cout << count << endl;
}

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

using namespace std;

int main(void){
    int n, maxj = 1;
    cin >> n;
    string s;
    map<string, int> mapj;
    for(int i = 0; i < n; i++){
        cin >> s;
        if(mapj.count(s)){
            mapj.at(s)++;
            maxj = max(maxj, mapj.at(s));
        }else{
            mapj.insert(make_pair(s, 1));
        }
    }
    for(map<string, int>::iterator i = mapj.begin(); i != mapj.end(); i++){
        if(i->second == maxj){
            cout << i->first << endl;
        }
    }
    return 0;
}

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

int main () {
  int N, K, i, sum;
  cin >> N >> K;
  
  for (i = 0; i < N; i++) {
    int x;
    cin >> x;
    if (K - x < x) {
      sum += (K - x);
    }
    else {
      sum += x;
    }
  }
  
  cout << (sum * 2) << endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.next());
        int M = Integer.parseInt(sc.next());
        int[] prob = new int[N];
        prob[0] = 1;
        int[] cnt = new int[N];
        Arrays.fill(cnt, 1);
        for (int i=0;i<M;i++) {
            int x = Integer.parseInt(sc.next())-1;
            int y = Integer.parseInt(sc.next())-1;
            cnt[x]--;
            cnt[y]++;
            if (prob[x]==1) {
                prob[y]=1;
            }
            if (cnt[x]==0) prob[x]=0;
        }
        int ans = 0;
        for (int i=0;i<N;i++) {
            if (prob[i]==1) ans++;
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 50600
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const ll INF = 1e14;
const ll MOD = 1000000007;
const double PI = 3.1415926535897;

int main() {
    ll N,A,B;
    cin >> N >> A >> B;
    if(A > B) {
        ll tmp = A;
        A = B;
        B = tmp;
    }
    if((B - A) % 2 == 0) {
        cout << (B - A) / 2 << endl;
    }
    else {
        ll C = min(A + B - 2,(N - A + 1) + (N - B + 1) - 2);
        cout << (C + 1) / 2 << endl;
    }
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
const long long mod = 1000000007;
const int inf = 1145141919810931;
typedef pair<int, int> P;
typedef pair<P, int>PP;
typedef pair<int, char>PC;
struct edge { int to, cost; };
int t[100006], x[100006], y[100006];
signed main() {
	int n; cin >> n;
	rep(i, n)cin >> t[i+1] >> x[i+1] >> y[i+1];
	rep(i, n) {
		int dt = t[i + 1] - t[i], dx = x[i + 1] - x[i], dy = y[i + 1] - y[i];
		if ((dt & 1) != ((dx + dy) & 1)) {
			puts("No");
			return 0;
		}
		else if (dt < dx + dy) {
			puts("No"); return 0;
		}
	}puts("Yes");
}

Measured memory_bytes: 2560
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define repLRE(i, l, r) for (ll i = (l); i <= (r); ++i)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;

ll dx[9] = {-1, 1, 0, 0, -1, -1, 1, 1, 0};
ll dy[9] = {0, 0, -1, 1, -1, 1, -1, 1, 0};

/* Macros reg. ends here */

const ll INF = 1LL << 50;

static const long long mod = 1000000007;

int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cout << fixed << setprecision(15);

  string a, b;
  cin >> a >> b;

  if (a.size() > b.size()) puts("GREATER");
  else if (a.size() < b.size()) puts("LESS");
  else {
    if (a > b) puts("GREATER");
    else if (a == b) puts("EQUAL");
    else puts("LESS");
  }

  return 0;
}


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

#define REP(i, a, b) for (int i = (a), i##_end_ = (b); i < i##_end_; ++i)
#define MP make_pair
#define PB push_back
#define SZ(x) (int((x).size()))
#define ALL(x) (x).begin(), (x).end()
#define X first
#define Y second
template<typename T> inline bool chkmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; }
template<typename T> inline bool chkmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }

template <class T>  
inline bool RD(T &ret) {  
        char c; int sgn;  
        if (c = getchar(), c == EOF) return 0;  
        while (c != '-' && (c<'0' || c>'9')) c = getchar();  
        sgn = (c == '-') ? -1 : 1 , ret = (c == '-') ? 0 : (c - '0');  
        while (c = getchar(), c >= '0'&&c <= '9') ret = ret * 10 + (c - '0');  
        ret *= sgn;  
        return 1;  
}  
template <class T>  
inline void PT(T x) {  
        if (x < 0) putchar('-') ,x = -x;  
        if (x > 9) PT(x / 10);  
        putchar(x % 10 + '0');  
}

const int INF = 0x3f3f3f3f;
typedef long long LL;
typedef pair<int, int> pii;
typedef long double LD;


const LL MOD = 1e9 + 7;
LL dp[1 << 17][42];

int main() {
	LL ans = 0;
	int n, x, y, z;
	cin >> n >> x >> y >> z;
	int gmask = (1 << (x + y + z - 1)) | (1 << (z + y - 1)) | (1 << (z - 1));
	int m = 1 << (x + y + z);
	dp[0][0] = 1;
   	for(int i = 1; i <= n; i ++) {
		ans = 10 * ans % MOD;
		for(int mask = 0; mask < m; mask ++) {
			if((mask & gmask) == gmask || dp[mask][i - 1] == 0) continue;
			for(int num = 1; num <= 10; num ++) {
				int nmask = ((mask << num) | (1 << (num - 1))) & (m - 1);
				if((nmask & gmask) == gmask) ans = (ans + dp[mask][i - 1]) % MOD;
				else dp[nmask][i] = (dp[nmask][i] + dp[mask][i - 1]) % MOD;
			}
		}
	}	
	cout << ans << endl;
}



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

int main() {
    int N;
    cin >> N;
    vector<int>H(N);
    int count=1, tmp=0;
    for(int i=0; i<N; i++){
        cin >> H.at(i);
    }

    int j;
    for(int i=N-1; i>0; i--){
        tmp=0;
        for(j=i-1; j>-1; j--){
            if(H.at(i)<H.at(j)){
                break;
            }
        }
        if(j<0){
            count++;
        }
    }

    cout << count << endl;

  return 0;
}


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

int main() {
	string s, t;
	while(cin >> s >> t, s != "0" && t != "0") {
		int a[10] = {0}, b[10] = {0};
		int hit = 0, blow = 0;
		for(int i = 0; i < s.size(); i++) {
			if(s[i] == t[i])
				hit++;
			else {
				a[s[i]-'0']++;
				b[t[i]-'0']++;
			}
		}
		for(int i = 0; i < 10; i++) {
			blow += min(a[i], b[i]);
		}
		cout << hit << " " << blow << endl;
	}
}

Measured memory_bytes: 1184
#include <bits/stdc++.h>
using namespace std;
inline int read()
{
    int x = 0,f = 1;char ch = getchar();
    for(;!isdigit(ch);ch = getchar())if(ch == '-') f = -f;
    for(;isdigit(ch);ch = getchar())x = 10 * x + ch - '0';
    return x * f;
}
const int N = 2010 ;

int vis[N], ok[N][N], in[N], a[N] ;
vector <int> g[N] ;
int n ;

void dfs(int rt) {
    vis[rt] = 1 ;
    for (int i = 1; i <= n; i++)
    if (!vis[i] && ok[rt][i]) {
        in[i]++ ;
        g[rt].push_back(i) ;
        dfs(i) ;
    }
}

void Top() {
    priority_queue <int> q ;
    for (int i = 1;  i <= n; i++) if (!in[i]) q.push(i) ;
    while (!q.empty()) {
        int now = q.top() ;
        q.pop() ;
        cout << a[now] << " " ;
        for (int i = 0; i < g[now].size(); i++) q.push(g[now][i]) ;
    }
}

signed main(){
    scanf("%d", &n) ;
    for (int i = 1; i <= n; i++) scanf("%d", &a[i]) ;
    sort(a + 1, a + n + 1) ;
    for (int i = 1; i <= n; i++)
    for (int j = i + 1; j <= n; j++)
    if (__gcd(a[i], a[j]) != 1) ok[i][j] = ok[j][i] = 1 ;
    for (int i = 1; i <= n; i++) if (!vis[i]) dfs(i) ;
    Top() ;
}

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

long long N, X, A[100009], L;

long long gcd(long long a, long long b) {
	if (b == 0) return a;
	return gcd(b, a%b);
}

int main() {
	cin >> N >> X;
	for (int i = 1; i <= N; i++) cin >> A[i];
	L = abs(X - A[1]);
	for (int i = 1; i <= N; i++) L = gcd(L, abs(X - A[i]));
	cout << L << endl;
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define MOD 1000000007
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
using P = pair<int,int>;
const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

int main()
{
  ll N,K;
  cin >> N >> K;

  mint ans=0;
  FOR(i,K,N+2){
    ans+=(N-i+1)*i+1;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3592
#include <stdio.h>

int main(void) {
    int a,b,c,d,e;
    scanf("%d%d%d%d%d", &a,&b,&c,&d,&e);

    if(a == 0){
        printf("1\n");
    }else if(b == 0){
        printf("2\n");
    }else if(c == 0){
        printf("3\n");
    }else if(d == 0){
        printf("4\n");
    }else{
        printf("5\n");
    }
}

Measured memory_bytes: 1608
N, M, X = map(int, input().split())
arr = input().split()
list_fee = []

for i in range(N):
    if arr == []:
        break
    if int(arr[0]) == i+1:
        list_fee.append(1)
        arr.pop(0)
    else:
        list_fee.append(0)
    
a = list_fee[:X].count(1)
b = list_fee[X:].count(1)

print(min(a, b))

Measured memory_bytes: 3064
// contest.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//

#include "bits/stdc++.h"
using namespace std;

int main()
{
	int A, B, M;
	cin >> A >> B >> M;
	vector<int> R(A), E(B), X(M), Y(M), C(M);
	int p = 1000000, q = 1000000, v;
	for (int i = 0; i < A; i++)
	{
		cin >> R[i];
		p = min(p, R[i]);
	}
	for (int i = 0; i < B; i++)
	{
		cin >> E[i];
		q = min(q, E[i]);
	}
	v = p + q;
	for (int i = 0; i < M; i++)
	{
		cin >> X[i] >> Y[i] >> C[i];
		v= min(v, R[X[i]-1] + E[Y[i]-1] - C[i]);

	}
	cout << v;

	return 0;
}


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

#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define fst first
#define snd second
#define pb push_back
#define ALL(x) x.begin(),x.end()
#define EPS (1e-9)
#define equals(a,b) (fabs((a)-(b))<EPS)

using namespace std;

bool LT(double a,double b) { return !equals(a,b) && a < b; }
bool LTE(double a,double b) { return equals(a,b) || a < b; }

const string YES = "";
const string NO  = "";

typedef long long ll;

void solve() {

}

int a[3][3];
bool ok[3][3];

int main() {
  rep(i,3) rep(j,3) cin >> a[i][j];
  int n;
  cin >> n;
  rep(_,n) {
    int b;
    cin >> b;
    rep(i,3) rep(j,3) if( a[i][j] == b ) ok[i][j] = true;
  }
  /*
  rep(i,3) {
    rep(j,3) {
      cout << ok[i][j] << " ";
    } puts("");
  }
  */
  rep(i,3) {
    bool c = true;
    rep(j,3) if( !ok[i][j] ) { c = false; break; }
    if( c ) { puts("Yes"); return 0; }
  }
  rep(i,3) {
    bool c = true;
    rep(j,3) if( !ok[j][i] ) { c = false; break; }
    if( c ) { puts("Yes"); return 0; }
  }
  bool c = true;
  rep(i,3) if( !ok[i][i] ) { c = false; break; }
  if( c ) { puts("Yes"); return 0; }

  c = true;
  rep(i,3) if( !ok[2-i][i] ) {
    c = false; break; }
  if( c ) { puts("Yes"); return 0; }


  puts("No");
  
  return 0;
}


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

#define int long long
const int mod = 1e9 + 7;
int h, w, a, b, fac[200001], invfac[200001], ans;

int binpw(int base, int exp){
    int ans = 1;
    while(exp){
        if(exp % 2) ans = (ans * base) % mod;
        base = (base * base) % mod;
        exp /= 2;
    }
    return ans;
}

int c(int n, int k){
    int tmp = (fac[n] * invfac[k]) % mod;
    return (tmp * invfac[n - k]) % mod;
}

signed main(){
    fac[0] = 1;
    for(int i = 1; i <= 200000; i++) fac[i] = (fac[i - 1] * i) % mod;
    for(int i = 0; i <= 200000; i++) invfac[i] = binpw(fac[i], mod - 2);
    cin >> h >> w >> a >> b;
    for(int i = 1; i <= (h - a); i++){
        ans = ans + (c(b - 1 + i - 1, i - 1) * c(w - b - 1 + h - i, w - b - 1)) % mod;
    }
    cout << ans % mod;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
#define INF 1e18
#define int int64_t
vector<int>v;

int pos(int i,int x){
   
   int l = -1;int r = v.size();
   int mid;
   while(l+1<r)
   {
        mid = (l+r)/2;
        if(v[i]*v[mid]<x)
          l = mid;
        else
          r =mid;
   }
   return r;

}
int neg(int i,int x)
{
   int l = -1;int r = v.size();
   int mid;
   while(l+1<r)
   {
        mid = (l+r)/2;
        if(v[i]*v[mid]<x)
          r = mid;
        else
          l = mid;
   }
   return v.size()-r;

}
int calculate(int x) 
{
      int val = 0; int sum =0;
      for(int  i =0;i<v.size();i++)
      {
          if(v[i]<0)
             val = neg(i,x);
          else
             val = pos(i,x);

          if(v[i]*v[i]<x)
            val--;

          sum+= val;
      }

      return sum/2;
}
signed main(void)
{
  int n,k,a;
   cin>>n>>k;
  for(int i=0;i<n;i++){
    cin>>a;
    v.push_back(a);
  }
  
  sort(v.begin(),v.end());
   
  int l = -INF; int r = INF;  
  int mid;
       while(l+1<r)
       {  
            mid = (l+r)/2;
          
            if(calculate(mid)<k)
              l = mid;
            else
              r = mid;

       }
    
    cout<<l<<endl;

}

Measured memory_bytes: 2420