akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define ll long long
#define endl "\n"
#define mod 1000000007
using namespace std;

int main()
{
    ll n;
    cin>>n;
    
    ll dp[100001][3];
    ll arr[100001][3];
    
    for(ll i=0; i<n; i++)
    {
        ll x, y, z;
        cin>>x>>y>>z;
        
        arr[i][0] = x;
        arr[i][1] = y;
        arr[i][2] = z;
    }
    
    for(ll i=0; i<n; i++)
    {
        if(i == 0)
        {
            dp[i][0] = arr[i][0];
            dp[i][1] = arr[i][1];
            dp[i][2] = arr[i][2];
            continue;
        }
        dp[i][0] = max(arr[i][0] + dp[i-1][1], arr[i][0] + dp[i-1][2]);
        dp[i][1] = max(arr[i][1] + dp[i-1][0], arr[i][1] + dp[i-1][2]);
        dp[i][2] = max(arr[i][2] + dp[i-1][0], arr[i][2] + dp[i-1][1]);
    }
    
    cout<<*max_element(dp[n-1], dp[n-1]+3)<<endl;
    
    return 0;
}

Measured memory_bytes: 8240
#include <stdio.h>

int main()
{
	char* text = new char[127];

	scanf("%s", text);
	
	bool yes = true;
	int index = 0;
	while (true)
	{
		if (text[index] == '\0')
			break;
		else
		{
			if ((index & 1 && text[index] == 'R') || (!(index & 1) && text[index] == 'L'))
			{
				yes = false;
				break;
			}
		}

		++index;
	}

	delete[] text;

	printf("%s\n", yes ? "Yes" : "No");

	return 0;
}


Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;
class P
{
    static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        int[] a = Console.ReadLine().Split().Select(int.Parse).OrderByDescending(x => x).ToArray();
        int alice = a.Where((x, y) => y % 2 == 0).Sum();
        int bob = a.Where((x, y) => y % 2 == 1).Sum();
        Console.WriteLine(alice - bob);
    }    
}

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

using namespace std;

using ll = long long;

int n, a, b, c;
vector<int> l;

int Solve(int idx, int sum_a, int sum_b, int sum_c) {
    if (idx == n) {
        if (min({sum_a, sum_b, sum_c}) == 0) return n * n * (a + b + c);
        else return abs(a - sum_a) + abs(b - sum_b) + abs(c - sum_c) - 30;
    }

    int res = Solve(idx + 1, sum_a, sum_b, sum_c);
    res = min(res, Solve(idx + 1, sum_a + l[idx], sum_b, sum_c) + 10);
    res = min(res, Solve(idx + 1, sum_a, sum_b + l[idx], sum_c) + 10);
    res = min(res, Solve(idx + 1, sum_a, sum_b, sum_c + l[idx]) + 10);

    return res;
}

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

    cin >> n >> a >> b >> c;

    l.resize(n);
    for (int i = 0; i < n; ++i) cin >> l[i];

    cout << Solve(0, 0, 0, 0) << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int td(int n,vector<int> a)
{
    vector<int> dp(n+1);
    dp[1]=0;
    dp[2]=abs(a[1]-a[2]);
    for(int i=3;i<=n;i++)
    {
        dp[i]=min(abs(a[i]-a[i-1])+dp[i-1],abs(a[i]-a[i-2])+dp[i-2]);
    }
    return dp[n];
}
int main()
{
    int n;
    cin>>n;
    vector<int> a(n+1);
    for(int i=1;i<=n;i++)
        cin>>a[i];
    cout<<td(n,a);
}


Measured memory_bytes: 4516
#include <bits/stdc++.h>
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <random>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define repp(i,n,m) for (int i = m; i < (n); ++i)
#define repl(i,n) for (long long i = 0; i < (n); ++i)
#define reppl(i,n,m) for (long long i = m; i < (n); ++i)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using PL = pair<long long, long long>;
using Pxy = pair<double, double>;
using T = tuple<int, int, bool>;
const int INF = 1001001007;
const int mod = 1000000007;
const int MOD = 998244353;
const ll inf = 1e18;
template <typename AT>
void printvec(vector<AT> &ar){
    rep(i,ar.size()-1) cout << ar[i] << " ";
    cout << ar[ar.size()-1] << endl;
}
template <typename Q>
void printvvec(vector<vector<Q>> &ar){
    rep(i,ar.size()){
        rep(j,ar[0].size()-1) cout << ar[i][j] << " ";
        cout << ar[i][ar[0].size()-1] << endl;
    }
}
template <typename S>
bool range(S a, S b, S x){
    return (a <= x && x < b);
}

void yn(int o){
    if (o == 0) cout << "No" << endl;
    else cout << "Yes" << endl;
}

int cul(int n){
    vector<int> ar(10,0);
    int re = 0;
    rep(i,10){
        ar[i] = n % 10;
        n /= 10;
        re += ar[i];
    }
    return re;
}

int main() {
    int n; cin >> n;
    int ans = 0;
    while (ans * ans <= n){
        ans++;
    }
    cout << (ans-1) * (ans-1) << endl;
}

Measured memory_bytes: 3612
#include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i,N) for(int i=0;i<N;++i)
typedef long long int LL;

LL N;
std::vector<LL>a, b;

int main()
{
	in >> N;
	a.resize(N), b.resize(N);
	rep(i, N) in >> a[i];
	rep(i, N) in >> b[i];
	LL ans = 0;
	rep(i, 30)
	{
		LL power = 1LL << i, powerPlus = 1LL << (i + 1);
		auto aa = a, bb = b;
		rep(j, N)
		{
			aa[j] %= powerPlus;
			bb[j] %= powerPlus;
		}
		std::sort(bb.begin(), bb.end());
		LL one = 0;
		rep(j, N)
		{
			one += std::lower_bound(bb.begin(), bb.end(), 2 * power - aa[j])
				- std::lower_bound(bb.begin(), bb.end(), power - aa[j]);
			one += std::lower_bound(bb.begin(), bb.end(), 4 * power - aa[j])
				- std::lower_bound(bb.begin(), bb.end(), 3 * power - aa[j]);
		}
		if (one % 2 == 1) ans += power;
	}
	out << ans << std::endl;
	return 0;
}


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

int main(){
	int n, d;
	cin >> n >> d;
	int c = 0;
	if(n % ((d*2)+1) != 0){
		c++;
	}
	cout << (n / ((d*2)+1)) + c << endl;
	return 0;
}


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

