akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
int main(void) {
    multiset<int> st;
    int q,a,b,c;
    cin >> q;
    for (int i=0;i<q;i++) {
        cin >> a;
        if ( a==0 ) {
            cin >> b;
            st.insert(b);
            cout << st.size() << endl;
        } else if ( a==1 ) {
            cin >> b;
            cout << st.count(b) << endl;
        } else if ( a==2 ) {
            cin >> b;
            if ( st.find(b)!=st.end() ) {
                st.erase(b);
            }
        } else if ( a==3 ) {
            cin >> b >> c;
            auto itr1 = st.lower_bound(b);
            auto itr2 = st.upper_bound(c);
            for (itr1;itr1!=itr2;++itr1) {
                cout << *itr1 << endl;
            }
        }
    }
}



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

#define int long long

int N;
int L[100010];
int R[100010];

main()
{
	ios::sync_with_stdio(false);
	
	cin>>N;
	for(int i=1;i<=N;i++)
	{
		cin>>L[i]>>R[i];
	}
	sort(L+1,L+1+N); reverse(L+1,L+1+N);
	sort(R+1,R+1+N);
	int ml=0,mr=0;
	int ans=0;
	for(int i=1;i<=N;i++)
	{
		if(L[i]<=mr || i==N)
		{
			ans+=abs(mr);
			break;
		}
		ml=L[i];
		ans+=ml-mr;
		if(R[i]>=ml)
		{
			ans+=abs(ml);
			break;
		}
		mr=R[i];
		ans+=ml-mr;
	}
	int ans2=ans;
	
	ml=0,mr=0;
	ans=0;
	for(int i=1;i<=N;i++)
	{
		if(R[i]>=ml || i==N)
		{
			ans+=abs(ml);
			break;
		}
		mr=R[i];
		ans+=ml-mr;
		if(L[i]<=mr)
		{
			ans+=abs(mr);
			break;
		}
		ml=L[i];
		ans+=ml-mr;
	}
	cout<<max(ans,ans2)<<endl;
}

/*
	|- L[i]-pos (pos<L[i])
dis=|  0 (L[i]<=pos<=R[i])
	|- pos-R[i] (pos>R[i])
*/

Measured memory_bytes: 1792
def output(A):
    for i in range(3):
        print(" ",end="")
        print(*A[i])

a = [[0 for i in range(10)] for j in range(3)]
b = [[0 for i in range(10)] for j in range(3)]
c = [[0 for i in range(10)] for j in range(3)]
d = [[0 for i in range(10)] for j in range(3)]

N = int(input())
for _ in range(N):
    bb,f,r,v = map(int,input().split())
    r -= 1
    f -= 1
    if bb == 1:
        a[f][r] += v
    elif bb == 2:
        b[f][r] += v
    elif bb == 3:
        c[f][r] += v
    else:
        d[f][r] += v

output(a)
print("####################")
output(b)
print("####################")
output(c)
print("####################")
output(d)


Measured memory_bytes: 5624
import sys
from fractions import gcd
from itertools import groupby as gb
from itertools import permutations as perm
from itertools import combinations as comb
from collections import Counter as C
from collections import defaultdict as dd
sys.setrecursionlimit(10**5)
def y(f):
    if f:
        print('Yes')
    else:
        print('No')
def Y(f):
    if f:
        print('YES')
    else:
        print('NO')
def Z(f):
    if f:
        print('Yay!')
    else:
        print(':(')
def ispow(n):
    if int(n**.5)**2==n:
        return True
    return False

n,m = map(int,input().split())
print(n * (n - 1) // 2 + m * (m - 1) // 2)


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

map<string,bool> mp;

signed main(){
    int n , ans = 0;
    string s;
    cin >> n;
    for(int i=0 ;i<n ;i++ ){
        cin >> s;
        if(mp[s] == false){
            ans ++;
            mp[s] = true;
        }
    }
    
    cout << ans << endl;
    return(0);
}


Measured memory_bytes: 19228
using System;
using System.Collections.Generic;
using System.Linq;

namespace ConsoleApp2
{
	class Program
	{
		static void Main(string[] args)
		{
			var input1 = Console.ReadLine().Split(' ');
			int n = int.Parse(input1[0]);
			int x = int.Parse(input1[1]);
			var input2 = Console.ReadLine().Split(' ');
			var q = from a in input2
					select int.Parse(a);
			var l = new List<int>(q);

			int count = 0;
			int d = 0;

			for (int i = 0; i < n + 1; i++)
			{
				if (0 < i)
				{
					d += l[i - 1];
				}
				if (d <= x)
				{
					count++;
				}
				else
				{
					break;

				}
			}
			Console.WriteLine(count);
		}
	}
}


Measured memory_bytes: 13268
#include <map>
#include <queue>
#include <cmath>
#include <bitset>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define pi acos(-1)
#define ll long long
#define inf 1000000000
#define PI acos(-1)
#define bug puts("edfesfs")
#define REP(i,x,n) for(int i=x;i<=n;i++)
#define DEP(i,n,x) for(int i=n;i>=x;i--)
#define mem(a,x) memset(a,x,sizeof(a))
using namespace std;
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*10+ch-'0';
        ch=getchar();
    }
    return x*f;
}
const int N=1000;
int t[N],v[N];
int l[N],r[N];
int main()
{
    int n=read();
    int time=0;
    REP(i,1,n) t[i]=read();
    REP(i,1,n) v[i]=read();
    int pre=0,now=0;
    REP(i,1,n){
        now+=t[i];
        l[i]=pre;r[i]=now;
        pre=now;
    }
    l[0]=0;r[0]=0;v[0]=0;
    l[n+1]=now;r[n+1]=now;v[n+1]=0;
    double ans=0;
    for(double j=0;j<(double)now;j+=0.5){
        double mix=1000;
        for(int i=0;i<=n+1;i++){
            if(l[i]<=j&&r[i]>=j) mix=min(mix,v[i]*1.0);
            else if(j<l[i]) mix=min(mix,v[i]+l[i]-j);
            else mix=min(mix,v[i]+j-r[i]);
        }
        ans+=mix*0.5;
    }
    printf("%.3f\n",ans);
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define uint unsigned long long
#define double long double
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, n) for (int i = 1; i <= (n); i++)
#define all(x) begin(x), end(x)
using vint = vector<int>;
using vvint = vector<vint>;
using vchar = vector<char>;
using vvchar = vector<vchar>;
constexpr double pi = 3.1415926535897932384626433832795028L;

