akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import java.lang.StringBuilder;


class Main {

    class Node{
        Node prev, next;
        int value;

        Node (int value){
            this(null,null,value);
        }

        Node(Node prev, Node next, int value){
            this.prev = prev;
            this.next = next;
            this.value = value;
        }
    }

    Node head;

    Main(){
        head = new Node(-1);
        head.next = head.prev = head;
    }

    /**
     * insert an element with key x into the front of the list.
     */
    void insert(int x){
        Node newNode = new Node(head,head.next,x);
        head.next.prev = head.next= newNode;
    }

    /**
     * delete the first element which has the key of x from the list.
     * If there is not such element, you need not do anything.
     */
    void delete(int x){
        Node p = head.next;
        while(p != head){
            if (p.value == x){
                p.prev.next = p.next;
                p.next.prev = p.prev;
                break;
            }
            p = p.next;
        }
    }

    /**
     * delete the first element from the list.
     */
    void deleteFirst(){
        head.next.next.prev = head;
        head.next = head.next.next;
    }

    /**
     * delete the last element from the list.
     */
    void deleteLast(){
        head.prev.prev.next = head;
        head.prev = head.prev.prev;
    }
    void print(){
        Node p = head.next;

        StringBuilder s = new StringBuilder();
        while(p != head) {
            if (p.next == head)
                s.append(p.value);//System.out.print(p.value + "\n");
            else
                s.append(p.value).append(" ");//System.out.print(p.value + " ");
            p = p.next;
        }

        System.out.println(s);
    }


    public static void main(String[] args) throws IOException{
        //Scanner sc = new Scanner(System.in);

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



        int n = Integer.parseInt(br.readLine());
        Main DL = new Main();



        for (int i = 0; i < n; i++) {
            StringTokenizer st = new StringTokenizer(br.readLine());
            String operation = st.nextToken();
            if(operation.equals("insert")) DL.insert(Integer.parseInt(st.nextToken()));
            else if(operation.equals("delete")) DL.delete(Integer.parseInt(st.nextToken()));
            else if(operation.equals("deleteFirst")) DL.deleteFirst();
            else DL.deleteLast();
        }

        DL.print();
    }
}



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

#define rep(i, n) for(int i = 0; i < (n); ++i)
#define repr(i, n) for(int i = (n-1); i >= 0; --i)

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

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

const int MAX = 200005;
const int INF = 1001001001;
const int MOD = 1000000007;

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

    vector<int> A(N);
    rep(i, N) cin >> A[i];

    vector<vector<map<int, ll>>> dp(N+1, vector<map<int, ll>>(2));
    vector<vector<map<int, bool>>> flg(N+1, vector<map<int, bool>>(2));
    dp[0][0][0] = 0;

    rep(i, N) {
        rep(j, 2) {
            for (auto &p : dp[i][j]) {
                int k = p.first, ni = i+1, nk = k;
                rep(nj, 2) {
                    if (j && nj) continue;
                    if (nj) nk++;
                    
                    if (nk < (ni-1)/2 || (ni+1)/2 < nk) continue;

                    if (nj) {
                        if (dp[ni][nj].count(nk)) chmax(dp[ni][nj][nk], dp[i][j][k] + A[i]);
                        else dp[ni][nj][nk] = dp[i][j][k] + A[i];
                    } else {
                        if (dp[ni][nj].count(nk)) chmax(dp[ni][nj][nk], dp[i][j][k]);
                        else dp[ni][nj][nk] = dp[i][j][k];
                    }
                }
            }
        }
    }

    ll ans = max(dp[N][0][N/2], dp[N][1][N/2]);
    cout << ans << endl;
}

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

int main() {
  int N, Q;
  string S;
  
  cin >> N >> Q;
  cin >> S;
  
  int num[N];
  num[0] = 0;
  
  for(int i=1; i<N; i++) {
    if(S.substr(i-1,2) == "AC") {
      num[i] = num[i-1] + 1;
    } else {
      num[i] = num[i-1];
    }
  }
  
  int L, R;
  for(int i=0; i<Q; i++) {
    cin >> L >> R;
    cout << num[R-1] - num[L-1] << endl;
  }
  
  return 0;
}

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

int main() {
	int n;
	int a;
	int max = 0;
	long long min = 10000000000000;

	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a;
		if (min > a) {
			min = a;
		}
		if (max < a) {
			swap(max, a);
		}
	}
	cout << max - min << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
int* countingSort(int* a, int n, int max)
{
    int* c = (int*)malloc(max * sizeof(int));
    //init
    for (int i = 0; i < max; i++) {
	c[i] = 0;
    }
    //count up
    for (int i = 0; i < n; i++) {
	c[a[i]]++;
    }
    //sum
    for (int i = 1; i < max; i++) {
	c[i] += c[i - 1];
    }
    int* sorted = (int*)malloc((n + 1) * sizeof(int));
    for (int i = n - 1; i >= 0; i--) {
	int index = c[a[i]];
	sorted[index] = a[i];
	c[a[i]]--;
    }
    return sorted;
}
int main()
{
    int n = 0;
    std::cin >> n;
    int* a = (int*)malloc(n * sizeof(int));
    int max = 0;
    int min = 10000;
    for (int i = 0; i < n; i++) {
	std::cin >> a[i];
	if (a[i] > max) {
	    max = a[i];
	}
	if (a[i] < min) {
	    min = a[i];
	}
    }
    int* sorted = countingSort(a, n, max + 1);
    for (int i = 1; i < n + 1; i++) {
	std::cout << sorted[i];
	if (i < n) {
	    std::cout << " ";
	}
    }
    std::cout << std::endl;

    return 0;
}

Measured memory_bytes: 18748
S = list(input())

#白から
cnt1 = 0
for i, s in enumerate(S):
    if i % 2 == 0:
        if s != '0':
            cnt1 += 1
    else:
        if s != '1':
            cnt1 += 1

#黑から
cnt2 = 0
for i, s in enumerate(S):
    if i % 2 == 0:
        if s != '1':
            cnt2 += 1
    else:
        if s != '0':
            cnt2 += 1

print(min(cnt1,cnt2))



Measured memory_bytes: 9852
a,b,c=map(int,input().split())
K=int(input())
flag=False
for i in range(10):
    for j in range(10):
        for k in range(10):
            if i+j+k<=K and 2**i*a<2**j*b<2**k*c:
                flag=True
