akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
using LL = long long;
const LL LINF = 1e18;
using namespace std;
#define COUT(v) cout<<(v)<<endl
#define CIN(n)  int(n);cin >> (n)
#define LCIN(n) LL(n);cin >> (n)
#define SCIN(n) string(n);cin >> (n)
#define YES(n) cout<<((n)? "YES" : "NO")<<endl
#define Yes(n) cout<<((n)? "Yes" : "No")<<endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) <<endl

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

#define FOREACH(x,a) for(auto& (x) : (a) )

#define ALL(obj) (obj).begin(),(obj).end()

#define P pair<LL,LL>
#define I vector<int>
#define S set<int>
#define pb(v) push_back(v)
#define V vector
#define rt return
#define rmsame(a) sort(ALL(a)),a.erase(unique(ALL(a)), a.end())

typedef string::const_iterator State;
class PalseError {};
class Edge{
public:
    LL from,to,value;
    Edge(LL a,LL b,LL c){
        from = a;
        to = b;
        value = c;
    }
    Edge(LL a,LL b){
        from = a;
        to = b;
    }
};
queue<pair<string,int>> que;
int main(){
    CIN(N);CIN(Q);
    REP(a,N){
        SCIN(str);
        CIN(t);
        que.push(make_pair(str,t));
    }
    int times = 0;
    while(!que.empty()){
        pair<string,int> p = que.front();
        que.pop();
        if(p.second <= Q){
            times+=p.second;
            cout<<p.first<<" "<<times<<endl;
        }else{
            p.second-=Q;
            times+=Q;
            que.push(p);
        }
    }
    return 0;
}



Measured memory_bytes: 6372
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>



using namespace std;   // H是行W是列，i是行j是列 


bool a[55][55],t[55]; 

int main() {
	int H, W;
	cin >> H >> W;
	getchar();
	int i, j;
	char ch;
	for(i = 1; i <= H; i++) {
		for(j = 1; j <= W; j++) {
			ch = getchar();
			a[i][j] = (ch == '#')? 1 : 0;//1表示是黑色，0表示是白色 
		} 
		getchar();
	}
	bool no = 0;
//	for(i = 1; i <= H; i++) {
//		for(j = 1; j <= W; j++) {
//			
//			cout<<a[i][j];
//		} 
//		cout <<endl;
//	}
	for(i = 2; i < H; i++) {
		for(j = 2; j < W; j++) {
			/*//if(no && (!a[i][j])) {
				cout << "No";
				return 0;
		//	}
			if(a[i][j]) {
				t[i] = 1;
				no = 1;//no = 1表示现在是黑色的 
			}
			else {
				if(no) {
				
				}
				if(t[i])
			}*/
			if(a[i][j - 1] == 0 && a[i][j] == 1 && a[i][j + 1] == 0 
			&& a[i - 1][j] == 0 &&a[i + 1][j] == 0) {
				cout << "No" << endl;
				return 0;
			}
		}
	}
	cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 256
package main

import (
        "bufio"
        "fmt"
        "os"
        "strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
        sc.Scan()
        i, e := strconv.Atoi(sc.Text())
        if e != nil {
                panic(e)
        }
        return i
}

func swap(ns []int, n1 int, n2 int) []int {
        if ns[n1] > ns[n2] {
                tmp := ns[n1]
                ns[n1] = ns[n2]
                ns[n2] = tmp
        }
        return ns
}

func main() {
        sc.Split(bufio.ScanWords)
        a := nextInt()
        b := nextInt()
        c := nextInt()

        ns := []int{a, b, c}
        ns = swap(ns, 0, 1)
        ns = swap(ns, 1, 2)
        ns = swap(ns, 0, 1)
        fmt.Println(ns[0], ns[1], ns[2])
}


Measured memory_bytes: 1104
#include<bits/stdc++.h>
using namespace std;
int A[10];
int main(){
	for(int i = 0; i < 6; i ++)cin>>A[i];
	bool flag = true;
	for(int i = 0; i < 5 && flag; i ++){
		for(int j = i + 1; j < 5; j ++){
			if(abs(A[i] - A[j]) > A[5])flag = false;
		}
	}
	if(flag)cout << "Yay!" <<endl;
	else cout << ":(" << endl;
	return 0;
} 

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#define LEN 1000

int lsc(char *, char *);

int main(){
  int q, ans;
  int i;
  char x[LEN] = {}, y[LEN] = {};

  scanf("%d", &q);
  for(i=0;i<q;i++){
    scanf("%s", x);
    scanf("%s", y);
    //printf("%s\n%s\n", x, y);
    ans = lsc(x, y);
    printf("%d\n", ans);
  }

  return 0;
}

int lsc(char *x, char *y){
  int m, n; //mはxの長さ、nはyの長さ(ヌル文字含めないやつ)
  int i, j;

  m = strlen(x);
  n = strlen(y);

  //printf("%d\n%d\n", m, n);

  int c[m+1][n+1]; //x, yが0文字目の時もカウントするから+1確保

  //どっちかが0文字目ならlscは0
  for(i=0;i<=m;i++) c[i][0] = 0;
  for(j=0;j<=n;j++) c[0][j] = 0;

  for(i=1;i<=m;i++){
    for(j=1;j<=n;j++){
      //xとyの1文字目から比べたいから-1する
      if(x[i-1] == y[j-1]) c[i][j] = c[i-1][j-1] + 1; //xiとyjが同じなら直前までのlscの長さ+1
      //xiとyjが違う文字の時
      //xi-1とyjのlscの長さと、xjとyj-1のlscの長さのうち長い方がxiとyjのlscの長さになる
      else if(c[i-1][j] >= c[i][j-1]) c[i][j] = c[i-1][j];
      else c[i][j] = c[i][j-1];
    }
  }

  //求める回答はc[m][n]
  return c[m][n];
}



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

#define int long long
#define fi first
#define se second
#define otp(n) cout << n;
#define ct(n) cout << n << endl;
#define cts(n) cout << n << " ";
#define cte cout << endl;
#define ctv(v) rep(i,(v).size()) ct(v[i])
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define repo(i,o,n) for(int i=o;i<n;i++)
#define repm(i,n) for(int i=n-1;i>=0;i--)
#define repv(i,v) for(int i=0;i<(v).size();i++)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define sperase(v,n) (v).erase(remove(all(v), n), (v).end());
#define vdelete(v) (v).erase(unique(all(v)), (v).end());
#define pb(n) push_back(n);

int n,a,ans;
vector<int> v;

main() {
    cin >> n;
    rep(i,n*3) cin >> a,v.pb(a)
    sort(rall(v));
    rep(i,n) ans += v[i*2+1];
    ct(ans)
}



Measured memory_bytes: 6000
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define dump(...)
#endif
#define endl '\n'
//#define int long long
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, x) for (int i = 0; i < (int)(x); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define RREP(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (int i = ((int)(x)); i > 0; i--)
#define INF 2147483647
#define LLINF 9223372036854775807LL
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define BIT(n) (1LL << (n))
#define TOUPPER(s) transform(s.begin(), s.end(), s.begin(), ::toupper)
#define TOLOWER(s) transform(s.begin(), s.end(), s.begin(), ::tolower)
#define FILLZERO(s, n)                      \
    do {                                    \
        ostringstream os;                   \
        os << setw(n) << setfill('0') << s; \
        s = os.str();                       \
    } while (0);
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()) //sortしてからつかうこと
#define INIT                               \
    std::cin.tie(nullptr);                 \
    std::ios_base::sync_with_stdio(false); \
    cout << std::fixed << std::setprecision(10);

using ll = long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using pi = pair<int, int>;
template <typename T>
using Pq = priority_queue<T>;
template <typename T>
using pQ = priority_queue<T, vector<T>, greater<T>>;

template <typename T>
vector<T> make_vec(size_t a, T n) { return vector<T>(a, n); }
template <typename T, typename... Ts>
auto make_vec(size_t a, Ts... ts) { return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...)); }
template <class T>
inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
    for (T &x : vec)
        is >> x;
    return is;
}

