akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const int maxn = 2e5 + 7;
int n, c[maxn], a[maxn], t;
long long now[maxn], dp[maxn];

int main() {
	scanf("%d", &n);
	for (int i = 1; i <= n; ++i) scanf("%d", &c[i]);
	for (int i = 1; i <= n; ++i) if(c[i] != c[i - 1]) a[++t] = c[i];
	dp[0] = 1;
	for (int i = 1; i <= t; ++i) {
		dp[i] = (now[a[i]] + dp[i - 1]) % mod;
		now[a[i]] = (now[a[i]] + dp[i - 1]) % mod;
	}
	printf("%lld\n", dp[t]);
	return 0;
}

Measured memory_bytes: 8508
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;
inline int getInt() { int x; scanf("%d",&x); return x;}
template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>inline ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MX = 200005;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
//---------------------------------------------------------------
#define fastio std::ios::sync_with_stdio(false);
#define myio ifstream iofi; if(argc>1){iofi.open(argv[1]); std::cin.rdbuf(iofi.rdbuf());}
//--------------------------------------------------------------


int main(int argc,char** argv){ fastio; myio;
  string s;
  cin>>s;
  vi a(3);
  int a0 = s[0]-'0';
  rep(i,3) a[i] = (int)(s[i+1]-'0'); 
  for(int i=0;i<8;++i){
    bitset<3> b(i);
    int sum = a0;
    rep(i,3) sum += (b[i]? a[i]:-a[i]);
    if(sum==7){
      cout<<a0;
      rep(i,3){
        cout<<(b[i]? '+':'-')<<a[i];
      }
      cout<<"=7"; return 0;
    }
  }
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
int n,p[20002],a[20002],b[20002];
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		a[i]=20002*i,b[i]=20002*(n-i+1);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&p[i]);
		a[p[i]]-=(n-i+1);
	}
	for(int i=1;i<=n;i++)
		printf("%d ",a[i]);
	printf("\n");
	for(int i=1;i<=n;i++)
		printf("%d ",b[i]);
}


Measured memory_bytes: 768
/*Always success does not build on success,success build on failure and hardwork*/
#include <bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define vec         vector<int>
#define map         map<int,int>
#define scn(t)      scanf("%d",&t);
#define lscn(t)      scanf("%lld",&t);
#define mod         1000000007
#define rep(i,a,b)  for(int i=a;i<b;i++)
#define endl        "\n"
using namespace std;
const int N=2e5+5;

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

    vec v;

    for(int i=0;i<(int)s.length();i++)
    {
        if(s[i]=='B')
        {
            if(v.size())
            v.pop_back();
            else
            continue;
        }
        else if(s[i]=='0')
        {
            v.pb(0);
        }
        else
        {
            v.pb(1);
        }
    }

    for(auto it: v)
    cout<<it;
}



Measured memory_bytes: 3560
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int k = sc.nextInt();
		int n = sc.nextInt();
		int prev = 0;
		int maxDis = 0;
		int first = 0;
		for (int i=0; i<n; i++) {
			int x = sc.nextInt();
			if (i == 0) {
				first = x;
			}
			maxDis = Math.max(x - prev, maxDis);
			prev = x;
		}
		System.out.println(k - Math.max(maxDis, first + k - prev));
		sc.close();
	}

}


Measured memory_bytes: 49236
typedef long long ll;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;cin>>n;
  vector<int>V(n);
  rep(i,n){
    cin>>V[i];
  }
  int ans=0;
  rep(i,n){
    rep(j,i){
      ans+=V[i]*V[j];
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
     char k[3];
     int ca=0,cb=0;
     scanf("%s",k);
    // printf("%s.\n",&k);
       for(int i=0;i<3;i++){ 
        if(k[i]=='A'){
            ca++;
        }
        if(k[i]=='B'){
                cb++;
            }
       }
    
    if((ca==3) || (cb==3)){
    printf("No\n");}
    else{
        printf("Yes\n");
    }
    return 0;
}

Measured memory_bytes: 128
#include <algorithm>
#include <iostream>
#include <queue>
#include <utility>

using namespace std;

typedef pair<int, int> P;

int q, med_a;
long long min_a, sum_b;
priority_queue<int> q1;
priority_queue<int, vector<int>, greater<int> > q2;

int main() {
  cin >> q;
  
  while (q--) {
    int c; cin >> c;
    
    if (c == 2) { 
      cout << med_a << " " << min_a + sum_b << endl;
      continue;
    }
    
    int a, b;
    cin >> a >> b;
    sum_b += b;
    if (q1.size() == q2.size()) {
      if (q1.empty()) {
        med_a = a;
        q1.push(a);
        continue;
      }
      if (a <= q1.top()) {
        min_a += med_a - a;
        q1.push(a);
      } else if (a <= q2.top()) {
        med_a = a;
        q1.push(a);
      } else {
        med_a = q2.top();
        min_a += a - med_a;
        q1.push(med_a);
        q2.pop();
        q2.push(a);
      }
    } else {
      if (a <= q1.top()) {
        q2.push(med_a);
        q1.pop();
        q1.push(a);
        med_a = q1.top();
        min_a += q2.top() - a;
      } else {
        min_a += a - med_a;
        q2.push(a);
      }
    }
  }
  
  return 0;
}

Measured memory_bytes: 3452
# ITP_10_C
import math
while True:
    n = int(input())
    if n == 0:
        break
    l = list(map(int, input().split()))
    s = 0
    M = sum(l) / len(l)
    for data in l:
        s += ((data - M)** 2)
    print((s / len(l)) ** 0.5)


Measured memory_bytes: 5720
MAX = 50001

is_prime = [True for _ in range(MAX)]
is_prime[0] = is_prime[1] = False
for i in range(2, int(MAX ** (1 / 2)) + 1):
  if is_prime[i]:
    for j in range(i ** 2, MAX, i):
      is_prime[j] = False

primes = [i for i in range(MAX) if is_prime[i]]

while True:
  n = int(input())
  if not n:
    break
  
  ans = 0
  for i in primes:
    if i > n // 2:
      break
    if is_prime[n - i]:
      ans += 1

  print(ans)


Measured memory_bytes: 6068
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		Scanner stdn = new Scanner(System.in);
		
		int t = 0;
		
		for(int i = 0; i <= 3000; i++){
			int x = stdn.nextInt();
			int y = stdn.nextInt();
			if(x != 0 || y != 0){
				if(x > y){
					t = x;
					x = y;
					y = t;
				}
				System.out.println(x + " " +y);
			} else if(x == 0 && y == 0){
				break;
			}
		}
	}
}

