akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;

int N,M;
const int MAX_N = 105;
int a[MAX_N],cnt[MAX_N];

bool solve(){
	if(cnt[M]==1)return false;
	for(int i=0;i<=(M-1)/2;i++){
		if(cnt[i])return false;
	}
	for(int i=(M+1)/2;i<=M;i++){
		if(i==(M+1)/2){
			if(M%2==0 && cnt[(M+1)/2]!=1)return false;
			if(M%2==1 && cnt[(M+1)/2]!=2)return false;
		}else if(cnt[i]<2){
			return false;
		}
	}
	return true;
}

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

	cin >> N;
	for(int i=0;i<N;i++){
		cin >> a[i];
		cnt[a[i]]++;
		M = max(M,a[i]);
	}

	if(solve()){
		cout << "Possible" << endl;
	}else{
		cout << "Impossible" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define mp(x,y) make_pair(x,y)
const int nax=2e5+5;
void solve(){
    string a,b;
    cin>>a>>b;
    int n=a.size();
    if(b.substr(0,n)==a)cout<<"Yes\n";
    else cout<<"No\n";
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    int tc;
    tc=1;
    while(tc--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 3620
import java.util.Scanner;
import java.util.stream.IntStream;

public class Main {

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int n = scanner.nextInt();
			int[] v = IntStream.range(0, n).map(i -> scanner.nextInt()).toArray();
			int[] c = IntStream.range(0, n).map(i -> scanner.nextInt()).toArray();
			System.out.println(IntStream.range(0, n).map(i -> v[i] - c[i]).filter(i -> i > 0).sum());
		}
	}
}


Measured memory_bytes: 36420
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <string>
#include <iostream>
#include <algorithm>
#include <queue>
#include <map>

using namespace std;

typedef long long ll;
const int N = 200100;
ll a[N], b[N];

int main(){
	ll n, t;
	memset(a, 0, sizeof(a));
	memset(b, 0, sizeof(b));
	while(~scanf("%lld %lld", &n, &t)){
		for(int i = 0; i < n; i++)
			cin >> a[i];
		ll sum = 0;
		for(int i = 1; i < n; i++){
			sum = sum + min(a[i] - a[i - 1], t);
		}
		printf("%lld\n", sum + t);
	}
}

Measured memory_bytes: 3328
use std::io;


/// https://beta.atcoder.jp/contests/code-festival-2016-quala/tasks/codefestival_2016_qualA_b
fn main() {
    let n = read_one::<usize>();
    let an = read::<usize>();
    let mut cnt = 0;
    for i in 0..n {
        if an[an[i] - 1] == i + 1 { cnt += 1; }
    }
    println!("{}", cnt / 2);
}


#[allow(dead_code)]
fn read<T>() -> Vec<T>
where T:
    std::str::FromStr,
    T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.split_whitespace()
        .map(|s| s.trim().parse().unwrap())
        .collect()
}

#[allow(dead_code)]
fn read_one<T>() -> T
where T:
    std::str::FromStr,
    T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.trim().parse().unwrap()
}

Measured memory_bytes: 6396
#include <iostream>
#include <vector>
using namespace std;
int main(){
  int h,w;
  cin >> h >> w;
  vector<string> s(h);
  for(int i=0;i<h;i++){
    cin >> s[i];
  }

  vector<vector<int>> m(h,vector<int>(w));

  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      m[i][j] = 0;
    }
  }

  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      for(int kh=-1;kh<=1;kh++){
        for(int kw=-1;kw<=1;kw++){
          if(i+kh>=0 && i+kh<h && j+kw>=0 && j+kw<w){
            if(!(kh==0&&kw==0)){
              if(s[i+kh][j+kw]=='#'){
                m[i][j]++;
              }
            }
          }
        }
      }
    }
  }

  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      if(s[i][j] != '#'){
        s[i][j] = '0'+m[i][j];
      }
    }
  }

  for(int i=0;i<h;i++){
    cout << s[i] << endl;
  }
}


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

// #define int long long
#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) int(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;

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

const ll INF = 1e15;
const int MOD = 1e9+7;
const ll LINF = 1e18;

ll G[10][10];
ll dist[10][10];


signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  ll h,w; cin>>h>>w;
  rep(i,10) rep(j,10) cin>>G[i][j];
  
  memset(dist,0x3f,sizeof(dist));
  
  rep(i,10){
    priority_queue<pll, vector<pll>, greater<pll>> q;
    q.emplace(0,i);
    dist[i][i]=0;
    // vector<bool> visited(10);
    // visited[i]=true;
    while(!q.empty()){
      auto p=q.top(); q.pop();
      ll v=p.second, c=p.first;
      if(dist[i][v]<c) continue;
      rep(nv,10){
        ll nc=G[v][nv];
        if(dist[i][nv]>c+nc){
          dist[i][nv]=c+nc;
          q.emplace(dist[i][nv],nv);
        }
      }
    }
  }
  vll a(10);
  rep(i,10){
    a[i]=dist[i][1];
    // cout<<a[i]<<" ";
  }
  // cout<<endl;
  
  ll ans=0;
  rep(i,h){
    rep(j,w){
      ll b; cin>>b;
      if(b==-1) continue;
      ans+=a[b];
    }
  }
  
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N=100005;
int n,q,a[N],ans;
signed main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		int x;
		cin>>x;
		a[x]++;
		ans+=x;
	}
	cin>>q;
	while(q--)
	{
		int b,c;
		cin>>b>>c;
		ans+=(c-b)*a[b];
		a[c]+=a[b];
		a[b]=0;
		cout<<ans<<endl;
	}
	return 0;
}


Measured memory_bytes: 4376
#include<bits/stdc++.h>
using namespace std;
int n,i,c,x,y;
set<int>S;
main()
{
  cin>>n;
  for(i=0;i<n;i++)
  {
    cin>>c>>x;
    if(c==1)cout<<(S.find(x)!=S.end())<<endl;
    else if(c==0)S.insert(x),cout<<S.size()<<endl;
    else if(c==2)S.erase(x);
    else
    {
      cin>>y;
      auto a=S.lower_bound(x),b=S.upper_bound(y);
      for(auto it=a;it!=b;it++)cout<<*it<<endl;
    }
  }
}


