akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Math;
using static System.Console;
using static exMath;
using static exReadLine;


class Program
{
    static void Main(string[] args)
    {
        int H, A;
        intReadLine(out H, out A);
        if(H % A == 0)
        {
            WriteLine(H / A);
        }
        else
        {
            WriteLine(1 + (H / A));
        }
    }
}

static class exReadLine
{
    public static void intReadLine(out int a)
    {
        a = int.Parse(ReadLine());
    }
    public static void intReadLine(out int a, out int b)
    {
        int[] input = ReadLine().Split().Select(int.Parse).ToArray();
        a = input[0];
        b = input[1];
    }
    public static void intReadLine(out int a, out int b, out int c)
    {
        int[] input = ReadLine().Split().Select(int.Parse).ToArray();
        a = input[0];
        b = input[1];
        c = input[2];
    }
    public static void intReadLine(out int a, out int b, out int c, out int d)
    {
        int[] input = ReadLine().Split().Select(int.Parse).ToArray();
        a = input[0];
        b = input[1];
        c = input[2];
        d = input[3];
    }

    public static void longReadLine(out long a)
    {
        a = long.Parse(ReadLine());
    }
    public static void longReadLine(out long a, out long b)
    {
        long[] input = ReadLine().Split().Select(long.Parse).ToArray();
        a = input[0];
        b = input[1];
    }
    public static void longReadLine(out long a, out long b, out long c)
    {
        long[] input = ReadLine().Split().Select(long.Parse).ToArray();
        a = input[0];
        b = input[1];
        c = input[2];
    }
    public static void longReadLine(out long a, out long b, out long c, out long d)
    {
        long[] input = ReadLine().Split().Select(long.Parse).ToArray();
        a = input[0];
        b = input[1];
        c = input[2];
        d = input[3];
    }
}

static class exMath
{
    // 最大公約数
    public static int Gcd(int a, int b)
    {
        if (a < b) return Gcd(b, a);
        while (b != 0)
        {
            var r = a % b;
            a = b;
            b = r;
        }
        return a;
    }
    public static long Gcd(long a, long b)
    {
        if (a < b) return Gcd(b, a);
        while (b != 0)
        {
            var r = a % b;
            a = b;
            b = r;
        }
        return a;
    }

    // 最小公倍数
    public static long Lcm(int a, int b)
    {
        return BigMul(a, b) / Gcd(a, b);
    }
    public static long Lcm(long a, long b)
    {
        return a * b / Gcd(a, b);
    }
}

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

int main(){
    int n, cnt = 0;
    int a[100];
    cin >> n;
    for(int i=0; i<n; i++){
        cin >> a[i];
    }
    for(int i = 0; i < n-1; i++){
        for(int j = 0; j<n-1; j++){
            if(a[j] > a[j+1]){
                int tmp;
                tmp = a[j];
                a[j] = a[j+1];
                a[j+1] = tmp;
                cnt++;
            } 
        }
    }
    for(int i=0;i<n;i++){
        if(i > 0) cout << " ";
        cout << a[i];

    }cout << endl;

    cout << cnt << endl;
    return 0;

}



Measured memory_bytes: 3088
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
#define MOD 1000000007
using namespace std;
typedef long long ll;

template <typename Tp> inline void getint(Tp &num){
	register int ch, neg = 0;
	while(!isdigit(ch = getchar())) if(ch == '-') neg = 1;
	num = ch & 15;
	while(isdigit(ch = getchar())) num = num * 10 + (ch & 15);
	if(neg) num = -num;
}

inline int kazu(int a, const int &b) {return (a += b) >= MOD ? a - MOD : a;}
inline int hiku(int a, const int &b) {return (a -= b) < 0 ? a + MOD : a;}

inline ll fastpow(ll bas, ll ex){
	register ll res = 1; bas %= MOD;
	for(; ex; ex >>= 1, bas = bas * bas % MOD) if(ex & 1) res = res * bas % MOD;
	return res;
}

int N, M, L, R;
ll fac[600005] = {1}, ifac[600005];

inline void initfac(const int &lim){
	for(register int i = 1; i <= lim; i++) fac[i] = fac[i - 1] * i % MOD;
	ifac[lim] = fastpow(fac[lim], MOD - 2);
	for(register int i = lim; i >= 1; i--) ifac[i - 1] = ifac[i] * i % MOD;
}

inline ll C(const int &n, const int &m) {return fac[n] * ifac[m] % MOD * ifac[n - m] % MOD;}

inline int calc2(int S, const int &l, const int &r){
	if(S < M * (ll)r) return 0; int res = 0; S -= M * r;
	for(register int i = 0, sgn = 1; i <= N - M && S >= 0; i++, sgn = sgn * (MOD - 1LL) % MOD, S -= l)
		res = kazu(res, sgn * C(S + N, N) % MOD * C(N - M, i) % MOD);
	return res * C(N, M) % MOD;
}
/*	∑A[i] + B = S, A[1 .. M] >= r, 0 <= A[M + 1 .. N] < l
==>	∑A[i] + B = S - M * r, A[1 .. M] >= 0, 0 <= A[M + 1 .. N] < l */

inline int calc(const int &S){
	int res = C(S + N, N);
	for(register int i = S; i > 0; i--) res = hiku(res, hiku(calc2(S, i, i), calc2(S, i, i + 1)));
	return res;
}
/*	∑A[i] <= S
==>	∑A[i] + B = S */

int main(){
	getint(N), getint(M), getint(L), getint(R), initfac(R + N);
	return printf("%d\n", hiku(calc(R), calc(L - 1))), 0;
}

Measured memory_bytes: 9600
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>

#define ll long long
#define ull unsigned long long

using namespace std;

void Zalgorithm(string s, vector <int>& Z, int i, int j) {
	while (i < s.size()) {
		while ((i + j < s.size()) && (s[j] == s[i+j]) ) { ++j; }
		Z[i] = j;
		if (j == 0){ ++i; continue; }
		int k = 1;
		while ((i + k < s.size()) && (k + Z[k] < j) ) { Z[i+k] = Z[k]; ++k; }
		i += k; j -= k;
	}
}

int main() {
	int N;
	cin >> N;
	string S;
	cin >> S;

	int ans = 0;
	for (int ii = 0; ii < N-1; ++ii){
		int size = N - ii;
		vector <int> Z(size);
		Z[0] = size;
		string sub = S.substr(ii);
		Zalgorithm(sub, Z, 1, 0);

		int val = 0;
		for (int jj = 0; jj < size; ++jj){
			int tmp = min(jj, Z[jj]);
			val = max(val, tmp);
		}
		ans = max(ans, val);
	}

	cout << ans << "\n";

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define all(vec) vec.begin(), vec.end()
#define END return 0
typedef int64_t ll;
const int mod7 = 1e9 + 7;
const int mod9 = 1e9 + 9;
const int inf = 1 << 30;
const ll INF = 1LL << 60;
template<typename T> T gcd(T a, T b) {return b ? gcd(b, a % b) : abs(a);}
template<typename T> T lcm(T a, T b) {return a / gcd(a, b) * b;}
template<typename T> bool chmax(T &a, T b) {if (a < b) {a = b; return true;} return false;}
template<typename T> bool chmin(T &a, T b) {if (a > b) {a = b; return true;} return false;}
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val) {fill((T*)array, (T*)(array+N), val);}

