akhauriyash/Code-Regression huggingface dataset:
// https://atcoder.jp/contests/m-solutions2020/tasks/m_solutions2020_d
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <map>
#include <unordered_map>
#include <stack>
#include <queue>
#include <set>
#include <unordered_set>
#include <bitset>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
#define REP(i, n) for(size_t i = 0; i < (n); ++i)

int main()
{
    int N;
    cin >> N;
    vector<int> A(N);
    REP(i, N) cin >> A[i];
    // Greedy
    // 売り買いの履歴によらず、
    // 株の移動を足し引きすることで、
    // T 枚 i 日目に買い、T枚 i + 1 日目に売るとみなすことができる。
    // T * (A[i + 1] - A[i]) > 0 であれば得するので、
    // A[i] < A[i + 1] の時に株をできるだけ多く買うのが最適である
    ll cur = 1000;
    for (int i = 0; i < N - 1; ++i)
    {
        ll s = 0;
        if (A[i] < A[i + 1]) s = cur / A[i];
        cur += (A[i + 1] - A[i]) * s;
    }
    cout << cur << endl;
    return 0;
}


Measured memory_bytes: 3604
#include <cstdio>
#include <cstring>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR (i, 0, n)
#define _ << " _ " <<
#define TRACE(x) cerr << #x << " = " << x << endl
#define debug(...) fprintf(stderr, __VA_ARGS__)
//#define debug
//#define TRACE(x)

using namespace std;

typedef long long llint;

const llint INF = 1e18;

llint sol;

void check(llint a, llint b, llint c) {
  sol = min(sol, a * b * c);
}

int main(void) {
  llint a, b, c;
  sol = INF;
  cin >> a >> b >> c;

  check(abs(a/2 - (a-a/2)), b, c);
  check(a, abs(b/2 - (b-b/2)), c);
  check(a, b, abs(c/2 - (c-c/2)));

  cout << sol << endl;
  
  return 0;
}


Measured memory_bytes: 256
import sys
import numpy as np


a=np.array([sys.stdin.readline().split() for _ in range(3)],dtype='int64')
n=int(sys.stdin.readline())
b=np.array([sys.stdin.readline() for _ in range(n)],dtype='int64')

for bi in b:
    a=np.where(a==bi,0,a)
ans=0

for i in range(3):
    if a[i,0]==a[i,1]==a[i,2]==0:
        ans=1
        break
    if a[0,i]==a[1,i]==a[2,i]==0:
        ans=1
        break
if a[0,0]==a[1,1]==a[2,2]==0:
    ans=1
elif a[0,2]==a[1,1]==a[2,0]==0:
    ans=1

if ans==1:
    print('Yes')
else:
    print('No')

    

Measured memory_bytes: 12488
N,M = map(int,input().split())
q = ["WA" for i in range(N)]
wa_list = [0 for i in range(N)]
ac_list = [0 for i in range(N)]
wa = 0
ac = 0
for i in range(M):
    p,s = map(str,input().split())
    if s == "WA" and q[int(p)-1] == "WA":
        wa_list[int(p)-1]+=1
    elif s == "AC" and q[int(p)-1] == "WA":
        q[int(p)-1] = "AC"
        ac_list[int(p)-1] = wa_list[int(p)-1]
        #ac+=1
ac = q.count("AC")
wa = sum(ac_list)
print(ac,wa)

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

int main(void){
    ll x, k, d;
    cin >> x >> k >> d;
    x = abs(x);

    ll m;
    m = ceil((double)x/d);

    ll ans;
    if (m > k) ans = x - k*d;
    else if ((k-m)%2 == 0) ans = abs(x-m*d);
    else ans = x - (m-1)*d;
    
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
  	using namespace std;
  	typedef long long int ll;
    int main() {
  		// #ifndef ONLINE_JUDGE
  		// 	// for getting input from input.txt
  		// 	freopen("input.txt", "r", stdin);
  		// 	// for writing output to output.txt
  		// 	freopen("output.txt", "w", stdout);
  		// #endif
      ios_base::sync_with_stdio(false);
      cin.tie(NULL);
      ll n,k=0,l=0,b=0;
      cin>>n;
      vector<ll> v(n+1,0);
      for (ll i = 0; i < n; ++i)
        {
          cin>>v[i];            
        }  
      sort(v.begin(), v.end());
      

      for (int i = 0; i < n; i +=2)
      {
        if(v.at(i) == v.at(i+1)){
          l = b;
          b = v[i];
        }
        else{
          i--;
        }
      }
      cout<<l*b<<"\n";
}


Measured memory_bytes: 1024
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>

using namespace std;

vector<pair<int,int> >area[100005];
int ranking[100005];
int P[100005];
int Y[100005];
int visit[100005];

int main(){

	int N,M;

	scanf("%d %d",&N,&M);

	int i,j;

	for(i=0;i<M;i++){
		scanf("%d %d",&P[i],&Y[i]);
		area[P[i]].push_back(make_pair(Y[i],i));
	}

	for(i=0;i<M;i++){
		if(visit[P[i]]==0){
			sort(area[P[i]].begin(),area[P[i]].end());
			for(j=0;j<area[P[i]].size();j++){
				ranking[area[P[i]][j].second+1]=j+1;
			}
		}
		visit[P[i]]=1;
	}
	for(i=0;i<M;i++){
		printf("%06d%06d\n",P[i],ranking[i+1]);
	}

	return 0;
}

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


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll a,b,n;
  cin >> a >> b >> n;

  ll c = min(b-1,n);
  cout << (a * c) /b << endl;

  return 0;
    

}


Measured memory_bytes: 3652
#[allow(unused_imports)]
use std::cmp::{Ordering};

#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};

#[allow(unused_imports)]
use std::io::{stdin, stdout, BufWriter, Write};

#[allow(unused_imports)]
use std::iter::FromIterator;

#[allow(unused_macros)]
macro_rules! min {
    ($x: expr) => ($x);
    ($x: expr, $($z: expr),+) => {{
        std::cmp::min($x, min!($($z),*))
    }}
}

#[allow(unused_macros)]
macro_rules! max {
    ($x: expr) => ($x);
    ($x: expr, $($z: expr),+) => {{
        std::cmp::max($x, max!($($z),*))
    }}
}

#[allow(unused_macros)]
macro_rules! get { 
    ([$t: ty]) => { 
        { 
            let mut line = String::new(); 
            stdin().read_line(&mut line).unwrap(); 
            line.split_whitespace().map(|t|t.parse::<$t>().unwrap()).collect::<Vec<_>>()
        }
    };
    ([$t: ty];$n: expr) => {
        (0..$n).map(|_|get!([$t])).collect::<Vec<_>>()
    };
    ($t: ty) => {
        {
            let mut line = String::new();
            stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t: ty),*) => {
        { 
            let mut line = String::new();
            stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            ($(iter.next().unwrap().parse::<$t>().unwrap(),)*)
        }
    };
    ($t: ty; $n: expr) => {
        (0..$n).map(|_|get!($t)).collect::<Vec<_>>()
    };
    ($($t: ty),*; $n: expr) => {
        (0..$n).map(|_|get!($($t),*)).collect::<Vec<_>>()
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*).unwrap();
    }
}

