akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"

using namespace std;

using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using vvvll = vector<vector<vector<ll>>>;
using vvvvll = vector<vector<vector<vector<ll>>>>;
using pl4 = pair<ll,ll>;
using str = string;
using vpl4 = vector<pair<ll,ll>>;

#define sz size()
#define be begin()
#define en end()
#define fi first
#define se second
#define pb push_back
#define mp make_pair

#define llin(x) ll (x);cin >>(x);
#define stin(x) str (x);cin >>(x);
#define vllin(x,n) vll (x)(n);FOR(i,0,n-1){cin >>(x)[i];}
#define vllin2(a,b,n) vll (a)(n);vll (b)(n);FOR(i,0,n-1){cin >>(a)[i]>>(b)[i];}
#define vllin3(a,b,c,n) vll (a)(n);vll (b)(n);vll (c)(n);FOR(i,0,n-1){cin >>(a)[i]>>(b)[i]>>(c)[i];}
#define vlling(x,n) (x).assign(n,0);FOR(i,0,n-1){cin >>(x)[i];}
#define vlling2(a,b,n) (a).assign(n,0);(b).assign(n,0);FOR(i,0,n-1){cin >>(a)[i]>>(b)[i];}
#define vlling3(a,b,c,n) (a).assign(n,0);(b).assign(n,0);(c).assign(n,0);FOR(i,0,n-1){cin >>(a)[i]>>(b)[i]>>(c)[i];}
#define vpl4in(x,n) vpl4 (x)((n),mp(0,0));FOR(i,0,n-1){cin >>x[i].fi>>x[i].se;}
#define FOR(i,a,b) for(ll i = a ; i <= b ; i++)
#define rFOR(i,b,a) for(ll i = a; i >= b ; i--)
#define SORT(x) sort(x.be, x.en)
#define rSORT(x) sort(x.rbegin(), x.rend())
#define say(x) cout<<(x);
#define sal(x) cout<<(x)<<endl;
#define says(x) cout<<(x)<<(' ');
#define sas cout<<(' ');
#define sayR(x) cout<<fixed<<setprecision(10)<<(x);
#define salR(x) cout<<fixed<<setprecision(10)<<(x)<<endl;
#define yn(a) cout <<((a)?"yes":"no")<<endl;
#define Yn(a) cout <<((a)?"Yes":"No")<<endl;
#define YN(a) cout <<((a)?"YES":"NO")<<endl;
#define Imp(a) cout <<((a)?"Possible":"Impossible")<<endl;
#define IMP(a) cout <<((a)?"POSSIBLE":"IMPOSSIBLE")<<endl;
#define pow(a,b) ll(pow(a,b))

ll MOD=1000000007;

signed main(){
        llin(n);
        vector<pair<str,pair<ll,ll>>> a(n);
        str s;
        ll p;
        FOR(i,0,n-1){
                cin >>s;
                cin >>p;
                a[i].fi=s;
                a[i].se.fi=100-p;
                a[i].se.se=i+1;
        }
        SORT(a);
        FOR(i,0,n-1){
                sal(a[i].se.se)
        }
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args)
	{
		Scanner scan = new Scanner(System.in);
		int height = scan.nextInt();
		int width = scan.nextInt();
		
		while(height != 0 || height != 0)
		{
			for(int i = 0;i < height;i++)
			{
				for(int j = 0;j < width;j++)
				{
					System.out.print("#");
				}
				System.out.println("");
			}
			System.out.println("");
			height = scan.nextInt();
			width = scan.nextInt();
		}
	}
}

Measured memory_bytes: 25820
import java.util.*;

public class Main {
	public static void main(String[] args) {
		long i,j;
		Scanner sc = new Scanner(System.in);
		long a = Long.parseLong(sc.next());
		long b = Long.parseLong(sc.next());
		long c = Long.parseLong(sc.next());
		long d = Long.parseLong(sc.next());
		sc.close();
		long cd = c*d/gcd(c,d);
		long cnt = 0;
		cnt = b/c - (a-1)/c;
//		System.out.println(cnt);
		cnt += b/d - (a-1)/d;
//		System.out.println(cnt);
		cnt -= b/cd - (a-1)/cd;
//		System.out.println(cnt);
		System.out.println(b-a-cnt+1);
	}
	public static long gcd(long a, long b) {
		long t;
		while((t=a%b)!=0) {
			a = b;
			b = t;
		}
		return b;
	}
}


Measured memory_bytes: 23764
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define MOD (1000000007LL)

ll ppow(ll a,ll b){
	a %= MOD;
	ll res = 1;
	while(b){
		if(b & 1) res = (res * a) % MOD;
		a = (a * a) % MOD;
		b >>= 1;
	}
	return res;
}

ll fact(int n){
    if(n==0) return 1;
    ll res = 1;
    for(int i=1;i<=n;i++){
        res = (res * i) % MOD;
    }
    return res;
}

ll comb(int n, int r){
    return (((fact(n) * ppow(fact(n-r),MOD-2)) % MOD) * ppow(fact(r),MOD-2)) % MOD;
}

int main(void){
    int x,y;
    cin >> x >> y;
    if((x+y)%3){
        cout << 0 << endl;
        return 0;
    }
    int a = (2*x-y)/3;
    int b = (2*y-x)/3;
    if(a<0 || b<0){
        cout << 0 << endl;
        return 0;
    }
    cout << comb(a+b,a) << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define endl '\n';
using namespace std;
using ll = long long;
using P = pair<int,int>;
constexpr ll INF = 9e18;
constexpr int inf = 1e9;
constexpr double INFD = 1e100;
constexpr ll mod = 1000000007;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
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; }
// ---------------------------------------------------------------------------
ll N,K;
vector<vector<int>> G;

ll dfs(int v,int p=-1){
  ll use;
  if(p == -1){
    use = K-1;
  }else{
    use = K-2;
  }
  if(G[v].size() > K){
    return 0;
  }else{
    ll res = 1;
    for(int nv: G[v]){
      if(nv == p) continue;
      res *= use;
      res %= mod;
      use--;
    }
    for(int nv: G[v]){
      if(nv == p) continue;
      res *= dfs(nv,v);
      res %= mod;
    }
    return res;
  }
}