template < typename Container, typename Value = typename Container::value_type, std::enable_if_t<!std::is_same< Container, std::string >::value, std::nullptr_t> = nullptr>
std::istream& operator>> (std::istream& is, Container& v)
    { for (auto & x : v) { is >> x; } return is; }

template < typename Container, typename Value = typename Container::value_type, std::enable_if_t<!std::is_same< Container, std::string >::value, std::nullptr_t> = nullptr >
std::ostream& operator<< (std::ostream& os, Container const& v) {
os << "{";
    for (auto it = v.begin(); it != v.end(); it++)
        {os << (it != v.begin() ? "," : "") << *it;}
    return os << "}";
}

int main() {
    int N;
    cin >> N;
    vector< int > A(N);
    cin >> A;
    sort(begin(A), end(A));
    reverse(begin(A), end(A));
    ll ret = 0;
    if(N % 2 == 0) {
        for(int i = 0; i + 1 < N / 2; i++) ret += A[i];
        for(int i = 1; i < N / 2; i++) ret += A[i];
        ret += A[N / 2 - 1];
    } else {
        for(int i = 0; i < N / 2; i++) ret += A[i];
        for(int i = 1; i <= N / 2; i++) ret += A[i];
    }
    cout << ret << "\n";
}

Measured memory_bytes: 4024
var GET=(function(){function f(s){return new g(s);}function g(s){this._s=s.trim().split("\n");this._y=0;}g.prototype.a=function(f){var s=this._s, y=this._y, r;if(typeof s[y]==="string")s[y]=s[y].split(" ").reverse();r=s[y].pop();if(!s[y].length)this._y++;return f?r:+r;};g.prototype.l=function(f){var s=this._s[this._y++].split(" ");return f?s:s.map(a=>+a);};g.prototype.m=function(n,f){var r=this._s.slice(this._y,this._y+=n).map(a=>a.split(" "));return f?r:r.map(a=>a.map(a=>+a));};g.prototype.r=function(n,f){var r=this._s.slice(this._y,this._y+=n);return f?r:r.map(a=>+a);};return f;})();
var o=GET(require("fs").readFileSync("/dev/stdin","utf8"));
function xArray(v){var a=arguments,l=a.length,r="Array(a["+--l+"]).fill(0).map(x=>{return "+v+";})";while(--l)r="Array(a["+l+"]).fill(0).map(x=>"+r+")";return eval(r);}
function lower_bound(d,a,b,e){for(var c;1<b-a;)d[c=0|(a+b)/2]<e?a=c:b=c;return d[a]<e?b:a};
function segTree(n){
  var u = n-1, x = 2;
  while(u)u >>= 1, x <<= 1;
  this.seg = Array(x-1).fill(2e9);
  this.l = x >> 1;
}
segTree.prototype={
  get:function(x){
    x += this.l-1;
    var r = 2e9;
    while(x >= 0){
      if(this.seg[x] < r)r = this.seg[x];
      x = (x-1)>>1;
    }
    if(r === 2e9)r = -1;
    return r;
  },
  update:function(l,r,t){
    var v = this.seg;
    q(l,r,0,this.l,0);
    function q(l,r,x,y,i){
      if(l === x && r === y){v[i] = t;return;}
      var m = x+y >> 1;
      if(m < r)if(l < m){q(l,m,x,m,i+i+1);q(m,r,m,y,i+1<<1);}
      else q(l,r,m,y,i+1<<1);
      else q(l,r,x,m,i+i+1);
    }
  },
}
console.log(main());
function main(){
  var n = o.a();
  var q = o.a();
  var s = o.m(n);
  var d = o.r(q);
  var st = new segTree(q);
  s.sort((a,b)=>b[2]-a[2]);
  for(var i = 0; i < n; i++){
    if(s[i][1]-s[i][2]-1<d[0])continue;
    var l = lower_bound(d,0,q,s[i][0]-s[i][2]);
    var r = lower_bound(d,l,q,s[i][1]-s[i][2]);
    if(l<r)st.update(l,r,s[i][2]);
  }
  var ans = Array(q);
  for(var i = 0; i < q; i++){
    ans[i] = st.get(i);
  }
  return ans.join("\n");
}

Measured memory_bytes: 144292
n = int(input())
a = [int(i) for i in input().split()]

flag = 1
c = 0
while flag:
    flag = 0
    for i in range(1,n):
        j = n-i
        if a[j] < a[j-1]:
            a[j],a[j-1] = a[j-1],a[j]
            c += 1
            flag = 1

print(' '.join(map(str,a))) 
print(c)


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

a = list(map(str, input().split()))

