akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
        }

        public void Solve(ConsoleInput cin)
        {
            var N = cin.ReadInt;
            var M = cin.ReadInt;
            var Num = new string[N];
            for (var i = 0; i < N; i++)
            {
                Num[i] = "0";
            }

            var ans = "";
            var Selected = new int[N];
            for (var i = 0; i < M; i++)
            {
                var s = cin.ReadInt;
                var c = cin.ReadInt;
                if (N != 1 && s == 1 && c == 0)
                {
                    ans = "-1";
                    break;
                }
                if (Selected[s - 1] == 1 && Num[s - 1].Equals(c.ToString()) == false)
                {
                    ans = "-1";
                    break;
                }
                Selected[s - 1] = 1;
                Num[s - 1] = c.ToString();
            }
            if (!ans.Equals("-1"))
            {
                ans = "";
                if (N!=1 && Num[0].Equals("0")) ans = "1";
                else ans = Num[0];
                for (var i = 1; i < N; i++)
                {
                    ans += Num[i];
                }
            }

            WriteLine(ans);

        }
    }


    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }

        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; i++)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }


        public string ReadLine { get { return _stream.ReadLine(); } }
        public int ReadInt { get { return int.Parse(Read); } }
        public long ReadLong { get { return long.Parse(Read); } }
        public double ReadDouble { get { return double.Parse(Read); } }
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
    }

}

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

int main(){
  long long K , N ;
  cin >> K >> N ;
  long long x = 0 ;
  long long y = 0 ;
  long long A[2000000] ;
  for(long long i=0;i<N;i++){
    cin >> A[i] ;
  }
  for(long long i=0;i<N;i++){
    if(A[i+1]-A[i]>x) x = (A[i+1]-A[i]);
  }
  y = K-A[N-1]+A[0] ;
  
  cout << K-max(x,y) << endl;
  
}


Measured memory_bytes: 3456
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a=new int[n];
		long[] g=new long[n+1];
      	int al=0;
		for(int i=0;i<n;i++){
			a[i]= sc.nextInt();
          	al+=g[a[i]];
          	g[a[i]]++;
		}
      	long all=0;
      	for(int i=0;i<n+1;i++){
             all+=g[i]*(g[i]-1)/2;
          //System.out.println(x);
        }  
      	//System.out.println(all);
		//System.out.println(al);

		for(int i=0;i<n;i++){
			System.out.println(all-g[a[i]]+1);
		}
		
	}
}


Measured memory_bytes: 105428
#include<bits/stdc++.h>
int main(){
  std::string s[3];
  long long k,a[3]={};
  std::cin>>s[0]>>k;
  for(size_t i=0;i<2;++i) s[i+1]=s[i]+s[0];
  for(size_t i=0;i<3;++i) for(size_t j=1;j<s[i].length();++j) if(s[i][j]==s[i][j-1]) ++a[i],++j;
  std::cout<<(k&1?a[0]:a[1])+(k-1)/2*(a[2]-a[0])<<std::endl;
}


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

using namespace std;

int main(){
	long long int x;
	cin>>x;
	
	long long int mid = sqrt(x);
	for(long long int i=mid; i>0; i--){
		if(x%i == 0){
			mid=i;
			break;
		}
	}
	cout<<mid + (x/mid) -2;	
	return 0;
}

Measured memory_bytes: 256
import math
N,A,B = map(int,input().split())
H = [int(input()) for i in range(N)]

C=A-B
sum,d=0,0
high = math.ceil(max(H)/B)
low = 0
while high > low:
    sum = 0
    mid = (high + low) //2
    for i in range(N):
        if H[i]-B*mid > 0:
            sum += math.ceil((H[i]-B*mid)/C)
    if sum <= mid:
        high = mid
    else:
        low = mid + 1

print(low)

Measured memory_bytes: 7088
import sys

num,total = map(int,input().split())

if(total%10000 == 0 and num == total/10000):
    print(num,0,0)
    sys.exit()
if(total%5000 == 0 and num == total/5000):
    print(0,num,0)
    sys.exit()
if(total%1000 == 0 and num == total/1000):
    print(0,0,num)
    sys.exit()