int gcd(int a, int b) {
    while (b) { swap(a %= b, b); }
    return a;
}
int lcm(int a, int b) {
    return a / gcd(a, b) * b;
}
int sigma(int n){
    int sum=0;
    for (int i=1; i<=(n); i++){
        sum+=i;
    }
    return sum;
}
int sigma_2(int n) {
  if (n == 0) {
    return 0;
  }
  return n + sigma_2(n - 1);
}
int sum_range(int a, int b) {
  if (a == b) {
    return a;
  }
  return sum_range(a, b - 1) + b;
}
int distance(int yo,int xo,int yi,int xi){
    return (yo-yi)*(yo-yi)+(xo-xi)*(xo-xi);
}

int array_sum_from_i(vint &data, int i) {
  if (i == data.size()) {
    return 0;
  }
  int s = array_sum_from_i(data, i + 1);
  return data[i] + s;
}
int array_sum(vint &data) {
  return array_sum_from_i(data, 0);
}
bool has_divisor(int N, int i) {
  if (i == N) {
    return false;
  }
  if (N % i == 0) {
    return true;
  }
  return has_divisor(N, i + 1);
}

bool is_prime(int N) {
  if (N == 1) {
    return false;
  }
  else if (N == 2) {
    return true;
  }
  else {
    return !has_divisor(N, 2);
  }
}
bool is_even(int);
bool is_odd(int);

bool is_even(int n) {
  if (n == 0) {
    return true;
  }
  return is_odd(n - 1);
}

bool is_odd(int n) {
  if (n == 0) {
    return false;
  }
  return is_even(n - 1);
}








signed main() {
    int N  ,M ;
    cin >> N >> M ;
    int A[N];

    int count = 0;
    rep(i,N){
        cin >> A[i];
        count += A[i];
    }
    double a = count * 0.25/M;
    int result = 0;
    rep(i,N){
        if(A[i]>=a){
            result ++;
        }
    }
    if(result>=M){
        cout << "Yes" << endl;
        return 0;
    }
    else{

            cout << "No" << endl;
            return 0;
    }
}


Measured memory_bytes: 256
from math import sqrt
from collections import Counter
n = int(input())
if n == 1:
    print(0)
    quit()
def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    a.sort()
    return a
l = prime_factorize(n)
c = Counter(l)
ans = 0
for v in c.values():
    i = 1
    while True:
        s = i*(i+1)//2
        if s <= v <= s+i:
            ans += i
            break
        i += 1
print(ans)

Measured memory_bytes: 9484
import sys
from operator import itemgetter
input = sys.stdin.readline

def main():
    N = int(input())
    red = [list(map(int, input().split())) for _ in range(N)]
    blue = [list(map(int, input().split())) for _ in range(N)]
    red = sorted(red, key=itemgetter(0), reverse=True)
    blue = sorted(blue, key=itemgetter(1))
    visited = [False] * N
    ans = 0
    for i in blue:
        c = i[0]
        d = i[1]
        for j in range(N):
            a = red[j][0]
            b = red[j][1]
            if a < c and b < d and not visited[j]:
                ans += 1
                visited[j] = True
                break
    print(ans)


if __name__ == '__main__': main()

Measured memory_bytes: 3064
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String line = "";

        StringBuilder sb = new StringBuilder();
        while ((line = br.readLine()) != null && !line.isEmpty()) {
            StringTokenizer st = new StringTokenizer(line);
            int a, b, c, d, e, f;
            double x, y;
            a = Integer.parseInt(st.nextToken());
            b = Integer.parseInt(st.nextToken());
            c = Integer.parseInt(st.nextToken());
            d = Integer.parseInt(st.nextToken());
            e = Integer.parseInt(st.nextToken());
            f = Integer.parseInt(st.nextToken());
            x = (double) (c * e - b * f) / (a * e - b * d);
            y = (double) (c * d - a * f) / (b * d - a * e);
            if (x == -0)
                x = 0;
            if (y == -0)
                y = 0;
            sb.append(String.format("%4.3f %4.3f\n", x, y));
        }
        System.out.print(sb.toString());
    }
}

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

int main() {
    int n;
    vector< int > num(100001);
    int res = 0;
    cin >> n;

    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;
        if (a < 100001) {
            num[a] += 1;
        } else {
            res += 1;
        }
    }
    for (int i = 1; i < 100001; i++) {
        if (num[i] != i && num[i] != 0) {
            if (num[i] < i) {
                res += num[i];
            } else {
                res += (num[i] - i);
            }
        }
    }

    cout << res << endl;

    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define endl "\n"
 
int main ()
{
	
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //#define int ll
	
    int n, x, y;
    cin >> n >> x >> y;

    vector <vector <int> > distance(n+1, vector <int> (n+1, 0));
    for (int i=1; i<=n; i++){
    	for (int j=1; j<=n; j++){
    		distance[i][j] = abs(i-j);
    // 		cout << distance[i][j] << " ";
    	}
    // 	cout << endl;
    }

    vector <int> cnt(n+3, 0);

    for (int i=1; i<=n; i++){
    	for (int j=1; j<=n; j++){
    		if (i == j) continue;
    		if (distance[i][x] + distance[y][j] + 1 < distance[i][j]){
    			distance[i][j] = distance[j][i] = distance[i][x] + distance[y][j] + 1;
    		}
    	}
    }

    for (int i=1; i<=n; i++){
    	for (int j=1; j<=n; j++){
    		int now = distance[i][j];
    // 		cout << now << " ";
    		if (j < i) continue;
    // 		cnt[1]++;
    // 		cnt[now+1]--;
            cnt[now]++;
    	}
    // 	cout << endl;
    }

    // for (int i=1; i<=n+1; i++){
    // 	cnt[i] += cnt[i-1];
    // }

    for (int i=1; i<n; i++){
    	cout << cnt[i] << endl;
    }

	return 0;
	
}


Measured memory_bytes: 18976
#include "bits/stdc++.h"
using namespace std;
const int MAX = 700000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 二項係数計算
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
/*第二引数で第一引数を割ったときの切り上げの計算*/
long long int maxtime(long long int x, long long int y) {
	return(x + y - 1) / y;

}
/*最大公約数*/
long long int lcm(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;

	if (number2 > number1) {
		m = number2;
		n = number1;
	}
	long long int s = -1;
	while (s != 0) {
		s = m % n;
		m = n;
		n = s;
	}
	return m;
}
/*最大公倍数*/
long long int gcd(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;
	return m / lcm(m, n) * n;
}