if flag:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 9156
n, t = map(int, input().split())
li = []
for i in range(0, n):
    li.append(list(map(int,input().split())))

cost = 1001

for i in li:
    if t >= i[1]:
        if cost > i[0]:
            cost = i[0]

if cost == 1001:
    print('TLE')
else:
    print(cost)


Measured memory_bytes: 3060
#include "bits/stdc++.h"
using namespace std;

#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()
#define dump(o) if(DEBUG){cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) if(DEBUG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
using ll = long long; using ull = unsigned long long; using pii = pair<int, int>;
static const int INF = 0x3f3f3f3f; static const long long INFL = 0x3f3f3f3f3f3f3f3fLL;
static const int MOD = 1e9 + 7;
static const bool DEBUG = false;

signed main() {
	int W, H; cin >> W >> H;
	vector<pii> a(W + H);
	vector<int> p(W), q(H);
	rep(i, 0, W) {
		cin >> p[i];
		a[i] = pii(p[i], 1);
	}
	rep(i, 0, H) {
		cin >> q[i];
		a[i + W] = pii(q[i], 2);
	}
	sort(all(a));


	int ans = 0;
	int WW = H + 1, HH = W + 1;
	rep(i, 0, W + H) {
		if (a[i].second == 1) {
			ans += WW*a[i].first; HH--;
		}
		else {
			ans += HH*a[i].first; WW--;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 4992
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author cherrypi59
 */

#pragma GCC optimize ("O2")
#pragma GCC optimize ("tree-vectorize")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define FFOR(i, a, b) FOR(i, a, b+1)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) FOR(i, 1, n+1)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define LEN(x) (int)(x).size()
#define DUMP(x) cerr<<__LINE__<<' '<<#x<<"="<<(x)<<endl;
#define popcnt(x) __builtin_popcount(x)
#define popcntll(x) __builtin_popcountll(x)
#define pb push_back
#define eb emplace_back
#define mp make_pair

using namespace std;
using lint = long long;
using pii =  pair<int, int>;
using pll =  pair<lint, lint>;
template <typename T> using vc = vector<T>;
template <typename T> using vvc = vector<vector<T>>;
template <typename T> inline bool chmax(T &a, T b){if(a<b){a = b; return true;} return false;}
template <typename T> inline bool chmin(T &a, T b){if(a>b){a = b; return true;} return false;}

constexpr lint ten(int n) {return n==0 ? 1 : ten(n-1)*10;}

class BGraphPartition {
public:
    void solve(std::istream& in, std::ostream& out){
        ios_base::sync_with_stdio(false);
        in.tie(nullptr), out.tie(nullptr);
        int N;
        in>>N;
        vvc<int> G(N);
        REP(i, N){
            string s;
            in>>s;
            REP(j, N){
                if(s[j]=='1') G[i].pb(j);
            }
        }
        auto bfs = [&](int s){
            vc<int> dist(N, -1);
            dist[s] = 0;
            queue<int> que;
            que.emplace(s);
            while(not que.empty()){
                int u = que.front();
                que.pop();
                for(auto& v : G[u]){
                    if(dist[v]==dist[u]) return -1;
                    else if(dist[v]!=-1) continue;
                    dist[v] = dist[u] + 1;
                    que.emplace(v);
                }
            }
            return *max_element(ALL(dist)) + 1;
        };
        int ans = -1;
        REP(i, N){
            chmax(ans, bfs(i));
        }
        out<<ans<<'\n';
    }
};


int main() {
	BGraphPartition solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


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

int main(void)
{
    int n, x, t, count;
    count = 0;
    cin >> n >> x >> t;
    while (n > x * count)
    {
        count++;
    }
    cout << t * count << endl;

    return 0;
}

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

typedef long long ll;

const int Maxd = 10;
const int Maxm = 200005;

int m;
int cur;
ll res;
int id[Maxd];
int cost[Maxd];

void Solve(int d, ll c)
{
    if (c <= Maxd)
        for (int i = 0; i < c; i++) {
            res++; cur += d;
            if (cur >= Maxd) { res++; cur -= 9; }
        }
    else {
        fill(id, id + Maxd, -1);
        int curid = 0, curcost = 0;
        while (id[cur] == -1) {
            id[cur] = curid; cost[cur] = curcost;
            res++; curcost++;
            cur += d;
            if (cur >= Maxd) { res++; curcost++; cur -= 9; }
            c--; curid++;
        }
        ll tot = c / (curid - id[cur]);
        res += tot * ll(curcost - cost[cur]);
        c %= (curid - id[cur]);
        for (int i = 0; i < c; i++) {
            res++; cur += d;
            if (cur >= Maxd) { res++; cur -= 9; }
        }
    }
}

int main()
{
    cur = 0;
    scanf("%d", &m);
    for (int i = 0; i < m; i++) {
        int d; ll c; scanf("%d %lld", &d, &c);
        Solve(d, c);
    }
    res--;
    printf("%lld\n", res);
    return 0;
}


Measured memory_bytes: 384
n, m, c = map(int, input().split())
l = [list(map(int, input().split())) for i in range(n+1)]
count = 0
for i in range(1, n+1):
    s = 0
    for j in range(m):
        s += l[i][j] * l[0][j]
    if s + c > 0:
        count += 1
print(count)

Measured memory_bytes: 3064
// Library
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

// TYPEDEFS
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pi;

// CONSTANTS
#define SZA 0
#define SZB 0

// MACRO
#define MAX(X, Y) (((X) > (Y))? (X) : (Y))
#define MIN(X, Y) (((X) < (Y))? (X) : (Y))
#define ABS(X) (((X) > 0)? (X) : -(X))
#define YN(X) ((X)? "Yes" : "No")
#define SWAP(T, X, Y) {T t; t = X; X = Y; Y = t;}

#define F first
#define S second
#define PB push_back
#define MP make_pair


// Global Tables

//ull gPreProcess[SZA][SZB];

// Functions

void Print2DVector(vector<vector<int>>& v)
{
    ull i, j; 
    for(i = 0; i < v.size(); i++)
    {
        for(j = 0; j < v[i].size(); j++)
        {
            cout << v[i][j];
            if(j == v[i].size()-1)
            {
                cout << endl;
            }
            else
            {
                cout << " ";
            }
        }
    }
}

void PrintVector(vi& v)
{
    ull i;
    for(i = 0; i < v.size(); i++)
    {
        cout << v[i];
        if(i == v.size()-1)
        {
            cout << endl;
        }
        else
        {
            cout << " ";
        }
    }
}

void PrintArr(int* a, ull N)
{
    ull i;
    for(i = 0; i < N; i++)
    {
        cout << a[i];
        if(i == N-1)
        {
            cout << endl;
        }
        else
        {
            cout << " ";
        }
    }
}

void PreProcessTables()
{
    ull i, j;
    for(i = 0; i < SZA; i++)
    {
        for(j = 0; j < SZB; j++)
        {
            break;
        }
        break;
    }
}

void TC(int t)
{
    const unsigned long long mod = 1E9+7;
    int N;
    cin >> N;
    unsigned long long A[N];
    unsigned long long sum1 = 0, sum2 = 0, out = 0, inv = (mod+1)/2;
    for(int i = 0; i < N; i++)
    {
        cin >> A[i];
        sum1 += A[i];
        sum1 %= mod;
        sum2 += (A[i]*A[i])%mod;
        sum2 %= mod;
    }
    sum1 = (sum1*sum1)%mod;
    out = (inv*((mod + sum1 - sum2)%mod))%mod;
    cout << out << endl;
}   

// Main

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

    int T = 1, t;
    for(t = 1; t <= T; t++)
    {
        TC(t);
    }
    return 0;
}


Measured memory_bytes: 5112
#include <stdio.h>
#include <math.h>
int main(){
	int a,b,h,m,c,d,t;
	double e,ans;
	scanf("%d%d%d%d",&a,&b,&h,&m);
	c=60*h+m,d=12*m;
	if(c<d)t=c,c=d,d=t;
	e=(c-d)*2*M_PI/720;
	ans=sqrt(a*a+b*b-2*a*b*cos(e));
	printf("%.12lf\n",ans);
	return 0;
}

Measured memory_bytes: 3616
#include <iostream>

using namespace std;

int grid[501][501];

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

    for (int i = 0; i <= N; i++)
        for (int j = 0; j <= N; j++)
        {
            grid[i][j] = 0;
        }

    for (int i = 0; i < M; i++)
    {
        int l, r;
        cin >> l >> r;
        grid[l][r]++;
    }

    for (int i = 1; i <= N; i++)
        for (int j = 1; j <= N; j++)
        {
            grid[i][j] += grid[i - 1][j] + grid[i][j - 1] - grid[i - 1][j - 1];
        }

    for (int i = 0; i < Q; i++)
    {
        int p, q;
        cin >> p >> q;

        int result = grid[q][q] - grid[q][p - 1] - grid[p - 1][q] + grid[p - 1][p - 1];
        cout << result << endl;
    }
    return 0;
}

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


int main(){
  int sx, sy, tx, ty;
  int ansa = 0, ansb = 0;

  cin>>sx>>sy>>tx>>ty;
  	
  ansb = ty - sy;
  ansa = tx - sx;

  for(int i = 1; i <= ansa; i++){
    cout<<'R';
    //maze[sy][sx+i]=1;
  }
  for(int j =1; j <= ansb; j++){
    cout<<'U';
    //maze[sy+j][sx]=1;
  }



   for(int i = 1; i <= ansa; i++){
    cout<<'L';
    //maze[ty][tx-i]=1;
  }
  for(int j =1; j <= ansb; j++){
    cout<<'D';
    //maze[ty-j][tx]=1;
  }


  cout<<'D';

  for(int i = 1; i <= ansa+1; i++){
    cout<<'R';
      
  }
  for(int j =1; j <= ansb+1; j++){
    cout<<'U';
  }
  cout<<'L';
  
  cout<<'U';
  
   for(int i = 1; i <= ansa+1; i++){
    cout<<'L';
    // maze[ty][tx-i]=1;
  }
  for(int j =1; j <= ansb+1; j++){
    cout<<'D';
    //maze[ty-j][tx]=1;
  }
  cout<<'R';
  cout<<endl;


  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <iomanip>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define int long long
#define INF 1e9 + 7
#define cae cout << ans << endl;
#define cye cout << "Yes" << endl;
#define cne cout << "No" << endl;
#define r0 return 0;
using namespace std;
typedef pair<int,int>P;
typedef long long ll;
signed main() {
    float l;
    cin >> l;
    float d = l / 3;
    cout << setprecision(15) << pow(d, 3) << endl;
    r0
}


Measured memory_bytes: 256
S = input()
S1 = S[::2]
S2 = S[1::2]
f = 1
for i in S1:
    if i in ['R', 'U', 'D']:
        f *= 1
    else:
        f *= 0
        
for i in S2:
    if i in ['L', 'U', 'D']:
        f *= 1
    else:
        f *= 0
if f:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3060
use std::io::*;
use std::cmp;

fn read<T: std::str::FromStr>() -> T {
    let stdin = stdin();
    let mut buf = String::new();
	stdin.lock().read_line(&mut buf);
	buf.trim().parse().ok().unwrap()
}

fn main() {
    let n = read::<usize>();
    let max = usize::max_value();
    let mut v: Vec<usize> = vec![max;n+1];
    v[0] = 0;
    for i in 0..n {
        if v[i] + 1 < v[i+1] {
            v[i+1] = v[i] + 1;
        }
        let mut j = 6;
        while i + j <= n {
            v[i+j] = cmp::min(v[i+j],v[i]+1);
            j *= 6;
        }
        j = 9;
        while i + j <= n {
            v[i+j] = cmp::min(v[i+j],v[i]+1);
            j *= 9;
        }
    }
    println!("{}",v[n]);
}


Measured memory_bytes: 4352
#include <iostream>
#include <vector>
#include <string>
#include <stdlib.h>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <climits>
#include <iomanip>
#include <deque>

using namespace std;

using Position = pair<int, int>;

int main()
{
  int L;

  cin >> L;

  cout << fixed << setprecision(8)
       << pow(L, 3) / 27.0
       << endl;

  return 0;
}


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

int main() {
  int n; cin >> n;
  int count, ans = 0;
  for(int i = 1; i <= n; i+=2){
    count = 0;
    for(int j = 1; j <= n; j++){
      if(i % j == 0) count++;
    }
    if(count == 8 ) ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define pi (double) acos(-1)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
using namespace std;

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n)cin >> a.at(i);
    sort(all(a));
    cout << a.at(n-1)-a.at(0);
}  

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
using namespace std;
int arr[100005];
int dp[100005];
int n;

int calc(int ind,int n){
    if(ind==n-1)
        return 0;
    if(ind>=n)
        return INT_MAX;
    if(dp[ind]!=-1)
        return dp[ind];
    int left = abs(arr[ind]-arr[ind+1]) + calc(ind+1,n);
    int right = INT_MAX;
    if(ind+2<n) right = abs(arr[ind]-arr[ind+2]) + calc(ind+2,n);
    dp[ind] = min(left,right);
    return dp[ind];
}
signed main()
{
    cin>>n;
    memset(dp,-1,sizeof(dp));
    for(int i=0;i<n;i++)
        cin>>arr[i];
    cout<<calc(0,n)<<endl;
    return 0;
}


Measured memory_bytes: 6656
fn main() {
    let s = std::io::stdin();
    let mut sc = Scanner { stdin: s.lock() };
    let n: usize = sc.read();
    let l: usize = sc.read();
    let t: usize = sc.read();
    let xw: Vec<(usize, usize)> = (0..n).map(|_| (sc.read(), sc.read())).collect();

    let mut clockwise = 0;
    let mut counter_clock_wise = 0;
    for (x, w) in xw.iter().cloned() {
        if w == 1 {
            clockwise += (x + t) / l;
        } else if t > x {
            counter_clock_wise += ((l - x) + t - 1) / l;
        }
    }

    let mut next = xw
        .into_iter()
        .map(|(x, w)| {
            if w == 1 {
                (x + t) % l
            } else {
                (l - ((l - x) + t) % l) % l
            }
        })
        .collect::<Vec<_>>();
    next.sort();
    let over = clockwise % n + n - counter_clock_wise % n;
    for i in 0..n {
        println!("{}", next[(i + over) % n]);
    }
}

pub struct Scanner<R> {
    stdin: R,
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 7164
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
class triangle{
public:
    int position[3];
};
bool compare(triangle &a,triangle &b){
    for(int i=0;i<3;++i){
        if(a.position[i]<b.position[i]){
            return true;
        }else if (a.position[i]>b.position[i]){
            return false;
        }
    }
    return false;
}
void input(vector<triangle> &line){
    int num;
    cin>>num;
    line.resize(num);
    for(int i=0;i<num;++i){
        for(int j=0;j<3;++j){
            cin>>line[i].position[j];
        }
        sort(line[i].position,line[i].position+3);
    }
    sort(line.begin(),line.end(),compare);
}
int func(vector<triangle> &line){
    int res = 0;
    for(int i=1;i<line.size();++i){
        bool flag=true;
        for(int j=0;j<3;++j){
            if(line[i-1].position[j]!=line[i].position[j]){
                flag=false;
                break;
            }
        }
        if(flag) {
            ++res;
        }
    }
    return res;
}
int main(){
    vector<triangle> line;
    input(line);
    cout<<func(line)<<endl;
    return 0;
}

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

#define REP(i, m, n) for (int i = (m); i < (int)(n); i++)
#define REPS(i, m, n) for (int i = (m); i <= (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define reps(i, n) for (int i = 0; i <= (int)(n); i++)
#define rrep(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define rreps(i, x) for (int i = (int)(x); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
typedef long long ll;
typedef pair<int, int> P;
const int inf = INT_MAX;
const ll INF = 1LL << 60;
const ll mod = 1e9 + 7;
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; }
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val) { fill( (T*)array, (T*)(array+N), val ); }

int dp[50][500][500];
int a[50], b[50], c[50];
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);

    int N, Ma, Mb; cin >> N >> Ma >> Mb;
    rep(i, N) cin >> a[i] >> b[i] >> c[i];

    Fill(dp, inf);
    dp[0][0][0] = 0;
    rep(i, N) rep(j, 500) rep(k, 500) {
        if (inf == dp[i][j][k]) continue;
        chmin(dp[i+1][j+a[i]][k+b[i]], dp[i][j][k] + c[i]);
        chmin(dp[i+1][j][k], dp[i][j][k]);
    }
    int res = inf;
    REP(j, 1, 500) REP(k, 1, 500) if(k * Ma == j * Mb) chmin(res, dp[N][j][k]);
    if (res == inf) res = -1;
    cout << res << endl;
}