for i in range(total//10000+1):
    for j in range(min([num - i,total//5000+1])):
        if(10000*i + 5000*j + 1000*(num-i-j) == total):
            print(i,j,(num-i-j))
            sys.exit()
print("-1 -1 -1")

Measured memory_bytes: 3064
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <functional>
#include <utility>
#include <tuple>
#include <cctype>
#include <bitset>
#include <complex>
#include <cmath>
#include <array>
#include <numeric>
using namespace std;
#define INF 0x3f3f3f3f
#define INFLL 0x3f3f3f3f3f3f3f3fLL
//#define MOD 998244353
#define MOD 1000000007
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pint;
typedef pair<ll,ll> pll;
typedef tuple<int,int,int> tint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<ull> vull;
typedef vector<pint> vpint;
typedef vector<tint> vtint;
typedef vector<vint> vvint;
int dx[8]={0,0,-1,1,1,1,-1,-1};
int dy[8]={-1,1,0,0,1,-1,1,-1};
const int SIZE=10050;
//↑templete
signed main(){

    string S;
    cin>>S;
    if(S.length()%2){
        cout<<"No"<<endl;
        return 0;
    }
    bool flag=0;
    for(int i=0;i<S.length();i++){
        if(i%2 && S[i]!='i')
            flag=1;
        if(i%2==0 && S[i]!='h')
            flag=1;
    }
    if(flag)
        cout<<"No"<<endl;
    else
        cout<<"Yes"<<endl;
	
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0; i<(int)(n); i++)
#define all(vec) vec.begin(),vec.end()
#define MOD 1000000007
#define int long long

signed main(){
    int n;cin>>n;
    if(n<1000)cout<<"ABC"<<endl;
    else cout<<"ABD"<<endl;
}

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

int main(){
	long long int k[21][101];
	int n;
	int num[100];
	long long int sum=0;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>num[i];
	}
	memset(k,0,sizeof(k));
	k[num[0]][0]=1;
	for(int i=1;i<n-1;i++){
		for(int j=0;j<=20;j++){
			if(j+num[i]<=20){
				k[j+num[i]][i] += k[j][i-1];
			}
			if(j-num[i]>=0){
				k[j-num[i]][i] += k[j][i-1];
			}
		}
	}
	sum += k[num[n-1]][n-2];
	cout<<sum<<endl;
	return 0;
}

Measured memory_bytes: 1180
import java.io.InputStreamReader;
import java.io.IOException;
import java.lang.reflect.Method;
import java.util.*;
import java.io.BufferedReader;
import java.io.PrintWriter;
import java.io.InputStream;
import static java.lang.Math.*;

public class Main {

    public static void main(String[] args) {
        final String[] tasks = new String[]{"D","C","B","A"};
        for(final String task:tasks) {
            try {
                Class ca = Main.class.getClassLoader().loadClass(task);
                if (ca.getField("on").getInt(null) == 1) {
                    Object aTask = ca.newInstance();
                    Method m = ca.getMethod("S", null);
                    m.invoke(aTask, null);
                }
            } catch (Exception ex) { }
        }
    }

}

class A {
    public static int on = 1;

    public void run(){
        int n = ni();
        int[] a = new int[n];
        for(int i=0;i<n;i++){
            a[i] = ni();
        }
        Arrays.sort(a);
        int s1 = 0;
        int s2 = 0;
        boolean al = true;
        for(int i=n-1;i>=0;i--){
            if(al) {
                s1 += a[i];
            }else{
                s2 += a[i];
            }
            al = !al;
        }
        pl(s1-s2);




    }
    private InputReader in =  new InputReader(System.in);
    private PrintWriter out = new PrintWriter(System.out);
    public void S(){run();out.close(); }
    public int ni(){return Integer.parseInt(in.ns());}
    public long nl(){return Long.parseLong(in.ns());}
    public String ns(){return in.ns();}
    public void p(Object obj){out.print(obj);}
    public void ps(Object obj){p(obj);p(" ");}
    public void pl(Object obj){out.println(obj);}
    public int gcd(int a,int b){ while( b != 0 ) { int t = a % b;a = b;b = t; } return a; }
}

class B {
    public static int on = 0;

    public void run(){

    }
}

class InputReader {
    private BufferedReader reader;
    private StringTokenizer tokenizer;

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

    public String ns() {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

}





Measured memory_bytes: 20692
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>

#define ll long long
#define ull unsigned long long
#define ui unsigned int

using namespace std;

const ll mod = 1e9 + 7;
int N;

ll binary_pow[200005] = { 1, };
ll input[200005];

int main()
{
	scanf("%d", &N);
	for (int i = 1; i <= N; ++i) binary_pow[i] = (2LL * binary_pow[i - 1]) % mod;

	for (int i = 0; i < N; ++i) scanf("%lld", &input[i]);
	
	sort(input, input + N);
	ll ans = 0;

	for (int i = 0; i < N - 1; ++i)
	{
		ll a = (input[i] * binary_pow[N]) % mod;
		a = (a * binary_pow[i]) % mod;
		
		ll b = ((N - i - 1) * binary_pow[N - i - 2]) % mod;
		b = (b + binary_pow[N - i - 1]) % mod;

		a = (a * b) % mod;
		ans = (ans + a) % mod;
	}

	ll a = (input[N - 1] * binary_pow[N]) % mod;
	a = (a * binary_pow[N - 1]) % mod;

	ans = (ans + a) % mod;

	printf("%lld\n", ans);

	return 0;
}

Measured memory_bytes: 3328
#include<iostream>
#include<algorithm>
#include<utility>
#include<cmath>
#include<string>

using namespace std;

char map[101][101];
int a,b;

void dfs(int x,int y,char s){
  if(x>=a||x<0){
    return;
  }
  else if(y>=b||y<0){
    return;
  }

  if(map[x][y]== s){
    map[x][y]='x';
  }
  else{
    return;
  }

  dfs(x+1,y,s);
  dfs(x-1,y,s);
  dfs(x,y+1,s);
  dfs(x,y-1,s);
}

int main(){
  
  int ans;
  
  while(cin>>a>>b){
  if(a==0&&b==0){
    break;
  }
  ans=0;
  	
  for(int i=0;i<a;i++){
    for(int j=0;j<b;j++){
      cin >> map[i][j];
    }
  }

  for(int i=0;i<a;i++){
    for(int j=0;j<b;j++){
      if(map[i][j]!='x'){
	dfs(i,j,map[i][j]);
	ans+=1;
      }
      
    }
  }
  cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 3420
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws Exception{
		BufferedReader keyIn = new BufferedReader(new InputStreamReader(System.in));
		String s = keyIn.readLine();
		String[] array = s.split("");
		int count = 0;
		if(array[0].equals("1")) count++;
		if(array[1].equals("1")) count++;
		if(array[2].equals("1")) count++;
		
		System.out.println(count);

	}

}

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


public class Test
{
	public static void Main( )
	{
		var n = int.Parse( Console.ReadLine().Trim() );
		var A = Console.ReadLine().Trim().Split().Select( x => int.Parse( x ) ).ToArray();
		var q = int.Parse( Console.ReadLine().Trim() );
		var M = Console.ReadLine().Trim().Split().Select( x => int.Parse( x ) );
		

		foreach( int i in M ) {
			if( solve( A, 0, i ) ) {
				Console.WriteLine( "yes" );
			} else {
				Console.WriteLine( "no" );
			}
		}
		
		return;
	}
	public static bool solve( int[] A, int p, int t )
	{
		if( t == 0 ) {
			return true;
		}

		if( p+1 <= A.Length ) {
			return solve( A, p+1, t-A[p] ) || solve( A, p+1, t );
		} else {
			return false;
		}
	}
}


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

#define ll long long
#define dd double

using namespace std;



int main(){
    int N;
    cin >> N;
    vector<int> x(N);
    vector<int> y(N);
    dd ans = 0;
    for(int i = 0; i < N ;i++){
        cin >> x[i] >> y[i];
        for(int j = 0; j < i; j++){
            ans += (sqrt(pow((x[i]-x[j]),2) + pow((y[i]-y[j]),2)) * 2)/ N;
        }
    }

    cout << fixed << setprecision(20) << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
    int n,l,m=0,k=0;
    cin>>n;
    m=n;
    while(n--){
        cin>>l;
        if(l<=m)
            k++;
        if(l<m)
            m=l;
    }
    cout<<k<<endl;
    return 0;
}


Measured memory_bytes: 256
h,w = map(int,input().split())
u = [list(input()) for _ in range(h)]

from collections import deque
q = deque([(0,0)])
dist = [[-1]*w for _ in range(h)]
dist[0][0]=0

while q:
    (i,j) = q.popleft()
    if 0<=i-1<h:
        if u[i-1][j]=='.' and dist[i-1][j]==-1:
            q.append((i-1,j))
            dist[i-1][j]=dist[i][j]+1
    if 0<=i+1<h:
        if u[i+1][j]=='.' and dist[i+1][j]==-1:
            q.append((i+1,j))
            dist[i+1][j]=dist[i][j]+1
    if 0<=j-1<w:
        if u[i][j-1]=='.' and dist[i][j-1]==-1:
            q.append((i,j-1))
            dist[i][j-1]=dist[i][j]+1
    if 0<=j+1<w:
        if u[i][j+1]=='.' and dist[i][j+1]==-1:
            q.append((i,j+1))
            dist[i][j+1]=dist[i][j]+1

count=0
for i in range(h):
    for j in range(w):
        if u[i][j]=='.':
            count+=1
if dist[h-1][w-1]==-1:
    print(-1)
else:
    print(count-dist[h-1][w-1]-1)

Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define P pair<int,int>
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<n;i++)
#define all(v) v.begin(),v.end()
#define pb push_back
template<class T>void chmax(T &a,T b){if(a<b)a=b;}
template<class T>void chmin(T &a,T b){if(a>b)a=b;}
constexpr int INF=1000000000000000000;
constexpr int mod=1000000007;
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
int gcd(int a,int b){
    if(b==0)return a;
    return gcd(b,a%b);
}
int lcm(int a,int b){
    return a/gcd(a,b)*b;
}
bool prime(int a){
    if(a==1)return false;
    for(int i=2;i*i<=a;i++){
        if(a%i==0)return false;
    }
    return true;
}
vector<int>kaijo;
void init_fact(int n){
    kaijo.resize(n+1);
    kaijo[0]=1;
    for(int i=1;i<=n;i++){
        kaijo[i]=kaijo[i-1]*i;
        kaijo[i]%=mod;
    }
}
int modpow(int a,int b){
    if(b==0)return 1;
    if(b%2)return modpow(a,b-1)*a%mod;
    int memo=modpow(a,b/2);
    return memo*memo%mod;
}
int comb(int a,int b){
    //if(!kaijo[0])init_fact(2000010);
    return kaijo[a]*modpow(kaijo[a-b],mod-2)%mod*modpow(kaijo[b],mod-2)%mod;
}
int inv(int x){
    x=modpow(x,mod-2);
    return x;
}
bool kosa(double ax,double ay,double bx,double by,double cx,double cy,double dx,double dy){
    double ta=(cx-dx)*(ay-cy)+(cy-dy)*(cx-ax);
    double tb=(cx-dx)*(by-cy)+(cy-dy)*(cx-bx);
    double tc=(ax-bx)*(cy-ay)+(ay-by)*(ax-cx);
    double td=(ax-bx)*(dy-ay)+(ay-by)*(ax-dx);
    return tc*td<0&&ta*tb<0;
}
int n,m,k;
signed main(){
    cin>>n>>m>>k;
    init_fact(400000);
    int hoge=comb(n*m-2,k-2);
    int ans=0;
    int res=0;
    rep(i,n){
        res+=i*(n-i)*m%mod*m%mod;
        res%=mod;
    }
    ans+=res;
    swap(n,m);
    res=0;
    rep(i,n){
        res+=i*(n-i)*m%mod*m%mod;
        res%=mod;
    }
    ans+=res;
    ans%=mod;
    ans*=hoge;
    ans%=mod;
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3328
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast") 
#define int long long
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back 
#define eb emplace_back
#define fn for(int i =0 ;i <n;i++)
#define fn1 for( int i =1;i<=n;i++)
#define fm for(int j =0 ;j <m;j++)
#define fm1 for(int j =1;j<=m;j++)
#define fi first
#define se second
#define endl '\n'
# define PI  3.14159265358979323846
#define MOD 1000000007
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
const int N = 1e2+5;
const int INF = 1e18L;
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}
int ar[N][N];
int dp[N];
// bc N nhi dekha :/
signed main(){
	// #ifndef ONLINE_JUDGE
	// freopen("input.txt","r",stdin);
	// freopen("output.txt","w",stdout);
	// #endif
	IOS;
	int T=1;
	// cin >> T;
	while(T--){
		int n , m ,x;
		cin >> n >> m >> x;
		int ans = INF;
		m++;
		fn{
			fm{
				cin >> ar[i][j];
			}
		}
		for(int mask =0 ; mask < (1ll << n ) ; mask++){
			int cur= 0 ;
			vector<int>cost(m-1,0);
			for(int i =0 ;i < n ;i++){
				if(((mask>>i)&1)){
					cur+=ar[i][0];
					for(int j =1 ;j < m;j++){
						cost[j-1]+=ar[i][j];
					}
				}
			}
			int f =1;
			for(int j =1;j<m;j++){
				if(cost[j-1]<x)f =0;
			}
			if(f)ans= min(ans,cur);
		}
		if(ans==INF)ans=-1;
		cout << ans <<'\n';
	
	}
	return 0;
}

Measured memory_bytes: 3628
import java.util.*;

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

        String S  = sc.nextLine();
        String T = sc.nextLine();

        HashMap<Character, Character> stmap = new HashMap<>();
        HashMap<Character, Character> tsmap = new HashMap<>();

        for (int i = 0; i < S.length(); i++) {
            if (stmap.containsKey(S.charAt(i)) && stmap.get(S.charAt(i)) != T.charAt(i)) {
                System.out.println("No");
                return;
            }

            if (tsmap.containsKey(T.charAt(i)) && tsmap.get(T.charAt(i)) != S.charAt(i)) {
                System.out.println("No");
                return;
            }

            stmap.put(S.charAt(i), T.charAt(i));
            tsmap.put(T.charAt(i), S.charAt(i));
        }

        System.out.println("Yes");
    }
}

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

int main(){
    int n,t; cin >> n >> t;
    vector<tuple<int,int>> arr;
    for(int i = 0; i < n; ++i){
        int c,d;
        cin >> c >> d;
        arr.push_back(tie(c,d));
        sort(arr.begin(),arr.end());
    }

    for(int i = 0; i <= n; i++){
        if(i == n){
            cout << "TLE" << endl;
            break;
        }
        if( get<1>(arr[i]) <= t){
            cout << get<0>(arr[i]) << endl;
            break;
        }
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <cstdio>

#define PI 3.141592653589793
#define RAD(d) (d * PI / 180)

using namespace std;

class People{
private:
	int angle;
	double x, y;

public:
	People(){
		angle = 90;
		x = y = 0;
	}
	void move(int distance, int relativeAngle){
		x += distance * cos(RAD(angle));
		y += distance * sin(RAD(angle));
		angle -= relativeAngle;
	}
	double getX(){ return x; }
	double getY(){ return y; } 
};

int main(){
	People me;
	for(int distance, relativeAngle; ~scanf("%d,%d", &distance, &relativeAngle), distance;)
		me.move(distance, relativeAngle);
	cout << (int)me.getX() << endl << (int)me.getY() << endl;

	return 0;
}

Measured memory_bytes: 1212
n, m = map(int, input().split())
lst = []
for i in range(n):
    a, b = map(int, input().split())
    lst.append([a, b])
lst.sort()
get = 0
money = 0
for i in lst:
    if get + i[1] <= m:
        get += i[1]
        money += i[0]*i[1]
    else:
        money += (m-get)*i[0]
        break
print(money)

Measured memory_bytes: 20048
using System;

namespace ABC064B
{
  class Program
  {
    static void Main(string[] args)
    {
      int N = int.Parse(Console.ReadLine());
      string[] bufs = Console.ReadLine().Split(' ');

      int max = -1;
      int min = 0x30303030;

      for (int i = 0; i < N; i++) {
        int pos = int.Parse(bufs[i]);
        if (max < pos) {
          max = pos;
        }
        if (min > pos) {
          min = pos;
        }
      }


      Console.WriteLine(max - min);
    }
  }
}


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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N, Q;
  cin >> N >> Q;
  vector<vector<int>> G(N);
  for (int i = 0; i < N - 1; i++) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    G[a].emplace_back(b);
    G[b].emplace_back(a);
  }
  vector<int> res(N, 0);
  for (int i = 0; i < Q; i++) {
    int p, x;
    cin >> p >> x;
    p--;
    res[p] += x;
  }
  vector<bool> used(N, false);
  used[0] = true;
  queue<int> que;
  que.push(0);
  while (!que.empty()) {
    int u = que.front();
    que.pop();
    for (int v : G[u]) {
      if (used[v]) continue;
      res[v] += res[u];
      que.push(v);
      used[v] = true;
    }
  }
  for (auto &v : res) {
    cout << v << (&v == &res.back() ? '\n' : ' ');
  }
  return 0;
}


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

// #define int long long
#define rep(i, n) for (long long i = (long long)(0); i < (long long)(n); ++i)
#define reps(i, n) for (long long i = (long long)(1); i <= (long long)(n); ++i)
#define rrep(i, n) for (long long i = ((long long)(n)-1); i >= 0; i--)
#define rreps(i, n) for (long long i = ((long long)(n)); i > 0; i--)
#define irep(i, m, n) for (long long i = (long long)(m); i < (long long)(n); ++i)
#define ireps(i, m, n) for (long long i = (long long)(m); i <= (long long)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) long long(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

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; }

const ll INF = 1e9;
const ll MOD = 1e9+7;
const ll LINF = 1e18;

// 参考: https://drken1215.hatenablog.com/entry/2019/01/14/033200

ll n,m; 
vll a,b;

ll solve(){
  ll res=1;
  ll biggerX_a=0, biggerX_b=0; // a,b で x より大きいのが何個あるか
  for(ll x=n*m; x>=1; --x){
    if(a[biggerX_a]>x) return 0;
    if(b[biggerX_b]>x) return 0;
    
    ll tmp=1;
    if(a[biggerX_a]==x && b[biggerX_b]==x){
      // 行、列の両方にxが登場する
      tmp=1;
      ++biggerX_a, ++biggerX_b;
    }else if(a[biggerX_a]==x){
      // 行側にのみxが登場する
      // xより大きい値が入ることが確定している列のみ選択可能
      tmp=biggerX_b;
      ++biggerX_a;
    }else if(b[biggerX_b]==x){
      // 列側にのみxが登場する
      tmp=biggerX_a;
      ++biggerX_b;
    }else{
      // 行、列の両方にxが登場しない
      // xより大きい値が入ることが確定している行列内のいずれかに入る
      // このうち、n*m-x個はxより大きい値で埋められているので除外する必要がある
      tmp=biggerX_a*biggerX_b-(n*m-x);
      if(tmp<=0) return 0;
    }
    res=(res*tmp)%MOD;
  }
  return res;
}

signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  
  cin>>n>>m;
  a.resize(n+1), b.resize(m+1);
  rep(i,n) cin>>a[i];
  rep(i,m) cin>>b[i];
  sort(a.rbegin(),a.rend());
  sort(b.rbegin(),b.rend());
  cout<<solve()<<endl;
  
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    string str;
    cin>>str;
    ll n=str.length(),i;
    for(i=0;i<n;i++)
        cout<<"x";
    cout<<endl;
    return 0;
}

