akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<cstring>
#include<queue>
#include<algorithm>
using namespace std;
const int MAXN=2005;
int n,a[MAXN];
int rd[MAXN];
int vis[MAXN];
struct edge
{
	int v,nxt;
	edge(){}
	edge(int vv,int nn)
	{
		v=vv,nxt=nn;
	}
}E[MAXN*MAXN];
int w[MAXN],ncnt=0;
struct node
{
	int id,val;
	node(){}
	node(int ii,int vv)
	{
		id=ii,val=vv;
	}
	bool operator < (const node &a)const 
	{
		return a.val>val;
	}
};
priority_queue<node>q;
int gcd(int a,int b)
{
	return b==0?a:gcd(b,a%b);
}
void addedge(int u,int v)
{
	ncnt++;
	E[ncnt]=edge(v,w[u]);
	w[u]=ncnt;
}
void dfs(int u)
{
	vis[u]=1;
	for(int i=1;i<=n;i++)
	{
		if(!vis[i]&&gcd(a[u],a[i])!=1)
		{
			dfs(i);
			rd[i]++;
			addedge(u,i);
		}
	}
}
int 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++)
		if(!vis[i])
			dfs(i);
	for(int i=1;i<=n;i++)
		if(rd[i]==0)
			q.push(node(i,a[i]));
	while(!q.empty())
	{
		node k=q.top();
		q.pop();
		printf("%d ",k.val);
		for(int i=w[k.id];i;i=E[i].nxt)
		{
			int v=E[i].v;
			rd[v]--;
			if(rd[v]==0)
				q.push(node(v,a[v]));
		}
	}
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,k,sum=0;
    cin>>n>>k;
    int x[n];
    sort(x,x+n);
    for(int i=0; i<n; i++)
    {
        cin>>x[i];
    }
     sort(x,x+n);

        for(int i=0; i<k; i++)
        {
            sum = sum+x[i];

        }
cout<<sum<<endl;
}


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

#define ll long long
#define fw(p) for(int w=0;w<(p);w++)
#define fx(p) for(int x=0;x<(p);x++)
#define fy(p) for(int y=0;y<(p);y++)
#define fz(p) for(int z=0;z<(p);z++)
#define fyg(p,g) for(int y=(g);y<(p);y++)
#define fzg(p,g) for(int z=(g);z<(p);z++)
#define ce(d) cout<<d<<endl;
#define vecp(p) int aa;cin>>aa;(p).push_back(aa);
#define vecpl(p) long long aa;cin>>aa;(p).push_back(aa);
#define vecps(p) string aa;cin>>aa;(p).push_back(aa);
#define vecp2(p) cin>>aa;(p).push_back(aa);
#define vecpl2(p) long long a	b;cin>>ab;(p).push_back(ab);
#define vecps2(p) string ab;cin>>ab;(p).push_back(ab);
#define sorts(c) sort((c).begin(),(c).end());
#define reverses(c) reverse((c).begin(),(c).end());
#define vec(b) vector<int> (b);
#define vecl(b) vector<long long> (b);
#define vecs(b) vector<string> (b);
#define pb(b,a) (b).push_back((a));
#define doublece(a,b) cout<<(a)<<' '<<(b)<<endl;
#define pairs(s) vector<pair<int,int>> (s);
#define pairsp(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define MOD 1000000007
#define cey ce("Yes")
#define cen ce("No")
#define ceY ce("YES")
#define ceN ce("NO")

int main()
{
	int N, M;
	cin >> N >> M;
	vector<vector<int> > G(N+1);
	fx(M) {
		int a, b;
		cin >> a >> b;
		G[a].push_back(b);
		G[b].push_back(a);
	}

	int cost[110000];
	fx(N) {
		cost[x + 1] = N+1;
	}
	cost[1] = 0;
	bool flags[110000] = { false, };
	int prev[110000];
	priority_queue<pair<int,int> > Q;
	Q.push(make_pair(0,1));
	while (Q.size()) {
		auto q = Q.top(); Q.pop();
		if (flags[q.second]) {
			continue;
		}
		flags[q.second] = true;
		fx(G[q.second].size()) {
			if (cost[G[q.second][x]]>cost[q.second]+1) {
				cost[G[q.second][x]] = cost[q.second] + 1;
				prev[G[q.second][x]] = q.second;
				Q.push(make_pair(-cost[G[q.second][x]], G[q.second][x]));
			}
		}
	}
	fx(N) {
		if (cost[x+1]>N) {
			cen;
			return 0;
		}
	}
	cey;
	fyg(N,1) {
		ce(prev[y+1])
	}

    return 0;
}



Measured memory_bytes: 11324
#include <bits/stdc++.h>
using namespace std;
int main(void){
    long long int n,a;
    cin>>n;
    std::deque<long long int> deq;
    for (int i=0;i<n;i++) {
        cin>>a;
        deq.emplace_back(a);
    }
    int flag=0;
    long long int max=0;
    for (int j=0;j<n;j++) {
        if (deq[j]<max&&deq[j]-1<max) {
            cout<<"No"<<endl;
            flag=1;
            break;
        } else {
            if (j!=n-1&&deq[j]>deq[j+1]) {
                if (abs(deq[j]-deq[j+1])>1) {
                    cout<<"No"<<endl;
                    flag=1;
                    break;
                } else if (abs(deq[j]-1-deq[j+1])>1) {
                    cout<<"No"<<endl;
                    flag=1;
                    break;
                } else {
                    if (max<deq[j]-1) {
                        max=deq[j]-1;
                    }
                }
            } else {
                if (max<deq[j]-1) {
                    max=deq[j]-1;
                }
            }
        }
    }
    if (flag==0) {
        cout<<"Yes"<<endl;
    }
}

Measured memory_bytes: 1024
using System;
using System.Collections.Generic;
using System.Numerics;
using System.Linq;
using static System.Math;

class MainClass
{