Measured memory_bytes: 34456
#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int X;
  cin >> X;
  if(X == 2 || X == 3 || X == 5 || X == 7) {
    cout << X << endl;
  }
  else {
    bool finished = false;
    if(X % 2 == 1) {
      for(long long int i = X; true; i += 2) {
        for(long long int j = 3; j * j <= i; j += 2) {
          if(i % j == 0) {
            break;
          }
          if((j + 2) * (j + 2) > i && i % j != 0) {
            finished = true;
            cout << i << endl;
          }
        }
        if(finished) {
          break;
        }
      }
    }
    else {
      for(long long int i = X + 1; true; i += 2) {
        for(long long int j = 3; j * j <= i; j += 2) {
          if(i % j == 0) {
            break;
          }
          if((j + 2) * (j + 2) > i && i % j != 0) {
            finished = true;
            cout << i << endl;
          }
        }
        if(finished) {
          break;
        }
      }
    }
  }
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> pll;


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

    int count = 1;
    for(int i= 0; i< n-1; i++){
        if(s.at(i) != s.at(i+1)){
            count++;
        }
    }
    
    cout << count << endl;
}

Measured memory_bytes: 512
#include<cmath>
#include<cstdio>
#include<iostream>
#include<cstdlib>
#include<algorithm>
#include<cstring>
#include<map>
#include<queue>
#include<set>
#include<vector>
#include<bitset>
#define int long long
#define lowbit(x) ((x)&(-x))
#define hh putchar('\n')
#define kg putchar(' ')
using namespace std;
const int maxn=10005,mod=20101009;
int n;
inline int read()
{
    int x=0,f=1;
    char ch=getchar();
    while(ch<'0'||ch>'9')
    {
		if(ch=='-')
			f=-1;
		ch=getchar();
    }
    while(ch>='0'&&ch<='9')
    {
		x=(x<<1)+(x<<3)+(ch^48);
		ch=getchar();
    }
    return x*f;
}
inline void write(int a)
{
    if(a<0)
    {
		putchar('-');
		putchar('1');
    }
    else
    {
		if(a>=10)
			write(a/10);
		putchar(a%10+'0');
    }
}
signed main()
{
	char ch[10];
	cin>>ch;
	if(ch[1]=='B')
		cout<<"ARC";
	else
		cout<<"ABC";
	return 0;
}


Measured memory_bytes: 3620
# 入力
import sys
stdin = sys.stdin

def li(): return [int(x) for x in stdin.readline().split()]
def li_(): return [int(x)-1 for x in stdin.readline().split()]
def lf(): return [float(x) for x in stdin.readline().split()]
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(ns())
def nf(): return float(ns())

n = ni()
a = li()

# 各数のindexを格納
dic = {}
for i, ai in enumerate(a):
    dic[ai] = i
    
# 各indexに対して、左端のindexをleft, 右端のindexをrightに格納する
left = list(range(n+2))
right = list(range(n+2))

ans = 0
for i in range(n,0,-1):
    idx = dic[i]
    ans += i * (right[idx] - idx + 1) * (idx - left[idx] + 1)
    right[left[idx] - 1] = right[idx]
    left[right[idx] + 1] = left[idx]

print(ans)

Measured memory_bytes: 46140
#include<iostream>
#include<map>
#include<set>
using namespace std;
typedef double D;
typedef pair<int,int> P;

const int dy[] = {-1,-1,0,1,1,1,0,-1}, dx[] = {0,1,1,1,0,-1,-1,-1};
int n;
D r,x,y;
set<P> s;

int main(){
  cin >> n >> r;
  for(int i=0;i<n;i++){
    cin >> x >> y;
    s.insert(P((int)(x/r),(int)(y/r)));
  }

  int res = 0;
  while(s.size()){
    set<P>::iterator it = s.begin();
    P p = *it; s.erase(it); res++;
    for(int i=0;i<8;i++){
      P tmp = P(p.first+dx[i],p.second+dy[i]);
      it = s.find(tmp);
      if(it != s.end())s.erase(it);
    }
  }

  cout << res << endl;
}

Measured memory_bytes: 9764
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;
const int maxn = 100100;


int main()
{
	int n, k;
	cin >> n >> k;
	char a;
	for (int i = 1; i <= n; i++)
	{
		cin >> a;
		if (i == k)printf("%c", a + 32);
		else cout << a;
	}

	//system("pause");
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=200200;
const int INF=0x3f3f3f3f;

int a[N];
struct TM{
	int c[2],a[2];
	TM(){
		c[0]=c[1]=0;
		a[0]=a[1]=-INF;
	}
	void ins(int cc,int aa){
		if(aa>a[1]){
			swap(cc,c[1]);
			swap(aa,a[1]);
		}
		if(a[1]>a[0]){
			swap(c[1],c[0]);
			swap(a[1],a[0]);
		}
	}
};
int b1[N]={0},b2[N]={0};
int main(){
	int n;
	scanf("%d",&n);
	for(int i=0;i<n;i++)scanf("%d",&a[i]);
	TM s1,s2;
	for(int i=0;i<n;i+=2){
		b1[a[i]]++;
	}
	for(int i=1;i<n;i+=2){
		b2[a[i]]++;
	}
	for(int i=1;i<N;i++){
		s1.ins(i,b1[i]);
		s2.ins(i,b2[i]);
	}
	int ans=0;
	if(s1.c[0]!=s2.c[0])ans=s1.a[0]+s2.a[0];
	else ans=max(s1.a[1]+s2.a[0],s2.a[1]+s1.a[0]);
	printf("%d\n",n-ans);
	return 0;
}

Measured memory_bytes: 1408
<?php
while(fscanf(STDIN, "%d%d", $h, $w)){
if($h == "0" && $w == "0"){
    return;
}

for($i = 1; $i <= $h; $i++){
    echo str_repeat("#", $w). PHP_EOL;
    if($i == $h){ echo PHP_EOL;}
}
}
?>

Measured memory_bytes: 14904
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
int n,cur=1,root=1,prv=1;
string s;
vector < pair<int,int> > edge;
int main(){
	ios_base::sync_with_stdio(0);
	cin>>s;
	n=(int)s.length();
	if(s[0]=='0' || s[n-1]=='1') return cout<<-1, 0;
	for(int i=2;i<n;i++){
		if(s[i-1]!=s[n-i-1]){
			return cout<<-1, 0;
		}
	}
	for(int i=2;i<=n;i++){
		if(i<n && s[i-1]=='0') continue;
		int need=i-prv-1;
		edge.pb(mp(cur+1,root));
		root=++cur;
		while(need>0){
			need--;
			edge.pb(mp(root,++cur));
		}
		prv=i;
	}
	for(int i=0;i<n-1;i++) cout<<edge[i].fi<<" "<<edge[i].se<<"\n";
}


Measured memory_bytes: 2372
def slove():
    import sys
    input = sys.stdin.readline
    n = int(input().rstrip('\n'))
    t = 0
    for i in range(n):
        a, b = list(map(str, str(input().rstrip('\n')).split()))
        if b == "JPY":
            t += int(a)
        else:
            t += (float(a) * 380000)
    print(t)


if __name__ == '__main__':
    slove()


Measured memory_bytes: 38384
#include <bits/stdc++.h>
using namespace std;
#define REP(i,b,e) for(int i=(b);i<(e);++i)
#define RREP(i,b,e) for(int i=(b)-1;i>=e;--i)
#define rep(i,e) for(int i=0;i<(e);++i)

constexpr int MOD = 1000000007;
constexpr int INF = 1LL << 30;
constexpr long long LLINF = 1LL << 62;
constexpr double EPS = 1e-9;

struct Initializer {
  Initializer() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(15) << boolalpha;
  }
} initializer;

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