Measured memory_bytes: 256
use std::collections::HashSet;
use std::io::*;
use std::str::*;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let s = stdin
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect::<String>();
    s.parse::<T>().ok().unwrap()
}

fn string() -> String { read() }

fn usize() -> usize {
    read()
}

fn main() {
    let mut results: HashSet<String> = HashSet::new();

    let n = usize();
    let s: Vec<char> = string().chars().collect();

    let mut s1_set: HashSet<String> = HashSet::new();
    let mut s12_set: HashSet<String> = HashSet::new();
    for s1i in 0..n {
        let mut buf1: Vec<char> = Vec::new();
        buf1.push(s[s1i]);
        let s1: String = buf1.clone().into_iter().collect();
        if s1_set.contains(&s1) {
            continue;
        }
        s1_set.insert(s1);
        for s2i in s1i + 1..n {
            let mut buf2 = buf1.clone();
            buf2.push(s[s2i]);
            let s12: String = buf2.clone().into_iter().collect();
            if s12_set.contains(&s12) {
                continue;
            }
            s12_set.insert(s12);
            for s3i in s2i + 1..n {
                let mut buf3 = buf2.clone();
                buf3.push(s[s3i]);
                results.insert(buf3.into_iter().collect());
            }
        }
    }
    println!("{}", results.len());
}


