akhauriyash/Code-Regression huggingface dataset:
#include<math.h>
#include<map>
#include<iostream>
#include <algorithm>
#include <string>
#include<vector>
#include<array>
#include<tuple>
#include<queue>
#include<stack>
#include<iomanip>
#include<bitset>
#include <list>
//AtCoderC++.cpp

using namespace std;


inline int ceileing(int a, int b) {
	return a % b == 0 ? a / b : a / b + 1;
}

template<typename T,typename Pred=less<T>>
void sort_vec(vector<T>& v, Pred p = Pred()) {
	sort(v.begin(), v.end(), p);
}

template<typename T>
void show_vec(vector<T>& t) {
	for (size_t i = 0; i < t.size(); i++) {
		cout << t[i] << " ";
	}
	cout << endl;
}

template<typename T,typename Op=plus<T>>
T accumrate(T init, const vector<T>& v, Op op = Op()) {
	for (auto p : v)init = op(init, p);
	return init;
}

class UF_Node {
	UF_Node* par{ this };
public:
	UF_Node* parent() {
		if (par == this)return this;
		return par = par->parent();
	}
	void set_parent(UF_Node* n) { par = n; }
};
class Union_Find_Tree {
private:
	vector<UF_Node> nodes;
public:
	Union_Find_Tree(int N) :nodes{ vector<UF_Node>(N) } {}
	UF_Node& operator[](int i) { return nodes[i]; }
	void _union(int i, int j) {
		auto root1 = nodes[i].parent();
		auto root2 = nodes[j].parent();
		if (root1 == root2)return;
		root2->set_parent(root1);
	}
	bool in_same_tree(int i, int j) { return nodes[i].parent() == nodes[j].parent(); }
};

void swap(int i,vector<int>& ps, Union_Find_Tree& tree) {
	if (i == ps.size())return;
	if (ps[i] == i + 1) {
		swap(++i, ps, tree);
		return;
	} else {
		if (tree.in_same_tree(i, ps[i] - 1)) {
			std::swap(ps[i], ps[ps[i] - 1]);
			swap(i, ps, tree);
		} else {
			swap(++i, ps, tree);
		}
	}
}

int main() {
	int N, M; cin >> N >> M;
	auto ps = vector<int>(N);
	for (auto i = 0; i < N; i++)cin >> ps[i];
	auto tree = Union_Find_Tree(N);
	int l, r;
	for (auto i = 0; i < M; i++) {
		cin >> l >> r;
		tree._union(l - 1, r - 1);
	}
	//	for (size_t i = 0; i < N; i++) cout << i << ":" << &tree[i] << " "; cout << endl;
	//	for (size_t i = 0; i < N; i++) cout << tree[i].parent() << " "; cout << endl;

	//同じtreeにいるなら到達可能。正しい操作で特定の2つだけを入れ替えることは可能である。
	//具体的には、aiとaj入れ替えるまでに行った互換(i,k)(k,m)...(z,j)を逆順に実行する。
	swap(0, ps, tree);
	auto answer = 0;
	for (size_t i = 0; i < N; i++) {
		if (ps[i] == i + 1)++answer;
	}
	cout << answer << endl;
}

Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define rep0(a,b) for(int a=0;a<b;a++)
#define rep1(a,b) for(int a=1;a<=b;a++)
#define repp(a,b,c) for(int a=b;a<c;a++)
#define rev(a,b,c) for(int a=b;a>=c;a--)
#define in insert
#define len length()
#define si size()
#define lb lower_bound
#define ub upper_bound
#define beg begin()
#define end end()
#define vec vector<ll>
#define se set<ll>
#define mults multiset<ll>
#define F first
#define S second
#define pr(a) cout<<a
#define pr2(a,b) cout<<a<<" "<<b
#define get(a) cin>>a
#define nextl cout<<endl
const ll mod = 1000000007;
const ll maxn = 500005;
const ll mm = 1e+18;
ll power(ll x, ll y)
{
    ll res = 1;
    x = x % mod;
    while (y > 0)
    {
        if (y & 1)
            res = (res*x) % mod;
        y = y>>1;
        x = (x*x) % mod;
    }
    return res;
}
ll ncr(ll n, ll k)
{
    ll C[k+1];
    memset(C, 0, sizeof(C));

    C[0] = 1;

    for (ll i = 1; i <= n; i++)
    {
        for (ll j = min(i, k); j > 0; j--)
            C[j] = (C[j] + C[j-1])%mod;
    }
    return C[k];
}
void solve()
{
    int n;
    get(n);
    double sum=0;
    while(n--){
        double x;
        cin>>x;
        sum+=(1/x);
    }
    pr(1/sum);
}
int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t=1;
    //cin>>t;
    while(t--){
        solve();
        //nextl;
    }
    return 0;
}


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