int main(){
  cin >> N >> K;
  G.resize(N);
  for(int i=0; i<N-1; i++){
    int u,v;
    cin >> u >> v;
    u--;
    v--;
    G[u].emplace_back(v);
    G[v].emplace_back(u);
  }
  ll ans = K * dfs(0);
  ans %= mod;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 10368
#include<bits/stdc++.h>
using namespace std;
#define ll              long long
#define pb              push_back
#define read(s)         freopen(#s,"r",stdin)
#define write(s)        freopen(#s,"w",stdout)
#define lead_zero(x)    __builtin_clzll(x)
#define trail_zero(x)   __builtin_ctz(x)
#define total_1s(x)     __builtin_popcount(x)
 
int ext_gcd ( int A, int B, int *X, int *Y )
{
    int x2, y2, x1, y1, x, y, r2, r1, q, r;
    x2 = 1;
    y2 = 0;
    x1 = 0;
    y1 = 1;
    for (r2 = A, r1 = B; r1 != 0; r2 = r1, r1 = r, x2 = x1, y2 = y1, x1 = x, y1 = y )
    {
        q = r2 / r1;
        r = r2 % r1;
        x = x2 - (q * x1);
        y = y2 - (q * y1);
    }
    *X = x2;
    *Y = y2;
    return r2;
}
 
 
bool linearDiophantine ( int A, int B, int C, int *x, int *y )
{
    int g = __gcd ( A, B );
    if ( C % g != 0 ) return false; //No Solution
 
    int a = A / g, b = B / g, c = C / g;
    ext_gcd( a, b, x, y ); //Solve ax + by = 1
 
    if ( g < 0 )   //Make Sure gcd(a,b) = 1
    {
        a *= -1;
        b *= -1;
        c *= -1;
    }
 
    *x *= c;
    *y *= c; //ax + by = c
    return true; //Solution Exists
}
 
int main ()
{
    ll i,j,k,n,m;
    cin>>n>>m;
    for(i=0;i<=n;i++)
    {
        for(j=0;j<=n-i;j++)
        {
            ll k=n-i-j;
            if(10000*i+5000*j+1000*k==m && k>-1 && j>-1 && i>-1)
            {
                cout<<i<<" "<<j<<" "<<k<<endl;
                return 0;
            }
        }
    }
    cout<<"-1 -1 -1"<<endl;
}

Measured memory_bytes: 256
import collections


def mod_pow(a, n, mod):
    result = 1
    a_n = a
    while n > 0:
        if n & 1:
            result = result * a_n % mod
        a_n = a_n * a_n % mod
        n >>= 1
    return result


def main(n, d):
    MOD = 998244353
    counter = collections.Counter(d)
    if counter[0] != 1 or d[0] != 0:
        return 0
    pows = [mod_pow(a=counter[i - 1], n=counter[i], mod=MOD) for i in
            range(1, max(counter.keys()) + 1)]
    patterns = 1
    for p in pows:
        patterns *= p
        patterns %= MOD
    return patterns


if __name__ == '__main__':
    N = int(input())
    D = list(map(int, input().split()))
    print(main(n=N, d=D))


Measured memory_bytes: 19936
N,M=map(int,input().split())
count=0
A=[[] for i in range(3)]
for i in range(M):
    s,c=map(int,input().split())
    if s==1 and c==0 and N>=2:
        count+=1
    else:
        A[s-1].append(c)
B=[]
for i in range(N):
    if len(A[i])>=1:
        B.append(A[i][0])
        for j in range(1,len(A[i])):
            if A[i][j]!=A[i][0]:
                count+=1
    elif N>=2:
        B.append(max(1-i,0))
    else:
        B.append(0)
if count>0:
    print(-1)
elif N==3:
    print(B[0]*(10**2)+B[1]*(10**1)+B[2])
elif N==2:
    print(B[0]*(10**1)+B[1])
else:
    print(B[0])

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

int main () {
    string s,t;
    cin>> s >> t;
    sort(s.begin(), s.end());
    sort(t.begin(), t.end());
    reverse(t.begin(), t.end());

    if (s < t) cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

using ll = long long;
using ull = unsigned long long;
#define repi(n) for (long long i = 0; i < (n); ++i)
#define repj(n) for (long long j = 0; j < (n); ++j)
#define repk(n) for (long long k = 0; k < (n); ++k)
#define rep(i, a, b) for (auto i = (a); i < (b); ++i)
#define itr(itr) for (auto&& v : (itr))
#define updatemax(t, v) (t = std::max(t, (v)))
#define updatemin(t, v) (t = std::min(t, (v)))

ll sc[10][10];
int main() {
  auto msd = [](const int& x) {
    int y = x;
    while (y >= 10) y /= 10;
    return y;
  };
  int n;
  cin >> n;
  rep(i, 1, n + 1) sc[msd(i)][i % 10]++;
  ll res = 0;
  rep(i, 1, 10) rep(j, 1, 10) res += sc[i][j] * sc[j][i];
  cout << res << endl;
}


Measured memory_bytes: 3556
import java.util.*;
public class Main{
    public static void main(String[] args) {
        Scanner in  = new Scanner(System.in);
        int n = in.nextInt();
        if(n==0){
            System.out.println(0);
            return;
        }
        int []arr = new int[n];
        for(int i=0;i<n;i++)arr[i] = in.nextInt();
        int []dp = new int[n];
        Arrays.fill(dp,-1);
        int ans = recur(0,dp,arr);
        System.out.println(ans);
    }
    public static int recur(int index,int []dp,int []arr){
        if(index==dp.length)return 0;
        if(index==dp.length-1)return 0;
        if(dp[index]!=-1)return dp[index];
        int ret = Math.abs(arr[index]-arr[index+1])+recur(index+1,dp,arr);
        if(index+2<arr.length){
            ret = Math.min(ret,Math.abs(arr[index]-arr[index+2])+recur(index+2,dp,arr));
        }
        return dp[index] = ret;
    }
}


Measured memory_bytes: 62772
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<string>
#include<utility>
#define rep(i, n) for(int i=0;i<n;i++)
using namespace std;
int main(){
	int n, m;
	cin>>n>>m;
	vector<pair<int, string>> v;
	int p;
	string s;
	rep(i, m){
		cin>>p>>s;
		v.push_back(make_pair(p-1, s));
	}
	pair<bool, int> a[n];
	int b=0, c=0;
	for(int i=0;i<n;i++){
		a[i]=make_pair(0, 0);
	}
	rep(i, m){
		if(v[i].second=="WA" && a[v[i].first].first==0)
			a[v[i].first].second++;
		if(v[i].second=="AC" && a[v[i].first].first==0)
			b++, a[v[i].first].first=1, c+=a[v[i].first].second;
	}
	cout<<b<<" "<<c<<endl;
	return 0;
}

Measured memory_bytes: 7280
#互いに素なa,bについて、a*x+b*y=1の一つの解
def extgcd(a,b):
    r = [1,0,a]
    w = [0,1,b]
    while w[2]!=1:
        q = r[2]//w[2]
        r2 = w
        w2 = [r[0]-q*w[0],r[1]-q*w[1],r[2]-q*w[2]]
        r = r2
        w = w2
    #[x,y]
    return [w[0],w[1]]

# aの逆元(mod m)を求める。(aとmは互いに素であることが前提)
def mod_inv(a,m):
    if a%m!=0:
      x = extgcd(a,m)[0]
      return (m+x%m)%m
      

#nCk mod m を計算する(デフォルトの引数は10**9+7)
def c_mod(n,k,m=10**9+7):
  res = 1
  for i in range(1,n+1):
      if (i%m)!=0:
        res = res*i%m
      else:
        res=res/i%m
  for i in range(1,k+1):
      if (i%m)!=0:
        res = res*mod_inv(i,m)%m
      else:
        res=res/i%m
  for i in range(1,n-k+1):
      if (i%m)!=0:
        res = res*mod_inv(i,m)%m
      else:
        res=res/i%m
  return res


x,y=map(int,input().split())
if (2*x-y)%3==0 and (2*y-x)%3==0 and (2*y-x)>=0 and (2*x-y)>=0 :
  l=int((2*x-y)/3)
  k=int((2*y-x)/3)
  ans=c_mod(l+k,k)

else:
  ans=0
print(ans)


Measured memory_bytes: 42092
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <tuple>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;
 
int main(){
    ll n, m;
    cin >> n >> m;

    vector<vector<pair<ll, ll>>> v(n+1);  // v[i][j] : 県i(iは1-index)に属する市の中でj番目に早く誕生した市の (誕生年, 市の番号)
    exrep(i, 1, m) {
        ll p, y;
        cin >> p >> y;
        v[p].pb(make_pair(y, i));
    }

    exrep(i, 1, n) {
        if(v[i].size() == 0) {
            continue;
        }
        sort(all(v[i]));
    }
    
    vector<pair<ll, ll>> w(m+1);  // w[i] : 市i(iは1-index)の (属する県の番号, その県の中で誕生した順番)
    exrep(i, 1, n) {
        rep(j, v[i].size()) {
            ll k = v[i][j].second;
            w[k] = make_pair(i, j+1);
        }
    }

    exrep(i, 1, m) {
        ll A = w[i].first;
        ll B = w[i].second;
        printf("%06lld", A);
        printf("%06lld\n", B);
    }

    re0;
}

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

using namespace std;
int n, m, ans, h[100005], a[100005], b[100005], c[100005];
int main()
{
    cin>> n>> m;
    for(int i=1; i<=n; i++) cin>> h[i];
    for(int i=1; i<=m; i++){
        cin>> a[i]>> b[i];
        if(h[a[i]] == h[b[i]]){
            c[a[i]]=-1;
            c[b[i]]=-1;
        }
        else if(h[a[i]] < h[b[i]]) c[a[i]]=-1;
        else c[b[i]]=-1;
    }
    for(int i=1; i<=n; i++)
        if(c[i]!=-1)
            ans++;
    cout<< ans;
    return 0;
}


Measured memory_bytes: 5156
S = input()
N = len(S)

flag = 0
if S[0] == "A":
    s = S[2:N-1]
    if s.count("C") == 1:
        x = S.index("C")
        s1 = S[1:x]
        s2 = S[x+1:]
        S = s1+s2
        if S.islower():
            flag = 1
        else:
            flag = 0
if flag == 1:
    print("AC")
else:
    print("WA")

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAX_T = 30000;
int T;
ll res[30003];
vector<int> ps;
unordered_map<int,ll> dp[2];

void init(){
  bool f[30003];
  memset( f,0,sizeof(f) );
  for(int i=2;i<=30000;i++){
    if( f[i] ) continue;
    ps.emplace_back(i);
    for(int j=i+i;j<=30000;j+=i)
      f[j] = true;
  }
}

void solve(){
  for(int p : ps){
    dp[0][p]++;
    for( auto q : dp[0] ){
      if( q.first + p > MAX_T ) continue; 
      dp[1][q.first+p] += q.second;
    }
    for( auto q : dp[1] ){
      if( q.first + p > MAX_T ) continue;
      if( q.first <= p )
        continue;      
      res[ q.first + p ] += q.second;
    }
  }
}

int main(){
  init();
  solve();
  while( cin >> T && T ){
    cout << res[T] << endl;
  }
}

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

using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using LL = long long;
using VL = vector<LL>;
using VVL = vector<VL>;
using PLL = pair<LL, LL>;
using VS = vector<string>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))

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

