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

  struct Circle {
    double x, y, r;
    Circle (double xx, double yy, double rr) : x(xx), y(yy), r(rr) {}
  };

  vector<pair<double, double>> inter (Circle A, Circle B) {
  double d = hypot(B.x - A.x, B.y - A.y);
  if (d <= A.r + B.r + 1e-7 && d + 1e-7 >= abs(B.r - A.r)) {

      double ex = (B.x - A.x) / d;
      double ey = (B.y - A.y) / d;

      double x = (A.r * A.r - B.r * B.r + d * d) / (2 * d);
      double y = sqrt(A.r * A.r - x * x);
      vector<pair<double, double>> res;
      pair<double, double> P1 = {A.x + x * ex - y * ey, A.y + x * ey + y * ex};

      pair<double, double> P2 = {A.x + x * ex + y * ey, A.y + x * ey - y * ex};
      return {P1, P2};
  } else {
    return {{0, 0}};
  }
  }

  signed main() { 
    ios::sync_with_stdio(false); cin.tie(0);
    //f
    int n, k;
    cin >> n >> k;
    vector<vector<double>> in;
    for (int i = 0; i < n; i++) {
      double x, y, c;
      cin >> x >> y >> c;
      in.push_back({x, y, c});
    }
    if (k == 1) {
      cout << 0 << endl;
      return 0;
    }
    auto judge = [&] (double time) -> bool {
      vector<Circle> v;
      for (int i = 0; i < n; i++) {
        v.push_back(Circle(in[i][0], in[i][1], time / in[i][2]));
      }
      for (int i = 0; i < n; i++) for (int j = i + 1; j < n; j++) {
        auto res = inter(v[i], v[j]);
        for (auto& p : res) {
          int cnt = 0;
          for (int u = 0; u < n; u++) {
            if (hypot(v[u].x - p.first, v[u].y - p.second) * in[u][2] <= time + 1e-7) {
              cnt++;
            }
          }
          if (cnt >= k) return true;
        }
      }
      for (int i = 0; i < n; i++) {
        int cnt = 0;
        for (int j = 0; j < n; j++) {
          if (hypot(v[i].x - v[j].x, v[i].y - v[j].y) * in[j][2] <= time + 1e-7) {
            cnt++;
          }
        }
        if (cnt >= k) return true;
      }
      return false;
    };
    //cerr << judge(3) << endl;
    //return 0;
    double lo = 0, hi = 1e9;
    for (int i = 0; i < 200; i++) {
      double mid = (lo + hi) / 2;
      //cerr << mid << " " << judge(mid) << endl;
      if (judge(mid)) hi = mid;
      else lo = mid;
    }
    cout << setprecision(20) << fixed << hi << endl;
    return 0;
  }

Measured memory_bytes: 384
#include<stdio.h>

int main(void){
    int N;
    scanf("%d",&N);

    int p[N+1];

    int i;
    int count=0;
    for(i=1;i<=N;i++){
        scanf("%d",&p[i]);
        if(i!=p[i]){
            count++;
        }
    }

    if(count==0 || count==2){
        printf("YES");
    }else{
        printf("NO");
    }

    return 0;


}

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

int main()
{
	int m = 100000, n;
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		m = (int)(m*1.05);
		if (m % 1000 != 0)
			m += 1000;
		m /= 1000;
		m *= 1000;
	}
	cout << m << endl;

	return 0;
}

Measured memory_bytes: 2956
from __future__ import division
from collections import defaultdict

class UFSet:
	def __init__(self, n):
		self.fa = [i for i in range(n + 1)]

	def find(self, x):
		if self.fa[x] == x:
			return x
		else:
			self.fa[x] = self.find(self.fa[x])
			return self.fa[x]

	def union(self, x, y):
		fx = self.find(x)
		fy = self.find(y)
		if fx == fy:
			return fx
		else:
			self.fa[fx] = fy
			return fy


"""
graph is a hash
graph["nodes"] is a list of all nodes in the graph
graph["edges"] is a list of all edges in the graph in (x, y, w) form
  - x is the first nodes
  - y is the second nodes
  - w is the weight of the edges
graph["relation"] is the graph relation of the graph
"""

def kruscal(graph):
	"kruscal minimum spanning tree algorithm"
	n = len(graph["nodes"])
	ufset = UFSet(n)

	ret = 0

	for (x, y, w) in sorted(graph["edges"], key = lambda x: x[-1]):
		fx = ufset.find(x)
		fy = ufset.find(y)
		if fx != fy:
			ret += w
			ufset.union(fx, fy)
		else:
			pass
	return ret

if __name__ == '__main__':
	V, E = map(int, raw_input().strip().split())
	graph = {}
	graph["nodes"] = [i for i in range(V)]
	graph["edges"] = []
	graph["adj"] = defaultdict(list)
	for _ in range(E):
		x, y, w = map(int, raw_input().strip().split())
		graph["edges"].append((x, y, w))
		graph["adj"][x].append((y, w))
		graph["adj"][y].append((x, w))

	print kruscal(graph)

Measured memory_bytes: 46148
import decimal
class Imos_2:
    def __init__(self,W,H):
        self.width=W
        self.height=H
        self.list=[[0]*(W+1) for _ in range(H+1)]

    def Add(self,F,T,C=1):
        Fx,Fy=F
        Tx,Ty=T

        self.list[Fx][Fy]+=C
        self.list[Fx][Ty+1]-=C
        self.list[Tx+1][Fy]-=C
        self.list[Tx+1][Ty+1]+=C

    def Cumulative_Sum(self):
        Y=[[0]*(self.height+1) for _ in range(self.width+1)]

        for x in range(self.width+1):
            S=0
            for y in range(self.height+1):
                S+=self.list[x][y]
                Y[x][y]=S

        for y in range(self.height+1):
            S=0
            for x in range(self.width+1):
                S+=Y[x][y]
                Y[x][y]=S

        return Y
#================================================
def f(N):
    R=[]
    for k in [2,5]:
        X=N
        Y=0
        while X%k==0:
            X//=k
            Y+=1
        R.append(min(Y,2*Max_power))
    return R

N=int(input())
Max_power=9
A=[0]*N
I=Imos_2(2*Max_power+1,2*Max_power+1)
Power=[0]*N

for i in range(N):
    A[i]=int(decimal.Decimal(input())*(10**Max_power))

for i in range(N):
    (p,q)=f(A[i])
    Power[i]=(p,q)
    I.Add((2*Max_power-p,2*Max_power-q),(2*Max_power,2*Max_power))

J=I.Cumulative_Sum()

