akhauriyash/Code-Regression huggingface dataset:
//Relive your past life.
//Face your demons.
//The past is never dead,it is not even past.
//The memories are not only the key to the past but...also to the future.
//coded in Rusty Lake
#include<cmath>
#include<math.h>
#include<ctype.h>
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<ciso646>
#include<climits>
#include<clocale>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<cwchar>
#include<cwctype>
#include<deque>
#include<exception>
#include<fstream>
#include<functional>
#include<iomanip>
#include<ios>
#include<iosfwd>
#include<iostream>
#include<istream>
#include<iterator>
#include<limits>
#include<list>
#include<locale>
#include<map>
#include<memory>
#include<new>
#include<numeric>
#include<ostream>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<stdexcept>
#include<streambuf>
#include<string>
#include<typeinfo>
#include<utility>
#include<valarray>
#include<vector>
#include<string.h>
#include<stdlib.h>
#include<stdio.h>
#define ll   long long
#define pb   push_back
#define mp   make_pair
#define orz  1000000007
using namespace std;
int n,a[100005],ans,cnt[2];
int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;++i)scanf("%d",a+i);
    while(1){
        cnt[0]=cnt[1]=0;
        for(int i=1;i<=n;++i)if(a[i]>1)++cnt[a[i]&1];
        if(cnt[0]&1){
            ans^=1;
            break;
        }
        if(cnt[1]!=1||cnt[0]!=n-1) break;
        for(int i=1;i<=n;++i)if(a[i]>1&&(a[i]&1))--a[i];
        int o=a[1];
        for(int i=2;i<=n;++i)o=__gcd(o,a[i]);
        for(int i=1;i<=n;++i)a[i]/=o;
        ans^=1;
    }
    if(ans)puts("First");
    else puts("Second");
    //system("pause");
    return 0;
}


Measured memory_bytes: 640
"use strict";
function Main(input) {
    let cin = new Inputer(input);
    let N = cin.getInt();
    let A = cin.getIntArray(N);
    let B = A.map((v, i) => v - i - 1);
    B.sort((a,b) => a- b);
   let c = Math.floor(N / 2);
    let b = B[c];
    let ans = A.reduce((ac, v, i) => ac + Math.abs(v - (b + i + 1)),  0);
console.log(ans);
}
class Inputer{constructor(t){if(typeof t=='undefined')throw new Error('引数（stdin）を省略できません！');this.cnt=0;this.items=t.split(/\n|\s/)}getInt(){return this.items[this.cnt++]-0}getIntArray(t){if(typeof t=='undefined')throw new Error('引数（1以上）を省略できません！');if(t<1)throw new Error('引数は1以上であること！');let r=new Array(t);for(let e=0;e<t;e++)r[e]=this.getInt();return r}getStr(){return this.items[this.cnt++]}getStrArray(t){if(typeof t=='undefined')throw new Error('引数（1以上）を省略できません！');if(t<1)throw new Error('引数は1以上であること！');let r=new Array(t);for(let e=0;e<t;e++)r[e]=this.getStr();return r}}
if (typeof window == "undefined") Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 36624
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		
		String s = in.next();
		int start = 0;
		while (s.charAt(start) != 'A') {
			start++;
		}
		int end = s.length() - 1;
		while (s.charAt(end) != 'Z') {
			end--;
		}
		System.out.println(end - start + 1);
	}
}

Measured memory_bytes: 25692
#include<bits/stdc++.h>
#define LL long long
#define P pair<int,int>
#define P2 pair<LL,int>
#define ls(i) seg[i].lc
#define rs(i) seg[i].rc
using namespace std;
const int N = 18;
const int mod = 1e9 + 7;

int main()
{
    int cnt[20] = {0};
    int n,res = 0;
    cin>>n;
    for(int i = 0;i < n;i++){
        int x;
        cin>>x;
        if(x < 3200) cnt[x/400]++;
        else res++;
    }
    int ans = 0;
    for(int i = 0;i < 8;i++) if(cnt[i]) ans++;
    if(!ans) cout<<1<<" ";
    else cout<<ans<<" ";
    cout<<ans+res<<endl;
    return 0;
}



Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve();
    }
    public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int N = scan.nextInt();
        int M = scan.nextInt();
        HashMap<Integer, List<Integer>> edges = new HashMap<>();
        int[] A = new int[M];
        int[] B = new int[M];
        for (int i = 0; i < M; i++) {
            int a = scan.nextInt()-1;
            int b = scan.nextInt()-1;
            A[i] = a;
            B[i] = b;
            if (!edges.containsKey(a)) {
                edges.put(a, new ArrayList<>());
            }
            if (!edges.containsKey(b)) {
                edges.put(b, new ArrayList<>());
            }
            edges.get(a).add(b);
            edges.get(b).add(a);
        }
        int answer = 0;
        for(int i = 0; i < M; i++) {
            boolean[] visited = new boolean[N];
            int a = A[i];
            int b = B[i];
            dfs(N, edges, visited, a, a, b);
            for (int j = 0; j < N; j++) {
                if (!visited[j]) {
                    answer += 1;
                    break;
                }
            }
        }
        System.out.println(answer);
    }
    private void dfs(int N, HashMap<Integer, List<Integer>> edges, boolean[] visited, int current, int a, int b) {
        if (visited[current]) {
            return;
        }
        visited[current] = true;
        for (int i : edges.get(current)) {
            if (current == a && i == b) {
                continue;
            }
            if (current == b && i == a) {
                continue;
            }
            if (visited[i]) {
                continue;
            }
            dfs(N, edges, visited, i, a, b);
        }
    }
}


