akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <cassert>
#include <cstdarg>
#include <sys/time.h>
#include <fstream>
//#include "cout.h"

using namespace std;

#define SZ(x) ((int)x.size())
#define MSET(x,a) memset(x, a, (int)sizeof(x))
#define PB push_back
#define VI vector < int >
#define PII pair < int, int >
#define LL long long
#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(), (v).end()
#define FIT(it,v) for (__typeof((v).begin()) it = (v).begin(); it != (v).end(); it++)
#define OUT(A) cout << #A << " = "<< (A) << endl
#define OUT2(A, B) cout << "(" << #A << ", " << #B << ") = (" << (A) << ", "<< (B) << ")" << endl
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }

#define present(c, e) ((c).find((e)) != (c).end())
#define cpresent(c, e) (find(ALL(c), (e)) != (c).end())

int n;
int a[110];

void init() {

}

void input() {
  cin >> n;
  REP(i, n) cin >> a[i];
}

void solve() {
  int sum = 0;
  REP(i, n) sum += a[i];

  int i = 0;
  int cnt = 0;
  while(sum > 0) {
    if (a[i] > 0) {
      a[i]--;
      sum--;
      if (i == n-1 || a[i+1] == 0) cnt++;
    }
    i = (i+1) %n;
  }

  cout << cnt << endl;
}

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


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

using namespace std;


//repetition
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define euc_dis(x, y) sqrt(x*x + y*y)

#define pb push_back
#define mp make_pair
#define INF 999999999
#define MOD 1000000007
#define sp ' '


//typedef
typedef long long ll;
typedef pair<int, int> pint;
typedef pair<long, long> pll;
typedef map<int, int> mint;
typedef set<int> sint;
typedef vector<int> vint;
typedef vector<char> vchr;
typedef vector<long long> vll;
typedef vector<string> vstr;


ll mod(ll a, ll b){return (a%b+b)%b;}
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);}
void Yes(){cout << "Yes" << endl;}
void No(){cout << "No" << endl;}
void Judge(bool b){b?Yes():No();}
void YES(){cout << "YES" << endl;}
void NO(){cout << "NO" << endl;}
void JUDGE(bool b){b?YES():NO();}
ll powMod(ll a, ll b, ll c){ll ans=1; rep(i, b){ans=ans*a%c;} return ans;}
double distance(ll x1, ll y1, ll x2, ll y2){return sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));}

template<typename T>
void ppp(T n){cout << n << endl;}
template<typename T>
void dpp(T n){cerr << n << endl;}
template<typename T>
void vpp(T a){rep(i,a.size()){cout << a[i] << endl;}}
template<typename T>
void vdp(T a){rep(i,a.size()){cerr << a[i] << endl;}}

const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int ddx[8] = {1,0,-1,0,1,-1,-1,1};
const int ddy[8] = {0,1,0,-1,1,1,-1,-1};

int main(){

    cin.tie(0);
    ios::sync_with_stdio(false);

    int a, b;
    cin >> a >> b;
    Judge(a*b % 2);



    return 0;
}


Measured memory_bytes: 256
n = int(input())
words = [input().strip() for _ in range(n)]

said = []
prev = ""
safe = True
for w in words:
    if prev == "":
        prev = w
        said.append(w)
        continue
    else:
        if prev[-1] != w[0]:
            safe = False
            break
        else:
            if w in said:
                safe = False
                break
            else:
                prev = w
                said.append(w)

if safe:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 3064
#include <stdio.h>

int main(){
    double kg;
    
    while(scanf("%lf", &kg) != EOF){
        if (kg <= 48) printf("light fly\n");
        else if (48 < kg && kg <= 51) printf("fly\n");
        else if (51 < kg && kg <= 54) printf("bantam\n");
        else if (54 < kg && kg <= 57) printf("feather\n");
        else if (57 < kg && kg <= 60) printf("light\n");
        else if (60 < kg && kg <= 64) printf("light welter\n");
        else if (64 < kg && kg <= 69) printf("welter\n");
        else if (69 < kg && kg <= 75) printf("light middle\n");
        else if (75 < kg && kg <= 81) printf("middle\n");
        else if (81 < kg && kg <= 91) printf("light heavy\n");
        else if (91 < kg) printf("heavy\n");
    }
    
    return 0;
}

Measured memory_bytes: 608
#include<bits/stdc++.h>
#define maxn 505
using namespace std;

int n,x[maxn],c[maxn],a[maxn*maxn];

int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d",&x[i]);
	bool ER = 0;
	for(int i=1;i<=n*n;i++){
		for(int j=1;j<=n;j++) if(x[j] == i){
			c[j] ++;
			if(c[j] != j){
				ER = 1;
			}
			a[i] = j;
			break;
		}
		if(!a[i]){
			int p=0 , lc = n*n+2;
			for(int j=1;j<=n;j++) if(c[j] < j-1){
				if(x[j] < lc){
					lc = x[j];
					p = j;
				}
			}
			if(p){
				a[i] = p ,
				c[p] ++;
			}
		}
		if(!a[i]){
			for(int j=1;j<=n;j++) if(c[j] < n && x[j] < i){
				a[i] = j;
				c[j]++;
				break;
			}
		}
		if(!a[i]){
			ER = 1;
		}
	}
	if(ER){
		puts("No");
	}
	else{
		puts("Yes");
		for(int i=1;i<=n*n;i++) printf("%d%c",a[i]," \n"[i==n*n]);
	}
}

Measured memory_bytes: 2176
#include <cstdio>
using namespace std;
                                                                                                
  
int main(){
                                                                                                
   
    int n, a, b, c, d;

    char k[5];

    scanf("%s", &k );

    a = k[0] - '0';

    b = k[1] - '0';

    c = k[2] - '0';

    d = k[3] - '0';


    if( a + b + c + d == 7 ){

        printf("%d+%d+%d+%d=7\n", a, b, c, d );

        return 0;

        }

    if( a - b + c + d == 7 ){

        printf("%d-%d+%d+%d=7\n", a, b, c, d );

        return 0;

        }

    if( a - b - c + d == 7 ){

        printf("%d-%d-%d+%d=7\n", a, b, c, d );

        return 0;

        }
         
    if( a - b - c - d == 7 ){

        printf("%d-%d-%d-%d=7\n", a, b, c, d );

        return 0;

        }

    if( a + b - c + d == 7 ){

        printf("%d+%d-%d+%d=7\n", a, b, c, d );

        return 0;

        }

    if( a + b + c - d == 7 ){

        printf("%d+%d+%d-%d=7\n", a, b, c, d );

        return 0;

        }
   
    if( a + b - c - d == 7 ){

        printf("%d+%d-%d-%d=7\n", a, b, c, d );

        return 0;

        }

    if( a - b + c - d == 7 ){

        printf("%d-%d+%d-%d=7\n", a, b, c, d );

        return 0;

        }

    return 0;
                                                          
}

