akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
#include<math.h>
#include<queue>
#include<vector>
#include<climits>
#include<map>
#include<string>
#include<functional>
#include<iomanip>
#include<deque>
#include<random>
#include<set>
#include<bitset>
#include<cassert>

using namespace std;
typedef long long ll;
typedef double lldo;
#define mp make_pair
#define pub push_back
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
ll gcd(ll a, ll b) { if (a % b == 0) { return b; } else  return gcd(b, a % b); }
ll lcm(ll a, ll b) { if (a == 0) { return b; }return a / gcd(a, b) * b; }
template<class T>ll LBI(vector<T>& ar, T in) { return lower_bound(ar.begin(), ar.end(), in) - ar.begin(); }
template<class T>ll UBI(vector<T>& ar, T in) { return upper_bound(ar.begin(), ar.end(), in) - ar.begin(); }

ll d, c[30] = {}, s[370][30] = {}, last[30] = {}, ans[370] = {}, t[370] = {};

int main() {
	cin >> d;
	rep(i, 26)cin >> c[i];
	rep(i, d) {
		rep(j, 26)cin >> s[i][j];
	}
	rep(i, d) {
		cin >> t[i];
		t[i]--;
	}
	rep(i, 26)last[i] = -1;
	rep(i, d) {
		rep(j, 26) {
			if (j == t[i]) {
				ans[i] += s[i][j];
				last[j] = i;
			}
			else {
				ans[i] -= c[j] * (i - last[j]);
			}
		}
		if (i)ans[i] += ans[i - 1];
	}
	rep(i, d)cout << ans[i] << endl;
	return 0;
}

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

int main()
{
    int n,score1=0,score2 = 0;
    string s1,s2;
    cin>>n;
    for (int i = 0;i < n;++i)
    {
        cin>>s1>>s2;
        if (s1 > s2)
            score1 += 3;
        else if (s1 == s2)
        {
            score1++;
            score2++;
        }
        else score2 += 3;
    }
    cout<<score1<<" "<<score2<<endl;
    return 0;
}



Measured memory_bytes: 3192
import heapq
import sys


def input(): return sys.stdin.readline().strip()
def I(): return int(input())
def LI(): return list(map(int, input().split()))
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def S(): return input()
def LS(): return input().split()


INF = float('inf')


n = I()
a = LI()
a = list(map(lambda x: -x, a))
a = sorted(a)
l = []
heapq.heapify(l)
ans = 0
heapq.heappush(l, a[0])
for elem in a[1:]:
    ans += -heapq.heappop(l)
    heapq.heappush(l, elem)
    heapq.heappush(l, elem)
print(ans)


Measured memory_bytes: 33092
#include <iostream>
#include <vector>

using namespace std;

int main(){
    int n, k, q;
    cin >> n >> k >> q;
    vector<int> cnt(n);
    for(int i = 0; i < q; i++){
        int a;
        cin >> a;
        cnt[a - 1]++;
    }
    for(int i = 0; i < n; i++){
        if(0 < k - q + cnt[i]){
            cout << "Yes\n";
        }else{
            cout << "No\n";
        }
    }
}

Measured memory_bytes: 1024
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1000000007;

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
int main(void)
{
	int n,m,k;
	while (1) {
		scanf("%d%d",&m,&n);
		if(n == 0 && m == 0) return 0;
		k = 0;
		char set[7368800];
		for (int i = 0; i < 7368800; i++) {
			set[i] = 0;
		}
		for (int i = m; i < 7368800; i++) {
			if (set[i] == 0) {
				k++;
				for (int j = i; j < 7368800; j += i) {
					set[j] = 1;
				}
			}
			if (k == n+1) {
				printf("%d\n",i);
				break;
			}
		}
	}
	return 0;
}



Measured memory_bytes: 10396
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner reader = new Scanner(System.in);
		String a = reader.next();
		String b = reader.next();
		int N = Integer.parseInt(a + b);
		String ans = "No";

		int base = 1;
		while (Math.pow((base), 2) <= N) {
			if (Math.pow((base), 2) == N) {
				ans = "Yes";
			}
			base++;
		}


		System.out.print(ans);
		reader.close();
	}
}





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