int main() {
    int h, n;
    cin >> h >> n;
    int sum = 0;
    rep(i, n) {
        int a;
        cin >> a;
        sum += a;
    }
    if(sum >= h) cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

int main(){
    int N,A;
    cin >> N >> A;
    int amari = N % 500;
    if(amari <= A){
      printf("Yes\n");
    }
    else{
      printf("No\n");
    }
    return 0;
  }


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

using namespace std;


int main(void){

  long long int ans=0,n,a,b;
  cin>>n;
  for(int i=1;i<=n;i++)
      ans+=(i*(n-i+1));

  for(int i=1;i<=n-1;i++)
  {
     cin>>a>>b;
     if(a>b)swap(a,b);
     ans-=(a*(n-b+1));
  }
  cout<<ans<<"\n";
  return 0;
}


Measured memory_bytes: 3588
#include<iostream>
#include<string>
#include<vector>
#include<iomanip>
#include<algorithm>
#include<queue>
#include<stack>
#include<list>
#include<map>
#include<deque>
#include<math.h>
using namespace std;
#define ll long long
int main(){
    ll h,w,k;
    cin >> h >> w >> k;
    string s[h];
    ll a[h][w];
    ll i,j,l;
    for(i=0;i<h;i++){
        cin >> s[i];
    }
    ll lb,lu=0;
    ll cnt0=0,cnt1=0;
    for(i=0;i<h;i++){
        lb=0;
        cnt1=0;
        for(j=0;j<w;j++){
            if(s[i][j]=='.'){
                lb++;
                if(j==w-1&&cnt1!=0){
                    for(l=0;l<lb;l++){
                        a[i][j-l]=cnt0;
                    }
                }
            }
            if(s[i][j]=='#'){
                cnt0++;
                for(l=0;l<=lb;l++){
                    a[i][j-l]=cnt0;
                }
                cnt1++;
                lb=0;
            }
        }
        if(cnt1==0){
            lu+=1;
            if(i==h-1){
                for(j=0;j<w;j++){
                    for(l=0;l<lu;l++){
                        a[h-1-l][j]=a[h-1-lu][j];
                    }
                }
            }
        }else {
            if(lu!=0){
                for(j=0;j<w;j++){
                    for(l=0;l<lu;l++){
                    a[i-1-l][j]=a[i][j];
                }
            }
            }
            lu=0;
        }
    }
    for(i=0;i<h;i++){
        for(j=0;j<w-1;j++){
            cout <<a[i][j] <<" ";
        }
        cout <<a[i][w-1]<<endl;
    }
    return 0;
}


Measured memory_bytes: 3992
#include <bits/stdc++.h>
#define maxn 100005
using namespace std;

const int INF = 1e9;

int h[maxn], dp[maxn] = {};
int n;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> n;
    for(int i = 1; i <= n; i++) {
        cin >> h[i];
    }
    for(int i = 2; i <= n; i++) {
        dp[i] = INF;
        if(i - 1 > 0) dp[i] = min(dp[i], dp[i - 1] + abs(h[i] - h[i - 1]));
        if(i - 2 > 0) dp[i] = min(dp[i], dp[i - 2] + abs(h[i] - h[i - 2]));
    }
    cout << dp[n] << '\n';
    return 0;
}



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

