akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <functional>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <climits>

#define all(c) (c).begin(), (c).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)
#define fr first
#define sc second

const int INF=100000000;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
using namespace std;
typedef pair<int ,int > P;
typedef long long ll;

struct Lab {
    double l,a,b;
    Lab(double l=0,double a=0,double b=0) :
        l(l),a(a),b(b) { }
};
double pow2(double a) {
    return a*a;
}
double func(const Lab& lab1,const Lab& lab2) {
    double res = 0;
    res += pow2(lab1.l-lab2.l);
    res += pow2(lab1.a-lab2.a);
    res += pow2(lab1.b-lab2.b);
    return res;
}

int bitcount(int S) {
    int res = 0;
    rep(i,32) if((S>>i)&1) res++;
    return res;
}

Lab lab[22];
int N,M;

int main() {
    cin>>N>>M;
    rep(i,N) {
        double l,a,b;
        cin>>l>>a>>b;
        lab[i].l=l;
        lab[i].a=a;
        lab[i].b=b;
    }
    double ans = 0;
    rep(S,1<<N) {
        double tmp=0;
        if(bitcount(S)!=M) continue;
        rep(i,N) for(int j=i+1;j<N;j++) {
            if(((S>>i)&1) && ((S>>j)&1)) {
                tmp += func(lab[i],lab[j]);
            }
        }
        ans=max(ans,tmp);
    }

    printf("%.6f\n", ans);
    return 0;
}

Measured memory_bytes: 1248
import sys
n=int(input())
a=list(map(int,input().split()))
b=a[:]

for i in range(len(a)):
    if a[i]%2!=0:
        b.remove(a[i])

for i in b:
    if i%3!=0:
        if i%5!=0:
            print('DENIED')
            sys.exit()
            
print('APPROVED')

Measured memory_bytes: 9128
#include<bits/stdc++.h>
#define ll long long 
#define ull unsigned long long 
#define ld long double
#define ui unsigned int 
using namespace std;

int main() {
	int x, y,z,c;
	cin >> x >> y;
	z = x / y;
	c = x % y;
	double v = x*1.00 / y;
	cout << z << " " << c<<" ";
	cout << fixed << setprecision(5);
	cout << v<<endl;
}



Measured memory_bytes: 3244
N = int(input())
A = list(map(int, input().split()))
absA = sorted([abs(A[i]) for i in range(N)], reverse = True)
minuscount = 0
for i in range(N):
  if A[i] < 0:
    minuscount += 1
if minuscount % 2 == 0:
  print(sum(absA))
else:
  print(sum(absA[: -1]) - absA[-1])

Measured memory_bytes: 14412
#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include<algorithm>
#include<string>
#include <map>
#include <queue>
#include <stack>

#define DIV 1000000007
using namespace std;

typedef struct {
    int a;
    int b;
}rela_t;

bool cmp(const rela_t& p, rela_t& q)
{
    return p.b < q.b;
}

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

    vector<rela_t> rela(M);
    for (int i = 0; i < M; i++)
        cin >> rela[i].a >> rela[i].b;

    sort(rela.begin(), rela.end(),cmp);
    int right = 1;
    int ans = 0;
    for (int i = 0; i < M; i++) {
        if (right <= rela[i].a) {
            ans++;
            right = rela[i].b;
        }

    }
    cout << ans << endl;
}


Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
 
long long st[200010];
int vis[200010];
 
int main() {
	int x, m;
	long long n;
	scanf("%lld%d%d", &n, &x, &m);
	memset(vis, -1, sizeof(vis));
	long long ans = 0;
	int i;
	long long j;
	for (i = 0, j = x; vis[j] == -1; ++i, j = j * j % m)
		vis[j] = i, st[i] = j;
	if (n == vis[j]) {
		for (int k = 0; k < n; ++k)
			ans += st[k];
		printf("%lld\n", ans);
		return 0;
	}
	
	for (int k = 0; k <	vis[j]; ++k)
		ans += st[k];
	long long sum = 0;
	for (int k = vis[j]; k < i; ++k)
		sum += st[k];
	for (int k = 0; k < (n - vis[j]) % (i - vis[j]); ++k)
		ans += st[k + vis[j]];
	printf("%lld\n", ans + (n - vis[j]) / (i - vis[j]) * sum);
	return 0;
}

Measured memory_bytes: 4968
#include<iostream>
#include<string>
#include<algorithm>

using namespace std;

int N;
int edge[200 + 10][200 + 10];

int INF = 114514;

int visited[300 + 10];
bool isok = true;

void dfs(int pos, int bef) {
	for (int i = 0; i < N; i++) {
		if (edge[pos][i] == INF)continue;
		if (i == bef)continue;
		if (i == pos)continue;
		if (visited[i] == 0) {
			if(visited[pos] == 1)visited[i] = 2;
			else visited[i] = 1;
			dfs(i, pos);
		}
		else if(visited[i] + visited[pos] != 3){
			isok = false;
		}
	}
}

int main() {
	cin >> N;
	for (int i = 0; i < N; i++) {
		string s;
		cin >> s;
		for (int j = 0; j < N; j++) {
			if (s[j] == '0')edge[i][j] = INF;
			else edge[i][j] = 1;
		}
		edge[i][i] = 0;
	}

	visited[0] = 1;
	dfs(0, -1);
	if (!isok) {
		cout << -1 << endl;
		return 0;
	}
	int ans = 0;
	for (int k = 0; k < N; k++) {
		for (int i = 0; i < N; i++) {
			for (int j = 0; j < N; j++) {
				edge[i][j] = min(edge[i][j], edge[i][k] + edge[k][j]);
			}
		}
	}
	for (int i = 0; i < N; i++)for (int j = 0; j < N; j++) {
		if (edge[i][j] < INF)ans = max(ans, edge[i][j]);
	}
	cout << ans + 1 << endl;
	return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define vi vector<int>
#define all(x) (x).begin(),(x).end()
#define INF (1<<30)-1
using ll = long long;
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if(a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if(b<a) { a=b; return 1; } return 0; }

int main(){
  int n,m,x; cin >> n >> m >> x;
  vi c(n);
  vector<vi> a(n,vi(m));
  rep(i,n){
    cin >> c[i];
    rep(j,m) cin >> a[i][j];
  }
  ll ans = INF;
  for(int bit = 0; bit < (1<<n); bit++){
    vi sum(m);
    ll res = 0;
    rep(i,n){
      if(bit>>i & 1){
        res += c[i];
        rep(j,m) sum[j] += a[i][j];
      }
    }
    bool ok = true;
    rep(i,m){
      if(sum[i] < x){
        ok = false;
        break;
      }
    }
    if(ok) chmin(ans,res);
  }
  if(ans == INF) cout << -1;
  else cout << ans;
  cout << "\n";
  return 0;
}


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

int main() {
    int n; cin >> n;
    vector<int> a(n, 0);
    for (int i = 0; i < n; i += 1)
        cin >> a[i];
        
    int64_t full = accumulate(a.begin(), a.end(), 0LL);
    int64_t rolling = 0;
    
    int64_t ans = numeric_limits<int64_t> :: max() / 2;

    for (int i = 0; i < n; i += 1) {
        rolling += a[i];
        ans = min(ans, abs(rolling - (full - rolling)));
    }

    cout << ans << "\n";
}

Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while (true) {
			int n = sc.nextInt();
			if (n == 0)
				break;
			else {
				int[] s = new int[n];
				int sum1 = 0;
				double sum2 = 0;
				for (int i = 0; i < n; i++) {
					s[i] = sc.nextInt();
					sum1 += s[i];
				}
				double m = (double) sum1 / n;
				for (int i = 0; i < n; i++) {
					sum2 += (s[i] - m) * (s[i] - m);
				}
				double sd = Math.sqrt((double) sum2 / n);
				System.out.println(sd);
			}
		}
		sc.close();
	}

}



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