int main() {
	int n;
	string s;
	cin >> n >> s;
	int cnt = n / 2;
	string s1 = s.substr(0, cnt);
	string s2 = s.substr(cnt);
	if (s1 == s2) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
using namespace std;
#define MAXN 1000
#define pb push_back
#define sz size
#define pii pair<int,int>
#define fi first
#define se second
#define mp make_pair
#define int long long
int n , m;
char ch[MAXN];
int blo[MAXN];
signed main() {
	scanf("%s",ch); n = strlen( ch );
	cin >> m;
	for( int i = 1 ; i < 3 ; ++ i )
		for( int j = 0 ; j < n ; ++ j ) 
			ch[i * n + j] = ch[j];
	for( int i = 0 ; i < n * 3 ; ++ i ) {
		if( blo[i] || ch[i] != ch[i + 1] ) continue;;
		blo[i + 1] = 1;
	}
	if( blo[n] && blo[n * 2] ) {
		int res = 0 , res1 = 0;
		for( int i = 0 ; i < n ; ++ i ) res += blo[i];
		for( int j = n ; j < 2 * n ; ++ j ) res1 += blo[j];
		cout << res + res1 * ( m - 1 ) << endl;
	} else if( blo[n] && !blo[n * 2] ) {
		int res = 0 , res1 = 0;
		for( int i = 0 ; i < n ; ++ i ) res += blo[i];
		for( int j = n ; j < 2 * n ; ++ j ) res1 += blo[j];
		cout << ( m / 2 ) * res1 + ( m - m / 2 ) * res;
	} else if( !blo[n] ) {
		int res = 0 , res1 = 0;
		for( int i = 0 ; i < n ; ++ i ) res += blo[i];
		cout << res * m << endl;
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define all(v) v.begin(),v.end()
#define P pair<int,int>
#define len(s) (int)s.size()
#define pb push_back

template<class T> inline bool chmin(T &a, T b){
	if(a>b){a=b;return true;}
	return false;
}
template<class T> inline bool chmax(T &a, T b){
	if(a<b){a=b;return true;}
	return false;
}
constexpr int mod = 1e9+7;
constexpr int inf = 3e18;



signed main(){
	int X,Y;
	cin>>X>>Y;
	if(2*X>Y||4*X<Y)cout<<"No"<<endl;
	else if((4*X-Y)%2)cout<<"No"<<endl;
	else cout<<"Yes"<<endl;
}


Measured memory_bytes: 3652
from collections import Counter, defaultdict
import sys
sys.setrecursionlimit(10 ** 5 + 10)
input = sys.stdin.readline
from math import factorial
import heapq, bisect


visit = []

def aaa(ind_lim, dame_num):
    global visit
    if ind_lim >= dame_num:
        return -1
    elif visit[ind_lim] == -1:
        return -1
    elif visit[ind_lim] == 0:
        return ind_lim
    else:
        visit[ind_lim] = aaa(visit[ind_lim], dame_num)
        return visit[ind_lim]

def main():
    num, max_num = map(int, input().split())
    data = [list(map(int, input().split())) for i in range(num)]

    data.sort(key=lambda x:(-x[1]))
    # for

    global visit
    visit = [0 for i in range(max_num + 1)]

    ans = 0

    for i in range(num):
        day, value = data[i]
        ind_lim = day
        # print(i, num, visit)
        ind_insert = aaa(ind_lim, max_num + 1)
        if ind_insert != -1:
            visit[ind_insert] = ind_insert + 1
            ans += value

    # print('uuu')
    print(ans)







if __name__ == '__main__':
    main()


Measured memory_bytes: 118876
#include <iostream>
#include <algorithm>
#include <set>
#include <string>
#include <vector>

int main(void){
    int h,w;
    std::cin >> h >> w;

    std::vector<std::vector<int>> s(h+2, std::vector<int>(w+2,0));

    for(int i = 1; i < h+1; i++){
        for(int j = 1; j < w+1; j++){
            char x;
            std::cin >> x;

            if(x == '#'){
                s[i][j] = 10;
            } 
            else if(x == '.'){
                //何もしない。
            }

        }
    }


    for(int i = 1; i < h+1; i++){
        for(int j = 1; j < w+1; j++){
            if(s[i][j] == 10){
                if(!(s[i-1][j-1] == 10)){
                    s[i-1][j-1]++;
                }
                if(!(s[i][j-1] == 10)){
                    s[i][j-1]++;
                }
                if(!(s[i+1][j-1] == 10)){
                    s[i+1][j-1]++;
                }
                if(!(s[i-1][j] == 10)){
                    s[i-1][j]++;
                }
                if(!(s[i+1][j] == 10)){
                    s[i+1][j]++;
                }
                if(!(s[i-1][j+1] == 10)){
                    s[i-1][j+1]++;
                }
                if(!(s[i][j+1] == 10)){
                    s[i][j+1]++;
                }
                if(!(s[i+1][j+1] == 10)){
                    s[i+1][j+1]++;
                }







            }
        }
    }

    for(int i = 1; i < h+1; i++){
        for(int j = 1; j < w+1; j++){
            if(s[i][j] == 10){
                std::cout << '#';
            }
            else {
                std::cout << s[i][j];
            }

        }
        std::cout << std::endl;
    }

    return 0;
}




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

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

static const int INF = 1E8;
static const int dx[] = {-1, 0, 1, 0};
static const int dy[] = {0, -1, 0, 1};
int n, m;
int d[92][92][92][92];
bool maze[92][92];

inline bool check(int hx, int hy){ return 0 <= hx && hx < n && 0 <= hy && hy < m; }

void dfs(int hx, int hy, int& cnt)
{
  maze[hx][hy] = 0;
  cnt += 1;
  int mx = cnt;
  rep(k, 4){
    int nx = hx + dx[k];
    int ny = hy + dy[k];
    if(!check(nx, ny)) continue;
    int tmp = mx;
    if(maze[nx][ny]){
      dfs(nx, ny, tmp);
      cnt = max(cnt, tmp);
    }
  }
  maze[hx][hy] = 1;
}

int main(int argc, char *argv[])
{
  while(cin >> m >> n, m){
    rep(i, n) rep(j, m) cin >> maze[i][j];

    int res = 0;
    rep(i, n) rep(j, m) if(maze[i][j]){
      int cnt = 0;
      dfs(i, j, cnt);
      res = max(res, cnt);
    }
    cout << res << endl;
  }

  return 0;
}

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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value!=0>::type
fill_v(U &u,const V... v){u=U(v...);}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_v(U &u,const V... v){
  for(auto &e:u) fill_v<T>(e,v...);
}


int main(void) {
	string s;
	cin >> s;
	vector<int64> a(s.size());
	REP(i, s.size()) a[i] = s[i]-'0';
	int64 res[2] = {};
	REP(i, s.size()) {
		if (a[i] != i%2) res[0]++;
		if (a[i] != (1-i%2)) res[1]++;
	}
	cout << min(res[0], res[1]) << endl;
}


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

int main()
{
	int n,x[100005];
	memset(x,0,sizeof(x));
	cin >> n;
	int a[n],max = 0;
	
	for(int i = 0;i < n;i++){
		cin >> a[i];
		if(a[i] > max) max = a[i];
		if(!a[i]){
			x[a[i]]++;
			x[a[i] + 1]++;
		}
		else{
			x[a[i] - 1]++;
			x[a[i]]++;
			x[a[i] + 1]++;
		}
	}
	
	int max2 = 0;
	for(int i = 0;i <= max;i++){
		if(x[i] > max2) max2 = x[i];
	}
	cout << max2;
	return 0;
}

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

char map[101][101];
int f[101][101];

int main() {
	int w, h, x, y, e;
	while(1) {
		cin >> h >> w;
		if(!w&&!h) break;
		for(int i=0; i<h; ++i) {
			cin >> map[i];
			for(int j=0; j<w; ++j) f[i][j] = 0;
		}
		x = y = 0; e = 0;
		while(1) {
			f[y][x] = 1;
			switch(map[y][x]) {
			case '>': x+=1; break;
			case '<': x-=1; break;
			case 'v': y+=1; break;
			case '^': y-=1; break;
			case '.': e = 1; break;
			}
			if(e || f[y][x]) break;
		}
		if(e) cout << x << " " << y << endl;
		else cout << "LOOP" << endl;
	}
	return 0;
}

Measured memory_bytes: 1212
#include <bits/stdc++.h> 
#define int long long
#define quickie ios_base::sync_with_stdio(false); cin.tie(NULL);
#define rep(i, a, b) for(int i=a; i<b; i++)
#define rep1(i, a, b) for(int i=a; i<=b; i++)
#define repp(i, a, b) for(int i=b-1; i>=a; i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define db double
#define mi map<int, int>
#define mc map<char, int>
#define ms map<string, int>
#define vi vector<int>
#define qi queue<int>
#define MI(x) power(x, mod-2)
#define test int t; cin >> t;
//#define mod 1000000007LL
#define mod 998244353 
using namespace std;
int power(int x, int y) ;
int gcd(int a, int b) ;

signed main() {
    quickie
    int n ;
    cin >> n ;
    cout << 3*n*n << "\n" ;
}

int power(int x, int y) {
    int res = 1; x %= mod;
    while (y > 0) {
        if (y & 1)
            res = (res*x) % mod;
        y = y>>1;
        x = (x*x) % mod;
    }
    return res%mod;
}
 
int gcd(int a,int b){
    if(a==0) return b;
    return gcd(b%a,a);
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
using namespace std;
const int mod = 1000000007;
#define ll long long

int main()
{
	string s, t;
	cin >> s >> t;
	if (s[0] == t[2] && s[1] == t[1] && s[2] == t[0]) cout << "YES" << endl;
	else cout << "NO";
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
using ll     = long long;
using pii    = pair<int, int>;
using pll    = pair<ll, ll>;
using vi     = vector<int>;
using vl     = vector<ll>;
using vvi    = vector<vi>;
using vvl    = vector<vl>;
const ll INF = 1LL << 60;
const ll MOD = 1000000007;
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;
}
template <class C>
void print(const C &c, std::ostream &os = std::cout) {
    std::copy(std::begin(c), std::end(c), std::ostream_iterator<typename C::value_type>(os, " "));
    os << std::endl;
}

//   abcabe
// a:0333666
// b:1144466
vector<vector<int>> nextidx(const string &s) {
    int n = s.size();
    vector<vector<int>> ret(n + 1, vector<int>(26, n));
    for (int i = n - 1; i >= 0; --i) {
        for (int j = 0; j < 26; ++j)
            ret[i][j] = ret[i + 1][j];
        ret[i][s[i] - 'a'] = i;
    }
    return ret;
}

int main() {
    string s;
    cin >> s;
    int n         = s.size();
    auto nxt      = nextidx(s);
    const int inf = 1 << 29;
    vi dp(n + 2, inf);
    dp[n + 1] = 0;
    vector<pair<char, int>> rec(n + 1, {'?', n});
    for (int i = n - 1; i >= 0; --i) {
        for (int j = 0; j < 26; ++j) {
            if (chmin(dp[i], dp[nxt[i][j] + 1] + 1))
                rec[i] = {'a' + j, nxt[i][j] + 1};
        }
    }
    string ret = "";
    int idx    = 0;
    while (idx < n) {
        auto p = rec[idx];
        ret += p.first;
        idx = p.second;
    }
    cout << ret << "\n";
    return 0;
}

Measured memory_bytes: 29316
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>
#include<iomanip>
#include<sstream>
#include<vector>
#include<stack>
#include<math.h>
#include<queue>
#include<complex>
#include<random>
#include<ctime>
#include<set>
using namespace std;


const long long int mod=1000000007;
const long long int INF=99999999999999999;

class Plant{
public:
	string Name;
	long long int P,A,B,C,D,E,F,S,M;
	long long int AllTime,AllMoney;
};

bool cmp(Plant X,Plant Y){
	if(X.AllMoney*Y.AllTime!=Y.AllMoney*X.AllTime){
		return X.AllMoney*Y.AllTime>Y.AllMoney*X.AllTime;
	}else{
		return X.Name<Y.Name;
	}
}

int main() {
	cout << fixed << setprecision(18);
	long long int N;
	cin>>N;
	while(N!=0){
		Plant plant[55];
		for(int i=0;i<N;i++){
			cin>>plant[i].Name>>plant[i].P>>plant[i].A>>plant[i].B>>plant[i].C>>plant[i].D>>plant[i].E>>plant[i].F>>plant[i].S>>plant[i].M;
			plant[i].AllTime=plant[i].A+plant[i].B+plant[i].C+plant[i].M*(plant[i].D+plant[i].E);
			plant[i].AllMoney=plant[i].M*plant[i].S*plant[i].F-plant[i].P;
		}
		sort(plant,plant+N,cmp);
		for(int i=0;i<N;i++){
			cout<<plant[i].Name<<endl;
		}
		cout<<'#'<<endl;
		cin>>N;
	}
	
} 


Measured memory_bytes: 3212
n=int(input())
s=input()
cnt=0
ans=str()
for i in range(n):
    if s[i]=="(":
        cnt+=1
        ans+="("
    elif s[i]==")":
        if cnt>0:
            cnt-=1
            ans+=")"
        else:
            ans=ans[::-1]
            ans+="("
            ans=ans[::-1]
            ans+=")"
            cnt=0

if cnt>0:
    while cnt>0:
        ans+=")"
        cnt-=1

print(ans)

Measured memory_bytes: 3064
s = input()
a = int(s[:2])
b = int(s[2:])
if 1 <= a <= 12:
    if 1 <= b <= 12:
        print("AMBIGUOUS")
    else:
        print("MMYY")
else:
    if 1 <= b <= 12:
        print("YYMM")
    else:
        print("NA")

Measured memory_bytes: 61588
def main():
    a, b = map(int, input().split())
    if a-2 < 0:
        a = 14

    if b-2 < 0:
        b = 14

    if a-2 > b-2:
        print('Alice')
    elif a-2 < b-2:
        print('Bob')
    else:
        print('Draw')


if __name__ == "__main__":
    main()



Measured memory_bytes: 9044
#include <bits/stdc++.h>
        using namespace std;
        typedef long long ll;
        typedef long double ld;
        typedef pair<ll, ll> l_l;
        typedef pair<int , int> i_i;
        typedef vector<ll> vl;
        typedef vector<int> vi;
        typedef vector<char> vec;
        typedef vector<bool> veb;
        typedef vector<string> ves;
        typedef vector<vector<ll>> vvl;
        typedef vector<vector<int>> vvi;
        typedef vector<vector<char>> vvec;
        typedef vector<vector<bool>> vveb;
        typedef vector<vector<string>> vves;
        #define rep(i,n) for(int i=0;i<(int)(n);i++)
        #define rep1(i,n) for(int i=1;i<(int)(n);i++)
        #define rep2(i,n) for(int i=2;i<(int)(n);i++)
        #define repk(i,k,n) for(int i=k;i<(int)(n);i++)
        #define fs first
        #define sc second
        #define pb push_back
        #define pp pop_back
        #define all(a) a.begin(),a.end()
        #define rall(a) a.rbegin(),a.rend()
        #define maxel(a) *max_element(all(a))
        #define minel(a) *min_element(all(a))
        #define acc accumulate
        #define EPS (1e-7)
        #define INF (1e9)
        #define PI (acos(-1))
        #define mod (1000000007)
        typedef long long int64;
        //const int64 INF = 1LL << 58;
        #define dame { puts("-1"); return 0;}
        #define YES { cout << "YES" << endl; return 0; }
        #define NO { cout << "NO" << endl; return 0; }
        #define Yes { cout << "Yes" << endl; return 0; }
        #define No { cout << "No" << endl; return 0; }
        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; }
        int dx[] = {0, 0, -1, 1};
        int dy[] = {1, -1, 0, 0};
         
        int main(){
        	cin.tie(0);
        	ios::sync_with_stdio(false);


	vi l1(3);
    rep(i,3){
        cin >> l1.at(i);
    }
	vi l2(3);

        rep(i,3){
        cin >> l2.at(i);
    }

	vi l3(3);

    rep(i,3){
        cin >> l3.at(i);
    }
	int n =0;
	cin >> n;
	int a =0;

	rep(i,n){
	    cin >> a;
	    rep(j,3){

	    if(a==l1.at(j)){
	    l1.at(j) = 0;
	    }
	    if(a==l2.at(j)){
	    l2.at(j) = 0;
	    }
	    if(a==l3.at(j)){
	    l3.at(j) = 0;
	    }

	    }
    }
	    if(l1.at(0)+l1.at(1)+l1.at(2)==0){
	    Yes
	return 0;
	}
		
	if(l2.at(0)+l2.at(1)+l2.at(2)==0){
	Yes
	return 0;
	}

	if(l3.at(0)+l3.at(1)+l3.at(2)==0){
	Yes
	return 0;
	}

	if(l1.at(0)+l2.at(0)+l3.at(0)==0){
	Yes
	return 0;
	}
	if(l1.at(1)+l2.at(1)+l3.at(1)==0){
	Yes
	return 0;
	}
	if(l1.at(2)+l2.at(2)+l3.at(2)==0){
	Yes
	return 0;
	}
	if(l1.at(0)+l2.at(1)+l3.at(2)==0){
	Yes
	return 0;
	}

	if(l1.at(2)+l2.at(1)+l3.at(0)==0){
	Yes
	return 0;
	}
	
	No
          	return 0;
    
    }

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define range(a) (a).begin(),(a).end()
#define print(A,x,n) rep(i,0,n){cout<<(i ? " ":"")<<A[i]x;}cout<<endl;
#define pprint(A,y,m,n) rep(j,0,m){print(A[j],y,n);}
const long mod=998244353;
const int siz=2e5;
const int inf=1e9;
int main(){
	long N; cin>>N;
	deque<int> dq;
	while(N > 0){
		if(N % 26 == 0) dq.push_front(26);
		else dq.push_front(N % 26);
        (N -= dq.front()) /= 26;
	}
	for(int v:dq) cout<<(char)(v - 1 + 'a');
	cout<<endl;
}

Measured memory_bytes: 3632
import java.util.Scanner;

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

		int a = 0;
		while (a < s.length() && s.charAt(0) == s.charAt(a)) a++;

		int b = 0;
		while (s.length() - b - 1 >= 0 && s.charAt(s.length() - 1) == s.charAt(s.length() - b - 1))
			b++;

		long c = 0;
		for (int i = 1; i < s.length(); i++) {
			if (s.charAt(i - 1) != s.charAt(i)) continue;
			long t = 1L;
			while (i < s.length() && s.charAt(i - 1) == s.charAt(i)) {
				i++;
				t++;
			}
			c += t / 2L;
		}

		boolean allSame = true;
		for (int i = 1; i < s.length(); i++) {
			if (s.charAt(i - 1) != s.charAt(i)) {
				allSame = false;
				break;
			}
		}
		if (allSame) {
			System.out.println(s.length() * k / 2L);
			return;
		}

		long answer = k * c;
		if (s.charAt(0) != s.charAt(s.length() - 1)) {
			System.out.println(answer);
			return;
		}

		//System.out.println(a);
		//System.out.println(a);
		//System.out.println(a);

		answer -= (a / 2L) * (k - 1L);
		answer -= (b / 2L) * (k - 1L);
		answer += ((a + b) / 2L) * (k - 1L);
		System.out.println(answer);
	}
}


Measured memory_bytes: 23636
# -*- coding utf-8 -*-
N = int(input())

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

bn = [0] * N

for i in range(N, 0, -1):
    s = sum(bn[(i - 1)::i]) % 2
    bn[i - 1] = 0 if s == an[i - 1] else 1

ans = sum(bn)
print(ans)
ans_b = []
if ans != 0:
    for i in range(N):
        if bn[i] == 1:
            ans_b.append(str(i + 1))
    print(' '.join(ans_b))


Measured memory_bytes: 17212
#include <stdio.h>

int main(){

  int a,i;

  scanf("%d",&a);

  int b[10000];

  for(i=1;i<=a;i++){

    scanf("%d",&b[i-1]);

  }

  int max=b[0],min=b[0];

  long long int sum=b[0];

  for(i=1;i<=a-1;i++){

    if(max<b[i])
      max=b[i];
    if(min>b[i])
      min=b[i];

    sum += b[i];

  }

  printf("%d %d %lld\n",min,max,sum);

  return 0;

}

Measured memory_bytes: 636
#include<bits/stdc++.h>
using namespace std;
int main(){
  int A,B; cin>>A>>B;
  if(A<=0&&0<=B) cout<<"Zero"<<endl;
  else if(B<0&&(A+B)%2==0) cout<<"Negative"<<endl;
  else cout<<"Positive"<<endl;
}


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


using namespace std;

int main(){
	string s;
	long long k;
	cin >> s >> k;
	for(int i=0;i<(int)s.size();i++) {
		if(s[i]=='1') {
			k--;
		}else {
			k=0;
		}
		if(k<=0) {
			cout << s[i];
			return 0;
		}
	} 
}




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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

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

#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define ins insert

#define debug(a) cerr<<(a)<<endl
#define dbrep(a,n) rep(_i,n) cerr<<(a[_i])<<" "; cerr<<endl
#define dbrep2(a,n,m) rep(_i,n){rep(_j,m) cerr<<(a[_i][_j])<<" "; cerr<<endl;}

using namespace std;

template<class A, class B>
ostream &operator<<(ostream &os, const pair<A,B> &p){return os<<"("<<p.fi<<","<<p.se<<")";}
template<class A, class B>
istream &operator>>(istream &is, pair<A,B> &p){return is>>p.fi>>p.se;}

/* Some Libraries */

//-------------------------------------------------

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N,A,B,C,D; cin>>N>>A>>B>>C>>D; N--;

    ll diff = abs(A-B);
    int p = N&1;
    bool yes=false;
    for(int i=p; i<=N; i+=2){
        ll l = C*i-(D-C)*(N-i)/2;
        ll r = D*i+(D-C)*(N-i)/2;
        if (l<=diff && diff<=r) yes=true;
    }
    cout<<(yes?"YES":"NO")<<"\n";
    return 0;
}