Measured memory_bytes: 12372
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> ii;
typedef vector<ll> vi;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<ii> vii;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define fr(be, en) for(ll i = be; i <= en; i++) 
ll mod = 998244353;
ll power(ll a, ll b)
{
	if(b == 0) return 1;
	ll ans = power(a, b/2);
	ans = (ans*ans)%mod;
	if(b%2) ans*=a;
	return ans%mod;
}
ll mul(ll a,ll n, ll mod)
{
	ll ret;
	if(n==0) return 0;
	ret = mul(a,n/2, mod);
	ret = (ret+ret)%mod;
	if(n%2)	ret=(ret+a)%mod;
	return ret;
}
ll dp[3001][3001];
vi v(3001, 0);
vi p(3001, 1);
ll n, k, val;
vi fact(3001, 1);
vi inv_fact(3001, 1);
ll ncr(ll a, ll b)
{
	ll den = (inv_fact[b]*inv_fact[a - b])%mod;
	return (fact[a]*den)%mod;
}
ll solve(int idx, int targ)
{
	if(idx > 3000) 
	{
		if(targ == 0) return 1;
		return 0;
	}
	if(dp[idx][targ] != -1) return dp[idx][targ];
	ll cur_ans = 0;
	for(ll i = 0; i <= v[idx]; i++)
	{
		if(i*idx <= targ)
		{
			cur_ans += (((ncr(v[idx], i)*p[v[idx] - i])%mod)*solve(idx + 1, targ - i*idx))%mod;
			cur_ans %= mod;
		}
	}
	return dp[idx][targ] = cur_ans;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cout.tie(NULL);
	cin.tie(NULL);
	cin >> n >> k;
	fr(1, n)
	{
		cin >> val;
		v[val]++;
	}
	fr(1, 3000)
	{
		 p[i] = (p[i - 1]*2)%mod;
		fact[i] = (fact[i - 1]*i)%mod;
		inv_fact[i] = (power(i, mod - 2)*inv_fact[i - 1])%mod;
	}
	memset(dp, -1, sizeof(dp));
	cout << solve(0, k);
}

Measured memory_bytes: 74432
#include<cstdio>
#include<map>
using namespace std;
#define int long long
#define re 
int n,a,b,c,d,f,tot;
inline long long as(re long long x){
	return x<0?-x:x;
}
map<int,int>v;
inline int dfs(re int x){
	if(x==0)return 0;if(x==1)return d;
	if(v.find(x)!=v.end())return v[x];
	re int ans=min(9e18,(double)x*d);
	ans=min(ans,dfs(x/5)+c+(x%5)*d);
	ans=min(ans,dfs(x/5+1)+c+(5-x%5)*d);
	ans=min(ans,dfs(x/3)+b+(x%3)*d);
	ans=min(ans,dfs(x/3+1)+b+(3-x%3)*d);
	ans=min(ans,dfs(x/2)+a+(x%2)*d);
	if(x!=2)
	ans=min(ans,dfs(x/2+1)+a+(2-x%2)*d);
	return v[x]=ans;
}
signed main(){
	int t;
	scanf("%lld",&t);
	while(t--){
	scanf("%lld%lld%lld%lld%lld",&n,&a,&b,&c,&d);tot=0;v.clear();
	printf("%lld\n",dfs(n)); 
	}
}

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

int main(){
  int64_t L,R;
  cin >> L >> R;
  vector <int> v;
  if(R-L>=2019){
    cout << 0 << endl;
    return 0;
  }else{
    L%=2019;
    R%=2019;
    if(L>R){
      cout << 0 << endl;
      return 0;
    }else{
      for(int i=L;i<R;i++){
        for(int j=i+1;j<=R;j++){
          v.push_back((i*j)%2019);
        }
      }
      sort(v.begin(),v.end());
      cout << v.at(0) << endl;
      return 0;
    }
  }
}


Measured memory_bytes: 10476
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,a,b) for(ll i=a;i<=b;i++)
#define repr(i,a,b) for(ll i=a;i>=b;i--)

int main() {
    // your code goes here
    char a[5][2005];
    ll l[5],r[5]={0},ans=100000000;
    bool z[5015][5][5]={0};
    cin >> a[0] >> a[1] >> a[2];
    rep(i,0,2) l[i]=strlen(a[i]);
    rep(i,0,2){
        rep(j,0,2){
            if(i==j) continue;
            rep(k,0,l[i]-1){
                bool memo=true;
                rep(s,0,min(l[j]-1ll,l[i]-k-1)){
                    if(a[i][k+s]=='?') continue;
                    if(a[j][s]=='?') continue;
                    if(a[i][k+s]!=a[j][s]) memo=false;
                }
                if(memo) z[k][i][j]=true;
                //if(memo) cout << i << " " << j << " " << k << endl;
            }
            rep(k,l[i],5000) z[k][i][j]=true;
        }
    }
    vector<ll> p;
    p.push_back(0); p.push_back(1); p.push_back(2);
    do {
        rep(i,0,3*l[p[0]]){
            rep(j,0,min(3ll*l[p[1]],4500ll-i)){
                if(z[i][p[0]][p[1]]&&z[j][p[1]][p[2]]&&z[i+j][p[0]][p[2]]){
                    ll mm=max(l[p[0]],max(i+l[p[1]],i+j+l[p[2]]));
                    ans=min(ans,mm);
                }
            }
        }
    } while (next_permutation(p.begin(),p.end()));
    cout << ans << endl;
    return 0;
}

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

int main(){
    double w, h, x, y;
    cin >> w >> h >> x >> y;
    int p = 0;
    if(x == w/2 && y == h/2) p = 1;
    double ans = w*h/2;
    cout << ans << endl;
    cout << p << endl;
    return 0;
}

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

int main(){
  int N;
  cin >> N;
  int th_num,h_num,te_num,o_num;
  th_num = N /1000;
  N %= 1000;
  h_num = N/100;
  N %= 100;
  te_num = N/10;
  o_num = N%10;
  if(th_num==h_num&&th_num==te_num){
      cout << "Yes" << endl;
  }
  else if(h_num==te_num&&h_num==o_num){
      cout << "Yes" <<endl;
  }
  else{
    cout << "No" << endl; 
  }
}