Measured memory_bytes: 4352
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <math.h>
#include <sstream>

using namespace std;

int main()
{
  int N;
  cin >> N;
  int sum = 0;
  for (int i = 0; i < N; ++i) {
    int x;
    cin >> x;
    sum += x;
  }
  cout << sum - N << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char const *argv[])
{
	long long a,b,n;
	cin >> n >> a >> b;
	long long num = n / (a+b);
	if (n % (a+b) == 0)
		cout << num*a;
	else
		cout << num*a + (n%(a+b) <= a? n%(a+b): a );
	cout << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int N,a[3][3],b[10];
    bool appear[3][3];
    for(int i = 0; i < 3; i++)
        for(int j = 0; j < 3; j++)
            cin >> a[i][j];
    cin >> N;
    for(int i = 0; i < N; i++)
        cin >> b[i];
    for(int i = 0; i < 3; i++){
        for(int j = 0; j < 3; j++){
            appear[i][j] = false;
            for(int k = 0; k < N; k++){
                if(a[i][j] == b[k])
                    appear[i][j] = true;
            }
        }
    }
    string ans = "No";
    for(int i = 0; i < 3; i++){
        if(appear[i][0] and appear[i][1] and appear[i][2])
            ans = "Yes";
    }
    for(int i = 0; i < 3; i++){
        if(appear[0][i] and appear[1][i] and appear[2][i])
            ans = "Yes";
    }
    if(appear[0][0] and appear[1][1] and appear[2][2])
        ans = "Yes";
    if(appear[0][2] and appear[1][1] and appear[2][0])
        ans = "Yes";
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define ull unsigned long long
#define vi vector<ll>
#define vvi vector<vi>
#define BITLE(n) (1LL<<(n))
#define BITCNT(n) (__builtin_popcountll(n))
#define SUBS(s,f,t) ((s).substr((f)-1,(t)-(f)+1))
#define ALL(a) (a).begin(),(a).end()
using namespace std;
struct Grid{ll x,y,t;};
struct Edge{ll to,cost;};
struct Graph{vector<vector<Edge>>E;int V;
  const ll Inf = llINF;const int MAX_V=201010;vector<ll>d;
  Graph(int n):E(n){d.resize(MAX_V);E.resize(n);V=n;}
  void init(){for(int i=0;i<MAX_V;i++)d[i]=Inf;}
  void add_edge(ll from,ll to,ll cost){E[from].pb({to,cost});}
};

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll q;cin>>q;
  for(int i=0;i<q;i++){
    ll ans=0;
    ll a,b,c,d;cin>>a>>b>>c>>d;
    for(int j=a;j<=c;j++)
      for(int k=b;k<=d;k++)
	ans+=(j%2==0||k%2==1);
    cout<<ans<<endl;
  }
  return 0;
}