Measured memory_bytes: 3616
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("fma,avx")

#include <bits/stdc++.h>

using namespace std;

#define sz(a) (int) (a).size()
#define all(a) (a).begin(), (a).end()
#define x first
#define y second

mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    int n, x;
    cin >> x >> n;
    vector<int> used(102);
    for (int i = 0; i < n; i++) {
        int y;
        cin >> y;
        used[y] = 1;
    }
    int id = -1;
    for (int i = 0; i < 102; i++) {
       if (used[i]) continue;
       if (id == -1 || abs(x - id) > abs(x - i)) {
           id = i;
       }
    }
    cout << id << "\n";
    return 0;
}

Measured memory_bytes: 3664
//AtCoder ABC060 A - Shiritori
#include <bits/stdc++.h>
using namespace std;
using ll=int64_t;

int main() {
    string A,B,C;
    cin>>A>>B>>C;
    cout<<((A.back()==B[0] && B.back()==C[0])?"YES":"NO")<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
   
using namespace std;
     
#define PB(x) push_back(x)
#define ALL(x) (x).begin(), (x).end()
#define ALLR(x) (x).rbegin(), (x).rend()
#define MP(x) make_pair(x);
    
#define debug(x) cerr << #x << '=' << x << endl;
#define debug2(x, y) cerr << #x << '=' << x << ' ' << #y << '=' << y << endl;
#define debugn(a) for (int x: a) cerr << x << ' '; cerr << endl;
     
#define int long long
     
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<pair<int, int>> vii;
typedef vector<string> vs;
typedef unsigned long long ull;

const int INF = 1e9;

struct sgain { int a, b, c; };

int32_t main()
{
	int n;
	cin >> n;
	sgain gain[n+1];
	gain[0] = {0, 0, 0};
	for (int i = 1; i <= n; i++) cin >> gain[i].a >> gain[i].b >> gain[i].c;
	
	int dp[n+1][3];
	dp[0][0] = 0;
	dp[0][1] = 0;
	dp[0][2] = 0;
	
	for (int i = 1; i <= n; i++) {
		dp[i][0] = gain[i].a+max(dp[i-1][1], dp[i-1][2]);
		dp[i][1] = gain[i].b+max(dp[i-1][0], dp[i-1][2]);
		dp[i][2] = gain[i].c+max(dp[i-1][1], dp[i-1][0]);
	}
	cout << max(dp[n][0], max(dp[n][1], dp[n][2])) << endl;
}



Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

//  const int MOD = 1e9 + 7;

//unsigned seed1= chrono::system_clock::now().time_since_epoch().count();
//mt19937 rng (seed1);


int main(){
  ios::sync_with_stdio(0);
  cin.tie(0);
  
  int N;
  cin >> N;
  string s;
  cin >> s;
  unordered_map<short,short> is;
  vector<vector<int>> pos(10);
  for(int i = 0; i < N; ++i){
    pos[(int)(s[i] - '0')].push_back( i );
  }
  int ans = 0;
  for(int X = 0; X < 1000; ++X){
    char t[4];
    sprintf(t, "%03d", X);
    int a = t[0] - '0';
    int b = t[1] - '0';
    int c = t[2] - '0';

    if(pos[a].empty() || pos[b].empty() || pos[c].empty())
      continue; 

    bool ok = true;
    int first = pos[a][0];
    for(int i = 0; i < (int)pos[b].size(); ++i){
      if( pos[b][i] > first ){
        first = pos[b][i];
        break;
      }
      if(i + 1 == (int)pos[b].size() ){
        ok = 0;
      }
    }
    for(int i = 0; i < (int)pos[c].size(); ++i){
      if( pos[c][i] > first ){
        first = pos[c][i];
        break;
      } else if( i + 1 == (int)pos[c].size() ){
        ok = 0;
      }
    }

    ans += ok;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 512
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace F
{
    public class Program
    {
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            Solve();
            Console.Out.Flush();
        }

        public static void Solve()
        {
            var S = Console.ReadLine();
            var T = Console.ReadLine();
            var dp = (new int[S.Length + 1][]).Select(x => x = new int[T.Length + 1]).ToArray();
            for (var i = 0; i < S.Length; i++)
            {
                for (var j = 0; j < T.Length; j++)
                {
                    if (S[i] == T[j])
                    {
                        dp[i + 1][j + 1] = dp[i][j] + 1;
                    }
                    else
                    {
                        dp[i + 1][j + 1] = Math.Max(dp[i][j + 1], dp[i + 1][j]);
                    }
                }
            }
            // Console.WriteLine(string.Join("\n", dp.Select(x => string.Join(" ", x))));
            var answer = "";
            var si = S.Length;
            var ti = T.Length;
            while (si > 0 || ti > 0)
            {
                var x = dp[si][ti];
                if (si > 0 && dp[si - 1][ti] == x) si--;
                else if (ti > 0 && dp[si][ti - 1] == x) ti--;
                else
                {
                    si--;
                    ti--;
                    answer = S[si] + answer;
                }
            }

            Console.WriteLine(answer);
        }
    }
}


Measured memory_bytes: 71288
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#define MOD 1000000007
#define mkp make_pair
typedef long long ll;
using namespace std;

vector<int> x[100010],y[100010];

bool w[100010],z[100010];

int main(){
  int N;
  cin>>N;
  vector<int> X(N),Y(N);
  for(int i=0;i<N;i++) cin>>X[i]>>Y[i];

  for(int i=0;i<N;i++){
    x[X[i]].push_back(Y[i]);
    y[Y[i]].push_back(X[i]);
  }

  ll ans=0;
  for(int i=0;i<N;i++){
    if(w[X[i]]||z[Y[i]]) continue;
    queue<pair<int,int>> Q;
    Q.push(mkp(X[i],Y[i]));
    w[X[i]]=true;
    z[Y[i]]=true;

    ll px=1,py=1;
    ll num=1;
    map<pair<int,int>,bool> mp;
    mp[mkp(X[i],Y[i])]=true;
    while(!Q.empty()){
      int tx,ty;
      tie(tx,ty)=Q.front();
      Q.pop();

      for(int k=0;k<x[tx].size();k++){
        if(mp[mkp(tx,x[tx][k])]) continue;

        num++;
        mp[mkp(tx,x[tx][k])]=1;

        if(z[x[tx][k]]) continue;
        py++;
        Q.push(mkp(tx,x[tx][k]));
        z[x[tx][k]]=true;
      }
      for(int k=0;k<y[ty].size();k++){
        if(mp[mkp(y[ty][k],ty)]) continue;

        num++;
        mp[mkp(y[ty][k],ty)]=1;
        
        if(w[y[ty][k]]) continue;
        px++;
        Q.push(mkp(y[ty][k],ty));
        w[y[ty][k]]=true;
      }
    }
    ans+=px*py-num;
  }

  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 15360
//#pragma GCC optimize(\"Ofast,no-stack-protector\")
//#pragma GCC target(\"sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx\")
//#pragma GCC target(\"avx,tune=native\")
// Neil

#include<bits/stdc++.h>

using namespace std;

typedef complex<double> base;
typedef long double ld;
typedef long long ll;

#define endl "\n"
#define pb push_back
#define pii pair<int,int>
#define pll pair< ll , ll >
#define vi vector<int>
#define vvi vector< vi >
const int MAXN=(int)(2e5+5);
const ll MOD=(ll)(1e9+7);
int t;
int arr[11];
int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);
    t = 1;
    while(t--){
        int a,b,c;
        cin>>a>>b>>c;
        arr[a]++;
        arr[b]++;
        arr[c]++;
        if(arr[5]==2 and arr[7]==1)
            cout<<"YES"<<endl;
        else
        {
            
            cout<<"NO"<<endl;
        }
        
    }
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#define ll long long
#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define foreach(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
using namespace std;

ll n;
const int Mod=1e9+7;
ll ans=1,tot=1,cnt=1;

int main()
{
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	cin>>n;
	REP(i,n)ans=(ans*10)%Mod;
	REP(i,n)cnt=(cnt*9)%Mod;
	REP(i,n)tot=(tot*8)%Mod;
	cout<<(ans-2*cnt+tot+Mod+Mod)%Mod<<endl;
	return 0;
}


Measured memory_bytes: 3576
// scan tuple
let scan1 f = stdin.ReadLine() |> f
let scan2 f = stdin.ReadLine().Split() |> Array.map f |> (fun a -> (a.[0], a.[1]))
let scan3 f = stdin.ReadLine().Split() |> Array.map f |> (fun a -> (a.[0], a.[1], a.[2]))
let scan4 f = stdin.ReadLine().Split() |> Array.map f |> (fun a -> (a.[0], a.[1], a.[2], a.[3]))
// scan vec and matrix (using Array)
let scanVecH f = stdin.ReadLine().Split() |> Array.map f
let scanVecV f n = [| for i in 1..n -> stdin.ReadLine() |> f |]
let scanMatrix f n = [| for i in 1..n -> stdin.ReadLine().Split() |> Array.map f |]
let scanCharMatrix n = [| for i in 1..n -> stdin.ReadLine().ToCharArray() |]
// vec tools
let transpose (m:'a [][]) = 
  let h,w = Array.length m, Array.length m.[0]
  [| for i in 0..w-1 -> [|0..h-1|] |> Array.map (fun j -> m.[j].[i]) |]

let h, w = scan2 int

scanCharMatrix h
|> Array.filter (Array.exists ((=) '#'))
|> transpose
|> Array.filter (Array.exists ((=) '#'))
|> transpose
|> Array.map (fun a -> Array.map string a |> String.concat "")
|> String.concat "\n"
|> printfn "%s"


Measured memory_bytes: 14300
#include <stdio.h>
int main(){
  int b, n, m[200000+1]={0};
  scanf("%d", &n);
  for(int i=1; i<n; i++){
    scanf("%d", &b);
    m[b-1]++;
  }
  for(int i=0; i<n; i++){
    printf("%d\n", m[i]);
  }
  return 0;
}

Measured memory_bytes: 2512
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
import java.util.Comparator;
import static java.util.Comparator.*;

class Crop {
	String name;
	int p;
	int a;
	int b;
	int c;
	int d;
	int e;
	int f;
	int s;
	int m;
	
	public Crop(String name, int p, int a, int b, int c, int d, int e, int f, int s, int m) {
		this.name = name;
		this.p = p;
		this.a = a;
		this.b = b;
		this.c = c;
		this.d = d;
		this.e = e;
		this.f = f;
		this.s = s;
		this.m = m;	
	}
	
	public double calculateEfficiency() {
		int sales = -p;
		int times = 0;
		
		for (int i = 0; i < m; i++) {
			if (i == 0) {
				times += a + b + c + d + e;
			} else {
				times += d + e;
			}
			
			sales += s * f;
		}
		
		return sales / (double)times;
	}
	
	public String getName() {
		return this.name;
	}
}

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		while (true) {
			int n = sc.nextInt(); sc.nextLine();
			if (n == 0) break;
			
			List<Crop> crops = new ArrayList<Crop>();
			
			while (n > 0) {
				String line = sc.nextLine();
				String[] inputs = line.split(" ");
				String l = inputs[0];
				int p = Integer.parseInt(inputs[1]);
				int a = Integer.parseInt(inputs[2]);
				int b = Integer.parseInt(inputs[3]);
				int c = Integer.parseInt(inputs[4]);
				int d = Integer.parseInt(inputs[5]);
				int e = Integer.parseInt(inputs[6]);
				int f = Integer.parseInt(inputs[7]);
				int s = Integer.parseInt(inputs[8]);
				int m = Integer.parseInt(inputs[9]);

				crops.add(new Crop(l, p, a, b, c, d, e, f, s, m));
				n--;
			}
			
			crops.sort(comparing(Crop::calculateEfficiency, reverseOrder()).thenComparing(Crop::getName));
			crops.forEach((c) -> System.out.println(c.getName()));
			System.out.println("#");
		}
		
		sc.close();
	}
}

Measured memory_bytes: 41076
#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
#include <set>
#include <unordered_set>
#include <queue>
#include <stack>
#include <map>           // sorted map so O(logn)
#include <unordered_map> // O(1)
#define rep(i, n) for (int i = 0; i < n; i++)
typedef long long ll;
using namespace std;

int main()
{
    string s;
    cin >> s;
    if (s[2] == s[3] && s[4] == s[5])
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
}


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

using namespace std;


template <int p>
struct Modint
{
	int value;

	Modint() : value(0) {}
	Modint(long x) : value(x >= 0 ? x % p : (p + x % p) % p) {}

	inline Modint &operator+=(const Modint &b)
	{
		if ((this->value += b.value) >= p)
			this->value -= p;
		return (*this);
	}
	inline Modint &operator-=(const Modint &b)
	{
		if ((this->value += p - b.value) >= p)
			this->value -= p;
		return (*this);
	}
	inline Modint &operator*=(const Modint &b)
	{
		this->value = (int)((1LL * this->value * b.value) % p);
		return (*this);
	}
	inline Modint &operator/=(const Modint &b)
	{
		(*this) *= b.inverse();
		return (*this);
	}

	Modint operator+(const Modint &b) const { return Modint(*this) += b; }
	Modint operator-(const Modint &b) const { return Modint(*this) -= b; }
	Modint operator*(const Modint &b) const { return Modint(*this) *= b; }
	Modint operator/(const Modint &b) const { return Modint(*this) /= b; }

	inline Modint &operator++(int) { return (*this) += 1; }
	inline Modint &operator--(int) { return (*this) -= 1; }

	inline bool operator==(const Modint &b) const { return this->value == b.value; }
	inline bool operator!=(const Modint &b) const { return this->value != b.value; }
	inline bool operator<(const Modint &b) const { return this->value < b.value; }
	inline bool operator<=(const Modint &b) const { return this->value <= b.value; }
	inline bool operator>(const Modint &b) const { return this->value > b.value; }
	inline bool operator>=(const Modint &b) const { return this->value >= b.value; }

	//requires that "this->value and p are co-prime"
	// a_i * v + a_(i+1) * p = r_i
	// r_i = r_(i+1) * q_(i+1) * r_(i+2)
	// q == 1 (i > 1)
	// reference: https://atcoder.jp/contests/agc026/submissions/2845729 (line:93)
	inline Modint inverse() const
	{
		assert(this->value != 0);
		int r0 = p, r1 = this->value, a0 = 0, a1 = 1;
		while (r1)
		{
			int q = r0 / r1;
			r0 -= q * r1;
			swap(r0, r1);
			a0 -= q * a1;
			swap(a0, a1);
		}
		return Modint(a0);
	}

	friend istream &operator>>(istream &is, Modint<p> &a)
	{
		long t;
		is >> t;
		a = Modint<p>(t);
		return is;
	}
	friend ostream &operator<<(ostream &os, const Modint<p> &a)
	{
		return os << a.value;
	}
};

const int MOD = 1e9 + 7;

using Int = Modint<MOD>;


void solve()
{
	int n, x;
	cin >> n >> x;
	vector<int> fs(n);
	for (int i = 0; i < n; i++)
	{
		cin >> fs[i];
	}
	sort(fs.rbegin(), fs.rend());
	vector<Int> dp(x+1);
	dp[x] = 1;
	for (int i = 0; i < n; i++)
	{
		vector<Int> nx(x+1);
		for (int t = 0; t <= x; t++)
		{
			nx[t%fs[i]] += dp[t];
			nx[t] += dp[t] * (n-i-1);
		}
		swap(dp, nx);
	}
	Int ans = 0;
	for (int t = 0; t <= x; t++)
	{
		ans += dp[t] * t;
		//if (dp[t] > 0) cout << t << ' ' << dp[t] << endl;
	}
	cout << ans << endl;
}

int main()
{
	solve();
	//cout << "yui(*-v・)yui" << endl;
	return 0;
}


Measured memory_bytes: 1048
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <ctime>
#include <iterator>
#include <bitset>
#include <numeric>
#include <list>
#include <iomanip>
#include <cassert>

#if __cplusplus >= 201103L
#include <array>
#include <tuple>
#include <initializer_list>
#include <unordered_set>
#include <unordered_map>
#include <forward_list>

#define cauto const auto&
#define ALL(v) begin(v),end(v)
#else
#define ALL(v) (v).begin(),(v).end()
#endif

using namespace std;


namespace{
typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
	v.assign(a, vector<T>(b, t));
}
template <class T> inline T &chmin(T &x, const T &y){ return x = min(x, y); }
template <class T> inline T &chmax(T &x, const T &y){ return x = max(x, y); }
template <class F, class T>
void convert(const F &f, T &t){
	stringstream ss;
	ss << f;
	ss >> t;
}


#define REP(i,n) for(int i=0;i<int(n);++i)
#define RALL(v) (v).rbegin(),(v).rend()


#define MOD 1000000007LL
#define EPS 1e-8


void mainmain(){
	const LL offset = 4e18;

	LL n, x, d;
	cin >> n >> x >> d;

	LL ans = 0;
	if(d == 0){
		set<LL> st;
		for(int i = 0; i <= n; ++i){
			st.insert(x * i);
		}
		ans = st.size();
	}
	else{
		map<LL,set<pll>> mp;
		for(LL i = 0; i <= n; ++i){
			LL md = (x * i + offset) % d;
			set<pll> &st = mp[md];
			LL from = (x * i + offset) / d + i * (i - 1) / 2;
			LL to = (x * i + offset) / d + i * (2 * n - i - 1) / 2 + 1;

			auto it = st.emplace(from, to).first;
			auto it2 = next(it);
			if(it2 != st.end() && it2->first <= it->second){
				LL a = min(it->first, it2->first);
				LL b = max(it->second, it2->second);
				st.erase(it);
				st.erase(it2);
				it = st.emplace(a, b).first;
			}
			if(it != st.begin()){
				it2 = prev(it);
				if(it2->second >= it->first){
					LL a = min(it->first, it2->first);
					LL b = max(it->second, it2->second);
					st.erase(it);
					st.erase(it2);
					it = st.emplace(a, b).first;
				}
			}
		}
		for(cauto p : mp){
			cauto st = p.second;
			for(cauto q : st){
				ans += q.second - q.first;
			}
		}
	}
	cout << ans << endl;
}



}
int main() try{
//	ios::sync_with_stdio(false); cin.tie(0);
	cout << fixed << setprecision(10);
	cerr << fixed << setprecision(4);
	mainmain();
}
catch(...){
	throw;
}