#define FF first
#define SS second
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}
template<class S, class T>
ostream& operator<<(ostream& os, const pair<S,T>& p){
  return os << p.FF << " " << p.SS;
}
template<class T>
void maxi(T& x, T y){
  if(x < y) x = y;
}
template<class T>
void mini(T& x, T y){
  if(x > y) x = y;
}


const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;

int dp[101][101];

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

  int N, P;
  cin >> N >> P;
  vector<PII> xs(N);
  REP(i,N) cin >> xs[i];

  // cost[i][j] := i??\?????????j??\????????§?????´???????????¨???????¶??????±?????????
  VVI cost(N, VI(N));
  REP(i,N){
	int t = 0, sum = 0;
	FOR(j,i,N){
	  int nt = max(0, xs[j].SS - max(0, xs[j].FF - t));
	  sum += nt;
	  t = nt;
	  cost[i][j] = sum;
	}
  }

  fill((int*)dp, (int*)dp+101*101, -1e9);
  // dp[i][j] := i??\????????§??§????¨?j??\??????i??\??????????????£?????¨??????????????±?????????????????§
  REP(i,N+1){
	dp[i][0] = P;
	if(i) dp[i][i] = P - cost[0][i-1];
  }

  REP(i,N+1){
	if(i)
	  REP(j,N+1)
		maxi(dp[i][j], dp[i-1][j]);
		   
	for(int x=0;x<=N;++x)
	  for(int j=1;j<=i;++j){
		if(i-j-1>=0 && x-j>=0 && i-j <= i-1)
		  maxi(dp[i][x], dp[i-j-1][x-j] - cost[i-j][i-1]);
	  }
  }
  
  int ans = 0;
  REP(i,N+1) REP(x,N+1)
	if(dp[i][x] >= 0)
	  maxi(ans, x);

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 3276
L = input()