Measured memory_bytes: 21844
S = input()
ls= ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]
ls2=["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]
for i in range(len(S)):
  for j in range(len(ls)):
    if S[i] == ls[j]:
      if ls[j] in ls2:
        ls2.remove(ls[j])
      break
if len(ls2) == 0:
  print("None")
else:
  print(ls2[0])

Measured memory_bytes: 3188
#include <stdio.h>

#define MAX 10000
#define NIL -1

struct Node {int p, l, r;};
struct Node T[MAX];
int n;

/* 先行順巡回 */
void preParse(int u) {
  if(u == NIL) return;
  printf(" %d",u);
  preParse(T[u].l);
  preParse(T[u].r);
}

/* 中間順巡回 */
void inParse(int u) {
  if(u == NIL) return;
  inParse(T[u].l);
  printf(" %d",u);
  inParse(T[u].r);
}

/* 後方順巡回 */
void postParse(int u) {
  if(u == NIL) return;
  postParse(T[u].l);
  postParse(T[u].r);
  printf(" %d",u);
}

int main(void) {
  int i, v, l, r, root;
  scanf("%d",&n);
  for(i=0; i<n; i++) {
    T[i].p = NIL;
  }
  
  for(i=0; i<n; i++) {
    scanf("%d %d %d",&v,&l,&r);
    T[v].l = l;
    T[v].r = r;
    if(l != NIL) T[l].p = v;
    if(r != NIL) T[r].p = v;
  }
  
  for(i=0;i<n;i++) if(T[i].p == NIL) root = i;
  
  printf("Preorder\n");
  preParse(root);
  printf("\n");

  printf("Inorder\n");
  inParse(root);
  printf("\n");

  printf("Postorder\n");
  postParse(root);
  printf("\n");

  return 0;
}


Measured memory_bytes: 2056
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <queue>
#include <vector>
#include <string>
#include <sstream>
#include <utility>
#include <deque>
#include <numeric>
#include <map>
#define rep(i,n) for (int i = 0; i < (n); ++i)
 
using namespace std;
 
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef long long ll;

bool visited[1005][1005][1005];
 
int main () {
	int N;
    cin >> N;
	vector<ll> v(N);
	rep(i,N) {
		cin >> v[i];
	}
	int max_ind = max_element(v.begin(),v.end()) - v.begin();

	int min_ind = min_element(v.begin(),v.end()) - v.begin();
	if (v[max_ind] < 0) {
		cout << N-1 << endl;
		for (int i = N; i > 1; --i) {
			cout << i << " " << i-1 << endl; 
		}		
	}
	else if (v[min_ind] >= 0) {
		cout << N-1 << endl;
		for (int i = 1; i < N; ++i) {
			cout << i << " " << i+1 << endl; 
		}		
	} else {
		if (abs(v[max_ind]) >= abs(v[min_ind])) {
			cout << 2*N-1 << endl;
			for (int i = 1; i <= N; ++i) {
				cout << max_ind + 1 << " " << i << endl; 
			}	
			for (int i = 1; i < N; ++i) {
				cout << i << " " << i+1 << endl; 
			}	
		} else {
			cout << 2*N-1 << endl;
			for (int i = 1; i <= N; ++i) {
				cout << min_ind + 1 << " " << i << endl; 
			}	
			for (int i = N; i > 1; --i) {
				cout << i << " " << i-1 << endl; 
			}	
		}
	}
    return 0;
}

Measured memory_bytes: 760
#include<iostream>
#include<stdio.h>
//#include <bits/stdc++.h>
#include<vector>
#include<float.h>
#include<iomanip>
#include<algorithm>
#include<string>
#include<cstring>
#include<math.h>
#include<cmath>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include <cassert>
#include <cmath>
#include<cstdint>

#define INF 1e9
#define rep(i,n)for(int i=0;(i)<(int)(n);i++)
#define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
#define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
#define vec(type,n) vector<type>(n)
#define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
#define ALL(a)  (a).begin(),(a).end()

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<int,int>;

vector<int>bitSearch(int bit,int n){
    vector<int>S;
    rep(i,n)if(bit&(1<<i))S.push_back(i);
    return S;
}


int main(){
    int x,y,a,b,c;cin>>x>>y>>a>>b>>c;
    VEC(ll,p,a);
    VEC(ll,q,b);
    VEC(ll,r,c);
    sort(ALL(p),greater<ll>());
    sort(ALL(q),greater<ll>());
    sort(ALL(r),greater<ll>());
    vector<int>sum;
    rep(i,x)sum.push_back(p[i]);
    rep(i,y)sum.push_back(q[i]);
    sort(ALL(sum));
    int cnt = 0;
    rep(i,x+y){
        if(cnt>=c)break;
        if(sum[i]<r[cnt]){
            sum[i] = r[cnt];
            cnt++;
        }
    }
    ll res = 0;
    rep(i,x+y)res += sum[i];
    cout<<res;
}



Measured memory_bytes: 3704
#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <map>
#include <set>
#include <stack>
#include <queue>
 
using namespace std;
 
#define pb(n)	push_back(n)
#define mp(n,m) make_pair(n,m)
#define fi 	first
#define se 	second
#define all(r) (r).begin(),(r).end()

#define rep(i,n) for(int i=0; i<(n); i++)
#define repc(i,a,b) for(int i=(a); i<(b); i++)

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
 
const int IMAX=((1<<30)-1)*2+1;
const double EPS=1e-10;
//int mod=1000000007


double f[7]={35.5,37.5,40.0,43.0,50.0,55.0,70.0};
double t[7]={71.0,77.0,83.0,89.0,105.0,116.0,148.0};
string s[8]={"AAA","AA","A","B","C","D","E","NA"};




int main(){
	double d,e;
	while(cin>>d>>e){
		rep(i,8){
			if(i==7||(d<f[i]&&e<t[i])){
				cout<<s[i]<<endl;
				break;
			}
		}
	}
}

Measured memory_bytes: 1228
N,M,K = map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))

SumA=[0 for _ in range(N+1)]
SumB=[0 for _ in range(M+1)]
for i in range(1,N+1):
    SumA[i]=SumA[i-1]+A[i-1]
for i in range(1,M+1):
    SumB[i]=SumB[i-1]+B[i-1]

def binary_search(Time,IndexA):
    if Time>K:
        return 0 
    l=0
    r=M
    c=(l+r)//2
    while r-l>1:
        if Time+SumB[c]>K: r=c
        if Time+SumB[c]<=K: l=c
        c=(l+r)//2
    if Time+SumB[r]>K: IndexB=l
    else: IndexB=r
    NumOfBooks=IndexA+IndexB
    return NumOfBooks

MaxNumOfBooks=0
for IndexA in range(N+1):
    NumOfBooks=binary_search(SumA[IndexA],IndexA)
    if MaxNumOfBooks<NumOfBooks: MaxNumOfBooks=NumOfBooks
