akhauriyash/Code-Regression huggingface dataset:
#pragma region header
#include <bits/stdc++.h>
using namespace std;
#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 rev(i, n) for(int i = (int)(n - 1); i >= 0; i--)
#define rev1(i, n) for(int i = (int)(n); i > 0; i--)
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define resort(v) sort((v).rbegin(), (v).rend())
#define vi vector<int>
#define vvi vector<vector<int>>
#define vc vector<char>
#define vvc vector<vector<char>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
using ll = long long;
using P = pair<int, int>;
/* ----------------よく使う数字や配列----------------- */
int dx[] = {1,0,-1,0};
int dy[] = {0,1,0,-1};
constexpr ll mod = 1e9+7;
constexpr ll inf = INT32_MAX/2;
constexpr ll INF = LLONG_MAX/2;
constexpr long double eps = DBL_EPSILON;
constexpr long double pi = 3.141592653589793238462643383279;
/* ----------------------end----------------------- */

/* --------------------テンプレート------------------ */
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;
}
/* ----------------------end----------------------- */

/* --------------------ライブラリ-------------------- */
ll fact(int i) {       //階乗
    if (i == 0) return 1;
    return (fact(i - 1)) * i;
}
ll gcd(ll a, ll b) {        //最大公約数
    if(b == 0) return a;
    return gcd(b, a % b); 
}
ll lcm(ll a, ll b) {      //最小公倍数
    return a * b / gcd(a, b);
}
int keta(ll n) {        //桁数を求める
    if(n == 0) return 1;
    int count = 0;
    while(n != 0) {
        n /= 10;
        count++;
    }
    return count;
}
ll ketasum(ll n) {    //各桁の和
    ll sum = 0;
    while(n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
/* ----------------------end----------------------- */
#pragma endregion
int main() {
    int a,b,c;cin >> a >> b >> c;
    int i = 0;
    while(i<=1e8) { 
        if(a%2||b%2||c%2) {
            cout << i << endl;
            return 0;
        }
        int A = a,B=b,C=c;
        a=B/2+C/2,b=C/2+A/2,c=A/2+C/2;
        i++;
    }
    cout << -1 << endl;
    return 0;
}


Measured memory_bytes: 3556
#include <iostream>
#include <vector>
#include <utility>
#include <string>
#include <map>
#include <algorithm>
#include <set>
#include <queue>
#include <functional>
#include <cmath>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define show(x) cerr << #x << " = " << x << endl;
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
int dp[4005][2005];
int black[4005][2005];
int white[4005][2005];
int black_pos[2005];
int white_pos[2005];
int main(){
    int n;
    cin >> n;
    vector<int>a,b;
    vector<pii>vec(2*n);
    rep(i,2*n){
        char c;
        int k;
        cin >> c >> k;
        if(c=='B')vec[i] = pii(0,k);
        else vec[i] = pii(1,k);
    }
    rep(i,2*n){
        if(vec[i].first==0){
            for(int j = 1; j <= vec[i].second; j++){
                black[i][j]++;
            }
            black_pos[vec[i].second] = i;
        }else{
            for(int j = 1; j <= vec[i].second; j++){
                white[i][j]++;
            }
            white_pos[vec[i].second] = i;
        }
        rep(j,n+1){
            black[i+1][j] += black[i][j];
            white[i+1][j] += white[i][j];
        }
    }
    rep(i,2*n+1)rep(j,n+1)dp[i][j] = 1<<29;
    dp[0][0] = 0;
    rep(i,2*n){
        rep(j,n+1){
            if(dp[i][j] == 1<<29)continue;
            //black
            if(j+1<=n){
                int id = black_pos[j+1];
                dp[i+1][j+1] = min(dp[i+1][j+1], dp[i][j] + black[id][j+1]-1 + white[id][i-j+1]);
            }
            //white
            if(i-j+1<=n){
                int id = white_pos[i-j+1];
                dp[i+1][j] = min(dp[i+1][j], dp[i][j] + black[id][j+1] + white[id][i-j+1]-1);
            }
        }
    }
    cout << dp[2*n][n] << endl;
}

Measured memory_bytes: 94336
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(a); (i)<(b); ++(i))
#define rFor(i, a, b) for(int (i)=(a)-1; (i)>=(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef pair<int, lint> pil;
typedef pair<lint, int> pli;
template<class T>bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}
template<class T>bool chmin(T &a, const T &b){if(a>b){a=b; return true;} return false;}

constexpr lint mod = 1e9+7;
constexpr lint INF = mod*mod;
constexpr int MAX = 100010;

int main(){
        int n;
        scanf("%d", &n);
        int cur=0;
        rep(i, n){
                string s;
                cin>>s;
                s=="A" ? ++cur : --cur;
                if(cur<0){
                        printf("NO\n");
                        return 0;
                }
        }
        printf(cur==0 ? "YES\n" : "NO\n");
}


Measured memory_bytes: 3300
#include <stdio.h>

int main(void){
    int n;
    int a[250];

    scanf("%d", &n);
    for(int i = 0;i < n;++i){
        scanf("%d", &a[i]);
    }

    int flag = 0;
    int cnt = 0;
    while(1){
        for(int i = 0;i < n;++i){
            if(a[i] % 2 == 0) a[i] /= 2;
            else{
                flag = 1;
                break;
            }
        }
        if(flag == 1) break;
        else cnt++;
    }

    printf("%d\n", cnt);

    return 0;
}

Measured memory_bytes: 1736
N = int(input())
DX = input().split()
A = [input() for i in range(N)]
D = int(DX[0])
X = int(DX[1])
A = [ int(x) for x in A]
#print(N, D, C, A)
ANS = [0 for i in range(N)]
for i in range(N):
    for j in range(D):
        if D >= (j * A[i] + 1):
            ANS[i] +=  1


ans = sum(ANS) + X        
print(ans)

Measured memory_bytes: 3188
import java.util.Scanner;

public class Main {
	
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int a=sc.nextInt();
		int b=sc.nextInt();
		int c=sc.nextInt();
		int d=sc.nextInt();
		
		if(a<=c&&b<=d&&c<=b)
			System.out.println(b-c);
		else if(a>=c&&d<=b&&d>=a)
			System.out.println(d-a);
		else  if(a<=c&&b>=d)
			System.out.println(d-c);
		else if(a>=c&&b<=d)
			System.out.println(b-a);
		else
			System.out.println(0);
		sc.close();
	}
}