constexpr ll MOD = 1e9 + 7;
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};
ll A, B, C, D, E, F, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S, T;
ll ans = 0;

signed main() {
    INIT;
    cin >> S;
    ans = INF;
    REP(i, S.size() - 1) {
        if (S[i] != S[i + 1]) {
            chmin(ans, (ll)max(i + 1, (int)S.size() - i - 1));
        }
    }
    if (ans == INF) {
        ans = S.size();
    }
    cout << ans << endl;
}

Measured memory_bytes: 3740
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <cstring>
#include <climits>
#include <cmath>
#include <cfloat>

using namespace std;

int d,integ;

int main()
{
	while(cin >> d, !cin.eof())
	{
		integ = 0;
		
		for( int i = 0 ; i+d <= 600; i += d)
		{
			integ += d*pow((float)(i), 2);
		}
		
		cout << integ << endl;
	}
	
	return 0;
}

Measured memory_bytes: 0
# -*- coding: utf-8 -*-
import sys
from collections import deque, defaultdict
from math import sqrt, factorial, gcd
# def input(): return sys.stdin.readline()[:-1] # warning not \n
# def input(): return sys.stdin.buffer.readline().strip() # warning bytes
# def input(): return sys.stdin.buffer.readline().decode('utf-8')


def solve():
    n = int(input())
    cc = ['M', 'A', 'R', 'C', 'H']
    cnt = defaultdict(int)
    for _ in range(n):
        s = input()
        if s[0] in cc:
            cnt[s[0]] += 1

    ans = 0
    from itertools import combinations
    kc = list(cnt.keys())
    for a, b, c in combinations(kc, 3):
        ans += cnt[a] * cnt[b] * cnt[c] 
    print(ans)
    
t = 1
# t = int(input())
for case in range(1,t+1):
    ans = solve()


"""

abc

"""


Measured memory_bytes: 9400
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int MAX_N = 105;
const int MAX_V = 1005;
const ll INF = 1e13;
int w[MAX_N],v[MAX_N];
ll dp[MAX_N][MAX_N * MAX_V];