Measured memory_bytes: 3184
def main():
    import sys
    input = sys.stdin.readline
    
    N,H = map(int,input().split())
    AB = [list(map(int,input().split())) for i in range(N)]
    
    AB = sorted(AB,key=lambda a:a[1])[::-1]
    AB = sorted(AB,key=lambda a:a[0])[::-1]
    master = AB[0]
    throw1 = []
    throw2 = []
    for i in range(1,N):
        if AB[i][1] >= master[1]:
            throw1.append(AB[i][1])
        elif AB[i][1] > master[0]:
            throw2.append(AB[i][1])
    throw1 = sorted(throw1)[::-1]
    throw2 = sorted(throw2)[::-1]
    
    throw1Sum = sum(throw1)
    throw2Sum = sum(throw2)
    tmpH = H
    ans = 0
    
    if throw1Sum < H:
        ans += len(throw1)
        tmpH -= throw1Sum
        if throw2Sum+master[1] < H:
            ans += len(throw2)
            tmpH -= throw2Sum
            ans += max(1, -(-(tmpH-master[1])//master[0])+1)
        else:
            throw2.append(master[1])
            throw2 = sorted(throw2)[::-1]
            i = 0
            while tmpH > 0:
                ans += 1
                tmpH -= throw2[i]
                i +=1
    else:
        i = 0
        while tmpH > 0:
            ans += 1
            tmpH -= throw1[i]
            i += 1
    print(ans)

main()

Measured memory_bytes: 73948
a, b, c, x = map(int, [input() for z in range(4)])
 
ans = 0
 
for i in range(a+1):
  for j in range(b+1):
    for k in range(c+1):
      if i*500 + j*100 + k*50 == x:
        ans += 1
print(ans)

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

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

  string s;
  cin >> s;
  if(s.size() == 2) {
   cout << s; 
  }else{
   cout << s[2] << s[1] << s[0]; 
  }
  cout << endl;
}


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

#define rep(i,n) for (int i=0; i<(n); i++)
using namespace std;
using ll = long long;

ll gcd(int a, int b) {
  if(a < b) return gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}

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

    ll sum = 0;

    for (int i = 1; i <= N; i++) {
        for (int j = 1; j <= N; j++) {
            for (int k = 1; k <= N; k++) {
                sum += gcd(gcd(i, j), k);
            }
        }
    }
    
    cout << sum << endl;
}