Ans=0
for i in range(N):
    p,q=Power[i]
    Y=J[p][q]

    if (p>=Max_power) and (q>=Max_power):
        Y-=1

    Ans+=Y

print(Ans//2)


Measured memory_bytes: 280236
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <cmath>
#include <string>
#include <bitset>
#include <functional>
#include <set>
#include <map>
#include <array>
#include <numeric>

using namespace std;
typedef long long int ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define fst first
#define snd second
#define pb push_back
#define ALL(obj) (obj).begin(), (obj).end()
#define debug(x) cout << #x << ": " << x << endl
#define int long long int
const int MOD = 1000000007;
const int INF = 1001001000;
const double EPS = 0.000000001;

int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

bool pairCompare(const P& pair1, const P& pair2) {
    return pair1.second > pair2.second;
}

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s;
  cin >> s;
  int n = (int)(s.length());
  int ans = 0;
  int acount = 0;
  int i = 0;
  while(i < n){
    if(s[i] == 'A' && s[i+1] == 'B' && s[i+2] == 'C') {
      acount++;
      ans += acount;
      s[i+2] = 'A';
      acount--;
      i = i+2;
    }
    else if(s[i] == 'A') {
      i++;
      acount++;
    }
    else {
      i++;
      acount = 0;
    }
  }
  cout << ans << endl;
  return 0;
}


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

#define dump(x) cout << (x) << '\n'
#define Int int64_t
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()

Int INF = 1e18;
int inf = 1e9;
Int mod = 1e9+7;

int main() {
    Int n, k;
    cin >> n >> k;
    vector<Int> a(n);
    for (Int i = 0; i < n; i++) {
        cin >> a[i];
    }
    sort(all(a));
    Int ok = -1e18;
    Int ng = 1e18;
    while (abs(ok - ng) > 1) {
        Int mid = (ok + ng) / 2;
        Int cnt = 0;
        for (Int i = 0; i < n; i++) {
            Int l = i;
            Int r = n;
            while (abs(l - r) > 1) {
                Int m = (l + r) / 2;
                if (a[i] >= 0) {
                    if (a[i] * a[m] <= mid) {
                        l = m;
                    }
                    else {
                        r = m;
                    }
                }
                else {
                    if (a[i] * a[m] <= mid) {
                        r = m;
                    }
                    else {
                        l = m;
                    }
                }
            }
            if (a[i] >= 0) {
                cnt += l - i;
            }
            else {
                cnt += n - r;
            }
        }
        //cout << mid << " " << cnt << endl;
        if (cnt < k) {
            ok = mid;
        }
        else {
            ng = mid;
        }
        // cout << ok << " " << ng << endl;
    }
    dump(ng);
    return 0;
}


Measured memory_bytes: 1792
N = gets.to_i
A = gets.split.map(&:to_i)
B = Hash.new(0)
total = 0
A.each do |a|
  B[a] += 1
  total += a
end
gets.to_i.times do
  x,y = gets.split.map(&:to_i)
  if B[x] != 0
    total = total - x * B[x] + y * B[x]
    B[y] += B[x]
    B[x] = 0
  end
  puts total
end


Measured memory_bytes: 25596
#include<bits/stdc++.h>
#define PB push_back
#define FO(i,a,b) for (int i = a; i <= b; i++)
#define FOb(i,a,b) for(int i=b;i>=a;i--)
#define vi vector<int>
#define vulli vector<unsigned long long int>
using namespace std;
typedef unsigned long long int ulli;
void solve()
{ 
 ulli n;
 cin >> n;
 map<string,int> mp;
 while(n--)
{
    string s;
    cin>>s;
    mp[s]++;
}    

    cout << "AC x " << mp["AC"] << endl;
    cout << "WA x " <<mp["WA"]  << endl;
    cout << "TLE x " << mp["TLE"] <<endl;
    cout << "RE x " << mp["RE"] <<endl;
 
}
int main()
{
    std::ios_base::sync_with_stdio(false);
    ulli t=1;
   // cin>>t;   
    while(t--){ solve(); cout<<"\n"; }
    return 0;
}

Measured memory_bytes: 3668
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

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

#[allow(unused_imports)]
use std::cmp::{min, max};

#[allow(unused_imports)]
use std::io::Write;

fn main() {
    input!{
      n: usize,
      aa: [i64; n],
      bs: [i64; n],
    }
    let asum: i64 = aa.iter().sum();
    let bsum: i64 = bs.iter().sum();
    if asum < bsum {
        return println!("{}", -1);
    }

    let mut need = 0;
    let mut ans = 0;
    for i in 0..n {
        if aa[i] < bs[i] {
            need += bs[i]-aa[i];
            ans += 1;
        }
    }

    if need == 0 {
        return println!("{}", 0);
    }

    let mut cs = vec![];
    for i in 0..n {
        cs.push(
            aa[i]-bs[i]
        )
    }
    cs.sort();
    cs.reverse();

    let mut sup = 0;

    for i in 0..n {
        sup += cs[i];
        ans += 1;
        if sup >= need {
            return println!("{}", ans);
        }
    }
    println!("{}", ans);
}


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

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define LCM(a, b) (a) / __gcd((a), (b)) * (b)
#define CEIL(a, b) (a)/(b)+(((a)%(b))?1:0)
#define ln '\n'

using namespace std;
using LL = long long;
using ldouble = long double;
using P = pair<int, int>;
using LP = pair<LL, LL>;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1e9 + 7;
static const int SIZE = 200005;

const int dx[] = {0, -1, 1, 0};
const int dy[] = {-1, 0, 0, 1};

vector<LL> Div(LL n) {
    vector<LL> ret;
    for(LL i = 1; i * i <= n; ++i) {
        if(n % i == 0) {
            ret.pb(i);
            if(i * i != n) ret.pb(n / i);
        }
    }
    sort(all(ret));
    return ret;
}

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

    string s;
    cin >> s;
    int K;
    cin >> K;

    LL dp[105][10][2] = {};
    if(s[0] == '1') {
        dp[0][0][0] = 1;
        dp[0][1][1] = 1;
    } else {
        dp[0][0][0] = dp[0][1][1] = 1;
        dp[0][1][0] = s[0] - '0' - 1;
    }

    for(int i = 1; i < s.size(); ++i) {
        int d = s[i] - '0';
        for(int j = 0; j <= K; ++j) {
            if(d == 0) {
                dp[i][j][1] += dp[i - 1][j][1];
            } else {
                dp[i][j][0] += dp[i - 1][j][1];
                if(j != 0){
                    dp[i][j][1] += dp[i - 1][j - 1][1];
                    dp[i][j][0] += dp[i - 1][j - 1][1] * (d - 1);
                }
            }
            dp[i][j][0] += dp[i - 1][j][0];
            if(j != 0) {
                dp[i][j][0] += dp[i - 1][j - 1][0] * 9;
            }
        }
    }
    cout << dp[s.size() - 1][K][0] + dp[s.size() - 1][K][1] << endl;

    return 0;
}