Measured memory_bytes: 49152
n,m = map(int, input().split())
b = 0
ue = sita = n
flag = 0

l = list(map(int, input().split()))

while b == 0:
    for i in l:
        if(ue == i):
            flag = 1
            break
            
    if(flag == 0):
        b = 1
        break
        
    flag = 0
    ue += 1
    
b = 0
flag = 0

while b == 0:
    for i in l:
        if(sita == i):
            flag = 1
            break
            
    if(flag == 0):
        b = 1
        break
        
    flag = 0
    sita -= 1
    
##print(ue)
##print(sita)
##print(n)    
    
if(ue-n > n-sita or ue-n == n-sita):
    print(sita)
else:
    print(ue)

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

int main(){
  ll N, M; cin>>N>>M;
  map<ll, ll> X;
  map<ll, ll> Y;
  for(int i=0; i<M; i++){
    ll A, B; cin>>A>>B;
    if(A==1) X[B]=1;
    if(B==N) Y[A]=1;
  }
  bool ikeru=0;
  for(auto p:X){
    auto k=p.first;
    if(Y.count(k)) ikeru=1; 
  }
  if(ikeru) cout<<"POSSIBLE"<<endl;
  else cout<<"IMPOSSIBLE"<<endl;
}


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

using namespace std;

typedef long long LL;