int main() {
	vector<int> s;
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		int a;
		cin >> a;
		s.push_back(a);
	}
	vector<int>ans;
	if (n % 2 == 0) {
		for (int i = n - 1; i > 0; i = i - 2){
			ans.push_back(s[i]);
		}	
		for (int i = 0; i < n; i = i + 2) {
			ans.push_back(s[i]);
		}
	}
	else {
		for (int i = n - 1; i >= 0; i = i - 2) {
			ans.push_back(s[i]);
		}
		for (int i = 1; i < n; i = i + 2) {
			ans.push_back(s[i]);
		}
	}
	for (int i = 0; i < n; i++) {
		cout << ans[i] <<" ";
	}
}

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

class Rolling_Hash{
private:
  ll n;
  static constexpr ll base1=1007,base2=2009;
  static constexpr ll mod1=(1e9+7),mod2=(1e9+9);
  vector<ll> hash1,hash2,mpow1,mpow2;
public:
  Rolling_Hash(const string& s){
    n=s.size();
    hash1.resize(n+1,0);
    hash2.resize(n+1,0);
    mpow1.resize(n+1,1);
    mpow2.resize(n+1,1);
    for(ll i=0;i<n;++i){
      hash1[i+1] = (hash1[i]*base1+s[i])%mod1;
      hash2[i+1] = (hash2[i]*base2+s[i])%mod2;
      mpow1[i+1] = (mpow1[i]*base1)%mod1;
      mpow2[i+1] = (mpow2[i]*base2)%mod2;
    }
  }
  auto get(ll l,ll r){
    ll lefval = hash1[r]-hash1[l]*mpow1[r-l]%mod1;
    ll rigval = hash2[r]-hash2[l]*mpow2[r-l]%mod2;
    if(lefval<0)lefval+=mod1;
    if(rigval<0)rigval+=mod2;
    return make_pair(lefval,rigval);
  }
  auto get_LCP(ll a,ll b){
    ll len = min( n-a+1,n-b+1 );
    ll low=0,high=len;
    while( high-low>1 ){
      ll mid=(high+low)>>1;
      if(get(a,a+mid)!=get(b,b+mid))high=mid;
      else low=mid;
    }
    return low;
  }
};
ostream &operator<< (ostream& out,const pair<ll,ll>& p){
  out<<p.first<<","<<p.second;
  return out;
}
void solve1(){
  string s,t;
  cin>>s>>t;
  ll n=s.size(),m=t.size();
  Rolling_Hash SR(s),TR(t);
  rep(i,n-m+1){
    if(SR.get(i,i+m)==TR.get(0,m)){
      cout<<i<<endl;
    }
  }
}

main(){
  solve1();
}


Measured memory_bytes: 35600
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb emplace_back
typedef long long ll;
typedef pair<int,int> pint;

double PI=acos(-1.0);
#define eps (1e-10)
struct Point{
    double x,y;
    Point(){}
    Point(double x,double y):x(x),y(y){}
    Point operator+(Point p) {return Point(x+p.x,y+p.y);}
    Point operator-(Point p) {return Point(x-p.x,y-p.y);}
    Point operator*(Point p) {return Point(x*p.x-y*p.y,x*p.y+y*p.x);}
    Point operator*(double k){return Point(x*k,y*k);}
    Point operator/(double k){return Point(x/k,y/k);}
    double norm(){return x*x+y*y;}
    double abs(){return sqrt(norm());}
    bool operator == (const Point &p) const{return fabs(x-p.x)<eps && fabs(y-p.y)<eps;}
    double arg(){return atan2(y,x);}
    double dot(Point p){return x*p.x+y*p.y;}
    double det(Point p){return x*p.y-y*p.x;}
};
struct Circle{
    double r;
    Point p;
    Circle(){}
    Circle(Point p,double r):p(p),r(r){}
};
bool isIntersectCC(Circle c1,Circle c2){
    return (c1.p-c2.p).abs()<=c1.r+c2.r+eps;
}
int isIntersectCC2(Circle c1,Circle c2){
    double dist=(c1.p-c2.p).abs();
    double sub=abs(c1.r-c2.r);
    if(dist>c1.r+c2.r+eps) return 4; //not cross
    if(dist>c1.r+c2.r-eps) return 3; //外接
    if(dist>sub+eps) return 2;//intersect
    if(dist>sub-eps) return 1;//内接
    return 0;//include
}
int main(){
    double x1,y1,r1,x2,y2,r2;
    cin>>x1>>y1>>r1>>x2>>y2>>r2;
    cout<<isIntersectCC2(Circle(Point(x1,y1),r1),Circle(Point(x2,y2),r2))<<endl;
    return 0;
}


Measured memory_bytes: 3220
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define all(x) x.begin(),x.end()
#define dbg(x) cout<<#x<<":"<<x<<endl
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,P> PP;

int main(){
  int n;
  cin>>n;
  int ma=0,ans=0;
  for(int i=0;i<n;i++){
    int h;
    cin>>h;
    ma=max(ma,h);
    if(ma==h)ans++;
  }
  cout<<ans<<endl;
  return 0;
}


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

typedef vector<int> vi;
typedef pair<int,int> ii;
typedef long long int ll;
typedef unsigned long long int ull;
#define inf INT_MAX
#define minf INT_MIN
#define watch(x)	cout<<(#x)<<"=>"<<x<<'\n';
#define sz(a) (int)(a).size()

ll ans;
int arr[300009];
vi vr;
void solve()
{
				int n,x,t;	cin>>n>>x>>t;
				ans = 9;
				ans = n/x;
				if(n % x){
								ans++;
				}
				ans = ans*t;
				cout<<ans<<'\n';
}

int main()
{
				ios_base::sync_with_stdio(false);
				cin.tie(NULL);
				int testc = 1;
				for(int t = 0; t < testc; ++t)
								solve();
				return 0;
}

		//Sat 22 Aug 2020 05:35:48 PM IST


					/***astrainL3gi0N***/


Measured memory_bytes: 3652
#include <iostream>

using namespace std;

int main() {
    int A, B;
    cin >> A >> B;
    
    int C;
    for(int i=0; i<3; i++) {
        if(i+1==A || i+1==B) {
            continue;
        }
        C=i+1;
    }
    
    cout << C << endl;

    return 0;
    
}

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