long long lcm(long long x, long long y){
    long long d = x * y;
    while(x*y > 0){
        if(x >= y){
            x %= y;
        }
        else{
            y %= x;
        }
    }
    return d / (x + y);
}

int main(){
    long long A, B, C, D;
    cin >> A >> B >> C >> D;
    long long n = lcm(C, D);
    long long a = (A/n + 1)*n;
    long long b = (B/n) * n;
    long long p = n - (A%n);
    long long q = B % n;

    if(p == n){
        cout << (B - A + 1) - ((p/C + p/D) + (((b-a)/n) * (n/D+n/C-1) - 1) + (q/C + q/D +1)) << endl;
    }

    else{
        cout << (B - A + 1) - ((p/C + p/D + 1) + (((b-a)/n) * (n/D+n/C-1) - 1) + (q/C + q/D +1)) << endl;
    }
}

Measured memory_bytes: 256
import Foundation

#if swift(>=4.0)
extension String {
    func split(by separator: String) -> [String] {
        return self.components(separatedBy: separator)
    }
    func toArray() -> [String] {
        return self.map{String($0)}
    }
}
#else
extension String {
    func split(by separator: String) -> [String] {
        return self.componentsSeparatedByString(separator)
    }
    func count() -> Int {
        return self.characters.count
    }
    func toArray() -> [String] {
        return self.characters.map{String($0)}
    }
}
extension Array where Element: Comparable {
    func max() -> Element! {
        return self.maxElement()
    }
    func min() -> Element! {
        return self.minElement()
    }
    func sorted() -> Array {
        return self.sort()
    }
    func reversed() -> Array {
        return self.reverse()
    }
    mutating func sort() {
        self.sortInPlace()
    }
}
extension Array {
    init(repeating: Element, count: Int) {
        self.init(count: count, repeatedValue: repeating)
    }
}
func stride<T: Strideable>(from start: T, to end: T, by stride: T.Stride) -> StrideTo<T> {
    return start.stride(to: end, by: stride)
}
#endif
func readInt() -> Int? {
    return Int(readLine()!)
}
func readStringSplit(by separator: String) -> [String] {
    return readLine()!.split(by: separator)
}
func readIntSplit(by separator: String) -> [Int] {
    return readLine()!.split(by: separator).map{Int($0)!}
}

/*************** テストスペース ***************/



/*************** メインプログラム ***************/

let N = readInt()!
var ans = 0
var maxP = 0
for _ in 0..<N {
    let p = readInt()!
    ans += p
    maxP = max(p, maxP)
}
print(ans-maxP/2)


Measured memory_bytes: 3828
n = int(input())
h = list(map(int, input().split()))

result = True
for i in range(n):
    if n == 1:
        break
    
    pos = ""
    if (i == 0):
        if (h[i] > h[i+1]):
            h[i] -= 1
    elif (i == (n-1)):
        if (h[i] > h[i-1]):
            h[i] -= 1
    else:
        if (h[i] > h[i+1]) | (h[i] > h[i-1]):
            h[i] -= 1
    
    if (i != 0):
        if(h[i] < h[i-1]):
            result = False
            break

            
if result:
    print("Yes")
else:
    print("No")

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

using i64 = int64_t;

