akhauriyash/Code-Regression huggingface dataset:
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Scanner;

class Main {

    static final int MOD = 1000000007;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int T = sc.nextInt();
        int A = sc.nextInt();
        double[] hei = new double[N];
        int sum = 0;
        for (int i = 0; i < N; i++) {
            hei[i] = Math.abs(A-(T-sc.nextInt()*0.006));
        }
        double min = Double.MAX_VALUE;
        int c = -1;
        for (int i = 0; i < N; i++) {
            if(min>hei[i]){
                min=hei[i];
                c=i;
            }
        }
        System.out.println(c+1);
        
    }
}

Measured memory_bytes: 22356
# -*- coding: utf-8 -*-
N, A, B = map(int, input().split(' '))

if A > B:
    print(0)

elif N == 1:
    if A != B:
        print(0)
    else:
        print(1)

else:
    min_n = A * (N - 1) + B
    max_n = A + (N - 1) * B
    print(max_n - min_n + 1)



Measured memory_bytes: 38384
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int i,a,b,c,d;
    cin >> a;
    vector<int>vec;
    while(a--)
    {
        cin >> b;
        vec.push_back(b);
    }
    int m=0;
    for(i=1;i<vec.size()-1;i++)
    {
        if((vec[i-1]>vec[i] && vec[i]>vec[i+1]) || (vec[i-1]<vec[i] && vec[i]<vec[i+1]))
        {
            m++;
        }
    }
    cout << m << endl;



}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include <numeric>
#include <queue>
#include <numeric>
#include <iomanip>
#include <sstream>
#include <cmath>
#include <map>
#include <functional>
#include <limits>
#include <set>
#define rep(i,a,b) for((i)=a;i<(int)(b);i++)
#define max(a,b) ((a) < (b) ? (b) : (a))
#define min(a,b) ((a) > (b) ? (b) : (a))
#define AAA (1000000007)

using namespace std;
typedef long long ll;
typedef unsigned long long ull;



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

ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}



int main() {
	int i, j, k;
	ll N, M, K;
	ll ans = 0;

	cin >> N >> M >> K;
	queue<int> Q;

	vector<vector<int>> A(100000);
	vector<vector<int>> B(100000);
	int Follow[100000] = { 0 };
	int Block[100000] = { 0 };
	int color[100000] = { 0 };
	int Cel[100000] = { 0 };
	int eachCelNum[100000] = { 0 };
	rep(i, 0, M) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		A[a].push_back(b);
		A[b].push_back(a);
		Follow[a]++;
		Follow[b]++;
	}
	rep(i, 0, K) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		B[a].push_back(b);
		B[b].push_back(a);
	}
	int sum = 0;
	int x = 0;
	int ppp = 0;
	int celNum = -1;
	while (sum < N) {
		celNum++;
		for (; ppp < N && color[ppp] != 0; ppp++) {
		}
		x = ppp;
		color[x] = 1;
		Q.push(x);
		Cel[celNum]++;
		eachCelNum[x] = celNum;
		sum++;
		while (!Q.empty()) {
			x = Q.front();
			Q.pop();
			for (auto qq : A[x]) {
				if (color[qq] == 0) {
					color[qq] = 1;
					Cel[celNum]++;
					Q.push(qq);
					eachCelNum[qq] = celNum;
					sum++;
				}
			}

		}



	}

	rep(i, 0, N) {
		int minus = 0;
		for (auto qq : B[i]) {
			if (eachCelNum[qq] == eachCelNum[i])
				minus++;
		}

		cout << Cel[eachCelNum[i]] - 1 - minus - Follow[i];
//		cout << Cel[eachCelNum[i]] << " " <<Block[i] << " " << Follow[i];

		cout << " ";
	}
	return 0;


}


Measured memory_bytes: 13816
#include <bits/stdc++.h>
using namespace std;
int main(){
	int N; long long int Y; 
	cin >> N >> Y; 
	long long int X[200010] = {}; 
	long long int S[200010] = {}; 
	for(int i = 0; i < N; i++){
		cin >> X[N - i]; 
	}
	long long int C[200010] = {}; // 係数
	C[0] = 5; C[1] = 5; 
	for(int i = 2; i <= N; i++){
		C[i] = C[i-1] + 2; 
	}
	for(int i = 1; i <= N; i++){
		S[i] = S[i-1] + X[i]; 
	}
	long long int M[200010] = {}; // i回に分けて捨てるときの最小値
	long long int INF = 2e15; // どこかで打ち切らないと、最適でないケースでlonglongでも溢れるぞ
	for(int i = 1; i <= (N+1)/2; i++){
		long long int tmp = (long long) (N + i) * Y; 
		int k = N / i; 
		for(int j = 0; j < k; j++){
			tmp += C[j] * (S[(j+1) * i] - S[j * i]); 
			if(tmp > INF) break; 
		}
		tmp += C[k] * (S[N] - S[k * i]); 
		M[i] = min(tmp, INF); 
	}
	long long int ans = INF; 
	for(int i = 1; i <= (N+1)/2; i++){
		ans = min(M[i], ans); 
	}
	cout << ans << endl; 
}

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

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl




typedef long long ll;
const ll mod = 1e9+7;
const int maxn = 1e6 + 5;


int n;

map<ll,ll> mp;

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);  cout.tie(0);
    cin>>n;

    ll ans = 0;
    for (int i=1; i<=n; i++) {
	ll x; cin>>x;
	ans += mp[i-x];
	mp[i+x]++;
    }

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


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

using namespace std;
typedef long long ll;
int N,A;
int x[51];
ll dp[51][5001];
int main() {
  cin >> N >> A;
  int MAX = 0;
  for(int i = 0; i < N; i++) {
    cin >> x[i];
    MAX = max(MAX,x[i]);
    x[i] -= A;
  }


  dp[0][MAX * N] = 1;

  for(int i = 0; i < N; i++) {
    for(int k = 0; k < 2 * MAX * N; k++) {
      if(dp[i][k]) {
	dp[i+1][k+x[i]] += dp[i][k];
	dp[i+1][k] += dp[i][k];
      }
    }
  }

  cout << dp[N][MAX*N] - 1 <<endl;
}

  


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