ans = []
if n % 2 == 0:
    for i in range(n//2):
        ans.append(a[-(2*i+1)])
    for i in range(n//2):
        ans.append(a[2*i])
    print(' '.join(ans))
else:
    for i in range(n//2+1):
        ans.append(a[-(2*i+1)])
    for i in range(n//2):
        ans.append(a[2*i+1])
    print(' '.join(ans))

Measured memory_bytes: 104228
#include <stdio.h>

#define N 4
int main(){
  int A[N],B[N],i,j;
  while(scanf("%d %d %d %d",&A[0],&A[1],&A[2],&A[3])!=EOF){
    scanf("%d %d %d %d",&B[0],&B[1],&B[2],&B[3]);
    int cnt_hit=0,cnt_blow=0;
    for (i=0;i<N;i++){
      if (A[i]==B[i]){
        cnt_hit++;
      }
    }
    for (i=0;i<N;i++){
      for (j=0;j<N;j++){
        if (A[i]==B[j]){
          cnt_blow++;
        }
      }
    }
    printf("%d %d\n",cnt_hit,cnt_blow-cnt_hit);
  }

  return 0;
}

Measured memory_bytes: 592
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>
#include<functional>
#include<numeric>
#include<queue>
#include<stack>
#include<map>
#include<unordered_map>
#include<set>
#include<bitset>
#include<random>
#pragma region
using namespace std;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define rep(i,n) FOR(i,0LL,n)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define rrep(i,n) RFOR(i,0LL,n)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define COUNT(a,y,x) upper_bound(all(a), y) - lower_bound(all(a), x)
#define UNIQUE(a) sort(all(a)); a.erase(unique(all(a)), a.end())
#define pb push_back
typedef long long int ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<string> vs;
typedef map<ll, ll> MAP;
const ll inf = 1LL << 61;
const ll mod = 1000000007LL;
//const ll mod = 998244353LL;

ll n = 0, m = 0, ans = 0, tmp = 0, ma = -inf, mi = inf;
string s;
ll dx[9] = { 0,1,0,-1,0,1,1,-1,-1 }, dy[9] = { 0,0,1,0,-1,1,-1,1,-1 };
#define endl '\n'
#pragma endregion
#define MAX 222222






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



  cin >> n;
  ll x, y, z, ee = 1e18, e = 1e9;
  if (n == ee) {
    cout << "0 0 " << e << " 0 0 " << e << endl;
    return 0;
  }
  if (n <= e) {
    cout << "0 0 0 1 " << n << " 0" <<endl;
    return 0;
  }
  y = n / e;
  x = n % e;
  z = y + 1;
  cout << x << " 0 0 " << y << " " << e << " " << z << endl;




  return 0;
}


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

int main() {
    int n;
    cin >> n;
    vector<int> a(n * 3);
    for (int i = 0; i < n * 3; i++) {
        cin >> a.at(i);
    }

    map<int, int> left_map;
    long long left_sum = 0;
    for (int i = 0; i < n; i++) {
        left_sum += a.at(i);
        left_map[a.at(i)]++;
    }

    vector<pair<int, int>> sorted_right(n * 2);
    for (int i = 0; i < n * 2; i++) {
        sorted_right.at(i) = make_pair(a.at(n + i), n + i);
    }
    sort(sorted_right.begin(), sorted_right.end());

    vector<bool> used(n * 3, false);
    long long right_sum = 0;
    for (int i = 0; i < n; i++) {
        right_sum += sorted_right.at(i).first;
        used.at(sorted_right.at(i).second) = true;
    }
    int right_max_index = n;
    
    vector<bool> done(n * 3);
    long long ans = left_sum - right_sum;
    for (int i = n; i < n * 2; i++) {
        done.at(i) = true;
        if (used.at(i)) {
            right_sum -= a.at(i);
            
            while (done.at(sorted_right.at(right_max_index).second)) right_max_index++;
            
            right_sum += sorted_right.at(right_max_index).first;
            done.at(sorted_right.at(right_max_index).second) = true; 
            used.at(sorted_right.at(right_max_index).second) = true;
            right_max_index++;
        }

        auto ite = left_map.begin();
        if (ite -> first < a.at(i)) {
            left_sum -= ite -> first;
            left_sum += a.at(i);

            left_map[ite -> first]--;
            if (ite -> second == 0) left_map.erase(ite -> first); 
            left_map[a.at(i)]++;
        }

        ans = max(ans, left_sum - right_sum);
    }
    
    cout << ans << endl;
}   

Measured memory_bytes: 7680
#include <algorithm>
#include <iostream>
#include <queue>
#include <string>

using namespace std;

void solve(string S) {
  int a = 0;
  int b = 0;
  for (int i = 0; i < S.length(); i++) {
    if (i % 2 == 0) {
      if (S.substr(i, 1) == "0") {
        a += 1;
      }
    } else {
      if (S.substr(i, 1) != "0") {
        a += 1;
      }
    }
  }

  for (int i = 0; i < S.length(); i++) {
    if (i % 2 == 0) {
      if (S.substr(i, 1) == "1") {
        b += 1;
      }
    } else {
      if (S.substr(i, 1) != "1") {
        b += 1;
      }
    }
  }

  cout << min(a, b) << endl;
}

int main() {
  string S;
  cin >> S;
  solve(S);
  return 0;
}


Measured memory_bytes: 512
N = int(input())
K = int(input())
x = list(map(int, input().split()))

res = []
for i in range(N):
    a_cost = 2 * x[i]
    b_cost = 2 * (K - x[i])
    cost = min([a_cost, b_cost])
    res.append(cost)

print(sum(res))

Measured memory_bytes: 3060
#include <stdio.h>

int main() {
    
    int a,b;
    
    scanf("%d %d", &a, &b);
        
    if(a>b)
        printf("a > b\n");
    else if(a<b)
        printf("a < b\n");
    else if(a==b)
        printf("a == b\n");
    
    return 0;
}



Measured memory_bytes: 2100
#include "bits/stdc++.h"
using namespace std;
#define int long long
#define endl '\n'


int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr), cout.tie(nullptr);

    int n;
    cin >> n;
    map<int, int> m;
    for (int i = 1; i <= 100; i++) {
    	for (int j = 1; j <= 100; j++) {
    		for (int k = 1; k <= 100; k++) {
    			int ans = i * i + j * j + k * k + (i * j) + (i * k) + (k * j);
    			if (ans > n) continue;
    			m[ans]++;
    		}
    	}
    }
    for (int i = 1; i <= n; i++)
    	cout << m[i] << endl;
}

Measured memory_bytes: 4172
from collections import defaultdict as dd
from collections import Counter
from pprint import pprint as pp
import itertools
import functools

YN = {True: 'Yes', False: 'No'}
ri = lambda: int(input())
ria = lambda: list(map(int, input().split()))
rian = lambda n: [ria() for _ in range(n)]
rs = lambda: input()
rsa = lambda: input().split()
rsn = lambda n: [rs() for _ in range(n)]

S = rs()
print(S.count('+')-S.count('-'))

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

using i64 = long long;
using u64 = unsigned long long;

const int mod = (int) 1e9+7;

void __print() {cerr << "]\n";}

template<typename T, typename... V>
void __print(T t, V... v)
{ cerr << t; if(sizeof...(v)) cerr << ", "; __print(v...);}

#define dbg(x...) cerr << "[" << #x << "] = [", __print(x)
#define FASTIO ios_base::sync_with_stdio(false), cin.tie(NULL)

int n;
int a[51];

int f(int k)
{
    int ans = 0;
    for(int A = 0; A <= n; A++) {
        for(int B = 0; B <= n; B++) {
            if(A+B > k || A+B > n) continue;
            int sum = 0;
            vector<int> v;
            for(int i = 0; i < A; i++) {
                v.push_back(a[i]);
                sum += a[i];
            }
            for(int i = n-1; i >= n - B; i--) {
                v.push_back(a[i]);
                sum += a[i];
            }
            sort(v.rbegin(), v.rend());
            ans = max(ans, sum);
            for(int i = 0; i < k-A-B && v.size(); i++) {
                sum -= v.back();
                ans = max(ans, sum);
                v.pop_back();
            }
        }
    }
    return ans;
}

int main()
{
    int k;
    scanf("%d%d", &n, &k);
    for(int i = 0; i < n; i++) scanf("%d", &a[i]);
    int ans = 0;
    for(int i = 0; i <= k; i++) {
        ans = max(ans, f(i));
    }
    printf("%d\n", ans);
}


Measured memory_bytes: 3764
#include <iostream>
#include<string>
#include<algorithm>
using namespace std;
int main(void){
    string s;
    cin>>s;
    if(s[0]=='A'){
        cout<<'T'<<endl;
    }
    
    else if(s[0]=='T'){
        cout<<'A'<<endl;
    }
    
    else if(s[0]=='C'){
        cout<<'G'<<endl;
    }
    
    else if(s[0]=='G'){
        cout<<'C'<<endl;
    }
    
}

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

typedef long long lint;
typedef long double louble;

template<typename T1,typename T2> inline T1 max(T1 a,T2 b){return a<b?b:a;}
template<typename T1,typename T2> inline T1 min(T1 a,T2 b){return a<b?a:b;}

namespace ae86
{
	const int bufl = 1<<15;
	
	char buf[bufl],*s=buf,*t=buf;
	
	inline int fetch()
	{
		if(s==t){t=(s=buf)+fread(buf,1,bufl,stdin);if(s==t)return EOF;}
		return *s++;
	}
	
	inline int ty()
	{
		int a=0,b=1,c=fetch();
		while(!isdigit(c))b^=c=='-',c=fetch();
		while(isdigit(c))a=a*10+c-48,c=fetch();
		return b?a:-a;
	}
}
using ae86::ty;

const int _ = 100007;

struct cxk
{
	lint l,r,bas,val;
	cxk(lint _l=0,lint _r=0,lint _bas=0,lint _val=0){l=_l,r=_r,bas=_bas,val=_val;}
	inline friend int operator < (cxk a,cxk b){return a.val>b.val;}
}p[_];

int n;lint lim;

int main()
{
	n=ty(),lim=ty();

	lint riva=0;
	for(int i=1;i<=n;i++)
	{
		lint b=ty(),l=ty(),r=ty();
		riva+=b*l,p[i]=cxk(l,r,b,b*l+r*(lim-b));
	}

	sort(p+1,p+n+1);

	lint taka=0,ans=0;int loc=0;
	for(int i=1;i<=n;i++)
	{
		if(taka+p[i].val>=riva){loc=i-1;break;}
		taka+=p[i].val,ans+=lim;
	}
	
	lint sans=ans+lim;
	for(int i=1;i<=n;i++)
	{
		lint sval=taka;
		if(i<=loc)sval-=p[i].val,sval+=p[loc+1].val;
		lint l=0,r=lim,ret=lim+1;
		while(r>=l)
		{
			lint mid=(l+r)>>1,dlt=0;
			if(mid<=p[i].bas)dlt=p[i].l*mid;
			else dlt=(p[i].l-p[i].r)*p[i].bas+p[i].r*mid;
			if(sval+dlt>=riva)ret=mid,r=mid-1;
			else l=mid+1;
		}
		if(ret<=lim)sans=min(sans,ans+ret);
	}

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

	return 0;
}


Measured memory_bytes: 3456
#include <iostream>
#include <cstdio>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#define mem(a,b) memset(a,b,sizeof(a))
#define IOSF ios::sync_with_stdio(false)
typedef long long LL;
using namespace std;
const int INF=0x3f3f3f3f;
const int MAX=10e6+5;
const int MOD=10e9+7;

char wa[100][100];

int main()
{
    IOSF;
    int H,W;
    mem(wa,0);
    cin>>H>>W;
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            cin>>wa[i][j];
        }
    }
    int flag=0;
    for(int i=1;i<H;i++){
        for(int j=1;j<W;j++){
            if(wa[i][j]=='#'){
                if(wa[i-1][j]!='#'&&wa[i+1][j]!='#'&&wa[i][j-1]!='#'&&wa[i][j+1]!='#'){
                    cout<<"No"<<endl;
                    flag=1;
                    i=H;j=W;
                }
            }
        }
    }
    if(flag==0)
        cout<<"Yes"<<endl;
    return 0;
}
/*
7 5 3
*****
*...*
*****
*..**
*****
*.***
*****
4 4 0
****
*...
*.**
*.**
*/