void solve(){

}
int main (){
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,n+1) cin >> a[i];
    ll ans=0;
    rep(i,n){
        int m;
        cin >> m;
        if(m<=a[i]) {
            ans+=m;
            // cout << ans << endl;
        }
        else{
            if(m-a[i]<=a[i+1]){
                a[i+1]-=m-a[i];
                ans+=m;
                // cout << ans << endl;
            }
            else{
                ans+=a[i]+a[i+1];
                a[i+1]=0;
                // cout << ans << endl;
            }
        }
    }
    cout << ans;

    return 0;
}

Measured memory_bytes: 3712
from itertools import groupby
from sys import stdin
from numpy import logical_or, zeros


def solve(s, p, q):

    ss = [list(g) for k, g in groupby(s)]
    len_sss = [len(sss) for sss in ss]
    ss_and_len = list(zip(ss, len_sss))
    is_start_with_TT = True if ss[0][0] == 'T' and 0 < len_sss[0] else False
    dir = 0
    dx, dy = [], []

    for sss, l in ss_and_len:
        if sss[0] == 'T':
            dir += l
        elif sss[0] == 'F':
            if dir % 2 == 0:
                dx.append(l)
            else:
                dy.append(l)

    len_dx = len(dx)
    len_dy = len(dy)

    _n = max(sum(dx), sum(dy))
    __n = _n*2+1
    if _n < abs(p) or _n < abs(q):
        return 0

    if 0 < len_dx:
        dpx = zeros((len_dx, __n), dtype='uint64')
        if is_start_with_TT:
            dpx[0][_n-dx[0]] = 1
        dpx[0][_n+dx[0]] = 1

        for i in range(1, len_dx):
            s = dx[i]
            dpx[i][:s] = dpx[i-1][s:2*s]
            dpx[i][s:-s] = logical_or(dpx[i-1][:-2*s], dpx[i-1][2*s:])
            dpx[i][-s:] = dpx[i-1][-2*s:-s]
    else:
        dpx = [[0]*__n]
        dpx[0][_n] = 1

    if 0 < len_dy:
        dpy = zeros((len_dy, __n), dtype='uint64')
        dpy[0][_n+dy[0]] = 1
        dpy[0][_n-dy[0]] = 1

        for i in range(1, len_dy):
            s = dy[i]
            dpy[i][:s] = dpy[i-1][s:2*s]
            dpy[i][s:-s] = logical_or(dpy[i-1][:-2*s], dpy[i-1][2*s:])
            dpy[i][-s:] = dpy[i-1][-2*s:-s]
    else:
        dpy = [[0]*__n]
        dpy[0][_n] = 1
    # print(dpx[-1])
    # print(dpy[-1])

    return dpx[-1][_n+p] and dpy[-1][_n+q]


if __name__ == '__main__':
    s = stdin.readline()
    p, q = map(int, input().split())

    print('Yes' if solve(s, p, q) else 'No')


Measured memory_bytes: 139144
#include<bits/stdc++.h>
typedef long long int ll;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
int main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);

	freopen("output.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);


	ll flag = 0;
	ll x, y;
	cin >> x >> y;
	for (ll i = 0; i <= x; i++)
	{
		if ((2 * i + 4 * (x - i)) == y)
		{
			flag++;
		}
	}
	if (flag)
	{
		cout << "Yes";
	}
	else
	{
		cout << "No";
	}

}


Measured memory_bytes: 3652
#include<iostream>
#include<string>
#include<vector>
#include<numeric>
#include<math.h>
#include<algorithm>
#include<iomanip>
#include<list>
#include<bitset>
using namespace std;

int main() {

	int x[5];
	int ans = 0;

	for (int i = 0; i < 5; i++) {
		cin >> x[i];
		if (x[i] == 0) {
			ans = i;
		}
	}

	cout << ans + 1 << endl;

	return 0;
}



Measured memory_bytes: 3592
import sys
MAX_INT = int(10e12)
MIN_INT = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

N = I()
s = S()
N = len(s)

ans = 0
tmp = 0
for i in range(N):
  if s[i] == "I":
    tmp += 1
    ans = max(ans, tmp)
  else:
    tmp -= 1
print(ans)

Measured memory_bytes: 38256
#include<bits/stdc++.h>
#define ll long long
using namespace std;
#define mx 100009
ll ar[mx][4];
ll br[mx][4];
ll n;

ll dp(){
    br[n][1]=ar[n][1];
    br[n][2]=ar[n][2];
    br[n][3]=ar[n][3];
    for(ll i=n-1;i>=1;i--){
        br[i][1]=ar[i][1]+max(br[i+1][2],br[i+1][3]);
        br[i][2]=ar[i][2]+max(br[i+1][1],br[i+1][3]);
        br[i][3]=ar[i][3]+max(br[i+1][1],br[i+1][2]);
    }
    return max(br[1][1],max(br[1][2],br[1][3]));
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    //ll n;
    cin>>n;
    for(ll i=1;i<=n;i++){
        for(ll j=1;j<=3;j++){
            cin>>ar[i][j];
        }
    }
    cout<<dp()<<endl;
    return 0;
}


Measured memory_bytes: 6528
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    vector<int>v;
    for(int i=0;i<n;i++)
    {
        int x;
        cin>>x;
        v.push_back(x);
    }
    int mx = -1,cnt=0;
    for(int i=0,j=0;i<n-1;)
    {
        if(v[i+1]>v[i])
        {
            j++;
            i = j;
            mx = max(mx,cnt);
            cnt = 0;
        }
        else
        {
            cnt++;
            i++;
        }
        //cout<<i<<" "<<j<<" "<<mx<<" "<<cnt<<endl;
    }
    cout<<max(mx,cnt)<<endl;

}


Measured memory_bytes: 892
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s,t;
    cin>>s>>t;
    int c=0;
    for(int i=0;i<s.size();i++)
   // for(int j=0;j<s.size();j++){
        if(s[i]!=t[i]){
            c++;
        }
         //cout<<c<<endl;
   // }
    cout<<c<<endl;
    return 0;
}


Measured memory_bytes: 3900
l, r = [int(x) for x in input().split()]

if r - l >= 2019:
    a = 0
    b = 2019
else:
    a = l % 2019
    temp = r % 2019
    b = temp if a < temp else temp + 2019

ans = 2019
for i in range(a, b):
    for j in range(i + 1, b + 1):
        temp = (i * j) % 2019
        if temp < ans:
            ans = temp
            if ans == 0:
                print(0)
                exit()
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
using ll = long long;
using P = pair<int, int>;
ll GCD(ll a, ll b) { return b?GCD(b, a%b):a; }
ll LCM(ll a, ll b) { return a/GCD(a, b)*b; }