Measured memory_bytes: 128
#include<stdio.h>
#include<string.h>
int main()
{
int a,b,i,j;
	char c[100],s[100][100];
	while(~scanf("%d%d",&a,&b))
	{
		for (i=0;i<a;i++)
		{
			scanf("%s",&c);
			for (j=0;j<b;j++)
			{
				s[i][j]=c[j];
			}
		}
		for (i=0;i<b+2;i++)
		{
			printf("#");
		}
		printf("\n");
		for (i=0;i<a;i++)
		{
			printf("#");
			for (j=0;j<b;j++)
			{
				printf("%c",s[i][j]);
			}
			printf("#\n");
		}
		for (i=0;i<b+2;i++)
		{
			printf("#");
		}
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 128
import java.util.*;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        String[] s = new String[N];
        int[] t = new int[N];
        int totalTime = 0;
        for(int i=0;i<N;i++){
            s[i] = sc.next();
            int time = sc.nextInt();
            totalTime += time;
            if(i>0){
                t[i] = t[i-1] + time;
            } else {
                t[i] = time;
            }
        }
        String X = sc.next();
        for(int i=0;i<N;i++) {
            if(X.equals(s[i])){
                System.out.println(totalTime - t[i]);
                break;
            }
        }
    }

}


Measured memory_bytes: 22100
<?php 
  function kumiawase($n){
    $ans=0;
    if(count($n)<3) return 0;
    for($i=0;$i<count($n)-2;$i++){
      for($j=$i+1;$j<count($n)-1;$j++){
        for($k=$j+1;$k<count($n);$k++){
          if($n[$i]==$n[$j] || $n[$j]==$n[$k]) continue;
          if($n[$i]+$n[$j]>$n[$k] && $n[$i]+$n[$k]>$n[$j] && $n[$j]+$n[$k]>$n[$i]){
            $ans++;
          }
        }
      }
    }
    return $ans;
  }
function main(){
  $n = trim(fgets(STDIN));
  $l = explode(" ",trim(fgets(STDIN)));
  sort($l);
  $ans = kumiawase($l);
  echo $ans."\n";
}
main();

Measured memory_bytes: 15928
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
const ll INF = 1e12;
const ll MOD = 1000000000 + 7;
#define PB push_back
#define PF push_front
#define fi first
#define se second
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vpi vector<pii>
#define vll vector<ll>
#define vpl vector<pll>
#define vvi vector<vector<int>>
#define vvl vector<vector<ll>>
#define mii map<int, int>
#define mci map<char, int>
#define MX(x) *max_element(all(x))
#define MN(x) *min_element(all(x))
#define ios ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define pr_d(x) cout << fixed << setprecision(15) << x << endl
#define ud(c, x) distance(c.begin(), upper_bound(all(c), x))
#define ld(c, x) distance(c.begin(), lower_bound(all(c), x))
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define rep3(i, n) for (int i = (n - 1); i >= 0; --i)
#define rep4(i, a, b) for (int i = (a); i > (b); --i)
#define pb push_back
#define out(x) cout << x << "\n"
bool odd(int i) { return i % 2; }

#define all(v) v.begin(), v.end()
#define size(x) int(x.size())

int gcd(int a, int b) { return __gcd(a, b); }
int lcm(int a, int b) { return a * (b / gcd(a, b)); }
void Yes_No(bool f) {
  if (f)
    printf("Yes\n");
  else
    printf("No\n");
}
void YES_NO(bool f) {
  if (f)
    printf("YES\n");
  else
    printf("NO\n");
}

template <typename T>
void deb1(T x) {
  cout << "debug: " << x << "\n";
}

