akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
//typedef vector<vector<ll>> Graph;

const ll mod = 1e9 + 7;
//const ll mod = 998244353;

#define REP(i,n) for(ll i=0;i<(ll)n;i++)
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define spa << " " <<
#define fi first
#define se second

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 S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}

template<typename T> void debug(vector<vector<T>>&v,ll h,ll w){for(ll i=0;i<h;i++)
{cerr<<v[i][0];for(ll j=1;j<w;j++)cerr spa v[i][j];cerr<<endl;}};
template<typename T> void debug(vector<T>&v,ll n){if(n!=0)cerr<<v[0];
for(ll i=1;i<n;i++)cerr spa v[i];
cerr<<endl;};

string num2bit(ll num, ll len){
    string bit = "";
    REP(i, len){
    bit += char('0'+(num>>i & 1));
    }
    return bit;
}

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

    ll X, N;
    cin >> X >> N;
    vector<ll> p(N);
    REP(i, N) cin >> p[i];

    set<ll> st;
    REP(i, N) st.insert(p[i]);

    ll x = 0;
    while(1){
        if(st.find(X-x) == st.end()){
            cout << X-x << endl;
            return 0;
        }
        if(st.find(X+x) == st.end()){
            cout << X+x << endl;
            return 0;
        }
        x++;
    }

    

    return 0;
}

Measured memory_bytes: 3664
module mod_queue

  type t_node
    integer(8) :: item
    type(t_node), pointer :: prev => null()
    type(t_node), pointer :: next => null()
  end type t_node

  type t_queue
    integer(8) :: num = 0
    type(t_node), pointer :: head => null()
    type(t_node), pointer :: tail => null()
  end type t_queue

contains

  function new_node(item) result(node)
    implicit none
    integer(8), intent(in) :: item
    type(t_node), pointer :: node

    allocate(node)
    node%item = item
    return
  end function new_node

  subroutine enqueue(queue,item)
    implicit none
    type(t_queue), intent(inout) :: queue
    integer(8), intent(in) :: item
    type(t_node), pointer :: node

    node => new_node(item)
    if (associated(queue%head)) then
      node%prev => queue%tail
      queue%tail%next => node
    else
      queue%head => node
    end if
    queue%tail => node
    queue%num = queue%num+1
    return
  end subroutine enqueue

  function dequeue(queue) result(item)
    implicit none
    type(t_queue), intent(inout) :: queue
    integer(8) :: item
    type(t_node), pointer :: node

    item = queue%head%item
    node => queue%head%next
    deallocate(queue%head)
    queue%head => node
    if (associated(node)) then
      node%prev => null()
    else
      queue%tail => null()
    end if
    queue%num = queue%num-1
    return
  end function dequeue

end module mod_queue

program main
  use mod_queue
  implicit none
  integer(8) ::  K, i, tmp
  type(t_queue) :: queue
  read(*,*) K
  do i = 1,9
     call enqueue(queue,i)
  end do
  do i = 1,K
     tmp=dequeue(queue)
     if ( mod(tmp,10) /=0 ) then
        call enqueue(queue,10*tmp+mod(tmp,10) -1 )
     end if
     call enqueue(queue,10*tmp+mod(tmp,10)  )
     if ( mod(tmp,10) /= 9 ) then
        call enqueue(queue,10*tmp+mod(tmp,10)+1  )
     end if
  end do
  write(*,'(i0)') tmp
end program main
  

Measured memory_bytes: 8672
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using static System.Console;
using static System.Convert;
using static System.Math;
using static Extentions;

class IO
{
    int idx;
    string[] input = In.ReadToEnd().Split(new[] { " ", "\n", "\r" },
        StringSplitOptions.RemoveEmptyEntries);

    T Get<T>(Func<string, T> parser) => parser(input[idx++]);

    public string S => Get(s => s);
    public char C => Get(char.Parse);
    public int I => Get(int.Parse);
    public long L => Get(long.Parse);
    public double F => Get(double.Parse);
    public decimal D => Get(decimal.Parse);
    public BigInteger B => Get(BigInteger.Parse);

    T[] Gets<T>(int n, Func<string, T> parser)
        => input.Skip((idx += n) - n).Take(n).Select(parser).ToArray();

    public string[] Ss(int n) => Gets(n, s => s);
    public char[] Cs(int n) => Gets(n, char.Parse);
    public int[] Is(int n) => Gets(n, int.Parse);
    public long[] Ls(int n) => Gets(n, long.Parse);
    public double[] Fs(int n) => Gets(n, double.Parse);
    public decimal[] Ds(int n) => Gets(n, decimal.Parse);
    public BigInteger[] Bs(int n) => Gets(n, BigInteger.Parse);

    public void Write<T>(params T[] xs) => WriteLine(string.Join(" ", xs));
    public void Write(params object[] xs) => WriteLine(string.Join(" ", xs));
}

#region Library

static class Extentions
{
}

#endregion

static class Program
{
    public static void Main()
    {
        var sw = new StreamWriter(OpenStandardOutput()) { NewLine = "\n" };
#if DEBUG
        sw.AutoFlush = true;
#else
        sw.AutoFlush = false;
#endif
        SetOut(sw);
        Solve(new IO());
        Out.Flush();
    }

    static void Solve(IO io)
    {
        var n = io.I;
        var m = io.I;

        io.Write((n - 1) * (m - 1));
    }
}

Measured memory_bytes: 11220
//
//  soundhound2018d.cpp
//  
//
//  Created by Yoshida Satoshi on 2018/11/08.
//

#include <stdio.h>
#include <iostream>
#include <queue>
#include <utility>
#include <vector>

#define MAX 100010
#define INF 10000000000000000

typedef long long ll;

#define P make_pair<ll,ll>

using namespace std;

struct path
{
    ll v,a,b;
};