// auto mod int
const int mod = 1000000007;
// const int mod = 998244353;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

const int MX = 100100;
struct Sieve {
    int n;
    vector<int> f, primes;
    Sieve(int n = 1):n(n), f(n+1) {
        f[0] = f[1] = -1;
        for(ll i = 2; i <= n; ++i) {
            if(f[i]) continue;
            primes.push_back(i);
            f[i] = i;
            for(ll j = i*i; j <= n; j += i) {
                if(!f[j]) f[j] = i;
            }
        }
    }
    bool isPrime(int x) { return f[x] == x; }
    vector<int> factorList(int x) {
        vector<int> res;
        while(x != 1) {
            res.emplace_back(f[x]);
            x /= f[x];
        }
        return res;
    }
    vector<P> factor(int x) {
        vector<int> fl = factorList(x);
        if(fl.size() == 0) return {};
        vector<P> res(1, P(fl[0], 0));
        for(int p : fl) {
            if(res.back().first == p) {
                res.back().second++;
            }else {
                res.emplace_back(p, 1);
            }
        }
        return res;
    }
};

// エラストテネスの篩で素数列挙

int main() {
    Sieve sieve(1e6);
    int n;
    cin >> n;
    vector<int> A(n);
    for(int i = 0; i < n; ++i) cin >> A.at(i);

    map<int, int> mp;
    for(int i = 0; i < n; ++i) {
        auto f = sieve.factor(A[i]);
        for(auto p : f) {
            mp[p.first] = max(mp[p.first], p.second);
        }
    }

    mint lc = 1;
    for(auto p : mp) {
        for(int i = 0; i < p.second; ++i) {
            lc *= p.first;
        }
    }

    mint ans;
    for(int i = 0; i < n; ++i) {
        mint b = lc/A.at(i);
        ans += b;
    }
    cout << ans.x << endl;

}

Measured memory_bytes: 4984
#include <cstdio>

int main() {
  int c = getchar();
  for (int i = 0; i < 4; i++) {
    putchar(c);
    c = getchar();
  }
  putchar(' ');
  for (int i = 0; i < 8; i++) {
    putchar(c);
    c = getchar();
  }
  puts("");
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define all(v) ((v).begin()),((v).end())
#define ll long long
#define fastIO cout << fixed << setprecision(9), ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)
double const EPS = 1e-9, PI = acos(-1);
const int N = 1e5 + 9, M = 5e2 + 9, OO = 1e9 + 7, MOD = 1e9 + 9;
const ll inf = 1e18;

double mem[309][309][309];

int n;

double solve(int a, int b, int c) {
  if(a < 0 || b < 0 || c < 0)
    return 0;
  if(a + b + c > n)
    return 0;
  if(a + b + c == 0)
    return 0;
  double& ret = mem[a][b][c];
  if(ret == ret)
    return ret;
  ret = 1.0;
  double p_a = 1.0 * a / (n), p_b = 1.0 * b / n, p_c = 1.0 * c / n, factor = 1.0 - ((double)(n - (a + b + c)) / n);
  p_a *= solve(a-1, b, c);
  p_b *= solve(a+1, b-1, c);
  p_c *= solve(a, b+1, c-1);
  ret = (p_a + p_b + p_c + 1) / factor;
  return ret;
}

int main() {
  fastIO;
#ifdef LOCAL
  freopen("input.in", "rt", stdin);
#endif
  memset(mem, -1, sizeof mem);
  int cnt[4] = {}, x;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> x;
    ++cnt[x];
  }
  cout << solve(cnt[1], cnt[2], cnt[3]);
  return 0;
}


Measured memory_bytes: 230912
n, k = map(int, input().split())
c = (n-1) * (n-2) // 2
if k > c:
    print(-1)
    exit()
m = n - 1 + c - k
print(m)
for i in range(2, n+1):
    print("1 {}".format(i))
i = 2
j = 3
while c > k:
    print("{} {}".format(i, j))
    if j < n:
        j += 1
    else:
        i += 1
        j = i + 1
    c -= 1

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

using namespace std;