Measured memory_bytes: 256
def dfs(u):
    global dfs_color, d, f, t
    color[u] = GRAY
    d[u] += t
    t += 1
    for v in range(n):
        if (M[u][v] == 0):
            continue
        else:
            if (color[v] == WHITE):
               dfs(v)
    color[u] = BLACK
    f[u] = t
    t += 1

n = int(input())
M = [[False for i in range(n)] for j in range(n)]
for i in range(n):
    tmp = list(map(int, input().split()))
    for j in range(tmp[1]):
        M[tmp[0]-1][tmp[j+2]-1] = True

WHITE = 0
GRAY = 1
BLACK = 2
color = [WHITE for i in range(n)]
d = [0 for i in range(n)]
f = [0 for i in range(n)]
t = 1

for u in range(n):
    if (color[u] == WHITE):
        dfs(u)
for u in range(n):
    print(str(u+1), str(d[u]), str(f[u]), sep = " ")

Measured memory_bytes: 5808
#include <bits/stdc++.h>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long int;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll INF = 1e10;
const ll MOD = 1000000007;
typedef pair<ll,ll> P;
int main() {
    string s;
    cin >> s;
    int cnt1 = 0,cnt2 = 0;
    rep(i,s.length()){
        if (s[i] == '0') cnt1++;
        else cnt2++;
    }
    PRINT(2*min(cnt1,cnt2));
}

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

int main()
{
    int a,b,c;
    scanf("%d%d%d",&a,&b,&c);
    int t;
    t=b/a;
    if(t>=c)
        printf("%d\n",c);
    else
        printf("%d\n",t);
    return 0;
}


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

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

  vector<int> vec2(N);
  for (int i = 0; i < M; i++) {
    vector<int> vec(2);
    cin >> vec.at(0) >> vec.at(1);
    for (int j = 0; j < N; j++) {
      if (vec.at(0) == j + 1) {
        vec2.at(j)++;
      }
      if (vec.at(1) == j + 1) {
        vec2.at(j)++;
      }
    }
  }
  for (int k = 0; k < N; k++) {
    cout<< vec2.at(k) << endl;
  }
}


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

long long modpow(int a, long long n, int mod) {
  long long res = 1;
  long long apow = a; // a^1, a^2, a^4, ...
  while (n) {
    if (n & 1LL)
      res = (res * apow) % mod;
    apow = apow * apow % mod;
    n = n >> 1;
  }
  return res;
}

int main() {
  int N, K;
  std::cin >> N >> K;

  int mod = 1000000007;
  long long res = 0;
  std::vector<long long> dp(K + 1, 0);
  for (int v = K; v >= 1; --v) {
    long long tmp = modpow(K / v, N, mod);
    int p = 2;
    while (p * v <= K) {
      tmp -= dp[p * v];
      if (tmp < 0)
        tmp += mod;
      p += 1;
    }
    dp[v] = tmp;
    res = (res + v * tmp) % mod;
  }
  std::cout << res << std::endl;
}


Measured memory_bytes: 4012
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define ld long double
#define F first
#define S second
#define P pair<int,int>
#define V vector
#define pb push_back
#define mp make_pair
#define endl "\n"
#define db(...) __f(#__VA_ARGS__, __VA_ARGS__)
#define MOD 1000000007  //1e9+7

template <typename Arg1>
void __f(const char* name, Arg1&& arg1) { cout << name << " : " << arg1 << '\n'; }
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
    const char* comma = strchr(names + 1, ',');
    cout.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...);
}

void solve()
{
	int n; cin>>n;
	vector<int>a;
	int op1=0,op2=0,cnt=0;
	for(int i=0,x;i<n;i++){
		cin>>x;
		if(x!=i+1){
			cnt++;
			if(cnt>2){
				cout<<"NO"<<endl;
				return;
			}
			if(op1==0) op1=i+1;
			else op2=i+1;
		}
	}
	cout<<"YES"<<endl;
}
	
