akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
int main(void){
    
    long long int H,W;
    cin >> H >> W;
    if(H % 3 == 0 || W % 3 == 0) {
        cout << 0 << endl;
    }else {
        long long int tmp[3],S=10000000000;
        for(long long int i = 1; i < max(H,W); i++) {
            tmp[0] = min(H,W)*i;
            if((max(H,W)-i)%2==0) {
                tmp[1] = (H*W-tmp[0])/2;
                tmp[2] = tmp[1];
            }else {
                tmp[1] = (max(H,W)-i)*(min(H,W)/2);
                tmp[2] = H*W-tmp[0]-tmp[1];
            }
            sort(tmp,tmp+3);
            S = min(S,tmp[2]-tmp[0]);
        }
        for(long long int i = 1; i < min(H,W); i++) {
            tmp[0] = max(H,W)*i;
            if((min(H,W)-i)%2==0) {
                tmp[1] = (H*W-tmp[0])/2;
                tmp[2] = tmp[1];
            }else {
                tmp[1] = (min(H,W)-i)*(max(H,W)/2);
                tmp[2] = H*W-tmp[0]-tmp[1];
            }
            sort(tmp,tmp+3);
            S = min(S,tmp[2]-tmp[0]);
        }
        cout << S << endl;
    }
    
    return 0;
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define REP(i,s,n) for(int i=s; i<(n); ++i)
#define ALL(n) begin(n),end(n)
using ll = long long;
const ll INF = numeric_limits<long long>::max();

int main(){
    ll N, K;
    cin >> N >> K;

    if (K == 1){
        cout << 0 << endl;
        return 0;
    }

    N = N % K;
    while(N * 2 > K){
        N = abs(N - K);
    }
    cout << N << endl;

    return 0;
}


Measured memory_bytes: 256
import re
w = input()
i =0
k = 0
a = 'abcdefghijklmnopqrstuvwxyz'
for i in  range(26):
    if ((len(re.findall(a[i] , w)) %2) == 0):
        k += 1
    i +=1
if k == 26:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 3188
import sys
import heapq
import re
from itertools import permutations
from bisect import bisect_left, bisect_right
from collections import Counter, deque
from fractions import gcd
from math import factorial, sqrt
from functools import lru_cache, reduce
INF = 1 << 60
mod = 1000000007
sys.setrecursionlimit(10 ** 7)

# UnionFind
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

# ダイクストラ
def dijkstra_heap(s, edge, n):
    #始点sから各頂点への最短距離
    d = [10**20] * n
    used = [True] * n #True:未確定
    d[s] = 0
    used[s] = False
    edgelist = []
    for a,b in edge[s]:
        heapq.heappush(edgelist,a*(10**6)+b)
    while len(edgelist):
        minedge = heapq.heappop(edgelist)
        #まだ使われてない頂点の中から最小の距離のものを探す
        if not used[minedge%(10**6)]:
            continue
        v = minedge%(10**6)
        d[v] = minedge//(10**6)
        used[v] = False
        for e in edge[v]:
            if used[e[1]]:
                heapq.heappush(edgelist,(e[0]+d[v])*(10**6)+e[1])
    return d

# 素因数分解
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

# 2数の最小公倍数
def lcm(x, y):
    return (x * y) // gcd(x, y)

# リストの要素の最小公倍数
def lcm_list(numbers):
    return reduce(lcm, numbers, 1)

# リストの要素の最大公約数
def gcd_list(numbers):
    return reduce(gcd, numbers)

# ここから書き始める
x, y = 0, 0
n = int(input())
for i in range(n):
    t, a = map(int, input().split())
    if i == 0:
        x = t
        y = a
        continue
    b = -(-x // t)
    c = -(-y // a)
    d = max(b, c)
    x = t * d
    y = a * d
print(x + y)

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

road = [[] for _ in range(N)]

for _ in range(M):
  a,b = map(int,input().split())
  road[a-1].append(b-1)
  road[b-1].append(a-1)

def dfs(v,w):
  l = [0 for _ in range(N)]
  l[v] = 1
  stack = [v]
  while stack:
    vv = stack.pop()
    for i in road[vv]:
      if i == w and v == vv or i == vv and v == w:
        continue
      else:
        if l[i] == 0:
          l[i] = 1
          stack.append(i)
  return sum(l)

ans = 0
check = [[0 for _ in range(N)] for _ in range(N)]

for n in range(N):
  for m in range(len(road[n])):
    if check[n][road[n][m]] == 0 or check[road[n][m]][n] == 0:
      check[n][road[n][m]] = 1
      check[road[n][m]][n] = 1
      d = dfs(n,road[n][m])
      if d != N:
        ans += 1

print(ans)

Measured memory_bytes: 3064
N,M,K=map(int,input().split())
mod= 998244353

FACT=[1]
for i in range(1,2*10**5+1):
    FACT.append(FACT[-1]*i%mod)

FACT_INV=[pow(FACT[-1],mod-2,mod)]
for i in range(2*10**5,0,-1):
    FACT_INV.append(FACT_INV[-1]*i%mod)

FACT_INV.reverse()

def Combi(a,b):
    if 0<=b<=a:
        return FACT[a]*FACT_INV[b]*FACT_INV[a-b]%mod
    else:
        return 0

ANS=0
for i in range(K+1):
    ANS+=Combi(N-1,i)*pow(M-1,N-1-i,mod)
    ANS%=mod
print(ANS*M%mod)


Measured memory_bytes: 24876
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cassert>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <unordered_map>
#include <set>
#include <map>
#define INCANT cin.tie(0), cout.tie(0), ios::sync_with_stdio(0), cout << fixed << setprecision(20);
#define rep(i,n) for (int i=0; i<n;++i)
#define ALL(a)  (a).begin(),(a).end()
#define PI 3.14159265358979
typedef long long ll;
using namespace std;
const ll MOD = 1e9+7LL;
const int INF = 2e9;
int N, M;
vector<int> G[100005];
int d[100005]; // 最後に全部に1足すこと
typedef pair<int, int> P;

void dijkstra() {
  queue<P> que;
  que.push(P(0, INF));
  while(!que.empty()) {
    P q = que.front(); que.pop();
    if (d[q.first]>0) continue;
    d[q.first] = q.second+1;
    for (auto n: G[q.first]) {
      if (d[n]==0) que.push(P(n, q.first));
    }
  }
}

int main() {
  INCANT;
  cin >> N >> M;
  int a,b;
  rep(i, M) {
    cin >> a >> b;
    a--;b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  dijkstra();
  cout << "Yes" << endl;
  rep(i, N) {
    if (i==0) continue;
    cout << d[i] << endl;
  }
  return 0;
}

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

int main()
{
    long int n;
    cin>>n;
    
    long int A[n],tot=0,i;
    for(i=0;i<n;++i)
    {
        cin>>A[i];
        tot=tot ^ A[i];
    }
    
    for(i=0;i<n;++i)
    {
        cout<<(tot xor A[i])<<" ";
    }
    cout<<endl;
}

Measured memory_bytes: 5068
#include <iostream>
#include <string>
#include<vector>
#include<algorithm>
#include<utility>
#include<queue>
#include<math.h>
#include<stack>
#include<set>
#include<map>
#define INF long long int(1e18+1)
#define rep(i,n,m) for(int i=n;i<m;i++)

using namespace std;



int main() 
{
	string s;
	cin >> s;
	rep(i, 0, s.size())cout << "x";

}




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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<int, int> Pi;
typedef vector<ll> Vec;
typedef vector<int> Vi;
typedef vector<string> Vs;
typedef vector<P> VP;
typedef vector<vector<ll>> VV;
typedef vector<vector<int>> VVi;

#define REP(i, a, b) for(ll i=(a); i<(b); i++)
#define PER(i, a, b) for(ll i=(a); i>=(b); i--)
#define rep(i, n) REP(i, 0, n)
#define per(i, n) PER(i, n, 0)
const ll INF=1e18+18;
const ll MAX=100005;
const ll MOD=1000000007;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define YES(n) cout << ((n) ? "YES" : "NO") << endl;
#define ALL(v) v.begin(), v.end()
#define rALL(v) v.rbegin(), v.rend()
#define pb(x) push_back(x)
#define mp(a, b) make_pair(a,b)
#define Each(a,b) for(auto &a :b)
#define REPM(i, mp) for (auto i = mp.begin(); i != mp.end(); ++i)
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define dbgmap(mp) cerr << #mp << ":"<<endl; for (auto i = mp.begin(); i != mp.end(); ++i) { cerr << i->first <<":"<<i->second << endl;}
#define dbgarr(n,m,arr) rep(i,n){rep(j,m){cerr<<arr[i][j]<<" ";}cerr<<endl;}
#define dbgdp(n,arr) rep(i,n){cerr<<arr[i]<<" ";}cerr<<endl;
#define dbgmint(n,arr) rep(i,n){cerr<<arr[i].x<<" ";}cerr<<endl;
#define out(a) cout<<a<<endl
#define out2(a,b) cout<<a<<" "<<b<<endl
#define vout(v) rep(i,v.size()){cout<<v[i]<<" ";}cout<<endl
#define Uniq(v) v.erase(unique(v.begin(), v.end()), v.end())
#define fi first
#define se second

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

template<typename T1, typename T2>
ostream &operator<<(ostream &s, const pair<T1, T2> &p) { return s<<"("<<p.first<<", "<<p.second<<")"; }

template<typename T>istream& operator>>(istream&i,vector<T>&v)
{rep(j,v.size())i>>v[j];return i;}

// vector
template<typename T>
ostream &operator<<(ostream &s, const vector<T> &v) {
    int len=v.size();
    for(int i=0; i<len; ++i) {
        s<<v[i];
        if(i<len-1) s<<"	";
    }
    return s;
}

// 2 dimentional vector
template<typename T>
ostream &operator<<(ostream &s, const vector<vector<T> > &vv) {
    int len=vv.size();
    for(int i=0; i<len; ++i) {
        s<<vv[i]<<endl;
    }
    return s;
}

ll dp[102][MAX];
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<std::setprecision(10);

    ll n,W;
    cin>>n>>W;
    Vec w(n);
    Vec v(n);
    rep(i,n){
        cin>>w[i]>>v[i];
    }
    rep(i,n){
        rep(j,W+1){
            chmax(dp[i+1][j],dp[i][j]);
            if(j-w[i]<0)continue;
            chmax(dp[i+1][j],dp[i][j-w[i]]+v[i]);
        }
    }
//    dbgarr(4,4,dp);
    ll ans=dp[n][W];
    cout<<ans<<endl;
    return  0;
}


Measured memory_bytes: 78336
n = int(input())
t, a = map(int, input().split())
H = list(map(int, input().split()))

ans = -1
exp = 1000000007 
for i in range(n):
  avg = t - H[i] * 0.006
  
  if abs(a - avg) < exp:
    ans = i + 1
    exp = abs(a-avg)

print(ans)



Measured memory_bytes: 3060
import java.util.Scanner
object Main extends App {
  val sc = new Scanner(System.in)
  val n = sc.nextInt
  val as = Array.fill(n)(sc.nextInt)

  def dp(flipped: Long, notFlipped: Long, i: Int): Long = {
    if (i == n - 1) Math.max(flipped, notFlipped)
    else {
      dp(
        Math.max(flipped + 2 * as(i) - as(i + 1),
              notFlipped - 2 * as(i) - as(i + 1)),
        Math.max(flipped + as(i + 1),
              notFlipped + as(i + 1)),
        i + 1)
    }
  }

  println(dp(-(as(0) + as(1)), as(0) + as(1), 1))
}

Measured memory_bytes: 52096
N = int(input())
for i in range(N):
    out = 0
    hit = 0
    point = 0
    
    while out < 3 :
         a = input()
         if a == "HIT":
              if hit < 3:
                   hit = hit + 1
              else:
                  point = point + 1
         elif a == "HOMERUN":
            point += hit + 1
            hit = 0
         elif a == "OUT":
            out += 1
    print(point)
            
             

Measured memory_bytes: 7544
#include<stdio.h>
int a[4010],pb[2010],pw[2010],cb[2010][2010],cw[2010][2010],f[2010][2010];
char c[4010];
int min(int a,int b){return a<b?a:b;}
int main(){
	int n,i,j,s;
	scanf("%d",&n);
	for(i=1;i<=n<<1;i++){
		scanf("%s%d",c+i,a+i);
		(c[i]=='B'?pb:pw)[a[i]]=i;
	}
	for(i=1;i<=n;i++){
		s=0;
		for(j=pb[i]+1;j<=n<<1;j++){
			if(c[j]=='B'&&a[j]<i)s++;
		}
		for(j=0;j<=n;j++){
			if(pw[j]>pb[i])s++;
			cb[i-1][j]=s;
		}
		s=0;
		for(j=pw[i]+1;j<=n<<1;j++){
			if(c[j]=='W'&&a[j]<i)s++;
		}
		for(j=0;j<=n;j++){
			if(pb[j]>pw[i])s++;
			cw[j][i-1]=s;
		}
	}
	for(i=1;i<=n;i++){
		f[i][0]=f[i-1][0]+cb[i-1][0];
		f[0][i]=f[0][i-1]+cw[0][i-1];
	}
	for(i=1;i<=n;i++){
		for(j=1;j<=n;j++)f[i][j]=min(f[i-1][j]+cb[i-1][j],f[i][j-1]+cw[i][j-1]);
	}
	printf("%d",f[n][n]);
}

Measured memory_bytes: 47488
#include <bits/stdc++.h>
#include <string>
using namespace std;
#define ll long long
#define endl "\n"
#define print_array(name,n) for(ll o=0;o<n;o++) cout<<name[o]<<" "
#define fr(i,f,t) for(ll i=(f);i<t;i++)
#define fb(i,f,t) for(ll i=(f);i>=t;i--)
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define inf 2e18
bool sortbysecond(const pair<int,int> &a,const pair<int,int> &b){
	return (a.ss>b.ss);
}
template <typename T>
string NumberTostring(T Number )
{
	ostringstream ss;
	ss<<Number;
	return ss.str();
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    int n,m;
    cin>>n>>m;
    vector<int> vec(n+1,0);
    for(int i=1;i<=n;i++){
    	cin>>vec[i];
    }
    vector<int> data(n+1,1);
    int a,b;
    for(int i=0;i<m;i++){
    	cin>>a>>b;
    	if(vec[a]>vec[b]){
    		data[b] = 0;
    	}
    	if(vec[a]==vec[b]){
    		data[a] = 0;
    		data[b] = 0;
    	}
    	if(vec[a]<vec[b]){
    		data[a]=0;
    	}
    }
    // print_array(data,n+1);
    // cout<<endl;
    int cnt=0;
    for(int i=1;i<=n;i++){
    	if(data[i]==1){
    		cnt++;
    	}
    }
    cout<<cnt<<endl;
    return 0;
}

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

using namespace std;

int main(){
    string S; cin >> S;
    int upper = atoi(S.substr(0,2).c_str());
    int lower = atoi(S.substr(2,2).c_str());

    if(1 <= upper && upper <= 12 && 1 <= lower && lower <= 12){
        cout << "AMBIGUOUS" << endl;
    }else if(1 <= upper && upper <= 12){
        cout << "MMYY" << endl;
    }else if(1 <= lower && lower <= 12){
        cout << "YYMM" << endl;
    }else{
        cout << "NA" << endl;
    }
}

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

using namespace std;

bool is_squre(int d) {
    long long L = 0, R = 1e9;
    while (R - L > 1) {
        long long M = (L + R) / 2;
        if (M * M <= d) {
            L = M;
        } else {
            R = M;
        }
    }
    return L * L == d;
}

int get_dist(vector <int> a, vector <int >b) {
    int ans = 0;
    for (int i = 0; i < a.size(); i++) {
        ans += (a[i] - b[i]) * (a[i] - b[i]);
    }
    return ans;
}

int main()
{
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
#endif // LOCAL
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n, d;
    cin >> n >> d;
    vector <vector<int>> points(n);
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < d; j++) {
            int x;
            cin >> x;
            points[i].push_back(x);
        }
    }
    int ans = 0;
    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            if (is_squre(get_dist(points[i], points[j]))) {
                ans++;
            }
        }
    }
    cout << ans;
    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 pb push_back

