akhauriyash/Code-Regression huggingface dataset:
/*input
3
1 1
2 4
3 2
*/

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

int main() {
    int n;
    cin >> n;
    vector<int> a(n), b(n);
    rep(i, n) {
        int x, y;
        cin >> x >> y;
        a[i] = x+y;
        b[i] = x-y;
    }
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    ll ans = max(a[n-1]-a[0], b[n-1]-b[0]);
    cout << ans << endl;
}

Measured memory_bytes: 4764
#include <bits/stdc++.h>
#define REP(i, n) for (int i=0, i##_limit=(n); i<i##_limit; ++i)
#define FOR(i, a, b) for (int i=(a), i##_limit=(b); i<i##_limit; ++i)
#define pb push_back
#define mp make_pair
using namespace std;
using ll = long long;
using pi = pair<int, int>;

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

    string week[] = {
        "SUN",
        "MON",
        "TUE",
        "WED",
        "THU",
        "FRI",
        "SAT"
    };

    int i = -1;
    for (i=0; i<7; ++i) if (!S.compare(week[i])) break;

    cout << (7-i) << endl;
    return 0;
}

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

int main(void)
{
    string s;

    cin >> s;
    int count = 0;
    int ct = 0;
    int len = s.length();

    for (int i = 0 ; i < len ; i++){
        if ( (s[i] == 'A') || (s[i] == 'C') || (s[i] == 'G') || (s[i] == 'T') ) {
            ct++;

        }
        else {
            if (count < ct) count = ct;
            ct = 0;
        }
    }
    if (count < ct) count = ct;
  
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
long long n,a[200000],b[200000],ret;
int main(){
	cin>>n;for(int i=0;i<n;i++)cin>>a[i]>>b[i];
	for(int i=n-1;i>=0;i--){
		a[i]+=ret;
		long long p=b[i]-(a[i]%b[i]);if(p==b[i])p=0;
		ret+=p;
	}
	cout<<ret<<endl;
	return 0;
}


Measured memory_bytes: 1920
#include <bits/stdc++.h>
using namespace std;
#pragma region Macros
typedef long long ll;
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(x) (x).begin(),(x).end()
const long long MOD=1e9+7;
// const long long MOD=998244353;
const int INF=1e9;
const long long IINF=1e18;
const int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
const char dir[4]={'D','R','U','L'};
#define LOCAL

template<typename T>
istream &operator>>(istream &is,vector<T> &v){
    for (T &x:v) is >> x;
    return is;
}
template<typename T>
ostream &operator<<(ostream &os,const vector<T> &v){
    for (int i=0;i<v.size();++i){
        os << v[i] << (i+1==v.size()?"": " ");
    }
    return os;
}
template<typename T,typename U>
ostream &operator<<(ostream &os,const pair<T,U> &p){
    cout << '(' << p.first << ',' << p.second << ')';
    return os;
}
template<typename T,typename U>
ostream &operator<<(ostream &os,const map<T,U> &m){
    os << '{';
    for (auto itr=m.begin();itr!=m.end();++itr){
        os << '(' << itr->first << ',' << itr->second << ')';
        if (++itr!=m.end()) os << ',';
        --itr;
    }
    os << '}';
    return os;
}
template<typename T>
ostream &operator<<(ostream &os,const set<T> &s){
    os << '{';
    for (auto itr=s.begin();itr!=s.end();++itr){
        os << *itr;
        if (++itr!=s.end()) os << ',';
        --itr;
    }
    os << '}';
    return os;
}

void debug_out(){cerr << '\n';}
template<class Head,class... Tail>
void debug_out(Head&& head,Tail&&... tail){
    cerr << head;
    if (sizeof...(Tail)>0) cerr << ", ";
    debug_out(move(tail)...);
}
#ifdef LOCAL
#define debug(...) cerr << " ";\
cerr << #__VA_ARGS__ << " :[" << __LINE__ << ":" << __FUNCTION__ << "]" << '\n';\
cerr << " ";\
debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

template<typename T> T gcd(T x,T y){return y!=0?gcd(y,x%y):x;}
template<typename T> T lcm(T x,T y){return x/gcd(x,y)*y;}

template<class T1,class T2> inline bool chmin(T1 &a,T2 b){
    if (a>b){a=b; return true;} return false;
}
template<class T1,class T2> inline bool chmax(T1 &a,T2 b){
    if (a<b){a=b; return true;} return false;
}
#pragma endregion

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    vector<ll> a(N); cin >> a;
    ll whole=0;
    for (int i=0;i<N;++i) whole^=a[i];
    vector<int> ans(N);
    for (int i=0;i<N;++i) ans[i]=whole^a[i];
    cout << ans << '\n';
}

Measured memory_bytes: 5484
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
  string str; cin>>str; ll k=0;
  for(ll i=0;str[i]!='\0';i++){
    k+=str[i]-'0';
  }
  if(k%9==0)cout<<"Yes";
  else cout<<"No";
  cout<<endl;
}


Measured memory_bytes: 3752
#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
    int g[6][2]={{1,2},{10,3},{1,10},{4,5},{5,2},{2,1}};
    char str[128];
    while(scanf("%s",str),str[0]!='#'){
        int pos=0;
        bool flag=false;
        for(int i=0;str[i];i++){
            pos=g[pos][str[i]-'0'];
            if(pos==10){
                flag=true;
                break;
            }
        }
        if(flag)puts("No");
        else puts(pos==5?"Yes":"No");
    }
    return 0;
}

Measured memory_bytes: 948
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define int long long
#define ll long long
#define INF LLONG_MAX/3
#define eps LDBL_EPSILON
#define moder 1000000007
#define pie 3.141592653589793238462643383279
#define P std::pair<int,int>
#define prique priority_queue
using namespace std;
int n,a,b,c,d;
signed main(){
	cin>>n>>a>>b>>c>>d;
	rep(i,n){
		if(c*(n-1-i)-d*i<=b-a&&b-a<=-c*i+(n-1-i)*d){
			puts("YES");
			return 0;
		}
	}
	puts("NO");
    return 0;
}

Measured memory_bytes: 256
<?php

fscanf(STDIN, "%d", $n);
$h_arr = explode(' ', trim(fgets(STDIN)));

$count = 0;
foreach ($h_arr as $i => $h) {
    $viewable = true;
    for ($j = 0; $j < $i; ++$j) {
        if ($h < $h_arr[$j]) {
            $viewable = false;
        }
    }

    $count += $viewable ? 1 : 0;
}

echo $count;


Measured memory_bytes: 4728
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pii pair<int, int>
#define ff first
#define ss second

signed main() {

    int n;
    cin >> n;
    int a[n];
    for(int i = 0; i < n; i++)
        cin >> a[i];

    bool can = true;
    for(int i = 1; i < n; i++)
        if(a[i] > a[i - 1])
            a[i]--;

    //for(int it : a) cout << it << " "; cout << endl;

    for(int i = 1; i < n; i++)
        if(a[i] < a[i - 1])
            can = false;

    cout << (can == 1 ?"Yes" :"No");

    return 0;
}