int main()
{
	int N,W;
	cin >> N >> W;
	rep(i,N)
	{
		cin >> w[i] >> v[i];
	}

	dp[0][0] = 0;
	for (int i = 1; i < MAX_N * MAX_V; ++i)
	{
		dp[0][i] = INF;
	}

	rep(i,N)
	{
		rep(j,MAX_N * MAX_V)
		{
			if (j - v[i] < 0)
			{
				dp[i+1][j] = dp[i][j];
			}
			else
			{
				dp[i+1][j] = min(dp[i][j], dp[i][j-v[i]] + w[i]);
			}
		}
	}
	rep(i,MAX_N * MAX_V)
	{
		if (dp[N][MAX_N * MAX_V - 1 - i] <= W)
		{
			cout << MAX_N * MAX_V - 1 - i << endl;
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 84224
#include <bits/stdc++.h>
using namespace std;
int main(){
	long long N; cin >> N; 
	if(N % 2 == 1){
		cout << 0 << endl; return 0; 
	}
	long long ans = N / 10; 
	long long tmp = N / 10; 
	while(tmp > 0){
		ans += tmp / 5; 
		tmp /= 5; 
	}
	cout << ans << endl; 
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
using namespace std;
typedef long long ll;

int main(void){
    int n;
    char s[105];
    cin >> n;
    cin >> s;
    
    int ans = 0;
    for (int i = 0; i < n; i++) {
        if (s[i] == 'R') ans++;
    }
    
    if (n % 2 == 0) {
        if (ans > n / 2) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
    else {
        if (ans > n / 2) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
    
}


Measured memory_bytes: 384
#include<stdio.h>
int main(){
  int a,b,num,sum;
  num=1;
  while(scanf("%d %d",&a,&b)!= EOF){
    sum=a+b;
    while(sum>9){
      sum=sum/10;
      num++;
    }
    printf("%d\n",num);
    num=1;
  }
  return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;

#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();i++)
#define ALL(container) (container).begin(), (container).end()
#define RALL(container) (container).rbegin(), (container).rend()
#define mp(a,b) make_pair(a, b)
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define __builtin_popcount __builtin_popcountll
//#define endl '\n'

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
    os<<"["; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"]"; return os;
}
template<class T> ostream& operator<<(ostream &os, const set<T> &t) {
    os<<"{"; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"}"; return os;
}
template<class S, class T> ostream& operator<<(ostream &os, const map<S, T> &t) {
    os<<"{"; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"}"; return os;
}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}
template<class S, class T> pair<S,T> operator+(const pair<S,T> &s, const pair<S,T> &t){ return pair<S,T>(s.first+t.first, s.second+t.second);}
template<class S, class T> pair<S,T> operator-(const pair<S,T> &s, const pair<S,T> &t){ return pair<S,T>(s.first-t.first, s.second-t.second);}

const int INF = 1<<28;
const double EPS = 1e-8;
const int MOD = 1000000007;

ll modpow(ll x, ll y){
    ll r = 1, a = x % MOD;
    while(y > 0){
        if((y&1) == 1) r = (r*a) % MOD;
        a = (a*a) % MOD;
        y /= 2;
    }
    return r;
}

ll solve1(ll n) {
    return modpow(2, n);
}

ll solve2(ll n, ll m) {
    return (modpow(2, __gcd(n, m)) - 2 + MOD) % MOD;
}

ll solve(ll n, ll m) {
    ll a1 = solve1(n);
    ll a2 = solve1(m);
    ll a3 = solve2(n, m);
    return (a1 + a2 - 1 + a3 + MOD) % MOD;
}

ll T, n, m, t;

int main(int argc, char *argv[]){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    while(cin >> n >> m >> t){
        ll k = 1;
        ll g = __gcd(n, t);
        n /= g; k *= g;
        g =  __gcd(m, t);
        m /= g; k *= g;
        cout << modpow(solve(n, m), k) << endl;
    }
    return 0;
}

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

int main() {
  int N;
  bool p, w, g, y;
  cin >> N;

  for (int i = 0; i < N; i++)
  {
    char S;
    cin >> S;

    if(S == 'Y') {
      cout << "Four" << endl;
      return 0;
    }
  }

  cout << "Three" << endl;
}

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

template <class T>
using Vvec = std::vector<std::vector<T> >;

// Karn's algorithm
void Topological_sort(Vvec<int> &to, std::vector<int> &ans)
{
    const int V = to.size();
    // std::vector<int> ans; // 結果
    std::stack<int> st; // 入次数0の頂点
    ans.clear();

    // 入次数のカウント
    std::vector<int> in_deg(V, 0);
    for(auto& u_to: to){
        for(int& v: u_to) in_deg[v]++;
    }

    // 入次数0の頂点追加
    for(int i=0; i<V; i++){
        if(in_deg[i] == 0) st.push(i);
    }

    // 更新
    while(!st.empty()){
        int u = st.top(); st.pop();
        ans.push_back(u);
        for(int &v: to[u]){
            in_deg[v]--;
            if(in_deg[v] == 0) st.push(v);
        }
    }
}

int main()
{
    int N;
    std::cin >> N;
    std::vector<std::vector<long long> > A(N, std::vector<long long>(N-1));
    for(int i=0; i<N; i++){
        for(int j=0; j<N-1; j++){
            scanf(" %lld", &A[i][j]); A[i][j]--;
        }
    }

    int M = N*(N-1)/2;
    Vvec<int> to(M);
    for(int i=0; i<N; i++){
        for(int j=0; j<N-2; j++){
            int a = i < A[i][j] ? i : A[i][j];
            int b = i > A[i][j] ? i : A[i][j];
            int c = i < A[i][j+1] ? i : A[i][j+1];
            int d = i > A[i][j+1] ? i : A[i][j+1];
            int u = b*(b-1)/2 + a;
            int v = d*(d-1)/2 + c;
            to[u].push_back(v);
        }
    }

    std::vector<int> t_sorted;
    Topological_sort(to, t_sorted);
    if(t_sorted.size() != M){
        std::cout << -1 << std::endl; return 0;
    }

    Vvec<int> from(M);
    for(int u=0; u<M; u++){
        for(int &v: to[u]) from[v].push_back(u);
    }

    // for(int i=0; i<N*N; i++){
    //     printf("i=%d: ", i);
    //     for(int &j: from[i]) printf("%d ", j);
    //     printf("\n");
    // }

    std::vector<int> p_length(M);
    for(int& v: t_sorted){
        if(from[v].empty()){
            p_length[v] = 0; continue;
        }
        int max = 0;
        for(int u: from[v]){
            if(max < p_length[u]) max = p_length[u];
        }
        p_length[v] = max+1;
    }

    std::cout << *max_element(p_length.begin(), p_length.end())+1 << std::endl;

    // for(int& u: t_sorted) printf("%d ", u);
    // printf("\n");
    // for(int& l: p_length) printf("%d ", l);
    // printf("\n");
}

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

int main(){
  int cou[26]={0};
  string s;
  cin >> s;
  for(int i=0;i<s.size();i++){
    int alpha = s[i]-97;
    if(cou[alpha]==0){
      cou[alpha]++;
    }
    else{
      cout << "no" << endl;
      return 0;
    }
  }
  cout << "yes" << endl;
  return 0;
}


Measured memory_bytes: 384
//By TheOneYouWant
#pragma GCC optimize ("-O2")
#include <bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define memreset(a) memset(a,0,sizeof(a))
#define testcase(t) int t;cin>>t;while(t--)
#define forstl(i,v) for(auto &i: v)
#define forn(i,e) for(int i=0;i<e;++i)
#define forsn(i,s,e) for(int i=s;i<e;++i)
#define rforn(i,s) for(int i=s;i>=0;--i)
#define rforsn(i,s,e) for(int i=s;i>=e;--i)
#define bitcount(a) __builtin_popcount(a) // set bits (add ll)
#define ln '\n'
#define getcurrtime() cerr<<"Time = "<<((double)clock()/CLOCKS_PER_SEC)<<endl
#define dbgarr(v,s,e) cerr<<#v<<" = "; forsn(i,s,e) cerr<<v[i]<<", "; cerr<<endl
#define inputfile freopen("input.txt", "r", stdin)
#define outputfile freopen("output.txt", "w", stdout)
#define dbg(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); \
stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) { cerr<<endl; }
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << "\t"; err(++it, args...);
}
template<typename T1,typename T2>
ostream& operator <<(ostream& c,pair<T1,T2> &v){
	c<<"("<<v.fi<<","<<v.se<<")"; return c;
}
template <template <class...> class TT, class ...T>
ostream& operator<<(ostream& out,TT<T...>& c){
    out<<"{ ";
    forstl(x,c) out<<x<<" ";
    out<<"}"; return out;
}
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll,ll> p64;
typedef pair<int,int> p32;
typedef pair<int,p32> p96;
typedef vector<ll> v64;
typedef vector<int> v32; 
typedef vector<v32> vv32;
typedef vector<v64> vv64;
typedef vector<p32> vp32;
typedef vector<p64> vp64;
typedef vector<vp32> vvp32;
typedef map<int,int> m32;
const int LIM=1e5+5,MOD=1e9+7;
const ld EPS = 1e-9;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int main(){
	fastio;

	ll n,m; 
	cin>>n>>m;

	ll fact[LIM];
	fact[0] = 1;
	forsn(i,1,LIM){
		fact[i] = (fact[i-1]*i)%MOD;
	}

	if(abs(n-m)<=1){
		if(abs(n-m) == 1){
			ll ans = 0;
			ans = fact[n]*fact[m];
			ans %= MOD;
			cout<<ans<<ln;	
		}
		else{
			ll ans = 2*fact[n]*fact[m];
			ans %= MOD;
			cout<<ans<<ln;
		}
	}
	else cout<<0<<ln;

	return 0;
}

Measured memory_bytes: 4364
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

template <typename T>
void print(T x) {
    cout << x << endl;
}

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REVFOR(i, m, n) for (int i = (n - 1); i >= (m); --i)
#define REP(i, n) FOR(i, 0, n)
#define REVREP(i, n) REVFOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    int N; string X;
    cin >> N >> X;
    int cnt = 0;
    REP(i, N) if (X[i] == '1') cnt++;

    int div_neg = max(1, cnt - 1), div_pos = cnt + 1;

    vector<ll> v_neg(N), v_pos(N);
    v_neg[0] = div_neg > 1 ? 1 : 0;
    v_pos[0] = div_pos > 1 ? 1 : 0;
    REP(i, N - 1) {
        v_neg[i + 1] = (v_neg[i] * 2) % div_neg;
        v_pos[i + 1] = (v_pos[i] * 2) % div_pos;
    }

    ll s_neg = 0, s_pos = 0;
    REP(i, N) {
        if (X[i] == '1') {
            s_neg = (s_neg + v_neg[N - i - 1]) % div_neg;
            s_pos = (s_pos + v_pos[N - i - 1]) % div_pos;
        }
    }

    REP(i, N) {
        ll s_cur;
        if (X[i] == '1') {
            if (cnt == 1) {
                print(0);
                continue;
            }
            s_cur = (s_neg - v_neg[N - i - 1] + div_neg) % div_neg;
        } else {
            s_cur = (s_pos + v_pos[N - i - 1]) % div_pos;
        }

        int ans = 1;
        while(s_cur > 0) {
            ans++;
            s_cur %= bcnt(s_cur);
        }

        print(ans);
    }

}


Measured memory_bytes: 6764
n = int(input())
cs = []
for i in range(n):
    cs.append(int(input()))
dp = [0] * n
last_num = [-1] * 2 * 10**5
MOD = 10**9 + 7

for i, c in enumerate(cs):
    if i == 0:
        dp[i] = 1
        last_num[c-1] += 1
        continue
    # Fisrt color
    if(last_num[c-1] == -1):
        dp[i] += dp[i-1]
    # Previous color
    elif(last_num[c-1] == i-1):
        dp[i] += dp[i-1]
    # Reversi
    else:
        dp[i] += dp[i-1]
        dp[i] += dp[last_num[c-1]]
    dp[i] %= MOD
    last_num[c-1] = i
print(dp[n-1])

Measured memory_bytes: 24384
#include "bits/stdc++.h"
using namespace std;

int main()
{
	string S;
	cin >> S;
	int a = 0,amax=0;
	long sum = 0;
	int down = 0;
	for (int i = 0; i < S.size(); i++)
	{

		if (S[i] == '<') {
			if (down > 0) {
				sum -= down * a;
				a = 0;
			}
			a++;
			down = 0;
			amax = a;
		}
		else {
			a--;
			down++;
			if (a < 0) {
				sum += down;//このフェーズではaをまだ足してない
				a++;
			}
		}
		sum += a;
	}
	sum -= down * a;
	cout << sum;
	return 0;
}




Measured memory_bytes: 900
#include<bits/stdc++.h>
#define LLI long long int
#define pii pair<int,int>
#define fst first
#define sec second
#define ULTRA 2134567890
#define de(x) if(x!=0 && MODE==x)
#define MODE 1
using namespace std;

char s[4007] = {};
int R[4007] = {};
int G[4007] = {};
int B[4007] = {};

int main()
{
    int i,j;
    int N;

    scanf("%d", &N);
    scanf("%s", s+1);

    for( i=1; i<=N+1; i++)
    {
        R[i] = ( s[i] == 'R' ? R[i-1]+1 : R[i-1] );
        G[i] = ( s[i] == 'G' ? G[i-1]+1 : G[i-1] );
        B[i] = ( s[i] == 'B' ? B[i-1]+1 : B[i-1] );
    }

    LLI ans = 0;
    for( i=1; i<=N; i++)
    {
        for( j=i+1; j<=N; j++)
        {
            if( s[i] == s[j])
                continue;
            int k = min( N+1, j+(j-i));

            if( s[i] != 'R' && s[j] != 'R')
                ans += R[N+1] - R[j] - ( s[k] == 'R');
            else if( s[i] != 'G' && s[j] != 'G')
                ans += G[N+1] - G[j] - ( s[k] == 'G');
            else if( s[i] != 'B' && s[j] != 'B')
                ans += B[N+1] - B[j] - ( s[k] == 'B');

            de(0) printf("( %d, %d) >>> %lld\n", i, j, ans);
        }
    }

    printf("%lld\n", ans);

    return 0;
}

//
//          ___ ___  __________  __________
//         /////\  \/\   ______\/\\\\\\\\\\\  Code by ~Ice Tea~ of
//        //// \ \  \ \  \_____/\ \\\\_____/      New Empire of CHSH ...
//       ////   \ \  \ \  \      \ \\\\\\\\\\\
//      ////__   \ \  \ \  \      \ \\\\_____/
//     ///////\   \ \  \ \  \______\ \\\\_______   ________
//    ////____/    \ \__\ \___   ___\ \\\\\\\\\\\ _\  ___  \_
//   /__/           \/__/\/__/\  \__/\ \\\\_____//\  .\_/\_  \
//                           \ \  \   \ \\\\\\\\\\\\  \_\/_\  \
// ... with the AC Power of   \ \  \   \ \\\\_____/ \   _____  \
//   The Great Tsundere Doggy. \ \  \   \ \\\\     \ \  \  \ \  \
//                              \ \__\   \ \\\\\\\\\\ \__\  \ \__\
//                               \/__/    \/________/\/__/   \/__/
//


Measured memory_bytes: 3840
#include<bits/stdc++.h>
  using namespace std;
  #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  #define endl "\n"
  #define int long long
  #define all(v) v.begin(),v.end()
  #define f first
  #define s second
  #define PB push_back
  #define MP make_pair
  #define double long double
  #define trace1(x)                cerr<<#x<<": "<<x<<endl
  #define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
  #define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
  #define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
  #define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
  #define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
  #define cases int testcases;cin>>testcases; while(testcases--)
  #define MOD 1000000007
  #define N 50000005
  #define INF 1000000000000
  #define eps 1e-6


  int32_t main()
  {         


    IOS

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


    if(sum >= h)
    {
      cout <<"Yes";
    }
    else
    {
      cout <<"No";
    }


    return 0; 
}

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

using namespace std;

using ll = long long;
using Graph = vector< vector<int> >;

constexpr char newl = '\n';
constexpr int INF = 1145141919;

void dfs(int cur, int par, const Graph& g, const vector<int>& a, vector<int>& dp, vector<int>& ans) {
    int i = lower_bound(dp.begin(), dp.end(), a[cur]) - dp.begin();
    int memo = dp[i];
    dp[i] = a[cur];

    for (int nex : g[cur]) {
        if (nex == par) continue;
        dfs(nex, cur, g, a, dp, ans);
    }

    ans[cur] = lower_bound(dp.begin(), dp.end(), INF) - dp.begin();
    dp[i] = memo;
}

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

    int n;
    cin >> n;

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

    Graph g(n);
    for (int i = 1; i < n; i++) {
        int u, v;
        cin >> u >> v;
        --u; --v;
        g[u].push_back(v);
        g[v].push_back(u);
    }

    vector<int> dp(n, INF);
    vector<int> ans(n);
    dfs(0, -1, g, a, dp, ans);

    for (int i = 0; i < n; i++) {
        cout << ans[i] << newl;
    }
    return 0;
}

Measured memory_bytes: 33724
#include<iostream>
#include <list>
#include<stack>
#include<queue>
#include <vector>
#include <set>
#include<algorithm>
#include<math.h>
#include<stdlib.h>
#include<string>
#include <functional>
#include<fstream>

#define FOR(k,m,n) for(int (k)=(m);(k)<(n);(k)++)
#define REP(i,n) FOR((i),0,(n))
#define LL long long
#define CLR(a) memset((a),0,sizeof(a))
#define SZ(x) (int((x).size()))
#define WAITING(str) int str;std::cin>>str;
#define DEBUGING(str) cout<<str<<endl
using namespace std;

const LL MOD = 1000000007;// 10^9+7
const int INF = (1 << 28);

struct Stage {
	int N, M, L, K, A, H;
	vector<int> cold;
	vector<vector<int>> route;

	Stage() 
	{
		int a, b, c;
		cin >> N >> M >> L >> K >> A >> H;
		if (N == 0)return;
		cold.resize(L);
		route.resize(N, vector<int>(N, INF));

		REP(i, L) {
			cin >> a; 
			cold[i] = a;
		}
		//cold.push_back(H);
		REP(i, K) {
			cin >> a >> b >> c;
			route[a][b] = route[b][a] = c;
		}
	}

	void warshall_floyd()
	{
		REP(k, N)REP(i, N)REP(j, N) {
			if (i == j)continue;
			route[i][j] = min(route[i][j], route[i][k] + route[k][j]);
		}
	}

	int search()
	{
		vector<int> time(N, INF);
		set<int> s;
		time[A] = 0;
		s.insert(A);

		while (!s.empty()) {
			auto itr = s.begin();
			int now = *itr; s.erase(itr);

			for (int next : cold) {
				//距離限界
				if (route[now][next] > M)continue;

				//最適値
				if (time[next] < time[now] + route[now][next])continue;

				time[next] = time[now] + route[now][next];
				s.insert(next);
			}
		}


		int res = INF;
		cold.push_back(A);
		for (int last : cold) {
			if (route[last][H] > M)continue;
			res = min(res, time[last] + route[last][H]);
		}


		if (res == INF) {
			return INF;
		}
		else {
			int over = res- M;
			over = max(over, 0);
			return res + over;
		}
	}
};

//計算
bool calc()
{
	Stage stage;
	if (stage.N == 0)return false;
	
	stage.warshall_floyd();
	int time = stage.search();
	//cerr << "=========";
	if (time == INF)cout << "Help!" << endl;
	else cout << time << endl;

	return true;
}

//デバッグ
void debug()
{
	int N;
	cin>>N;
}


//メイン関数
int main()
{
	while (calc());
	//debug();
	
	return 0;
}



Measured memory_bytes: 3200
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define INF 999999999
#define m0(x) memset(x,0,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))

using namespace std;


int dy[4] = { 0,0,1,-1 };
int dx[4] = { 1,-1,0,0 };
int dxx[8] = { 0,0,1,1,1,-1,-1,-1 };
int dyy[8] = { 1,-1,0,1,-1,0,1,-1 };


ll m = 1000000007;

const int MOD = 1000000007;

ll gcd(ll x, ll y) {
	ll m = max(x, y), n = min(x, y);
	if (m%n == 0)return n;
	else return gcd(m%n, n);
}
ll lcm(ll x, ll y) {
	return x / gcd(x, y)*y;
}

ll myPow(ll x, ll n, ll m) {
	if (n == 0)
		return 1;
	if (n % 2 == 0)
		return myPow(x * x % m, n / 2, m);
	else
		return x * myPow(x, n - 1, m) % m;
}



long long nCr(int n, int r) {
	if (r > n / 2) r = n - r; // because C(n, r) == C(n, n - r)
	long long ans = 1;
	int i;

	for (i = 1; i <= r; i++) {
		ans *= n - r + i;
		ans /= i;
	}

	return ans;
}


int N, A, B;
int h[100010], x[100010];

//a÷b以上の最小の整数
ll CEIL(ll a, ll b) {
	return (a + b - 1) / b;
}

bool isOK(ll K) {
	ll cnt = 0;
	REP(i, N) {
		if (B*K < h[i]) {
			cnt += CEIL(h[i] - B * K, A - B);
		}
	}
	if (cnt <= K)return true;
	else return false;
}

int binary_search() {
	int ng = -1;
	ll ok = 1000000001;

	while (abs(ok - ng) > 1) {
		ll mid = (ok + ng) / 2;

		if (isOK(mid)) ok = mid;
		else ng = mid;
	}
	return ok;
}

int main() {
	cin >> N >> A >> B;
	REP(i, N) {
		cin >> h[i];
	}

	ll ans = binary_search();
	cout << ans << endl;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define inf INT_MAX
#define INF LLONG_MAX
#define ll long long
#define ull unsigned long long
#define M (int)(1e9+7)
#define P pair<int,int>
#define PLL pair<ll,ll>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
#define IN(a,n) rep(i,n){ cin>>a[i]; }
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define int ll
#define vi vector<int>
#define IP pair<int,P>
#define PP pair<P,P>
#define Yes(f){cout<<(f?"Yes":"No")<<endl;}
#define YES(f){cout<<(f?"YES":"NO")<<endl;}


signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(20);

  int n,k;
  cin>>n>>k;
  vi v(n);
  rep(i,n){
    cin>>v[i];
  }

  set<int> s;
  int c[210000]={};
  int ans=0;
  FOR(i,1,n){
    if(v[i-1]<v[i]) c[i]=c[i-1]+1;
 
    if(c[i]>=k-1) ans=1;
  }

  rep(i,k-1) s.insert(v[i]);

  FOR(i,k-1,n){
    s.insert(v[i]);
    if(*s.begin()!=v[i-k]||*s.rbegin()!=v[i]){
      if(c[i]<k-1) ans++;
    }
    s.erase(v[i-k]);
  }

  cout<<ans<<endl;
}

 

Measured memory_bytes: 12800
#coding utf-8
N=int(input())
A=list(map(int,input().split())) 
x = [0 for i in range(N)]
S =sum(A)
x[0]=S
for i in range(1,N,2):
  x[0]-=2*A[i]

for i in range(1,N):
  x[i]=2*A[i-1]-x[i-1]
ans= map(str,x)
print(' '.join(ans))

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

#define ll long long

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

Measured memory_bytes: 3636
read_ints = lambda : map(int, raw_input().strip().split())

n = input()
a = read_ints()

neg = 0
mn = float('inf')
s = 0
for num in a:
    mn = min(mn, abs(num))
    s += abs(num)
    if num < 0: neg += 1

if neg % 2 == 1:
    print s - 2 * mn
else:
    print s

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N,M;
int mat[101][101];
int dp[1<<15][15];
int cost[1<<15][15];


void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>M;
	FOR(i,M) {
		cin>>x>>y>>r;
		mat[x-1][y-1]=r;
		mat[y-1][x-1]=r;
	}
	
	FOR(i,1<<N) {
		FOR(x,N) {
			dp[i][x]=1<<30;
			FOR(y,N) if(i&(1<<y)) cost[i][x]+=mat[x][y];
		}
	}
	
	dp[1][0]=0;
	for(int mask=0;mask<1<<N;mask++) {
		FOR(x,N) if((mask&(1<<x)) && dp[mask][x]<1<<30) {
			FOR(y,N) if(mat[x][y] && (mask&(1<<y))==0) {
				int addco=cost[mask][y]-mat[x][y];
				dp[mask|(1<<y)][y]=min(dp[mask|(1<<y)][y],dp[mask][x]+addco);
			}
		}
		FOR(x,N) if((mask&(1<<x)) && dp[mask][x]<1<<30) {
			int nmask=mask^(1<<x);
			int left=((1<<N)-1)^mask;
			for(int i=left; i>0; i=(i-1)&left) {
				int add=0;
				FOR(y,N) if(i&(1<<y)) add+=cost[nmask][y];
				dp[mask|i][x]=min(dp[mask|i][x],dp[mask][x]+add);
			}
		}
	}
	
	
	cout<<dp[(1<<N)-1][N-1]<<endl;
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n';
	FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	solve(); return 0;
}