Measured memory_bytes: 256
#include<cstring>
#include<algorithm>
#include<cstdio>
#include<iostream>
using namespace std;
int main(){
	long long a,b,x;
	cin>>a>>b>>x;
	long long z=b/x-(a-1)/x;
	if (!a)cout<<b/x+1;
	else cout<<z;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 1000000000


int main(){

	int A,B,C,D,E,F;
	cin>>A>>B>>C>>D>>E>>F;
	
	vector<vector<bool>> dp(F+1,vector<bool>(F+1,false));
	dp[0][0] = true;
	
	for(int i=0;i<=F;i++){
		for(int j=0;j<=F;j++){
			if(!dp[i][j])continue;
			int a;
			a = i+100*A;
			if(a<=F)dp[a][j]=true;
			a = i+100*B;
			if(a<=F)dp[a][j]=true;
			a = j+C;
			if(a<=F)dp[i][a]=true;
			a = j+D;
			if(a<=F)dp[i][a]=true;
		}
	}
	int ans1 = 100*A;
	int ans2 = 0;
	for(int i=0;i<=F;i++){
		for(int j=0;j<=F;j++){
			if(!dp[i][j])continue;
			if(i+j>F)continue;
			if(E*(i/100)<j)continue;
			if(i==0&&j==0)continue;
			if(100*j*(ans1+ans2) > 100*ans2*(i+j)){
				ans1=i;
				ans2=j;
			}
		}
	}
	
	cout<<ans1+ans2<<' '<<ans2<<endl;
	
    return 0;
}



Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
	int n,sta = 1;
	cin >> n;
	int ans[33] = {};
	for (int i = 1; i <= 32; ++i)
	{
		ans[i] = abs(n % 2);
		sta = ((ans[i])?i:sta);
		if(i % 2 == 0 && n > 0)
		{
			++n;
		}
		else if(i % 2 == 1 && n < 0)
		{
			--n;
		}
		n /= 2;
	}
	for (int i = sta; i >= 1; --i)
	{
		cout << ans[i];
	}
	cout << endl;
	return 0;
}

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

ll n,m,q,ma=0;
vector<vector<int>> b(50, vector<int>(4));;

void f(vector<int> a,int i){
  a.push_back(i);
  if(a.size()==n){
    ll ans=0;
    rep(j,q){
      if((a[b[j][1]-1]-a[b[j][0]-1])==b[j][2]){
        ans+=b[j][3];
      }
    }
    ma=max(ma,ans);
    return;
  }
  for(int k=i;k<=m;k++){
    f(a,k);
  }
  return;
}

int main() {
  cin >>n>>m>>q;
  vector<int> a;
  rep(i,q){
    cin >>b[i][0]>>b[i][1]>>b[i][2]>> b[i][3];
  }
  for(int i=1;i<=m;i++){
    f(a,i);
  }
  cout <<ma<<endl;
}


Measured memory_bytes: 3632
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif

#include <bits/stdc++.h>

using namespace std;

#define mp make_pair
#define pb push_back
#define sz(s) ((int) ((s).size()))

#ifdef DEBUG
#define eprintf(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#else
#define eprintf(...) ;
#endif

#ifdef _WIN32
#define LLD "%I64d"
#else
#define LLD "%lld"
#endif

typedef long long ll;
typedef long double ld;

const int inf = (int) 1e9 + 100;
const ld eps = 1e-11;
const ld pi = acos(-1.0L);

mt19937 mrand(random_device{} ());
int rnd(int x) {
  return mrand() % x;
}

void precalc() {
}

const int maxn = 1e5 + 100;
int n;
ll a[maxn], b[maxn];

bool read() {
  if (scanf("%d", &n) < 1) {
    return false;
  }
  for (int i = 0; i < n; i++) {
    scanf("%lld %lld", a + i, b + i);
  }
  return true;
}

void solve() {
  ll cur = 0;
  for (int i = n - 1; i >= 0; i--) {
    ll val = cur + a[i];
    cur += (val + b[i] - 1) / b[i] * b[i] - val;
  }
  printf("%lld\n", cur);
}

int main() {
  precalc();
#ifdef DEBUG
  assert(freopen("text.in", "r", stdin));
  assert(freopen("text.out", "w", stdout));
#endif

  while (read()) {
    solve();
#ifdef DEBUG
    eprintf("Time: %.18f\n", (double) clock() / CLOCKS_PER_SEC);
#endif
  }
  return 0;
}


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

int main()
{
 int n,t;
  cin>>n>>t;
  map<int,int> mp;
  for(int i=0;i<n;i++)
  {
    int a,b;
    cin>>a>>b;
    mp[a]=b;
  }
  int ans=-1;
  for(auto i:mp)
  {
    if(i.second<=t)
    {
      if(ans==-1)
      {
        ans=i.first;
        continue;
      }
      if(ans>i.first)
        ans=i.first;
    }
  }
  if(ans==-1)
    cout<<"TLE\n";
  else
    cout<<ans<<"\n";
  return 0;
}


Measured memory_bytes: 256
import math

str=input()
n,k=int(str.split()[0]),int(str.split()[1])

def place(n,x):
    if n==1:
        return 1
    ans=1
    if n-1 < x:
        for i in range(x+1,n+x):
            ans*=i
        ans//=math.factorial(n-1)
    else:
        for i in range(n, n+x):
            ans*=i
        ans//=math.factorial(x)
    return ans%1000000007


for i in range (1,k+1):
    if n-k < i-1:
        print(0)
    else:
        cb=place(  i,  k-i  )
        cr=place(i+1,n-k-i+1)
        cr=cr%1000000007
        print(cb*cr%1000000007)


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


