akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

#define pb push_back
#define F first
#define S second
#define mp make_pair

const int N = 1e6 + 10, Mod = 1e9 + 7;

int32_t main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    int n, m; cin >> n >> m;
    int l = -1, r = Mod;
    for(int i = 1; i <= m; i++){
        int x, y; cin >> x >> y;
        l = max(l, x);
        r = min(r, y);
    }
    r = min(r, n);
    if(r >= l)
        return cout << r - l + 1, 0;
    return cout << 0, 0;
}


Measured memory_bytes: 256
import java.util.*;

class Main{

    void solve(){
        Scanner sc = new Scanner(System.in);

        int[] dp = new int[310];
        dp[0] = 1;
        for(int i=1; i*i<=300; i++){
            for(int j=300; j>=0; j--){
                for(int k=1; i*i*k+j<=300; k++){
                    if(dp[j]==0) continue;
                    dp[j+i*i*k] += dp[j];
                }
            }
        }

        while(true){
            int n = sc.nextInt();
            if(n==0) break;
            System.out.println(dp[n]);
        }
    }

    public static void main(String[] args){
        new Main().solve();
    }
}

Measured memory_bytes: 18780
import java.util.Scanner;
class Main 
{
  public static void main(String[] args) 
  {
    Scanner input=new Scanner(System.in);
    String a=input.next();
    a=a.toUpperCase();
    int list[]=new int[26];
    for(int i=0;i<a.length();i++)
    {
      int temp=a.codePointAt(i);
      list[temp-65]=1;
    }
    int test=0;
    for(int i=0;i<list.length;i++)
    {
      int c=list[i];
      if(c==1)
      {
        char d=(char)(i+65);
        int count=0;
        for(int k=0;k<a.length();k++)
        {
          char f=a.charAt(k);
          if(f==d)
          {
            count++;
          }
        }
        if(count%2!=0)
        {
          test=1;
          break;
        }
      }
    }
    if(test==0)
    {
      System.out.println("Yes");
    }else
    System.out.println("No");
  }
}

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

int main(){
  string s;
  cin>>s;
  int j = 0;
  vector<int> cnt(20, 0);
  for(int i = 0; i < s.size(); i++){
    if(s[i] == 'A'|| s[i] == 'T'|| s[i] == 'G'|| s[i] == 'C'){
      cnt[j] += 1;
    }else{
      j += 1;
    }
  }
  cout<<*max_element(cnt.begin(), cnt.end());
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//INSERT ABOVE HERE

int dy[]={-1,-1,-1,0,1,1,1,0};
int dx[]={-1,0,1,1,1,0,-1,-1};
struct State{
  vector<string> st;
  State(int n):st(n){}

  int in(int y,int x) const{
    return 0<=y&&y<(int)st.size()&&0<=x&&x<(int)st[0].size();
  }

  State next() const{
    State res(*this);

    int n=st.size();
    for(int i=0;i<n;i++){
      for(int j=0;j<n;j++){
        if(st[i][j]=='@') continue;

        int cnt=0;
        for(int k=0;k<8;k++){
          int ny=i+dy[k],nx=j+dx[k];
          if(!in(ny,nx)) continue;
          if(st[ny][nx]!='.') cnt++;
        }

        res.st[i][j]='.';
        if(st[i][j]=='#'){
          if(cnt==2) res.st[i][j]='#';
          if(cnt==3) res.st[i][j]='#';
        }
        if(st[i][j]=='.'){
          if(cnt==3) res.st[i][j]='#';
        }
      }
    }
    return res;
  }

  vector<State> move() const{
    int n=st.size();
    int y=-1,x=-1;
    for(int i=0;i<n;i++)
      for(int j=0;j<n;j++)
        if(st[i][j]=='@') y=i,x=j;

    vector<State> adj;
    for(int k=0;k<8;k++){
      int ny=y+dy[k],nx=x+dx[k];
      if(!in(ny,nx)) continue;
      if(st[ny][nx]=='#') continue;
      State res(*this);
      swap(res.st[y][x],res.st[ny][nx]);
      adj.emplace_back(res.next());
    }
    return adj;
  }
};

signed main(){
  int n;
  while(cin>>n,n){
    State init(n);
    for(int i=0;i<n;i++) cin>>init.st[i];

    map<vector<string>, int> dist;
    queue<State> que;
    dist[init.st]=0;
    que.emplace(init);

    int ans=-1;
    while(!que.empty()){
      auto v=que.front();que.pop();

      int cnt=0;
      for(int i=0;i<n;i++)
        for(int j=0;j<n;j++)
          if(v.st[i][j]=='#') cnt++;
      if(cnt==0){
        ans=dist[v.st];
        break;
      }

      auto adj=v.move();
      for(auto u:adj){
        if(dist.count(u.st)) continue;
        dist[u.st]=dist[v.st]+1;
        que.emplace(u);
      }
    }
    cout<<ans<<endl;
  }
  return 0;
}



Measured memory_bytes: 10792
#include<iostream>
#include<algorithm>
#include<vector>
#include<numeric>
#include<string>
#include<cmath>
#include<set>
#include<queue>
#include<deque>
#include<bitset>
#include<iomanip>
#include<cctype>
#include<map>
#include<cstring>

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,a,b) for (int (i)=a;(i)<(b);(i)++)
#define all(x) (x).begin(),(x).end()

using namespace std;
using ll = long long int;
const int inf = 1001001000;
const long long int Inf = 1001001001001001000;

void print(vector<vector<int>> a){
	for (int i = 0; i < a.size(); i++)
	{
		for (int j=0;j<a[i].size();j++){
			cout << a[i][j] << " ";
		}
		cout << endl;
	}
}

void print(vector<vector<long long int>> a){
	for (int i=0;i<a.size();i++){
		for (int j=0;j<a[i].size();j++){
			cout << a[i][j] << " ";
		}
		cout << endl;
	}
}

void print(vector<int> a){
    int n = a.size();
    for (int j=0;j<n;j++) {
        if (j != n-1) cout << a[j] << " ";
        else cout << a[j] << endl;
    }
}

void print(set<int> a){
	for (auto x:a)
		cout << x << " ";
	cout << endl;
}

//最大公約数を返す関数.
long long int gcd(long long int x, long long int y){
    if (x < y) swap(x,y);
    while (y > 0){
        long long int r = x % y;
        x = y;
        y = r;
    }
    return x;
}
//最小公倍数を返す関数.gcdが必要.
long long int lcm(long long int x, long long int y){
	return x / gcd(x, y) * y;
}


int main()
{
	int n;
	cin >> n;
	vector<int> a(n);
	rep(i, n) cin >> a[i];

	if(count(all(a),1) == 0){
		cout << -1 << endl;
		return 0;
	}

	int ans = 0;
	int j = 1;
	rep(i, n)
	{
		if(a[i] == j){
			j++;
		} else {
			ans++;
		}
	}
	cout << ans << endl;
	return 0;
}

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