Measured memory_bytes: 23508
import java.util.*; import java.io.*; import java.math.*;
public class Main{
	//Don't have to see. start------------------------------------------
	static class InputIterator{
		ArrayList<String> inputLine = new ArrayList<String>(1024);
		int index = 0; int max; String read;
		InputIterator(){
			BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
			try{
				while((read = br.readLine()) != null){
					inputLine.add(read);
				}
			}catch(IOException e){}
			max = inputLine.size();
		}
		boolean hasNext(){return (index < max);}
		String next(){
			if(hasNext()){
				return inputLine.get(index++);
			}else{
				throw new IndexOutOfBoundsException("There is no more input");
			}
		}
	}
	static HashMap<Integer, String> CONVSTR = new HashMap<Integer, String>();
	static InputIterator ii = new InputIterator();//This class cannot be used in reactive problem.
	static PrintWriter out = new PrintWriter(System.out);
	static void flush(){out.flush();}
	static void myout(Object t){out.println(t);}
	static void myerr(Object t){System.err.print("debug:");System.err.println(t);}
	static String next(){return ii.next();}
	static boolean hasNext(){return ii.hasNext();}
	static int nextInt(){return Integer.parseInt(next());}
	static long nextLong(){return Long.parseLong(next());}
	static double nextDouble(){return Double.parseDouble(next());}
	static ArrayList<String> nextStrArray(){return myconv(next(), 8);}
	static ArrayList<String> nextCharArray(){return myconv(next(), 0);}
	static ArrayList<Integer> nextIntArray(){
		ArrayList<String> input = nextStrArray(); ArrayList<Integer> ret = new ArrayList<Integer>(input.size());
		for(int i = 0; i < input.size(); i++){
			ret.add(Integer.parseInt(input.get(i)));
		}
		return ret;
	}
	static ArrayList<Long> nextLongArray(){
		ArrayList<String> input = nextStrArray(); ArrayList<Long> ret = new ArrayList<Long>(input.size());
		for(int i = 0; i < input.size(); i++){
			ret.add(Long.parseLong(input.get(i)));
		}
		return ret;
	}
	static String myconv(Object list, int no){//only join
		String joinString = CONVSTR.get(no);
		if(list instanceof String[]){
			return String.join(joinString, (String[])list);
		}else if(list instanceof ArrayList){
			return String.join(joinString, (ArrayList)list);
		}else{
			throw new ClassCastException("Don't join");
		}
	}
	static ArrayList<String> myconv(String str, int no){//only split
		String splitString = CONVSTR.get(no);
		return new ArrayList<String>(Arrays.asList(str.split(splitString)));
	}
	public static void main(String[] args){
		CONVSTR.put(8, " "); CONVSTR.put(9, "\n"); CONVSTR.put(0, "");
		solve();flush();
	}
	//Don't have to see. end------------------------------------------
	static void solve(){//Here is the main function
      int r = nextInt();
      myout(r * r);
	}
	//Method addition frame start



	//Method addition frame end
}


Measured memory_bytes: 32972
#include<bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define repk(i,k, n) for (ll i = k; i < (ll)(n); ++i)
#define MAX 100010
#define MOD 1000000007
typedef long long  ll;

using namespace std;


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

	if (N == M) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using pii=pair<int,int>;
using ll=long long;

#define fi first
#define se second
#define pb push_back
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define MOD 1000000007

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

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

  return 0;
}


Measured memory_bytes: 256
package main

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

func readLine(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}

func strToInts(s string) []int {
	var ints []int
	for _, str := range strings.Split(s, " ") {
		i, _ := strconv.Atoi(str)
		ints = append(ints, i)
	}
	return ints
}

func subs(vs, cs []int) int {
	res := 0
	for i := 0; i < len(vs); i++ {
		if vs[i]-cs[i] <= 0 {
			continue
		}
		res += vs[i] - cs[i]
	}
	return res
}

func main() {
	var n int
	fmt.Scan(&n)

	sc := bufio.NewScanner(os.Stdin)

	vs := strToInts(readLine(sc))
	cs := strToInts(readLine(sc))

	fmt.Println(subs(vs, cs))
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define INF 1e18
#define int long long
#define Rep(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) Rep(i, 0, n)
#define all(a) (a).begin(), (a).end()
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;
const int mod = 1000000007;

#define MAX_LEN 100010
string L;
int dp[MAX_LEN][2];
bool vis[MAX_LEN][2];

int solve(int bit, int f)
{
    if (vis[bit][f])
        return dp[bit][f];
    vis[bit][f] = true;
    if (bit == L.size())
        return dp[bit][f] = 1;
    int res;
    if (L[bit] == '1')
    {
        if (f)
            res = (3 * solve(bit + 1, f)) % mod;
        else
            res = (2 * solve(bit + 1, f) + solve(bit + 1, 1)) % mod;
    }
    else
    {
        if (f)
            res = (3 * solve(bit + 1, f)) % mod;
        else
            res = solve(bit + 1, f);
    }
    return dp[bit][f] = res;
}

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

    cin >> L;
    cout << solve(0, 0) << endl;
}

Measured memory_bytes: 6992
#include <iostream>
#include <sstream>
#include <stdio.h>
#define _USE_MATH_DEFINES
#include <math.h>
#include <set>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <limits>
#include <bitset>
#include <stack>
#include <queue>
#include <ctype.h>
#include <list>

typedef long long int lli;
#define rep(i,s,N) for(int i=s;i<N;i++)
//#define MOD 1000000007
#define more(a,b) (((a)>(b))?(a):(b))
#define less(a,b) (((a)<(b))?(a):(b))
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

using namespace std;

int main(void)
{
    int X, Y; cin >> X >> Y;
    if (Y % 2 == 1)cout << "No" << endl;
    else {
        if ((4 * X - Y >= 0) && (Y - 2 * X >= 0))cout << "Yes" << endl;
        else cout << "No" << endl;
    }


    return 0;
}


Measured memory_bytes: 3616
#include<iostream>
char a[16], b[16] = {'C', 'O', 'D', 'E', 'F', 'E', 'S', 'T', 'I', 'V', 'A', 'L', '2', '0', '1', '6'};
int ans;
int main(int argc, char **argv){
    std::cin >> a;
    for(int i = 0; i < 16; i ++){
        if(a[i] != b[i]) ans++;
    }
    std::cout << ans << "\r\n";  
}

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

