akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#include<string.h>
 
typedef long long int ll;
#define all(x) (x).begin(), (x).end()
 
using namespace std;

int nxt() {
    int x;
    cin >> x;
    return x;
}

ll nxtl(){
    ll x;
    cin>>x;
    return x;
}
 
void SieveOfEratosthenes(int n,vector <int> &primes) 
{ 
    // Create a boolean array "prime[0..n]" and initialize 
    // all entries it as true. A value in prime[i] will 
    // finally be false if i is Not a prime, else true. 
    bool prime[n+1]; 
    memset(prime, true, sizeof(prime)); 
  
    for (int p=2; p*p<=n; p++) 
    { 
        // If prime[p] is not changed, then it is a prime 
        if (prime[p] == true) 
        { 
            // Update all multiples of p greater than or  
            // equal to the square of it 
            // numbers which are multiple of p and are 
            // less than p^2 are already been marked.  
            for (int i=p*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    } 
  
    // Print all prime numbers 
    for (int p=2; p<=n; p++) 
       if (prime[p]) 
          primes.push_back(p);
} 
 
ll max(ll a,ll b)
{
    if(a>b)
        return a;
    return b;
}
 
ll power(ll x, ll y,ll mod) 
{ 
    ll temp; 
    if( y == 0) 
        return 1; 
    temp = power(x, y/2,mod); 
    if (y%2 == 0) 
        return (temp*temp)%mod; 
    else
        return (((x*temp)%mod)*temp)%mod; 
} 

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n=nxtl(),k=nxtl();
    vector <ll> s(n+1);
    s[0]=0;
    for(int i=1;i<=n;i++)
    {
        ll x=nxtl();
        s[i]=s[i-1]+x;
    }
    map <ll,int> m;
    ll test=0;
    m[0]+=1;
    for(int i=1;i<=n;i++)
    {
        if(i-k>=0)
            m[(s[i-k]-(i-k))%k]-=1;
        test+=m[(s[i]-i)%k];
        m[(s[i]-i)%k]+=1;
    }
    cout<<test<<endl;
    
    
    

    return 0;   
}


 
 


Measured memory_bytes: 14336
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

#define EPS 1e-9
#define INF 1070000000LL
#define MOD 1000000007LL
#define fir first
#define foreach(it,X) for(__typeof((X).begin()) it=(X).begin();it!=(X).end();it++)
#define ite iterator
#define mp make_pair
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define pb push_back
#define sec second
#define sz(x) ((int)x.size())

using namespace std;

typedef istringstream iss;
typedef long long ll;
typedef pair<int,int> pi;
typedef stringstream sst;
typedef vector<int> vi;

int N,M;
double P;
int u[111],v[111];
double dp[1<<14];

int main(){
	cin.tie(0);
	ios_base::sync_with_stdio(0);
	
	cin>>N>>M>>P;
	P/=100;
	rep(i,M)cin>>u[i]>>v[i],u[i]--,v[i]--;
	
	rep2(mask,1,1<<N){
		
		if(__builtin_popcount(mask)==1){
			dp[mask]=1;
			continue;
		}
		
		dp[mask]=1;
		int par=N-1;
		while(!(mask>>par&1))par--;
		int sub=mask,e;
		
		while(1){
			sub=(sub-1)&mask;
			e=0;
			rep(i,M){
				if((sub>>u[i]&1) && !(sub>>v[i]&1) && (mask>>v[i]&1)
				|| (sub>>v[i]&1) && !(sub>>u[i]&1) && (mask>>u[i]&1))e++;
			}
			//cout<<mask<<" - "<<dp[sub]<<" * "<<pow(P,e)<<endl;
			dp[mask]-=dp[sub]*pow(P,e);
			if(sub==(1<<par))break;
		}
		
		//cout<<mask<<" "<<dp[mask]<<endl;
	}
	//cout<<setprecision(16)<<dp[(1<<N)-1]<<endl;
	printf("%.16f\n",dp[(1<<N)-1]);
}

Measured memory_bytes: 1396
#include <iostream>

/*さいころの面の数*/
const unsigned int FACE_SIZE = 6;

/*さいころの面の位置と、配列の番号の対応*/
enum FaceNumber{ TOP, SOUTH, EAST, WEST, NORTH, BOTTOM };

class Dice{
	private:
		/*face[i]はi面の数字
		 *iは{ TOP, SOUTH, EAST, WEST, NORTH, BOTTOM }のどれかを取る*/
		int face[FACE_SIZE];
		/*swapFace：引数で指定した順番にfaceを入れ替える関数*/
		void swapFace(int[FACE_SIZE]);
	public:
		/*Dice():入力された6つの数値でfaceを初期化*/
		Dice();
		/*Dice::turn：commandで指定された方向にさいころを転がす*/
		void turn(char command);
		/*fNumで指定された面の数字を返す*/
		int getFace(int fNum){ return face[fNum]; }
};

/*Dice():入力された6つの数値でfaceを初期化*/
Dice::Dice(){
	for (size_t i = 0; i < FACE_SIZE; i++)
	{
		std::cin >> face[i];
	}
}

/*swapFace：引数で指定した配列の順番にfaceを入れ替える関数
 *配列の中身が{ WEST, SOUTH, TOP, BOTTOM, NORTH, EAST }なら、
 *face[TOP]をface[WEST]に、face[SOUTH]はそのまま、face[EAST]をface[TOP]に・・・
 *というように入れ替える
 *参考： enum FaceNumber{ TOP, SOUTH, EAST, WEST, NORTH, BOTTOM }
*/
void Dice::swapFace(int* afterFace){
	int tmp[FACE_SIZE];									//変更前のさいころの面を保存する一時変数
	for (size_t faceNum = 0; faceNum < FACE_SIZE; faceNum++)
	{
		tmp[faceNum] = face[faceNum];
	}
	for (size_t faceNum = 0; faceNum < FACE_SIZE; faceNum++)
	{
		//faceNum面の数字を更新する
		int num = afterFace[faceNum];
		face[faceNum] = tmp[num];
	}
}

//commandで指定された方向にさいころを転がす
void Dice::turn(char command){
	if (command == 'E'){
		int afterFace[FACE_SIZE] = { WEST, SOUTH, TOP, BOTTOM, NORTH, EAST };
		Dice::swapFace(afterFace);
	}
	else if (command == 'N'){
		int afterFace[FACE_SIZE] = { SOUTH, BOTTOM, EAST, WEST, TOP, NORTH };
		Dice::swapFace(afterFace);
	}
	else if (command == 'S'){
		int afterFace[FACE_SIZE] = { NORTH, TOP, EAST, WEST, BOTTOM, SOUTH };
		Dice::swapFace(afterFace);
	}
	else if (command == 'W'){
		int afterFace[FACE_SIZE] = { EAST, SOUTH, BOTTOM, TOP, NORTH, WEST };
		Dice::swapFace(afterFace);
	}
}

int main(){
	Dice dice1 = Dice();
	char commands[100];

	std::cin >> commands;

	for (size_t i = 0; commands[i] != '\0'; i++)
	{
		dice1.turn(commands[i]);
	}

	std::cout << dice1.getFace(TOP) << std::endl;
	
	return 0;
}


Measured memory_bytes: 3116
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define FORq(i, m, n) for(int i = m;i <= n;i++)
#define SCD(n) scanf("%d",&n)
#define SCD2(m,n) scanf("%d%d",&m,&n)
#define SCD3(m,n,k) scanf("%d%d%d",&m,&n,&k)
#define PB push_back
#define MP make_pair
#define ARSCD(A,N) REP(i,N){SCD(A[i]);}
#define ARSCD1(A,N) FORq(i,1,N){SCD(A[i]);}
#define PRINTD(n) printf("%d\n",n)
#define PRINTLLD(n) printf("%lld\n",n)
#define DEBUG printf("%s\n","debug")
#define fst first
#define snd second
using namespace std;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef long long ll;
//////////////////////////////////////////////////////
int main(){
	int A,B;
	SCD2(A,B);
	int ans = 0;
	
	FORq(i,1,A-1){
		FORq(j,1,30){
			if (i==j) ans++;
		}
	}
	
	FORq(j,1,B){
		if (A==j) ans++;
	}
	
	PRINTD(ans);
	
    return 0;
}

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


int main(){
    
    int i;
    char str[210];
    gets(str);
    
    for (i=0; i<strlen(str); i++) {
        if(str[i]>='a' && str[i]<='z')
            str[i] =str[i]-32;
    }
    puts(str);
    
    return 0;
    
}

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

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

bool edge[51][51];
bool visited[51];
int a[50], b[50];
int n, m;

void dfs(int i) {
  visited[i] = true;
  FOR(j,1,n+1) {
    if (edge[i][j] && !visited[j]) {
      dfs(j);
    }
  }
}

int main() {
  cin >> n >> m;
  REP(i,m) {
    cin >> a[i] >> b[i];
    edge[a[i]][b[i]] = edge[b[i]][a[i]] = true;
  }
  int ans = 0;
  REP(i,m) {
    edge[a[i]][b[i]] = edge[b[i]][a[i]] = false;
    FOR(j,1,n+1) visited[j] = false;
    dfs(1);
    FOR(j,1,n+1) if (!visited[j]) { ans++; break; }
    edge[a[i]][b[i]] = edge[b[i]][a[i]] = true;
  }
  cout << ans << endl;
  return 0;
}


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

#define N 200010
int n, a[N], b[N];

bool ok() {
    for (int i = 1; i <= n; ++i) {
        int tot = 0;
        for (int j = i; j <= n; j += i) {
            tot = tot + b[j];
            tot %= 2;
        }
        if (tot ^ a[i]) return 0;
    }
    return 1;
}

int main() {
    while (scanf("%d", &n) != EOF) {
        for (int i = 1; i <= n; ++i) scanf("%d", a + i);
        for (int i = n; i >= 1; --i) {
            int now = 0;
            for (int j = i + i; j <= n; j += i) {
                now += b[j];
                now %= 2;
            }
            b[i] = now ^ a[i];
        }

            vector <int> vec;
            for (int i = 1; i <= n; ++i) if (b[i]) vec.push_back(i);
            int sze = (int)vec.size();
            printf("%d\n", sze);
            for (int i = 0; i < sze; ++i) printf("%d%c", vec[i], " \n"[i == sze - 1]);

    }
    return 0;
}

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

#define newline printf("\n")
#define nl '\n'
#define ll long long 
#define ui unsigned int
#define ul unsigned long

using namespace std;

int main()
{
	int N;
	scanf("%d", &N);

	int digit = N % 10;

	string result;

	if(digit == 0 || digit == 1 || digit == 6 || digit == 8){
		result = "pon";
	} else if(digit == 3){
		result = "bon";
	} else {
		result = "hon";
	}

	cout << result << nl;

	return 0;
}


Measured memory_bytes: 3656
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,k,ans;
ll a[200100];
ll mod=1e9+7;
int main()
{
	cin>>n>>k;
	for(int i=1;i<=n;i++)  scanf("%lld",&a[i]);
	sort(a+1,a+1+n);
	bool pd=0;
	ll l=1,r=n;
	ans=1;
	if(k&1)
	{
		if(a[n]<0)
		{
		  for(int i=1;i<=k;i++)  
		  ans=ans*a[n-i+1]%mod;	
		  pd=1;
		}
		else 
		{
			ans=a[n];
			r--;
		} 
		k--;
	}
	
	if(!pd)
	while(k)
	{
		ll aa=a[l]*a[l+1];
		ll bb=a[r]*a[r-1];
		if(aa>bb)  ans=ans*(aa%mod)%mod,l+=2;
		else       ans=ans*(bb%mod)%mod,r-=2;
		k-=2;       
	}
	cout<<(ans+mod)%mod<<endl;
	return 0;
}

Measured memory_bytes: 5224
# 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 = 998244353;//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, acost, bcost; };
struct edge {
	LL from, to, cost;
};
vector<vector<LL>>g;
vector<edge>ed;
vector<Pll>pv;
map<Pll, LL>ma;
set<LL>st;
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[200000],b[200000];
string str;
bool f;
char c[1100][1100];
int main() {
	cin >> s >> t >> w;
	cout << max(w-(s - t),0LL) << endl;
	return 0;
}

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

int main(){
    char s[4];
    int ab = 0, cd =0;
    scanf("%s", s);
    for(int i = 0; i < 2; i++){
        ab += pow(10,(1 - i)) * (s[i] - '0');
    }
    for(int i = 2; i < 4; i++){
        cd += pow(10,(3-i ))* (s[i]-'0');
    }
    if(1 <= ab && ab <= 12){
        if(1 <= cd && cd <= 12){
            cout << "AMBIGUOUS" <<endl;
        }else{
            cout << "MMYY\n";
        }
    }else{
        if(1 <= cd && cd <= 12){
            cout << "YYMM" <<endl;
        }else{
            cout << "NA\n";
        }
    }
    return 0;
}

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

using namespace std;

int main () {
	string strA, strB;
	cin >> strA >> strB;

	sort(strA.begin(), strA.end());
	sort(strB.begin(), strB.end(), greater<char>());

	if (strA < strB) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}


Measured memory_bytes: 888
#include<bits/stdc++.h>
#define fastio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define endl '\n'
#define pb push_back
#define ll long long
#define ull unsigned long long
#define vi vector<int>
using namespace std;
constexpr int MOD=1e9+7;
constexpr int mod=998244353;

bool prime(int n){
    for(int i = 2 ; i <= sqrt(n) ; ++i){
        if(n % i == 0) {
            return 0 ; 
        }
    }

    return 1 ; 
}

int main() {
    ll n ; 
    cin >> n ; 
    int num = 26 ; 
    ll ans = n ; 
    string res = "" ; 
    while(ans ) {
        int rem = ans % 26 ;
        ans = ans / 26 ; 
        if(rem == 0){
            res += 'z' ; 
            ans--;
        }
        else
        res += char('a' + rem-1) ; 
    }

    for(int i = res.size()-1 ; i>= 0; --i)
    cout << res[i] ;  
    
    // char t = 'z' ; 
    // cout << (int)t << endl; 
    return 0 ; 
}

Measured memory_bytes: 3724
#include <iostream>
#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;

int main() {
  int h, w, a, b;
  cin >> h >> w >> a >> b;
  rep(i, h) {
    rep(j, w) {
      if ((i < b) ^ (j < a))
        cout << 1;
      else
        cout << 0;
    }
    cout << endl;
  }
}


Measured memory_bytes: 1280
#include <iostream>
#include <string>
#include <algorithm>
#include<iomanip>
#include<cmath>
using namespace std;

int main() {
	int n;
	cin >> n;
	int a = n;
	int x = 0;
	while (n != 0) {
		x += n % 10;
		n /= 10;
	}
	if (a % x == 0)cout << "Yes";
	else cout << "No";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	string s;
	cin >> s;
	int l;
	l=s.size();
	int st,f,ans;
	st = 0;f= l-1;ans=0;
	while(st<f){
		if(s[st]==s[f]){
			++st;--f;
		}else if(s[st]=='x'){
			++ans;
			++st;
		}else if(s[f]=='x'){
			++ans;
			--f;
		}else{
			cout << -1 << endl;
			return 0;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 512
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
void p(vector<int> A){rep(i,A.size()){cout << A[i];}cout << endl;}

int main(){
    int n;
    cin >> n;
    vector<int> a(n+1);
    rep(i,n+1) cin >> a[i];
    vector<int> b(n);
    rep(i,n) cin >> b[i];
    ll ans = 0;
    rep(i,n){
        int left = min(b[i],a[i]);
        ans += left;
        a[i] -= left;
        b[i] -= left;
        int right = min(b[i],a[i+1]);
        ans += right;
        a[i+1] -= right;
        b[i] -= right; 
    }
    cout << ans;
}

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

int main() {
	 int n,m,a,b;
	 cin>>n>>m>>a>>b;
	 int X[n], Y[m];
	 for(int i=0;i<n;i++)
	 {
	 	cin>>X[i];
	 }
	 sort(X,X+n,greater<int>());
	 for(int i=0;i<m;i++)
	 {
	 	cin>>Y[i];
	 }
	sort(Y,Y+m);
	bool ok=false;
	for(int i=a+1;i<=b;i++)
	{
		if(Y[0]>=i&&i>X[0])
		{ 
			ok=true;
			break;
		}
		
	}
	
	cout<<(ok? "No War": "War");
}

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

int main() {
	int N;
	cin >> N;
	map<string, int> mp;
	bool ok = true;

	char h, t;
	for (int i = 0; i < N; i++) {
		string s;
		cin >> s;
		mp[s]++;
			
		if (i == 0) {
			h = s[0];
			t = s[s.size() - 1];
			continue;
		}

		h = s[0];

		if ((mp[s] > 1) || (h != t)) {
			ok = false;
		} else {
			t = s[s.size() - 1];
		}
	}

	if (ok) {
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#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 Graph vector<vecctor<ll>>
#define pairs vector<pair<ll,ll>>
#define pb push_back



using namespace std;
using ll = long long;
const ll INF = 1e18;
const double PI = acos(-1);

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 = 1e9+7;


int main(void){
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    int n,suc = 0,ans = 0;
    cin >> n;
    rep(i,n){
        int a,b;
        cin >> a >> b;
        if(a == b){
            suc++;
        }else{
            suc = 0;
        }
        if(suc == 3)ans = 1;
    }
    if(ans){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;

}

Measured memory_bytes: 3648
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cctype>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <stack>
#include <iomanip>
#include <cstdio>
#include <numeric>
#include <functional>
#include <cstdlib>
#include <regex>
#include <list>
int main() {
	int n;
	std::cin >> n;
	std::vector<double> x(n);
	std::vector<std::string> u(n);
	double otoshidama = 0;
	for (int i = 0;i < n;++i) {
		std::cin >> x[i] >> u[i];
	}
	for (int i = 0;i < n;++i) {
		if (u[i] == "JPY") {
			otoshidama += x[i];
		}
		else if (u[i] == "BTC") {
			otoshidama += x[i] * 380000.0;
		}
	}
	std::cout << otoshidama << std::endl;
	return 0;
}

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

using namespace std;

const long long int MOD = 1e9 + 7;
long long int dp[2001];

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

	memset(dp,0,sizeof(dp));
	dp[0] = 1;

	for(int i=0;i<=2000;i++)
	{
		for(int j=3;j<=2000;j++)
		{
			if(i+j<=2000)
			{
				dp[i+j] = ((dp[i+j]%MOD) + (dp[i]%MOD)%MOD);
				dp[i+j]%=MOD;
			}
		}
	}

	int s;

	cin >> s;

	cout << dp[s] << '\n';
	
	return 0;
}


Measured memory_bytes: 3628
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
  vector<int> X(1000010);
  for(int x=1;x<=100;x++){
    for(int y=1;y<=100;y++){
      for(int z=1;z<=100;z++){
        X.at(x*x+y*y+z*z+x*y+y*z+z*x-1)++;
      }
    }
  }
  
  int N;
  cin>>N;
  for(int i=0;i<N;i++) cout<<X.at(i)<<endl;
  return 0;}


Measured memory_bytes: 6984
#include <bits/stdc++.h>
// statics
using namespace std;
using int64 = long long;
using PAIR = pair<int64, int64>;
constexpr int INF = 1 << 30;
constexpr int64 LINF = 1LL << 60;
constexpr int MOD = 1e9 + 7;
constexpr int MAX_N = 3e5 + 1;

// init/input
#define int int64
#define INIT ios::sync_with_stdio(false);cin.tie(0);
#define VAR(type, ...) type __VA_ARGS__;MACRO_VAR_Scan(__VA_ARGS__);
template<typename T> void MACRO_VAR_Scan(T &t) {cin>>t;}
template<typename First, typename...Rest> void MACRO_VAR_Scan(First &first, Rest&...rest) {cin>>first;MACRO_VAR_Scan(rest...);}
#define VEC(type, c, n) vector<type> c(n);for(auto &&i:c)cin>>i;

// out
#define OUT(dist) cout<<(dist);
#define FOUT(n, dist) cout<<fixed<<setprecision(n)<<(dist);
#define SP cout<<" ";
#define BR cout<<endl;
#define zero(n) cout<<setfill('0')<<right<<setw(n)
#define debug(x) cerr<<#x<<":"<< (x);BR;

// utility
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define EACH(i, a) for(auto &&i:(a))
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define RFOR(i, a, b) for(int i=(b)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<(n);++i)
#define RREP(i, n) for(int i=(n)-1;i>=0;--i)
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; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}

signed main() {
  INIT;
	VAR(int,n);
  vector<PAIR> a(n);
  REP(i,n){
    VAR(int,p,q);
    a[i] = make_pair(q,p);
  }

  sort(ALL(a));

  int now = 0;
  REP(i,n){
    now += a[i].second;
    if (now>a[i].first) {
      OUT("No")BR;
      return 0;
    }
    debug(now);
  }
  OUT("Yes")BR;
  
  return 0;
}


Measured memory_bytes: 3584
"use strict";
const main = arg => {
  let num1, num2;
  let ans = 0;
  let info = arg * 1;
  for(let i = 1; i <= Math.sqrt(info); i++){
    if(info % i == 0){
      ans = i + (info / i) - 2;
    }
  }
  if(ans == 0){
  	ans = info - 1;
  }
  console.log(ans);
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 23752
A = int(input())
X = [input() for _ in range(A)]
B = int(input())
Y = [input() for _ in range(B)]
t = 0
for x in X:
  if X.count(x)-Y.count(x)>t:
    t = X.count(x)-Y.count(x)
  else:
    pass
print(t)

Measured memory_bytes: 9000
#include<iostream>


#define maxn 100005
#define ll long long 
using namespace std;

ll DP[maxn];
int N, K;
int height[maxn];

ll min(ll a, ll b) {
	if(a <= b) return a;
	return b;
}

ll cal(int pos) {
	if (pos == N - 1) return 0LL;


	ll &res = DP[pos];

	if (res != -1) return res;
	res = abs(height[pos + 1] - height[pos]) + cal(pos + 1);
	for (int i = 2; i <= K; i++) {
		if (pos + i < N) {
			res = min(res, abs(height[pos + i] - height[pos]) + cal(pos + i));
		}
	}

	return res;
}


int main() {

	cin >> N >> K;
	for (int i = 0; i < N; i++) {
		cin >> height[i];
	}

	for (int i = 0; i < maxn; i++) {
		DP[i] = -1;
	}

	cout << cal(0) << endl;

	return 0;
}

Measured memory_bytes: 6144
#include <iostream>
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

using namespace std;

int N, Q;
vector<int> edges[202020];
long long num[202020];

void dfs(int i, int p){
    for (int j : edges[i]){
        if (j != p){
            num[j] += num[i];
            dfs(j, i);
        }
    }
}

int main(){
    cin >> N >> Q;
    
    //グラフの入力を受け取る
    for (int i = 0; i < N-1; i++){
        int a, b;
        cin >> a >> b;
        a--, b--;
        edges[a].push_back(b);
        edges[b].push_back(a);
    }
    
    for (int i = 0; i < Q; i++){
        int p, x;
        cin >> p >> x;
        num[p-1] += x;
    }
    
    
    dfs(0, -1);
    
    for (int i = 0; i < N; i++) cout << num[i] << " ";
}

Measured memory_bytes: 24320
#include<bits/stdc++.h>
using namespace std;
#define ll long long
typedef pair<ll,ll> P;
#define MOD 1000000007
int main(){
  ll n,k;
  cin>>n>>k;
  vector<ll> a(n),b(n);
  for(int i=0;i<n;i++){
    cin>>a[i];
    b[i]=a[i];
  }
  if(k==0){
    ll c=0;
    for(int i=0;i<n;i++) c+=a[i];
    cout<<c;
    return 0;
  }
  sort(a.begin(),a.end());
  reverse(a.begin(),a.end());
  ll x=max(a[0],k);
  ll c=0;
  while(x!=0){
    x/=2;
    c++;
  }
  vector<ll> d(c,0);
  for(int i=0;i<n;i++){
    for(int j=0;j<c;j++){
      if(b[i]%2==1) d[j]++;
      b[i]/=2;
    }
  }
  x=k;
  ll cnt=0;
  while(x!=0){
    x/=2;
    cnt++;
  }
  x=a[0];
  ll cn=0;
  while(x!=0){
    x/=2;
    cn++;
  }
  vector<ll> f(c);
  x=k;
  for(int i=0;i<c;i++){
    f[i]=x%2;
    x/=2;
  }
  ll me=0;
  x=1;
  for(int i=0;i<c;i++){
    if(i<cnt-1){
      me+=max(d[i],n-d[i])*x;
      x*=2;
    }else{
      me+=d[i]*x;
      x*=2;
    }
  }
  ll mem=0;
  x/=2;
  bool bo=false;
  for(int i=c-1;i>=0;i--){
    if(bo){
      mem+=max(d[i],n-d[i])*x;
      x/=2;
    }else{
      if(f[i]==0){
        mem+=d[i]*x;
        x/=2;
      }else{
        if(d[i]<n-d[i]){
          mem+=(n-d[i])*x;
          x/=2;
        }else{
          mem+=max(d[i],n-d[i])*x;
          x/=2;
          bo=true;
        }
      }
    }
  }
  cout<<max(me,mem);
}

Measured memory_bytes: 1792
n,m,p=map(int,input().split())
l=[list(map(int,input().split())) for i in range(m)]
distance=[float('inf')]*n
distance[0]=0
for i in range(n-1):
  for j in range(m):
    if distance[l[j][1]-1]>distance[l[j][0]-1]-l[j][2]+p:
      distance[l[j][1]-1]=distance[l[j][0]-1]-l[j][2]+p
x=distance[n-1]
for i in range(n):
  for j in range(m):
    if distance[l[j][1]-1]>distance[l[j][0]-1]-l[j][2]+p:
      distance[l[j][1]-1]=-float('inf')
if distance[n-1]!=x:
  print(-1)
else:
  print(max(-distance[n-1],0))

Measured memory_bytes: 48216
from collections import Counter
N = int(input())
A = list(map(int,input().split()))
sum_list = [0]*(N+1)
for i in range(N):
    sum_list[i+1] = sum_list[i]+A[i]

sum_list = Counter(sum_list)
sum_list =list(sum_list.items())

ans = 0
for i in range(len(sum_list)):
    ans += sum_list[i][1]*(sum_list[i][1]-1)/2

print(int(ans))

Measured memory_bytes: 48276
// IOI 2021
#include <bits/stdc++.h>
using namespace std;
 
#define endl '\n'
#define ends ' '
#define die(x) return cout << x << endl, 0
#define all(v) v.begin(), v.end()
#define sz(x) (int)(x.size())
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) { cerr << ends << H; debug_out(T...); }
#define debug(...) cerr << "{" << #__VA_ARGS__ << "}:", debug_out(__VA_ARGS__)
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1e9;
const ll MOD = 998244353;
 
////////////////////////////////////////////////////////////////////
 
const int N = 3e3 + 5;

int DP[N][N];

int main() {
 
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	mt19937 Rnd(time(0));

	int a, b, c, d; cin >> a >> b >> c >> d;
	DP[a][b] = 1;
	for (int i = a; i <= c; i++) for (int j = b; j <= d; j++) if (!DP[i][j]) 
		DP[i][j] = (1LL * DP[i][j - 1] * i % MOD + 1LL * DP[i - 1][j] * j % MOD - 1LL * DP[i - 1][j - 1] * (i - 1) * (j - 1) % MOD + MOD) % MOD;
	cout << DP[c][d] << endl;

	return 0;
}


Measured memory_bytes: 38700
#include <bits/stdc++.h>
#define N 190
#define M 17
#define INF 1000000000
#define LINF 1000000000000000000
#define MOD 1000000007
#define INF63 1061109567
#define INF127 9187201950435737471
using namespace std;
int n,m,dp[N][N][N][M];
char grid[N][N];
int dfs(int x,int l,int r,int k){
	if(l>r||k==-1) return 0;
	if(dp[x][l][r][k]!=-1) return dp[x][l][r][k];
	if(k==0) return x-1;
	if(k>=r-l) dp[x][l][r][k]=x;
	int lb,ub,mid,t,left,right;
	
	t=dfs(x,l,r,k-1);
	//cout<<x<<" "<<l<<" "<<r<<" "<<k<<" "<<t<<endl;
	if(t!=n-1) dp[x][l][r][k]=max(dp[x][l][r][k],dfs(t+1,l,r,k-1));
	else dp[x][l][r][k]=n-1;
	lb=0;
	ub=r-l-1;
	while(lb<=ub){
		mid=(lb+ub)/2;
		left=dfs(x,l,l+mid,k-1);
		right=dfs(x,l+mid+1,r,k-1);
		dp[x][l][r][k]=max(dp[x][l][r][k],min(left,right));
		if(left<=right) ub=mid-1;
		else lb=mid+1;
	}
	return dp[x][l][r][k];
}
int main(){
	int i,j,k,ans;
	cin>>n>>m;
	for(i=0;i<n;i++) for(j=0;j<m;j++) cin>>grid[i][j];
	memset(dp,-1,sizeof(dp));
	for(i=0;i<n;i++)
		for(j=0;j<m;j++){
			k=i;
			while(k<n&&grid[k][j]==grid[i][j]) k++;
			dp[i][j][j][0]=k-1;
		}
	for(i=0;i<n;i++)
		for(j=0;j<m;j++)
			for(k=j+1;k<m;k++){
				if(grid[i][k]!=grid[i][j]) break;
				dp[i][j][k][0]=min(dp[i][j][k-1][0],dp[i][k][k][0]);
			}
	for(i=0;i<18;i++){
		ans=dfs(0,0,m-1,i);
		if(ans==n-1) break;
	}
	cout<<i<<endl;
	return 0;
}

Measured memory_bytes: 456316
import sys
input = sys.stdin.readline
N = int(input())
a = list(map(int, input().split()))
mx = -float("inf")
mn = float("inf")
mxi = 0
mni = 0
for i in range(N):
  x = a[i]
  if mx < x:
    mx = x
    mxi = i
  if mn > x:
    mn = x
    mni = i
print(2 * N - 1)
if abs(mx) > abs(mn):
  for i in range(N): print(mxi + 1, i + 1)
  for i in range(N - 1): print(i + 1, i + 2)
else:
  for i in range(N): print(mni + 1, i + 1)
  for i in range(N - 1, 0, -1): print(i + 1, i)

Measured memory_bytes: 38256
#include <bits/stdc++.h>
using namespace std;
#define mt make_tuple
#define mp make_pair
#define int long long
 
int a[200005], p[200005];
 
main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int k, n, r = 1e9;
	cin >> k >> n;
	for (int i = 1; i <= n; i++) cin >> a[i];
	for (int i = 1; i <= n; i++) {
		r = min({r, a[n] - a[i] + (i != 1 ? k - a[n] + a[1] : 0) + a[i] - a[1], a[i] - a[1] + (i != n ? k - a[n] + a[1] : 0) + a[n] - a[i + 1]});
	}
	cout << r << '\n';
}


Measured memory_bytes: 1792
def examA():
    N = I()
    ans = 180*(N-2)
    print(ans)


import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

examA()


Measured memory_bytes: 38256
#include <cstring>
#include <map>
#include <unordered_map>
#include <string>
#include <list>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <cstdio>
#include <iostream>
#include <set>
#include <unordered_set>
using namespace std;

#define MAX(a,b) (a>b?a:b)
#define MIN(a,b) (a<b?a:b)
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef pair<int, int> pii;

int gi() {
    int a;
    scanf("%d", &a);
    return a;
}

ll gli() {
    ll a;
    scanf("%lld", &a);
    return a;
}

#define M 1000000007LL
ll f[100004];
ll fi[100004];
ll a[100000];

ll pw(ll a, ll b) {
    if (b == 0)
        return 1LL;
    ll x = pw(a, b/2);
    x = (x*x) % M;
    if (b%2)
        return (x*a)%M;
    return x;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n = gi();
    ll k = gi();
    f[0] = 1;
    fi[0] = 1;
    for (ll i = 1; i <= n; i++) {
        a[i-1] = gi();
        f[i] = (f[i-1] * i) % M;
        fi[i] = pw(f[i], M-2LL);
    }

    sort(a, a+n);
    ll mx = 0, mn = 0;
    for (int i = 0; i < n; i++) {
        if (n-i >= k) {
            // c[n-i-1][k-1]
            ll r = (((f[n-i-1] * fi[k-1]) % M) * fi[n-i-k]) % M;
            mn += r * a[i];
            mn %= M;
        }
        if (i+1 >= k) {
            // c[i][k-1]
            ll r = (((f[i] * fi[k-1]) % M) * fi[i+1-k]) % M;
            mx += r * a[i];
            mx %= M;
        }
    }

    mx += M-mn;
    mx %= M;
    cout << mx << endl;

    return 0;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
  
#define FOR(i,a,b) for( ll i = (a); i < (ll)(b); i++ )
#define REP(i,n) FOR(i,0,n)
#define YYS(x,arr) for(auto& x:arr)
#define ALL(x) (x).begin(),(x).end()
#define SORT(x) sort( (x).begin(),(x).end() )
#define REVERSE(x) reverse( (x).begin(),(x).end() )
#define UNIQUE(x) (x).erase( unique( ALL( (x) ) ) , (x).end() )
#define PW(x) (1LL<<(x))
#define SZ(x) ((ll)(x).size())
#define SHOW(x) cout << #x << " = " << x << endl
 
#define pb emplace_back
#define fi first
#define se second

using namespace std;
 
typedef long double ld;
typedef long long int ll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<bool> vb;
typedef vector<ld> vd;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<vpl> gr;
typedef vector<vl> ml;
typedef vector<vd> md;
typedef vector<vi> mi;
 
const ll INF = (ll)1e9 + 10;
const ll INFLL = (ll)1e18 + 10;
const ld EPS = 1e-8;
const ll MOD = 1e9+7;

template<class T> T &chmin( T &a , const T &b ){ return a = min(a,b); }
template<class T> T &chmax( T &a , const T &b ){ return a = max(a,b); }
template<class T> inline T sq( T a ){ return a * a; }
ll in(){ ll x; scanf( "%lld" , &x ); return x; }
 
// head

int n;
int a[128];
int ans = INF;


int calc( int x ){
  int res = 0;
  REP( i , n ){
    res += sq( x - a[i] );
  }
  return res;
}

int main(){

  n = in();
  REP( i , n ){
    a[i] = in();
  }

  FOR( i , -110 , 110 ){
    chmin( ans , calc( i ) );
  }

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


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

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

		int i=0;
		while(N >= Math.pow(2, i)) {
			i++;
		}
		System.out.println((int)Math.pow(2, i-1));

	}

}


Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
string s;
char f[20];
int main(){
	int tot=0;
	cin>>s;
	for(int i=0;i<s.size();i++){
		if(s[i]=='B'){
			if(tot>0)tot--;
		}
		else f[++tot]=s[i];
	}
	for(int i=1;i<=tot;i++)
	cout<<f[i];
	cout<<"\n";
	return 0;
}

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

int main() {
  int N; cin>>N;
  int ans = 0;
  for(int i=1; i<=N; i+=2){
      int eig = 0;
    for(int j=1; j<=i; j++){
      if(i%j==0){
      eig ++;
    }
      if(eig == 8){
        ans ++;
      }
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define v vector
#define ar array

using namespace std;


string s;

int main(){
	cin>>s;
	if(s[0] =='R' && s[1]=='R' && s[2]=='R')
		cout<<3;
	else if(s[0]=='R' && s[1]=='R')
		cout<<2;
	else if(s[1]=='R'&&s[2]=='R')
		cout<<2;
	else if(s[0]=='R' || s[1]=='R' || s[2]=='R')
		cout<<1;
	else 
		cout<<0;
	return 0;
}


Measured memory_bytes: 3664
#include <iostream>
#include <queue>

using namespace std;
using pii = pair<int, int>;
#define loop(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)
#define in(v) cin>>v;
#define out(v) cout<<v<<"\n"

const int di[4] = {1, 0, -1, 0}, dj[4] = {0, 1, 0, -1};
const int INF = 1e9;
int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  int H, W; in(H); in(W);

  char s[H][W];
  int visited[H*W];
  int count = 0;
  rep(i, H) rep(j, W) {
    visited[i*W+j] = INF;
    in(s[i][j]);
    if (s[i][j] == '.')
      ++count;
  }
  queue<int> q;
  q.push(0);
  visited[0] = 0;
  while (!q.empty()) {
    int p = q.front(); q.pop();
    int i = p / W,
        j = p % W;
    if (p == H*W-1)
      break;
    rep(d, 4) {
      int next_i = i + di[d], next_j = j + dj[d];
      int next = next_i * W + next_j;
      if (0 <= next_i && next_i < H &&
          0 <= next_j && next_j < W &&
          s[next_i][next_j] == '.' && visited[next] == INF) {
        visited[next] = visited[p] + 1;
        q.push(next);
      }
    }
  }
  if (visited[H*W-1] == INF) {
    out(-1);
    return 0;
  }
  out(count - visited[H*W-1] - 1);

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const long long M=1000000007;
long long fact[200001];
long long inv[200001];
long long qpow(long long x,long long y) //unit*x=x
{
    long long ans=1;
    while (y){
        if (y&1) ans=ans*x%M;
        x=x*x%M;
        y=y>>1;
    }
    return ans;
}
long long C(int a,int n){
    return fact[n]*inv[a]%M*inv[n-a]%M;
}
void init(){
    fact[0]=1;
    for (int i=1;i<=200000;++i) fact[i]=(fact[i-1]*i)%M;
    for (int i=0;i<=200000;++i) inv[i]=qpow(fact[i],M-2);
}
int main(){
    long long n,k;
    init();
    cin>>n>>k;
    k=min(k,n-1);
    long long ans=0;
    for (int i=0;i<=k;++i){
        ans=(ans+C(i,n)*C(n-i-1,n-1)%M)%M;
    }
    cout<<ans;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) cin >> a[i];
  int m;
  cin >> m;
  vector<int> b(m);
  for (int i = 0; i < m; i++) cin >> b[i];
  cout << (b > a) << endl;

  return 0;
}


Measured memory_bytes: 3096
#include<bits/stdc++.h>
using namespace std;
int main(){
  
  int N;
  cin >> N;
  vector<string> s(N);
  vector<int> t(N);
  
  for(int i = 0;i < N;++i){
    cin >> s[i] >> t[i];
  }
  
  string X;
  cin >> X;
 
  int num = X.size();
  
  int num2;
  
  int num3 = 0;
  
  int num4;
  
  for(int i = 0;i < N;++i){
    num2 = s[i].size();
    if(num == num2){
      for(int j = 0;j < num;++j){
        if(s[i][j] == X[j]){
          num3++;
        }
      }
      if(num3 == num2){
        num4 = i;
        goto end;
      }
    }
    num3 = 0;
  }
  
  end:
  
  int num5 = 0;
  
  int num6 = num4;
  
  
  for(int i = num6 + 1;i < N;++i){
    num5 = t[i] + num5;
  }
  
  cout << num5 << endl;
      
}
  

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
 
#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=(int)(a)-1;i>=(int)(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)
 
#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
 
// #define DEBUG
 
#ifdef DEBUG
    #define dump(...) fprintf(stderr, __VA_ARGS__)
#else
    #define dump(...)
#endif
 
template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}
 
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
 
const double EPS = 1e-10;
const double PI = acos(-1.0);
const ll inf =1LL << 62;
const ll mod=1000000007LL;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
 
 
ll extgcd(ll a,ll b,ll& x,ll& y){x=1,y=0;ll g=a;if(b!=0) g=extgcd(b,a%b,y,x),y-=a/b*x;return g;}
ll ADD(const ll &a, const ll &b,const ll &mod) { return (a+b)%mod;}
ll SUB(const ll &a, const ll &b,const ll &mod) { return (a-b+mod)%mod;}
ll MUL(const ll &a, const ll &b,const ll &mod) { return (1LL*a*b)%mod;}
ll DIV(const ll &a, const ll &b,const ll &mod) {ll x,y; extgcd(b,mod,x,y);return MUL(a,(x+mod)%mod,mod);}
 
random_device rd;
mt19937 mt(rd());
uniform_int_distribution<int> dice(1,6);
uniform_real_distribution<double> score(0.0,10.0);

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

    int n; cin >> n;
    vll a(n); for(auto& e : a) cin >> e, e--;

    vi nidx(n + 1, n);
    vi v2i(n);
    rep(i, n) v2i[a[i]] = i;

    set<int> s = {n};
    rep(v, n){
        int idx = v2i[v];
        nidx[idx] = *s.upper_bound(idx);
        s.insert(idx);
    }

    vll memo(n + 1);
    ll res = 0;
    rrep(i, n){
        int ni = nidx[i];
        memo[i] = memo[ni] + (ni - i) * (a[i] + 1);
        res += memo[i];
    }

    cout << res << endl;

    return 0;
}


Measured memory_bytes: 14592
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    using P = array<int, 6>;
    vector<P> ps{{0,1,2,3,4,5},{0,2,4,1,3,5},{0,3,1,4,2,5},{0,4,3,2,1,5},{1,0,3,2,5,4},{1,2,0,5,3,4},{1,3,5,0,2,4},{1,5,2,3,0,4},{2,0,1,4,5,3},{2,1,5,0,4,3},{2,4,0,5,1,3},{2,5,4,1,0,3},{3,0,4,1,5,2},{3,1,0,5,4,2},{3,4,5,0,1,2},{3,5,1,4,0,2},{4,0,2,3,5,1},{4,2,5,0,3,1},{4,3,0,5,2,1},{4,5,3,2,0,1},{5,1,3,2,4,0},{5,2,1,4,3,0},{5,3,4,1,2,0},{5,4,2,3,1,0}};
    vector<string> v(8);
    while(cin >> v[0], v[0] != "0") {
        for (int i = 1; i < 8; ++i) cin >> v[i];
        vector<vector<string>> vv(8);
        array<char, 256> p;
        for (int i = 'a'; i <= 'z'; ++i) {
            p[i] = i-'a'+'A';
            p[i-'a'+'A'] = i;
        }
        for (int i = 0; i < 8; ++i) {
            for (int j = 0; j < ps.size(); ++j) {
                string a(6, ' ');
                for (int k = 0; k < 6; ++k) {
                    a[k] = v[i][ps[j][k]];
                }
                vv[i].emplace_back(a);
            }
        }
        vector<string> ans;
        vector<int> selected(8, 0);

        auto f = [&](int cur, auto &&f) -> bool {
            if (cur == 8) return true;
            for (int i = 0; i < 8; ++i) {
                if (!selected[i]){
                    selected[i] = 1;
                    for (int j = 0; j < ps.size(); ++j) {
                        int ok = 1;
                        if(cur&1){
                            if(p[ans[cur^1][1]] != vv[i][j][4]) ok = 0;
                        }
                        if(cur & 2){
                            if(p[ans[cur^2][3]] != vv[i][j][2]) ok = 0;
                        }
                        if(cur & 4){
                            if(p[ans[cur^4][0]] != vv[i][j][5]) ok = 0;
                        }
                        if(ok){
                            ans.emplace_back(vv[i][j]);
                            if(f(cur+1, f)) return true;
                            ans.pop_back();
                        }
                    }
                    selected[i] = 0;
                }
            }
            return false;
        };
        puts(f(0, f) ? "YES" : "NO");
    }
    return 0;

}


Measured memory_bytes: 3228
program main
  implicit none
  integer(8) :: n, i, streak, res
  integer(8), allocatable :: h(:)
  read (*, *) n
  allocate (h(n))
  read (*, *) h(:)
  res = 0
  streak = 0
  do i = 1, n - 1
    if (h(i + 1) <= h(i)) then
      streak = streak + 1
      res = max(res, streak)
    else
      streak = 0
    end if
  end do
  write (*, "(i0)") res
end program main


Measured memory_bytes: 1536
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
 
using namespace __gnu_pbds;
using namespace std;
 
typedef   long long int ll;
typedef unsigned long long int sll;
typedef  double ld;
#define A 1000000007ll
#define B 998244353ll
#define C 1000000000000000000ll
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define oset tree<pair<ll,ll>, null_type,less<pair<ll,ll>>, rb_tree_tag,tree_order_statistics_node_update> 
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define mxe(v) *max_element(v.begin(),v.end())
#define mne(v) *min_element(v.begin(),v.end())
#define bs binary_search
#define lb lower_bound
#define ub upper_bound
#define ve vector
#define br break
#define PI 3.14159265358979323

ll power(ll x, ll y, ll p) 
{ 
    ll res = 1;
    x = x % p; 
    while (y > 0) 
    { 
        if (y & 1) 
            res = (res*x) % p; 
        y = y>>1; 
        x = (x*x) % p; 
    } 
    return res; 
} 

ll inv(ll n, ll p) 
{ 
    return power(n, p-2, p); 
} 
ll fac[300000];
ll ncr(ll n, ll r, ll p) 
{ 
    if (r==0)
    	return 1; 
    return (fac[n]* inv(fac[r], p) % p * inv(fac[n-r], p) % p) % p; 
} 

int main() 
{
    FAST;
    fac[0] = 1; 
    for (int i=1 ; i<300000; i++) 
        fac[i] = (fac[i-1]*i)%B; 
    ll n,m,k;
    cin>>n>>m>>k;
    ll ans = 0;
    for(int i=1;i<=k+1;i++)
    {
    	ll x = power(m-1,n-i,B);
    	x = (x*m)%B;
    	x = (x*ncr(n-1,i-1,B))%B;
    	ans = (ans+x)%B;
    }
    cout<<ans;
    //cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
    return 0;
}

Measured memory_bytes: 5916
#include <cstdio>
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <ctime>
#include <cstring>
#include <cassert>
#include <bitset>
#include <sstream>
#include <queue>

#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define sz(a) ((int) (a).size())
#define eprintf(...) fprintf(stderr, __VA_ARGS__)

using namespace std;

typedef long long int64;
typedef long double ldb;

const long double eps = 1e-9;
const int inf = (1 << 30) - 1;
const long long inf64 = ((long long)1 << 62) - 1;
const long double pi = acos(-1);

template <class T> T sqr (T x) {return x * x;}
template <class T> T abs (T x) {return x < 0 ? -x : x;}

int main () {
	ios_base::sync_with_stdio(0);
//	freopen("input.txt", "rt", stdin);
//	freopen("output.txt", "wt", stdout);

	string s;
	cin >> s;

	int n = sz(s);
	vector<int> num(26, 0);

	long long res = 1;
    for (int i = 0; i < n; ++i) {
    	res += i - num[s[i] - 'a'];
    	++num[s[i] - 'a'];
    }

    cout << res << endl;

	return 0;
}


Measured memory_bytes: 720
#include <iostream>

using namespace std;

int main() {
    int in;
    int h,m,s;
    cin>>in;
    s=in%60;
    in-=s;
    m=in%3600;
    in-=m;
    m/=60;
    h=in/3600;
    cout<<h<<':'<<m<<':'<<s<<endl;
}


Measured memory_bytes: 3120
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <bitset>
#include <map>
#include <tuple>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <numeric>
#include <utility>
#include <iterator>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <ctime>
#include <cassert>
#include <random>
#include <cstring>

#define rep(i,n) for(int i=0;i<int(n);i++)
#define all(x) (x).begin(),x.end()
#define pb push_back

using namespace std;
using ll = long long;

const ll mod = 1000000007;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int ddx[8]={-1,-1,0,1,1,1,0,-1};
int ddy[8]={0,1,1,1,0,-1,-1,-1};
bool debug=false;

/*---------------------------------------------------*/

int main(){
  int h, w, a, b;
  cin >> h >> w >> a >> b;
  cout << (h * w) - ((h / a) * a) * ((w / b) * b) << endl;
  return 0;
}


Measured memory_bytes: 3136
N,x = map(int,input().split())
if x in [1,2*N-1]:
  print('No')
else:
  print('Yes')
  if N >= x:
    [print(2*N-1-i) for i in range(N-x)]
    [print(i+1) for i in range(2*N-1-(N-x))]
  else:
    [print(i+1+(x-N)) for i in range(2*N-1-(x-N))]
    [print(i+1) for i in range(x-N)]
    

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

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

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

template<class like_bool> inline void YES(like_bool condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
template<class like_bool> inline void Yes(like_bool condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class like_bool> inline void POSS(like_bool condition){ if(condition) cout << "POSSIBLE" << endl; else cout << "IMPOSSIBLE" << endl; }
template<class like_bool> inline void Poss(like_bool condition){ if(condition)cout << "Possible" << endl; else cout << "Impossible" << endl; }
template<class like_bool> inline void First(like_bool condition){ if(condition)cout << "First" << endl; else cout << "Second" << endl; }
int character_count(string text, char character){ int ans = 0; for(int i = 0; i < text.size(); i++){ ans += (text[i] == character); } return ans; }
long power(long base, long exponent, long module){ if(exponent % 2){ return power(base, exponent - 1, module) * base % module; }else if(exponent){ long root_ans = power(base, exponent / 2, module); return root_ans * root_ans % module; }else{ return 1; }}
struct position{ int y, x; }; position move_pattern[4] = {{-1, 0}, {0, 1}, {1, 0}, {0, -1}};
template<class itr> void array_output(itr start, itr goal){ string ans; for(auto i = start; i != goal; i++){ ans += to_string(*i) + " "; } ans.pop_back(); cout << ans << endl; }
long gcd(long a, long b){ if(a && b){ return gcd(min(a, b), max(a, b) % min(a, b)); }else{ return a; }}
#define mod long(1e9 + 7)
#define all(x) (x).begin(), (x).end()
#define bitcount(n) __builtin_popcount(n)


int H, N;
vector<int> space;

int dp[10010][15];

int put(int now, int back){
    if(now == H - 1){
        return 0;
    }else if(dp[now][back] != -1){
        return dp[now][back];
    }
    int ans = put(now + 1, space[now + 1]);
    if(!(back & 3) && !(space[now + 1] & 3)){ // ooxx
        ans = max(ans, put(now + 1, space[now + 1] | 3) + 1);
    }
    if(!(back & 6) && !(space[now + 1] & 6)){ // xoox
        ans = max(ans, put(now + 1, space[now + 1] | 6) + 1);
    }
    if(!(back & 12) && !(space[now + 1] & 12)){ // xxoo
        ans = max(ans, put(now + 1, space[now + 1] | 12) + 1);
    }
    if(!(back & 15) && !(space[now + 1] & 15)){ // oooo
        ans = max(ans, put(now + 1, space[now + 1] | 15) + 2);
    }
    return dp[now][back] = ans;
}

int main(){
    cin >> H >> N;
    space.resize(H, 0);
    for(int i = 0; i < N; i++){
        int x, y;
        cin >> x >> y;
        space[y] |= (1 << x);
    }
    for(int i = 0; i < 10010; i++){
        for(int j = 0; j < 15; j++){
            dp[i][j] = -1;
        }
    }
    cout << put(0, space[0]) << endl;
}




Measured memory_bytes: 4200