int main() {
    int n;
    scanf("%d", &n);
    LL ans = 0;
    int last = 0;
    for (int i = 0; i < n; i++) {
        int a;
        scanf("%d", &a);

        if (last) {
            if (a > 1) {
                ans++;
                a--;
                last = 0;
            }
        }

        ans += a/2;
        a &= 1;

        if (last && a) {
            last = 0;
            ans++;
        }
        else last = a;
    }
    printf("%lld", ans);
    return 0;
}


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

const int CardsNum = 100;

int main(){

    int N,Field;
    string Cards;

    while(1){

      cin >> N;

      if(N==0){
        break;
      }

      Field = 0;

      int Hands[N];

      for(int i=0; i<N; i++){
        Hands[i] = 0;
      }

      cin >> Cards;

      for(int i=0; i<CardsNum; i++){
          if(Cards[i] == 'S'){
            Field += Hands[i%N] + 1;
            Hands[i%N] = 0;
          }
          else if(Cards[i] == 'L'){
            Hands[i%N] += Field + 1;
            Field = 0;
          }
          else{
            Hands[i%N] += 1;
          }

      }

      for(int i=0; i<N; i++){
        for(int j=i; j<N; j++){
          if(Hands[i] > Hands[j]){
            swap(Hands[i],Hands[j]);
          }
        }
      }

      for(int i=0; i<N; i++){
        cout  << Hands[i] << ' ';
      }

      cout << Field << endl;

    }

    return 0;
}

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