typedef long long ll;

ll solve(ll x, ll y) {
	ll lb = 0, ub = 1000000001;
	while (ub - lb > 1) {
		ll mid = (lb + ub) / 2;
		if (mid * mid < x * y) lb = mid;
		else ub = mid;
	}
	ll z = lb;
	ll ans = z * 2;
	if (z * (z + 1) >= x * y) ans--;
	if (z >= x || z >= y) ans--;
	return ans;
}

int main() {
	int Q; cin >> Q;
	while (Q--) {
		ll x, y; cin >> x >> y;
		cout << solve(x, y) << endl;
	}
}


Measured memory_bytes: 256
import sys
import os
import math


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N, *TIME = [int(sys.stdin.readline().rstrip()) for _ in range(6)]

    m = min(TIME)
    ret = math.ceil(N / m) + TIME.index(m)
    ret += len(TIME) - TIME.index(m) - 1

    print(ret)


if __name__ == '__main__':
    main()


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

struct l{int x,y;};
int pw(int n,int k){
  assert(k>=0);
  int res=1;
  while(k){
    if(k&1)res*=n;
    n*=n;
    k>>=1;
  }
  return res;
}
template<typename T>
void chmax(T &a,T b){
  if(a<b)a=b;
}

signed main(){
  int n;cin>>n;
  vector<l> spe[n];
  for(int i=0;i<n;i++){
    int a;cin>>a;
    while(a--){
      int x,y;cin>>x>>y;x--;
      spe[i].push_back({x,y});
    }
  }
  int ans=0;
  for(int i=0;i<pw(2,n);i++){
    bool f=true;
    int cnt=0;
    for(int j=0;j<n;j++){
      if(((i>>j)&1)==0)continue;
      cnt++;
      for(l p:spe[j])if(p.y!=((i>>p.x)&1))f=false;
    }
    if(f)chmax(ans,cnt);
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include<stdio.h>

#define MAX_LENGTH 32

int main(void)
{
        char line[MAX_LENGTH];
        int a,b,c;
        int divnum = 0;
        int i = 0;

        fgets(line, sizeof(line), stdin);
        sscanf(line, "%d %d %d", &a, &b, &c);

        for (i = a; i <= b; i++) {
                if ( (c % i) == 0 )
                        divnum++;
        }

        printf("%d\n", divnum);

        return 0;
}

Measured memory_bytes: 604
#include<bits/stdc++.h>
using namespace std;
struct node
{
  string s;
  int v;
    int id;
  bool operator< (const node l)
  {
     if(s == l.s)return v > l.v;
      return s < l.s;
  }
}a[105];
int main()
{
    int n;
    while(cin>>n)
    {
        for(int i = 0; i < n; ++i)
        {
            a[i].id = i+1;
            cin>>a[i].s>>a[i].v;
        }
        sort(a,a+n);
        for(int i = 0; i < n; ++i)
            cout<<a[i].id<<endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n;
  cin >> n;
  int pt[n][3];
  int fpt = 1;
  int ans[n];

  memset(ans,0,sizeof(ans));
  for(int i = 0;i < n;i++)cin >> pt[i][0] >> pt[i][1] >> pt[i][2];

  for(int i = 0;i < 3;i++){
    for(int j = 0;j < n;j++){
      fpt = 1;
      for(int k = 0;k < n;k++){
	if(pt[j][i] == pt[k][i] && j != k){
	  fpt = 0;
	}
      }
      if(fpt){
	ans[j] += pt[j][i];
      }
    }
  }
  for(int i = 0;i < n;i++){
    cout << ans[i] << endl;
  }
}

Measured memory_bytes: 1168
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.*;
import java.util.*;

public class Main {
	
	public static void main(String[] args) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		String input = in.readLine();
		String[] first = input.split(" ");
		int n = Integer.parseInt(first[0]);
		int amount = Integer.parseInt(first[1]);
		
		int[][] WV = new int[n][2];
		for(int i = 0; i < n; i++) {
			input = in.readLine();
			first = input.split(" ");
			int weight = Integer.parseInt(first[0]);
			int value = Integer.parseInt(first[1]);
			WV[i][0] = weight;
			WV[i][1] = value;
		}
		//System.out.println(Arrays.deepToString(WV));
		System.out.println(knapSack(WV,amount));
	}
	
	public static long knapSack(int[][] WV, int amount) {
		int rows = WV.length + 1;
		long[][] DP = new long[rows][amount + 1];
		for(int i = 1; i < rows; i++) {
			for(int j = 1; j <= amount; j++) {
				if(j < WV[i-1][0]) DP[i][j] = DP[i-1][j];
				else DP[i][j] = Math.max(DP[i-1][j], DP[i-1][j-WV[i-1][0]] + WV[i-1][1]);
			}
		}
		//System.out.println(Arrays.deepToString(DP));
		return DP[rows-1][amount];
	}
}


Measured memory_bytes: 125012
N = int(input())
cnt,ext,na,nb,nc = 0,0,0,0,0
for i in range(N):
    s = input()
    cnt += s.count('AB')
    if (s[-1] == 'A') and (s[0]!='B'):
        na += 1
    if (s[-1] != 'A') and (s[0]=='B'):
        nb += 1
    if(s[-1] == 'A') and (s[0]=='B'):
        nc += 1

if nc>0:
    ext += nc-1
    if na>0:
        ext += 1
        na -= 1
    if nb>0:
        ext += 1
        nb -= 1

ext += min(na,nb)

print(cnt+ext)

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

namespace _1_9_d
{
    class Program
    {
        static void Main(string[] args)
        {
            string str = Console.ReadLine();
            int q = int.Parse(Console.ReadLine());
            for (int i = 0; i < q; i++)
            {
                string[] s = Console.ReadLine().Split(' ');
                string program = s[0];
                int a = int.Parse(s[1]);
                int b = int.Parse(s[2]);
                string p = "";
                List<string> answer = new List<string>();

                string ab = str.Substring(0, a);
                string bc = str.Substring(a, b - a + 1);
                string cd = str.Substring(b + 1);

                if (program == "print")
                {
                    Console.WriteLine(bc);
                }
                else if (program == "reverse")
                {
                    str = ab+ string.Join("", bc.Reverse()) + cd;
                }
                else
                {
                    p = s[3];
                    System.Text.StringBuilder replace = new System.Text.StringBuilder(str);
                    replace.Replace(str.Substring(a, b - a + 1), p, a, b - a + 1);
                    str = replace.ToString();
                }
                //foreach (string item in answer)
                //    Console.WriteLine(item);
            }
        }
    }
}



Measured memory_bytes: 18292
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll mod = 1000000007;

int main() {
  int N, K;
  cin >> N >> K;
  vector<ll> a, b;
  for (int i = 0; i < N; i++) {
    int x;
    cin >> x;
    if (x >= 0)
      a.push_back(x);
    else
      b.push_back(x);
  }

  sort(a.begin(), a.end(), greater<ll>());
  sort(b.begin(), b.end(), greater<ll>());

  int i, j;
  i = j = 0;
  ll k = 1;
  ll ans = 1;

  if (N == K) {
    for (ll i : a) {
      ans *= i;
      ans %= mod;
    }
    for (ll j : b) {
      ans *= j;
      ans += mod * ((ans * -1 + mod - 1) / mod);
    }
    cout << ans << endl;
    return 0;
  }

  if (K % 2 == 1) {
    if (a.size() == 0) {
      for (int i = 0; i < K; i++) {
        ans *= b[i];
        if (ans >= 0)
          ans %= mod;
        else {
          ans += mod * ((ans * -1 + mod - 1) / mod);
        }
      }
      cout << ans << endl;
      return 0;
    } else {
      ans *= a[0];
      K--;
      i++;
    }
  }

  sort(b.begin(), b.end());
  while (K > 0) {
    if (b.size() <= j + 1 ||
        (a.size() > i + 1 && a[i] * a[i + 1] >= b[j] * b[j + 1])) {
      ans *= a[i];
      ans %= mod;
      ans *= a[i + 1];
      ans %= mod;
      i += 2;
      K -= 2;
    } else {
      ans *= abs(b[j]);
      ans %= mod;
      ans *= abs(b[j + 1]);
      ans %= mod;
      j += 2;
      K -= 2;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 5440
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int asc(const void *a, const void *b) {
  return *(char *)a - *(char *)b;
}

int ascs(const void *a, const void *b) {
  return strcmp((char *)a,(char *)b);
}

int main(){
   int n,i,k;
   long j,sum;
   char s[100000][11];
    
   scanf("%d",&n);
   for (i=0;i<n;i++) {
      scanf("%s",s[i]);
      qsort(s[i],10,sizeof(char),asc);
   }
   qsort(s,n,sizeof(char)*11,ascs);
   for (sum=i=0;i<n;i++) {
      for (j=i+1;j<n;j++) 
         if (strcmp(s[i],s[j])!=0) break;
      sum+=(j-i-1)*(j-i)/2;
      i=j-1;
   }
   printf("%ld\n",sum);
   return 0;
}


Measured memory_bytes: 2300
#include <bits/stdc++.h>
#define pb push_back
#define IOS                                                                    \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(0);                                                                  \
  cout.tie(0)
#define ll long long int
#define ld long double
#define el '\n'
#define PI (ld)3.14159265358979323846
#define inf (ll)1000000000
#define mod (ll)1000000007
#define mod1 (ll)998244353
#define fo(i, n) for (long long i = 0; i < int(n); i++)
#define pll pair<ll, ll>
#define ff first
#define ss second
#define pqueue priority_queue< int >
#define pdqueue priority_queue< int,vi ,greater< int > >
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define sz(a) a.size()
#define f(i,a,b) for(ll i=a;i<b;i++)
#define fd(i,a,b) for(ll i=a;i>=b;i--)
#define all(a) a.begin(),a.end()
#define vl vector<ll>
//#define x ff
//#define y ss
#define pt(a) for(auto it:a)cout<<it<<" ";cout<<endl;
unsigned seed = std::chrono::system_clock::now().time_since_epoch().count();
using namespace std;

double gcd(double a, double b) { return a < 0.01 ? b : gcd(fmod(b, a), a); }

/*vector<int> parent, rak;

int find_set(int v) {
    if (v == parent[v])
        return v;
    return parent[v] = find_set(parent[v]);
}

void union_sets(int a, int b) {
    a = find_set(a);
    b = find_set(b);
    if (a != b) {
        if (rak[a] < rak[b])
            swap(a, b);
        parent[b] = a;
        rank[a]+=rank[b];
    }
}*/

long long bpow(long long a, long long b, long long m) {
  a %= m;
  long long res = 1;
  while (b > 0) {
    if (b & 1)
      res = res * a % m;
      a = a * a % m;
      b >>= 1;
  }
  return res;
}
ll extend_gcd(ll a,ll b,ll &x,ll &y){
    if(b==0){
        x=1;
        y=0;
        return a;
    }
    ll x1,y1;
    ll ans =extend_gcd(b,a%b,x1,y1);
    x=y1;
    y=x1-(a/b)*y1;

    return ans;
}
ll inverse(ll a,ll m){
    ll x,y;
    extend_gcd(m,a,x,y);
    y%=m;
    y+=m;
    y%=m;
    return y;
}

/*const int N = 1000001;
int lp[N+1];
vector<int> pr;
void s(){
for (int i=2; i<=N; ++i) {
        if (lp[i] == 0) {
            lp[i] = i;
            pr.push_back (i);
        }
        for (int j=0; j<(int)pr.size() && pr[j]<=lp[i] && i*pr[j]<=N; ++j)
            lp[i * pr[j]] = pr[j];
    }
}*/


ll kv;
ll t,n,x,y,h,k,z,p,q,w;

//vector<vector<ll>>v;
//vector<ll>vis,d;
  

int main() {
    IOS;
    cin>>n;
    ll a[5];h=inf*inf;
    fo(i,5){
        cin>>a[i];
        if(a[i]<h)h=a[i],p=i;
    }
    kv=4;
    kv+=n/h+(n%h!=0);
    cout<<kv;
    return 0;
}


Measured memory_bytes: 256
import math
K = int(input())

odd = list(range(1, K+1, 2))
even = list(range(2, K+1, 2))


def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))


print(combinations_count(len(odd), 1)*combinations_count(len(even), 1))


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

public class Program
{
    static void Main()
    {
        var nmc = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();
        var bArray = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();

        var count = 0;
        for (int i = 0; i < nmc[0]; i++)
        {
            var aArray = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();
            var val = 0;
            for (int j = 0; j < nmc[1]; j++)
            {
                val += aArray[j] * bArray[j];
            }

            if (val + nmc[2] > 0)
            {
                count++;
            }
        }

        Console.WriteLine(count);
    }
}


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

int dp[10001]; // dp[i] 重さi以下の最大値
int v, w;
int N, W;

int main() {
    cin >> N >> W;
    for(int i = 0; i < N; i++) {
        cin >> v >> w;
        for(int j = W; j >= 0; j--) {
            if(j + w <= W)
                dp[j + w] = max(dp[j + w], dp[j] + v);
        }
    }
    cout << dp[W] << endl;
}


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

using namespace std;
using u64 = std::uint_fast64_t;

class RollingHash {
 private:
  using u64 = std::uint_fast64_t;

  const u64 mod = ((u64)1 << 61) - 1;
  std::vector<u64> hashes, pows;

  inline u64 add(u64 a, u64 b) const {
    a += b;
    if (a >= mod) a -= mod;
    return a;
  }

  inline u64 sub(u64 a, u64 b) const {
    if (a < b) a += mod;
    a -= b;
    return a;
  }

  inline u64 mul(u64 a, u64 b) const {
    u64 ah = a >> 31, al = a & (((u64)1 << 31) - 1), bh = b >> 31,
        bl = b & (((u64)1 << 31) - 1), m = ah * bl + al * bh,
        v = (ah * bh << 1) + (m >> 30) + ((m & (((u64)1 << 30) - 1)) << 31) +
            al * bl;
    v = (v & (((u64)1 << 61) - 1)) + (v >> 61);
    return v;
  }

 public:
  template <typename T>
  RollingHash(const T &S, u64 base = 10007)
      : hashes(S.size() + 1, 0), pows(S.size() + 1, 0) {
    pows[0] = 1;
    for (size_t i = 0; i < S.size(); i++) {
      pows[i + 1] = mul(pows[i], base);
      hashes[i + 1] = add(mul(hashes[i], base), S[i]);
    }
  }

  // S[r, l)
  u64 slice(int l, int r) const {
    return sub(hashes[r], mul(hashes[l], pows[r - l]));
  }
};

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N;
  cin >> N;
  vector<u64> A(N), B(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  for (int i = 0; i < N; i++) {
    cin >> B[i];
  }

  vector<u64> S(N), T(N);
  for (int i = 0; i < N; i++) {
    S[i] = A[i] ^ A[(i + 1) % N];
    T[i] = B[i] ^ B[(i + 1) % N];
  }
  for (int i = 0; i < N; i++) {
    S.emplace_back(S[i]);
  }

  RollingHash rhs(S), rht(T);
  for (int i = 0; i < N; i++) {
    if (rhs.slice(i, i + N) == rht.slice(0, N)) {
      cout << i << " " << (A[i] ^ B[0]) << '\n';
    }
  }

  return 0;
}


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

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

using namespace std;

typedef long long ll;

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

  int m1, m2, d1, d2;
  cin >> m1 >> d1 >> m2 >> d2;

  if (m1 == m2) {
    cout << 0 << endl;
  } else {
    cout << 1 << endl;
  }

  return 0;
}


Measured memory_bytes: 896
#include<iostream>
#include<vector>
#include<set>
#include<list>
#include<queue>
#include<stack>
#include<map>
#include<utility>
#include<algorithm>
#include<numeric>
#include<string>
#include<cstdio>

#define pii pair<int,int>
#define pll pair<long long,long long>
#define pli pair<long long,int>
#define pil pair<int,long long>
#define ll long long 
#define fl for(int i{0};i!=n;++i)
#define vi vector<int>
#define vll vector<long long>
#define mii map<int,int>
#define mli mpa<long long,int>

using namespace std;

int main()
{
   ios_base::sync_with_stdio(false);
   cin.tie(0);
   int n{0},m{0};
   cin>>m;
   n=3*m;
   vll v(n,0),l(n,0),r(n,0);
   fl
   cin>>v[i];
   priority_queue<ll,vll,greater<ll> > p1;
   priority_queue<ll> p2;
   ll sum=0,ans=-1E17;
   fl
   {
       sum+=v[i];
       p1.push(v[i]);
       if(p1.size()>m)
       sum-=p1.top(),p1.pop();
       if(p1.size()==m)
       l[i]=sum;
       else
       l[i]=ans;
   }
   sum=0;
   for(int i{n-1};i>=0;--i)
   {
       sum+=v[i];
       p2.push(v[i]);
       if(p2.size()>m)
       sum-=p2.top(),p2.pop();
       if(p2.size()==m)
       r[i]=sum;
       else
       r[i]=-ans;
   }
   --n;
   fl
   ans=max(ans,l[i]-r[i+1]);
   cout<<ans;
}

Measured memory_bytes: 9588
#include<iostream>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<set>
#include<unordered_set>
#include<vector>
#include<array>
#include<string>
#include<stack>
#include<queue>
#include<algorithm>
#include<iterator>
#include<cassert>
#include<functional>
#include<random>
#include<complex>
#include<bitset>
#include<cstdint>
#include<chrono>
#define int int64_t
#define uint uint64_t
#define REP(i, a, b) for (int64_t i = (int64_t)(a); i < (int64_t)(b); i++)
#define rep(i, a) REP(i, 0, a)
#define EACH(i, a) for (auto i: a)
#define ITR(x, a) for (auto x = a.begin(); x != a.end(); x++)
#define ALL(a) (a.begin()), (a.end())
#define HAS(a, x) (a.find(x) != a.end())
#define Min(x) *min_element(ALL(x))
#define Max(x) *max_element(ALL(x))
#define chmax(a, b) (((a) < (b)) ? (b) : (a))
#define chmin(a, b) (((a) < (b)) ? (a) : (b))
#define intmax (std::numeric_limits<int64_t>::max() / 4)
using namespace std;
//typedef boost::multiprecision::cpp_int bigint;
const double EPS = 1e-9;
const double PI = acos(-1.0);

using namespace std;



signed main() {

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

	vector<vector<int>> v(26);
	rep(i, n) {
		v[s[i] - 'a'].push_back(i + 1);
	}
	rep(i, n) {
		v[s[i] - 'a'].push_back(n + i + 1);
	}

	int ans = 0;
	int now = 0;
	rep(i, t.size()) {
		int x = t[i] - 'a';
		if (v[x].size() == 0) {
			cout << -1 << endl;
			return 0;
		}
		now = *upper_bound(ALL(v[x]), now);
		if (now > n) {
			now -= n;
			ans += n;
		}
	}
	ans += now;
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 2800
def main(n):
	a = list(map(int,input().split()))
	ans = 0
	for i in range(n):
		minj = i
		for j in range(i, n):
			if a[j] < a[minj]:
				minj = j
		if minj == i:
			continue
		a[i], a[minj] = a[minj], a[i]
		ans += 1
	print(" ".join(map(str, a)))
	print(ans)

main(int(input()))


Measured memory_bytes: 5600
#include<stdio.h>

int main(){
	int perimetro,n,a[212345],l,max;
	scanf("%d%d",&perimetro,&n);

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

	max = perimetro - a[n - 1] + a[0]; //respeitando o movimento anti-horario.
  for (int i = 1; i < n; i++){ //o for segue um raciocinio: você vai contar a distancia entre todos os segmentos,
															 // só que o for nao conta a diferença entre o ultimo e o primeiro segmento.
    l = a[i] - a[i - 1];			 //já que o perimetro é circular, vc tbm tem a distancia entre a primeira e a ultima casa que nao
		if (l > max)							 //foi contada no for, pra isso serve a variavel max.
			max = l;
	}
  printf("%d\n",perimetro - max);
  return 0;
}


Measured memory_bytes: 896
S = input()
Q = int(input())
bs = ''
fs = ''
hanten = 0
for i in range(Q):
    query = list(input().split())
    if query[0] == '1':
        hanten += 1
    else:
        if query[1] == '1':
            if hanten % 2 == 0:
                #fs += query[2]
                fs = ''.join([fs,query[2]])
            else:
                #bs += query[2]
                bs = ''.join([bs, query[2]])
        else:
            if hanten % 2 == 0:
                #bs += query[2]
                bs = ''.join([bs, query[2]])
            else:
                #fs += query[2]
                fs = ''.join([fs, query[2]])
if hanten % 2 == 0:
    #print(fs[::-1]+S+bs)
    print(''.join([fs[::-1], S, bs]))
else:
    #print(bs[::-1]+S[::-1]+fs)
    print(''.join([bs[::-1], S[::-1], fs]))

Measured memory_bytes: 174512
//  Created by conan1024hao in 2019.
//  Copyright © 2019 conan1024hao. All rights reserved.
//  専用ライブラリです、自由にコピーして構いません。
//  感谢看我的代码！Wechat:conan1024hao QQ:810396815
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
#define INF 10e16
#define MOD 1000000007
#define rep(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define siz(x) (ll)(x).size()
#define PI acos(-1.0)
using namespace std;
//using Int=int_fast64_t;
typedef long long int ll;
typedef pair<ll,ll>Pll;
typedef pair<int,int>Pin;
long long GCD(long long a, long long b) { return b ? GCD(b, a%b) : a; }
long long LCM(long long a, long long b)  {return a/GCD(a,b)*b;}
int dx[8]={-1,0,1,0};
int dy[8]={0,-1,0,1};
char dir[4]={'u','l','d','r'};
ll cmp1(pair<ll,string>a,pair<ll,string> b){
        if(a.fi!=b.fi)
        return a.fi<b.fi;
        else
        return a.se<b.se;
}
//--------------------------------------------------------------------------

//---------------------------------------------------------------------------
int main(){//問題をちゃんと見ろ!!!!!!!!!!!!!!!!!      llか??????????        memset()!!!!!!!!!!!!
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------
    int n,m;cin>>n>>m;
    vector<ll>G(n);
    vector<ll>a(m);
    vector<ll>b(m);
    vector<ll>c(m);
    for(int i=0;i<n;i++)
        G[i]=-INF;
    G[0]=0;
    for(int i=0;i<m;i++){
        cin>>a[i]>>b[i]>>c[i];
        a[i]--;b[i]--;
        //chmax(G[b],G[a]+c);
    }
    int abc[3000];
    memset(abc,0,sizeof(abc));
    for(int j=0;j<n;j++){
        for(int i=0;i<m;i++){
            ll mmgv=G[b[i]];
            chmax(G[b[i]],G[a[i]]+c[i]);
            if(mmgv!=G[b[i]]&&b[i]==n-1&&j==n-1){
                cout<<"inf"<<endl;
                return 0;
            }
                
        }
    }
    
   // cout<<abc[1]<<endl;
   
    //if(m>=n)
     //   cout<<"inf"<<endl;
    //else
    cout<<G[n-1]<<endl;
    //-------------------------------
    return 0;
}
//---------------------------------------------------------------------------


Measured memory_bytes: 384
#include<iostream>
#include<vector>
#include<queue>
#include<set>
#include<climits>
using namespace std;

#define NONE INT_MAX

struct Data{int id,cost;};
bool operator<(Data a,Data b){return a.cost>b.cost;}

vector< vector<int> >A;

int Dijkstra(int start,int goal)
{
  vector<int>cost(A.size(),NONE);
  priority_queue<Data>q;
  set<int>used;

  Data node={start,0};
  q.push(node);
  cost[start]=0;

  while(q.size()){
    node=q.top();
    q.pop();

    if(node.id==goal)return node.cost;
    if(used.count(node.id))continue;
    else used.insert(node.id);

    for(int i=0;i<A[node.id].size();i++){
      if(used.count(i))continue;
      if(A[node.id][i]==NONE)continue;
      if(cost[i]<=cost[node.id]+A[node.id][i])continue;
      Data next={i,cost[node.id]+A[node.id][i]};
      cost[i]=next.cost;
      q.push(next);
    }

  }

  return -1;
}

int main()
{
  int n,k,a,b,c,d,e;
  while(cin>>n>>k,n|k){
    A.resize(n);
    for(int i=0;i<n;i++){
      A[i].resize(n);
      for(int j=0;j<n;j++)A[i][j]=NONE;
    }
    for(int i=0;i<k;i++){
      cin>>a;
      if(a==0){
	cin>>a>>b;
	a--;b--;
	cout<<Dijkstra(a,b)<<endl;
      }else if(a==1){
	cin>>c>>d>>e;
	c--;d--;
	if(A[c][d]>e)A[c][d]=A[d][c]=e;
      }
    }
  }
}

Measured memory_bytes: 980
import Control.Applicative ((<$>), (<*>))
import Control.Monad
import Data.List
import Data.Array.Unboxed

main :: IO ()
main = do
  n <- getl toInt
  m <- getl toInt
  solve n <$> getl (wrds toInt) <*> replicateM m (getl $ wrds toInt) >>= mapM_ print

solve :: Int -> [Int] -> [[Int]] -> [Int]
solve n ms ns = map sum $ transpose $ map elems $ f ms ns
  where
    f :: [Int] -> [[Int]] -> [UArray Int Int]
    f [] [] = []
    f (x:xs) (ys:yss) = accum (+) (listArray (1,n) zs) [(x,length $ filter (==0) zs)] : f xs yss
      where zs = map (\c -> if x == c then 1 else 0) ys

toInt :: String -> Int
toInt = read

wrds :: (String -> a) -> String -> [a]
wrds f = map f . words

getl :: (String -> a) -> IO a
getl f = f <$> getLine

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

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

    int a = n, sum = 0;
    while (a > 0)
    {
        sum += a % 10;
        a /= 10;
    }
    
    if (n % sum == 0)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
    
}

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

int main() {
  int D;
  cin >>D;
  
  if(D==25)cout<<"Christmas"<<endl;
  if(D==24)cout<<"Christmas Eve"<<endl;
  if(D==23)cout<<"Christmas Eve Eve"<<endl;
  if(D==22)cout<<"Christmas Eve Eve Eve"<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string.h>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#include <functional>
#include <cassert>
#include <utility>
#include <stack>
#include <queue>
using namespace std;
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,n1,n2) for(int i=n1;i<n2;i++)
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
typedef pair<int,int> Pi;
typedef long long int ll;
const int INF=(ll)(1<<30)-1;
const ll INFl=(ll)9223372036854775807;
const int MAX=10000;
const ll MOD=(ll)1e9+7;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a, b)*b;}
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};