const BIG_STACK_SIZE: bool = true;

#[allow(dead_code)]
fn main() {
    use std::thread;
    if BIG_STACK_SIZE {
        thread::Builder::new()
            .stack_size(32 * 1024 * 1024)
            .name("solve".into())
            .spawn(solve)
            .unwrap()
            .join()
            .unwrap();
    } else {
        solve();
    }
}

fn solve() {
    let n = get!(usize);
    let mut a = get!([usize]);

    a.sort_by(|e1,e2| e2.cmp(&e1));
    let mut sum = 0;
    for i in 0..2*n {
        if i % 2 == 1 {
            sum += a[i];
        }
    }
    println!("{}", sum);
}


Measured memory_bytes: 18160
#include <bits/stdc++.h>
 
#pragma GCC optimize("O2")
using namespace std;
#define ll long long
#define ull unsigned long long
#define rep(i,n,N) for(ll i=n;i<=N;++i)
#define rap(i,n,N) for(ll i=n;i>=N;--i)
#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define fi first
#define se second
#define ff fi.fi
#define fs fi.se
#define sf se.fi
#define ss se.se
#define lc (id<<1)
#define rc ((id<<1)|1)
#define db(x) cout << ">>>>>> " << #x << " -> " << x << endl;
#define all(x) x.begin(),x.end()
#define pii pair<int,int> 
#define pll pair<ll,ll>
#define piii pair<int,pii>
#define plll pair<ll,pii>
#define piiii pair<pii,pii>
#define psi pair<string,int>
//#define endl "\n"
const int MAX = 1e3+5;
const ll MAX2 = 11;
const ll MOD = 1000000007;
const ll INF = 1e18;
const int dr[]={1,0,-1,0,1,1,-1,-1,0};
const int dc[]={0,1,0,-1,1,-1,1,-1,0};
const double pi = acos(-1);
const double EPS = 1e-9;
const int block = 450;

int n,x;
set<int> s;

int main(){
//	cout<<fixed<<setprecision(15);
//    freopen("output.txt", "r", stdin);
//	freopen("output.txt","w",stdout);
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cin>>n;
    while(n--){
    	cin>>x;
    	if(s.count(x))s.erase(x);
    	else s.insert(x);
	}
	cout<<s.size()<<endl;
	return 0;
}

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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void Main() {
    ll H, W, K; cin >> H >> W >> K;
    ll a[H][W];
    rep(i, H){
        string tmp; cin >> tmp;
        rep(j, W){
            if (tmp[j] == '#'){
                a[i][j] = 1;
            } else {
                a[i][j] = 0;
            }
        }
    }

    ll cnt = 0;
    for (int rbit = 0; rbit < (1<<H); ++rbit) { // 1を左に2回シフトすると100
        vector<int> R;
        for (int i = 0; i < H; ++i) {
            if (rbit & (1<<i)) { // 列挙に i が含まれるか
                R.push_back(i);
            }
        }

        for (int cbit = 0; cbit < (1<<W); ++cbit) { // 1を左に2回シフトすると100
            vector<int> C;
            for (int i = 0; i < W; ++i) {
                if (cbit & (1<<i)) { // 列挙に i が含まれるか
                    C.push_back(i);
                }
            }

            // ひたすら探索
            ll tmp = 0;
            for (auto r: R){
                for (auto c: C){
                    tmp += a[r][c];
                }
            }
            if (tmp == K){cnt++;}
        }
    }
    cout << cnt << endl;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}


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

int main()
{
    int N, X, T;
    cin >> N >> X >> T;

    int result = (N / X) * T;
    if (N % X != 0)
    {
        result += T;
    }

    cout << result << endl;

    return 0;
}

Measured memory_bytes: 3632
def func(d, x, y):
    n = int("9" * x + "0" * y)
    return d == 0 if x < 1 else sum(func(d + i * n, x - 2, y + 1) * (10 - abs(i) - (y < 1)) for i in range(-9, 10) if abs(d + i * n) < n)
D = input();print sum(func(D, i, 0) * (10 - i % 2 * 9) for i in range(1, 21))

Measured memory_bytes: 2568
#include <cstdio>
#include <algorithm>

using namespace std;

int main() {
  char s[9];
  scanf("%s", s);
  sort(s, s + 4);
  puts(s[0] == s[1] && s[2] == s[3] && s[0] != s[2] ? "Yes" : "No");
}