Measured memory_bytes: 256
def check(n):
    i = 1
    while n > 0:
        n -= i
        if n == 0:
            return i
        i += 1
    return 0


N = int(input())
K = check(N)
if K == 0:
    print("No")
    exit()

print("Yes")
print(K + 1)
ans = [[] for _ in range(K + 1)]
cur = 0
nxt = K
for k in range(K):
    ans[k] += range(cur + 1, cur + K - k + 1)
    for i in range(K - k):
        ans[i + k + 1].append(i + cur + 1)
    cur += nxt
    nxt -= 1

[print(K, *row) for row in ans]


Measured memory_bytes: 17164
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define pf push_front
#define mod 1000000007
#define endl '\n'
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);


int main()
{
    ll n,i;
    cin>>n;
    ll x=1;
    for(i=2;i<=sqrt(n); i++)
    {
        if(n%i==0)
        {
            x=i;
        }
    }
    ll ans = x+(n/x)-2;
    cout<<ans<<endl;
}


Measured memory_bytes: 256
mod = 10 ** 9 + 7

n = int(input())
s = input()
a = ord('a')

counter = {chr(a + i): 0 for i in range(26)}

for c in s:
  counter[c] += 1
  
result = 1
for v in counter.values():
  result = result * (v + 1) % mod
print(result - 1)

Measured memory_bytes: 3188
#include<iostream>
#include<vector>
#include<algorithm>
typedef long long int llint;
using namespace std;
int main() {
	int n, a, b;
	cin >> n >> a >> b;
	vector<int>x(n);
	for (int i = 0;i < n;i++) {
		cin >> x[i];
	}
	sort(x.begin(), x.end());
	int x1 = 0, x2 = 0, x3 = 0;
	for (int i = 0;i < n;i++) {
		if (x[i] <= a) {
			x1++;
		}
		else if (x[i] <= b) {
			x2++;
		}
		else {
			x3++;
		}
	}
	if (x1 < x2) {
		x2 = x1;
	}
	if (x2 < x3) {
		x3 = x2;
	}
	cout << x3 << endl;
	return 0;
}

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