int main()
{
    int n,m,s,t;
    vector<path> p[MAX];
    
    cin>>n>>m>>s>>t;
    s--;t--;
    for(ll i=0;i<m;i++)
    {
        ll u,v,a,b;
        cin>>u>>v>>a>>b;
        u--;v--;
        p[u].push_back({v,a,b});
        p[v].push_back({u,a,b});
    }
    
    ll da[MAX],db[MAX];
    priority_queue<pair<ll,ll> ,vector<pair<ll,ll> > , greater<pair<ll,ll> > > pa;
    priority_queue<pair<ll,ll> ,vector<pair<ll,ll> > , greater<pair<ll,ll> > > pb;
    
    for(ll i=0;i<n;i++)
    {
        da[i]=db[i]=INF;
    }
    
    pa.push(P(0ll,s));
    pb.push(P(0ll,t));
    
    while(!pa.empty())
    {
        pair<ll,ll> x=pa.top();
        pa.pop();
        ll c=x.first;
        ll y=x.second;
        if(da[y]<c) continue;
        
        da[y]=c;
        
        for(ll i=0;i<p[y].size();i++)
        {
            int vv=p[y][i].v;
            ll a=p[y][i].a;
            if(c+a<da[vv])
            {
                da[vv]=c+a;
                pa.push(P (c+a,vv));
            }
        }
    }
    
    while(!pb.empty())
    {
        pair<ll,ll> x=pb.top();
        pb.pop();
        ll c=x.first;
        ll y=x.second;
        if(db[y]<c) continue;
        
        db[y]=c;
        
        for(ll i=0;i<p[y].size();i++)
        {
            int vv=p[y][i].v;
            ll b=p[y][i].b;
            
            if(c+b<db[vv])
            {
                db[vv]=c+b;
                pb.push(P (c+b,vv));
            }
        }
    }
    
    ll ans[MAX];
    ans[n]=INF;
    
    for(int i=n-1;i>=0;i--)
    {
        ans[i]=min(ans[i+1],da[i]+db[i]);
    }
    
    for(int i=0;i<n;i++) cout<<1000000000000000-ans[i]<<endl;
    
    
    return 0;
}


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

int happy(int N,int a[],int b[],int c[])
{
	int ans[N][3];
	ans[0][0]=a[0];
	ans[0][1]=b[0];
	ans[0][2]=c[0];
	ans[1][0]=max(ans[0][1]+a[1],ans[0][2]+a[1]);
	ans[1][1]=max(ans[0][2]+b[1],ans[0][0]+b[1]);
	ans[1][2]=max(ans[0][1]+c[1],ans[0][0]+c[1]);
	for(int i=2;i<N;i++)
	{
		ans[i][0]=max(ans[i-1][1]+a[i],ans[i-1][2]+a[i]);
		ans[i][1]=max(ans[i-1][0]+b[i],ans[i-1][2]+b[i]);
		ans[i][2]=max(ans[i-1][0]+c[i],ans[i-1][1]+c[i]);
	}
	return max(ans[N-1][0],max(ans[N-1][1],ans[N-1][2]));	
}

int main()
{
	int N;
	cin>>N;
	int a[N],b[N],c[N];
	for(int i=0;i<N;i++)
		cin>>a[i]>>b[i]>>c[i];
	printf("%d\n",happy(N,a,b,c));
	return 0;
}

Measured memory_bytes: 2560
N = int(input())
X = []
for i in range(N):
    a,b = map(str, input().split())
    X.append([a, int(b), i + 1])

X.sort(key=lambda x:(x[0],x[1]),reverse = True)
X.sort(key=lambda x:(x[0]))

for x in X:
    print(x[2])


Measured memory_bytes: 38384
/*
.   Bismillahir Rahmanir Rahim
.   Author - Marajul islam
.   created- 

*/ 
#include<bits/stdc++.h>
using namespace std;


 
int sc1() {int x; scanf("%d", &x); return x;}
long long sc2() {long long x; scanf("%lld", &x); return x;}

const int mod= 1e9 + 7;
inline int add(int a, int b) {a += b; return a >= mod ? a - mod : a;}
inline int sub(int a, int b) {a -= b; return a < 0 ? a + mod : a;}
inline int mul(int a, int b) {return (long long)a * b % mod;}
 
#define F               first
#define S               second 
#define mp              make_pair
#define pb              push_back
#define pf              push_front
#define speed_up        ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define sz(x)           (int)x.size()
#define all(x)          x.begin(), x.end()
#define debug           cerr << "OK\n";
#define ub              upper_bound
#define lb              lower_bound
#define gcd(a,b)        __gcd(a,b)
#define lcm(a,b)        (a*b)/gcd(a,b)
#define Int             sc1()
#define LL              sc2()
#define For(n)          for(int i=0;i<n;i++)
#define Forj(n)         for(int j=0;j<n;j++)
#define Fork(n)         for(int k=0;k<n;k++)
#define For1(n)         for(int i=1;i<=n;i++)

typedef long long       ll;
typedef vector<int>     vi;
typedef vector<ll>      vll;
typedef pair<int, int>  pii;
typedef pair<ll, ll>    pll;
typedef vector<pii>     vpii;
typedef set <int>       si;
typedef set <ll>        sll;
typedef multiset <int>  msi;
typedef multiset <ll>   msll;
typedef map <int, int>  mi;
typedef map <ll, ll>    mll;

#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {cout << endl;}
template<typename T, typename... Args> void err(istream_iterator<string> it, T a, Args... args) {
    cerr << *it << " = " << a << ", ";
    err(++it, args...);
}
  
const int inf           = (int)2e9 + 5;
const ll  Inf           = (ll)1e18 + 5;
const int N             = 5e6 + 5;
 
 
 
int solve() {
 
	int x;
 	cin>>x;
 	if(x==0 ) cout<<1<<endl;
 	else cout<<0<<endl;
	return 0;
}
 
 
 
 
int main()
{
	//speed_up;
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
 
	int test = 1, tc = 0;
	//scanf("%d", &test);
	//cin >> test;
	while (test--) {
		//printf("Case %d: ", ++tc);
		solve();
	}
 
	return 0;
 
 
 
 
}




Measured memory_bytes: 3616
import java.util.*;
public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int c = sc.nextInt();
    
    String ans;
    
    if(b-a==c-b) ans = "YES";
    else ans = "NO";


    System.out.println(ans);
    
  }
}

Measured memory_bytes: 35676
//A.cpp
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#include <math.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){return b!=0?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
const ll mod=1e9+7;
// const int INF = 1000000;

int main(){
  ll n,k;
  cin >> n >> k;
  ll h[n];
  rep(i,n) cin >> h[i];
  sort(h,h+n);
  ll dif[n-k+1];
  rep(i,n-k+1){
    dif[i] = h[i+k-1] - h[i];
  }
  sort(dif,dif+n-k+1);
  printf("%lld\n", dif[0]);
  return 0;
}


Measured memory_bytes: 1792
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;


namespace Contest
{
    class Scanner
    {
        private string[] line = new string[0];
        private int index = 0;