dp_equal = 1 # a+bがLとイコールの場合
dp_less = 0  # a+bがLと未満の場合

MOD = 10**9+7
        
for s in L:
    next_equal = 0
    next_less = 0
    # (a, b) = (0, 0)
    if s == '0':
        next_equal += dp_equal
        next_less += dp_less 
    else:
        next_less += dp_equal + dp_less
        
    # (a, b) = (1, 0) or (0, 1)
    if s == '0':
        next_less += dp_less * 2
    else:
        next_equal += dp_equal * 2
        next_less += dp_less  * 2
    
    dp_equal, dp_less = next_equal % MOD, next_less % MOD
    
print((dp_equal + dp_less) % MOD)

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



int main(void) {
  ll n;
  cin >> n;
  ll b;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      b = n / i;
    }
  }
  string s = to_string(b);
  cout << s.size() << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=200005;
int tot,color[maxn],head[maxn],sz[maxn],sum[maxn];
ll ans[maxn];
struct node{
	int to,next;
}edge[maxn*2];
void add_edge(int u,int v){
	++tot;
	edge[tot].to=v;
	edge[tot].next=head[u];
	head[u]=tot;
}
ll f(ll n){return n*(n+1)/2;}
void dfs(int u,int fa){	
	int c=color[u],last,delta,v;
	sz[u]=1;
	ll pre=sum[c];
	for(int i=head[u];i;i=edge[i].next){
		v=edge[i].to;
		if(v==fa) continue;
		last=sum[c];
		dfs(v,u);
		delta=sum[c]-last;
		sz[u]+=sz[v];
		ans[c]-=f(sz[v]-delta);
	}
	sum[c]=pre+sz[u];
}
int main(){
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%d",&color[i]);
		ans[i]=f(n);
	}
	for(int i=1;i<=n-1;i++){
		int u,v;
		scanf("%d%d",&u,&v);
		add_edge(u,v);
		add_edge(v,u);
	}
	dfs(1,0);
	for(int i=1;i<=n;i++){
		ans[i]-=f(n-sum[i]);
		printf("%lld\n",ans[i]);
	}
	return 0;
}

Measured memory_bytes: 27000
import numpy as np
import math
import collections
import fractions
import itertools

def solve():
    n = int(input())
    a = list(map(int, input().split()))
    ruiseki = [0]
    ans = 0
    for i in range(n):
        ruiseki.append(ruiseki[i]+a[i])
    c = collections.Counter(ruiseki).values()
    for i in c:
        ans += i*(i-1)//2
    print(ans)
    return 0

if __name__ == "__main__":
    solve()
#fooooooooooooooo!! yattaze!! AC!!

Measured memory_bytes: 51392
#include <cstdio>
#define MAX_N 100001

bool IsPrime[MAX_N];

void get_primes() {
    for (int x = 1; x*x < MAX_N; x++) {
        for (int y = 1; y*y < MAX_N; y++) {
            int n = (4*x*x) + (y*y);
            if (n <= MAX_N && (n % 12 == 1 || n % 12 == 5)) {
                IsPrime[n] ^= true;
            }
            n = (3*x*x)+(y*y);
            if (n <= MAX_N && n % 12 == 7) {
                IsPrime[n] ^= true;
            }
            n = (3*x*x)-(y*y);
            if (x > y && n <= MAX_N && n % 12 == 11) {
                IsPrime[n] ^= true;
            }
        }
    }

    for (int r = 5; r*r < MAX_N; r++) {
        if (IsPrime[r]) {
            for (int i = r*r; i < MAX_N; i += r*r) {
                IsPrime[i] = false;
            }
        }
    }
    IsPrime[2] = IsPrime[3] = true;
}

int main() {
    int Q, l, r;
    int cnt[MAX_N] = {0};

    get_primes();

    for (int i = 3; i <= MAX_N; i += 2) {
        if (IsPrime[i] && IsPrime[(i+1)/2]) { cnt[i]++; }
    }
    for (int i = 1; i <= MAX_N; i++) {
        cnt[i] += cnt[i-1];
    }

    scanf("%d", &Q);

    while (Q--) {
        scanf("%d %d", &l, &r);
        printf("%d\n", cnt[r] - cnt[l-1]);
    }

    return 0;
}

Measured memory_bytes: 1024
import sys
sys.setrecursionlimit(250000)

def main():
    n = int(input())

    numbers =[]
    for i in range(n):
        numbers.append(input().split())

    count = 0
    zoronum =-1
    exists = False
    for obj in numbers:
        if obj[0] == obj[1]:
            if count == 0:
                count = 1
            else:
                count = count + 1
            if count >= 3:
                exists = True
        else:
            count = 0

    if exists:
        print("Yes")
    else:
        print("No")

main()



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

typedef long long ll;

vector<ll> upf(ll x) {
  vector<ll> rv;
  for (ll i = 2; i*i <= x; ++i) {
    if (x % i == 0) {
      rv.push_back(i);
    }
    while (x % i == 0) {
      x /= i;
    }
  }
  if (x > 1) {
    rv.push_back(x);
  }
  return rv;
}

bool pc(vector<ll> & A) {
  vector<bool> d(1e6+1, false);
  for (auto ai : A) {
    if (ai == 1) {
      continue;
    }
    auto pf = upf(ai);
    for (ll pfi : pf) {
      if (d[pfi]) {
        return false;
      }
      d[pfi] = true;
    }
  }
  return true;
}

ll gcd(ll a, ll b) {
  if (a < b) {
    swap(a,b);
  }
  while (b) {
    a %= b;
    swap(a,b);
  }
  return a;
}

bool sc(vector<ll> & A) {
  ll g = A[0];
  for (auto ai : A) {
    g = gcd(g, ai);
  }
  return (g==1);
}

void solve(long long N, std::vector<long long> A){
  if (sc(A)) {
    if (pc(A)) {
      cout << "pairwise coprime";
    } else {
      cout << "setwise coprime";
    }
  } else {
    cout << "not coprime";
  }
  cout << endl;
}

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


Measured memory_bytes: 11160
// #pragma GCC optimize("Ofast")
// #pragma GCC optimize ("unroll-loops")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
 
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace __gnu_pbds;
using namespace std;
#define gcd(a,b) __gcd(a,b)
#define ll long long int
#define ld double
#define pi pair<ll,ll>
#define pb push_back
#define pf push_front
#define pu push
#define po pop
#define fi first
#define se second
#define mk make_pair
#define ve vector
#define lr(n) for(ll i=0;i<n;i++)
#define all(x) x.begin(),x.end()
#define be begin
#define sz(a) (ll)a.size()
#define INF 1e18
 