int main()
{
    int N,M,a[50]={0};
    cin >> N >> M;
    int k;
    for(int i=0; i<M*2; i++){
        cin >> k;
        a[k]++;
    }
    for(int i=1; i<=N; i++){
        cout << a[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N=105,M=1e9+7;
int n,m,dp[N][N*N],ans,a[N],s;
signed main(){
	scanf("%lld%lld",&n,&a[1]);s+=a[1];
	for (int i=2;i<=n;i++)a[i]=a[1],s+=a[i];
	dp[n][0]++;
	for (int i=n;i;i--)
		for (int j=0;j<=s;j++)
			if (dp[i][j])for (int k=0;k<=a[i];k++)
				if (k<=i)(dp[i-1][j+(k+j)/i]+=dp[i][j])%=M;
				else (dp[i-1][j]+=dp[i][j])%=M;
	for (int j=0;j<=s;j++)(ans+=M-dp[0][j]*j%M)%=M;
	int fac=1;
	for (int i=1;i<=n;i++){
		int fac=1;
		for (int j=1;j<=n;j++)
			if (j!=i)(fac*=a[j]+1)%=M;
		for (int j=0;j<=a[i];j++)(ans+=fac*j)%=M;	
	}
	printf("%lld\n",ans);
	return 0;
}

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

int main()
{
	int H, W;
	cin >> H >> W;
	while (H != 0 && W != 0)
	{
		for (int i = 0; i < H; i++)
		{
			for (int j = 0; j < W; j++)
			{
				if ((i + j) % 2 == 0) {
					cout << "#";
				}
				else {
					cout << ".";
				}
			}
			cout << endl;
		}
		cout << endl;
		cin >> H >> W;
		
	}
	
	
}


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

struct node{
  unsigned int key;
  struct node *next;
  struct node *prev;
};

typedef struct node * NodePointer;

NodePointer nil;

NodePointer listSearch(int key){
  NodePointer cur;

  cur = nil->next;
  while(cur->key != key && cur != nil){
    cur = cur->next;
  }/*ちなみにfor文だとTELになっちゃうんだよタコ助*/
    return cur;
}

void init(){
  nil = malloc(sizeof(struct node));
  nil->next = nil;
  nil->prev = nil;
}

void printList(){
  NodePointer cur = nil->next;
  int isf = 1;
  while(1){
    if ( cur == nil ) break;
    if ( isf == 0)  printf(" ");
    printf("%d", cur->key);
    cur = cur->next;
    isf = 0;
  }
  printf("\n");
}

void deleteNode(NodePointer t){
  if(t == nil){
    return;
  }
  t->prev->next = t->next;
  t->next->prev = t->prev;

  free(t);/*解放してやってるぜへへへ*/
}

void deleteFirst(){
  NodePointer t = nil->next;
  if ( t == nil ) return;
  deleteNode(t);
}

void deleteLast(){
  deleteNode(nil->prev);
}

void delete(int key){
  /*検索したノードをぶっ壊す*/
  deleteNode(listSearch(key));
}


void insert(int key){
  NodePointer x;

  x = malloc(sizeof(struct node));
  x->key = key;
  /*番兵君直後に要素を追加うなう*/
  x->next = nil->next;
  nil->next->prev = x;
  nil->next = x;
  x->prev = nil;
}

int main(){
  int key, n, i;
  int size = 0;
  char com[20];
  int np = 0, nd = 0;
  scanf("%d", &n);
  init();
  for ( i = 0; i < n; i++ ){
    scanf("%s%d", com, &key);
    if ( com[0] == 'i' ) {
      insert(key); 
      np++; 
      size++;
    }else if ( com[0] == 'd' ) {
      if (strlen(com) > 6){
       if ( com[6] == 'F' ) deleteFirst();
       else if ( com[6] == 'L' ) deleteLast();
     } else {
       delete(key); nd++; 
     }
     size--;
   }
 }

 printList();
 return 0;
}



Measured memory_bytes: 32956
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define rep(i, s, e) for (int i = s; i < e; i++)
#define endl '\n'
int main()
{
    int N, K;
    cin >> N >> K;
    vector<int> d(K);
    vector<int> P(N);
    int res = 0;
    rep(i, 0, N) P[i] = 0;
    rep(i, 0, K)
    {
        cin >> d[i];
        rep(j, 0, d[i])
        {
            int tmp;
            cin >> tmp;
            P[tmp-1]++;
        }
    }
    rep(i, 0, N)
    {
        if (P[i] == 0)
            res++;
    }
    cout << res << endl;
}

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

#define ll long long
#define vvi vector< vector<int> >
#define vi vector<int>
#define All(X) X.begin(),X.end()
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back
#define pii pair<int,int>
#define mp make_pair
#define pi 3.14159265359
#define shosu(X) fixed << setprecision(X)
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int main(){
int sx,sy,tx,ty;
cin >> sx >> sy >> tx >> ty;
REP(i,ty-sy) cout << "U";
REP(i,tx-sx) cout << "R";
REP(i,ty-sy) cout << "D";
REP(i,tx-sx) cout << "L";
cout << "L";
REP(i,ty-sy+1) cout << "U";
REP(i,tx-sx+1) cout << "R";
cout << "D";
cout << "R";
REP(i,ty-sy+1) cout << "D";
REP(i,tx-sx+1) cout << "L";
cout << "U" << endl;
}



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

using namespace std;
using ll = long long;
// #define int ll
using PII = pair<ll, ll>;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()

template<typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template<typename T> bool IN(T a, T b, T x) { return a<=x&&x<b; }
template<typename T> T ceil(T a, T b) { return a/b + !!(a%b); }

template<typename T> vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts) {
    return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type
fill_v(T &t, const V &v) { t=v; }
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t, const V &v ) { for(auto &e:t) fill_v(e,v); }

int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0}; // DRUL
const int INF = 1<<30;
const ll LLINF = 1LL<<60;
const ll MOD = 1000000007;

string to_string(string s) { return '"' + s + '"'; }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A, typename B>
string to_string(pair<A, B> p) {
    return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A>
string to_string(A v) {
    bool first = true;
    string res = "{";
    for (const auto &x : v) {
        if (!first) res += ", ";
        first = false;
        res += to_string(x);
    }
    res += "}";
    return res;
}

void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << to_string(H);
    debug_out(T...);
}

// #define LOCAL
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

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

    ll h, w, n, sx, sy;
    cin >> h >> w >> n >> sy >> sx;
    sx--, sy--;
    string s, t;
    cin >> s >> t;

    ll xl = 0, xu = w-1, yl = 0, yu = h-1;
    for(ll i=n-1; i>=0; --i) {
        if(t[i] == 'R') xl = max(0LL, xl-1);
        else if(t[i] == 'L') xu = min(w-1, xu+1);
        else if(t[i] == 'D') yl = max(0LL, yl-1);
        else if(t[i] == 'U') yu = min(h-1, yu+1);
        if(yl > yu || xl > xu) {
            cout << "NO" << endl;
            return 0;
        }
        debug(i, xl, xu, yl, yu);

        if(s[i] == 'R') xu--;
        else if(s[i] == 'L') xl++;
        else if(s[i] == 'D') yu--;
        else if(s[i] == 'U') yl++;
        if(yl > yu || xl > xu) {
            cout << "NO" << endl;
            return 0;
        }
        debug(i, xl, xu, yl, yu);
    }

    if(yl <= sy && sy <= yu && xl <= sx && sx <= xu) cout << "YES" << endl;
    else cout << "NO" << endl;

    return 0;
}