int32_t main()
{
    ios_base:: sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    //int t; cin>>t;
    //while(t--)
    solve();
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h> 
using namespace std; 
  
int main() 
{ 
    string s;
    cin>>s;
    string words[7] = { "SAT", "FRI", 
                         "THU", "WED","TUE","MON","SUN" }; 
  
    // Print Strings 
    int i;
    for ( i = 0; i < 7; i++) 
        if(s==words[i]){
            cout<<i+1;
        }
        return 0;
} 
  

Measured memory_bytes: 256
n,m = map(int,input().split())
a_list = []
for i in range(n):
  a_list.append(input())
b_list = []  
for i in range(m):
  b_list.append(input())
move = n - m + 1
ans = "No"
for i in range(move):
  for j in range(move):
    check = True
    for k  in range(m):
      for l in range(m):
        if a_list[i + k][j + l] != b_list[k][l] :
          check = False
    if check == True:
      ans = "Yes"
print(ans)      

      
      

Measured memory_bytes: 3188
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <numeric>
using namespace std;
typedef long long int ll;

#define EPS (1e-7)
#define INF 1e18
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define PI (acos(-1))

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define rep(i, init, n) for(int i = init; i <(int)(n); i++)

int main() {

    int N, A;
    cin >> N >> A;

    REP(i, A+1){
        if (N - i >= 0 && (N - i) % 500 == 0){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;

    return 0;
}

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

using namespace std;
using namespace __gnu_pbds; 
  
#define ll long long
#define X first
#define Y second
#define all(x) x.begin(), x.end()
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
	enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
	ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
	*this << "[";
	for (auto it = d.b; it != d.e; ++it)
		*this << ", " + 2 * (it == d.b) << *it;
	ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

const int mod = (int)1e9 + 7;
const int MX = (int)1e5 + 10;

void add_self(int &x, int y){x += y; if(x >= mod) x -= mod;}
void sub_self(int &x, int y){x -= y; if(x < 0) x += mod;}
void mul(int &x, int y){x = x * 1LL * y % mod;}

int main(){

	cin.tie(0); cout.tie(0);
	ios_base::sync_with_stdio(0);

	string s;
	cin >> s;
	int n = s.size();

	ll res = 0;
	// map<pair<int, int>, int> mp;
	// int prf3 = 0;
	// int prf673 = 0;
	// mp[{0, 0}] = 1;
	// int pw3 = 1;
	// int pw673 = 1;
	unordered_map<int, int> mem;
	mem[0] = 1;
	int pw = 1;
	int sum = 0;

	for(int i = n - 1; i >= 0; --i){
		int d = s[i] - '0';
		// prf3 = (prf3 + d * pw3) % 3;
		// prf673 = (prf673 + d * pw673) % 673;
		// pw3 = pw3 * 10 % 3;
		// pw673 = pw673 * 10 % 673;
		// res += mp[{prf3, prf673}];
		// cout << prf3 << " " << prf673 << endl;
		// mp[{prf3, prf673}]++;
		sum = (sum + d * pw) % 2019; 
		res += mem[sum];
		mem[sum]++;
		pw = (pw * 10 % 2019);
	}
	cout << res << endl;

	return 0;
}

Measured memory_bytes: 3792
/*
    Author: Nguyen Tan Bao
    Status:
    Idea:
*/

#include <bits/stdc++.h>
#define FI first
#define SE second
#define EPS 1e-9
#define ALL(a) a.begin(),a.end()
#define SZ(a) int((a).size())
#define MS(s, n) memset(s, n, sizeof(s))
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORE(i,a,b) for (int i = (a); i >= (b); i--)
#define FORALL(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
//__builtin_ffs(x) return 1 + index of least significant 1-bit of x
//__builtin_clz(x) return number of leading zeros of x
//__builtin_ctz(x) return number of trailing zeros of x

using namespace std;
using ll = long long;
using ld = double;
typedef pair<int, int> II;
typedef pair<II, int> III;
typedef complex<ld> cd;
typedef vector<cd> vcd;

const ll MODBASE = 1000000007LL;
const int MAXN = 110;
const int MAXM = 1000;
const int MAXK = 16;
const int MAXQ = 200010;

#include <atcoder/all>
using namespace atcoder;

int n, q;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    cin >> n >> q;
    fenwick_tree<ll> fw(n);
    FOR(i,1,n) {
        int x;
        cin >> x;
        fw.add(i-1, x);
    }
    while (q--) {
        int ch, u, v;
        cin >> ch >> u >> v;
        if (ch == 0) {
            fw.add(u, v);
        } else {
            cout << fw.sum(u, v) << "\n";
        }
    }
    return 0;
}


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

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

int main(){
	string s; cin>>s;
	int n=s.length();

	int ans=0,last=0;
	rep(i,n){
		if(last!=1 || s[i]!=s[i-1]){
			ans++;
			last=1;
		}
		else{
			if(i<n-1) ans++;
			last=2;
			i++;
		}
	}
	printf("%d\n",ans);

	return 0;
}


Measured memory_bytes: 640
package main

import (
	"bufio"
	"errors"
	"fmt"
	"math"
	"os"
	"strconv"
	"strings"
)

var sc = bufio.NewScanner(os.Stdin)

// NextLine reads a line text from stdin, and then returns its string.
func NextLine() string {
	sc.Scan()
	return sc.Text()
}

// NextIntsLine reads a line text, that consists of **ONLY INTEGERS DELIMITED BY SPACES**, from stdin.
// And then returns intergers slice.
func NextIntsLine() []int {
	ints := []int{}
	intsStr := NextLine()
	tmp := strings.Split(intsStr, " ")
	for _, s := range tmp {
		integer, _ := strconv.Atoi(s)
		ints = append(ints, integer)
	}
	return ints
}

// NextRunesLine reads a line text, that consists of **ONLY CHARACTERS ARRANGED CONTINUOUSLY**, from stdin.
// Ant then returns runes slice.
func NextRunesLine() []rune {
	return []rune(NextLine())
}

// Max returns the max integer among input set.
// This function needs at least 1 argument (no argument causes panic).
func Max(integers ...int) int {
	m := integers[0]
	for i, integer := range integers {
		if i == 0 {
			continue
		}
		if m < integer {
			m = integer
		}
	}
	return m
}

// Min returns the min integer among input set.
// This function needs at least 1 argument (no argument causes panic).
func Min(integers ...int) int {
	m := integers[0]
	for i, integer := range integers {
		if i == 0 {
			continue
		}
		if m > integer {
			m = integer
		}
	}
	return m
}

// PowInt is integer version of math.Pow
func PowInt(a, e int) int {
	if a < 0 || e < 0 {
		panic(errors.New("[argument error]: PowInt does not accept negative integers"))
	}
	fa := float64(a)
	fe := float64(e)
	fanswer := math.Pow(fa, fe)
	return int(fanswer)
}

// AbsInt is integer version of math.Abs
func AbsInt(a int) int {
	fa := float64(a)
	fanswer := math.Abs(fa)
	return int(fanswer)
}

// DeleteElement returns a *NEW* slice, that have the same and minimum length and capacity.
// DeleteElement makes a new slice by using easy slice literal.
func DeleteElement(s []int, i int) []int {
	if i < 0 || len(s) <= i {
		panic(errors.New("[index error]"))
	}
	// appendのみの実装
	n := make([]int, 0, len(s)-1)
	n = append(n, s[:i]...)
	n = append(n, s[i+1:]...)
	return n
}

// Concat returns a *NEW* slice, that have the same and minimum length and capacity.
func Concat(s, t []rune) []rune {
	n := make([]rune, 0, len(s)+len(t))
	n = append(n, s...)
	n = append(n, t...)
	return n
}

// sort package (snippets)
//sort.Sort(sort.IntSlice(s))
//sort.Sort(sort.Reverse(sort.IntSlice(s)))
//sort.Sort(sort.Float64Slice(s))
//sort.Sort(sort.StringSlice(s))

// copy function
//a = []int{0, 1, 2}
//b = make([]int, len(a))
//copy(b, a)

/*******************************************************************/

var n, m int
var T, P, X []int

func main() {
	tmp := NextIntsLine()
	n = tmp[0]
	T = NextIntsLine()
	tmp = NextIntsLine()
	m = tmp[0]
	for i := 0; i < m; i++ {
		tmp = NextIntsLine()
		P = append(P, tmp[0])
		X = append(X, tmp[1])
	}

	// ドリンク
	for i := 0; i < m; i++ {
		// 問題
		answer := 0
		for j := 0; j < n; j++ {
			if P[i]-1 == j {
				answer += X[i]
			} else {
				answer += T[j]
			}
		}
		fmt.Println(answer)
	}
}


Measured memory_bytes: 640
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>//sort,reverse
#include<utility>//pair
#include<queue>//queue,priority_queue
#include<deque>//double_ended queue
#include<map>//map
using namespace std;
typedef long long LL; 
typedef pair<LL,LL> P;//Pでpair<-,->を表す。
const LL MAX=2000010;
LL MOD;
typedef map<LL,LL>::iterator Itr;

/*ここから*/
LL Euclid(LL a,LL b){
    while(1){
        if(a<b){int c=a;a=b;b=c;}
        if(a%b==0){return b;}
        else{a=a%b;}
    }
}
/*ここまで*/
/*ここから*/
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;
}

/*ここまで*/

int main()
{ 
    LL A,B,n;
    cin>>A>>B>>n;
    /*LL d=Euclid(A,B);
    LL a=A/d;
    LL b=B/d;
    MOD=b;
    COMinit();
    LL max=n;
    LL min=0;
    while(max-min>1){
        LL m=(max+min)/2;
        LL x=b*
    }*/
    if(B>n){
        cout<<(n*A)/B<<endl;
    }
    else{cout<<((B-1)*A)/B<<endl;}
    return 0;
}

Measured memory_bytes: 3592
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main{

	public static void main(String[] args) throws IOException {
		//variety
		String str;
		int a, b, c;

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		str = br.readLine();
		int N = Integer.parseInt(str);
		for (int i = 0; i < N; i++) {
			str = br.readLine();
			String[] num = str.split(" ", 0);
			a = Integer.parseInt(num[0]);
			b = Integer.parseInt(num[1]);
			c = Integer.parseInt(num[2]);
			if (a >= b && a >= c) {
				if (a * a == b * b + c * c) {
					System.out.println("YES");
				} else {
					System.out.println("NO");
				}
			} else {
				if (b >= a && b >= c) {
					if (b * b == a * a + c * c) {
						System.out.println("YES");
					} else {
						System.out.println("NO");
					}
				} else {
					if (c >= a && c >= b) {
						if (c * c == a * a + b * b) {
							System.out.println("YES");
						} else {
							System.out.println("NO");
						}
					}
				}
			}
		}
	}

}

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

int main() {
  int a,b,c,x,y,sum;
  cin>>a>>b>>c>>x>>y;

  if (a+b>c*2) 
  {
    if (x<y) 
    {
      sum=x*2*c;
      y-=x;
      
      if (b>c*2) 
      {
	    sum+=y*2*c;
      }
      else 
      {
	    sum+=y*b;
      }
    }

    else 
    {
      sum=y*2*c;
      x-=y;
      
      if (a>c*2) 
      {
	    sum+=x*2*c;
      }
      
      else 
      {
	    sum+=x*a;
      }
    }
  }  
  else 
  {
    sum=x*a+y*b;
  }

  cout << sum << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <iomanip>
using namespace std;
typedef long long ll;
int INF=1<<29;

int main(){
	ios::sync_with_stdio(false);
	ll N,A,B;
	ll pat[60][60],ans2=0;
	long double sum[60][60],dp[60][60],ans=0;
	cin>>N>>A>>B;
	vector<long double> v(N);
	for(int i=0;i<N;i++) cin>>v[i];
	for(int i=0;i<60;i++){
		for(int j=0;j<60;j++){
			sum[i][j]=0;
			dp[i][j]=0;
			pat[i][j]=0;
		}
	}
	for(int j=0;j<60;j++) pat[0][j]=1;
	for(int i=0;i<N;i++){
		for(int j=0;j<60;j++){
			if(j==0){
				dp[i+1][j]=dp[i][j];
				pat[i+1][j]=pat[i][j];
			}else{
				if(dp[i][j]>(sum[i][j-1]+v[i])/j){
					dp[i+1][j]=dp[i][j];
					sum[i+1][j]=sum[i][j];
					pat[i+1][j]=pat[i][j];
				}else{
					dp[i+1][j]=(sum[i][j-1]+v[i])/j;
					sum[i+1][j]=sum[i][j-1]+v[i];
					if(dp[i][j]==(sum[i][j-1]+v[i])/j){
						pat[i+1][j]=pat[i][j];
						pat[i+1][j]+=pat[i][j-1];
					}else{
						pat[i+1][j]=pat[i][j-1];
					}
				}
			}
		}
	}
	for(int i=A;i<=B;i++){
		if(ans<dp[N][i]){
			ans=dp[N][i];
			ans2=pat[N][i];
		}else if(ans==dp[N][i]){
			ans2+=pat[N][i];
		}
	}
	cout<<fixed<<ans<<endl;
	cout<<ans2<<endl;
	return 0;
}

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

int main()
{
    int N;
    long long mod = 1000000000 + 7;
    cin >> N;
    long long A[N];
    for (int i = 0; i < N; i++)
    {
        cin >> A[i];
    }
    long long sum_mod[N + 2];
    sum_mod[N+1] = 0;
    for (int i = N; i > 0; i--)
    {
        sum_mod[i] = sum_mod[i+1] + A[i - 1];
        sum_mod[i] %= mod;
    }
    long long ans = 0;
    for (int i = 0; i < N-1; i++)
    {
        ans += (A[i]*sum_mod[i+2])%mod;
    }
    cout << ans % mod << endl;
}

Measured memory_bytes: 6776
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int[] dic = new int[m+1];

        sc.nextLine();
        for (int i = 0; i < n; i++) {
            String line = sc.nextLine();

            boolean flag = false;
            for (String s : line.split(" ")) {
                if (flag) {
                    dic[Integer.valueOf(s).intValue()]++;
                } else {
                    flag = true;
                }

            }
        }

        int sum = 0;
        for (int i : dic) {
            if (i == n) sum++;
        }
        System.out.println(sum);
    }
}