template<typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
  os << "[";
  for (auto it = vec.begin(); it != vec.end(); ++it) {
    if (it != vec.begin()) os << ", ";
    os << *it;
  }
  return os << "]";
}

template<typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &pa) {
  return os << "(" << pa.first << ", " << pa.second << ")";
}

template<typename Tuple, size_t N>
struct TuplePrinter {
  static void print(const Tuple &t) {
    TuplePrinter<Tuple, N-1>::print(t);
    cout << ", " << get<N-1>(t);
  }
};

template<typename Tuple>
struct TuplePrinter<Tuple, 1> {
  static void print(const Tuple &t) {
    cout << get<0>(t);
  }
};

template<typename... T>
ostream &operator<<(ostream &os, const tuple<T...> &tup) {
  os << "(";
  TuplePrinter<decltype(tup), sizeof...(T)>::print(tup);
  return os << ")";
}

template<typename T>
ostream &operator<<(ostream &os, const set<T> &se) {
  os << "{";
  for (auto it = se.begin(); it != se.end(); ++it) {
    if (it != se.begin()) os << ", ";
    os << *it;
  }
  return os << "}";
}

template<typename T, typename U>
ostream &operator<<(ostream &os, const map<T, U> &ma) {
  os << "{";
  for (auto it = ma.begin(); it != ma.end(); ++it) {
    if (it != ma.begin()) os << ", ";
    os << it->first << ": " << it->second;
  }
  return os << "}";
}

inline void print(void) { cout<<'\n'; }
template<class T> inline void print(const T &x) { cout<<x<<'\n'; }
template<class T, class... U> inline void print(const T &x, const U&... y) { cout<<x<<" "; print(y...); }
#define dump(...) cout<<#__VA_ARGS__<<": [L_"<<__LINE__<<"]"<<'\n'; print(__VA_ARGS__);cout<<'\n';

template<class T, class U>inline bool chmax(T &a, const U &b) { if(a<b){ a=b; return 1; } return 0; }
template<class T, class U>inline bool chmin(T &a, const U &b) { if(b<a){ a=b; return 1; } return 0; }


int main() {
  int n; cin>>n;
  long long cnt = 0;
  vector<long long> a(n), b(n);
  rep(i, n) cin>>a[i]>>b[i];
  RREP(i, n, 0) {
    long long at = a[i], bt = b[i];
    at += cnt;
    if (at%bt != 0) {
      cnt += bt-(at%bt);
    }
  }
  print(cnt);

  return 0;
}

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