Measured memory_bytes: 920
import std.stdio;
import std.algorithm;
import std.range;
import std.conv;

int f(int n, int m, int k) {
    if (n < m) return max(0, n-k+1);
    return f(n%m, m, k) + (n/m)*(m-k);
}

void main() {
    string[] input = split(readln());
    int n = to!int(input[0]);
    int k = to!int(input[1]);
    long ans = 0;
    foreach (i; k+1 .. n+1) {
        ans += f(n,i,k);
        if (k == 0) ans--;
    }
    writeln(ans);
}

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

using i32 = std::int_fast32_t;
using i64 = std::int_fast64_t;
template <typename T>
constexpr T INF = numeric_limits<T>::has_infinity ? numeric_limits<T>::infinity() : numeric_limits<T>::max() / 2;

#define REP(i, stop) FOR(i, 0, stop)
#define FOR(i, start, stop) for (int i = start, i##_len = stop; i < i##_len; ++i)
#define RREP(i, n) for (int i = n; i-- > 0;)
#define ALL(v) (v).begin(), (v).end()

template<typename T>
istream& operator>>(istream& in, vector<T>& a) { for (T& x : a) cin >> x; }

void LOG(const int& x) { cerr << x << "\n"; }
void LOG(const vector<int>& a) { for (int x : a) cerr << x << " "; cerr << "\n"; }

int ceil(int a, int b) { return (a - 1) / b + 1; }
i64 gcd(i64 a, i64 b) { while (b != 0) { i64 t = b; b = a % b; a = t; } return a; }
i64 lcm(i64 a, i64 b) { return a / gcd(a, b) * b; }
i64 gcd(const vector<i64>& v) { return accumulate(ALL(v), 1LL, static_cast<i64(*)(i64, i64)>(gcd)); }
i64 lcm(const vector<i64>& v) { return v.empty() ? 0LL : accumulate(v.begin() + 1, v.end(), v[0], static_cast<i64(*)(i64, i64)>(lcm)); }

class UnionFind {
private:
  vector<int> par;
  vector<int> rnk;
  int find(int x) { return par[x] == x ? x : par[x] = find(par[x]); }
public:
  UnionFind(int size) { par.resize(size); rnk.resize(size); REP(i, size) par[i] = i, rnk[i] = 0; }
  void unite(int x, int y) { x = find(x); y = find(y); if (x == y) return; if (rnk[x] < rnk[y]) { par[x] = y; } else { par[y] = x; if (rnk[x] == rnk[y]) rnk[x]++; } }
  bool same(int x, int y) { return find(x) == find(y); }
};

struct InitCpp { InitCpp() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
} } initCpp;

