akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <stdlib.h>


int main()
{
    int a,c,k,b;
    while(~scanf("%d",&a))
    {
        c=0,k=0;
        if(a<3)
          printf("0\n");
        else
        {
            b=a;
            while(a--)
           {
             b--;
             c++;
            if(c==3)
            {
              k++;c=0;
            }
          }
            printf("%d\n",k);
        }

    }

}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <vector>
#include <numeric>
#define PI 3.14159265358979323846
#define MAXINF (1e18L)
#define INF (1e9L)
#define EPS (1e-9)
#define MOD ((ll)(1e9+7))
#define REP(i, n) for(int i=0;i<int(n);++i)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define ALL(v) v.begin(),v.end()
#define FIND(v,x) (binary_search(ALL(v),(x)))
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v));reverse(ALL(v))
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define YES(n) cout<<((n)?"YES":"NO")<<endl
#define pb push_back
#define fi first
#define se second
using namespace std;
template<class A>void pr(A a){cout << (a) << endl;}
template<class A,class B>void pr(A a,B b){cout << a << " "  ;pr(b);}
template<class A,class B,class C>void pr(A a,B b,C c){cout << a << " " ;pr(b,c);}
template<class A,class B,class C,class D>void pr(A a,B b,C c,D d){cout << a << " " ;pr(b,c,d);}
template<class T> inline bool chmin(T& a, T b){return a>b ? a=b, true : false;}
template<class T> inline bool chmax(T& a, T b){return a<b ? a=b, true : false;}
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;