int main() {
    int X, R, N, K, res;
    cin >> X;
    N = X / 100;
    R = X % 100;
    K = R / 5;
    if (R % 5 > 0) {
        K++;
    }

    res = K <= N ? 1 : 0;

    cout << res << endl;
    return 0;
}



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

int main(){
    string s, t;
    cin >> s >> t;
    int h = s.length(), w = t.length();

    int dp[h+1][w+1];
    memset(dp, 0, sizeof(dp));
    pair<int,int> rev[h+1][w+1];

    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            if(s[i] == t[j]){
                dp[i+1][j+1] = dp[i][j]+1;
                rev[i+1][j+1] = {-1,-1};
            }
            if(dp[i+1][j+1] < dp[i][j+1])   dp[i+1][j+1] = dp[i][j+1], rev[i+1][j+1] = {-1, 0};
            if(dp[i+1][j+1] < dp[i+1][j])   dp[i+1][j+1] = dp[i+1][j], rev[i+1][j+1] = {0, -1};
        }
    }

    string res = "";
    int hh = h, ww = w;
    while(hh > 0 && ww > 0){
        pair<int,int> p = rev[hh][ww];
        if(p.first+p.second == -2){
            res += s[hh-1];
        }else if(p.first+p.second == 0){
            break;
        }
        hh += p.first, ww += p.second;
    }

    reverse(res.begin(), res.end());

    cout << res << endl;

    return 0;
}

Measured memory_bytes: 105856
Card = Struct.new(:suit, :rank) do
  def self.all
    %w{S H C D}.flat_map{|s| 13.times.map{|r| Card.new(s, r+1) }}
  end

  def to_s
    "#{suit} #{rank}"
  end
end

set = Card.all

gets.to_i.times {
  suit, rank = gets.split
  rank = rank.to_i

  set.delete Card.new(suit, rank)
}

puts set



Measured memory_bytes: 6880
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array;


void main() {
    int a,b;
    scan(a,b);
    a %= 3, b %= 3;
    writeln(a == b && a != 0 ? "Impossible" : "Possible");
}



void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}



void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
#include <random>
#include <chrono>

#define _ << " " <<
#define all(v) v.begin(), v.end()
#define sp(n) fixed << setprecision(n)
#define ff first
#define ss second

using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

const ll mod = 1e9 + 7;
const double eps = DBL_EPSILON;

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n, k, ans = 0;
	cin >> n >> k;
	for (int i = 0; i < n; i++) {
		int t;
		cin >> t;
		ans += t >= k;
	}
	cout << ans << endl;
	return 0;
}

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

using namespace std;

int main(void) {
    int n;
    cin >> n;
    multiset <int> bst;
    int a;
    cin >> a;
    bst.insert(a);
    for (int i = 1; i < n; i++) {
        cin >> a;
        auto ptr = bst.lower_bound(a);
        if (ptr == bst.begin()) {
            bst.insert(a);
        } else {
            ptr--;
            bst.erase(ptr);
            bst.insert(a);
        }
    }
    cout << bst.size() << endl;
    return 0;
}


Measured memory_bytes: 4992
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define forn(i,a,n) for(int i=a;i<n;i++)
using namespace std;
string s;
int n;
int main()
{
	cin>>n;
	s="1";
	n--;
	while(n){
		int g=0;
		for(int i=s.size()-1;i>0;i--){
			if(s[i]!=((s[i-1]-'0')+1)+'0'&&s[i]!='9'){
				g=i;
				break;
			}
		}
		if(s[g]!='9'){
			s[g]++;
			forn(i,g+1,s.size()){
				if(s[i-1]=='0')
				s[i]='0';
				else
				s[i]=((s[i-1]-'0')-1)+'0';
			}
		}else{
			bool f=true;
			for(int i=g;i>=0;i--){
				int x=s[i]-'0';
				if(f)
				x++;
				f=false;
				if(x==10){
					x=0;
					f=true;
				}
				s[i]=x+'0';
				if(!f)
				break;
			}
			forn(i,g+1,s.size())
			s[i]='0';
			if(f){
				s='1'+s;
			}
		}
		n--;
	}
	cout<<s;
	return 0;
}

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

const int MAX = 500010;
int n;
int a[MAX];
int tmp[MAX];
int com;

void merge(int A[], int lo, int mi, int hi) {
    int p1 = lo;
    int p2 = mi;
    int p3 = lo;
    while (p1 < mi && p2 < hi) {
        com++;
        if (A[p1] <= A[p2]) {
            tmp[p3++] = A[p1++];
        } else {
            tmp[p3++] = A[p2++];
        }
    }
    while (p1 < mi) {tmp[p3++] = A[p1++]; com++;}
    while (p2 < hi) {tmp[p3++] = A[p2++]; com++;}
    for (int i = lo; i < hi; i++) {
        A[i] = tmp[i];
    }
}

void mergeSort(int A[], int lo, int hi) {
    if (lo + 1 < hi) {
        int mi = (lo + hi) >> 1;
        mergeSort(A, lo, mi);
        mergeSort(A, mi, hi);
        merge(A, lo, mi, hi);
    }
}


int main() {
    //freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    scanf("%d", &n);
    com = 0;
    for (int i = 0; i < n; i++) {
        scanf("%d", &a[i]);
    }
    mergeSort(a, 0, n);
    for (int i = 0; i < n; i++) {
        if (i > 0) printf(" ");
        printf("%d", a[i]);
    }
    printf("\n");
    printf("%d\n", com);
    return 0;
}

Measured memory_bytes: 7012
#include <stdio.h>

int main(void)
{
	char board[3][3];
	int i, j;
	
	while (scanf("%s", board[0]) + board[0][0] != '1'){
		char win = '+';
		
		for (i = 1; i < 3; i++){
			scanf("%s", board[i]);
		}
		for (i = 0; i < 3; i++){
			if (board[i][0] == board[i][1] && board[i][1] == board[i][2]){
				win = board[i][0];
			}
			if (board[0][i] == board[1][i] && board[1][i] == board[2][i]){
				win = board[0][i];
			}
			if (win != '+'){
				break;
			}
		}
		if (board[0][0] == board[1][1] && board[1][1] == board[2][2]){
			win = board[0][0];
		}
		else if (board[0][2] == board[1][1] && board[1][1] == board[2][0]){
			win = board[0][2];
		}
		
		if (win == '+'){
			puts("NA");
		}
		else {
			printf("%c\n", win);
		}
	}
	
	return 0;
}

Measured memory_bytes: 548
import kotlin.math.*
import java.util.*

const val mod = 1000000007L