int main(){
  int A, B,C;
  cin >> A >> B >>C;
  string ans;
  if (A < C && C < B){
    ans = "Yes";
  } else if( B < C && C < A){
    ans ="Yes";
  } else ans = "No";
  cout  << ans << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#define WHITE 0
#define GRAY 1
#define BLACK 2
#define NIL -1

int main(){
  int i,j,n,count = 0;
  int G[101][101],color[101],d[101],pi[101],mincost,u;

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

  for(i=0;i<n;i++){
    d[i] = 2001;
    pi[i] = NIL;
    color[i] = WHITE;
  }

  d[0] = 0;
  
  while(1){
    mincost = 2001;
    for(i=0;i<n;i++){
      if(color[i] != BLACK && d[i] < mincost){
	mincost = d[i];
	u = i;
      }
    }
    
    if(mincost == 2001)break;
    
    color[u] = BLACK;
    
    for(i=0;i<n;i++){
      if(G[u][i] != NIL && color[i] != BLACK && G[u][i] < d[i]){
	pi[i] = u;
	d[i] = G[u][i];
	color[i] = GRAY;
      }
    }
    
  }
  for(i=0;i<n;i++){
    if(pi[i] != NIL)count+=G[i][pi[i]];
  }
  
  printf("%d\n",count);
  return 0;
}



Measured memory_bytes: 2052
#include <bits/stdc++.h>
using namespace std;
using P = pair<int, int>;
#define chmin(i, j) i = min(i, j);
#define chmax(i, j) i = max(i, j);
int main() {
  int n, A;
  cin >> n >> A;
  int x[n];
  long long ans = 0;
  for(int i=0;i<n;i++) {
    cin >> x[i];
  }
  vector<vector<vector<long long>>> dp(n+1, vector<vector<long long>>(n+1, vector<long long>(n*A+1)));
  for(int i=0;i<n+1;i++) {
    for(int j=0;j<n+1;j++) {
      if(j > i) break;
      for(int k=0;k<n*A+1;k++) {
        if(i == 0) {
          if(k == 0) dp[i][j][k] = 1;
          else dp[i][j][k] = 0;
        }
        else if(j == 0) {
          if(k == 0) dp[i][j][k] = 1;
          else dp[i][j][k] = 0;
        }
        else if(x[i-1] > k) dp[i][j][k] = dp[i-1][j][k];
        else dp[i][j][k] = dp[i-1][j][k] + dp[i-1][j-1][k-x[i-1]];
      }
    }
  }
  for(int i=1;i<n+1;i++) {
    ans += dp[n][i][i*A];
  }
  cout << ans << endl;
}



Measured memory_bytes: 52224
#include<bits/stdc++.h>
using namespace std;
int n,k;
int main()
{
    double ans=0;
    cin>>n>>k;
    if(n>=k)ans+=(n-k+1.0)/n;
    for(int i=1;i<=min(n,k-1);i++){
        double tmp=1.0/n;
        int j=i;
        while(j<k)tmp*=1.0/2,j*=2;
        ans+=tmp;
    }
    return printf("%.10f",ans),0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>

using namespace std;

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

    if(s.at(2) == s.at(3) && s.at(4) == s.at(5))
        cout << "Yes" << endl;
    else
        cout << "No" << endl;

    return 0;
}


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

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

using ll = long long int;
const ll MOD = 1e9 + 7;

int main() {
  int N;
  std::cin >> N;
  std::vector<int> A(N);

  std::map<int, int> cnt;
  rep(i, N) {
    std::cin >> A[i];
    ++cnt[A[i]];
  }

  ll base = 0;
  std::map<int, bool> used;
  rep(i, N) {
    if(used[A[i]]) continue;
    base += (ll) cnt[A[i]] * (cnt[A[i]] - 1) / 2;
    used[A[i]] = true;
  }

  rep(k, N) {
    ll ans = base - (cnt[A[k]] - 1);
    std::cout << ans << '\n';
  }
}


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

int main(){
    int n,x; cin >> n >> x;
    vector<int> m(n);
    int sum = 0;
    rep(i,n){
        cin >> m[i];
        sum += m[i];
    }
    sort(m.begin(), m.end());
    int res = n;
    x = x - sum;
    res += (x / m[0]);
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
<?php
const MOD = 10 ** 9 + 7;
list($n) = ints();
echo $n >= 2 ? modSub(modMul(2, modSub(modPow(10, $n), modPow(9, $n))), modSub(modPow(10, $n), modPow(8, $n))) : 0;
function ints()
{
    return array_map('intval', explode(' ', trim(fgets(STDIN))));
}
// 足し算
function modAdd($x, $y)
{
    return ($x + $y) % MOD;
}

// SUM
function modSum(...$xs)
{
    $res = 0;
    foreach ($xs as $x) $res = modAdd($res, $x);
    return $res;
}

// 引き算
function modSub($x, $y)
{
    return ($x + MOD - $y) % MOD;
}

// 掛け算
function modMul($x, $y)
{
    return ($x * $y) % MOD;
}

// PRODUCT
function modProd(...$xs)
{
    $res = 1;
    foreach ($xs as $x) $res = modMul($res, $x);
    return $res;
}

// 割り算
function modDiv($x, $y)
{
    return modMul($x, modPow($y, MOD - 2));
}

// 累乗（繰り返し二乗法）
function modPow($n, $x)
{
    if ($x === 0) return 1;
    $res = (modPow($n, $x >> 1) ** 2) % MOD;
    if ($x % 2 === 1) $res = modMul($res, $n);
    return $res;
}

// 階乗
function modFac($n)
{
    if ($n === 0) return 1;
    return modMul($n, modFac($n - 1));
}

// 順列
function nPr($n, $r)
{
    if ($r === 0) return 1;
    return modMul(nPr($n, $r - 1), $n - $r + 1);
}

// 組み合わせ
function nCr($n, $r)
{
    $r = min($r, $n - $r);
    if ($r === 0) return 1;
    return modDiv(nPr($n, $r), modFac($r));
}

// 階乗、逆元を前処理
function init($n)
{
    global $fact, $ifact;
    $fact[0] = 1;
    for ($i = 1; $i <= $n; ++$i) $fact[$i] = modMul($fact[$i - 1], $i);
    $ifact[$n] = modDiv(1, $fact[$n]);
    for ($i = $n; $i >= 1; --$i)
        $ifact[$i - 1] = modMul($ifact[$i], $i);
}

// 順列（前処理）
function nPr2($n, $r)
{
    global $fact, $ifact;
    return modMul($fact[$n], $ifact[$n - $r]);
}

// 組み合わせ（前処理）
function nCr2($n, $r)
{
    global $fact, $ifact;
    return modMul(modMul($fact[$n], $ifact[$r]), $ifact[$n - $r]);
}


Measured memory_bytes: 16208
import numpy


N = int(input().strip())

V_array = []
C_array = []

V_array =[int(x) for x in input().split()]
C_array =[int(x) for x in input().split()]

ans = 0
for j in range(N):
    ans += V_array[j] - C_array[j] if V_array[j] > C_array[j] else 0


print(ans)

Measured memory_bytes: 27032
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <fstream>
#include<cstdio>
#include<iomanip>

#define REP(i, n) for(int i=0;i<n;i++)
#define REP_1(i, n) for(int i=1;i<n+1;i++)
using namespace std;
typedef long long ll;
typedef unsigned long ul;
typedef long double ld;


int main() {
    int a, b, c, d;
    bool Alice[110] = {false};
    bool Bob[110] = {false};
    bool both[110] = {false};
    cin >> a >> b >> c >> d;
    for (int i = a; i < b; i++) {
        Alice[i] = true;
    }
    for (int i = c; i < d; i++) {
        Bob[i] = true;
    }
    int ans = 0;
    REP(i, 110) {
        both[i] = Alice[i] && Bob[i];
        if (both[i])ans++;
    }
    cout<<ans;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
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: 3616
use std::io::*;
use std::str::FromStr;

pub fn read<T: FromStr>() -> T {
  let stdin = stdin();
  let stdin = stdin.lock();
  let token: String = stdin
    .bytes()
    .map(|c| c.expect("failed to read char") as char)
    .skip_while(|c| c.is_whitespace())
    .take_while(|c| !c.is_whitespace())
    .collect();
  token.parse().ok().expect("failed to parse token")
}

use std::cmp::{max, min};
use std::collections::HashMap;

fn main() {
  let x = read::<i64>();
  let mut dist: HashMap<i64, i64> = HashMap::new();
  let mut ans = 0;

  for _ in 0..x {
    let a = read::<i64>();
    let current = dist.entry(a).or_insert(0);
    *current += 1;
  }

  for (k, v) in dist.iter() {
    if v % 2 == 1 {
      ans += 1;
    }
  }

  println!("{}", ans);
}



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

#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define RFOR(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define LL long long
#define INF INT_MAX/3

const double EPS = 1e-14;
const double PI  = acos(-1.0);


int gcd(int a, int b) {
  if (a % b == 0) return b;
  return gcd(b, a % b);
}

int main(){
  int n, w;
  scanf("%d %d", &n, &w);

  vector<int> v(n + 1);
  v[0] = w;
  FOR (i, 1, n + 1) {
    scanf("%d", &v[i]);
  }

  sort(v.begin(), v.end());

  int ans = v[1] - v[0];
  FOR (i, 1, n) {
    ans = gcd(ans, v[i + 1] - v[i]);
  }

  cout << ans << endl;
}


Measured memory_bytes: 640
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>

#define SIZE 2000000

int main() {
  static int A[SIZE];
  int H=0;
  int i, l, largest, tmp, n;
  static char com[21], buf[20];
  buf[19]='\n';
  char outbuf[4096];
  int outlen=0;
  char *p;
  do {
    fgets(com, 20, stdin);
    if (*com == 'i') { // insert
      A[++H] = 0;
      p = com+7;
      do {
        A[H] = A[H]*10 + *p-'0';
        p++;
      } while (*p&0x20);  // (*p!='\n');
      for (i=H; i>1 && A[i>>1]<A[i];i>>=1) {
        tmp = A[i>>1];
        A[i>>1] = A[i];
        A[i] = tmp;
      }
    } else if (com[1]=='x') { // extract
      n = A[1];
      for (i=18; n>0; n/=10) buf[i--]=(n%10)+'0';
      //      fputs(buf+i+1, stdout);
      strncpy(outbuf+outlen, buf+i+1, 19-i);
      outlen += 19-i;
      if (outlen>4080) {
        write(1, outbuf, outlen);
        outlen=0;
      }
      
      A[1] = A[H];
      i = 1;
      while (1) {
        l = i<<1;
        largest = i;
        if (l < H && A[l] > A[i])        largest = l;
        if (l+1 < H && A[l+1] > A[largest])  largest = l+1;
        if (largest == i) break;
        tmp = A[i];
        A[i] = A[largest];
        A[largest] = tmp;
        i = largest;
      }
      H--;
    } else {
      write(1, outbuf, outlen);
      break;
    }
  } while (1); //(com[2]!='d'); // end
  return 0;
}


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

long long N, M;
long long H[100005];
int main(){
	cin >> N >> M;

	set<long long> good;

	for(long long i = 0; i < N; i++){
		cin >> H[i];
		good.insert(i);
	}

	for(long long i = 0; i < M; i++){
		long long A, B;
		cin >> A >> B;
		A--;B--;
		if(H[A] == H[B]) {
			good.erase(A);
			good.erase(B);
		}
		if(H[A] < H[B]) {
			good.erase(A);
		}
		if(H[A] > H[B]) {
			good.erase(B);
		}
	}
	cout << good.size() << endl;
}



Measured memory_bytes: 9076
#include<bits/stdc++.h>
using namespace std;
int n,k,q;
int a[2009],b[2009];
main(){
    cin >> n>>k>>q;
    for(int i = 1;  i <= n; i++){
        cin >> a[i];
    }
    int ans = 1e9;
    for(int i = 1; i <= n; i++){
        int l = 0, x = a[i];
        vector<int> VV;
        for(int j = 1; j <= n+1; j++){
            if(a[j] < x || j == n+1){
                vector<int> V;

                for(int i = l +1; i < j; i ++) {
                    V.push_back(a[i]);
                }
                 l = j;
                if(!V.size()) continue;
                sort(V.begin(),V.end());
                for(int i = 0; i < (int)V.size() - k + 1; i++)
                    VV.push_back(V[i]);

            }
        }
        sort(VV.begin(), VV.end());
        if(VV.size() < q) continue;
        ans = min(ans , VV[q-1]-VV[0]);
    }
    cout<<ans<<endl;

}



Measured memory_bytes: 256
require 'complex'
N,D = gets.chomp.split(" ").map(&:to_i)
points = []
N.times do
    points << gets.chomp.split(" ").map(&:to_i)
end
sum = 0
0.upto(N-1) do |i|
    (i+1).upto(N-1) do |j|
        a_point = points[i]
        b_point = points[j]
        length = 0
        a_point.each_with_index do |point,k|

            length += (b_point[k] - point)**2
        end
        if Math.sqrt(length) ==  Math.sqrt(length).to_i
            sum += 1
        end
    end
end
puts sum

Measured memory_bytes: 1916
#include<iostream>
 #include<stdio.h>
 #include<string>
 #include<math.h>
 #include<iomanip>
 #include<algorithm>
 #include<string.h>
 #include<cctype>
 #include<map>
 #include<set>
 #include<vector>
 #include<sstream>
 
 using namespace std;
 
 int main()
 {
   int n;
   cin>>n;
   while(n--)
   {
     double x1,y1,x2,y2,x3,y3;
     cin>>x1>>y1>>x2>>y2>>x3>>y3;
     double x=((y2-y1)*(y3*y3-y1*y1+x3*x3-x1*x1)-(y3-y1)*(y2*y2-y1*y1+x2*x2-x1*x1))/(2*(x3-x1)*(y2-y1)-2*((x2-x1)*(y3-y1)));  
     double y=((x2-x1)*(x3*x3-x1*x1+y3*y3-y1*y1)-(x3-x1)*(x2*x2-x1*x1+y2*y2-y1*y1))/(2*(y3-y1)*(x2-x1)-2*((y2-y1)*(x3-x1))); 
     double R=sqrt((x1-x)*(x1-x)+(y1-y)*(y1-y));
     printf("%.3lf %.3lf %.3lf\n",x,y,R);      
   }
   //while(1);      
   return 0;    
 }
 
 
 
 
 

Measured memory_bytes: 3212
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <cstring>
#include <iomanip>

using namespace std;
// ascending order
#define vsort(v) sort(v.begin(), v.end())
// descending order
#define vsort_r(v) sort(v.begin(), v.end(), greater<int>())
#define vunique(v) v.erase(unique(v.begin(), v.end()), v.end())
#define mp make_pair
#define ts(x) to_string(x)
#define rep(i, a, b) for(int i = (int)a; i < (int)b; i++)
#define repm(i, a, b) for(int i = (int)a; i > (int)b; i--)
#define bit(a) bitset<8>(a)
#define des_priority_queue priority_queue<int, vector<int>, greater<int> >
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 ll;
typedef pair<int, int> P;
const ll INF = 1e18;

#define MAX_V 1000000

void solve(int n, int x) {
  int rsl = 0;
  rep(a, 1, n + 1) {
    rep(b, a + 1, n + 1) {
      int c = x - a - b;
      if(1 <= c && c <= n && a < c && b < c) {
        ++rsl;
      }
    }
  }
  cout << rsl << endl;
}

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

  while(true) {
    int n, x;
    cin >> n >> x;
    if(n == 0 && x == 0) return 0;

    solve(n, x);
  }
}



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

double distance(int x1, int y1, int x2, int y2);

int main() {
  int N;
  cin >> N;
  vector<vector<int>> cities(N,vector<int>(2));
  vector<double> distances;
  for(int i = 0; i < N; ++i){
      int x,y;
      cin >> x >> y;
      cities[i][0] = x;
      cities[i][1] = y;
  }
  vector<int> v(N);
  iota(v.begin(),v.end(),0);
  int count = 0;
  do
  {
      count++;
      double distance_sum = 0;
      for(int i = 0; i < N-1;i++){
          distance_sum += distance(cities[v[i]][0],cities[v[i]][1],cities[v[i+1]][0],cities[v[i+1]][1]);
      }
      distances.push_back(distance_sum);
  } while ( next_permutation(v.begin(),v.end()));
  double average = accumulate(distances.begin(),distances.end(),0.0) / (double)count;
  cout << fixed << setprecision(10) <<average << endl;
  return 0;
}

double distance(int x1, int y1, int x2, int y2) {
  return sqrt(pow(x2 - x1, 2) + pow(y2 - y1, 2));
}

Measured memory_bytes: 892
import sys
#import cython

def main():
    read = lambda: sys.stdin.readline().rstrip()
    
    #N: cython.longlong = 0
    K = int(read())
    S = read()
    print(S[:K] + '...' if len(S) > K else S)
 
if __name__ == "__main__":
    main()

Measured memory_bytes: 9140
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip> 
#include <complex> 
#include <string>
#include <vector> 
#include <list>
#include <deque> 
#include <stack> 
#include <queue> 
#include <set>
#include <map>
#include <bitset>
#include <functional>
#include <utility>
#include <algorithm> 
#include <numeric> 
#include <typeinfo> 
#include <cstdio>
#include <cstdlib> 
#include <cstring>
#include <cmath>
#include <climits> 
#include <ctime>

using namespace std;

int rail[11],railal=0,sp[2];
double  c1,c2,t;
int main(void){
	int a;
	while(~scanf("%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d",&rail[1],&rail[2],&rail[3],&rail[4],&rail[5],&rail[6],&rail[7],&rail[8],&rail[9],&rail[10],&sp[0],&sp[1])){
		railal=0;
		t=0;
		for(a=1;a<=10;a++)railal+=rail[a];
		c1=(double)sp[0]/3600;
		c2=(double)sp[1]/3600;
		for(a=1;a<=10;a++){
			t+=(double)rail[a]/c1;
			if((double)t*(sp[0]+sp[1])/3600>=railal){
				cout << a << endl;
				break;
			}
		}
	}
	return 0;
}

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

ll solve(int n, int *A, int *B, int *C, int chk , ll dp[][3]){
	
	if(n == 0){
		return 0;
	}
	
	ll ans1,ans2,ans3;
	if(dp[n-1][chk] != -1)
	return dp[n-1][chk];
	
	if(chk == 0){
		ans2 = A[0] + solve(n-1 , A+1, B+1, C+1 , 1 , dp);
		ans3 = A[0]+ solve(n-1 , A+1, B+1, C+1 , 2, dp);
		dp[n-1][chk] = max(ans2,ans3);
		
	}
	else if(chk == 1){
		ans1 = B[0] + solve(n-1 , A+1, B+1, C+1 , 0, dp);
		ans3 = B[0] + solve(n-1 , A+1, B+1, C+1 , 2, dp);	
		dp[n-1][chk] =  max(ans1 , ans3);
	}
	else if(chk == 2){
		ans1 = C[0] + solve(n-1 , A+1, B+1, C+1 , 0, dp);
		ans2 = C[0] + solve(n-1 , A+1, B+1, C+1 , 1, dp);
		dp[n-1][chk] =  max(ans1 ,ans2);
	}
	return dp[n-1][chk];
}

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

int A[n],B[n],C[n];

for(int i=0;i<n;i++){
	cin>>A[i]>>B[i]>>C[i];
}

ll dp[n][3];
memset(dp,-1,sizeof(dp));
ll t1 = solve(n, A, B, C , 0 , dp);
memset(dp,-1,sizeof(dp));
ll t2 = solve(n, A, B, C , 1 , dp);
memset(dp,-1,sizeof(dp));
ll t3 = solve(n, A, B, C , 2 , dp);

cout<<max(t1,max(t2,t3));

return 0;
}

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

using ull = unsigned long long;
class RollingHash_Mersenne {
	const ull MASK30 = (1ULL << 30) - 1;
	const ull MASK31 = (1ULL << 31) - 1;
	const ull MASK61 = (1ULL << 61) - 1;
	const ull MOD = MASK61;
	const ull POSITIVIZER = MOD << 2;
	vector<ull> hash, power;
	ull base = rand() % (ull)1e5 + 3;

	// a * b と mod が等しい数を返す
	// 結果は (1UL << 63) + 3 - (1UL << 31) * 3 以下
	ull Mul(ull a, ull b) const {
		ull au = a >> 31;
		ull ad = a & MASK31;
		ull bu = b >> 31;
		ull bd = b & MASK31;
		ull mid = ad * bu + au * bd;
		ull midu = mid >> 30;
		ull midd = mid & MASK30;
		return au * bu * 2 + midu + (midd << 31) + ad * bd;
	}

	// mod 2^61-1を計算する
	ull CalcMod(ull x) const {
		ull xu = x >> 61;
		ull xd = x & MASK61;
		ull res = xu + xd;
		if(res >= MOD) res -= MOD;
		return res;
	}

   public:
	RollingHash_Mersenne(const string &s) {
		int sz = (int)s.size();
		hash.assign(sz + 1, 0);
		power.assign(sz + 1, 0);
		power[0] = 1;
		for(int i = 0; i < sz; i++) {
			power[i + 1] = CalcMod(Mul(power[i], base));
			hash[i + 1] = CalcMod(Mul(hash[i], base) + s[i]);
		}
	}

	template <class T>
	RollingHash_Mersenne(const vector<T> &v) {
		int sz = (int)v.size();
		hash.assign(sz + 1, 0);
		power.assign(sz + 1, 0);
		power[0] = 1;
		for(int i = 0; i < sz; i++) {
			power[i + 1] = CalcMod(Mul(power[i], base));
			hash[i + 1] = CalcMod(Mul(hash[i], base) + v[i]);
		}
	}

	ull get(int l, int r) const { return CalcMod(hash[r] + POSITIVIZER - Mul(hash[l], power[r - l])); }

	ull connect(ull h1, ull h2, ull h2len) const { return CalcMod(Mul(h1, power[h2len]) + h2); }

	// Longest Common Prefix
	int LCP(int l_this, int r_this, RollingHash_Mersenne &other, int l_other, int r_other) {
		int len = min(r_this - l_this, r_other - l_other);
		int low = 0, high = len + 1;
		while(high - low > 1) {
			int mid = (low + high) / 2;
			if(get(l_this, l_this + mid) == other.get(l_other, l_other + mid))
				low = mid;
			else
				high = mid;
		}
		return low;
	}
};

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

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

	RollingHash_Mersenne rh(s);
	int res = 0;
	rep(i, n) {
		rep(j, n) {
			if(j <= i) continue;
			int a = rh.LCP(i, n, rh, j, n);
			//	cout << a << endl;
			res = max(res, min(a, j - i));
		}
	}
	cout << res << endl;
}