template <typename T>
bool chmax(T& a, const T& b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T>
bool chmin(T& a, const T& b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
//-------------------ここから回答する-----------------------

void solve(void) {
  string s;
  cin >> s;
  int ans = 0;
  if (s == "RRR")
    ans = 3;
  else if (s == "RRS")
    ans = 2;
  else if (s == "RSR")
    ans = 1;
  else if (s == "RSS")
    ans = 1;
  else if (s == "SRR")
    ans = 2;
  else if (s == "SRS")
    ans = 1;
  else if (s == "SSR")
    ans = 1;
  else
    ans = 0;
  out(ans);
}

int main(void) { solve(); }

Measured memory_bytes: 3596
///17571@nith.ac.in @Ankit Verma
#include <bits/stdc++.h>
using namespace std;
#define ff          first
#define ss          second
#define pb          push_back
#define MP          make_pair
#define int         long long
#define ll          long long
#define inf         0x3f3f3f3f
#define MOD         1000000007
#define ld          long double
#define eb          emplace_back
#define pii         pair<int,int>
#define ull         unsigned long long
#define all(v)      v.begin(), v.end()
#define f(i,x,n)    for(int i=x;i<n;i++)
#define fr(i,x,n)   for(int i=x;i>=n;i--)
#define fastio      ios::sync_with_stdio(false)

#define n_l '\n'
template <typename T, size_t N> int SIZE(const T (&t)[N]){ return N; } template<typename T> int SIZE(const T &t){ return t.size(); } string to_string(const string s, int x1=0, int x2=1e9){ return '"' + ((x1 < s.size()) ? s.substr(x1, x2-x1+1) : "") + '"'; } string to_string(const char* s) { return to_string((string) s); } string to_string(const bool b) { return (b ? "true" : "false"); } string to_string(const char c){ return string({c}); } template<size_t N> string to_string(const bitset<N> &b, int x1=0, int x2=1e9){ string t = ""; for(int __iii__ = min(x1,SIZE(b)),  __jjj__ = min(x2, SIZE(b)-1); __iii__ <= __jjj__; ++__iii__){ t += b[__iii__] + '0'; } return '"' + t + '"'; } template <typename A, typename... C> string to_string(const A (&v), int x1=0, int x2=1e9, C... coords); int l_v_l_v_l = 0, t_a_b_s = 0; template <typename A, typename B> string to_string(const pair<A, B> &p) { l_v_l_v_l++; string res = "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; l_v_l_v_l--; return res; } template <typename A, typename... C> string to_string(const A (&v), int x1, int x2, C... coords) { int rnk = rank<A>::value; string tab(t_a_b_s, ' '); string res = ""; bool first = true; if(l_v_l_v_l == 0) res += n_l; res += tab + "["; x1 = min(x1, SIZE(v)), x2 = min(x2, SIZE(v)); auto l = begin(v); advance(l, x1); auto r = l; advance(r, (x2-x1) + (x2 < SIZE(v))); for (auto e = l; e != r; e = next(e)) { if (!first) { res += ", "; } first = false; l_v_l_v_l++; if(e != l){ if(rnk > 1) { res += n_l; t_a_b_s = l_v_l_v_l; }; } else{ t_a_b_s = 0; } res += to_string(*e, coords...); l_v_l_v_l--; } res += "]"; if(l_v_l_v_l == 0) res += n_l; return res; } void dbgm(){;} template<typename Heads, typename... Tails> void dbgm(Heads H, Tails... T){ cout << to_string(H) << " | "; dbgm(T...); } 
#define debug(...) cout << "[" << #__VA_ARGS__ << "]: "; dbgm(__VA_ARGS__); cout << endl

void IO() {
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
}

int32_t main() {
    IO();
    fastio;
    cin.tie(nullptr);
    cout.tie(nullptr);
    int n; cin >> n;
    vector <int> ar(n);
    for (auto &i : ar) cin >> i;
    int res = 0;
	for (int i = 0; i < n; i++) {
		if ((i + 1) & 1 && ar[i] & 1) {
			res++;
		}
	}
	cout << res << endl;
    

    return 0;
}


Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
const int inf = 1001001001;
 
int main(){

    ll N;
    cin >> N;
    vector<ll> weight(N);
    rep(i,N){
        cin >> weight.at(i);
    }
    ll t=INF;
    for(ll i=0; i<N; i++){
        ll suma=0;
        ll sumb=0;
        for(ll j=0; j<i+1; j++){
            suma+=weight.at(j);
        }
        for(ll k=i+1; k<N; k++){
            sumb+=weight.at(k);
        }
        if(abs(suma-sumb)<t){
            t=abs(suma-sumb);
        }
    }

    cout << t << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include<map>
#include <algorithm>
#include <vector>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

int main() {
    string s;
    int n, k;
    cin >> n >> k >> s;
    if (s[k-1] == 'A') s[k-1] = 'a';
    if (s[k-1] == 'B') s[k-1] = 'b';
    if (s[k-1] == 'C') s[k-1] = 'c';
    cout << s << endl;
}

Measured memory_bytes: 256
//↓template↓

#include "bits/stdc++.h"
using namespace std;
#define Would
#define you
#define all(n)  n.begin(),n.end()
#define rall(n) n.rbegin(),n.rend()
typedef long long ll;
const ll INF = 1e18;
const ll MOD = 1e9 + 7;
const double pi = acos(-1);
const ll SIZE = 1 << 17;
int dx[] = { 1,0,-1,0 }, dy[] = { 0,1,0,-1 }, alp[30];
ll fac[200005], finv[200005], inv[200005];
vector<ll>dij;
struct edge { ll to, cost; };
vector<vector<edge> >G;

ll mod_pow(ll a, ll b) {
	ll res = 1, mul = a;
	for (int i = 0; i < 31; ++i) {
		if (b >> i & 1) {
			res *= mul;
			res %= MOD;
		}
		mul = (mul * mul) % MOD;
	}

	return res;
}

void addedge(int from, int to, int cost) {
	G[from].push_back({ to,cost });
	G[to].push_back({ from,cost });
}


template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }

template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
	return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}

template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T &t, const V &v) { t = v; }

template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T &t, const V &v) {
	for (auto &e : t) fill_v(e, v);
}

template<typename T>
void outp(vector<T>v) {
	for (int i = 0; i < v.size(); ++i) {
		cout << v[i];
		if (i != v.size() - 1) { cout << " "; }
	}
}

//↑template↑


int main() {



	string h;
	cin >> h;
	for (int i = 0; i < 3; ++i) {
		if (h[i] == h[i + 1]) { cout << "Bad" << endl; return 0; }
	}
	cout << "Good" << endl;












}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#define MAX 100001
int main()
{
  int youko1,youko2,haire1[MAX],haire2[MAX],i,j,k=1,l=1,samec=0,hida,migi,man,flag=0;
  //char c1,c2;
  scanf("%d",&youko1);
  //printf("%d\n",youko1);
  for(i=1;i<=youko1;i++)
    {
      scanf("%d",&haire1[i]);
      //printf("%d\n",haire1[i]);
      //haire1[i]=atoi(&c1);
    }
  scanf("%d",&youko2);
  for(j=1;j<=youko2;j++)
    {
      scanf("%d",&haire2[j]);
      //printf("%d\n",haire2[i]);
      //haire2[i]=atoi(&c2);
    }
  hida=1;
  migi=youko1+1;
  while(k<=youko2)
    {
      while(hida<migi)
	{
	  man=(hida+migi)/2;
	  if(haire2[k]==haire1[man])
	    {
	      flag=1;
	      break;
	    }
	  if(haire2[k]>haire1[man])
	    {
	      hida=man+1;
	    }
	  else
	    {
	      migi=man;
	    }
	}
      if(flag==1)
	{
	  samec++;
	}
      flag=0;
      hida=1;
      migi=youko1+1;
      k++;
    }
  printf("%d\n",samec);
  return 0;
}

/*
  if(youko1>youko2)
  {
  ooki=youko1;
  }
  else
  {
  ooki=youko2;
  }
  for(k=1;k<=ooki;k++)
  {
  strcmp(haire1[i]);
  }
  while(k<=youko2)
  {
  //printf("100\n");
  while(l<=youko1)
  {
  //printf("100\n");
  // printf("%d %d\n",l,haire2[k]);
  if(haire2[k]==haire1[l])
  {
  //printf("100\n");
  samec++;
  break;
  }
  else
  {
  l++;
  }
  }
  l=1;
  k++;
  }
  printf("%d\n",samec);
*/



Measured memory_bytes: 2296
import java.util.*;

public class Main {
	public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    List<Integer> a = new ArrayList<Integer>();

    for (int i = 0; i < n; i++) {
      int ai = sc.nextInt();
      a.add(ai);
    }

    Collections.sort(a, Collections.reverseOrder());

    int answer = 0;
    for (int i = 0; i < n; i++) {
      if (i % 2 == 0) {
        answer += a.get(i);
      } else {
        answer -= a.get(i);
      }
    }