Measured memory_bytes: 1024
// 見せてやるぜ、奇跡ってやつをよぉ……
#include <iostream>
#include <array>
#include <algorithm>
#include <vector>
#include <set>
#include <unordered_set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <numeric>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
#include <functional>
#include <cassert>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
#define ALL(v) v.begin(),v.end()
template < class T > inline bool chmax(T& a, T b) {if (a < b) { a=b; return true; } return false; }
template < class T > inline bool chmin(T& a, T b) {if (a > b) { a=b; return true; } return false; }
#define DEBUG_VLL(vec) REP(sz, vec.size()) cerr<<vec[sz]<<(sz==vec.size()-1?'\n':' ');

const ll MOD = 1000000007;
const ll HIGHINF = (ll)1e18;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, m;
    cin >> n >> m;
    vll l(m), r(m), c(m);
    REP(i, m) {
        cin >> l[i] >> r[i] >> c[i];
        l[i]--, r[i]--;
    }

    V< V< P<ll, ll> > > edges(n);
    rep(i, 1, n) edges[i].emplace_back(i - 1, 0);

    REP(i, m) edges[l[i]].emplace_back(r[i], c[i]);

    vll d(n, HIGHINF);
    d[0] = 0;
    priority_queue< P<ll, ll> > pq;
    pq.emplace(0, 0);
    while (!pq.empty()) {
        P<ll, ll> q = pq.top(); pq.pop();
        for (P<ll, ll> e: edges[q.second]) {
            if (d[e.first] > d[q.second] + e.second) {
                d[e.first] = d[q.second] + e.second;
                pq.emplace(-d[e.first], e.first);
            }
        }
    }

    if (d[n - 1] == HIGHINF) cout << -1 << '\n';
    else cout << d[n - 1] << '\n';
    return 0;
}


Measured memory_bytes: 12408
#include <bits/stdc++.h>
 
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;
 
#define pb push_back 
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second 
#define debug(x)  do{cerr<<#x<<": "<<x<<"\n";}while(0)
#define debugv(x) do{cerr<<#x<<": ";for(auto&e: (x))cerr<<e<<" ";cerr<<"\n";}while(0)
#define fori(i, n) for (int i = 0; i < (int)(n); ++i)
#define forn(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n); i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
#define RETURN(x) do{cout << x << '\n'; return 0;}while(0)
#define FIRSTWIN do{cout << "Monocarp\n"; return 0;}while(0)
#define SECONDWIN do{cout << "Bicarp\n"; return 0;}while(0)
 
const int MAXN = 1e5+4;
const int MOD = 1e9+7;
const int INF = 1e9+1;

int N,M;
vector<pii> V[MAXN];
vector<LL> A[MAXN];

int main() {
#ifdef OJ
    freopen("input.txt", "rt", stdin);
    //freopen("output.txt", "wt", stdout);
#endif
    ios::sync_with_stdio(false);
    cin.tie(0);

    cin >> N >> M;
    fori(i,M) {
        int l,r,c;
        cin >> l >> r >> c;
        l--; r--;
        V[l].eb(c,r);
    }

    multiset<LL> S;
    S.insert(0);
    A[1].pb(0);
    fori(i,N) {
        for(LL a: A[i]) S.erase(S.find(a));
        if(!S.size()) RETURN(-1);

        LL mn = *S.begin();
        if(i == N-1) {
            cout << mn << endl;
            return 0;
        }

        for(auto v: V[i]) {
            LL tmp = mn+v.fi;
            S.insert(tmp);
            A[v.se+1].pb(tmp);
        }
    }

    return 0;
}



Measured memory_bytes: 11008
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long a,b,c;
	cin>>a>>b>>c;
	long long s=0;
	s+=a/(b+c)*b;
	a=a%(b+c);
	if(a>b)
	s+=b;
	else
	s+=a;
	cout<<s;
	return 0;
 } 

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<double> vd;
typedef vector<ll> vl;
typedef vector<string> vs;
#define fo(i, a, b) for (int i = a; i < b; i++)
#define re(i, n) fo(i, 0, n)
#define pb push_back
#define mp make_pair
#define all(s) s.begin(), s.end()
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { ll g = gcd(a, b); return a / g * b; }
int main()
{
  string s;
  cin >> s;

  re(i, s.size()) {
    cout << 'x';
  }
  cout << endl;

  return 0;
}


Measured memory_bytes: 256
from collections import defaultdict
N = int(input())
V = [int(a) for a in input().split(" ")]
arr1,arr2 = V[::2], V[1:][::2]
dic1,dic2 = defaultdict(lambda: 0), defaultdict(lambda: 0)
for v1, v2 in zip(arr1, arr2):
    dic1[v1] += 1
    dic2[v2] += 1
rank1 = sorted(dic1.items(), key=lambda t: t[1])[::-1]
rank2 = sorted(dic2.items(), key=lambda t: t[1])[::-1]
if rank1[0][0] == rank2[0][0]:
    if rank1[0][1] == rank2[0][1]:
        nadd1 = rank1[1][1] if len(rank1)>=2 else 0
        nadd2 = rank2[1][1] if len(rank2)>=2 else 0
        print(N-rank1[0][1]-max(nadd1, nadd2))
    else:
        rank1, rank2 = rank1, rank2 if rank1[0][0]>rank2[0][0] else rank2, rank1
        nadd = rank2[1][1] if len(rank2)>=2 else 0
        print(N-rank1[0][1]-nadd)
else:
    print(N-(rank1[0][1]+rank2[0][1]))

Measured memory_bytes: 66028
#include<bits/stdc++.h>
#define int long long
using namespace std;
constexpr int mod=1e9+7;
signed main(){
    int k;
    cin>>k;
    int sum=0;
    for(int a=1;a<=k;a++)
        for(int b=1;b<=k;b++)
            for(int c=1;c<=k;c++)
                sum+=gcd(gcd(a,b),c);
    cout<<sum<<endl;
}


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

int main() {
	int n;
	cin >> n;
	vector<int> h(n);
	rep(i, n) cin >> h[i];
	rep(i, n-1) {
		if(i == 0) h[i]--;
		else if(h[i+1] <= h[i] && h[i] > h[i-1]) h[i]--;
	}
	string ans = "Yes";
	rep(i, n-1) {
		if(h[i+1] < h[i]) ans = "No"; 
	}
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 640
import java.util.*;
import java.math.BigInteger;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        String S = sc.next();
        char[] strArray = S.toCharArray();
        int[] countChar = new int[26];
        for(int i = 0; i < strArray.length; i++){
            countChar[((int)strArray[i]) % 26] ++;
        }
        
        BigInteger total = new BigInteger("1");
        for(int i = 0; i < 26; i++){
            total = total.multiply(new BigInteger(Integer.toString(countChar[i]+1)));
        }
        total = total.subtract(new BigInteger("1"));
        BigInteger ans = total.remainder(new BigInteger(Integer.toString(1000000007)));
        System.out.println(ans);
    }
}

