akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cmath>
#include<vector>
#include<set>
#include<algorithm>
#include<tuple>
#include<utility>
#include<cctype>
#include<climits>
#include<map>
#include<queue>
#include<functional>

using namespace std;
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;}}

#define REP(i,a,n) for(int i=a;i<n;++i)
#define RUP(a,b) ((a+b-1)/(b))
#define ENT "\n"
#define REV(v) reverse(v.begin(),v.end())
#define SRT(v) sort(v.begin(),v.end())
#define MOD 1000000007

typedef long long ll;
typedef tuple<int,int,bool> Tb;

int atcoder(){
    //入力
    int p[1100];
    p[0] = 0;
    REP(i,1,1000){
        p[i] = p[i-1] + i;
    }
    int a,b;
    cin >> a >> b;
    //処理
    //出力
    cout << p[b-a]-b << ENT;
    return 0;
}

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


Measured memory_bytes: 256
#include<stdio.h>
void swap(int *a,int *b){
    int t=*a;
    *a = *b;
    *b = t;
    return;
}
int bubble(int n, int a[]){
    int i, j, flag, sw=0;
    flag=1;
    for(i=0;flag;i++){
        flag=0;
        for(j=n-1;j>=i+1;j--){
            if(a[j] < a[j-1]){
                swap(&a[j], &a[j-1]);
                flag=1;
                sw++;
            }
        }
    }
    return sw;
}
int main(void){
    int n, sw, i, a[100];
    scanf("%d", &n);
    for(i=0;i<n;i++){
        scanf("%d", &a[i]);
    }
    sw = bubble(n, a);
    for(i=0;i<n;i++) {
        if(i){
            printf(" ");
        }
        printf("%d",a[i]);
    }
    printf("\n%d\n",sw);
    return 0;
}


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

using namespace std;

using int64 = long long;

int main() {
  int X[4] = {};
  for(int i = 0; i < 3; i++) {
    int a, b;
    cin >> a >> b;
    --a, --b;
    X[a]++;
    X[b]++;
  }
  sort(X, X + 4);
  if(X[0] == 1 && X[1] == 1 && X[2] == X[3] && X[2] == 2) {
    cout << "YES\n";
  } else {
    cout << "NO\n";
  }
}



Measured memory_bytes: 256
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE BinaryLiterals #-}
{-# LANGUAGE MultiWayIf #-}
{-# LANGUAGE NumDecimals #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TupleSections #-}

import Control.Applicative
import Control.Arrow
import Control.Monad
import Control.Monad.ST

import Data.Char
import Data.List
import Data.Maybe

import qualified Data.ByteString.Char8 as B

import Data.Array.ST.Safe
import Data.STRef

import Debug.Trace
import Text.Printf

readInt = readLn :: IO Int
readInteger = readLn :: IO Integer
readInts = map ( fst . fromJust . B.readInt ) . B.words <$> B.getLine
readIntegers = map ( fst . fromJust . B.readInteger ) . B.words <$> B.getLine

which a b f = if f then a else b
mp [ a, b ] = ( a, b )

modifyArray a i f = writeArray a i =<< f <$> readArray a i

main = getLine >>= putStrLn . f

f "Sunny" = "Cloudy"
f "Cloudy" = "Rainy"
f "Rainy" = "Sunny"

Measured memory_bytes: 380
#include <bits/stdc++.h>                                                                        
using namespace std;                                                                            
using ll = long long;                                                                           
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }         
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }         
#define rep(i,n) for (int i=0; i< (n); ++i)                                                     
typedef pair<int, int> P;                                                                       
                                                                                                
int main() {                                                                                    
  int n;                                                                                        
  cin >> n;                                                                                     
  vector<string> s(n);                                                                          
  rep(i,n) cin >> s[i];                                                                         
  rep(i,n) sort(s[i].begin(), s[i].end());                                                      
  sort(s.begin(), s.end());                                                                     
  //rep(i,n) cout << s[i] << endl;                                                              
  vector<int> comb;                                                                             
                                                                                                
  ll sum = 0;                                                                                   
  int curcomb = 0;                                                                              
  rep(i,n-1) {                                                                                  
    if (s[i] == s[i+1]) {                                                                       
      curcomb++;                                                                                
    } else {                                                                                    
      sum += (ll)curcomb * ((ll)curcomb+1) / 2;                                                 
      curcomb = 0;                                                                              
    }                                                                                           
  }                                                                                             
  sum += (ll)curcomb * ((ll)curcomb+1) / 2;                                                     
  cout << sum << endl;                                                                          
                                                                                                
  return 0;                                                                                     
}    

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

public class Main{
    public static void main(String[] args) throws IOException {
        BufferedReader r = new BufferedReader(new InputStreamReader(System.in));
        String str;

        while(true){
            str = r.readLine();

            // str = 0 の場合は処理を終了
            if (str.equals("0")) {
                break;
            }

            int n = Integer.parseInt(str);
            long sum = 0;
            long max = Long.MIN_VALUE;

            for (int i = 0; i < n; i++) {
                int a = Integer.parseInt(r.readLine());
                sum = Math.max((sum + a), a);
                max = Math.max(sum, max);
            }

            System.out.println(max);
        }
    }
}

Measured memory_bytes: 21540
#include<bits/stdc++.h>
using namespace std;
bool flg[500000]{false};
int main(void){
	int n;
	int i,j;
	
	for(i=2;i*i<=500000;i++){
		if(!flg[i]){
			for(j=2;i*j<=500000;j++){
				flg[i*j]=true;
			}
		}
	}
	//for(i=2;i*i<=500000;i++)	if(!flg[i])	cout<<i<<endl;
	while(1){
		cin>>n;
		if(cin.eof())	break;
		i=n-1;
		while(1){
			if(!flg[i]){
				cout<<i<<" ";
				break;
			}
			i--;
		}
		i=n+1;
		while(1){
			if(!flg[i]){
				cout<<i<<endl;
				break;
			}
			i++;
		}
	}
	return 0;
}


Measured memory_bytes: 3508
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::{Bytes, Chars};
#[allow(unused_imports)]
use std::cmp::{min, max};

fn main() {
	input! {
		n: usize,
		mut a: [usize; n],
	}

	let mut ans = 0;
	loop {
		for i in 0..n {
			if a[i] % 2 == 1 {
				println!("{}", ans);
				return;
			}
			a[i] /= 2;
		}
		ans += 1;
	}
}