long long mins[200001];

int main(){
    long long n;
    cin >> n;

    int cnt = 0;
    mins[0] = 9999999;

    for (int i=0; i<n; i++){
        long long p;
        cin >> p;

        if (p <= mins[i]){
            mins[i+1] = p;
            cnt++;
        } else {
            mins[i+1] = mins[i];
        }
    }

    cout << cnt << endl;
    return 0;
}


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

using namespace std;

int main(){
	int n,Y;
	cin>>n>>Y;
	for(int i=0; i<=Y/10000; ++i){
		for(int j=0; j<=Y/5000; ++j){
			int k = n-i-j;	
			if(k>=0&&(i*10000 + j*5000 + k*1000 == Y)){
				cout<<i<<' '<<j<<' '<<k<<endl;
				return 0;
			}
		}
	}	
	cout<<"-1 -1 -1"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int N;
int person[10];
int field; 
void solve(){
  field = 0;
  for (int i = 0; i < 10; i++) person[i] = 0;
  char s;
  for (int i = 0; i < 100; i++){
    scanf(" %c", &s);
    person[i % N]++;
    if (s == 'S') {
      field += person[i % N];
      person[i % N] = 0;
    }
    else if (s == 'L') {
      person[i % N] += field;
      field = 0;
    }
  }
  std::sort(person, person + N);
  for (int i = 0; i < N; i++){
    printf("%d ", person[i]);
  }
  printf("%d", field);
  printf("\n");
}
int main(){
  while (scanf("%d", &N), N) solve();
}

Measured memory_bytes: 1208
#include <algorithm>
#include <climits>
#include <cmath>
#include <iostream>
#include <numeric>
#include <queue>
#include <unordered_map>
#include <vector>

const int mod = 1e9 + 7;
const int kmax = 510000;

long long fact[kmax], fact_inv[kmax], inv[kmax];

int gcd(int a, int b)
{
    if (!b) {
        return a;
    }

    return gcd(b, a % b);
}

void init_comb()
{
    fact[0] = fact[1] = 1;
    fact_inv[0] = fact_inv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < kmax; i++) {
        fact[i] = fact[i - 1] * i % mod;
        inv[i] = mod - inv[mod % i] * (mod / i) % mod;
        fact_inv[i] = fact_inv[i - 1] * inv[i] % mod;
    }
}

long long comb(int n, int r)
{
    if (n < r) {
        return 0;
    }

    if (n < 0 || r < 0) {
        return 0;
    }

    return fact[n] * (fact_inv[r] * fact_inv[n - r] % mod) % mod;
}

template <typename T, T N>
class UnionFind {
    T parent_[N];
    T rank_[N];
    T size_[N];

public:
    UnionFind();
    T Root(T idx);
    bool IsSame(T x, T y);
    void Unite(T x, T y);
    T GetSize(T idx);
};

template <typename T, T N>
UnionFind<T, N>::UnionFind()
{
    for (T i = 0; i < N; i++) {
        parent_[i] = i;
        rank_[i] = 0;
        size_[i] = 1;
    }
}

template <typename T, T N>
T UnionFind<T, N>::Root(T idx)
{
    return parent_[idx] == idx ? idx : parent_[idx] = Root(parent_[idx]);
}

template <typename T, T N>
bool UnionFind<T, N>::IsSame(T x, T y)
{
    return Root(x) == Root(y);
}

template <typename T, T N>
void UnionFind<T, N>::Unite(T x, T y)
{
    x = Root(x);
    y = Root(y);
    if (x == y) {
        return;
    }

    if (rank_[x] < rank_[y]) {
        parent_[x] = y;
        size_[y] += size_[x];
    } else {
        parent_[y] = x;
        size_[x] += size_[y];
        if (rank_[x] == rank_[y]) {
            rank_[x]++;
        }
    }
}

template <typename T, T N>
T UnionFind<T, N>::GetSize(T idx)
{
    return size_[Root(idx)];
}

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

    std::cout << (s[2] == s[3] && s[4] == s[5] ? "Yes" : "No") << std::endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <iomanip>
#include <string.h>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()

typedef long long lint;

using namespace std;
lint p=998244353;
lint pro[300001];

lint pow_mod(lint a,lint b,lint p){
  if(b==0)return 1;
  if(b%2==0){
    lint d=pow_mod(a,b/2,p);
    return (d*d)%p;
  }else{
    return (a*pow_mod(a,b-1,p))%p;
  }
}

//x / a mod p=x * inv_mod(a,p) 
lint inv_mod(lint a,lint p){
  return pow_mod(a,p-2,p);//(a^(p-2))mod p
}

lint nCk(lint n,lint k){
  return (pro[n]*inv_mod((pro[k]*pro[n-k])%p,p))%p;
}