Measured memory_bytes: 3636
n,m = input().split()
n = int(n)
m = int(m)
arr = list(map(int,input().split()))
minn = sum(arr)*(1/(4*m))
t = 0
for i in arr:
  if i >= minn:
    t += 1
#print(t)
if t >= m:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 9092
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>

using namespace std;

int main(){

	char buf[300];
	stack<char> S;
	bool Broken;

	while(true){
		fgets(buf,300,stdin);
		if(buf[0] == '.' && buf[1] == '\n')break;

		Broken = false;

		for(int i = 0; buf[i] != '\0' && buf[i] != '\n'; i++){
			if(buf[i] == '('){
				S.push('(');
			}else if(buf[i] == '['){
				S.push('[');
			}else if(buf[i] == ')'){
				if(S.empty() == true || S.top() != '('){
					Broken = true;
					break;
				}else{
					S.pop();
				}
			}else if(buf[i] == ']'){
				if(S.empty() == true || S.top() != '['){
					Broken = true;
					break;
				}else{
					S.pop();
				}
			}
		}

		if(!S.empty()){
			Broken = true;
			while(!S.empty())S.pop();
		}

		if(!Broken)printf("yes\n");
		else{
			printf("no\n");
		}
	}

	return 0;
}

Measured memory_bytes: 2436
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define endl        '\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000001
#define r(i,a,b)    for(i=a;i<b;i++)
#define ra(i,a,b)   for(i=a;i<=b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define ss          set<ll int>
using namespace std;
 
#define N 1000000
#define M 100000000

struct unit {
  ll int a[N];  
};

ll fact (ll int x)
{if(x==1 || x==0)return 1;
else return x*fact(x-1);}

ll power(ll int x,ll int n)
{if(n==0)return 1;
else if(n%2 == 0)return power(x*x,n/2);
else return x*power(x*x,(n-1)/2);}

bool cmp (const pii&a,const pii&b)
{ return((a.F-a.S) > (b.F-b.S));
/*if(a.S<=b.S){if(a.S==b.S)return a.F<b.F;else return a.S<b.S;}
else return a.S<b.S;*/}

void solve()
{
    ll i,j,k,l,m,n,a=0,b=0;
    cin>>k>>n;
    if(n==0)
      cout<<k;
    else
    {
      vi v;
      map<ll int,ll int> p;
      r(i,0,n)
      {
        cin>>l;
        v.pb(l);
        p[l]=1;
      }
      a=0;
      while(1)
      {
        if(p[k-a]!=1)
        {
          cout<<k-a;
          return;
        }
        else
          if(p[k+a]!=1)
          {
            cout<<k+a;
            return;
          }
        a++;
      }
    }
    
}


int main()
{
    cin.tie(0), cin.sync_with_stdio(0), cout.tie(0), cout.sync_with_stdio(0);
    ll t=1;
    //cin>>t;
    while(t--)
    {
        solve();
    }
    
}
//pr12


Measured memory_bytes: 3592
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <string>
#include <stdlib.h>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <climits>
#include <iomanip>
#include <deque>
#include <limits>
#include <map>
#include <set>
#include <functional>

using namespace std;

int main()
{
  int64_t A;
  long double B;

  cin >> A >> B;

  cout << static_cast<int64_t>(A * B) << endl;
  return 0;
}


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

using namespace std;