Measured memory_bytes: 2176
#include <bits/stdc++.h>
#define debug(x) cerr << #x << ": " << x << '\n';
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = (int)1e9;

int w, h;
int c[51][51];
int dx[] = {1, -1, 0, 0, 1, 1, -1, -1};
int dy[] = {0, 0, 1, -1, 1, -1, 1, -1};

void dfs(int y, int x){
	c[y][x] = 0;
	for(int i = 0; i < 8; i++){
		int ny = y + dy[i], nx = x + dx[i];
		if(0<=ny and ny<h and 0<=nx and nx<w and c[ny][nx]==1){
			dfs(ny, nx);
		}
	}
}

int solve(){
	int res = 0;
	for(int i = 0; i < h; i++){
		for(int j = 0; j < w; j++){
			if(c[i][j] == 1){
				dfs(i, j);
				res++;
			}
		}
	}

	return res;
}

int main(void){
	while(scanf("%d%d", &w, &h) != EOF){
		if(w == 0 and h == 0) break;
		for(int i = 0; i < h; i++){
			for(int j = 0; j < w; j++){
				scanf("%d", &(c[i][j]));
			}
		}
		printf("%d\n", solve());
	}

	return 0;
}



Measured memory_bytes: 3208
# -*- coding:utf-8 -*-
import sys

def main():
    data = []
    for passwd in sys.stdin.readlines():
        data.append(passwd.strip())
    for answer in proc(data):
        print answer
    return 0

def proc(data):
    return [passwd for passwd in data if is_hitofude(passwd)]

def is_hitofude(text):
    for first, second in get_pair(text):
        if second == '': break
        if not _can_slide(first, second):
            return False
    return True

def get_pair(text):
    pair_list = list(text)
    pair_list.reverse()
    while(True):
        if 2 <= len(pair_list):
            yield (pair_list.pop(), pair_list[-1])
        elif 1 == len(pair_list):
            yield (pair_list.pop(), '')
        else:
            break

matrix = ["ABC",
          "DEF",
          "GHI"]
pair = []
for y, row in enumerate(matrix):
    for x, base in enumerate(row):
        if x+1 < len(row): pair.append((base, row[x+1])) #EF
        if 0 <= x-1 : pair.append((base, row[x-1])) #ED
        if y+1 < 3: pair.append((base, matrix[y+1][x])) #EH
        if 0 <= y-1: pair.append((base, matrix[y-1][x])) #EB

def _can_slide(first, second):
    return (first, second) in pair

if __name__ == '__main__':
    main()

Measured memory_bytes: 6488
<?php
  
fscanf(STDIN,"%d",$x);
$count=0;

$waru=2;

if($x==1){
  echo "1\n";
}else{
  for($i=$x;$i>1;$i--){
    $beki = $i;
	for($j=2;$j<$x;$j++){
      //echo $j."\n";
      for($k=2;  $waru<$i;$k++){
       	$waru = $j**$k;
        //echo $waru."\n";
       
        if($i==$waru){ 
          echo $i."\n";
          //echo $j;
          exit;
        }
      }
$waru=0;
    }
  
  
  }
  
  
  
  
  
}




Measured memory_bytes: 4604
#include <iostream>
#include <queue>
#include <algorithm>
using namespace std;

#define INF 1000000000

struct edge {
    int to;
    double dis;
    edge(int to, double dis):to(to), dis(dis){}
};

typedef pair< int, int > iP;
typedef pair< double, iP > iiP;

int n, m, p, a, b;
int t[8];
vector< vector< edge > > graph;

double dijkstra() {
    double dist[31][1 << 8];
    priority_queue< iiP, vector< iiP >, greater< iiP > > que;
    fill_n(*dist, 31 * (1 << 8), INF);
    que.push(iiP(0.0, iP(a, (1 << n) - 1)));
    dist[a][1 << n - 1] = 0.0;
    while(!que.empty()) {
        iiP p = que.top(); que.pop();
        int now = p.second.first, tt = p.second.second;
        double dis = p.first;
        if(now == b) return dis;

        for(int i = 0; i < graph[now].size(); i++) {
            edge &e = graph[now][i];
            for(int j = 0; j < n; j++) {
                if(tt & (1 << j)) {
                    int next_bit = tt & ~(1 << j);
                    if(dis + e.dis / t[j] < dist[e.to][next_bit]) {
                        que.push(iiP(dis + e.dis / t[j], iP(e.to, next_bit)));
                        dist[e.to][next_bit] = dis + e.dis / t[j];
                    }
                }
            }
        }
    }
    return -1;
}

int main() {

    while(cin >> n >> m >> p >> a >> b, n) {
        graph.resize(m + 1);
        for(int i = 0; i < n; i++)
            cin >> t[i];
        for(int i = 0; i < p; i++) {
            int x, y; double dis;
            cin >> x >> y >> dis;
            graph[x].push_back(edge(y, dis));
            graph[y].push_back(edge(x, dis));
        }
        double ans = dijkstra();
        if(ans != -1) {
            cout << ans << endl;
        } else {
            cout << "Impossible" << endl;
        }

        for(int i = 0; i <= m; i++) {
            graph[i].clear();
        } graph.clear();
    }
}

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

int main() {
  int A,B;
  cin >> A >> B;
  int num=0;

  for (int i=A; i<=B; i++) {
    string str = to_string(i);
    if (str[0]==str[4]&&str[1]==str[3]){
      num += 1; 
    }
  }

  cout << num << endl;
}

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

int main() {
    int N, M; cin >> N >> M;
    vector<pair<int, int>> AB(M);
    REP(i, 0, M) {
        int a, b; cin >> a >> b;
        AB[i] = make_pair(a, b);
    }

    sort(AB.begin(), AB.end(), [](auto &x, auto &y){return x.second < y.second;});
    
    int last = 0, cnt = 0;
    REP(i, 0, M) {
        if (last < AB[i].first) {
            last = AB[i].second - 1;
            cnt++;
        }
    }
    cout << cnt << endl;
    return 0;
}

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

struct Node{
    int key;
    Node *next, *prev;
};

Node *nil;