int main(){
  pro[0]=1;
  FOR(i,1,300001){
    pro[i]=pro[i-1]*i;
    pro[i]%=p;
  }
  lint N,A,B,K;
  cin>>N>>A>>B>>K;
  lint ans=0;
  REP(i,N+1){
    if(K<A*i)continue;
    if((K-A*i)%B!=0)continue;
    if((K-A*i)/B>N)continue;
    ans+=nCk(N,i)*nCk(N,(K-A*i)/B);
    ans%=p;
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 2560
n =int(input())
a=int(n/4)+1
b=int(n/7)+1

total=0
count=0
for i in range(a):
    for j in range(b):
            total=4*i+7*j
            if total==n:
                count+=1
                
if count>=1:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3060
# -*- coding: utf-8 -*-
n,x,y = list(map(int,input().split()))
x-=1
y-=1
inf=float("inf")
#最短距離の隣接行列
am = [[inf]*n for _ in range(n)]
for i in range(n):
    for j in range(i,n):
        am[i][j]=min(j-i,abs(i-x)+1+abs(y-j),abs(i-y)+1+abs(x-j))

from math import isinf
ret_bucket = [0] * n
for a_list in am:
    for min_dist in a_list:
        if not isinf(min_dist):
            ret_bucket[min_dist]+=1

for i in ret_bucket[1::]:
    print(i)

Measured memory_bytes: 147932
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, start, n) for (int i = (int)(start); i < (int)(n); ++i)
static const int INFTY = (1 << 30);
int H, W;
int func2(vector<vector<bool>> &a, vector<vector<bool>> &v)
{
    int r[H][W] = {};
    int ans;
    queue<pair<int, int>> q;
    rep(i, 0, H)
    {
        rep(j, 0, W)
        {
            if (a[i][j])
            {
                q.push(make_pair(j, i));
                v[i][j] = true;
                r[i][j] = 0;
            }
        }
    }
    while (!q.empty())
    {
        int x = q.front().first, y = q.front().second;
        ans = r[y][x];
        q.pop();
        if (x > 0 && !v[y][x - 1])
        {
            r[y][x - 1] = ans + 1;
            v[y][x - 1] = true;
            a[y][x - 1] = true;
            q.push(make_pair(x - 1, y));
        }
        if (x < W - 1 && !v[y][x + 1])
        {
            r[y][x + 1] = ans + 1;
            v[y][x + 1] = true;
            a[y][x + 1] = true;
            q.push(make_pair(x + 1, y));
        }
        if (y > 0 && !v[y - 1][x])
        {
            r[y - 1][x] = ans + 1;
            v[y - 1][x] = true;
            a[y - 1][x] = true;
            q.push(make_pair(x, y - 1));
        }
        if (y < H - 1 && !v[y + 1][x])
        {
            r[y + 1][x] = ans + 1;
            v[y + 1][x] = true;
            a[y + 1][x] = true;
            q.push(make_pair(x, y + 1));
        }
    }
    return ans;
}
void func()
{
    cin >> H >> W;
    vector<vector<bool>> a(H, vector<bool>(W));
    vector<vector<bool>> v(H, vector<bool>(W, false));
    rep(i, 0, H)
    {
        string tmpstr;
        cin >> tmpstr;
        rep(j, 0, W)
            a[i][j] = (tmpstr[j] == '#') ? true : false;
    }
    cout << func2(a, v) << endl;
}
int main()
{
    func();
}

Measured memory_bytes: 15432
n = int(input())
h = list(map(int, input().split()))
h.append(0)
cnt = 0
for i in range(len(h)):
    while True:
        if h[i] != 0:
            for j in range(i + 1, len(h)):
                if h[j] == 0:
                    m = min(h[i:j])
                    for k in range(i, j):
                        h[k] -= m
                    cnt += m
        else:
            break
print(cnt)


Measured memory_bytes: 3060
//
//  main.cpp
//  ABC124
//
//  Created by hiroaki on 2019/05/07.
//  Copyright © 2019年 hiroaki. All rights reserved.
//

#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>


//pair sort firstに揃う

#define int long long
#define pb(n) push_back(n)
#define Rap(n,i) for(int (i)=0;(i)<(n);(i)++)
#define Pr(n) cout<<n<<endl;
#define F first
#define S second
#define vector2 vector<vector<int> >
#define index(v,x) find((v).begin(), (v).end(), (x))-(v).begin()
#define ctoi(c) (int)(c-'0')
#define incin(n) int (n); cin>>(n);
#define stcin(s) string (s); cin>>(s);
#define all(v) (v).begin() , (v).end()
#define PI 3.14
#define Rad2Deg  57.29578

using namespace std;

signed  main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    stcin(s);
    incin(k);

    char ans = '1';
    for(int i=0;i<k;i++){
        if(s[i]!='1'){
            ans = (char)s[i];
            break;
        }
    }
    Pr(ans);
    return 0;
}


Measured memory_bytes: 256
n = gets.to_i
ans = Array.new(10**4 + 1, 0)
## x <= y <= zとする。
max_x = Math.sqrt(n/6).to_i
max_y = Math.sqrt(n/3).to_i
max_z = Math.sqrt(n).to_i
(1..max_x).each do |x|
  (x..max_y).each do |y|
    break if x**2 + y**2 + x*y + x + y + 1 > n
    (y..max_z).each do |z|
      result = x**2 + y**2 + z**2 + x*y + y*z + z*x
	  break if result > n
      if x == y && x == z
	      plus_cnt = 1
      elsif x == y || y == z || z == x
          plus_cnt = 3
      else
          plus_cnt = 6
      end
	      ans[result] += plus_cnt if result <= n
    end
  end
end
(1..n).each do |i|
  puts ans[i]
end

Measured memory_bytes: 14448
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif
//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long ll;
ll cnt[10];
int h, w, n;
unordered_map < ll, int > mp;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
//    freopen("input.txt", "r", stdin);
    cin >> h >> w >> n;
    for (int i = 1; i <= n; i++) {
        int x, y;
        cin >> x >> y;
        for (int t = -2; t <= 0; t++) {
            for (int g = -2; g <= 0; g++) {
                int nx = t + x;
                int ny = g + y;
                if (nx + 2 > h || nx <= 0 || ny + 2 > w || ny <= 0) continue;
                mp[1LL * w * nx + ny]++;
            }
        }
    }
    for (auto it : mp) {
        cnt[it.second]++;
    }
    ll tot = (1LL * h - 2) * (1LL * w - 2);
    cnt[0] = tot;
    for (int i = 1; i <= 9; i++) cnt[0] -= cnt[i];
    for (int i = 0; i <= 9; i++) cout << cnt[i] << '\n';
    return 0;
}

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

int main(){
                                                                     

    int n;

    
    cin >> n;

    if( n <= 999 ){

        cout << "ABC" << endl;

        return 0;

        }


    cout << "ABD" << endl;

    return 0;

    }

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
#define ld long double
#define ios       ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define forn(i,a,n) for (ll i = a; i < (ll)(n); i++)
#define fon(i,n) for (ll i = (ll)n-1; i >=0; i--)
#define vi          vector<ll>
#define vii vector<pair<ll,ll>>
#define all(a)      (a).begin(),(a).end()
#define pb push_back
#define mp make_pair
#define se second
#define fi first
#define ciin(v) forn(i,0,v.size()) cin>>v[i]
#define coutt(v) forn(i,0,v.size()) cout<<v[i]<<" "
using namespace std; 
int main(){
    ios
    ll t;
    t=1;
    //cin>>t;
    while(t--){
       ll k,n;
       cin>>k>>n;
       vi v(n);
       ciin(v);
       ll ans=0;
       forn(i,0,n-1){
        ans=max(ans,v[i+1]-v[i]);
       }
       ans=max(ans,(k-v[n-1])+v[0]);
       cout<<k-ans;
        

    }}

Measured memory_bytes: 1792
/* B - FizzBuzz Sum */

#include <stdio.h>