signed main() {
  int h, w;
  cin >> h >> w;
  int ans = 0;
  if (h % 3 == 0 || w % 3 == 0) {
    ans = 0;
  } else {
    ans = min({
      h,
      w,
      max({
        abs((h / 3) * w - (h - h / 3) * (w / 2)),
        abs((h / 3) * w - (h - h / 3) * (w - w / 2)),
        (h - h / 3) * (w % 2)
      }),
      max({
        abs((h / 3 + 1) * w - (h - h / 3 - 1) * (w / 2)),
        abs((h / 3 + 1) * w - (h - h / 3 - 1) * (w - w / 2)),
        (h - h / 3 - 1) * (w % 2)
      }),
      max({
        abs((w / 3) * h - (w - w / 3) * (h / 2)),
        abs((w / 3) * h - (w - w / 3) * (h - h / 2)),
        (w - w / 3) * (h % 2)
      }),
      max({
        abs((w / 3 + 1) * h - (w - w / 3 - 1) * (h / 2)),
        abs((w / 3 + 1) * h - (w - w / 3 - 1) * (h - h / 2)),
        (w - w / 3 - 1) * (h % 2)
      })
    });
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
  
using namespace std;
  
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;

const int MAX_N = 5010;
int prv[MAX_N][MAX_N];
int dp[MAX_N][MAX_N];

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vi x(n);
    rep(i, n) cin >> x[i];
    if(n == 2) {
        cout << 2 << '\n';
        return 0;
    }
    sort(all(x));
    rep(i, MAX_N) rep(j, MAX_N) {
        prv[i][j] = -1;
        dp[i][j] = 2;
    }
    REP(j, 1, n-1) {
        int i = j+1;
        int k = j-1;
        while(i < n) {
            while(k >= 0 && x[i] - x[j] > x[j] - x[k]) {
                --k;
            }
            if(k >= 0 && x[i] - x[j] == x[j] - x[k]) prv[i][j] = k;
            ++i;
        }
    }
    REP(i, 1, n) rep(j, i) {
        int k = prv[i][j];
        if(k == -1) continue;
        dp[i][j] = max(dp[i][j], dp[j][k]+1);
    } 
    int ans = 0;
    rep(i, n) rep(j, i) ans = max(ans, dp[i][j]);
    cout << ans << '\n';
    return 0;
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define REP(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, a, b) for(int i=(a); i<(b); ++i)
#define FORR(i, a, b) for(int i=(b)-1; i>=(a); --i)

#define DEBUG(x) cout<<#x<<": "<<(x)<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";REP(i, v.size())cout<<' '<<v[i];cout<<'\n'
#define ALL(a) (a).begin(), (a).end()

template<typename T> inline void CHMAX(T& a, const T b) {if(a<b) a=b;}
template<typename T> inline void CHMIN(T& a, const T b) {if(a>b) a=b;}

constexpr ll MOD=1000000007ll;
// constexpr ll MOD=998244353ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

const double EPS=1e-11;
#define EQ0(x) (abs((x))<EPS)
#define EQ(a, b) (abs((a)-(b))<EPS)

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	// cout<<setprecision(10)<<fixed;
	ll n;
	cin>>n;
	ll ans=n*(n-1)/2;
	cout<<ans<<'\n';
	return 0;
}


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

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

using ll = long long;

int main() {
	ll ANS = 0;
	int K;
	cin >> K;
	rep(i, 1, K + 1)rep(j, 1, K + 1)rep(m, 1, K + 1)ANS += gcd(m, gcd(i, j));
	cout << ANS << "\n";
	return 0;
}

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

unsigned long long N, power[500009], inv[500009], L[500009]; int bx[500009]; string S;
map<unsigned long long, int>M;

int main() {
	cin >> N >> S;
	power[0] = 1; for (int i = 1; i <= 500000; i++) power[i] = (power[i - 1] * 1000000007LL);
	inv[0] = 1; for (int i = 1; i <= 500000; i++) inv[i] = (inv[i - 1] * 13499267949257065399ULL);

	L[0] = 0; int cx = 0;
	for (int i = 0; i < S.size(); i++) {
		if (S[i] == '>') cx++;
		if (S[i] == '<') cx--;
		if (S[i] == '+') L[i + 1] += power[250000 + cx];
		if (S[i] == '-') L[i + 1] -= power[250000 + cx];
		L[i + 1] += L[i];
		bx[i + 1] = cx;
	}

	long long cnt = 0;
	for (int i = N - 1; i >= 0; i--) {
		M[L[i + 1]]++;
		unsigned long long I = L[N];
		if (bx[i] > 0) I *= power[bx[i]];
		else I *= inv[-bx[i]];

		unsigned long long J = I + L[i];
		cnt += M[J];
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 44420
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#define ll long long
using namespace std;
typedef struct tt{
  ll a,b;
} tt;
int main(){
ll N,H,W,count=0;
cin>>N>>H>>W;
vector<tt> vec(N);
for(ll i=0;i<N;i++){
  cin>>vec[i].a>>vec[i].b;
}

for(ll i=0;i<N;i++){
  if(vec[i].a>=H&&vec[i].b>=W)
  count++;
}

printf("%lld",count);
}


Measured memory_bytes: 256
#include<iostream>
#include<cassert>
using namespace std;
#define FREE -1
#define NOT_FREE 1
int row[8],col[8],dir1[2*8-1],dir2[2*8-1];
bool x[8][8];

void init(){
  for(int i=0;i<8;i++){row[i]=FREE,col[i]=FREE;}
  for(int i=0;i<2*8-1;i++){dir1[i]=FREE,dir2[i]=FREE;}
}

void print(){
  for(int i=0;i<8;i++){
    for(int j=0;j<8;j++){
      if(x[i][j])if(row[i]!=j)return;
    }
  }
  for(int i=0;i<8;i++){
    for(int j=0;j<8;j++){
      if(row[i]==j) cout <<"Q";
      else cout << ".";
    }cout<<endl;
  }
}

void rec(int i){
  if(i==8){
    print();
    return;
  }

  for(int j=0;j<8;j++){
    if(col[j]==NOT_FREE || dir1[i+j] ==NOT_FREE || dir2[i-j+8-1]==NOT_FREE)continue;

    row[i]=j;
    col[j]=dir1[i+j]=dir2[i-j+8-1]=NOT_FREE;
    rec(i+1);
    row[i]=col[j]=dir1[i+j]=dir2[i-j+8-1]=FREE;
  }

}

int main(){
  init();
  for(int i=0;i<8;i++){
    for(int j=0;j<8;j++){
      x[i][j] = false;
    }
  }
  int k;
  cin >>k;

  for(int i=0;i<k;i++){
    int r,c; cin >>r >>c;
    x[r][c]=true;
  }

  rec(0);
  return 0;
}


Measured memory_bytes: 3104
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#define MaxN 200000+100
typedef long long LL;
LL loca[MaxN];
int main()
{
    int N;
    scanf("%d",&N);
    for(int i=0;i<N;i++)
        scanf("%lld",&loca[i]);
    LL ans=0;
    if(loca[0]!=0)
        printf("-1\n");
    else
    {
        bool flag=false;
        ans=loca[N-1];
        for(int i=N-2;i>=0;i--)
        {
                if(loca[i+1]>loca[i]+1)
                {
                    flag=true;
                    break;
                }
                else
                if(loca[i+1]==loca[i]+1)
                    continue;
                else
                    ans+=loca[i];
        }
        if(flag)
            printf("-1\n");
        else
        {
            printf("%lld\n",ans);
        }
    }
    return 0;
}


Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pl;
typedef vector<pl> vp;
#define fore(i,a,b) for(ll i=(a);i<=(b);++i)
#define rep(i,n) fore(i,0,(n)-1)
#define rfore(i,a,b) for(ll i=(b);i>=(a);--i)
#define rrep(i,n) rfore(i,0,(n)-1)
#define all(x) (x).begin(),(x).end()
const ll INF=1001001001;
const ll LINF=1001001001001001001;
const ll D4[]={0,1,0,-1,0};
const ll D8[]={0,1,1,0,-1,-1,1,-1,0};
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(b<a){a=b;return 1;}return 0;}
template<class T>
ll sum(const T& a){return accumulate(all(a),0LL);}

void solve(){
    ll n;cin>>n;
    ll ans=0;
    for(ll i=1;i<=n;i+=2){
        ll cnt=0;
        for(ll j=1;j*j<=i;j++){
            if(i%j==0){
                cnt++;
                if(j*j!=i)cnt++;
            }
        }
        if(cnt==8)ans++;
    }
    cout<<ans<<endl;
}

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define repp(i, m, n) for(int i = m; i < n; i++)
#define reps(i, n) for(int i = 1; i <= n; i++)
const int    INF = 100000000;
const double EPS = 1e-10;
const int    MOD = 1000000007;
using namespace std;
typedef long long ll;
typedef pair<int, int> pai;
typedef pair<ll,ll> pal;

int fuka[100010];
int n;
int a[100010];
vector<int> child[100010];
vector<int> sagyo[100010];

void dfs(int v)
{
	rep(i, child[v].size()) dfs(child[v][i]), sagyo[v].push_back(fuka[child[v][i]]);
	fuka[v]=child[v].size();
	sort(sagyo[v].begin(), sagyo[v].end());
	rep(i, sagyo[v].size()) fuka[v]=max(fuka[v], ((int)sagyo[v].size())-i+sagyo[v][i]);
}

int main()
{
	cin >> n;
	repp(i, 2, n+1) cin >> a[i], child[a[i]].push_back(i);
	dfs(1);
	cout << fuka[1] << endl;
	return 0;
}

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

typedef long long ll;
typedef int64_t i6;

#define rep(i, n) for (ll i = 0; i < n; ++i)
#define rep2(i, n) for (ll i = 1; i <= n; ++i)
#define ALL(v) (v).begin(), (v).end()
#define Sort(x) sort(ALL(x))
#define Sort_rev(x) Sort(x);reverse(ALL(x))

template<typename V,typename T>
T find_num(V v, T num) {
    if ( find(ALL(v), num) == v.end() ) {
        return false;
    } else {
        return true;
    }
}

// π M_PI
// deg = rad*180/M_PI

int main() {
    ll n, m, k;
    cin >> n >> m >> k;
    /*
    int a = m/n;
    int b = k/n;
    ll ans = 0;
    if ( a+1 <= b ) {
        ans = 1;
    }
    if ( m == k ) {
        if ( m%n == 0 ) {
            ans = 1;
        }
    }*/
    ll ans = 0;
    ll num = 2;
    ll nn = n;
    while (nn <= k) {
        if ( nn >= m && nn <= k ) {
            ans = 1;
            break;
        }
        nn = n*num;
        // cout << "n" << nn << endl;
        num++;
    }
    cout << ( ans ? "OK" : "NG" ) << endl;
    return 0;
}


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

using namespace std;
int main()
{
  long long A, B, C, K, SUM = 0;
  cin >> A >> B >> C >> K;

  if (A >= K)
  {
    SUM += K;
    K = 0;
  }
  else
  {
    SUM += A;
    K -= A;
  }

  if (B >= K)
  {
    K = 0;
  }
  else
  {
    K -= B;
  }

  if (C >= K)
  {
    SUM -= K;
    K = 0;
  }
  else
  {
    SUM -= C;
    K -= C;
  }

  cout << SUM << endl;

  return 0;
}


Measured memory_bytes: 3608
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const long long INF = 1LL << 60;
using Graph = vector<vector<int>>;

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

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; }

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

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    if (c % gcd(a, b) == 0) {
        cout << "YES" << endl;
        return 0;
    }
    cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
int  main(){
    int N;
    cin>>N;
    bool flag=false;
    for(int i=0;i<101;i+=4){
        for(int j=0;j<101;j+=7){
            if(i+j==N) flag=true;
        }
    }
    cout<<(flag ? "Yes" : "No") <<endl;
    return 0;
}



Measured memory_bytes: 256
N,K = map(int,input().split())
V = list(map(int,input().split()))
ans = 0
R = min(N,K)
for A in range(R+1):
    for B in range(R-A+1):
        s = V[:A]+V[N-B:]
        
        s.sort()
        S = sum(s)
        for k in range(min(K-A-B,len(s))):
            
            if s[k] < 0:
                S -= s[k]
        ans = max(ans,S)
print(ans)


Measured memory_bytes: 3064
# include <iostream>
# include <algorithm>
#include <array>
# include <cassert>
#include <cctype>
#include <climits>
#include <numeric>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <tuple>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
# include <chrono>
# include <random>
# include <limits.h>
# include <unordered_map>
# include <unordered_set>
# include <deque>
# include <cstdio>
# include <cstring>
#include <stdio.h>
#include<time.h>
#include <stdlib.h>
#include <cstdint>
#include <cfenv>
#include<fstream>
//#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
long long MOD = 1000000000 + 7;// ;//1000000000 + 7 998244353 924844033 1000000000 + 9;
constexpr long long INF = numeric_limits<LL>::max()/100;
constexpr long long DINF = 1000000000000;
const double PI = acos(-1);
#define fir first
#define sec second
#define thi third
#define debug(x) cerr<<#x<<": "<<x<<'\n'
typedef pair<LL, LL> Pll;
typedef pair<double, double> Dll;
typedef pair<LL, pair<LL, LL>> Ppll;
typedef pair<LL, pair<LL, bitset<100001>>> Pbll;
typedef pair<LL, pair<LL, vector<LL>>> Pvll;
typedef pair<LL, LL> Vec2;
struct Tll { LL first, second, third; };
struct Fll { LL first, second, third, fourth; };
typedef pair<LL, Tll> Ptll;
#define rep(i,rept) for(LL i=0;i<rept;i++)
#define Rrep(i,mf) for(LL i=mf-1;i>=0;i--)
void YN(bool f) {
	if (f)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;
}
void yn(bool f) {
	if (f)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}
struct Edge { LL to, cost; };
struct edge {
	LL from, to, cost;
};
vector<vector<LL>>g;
vector<edge>ed;
vector<Pll>pv;
map<LL, LL>ma;
set<LL>st;
vector<LL>rest;
int di[4][2] = { { 0,1 },{ 1,0 },{ 0,-1 },{ -1,0 } };
LL n, m, k, p, q, w, h, s, t, ans, cnt, sum, a[310000], b[310000];
string str;
bool f;
char c[1100][1100];
int main() {
	cin >> n >> m;
	if (m - n >= 2019)
		cout << 0 << endl;
	else {
		n %= 2019, m %= 2019;
		if (n <= m) {
			ans = INF;
			for (int i = n; i <= m; i++) {
				for (int j = i+1; j <= m; j++) {
					ans = min(ans, (LL)(j*i) % 2019);
				}
			}
			cout << ans << endl;
		}
		else {
			cout << 0 << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ull unsigned long long
#define ll long long
#define pb push_back
#define endl '\n'
#define line cout<<"----------------------"<<endl
#define mp make_pair
#define mod 1000000007
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL)
#define filein freopen("input.txt","r",stdin)
#define fileout freopen("output.txt","w",stdout)
using namespace std;
const ll  mx=200009;
ll  ara[mx];
ll val[mx];
ll dp[mx];
ll  tree[mx*4];
void update(ll  node,ll  b, ll  e,ll  i,ll  val)
{
    if(b>i or e<i) return ;
    if(b==e)
    {
        tree[node]=val;
        return ;
    }
    ll  mid=(b+e)>>1;
    update(node*2,b,mid,i,val);
    update(node*2+1,mid+1,e,i,val);
    tree[node]=max(tree[node*2],tree[node*2+1]);
}
ll  query(ll  node,ll  b, ll  e,ll  i, ll  j)
{
    if(b>j or e<i) return 0;
    if(b>=i and e<=j) return tree[node];
    ll  mid=(b+e)>>1;
    return max(query(node*2,b,mid,i,j),query(node*2+1,mid+1,e,i,j));
}
int main()
{
    ll  n;
    cin>>n;
    for(ll  i=1;i<=n;i++)
    {
        cin>>ara[i];
    }
    for(ll  j=1;j<=n;j++)
    {
        cin>>val[j];
    }
    for(ll i=1;i<=n;i++)
    {
            dp[ara[i]]=query(1,0,n,0,ara[i]-1)+val[i];
            update(1,0,n,ara[i],dp[ara[i]]);
    }
    ll ans=0;
    for(ll  i=1;i<=n;i++) ans=max(ans,dp[i]);
    cout<<ans<<endl;
}


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

using namespace std;

#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define FORR(i, a, b) for(int i = (a); i > (b); --i)
#define REP(i, n) for(int i = 0; i < (n); ++i)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOREACH(x, a) for(auto &(x) : (a))
#define VECCIN(x)                                                              \
    for(auto &youso_ : (x)) cin >> youso_
#define mp make_pair
#define bitcnt __builtin_popcount
#define All(a) (a).begin(), (a).end()
template <typename T = long long> inline T IN() {
    T x;
    cin >> x;
    return (x);
}
inline void CIN() {}
template <class Head, class... Tail>
inline void CIN(Head &&head, Tail &&... tail) {
    cin >> head;
    CIN(move(tail)...);
}
#define CINT(...)                                                              \
    int __VA_ARGS__;                                                           \
    CIN(__VA_ARGS__)
#define LCIN(...)                                                              \
    ll __VA_ARGS__;                                                            \
    CIN(__VA_ARGS__)
#define SCIN(...)                                                              \
    string __VA_ARGS__;                                                        \
    CIN(__VA_ARGS__)
#define Yes(a) cout << (a ? "Yes" : "No") << "\n"
#define YES(a) cout << (a ? "YES" : "NO") << "\n"

typedef long long ll;
typedef unsigned long long ul;
typedef vector<int> V;
typedef vector<ll> VL;
typedef pair<int, int> Pair;
typedef pair<ll, ll> PL;
typedef priority_queue<int> PQ;
typedef priority_queue<int, V, greater<int>> PQG;

const int INF = 1e9;
const int MOD = 1e9 + 7;
// const int MOD = 998244353;
const ll LINF = 1e18;

ll N, K;
map<ll, ll> dem;
ll mod = 10000;
ll dp[101][4][2];

void eat(ll day, ll kind) {
    dp[day + 1][kind][1] = dp[day][kind][0];
    FOR(j, 1, 4) {
        if(j != kind) {
            dp[day + 1][kind][0] += dp[day][j][0] % mod;
            dp[day + 1][kind][0] += dp[day][j][1] % mod;
            dp[day + 1][kind][0] %= mod;
        }
    }
}

int main() {
    cin >> N >> K;
    REP(i, K) {
        CINT(A, B);
        dem[A] = B;
    }
    if(dem[1]) {
        dp[1][dem[1]][0] = 1;
    } else {
        dp[1][1][0] = 1;
        dp[1][2][0] = 1;
        dp[1][3][0] = 1;
    }
    FOR(i, 1, N) {
        if(dem[i + 1]) {
            eat(i, dem[i + 1]);
        } else {
            FOR(j, 1, 4) { eat(i, j); }
        }
        // REP(i, N + 1) {
        //     cout << "\n";
        //     FOR(j, 1, 4) {
        //         REP(k, 2) { cout << dp[i][j][k] << " "; }
        //         cout << "   ";
        //     }
        // }
    }
    ll ans = 0;
    FOR(i, 1, 4) REP(j, 2)(ans += dp[N][i][j] % mod) %= mod;
    cout << ans << "\n";
}



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

using namespace std;

typedef struct{
  int num;
  int point;
  int pos;
}Team;


int main(){
  int num;
  cin >> num;
  Team data[num+1];

  for(int i = 0; i <= num; i++){
    data[i].num = i;
    data[i].point = 0;
  }
  
  for(int i = 0; i < num*(num-1)/2; i++){
    int in[4];
    cin >> in[0] >> in[1] >> in[2] >> in[3];
    if(in[2] > in[3]) data[in[0]].point += 3;
    else if(in[2] < in[3]) data[in[1]].point += 3;
    else{
      data[in[0]].point++;
      data[in[1]].point++;
    }
  }
  for(int i = 1; i < num; i++){
    for(int j = 1; j <= num-i; j++){
      if(data[j].point < data[j+1].point){
	Team tmp;
	tmp = data[j];
	data[j] = data[j+1];
	data[j+1] = tmp;
      }
    }
  }
  int out[num+1];
  out[data[1].num] = 1;
  int nowp = data[1].point, pos = 1, eq = 0;
  for(int i = 2; i <= num; i++){
    if(data[i].point == nowp){
      out[data[i].num] = pos;
      eq++;
    }
    else{
      nowp = data[i].point;
      pos+=eq;
      eq = 0;
      pos++;
      out[data[i].num] = pos;
    }
  }
  for(int i = 1; i <= num; i++) cout << out[i] << endl;
  return 0;
}

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

using namespace std;

namespace {

    typedef double real;
    typedef long long ll;

    template<class T> ostream& operator<<(ostream& os, const vector<T>& vs) {
        if (vs.empty()) return os << "[]";
        auto i = vs.begin();
        os << "[" << *i;
        for (++i; i != vs.end(); ++i) os << " " << *i;
        return os << "]";
    }
    template<class T> istream& operator>>(istream& is, vector<T>& vs) {
        for (auto it = vs.begin(); it != vs.end(); it++) is >> *it;
        return is;
    }

    string s;
    int N;
    void input() {
        cin >> s;
        N = int(s.size());
    }

    ll to_i(string t) {
        istringstream is(t);
        ll n; 
        is >> n;
        return n;
    }

    void solve() {
        ll ans = 0;
        for (ll bit = 0; bit < (1LL<<(N-1)); bit++) {
            //cout << "bit: " <<  bit << endl;
            string t = "";
            for (int i = 0; i < N; i++) {
                t.push_back(s[i]);
                if (bit & (1<<i)) {
                    ans += to_i(t);
                    //cout << t << " ";
                    t = "";
                }
            }
            //cout << t << endl;
            ans += to_i(t);
        }
        cout << ans << endl;
    }
}

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



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

const int MAXN = 1e5 + 5;
const int MOD = 1e9 + 7;

int N;
int a[MAXN];
int pref[MAXN];

void load() {
	scanf("%d", &N);
	for (int i = 0; i < N; i++)
		scanf("%d", a + i);
}

inline int add(int x, int y) {
	x += y;
	if (x >= MOD)
		x -= MOD;
	else if (x < 0)
		x += MOD;
	return x;
}

inline int mul(int x, int y) {
	return (long long)x * y % MOD;
}

int pot(int x, int y) {
	int res = 1;
	for (; y; y /= 2) {
		if (y % 2)
			res = mul(res, x);
		x = mul(x, x);
	}
	return res;
}

int solve() {
	for (int i = 1; i <= N; i++)
		pref[i] = add(pref[i - 1], pot(i, MOD - 2));
	
	int sol = 0;
	for (int i = 0; i < N; i++)
		sol = add(sol, mul(a[i], add(add(pref[i + 1], pref[N - i]), -1)));
	
	for (int i = 1; i <= N; i++)
		sol = mul(sol, i);
	
	return sol;
}

int main() {
	load();
	printf("%d\n", solve());
	return 0;
}

Measured memory_bytes: 1152
import java.io.*;
import java.util.*;

public class Main {

	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		
		int n = sc.nextInt();
		int[] a = new int[n];
		for(int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
		}
		
		long ans = 0;
		
		for(int i = 0; i < n; i++) {
			int pair = Math.max((a[i]-1)/2, 0);
			ans += pair;
			a[i] -= pair*2;
		}
		
		for(int i = 0; i < n-1; i++) {
			if(a[i] == 2) {
				ans++;
			} else if(a[i] == 1) {
				if(a[i+1] != 0) {
					ans++;
					a[i+1]--;
				}
			}
		}
		
		if(a[n-1] == 2) {
			ans++;
		}
		
		System.out.println(ans);
		
		return;
	}
	
}


class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    private void skipUnprintable() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;}
    public boolean hasNext() { skipUnprintable(); return hasNextByte();}
    
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    
    public int nextInt() {
    	return (int)nextLong();
    }
    
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
}