int main (){

    int N,M;
    cin >> N >> M;
    int a[M],b[M];
    map<int,int>m;
    for(int i = 0; i < M; i++) {
        cin >> a[i] >> b[i];
        m[a[i]]++;
        m[b[i]]++;
    }
    for(int i = 1; i <= N; i++) {
        cout << m[i] << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define BIT(n) (1LL << (n))
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPB(i, n) for (int i = 0; i < BIT(n); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); 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 FORA(i, n) for (auto &&i : n)
#define FORS(i, m, n) for (int i = m; i <= n; i++)
#define DEBUG(x) cerr << #x << ": " << x << "\n"
#define PRINTALL(V)    \
  for (auto v : (V)) { \
    cerr << v << " ";  \
  }                    \
  cerr << "\n";
#define ALL(v) v.begin(), v.end()
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
#define epb emplace_back
#define int long long
using namespace std;
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> using vec = std::vector<T>;
template <class T> void print(const T &x) { cout << x << "\n"; }
const int MOD = 1000000007, INF = 1061109567, INF2 = INF * INF;
const double EPS = 1e-10, PI = acos(-1.0);
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
signed main() {
  cin.tie(0), ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  int N, L;
  cin >> N >> L;
  vec<string> S(N);
  REP(i, N) { cin >> S[i]; }
  sort(ALL(S));
  print(accumulate(ALL(S), string()));
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
        using namespace std;
        #define ll long long int
        #define pb push_back
        #define mk make_pair
        #define ft first
        #define sc second
        #define ppb pop_back
        #define sz size
        #define forn(i,a,n) for(i=a;i<n;i++)
        #define M 1000000007
        #define inf 2e18


        int main() {

        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        cout.tie(NULL);
            
        ll n;
        cin>>n;
        vector<ll> v(n);
        for(ll i=0;i<n;i++)
            cin>>v[i];
        ll ans=0,mx;
        for(ll i=0;i<n;i++){
             
             if(i==0){ mx = v[i]; continue; }
            // for(ll j=0;j<=i;j++){
            //     if(v[i]>v[j]){
            //         ans++; break;
            //     }
            // }
             // cout<<mx<<" "<<v[i];
            if(v[i]>mx){
                ans++;
            }
            mx = min(mx,v[i]);
            // cout<<ans<<" \n";
        }
        cout<<n-ans<<"\n";

        return 0;
        }

Measured memory_bytes: 1792
S = input()

a = int(S[:2])
b = int(S[2:])

if 0 < a <= 12 and (b > 12 or b == 0):
    print("MMYY")
elif (a > 12 or a == 0) and 0 < b <= 12:
    print("YYMM")
elif 0 < a <= 12 and 0 < b <=12:
    print("AMBIGUOUS")
else:
    print("NA")


Measured memory_bytes: 2940
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <array>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <cassert>
#include <utility>
#include <functional>

using namespace std;
using lli = long long int;

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

int main() {
    int n, m;
    cin >> n >> m;
    vector<int> broken(n+1);
    rep(i,m) {
        int a;
        cin >> a;
        broken[a] = 1;
    }
    vector<int> dp(n+2);
    const int mod = 1000000007;
    dp[n] = 1;
    for (int i = n-1; i >= 0; i--) {
        if (broken[i]) {
            dp[i] = 0;
            continue;
        }
        dp[i] = (dp[i+1] + dp[i+2]) % mod;
    }
    cout << dp[0] << endl;
    return 0;
}


Measured memory_bytes: 1024
mod = 1000000007
eps = 10**-9


def main():
    import sys
    input = sys.stdin.readline

    def PrimeDecomposition(N):
        ret = {}
        n = int(N ** 0.5)
        for d in range(2, n + 1):
            while N % d == 0:
                if d not in ret:
                    ret[d] = 1
                else:
                    ret[d] += 1
                N //= d
            if N == 1:
                break
        if N != 1:
            ret[N] = 1
        return ret

    def extgcd(a, b):
        if b:
            d, y, x = extgcd(b, a % b)
            y -= (a // b) * x
            return d, x, y
        else:
            return a, 1, 0

    N = int(input())
    if N == 1:
        print(1)
        exit()
    P = PrimeDecomposition(N)
    if 2 in P:
        P[2] += 1
    else:
        P[2] = 1
    p_list = list(P.keys())
    np = len(p_list)
    ans = 2*N
    for i in range(2 ** np):
        p1 = 1
        p2 = 1
        for j in range(np):
            pp = p_list[j]
            if i >> j & 1:
                p1 *= pp ** P[pp]
            else:
                p2 *= pp ** P[pp]
        _, s2, s1 = extgcd(p2, p1)
        while s1 >= 0 or s2 <= 0:
            s1 -= p2
            s2 += p1
        while s2 - p1 > 0 and s1 + p2 < 0:
            s2 -= p1
            s1 += p2
        ans = min(ans, (-s1)*p1)
    print(ans)


if __name__ == '__main__':
    main()


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

using namespace std;

int main(void) {
  int i, j;
  int N;
  string ans;
  cin >> N;
  ans = "No";
  for(i = 1; i <= 9; i++) {
    for(j = 1; j <= 9; j++) {
      if(i*j == N) {
        ans = "Yes";
        break;
      }
    }
  }
  cout << ans << endl;
  return 0;
}




Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>


int main(void)
{
	char s[10+2];

	while(scanf("%10[1-9]\n", s)==1)
	{
		int ans=9999;

		for(int i=0;i<10;i++)
		{
			int x=0;
			sscanf(s+i, "%3d", &x);
			if(x<100) break;
			if(ans>abs(x-753)) ans=abs(x-753);
		}
		printf("%d\n", ans);
	}

	return 0;
}


Measured memory_bytes: 128
#include <stdlib.h>
#include <iostream>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>
using namespace std;

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

  map<string, int> S;
  string tmp_s;
  
  for(int i=0; i<N; i++){
    cin >> tmp_s;
    if(S.count(tmp_s)) S.at(tmp_s)++;
    else S[tmp_s]=1;
  }

  int max=-1;
  
  for(auto p: S){
    if(max<=p.second) max=p.second;
  }

  for(auto p: S){
    if(p.second==max){
      cout << p.first << endl;
    }
  }
  
  return 0;
}


Measured memory_bytes: 25344
def dfs(i,f,sum):
    if i==3:
        if sum==7:
            print(f+"=7")
            exit()

    else:
        dfs(i+1,f+"+"+s[i+1],sum+int(s[i+1]))
        dfs(i + 1, f + "-" + s[i + 1], sum - int(s[i + 1]))

s=input()
dfs(0,s[0],int(s[0]))

Measured memory_bytes: 3064
import Control.Monad
import Control.Applicative

import qualified Data.Sequence as S

type Process = (String, Int)

process :: Int -> Int -> Process -> (Int, Process)
process quantum elapsed (name, time)
  | time <= quantum = (elapsed+time,    (name, 0))
  | otherwise       = (elapsed+quantum, (name, time-quantum))

processAndPrint :: Int -> Int -> S.Seq Process -> IO ()
processAndPrint quantum elapsed ps =
  case S.viewl ps of
    S.EmptyL     -> return ()
    (p S.:< ps') ->
      let
        (elapsed', p'@(name, time)) = process quantum elapsed p
      in
        if time == 0
           then do
             putStrLn $ name ++ " " ++ show elapsed'
             processAndPrint quantum elapsed' ps'
           else
             processAndPrint quantum elapsed' (ps' S.|> p')

main :: IO ()
main = do
  [n, q] <- map read . words <$> getLine :: IO [Int]
  processes <- replicateM n readProcess
  processAndPrint q 0 (S.fromList processes)
  where
    readProcess :: IO Process
    readProcess = do
      [name, time] <- words <$> getLine
      return (name, read time)



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

using namespace std;

typedef long long ll;
const ll INF = 1LL<<60;

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

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

ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

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

  int N;
  cin >> N;
  vector<int> vec(101);
  for(int i = 1; i < 10; i++){
    for(int j = 1; j < 10; j++){
      vec[i*j] = 1;
    }
  }

  if(vec[N]){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(){
  int n, a[3][100], i, j, cnt=0, t, s;

  scanf("%d", &n);

  for(i=0; i<n; i++){
    a[0][i]=a[1][i]=a[2][i]=0;
  }

  for(i=0; i<3; i++){
    scanf("%d", &t);
    for(j=0; j<t; j++){
      scanf("%d", &s);
      a[i][s-1]=1;
    }
  }

  for(i=0; i<n; i++){
    if((a[0][i]==0 && a[2][i]==1) || (a[1][i]==1 && a[2][i]==1)){
      cnt++;
    }
  }

  printf("%d\n", cnt);

  return 0;
}

Measured memory_bytes: 600
#include<iostream>

using namespace std;

int main(){
  int n;
  int sum=0;
  int ma=0;
  cin>>n;
  for(int i=0;i<n;i++){
    int l;
    cin>>l;
    sum+=l;
    ma=max(l,ma);
  }
  if(sum>2*ma)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}


Measured memory_bytes: 256
import numpy as np
 
x1,y1,x2,y2 = map(int,input().split())
 
x1y1 = np.array([x1,y1])
x2y2 = np.array([x2,y2])
 
vector = x1y1 - x2y2
rotation = np.array([[0,1],
                     [-1,0]])
rotated_vector = np.dot(rotation,vector)
x3y3 = x2y2 + rotated_vector
x4y4 = x3y3 + vector
 
print(x3y3[0],x3y3[1],x4y4[0],x4y4[1])

Measured memory_bytes: 17984
#include <iostream>
#include <vector>
#include <map>
#include <list>
#include <queue>
#include <algorithm>
#include <cassert>
#include <string>
#include <climits>

using namespace std;
using ll = long long;

long long N, M;

int main()
{
	cin >> N >> M;
	multimap <long long, long long> m;
	for (long long i = 0; i < N; i++) {
		long long tmp1, tmp2;
		cin >> tmp1 >> tmp2;
		m.insert(make_pair(tmp1, tmp2));
	}

	long long res = 0;
	long long num = 0;
	for (auto i = m.begin(); i != m.end(); ++i) {
		res += i->first * i->second;
		num += i->second;
		if (num > M) {
			res -= (num-M) * i->first;
			break;
		}
		if (num == M)
			break;
	}

	cout << res << endl;

}



Measured memory_bytes: 6528
#include<iostream>
#include<algorithm>
#include<math.h>
#include<string>
#include<vector>
#include<queue>
#include<deque>
#include<iomanip>
#include<map>
using namespace std;
typedef pair<int, pair<int, int> >PP;
typedef long long ll;
typedef pair<ll, ll>P;
typedef vector<int>vec;
int inf=-1;
ll mod = pow(10, 9) + 7;

int a[200010];
int b[200010];
int main() {
	int n;cin>>n;
	for(int i=0;i<n;i++){
		cin>>a[i];
		b[i]=a[i];
	}
	sort(a,a+n);
	for(int i=0;i<n;i++){
		if(b[i]==a[n-1]){
			cout<<a[n-2]<<endl;
		}
		else{
			cout<<a[n-1]<<endl;
		}
	}
	return 0;
}

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

int main(){
    int n;
    long ans = 0;
    cin >> n;

    for (int i = 1;i <= n;i++){
        if ((i % 3 != 0) && (i % 5 != 0)){
            ans += i;
        }
    }
    cout << ans;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <iostream>
#include <bitset>
#include <cassert>
#include <queue>
#include <random>
#include <stack>
#include <iomanip>
#include <math.h>
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)n; i++)
#define repf(i, a, b) for (ll i = (ll)a; i < (ll)b; i++)
#define repr(i, a, b) for (ll i = (ll)a; i > (ll)b; i--)
#define repv(x, arr) for (auto &x : arr)
#define all(v) (v).begin(), (v).end()
#define vec(name, num) vector<ll> name((num), 0);
#define mp(a, b) make_pair(a, b)
#define pb(x) push_back(x)
#define F first
#define S second
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<int> vii;
typedef vector<vii> vvii;
const ll mod = 1e9 + 7;
const int infi = 2147483600;
const ll infl = 1e17;

int main()
{
    ll k,x,y;cin>>k>>x>>y;
    ll px = 1, py = 1;
    if (x<0)
        px = -1;
    if (y<0)
        py = -1;
    ll xm = abs(x), ym = abs(y);
    ll s = 0;
    vector<pll> move;
    while (xm+ym>=2*k){
        //cout << xm << " " << ym << endl;
        s++;
        if (xm>=k){
            move.pb(mp(k, 0));
            xm -= k;
        }
        else if (xm!=0){
            move.pb(mp(xm, k - xm));
            ym -= (k - xm);
            xm = 0;
        }
        else {
            move.pb(mp(0, k));
            ym -= k;
        }
    }

    ll nowx = 0, nowy = 0;
    if ((xm+ym)==k){
        move.pb(mp(xm, ym));
        s++;
        cout << s << endl;
        repr(i, s - 1, -1)
        {
            nowx += move[i].F;
            nowy += move[i].S;
            cout << px * nowx << " " << py * nowy << endl;
        }
        return 0;
    }

    if ((xm+ym)%2==1){
        if (k%2==0){
            cout << -1 << endl;
            return 0;
        }

        s++;
        if (xm==0){
            move.pb(mp(0, k));
            ym -= k;
        }
        else if (xm>=k){
            move.pb(mp(k, 0));
            xm -= k;
        }
        else {
            move.pb(mp(xm, k - xm));
            ym -= k - xm;
            xm = 0;
        }
    }


    s += 2;
    ll g = k - (abs(xm) + abs(ym)) / 2;
    ll pxm = 1, pym = 1;
    if (xm<0)
        pxm = -1;
    if (ym<0)
        pym = -1;
    xm = abs(xm);
    ym = abs(ym);
    if (xm<=ym){
        move.pb(mp(pxm*(xm + g), pym*(k - xm - g)));
        move.pb(mp(-g*pxm, (k - g)*pym));
    }
    else {
        move.pb(mp((k - ym - g)*pxm, (ym + g)*pym));
        move.pb(mp((k-g)*pxm, -g*pym));
    }
    cout << s << endl;
    repr(i,s-1,-1){
        nowx += move[i].F;
        nowy += move[i].S;
        cout << px*nowx << " " << py*nowy << endl;
    }
}

//この時点でx+y<2kになっている
//１．x+y=k：あと1回で終わる
//２．(x+y)%2==1のとき：1回近づけて３にいく
//３．(x+y)%2==0のとき：
//g=k-(x+y)/2として

//小さい方を―gまで動かす。大きい方は余り分動かす
//移動量はxm+g、k-xm-g
//ここでxm+g<=kは保証される

//次に-g、k-g動かす。
//ym=(k-xm-g)+k-gになるはず
//この2回の操作で必ず0，0に到達できる

Measured memory_bytes: 5488
N = int(input())
S = input()
d = {
    'R': {},
    'G': {},
    'B': {}
}
for i, s in enumerate(S):
    d[s][i] = True
answer = len(d['R']) * len(d['G']) * len(d['B'])
for r in d['R'].keys():
    for g in d['G'].keys():
        if 2 * r - g in d['B']:
            answer -= 1
        if 2 * g - r in d['B']:
            answer -= 1
        if ((r + g) % 2 == 0 and ((r + g) // 2) in d['B']):
            answer -= 1
            

print(answer)

Measured memory_bytes: 9100
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define all(c) begin(c),end(c)

template<typename T1, typename T2>
inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }

template<typename T1, typename T2>
inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

//改造
typedef long long int ll;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007


//ここから編集する
class SegTree {
public:
    const int MAX_N = 1 << 17;
    int n;
    vector<ll> dat;
    const ll INITIAL_DAT = 0L;

    SegTree(int n_) {
        init(n_);
    }

    void init(int n_) {
        n = 1;
        while (n < n_) n *= 2;
        dat = vector<ll>(2 * n);
        for (int i = 0; i < 2 * n - 1; ++i) dat[i] = INITIAL_DAT;
    }

    //どんなSegTreeを構築するか(デフォルトはRMQ)
    ll calc(ll vl, ll vr) {
        return max(vl, vr);
    }

    //k番目の値(0-indexed)をaに変更
    void update(int k, int a) {
        k += n - 1;
        dat[k] = a;
        //登りながら更新
        while (k > 0) {
            k = (k - 1) / 2;
//            dat[k] = min(dat[k * 2 + 1], dat[k * 2 + 2]);
            dat[k] = calc(dat[k * 2 + 1], dat[k * 2 + 2]);
        }
    }

    //[a,b)の最小値を求める
    //kは接点の番号,l,rはその接点が[l,r)に対応づいていることを表す。
    //したがって、外からはquery(a,b,0,0,n)として呼ぶ。
    ll query(int a, int b, int k, int l, int r) {
        //[a,b)と[l,r)が交差しなければINITIAL_DAT
        if (r <= a || b <= l) return INITIAL_DAT;

        //[a,b)が[l,r)が交差しなければ、INT_MAX
        if (a <= l && r <= b) return dat[k];
        else {
            //そうでなければ、2つの子に対する処理,デフォルトは最小値
            ll vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
            ll vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
            return calc(vl, vr);
        }
    }

    //[a,b)の最小値を求める
    ll find(int a, int b) {
        return query(a, b, 0, 0, n);
    }
};

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

    int N, M;
    cin >> N >> M;
    SegTree treeone(N + 5);

    using P = pair<int, int>;
    vector<P> vp;

    rep(i, 0, M) {
        int a, b;
        cin >> a >> b;
        vp.emplace_back(a, b);
    }

    sort(all(vp));
    reverse(all(vp));
    int ans = 0;
    for (auto e : vp) {
        int beg = e.first;
        int en = e.second;
        int max_v = treeone.find(beg, en);
        if (max_v == 0) {
            ans++;
            for (int i = beg; i < en; ++i) {
                treeone.update(i, 1);
            }
        }
    }

    cout << ans << endl;


    return 0;
}


Measured memory_bytes: 3448
var
	n,i,c:Longint;
	p:Array[1..20]of Longint;
begin
	read(n);
	for i:=1 to n do begin
		read(p[i]);
	end;
	for i:=2 to n-1 do begin
		if((p[i-1]<p[i])and(p[i]<p[i+1]))or((p[i-1]>p[i])and(p[i]>p[i+1]))then inc(c);
	end;
	writeln(c);
end.


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=1;i<=n;i++)
#define drep(i,n) for(int i=n;i>=0;i--)
#define MAX 100001
#define B 100
#define dmp make_pair
#define dpb push_back
#define fi first
#define se second
typedef long long ll;
typedef pair<ll,ll> P;
const int inf = 1e9;
const ll INF = 1e18;

int mx = 0;
priority_queue<int> q;
int main(){
	int n, h, t1, t2;
	ll ans = 0;
	scanf("%d%d", &n, &h);
	rep(i,n){
		scanf("%d%d", &t1, &t2);
		mx = max(mx, t1);
		q.push(t2);
	}
	
	while(h > 0){
		if(!q.empty() && q.top() >= mx){
			h -= q.top();
			q.pop();
		}else{
			//printf("%d %d %d\n", h, mx, (h/mx));
			if(h/mx >= 1)ans += (h/mx)-1;
			else h -= mx;
			h -= (h/mx)*mx;
		}
		ans++;
	}
	
	printf("%lld\n", ans);
	//rep(i,n)printf("%d\n",a[i]);
	//ll 注意
	return 0;
}





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

int main(){
    int N;
    cin >> N;
    int f=0;
    rep(i,9){
        rep(j,9){
            int temp = (i+1) * (j+1) ;
            if (temp == N) f++;
        }
    }
    if (f!=0) cout << "Yes" <<endl;
    else cout << "No" <<endl;
}

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

int main()
{
  int n, k;
  cin >> n >> k;
  string s;
  cin >> s;
  vector<int> nums;
  bool one(true);
  int cnt(0);

  for (int i = 0; i < n; i++) {
    if (s[i] == (one ? '1' : '0')) {
      cnt++;
    } else {
      nums.push_back(cnt);
      one = !one;
      cnt = 1;
    }
  }
  nums.push_back(cnt);
  if (nums.size() % 2 == 0) {
    nums.push_back(0);
  }

  vector<int> sums(nums.size() + 1);
  for (int i = 0; i < nums.size(); i++) {
    sums[i + 1] = sums[i] + nums[i];
  }

  int ans(0);
  for (int i = 0; i < nums.size(); i += 2) {
    int left = i;
    int right = min(left + 2 * k + 1, int(nums.size()));
    ans = max(ans, sums[right] - sums[left]);
    if (right == nums.size()) break;
  }
  cout << ans << endl;
}


Measured memory_bytes: 1272
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <numeric>
// #include <string>
// #include <cmath>
// #include <map>
// #include <iomanip>

#define MOD 1000000007

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

// void p() {
//     cout << "\n";
// }
// template<class Head, class... Body>
// void p(Head head, Body... body) {
//     cout << head << ",";
//     p(body...);
// }

template<typename T>
ostream& operator<<(ostream& os, const vector<T>& v) {
    os << "[";
    for (const auto i : v) {
        os << i << " ";
    }
    os << "]";
    return os;
}


int main(int argc, char const *argv[]) {
    int N;
    ull K;
    cin >> N >> K;
    vector<int> a(N), b(N);
    for (int i = 0; i < N; ++i) {
        cin >> a[i] >> b[i];
    }

    vector<int> idxs(N);
    iota(idxs.begin(), idxs.end(), 0);
    sort(idxs.begin(), idxs.end(), [&](int i, int j) {return a[i] < a[j];});
    // cout << idxs << endl;

    ull count = 0;
    int ans;
    for (int idx : idxs) {
        count += b[idx];
        if (count >= K) {
            ans = a[idx];
            break;
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1408
#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
  vector<int> hoge;
  for(int i=0; i<5; i++){
    int n;
    scanf("%d",&n);
    hoge.push_back(n);
  }

  sort(hoge.begin(),hoge.end());

  for(int i=0; i<5; i++){
    printf("%d",hoge[4-i]);
    if(i!=4)
      putchar(' ');
  }
  putchar('\n');
}

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

int main() {
  int h, w, n;
  cin >> h >> w >> n;
  int a[n];
  for (int i=0; i<n; i++)
    cin >> a[i];
  int ans[h*w], idx = 0;
  for (int i=0; i<n; i++) {
    for (int j=0; j<a[i]; j++) {
      ans[idx] = i+1;
      idx++;
    }
  }
  for (int i=0; i<h; i++) {
    if (i%2) {
      for (int j=w-1; j>=0; j--)
        cout << ans[i*w+j] << ' ';
    } else {
      for (int j=0; j<w; j++)
        cout << ans[i*w+j] << ' ';
    }
    cout << endl;
  }
  return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repr(i, a, b) for(int i = a; i >= b; i--)
#define int long long
#define all(a) a.begin(), a.end()
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e18;

int h, w, ans;
string s[410];
int d[410][410];
int dy[4] = {-1, 0, 1, 0};
int dx[4] = { 0, 1, 0, -1};
bool contain(int y, int x){
   return (0 <= y && y < h && 0 <= x && x < w);
}
int bl[410][410], wh[410][410];

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> h >> w;
    rep(i, 0, h){
        cin >> s[i];
    }
    rep(i, 0, h) rep(j, 0, w) d[i][j] = -1;
    rep(i, 0, h){
        rep(j, 0, w){
            if(s[i][j] == '.') continue;
            if(d[i][j] != -1) continue;
            queue<P> q;
            bl[i][j]++;
            d[i][j] = 0;
            q.push({i, j});
            while(q.size()){
                P p = q.front(); q.pop();
                int y = p.first;
                int x = p.second;
                rep(k, 0, 4){
                    int ny = y + dy[k];
                    int nx = x + dx[k];
                    if(!contain(ny, nx)) continue;
                    if(d[ny][nx] != -1) continue;
                    if(d[y][x] % 2 == 0 && s[ny][nx] == '#') continue;
                    if(d[y][x] % 2 && s[ny][nx] == '.') continue;
                    if(s[ny][nx] == '.') wh[i][j]++;
                    else bl[i][j]++;
                    d[ny][nx] = d[y][x] + 1;
                    q.push({ny, nx});
                }
            }
        }
    }
    rep(i, 0, h){
        rep(j, 0, w){
            ans += bl[i][j] * wh[i][j];
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 4352
#include<stdio.h>
int main(void){
	int i,n,min,max;
	long sum ;
	min = 0 ;
	max = 0 ;
	sum = 0 ;
	scanf("%d",&n) ;
	int a[n] ;
	for(i = 0 ;i<=n-1 ;i++){
		scanf("%d",&a[i]) ;
		if(i == 0){
			min = a[i] ;
			max = a[i] ;
		}
		if(min>a[i]){
			min = a[i] ;
		}
		if(max<a[i]){
			max = a[i] ;
		}
			sum+=a[i] ;
	}
	printf("%d %d %ld\n",min,max,sum) ;
	return 0 ;
}

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

int main() {
    size_t n;
    cin >> n;
    bool yes = true;
    for (size_t i = 0; i < n; i++) {
        int x;
        cin >> x;
        if (x % 2 == 0) {
            yes &= (x % 3 == 0) || (x % 5 == 0);
        }
    }

    cout << (yes ? "APPROVED" : "DENIED") << endl;

    return 0;
}


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

int main(){
  string s;
  cin >> s;
  if(s.size() == 2 && s[0] == s[1]){
    cout << 1 << " " << 2 << endl;
    return 0;
  }
  rep(i,s.size()-2,0){
    if(s[i] == s[i+1] || s[i] == s[i+2] || s[i+1] == s[i+2]){
      cout << i+1 << " " << i+3 << endl;
      return 0;
    }
  }
  cout << -1 << " " << -1 << endl;
}

Measured memory_bytes: 512
li = list(input())
#print(li)
#li2 = list(map(int,li))
#print(li2)

f12=int(li[0]+li[1])
b34=int(li[2]+li[3])
#print(f12)

if f12 > 0 and f12 <13:
    if b34 > 0 and b34 <13:
        print("AMBIGUOUS")
    else:
        print("MMYY")
else:
    if b34 > 0 and b34 < 13:
        print("YYMM")
    else:
        print("NA")

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) FOR(i,0,n)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define PB push_back
#define LB lower_bound
#define UB upper_bound
#define PQ priority_queue
#define UM unordered_map
#define ALL(a) (a).begin(),(a).end()
typedef vector<ll> vi;
typedef vector<vector<ll>> vvi;
const ll INF = (1ll << 60);
typedef pair<ll,ll> pii;

int main(){
  ll N,T; cin>>N>>T;
  vi l(N),r(N); REP(i,N) cin>>l[i]>>r[i];
  vi tl(T+1),tr(T+1);
  REP(i,N) {tl[l[i]]+=1; tr[r[i]]+=1;}
  ll num=0,ans=0;
  FOR(t,0,T+1) {num+=tl[t]-tr[t]; ans=max(ans,num);}
  cout<<ans<<endl;
}

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

#ifdef DEBUG
    #define IFD if(true)
#else
    #define IFD if(false)
#endif

int main()
{
    int N, M;

    cin >> N >> M;
    int L = 1;
    int R = 100000;
    for(int i = 1; i <= M; i++) {
        int l, r;
        cin >> l >> r;
        L = max(L, l);
        R = min(R, r);
        IFD cout << "(L, R) = (" << L << ", " << R << ")" << endl;
    }

    cout << max(0, R - L + 1) << endl;

    return 0;
}


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

int main() {
	int N, *A;
	int B;
	long long int sum = 0;

	//Nの読み込み
	scanf("%d", &N);

	A = calloc(N, sizeof(int));
	for (int i = 0; i < N + 1; i++)
		scanf("%d", &A[i]);

	for (int i = 0; i < N; i++) {
		scanf("%d", &B);
		if (B - A[i] >= 0) {
			sum += A[i];
			B -= A[i];
			if (B - A[i + 1] >= 0) {
				sum += A[i + 1];
				A[i + 1] = 0;
			}
			else {
				sum += B;
				A[i + 1] -= B;
			}
		}
		else {
			sum += B;
		}
	}
	printf("%lld", sum);
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1e9;
const int MOD = 1000000007;
const double PI = acos(-1);
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};

void solve() {
	int a, b, ab, numA, numB;
	cin >> a >> b >> ab >> numA >> numB;
	int s = a * numA + b * numB;
	int t = max(numA, numB) * ab * 2;
	int sw = (max(numA, numB) == numA) ? a: b;
	int u = 2 * ab * min(numA, numB) + sw * (max(numA, numB) - min(numA, numB));
	cout << min(min(s, t), u) << endl;
}

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

Measured memory_bytes: 3548
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <iomanip>
#include <queue>
#include <unordered_map>
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
using namespace std;
typedef long long ll;

int X;

int main(){
    cin>>X;

    if(X==7 || X==5 || X==3){
        cout<<"YES"<<endl;
    }else{
        cout<<"NO"<<endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define RG register
#define Min(a,b) (a<b?a:b)
#define ll long long
 
using namespace std;
 
inline int gi(){
	RG char ch=getchar();RG int x=0,q=0;
	while(ch<'0' || ch>'9') ch=='-'?(q=1):0,ch=getchar();
	while(ch>='0' && ch<='9') x=x*10+ch-'0',ch=getchar();
	return q?(-x):x;
}
 
int main(){
	//freopen("1.in","r",stdin);
	//freopen("1.out","w",stdout);
	int q=gi(),h=gi(),s=gi(),d=gi(),n=gi();
	h=Min(h,(q<<1));
	s=Min(s,(h<<1));
	d=Min(d,(s<<1));
	ll ans=1ll*n/2*d;
	if (n&1) ans+=s;
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<functional>
using namespace std;
long long int dp[101][4][4];
int main(void)
{
	int i,j,k,n,m,a,b[101],c;
	long long int sum,x;
	cin>>n>>m;
	for(i=1;i<=n;i++){
		for(j=1;j<=3;j++){
			for(k=0;k<=3;k++) dp[i][j][k]=0;
		}
	}
	for(i=1;i<=n;i++) b[i]=0;
	for(i=1;i<=m;i++){
		cin>>a;
		cin>>b[a];
	}
//	for(i=1;i<=n;i++)	printf("b=%d\n",b[i]);
	if(b[1]>0) dp[1][b[1]][0]=1;
	else{
		for(i=1;i<=3;i++) dp[1][i][0]=1;
	}
	for(i=1;i<n;i++){
//		printf("i=%d\n",i);
		for(j=1;j<=3;j++){
			if(dp[i][j][0]+dp[i][j][1]+dp[i][j][2]+dp[i][j][3]>0){
				for(k=0;k<=3;k++){
					if(b[i+1]>0){
						if(b[i+1]!=k||b[i+1]!=j){
							dp[i+1][b[i+1]][j]+=dp[i][j][k];
							dp[i+1][b[i+1]][j]%=10000;
						}
					}
					else{
						if(k!=1||j!=1){
							dp[i+1][1][j]+=dp[i][j][k];
							dp[i+1][1][j]%=10000;
						}
						if(k!=2||j!=2){
							dp[i+1][2][j]+=dp[i][j][k];
							dp[i+1][2][j]%=10000;
						}
						if(k!=3||j!=3){
							dp[i+1][3][j]+=dp[i][j][k];
							dp[i+1][3][j]%=10000;
						}
					}
				}
			}
		}
/*		for(j=1;j<=3;j++)	{
			for(k=1;k<=3;k++)	{			
				printf("dp=%d ",dp[i][j][k]);
			}
			printf("\n");
		}*/
	}
/*	for(i=1;i<=n;i++){
		for(j=1;j<=3;j++){
			sum=0;
			for(k=0;k<=3;k++) sum+=dp[i][j][k];
			printf("%lld ",sum);
		}
		printf("\n");
	}*/
	sum=0;
	for(i=1;i<=3;i++){
		for(j=0;j<=3;j++) sum+=dp[n][i][j];
	}
	x=sum%10000;
	printf("%d\n",x);
	return 0;
}

Measured memory_bytes: 3164
S = [int(i) for i in input().split('/')]

def f(S):
    if S[0] < 2019:
        return False
    elif S[0] > 2019:
        return True
    else:                                                                                                      
        if S[1] < 4:
            return False
        elif S[1] > 4:
            return True
        else:
            if S[2] <= 30:
                return False
            else:
                return True

if f(S):
    print('TBD')
else:
    print('Heisei')

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

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

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

int main() {
    int n;
    while(cin >> n, n){
        vector<array<int, 4>> v(n);
        for (int i = 0; i < n; ++i) {
            for (int j = 0; j < 4; ++j) {
                scanf("%d", &v[i][j]);
            }
        }
        int p, q, r, c;
        cin >> p >> q >> r >> c;
        int cnt = 0;
        for (int i = 0; i < n; ++i) {
            if(v[i][1] <= p && v[i][2] <= q && v[i][3] <= r && v[i][1]*4+v[i][2]*9+v[i][3]*4 <= c){
                cnt++;
                cout << v[i][0] << "\n";
            }
        }
        if(!cnt) puts("NA");
    }
    return 0;
}


Measured memory_bytes: 3152
#include <iostream>
#include <stdio.h>
#include <string>
#include <vector>
#include <array>
using namespace std;
int n;
vector<int> c;
vector<int> s;
vector<int> f;
vector<int> result;
void solve () {
    cin >> n;
    for(int i = 0; i < n - 1; i++) {
        int tmpc, tmps, tmpf;
        cin >> tmpc >> tmps >> tmpf;
        c.push_back(tmpc);
        s.push_back(tmps);
        f.push_back(tmpf);
    }
    for(int i = 0; i < n; i++) {
        int t = 0;
        for(int j = i; j < n - 1; j++) {
            if(t < s[j]) {
                t = s[j];
            } else if(t % f[j] == 0) {
            } else {
                t = t + f[j] - (t % f[j]);
            }
            t += c[j];
        }
        result.push_back(t);
        t = 0;
    }
    result.push_back(0);
    for(int i = 0; i < n; i++) {
        cout << result[i] << endl;
    }
}

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

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<vector>
using namespace std;
typedef long long ll;
ll x;
int main(){
	cin>>x;
	for(ll i=-4000;i<=4000;i++){
		for(ll j=i+1;j<=4000;j++){
			if(j*j*j*j*j-i*i*i*i*i==x)return cout<<j<<' '<<i<<endl,0;
		}
	}
}


Measured memory_bytes: 3624
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>

using namespace std;

int main() {
	int n;
	cin >> n;
	vector<int> p(n), a(n), b(n);
	for (int i = 0; i < n; i++) {
		cin >> p[i];
		p[i]--;
		a[i] = 30000 * (i + 1);
		b[i] = 30000 * (n - i);
	}
	for (int i = 0; i < n; i++) {
		a[p[i]] += i;
	}

	for (int i = 0; i < n - 1; i++) {
		cout << a[i] << " ";
	}
	cout << a[n-1] << endl;
	for (int i = 0; i < n - 1; i++) {
		cout << b[i] << " ";
	}
	cout << b[n-1] << endl;
	return 0;
}


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

#define ll long long
#define ld long double
#define F first
#define S second

#define ONLINE_JUDGE 1

using namespace std;

const int mod = 1e9+7;

bool check(ll n, ll d){
	while(n%d==0 && d > 1)
		n/=d;
	return n%d==1;
}

ll phi(ll n) {
    ll result = 0;
    for (ll i = 1; i * i <= n; i++) {
       if(n%i==0){
       	if(n/i==i) result++;
       	else result+=2;
       }
    }
    return result;
}

void solve(){
	ll n;
	cin >> n;
	int cnt = 0;
	for(ll i = 2; i * i <= n; i++){
		if(n%i==0){
			if(n/i==i){
				cnt+=check(n,i);
			}else{
				cnt+=check(n,i);
				cnt+=check(n,n/i);
			}
		}
	}
	cnt+= phi(n-1);
	//cout << phi(n-1) << "\n";
	cout << cnt  << "\n";	
}
int main(){
	#ifndef ONLINE_JUDGE	
		freopen("in.txt","r",stdin);
		freopen("out.txt","w",stdout);
	#endif
	//ios_base::sync_with_stdio(false);
	//cin.tie(NULL),cout.tie(NULL);		
	int t = 1;
	//cin >> t;
	while(t--)
		solve();
	return 0;
}

Measured memory_bytes: 256
from collections import defaultdict
H, W, D = map(int, input().split())
A = [[] * W for i in range(H)]
dic = {}
for i in range(H):
    a = list(map(int, input().split()))
    A[i] = a
    for j in range(W):
        dic[a[j]] = (i + 1, j + 1)

d = defaultdict(int)
for i in range(D + 1, H * W + 1):
    d[i] = d[i - D] + abs(dic[i][0] - dic[i - D][0]) + abs(dic[i][1] - dic[i - D][1])


Q = int(input())
for i in range(Q):
    L, R = map(int, input().split())
    print(d[R] - d[L])

Measured memory_bytes: 37560
#include <iostream>
#include <string>
#include<algorithm>
#include <vector>
#include<stack>
#include<queue>
#include<list>
#include<set>
#include<map>
#include<numeric>
using namespace std;

typedef long long ll;
#define modulo 1000000007 // 10^9 + 7
#define MAX 1000000000 // 10^9



int main() {
	int N; cin >> N;
	ll a[N + 1];

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

	// sortすることでNlogNのオーダーにする
	sort(a, a + (N + 1));

	/*
	for (int i = 0; i <= N; i++) {
		cout << a[i] << " ";
	}
	*/

	ll ans = 0;
	ll temp = a[0];
	int temp_count = 1;
	for (int i = 1; i <= N; i++) {
		if (temp == a[i]) {
			ans += temp_count;
			temp_count++;
		}
		else {
			temp = a[i];
			temp_count = 1;
		}
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1792
N = int(input())
t0 = 0
x0 = 0
y0 = 0
flag = 0
for i in range(N) :
    t1,x1,y1 = map(int,input().split())
    t = t1-t0
    x = abs(x1-x0)
    y = abs(y1-y0)
    if x+y <= t and (t-(x+y))%2 == 0 :
        t0 = t1
        x0 = x1
        y0 = y1
    else :
        flag = 1
if flag == 0 :
    print("Yes")
else :
    print("No")
   

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,M,K,A;
  cin >> N >> M;
  vector<int> vec(30);
  vector<int> vecans(30);
  cin >> K;
  for(int i=0;i<K;i++){
    cin>>A;
    vecans.at(A-1)=1;
  }
  for(int i=0;i<N-1;i++){
    cin >> K;
    for(int i=0;i<K;i++){
      cin>>A;
      vec.at(A-1)=1;
    }
    for(int i=0;i<30;i++){
      if(vecans.at(i)==vec.at(i))continue;
      else vecans.at(i)=0;
    }
    for(int i=0;i<30;i++)vec.at(i)=0;
  }
  int ans = 0;
  for(int i=0;i<30;i++){
    if(vecans.at(i)==1)ans++;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void){
    int h ,w ;
    int i ,j ;

    while(1){
        scanf("%d%d",&h ,&w);
        if (h==0 && w==0) break;

        for (i=0 ;i<h ;i++){
            for (j=0 ;j<w ;j++){

                if (((i+j)%2)==0){
                    printf("#");
                } else printf(".");

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

Measured memory_bytes: 572
#include<iostream>
#include<algorithm>
#include<vector>
#include<stdio.h>
#include<complex>
using namespace std;

int main(){
  vector<int> ans(26,0);
  string s;
while(getline(cin,s)){
  for(int i = 0; i < s.size(); i++){
    if('A' <= s[i] && s[i] <= 'Z'){
      int now = s[i] - 'A';
      ans[now]++;
    }else if('a' <= s[i] && s[i] <= 'z'){
      int now = s[i] - 'a';
      ans[now]++;
    }
  }
}
for(int i = 0; i < 26; i++){
  char c = 'a' + i;
  cout << c << " : " << ans[i] << endl;
}
return 0;
}



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

typedef long long ll;
typedef long double ld;
typedef vector<vector<int>> Graph;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
#define pi 3.14159265359
#define inf 2147483647
#define INF 9223372036854775807
#define mod 1000000007
#define mod2 998244353

int main() {
	int n; cin >> n;
    vector<vector<int>> alpha(n, vector<int>(26));
    vector<string> S(n);
    for(int i = 0; i < n; i++) {
        cin >> S[i];
        for(int j = 0; j < S[i].size(); j++) {
            char k = S[i][j] - 'a';
            alpha[i][(int)k]++;
        }
    }
    string ans;
    string bet = "abcdefghijklmnopqrstuvwxyz";
    for(int j = 0; j < 26; j++) {
        int m = inf;
        for(int i = 0; i < n; i++) {
            m = min(m, alpha[i][j]);
        }
        for(int i = 0; i < m; i++) ans += bet[j];
    }
    cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3580
import java.util.*;

class Main {
    public static void main(String[] args) {
        new Solver().run();
    }
}

class Combination {
    long[] fact;
    long[] ifact;
    long M;

    private long mpow(long x, long n) {
        long ans = 1;
        while (n != 0) {
            if ((n & 1) == 1) ans = ans * x % M;
            x = x * x % M;
            n = n >> 1;
        }
        return ans;
    }

    private long inv(long x) {
        return mpow(x, M - 2);
    }

    public Combination(int n, long M) {
        assert n < M;
        this.M = M;
        fact = new long[n + 1];
        ifact = new long[n + 1];

        fact[0] = 1;
        ifact[0] = 1;
        for (int i = 1; i <= n; ++i) fact[i] = (fact[i-1]*i) % M;
        ifact[n] = inv(fact[n]);
        for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i % M;
    }

    public long c(int n, int k) {
        if (k < 0 || k > n) return 0;
        return ((fact[n]*ifact[k] % M)*ifact[n-k] % M);
    }
}

class Solver {

    private long combi(long n, long r, long mod) {
        long ret = 1;
        for(int i = 1; i <= r; i++){
            ret = ret * (n - i + 1) / i;
            ret %= mod;
        }   
        return ret;
    }   

    public void run() {
        //Combination comb = new Combination(1000000, 998244353);
        //System.out.println(comb.c(1, 1));
        //System.out.println(comb.c(100, 1));
        //System.out.println(comb.c(100, 2));
        //System.out.println(comb.c(100, 3));
        //
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();
        int K = sc.nextInt();

        long mod = 998244353;
        Combination comb = new Combination(200005, mod);

        long ans = 0;
        long col = M; 
        for (int x = N - 1; x >= 0; x--) {
            long now = col;
            now *= comb.c(N - 1, x);
            if (x <= K) {
                ans += now;
                ans %= mod;
            }
            col *= M-1;
            col %= mod;
        }
        System.out.println(ans % mod);
        
        return;
    }

}

Measured memory_bytes: 39464
#include<iostream>
#include<algorithm>
using namespace std;
int a[105];
int main(){
	int n,ans;
	cin>>n;
	for (int i=1;i<=n*2;i++)cin>>a[i];
	sort(a+1,a+n*2+1);
	ans=0;
	for (int i=1;i<=n*2-1;i+=2) ans+=a[i];
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 632
#include<stdio.h>
#include<map>

using namespace std;

map<int, int> mp;

int n, cnt;

int main(void) {
    int t;
    scanf("%d", &n);
    for(int i=0; i<n; i++) {
        scanf("%d", &t);
        mp[t]++;
    }
    
    for(auto p: mp) {
        int a = p.first;
        int b = p.second;
        if(b>=a) cnt += (b-a);
        else cnt += b;
    }
    printf("%d", cnt);
    
    return 0;
}

Measured memory_bytes: 4736
#include<bits/stdc++.h>
#define ll long long int

using namespace std;

const ll mod=1000000007;
const ll inf=1e18;

int main(){

  ll n;
  cin >> n;
  ll s=0;
  for(int i=1;i<=n;i++){
    s+=i*(n-i+1);
  }
  for(int i=0;i<n-1;i++){
    ll u,v;
    cin >> u >> v;
    ll w;
    if(u>v){
      w=u;
      u=v;
      v=w;
    }
    s-=u*(n-v+1);
  }
  cout << s << endl;

}

Measured memory_bytes: 3648
n, t = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]

maxA = [min(A)]

for a in A[::-1]:
    maxA.append(max(maxA[-1], a))

del maxA[0]
maxA.reverse()

ans = 0
maxd = 0

for maxa, a in zip(maxA, A):
    d = maxa - a
    if maxd == d:
        ans += 1
    elif maxd < d:
        maxd = d
        ans = 1

print(ans)

Measured memory_bytes: 16016