Measured memory_bytes: 31488
#include <iostream>
#include <climits>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#define INF_INT (INT_MAX / 2)
#define INF_LONG (LONG_MAX / 2)
//#define DEBUG true
#define DEBUG false
using namespace std;

typedef long long ll;

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

  int d, n;
  cin >> d >> n;

  int ans;
  switch(d){
    case 0: ans = (n != 100) ? n : 101; break;
    case 1: ans = (n != 100) ? n * 100 : 10100; break;
    case 2: ans = (n != 100) ? n * 100 * 100 : 1010000; break;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
/*
 * atcoder/abc118_2nd/d.cpp
 */

// C++ 14
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstring> // memset
#include <cassert>
using namespace std;
#define ll long long
#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)
template <class T> ostream & operator << (ostream & out, vector<T> const & v) {
  for (auto &&a: v) out << a << " "; out << endl; return out;
}
template <class T> void dump(T &a) { cout << a << endl; }
template <class T> bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false; }

/*
 * 整数として大きいとはどういうことか.
 * 長さが等しければ辞書順大が大きい.
 * 長さが等しくなければ長いほうが大きい.
 *
 * 後は容量制限ナップサックか.
 */
void chmax(string &a, string b) {
  if (a.size() == b.size()) {
    if (a < b) a = b;
  }
  else {
    if (a.size() < b.size()) a = b;
  }
}