int main(){
    string s;
    cin >> s;
    if(s[6] >= '5' || s[5] == '1')cout << "TBD";
    else cout << "Heisei";
    cout << endl;

    return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<string>
#include<iostream>
#include<cctype>
#include<cstdio>
#include<vector>
#include<stack>
#include<queue>
#include <algorithm>
#include<math.h>
#include<set>
#include<map>
#include<iomanip>

//#include<bits/stdc++.h>


using namespace std;



int main() {
	int n, m;
	cin >> n >> m;

	pair<int, int>r[51], t[51];
	for (int i = 0; i < n; i++)
		cin >> r[i].first >> r[i].second;
	for (int i = 0; i < m; i++)
		cin >> t[i].first >> t[i].second;
	for (int i = 0; i < n; i++) {
		int y = 0,b=1000000000;
		for (int j = 0; j < m; j++) {
			if (abs(r[i].first - t[j].first) + abs(r[i].second - t[j].second) < b) {
				b = abs(r[i].first - t[j].first) + abs(r[i].second - t[j].second);
				y = j;
			}
		}
		cout << y+1 << endl;
	}

	return 0;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = double;
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define all(v) (v).begin(),(v).end()
#define siz(v) (ll)(v).size()
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define repi(i,x,n) for(ll i=x;i<(ll)(n);i++)
#define lb lower_bound
#define ub upper_bound
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
const ll mod = 1000000007;
const ll INF = 1000000099;
vector<ll> dx={-1,1,0,0},dy={0,0,-1,1};
//cin.tie(0);ios::sync_with_stdio(false);



signed main(){
    ll n,k,ans=0;cin>>n>>k;
    string s;cin>>s;
    vector<ll> l(n+1,0),r(n+1,0);

    ll lcnt=0,rcnt=0;
    rep(i,n){
        if(s[i]=='L'){
            lcnt++;
            rcnt=0;
        }else{
            rcnt++;

            lcnt=0;
        }
        if(max(lcnt,rcnt)>1){
            l[i+1]=l[i]+1;
        }else{
            l[i+1]=l[i]+max(lcnt,rcnt)-1;
        }
            
        //cout<<l[i+1]<<endl;
    }

    lcnt=0,rcnt=0;
    for(int i=n-1;0<=i;i--){
        if(s[i]=='L'){
            lcnt++;
            rcnt=0;
        }else{
            rcnt++;

            lcnt=0;
        }

        if(max(lcnt,rcnt)>1){
            r[i+1]=r[i]+1;
        }else{
            r[i+1]=r[i]+max(lcnt,rcnt)-1;
        }
        //cout<<r[i]<<endl;
    }
    

    ll ri=0,cnt=0;
    for(int li=0;li < n-1;li++)
    {
        while(cnt<=2*k){
            if(ri>=n-1){
                //cout<<li<<" "<<ri<<endl;
                ans=max(ans,ri-li+l[li]);//
                goto flag;
            }
            if(s[ri]!=s[ri+1]){
                cnt++;
            }
            ri++;
        }
        ans=max(ans,ri-1-li+l[li]+r[ri]);

        while(s[li]==s[li+1]){
            li++;
        }
        cnt--;
    }
    flag:;
    cout<<ans<<endl;

}

Measured memory_bytes: 2048
#include <string>
#include <iostream>
using namespace std;
int a[100]; string s;
int main() {
	while(cin >> s) {
		int n = s.size();
		for(int i = 0; i < n; i++) {
			switch(s[i]) {
				case 'I': a[i] = 1; break;
				case 'V': a[i] = 5; break;
				case 'X': a[i] = 10; break;
				case 'L': a[i] = 50; break;
				case 'C': a[i] = 100; break;
				case 'D': a[i] = 500; break;
				case 'M': a[i] = 1000; break;
			}
		}
		int ret = 0;
		for(int i = 0; i < n - 1; i++) {
			if(a[i] >= a[i + 1]) ret += a[i];
			else ret -= a[i];
		}
		printf("%d\n", ret + a[n - 1]);
	}
	return 0;
}

Measured memory_bytes: 3056
#include<iostream>
using namespace std;
int main() {
	int a, b[20],c=0,p=0;
	cin >> a;
	for (int i = 0; i < a; i++) {
		cin >> b[i];
	}
	for (int i = 1; i < a; i++) {
		for (int j = 0; j < i; j++) {
			if (b[i] < b[j])c++;
		}
		if (c==0)p++;
		c = 0;
	}
	cout << p + 1 << endl;

	return 0;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int inf = 1e8;
typedef pair <int, int> pii;

struct Tree {
	int size;
	pii t[200010 * 4];
	void set_size(int n) {
		this -> size = n;
		for(int i = 0; i <= 4 * size; i++) {
			t[i] = pii(0, 0);
		}
	}
	void update(int x, int val, int c, int b, int e) {
		if(b == e) {
			t[c] = pii(val, b);
			return ;
		}
		int m = (b + e) >> 1;
		int l = c << 1;
		int r = l + 1;
		if(x <= m) update(x, val, l, b, m);
		else update(x, val, r, m+1, e);
		t[c] = min(t[l], t[r]);
	}
	pii query(int x, int y, int c, int b, int e) {
		if(x <= b && e <= y) {
			return t[c];
		}
		if(y < b || e < x) return pii(inf, inf);
		int m = (b + e) >> 1;
		int l = c << 1;
		int r = l + 1;
		return min(query(x, y, l, b, m), query(x, y, r, m+1, e));
	}
	void update(int x, int val) {
		update(x, val, 1, 1, size);
	}
	pii query(int x, int y) {
		return query(x, y, 1, 1, size);
	}
} t[2];
int a[200010];
pii getPair(int x, int y) {
	if(x > y) return pii(-1, -1);
	pii p1 = t[x & 1].query(x, y);
	pii p2 = t[(x & 1) ^ 1].query(p1.second, y);
	return pii(p1.second, p2.second);
}
struct data {
	int l, r;
	int p1, p2;
	bool operator < (data x) const {
		if(p1 == x.p1) {
			return a[p2] > a[x.p2];
		}
		return a[p1] > a[x.p1];
	}
};
int main (int argc, char const* argv[])
{
	int n;
	scanf("%d", &n);
	for(int i = 1; i <= n; i++) {
		scanf("%d", &a[i]);	
	}
	t[0].set_size(n);
	t[1].set_size(n);
	for(int i = 1; i <= n; i++) {
		t[i & 1].update(i, a[i]);
		t[(i & 1) ^ 1].update(i, inf);
	}		
	priority_queue <data> Q;
	pii p = getPair(1, n);
	Q.push({1, n, p.first, p.second});
	
	vector <int> v;
	
	while(!Q.empty()) {
		data x = Q.top();
		Q.pop();
		v.push_back(a[x.p1]);
		v.push_back(a[x.p2]);
		
		pii q1 = getPair(x.l, x.p1 - 1);
		pii q2 = getPair(x.p1 + 1, x.p2 - 1);
		pii q3 = getPair(x.p2 + 1, x.r);
		
		if(q1.first > 0) Q.push({x.l, x.p1 - 1, q1.first, q1.second});
		if(q2.first > 0) Q.push({x.p1 + 1, x.p2 - 1, q2.first, q2.second});
		if(q3.first > 0) Q.push({x.p2 + 1, x.r, q3.first, q3.second});
	}
	
	for(auto i : v) {
		printf("%d ", i);
	}
	printf("\n");
	return 0;
}

Measured memory_bytes: 16372
#include <bits/stdc++.h>
#define int long long
#define ALL(v) (v).begin(),(v).end()
#define Vi vector<int>
#define pb push_back
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repr(i,a,b) for(int i=a;i>b;i--)
#define leng(n) (int)(log10(n)+1)
#define INF 9000000000000000000
using namespace std;

int gcd(int a,int b){return b?gcd(b,a%b):a;}  //  最大公約数gcd
int lcm(int a,int b){return a/gcd(a,b)*b;}  //  最小公倍数lcm

signed main() {
  int a,b,c,d;
  cin >> a >> b >> c >>d;
  if(a>=b) cout << b*c + (a-b)*d << endl;
  if(a<b) cout << a*c << endl;
}


Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		
		long T = sc.nextLong();
		
		for(int i = 1; i < N; i++) {
			long t = sc.nextLong();
			long gcd = gcd(T, t);
			T = T / gcd * t;
		}
		System.out.println(T);
	}
	
	public static long gcd(long a, long b) {
		if(b == 0) {
			return a;
		}
		return gcd(b, a % b);		
	}
}


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

int main() {
	int n;
	cin >> n;
	vector<int> a(n);
	rep(i, n) cin >> a[i];
	sort(a.begin(), a.end(), greater<>());
	int cnt = 1;
	ll ans = 0;
	REP(i, 1, n - 1) {
		ans += a[i / 2];
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 4048
#include<iostream>
using namespace std;
int main(){
  int a,b;cin >>a >>b;
  if( a == b) cout << "Draw" << endl;
  else if(a == 1) cout << "Alice" << endl;
  else if(b == 1) cout << "Bob" << endl;
  else if( a > b) cout << "Alice" << endl;
  else cout << "Bob" << endl;
}

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

int main() {
  int N;
  int min_num = pow(10, 9);
  int max_num = 0;
  cin >> N;

  rep(i, N) {
    int a;
    cin >> a;
    min_num = min(min_num, a);
    max_num = max(max_num, a);
  }

  cout << abs(max_num - min_num) << endl;

  return 0;
}

Measured memory_bytes: 3584
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();
// freopen("input.txt", "r", stdin);

int main() {
	int n, d;
  	cin >> n;
  	set<int> ans;
  	for(int i = 0; i < n; i++) {
    	cin >> d;
      	ans.insert(d);
    }
  	cout << ans.size() << endl;
    return 0;
}



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


int main() {
  int N;
  string S;
  cin >> N;
  cin >> S;
    long int Ans = 0;
  long int Rkosu = 0;
  long int Gkosu = 0;
  long int Bkosu = 0;
  
  for(int i=0; i<N; i++){
    
     if(S.at(i) == 'R'){
       Rkosu++;
     }
    
    if(S.at(i) == 'G'){
       Gkosu++;
     }
    
    if(S.at(i) == 'B'){
       Bkosu++;
     }
    
  }
  
    Ans = Rkosu * Gkosu * Bkosu;
      
      for(int i=0; i<N; i++){
        
        for(int j=1; i+2*j<N; j++){
          if(S.at(i)!=S.at(i+j) && S.at(i)!=S.at(i+2*j) && S.at(i+j)!=S.at(i+2*j)){
            Ans--;
          }
             
        }
    
      }
  cout << Ans;
}


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

ll diff_a(ll a, ll b){
    return max(a-b, z);
}

ll diff_b(ll a, ll b){
    return max(b - a, z);
}

int main(){
    int n;
    cin >> n;
    vector<ll> a(n+1);
    rep(i, n+1){
        cin >> a[i];
    }
    ll cnt = 0;
    ll b;
    rep(i, n){
        cin >> b; 
        ll ax = diff_a(a[i], b);
        ll bx = diff_b(a[i], b);
        cnt += a[i] - ax;
        a[i] = ax;
        b = bx;
        if (b > z){
            ll ax = diff_a(a[i+1], b);
            cnt += a[i+1] - ax;
            a[i+1] = ax;
        }
    }
    cout << cnt << endl;
}


Measured memory_bytes: 1024
def resolve():
    # 整数 1 つ
    # n = int(input())
    # 整数複数個
    n, l = list(map(int, input().split()))
    # 整数 N 個 (改行区切り)
    S = [input() for i in range(n)]
    # 整数 N 個 (スペース区切り)
    # N = list(map(int, input().split()))
    # 整数 (縦 H 横 W の行列)
    #S = [list(map(str, input().split())) for i in range(n)]

    Ssort = sorted(S)
    print("".join(Ssort))
resolve()

Measured memory_bytes: 38432
A, B, C, K = map(int,input().split())

if K <= A:
    print(K)
else:
    cards  = [A, B, C]
    points = [1, 0, -1]
    val = 0
    rem = K
    for i in range(3):
        rem -= cards[i]
        if rem <= 0:
            val += (cards[i] + rem) * points[i]
            break
        else:
            val += cards[i] * points[i]
    print(val)

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

int main(){

  int H,W,i,j;


  while(1){
    
  cin >> H >> W;
  if(H==0 && W==0) break;

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

    for(j=1;j<=W;j++){

      if(i%2!=0){
	if(j%2!=0){
	cout << "#";
	}else{
	  cout << ".";
	}
      }else{
	if(j%2==0){
	  cout << "#";
	}else{
	  cout << ".";
	}
      }
    }
    cout << endl;
  }
  cout << endl;
  
  }
}


Measured memory_bytes: 3088
/*
 * Created By : pash123
 * 2020-08-29-17.21
*/


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;

const int M=1e9+7;
vector<ll> prefSum;

int main()
{
    int n;
    cin>>n;
    int a[n];
    ll sum=0;
    for(int i=0;i<n;++i)
        {
            cin>>a[i];
            sum+=a[i];
            prefSum.push_back(sum);
        }
    ll ans=0;
    for(int i=0;i<n;++i)
    {
        ans= ((ans%M) + ((((a[i]%M) *((prefSum[n-1]-prefSum[i])%M))%M)%M))%M;
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 5836
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from bisect import bisect

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

H, W = MAP()
S = [list(input()) for _ in range(H)]

dx = [0, -1, -1, -1, 0, 1, 1, 1]
dy = [-1, -1, 0, 1, 1, 1, 0, -1]

for i in range(H):
	for j in range(W):
		tmp = 0
		for k in range(8):
			x = j+dx[k]
			y = i+dy[k]
			if 0 <= x <= W-1 and 0 <= y <= H-1:
				if S[y][x] == "#":
					tmp += 1
		if not S[i][j] == "#":
			S[i][j] = tmp

for i in range(H):
	print(*map(str, S[i]), sep="")


Measured memory_bytes: 5580
module mod_binary_tree
  implicit none
  type t_node
    type(t_node), pointer :: left => null(), right => null()
  end type
contains
  function newn0() result(res)
    type(t_node), pointer :: res
    res => null()
    allocate(res)
  end
end module mod_binary_tree
program prefix_free_game
  use mod_binary_tree
  implicit none
  integer :: n, m, i, j
  integer(8) :: l, x = 0
  character(100000) :: s
  type(t_node), pointer :: root, node
  root => newn0()
  read(*,*) n, l
  do i = 1, n
    read(*,*) s
    m = len_trim(s)
    node => root
    do j = 1, m
      if (s(j:j) == '0') then
        if (.not.associated(node%left)) node%left => newn0()
        node => node%left
      else
        if (.not.associated(node%right)) node%right => newn0()
        node => node%right
      end if
    end do
  end do
  call dfs(root, 0)
  write(*,'(a)') trim(merge('Bob  ', 'Alice', x == 0))
contains
  recursive subroutine dfs(node, depth)
    type(t_node), pointer, intent(in) :: node
    integer, intent(in) :: depth
    logical :: fl, fr
    fl = associated(node%left)
    fr = associated(node%right)
    if (fl) then
      if (.not.fr) call grundy(l - depth)
      call dfs(node%left, depth + 1)
    end if
    if (fr) then
      if (.not.fl) call grundy(l - depth)
      call dfs(node%right, depth + 1)
    end if
  end
  subroutine grundy(h)
    integer(8), intent(in) :: h
    integer :: i
    do i = 0, 63
      if (btest(h, i)) then
        x = xor(x, ibset(0_8, i))
        return
      end if
    end do
  end
end program prefix_free_game

Measured memory_bytes: 12308
#include <stdio.h>
int main() {
  int N;
  scanf("%d", &N);
  int adjust = 101;
  int total = 0;
  for (int i = 0; i < N; ++i) {
    int n;
    scanf("%d", &n);
    total += n;
    if (n % 10 != 0 && n < adjust)
      adjust = n;
  }
  if (total % 10)
    printf("%d\n", total);
  else if (adjust < 101)
    printf("%d\n", total - adjust);
  else
    printf("0\n");
  return 0;
}

Measured memory_bytes: 128
def multiply(num_list):
  # if "0" in list, return 0
  if 0 in num_list:
    return 0
  
  # if res > 10^18: return -1
  MAX = pow(10,18)
  res = 1
  for i in num_list:
    res *= i
    if res > MAX:
      return -1
  return res

input()
num_list = list(map(int,input().split()))
print(multiply(num_list))

Measured memory_bytes: 21600
# D - Flipping Signs
# https://atcoder.jp/contests/abc125/tasks/abc125_

import sys
sys.setrecursionlimit(1000000)

N = int(input())
A = list( map(int, raw_input().split()) )

rcd = dict()

# dynamic programming, dp(current_position, (i-1)-th_sign)
def dp(pos, sign):

    # boundary condition
    if pos == N-1:
        if sign == 0:
            return A[pos]
        else:
            return -A[pos]

    # if visit (pos, sign) state before
    if (pos, sign) in rcd:
        return rcd[(pos, sign)]

    elif sign == 0:
        # memorize
        rcd[(pos, sign)] = max( dp(pos+1, 0) + A[pos], dp(pos+1, 1) - A[pos])
        return rcd[(pos, sign)]

    else: # st == 1
        # memorize
        rcd[(pos, sign)] = max( dp(pos+1, 0) -  A[pos], dp(pos + 1, 1) + A[pos])
        return rcd[(pos, sign)]

print '{}'.format( dp(0,0) )


Measured memory_bytes: 114244
module WeightedGraph
  (Vertex : sig
    type t
    val compare : t -> t -> int
  end)
  (Weight : sig
    type t
    val compare : t -> t -> int
  end) :
sig
  val prim :
    (* 隣接リスト *)
    (Vertex.t -> (Vertex.t * Weight.t) list) ->
    (* 始点 *)
    Vertex.t ->
    (* 最小全域木に含まれる辺のリスト *)
    (Vertex.t * Vertex.t * Weight.t) list
end =
struct
  module VSet = Set.Make (Vertex)
  module WMap = Map.Make (Weight)
 
  (*
   * プリム法のメインループ
   * es : 隣接リスト
   * vs : 訪れた頂点の集合
   * q : 訪れた頂点から伸びる辺が重み順に入ったヒープ
   * acc : 最小全域木に使うのが確定した辺を入れるやつ
   *)
  let rec prim_aux es acc vs q =
    match WMap.min_binding q with
    | exception Not_found -> acc
    | (w, []) -> prim_aux es acc vs (WMap.remove w q)
    | (w, (u, v) :: rest) ->
        if VSet.mem v vs then
          (* vは既に訪れていた *)
          prim_aux es acc vs (WMap.add w rest q)
        else
          (* vはまだ訪れていなかった *)
          prim_aux es ((u, v, w) :: acc) (VSet.add v vs) @@
            (* vから伸びる辺をキューに追加 *)
            List.fold_left (fun q (u, w) ->
              WMap.add w ((v, u) :: try WMap.find w q with Not_found -> []) q) (WMap.add w rest q) (es v)
 
  let prim es s =
    prim_aux es [] (VSet.singleton s) @@
      (* 始点から伸びる辺をキューに入れておく *)
      List.fold_left (fun q (v, w) ->
        WMap.add w ((s, v) :: try WMap.find w q with Not_found -> []) q) WMap.empty (es s)
end
 
module Int = struct
  type t = int
  let zero = 0
  let ( + ) = ( + )
  let compare = compare
end
 
module G = WeightedGraph (Int) (Int)
 
let () = Scanf.scanf "%d\n" (fun n ->
  let xys = Array.to_list @@ Array.init n (fun i -> Scanf.scanf "%d %d\n" (fun x y -> x, y, i)) in
  let es = Array.make n [] in
  begin match List.sort (fun (x, _, _) (x', _, _) -> compare x x') xys with
  | [] -> ()
  | (x, y, i) :: rest ->
      ignore @@ List.fold_left (fun (x, y, i) (x', y', j) ->
        es.(i) <- (j, min (abs (x - x')) (abs (y - y'))) :: es.(i);
        es.(j) <- (i, min (abs (x - x')) (abs (y - y'))) :: es.(j);
        (x', y', j)) (x, y, i) rest
  end;
  begin match List.sort (fun (_, y, _) (_, y', _) -> compare y y') xys with
  | [] -> ()
  | (x, y, i) :: rest ->
      ignore @@ List.fold_left (fun (x, y, i) (x', y', j) ->
        es.(i) <- (j, min (abs (x - x')) (abs (y - y'))) :: es.(i);
        es.(j) <- (i, min (abs (x - x')) (abs (y - y'))) :: es.(j);
        (x', y', j)) (x, y, i) rest
  end;
  G.prim (fun i -> es.(i)) 0
  |> List.map (fun (_, _, w) -> w)
  |> List.fold_left ( + ) 0
  |> Printf.printf "%d\n")

Measured memory_bytes: 75260
def sieve(n):
    is_prime = [True for _ in range(n+1)]
    is_prime[0] = False

    for i in range(2, n+1):
        if is_prime[i-1]:
            j = 2 * i
            while j <= n:
                is_prime[j-1] = False
                j += i
    table = [ i for i in range(1, n+1) if is_prime[i-1]]
    return is_prime, table
N=int(input())
_, table = sieve(N)
d={}
for p in table:
    sum_=0
    calc=p
    while calc <= N:
        sum_ += N//calc
        calc *= p
    d[p] = sum_
    
lim = 10**9+7
ans=1
for i in d.values():
    ans = (ans * (i+1)) % lim
print(ans)

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

using ll = long long;
using P = pair<int, int>;

const int INF = 1e9;
const int MOD = 1e9 + 7;

// 4近傍、8近傍
int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};

bool dir[4];

int main() {
  // 入力
  string s;
  cin >> s;

  for (int i = 0; i < s.size(); i++) {
    if (s[i] == 'N') {
      dir[0] = true;
    } else if (s[i] == 'E') {
      dir[1] = true;
    } else if (s[i] == 'S') {
      dir[2] = true;
    } else {
      dir[3] = true;
    }
  }

  // 解答
  int cnt = 0;
  for (int i = 0; i < 4; i++) if (dir[i]) cnt++;
  if (cnt == 2 || cnt == 4) {
    if ((dir[0] && dir[1] && dir[2] && dir[3]) || (dir[0] && dir[2]) || (dir[1] && dir[3])) {
      cout << "Yes" << endl;
    } else {
      cout << "No" << endl;
    }
  } else {
    cout << "No" << endl;
  }

  return 0;
}


Measured memory_bytes: 256
// c++include
#include <iostream>
#include <algorithm>
// cinclude
#include <stdio.h>
#include<string.h>
#include<math.h>
//c++標準ライブラリ
#include<vector>
#include<string>
//std使用<-namespace
using namespace std;

// define, typedef
#define rpt(i, n) for(ll i = 0; i < (n); i++)
typedef long long ll;

// main関数
int main(void) {
	string str;
	cin >> str;
	if (str == "Sunny") {
		str = "Cloudy";
	}
	else if (str == "Cloudy") {
		str = "Rainy";
	}
	else {
		str = "Sunny";
	}
	cout << str;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>

int main(){
  int n;
  scanf("%d\n",&n);
  int sum=0;
  char s[n];
  //s=malloc(sizeof(char)*(n+1));
  for(int i=0;i<n;i++){
    scanf("%c",&s[i]);
    if(i==0){
      sum=1;
      continue;}
    if(s[i-1]!=s[i]){
      sum++;}
  }
  printf("%d\n",sum);
  return 0;
}


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

int n,sa=0,sb=0;
int a[100005];

bool cmp(int a,int b)
{
	return a>b;
}

signed main()
{
	cin>>n;
	for (int i=1;i<=n;i++)  cin>>a[i];
	
	sort(a+1,a+n+1,cmp);
	
	for (int i=1;i<=n;i++)
	{
		if (i%2==0)  sa+=a[i];
		else sb+=a[i];
	}
	cout<<abs(sa-sb)<<endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
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;
}
typedef long long int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define MOD (1000000007)
#define ALL(v) (v).begin(), (v).end()
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, m;
    cin >> n >> m;
    priority_queue<ll, vector<ll>, greater<ll>> a;
    vector<pair<ll, ll>> bc(m);
    for (ll i = 0; i < n; i++)
    {
        ll tmp;
        cin >> tmp;
        a.push(tmp);
    }
    for (ll i = 0; i < m; i++)
    {
        cin >> bc[i].first >> bc[i].second;
    }

    sort(ALL(bc), [](const auto &a, const auto &b) { return a.second > b.second; });

    for (ll i = 0; i < m; i++)
    {
        bool flg = false;
        for (ll j = 0; j < bc[i].first; j++)
        {
            if (a.top() < bc[i].second)
            {
                a.pop();
                a.push(bc[i].second);
            }
            else
            {
                flg = true;
                break;
            }
        }
        if (flg)
        {
            break;
        }
    }

    ll ans = 0;

    while (!a.empty())
    {
        ans += a.top();
        a.pop();
    }

    cout << ans << endl;
}

Measured memory_bytes: 2936
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
int a[100010];
int main()
{
    int n,c,k,cnt=0,ans=0;
    cin>>n>>c>>k;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
    }
    sort(a+1,a+n+1);
    int i=1;
    while(1)
    {
        for(int j=i;j<=i+c-1;j++)
        {
            if(j>n) break;
            if(a[j]-a[i]<=k)
            {
                ++cnt;
            }
            else break;
        }
        if(cnt)
        {
            ++ans;
            i=cnt+i;
            cnt=0;
        }
        if(i>n) break;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 640
#include <stdio.h>

int prime(int n){
	int i;
	if(n%2 == 0)return 0;
	for(i = 3;i*i <= n;i += 2){
		if(n%i == 0)return 0;
	}
	
	return 1;
}

int main(void){
	int N;
	int num[10000];
	
	int i,j;
	
	int result = 0;
	
	scanf("%d",&N);
	
	for(i = 0;i < N;i++){
		scanf("%d",&num[i]);
	}
	
	
	
	for(i = 0;i < N;i++){
		if(num[i] == 2){
			result++;
		}else{
			result += prime(num[i]);
		}
	}
	
	printf("%d\n",result);
	
	return 0;
}

Measured memory_bytes: 628
N = int(input())
g = 0
h = 0
for i in range(N):
    D1,D2 = map(int,input().split())
    if D1 == D2:
        g += 1
    else:
        g = 0
    if g == 3:
        h = 1
if h:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 62220
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<P,int> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1000000000000000000;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

int q,n;
ll t,x,y;
vl a,b;

ll f(int I,ll A,ll B){
	if(I==1) b[I]=2;
	else b[I]=b[I-1]+b[I-2];
	if(I==t){
		ll res=0;
		if(b[I]<=x) (res+=(x-b[I])/b[I-1]+1)%=mod;
		if(b[I]<=y) (res+=(y-b[I])/b[I-1]+1)%=mod;
		return res;
	}
	ll res=f(I+1,A,B);
	while(1){
		b[I]+=b[I-1];
		A-=b[I-1]*(t-I-2<0?1:a[t-I-2]);
		B-=b[I-1]*(t-I-1<0?1:a[t-I-1]);
		if(A<0||B<0) break;
		(res+=f(I+1,A,B))%=mod;
	}
	return res;
}

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin>>q;
	a.push_back(1);
	a.push_back(2);
	while(a.back()<=INF) a.push_back(a.back()+a[a.size()-2]);
	n=a.size();
	b=a;
	for(int i=0;i<q;i++){
		cin>>x>>y;
		if(x==1&&y==1){
			cout<<1<<' '<<1<<endl;
			continue;
		}
		if(x>y) swap(x,y);
		for(int j=0;j<n;j++) if(a[j]>x){
			t=j;
			if(a[j]>y) t--;
			break;
		}
		cout<<t<<' '<<f(1,x-a[t-1],y-a[t])+(t==1?x:0)<<endl;
	}
}

Measured memory_bytes: 4096
#include<bits/stdc++.h>
#define P push_back
#define N 41
using namespace std;
typedef long long ll;
ll n,m,a,b,p,q,d;
vector<ll> v[2],x[2];

int main(){
  cin>>n>>m>>a>>b>>p>>q;
  ll ti=min(n,m/(p+q));
  ll ans=m;
  if(a==1&&b==1)
    ans=min(ans,min(m-ti*(p+q),
		    abs(min(ti+1,n)*(p+q)-m)));
  ll A=1,B=1,T=min((ll)N,n);
  for(int i=0;i<T;i++){
    d=p*A+q*B;
    i<T/2?v[0].P(d):v[1].P(d);
    if(d>m)break;
    A*=a,B*=b;
  }
  int len[2]={v[0].size(),v[1].size()};
  for(int i=0;i<2;i++){
    v[i].P(0);
    for(int j=0;j<(1<<len[i]);j++){
      ll sum=0;
      for(int k=0;k<len[i];k++)
	if((j&(1<<k)))sum+=v[i][k];
      x[i].P(sum);
    }
    sort(x[i].begin(),x[i].end());
  }
  for(int i=0;i<x[0].size();i++){
    ll S=m-x[0][i];
    vector<ll>::iterator r=lower_bound(x[1].begin(),x[1].end(),S);
    if(r!=x[1].end())ans=min(ans,(*r)-S);
    if(r!=x[1].begin())ans=min(ans,S-(*(r-1)));
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 27708
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#include <cmath>

using namespace std;

using i8 = int8_t;
using i16 = int16_t;
using i32 = int32_t;
using i64 = int64_t;
using u8 = uint8_t;
using u16 = uint16_t;
using u32 = uint32_t;
using u64 = uint64_t;


int main(int argc, char* argv[]) {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  
  i32 N, K;
  cin >> N >> K;
  
  i32 R, S, P;
  cin >> R >> S >> P;
  
  string T;
  cin >> T;
  
  auto win = [&](char t) -> pair<char, i32> {
    char ch = 'x';
    i32 ret = 0;
    switch(t) {
      case 'r':
        ret = P;
        ch = 'p';
        break;
      case 's':
        ret = R;
        ch = 'r';
        break;
      case 'p':
        ret = S;
        ch = 's';
        break;
    }
    return {ch, ret};
  };
  
  i32 total = 0;
  string ss_win(' ', N);
  
  // 最初のK
  for(i32 i = 0; i < K; ++i) {
    auto result = win(T[i]);
    total += result.second;
  }

  for(i32 i = K; i < N; ++i) {
    auto result = win(T[i]);
    if(T[i] == T[i-K]) {T[i] = 'x';}
    result = win(T[i]);
    total+=result.second;
  }
  
  cout << total << endl;
  return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#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 == "ABC")
        cout << "ARC" << endl;
    else
        cout << "ABC" << endl;
    return 0;
}


Measured memory_bytes: 3604
#pragma GCC optimize("Ofast", "unroll-loops")

#include <bits/stdc++.h>

using namespace std;

#define ll long long

const ll mod = 1000000007LL;

// aのb乗を求める.
ll modpow(ll a, ll b) {
	if (a > mod) a %= mod;
	if (b == 0LL) return 1LL;
	ll tmp = modpow(a, b / 2);
	if (b & 1LL)
		return tmp * tmp % mod * a % mod;
	return tmp * tmp % mod;
}

// aの逆元を求める.
ll inverse(ll a) {
	return modpow(a, mod - 2);
}

// kの階乗を計算する.(sgnを0以外に設定すると逆元を返す)
ll fact(ll k, int sgn = 0) {
	static vector<ll> fac(2, 1LL);
	static vector<ll> inv(2, 1LL);
	static vector<ll> finv(2, 1LL);
	static ll nx = 2LL;
	while (nx <= k) {
		fac.push_back(fac[nx - 1] * nx % mod);
		inv.push_back(mod - inv[mod % nx] * (mod / nx) % mod);
		finv.push_back(finv[nx - 1] * inv[nx] % mod);
		++nx;
	}
	if (sgn == 0)
		return fac[k];
	return finv[k];
}

ll inverse_sum(int k){
    static vector<ll> res(1, 1LL);
    static int nx = 2;
    while (nx <= k){
        ll lst = res[nx - 2];
        lst += inverse(nx);
        lst %= mod;
        res.push_back(lst);
        ++nx;
    }
    return res[k - 1];
}

int main(void){
    int N; cin >> N;
    vector<ll> x(N);
    for (int i = 0; i < N; ++i)
        cin >> x[i];
    ll res = 0;
    for (int i = 0; i < N - 1; ++i){
        ll d = x[i + 1] - x[i];
        res += d * inverse_sum(i + 1) % mod;
        res %= mod;
    }
    res *= fact(N - 1);
    res %= mod;
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 4852
# Union-Find部分
def find(x):
    global uf
    if uf[x]<0:
        return x
    else:
        uf[x] = find(uf[x])
        return uf[x]
    
def union(x, y):
    """
    Input: x, y
          x,y are vertex in tree.
    Return: bool
          False: not union. x,y are in same tree.
          True: do union. x,y are not in same tree.
    """
    global uf
    x, y = find(x), find(y)
    if x==y:
        return False
    else:
        if uf[x]<uf[y]:
            x, y = y, x
        uf[x] += uf[y]
        uf[y] = x
        return True
    
V, E = map(int, input().split())
edges = []
for _ in range(E):
    edges.append(tuple(map(int, input().split())))
    
uf = [-1]*V

# クラスカル法の部分
# Union-Findで閉路を作らないようにgreedyに辺を加えているだけ
mst = []
for e in sorted(edges, key=lambda x: x[2]):
    if find(e[0])!=find(e[1]):
        union(e[0], e[1])
        mst.append(e)
print(sum(map(lambda x: x[2], mst)))


Measured memory_bytes: 25060
n, m, l = list(map(int, input().split()))

A = []
for _ in range(n):
    row = list(map(int, input().split()))
    A.append(row)

B = []
for _ in range(m):
    row = list(map(int, input().split()))
    B.append(row)

for i in range(n):
    row = []
    for j in range(l):
        tmp = 0
        for k in range(m):
            tmp += A[i][k] * B[k][j]
        row.append(str(tmp))
    print("{}".format(' '.join(row)))



Measured memory_bytes: 6308
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<list>
#include<cstdint>
#include<bits/stdc++.h>
#include<queue>
#include<set>

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep_r(i, n) for(int i = n-1; i >= 0; i--)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i++)
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((ll)(x).size())
#define bit(n) (1LL<<(n))
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define INF bit(60)
#define pb push_back
#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; }

using namespace std;
using uif=uint_fast64_t;
using ll=long long int;

int qp(int a,ll b){int ans=1;do{if(b&1)ans=1ll*ans*a%mod;a=1ll*a*a%mod;}while(b>>=1);return ans;}
int qp(int a,ll b,int mo){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}

int gcd(int a,int b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};


#define FACSIZE 2002

ll invfac[FACSIZE];
ll fac[FACSIZE];

ll mod_pow(ll x,ll r){
  if(r==0) return 1;
  else if(r==1) return x%mod;
  else if(r%2==0){
    ll t=mod_pow(x,r/2)%mod;
    return t*t %mod;
  } 
  else{
    ll t=mod_pow(x,r/2)%mod;
    ll k= t*t %mod;
    return k*x%mod;
  } 
}
ll mod_add(ll a,ll b){
  return (a+b)%mod;
}

ll mod_mul(ll a,ll b){
  return (a*b)%mod;
}

ll div(ll a,ll b){
  return mod_mul(a,mod_pow(b,mod-2));
}

void make_fact(ll n){
  fac[0]=1;
  rep(i,n){
    fac[i+1]=mod_mul(fac[i],i+1);
  }  
}

void make_invfact(ll n){
  invfac[n]= mod_pow( fac[n] ,mod-2);
  for(int i=n-1;i>=0;i--){
    invfac[i]=mod_mul(invfac[i+1],i+1);
  }

}

ll mod_combi(ll n, ll m){
    ll tmp = mod_mul(fac[n],invfac[n-m]);
    return mod_mul(tmp,invfac[m]);
}

int main(void){

  ll l,r;
  cin>>l>>r;

  if(r-l > 2019){
    cout << 0 << endl;
  }
  else{
    ll ans=2020;
    for(ll i=l;i<=r;i++){
        for(ll j=i+1;j<=r;j++){
          ans=min(ans,(i*j)%2019 );
      } 
    }
    cout << ans << endl;
  }

  return 0;

}


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

int main(){
  int x,y;
  cin >> x >> y;
  int x1;
  if(y%2==1)
    cout << "No" << endl;
  else if((x*2 - y/2) >= 0 && x >= (x*2 - y/2))
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#include<iostream>
using namespace std;
 
int main() {
    string s,t;

    cin >> s >> t;

    sort(s.begin(),s.end());
    sort(t.begin(),t.end());
    reverse(t.begin(),t.end());
    if(s < t){
        cout << "Yes";
    }else{
        cout << "No";
    }
}
   


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

int main() {
  
  int A=0, B=0;
  
  cin >> A >> B;
  
  int sum = A+B;
  
  if(A%3==0 || B%3==0 || sum%3==0) {
    
    cout << "Possible" << endl;
    
  } else {
    
    cout << "Impossible" << endl;
    
  }
  
  return 0;
  
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cassert>

#include <utility>
#include <vector>
#include <limits>
#include <algorithm>
#include <map>
using namespace std;

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

constexpr int INF = numeric_limits<int>::max();

void Main()
{
	string S;
	map<char, bool> m;

	bool isYes = true;
	cin >> S;
	rep(i, S.size())
	{
		if (m.find(S[i]) != m.end())
		{
			isYes = false;
			break;
		}

		m[S[i]] = true;
	}

	cout << (isYes ? "yes" : "no") << endl;
}

int main()
{
	std::cin.tie(nullptr);
	std::ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);

	Main();
	return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Text;
using System.Numerics;
using System.IO;

namespace SolutionCS
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] v = new int[5];
            int m = 10;
            int ind = 0;
            for (int i = 0; i < 5; i++)
            {
                v[i] = int.Parse(Console.ReadLine());

                int a = v[i] % 10;
                if( a != 0 && m > a)
                {
                    m = a;
                    ind = i;
                }
            }
            int ans = 0;
            for (int i = 0; i < 5; i++)
            {
                if(ind == i)
                {
                    ans += v[i];
                }
                else
                {
                    ans += ((v[i] + 9) / 10) * 10;
                }
            }

            Console.WriteLine(ans);
        }
    }
}

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

using namespace std;
#define ll long long
#define f first
#define s second

int main() {
    //freopen("sample-8.in", "r", stdin);
    //freopen("output8.txt", "w", stdout);
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n,m;
    cin>>n>>m;
    int ar[n];
    priority_queue<int> pq;
    for(int i=0;i<n;i++){
        cin>>ar[i];
        pq.push(-ar[i]);
    }
    priority_queue<pair<int,int>> ppq;
    for(int i=0;i<m;i++){
        int a,b;
        cin>>a>>b;
        ppq.push({b,a});
    }
    while(!ppq.empty()){
        if(ppq.top().first<=(-pq.top())){
            break;
        }
        for(int i=0;i<ppq.top().second;i++){
            if(ppq.top().first<=(-pq.top())){
                break;
            }
            pq.pop();
            pq.push(-ppq.top().first);
        }
        if(ppq.top().first<=(-pq.top())){
            break;
        }
        ppq.pop();
    }
    ll sum=0;
    while(!pq.empty()){
        sum+=(-pq.top());
        pq.pop();
    }
    cout<<sum<<endl;
    return 0;
}

Measured memory_bytes: 2168