print(MaxNumOfBooks)

Measured memory_bytes: 48660
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1e9+7,MAX = 1e5;

struct Node
{
	int key;
	Node *right, *left, *parent;
};

Node *root;

void insert(int k)
{
	Node *y = nullptr;
	Node *x = root;
	Node *z ;

	z = new Node;
	z->key = k;
	z->left = nullptr;
	z->right = nullptr;

	while(x!=nullptr)
	{
		y=x;
		if(z->key<x->key)
		{
			x = x->left;
		}
		else
		{
			x = x ->right;
		}
	}
	
	z -> parent = y;
	if(y == nullptr)
	{
		root = z;
	}
	else
	{
		if(z->key < y->key)
		{
			y->left = z;
		}
		else
		{
			y -> right = z;
		}
	}
}

void inorder(Node *u)
{
	if(u == nullptr)return;
	inorder(u->left);
	cout<<' '<<u->key;
	inorder(u->right);
}

void preorder(Node *u)
{
	if(u==nullptr)return;
	cout<<' '<<u->key;
	preorder(u->left);
	preorder(u->right);
}

Node *find(Node *u,int k)
{
	while(u != nullptr&&k!=u->key)
	{
		if(k<u->key)u = u->left;
		else u = u->right;
	}
	return u;
}

int main()
{
	int n,x;
	cin >> n;
	string s;
	for(int i =0;i<n;i++)
	{
		cin >> s;
		if(s=="insert")
		{
			cin >> x;
			insert (x);
		}
		else if(s=="find")
		{
			cin >> x;
			if(find(root,x)!=nullptr)cout<<"yes"<<endl;
			else cout<<"no"<<endl;
		}
		else
		{
			inorder(root);cout<<endl;
			preorder(root);cout<<endl;
		}
	}
	return 0;
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef pair<int,int> P;

#define INF 1<<30
#define LINF 1ll<<60ll
#define MOD 1000000007
#define pb(a) push_back(a)

#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) _repi(i,0,n)
#define _repi(i,a,b) for(int i=a, i##_len=(b); i<i##_len; ++i)
#define REP(...) _overload3(__VA_ARGS__,_repi,_rep,)(__VA_ARGS__)

#define REPR(i, n) for(int i = n;i >= 0;--i)
#define REPARR(i, v) for(int i = 0;i < sz(v);++i)

#define all(vec) (vec.begin()),(vec.end())
#define sz(x) ((int)(x).size())
#define bit(n) (1ll<<(n))

template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(a>b){a=b;return true;}return false;}

#define YES(n) cout<<((n)?"YES":"NO")<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define yes(n) cout<<((n)?"yes":"no")<<endl
#define poss(n) cout<<((n)?"possible":"impossible")<<endl
#define Poss(n) cout<<((n)?"Possible":"Impossible")<<endl


int main(){
    int n;
    cin>>n;
    vl a(n);
    ll sum=0;
    REP(i,n){
        int buf;
        cin>>buf;
        sum+=buf;
        a[i]=sum;
    }
    ll mn=LINF;
    REP(i,n-1){
        chmin(mn,abs(sum-a[i]*2));
    }
    cout<<mn<<endl;
    return 0;
}


Measured memory_bytes: 1792
/* --- author: dxm --- */
#include<bits/stdc++.h>
#pragma GCC optimize(2)
using namespace std;

#define INF 1e9
#define Inf 1e18
#define rep(i,n) for(int (i)=0;(i)<n;i++)
#define REP(i,n) for(int (i)=1;(i)<=n;i++)
#define mp make_pair
#define pb push_back
#define fst first
#define snd second
typedef long long ll;
typedef double db;
typedef long double ldb;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;

void qread(int &x){
	int neg=1;x=0;
	char c=getchar();
	while(c<'0'||c>'9'){if(c=='-')neg=-1;c=getchar();}
	while(c>='0'&&c<='9')x=10*x+c-'0',c=getchar();
	x*=neg;
}

const int maxn=200005;
int n,q;
int a,b,x[maxn];

class Segtree{
public:
	ll t[maxn*4],tag[maxn*4];
	void init(){
		rep(i,maxn*4)t[i]=Inf;
	}
	void pushdown(int v){
		if(tag[v]){
			t[v<<1]+=tag[v];
			t[v<<1|1]+=tag[v];
			tag[v<<1]+=tag[v];
			tag[v<<1|1]+=tag[v];
			tag[v]=0;
		}
	}
	void update(int v,int l,int r,int vl,int vr,ll val){
		if(l>=vl&&r<=vr){
			tag[v]+=val;
			t[v]+=val;
			return;
		}
		pushdown(v);
		int mid=(l+r)>>1;
		if(mid>=vl)update(v<<1,l,mid,vl,vr,val);
		if(mid<vr)update(v<<1|1,mid+1,r,vl,vr,val);
		t[v]=min(t[v<<1],t[v<<1|1]);
	}
	void update2(int v,int l,int r,int k,ll val){
		if(l==r){
			t[v]=min(t[v],val);
			return;
		}
		pushdown(v);
		int mid=(l+r)>>1;
		if(k<=mid)update2(v<<1,l,mid,k,val);
		else update2(v<<1|1,mid+1,r,k,val);
		t[v]=min(t[v<<1],t[v<<1|1]); 
	}
	ll query(int v,int l,int r,int vl,int vr){
		if(l>=vl&&r<=vr)return t[v];
		pushdown(v);
		int mid=(l+r)>>1;
		ll sl=mid>=vl?query(v<<1,l,mid,vl,vr):Inf;
		ll sr=mid<vr?query(v<<1|1,mid+1,r,vl,vr):Inf;
		return min(sl,sr);
	}
}T1,T2;