Measured memory_bytes: 26964
/*BISMILLAH
THE WHITE WOLF
NO DREAM IS TOO BIG AND NO DREAMER IS TOO SMALL*/

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<long long> vll;
typedef vector<int> vi;

#define io ios_base::sync_with_stdio(false)
#define pb push_back
#define eb emplace_back
#define mod    1000000007
#define PI 2*acos(0.0)

const int N = 1000005;

int32_t main()
{
    io;
    int n;
    cin>>n;
    vi cnt(N);
    set<int> un;
    for(int i = 0; i< n; i++)
    {
        int x;
        cin>>x;
        cnt[x]++;
        un.insert(x);
    }
    int dec = 0;
    while(!un.empty())
    {
        int ac = *un.begin();
        un.erase(ac);
        if(cnt[ac] > 1)
            dec += cnt[ac];
        for(int i = 2*ac; i < N; i+= ac)
        {
            dec += cnt[i];
            if(cnt[i])
                un.erase(i);
            cnt[i] = 0;
        }
    }
    cout<<n-dec;
    return 0;
}

Measured memory_bytes: 16416
#include "bits/stdc++.h"
#define LF '\n'
#define ALL(x) x.begin(), x.end()
#define LEN(x) (int)x.size()
#define iostreamBooster() do{ cin.tie(nullptr); ios_base::sync_with_stdio(false); }while(0)
using namespace std;
typedef int64_t i64;
typedef pair<int,int> pii;
template<class A, class B>inline bool chmax(A &a, const B &b){return b>a ? a=b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return b<a ? a=b,1 : 0;}
constexpr int INF = 0x3f3f3f3f;
template<class Itr>void dump(Itr begin, Itr end) {
  for(;begin != end; ++begin) clog << ' ' << *begin;
  clog << LF;
}


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

  return 0;
}



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

typedef long long ll;

int main (void) {
    int n; cin >> n;
	double ans = 0;
	double v[55];

	for (int i = 0; i < n; i++) {
		cin >> v[i];
	}
    
    sort(v, v+n);
	ans = (v[0] + v[1]) / 2.0;
	for (int i = 2; i < n; i++){
		ans = (ans + v[i]) / 2.0;
	}
	printf("%.6lf\n", ans);
    
    return 0;
}

Measured memory_bytes: 256
#include <cstring>
#include <map>
#include <deque>
#include <queue>
#include <stack>
#include <sstream>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <fstream>
#include <string>
#include <cstdlib>
#include <ctime>
#include <functional>
#include <algorithm>
#include <vector>
#include <set>
#include <complex>
#include <list>
#include <climits>
#include <cctype>
#include <bitset>
using namespace std;

#define PI 3.14159265359
#define all(v) v.begin(),v.end()
#define sortva(v) sort(all(v))
#define sortvd(v) sort(v.rbegin(),v.rend())
#define sortaa(a,n) sort(a,a+n)
#define sortad(a,n) sort(a,a+n),reverse(a,a+n)
#define sfi1(v) scanf("%d",&v)
#define sfi2(v1,v2) scanf("%d %d",&v1,&v2)
#define sfi3(v1,v2,v3) scanf("%d %d %d",&v1,&v2,&v3)
#define sfll1(v) scanf("%I64d",&v);
#define sfll2(v1,v2) scanf("%I64d %I64d",&v1,&v2)
#define sfll3(v1,v2,v3) scanf("%I64d %I64d %I64d",&v1,&v2,&v3)
#define sfstr(v) scanf("%s", v);
#define sz(v) (int)v.size()
#define ndl puts("")
#define SS stringstream
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

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

ll gcd(ll a, ll b) { return !b ? a : gcd(b, a % b); }
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }

void PLAY() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	cout << fixed << setprecision(10);
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
}


