akhauriyash/Code-Regression huggingface dataset:
import qualified Data.Vector.Unboxed as V
import Data.Array.IArray (listArray, accumArray, (!))
import Data.Array.MArray
import Data.Array.ST (STUArray, runSTUArray)
import Data.Array.Unboxed (UArray)
import Data.List (sortOn, sortBy, unfoldr, partition)
import Data.Char (isSpace)
import Control.Monad.ST (ST)
import Control.Monad.Trans.State (StateT(..))
import qualified Data.ByteString.Char8 as B

-- utility functions

--   Input functions
readInt = B.readInt . B.dropWhile isSpace

readInts :: Int -> B.ByteString -> [Int]
readInts n = take n . unfoldr readInt

readIntsV :: Int -> B.ByteString -> V.Vector Int
readIntsV n = V.unfoldrN n readInt

readIntsA :: Int -> B.ByteString -> UArray Int Int
readIntsA n bs = runSTUArray $ do
  arr <- newArray_ (0,n-1)
  go arr 0 bs
  return arr
  where
    go :: STUArray s Int Int -> Int -> B.ByteString -> ST s ()
    go arr i bs
      | i==n = return ()
      | otherwise = do
        let Just (x,bs') = readInt bs
        writeArray arr i x
        go arr (i+1) bs'

readTsV :: Int -> B.ByteString -> V.Vector (Int,Int)
readTsV n = V.unfoldrN n $ runStateT ((,) <$> StateT readInt <*> StateT readInt)

readTs :: Int -> B.ByteString -> [(Int,Int)]
readTs n = take n . unfoldr readT where
  readT = runStateT ((,) <$> StateT readInt <*> StateT readInt)

-- main

ceilDiv x y = (x+(y-1))`div`y

main = do
  n <- read <$> getLine
  xs <- map read . words <$> getContents
  print $ 4 + ceilDiv n (minimum xs)


Measured memory_bytes: 508
#include <bits/stdc++.h>
using namespace std;
#define Endl endl
typedef long long ll;
const int MAXN = (int)1e5 + 5;
ll a, b, c, d;
ll gcd(ll x, ll y)
{
	return y ? gcd(y, x%y) : x;
}
ll solve(ll n)
{
	return n - n / c - n / d + n / (c*d / gcd(c, d));
}
int main()
{
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	while (cin >> a >> b >> c >> d)
		cout << solve(b) - solve(a - 1) << endl;
}
/*
4 9 2 3
10 40 6 8
314159265358979323 846264338327950288 419716939 937510582
*/

Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<map>
#include<set>
#include<vector>
#include<string>
#include<queue>
#include<iostream>
#define REP(i, n) for(int i = 0, ed_##i = n; i < ed_##i; i++)
#define FOR(i, n) for(int i = 1, ed_##i = n; i <= ed_##i; i++)
#define bit(x) (1 << (x))
#define bitl(x) (1LL << (x))
#define sqr(x) ((x) * (x))
#define sz(x) ((int)(x.size()))
#define cnti(x) (__builtin_popcount(x))
#define cntl(x) (__builtin_popcountll(x))
#define clzi(x) (__builtin_clz(x))  // Leading zeros
#define clzl(x) (__builtin_clzll(x))
#define ctzi(x) (__builtin_ctz(x))
#define ctzl(x) (__builtin_ctzll(x))

#ifdef QWERTIER
#define err(x) cerr << #x << " : " << x << endl
#else
#define err(x)
#endif

typedef long long LL;
using namespace std;

typedef pair<int,int> pii;
#define MP make_pair

#define N 100010
int n, a[N], cnt[N];

int main(){
#ifdef QWERTIER
  freopen("in.txt","r",stdin);
#endif
  scanf("%d", &n);
  int dia = 0;
  FOR (i, n) {
    scanf("%d", &a[i]);
    cnt[a[i]]++;
    dia = max(dia, a[i]);
  }
  FOR (i, n) {
    if (a[i] < (dia + 1) / 2) {
      puts("Impossible");
      return 0;
    } 
  }
  for (int i = dia; i >= (dia+1) / 2; i--) {
    if (i == dia && cnt[i] < 2) {
      puts("Impossible");
      return 0;
    }
    if (cnt[i] == 0) {
      puts("Impossible");
      return 0;
    }
    if (i == (dia+1) / 2) {
      if ((dia % 2 == 0 && cnt[i] != 1) || (dia % 2 == 1 && cnt[i] != 2)) {
        puts("Impossible");
        return 0;
      }
    }
  }
  puts("Possible");
  return 0;
}


Measured memory_bytes: 256
from itertools import accumulate
from collections import defaultdict
N, K = map(int, input().split())
A = list(map(int, input().split()))
B = accumulate([0]+ A)
C = [(b-i)%K for i, b in enumerate(B)]
cnt = defaultdict(int)
cnt[C[0]] = 1
res = 0
for i in range(1, N+1):
    if i >= K:
        cnt[C[i-K]] -= 1
    res += cnt[C[i]]
    cnt[C[i]] += 1
print(res)


Measured memory_bytes: 132092
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>

using namespace std;

int n, m;
typedef long long ll;

int main() {
    cin >> n >> m;
    if (n==1&&m>1) {
        cout << m-2 << endl;
    } else if (n>1&m==1){
        cout << n-2 << endl;
    } else if (n==1 && m==1) {
        cout << 1 << endl;
    } else {
        ll ans = 1ll*n*m-2*n-2*m+4;
        cout << ans << endl;
    }
    return 0;
}


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

void dfs(int n, int sh, int sw, int gh, int gw, vector<vector<int>> &maze, int &ans){
    if (n < 10){
        int w = maze[0].size();
        int h = maze.size();
        if (sh > 0 && maze[sh-1][sw] != 1){
            int th = sh - 1;
            while (th >= 0){
                if (maze[th][sw] == 3){
                    ans = min(ans, n+1);
                    break;
                }
                if (maze[th][sw] == 1){
                    maze[th][sw] = 0;
                    dfs(n+1, th+1, sw, gh, gw, maze, ans);
                    maze[th][sw] = 1;
                    break;
                }
                th--;
            }
        }
        if (sh < h - 1 && maze[sh+1][sw] != 1){
            int th = sh + 1;
            while (th < h){
                if (maze[th][sw] == 3){
                    ans = min(ans, n+1);
                    break;
                }
                if (maze[th][sw] == 1){
                    maze[th][sw] = 0;
                    dfs(n+1, th-1, sw, gh, gw, maze, ans);
                    maze[th][sw] = 1;
                    break;
                }
                th++;
            }
        }
        if (sw > 0 && maze[sh][sw-1] != 1){
            int tw = sw - 1;
            while (tw >= 0){
                if (maze[sh][tw] == 3){
                    ans = min(ans, n+1);
                    break;
                }
                if (maze[sh][tw] == 1){
                    maze[sh][tw] = 0;
                    dfs(n+1, sh, tw+1, gh, gw, maze, ans);
                    maze[sh][tw] = 1;
                    break;
                }
                tw--;
            }
        }
        if (sw < w - 1 && maze[sh][sw+1] != 1){
            int tw = sw + 1;
            while (tw < w){
                if (maze[sh][tw] == 3){
                    ans = min(ans, n+1);
                    break;
                }
                if (maze[sh][tw] == 1){
                    maze[sh][tw] = 0;
                    dfs(n+1, sh, tw-1, gh, gw, maze, ans);
                    maze[sh][tw] = 1;
                    break;
                }
                tw++;
            }
        }
    }
}

int main(){
    while (1){
        int w, h;
        cin >> w >> h;
        if (!w) break;
        vector<vector<int>> maze(h, vector<int>(w));
        int sh, sw;
        int gh, gw;
        for (int i = 0; i < h; i++){
            for (int j = 0; j < w; j++) {
                cin >> maze[i][j];
                if (maze[i][j] == 2){
                    sh = i;
                    sw = j;
                }
                if (maze[i][j] == 3){
                    gh = i;
                    gw = j;
                }
            }
        }
        int ans = 11;
        maze[sh][sw] = 0;
        dfs(0, sh, sw, gh, gw, maze, ans);
        if (ans == 11) cout << -1 << endl;
        else cout << ans << endl;
    }
}


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

#define mem(ar,a)       memset(ar,a,sizeof ar)
#define iOS               ios_base::sync_with_stdio(false);cin.tie(NULL); 
#define pb(x)           push_back(x)
#define all(c)          c.begin(), c.end()
//#define int             long long
#define ff              first
#define ss              second
#define nl              '\n'

int main()
{
    iOS
    int d,t,s; cin>>d>>t>>s;

    if(d%s==0){
        int x=d/s;
        if(x<=t){
            cout<<"Yes";
        }
        else
            cout<<"No";
    }
    else{
        int x=ceil((float)d/(float)s);
        if(x<=t){
            cout<<"Yes";
        }
        else
            cout<<"No";
    }
}



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

int main(){    
  int N,a;
  cin >> N;
  vector<int> vec(N);
  for(int i = 0; i < N; i++){
    cin >> a;
    vec[i] = a;
  }
  ll Ans = 0;
  for(int i = 0; i < N-1; i++){
    for(int j = i+1; j < N; j++){
      Ans += vec[i] * vec[j];
    }
  }
  cout << Ans << endl;
}


Measured memory_bytes: 256
a,b = gets.chomp.split(" ").map{|x| x.to_i}
h,w = 80,50
field = []
for i in 0..h-1 do
  c =  i<(h/2) ? "#" : "."
  field[i] = c*w
end

a -= 1
isBreak = false
for i in 0.step(38,2).to_a do
  for j in 0.step(48,2).to_a do
    if a == 0
      isBreak = true
      break
    end
    field[i][j] = "."
    a -= 1
  end
  if isBreak
    break
  end
end

b -= 1
isBreak = false
for i in 41.step(79,2).to_a do
  for j in 0.step(48,2).to_a do
    if b == 0
      isBreak = true
      break
    end
    field[i][j] = "#"
    b -= 1
  end
  if isBreak
    break
  end
end

print "80 50\n"
for n in 0..(field.size-1) do 
  print "#{field[n]}\n" 
end

Measured memory_bytes: 1788
#pragma GCC optimize("O4")
#include <bits/stdc++.h>
#define For(i,a,b) for(int i=a;i<=b;i++)
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define sz(x) ((int)x.size())
//#define MOD (ll)(998244353)
#define MOD (ll)(1e9+7)
#define INF (1e17)
#define int ll
#define EPS (1e-6)
using namespace std;
using ll=long long;
using pii=pair<int,int>;

int gcd(int a,int b) { return b==0?a:gcd(b,a%b); }
int lcm(int a,int b) { return a/gcd(a,b)*b; }
int fpow(int b,int p){
	if(p==0) return 1;
	int h=fpow(b,p/2);
	if(p%2) return h*b%MOD*h%MOD;
	return h*h%MOD;
}

int32_t main() {
#ifdef LOCAL_TEST
	freopen("E:\\Jimmy\\2 Coding\\1 C++\\input.in","r",stdin);
	freopen("E:\\Jimmy\\2 Coding\\1 C++\\output.out","w",stdout);
	freopen("E:\\Jimmy\\2 Coding\\1 C++\\error.out","w",stderr);
#endif
	ios::sync_with_stdio(false);
	cin.tie(0);

	//code...
	string s; cin>>s>>s;
	cout<<'A'<<s[0]<<'C'<<"\n";
	return 0;
}

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

#include <vector>
#include <iostream>

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

using namespace std;

typedef long long ll;

/*
vector.push_back()
vector<int> hoge(3,-1); {-1,-1,-1}
vector<vector<int>> hogehoge(2,vector<int>(2,-1)); {{-1,-1},{-1,-1}} 
cin >>temp;
scanf("%d %d %d",&A,&B,&Q);
sort(a.begin(),a.end());
a.push_back(4000000000000);
a.insert(a.begin(),-1000000000000);
upper_bound(a.begin(),a.end(),x); // list[i] > x のイテレータ取得. *itrで数値化 
    std::priority_queue<
      int,
      std::vector<int>,
      decltype(compare) // 比較関数オブジェクトを指定
    > que(comp);
*/
template <typename T> void debug(T arr);
template <typename T> void debug (T arr, int dim);





int main(void){
    ll n;
    cin >> n;
    vector<ll> arr(n,0);
    rep(i,n){
        scanf("%lld",&arr[i]);
    }
    vector<ll> cost(n,0);
    cost[1] = cost[0]+abs(arr[0]-arr[1]);
    for (int i = 2; i < n; ++i){
        cost[i] = min(cost[i-1]+abs(arr[i-1]-arr[i]),cost[i-2]+abs(arr[i-2]-arr[i]));
    }
    cout << cost[n-1] << endl;


};


template <typename T> void debug(T arr){
    for (auto col:arr){
        cout << col << " ";
    }
    cout <<endl;
};

template <typename T> void debug (T arr, int dim){
    for (auto raw:arr){
        for(auto col:raw){
            cout << col << " ";
        }
        cout << endl;
    }
};


Measured memory_bytes: 1792
package main

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

func main() {
	sc := NewScanner()

	n := sc.NextInt()
	m := sc.NextInt()

	foods := make([]int, m+1)

	for i := 0; i < n; i++ {
		k := sc.NextInt()
		for j := 0; j < k; j++ {
			tmp := sc.NextInt()
			foods[tmp]++
		}
	}
	ans := 0
	for i := 0; i < m+1; i++ {
		if foods[i] == n {
			ans++
		}
	}

	fmt.Printf("%v\n", ans)

}

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r: rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			result = append(result, v)
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	result = append(result, v)

	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define FORR(i,a,b) for (int i=(a);i>=(b);i--)
#define pb push_back
#define pcnt __builtin_popcount
#define show(x) cout<<#x<<" = "<<x<<endl;
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define fi first
#define se second
#define rng(a) (a.begin()),(a.end())
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define sz(x) (int)(x).size()
#define mp make_pair

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef set<int> si;
typedef pair<ll,ll> pll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<pll> vpll;
typedef set<ll> sl;
typedef __int128_t lll;
typedef pair<lll,lll> plll;
typedef vector<lll> vlll;
template<typename T>string join(vector<T>&v)
{stringstream s;FOR(i,0,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename A, size_t N, typename T>void Fill(A (&array)[N], const T&v)
{fill((T*)array,(T*)(array+N),v);}
lll gcd(lll a,lll b,lll &x,lll &y){if(!b){x=1;y=0;return a;}lll d=gcd(b,a%b,y,x);y-=a/b*x;return d;}
ll gcd(ll a,ll b){lll x=0,y=0; return gcd(a, b, x, y);}
ll modpow(lll a,lll n,ll m){if(a==0)return a;lll p=1;for(;n>0;n/=2,a=a*a%m)if(n&1)p=p*a%m;return(ll)p;}
void dout(double d){printf("%.12f\n",d);}

const int iinf = 1e9;
const ll linf = 1e18;
const int mod = 1e9+7;
const double pi = acos(-1);
const double eps = 1e-10;
string s;
ll k;
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> s >> k;
  FOR(i, 0, sz(s)){
    if(s[i] != '1'){
      if(i+1 > k){
        break;
      }else{
        cout << s[i] << endl;
        return 0;
      }
    }
  }
  cout << 1 << endl;
  return 0;
}

Measured memory_bytes: 256
def main():

    m, n = tuple(map(int, input().split()))
    a = [[0 for j in range(n)] for i in range(m)]
    b = [0 for j in range(n)]
    c = [0 for i in range(m)]

    for i in range(m):
        tmplst = list(map(int, input().split()))
        for j in range(n):
            a[i][j] = tmplst[j]

    for j in range(n):
        b[j] = int(input())

    for i in range(m):
        for j in range(n):
            c[i] += a[i][j] * b[j]
        print(c[i])



if __name__ == '__main__':
    main()


Measured memory_bytes: 5948
#include <vector>
#include <algorithm>
#include <iostream>
#include <cassert>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <ctime>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <cassert>
#include <stack> 

#define INFLL 2000000000000000000
#define INF 2000000000
#define MOD 998244353 
#define BASE 77747
#define PI acos(-1.0)
#define MAXLEN 29

using namespace std;

typedef pair <int, int> pii;
typedef long long ll;
typedef vector <ll> vll;

ll add(ll a, ll b) {
	return (a + b) % MOD;
}
ll mul(ll a, ll b) {
	return (a * b) % MOD;
}
ll mpw(ll a, ll b) {
	ll ans = 1;
	while (b) {
		if (b & 1) ans = mul(ans, a);
		a = mul(a, a);
		b >>= 1;
	}
	return ans;
}

int k, n;
ll dp[2002][2002];
ll sums[2002];
ll c[4001][4001];

int main() {
	for (int i = 0; i <= 4000; i++) c[i][0] = 1;
	for (int i = 1; i <= 4000; i++) c[0][i] = 0;
	for (int i = 1; i <= 4000; i++) for (int j = 1; j <= i; j++) 
		c[i][j] = add(c[i - 1][j - 1], c[i - 1][j]);
	cin >> k >> n;
	for (int i = 1; i <= k; i++) {
		dp[0][i] = 1;
		dp[1][i] = i - 1;
		sums[i] = add(dp[1][i], dp[0][i]);
	}
	for (int i = 2; i <= n; i++) {
		for (int j = 2; j <= k + 1; j++) {
			if (j % 2) {
				dp[i][j] = add(dp[i][j - 2], mul(2, sums[j - 2]));
			} else {
				dp[i][j] = add(dp[i][j - 1], dp[i - 1][j - 1]);
			}
		}
		for (int j = 2; j <= k + 1; j++) sums[j] += dp[i][j];
	}
	for (int i = 0; i <= n; i++) for (int j = 2; j <= k; j++) 
		dp[i][j] = mul(dp[i][j], c[n - i + k - j][k - j]);
	for (int i = 2; i <= k; i++) {
		sums[i] = 0;
		for (int j = 0; j <= n; j++) sums[i] = add(sums[i], dp[j][i]);
		cout << sums[i] << endl;
	}
	cout << dp[n][k + 1] << endl;
	for (int i = k; i >= 2; i--) cout << sums[i] << endl;
	return 0;
}


Measured memory_bytes: 154880
#include<bits/stdc++.h>
#define FOR(i,a,b) for(long long i = (long long)(a); i < (long long)(b); i++)
#define RFOR(i,a,b) for(long long i = (long long)(a); i >= (long long)(b); i--)
#define MIN3(a,b,c) (a)<(b)?((a)<(c)?(a):(c)):((b)<(c)?(b):(c))
#define MAX(a,b) (a)>(b)?(a):(b)
#define MIN2(a,b) (a)<(b)?(a):(b)
using namespace std;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef long long ll;
#define ull unsigned long long
typedef long double ld;
typedef vector<ll> vll;
typedef pair<ll,ll> lll;
#define deb(x )     cerr << #x << " here "<< x << endl;
#define endl    "\n"
#define printCase() "Case #" << caseNum << ": "
inline bool is_palindrome(const string& s){ return std::equal(s.begin(), s.end(), s.rbegin()); }
const ll MOD = 1000000007;
const ll INF = 1e9+5;
const double eps = 1e-7;
const double PI = acos(-1.0);
#define coud(a,d) cout << fixed << showpoint << setprecision(d) << a;
inline void debug_vi(vi a) {FOR(i, 0, a.size()) cout<<a[i]<<" ";}
inline void debug_vll(vll a) {FOR(i, 0, a.size()) cout<<a[i]<<" ";}
#define ff first
#define ss second
/*----------------------------------------------------------------------*/

const int N = 1e5+5;
#define iis pair<ii,int>
iis arr[N], arr2[N];
vector<iii> prospects;

const int FINDSIZE = N;
int p[FINDSIZE],sizes[FINDSIZE];

//if it is the representative then return itself otherwise return parent of it's immediate parent
int findSet(int i){
	return (p[i]==i)? i : p[i]=findSet(p[i]);
}

bool isSameSet(int i, int j){
	return findSet(i) == findSet(j);
}

void join(int i, int j){
	if (!isSameSet(i,j))
	{
		int x = findSet(i),y = findSet(j);
		if(sizes[x] < sizes[y]){
			p[x] = y;
			sizes[y]+=sizes[x];
			
		}else{
			p[y] = x;
			sizes[x]+=sizes[y];
		}

	}
}

void initialiseUnionFind(){
	for(int i=0;i<FINDSIZE;i++){
		p[i] = i;
		sizes[i] = 1;
	}
}

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

    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    initialiseUnionFind();
    int n,u,v;
    cin>>n;

    FOR(i, 0, n) {
    	cin>>arr[i].ff.ff>>arr[i].ff.ss;
    	arr[i].ss = i;
    	arr2[i].ss = i;
    	arr2[i].ff.ss = arr[i].ff.ff;
    	arr2[i].ff.ff = arr[i].ff.ss;
    }
    sort(arr, arr+n);
    sort(arr2, arr2+n);
    ll ans = 0;
    FOR(i, 0, n-1) {
    	u = arr[i].ss; v = arr[i+1].ss;
    	prospects.push_back({abs(arr[i].ff.ff - arr[i+1].ff.ff), {u, v}});
    }
    FOR(i, 0, n-1) {
    	u = arr2[i].ss; v = arr2[i+1].ss;
    	prospects.push_back({abs(arr2[i].ff.ff - arr2[i+1].ff.ff), {u, v}});
    }
    sort(prospects.begin(), prospects.end());
    FOR(i, 0, prospects.size()) {
    	tie(u,v) = prospects[i].ss;
    	if(!isSameSet(u, v)) {
    		join(u, v);
    		ans += (ll)prospects[i].ff;
    	}
    }
    cout<<ans;

    return 0;
}

Measured memory_bytes: 7796
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
#define rep(i,x) for(ll i = 0; i < (ll)(x); i++)
#define rrep(i,x) for(ll i = (ll)(x)-1;i <= 0; i--)
#define reps(i,x) for(ll i = 1; i < (ll)(x); i++)
#define rreps(i,x) for(ll i = (ll)(x)-1; i <= 1; i--)
#define debug(x) cerr << #x << ": " << (x) << "\n";
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<ll>>> vvvl;
const ll INF = numeric_limits<ll>::max()/4;
const int n_max = 1e5+10;

int main(){
    ll n; cin >> n;
    bool ok = true;
    rep(i,n){
        ll a; cin >> a;
        if(a % 2 == 0){
            if(a % 3 != 0 && a % 5 != 0)ok = false;
        }
    }

    cout << (ok ? "APPROVED" : "DENIED") << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
using namespace std;
typedef long long ll;
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    ll a;
    cin>>a;
    string b;
    cin>>b;
    ll m =(long long)( b[0]-'0');
    ll k = (long long)( b[2]-'0');
    ll n= (long long)( b[3]-'0');
    
    ll ans = 0ll;
    ans += a*m;

    ll hi = a*k;
    ll you = a*n;
    hi%=10;
    you%=100;
    if(hi*10+you>=100){
        ans++;
    }
    
    
    k = a*k/10ll;
    ans+=k;
    n=a*n/100ll;
    ans+=n;
    
    
    cout<<ans<<endl;
    return 0;
}

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

int main(){
    ll n, m;
    cin >> n >> m;
    ll ans = 0;
    for(ll i = 1; i * i <= m; i++){
        if(m % i == 0){
            if(m / i >= n)
                ans = max(ans, i);
            if(i >= n)
                ans = max(ans, m / i);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define IOS                           \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL)
#define ll long long

using namespace std;

long long maxPossibleValue(vector<pair<int, int>> &items, int cur, int maxWeight, int totalWeight, vector<vector<ll>> &dp)
{
    if (cur == items.size())
    {
        return 0;
    }

    if (totalWeight <= maxWeight && dp[cur][totalWeight] != -1)
    {
        // cout << "MIRACLE" << endl;
        return dp[cur][totalWeight];
    }

    long long exclude = maxPossibleValue(items, cur + 1, maxWeight, totalWeight, dp);

    if (maxWeight == totalWeight + items[cur].first)
    {
        return max(exclude, (ll)items[cur].second);
    }

    if (maxWeight < totalWeight + items[cur].first)
    {
        return exclude;
    }

    long long include = items[cur].second + maxPossibleValue(items, cur + 1, maxWeight, totalWeight + items[cur].first, dp);

    dp[cur][totalWeight] = max(exclude, include);
    return max(exclude, include);
}

void solve()
{
    ll n, w;
    cin >> n >> w;

    vector<pair<int, int>> v;
    vector<vector<ll>> dp(n + 1, vector<ll>(w + 1, -1));
    int a, b;
    for (int i = 0; i < n; i++)
    {
        cin >> a >> b;
        v.push_back(make_pair(a, b));
    }
    // cout << v[0].first << " " << v[0].second << endl;
    cout << maxPossibleValue(v, 0, w, 0, dp);
}
int main()
{
    IOS;
    // int t;
    // cin>>t;
    // while(t>0)
    {
        solve();
        // t--;
    }
    return 0;
}

Measured memory_bytes: 80256
N = int(input())
An = list(map(int,input().split()))

# n(n-1)/2 - (n-1)(n-2)/2 = n-1
dic = {}
su = 0
m = 0
for a in An:
  dic[a] = 0
for a in An:
  dic[a] += 1 
for d,i in enumerate(dic):
  su += dic[i] * (dic[i]-1) / 2
for a in An:
  print(int(su - dic[a] + 1))


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

int A[300055];

int N, Ans;

int main() {
	scanf("%d", &N); Ans = N;
	for(int i = 1; i <= N; i++) {
		char c; scanf(" %c", &c);
		A[i] = A[i-1] + ('E' == c);
	}
	for(int i = 1, t; i <= N; i++) {
		t = A[N] - A[i] + i-1 - A[i-1];
		if(t < Ans) Ans = t;
	}
	cout << Ans << endl;
	return 0;
}

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

//#define int long long
#define reps(i,s,n) for(int (i)=(s);(i)<(n);++(i))
#define rep(i,n) reps(i,0,n)
#define rept(i,n) reps(i,0,((n)+1))
#define repst(i,s,n) reps(i,s,((n)+1))
#define reprt(i,n,t) for(int (i)=(n);(i)>=(t);--(i))
#define repr(i,n) reprt(i,n,0)
#define each(itr,v) for(auto &(itr):(v))
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define mp(x,y) make_pair((x),(y))
#define fi first
#define se second
#define tmax(x,y,z) max(x,max(y,z))
#define tmin(x,y,z) min(x,min(y,z))
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define ln '\n'
#define bln(i,n) (i==n-1?'\n':' ')
#define dbg(x) cout<<#x" = "<<(x)<<ln
#define dbga(x,n) {cout<<#x" : ";for(int (i)=0;i<(n);++i){cout<<((x)[i])<<(i==((n)-1)?'\n':' ');}}

typedef long double ld;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vst;
typedef vector<bool> vb;
typedef vector<ld> vld;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vector<int> > mat;

const ll inf = (ll)1e9+10;
const ll linf = (ll)1e18+10;
const ll mod = (ll)(1e9+7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};
const double eps = 1e-10;

struct oreno_initializer {
	oreno_initializer() {
		cin.tie(0);
		ios::sync_with_stdio(0);
	}
} oreno_initializer;

// ━━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…
// .｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋
// ・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・

int n;
string s;

signed main() {
	cin >> s;
	n = s.size();
	cout << (n%2==(s[0]==s[n-1]) ? "Second" : "First") << ln;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
int a,b,c,d,e,k;
cin>>a>>b>>c>>d>>e>>k;
if(b-a<=k&&c-a<=k&&d-a<=k&&e-a<=k&&c-b<=k&&d-b<=k&&e-b<=k&&e-c<=k&&d-c<=k&&e-d<=k)cout<<"Yay!";
else cout<<":(";
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#define exchange(a,b) {typeof(a) __tmp=a;a=b;b=__tmp;}
 
 
char A[100001];
int B[100001];
 
 
int Partition(int A[], int p, int r) {
  int i,j;
  int x;
  x = A[r];
  i = p-1;
  for(j = p; j < r; ++j) {
    if(B[A[j]] <= B[x]) { // if(A[j] <= x) {
      i = i+1;
      exchange(A[i], A[j]);
    }
  }
  exchange(A[i+1], A[r]);
  return i+1;
}
 
void Quicksort(int A[], int p, int r) {
  int q;
  if(p < r) {
    q = Partition(A,p,r);
    Quicksort(A,p,q-1);
    Quicksort(A,q+1,r);
  }
}
 
int isStable(int A[], int n) {
  int i;
  for(i = 2; i <= n; ++i) {
    if(B[A[i-1]] == B[A[i]] && A[i-1] > A[i]) return 0;
  }
  return 1;
}
 
int main() {
  int i;
  int n;
  int C[100001];
  scanf("%d", &n);
  for(i = 1; i <= n; ++i) {
    scanf(" %c %d", A+i,B+i);
    C[i] = i;
  }
  Quicksort(C,1,n);
  if(isStable(C,n)) printf("Stable\n");
  else printf("Not stable\n");
  for(i = 1; i <= n; ++i) {
    printf("%c %d\n", A[C[i]], B[C[i]]);
  }
  return 0;
}

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

const int MaxC = 10005;
const int MaxA = 2000005;
const int MaxB = 2000005;

int A[MaxA], B[MaxB], C[MaxC];
void CountingSort(int A[], int n, int k)
{
    memset(C, 0, sizeof(C));
    for(int i=0; i<n; i++)
    {
        C[A[i]]++;
    }
    for(int i=1; i<=k; i++)
    {
        C[i] += C[i-1];
    }
    for(int i=n-1; i>=0; i--)
    {
        B[C[A[i]]] = A[i];
        C[A[i]]--;
    }
}
int main()
{
    int n, k = 0;
    cin >> n;
    for(int i=0; i<n; i++)
    {
        cin >> A[i];
        if(k<A[i]) k = A[i];
    }
    CountingSort(A, n, k);
    for(int i=1; i<=n-1; i++)
        cout << B[i] << " ";
    cout << B[n] << endl;
    return 0;
}



Measured memory_bytes: 18760
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define int long long
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF (LLONG_MAX - 1e5)
#define fcout cout << fixed << setprecision(10)

using namespace std;

struct edge {
    int to, cost;
    edge(int _to, int _cost) : to(_to), cost(_cost) {}
    edge() {}
};

int N, M;
vector<edge> E[100005];
int V[2][100005];

void dfs(int status, int cur, int v) {
    if (V[status][cur] == INF) {
        V[status][cur] = v;
        for (auto e : E[cur]) {
            dfs(status ^ 1, e.to, e.cost - v);
        }
    }
    if (V[status][cur] != v) {
        cout << 0 << endl;
        exit(0);
    }
}

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

    cin >> N >> M;
    REP(i, M) {
        int u, v, s;
        cin >> u >> v >> s;
        u--;
        v--;
        E[u].push_back(edge(v, s));
        E[v].push_back(edge(u, s));
    }

    REP(i, 2) REP(j, N) V[i][j] = INF;
    dfs(0, 0, 0);

    if (V[1][0] != INF) {
        // 奇閉路が存在する
        int t = abs(V[1][0] - V[0][0]) / 2;
        REP(i, 2) REP(j, N) V[i][j] = INF;
        dfs(0, 0, t);
        REP(i, 2) REP(j, N) {
            if (V[i][j] <= 0) {
                cout << 0 << endl;
                return 0;
            }
        }
        cout << 1 << endl;
    } else {
        int minpos = INF;
        int minneg = INF;
        REP(i, N) {
            if (V[0][i] != INF) minpos = min(minpos, V[0][i]);
            if (V[1][i] != INF) minneg = min(minneg, V[1][i]);
        }
        cout << max(0LL, minneg + minpos - 1) << endl;
    }

    return 0;
}


Measured memory_bytes: 18816
#include <iostream>
#include <string> 
#include <vector> 
#include <algorithm> 
#include <utility> 
#include <tuple> 
#include <cstdint> 
#include <cstdio> 
#include <map> 
#include <queue> 
#include <set> 
#include <stack> 
#include <deque> 
#include <unordered_map> 
#include <unordered_set> 
#include <bitset> 
#include <cctype> 
#include <math.h>
using namespace std;

#define int long long
#define endl "\n"
#define all(v)  v.begin(),v.end()
#define fir first
#define sec second
#define fro front
#define m_p make_pair
#define mod 1000000007
#define INF 2000000000
#define rep(i,n)  for(int i=0; i<(int) (n); i++)
#define vecin(v) for(int i=0; i<(int)v.size(); i++)cin>>v[i];
using namespace std;

const int MAX = 510000;
const int MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];
int jousu(int x00, int y00) {
	int z00 = 1;
	for (int i = 0; i < y00; i++) {
		z00 *= x00;
	}
	return z00;
}
int keta(int x00) {
	int z00 = x00;
	int w00 = 0;
	while (z00 != 0) {
		z00 /= 10;
		w00++;
	}
	return w00;
}
int krag(double xx) {
	return INF - (int)(INF - xx);
}


int modinv(int a, int m) {
	int b = m, u = 1, v = 0;
	while (b) {
		int t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
int modpow(int a, int n) {
	int res = 1;
	while (n > 0) {
		if (n & 1) res* a% mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}
int com(int xx, int yy) {
	int zz = 1;
	for (int i = xx; i > xx - yy; i--) {
		zz *= i;
		zz %= mod;
	}
	for (int i = 1; i <= yy; i++) {
		zz *= modinv(i, mod);
		zz %= mod;
	}
	return zz;
}
int gcd(int xx, int yy) {
	int p = xx;
	int q = yy;
	if (q > p)swap(p, q);
	while (p % q != 0) {
		p %= q;
		swap(p, q);
	}
	return q;
}
int lcm(int xx, int yy) {
	return xx * yy / gcd(xx, yy);
}
bool prime(int xx) {
	int a = xx;
	for (int i = 2; i * i <= xx; i++) {
		if (xx % i == 0) {
			return 0;
		}
	}
	return 1;
}



signed main() {
	int a,n, t = 0,b=0;
	cin >> n;
	rep(i, n) {
		cin >> a;
		b = max(a, b);
		t += a;
	}
	cout << t - b / 2 << endl;
}



Measured memory_bytes: 256
import java.util.*;

public class Main {

	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int x = sc.nextInt();
		int total = 0;
		int min = Integer.MAX_VALUE;
		for (int i = 0; i < n; i++) {
			int y = sc.nextInt();
			total += y;
			if (y < min) {
				min = y;
			}
		}
		System.out.println(n + (x - total) / min);
	}
}


Measured memory_bytes: 23252
#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define EPS (1e-10)
using namespace std;
typedef long long ll;
typedef pair<int,int>P;

int d[200][200];
int R[200];
int dp[1<<8][8];
signed main() {
	int n,m,r;scanf("%d%d%d",&n,&m,&r);
	memset(d,0x3f,sizeof(d));
	rep(i,n)d[i][i]=0;
	rep(i,r){
		scanf("%d",&R[i]);R[i]--;
	}
	rep(i,m){
		int a,b,c;scanf("%d%d%d",&a,&b,&c);a--;b--;
		d[a][b]=d[b][a]=c;
	}
	rep(k,n)rep(i,n)rep(j,n)d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
	memset(dp,0x3f,sizeof(dp));
	rep(i,r){
		dp[1<<i][i]=0;
	}
	rep(i,1<<r){
		rep(k,r){
			rep(j,r){
				if(i>>j&1)continue;
				dp[i|1<<j][j]=min(dp[i|1<<j][j],dp[i][k]+d[R[k]][R[j]]);
			}
		}
	}
	int Min=INF;
	rep(i,r){
		Min=min(Min,dp[(1<<r)-1][i]);
	}
	cout<<Min<<endl;
}


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

int main() {
  char c;
  string s;
  int j=0;

  cin >> s;

  for(int i=0;i<s.length();i++) {
    c = s[i];
    if(c != 0) {
      if(c == s[i-1]) {
          cout << "Bad" << endl;
          break;
      }
      else {
        j++;
      }
    }
    else {j++;}
  }

  if(j == s.length()) {
    cout << "Good" << endl;
  }
  return 0;
}


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

int main() {
    int h,w,c=0;
    cin>>h>>w;
    for(int i=0;i<h;i++){
        string a;
        cin>>a;
        for(int j=0;j<w;j++){
            if(a[j]=='#')c++;
        }
    }
    if(c==h+w-1){
        cout<<"Possible"<<endl;
    }else{
        cout<<"Impossible"<<endl;
    }
	return 0;
}

Measured memory_bytes: 256
// ------------------------------------
// Date:2018/ 2/28
// Problem:ABC 052 TwoRectangles re_a.cpp
//
// ------------------------------------

#include <bits/stdc++.h>

using namespace std;

#define EACH(i,a) for (auto&& i : a)
#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 ALL(a) (a).begin(),(a).end()
#define debug(x) cerr << #x << ":" << x << endl

typedef long long ll;

static const int MOD = 1000000007;

int main()
{
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  cout << (a * b > c * d ? a * b : c * d) << endl;
  return 0;
}



Measured memory_bytes: 256
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**13
mod = 10**9+9
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


class Matrix():
    def __init__(self, A):
        self.A = A
        self.row = len(A)
        self.col = len(A[0])

    def __iter__(self):
        return self.A.__iter__()

    def __getitem__(self, i):
        return self.A.__getitem__(i)

    def __add__(self, B):
        aa = self.A
        bb = B.A
        return Matrix([[aa[i][j] + bb[i][j] for j in range(self.col)] for i in range(self.row)])

    def __sub__(self, B):
        aa = self.A
        bb = B.A
        return Matrix([[aa[i][j] - bb[i][j] for j in range(self.col)] for i in range(self.row)])

    def __mul__(self, B):
        bb = [[B.A[j][i] for j in range(B.row)] for i in range(B.col)]
        return Matrix([[sum([ak * bk for ak,bk in zip(ai,bj)]) % mod for bj in bb] for ai in self.A])

    def __truediv__(self, x):
        pass

    def pow_init(self, a):
        self.PA = pa = {}
        t = self.pow(a[0])
        c = a[0]
        pa[c] = t
        for d in a[1:]:
            t = t * self.pow(d-c)
            pa[d] = t
            c = d

    def pow(self, n):
        if n in self.PA:
            return self.PA[n]
        A = self
        r = Matrix([[0 if j != i else 1 for j in range(self.row)] for i in range(self.row)])
        while n > 0:
            if n % 2 == 1:
                r = r * A
            A = A * A
            n //= 2
        return r

    def __str__(self):
        return self.A.__str__()

def main():
    rr = []

    def f(w,h,n):
        a = sorted([LI()[::-1] for _ in range(n)])
        aa = [[0]*w for _ in range(w)]
        for i in range(w):
            ai = aa[i]
            ai[i] = 1
            if i > 0:
                ai[i-1] = 1
            if i < w-1:
                ai[i+1] = 1
        A = Matrix(aa)
        A.pow_init(list(map(lambda x: x[0], a)) + [h])
        t = [[0] for _ in range(w)]
        t[0][0] = 1
        T = Matrix(t)
        c = 1
        for hi,wi in a:
            T = A.pow(hi-c) * T
            T.A[wi-1][0] = 0
            c = hi
        T = A.pow(h-c) * T
        return T.A[-1][0]

    ci = 0
    while 1:
        ci += 1
        n,m,l = LI()
        if n == 0:
            break
        rr.append('Case {}: {}'.format(ci, f(n,m,l)))

    return '\n'.join(map(str, rr))


print(main())



Measured memory_bytes: 17084
#include<bits/stdc++.h>
#define N 200050
#define ll long long
#define pb push_back
#define x first
#define y second
using namespace std;
ll mod = 1e9 + 7;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n,k;
    cin>>n>>k;
    ll ans = 0;
    for(ll i = k;i<=n+1;i++){
        ll val = (i-1)*(i); val/=2ll;
        ll jal = n*(n+1);
        ll f = (n-i)*(n-i+1);
        jal -= f;
        jal/=2ll;
        jal-=val;
        jal%=mod;
        if(jal<0)jal+=mod;
        ans += jal+1;
        ans%=mod;if(ans<0)ans+=mod;
    }
    ans%=mod;
    if(ans<0)ans+=mod;
    cout<<ans;
    
    
    return 0;
}


Measured memory_bytes: 3648
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;

class Program
{
    static void Main(string[] args)
    {
        var N = int.Parse(ReadLine());

        var ans = "No";

        for (int i = 1; i <= 9; i++)
        {
            for (int j = 1; j <= 9; j++)
            {
                if (i * j == N)
                {
                    ans = "Yes";
                    break;
                }
            }
        }

        WriteLine(ans);
    }
}


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

int main()
{
	string t, h;
	int n, tp = 0, hp = 0;

	cin >> n;

	while (n-- && cin >> t >> h)
		if (t == h)
			tp++, hp++;
		else if (t > h)
			tp += 3;
		else
			hp += 3;

	cout << tp << " " << hp << endl;

	return 0;
}


Measured memory_bytes: 3144
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int a,b,c; cin >> a >> b >> c;
  if(a == b) cout << c << endl;
  if(b == c) cout << a << endl;
  if(a == c) cout << b << endl;
  return 0;
}

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

int main(int argc, char *argv[]) {
  int n;
  std::cin >> n;
  std::vector<std::vector<int>> a(n, std::vector<int>(3));
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < 3; ++j)
      std::cin >> a.at(i).at(j);

  std::vector<std::vector<int>> dp(n + 1, std::vector<int>(3, 0));
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < 3; ++j)
      for (int k = 0; k < 3; ++k) {
        if (j != k)
          dp.at(i + 1).at(j) =
              std::max(dp.at(i + 1).at(j), dp.at(i).at(k) + a.at(i).at(j));
      }

  int ans = 0;
  for (auto i : dp.at(n))
    ans = std::max(ans, i);

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


Measured memory_bytes: 11136
#include <iostream>
#include <iomanip>
#include <string>
#include <cctype>
#include <algorithm>
#include <numeric>
#include <iterator>
#include <vector>
#include <map>
#define _USE_MATH_DEFINES
#include <math.h>
using namespace std;

int main() {
	cout << fixed << setprecision(10);

	for (;;) {
		int n;
		cin >> n;
		if (n == 0) {
			break;
		}
		vector<double> s;
		copy_n(istream_iterator<double>(cin), n, back_inserter(s));
		double sum = accumulate(s.begin(), s.end(), 0.0);
		double avg = sum / n;
		double var = accumulate(s.begin(), s.end(), 0.0,
			[&](double a, double b) { return a + (b - avg) * (b - avg); }) / n;
		double sd = sqrt(var);
		cout << sd << endl;
	}

	return 0;
}



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

const int MAXN = 305;
const int MAXK = 305;
int N, K, M;
long long comb[MAXN][MAXN];
long long dp[MAXN][MAXN];
long long prefix[MAXN][MAXN];

int main() 
{
    // freopen("./input.txt", 'r', stdin);
    // freopen("./output.txt", 'w', stdout);

	scanf("%d %d %d", &N, &K, &M);
	comb[0][0] = 1;
	for (int i = 1; i <= N; i++) {
		comb[i][0] = comb[i][i] = 1;
		for (int j = 1; j <= i - 1; j++) {
			comb[i][j] = (comb[i - 1][j - 1] + comb[i - 1][j]) % M;
		}
	}	
	for (int x = K; x >= 0; x--) {
		dp[1][x] = 1;
		prefix[1][x] = (dp[1][x] + prefix[1][x + 1]) % M;
	}
	for (int n = 2; n <= N + 1; n++) {
		for (int x = K; x >= 0; x--) {
			dp[n][x] = 0;
			for (int k = 1; k <= n-1; k++) {
				long long temp = comb[n - 2][k - 1] * dp[n - k][x] % M;
				temp = temp * prefix[k][x + 1] % M;
				dp[n][x] = (dp[n][x] + temp) % M;
			}			
			prefix[n][x] = (dp[n][x] + prefix[n][x + 1]) % M;
		}
	}
	
	printf("%lld\n", dp[N + 1][0]);

	return 0;
}

Measured memory_bytes: 2432
#include <bits/stdc++.h>
#define ll long long

#define INF 999999999

using namespace std;

// input
int a[3];

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

    for(int i = 0;cin >> a[i];i++);
    sort(a,a+3);

    int ans = 0;

    for(int i = 1;i < 3;i++){
        ans += a[i] - a[i-1];
    }

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

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

using namespace std;

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

  int t, a;
  cin >> t >> a;

  vector<int> h(n);
  for (int i=0; i<n; i++) {
    cin >> h[i];
  }

  int ans_idx = 0;
  float ans_temp = FLT_MAX;
  for (int i=0; i<n; i++) {
    float temp = t - h[i] * 0.006;
    if (abs(temp - a) < ans_temp) {
      ans_idx = i;
      ans_temp = abs(temp - a);
    }
  }

  cout << ans_idx + 1 << endl;

  return 0;
}