typedef long long ll;
ll x, y;
bool f_x,f_y;
int main() {
  cin >> x >> y;

  if(x >= 0) f_x = true;
  if(y >= 0) f_y = true;

  if((f_x && f_y) || (!f_x && !f_y)) {
    if(y == 0 && x > y) cout << x + 1 <<endl;
    else if(x > y) cout << x - y + 2 <<endl;
    else cout << y - x <<endl;
  }
  else if(!f_x && f_y) {
    if(-x > y && y == 0) cout << y - x <<endl;
    else if(-x > y) cout << -y - x + 1 <<endl;
    else cout << x + y + 1 <<endl;
  }
  else {
    if(x < -y) cout << -x - y + 1 <<endl;
    else cout << x + y + 1 <<endl;
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int temp;
string s;
bool a[27]; 
int main()
{
    cin>>s;
    for(int i=0;i<=s.length()-1;i++)
	  if(s[i]<='z'&&s[i]>='a'&&a[s[i]-96]==0)
	    {
	    	a[s[i]-96]=1;
	    	temp++;
		}
	if(temp==26)
	  {
	  	cout<<"None"<<endl;
	  	return 0;
	  }
	for(int i=1;i<=26;i++)
	  if(a[i]==0)
	    {cout<<char(i+96)<<endl;return 0;}
    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
  using namespace std;
#define ll long long
#define fw(p) for(int w=0;w<(p);w++)
#define fx(p) for(int x=0;x<(p);x++)
#define fy(p) for(int y=0;y<(p);y++)
#define fz(p) for(int z=0;z<(p);z++)
#define fyg(p,g) for(int y=(g);y<(p);y++)
#define fzg(p,g) for(int z=(g);z<(p);z++)
#define ce(d) cout<<d<<endl;
#define vecp(p) int aa;cin>>aa;(p).push_back(aa);
#define vecpl(p) long long aa;cin>>aa;(p).push_back(aa);
#define vecps(p) string aa;cin>>aa;(p).push_back(aa);
#define vecp2(p) cin>>aa;(p).push_back(aa);
#define vecpl2(p) long long a	b;cin>>ab;(p).push_back(ab);
#define vecps2(p) string ab;cin>>ab;(p).push_back(ab);
#define set0(k,n) for(int nn=0;nn<(n);nn++){ (k).push_back(0); }
#define sorts(c) sort((c).begin(),(c).end());
#define reverses(c) reverse((c).begin(),(c).end());
#define vec(b) vector<int> (b);
#define vecl(b) vector<long long> (b);
#define vecs(b) vector<string> (b);
#define vecsize(b,size) vector<int> (b)((size));
#define pb(b,a) (b).push_back((a));
#define doublece(a,b) cout<<(a)<<' '<<(b)<<endl;
#define pairs(s) vector<pair<int,int>> (s);
#define pairsl(s) vector<pair<ll,ll>> (s);
#define pairss(s) vector<pair<string,string>> (s);
#define pairsp(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairspl(s) ll aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsps(s) string aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsREV(s) (s).push_back(make_pair(bb,aa));
#define pairslREV(s) (s).push_back(make_pair(bb,aa));
#define pairssREV(s) (s).push_back(make_pair(bb,aa));
#define MOD 1000000007

int main() {
		
	int X,Y,Z,K;
	cin>>X>>Y>>Z>>K;
	vecl(A)
	vecl(B)
	vecl(C)
	fx(X){
		vecpl(A)
	}
	fy(Y){
		vecpl(B)
	}
	fz(Z){
		vecpl(C)
	}
	vecl(AB)
	for(int x=0;x<X;x++){
		for(int y=0;y<Y;y++){
			pb(AB,A.at(x)+B.at(y))
		}
	}
	sorts(AB)
	reverses(AB)
	vecl(ANS)
      int s=AB.size();
	fx(min(K,s)){
		fz(Z){
			pb(ANS,AB.at(x)+C.at(z))
		}
	}
	sorts(ANS)
	reverses(ANS)
	fx(K){
		ce(ANS.at(x))
	}
}

Measured memory_bytes: 43256
// #pragma GCC optimize("unroll-loops", "omit-frame-pointer", "inline")
// #pragma GCC option("arch=native", "tune=native", "no-zero-upper")
// #pragma GCC
// target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
// #pragma GCC optimize("Ofast")
// #pragma GCC optimize("tree-vectorize","openmp","predictive-commoning")
// #pragma GCC option("D_GLIBCXX_PARALLEL","openmp")
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<ll> vll;
// #define int long long
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000               // 2e9
#define LLINF 2000000000000000000ll  // 2e18 (llmax:9e18)
#define fi first
#define sec second
#define all(x) (x).begin(), (x).end()
#define sq(x) ((x) * (x))
#define dmp(x) cerr << #x << ": " << x << endl;

template <class T>
void chmin(T &a, const T &b) {
  if (a > b) a = b;
}
template <class T>
void chmax(T &a, const T &b) {
  if (a < b) a = b;
}

template <class T>
using MaxHeap = priority_queue<T>;
template <class T>
using MinHeap = priority_queue<T, vector<T>, greater<T>>;
template <class T>
vector<T> vect(int len, T elem) {
  return vector<T>(len, elem);
}

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << p.fi << ',' << p.sec;
  return os;
}
template <class T, class U>
istream &operator>>(istream &is, pair<T, U> &p) {
  is >> p.fi >> p.sec;
  return is;
}
template <class T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
  for (int i = 0; i < vec.size(); i++) {
    os << vec[i];
    if (i + 1 < vec.size()) os << ' ';
  }
  return os;
}
template <class T>
istream &operator>>(istream &is, vector<T> &vec) {
  for (int i = 0; i < vec.size(); i++) is >> vec[i];
  return is;
}
void fastio() {
  cin.tie(0);
  ios::sync_with_stdio(0);
  cout << fixed << setprecision(20);
}

#define endl "\n"

void solve() {
  int N;
  cin >> N;
  vector<ll> A(N);
  cin >> A;
  vector<pair<ll, int>> B;
  for (int i = 0; i < N; i++) B.push_back(make_pair(A[i], i));
  sort(all(B));
  reverse(all(B));
  auto dp = vect(N + 1, vect(N + 1, -LLINF));
  dp[0][0] = 0ll;
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      if (dp[i][j] == -LLINF) continue;
      int l = j;
      int r = i - j;
      chmax(dp[i + 1][j + 1], dp[i][j] + B[i].first * abs(B[i].second - l));
      chmax(dp[i + 1][j],
            dp[i][j] + B[i].first * abs(B[i].second - (N - 1 - r)));
    }
  }
  cout << *max_element(all(dp[N])) << endl;
  return;
}

signed main() {
  fastio();
  solve();
  // int t; cin >> t; while(t--)solve();

  // int t; cin >> t;
  // for(int i=1;i<=t;i++){
  //   cout << "Case #" << i << ": ";
  //   solve();
  // }
  return 0;
}


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

int main(){
  int A, B, count, temp, j;
  int d[5];
  
  cin >> A >> B;
  count = 0;
  
  for(int i = A; i <= B; i++) {
    temp = i;
    j = 0;
    while(temp > 0) {
      d[j] = temp % 10;
      temp /= 10;
      j++;
    }
    
    if(d[0] == d[4] && d[1] == d[3])
      count++;
  }
  cout << count << endl;
}

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

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using WGraph = vector<vector<pair<int, ll>>>;

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

constexpr int dx[4] = {-1, 0, 0, 1}, dy[4] = {0, -1, 1, 0};
constexpr int INF = 1e9;
constexpr int MOD = 1e9 + 7;
constexpr long long LINF = 1e18;
constexpr double EPS = 1e-10;
constexpr double PI = M_PI;
#pragma endregion

void solve() {
    int n, k;
    cin >> n >> k;
    vector<long long> cnt(n+2);
    ll left = 0, right = 0;
    for (int i=1; i<n+2; ++i) {
        left += i-1;
        right += n-i+1;
        cnt.at(i) = right - left + 1;
        cnt.at(i) %= MOD;
    }
    ll res = 0;
    for (int i=k; i<n+2; ++i) {
        res += cnt.at(i);
        res %= MOD;
    }
    cout << res << '\n';
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);

    solve();

    return 0;
}


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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repi(i, a, b) for (int i = (a); i < int(b); i++)
#define all(a) (a).begin(), (a).end()
#define bit(b) (1ull << (b))

using namespace std;
using i32 = int;
using i64 = long long;
using f64 = double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;
using vf64 = vector<f64>;
using vstr = vector<string>;