int main(){
#ifdef FILE
	freopen("FILE.in","r",stdin);
	freopen("FILE.out","w",stdout);
#endif
	scanf("%d%d%d%d",&n,&q,&a,&b);
	REP(i,q)scanf("%d",&x[i]);
	T1.init(),T2.init();
	T1.update2(1,1,n,b,abs(x[1]-a)-b);
	T2.update2(1,1,n,b,abs(x[1]-a)+b);
	T1.update2(1,1,n,a,abs(x[1]-b)-a);
	T2.update2(1,1,n,a,abs(x[1]-b)+a);
	for(int i=2;i<=q;i++){
		ll tmp=min(T1.query(1,1,n,1,x[i])+x[i],T2.query(1,1,n,x[i]+1,n)-x[i]);
		T1.update(1,1,n,1,n,abs(x[i]-x[i-1]));
		T2.update(1,1,n,1,n,abs(x[i]-x[i-1]));
		T1.update2(1,1,n,x[i-1],tmp-x[i-1]);
		T2.update2(1,1,n,x[i-1],tmp+x[i-1]);
	}
	ll ans=Inf;
	REP(i,n){
		ans=min(ans,T1.query(1,1,n,i,i)+i);
		ans=min(ans,T2.query(1,1,n,i,i)-i);
	}
	printf("%lld\n",ans);
#ifdef TIME
	printf("Running Time = %d ms\n",int(clock()*1000.0/CLOCKS_PER_SEC));
#endif
	return 0;
}

/*
Input:
-----------------
Output:
*/


Measured memory_bytes: 25600
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <string>
#include <numeric>
#include <cmath>

#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
using P = pair<ll, ll>;