Measured memory_bytes: 256
import sys
import numpy as np


def inputs(func=lambda x: x, sep=None, maxsplit=-1):
	return map(func, sys.stdin.readline().split(sep=sep, maxsplit=maxsplit))

def input_row(n : int, type=np.int, **kwargs):
	return np.fromiter(inputs(type, **kwargs), dtype=type)

def input_2d(nrows : int, ncols : int, type=np.int, **kwargs):
	data = np.zeros((nrows, ncols), dtype=type)
	for i in range(nrows):
		data[i, :] = input_row(ncols, type, **kwargs)
	return data


K, = inputs(int)
S = input()

if len(S) <= K:
	print(S)
else:
	print(f'{S[:K]}...')


Measured memory_bytes: 27144
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repf(i, j, n) for (int i = (j); i < (n); i++)
#define repr(i, n) for (int i = (n)-1; i >= 0; i--)
int mod = 1e9 + 7;

signed main() {
  int n, m;
  cin >> n >> m;
  vector<int> a(m), dp(n + 2, 0);
  for (auto&& u : a) cin >> u;
  for (auto&& u : a) dp[u] = -1;
  dp[0] = 1;
  rep(i, n) {
    if (dp[i] == -1) continue;
    if (dp[i + 1] != -1) (dp[i + 1] += dp[i]) %= mod;
    if (dp[i + 2] != -1) (dp[i + 2] += dp[i]) %= mod;
  }
  cout << dp[n] << endl;
}


