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

int par[2 * 100000];
int ran[2 * 100000];

void init(int n){
	for(int i = 0; i < n; ++i){
		par[i] = i;
		ran[i] = 0;
	}
}

int find(int x){
	return (x == par[x] ? x : par[x] = find(par[x]));
}

void unit(int x, int y){
	x = find(x);
	y = find(y);
	if(x == y){
		return;
	}else if(ran[x] > ran[y]){
		par[y] = x;
	}else{
		par[x] = y;
		if(ran[x] == ran[y]){
			++ran[y];
		}
	}
}

bool same(int x, int y){
	return find(x) == find(y);
}

int main(){
	int n, k, l; cin >> n >> k >> l;
	init(n);
	for(int i = 0; i < k; ++i){
		int p, q; cin >> p >> q;
		--p; --q;
		unit(p, q);
	}
	int road[n];
	for(int i = 0; i < n; ++i){
		road[i] = find(i);
	}
	init(n);
	for(int i = 0; i < l; ++i){
		int p, q; cin >> p >> q;
		--p; --q;
		unit(p, q);
	}
	int train[n];
	for(int i = 0; i < n; ++i){
		train[i] = find(i);
	}
	map<pair<int, int>, int> m;
	for(int i = 0; i < n; ++i){
		++m[pair<int, int>(road[i], train[i])];
	}
	for(int i = 0; i < n; ++i){
		cout << m[pair<int, int>(road[i], train[i])] << " ";
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 15104
#include <bits/stdc++.h>
#define all(vec) vec.begin(), vec.end()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
template <class T>
using V = vector<T>;
constexpr ll INF = (1LL << 60) - 1LL;
constexpr ll MOD = 998244353LL;
constexpr int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
template <class T>
void chmin(T &a, T b) { a = min(a, b); }
template <class T>
void chmax(T &a, T b) { a = max(a, b); }
void debug() { cerr << "ok" << endl; }
template <class T>
void printv(const vector<T> &v) {
    for (int i = 0; i < v.size(); i++) cout << v[i] << (i + 1 == v.size() ? '\n' : ' ');
}
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    V<P> v(n);
    for (int i = 0; i < n; i++) {
        cin >> v[i].first;
        v[i].second = i;
    }
    sort(all(v));
    reverse(all(v));
    V<V<ll>> dp(n + 2, V<ll>(n + 2, -INF));
    dp[0][n + 1] = 0;
    for (int i = 0; i <= n; i++) {
        for (int j = n + 1; j > i + 1; j--) {
            ll a, id;
            tie(a, id) = v[i + (n + 1 - j)];
            //     cout << i << " " << j << " " << dp[i][j] << '\n';
            id++;
            if (id >= i + 1) {
                chmax(dp[i + 1][j], dp[i][j] + (id - (i + 1)) * a);
            }
            if (id <= j - 1) {
                chmax(dp[i][j - 1], dp[i][j] + (j - 1 - id) * a);
            }
        }
    }
    ll res = -INF;
    for (int i = 0; i <= n; i++) {
        chmax(res, dp[i][i + 1]);
    }
    cout << res << '\n';
}

Measured memory_bytes: 34628
#include<math.h>
#include <bits/stdc++.h>
#include <algorithm>
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define ll long long int
#define py printf("Yes\n")
#define pn printf("No\n")
#define in cin>>
using namespace std;
const int INF = 1001001001;

int main()
{
    int a,b,c,x,ans=0;
    in a>>b>>c>>x;
    for(int i=0;i<=a;i++)
    {
        for(int j=0;j<=b;j++)
        {
            for (int k=0;k<=c;k++)
            {
                if(500*i+100*j+50*k==x)ans++;
            }

        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
K = int(input())
if K % 2 == 0 or K % 5 == 0:
    print(-1)
    exit()

tmp1 = 0
for i in range(1, K + 1):
    tmp1 += 7 * pow(10, i, K)
    if tmp1 % K == 0:
        print(i)
        exit()

print(-1)

Measured memory_bytes: 63384
#include<iostream>
#include<vector>
#include<cstring>
#include<unordered_map>
#include<algorithm>
#include<cmath>
#include<queue>
#include<deque>
#include<map>
#include<bitset>
#include<random>

using namespace std;
using ll = long long;

#define rep(i, n) for(int i = 0;i < (n);i++)
#define repr(i, n) for(int i = (n);i >= 0;i--)
#define repf(i, m, n) for(int i = (m);i < (n);i++)

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;}
int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};
//////////////////////////////////////////////////

int h, n;
int a[1010], b[1010];

int main() {
    cin >> h >> n;
    rep(i, n) cin >> a[i] >> b[i];
    vector<int> dp(h+1, 1000000000);
    dp[0] = 0;
    rep(i, n) {
        rep(j, h+1) {
            if (j >= a[i])
            dp[j] = min(dp[j], dp[j - a[i]] + b[i]);
            else
            dp[j] = min(dp[j], dp[0] + b[i]);

        }
    }
    cout << dp[h] << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define sz 100005
#define all(x) x.begin(),x.end()
#define l_b lower_bound
#define u_b upper_bound
#define pb push_back
#define MOD 1000000007
void fastio(void);

int main(){
    fastio();
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif

    int t;  cin>>t;
    map<string, int> s;
    for(int la=1;la<=t;la++){
        string st;  cin>>st;
        s[st]++;
    }

    cout<<"AC x "<<s["AC"]<<endl;
    cout<<"WA x "<<s["WA"]<<endl;
    cout<<"TLE x "<<s["TLE"]<<endl;
    cout<<"RE x "<<s["RE"]<<endl;

    return 0;
}

void fastio(void){
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}

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

using namespace std;

#define FOR(i,s,e) for(int i=(s);(i)<(int)(e);(i)++)
#define REP(i,e) FOR(i,0,e)
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define all(o) (o).begin(), (o).end()
#define pb(x) push_back(x)
#define mp make_pair
#define mt make_tuple
#define t0(t) get<0>((t))
#define t1(t) get<1>((t))
#define t2(t) get<2>((t))

typedef long long ll;
const int INF = 1e9;
const int H = 1000;
const int W = 1000;
int h, w;
int b[H][W], d[H][W];
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};

int main() {
  queue<tuple<int,int>> q;
  fscanf(stdin, "%d%d ", &h, &w);
  REP(i,h) {
    char s[W+10];
    fscanf(stdin, "%s", s);
    REP(j,w)
      if (s[j] == '#') {
        q.push(mt(i,j));
        d[i][j] = 0;
      } else {
        b[i][j] = 1;
        d[i][j] = INF;
      }
  }
  while (q.size()) {
    int y, x; tie(y,x) = q.front(); q.pop();
    b[y][x] = 0;
    REP(i,4) {
      int ny = y + dy[i], nx = x + dx[i];
      if (ny < 0 || ny >= h) continue;
      if (nx < 0 || nx >= w) continue;
      if (!b[ny][nx]) continue;
      if (d[ny][nx] <= d[y][x] + 1) continue;
      d[ny][nx] = d[y][x] + 1;
      q.push(mt(ny,nx));
    }
  }
  int res = 0;
  REP(i,h) REP(j,w) res = max(res, d[i][j]);
  fprintf(stdout, "%d\n", res);
  return 0;
}


Measured memory_bytes: 16272
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
using namespace std;
struct Val{
	long long d;
	int u;
}p[100010];
bool cmp(Val a,Val b)
{
	return a.d>b.d;
}
int find(int l,int r,long long t)
{
	while(l+1<r)
	{
		int mid=(l+r)>>1;
		if(p[mid].d<=t)r=mid;
		else l=mid;
	}
	if(p[r].d!=t)return -1;
	return r;
}
int u[100010],v[100010];
int siz[100010];
int main()
{
	int n;scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%lld",&p[i].d);
		p[i].u=i;
	}
	sort(p+1,p+n+1,cmp);
	long long res=0;
	for(int i=1;i<n;i++)
	{
		siz[i]++;
		u[i]=p[i].u;
		int pos=find(i,n,p[i].d+siz[i]-(n-siz[i]));
		if(pos==-1){
			printf("-1\n");
			return 0;
		}
		v[i]=p[pos].u;
		siz[pos]+=siz[i];
		res+=siz[i];
	}
	if(res!=p[n].d){
		printf("-1\n");
		return 0;
	}
	for(int i=1;i<n;i++)
		printf("%d %d\n",u[i],v[i]);
	return 0;
}

Measured memory_bytes: 4096
#include<bits/stdc++.h>
using namespace std;
int n,m;
int h[100010];
bool ok[100010];
int main(){
    cin>>n>>m;
    for(int i=1;i<=n;i++)ok[i]=1;
    for(int i=1;i<=n;i++)scanf("%d",h+i);
    for(int i=0;i<m;i++){
        int u,v;
        scanf("%d%d",&u,&v);
        if(h[u]>=h[v])ok[v]=0;
        if(h[v]>=h[u])ok[u]=0;
    }
    int ans=0;
    for(int i=1;i<=n;i++)ans+=ok[i];
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 4148
#include<cmath>
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
stack<int> st;
queue<int> qu;
queue<pair<int,int> > qu2;
priority_queue<int> pq;
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define rep2(i,n) for(int i=1; i<=(int)(n); i++)
#define mins(x,y) x=min(x,y)
#define maxs(x,y) x=max(x,y)
#define ALL(a) a.begin(), a.end()
typedef set<int> set_t;
typedef set<string> set_g;
typedef complex<double> xy_t;
static const int NIL = -1;
static const int INF = 1000000007;
#define mp make_pair
#define sz(x) int(x.sise())
#define mod 1000000007
#define reps(i,s,n) for(int i = s; i < n; i++)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
deque<int> deq;
#define fi first
#define se second
//const ll MOD = 998244353;
const ll MOD = (1e+9) + 7;
typedef pair<int, int> P;
typedef vector<ll> vec;
typedef vector<vec> mat;
int main(){
    int n,x,t;
    cin >> n>> x>> t;
    int ans=((n-1)/x+1)*t;
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3632
// Problem : C - Ubiquity
// Contest : AtCoder - AtCoder Beginner Contest 178
// URL : https://atcoder.jp/contests/abc178/tasks/abc178_c
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
#define int long long 	
int mod=1e9+7;
int po(int x,int y,int m)  { if (y==0) return 1; int t=po(x,y/2,m)%m; t=(t*t)%m; if (y&1) return (t*x)%m;	return t%m; }

void fun(){
	
}

signed 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(0); 

  int n;
  cin>>n;
  if (n==1)
  	cout<<0<<endl;
else if (n==2)
	cout<<2<<endl;
else{
	int ans=po(10,n,mod);
	ans=(mod+ans-(2*po(9,n,mod))%mod)%mod;
	ans=ans%mod;
	ans=(ans+po(8,n,mod)+mod)%mod;
	cout<<ans%mod<<endl;
}
   	
   
   	return 0;
}

Measured memory_bytes: 3628
#include <iostream>
#include <bits/stdc++.h>
#include <cmath>

using namespace std;

float sum(vector<int> x) {
    float result = 0;
    for (int i=0; i<x.size(); i++) {
        result += x[i];
    }
    return result;
}

int main()
{
    int ave;
    int N, i;
    int result = 0;
    cin >> N;
    vector<int> x(N);
    for(i=0; i<N; i++) {
        cin >> x[i];
    }
    
    ave = round(sum(x) / N);
    for(i=0; i<N; i++) {
        result += pow(x[i] - ave, 2);
    }
    
    cout << result << endl;
}

Measured memory_bytes: 512
from collections import defaultdict, deque
import sys


def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]


a, b = LI()
print(max([a + b, a - b, a * b]))


Measured memory_bytes: 3316
N, K = map(int,input().split())

halfs = []
tar = 1
for i in range(1,20):
    tar /= 2.0
    halfs.append(tar)

res = 0
for i in range(1,N + 1):
    if i < K:
        tmp = i
        index = 0
        while tmp < K:
            tmp *= 2
            index += 1
        res += halfs[index - 1] * float(1.0 / N)
    else:
        res += float(N - K + 1) / N
        break

print(res)


Measured memory_bytes: 40048
N, M, K = gets.chomp.split.map(&:to_i)
A = gets.chomp.split.map(&:to_i)
B = gets.chomp.split.map(&:to_i)

a = [0]
b = [0]

A.size.times{ |i| a << A[i] + a.last }
B.size.times{ |i| b << B[i] + b.last }

i = 0
j = B.size
max = 0
while i < a.size && j >= 0
  if a[i] + b[j] <= K
    max = i+j if max < i+j
    i += 1
  else
    j -= 1
  end
end

puts max

Measured memory_bytes: 48980
use proconio::input;
use proconio::marker::{Bytes, Chars};
use std::cmp::{max, min};

fn main() {
    input! {
        (n, m): (usize, usize),
    }
    let mut uf = UnionFind::new(n);
    for _ in 0..m {
        input! {
            (a, b): (usize, usize),
        }
        uf.unite(a - 1, b - 1);
    }
    let ans = uf.roots().len() - 1;
    println!("{}", ans);
}

struct UnionFind {
    root: Vec<usize>,
    rank: Vec<usize>,
    sizes: Vec<usize>,
    n: usize,
}

impl UnionFind {
    fn new(n: usize) -> UnionFind {
        let mut vec = vec![0;n];
        for i in 0..n {
            vec[i] = i;
        }
        UnionFind {
            root: vec,
            rank: vec![0;n],
            sizes: vec![1;n],
            n,
        }
    }

    fn find(&mut self, x: usize) -> usize {
        if self.root[x] == x { return x }
        self.root[x] = self.find(self.root[x]);
        self.root[x]
    }

    fn unite(&mut self, x: usize, y: usize) -> () {
        let x = self.find(x);
        let y = self.find(y);
        if x == y { return }
        if self.rank[x] < self.rank[y] {
            self.root[x] = y;
            self.sizes[y] += self.sizes[x];
        } else {
            self.root[y] = x;
            self.sizes[x] += self.sizes[y];
            if self.rank[x] == self.rank[y] {
                self.rank[x] += 1;
            }
        }
    }

    fn same(&mut self, x: usize, y: usize) -> bool {
        self.find(x) == self.find(y)
    }

    fn size(&mut self, x: usize) -> usize{
        let f = self.find(x);
        self.sizes[f]
    }

    fn roots(&mut self) -> Vec<usize> {
        let mut vec = vec![];
        for i in 0..self.n {
            if self.root[i] == i {
                vec.push(self.root[i]);
            }
        }
        vec
    }
}

Measured memory_bytes: 5712
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
 
const int mod=1e9+7;
 
ll L,R;
 
ll f[64][2][2][2][2];
int l[100],r[100];
 
ll dfs(int x,int fl,int fr,int s,int ht)
{
	if(x<0)return 1;
	// x：第x位 （二进制转十进制下权值是1的为第0位）
	// fl： y之前是否有填过小于 R的某一位的数字   例如：R:11000 y:10??? fl即为1 表示后面数字可以往大了填 
	// fr： x之前是否有填过大于 L的某一位的数字   类似fl
	// s： 之前x是否有某一位 < y的某一位 如果有，后面的位数就没有相对大小限制了 (确保 x<=y)
	//ht：确保 x，y 最高位一样都为1  （满足推导的要求） 
	ll &ans=f[x][fl][fr][s][ht];
	if(ans)return ans;
	
	for(int i=0;i<2;i++)//y
	{
		for(int j=0;j<2;j++)//x
		{
			int tl=fl,tr=fr,ts=s,tt=ht;
			if(!tt&&i)if(i!=j)continue;
			if((j&i)!=j)continue;
			if(!tl&&j<l[x])continue;
			if(!tr&&i>r[x])continue;
			if(!ts&&j>i)continue;
			if(j>l[x])tl=1;if(i<r[x])tr=1;if(j<i)ts=1;if(j)tt=1;
			ans+=dfs(x-1,tl,tr,ts,tt);
		}
	}
	ans%=mod;
	return ans;
}
 
int main()
{
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	
	cin>>L>>R;
	for(int i=63;i>=0;i--)
	{
		l[i]=(bool)((1ll<<i)&L);r[i]=(bool((1ll<<i)&R));
	}
	
	cout<<dfs(63,0,0,0,0);
	
	return 0;
}

Measured memory_bytes: 256
//GRL_2_Aにてたしかめ
#include<bits/stdc++.h>
using namespace std;
struct Unionfind{
  vector<int> rank,p;
  Unionfind(){}
  Unionfind(int size){
		rank.resize(size,0);
		p.resize(size,0);
		for(int i=0;i<size;i++){
	    makeSet(i);
		}
	}
  void makeSet(int x){
		p[x]=x;
		rank[x]=0;
	}
  bool same(int x,int y){
		return (findSet(x)==findSet(y));
  }

  void unite(int x,int y){
		link(findSet(x),findSet(y));
  }

  void link(int x,int y){
		if(rank[x]>rank[y]){
	    p[y]=x;
		}
		else{
	    p[x]=y;
	    if(rank[x]==rank[y]){
				rank[y]++;
	    }
		}
  }

  int findSet(int x){
		if(x!=p[x]){
	    p[x]=findSet(p[x]);
		}
		return p[x];
  }
};

struct Edge{
  int source,target,cost;
  Edge(int source=0,int target=0,int cost=0):
  source(source),target(target),cost(cost){}
  bool operator < (const Edge &e) const{
    return cost < e.cost;
  }
};

int main(){
  int n,m,cost,source,target;
  cin>>n>>m;
  //辺の入力
  vector<Edge> edges;
  for(int i=0;i<m;i++){
    cin>>source>>target>>cost;
    edges.push_back(Edge(source,target,cost));
  }

  //ここから本番
  int ans=0;
  //辺の整列
  sort(edges.begin(),edges.end());
  
  Unionfind uf(n+1);

  for(int i=0;i<(int)edges.size();i++){
    Edge e=edges[i];
    if(!uf.same(e.source,e.target)){
      //最小全域木を構築するには, MST.push_back(e);
      ans+=e.cost;
      uf.unite(e.source,e.target);
    }
  }
  cout<<ans<<'\n';
}


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

#define pi 3.141592654
#define fix(n) cout << fixed << setprecision(n)

#define rep(i,a,b) for(int i=a;i<b;i++)
#define ren(i,a,b) for(int i=a;i>=b;i--)

#define ll  long long
#define ull unsigned long long

#define mp make_pair
#define pb push_back
#define fi first
#define se second

#define vi      vector<int>
#define pii     pair<int,int>
#define piii    pair<pair<int,int>,int>
#define all(v)  v.begin(), v.end()

int mod = 1000000007;
const int N = 1005;

// gcd
ll gcd(ll a , ll b)
{
    if ( b == 0)
    return a;
    return gcd( b, a % b);
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int n, a, b;
	cin >> n >> a >> b;
	int x = abs(a-b);
	if ( x % 2 == 0)
		cout << "Alice";
	else
		cout << "Borys";
	return 0;
}


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

using namespace std;

int main()
{
	int cnt[10001] = { 0, };

	int n;

	scanf("%d", &n);

	for (int i = 1; i <= 100; i++)
	{
		for (int j = 1; j <= 100 && (i*i+j*j+i*j < n); j++)
		{
			for (int k = 1; k <= 100; k++)
			{
				const int cand = i*i + j*j + k*k + i*j + j*k + k*i;

				if (cand <= n)
				{
					cnt[cand]++;
				}
			}
		}
	}

	for (int i = 1; i <= n; i++)
	{
		printf("%d\n", cnt[i]);
	}

	return 0;
}

Measured memory_bytes: 1772
; ABC159 D
(let* ((n (read))
       (a (make-array `(,(1+ n))))
       (c (make-array `(,(1+ n)) :initial-element 0))
       (sum 0))
  (loop :for i :from 1 :to n
        :do (let ((x (read)))
              (setf (aref a i) x)
              (incf (aref c x))))
  (loop :for i :from 1 :to n
        :do (let ((x (aref c i)))
              (incf sum (/ (* x (1- x)) 2))))
  (loop :for k :from 1 :to n
        :do (let ((x (aref a k)))
              (format t "~A~%" (- sum (1- (aref c x)))))))


Measured memory_bytes: 80312
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0;i < n;i++)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define ll long long
#define MOD 1000000007
#define INF 2000000001
using namespace std;