template<class T> inline bool chmin(T& a,T b) {if (a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a,T b) {if (a < b) {a = b; return true;} return false;}

const ll MOD = 1000000007;
const int INF = 1<<30;
//const ll INF = (ll)1e18 + 1;

int main(){
  string S; cin >> S;
  ll K; cin >> K;
  ll N = S.length();

  ll ans = 0;
  ll cnt = 0;
  rep(i, N) if (S[0] == S[i]) cnt++;

  if (cnt == N) {
    cout << N * K / 2 << endl;
    return 0;
  }
  if (S[0] != S[N - 1]) {
    rep(i, N){
      ll length = 1;
      while (i + 1 < N && S[i] == S[i + 1]) i++, length++;
      ans += length / 2 * K;
    }
  }
  else {
    vector<ll> que;
    rep(i, N){
      ll length = 1;
      while (i + 1 < N && S[i] == S[i + 1]) i++, length++;
      que.push_back(length);
    }
    for (int i = 1; i < (int)que.size() - 1; ++i) ans += que[i] / 2 * K;
    ans += que[0] / 2;
    ans += que[(int)que.size() - 1] / 2;
    ans += (que[0] + que[(int)que.size() - 1]) / 2 * (K - 1);
  }
  cout << ans << endl;
}


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

int main() {
  
  int A, B; cin >> A >> B; int sum = 1; int ans = 0; A--;
  
  while (true) {
    
    if (B <= sum) {
      cout << ans << endl;
      break;
    }
    
    sum += A; ans++;
    
  }
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
using ppl = pair<pll, ll>;

set<ppl> st;

int main() {
    #ifdef DEBUG
        freopen("in.txt", "r", stdin);
    #endif
    ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);

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

    ll cnt = 0;
    while (true) {
        if (a % 2 || b % 2 || c % 2) break;
        ll A = b / 2 + c / 2;
        ll B = a / 2 + c / 2;
        ll C = a / 2 + b / 2;
        a = A; b = B; c = C;

        if (st.count(ppl(pll(a, b), c))) {
            cout << "-1\n"; return 0;
        } else {
            st.insert(ppl(pll(a, b), c));
        }

        cnt++;
    }
    cout << cnt << '\n';

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
 #include<string>
 using namespace std;
 
 int min(int a,int b)
 {
 	if(a<b) return a;
 	else return b;
 }
 
 int main()
 {
 	int a,b;
 	while(cin>>a>>b)
 	{
 	    long long int x=min(a,b);
 	    long long int y=(a+b-min(a,b));
 	    if(x==1&&y==1) cout<<"1"<<endl;
 	    else if(x==1) cout<<(y-2)<<endl;
 	    else 
 	    {
 	    	if(x==2) cout<<"0"<<endl;
 	    	else cout<<(x-2)*(y-2)<<endl;
		 }
	 }
 	return 0;
 }

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

#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = (n)-1; i >= 0; i--)
#define rep1(i,n) for(int i = 1; i <= (n); i++)
#define rrep1(i,n) for(int i = (n); i > 0; i--)

#define ll long long
#define pi pair<int, int>
#define pll pair<ll, ll>

#define MOD 1000000007
#define INF 1000000000000000LL

using namespace std;

int main(){
  int n;cin>>n;
  vector<int>a(n);
  rep(i, n)cin>>a[i];
  map<int, int> counter;
  rep(i, n)counter[a[i]]++;

  ll sum = 0;
  for(auto p: counter){
    ll ca = p.second;
    if(ca>=2)sum += (ca*(ca-1)/2);
  }

  rep(i, n){
    ll result = sum;
    ll ca = counter[a[i]];
    if(ca>=2){
      result = result-ca*(ca-1)/2+(ca-1)*(ca-2)/2;
    }
    cout<<result<<endl;
  }

  return 0;
}

Measured memory_bytes: 8320
#include <iostream>
#include <string>
using namespace std;
int main(void){
  int n;
  cin >> n;
  
  double money;
  string kind;
  
  double ans = 0;
  
  for(int i=0;i<n;i++){
    cin >> money;
    cin >> kind;
    
    if(kind == "BTC")
      ans = ans + money * 380000.0;
    else
      ans = ans + money;
  }
    
    cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MAXN 17
#define pii pair<int, int>
#define pb push_back
typedef long long ll;

using namespace std;

ll n, a[MAXN][MAXN], dp[1 << MAXN], ans = 0;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
    cin >> n;
    for(int i = 0; i < n; i++){
    	for(int j = 0; j < n; j++){
    		cin >> a[i][j];
    	}
    }
    for(int b = 1; b < (1 << n); b++){
    	vector<ll> v;
    	for(int j = 0; j < n; j++){
    		if((b >> j) & 1) v.pb(j);
    	}
    	for(auto i : v){
    		for(auto j : v){
    			dp[b] += a[i][j];
    		}
    	}
    	dp[b] /= 2;
    }
    for(int b = 0; b < (1 << n); b++){
    	
    	for(int i = 1; i < b; i++){
	    	if((i | b) != b) continue;
	    	ll t = dp[i] + dp[b ^ i];
	    	dp[b] = max(dp[b], t);
	    }
	    //cout <<  dp[b] + dp[((1 << n) - 1) ^ b] << endl;	
    	ans = max(ans, dp[b] + dp[((1 << n) - 1) ^ b]);	
	    
    }
    cout << ans;
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i, n) for(int i = 0; i < n; ++i)
#define INF (2e9)

ll n, A[2000001];
ll B[2000001], C[10001];

int main() {
  cin >> n;
  REP(i, n) cin >> A[i];

  REP(i, 10001) C[i] = 0;
  REP(i, n) C[A[i]]++;
  for(int i = 1; i <= 10000; ++i) C[i] += C[i-1];
  for(int i = n-1; i >= 0; --i) {
    B[C[A[i]]] = A[i];
    C[A[i]]--;
  }

  cout << B[1];
  for(int i = 2; i <= n; ++i) cout << " " << B[i];
  cout << endl;

  return 0;
}


Measured memory_bytes: 34388
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <unordered_map>
using namespace std;

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

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

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }

#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }






vector<long long> calc_divisor(long long n) {
    vector<long long> res;
    for (long long i = 1LL; i*i <= n; ++i) {
        if (n % i == 0) {
            res.push_back(i);
            long long j = n / i;
            if (j != i) res.push_back(j);
        }
    }
    sort(res.begin(), res.end());
    return res;
}


long long N;

long long solve() {
    auto div = calc_divisor(N);
    long long res = 0;
    for (auto r : div) {
        if (r > 1000000) continue;
        if (N > r*r + r) res += (N-r)/r;
    }
    return res;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    while (cin >> N) {
        cout << solve() << endl;
    }
}




















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

#define li long long int
#define rep(i, to) for (li i = 0; i < ((li)(to)); i++)
#define repp(i, start, to) for (li i = (li)(start); i < ((li)(to)); i++)

li n;


int main() {
	li n;
	cin >> n;
	set<li> st;
	rep(i, n) {
		li d;
		cin >> d;
		st.insert(d);
	}
	cout << st.size() << endl;


	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll mod2 = 998244353;
const int INF = 1e9;
const long double EPS = 1e-10;

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

  int dp[n + 1];
  fill(dp, dp + n + 1, INF);
  dp[0] = 0;

  FOR(i, 1, n + 1) {
    for (int j = 1;; j *= 6) {
      if (i - j < 0) break;
      dp[i] = min(dp[i], dp[i - j] + 1);
    }
    for (int j = 1;; j *= 9) {
      if (i - j < 0) break;
      dp[i] = min(dp[i], dp[i - j] + 1);
    }
  }
  cout << dp[n] << endl;
  


  
  return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) (v).begin(),(v).end()
#define out(a) cout << (a) << endl
using namespace std;
using ll = long long;
int main(){
    int x, y, z;
    cin >> x >> y >> z;
    int ans = (x - z) / (y + z);
    out(ans);
}

Measured memory_bytes: 256
main=do
 n<-readLn
 print$length$filter(f n)$(g n)++(g$n-1)
f n x
 |x==1=False
 |n`mod`x==0=f(n`div`x)x
 |otherwise=n`mod`x==1
g n=foldl f []$takeWhile((n>=).(^2))[1..n]
 where
  f s i
   |n`mod`i==0&&i*i<n=i:n`div`i:s
   |n`mod`i==0=i:s
   |otherwise=s

Measured memory_bytes: 141692
import scala.io.StdIn
import scala.annotation.tailrec

object Main{
  def main(args: Array[String]){
    StdIn.readLine()
    val line = StdIn.readLine().split(" ").toList.map(_.toInt)

    println(line.sorted.mkString(" "))
    println(sSort(List(), line, 0))
  }

  @tailrec
  def sSort(sorted: List[Int], unsorted: List[Int], n: Int): Int={
    if(unsorted.length == 0) n
    else if(unsorted.sorted == unsorted) n
    else if(unsorted.indexWhere(_ == unsorted.min) == 0) sSort(sorted :+ unsorted.head, unsorted.tail, n)
    else {
      val pos = unsorted.indexWhere(_ == unsorted.min)
      // pos??¨head???????´????swap?????????
      val swapped = unsorted.updated(0, unsorted(pos)).updated(pos, unsorted.head)

      sSort(sorted :+ unsorted.min, swapped.tail, n+1)
    }
  }
}

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

int main() {
    int a, b, c;
    int A, B, C;
    cin >> a >> b >> c;
    A = a + b;
    B = b + c;
    C = c + a;
    cout << min({A, B, C}) << 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() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int a, p;
	cin >> a >> p;
	cout << (3 * a + p) / 2 << endl;
}

Measured memory_bytes: 256
#include <string>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
int n,h[100005];
ll dp[100005];

int main(){
	int N,M,K;
	//stack<int> s;   
    queue<int> que;
    //std::cin >> N;
    //std::cin >> N >> M;
    //std::cin >> N >> M >> K;
  string s;
  cin>>s;
    
    std::vector<long long> v(N);
 
    // 入力
    int max,cnt;
    max=0;
    cnt=0;
    //printf("%d",(int)s.size());
    
    for(int i=0;i<(int)s.size();i++){
		//printf("*");
		if(s[i]=='A' || s[i]=='C' || s[i]=='G' || s[i]=='T' ){
			cnt++;
			if(cnt>max){
				max=cnt;
			}
		}
		else{
			cnt=0;
		}	
	}
    
	printf("%d",max);
    
	return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using static System.Math;
using static System.Array;
using static AtCoder.Tool;
namespace AtCoder
{
    class AC
    {
        const int mod = 1000000007;
        const int INF = int.MaxValue / 2;
        const long SINF = long.MaxValue / 2;
        static readonly int[] dx = { 0, 1, 0, -1 };
        static readonly int[] dy = { 1, 0, -1, 0 };
        

        static void Main(string[] args)
        {
            //var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            //Console.SetOut(sw);
            var cin = new Scanner();

            int N = int.Parse(Console.ReadLine());
            long[] a = cin.SplitReadL();
            long[] b = cin.SplitReadL();
            long asum = a.Sum();
            long bsum = b.Sum();

            if (bsum < asum)
            {
                Console.WriteLine("No");
                return;
            }
            long op = bsum - asum;
            

            for(var i = 0; i < N; i++)
            {
                op -= Max(0, (b[i] - a[i] + 1) / 2);
            }
            Console.WriteLine(op >= 0 ? "Yes" : "No");
            
            //Console.Out.Flush();
        }
        
        
    }
    public class Scanner
    {
        public int[] SplitRead()
        {
            int[] array = Console.ReadLine().Split().Select(int.Parse).ToArray();
            return array;
        }
        public long[] SplitReadL()
        {
            long[] array = Console.ReadLine().Split().Select(long.Parse).ToArray();
            return array;
        }
    }

    public static class Tool
    {
        static public void Initialize<T>(ref T[] array, T initialvalue)
        {
            for (var i = 0; i < array.Length; i++)
            {
                array[i] = initialvalue;
            }
        }
        static public long Modulo(long value, long mod)
        {
            long r = value % mod;

            if (r * mod < 0)
            {
                r += mod;
            }
            return r;
        }
    }

    

}


Measured memory_bytes: 15584
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <algorithm>
using namespace std;

int main()
{
	int N, M, a, b;
	cin >> N >> M;

	vector<vector<int>> arr(N);
	for (int i = 0; i < M; i++) {
		cin >> a >> b;
		arr[a - 1].push_back(b - 1);
		arr[b - 1].push_back(a - 1);
	}

	queue<vector<bool>> roots;
	queue<int> nexts;
	roots.push(vector<bool>(N));
	nexts.push(0);

	int cnt = 0;
	while (!roots.empty()) {
		auto root = roots.front();
		roots.pop();
		int next = nexts.front();
		nexts.pop();

		vector<bool> newRoot(root);
		newRoot[next] = true;
		bool allVisited = true;
		for (int i = 0; i < newRoot.size(); i++) {
			if (!newRoot[i]) {
				allVisited = false;
				break;
			}
		}
		if (allVisited)
			cnt++;
		else {
			for (int val : arr[next]) {
				if (!root[val]) {
					roots.push(newRoot);
					nexts.push(val);
				}
			}
		}
	}

	cout << cnt << endl;

	return 0;
}



Measured memory_bytes: 640
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <random>
#include <cmath>
#include <chrono>
#include <cstring>
#include <algorithm>
#include <string>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cassert>
using namespace std;
using LL = long long;
#define eps 1e-8
#define fi first
#define se second
#define eb emplace_back
#define close std::ios::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr)
#define FOR(i, x, y) for (LL i = (x), _##i = (y); i < _##i; ++i)
#define FORD(i, x, y) for (LL i = (x), _##i = (y); i > _##i; --i)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define CASET int ___T; scanf("%d", &___T); for(int __CS=1;__CS<=___T;__CS++)
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
mt19937 dlsrand(random_device{}());
mt19937 mrand(std::chrono::system_clock::now().time_since_epoch().count()); 
int rnd(int x) { return mrand() % x;}
LL bin(LL x, LL n, LL MOD) {LL ret = MOD != 1;for (x %= MOD; n; n >>= 1, x = x * x % MOD)if (n & 1) ret = ret * x % MOD;return ret;}
inline LL get_inv(LL x, LL p) { return bin(x, p - 2, p); }
const double PI = acos(-1.0);
constexpr int maxn = 1e6+10;
constexpr int INF = 0x3f3f3f3f;
constexpr ll linf = 0x3f3f3f3f3f3f3f3f;
constexpr int mod = 1e9+7;
int n , m , k , u , v;
int fa[maxn], deg[maxn], cnt[maxn],sz[maxn];
int get_fa(int x){
    return x == fa[x] ? x : fa[x] = get_fa(fa[x]);
}
void unit(int x, int y){
    int fx = get_fa(x);
    int fy = get_fa(y);
    if(fx == fy)return ;
    fa[fy] = fx;
    sz[fx] += sz[fy];
    return ;
}
int main()
{
    cin >> n >> m >> k;
    for(int i = 1; i <= n+10;i++){
        fa[i] = i;
        sz[i] = 1;
    }
    for(int i = 1; i <= m ; i++){
        cin >> u >> v;
        deg[u]++;deg[v]++;
        unit(u , v);
    }
    for(int i = 1; i <= k ; i++){
        cin >> u >> v;
        if(get_fa(u ) == get_fa(v))cnt[u]--,cnt[v]--;
    }
    for(int i = 1; i <= n ; i++)cout << sz[get_fa(i)]-deg[i]+cnt[i]-1 << ' ';
}

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

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

  vector<string> s(n);

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

  sort(s.begin(), s.end(), greater<string>());

  int num = 1;
  for(int i = 0; i < n - 1; i++){
    if(s[i] != s[i + 1]){
      num++;
    }
  }

  cout << num << endl;

  return 0; 
}


Measured memory_bytes: 9548
import sys
import socket

hostname = socket.gethostname()

if hostname == 'F551C':
    sys.stdin = open('c1.in')


def read_int_list():
    return list(map(int, input().split()))


def read_str_list():
    return input().split()


def read_int():
    return int(input())


def read_str():
    return input()


def main():
    S = read_str()
    T = read_str()
    n = len(S)
    res = 'Yes'
    A = [0] * n
    B = [0] * n
    vu = {}
    for i in range(n):
        if S[i] in vu:
            A[i] = vu[S[i]]
        else:
            vu[S[i]] = i
            A[i] = vu[S[i]]

    vu = {}
    for i in range(n):
        if T[i] in vu:
            B[i] = vu[T[i]]
        else:
            vu[T[i]] = i
            B[i] = vu[T[i]]

    if A != B:
        res = 'No'

    # for i in range(n):
    #     for j in range(n):
    #         if S[i] != S[j] and T[i] == T[j]:
    #             res = 'No'
    #         if S[i] == S[j] and T[i] != T[j]:
    #             res = 'No'
    print(res)


main()


Measured memory_bytes: 7340
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, n) for(int i = 0; i < (n); i++)
#define MEM(a, x) memset(a, x, sizeof(a))
#define ALL(a) a.begin(), a.end()
#define UNIQUE(a) a.erase(unique(ALL(a)), a.end())
typedef long long ll;