using namespace std;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	int n; cin >> n;
	
	long long a=1,b=1;
	while(n--){
		int s,t; cin >> s >> t;
		long long fac = max((a+s-1)/s, (b+t-1)/t);
		a=s*fac;
		b=t*fac;
	}
	
	cout << a+b << endl;
	return 0;
}

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

#define ll long long

using namespace std;

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

    int ans = 0;
    int curr_min = INT_MAX;

    for (int i = -100; i <= 100; i++) {
        int curr = 0;
        for (int j = 0; j < n; j++) {
            curr += (arr[j] - i) * (arr[j] - i);
        }

        if (curr < curr_min) {
            curr_min = curr;
            ans = curr;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
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 (b<a) { a=b; return 1; } return 0; }

using ll = long long;

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int INF = 1<<30;
const ll mod = 1000000007LL;

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

    else {
        return gcd(y, x % y);
    }
}

int main() {
    int T;
    cin>>T;
    for(int i = 0; i < T; i++){
        ll A,B,C,D;
        cin>>A>>B>>C>>D;
        bool can;
        if(D<B) can = false;
      	else if(A<B) can = false;
        else if(A%B>C) can = false;
        else if(C>=B) can = true;
        else {
            ll E = A%B;
            ll F = gcd(B,D);
            if((B-E-1)/F!=(C-E)/F) can = false;
            else can = true;
        }
        if(can) cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
    }
}

Measured memory_bytes: 3576
temp = input()
s = temp.count("S")
n = temp.count("N")
e = temp.count("E")
w = temp.count("W")

if (s == n):
 if (e>=1 & w >= 1):
  print ("Yes")
 else:
  print ("No")
elif (e == w):
 if (s >= 1 & n >= 1):
  print ("Yes")
 else:
  print ("No")
else:
 print ("No")

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ll, pair<ll, ll> > P3;

const ll MOD = ll(1e9 + 7);
const ll LLINF = LLONG_MAX;
const int IINF = INT_MAX;
const int MAX_N = int(2e5) + 5;
const int MAX_A = int(15e6);
const double EPS = 1e-8;
const int di[] = {0, 1, 0, -1}, dj[] = {1, 0, -1, 0};
string dir = "RDLU";
#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 SORT(v) sort((v).begin(), (v).end())
#define SORTR(v) sort((v).rbegin(), (v).rend())
#define ALL(v) (v).begin(), (v).end()

int extgcd(int a, int b, int &x, int &y){
    if(b==0){
        x = 1;
        y = 0;
        return a;
    }
    else{
        int d = extgcd(b, a%b, y, x);
        y -= (a/b)*x;
        return d;
    }
}


int main() {
    int a, b, x, y;
    cin >> a >> b;
    extgcd(a,b,x,y);
    cout << x << " " << y << endl;
    return 0;
}



Measured memory_bytes: 3208
//2017.11.18
//YES,NOを小文字で書いてWA

#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
	string a,b,huk;
	cin >> a;
  cin >> b;
  int len;
  len = a.length();
  for(int i=len-1; i>=0; i--){huk=huk+a.at(i);}


  if(huk==b) cout << "YES" << endl;
  else cout << "NO" << endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
void ABC130(void);
void ABC131(void);
void ABC132(void);
void ABC133(void);
void ABC134(void);
void ABC135(void);
void ABC136(void);
void ABC137(void);
void ABC138(void);
void ABC139(void);

int main(void){
    ABC132();
}

void ABC132(){
    string s;
    char n;
    int i,k=0,b=0;
    cin>>s;
    n=s[0];
    for(i=1;i<=3;++i){
        if(s[i]==s[0])++k;
        else if(s[i]!=n){
            n=s[i];
            ++b;
        }
    }
    if(k==1&&b==1)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**7)

readline = sys.stdin.buffer.readline
def readstr():return readline().rstrip().decode()
def readstrs():return list(readline().decode().split())
def readint():return int(readline())
def readints():return list(map(int,readline().split()))
def printrows(x):print('\n'.join(map(str,x)))
def printline(x):print(' '.join(map(str,x)))

n = readint()

ans = n*(n+1)*(n+2)//6

for i in range(n-1):
    x = readints()
    x.sort()
    ans -= x[0]*(n-x[1]+1)

print(ans)

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

	char in[7010];
	main(){
		char *p = in;
		int res,prev,r=0,max=0;
		cin >> in;
		while(*p){
			int t = (*p == 'c');
			if(prev == t) r=0;
			r++;
			prev = t;
			if(max < r){
				max = r;
				res = t;
			}
			p+=t?7:3;
		}
		cout << ((res) ? "chicken" : "egg") << endl;
	}

Measured memory_bytes: 1144
//---------------------------------------------------------------
#include <bits/stdc++.h>
using namespace std;
#include <iostream>
#include <vector>
#include <cstdlib>
#include <cmath>
#include <math.h>
#include <sstream>
#include <numeric>
#include <cctype>
#include <bitset>
#include <cassert>
#include<algorithm>
//---------------------------------------------------------------
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define SIZE 100005
#define INF 1000000000000000LL
#define all(x) x.begin(),x.end()
#define fi first
#define se second
using pint = pair<int,int>;
using vec = vector<int>;
using ll=long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
//---------------------------------------------------------------
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
//---------------------------------------------------------------

//↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓


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



    ll n,m;cin>>n>>m;
    vll x(m);
    rep(i,m) cin>>x[i];
    if(m==1 || n>=m){
      cout<<0<<endl;
      return 0;
    }    
    sort(all(x));
    vll l(m-1);
    rep(i,m-1){
      l[i] = abs(x[i+1] - x[i]);
    }

    ll ans=0;
    rep(i,m-1) ans+=l[i];

    sort(all(l), greater<ll> ());

    rep(i,n-1){
      ans-=l[i];
      if(ans<=0){
        cout<<ans<<endl;
        return 0;
      }
    }

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