int main() {
//	PLAY();

	string s;
	cin >> s;
	s[0] = '2';
	s[1] = '0';
	s[2] = '1';
	s[3] = '8';
	cout << s << endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef double lod;
const int N=4e5;
int gi() {
	int w=0;bool q=1;char c=getchar();
	while ((c<'0'||c>'9') && c!='-') c=getchar();
	if (c=='-') q=0,c=getchar();
	while (c>='0'&&c <= '9') w=w*10+c-'0',c=getchar();
	return q? w:-w;
}
struct P{ int x,y; inline bool operator < (const P &b) const { return y<b.y; } }p[N];
int x[N],c[N];
int mn[N];
int main()
{
	int x1=gi(),y1=gi(),x2=gi(),y2=gi(),i;
	int n=gi(),t,k,sum=0,s;
	const lod pi=3.14159265358979323846;
	for (i=1;i<=n;i++)
		p[i].x=gi(),p[i].y=gi();
	if (x1>x2) { x1*=-1; x2*=-1; for (i=1;i<=n;i++) p[i].x*=-1; }
	if (y1>y2) { y1*=-1; y2*=-1; for (i=1;i<=n;i++) p[i].y*=-1; }
	for (i=1;i<=n;i++)
		if (p[i].x<x1||x2<p[i].x||p[i].y<y1||y2<p[i].y) p[i--]=p[n--];

	for (i=1;i<=n;i++) x[i]=p[i].x;
	sort(x+1,x+1+n);
	sort(p+1,p+1+n);
	for (i=1;i<=n;i++) {
		k=lower_bound(x+1,x+1+n,p[i].x)-x;
		s=0;
		for (t=k;t;t^=t&-t) s=max(s,c[t]);
		sum=max(sum,++s);
		for (t=k;t<=n;t+=t&-t) c[t]=max(c[t],s);
	}
	cout << fixed << setprecision(15);
	double ans=100LL*(x2-x1+y2-y1);
	ans=ans-20*sum+5*pi*sum;
 	if (sum==abs(x1-x2)+1||sum==abs(y1-y2)+1)
		ans=ans+5*pi;
	cout<<ans<<endl;
	//printf("%.15lf\n",
	//cout<<100LL*(x2-x1+y2-y1)+(sum==min(y2-y1,x2-x1)+1?-(sum-1)*(20*5-pi)+10*pi-20:-sum*(20-5*pi));//);
	return 0;
}


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

int main()
{
	int x;
	cin >> x;
	if (x < 0)
		x = -x;
	long long tot = 0;
	for (int i = 1;; i++)
	{
		tot += i;
		if (tot >= x)
		{
			cout << i << endl;
			break;
		}
	}
	return 0;
}

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

int main(){
    int h,w;cin>>h>>w;
char v[h][w];
for(int i=0;i<h;i++)
for(int j=0;j<w;j++)cin>>v[i][j];
for(int i=0;i<2*h;i++){
    for(int j=0;j<w;j++)cout<<v[i/2][j];
    cout<<endl;
}

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define faster ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long ll;
 
typedef vector<int> vi;;
typedef vector<ll> vll;

#define l() length()
#define sz() size()
 
#define b() begin()
#define e() end()
#define all(x) x.begin(), x.end()
 
#define pb(i) push_back(i)
#define PB() pop_back()
 
 
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;
#define mp make_pair
#define Fi first
#define Se second
 
const int maxx=1e6+9;
 
// Happy Coding!


void solve(){
    char s[5];
    scanf ("%s",&s);
    int a=s[0]-'0',b=s[1]-'0',c=s[2]-'0',d=s[3]-'0';
    if(a-b-c-d==7) printf ("%d-%d-%d-%d=7\n",a,b,c,d);
    else if(a-b-c+d==7) printf ("%d-%d-%d+%d=7\n ",a,b,c,d);
    else if(a-b+c-d==7) printf ("%d-%d+%d-%d=7\n",a,b,c,d);
    else if(a-b+c+d==7) printf ("%d-%d+%d+%d=7\n",a,b,c,d);
    else if(a+b-c-d==7) printf ("%d+%d-%d-%d=7\n",a,b,c,d);
    else if(a+b-c+d==7) printf ("%d+%d-%d+%d=7\n",a,b,c,d);
    else if(a+b+c-d==7) printf ("%d+%d+%d-%d=7\n",a,b,c,d);
    else if(a+b+c+d==7) printf ("%d+%d+%d+%d=7\n",a,b,c,d);}

int main() {
    faster;
    int t=1;
    // cin>>t;
    while(t-->0){
        solve();
    }
	return 0;
}

Measured memory_bytes: 3704
#include <bits/stdc++.h>
using namespace std;
#include <stdlib.h>
 
int main() {
    long long a,b;
    cin >> a>>b;
    if(a==0){
        cout <<"Zero"<<endl;
    }
    else if(a>0){
        cout <<"Positive"<<endl;
    }
    else{
        if(b>=0){
            cout <<"Zero"<<endl;
        }
        else{
            if((b-a+1)%2==0){
               cout <<"Positive"<<endl; 
            }
            else{
                cout <<"Negative"<<endl;
            }
        }
    }
}

Measured memory_bytes: 3492
#include<cstdio>
#define MAX 100010
#define NIL -1
struct Node{
	int parent = NIL;
	int left = NIL;
	int right = NIL;
};

Node T[MAX];
int D[MAX];
void print(int u){
	int i,c;
	printf("node %d: ",u);
	printf("parent = %d, ",T[u].parent);
	printf("depth = %d, ",D[u]);

	if(T[u].parent == NIL) printf("root, ");
	else if(T[u].left == NIL) printf("leaf, ");
	else printf("internal node, ");

	printf("[");

	for(int i=0, c = T[u].left; c != NIL; i++, c = T[c].right){
		if(i) printf(", ");
		printf("%d",c);
	}
	printf("]\n");
}

int solve(int u, int p)
{
	D[u] = p;
	if(T[u].right != NIL) solve(T[u].right, p);
	if(T[u].left != NIL) solve(T[u].left, p+1);
}

int main(){
	int n,v,p,c,l,r;
	scanf("%d",&n);
	for(int i=0; i<n; i++)
	{
		scanf("%d%d",&v,&p);
		for(int j=0; j<p; j++)
		{
			scanf("%d",&c);
			if(j==0) T[v].left = c;
			else T[l].right = c;
			l = c;
			T[c].parent = v;
		}
	}

	for(int i=0; i<n; i++)
	{
		if(T[i].parent == NIL)
			r = i;
	}

	solve(r,0);

	for(int i=0; i<n; i++)
		print(i);

	return 0;
}


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


void solve(long long K){
    int values[] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    cout << values[K-1] << endl;

}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long K;
    scanf("%lld",&K);
    solve(K);
    return 0;
}


Measured memory_bytes: 256
N = $stdin.gets.chomp.to_i
$ab = []
$cd = []
N.times do |i|
    $ab[i] = $stdin.gets.chomp.split(' ').map(&:to_i)
end
N.times do |i|
    $cd[i] = $stdin.gets.chomp.split(' ').map(&:to_i)
end

$ab = $ab.sort_by{|p| -p[1]}
$cd = $cd.sort_by{|p| p[0]}
n_pair = 0
while $cd.length > 0 do
    cd = $cd.shift
    $ab.each do |ab|
        if ab[0] < cd[0] && ab[1] < cd[1]
            n_pair += 1
            $ab.delete(ab)
            break
        end
    end
end

print n_pair

Measured memory_bytes: 1916
#include <algorithm>
#include <assert.h>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
#define MOD 1000000007LL
#define MX 5005

using namespace std;

typedef long long ll;

template <typename T> void read(T& x)
{
	x = 0; char c = getchar(); bool f = 0;
	while(!isdigit(c) && c!='-') c = getchar();
	if(c == '-') f = 1, c = getchar();
	while(isdigit(c)) x = x*10+c-'0', c = getchar();
	if(f) x = -x;
}

int n;
int fst[MX], nxt[MX*2], v[MX*2], lnum;
ll fac[MX], faci[MX], inv[MX];
int siz[MX], mxs[MX], cen, cnt;
int sbt[MX], sum[MX], snm;
ll f[MX][MX];

void addeg(int nu, int nv)
{
	nxt[++lnum] = fst[nu];
	fst[nu] = lnum;
	v[lnum] = nv;
}

void input()
{
	int a, b;
	read(n);
	for(int i=1; i<n; i++)
	{
		read(a); read(b);
		addeg(a, b);
		addeg(b, a);
	}
	fac[0] = faci[0] = inv[0] = inv[1] = 1;
	for(int i=2; i<=n; i++) inv[i] = (MOD - MOD/i) * inv[MOD%i] % MOD;
	for(int i=1; i<=n; i++) fac[i] = fac[i-1] * i % MOD, faci[i] = faci[i-1] * inv[i] % MOD;
}

void dfs(int x, int f)
{
	siz[x] = 1;
	for(int i=fst[x]; i; i=nxt[i])
	{
		if(v[i] != f)
		{
			dfs(v[i], x);
			siz[x] += siz[v[i]];
			mxs[x] = max(mxs[x], siz[v[i]]);
		}
	}
	mxs[x] = max(mxs[x], n-siz[x]);
	if(!cen || mxs[x]<mxs[cen]) cen = x, cnt = 1;
	else if(mxs[x] == mxs[cen]) cnt++;
}

void work()
{
	dfs(1, 0);
	assert(cnt <= 2);
	if(cnt > 1) sbt[1] = sbt[2] = n/2, snm = 2;
	else
	{
		for(int i=fst[cen]; i; i=nxt[i])
			if(siz[v[i]] < siz[cen])
				sbt[++snm] = siz[v[i]];
		sbt[++snm] = n-siz[cen];
	}
	sort(sbt+1, sbt+snm+1);
	f[0][0] = 1;
	for(int i=1; i<=snm; i++) sum[i] = sum[i-1] + sbt[i];
	for(int i=1; i<=snm; i++)
	{
		for(int j=0; j<=sum[i]; j++)
		{
			for(int k=0; k<=sbt[i]&&k<=j; k++)
			{
				ll f2 = fac[sbt[i]] * fac[sbt[i]] % MOD;
				ll d2 = faci[sbt[i]-k] * faci[sbt[i]-k] % MOD;
				ll d = faci[k] % MOD;
				f[i][j] = (f[i][j] + f[i-1][j-k] * f2 % MOD *d2 % MOD * d) % MOD;
			}
		}
	}
	ll ans = 0;
	for(int i=0; i<=n; i++)
		if(i & 1) ans = (ans + MOD*MOD - f[snm][i]*fac[n-i]) % MOD;
		else ans = (ans + f[snm][i]*fac[n-i]) % MOD;
	printf("%lld\n", ans);
}

int main()
{
	input();
	work();
	return 0;
}

Measured memory_bytes: 194176
n, m = map(int, input().split())
ks = [list(map(int, input().split())) for _ in range(m)]
p = list(map(int, input().split()))

count=0
for i in range(1<<n):
    f = True
    for j in range(m):
        pc = 0
        sw = ks[j][1:]
        for s in sw:
            s-=1
            if i&(1<<s):
                pc ^= 1
        if pc != p[j]:
            f = False
    if f:
        count += 1
print(count)

Measured memory_bytes: 3064
import java.util.*;
public class Main
{
	public static void main(String[] args) 
	{
		Scanner in=new Scanner(System.in);
		int M=100000;
		boolean a[]=new boolean[M+1];
		Arrays.fill(a, true);
		a[0]=a[1]=false;
		for(int i=2;i*i<=M;i++)
		{
			if(!a[i])
				continue;
			for(int j=i*2;j<=M;j+=i)
				a[j]=false;
		}
		for(;;)
		{
			int n=in.nextInt();
			if(n==0)
				return;
			int ans=0;
			for(int i=0;i<=n;i++)
			{
				if(!a[i])
					continue;
				for(int j=i;j<=n;j++)
				{
					if(i+j>n)
						break;
					if(!a[j])
						continue;
					if(i+j==n)
						ans++;
				}
			}
			System.out.println(ans);
		}
	}
}

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

#define INF 100000000
#define ABS(a) (a<0?-(a):a)
#define MIN(a,b) (a>b?b:a)
#define MAX(a,b) (a>b?a:b)
#define REP(i,a) for(int i=0;i<a;i++) 

using namespace std;
int po(int a){
  switch(a){
    case 1:
    case 3:
    case 5:
    case 7:
    case 8:
    case 10:
    case 12:
      return 1;

    case 4:
    case 6:
    case 9:
    case 11:
      return 2;

    case 2:
      return 3;
  }
}
int main(){
  int x,y;
  cin >> x >> y;

  if(po(x) == po(y)){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}



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

int main(void){
  
  int i,j,k,l,n,p,cntr = 0;
  
  scanf("%d",&n);
  
  for(i=0;i<n;i++){
    
    scanf("%d",&p);
    if(p==2) cntr++;
    else{
      k=0;
      for(j=2;j<=p/j;j++)
	{
	  if(p%j==0)
	    {
	      k++;
	    
	    }
	}
      if(k==0) cntr++;
    }
  }
  printf("%d\n",cntr);
  
  return 0;
}
      

Measured memory_bytes: 596
#include<bits/stdc++.h>
using namespace std;
int main() {
    long long int  n,m,sum=0;
    cin >> n >>m;
    for(int i=1;i<=m;i++){
        int a;
        cin >>a;
        sum+=a;
    }
    if(sum>n)sum=n+1;
    cout << n-sum << endl;
  return 0;

}


Measured memory_bytes: 3644
#include<iostream>
#include<string>
#include<vector>
#include<utility>
#include<queue>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<complex>
#define INF 2147483647
#define llINF 9223372036854775807
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long

using namespace std;
typedef struct eee{
  int to,cost;
}edge;
const int MAX_V=1010;
const ll llinf=1e15; 
vector<vector<edge> >E(MAX_V);
ll d[MAX_V];
int V,EE;
bool bellman_ford(int s){
  fill_n(d,MAX_V,llinf);
  ll cnt=0,r=0;
  bool flag=false;
  d[s]=0;
  while(1){
    r=d[V-1];
    flag=false;
    for(int i=0;i<V;i++){
      for(int j=0;j<E[i].size();j++){
	edge e=E[i][j];
	if(d[i]!=llinf&&d[e.to]>d[i]+e.cost){
	  d[e.to]=d[i]+e.cost;
	  flag=true;
	}
      }
    }
    if(!flag)
      break;
    if(cnt==V-1&&r!=d[V-1])
      return true;
    else if(cnt==V-1&&r==d[V-1])
      return false;
    cnt++;
  }
  return false;
}
int main(){
  cin>>V>>EE;
  for(int i=0;i<EE;i++){
    int a,b,c;cin>>a>>b>>c;a--;b--;
    edge e;e.to=b;e.cost=-c;
    E[a].pb(e);
  }
  if(bellman_ford(0))
    cout<<"inf"<<endl;
  else
    cout<<-d[V-1]<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i,a,b)  for(int (i)=(a);(i)<(b);(i)++)
#define REP(i,n)    FOR(i,0,n)
#define RER(i,n)    FOR(i,0,(n+1))
#define pb          push_back
#define mp(a,b)     make_pair((a),(b))
#define mset(m,v)   memset(m,v,sizeof(m))
using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<pair<int, int> > vpii;
typedef long long ll;
typedef vector<ll> vl;
typedef pair<ll,ll> pll;
typedef vector<pair<ll, ll> > vpll;
typedef vector<string> vs;
typedef long double ld;
const double EPS    = 1e-10;
const int INF       = 1e+9;
const double PI     = acos(-1);


auto main() -> int
{
    int a, b;
    char op;
    cin >> a >> op >> b;

    cout << ((op == '+') ? a + b : a - b) << endl;

    return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>
#include<iomanip>
#include<sstream>
#include<vector>
#include<stack>
#include<math.h>
#include<queue>
#include<complex>
#include<random>
#include<ctime>
#include<set>
using namespace std;


const long long int mod=1000000007;
const long long int INF=99999999999999999;

long long int N,P;

//素数判定　素数ならそのまま返す　合成数なら０を返す。
class Sosu{
	public:
	long long int sosu(long long int n) {
		for (int i = 2; i*i <= n; i++) {
			if (n%i == 0) { return 0; }
		}
		return n;

	}
};

int main() {
	
	cout << fixed << setprecision(18);
	cin>>N>>P;
	Sosu so;
	while(N!=-1){
		vector<long long int>vec,sos;
		for(int i=max(2LL,N+1);i==i;i++){
			if(so.sosu(i)==i){sos.push_back(i);}
			if(sos.size()>=100){break;}
		}
		for(int i=0;i<sos.size();i++){
			for(int j=i;j<sos.size();j++){
				vec.push_back(sos[i]+sos[j]);
			}
		}
		sort(vec.begin(),vec.end());
		cout<<vec[P-1]<<endl;
		for(int i=0;i<100;i++){
			//cout<<vec[i]<<" ";
		}
		//cout<<endl;

		cin>>N>>P;
	}

} 


Measured memory_bytes: 3268
N = int(input())
F = [list(map(int, input().split())) for i in range(N)]
P = [list(map(int, input().split())) for i in range(N)]
ans = []

for i in range(2**10):
    tmp = 0
    for j in range(N):
        num = 0
        for index, k in enumerate(F[j]):
            if k == 1:

                if i & 2**index:
                    num += 1
        tmp += P[j][num]
    ans.append(tmp)
ans = ans[1:]
print(max(ans))


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

int main()
{
    int count[26] = {0};
    string s;
    int i;
    while(cin >> s)
    {
        for(i = 0; i < s.length(); i++)
        {
            if (s[i] >= 'a' && s[i] <= 'z')
                count[s[i] - 'a']++;
            else if (s[i] >= 'A' && s[i] <= 'Z')
                count[s[i] - 'A']++;
        }
    }

    for (i = 0; i < 26; i++)
        cout << (char)('a'+i) << " : " << count[i] << endl;
    return 0;
}


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

int main() {
    double n, a[1005], suma = 0;
    cin >> n;
    for(int i=0; i<n; i++) {
        cin >> a[i];
        a[i] = 1 / a[i];
        suma += a[i];
    }
    cout << 1 / suma;
    return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from functools import lru_cache
import bisect
import re
import queue


class Scanner():
    @staticmethod
    def int():
        return int(sys.stdin.readline().rstrip())

    @staticmethod
    def string():
        return sys.stdin.readline().rstrip()

    @staticmethod
    def map_int():
        return [int(x) for x in Scanner.string().split()]

    @staticmethod
    def string_list(n):
        return [input() for i in range(n)]

    @staticmethod
    def int_list_list(n):
        return [Scanner.map_int() for i in range(n)]

    @staticmethod
    def int_cols_list(n):
        return [int(input()) for i in range(n)]


class Math():
    @staticmethod
    def gcd(a, b):
        if b == 0:
            return a
        return Math.gcd(b, a % b)

    @staticmethod
    def lcm(a, b):
        return (a * b) // Math.gcd(a, b)

    @staticmethod
    def roundUp(a, b):
        return -(-a // b)

    @staticmethod
    def toUpperMultiple(a, x):
        return Math.roundUp(a, x) * x

    @staticmethod
    def toLowerMultiple(a, x):
        return (a // x) * x

    @staticmethod
    def nearPow2(n):
        if n <= 0:
            return 0
        if n & (n - 1) == 0:
            return n
        ret = 1
        while(n > 0):
            ret <<= 1
            n >>= 1
        return ret

    @staticmethod
    def sign(n):
        if n == 0:
            return 0
        if n < 0:
            return -1
        return 1

    @staticmethod
    def isPrime(n):
        if n < 2:
            return False
        if n == 2:
            return True
        if n % 2 == 0:
            return False
        d = int(n ** 0.5) + 1
        for i in range(3, d + 1, 2):
            if n % i == 0:
                return False
        return True

    @staticmethod
    def divisor(n):
        i = 1
        table = []
        while i * i <= n:
            if n % i == 0:
                table.append(i)
                table.append(n // i)
            i += 1
        table = list(set(table))
        return table


class PriorityQueue:
    def __init__(self, l=[]):
        self.__q = l
        heapq.heapify(self.__q)
        return

    def push(self, n):
        heapq.heappush(self.__q, n)
        return

    def pop(self):
        return heapq.heappop(self.__q)

    def list(self):
        return self.__q

    def length(self):
        return len(self.__q)


sys.setrecursionlimit(1000000)
MOD = int(1e09) + 7
INF = int(1e30)


def main():
    # sys.stdin = open("Sample.txt")
    N, M = Scanner.map_int()
    X = Scanner.int_list_list(N)
    X.sort()
    ans = 0
    tasks = PriorityQueue()
    i = 0
    for t in reversed(range(M)):
        while i < N and X[i][0] + t <= M:
            tasks.push(-X[i][1])
            i += 1
        if tasks.length() > 0:
            ans += -tasks.pop()
    print(ans)
    return


if __name__ == "__main__":
    main()


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

using namespace std;

typedef long long ll;

int main(){
	int n;
	cin >> n;
	ll damps[n];
	for(int i=0;i<n;++i) cin >> damps[i];
	
	ll ans[n];
	ll sum = 0;
	for(int i=n-1;i>=0;--i){
		if(i&1) sum -= damps[i];
		else sum += damps[i];
	}
	ans[0] = sum;
	damps[n-1] -= sum/2;
	damps[0] -= sum/2;
	for(int i=1;i<n;++i){
		int val = 2*damps[i-1];
		ans[i] = val;
		damps[i-1] -= val/2;
		damps[i] -= val/2;
	}
	for(int i=0; i<n; ++i){
		if(i==0) cout << ans[i];
		else cout << " " << ans[i];
	}
	cout << endl;
}

Measured memory_bytes: 2816
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, K;
  cin >> N >> K;
  
  vector<int> vec(N);
  
  for (int i = 0; i < K; i++) {
       int d;
       cin >> d;
    
       vector<int> vec2(d);
    for (int j = 0; j < d; j++) {
      cin >> vec2.at(j);
      vec.at(vec2.at(j) - 1)++;
    }
  }
  
  int ans = 0;
  for (int i = 0; i < N; i++) {
    if (vec.at(i) == 0) {
      ans++;
    }
  }
  
  cout << ans << endl;
}

    


Measured memory_bytes: 3632
fun main(args: Array<String>) {
    abc133d()
}

fun abc133d() {
    val n = readLine()!!.toInt()
    val dams = readLine()!!.split(" ").map { it.toLong() }.toLongArray()

    val rains = LongArray(n) { 0 }

    rains[0] = dams.sum() - dams.filterIndexed { index, l -> index % 2 != 0 }.sum() * 2

    for (i in 0 until n - 1) rains[i + 1] = dams[i] * 2 - rains[i]

    println(rains.joinToString(" "))
}


Measured memory_bytes: 74504
#include <bits/stdc++.h>
using namespace std;
#define repl(i, l, r) for (ll i = (l); i < (r); i++)
#define rep(i, n) repl(i, 0, n)
#define CST(x) cout << fixed << setprecision(x)
using ll = long long;
const ll MOD = 1000000007;
const int inf = 1e9 + 10;
const ll INF = 4e18 + 10;
const int dx[9] = {1, 0, -1, 0, 1, -1, -1, 1, 0};
const int dy[9] = {0, 1, 0, -1, 1, 1, -1, -1, 0};
int main() {
	cin.tie(0);
	cout.tie(0);
	ios::sync_with_stdio(false);

	int n;
	cin >> n;
	int a[n];
	rep(i, n) cin >> a[i];
	sort(a, a + n);
	int ans = 0;
	rep(i, n) {
		repl(j, i + 1, n) {
			repl(k, j + 1, n) {
				if (a[i] == a[j] or a[i] == a[k] or a[j] == a[k])
					continue;
				else {
					if (a[i] + a[j] > a[k]) ans++;
				}
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3644
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include <cmath>
#include <limits>
#include <utility>
#include <map>
#include <iomanip>
#include <queue>
#include <cctype>
#include <stack>


#define rep(p,q) for(int i = p;i < q;i++)
#define ll long long

using namespace std;

bool pairCompare(const pair<ll, ll> firstElof, const pair<ll, ll> secondElof)
{
	return firstElof.second > secondElof.second;
}

int main(void) {
	int n;
	cin >> n;
	map<string, vector<int>> c = map<string, vector<int>>();
	vector<int> point = vector<int>(n);
	rep(0, n) {
		string s;
		int p;
		cin >> s >> p;
		point[i] = p;
		c[s].push_back(i);
	}
	auto iter = c.begin();
	rep(0, c.size()) {
		vector<int> ci = iter->second;
		vector<pair<int,int>> ps = vector<pair<int,int>>();
		rep(0, ci.size()) {
			ps.push_back(make_pair(ci[i], point[ci[i]]));
		}
		sort(ps.begin(), ps.end(), pairCompare);
		rep(0, ps.size()) {
			cout << ps[i].first + 1 << endl;
		}
		iter = next(iter, 1);
	}
}

Measured memory_bytes: 256
using System;

class Program
{
    static void Main()
    {
            while (true)
            {
                string[] s = Console.ReadLine().Split(' ');
                int H = int.Parse(s[0]);
                int W = int.Parse(s[1]);
                if (H == 0 || W == 0)
                    break;
                for (int i = 0; i < H; i++)
                {
                    for (int j = 0; j < W; j++)
                    {
                        if (i + j == 0)
                            Console.Write("#");
                        else if ((i + j) % 2 > 0)
                            Console.Write(".");
                        else if ((i + j) % 2 == 0)
                            Console.Write("#");
                    }
                    Console.WriteLine("");
                }
                Console.WriteLine("");
            }
    }
}

Measured memory_bytes: 9004
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) {
        FastInput in = new FastInput();
        PrintWriter out = new PrintWriter(System.out);
        int n = in.nextInt();
        long[] arr = new long[n];
        long modulo = 1000 * 1000 * 1000 + 7;
        long sum = 0;
        for (int i = 0; i < n; i++) {
            arr[i] = in.nextLong();
            sum += arr[i];
            sum %= modulo;
        }
        long ans = 0;
        for (int i = 0; i < n; i++) {
            sum -= arr[i];
            if (sum < 0) sum += modulo;
            ans += arr[i] * sum;
            ans %= modulo;
        }
        out.println(ans);
        out.close();
    }

    static class FastInput {
        BufferedReader br;
        StringTokenizer st;

        public FastInput() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
}


Measured memory_bytes: 56168
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(n) for (ll i = 0; i < n; ++i)
#define rep2(i, n) for (ll i = 0; i < n; ++i)
#define rep3(i, a, b) for (ll i = a; i < b; ++i)
#define rep4(i, a, b, c) for (ll i = a; i < b; i += c)
#define erep(n) for (ll i = 0; i <= n; ++i)
#define erep2(i, n) for (ll i = 0; i <= n; ++i)
#define erep3(i, a, b) for (ll i = a; i <= b; ++i)
#define erep4(i, a, b, c) for (ll i = a; i <= b; i += c)
#define rrep(i, a, b) for (ll i = a; i > b; --i)
#define rrep2(i, a, b, c) for (ll i = a; i > b; i -= c)
#define errep(i, a, b) for (ll i = a; i >= b; --i)
#define errep2(i, a, b, c) for (ll i = a; i >= b; i -= c)
#define print(a) cout << a << endl;
#define printVec(v) printf("{"); for (const auto& i : v) { std::cout << i << ", "; } printf("}\n");
#define cin(x) cin >> x;
const ll MOD = 1000000007;
const double PI = 3.14159265358979323846264338327950;
inline int newline() { putchar('\n'); return 0; }

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

    vector<ll> h(n);
    rep2(i, n) cin(h[i]);

    vector<ll> dp(n);
    dp[0] = 0;
    dp[1] = abs(h[1] - h[0]);

    rep3(i, 2, n) {
        dp[i] = min(dp[i - 1] + abs(h[i] - h[i - 1]), dp[i - 2] + abs(h[i] - h[i - 2]));
    }

    print(dp[n - 1]);
    return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
#include <utility>
#include <queue>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

int main()
{
    int n, m;
    cin >> n >> m;
    int a[100002], b[100002];
    P p[100002];
    for(int i = 0; i < n; i++){
        cin >> a[i] >> b[i];
        p[i] = P(a[i], b[i]);
    }
    sort(p, p + n);
    priority_queue<P> que;
    int now = 0;
    ll ans = 0;
    for(int i = 1; i <= m; i++){
        while(now < n && p[now].first <= i){
            que.push(P(p[now].second, p[now].first));
            now++;
        }
        if(!que.empty()){
            ans += que.top().first;
            que.pop();
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 2936
#include<stdio.h>
#include<math.h>
int isprime(int);
int main(){

  int m=0,n=0,i=0,c=0,allc=0,s,a;

  
  scanf("%d",&n);
  int A[n];
  for(i=0;i<n;i++)scanf("%d",&A[i]);

  for(i=0;i<n;i++){
   a=isprime(A[i]);
   if(a==1)c++;
  }

  printf("%d\n",c);
  return 0;
}


  int isprime(int x){
    int true=1,false=0, i,frg=1;

  
  if(x==2)return true;
  else if(x<2||x%2==0)return false;

  else{
    i=3;
    while(i<=sqrt(x))
      {
	if(x%i==0){
	frg=0;
	break;
	}
        i=i+1;
	}
    if(frg==1)return true;
    else return false;
  }
  
}
  



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

int flag[100];

int main(){
   int N;
   cin>>N;
   int X,a[100];
   cin>>X;
   for(int i=0;i<X;i++){
       cin>>a[i];
       flag[a[i]-1]=-1;
   }
   int Y,b[100];
   cin>>Y;
   for(int i=0;i<Y;i++){
       cin>>b[i];
       flag[b[i]-1]+=2;
   }
   int Z,c[100];
   cin>>Z;
   for(int i=0;i<Z;i++){
       cin>>c[i];
       flag[c[i]-1]+=3;
   }
   int cnt=0;
   for(int i=0;i<N;i++){
       if(flag[i]==3||flag[i]==4||flag[i]==5) cnt++;
   }

   cout<<cnt<<endl;
   return 0;
}


Measured memory_bytes: 3100
import collections
N,X,Y=map(int,input().split())
xdex=X-1            #配列に落とし込んで考える時は
ydex=Y-1            #素の値-1にして考えると混乱がない
"""
#ans1…愚直な場合分け
l=[0]*(N)
#print(l)
le=0
#print(xdex,ydex)
for i in range(N):
    for j in range(i+1,N):
        le=(j-i)
        if (i<=xdex)and(ydex<=j):
            le = min(j - i, (j - i) - (Y - X - 1))
        elif ((i<=xdex)and(j<=ydex)and(xdex<=j)):
            le=min(j - i, (xdex-i)+(ydex- j)+1)
        elif ((xdex<i)and(j<=ydex)and(xdex<=j)):
            le=min(j-i,(i-xdex)+(ydex-j)+1)
        elif ((xdex<i)and(ydex<j)):
            le=min(j-i,(i-xdex)+(j-ydex)+1)
        #print(i+1,j+1,le)
        l[le]=l[le]+1
#print(l)
for i in range(N-1):
    print(l[i+1])
"""
#ans2…bfsチックなやつ
inf=1001001
def pus(v,d,dist,q):    #vは頂点,dは距離、distは(1頂点固定時の)距離配列、 qは作業用deque
    if dist[v]==inf:    #ある点から頂点vまでの距離が定義されてないならば
        dist[v]=d       #vまでの距離はdである
        q.append(v)     #次はvを起点にして考えるつもり
    return 0


v=0
d=0
ans=[0]*N
for i in range(N):                  #N頂点全てにてやる
    dist=[inf]*N                    #まず頂点iからの距離配列を組む(まずは距離を無限大に定義mugendainiteigi)
    q = collections.deque()         #qは距離計算時の基準点を格納する。それにより、始点から基準点までの距離を計算できていれば、基準点から新しい点までの距離も計算でき、再帰的に視点から新しい点までの距離が格納される流れだ
    pus(i,0,dist,q)                 #まず始点iは距離が0であることを格納する
    while len(q)!=0:                #以後基準点をpopしていくので、もう基準点ができないこと=全て探索できたということである
        #print(dist,q)
        v=q.popleft()               #qの中にvは距離が小さい順に右へ右へappendしていくため、最短路探査の際にはqの最左頂点vを基準に探索する(探索できたら不要なのでq.popleftで対応)
        d=dist[v]                   #取りまず基準点からvまでの距離をdとする
        if (v-1>=0):                #左に行けるなら
            pus(v-1,d+1,dist,q)     #頂点v-1へはvまでの距離dに1加えた距離でも行ける。distにこれを格納し、q.append(v-1)とすれば良い
        if (v+1<N):                 #右に行けるなら
            pus(v+1,d+1,dist,q)     #頂点v+1へはvまでの距離dに1加えた距離でも行ける。distにこれを格納し、q.append(v-1)とすれば良い
        if v==xdex:                 #ここがxdex(分岐の最左部)ならば
            pus(ydex,d+1,dist,q)    #頂点ydex(分岐の最右側)まではvまでの距離dに1加えた距離でも行ける。distにこれを格納し、q.append(xdex)とすれば良い
        if v==ydex:                 #ここがydex(分岐の最右部)ならば
            pus(xdex,d+1,dist,q)    #頂点xdex(分岐の最左側)まではvまでの距離dに1加えた距離でも行ける。distにこれを格納し、q.append(ydex)とすれば良い
        #print(dist,q)
        #input()
    for i in range(N):              #全ての点にて
        ans[dist[i]]=ans[dist[i]]+1 #基準点からの距離dist[i]をincrementすれば、ある点から全ての点までの距離を格納できる(これをN頂点にやれば全て探査できる)
for i in range(1,N):                #距離1の時の数値から出力することに注意
    print(ans[i]//2)                #距離の個数は重複しているので/2した値を出力する





Measured memory_bytes: 52700
package main

import (
	"bufio"
	"fmt"
	basicIO "io"
	"os"
	"strconv"
)

func main() {
	protagonist(os.Stdin, os.Stdout)
}

func protagonist(r basicIO.Reader, w basicIO.Writer) {
	io := NewIO(r, w)
	R, _ := io.nextInt()
	D, _ := io.nextInt()
	X, _ := io.nextInt()

	x := X
	for i := 0; i < 10; i++ {
		x = x*R - D
		io.PutInt(x)
	}
}

type IO struct {
	Scanner *bufio.Scanner
	Writer  basicIO.Writer
}

func NewIO(r basicIO.Reader, w basicIO.Writer) *IO {
	s := bufio.NewScanner(r)
	s.Split(bufio.ScanWords)
	return &IO{
		Scanner: s,
		Writer:  w,
	}
}

func (io *IO) nextString() string {
	io.Scanner.Scan()
	return io.Scanner.Text()
}

func (io *IO) nextInt() (int, error) {
	io.Scanner.Scan()
	i, err := strconv.Atoi(io.Scanner.Text())
	return i, err
}

func (io *IO) PutInt(v int) {
	fmt.Fprintf(io.Writer, "%d\n", v)
}

func (io *IO) PutString(s string) {
	fmt.Fprintf(io.Writer, "%s\n", s)
}


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

int main (void){
  long long int n,k,count = 0,con = 0;

  cin >> n >> k;

  vector<long long int> a(n,0);
  vector<long long int> b(n,0);
  for(int i = 0;i < n;i++){
    cin >> a[i];
  }

  if(k >= n){
    for(int i = 0;i < n;i++){
      cout << n << " ";
    }
    cout << endl;
    return 0;
  }

  while(count < k){
    for(int i = 0;i < n;i++){
      if(i - a[i] < 0){
        b[0]++;
      }else{
        b[i - a[i]]++;
      }
      if(i + a[i] + 1 >= n){
        continue;
      }
      b[i + a[i] + 1]--;
    }
    for(int i = 0;i < n;i++){
      b[i+1] += b[i];
      a[i] = b[i];
      b[i] = 0;
    }
    count++;

    if(k - count >= n - a[0]){
      con++;
    }

    if(con > 25){
      for(int i = 0;i < n;i++){
        cout << n << " ";
      }
      cout << endl;
      return 0;
    }

  }

for(int i = 0;i < n;i++){
  cout << a[i] << " ";
}
cout << "\n";
return 0;


}

Measured memory_bytes: 6428