Measured memory_bytes: 1792
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce


sys.setrecursionlimit(2147483647)
INF = 10 ** 20
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007

class Dinic():
    def __init__(self, source, sink):
        self.G = defaultdict(lambda:defaultdict(int))
        self.sink = sink
        self.source = source

    def add_edge(self, u, v, cap):
        self.G[u][v] = cap
        self.G[v][u] = 0

    def bfs(self):
        level = defaultdict(int)
        q = [self.source]
        level[self.source] = 1
        d = 1
        while q:
            if level[self.sink]:
                break
            qq = []
            d += 1
            for u in q:
                for v, cap in self.G[u].items():
                    if cap == 0:
                        continue
                    if level[v]:
                        continue
                    level[v] = d
                    qq += [v]
            q = qq
        self.level = level

    def dfs(self, u, f):
        if u == self.sink:
            return f
        for v, cap in self.iter[u]:
            if cap == 0 or self.level[v] != self.level[u] + 1:
                continue
            d = self.dfs(v, min(f, cap))
            if d:
                self.G[u][v] -= d
                self.G[v][u] += d
                return d
        return 0

    def max_flow(self):
        flow = 0
        while True:
            self.bfs()
            if self.level[self.sink] == 0:
                break
            self.iter = {u: iter(self.G[u].items()) for u in self.G}
            while True:
                f = self.dfs(self.source, INF)
                if f == 0:
                    break
                flow += f
        return flow

n = I()
s = 0
t = n + 1
dinic = Dinic(s, t)
A = LI()
total = 0
for i in range(1, n + 1):
    if A[i - 1] >= 0:
        total += A[i - 1]
        dinic.add_edge(s, i, 0)
        dinic.add_edge(i, t, A[i - 1])
    else:
        dinic.add_edge(s, i, -A[i - 1])
        dinic.add_edge(i, t, 0)
    for j in range(i * 2, n + 1, i):
        dinic.add_edge(i, j, INF)

print(total - dinic.max_flow())



Measured memory_bytes: 83416