Measured memory_bytes: 4224
#include <iostream>
#include <vector>
#include <string>
#include <numeric>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <queue>
#include <deque>

using namespace std;
using ll = long long;

#define rep(countName, left, right, up) for (ll countName = left; countName < right; countName += up)
#define rev(countName, right, left, down) for (ll countName = right - 1; countName >= left; countName -= down)

int solve1(void)
{
    ll n, ans;

    cin >> n;

    vector<int> x(n);

    rep(i, 0, n, 1)
    {
        cin >> x[i];
    }

    rep(i, 1, 101, 1)
    {
        ll sum = 0;
        rep(k, 0, n, 1)
        {
            sum += pow(abs(x[k] - i), 2);
        }

        if (i == 1)
        {
            ans = sum;
        }
        else
        {
            ans = min(ans, sum);
        }
    }

    return ans;
}

int solve2(void)
{
    ll n, ans;
    ll min, max;

    cin >> n;

    vector<int> x(n);

    rep(i, 0, n, 1)
    {
        cin >> x[i];
    }

    min = *std::min_element(x.begin(), x.end());
    max = *std::max_element(x.begin(), x.end());

    rep(i, min, max + 1, 1)
    {
        ll sum = 0;
        rep(k, 0, n, 1)
        {
            sum += pow(abs(x[k] - i), 2);
        }

        if (i == 1)
        {
            ans = sum;
        }
        else
        {
            ans = std::min(ans, sum);
        }
    }

    return ans;
}