Measured memory_bytes: 21844
import sys
input=sys.stdin.readline
from collections import defaultdict as dd
n,w=map(int,input().split())
maxn=10000000000000000
we=[0]*n
val=[0]*n
su=0
for i in range(n):
    ww,v=map(int,input().split())
    we[i]=ww
    val[i]=v
    su+=v
dp=[maxn]*(su+1)
dp[0]=0
for i in range(n):
    for j in range(su-val[i],-1,-1):
        dp[j+val[i]]=min(dp[j+val[i]],we[i]+dp[j])
ans=0
for i in range(len(dp)):
    if(dp[i]<=w):
        ans=max(ans,i)
print(ans)

Measured memory_bytes: 41436
import collections
n = int(input())
s = [input() for i in range(n)]
s.sort()
t = collections.Counter(s)
maxv = max(t.values())
li = []
for key,value in t.items():
    if value == maxv:
        li.append(key)
li.sort()
for i in range(len(li)):
    print(li[i])

Measured memory_bytes: 35572
import java.util.Scanner;

/**
 *
 * @author k16075kk
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        Scanner stdIn = new Scanner(System.in);
        String s = stdIn.next();
        String p = stdIn.next();
        s += s;
        boolean flag;

        for (int i = 0; i < s.length() / 2; i++) {
            if (s.charAt(i) == p.charAt(0)) {
                flag = true;
                for (int j = i + 1, k = 1; k < p.length(); j++, k++) {
                    if (s.charAt(j) != p.charAt(k)) {
                        flag = false;
                    }
                }
                if (flag) {
                    System.out.println("Yes");
                    return;
                }
            }
        }
        System.out.println("No");
    }
}





Measured memory_bytes: 26332
#include"bits/stdc++.h"
using namespace std;

void Main() {
  int x, y, z, k;
  cin >> x >> y >> z >> k;
  vector<long long> a(x), b(y), c(z);
  for (int i = 0; i < x; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < y; i++) {
    cin >> b[i];
  }
  for (int i = 0; i < z; i++) {
    cin >> c[i];
  }

  vector<long long> ab;
  for (int i = 0; i < x; i++) {
    for (int j = 0; j < y; j++) {
      ab.push_back(a[i] + b[j]);
    }
  }
  sort(ab.rbegin(), ab.rend());
  sort(c.rbegin(), c.rend());
  vector<long long> ans;
  for (int i = 0; i < min(k, (int)ab.size()); i++) {
    for (int j = 0; j < min(k, (int)c.size()); j++) {
      ans.push_back(ab[i] + c[j]);
    }
  }
  sort(ans.rbegin(), ans.rend());
  for (int i = 0; i < k; i++) {
    cout << ans[i] << endl;
  }
}

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


Measured memory_bytes: 43368
import sys
readline = sys.stdin.readline

N,M = map(int,readline().split())
G = [[] for i in range(N)]
for i in range(M):
  a,b = map(int,readline().split())
  G[a - 1].append(b - 1)
  G[b - 1].append(a - 1)

ans = [None] * N
from collections import deque
q = deque([[0,-1]])
while q:
  v,parent = q.popleft()
  if ans[v] is not None:
    continue
  ans[v] = parent
  for child in G[v]:
    if ans[child] is None:
      q.append([child, v])
print("Yes")
for i in range(1,len(ans)):
  print(ans[i] + 1)

Measured memory_bytes: 41736
n = int(input())
ans = 0
for i in range(1,n+1):
    t,b = str(i)[0],str(i)[-1]
    if b == "0":
        continue
    if t==b:
        ans += 1
    if int(b + t) <= n:
        ans += 1
    l = len(str(n))
    for j in range(l-2):
        if j == l - 3:
            if int(str(n)[0]) > int(b):
                ans += 10**(j + 1)
            elif int(str(n)[0]) == int(b):
                ans += int(str(n)[1:-1])
                if int(str(n)[-1]) >= int(t):
                    ans += 1
        else:
            ans += 10 ** (j + 1)
print(ans)

Measured memory_bytes: 3064
s = list(map(str,input()))
ans = 0
if s[0] == "A":
    ans += 1
S = (s[2:-1])
c = 0
cp = 0
for i in range(len(S)):
    if S[i] == "C":
        c += 1
        cp = i
if c == 1:
    ans += 1
isl = 0
for i in range(len(s)):
    if i == 0 or i == cp+2:
        pass
    else :
        if s[i].islower():
            isl += 1
if isl == len(s)-2:
    ans += 1
if ans == 3:
    print("AC")
else :
    print("WA")

Measured memory_bytes: 3064
//#include "bits/stdc++.h"
#include <iostream>
#include <vector>
#include <map>
#include <utility>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <stack>
#include <queue>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <numeric>
#include <complex>
#include <bitset>
#include <functional>
#include <stack>
#include <regex>
#include <tuple>
#include <iomanip>


#define int long long
#define REP(i,l,r) REPEAT(i,l,r,true) // [l, r)
#define rep(i,n) REP(i,0,n)           // [0, n)
#define REPEAT(i,l,r,condition) for(int i=(condition)?l:r-1;(condition)?i<r:i>=l;(condition)?++i:--i) // false<-[l, r)->true
#define all(e) e.begin(),e.end()
#define rall(e) e.rbegin(),e.rend()
#define pb push_back
#define fs first
#define sc second
#ifdef LOCAL
#define show(...) cerr<<#__VA_ARGS__<<" = ";_DEBUG(__VA_ARGS__)
#define showlr(n,l,r) cerr<<#n<<" = ";for(int i=l;i<r;i++){cerr<<n[i]<<", ";}cerr<<endl // [l, r)
#else
#define show(...)
#define showlr(n,l,r)
#endif

#define YN(condition) puts((condition)?"YES":"NO")
#define Yn(condition) puts((condition)?"Yes":"No")
#define yn(condition) puts((condition)?"yes":"no")
#define YES puts("YES")
#define Yes puts("Yes")
#define yes puts("yes")
#define NO  puts("NO")
#define No  puts("No")
#define no  puts("no")

#define case(i) printf("Case #%lld: ",i)

using namespace std;

using vi=vector<int>;
using pint=pair<int,int>;

struct io{io(){cin.tie(0);ios::sync_with_stdio(false);cout.tie(0);cout<<fixed<<setprecision(20);}}io;

template<class T> istream& operator >>(istream &is, vector<T> &v){for(T &e:v)is>>e;return is;}
template<class T> ostream& operator <<(ostream &os, vector<T> v){os<<"{";for(T &e:v)os<<e<<(v.size()-(int)(&e-&v[0])>1?", ":"");os<<"}";return os;}

void _DEBUG(){}
template<typename H,typename... T> void _DEBUG(H a,T...b){cerr<<a<<(sizeof...(b)?",":"\n");_DEBUG(b...);}

inline void in(){}
template<typename H,typename... T>void in(H &a, T&... b){cin>>a;in(b...);}
inline void out(){}
template<typename H,typename... T> void out(H a, T... b){cout<<a<<(sizeof...(b)?" ":"\n");out(b...);}

template<class T> void resz(int n,T& v){v.resize(n);}
template<class H,class... T> void resz(int n,H& a,T&... b){a.resize(n);resz(n,b...);}

template<typename V,typename H> void resize(vector<V>& v,const H a){v.resize(a);}
template<typename V,typename H,typename... T> void resize(vector<V>& v,const H& a,const T... b){v.resize(a);for(auto &v:v) resize(v,b...);}

const int INF=1LL<<55;
const int MOD=1000000007;
const double EPS=1e-8;
/*------------end of definitions------------*/