    public static void Main(string[] args)
    {
        var N = LnInt();
        var S = LnStr();

        long r = S.Count(x => x == 'R');
        long g = S.Count(x => x == 'G');
        long v = S.Count(x => x == 'B');
        long result = r * g * v;

        long count = 0;
        for (var i = 0; i <= N; i++)
        {
            for (var dif = 1; (i + dif + dif) < N; dif++)
            {
                var j = i + dif;
                var k = j + dif;

                if ((S[i] != S[j]) && (S[i] != S[k]) && (S[j] != S[k]))
                    count++;
            }
        }
        Console.WriteLine(result - count);
    }



    public static int[] LnInts()
    {
        var vs = Console.ReadLine().Trim().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
        var ins = new int[vs.Length];
        for (int i = 0; i < vs.Length; i++) ins[i] = int.Parse(vs[i]);
        return ins;
    }

    public static int LnInt()
    {
        var vs = Console.ReadLine().Trim();
        return int.Parse(vs);
    }

    public static string[] LnStrs()
    {
        var vs = Console.ReadLine().Trim().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
        return vs;
    }
    public static string LnStr()
    {
        var vs = Console.ReadLine().Trim();
        return vs;
    }
}

Measured memory_bytes: 27928
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define All(a) a.begin(),a.end()
#define INF 1000000007
const int MOD = 1000000007;
//accumulate(vec.begin(), vec.end(), 0)

int gcd(int x,int y){
  if(x%y==0) return y;
  else return gcd(y,x%y);
}

int main(){
  int n,m;
  int cnt =0 ;
  cin >> n >> m;
  vector<int>H(n);
  vector<bool>C(n,true);
  for(int i=0;i<n;i++) cin >> H[i];
  for(int i=0;i<m;i++){
    int a,b;
    cin >> a >> b;
    a--,b--;
    if(H[a]==H[b]){
      C[a]=false;
      C[b]=false;
    }
    else if(H[a]>H[b]) C[b]=false;
    else C[a]=false;
  }
  cout<< accumulate(All(C),0) <<endl;
}


Measured memory_bytes: 3788
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int A[3][3];
bool c[3][3];

int main()
{
	rep(i,3)
	{
		rep(j,3)
		{
			cin >> A[i][j];
		}
	}
	int N;
	cin >> N;
	rep(i,N)
	{
		int b;
		cin >> b;
		rep(j,3)
		{
			rep(k,3)
			{
				if (b == A[j][k]) c[j][k] = true;
			}
		}
	}
	/*
	rep(i,3)
	{
		rep(j,3)
		{
			cout << c[i][j] << " "; 
		}
		cout << endl;
	}
	*/
	bool ans = false;
	rep(i,3)
	{
		if (c[i][0] && c[i][1] && c[i][2]) ans = true;
		if (c[0][i] && c[1][i] && c[2][i]) ans = true;
	}
	if (c[0][0] && c[1][1] && c[2][2]) ans = true;
	if (c[0][2] && c[1][1] && c[2][0]) ans = true;

	if (ans) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Math;

class MainClass
{
    static void Main()
    {
        int n = int.Parse(ReadLine());
        var v = ReadLine().Split().Select(int.Parse).ToArray();

        var dic1 = new Dictionary<int, int>();
        var dic2 = new Dictionary<int, int>();
        for (int i = 0; i < n; i+=2)
        {
            if (dic1.ContainsKey(v[i])) dic1[v[i]]++;
            else dic1[v[i]] = 1;
        }
        for (int i = 1; i < n; i+=2)
        {
            if (dic2.ContainsKey(v[i])) dic2[v[i]]++;
            else dic2[v[i]] = 1;
        }
        var pair1 = dic1.OrderByDescending(_ => _.Value).ToArray();
        var pair2 = dic2.OrderByDescending(_ => _.Value).ToArray();
        var odd = pair1[0].Value;
        var even = pair2[0].Value;
        var minus = 0;
        if (pair1[0].Key == pair2[0].Key)
        {
            if (pair1.Length >= 2)
            {
                minus = odd - pair1[1].Value;
            }
            else
            {
                minus = odd;
            }
            if (pair2.Length >= 2)
            {
                minus = Min(minus, even - pair2[1].Value);
            }
            else
            {
                minus = Min(minus, even);
            }
        }
        WriteLine(n-odd-even+minus);
    }
}


Measured memory_bytes: 40644
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();

int main() {
    int A, B, Q;
    cin >> A >> B >> Q;
    ll pos;
    set<ll> shrine;
    set<ll> temple;
    for(int i = 0; i < A; i++) {
        cin >> pos;
        shrine.insert(pos);
    }

    for(int i = 0; i < B; i++) {
        cin >> pos;
        temple.insert(pos);
    }
    auto to_nearest = [&] (ll start, set<ll>& building) {
        auto it = building.upper_bound(start);
        ll ans = 1e15;
        if (it != building.end())
            ans = min(ans, llabs(start-*it));
        if (it != building.begin())
            ans = min(ans, llabs(start-*prev(it)));
        return ans;
    };
    while (Q--) {
        ll res = 1e15;
        cin >> pos;
        // shrine first;
        ll tmp = 0;
        auto it = shrine.upper_bound(pos);
        if (it != shrine.end()) {
            tmp += llabs(pos-*it);
            tmp += to_nearest(*it, temple);
            res = min(res, tmp);
        }
        tmp = 0;
        if (it != shrine.begin()) {
            tmp += llabs(pos-*prev(it));
            tmp += to_nearest(*prev(it), temple);
            res = min(res, tmp);
        }
        tmp = 0;
        it = temple.upper_bound(pos);
        if (it != temple.end()) {
            tmp += llabs(pos-*it);
            tmp += to_nearest(*it, shrine);
            res = min(res, tmp);
        }
        tmp = 0;
        if (it != temple.begin()) {
            tmp += llabs(pos-*prev(it));
            tmp += to_nearest(*prev(it), shrine);
            res = min(res, tmp);
        }
        cout <<res << endl;
    }
    return 0;
}

Measured memory_bytes: 10752
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define f first
#define s second
#define pb push_back
#define eb emplace_back
#define mk make_pair
#define mt make_tuple
#define MOD 1000000007
#define fo(i,a,b) for(i=a;i<b;i++)
#define foe(i,a,b) for(i=a;i<=b;i++)
#define all(x) x.begin(), x.end()
#define vi vector<int>
#define vl vector <long long int>
#define pii pair <int,int>
#define pll pair <long long int, long long int>
#define vpii vector< pair<int,int> >
#define vpll vector < pair <long long int,long long int> >
#define boost ios::sync_with_stdio(false); cin.tie(0)
using namespace std;
const int inf = 1e9 + 5;
const ll inf64 = 1e18 + 5;

int main()
{
	boost;
	int x;
	cin >> x;
	cout << (x >= 30 ? "Yes\n" : "No\n");
}


Measured memory_bytes: 3664
N,K=map(int,input().split())
A = list(map(int,input().split()))
count = 0
now = 1
city = [1]
city2 = {1}
while count < K:
    count +=  1
    now = A[now-1]
    if now in city2:
        break
    else:
        city.append(now)
        city2.add(now)
if count == K:
    print(now)
else:
    n = city.index(now)
    K -= n
    count -= n
    K %= count
    print(city[n+K])

Measured memory_bytes: 32356
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int x = sc.nextInt();
		int ans = 0;
		for(int i = 0; i <= a; i++)
			for(int j = 0; j <= b; j++)
				for(int k = 0; k <= c; k++)
					if(500*i+100*j+50*k == x) ans++;
		System.out.println(ans);
	}
}