int n, a, b, m;
vector<int> v[100001];
int main() {
	cin >> n >> m;
	cout << n * n - m << endl;
	return 0;
}

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

using namespace std;
const int maxn=10000+10;
const int maxq=500+10;
int a[maxn],b[maxq];
int n,q;


void solve()
{

    int sum=0;
    for(int i=0; i<q; i++)
    {
        for(int j=0;j<n;j++)
        {

            if(b[i]==a[j])
            {
                sum++;
                break;
            }



        }
        //if(binary_search(b,b+q,a[i])) sum++;
    }
    printf("%d\n",sum);
}
int main()
{
//    freopen("in.txt","r",stdin);
    scanf("%d",&n);
    for(int i=0; i<n; i++) scanf("%d",&a[i]);

    scanf("%d",&q);
    for(int i=0; i<q; i++) scanf("%d",&b[i]);
    //sort(b,b+q);
    solve();
    return 0;
}

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

class Solve {
private:
	using vi = std::vector<int64_t>;
	using vvi = std::vector<vi>;
	using vvvi = std::vector<vvi>;

	using i3 = std::array<int64_t, 3>;
	using vi3 = std::vector<i3>;
	using vvi3 = std::vector<vi3>;

public:
	bool is_last_query{};
	Solve()
	{
		int n, m, company, start, goal;
		scanf("%d%d%d%d%d", &n, &m, &company, &start, &goal);
		if (n == 0)
		{
			is_last_query = true;
			return;
		}
		start--;
		goal--;

		vvvi companyGraph(company, vvi(n, vi(n, 1ll << 60)));
		for (int i{}; i < m; i++)
		{
			int x, y, d, c;
			scanf("%d%d%d%d", &x, &y, &d, &c);
			x--;
			y--;
			c--;
			companyGraph[c][x][y] = std::min(companyGraph[c][x][y], (int64_t)d);
			companyGraph[c][y][x] = std::min(companyGraph[c][y][x], (int64_t)d);
		}
		for (auto& e: companyGraph)
			for (int i{}; i < n; i++)
				e[i][i] = 0;

		vvi graph(n, vi(n, 1ll << 60));
		vi p(company);
		for (auto& e: p) scanf("%d", &e);
		for (int c_i{}; c_i < company; c_i++)
		{
			// {point, cost, cost_delta}
			vi3 costs(p[c_i]);
			for (int i{1}; i < p[c_i]; i++)
				scanf("%d", &costs[i][0]);
			for (int i{}; i < p[c_i]; i++)
				scanf("%d", &costs[i][2]);
			for (int i{1}; i < p[c_i]; i++)
				costs[i][1] = costs[i - 1][1] + costs[i - 1][2] * (costs[i][0] - costs[i - 1][0]);
			auto& eachGraph{companyGraph[c_i]};
			for (int mid{}; mid < n; mid++)
				for (int from{}; from < n; from++)
					for (int to{}; to < n; to++)
						eachGraph[from][to] = std::min(eachGraph[from][to], eachGraph[from][mid] + eachGraph[mid][to]);
			for (int i{}; i < n; i++)
				for (int j{}; j < n; j++)
				{
					int64_t dist{eachGraph[i][j]};
					if (dist == (1ll << 60)) continue;
					int64_t left{}, right{p[c_i]};
					while (right - left > 1)
					{
						int64_t mid{(right + left) >> 1};
						if (costs[mid][0] <= dist) left = mid;
						else right = mid;
					}
					graph[i][j] = std::min(graph[i][j], costs[left][1] + costs[left][2] * (dist - costs[left][0]));
				}
		}

		vi dist(n, 1ll << 60);
		dist[start] = 0;
		using pii = std::pair<int64_t, int>;
		std::priority_queue<pii, std::vector<pii>, std::greater<pii>> dij;
		dij.push({0, start});
		while (!dij.empty())
		{
			auto now{dij.top()};
			dij.pop();
			if (now.first > dist[now.second]) continue;
			for (int i{}; i < n; i++)
				if (now.first + graph[now.second][i] < dist[i])
				{
					dist[i] = now.first + graph[now.second][i];
					dij.push({dist[i], i});
				}
		}
		if (dist[goal] == (1ll << 60)) puts("-1");
		else printf("%lld\n", dist[goal]);
	}
};