int N;
vi H;
int ans=1;

signed main(){

    in(N);
    H.resize(N);
    in(H);

    REP(i,1,N){
        bool f=true;
        rep(j,i){
            if(H[i]<H[j]){
                f=false;
                break;
            }
        }
        if(f) ans++;
    }
    out(ans);

    return 0;
}


Measured memory_bytes: 504
#ifdef LOCAL
#define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define reps(i,a,b) for(int i=a;i<b;++i)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
using namespace std;
using ll = long long;
using P = pair<int, int>;
template<typename T> inline bool chmax(T &a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T> inline bool chmin(T &a,T b){if(b<a){a=b;return 1;}return 0;}
template<typename T> vector<T> make_vec(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_vec(size_t a,Ts... ts){return vector<decltype(make_vec<T>(ts...))>(a,make_vec<T>(ts...));}
template<typename T,typename U,typename... V>
typename enable_if<is_same<T,U>::value>::type fill_v(U &u,const V... v){u=U(v...);}
template<typename T,typename U,typename... V>
typename enable_if<!is_same<T,U>::value>::type fill_v(U &u,const V... v){for(auto &e:u)fill_v<T>(e,v...);}

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

    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    int mn = *min_element(all(a));
    int mx = *max_element(all(a));
    ll sum = accumulate(all(a), 0LL);
    printf("%d %d %lld\n", mn, mx, sum);
}



Measured memory_bytes: 3260
n=int(input())
k=int(input())
x=int(input())
y=int(input())
fees=0
if(k>n or n==k):
	for i in range(0,n):
		fees+=x
elif(k<n):
	diff=n-k
	for j in range(0,k):
		fees+=x
	for k in range(0,diff):
		fees+=y
		
print(fees)


Measured memory_bytes: 9104
#include<bits/stdc++.h>
using namespace std;
int main(){
  string a;
  cin >> a;
  int MAX = 0;
  for(int i = 0;i<a.size();i++){
    for(int j = 1;j<=a.size()-i;j++){
      string b = a.substr(i,j);
      int key = 0;
      int length = 0;
      for(int s = 0;s<b.size();s++){
        if(b.at(s) != 'A' && b.at(s) != 'C' && b.at(s) != 'G' && b.at(s) != 'T' ){
          key = 1;
          break;
        }
        else
          length++;
      }
      if(MAX < length && key != 1)
        MAX = length;
    }
  }
  cout << MAX << endl;
}
      
    
  


Measured memory_bytes: 256
#include <iostream>
#include <set>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <set>
#include <cstring>
#include <map>
#include <bitset>
#include <random>
#include <stack>
#include <list>
#include <unordered_set>
#include <unordered_map>
#include <ctime>

using namespace std;

#define ll long long
#define ld long double
#define pb push_back
#define sc second
#define fs first
#define mp make_pair
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()

template<class T> T sqr(T x) { return x*x; }
ld pi = 3.1415926535897932384626433832795;
ll mod = 1e9 + 7;
const int N = 1e5 + 10;

ll gcd(ll a, ll b) {
	return b ? gcd(b, a % b) : a;
}

int xx[N], yy[N], n, pr[N], sz[N];
vector<pair<int, int> > dx, dy;

int find(int a) {
	return (a == pr[a]) ? a : pr[a] = find(pr[a]);
}

void merge(int a, int b) {
	a = find(a), b = find(b);
	if (a != b) {
		if (sz[b] > sz[a])
			swap(a, b);
		pr[b] = a;
		sz[a] += b;
	}
}

int main() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		pr[i] = i;
		sz[i] = 1;
		cin >> xx[i] >> yy[i];
		dx.push_back(mp(xx[i], i));
		dy.push_back(mp(yy[i], i));
	}
	sort(all(dx));
	sort(all(dy));
	ll ans = 0;
	vector < pair<ll, pair<int, int> > > e;
	for (int i = 1; i < n; i++) {
			e.push_back(mp(dx[i].fs - dx[i - 1].fs, mp(dx[i].sc, dx[i - 1].sc))),
			e.push_back(mp(dy[i].fs - dy[i - 1].fs, mp(dy[i].sc, dy[i - 1].sc)));
	}
	sort(all(e));
	for (int i = 0; i < e.size(); i++) {
		int u = e[i].sc.fs, v = e[i].sc.sc;
		if (find(u) != find(v))
			merge(u, v), ans += e[i].fs;
	}
	cout << ans;
	return 0;
}

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