Measured memory_bytes: 4608
/*
* Filename:    aoj0525.cpp
* Desciption:  Desciption
* Created:     2016-03-10
* Author:      JIngwei Xu [mail:xu_jingwei@outlook.com]
*
*/
#include<bitset>
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<cstring>
#define INT_MAX 1<<30
using namespace std;
typedef long long ll;
const int INF=0x7F;
int n,m,ans;
bitset<10000> bits[10];
int check(){
	int ct=0,rec=0;
	for (int i = 0; i < m; i += 1)
	{
		ct=0;
		for (int j = 0; j < n; j += 1)
		{
			if(bits[j][i]==1)ct++;
		}
		ct=max(ct,n-ct);
		rec+=ct;
	}
	return rec;
}
void dfs(int k){
	if (k==n)
	{
		ans=max(ans,check());
		return;
	}
	for (int i = 0; i < 2; i += 1)
	{
		bits[k].flip();
		dfs(k+1);
	}
}
int main()
{
//ios_base::sync_with_stdio(0);
#ifdef JIngwei_Xu
	freopen("data.in","r",stdin);
	freopen("data.out","w",stdout);
#endif
	while (scanf("%d%d",&n,&m)&&n&&m)
	{
		int t;
		ans=0;
		for (int i = 0; i < n; i += 1)
		{
			for (int j = 0; j < m; j += 1)
			{
				scanf("%d",&t);
				bits[i][j]=t;
			}
		}
		dfs(0);
		printf("%d\n",ans);
	}
	return 0;
}

Measured memory_bytes: 1200
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <limits>

using namespace std;
typedef long long int ll;
void sayYes() { cout << "Yes" << endl; };
void sayNo() { cout << "No" << endl; };
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }                   // 最大公約数
ll lcm(ll a, ll b) { return a * b / gcd(a, b); };                      // 最小公倍数
ll getDigit(ll num) { return log10(num) + 1; }                         // 桁数
ll digitSum(ll n) { return (n < 10) ? n : digitSum(n / 10) + n % 10; } // 各桁の和
#define rep(i, n) for (ll i = 0; i < n; i++)

void Main()
{
    // int n;
    // cin >> n;
    // vector<int> a(n);
    // rep(i, n)
    // {
    //     cin >> a[i];
    // }

    // int ans = 0;

    int a, b, c, d;
    cin >> a >> b >> c >> d;

    while (1)
    {
        c -= b;
        if (c <= 0)
        {
            sayYes();
            return;
        }

        a -= d;
        if (a <= 0)
        {
            sayNo();
            return;
        }
    }

    // cout << ans << endl;
    return;
}