#define int         long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define sz(x)       (int)x.size()
#define endl        "\n"
#define repp(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a,b) 	for(int i=a;i<=b;i++)
#define IOS         ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);

const int N=2005;
const int M=1e9 + 7;

pair<int,int> a[N];
int n;
int dp[N][N];

int solve(int idx,int i,int j)
{
	if(idx>n)
		return 0;
	if(dp[idx][i]!=-1)
		return dp[idx][i];
	int ans = a[idx].first*(abs(a[idx].second-i)) + solve(idx+1,i+1,j);
	ans = max(ans, a[idx].first*(abs(a[idx].second-j)) + solve(idx+1,i,j-1));
	return dp[idx][i] = ans;
}

int32_t main()
{
	IOS;
	memset(dp,-1,sizeof(dp));	
	cin >> n;
	rep(i,1,n)
	{
		cin >> a[i].first;
		a[i].second = i;	
	}	
	sort(a+1,a+n+1);
	reverse(a+1,a+n+1);
	cout << solve(1,1,n) << endl;
}


Measured memory_bytes: 35220
package main

import (
	"fmt"
)

func main() {
	var S string
	fmt.Scan(&S)
	if S[0] == 82 && S[1] == 82 && S[2] == 82 {
		fmt.Println(3)
	} else if S[0] == 82 && S[1] == 82 && S[2] != 82 {
		fmt.Println(2)
	} else if S[0] != 82 && S[1] == 82 && S[2] == 82 {
		fmt.Println(2)
	} else if S[0] == 82 || S[1] == 82 || S[2] == 82 {
		fmt.Println(1)
	} else {
		fmt.Println(0)
	}
}


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

int main() {
  int x, y, t;

  cin >> x;

  y = x;
  while (y != 0) {
    t += y % 10;
    y /= 10;
  }
  
  if (x % t == 0) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  
  return 0;
}


Measured memory_bytes: 256
while true
    n = gets.to_i
    break if n == 0
    arr = []
    n.times{
        line = gets.chomp.split.map(&:to_i)
        arr << [line[0], [[line[1], 0], [line[2], 1], [line[3], 2], [line[1] * 4 + line[2] * 9 + line[3] * 4, 3]]]
    }
    limit = gets.chomp.split.map(&:to_i)
    result = []
    arr.each{|name, info| result << name if info.all?{|x, i| x <= limit[i]}}
    puts result.empty? ? "NA" : result
end


Measured memory_bytes: 7396
N = int(input())
Ss = [0] * N
Ps = [0] * N
cities = [0] * N
for i in range(N):
    l = input().split()
    Ss[i], Ps[i] = l[0], int(l[1])
    cities[i] = Ss[i]

cities = sorted(set(cities))

cities_dir = {}
for city in cities:
    cities_dir[city] = []

for i in range(N):
    cities_dir[Ss[i]].append((Ps[i], i))

for city in cities:
    vs = sorted(cities_dir[city], key=lambda x: x[0], reverse=True)
    for k in vs:
        print(k[1] + 1)

Measured memory_bytes: 3064
#include <stdio.h>
#include <math.h>
int main(void){
	int tab[10][400],a[10]={0,1,2,3,4,5,6,7,8,9},b[10]={0,0,0,0,0,0,0,0,0,0},sw[10]={1,1,1,1,1,1,1,1,1,1},sum,i,j,k,n,s;
	for(i=0;i<10;i++){for(j=0;j<400;j++){tab[i][j]=0;}}
	while(1){
		sum=0;
		for(i=0;i<10;i++){
			sum+=a[i]*(i+1);
			if(sw[i]==1){tab[i][sum]++;sw[i]=0;}
		}
		sw[9]=1;b[a[9]]=1;
		for(n=8;n>=0;n--){
			sw[n]=1;b[a[n]]=1;
			if(a[n]<a[n+1])break;
		}
		if(n<0)break;
		for(i=a[n]+1;i<10;i++){if(b[i]==1){a[n]=i;b[i]=0;break;}}
		for(i=0,n++;i<10&&n<10;i++){
			if(b[i]==1){a[n]=i;b[i]=0;n++;}
		}
	}
	while(scanf("%d %d",&n,&s)!=EOF){if(s>350)printf("0\n");else printf("%d\n",tab[n-1][s]);}
	return 0;
}

Measured memory_bytes: 628
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7/*998244353*/;
const ll INF = 1LL << 60;
ll mod_pow(ll, ll, ll); ll mod_fact(ll, ll); ll mod_inv(ll, ll); ll gcd(ll, ll); ll lcm(ll, ll);
//
int main(){
    int n;
    cin >> n;
    int cnt = 0;
    for(int i = 0; i <= n; i++){
        if(i == 105 || i == 135 || i == 165 || i == 189 || i == 195)cnt++;
    }
    cout << cnt;
}

Measured memory_bytes: 256
#include <vector>
#include <map>
#include <set>
#include <cmath>
#include <iostream>
#include <algorithm>

typedef char                SINT8;
typedef unsigned char       UINT8;
typedef short               SINT16;
typedef unsigned short      UINT16;
typedef int                 SINT32;
typedef unsigned int        UINT32;
typedef long long           SINT64;
typedef unsigned long long  UINT64;
typedef double              DOUBLE;

#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ABS(a) ((a)>(0)?(a):-(a))
#define rep(i,a,b) for(int (i)=int(a);(i)<int(b);(i)++)

#define INF = 1e9;
#define MOD = 1e9+7;
#define INF64 = 1e18;


using namespace std;

int main() {

	SINT32 N = 0;
	cin >> N;
	SINT32 ANS = 1;
	
	rep(i,2,N) {
		SINT32 j = 2;
		while (pow(i,j) <= N) {
			ANS = MAX(ANS,pow(i,j));
			j++;
		}
	}

	cout << ANS << endl;
	return 0;
}