int main() {
    //ios_base::sync_with_stdio(false);
    //cout<<fixed<<setprecision(20);
    int n;
    cin>>n;
    ll a[200000];
    for(int i=0;i<n;i++) cin>>a[i];
    sort(a,a+n);
    if(n%2==0){
        ll ans=0;
        int k=n/2;
        for(int i=0;i<k;i++){
            ans+=abs(a[i]-a[k+i]);
        }
        for(int i=0;i<k-1;i++){
            ans+=abs(a[k+i+1]-a[i]);
        }
        cout<<ans;
    }
    else{
        ll ans=0;
        ll ans1=0;
        int k=n/2;
        for(int i=0;i<k;i++){
            ans+=abs(a[i]-a[k+1+i]);
        }
        ans+=abs(a[k]-a[k+1]);
        for(int i=0;i<k-1;i++){
            ans+=abs(a[k+i+2]-a[i]);
        }
        
        
        for(int i=0;i<k-1;i++){
            ans1+=abs(a[i]-a[k+2+i]);
        }
        ans1+=abs(a[k]-a[0]);
        ans1+=abs(a[k-1]-a[k+1]);
        for(int i=0;i<k-1;i++){
            ans1+=abs(a[k+i+2]-a[i+1]);
        }
        cout<<max(ans,ans1);
    }
    return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<string>
#include<vector>
#include<cmath>
#include<queue>
#include<deque>
#include<stack>
#include<set>
#include<map>
#define PI acos(-1.0)
#define LL long long
#define MAX 0x3fffffff
using namespace std;

int m[15][15];
int n, a[15];

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	for (int i = 1; i <= 3; i++) {
		for (int j = 1; j <= 3; j++) {
			cin >> m[i][j];
		}
	}
	cin >> n;
	for (int i = 0; i < n; i++)cin >> a[i];
	for (int i = 1; i <= 3; i++) {
		for (int j = 1; j <= 3; j++) {
			for (int k = 0; k < n; k++) {
				if (m[i][j] == a[k])m[i][j] = '_';
			}
		}
	}
	for (int i = 1; i <= 3; i++) {
		int f = 1;
		for (int j = 1; j <= 3; j++) {
			if (m[i][j] != '_')f = 0;
		}
		if (f) {
			cout << "Yes" << endl;
			return 0;
		}
	}
	for (int i = 1; i <= 3; i++) {
		int f = 1;
		for (int j = 1; j <= 3; j++) {
			if (m[j][i] != '_')f = 0;
		}
		if (f) {
			cout << "Yes" << endl;
			return 0;
		}
	}
	if (m[1][1] == '_'&&m[2][2] == '_'&&m[3][3] == '_') {
		cout << "Yes" << endl;
		return 0;
	}
	if (m[1][3] == '_'&&m[2][2] == '_'&&m[3][1] == '_') {
		cout << "Yes" << endl;
		return 0;
	}
	cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void solution(int [] arr1, int [] arr2) {
		long monster = 0;
		for(int i=0;i<arr2.length;i++) {
			if(arr1[i]>=arr2[i]) {
				monster+=arr2[i];
			}
			else {
				if(arr1[i]+arr1[i+1]>=arr2[i]) {
					monster+=arr2[i];
					arr1[i+1]-=arr2[i]-arr1[i];
				}
				else {
					monster+=arr1[i]+arr1[i+1];
					arr1[i+1]=0;
				}
			}
		}
		System.out.println(monster);
	}
	
	
	public static void main(String args []) {
		Scanner obj = new Scanner(System.in);
		int n = obj.nextInt();
		int a [] = new int [n+1];
		int b [] = new int [n];
		for(int i=0;i<a.length;i++) {
			a[i]= obj.nextInt();
		}
		for(int i=0;i<b.length;i++) {
			b[i]= obj.nextInt();
		}
		solution(a,b);
		
	}
}


Measured memory_bytes: 89892
package main

import (
	"fmt"
	"bufio"
	"os"
	"strconv"
	"sort"
	"container/heap"
)

var sc = bufio.NewScanner(os.Stdin)
func scanInt() int {
	sc.Scan()
	a,_ := strconv.Atoi(sc.Text())
	return a
}

func scanText() string {
	sc.Scan()
	return sc.Text()
}

type job struct {
	a int
	b int
}

type jobs []job

func (a jobs) Len() int           { return len(a) }
func (a jobs) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

func (a jobs) Less(i, j int) bool { return a[i].a < a[j].a }

type arr []int

func (a arr) Len() int           { return len(a) }
func (a arr) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
func (a arr) Less(i, j int) bool { return a[i] > a[j] }

func (a *arr) Push(x interface{}) {
	*a = append(*a, x.(int))
}

func (a *arr) Pop() interface{} {
	old := *a
	n := len(old)
	x := old[n-1]
	*a = old[0:n-1]

	return x
}

func main() {
	sc.Split(bufio.ScanWords)
	
	n,m := scanInt(),scanInt()
	j := make(jobs, n)
	for i := 0; i < n; i++ {
		j[i] = job{scanInt(),scanInt()}
	}

	sort.Sort(j)

	h := &arr{}
	heap.Init(h)

	ans := 0
	p := 0
	for i := 1; i < m+1; i++ {
		for p < n {
			if i < j[p].a {
				break
			}
			heap.Push(h,j[p].b)
			p++
		}

		if h.Len() != 0 {
			ans+=heap.Pop(h).(int)
		}
	}
	fmt.Println(ans)

}


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

int main(){
int dp[110][11000];

vector<int> v(110);
vector<int> w(110);

int N,W; cin >> N >> W;
for(int i=0;i<N;i++){
  cin >> v[i]    >> w[i];
}

for(int i=0;i<=W;i++)  dp[0][i] = 0;

for(int i=0;i<N;i++){
  for(int p=0;p<=W;p++){

    if( p < w[i] ) dp[i+1][p] = dp[i][p];
    else dp[i+1][p] = max(dp[i][p] , dp[i][p-w[i]] + v[i]);
  }
}

cout << dp[N][W] << endl;

}



Measured memory_bytes: 7444
import sys
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
def resolve():
    A, B = lr()
    for i in range(100000):
        if int(i*0.08) == A and int(i*0.1) == B:
            print(i)
            return
    print('-1')
resolve()

Measured memory_bytes: 3064
#!/usr/bin/env python3
import sys
from math import *
from itertools import *
from collections import *
from functools import *
try:
    from math import gcd
except Exception:
    from fractions import gcd


def solve(N: int, M: int, X: "List[int]"):
    X = sorted(X)
    d = sorted([e - b for b, e in zip(X, X[1:])], reverse=True)
    return X[-1] - X[0] - sum(d[:N-1])


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    X = [ int(next(tokens)) for _ in range(M) ]  # type: "List[int]"
    result = solve(N, M, X)
    print(result)

if __name__ == '__main__':
    main()


Measured memory_bytes: 18996
#include <stdio.h>