Measured memory_bytes: 21972
/* ex4_3
	kanon */

#include <stdio.h>
#include <math.h>

//n番目の塔の高さを求める
int calculate_height(int height_a,int height_b);

int main(void)
{

    //与えられる値を入れる数を宣言
    int height_a,height_b;

    //変数に値を入力する
    scanf("%d %d",&height_a,&height_b);
    
    int ans=calculate_height(height_a,height_b);
    printf("%d",ans);

    return 0;
}

int calculate_height(int height_a,int height_b){
    int snow_height=0;
    //高さの差を計算する
    int diff=height_b-height_a;
    //diff-1番目の塔ーheight_a＝求める雪の高さ
    for(int i=1;i<diff;i++){
        snow_height+=i;
    }
    return snow_height-height_a;
}


Measured memory_bytes: 128
n, p = map(int, input().split())
a = list(map(int, input().split()))
flag = True
for i in a:
    if i % 2 == 0:
        continue
    else:
        flag = False
        break

if n == 1 and a[0] % 2 == 0:
    if p == 0:
        print(2)
    else:
        print(0)
elif n == 1 and a[0] % 2 == 1:
    print(1)

else:
    if flag:
        if p == 0:
            print(2 ** n)
        else:
            print(0)
    else:
        print(2 ** n // 2)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define NMAX 2010
using namespace std;

bool Vis[NMAX];
vector <int> V[NMAX];
int n, Done[NMAX][NMAX], Map[NMAX], num[NMAX];

void DFS(int Root) {
    Vis[Root] = 1;
    for (int i = 1; i <= n; ++i) {
	    if (!Vis[i] && Done[Root][i]) {
	        ++Map[i];
	        V[Root].push_back(i);
	        DFS(i);
	    }
    }
}

void Top() {
    priority_queue <int> Q;
    for (int i = 1; i <= n; ++i) {
    	if (!Map[i]) Q.push(i);
    }
    while (!Q.empty()) {
        int now = Q.top();
        Q.pop();
        printf("%d ", num[now]);
        for (int i = 0; i < V[now].size(); ++i) Q.push(V[now][i]);
    }
}

signed main(){
    scanf("%d", &n);
    for (int i = 1; i <= n; ++i) scanf("%d", &num[i]);
    sort(num + 1, num + n + 1);
    for (int i = 1; i <= n; ++i) {
    	for (int j = i + 1; j <= n; ++j) {
    		if (__gcd(num[i], num[j]) != 1) Done[i][j] = Done[j][i] = 1;
    	}
    }
    for (int i = 1; i <= n; ++i) if (!Vis[i]) DFS(i);
    Top();
    return 0;
}

Measured memory_bytes: 16256
import bisect

n = int(input())
ListL = [int(i) for i in input().split()]

ListL.sort()
ans = 0

for i in reversed(range(2, n)):
	a = ListL[i]
	b = ListL[i-1]
	c = a - b + 1
	indexb = i - 1
	indexc = bisect.bisect_left(ListL, c)
	while(indexb > indexc):
		if (ListL[indexb] + ListL[indexc] > a):
			ans += indexb - indexc
			indexb -= 1
		else:
			indexc += 1

print(ans)

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

int main(){
  int A,B,C;
  cin >>A>>B>>C;
  
  string ans = "NO";
  repeat(i,1,B){
    if(i*A%B==C) {
      ans = "YES";
      break;
    }
  }
  cout <<ans<< endl;
}

Measured memory_bytes: 256
N,X = map(int,input().split(" "))
l_list = input().split()

count = 1
d = 0
for i in range(N):
        da = d + int(l_list[i])
        d = da
        if da <= X:
                count +=1
        else:

                print(count)
                break
        if count == int(N) + 1:
                print(count)

Measured memory_bytes: 3060
#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<set>

#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 FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)

using namespace std;

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

/*
template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
	return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T& t, const V& v) { t = v; }
template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T& t, const V& v) {
	for (auto& e : t) fill_v(e, v);
}*/


#define ARRAY_MAX 100005
const ll INF = 1e9 + 7;


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

const ll MOD = 1e9 + 7;


ll dp[105][4][4][4];


//TAGCを0123に割り当てる

int main() {

	ll n;
	cin >> n;

	dp[0][0][0][0] = 1;

	for (int i = 0; i < n; i++)
	{
		for (int a = 0; a < 4; a++)
		{
			for (int b = 0; b < 4; b++)
			{
				for (int c = 0; c < 4; c++)
				{
					for (int d = 0; d < 4; d++)
					{
						if (b == 1 && c == 2 && d == 3)continue;//直前3文字がAGC
						if (b == 1 && c == 3 && d == 2)continue;//直前3文字がACG
						if (b == 2 && c == 1 && d == 3)continue;//直前3文字がGAC
						if (a == 1 && b == 2 && d == 3)continue;//直前4文字がAG?C
						if (a == 1 && c == 2 && d == 3)continue;//直前4文字がA?GC

						dp[i + 1][b][c][d] += dp[i][a][b][c];
						dp[i + 1][b][c][d] %= MOD;
					}
				}
			}
		}
	}

	ll ans = 0;
	for (int a = 0; a < 4; a++)
	{
		for (int b = 0;  b < 4;  b++)
		{
			for (int c = 0; c < 4; c++)
			{
				ans += dp[n][a][b][c];
				ans %= MOD;
			}
		}
	}

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


Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main(void){
  int input,pasta,juice;
  cin>>pasta;
  cin>>input;
  if(input<pasta) pasta=input;
  cin>>input;
  if(input<pasta) pasta=input;
  cin>>juice;
  cin>>input;
  if(input<juice) juice=input;
  cout<<(juice+pasta)-50<<endl;
  return 0;
}

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

const int INF = 1e9;

int main() {
	int N, W;
	cin >> N >> W;
	vector<int> v(N, 0);
	vector<int> w(N, 0);
	for (int i=0;i<N;i++) {
		cin >> v[i] >> w[i];
	}

	vector<vector<int>> dp(N+1, vector<int>(W+1, -INF));
	dp[0][0] = 0;
	for (int i=0;i<N;i++) {
		for (int j=0;j<W+1;j++) {
			dp[i+1][j] = max(dp[i+1][j], dp[i][j]);
			if (j+w[i]<W+1) dp[i+1][j+w[i]] = max(dp[i+1][j+w[i]], dp[i+1][j]+v[i]);
		}
	}

	int ans = 0;
	for (int i=0;i<=W;i++) ans = max(ans, dp[N][i]);

	cout << ans << endl;
}


Measured memory_bytes: 6852
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		double a = sc.nextInt();
		double b = sc.nextInt();
		double x = sc.nextInt();
		if(x == a*a*b)
			System.out.println(0);
		else if(x > a*a*b/2)
			System.out.println(Math.atan((2*b-2*x/a/a)/a)/Math.PI*180);
		else
			System.out.println(Math.atan(b*b*a/x/2)/Math.PI*180);

	}

}