typedef tree <ll, null_type, less <ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
// order_of_key(val): returns the number of values less than val
// find_by_order(k): returns an iterator to the kth largest element (0-based)
 
ll mod=1e9+7;
// ll gcd(ll a, ll b){
//     if(a<b) swap(a,b);
//     if(b==0) return a;
//     return gcd(b,a%b);
// }
 
// ll fun(ll x, ll y){
//     ll rem=1;
//     while(y!=0){
//         if(y%2==1){
//             rem=(rem*x)%mod;
//         }
//         x=(x*x)%mod;
//         y/=2;
//     }
//     return rem;
// }


ll ar[101];
ll dp[102][100001];

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	ll n,k;
	cin>>n>>k;
	for(ll i=1;i<=n;i++) cin>>ar[i];
	for(ll i=1;i<=n;i++) for(ll j=0;j<=k;j++) dp[i][j]=0;
	for(ll i=0;i<=ar[n];i++) dp[n][i]=1;
	for(ll i=1;i<=k;i++) dp[n][i]=(dp[n][i]+dp[n][i-1])%mod;
	for(ll i=n-1;i>=1;i--){
		for(ll j=0,x;j<=k;j++){
			x=max(0LL, j-ar[i]);
			if(x==0)
				dp[i][j]=dp[i+1][j];
			else dp[i][j]=(dp[i+1][j]-dp[i+1][x-1]+mod)%mod;
		}
		for(ll j=1;j<=k;j++) dp[i][j]=(dp[i][j]+dp[i][j-1])%mod;
	}
	cout << (dp[1][k]-dp[1][k-1]+mod)%mod << "\n";
	return 0;
}