int main(void){
  int N, i;
  long long sum = 0;
  scanf("%d", &N);
  for(i = 1; i <= N; i++){
    if(i % 3 != 0 && i % 5 != 0){
      sum += i;
    }
  }
  printf("%lld\n", sum);

  return 0;
}


Measured memory_bytes: 1728
#include <iostream>

using namespace std;

bool prime_check(int n, int k = 2)
{
	if (n < k * k) { return true; }

	if (n % k == 0) { return false; }

	return prime_check(n, k + 1);
}

int main()
{
	int n;

	while (true)
	{
		cin >> n;

		if (n == 0) { break; }

		int l = n;
		int r = n;

		while (prime_check(l) == false)
		{
			l--;
		}

		while(prime_check(r) == false)
		{
			r++;
		}

		cout << r - l << endl;
	}

	return 0;
}

Measured memory_bytes: 1160
#include<iostream>
#include<algorithm>
#include<cstdint>

int64_t gcd(int64_t a, int64_t b) {
  int64_t r = a%b;
  while(r){ a=b; b=r; r=a%b; }
  return b;
}

int64_t floor_div(int64_t x, int64_t y) {
  int64_t res = x/y, rem = x%y; // res*y+rem == x and abs(rem)<abs(y) by spec
  if(rem!=0 && (rem < 0) != (y < 0)) --res;
  return res;
}

bool solve() {
  int64_t A, B, C, D; std::cin >> A >> B >> C >> D;
  if(A < B) return false;
  if(D < B) return false;
  if(C-B+1 >= 0) return true;
  int64_t q = gcd(D, B);
  int64_t r = A%q;
  // min next morning:
  int64_t x = floor_div(C-r, q) + 1;
  return q*x+r >= B;
}

int main() {
  std::cin.tie(0); std::ios::sync_with_stdio(false);
  int T; std::cin >> T;
  for(int i = 0; i < T; ++i) std::cout << (solve()? "Yes\n": "No\n");
  return 0;
}


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