int main(void) {
	int N,M;
	int knum=0;
	static int kiroku[50010][3];
	int L;
	static int tanka[10000];
	int i;
	if(scanf("%d%d",&N,&M)!=2)return 1;
	for(;;) {
		if(scanf("%d%d%d",&kiroku[knum][0],&kiroku[knum][1],&kiroku[knum][2])!=3)return 1;
		if(kiroku[knum][0] == 0 && kiroku[knum][1] == 0 && kiroku[knum][2] == 0)break;
		kiroku[knum][0]--;
		kiroku[knum][1]--;
		knum++;
	}
	if(scanf("%d",&L)!=1)return 1;
	for(i=0;i<L;i++) {
		static int result[10000];
		int j;
		for(j=0;j<M;j++) {
			if(scanf("%d",&tanka[j])!=1)return 1;
		}
		for(j=0;j<N;j++)result[j]=0;
		for(j=0;j<knum;j++) {
			result[kiroku[j][0]]+=tanka[kiroku[j][1]]*kiroku[j][2];
		}
		for(j=0;j<N;j++) {
			printf("%d%c",result[j],j+1<N?' ':'\n');
		}
	}
	return 0;
}

Measured memory_bytes: 1264
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <numeric>
typedef long long Int;
#define rep(i,a,b) for(Int i=a;i<b;++i)
#define rrep(i,a,b) for(Int i=a;i>=b;--i)
using namespace std;

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

    Int N; cin >> N;
    vector<Int> A(N);
    rep(i, 0, N) { cin >> A[i]; A[i] *= 2; }

    Int x = 0;
    rep(i, 0, N) x = A[i] - x;
    x /= 2;

    Int now = x;
    rep(i, 0, N) {
        cout << now << " ";
        now = A[i] - now;
    }
    cout << endl;
}