signed main(){
  int N,M;cin>>M>>N;
  std::vector<int> v(N+1,0);
  for(int i=0;i<M;i++){
    int K;cin>>K;
    for(int j=0;j<K;j++){
      int a;cin>>a;v[a]++;
    }
  }
  int ans=0;
  for(int i=1;i<=N;i++){
    if(v[i]==M)ans++;
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <cstdio> 
using namespace std; //This makes the code much more cleaner

int main()
{

	int x, y, z;
	scanf("%d %d %d",&x,&y,&z);
	
	if (x+y<=y+z and x+y<=x+z)
	{
		printf("%d",x+y);
	}
	else if (y+z<=x+y and y+z<=x+z)
	{	
		printf("%d",y+z);
	}
	else
	{
		printf("%d", x + z);
	}



	return 0;

}

Measured memory_bytes: 128
/*
─────────────────────
───────────████████──
──────────███▄███████
──────────███████████
──────────███████████
──────────██████─────
──────────█████████──
█───────███████──────
██────████████████───
███──██████████──█───
███████████████──────
███████████████──────
─█████████████───────
──███████████────────
────████████─────────
─────███──██─────────
─────██────█─────────
─────█─────█─────────
─────██────██────────
─────────────────────
*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>

#define int long long
#define read(a) int a; cin >> a;
#define readb(a, b) int a, b; cin >> a >> b;
#define readc(a, b, c) int a, b, c; cin >> a >> b >> c;
#define reads(s) string s; cin >> s;
#define readarr(a, n) int a[(n) + 1] = {}; fori (i, 1, (n)) {cin >> a[i];}
#define readmat(a, n, m) int a[n + 1][m + 1] = {}; fori (i, 1, n) {fori (j, 1, m) cin >> a[i][j];}

#define print(a) cout << a << endl;
#define printarr(a, n) fori (i, 1, n) cout << a[i] << " "; cout << endl;
#define printv(v) for (int i: v) cout << i << " "; cout << endl;
#define printmat(a, n, m) fori (i, 1, n) {fori (j, 1, m) cout << a[i][j] << " "; cout << endl;} cout << endl;
#define all(v) v.begin(), v.end()
#define sz(s) (int)(s.size())
#define pb push_back
#define fi first
#define se second
#define rz resize
#define fori(i, a, b) for (int i = (a); i <= (b); i++)
#define ford(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
#define setprec(x) cout << fixed << setprecision(x)
 
using namespace std;
using namespace __gnu_pbds; 
 
typedef tree<long long,null_type,less<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<pair <int, int>> vpi;
typedef vector < vector <int> > vvi;
 
const int INF = 4e18;
const int mod = 1e9+7; 

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

    //start from here

    reads(s); read(w);

    string ans = "";

    for (int i = 0; i < sz(s); i += w) ans += s[i];

    cout << ans; 

    return 0;
}


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

signed main() 
{
	int n , k , ans = 0;
	cin >> n >> k;
	int p[n];
	for(int i = 0 ; i < n ; i++)
		cin >> p[i];
	sort(p,p+n);
	for(int i = 0 ; i < k ; i++)
		ans = ans + p[i];
	cout << ans;
}

Measured memory_bytes: 3624
n = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

cnt = 0
for a, b in zip(A, B):
    if a > b:
        cnt += (a-b)
    else:
        cnt -= (b-a)//2

print("No" if cnt>0 else "Yes")

Measured memory_bytes: 68496
#include<bits/stdc++.h>
using namespace std;
typedef int64_t ll;
typedef long double ld;
const ll MOD=1000000007;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define change(a,b) do{ll c=a; a=b; b=c;}while(0)
long long gcd(long long a,long long b){
    ll gcdmax=max(a,b);
    ll gcdmin=min(a,b);
    while(true){
        if(gcdmax%gcdmin==0)break;
        else gcdmax%=gcdmin;
        change(gcdmin,gcdmax);
    }
    return gcdmin;
}
ll powerup(ll N,ll P,ll M){
    if(P==0)return 1;
    else if(P%2==0){
        ll t=powerup(N,P/2,M);
        return t*t%M;
    }
    else return N*powerup(N,P-1,M)%M;
}
int main()
{
  int N;
  string S;
  int ans=1;
  cin>>S;
  N=S.size();
  rep(i,(N-1)/2){
    if(S[i]!=S[N-i-1])ans=0;
    if(S[i]!=S[N/2-i-1])ans=0;
    if(S[i+N/2+1]!=S[N-i-1])ans=0;
  }
  if(ans==0)cout<<"No"<<endl;
  else cout<<"Yes"<<endl;
}

Measured memory_bytes: 256
from collections import deque

N, L = map(int, input().split())
*A, = map(int, input().split())

ans = []

que = deque()
for i, a in enumerate(A):
    while que and a <= que[-1][1]:
        que.pop()
    que.append((i, a))

    ans.append(que[0][1])

    if que and que[0][0] <= i+1-L:
        que.popleft()

print(*ans[L-1:])


Measured memory_bytes: 126692
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <queue>
#include <unordered_map>
#include <unordered_set>

#define int long long
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001ll
#define fcout cout << fixed << setprecision(10)

using namespace std;

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

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

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

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

typedef pair<int, int> P;

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

    int N;
    cin >> N;


    int a = 0;
    int b = 0;
    int ba = 0;
    int res = 0;
    REP(i, N) {
        string s;
        cin >> s;

        REP(j, s.size() - 1) {
            if (s.substr(j, 2) == "AB") res++;
        }
        if (s[0] == 'B' && s[s.size() - 1] == 'A') {
            ba++;
        }
        else if (s[0] == 'B') {
            b++;
        }
        else if (s[s.size() - 1] == 'A') {
            a++;
        }
    }

    if (ba > 1) {
        res += ba - 1;
        ba = 1;
    }
    if (ba > 0 && a > 0 && b > 0) {
        ba--;
        a--;
        b--;
        res += 2;
    }

    int n = min(a, b);
    res += n;

    if (a - n > 0 || b - n > 0) {
        res += ba;
    }


    cout << res << endl;

    return 0;
}


Measured memory_bytes: 256