void initialize(){
    nil = (Node *)malloc(sizeof(Node)); // malloc:メモリを確保,sizeof:Nodeを定義するのに必要なメモリを確保
    nil->next = nil; // (*nil).next = nil
    nil->prev = nil; // ->は参照？
}

Node* listSearch(int key){
    Node *cur = nil->next;
    while(cur != nil && cur->key != key) cur = cur->next;
    // curがnilでなく、キーが見つからなければそこのキーを返し、見つかれば次のcurを返す
    return cur;
}

// Nodeを消す
void deleteNode(Node *t){
    if(t == nil) return; // tがなければ何もしない
    //2つの操作でtの前とあとを相互に繋げる
    t->prev->next = t->next;
    t->next->prev = t->prev;
    free(t); // メモリ解放
}

void deleteFirst(){
    deleteNode(nil->next); // nilが基準だから、nil->nextが最初のポインタ、nil->prevが最後のポインタ
}

void deleteLast(){
    deleteNode(nil->prev);
}

void deleteKey(int key){
    deleteNode(listSearch(key));
}

void insert(int key){
    Node *x = (Node *)malloc(sizeof(Node));
    x->key = key;

    x->next = nil->next; // nilの次が最初だから
    nil->next->prev = x;
    nil->next = x;
    x->prev = nil;
}

void printList(){
    Node *cur = nil->next;
    int count = 0;
    while(1){
        if(cur == nil) break;
        if(count > 0) cout << " ";
        cout << cur->key;
        count++;
        cur = cur->next;
    }
    
    cout << endl;
}

int main(){
    int n; scanf("%d", &n); // %dで整数,nのポインタを入れる
    char com[20]; // サイズ20のchar型配列
    int d;

    initialize();
    for(int i=0; i<n; ++i){
        scanf("%s", com);
        if(com[0] == 'i'){
            scanf("%d", &d);
            insert(d);
        }else if(com[0] == 'd'){
            if(strlen(com) > 6){
                if(com[6] == 'F') deleteFirst();
                else if(com[6] == 'L') deleteLast();
            }else{
                scanf("%d", &d);
                deleteKey(d);
            }
        }
    }

    printList();
}


Measured memory_bytes: 34400
#include<iostream>

#include<cmath>

using namespace std;



int main()

{

	int a[3], k;

	scanf("%d%d%d%d", &a[0], &a[1], &a[2], &k);

	int max = 0, add = 0;

	for (int i = 0; i < 3; ++i)

		if (max < a[i])

		{

			add += max;

			max = a[i];

		}

		else

			add += a[i];

	add += max*pow(2, k);
        cout<<add<<endl;
	

	return 0;

}


Measured memory_bytes: 256
#include <stdio.h>
#include<iostream>
#include <string.h>
using namespace std;
long long int DP[10000];
bool chack[10000];
long long int lucas(int a){
    if(chack[a]){
        return DP[a];
    }
    if(a==0){
        return 2;
    }
    if(a==1){
        return 1;
    }
    long long int ent;
    ent=lucas(a-1)+lucas(a-2);
    DP[a]=ent;
    chack[a]=true;
    return ent;
}
int main(void) {
    long long int ans;
    int n;
    cin >>n;
    ans=lucas(n);
    cout<<ans<<endl;
    return 0;
}



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


int main()
{
	int a, b, total=0;
	cin >> a >> b;
	for(int i=0; i<a; i++)
	{
		double x, y, j;
		cin >> x >> y;
		j = sqrt(x*x+y*y);
		if(j <= b)
		{
			total++;
		}
	}
	cout << total;
}



Measured memory_bytes: 3760
#include<bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
#define pb push_back
int dy[]={0, 0, 1, -1, 1, 1, -1, -1};
int dx[]={1, -1, 0, 0, 1, -1, -1, 1};

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define mp make_pair
#define fi first
#define sc second
ll n;
char s[200000];
char cou[3];
int main(){
	cin >> s;
	n = strlen(s);

	REP(i,n) {
		cou[s[i] - 'a']++;
	}

	sort(cou,cou+3);

	cou[2] -= cou[0];

	if(cou[2] <= 1) {
		cout << "YES" << endl;
	}else {
		cout << "NO" << endl;
	}
	return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <stack>
#include <string>

using namespace std;

int main(void)
{	

	stack<int> st;
	
	int i;
	while(true){
		string s;
		cin >> s;
		if(cin.good() == false){
			break;
		}
		
		if(s == "+"){
			int a = st.top();
			st.pop();
			int b = st.top();
			st.pop();
			st.push(a + b);
		}
		else if(s == "-"){
			int a = st.top();
			st.pop();
			int b = st.top();
			st.pop();
			st.push(b - a);
		}
		else if(s == "*"){
			int a = st.top();
			st.pop();
			int b = st.top();
			st.pop();
			st.push(a * b);
		}
		else{
			i = stoi(s);
			st.push(i);
		}
	}
	
	int r = st.top();
	cout << r << endl;
	return 0;
}

Measured memory_bytes: 3128
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#define REP(i,n) for (int i=1;i<=(n);++i)
#define FOR(i,a,b) for (int i=(a);i<=(b);++i)
#define ROF(i,a,b) for (int i=(a);i>=(b);--i)
#define FEC(p,u) for (edge*p=head[u];p;p=p->nxt)
using namespace std;
typedef long long LL;

int n, a[110000], ans;
int main(){
	scanf("%d", &n);
	REP(i,n) scanf("%d", a+i);
	REP(i,n) if (a[a[i]] == i) ++ans;
	printf("%d\n", ans/2);
	return 0;
}


Measured memory_bytes: 768
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>
using namespace std;

int main() {
	int N; cin >> N;
	vector<int> r(N);
	for (int i = 0; i < N; i++)
		cin >> r[i];
	sort(r.begin(), r.end());
	double ma = 0;
	for (int n = 3; n <= N; n++) {
		vector<int> a(r.end() - n, r.end());
		do {
			vector<double> x(n), y(n);
			for (int i = 0; i < n; i++) {
				x[i] = a[i] * cos(M_PI*2 / n * i);
				y[i] = a[i] * sin(M_PI*2 / n * i);
			}
			for (int t = 0; t < 20; t++) {
				int i = rand() % n;
				int j = (i + n - 1) % n, k = (i + 1) % n;
				double dx = x[k] - x[j], dy = y[k] - y[j];
				double _dx = dy, _dy = -dx;
				double r = sqrt(_dx * _dx + _dy * _dy);
				x[i] = _dx / r * a[i];
				y[i] = _dy / r * a[i];
			}
			double sum = 0;
			for (int i = 0; i < n; i++) {
				int j = (i + 1) % n;
				sum += x[i] * y[j] - y[i] * x[j];
			}
			ma = max(ma, sum);
		} while (next_permutation(a.begin() + 1, a.end()));
	}
	printf("%.15f\n", ma / 2);
}

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

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))
#define INF 1000000000000 //10^12
#define MOD 1000000007 //10^9+7
#define PB push_back
#define MP make_pair
// #define F first
// #define S second
#define MAXR 100000 //10^5:最大のrange(素数列挙などで使用)
#define Sp(p) cout<<setprecision(25)<< fixed<<p<<endl
ld P[200000+5];