Measured memory_bytes: 9524
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<queue>
#include<vector>
using namespace std;
#define ll long long 
#define il inline
const int maxn=200010;
const ll mod=1e9+7;
ll a[maxn],s[maxn];
int n; ll ans=0;
int main(){
    scanf("%d",&n);
    for (int i=1;i<=n;++i){
        scanf("%lld",&a[i]);
        s[i]=(s[i-1]+a[i])%mod;
    }
    for (int i=n;i>=2;--i){
        ans=(ans+(s[i-1]*a[i])%mod)%mod;
    }
    printf("%lld",ans);
}

Measured memory_bytes: 6920
#!/usr/bin/env python3
from itertools import product, permutations, combinations
from bisect import bisect_right,bisect_left
INF = float('inf')

H=int(input())
cnt = 1
p = 1
import math
while H > 1:
    H = math.floor(H/2)
    cnt += 2 ** p
    p += 1
print(cnt)

Measured memory_bytes: 3060
var input = require("fs").readFileSync("/dev/stdin", "utf8").trim().split("\n");
var obj = {
  "list" : input,
  "index" : 0,
  "max" : input.length,
  "next" : function(){
    if(!this.hasNext()){throw "NoSuchElementException:次に要素は無いよ";}
    var returnObj = this.list[this.index];
    this.index++;
    return returnObj;
  },
  "hasNext" : function(){return (this.index < this.max);}
}
Main();
function next(){return obj.next();}
function hasNext(){return obj.hasNext();}
function myout(t){console.log(t);}//standard output
function myerr(t){console.error(t);}//standard error
//[no]要素の扱い。数値型
//不明値、異常時:引数そのまま返す　1:数値へ変換
//2:半角SPで分割 4:半角SPで分割し、数値配列へ
//6:1文字で分割  7:1文字で分割し、数値配列へ
//8:半角SPで結合 9:改行で結合 0:文字なしで結合
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(" ");case 4:return i.split(" ").map((a)=>Number(a));case 6:return i.split("");case 7:return i.split("").map((a)=>Number(a));case 8:return i.join(" ");case 9:return i.join("\n");case 0:return i.join("");default:return i;}}catch(e){return i;}}
function Main(){
  var s = next();
  var output = "";
  for(var i = 0; i < s.length; i++){
    output += "x";
  }
  myout(output);
}