const int MAX_N=100100;

int par[MAX_N];
int ran[MAX_N];

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

int find(int x){
	if(par[x]==x){
		return x;
	}else{
		return par[x]=find(par[x]);
	}
}

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

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

int n,m;
int p[100100];
int x[100100],y[100100];

vector<int> t[100100];
vector<int> s[100100];

vector<int> r[100100];

int main(){
	cin>>n>>m;
	REP(i,n){
		cin>>p[i];
		p[i]--;
	}
	REP(i,m){
		cin>>x[i]>>y[i];
		x[i]--,y[i]--;
	}
	init(n+1);
	REP(i,m){
		unite(x[i],y[i]);
	}
	
	int ans=0;
	for(int i=0;i<n;i++)
		if(find(i)==find(p[i]))
			ans++;
		
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 9216
#include <iostream>
#include <algorithm>
#include <functional>
#include <cstring>
#include <vector>
using namespace std;

int zen(long int N, long int x, int check3, int check5, int check7){
	if(x > N) return 0;
	int sum = 0;
	if(check3 && check5 && check7) sum++;
	sum += zen(N, x * 10 + 3, 1, check5, check7);
	sum += zen(N, x * 10 + 5, check3, 1, check7);
	sum += zen(N, x * 10 + 7, check3, check5, 1);
	return sum;
}

int main(){
	long int N;
	cin >> N;
	cout << zen(N, 0, 0, 0, 0) << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <limits.h>
#include <stdbool.h>

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

//qsort(str, n, sizeof(int), up_comp);
int up_comp(const void *a, const void *b){return *(int*)a - *(int*)b;}
int down_comp(const void *a, const void *b){return *(int*)b - *(int*)a;}
int int_sort( const void * a , const void * b ) {return strcmp(( char * )a , ( char * )b );}
int count_digit(int a){int i=0;while(a!=0){a=a/10;i++;}return i;}
int euclid( int a, int b ){int temp;if(a<b){temp=a;a=b;b=temp;}if(b<1)return -1;if(a%b==0) return b;return euclid(b,a%b);}

int main(void){
    
    int n, a, b, j;
    int sum=0, ans=0;
    
    scanf("%d%d%d", &n, &a, &b);
    
    for (int i=1; i<=n; i++) {
        sum=0;
        j=i;
        while(j!=0){
            sum+=j%10;
            j=(j-(j%10))/10;
        }
        if (sum>=a&&b>=sum) {
            ans+=i;
        }
    }
    
    printf("%d", ans);
    
    return 0;
}


Measured memory_bytes: 1692
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>

using namespace std;

using ll = long long;

int dp[101][101];

int main()
{
    int h, w;
    cin >> h >> w;
    vector<string> s(h);
    for (int i = 0; i < h; i++) {
        cin >> s[i];
    }

    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            dp[i][j] = 100000;
        }
    }
    dp[0][0] = (s[0][0] == '#' ? 1 : 0) + (s[h - 1][w - 1] == '#' ? 1 : 0) % 2;
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            int dpi = 100000;
            int dpj = 100000;
            if (i > 0) {
                dpi = dp[i - 1][j];
                if (s[i - 1][j] != s[i][j]) {
                    dpi++;
                }
            }
            if (j > 0) {
                dpj = dp[i][j - 1];
                if (s[i][j - 1] != s[i][j]) {
                    dpj++;
                }
            }
            dp[i][j] = min(dp[i][j], min(dpi, dpj));
        }
    }
    int ans = dp[h - 1][w - 1] / 2;
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  
  int X; cin >> X;
  int score = 0;
  
  while(X >= 500){
    score += 1000;
    X -= 500;
  }
  while(X >= 5){
    score += 5;
    X -= 5;
  }
  
  cout << score << endl;
  
}

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