int main() {
  int a,b;
  cin >> a >> b;
  if(a>=13){
    cout << b << endl;
  }
  else if(12 >= a && a >=6){
    cout << b/2 << endl;
  }
  else {
    cout << 0 << endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long double LD; 
typedef long long ll;
#define int ll
#define ff(i,a,b) for (int i = a; i < b; i++) 
#define bf(i,a,b) for (int i = a; i >= b; i--) 
#define aint(v) v.begin(),v.end() 
#define show(a) for(auto xyz:a)cout<<xyz<<" ";cout<<endl;
#define F first 
#define S second
#define pb push_back
#define mp make_pair
#define lb lower_bound   
#define ub upper_bound
#define yes cout<<"Yes"<<endl
#define no cout<<"No"<<endl
#define one cout<<"-1"<<endl
#define pi 3.141592653589793238
#define intmx INT_MAX 
#define intmi INT_MIN
void solve(){
    int n;
    cin>>n;
    int mod=1000000007;
    int a[n];
    ff(i,0,n)
    cin>>a[i];
    int ans=0;
    int sum[n];
    bf(i,n-1,1){
        if(i==n-1)
        sum[i]=a[i];
        else
        sum[i]=(sum[i+1]%mod+a[i]%mod)%mod;
    }
    ff(i,0,n-1){
        ans=(ans+((a[i]%mod)*(sum[i+1]%mod))%mod)%mod;
    }
    ans=(ans%mod+mod)%mod;
    cout<<ans<<endl;
}
signed main() {
    int t=1;
    //cin>>t;
    while(t--){
        solve();
    }
}


Measured memory_bytes: 6724
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0;i<n;i++)
#define erep(i,n) for(int i = 0;i<=n;i++)
#define rep1(i,n) for(int i = 1;i<n;i++)
#define erep1(i,n) for(int i = 1;i<=n;i++)
typedef long long ll;
#define vint vector<int>
#define vstring vector<string>
#define vll vector<ll>
#define vbool vector<bool>
#define INF 100000000

int main(){
  int n;
  cin >> n;
  vint A(n+2);
  int max = 0;
  A[0] = 0;
  A[n+1] = 0;
  erep1(i,n+1){
    cin >> A[i];
    max += abs(A[i]-A[i-1]);
  }
  erep1(i,n){
    cout << max + abs(A[i-1]-A[i+1]) - abs(A[i-1] - A[i]) - abs(A[i+1]-A[i]) <<endl;
  }
}

Measured memory_bytes: 1664
import java.util.Scanner;

public class Main {

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

	Scanner sc = new Scanner(System.in);

	void run() {
		int t = sc.nextInt();
		for(int i = 0; i < t; i++){
			
			long a = sc.nextLong();
			long b = sc.nextLong();
			long c = sc.nextLong();
			long d = sc.nextLong();
			
			
			System.out.println(solve(a,b,c,d)?"Yes":"No");
			
		}
		
	}
	
	boolean solve(long a, long b, long c, long d){
		
		if(a < b){
			return false;
		}
		
		if( d < b){
			return false;
		}
		
		long gcd = gcd(b,d);
		
		long start = (a - c -1 )%gcd;
		
		long min = start - b;
		
//		System.out.println(gcd+" "+start+ " "+min);
		if(min < -c-1){
			return false;
		}
		return true;
	}
	
	
	long gcd(long a,long b){
		if(a < b){
			return gcd(b,a);
		}
		if(a % b == 0){
			return b;
		}
		return gcd(b,a%b);
	}
}



Measured memory_bytes: 25952
#include <bits/stdc++.h>
#ifdef DEMETRIO
#define deb(...) fprintf(stderr,__VA_ARGS__)
#define deb1(x) cerr << #x << " = " << x << endl
#else
#define deb(...) 0
#define deb1(x) 0
#endif
#define pb push_back
#define mp make_pair
#define fst first
#define snd second
#define fore(i,a,b) for(int i=a,ThxDem=b;i<ThxDem;++i)
#define SZ(x) ((int)x.size())
#define MOD 1000000007
using namespace std;
typedef long long ll;

int pm(int a, int e){
	int r=1;
	while(e){
		if(e&1)r=(1LL*r*a)%MOD;
		e>>=1;
		a=(1LL*a*a)%MOD;
	}
	return r;
}
int inv(int a){return pm(a,MOD-2);}

vector<int> g[200005];int n,rt;
set<int> gg[200005];
int p2[200005];
int p[200005];
int s[200005],f[200005];
int r;

void dfs(int x){
	if(!SZ(gg[x])){s[x]=f[x]=1;return;}
	s[x]=f[x]=0;
	int q=1;
	for(int y:gg[x]){
		dfs(y);s[x]+=s[y];
		int t=(p2[s[y]]-f[y]+MOD)%MOD;
		q=(1LL*q*t)%MOD;
	}
	for(int y:gg[x]){
		int t=(p2[s[y]]-f[y]+MOD)%MOD;
		int qq=(1LL*q*inv(t))%MOD;
		qq=(1LL*qq*f[y])%MOD;
		f[x]+=qq;f[x]%=MOD;
	}
}

void er(int x){
	if(x==rt)return;
	gg[p[x]].erase(x);
	if(!SZ(gg[p[x]]))er(p[x]);
}

int main(){
	p2[0]=1;
	fore(i,1,200005)p2[i]=(2*p2[i-1])%MOD;
	scanf("%d",&n);n++;
	fore(i,1,n){
		int p;
		scanf("%d",&p);
		g[p].pb(i);
	}
	vector<int> v={0};
	while(SZ(v)){
		dfs(rt);
		r+=(1LL*p2[n-SZ(v)]*f[rt])%MOD;r%=MOD;
		vector<int> vv;
		for(int x:v){
			if(SZ(g[x])==0)er(x);
			else if(SZ(g[x])==1){
				if(x==rt)rt=g[x][0];
				else {
					gg[p[x]].erase(x);
					gg[p[x]].insert(g[x][0]);
					p[g[x][0]]=p[x];
				}
			}
			else {
				for(int y:g[x]){
					gg[x].insert(y);
					p[y]=x;
				}
			}
			for(int y:g[x])vv.pb(y);
		}
		v=vv;
	}
	printf("%d\n",r);
	return 0;
}

Measured memory_bytes: 28516
#pragma gcc optimize("Ofast")
#include "bits/stdc++.h"
using namespace std;

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int d, t, s; cin >> d >> t >> s;
    cout << (s * t >= d ? "Yes" : "No") << '\n';
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define int long long
#define ll long long
#define INF LLONG_MAX/3
#define eps LDBL_EPSILON
#define moder 1000000007
#define pie 3.141592653589793238462643383279
#define P std::pair<int,int>
#define prique priority_queue
using namespace std;
int h,w;
char s[410][410];
vector<P> vec;
bool used1[410][410],used2[410][410];
int f[]={0,1,0,-1,0,-1,0,1};
int g[]={1,0,-1,0,1,0,-1,0};
void init(){
	memset(used1,false,sizeof(used1));
}
int bl,wh;
void dfs(int x,int y){
	init();
	used1[x][y]=true;
	used2[x][y]=true;
	if(s[x][y]=='#')bl++;
	else wh++;
	rep(i,8){
		if(x+f[i]<0||x+f[i]>=h||y+g[i]<0||y+g[i]>=w)continue;
		if(s[x][y]!=s[x+f[i]][y+g[i]]&&!used2[x+f[i]][y+g[i]])dfs(x+f[i],y+g[i]);
	}
}
signed main(){
	cin>>h>>w;
	rep(i,h){
		rep(j,w){
			cin>>s[i][j];
			if(s[i][j]=='#'){
				vec.push_back({i,j});
			}
		}
	}
	int ans=0;
	for(P i:vec){
		if(used2[i.first][i.second])continue;
		bl=0,wh=0;
		dfs(i.first,i.second);
		ans+=bl*wh;
	}
	cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 9584
N=int(input())
ls1=[]
for _ in range(N):
  title,time=input().split()
  ls1.append([title,int(time)])
X=input()
i=0
a=0
flag=False
while flag==False:
  if ls1[i][0]==X:
    i+=1
    break
  i+=1
while i<N:
  a+=ls1[i][1]
  i+=1
print(a)

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

#define all(a) begin(a),end(a)
#define F first
#define S second
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;

#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif

const int mod=998244353;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int mul(int a,int b){
  return ((a)*1ll*(b))%mod;
}

void add(int &a,int b){
  a+=b;
  if(a>=mod)a-=mod;
}

int sub(int a,int b){
  a-=b;
  if(a<0){
    a+=mod;
  }
  return a;
}

int powz(int a,int b){
  int res=1;
  while(b){
    if(b&1){
      res=mul(res,a);
    }
    b/=2;
    a=mul(a,a);
  }
  return res;
}

template <typename A, typename B>
istream& operator>>(istream& input,pair<A,B>& x) {
  input>>x.F>>x.S;
  return input;
}

template <typename A>
istream& operator>>(istream& input,vector<A>& x) {
  for(auto& i:x)
    input>>i;
  return input;
}

template<typename A>
ostream& operator<<(ostream& output,vector<A>& x) {
  for(auto& i:x)
    output<<i<<' ';
  return output;
}


const int N=200005;

void solve(){ 
	int n;
	cin>>n;
	string s;
	cin>>s;
	vector<int>cnt(3);
	for(auto &i:s){
		if(i=='R'){
			i='0';
		}
		else if(i=='B'){
			i='1';
		}
		else{
			i='2';
		}
		cnt[i-'0']++;	
	}
	ll ans=0;
	for(int i=0;i<n;i++){
		cnt[s[i]-'0']--;
		for(int j=i+1;j<n;j++){
			cnt[s[j]-'0']--;
			if(s[j]==s[i]){
				continue;
			}
			for(int k=0;k<3;k++){
				if(s[j]-'0'==k||s[i]-'0'==k){
					continue;
				}
				ans+=cnt[k];
			}
			int dif=j-i;
			int val2=j+dif;
			if(val2<n&&s[val2]!=s[i]&&s[val2]!=s[j]){
				ans--;
			}
		}
		for(int j=i+1;j<n;j++){
			cnt[s[j]-'0']++;
		}
	}	
	cout<<ans;
}

signed main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int tc=1;
  //~cin>>tc;
  for(int _=0;_<tc;_++){
    //~cout<<"Case #"<<_+1<<": \n";
    solve();
    if(_!=tc-1){
      cout<<'\n';
    }
  }
}



Measured memory_bytes: 3668
import sys
import re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
S = [input() for _ in range(N)]

new_S = []
for s in S:
    tmp = [_ for _ in s]
    tmp = ''.join(sorted(tmp))
    new_S.append(tmp)

c = Counter(new_S)

def combinations_count(n, r):
    if n < 2:
        return 0
    else:
        return factorial(n) // (factorial(n - r) * factorial(r))

ans = 0
for n in c.values():
    ans += combinations_count(n, 2)
print(ans)


Measured memory_bytes: 32304
#include<stdio.h>
int a[6], b[6];

int rotate(int res[], int x, int y, int z)
{
    int i, temp;
    for(i=0;i<6;i++){
        res[i] = a[i];
    }
    while(x--){
        temp = res[0];
        res[0] = res[1];
        res[1] = res[5];
        res[5] = res[4];
        res[4] = temp;
    }
    while(y--){
        temp = res[1];
        res[1] = res[2];
        res[2] = res[4];
        res[4] = res[3];
        res[3] = temp;
    }
    while(z--){
        temp = res[0];
        res[0] = res[2];
        res[2] = res[5];
        res[5] = res[3];
        res[3] = temp;
    }
    if(res[0]==b[0] && res[1]==b[1] && res[2]==b[2] && res[3]==b[3] && res[4]==b[4] && res[5]==b[5]){
        return 1;
    }else{return 0;}
}
int main()
{

    int res[6], i, j, k, found;
    found = 0;
    for(i=0;i<6;i++)scanf("%d", &a[i]);
    for(i=0;i<6;i++)scanf("%d", &b[i]);

    for(i=0;i<4 && found!=1;i++){
        for(j=0;j<4 && found!=1;j++){
            for(k=0;k<4 && found!=1;k++){
                found = rotate(res, i, j, k);
            }
        }
    }
    if(found == 1)printf("Yes\n");
    else printf("No\n");

    return 0;
}



Measured memory_bytes: 2112
#include<map>
#include<cmath>
#include<stack>
#include<queue>
#include<cstdio>
#include<vector>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
template<class Read>void in(Read &x){
    x=0;
    int f=0;
    char ch=getchar();
    while(ch<'0'||ch>'9'){
        f|=(ch=='-');
        ch=getchar();
    }
    while(ch>='0'&&ch<='9'){
        x=(x<<1)+(x<<3)+(ch^48);
        ch=getchar();
    }
    x=f?-x:x;
    return;
}
int n,a[200005],l=1,r=(n*2-1),ans;
bool check(int x){
	for(int i=0;i<=n-2;i++){
		if((a[n+i]<=x&&a[n+i+1]<=x)||(a[n-i]<=x&&a[n-i-1]<=x))return 1;
		if((a[n+i]>x&&a[n+i+1]>x)||(a[n-i]>x&&a[n-i-1]>x))return 0;
	}
	if(a[1]>x)return 0;
	else return 1;
}
int main(){
	in(n);
	for(int i=1;i<=n*2-1;i++)in(a[i]);
	r=n*2-1;
	while(l<=r){
		int mid=(l+r)/2;
		if(check(mid))ans=mid,r=mid-1;
		else l=mid+1;
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x ,n) for(int i = x; i < n; i++)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main(){
    int n,ans=0;
    cin >> n;
    int d[n];
    rep(i,n)cin >> d[i];
    rep(i,n-1){
        rep2(j,i+1,n){
            ans+=d[i]*d[j];
        }
    }
    
    
    cout << ans;
    
	return 0;
}

Measured memory_bytes: 3568
use proconio::input;
use proconio::marker::{Chars, Usize1};
use std::iter::Iterator;
use std::collections::HashSet;
use std::cmp::*;
use itertools::Itertools;

#[allow(unused_macros)]
macro_rules! max {
    ($x:expr) => {
      $x
    };
    ($x:expr, $($xs:tt)+) => {
      max($x,max!($($xs)+))
    };
  }
  
  #[allow(unused_macros)]
  macro_rules! min {
    ($x:expr) => {
      $x
    };
    ($x:expr, $($xs:tt)+) => {
      min($x,min!($($xs)+))
    };
  }

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        eprintln!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

fn main() {
    input! {
      n:i64,
    mut s: Chars,
    }

    s.dedup();

    debug!(s);

     println!("{}", s.len());
}


Measured memory_bytes: 2460
#include<iostream>
using ll = long long;
using namespace std;
int main(){
    ll n,k,a,b,array[101010]={},ans;
    cin >> n >> k;
    for(ll i=0;i<n;i++){
        cin >> a >> b;
        array[a]+=b;
    }
    for(ll i=0;i<=100000;i++){
        if(k<=array[i]){
              ans=i;
              break;
        }
        k-=array[i];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using static System.Console;
using static System.Math;

namespace Atcoder
{
    class Program
    {
        static StreamWriter sw = new StreamWriter(OpenStandardOutput()) { AutoFlush = false };
        static void Main(string[] args)
        {
            try
            {
                SetOut(sw);
                Solve.Answer();
                Out.Flush();
            }
            catch (Exception ex)
            {
                WriteLine(ex.ToString());
                Out.Flush();
            }
        }
    }

    public class Solve
    {
        public static void Answer()
        {
            var N = IO.RInt;
            var H = IO.RInt;
            var W = IO.RInt;
            WriteLine((N - H + 1) * (N - W + 1));
        }
    }

    public class IO
    {
        #region Input
        public static int RInt => int.Parse(ReadLine());
        public static long RLong => long.Parse(ReadLine());
        public static double RDouble => double.Parse(ReadLine());

        public static string[] RSString => ReadLine().Split();
        public static int[] RSInt => ReadLine().Split().Select(s => int.Parse(s)).ToArray();
        public static long[] RSLong => ReadLine().Split().Select(s => long.Parse(s)).ToArray();
        public static double[] RSDouble => ReadLine().Split().Select(s => double.Parse(s)).ToArray();
        #endregion

        #region Output
        public static void OutJoinSpace<T>(IEnumerable<T> list) => WriteLine(string.Join(" ", list));
        public static void WriteLineYes_or_No(bool flag) => WriteLine(flag ? "Yes" : "No");
        public static void WriteLineYES_or_NO(bool flag) => WriteLine(flag ? "YES" : "NO");
        #endregion
    }

    public class Mod
    {
        #region
        private readonly static long M = 1000000007;

        public static long Add(long a, long b) => (a * b) % M;
        public static long Sub(long a, long b) => (a - b) % M >= 0 ? (a - b) % M : (a - b) % M + M;
        public static long Multi(long a, long b) => (a * b) % M;
        #endregion
    }
}

Measured memory_bytes: 17348
# 三井住友信託銀行プログラミングコンテスト 2019 D - Lucky PIN

import sys

N = int(input())
S = str(input())

ans = 0
for i in range(10):
    code1 = S.find(str(i))
    if code1 == -1:
        continue
    for j in range(10):
        code2 = S.find(str(j), code1 + 1)
        if code2 == -1:
            continue
        for k in range(10):
            code3 = S.find(str(k), code2 + 1)
            if code3 != -1:
                ans += 1

print(ans)


Measured memory_bytes: 38384
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long a = sc.nextLong();
		long b = sc.nextLong();
      
      long c=a-b;
      if(c<0){
      c=0;
      }
      System.out.println(c);}}

Measured memory_bytes: 22612
N, M = map(int, input().split())

AB = [list(map(int, input().split())) for _ in range(M)]

AB.sort(key = lambda x: x[0])

MAX = 10 ** 9

count = 1
min_ = MAX
for a, b in AB:
    if a < min_:
        min_ = min(min_, b)
    else:
        count += 1
        min_ = b

print (count)


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

int main(){
  int n,i,kotae;
  cin>>n;
  int a[n-1];
  for(i=0;i<n-1;i++){
    cin>>a[i];
  }
  kotae=a[0];
  for(i=0;i<n-2;i++){
    kotae+=min(a[i],a[i+1]);
  }
  kotae+=a[n-2];
  cout<<kotae;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string S;
  cin >> S;
  bool Palindrome = true;
  for(int i=0;i<S.size()/2;i++){
    if(S.at(i)!=S.at(S.size()-1-i)) Palindrome = false;
//    cout << S.at(i) << " :0 " << S.at(S.size()-1-i) << endl;
  }
  for(int i=0;i<S.size()/2/2;i++){
//    cout << i << " : " << S.size()/2-1-i << " : " << S.size()-1-i << " : " << (S.size()+1)/2+i << endl;
    if(S.at(i)!=S.at(S.size()/2-1-i)) Palindrome = false;
    if(S.at(S.size()-1-i)!=S.at((S.size()+1)/2+i)) Palindrome = false;    
//    cout << S.at(i) << " :1 " << S.at(S.size()/2-1-i) << endl;
//    cout << S.at(S.size()-1-i) << " :2 " << S.at((S.size()+1)/2+i) << endl;
  }
  if(Palindrome) cout << "Yes" << endl;
  else cout << "No" << endl;
}
  

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

const int N = 1e5 + 7;

bool vis[N][100];

int suma(int n)
{
    int res = 0;
    while(n > 0)
    {
        res += n % 10;
        n /= 10;
    }
    return res;
}

int n;

void dfs(int r, int s)
{
    if(s >= 50) return;
    if(vis[r][s]) return;
    vis[r][s] = 1;
    for(int i = 0; i < 10; i++)
        dfs((10 * r + i) % n, s + i);
}

int main()
{
    cin >> n;
   
    dfs(0, 0);
    //while(n % 2 == 0) n /= 2;
    //while(n % 5 == 0) n /= 5;
    int res = 1e9;
    for(int i = 1; i < 99; i++)
        if(vis[0][i]) res = min(res, i);
    cout << res << "\n";
    return 0;
}


Measured memory_bytes: 120832
#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 = 1000000007;
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, M;
    cin >> N >> M;
    if(N % 2 == 1){
        int A = 1, B = M * 2;
        rep(i,M){
            cout << A << ' ' << B << endl;
            ++A; --B;
        }
    }
    else{
        int A = 1, B = N;
        int n = N/2;
        rep(i,M){
            if(B - A > n){
                cout << A << ' ' << B << endl;
            }
            else if(B - A == n){
                ++A;
                cout << A << ' ' << B << endl;
            }
            else{
                if(i+1 == A){
                    ++A;
                }
                cout << A << ' ' << B << endl;
            }
            ++A; --B;
        }
    }
}

Measured memory_bytes: 3656
#include<iostream>
#include<cstdio>

using namespace std;

class Dice{
public:
    int dice[6];
    Dice(){}
    void roll1(){
        roll(1,2,4,3);
    }

    void roll2(){
        roll(0,2,5,3);
    }
    void roll3(){
        roll(0,1,5,4);
    }

    void roll(int i, int j, int k, int l){
        int t=dice[i]; dice[i]=dice[j]; dice[j]=dice[k]; dice[k]=dice[l]; dice[l]=t;
    }
};

bool eq(Dice d1, Dice d2){
    for(int i=0; i<6; i++){
        if(d1.dice[i] != d2.dice[i]) return false;
    }
    return true;
}

bool equal(Dice d1, Dice d2){
    for(int i=0; i<6; i++){
        for(int j=0; j<4; j++){
            if(eq(d1,d2)) return true;
            d1.roll1();
        }
        if(i%2==0) d1.roll2();
        else d1.roll3();
    }
    return false;
}

Dice d[1000]; int n;

bool check(){
    for(int i=0; i<n-1; i++){
        for(int j=i+1; j<n; j++){
            if(equal(d[i], d[j])) return false;
        }
    }
    return true;
}

int main(){
    cin>>n;
    for(int i=0; i<n; i++){
        for(int j=0; j<6; j++){
        cin>>d[i].dice[j];
        }
    }
    
    if(check()) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    
    return 0;
}






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

#define MOD 1000000007

int main(){
    int n, m;
    cin >> n >> m;
    vector<long long> x, y;
    for(int i=0;i<n;++i){
        long long tmp;
        cin >> tmp;
        x.push_back(tmp);
    }
    for(int i=0;i<m;++i){
        long long tmp;
        cin >> tmp;
        y.push_back(tmp);
    }

    long long xsum = 0;
    for(int i=0;i<n;++i){
        long long tmp = (x[i] * i % MOD) - (x[i] * (n-i-1) % MOD);
        if(tmp < 0)tmp = MOD + tmp;
        xsum = (xsum + tmp) % MOD;
    }

    long long ysum = 0;
    for(int i=0;i<m;++i){
        long long tmp = (y[i] * i % MOD) - (y[i] * (m-i-1) % MOD);
        if(tmp < 0)tmp = MOD + tmp;
        ysum = (ysum + tmp) % MOD;
    }

    cout << (xsum * ysum) % MOD << endl;

    return 0;
}


Measured memory_bytes: 2676
def check(b):
    if not b:
        print('No')
        exit()
a, b = map(int, input().split())
s = input()
deg = '0123456789'
check(len(s) == a+b+1)
check(s[a] == '-')
for i in range(a+b+1):
    if i != a:
        check(s[i] in deg)
print('Yes')

Measured memory_bytes: 3064
#include<set>
#include<map>
#include<deque>
#include<queue>
#include<stack>
#include<cmath>
#include<ctime>
#include<bitset>
#include<string>
#include<vector>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<complex>
#include<iostream>
#include<algorithm>
#define ll long long
using namespace std;

const int maxn = 110000;

ll n,a,b;

int main()
{
	scanf("%lld%lld%lld",&n,&a,&b);
	ll l=(n-1ll)*a+b,r=(n-1ll)*b+a;
	ll ans=r-l+1;
	printf("%lld\n",max(ans,0ll));
	
	return 0;
}


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

#define rep(i, n) for (int i = 0; i < (n); i++)
int gcd(int a, int b){ return (a%b ? gcd(b,a%b) : b); }

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

    int zero = 0;
    int one = 0;
    for(char c : str){
        if(c == '0'){
            zero++;
        }else if (c == '1'){
            one++;
        }
    }
    cout << min(zero,one) * 2;

    return 0;
}