Measured memory_bytes: 78336
#include<iostream>
using namespace std;
int main() {
  int N;
  cin >> N;
  long long ans = 0;
  int i;
  for(i=1;i<=N;i++) {
    if(i%3 != 0 && i%5 != 0) {
      ans += i;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3636
from collections import Counter
from itertools import combinations


n = int(input())
lst_s = [input()[0] for _ in range(n)]
lst_march = [s for s in lst_s if s in "MARCH"]
cnt_s = Counter(lst_march)
lst_num = list(cnt_s.values())
cmb_num = list(combinations(lst_num, 3))
ans = sum(c[0] * c[1] * c[2] for c in cmb_num)
print(ans)

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

using namespace std;

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

    int max_val = 0;
    int min_val = 1e+9;
    int previous = 0;
    for (int i = 0; i < N; ++i)
    {
        int n;
        cin >> n;
        if (max_val < n)
        {
            max_val = n;
        }
        if (n < min_val)
        {
            min_val = n;
        }
    }

    cout << (max_val - min_val) << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <queue>
#include <stack>
#include <string>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>

#define rep(i, n) for(int i = 0; i < n; i ++)
#define COUNT(i, n) for(int i = 1; i <= n; i ++)
#define ALL(T) T.begin(), T.end()
#define mp make_pair
#define pb push_back
#define ITER(c) __typeof((c).begin())
#define each(c, it) for(ITER(c) it = (c).begin(); it != (c).end(); it++)
#define H first
#define R second

using namespace std;

typedef pair<int, int> pii;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<string> vs;

const int INF = 1 << 24;
const int N = 201;

int dp[N];

int main(void){
    for(int n; cin >> n, n;){
        vector<pii> in(N);
        rep(i, n) cin >> in[i].H >> in[i].R;

        int m; cin >> m;
        rep(i, m) cin >> in[n + i].H >> in[n + i].R;

        rep(i, n + m)  dp[i] = 0;

        sort(in.begin(), in.begin() + n + m);

        rep(i, n + m) rep(j, i) if(in[j].H < in[i].H && in[j].R < in[i].R) dp[i] = max(dp[i], dp[j] + 1);

        cout << *max_element(dp, dp + m + n) + 1 << endl;
    }

    return 0;
}

Measured memory_bytes: 1200
using System;

namespace ABC148A
{
    class Program
    {
        static void Main(string[] args)
        {
            var A = int.Parse(Console.ReadLine());
            var B = int.Parse(Console.ReadLine());

            if (A == 1 && B == 2) Console.WriteLine(3);
            else if (A == 1 && B == 3) Console.WriteLine(2);
            else if (A == 2 && B == 1) Console.WriteLine(3);
            else if (A == 2 && B == 3) Console.WriteLine(1);
            else if (A == 3 && B == 1) Console.WriteLine(2);
            else if (A == 3 && B == 2) Console.WriteLine(1);
        }
    }
}

Measured memory_bytes: 11092
import unittest


class TestB(unittest.TestCase):
    def test_1(self):
        self.assertEqual(think(8, 3, 4), 4)

    def test_2(self):
        self.assertEqual(think(8, 0, 4), 0)

    def test_3(self):
        self.assertEqual(think(6, 2, 4), 2)


def solve():
    n, a, b = read()
    result = think(n, a, b)
    write(result)


def read():
    return read_int(3)


def read_int(n):
    return read_type(int, n, sep=' ')


def read_float(n):
    return read_type(float, n, sep=' ')


def read_type(t, n, sep):
    return list(map(lambda x: t(x), read_line().split(sep)))[:n]


def read_line(n=0):
    if n == 0:
        return input().rstrip()
    else:
        return input().rstrip()[:n]


def think(n, a, b):
    mode = a + b
    if n % mode == 0:
        return a * (n // mode)
    else:
        blue = a * (n // mode)
        remain = n - (n // mode) * mode
        if a <= remain:
            return blue + a
        else:
            return blue + remain


def write(result):
    print(result)


if __name__ == '__main__':
    # unittest.main()
    solve()

Measured memory_bytes: 49392
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <vector>
#include <cmath>
#include <functional>
#include <limits>
#include <map>
using namespace std;

typedef long long ll;
const ll INF = 1ll<<60;
#define rep1(i, n) for(ll i = 1; i <=(ll)(n); i++)
#define rep0(i, n) for(ll i = 0; i <=(ll)(n); i++)

int main(){
    ll n,x,d;
    ll ans = 0;
    cin >> n >> x >> d;
    if(d == 0){
        if(x == 0){
            cout << 1 << endl;
            return 0;
        }else{
            cout << n+1 << endl;
            return 0;
        }
    }

    map<int , vector<pair<ll,ll> > > mp;
    rep0(k, n){
        ll s = k*x;
        ll l = k*(k-1)/2;
        ll rtol = k*(n-k);
        s += l*d;
        mp[((s%d)+d)%d].push_back(make_pair(s,rtol));
    }

    for(auto p:mp){
        vector<pair<ll,ll> > section = p.second;
        int size = section.size();
        rep0(i, size-1) section[i].first = (section[i].first - p.first)/d;
        vector<pair<ll,ll> > event;
        rep0(i, size-1){
            event.push_back(make_pair(section[i].first, 1));
            event.push_back(make_pair(section[i].first+section[i].second+1, -1));
        }
        sort(event.begin(), event.end());
        ll cnt_cumulative = 0;
        ll pre_endpoints = -INF;
        rep0(i, event.size()-1){
            ll endpoints = event[i].first;
            ll cnt = event[i].second;
            ll length = endpoints - pre_endpoints;
            if(cnt_cumulative > 0) ans += length;
            cnt_cumulative += cnt;
            pre_endpoints = endpoints; 
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 24952
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int a,b,c;
    cin>>a>>b>>c;
    if(a==b&&b==c){
        cout<<"1"<<endl;
    }else if(a!=b&&b!=c&&c!=a){
        cout<<"3"<<endl;
    }else{
        cout<<"2"<<endl;
    }
    return 0;
}

Measured memory_bytes: 764
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define PI 				acos(-1)
#define mp				make_pair
#define pb				push_back
#define all(a)			(a).begin(), (a).end()
#define sz(a)			a.size()
#define srt(a)			sort(all(a))
#define mem(a, h)		memset(a, (h), sizeof(a))
#define f 				first
#define s 				second
#define MOD1			998244353
#define fore(i, b, e)	for(int i = b; i < e; i++)
#define forg(i, b, e, m)	for(int i = b; i < e; i+=m)
int in(){int r=0,c;for(c=getchar();c<=32;c=getchar());if(c=='-') return -in();for(;c>32;r=(r<<1)+(r<<3)+c-'0',c=getchar());return r;}

using namespace std;
using namespace __gnu_pbds;

typedef long long 		ll;
typedef unsigned long long 		ull;
typedef pair<int, int>  ii;
typedef vector<int>     vi;
typedef vector<ii>      vii;
typedef vector<ll>      vll;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
const int tam = 100010;
const int MOD = 1e9+7;
const double EPS = 1e-9;

int main()
{
	ios::sync_with_stdio(0); cin.tie(0);
	//freopen("qwe.txt", "r", stdin);
	//freopen("asd.txt", "w", stdout);
	int gri[3][3];
	fore(i, 0, 3) fore(j, 0, 3) cin>>gri[i][j];
	int ar[3];
	int posi, mini = 200;
	fore(i, 0, 3) mini = min(mini, gri[0][i]);
	fore(i, 0, mini + 1)
	{
		fore(j, 0, 3)
		ar[j] = gri[0][j] - mini;
		set<int> st;
		bool bo = true;
		fore(j, 1, 3)
		{
			st.clear();
			fore(k, 0, 3)
				st.insert(gri[j][k] - ar[k]);
			if(st.size() > 1) bo = false;
		}
		if(bo)
		{
			cout<<"Yes\n";
			return 0;
		}
	}
	cout<<"No\n";
	return 0;
}

// read the question correctly (is y a vowel? what are the exact constraints?)
// look out for SPECIAL CASES (n=1?) and overflow (ll vs int?) ARRAY OUT OF BOUNDSS2

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 P = pair<int,int>;

int main() {
  int h, a;
  cin >> h >> a;

  if (h % a == 0) cout << (h / a) << endl;
  else cout << (h / a) + 1 << endl;
}

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

int main(){
	int n,m,v,ans;
	while(1){
		vector<int>  b ;
		ans=0;
		cin >> n >> m ;
		if( (n==0) && (m==0) ){
			return 0;
		}
		for(int i=0;i<n;i++){
			cin >> v;
			ans += v;
			b.push_back(v);
		}
		sort(b.begin(),b.end());
		reverse(b.begin(),b.end());
		for(int i=m-1;i<n;i+=m){
			ans -= b[i];
		}
		cout << ans << "\n";
	}
}

Measured memory_bytes: 1228
import java.util.*;
public class Main {
  public static void main (String[] args) {
    Scanner sc = new Scanner (System.in);
    int N = sc.nextInt();
    int[] array = new int[N];
    for (int i=1; i<N; i++) {
      int n = sc.nextInt();
      array[n-1] += 1;
    }
    for (int ans : array)
      System.out.println(ans);
  }
}

Measured memory_bytes: 70204
N, M = map(int, input().split())
Lamp_switch = []
for _ in range(M):
    S = list(map(int, input().split()))[1:]
    Lamp_switch.append(S)

Pon = list(map(int, input().split()))
ans = 0

for i in range(2**N):
    Cou = [0] * M
    for j in range(N):
        if (i >> j) & 1 == 1:
            for k in range(M):
                if (j+1) in Lamp_switch[k]:
                    Cou[k] += 1
                    Cou[k] %= 2

    if Cou == Pon:
        ans += 1

print(ans)

Measured memory_bytes: 3064
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
const int INF = 1e9;
int gcd(int a, int b) {
	int temp;
	if (a < b) {
		temp = a;
		a = b;
		b = temp;
	}
	if (a%b == 0)return b;
	return gcd(b, a%b);
}
int main() {
	int N, X;
	cin >> N >> X;
	int x[100010];
	int G[100010];
	for (int i = 0; i < N; ++i) {
		int a;
		cin >> a;
		x[i] = abs(X - a);
	}
	if (N == 1)cout << x[0] << endl;
	else {
		int ans;
		for (int i = 0; i < N - 1; ++i) {
			ans = gcd(x[i], x[i + 1]);
			x[i + 1] = ans;
		}
		cout << ans << endl;
	}
	return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=1LL<<61;

int main() {
  string s,t;
  cin >> s >> t;
  reverse(s.begin(),s.end());
  if(s==t) cout << "YES" << endl;
  else cout << "NO" << endl;
}

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


using namespace std;

using ll   = long long;
using ii   = pair   < int , int >;
using i3   = pair   < int , ii  >;
using li   = pair   < ll  , int >;
using lii  = pair   < ll  , ii  >;
using pll  = pair   < ll  , ll  >;
using vi   = vector < int       >;
using vl   = vector < ll        >;
using vii  = vector < ii        >;
using vli  = vector < li        >;
using vpll = vector < pll       >;
using vi3  = vector < i3        >;
using vlii = vector < lii       >;


const int N = 2e5 + 5;
const ll INF = 1e17 + 7;
const double eps = 1e-9 , PI = acos(-1);

ll dp[110][N];

void solve(int testCase){

    int n , W;
    scanf("%d %d" , &n , &W);

    vi v(n+1 , 0) , w(n+1 , 0);
    for(int i = 1 ; i <= n ; i ++){
            scanf("%d %d" , &w[i] , &v[i]);
    }

    for(int i = 1 ; i <= n ; i ++){
            for(int j = 0 ; j <= W ; j ++){
                    dp[i][j] = dp[i-1][j];

                    if(j - w[i] >= 0){
                            dp[i][j] = max(dp[i][j] , dp[i-1][j - w[i]] + v[i]);
                    }
            }
    }

    ll ans = 0;
    for(int i = 1 ; i <= n ; i ++){
            for(int j = 0 ; j <= W ; j ++){
                    ans = max(ans , dp[i][j]);
            }
    }
    printf("%lld\n" , ans);

    /*
    vl dp(W + 1 , 0);

    for(int i = 0 ; i < n ; i ++){
            for(int j = W ; j >= 0 ; j --){
                    if(j - w[i] < 0)continue;
                    dp[j] = max(dp[j] , dp[j - w[i]] + 1ll * v[i]);
            }
    }

    ll ans = *max_element(dp.begin() , dp.end());
    printf("%lld\n" , ans);
    */

}

main(){

    int t = 1;
    // scanf("%d" , &t);

    for(int testCase = 1 ; testCase <= t ; testCase ++){
            solve(testCase);
    }

    return 0;
}


Measured memory_bytes: 156416
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
    int N;
    vector<int> A;

    cin >> N;
    A = vector<int>(N);
    for (int i = 0; i < N; i++) cin >> A[i];

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

    long long int sum = 0;
    vector<int> M;
    
    M.push_back(A[0]);
    A.erase(A.begin());
    
    while (!A.empty()){
        int max;
        int insert_p = 0;
        int insert_v = 0;
        
        max = abs(A[0] - M[0]);

        if (abs(A.back() - M[0]) > max){
            max = abs(A.back() - M[0]);
            insert_p = 0;
            insert_v = 1;
        }

        if (abs(A[0] - M.back()) > max){
            max = abs(A[0] - M.back());
            insert_p = 1;
            insert_v = 0;
        }

        if (abs(A.back() - M.back()) > max){
            max = abs(A.back() - M.back());
            insert_p = 1;
            insert_v = 1;
        }

        int v;
        if (insert_v == 0){
            v = A[0];
            A.erase(A.begin());
        } else {
            v = A.back();
            A.pop_back();
        }

        if (insert_p == 0){
            M.insert(M.begin(), v);
        } else M.push_back(v);

        sum += max;
    }

    cout << sum << endl;

    return 0;
}



Measured memory_bytes: 1276
ans = {}
t = input()
for i in range(len(t)):
    if t[i] not in ans:
        ans[t[i]] = i + 1

    for j in range(i+1, len(t)):
        if t[i] == t[j]:
            if t[i] in ans:
                ans[t[i]] = max(ans[t[i]], abs(j - i))
            else:
                ans[t[i]] = abs(j - i)
            
            break
    
        if j == len(t) - 1:
            ans[t[i]] = max(ans[t[i]], abs(j + 1 - i))


print(min(ans.values()) - 1)

Measured memory_bytes: 3064
#include<stdio.h>
#include<string.h>
int main()
{
    char s[10006];
    int a,i;
    scanf("%d",&a);
    scanf("%s",s);
    for(i=0; s[i]!='\0'; i++){
        if(s[i]>='A' && s[i]<='Z'){
            s[i]=s[i]+a;
            if(s[i]>=91){
                s[i]=s[i]-91;
                s[i]=s[i]+65;
            }
        }
    }
    printf("%s\n",s);
}


Measured memory_bytes: 128
N, M, C = map(int, input().split())
b = list(map(int, input().split()))
count = 0
for i in range(N):
    a = list(map(int, input().split()))
    sum_a = 0
    for j in range(M):
        sum_a += a[j]*b[j]
    sum_a += C
    if sum_a > 0:
        count += 1
print(count)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
constexpr int MOD = 998244353;
constexpr int INF = numeric_limits<int>::max() / 2;
typedef pair<int,int> P;
using Graph = vector<vector<int>>;


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

	int N;
	cin >> N;
	int a, b, c;
	int ans = 0, num = 0;
	int cou0{}, cou1{};
	P med = P(INF, 0);
	multiset<P> st;
	rep(i,N){
		cin >> a;
		if(a == 1){
			++num;
			cin >> b >> c;
			P p = P(b,num);
			ans += c;
			st.insert(p);
			if(med.first == INF){
				med = p;
			}
			else{
				if(med > p){
					cou0++;
				}
				else{
					cou1++;
				}
				ans += abs(med.first-b);
			}

			if(cou1 - cou0 == 2){
				auto itr = st.lower_bound(med);
				++itr;
				P p1 = *itr;
				ans -= abs(p1.first - med.first);
				med = p1;
				cou0 = 0, cou1 = 0;
			}
			else if(cou0 - cou1 == 1){
				auto itr = st.lower_bound(med);
				--itr;
				P p1 = *itr;
				// ans -= abs(med.first - p1.first);
				med = p1;
				cou0 = 0, cou1 = 1;
			}
		}
		else{
			cout << med.first << ' ' << ans << endl;
		}
	}
 }

Measured memory_bytes: 12800
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <map>
#include <set>
#include <queue>

#ifdef _DEBUG
#define DMP(x) cerr << #x << ": " << x << "\n"
#else
#define DMP(x) ((void)0)
#endif

const int MOD = 1000000007, INF = 1111111111; 
using namespace std;
typedef long long lint;

int main() {

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

	char c;
	cin >> c;

	if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u') cout << "vowel";
	else cout << "consonant";

	return 0;
}

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

struct dat {
  int d;
  vector<int> c;
  vector<vector<int>> s;
};

int calc(const dat &a, const vector<int> &last, int day, int t) {
  int v = 0;
  v += a.s.at(day - 1).at(t);
  for (int i = 0; i < 26; i++) {
    if (i == t) continue;
    v -= a.c.at(i) * (day - last.at(i));
  }
  return v;
}

int main() {
  int d;
  cin >> d;
  vector<int> c(26);
  vector<vector<int>> s(d, vector<int>(26));
  for (int i = 0; i < 26; i++) {
    cin >> c.at(i);
  }
  for (int i = 0; i < d; i++) {
    for (int j = 0; j < 26; j++) {
      cin >> s.at(i).at(j);
    }
  }
  dat a = {d, c, s};
  
  int w = 5;
  vector<vector<int>> last(w, vector<int>(26)), ans(w);
  vector<int> score(w);
  for (int i = 0; i < d; i++) {
    vector<tuple<int, int, int>> idx;
    for (int j = 0; j < w; j++) {
      vector<int> best(w, -1e9), best_t(w);
      for (int t = 0; t < 26; t++) {
        int v = calc(a, last.at(j), i + 1, t);
        if (v > best.at(0)) {
          best.at(w - 1) = v;
          best_t.at(w - 1) = t;
        }
        for (int k = w - 1; k > 0; k--) {
          if (best.at(k - 1) < best.at(k)) {
            swap(best.at(k - 1), best.at(k));
            swap(best_t.at(k - 1), best_t.at(k));
          }
        }
      }
      for (int k = 0; k < w; k++) {
        idx.emplace_back(score.at(j) + best.at(k), j, best_t.at(k));
      }
    }
    sort(idx.rbegin(), idx.rend());
    vector<vector<int>> newans(w);
    for (int j = 0; j < w; j++) {
      score.at(j) = get<0>(idx.at(j));
      newans.at(j) = ans.at(get<1>(idx.at(j)));
      newans.at(j).push_back(get<2>(idx.at(j)));
    }
    ans = newans;
  }
  for (int i = 0; i < d; i++) {
    cout << ans.at(0).at(i) + 1 << endl;
  }
}


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

int main() {
    int a, b;
    cin >> a >> b;
    if (a > b) {
        swap(a,b);
    }
    string str = "";
    for(int i = 0; i < b; i++)
        str.push_back('0'+a);
    cout << str << endl;
    return 0;
}

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


int main(void){
    int n,m,x,a;
    int beforeX=0,afterX=0;
    cin>>n>>m>>x;
    for(int i=0; i<m; i++){
        cin>>a;
        if(a<x)beforeX++;
        else afterX++;
    }
    cout<<min(beforeX,afterX)<<endl;

    return 0;
}


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

/* using */
using namespace std;

/* main constructor */
struct Fast
{
    Fast()
    {
        std::cin.tie(0);
        ios::sync_with_stdio(0);
        //cout << fixed << setprecision(12);
    }
} fast;

/* template */
template <class T>
bool chmax(T &a, const T &b) { return (a < b) ? (a = b, 1) : 0; }
template <class T>
bool chmin(T &a, const T &b) { return (b < a) ? (a = b, 1) : 0; }

/* define */
#define REP(i, x, n) for (int i = x; i < (int)(n); ++i)
#define RREP(i, x, n) for (int i = x - 1; i >= (int)(n); --i)
#define rep(i, n) REP(i, 0, n)
#define reps(i, n) REP(i, 1, n + 1)
#define rrep(i, n) RREP(i, n, 0)
#define each(i, n) for (auto &i : n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define eunique(x) \
    sort(all(x));  \
    (x).erase(unique(all(x)), (x).end())
#define int long long
#define mp make_pair
#define r0 return 0

/* function */
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a * b / gcd(a, b); }

/* const */
const int inf = 1e9 + 7;
const int dxl[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dyl[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dxs[4] = {1, 0, -1, 0};
const int dys[4] = {0, 1, 0, -1};

/* main */
signed main(void)
{
    int n, m;
    string tmp;
    cin >> n;
    vector<int> num = {0};
    vector<string> str;
    unordered_multiset<string> s(n);
    rep(i, n)
    {
        cin >> tmp;
        str.emplace_back(tmp);
        s.emplace(tmp);
    }
    cin >> m;
    unordered_multiset<string> t;
    rep(i, m)
    {
        cin >> tmp;
        t.emplace(tmp);
    }
    rep(i, n)
    {
        num.emplace_back(s.count(str[i]) - t.count(str[i]));
    }
    cout << *max_element(all(num)) << endl;
    r0;
}

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

int main() {
 int a,b,c,d;

 cin >> a >> b >> c >> d;

 if (a+b>c+d){
  cout << "Left" << endl;
 }
 else if (a+b<c+d){
  cout << "Right" << endl;
 }
 else{
  cout << "Balanced" << endl;
 }

}

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

using namespace std;
using llong = long long;
using ldbl = long double;
using lpair = pair<llong, llong>;

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

template<typename T>
constexpr T inf = static_cast<T>(pow(10, static_cast<int>(log10(numeric_limits<T>::max())))) + 7;
constexpr llong mod = 1e9+7;

int main() {
  string s;
  cin >> s;

  cout << (s == "ABC" ? "ARC": "ABC") << endl;

  return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string s;
  cin >> s;
  if (s.at(s.size()-1) == 's')
  {
    s += "es";
  }else
  {
    s += "s";
  }
  
  cout << s << endl;
}

Measured memory_bytes: 3632
import math
H,W = map(int,input().split())

if H == 1 or W == 1:
    print(1)
    exit()

HH = H // 2
hh = H % 2
WW = W // 2
ww = W % 2

a = 0

a += HH * WW * 2
a += hh * WW
a += HH * ww
a += hh * ww

print(a)

Measured memory_bytes: 38384
#include<iostream>
#include<string>
using namespace std;
int main(){
	int a,b,c;
	cin>>a>>b>>c;
	int d=0;
	for(int x=a;x<=b;x++){
		if(c%x==0){
			d++;
		}
		
	}			
	cout<<d<<endl;
}


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

int main(){
    int N; cin >> N;
    long long cost, minCost = 100000000000000, x; cin >> x;
    long long A[N][N];
    for (int i = 0; i < N; i++){
        cin >> A[0][i];
    }
    for (int i = 1; i < N; i++){
        for (int j = 0; j < N; j++){
            if (j-i > 0) A[i][j] = min(A[i-1][j], A[0][j-i]);
            else A[i][j] = min(A[i-1][j], A[0][j-i+N]);
        }
    }

    for (int i = 0; i < N; i++){
        cost = x*i;
        for (int j = 0; j < N; j++){
            cost += A[i][j];
        }
        minCost = min(cost, minCost);
    }
    cout << minCost << endl;
    return 0;
}


Measured memory_bytes: 31488