int main()
{
	while (!Solve().is_last_query);

	return 0;
}


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

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

int main() {
  int n; cin >>n;
  vector<ll> h(n);
  rep (i,n) cin >>h.at(i);
  const ll INF = 1LL << 60;
  vector<ll> dp(100010);
  rep (i,100010) dp.at(i) = INF;
  dp.at(0) = 0;
  for (int i=0; i<n; i++){
    chmin(dp[i+1], dp[i] + abs(h[i] - h[i+1]));
    chmin(dp[i+2], dp[i] + abs(h[i] - h[i+2]));
  }

  cout <<dp[n-1] <<endl;

}


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

#define int long long
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; }

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

	int now = 1;
	int ans = 0;
	int a[200010];
	for(int i = 0;i < n;i++){
		cin >> a[i];
		if(a[i] == now){
			now++;
			ans++;
		}
	}
	cout << (ans == 0 ? -1 : n-ans) << endl;
	return 0;
}


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

using ll = long long;

const int INF = 1001001001;
const ll INF_LL = 1001001001001001001LL;

int main(void){
  double t,x; cin >> t >> x;
  double ans = t/x;

  printf("%.5f\n",ans);  
  
  return 0;
}


Measured memory_bytes: 3712
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)(n); ++i)
using P = pair<int,int>;
using ll = long long;
static const int INF = 1000000000;
static const ll MOD = 1000000007;