    System.out.println(answer);
  }
}


Measured memory_bytes: 21844
#include <stdlib.h>
#include <cmath>
#include <cstdio>
#include <cstdint>
#include <string>
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
using namespace std;
using ll = long long;

int main(){
  int N;
  cin >> N;
  vector<int> a(N);
  for(int i=0;i<N;i++) cin >> a.at(i);
  sort(a.begin(),a.end(),greater<int>());
  int alice=0,bob=0;
  for(int i=0;i<N;i++){
    if(i%2==0) alice+=a.at(i);
    else bob+=a.at(i);
  }

  cout << alice-bob << endl;

  return 0;
}


Measured memory_bytes: 256
import sys
import math
import bisect

def solve(k, x):
    B = []
    l = max(-1000000, x - k + 1)
    r = min(1000000, x + k - 1)
    for i in range(l, r + 1):
        B.append(i)
    return B

def main():
    k, x = map(int, input().split())
    ans = solve(k, x)
    print(' '.join(list(str(a) for a in ans)))

if __name__ == "__main__":
    main()


Measured memory_bytes: 3060
#http://www.geocities.jp/m_hiroi/light/pyalgo61.html
class UF(object):
    def __init__(self, n):
        self.table = [None for i in range(n)]
    def find(self, x):
        if self.table[x] is None:
            return x
        else:
            self.table[x] = self.find(self.table[x])
            return self.table[x]
    def union(self, x, y):
        s1 = self.find(x)
        s2 = self.find(y)
        if s1 != s2:
            self.table[s2] = s1

n, k, l = [int(x) for x in raw_input().split()]
d = UF(n)
t = UF(n)
for i in range(k):
    p, q = [int(x) - 1 for x in raw_input().split()]
    d.union(p, q)
for i in range(l):
    r, s = [int(x) - 1 for x in raw_input().split()]
    t.union(r, s)
res = {}
for i in range(n):
    key = (d.find(i), t.find(i))
    res[key] = res.get(key, 0) + 1
for i in range(n):
    print res[(d.find(i), t.find(i))],


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

long long dp[11][1010];

int main() {
    dp[0][0] = 1;
    for (int i = 0; i <= 100; i++) { // 0, 1, 2, ... を使う場合についての総和を考える
        for (int j = 9; j >= 0; j--) {
            for (int k = 0; k <= 1000 - i; k++) {
                // i未満の数字を使ってj個の数でkを作れる分だけ
                // i以下の数字を使ってk+iを作れる
                dp[j + 1][k + i] += dp[j][k];
            }
        }
    }

    int n, s;
    while (cin >> n >> s, n || s) {
        cout << dp[n][s] << endl;
    }
    return 0;
}

Measured memory_bytes: 1240
// AOJ 0121 http:/judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0121/

#include <iostream>
#include <string>
#include <queue>
#include <map>
#include <sstream>

using namespace std;

string swp(string s,const int&a,const int&b){swap(s[a],s[b]);return s;}

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

    string s = "01234567";

    queue<string> q;
    map<string, int> m;

    q.push(s);
    m[s] = 0;

    while (q.size()) {
        string t = q.front(); q.pop();
        int idx = t.find('0');
        string u;
        if (idx - 1 >= 0 && idx != 4) {
            u = swp(t, idx, idx - 1);
            if (m.find(u) == m.end()) {
                m[u] = m[t] + 1;
                q.push(u);
            }
        }
        if (idx + 1 < 8 && idx != 3) {
            u = swp(t, idx, idx + 1);
            if (m.find(u) == m.end()) {
                m[u] = m[t] + 1;
                q.push(u);
            }
        }
        if (idx - 4 >= 0) {
            u = swp(t, idx, idx - 4);
            if (m.find(u) == m.end()) {
                m[u] = m[t] + 1;
                q.push(u);
            }
        }
        if (idx + 4 < 8) {
            u = swp(t, idx, idx + 4);
            if (m.find(u) == m.end()) {
                m[u] = m[t] + 1;
                q.push(u);
            }
        }
    }

    string line; stringstream ss;
    while (getline(cin, line)) {
        ss << line;
        string t = "";
        for (int i = 0; i < 8; ++i) {char c;ss >> c;t += c;}
        cout << m[t] << endl;
    }
}

Measured memory_bytes: 3496
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll gcdEx(ll a, ll b, ll *x, ll *y) {
    if (!a) {*x = 0; *y = 1; return b;}
    ll x1, y1, gcd = gcdEx(b % a, a, &x1, &y1); *x = y1 - (b / a) * x1; *y = x1; return gcd;
}
ll modI(ll b, ll m)      {ll x, y; gcdEx(b, m, &x, &y); return (x % m + m) % m;}
#define all(x) (x).begin(), (x).end()
#define make_unique(x) sort(all((x))); (x).resize(unique(all((x))) - (x).begin())

#define sum(a)     ( accumulate ((a).begin(), (a).end(), 0ll))
#define mine(a)    (*min_element((a).begin(), (a).end()))
#define maxe(a)    (*max_element((a).begin(), (a).end()))
#define mini(a)    ( min_element((a).begin(), (a).end()) - (a).begin())
#define maxi(a)    ( max_element((a).begin(), (a).end()) - (a).begin())
#define lowb(a, x) ( lower_bound((a).begin(), (a).end(), (x)) - (a).begin())
#define uppb(a, x) ( upper_bound((a).begin(), (a).end(), (x)) - (a).begin())
#define MOD                 1000000007
#define modA(a,b)           (((a%MOD)+(b%MOD))%MOD)
#define modS(a,b)           (((((a%MOD)-(b%MOD))%MOD)<0)?(ll)(MOD+((a%MOD)-(b%MOD))%MOD):(ll)(((a%MOD)-(b%MOD))%MOD))
#define modM(a,b)           (ll)((((ll)(a%MOD))*((ll)(b%MOD)))%MOD)
#define modD(a,b)           ((modI(b,MOD)*(a%MOD))%MOD)
ll modP(ll x, ll y)         {
    ll r = 1; x %= MOD; while (y > 0) {
        if (y & 1) {r = (r * x) % MOD;}
        y = y >> 1; x = (x * x) % MOD;
    } return r;
}
ll max(ll a, ll b) {return (a > b ? a : b);}
ll min(ll a, ll b) {return (a < b ? a : b);}
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) { cerr << name << " : " << arg1 << '\n'; }
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
    const char* comma = strchr(names + 1, ',');
    cerr.write(names, comma - names) << " = " << arg1 << " | "; __f(comma + 1, args...);
}
ll gcd( ll a, ll b )
{
    if (b == 0)
    {
        return a;
    }
    else
    {
        return gcd( b, (a % b) );
    }
}
ll lcm (ll a, ll b)
{
    ll ans = (a  / gcd(a, b)) * b;
    return ans;
}
ll sol(ll x, ll y, ll z)
{
    ll ans = (x * x) + (y * y) + (z * z) + (x * y) + (y * z) + (z * x);
    return ans;
}
void series(ll n)
{
    ll ans = 0;
    vector<ll> res(n + 1, 0);
    for (int i = 1; i <= n; i++)
    {
        for (int j = 1; j <= n; j++)
        {
            for (int k =  1; k <= n; k++)
            {
                if (sol(i, j, k) > n)
                {
                    break;
                }
                else
                    res[sol(i, j, k)]++;

            }
        }

    }
    // for (ll i : res) cout << i << "\n";

    for (int i = 1; i <= n; i++) cout << res[i] << "\n";

}
void solve()
{
    ll ans = 0;
    ll n;
    cin >> n;
    //cin >> n;


    // for (int i = 1; i <= n; i++)
    series(n);
    //  cout << ans << "\n";
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    int t ;
    t = 1;
    //  cin >> t;
    while (t--)
        solve();
    return 0;
}