Measured memory_bytes: 23124
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vin=vector<int>;
using vll=vector<long long>;
using vvin=vector<vector<int>>;
using vvll=vector<vector<long long>>;
using vstr=vector<string>;
using vvstr=vector<vector<string>>;
using vch=vector<char>;
using vvch=vector<vector<char>>;
using vbo=vector<bool>;
using vvbo=vector<vector<bool>>;
using vpii=vector<pair<int,int>>;
using pqsin=priority_queue<int,vector<int>,greater<int>>;
#define mp make_pair
#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++)
#define all(v) v.begin(),v.end()
#define decp(n) cout<<fixed<<setprecision((int)n)
const int inf=1e9+7;
const ll INF=1e18;

int main(){
    int n;cin>>n;
    int tmp=1;int m=0;
    int a;
    rep(i,n){
        cin>>a;
        if(a==tmp)tmp++;
    }
    if(tmp==1)cout<<-1<<endl;
    else cout<<n-tmp+1<<endl;
}

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

int main() {
    int n;
    cin>>n;
    vector<int> vi(n,0);
    
    int input;
    for (size_t i = 0; i < n; i++)
    {
        scanf("%d",&input);
        vi[input-1] = i;
    }
    for (size_t i = 0; i < n; i++)
    {
        cout << vi[i]+1<<" ";
    }
    
    cout<<endl;
    return 0;
}

Measured memory_bytes: 1152
from collections import deque
H, W = map(int, input().split())
G = [input() for _ in range(H)]
num = 0
for i in range(H):
    for j in range(W):
        if G[i][j] == ".":
            num += 1
q = deque([(0, 0)])
done = [[-1]*W for _ in range(H)]
done[0][0] = 1
while q:
    w, h = q.popleft()
    for dw, dh in [[0, 1], [0, -1], [1, 0], [-1, 0]]:
        nw, nh = w+dw, h+dh
        if not (0 <= nw < W and 0 <= nh < H and G[nh][nw] == "." and done[nh][nw] == -1): continue
        done[nh][nw] = done[h][w]+1
        q.append((nw, nh))
if done[H-1][W-1] != -1:
    print(num-done[H-1][W-1])
else:
    print(-1)


Measured memory_bytes: 9304
# B
# get bingo sheet numbers
first_array = [int(i) for i in input().split()]
second_array = [int(i) for i in input().split()]
third_array = [int(i) for i in input().split()]
N = int(input())
bs = []
for i in range(N):
    bs.append(int(input()))

first_array = [(i in bs) for i in first_array]
second_array = [(i in bs) for i in second_array]
third_array = [(i in bs) for i in third_array]
check_array = [True for i in range(3)]
bingo = [first_array, second_array, third_array]
# [0][0] == first_array[0]

def main():
    bingo_count = int()
    # horizon
    for horizon in bingo:
        bingo_count += int(horizon == check_array)

    # vertical
    for i in range(3):
        vertical = []
        for j in range(3):
            vertical.append(bingo[j][i])
        bingo_count += int(vertical == check_array)

    # diagnal 1
    diagnal = [bingo[i][i] for i in range(3)]
    bingo_count += int(diagnal == check_array)

    # diagnal 2
    diagnal = [bingo[i][up] for up,i in enumerate(reversed(range(3)))]
    bingo_count += int(diagnal == check_array)
    
    # last bingo check
    if bingo_count > 0:
        print("Yes")
    else:
        print("No")
main()

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

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> p(n), c(n);
  rep(i, n) cin >> p[i];
  rep(i, n) cin >> c[i];
  rep(i, n) p[i]--;

  ll ans = -1e18;
  rep(si, n) {
    int x = si;
    vector<int> s;
    ll tot = 0;
    while (true) {
      x = p[x];
      s.push_back(c[x]);
      tot += c[x];
      if (x == si) break;
    }
    int l = s.size();
    ll t = 0;
    rep(i, l) {
      t += s[i];
      if (i + 1> k) break;
      ll now = t;
      if (tot > 0) {
        ll e = (k - i - 1) / l;
        now += tot * e;
      }
      ans = max(ans, now);
    }
  }

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

Measured memory_bytes: 3732
def find(x):
    if par[x] < 0:
        return x
    else:
        par[x] = find(par[x])
        return par[x]