Measured memory_bytes: 3712
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define endl "\n"
#define se second
#define ll long long
//priority_queue<int, vector<int>, greater<int> > pq;
#define _CRT_SECURE_NO_DEPRECATE
const int N = 300030;
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
const ll mod =  1e9+7;
int n; double x[1009], y[1009], r[1009]; vector<pair<int, double> > G[1009];
int main()
{
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin>>x[0]>>y[0]>>x[1]>>y[1];
	cin>>n;
	rep(i,0,n)
	cin>>x[i+2]>>y[i+2]>>r[i+2];
	rep(i,0,n+2)
	{
		rep(j,i+1,n+2)
		{
			double dist=max(hypot(x[i]-x[j],y[i]-y[j])-r[i]-r[j],0.0);
			G[i].push_back({j,dist});
			G[j].push_back({i,dist});
		}
	}
priority_queue<pair<double,int> > pq;
pq.push({0,0});
vector<double> d(n+2,1.0e+10);d[0]=0;
while(!pq.empty())
{
	int u=pq.top().se;
	pq.pop();
	for(pair<int,double> p: G[u])
	{
		if(d[p.fi]>d[u]+p.se)
		{
			d[p.fi]=d[u]+p.se;
			pq.push({-d[p.fi],p.fi});
		}
	}
}
cout<<setprecision(15)<<d[1]<<endl;
}