int a, b;

int main(int argc, char const *argv[]) {
	ios_base::sync_with_stdio(false);
	cin >> a >> b;
	cout << a*a-b << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] v = new int[N];
		Arrays.setAll(v, i -> sc.nextInt());
		Arrays.sort(v);
		double ans = (v[0] + v[1]) / 2.0;
		for(int i = 2; i < N; i++) {
			ans = (ans + v[i]) / 2.0;
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 26836
import itertools


def main():
    s = input()
    res = int(s)
    all_indices = list(range(1, len(s)))
    for r in range(1, len(all_indices) + 1):
        for indices in itertools.combinations(all_indices, r):
            ss = s[:]
            for i in sorted(indices, reverse=True):
                ss = ss[:i] + '+' + ss[i:]
            res += eval(ss)
    print(res)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include <bits/stdc++.h>
          
#define pb push_back
#define ll long long
#define f first
#define s second
#define ld long double
#define fa fflush(stdout); 
#define mp make_pair
using namespace std;
void data() {
    #ifdef NURS
        freopen("main.in", "r", stdin);
        freopen("main.out", "w", stdout);
    #endif
    ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);;                                                      
} 
int dx[5] = {-1, 0, 0, 1};
int dy[5] = {0, -1, 1, 0};
  
const int N = 1e6 + 100;
const ll mod = 1e9 + 7;
const ll big = 1e9;
  