def union(x, y):
    x = find(x)
    y = find(y)
    
    if x == y:
        return

    # sizeの大きいほうがx
    if par[x] > par[y]:
        x, y = y, x
    par[x] += par[y]
    par[y] = x


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


def size(x):
    return -par[find(x)]


n, m, k = map(int, input().split())

par = [-1] * n
friend = [0] * n
for _ in range(m):
    a, b = map(int, input().split())
    union(a-1, b-1)
    friend[a-1] += 1
    friend[b-1] += 1

block = [[] for _ in range(n)]
for _ in range(k):
    c, d = map(int, input().split())
    block[c-1].append(d-1)
    block[d-1].append(c-1)

for i in range(n):
    ans = size(i) - friend[i] - 1
    for j in block[i]:
        if same(i, j):
            ans -= 1
    print(ans, end=' ')

Measured memory_bytes: 112472
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); i++)
 
int main() {
  int n;
  cin >> n;
  vector<string> s(n);
  rep(i, n) cin >> s.at(i);
  vector<int> c(4);
  c = {0, 0, 0, 0};
  rep(i, n){
  	if(s.at(i) == "AC") c.at(0)++;
    if(s.at(i) == "WA") c.at(1)++;
    if(s.at(i) == "TLE") c.at(2)++;
    if(s.at(i) == "RE") c.at(3)++;
    }
  
  cout << "AC x " << c.at(0) << endl;
  cout << "WA x " << c.at(1) << endl;
  cout << "TLE x " << c.at(2) << endl;
  cout << "RE x " << c.at(3) << endl;
  return 0;
}

Measured memory_bytes: 6412
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
const int inf=1e9+7;
const ll mod=1e9+7;

int main() {
    int N;
    cin>>N;
    vector<pair<int, int> > red;
    vector<pair<int, int> > blue;
    int a, b, c, d;
    for(int i=0;i<N;++i){
        cin>>a>>b;
        red.push_back(make_pair(a, b));
    }
    for(int i=0;i<N;++i){
        cin>>c>>d;
        blue.push_back(make_pair(c, d));
    }
    sort(red.begin(), red.end(), greater<pair<int, int> >());
    sort(blue.begin(), blue.end(), greater<pair<int, int> >());
    int ans = 0;
    map<int, int> usedblue;
    int index;
    int miny;
    bool tmpans;
    for(int i=0;i<N;++i){
        miny = 300;
        tmpans = false;
        for(int j=0;j<N;++j){
            if((usedblue[j]==0) & (miny > blue[j].se) & (red[i].fi < blue[j].fi) & (red[i].se < blue[j].se)){
                index = j;
                miny = blue[j].se;
                tmpans = true;
            }
        }
        if(tmpans){
            usedblue[index]++;
            ans++;
        }
    }
    cout<<ans<<endl;
}



Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)n; ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cout<<*i<<" "; cout<<endl; }

typedef long long ll;
typedef pair<int,int> P;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;

int main(){
  int R,C;
  bool f = false;
  while(cin>>R>>C){
    if(f) cout<<endl;
    else f = true;
    int data[101][101];
    int cntx[101]={};
    int cnty[101]={};
    vector<P> fout;
    REP(y,R+1)REP(x,C+1){
      string s; cin>>s;
      if(s == "?") {
        data[y][x] = -INF;
        fout.push_back(P(x,y));
        cntx[x]++;
        cnty[y]++;
      } else {
        data[y][x] = atoi(s.c_str());
      }
    }
    while(true){
      bool updata = false;
      REP(y,R+1){
        if(cnty[y] == 1){
          updata = true;
          int sum = 0;
          REP(x,C+1)if(data[y][x]!=-INF)sum += ((x==C)?1:-1) * data[y][x];
          REP(x,C+1)if(data[y][x]==-INF){
            data[y][x] = ((x==C)?-1:1) * sum;
            cntx[x]--;
            cnty[y]--;
          }
        }
      }
      REP(x,C+1){
        if(cntx[x] == 1){
          cntx[x] = 0;
          updata = true;
          int sum = 0;
          REP(y,R+1)if(data[y][x]!=-INF)sum += ((y==R)?1:-1) * data[y][x];
          REP(y,R+1)if(data[y][x]==-INF){
            data[y][x] = ((y==R)?-1:1) * sum;
            cntx[x]--;
            cnty[y]--;
          }
        }
      }
      if(!updata) break;
    }
    int cnt = 0;
    REP(y,R+1)REP(x,C+1)if(data[y][x]==-INF) cnt++;
    if(cnt > 0) cout<<"NO"<<endl;
    else {
      REP(i, fout.size()){
        cout<<data[fout[i].second][fout[i].first]<<endl;
      }
    }
  }
  return 0;
}

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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);

	int32 H, W, N;
	cin >> H >> W >> N;
	vector<PII> v(N);
	REP(i, v.size()){
		cin >> v[i].fs >> v[i].sc;
	}
	sort(all(v));
	int32 nowy = 1;
	int32 res = H;
	REP(i, N){
		if(i > 0){
			nowy += max(v[i].fs-v[i-1].fs-1, (int32)0);
		}else{
			nowy += max(v[i].fs-2, (int32)0);
		}
		if(nowy >= v[i].sc){
			res = min(res, v[i].fs-1);
		}
		bool ok = v[i].sc-1 != nowy;
		while(v[i].fs == v[i+1].fs){
			i++;
			ok = ok && (v[i].sc-1 != nowy);
		}
		if(ok && (v[i].fs > 0)) nowy++;
	}
	cout << res << endl;
}


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