Measured memory_bytes: 3568
#include <bits/stdc++.h>
using namespace std;
struct Fast {
    Fast() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(20);
    }
} fast;

long long mod = 1000000007;

long long div(long long a, long long b, long long c) { return b / c - (a - 1) / c; }

void print_binary(long long a) {
    for (int i = 31; i >= 0; i--) {
        cout << (a >> i & 1);
    }
    cout << endl;
}
long long modpow(long long m, long long n) {
    if (n == 0) return 1;
    if (n % 2 == 0) {
        long long t = modpow(m, n / 2);
        return t * t;
    } else {
        return modpow(m, n - 1) * m;
    }
}
void yes() {
    cout << "Yes" << endl;
    exit(0);
}
void no() {
    cout << "No" << endl;
    exit(0);
}
string op(string x) {
    if (x == "Sunny") {
        return ("Cloudy");
    }
    if (x == "Cloudy") {
        return ("Rainy");
    }
    if (x == "Rainy") {
        return ("Sunny");
    }
    return 0;
}

int main() {
    long long a, b, c, ra, rb, rc, g;
    string s;
    cin >> s;
    cout << op(s) << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define endl '\n'
using namespace std;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int k;
	cin>>k;
	string s;
	cin>>s;
	if(s.size()<=k) cout<<s<<endl;
	else{
		for(int i=0;i<k;i++) cout<<s[i];
		cout<<"..."<<endl;
	}
	return 0;
}


