akhauriyash/Code-Regression huggingface dataset:
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();
        long a[] = new long[(int)n];
        for (long l = 1; l < n; l++) {
            a[sc.nextInt() - 1] += 1;
        }
        sc.close();

        for (int i = 0; i < a.length; i++) {
            System.out.println(a[i]);
        }
    }
}


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

#define int long long
#define itn int
#define For(i, a, b) for (int i = (a); i <= static_cast<int>(b); i++)
#define Forr(i, a, b) for (int i = (a); i >= static_cast<int>(b); i--)
#define rep(i, n) For(i, 0, n - 1)
#define repall(i, arr) for (auto& i : (arr))
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define dump(x) cerr << #x << " = " << (x) << '\n'
#define dump2(x, y) \
    cerr << #x << " = " << (x) << " " << #y << " = " << (y) << '\n'
#define SZ(x) ((int)(x).size())
#define bit(n) (1LL << (n))
constexpr int MOD = 1e9 + 7;

template <typename T>
using pq = priority_queue<T>;
template <typename T>
using pqr = priority_queue<T, vector<T>, greater<T>>;
const int INF = LLONG_MAX / 2;
using P = pair<int, int>;
using vec = vector<int>;
template <typename T>
using mat = vector<vector<T>>;

// clang-format off
template <typename T1, typename T2>
ostream& operator<<(ostream& stream, const pair<T1, T2>& p) { return stream << p.first << "," << p.second; }
template <typename T>
void print(const vector<T> vec) { rep (i, vec.size() - 1) cout << vec[i] << ' '; cout << vec[vec.size() - 1] << '\n'; }
template <typename Arg>
void print(const Arg arg) { cout << arg << '\n'; }
template <typename Head, typename... Args>
void print(const Head head, const Args... args) { cout << head << " "; print(args...); }
template <typename T, typename U>
void init(vector<T>& v, vector<U>& w) { rep (i, v.size()) cin >> v[i] >> w[i]; }
template <typename T>
void init(vector<T>& v) { rep (i, v.size()) cin >> v[i]; }
template <typename T>
T sum_(vector<T> vec, T init = 0) { return std::accumulate(all(vec), T(init)); }
template<typename T>
bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } return false; }
template<typename T>
bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } return false; }
template <typename T>
int index(const T& vec, const typename T::iterator it) { return distance(vec.begin(), it); }
template <typename T = int>
mat<T> mmat(int n, int m=0) { return mat<T>(n, vector<T>(m)); }
template <typename T = int>
vector<T> ivec(int n) { vector<T> v(n); init(v); return v; }
// clang-format on

void yn(bool tf) { print(tf ? "Yes" : "No"); }
void YN(bool tf) { print(tf ? "YES" : "NO"); }

int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
// -------------------------------------------------------------------
// sort 1 2 3 4
// pqr 1 2 3 must impl >

signed main() {
    cin.tie(0), cout.tie(0), ios::sync_with_stdio(false);
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    while (true) {
        c -= b;
        if (c <= 0) {
            print("Yes");
            return 0;
        }

        a -= d;
        if (a <= 0) {
            print("No");
            return 0;
        }
    }

    return 0;
}


Measured memory_bytes: 3652
#include <iostream>
#include <fstream>
#include <typeinfo>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <iomanip>
#include <cctype>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<25;
const ll INF=1ll<<50;
const double pi=acos(-1);
const double eps=1e-8;
const vi emp;

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

int h,w,ans;
vvb a;
vp p;

int func(vp q){
	int ans=0;
	vvb b(h,vb(w));
	for(int i=0;i<q.size();i++){
		int x=q[i].first,y=q[i].second;
		int tmp=6;
		b[x][y]=1;
		for(int j=0;j<6;j++){
			int cx=x+dx[j],cy=y+dy[x%2][j];
			if(cx>=0&&cx<h&&cy>=0&&cy<w&&b[cx][cy]) tmp-=2;
		}
		ans+=tmp;
	}
	return ans;
}

void bfs(int x,int y){
	queue<P> que;
	que.push(P(x,y));
	while(!que.empty()){
		P q=que.front();
		que.pop();
		a[q.first][q.second]=1;
		for(int i=0;i<6;i++){
			int cx=q.first+dx[i],cy=q.second+dy[q.first%2][i];
			if(cx>=0&&cx<h&&cy>=0&&cy<w&&!a[cx][cy]) que.push(P(cx,cy));
		}
	}
}

void dfs(int x,int y){
	a[x][y]=1;
	for(int i=0;i<6;i++){
		int cx=x+dx[i],cy=y+dy[x%2][i];
		if(cx>=0&&cx<h&&cy>=0&&cy<w&&!a[cx][cy]) dfs(cx,cy);
	}
}

int main(){
	cin>>w>>h;
	a=vvb(h,vb(w));
	for(int i=0;i<h;i++) for(int j=0;j<w;j++){
		int tmp;
		cin>>tmp;
		if(tmp){
			a[i][j]=1;
			p.push_back(P(i,j));
		}
	}
	ans=func(p);
	for(int i=0;i<h;i++) for(int j=0;j<w;j++){
		if((!i||!j||i==h-1||j==w-1)&&!a[i][j]) dfs(i,j);
	}
	vp q;
	for(int i=0;i<h;i++) for(int j=0;j<w;j++) if(!a[i][j]) q.push_back(P(i,j));
	cout<<ans-func(q)<<endl;
}

Measured memory_bytes: 3472
n = int(input())
lis = [0]
x = [0]
y = [0]
for i in range(n):
  a,b,c = map(int,input().split())
  lis.append(a)
  x.append(b)
  y.append(c)

for m in range(n):
  time = lis[m+1]-lis[m]
  idou = abs(x[m+1]-x[m]) + abs(y[m+1]-y[m])
  if time < idou or (time - idou)% 2 == 1:
    print("No")
    break
  if m == n-1:
    print("Yes")

Measured memory_bytes: 11736
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include <numeric>
using namespace std;

int main()
{	long long int X;
	scanf("%lld", &X);
	if((X-3)*(X-5)*(X-7)==0){
	printf("YES");
	}
	else
	{
	printf("NO");
	}
	
}


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