int main() {
    int n;
    cin >> n;
    ll a[n];
    rep(i, n) {
        ll b;
        cin >> b;
        if (b == 0) {
            cout << 0 << endl;
            return 0;
        }
        a[i] = b;
    }

    ll ans = 1;
    rep(i, n) {
        if (a[i] <= 1000000000000000000 / ans) {
            ans *= a[i];
        } else {
            cout << -1 << endl;
            return 0;
        }
    }

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


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

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repm(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define inf 2e9
#define MOD 1000000007

using namespace std;
typedef long long ll;

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

  ll ans_a = 0, ans_b = 0;
  if(a < k) ans_b = (b+(a-k) < 0)? 0:b+(a-k);
  else{
    ans_a = a-k;
    ans_b = b;
  }

  cout << ans_a << " " << ans_b << endl;
}


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

int retGCD(int a,int b);

int main(void){
	int n,k,i,max=0,in;
	int gcd;
	scanf("%d %d",&n,&k);
	for(i=0;i<n;i++){
		scanf("%d",&in);
		if(max<in) max=in;
		if(i==0) gcd=in;
		else gcd=retGCD(gcd,in);
	}
	if(max<k || k%gcd>0) puts("IMPOSSIBLE");
	else puts("POSSIBLE");
	return 0;
}

int retGCD(int a,int b){
	if(a<b){
		int tmp=a;
		a=b;
		b=tmp;
	}
	if(b==0) return a;
	else return retGCD(b,a%b);
}


Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;


long long mul_inv(long long a, long long b)
{
	long long b0 = b, t, q;
	long long x0 = 0, x1 = 1;
	if (b == 1) return 1;
	while (a > 1) {
		q = a / b;
		t = b, b = a % b, a = t;
		t = x0, x0 = x1 - q * x0, x1 = t;
	}
	if (x1 < 0) x1 += b0;
	return x1;
}

long long division(long long a, long long b, long long p) {		// (a / b) mod p = ((a mod p) * (b^(-1) mod p)) mod p
	long long ans, inv;
	inv = mul_inv(b, p);
	ans = ((a % p) * inv) % p;
	return ans;
}




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

	long long n, s, i, j, k, ans, MOD = 998244353, x, p2;
	cin >> n >> s;
	vector<long long> a(n);
	for (i = 0; i < n; i++) cin >> a[i];

	vector<long long> pow2(n + 1);
	pow2[0] = 1;
	for (i = 1; i <= n; i++) pow2[i] = (pow2[i - 1] * 2) % MOD;
	p2 = division(1, 2, MOD);

	vector<vector<long long>> dp(n + 1, vector<long long>(s + 1, 0));
	vector<vector<long long>> dpsum(n + 1, vector<long long>(s + 1, 0));
	dp[0][0] = 1;
	dpsum[0][0] = pow2[n];

	for (i = 0; i < n; i++) {
		dp[i + 1] = dp[i];
		dpsum[i + 1] = dpsum[i];
		for (j = 0; j <= s; j++) {
			x = (dpsum[i][j] * p2) % MOD;
			//dpsum[i + 1][j] = (dpsum[i + 1][j] + x) % MOD;
			if (j + a[i] <= s) {
				dp[i + 1][j + a[i]] = (dp[i + 1][j + a[i]] + dp[i][j]) % MOD;
				dpsum[i + 1][j + a[i]] = (dpsum[i + 1][j + a[i]] + x) % MOD;
			}
		}
	}
		
	ans = dpsum[n][s];
	cout << ans << "\n";


	return 0;
}


Measured memory_bytes: 144180
#include <bits/stdc++.h>
using namespace std;
#define fastIO ios::sync_with_stdio(0), cin.tie(0)
#define endl '\n'
#define ft first
#define sd second
#define pb push_back
#define pob pop_back()
#define pf push_front
#define pof pop_front()
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin, (x).rend()
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<char,char> pcc;
typedef pair<double,double> pdd;
typedef pair<long long,long long> pll;
// scanf("%d %d %d %d",&w,&b,&d,&s); %lld
// printf("%d\n" ,points);
// const double PI=acos(-1);

const int MAX=1e5+5;
bool dp[MAX];
int n,k;

int main(){
    cin >> n >> k;
    int aux;
    vector<int> stones;
    for(int i=0;i<n;i++){
        cin >> aux;
        stones.pb(aux);
    }
    for(int i=1;i<=k;i++){
        bool ok=false;
        for(int j=0;j<n;j++){
            if(i-stones[j]>-1){
                if(!dp[i-stones[j]]) ok=true;
            }
        }
        dp[i]=ok;
    }
    if(dp[k]) cout << "First" << endl;
    else cout << "Second" << endl;
    return 0;
}


Measured memory_bytes: 3704
import sys
import math
stdin = sys.stdin
mod = 10**9 + 7

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
sa = lambda h: [list(map(int, stdin.readline().split())) for i in range(h)]

a, b = na()
if a < 10 and b < 10:
    print(a*b)
else:
    print(-1)

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

using ll = int64_t;
#define chmax(x, y) x = (x, y)