        public string Next()
        {
            if (line.Length <= index)
            {
                line = Console.ReadLine().Split(' ');
                index = 0;
            }

            var res = line[index];
            index++;
            return res;
        }

        public int NextInt()
        {
            return int.Parse(Next());
        }

        public long NextLong()
        {
            return long.Parse(Next());
        }

        public ulong NextUlong()
        {
            return ulong.Parse(Next());
        }

        public string[] Array()
        {
            line = Console.ReadLine().Split(' ');
            index = line.Length;
            return line;
        }

        public int[] IntArray()
        {
            var array = Array();
            var result = new int[array.Length];
            for (int i = 0; i < array.Length; i++)
            {
                result[i] = int.Parse(array[i]);
            }

            return result;
        }

        public long[] LongArray()
        {
            var array = Array();
            var result = new long[array.Length];
            for (int i = 0; i < array.Length; i++)
            {
                result[i] = long.Parse(array[i]);
            }

            return result;
        }
    }

    class Program
    {
        private int N, M;
        private List<int>[] To;
        private int[] Memo;
        void Scan()
        {
            var sc = new Scanner();
            N = sc.NextInt();
            M = sc.NextInt();
            To = new List<int>[N];
            Memo = new int[N];
            for (int i = 0; i < N; i++)
            {
                To[i] = new List<int>();
                Memo[i] = -1;
            }
            for (int i = 0; i < M; i++)
            {
                int x = sc.NextInt() - 1;
                int y = sc.NextInt() - 1;
                To[x].Add(y);
            }


        }

        private int Ans(int n)
        {
            if (Memo[n] != -1) return Memo[n];
            if (To[n].Count == 0)
            {
                Memo[n] = 0;
                return 0;
            }
            int result = -1;
            foreach (var i in To[n])
            {
                result = Math.Max(result, Ans(i) + 1);
            }

            Memo[n] = result;
            return result;
        }

        public void Solve()
        {
            Scan();
            int ans = 0;
            for (int i = 0; i < N; i++)
            {
                ans = Math.Max(ans, Ans(i));
            }
            Console.WriteLine(ans);
        }




        static void Main() => new Program().Solve();
    }


}