int main() {
    ll N,K;
    cin >> N >> K;
    FOR(i,0,N-1) {
        cin >> P[i];
    }

    ld sum = 0;
    FOR(i,0,K-1) {
        sum += (P[i]+1)/2;
    }

    ld max = sum;
    FOR(i,1,N-K) {
        sum = sum - (P[i-1]+1)/2 + (P[i+K-1]+1)/2;
        if (max < sum) {
            max = sum;
        }
    }
    Sp(max);
}

Measured memory_bytes: 3328
#include <iostream>
//#include <algorithm>
//#include <cmath>
//#include <vector>
//#include <string>
//typedef long long LL;
using namespace std;

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

    if(a<=5){
        fee = 0;
    }else if(a<=12){
        fee = b/2;
    }else{
        fee = b;
    }
    cout << fee << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <iomanip>
#include <queue>
#include <deque>
#include <map>
#include <unordered_map>
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define repr(e,x) for(auto& e:x)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

ll N;

int main(){
    cin>>N;

    ll ans[3];
    repn(h,3500){
        repn(n,3500){
            ll A=N*h*n;
            ll B=4*h*n-N*(n+h);
            if(B==0) continue;
            if(A%B==0){
                if(A/B<0) continue;
                ans[0]=h;
                ans[1]=n;
                ans[2]=A/B;
                goto a;
            }
        }
    }
    a:;

    rep(i,3) cout<<ans[i]<<' '; cout<<endl;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
//#pragma GCC target("avx2,sse2,sse,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
#include<bits/extc++.h>
using namespace __gnu_pbds;
#define pb push_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
using namespace std;
using ll = long long;
using vi = vector<ll>;
int n, m, q, mat[2020][2020], res[2020][2020], pref[2020][2020][5];
int dx[] = {1, -1, 0, 0}, dy[] = {0, 0, 1, -1};
void dfs(int x, int y) {
	for(int i = 0; i < 4; i++) {
		int tx = x+dx[i], ty = y+dy[i];
		if(tx<1||tx>n||ty<1||ty>m) continue;
		if(!mat[tx][ty]||res[tx][ty]) continue;
		res[tx][ty] = 2+i;
		dfs(tx, ty);
	}
}
void calc() {
	for(int x = 0; x < 5; x++) {
		for(int i = 1; i <= n; i++) {
			for(int j = 1; j <= m; j++) {
				pref[i][j][x] = pref[i-1][j][x]+pref[i][j-1][x]-pref[i-1][j-1][x]+(res[i][j]==x+1);
			}
		}
	}
}
int get(int lx, int rx, int ly, int ry, int x) {
	--lx, --ly;
	return pref[rx][ry][x]-pref[lx][ry][x]-pref[rx][ly][x]+pref[lx][ly][x];
}
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin >> n >> m >> q;
	char c;
	for(int i = 1; i <= n; i++) {
		for(int j = 1; j <= m; j++) {
			cin >>c;
			mat[i][j]=(c>'0');
		}
	}
	for(int i = 1; i <= n; i++) {
		for(int j = 1; j <= m; j++) {
			if(!mat[i][j]||res[i][j]) continue;
			res[i][j] = 1;
			dfs(i, j);
		}
	}
	calc();
	ll lx, ly, rx, ry;
	while(q--) {
		cin >> lx >> ly >> rx >> ry;
		int ans = get(lx, rx, ly, ry, 0);
		ans += get(lx, lx, ly, ry, 1);
		ans += get(rx, rx, ly, ry, 2);
		ans += get(lx, rx, ly, ly, 3);
		ans += get(lx, rx, ry, ry, 4);
		cout << ans << "\n";
	}
}


Measured memory_bytes: 113280
#include <iostream>

#include <iomanip>
#include <stdio.h>
using namespace std;

int main()
{
    int N, h;
    cin >> h >> N;
    int a[N];
    for (int i = 0; i < N; i++)
    {
        cin>>a[i];
        h -= a[i];
    }
    if (h > 0)
        printf("No");
    else
        printf("Yes");

}

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

int check(vector<int> character, int i, int color)
{
  if(character[i] == color) return character.size();

  character[i] = color;
  bool vanished = true;
  while(vanished){
    int count = 0;
    int top, bottom;
    for(top=i; top>=0 && character[top]==color; top--){
      count++;
    }
    for(bottom=i+1; bottom<character.size() && character[bottom]==color; bottom++){
      count++;
    }
    top++;
    bottom--;

    if(count<4){
      vanished = false;
    }else{
      character.erase(character.begin()+top, character.begin()+bottom+1);
      i = min(top, (int)character.size()-1);
      color=character[i];
    }
  }

  return character.size();
}

int main()
{
  int N, M;
  while(cin>>N, N){
    vector<int> character(N);
    for(int i=0; i<N; i++) cin>>character[i];

    M = 100000;
    for(int i=0; i<N; i++){
      for(int color=1; color<=3; color++){
        M = min(M, check(character, i, color));
      }
    }
    cout<<M<<endl;
  }
}

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


int main() {
  ll n,m; cin>>n>>m;
  vector<ll> v(n);
  rep(i,n){cin>>v[i];}
  sort(v.begin(),v.end());
  vector<pll> vec(m);
  rep(i,m){
    cin>>vec[i].second>>vec[i].first;
  }
  sort(vec.begin(), vec.end(), greater<pll>());
  ll k=0;
  rep(i,m){
    rep(j,vec[i].second){
      if(v[k]>=vec[i].first){break;}
      v[k]=vec[i].first;
      k++;
      if(k==n){break;}
    }
  }
  ll sum=0;
  rep(i,n){sum+=v[i];}
  cout<<sum<<endl;
}