int main(void)
{
    cout << solve1() << endl;
    //cout << solve2() << endl;
    return 0;
}

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

#define ll long long int
#define pb push_back
#define mk make_pair
#define ff first
#define ss second
#define finput ifstream cin;cin.open("in.txt")
#define foutput ofstream cout;cout.open("out.txt")  
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define mod 1000000007

ll gcd(ll x, ll y){ 
	if(x<y) 
		swap(x,y); 
	if(x%y==0)
		return y;
	return gcd(y, x%y);
}

ll pwm(ll a, ll n){
	ll ans = 1;
	while(n>0){
		if(n%2==1){
			ans = (ans * a)%mod;
		}
		a = (a*a)%mod;
		n /= 2;
	}
	return ans%mod;
}

const int pwn = 100010;
ll pw[pwn];
void pwtwo(){
	pw[0] = 1;
	for(int i=1; i<pwn; i++){
		pw[i] = (pw[i-1]*2)%mod;
	}
}


ll gcdExtended(ll a, ll b, ll *x, ll *y); 
  
ll modInverse(ll a, ll m) 
{ 	
	if(a==1)
		return 1;
	//cout<<"mi "<<a<<" "<<m<<" ";
    ll x, y; 
    ll g = gcdExtended(a, m, &x, &y); 
    if (g != 1){
        //cout << "Inverse doesn't exist"<<endl; 
        return -1;
    }
    else
    { 
        // m is added to handle negative x 
        ll res = (x%m + m) % m; 
        //cout<<res<<endl;
        return res;
        // cout << "modular multiplicative inverse is " << res; 
    } 
} 
  