Measured memory_bytes: 29452
#include<bits/stdc++.h>
#define mo 1000000007
using namespace std;
int n,m,i,j,a[100005],ans;
int l,r,mid,xr,p1,flag;
char s[100005];
int read(){
	char ch=getchar();
	int xx=0;
	while(ch<'0'||ch>'9')
		ch=getchar();
	while(ch>='0'&&ch<='9'){
		xx=xx*10+ch-'0';
		ch=getchar();
	}
	return xx;
}
int main(){
	scanf("%s",s+1);
	n=strlen(s+1);
	for(i=1;i<=n;i++)
		a[i]=s[i]-'0';
	l=n/2+1;r=n;mid=(l+r)/2;ans=n/2;
	while(l<=r){
		p1=n-mid+1;
		xr=0;
		for(i=1;i<=p1;i++)
			if(a[i]!=xr)
				xr^=1;
		flag=0;
		for(i=p1+1;i<=mid;i++)
			if(a[i]!=xr)
				flag=1;
		if(flag==0){
			ans=max(ans,mid);
			l=mid+1;
		}
		else
			r=mid-1;
		mid=(l+r)/2;
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const long long INF = 1LL<<60;
#define REP(i,n) for(int i=0;i<n;i++)
#define REP2(i,m,n) for(int i=m;i<n;i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

int main(){
    int N;
    cin >> N;
    int A[N];
    int B[N]={};
    A[0]=0;
    int index=0;
    int people=1;
    REP2(i,1,N){
        cin >> A[i];
        ++B[A[i]-1];
    }
    REP(i,N){
        cout<<B[i]<<endl;
    }
    // REP2(i,2,N){
    //     // cout<<A[i];
    //     if(A[i]==A[i-1]){
    //         people++;
    //         // cout<<" same"<<endl;
    //     }else{
    //         // cout<<" people ";
    //         cout<<people<<endl;
    //         index++;
    //         people=1;
            
    //     }
    // }
    // cout << people<<endl;
    // REP2(i,index+1,N){
    //     cout<<0<<endl;
    // }
    
}

Measured memory_bytes: 5156
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <ctime>
#include <cstring>
#include <functional>
#include <iostream>
#include <iomanip>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <regex>
#include <vector>

#define fix(n)          cout<<fixed<<setprecision(n)
#define rep(i,n)        for (int i = 0; i < (n); ++i)
#define sort(a)         sort((a).begin(), (a).end())
#define uniq(a)         sort(a);(a).erase(unique((a).begin(), (a).end()), (a).end())
#define reverse(a)      reverse((a).begin(), (a).end())
#define ctos(c)         string(1, (c))
#define out(d)          cout << (d)
#define outl(d)         std::cout<<(d)<<"\n"
#define YES()           cout << "YES" << endl
#define NO()            cout << "NO" << endl
#define Yes()           cout << "Yes" << endl
#define No()            cout << "No" << endl
#define ceil(x, y)      ((x + y - 1) / (y))
#define debug(x)        cerr << #x << ": " << (x) << '\n'
#define debug2(x, y)    cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << '\n'
#define debug3(x, y, z) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << ", " << #z << ": " << (z) << '\n'
#define dbg(v)          for (size_t _ = 0; _ < v.size(); ++_){ cerr << #v << "[" << _ << "] : " << v[_] << '\n'; }

using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll,ll>;

const ll MOD = 1000000007; // 10^9 + 7
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

void solve() {
  ll k, a, b; cin >> k >> a >> b;

  if (b <= a + 2) outl(k + 1);
  else if ((k - a) % 2 == 1) {
    ll t = k - a;
    outl((t + 1) / 2 * b - ((t + 1) / 2 - 1) * a);
  } else {
    ll t = k - a - 1;
    outl((t + 1) / 2 * b - ((t + 1) / 2 - 1) * a + 1);
  }
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  srand((unsigned)time(NULL));
  fix(12);

  solve();
}


Measured memory_bytes: 632
#include <stdio.h>
 
int main(void)
{
    int n, card[4][13] = {0};
    int i, j, c, d;
    char m;
 
 
    scanf("%d", &n);
 
    for(i=0;i<n;i++){
        scanf(" %c %d", &m, &d);
 
        switch(m){
            case 'S' : card[0][d-1] = 1;
                        break;
            case 'H' : card[1][d-1] = 1;
                        break;
            case 'C' : card[2][d-1] = 1;
                        break;
            case 'D' : card[3][d-1] = 1;
                        break;
        }
    }
 
    for(i=0;i<4;i++){
        for(j=0;j<13;j++){
            if(card[i][j] == 0){
                switch(i){
                    case 0 : printf("S %d", j+1);
                            break;
                    case 1 : printf("H %d", j+1);
                            break;
                    case 2 : printf("C %d", j+1);
                            break;
                    case 3 : printf("D %d", j+1);
                            break;
                }
             printf("\n");
            }
        }
    }
 
    return 0;
}

Measured memory_bytes: 600
#include <iostream>

using namespace std;

int n;
string s;
int suffR[4001], suffG[4001], suffB[4001];

void input(){
    scanf("%d", &n);
    cin >> s;
}

void prepare(){
    for (int i = s.length() - 1; i >= 0; i--){
        if (s[i] == 'R'){
            suffR[i] = suffR[i+1] + 1;
            suffG[i] = suffG[i+1];
            suffB[i] = suffB[i+1];
        } else if (s[i] == 'G'){
            suffR[i] = suffR[i+1];
            suffG[i] = suffG[i+1] + 1;
            suffB[i] = suffB[i+1];
        } else if (s[i] == 'B'){
            suffR[i] = suffR[i+1];
            suffG[i] = suffG[i+1];
            suffB[i] = suffB[i+1] + 1;
        }
    }
}

void solve(){
    long long int ans = 0;
    for (int i = 0; i < s.length(); i++){
        if (s[i] == 'R'){
            for (int j = i+1; j < s.length(); j++){
                if (s[j] == 'G'){
                    ans += suffB[j];
                    if (2*j-i < s.length() && s[2*j-i] == 'B'){
                        ans--;
                    }
                }
            }
        }
    }
    for (int i = 0; i < s.length(); i++){
        if (s[i] == 'R'){
            for (int j = i+1; j < s.length(); j++){
                if (s[j] == 'B'){
                    ans += suffG[j];
                    if (2*j-i < s.length() && s[2*j-i] == 'G'){
                        ans--;
                    }
                }
            }
        }
    }
    for (int i = 0; i < s.length(); i++){
        if (s[i] == 'G'){
            for (int j = i+1; j < s.length(); j++){
                if (s[j] == 'R'){
                    ans += suffB[j];
                    if (2*j-i < s.length() && s[2*j-i] == 'B'){
                        ans--;
                    }
                }
            }
        }
    }

    for (int i = 0; i < s.length(); i++){
        if (s[i] == 'G'){
            for (int j = i+1; j < s.length(); j++){
                if (s[j] == 'B'){
                    ans += suffR[j];
                    if (2*j-i < s.length() && s[2*j-i] == 'R'){
                        ans--;
                    }
                }
            }
        }
    }

    for (int i = 0; i < s.length(); i++){
        if (s[i] == 'B'){
            for (int j = i+1; j < s.length(); j++){
                if (s[j] == 'R'){
                    ans += suffG[j];
                    if (2*j-i < s.length() && s[2*j-i] == 'G'){
                        ans--;
                    }
                }
            }
        }
    }

    for (int i = 0; i < s.length(); i++){
        if (s[i] == 'B'){
            for (int j = i+1; j < s.length(); j++){
                if (s[j] == 'G'){
                    ans += suffR[j];
                    if (2*j-i < s.length() && s[2*j-i] == 'R'){
                        ans--;
                    }
                }
            }
        }
    }

    cout << ans << endl;
}

int main(){
    input();
    prepare();
    solve();
}


Measured memory_bytes: 3280
using System;

class Program
{
    static void Main(string[] args)
    {
        var s = Console.ReadLine();

        var x = 0;
        var y = 0;

        for (int i = 0; i < s.Length; i++)
        {
            if (i % 2 == 0)
            {
                if (s[i] == '0')
                {
                    x++;
                }
                else
                {
                    y++;
                }
            }
            else
            {
                if (s[i] == '0')
                {
                    y++;
                }
                else
                {
                    x++;
                }
            }
        }

        Console.WriteLine(Math.Min(x, y));
    }
}


Measured memory_bytes: 13244
#include <iostream>

using namespace std;

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

    int dp[n];
    int tab[n];

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



    dp[0] = 0;

    for(int i = 1; i < n; i++) {
        for(int j = 1; j <= k; j++) {
            if(i - j >= 0) {
                dp[i] = min(dp[i], dp[i - j] + abs(tab[i]- tab[i-j]));
            }
        }
    }

    //for(int i = 0; i < n; i++) cout << dp[i] << endl;

    cout << dp[n-1];

    return 0;
}


Measured memory_bytes: 1024
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {

    public static void main(String[] args) throws Exception {
        try (BufferedReader reader = new BufferedReader(new InputStreamReader(System.in))) {
            int N = Integer.parseInt(reader.readLine());
            String S = reader.readLine();

            int max = 0;
            for (int i = 0; i < N; i++) {
                int[] prefix = z(S.substring(i));
                for (int j = 1; j < prefix.length; j++) {
                    if (max < prefix[j]) {
                        if (prefix[j] < j) {
                            max = prefix[j];
                        } else if (max < j) {
                            max = j;
                        }
                    }
                }
            }

            System.out.println(max);
        }
    }

    public static int[] z(String S) {
        int[] prefix = new int[S.length()];

        for (int i = 1, j = 0; i < S.length(); i++) {
            if (i + prefix[i - j] < j + prefix[j]) {
                prefix[i] = prefix[i - j];
            } else {
                int k = Math.max(0, j + prefix[j] - i);
                while (i + k < S.length() && S.charAt(k) == S.charAt(i + k)) {
                    k++;
                }
                prefix[i] = k;
                j = i;
            }
        }

        prefix[0] = S.length();

        return prefix;
    }

}


Measured memory_bytes: 46784
S = input()

def main():
    s = S
    l = len(s)
    while l:
        s = s[:l - 2]
        l = len(s)
        mid = l // 2
        if s[:mid] == s[mid:]:
            ans = l
            break
    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
#include<iostream>
#include<cstring>
using namespace std;
int n, m, cnt, turn, remain; bool x[1000000];
int main() {
	while (true) {
		cin >> n >> m;
		if (n == 0 && m == 0) { break; }
		turn = 1; cnt = 1;
		remain = n;
		memset(x, false, sizeof(x));
		while (remain > 1) {
			cnt = 0;
			while (true) {
				if (x[turn] == false) {
					cnt++;
					if (cnt == m) { goto E; }
				}
				turn++;
				if (turn > n) { turn = 1; }
			}
		E:;
			x[turn] = true;
			remain--;
		}
		for (int i = 1; i <= n; i++) {
			if (x[i] == false) { cout << i << endl; }
		}
	}
}

Measured memory_bytes: 2144
def main():
    from collections import Counter as ct
    n = int(input())
    a = list(map(int, input().split()))
    mod = 10**9+7

    def soinsuu(a):
        yy, j = [], 2
        y = yy.append
        while(a > 1):
            for i in range(j, int(a**0.5)+1):
                if a % i == 0:
                    y(i)
                    a, j = a//i, i
                    break
            else:
                y(a)
                break
        return ct(yy)

    soinsuu_dict = dict()

    for i in a:
        j = soinsuu(i)
        # print(j)
        for x, y in j.items():
            if x not in soinsuu_dict.keys():
                soinsuu_dict[x] = y
            else:
                soinsuu_dict[x] = max(soinsuu_dict[x], y)
    # print(soinsuu_dict)
    l = 1
    for i, j in soinsuu_dict.items():
        l = l*pow(i, j, mod) % mod
    # print(l)
    ans = 0
    for i in a:
        ans = (ans+l*pow(i, mod-2, mod)) % mod
    print(ans)


main()


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

p1=0
p2=0

for i in range(n):
    
    a,b = input().split()
    
    if a > b:
        p1 += 3
    elif b > a:
        p2 += 3
    else:
        p1 += 1
        p2 += 1
        
print(p1,p2)


Measured memory_bytes: 5596
/*
	Created by : imay_10
	" It won't be EASY, but I'll make it "
*/

#include<bits/stdc++.h>
using namespace std;

typedef long long int ll;
const int mod = 1e9+7;
const ll inf = 1e18;
const double pi = 3.1415926535897932384626;

// Utility for fast exponentiation
ll mpow(ll a,ll b,ll m){
    ll res=1;
    //a%=m;
    while(b){
    	if(b%2) res=res*a%m;
		a=a*a%m;
		b/=2;
	}
	return res;
}

// Utility for modular inverse
ll inv(ll a,ll m){
	return mpow(a,m-2,m);
}

// Utility for GCD Calculation
ll gcd(ll a,ll b){
	if(b==0) return a;
	return gcd(b,a%b);
}

// Utility for binomial coefficient
ll ncr(ll n,ll k)
{
    if(n<k)
        return 0;
    ll C[n + 1][k + 1];
    ll i,j;
    for(i=0;i<=n;i++){
        for(j=0;j<=min(i,k);j++){
            if (j==0 || j==i)
                C[i][j]=1;
            else
                C[i][j]=(C[i-1][j-1]+C[i-1][j])%mod;
        }
    }
    return C[n][k];
}

void solve(){
	//code
	int m1,d1,m2,d2;
	cin>>m1>>d1;
	cin>>m2>>d2;
	
	if(m2-1==m1 and d2<d1)
		cout<<1;
	else cout<<0;
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	
	solve();
 	return 0;
}


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

int a, b;

int main() {
  cin >> a >> b;
  for (size_t i = 0; i < max(a, b); i++) {
    cout << min(a, b);
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 256
defmodule Main do
  def main do
    _ = IO.gets("")
    t = 
      IO.gets("")
      |> String.trim()
      |> String.split()
      |> Enum.map(&String.to_integer/1)
      |> Enum.with_index(1)
    m = 
      IO.gets("")
      |> String.trim()
      |> String.to_integer()
    px =
      IO.stream(:stdio, :line)
      |> Enum.take(m)
      |> Enum.map(&String.trim/1)
      |> Enum.map(&String.split/1)
      |> Enum.map(&Enum.map(&1, fn elem -> String.to_integer(elem) end))
    
    process(px, t)
  end
  
  
  defp process([], _), do: nil
  defp process([head | tail], t) do
  	_process(head, t, 0)
    process(tail, t)
  end
  
  defp _process([p, x], [], acc), do: IO.puts(acc)
  defp _process([p, x], [{val, index} | tail], acc) when p == index, do: _process([p, x], tail, acc + x)
  defp _process(px, [{val, _} | tail], acc), do: _process(px, tail, acc + val)
end

Measured memory_bytes: 31060
#include <stdio.h>
#include <stdlib.h>
int main() {
	
	int arr1[3][3];
	int N, a,x;
	int arr2[3][3] = {0};
	
	for(int i = 0; i < 3; i++){
		for(int j = 0; j < 3; j++){
			scanf("%d", &arr1[i][j]);
		}
	}
	
	scanf("%d", &N);
	
	for(int a = 0; a < N; a++){
			scanf("%d", &x);
			for(int i = 0; i < 3; i++){
				for(int j= 0; j < 3; j++){
					if(arr1[i][j] == x){
						arr2[i][j] = 1;
					}
				}
		}
	}
	
	if(arr2[0][0] + arr2[1][1] + arr2[2][2] == 3
		|| arr2[0][2] + arr2[1][1] + arr2[2][0] == 3){
		printf("Yes\n");
		return 0;
	}
	
	for(int i = 0; i < 3; i++){
		if(arr2[i][0] + arr2[i][1] + arr2[i][2] == 3
			|| arr2[0][i] + arr2[1][i] + arr2[2][i] == 3){
			printf("Yes\n");
			return 0;
		}
	}
	
	printf("No");
	
	return 0;
}

Measured memory_bytes: 1688
N,L = (int(i) for i in input().split())

taste=0

if L >= 0:
    for i in range(1,N):
        taste = taste + L + i

elif abs(L) < N:
    for i in range(N):
        taste = taste + L + i

else:
    for i in range(N-1):
        taste = taste + L + i
    
        
        
print(taste)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define in ({int x=0;int c=getchar(),n=0;for(;!isdigit(c);c=getchar()) n=(c=='-');for(;isdigit(c);c=getchar()) x=x*10+c-'0';n?-x:x;})
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int rnd(int l,int r){return l+rng()%(r-l+1);}
#define fasty ios_base::sync_with_stdio(false),cin.tie(nullptr);
#define task "A"
#define forinc(a,b,c) for(int a=b,_c=c;a<=_c;++a)
#define fordec(a,b,c) for(int a=b,_c=c;a>=_c;--a)
#define forv(a,b) for(auto&a:b)
#define fi first
#define se second
#define pb push_back
#define ii pair<int,int>
#define mt make_tuple
#define all(a) a.begin(),a.end()
#define reset(f, x) memset(f, x, sizeof(f))
#define bit(x,i) ((x>>(i-1))&1)
#define on(x,i) (x|(1ll<<(i-1)))
#define off(x,i) (x&~(1<<(i-1)))

const int N=200010;

string s;
int f[N],g[N];

main(){
	//freopen(task".inp","r",stdin);
	//freopen(task".out",w"",stdout);
	cin>>s;
	f[1]=1;
	g[2]=1;
	forinc(i,1,s.size()){
		if(i>1 && s[i-1]!=s[i-2]) f[i]=f[i-1]+1;
		if(i>2){
			g[i]=f[i-2]+1;
			f[i]=max(f[i],g[i-1]+1);
		}
		if(i==(int)s.size()){
			return cout<<max(f[i],g[i]),0;
		}
	}
}

Measured memory_bytes: 2180
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
int main(){
	int H,W;
	for(int i=0; i<100; i++){
		if(i!=0)cout<<endl;
		cin>>H>>W;
		if(H==0&&W==0){
			i=100;
		}
		for(int a=0;a<H;a++){
			for(int c=0;c<W;c++){
				cout<<"#";
			}
			cout<<endl;
		}
	}
	return 0 ;
}



Measured memory_bytes: 3080
using System;
using System.Linq;

class Program {
    static void Main(string[] args) {
        int a = Cin.Ni();
        int b = Cin.Ni();
        int count = 0;

        for (int i = a; i <= b; i++) {
            string s = i.ToString();
            if (s[0] == s[4] && s[1] == s[3]) count++;
        }

        Console.WriteLine(count);
    }
}

public class Cin {
    private static string[] s = new string[0];
    private static int i = 0;

    private static char[] cs = new char[] { ' ' };

    public static string Next() {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        i = 0;
        return Next();
    }

    public static int Ni() {
        return int.Parse(Next());
    }

    public static long NextLong() {
        return long.Parse(Next());
    }

    public static double NextDouble() {
        return double.Parse(Next());
    }

}


Measured memory_bytes: 15188
#include<stdio.h>
main()
{
	int h, m, s, x;
	scanf("%d", &x);
	h = x / 3600; 
	m = (x-h*3600) / 60;
	s = x - (h*3600 + m*60); 
	printf("%d:%d:%d\n", h, m, s);
	return 0;
}



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

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = std::int64_t;

int N, M, V, P;
ll A[100100], B[100100];

int main(){
  std::cin.tie(nullptr);
  std::ios::sync_with_stdio(false);
  
  std::cin >> N >> M >> V >> P;

  for(int i=0;i<N;++i){
      std::cin >> A[i];
  }

  std::sort(A, A + N);
  std::reverse(A, A + N);

  for(int i=0;i<N;++i){
      B[i+1] = A[i] + B[i];
  }

  int res = 0;

  for(int i=0;i<N;++i){
      if(i < P){
          res += 1;
          continue;
      }

      int r = V - ((N - i) + (P - 1));
      if(r <= 0){
          if(A[i] + M >= A[P-1]){
              res += 1;
          }
          continue;
      }

      if(A[P-1] > A[i] + M){
          continue;
      }

      if(1ll * (i - (P - 1)) * (A[i] + M) - (B[i] - B[P-1]) >= 1ll * r * M){
          res += 1;
      }
  }

  std::cout << res << std::endl;
}


Measured memory_bytes: 1792
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
const int INF = 1 << 30;
const ll INFll = 1ll << 60;

int main() {
  int a, b;
  char op;
  cin >> a >> op >> b;
  if (op == '+')
    cout << a + b << endl;
  else
    cout << a - b << endl;

  return 0;
}


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

int main() {
  int value;

  int ans1;
  int ans2;
  int ans3;
  int finalAnswer;
  
  cin >> value;
  
  ans1 = value / 100;
  value = value - (ans1 * 100);
  ans2 = value / 10;
  value = value - (ans2 * 10);
  ans3 = value;

  finalAnswer = ans1 + ans2 + ans3;
  
  cout << finalAnswer << endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#ifdef ONLINE_JUDGE
#define LLD "%I64d"
#else
#define LLD "%lld"
#endif
#define fu(a,b,c) for(int a=b;a<=(int)c;++a)
#define fd(a,b,c) for(int a=b;a>=(int)c;--a)
#define cu(a,b,c) for(int a=b;a<(int)c;++a)
#define cd(a,b,c) for(int a=(b)-1;a>=(int)c;--a)
#define gcd(a,b) __gcd(a,b) 
#define pii pair<int,int>
#define pll pair<long long,long long>
#define all(a) a.begin(),a.end()
#define F first
#define S second
#define pb push_back
#define pf push_front
#define MOD 1000000007 
#define MAXN 52
#define MAXH 20
#define MAXM 52
#define INF 100000000
#define ll long long
#define ull unsigned long long
#define RNG rng mt19937(time(NULL))
#define udist(a,b) uniform_int_distribution<uint32_t> distribution(a,b)
#define max3(a,b,c) max(a, max(b, c))
#define min3(a,b,c) min(a, min(b, c))
#define gmax(a,b) a = max(a, b)
#define gmin(a,b) a = min(a, b)
#define whatis(x) cerr << #x << " is " << x << endl;
#define fast_io() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define PI 3.1415926535897932384626433
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

int main(){
	int n;
	cin >> n;
	vector<int> v(n);
	cu(i,0,n)cin >> v[i];
	ll ans = 0;
	cu(i,0,n){
		while(v[i]){
			int end = i;
			while(end < n && v[end]){
				++end;
			}
			++ans;
			cu(j,i,end){
				--v[j];
			}
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    int n,t,k,cnt=0;
    cin>>n;
    t=n;
    while(t!=0)
    {
        k=t%10;
        t=t/10;
        cnt++;
    }
    if(cnt==1)cout<<n<<endl;
    else if(cnt==2)cout<<9;
    else if(cnt==3)cout<<n-100+1+9<<endl;
    else if(cnt==4)cout<<900+9<<endl;
    else if(cnt==5)cout<<n-10000+1+900+9<<endl;
    else if(cnt==6)cout<<90000+900+9;
    return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-

n,k = map(int,input().split())
a = [0] * n
b = [0] * n
for i in range(n):
    a[i],b[i] = map(int,input().split())

ab = [[0,0] for i in range(n)]

for i in range(n):
    ab[i] = [a[i],b[i]]

ab.sort()

cnt = 0

for i in range(n+1):
    if cnt >= k:
        print(ab[i-1][0])
        break
    cnt += ab[i][1]


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

int main(){
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  int l = a + b,r = c + d;
  if(l > r)cout << "Left";
  else if(l == r)cout << "Balanced";
  else cout << "Right";

  cout << endl;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
	int n,temp,count=1;
	cin>>n;
	for(int i=0;i<4;i++){
		if(!i)temp=n%10;
		else{
			if(n%10==temp)count++;
			else{
				count=1;
				temp=n%10;
			}
			if(count>=3){
				cout<<"Yes\n";
				break;
			}
		}
		n/=10;
	}
	if(count<3)cout<<"No\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(var,cnt) for(int (var)=0; (var)<(int)(cnt); ++(var))
#define Rep(var,init,cnt) for(int (var)=(init); (var)<(cnt); ++(var))
#define ran(var,vec) for(auto &(var):(vec))
#define all(v) (v).begin(),(v).end()
#define SORT(v) sort(all(v))
#define SUM(v) accumulate(all(v),0)
#define tget(tp,idx) get<idx>(tp)
#define TF(flag) (flag)?1:0
using namespace std;

using ll = long long;
using ull = unsigned long long;
using pi = pair<int,int>;
using pl = pair<ll,ll>;
using ti = tuple<int,int,int>;
using tl = tuple<ll,ll,ll>;

template<typename T>
using vec = vector<T>;
template<typename T>
using mat = vector<vec<T>>;
template<typename T>
using cub = vector<mat<T>>;
template<typename T>
using val = valarray<T>;

template<typename T>
using pq = priority_queue<T>;
template<typename T>
using rpq = priority_queue<T,vec<T>,greater<T>>;

template<typename T1,typename T2>
ostream &operator<<(ostream &os, const pair<T1,T2> &p){
  os<<"P("<<p.first<<", "<<p.second<<") ";
  return os;
}

template<typename T1,typename T2>
istream &operator>>(istream &is, pair<T1,T2> &p){
  is>>p.first>>p.second;
  return is;
}

template<typename T>
ostream &operator<<(ostream &os, const vector<T> &v){
  cout<<"V{";
  for(int i=0; i<(int)v.size(); ++i){
    os<<v[i]<<(i+1!=v.size()?" ":"");
  }
  cout<<"}";
  return os;
}

template<typename T>
istream &operator>>(istream &is, vector<T> &v){
  for(T &in:v) is>>in;
  return is;
}

template<typename T>
ostream &operator<<(ostream &os, const valarray<T> &v){
  cout<<"V{";
  for(int i=0; i<(int)v.size(); ++i){
    os<<v[i]<<(i+1!=v.size()?" ":"");
  }
  cout<<"}";
  return os;
}

template<typename T>
istream &operator>>(istream &is, valarray<T> &v){
  for(T &in:v) is>>in;
  return is;
}

// Usual Template End ================================================

// Template End ======================================================

constexpr int MOD=1e9+7;

int main(void){
  int N,M; cin>>N>>M;
  pq<int> A;
  rep(i,N){
    int a; cin>>a; A.push(a);
  }
  rep(i,M){
    int H=A.top(); A.pop(); A.push(H/2);
  }
  
  ll ans=0;
  while(!A.empty()){
    ans+=A.top(); A.pop();
  }
  cout<<ans<<endl;
}













Measured memory_bytes: 892
import collections


N = int(input())
a = list(map(int, input().split()))
C = collections.Counter(a)
L = len(C)
e = list(C.keys())
print(
    (
        ((L == 1) and (C[0] > 0))
        or ((L == 2) and (C[0] > 0) and (C[e[0]] * 2 == C[e[1]]))
        or ((L == 3) and (C[e[0]] == C[e[1]] == C[e[2]]) and ((e[0] ^ e[1]) == e[2]))
    )
    and "Yes"
    or "No"
)



Measured memory_bytes: 14468
#include<iostream>
#include<string>
using namespace std;
int main(){
	int ans = 0;
	string s,t;
	cin >> s>>t;
	for (int i = 0; i < s.size(); i++){
		if (s[i] != t[i]){
			ans++;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3788
#include <iostream>
#include <vector>

using namespace std;

vector<int> factorize(const int n) {
	vector<int> ps;

	int tmp = n;
	while (tmp % 2 == 0) {
		ps.push_back(2);
		tmp /= 2;
	}
	for (int i = 3; 2 * i <= n; i += 2) {
		while (tmp % i == 0) {
			ps.push_back(i);
			tmp /= i;
		}
	}
	if (ps.size() == 0) ps.push_back(n);

	return ps;
}

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

    vector<int> ps = factorize(n);
    cout << n << ':';
    for (vector<int>::iterator it = ps.begin(); it != ps.end(); ++it) {
        cout << ' ' << *it;
    }
    cout << endl;

    return 0;
}

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

using namespace std;

int main(void)
{
    string s[3];
    cin >> s[0];
    cin >> s[1];
    cin >> s[2];

    cout << s[0][0];
    cout << s[1][1];
    cout << s[2][2];
    cout << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define all(a)  (a).begin(),(a).end()
typedef long long ll;
const ll mod=1000000007;
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)

int main() {
  double l;cin >>l;
  cout << setprecision(10) << fixed<< (l/3.0d)*(l/3.0d)*(l/3.0d) << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int n;
    cin >> n;
    
    for(int i = 0;i <= n;i++){
        if((int)(i * 1.08) == n){
            cout << i << endl;
            return 0;
        }
    }
    
    cout << ":(" << endl;
}


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

#define rep(i,s,n) for(ll i = (s); i < (n); i++)
#define rep0(i,n) rep(i,0,n)
#define rep1(i,n) rep(i,1,n+1)
#define repR(i,s,n) for(ll i = (n-1); i >= (s); i--)
#define repR0(i,n) repR(i,0,n)
#define repR1(i,n) repR(i,1,n+1)

#define BR "\n"
#define SP " "
#define SHOW(x) for(int i = 0; i < x.size(); i++) { cout << x[i] << SP; } cout << BR;
#define SHOW2(x) for(int j = 0; j < x.size(); j++) { SHOW(x[j]); } cout << BR;
#define fcout cout << fixed << setprecision(18)

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

int a[100];
int cells[100][100]; // r * c

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

  vector<ll> A(N), S(N, 0);
  map<ll, ll> m;

  rep0(i, N) {
    cin >> A[i];
    if (i > 0) {
      S[i] = S[i - 1] + A[i];
    } else {
      S[0] = A[i];
    }
    m[S[i]]++;
  }

  ll ans = 0;
  for(auto itr = m.begin(); itr != m.end(); ++itr) {
    ll k = itr->first, v = itr->second;
    if (k == 0) ans += v * (v + 1) / 2;
    else ans += v * (v - 1) / 2;
  }

  cout << ans << BR;
  return 0;
}

Measured memory_bytes: 15872
n = int(input())
A = list(map(int, input().split()))
q = int(input())
m = list(map(int, input().split()))


def memoize(f):  # メモ化関数
    table = [{} for _ in range(n+1)]

    def func(cur, m):
        if m not in table[cur]:
            table[cur][m] = f(cur, m)
        return table[cur][m]
    return func


# メモ再帰で書く
@memoize
def dfs(cur, m):
    if m == 0:
        return True
    if cur >= n:
        return False
    res = dfs(cur+1, m) | dfs(cur+1, m-A[cur])
    return res


for num in m:
    if dfs(0, num):
        print('yes')
    else:
        print('no')



Measured memory_bytes: 7884
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;
using static AtCoderTemplate.MyLibrary;

namespace AtCoderTemplate
{
    class Program
    {
        static void Main (string[] args)
        {
            string[] str;
            str = Console.ReadLine ().Split (' ');

            long X = Math.Abs (long.Parse (str[0]));
            long K = long.Parse (str[1]);
            long D = long.Parse (str[2]);

            long ans = 0;

            long q = X / D;
            if (K < q) ans = X - K * D;
            else if (K % 2 == q % 2) ans = X - q * D;
            else ans = Math.Abs (X - (q + 1) * D);

            Console.Write (ans);
        }
    }

    class MyLibrary
    {
        public static int GCD (int a, int b)
        {
            if (a % b == 0) return b;
            return GCD (b, a % b);
        }
    }
}

Measured memory_bytes: 27488
#include <bits/stdc++.h>
 
using namespace std;
 
#define rep(i, n) for(int i=0; i<(n); i++)
#define FOR(i, m, n) for(int i=(m);i<(n);i++)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define SORT(x) sort((x).begin(),(x).end())
#define RSORT(x) sort((x).rbegin(),(x).rend())
#define REVE(x) reverse((x).begin(),(x).end())
#define mp make_pair
#define pb push_back
#define chmax(x,y) x = max(x,y)

 
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<vector<int> > VVI;
typedef pair<int, int> PII;
typedef long long LL;
typedef vector<bool> VB;
typedef vector<LL> VL;
typedef vector<vector<long long>> VVLL;
typedef vector<set<int>> VSI;
const int MOD = 1e9+7;
const int INF = 1e9;
const LL LINF = 1e18;
int gcd(int a, int b)
{
   if (a%b == 0)
   {
       return(b);
   }
   else
   {
       return(gcd(b, a%b));
   }
}

int lcm(int a, int b)
{
   return a * b / gcd(a, b);
}

int main() {
    int n;
    cin >> n;
    vector<char> c(n);
    rep(i,n) cin >> c[i];
    int k = 0;
    rep(i,n) {
        if(c[i] == 'R') {
            k++;
        }
    }
    LL t = k;
    rep(i,t) {
        if(c[i] == 'R') {
            k--;
        }
    }

    cout << k << endl;

}


Measured memory_bytes: 3588
#include<bits/stdc++.h>
using namespace std;
#define V vector
#define L long long
#define W V<L>
#define R(n)for(L i=0;i<n;i++)
L E=70;W S(V<W>p){if(!E){return{1,0};}V<V<W>>T(2);for(W x:p){T[x[1]&1].push_back({x[0]/2,x[1]/2});if(x[0]&1){T[(x[1]+1)&1].push_back({x[0]/2,(x[1]+1)/2});}}R(2){L c=0;for(W x:T[!i]){L Q=(2*x[0]+x[1])%3;c^=Q+1;}if(!c){E--;W A=S(T[i]);A[0]*=2;A[1]*=2;A[1]+=i;return A;}}for(W&v:p){v[0]++;}W A=S(p);A[0]--;return A;}int main(){L M=2e17,n,a,b;cin>>n;V<W>p(n);R(n){cin>>a>>b;p[i]={a+M,b+M};}W x=S(p);cout<<x[0]-M<<" "<<x[1]-M;}

Measured memory_bytes: 62908
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
ll gcd(ll a, ll b) {
	if (a<b) { return gcd(b, a); }
	else if (a%b) { return gcd(b, a%b); }
	else { return b; }
}
ll lcm(ll a,ll b){
    return (a/gcd(a,b))*b;
}
int main(){
    ll N,K;
    cin>>N>>K;
    ll h[N];
    ll sum[N];
    for(int i=0; i<N; i++){
        cin>>h[i];
    }
    sort(h,h+N);
    ll mi=1000000000000;
    for(int i=0; i<=N-K; i++){
        mi=min(mi,h[i+K-1]-h[i]);
    }
    cout<<mi<<endl;
}



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

int main(int H, int M) {
    while (true) {
        cin >> H >> M;
        if (H == 0 && M == 0){
            break;
        }
        for (int i = 0; i < H; i++) {
            for (int j = 0; j < M; j++) {
                if (i == 0 || i == H-1 || j == 0 || j == M-1) {
                    cout << "#";
                }
                else {
                    cout << ".";
                }
            }
            cout << endl;
        }
        cout << endl;
    }
}


Measured memory_bytes: 2992
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
int n,m;
char s[15];
int main()
{
    cin>>n>>m;
    int ok = 1;
    int sum2 = 0;
    for(int i=1;i<=n+m+1;i++)
    {
        char x;
        cin>>x;
        if(i==n+1)
        {
            if(x!='-')ok = 0;
        }
        else if(x>='0'&&x<='9')sum2++;
    }
    if(ok==1&&sum2==n+m)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}



Measured memory_bytes: 256