Measured memory_bytes: 512
def lcm(a, b):
  return a // gcd(a, b) * b

def gcd(a, b):
  if(b == 0): return a
  else: return gcd(b, a % b)

def cnt(a):
  res = 0
  while(a and a % 2 == 0):
    a //= 2
    res += 1
  return res

n, m = map(int, input().split())
A = list(map(int, input().split()))

l = 1
c = cnt(A[0])
for a in A:
  if cnt(a) != c or c == 0:
    print(0)
    exit()
  else:
    l = lcm(l, a // 2)
d = m // l
print((d + 1) // 2)

Measured memory_bytes: 20136
N,M = map(int,input().split())
Hs = [int(h) for h in input().split()]
Answer = [True for _ in range(N)]
for _ in range(M):
  A,B = map(int,input().split())
  Ha, Hb = Hs[A-1], Hs[B-1]
  if Ha <= Hb:
    Answer[A-1] = False
  if Ha >= Hb:
    Answer[B-1] = False
#print(Answer)
print(Answer.count(True))

Measured memory_bytes: 20004
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <stack>


typedef long long ll;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define _GLIBCXX_DEBAC
/*map<Keyの型, Valueの型> 変数名;
queue<型> 変数名;
priority_queue<型> 変数名;
priority_queue<型, vector<型>, greater<型>> 変数名;*/
//copy(v1.begin(), v1.end(), back_inserter(v2));
using namespace std;

int gcd(int a, int b) {
	int c;
	if (a < b) {
		c = a; a = b; b = c;
	}
	while (b != 0) {
		c = a % b; a = b; b = c;
	}
	return a;
}

int sort_greater(int m,int n) {
	vector<int> a(m);
	for (int i = 0; i < m; i++) {
		cin >> a[i];
	}
	sort(a.begin(), a.end(),greater<int>());
	for (int i = 0; i < n; i++) {
		cout << a[i];
	}
		return 0;
}

int bubblesort(int a[], int n) {
	int sw = 0;
	bool flag = 1;
	for (int i = 0; flag; i++) {
		flag = 0;
		for (int j = n - 1; j >= i + 1; j--) {
			if (a[j] < a[j - 1]) {
				swap(a[j], a[j - 1]);
				flag = 1;
				sw += 1;
			}
		}
	}
	return sw;
}

int a_z()
{
	for (int i = 0; i <= ('Z' - 'A'); i++) {
		cout << (char)('A' + i);
	}
	return 0;
}

int selecttionsort(int a[], int n) {
	int t,sw = 0, minj;
	for (int i = 0; i < n - 1; i++) {
		minj = i;
		for (int j = 0; j < n - 1; j++) {
			if (a[j] < a[minj]) {
				minj = j;
			}
		}
		t = a[i]; a[i] = a[minj]; a[minj] = t;
		if (i != minj) sw += 1;

	}
	return sw;
}

bool is_prime(int x) {
	if (x <= 1) return false;
	for (int i = 2; i * i <= x; i++) {
		if (x % i == 0) return false;
	}
	return true;
}

map<string, int> memo;

using P=pair<int, int>;

struct Clock {
	int hour, minute, second;
	void set(int h, int m, int s) {
		hour = h; minute = m; second = s;
	}
	string to_str() {
		string h, m, s;
		h = to_string(hour);
		m= to_string(minute);
		s= to_string(second);
		if (h.size() < 2) h = "0" + h;
		if (m.size() < 2) m = "0" + m;
		if (s.size() < 2) s = "0" + s;
		return h + ":" + m + ":" + s;
	}
	void shift(int diff_second) {
		int h, m;
		h = diff_second / 3600;
		m = diff_second / 60;
		diff_second %= 60;
		second += diff_second;
		
	}
};

vector<int> to[200005];
vector<int> ans;
void dfs(int v, int p = -1) {
	for (int u : to[v]) {
		if (u == p) continue;
		ans[u] += ans[v];
		dfs(u, v);
	}
}
int main() {
	//sort(a.begin(),a.end());
	int n, q;
	cin >> n >> q;
	rep(i, n-1) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		to[a].push_back(b);
		to[b].push_back(a);
	}
	ans.resize(n);
	rep(i, q) {
		int p, x;
		cin >> p >> x;
		p--;
		ans[p] += x;
	}
	dfs(0);
	rep(i, n) {
		cout << ans[i] << endl;
	}
	return 0;
}









Measured memory_bytes: 23424
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cassert>
#include <bitset>
#include <fstream>
#include <cstring>
#include <stack>

using namespace std;

#define fst first
#define snd second
#define pb push_back
#define mp make_pair
#define ll long long
#define ull unsigned long long
#define ld long double

const ld pi = acos(-1);

template<typename T>
T abs(T x) {
    return x > 0 ? x : -x;
}

template<typename T>
T sqr(T x) {
    return x * x;
}

template<typename T>
ostream& operator << (ostream &s, const vector<T> &x) {
    s << "[";
    for (auto it : x) {
        s << it << ", ";
    }
    s << "]";
    return s;
}

template<typename T>
ostream& operator << (ostream &s, const set<T> &x) {
    s << "{";
    for (auto it : x) {
        s << it << ", ";
    }
    s << "}";
    return s;
}


template<typename U, typename V>
ostream& operator << (ostream &s, const pair<U, V> &x) {
    s << "(" << x.fst << ", " << x.snd << ")";
    return s;
}

template<typename T>
bool chmax(T &x, const T &y) {
    if (x < y) {
        x = y;
        return true;
    }
    return false;
}

template<typename T>
bool chmin(T &x, const T &y) {
    if (x > y) {
        x = y;
        return true;
    }
    return false;
}

//---------------------------------------------------------------------

const int maxn = 505;
char a[maxn][maxn], b[maxn][maxn], c[maxn][maxn];

int main() {
    srand(time(NULL));
    retry:
#ifdef LOCAL
    freopen("a.in", "r", stdin);
    //freopen("a.out", "w", stdout);
#else
    //freopen("sum.in", "r", stdin);
	//freopen("sum.out", "w", stdout);
#endif

    int n, m;
    scanf("%d %d", &n, &m);
    for (int i = 0; i < n; i++) {
        scanf("%s", a[i]);
    }

    for (int j = 0; j < n; j++) {
        for (int h = 0; h < m; h++) {
            b[j][h] = a[j][h];
            c[j][h] = a[j][h];
        }
    }

    for (int j = 0; j < m; j++) {
        b[0][j] = '#';
        c[n - 1][j] = '#';
    }

    for (int i = 0; i < m; i++) {
        for (int j = 0; j < n - 1; j++) {
            if (i & 1) {
                b[j][i] = '#';
            } else {
                c[n - 1 - j][i] = '#';
            }
        }
    }

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            assert((a[i][j] == '#') == ((b[i][j] == '#') && (c[i][j] == '#')));
        }
    }

    for (int i = 0; i < n; i++) {
        printf("%s\n", b[i]);
    }
    printf("\n");

    for (int i = 0; i < n; i++) {
        printf("%s\n", c[i]);
    }
    printf("\n");


    return 0;
}





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