Measured memory_bytes: 3592
import java.util.*;
import java.math.*;
public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int x = in.nextInt();
		int y = in.nextInt();
		String ans ="No";
		for(int i = 0; i <= x; i++) {
			int one = i * 4;
			int two = (x - i) * 2;
			if((one + two) == y) {
				ans = "Yes";
			}
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 35832
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
using namespace std;

int main(){
    int A, B, K;
    cin >> A >> B >> K;

    vector<int> box;
    if(A+K < B){
        for (int i = A; i < A+K; i++)
        {
            box.push_back(i);
        }
        for (int i = B-(K-1); i <= B; i++){
            box.push_back(i);
        }
    }else{
        for (int i = A; i <= B; i++)
        {
            box.push_back(i);
        }
    }
    sort(box.begin(), box.end());
    
    box.erase(unique(box.begin(),box.end()),box.end());
    for (int i = 0; i < box.size(); i++){
        cout << box[i] << endl;
    }
}

Measured memory_bytes: 256
# E - This Message Will Self-Destruct in 5s
from collections import defaultdict

N = int(input())
A = list(int(x) for x in input().split())

di = defaultdict(int)
for i in range(N):
    di[i+1+A[i]] += 1

dj = defaultdict(int)
for j in range(N):
    dj[j+1-A[j]] += 1

ans = 0
for k, v in di.items():
    ans += v * dj.get(k,0)
print(ans)

Measured memory_bytes: 59592
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
#define int long long
#define P pair<long,long>
#define all(a) a.begin(),a.end()
using namespace std;
vector<int> count(vector<int> v){
    vector<int> ans;
    v.push_back(10000000000);
    int cnt=0;
    rep(i,v.size()-1){
        cnt++;
        if(v.at(i)!=v.at(i+1)){
            ans.push_back(cnt);
            cnt=0;
        }
    }
    return ans;
}
signed main(){
    int n; cin>>n;
    vector<int> a(n),aa(n+1,0);
    int sum=0;
    rep(i,n){
        cin>>a.at(i);
        sum+=a.at(i);
        aa.at(i+1)=sum;
    }
    sort(all(aa));
    vector<int> aaa=count(aa);
    int ans=0;
    rep(i,aaa.size()){
        ans+=aaa.at(i)*(aaa.at(i)-1)/2;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 8548
import bisect as bi
n = int(input())
a = list(map(int, input().split()))
a.sort()
ans = 0
for i in range(a[0], a[n-1]+1):
	ans = max(ans, bi.bisect_right(a, i+1)-bi.bisect_left(a, i-1))
print(ans)

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

using u32 = uint32_t;
using u64 = uint64_t;
using i32 = int32_t;
using i64 = int64_t;

int main()
{
    std::ios_base::sync_with_stdio(0);

    u32 price101 = 101, price102 = 102, price103 = 103, price104 = 104, price105 = 105;

    i32 money;
    std::cin >> money;

    if (money < 100)
    {
        std::cout << "0";
        return 0;
    }

    std::stringstream stream;
    stream << money;
    std::string digits = stream.str();

    u32 last2digits = (u32)std::stoi(digits.substr(digits.size() - 2, 2));

    while (money >= 0)
    {
        if (last2digits >= 5)
        {
            last2digits -= 5;
            money -= price105;
        }
        else if (last2digits >= 4)
        {
            last2digits -= 4;
            money -= price104;
        }
        else if (last2digits >= 3)
        {
            last2digits -= 3;
            money -= price103;
        }
        else if (last2digits >= 2)
        {
            last2digits -= 2;
            money -= price102;
        }
        else if (last2digits >= 1)
        {
            last2digits -= 1;
            money -= price101;
        }
        else if (last2digits == 0)
        {
            std::cout << "1";
            return 0;
        }
    }
    std::cout << "0";

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int 
ll n;
ll a[1000005];
ll dp[1000005];

ll fun(ll i){
	if(i>=n)
		return 0;
	if(dp[i]!=-1)
		return dp[i];
	if(i<n-1){
		return dp[i] = min(abs(a[i]-a[i+1])+fun(i+1) , abs(a[i]-a[i+2])+fun(i+2));
	}else{
		return dp[i]= abs(a[i]-a[i+1]);
	}

 
}
int main(){

	
	cin>>n;
	int i;
	memset(dp,-1,sizeof(dp));
	
	for(i=1;i<=n;i++){
		cin>>a[i];
	}	
	cout<<fun(1)<<"\n";
 
	return 0;
} 

Measured memory_bytes: 15300
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <utility>
#include <queue>
#include <set>
#include <map>

using namespace std;
typedef  long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
#define  MP make_pair
#define  PB push_back
#define inf  1000000007
#define rep(i,n) for(int i=0;i<(int)(n);++i)

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}


ll mod = inf;
ll dp[401][401];
ll s[401][401];
long long calc(long long  k,long long m){
	if(m==0)return 1;
	if(m==1)return k%mod;
	long long s = calc(k,m/2);
	if(m%2==0){
		return (s*s)%mod;
	}else{
		long long ans;
		ans = (s*s)%mod;
		return (k*ans)%mod;
	}
}
ll n,c;
vector<ll>a,b;
ll saiki(ll p,ll q){
    if(dp[p][q]!=0)return dp[p][q];
    if(p==n){
        return (s[q][b[p]]+mod-s[q][a[p]-1])%mod;
    }
    ll ans = 0;
    for(ll i=0;i<=q;i++){
        ans = (ans+ ((s[i][b[p]]+mod-s[i][a[p]-1])%mod)*saiki(p+1,q-i)) %mod;

    }
    return dp[p][q] = ans;
}

int main(){
    cin >> n >> c;
    a.push_back(0);
    b.push_back(0);
    for(int i=0;i<n;i++){
        ll tmp;
        cin >> tmp;
        a.push_back(tmp);
    }
    for(int i=0;i<n;i++){
        ll tmp;
        cin >> tmp;
        b.push_back(tmp);
    }
    for(ll i=0;i<401;i++){
        for(ll j=1;j<401;j++){
            s[i][j] = (s[i][j-1]+ calc(j,i))%mod;  
        }
    }
    cout << saiki(1,c) << endl;
    return 0;
}

Measured memory_bytes: 2816
#include <iostream>
#define MAX 101

using namespace std;

int main(){
  int n, i, j, k, l, m;
  bool g[MAX][MAX];
  
  for(i=1;i<MAX;++i){
    for(j=1;j<MAX;++j)
      g[i][j] = false;
  }
  
  cin >> n;
  for(i=1;i<=n;++i){
    cin >> k >> l;
    for(j=1;j<=l;++j){
      cin >> m;
      g[k][m] = true;
    }
  }
  
  for(i=1;i<=n;++i){
    for(j=1;j<=n;++j){
      cout << g[i][j];
      if(n != j)cout << " ";
    }
    cout << "\n";
  }
  
  return 0;
}



Measured memory_bytes: 3108
#![allow(non_snake_case)]

use std::collections::VecDeque;
use std::io::{stdin, Read};
use std::str::FromStr;
fn read_option<T: FromStr>() -> Option<T> {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok()
}
fn read<T: FromStr>() -> T {
    let opt = read_option();
    opt.expect("failed to parse token")
}

fn main() {
    let H: usize = read();
    let W: usize = read();
    let mut map: Vec<Vec<char>> = vec![];
    for _ in 0..H {
        let row: String = read();
        map.push(row.chars().collect());
    }
    let mut ans = 0;
    for i in 0..H {
        for j in 0..W {
            if map[i][j] == '#' {
                continue;
            }
            ans = std::cmp::max(ans, wfs(i, j, &map, H - 1, W - 1));
        }
    }
    println!("{}", ans);
}

fn wfs (i: usize, j: usize, map: &Vec<Vec<char>>, i_max: usize, j_max: usize) -> usize {
    let mut depth_map: Vec<Vec<Option<usize>>> = vec![vec![None; j_max + 1]; i_max + 1];
    let mut queue: VecDeque<(usize, usize)> = VecDeque::new();
    queue.push_front((i, j));
    depth_map[i][j] = Some(0);
    let dir = vec![(-1, 0), (0, -1), (1, 0), (0, 1)];
    let mut max_depth = 0;
    while let Some((i, j)) = queue.pop_back() {
        let depth = depth_map[i][j].unwrap();
        max_depth = std::cmp::max(max_depth, depth);
        for &(di, dj) in &dir {
            let ni = i as i32 + di;
            let nj = j as i32 + dj;
            if ni < 0 || nj < 0 || ni > i_max as i32 || nj > j_max as i32 {
                continue;
            }
            let ni: usize = ni as usize;
            let nj: usize = nj as usize;
            if map[ni][nj] == '#' {
                continue;
            }
            if depth_map[ni][nj].is_some() {
                continue;
            }
            queue.push_front((ni, nj));
            depth_map[ni][nj] = Some(depth + 1);
        }

    }
    return max_depth;
}

Measured memory_bytes: 4352
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

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

	int ans = 0;

	for (int a = 1; a <= 10; ++a) {
		for (int b = 1; a + b <= 10; ++b) {
			for (int c = 1; a + b + c <= 10; ++c) {
				string s;
				s.append(a, '3');
				s.append(b, '5');
				s.append(c, '7');
				do {
					auto x = stoll(s);
					if (x <= N) {
						++ans;
					}
				} while (next_permutation(s.begin(), s.end()));
			}
		}
	}
	cout << ans << endl;
}


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

using namespace std;

const int MaxN = 2e5 + 25;

bool used[MaxN];

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n;
    cin >> n;

    if(n == 3)
    {
        cout << 2 << ' ' << 5 << ' ' << 63 << '\n';
        return 0;
    }

    if(n == 4)
    {
        cout << 2 << ' ' << 5 << ' ' << 20 << ' ' << 63 << '\n';
        return 0;
    }

    if(n < 150000)

    {
        vector <int> v1, v2;

        int k = n / 2;

        long long s1 = 0, s2 = 0;



        for(int i = 1, step = 1; i <= 10000 && step < k; ++i)
            if(!used[i * 3])
            {
                v2.push_back(i * 3);
                used[i * 3] = true;
                s2 += i * 3;
                ++step;
            }

        for(int i = 1, step = 1; i <= 15000 && step < n - k; ++i)
            if(!used[i * 2])
            {
                v1.push_back(i * 2);
                used[i * 2] = true;
                s1 += i * 2;
                ++step;
            }

        for(int i = 30000; ; --i)
            if(!used[i])
                if(i % 2 == 0)
                {
                    if((s1 + i) % 3 == 0)
                    {
                        v1.push_back(i);
                        s1 += i;
                        used[i] = true;
                        break;
                    }
                }

        for(int i = 30000; ; --i)
            if(!used[i])
                if(i % 3 == 0)
                {
                    if(i != v1.back())
                        if((s2 + i) % 2 == 0)
                            {
                                v2.push_back(i);
                                s2 += i;
                                used[i] = true;
                                break;
                            }
                }

        if(v1.size() + v2.size() != n)
            while(1);

        for(int x : v1)
            cout << x << ' ';
        for(int x : v2)
            cout << x << ' ';

        cout << '\n';

    }
    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define END '\n'
#define int long long
#define pb push_back
#define pii pair<int, int>
#define ff first
#define ss second
#define trace(x) cerr<<x<<END;
#define loop(i, a, b) for(int i = (a); i < (b); i++)
#define loopb(i, b, a) for(int i = (b); i > (a); --i) 
const int mod = 1e9+7;
const int mod1 = 998244353;
const int inf = 9223372037ll;
int n,m,k,ans = 0;
vector<string> grid(10);
void chk(set<int> row,set<int> col)
 {
  int c = 0;
  loop(i,0,n)
   loop(j,0,m)
    c += (grid[i][j] == '#' && row.count(i) != 0 && col.count(j) != 0);
  /*loop(i,0,n)
   cerr<<grid[i]<<END;*/
  /*for(auto x : row)
     cerr<<x<<" ";
  cerr<<END;
  for(auto x : col)
     cerr<<x<<" ";
  cerr<<END;
  cerr<<END;*/
  if(c==k)
     ans++;
 }
set<set<int>> row,col;
void find_rows(int pos,set<int> s)
 {
  if(pos>=n)
     return;
  row.insert(s);
  find_rows(pos+1,s);

  s.insert(pos);
  row.insert(s);
  find_rows(pos+1,s);

 }
void find_cols(int pos,set<int> s)
 {
  if(pos>=m)
     return;
  col.insert(s);
  find_cols(pos+1,s);

  s.insert(pos);
  col.insert(s);
  find_cols(pos+1,s);

 }
void solve()
  {
   cin>>n>>m>>k;
   loop(i,0,n)
    cin>>grid[i];
   find_rows(0,{});
   find_cols(0,{});
   for(auto x : row)
    for(auto y : col)
     chk(x,y);
   cout<<ans;
  } 
signed main()
 {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0); 
     solve();
  //cerr<<END<<1.0*clock();
  return 0;
} 

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define REP(i, n) for (long long i = 0; i < (long long)n; i++)
//#define _GLIBCXX_DEBUG
using namespace std;
using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using Vl = vector<ll>;
using vi = vector<int>;
using Graph = vector<vi>;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  // std::cout << std::fixed << std::setprecision(15); //"for float-base
  // problem"
  ll N;
  cin >> N;
  Vl P(N);
  REP(i, N) cin >> P.at(i);
  int ans = 0;
  int MIN = 9999999;
  for (auto a : P) {
    if (a > MIN)
      continue;
    else {
      ans++;
      MIN = a;
    }
  }

  cout << ans << endl;
}