signed main(void)
{
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll inf = 12345678999999;
const ll wall = -12345678;
bool agct(string s)
{
	for(int i=0;i<s.size();i++)
	{
		if(s[i]!='A'&&s[i] != 'C'&&s[i]!='G'&&s[i]!='T')
			return false;
	}
	return true;
}
int main()
{
	string s;
	cin>>s;
	ll ma = wall;
	for(int i=0;i<=s.size();i++)
	{
		for(int pos = 0;pos<s.size();pos++)
		{
			string h = s.substr(pos,i);
			ll sz = h.size();
			if(agct(h))
				ma = max(ma,sz);
		}
	}
	cout<<ma<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,d,x;cin>>n>>d>>x;
  int total=0;
  for(int i=0,a;i<n;i++){
  	cin>>a;
    for(int j=0;(j*a+1)<=d;j++)total+=1;
  }
  cout<<total+x;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
long long N;
long long w;
long long W[101];
long long V[101];
long long a[5];
int main(void)
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    memset(a,0,sizeof(a));
    vector<int>v[4];
    cin>>N>>w;
    cin>>W[0]>>V[0];
    a[0]=1;
    v[0].push_back(V[0]);
    for(long long i=1;i<N;++i)
    {
        cin>>W[i]>>V[i];
        ++a[W[i]-W[0]];
        v[W[i]-W[0]].push_back(V[i]);
    }
    for(int i=0;i<4;++i)
    {
        sort(v[i].begin(),v[i].end(),greater<int>());
    }

    long long temp=0;
    long long ans=0;
    for(long long i=0;i<=a[0];++i)
    {
        for(long long j=0;j<=a[1];++j)
        {
            for(long long k=0;k<=a[2];++k)
            {
                for(long long s=0;s<=a[3];++s)
                {
                    temp=W[0]*i+(W[0]+1)*j+(W[0]+2)*k+(W[0]+3)*s;
                    if(temp<=w)
                    {
                        long long val=0;
                        for(int cnt=0;cnt<i;cnt++)
                        {
                            val+=v[0][cnt];
                        }
                        for(int cnt=0;cnt<j;cnt++)
                        {
                            val+=v[1][cnt];
                        }
                        for(int cnt=0;cnt<k;cnt++)
                        {
                            val+=v[2][cnt];
                        }
                        for(int cnt=0;cnt<s;cnt++)
                        {
                            val+=v[3][cnt];
                        }
                        ans=max(ans,val);
                    }
                    else
                    {
                        break;
                    }
                }
            }
        }
    }
    cout <<ans <<endl;
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<queue>
#include<utility>
#include<cstring>
#include<stack>
#include<algorithm>
#include<cmath>
#include<iostream>
#define MAX_N 100001
#define INF 2147483647
#define REP(i,n) for(int i=0;i<(int)(n);i++)
void init(int n);
int find(int n);
void unite(int x,int y);
bool same(int x, int y);
int dx[4] = {1,0,0,-1};
int dy[4] = {0,1,-1,0};
using namespace std;

struct edge{
  int from,to,cost;
};
typedef vector<vector<edge> > AdjList;
AdjList graph;
typedef pair<int , int> P;
bool comp(const edge& e1, const edge& e2){
  return e1.cost < e2.cost;
}
int E,V;
edge es[100001];
int kruskal(){
  sort(es,es+E,comp);
  init(V);
  int res = 0;
  for(int i=0;i<E;i++){
    edge e = es[i];
    if(!same(e.to,e.from)){
      unite(e.to,e.from);
      res += e.cost;
    }
  }
  return res;
}


int main()
{
  int co=0,dp[1001][1001];
  dp[0][0] = 0;
  dp[0][1] = 0;
  dp[1][0] = 0;
  string x,y;
  cin >> co;
  REP(i,co){
    cin >> x;
    cin >> y;
    REP(i,x.length()+1)REP(j,y.length()+1){
      if(i == 0 || j == 0)
        dp[i][j] = 0;
      else{
      if(x[i-1] == y[j-1]){
        dp[i][j] = dp[i-1][j-1]+1;
        }else{
        dp[i][j] = max(dp[i-1][j],dp[i][j-1]);
      }
      }
      
    }
    cout << dp[x.length()][y.length()] << endl;
  }
  return 0;
}

int par[MAX_N];
int ranks[MAX_N];

//n要素で初期化
void init(int n){
  REP(i,n){
    par[i] = i;
    ranks[i] = 0;
  }

}

//木の根を求める
int find(int x){
  if(par[x] == x){
    return x;
  }else{
    return par[x] = find(par[x]);
  }
}

void unite(int x,int y){
  x = find(x);
  y = find(y);
  if(x == y) return ;
  if(ranks[x] < ranks[y]){
    par[x] = y;
  }else{
    par[y] = x;
    if(ranks[x] == ranks[y]) ranks[x]++;
  }
}

bool same(int x, int y){
  return find(x) == find(y);
}




Measured memory_bytes: 7144
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string s;
  cin >> s;
  
if(s.at(0)==s.at(1) && s.at(0)==s.at(2) &&s.at(1)==s.at(2)){
  cout << "No" << endl;
}
  else{
    cout << "Yes" << endl;
  }
  
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#define ll long long
#define fi first
#define se second
#define pb push_back
#define me memset
const int N = 1e6 + 10;
const int mod = 1e9 + 7;
using namespace std;
typedef pair<int,int> PII;
typedef pair<long,long> PLL;

ll n,k;

int main() {
    ios::sync_with_stdio(false);
    cin>>n>>k;
     if(n%k==0){
         printf("0\n");
     }
     else{
         ll res=n/k;
         printf("%lld\n",min(n-res*k,k-(n-res*k)));
     }




    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

typedef long long ll;

#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define per(i,a,b) for(ll i=b-1LL;i>=(a);--i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define print(x) cout<<#x<<" = "<<x<<endl;

#define MOD 1000000007

int main() {
  ll a,b;
  cin>>a>>b;
  if(a>9||b>9){
    cout << -1 << endl;
  }
  else{
    cout << a*b << endl;
  }
  return 0;
}

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

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

  vector<int> vec(N);
  for (int i = 0; i < N; i++) {
    cin >> vec.at(i);
  }

  int count = 0;

  for (int i = 1; i <= N; i++) {
    if (i % 2 == 1 && vec.at(i - 1) % 2 == 1) {
      count++;
    }
  }

  cout << count << endl;
}


Measured memory_bytes: 3480
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;

int main() {
    int l, r, ans = 10000;
    cin >> l >> r;
    int a = l%2019;
    int b = r%2019;
    
    if( (r-l) >= 2019) {
        cout << 0;
        cout << endl;
        return 0;
    }
    else if(a >= b){
        cout << 0;
        cout << endl;
        return 0;
    }
    else {
        for(int i = a; i <= b-1; i++) {
            for(int j = i+1; j <= b; j++) {
                ans = min(ans, (i*j)%2019);
            }
        }
    }

    cout << ans;

    cout << endl;
    return 0;
}

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

int compare_int(const void *a, const void *b)
{
    return *(int*)a - *(int*)b;
}

int main(void)
{
    int N, i, j, tmp;
    int A[200001];
    long long int B[200002];//2個以上の時に0、そうでない時に1
    int A_sort[200001];
    long long int sum=0, sum_tmp;

    scanf("%d",&N);

    for(i=0; i<N; i++){
        scanf("%d",&A[i]);
        A_sort[i] = A[i];
    }

    for(i=0; i<200002; i++){
        B[i] = 1;
    }

    
    qsort(A_sort,N,sizeof(int),compare_int);
    //何個並んでるかのカウントをする
    for(i=0; i<N-1; i++){
        tmp = A_sort[i];
        if(A_sort[i] == A_sort[i+1]){
            B[tmp]++;
        }
    }

    //sumの計算
    for(i=0; i<N; i++){
        sum += (B[i+1]*(B[i+1]-1))/2;
    }


    //出力
    for(i=0; i<N; i++){
        sum_tmp = sum;
        tmp = A[i];
        if(B[tmp] == 1){
            printf("%lld\n",sum);
        } else {
            sum_tmp -= (B[tmp]*(B[tmp]-1))/2;
            sum_tmp += ((B[tmp]-1)*(B[tmp]-2))/2;
            printf("%lld\n",sum_tmp);
        }
    }

    return 0;
}

Measured memory_bytes: 5612
import sys

stdin = sys.stdin
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip() # ignore trailing spaces

def main():
    ta,aa,tb,ab = na()
    cnta = (tb-1)//aa + 1
    cntb = (ta - 1)//ab +1
    if cnta <= cntb:
        print("Yes")
    else:
        print("No")
    return

if __name__ == '__main__':
  main()

Measured memory_bytes: 61720
//#define _GLIBCXX_DEBUG

#include<bits/stdc++.h>
#define PI 3.14159265359
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const int INF= 1e9+5;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int> >vvi;
const ll MOD=1000000007LL;
ll factorial(ll x){
  if(x==0)return 1;
  return x*factorial(x-1);
}


ll comb(ll n, ll r){
  ll res=1;
    for(ll i=0;i<r;i++){
      res*=n-i;
      //res%=MOD;
    }
  res/=factorial(r);
  //res%=MOD;
  return res;
}
int main(){
  ll n;
  cin>>n;
  vector<ll>a(n);
  rep(i,n)cin>>a[i];
  vector<ll>sum(n);
  sum[0]=a[0];
  ll ans=0;
  if(a[0]==0)ans++;
  for(int i=1;i<n;i++){
    sum[i]=sum[i-1]+a[i];
    if(sum[i]==0)ans++;
  }
  map<ll,ll>m;
  rep(i,n){
    m[sum[i]]++;
  }
  for(auto p:m){
    ans+=comb(p.second,2);
  }
  cout<<ans<<endl;
}

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

int main() {
  int s;
  cin >> s;
  set<int> st;
  int x = s;
  while(st.count(x)==0){
    st.insert(x);
    if(x%2==0){
      x/=2;
    }
    else{
      x=3*x+1;
    }
  } 
  cout << (st.size()+1) << endl;
  return 0;
}

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

#define int long long
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rep1(i,n) for(int i=1;i<=(int)(n);++i)
#define rep11(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define repm(i,n) for(int i=(int)(n)-1;i>=0;--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)
#define mp make_pair
#define MOD 1000000007
#define INF 9223372036854775807

struct UnionFind {
#define MAX 100001
    int ElementCount[MAX],Adress[MAX];
    void Init() {rep(i,MAX) ElementCount[i] = 1,Adress[i] = i;}
    void unite(int a ,int b) {
        int a_root = find(a),b_root = find(b);
        if (a_root != b_root) {
            ElementCount[a_root] += ElementCount[b_root];
            Adress[b_root] = a_root;
        }
    }
    int find(int a) {
        if (a == Adress[a]) return Adress[a];
        else {
            Adress[a] = find(Adress[a]);
            return Adress[a];
        }
    }
    int size(int a) {
        int root = find(a);
        return ElementCount[root];
    }
    /*
     * ElementCount : 属するグループの要素数
     * Adress : rootの番号
     * unite : 併合
     * find : aのrootを返す
     * size : aのrootのElementCountを返す
     * */
};

int n,m,p[100000],x,y,ans;
UnionFind UF;

signed main() {
    UF.Init();
    cin >> n >> m;ans=n;
    rep(i,n) cin >> p[i];
    rep(i,m) cin >> x >> y, UF.unite(x,y);
    rep(i,n) if (UF.find(i+1) != UF.find(p[i])) ans--;
    cout << ans << endl;
}


Measured memory_bytes: 2560
import sys
from math import factorial
from collections import Counter
from fractions import Fraction
import heapq, bisect, fractions
import math
import itertools
sys.setrecursionlimit(10 ** 5 + 10)
INF = 10**15 +5
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))