inline long long calc(long long k, long long n) {
    return k * (n - k) + 1;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int N, K;
    const long long MAGIC = 1e9 + 7;
    cin >> N >> K;
    long long ans = 0;
    for (int i = K; i <= N+1; ++i) {
        ans = (ans + calc(i, N+1)) % MAGIC;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3644
#include<bits/stdc++.h>
#define ll long long
#define F(type, i, a, b) for(type i = a; i <= b; i ++)
#define RF(type, i, a, b) for(type i = a; i >= b;i --)
#define sz(a) sizeof(a)
#define deb(a) cerr<<" ["<<#a<<"->"<<a<<"] "
#define next_line cerr<<'\n'
#define all(a) a.begin(), a.end()
#define iter(it, s) for(auto it = s.begin(); it != s.end(); it ++)

using namespace std;

typedef pair<ll,ll> pii;
typedef pair<ll,ll> pll;

ll n, MaxBen = 0LL;
vector<ll> dp(2e5 + 1, -1);
ll Maxval(ll st, vector<ll> &h, vector<ll> &a){
    ll val = a[st], maxIncr = 0LL;
    if(dp[st ] != -1LL)
        return dp[st];
    F(ll, i, 0, st - 1){
        if(h[i] <= h[st]){
            maxIncr = max(maxIncr, Maxval(i, h, a));
        }
    }
    val += maxIncr;
    dp[st] = val;
    MaxBen = max(MaxBen, val);
    return val;
}

ll Query(ll st, ll end, ll node, ll l, ll r, vector<ll> &Tree){
    if(st > end)
        return 0LL;
    if((r < st) || (end < l))
        return 0LL;
    if((l <= st) && (end <= r))
        return Tree[node];
    ll mid = (st + end) >> 1;
    return max( Query(st, mid, 2LL * node, l, r, Tree), 
                Query(1LL + mid, end, 2LL * node + 1LL, l, r, Tree)); 
}

void update(ll st, ll end, ll node, ll indx, ll val, vector<ll> &Tree){
    if((indx < st) || (indx > end))
        return;
    if(st == end){
        Tree[node] = val;
        return;
    }
    ll mid = (st + end) >> 1LL;
    update(st, mid, 2LL * node, indx, val, Tree);
    update(mid + 1LL, end, 2LL * node + 1LL, indx, val, Tree);
    Tree[node] = max(Tree[2LL * node],
                     Tree[2LL * node + 1LL]);
}

void solve()
{
    cin>>n;
    vector<ll> Height(n), Beauty(n), Tree(4LL * n + 1LL, 0LL);
    F(ll, i, 0, n - 1){
        cin>>Height[i];
    }
    F(ll, i, 0, n - 1){
        cin>>Beauty[i];
    }
    // RF(ll, i, n - 1, 0){
    //     Maxval(i, Height, Beauty);
    // }
    //We need to find the maximum value of dp 
    //in heights less than our height
    //For this we need that the heights are in increasing 
    //order ,so that we can query over a range easily and find the
    //maximum of them. For this we can use segment tree .For heights
    //That we don't wanna involve ,we can simply initialize them as 0
    F(ll, st, 0, n - 1){
        ll Maxincr = Query(0LL, n - 1LL, 1LL, 0LL, Height[st] - 2LL, Tree);
        dp[st] = Maxincr + Beauty[st];
        update(0LL, n - 1LL, 1LL, Height[st] - 1LL, dp[st], Tree);
        MaxBen = max(MaxBen, dp[st]);
    }
    cout<<MaxBen<<'\n';
}

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


Measured memory_bytes: 14284
#include<iostream> 
#include<sstream> 
#include<string> 
#include<vector> 
#include<map> 
#include<set> 
#include<queue> 
#include<stack> 
#include<utility> 
#include<algorithm> 
#include<functional> 
#include<cstdio> 
#include<cstdlib> 
#include<cstring> 
#include<cmath> 
#include<cctype> 
  
using namespace std; 
  
#define FOR(i,a,b) for(int i=(a);i<(b);i++) 
#define REP(i,n) FOR(i,0,n) 
  
int main(){ 
    int h, w; 
      
    while(true) { 
        int tmpTaikaku; 
        int tmpH, tmpW; 
          
        cin>>h; 
        cin>>w; 
        if(h==0 && w==0) 
            break; 
        int taikakuMoto = h*h+w*w; 
          
        tmpTaikaku = 151*151+151*151; 
        tmpH = h; 
        for(int hh=1; hh<=150; hh++) { 
            for(int ww=hh+1; ww<=150; ww++) { 
          /*      if(taikakuMoto<hh*hh+ww*ww && hh*hh+ww*ww<tmpTaikaku) { 
                    tmpTaikaku = hh*hh+ww*ww; 
                    tmpH = hh; 
                    tmpW = ww; 
                } 
                else if(taikakuMoto<hh*hh+ww*ww && hh*hh+ww*ww==tmpTaikaku && hh<tmpH) { 
                    tmpH = hh; 
                    tmpW = ww; 
                } 
                else if(taikakuMoto == hh*hh+ww*ww && hh*hh+ww*ww < tmpTaikaku && tmpTaikaku!=151*151+151*151) { 
                    tmpTaikaku = hh*hh+ww*ww; 
                    tmpH = hh; 
                    tmpW = ww; 
                } 
                else if(taikakuMoto == hh*hh+ww*ww && hh<h) { 
                    tmpTaikaku = hh*hh+ww*ww; 
                    tmpH = hh; 
                    tmpW = ww; 
                } 
           */
                int tmpHW = hh*hh+ww*ww; 
                if(taikakuMoto<tmpHW && ((tmpHW<tmpTaikaku) || (tmpHW==tmpTaikaku && hh<tmpH))) { 
                    tmpTaikaku = tmpHW; 
                    tmpH = hh; 
                    tmpW = ww; 
                } 
                if(taikakuMoto==tmpHW && ((tmpHW<tmpTaikaku && hh!=h && ww!=w && h<hh) || (tmpHW==tmpTaikaku && h<hh && hh<tmpH))) { 
                    tmpTaikaku=tmpHW; 
                    tmpH=hh; 
                    tmpW=ww; 
                } 
                /* 
                if(taikakuMoto==tmpHW && hh<tmpH) { 
                    tmpTaikaku=tmpHW; 
                    tmpH=hh; 
                    tmpW=ww; 
                } 
                if(taikakuMoto==tmpHW && tmpHW==tmpTaikaku && hh<tmpH) { 
                    tmpTaikaku = tmpHW; 
                    tmpH = hh; 
                    tmpW = ww; 
                } 
                 */
            } 
        } 
        cout<<tmpH<<" "<<tmpW<<endl; 
    } 
      
      
      
      
      
    return 0; 
} 

Measured memory_bytes: 1160
H,W=map(int,input().split())
a=[]
for _ in range(H):
  a.append(list(map(lambda x: 1 if x=="#" else 0,list(input()))))
#print(a)

b=[]
for i in range(H):
  if sum(a[i])!=0:
    b.append(a[i])
#print(b)

c=[]
for j in range(W):
  cnt=0
  for i in range(len(b)):
    cnt+=b[i][j]
  c.append(cnt)
#print(c)

d=[]
for i in range(len(b)):
  dd=[]
  for j in range(W):
    if c[j]!=0:
      dd.append(b[i][j])
  d.append(dd)
#print(d)

for i in range(len(d)):
  print("".join(list(map(lambda x: "." if x==0 else "#",d[i]))))

Measured memory_bytes: 3188
X,Y = map(int,input().split())

MAX_NUM = 10**6 + 1
MOD = 10**9+7

fac  = [0 for _ in range(MAX_NUM)]
finv = [0 for _ in range(MAX_NUM)]
inv  = [0 for _ in range(MAX_NUM)]

fac[0]  = fac[1] = 1
finv[0] = finv[1] = 1
inv[1] = 1

for i in range(2,MAX_NUM):
    fac[i] = fac[i-1] * i % MOD
    inv[i] = MOD - inv[MOD%i] * (MOD // i) % MOD
    finv[i] = finv[i-1] * inv[i] % MOD

def combinations(n,k):
    if n < k:
        return 0
    if n < 0 or k < 0:
        return 0
    return fac[n] * (finv[k] * finv[n-k] % MOD) % MOD

if (X+Y)%3 != 0:
    answer = 0
else:
    up = -(X+Y)//3+Y
    right = -(X+Y)//3+X
    answer = combinations(up+right,up)
print(answer)

Measured memory_bytes: 208448
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int,int>
#define priq priority_queue<int>
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
#define tii tuple<int,int,int>
#define Priq priority_queue<int,vi,greater<int>>
#define pb push_back
#define mp make_pair
#define INF (1ll<<60)
int A[51],B[51];
int N,X;
int func(int sum,int K,int le){
  if(K==X) return sum;
  if(A[le]+K<X){
    return func(sum+B[le]+1,K+A[le]+1,le);
  }
  else if(A[le]+K==X) return sum+B[le];
  else return func(sum,K+1,le-1);
}
signed main(){
  cin>>N>>X;
  A[0]=B[0]=1;
  REP(i,1,50){
    A[i]=A[i-1]*2+3;
    B[i]=B[i-1]*2+1;
  }
  cout<<func(0,0,N)<<endl;
  }



Measured memory_bytes: 256
import sys
N=int(input())
alist=list(map(int,input().split()))

if N==0 and alist[0]!=1:
  print(-1)
  sys.exit(0)
elif N>0 and alist[0]>0:
  print(-1)
  sys.exit(0)

#pow2d=1<<N
blist=[0]*(N+1)
for d in reversed(range(1,N+1)):
  if d>50:
    blist[d-1]=alist[d]+blist[d]
  else:
    blist[d-1]=min(alist[d]+blist[d],(1<<(d-1))-alist[d-1])
  if blist[d-1]<0:
    print(-1)
    sys.exit(0)
  #pow2d>>=1
  
#print(alist,blist)
cmax_bu=[0]*(N+1)
for d in range(N+1):
  cmax_bu[d]=alist[d]+blist[d]
#print(cmax_bu)

pow2d=1
blist=[0]*(N+1)
if alist[0]==0:
  blist[0]=1
for d in range(1,N+1):
  if pow2d<10**10:
    pow2d<<=1
    c=min(2*blist[d-1],pow2d,cmax_bu[d])
  else:
    c=min(2*blist[d-1],cmax_bu[d])
  blist[d]=c-alist[d]
  if blist[d]<0:
    print(-1)
    sys.exit(0)
#print(alist,blist)

answer=0
for i in range(N+1):
  answer+=alist[i]+blist[i]
  
print(answer)

Measured memory_bytes: 84456
#include <stdio.h>
#define N 200005


int main(void){
  int n,r[N],i,d,min;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&r[i]);
  }
  min=r[0];
  d=-r[0];
  for(i=1;i<n;i++){
    if(r[i]-min>d){
      d=r[i]-min;
    }
    if(r[i]<min){
      min=r[i];
    }
  }
  
  printf("%d\n",d);
  
  return 0;
}

Measured memory_bytes: 1376
import java.util.Map.Entry;
import java.io.*;
import java.math.BigInteger;
import java.util.*;

public class Main {
	
	public static void main(String[] args) throws IOException {
		FastScanner sc = new FastScanner(System.in);
		
		int N = sc.nextInt();
		int M = sc.nextInt();
		String S = sc.next();
		String T = sc.next();
		
		long l = lcm((long)N, (long)M);
		int g = (int)gcd((long)N, (long)M);
		
		for(int i = 0; i < g; i++){
			if(S.charAt(N * i / g) != T.charAt(M * i / g)){
				System.out.println(-1);
				return;
			}
		}
		
		System.out.println(l);
	}
	
	public static long lcm(long a, long b){
		return a / gcd(a, b) * b; //オーバーフローに注意
	}
	
	public static long gcd(long a, long b){
		return b == 0 ? a : gcd(b, a % b);
	}
}

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


Measured memory_bytes: 22996
#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 <functional>

using namespace std;
 
#define mod 1000000007
#define FOR(x,to) for(int x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define long long long
inline int rei(){int x;cin>>x;return x;}
inline long rel(){long x;cin>>x;return x;}
inline string res(){string x;cin>>x;return x;}
//------------------------------------------------------- 
pair<int,int> A[200000];
void Calc(){
	int N = rei();
	for(int i=0;i<N;i++){
		A[i] = {rei(),i};
	}
	sort(A,A+N);
	for(int i=0;i<N;i++){
		if(A[N-1].second == i){
			cout << A[N-2].first << "\n";
		}
		else{
			cout << A[N-1].first << "\n";
		}
	}
}
int main(int argc,char** argv){
	ios::sync_with_stdio(false), cin.tie(0);
	cout.tie(0); Calc(); return 0;
}

Measured memory_bytes: 3200
#define ENABLE_LL
#include <iostream>
#include <cstdio>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <queue>
#include <cmath>
#include <cstring>
using namespace std;

#ifdef ENABLE_LL
#define int long long
#endif

#ifdef ENABLE_LL
#define I "%lld"
#define II "%lld%lld"
#define III "%lld%lld%lld"
#define IIII "%lld%lld%lld%lld"
#define IN "%lld\n"
#define IIN "%lld%lld\n"
#define IIIN "%lld%lld%lld\n"
#define IIIIN "%lld%lld%lld%lld\n"
#else
#define I "%d"
#define II "%d%d"
#define III "%d%d%d"
#define IIII "%d%d%d%d"
#define IN "%d\n"
#define IIN "%d%d\n"
#define IIIN "%d%d%d\n"
#define IIIIN "%d%d%d%d\n"
#endif

#ifdef __LOCALE__
#define see(a) std::cout << #a << "=" << a << std::endl
#define ses(a) std::cout << #a << "=" << a << " " 
#else
#define see(a) //std::cout << #a << "=" << a << std::endl
#define ses(a)
#endif
#define repe(a,b) for (int a=0;a<(int)b.size();a++)
#define rep(i,n) for (int i=0;i<n;i++)
#define repa(i,n) for (int i=1;i<=n;i++)
#define repi(i,a,b) for (int i=a;i<=b;i++) 
#define repb(i,a,b) for (int i=a;i>=b;i--)
typedef pair < int , int > pr;
typedef pair < pr  , int > prr;
#define L first
#define R second
template <class T> inline bool checkMin(T& a , T b) { return (a > b ? a=b,1 : 0); }
template <class T> inline bool checkMax(T& a , T b) { return (a < b ? a=b,1 : 0); }
class Scanner{ private: istream& ist;public: Scanner(istream& in):ist(in){} string next(){ string r; ist >> r; return r; } string nextLine(){ string r; getline(ist,r); return r; } int nextInt(){ int r; ist >> r; return r; } double nextDouble(){ double r; ist >> r; return r; }};
Scanner sc(cin);

const int MOD = 1e9 + 7;
const int N = 100005;
int x[N];
int n;

void init() {
    scanf(I,&n);
    rep (i,n) scanf(I,&x[i]);
}

int fac[N];
int pac[N];
int dp[N];
void solve() {
    fac[0] = 1;
    repa (i,n) fac[i] = fac[i-1] * i % MOD;
    pac[n] = 1;
    repb (i,n-1,0) pac[i] = pac[i+1] * i % MOD;
    dp[1] = 0;
    repi (i,2,n) dp[i] = (dp[i-1] * (i-1) + fac[i-2]) % MOD;
    repa (i,n) ses(dp[i]); see("");
    int ans = 0;
    repa (i,n-1) (ans += dp[i+1] * (x[i] -x[i-1]) % MOD * pac[i+1]) %= MOD;
    printf(IN,ans);
}

#ifdef ENABLE_LL
#undef int
#endif
int main(){
    init();
    solve();
    return 0;
}


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

int main() {
	int n, m;
	cin >> n >> m;
	vector<vector<int>> g(n);
	rep(i, m) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	string ans = "IMPOSSIBLE";
	for(int f: g[0]) {
		for(int s: g[f]) {
			if(s == n-1) ans = "POSSIBLE";
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 12016
// #include <bits/stdc++.h>
// using namespace std;
// #define ll long long
// int a[150];
// int dp[11000000]={0};
// int getans(int k,int n)
// {
//     if(dp[k]!=0) return dp[k];
//     for(int i=0;i<n;i++)
//     {
//         if(a[i]<=k)
//         {
//             if(getans(k-a[i],n)==2) return dp[k]=1;
//         }
//     }
//     return dp[k]=2;
// }

// void solve()
// {
//     int n,k;
//     cin>>n>>k;
//     dp[0]=2;
//     for(int i=0;i<n;i++) cin>>a[i];
//     if(getans(k,n)==1) cout<<"FIRST\n";
//     else cout<<"SECOND\n";
//     //for(int i=0;i<k;i++) cout<<dp[i]<<" ";
// }

// int main()
// {
//     ios_base::sync_with_stdio(false);
//     cin.tie(NULL);
//     cout.tie(NULL);
//     solve();
//     return 0;
// }
#include <iostream>
#include <bits/stdc++.h>
#include <cmath>
#include <vector>
#define ll long long int
#define mp make_pair
#define pb push_back
#define vi vector<int>
using namespace std;
long long int p=1e9 +7;
int n;
int moves[100];
int ans[100007]={0};
int solve(int k){
    if(ans[k]){
        return ans[k];
    }
    for(int i=0;i<n;i++){
        if(k>=moves[i]){
        if(solve(k-moves[i])==2){
            ans[k]=1;
            return ans[k];
        }
      }
    }
   ans[k]=2;
   return ans[k];
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	   int k;
	   cin>>n>>k;
	   for(int i=0;i<n;i++){
	       cin>>moves[i];
	   }
	   ans[0]=2;
	   if(solve(k)==1){
	    cout<<"First";   
	   }
	   else{
	       cout<<"Second";
	   }
}


Measured memory_bytes: 3712
#include <iostream>

using namespace std;

int main(){
    int N,K,Q,a;
    cin >> N >> K >> Q;
    int score[100001];
    for (int i=0;i<N;i++){
        score[i] = K-Q;
    }
    for (int i=0;i<Q;i++){
        cin >> a;
        score[a-1]++;
    }
    for (int i=0;i<N;i++){
        cout << (score[i]>0 ? "Yes" : "No") << endl;
    }

}


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

int main(){
    vector<vector<int>> A(3,vector<int>(3));

    for(int i=0;i<3;i++){
        for(int j=0;j<3;j++){
            cin >> A[i][j];
        }
    }
    int N; cin >> N;
    bool flag1 = false;
    if(N<=2){
        cout << "No" << endl;
    }else{
        for(int i=0;i<N;i++){
            int b; cin >> b;
            flag1 = false;
            for(int j=0;j<3;j++){
                for(int k=0;k<3;k++){
                    if(b == A[j][k]){
                        A[j][k] = 0;
                        flag1 = true;
                        break;
                    }
                    if(flag1){
                        break;
                    }
                }
            }

        }
        if(A[0][0] == A[0][1] && A[0][1] == A[0][2]){
            cout << "Yes" ;
        }else if(A[1][0] == A[1][1] && A[1][1] == A[1][2]){
            cout << "Yes" ;
        }else if(A[2][0] == A[2][1] && A[2][1] == A[2][2]){
            cout << "Yes" ;
        }else if(A[0][0] == A[1][0] && A[1][0] == A[2][0]){
            cout << "Yes" ;
        }else if(A[0][1] == A[1][1] && A[1][1] == A[2][1]){
            cout << "Yes" ;
        }else if(A[0][2] == A[1][2] && A[1][2] == A[2][2]){
            cout << "Yes" ;
        }else if(A[0][0] == A[1][1] && A[1][1] == A[2][2]){
            cout << "Yes" ;
        }else if(A[0][2] == A[1][1] && A[1][1] == A[2][0]){
            cout << "Yes" ;
        }else{
            cout << "No" ;
        }
    }



}

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

int main(){
  int a,b,c,d,e,k;
  cin >> a>> b>> c>> d>> e>> k;
  if(b-a>k)
  {
  cout << ":(" << endl;
  }
  else if(c-a>k)
  {
  cout << ":(" << endl;
  }
  else if(d-a>k)
  {
  cout << ":(" << endl;
  }
  else if(e-a>k)
  {
  cout << ":(" << endl;
  }
  else if(c-b>k)
  {
  cout << ":(" << endl;
  }
  else if(d-b>k)
  {
  cout << ":(" << endl;
  }
  else if(e-b>k)
  {
  cout << ":(" << endl;
  }
  else if(d-c>k)
  {
  cout << ":(" << endl;
  }
  else if(e-c>k)
  {
  cout << ":(" << endl;
  }
  else if(e-d>k)
  {
  cout << ":(" << endl;
  }
   else
  {
  cout << "Yay!" << endl;
  }
}

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

int main(void){
    int N, numR, numG, numB;
    char subS;
    cin >> N;
    vector<bool> R(N, false), G(N, false), B(N, false);
    numR = 0;
    numG = 0;
    numB = 0;
    for(int i=0; i<N; i++){
        cin >> subS;
        if(subS == 'R'){
            R[i] = true;
            numR++;
        }else if(subS == 'G'){
            G[i] = true;
            numG++;
        }else{
            B[i] = true;
            numB++;
        }
    }
    long long res = (long long)numR*numG*numB;
    for(int i=0; i<N; i++){
        for(int j=1; i+j*2<N; j++){
            if(R[i]&&G[i+j]&&B[i+2*j])res--;
            if(R[i]&&B[i+j]&&G[i+2*j])res--;
            if(G[i]&&R[i+j]&&B[i+2*j])res--;
            if(G[i]&&B[i+j]&&R[i+2*j])res--;
            if(B[i]&&R[i+j]&&G[i+2*j])res--;
            if(B[i]&&G[i+j]&&R[i+2*j])res--;
        }
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 3632
#include <stdio.h>
#include <math.h>
int main(void){
    // Your code here!
    long int x, y;
    long int n, d;
    long int point = 0;
    long int z;
    long int i;
    
    scanf("%ld %ld", &n, &d);
    if((n<1) || (n>200000)){
        printf("incorrect number:N\n");
        return -1;
    }
    if((d<0) || (d>200000)){
        printf("incorrect number:D\n");
        return -1;
    }
    
    for(i=0; i<n; i++){
        scanf("%ld %ld", &x, &y);
        if((x<-200000) || (x>200000)){
            printf("incorrect number:X\n");
            return -1;
        }
        if((y<-200000) || (y>200000)){
            printf("incorrect number:Y\n");
            return -1;
        }
        //printf("%ld %ld ", x, y);
        z = x*x + y*y;
        //printf("%ld ", z);
        //printf(" %f\n", sqrt(z));
        if(sqrt(z) <= d){
            point++;
        }
    }
    
    printf("%ld\n", point);
    
    return 0;
}


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

int main(){
  int a,b,c;
  std::cin >> a >> b >> c;

  if (a<b && b<c && a<c) {
    std::cout << "Yes" << std::endl;
    return 0;
  }

  std::cout << "No" << std::endl;
  return 0;
}



Measured memory_bytes: 3072