int main() 
{
    data();     
    int n;
    cin >> n;
    int a[n + 1];
    for (int i = 1; i <= n; i++)
    {
    	cin >> a[i];
    }
    ll ans = 0;
    ll s = 0;
    for (int i = 1; i <= n; i++)
    {
    	ans += a[i] * s;
    	s += a[i];
    	ans %= mod;
    	s %= mod;
    }
    cout << ans;
}
//a[3] * (a[1] + a[2]

Measured memory_bytes: 4456
#include <bits/stdc++.h>
#define INF 2e9
#define MOD 1000000007
#define MOD9 998244353
#define intMAX 51000;
#define PI 3.14159265359
using namespace std;
typedef long long llong;
typedef long double ldouble;

using Graph = vector<vector<int>>;

int main(){
  typedef pair<int, int> pair;
  int H, W, M;
  cin >> H >> W >> M;
  map<pair, bool> exist;
  vector<int> Hnum(H, 0);
  vector<int> Wnum(W, 0);
  for(int l=0; l<M; ++l) {
    int h, w;
    cin >> h >> w;
    --h; --w;
    exist[{h, w}] = true;
    ++Hnum[h]; ++Wnum[w];
  }
  vector<pair> Hpair;
  for(int i=0; i<H; ++i) Hpair.push_back(pair(Hnum[i], i));
  vector<pair> Wpair;
  for(int i=0; i<W; ++i) Wpair.push_back(pair(Wnum[i], i));
  sort(Hpair.rbegin(), Hpair.rend());
  sort(Wpair.rbegin(), Wpair.rend());
  int Hmax = 0;
  int Wmax = 0;
  for(int i=0; i<H; ++i){
    if(i==0) Hmax = Hpair[i].first;
    if(Hmax != Hpair[i].first) break;
    else{
      for(int j=0; j<W; ++j){
        if(j==0) Wmax = Wpair[j].first;
        if(Wmax != Wpair[j].first) break;
        else{
          if(!exist[{Hpair[i].second, Wpair[j].second}]){
            cout << Hmax + Wmax << endl;
            return 0;
          }
        }
      }
    }
  }
  cout << Hmax + Wmax - 1 << endl;
  return 0;
}

Measured memory_bytes: 32736
import java.io.*;
import java.math.*;
import java.util.*;

public class Main {
    private static boolean debug = false;
    private static boolean elapsed = false;

    private static PrintWriter _out = new PrintWriter(System.out);
    private static PrintWriter _err = new PrintWriter(System.err);

    private void solve(Scanner sc) {
        int n = sc.nextInt();
        int[] a = new int[n];
        int[] idx = new int[n];
        for (int i = 0; i < n; ++i) {
            a[i] = sc.nextInt() - 1;
            idx[a[i]] = i;
        }

        NavigableSet<Integer> set = new TreeSet<>();
        set.add(-1);
        set.add(n);
        long ans = 0;
        for (int i = 0; i < n; ++i) {
            int m = idx[i];
            int l = set.lower(m);
            int r = set.higher(m);
            ans += (long)(i + 1) * (m - l) * (r - m);
            set.add(m);
        }

        _out.println(ans);
    }
    private static BigInteger C(long n, long r) {
        BigInteger res = BigInteger.ONE;
        for (long i = n; i > n - r; --i) {
            res = res.multiply(BigInteger.valueOf(i));
        }
        for (long i = r; i > 1; --i) {
            res = res.divide(BigInteger.valueOf(i));
        }
        return res;
    }
    private static BigInteger P(long n, long r) {
        BigInteger res = BigInteger.ONE;
        for (long i = n; i > n - r; --i) {
            res = res.multiply(BigInteger.valueOf(i));
        }
        return res;
    }
    /*
     * 10^10 > Integer.MAX_VALUE = 2147483647 > 10^9
     * 10^19 > Long.MAX_VALUE = 9223372036854775807L > 10^18
     */
    public static void main(String[] args) {
        long S = System.currentTimeMillis();

        Scanner sc = new Scanner(System.in);
        new Main().solve(sc);
        _out.flush();

        long G = System.currentTimeMillis();
        if (elapsed) {
            _err.println((G - S) + "ms");
        }
        _err.flush();
    }
}

Measured memory_bytes: 92812
# 素数生成器
def generate_primes():
  from collections import defaultdict
  from itertools import count
  D = defaultdict(list)

  q = 2
  for q in count(2):
    if q in D:
      for p in D[q]:
        D[p+q].append(p)
      del D[q]
    else:
      yield q
      D[q*q].append(q)


n = int(input())

L = []
m = 0
for i in range(2,30001):
  if i % 2 == 0 or i % 3 == 0:
    L.append(i)
    m += i
    m %= 6
    if len(L) == n-1:
      break

t = sum(L)
if t % 2 != 0 and t % 3 != 0:
  for p in generate_primes():
    s = 6*p
    if (t%s)%p == 0:
      L.append(s-(t%s))
      break


else:
  m = t % 6
  for j in range(L[-1]+1,30001):
    if (j % 2 == 0 or j % 3 == 0) and (m+j) % 6 == 0:
      L.append(j)
      break