Measured memory_bytes: 5608
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define int long long
using namespace std;
typedef vector<int>   vint;
typedef pair<int,int> pint;

int N,ans;

void dfs(int cur,int mask){
    if(cur>N) return;
    if(mask==7) ans++;

    dfs(cur*10+3,mask|1);
    dfs(cur*10+5,mask|2);
    dfs(cur*10+7,mask|4);
}

signed main()
{
    cin>>N;
    dfs(0,0);
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cmath>

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

#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define REP2(i,n,s) for(int i=(int)(s);i<(int)(n);++i)
#define RREP(i,n,s) for(int i=(int)(s);i>=(int)(n);--i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin(),ie=(c).end();i!=ie;++i)
#define ALL(c) (c).begin(), (c).end()

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

    bool f = false;
    RREP(i,0,s.size()-1-(t.size()-1)) {
        int index = i;
        f = true;
        REP(j,t.size()) {
            if(!(s[index] == t[j] || s[index] == '?')) {
                f = false;
                break;
            }
            index++;
        }
        if(f) {
            s.replace(i, t.size(), t);
            break;
        }
    }
    if(f) {
        FOR(i,s) if(*i == '?') *i = 'a';
        cout << s << endl;
    } else cout << "UNRESTORABLE" << endl;
}


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

int Binary_Research(int key, vector<int> &vec){
    int left,right,mid;
    left=0; right=vec.size()-1;
    while(left<=right){
        mid=(left+right)/2;
        if(vec[mid]==key) 
            return 1;
        else if(vec[mid]>key)  
            right=mid-1;
        else 
            left=mid+1;
    }
    return 0;
}

int main(){
    int n; cin >> n;
    vector<int> S(n);
    for(int i=0; i<n; i++) cin >> S[i];

    int q; cin >> q;
    vector<int> T(q);
    for(int i=0; i<q; i++) cin >> T[i];

    int count=0;
    for(int i=0; i<q; i++)
        if(Binary_Research(T[i],S)) count++;
    
    cout << count << endl;
    return 0;
}



Measured memory_bytes: 3360
// #define DEBUGGING
#include <bits/stdc++.h>
#define endl '\n'
#define ALL(V) (V).begin(), (V).end()
#define ALLR(V) (V).rbegin(), (V).rend()
template <typename T> using V = std::vector<T>;
template <typename T> using VV = V<V<T>>;
using ll = std::int64_t;
using ull = std::uint64_t;
using PLL = std::pair<ll, ll>;
using TLL = std::tuple<ll, ll, ll>;
template <typename T> const T& var_min(const T &t) { return t; }
template <typename T> const T& var_max(const T &t) { return t; }
template <typename T, typename... Tail> const T& var_min(const T &t, const Tail&... tail) { return std::min(t, var_min(tail...)); }
template <typename T, typename... Tail> const T& var_max(const T &t, const Tail&... tail) { return std::max(t, var_max(tail...)); }
template <typename T, typename... Tail> void chmin(T &t, const Tail&... tail) { t = var_min(t, tail...); }
template <typename T, typename... Tail> void chmax(T &t, const Tail&... tail) { t = var_max(t, tail...); }
template <typename T> const T& clamp(const T &t, const T &low, const T &high) { return std::max(low, std::min(high, t)); }
template <typename T> void chclamp(T &t, const T &low, const T &high) { return t = clamp(t, low, high); }
namespace init__ { struct InitIO { InitIO() { std::cin.tie(nullptr); std::ios_base::sync_with_stdio(false); std::cout << std::fixed << std::setprecision(30); } } init_io; }
#define mv_rec make_v(init, tail...)
template <typename T> T make_v(T init) { return init; }
template <typename T, typename... Tail> auto make_v(T init, size_t s, Tail... tail) { return V<decltype(mv_rec)>(s, mv_rec); }
#undef mv_rec
using namespace std;
#ifdef DEBUGGING
#include "../../debug/debug.cpp"
#else
#define DEBUG(...) 0
#define DEBUG_SEPARATOR_LINE 0
#endif

const ll inf = 5e15;

int main() {
    ll N, Q;
    cin >> N >> Q;
    V<ll> A(N);
    for(auto &&ele : A) cin >> ele;
    sort(ALL(A));
    A.push_back(inf);

    while(Q--) {
        ll l, r;
        cin >> l >> r;
        auto lite = lower_bound(ALL(A), l);
        auto rite = upper_bound(ALL(A), r);
        cout << distance(lite, rite) << endl;
    }

    return 0;
}



Measured memory_bytes: 4308
n=int(input())
h=[int(i) for i in input().split()]
dp=[0]*n
dp[1]=abs(h[1]-h[0])
for i in range(1,n-1):
  dp[i+1]+=min(dp[i]+abs(h[i+1]-h[i]),dp[i-1]+abs(h[i+1]-h[i-1]))
print(dp[n-1])

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

long long N;
vector<pair<pair<string, long long>, long long> >SP;