void solve(std::string s){
    s.insert(4, " ");
    cout << s << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools
int main(){
    std::string s;
    std::cin >> s;
    solve(s);
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int a[44];

int fib(int n){
  if(n == 0 || n == 1) return a[n] = 1;
  if(a[n] != 0) return a[n];
  return a[n] = fib(n-1) + fib(n-2);
}

int main(){
  int i,n;
  for(i = 0;i <44;i++) a[i] = 0;

  scanf("%d",&n);
  printf("%d\n",fib(n));

  return 0;
}



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

const int mod = 1e9 + 7;
void upd(int &x,int y){
	x += y;
	if(x >= mod)
		x -= mod;
}

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n,m,k;
	cin>>n>>m>>k;
	if(!n||!m){
		cout<<1<<endl;
		return 0;
	}
	int lev = (n+m-1) / (k-1);
	vector<int> dp(n+1,0);
	dp[0] = 1;
	int ans = 0;
	for(int i=1;i<=lev;i++){
		vector<int> nxt(n+1,0);
		for(int j=0;j<=n;j++)
			for(int l=0;l+j<=n&&l<=k-1;l++)
				upd(nxt[j+l],dp[j]);
		for(int nct=0;nct<=n;nct++){
			int mct = i * (k-1) - nct;
			if(mct <= m - 1 && nct % (k-1) == n % (k-1) && mct % (k-1) == (m-1) % (k-1))
				upd(ans, (nxt[nct]-dp[nct] + mod)%mod);
		}
		dp.swap(nxt);
	}
	cout << ans << endl;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<ll> vl;
typedef vector<pair<ll,ll>> vp;
#define rep(i,n) for(ll i = 0; i < ll(n); i++)
#define MMOD(i) ((i%MOD)+MOD)%MOD;
#define all(v) v.begin() , v.end()
#define vec(i,j) vector<vector<ll>>(i,vector<ll>(j,0))
#define input(v,n) rep(i,n){\
    ll x;\
    cin>>x;\
    v.push_back(x);\
    }
const ll INF=99999999999999;
const ll MOD=1000000007;
const ll MAX_N=100010;
ll a,b,c,d,e,f,x,y,z,k,m,n,l,h,w,t,p,q,ans=0;
vl v,v2,dp(1000);
string s1,s2;
ll solve(){
    return n*n*3;
}
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin>>n;
    cout<<solve()<<endl;

}