Measured memory_bytes: 11468
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
#define int long long
 
 
double dp[3001][3001]; 
 
double prob(int n,int i,double p[],double dp[][3001]){
    if(i==0){return 1;}
    if(n==0 && i!=0){return 0;}
    if(dp[n][i] >-0.9){return dp[n][i];}
    return  dp[n][i] = p[n]*prob(n-1,i-1,p,dp) + (1-p[n])*prob(n-1,i,p,dp);
}
 
 
 
int32_t main(){
    
int n;
    cin>>n;
    double p[n+1];
p[0] = 0;
 
    for(int i=1;i<=n;i++){
        cin>>p[i];
    }
   
    memset(dp,-1,sizeof dp);
    cout<<fixed<<setprecision(10)<<prob(n,(n+1)/2,p,dp);
    return 0;
   
    
    
    }
 
    
 

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

int main()
{
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	int x, y, z;
	cin >> x >> y >> z;
	swap(x, z);
	swap(y, z);
	cout << x << " " << y << " " << z;
}


Measured memory_bytes: 256
N, M = map(int, input().split())
E = []
for i in range(M):
    a, b, c = map(int, input().split())
    a, b = a - 1, b - 1
    c = -c
    E.append([a, b, c])

dist = [float('inf')] * (N+1)
dist[0] = 0