vector<int> divisor(int x){
    vector<int> res;
    for(int i = 1; (ll)i * i <= x; ++i){
        if(x % i == 0){
            res.push_back(i);
            if(i * i != x)  res.push_back(x / i);
        }
    }
    sort(res.begin(), res.end());
    return res;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int n, m;
    cin >> n >> m;
    vector<int> div = divisor(m);
    int sz = div.size();
    int ans = 1;
    for(int i = 0; i < sz; ++i){
        int foo = m / div[i];
        if(foo >= n)    chmax(ans, div[i]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int		long long
#define mp		make_pair
#define pb		push_back
#define pf		push_front
#define db(x)	{ cerr << #x << " = " << x << endl; }
#define sz(x)	((int)(x).size())
#define w(x)		int x; cin>>x; while(x--)
#define rep(i,a,n)		for (int i=a;i<n;i++)
#define per(i,a,n)		for (int i=n-1;i>=a;i--)

int32_t main(){
	ios::sync_with_stdio(false); cin.tie(0);
	int n; cin>>n;
	if(n%10 == 2 || n%10 == 4 || n%10 == 5 || n%10 == 7 || n%10 == 9) cout<<"hon";
	if(n%10 == 0 || n%10 == 1 || n%10 == 6 || n%10 == 8) cout<<"pon";
	if(n%10 == 3) cout<<"bon";
	return 0;
}

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

typedef long long ll;
const int P = 1000000007;
int mul(int a, int b) { return 1ll * a * b % P; }
int mod(int x) { return x < 0 ? x + P : x; }

const int N = 200001;
int a[N];

int main(void) {
    int n, k; scanf("%d %d", &n, &k);
    int mv = INT_MIN;
    for (int i = 1; i <= n; ++i)
        scanf("%d", &a[i]), mv = max(mv, a[i]);
    sort(a + 1, a + n + 1, [](int u, int v) { return abs(u) > abs(v); });
    
    if ((k & 1) && mv < 0) {
        int ans = 1;
        for (int i = n; i >= n - k + 1; --i)
            ans = mul(ans, mod(a[i]));
        printf("%d\n", ans);
    }
    else {
        int cn = 0, ans = 1;
        for (int i = 1; i <= k; ++i)
            if (a[i] < 0) cn++;
        if (a[k] == 0)
            printf("0\n");
        else {
            if (cn & 1) {
                int r;
                int p1 = k, n1 = k + 1;
                while (p1 >= 1 && a[p1] <= 0) p1--;
                while (n1 <= n && a[n1] > 0) n1++;
                bool f1 = (p1 < 1 || n1 > n);

                int n2 = k, p2 = k + 1;
                while (n2 >= 1 && a[n2] >= 0) n2--;
                while (p2 <= n && a[p2] < 0) p2++;
                bool f2 = (n2 < 1 || p2 > n);
                
                if (f1 && f2)
                    r = 0;
                else if (f1 && !f2)
                    r = 2;
                else if (f2 && !f1)
                    r = 1;
                else {
                    if (abs(1ll * a[n1] * a[n2]) > abs(1ll * a[p1] * a[p2]))
                        r = 1;
                    else
                        r = 2;
                }
                if (r == 1)
                    swap(a[p1], a[n1]);
                if (r == 2)
                    swap(a[p2], a[n2]);
            }
            for (int i = 1; i <= k; ++i)
                ans = mul(ans, mod(a[i]));
            printf("%d\n", ans);
        }
    }


    return 0;
}

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

int main() {
  int n;
  cin >> n;
  vector<int> a(n+1);
  rep(i,n) cin >> a[i];
  a[n] = -1;
  vector<int> b(n);
  rep(i,n) cin >> b[i];
  vector<int> c(n-1);
  rep(i,n-1) cin >> c[i];
  int ans = 0;
  rep(i,n) {
    ans += b[a[i]-1];
    if(a[i]+1 == a[i+1]){
      ans += c[a[i]-1];
    }
  }
  cout << ans << endl;
  return 0;
  
}


Measured memory_bytes: 256
n, k = gets.split.map(&:to_i)
h = gets.split.map(&:to_i)
dp = Array.new(n, Float::INFINITY)
dp[0] = 0
(1...n).each do |i|
  (1..[k, i].min).each do |j|
    cost = dp[i-j] + (h[i] - h[i-j]).abs
    dp[i] = cost if cost < dp[i]
  end
end
puts dp.last


Measured memory_bytes: 11396
#include <bits/stdc++.h>
using namespace std;
template <typename T> bool chmax(T &u, const T z) { if (u < z) {u = z; return true;} else return false; }
template <typename T> bool chmin(T &u, const T z) { if (u > z) {u = z; return true;} else return false; }
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long 
//typedef pair<ll, ll> P;
const ll INF=1LL<<60;
ll gcd(ll x,ll y){return y? gcd(y,x%y) :x;}

int main(){
    string s,t;
    cin>>s>>t;
    vector<int>start(26,-1);
    vector<int>goal(26,-1);
    rep(i,s.size()){
        int a=s[i]-'a';
        int b=t[i]-'a';
        if(start[a]!=-1||goal[b]!=-1){
            if(start[a]!=b||goal[b]!=a){
                cout<<"No"<<endl;
                return 0;
            }
        }else{
            start[a]=b;
            goal[b]=a;
        }
    }
    cout<<"Yes"<<endl;
    return 0;
}

Measured memory_bytes: 3844
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n); i >= 0; i--)
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define ALL(obj) begin(obj), end(obj)
using namespace std;
using ll = long long;

const int INF = 200000000;
const int MOD = 1e9 + 7;

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

    string S, S_inv;
    cin >> S;
    S_inv = S;
    reverse(ALL(S_inv));
    int ans = 0;
    REP(i, (S.size() + 1) / 2) {
        if (S[i] != S_inv[i]) {
            ans++;
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
set<int> s;
int main(){
    int n,x;
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>x;
        s.insert(x);
    }
    if(s.size()==n) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
}

Measured memory_bytes: 9600
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define erep(i,a,b) for(int i=a;i<=(int)(b);++i)
#define per(i,a,b) for(int i=(b);i>(a);--i)
#define eper(i,a,b) for(int i=((int)(a));i>=b;--i)
#define min(a,b) (((a)>(b))?(b):(a))
#define max(a,b) (((a)>(b))?(a):(b))
#define pb push_back
#define mp make_pair
#define INF (1<<28)-1
#define MOD 1000000007
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
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 dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a, b)*b;}
int main(){
	int n,x;
	cin>>n;
	cin>>x;
	int res;
	for(int i=0;i<n;i++){
		int t;
		cin>>t;
		t=abs(t-x);
		if(i!=0){
			res=gcd(res,t);
		}else{
			res=t;
		}
	}
	cout<<res<<endl;
}

Measured memory_bytes: 256
import sys
from bisect import bisect_left
def input(): return sys.stdin.readline().strip()


def main():
    N = int(input())
    A = list(map(int, input().split()))
    A.sort()
    
    """
    もし負の数が偶数個存在すればそれらはすべて正の数にできる。
    もし負の数が奇数個存在すればそれは最終的に１個にできる。
    """

    idx = bisect_left(A, 0)
    if idx % 2 == 0:
        print(sum(A[idx:]) - sum(A[:idx]))
    elif idx < len(A) :
        cand1 = sum(A[idx:]) - sum(A[:idx]) + A[idx - 1] * 2
        cand2 = sum(A[idx:]) - sum(A[:idx]) - A[idx] * 2
        print(max(cand1, cand2))
    else:
        print(-sum(A) + A[-1] * 2)
    


if __name__ == "__main__":
    main()