//	sort(DATA.begin(),DATA.end());
//	sort(DATA.begin(),DATA.end(),std::greater<SINT32>());
//	__gcd(ANS,DATA[i]);

//	// DATA.emplace_back(BUF);	//後ろに追加

//  DATA.erase(std::unique(DATA.begin(), DATA.end()), DATA.end());

//	DATA.insert(DATA.begin() + X, 0);	//X番目の要素に0を挿入


//	vector<vector<SINT32>> DP(N,vector<SINT32>(3));　//2次元配列

/*
	SINT32 M = 3;
	vector<pair<SINT32,SINT32>> DATA2(M);
	for (SINT32 i = 0; i < M; i++) {
		cin >> DATA2[i].first;
		cin >> DATA2[i].second;
	}
	sort(DATA2.begin(),DATA2.end());
	cout << DATA2[0].first << endl;
	cout << DATA2[0].second << endl;
*/

// 	vector<pair<int,pair<int,int>>> DATA(M);
//	cin >> DATA[i].first;
//	cin >> DATA[i].second.first;
//	cin >> DATA[i].second.second;


//		APOSI = lower_bound(ADATA.begin(),ADATA.end(),QDATA[i]) - ADATA.begin();
//		BPOSI = lower_bound(BDATA.begin(),BDATA.end(),QDATA[i]) - BDATA.begin();


/* 文字列回転
	string N;
	cin >> N;
	N = N[N.length()-1] + N.substr(0,N.length()-1);
*/

/* SET コンテナ
	set<SINT32> DATA;
	for (SINT32 i = 0; i < N; i++) {
		SINT32 buf;
		cin >> buf;
		DATA.insert(buf);
	}
*/

/* map
	map<string,SINT32> mp;
	SINT32 N = 0;
	SINT32 mx = 0;

	cin >> N;
	for (SINT32 i = 0; i < N; i++) {
		string s;
		cin >> s;
		mp[s]++;
	}
	for(auto it=mp.begin();it!=mp.end();it++) {
		mx=max(mx,it->second);
	}

*/


Measured memory_bytes: 512
n, l = map(int, input().split())
eat = []
ans = 0
for i in range(n):
  eat.append(l + i)
good = []
for i in eat:
  good.append(abs(i))
if n + l > 0:
  print(sum(eat)-min(good))
else:
  print(sum(eat)+min(good))

Measured memory_bytes: 3188
//K-OS WITH THE OCDE

#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <stack>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <deque>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <climits>

using namespace std;

typedef long long int ll;
typedef long double db;


#define TEST ll t; cin>>t; while(t--)
#define vell vector<ll>
#define pl pair<ll,ll>
#define all(v) v.begin(),v.end()
#define pb push_back
#define ff first
#define ss second
#define mp make_pair
#define dbg(x)  cerr << #x << ": "<< x <<endl
#define dbg2(x,y) cerr<< #x <<": "<< x <<" || "<< #y << ": " << y << endl

#define endl "\n"
#define MAX 1e18
#define MIN INT_MIN
#define mod 1000000007



void solve()
{
	ll n;
	cin >> n;
	ll a[8] = {400 , 600 , 800 , 1000 , 1200 , 1400 , 1600 , 1800};

	ll it = lower_bound(a, a + 8LL , n) - a;

	ll ans = 9 - it;

	if(it < 8 && a[it] == n)
		ans--;
	cout << ans;


}

int main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(0); cin.tie(0);
	//TEST
	solve();
}



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

using namespace std;

int main() {
	int A[10000], B[10000];
	string s[10000];

	for (int i = 0; i < 9999; i++) {
		cin >> A[i] >> s[i] >> B[i];
	}

	for (int i = 0; i < 9999; i++) {
		if (s[i] == "+") {
			cout << A[i] + B[i] << endl;
		}
		else if (s[i] == "-") {
			cout << A[i] - B[i] << endl;
		}
		else if (s[i] == "*") {
			cout << A[i] * B[i] << endl;
		}
		else if (s[i] == "/") {
			cout << A[i] / B[i] << endl;
		}
		else {
			break;
		}
	}

	return 0;
}


Measured memory_bytes: 3240
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <string.h>
#include <string>
#include <vector>
#include <limits.h>
#define maxn 10000000
#define pi acos(-1)
using namespace std;
signed int maxx=-1e9;
double aabs(double x)
{
	if(x<0)return -x;
	return x;
}
int gcd(int a,int b)
{
	if(a%b==0)return b;
	return gcd(b,a%b);
}
int main(){
	int n,x,minn=INT_MAX,maxx=INT_MIN;
	cin>>n;
	for(int i = 1; i <= n; i++)
	{
		cin>>x;
		if(maxx < x-minn) maxx = x - minn;
		if(minn > x) minn = x;
	}
	cout<<maxx<<endl;
	return 0;
}



Measured memory_bytes: 3116
import java.math.*

fun main(args: Array<String>) {
    val (N, A) = readInputLine().split(" ").map { it.toInt() }
    val xs = readInputLine().split(" ").map { it.toInt() - A }
    
    val dp = Array(N + 1, { LongArray(50 * N) })
    
    dp[0][(A - 1) * N] = 1L
    
    for ((i, x) in xs.withIndex()) {
        for (j in 0 until 50 * N) {
            dp[i + 1][j] = dp[i][j]
        }
        for (j in Math.max(0, -x) until Math.min(50 * N, 50 * N - x)) {
            dp[i + 1][j + x] += dp[i][j]
        }
    }
    
    println(dp[N][(A - 1) * N] - 1L)
}

fun readInputLine(): String {
    return readLine()!!
}


Measured memory_bytes: 42324
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int a,b;
int main(void){
    cin>>a>>b;
    if(b==100)b++;
    if(a==0)cout<<b<<endl;
    else if(a==1)cout<<b*100<<endl;
    else cout<<b*10000<<endl;
    
}


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

#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
#define ALL(x) (x).begin(), (x).end()

using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 1e15;