#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
typedef long long ll;

const long long INF = 1LL << 60;

int main()
{
    int H, W;

    cin >> H >> W;
    int field[H][W];
    int COL[H][W], ROW[H][W];

    rep(i, H) {
        rep(j, W) {
            char s;
            cin >> s;
            if (s == '#') {
                field[i][j] = 0;
            }
            else {
                field[i][j] = 1;
            }
        }
    }

    rep(i, H) {
        int tmp = 0;
        rep(j, W) {
            if (field[i][j] == 0) {
                COL[i][j] = 0;
                tmp = 0;
            }
            else {
                tmp++;
                COL[i][j] = tmp;
            }
        }
    }

    rep(i, W) {
        int tmp = 0;
        rep(j, H) {
            if (field[j][i] == 0) {
                ROW[j][i] = 0;
                tmp = 0;
            }
            else {
                tmp++;
                ROW[j][i] = tmp;
            }
        }
    }

    rep(i, H) {
        int tmp = 0;
        for (int j = W - 1; j >= 0; j--) {
            if (COL[i][j] == 0) {
                tmp = 0;
            }
            else {
                tmp = max(tmp, COL[i][j]);
                COL[i][j] = tmp;
            }
        }
    }

    rep(i, W) {
        int tmp = 0;
        for (int j = H - 1; j >= 0; j--) {
            if (ROW[j][i] == 0) {
                tmp = 0;
            }
            else {
                tmp = max(tmp, ROW[j][i]);
                ROW[j][i] = tmp;
            }
        }
    }

    int ans = 0;
    rep(i, H) {
        rep(j, W) {
            ans = max(ans, COL[i][j] + ROW[i][j]);
        }
    }

    cout << ans - 1 << endl;

    return 0;
}

Measured memory_bytes: 47104
import heapq as hq

def relax(u, v, w):
    if D[u] + w < D[v]:
        D[v] = D[u] + w
        P[v] = u
        hq.heappush(H, (D[v], v))

INF = float('inf')
N = int(input())
D = [INF for i in range(N)]
P = [None for i in range(N)]
D[0] = 0

G = [{} for i in range(N)]
for i in range(N):
    x = list(map(int, input().split()))
    g = x[2:]
    for j, n in enumerate(g):
        if j % 2 == 0:
            G[i][n] = g[j + 1]

H = [(0, 0)]

while 0 < len(H):
    d_u, u = hq.heappop(H)
    for v, w in G[u].items():
        relax(u, v, w)

for i, d in enumerate(D):
    print('{0} {1}'.format(i, d))

Measured memory_bytes: 58048