Measured memory_bytes: 1792
#include <stdio.h>
int main(void){
    // Your code here!
    int a=0, m;
    double n;
    
    scanf("%lf",&n);
    m=n;
    while(m>0){
        a+=(int)m%10;
        m=m/10;
    }
    if((int)n%a==0) printf("Yes\n");
    else printf("No\n");
    return 0;
}

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

num_kill = 0
bb = 0 
aa = A[0]
for i in range(N):
    num_kill += min(B[i], aa + A[i + 1])
    bb = B[i] - aa
    if bb < 0:
        bb = 0

    aa = A[i + 1] - bb
    if aa < 0:
        aa = 0

print(num_kill)


Measured memory_bytes: 82020
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int A,B;
  cin >>A >>B;
  int score=0;
  if(A>=B+1){
    score =A +A-1;
  }
  else if(A+1<=B){
    score =B+B-1;
  }
  else{
    score =A+B;
  }
  cout<<score<<endl;
}
  

Measured memory_bytes: 256
#define taskname "test"

#include <bits/stdc++.h>

using namespace std;

#define sz(x) (int)x.size()
#define fi first
#define se second

typedef long long lli;
typedef pair<int, int> pii;

const int maxn = 2e5 + 5;

int n, K;
int a[maxn];

lli pre[maxn];
vector<lli> v;

struct fenwick
{
    int val[maxn];

    void init()
    {
        fill(begin(val), end(val), 0);
    }

    void update(int x, int k)
    {
        for(; x < maxn; x += x & -x)
            val[x] += k;
    }

    int get(int x)
    {
        int res = 0;
        for(; x > 0; x -= x & -x)
            res += val[x];
        return res;
    }
} tree;

void read_input()
{
    cin >> n >> K;
    for(int i = 1; i <= n; ++i)
    {
        cin >> a[i];
        a[i] -= K;
    }
}

int pos(lli val)
{
    return lower_bound(v.begin(), v.end(), val) - v.begin() + 1;
}

void solve()
{
    pre[0] = 0;
    for(int i = 1; i <= n; ++i)
        pre[i] = pre[i - 1] + a[i];
    for(int i = 0; i <= n; ++i) v.push_back(pre[i]);
    sort(v.begin(), v.end());
    v.erase(unique(v.begin(), v.end()), v.end());
    tree.init();
    tree.update(pos(0), 1);
    lli ans = 0;
    for(int i = 1; i <= n; ++i)
    {
        ans += tree.get(pos(pre[i]));
        tree.update(pos(pre[i]), 1);
    }
    cout << ans << '\n';
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    read_input();
    solve();
}



Measured memory_bytes: 5104
import java.util.Scanner;
class Main
{
  public static void main(String[] args)
  {
    Scanner scan = new Scanner(System.in);
    int[] rec = new int[2], cir = new int[3];

    for(int i=0 ; i<2 ; i++){rec[i] = scan.nextInt();}
    for(int i=0 ; i<3 ; i++){cir[i] = scan.nextInt();}
    if((cir[0] - cir[2]) >= 0 && (cir[0] + cir[2]) <= rec[0] && (cir[1] - cir[2]) >= 0 && (cir[1] + cir[2]) <= rec[1])
      System.out.println("Yes");
    else
      System.out.println("No");
  }
}