template<typename T, typename S> void amax(T &x, S y) { if (x < y) x = y; }
template<typename T, typename S> void amin(T &x, S y) { if (y < x) x = y; }

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(16);
  int n; cin >> n;
  vi32 a(n); rep(i, n) cin >> a[i];
  int ans = 0;
  rep(i, n - 1) {
    if (a[i] == a[i + 1]) {
      ans++;
      i++;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <cmath>
#include <iostream>
#include <vector>

using namespace std;

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

    vector<int> va, vb, vc;
    int ai, bi, ci;
    for (int i = 0; i < n; ++i)
    {
        cin >> ai >> bi >> ci;
        va.push_back(ai);
        vb.push_back(bi);
        vc.push_back(ci);
    }

    vector<vector<int>> opti(n);
    opti[n-1] = vector<int>{va[n-1], vb[n-1], vc[n-1]};
    int a, b, c;
    for (int i = n-2; i >= 0; --i)
    {
        a = va[i] + max(opti[i+1][1], opti[i+1][2]);
        b = vb[i] + max(opti[i+1][0], opti[i+1][2]);
        c = vc[i] + max(opti[i+1][0], opti[i+1][1]);
        opti[i] = vector<int>{a, b, c};
    }

    int max_h = max(max(opti[0][0], opti[0][1]), opti[0][2]);
    cout << max_h;

    return 0;
}

Measured memory_bytes: 6892
U,R,D,L="URDL"
d={i:[]for i in"URDL"}
_,*a=map(str.split,open(0))
for*z,u in a:d[u]+=[*map(int,z)],
N,P,M=9e9,"x+y,","x-y,"
for A,B,S in(U,D,"x,y,"),(R,L,"y,x,"),(R,U,P+M),(D,L,P+M),(U,L,M+P),(R,D,M+P):
 n=p=-9e9
 for x,y,r in sorted(eval(f"[({S}Q)for P,Q in[(A,1),(B,0)]for x,y in d[P]]")):
  if x-n:
   if r:n,p=x,y
  elif r:p=y
  else:N=min(N,y-p)
print(["SAFE",N*5][N<9e9])

Measured memory_bytes: 131216
#include <bits/stdc++.h>
#define int long long
using namespace std;

signed main() {
    int N, M;
    cin >> N >> M;
    vector<pair<int, int>> vp(N);
    for (auto& p : vp) cin >> p.first >> p.second;
    sort(vp.begin(), vp.end());

    priority_queue<int> q;
    int idx = 0;
    int ans = 0;
    for (int i = 0; i <= M; i++) {
        while (idx < N && vp[idx].first <= i) {
            q.push(vp[idx].second);
            idx++;
        }
        if (q.empty()) continue;
        ans += q.top();
        q.pop();
    }
    cout << ans << endl;
}


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main(){
	bool b=0;
	int n,ans=0;
	string a;
	cin>>a;
	n=a.size();
	for(int i=0;i<n;i++){
		bool t;
		b=!b;
		if(a[i]=='g'){
			t=1;
		}else if(a[i]=='p'){
			t=0;
		}
		if(t==b){
			continue;
		}else if(t==1&&b==0){
			ans++;
		}else{
			ans--;
		}
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 512
#include <stdio.h>

int main() {
	int n, k, d[100], a[100][100], dd[100] = {10000},ans=0;
	scanf("%d%d", &n, &k);
	for (int i = 0; i < n; i++) dd[i] = 0;
	for (int i = 0; i < k; i++) {
		scanf("%d", &d[i]);
		for (int j = 0; j < d[i]; j++) {
			scanf("%d", &a[i][j]);
			a[i][j]--;
			dd[a[i][j]]++;
		}
	}
	for (int i = 0; i < n; i++)if(dd[i]==0)ans++;
	printf("%d", ans);
	return 0;
}

Measured memory_bytes: 1744
N = int(input())
S = input()

L = [0]*N

l = 0
for i, x in enumerate(S):
    L[i] += l
    if x == 'E':
        l += 1
r = 0
for i, x in enumerate(S[::-1]):
    L[N-1-i] += r
    if x == 'W':
        r += 1

print(N-1 - max(L))


Measured memory_bytes: 15436
a,b = map(int,input().split())
AC = [0]*(a+1)
WA = [0]*(a+1)
ac = 0
wa = 0
wat = 0

for i in range(b):
  x,y = map(str,input().split())
  if y == "WA":
    WA[int(x)] += 1
  elif AC[int(x)] == 0 and y == "AC":
    wa += WA[int(x)]
    ac += 1
    AC[int(x)] = 1

print(ac,wa)


Measured memory_bytes: 4596
#include <iostream>
#include <bits/stdc++.h>
#include <algorithm>
#include <vector>
using namespace std;
#define rep(i,strt,end) for(long long i = strt;i < end;i++)
unsigned long long a,b,n;
unsigned long long calc(unsigned long long x){
    return (a*x)/b - a * (x / b);
}


int main(){
    cin >> a >> b >> n;
    if(n < b){
        cout << calc(n) << endl;
    }else{
        cout << max(calc(n - (n%b) - 1),calc(n)) << endl;
    }
    //--------------
    return 0;
}

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

public class Program
{
    static void Main()
    {
        var n = long.Parse(Console.ReadLine());
        var len = int.MaxValue;
        for (long i = 1; i * i <= n; i++)
        {
            if (n % i != 0)
            {
                continue;
            }

            len = Math.Min(len, F(i, n / i));
        }

        Console.WriteLine(len);
    }

    static int F(long a, long b)
    {
        return Math.Max(a.ToString().Length, b.ToString().Length);
    }
}


Measured memory_bytes: 13140
S = input()
temp1 = S[:1]
temp2 = S[:2]
# print(temp1+temp2)

count1 = 1
count2 = 1
i = 1
while (True):
    if i >= len(S):
        break
    else:
        if temp1 != S[i]:
            count1 += 1
            temp1 = S[i]
            i += 1
            # print(temp1)
        else:
            if i == len(S)-1:
                break
            else:
                temp1 = S[i]+S[i+1]
                count1 += 1
                i += 2
                # print(temp1)

i = 2

while (True):
    if i == len(S):
        break
    else:
        if temp2 != S[i]:
            count2 += 1
            temp2 = S[i]
            i += 1
            # print(temp2)
        else:
            if i == len(S)-1:
                break
            else:
                temp2 = S[i]+S[i+1]
                count2 += 1
                i += 2
                # print(temp2)

print(max(count1,count2))

Measured memory_bytes: 3500
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;

    long long a[n],
    cnt=0;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }
    sort(a,a+n);

    for(int i=0;i<n;i++)
    {
        for(int j=i+1;j<n;j++)
        {
            for(int k=j+1;k<n;k++)
            {
                if(a[i]<a[j] && a[j]<a[k])
                {
                    if(a[i]+a[j]>a[k])
                    {
                        cnt++;
                    }
                }
            }
        }
    }
    cout<<cnt<<endl;

}


Measured memory_bytes: 3596
#include <iostream>
#include <algorithm>
#include <utility>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <math.h>
#include <string.h>
#include <iomanip>
#include <numeric>
#include <cstdlib>
#include <cstdint>
#include <cmath>
#include <functional>
#include <limits>
#include <cassert>

using namespace std;

/* template */

using ll = long long;

void debug_out() { std::cout << std::endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cout << H << " ";
  debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cout << "debug: "; debug_out(__VA_ARGS__)
#else
#define debug(...) 
#endif

#define rep(i, a, n) for (int i = (int)(a); i < (int)(n); i++)
#define rrep(i, a, n) for (int i = ((int)(n-1)); i >= (int)(a); i--)
#define Rep(i, a, n) for (long long i = (long long)(a); i< (long long)(n); i++)
#define RRep(i, a, n) for (long long i = ((long long)(n-1ll)); i>=(long long)(a); i--)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()

template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
  for (std::size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  return os;
}

struct Edge{
    int to;
    ll weight;
    Edge(int t, ll w) : to(t), weight(w){ }
};

struct edge{
    int from;
    int to;
    ll weight;
    edge(int f,int t,ll w) : from(f), to(t), weight(w){ }
};


using Graph = vector<vector<Edge>>;
using graph = vector<vector<int>>;
using edges = vector<edge>;

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;
}

template <class T>
T lcm(T a, T b){
    return (a*b)/gcd(a,b);
}

bool isPalindrome(string s){
    string t = s;
    reverse(all(t));
    return s==t;
}

constexpr ll LNF = 1e15;

constexpr int INF = 1e9+7;

vector<int> dx = {-1,0,1,0,-1,1,-1,1};
vector<int> dy = {0,-1,0,1,1,-1,-1,1};

/* template */

vector<int> ans;
vector<ll> a;
vector<ll> dp;
vector<bool> seen;
graph g;

void dfs(int v){
    int x = lower_bound(all(dp),a[v])-dp.begin();
    ll pre = dp[x];
    dp[x] = a[v];
    ans[v] = lower_bound(all(dp),LNF)-dp.begin();
    for(auto &nv: g[v]){
        if(seen[nv]) continue;
        seen[nv] = true;
        dfs(nv);
    }
    dp[x] = pre;
}

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    a.resize(n);
    rep(i,0,n) cin >> a[i];
    g.resize(n);
    rep(i,0,n-1){
        int u,v; cin >> u >> v;
        u--; v--;
        g[u].emplace_back(v);
        g[v].emplace_back(u);
    }
    ans.resize(n);
    dp.assign(n,LNF);
    seen.assign(n,false);
    ans[0] = 1;
    seen[0] = true;
    dfs(0);
    rep(i,0,n){
        cout << ans[i] << endl;
    }
}

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