ll gcdExtended(ll a, ll b, ll *x, ll *y) 
{ 
    if (a == 0) 
    { 
        *x = 0, *y = 1; 
        return b; 
    } 
  
    ll x1, y1;
    ll gcd = gcdExtended(b%a, a, &x1, &y1); 
  
    *x = y1 - (b/a) * x1; 
    *y = x1; 
  
    return gcd; 
} 

ll fact[1010];
ll init(){
	fact[0] = 1;
	for(int i=1; i<1010; i++)
		fact[i] = (fact[i-1]*i)%mod;
}

ll ncr(ll n, ll r){
	ll ans = fact[n];
	if(r>n)
		return 0;
	//if(r!=0)
	ans = (ans*modInverse(fact[r], mod))%mod;
	// if(n-r!=0)
	ans = (ans*modInverse(fact[n-r], mod))%mod;

	return ans;
}

int main(){
	// finput;
	// foutput;
	fast;

	ll n, k, i, j, x, m;
	ll ans = 0ll;
	// string s;
	cin>>n;

	vector<int> vec;
	map<ll, ll> mp;
	ll pre = 0ll;
	mp[0] = 1;
	for(i=0; i<n; i++){
		cin>>x;
		pre += x;
		if(mp.find(pre)!=mp.end()){
			ans += mp[pre];
		}

		if(mp.find(pre)!=mp.end()){
			mp[pre] = mp[pre]+1;
			// cout<<pre<<" "<<mp[pre]<<" ";
		}
		else
			mp[pre] = 1;
// 
		// cout<<ans<<" "<<endl;
	}

	cout<<ans;


	return 0;
}