int main(){
	int M, D; cin >> M >> D;

	int ans = 0;
	for(int m = 1; m<=M; ++m){
		for(int d = 1; d<=D; ++d){
			string dd = to_string(d) + "0"s;
			int d1 = (int)(dd[0] - '0'), d2 = (int)(dd[1] - '0');
			if(d1 >= 2 && d2 >= 2 && d1*d2 == m){
				++ans;
			}
		}
	}

	cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
#define osu(a,b,i) for(int i = (a);i <= (b);i++)
#define nso(a,b,i) for(int i = (a);i >= (b);i--)
#define MAXN 100005
#define MAXM 100005
#define MAXQ 100005
#define MAXD 15
using namespace std;
struct Node
{
    int x,d;
};
int qv[MAXQ],qd[MAXQ],qc[MAXQ];
int c[MAXN];
bool vis[MAXN];
int f[MAXN][MAXD];
queue<Node> q;
struct Edge{
    int to,w,ne;
}e[MAXM*2];
int ecnt = 0;
int head[MAXN];
int N,M,Q;
void addedge(int u,int v,int w)
{
    e[++ecnt].to = v;
    e[ecnt].w = w;
    e[ecnt].ne = head[u];
    head[u] = ecnt;
    return ;
}
void bfs()
{
    nso(Q,1,tql)
    {
        memset(vis,false,sizeof vis);
        q.push((Node){qv[tql],qd[tql]});
        while(!q.empty())
        {
            Node nown = q.front();
            q.pop();
            if(f[nown.x][nown.d]) continue;
            if(vis[nown.x]) continue;
            vis[nown.x] = 1;
            f[nown.x][nown.d] = 1;
            if(c[nown.x] == 0) c[nown.x] = qc[tql];
            //cout << "!" << endl;
            for(int i = head[nown.x];i;i = e[i].ne)
            {
                if(e[i].w > nown.d) continue;
                q.push((Node){e[i].to,nown.d - e[i].w});
            }
        }
    }
}
void read(int &ss)
{
    ss=0;char ch=getchar();while(ch>'9'||ch<'0') ch=getchar();
    while(ch>='0'&&ch<='9') ss*=10,ss+=ch-'0',ch=getchar();return ;
}
int main()
{
    read(N);read(M);
    osu(1,M,i)
    {
        int op,ed,w;
        read(op);read(ed);
        addedge(op,ed,1);
        addedge(ed,op,1);
    }
    read(Q);
    osu(1,Q,i)
    {
        read(qv[i]);read(qd[i]);read(qc[i]);
    }
    bfs();
    osu(1,N,i)
    {
        printf("%d\n",c[i]);
    }
}


Measured memory_bytes: 11776
#include <stdio.h>
#include <stdlib.h>
#define ms_valtype int

//比較関数
int compare_ms(ms_valtype a, ms_valtype b){
	return a - b;
}

//昇順
void sort_sub(ms_valtype *origin, int left, int right, ms_valtype *tmp){
	if(right - left > 1){
		int i, j, k, half = (left + right) / 2;
		sort_sub(origin, left, half, tmp);
		sort_sub(origin, half, right, tmp);
		for(i = left; i < right; i++){
			tmp[i] = origin[i];
		}
		for(i = left, j = left, k = half; i < right; i++){
			if(k == right){
				origin[i] = tmp[j];
				j++;
			}
			else if(compare_ms(tmp[j], tmp[k]) <= 0 && j < half){
				origin[i] = tmp[j];
				j++;
			}
			else{
				origin[i] = tmp[k];
				k++;
			}
		}
	}
}

void sort(ms_valtype *origin, int N){
	ms_valtype *tmp = (ms_valtype *)malloc(sizeof(ms_valtype) * N);
	sort_sub(origin, 0, N, tmp);
	free(tmp);
}

int bound(int k, int N, int *b){
	int l = -1, h, r = N;
	while(r - l > 1){
		h = (l + r) / 2;
		if(b[h] < k){
			l = h;
		}
		else{
			r = h;
		}
	}
	return r;
}

int main(){
	int N, i, j, ans = 0, xor, dig, cov;
	scanf("%d", &N);
	int *a = (int *)malloc(sizeof(int) * N);
	int *b = (int *)malloc(sizeof(int) * N);
	for(i = 0; i < N; i++){
		scanf("%d", &a[i]);
	}
	for(i = 0; i < N; i++){
		scanf("%d", &b[i]);
	}
	for(i = 28; i >= 0; i--){
		dig = 1 << i, cov = (dig << 1) - 1;
		xor = N & 1;
//		printf("i = %d\n", i);
		for(j = 0; j < N; j++){
			a[j] &= cov;
			b[j] &= cov;
		}
		sort(b, N);
/*		for(j = 0; j < N; j++){
			printf("b[%d] = %d\n", j, b[j]);
		}
*/		for(j = 0; j < N; j++){
			xor ^= bound(1 * dig - a[j], N, b) & 1;
			xor ^= bound(2 * dig - a[j], N, b) & 1;
			xor ^= bound(3 * dig - a[j], N, b) & 1;
		}
//		printf("xor = %d\n", xor);
		ans |= (xor << i);
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long int
const int mod = 1e9 + 7;
const int N = 1e6 + 5;
int32_t main()
{
	IOS;
	int t=1;

	while(t--)
	{
		int n,k;
		cin>>n>>k;

		vector<int> arr(n+1);

		for(int i=0;i<n;i++)
		{
			cin>>arr[i];
			arr[i]--;
		}
		vector<int> ans;
		unordered_set<int> s;
		int now=0;
		while(s.count(now)==0)
		{
			ans.push_back(now);
			s.insert(now);
			now=arr[now];
		}
		int place=find(ans.begin(),ans.end(),now)-ans.begin();
		int modi=ans.size()-place;

		if(k<place)
		{
			cout<<ans[k]+1;
		}
		else
		{
			cout<<ans[(k-place)%modi+place]+1;
		}
	}
	return 0;
}

Measured memory_bytes: 14380
ｎ = int(input())
a = list(map(int,input().split()))
cnt = 0
mx = a[0]

for i in range(1,n):
  if a[i] > mx:
    mx = a[i]
  if a[i] < mx:
    cnt = cnt + (mx - a[i])

print(cnt)  

Measured memory_bytes: 33448
#include <stdio.h>


int main(){
	int a, b, c;
	scanf("%i %i %i", &a, &b, &c);
	if(a<=b&&a<=c){
		if(b<=c){
			printf("%i\n", a+b);
		}
		else{
			printf("%i\n", a+c);
		}
	}
	else if(b<=c){
		if(a<=c){
			printf("%i\n", b+a);
		}
		else{
			printf("%i\n", b+c);
		}
	}
	else{
		if(a<=b){
			printf("%i\n", c+a);
		}
		else{
			printf("%i\n", c+b);
		}
	}



}

Measured memory_bytes: 128
import java.util.Scanner;
public class Main {
	public static void main(String[] args) throws Exception {
		Scanner scan=new Scanner(System.in);
		int a=scan.nextInt();
		int ans=0;
		int max=0;
		for(int i=0;i<a;i++) {
			int b=scan.nextInt();
			if(max<=b) {
				max=b;
				ans++;
			}
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 21844
def resolve():
    N,M,K = map(int, input().split())
    A = list(map(int,input().split()))
    B = list(map(int,input().split()))
    a, b = [0], [0]
    for i in range(N):
        a.append(a[i]+A[i])
    for i in range(M):
        b.append(b[i]+B[i])

    ans, j = 0,M
    for i in range(N+1):
        if a[i] > K:
            break
        while b[j] > K - a[i]:
            j -= 1
        ans = max(ans, i+j)
    print(ans)
    
resolve()

Measured memory_bytes: 47552
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mp make_pair
#define pii pair<int,int>
inline int read()
{
	int x=0;
	bool pos=1;
	char ch=getchar();
	for(;!isdigit(ch);ch=getchar())
		if(ch=='-')
			pos=0;
	for(;isdigit(ch);ch=getchar())
		x=x*10+ch-'0';
	return pos?x:-x;
}
const int MAXN=1e5+10;
int n,a[MAXN];
int gcd(int x,int y)
{
	return y?gcd(y,x%y):x;
}
int main()
{
	n=read();
	int x=read(),y;
	for(int i=2;i<=n;++i)
		y=read(),x=gcd(x,y);
	cout<<x<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<vector>
#include<complex>
#include<utility>
#include<cstdlib>
#include<cctype>
#include<cmath>
using namespace std;

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

bool overflow;
typedef complex<int> result;

void check_overflow(int n) {
  if( abs(n) > 10000 )
    overflow = true;
}

void check_overflow( result p ) {
  check_overflow( p.real() );
  check_overflow( p.imag() );
}

result expr(const string &s, int &p);
result term(const string &s, int &p);
result fact(const string &s, int &p);

result expr(const string &s, int &p) {
  result r = term(s, p);
  check_overflow( r );
  while(1) {
    if( s[p] == '+' ) {
      p++;
      result temp = term(s,p);
      r += temp;
      check_overflow( temp );
      check_overflow( r );
    }
    else if( s[p] == '-' ) {
      p++;
      result temp = term(s,p);
      r -= temp;
      check_overflow( temp );
      check_overflow( r );
    }
    else
      break;
  }
  return r;
}

result term(const string &s, int &p) {
  result r = fact(s, p);
  check_overflow( r );
  while(1) {
    if( s[p] == '*' ) {
      p++;
      result temp = fact(s,p);
      r *= temp;
      check_overflow( temp );
      check_overflow( r );
    }
    else
      break;
  }
  return r;
}

result fact(const string &s, int &p) {
  if( isdigit(s[p]) ) {
    int n = 0;
    while( isdigit(s[p]) ) {
      n = n * 10 + s[p++] - '0';
      check_overflow( n );
    }
    return result(n, 0);
  }
  else if( s[p] == '(' ) {
    p++;
    result r = expr(s, p);
    check_overflow( r );
    p++;
    return r;
  }
  else if( s[p] == 'i' ) {
    p++;
    return result(0,1);
  }
  return result(0,0);
}



int main() {
  string line;
  while( getline(cin, line) ) {
    overflow = false;
    int p = 0;
    result r = expr(line+"$", p);

    if( overflow ) {
      cout << "overflow" << endl;
    } else {
      if( r.real() == 0 && r.imag() == 0 ) {
        cout << 0 << endl;
      } else if( r.real() == 0 && r.imag() ) {
        cout << r.imag() << "i" << endl;
      } else if( r.real() && r.imag() == 0 ) {
        cout << r.real()  << endl;
      } else {
        cout << r.real();
        if( r.imag() > 0 ) cout << "+";
        cout << r.imag() << "i" << endl;
      }

    }

  }
  return 0;
}

Measured memory_bytes: 0
// https://atcoder.jp/contests/abc085/tasks/abc085_c

#include <algorithm>
#include <iostream>
using namespace std;
#define max(a, b) (((a) > (b)) ? (a) : (b))
#define min(a, b) (((a) < (b)) ? (a) : (b))

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

    for (int i = 0; i <= n; i++) {
        for (int j = 0; j <= n - i; j++) {
            if (y == i * 10000 + j * 5000 + (n - i - j) * 1000) {
                cout << i << " " << j << " " << (n - i - j) << endl;
                return 0;
            }
        }
    }
    cout << "-1 -1 -1" << endl;

    return 0;
}

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

int main(){
int a[10];
int n,b=0,c=0;
cin>>n;
for(int i=0;i<n;i++){
b=0;c=0;
for(int j=0;j<10;j++)cin>>a[j];
for(int j=0;j<10;j++){
if(a[j]>b){b=a[j];}
if(a[j]<b&&a[j]>c){c=a[j];}
if(a[j]<b&&a[j]<c){
cout<<"NO"<<endl;
break;}
if(j==9){
cout<<"YES"<<endl;
break;}
}
}}

Measured memory_bytes: 1156
#include "bits/stdc++.h"
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <map>
#include <vector>
#include <math.h>
#include <algorithm>
#include <queue>
#include <set>
#include <tuple>
using namespace std;

#define FOR(i,init,a) for(int i=init; i<a; i++)
#define rep(i,a) FOR(i,0,a)
#define rrep(i,a) for(int i=a; i>=0; i--)
#define rep1(i,a) for(int i=1; i<=a; i++)
#define cout1(a) cout << a << endl;
#define cout2(a,b) cout << a << " " << b << endl;
#define cout3(a,b,c) cout << a << " " << b << " " << c << endl;
#define cout4(a,b,c,d) cout << a << " " << b << " " << c << " " << d << endl;
#define mem(a,n) memset( a, n, sizeof(a))
#define all(a) a.begin(),a.end()
#define chmin(a,b) a=min(a,b);
#define chmax(a,b) a=max(a,b);

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LLINF = 1e18;
static const double pi = 3.141592653589793;

int nums[2009];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N,Z,W;
    cin>>N>>Z>>W;
    
    rep(i,N) cin>>nums[i];
    
    ll ans=abs(W-nums[N-1]);
    if(N>=2) ans=max(ans,abs(1ll*nums[N-2]-nums[N-1]));
    cout1(ans)
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <stack>
#include <cstdlib>
#include <ctime>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef double DB;

const int MaxN = 1e5;
int n, k, a[MaxN + 5];

int Gcd(int x, int y) {
	if(y == 0) return x;
	return Gcd(y, x % y);
}

int main()
{
	scanf("%d%d", &n, &k);
	for(int i = 1; i <= n; i++) scanf("%d", &a[i]);
	if(n == 1) {
		if(a[1] == k) printf("POSSIBLE\n");
		else printf("IMPOSSIBLE\n");
	}
	else {
		sort(a + 1, a + n + 1);
		int t = a[1];
		for(int i = 2; i <= n; i++) t = Gcd(t, a[i]);
		bool ok = 0;
		for(int i = n; i >= 1; i--) {
			if(a[i] < k) break;
			if((a[i] - k) % t == 0) ok = 1;
		}
		if(ok) printf("POSSIBLE\n");
		else printf("IMPOSSIBLE\n");
	}
}

Measured memory_bytes: 640
N = int(input())
S = input().strip()
C = {"R":[],"G":[],"B":[]}
for i in range(N):
    C[S[i]].append(i)
C["B"] = set(C["B"])
cnt = 0
for r in C["R"]:
    for g in C["G"]:
        if r<g:
            i = r
            j = g
        else:
            i = g
            j = r
        cnt += len(C["B"])
        if i-(j-i) in C["B"]:
            cnt -= 1
        if j+(j-i) in C["B"]:
            cnt -= 1
        if (j+i)%2==0 and (j+i)//2 in C["B"]:
            cnt -= 1
print(cnt)

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

ll floor(ll a, ll b, ll x){
    return a*x/b - a*(x/b);
}

int main(void) 
{
    ll a, b, n;
    cin >> a >> b >> n;
    ll ans =0;
    ll x = n;
    if(n >= b-1) x = b-1;
    ans = floor(a,b,x);
    cout << ans << endl;
}

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

int main(void){
    int N, M;
    cin >> N >> M;
    vector<int> v(M, 0);
    int K;
    int A;
    for(int i{0}; i<N; ++i){
        cin >> K;
        for(int j{0}; j<K; ++j){
            cin >> A;
            ++v[A-1];
        }
    }
    int sum{0};
    for(int i{0}; i<M; ++i){
        if(v[i]==N)
            ++sum;
    }
    cout << sum << endl;
    
}


Measured memory_bytes: 256
/*created by tanishk gupta*/
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef vector<int> VI;
typedef long long int ll;
typedef pair<int,int> PII;
typedef double db;
mt19937 mrand(random_device{}());
const ll MOD=1e9+7;
const ll mod=1e9+7;
//const llint MOD;
const int N=(int)(2*1e5+10);
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
ll add(ll a,ll b){return ((a%MOD)+(b%MOD))%MOD;}
ll mul(ll a,ll b){return ((a%MOD)*(b%MOD))%MOD;}
ll sub(ll a,ll b){return ((a%MOD)-(b%MOD)+MOD)%MOD;}
ll binpow(ll x, ll y){ll z = 1;while(y){if(y & 1) z = mul(z, x);x = mul(x, x);y >>= 1;}return z;}
int inv(int x){return binpow(x, MOD - 2);}
int divide(int x, int y){return mul(x, inv(y));}
//int fact[N];
//void precalc(){fact[0] = 1;for(int i = 1; i < N; i++)fact[i] = mul(fact[i - 1], i);}
//int C(int n, int k){return divide(fact[n], mul(fact[k], fact[n - k]));}
//bool prime[N];
//void sieve() {for(int i=2;i<N;i++) {prime[i]=true;}for (int p=2; p*p<=N; p++){if (prime[p] == true){for (int i=p*p; i<=N; i += p)prime[i] = false;}}}
ll legendpow(ll n, ll p){ll total = 0;while (n){n /= p;total += n;}return total;}

//head==================================================================================

int main()
{ IOS;
int n;
cin>>n;
ll a[n+1];
ll ans=0;
a[0]=0;
rep(i,1,n+1){
    cin>>a[i];
 //   if (i)  {ans+=t;}
}
sort(a,a+n+1);
rep(i,1,n)
{
    int index=n-floor(i/2);
    ans+=a[index];
}
cout<<ans<<endl;
}

Measured memory_bytes: 5148
#include <stdio.h>
#include <stdlib.h>

int main()
{
    int h,w,i,j,flag,flag2;
    char temp;
    int a[50][50];
    scanf("%d%d",&h,&w);
    scanf("%c",&temp);
    for(i=0;i<h;i++)
    {
        for(j=0;j<w;j++)
        {
            scanf("%c",&temp);
            if(temp=='#')
                a[i][j]=1;
            else a[i][j]=0;
        }
            scanf("%c",&temp);
    }
    flag2=0;
        for(i=0;i<h;i++)
    {
        for(j=0;j<w;j++)
        {
            flag=0;
            if(a[i][j]==0)
                continue;
            if(a[i][j]==1)
            {
                if(a[i+1][j]+a[i][j+1]+a[i-1][j]+a[i][j-1]>=1&&i>0&&i<h-1&&j<w-1&&j>0)
                flag=1;
                else if(a[i][j+1]+a[i-1][j]+a[i][j-1]>=1&&i==h-1)
                flag=1;
                else if(a[i+1][j]+a[i-1][j]+a[i][j-1]>=1&&j==w-1)
                flag=1;
                else if(a[i+1][j]+a[i][j+1]+a[i][j-1]>=1&&i==0)
                flag=1;
                else if(a[i+1][j]+a[i][j+1]+a[i-1][j]>=1&&j==0)
                flag=1;
            }
            if(flag==0)
            {
                flag2=1;
                break;
            }


        }
        if(flag2==1)
            break;
    }
    if(flag2==1) printf("No");
    else printf("Yes");

    return 0;
}


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

int main(){
  int a,b,c;
  cin >> a >> b >> c;
  bool ans = false;
  for(int i=1; i<=1000000; i++){
    if(a*i%b==c) ans=true;
  }
  
  if(ans) cout << "YES" << endl;
  else cout << "NO" << endl;
  
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();

        int[] h = new int[n];
        for (int i = 0; i < n; i++) {
            h[i] = sc.nextInt();
        }

        int count = 0;
        boolean flag = false;
        int sum = Arrays.stream(h).sum();

        while (sum != 0) {
            for (int i = 0; i < n; i++) {
                if (h[i] > 0) {
                    if (!flag) {
                        flag = true;
                        count++;
                    }
                    h[i]--;
                    sum--;
                } else {
                    flag = false;
                }
            }
            flag = false;
        }

        System.out.print(count);
    }
}


Measured memory_bytes: 28240
/*
ID: jayyesh
LANG: C++                 
*/

#include <iostream>
#include <algorithm>
#include <string>
using namespace std;

int main()
{
    int n,i,flag=0;
    cin>>n;
    int arr[n];
    for(i=0;i<n;i++)
    {
        cin>> arr[i];
    }
    sort(arr, arr+n);
    for(i=0;i<n;i++)
    {
        if(arr[i]==arr[i+1] || arr[i] == arr[i-1])
        {
            flag =0;
            break;
        }
        else
        {
            flag =1;
        }
    }
    if(flag)
        cout<<"YES";
    else
    {
        cout<<"NO";
    }
    
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <utility>
#include <set>
#include <stack>
#include <climits>
#include <cmath>

#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define MEMSET(v, h) memset((v), h, sizeof(v))
typedef long long ll;
const char sp = ' ';


using namespace std;

int main(void){
    string S;
    cin>>S;
    ll count=0, Maxim=0;
    rep(i, S.size()){
        if(S[i]=='A' || S[i]=='C' || S[i]=='G' || S[i]=='T') count++;
        else{
            Maxim=max(Maxim, count);
            count=0;
        }
    }
    Maxim=max(Maxim, count);
    cout<<Maxim<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <algorithm>
#include <functional>
#include <string>
#include <iostream>
using namespace std;

int main() {
        string s;
        cin >> s;
        int k;
        scanf("%d", &k);
        int n = s.size();
        vector<vector<vector<int>>> dp(n + 1, vector<vector<int>> (n + 1, vector<int> (n + 1, -1)));
        function<int (int, int, int)> calc = [&](int l, int r, int t) {
                if (dp[l][r][t] != -1) return dp[l][r][t];
                if (l > r) return 0;
                if (l == r) return 1;
                int ma = 0;
                if (s[l] == s[r]) ma = max(ma, calc(l + 1, r - 1, t) + 2);
                ma = max(ma, calc(l + 1, r, t));
                ma = max(ma, calc(l, r - 1, t));
                if (t > 0) ma = max(ma, calc(l + 1, r - 1, t - 1) + 2);
                return dp[l][r][t] = ma;
        };
        printf("%d\n", calc(0, n - 1, k));
        return 0;
}


Measured memory_bytes: 110336
#include <iostream>
#include <string>
#include <cstring>
#include <cstdio>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <iomanip>
//#include <unordered_map>
//#include <unordered_set>
using namespace std;
#define fi first
#define se second
#define ll long long
#define pb push_back
#define vi vector<int>
#define pii pair<int,int>
#define mem(a,b) memset(a,b,sizeof(a))
#define IOS ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0);
const int INF = 0x3f3f3f3f;

inline int read () {
	register int s = 0, w = 1;
	register char ch = getchar ();
	while (! isdigit (ch)) {if (ch == '-') w = -1; ch = getchar ();}
	while (isdigit (ch)) {s = (s << 3) + (s << 1) + (ch ^ 48); ch = getchar ();}
	return s * w;
}

ll a[10];
int s1[10],s2[10],vis[10];
int main() {
	IOS;
	//freopen("D:\\in.txt","r",stdin);
	//freopen("D:\\out2.txt","w",stdout);
	for(int i=1;i<=8;i++){
		ll sum=1;
		for(int j=1;j<=i;j++){
			sum*=j;
		}
		a[i]=sum;
	}
	ll ans1=0,ans2=0;
	int n;
	cin>>n;
	for(int i=1;i<=n;i++)cin>>s1[i];
	for(int i=1;i<=n;i++)cin>>s2[i];
	for(int i=1;i<=n;i++){
		vis[s1[i]]++;
		ll cnt=0;
		for(int j=1;j<=s1[i];j++){
			if(!vis[j]){
				cnt++;
			}
		}
		cnt*=a[n-i];
		ans1+=cnt;
	}
	mem(vis,0);
	for(int i=1;i<=n;i++){
		vis[s2[i]]++;
		ll cnt=0;
		for(int j=1;j<=s2[i];j++){
			if(!vis[j]){
				cnt++;
			}
		}
		cnt*=a[n-i];
		ans2+=cnt;
	}
	cout<<abs(ans1-ans2)<<endl;
	
	
	


	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <numeric>
#include <string>
#include <cstdlib>
#include <vector>
#include <cstdint>

#define _rep_overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _rep_overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)

#define _rrep_overload3(_1,_2,_3,name,...) name
#define _rrep(i,n) rrepi(i,n,0)
#define rrepi(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _rrep_overload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__)

using namespace std;

// Globals

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

  int N, M;
  cin >> N >> M;

  long a = 1900 * M + 100 * (N-M);
  long p = 1 << M;
  long q = p - 1;
  long ans = a * p * p / (p*(p-q)*(p-q));

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;

#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, n) for(ll i = 1; i < n + 1; i++)
#define PI 3.14159265359
#define EPS 0.0000000001
#define MOD 1000000007
//cout << std::fixed << std::setprecision(15) << y << endl;


int main(){
    ll N, X;
    cin >> N >> X;

    ll L[N];
    rep(i, N){
        cin >> L[i];
    }

    ll D = 0;
    ll count = 0;
    while(D <= X && count < N + 1){
        D += L[count];
        count++;
    }

    cout << count << endl;

    return 0;
}

Measured memory_bytes: 3588
#include <stdio.h>

int main(void){
  char s[9];
  int c=0, i=0;
  scanf("%s",s);
  for(;i<3;i++){
    if(s[i] =='1')
      c += 1;
  }
  printf("%d\n",c);

  return 0;
}

      
      


Measured memory_bytes: 128
#include<bits/stdc++.h>
 
using namespace std;
typedef long long ll;
typedef long double ld;
 
typedef pair<ll, ll> pll;
typedef vector<ll> vll;
typedef vector<pll> vpll;
typedef vector<vll> vvll;
typedef vector<ld> vld;
typedef map<ll,ll> mpll;
typedef set<ll> setll;
typedef multiset<ll> msetll;
 
#define F first
#define S second
#define pb push_back
#define mp make_pair 

const ll inf = ll(1e18);
const ll MOD = (1e9 + 7);

int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #ifdef DEBUG_
		freopen("input.txt","r",stdin);
	#endif
	cout.setf(ios::fixed), cout.precision(20);
    ll n;
    cin >> n;
    string s,t;
    cin >> s >> t;
    for(int i=0;i<n;i++){
        cout<<s[i]<<t[i];
    }
    cout<<"\n";
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define maxn 200100
#define mod 1000000007
using namespace std;
struct edge{
	int r,nxt;
}e[maxn<<1];
int vis[maxn],q[maxn],head[maxn],esz,dp[maxn];
vector<int>used;
int a[maxn],eg,dt,sz[maxn],b[maxn],n,f[maxn],fa[maxn],ans=1,fac[maxn],inv[maxn];
int qpow(int a,int b){
	int ans=1,tmp=a;
	for(;b;b>>=1,tmp=1ll*tmp*tmp%mod)
		if(b&1)ans=1ll*ans*tmp%mod;
	return ans;
}
int C(int x,int y){
	if(x<0||x>y)return 0;
	return 1ll*fac[y]*inv[x]%mod*inv[y-x]%mod;
}
int find(int x){
	return x==f[x]?x:f[x]=find(f[x]);
}
int calc(int u,int to){
	if(sz[u])return sz[u];
	sz[u]=1;
	for(int t=head[u];t;t=e[t].nxt)if(e[t].r<to)
		calc(e[t].r,u),sz[u]+=sz[e[t].r];
	return sz[u];
}
void dfs(int u,int f){
	q[++dt]=u,vis[u]=1;
	for(int t=head[u];t;t=e[t].nxt,eg++)if(e[t].r!=f)
		if(!vis[e[t].r])dfs(e[t].r,u);
}
void init(int u,int f,int fz){
	fa[u]=f;
	for(int t=head[u];t;t=e[t].nxt)if(e[t].r!=f&&e[t].r!=fz)
		init(e[t].r,u,fz);
}
int solve(int bg,int ed){
	init(bg,0,bg),fa[bg]=ed;
	for(int i=1;i<=dt;++i)dp[q[i]]=sz[q[i]]=0;
	int ret=1;
	for(int i=1;i<=dt;++i)
		ret=1ll*ret*inv[calc(q[i],fa[q[i]])]%mod;
	return ret;
}
void addedge(int u,int v){
	e[++esz].r=v;e[esz].nxt=head[u];head[u]=esz;
	e[++esz].r=u;e[esz].nxt=head[v];head[v]=esz;
}
int main(){
	scanf("%d",&n),fac[0]=inv[0]=1;
	for(int i=1;i<=n*2;++i)fac[i]=1ll*fac[i-1]*i%mod;
	inv[n*2]=qpow(fac[n*2],mod-2);
	for(int i=n*2-1;i>=1;--i)inv[i]=1ll*inv[i+1]*(i+1)%mod,inv[i+1]=1ll*fac[i]*inv[i+1]%mod;
	
	for(int i=1;i<=n*2;++i)scanf("%d%d",&a[i],&b[i]),b[i]+=n,addedge(a[i],b[i]);
	for(int i=1;i<=n*2;++i)f[i]=i;
	int sum=n*2;
	for(int i=1;i<=n*2;++i){
		ans=1ll*ans*i%mod;
		if(find(a[i])==find(b[i])){
			dt=0,eg=0,dfs(a[i],0);
			if(dt*2!=eg)return puts("0"),0;
//			printf("[%d,%d]",dt,sum);
			ans=1ll*ans*(solve(a[i],b[i])+solve(b[i],a[i]))%mod;
			sum-=dt;
		} else {
			f[find(a[i])]=find(b[i]);
		}
	}
//	printf("[%d]",sum);
	if(sum!=0)puts("0");
	else printf("%d",ans);
}

Measured memory_bytes: 14592
#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>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
    int x, y;
    cin >> x >> y;
    cout << x + y/2 << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  vector<int> B(N-1);
  for(int i=0; i<N-1; i++){
    cin >> B.at(i);
  }
  
  int64_t ans = B.at(N-2);
  for(int i=N-2; i>0; i--){
    ans += min(B.at(i),B.at(i-1));
  }
  ans += B.at(0);
    
  cout << ans << endl;
}

Measured memory_bytes: 256
import std.stdio,
  std.array,
  std.range,
  std.conv,
  std.string,
  std.algorithm;

void main()
{
  int n = readln.chomp.to!int;
  int[] xs = readln.split.map!(to!int).array.sort().array;
  auto tako = zip(iota(0, xs.length), xs).filter!(a => a[0] % 2 == 0).array.map!(a => a[1]);
  writeln(sum(tako));
}


Measured memory_bytes: 256
# import copy
# from fractions import gcd
# from functools import reduce
# from itertools import accumulate, permutations, combinations, combinations_with_replacement, groupby, product
# import math
# import numpy as np
import sys

sys.setrecursionlimit(10 ** 5 + 10)


# input = sys.stdin.readline

def resolve():
    from heapq import heappush, heappop

    V, E, r = map(int, input().split())
    g = [[] for i in range(V)]

    for i in range(E):
        s, t, d = map(int, input().split())
        g[s].append((d, t))  # g[s]の要素(cost,t)はsからコストcostでtに直接行けることを意味する

    INF = 10 ** 10

    # 長点数V、直接移動先とコストを記したリストg、スタート地点rをとって、
    # rからiに行くまでの最低コストがdist[i]であることを意味するリストdistを返す関数
    def dijkstra(V, g, r):

        dist = [INF] * V
        queue = [(0, r)]  # queueの要素(c,v)は、コストcで直接vに行けることを意味する
        dist[r] = 0  # スタート地点rにはコスト0で行ける
        
        while queue:
            c, v = heappop(queue)
            if dist[v] < c:  # すでに記録されているコストの方が小さいので更新不要
                continue
            for cost, t in g[v]:
                if dist[v] + cost < dist[t]:
                    dist[t] = dist[v] + cost
                    heappush(queue, (dist[t], t))

        return dist

    for i in dijkstra(V, g, r):
        print(i if i < INF else "INF")


resolve()


Measured memory_bytes: 89280
#include <bits/stdc++.h>
using namespace std;
# define ll int
#define M 998244353
#define pb push_back                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 
 
							
 
 int main(){
   ios::sync_with_stdio(0);
   cin.tie(0); cout.tie(0);
   ll i,j,n,m,ans,h,hh,k,kk,ii,jj;
   cin>>n>>m;
   char a[n+5][m+5];
   for(i=0;i<n;i++){
   	for(j=0;j<m;j++){
   		cin>>a[i][j];
	   }
   }
   ll fans = 0;
   ll vis[n+5][m+5],lvl[n+5][m+5];
   queue<pair<ll,ll> > q;
   for(i=0;i<n;i++){
   	for(j=0;j<m;j++){
   		for(h = 0;h<n;h++){
   			for(hh=0;hh<m;hh++){
   				vis[h][hh] = 0;
   				lvl[h][hh] = 0;
			   }
		   }
   		if(a[i][j] == '#')	continue;
   		q.push({i,j});
   		lvl[i][j] = 0;
   		vis[i][j] = 1;
	   	while(!q.empty()){
	   	pair<ll,ll> r = q.front();
	   		q.pop();
	   		ii = r.first;
	   		jj = r.second;
	   		for(k=-1;k<2;k++){
	   			for(kk=-1;kk<2;kk++){
	   				if((abs(k) + abs(kk) == 1) && (ii+k < n) && (ii+k >=0) && (jj+kk >=0) && (jj+kk <m)){
	   					if(vis[ii+k][jj+kk] == 0 && a[ii+k][jj+kk]!='#'){
	   						q.push({ii+k,jj+kk});
	   						lvl[ii+k][jj+kk] = lvl[ii][jj] + 1;
	   						vis[ii+k][jj+kk] = 1;
						   }
					   }
				   }
			   }
		   }
		   ll ans = 0;
		   	for(h = 0;h<n;h++){
   			for(hh=0;hh<m;hh++){
   					ans = max(ans,lvl[h][hh]);
			   }
		   }
		 //  cout<<i<<" "<<j<<" "<<ans<<endl;
		   fans = max(fans,ans);
		   
	   }
   	
   }
   cout<<fans;
   
}

Measured memory_bytes: 256
//(a-b)^2>c*(2a+2b-c) 
#include <iostream>
using namespace std;

int main()
{
	int a,b,c;
	while(cin >> a >> b >> c){
		if(c - a - b <= 0){
			cout << "No" << endl;
			continue;
		}
		long long x = 1ll * (a - b) * (a - b);
		long long y = 1ll * c * (2 * a + 2 * b - c);
		if(x > y)
			cout << "Yes" << endl;
		else
			cout << "No" << endl;
	}
	return 0;	
}

Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
typedef  unsigned long long int ull;
typedef pair<ll,ll> P;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
//const ll mod=998244353;
const ll mod=1000000007;
//ios_base::sync_with_stdio(false);
//cin.tie(NULL);
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
int main(){
ll n,m,p;
while(1){
    cin>>n>>m>>p;
    if(n==0||m==0)return 0;
    V<ll> a(n,0);
    ll sum=0;
    for(int i=0;i<n;i++){
        cin>>a[i];
        sum+=a[i];
    }
   if(a[m-1]==0)cout<<0<<endl;
   else cout<<sum*(100-p)/a[m-1]<<endl;
  }
}


Measured memory_bytes: 3144
n,k = map(int,input().split())

ans = 0

for i in range(1,n+1):
    if i>=k:
        ans += (1/n)
        continue
    x = 1
    while 1:
        i *= 2
        if i>=k:
            break
        else:x+=1
    ans += (1/n)*(1/2)**x
print(ans)

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

int main() {
    int N, A, B;
    cin >> N >> A >> B;
    vector<int> xs = {A, B};
    vector<int> t(N);
    for(int i = 0; i < N; ++i) {
        cin >> t[i];
        xs.push_back(t[i]);
    }
    sort(xs.begin(), xs.end());
    xs.erase(unique(xs.begin(), xs.end()), xs.end());
    vector<int> cnt(xs.size() + 1);
    for(int i = 0; i < N; ++i) {
        t[i] = lower_bound(xs.begin(), xs.end(), t[i]) - xs.begin();
        cnt[t[i]]++;
    }
    int s = lower_bound(xs.begin(), xs.end(), A) - xs.begin();
    int e = lower_bound(xs.begin(), xs.end(), B) - xs.begin();
    int res = 0;
    for(int i = s; i < e; ++i) {
        res += (cnt[i] != 0);
    }
    res = N - res;
    cout << res << endl;
}


Measured memory_bytes: 256
N = int(input())
a = [int(s) for s in input().split()]
ans = int(0)
temp = int(0)
MOD = int(1000000007)
sumari = sum(a)

for i in range(N-1):
  sumari = sumari - a[i] 
  temp = sumari % MOD
  temp = temp * a[i]
  temp = temp % MOD
  ans += temp
  ans = ans % MOD
print(ans)

Measured memory_bytes: 31520
A,B,C,D,E,F=map(int, raw_input().split())
max_sugar=int(float(E)/(100+E)*F)

a=set()
for i in range(max_sugar+1):
	for j in range(max_sugar):
		#print i,j
		if i*C+D*j<= max_sugar:
			a.add(i*C+D*j)

b=set()
cnt=F/100
for i in range(cnt+1):
	for j in range(cnt+1):
		if A*i*100+B*j*100<=F and A*i*100+B*j*100!=0:
			b.add(A*i*100+B*j*100)

#print a
#print b

noudo=float(E)/(100+E)*100
max_noudo=0
ans=A*100,0

for i in a:
	for j in b:
		t_noudo=float(i)/(i+j)*100
		#print i,j
		if t_noudo <= noudo and t_noudo > max_noudo and i+j<=F:
			#print i,j,t_noudo
			max_noudo=t_noudo
			ans=i+j,i

print ans[0],ans[1]




Measured memory_bytes: 2696
#define print(x) printf("%d\n",x)

#include <queue>
typedef long long ll;

#include <iostream>
#define REP(i,n) for(int i=0; i<(int)(n); i++)

#include <cstdio>
inline int getInt(){ int s; scanf("%d", &s); return s; }

#include <set>

using namespace std;

ll calc(const vector<ll> &s, ll x, int b){
  const int n = s.size();
  ll ans = x * n + x * b;
  REP(i,n){
    const int k = i / b;
    const int m = k == 0 ? 5 : (5 + (k - 1) * 2);
    ans += m * s[i];
  }
  return ans;
}


int main(){
  const int n = getInt();
  const ll x = getInt();
  vector<ll> s(n);
  REP(i,n) s[n - 1 - i] = getInt();

  int mx = n;
  int mn = 1;
  REP(i,50){
    const int d = mx - mn;
    const int m1 = mn + d / 3;
    const int m2 = mn + 2 * d / 3;

    const ll a1 = calc(s, x, m1);
    const ll a2 = calc(s, x, m2);
    // printf("%d=%lld %d=%lld : %d %d\n", m1, a1, m2, a2, mn, mx);
    if(a1 < a2) mx = m2;
    else mn = m1;
  }

  ll ans = 1ll << 60;
  for(int i = mn; i <= mx; i++){
    ans = min(ans, calc(s, x, i));
    // printf("%d => %lld\n", i, calc(s, x, i));
  }
  printf("%lld\n", ans);

  return 0;
}

Measured memory_bytes: 1792
#ifndef LOCAL
#pragma GCC optimize("O3")
#endif
#include "bits/stdc++.h"
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
typedef long long ll;

int main(){
    int n ; 
    cin >> n ; 
    ll cnt[5] = {0}; 
    for(int i=0;i<n;i++){
    	string x ; 
    	cin >> x ; 
    	if ( x[0] == 'M' ) cnt[0]++;
    	if ( x[0] == 'A' ) cnt[1]++;
    	if ( x[0] == 'R' ) cnt[2]++;
    	if ( x[0] == 'C' ) cnt[3]++;
    	if ( x[0] == 'H' ) cnt[4]++;
    }
    vector<ll> v ; 
    for(ll &x : cnt){
    	if ( x != 0 )
    		v.push_back(x);
    }
    debug() << imie(v) ; 
    ll ans = 0 ; 
    for(int i=0;i<(int)v.size()-2;i++){
    	for(int j=i+1;j< (int) v.size()-1;j++){
    		for(int k=j+1;k< (int) v.size();k++){
    			ans += v[i]*v[j]*v[k] ; 
    		}
    	}
    }
    cout << ans << endl;
    return 0 ;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
    static int[] dx = {0, 1, 0, -1};
    static int[] dy = {1, 0, -1, 0};
    static int INF = 1000000000;
    static boolean[][] used;
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int h = sc.nextInt();
        int w = sc.nextInt();
        List<String> str = new ArrayList<>();
        for (int i = 0; i < h; i++) {
            str.add(sc.next());
        }

        used = new boolean[w][h];
        long ans = 0;
        for (int y = 0; y < h; y++) {
            for (int x = 0; x < w; x++) {
                if (used[x][y]) {
                    continue;
                }
                Point p = new Point(x, y);
                ans += bfs(p, str);
            }
        }
        System.out.println(ans);
    }
    public static long bfs(Point s, List<String> str) {
        long b = 0;
        long w = 0;
        Queue<Point> que = new LinkedList<>();
        que.offer(s);
        used[s.x][s.y] = true;
        while (!que.isEmpty()) {
            Point p = que.poll();
            if (str.get(p.y).charAt(p.x) == '#') {
                b++;
            } else {
                w++;
            }
            // System.out.println("p = " + p);
            for (int i = 0; i < 4; i++) {
                int ny = p.y + dy[i];
                int nx = p.x + dx[i];
                char ch = str.get(p.y).charAt(p.x);
                if (nx < 0 || ny < 0 || nx >= str.get(0).length() || ny >= str.size()) {
                    continue;
                }
                if (!check(ch, str.get(ny).charAt(nx))) {
                    continue;
                }
                if (used[nx][ny]) {
                    continue;
                }
                used[nx][ny] = true;
                // System.out.printf("nx = %d ,ny = %d %n", nx, ny);
                que.offer(new Point(nx, ny));
            }
        }
        return b * w;
    }
    public static boolean check(char ch1, char ch2) {
        if (ch1 != ch2) {
            return true;
        }
        return false;
    }
}
class Point {
    int x;
    int y;
    public Point(int x, int y) {
        this.x = x;
        this.y = y;
    }
    public String toString() {
        return String.format("(x = %d,y = %d)", this.x, this.y);
    }
}


Measured memory_bytes: 34924
def solve(a, b, q, al, bl, ql):
    sql = sorted(ql)
    adic = search(al, q, sql)
    bdic = search(bl, q, sql)
    qstep(adic, bdic, ql)


limit_begin = -1
limit_end = 10 ** 10 + 1
def search(tl, q, sql):
    z = list(zip([limit_begin] + tl, tl + [limit_end]))
    zi = 0
    dic = {}
    for e in sql:
        while(True):
            begin, end = z[zi]
            if (begin <= e) and (e <= end):
                dic[e] = (begin, end)
                break
            else:
                zi += 1
                if zi == (q + 1):
                    raise "system error"

    return dic

def qstep(adic, bdic, ql):
    
    for e in ql:
        asmall, abig = adic[e]
        bsmall, bbig = bdic[e]
        
        answer = 2 * (10 ** 10)
    
        # small , small
        if (asmall != limit_begin) and (bsmall != limit_begin):
            t = min(asmall,bsmall)
            v = e - t
            if v < answer:
                answer = v

        # big , big
        if (abig != limit_end) and (bbig != limit_end):
            t = max(abig,bbig)
            v = t - e
            if v < answer:
                answer = v

        # small , big
        if( asmall != limit_begin) and (bbig != limit_end):
            v = (bbig - asmall) + min(bbig - e, e - asmall)
            if v < answer:
                answer = v

        # big , small
        if( abig != limit_end) and (bsmall != limit_begin):
            v = (abig - bsmall) + min(abig - e, e - bsmall)
            if v < answer:
                answer = v

        print(answer)

        
a, b, q = map(int,input().split())

al = []
for i in range(a):
    al.append(int(input()))
bl = []
for i in range(b):
    bl.append(int(input()))
ql = []
for i in range(q):
    ql.append(int(input()))

solve(a, b, q, sorted(al), sorted(bl), ql)


Measured memory_bytes: 55592