print(' '.join(map(str,L)))

Measured memory_bytes: 5460
n = int(input())


csf =  [tuple(map(int,input().split())) for _ in range(n-1)]

# print(csf)

for i in range(n-1):

    ans = csf[i][0] + csf[i][1]

    for j in range(i+1,n-1):
        here = csf[j]
        
        ans = max(ans,here[1])
        
        rm = ans % here[2]
        if rm != 0:
            ans += here[2] - rm
            
        ans += here[0]

#        print(ans)
    print(ans)

print(0)

Measured memory_bytes: 3188
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<cstdio>
#include<cstdlib>
#include<queue>
#include<list>
#include<deque>
#include<cmath>
#include<unordered_map>
#include<unordered_set>
#include<numeric>
using namespace std;

using ll = int64_t;

/// <summary>
/// 単純なcoutの時に使う
/// </summary>
#define co(a) cout<<a<<"\n"


/// <summary>
/// [beg, end)の範囲を，添え字indexでループするfor文に置換します
/// </summary>
#define rep(i,a) for(ll i=0; i<a; ++i)

/// <summary>
/// 迷路等で使う方向のベクトル
/// </summary>
const vector<ll> dx = { 0, 1, 0, -1 }, dy = { 1, 0, -1, 0 };

/// <summary>
/// デバッグ時に使う
/// </summary>
#define DEBUG(x)     std::cout << #x << " : " << x << "\n"

///////////////////////////////////////////////////////////////////////////

vector<vector<ll>> grid;

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

	ll N, M;
	cin >> N >> M;
	vector<ll> a (N + 3, 0);
	
	rep (i, M) {
		ll hoge;
		cin >> hoge;

		a[hoge] = -1;
	}

	rep (i, 2) {
		if (a[i] == -1) {
			continue;
		}
		a[i] = 1;
	}

	for (ll i = 2; i < N+1; ++i) {
		int sum = 0;

		if (a[i] == -1) {
			continue;
		}
		sum += a[i - 1] == -1 ? 0 : a[i - 1];
		sum += a[i - 2] == -1 ? 0 : a[i - 2];

		a[i] = sum % 1000000007;
	}

	cout << a[N] << endl;
}

Measured memory_bytes: 1024
#include<stdio.h>
int main()
{
    int h, n;

    scanf("%d %d", &h, &n);

    int arr[100000];

    int sum=0;

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

        sum = sum + arr[i];
    }

    if(sum>=h)
    {
        printf("Yes\n");
    }

    else
    {
        printf("No\n");
    }

    return 0;
}

Measured memory_bytes: 1992
#!/usr/bin/env python3
import sys


def solve(S: str):
    if len(set(S)) == 2:
        if list(S).count(list(set(S))[0]) == 2 and list(S).count(list(set(S))[1]) == 2:
            print("Yes")
        else:
            print("No")
    else:
        print("No")


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word

    tokens = iterate_tokens()
    S = next(tokens)  # type: str
    solve(S)


if __name__ == "__main__":
    main()


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

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

  int ans = 0;
  for (int i = 0; i < n; ++i) {
    int l, r;
    cin >> l >> r;
    ans += (r - l + 1);
  }

  cout << ans << endl;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        String S = sc.next();
        int cnt = 0;
        int y = 0;
        int n = 0;
        for(int i = 0;i < S.length();i++){
            for(int j = 0;j < S.length(); j++){
                if(S.charAt(i) == S.charAt(j)){
                    cnt++;
                }
            }
            if(cnt % 2 == 0){
                y++;
            }else{
                n++;
            } 
        }
        if(n == 0){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
        
    }
}


Measured memory_bytes: 23764
# -*- coding: utf-8 -*-


def main():
    n, k = map(int, input().split())
    h = list(map(int, input().split()))
    cost = [float('inf') for _ in range(n)]
    cost[n - 1] = 0

    for j in range(2, n + 1):
        for i in range(max(1, j - k), j + 1):
            cost[n - j] = min(cost[n - j],
                              cost[n - i] + abs(h[n - i] - h[n - j]))

    print(cost[0])


if __name__ == '__main__':
    main()


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

int main()
{
  int n, w;
  scanf("%d%d", &n, &w);
  vector<long long> dp(w + 1);
  for(int i = 0; i < n; i++)
  {
    int x, y;
    scanf("%d%d2", &x, &y);
    for(int weight = w - x; weight >= 0; weight--)
    {
      dp[weight + x] = max(dp[weight + x], dp[weight] + y);
    }
  }
  cout << dp[w];
  
  return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<math.h>
using namespace std;
int main(){
    int n,a,b;
    cin >> n >> a >> b;
    vector<int> p(n);
    for(int i=0;i<n;i++){
        cin >> p[i];
    }
    int e=0,f=0,g=0;
    for(int i=0;i<n;i++){
        if(p[i] <= a){
            e++;
        }else if(p[i] <= b){
            f++;
        }else{
            g++;
        }
    }
    int ans = min(min(e,f),g);
    cout << ans << endl;
    return 0;
}

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


int main(){
  string s,t,a1,a2,a3,a4;
  cin >> s;
  a1="maerd";
  a2="remaerd";
  a3="esare";
  a4="resare";
  int i=0;
  reverse(s.begin(),s.end());
  if(s[0]=='m'){
    t=a1;
    i+=5;
  }else if(s[0]=='e'){
    t=a3;
    i+=5;
  }else if(s[0]=='r' && s[2]=='m'){
    t=a2;
    i+=7;
  }else if(s[0]=='r' && s[2]=='s'){
    t=a4;
    i+=6;
  }
  while(i<s.size()){
    if(s[i]=='m'){
      t=t+a1;
      i+=5;
    }else if(s[i]=='e'){
      t=t+a3;
      i+=5;
      
    }else if(s[i]=='r' && s[i+2]=='m'){
      t=t+a2;
      i+=7;
    }else if(s[i]=='r' && s[i+2]=='s'){
      t=t+a4;
      i+=6;
    }else{
    i=s.size();
    }
  }
  if(s==t){
    cout << "YES" << endl;
  }else{
    cout << "NO" << endl;
  }
  return 0;
}


Measured memory_bytes: 696