Measured memory_bytes: 128
#include<iostream>
using namespace std;
int main(){
	int D;
	cin >> D;
	if (D == 25)cout << "Christmas" << endl;
	if (D == 24)cout << "Christmas Eve" << endl;
	if (D == 23)cout << "Christmas Eve Eve" << endl;
	if (D == 22)cout << "Christmas Eve Eve Eve" << endl;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int MX = 105;
#define rep(i,n) for(int i=0; i<(n); i++)
int n, m, a, pr[MX], w, b[MX][MX];
set<int> st[MX];
bool used[MX];
bool dfs(int v){
	used[v] = true;
	for(int it: st[v]) if((w = pr[it/m]) < 0 || (!used[w] && dfs(w))){
		pr[it/m] = v;
		return true;
	}
	return false;
}
int main(){
	scanf("%d%d", &n, &m);
	rep(i,n) rep(j,m){
		scanf("%d", &a);
		st[i].insert(a-1);
	}
	rep(i,m){
		fill(pr, pr+n, -1);
		rep(j,n){
			fill(used,used+n,0);
			dfs(j);
		}
		rep(j,n){
			w = pr[j];
			auto it = st[w].lower_bound(j*m);
			b[i][w] = *it;
			st[w].erase(it);
		}
	}
	rep(i,n) rep(j,m) printf("%d%c", b[j][i]+1, j<m-1?' ':'\n');
	rep(i,m) sort(b[i],b[i]+n);
	rep(i,n) rep(j,m) printf("%d%c", b[j][i]+1, j<m-1?' ':'\n');
}

Measured memory_bytes: 896
a,b = gets.chomp.split(" ").map(&:to_i)

def div100(x)
  if x % 100 != 0 then
    0
  else
    div100(x / 100) + 1
  end
end

i = 0;
cnt = 0;
while true do
  i += 1
  cnt += 1 if div100(i) == a
  break if cnt == b
end

puts i


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

int max(int a, int b){
    if(a>=b) return a;
    return b ; 

}

int main()
{

  int n ;
  cin >> n ;
  int h[n] ;
  for(int i=0;i<n;i++) cin >> h[i] ;

  int ans = 0;
  int cnt = 0;

  for(int i=0;i<n-1;i++){
      if(h[i+1]<=h[i]){
          cnt++ ;
      }else{
          cnt = 0;
      }
        ans = max(cnt,ans) ;
  }

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



Measured memory_bytes: 640
def array_integer(a)
	0.upto(a.count) {|x|
		a[x] = a[x].to_i
	}
	return a
end

a,b,c = array_integer(STDIN.gets.split(" "))
divisor_count = 0
a.upto(b) {|x|
	if (c % x) == 0 then
		divisor_count += 1
	end
}

puts divisor_count



Measured memory_bytes: 6860
#include <iostream>
#include <set>
#include <string>
#include <algorithm>
#define MAX 1000000001

using namespace std;
#define ll long long
#define dbg if(0)



int main(){
    int n,s;
    int ans=MAX;
    cin>>n>>s;
    ll rui[n+1];
    rui[0]=0;
    for(int i=0;i<n;i++){
        cin>>rui[i+1];
        rui[i+1]+=rui[i];
    }
    int right=0;
    int left=0;
    while(right<=n){
        if(rui[right]-rui[left]>=s){
            ans=min(ans,right-left);
            left++;
        }else{
            right++;
        }
    }
    if (ans==MAX)ans=0;
    cout<<ans<<endl;
    return 0;
}



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

#define REP(i, start, count) for (int i = (start); i < (int)(count); ++i)
#define rep(i, count) REP(i, 0, count)
#define ALLOF(c) (c).begin(), (c).end()

typedef long long ll;
typedef unsigned long long ull;

int N,M;

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

    ll ans = 0;
    ans += max(0, (N * (N - 1)) / 2);
    ans += max(0, (M * (M - 1)) / 2);

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=2e6+5;
int p[N],a[N],b[N];
struct node{int l,r,mid,mn;}s[N<<2];
void build(int di,int l,int r){
	s[di].l=l,s[di].r=r,s[di].mid=l+r>>1,s[di].mn=1e9;
	if(l==r)return;
	build(di<<1,l,s[di].mid),build(di<<1|1,s[di].mid+1,r);
}
void ins(int di,int x,int v){
	if(s[di].l==s[di].r){s[di].mn=v;return;}
	if(x<=s[di].mid)ins(di<<1,x,v);
	else ins(di<<1|1,x,v);
	s[di].mn=min(s[di<<1].mn,s[di<<1|1].mn);
}
int qry(int di,int l,int r){
	if(l<=s[di].l&&s[di].r<=r)return s[di].mn;
	else if(r<=s[di].mid)return qry(di<<1,l,r);
	else if(l>s[di].mid)return qry(di<<1|1,l,r);
	return min(qry(di<<1,l,r),qry(di<<1|1,l,r));
}
struct edge{int to,nxt;}e[N<<1];
int head[N],tot=1;
void adde(int x,int y){e[tot]=(edge){y,head[x]};head[x]=tot++;}
priority_queue< int,vector<int>,greater<int> > q;
int n,rd[N];
void topo(){
	for(int i=1;i<=n;i++)
		for(int j=head[i];j;j=e[j].nxt)rd[e[j].to]++;
	for(int i=1;i<=n;i++)if(!rd[i])q.push(i);
	int tt=0;
	while(!q.empty()){
		int u=q.top();q.pop();
		// b[++tt]=u;
		p[u]=++tt;
		for(int i=head[u];i;i=e[i].nxt)
			if(!(--rd[e[i].to]))q.push(e[i].to);
	}
}
int main(){
	int k;scanf("%d%d",&n,&k);
	for(int i=1;i<=n;i++){int x;scanf("%d",&x),a[x]=i;}
	build(1,1,n);
	for(int i=n;i>=1;i--){
		int x=qry(1,max(1,a[i]-k+1),a[i]);
		if(x>=1&&x<=n)adde(a[i],a[x]);
		x=qry(1,a[i],min(n,a[i]+k-1));
		if(x>=1&&x<=n)adde(a[i],a[x]);
		ins(1,a[i],i);
	}
	topo();
	// for(int i=1;i<=n;i++)p[b[i]]=i;
	for(int i=1;i<=n;i++)printf("%d\n",p[i]);
}


Measured memory_bytes: 46720
import numpy as np
n,w = [int(x) for x in input().split()]
wv = np.array([[int(y) for y in input().split()] for z in range(n)],dtype=int)
sum_wv = np.sum(wv,axis=0)
sum_v = sum_wv[1]
sum_w = sum_wv[0]
dp = np.full(sum_v+1,sum_w,dtype="int")
dp[0] = 0
for wei,val in wv:
    dp[val:] = np.minimum(dp[val:],dp[:-val]+wei)
for p in range(sum_v,1,-1):
    if(dp[p] <= w):
        print(p)
        break

Measured memory_bytes: 14788
#include <set>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <cstdlib>
#include <complex>

#define REP(i,n) for(int i=0; i<(int)(n); i++)
inline int getInt(){ int s; scanf("%d", &s); return s; }

using namespace std;

typedef complex<double> P;

int main(){
  while(const int n = getInt()){
    vector<P>   pos(n);
    vector<double> v(n);

    REP(i,n){
      const int x = getInt();
      const int y = getInt();
      v[i] = getInt();
      pos[i] = P(x, y);
    }

    const double r = 0.99;
    P p(0, 0);

    auto calc = [&](P p){
      auto mx = make_pair(0.0, 0);
      REP(i,n) mx = max(mx, make_pair(abs(p - pos[i]) / v[i], i));
      return mx;
    };

    for(double d = 1000; d > 1e-8; d *= r){
      auto mx = calc(p).second;
      p += (pos[mx] - p) / abs(pos[mx] - p) * d;
    }

    printf("%.8f\n", calc(p).first);
  }

  return 0;
}

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

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

    int counta = 0, countb = 0;
    if(s[0] == 'A') counta++;
    else countb++;
    if(s[1] == 'A') counta++;
    else countb++;
    if(s[2] == 'A') counta++;
    else countb++;

    if(counta == 3 || counta == 0) {
        cout << "No" << endl;
    } else {
        cout << "Yes" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

var sc = bufio.NewScanner(os.Stdin)

func main() {
	var nk string
	if sc.Scan() {
		nk = sc.Text()
	}

	nkArr := strings.Split(nk, " ")

	n, _ := strconv.Atoi(nkArr[0])
	k, _ := strconv.Atoi(nkArr[1])

	sum := 0
	for i := k; i <= n+1; i++ {
		min := (i - 1) * i / 2
		max := (2*n - i + 1) * i / 2

		sum += (max - min + 1)
	}

	ans := sum % 1000000007

	fmt.Print(ans)
}


Measured memory_bytes: 1756
N = int(input())
X = []
music = []
time = []
for i in range(N):
  X.append(list(map(str,input().split())))
  music.append(X[i][0])
  time.append(int(X[i][1]))
S = input()

sleep_index = music.index(S)
print(sum(time[sleep_index+1:]))

Measured memory_bytes: 3064
#include <stdio.h>
int main(void)
{
	int a,b,c;
	scanf("%d %d",&a,&b);
	c=a+b;
	if (c==0)
	{
		printf("0\n");
	}
	else if (c>=1)
	{
		printf("1\n");
	}
	else if (a<=-1)
	{
		printf("-1\n");
	}
	return 0;
}

Measured memory_bytes: 2624
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
using namespace std;
typedef pair<int,int> pi;

vector<pi> cont[26];

inline int map(char t){
	if(t <= 'z' && t >= 'a') return t - 'a';
	if(t <= 'Z' && t >= 'A') return t - 'A' + 26;
	return 10000;
}

int dp[51][51][51][51];
bool go[51][51][51][51];

int n, m;
char a[55][55];

int f(int sx, int sy, int ex, int ey){
//	fprintf(stderr,"%d %d %d %d\n",sx,sy,ex,ey);
	if(sx == ex && sy == ey) return 0;
	if(sx > ex || sy > ey) return -1e9;
	if(!go[ex][ey][sx][sy]) return -1e9;
	if(~dp[sx][sy][ex][ey]) return dp[sx][sy][ex][ey];
	int ret = 0;
	if(go[sx+1][sy][sx][sy]) ret = max(ret, f(sx+1, sy, ex, ey));
	if(go[sx][sy+1][sx][sy]) ret = max(ret, f(sx, sy+1, ex, ey));
	if(ex && go[ex][ey][ex-1][ey]) ret = max(ret, f(sx, sy, ex-1, ey));
	if(ey && go[ex][ey][ex][ey-1]) ret = max(ret, f(sx, sy, ex, ey-1));
	if(map(a[sx][sy]) + 26 == map(a[ex][ey])){
		int ret2 = 0;
		if(ex && go[sx+1][sy][sx][sy] && go[ex][ey][ex-1][ey]) ret2 = max(ret2, f(sx+1, sy, ex-1, ey));
		if(ex && go[sx][sy+1][sx][sy] && go[ex][ey][ex-1][ey]) ret2 = max(ret2, f(sx, sy+1, ex-1, ey));
		if(ey && go[sx+1][sy][sx][sy] && go[ex][ey][ex][ey-1]) ret2 = max(ret2, f(sx+1, sy, ex, ey-1));
		if(ey && go[sx][sy+1][sx][sy] && go[ex][ey][ex][ey-1]) ret2 = max(ret2, f(sx, sy+1, ex, ey-1));
		ret = max(ret, ret2+1);
	}
	if(0 <= map(a[sx][sy]) && map(a[sx][sy]) <= 25){
		for(auto &i : cont[map(a[sx][sy])]){
			if(go[i.first][i.second][sx][sy] && go[ex][ey][i.first][i.second]){
				if(ex == i.first && ey == i.second) continue;
				ret = max(ret, f(sx, sy, i.first, i.second) + f(i.first, i.second, ex, ey));
			}
		}
	}
	return dp[sx][sy][ex][ey] = ret;
}

void solve(){
	for(int i=0; i<n; i++){
		scanf("%s",a[i]);
	}
	for(int i=0; i<n; i++){
		for(int j=0; j<m; j++){
			if(map(a[i][j]) <= 51 && map(a[i][j]) >= 26){
				cont[map(a[i][j]) - 26].push_back(pi(i,j));
			}
			if(a[i][j] == '#') continue;
			go[i][j][i][j] = 1;
			for(int k=i; k>=0; k--){
				for(int l=j; l>=0; l--){
					if(a[k][l] != '#'){
						go[i][j][k][l] |= (go[i][j][k+1][l] | go[i][j][k][l+1]);
					}
				}
			}
		}
	}
	printf("%d\n",max(-1,f(0,0,n-1,m-1)));
}

int main(){
	while(1){
		memset(dp,-1,sizeof(dp));
		memset(go,0,sizeof(go));
		memset(a,0,sizeof(a));
		for(int i=0; i<26; i++) cont[i].clear();
		scanf("%d %d",&n,&m);
		if(n == 0 && m == 0) break;
		solve();
	}
}

Measured memory_bytes: 34080
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iomanip>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

#define DEBUG

#ifdef DEBUG
#define var_dump(...) fprintf(stdout, __VA_ARGS__)
#define dump(a) cout << a << "\n";
#else
#define var_dump(...) 42
#define dump(a) 42
#endif

typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

int dy4[]={0, 0, 1, -1};
int dx4[]={1, -1, 0, 0};
int dx8[]={0, 0, 1, -1, 1, 1, -1, -1};
int dy8[]={1, -1, 0, 0, 1, -1, -1, 1};

// https://beta.atcoder.jp/contests/abc096/tasks/abc096_b

int main() {
    int A[3];
    for (int i = 0; i < 3; i++) {
        cin >> A[i];
    }
    sort(A, A+3);
    int K; cin >> K;

    for (int i = 0; i < K; i++) {
        A[2] *= 2;
    }

    printf("%d\n", A[0]+A[1]+A[2]);

    return 0;
}


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

typedef long long ll;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int h, n;
  cin >> h >> n;
  int a, sum;
  sum = 0;
  for(int i = 0; i < n; i++) {
    cin >> a;
    sum += a;
  }
  if(sum >= h) {
    cout << "Yes";
  } else {
    cout << "No";
  }
  return 0;
}



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

int main() {
  int H1, M1, H2, M2, K;
  cin >> H1 >> M1 >> H2 >> M2 >> K;
  H1*=60;
  H2*=60;
  cout << H2+M2-H1-M1-K << endl;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
#include <vector>
#include <numeric>
#define PI 3.14159265358979323846
#define MAXINF 1e18L
#define MININF -1e18L
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define ALL(v) v.begin(),v.end()
#define SORT(v) sort(ALL(v))
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define pb push_back
using namespace std;
template<class A>void pr(A a){cout << (a) << endl;}
template<class A,class B>void pr(A a,B b){cout << a << " "  ;pr(b);}
template<class A,class B,class C>void pr(A a,B b,C c){cout << a << " " ;pr(b,c);}
template<class A,class B,class C,class D>void pr(A a,B b,C c,D d){cout << a << " " ;pr(b,c,d);}
typedef long long ll;
typedef pair<int, int> intint;

int main(void)
{
    int x;
    cin >> x;
    if(x==7||x==5||x==3)
        pr("YES");
    else 
        pr("NO");
}


Measured memory_bytes: 256
# カードの数を受け取る
n = int(input())

# スコア変数を定義
t_score = 0
h_score = 0

# カードを受け取って処理実行
for i in range(n):
    inp = input()
    inp_list = [j for j in inp.split()]
    t, h = inp.split()
    srtd_inp_list = sorted(inp_list)
    if inp_list[0] == inp_list[1]:
        t_score += 1
        h_score += 1
    elif inp_list[0] != srtd_inp_list[0]:
        t_score += 3
    else:
        h_score += 3

print(f"{t_score} {h_score}")



Measured memory_bytes: 5612
# frozen_string_literal: true

# induce sort (internal routine)
def sa_is_induce(s, ls, sum_l, sum_s, lms)
  n = s.size
  sa = [-1]*n

  buf = *sum_s # deep copy
  lms.each{ |lms|
    if lms != n then
      sa[buf[s[lms]]] = lms
      buf[s[lms]] += 1
    end
  }

  buf = *sum_l # deep copy
  sa[buf[s[-1]]] = n-1
  buf[s[-1]] += 1
  sa.each{ |v|
    if v>=1 && !ls[v-1] then
      sa[buf[s[v-1]]] = v-1
      buf[s[v-1]] += 1
    end
  }

  buf = *sum_l # deep copy
  sa.reverse_each{ |v|
    if v>=1 && ls[v-1] then
      buf[s[v-1]+1] -= 1
      sa[buf[s[v-1]+1]] = v-1
    end
  }

  return sa
end

# SA-IS (internal routine)
def sa_is(s, upper)
  n = s.size

  return [] if n == 0
  return [0] if n == 1

  ls = [false]*n
  (n-2).downto(0){ |i|
    ls[i] = s[i]==s[i+1] ? ls[i+1] : s[i]<s[i+1]
  }

  sum_l = [0]*(upper+1)
  sum_s = [0]*(upper+1)
  n.times{ |i|
    if ls[i] then
      sum_l[s[i]+1] += 1
    else
      sum_s[s[i]] += 1
    end
  }
  0.upto(upper){ |i|
    sum_s[i] += sum_l[i]
    sum_l[i+1] += sum_s[i] if i<upper
  }

  lms = (1 ... n).select{ |i| !ls[i-1] && ls[i] }
  m=lms.size
  lms_map = [-1]*(n+1)
  lms.each_with_index{ |lms, id| lms_map[lms] = id }

  sa = sa_is_induce(s, ls, sum_l, sum_s, lms)

  return sa if m == 0

  sorted_lms = sa.select{ |sa| lms_map[sa] != -1 }
  rec_s = [0]*m
  rec_upper = 0
  rec_s[lms_map[sorted_lms[0]]] = 0
  1.upto(m-1){ |i|
    l, r = sorted_lms[i-1, 2]
    end_l = lms[lms_map[l]+1]||n
    end_r = lms[lms_map[r]+1]||n
    same = true
    if end_l-l != end_r-r then
      same = false
    else
      while l < end_l do
        break if s[l] != s[r]
        l+=1
        r+=1
      end
      same = false if l==n || s[l]!=s[r]
    end
    rec_upper += 1 if not same
    rec_s[lms_map[sorted_lms[i]]] = rec_upper
  }

  sa_is(rec_s, rec_upper).each_with_index{ |rec_sa, id|
    sorted_lms[id] = lms[rec_sa]
  }

  return sa_is_induce(s, ls, sum_l, sum_s, sorted_lms)
end

# suffix array for array of integers or string
def suffix_array(s, upper = nil)
  if not upper then
  	case s
  	when Array
      # compression
      n = s.size
      idx = (0 ... n).sort_by{ |i| s[i] }
      t = [0]*n
      upper = 0
      t[idx[0]] = 0
      1.upto(n-1){ |i|
        upper += 1 if s[idx[i-1]] != s[idx[i]]
        t[idx[i]] = upper
      }
      s = t
    when String
      upper = 255
      s = s.chars.map(&:ord)
    end
  end
  return sa_is(s, upper)
end

# frozen_string_literal: true

# lcp array for array of integers or string
def lcp_array(s, sa)
  s = s.chars.map(&:ord) if s === String

  n = s.size
  rnk = [0]*n
  sa.each_with_index{ |sa, id|
    rnk[sa] = id
  }
  
  lcp = [0]*(n-1)
  h = 0
  n.times{ |i|
    h -= 1 if h > 0
    next if rnk[i] == 0
    j = sa[rnk[i]-1]
    h += 1 while j+h<n && i+h<n && s[j+h]==s[i+h]
    lcp[rnk[i]-1] = h
  }
  return lcp
end

s = gets.chomp
lcp = lcp_array(s, suffix_array(s))
ans = s.size*(s.size+1)/2
lcp.each{ |lcp| ans -= lcp }
puts ans


Measured memory_bytes: 92508
#include<bits/stdc++.h>
using namespace std;
int read(){
	int w=0,f=1;
	char c=' ';
	while(c<'0'||c>'9')c=getchar(),f=c=='-'?-1:f;
	while(c>='0'&&c<='9')w=w*10+c-48,c=getchar();
	return w*f;
}
char s[33][33];
int n=read(),m=read();
int p[33],a[33];
string t[33];
bool check(int l,int r) 
{
    for(int i=0; i<n; i++) if(s[i][l]!=s[p[i]][r]) return 0;
    return 1;
}
void dfscol(int d,bool b) 
{
    if(d==m) puts("YES"),exit(0);
    if(a[d]!=-1) { dfscol(d+1,b); return; }
    for(int i=d+1; i<m; i++) if(a[i]==-1&&check(d,i)) a[d]=i,a[i]=d,dfscol(d+1,b),a[d]=-1,a[i]=-1;
    if(b&&check(d,d)) a[d]=d,dfscol(d+1,0),a[d]=0;
}
void dfsrow(int d,bool b) 
{
    if(d==n) { dfscol(0,m&1); return; }
    if(p[d]!=-1) { dfsrow(d+1,b); return; }
    for(int i=d+1; i<n; i++) if(p[i]==-1&&t[d]==t[i]) p[d]=i,p[i]=d,dfsrow(d+1,b),p[d]=-1,p[i]=-1;
    if(b) p[d]=d,dfsrow(d+1,0),p[d]=0;
}
signed main() 
{
    memset(p,-1,sizeof(p)),memset(a,-1,sizeof(a)); 
    for(int i=0; i<n; i++) 
	{
        scanf("%s",s[i]);
        for(int j=0; j<m; j++) t[i]+=s[i][j];
        sort(t[i].begin(),t[i].end());
    }
    dfsrow(0,n&1),puts("NO");
    return 0;
}

Measured memory_bytes: 3772
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
#define rep(i, a, n) for (ll i = (a); i < (n); i++)
#define debug(x) cerr << #x << ": " << x << endl;
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;}

int main() {
    ll x, a;
    cin >> x >> a;
    if (x < a) cout << 0 << endl;
    else cout << 10 << endl;
}

Measured memory_bytes: 256
import java.util.*;

class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] v = new int[n];
    for(int i=0; i<n; i++){
      v[i] = sc.nextInt();      
    }
    int[] c = new int[n];
    for(int i=0; i<n; i++){
      c[i] = sc.nextInt();
    }
    
    int ans = 0;
    
    for(int i=0; i<n; i++){
      if((v[i]-c[i])>0){
        ans += (v[i]-c[i]);
      }
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 23892
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
    ll i,j,k,t,n,a,b;
    cin>>n;
    ll c=0;

    //ll ara[20000]={0};
    map<ll,ll>m;
    for(i=1;i<=100;i++)
    {
        for(j=1;j<=100;j++)
        {
            for(k=1;k<=100;k++)
            {
                a=i*i+j*j+k*k+i*j+j*k+k*i;
                m[a]++;
                if(a>10000)
                {
                    break;
                }
            }
        }
    }
    for(i=1;i<=n;i++)
    {
        cout<<m[i]<<endl;
    }
    return 0;
}


Measured memory_bytes: 4212
function main(){
  var i = 0;
  while(true){
    var fieldInfo = input[i].split(' ');
    var width = fieldInfo[0] - 0;//toInt
    var height = fieldInfo[1] - 0;//toInt
    
    // 0 0が入力された
    if(!width && !height){
      break;
    }
    
    var start;
    var goal;
    var elem = [[],[],[],[],[]];
    for(var ei = 0;ei < 5; ei++){
      elem[ei].length = 0;
    }
        
    for(var y = 0; y < height; y++){
      i++;//1行進める
      for(var x = 0; x < width; x++){
        var c = input[i][x];
    
        switch(c){
        case 'S':
          start = pos(x, y);
          break;
        case 'G':
          goal = pos(x, y);
          break;
        case '.':
          break;
        default : // 入力値が正しいので、絶対に属性
          elem[c - 1][elem[c - 1].length] = pos(x, y);
          break;
        }
      }
    }
    
    var INF = 1 << 30;
    var bestElement = -1;
    var distance = INF;
        
    // 属性ごとにループ
    for (var startElem = 0; startElem < 5; startElem++) {
      // DPの初期化 DP[属性][同じ属性内の連番]
      var dp = [[],[],[],[],[]];
      for(var h = 0; h < 5; h++){
        var hLength = elem[h].length;
        dp[h].length = hLength;
        for(var hidx = 0; hidx < hLength; hidx++){
          dp[h][hidx] = INF;
        }
      }
          
      // 最初に選んだパチモンから次に捕まえられる属性番号
      var first = (startElem + 1) % 5;
      for (var j = elem[first].length; j--; ) {
        // s→e1を計算
        dp[first][j] = dist(start, elem[first][j]);
      }
          
      // s->1->2->3->4->g
      // なので、ループは間の-> * 3分まわす
      for (var e = 0; e < 3; e++) {
        // ex->e(x+1)
        var now = (first + e) % 5;
        var next = (now + 1) % 5;
        for (var j = elem[now].length; j--; ) {
          for (var k = elem[next].length; k--; ) {
            dp[next][k] = fmin(
              dp[next][k],
              dp[now][j] + 
                  dist(elem[now][j], elem[next][k]));
          }
        }
      }
          
      var last = (first + 3) % 5;
      for (var j = elem[last].length; j--; ) {
        // e4->g
        var d = dp[last][j] + 
                    dist(elem[last][j], goal);
            
        if (d < distance) {
          distance = d;
          bestElement = startElem + 1;
        }
            
      }
          
    }
        
    if (distance == INF) {
      console.log("NA");
    } else {
      console.log(bestElement + " " + distance);
    }
    
    i++;
  }
      
    
}
    
function dist(from, to){
  // x座標とy座標の切り出し(11ビット右シフトでxを、2047(下位10ビット1)とのAND演算でyを取り出す)
  return fabs((from >> 11) - (to >> 11)) + fabs((from & 2047) - (to & 2047));
}
    
function fmin(a, b){
  // ビット演算で高速化
  var t = a - b;
 return b + (t & (t >> 31));
}
    
function pos(a, b){
  // 2^10 = 1024なので、下位10ビットでy座標を、上位ビットでx座標を表す
  return (a << 11) + b;
}
   
function fabs(a){
 // ビット演算で高速化
 var mask = a >> 31;
 return (a ^ mask) - mask;
}
    
var
input = '';
    
process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', function(chunk) {
  input += chunk;
});
process.stdin.on('end', function() {
  input = input.split('\n');
  main();
});

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