int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  int a, b;
  cin >>a >> b;
  cout << a * b << endl;
  return 0;
}

Measured memory_bytes: 3608
#include<stdio.h>

int main()
{
	char a[101];
	int r=0;
	int i=0;
	int m;
	int n;
	int s;
	int h;
	//const char C;
	//const char F;
	s=0;
	h=0;
	gets(a);
	while(a[i]!='\0'){
	    //printf("s=%d,h=%d,i=%d,1\n",s,h,i);
		if(a[i]==67){
			m=i;
		}else{
			s++;
		}
		i++;
	}
	
	while(a[r]!=0){
		//printf("s=%d,h=%d,i=%d,2\n",s,h,i);
		if(a[r]==70){
			n=r;
		}else{
			h++;
		}
		r++;
	}
    if(s==i||h==r){
		printf("No\n");
	}else if(m>n){
		printf("No\n");
	}else{
		printf("Yes\n");
    }
	return 0;
	
}

Measured memory_bytes: 128
#include <iostream>

int main() {
    long long int N;
    long long int SUM = 0;

    scanf("%lld",&N);
    for(long long int i = 1; i <= N; ++i){
        if(i % 3 == 0 || i % 5 == 0){
        }
        else{
            SUM += i;
        }
    }
    printf("%lld",SUM);
    return 0;
}