int main(){
	cin >> N;
	for(long long i = 0; i < N; i++){
		long long num;
		string name;
		cin >> name >> num;
		SP.push_back(make_pair(make_pair(name, -1 * num), i));
	}
	sort(SP.begin(), SP.end());
	for(long long i = 0; i < N; i++){
		cout << SP[i].second + 1<< endl;
	}
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#define LEN 100005

int min(int a, int b){return a<b?a:b;}

typedef struct pp{
  char name[100];
  int t;
}P;

P Q[LEN+1];
int head, tail, n;

void enqueue(P x){
  Q[tail]=x;
  if(tail == LEN) tail = 1;
  else tail++;
}

P dequeue(){
  P x = Q[head];
  if(head==LEN) head = 1;
  else head++;
  return x;
}


int main(){
  int elaps = 0, c;
  int i, q;
  P u;
  scanf("%d %d", &n, &q);

  for ( i = 1; i <= n; i++){
    scanf("%s", Q[i].name);
    scanf("%d", &Q[i].t);
  }
  head=1;
  tail=n+1;
  while(head != tail){
    u = dequeue();
    c = min(q,u.t);
    u.t -= c;
    elaps += c;
    if(u.t > 0) enqueue(u);
    else{
      printf("%s %d\n",u.name,elaps);
    }
  }
  
  return 0;
}

Measured memory_bytes: 10756
#include<cmath>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<functional>
//#define scanf scanf_s
#define fir first
#define sec second
#define mp make_pair
#define mt make_tuple
#define pub push_back
using namespace std;
typedef long long int llint;
const llint one = 1;
const llint big = (one<<50);
const int mod=1000000007;
inline int gcd(int a,int b) { return b ? gcd(b, a % b) : a; }
int main(void){
	llint N,i,j,k,q,wa=0,ans=0,ansa=0,fu;
	vector<llint> a;
	scanf("%lld",&N);
	for(i=0;i<N;i++){
		scanf("%lld",&q);
		a.pub(q);
	}
	for(i=0;i<N;i++){
		q=a[i];fu=i%2;//0is plas
		
		if(fu==0){ if(wa+q<=0){ ans+=abs(q+wa-1);q=-wa+1; } } 
		else{ if(wa+q>=0){ans+=abs(q+wa+1);q=-wa-1; }}
		wa+=q;
	}
	wa=0;
	for(i=0;i<N;i++){
		q=a[i];fu=i%2;//1is plas
		if(fu==1){ if(wa+q<=0){ ansa+=abs(q+wa-1);q=-wa+1; } } 
		else{ if(wa+q>=0){ansa+=abs(q+wa+1);q=-wa-1; }}
		wa+=q;
	}
	ans=min(ans,ansa);
	printf("%lld\n",ans);
	return 0;
}


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

int main(){
	string s, is;
	int n, sum = 0;

	while ( cin >> s ){
		int index = 0;
		while ( !( index == s.size() ) ){
			if ( s[ index ] >= '0' && s[ index ] <= '9' ){
				int len = 1;
				while (  s[ index + len ] >= '0' && s[ index + len ] <= '9' ){
					++len;
				}
				string is( s, index, len );
				istringstream iss( is );
				iss >> n;
				sum += n;
				index += len;
			}else{
				++index;
			}
		}
	}

	cout << sum << endl;

	return 0;
}

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

using namespace std;



int main(int argc, char* argv[])
{

  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  int R;
  cin >> R;

  if (R < 1200) cout << "ABC\n";
  else if (R < 2800) cout << "ARC\n";
  else cout << "AGC\n";

  return 0;
}


Measured memory_bytes: 256
def main():
    width = int(input())
    candies = [list(map(int, input().split(" "))) for _ in range(2)]
    candies_sum = []
    for c in candies:
        tmp = [0] * width
        for i in range(width):
            if i == 0:
                tmp[0] = c[0]
            else:
                tmp[i] = tmp[i - 1] + c[i]
        candies_sum.append(tmp)
    answer = candies_sum[0][0] + candies_sum[1][-1]
    for i in range(1, width):
        answer = max(answer, candies_sum[0][i] + candies_sum[1][-1] - candies_sum[1][i - 1])
    print(answer)


if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
import copy, collections, itertools
H, W = [int(_) for _ in input().split()]
S_ = [['#'] * (W + 2)] + [['#'] + list(input()) + ['#']
                          for _ in range(H)] + [['#'] * (W + 2)]
ans = 0
for i, j in itertools.product(range(1, H + 1), range(1, W + 1)):
    if S_[i][j] == '.':
        S = copy.deepcopy(S_)
        S[i][j] = '#'
        q = collections.deque([(i, j, 0)])
        while q:
            x, y, d = q.popleft()
            for dx, dy in [[-1, 0], [1, 0], [0, -1], [0, 1]]:
                if S[x + dx][y + dy] == '.':
                    X, Y = x + dx, y + dy
                    S[X][Y] = '#'
                    q += [(X, Y, d + 1)]
        ans = max(d, ans)
print(ans)


Measured memory_bytes: 52572
#include "iostream"

using namespace std;


int n, w[20];

bool solve(int m, int now, int d) {
	if (now == m) return true;
	else if (now > m || d >= n) return false;
	else {
		return solve(m, now + w[d], d+1) | solve(m, now, d+1);
	}
}

int main() {

	int q;
	int m;

	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> w[i];
	}
	cin >> q;
	for (int i = 0; i < q; i++) {
		cin >> m;
		if (solve(m, 0, 0)) cout << "yes" << endl;
		else cout << "no" << endl;
	}

	return 0;
}

Measured memory_bytes: 1152
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		Scanner sc = new Scanner(System.in);
		int H=sc.nextInt();
		int W=sc.nextInt();
		String S[]=new String[H];
		char C[][] = new char[H][W];
		for(int i=0;i<H;i++) {
			S[i]=sc.next();
			C[i]=S[i].toCharArray();
		}
		for(int i=0;i<H;i++) {
			for(int j=0;j<W;j++) {
				int c=0;
				if(C[i][j]=='.') {
					for(int k=-1;k<=1;k++) {
						if(i+k<0||i+k>=H)continue;
						for(int l=-1;l<=1;l++) {
							if(j+l<0||j+l>=W)continue;
							if(C[i+k][j+l]=='#') {
								c++;
							}
						}
					}
					C[i][j]=(char)('0'+c);
				}
			}
		}
		
		for(int i=0;i<H;i++) {
			S[i]=String.valueOf(C[i]);
			System.out.println(S[i]);
		}
		
	}
}


Measured memory_bytes: 21076
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		final int A = sc.nextInt();
		final int B = sc.nextInt();
		final int M = sc.nextInt();
		
		int[] a = new int[A];
		int[] b = new int[B];
		
		int minA = 100000;
		int minB = 100000;
		
		for (int i = 0; i < A; i++) {
			int p = sc.nextInt();
			if (p < minA)
				minA = p;
			a[i] = p;
		}
		for (int i = 0; i < B; i++) {
			int p = sc.nextInt();
			if (p < minB)
				minB = p;
			b[i] = p;
		}
		
		int min = minA + minB;
		
		for (int i = 0; i < M; i++) {
			int x = sc.nextInt();
			int y = sc.nextInt();
			int c = sc.nextInt();
			
			int cost = a[x - 1] + b[y - 1] - c;
			if (cost < min)
				min = cost;
		}
		
		System.out.println(min);
		sc.close();
	}
}


Measured memory_bytes: 151436
#include "bits/stdc++.h"