Measured memory_bytes: 26296
#include<stdio.h>
#include<string.h>

int main(){
    int N, Q;
    char s[110000];
    int check[110000];
    int l[110000], r[110000];
    int i, j, k;
    int ans;

    scanf("%d %d", &N, &Q);
    scanf("%s", &s);
    for(i=0; i<Q; i++){
        scanf("%d %d", &l[i], &r[i]);
    }

    for(i=0; i<N+2; i++){
        check[i] = 0;
    }

    for(i=1; i<N; i++){
        if(s[i-1] == 'A' && s[i] == 'C'){
            check[i] = check[i-1] + 1;
        }else{
            check[i] = check[i-1];
        }
        //printf("%d ", check[i]);
    }
    check[N] = check[N-1];

    for(i=0; i<Q; i++){
        ans = check[r[i]-1] - check[l[i]-1];
        printf("%d\n", ans);
    }

    return 0;
}


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

typedef long long lint;
typedef pair<int, int> P;
#define REP(i, x, n) for(int i = x ; i < n ; ++i)
#define rep(i, n) for(int i = 0 ; i < n ; ++i)
#define repr(i, n) for(int i = n - 1 ; i >= 0 ; --i)
#define ALL(x) (x).begin(), (x).end()
#define SORT(x) sort((x).begin(), (x).end())

const int IINF = 1e9 + 10;
const long long LLINF = (long long)1e18 + 10;
const long long MOD = (long long)1e9 + 7;
const int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1};
const int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};
const double EPS = 1e-8;

vector< vector<int> > g;
vector< P > dis;

void dfs(int now, int depth, vector<bool> done){
    done[now] = true;
    dis[now].first = max(dis[now].first, depth);
    rep(i, g[now].size()){
        if(!done[g[now][i]]){
            dfs(g[now][i], depth + 1, done);
        }
    }
    return;
}

int main(){
    int m, n;
    cin >> m >> n;
    g.resize(m);
    dis.resize(m);
    rep(i, m){
        dis[i].first = -1;
        dis[i].second = i;
    }
    vector<int> degree(m);
    bool flag = false;
    rep(i, n){
        int x, y;
        cin >> x >> y;
        --x;
        --y;
        g[y].push_back(x);
        ++degree[x];
        if(y == 1){
            flag = true;
        }
    }
    if(!flag){
        int j = -1;
        rep(i, m){
            if(degree[i] == 0 && i != 1){
                j = i;
                break;
            }
        }
        g[1].push_back(j);
    }
    vector<bool> done(m);
    dfs(1, 0, done);
    SORT(dis);
    repr(i, m){
        cout << dis[i].second + 1 << endl;
    }
    return 0;
}


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

#define all(x) begin(x), end(x)

using i64 = int_fast64_t;
using f64 = double;
using p64 = pair<i64, i64>;

constexpr i64 INF = INT_FAST64_MAX / 2;
constexpr f64 EPS = DBL_EPSILON;

template<typename T>
T c(i64 n, i64 k) {
    if (k < 0 || n < k) return 0;
    if (n - k < k) k = n - k;
    T res = 1;
    for (i64 i = 1; i <= k; i++) res = res * (n - i + 1) / i;
    return res;
}

void solve() {
    i64 n, p;
    cin >> n >> p;
    i64 odd = 0, even = 0;
    for (i64 i = 0; i < n; i++) {
        i64 a;
        cin >> a;
        (a % 2 ? odd : even)++;
    }

    i64 ans0 = 1l << even;
    i64 ans1 = 0;
    for (i64 i = p; i <= odd; i += 2) ans1 += c<i64>(odd, i);
    cout << ans0 * ans1 << endl;
}

int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); ++i)

using namespace std;
using ll = long long;
using v1 = vector<int>;
using v2 = vector<vector<int>>;
using v3 = vector<vector<char>>;

struct Node{
	int key;
	Node* parent;
	Node* left;
	Node* right;
};

Node* root;
Node* NIL;

void insert(int key){
	Node* x = root;
	Node* y = NIL;
	Node* z;
	z = (Node*)malloc(sizeof(Node));
	z->key = key;
	z->left = NIL;
	z->right = NIL;
	while(x != NIL){
		y = x;
		if(x->key < z->key){
			x = x->right;
		}else{
			x = x->left;
		}
	}
	z->parent = y;
	if(y == NIL){
		root = z;
	}else{
		if(y->key > z->key){
			y->left = z;
		}else{
			y->right = z;
		}
	}
}

void find(int key, Node* x){
	if(x == NIL){
		cout << "no" << endl;
		return;
	}
	if(x->key == key){
		cout << "yes" << endl;
		return;
	}
	if(x->key > key){
		find(key, x->left);
	}else{
		find(key, x->right);
	}
}

void preorder(Node* x){
	cout << " " << x->key;
	if(x->left != NIL) preorder(x->left);
	if(x->right != NIL) preorder(x->right);
}

void inorder(Node* x){
	if(x->left != NIL) inorder(x->left);
	cout << " " << x->key;
	if(x->right != NIL) inorder(x->right);
}

int main(){
	int n;
	cin >>n;
	rep(i,n){
		string s;
		int k;
		cin >> s;
		if(s[0] == 'i'){
			cin >> k;
			insert(k);
		}
		if(s[0] == 'p') {
			inorder(root);
			cout << endl;
			preorder(root);
			cout << endl;
		}
		if(s[0] == 'f'){
			cin >> k;
			find(k, root);
		}
	}
}



Measured memory_bytes: 21904
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;
 
#define fi first
#define se second
#define mp make_pair
#define pb push_back
 
typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef unsigned long long ull;
typedef long double ld; 
typedef tree<ii, null_type, less<ii>, rb_tree_tag, tree_order_statistics_node_update> pbds;

int a[111111];
int dp[111111];

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	int n,k; cin>>n>>k;
	for(int i=0;i<n;i++) cin>>a[i];
	dp[0]=0;
	for(int i=1;i<=k;i++)
	{
		dp[i]=0;
		for(int j=0;j<n;j++)
		{
			if(i-a[j]>=0&&dp[i-a[j]]==0) dp[i]=1;
		}
	}
	cout<<(dp[k]==1?"First":"Second")<<'\n';
}


Measured memory_bytes: 640