Measured memory_bytes: 256
def resolve():
    n = int(input())
    a = list(map(int, input().split()))
    m4 = [ai for ai in a if ai % 4 == 0]
    m2 = [ai for ai in a if ai % 2 == 0 and ai % 4 != 0]
    if 2 * len(m4) + 1 >= n:
        print("Yes")
    elif 2 * len(m4) + len(m2) >= n:
        print("Yes")
    else:
        print("No")


if __name__ == "__main__":
    resolve()


Measured memory_bytes: 63640
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i,a,b) for(ll i=a;i<=b;i++)
#define FORD(i,a,b) for(ll i=a;i>=b;i--)
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) int((a).size())
#define SORT(c) sort((c).begin(),(c).end())
#define PB push_back
#define MP make_pair
#define MEMSET(v, h) memset((v), h, sizeof(v))
#define sqr(x)  ((x) * (x)) 
#define cub(x)  ((x) * (x) * (x))
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
// ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
// ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

void trace(int a[], int N){
  int i;
  FOR(i,0,N-1){
    if(i>0) cout << " ";
    cout << a[i];
  }
  cout << endl;
}

int InsertionSort(int a[], int n){
  FOR(i,1,n-1){
    trace(a,n);
    int v = a[i];
    int j = i-1;
    while(j>=0 && a[j]>v){
      a[j+1] = a[j];
      --j;
    }
    a[j+1] = v;
  }
}

int main(){
  int n; cin >> n;
  int a[n];
  FOR(i,0,n-1) cin >> a[i];
  InsertionSort(a,n);

  FOR(k,0,n-1) {
    if(k!=n-1) cout << a[k] << " ";
    else cout << a[k];
  }
  cout << endl;
}


Measured memory_bytes: 3096
def main():
    n, k = map(int, input().split())
    # d = [None] * k
    a = [None] * k
    ret = [1] * n
    for i in range(k):
        _ = input()
        for _a in map(int, input().split()):
            ret[_a-1] = 0
    print(sum(ret))



if __name__=="__main__":
    main()


Measured memory_bytes: 9180