Measured memory_bytes: 22164
N = int(input())
h = list(map(int, input().split()))

DP = [0]
for i in range(1, N):
    if i == 1:
        DP += [abs(h[i]-h[i-1])]
        continue
    DP += [min(DP[i-1]+abs(h[i]-h[i-1]), DP[i-2]+abs(h[i]-h[i-2]))]

print(DP[-1])


Measured memory_bytes: 13928
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007

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

  int D[2][110];
  for(int i = 0;i < N;i++) {
    cin >> D[0][i] >> D[1][i];
  }

  for(int i = 0;i < N-2;i++) {
    if(D[0][i] != D[1][i]) continue;
    if(D[0][i+1] != D[1][i+1]) continue;
    if(D[0][i+2] != D[1][i+2]) continue;

    cout << "Yes" << endl;
    return 0;
  }

  cout << "No" << endl;

}


Measured memory_bytes: 3636
import Data.List
main = do
  x <- readLn
  let a = [1..x]
      b = 2 : [2..x]
      c = sort $ concat $ map (f x a) b
  print $ last c

f :: Int -> [Int] -> Int -> [Int]
f x [] n = []
f x (a:as) n
  | a ^ n <= x = (a^n) : f x as n
  | otherwise  = f x as n


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

int main(){
    int n;
    cin>>n;
    int x[n];
    for(int i=0;i<n;i++) cin>>x[i];
    int hp[100]={0};

    for(int i=1;i<=100;i++){
        for(int j=0;j<n;j++){
            hp[i-1] += (x[j]-i)*(x[j]-i);
        }
    }

    int tmp=hp[0];
    for(int i=0;i<100;i++){
        if(tmp>hp[i]){
            tmp=hp[i];
        }
    }

    cout<<tmp;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define eps 1e-10
#define MAXN 100005
//#define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
template<class T>
void read(T &res) {
    res = 0;T f = 1;char c = getchar();
    while(c < '0' || c > '9') {
	if(c == '-') f = -1;
	   c = getchar();
    }
    while(c >= '0' && c <= '9') {
    	res = res * 10 +c - '0';
    	c = getchar();
    }
    res *= f;
}
template<class T>
void out(T x) {
    if(x < 0) {x = -x;putchar('-');}
    if(x >= 10) {
    	out(x / 10);
    }
    putchar('0' + x % 10);
}
string s = "CODEFESTIVAL2016",t;
void Solve() {
    cin >> t;
    int ans = 0;
    for(int i = 0 ; i < s.length() ; ++i) {
        if(s[i] != t[i]) ++ans;
    }
    out(ans);enter;
}
int main() {
#ifdef ivorysi
    freopen("f1.in","r",stdin);
#endif
    Solve();
    return 0;
}


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

int main() {
  string str;
  cin >> str;
  sort(str.begin(), str.end());

  for (int i = 0; i < str.size() - 1; i++) {
    if (str.at(i) == str.at(i + 1)) {
      cout << "no" << endl;
      return 0;
    }
  }
  cout << "yes" << endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
	int h,w,i,j,flag=1;
	char map[51][51];
	cin>>h>>w;
	for(j=0;j<h;j++)
	for(i=0;i<w;i++)
	{
		cin>>map[j][i];
	}
	for(j=0;j<h;j++)
	{
		if(!flag)
		break;
		for(i=0;i<w;i++)	
	{
		if(map[j][i]=='#')
		{
		if(i!=0)
		{
			if(map[j][i-1]=='#')
			{
				continue;
			}	
		}
		if(i!=w-1)
		{
			if(map[j][i+1]=='#')
			{
				continue;
			}	
		}
		if(j!=0)
		{
			if(map[j-1][i]=='#')
			{
				continue;
			}	
		}
		if(j!=h-1)
		{
			if(map[j+1][i]=='#')
			{
				continue;
			}	
		}
		flag=0;
		break;
	    }
	}
	}
	if(flag)
	cout<<"Yes";
	else
	cout<<"No";
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
  int a, b, c;
  scanf("%d %d %d", &a, &b, &c);
  if (a < b) {
    if (b < c)
      printf("Yes\n");
    else
      printf("No\n");
  }
  else
    printf("No\n");
  return 0;
}



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

using namespace std;
using llong = long long;
using P = pair<llong, llong>;

#define BE(x) x.begin(), x.end()

const llong inf = llong(1e18)+7;
const llong mod = 1e9+7;

int main(){
	llong N, x;
	vector<llong> a;

	cin >> N >> x;
	a.resize(N);
	for(int i = 0; i < N; i++)
		cin >> a[i];
	sort(BE(a));
	llong sum = 0;
	int i;
	for(i = 0; i < N && sum + a[i] <= x; i++)
		sum += a[i];

	if(i == N && sum != x)
		i--;

	cout << i << endl;

	return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <iostream>
#include <vector>
#include <algorithm>
#include <ctime>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <random>
#include <unordered_set>
#include <unordered_map>
#include <string>
#include <cstring>
#include <iomanip>
using namespace std;

#define double long double
//#define int long long
#define mp make_pair
#define debug(x) cerr << #x << ": " << x << '\n';
#define fi first
#define se second
#define pb push_back
typedef long long ll;
typedef pair<int, int> pii;
template <typename T1, typename T2> bool chkmin(T1 &x, T2 y) { return y < x ? (x = y, true) : false; };
template <typename T1, typename T2> bool chkmax(T1 &x, T2 y) { return y > x ? (x = y, true) : false; };

void fast() {
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
}

const int N = 2e3 + 10;
int ans[N];

signed main() {
	fast();
	int n, x, y;
	cin >> n >> x >> y;
	for (int i = 1; i <= n; i++) {
		for (int j = i + 1; j <= n; j++) {
			int dist = j - i;
			chkmin(dist, abs(i - x) + abs(j - y) + 1);
			ans[dist]++;
		}
	}
	for (int i = 1; i < n; i++) cout << ans[i] << '\n';
 	return 0;
}

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

int main(){
  	ios_base::sync_with_stdio(false);
  	cin.tie(0);
  	cout.tie(0);
    string s;
    cin >> s;
    s = '0' + s;
    int n = s.size();
    int arr[n];
    for(int i = 0; i < n; i++){
        arr[i] = s[i] - '0';
    }
    int ans[n][2];
    ans[n-1][0] = arr[n-1];
    ans[n-1][1] = 10 - arr[n-1];
    for(int i = n-2; i >= 0; i--){
        for(int c = 0; c < 2; c++){
            int d = c ? 9 - arr[i] : arr[i];
            ans[i][c] = min(
                ans[i+1][c],
                ans[i+1][!c] + 1
            ) + d;
        }
    }
    cout << ans[0][0] << '\n';
}


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

int compare_char(char *a,char *b){
	return strcmp(a,b);
}

int intsort(const void *a, const void *b){
	return *(int*)b - *(int*)a;
	/*qsort(a,aの配列数,sizeof(int),intsort);*/
}

int longsort(const void *a, const void *b){
	long *A=(long *)a;
	long *B=(long *)b;
	if(*A>*B) return -1;
	if(*A<*B) return 1;
	return 0;
}

int main(){
  int i,N,K,a[20000];
  scanf("%d",&N);
  scanf("%d",&K);
printf("%d\n",N-K+1);
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>    
//#include <ext/pb_ds/assoc_container.hpp> 
//#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
//#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//using namespace __gnu_pbds; 
#define fastio() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define pb  push_back
#define show(x) cout<<(#x)<<" : "<<x<<endl;
#define ll  long long
#define ld  long double
#define fill(a,val) memset(a,val,sizeof(a))
#define mp  make_pair
#define ff  first
#define ss  second
#define pii pair<ll,ll>
#define sq(x) ((x)*(x))
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define endl "\n"
#define int long long 
#define printclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";
const ll MOD     = 1000*1000*1000+7;
const ll INF     = 1ll*1000*1000*1000*1000*1000*1000 + 7;
const ll MOD2    = 998244353;
const ll N       = 1000 * 100 + 10;
const ll N2      = 70;
const ld PI  = 3.141592653589793;
//template<class T> using oset=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
ll gcd(ll a, ll b){if(!b)return a;return gcd(b, a % b);} 
ll power(ll x,ll y,ll p = LLONG_MAX ){ll res=1;x%=p;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;}
ll lcm(ll a , ll b){return (a*b)/gcd(a,b);}

signed main()
{
    fastio();
    //cout<<fixed<<setprecision(20);
    //CHECK for LONG LONG and LONG DOUBLE
    //*comment for all except cc/cf    
    #ifndef ONLINE_JUDGE    
           freopen("input.txt","r",stdin);
           freopen("output.txt","w",stdout);
    #endif//*/
    int l,r,d;
    cin>>l>>r>>d;
    int ans = r/d - l/d;
    if(l%d==0)
        ans++;
    cout<<ans<<endl;

    printclock;
    return 0;
}


Measured memory_bytes: 3784
#include <bits/stdc++.h>
#include<vector>
using namespace std;
#define rep(i, n)        for(int i=0; i<(int)(n); ++i)
int main() {
  int a,b;
  cin>>a>>b;
  if((a*b)%2==0)cout<<"Even";
  else cout<<"Odd";
}


Measured memory_bytes: 256
n = int(input())
list_A = list(map(int, input().split()))
s = sum(list_A)
ans = 0
mod = pow(10, 9) + 7

for i in range(n):
    s -= list_A[i]
    ans += list_A[i] * (s % mod)
    ans %= mod

print(ans)

Measured memory_bytes: 31716
#include<iostream>
#include<string>
#include<algorithm>
#include<math.h>
#include<queue>
#include<set>
#include<map>
#include<random>
#include<functional>
#include<utility>

#define rep(i,n) for(int i=0; i<n; i++)
#define pb push_back
#define P pair<int, int>
#define PLI pair<ll, int>

using namespace std;

typedef long long ll;


const ll INF = 1e18;

struct dan
{
	int id, d;
	dan(int id, int d) :id(id), d(d) {}
};

int N, M, K, S;
ll p, q;
int danger[100000] = {};
vector<int> g[100000];
ll cost[100000];
int main() {
	cin >> N >> M >> K >> S >> p >> q;
	queue<dan> que;
	rep(i, K) {
		int c;
		cin >> c; c--;
		danger[c] = S + 1;
		que.emplace(c, S + 1);
	}
	rep(i, M) {
		int a, b;
		cin >> a >> b; a--; b--;
		g[a].push_back(b);
		g[b].push_back(a);
	}

	while (!que.empty())
	{
		dan n = que.front(); que.pop();
		if (n.d == 0) continue;
		if (danger[n.id] > n.d) continue;
		for (auto e : g[n.id]) {
			if (danger[e] < n.d - 1) {
				danger[e] = n.d-1;
				que.emplace(e, danger[e]);
			}
		}
	}

	fill(cost, cost + N, INF);
	priority_queue<PLI, vector<PLI>, greater<PLI>> pq;
	cost[0] = 0;
	pq.emplace(0, 0);
	while (!pq.empty())
	{
		P pr = pq.top(); pq.pop();
		if (cost[pr.second] < pr.first) continue;
		for (auto e : g[pr.second]) {
							if (danger[e] == S + 1) continue;
			ll tmp = 0;
			if (e != N-1) {
				if (danger[e] == 0) tmp = p;
				else tmp = q;
			}
			if (cost[e] > cost[pr.second] + tmp) {
				cost[e] = cost[pr.second] + tmp;
				pq.emplace(cost[e], e);
			}
		}
	}

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


	return 0;
}




Measured memory_bytes: 10984
from fractions import gcd

n, m = map(int, input().split())
a = list(map(int, input().split()))
l = 1
num = a[0]
bin = 1
while num % 2 == 0:
    bin *= 2
    num //= 2
for num in a:
    l = (l * num // 2) // gcd(l, num // 2)
    if num % bin != 0 or num % (bin * 2) == 0:
        print(0)
        exit()
print((m + l) // (2 * l))


Measured memory_bytes: 16280
import std.stdio, std.conv, std.string;
import std.algorithm, std.array, std.container;
import std.numeric, std.math;

string my_readln() { return chomp(readln()); }

long mod = pow(10, 9) + 7;
long moda(long x, long y) { return (x + y) % mod; }
long mods(long x, long y) { return (x - y) % mod; }
long modm(long x, long y) { return (x * y) % mod; }

void main()
{
	auto tokens = my_readln().split();
	auto N = tokens[0].to!uint;
	auto K = tokens[1].to!uint;
	auto a = my_readln.split.to!(long[]);

	auto dp = new long[][](105, 100005);
	dp[0][0] = 1;

	foreach (i; 0..N)
	{
		dp[i+1][0] = moda(dp[i+1][0], dp[i][0]);
		foreach (j; 1..K+1)
		{
			dp[i+1][j] = moda(dp[i+1][j], dp[i][j]);
			dp[i+1][j] = moda(dp[i+1][j], dp[i+1][j-1]);
			if (j > a[i])
				dp[i+1][j] = mods(dp[i+1][j] + mod, dp[i][j-a[i]-1] % mod);
		}
	}

	writeln(dp[N][K]);
	stdout.flush();
}

Measured memory_bytes: 85244
s = {}
s['a'] = input()
s['b'] = input()
s['c'] = input()

l = {i:len(s[i]) for i in 'abc'}
cnt = {i:0 for i in 'abc'}
t = 'a'

while True:
    if cnt[t] == l[t]:
        print(t.upper())
        break
    _t = t
    t = s[_t][cnt[_t]]
    cnt[_t] += 1

Measured memory_bytes: 3064
K = int(input())
N =[1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]

print(N[K-1])


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

std::vector<int> insertionSort(std::vector<int>,int);

int main(int argc, char const *argv[]){

	int N;
	std::cin >> N;
	std::vector<int> fig(N);

	for (int i = 0; i < N; ++i){
		std::cin >> fig[i];
	}

	for (int i=0; i<N; ++i){
		std::cout << fig[i];
		if(i<N-1)std::cout << " ";
	}
	std::cout << std::endl;

	std::vector<int> ans = insertionSort(fig,N);
	return 0;
}

std::vector<int> insertionSort(std::vector<int> fig, int N){

	for (int i = 1; i < N; ++i){
		int buff = fig[i];
		int j=i-1;
		while( j>=0 && fig[j]>buff ){
			fig[j+1] = fig[j];
			j -= 1;
		}
		fig[j+1] = buff;

		for (int k=0; k<N; ++k){
			std::cout << fig[k];
			if(k<N-1)std::cout << " ";
		}
		std::cout << std::endl;
	}
	return fig;
}


Measured memory_bytes: 3152
#include<bits/stdc++.h>
#define rep(i,n,m) for(int i = (n); i <(m); i++)
#define rrep(i,n,m) for(int i = (n) - 1; i >=(m); i--)
#define pvec(vec) {for (auto v: vec) cout << v << ' '; cout << endl;}
#define pivec(vec) {rep(i, 0, vec.size()) cout << i << ':' << vec[i] << ' '; cout << endl;}

using namespace std;
using ll = long long;

int main()
{
    int N;
    cin >> N;
    vector<double> probs(N);
    rep(i, 0, N) cin >> probs[i];

    vector<double> dp(N+1, 0);
    dp[0] = 1;

    rep(i, 0, N)
    {
        // double check_sum = 0;
        // rep(i, 0, N) check_sum += dp[i];
        // cout << "check_sum: " << check_sum << endl;

        vector<double> new_dp(N+1, 0);
        rrep(j, N, 0)
        {
            new_dp[j+1] += dp[j] * probs[i];
            new_dp[j] += dp[j] * (1 - probs[i]);
        }
        swap(dp, new_dp);
    }


    double ans = 0;
    for (int num = N; num > N - num; --num)
        ans += dp[num];
    printf("%.10f\n", ans);
    return 0;
}

Measured memory_bytes: 384
#include <iostream> // cin, cout, cerr
#include <algorithm> // minmax, sort, swap
#include <numeric> // iota
#include <cstdio> // printf, scanf
#include <string> // string, stoi, to_string
#include <vector> // vector
#include <queue> // queue, priority_queue
#include <deque> // deque
#include <map> // key-value pairs sorted by keys
#include <set> // set
#include <iomanip> // cout<<setprecision(n)
#include <functional> // function<void(int)>
#include <cmath>
#include <cassert>
#include <bitset>

#ifdef DEBUG
#include "debug.hpp"
#else
#define debug(...)
#endif

#define int long long // at least int64 > 9*10^18
#define EL '\n'
#define rep(i,n) for(int i = 0; i < (n); i++)
#define print(i) std::cout << (i) << '\n'
#define all(v) (v).begin(), (v).end()
/* libraries */

signed main() {
	int n;
	std::cin >> n;
	int min = 64;
	rep(i,n) {
		int x;
		std::cin >> x;
		int y = 0;
		while(!(x&1)) x>>=1,++y;
		min=std::min(min,y);
	}
	print(min);
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include <map>
//#include <time.h>
#include <queue>
#include <set>
#include <string>
#include <string.h>
#include <stack>
#include <assert.h>
#include <bitset>
#define Endl endl
#define mp make_pair
#define ll long long 
#define ull unsigned long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define over(A) {cout<<A<<endl;exit(0);}
#define all(A) A.begin(),A.end()
#define ceil(a,b) ((a-1)/b+1)
#define quickcin ios_base::sync_with_stdio(false);
const int mod=1e9+7;
const int inf=1039074182;
const ll llinf=1LL*inf*inf;
using namespace std;
template <typename T1,typename T2> inline void chmin(T1 &x,T2 b) {if(b<x) x=b;}
template <typename T1,typename T2> inline void chmax(T1 &x,T2 b) {if(b>x) x=b;}
template <typename T1,typename T2> inline void chadd(T1 &x,T2 b) {x+=b;if(x>=mod) x-=mod;}
template <typename T1,typename T2> inline void chmul(T1 &x,T2 b) {x=1LL*x*b%mod;}
template <typename T1,typename T2> inline void chmod(T1 &x,T2 b) {x%=b,x+=b;if(x>=b) x-=b;}
int n;
int a[1000005];
int par[1000005];
vector <int> vec[1000005];
int sz[1000005];

inline ll dfs(int x)
{
	ll res=0;
	int sm=0;
	int mx=0;
	vector <int> v;
	v.reserve((int)vec[x].size());
	for(auto u:vec[x])
	{
		if(u==par[x]) continue;
		res+=dfs(u);
		v.push_back(sz[u]);
	}
	sort(all(v));
	for(auto value:v)
	{
		res+=sm;
		sm+=value;
	}
	return res;
}

inline int getnum()
{
	int res=0;
	char c=0;
	int neg=1;
	while(!isdigit(c) && c!='-') c=getchar();
	if(c=='-')
	{
		neg=-1;
		c=getchar();
	}
	while(isdigit(c)) res=res*10+c-'0',c=getchar();
	return res*neg;
}

vector <int> order;
vector <int> v[1000005];
ll res[1000005];

int main()
{
//	freopen("input.txt","r",stdin);
	n=getnum();
	vector <int> st;
	for(int i=0;i<n;i++)
	{
		a[i]=getnum();
		par[i]=getnum();
		if(par[i]==-1)
		{
			st.push_back(i);
		}
		else
		{
			vec[par[i]].push_back(i);
		}
	}
	queue <int> que;
	for(auto x:st)
	{
		que.push(x);
	}
	while(que.size())
	{
		int tp=que.front();
		que.pop();
		order.push_back(tp);
		for(auto u:vec[tp])
		{
			que.push(u);
		}
	}
	reverse(all(order));
	for(int i=0;i<n;i++)
	{
		sz[i]=a[i];
	}
	for(int i=0;i<n;i++)
	{
		int x=order[i];
		if(par[x]==-1) continue;
		sz[par[x]]+=sz[x];
	}
	ll ans=0;
	for(int i=0;i<n;i++)
	{
		int x=order[i];
		
		sort(all(v[x]));
		int sm=0;
		for(auto value:v[x])
		{
			res[x]+=sm;
			sm+=value;
		}
		
		if(par[x]==-1)
		{
			ans+=res[x];
			continue;
		}
		v[par[x]].push_back(sz[x]);
		res[par[x]]+=res[x];
	}	
	cout<<ans<<endl;
	return 0;
}


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

int main() {
  int a, b, c;
  scanf("%d %d %d", &a, &b, &c);

  if (c > a + b && 4LL * a * b < 1LL * (c - a - b) * (c - a - b))
    printf("Yes\n");
  else
    printf("No\n");

  return 0;
}

Measured memory_bytes: 256