akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ull = unsigned long long;
using i64 = int64_t;
using u64 = uint64_t;

#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y

constexpr int64_t MOD = 1'000'000'007LL;

#define INT(NAME) int NAME; cin>>NAME;
#define INT64(NAME) int64_t NAME; cin>>NAME;
#define VECTOR(NAME, TYPE, SIZE) std::vector<TYPE> NAME((SIZE));\
    for(int xxxx_i=0; xxxx_i<SIZE; xxxx_i++) cin>>NAME[xxxx_i];
#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)    

void solve() {
    ull N,M,K; cin>>N>>M>>K;
    vector<ull> A(N), B(M);
    REP(i, N) cin>>A[i];
    REP(i, M) cin>>B[i];

    vector<ull> P(N);
    vector<ull> Q(M);

    partial_sum(A.begin(), A.end(), P.begin());
    partial_sum(B.begin(), B.end(), Q.begin());

    if (P.back() + Q.back() <= K) {
        cout<<N+M<<endl;
        return;
    }
    long ans = distance(
        Q.begin(),
        upper_bound(Q.begin(), Q.end(), K)
    );
    for (int i=P.size()-1; i >= 0; i--) {
        if (K < P[i]) continue;

        auto it = upper_bound(Q.begin(), Q.end(), K-P[i]);
        long d = distance(Q.begin(), it);
        ans = max(ans, i + 1 + d);
    }
    cout<<ans<<endl;
}

int main() {
    solve();
    return 0;
}

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

int main(){
  double a,b,c,d,e,f;
  while(cin >> a >> b >> c >> d >> e >> f){
    double x,y;
    if(0 != a * e - d * b){
      x = (e * c - b * f)  / (a * e - b * d);
      y = (a * f - d * c)  / (a * e - b * d);
    }else{
      x = 0;
      y = 0;
    }
    double x_ = round(x * 1000)/1000;
    double y_ = round(y * 1000)/1000;
    if(x_ > -0.001 && x_ < 0.001) { x_ = 0; }
    if(y_ > -0.001 && y_ < 0.001) { y_ = 0; }
    cout << fixed << setprecision(3) << x_ << " ";
    cout << fixed << setprecision(3) << y_ << endl;
  }
  return 0;
}

Measured memory_bytes: 1292
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

typedef vector<int> vi;

#define PB push_back
#define rep(i,x) for(int i=0;i<(x);++i)
#define rep1(i,x) for(int i=1;i<=(x);++i)
#define all(a) a.begin(),a.end()

int P[1001];

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

	int N, M;
	
	while (cin >> N >> M, N || M) {
		rep1(i, N) cin >> P[i];

		vi A;

		rep(i, N + 1) rep(j, i + 1) if (P[i] + P[j] <= M) A.PB(P[i] + P[j]);

		sort(all(A));

		int ma = 0;

        int l = 0, r = A.size() - 1;

        while (l < r) {
            while (A[l] + A[r] > M) r--;
            ma = max(ma, A[l] + A[r]);
            l++;
        }

		cout << ma << endl;
	}
}

Measured memory_bytes: 5248
from collections import deque
from typing import List, Optional, Tuple


def cycle_detectable_topological_sort(
    graph: List[List[int]], in_degrees: List[int], first_index: int = 0
) -> Tuple[Optional[List[int]], Optional[List[int]]]:
    """Topological sort that uses Kahn's algorithm and detects a loop (DAG or not).
    Returns:
        if the given graph is DAG, a list of sorted vertices and a list of depths of
        each vertex is returned.
        Otherwise, (None, None) is returned.
    """
    V = len(graph) + first_index
    order = []
    depths = [-1] * V  # depths[i] := the length of the longest path to V_i
    for i in range(first_index, V):
        if not in_degrees[i]:
            order.append(i)
            depths[i] = 0

    queue = deque(order)
    while queue:
        u = queue.popleft()
        cur_depth = depths[u]
        for v in graph[u]:
            in_degrees[v] -= 1
            if not in_degrees[v]:
                depths[v] = max(depths[v], cur_depth + 1)
                queue.append(v), order.append(v)
    return (order, depths) if len(order) + first_index == V else (None, None)