int main(void)
{
	string str;
	cin >> str;
	int strlen = str.length();

	for (int i = strlen - 2; i > 0; --i)
	{
		if (i % 2 == 0) continue;
		int h = i / 2;
		string sub1 = str.substr(0,h+1);
		string sub2 = str.substr(h + 1, i-h);
		if (sub1.compare(sub2) == 0)
		{
			cout << i + 1 << endl;;
			break;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string>
#include<stdlib.h>
#include<math.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<numeric>
#include<string.h>
#include<map>
#include<queue>

using namespace std;

typedef pair<int,int> pii;

#define rep(i,j) for(int i=0;i<(j);i++)
#define reps(i,j,k) for(int i=j;i<=k;i++)
#define in(i,j,k) ((i)>=(j)&&(i)<=(k))


int main(){
	double x,y,a,b;
	int k=90,dr,dk;
	x=y=0;
	for(;;){
		scanf("%d,%d",&dr,&dk);
		if(dr==0&&dk==0)break;
		x+=dr*cos(M_PI*k/180.0);
		y+=dr*sin(M_PI*k/180.0);
		k-=dk;
	}
	modf(x,&a);
	modf(y,&b);
	printf("%d\n%d\n",(int)a,(int)b);
	return 0;
}

Measured memory_bytes: 1200
//https://onlinejudge.u-aizu.ac.jp/problems/ALDS1_9_C
//p243.cpp

#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define MAX 2000000
#define INFTY (1<<30)

int H, A[MAX+1];

void maxHeapify(int i){
	int l, r, largest;
	l = 2 * i;
	r = 2 * i + 1;

	//左の子、自分、右の子で値が最大のノードを選ぶ
	if ( l <= H && A[l] > A[i] ) largest = l;
	else largest = i;
	if ( r <= H && A[r] > A[largest] ) largest = r;

	if ( largest != i ){
		swap(A[i], A[largest]);
		maxHeapify(largest);
	}
}

int extract(){
	int maxv;
	if ( H < 1) return -INFTY;
	maxv = A[1];
	A[1] = A[H--];
	maxHeapify(1);
	return maxv;
}

void increaseKey(int i, int key){
	if ( key < A[i] ) return;
	A[i] = key;
	while ( i > 1 && A[i/2] < A[i] ) {
		swap(A[i], A[i/2]);
		i = i / 2;
	}
}

void insert(int key){
	H++;
	A[H] = -INFTY;
	increaseKey(H, key);
}

int main(){
	int key;
	char com[10];

	while ( 1 ){
		scanf("%s", com);
		if ( com[0] == 'e' && com[1] == 'n' ) break;
		if ( com[0] == 'i' ){
			scanf("%d", &key);
			insert(key);
		}else{
			printf("%d\n", extract());
		}
	}

	return 0;
}




Measured memory_bytes: 6520
#include <stdio.h>
#define pi 3.141592653589793
   int main(void){

double r,S,L;

    scanf("%lf",&r);
    if(0<r&&r<10000){

    S=pi*r*r;
    L=2*pi*r;

    printf("%f %f",S,L);
    }
    return 0;
}



Measured memory_bytes: 2044
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>


using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e16;
const ll MOD = 1e9 + 7;

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




int main() {
    int n;
    
    while(cin >> n, n != 0){
        vector<int> w(n);
        REP(i, n){
            cin >> w[i];
        }
        
        bool dp[305][305] = {};
        REP(i, n - 1){
            if(abs(w[i] - w[i + 1]) <= 1){
                dp[i][i + 1] = true;
            }
        }
        
        for(int len = 3; len <= n; len++){
            for(int l = 0; l < n; l++){
                int r = l + len - 1;
                if(r >= n)continue;

                for(int c = l + 1; c < r - 1; c++){
                    if(dp[l][c] && dp[c + 1][r]){
                        dp[l][r] = true;
                    }
                }
                
                if(dp[l + 1][r - 1] && abs(w[l] - w[r]) <= 1){
                    dp[l][r] = true;
                }
            }
        }
        
        int dp2[305] = {};
        for(int r = 1; r < n; r++){
            dp2[r] = max(dp2[r], dp2[r - 1]);
            REP(l, r){
                if(dp[l][r]){
                    if(l == 0){
                        dp2[r] = max(dp2[r], r - l + 1);
                    }
                    else{
                        dp2[r] = max(dp2[r], dp2[l - 1] + r - l + 1);
                    }
                }
            }
        }
        cout << dp2[n - 1] << endl;
    }
}


Measured memory_bytes: 3176
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,sqrt,factorial,hypot,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from fractions import gcd
from random import randint
def ceil(a,b): return (a+b-1)//b
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    N = I()
    A = Counter(LI())
    ok = True
    if(N%3==0):
        B = []
        for a,c in A.items():
            if(c%(N//3)!=0):
                print("No")
                return 
                break
            for _ in range(c//(N//3)):
                B.append(a)
        if((B[0]^B[1]^B[2]) != 0):
            ok = False
    else:
        ok = len(A)==1
        
    if(ok):
        print("Yes")
    else:
        print("No")
if __name__ == '__main__':
    main()

Measured memory_bytes: 82668
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, from, to) for (int i = from; i < (to); ++i)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define pb push_back
using ll = long long;
using vin=vector<int>;
using vvin=vector<vin>;
using vll=vector<ll>;
using vvll=vector<vll>;
using vst=vector<string>;
using P = pair<ll,ll>;
const int inf=1e9+7;
const ll INF=9e18;
template <typename T> bool chmin(T &a, const T& b){if(a > b){a = b;return true;}return false;}
template <typename T> bool chmax(T &a, const T& b){if(a < b){a = b;return true;}return false;}
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };

int main(){cout<<fixed<<setprecision(20);
		   int n;
           int k;
           cin>>n>>k;
           vin x(n);
           rep(i,0,n)cin>>x[i];
           int ans=0;
           rep(i,0,n){
            ans+=min(abs(x[i]),abs(x[i]-k)); 
           }
           cout<<ans*2<<endl;
}

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

int main(){
    int n;
    cin >> n;
    vector<ll> a(n + 1);
    rep(i, n) cin >> a[i + 1];
    rep(i, n) a[i + 1] += a[i];
    sort(a.begin(), a.end());
    ll ans = 0;
    vector<ll> res;
    int p = a[0];
    int q = 1;
    rep(i, n){
        if (a[i] != a[i + 1]){
            res.pb(q);
            q = 1;
        }
        else q++;
    }
    res.pb(q);
    rep(i, res.size()) ans += res[i] * (res[i] - 1) / 2; 
    cout << ans << endl;
}

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

#define ll long long
#define pb push_back

const int maxn = 1e5 + 20;

int solve(vector<int> a)
{
	int odd = 0 , even = 0 , f = 0;

	for(auto x : a)
	{
		if(x % 2)
			odd++;
		else
			even++;

		if(x == 1)
			f = 1;
	}

	if(f)
		return even % 2;

	if(even == 0)
		return 0;
	
	if(odd == 1)
	{
		for(auto &x : a)
			if(x % 2 == 1)
				x--;
		int g = a[0];

		for(auto x : a)
			g = __gcd(g , x);

		for(auto &x : a)
			x /= g;

		return !solve(a);
	}

	return (even % 2);
}

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

	int n;
	cin >> n;

	vector<int> tmp;

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

		tmp.pb(x);
	}

	cout << (solve(tmp)? "First" : "Second") << endl;
}










Measured memory_bytes: 10232
//A
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;
int A, B;

int main()
{
  cin >> A >> B;
  if (A - (2 * B) <= 0)
  {
    cout << "0" << endl;
    return 0;
  }
  cout << A - (2 * B) << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int mod=1000000007;
int fac[5010];
int ksm(int b,int p)
{
	int ans=1;
	for(;p;p>>=1)
	{
		if(p&1)
			ans=ans*b%mod;
		b=b*b%mod;
	}
	return ans;
}
int C(int n,int m)
{
	return fac[n]*ksm(fac[m],mod-2)%mod*ksm(fac[n-m],mod-2)%mod;
}
signed main()
{
	int s,n,i,j,ans=0;
	cin>>s;
	fac[1]=fac[0]=1;
	for(i=2;i<=4003;i++)
		fac[i]=fac[i-1]*i%mod;
	if(s<3)
		cout<<0;
	else
	{
		for(i=1;i<=s/3;i++)
		{
			n=s-3*i;
			ans=(ans+C(n+i-1,i-1))%mod;
		}
	cout<<ans;
	}
	return 0;
}

Measured memory_bytes: 3664
from itertools import accumulate


def gcd(x, y):
    if y == 0:
        return x
    return gcd(y, x % y)


N, K = map(int, input().split())
A = list(map(int, input().split()))
B = [abs(a-K) for a in A]

ans = list(accumulate(B, func=gcd))[-1]
print(ans)

Measured memory_bytes: 14100
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using Pair = pair<int, int>;
using Graph = vector<vector<int>>;
#define MOD 1000000007
#define INF 1000000007
#define SEP " "

int     main()
{
	ll n, m, k;
	cin >> n >> m >> k;
	vector<ll> a(n, 0);
	vector<ll> b(m, 0);
	vector<ll> suma(n + 1, 0);
	vector<ll> sumb(m + 1, 0);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		suma[i+1] = suma[i] + a[i];
	}
	for (int i = 0; i < m; i++) {
		cin >> b[i];
		sumb[i+1] = sumb[i] + b[i];
	}
	ll max = 0;
	for (ll i = 0; i < n+1; i++) {
		auto it = upper_bound(sumb.begin(), sumb.end(), k - suma[i]);
		if (it == sumb.begin())
			continue ;
		ll tmp = it - sumb.begin() + i  - 1;
		if (tmp > max)
			max = tmp;
	}
	cout << max << endl;
}



Measured memory_bytes: 9588
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<vector>
using namespace std;

int main()
{
    int n, h;
    int i, p, ans = 0, judge = 0, key = 0;
    
    cin >> n >> h;
    
    int a[n], b[n], c[2*n];
    
    for(i = 0; i < n; i++) {
        cin >> a[i] >> b[i];
    }
    
    sort(a, a+n);
    sort(b, b+n);
    
    p = a[n-1];
    
    i = n - 1;
    do {
        
        if((p < b[i]) && (key == 0)) {
            h = h - b[i];
            ans++;
            i--;
            
            if(h <= 0) {
                judge = 1;
            }
            
            if(i < 0) {
                key = 1;
            }
            
        } else {
            
            if((h % p) == 0) {
                ans = ans + (h / p);
            } else {
                ans = ans + (h / p) + 1;
            }
            judge = 1;
        }
        
    } while(judge == 0);
    
    cout << ans << endl;
    
    return 0;
}

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

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

    int s,w; cin >> s >> w;
    if(w >= s){
        cout << "unsafe";
    }
    else{
        cout << "safe";
    }


    return 0;
}


Measured memory_bytes: 3636
a, b, k = map(int, input().split())
if a >= 1 and a <= k:
    k -= a
    a = 0

elif a >= 1 and a > k:
    a -= k
    k -= a

if b >= 1 and k > 0 and b <= k:
    k -= b
    b = 0
elif b >= 1 and k > 0 and b > k:
    b -= k
    k -= b


print(a, b)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
constexpr int64_t mod=1e9+7;

int main()
{
  int64_t n;
  cin>>n;
  std::vector<int64_t> a(n);
  std::vector<int64_t> sum(n+1);
  sum[0]=0;
  for (int i = 0; i < n; ++i)
  {
    cin>>a[i];
    sum[i+1]=sum[i]+a[i];
  }

  std::map<int64_t, int64_t> mp;
  for (int i = 0; i < n+1; ++i)
  {
    mp[sum[i]]++;
  }

  int64_t cnt=0;
  for(auto&& e: mp) {
    cnt+=e.second*(e.second-1)/2;
  }
  cout<<cnt;
  
}

Measured memory_bytes: 15872
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n;i++)
const int INF=1e9;
using namespace std;
vector<bool>v(200001,false);
vector<bool>s(200001,false);
vector<int>_v(200001,0);
vector<int>_s(200001,0);
int main(){
    int n,m; cin>>n>>m;
    rep(i,m){
        int a,b; cin>>a>>b;
        if(a==1||b==1){v[(a==1?b:a)]=true;_v.push_back((a==1?b:a));}
        if(a==n||b==n){s[(a==n?b:a)]=true; _s.push_back((a==n?b:a));}
    }
    rep(i,_v.size()){
        if(s[_v[i]])return puts("POSSIBLE")*0;
    }
    cout<<"IMPOSSIBLE"<<endl;
}


Measured memory_bytes: 2688
import math
N=int(input())
C=list(map(int,input().split()))
ave = sum(C) / len(C)
X=math.floor(ave)
Y=X+1
Xsum,Ysum=0,0
for i in range(len(C)):
  Xsum += (C[i]-X)**2
  Ysum += (C[i]-Y)**2
print(min([Xsum,Ysum]))

Measured memory_bytes: 9092