Measured memory_bytes: 3828
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> p;

int main(void){
  int a,b;
  cin >> a >> b;
  if(a==1)a=14;
  if(b==1)b=14;
  if(a>b)cout << "Alice" << endl;
  else if(a<b)cout << "Bob" << endl;
  else cout << "Draw" << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1e9;
const int MOD = 1000000007;
const double PI = acos(-1);
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};

void solve() {
  int n;
  cin >> n;
  vector<int> h(n);
  rep(i,n) cin >> h[i];
  int mx = 0;
  rep(i,n) {
    if (mx > h[i]) {
      cout << "No" << endl;
      return;
    }
    if (mx < h[i]) {
      mx = max(mx, h[i]-1);
    }
  }
  cout << "Yes" << endl;
}

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

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

#define CEIL(a,b) ((a) / (b) + ((a) % (b) == 0 ? 0 : 1))

using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pcc = pair<char, char>;

constexpr int MOD = 1'000'000'007;
constexpr int INF = 1'000'000'001;
constexpr ll LLINF = 4'000'000'000'000'000'001;
// constexpr int INF = 2147483647; // 2 * 1e9
// constexpr ll LLINF = 9223372036854775807; // 9 * 1e18

const int dx[] = {1, 0, -1, 0, 1, -1, -1, 1, 0};
const int dy[] = {0, 1, 0, -1, 1, 1, -1, -1, 0};

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(10);
    int n;
    cin >> n;
    vector<string> s(n);
    int a = 0, b = 0, ab = 0, ans = 0;
    for(int i = 0; i < n; ++i){
        cin >> s[i];
        if(s[i].back() == 'A' && s[i][0] == 'B') ++ab;
        else if(s[i].back() == 'A') ++a;
        else if(s[i][0] == 'B') ++b;
        for(int j = 0; j < s[i].size() - 1; ++j){
            if(s[i][j] == 'A' && s[i][j+1] == 'B') ++ans;
        }
    }
    if(a > 0 && b > 0){
        ans += ab + 1 + min(a, b) - 1;
    }
    else if(a > 0 || b > 0){
        ans += ab;
    }
    else{
        ans += max(0, ab - 1);
    }
    cout << ans << "\n";
    return 0;
}

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

#define ll long long
#define vecll vector<long long>
#define vec2ll vector<vector<long long>>
#define vecbool vector<bool>
#define vecpairll vector<pair<long long,long long>>
#define forll(s,a,b) for(long long s = a;s < b;s++)
#define forllde(s,a) for(long long s = a;s > 0;s--)