fun readI() = readLine()!!.toInt()
fun readL() = readLine()!!.toLong()
fun readD() = readLine()!!.toDouble()
fun readIs() = readLine()!!.split(' ').map(String::toInt)
fun readLs() = readLine()!!.split(' ').map(String::toLong)
fun readDs() = readLine()!!.split(' ').map(String::toDouble)

fun main(args: Array<String>) {
  readLine()
  val a = readLs()
  if (0L in a) {
    println(0)
    return
  }
  var ans = 1L
  for (i in a) {
    val j = ans
    ans *= i
    if (1_000_000_000_000_000_000L < ans || ans / i != j) {
      println(-1)
      return
    }
  }
  println(ans)
}


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

int main(){
  int H,W;
  cin >> H >> W;
  long long c[13][13],A[210][210];
  for(int i=0;i<=9;i++){
    for(int j=0;j<=9;j++){cin >> c[i][j];}
  }
  for(int i=1;i<=H;i++){
    for(int j=1;j<=W;j++){cin >> A[i][j];}
  }
  long long ans=0;
  for(int k=0;k<=9;k++){
    for(int i=0;i<=9;i++){
      for(int j=0;j<=9;j++){c[i][j]=min(c[i][j],c[i][k]+c[k][j]);}
    }
  }
  for(int i=1;i<=H;i++){
    for(int j=1;j<=W;j++){
      if(A[i][j]==-1)continue;
      ans+=c[A[i][j]][1];
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 640
#include <stdio.h>
#define N 100

int main() {

  int i, j, n, min, temp, count=0;
  int num[N];
  
  scanf("%d", &n);
  for(i=0; i<n; i++){
    scanf("%d", &num[i]);
  }

  for(i=0; i<n; i++){
    min = i;
    for(j=i; j<n; j++){
      if(num[j] < num[min]){
	min = j;
      }
    }
    if(i != min){
    temp = num[i];
    num[i] = num[min];
    num[min] = temp;
    count++;
    }
  }

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

  return 0;
}

Measured memory_bytes: 604
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>

#ifndef M_PI
#define M_PI 3.14159265358979
#endif
#define deg_to_rad(deg) (((deg) / 360) * 2 * M_PI)
#define rad_to_deg(rad) (((rad) / 2 / M_PI) * 360)

using namespace std;

typedef long long ll;
typedef vector<long long> vll;
typedef vector<int> vi;
typedef pair<long long, long long> pll;
typedef pair<int, int> pi;
typedef long double ld;
typedef pair<long double, long double> pld;

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll i, j, k;
    ll N;
    cin >> N;
    vll L(N);
    for(auto &e : L)
        cin >> e;

    ll ans = 0;
    for(i = 0; i < N; i++) {
        for(j = i + 1; j < N; j++) {
            for(k = j + 1; k < N; k++) {
                if(L[i] == L[j] || L[j] == L[k] || L[k] == L[i]) {
                    continue;
                }
                ll emax = max(L[i], max(L[j], L[k]));
                ll emin = min(L[i], min(L[j], L[k]));
                ll emid;
                if(L[i] < emax && L[i] > emin)
                    emid = L[i];
                if(L[j] < emax && L[j] > emin)
                    emid = L[j];
                if(L[k] < emax && L[k] > emin)
                    emid = L[k];
                if(emin + emid > emax) {
                    ans++;
                }
            }
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3656
n = int(input())
aaa = list(map(int, input().split(' ')))
before = 0
ans = 'Yes'
for i in range(n-2, -1, -1):
    if aaa[i] == aaa[i+1] + 1:
        aaa[i] -= 1
for i in range(n-1):
    if aaa[i] > aaa[i+1]:
        ans = 'No'
print(ans)

Measured memory_bytes: 63708
//============================================================================
// Name        : HelloCPP.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

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

int main() {

	int H,W;
	while(1){
		cin >> H >> W;

		if (H == 0 && W == 0) break;

		for(int i = 0; i < H; i++ ){	//gyou
			for(int j = 0; j < W; j++){ // retsu
				if((i % 2) == 0 ){
					if((j % 2) == 0){
						printf("#");
					}else{
						printf(".");
					}
				}else{
					if((j % 2) == 0){
						printf(".");
					}else{
						printf("#");
					}
				}
			}
			printf("\n");
		}
		printf("\n");
	}

	return 0;
}

Measured memory_bytes: 2952
N = int(input())
A = [int(n) for n in input().split()]
Ad = {a:0 for a in A}
S = 0
for a in A:
    Ad[a] += 1
    S += a
Q = int(input())
B = []
C = []
for i in range(Q):
    b, c = map(int, input().split())
    B.append(b)
    C.append(c)

for i in range(Q):
    if B[i] in Ad:
        if C[i] in Ad:
            Ad[C[i]] += Ad[B[i]]
        else:
            Ad[C[i]] = Ad[B[i]]
        S += (C[i]-B[i]) * Ad[B[i]]
        Ad[B[i]] = 0

    print(S)


Measured memory_bytes: 25080
#include <bits/stdc++.h>
 
#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
 
#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=(int)(a)-1;i>=(int)(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)
 
#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define bit(n) (1LL<<(n))
 
// #define DEBUG
 
#ifdef DEBUG
    #define dump(...) fprintf(stderr, __VA_ARGS__)
#else
    #define dump(...)
#endif
 
template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}
 
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
 
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int inf = INT_MAX;
const ll INF = LLONG_MAX;
const ll MOD = 1000000007LL;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
 
ll extgcd(ll a,ll b,ll& x,ll& y){x=1,y=0;ll g=a;if(b!=0) g=extgcd(b,a%b,y,x),y-=a/b*x;return g;}
ll ADD(const ll &a, const ll &b, const ll mod=MOD) { return (a+b)%mod;}
ll SUB(const ll &a, const ll &b, const ll mod=MOD) { return (a-b+mod)%mod;}
ll MUL(const ll &a, const ll &b, const ll mod=MOD) { return (1LL*a*b)%mod;}
ll DIV(const ll &a, const ll &b, const ll mod=MOD) {ll x,y; extgcd(b,mod,x,y);return MUL(a,(x+mod)%mod,mod);}
 
int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);

    int y, m, d;
    scanf("%d/%d/%d", &y, &m, &d);
    int date = 10000 * y + 100 * m + d;

    string res = "TBD";
    if(date <= 20190430){
        res = "Heisei";
    }

    cout << res << endl;

    return 0;
}


Measured memory_bytes: 256
S=list(input())
k=int(input())

cnt,ans=0,0
T=S+S
for i in range(1,len(T)):
  if T[i-1]==T[i]:
    cnt+=1
  else:
    ans+=(cnt+1)//2
    cnt=0
  if i==len(S)-1:
    ans+=(cnt+1)//2
    tmp=ans

if len(S)==1:
  print(k//2)
  exit()
if len(S)==2:
  if S[0]==S[1]:
    print(k)
  else:
    print(0)
  exit()
  
if len(set(T))==1:
  if len(S)%2==0:
    print(len(S)//2*k)
  else:
    out=(len(S)//2)*(k-(k//2))+(len(S)//2+1)*(k//2)
    print(out)
  exit()
      
print(tmp+(ans-tmp)*(k-1))

Measured memory_bytes: 3064
def make_divisors(n):
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]
    
a = [int(s) for s in input().split()]
N = a[0]
st = a[1]
mini = int(-1)
b = [int(s) for s in input().split()]

for i in range(N):
    if abs(b[i] - st) < mini or mini == -1:
        mini = abs(b[i] - st)

yakulist = make_divisors(mini)
gyakulist = sorted(yakulist, reverse=True)
kazu = len(gyakulist)
flag = int(0)

for i in range(kazu):
    for j in range(N):
        if abs(b[j] - st) % gyakulist[i] != 0:
            flag = 1
        else:
            pass
    if flag == 0:
        print(gyakulist[i])
        break
    else:
        flag = 0

Measured memory_bytes: 20340
import java.util._

object Main {
  def main(args: Array[String]) = {
    val scanner = new Scanner(System.in)
    val money = scanner.nextLong
    val fiveHundredCoins = money / 500;
    val fiveCoins = (money % 500) / 5
    println(fiveHundredCoins * 1000 + fiveCoins * 5)
  }
}


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

int main(){
cin.tie(0);
ios::sync_with_stdio(false);
int A,B;
cin>>A>>B;
int total=0;
rep(i,2){
if(A>B){
    total+=A;
    A-=1;
}
else{
    total+=B;
    B-=1;
}
}
cout<<total<<endl;
//system("pause");
return 0;
}

Measured memory_bytes: 256
char*p,s[99];main(c){for(;~scanf("%[^\n]\n",s);puts(s))for(;!strstr(s,"the")&!strstr(s,"this")&!strstr(s,"that");)for(p=s;c=*p;)*p++=c>96&c<123?(c-96)%26+97:c;}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define mod 1000000007
using ll = long long;
using namespace std;
int main(){
  int n,m;
  cin >> n >> m;
  rep(i, m){
    int a;
    cin >> a;
    n -= a;
  }
  if(n < 0) cout << -1 << endl;
  else cout << n << endl;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define SZ(x) ((int)(x).size())
#define INF 999999999
typedef long long int Int;
using ll = long long;
using VI = vector<int>;
int gcd(Int a, Int b) {
 return b != 0 ? gcd(b, a % b) : a;
}
int lcm(Int a, Int b) {
 return a / gcd(a, b)*b;
}
int main(){
  int n;cin >> n;
  int ans = 0;
  rep(i,n+1){
    if(((int)log10(i)+1)%2==1) ans++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 768
#include<bits/stdc++.h>
#define endl "\n"
#define ll long long int
#define N (ll)(1e9+7)
#define T int
#define P pair<T,T>
#define umap unordered_map<T,T>
#define uset unordered_set<T>
#define rep(i,n) for(i=0;i<n;i++)
#define all(v) v.begin(),v.end()
#define print(v) for(auto x:v) cout<<x<< " "
#define pb push_back
using namespace std;
#define _USE_MATH_DEFINES

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
   	ll n;
   	cin>>n;
   	ll i;
   	map<ll,ll> mp;
   	rep(i,n-1)
   	{
   		ll x;
   		cin>>x;
   		mp[x]++;
   	}
   	for(i=1;i<=n;i++)
   	cout<<mp[i]<<endl;
   	

    return 0;
}


Measured memory_bytes: 16164
#include<bits/stdc++.h>
using namespace std;
#define RI register int
int read() {
	int q=0;char ch=' ';
	while(ch<'0'||ch>'9') ch=getchar();
	while(ch>='0'&&ch<='9') q=q*10+ch-'0',ch=getchar();
	return q;
}
typedef long long LL;
const int N=405,bas=1000;
int n;LL ans,has[N],need[4];
struct node{int c[4];}b[N];
map<LL,int> mp;

LL gethas(node tmp) {
	LL re=0;
	for(RI i=0;i<=3;++i) re=1LL*bas*re+tmp.c[i];
	return re;
}
void add(LL d,int num) {
	int kl[4];
	for(RI i=3;i>=0;--i) kl[i]=d%bas,d/=bas;
	for(RI i=0;i<=3;++i) {
		LL orz=0;
		for(RI j=0;j<=3;++j) orz=1LL*bas*orz+kl[(i+j)&3];
		mp[orz]+=num;
	}
}
void work() {
	for(RI i=1;i<=n-5;++i) {
		add(has[i],-1);
		for(RI j=i+1;j<=n;++j) {
			add(has[j],-1);
			for(RI k=0;k<4;++k) {
				LL js=1;int flag=0;
				for(RI t=0;t<4;++t) {
					node kl;
					kl.c[0]=b[i].c[(t+1)&3],kl.c[1]=b[i].c[t];
					kl.c[2]=b[j].c[(k-t+4)&3],kl.c[3]=b[j].c[(k-t+3)&3];
					need[t]=gethas(kl);
					if(!mp[need[t]]) {flag=1;break;}
				}
				if(flag) continue;
				for(RI t=0;t<4;++t) js*=mp[need[t]],add(need[t],-1);
				ans+=js;for(RI t=0;t<4;++t) add(need[t],1);
			}
			add(has[j],1);
		}
	}
}
int main()
{
	n=read();
	for(RI i=1;i<=n;++i) {
		for(RI j=0;j<=3;++j) b[i].c[j]=read();
		has[i]=gethas(b[i]),add(has[i],1);
	}
	work();
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 20352
from collections import defaultdict
n,p=map(int,input().split())
S=input()
ans=0
if p==5:
    for i in range(n):
        if int(S[i])==5 or int(S[i])==0:
            ans+=i+1
elif p==2:
    for i in range(n):
        if int(S[i])%2==0:
            ans+=i+1
else:
    kouho=defaultdict(int)
    s=0
    ruijo=1
    for i in range(n):
        ruijo%=p
        s+=int(S[-(i+1)])*(ruijo)
        a=s%p
        kouho[a]+=1
        ruijo*=10
    for j in range(p):
        z=kouho[j]
        ans+=z*(z-1)//2
    ans+=kouho[0]
print(ans)

Measured memory_bytes: 4452
// Code for A - The Number of Even Pairs
#include <iostream>
using namespace std;

int cmb(int x, int y) {
  int a = 1;
  int b = 1;

  for (int i = 0; i < y; i++) {
    a = a * (x - i);
  }

  for (int i = 1; i <= y; i++) {
    b = b * i;
  }

  return a / b;
}

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

  cout << cmb(N, 2) + cmb(M, 2) << endl;
	return 0;
}


Measured memory_bytes: 256
import java.io.PrintWriter;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;

class Main implements Runnable {
	public static void main(String[] args) {
		new Main().run();
	}

	class State {
		int i;
		int parent;
		int j;// in the next step,go into g[i][j]

		public State(int i_, int parent_, int j_) {
			i = i_;
			parent = parent_;
			j = j_;
		}
	}

	int strongly_connected_componets(ArrayList<Integer>[] g, int[] col) {
		int n = g.length;
		Arrays.fill(col, -1);
		int cols = 0;
		int[] low = new int[n];
		int[] ord = new int[n];
		boolean[] marked = new boolean[n];
		Arrays.fill(low, -1);
		Arrays.fill(ord, -1);
		int order = 0;
		ArrayDeque<State> stk = new ArrayDeque<>();
		ArrayDeque<Integer> pnd = new ArrayDeque<>();
		for (int ii = 0; ii < n; ++ii) {
			if (ord[ii] == -1) {
				stk.add(new State(ii, -1, 0));
			}
			while (!stk.isEmpty()) {
				State s = stk.pollFirst();
				if (ord[s.i] == -1) {
					low[s.i] = (ord[s.i] = order++);
					pnd.addFirst(s.i);
				}
				if (s.j > 0 && s.parent != g[s.i].get(s.j - 1) && !marked[g[s.i].get(s.j - 1)]) {
					if (low[g[s.i].get(s.j - 1)] == -1) {
						throw new AssertionError();
					}
					low[s.i] = Math.min(low[s.i], low[g[s.i].get(s.j - 1)]);
				}
				if (s.j == g[s.i].size() && low[s.i] == ord[s.i]) {
					while (true) {
						int v = pnd.pollFirst();
						col[v] = cols;
						marked[v] = true;
						if (v == s.i)
							break;
					}
					++cols;
					continue;
				}
				if (s.j == g[s.i].size())
					continue;
				int v = g[s.i].get(s.j);
				stk.addFirst(new State(s.i, s.parent, s.j + 1));
				if (ord[v] == -1) {
					stk.addFirst(new State(v, s.i, 0));
				} else if (!marked[v]) {
					low[s.i] = Math.min(low[s.i], low[v]);
				}
			}
		}
		return cols;
	}

	@SuppressWarnings("unchecked")
	public void run() {
		Scanner sc = new Scanner(System.in);
		PrintWriter pw = new PrintWriter(System.out);
		int V = sc.nextInt();
		int E = sc.nextInt();
		ArrayList<Integer>[] g = new ArrayList[V];
		for (int i = 0; i < V; ++i) {
			g[i] = new ArrayList<>();
		}
		for (int i = 0; i < E; ++i) {
			int s = sc.nextInt();
			int t = sc.nextInt();
			g[s].add(t);
		}
		int[] col = new int[V];
		strongly_connected_componets(g, col);
		int q = sc.nextInt();
		while (q-- > 0) {
			int u = sc.nextInt();
			int v = sc.nextInt();
			System.out.println(col[u] == col[v] ? "1" : "0");
		}
	}

	static void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}

}

Measured memory_bytes: 101596
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

public class Main {
    public static void main(final String[] args) {
        final FastScanner scanner = new FastScanner(System.in);
        final int n = scanner.nextInt();
        final List<Integer> list = IntStream.range(0, n)
                .mapToObj(i -> scanner.nextInt())
                .sorted()
                .collect(Collectors.toList());

        final List<String> answer = new ArrayList<>();
        final int first = list.get(0);
        final int last = list.get(list.size() - 1);
        int tmp;
        if (first >= 0) {
            tmp = first;
            for (int i = 1; i < list.size() - 1; i++) {
                answer.add(tmp + " " + list.get(i));
                tmp -= list.get(i);
            }
            answer.add(last + " " + tmp);
            tmp = last - tmp;
        } else if (last <= 0) {
            tmp = last;
            for (int i = 0; i < list.size() - 1; i++) {
                answer.add(tmp + " " + list.get(i));
                tmp -= list.get(i);
            }
        } else {
            tmp = first;
            int tmp2 = last;
            for (int i = 1; i < list.size() - 1; i++) {
                final int current = list.get(i);
                if (current < 0) {
                    answer.add(tmp2 + " " + current);
                    tmp2 -= current;
                } else {
                    answer.add(tmp + " " + current);
                    tmp -= current;
                }
            }
            answer.add(tmp2 + " " + tmp);
            tmp = tmp2 - tmp;
        }

        System.out.println(tmp);
        answer.forEach(System.out::println);
    }

    private static class FastScanner {
        private final BufferedReader reader;
        private StringTokenizer tokenizer;

        FastScanner(final InputStream in) {
            reader = new BufferedReader(new InputStreamReader(in));
            tokenizer = null;
        }

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

        int nextInt() {
            return Integer.parseInt(next());
        }
    }
}
    

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

#define pb push_back
#define pp pop_back
#define mp make_pair
typedef long long Long;

const int N = 1e5;

int main()
{
  ios::sync_with_stdio(0);
  cin.tie(0),cout.tie(0);
  int tc, ca = 0;
  int x;
  cin >> x;
  if (x==0)cout << 1 << '\n';
  else cout << 0 << '\n';
  return 0;
}


Measured memory_bytes: 3636
a=input()
b=input()
c=a.split()
n=int(c[0])
d=b.split()
d=[int(i) for i in d]
d.sort(reverse=True)
count=0
ll=list()
for i in d:
    if count!=0:
        ll.append(c-i)
    c=i
    count+=1
ll.sort()
for i in range(n-1):
    ccc=len(ll)
    if ccc>=1:
        del ll[-1]
print(sum(ll))


Measured memory_bytes: 14468
#include <iostream>
#include <queue>
using namespace std;
static const int N=100;
static const int INFTY=(1<<21);

int n,M[N][N];
int d[N];
void kansuu(int s){
  queue<int>q;
  q.push(s);
  for(int i=0;i<n;i++){
    d[i]=INFTY;
  }
  d[s]=0;
  int u;
  while(!q.empty()){
    u=q.front();
    q.pop();
    for(int i=0;i<n;i++){
      if(M[u][i]==0) continue;
      if(d[i]!=INFTY) continue;
      d[i]=d[u]+1;
      q.push(i);
    }
  }
  for(int i=0;i<n;i++){
    if(d[i]==INFTY) d[i]=-1;
    cout<<i+1<<" "<<d[i];
    printf("\n");
  }
}
int main(void){
  int u,k,v;
  cin>>n;
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      M[i][j]=0;
    }
  }
  for(int i=0;i<n;i++){
    cin>>u>>k;
    u--;
    for(int j=0;j<k;j++){
      cin>>v;
      v--;
      M[u][v]=1;
    }
  }
  kansuu(0);
  return 0;
}



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

int main() {
    ll N,A,B;
    cin >> N >> A >> B;
    ll set = N/(A+B);
    ll modA = (N%(A+B));
    if(modA > A){
        modA = modA-abs(A-modA);
    }
    cout << modA+(set*A) << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int maxn=5010,mod=1000000007;
inline void Add(int &a,int b){a=a+b>=mod?a+b-mod:a+b;}
int n,m,f[maxn],g[maxn],pv[maxn];
int main()
{
	cin>>n>>m;
	for(int i=pv[0]=1;i<=m;i++) pv[i]=2ll*pv[i-1]%mod;
	f[m]=1;
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=m;j++) g[j]=0;
		/*
		for(int j=1;j<=m;j++)
		{
			Add(g[j],1ll*(j+1)*f[j]%mod);
			for(int len=2;len<=j;len++)
				Add(g[j-len+1],1ll*f[j]*pv[len-2]%mod*(j-len+1)%mod);
		}
		*/
	//	for(int j=1;j<=m;j++) for(int l=2;j+l-1<=m;l++) Add(g[j],1ll*f[j+l-1]*pv[l-2]%mod);
		int nowv=0;
		for(int j=m;j;j--)
		{
			Add(nowv,f[j+1]);
			Add(g[j],nowv);
			Add(nowv,nowv);
		}
		for(int j=1;j<=m;j++) g[j]=1ll*g[j]*j%mod;
		for(int j=1;j<=m;j++) Add(g[j],1ll*(j+1)*f[j]%mod);
		for(int j=1;j<=m;j++) f[j]=g[j];
	}
	int ans=0;
	for(int i=1;i<=m;i++) Add(ans,f[i]);
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3652
n = int(input())
p = list(map(int,input().split()))
q = list(map(int,input().split()))

def factrial(n):
  if n==0:
    return 1
  else:
    return(n * factrial(n-1))

def f(a):
  rank = 0
  for i in range(n-1):  
    left=a[i]-1
    for j in range(i+1):
      if a[j]<a[i]:
        left-=1    
    rank += left * factrial(n-i-1)  
  return rank

print(abs(f(q)-f(p)))

Measured memory_bytes: 3064
<?php
$n=trim(fgets(STDIN));
if($n%2==1){
  echo "No";
  exit;
}
$s=trim(fgets(STDIN));
$i=0;
$half=$n/2;
while($i<$half){
  if($s[$i]!=$s[$i+$half]){
    echo "No";
    exit;
  }
  ++$i;
}
echo "Yes";

Measured memory_bytes: 4728
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1000000007;
#define INF 1LL<<30
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()

vector<int> q[101010];

int main(){
    int n,m;
    cin>>n>>m;
    int a[n],b[n];
    rep(i,n) cin>>a[i]>>b[i];
    rep(i,n) q[a[i]].push_back(b[i]);

    priority_queue<int> que;
    int ans=0;
    for(int i=1;i<m+1;i++){
        for(auto b : q[i]) que.push(b);
        if(!que.empty()){
            ans+=que.top();
            que.pop();
        }
    }

    cout<<ans<<endl;
}


 

Measured memory_bytes: 6400
import math

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))


N, K = map(int, input().split())
if N > 2:
    x = combinations_count(N-1, 2)
else:
    x = 0
if x < K:
    print('-1')
    quit()

h = []
for i in range(2,N+1):
    h.append(('1', str(i)))

hen = x-K
x = 2
y = 3
while hen > 0:
    h.append((x,y))
    y += 1
    if y > N:
        x += 1
        y = x+1
    hen -= 1

print(len(h))
for x,y in h:
    print(x,y)

Measured memory_bytes: 3992
#include<bits/stdc++.h>
using namespace std;
#define LL long long 
LL l, r;
int main(){
    cin>>l>>r;
    if(l > r)swap(l, r);
    if(l == r){
        puts("1");
        return 0;
    }
    int x = 60, y = -1;
    while((l >> x & 1) == (r >> x & 1) && x){
        //printf("hi=%d l=%lld r=%lld\n", hi, l >> hi & 1, r >> hi & 1);
        l &= (1ll << x) - 1; r &= (1ll << x) - 1;
        x--;
    }
    for(int i = x - 1;i >= 0; i--){
        if(r >> i & 1){
            y = i; break;
        }
    }
    //printf("l=%lld r=%lld x=%d y=%d\n", l, r, x, y);
    //printf("hi=%d\n", hi);
    LL ans = (1ll << x) + (1ll << y + 1) - 1 - l + 1;
    //printf("ans=%lld\n", ans);
    ans += (1ll << x + 1) - 1 - ((1ll << x) + l) + 1;
    //printf("ans=%lld\n", ans);
    r = ((1ll << x) + l);
    l = (1ll << x) + (1ll << y + 1) - 1;
    if(l >= r)ans -= l - r + 1;
    //printf("l=%lld r=%lld\n", l, r);
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
 int a,b,c,d;
 cin >> a >> b >> c>> d;
 while(1){
   c=c-b;
   if(c<=0){
     cout << "Yes" << endl;
     break;
   }
   a=a-d;
   if(a<=0){
     cout << "No" << endl;
     break;
   }
 } 
}

Measured memory_bytes: 3624
#include <iostream>

using namespace std;

int a[3];
int str;
int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);

	cin >> a[0] >> a[1] >> a[2];
	for (int i = 0; i < 2; i++) {
		for (int j = i+1; j < 3; j++) {
			if (a[i] > a[j]) {
				str = a[i];
				a[i] = a[j];
				a[j] = str;
			}
		}
	}
	cout << a[0] << " " << a[1] << " " << a[2] << "\n";

	return 0;
}

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