def abc139_e():
    N, *A = map(int, open(0).read().split())

    ids = [[-1] * (N + 1) for _ in range(N + 1)]
    cur_id = 0
    for i in range(1, N + 1):
        for j in range(i + 1, N + 1):
            ids[i][j] = ids[j][i] = cur_id
            cur_id += 1

    graph = [[] for _ in range(N * (N - 1) // 2)]
    in_degrees = [0] * (N * (N - 1) // 2)
    for i, a in enumerate(zip(*[iter(A)] * (N - 1)), 1):
        source = -1
        for j in a:
            target = ids[i][j]
            if source != -1:
                graph[source].append(target)
                in_degrees[target] += 1
            source = target

    _, depths = cycle_detectable_topological_sort(graph, in_degrees)
    print(max(depths) + 1 if depths is not None else -1)


if __name__ == "__main__":
    abc139_e()


Measured memory_bytes: 144216
#include<bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define elif else if
#define INF 1000000007
using namespace std;
int n,a,b;
string s;
signed main()
{
	cin>>n>>a>>b;
	if((b-a)%2==0){
		cout<<(b-a)/2;
	}else{
		cout<<min((a+b-1)/2,(n-a+n-b+1)/2);
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define err(args...) {}
#ifdef DEBUG
#include "_debug.cpp"
#endif
using namespace std;
using ll = long long;
using ld = long double;
template <typename T> using lim = numeric_limits<T>;
template <typename T> istream& operator>>(istream& is, vector<T>& a) { for(T& x : a) { is >> x; } return is; }
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<int> a(n);
    cin >> a;
    const int N = 100'000;
    static ll opt[N+1][2];
    for(int i = n - 1; i >= 0; i--) {
        for(bool flipped : {true, false}) {
            if(i == n - 1) {
                opt[i][flipped] = flipped ? -a[i] : a[i];
            } else {
                opt[i][flipped] = max((flipped ? -a[i] : a[i]) + opt[i + 1][false], (flipped ? a[i] : -a[i]) + opt[i + 1][true]);
            }
        }
    }
    cout << opt[0][false] << endl;
    return 0;
}


Measured memory_bytes: 2176
MOD = 1000000007
class ModInt:
    def __init__(self, x):
        self.x = x % MOD

    def __str__(self):
        return str(self.x)

    __repr__ = __str__

    def __add__(self, other):
        return (
            ModInt(self.x + other.x) if isinstance(other, ModInt) else
            ModInt(self.x + other)
        )

    def __sub__(self, other):
        return (
            ModInt(self.x - other.x) if isinstance(other, ModInt) else
            ModInt(self.x - other)
        )

    def __mul__(self, other):
        return (
            ModInt(self.x * other.x) if isinstance(other, ModInt) else
            ModInt(self.x * other)
        )

    def __truediv__(self, other):
        return (
            ModInt(
                self.x * pow(other.x, MOD - 2, MOD)
            ) if isinstance(other, ModInt) else
            ModInt(self.x * pow(other, MOD - 2, MOD))
        )

    def __pow__(self, other):
        return (
            ModInt(pow(self.x, other.x, MOD)) if isinstance(other, ModInt) else
            ModInt(pow(self.x, other, MOD))
        )

    __radd__ = __add__

    def __rsub__(self, other):
        return (
            ModInt(other.x - self.x) if isinstance(other, ModInt) else
            ModInt(other - self.x)
        )

    __rmul__ = __mul__

    def __rtruediv__(self, other):
        return (
            ModInt(
                other.x * pow(self.x, MOD - 2, MOD)
            ) if isinstance(other, ModInt) else
            ModInt(other * pow(self.x, MOD - 2, MOD))
        )

    def __rpow__(self, other):
        return (
            ModInt(pow(other.x, self.x, MOD)) if isinstance(other, ModInt) else
            ModInt(pow(other, self.x, MOD))
        )
    
    def __iadd__(self,other):
        self.x += other.x if isinstance(other, ModInt) else other
        self.x %= MOD
        return self

    def __isub__(self,other):
        self.x += ModInt(MOD - other.x) if isinstance(other, ModInt) else ModInt(MOD - other)
        return self

    def __imul__(self, other):
        self.x *= other.x if isinstance(other, ModInt) else other
        self.x %= MOD
        return self
    
    def factorical(self,n):
        tmp = ModInt(1)
        for i in range(n):
            tmp *= (i+1)
        return tmp
    
    #m:int MOD
    def modinv(self,a,m=MOD):
        b = m
        u = 1
        v = 0
        while(b):
            t = a//b
            a -= t * b
            a,b = b,a
            u -= t * v
            u,v = v,u
        return ModInt(u)

    def comb(self,n,r):
        n = int(n)
        r = int(r)
        if r > n or n < 0 or r < 0:
            return 0
        m = n+1
        nterms = min(r, n-r)
        numerator = ModInt(1)
        denominator = ModInt(1)
        for j in range(1, nterms + 1):
            numerator *= m - j
            denominator *= j
        return numerator * self.modinv(denominator.x)
        
if __name__ == "__main__":
    x,y=map(int,input().split())
    a = ModInt(x)
    b = ModInt(y)
    print(pow(a,b))


Measured memory_bytes: 5632
n, y = map(int, input().split())
for i in range(n + 1):
    for j in range(n - i + 1):
        if i * 10000 + j * 5000 + (n - i - j) * 1000 == y:
            print(i, j, n - i - j)
            exit()
print(-1, -1, -1)

Measured memory_bytes: 3060
/*
  Compete against Yourself.
  Author - Aryan Choudhary (@aryanc403)
*/

#pragma GCC optimize ("Ofast")
#pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize ("-ffloat-store")

#include<iostream>
#include<bits/stdc++.h>
using namespace std;
#define fo(i,n)   for(i=0;i<(n);++i)
#define repA(i,j,n)   for(i=(j);i<=(n);++i)
#define repD(i,j,n)   for(i=(j);i>=(n);--i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define endl "\n"

typedef long long int lli;
typedef long double mytype;
typedef pair<lli,lli> ii;
typedef vector<ii> vii;
typedef vector<lli> vi;

clock_t time_p=clock();
void aryanc403()
{
#ifdef ARYANC403
    time_p=clock()-time_p;
    cerr<<"Time Taken : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";
#endif
}

#ifdef ARYANC403
#include "/home/priank/codes/PastCodes/header.h"
#else
    #define dbg(args...)
#endif

const lli INF = 0xFFFFFFFFFFFFFFFL;

lli seed;
mt19937 rng(seed=chrono::steady_clock::now().time_since_epoch().count());
inline lli rnd(lli l=0,lli r=INF)
{return uniform_int_distribution<lli>(l,r)(rng);}

class CMP
{public:
bool operator()(ii a , ii b) //For min priority_queue .
{    return ! ( a.X < b.X || ( a.X==b.X && a.Y <= b.Y ));   }};

void add( map<lli,lli> &m, lli x,lli cnt=1)
{
    auto jt=m.find(x);
    if(jt==m.end())         m.insert({x,cnt});
    else                    jt->Y+=cnt;
}

void del( map<lli,lli> &m, lli x,lli cnt=1)
{
    auto jt=m.find(x);
    if(jt->Y<=cnt)            m.erase(jt);
    else                      jt->Y-=cnt;
}

bool cmp(const ii &a,const ii &b)
{
    return a.X<b.X||(a.X==b.X&&a.Y<b.Y);
}

const lli mod = 1000000007L;
// const lli maxN = 1000000007L;

    lli T,n,i,j,k,in,cnt,u,v,x,y;
    lli m,r,c,ans;
    vector<string> s;
    vector<vi> dp;
    //priority_queue < ii , vector < ii > , CMP > pq;// min priority_queue .

void dfs(lli x,lli y)
{
    if(x<=0||y<=0||x>n||y>m||dp[x][y]<0||s[x][y]!='.')
        return;
    if(abs(x-r)+abs(y-c)>k)
        return;

    ans=min(ans,dp[x][y]);
    dp[x][y]=-INF;
    dfs(x+1,y);
    dfs(x-1,y);
    dfs(x,y-1);
    dfs(x,y+1);
}

int main(void) {
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    // freopen("txt.in", "r", stdin);
    // freopen("txt.out", "w", stdout);
// cout<<std::fixed<<std::setprecision(35);
// cin>>T;while(T--)
{

    cin>>n>>m>>k;
    s.resize(n+1,"");

    repA(i,1,n)
    {
        cin>>s[i];
        s[i]="."+s[i]+".";
    }

    dp.resize(n+1,vi(m+1,0));

    repA(i,1,n)
    repA(j,1,m)
    {
        lli &c=dp[i][j];
        c=INF;
        c=min(c,i-1);
        c=min(c,j-1);
        c=min(c,n-i);
        c=min(c,m-j);
        c=(c+k-1)/k;
        c++;
    }

    ans=INF;

    repA(i,1,n)
    repA(j,1,m)
    {
        if(s[i][j]!='S')
            continue;
        r=i;c=j;
        s[i][j]='.';
        dfs(i,j);
    }

    cout<<ans<<endl;
}   aryanc403();
    return 0;
}


Measured memory_bytes: 37888
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <cmath>
#include <set>
#include <algorithm>

typedef long long ll;
const ll MOD = 1e9 + 7;
const long long INF = 1LL<<60;
const double PI=3.14159265358979323846;
const int NMAX=100005;
using namespace std;

int main(){
    ios::sync_with_stdio(false);
    int n,q;
    cin >> n;
    vector<int> a(n);
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    cin >> q;
    vector<int> m(q);
    for(int i = 0; i < q; i++){
        cin >> m[i];
    }

    set<ll> ans;
    
    for(ll i = 1; i < 1<<n; i++){
        int sum = 0;
        for(int j = 0; j < n; j++){
            if((i>>j) & 1) sum += a[j];
        }
        ans.insert(sum);
    }

    for(int t = 0; t < q; t++){
        if(ans.find(m[t]) != ans.end()){
            cout << "yes" << endl;
        } else {
            cout << "no" << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 3204
import sys
from heapq import heappush, heappop
from operator import itemgetter

sys.setrecursionlimit(10 ** 7)
rl = sys.stdin.readline


def solve():
    N, Q = map(int, rl().split())
    events = []
    for _ in range(N):
        s, t, x = map(int, rl().split())
        events.append((t - x, 0, x))
        events.append((s - x, 1, x))
    for _ in range(Q):
        d = int(rl())
        events.append((d, 2, -1))
    events.sort(key=itemgetter(0, 1))
    
    pos_set = set()
    pos_hq = []
    ans = []
    for _, com, pos in events:
        if com == 0:
            pos_set.remove(pos)
        elif com == 1:
            pos_set.add(pos)
            heappush(pos_hq, pos)
        else:
            while pos_hq:
                if pos_hq[0] not in pos_set:
                    heappop(pos_hq)
                else:
                    break
            ans.append(pos_hq[0] if pos_hq else -1)
    print(*ans, sep='\n')


if __name__ == '__main__':
    solve()


Measured memory_bytes: 125172
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<set>
#include<string>
#include<stdio.h>
#include<cmath>

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
#define repn(i, n) for(int i = 1; i <= n; i++)
#define all(x) (x).begin(), (x).end()
#define lint long long

bool dp[81][81][80*160+1];

int main(){
    int h,w; cin>>h>>w;
    int a[81][81], b[81][81], c[81][81];
    rep(i, h) rep(j, w){
        cin >> a[i][j];
    }
    rep(i, h) rep(j, w){
        cin >> b[i][j];
        c[i][j] = abs(a[i][j] - b[i][j]);
    }

    int M = 80*(h+w)+1;
    dp[0][0][c[0][0]] = true;
    rep(i, h) rep(j, w) rep(k, M){
        if(!dp[i][j][k]) continue;
        if(i != h-1){
            int p = abs(k - c[i+1][j]);
            int q = k + c[i+1][j];
            dp[i+1][j][p] = true;
            if(q < M) dp[i+1][j][q] = true;
        }
        if(j != w-1){
            int p = abs(k - c[i][j+1]);
            int q = k + c[i][j+1];
            dp[i][j+1][p] = true;
            if(q < M) dp[i][j+1][q] = true;
        }
    }
    rep(k, M){
        if(dp[h-1][w-1][k]){
            cout<<k<<endl;
            return 0;
        }
    }
}

Measured memory_bytes: 81528
#include<iostream>
#include<vector>
#include<cmath>
#include<algorithm>


struct point {
	int x, y, h;
	point(): x{0}, y{0}, h{0} {}
	point(int xv,int yv,int hv) :x{xv}, y{yv}, h{hv} {}
	friend std::istream& operator>>(std::istream&is, point&p) {
		return is >> p.x >> p.y >> p.h;
	}
};

int main() {
	int N;
	int x[105]{}, y[105]{}, h[105]{};

	std::cin >> N;
	
	for (int i{}; i < N; i++) {
		std::cin >> x[i] >> y[i] >> h[i];
	}

	int idx{};
	for (; idx < N; idx++) {
		if (h[idx] != 0)break;
	}

	point core;
	bool find{ false };
	for (int xi{}; xi < 101; xi++) {

		for (int yi{}; yi < 101; yi++) {

			int H = h[idx] + std::abs(xi - x[idx]) + std::abs(yi - y[idx]);//与式を変形。
			if (H == 0)continue;//H is larger than 0.

			bool is_ = true;
			for (int i{}; i < N; i++) {
				if (h[i] != std::max(0, H - std::abs(xi - x[i]) - std::abs(yi - y[i]))) {
					is_  = false;//一つでも正しくh[i]を算出できないならH, Xi, Yiのセットが正しくない。
					break;
				}
			}
			if (is_) {
				std::cout << xi << " " << yi << " " << H << "\n";
				
			}

			//std::cout <<"xyh:"<< xi << " " << yi << " " << H << "\n";
		}

	}

	return 0;

}

auto legacy(){
	int tab[100][100]{ {-1} };

	int N{}; point stan{};

	std::cin >> N;// >> stan;
//	tab[stan.x][stan.y] = 0;
	for (int i{0}; i < N ; i++) {
		point tmp;
		std::cin >> tmp;
		tab[tmp.x][tmp.y] = tmp.h;
	}

	for (int yi{}; yi < 100; yi++) {
		for (int xi{}; xi < 100; xi++) {

		}
	}

	for (const auto&ye : tab) {
		for (const auto &xe : ye) {
			std::cout << xe<<"";
		}std::cout << "\n";
	}

}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <algorithm>
#include <set>
#include <string>
#include <queue>

using namespace std;

#define rep(i, N) for(int (i) = 0; (i) < (N); (i) ++)
typedef long long ll;

vector<pair<ll, ll>> pF;


int main(){
    int N;
    int Z, W;
    cin >> N >> Z >> W;
    vector<int> as(N);
    rep(i, N){
        cin >> as[i];
    }

    int ans = abs(as[N - 1] - W);
    if(N > 1){
        ans = max(abs(as[N - 2] - as[N-1]), abs(as[N-1]- W));
    }
    cout << ans << endl;

    return 0;
}


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

using namespace std;

int main() {
    int a, b;
    cin >> a >> b ;
    if (a <= b) {
        for (int i = 0; i < b; i++)
            cout << a;
        cout << endl;
    }
    else  {
        for (int i = 0; i < a; i++)
            cout << b;
        cout << endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
#include <algorithm>
#define f first
#define s second
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#define ll long long
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define FOR(i, n, x) for(int i = x; i < n; i++)
#define PUT(a, n) FOR(i, n) cin >> a[i]
#define OUT(a, n) FOR(i, n) cout << a[i] << ' '

using namespace std;


int main() {
	fast;
    int n, k; cin >> n >> k;
    int a[n];
    FOR(i, n, 0)cin >> a[i];
    int dp[n + 1] = {};
    FOR(i, min(k + 1, n), 1)
    {
        int minv = 1e9 + 5;
        FOR(j, i, 0)
        {
            minv = min(minv, dp[j] + abs(a[j] - a[i]));
        }
        dp[i] = minv;
    }
    FOR(i, n, k)
    {
        int minv = 1e9 + 5;
        FOR(j, k + 1, 1)
        {
            minv = min(minv, dp[i - j] + abs(a[i - j] - a[i]));
        }
        dp[i] = minv;
    }  
    cout << dp[n - 1];
    return 0;
}


Measured memory_bytes: 1024
// inputに入力データ全体が入る
function Main(input) {
  'use strict'
  const setting = input.trim().split('\n')

  const fruits_sum = setting[0].split(' ')[0] - 0
  const buy_sum = setting[0].split(' ')[1] - 0

  const price_arr = setting[1].split(' ')

  price_arr.sort(function(a,b){
    if( parseInt(a) < parseInt(b) ) return -1;
    if( parseInt(a) > parseInt(b) ) return 1;
    return 0;
  });

  let answer = 0

  for (let i = 0; i < buy_sum; i++) {
    answer += parseInt(price_arr[i])
  }

  console.log(answer)
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 31464
#include <bits/stdc++.h>
using namespace std;
template<class T> ostream& operator<<(ostream &os, vector<T> V) {
os << "[ "; for(auto v : V) os << v << " "; return os << "]";}
template<class L, class R> ostream& operator<<(ostream &os, pair<L,R> P) {
    return os << "(" << P.first << "," << P.second << ")";}

// #define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cout << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...) 1
#endif
typedef long long ll;
typedef double ld;
#define pll pair<ll,ll>
#define pii pair<int, int>
#define pb push_back
#define mp(x, y) make_pair((x), (y))
#define F first
#define S second
#define I insert
#define vi vector<int>
#define vll vector<ll>
#define vpll vector<pll>
#define all(x) (x).begin(), (x).end()
#define sz(x) (ll)(x).size()
   
const ll Mod = 1e9 + 7;
int main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); 
    ll n , x , y ; cin >> n;
    vpll A;
    for(int i = 0 ;i < n ; i++){
        cin >> x >> y;
        A.pb(mp(x , y));
    }
    sort(all(A));
    
    if(n == 1){
        cout << 1 << endl;
        return 0;
    }
    ll cost = 100;
    for(int i = 0 ;i < n; i++){
        
        for(int j = i+1 ; j < n ; j++){
            ll no = 0;
            int x = A[j].F-A[i].F , y = A[j].S - A[i].S; 
            for(int k = 0 ; k < n; k++){
                for(int l = k+1 ; l < n ; l++ ){
                    if( (A[l].F == A[k].F + x) && (A[l].S == A[k].S + y ))
                        no++;
                }
            }
            
            cost = min(cost , n-no);
        }
    }
    cout << cost << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int mxn(1e5 + 10), mxm(4e5 + 10);
const long long modl(998244353);
int nm, n, m, p, t, k, ans, l, r;
int a[mxn], b[mxn], h[mxn];
int main() {
  ios_base::sync_with_stdio(false);
//  freopen("in.txt", "r", stdin);///////////////////////////
//  cin >> nm;
  while (cin >> n) {
//    memset(a, 0, sizeof(a));
    ans = n^1;
    cout << ans;
    cout << endl;////////////////////////
  }
  return 0;
}
////////////////////////////////////////////////////////////////////////////////


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

int main() {
  long long H;
  long long X=1;
  long long ans =0;
  cin >> H;

 

  while(H != 0){
    ans += X;
    H /= 2;
    X *= 2;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3620
#include <iostream>
#include<bits/stdc++.h>
#include<vector>
#define fo(i,n) for(long long i=0;i<n;i++)
#define ll long double
#define inf 999999999999999999
#define pb push_back

#define pi 3.14159265359
#define MOD 1000000007
#define tr(c,it) for(auto it = (c).begin(); it != (c).end(); ++it)
#define fio ios_base::sync_with_stdio(false);cin.tie(0);
using namespace std;
//cerr<< '\n' << "Time elapsed :" << clock() * 1000.0 / CLOCKS_PER_SEC << " ms\n" ;


int32_t main() 
{
    fio
	ll j,i,n,t,b,a,r,c,h,m,maxi,d,x;
	cin>>a>>b>>h>>m;
	cout<<fixed<<setprecision(12);
	if(a>b)
	{
		c=b;
		b=a;
		a=c;
	}
	
	ll angle=abs(((360)/12)*h-(360/60-30.00/60.00)*m);
	angle=min(angle,abs(360-angle));
	// cout<<angle+(30.00/60.00)*m;
	ll base=a*cos((angle*pi)/180);
	ll k=a*sin((angle*pi)/180);
	ll l=b-base;
	// cout<<k<<l<<endl;
	ll dist=sqrt(pow(b-base,2)+pow(a*sin((angle*pi)/180),2));
	cout<<dist;
}




	

		

Measured memory_bytes: 4180
def eat(A,x):
    n = len(A)
    pt = 1
    output = 0
    while pt < n:
        if A[pt-1] + A[pt] > x:
            tmp = A[pt]
            A[pt] = max(0,x-A[pt-1])
            output += (tmp-A[pt])
        pt += 1
    if A[0] + A[1] > x:
        tmp = A[0]
        A[0] = max(0,x-A[1])
        output += (tmp-A[0])
    return output

def main():
    N,x = map(int,input().split())
    a = list(map(int,input().split()))

    ans = eat(a,x)

    print(ans)

if __name__ == "__main__":
    main()


Measured memory_bytes: 14588
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef vector<int> vi;
typedef vector<vi> vii;
#define fi first
#define se second
#define pb push_back
#define forn(i,n) for(int i=0;i<(n);i++)
#define for1(i,n) for(int i=1;i<=n;i++)
#define forr(i,n) for(int i=n;i>=0;i--)
#define all(x) x.begin(), x.end()
#define sz(x) ((int)x.size())
const int MAXN = 1e5 +5;
const LL m = 1e9 + 7;
void fio(){
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}

LL dp[2005][2005], pref[2005][2005];

int main(){
  fio();
  LL s; cin>>s;
  for1(i,s-1){
  	dp[i][0] = 1;
  	if(i>= 3) dp[i][1] = 1;
  	for(int k = 1; k <= (i-3) && k>=0; k++){
  		if(i>=3) dp[i][k+1] = pref[i-3][k];
  	}
    for(int k = 1; k <= i; k++){
  		pref[i][k] = (pref[i-1][k] + dp[i][k])%m;
  	}
  }
  LL su = 0;

  
  if(s <= 2) cout<<0<<endl;
  else{
  	for(int i = 1; i <= (s-3); i++)
  	su = (su + pref[s-3][i])%m;
  	cout<<(su + 1)%m<<endl;
  }
  return 0;
}

Measured memory_bytes: 48688
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define all(a) (a).begin(), (a).end()
typedef long long ll;
#define INF 1e9
typedef pair<int, int> P;

/* 　"assert"    assert(A：条件式)で　Aが真なら処理は続行、偽ならプログラムを終了する　*/

/*　　ラムダ式　　 auto a = [キャプチャ](パラメータ){ 処理 }  */

/* string型　メンバ関数　substr()    replace()  */

int main(){
    int n; cin >> n;
    map<string, int> m;
    
    rep(i,n){
        string s; cin >> s;
        m[s]++;
    }
    int max_num = 0;
    for(auto i : m){
        max_num = max(max_num, i.second);
    }
    vector<string> ans;
    for(auto i : m){
        if (i.second == max_num) {
            ans.push_back(i.first);
        }
    }
    sort(ans.begin(), ans.end());
    for(auto i : ans){
        cout << i << endl;
    }
}


Measured memory_bytes: 26868
# sys.stdin.readline
import sys

input = sys.stdin.readline


class AtCoder:
    def main(self):
        abc = list(map(int, input().split()))

        M = max(abc)
        if 3 * M % 2 == sum(abc) % 2:
            print((3 * M - sum(abc)) // 2)
        else:
            print((3 * (M + 1) - sum(abc)) // 2)


# Run main
if __name__ == '__main__':
    AtCoder().main()


Measured memory_bytes: 38384
s = input()
q = int(input())

forward = ""
reverse = ""

rev = 0
for _ in range(q):
    query = list(input().split())
    t = int(query[0])
    if t == 1:
        rev = rev^1
    else:
        f = int(query[1])
        c = query[2]
        if f == 1:
            if rev == 0:
                forward += c
            else:
                reverse += c
        else:
            if rev == 0:
                reverse += c
            else:
                forward += c

ans = ""
if rev == 0:
    for i in reversed(range(len(forward))):
        ans += forward[i]
    ans += s
    ans += reverse
else:
    for i in reversed(range(len(reverse))):
        ans += reverse[i]
    for i in reversed(range(len(s))):
        ans += s[i]
    ans += forward

print(ans)

Measured memory_bytes: 4444
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[n];
		for(int i = 0 ; i < n ; i++){
			int k = sc.nextInt();
			int p = sc.nextInt();
			if(k % p == 0){
				a[i] = p;
			} else {
				a[i] = k % p;
			}
		}
		for(int j : a){
			System.out.println(j);
		}
		sc.close();
	}

}

Measured memory_bytes: 20356
#include<iostream>
#include<algorithm>
#include<queue>
#include<vector>
#include<cmath>

using namespace std;

int answer;



int n;
int a[100005];
vector<int> V;
int b[100005];

int solver(int a[]){
  for(int i = 0; i < n; ++i){
    V.push_back(a[i]);
  }
  sort(V.begin(), V.end());
  int cnt = 0;
  for(int i = 0; i < n; ++i){
    if(V[i] % V[0] == 0){
      cnt++;
    }else{
      a[i] = V[i] % V[0];
    }
  }
  if(cnt == n){
    return V[0];
  }else{
    return solver(a);
  }
}

int main(){
  cin >> n;
  for(int i = 0; i < n; ++i){
    cin >> a[i];
  }
  cout << solver(a) << endl;
  
  
}

Measured memory_bytes: 1784
#include<stdio.h>

int search(int A[], int n, int key) {
    int i = 0;
    A[n] = key;  // 番兵の設置（条件式を少なくする）
    while (A[i] != key) i++;  // 数列Aの任意の場所がkeyと異なる場合、ループし続ける（番兵で必ず止まる）
    return i != n;  // もし番兵以外で止まったなら真、番兵で止まったなら偽を返す
}


int main() {
    int i, n, A[10000+1], q, key, sum = 0;

    scanf("%d", &n);
    for (i = 0; i < n; i++) scanf("%d", &A[i]);  // n個の数を入力

    scanf("%d", &q);
    for (i = 0; i < q; i++) {
        scanf("%d", &key);
        if (search(A, n, key)) sum++;
    }
    printf("%d\n", sum);

    return 0;
}


Measured memory_bytes: 2708
#include <iostream>
#include <algorithm>

int main(){
    long long q,h,s,d;
    std::cin>>q>>h>>s>>d;
    long long b1,b2;
    b1=std::min({q*4,h*2,s});
    b2=std::min(b1*2,d);
    long long n;
    std::cin>>n;
    std::cout<<b2*(n/2)+b1*(n%2)<<std::endl;
    return 0;
}

Measured memory_bytes: 256
import sys

input = sys.stdin.readline


def main():
    N, M = [int(x) for x in input().split()]
    AB = [[int(x) for x in input().split()] for _ in range(M)]

    AB.sort()

    ans = 1
    right = AB[0][1]
    left = AB[0][0]
    for a, b in AB[1:]:
        if a >= right:
            ans += 1
            right = b
            left = a
        else:
            left = max(left, a)
            right = min(right, b)

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 57948
import math
K = int(input())
N = 0
 
for a in range(1,K+1):
    for b in range(a,K+1):
        for c in range(b,K+1):
            g = math.gcd(math.gcd(a,b),c)
            if(a != b or a != c):
                if(a != b and a != c and b != c):
                    g *= 6
                else:
                    g *= 3
            N += g
 
print(N)

Measured memory_bytes: 9152
S = input()
ans = 0
now = 0
for s in S:
    if s == 'A' or s == 'C' or s == 'G' or s == 'T':
        now += 1
    else:
        if ans < now:
            ans = now
        now = 0
if ans < now:
    ans = now
print(ans)


Measured memory_bytes: 2940
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <cmath>   
#include<cctype>
#include<string>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include <deque>
#include <utility> 

#define rep(i,m,n) for(int i = m;i < n;++i)
using namespace std;
using ll = long long;
using R = double;
const ll inf = 1LL << 50;
const int MOD = 1e9 + 7;



int main() {	
	int n;
	cin >> n;
	vector<int>a(n);
	vector<int>b(n);
	vector<int>c(n);

	rep(i, 0, n) {
		cin >> a[i];
	}
	rep(i, 0, n) {
		cin >> b[i];
	}
	rep(i, 0, n) {
		cin >> c[i];
	}

	sort(a.begin(),a.end());
	sort(c.begin(),c.end());

	ll ans = 0;
	rep(i, 0, n) {
		ll anum = lower_bound(a.begin(),a.end(),b[i])-a.begin();
		ll cnum = n-(upper_bound(c.begin(), c.end(), b[i]) - c.begin());
		ans += anum * cnum;
	}

	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 1408
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;


int main(){
    int n;
    cin >> n;
    string s, t;
    cin >> s >> t;
    for(int i=0; i<n; i++){
        cout << s[i] << t[i];
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
//const ll MOD = 1e9 + 7;
const ll MOD = 998244353;
//const ll MOD = ;
ll mod(ll A, ll M) {return (A % M + M) % M;}
const ll INF = 1LL << 60;
template<class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
ll divceil(ll A, ll B) {return (A + (B - 1)) / B;}
ll myctoi(char C) {return C - '0';}
char myitoc(ll N) {return '0' + N;}
#define FINALANS(A) {cout << (A) << '\n'; exit(0);}

int main()
{
  ll N, K;
  cin >> N >> K;
  vector<ll> A(N), B(N), C(N);
  for (ll i = 0; i < N; i++)
  {
    C.at(i) = K + 2 * N + i;
  }

  ll a = K;
  for (ll i = 0; i < divceil(N, 2); i++)
  {
    A.at(i) = a;
    a += 2;
  }
  a = K + 1;
  for (ll i = divceil(N, 2); i < N; i++)
  {
    A.at(i) = a;
    a += 2;
  }

  ll b = K + N;
  for (ll i = divceil(N, 2) - 1; i >= 0; i--)
  {
    B.at(i) = b;
    b++;
  }
  for (ll i = N - 1; i >= divceil(N, 2); i--)
  {
    B.at(i) = b;
    b++;
  }

  for (ll i = 0; i < N; i++)
  {
    if (A.at(i) + B.at(i) > C.at(i))
      FINALANS(-1);
  }

  for (ll i = 0; i < N; i++)
  {
    cout << A.at(i) << " " << B.at(i) << " " << C.at(i) << endl;
  }
}

Measured memory_bytes: 4608
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate, product # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
import math
import bisect
import heapq
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入g
#
# インデックス系
# int min_y = max(0, i - 2), max_y = min(h - 1, i + 2);
# int min_x = max(0, j - 2), max_x = min(w - 1, j + 2);
#
#
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
#mod = 998244353
INF = float('inf')
from sys import stdin
readline = stdin.readline
def readInts():
  return list(map(int,readline().split()))
def readTuples():
    return tuple(map(int,readline().split()))
def I():
    return int(readline())
n = I()
s = input()
C = Counter(s)
w,r = 0,0
for k,v in C.items():
    if k == 'W':
        w += v
    else:
        r += v
p = 'R' * r + 'W' * w
ans = 0
for i in range(n):
    if p[i] == s[i]:
        pass
    else:
        ans += 1
print(ans//2)


Measured memory_bytes: 10748
#include<iostream>
#include<string>
using namespace std;
int main(){
int a,b,c;
cin>>a>>b>>c;
b=a-b;
c=a-c;
if(b<0){
	b=b*(-1);
}
if(c<0){
	c=c*(-1);
}
if(b<c){
cout<<"A"<<endl;
}
if(b>c){
cout<<"B"<<endl;
}
}

Measured memory_bytes: 256
//ΔAGC029B
#include<iostream>
#include<cstdio>
#include<fstream>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<bitset>
#include<cmath>
#include<cstring>
#include<cstdlib>
using namespace std;
typedef long long LL;
typedef double DB;
int f(int x){
	int i;
	for(i=2;i<=x;i=i+i);
	return i-x;
}
multiset<int> S;
multiset<int>::iterator it;
int main()
{
	int n,x;
	scanf("%d",&n);
	while(n--){
		scanf("%d",&x);
		S.insert(x);
	}
	n=0;
	while(!S.empty()){
		it=S.end();
		it--;
		x=*it;
		S.erase(it);
		x=f(x);
		it=S.lower_bound(x);
		if(it!=S.end()&&(*it)==x)
			S.erase(it),n++;
	}
	cout<<n;
	return 0;
}

Measured memory_bytes: 9600
/*
 *  I wish I could travel by the road that crosses baby's mind,
 *  and out beyond all bounds;
 *  Where messengers run errands for no cause
 *  between the kingdoms of kings of no history;
 *  Where Reason makes kites of her laws and flies them,
 *  and Truth sets Fact free from its fetters.
 *                                           Rabindranath Tagore
 */

#include <bits/stdc++.h>
using namespace std;

#ifndef ORZ_EVERYBODY_BUT_ME
#define ORZ_EVERYBODY_BUT_ME
#endif

const size_t MAX_N = 100 + 5;

int a[MAX_N];

int main() {
    int n, res = 0;
    cin >> n;
    for (int i = 0; i < n; ++i)
        cin >> a[i];
    for (int i = 0; i < n; ) {
        int cnt = 0, st = a[i];
        for (; i < n && a[i] == st; ++i, ++cnt) {}
        res += cnt / 2;
    }
    cout << res << '\n';
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
using ll = long long;
using pll = pair<ll, ll>;
#define all(x) (x).begin(), (x).end()
#define call(x) (x).cbegin(), (x).cend()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
#define sz(x) ((x).size())
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define rep(i, a, b) for(ll i = ll(a); i < ll(b); i++)
const double PI = acos(-1);
const int mod = 1e9+7;
const long long INF = (1LL << 60);
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
ll gcd(ll a,ll b){return b ? gcd(b,a%b) : a;}
ll lcm(ll a,ll b){return a / gcd(a,b) * b;}
ll stringcount(string s, char c){return count(s.cbegin(), s.cend(), c);}
bool isInteger(double x){return floor(x) == x;}
ll ceil(ll a, ll b){return ((a)+(b)-1)/b;}
template<class T> inline bool chmax(T &a, const T &b){ if(a < b){ a=b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b){ if(a > b){ a=b; return 1; } return 0; }

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

  ll a, b, c, k;
  cin >> a >> b >> c >> k;

  if(k < a){
    cout << k << endl;
  }else if(k >= a && k <= a+b){
    cout << a << endl;
  }else if(k > a+b){
    cout << a - (k - a - b) << endl;
  }
  return 0;
}

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

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

  if (abs(a - c) <= d || (abs(a - b <= d && abs(b - c) <= d)))
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

Measured memory_bytes: 256
import bisect
n,m=map(int,input().split())
l=[]
for i in range(1,int(m**(1/2))+1):
    if m%i==0:
        l.append(i)
        if i!=m//i:
            l.append(m//i)
l.sort()
z=bisect.bisect_left(l,n)
print(m//l[z])

Measured memory_bytes: 38640
#pragma comment (linker, "/STACK:256000000")
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <numeric>
#include <queue>
#include <map> 
#include <set>
#include <string>
#include <functional>
#include <list>
#include <random>
#include <time.h>
#include <iomanip>
#include <assert.h>
#include <numeric>
#define int long long
#define double long double
#define mod 1000000007
#define MAXN (int)1e+5 * 2+1
#define LL_MAX 9223372036854775807	//ない環境用
#define LL_HALFMAX 9223372036854775807 / 2	//ない環境用
#define MIN -(9223372036854775807 / 2)
#define INF 9223372036854775807 / 2
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)


using namespace std;

std::mt19937 mt((int)time(0));

int dx[4] = { 0, 1, 0, -1 }; // x軸方向への変位
int dy[4] = { 1, 0, -1, 0 }; // y軸方向への変位

class food {
public:
	int valueA;
	int valueB;
	int index;
	food(int va,int vb, int i) {
		valueA = va;
		valueB = vb;
		index = i;
	}
	bool operator<(const food &another) const
	{
		/*
		if (value != another.value) {
			return value < another.value;
		}
		return diff < another.diff;
		*/
		return valueA+valueB < another.valueA+another.valueB;
	};
};

bool visited[100001];
vector<food> Afo, Bfo;
int a_pos, b_pos, a_sum, b_sum, ate;


signed main() {
	//小文字repは初期値指定なし #やむどぅめも
	int N;
	cin >> N;
	vector<int>A, B, AB;
	vector<food> ABfo;

	rep(i, N) {
		int ta = 0, tb=0;
		cin >> ta >> tb;
		A.push_back(ta);
		B.push_back(tb);

		food f(ta, tb, i);
		ABfo.push_back(f);



	}
	sort(ALLOF(ABfo));
	reverse(ALLOF(ABfo));
	int a = 0, b = 0;

	for (int i = 0; i < N; i++) {
		if (i % 2 == 0) {
			a += ABfo[i].valueA;
		}
		else {
			b += ABfo[i].valueB;
		}
	}
	cout << a - b << "\n";


	return 0;
}

Measured memory_bytes: 6312
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(n);i++)
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const int MAX = 1000000;
const int INF = 1e9;
const double pi=acos(-1);
using namespace std;

int main(){
  string s,t;
  cin >> s >> t;;
  rep(i,s.size()){
    string u=s.substr(i)+s.substr(0,i);
    if(u==t){
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
  
  return 0;
}

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

int main() {
	
	int A;
	int B;
	int i = 0;
	int C = 0;
	int ans = 0;

	scanf("%d %d", &A, &B);

	while (ans == 0)
	{
		if (A * i-(i - 1) >= B) {
			ans = i;
			break;
		}
		else {
			i += 1;
		}
	}
	
	printf("%d", ans);

	return 0;
}



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

using namespace std;
using ll=long long int;
string text;
string t1,t2;
bool ispalin(string a) {
    int n=a.size();
    for(int i=0;i<n/2;i++) {
        if(a[i]!=a[n-i-1]) return false;
    }
    return true;
}

int main () {
    cin>>text;
    bool ans=true;
    int n=text.size();
    if(n%2==0) ans=false;
    else {
        for(int i=0;i<(n-1)/2;i++) {
            t1+=text[i];
        }
        for(int i=(n+1)/2;i<n;i++) {
            t2+=text[i];
        }
        if(!ispalin(t1) or !ispalin(t2) or !ispalin(text)) ans=false;
    }
    if(ans) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

Measured memory_bytes: 256
#pragma GCC optimize("trapv")
//#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
using namespace std;
using ll = long long;
using vi = vector<ll>;
using pi = pair<ll, ll>;
const int maxn = 3555;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	ll n, t, c;
	cin >> n;
	if(n&1) return cout << 0, 0;
	t = 0;
	c = 0;
	for(ll i = 2; i <= n; i<<=1) {
		t+=n/i;
	}
	n/=2;
	for(ll i = 5; i <= n; i*=5) {
		c+=n/i;
		if(i>n/5) break;
	}
	cout << min(c, t) << "\n";
}


Measured memory_bytes: 256
#include<cstdio>
#define maxn 1000005
int l,n,m,id[maxn],u[maxn],v[maxn],w[maxn];
void Add(int u1,int v1,int w1)
{
	m++;
	u[m]=id[u1],v[m]=id[v1],w[m]=w1;
}
void dfs(int x)
{
	if(id[x]) return;
	if(!x) { id[x]=++n; return; }
	if(x&1)
	{
		dfs(x/2);
		if(!id[x]) id[x]=++n;
		Add(x/2,x,x/2+1);
		Add(x/2,x,0);
	}
	else
	{
		dfs(x/2-1);
		if(!id[x]) id[x]=++n;
		Add(x/2-1,x,x/2);
		Add(x/2-1,x,0);
		Add(0,x,x);
	}
}
int main()
{
	scanf("%d",&l); l--;
	dfs(l);
	printf("%d %d\n",n,m);
	for(int i=1;i<=m;i++) printf("%d %d %d\n",u[i],v[i],w[i]);
}

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

using namespace std;
typedef long long ll;
const int mod=1000000007;
const int maxn=100007;

int main()
{
    int n;
    cin>>n;
    int r=n%100;
    n=n/100;
    if(n>0&&n<=12)
    {
        if(r>0&&r<=12)
            cout<<"AMBIGUOUS"<<endl;
        else
            cout<<"MMYY"<<endl;
    }
    else
    {
        if(r>0&&r<=12)
            cout<<"YYMM"<<endl;
        else
            cout<<"NA"<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
const long long INF = 1LL << 60;

long power(long a, long b) {
    return b ? power(a*a%MOD, b/2) * (b%2?a:1)%MOD:1;
}

long perm(int N, int K) {
    long x = 1;
    for(int i = 1; i <= K; i++) x = x * (N-i+1) % MOD;
    return x % MOD;
}

long comb(int N,int K) {
    long x = 1, y = 1;
    for(int i = 1; i <= K; i++) {
        x = x * (N-i+1) % MOD;
        y = y * i % MOD;
    }
    return x * power(y, MOD-2) % MOD;
}

bool isprime(int n) {
    if(n < 2) return false;
    for(int i = 2; i*i <= n; ++i) {
        if (n % i ==  0) return false;
    }
    return true;
}

void dfs(const vector<vector<int> > &G, int v, vector<int> &seen) {
    seen[v] = true;

    for(int next_v : G[v]) {
        if(seen[next_v]) continue;
        dfs(G, next_v, seen);
    }
}

void yes() { cout << "Yes" << endl;}
void no() { cout << "No" << endl;}

int main() {
  int k; cin >> k;
  string s, ans = ""; cin >> s;
  if (s.size() <= k) {
    cout << s << endl;
  } else {
    for (int i = 0; i < k; i++) {
      ans += s.at(i);
    }
    ans += "...";
    cout << ans << endl;
  }
	
}

Measured memory_bytes: 3636
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
#include <stack>
#include <set>
#include <bitset>
#include <functional>
#include <cassert>
using namespace std;
#define fast_io ios_base::sync_with_stdio (false) ; cin.tie(0) ; cout.tie(0) ;
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define MOD (long long int)(1e9+7)
#define INF (int)(1e9)
#define LINF (long long int)(1e18)
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
#define all(v) v.begin(), v.end()
typedef pair<int, int> Pii;
typedef pair<ll, ll> Pll;

ll mpow(ll a, ll b){
  if(b==0) return 1;
  else if(b%2==0){ll memo = mpow(a,b/2); return memo*memo%MOD;}
  else return mpow(a,b-1) * a % MOD;
}
ll lpow(ll a, ll b){
  if(b==0) return 1;
  else if(b%2==0){ll memo = lpow(a,b/2); return memo*memo;}
  else return lpow(a,b-1) * a;
}
ll gcd(ll a, ll b){
  if(b==0) return a;
  else return gcd(b, a%b);
}
vector<ll> kaijo_memo;
ll kaijo(ll n){
  if(kaijo_memo.size() > n) return kaijo_memo[n];
  if(kaijo_memo.size() == 0) kaijo_memo.push_back(1);
  while(kaijo_memo.size() <= n) kaijo_memo.push_back(kaijo_memo[kaijo_memo.size()-1] * kaijo_memo.size() % MOD);
  return kaijo_memo[n];
}
vector<ll> gyaku_kaijo_memo;
ll gyaku_kaijo(ll n){
  if(gyaku_kaijo_memo.size() > n) return gyaku_kaijo_memo[n];
  if(gyaku_kaijo_memo.size() == 0) gyaku_kaijo_memo.push_back(1);
  while(gyaku_kaijo_memo.size() <= n) gyaku_kaijo_memo.push_back(gyaku_kaijo_memo[gyaku_kaijo_memo.size()-1] * mpow(gyaku_kaijo_memo.size(), MOD-2) % MOD);
  return gyaku_kaijo_memo[n];
}

ll nCr(ll n, ll r){
  if(n == r) return 1;//0個の丸と-1個の棒みたいな時に時に効く？不安.
  if(n < r || r < 0) return 0;
  ll ret = 1;
  if(n <= 1e7){
    ret *= kaijo(n); ret %= MOD;
    ret *= gyaku_kaijo(r); ret %= MOD;
    ret *= gyaku_kaijo(n-r); ret %= MOD;
  }else{
    rep(i,r){
      ret *= n-i; ret %= MOD;
      ret *= mpow(r-i, MOD-2); ret %= MOD;
    }
  }
  return ret;
}

/*std::mt19937 mt{ std::random_device{}() };

std::uniform_int_distribution<int> dist(1, 6);
dist(mt);

while(1){
	val;
	cout << val << endl;
	sol1 = solver1();
	sol2 = solver2();
	if(sol1==sol2){
	cout << "OK" << endl;
	}else{
	cout << "NG" << endl;
	cout << sol1 << endl;
	cout << sol2 << endl;
	break;
	}
}
*/

int main(void){
  fast_io
  cout<<fixed<<setprecision(15);
  int n;
  cin >> n;
  vector<ll> as(n);
  vector<ll> bs(n);
  rep(i,n){
	  cin >> as[i];
  }
  bs[0] = as[0];
  reps(i,n-1){
	  bs[i] = (bs[i-1] + as[i])%MOD;
  }
  ll ans = 0;
  for(int i=n-1;i>0;i--){
	  ans = (ans +(as[i]*bs[i-1])%MOD)%MOD;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 6368
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#include<bits/stdc++.h>
using namespace std;
//using namespace __gnu_pbds;
#define ll long long
#define M 1000000007LL
#define rep(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define sep(i,a,b) for(ll i=(ll)a;i>=(ll)b;i--)
#define mll map<ll,ll>
#define vl vector<ll>
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define sz(v) ((ll)v.size())
#define all(a) a.begin(),a.end()
#define F first
#define S second
#define pii pair<ll,ll> 
#define mod 1000000007
#define MAXN 300002
ll arr[100002];
ll ans=0;
vector<ll>v;
void f(ll i,ll k,ll ind,ll an,ll su)
{

if(k==0 and i<v.size()) return;
  if(i==v.size() and k) return;
  if(i==v.size()and k==0) {ans=max(ans,an);
    return;}
  ll btti=(an >> (ind - 1)) & 1;
  if(btti==0) return;

  f(i+1,k-1,ind,(an&(su+v[i])),0);
  
  f(i+1,k,ind,an,su+v[i]);
}
int main() {
       ll t;
       ios::sync_with_stdio(0);
       cin.tie(0);
       cout.tie(0);
      ll n;
      cin>>n;
      ll mn=0,ans=0;

      for(ll i=0;i<n;i++)
      {
        ll x;
        cin>>x;
       // cout<<x<<" "<<mn<<endl;
        if(x>=mn)
          ans++;
        mn=max(mn,x);
      }
      cout<<ans;
       return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <cstdlib>
#include <set>
#include <utility>
#include <climits>
#include <cstdio>
#include <cmath>
#include <queue>
#include <stack>

#define ll long long
#define ull unsigned long long
using namespace std;

const int mod = 1e9 + 7;

ll fexp(ll base, ll p) {
	ll res = 1;
	while (p) {
		if (p & 1) res = res * base % mod;
		
		base = base * base % mod;
		p >>= 1;
	}
	return res;
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	
	int n, k;
	cin >> n >> k;
	ll cnt[k + 1]{};
	cnt[k] = 1;
	ll res = k;
	for (int i = k - 1; i > 0; --i) {
		cnt[i] = fexp(k / i, n);
		for (int j = 2 * i; j <= k; j += i) {
			cnt[i] -= cnt[j];
		}
		cnt[i] %= mod;
		res += cnt[i] * i;
	}
	cout << (res % mod + mod) % mod;
}

Measured memory_bytes: 4348