using namespace std;

using ll = long long;

template <class SemiLattice>
struct SparseTable {
    using T = typename SemiLattice::T;

    int n;
    vector< vector<T> > table;
    vector<int> log_table;

    SparseTable() {}
    SparseTable(const vector<T>& v) : n(v.size()) {
        log_table.resize(n + 1, 0);
        for (int i = 2; i <= n; i++) {
            log_table[i] = log_table[i >> 1] + 1;
        }

        table.resize(log_table[n] + 1, vector<T>(n));
        for (int i = 0; i < n; i++) {
            table[0][i] = v[i];
        }

        size_t sz = table.size();
        for (int i = 1; i < sz; i++) {
            for (int j = 0; j + (1 << i) <= n; j++) {
                table[i][j] = SemiLattice::merge(table[i - 1][j], table[i - 1][j + (1 << (i - 1))]);
            }
        }
    }

    //区間[l, r)に対するクエリに答える
    T query(int l, int r) {
        assert(l < r && r <= n);
        int k = log_table[r - l];
        return SemiLattice::merge(table[k][l], table[k][r - (1 << k)]);
    }
};

//以下、SemiLatticeの例
template <class U = ll>
struct RMQSL {
    using T = U;
    static T merge(T a, T b) { return __gcd(a, b); }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    SparseTable< RMQSL<int> > st(a);

    int ans = 0;
    for (int i = 0; i < n; i++) {
        int g = 0;
        if (i > 0) g = st.query(0, i);
        if (i < n - 1) {
            if (g == 0) g = st.query(i + 1, n);
            else g = __gcd(g, st.query(i + 1, n));
        }
        ans = max(ans, g);
    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 8064
#include <iostream>
#include <algorithm>
using namespace std;
struct {int no, w, l, d, p, r;} t[100], u;
int main()
{
	int n, a, b, c, d, r = 1, i, j, z = 1;
	cin >> n;
	for (i = 0; i < n; i++)
		t[i].w = t[i].l = t[i].d = 0;
	for (i = 0; i < n*(n-1)/2; i++)
	{
		cin >> a >> b >> c >> d;
		t[a-1].no = a;
		t[b-1].no = b;
		if (c > d)
		{
			t[a-1].w++;
			t[b-1].l++;
		}
		else if (c == d)
		{
			t[a-1].d++;
			t[b-1].d++;
		}
		else
		{
			t[a-1].l++;
			t[b-1].w++;
		}
	}
	for (i = 0; i < n; i++)
		t[i].p = t[i].w * 3 + t[i].d;
	for (i = 0; i < n; i++)
	{
		for (j = 0; j < n-1; j++)
		{
			if (t[j].p < t[j+1].p)
				u = t[j], t[j] = t[j+1], t[j+1] = u;
		}
	}
	for (i = 0; i < n; i++)
	{
		if (i != 0)
			if (t[i-1].p != t[i].p)
				r += z, z = 1;
			else
				z++;
		t[i].r = r;
	}
	for (i = 0; i < n; i++)
	{
		for (j = 0; j < n-1; j++)
		{
			if (t[j].no > t[j+1].no)
				u = t[j], t[j] = t[j+1], t[j+1] = u;
		}
	}
	for (i = 0; i < n; i++)
		cout << t[i].r << endl;
}

Measured memory_bytes: 0