int main()
{
  ll n, a, b, c, d;
  string s;
  cin >> n >> a >> b >> c >> d >> s;
  forll(i, b, d-1){
	if(s[i] == '#' && s[i + 1] == '#'){
	  cout << "No" << endl;
	  return 0;
	}
  }
  forll(i, a, c-1){
	if(s[i] == '#' && s[i + 1] == '#'){
	  cout << "No" << endl;
	  return 0;
	}
  }
  if (c > d){
	forll(i, b-2, d-1){
	  if(s[i] == '.' && s[i+1] == '.' && s[i+2] == '.'){
		cout << "Yes" << endl;
		return 0;
	  }
	}
	cout << "No" << endl;
	return 0;
  }
  cout << "Yes" << endl;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <stdlib.h>
#include <cmath>
using namespace std;
typedef long long ll;
ll mod=1000000007;
ll BIG=1e9;

ll d[100001];


int main(){
    int K;cin>>K;
    queue<int> Q;
    d[1]=1;
    Q.push(1);
    
    while(!Q.empty()){
        int x=Q.front();
        //cout<<d[x]<<':'<<x<<endl;
        int p=(10*x)%K, q=(x+1)%K;
        while(d[p]==0 || d[p]>d[x]){
            d[p]=d[x];
            Q.push(p);
            p=(10*p)%K;
        }
        
        if(d[q]==0 || d[q]>d[x]+1){
            d[q]=d[x]+1;
            Q.push(q);
        }
        Q.pop();

    }
    //for(int i=0;i<K;i++) if(d[i]==0) cout<<"0:"<<i<<endl;
    cout<<d[0]<<endl;


}

Measured memory_bytes: 1408
from itertools import combinations 
n, m, x = map(int, input().split())
c = [list(map(int, input().split())) for _ in range(n)]
ans = float("INF")
for a in range(1, n + 1):
    for i in combinations(c, a):
        point = [0] * m
        money = 0
        for j in range(a):
            for k in range(m):
                point[k] += i[j][k + 1]
            money += i[j][0]
        if min(point) >= x:
            ans = min(ans, money)

if ans == float("INF"):
    print(-1)
else:
    print(ans)

Measured memory_bytes: 73900
/**
 *    author:  ritik_0007
 *    created:  just assume some time
 *    college :IIIT Ranchi
 *	  3rd year(5ht sem)    
**/

		#include<bits/stdc++.h>
		using namespace std;
		#define sz(x) (int)(x).size()
		#define int long long int
		#define loop(i,a,b) for(int i=a;i<b;i++)
		#define scan(arr,n) for (int i = 0; i < n; ++i) cin >> arr[i]
		#define vi vector<int>
		#define si set<int>
		#define pii pair <int, int>
		#define sii set<pii>
		#define vii vector<pii>
		#define mii map <int, int>
		#define pb push_back
		#define ff first
		#define ss second
		#define all(aa) aa.begin(), aa.end()
		#define rall(a) a.rbegin() , a.end()
		#define faster ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
		//Constants
		const int mod = 1000000007; /* 1e9 + 7*/
		const int MAXN = 1000005; /*1e6 +5 */
		
		int spf[1000009]; // stores the smallest prime factor of a number
		const int siz=100001;
		vi adj[siz];
		int fac[1000001]={0};
		int depth[siz] ;
		int diameter=0;
		
		void print(vi v)
		{
			for(auto x:v)
			cout<<x<<" ";
			cout<<endl;
		}
		 
		// to find diameter of a tree and distance between two nodes in a tree. 
		//dist between a and b is depth[b] , Initialise depth[a]=0 for each test case.
		int dfs(int u,int par) 
		{
			int len=0;
			for(auto x:adj[u])
			{
				if(x!=par)
				{
					depth[x]=depth[u]+1;
					int cur=1+ dfs(x,u);
					diameter=max(diameter,cur+len);
					len=max(len,cur);
				}
			}
			return len;
		}
	
		void fact()
		{
			fac[0]=1;
			for(int i=1;i<=1000000;i++)
			fac[i]=(fac[i-1]%mod * i%mod)%mod;
		}
		
		
		void solve()
		{
			string s;
			cin>>s;
			if(s[sz(s)-1]!='s')
			{
				s+='s';
			}
			else
				s+="es";
			cout<<s;
		}


		 
		int32_t main()
		{
			#ifndef ONLINE_JUDGE
				freopen("input.txt", "r", stdin);
				freopen("output.txt", "w", stdout);
			#endif
			fact();
			faster;
			int t=1;
			//cin>>t; 
			while(t--)
				solve();		 
			return 0;
		}


Measured memory_bytes: 13804
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int m;
    cin >> m;
    if (m < 4) {cout << "No" << endl; return 0;}
    if (m % 4 == 0) {cout << "Yes" << endl; return 0;}
    if (m % 7 == 0) {cout << "Yes" << endl; return 0;}
    int k = m / 4;
    for(int i = 1; i <= k; i++)
    {
    	if ((m - i * 4) % 7 == 0) {cout << "Yes" << endl; return 0;}
	}
    k = m / 7;
    for(int i = 1; i <= k; i++)
    {
    	if ((m - i * 7) % 4 == 0) {cout << "Yes" << endl; return 0;}
	}
	cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 384
N, K = map(int, input().split())
R = N - K
mod = pow(10, 9) + 7

fact = [0] * 2001
inv = [0] * 2001
inv_cal = [0] * 2001

fact[:2] = [1, 1]
inv[1] = 1
inv_cal[:2] = [1, 1]

for i in range(2, 2001):
    fact[i] = fact[i-1] * i % mod
    inv[i] = mod - (mod // i) * inv[mod % i] % mod
    inv_cal[i] = inv_cal[i-1] * inv[i] % mod

def comb(n, k):
    if n < k:
        return 0
    if n < 0 or k < 0:
        return 0
    return fact[n] * (inv_cal[k] * inv_cal[n-k] % mod) % mod

for k in range(1, K+1):
    if R+1 >= k:
        print(comb(R+1, k) * comb(K-1, k-1) % mod)
    else:
        print(0)

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

int main(){
  long h,n,sum;
  cin >> h >> n;
  long a[n];
  
  sum = 0;
  for(int i = 0;i<n;i++){
    cin >> a[i];
    sum = sum + a[i];
  }
  if(sum>=h){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 1024
n, y = map(int, input().split())

def fun(n, y):
    for i in range(y//10000+1):
        for j in range((y - 10000*i)//5000+1):
            k = (y - 10000*i - 5000*j)//1000
            if i + j + k == n:
                return print(i, j, k)

    return print(-1, -1, -1)

fun(n, y)

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

int main(){
    map<string, int> m;
    int q, op, x;
    string s;
    
    cin >> q;
    while(q-- > 0){
        cin >> op;
        if(op == 0){
            cin >> s >> x;
            m[s] = x;
        }
        if(op == 1){
            cin >> s;
            if(m.count(s))  cout << m[s] << endl;
            else            cout << 0 << endl;
        }
        if(op == 2){
            cin >> s;
            m.erase(s);
        }
    }

    return 0;
}


Measured memory_bytes: 27644
#include<bits/stdc++.h>
#define fto(i, a, b) for(int i = a; i <= b; ++i)
#define fdto(i, a, b) for(int i = a; i >= b; --i)
#define scii(a, b) scanf("%d %d", &a, &b)
#define sci(a) scanf("%d", &a)
#define pri(a) printf("%d ", a)
#define pril(a) printf("%d\n", a)
#define pb(a) push_back(a)
#define oo 1000000007
#define maxN 100005
using namespace std;
int n, num[maxN], par[maxN];
struct town {
    int x, y, id;
};
town t[maxN], t2[maxN];

struct canh {
    int u, v, w;
};
canh ca[8*maxN];

bool cmp1(town l, town r) {
    return l.x < r.x;
}

bool cmp2(town l, town r) {
    return l.y < r.y;
}

bool cmp3(canh l, canh r){
    return l.w < r.w;
}




int findC(int u) {
    if(u != par[u]) return findC(par[u]);
    else return u;
}



bool uSet(int u, int v) {
    int x = findC(u);
    int y = findC(v);
    if(x != y) {
        if(num[x] > num[y]) {
            par[y] = x;
            ++num[x];
        }
        else {
            if(num[x] < num[y]) {
                par[x] = y;
                ++num[y];
            }
            else {
                par[y] = x;
                ++num[x];
            }
        }
        return 1;
    }
    return 0;
}


int main() {
    //freopen("built.inp", "r", stdin);
    //freopen("built.out", "w", stdout);
    sci(n);
    fto(i, 1, n) {
        scii(t[i].x, t[i].y);
        t[i].id = i;
        t2[i] = t[i];
    }

    sort(t + 1, t + 1 + n, cmp1);
    sort(t2 + 1, t2 + 1 + n, cmp2);
    int cnt = 0;
    fto(i, 1, n) {
        if(i > 1) {
            canh x;
            x.u = t[i].id;
            x.v = t[i-1].id;
            x.w = min(abs(t[i].x - t[i-1].x), abs(t[i].y - t[i-1].y));
            ca[++cnt] = x;
            x.u = t2[i].id;
            x.v = t2[i-1].id;
            x.w = min(abs(t2[i].x - t2[i-1].x), abs(t2[i].y - t2[i-1].y));
            ca[++cnt] = x;
        }
        if(i < n) {
            canh x;
            x.u = t[i].id;
            x.v = t[i+1].id;
            x.w = min(abs(t[i].x - t[i+1].x), abs(t[i].y - t[i+1].y));
            ca[++cnt] = x;
            x.u = t2[i].id;
            x.v = t2[i+1].id;
            x.w = min(abs(t2[i].x - t2[i+1].x), abs(t2[i].y - t2[i+1].y));
            ca[++cnt] = x;
        }
    }
    fto(i, 1, n) par[i] = i;
    sort(ca + 1, ca + cnt + 1, cmp3);
    long long res = 0;
    fto(i, 1, cnt) {
        if(uSet(ca[i].u, ca[i].v)) {
            //cout << ca[i].w << endl;
            res += ca[i].w;
        }
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 10752
n,m= list(map(int, input().split()))
ans_box=[0]*n
wa=[0]*n
ac=0
wa_cnt=0
for j in range(m):
    k,l=input().split()
    h=int(k)-1
    if ans_box[h]==0:
        if l=="AC":
            ac+=1
            ans_box[h]+=1
            wa_cnt+=wa[h]
        else:
            wa[h]+=1
print(ac,wa_cnt)           
            

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

char rest(char a, char b)
{
  string t = "rsp";
  for (ll i = 0; i < 3; i++)
  {
    if (t[i]!=a && t[i]!=b) return t[i];
  }
  cout << "ERROR" << endl;
  return 'e';
}

int main()
{
  ll n,k;
  ll r,s,p;
  string t;
  cin >> n >> k;
  cin >> r >> s >> p;
  cin >> t;
  ll tmp = 0;
  
  map<char,ll> point;
  point['r'] = p;
  point['s'] = r;
  point['p'] = s;

  map<char,char> win;
  win['r'] = 'p';
  win['s'] = 'r';
  win['p'] = 's';

  string seq;

  bool flag;

  for (ll i = 0; i < n; i++)
  {
    flag = 0;
    if (i<k) flag = 1;
    else if (seq[i-k]!=win[t[i]]) flag = 1;

    if(flag)
    {
      seq += win[t[i]];
      tmp += point[t[i]];
    } else if (i+k < n){
      seq += rest(win[t[i-k]],win[t[i+k]]);
    }
  }  
  cout << tmp << endl;

  return 0;
}

Measured memory_bytes: 640
#include <stdio.h>

int main(void)
{
  int n;
  long int wa = 0;
  int i;
  
  scanf("%d",&n);
  
  for (i=1; i<=n; i++) {
    if (i % 3 != 0)
      if (i % 5 != 0)
        wa += i;
  }
  
  printf("%lld",wa);
  
  return 0;
}

Measured memory_bytes: 1732
import unittest


class TestE(unittest.TestCase):
    def test_1(self):
        self.assertEqual(think(12), 1)

    def test_2(self):
        self.assertEqual(think(5), 0)

    def test_3(self):
        self.assertEqual(think(1000000000000000000), 124999999999999995)


def solve():
    n = read()
    result = think(n)
    write(result)


def read():
    return read_int(1)[0]


def read_int(n):
    return read_type(int, n)


def read_float(n):
    return read_type(float, n)


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


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


def think(n):
    if n == 0:
        return 0
    if n % 2 == 1:
        return 0
    return count_fives(n // 2)


def write(result):
    print(result)


def count_fives(n):
    count = 0
    mode = 5
    while mode <= n:
        count += n // mode
        mode *= 5
    return count


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


Measured memory_bytes: 5756
class InputLine
  def self.to_s
    gets.chomp
  end

  def self.to_i
    InputLine.to_s.to_i
  end
  
  def self.to_f
    InputLine.to_s.to_f
  end

  def self.to_sa
    InputLine.to_s.split(' ')
  end

  def self.to_ia
    InputLine.to_sa.map(&:to_i)
  end
  
  def self.to_fa
    InputLine.to_sa.map(&:to_f)
  end
end

def main(argv)
  (a, b, c, k) = InputLine.to_ia

  if k <= a then
    puts k.to_s
  elsif k <= (a + b) then
    puts a.to_s
  else
    x = k - (a + b)
    puts (a - x).to_s
  end
end

if self.to_s == 'main' then
  main(ARGV)
end

Measured memory_bytes: 14388
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Diverta
{
    class C
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());

            int countA = 0, countB = 0, countAB = 0, countBA = 0;
            for (int i = 0; i < N; i++)
            {
                string s = Console.ReadLine();
                if (s.StartsWith("B"))
                {
                    if (s.EndsWith("A"))
                    {
                        countBA++;
                    }
                    else
                    {
                        countB++;
                    }
                }
                else if (s.EndsWith("A"))
                {
                    countA++;
                }
                while (s.Length > 0)
                {
                    int id = s.IndexOf("AB");
                    if (id >= 0)
                    {
                        countAB++;
                        s = s.Substring(id + 2);
                    }
                    else
                    {
                        break;
                    }
                }
            }

            int sum = 0;
            if (countBA >= 1)
            {
                sum = countBA - 1;
                if (countB > 0)
                {
                    sum++; countB--;
                }
                if (countA > 0)
                {
                    sum++; countA--;
                }
            }

            int max = countAB + sum + Math.Min(countA, countB);
            Console.WriteLine(max);
        }

    }
}


Measured memory_bytes: 13408
/* ANTHOR KUMAR DAS
KUET ECE 2K18*/
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define sc(a) scanf("%d",&a)
#define sc1(n) scanf("%lld",&n)
#define sc2(b,c) scanf("%lld%lld",&b,&c)
#define f(a,b) for(a=0;a<b;a++)
#define pb(a) push_back(a)
#define br break
int main()
{
    string a="Sunny",b="Cloudy",c="Rainy",s;
    cin>>s;
    if(s==a)
    {
        cout<<b<<endl;
    }
    else if(s==b)
    {
        cout<<c<<endl;
    }
    else{
        cout<<a<<endl;
    }


    return 0;
}



Measured memory_bytes: 256
#Union Find
#xの根を求める
def find(x):
    if par[x] < 0:
        return x
    else:
        par[x] = find(par[x])
        return par[x]
#xとyの属する集合の併合
def unite(x,y):
    x = find(x)
    y = find(y)
    
    if x == y:
        return False
    else:
        #sizeの大きいほうがx
        if par[x] > par[y]:
            x,y = y,x
        par[x] += par[y]
        par[y] = x
        return True

#xとyが同じ集合に属するかの判定
def same(x,y):
    return find(x) == find(y)

#xが属する集合の個数
def size(x):
    return -par[find(x)]

N,M,K = map(int,input().split())
#初期化
#根なら-size,子なら親の頂点
par = [-1]*(N+1)

friends = [[]for i in range(0,N+1,1)]
block = [[]for i in range(0,N+1,1)]
for i in range(0,M,1):
    a,b = map(int,input().split())
    friends[a].append(b)
    friends[b].append(a)
    unite(a,b)
for i in range(0,K,1):
    a,b=map(int,input().split())
    block[a].append(b)
    block[b].append(a)

for i in range(1,N+1,1):
    friends[i].extend(block[i])
    set(friends[i])

countmem = [0]*N
for i in range(1,N+1,1):
    count = size(i)-1
    for j in range(0,len(friends[i]),1):
        if same(i,friends[i][j]):
            count -=1
    countmem[i-1]=count

print(*countmem)

Measured memory_bytes: 125088
#include <vector>
#include <iostream>
#include <utility>
#include <algorithm>
#include <string>
#include <deque>
#include <queue>
#include <tuple>
#include <queue>
#include <functional>
#include <cmath>
#include <iomanip>
#include <map>
#include <set>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
#include <complex>
#include <iterator>
#include <array>
#include <memory>
#include <stack>
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define all(in) in.begin(), in.end()
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
#define MAX 9999999
using namespace std;
typedef pair<int, int> pii;
typedef pair<double,double>pdd;
typedef pair<ll,ll>pll;
#define int ll
signed main(){
    int n; cin>>n;
    vi v(n);
    vi a(n),b(n);
    int ans=0;
    rep(i,n)cin>>v[i];
    rep(i,n){
        if(i)a[i]=a[i-1]+v[i];
        else a[i]=v[i];
        if(i%2){
            if(a[i]<0)continue;
            ans+=abs(a[i])+1;
            a[i] = -1;
        }else{
            if(a[i]>0)continue;
            ans+=abs(a[i])+1;
            a[i]=1;
        }
    }
    int temp=0;
    rep(i,n){
        if(i)b[i]=b[i-1]+v[i];
        else b[i]=v[i];
        if(i%2){
            if(b[i]>0)continue;
            temp+=abs(b[i])+1;
            b[i]=1;
        }else{
            if(b[i]<0)continue;
            temp+=abs(b[i])+1;
            b[i]= -1;
        }
    }
    cout<<min(temp,ans)<<endl;
    
}

Measured memory_bytes: 2560
#include <iostream>
using namespace std;
int main()
{
	int a,b;
	cin>>a>>b;
	if(a==b)
	{
		cout<<"Draw";
	}
	else if(a==1)
	{
		cout<<"Alice";
	}
	else if(b==1)
	{
		cout<<"Bob";
	}
	else if(a>b)
	{
		cout<<"Alice";
	}
	else if(b>a)
	{
		cout<<"Bob";
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
//----***やべーやつら***----
using namespace std;
#define int long long

//----***型定義***----
using ll = long long;
using P = pair<int,int>;

//----***Like a Pythonista***----
#define REP(ii,jj,nn) for (ll ii=jj;ii<(nn);ii++)
#define RREP(ii,nn,jj) for (ll ii = nn; jj<ii;ii--)
#define each(i,...) for (auto&& i:__VA_ARGS__)
#define ALL(vec) (vec).begin(),(vec).end()
#define sum(...) accumulate(ALL(__VA_ARGS__),0LL)
#define dsum(...) accumulate(ALL(__VA_ARGS__),0.0)
#define vec(type,name,...) vector<type> name(__VA_ARGS__)
template<class T> inline auto max(const T& a){ return *max_element(ALL(a)); }
template<class T> inline auto min(const T& a){ return *min_element(ALL(a)); }
inline ll gcd(ll a,ll b){if(b == 0) return a;return  gcd(b,a%b);}
inline ll lcm(ll a,ll b){ll g = gcd(a,b);return a / g * b;}

//----***定数***----
#define MOD 1000000007
#define INF 100000000000000000
#define EPS 1e-9
const vector<vector<int>> DXY={{-1,0},{1,0},{0,-1},{0,1}};

//----***パーツ***----
#define fi first
#define se second
#define pb push_back
#define re return
#define br break

//----***入出力***---
void print() { std::cout << "\n"; }
template <class T>void print(const T &x) {std::cout << x<<"\n";}
template <class T, class... Args>void print(const T &x, const Args &... args) {std::cout << x << " ";print(args...);}
#define debug(var)  do{std::cerr << #var << " ↓ "<<"\n";view(var);}while(0);
#define dbg cerr<<"🥺🥺🥺🥺🥺🥺"<<endl;
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }

//----***初期時読み込み***----
struct initial{initial(){cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(15);};}initial_;



signed main(){
  int N,K,a;cin>>N>>K;
  vector<int> A(N+10),visited(N,0);
  REP(i,0,N){
    cin>>a;
    a--;
    A[i]=a;
  }
  visited[0]=1;
  int before=0,value=1,next;
  while(true){
    next=A[before];
    if(visited[next]){
      break;
    }
    if(value==K){
      print(next+1);
      re 0;
    }
    value++;
    visited[next]=value;
    before=next;
  }
  // debug(visited);
  int tmp=(K-visited[next])%(value+1-visited[next]);
  before=next;
  // REP(i,0,N)visited[i]=0;
  REP(i,0,tmp+1){
    next=A[before];
    before=next;
  }
  print(next+1);

}


Measured memory_bytes: 6344
N = int(input())
ls = []
for i in range(N):
  ls.append(input())

l = [0,0,0,0,0]
for i in range(N):
  if ls[i][0] == "M":
    l[0] += 1
  if ls[i][0] == "A":
    l[1] += 1
  if ls[i][0] == "R":
    l[2] += 1
  if ls[i][0] == "C":
    l[3] += 1
  if ls[i][0] == "H":
    l[4] += 1        

ans = 0
for i in range(5):
  for j in range(i+1,5):
    for k in range(j+1,5):
      ans += l[i]*l[j]*l[k]
print(ans)      

Measured memory_bytes: 9772