int N, M;
vector<int> C{0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
vector<int> A;
string dp[10100];
void solve() {
  cin >> N >> M;
  A.resize(M);
  loop(m,0,M) cin >> A[m];

  loop(i,0,10100) dp[i] = "";
  for (int n=0; n<=N; n++) {
    if (n!=0 and dp[n] == "") continue;
    for (auto &&a: A) {
      int cost = C[a];
      chmax(dp[n+cost], dp[n] + (char)(a + '0'));
    }
  }

  // for (int n=0; n<=N; n++) {
  //   cout << dp[n] << endl;
  // }
  cout << dp[N] << endl;
}
int main() {
  // cout.precision(15); cout << fixed;

  solve();

  return 0;
}


Measured memory_bytes: 43776
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define all(v) v.begin(), v.end()
#define endk '\n'
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
const ld eps = 1e-10;

ll gcd(ll x, ll y) {
  if(x > y)
    return gcd(y, x);
  else if(x == 0)
    return y;
  else
    return gcd(y % x, x);
}
ll lcm(ll x, ll y) {
  ll g = gcd(x, y);
  return g * (x / g) * (y / g);
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll a, b, c, d; cin >> a >> b >> c >> d;
  a--;
  ll cntA=a, cntB=b;
  ll l = lcm(c, d);
  cntA -= a/c+a/d-a/l;
  cntB -= b/c+b/d-b/l;
  cout << cntB - cntA << endk;
  return 0;
}


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

int main(){
  int tmp,total,s,m;

  total = 0;
  for(int i=0;i<4;i++){
    cin >> tmp;
    total += tmp;
  }

  m = total/60;
  s = total%60;

  cout << m << endl << s << endl;

}

Measured memory_bytes: 0
#include <iostream>
#include <algorithm>

int N, L;
std::string arr[100];

bool compstr(std::string a, std::string b) {
    return a < b;
}

void solve() {
    std::cin >> N >> L;
    for (int i=0; i<N; ++i) 
        std::cin >> arr[i];
    std::sort(arr, arr+N, compstr);
    for (int i=0; i<N; ++i)
        std::cout << arr[i];
    std::cout << std::endl;
}

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

Measured memory_bytes: 256
[ n, a, b, c, d ] = map(int, input().split())

currentPen = 0
costA = 0
costB = 0
while (n > currentPen):
  costA += b
  currentPen += a

currentPen = 0
while(n > currentPen):
  costB += d
  currentPen += c

if (costA < costB):
  print(costA)
else:
  print(costB)






Measured memory_bytes: 5596