Measured memory_bytes: 2176
#include<iostream>
using namespace std;
int main()
{
	int num,s=0,n,n2;
	cin>>n2;
	n=n2;
	while(n2!=0)
	{
		num=n2%10;
		s+=num;
		n2/=10;
	}
	if(n%s==0)
		cout<<"Yes"<<endl;
	else
		cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define ll long long int
#define F first
#define S second
const ll mod = 1e9 + 7;
const ll INF = 10000000000000;
#define pb push_back
#define deb(x) cout << '>' << #x << ':' << x << endl;
#define fastio ios_base::sync_with_stdio(0); cin.tie(0);
using namespace std;
int main()
{
    fastio;
    ll n=0,m=0;
    cin>>n>>m;
    ll ar[n+1]={0};
    bool f=true;
    map<ll,bool>seen;
    for(ll i=0;i<m;++i){
        ll pos,dig;
        cin>>pos>>dig;
        if(seen[pos] and dig!=ar[pos]) f=false;
        seen[pos]=true;
        ar[pos]=dig;
    }
    if(n>=2 and !seen[1] and ar[1]==0) ar[1]=1;
    if(n>=2 and ar[1]==0) f=false;
    if(f){
        for(ll i=1;i<=n;++i) cout<<ar[i];
    }
    else cout<<"-1";
}


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

#define MAX 800000

P dat[MAX];
int N;

void init(int n){
	N=1;while(N<n)N<<=1;
}
void update(int k,P x){
	k+=N-1;
	dat[k]=x;
	while(k){
		k=(k-1)/2;
		dat[k]=min(dat[k*2+1],dat[k*2+2]);
	}
}
P query(int a,int b,int k,int l,int r){
	if(b<=l||r<=a)return P(INT_MAX,INT_MAX);
	if(a<=l&&r<=b)return  dat[k];
	return min(query(a,b,k*2+1,l,(l+r)/2),query(a,b,k*2+2,(l+r)/2,r));
}

int bit[300000];
void add(int k,int x){
	k++;
	while(k<300000){
		bit[k]+=x;
		k+=k&-k;
	}
}
int sum(int k){
	k++;
	int ans=0;
	while(k){
		ans+=bit[k];
		k-=k&-k;
	}
	return ans;
}
int main(){
	string s;int k;cin>>s>>k;
	rep(i,s.size()-1)add(i+1,1);
	init(s.size());
	rep(i,s.size())update(i,P(s[i],i));
	string ans;
	rep(i,s.size()){
		int l=1,r=s.size();
		while(l!=r){
			int t=(l+r)/2;
			if(r-l==1)t=r;
			if(sum(t-1)<=k)l=t;
			else r=t-1;
		}
		P p=query(0,l,0,0,N);
		ans+=p.first;
		k-=sum(p.second);
		add(p.second+1,-1);
		update(p.second,P(INT_MAX,i));
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 7384
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<ll>;
using vvi= vector<vi>;
using vs = vector<string>;
using pl = pair<ll,ll>;
#define ci(n,a)   ll a[n]; rep(i,(n)) cin>>a[i];
#define rep(i,n)  for(ll i = 0; i < (n); ++i)
#define red(i,n)  for(ll i = (n)-1; i >= 0; --i)
#define all(a)    begin(a),end(a)
#define pb(a)     push_back(a)
#define mp(a,b)   make_pair(a,b)
#define yn(a)     cout << ( (a)?"Yes\n":"No\n" )
inline ll gcd(ll a,ll b) { return b?gcd(b,a%b):a; }
ll INF = 1e9+9, LINF = 1e18;

int main(int argc,char* argv[]) 
{
    ll n;
    cin>>n;
    string s,c="01";
    if(n==0) s="0";
    else for(ll i=1;n!=0;i*=-2){
        s=c[(abs(n)%abs(i*2))/abs(i)]+s;
        if(abs(n)%abs(i*2)/abs(i)) n-=i;
    }
    cout<<s<<endl;
    return 0;
}



Measured memory_bytes: 256
#pragma region RegionDefs
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#include "boost/multi_array.hpp"
#define rep(i,n) for(int i=0,i##_len=(n);i<i##_len;++i)
#define reps(i,j,n) for(int i=(j),i##_len=(n);i<i##_len;++i)
#define repr(i,n) for(int i=(n);i>=0;--i)
#define all(x) begin(x),end(x)
using namespace std;
template<class T=int> using P  = pair<T, T>;
template<class T=int> using V  = vector<T>;
template<class T=int> using PQ = priority_queue<T>;
template<class T=int> using PQG = priority_queue<T, V<T>, greater<T>>;
typedef long long ll;
const int INF = 1e9;
const ll MOD = 1000000007LL;
void in() {}
template<class Head, class... Tail>
void in(Head&& head, Tail&&... tail)
{
    cin >> head;
    in(move(tail)...);
}
#define IN(...) ll __VA_ARGS__; in(__VA_ARGS__)
//時間が厳しいとき使う
#define INI(...) int __VA_ARGS__; in(__VA_ARGS__)
#define INS(T, ...) T __VA_ARGS__; in(__VA_ARGS__)
#define VIN(T, v, n) V<T> v(n); for(auto& _elem:v)cin>>_elem
template<class T>bool chmax(T &a, const T &b) {if (a<b) {a=b; return 1;} return 0;}
template<class T>bool chmin(T &a, const T &b) {if (a>b) {a=b; return 1;} return 0;}
#define y0 y__0
#define y1 y__1
#define j0 j__0
#define j1 j__1
#pragma endregion RegionDefs

void solve()
{
    IN(x);
    int i = (int)(x/1.08);
    rep(j, 100)
    {
        if ((int)((i+j)*1.08) == x)
        {
            cout << (i+j) << endl;
            return;
        }
    }
    cout << ":(" << endl;
}

int main()
{
    cin.tie(0); cout.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(numeric_limits<double>::max_digits10);

    solve();

    return 0;
}

Measured memory_bytes: 256
n, a, b, c = map(int, input().split())
l = [int(input()) for _ in range(n)]

from itertools import product
ptns = list(product([0,1,2,-1], repeat = n))

anss = []
for i in range(len(ptns)):
    if 0 not in ptns[i] or 1 not in ptns[i] or 2 not in ptns[i]:
        continue
    abc = [0, 0, 0, -30]
    ans = 10**9
    for j in range(n):
        tmp = ptns[i][j]
        if tmp >= 0:
            abc[tmp] += l[j]
            abc[3] += 10

    anss.append(abc[3] + abs(abc[0] - a) + abs(abc[1] - b) + abs(abc[2] - c))

print(min(anss))

Measured memory_bytes: 12912
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(void)
{
  int N, s = 0;
  cin >> N;
  int A[N];
  for(int i = 0;i<N;i++) cin>>A[i];
  for(int i = 0;i<N;i++)
  {
      for(int j = i+1;j<N;j++)
      {
          s += A[i] * A[j];
      }
  }
  cout << s << endl;
  return 0;
}



Measured memory_bytes: 256
n = int(input())
f = []
for i in range(n):
    f.append(list(map(int,input().split())))
p = []
for i in range(n):
    p.append(list(map(int,input().split())))

ans = -(int(1e9) + 7)
#print(ans)
for i in range(2 ** 10):
    d = [False] * 10
    for j in range(10):
        if i >> j & 1:
            d[j] = True
    if not True in d:
        continue

    val = 0
    for j in range(n):
        cnt = 0
        for k in range(10):
            if d[k] == True and f[j][k] == 1:
                cnt += 1
        val += p[j][cnt]
        #print(ans)
    ans = max(ans,val)
print(ans)


Measured memory_bytes: 3064
#!/usr/bin/env python3

N = int(input().split()[0])
r_list = []
b_list = []

for _ in range(N):
    a, b = list(map(int, input().split()))
    r_list.append((a, b))

blue_dict = {}

for _ in range(N):
    c, d = list(map(int, input().split()))
    b_list.append((c, d))
    blue_dict[(c, d)] = []
    for ab in r_list:
        a, b = ab
        if a < c and b < d:
            blue_dict[(c, d)] += [(a, b)]

b_list = sorted(b_list, key=lambda x: x[1])
pair_list = []

for b in b_list:
    # xが小さいものから見ていく
    kouho_r_list = blue_dict[b]
    if kouho_r_list:
        kouho_r_list = sorted(kouho_r_list, key=lambda x: x[0], reverse=True)
        r = kouho_r_list[0]
        pair_list.append((r, a))

        for k, v in blue_dict.items():
            if r in v:
                v.remove(r)

ans = len(pair_list)
print(ans)


Measured memory_bytes: 3188
import java.io.*;

import java.util.*;

public class Main {
    private static int[] heights;
    private static int n, ans = Integer.MAX_VALUE,k;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
      	k = sc.nextInt();
        heights = new int[n + 3];
        dp = new int[n + 3];
        for (int i = 1; i <= n; i++) {
            heights[i] = sc.nextInt();
        }
        Arrays.fill(dp, -1);
        System.out.println(findJumpCost(1));
        sc.close();
    }

    private static int[] dp;

    private static int findJumpCost(int ind) {
        if (ind == n)
            return 0;

        if (dp[ind] != -1) {
            return dp[ind];
        }
        int min = Integer.MAX_VALUE;
        for (int i = ind + 1; i <= Math.min(n, ind + k); i++) {
            min = Math.min(min, Math.abs(heights[i] - heights[ind]) + findJumpCost(i));
            // System.out.println(min);
        }
        return dp[ind] = min;
    }
}

Measured memory_bytes: 71160
import numpy as np

n = int(input())
A, B = [], []  # AにはXがとりうる値の最小値、Bには最大値を入れていく

for _ in range(n):
    a, b = map(int, input().split())
    A.append(a if n % 2 == 1 else a * 2)  # nが偶数だと、medianがとりうる値が0.5刻みになるので最初から2倍にしておく
    B.append(b if n % 2 == 1 else b * 2)

a = np.median(A)
b = np.median(B)

# medianのとりうる値の最小値と最大値の間に、カウントしたいmedianが１刻みで存在する
print(int(max(a, b) - min(a, b) + 1))

Measured memory_bytes: 45872
#include <iostream>
#include <list>
#include <vector>
#include <map>
#include <string>
#include <algorithm>

using namespace std;

int main(){
	string strInput;
	map< string,vector<int> > index;
	int intInput = 0;
	while(cin >> strInput >> intInput){
		index[strInput].push_back(intInput);
	}
	
	for(map< string,vector<int> >::iterator it = index.begin(); it != index.end() ; it++){
		sort( index[(*it).first].begin(),index[(*it).first].end() );
		cout << (*it).first << endl;
		for(int i = 0; i < index[(*it).first].size(); i++){
			if(i == index[(*it).first].size() - 1){
				cout <<  index[(*it).first][i];
				break;
			}
			cout <<  index[(*it).first][i] << ' ';
		}
		cout << endl;
	}

	return 0;
}

Measured memory_bytes: 1244
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll MOD = 1e9 + 7;
const ll INF = LLONG_MAX;
const ll MINF = LLONG_MIN;
const int INT_INF = INT_MAX;
using Tree = vector<pair<int, int>>;

int main()
{
    int a;
    string s;
    cin >> a >> s;
    if (a < 3200)
    {
        cout << "red" << endl;
    }
    else
        cout << s << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <string>
#include <map>
#include <queue>
using namespace std;
#define N 3
#define N2 9

struct Puzzle
{
  int f[N2];
  int space;
  string path;

  bool operator < (const Puzzle &p)const{
    for(int i=0;i<N2;i++){
      if(f[i]==p.f[i])continue;
      return f[i]>p.f[i];
    }
    return false;
  }
};

static const int dx[4]={-1,0,1,0};
static const int dy[4]={0,-1,0,1};
static const char dir[4]={'u','l','d','r'};

bool isTarget(Puzzle p){
  for(int i=0;i<N2;i++)
    if(p.f[i]!=(i+1))return false;
    return true;
}

string bfs(Puzzle s)
{
  queue<Puzzle>Q;
  map<Puzzle,bool>V;
  Puzzle u,v;
  s.path="";
  Q.push(s);
  V[s]=true;

  while(!Q.empty())
  {
    u=Q.front();Q.pop();
    if(isTarget(u))return u.path;
    int sx = u.space/N;
    int sy = u.space%N;
    for(int r=0;r<4;r++)
    {
      int tx = sx + dx[r];
      int ty = sy + dy[r];
      if(tx < 0 || ty < 0 || tx >= N || ty >= N)continue;
      v=u;
      swap(v.f[u.space],v.f[tx*N+ty]);
      v.space=tx * N + ty;
      if(!V[v])
      {
        V[v]=true;
        v.path+=dir[r];
        Q.push(v);
      }
    }
  }
  return "unsolvable";
}

int main()
{
  Puzzle in;

  for(int i=0;i<N2;i++)
  {
    cin >> in.f[i];
    if(in.f[i]==0)
    {
      in.f[i]=N2;
      in.space=i;
    }
  }
  string ans = bfs(in);
  cout << ans.size() << endl;

  return 0;
}



Measured memory_bytes: 30480
#include <iostream>
#include <fstream>
#include <iomanip>

#include <vector>
#include <set>
#include <bitset>
#include <map>
#include <deque>
#include <string>

#include <algorithm>
#include <numeric>
#include <random>

#include <cstdio>
#include <cassert>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>

using namespace std;

#define forn(i, n) for (ll i = 0; i < (ll) (n); ++i)
#define sz(a) static_cast<int>((a).size())
#define endl '\n'

using ll = long long;

const ll INF = static_cast<ll>(1e9) + 7;
const int MAXN = static_cast<int>(1e6) + 17;

int n;
string s[MAXN], t[MAXN];

bool read() {
    if (!(cin >> n))
        return false;

    forn (i, n)
        cin >> s[i];

    return true;
}

void solve() {
    int ans = 0;

    forn (i, n)
        t[i] = s[i];

    for (int a = 0; a < n; ++a) {
        forn (i, n)
            forn (j, n)
                t[i][(j + a) % n] = s[i][j];

        bool good = true;

        forn (i, n)
            forn (j, n)
                good &= (t[i][j] == t[j][i]);

        if (good)
            ++ans;
    }

    cout << ans * n << endl;
}

int main() {
    cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::mt19937 rand('S' + 'E' + 'R' + 'E' + 'Z' + 'H' + 'K' + 'A');

#ifdef SEREZHKA
    freopen("file.in", "r", stdin);
#endif

    while (read())
        solve();

    return 0;
}



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

using namespace std;
using ll = long long;
using ld = long double;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define reps(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
const ll mod = 1e9 + 7;
const ll INF = 10000000000;

int main() {
	int N;
	cin >> N;
	map<int, int>mp;
	vector<int>A(N);
	rep(i, N) {
		cin >> A[i];
		mp[A[i]]++;
	}
	int ans = 0;
	set<int>st;
	rep(i, N) {
		if (!st.count(A[i]))ans += mp[A[i]] % 2;
		st.insert(A[i]);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 9984
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin>>s;
  if(s.at(0)==s.at(1)||s.at(1)==s.at(2)||s.at(2)==s.at(3)){
    cout<<"Bad"<<endl;
    return 0;
  }
  else{
    cout<<"Good"<<endl;
    return 0;
  }
}

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


int ar[10];

int main()
{
    int a , b;


    cin >> a >> b;

    ar[a]++;
    ar[b]++;

    for(int i=1; i<=3; i++)
    {
        if(ar[i]==0)
        {
            cout << i << endl;
            return 0;
        }
    }

}


Measured memory_bytes: 256
def judge(data):
    num = list(map(int,data.split()))
    a,b = 0,0
    for i in range(10):
        if a <= num[i]:
            a = num[i]
        elif b <= num[i]:
            b = num[i]
        else:
            print('NO')
            return 0
    print('YES')
    return 0
            
n = int(input())
array = [0]*n
for i in range(n):
    array[i] = input()

for i in range(n):
    judge(array[i])

Measured memory_bytes: 7680
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<time.h>
#include<random>

using namespace std;

#define REP(i, n) for(int i = 0;i < n;++i)
#define REPR(i, n) for(int i = n-1;i >= 0;--i)
#define FOR(i, m, n) for(int i = m;i < n;++i)
#define FORR(i, m, n) for(int i = m-1;i >= n;--i)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end())
#define ll long long
#define pb(a) push_back
#define print(x) cout<<(x)<<endl
#define pe(x) cout<<(x)<<" "
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define lb(v,n) lower_bound(v.begin(), v.end(), n)
#define ub(v,n) upper_bound(v.begin(), v.end(), n)
#define int long long
#define all(x) (x).begin(), (x).end()
#define print_space(v) REP(i,v.size())cout << v[i] << ((i == v.size() - 1) ? "\n" : " ")
template<typename T1, typename T2> inline void chmin(T1 & a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
typedef pair<int, int>P;
const int MOD = 1e9+7; const int MAX = 200020;
const double pi = acos(-1); const double EPS = 1e-12;
const ll INF = 2e18;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 二項係数計算
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
ll add(ll x, ll y) {
	x += y;
	if (x >= MOD) return x - MOD;
	return x;
}
ll sub(ll x, ll y) {
	x -= y;
	if (x < 0) return x + MOD;
	return x;
}

ll mult(ll x, ll y) {
	return (x * y) % MOD;
}
ll bin_pow(ll x, ll p) {
	if (p == 0) return 1;
	if (p & 1) return mult(x, bin_pow(x, p - 1));
	return bin_pow(mult(x, x), p / 2);
}

int N;
int X[100010];
int cum[100010];
void solve() {
	cin >> N;
	REP(i, N)cin >> X[i];
	FOR(i, 1, N + 1) {
		cum[i] += cum[i - 1] + bin_pow(i, MOD - 2);
	}
	ll ans = 0;
	REP(i, N - 1) {
		ans += mult(cum[i + 1], X[i + 1] - X[i]);
		ans %= MOD;
	}
	COMinit();
	ans = mult(ans, fac[N - 1]);
	print(ans);
}

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	//int q;cin>>q;
	//while(q--)
	solve();
}




Measured memory_bytes: 6528
#include<bits/stdc++.h>
using namespace std;
#define llt long long int
char c[4]={'E','W','N','S'};

int main(){
	llt t=0,n;
	//string s;
	//cin>>t;
	//vector<pair<int,bool>> v;
	//int n;
	cin>>n;
	for(int i=1;i<=n;i++){
		if(i%3!=0&&i%5!=0)
		t+=i;
	}
	cout<<t<<endl;

}


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

int main() {
    long long n; // nの範囲が分からないからlongなのかな？
    scanf("%lld", &n);

    const int MAX = 3500;
    for (long long x = 1; x <= MAX; x++) {
        for (long long y = 1; y <= x; y++) {
            long long z1 = n * x * y;
            long long z2 = 4 * x * y - n * y - n * x;

            if (z2 > 0 && z1 % z2 == 0) {
                printf("%lld %lld %lld\n", x, y, z1/z2);
                return 0;
            }

        }
    }

    return 0;
}

Measured memory_bytes: 256
n, x = map(int, input().split())
a = list(map(int, input().split()))
ans = 0
if n==2:
    print(max(0, sum(a)-x))
    exit()
for i in range(n-1):
    s = a[i] + a[i+1]
    if s <= x:
        continue
    else:
        d = s-x
        ans += d
        if a[i+1] >= 1:
            if a[i+1] >= d:
                a[i+1] -= d
            else:
                a[i+1] = 0
                a[i] -= d-a[i+1]
        else:
            a[i] -= d
print(ans)



Measured memory_bytes: 14400
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define loop(i,a,b) for(int i=a;i<b;i++)
#define test() int t;cin>>t;loop(test,1,t+1)
#define pb push_back
#define eb emplace_back
#define mkp make_pair
#define nl cout<<"\n"
#define sp cout<<" "
#define F first
#define S second
#define vi vector<int>
#define vl vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<pii>
#define vll vector<pll>
#define MOD 1000000007
#define all(x) x.begin(),x.end()

template<class C> void min_self( C &a, C b ){ a = min(a,b); }
template<class C> void max_self( C &a, C b ){ a = max(a,b); }

ll mod( ll n, ll m=MOD ){ n%=m,n+=m,n%=m;return n; }

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }
    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

unordered_map<long long, int, custom_hash> safe_map;

const int MAXN = 1e5+5;
const int LOGN = 21;
const ll INF = 1e14;
int dx[] = {1,0,-1,0};
int dy[] = {0,1,0,-1};

int main() 
{
    fastio();

    ll a,b;
    cin>>a>>b;
    ll ans = a/__gcd(a,b);
    ans *= b;
    cout<<ans;

    cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>

using namespace std;

int a,b,c;
int p,q;

int main(){
	cin >> a >> b >> c;
	p = a - b;
	if(p<0)p = -p;
	q = a-c;
	if(q<0)q = -q;
	if(p<q) cout << 'A' << endl;
	else cout << 'B' << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<map>
#include<string.h>
using namespace std;

int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};

int main()
{
	map<char,pair<int,int> > M;
	M['A']=make_pair(0,0);
	M['B']=make_pair(1,0);
	M['C']=make_pair(2,0);
	M['D']=make_pair(0,1);
	M['E']=make_pair(1,1);
	M['F']=make_pair(2,1);
	M['G']=make_pair(0,2);
	M['H']=make_pair(1,2);
	M['I']=make_pair(2,2);

	int n;
	while(cin>>n &&n!=0){
		char s,t,b;
		cin>>s>>t>>b;
		pair<int,int> now=M[s];
		pair<int,int> goal=M[t];
		pair<int,int> nota=M[b];

		double ans[17][3][3];

		for(int i=0;i<16;i++)
			for(int x=0;x<3;x++)
				for(int y=0;y<3;y++)
					ans[i][y][x]=0.0;

//		cout<<now.first<<" "<<now.second<<endl;
		ans[0][now.second][now.first]=1.0;

		for(int i=0;i<n;i++){
			for(int x=0;x<3;x++){
				for(int y=0;y<3;y++){
					for(int r=0;r<4;r++){
						int nx=x+dx[r],ny=y+dy[r];
						if(nx<0 || nx>=3 || ny<0 || ny>=3 || make_pair(nx,ny)==nota){
							ans[i+1][y][x]+=ans[i][y][x]/4.0;
						}
						else{
							ans[i+1][ny][nx]+=ans[i][y][x]/4.0;
						}
					}
				}
			}
		}
		cout<<ans[n][goal.second][goal.first]<<endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include<stdio.h>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<utility>
#include<memory>
#include<cmath>
#include<stack>
#include<tuple>
#include<numeric>
#include<cassert>

#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define pb push_back
#define DEBUG false

using namespace std;

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

const int mod=1e9+7,INF=1<<30;
const double EPS=1e-12,PI=3.1415926535897932384626;
const ll LINF=1LL<<60;
const int MAX_N = 100005;
const ll lmod = 1e9+7;
const int alphabet = 26;

int main(){
  string S;
  cin >> S ;
  int cnt,l,r;
  l = cnt = 0;
  r = S.size()-1;
  bool possible = true;
  while(l<r){
    if(S[l]==S[r]){
      l++; r--;
    }else if(S[l]=='x'){
      cnt++; l++; 
    }else if(S[r]=='x'){
      cnt++; r--;
    }else{
      possible = false;
      break;
    }
  }
  if(possible) cout << cnt << endl;
  else cout << -1 << endl;
  return 0;
}


Measured memory_bytes: 512
#include	<stdio.h>
#include   <string.h>
int	main(void)
{
	int front = 0,back;//頭、最後
	char str1[256],str2[256],str3[256];
	scanf("%s %s %s",&str1,&str2,&str3);


	back = strlen(str1);
	if(str2[front] == str1[back-1]){
		back = strlen(str2);
		if(str3[front] == str2[back-1]){
				printf("YES");
			}else{
				printf("NO");
			}
	}else{
		printf("NO");
	}
	return	0;
}


Measured memory_bytes: 128