for n in range(N):
    for a, b, c in E:
        if (dist[a] != float('inf')) & (dist[b] > dist[a] + c):
            dist[b] = dist[a] + c
            if (n == N - 1) & (b == N - 1):
                print('inf')
                exit()

print(-dist[N - 1])


Measured memory_bytes: 3316
INF = 10 ** 9 + 7
N, K = map(int, input().split())

ans = 0
mx = 0
mn = 0
for i in range(N+1):
  s = 0
  mx += N-i
  mn += i
  if i + 1 >= K:
    ans += (mx - mn + 1) % INF

print(ans % INF)


Measured memory_bytes: 9140
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define ld double 
#define rep(i,a,b) for(ll i=a; i<b; ++i)
#define BOOST std::ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb push_back
#define all(v) v.begin(),v.end()
#define sl(a) a.size()
#define mod 1000000007 
#define lcm(a,b) (a*b)/__gcd(a,b)
#define MAX1 100006
#define f first
#define s second
#define pi 2*acos(0.0)
void solve()
{
    ll n,m;  cin>>n>>m;
    vector<ll> a(n),b(m);
    rep(i,0,n) cin>>a[i];
    rep(i,0,m) cin>>b[i];
    vector<vector<ll>> dp(n+1,vector<ll>(m+1,0));
    rep(i,1,n+1)
    {
        rep(j,1,m+1)
        {
            if(a[i-1]==b[j-1]) dp[i][j]=(dp[i-1][j]%mod+dp[i][j-1]%mod+1)%mod;
            else dp[i][j]=(dp[i-1][j]%mod+dp[i][j-1]%mod-dp[i-1][j-1]%mod+mod)%mod;
        }
    }cout<<(dp[n][m]%mod+1)%mod;
}
int main()
{
    #ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt","r",stdin);
    //for getting error from error.txt
    freopen("error.txt", "w", stderr);
    // for writing output to output.txt
    freopen("output.txt","w",stdout);
    #endif
    BOOST
    int T=1;  //cin>>T;
    while(T--) solve();
    cerr<<"Time taken : "<<(float)clock()/CLOCKS_PER_SEC<<" secs"<<"\n";
    cerr<<"My CLOCKS_PER_SEC= "<<CLOCKS_PER_SEC<<"\n";
    return 0;
}