Measured memory_bytes: 12800
import java.util.Scanner;

public class Main {

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

		for (; sc.hasNext();) {

			int H = sc.nextInt();
			int W = sc.nextInt();

			if (H == 0 && W == 0) {
				break;
			}

			boolean flag = true;

			for (int i = 0; i < H; i++) {
				for (int j = 0; j < W; j++) {
					if (flag) {
						System.out.print("#");
						flag = false;
					} else {
						System.out.print(".");
						flag = true;
					}
				}
				System.out.println("");
				if (W % 2 == 0) {
					flag = !flag;
				}

			}
			System.out.println("");
			flag = true;
		}

	}

}



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

// 総数を1000000007（素数）で割った余り
const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ll gcd(int a, int b) {
    while (b) {
        int r = a % b;
        a = b;
        b = r;;
    }
    return a;
}

int main(){
    int k;
    cin >> k;
    ll ans = 0;
    rep1(i, k) rep1(j, k) rep1(h, k) {
        ans += gcd(gcd(i, j), h);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3652
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;



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

	string s;
	cin >> s;
	int n = s.length(), i, w;
	cin >> w;

	for (i = 0; i < n; i += w) cout << s.substr(i, 1);


	return 0;
}



Measured memory_bytes: 888
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <algorithm>
#include <numeric>

typedef long long ll;
const ll INF = 1e18;

int main()
{
  ll A, B, C;
  std::cin >> A >> B >> C;

  std::map<ll, ll> mc;
  mc[A]++;
  mc[B]++;
  mc[C]++;
  if (mc[5] == 2 && mc[7] == 1) {
    std::cout << "YES" << std::endl;
  } else {
    std::cout << "NO" << std::endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
static const int N = 1000000;
int main(void){
  int n;
  int a[N], b[N], c[N];

  cin >> n;
  for(int i=0;i<n;i++) scanf("%d", a+i);
  for(int i=0;i<n;i++) scanf("%d", b+i);
  for(int i=0;i<n;i++) scanf("%d", c+i);

  sort(a,a+n);
  sort(b,b+n);
  sort(c,c+n);

  long long int res = 0;
  for(int i=0;i<n;i++){
    long long int t1 = lower_bound(a,a+n,b[i]) - a;
    long long int t2 = n - (upper_bound(c,c+n,b[i]) - c);
    res += t1 * t2;
  }
  cout << res << endl;
}

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

int main() {
  int N;
  cin >> N;
  int hundreds = N / 100; // 1マス目に書かれた数字
  int tens = (N - hundreds * 100) / 10; // 2マス目に書かれた数字
  int ones = (N - hundreds * 100 - tens * 10 ) / 1; // 3マス目に書かれた数字
  cout << hundreds + tens + ones << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
using namespace std;
int main() {
	long long a, b, c, d = 1000000001, e = 0;
	cin >> a;
	for (long long h = 1; h <= a; h++) {
		cin >> b;
		c = 0;
		while (b % 2 == 0) {
			c++;
			b = b / 2;
		}
		d = min(c, d);
	}
	cout << d << "\n";
	cin >> e;
}

Measured memory_bytes: 256
#include <iostream>
#include<cmath>
#include<vector>
#include<tuple>
#include <ctime>
#include<algorithm>
#include <initializer_list>
#include <cstring> 
#include <queue>

using namespace std;
 
#define tii tuple<int,int>
#define vi vector<int>
#define vii vector<vi>
#define ll long long
#define vl vector<ll>
#define vll vector<vl>
 
#define mymod 1000000007
#define sz 200002

ll power(ll a, ll b, ll p)
{
    if(a<2)
    return a;
    ll ans = 1;
    while(b)
    {
        if(b%2)
        {
            ans *= a;
            ans %= p;
        }
        b = b/2;
        a = (a*a)%p;
    }
    return ans;
}

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

int main() {
    clock_t tstart = clock();
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    // Start
    string s;
    cin>>s;
    for(int i=0;i<s.length()-2;i++) {
        vector<char> v{s[i],s[i+1], s[i+2]};
        sort(v.begin(), v.end());
        if(v[0]==v[1] || v[1] == v[2]) {
            cout<<i+1<<" "<<i+3;
            return 0;
        }
    }
    for(int i=0;i<s.length()-1;i++) {
        if(s[i] == s[i+1]) {
            cout<<i+1<<" "<<i+2;
            return 0;
        }
    }
    cout<<"-1 -1";
    // cout<<"\n\nTotal Time Taken : "<<(double)(-tstart + clock())/CLOCKS_PER_SEC<<"sec\n\n";
    return 0;
}
 


Measured memory_bytes: 3688
import math

N=int(input())
li = []

for a in range(math.floor(math.sqrt(N)) + 1):
  if a == 0:
    continue
  
  if N % a == 0:
    b = math.floor(N / a)
    li.append([a, b])

ans = 100000000000000000000000000

for i in li:
  if len(str(i[0])) >= len(str(i[1])):
    k = len(str(i[0]))
  else:
    k = len(str(i[1]))

  if ans > k:
    ans = k

print(ans)

Measured memory_bytes: 3188
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 1000000000000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


bool check[1000005];

int main(){

	int K;
	scanf("%d",&K);

	if(7%K == 0){

		printf("1\n");
		return 0;
	}

	int num = 7;

	for(int i = 0; i < K; i++){

		check[i] = false;
	}

	check[7%K] = true;

	int count = 1;

	while(true){

		count++;
		num = 10*num+7;

		if(num%K == 0){

			printf("%d\n",count);
			return 0;
		}
		num = num%K;
		if(check[num])break;
		check[num] = true;
	}

	printf("-1\n");

	return 0;
}


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

int N,Ma,Mb;
int A[50],B[50],C[50];
int G[50][410][410];
int inf = 1000000;

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

int main(){
	while(cin >> N >> Ma >> Mb){
		for(int i=0;i<N;i++){
			cin >> A[i] >> B[i] >> C[i];
		}
		for(int i=0;i<N+1;i++){
			for(int j=0;j<401;j++){
				for(int k=0;k<401;k++){
					G[i][j][k] = inf;
				}
			}
		}
		G[0][0][0] = 0;
		for(int i=0;i<N;i++){
			for(int j=0;j<401;j++){
				for(int k=0;k<401;k++){
					if(G[i][j][k]==inf) continue;
					G[i+1][j][k] = min(G[i+1][j][k],G[i][j][k]);
					G[i+1][j+A[i]][k+B[i]] = min(G[i+1][j+A[i]][k+B[i]], G[i][j][k] + C[i]); 
				}
			}
		}	
		int ans = inf;
		for(int j=1;j<401;j++){
			for(int k=1;k<401;k++){
				int a = gcd(j,k);
				if(Ma == j/a && Mb == k/a && G[N][j][k] != -1) ans = min(ans,G[N][j][k]);
			}
		}
		if(ans != inf) cout << ans << endl;
		else cout << -1 << endl;
	}
}

Measured memory_bytes: 29056
#include <bits/stdc++.h>
#define rep(i,x) for(int i=0;i<x; i++)
typedef long long  ll;
using namespace std;
int main(){
  int K,N;
  cin>>K>>N;
  int A[N+2];
  

  
  rep(i,N){
  	cin>>A[i];
  }
  
  int ma=0,ans=0;
  rep(i,N-1){
    ans+=A[i+1]-A[i];
  	ma=max(ma,A[i+1]-A[i]);
  }
  
  ans+=A[0]+K-A[N-1];
  ma=max(ma,A[0]-A[N-1]+K);
 
  cout<<ans-ma;
  
}


Measured memory_bytes: 1024
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn binary_search(array: Vec<u32>, key: u32) -> usize {
    let len: usize = array.len();
    let mut left: usize = 0;
    let mut right: usize = len;
    while left < right {
        let mid: usize = (left + right) / 2;
        if array[mid] == key {
            return mid;
        } else if key < array[mid] {
            right = mid;
        } else {
            left = mid + 1;
        }
    }
    return len;
}

fn main() {
    let n: usize = read();
    let s: Vec<u32> = (0..n)
        .map(|_| {
            let number: u32 = read();
            number
        })
        .collect();
    let q: usize = read();
    let t: Vec<u32> = (0..q)
        .map(|_| {
            let number: u32 = read();
            number
        })
        .collect();
    let mut count: u32 = 0;
    let s_len: usize = s.len();
    for key in t {
        if s_len != binary_search(s.clone(), key) {
            count += 1;
        }
    }
    println!("{}", count);
}



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

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

    int ans = 0;
    for(int i = 0; i < N; i++){
        while(a[i]%2 == 0){
            ans++;
            a[i] = a[i]/2;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256