int main(){
string a, b;
cin >> a >> b;
string ans = a + b;
int an = stoi(ans);
for(int i = 0; i * i <=an; i++){
  if(i * i == an) {
    cout << "Yes" << "\n";
    return 0;
  }
}
  cout << "No" << "\n";
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
/*{{{*/  //template
#define rep(i,n) for(int i=0;i<(int)(n);i++)
constexpr int INF = numeric_limits<int>::max()/2;
constexpr long long LINF = numeric_limits<long long>::max()/3;
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define sz(x) (int)(x).size()
#define debug(x) cerr<<#x<<":"<<x<<endl
#define debug2(x,y) cerr<<#x<<","<<#y":"<<x<<","<<y<<endl
//struct fin{ fin(){ cin.tie(0); ios::sync_with_stdio(false); } } fin_;
struct Double{ double d; explicit Double(double x) : d(x){} };
ostream& operator<<(ostream& os,const Double x){ os << fixed << setprecision(20) << x.d; return os; }
template<typename T> ostream& operator<<(ostream& os,const vector<T>& vec){ os << "["; for(const auto& v : vec){ os << v << ","; } os << "]"; return os; }
template<typename T,typename U> ostream& operator<<(ostream& os,const pair<T,U>& p){ os << "(" << p.first << ","<< p.second <<")"; return os; }
template<typename T> ostream& operator<<(ostream& os,const set<T>& st){ os<<"{"; for(T v:st) os<<v<<","; os <<"}"; return os; }
template<typename T,typename U> inline void chmax(T &x,U y){ if(y>x) x = y; }
template<typename T,typename U> inline void chmin(T &x,U y){ if(y<x) x = y; }
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
ll gcd(ll a,ll b){ if(b==0) return a; else return gcd(b,a%b); }
//constexpr double eps = 1e-14; 
constexpr double eps = 1e-10; 
constexpr ll mod = 1e9+7;
const int dx[]={1,0,-1,0} ,dy[] = {0,1,0,-1};
/*}}}*/

double dp[3001][3001];

int main(){
    int N; cin >> N;
    vector<double> p(N);
    for(int i=0;i<N;i++) cin >> p[i];

    // dp[i][j] := i枚中j枚が表を向く確率
    dp[0][0] = 1;
    for(int i=0;i<N;i++){
        for(int j=0;j<=i;j++){
            dp[i+1][j+1] += dp[i][j] * (p[i]); 
            dp[i+1][j]   += dp[i][j] * (1-p[i]);
        }
    }

    double ans = 0;
    for(int i=(N+1)/2;i<=N;i++){
        ans += dp[N][i];
    }
    cout << Double(ans) << endl;
}


Measured memory_bytes: 68992
import Data.List

main = do
  _ <- getLine
  s' <- getContents
  let s =  map (sortBy (compare)) $ map (map read)  $ map words $ lines s'
  mapM putStrLn (map yesOrno s)

yesOrno [a,b,c]
  | a^2 + b^2 == c^2 = "YES"
  | otherwise    = "NO"

Measured memory_bytes: 4292
#include <iostream>
#include <cassert>
#include <climits>
#include <bitset>
#include <stack>
#include <queue>
#include <iomanip>
#include <limits>
#include <string>
#include <cmath>
#include <set>
#include <map>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string.h>
#include <tuple>
#include <time.h>

using namespace std;

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

long long int INF = 3e18;
double Pi = 3.1415926535897932384626;

vector<ll> G[500005];
vector<P> tree[500010];
priority_queue <ll> pql;
priority_queue <P> pqp;
//big priority queue
priority_queue <ll,vector<ll>,greater<ll> > pqls;
priority_queue <P,vector<P>,greater<P> > pqps;
//small priority queue
//top pop

int dx[8]={1,0,-1,0,1,1,-1,-1};
int dy[8]={0,1,0,-1,1,-1,-1,1};
char dir[] = "DRUL";
//ll bit[500005];
//↓,→,↑,←


#define p(x) cout<<x<<endl;
#define el cout<<endl;
#define pe(x) cout<<(x)<<" ";
#define ps(x) cout<<fixed<<setprecision(25)<<x<<endl;
#define pu(x) cout<<(x);
#define pd(x) cerr<<"//"<<(x)<<endl;
#define re(i,n) for(i=0;i<n;i++);
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define deba(x) cout<< #x << " = " << x <<endl


ll mod = 1000000007;
ll rui(ll number1,ll number2){
    if(number2 == 0){
        return 1;
    }else{
        ll number3 = rui(number1,number2 / 2);
        number3 *= number3;
        number3 %= mod;
        if(number2%2==1){
            number3 *= number1;
            number3 %= mod;
        }
        return number3;
    }
}
ll gcd(ll number1,ll number2){
    if(number1 > number2){
        swap(number1,number2);
    }
    if(number1 == 0 || number1 == number2){
        return number2;
    }else{
        return gcd(number2 % number1,number1);
    }
}
void YES(bool condition){
    if(condition){
        p("YES");
    }else{
        p("NO");
    }
    return;
}
void Yes(bool condition){
    if(condition){
        p("Yes");
    }else{
        p("No");
    }
    return;
}

ll n,m,num,sum,ans,a,b,c,d,e,g,h,w,i,j,k,l,q;
ll x[500005],y[500005],z[500005];
ll dp[100005][205];
char s[500005],t[500005],u[500005];
bool flag,dame;

ll  fact[1200005];
ll rfact[1200005];

void c3_init(){
    fact[0] = rfact[0] = 1;
    for(ll i=1; i<1200000; i++){
        fact[i] = (fact[i-1]*i) % mod;
        rfact[i] = rui(fact[i],mod - 2);
    }
}
ll c3(ll n,ll r){
    return (((fact[n] * rfact[r]) % mod) * rfact[n-r]) % mod;
}

ll solve(ll init,ll num){
	//num以下だけでinitから始める
	//pe(init);p(num);
	if(dp[init][num] != -1){
		return dp[init][num];
	}
	if(num == 1){
		return init % x[num - 1];
	}
	ll a = solve(init % x[num-1],num - 1);
	ll b = solve(init,num - 1) * (num - 1);
	dp[init][num] = (a + b) % mod;
	return (a + b) % mod;
}

int main(){
    cin >> n >> k;
	for(i=0;i<n;i++){
		cin >> x[i];
	}
	sort(x,x+n);
	for(i=0;i<100003;i++){
		for(j=0;j<=n;j++){
			dp[i][j] = -1;
		}
	}
	ans = solve(k,n);
	p(ans);
	return 0;
}

Measured memory_bytes: 191232
#define KAKUSUKO

#include <iostream>
#include <algorithm>
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <cstring>
#include <utility>
#include <vector>
#include <complex>
#include <valarray>
#include <fstream>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <numeric>
#include <climits>
#include <random>

#define _overload(a, b, c, d, ...) d
#define _rep1(X, A, Y) for (int (X) = (A);(X) <= (Y);++(X))
#define _rep2(X, Y) for (int (X) = 0;(X) < (Y);++(X))
#define rep(...) _overload(__VA_ARGS__, _rep1, _rep2)(__VA_ARGS__)
#define rrep(X, Y) for (int (X) = Y-1;(X) >= 0;--(X))
#define all(X) (X).begin(),(X).end()
#define len(X) ((int)(X).size())
#define mod(n, m) (((n)%(m)+(m))%(m))
#define fi first
#define sc second
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> Pii;
typedef pair<ll, ll> Pll;
const int INFINT = 1 << 30;                          // 1.07x10^ 9
const ll INFLL = 1LL << 60;                          // 1.15x10^18
const double EPS = 1e-10;
const int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

const int MAX_N = 100000;
int N;
ll X[MAX_N];
ll L[MAX_N];
vector<Pll> segments;
vector<ll> lb_vec;
vector<ll> ub_vec;
int dp[MAX_N];

int main() {

    cin >> N;
    rep(i, N) cin >> X[i] >> L[i];

    rep(i, N) {
        segments.emplace_back(Pii(X[i] - L[i], X[i] + L[i]));
    }

    sort(all(segments), [](const Pii &p1, const Pii &p2) { return p1.sc < p2.sc; });
    rep(i, N) {
        lb_vec.push_back(segments[i].fi);
        ub_vec.push_back(segments[i].sc);
    }

    dp[0] = 1;
    for (int i = 1; i < N; ++i) {
        int lb = lb_vec[i];
        int idx = upper_bound(ub_vec.begin(), ub_vec.begin() + i, lb) - ub_vec.begin() - 1;
        if (idx < 0) {
            dp[i] = dp[i - 1];
        } else {
            dp[i] = max(dp[idx] + 1, dp[i - 1]);
        }
    }

    cout << dp[N - 1] << endl;

    return 0;
}


Measured memory_bytes: 6640
// ░░░░░░░░( •̪●)░░░░░░░░░░░░░░░░░░░░░░░░
// ░░░░░░███████ ]▄▄▄▄▄▄▄▄▃░░░▃░░░░ ▃░
// ▂▄▅█████████▅▄▃▂░░░░░░░░░░░░░░░░░
// [███████████████████].░░░░░░░░░░░░░░
// ◥⊙▲⊙▲⊙▲⊙▲⊙▲⊙▲⊙◤...░░░░░░░░░░░░

//PointBlank's code (⌐■_■)

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
 
ll power(ll x, ll y); 
#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 rrep(I, B, A) for(int I = B; I >= A; I--)
#define pb emplace_back
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define LB lower_bound
#define UB upper_bound
#define MP make_pair
#define mem(A, B) memset(A, B, sizeof(A));
#define mem0(A) memset(A, 0, sizeof(A));
#define quickio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define debug(this) cerr<<"> "<<#this<<" : "<<this<<"\n"
#define bitcount(n) __builtin_popcountll(n)
#define in_edges(M) repp(I, 1, M){int A, B; cin >> A >> B; v[A].pb(B), v[B].pb(A);}
#define in_edges2(M) repp(I, 1, M){int A, B; cin >> A >> B; v[A].pb(B);}
#define endl "\n"

const ll MOD = 1000000007;
 
int main() //PointBlank's code ¯\_(ツ)_/¯
{
    ll a, b;
    cin >> a >> b;
    a = __gcd(a, b);
    ll c = 0;
    repp(i, 2, 1000000) if(a % i == 0){
        c++;
        while(a % i == 0) a /= i;
    }
    if(a > 1) c++;
    cout << c + 1;
}

ll power(ll x, ll y)
{ 
    ll res = 1; x %= MOD;
    while(y > 0){if(y & 1) res = (res*x) % MOD; y = y>>1, x = (x*x) % MOD;} 
    return res; 
}

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

int a[100005];

int main(){
    int n; cin>>n;
    for(int i=1;i<=n;++i)cin>>a[i];
    sort(a+1,a+1+n);
    cout<<a[n]<<" "<<*max_element(a+1,a+n,[&](const int &x,const int &y){ return min(x,a[n]+1-x)<min(y,a[n]+1-y); })<<endl;
}


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

int main(){
int N,M;
vector<int> A(M);
cin>> N >> M ;
for (int i = 0; i < M; i++){
 cin >> A.at(i)  ;
}

int s=0;
for (int i = 0; i < M; i++){
s+=A.at(i);
}

if(N-s>=0){
cout <<N-s <<endl;
}

else{
cout << "-1" << endl;
}
}

Measured memory_bytes: 3720
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <set>
#include <string>
#include <cstring>
#include <cmath>
#include <map>
#include <stack>
#define N 1005
using namespace std;
typedef long long ll;
int a[305][305];
struct node
{
    int x;
    int y;
}p[90005];
int ans[90005];
int main()
{
    int h,w,d,len;
    scanf("%d%d%d",&h,&w,&d);
    for(int i=1;i<=h;i++)
        for(int j=1;j<=w;j++){
          scanf("%d",&a[i][j]);
          int n=a[i][j];
           p[n].x=i;
           p[n].y=j;
        }
    int q;
    len=h*w;
    scanf("%d",&q);
    for(int i=1;i<=d;i++)
    {
        int l=i,r=len,sum=0;
        ans[i]=0;
        while(l<=r-d)
        {
            sum=sum+abs(p[l].x-p[l+d].x)+abs(p[l].y-p[l+d].y);
            l=l+d;
            ans[l]=sum;
        }
 
    }
    while(q--)
    {
        int l,r;
        scanf("%d%d",&l,&r);
        printf("%d\n",ans[r]-ans[l]);
    }
}

Measured memory_bytes: 2560
from sys import stdin
n = int(stdin.readline().rstrip())
arr = list(map(int, stdin.readline().rstrip().split()))
tmp = []
count = 0

def has_duplicates(seq):
    return len(seq) == len(set(seq))

for i in range(0, len(arr)):
    for j in range(i+1, len(arr)):
        for k in range(j+1, len(arr)):
            tmp = sorted([arr[i],arr[j],arr[k]])
            if (tmp[2] < tmp[0] + tmp[1]) and (has_duplicates(tmp)):
                count += 1
print(count)

Measured memory_bytes: 9216
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue> 
#include <stack>
#include <set>
#include <list>

using namespace std;
typedef long long ll;
//#define rep(i, s, e) for (int(i) = (s); (i) < (e); ++(i))
#define rep(i, e) for (int(i) = 0; (i) < (e); ++(i))
#define all(x) x.begin(),x.end()


int main()
{
	string s, t; cin >> s >> t;
	cout << t << s << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <string>
#define MAX_LEN 200

char w[MAX_LEN + 1];
char t[MAX_LEN + 1];
int w_len = 0;
int n;
int a;

int main()
{
	while (true)
	{
		for (int i = 0; i < MAX_LEN + 1; i++)
		{
			w[i] = 0;
			t[i] = 0;
		}
		w_len = 0;

		scanf("%s", &w);
		if (w[0] == '-') break;
		scanf("%d", &n);

		for (int i = 0; i < MAX_LEN + 1; i++)
		{
			char c = w[i];
			if (c != 0)
			{
				w_len++;
			}
			else
			{
				break;
			}
		}

		for (int i = 0; i < n; i++)
		{
			scanf("%d", &a);
			for (int j = 0; j < a; j++)
			{
				t[j] = w[j];
			}
			for (int j = a, k = 0; j < w_len; j++, k++)
			{
				w[k] = w[j];
			}
			for (int j = w_len - a, k = 0; j < w_len; j++, k++)
			{
				w[j] = t[k];
			}
		}
		printf("%s\n", w);
	}
}


Measured memory_bytes: 3144
#include <bits/stdc++.h>
typedef long long int LL;
typedef unsigned long long int ULL;
using namespace std;

// 插入此處

int main() {
    string s;
    cin >> s;
    if (s == "ABC") {
        cout << "ARC" << endl;
    } else {
        cout << "ABC" << endl;
    }
}


Measured memory_bytes: 3596
#include <iostream>

using namespace std;

int a, b, c, d = 0, num = 0;
bool flag[100] = {};

int main(){
	cin >> a >> b >> c;

	d = a % b;
	num = d;
	flag[d] = true;

	while (num != 0){
		num = (num + d) % b;
		flag[num] = true;
	}

	if (flag[c]){
		cout << "YES" << endl;
	}
	else{
		cout << "NO" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;
typedef tree<pair<int,int>, null_type, less<pair<int,int>>, rb_tree_tag,tree_order_statistics_node_update> ordered_set;

#define scan(x) do{while((x=getchar())<'0'); for(x-='0'; '0'<=(_=getchar()); x=(x<<3)+(x<<1)+_-'0');}while(0)
char _;
#define complete_unique(a) a.erase(unique(a.begin(),a.end()),a.end())
#define all(a) a.begin(),a.end()
#define println printf("\n");
#define readln(x) getline(cin,x);
#define pb push_back
#define endl "\n"
#define MOD 1000000007
#define mp make_pair
#define fastio cin.tie(0); cin.sync_with_stdio(0);

#define MAXN 100005

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef unordered_map<int,int> umii;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<int,pii> triple;
typedef int8_t byte;

ll gcd(ll a, ll b) {return b == 0 ? a : gcd(b, a % b);}
ll fpow(ll  b, ll exp, ll mod){if(exp == 0) return 1;ll t = fpow(b,exp/2,mod);if(exp&1) return t*t%mod*b%mod;return t*t%mod;}
ll divmod(ll i, ll j, ll mod){i%=mod,j%=mod;return i*fpow(j,mod-2,mod)%mod;}

int len,vals[MAXN][3];
ll dp[MAXN][3];

int main(){
    scanf("%d",&len);
    for(int i=1; i<=len; i++)
        for(int k=0; k<3; k++)
            scanf(" %d",&vals[i][k]);
    for(int i=1; i<=len; i++){
        dp[i][0] = max(dp[i-1][0],max(dp[i-1][1],dp[i-1][2])+vals[i][0]);
        dp[i][1] = max(dp[i-1][1],max(dp[i-1][0],dp[i-1][2])+vals[i][1]);
        dp[i][2] = max(dp[i-1][2],max(dp[i-1][0],dp[i-1][1])+vals[i][2]);
    }
    printf("%lld\n",max(dp[len][0],max(dp[len][1],dp[len][2])));
}


Measured memory_bytes: 3712
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <unordered_set>

std::string solve(long n, const std::vector<long>& values)
{
  std::unordered_set<long> set;
  for (const auto v : values) {
    if (!set.insert(v).second) return "NO";
  }
  return "YES";
}

int main()
{
  long n;
  std::cin >> n;
  std::vector<long> values(n);
  for (auto& v : values) {
    std::cin >> v;
  }

  std::cout << solve(n, values) << std::endl;
}


Measured memory_bytes: 10056