N = INT()
S = input()
r = S.count('R')
g = S.count('G')
b = S.count('B')
res = r*g*b
for i in range(len(S)-2):
    for j in range(i+1, len(S)-1):
        if 2*j-i < len(S):
            if S[2*j-i] != S[j] and S[2*j-i] != S[i] and S[i] != S[j]:
                res -= 1

print(res)

Measured memory_bytes: 90888
#include <bits/stdc++.h>
using namespace std;
int h, w;
char a[1010][1010];

int move_x[4] = {1, -1, 0, 0};
int move_y[4] = {0, 0, 1, -1};
int memo[1010][1010] = {};

bool isOK(int y, int x){
    return 0 <= y && y < h && 0 <= x && x < w && memo[y][x] == -1;
}

int main(){
    cin >> h >> w;
    queue<pair<int, pair<int, int> > > que;
    for(int i = 0;i < h;i++){
        cin >> a[i];
        for(int j = 0;j < w;j++){
            if(a[i][j] == '#'){
                que.push(make_pair(0, make_pair(i, j)));
            }
        }
    }

    memset(memo, -1, sizeof(memo));

    while(!que.empty()){
        int x = que.front().second.second;
        int y = que.front().second.first;
        int cost = que.front().first;
        que.pop();
        if(!isOK(y, x)){
            continue;
        }
        memo[y][x] = cost;

        cost++;
        for(int i = 0;i < 4;i++){
            int nx = x + move_x[i];
            int ny = y + move_y[i];
            que.push(make_pair(cost, make_pair(ny, nx)));
        }
    }

    int ans = 0;
    for(int i = 0;i < h;i++){
        for(int j = 0;j < w;j++){
            ans = max(ans, memo[i][j]);
        }
    }

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


Measured memory_bytes: 53576
#include <stdio.h>

int main( void ) {
	int i, j, tmp, cnt, nData, data[ 100 ];

	while ( scanf( "%d", &nData ), nData ) {
		for ( i = 0; i < nData; i++ )
			scanf( "%d", data + i );

		cnt = 0;
		for ( i = 0; i < nData - 1; i++ )
			for ( j = nData - 1; j > i; j-- )
				if ( data[ j - 1 ] > data[ j ] ) {
					tmp = data[ j - 1 ];
					data[ j - 1 ] = data[ j ];
					data[ j ] = tmp;

					cnt++;
				}

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

	return 0;
}

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

#define INF 999999999
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; i++)
#define all(v) v.begin(), v.end()
#define pb push_back
#ifdef LOCAL
  #define de(e) cout << "L" << __LINE__ << ": " << e << "\n" // debug echo
  #define dr(e) cout << "L" << __LINE__ << ": " << #e << " -> " << e << "\n" // debug repr
#else
  #define de(e)
  #define dr(e)
#endif
#define out(...) cout << __VA_ARGS__ << endl
int gcd(int m, int n) { if((0 == m) || (0 == n)){return 0;} while(m != n){ if(m > n){m -= n;}else{n -= m;} } return m; }
int lcm(int m, int n) { if((0 == m) || (0 == n)){return 0;} return (m / gcd(m, n)) * n; }

//
// Implementation
//

int N;
int Y;

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

  for (int x = 0; x <= (int)(Y / 10000); x++) {
    for (int y = 0; y <= (int)(Y / 5000); y++) {
      int z = N - (x + y);
      if (z < 0) continue;
      if (x+y+z == N && x*10000 + y*5000 + z*1000 == Y) {
        out(x << " " << y << " " << z);
        return 0;
      }
    }
  }

  out("-1 -1 -1");
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cstring>
#define REP(i, n) for (int i = 0; i < (n); i++)
#define REPR(i, n) for (int i = (int)(n) - 1; i >= 0; i--)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define FORR(i, a, b) for (int i = (int)(b) - 1; i >= (a); i--)

using namespace std;

int main() {
  int H, W, N;
  cin >> H >> W >> N;
  int sy, sx;
  cin >> sy >> sx;
  string S, T;
  cin >> S >> T;
  int t = 0, b = H + 1, l = 0, r = W + 1;
  REPR(i, N) {
    if (T[i] == 'U') b = min(H + 1, b + 1);
    if (T[i] == 'D') t = max(0, t - 1);
    if (T[i] == 'L') r = min(W + 1, r + 1);
    if (T[i] == 'R') l = max(0, l - 1);
    if (S[i] == 'U') t++;
    if (S[i] == 'D') b--;
    if (S[i] == 'L') l++;
    if (S[i] == 'R') r--;
    if (t >= b - 1 || l >= r - 1) break;
  }
  if (sy <= t || b <= sy || sx <= l || r <= sx) {
    cout << "NO" << '\n';
  } else {
    cout << "YES" << '\n';
  }
}


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

using namespace std;

int main() {
  string s; cin >> s;
  int l = stoi(s.substr(0, 2));
  int r = stoi(s.substr(2));
  bool yymm = r >= 1 && r <= 12;
  bool mmyy = l >= 1 && l <= 12;
  if (yymm && mmyy) {
    cout << "AMBIGUOUS\n";
  } else if (yymm) {
    cout << "YYMM\n";
  } else if (mmyy) {
    cout << "MMYY\n";
  } else {
    cout << "NA\n";
  }
}


Measured memory_bytes: 256