int main() {
  string s;
  cin >> s;
  ll n = s.length();
  string ans = string(n, 'x');
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
class Program{
	static void Main(){
		int[] s=Array.ConvertAll(Console.ReadLine().Split(),int.Parse);
		int[] h=Array.ConvertAll(Console.ReadLine().Split(),int.Parse);
		long[] dp=new long[s[0]];
		dp[1]=Math.Abs(h[0]-h[1]);
		for(int i=2;i<s[0];i++){
			dp[i]=long.MaxValue;
			for(int j=i-1;j>=i-s[1]&&j>=0;j--){
				dp[i]=Math.Min(dp[i],Math.Abs(h[i]-h[j])+dp[j]);
			}
		}
		Console.WriteLine("{0}",dp[s[0]-1]);
	}
}

Measured memory_bytes: 19680
import java.util.Scanner;
 
class Main {
    Scanner sc = new Scanner(System.in);
 
    public void run() {
        String str=sc.nextLine();
         
        char[] c=str.toCharArray();
        for(int i=0;i<c.length;i++){
            if('a'<=c[i] &&c[i]<='z'){
                c[i]=(char)(c[i]-'a'+'A');
            }else if('A'<=c[i] &&c[i]<='Z'){
                c[i]=(char)(c[i]-'A'+'a');
            }
        }
        ln(String.copyValueOf(c));
    }
    public static void main(String[] args) {
        new Main().run();
    }
 
    public static void pr(Object o) {
        System.out.print(o);
    }
 
    public static void ln(Object o) {
        System.out.println(o);
    }
 
    public static void ln() {
        System.out.println();
    }
}


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

#ifdef DEBUG
#define PRINT(x)\
    cout<<"func "<<__func__<<": line "<<__LINE__<<": "<<#x<<" = "<<(x)<<endl;
#define PRINTA(a,first,last)\
    cout<<"func "<<__func__<<": line "<<__LINE__<<": "<<#a<<"["<<(first)<<", "<<(last)<<")"<<endl;\
    for (int i=(first);i<(last);++i){cout<<#a<<"["<<i<<"] = "<<(a)[i]<<endl;}
#else
#define PRINT(x)
#define PRINTA(a,first,last)
#endif

#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 pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define MOD 1000000007

using namespace std;

using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;

template <class T, class U> void amax(T& x, U y) {if (x < y) x = y;}
template <class T, class U> void amin(T& x, U y) {if (x > y) x = y;}

int main(void)
{
    int a[3];
    int b[3];
    REP(i, 3) {
        cin >> a[i] >> b[i];
    }
    bool result = true;
    for (int i = 1; i <= 4; i++) {
        bool flag = true;
        REP(j, 3) {
            if (a[j] != i && b[j] != i) {
                flag = false;
                break;
            }
        }
        if (flag) {
            result = false;
            break;
        }
    }
    if (result) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
    


    return 0;
}



Measured memory_bytes: 256
A, B = map(int, input().split())
sisi = [min((A+1)*12.5 ,  (B+1)*10), max(A*12.5, B*10)]
sisi = [i-0.1 if i == int(i) else i for i in sisi]
print

if sisi[0] < sisi[1]:
    ans = -1
elif int(sisi[0]) == int(sisi[1]):
    ans = -1
else:
    ans = int(sisi[1]) +1

print(ans)


Measured memory_bytes: 3064
INT = lambda: int(input())
INTM = lambda: map(int,input().split())
STRM = lambda: map(str,input().split())
STR = lambda: str(input())
LIST = lambda: list(map(int,input().split()))
LISTS = lambda: list(map(str,input().split()))
def do():
    a,b,c,d=INTM()
    if (a+b)>(c+d):
        print('Left')
    elif (a+b)==(c+d):
        print('Balanced')
    else:
        print('Right')
if __name__ == '__main__':
    do()

Measured memory_bytes: 3064
import sys
sys.setrecursionlimit(10 ** 9)
input = sys.stdin.readline
from itertools import permutations,  combinations, accumulate
from functools import *
from collections import deque, defaultdict, Counter
from heapq import heapify, heappop, heappush, heappushpop

INF = float('inf')
NIL = - 1


N, M = map(int, input().split())
jobs = [[] for _ in range(M + 1)]
for _ in range(N):
    a, b = map(int, input().split())
    if a <= M:
        jobs[M - a].append(b)

heap = []
for day in range(M + 1):
    for job in jobs[day]:
        if len(heap) <= day:
            heappush(heap, job)
        else:
            heappush(heap, job)
            heappop(heap)

print(sum(heap))


Measured memory_bytes: 62652
module ArrayRefinement
  refine Array do
    # 配列に対する最小公倍数
    def lcm
      self.inject(:lcm)
    end

    # 配列に対する最大公約数
    def gcd
      self.inject(:gcd)
    end
  end
end

using ArrayRefinement

def main

  n, x = gets.split.map(&:to_i)

  nums = gets.split.map do |s|
    i = s.to_i
    i - x
  end

  puts nums.gcd.abs
end

if __FILE__ == $0
  main
end


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

using namespace std;

int main() {
  int N, M, K;
  cin >> N >> M >> K;
  bool flag = false;
  if (K % N == 0 || K % M == 0) {
    flag = true;
  } else {
    for (int i = 1; i < N; i++) {
      for (int j = 1; j < M; j++) {
        // cout << i << "," << j << ":" << M * i + N * j - (2 * i * j) << endl;
        if (M * i + N * j - (2 * i * j) == K) {
          flag = true;
        }
      }
    }
  }

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
    string S;cin>>S;
    int Cindex=-1;
    bool is = true;
    for(int y=2;y<S.size()-1;y++){
        if(S[y]=='C'){
            if(Cindex!=-1)is=false;
            else Cindex=y;
        }
    }
    if(S[0]!='A'||Cindex==-1)is=false;
    REP(i,S.size()){
        if(i!=0&&i!=Cindex){
            if((S[i]<'a')||(S[i]>'z'))is=false;
        }
    }
    cout<<(is?"AC":"WA")<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
 
int main() {
  
  int A,B;
  cin>>A>>B;
  
  
  if((A+B)%2==0){
  cout<<(A+B)/2<<endl;
  }
  
  else{
  cout<<"IMPOSSIBLE"<<endl;
  }
  
  return 0;
}


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

using namespace std;
#define next next228

template<typename T1, typename T2>
ostream &operator<<(ostream &out, pair<T1, T2> &p) {
    out << "{" << p.first << ", " << p.second << "} ";//optional
    return out;
}

template<typename T1, typename T2>
istream &operator>>(istream &in, pair<T1, T2> &p) {
    in >> p.first >> p.second;
    return in;
}

template<typename T>
istream &operator>>(istream &in, vector<T> &arr) {
    for (auto &i : arr)
        in >> i;
    return in;
}

template<typename T>
ostream &operator<<(ostream &out, vector<T> &arr) {
    for (auto i : arr)
        out << i << " ";//optional
    out << endl;
    return out;
}

int n, m;
int a[200055];
int cnt[200055];
int d[200055];

int main() {
    cin >> n >> m;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        a[i]--;
        cnt[a[i]]++;
    }
    int res = 0;
    for (int i = 0; i < n; i++) {
        for (int j = i; j >= max(0, i - cnt[i] + 1); j--) {
            d[j]++;
        }
    }
    for (int i = 0; i < n; i++) {
        if (d[i] == 0) {
            res++;
        }
    }
    while (m--) {
        int x, y;
        cin >> x >> y;
        x--;
        y--;
        if (a[x] - cnt[a[x]] + 1 >= 0) {
            d[a[x] - cnt[a[x]] + 1]--;
            if (d[a[x] - cnt[a[x]] + 1] == 0) {
                res++;
            }
        }
        cnt[a[x]]--;
        cnt[y]++;
        if (y - cnt[y] + 1 >= 0) {
            d[y - cnt[y] + 1]++;
            if (d[y - cnt[y] + 1] == 1) {
                res--;
            }
        }
        a[x] = y;
        cout << res << endl;
    }
    return 0;
}

Measured memory_bytes: 3712
#include <iostream>
#include <cmath>
#include <bits/stdc++.h>

using namespace std;

int main() {

    int n, k;
    cin >> n >> k;
    long long arr[n];
    long long ans[n];
    for (int i = 0; i < n; i++) {
        cin >> arr[i];
        ans[i] = LLONG_MAX;
    }

    ans[0] = 0;
    ans[1] = abs(arr[0] - arr[1]);
    for (int i = 2; i < n; i++) {
        for (int j = i - 1; j >= 0 && j >= i - k; j--) {
            ans[i] = min(ans[i], (ans[j] + abs(arr[i] - arr[j])));
        }
    }
    cout << ans[n - 1];
    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#ifdef ENABLE_DEBUG_OUTPUT
#define DEBUG_LOG(s) cout << s << endl;
#else
#define DEBUG_LOG(s) void();
#endif
const int time_pow[3] = { 3600, 60, 1 };

int main(){
    while(true) {
        int n;
        cin >> n;

        if(n == 0) return 0;

        vector<int> train(1e5, 0);
        for (auto i = 0; i < n; i++) {
            string s, t; cin >> s >> t;
            int s_index = 0, t_index = 0;
            for (auto j = 0; j < 3; j++) {
                s_index += time_pow[j] * stoi(s.substr(j * 3, 2));
                t_index += time_pow[j] * stoi(t.substr(j * 3, 2));
            }
            train[s_index]++;
            train[t_index]--;
        }

        for (auto i = 0; i < 1e5 - 1; i++) train[i + 1] += train[i];

        int ans = 0;
        for (auto i = 0; i < 1e5; i++) ans = max(ans, train[i]);
        cout << ans << endl;
    }
}


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

int main() {
  int N;
  cin >> N;
  vector<int> V(N);
  rep(i, N) cin >> V[i];
  vector<int> C(N);
  rep(i, N) cin >> C[i];

  int ans = 0;
  rep(i, N) {
    if (V[i] > C[i]) ans += V[i] - C[i];
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fo(i, a, b) for (int i = a; i < b; i++)
#define re(i, n) fo(i, 0, n)
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<string> vs;
int main()
{
  int h, w;
  cin >> h >> w;
  re(i, h) {
    string s;
    cin >> s;
    cout << s << endl << s << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;using ll=long long;using uint=unsigned int;using pii=pair<int,int>;using pll=pair<ll,ll>;using ull = unsigned long long;using ld=long double;template<typename T>void _(const char*s,T h){cerr<<s<<" = "<<h<<"\n";}template<typename T,typename...Ts>void _(const char*s,T h,Ts...t){int b=0;while(((b+=*s=='(')-=*s==')')!=0||*s!=',')cerr<<*s++;cerr<<" = "<<h<<",";_(s+1,t...);}// break continue pop_back 998244353
// #define int ll
// #define pii pll
#define f first
#define s second
#define pb emplace_back
#define forn(i,n) for(int i=0;i<(n);++i)
#define sz(a)((int)(a).size())
#define sqr(x) ((x)*(x))
struct init{init(){cin.tie(0);iostream::sync_with_stdio(0);cout<<fixed<<setprecision(10);cerr<<fixed<<setprecision(5);}~init(){
#ifdef LOCAL
#define dbg(...) _(#__VA_ARGS__,__VA_ARGS__)
cerr<<"Time elapsed: "<<(double)clock()/CLOCKS_PER_SEC<<"s.\n";
#else
#define dbg(...) 
#endif
}}init;template<typename T,typename U>void upx(T&x,U y){if(x<y)x=y;}template<typename T,typename U>void upn(T&x,U y){if(x>y)x=y;}mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());const int D=4,dx[]={+1,0,-1,0},dy[]={0,+1,0,-1};
const int N=505;
pii a[N];
int ans[N*N];
int32_t main(){
    int n;
    cin>>n;
    for(int i=1;i<=n;++i){
        cin>>a[i].f;
        ans[a[i].f]=a[i].s=i;
    }
    sort(a+1,a+n+1);
    int j=1;
    for(int i=1;i<=n;++i){
        int c=a[i].s-1;
        while(c){
            while(j<a[i].f&&ans[j])j++;
            if(j==a[i].f)break;
            ans[j]=a[i].s;
            c--;
        }
        if(c){
            cout<<"No\n";
            return 0;
        }
    }
    j=n*n;
    for(int i=n;i>=1;--i){
        int c=n-a[i].s;
        while(c){
            while(j>a[i].f&&ans[j])j--;
            if(j==a[i].f)break;
            ans[j]=a[i].s;
            c--;
        }
        if(c){
            cout<<"No\n";
            return 0;
        }        
    }
    cout<<"Yes\n";
    for(int i=1;i<=n*n;++i){
        cout<<ans[i]<<' ';
    }
    cout<<'\n';
    return 0;
}

Measured memory_bytes: 4564