Measured memory_bytes: 64624
#include <bits/stdc++.h>
#define ll long long int
using namespace std;
int main () {
ios_base::sync_with_stdio(false);
    cin.tie(NULL);
  ll k,a,b;
  cin>>k>>a>>b;
  ll i;ll flag=0;
  for(i=a;i<=b;i++)
  {
  	if(i%k==0)
  	{
	  
  	flag=1;
  	break;
  }
  }
  if(flag==0)
  cout<<"NG"<<endl;
  else
  cout<<"OK"<<endl;
  return 0;
}

  
  
  	


Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
#define si(a) scanf("%d",&a)
#define sll(a) scanf("%lld",&a)
#define sl(a) scanf("%ld",&a)
#define pi(a) printf("%d\n",a)
#define pl(a) printf("%ld\n",a)
#define pll(a) printf("%lld\n",a) 
#define sc(a) scanf("%c",&a)a
#define pc(a) printf("%c",a)
#define ll long long
#define mod 1000000007

#define pb push_back
#define mp make_pair
#define f first
#define s second
#define INF INT_MAX
#define fr(i,a,b) for(int i=a;i<=b;i++)
#define VI vector<int>
#define VL vector<ll>
#define PI pair<int,int>
#define PL pair<ll,ll>
long double PIE=acos(-1);
//////////////////////////////////////////////////////////////
const ll N=1e5+5;
ll Ans=1;
bool done[1000009];
vector < ll > primes;

void FindPrime(ll N)
{
    done[1] = 1;
    for(int i=2;i<=N;i++)
	{
        if(done[i]) continue;
        for(int j=i*2;j<=N;j+=i)
		{
            done[j] = 1;
        }
        primes.push_back(i);
    }
}

ll solve(ll Num)
{
    for(int i=0;i<primes.size();i++)
	{
    	int p=primes[i];
        if(p*p*p > Num) break;
        ll Count = 1;
        while(Num%p == 0)
		{
            Num /= p,Count++;
        }
        Ans *= Count;
    }
    ll sq = (ll)sqrt(Num);
    if(!done[Num]) 
	Ans *= 2;
    else if(sq*sq == Num && !done[sq]) 
	Ans *= 3;
    else if(Num != 1) 
	Ans *= 4;
    return Ans;
}


ll fact[N], invfact[N];



ll pow(ll a, ll b, ll m)
{
	ll ans=1;
	while(b)
	{
		if(b&1)
			ans=(ans*a)%m;
		b/=2;
		a=(a*a)%m;
	}
	return ans;
}

ll modinv(ll k)
{
	return pow(k, mod-2, mod);
}


ll nCr(ll x, ll y)
{
	if(y>x)
		return 0;
	ll num=fact[x];
	num*=invfact[y];
	num%=mod;
	num*=invfact[x-y];
	num%=mod;
	return num;
}

void initinv()
{
	fact[0]=1;
	fr(i,1,N)
	{
		fact[i]=(i*fact[i-1])%mod;
	}
	invfact[N]=modinv(fact[N]);
	for(int i=N-1;i>=1;i--)
	{
		invfact[i]=((i+1)*invfact[i+1])%mod;
	}
}
///////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////
ll dp[100005][103];
ll w[103],v[103];
int main()
{
	int n,W;
	cin>>n>>W;
	fr(i,1,n)
	{
		cin>>w[i]>>v[i];
	}
	fr(i,1,W)
	{
		fr(j,1,n)
		{
			dp[i][j]=dp[i][j-1];
			if(w[j]<=i)
			{
				dp[i][j]=max(dp[i-w[j]][j-1]+v[j],dp[i][j]);
			}
			//cout<<dp[i][j]<<" ";
		}
		//cout<<"\n";
	}
	cout<<dp[W][n];
    return 0;
}





Measured memory_bytes: 83960
#include <iostream>
#include <string>

using namespace std;

int main() {
    int n; cin >> n;
    string s, t; cin >> s >> t;
    string res = "";
    for (auto i = 0; i < n; ++i) {
        res += s[i];
        res += t[i];
    }

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

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

int main() {

    string s;
    cin>>s;
    int flag = 0;
    //cout<<s.length()<<endl;
    for (int i = 0; i < s.length(); i += 2) {
        if (s[i] == 'R' || s[i] == 'U' || s[i] == 'D') {
            continue;
        } else {
            flag = 1;
        }
    }

    for (int i = 1; i < s.length(); i += 2) {
        if (s[i] == 'L' || s[i] == 'U' || s[i] == 'D') {
            continue;
        } else {
            flag = 1;
        }
    }

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


    return 0;
}


Measured memory_bytes: 3616
#include <iostream>
#include <string>

using namespace std;

int sets;
string sentences[500];
int dp[500][1001][1001];

int main(){
    cin >> sets;
    for(int i = 0; i < sets*2; i++){
        cin >> sentences[i];
    }

    for(int i = 0; i < sets*2; i+=2){
        for(int n = 0; n < sentences[i].size(); n++){
            for(int m = 0; m < sentences[i+1].size(); m++){
                if(sentences[i][n] == sentences[i+1][m]){
                    dp[i][n+1][m+1]= dp[i][n][m] + 1;
                }else{
                    dp[i][n+1][m+1] = max(dp[i][n+1][m],dp[i][n][m+1]);
                }
            }
        }
    }

    for(int i = 0; i<sets*2; i+=2){
        cout << dp[i][sentences[i].size()][sentences[i+1].size()] << endl;
    }
}


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

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

Measured memory_bytes: 256
// 基本テンプレート

#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
using namespace std;

#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define int long long int

template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}

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

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
constexpr ll INF = 1001001001001001LL;
constexpr ll MOD = 1000000007LL;

signed main() {
    int A, B, C; cin >> A >> B >> C;
    int ans = 0;
    if(A == C) ans = B;
    if(B == C) ans = A;
    if(A == B) ans = C;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long res = 0;
        for(int i = 1; i <= n; i++) if(String.valueOf(i).length() % 2 == 1) res++;
        System.out.println(res);
    }
}


Measured memory_bytes: 27220
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int N;
  cin>>N;
  int val=N/100;
  if(val==0)cout<<0<<endl;
  else if(N*20/(val*100)==20)cout<<1<<endl;
  else if(N%105==0)cout<<1<<endl;
  else cout<<0<<endl;
}


Measured memory_bytes: 256