Measured memory_bytes: 34608
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <list>
#include <string>
#include <numeric>
#include <math.h>
#include <set>
#include <map>
#include <fstream>
#include <sstream>
#include <iterator>
#include <complex>
using namespace std;

int main()
{
	int N;
	cin>>N;
	vector<int> w(N);
	for(int i=0; i<N; i++)
	{
		cin>>w[i];
	}
	//sort(w.begin(),w.end());

	//累積和
	vector<int> L(N+1);
	vector<int> R(N+1);
	vector<int> S(N+1);
	L[0] = 0;
	R[0] = accumulate(w.begin(),w.end(),0);
	S[0] = abs(R[0]-L[0]);
	for(int i=1; i<=N; i++)
	{
		L[i] = L[i-1] + w[i-1];
		R[i] = R[i-1] - w[i-1];
		S[i] = abs(R[i]-L[i]);
	}

	cout<<*min_element(S.begin(),S.end())<<endl;

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int a[2][100];
int main(void) {
  int n;
  cin>>n;
  for(int i=0; i<2; i++) {
    for(int j=0; j<n; j++) {
      cin>>a[i][j];
    }
  }

  int sum=0;
  int ans=0;

  for(int i=0; i<n; i++) {
    sum=0;
    for(int j=0; j<n-i; j++) {
      sum+=a[0][j];
    }
    for(int k=n-i-1; k<n; k++) {
      sum+=a[1][k];
    }
    ans=max(ans, sum);
  }

  cout<<ans<<endl;

  return 0;
}


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

int main() {
  int n;
  cin >> n;
  map<int, int> odd;
  map<int, int> even;
  rep(i, n) {
    int a;
    cin >> a;
    if ((i + 1) % 2 == 0) {
      even[a]++;
    } else {
      odd[a]++;
    }
  }

  vector<pair<int, int>> odd2;
  for (auto kv : odd) {
    odd2.push_back(make_pair(kv.second, kv.first));
  }
  sort(odd2.rbegin(), odd2.rend());

  vector<pair<int, int>> even2;
  for (auto kv : even) {
    even2.push_back(make_pair(kv.second, kv.first));
  }
  sort(even2.rbegin(), even2.rend());

  if (odd2[0].second != even2[0].second) {
    cout << n - odd2[0].first - even2[0].first << endl;
    return 0;
  }

  if (odd2.size() == 1 && even2.size() == 1) {
    cout << n / 2 << endl;
    return 0;
  }

  if (odd2.size() == 1) {
    cout << n - odd2[0].first - even2[1].first << endl;
    return 0;
  }
  if (even2.size() == 1) {
    cout << n - odd2[1].first - even2[0].first << endl;
    return 0;
  }

  if (odd2[0].first > even2[0].first) {
    cout << n - odd2[0].first - even2[1].first << endl;
    return 0;
  }
  if (odd2[0].first < even2[0].first) {
    cout << n - odd2[1].first - even2[0].first << endl;
  }
  if (odd2[1].first > even2[1].first) {
    cout << n - odd2[1].first - even2[0].first << endl;
    return 0;
  } else {
    cout << n - odd2[0].first - even2[1].first << endl;
    return 0;
  }

  return 0;
}

Measured memory_bytes: 6136