int main() {
    long long n, a, b;
    cin >> n;
    
    long long i = 1;
    while(i*i<=n){   
        if(n%i==0){
            a=i;
            b=n/i;
        }
        i++;
    }

    cout<<a+b-2<<endl;
    return 0;
}

Measured memory_bytes: 256
# ABC097C - K-th Substring (ARC097C)
from functools import reduce
from operator import or_


def get_substring(a: str, x: int) -> set:
    ret = set()
    for i in range(N - x + 1):
        ret |= {a[i : i + x]}
    return ret


def main():
    global N
    S = input()
    K = int(input())
    N = len(S)
    x = reduce(or_, [get_substring(S, i) for i in range(1, K + 1)])
    ans = sorted(x)[K - 1]
    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 5724
#include <algorithm>
#include <climits>
#include <iostream>
#include <string>
#include <utility>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <iomanip>
#include <cmath>

using namespace std;
using ll = long long int;

template <class T> ostream &operator<<(ostream &os, vector<T> &v) {
  for (auto i = v.begin(); i != v.end(); i++) {
    os << *i << " ";
  }
  return os;
}


void solve(long long n, std::vector<long long> v){
  map<ll, ll> e, o;
  for(ll i=0; i<n; i++) {
    if(i%2) {
      o[v[i]]++;
    } else {
      e[v[i]]++;
    }
  }
  vector<pair<ll, ll>> ve, vo;
  for(auto i : e) {
    ve.push_back(make_pair(i.second, i.first));
  }
  for(auto i : o) {
    vo.push_back(make_pair(i.second, i.first));
  }
  sort(ve.rbegin(), ve.rend());
  sort(vo.rbegin(), vo.rend());
  if(ve[0].second != vo[0].second) {
    std::cout << n-(ve[0].first+vo[0].first) << std::endl;
  } else if(ve.size() == 1 and vo.size() == 1){
    std::cout << n-(ve[0].first+vo[1].first) << std::endl;
  } else if(ve.size() == 1 and vo.size() != 1) {
    std::cout << n-(ve[0].first+vo[1].first) << std::endl;
  } else if(ve.size() != 1 and vo.size() == 1) {
    std::cout << n-(ve[1].first+vo[0].first) << std::endl;
  } else {
    std::cout << n-(max(ve[1].first+vo[0].first, ve[0].first+vo[1].first)) << std::endl;
  }


}