#define rep(a,b) for(int a = 0;a < b;a++)
#define REP(i, x, n) for(int i = x; i < n; i++)
#define P(a) cout << a << endl
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define ssort(v) sort(v.begin(),v.end())
#define rev(v) reverse(v.begin(),v.end())
#define vP(v) for(int i = 0;i < v.size();i++){cout << v[i];if(i != v.size()-1)cout << endl;}
#define vcin(v,n) rep(i,n){int a;cin >> a;v.pb(a);}

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
int dx[] = { 1, -1 , 0 , 0 };
int dy[] = { 0,  0,  1, -1 };
ll MOD = 1000000007;

void solve(){
	string s,f;
	cin >> s;
	vector<string> v;
	istringstream stream(s);
	while(getline(stream,f,',')){
		v.pb(f);
	}
	cout << v[0] << " " << v[1] << " " << v[2] << endl;
}

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


Measured memory_bytes: 256
/*------------------------------------
........Bismillahir Rahmanir Rahim....
..........created by Abdul Aziz.......
------------------------------------*/
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <unordered_map>
#include <queue>
#define   mod  998244353
#define   int  long long 
#define   ld   long double
#define   pb   push_back
#define   vi  vector<int> 
#define   dbg(x)  cerr << #x << " = " << x << '\n'
#define   sz(x)  (int)x.size()
#define   all(a) (a.begin(),a.end())
#define   ff   first
#define   ss   second
#define   pii  pair<int,int> 
#define   lcm(a,b) (a*b)/__gcd(a,b) 
using namespace std;

inline void solve(){
    bool ok=true;
    string s;cin>>s;
    for (int i=0;i<sz(s);){
        bool cur=false;
        for (int j=7 ;j>=5;j--){ 
            string h=s.substr(i,j);
            if (sz(h)<5) ok=false;
            if (h=="dream" or h=="erase" or h=="eraser") {
                cur=true;
                i+=sz(h); break;
            }
            if (h=="dreamer") {
                cur=true;
                i+=7; 
                if (i<sz(s) and s[i]=='a') i-=2;
                break;
            }
        }
        if (cur==false) ok=false;
        if (ok==false) break;
    }
    if (ok) cout << "YES"<< endl;
    else cout << "NO" << endl;
}

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


Measured memory_bytes: 3712
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.nextLine();
      	int cnt = 0;
        int cnt2 = 0;
      
      if(s.charAt(0)=='A'){
      	for(int i = 2;i < s.length()-1;i++){
        	if(s.charAt(i)=='C'){cnt++;}
        }if(cnt==1){
          for(int i = 0;i < s.length();i++){
          	if(s.charAt(i)>='A'&&s.charAt(i)<='Z'){cnt2++;}
          }
        }
      }
      		if(cnt2==2){
            System.out.println("AC");
        	System.exit(0);
            }
      		System.out.println("WA");
        	System.exit(0);
      
      }
}

Measured memory_bytes: 21844
// 6/26 解き直し → 6/30
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
using ll = long long;
using P = pair<int, int>;

const int INF = 1000000009;

int dp[1010][5000];
int N, M;
vector<vector<int>> c;

int get_nj(int x, int key) {
    vector<int> X;  // (N);
    rep(i, N) {
        X.push_back(x%2);
        x /= 2;
    }

    for (auto y : c[key]) X[y] = 1;

    int res = 0;
    int digit = 1;
    rep(i, N) {
        res += digit * X[i];
        digit *= 2;
    }

    // return 0;
    return res;
}

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

    vector<int> a(M), b(M);
    c.resize(M);

    // while (M--)
    rep(i, M) {
        cin >> a[i] >> b[i];
        c[i].resize(b[i]);
        rep(j, b[i]) {
            cin >> c[i][j];
            c[i][j]--;
        }
    }

    rep(i, M+1) rep(j, 1<<N) dp[i][j] = INF;
    dp[0][0] = 0;

    for (int i = 0; i < M; i++) {
        rep(j, 1<<N) {
            // if (dp[i][j] == -1) continue;
            // i番目の鍵を使わない場合
            dp[i+1][j] = min(dp[i+1][j], dp[i][j]);

            // i番目の鍵を使う場合
            int nj = get_nj(j, i);
            dp[i+1][nj] = min(dp[i+1][nj], dp[i][j] + a[i]);
        }
    }

    // printf("dp[%d][%d] = %d\n", M, (1<<N)-1, dp[M][(1<<N)-1]);
    if (dp[M][(1<<N)-1]==INF) cout << "-1" << endl;
    else cout << dp[M][(1<<N)-1] << endl;
}

Measured memory_bytes: 23216
input = readlines.map{|x|x.to_i}
n = input[0]

a_list = input.slice(1, n)
max_value = a_list.max
sorted_a_list = a_list.sort

a_list.each {|a|
    if max_value == a
        p sorted_a_list[n-2]
    elsif
        p max_value
    end
}

Measured memory_bytes: 29672
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cassert>
#include <iostream>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <sstream>
#include <bitset>
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define invrepr(i,a,b) for(int i=b-1;i>=a;i--)
#define invrep(i,n) invrepr(i,0,n)

using namespace std;
typedef long long ll;

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


    ll ans=0;
    ll anss =0;
    ll count=0;
    ll i,j,h;
    ll Q,N,K;
    
    long double a, b;
    long double x;

    vector<ll> aa;
    string S;

    ll flag=0;
    ll temp=0;

    cin  >> a;

    
    
    cout<<a*2*M_PI<<endl;

    return 0;
}

Measured memory_bytes: 3844
#include <iostream>
#include <string>
#include <vector>
#include <numeric>
#include <queue>
#include <unordered_map>
#include <algorithm>
#include <cmath>

using ll = long long;

int main() {
    int X, Y;
    std::cin >> X >> Y;
    std::cout << X + Y / 2 << std::endl;

    return 0;
}


Measured memory_bytes: 256
"use strict";

const main = arg => {
    // 標準入力の不要な空白と改行を削除し、配列に格納する
    const input = arg.trim().split(" ");
    const times = parseInt(input[0], 10);
    const displayR = parseInt(input[1], 10);

    const innerR = displayR + (1000 - (100 * times));

    (times >= 10) ? console.log(displayR) : console.log(innerR);
    //console.log(times, displayR, innerR);
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));  