int main(void)
{
    int N;
    cin >> N;
    map<int, int> m;
    REP(i, N){
        int a;
        cin >> a;
        m[a/400]++;
    }
    int ans = 0;
    REP(i, 8){
        if(m[i]>0)ans++;
    }
    int over = 0;
    Rep(i, 8, 20){
        over += m[i];
    }
    pr((ans>0?ans:1), ans + over);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define pa pair<int,int>
#define F first
#define S second
#define Max 9999
#define d n%3
typedef long long ll;

int main()
{
    int n,m;
    cin>>n>>m;
    int a[n][m];
    int count=0;
    rep(i,n)
    rep(j,m)
    cin>>a[i][j];
    rep(i,n)
    for(int j=i+1; j<n; j++)
    {
        int sum=0;
        rep(k,m)
        sum+=pow((a[i][k]-a[j][k]),2);
        for(int k=1; k*k<=sum; k++)
            if(k*k==sum)
                count++;
    }
    cout<<count<<endl;
    return 0;
}


Measured memory_bytes: 256
from sys import stdin
lines = stdin.readlines()

N = int(lines[0])
S = lines[1]

if N%2 == 0 :
  N2 = int(N / 2)
  N3 = int(N / 2 + 1)
  T1 = S[0:N2]
  T2 = S[N2:N]
  if T1 == T2 :
    print("Yes")
  else:
    print("No")
else:
  print("No")

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

#define for_(i,a,b) for(int i=a;i<b;++i)
#define ALL(a) a.begin(),a.end()
#define INIT(a,b) memset(a,b,sizeof(a))
using lint = long long int;

int main() {
    lint N;
    cin >> N;

    int M = sqrt(N) + 1;
    vector<bool> is_prime(M+1, true);
    for_(i,2,M+1) {
        if (!is_prime[i]) continue;
        for (int j=2*i; j<=M; j+=i) is_prime[j] = false;
    }

    vector<int> prime;
    for_(i,2,M+1) if (is_prime[i]) prime.push_back(i);

    int i = 0, m = prime.size(), ans = 0;
    while (i < m) {
        int p = prime[i], cnt = 0;
        while (N % p == 0) {
            ++cnt;
            N /= p;
        }
        int d = 1;
        while (cnt >= d) {
            ++ans;
            cnt -= d;
            ++d;
        }
        ++i;
    }

    if (N > 1) ++ans;
    cout << ans << endl;
}

Measured memory_bytes: 4052
#include<iostream>
#include<vector>
#include<queue>
#include<algorithm>
#include<stack>
using namespace std;
int T;
main()
{
	cin>>T;
	for(;T--;)
	{
		vector<int>dcnt(111,-1);
		vector<int>prev(111,-1);
		int now=0,sz=0,counter=0;
		vector<vector<int> >G(111);
		stack<int>dfs;
		dfs.push(0);
		int in;
		while(cin>>in,in)
		{
			while(dcnt[now]==0)
			{
				dfs.pop();
				now=dfs.top();
				counter--;
			}
			if(in>0)
			{
				sz++;
				if(now>0)
				{
					G[now].push_back(sz);
					G[sz].push_back(now);
					dcnt[now]--;
					in--;
				}
				now=sz;
				counter++;
				dcnt[now]=in;
				prev[counter]=now;
				dfs.push(now);
			}
			else
			{
				int id=prev[counter+in];
				G[id].push_back(now);
				G[now].push_back(id);
				dcnt[id]--;
				dcnt[now]--;
			}
		}
		for(int i=1;i<=sz;i++)
		{
			sort(G[i].begin(),G[i].end());
			cout<<i;
			for(int v:G[i])cout<<" "<<v;
			cout<<endl;
		}
	}
}



Measured memory_bytes: 3172
/******************************************************************************

Welcome to GDB Online.
GDB online is an online compiler and debugger tool for C, C++, Python, PHP, Ruby, 
C#, VB, Perl, Swift, Prolog, Javascript, Pascal, HTML, CSS, JS
Code, Compile, Run and Debug online from anywhere in world.

*******************************************************************************/
#include <stdio.h>
#include <iostream>

#define N 100

void insertionSort(int a[], int n)
{
    for(int i=1,j=0; i<n; i++)
    {   
        int v;
        v=a[i];
        j=i-1;
        while(j>=0 && a[j]>v)
        {
                a[j+1]=a[j];
                j--;
        }
        a[j+1]=v;
        for(int k=0; k<n; k++)
        {    
            std::cout<<a[k];
            if(k<n-1)
                std::cout<<' ';
        }
        std::cout<<std::endl;
        
    }
}

int main()
{
    int n, a[N], i=0;
    std::cin>>n;
    while(i<n)
    {
        std::cin>>a[i];
        i++;
    }
    
    for(int k=0; k<n; k++)
    {        
        std::cout<<a[k];
        if(k<n-1)
                std::cout<<' ';
    }
    std::cout<<std::endl;
   
   insertionSort(a, n);
    

    return 0;
}



Measured memory_bytes: 3092
// 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())
#define debug(x) cerr << #x << ": " << x << endl
#define debugP(p) cerr << #p << ": {" << p.first << ", " << p.second << '}' << endl
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const ll INF = 1e9, MOD = 1e9 + 7;
 
/////////////////////////////////////////////////////////////////////
 
const int N = 1e5 + 5;

bool Prime(int n) {
	for (int i = 2; i * i <= n; i++) if (n % i == 0) return false;
	return true;
}

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

	int n; cin >> n;
	int ans = 1;
	for (int i = 2; i <= n; i++) {
		if (!Prime(i)) continue;
		int tmp = n, cnt = 0;
		while(tmp) cnt += tmp / i, tmp /= i;
		ans = 1LL * ans * (cnt + 1) % MOD;
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
const ld eps = 1e-9;

//// < "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\a.txt" > "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\b.txt"


int main() {
	while (1) {
		int H, C, W, space;
		cin >> H; if (!H)break;
		cin >>  C >> W >> space;
		vector<vector<vector<string>>>anss;
		const vector<vector<string>>plane(H, vector<string>(C));
		vector<vector<string>>page(plane);
		int ny = 0, nx = 0;
		string dummy;
		getline(cin, dummy);
		while (1) {
			string st; 
			getline(cin, st);
			if (st == "?")break;
			else {
				if (st.empty())st = ".";
				for (int i = 0; i < (int(st.size())-1) / W+1; ++i) {
					
					page[ny][nx] = st.substr(i*W, W);
					ny++;
					if (ny == H) {
						ny = 0;
						nx++;
						if (nx == C) {
							anss.emplace_back(page);
							page = plane;
							nx = 0;
						}
					}
				}
			}
		}
		if (nx!=0||ny!=0) {

			anss.emplace_back(page);
		}
		for (int i = 0; i < anss.size(); ++ i) {
			auto page(anss[i]);
			for (int y = 0; y < H; ++y) {
				for (int x = 0; x < C; ++x) {
					string st = page[y][x];
					cout << st;
					for (int n = st.size(); n < W; ++n) {
						cout << '.';
					}
					if (x != C - 1) {
						for (int n = 0; n < space; ++n) {
							cout << '.';
						}
					}
				}
				cout << endl;
			}
			cout << '#' << endl;
		}
		cout << '?' << endl;
	}
	return 0;
}

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

int main(){
    int r, g, b, i;
    cin >> r >> g >> b;
    i = r * 100 + g * 10 + b;
    if (i % 4 == 0) {
        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 < 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 ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long double ld;
int main()
{
  int x,y;
  cin >> x >> y;

  cout << x + y/2 << endl;
  return 0;
}


Measured memory_bytes: 256
import sys

n,x = map(int,input().split())
a = list(map(int,input().split()))
a.sort()

c = 0
p = x

for i in range(n-1):
    if a[i] > p:
        print(c)
        sys.exit()
    else:
        c += 1
        p -= a[i]

if a[-1] == p:
    print(n)
else:
    print(n-1)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define INFTY 10000000000
typedef long long int ll;
const int MOD=1000000007;
using Graph = vector<vector<int>>;
using ipair = pair<ll,ll>;
bool operator< (const ipair a, const ipair b){return a.first < b.first;};
#define rep(i,n) for (ll i = 0; i < (n); ++i)
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}


int main(){
    int n;cin>>n;
    vector<ll> l(n);
    rep(i,n)cin>>l[i];
    int ans = 0;
    rep(i,n-2){
        for (int j = i+1; j < n-1; j++)
        {
           for (int k = j+1; k < n; k++)
           {
               if(l[i]!=l[j]&&l[i]!=l[k]&&l[k]!=l[j]){
                   if(l[i]+l[j]>l[k]&&l[i]+l[k]>l[j]&&l[k]+l[j]>l[i]){
                       ans++;
                   }
               }
           }       
        }      
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3636
import java.util.*;


public class Main {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
      String a[]=sc.nextLine().split("",0);
      String b[]=sc.nextLine().split("",0);
      System.out.println((a[0].equals(b[2])&&a[1].equals(b[1])&&a[2].equals(b[0]))?"YES":"NO");
    }
}


Measured memory_bytes: 21844
import scala.io.StdIn._
object Main extends App {
  val Array(hh, ww) = readLine.split(" ").map(_.toInt)

  def divHolizontal(h: Int, w: Int): Int = if (h % 3 == 0) 0 else w

  def divT(h: Int, w: Int): Int = {
    def largeSide = (w + 1) / 2

    def minTopDiff: Int = {
      val top = h / 3
      val bottom = h - top
      largeSide * bottom - Math.min(w * top, (w - largeSide) * bottom)
    }

    def maxTopDiff: Int = {
      val top = (h + 2) / 3
      val bottom = h - top
      Math.max(w * top, largeSide * bottom) - (w - largeSide) * bottom
    }

    Math.min(minTopDiff, maxTopDiff)
  }
  println(divHolizontal(hh, ww)
     .min(divHolizontal(ww, hh))
     .min(divT(hh, ww))
     .min(divT(ww, hh)))
}

Measured memory_bytes: 25416
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class Program
{
    static void Main(string[] args)
    {
            // 入力
            string sS = Console.ReadLine().Trim();
            int iN = int.Parse(sS);
            sS = Console.ReadLine().Trim();
            int iA = int.Parse(sS);

            System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
            sw.Start();

            // 解析
            // 出力
            Console.WriteLine("{0}", (iN * iN - iA).ToString().Trim());

            sw.Stop();
#if DEBUG
            Console.WriteLine();
            Console.WriteLine("{0}", sw.Elapsed.ToString());
            Console.WriteLine("続行するには何かキーを押してください．．．");
            Console.ReadKey();
#endif
    }
}


Measured memory_bytes: 13268
import sys
P = 0
N,M = map(int,input().strip().split())
if M == 0:
    print("{0} {1}".format(0,0))
    sys.exit()
ans_list = [list(input().strip().split()) for _ in range(M)]
result = [False] * N
wa_count = [0] * N
for ans in ans_list:
    if result[int(ans[0])-1] != True:
        if ans[1] == "WA":
            wa_count[int(ans[0])-1] += 1
        elif ans[1] == "AC":
            result[int(ans[0])-1] = True
for i in range(len(result)):
    if result[i] == True:
        P += wa_count[i]
print("{0} {1}".format(result.count(True),P))

Measured memory_bytes: 27448
#include<stdio.h>
int main(){
int a,b,c,d=0;
while(d==0){
scanf("%d %d %d \n",&a,&b,&c);
if(a==-1 && b==-1 && c==-1){
break;
}
else{
if(a==-1 || b==-1){
printf("F\n");
}
else if(a+b>=80){
printf("A\n");
}
else if(a+b>=65 && a+b<80){
printf("B\n");
}
else if(a+b>=50 && a+b<65){
printf("C\n");
}
else if(a+b>=30 && a+b<50){
if(c>=50){
printf("C\n");
}
else{
printf("D\n");
}
}
else{
printf("F\n");
}
}
}
return 0;
}



Measured memory_bytes: 2080
package main

import "fmt"

func main() {
	var a, b int
	fmt.Scanf("%d %d", &a, &b)

	for i := 1; i <= 100*100*100; i++ {
		if (i*8/100 == a) && (i*10/100 == b) {
			fmt.Println(i)
			return
		}
	}

	fmt.Println(-1)
}


Measured memory_bytes: 512
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<utility>
using namespace std;
typedef pair<string, string> Ps;

int main() {
	int m;
	cin >> m;
	for (int x = 0; x < m; x++) {
		vector<Ps>v;
		string s;
		cin >> s;
		for (int i = 1; i < s.size(); i++) {
			string a, b;
			a = s.substr(0, i);
			b = s.substr(i);
			string ra = a;
			reverse(ra.begin(), ra.end());
			string rb = b;
			reverse(rb.begin(), rb.end());
			v.push_back(Ps(a, b));
			v.push_back(Ps(b, a));
			v.push_back(Ps(ra, b));
			v.push_back(Ps(b, ra));
			v.push_back(Ps(a, rb));
			v.push_back(Ps(rb, a));
			v.push_back(Ps(ra, rb));
			v.push_back(Ps(rb, ra));
		}
		sort(v.begin(), v.end());
		v.erase(unique(v.begin(), v.end()), v.end());
		vector<string>va;
		for (int i = 0; i < v.size(); i++) {
			string sa = v[i].first;
			sa += v[i].second;
			va.push_back(sa);
		}
		sort(va.begin(), va.end());
		va.erase(unique(va.begin(), va.end()), va.end());
		cout << va.size() << endl;
		}
	return 0;
}

Measured memory_bytes: 3288
/*   ꧁༒☬महाकाल☬༒꧂ ꧁༒ঔमहाकालঔ༒꧂
                   
                   ঔৣ۝महाकालᴳᵒᵈ۝ঔৣ            
 
 */ 
#include<bits/stdc++.h>
using namespace std;
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//template <typename T, typename cmp=less<T>> using oset =tree<T, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
#define ll long long 
#define mod 1000000007
#define MOD 998244353
#define inf 100000000000000000
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define _it iterator
#define all(_x) _x.begin(),_x.end()
#define f first
#define s second
#define pb push_back
#define ar array
#define ld long double
void mahakal(){
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	freopen("error.txt","w",stderr);
	#endif
}
ll dx[4]={1,0,-1,0};
ll dy[4]={0,1,0,-1};
char c[4]={'D' , 'R' , 'U' , 'L'};
const ll maxN=2e5+5 , N=3e2+1;;
ll  cnt[4] , x , n;
ld dp[301][301][301] ;
void solve(){
	cin>> n ;
	for(ll i=0;i<n ;i++){
		cin>> x ; cnt[x]++;
	}
	dp[0][0][0]=0;
	for(ll three=0 ; three<=n ; three++){
		for(ll two=0 ; two<=n ; two++){
			for(ll one=0 ; one<=n ; one++){
				ll zero=(n-one-two-three);
				if(zero==n || (one+two+three)>n)continue;
				ld value=1;
				// Pick three
				if(three>0)value+=(1.0*three/n)*dp[three-1][two+1][one];
				if(two>0)value+=(1.0*two/n)*dp[three][two-1][one+1];
				if(one>0)value+=(1.0*one/n)*dp[three][two][one-1];
				dp[three][two][one]=(value)/(1-1.0*zero/n);
			}
		}
	}
	ld ans=dp[cnt[3]][cnt[2]][cnt[1]];
	cout<<fixed<<setprecision(10);
	cout<<ans<<endl;
}

int main(){
	//mahakal();
	fast;
	ll t =1 ;
	//cin>> t ; 
	while(t--)solve();
	//cerr << "\ntime taken : " << (float)clock() / CLOCKS_PER_SEC << " secs" << endl; 
	return 0;
}

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

using namespace std;
const int MOD = 1e9 + 7;

void act(int& a, int b) {
    a += b;
    if (a >= MOD)
        a -= MOD;
}

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

    string s; cin >> s;
    vector<int> ones(n), zero(n);
    for (int i = 0; i < n; ++i) {
        if (s[i] == '1') ones[i] = 1;
        else zero[i] = 1;
        if (i > 0) {
            ones[i] += ones[i - 1];
            zero[i] += zero[i - 1];
        }
    }

    vector<int> best(n);
    for (int i = 0; i < n; ++i)
        best[i] = i;

    for (int i = 0; i < m; ++i) {
        int l, r; cin >> l >> r; --l; --r;
        best[l] = max(best[l], r);
    }
    for (int i = 0; i + 1 < n; ++i) {
        best[i + 1] = max(best[i + 1], best[i]);
    }
    vector<vector<int>> dp(n + 1, vector<int>(n + 1, 0));
    dp[0][0] = 1;
    for (int i = 0; i <= n; ++i) {
        for (int j = 0; i + j <= n; ++j) {
            int at = i + j;
            bool can_zero = zero[best[at]] > i;
            bool can_ones = ones[best[at]] > j;
            if (can_zero) act(dp[i + 1][j], dp[i][j]);
            if (can_ones) act(dp[i][j + 1], dp[i][j]);
        }
    }
    
    int ans = 0;
    for (int i = 0, j = n; i <= n; ++i, --j)
        act(ans, dp[i][j]);
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 35584
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <cmath>

#define rep(x,to) for(int x=0;x<to;x++)
#define rep2(x,from,to) for(x=from;x<to;x++)

using namespace std;


int main(void){

double v,wn;
int n;

	while(cin >> v ){
		double h = 4.9 * (v / 9.8) * (v / 9.8);
		wn = (( h + 5 ) / 5);
		n = (int)wn;
		n = n + (wn==n? 0: 1);
		cout << n << endl;
	}
	
	return 0;
}

Measured memory_bytes: 1224
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
ll A,B,C,D,E,F,x,y,a,b,ans1,ans2=10000000;
int main(){
//	freopen("a.in","r",stdin);
	scanf("%lld%lld%lld%lld%lld%lld",&A,&B,&C,&D,&E,&F);
	for(x=0;x<=30ll;++x){
		for(y=0;y<=30ll;++y){
			for(a=0;a<=3000ll;++a){
				if((x*A+y*B)*100ll+a*C<=F && E*(x*A+y*B)>=a*C){
					b=min((E*(x*A+y*B)-a*C)/D,(F-((x*A+y*B)*100ll+a*C))/D);
					if((a*C+b*D)*ans2>=ans1*((x*A+y*B)*100ll+a*C+b*D)){
						ans1=a*C+b*D;
						ans2=(x*A+y*B)*100ll+a*C+b*D;
					}
				}
			}
		}
	}
	printf("%lld %lld\n",ans2,ans1);
	return 0;
}

Measured memory_bytes: 128
N = int(input())
H = list(map(int, input().split()))

count = min(H)
H = [h - count for h in H]
while any(0 < h for h in H):
    l = 0
    while H[l] == 0:
        l += 1
    r = l + 1
    while r < N and 0 < H[r]:
        r += 1

    count += 1
    H = [H[i] - (1 if l <= i < r else 0) for i in range(N)]
print(count)

Measured memory_bytes: 3064
#include<iostream>
#include<vector>
#include<string>
using namespace std;
int main() {
  string s;
  int K;
  cin >> s >> K;
  int n = s.size();
  vector<int> a;
  for (auto c : s) a.push_back(c - '0');

  vector<vector<vector<int>>> dp(n + 1, vector<vector<int>> (K + 1, vector<int> (2)));
  dp[0][0][1] = 1;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j <= K; j++) {
      for (int k = 0; k < 2; k++) {
        for (int d = 0; d < 10; d++) {
          int ni = i + 1;
          int nj = j + !!d;
          int nk = (k && d >= a[i]);
          if (nj > K) continue;
          if (k && d > a[i]) continue;
          dp[ni][nj][nk] += dp[i][j][k];
        }
      }
    }
  }
  cout << dp[n][K][0] + dp[n][K][1] << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<stdint.h>
#include<inttypes.h>

typedef int32_t i32;
typedef int64_t i64;

static i64 read_int(void){int prev='\0';int c=getchar();while(!('0'<=c && c<='9')){prev=c;c=getchar();}i64 res=0;while('0'<=c && c<='9'){res=10*res+c-'0';c=getchar();}return prev=='-'?-res:res;}

typedef struct count_val {
  i32 cnt;
  i32 val;
} node;

void run (void) {
  i32 n = read_int();
  node *p = (node *) calloc (n, sizeof (node));
  i64 sum = 0;
  i64 ans = 0;
  i32 len = 0;
  for (i32 i = 0; i < n; ++i) {
    node t = {1, read_int()};
    while (len > 0 && p[len - 1].val > t.val) {
      t.cnt += p[--len].cnt;
      sum -= (i64) p[len].cnt * p[len].val;
    }
    p[len++] = t;
    sum += (i64) t.cnt * t.val;
    ans += sum;
  }
  printf ("%" PRIi64 "\n", ans);
}

int main (void) {
  run();
  return 0;
}


Measured memory_bytes: 1664
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

int main() {
	int n, m;

	cin >> n >> m;

	vector<int> h(n);

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

	int a, b;
	
	vector<int> ans(n);

	for (int j = 0; j < m; j++) {
		cin >> a >> b;
		a--;
		b--;

		ans[a] = max(ans[a], h[b]);
		ans[b] = max(ans[b], h[a]);
	}

	int x = 0;

	for (int i = 0; i < n; i++) {
		if (h[i] > ans[i]) x++;
	}

	cout << x << endl;


	return 0;
}

Measured memory_bytes: 4044
f=range
h,w,k=map(int,input().split())
g=[[int(i) for i in input()] for _ in f(h)]
s=[[0]*-~w for _ in f(h+1)]
for i in f(h):
  for j in f(w):
    s[i+1][j+1]=s[i+1][j]+s[i][j+1]+g[i][j]-s[i][j]
a=h+w
for i in f(2**~-h):
  u=d=l=r=c=0
  e=[]
  for d in f(h):
    if i>>d&1: e+=[(u,d+1)]; c+=1; u=d+1
  e+=[(u,h)]
  for r in f(w):
    if max(s[d][r+1]-s[u][r+1]-s[d][l]+s[u][l] for u,d in e)>k:
      if r==l: break
      c+=1; l=r
  else: a=min(a,c)
print(a)

Measured memory_bytes: 43868
#include <stdio.h>

int main(int argc, const char * argv[]) {
    
    int a = 0;
    int b = 0;
    
    scanf("%d %d",&a,&b);
    
    if (a + b == 15) {
        printf("+");
    }else if(a * b == 15){
        printf("*");
    }else{
        printf("x");
    }
    
    return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
template<class T> istream& operator >> (istream& s, vector<T>& v)
{ for (T& x: v) { s >> x; } return s;}
void yes(){ cout << "Yes" << endl; }
void no(){ cout << "No" << endl; }
int SIZE(string s){ return (int)s.size(); }

int main(){
    cout << setprecision(16);
    int n; cin >> n;
    int ans = 0;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    rep(i,n-1){
        if(a[i] == i+1){
            ans++;
            swap(a[i],a[i+1]);
        }
    }
    if(a[n-1] == n) ans++;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <cmath>
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <string.h>
#include <stack>
#define Endl endl
#define mp make_pair
#define ll long long 
#define pii pair<int,int>
#define pll pair<ll,ll>
#define over(A) {cout<<A<<endl;exit(0);}
#define all(A) A.begin(),A.end()
#define ceil(a,b) ((a-1)/b+1)
#define srand() mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define rand(l,r) uniform_int_distribution<int>(l,r)(rng)
typedef unsigned long long ull;
const int inf=1039074182;
using namespace std;

int main()
{
//	freopen("input.txt","r",stdin);
	int n,k;
	cin>>n>>k;
	if(k==1) over(0);
	cout<<n-k<<endl;
	return 0;
}

Measured memory_bytes: 764
#include<bits/stdc++.h>
#define endl "\n"
#define FASTIO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define F first
#define S second
typedef long long int ll;
const int INF = 1e9;

using namespace std;

void solve()
{
    ll a;
    string b;
    cin>>a;
    cin>>b;

    string bb = b.substr(0,1) + b.substr(2,4);
    ll ans = a* stoi(bb);

    string s_ans = to_string(ans);
    //cout<<stoi(bb)<<endl;
    if(s_ans.length()<3) s_ans = "000";
    cout<<s_ans.substr(0, s_ans.length()-2)<<endl; 
}
 
int main()
{
    FASTIO
    solve();
    return 0;
}

Measured memory_bytes: 3728
using System;
using System.Collections.Generic;
using System.Text;

namespace ALDS1_9_C {
    class PriorityQueue {
        List<int> _heap;
        int _size;

        public PriorityQueue() {
            _heap = new List<int>();
        }

        public void Enqueue(int num) {
            _heap.Add(num);
            int i = _size++;
            while (i > 0) {
                int j = (i - 1) / 2;
                if (_heap[j] < num)
                    Swap(i, j);
                i = j;
            }
        }

        public int Dequeue() {
            int ret = _heap[0];
            int x = _heap[--_size];
            int i = 0;
            while (i * 2 + 1 < _size) {
                int a = i * 2 + 1;
                int b = i * 2 + 2;
                if (b < _size && _heap[a] < _heap[b])
                    a = b;
                if (_heap[a] < x)
                    break;
                _heap[i] = _heap[a];
                i = a;
            }
            _heap[i] = x;
            _heap.RemoveAt(_size);
            return ret;
        }

        public int Peek() {
            return _heap[0];
        }

        public int Count {
            get {
                return _size;
            }
        }

        private void Swap(int a, int b) {
            int temp = _heap[a];
            _heap[a] = _heap[b];
            _heap[b] = temp;
        }
    }

    class Program {
        static void Main(string[] args) {
            PriorityQueue pq = new PriorityQueue();
            StringBuilder sb = new StringBuilder();
            bool inputEnd = false;
            while (!inputEnd) {
                string[] input = Console.ReadLine().Split(' ');
                switch (input[0]) {
                    case "insert":
                        pq.Enqueue(int.Parse(input[1]));
                        break;
                    case "extract":
                        sb.AppendLine(pq.Dequeue().ToString());
                        break;
                    case "end":
                        inputEnd = true;
                        break;
                }
            }
            Console.Write(sb);
        }
    }
}

Measured memory_bytes: 31272
//by xxj
#include<bits/stdc++.h>
using namespace std;
#define fst first
#define snd second
#define mp make_pair
#define ll long long
#define pii pair<int,int>
#define lowbit(x) x&-x
const int inf=1e9+7;
const double eps=1e-10;
const ll linf=1e18+7;
const ll hh=523;
//const int mod=;
string s;
ll dps[17][127];
ll dpp[2][127][43][29][15][15];
ll ans;
int j2=0,j3=0,j5=0,j7=0;
int n;
int hve[17];
int c[17][17];
vector<int> v[17];
ll nw=1,prod=1;
bool used[10007];
void init2(){
	c[0][0]=1;
	for (int i=1;i<=14;i++){
		c[i][0]=1;
		for (int j=1;j<=i;j++){
			c[i][j]=c[i-1][j-1]+c[i-1][j];
		}
	}
}
ll calc(){
	int t=n;
	ll re=1;
	for (int i=0;i<=9;i++){
		re*=c[t][hve[i]];
		t-=hve[i];
//		cout<<hve[i]<<' ';
	}
//	puts("");
//	cout<<n<<' '<<t<<endl;
	return re;
}
void go(int k,int sum,int h){
	if (k*9<sum){
		return;
	}
	if (k==0){
//		int t=calc();
//		cout<<calc()<<endl;
//		cout<<sum<<' '<<nw<<endl;
		if (nw<prod){
			ans+=calc();
		}
		if (nw==prod){
			for (int i=0;i<=9;i++){
				v[i].push_back(hve[i]);
//				cout<<hve[i]<<' ';
			}
//			puts("");
		}
		return;
	}
	for (int i=h;i<=min(sum,9);i++){
		hve[i]++;
		nw*=(i+1);
		if (nw>prod){
			hve[i]--;
			nw/=(i+1);
			break;
		}
		go(k-1,sum-i,i);
		hve[i]--;
		nw/=(i+1);
	}
}
ll calc2(int k,int cs){
//	puts("in");
	ll re=1;
	int t=n-cs;
//	cout<<t<<endl;
	for (int i=0;i<=9;i++){
//		cout<<v[i][k]<<' ';
		re*=c[t][v[i][k]];
		t-=v[i][k];
//		cout<<v[k][i]<<' ';
	}
//	puts("out");
	return re;
}
int main(){
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
//	init();
//	puts("!!!");
	init2();
	cin>>s;
//	puts("!!");
	dps[0][0]=1;
	for (int i=1;i<=14;i++){
		for (int j=0;j<=9*i;j++){
//			cout<<i<<' '<<j<<endl;
			for (int k=0;k<=min(j,9);k++){
				dps[i][j]+=dps[i-1][j-k];
			}
		}
	}
	int sum=0;
	n=s.size();
	for (int i=0;i<n;i++){
		sum+=(s[i]-'0');
		prod*=(s[i]-'0')+1;
	}
	for (int i=0;i<sum;i++){
		ans+=dps[n][i];
	}
//	cout<<prod<<endl;
//	cout<<ans<<endl;
	go(n,sum,0);
//	cout<<ans<<endl;
	int cnt=v[0].size();
//	cout<<cnt<<endl;
//	for (int j=0;j<=9;j++){
//		cout<<v[j][0]<<' ';
//	}
//	puts("");
	for (int i=0;i<n-1;i++){
//		cout<<i<<endl;
		for (int k=0;k<cnt;k++){
			if (used[k]){
				continue;
			}
//			cout<<k<<endl;
			for (int j=0;j<(s[i]-'0');j++){
//				cout<<j<<endl;
				if (!v[j][k]){
					continue;
				}
//				cout<<j<<endl;
				v[j][k]--;
				ans+=calc2(k,i+1);
//				cout<<ans<<endl;
				v[j][k]++;
			}
			if (v[s[i]-'0'][k]){
				v[s[i]-'0'][k]--;
			}
			else{
				used[k]=true;
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}
/*
input:
2034->641
*/



Measured memory_bytes: 3244
N,M = gets.split.map(&:to_i)
G = Array.new(N + 1){ [] }
E = M.times.map{ gets.split.map(&:to_i) }
E.each do |from,to|
  G[from] << to
end

ACTIVE = Array.new(N + 1)
USED = Array.new(N + 1)
SUBGRAPH = Array.new(N + 1)

def active?(v); ACTIVE[v]; end
def activate!(v);  ACTIVE[v] = true; end
def inactivate!(v); ACTIVE[v] = false; end
def used?(v); USED[v]; end
def unused?(v); !USED[v]; end
def use!(v); USED[v] = true; end
def subgraph_include?(v); SUBGRAPH[v]; end
def subgraph_init!(vset)
  ACTIVE.fill(false)
  USED.fill(true)
  SUBGRAPH.fill(false)
  
  vset.each{|v| USED[v] = false }
  vset.each{|v| SUBGRAPH[v] = true }
end
  
def cycle_exists?
  stack = []
  (1 .. N).each do |s|
    next if used?(s)
    
    use!(s)
    stack << s
    
    until stack.empty?
      u = stack.pop
      next if active?(u).tap{ inactivate!(u) }

      activate!(u)
      stack << u
      
      G[u].each do |v|
        if active?(v)
          cycle = stack.select{|r| active?(r) }.drop_while{|r| r != s}
          return cycle
        elsif unused?(v)
          use!(v)
          stack << v
        end
      end
    end
  end
  return false
end

def smaller_cycle?(cycle)
  subgraph_init!(cycle)
  
  stack = nil
  smaller_not_found = cycle.each_with_index.none? do |from, i|
    to = (i + 1 == cycle.size ? cycle[0] : cycle[i + 1])
    to_ = G[from].find{|to_| subgraph_include?(to_) && to_ != to }
    stack = [from, to_] if to_
  end
  return false if smaller_not_found

  use!(stack[0])
  use!(stack[1])
  activate!(stack[0])

  until stack.empty?
    u = stack.pop
    
    next if active?(u).tap{ inactivate!(u) }
    
    activate!(u)
    stack << u
    
    G[u].each do |v|
      if active?(v)
        cycle_ = stack.select{|r| active?(r) }.drop_while{|r| r != v }
        return cycle_
      elsif unused?(v)
        use!(v)
        stack << v
      end
    end
  end
  
end

cycle = cycle_exists?
if !cycle
  puts -1
else
  loop do
    smaller = smaller_cycle?(cycle)
    if smaller  
      cycle = smaller
    else
      break
    end
  end
  puts cycle.size
  puts cycle
end


Measured memory_bytes: 2172
#include <cstdio>
#include <cstdlib>
#pragma warning(disable:4996)

struct Node {
	int k;
	Node *p, *l, *r;
};

Node *root = NULL;
int m, k;
char com[10];

void insert(int k) {
	Node *x = root;
	Node *y = NULL;
	Node *z = (Node *)malloc(sizeof(Node));
	z->k = k;
	z->l = NULL;
	z->r = NULL;

	while (x != NULL) {
		y = x;
		if (z->k < x->k) {
			x = x->l;
		}
		else {
			x = x->r;
		}
	}

	z->p = y;
	if (y == NULL) {
		root = z;
	}
	else {
		if (z->k < y->k) {
			y->l = z;
		}
		else {
			y->r = z;
		}
	}
}

Node *find(int k) {
	Node *node = root;
	while (node != NULL && node->k != k) {
		if (k < node->k) node = node->l;
		else node = node->r;
	}
	return node;
}

Node *treeMinimum(Node *node) {
	while (node->l != NULL) node = node->l;
	return node;
}

Node *treeSuccessor(Node *x) {
	if (x->r != NULL) return treeMinimum(x->r);
	Node *y = x->p;
	while (y != NULL && x == y->r) {
		x = y;
		y = y->p;
	}
	return y;
}

void deleteNode(Node *z) {
	Node *x;
	Node *y;

	if (z->l == NULL || z->r == NULL) y = z;
	else y = treeSuccessor(z);
	if (y->l != NULL) {
		x = y->l;
	}
	else {
		x = y->r;
	}

	if (x != NULL) {
		x->p = y->p;
	}

	if (y->p == NULL) {
		root = x;
	}
	else {
		if (y == y->p->l) {
			y->p->l = x;
		}
		else {
			y->p->r = x;
		}
	}

	if (y != z) {
		z->k = y->k;
	}

	free(y);
}

void preOrder(Node *node) {
	if (node == NULL) return;
	printf(" %d", node->k);
	preOrder(node->l);
	preOrder(node->r);
}

void inOrder(Node *node) {
	if (node == NULL) return;
	inOrder(node->l);
	printf(" %d", node->k);
	inOrder(node->r);
}

int main() {
	scanf("%d", &m);
	for (int i = 0; i < m; i++) {
		scanf("%s", com);
		if (com[0] == 'i') {
			scanf("%d", &k);
			insert(k);
		}
		else if (com[0] == 'f') {
			scanf("%d", &k);
			if (find(k) != NULL) printf("yes\n");
			else printf("no\n");
		}
		else if (com[0] == 'd') {
			scanf("%d", &k);
			deleteNode(find(k));
		}
		else if (com[0] == 'p') {
			inOrder(root);
			printf("\n");
			preOrder(root);
			printf("\n");
		}
	}
	return 0;
}

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

int main() {
    int N, M, a, b, p, nxt;
    cin >> N >> M;
    queue<int> q, next_pos;
    vector<queue<int> > G(N);
    vector<int> done(N, 0);
    for (int i = 0; i < M; i++) {
        cin >> a >> b;
        G[a-1].emplace(b-1);
        G[b-1].emplace(a-1);
    }

    q.emplace(0);
    done[0] = 1;
    while(!q.empty()) {
        p = q.front();
        q.pop();
        next_pos = G[p];
        while(!next_pos.empty()) {
            nxt = next_pos.front();
            next_pos.pop();
            if (done[nxt] == 0) {
                done[nxt] = p+1;
                q.emplace(nxt);
            }
        }
    }
    cout << "Yes" << endl;
    for (int i = 1; i < N; i++) {
        cout << done[i] << endl;
    }
    return 0;
}


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

const int N = 550000;
const int MOD = 1e9 + 7;

int a[N], sum[N], cnt[N];
vector<int> pos[1 << 21];
int chk[1 << 21];

inline int modExp(int a, int n, int mod) {
	int ret = 1;
	while (n) {
		if (n & 1) ret = (long long)ret * a % mod;
		a = (long long)a * a % mod;
		n >>= 1;
	}
	return ret;
}

int main() {
	
	ios::sync_with_stdio(0);
	cin.tie(0), cout.tie(0);
	
	int n; cin >> n;
	for (int i = 1; i <= n; i++) cin >> a[i], sum[i] = sum[i - 1] ^ a[i], cnt[i] = cnt[i - 1] + (sum[i] == 0);
	for (int i = 1; i <= n; i++) pos[sum[i]].push_back(i);
	if (sum[n] == 0) {
		int ans = 0;
		for (int i = 1; i <= n; i++) if (sum[i] && !chk[sum[i]]) {
			chk[sum[i]] = 1;
			int cnt0 = 1, cntg = 0;
			for (int j = pos[sum[i]].size() - 1; j >= 0; j--) {
				(cntg += cnt0) >= MOD && (cntg -= MOD);
				if (j) (cnt0 += (long long)cntg * (cnt[pos[sum[i]][j]] - cnt[pos[sum[i]][j - 1]]) % MOD) >= MOD && (cnt0 -= MOD);
			}
			(ans += cntg) >= MOD && (ans -= MOD);
		}
		(ans += modExp(2, cnt[n] - 1, MOD)) >= MOD && (ans -= MOD);
		cout << ans << "\n";
		return 0;
	} else {
		int cnt0 = 1, cntg = 0;
		for (int j = 0; j < pos[sum[n]].size(); j++) {
			(cntg += cnt0) >= MOD && (cntg -= MOD);
			if (j + 1 < pos[sum[n]].size()) (cnt0 += (long long)cntg * (cnt[pos[sum[n]][j + 1]] - cnt[pos[sum[n]][j]]) % MOD) >= MOD && (cnt0 -= MOD);
		}
		cout << cnt0 << "\n";
	}
	
	return 0;
}


Measured memory_bytes: 71412
#include <bits/stdc++.h>
using namespace std;
#define F(i,a,b) for(int i=a;i<b;i++)
#define f(i,n) for(int i=0;i<n;i++)
typedef unsigned long long ull;
typedef long long ll;
#define vint vector<int>
#define pb(a) push_back(a);
#define bug(x) cout<<#x<<" = "<<x<<endl;
#define fastio ios_base::sync_with_stdio(false); cin.tie(0);
#define printarr(x,n) cout<<"printing "<<#x<<"\n"; for(int kkk=0;kkk<n;++kkk) cout<<x[kkk]<<" ";  cout<<"\n";

class graph{
	public:
	int vertices;
	// int edge;
	vector<vector<int>> adj;
	graph(int x){
		vertices=x;
		// edge=y;
		adj.resize(vertices);
	}

	void add_edge(int a,int b){
		adj[a].push_back(b);
		adj[b].push_back(a);
	}

	void add_directed_edge(int a,int b){
		adj[a].push_back(b);
	}

	void print_graph(){
		for(int i=0;i<vertices;i++){
			cout<<i<<" --> ";
			for(int j=0;j<adj[i].size();j++){
				cout<<adj[i][j]<<" ";
			}cout<<"\n";
		}
	}

	int dfsRecursive(int i,bool vis[],int dp[]){
		if(vis[i]==true){
			return dp[i];
		}
		vis[i]=true;
		// cout<<i<<" ";
		if(adj[i].size()==0){
			dp[i]=0;
			return 0;
		}
		for(int j=0;j<adj[i].size();++j){
			if(!vis[adj[i][j]]){
				dfsRecursive(adj[i][j],vis,dp);
			}
			dp[i] = max(dp[i],1+dp[adj[i][j]]);
		}
		return dp[i];
	}
};


int longest(int n,graph* g){
	int dp[n+1]={0};
	bool vis[n]={false};
	int ans=0;
	for(int i=0;i<n;i++){
		if(vis[i]==false)
			g->dfsRecursive(i,vis,dp);
			//printarr(dp,n);
	}
	ans=0;
	f(j,n){
		ans=max(ans,dp[j]);
	}
	return ans;
}

int main(){
	fastio;
	int n,m;
	cin>>n>>m;
	graph* g = new graph(n);
	f(i,m){
		int a,b;
		cin>>a>>b;
		g->add_directed_edge(a-1,b-1);
	}
	// g->print_graph();
	cout<<longest(n,g)<<endl;
	return 0;
}

Measured memory_bytes: 7808
#include<bits/stdc++.h>
#define inf 2000000000
#define eb emplace_back
#define pb push_back
#define fi first
#define se second
#define fastio ios::sync_with_stdio(false);cin.tie(NULL)
#define rng_23 mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<pair<int,int>> vii;
typedef set<int> si;
typedef multiset<int> msi;
typedef map<int,int> mii;
int main()
{
    int a,b;
    cin>>a>>b;
    cout<<a*b;
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
#define forr(i, a, b) for(int i = (a); i < (b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = 1; i <= (n); i++)
#define ALL(a) (a.begin()),(a.end())
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll, ll> LP;
const ll LINF = 1LL<<60;
const int INF = 1001001001;

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

int main() {
    int n;
    cin >> n;
    vector<int> c(4, 0);
    rep(i, n) {
        string s;
        cin >> s;
        if(s == "AC") c[0]++;
        if(s == "WA") c[1]++;
        if(s == "TLE") c[2]++;
        if(s == "RE") c[3]++;
    }
    cout << "AC x " << c[0] << endl;
    cout << "WA x " << c[1] << endl;
    cout << "TLE x " << c[2] << endl;
    cout << "RE x " << c[3] << endl;

    return 0;
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    vector<vector<int>> nums(n,vector<int>(3));
    for(int i=0;i<n;i++)
        for(int j=0;j<3;j++)
            cin>>nums[i][j];

    // vector<int> dp(n,INT_MAX);
    // dp[0]=0;
    for(int i=n-2;i>=0;i--)
    {
        for(int j=0;j<3;j++)
        {
            if(j==0)
                nums[i][j]+=max(nums[i+1][2],nums[i+1][1]);
            else if(j==2)
                nums[i][j]+=max(nums[i+1][0],nums[i+1][1]);
            else
                nums[i][j]+=max(nums[i+1][0],nums[i+1][2]);//,nums[i+1][j+2]));
        }
    }
    cout<<nums[0][max_element(nums[0].begin(),nums[0].end())-nums[0].begin()]<<endl;
    return 0;
}

Measured memory_bytes: 5760
#include <bits/stdc++.h>
#define pb push_back
#define all(a) a.begin(), a.end()
#define sz(a) (int)a.size()
#define x first
#define y second
#define debug(...) cout << "[" << #__VA_ARGS__ << ": " << __VA_ARGS__ << "]\n"
#define rd() abs((int)rng())
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int>pii;
const int maxn = 1e5 + 100;
const int mod = 1e9 + 7;
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
int n, X, Y, Z;
void add(int &a, int b)
{
    a += b;
    if(a >= mod)
        a -= mod;
}
int main()
{
    ios_base::sync_with_stdio(false), cin.tie(0);
    cin >> n >> X >> Y >> Z;
    int m = (1 << (X + Y + Z + 1)) - 1;
    int need = (1 << 0) | (1 << Z) | (1 << (Y + Z)) | (1 << (X + Y + Z));
    vector<vector<int> >dp(m + 1, vector<int>(2, 0));
    dp[1][0] = 1;
    for(int i = 0; i < n; i++)
    {
        vector<vector<int> >new_dp(m + 1, vector<int>(2, 0));
        for(int msk = 1; msk <= m; msk++)
        {
            for(int f = 0; f < 2; f++)
            {
                if(!dp[msk][f])
                    continue;
                for(int a = 1; a <= 10; a++)
                {
                    int new_msk = (msk << a) | 1;
                    new_msk &= m;
                    int nf = f;
                    if((new_msk & need) == need)
                        nf = 1;
                    add(new_dp[new_msk][nf], dp[msk][f]);
                }
            }
        }
        dp = new_dp;
    }

    int ans = 0;
    for(int msk = 1; msk <= m; msk++)
        add(ans, dp[msk][1]);
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 30972
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#define vll vector<ll>
#define vvvl vector<vvl>
#define vvl vector<vector<ll>>
#define VV(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define VVV(a, b, c, d) vector<vvl>(a, vvl(b, vll (c, d)));
#define re(c, b) for(ll c=0;c<b;c++)
#define all(obj) (obj).begin(), (obj).end()
typedef long long int ll;
typedef long double ld;
using namespace std;

int main(int argc, char const *argv[]) {
  ll n;std::cin >> n;
  ll x = (n%1000==0?1000:n%1000);
  std::cout << 1000 - x << '\n';
  return 0;
}


Measured memory_bytes: 3144
n = gets.chomp.to_i

cnt = Array.new(n+1,0)

for x in 1..Math.sqrt(n).to_i do
    for y in 1..x do
        for z in y..x do
            ans = x**2 + y**2 + x*y + z**2 + y*z + z*x
            break if ans > n
            #puts "#{x} #{y} #{z}"
            if x == y && y == z 
                cnt[ans] += 1
            elsif x != y && y != z && x != z
                cnt[ans] += 6
            else
                cnt[ans] += 3
            end
        end
    end
end

for i in 1..n do
    #puts "N=#{i}のとき"
    puts cnt[i]
end

Measured memory_bytes: 14268
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int H,M,HH,MM,K;
  cin >> H >> M >> HH >> MM >> K;
  HH=HH-H;
  MM=MM-M;
  HH = HH * 60;
  HH = HH + MM;
  HH = HH - K;
  cout << HH << endl;
}

Measured memory_bytes: 3620
#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 INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

string S;

const int N_MAX = 10e5;
int t[N_MAX + 1];
int x[N_MAX + 1];
int y[N_MAX + 1];
int mitinori = 0;
int N;
int flg = 0;
string ans = "Yes";
int tmpa, tmpb;
int tmpaval, tmpbval;
int amax = 0;
int buse = 0;
int cCount = 0;
int main()
{
    cin >> N;
    t[0] = 0;
    x[0] = 0;
    y[0] = 0;
    FOR(i, 1, N + 1)
    {
        cin >> t[i] >> x[i] >> y[i];
    }

    REP(i, N)
    {
        mitinori = abs(x[i + 1] - x[i]) + abs(y[i + 1] - y[i]);
        if (mitinori > t[i + 1] - t[i] || ((t[i + 1] - t[i]) - mitinori) % 2 != 0)
        {
            ans = "No";
            break;
        }
    }

    cout << ans;
    return 0;
}

Measured memory_bytes: 8832
#include<bits/stdc++.h>
#define sqr(x) ((x)*(x))
#define ll long long
#define ull unsigned long long
#define ui unsigned int
#define ld long double
#define vi vector<int>
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define debuge cerr<<"isok"<<endl
#define debug(x) cerr<<#x<<"="<<x<<endl
#define SS second
#define FF first
#define ls (k<<1)
#define rs (k<<1|1)
#define inf 0x3f3f3f3f
#define clr(a,x) memset(a,x,sizeof(a))
#define cpy(a,x) memcpy(a,x,sizeof(a))
#define file(x) freopen(x".in","r",stdin),freopen(x".out","w",stdout);
using namespace std;

const int N=305,M=100005,mod=1e9+7;
template<class T> inline void gmin(T &x,const T &y){if(x>y) x=y;}
template<class T> inline void gmax(T &x,const T &y){if(x<y) x=y;}
inline void ch(int &x,int y){x=(x+y)%mod;}
template<class T>inline void read(T &x){
	x=0;char ch=getchar(),rev=0;
	while(ch>'9'||ch<'0') rev=(ch=='-'),ch=getchar();
	while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
	x=rev?-x:x;
}
template<class T>inline void print(T x,const char c){
	if(!x){putchar('0');putchar(c);return;}
	if(x<0) putchar('-'),x=-x;
	int m=0,a[10];
	while(x) a[m++]=x%10,x/=10;
	while(m--) putchar(a[m]+'0');
	putchar(c);
}
inline int exp(int x,int y){
	int ans=1;
	while(y){
		if(y&1) ans=(ll)ans*x%mod;
		x=(ll)x*x%mod;y>>=1;
	}return ans;
}

int n,m,now[N],a[N][N],du[N];
bool vis[N];
queue<int> q;
bool check(int k){
	clr(vis,0);clr(du,0);
//	if(x>1) return 1;
	while(!q.empty()) q.pop();
	for(int i=1;i<=n;i++){
		du[a[i][1]]++;now[i]=1;
		if(du[a[i][1]]==k+1) q.push(a[i][1]);
	}
	while(!q.empty()){
		int x=q.front();q.pop();
		vis[x]=1;
		for(int i=1;i<=n;i++){
			if(a[i][now[i]]!=x) continue;
			while(now[i]<=m&&vis[a[i][now[i]]]) now[i]++;
			if(now[i]>m) return 0;
			du[a[i][now[i]]]++;
//			debug(a[i][now[i]]);
			if(du[a[i][now[i]]]==k+1){
				q.push(a[i][now[i]]);
//				debug(a[i][now[i]]);
			}
		}
	}
//	for(int i=1;i<=m;i++)printf("%d ",du[i]);puts("");
	return 1;
}

int main(){
#ifdef rqgao2014
	freopen("input.txt","r",stdin);
#endif
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
			scanf("%d",&a[i][j]);
	int l=1,r=n;
	while(l<r){
		int mid=l+r>>1;
		if(check(mid)) r=mid; else l=mid+1;
	}
	printf("%d\n",r);
	return 0;
}

Measured memory_bytes: 640
import java.util.HashMap;
import java.util.Map;

public class Main {

  private static void solve() {
    int n = ni();
    int k = ni();
    int[] a = na(n);

    long[] sum = new long[n + 1];
    for (int i = 0; i < n; i++) {
      sum[i + 1] = sum[i] + a[i] + k - 1;
      sum[i + 1] %= k;
    }

    long ret = 0;
    Map<Long, Long> map = new HashMap<>();
    for (int i = 0; i <= n; i++) {
      map.putIfAbsent(sum[i], 0L);
      ret += map.get(sum[i]);
      map.put(sum[i], map.get(sum[i]) + 1);

      if (i >= k - 1) {
        map.put(sum[i - k + 1], map.get(sum[i - k + 1]) - 1);
      }
    }

    System.out.println(ret);


  }

  public static void main(String[] args) {
    new Thread(null, new Runnable() {
      @Override
      public void run() {
        long start = System.currentTimeMillis();
        String debug = args.length > 0 ? args[0] : null;
        if (debug != null) {
          try {
            is = java.nio.file.Files.newInputStream(java.nio.file.Paths.get(debug));
          } catch (Exception e) {
            throw new RuntimeException(e);
          }
        }
        reader = new java.io.BufferedReader(new java.io.InputStreamReader(is), 32768);
        solve();
        out.flush();
        tr((System.currentTimeMillis() - start) + "ms");
      }
    }, "", 64000000).start();
  }

  private static java.io.InputStream is = System.in;
  private static java.io.PrintWriter out = new java.io.PrintWriter(System.out);
  private static java.util.StringTokenizer tokenizer = null;
  private static java.io.BufferedReader reader;

  public static String next() {
    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
      try {
        tokenizer = new java.util.StringTokenizer(reader.readLine());
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
    return tokenizer.nextToken();
  }

  private static double nd() {
    return Double.parseDouble(next());
  }

  private static long nl() {
    return Long.parseLong(next());
  }

  private static int[] na(int n) {
    int[] a = new int[n];
    for (int i = 0; i < n; i++)
      a[i] = ni();
    return a;
  }

  private static char[] ns() {
    return next().toCharArray();
  }

  private static long[] nal(int n) {
    long[] a = new long[n];
    for (int i = 0; i < n; i++)
      a[i] = nl();
    return a;
  }

  private static int[][] ntable(int n, int m) {
    int[][] table = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[i][j] = ni();
      }
    }
    return table;
  }

  private static int[][] nlist(int n, int m) {
    int[][] table = new int[m][n];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[j][i] = ni();
      }
    }
    return table;
  }

  private static int ni() {
    return Integer.parseInt(next());
  }

  private static void tr(Object... o) {
    if (is != System.in)
      System.out.println(java.util.Arrays.deepToString(o));
  }
}



Measured memory_bytes: 70600