int main(){
  long long n;
  scanf("%lld",&n);
  std::vector<long long> v(n);
  for(int i = 0 ; i < n ; i++){
    scanf("%lld",&v[i]);
  }
  solve(n, std::move(v));
  return 0;
}



Measured memory_bytes: 9592
#include <bits/stdc++.h>
using namespace std;
long long H,Tree[500005],N,a[500005],h[500005],ans,dp[500005];
int Lowbit(int x){ return (x&(-x)); }
void Modify(int x,long long y){ for (int i=x;i<=H;i+=Lowbit(i)) Tree[i]=max(Tree[i],y); }
long long query(int x){ long long ans=0; for (int i=x;i>0;i-=Lowbit(i)) ans=max(ans,Tree[i]); return ans; }
int main()
{
	scanf("%lld",&N);
	for (int i=1;i<=N;i++) scanf("%lld",&h[i]),H=max(H,h[i]);
	for (int i=1;i<=N;i++) scanf("%lld",&a[i]);
	for (int i=1;i<=N;i++){ long long R=query(h[i]); dp[i]=R+a[i]; Modify(h[i],dp[i]); ans=max(ans,dp[i]); }
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 14080
#include <iostream>

using namespace std;

int main(){
    int N;
    cin >> N;
    int ma=0;
    long long ans=0;
    for(int i=0; i<N; i++){
        int a;
        cin >> a;
        ma=max(ma,a);
        ans +=(ma-a);
    }
    cout << ans << endl;
}

Measured memory_bytes: 3636
#include<stdio.h>
#include<string.h>

int main(){
char s[100];
int i;
int n;
int a=0,b=0,c=0,g=0;
scanf("%d",&n);

	for(i=0;i<n;i++){
	scanf("%*c%c",&s[i]);
	}
	
//printf("%s\n",s);
for(i=0;i<n;i++){
	/*if(s[i]=='P'){
		a++;
		
	}else
	if(s[i]=='W'){
		b++;
	}else
	if(s[i]=='G'){
		
		c++;
	}else*/
	if(s[i]=='Y'){
		g++;
		
	}
	
	
	
	
}
//printf("%d%d%d%d\n",a,b,c,g);
if(g>0){
	printf("Four\n");
	
}else{
	printf("Three\n");
	
}
	return 0;
}

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

template <typename T>
class SegmentTree
{
private:
  using Fn = function<T(T, T)>;
  int N;
  vector<T> dat;
  T unit;
  Fn func;

public:
  SegmentTree() {}
  SegmentTree(int n_, Fn func_, T unit_) : func(func_), unit(unit_)
  {
    N = 1;
    while (N < n_)
      N *= 2;
    dat.assign(2 * N - 1, unit);
  }
  SegmentTree(vector<T> v, Fn func_, T unit_) : func(func_), unit(unit_)
  {
    N = 1;
    int sz = v.size();
    while (N < sz)
      N *= 2;
    dat.resize(2 * N - 1);
    for (int i = 0; i < N; ++i)
      dat[i + N - 1] = (i < sz ? v[i] : unit);
    for (int i = N - 2; i >= 0; --i)
      dat[i] = func(dat[i * 2 + 1], dat[i * 2 + 2]);
  }

  // k 番目の要素を a に変更
  void update(int k, T a)
  {
    k += N - 1;
    dat[k] = a;
    while (k > 0)
    {
      k = (k - 1) / 2;
      dat[k] = func(dat[k * 2 + 1], dat[k * 2 + 2]);
    }
  }

  // k 番目の要素を取得
  T get(int k) { return dat[k + N - 1]; }

  // 区間 [l, r) の和を取得
  T query(int l, int r)
  {
    T vl = unit, vr = unit;
    for (l += (N - 1), r += (N - 1); l < r; l >>= 1, r >>= 1)
    {
      if ((l & 1) == 0)
        vl = func(vl, dat[l]);
      if ((r & 1) == 0)
        vr = func(vr, dat[--r]);
    }
    return func(vl, vr);
  }
};

int main()
{
  int n, q;
  cin >> n >> q;
  auto f = [](int a, int b) { return min(a, b); };
  SegmentTree<int> sg(n, f, INT_MAX);
  for (int qi = 0; qi < q; qi++)
  {
    int com, x, y;
    cin >> com >> x >> y;
    if (com == 0) // 変更クエリ
      sg.update(x, y);
    else // 求値クエリ
      cout << sg.query(x, y + 1) << "\n";
  }
  return 0;
}


Measured memory_bytes: 3848
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<iomanip>
#include<list>
#include<deque>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define DEB2(X) cout<<X<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define DEB2(X) {}
#define END {}
#endif
typedef long long ll;
#define int ll
#define uset unordered_set
#define umap unordered_map
//typedef std::pair<int,int> P;
struct edge{int to,cost;};
const int INF=100000000000000000;
const int INF2=9223372036854775807;
const int MOD=998244353;
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define min(X,Y) (((int)(X)<(int)(Y))?(X):(Y))
#define max(X,Y) (((int)(X)>(int)(Y))?(X):(Y))
#define NP(X,Y) next_permutation(X,Y)
#define setdouble(X,Y) cout<<fixed<<setprecision(X)<<Y
int ceil2(int a,int b){if(a%b==0){return a/b;}else{return a/b+1;}}
int pow2(int a,int b){int r=1;for(int i=1;i<=b;i++){r*=a;}return r;}
int Log2(int a){int t=0;while(1){if(a==0||a==1){break;}a/=2;t++;}return t;}

int extgcd(int a,int b,int &x,int &y){
	int g=a;
	x=1,y=0;
	if(b!=0){
		g=extgcd(b,a%b,y,x);
		y-=(a/b)*x;
	}
	return g;
}
 
// 逆元
int mod_inverse(int a,int m){
	int x, y;
	extgcd(a,m,x,y);
	return (m+x%m)%m;
}
 
// 階乗
std::vector<int>fact;
void mod_fact(int n, int m){
	fact.resize(n+1);
	fact[0]=1;
	for(int i=1;i<=n;i++){
		fact[i]=fact[i-1]*i%m;
	}
}
 
// nCk mod p
int mod_nCr(int n, int k, int m){
	if(n<k)return 0;
	return fact[n]*mod_inverse(fact[k]*fact[n-k]%m,m)%m;
}

int mod_pow(int b,int e,int m){
    if(e==0){
        return 1;
    }else{
        int sum = mod_pow(b,e/2,m);
        if(e%2==0){
            return (sum*sum)%m;
        }else{
            return (((sum*sum)%m)*b)%m;
        }
    }
}

int N,M,K;

int seki(vector<int> v,int m){
	int r=1;
	REP(i,v.size()){
		r*=v[i];
		r%=m;
	}
	return r;
}

signed main(){
	cin>>N>>M>>K;
	mod_fact(N+10,MOD);
	int ans=0;
	for(int i=0;i<=K;i++){
		ans+=seki({M,mod_nCr(N-1,i,MOD),mod_pow(M-1,N-1-i,MOD)},MOD);
		ans%=MOD;
	}
	cout<<ans<<endl;
	return 0;
}


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

int main(){
  int a,b,c,d;
  cin >> a>> b>> c>> d;
  int L=a+b;
  int R=c+d;
  if(L==R){
    cout << "Balanced" << endl;
  }else{
    if(L<R){
      cout << "Right" << endl;
    }else{
      cout << "Left" << endl;
    }
  }
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def iterate(L,n,m,edges,mode):
    # L -> L+1
    if(mode&1 or L==1):
        edges+=[(1,n,L)]
        return L+1,n,m+1,edges
    # L -> 2*L
    else:
        edges=[(u,v,2*w) for u,v,w in edges]
        edges+=[(n,n+1,0),(n,n+1,1)]
        return 2*L,n+1,m+2,edges
        
def resolve():
    L=int(input())
    res=[L%2]
    while(L!=1):
        if(L&1): L-=1
        else: L//=2
        res.append(L%2)
    res.reverse()

    # initialize
    L=1
    n=2
    m=1
    edges=[(1,2,0)]

    # iterate
    for mode in res[1:]:
        L,n,m,edges=iterate(L,n,m,edges,mode)

    # output
    print(n,m)
    for e in edges:
        print(*e)
resolve()

Measured memory_bytes: 38256
x = int(input())
ans = 0
if x >= 400 and x <= 599:
  ans = 8
elif x >= 600 and x <= 799:
  ans = 7
elif x >= 800 and x <= 999:
  ans = 6
elif x >= 1000 and x <= 1199:
  ans = 5
elif x >= 1200 and x <= 1399:
  ans = 4
elif x >= 1400 and x <= 1599:
  ans = 3
elif x >= 1600 and x <= 1799:
  ans = 2
elif x >= 1800 and x <= 1999:
  ans = 1
print(ans)

Measured memory_bytes: 9192
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  string S;
  cin >> N;
  cin >> S;
  int count = 0;
  int check;
  for (int i = 0; i < N; i++) {
    if (S.at(i) == 'A') {
      check = 1;
    } else if (S.at(i) == 'B' && check == 1) {
      check = 2;
    } else if (S.at(i) == 'C' && check == 2) {
      count++;
      check = 0;
    } else { 
      check = 0 ;
    }
    
  }
  cout << count << endl;
}

Measured memory_bytes: 384
// https://atcoder.jp/contests/abc143/tasks/abc143_e
#include <iostream>

long long connection[301][301];
const long long INF = (long long)1000000001;

int main()
{
	std::cin.sync_with_stdio(false);
	std::cout.sync_with_stdio(false);
	int cities, roads, tank;
	int x, y;
	std::cin >> cities >> roads >> tank;

	for (int i = 1; i <= cities; ++i)
	{
		for (int j = 1; j <= cities; ++j)
		{
			connection[i][j] = INF;
		}
	}

	for (int i = 1; i <= roads; ++i)
	{
		std::cin >> x >> y;
		std::cin >> connection[x][y];
		connection[y][x] = connection[x][y];
	}

	for (int k = 1 ; k <= cities; ++k)
	{
		for (int i = 1; i <= cities; ++i)
		{
			for (int j = 1; j <= cities; ++j)
			{
				if (connection[i][j] > connection[i][k] + connection[k][j])
				{
					connection[i][j] = connection[i][k] + connection[k][j];
				}
			}
		}
	}

	for (int i = 1; i <= cities; ++i)
	{
		for (int j = 1; j <= cities; ++j)
		{
			if (connection[i][j] > tank)
			{
				connection[i][j] = INF;
			}
			else
			{
				connection[i][j] = 1;
			}
		}
	}

	for (int k = 1; k <= cities; ++k)
	{
		for (int i = 1; i <= cities; ++i)
		{
			for (int j = 1; j <= cities; ++j)
			{
				if (connection[i][j] > connection[i][k] + connection[k][j])
				{
					connection[i][j] = connection[i][k] + connection[k][j];
				}
			}
		}
	}

	int q, s, t;
	std::cin >> q;
	for (int i = 1; i <= q; ++i)
	{
		std::cin >> s >> t;

		if (connection[s][t] >= INF)
		{
			std::cout << -1 << '\n';
		}
		else
		{
			std::cout << connection[s][t] - 1 << '\n';
		}
	}
}


Measured memory_bytes: 1280
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <cstdio>
#include <limits>
#define rep(i,n) for(int i = 0; i < n; ++i)
#define rep1(i,n) for(int i = 1; i <= n; ++i)
using namespace std;
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(a > b){ a = b; return 1; } return 0; }
using ll = long long; using ld = long double;
using pi = pair<int,int>; using pl = pair<ll,ll>;
using vi = vector<int>; using vii = vector<vi>;
using vl = vector<ll>; using vll = vector<vl>;
const int inf = numeric_limits<int>::max();
const ll infll = numeric_limits<ll>::max();
int main()
{
  int n; cin >> n;
  rep(i,n) {
    cout << "ACL";
  }
  cout << "\n";
  return 0;
}


Measured memory_bytes: 3128