Measured memory_bytes: 7372
#include <stdio.h>

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

int main(void) {
	int n,f,i,ans=1;
	int x[100001];
	scanf("%d %d",&n,&f);
	for(i=0;i<n;i++){
		scanf("%d",&x[i]);
		if(x[i]>f){
			x[i]=x[i]-f;
		}else{
			x[i]=f-x[i];
		}
		if(i==0){
			ans=x[i];
		}else{
			ans=gcd(x[i],ans);
		}
	}
	printf("%d",ans);
	return 0;
}


Measured memory_bytes: 512
import java.io.IOException;
import java.io.InputStream;
import java.util.*;

public class Main {
	
	public Main() {
		FastScanner scanner = new FastScanner();
		int A = scanner.nextInt();
		int B = scanner.nextInt();
		
		System.out.println(A * B);
	}
	
	public static void main(String[] args) {
		new Main();
	}
}

class FastScanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;
	
	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}
	
	private int readByte() {
		if (hasNextByte()) return buffer[ptr++];
		else return -1;
	}
	
	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}
	
	public boolean hasNext() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;
		return hasNextByte();
	}
	
	public String next() {
		if (!hasNext()) throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}
	
	public long nextLong() {
		if (!hasNext()) throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}
	
	public int nextInt() {
		long nl = nextLong();
		if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
		return (int) nl;
	}
	
	public double nextDouble() {
		return Double.parseDouble(next());
	}
}


Measured memory_bytes: 32376
#include<bits/stdc++.h>
#define ll long long 
#define ld long double
#define X first
#define Y second
#define pb push_back
#define max_el(x) max_element(x.begin(),x.end())-x.begin()
#define min_el(x) min_element(x.begin(),x.end())-x.begin()
#define mp make_pair
#define endl '\n'
#define fastread ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
// DONT USE MEMSET, USE VECTORS

void solve(){
	ll h,w;
	int n;
	cin>>h>>w>>n;
	map<pair<int,int>, int> mpp;
	for(int i=0;i<n;i++){
		int u,v;
		cin>>u>>v;

		for(int j=u-2;j<=u; j++){
			for(int k=v-2;k<=v;k++){
				if(1<=j && 1<= k && j + 2 <= h && k+2 <= w){
					mpp[{j,k}] += 1;
					// cout<<u<<" "<<v<<" contr "<<j<<" "<<k<<endl;
				}
			}
		}
	}
	vector<int> a(10);
	for(auto x: mpp){
		// cout<<x.X.X<<" "<<x.X.Y<<" "<<x.Y<<endl;
		a[x.Y] += 1;
	}
	ll a0 = (h-2)*(w-2);
	a0 -= (int)(mpp.size());
	cout<<a0<<endl;
	for(int i=1;i<=9;i++){
		cout<<a[i]<<endl;
	}

}

int main(){
	fastread;
	int t = 1;
	// cin>>t;
	for(int i=1;i<=t;i++){
		// cout<<"Case #"<<i<<": ";
		solve();
	}
	return 0;
}


Measured memory_bytes: 56576
import math


def resolve():
    a, b = map(int, input().split())

    for i in range(10000):
        t8 = math.floor(i * 0.08)
        t10 = math.floor(i * 0.1)

        if t8 == a and t10 == b:
            print(i)
            return

    print(-1)
    
resolve()


Measured memory_bytes: 2940
#include<iostream>
#include<cstdio>
using namespace std;
 
int main() {
    int n, m;
    cin >> n >> m;
 
    int b[1000] = {}, a[1000][1000] = {};
 
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            cin >> a[i][j];
        }
    }
 
    for (int j = 0; j < m; j++) {
        cin >> b[j];
    }
 
    for (int i = 0; i < n; i++) {
        int c = 0;
        for (int j = 0; j < m; j++) {
            c += a[i][j] * b[j];
        }
 
        cout << c << endl;
    }
  
}

Measured memory_bytes: 6984
import java.util.Scanner;

class Main{
	public static void main(String[] args) {
		Scanner stdIn=new Scanner(System.in);
		int w1=0,h1=0,w2=stdIn.nextInt(),h2=stdIn.nextInt(),n=stdIn.nextInt(),x,y,a,i,s;
		for(i=0;i<n;i++) {
			x=stdIn.nextInt();
			y=stdIn.nextInt();
			a=stdIn.nextInt();
			if(a==1&&x>w1) w1=x;
			if(a==2&&w2>x) w2=x;
			if(a==3&&y>h1) h1=y;
			if(a==4&&h2>y) h2=y;
		}
		System.out.print((w2-w1)*(h2-h1)>0&&w2-w1>0&&h2-h1>0?(w2-w1)*(h2-h1):0);
	}
}

Measured memory_bytes: 21332
S = input()
T = input()
N = len(S)
M = len(T)

ans = 0
for i in range(N-M+1):
  tmp = 0
  for j in range(M):
    if i + j >= N:
      break
    if S[i+j] == T[j]:
      tmp += 1
  ans = max(ans,tmp)
print(M- ans)
    

Measured memory_bytes: 9132
import java.util.Scanner;
import java.util.Arrays;
import java.util.Comparator;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt();
		P[] kk=new P[n];
		for(int i=0; i<n; i++){
			long a = sc.nextLong();
			long b = sc.nextLong();
			kk[i]=new P(a,b);
		}
		Arrays.sort(kk,Comparator.comparing(P::getB));
		long time=0;
		for(int i=0; i<n; i++){
			if(kk[i].a>kk[i].b-time){
				System.out.println("No");
				return;
			}
			time+=kk[i].a;
		}
		System.out.println("Yes");
	}
	static class P{
		long a;
		long b;
		public P(long a,long b){
			this.a=a;
			this.b=b;
		}
		public long getB(){
			return this.b;
		}
	}
}



Measured memory_bytes: 164512
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef vector<vector<int>> Matrix;


int main(){
  int x, n;
  cin >> x >> n;
  vector<bool> d(102, true);
  rep(i, n) {
    int p;
    cin >> p;
    d[p] = false;
  }
  int ans = 0;
  int sa = 100000;
  for (int i=0; i <= 101; i++) if (d[i] && abs(x - i) < sa) {
    ans = i;
    sa = abs(x - i);
  }
  cout << ans << endl;
}



Measured memory_bytes: 3556