akhauriyash/Code-Regression huggingface dataset:
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <cstdlib>
#include <cassert>
#include <cstdio>
#include <cmath>
#include <string>
#include <iomanip>
#include <deque>
using namespace std;
#define int long long
int mod = 1000000007;
signed main() {
#ifndef ONLINE_JUDGE
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
#endif
	int n;
	string s, ss;
	cin >> n;
	cin >> s >> ss;
	int ans = 1;
	int p = 0;
	for (int i = 0; i < s.size(); ++i) {
		if (s[i] == ss[i] || i == s.size() - 1) {
			ans *= 3 - p;
			ans %= mod;
			p = 1;
		}
		else {
			if (p == 0) ans *= 6;
			if (p == 1) ans *= 2;
			if (p == 2) ans *= 3;
			ans %= mod;
			p = 2;
			++i;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#define FAST ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#include <bits/stdc++.h>
#define Loop(x, l, r) for(int x = l; x < r; ++x)
#define LoopR(x, l, r) for(int x = r-1; x >= l; --x)
#define all(x) x.begin(), x.end()
#define Kill(x) return cout << x << '\n', 0
#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define F first
#define S second
using namespace std;

const int N = (1 << 18) + 10;
const int W = 100'010;
const int logS = 9;
const int S = 1 << logS;
int dp[S][W];
int v[N]={}, w[N]={};
int n;

void calcDP()
{
    Loop(i,0,W)
        dp[0][i] = 0;

    Loop(i,0,S)
    {
        Loop(j,0,W)
        {
            if(w[i] > j)
                dp[i][j] = dp[i/2][j];
            else
                dp[i][j] = max(dp[i/2][j], dp[i/2][j-w[i]] + v[i]);
        }
    }
}

int get(int u, int W)
{
    if(u < S)
        return dp[u][W];
    if(w[u] > W)
        return get(u/2, W);
    return max(get(u/2, W), get(u/2, W - w[u]) + v[u]);
}

int main()
{
    FAST;
    cin >> n;
    Loop(i,1,n+1)
        cin >> v[i] >> w[i];
    calcDP();
    int t;
    cin >> t;
    while(t--)
    {
        int u, W;
        cin >> u >> W;
        cout << get(u, W) << '\n';
    }
}


Measured memory_bytes: 205736
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
template<class T, class U> void assign(V<T>& v, int n, const U& a) { v.assign(n, a); }
template<class T, class... Args> void assign(V<T>& v, int n, const Args&... args) { v.resize(n); for (auto&& e : v) assign(e, args...); }


int main() {
  cin.tie(nullptr); ios_base::sync_with_stdio(false);
  int a, b; cin >> a >> b;
  cout << (b % a ? b - a : a + b) << '\n';
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#pragma warning (disable : 4996)
#ifdef _WIN32
#define __builtin_popcount __popcnt
#endif
using namespace std;
int n, c, z, a[33], b[33], dp[33][65555];
int main() {
	while (scanf("%d%d", &n, &c), n | c) {
		for (int i = 0; i < n; i++) {
			a[i] = 0;
			for (int j = 0; j < 16; j++) {
				scanf("%d", &z);
				if(z) a[i] += (1 << j);
			}
		}
		a[n] = 0;
		for (int i = 1; i <= c; i++) {
			b[i] = 0;
			for (int j = 0; j < 16; j++) {
				scanf("%d", &z);
				if (z) b[i] += (1 << j);
			}
		}
		for (int i = 0; i <= n; i++) {
			fill(dp[i] + 0, dp[i] + 65536, -999999999);
		}
		dp[0][a[0]] = 0;
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < 65536; j++) {
				if (dp[i][j] == -999999999) continue;
				for (int k = 0; k <= c; k++) {
					dp[i + 1][(j & ~b[k]) | a[i + 1]] = max(dp[i + 1][(j & ~b[k]) | a[i + 1]], dp[i][j] + (int)__builtin_popcount(j & b[k]));
				}
			}
		}
		printf("%d\n", *max_element(dp[n], dp[n] + 65536));
	}
	return 0;
}

Measured memory_bytes: 11140
N = int(input())
A = []
B = []
for i in range(N):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)
tmp = zip(B, A)
B, A = zip(*sorted(tmp))

total = 0
flag = False
for b, a in zip(B, A):
    total += a
    if total > b:
        flag = True
        break
if flag:
    print("No")
else:
    print("Yes")

Measured memory_bytes: 47452
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		String S = sc.nextLine();


		int ans = 0;
		String tmp = S.substring(0,1);
		int index = 1;
		ans++;
		for (int i = 2; i < S.length(); i++) {
			if (! tmp.equals(S.substring(index, i))){
				tmp = S.substring(index,i);
				ans++;
				index=i;
			}
		}

		if(!"".equals(S.substring(index,S.length())) && !tmp.equals(S.substring(index,S.length()))){
			tmp = S.substring(index,S.length());
			ans++;
		}

		System.out.println(ans);
	}
}

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

int main() {
  int n, m, s(0), c(0);
  double eps(1e-6);
  cin >> n >> m;
  int arr[n];
  for (int i = 0; i < n; ++i) {
    cin >> arr[i];
    s += arr[i];
  }
  for (int i = 0; i < n; ++i) {
    if (arr[i] + eps > s / (4.0 * m)) c++;
  }
  cout << (c >= m ? "Yes\n" : "No\n");
  return 0;  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <unordered_set>
using namespace std;
#define ll long long
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repeat(i,s,n) for(int (i)=s; (i)<(n); (i)++)
#define revrep(i,n) for(int (i)=(n)-1;i>=0; i--)

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<setprecision(std::numeric_limits<float>::max_digits10);
  int n,m;
  cin>>n>>m;
  vector<int> A(m);
  vector<int> B(m);
  rep(i,m)cin>>A[i]>>B[i];
  vector<set<int>> G(n+1);
  rep(i,m) {
    G[A[i]].insert(B[i]);
    G[B[i]].insert(A[i]);
  }
  deque<int> dq;
  set<int> s;
  dq.push_back(1);
  s.insert(1);
  while(true) {
    // check
    bool f=true;
    for(auto v : G[dq.front()]) {
      if(s.find(v)==s.end()) {
        f=false;
      }
    }
    for(auto v : G[dq.back()]) {
      if(s.find(v)==s.end()) {
        f=false;
      }
    }
    if(f)
      break;
    for(auto v : G[dq.front()]) {
      if(s.find(v)==s.end()) {
        dq.push_front(v);
        s.insert(v);
        break;
      }
    }
    for(auto v : G[dq.back()]) {
      if(s.find(v)==s.end()) {
        dq.push_back(v);
        s.insert(v);
        break;
      }
    }
  }
  cout << dq.size() << endl;
  for(auto& x: dq) {
    cout << x << " ";
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 20736
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <functional>
#include <limits.h>
#include <set>
#include <map>
#include <tuple>
using namespace std;

#define ll long long
#define ull unsigned long long
#define rep(i,N) for (int i=0;i<N;i++)
#define loop(i,N,M) for(int i=N;i<M;i++)
#define MAX(v) *max_element(v.begin(),v.end())
#define MIN(v) *min_element(v.begin(),v.end())
#define SORTL2S(type,v) sort(v.begin(),v.end(),greater<type>())
#define SORTS2L(type,v) sort(v.begin(),v.end())
#define SORTMF(v,func) sort(v.begin(),v.end(),func)

//変数
ll N;
vector<pair<ll, pair<ll, ll>>> hap;

//解法
void solve() {

	sort(hap.begin(), hap.end(), [](auto& x, auto& y) {return x.first > y.first; });

	ll ans = 0;

	rep(i, N) {
		if (i % 2 == 0) ans += hap[i].second.first;
		if (i % 2 == 1) ans -= hap[i].second.second;
	}

	cout << ans;

	return;
}

int main() {
	//入力

	cin >> N;
	hap.resize(N);

	rep(i, N) {
		ll A, B;
		cin >> A >> B;
		hap[i] = make_pair(A + B, make_pair(A, B));
	}

	solve();
	cout << endl;
	return 0;
}

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

using namespace std;

bool is_left(char c){
  string s = "qwertasdfgzxcvb";
  for(int i=0;i<s.size();i++)
    if(s[i]==c)return true;
  return false;
}

int main(void){

  string s;
  while(cin >> s, s!="#"){
    int cnt = 0;
    for(int i=0;i+1<s.size();i++){
      cnt += is_left(s[i])!=is_left(s[i+1]);
    }
    cout << cnt << endl;
  }
  
  return 0;
}

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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

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

using ll = long long;
using R = long double;
const R EPS = 1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r) {return (r > EPS) - (r < -EPS);}
inline R sq(R x) {return sqrt(max(x, 0.0L));}

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

// Problem Specific Parameter:

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

	vector<int> a(n);
	rep(i, n) cin >> a[i];

	int cmax = 0, idx = 0;
	rep(i, n) {
		if (chmax(cmax, abs(a[i]))) {
			idx = i;
		}
	}

	using pii = pair<int, int>;
	vector<pii> ans;

	rep(i, n) {
		ans.push_back(pii(idx, i));
		a[i] += a[idx];
	}


	if (a[0] > 0) {
		rep(i, n - 1) {
			if (a[i] > a[i + 1]) {
				ans.push_back(pii(i, i + 1));
				a[i + 1] += a[i];
			}
		}
	}

	if (a[0] < 0) {
		rrep(i, n - 1) {
			if (a[i] > a[i + 1]) {
				ans.push_back(pii(i + 1, i));
				a[i] += a[i + 1];
			}
		}
	}

	const int m = ans.size();
	cout << m << endl;
	rep(i, m) cout << ans[i].first + 1 << " " << ans[i].second + 1 << endl;

		
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
int main(){
	int n,s[1001];
	while(1){
		double a=0;
		cin>>n;
		if(n==0)break;
		for(int i=0;i<n;i++){
			cin>>s[i];
			a+=s[i];
		}
		double b=a/n;
		double c=0;
		for(int i=0;i<n;i++){
			c+=pow(b-s[i],2.0);
		}
		double d=0;
		d=sqrt(c/n);
		printf("%.8f\n",d);
	}
	return 0;
}

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

int N, Q, previous[500005], arr[500005];

int fwTree[500005];
pair<int, int> queries[500005], queries2[500005];
vector<tuple<int, int, int> > ans;

void update(int s, int delta)
{
	while(s <= N)
	{
		fwTree[s] += delta;
		s += (s & (-s));
	}
}

void rangeUpdate(int s, int e, int delta)
{
	update(s, delta);
	update(e + 1, -delta);
}

int query(int Li)
{
	int ans = 0;
	while(Li >= 1)
	{
		ans += fwTree[Li];
		Li -= (Li & (-Li));
	}
	
	return ans;
}

void printFw()
{
	for(int i = 1; i <= N; i++)
		printf("%d ", query(i));
	printf("\n");
}

int main()
{
	scanf("%d%d", &N, &Q);
	
	for(int i = 1; i <= N; i++)
	{
		scanf("%d", &arr[i]);
		previous[i] = 0;
	}
	
	for(int i = 1; i <= Q; i++)
	{
		int Li, Ri;
		scanf("%d%d", &Li, &Ri);
		
		queries[i] = make_pair(Ri, Li);
		queries2[i] = queries[i];
	}
	sort(queries + 1, queries + Q + 1);

	int currIdx = 1;
	for(int i = 1; i <= N; i++)
	{
		rangeUpdate(previous[arr[i]] + 1, i, 1);
		previous[arr[i]] = i;
		
		while(currIdx <= Q && queries[currIdx].first < i)
			currIdx++;
			
		while(currIdx <= Q && queries[currIdx].first == i)
		{
			int Li = queries[currIdx].second;
			
			tuple<int, int, int> soln = make_tuple(queries[currIdx].first, queries[currIdx].second, query(Li));
			ans.push_back(soln);
			
			//printf("%d %d %d\n", get<0>(soln), get<1>(soln), get<2>(soln));
			
			currIdx++;
		}
		
		//printf("\n");
	}
	
	for(int i = 1; i <= Q; i++)
	{
		int currIdx = lower_bound(ans.begin(), ans.end(), make_tuple(queries2[i].first, queries2[i].second, -1)) - ans.begin();
		
		printf("%d\n", get<2>(ans[currIdx]));
	}
}

Measured memory_bytes: 23372
#include <iostream>
#include <stack>

using namespace std;

void solve()
{
	stack<int> Stack;
	int Input;
	while(cin >> Input)
	{
		if(Input)
		{
			Stack.push(Input);
		}
		else
		{
			cout << Stack.top() << endl;
			Stack.pop();
		}
	}
}

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

Measured memory_bytes: 0
N, M, Q = map(int, input().split())
abcd = []
for _ in range(Q):
    a, b, c, d = map(int, input().split())
    a -= 1
    b -= 1
    abcd.append((a, b, c, d))

queue = [((1,), 1)]
maxvalue = 0
while queue:
    xs, n = queue.pop()
    if n == N:
        t = 0
        for a, b, c, d in abcd:
            if xs[b] - xs[a] == c:
                t += d
        maxvalue = max(t, maxvalue)
        continue
    for i in range(xs[n - 1], M + 1):
        queue.append((xs + (i,), n + 1))
print(maxvalue)

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

struct UnionFind{
private:
  vector<int> data;
public:
  int N;
  UnionFind(int n) : data(n, -1), N(n){}
  bool unite(int x, int y){
    x = find(x);
    y = find(y);
    if(x == y) return false;
    --N;
    if(data[y] < data[x]) swap(x,y);
    data[x] += data[y];
    data[y] = x;
    return x != y;
  }
  bool same(int x, int y){ return find(x) == find(y); }
  int find(int x){
    if(data[x] < 0) return x;
    return data[x] = find(data[x]);
  }
  int size(int x){ return -data[find(x)]; }
};

int main(){
  int N, M;
  cin >> N >> M;
  UnionFind uf(N);
  for(int i = 0; i < M; ++i){
    int u, v;
    cin >> u >> v;
    --u,--v;
    uf.unite(u,v);
  }
  cout << uf.N - 1 << endl;
}


Measured memory_bytes: 3796
#include <stdio.h>
#include <string.h>

int main(void)
{
  int n;
  int i;
  char s[32];

  while (scanf("%d", &n), n){
    sprintf(s, "%o", n);
    for (i = 0; i < strlen(s); i++){
      if (s[i] >= '4'){
        s[i]++;
      }
      if (s[i] >= '6'){
        s[i]++;
      }
    }
    printf("%s\n", s);
  }
  
  return (0);
}

Measured memory_bytes: 620
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
int main(){
    ll n,x;
    ll cnt=0;
    cin >> n >> x;
    vector<ll> a(n);
    for(ll i=0; i<n; i++){
        cin >> a[i];
    }
    sort(a.begin(),a.end());
    
    for(ll i=0; i<n; i++){
        if(i != n-1){
        if(x >= a.at(i)){
            x -= a.at(i);
            cnt++;
        }
        else break;
        }
        else{
            if(a.at(i) == x) cnt++;
        }
    }
    
    cout << cnt << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define DIM 100007
#define INF 1000000007
using namespace std;

long long a,b,k;
int main()
{
    cin>>a>>b>>k;
    for(int i=1;i<=min((b-a+2)/2,k);++i)
        cout<<a+i-1<<endl;
    for(int i=min((b-a+1)/2,k);i>=1;--i)
        cout<<b-i+1<<endl;
    return 0;
}


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

int main() {
  int N,M;
  cin >> N >> M;
  int A[2*M];
  for (int s=0; s<2*M; s++){
   cin >> A[s];}
  
  for (int k=1; k<=N; k++){  
   int count=0;
   for (int i=0; i<2*M; i++){
    if(A[i]==k){count++;}
   }  
   cout << count << endl;
  }
}

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

using ll = long long;
using ii = pair<int,int>;
using vi = vector<int>;
using vii = vector<ii>;

const ll oo = 1e9+5;

int main() {
    
    int n, k;
    scanf("%d%d",&n,&k);
    
    vector<ll> h(n);
    for(int i = 0; i < n; ++i) {
        scanf("%lld",&h[i]);
    }
    
    vector<ll> dp(n, oo);
    dp[0] = 0;
    
    for(int i = 0; i < n; ++i) {
        for(int j = i+1; j <= i+k && j < n; ++j) {
            dp[j] = min(dp[j], dp[i] + abs(h[i] - h[j]));
        }
    }
    
    printf("%lld\n", dp[n-1]);
    
    return 0;
}




Measured memory_bytes: 1792
(function(input) {
    var p = input.replace(/\n$/, '').split('\n');
    var n = Number(p.shift());
    for (var i = 0; i < p.length; i++) {
        var args = p[i].split(' ').map(Number).sort(function(a, b) {
            return b - a;
        });
        console.log(
            Math.pow(args[0], 2) === Math.pow(args[1], 2) + Math.pow(args[2], 2)
            ? 'YES' : 'NO'
        );
    }
})(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 10456
#include <iostream>
#include <algorithm>
#include <string>
#include <functional> 
#include <vector>
#include <numeric>
#include <stack>
#include <queue>
#include <utility>
#include <map>
#include <cstdlib>
typedef long long ll;
#define fi first
#define se second

using namespace std;

int main(){

    ll q,h,s,d,n;
    cin >> q >> h >>s >> d >> n;

    if(q*4<=2*h && 4*q <= s && 8*q <= d) cout << 4*q*n;
    else if(2*h <= s && 4*h <= d) cout << 2*h*n;
    else if(2*s <= d) cout << s*n;
    else{
        if(n%2 == 0) cout << d*n/2;
        else if(q*4<=2*h && 4*q <= s) cout << (n-1)*d/2 + q*4;
        else if(2*h <= s) cout << (n-1)*d/2 + 2*h;
        else cout << (n-1)*d/2 + s;
    }

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void){
	char s[101];
	int n,i,j,k,max=0;
	scanf("%d %s",&n,s);
	for(i=2;i<n-1;i++){
		char a[27]={0},b[27]={0};
		for(j=0;j<n;j++){
			if(j<i){a[s[j]-'a']=1;}
			else{b[s[j]-'a']=1;}
		}
		int cnt=0;
		for(k=0;k<27;k++){cnt+=a[k]==1&&b[k]==1;}
		if(max<cnt){max=cnt;}
	}
	printf("%d",max);
	return 0;
}

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

void dump(vector<int> d)
{
    rep(i, d.size())
    {
        printf("%d ", d[i]);
    }
    cout << endl;
}

int main()
{
    int N;
    cin >> N;
    vector<int> L(N);
    rep(i, N)
    {
        cin >> L[i];
    }

    // cout << N
    //      << endl;
    // dump(L);
    sort(L.begin(), L.end());
    // dump(L);

    int count = 0;
    rep(a, N)
    {
        for (int b = a + 1; b < N; b++)
        {
            int ab = L[a] + L[b];
            // L[c] < L[a]+L[b]
            int r = lower_bound(L.begin(), L.end(), ab) - L.begin();
            //L[r]以上はダメ
            int l = b + 1;
            //c= [l,r)
            count += max(0, r - l);
            // printf("%d %d %d : %d\n", a, b, r, max(0, r - l));
        }
    }
    cout << count << endl;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

#define MAX_A_NUM 2000
#define MAX_M_NUM 2000

int flags[MAX_A_NUM];

bool check_rec(int n, int a[], int m, int p) {
  if(p == n) {
    int x = 0;
    for(int i=0; i<n; i++) {
      if(flags[i] == 1) {
        x += a[i];
      }
    }
    if(x == m) {
      return true;
    }
    return false;
  }


  if(check_rec(n, a, m, p+1))
    return true;
  flags[p] = 1;
  if(check_rec(n, a, m, p+1))
    return true;
  flags[p] = 0;

  return false;
}

bool check(int n, int a[], int m) {
  for(int i=0; i<n; i++) {
    flags[i] = 0;
  }

  return check_rec(n, a, m, 0);
}

int main() {
  int n, q, m;
  int a[MAX_A_NUM];
  cin >> n;
  for(int i=0; i<n; i++) {
    cin >> a[i];
  }
  cin >> q;
  for(int i=0; i<q; i++) {
    cin >> m;
    if(check(n, a, m)) {
      cout << "yes" << endl;
    } else {
      cout << "no" << endl;
    }
  }
}

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

const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

const string YES = "Yes";
const string NO = "No";

int main(){
    int n;
    cin >> n;
    int k = 1;
    while (k*(k-1)/2 <= n) {
        if (k*(k-1)/2 == n) break;
        ++k;
    }
    if (k*(k-1)/2 > n) cout << NO << endl;
    else {
        vector<vi> s(k);
        int val = 1;
        for (int i=0; i<k; ++i) for (int j=i+1; j<k; ++j) {
            s[i].pb(val); s[j].pb(val);
            ++val;
        }
        cout << YES << endl;
        cout << k << endl;
        rep(i, k) {
            printf("%d ", k-1);
            rep(j, k-1) printf("%d%c", s[i][j], (j<k-2?' ':'\n'));
        }
    }
    return 0;
}


Measured memory_bytes: 4584
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i < (int)(n); i++)
#define Sort(a) sort(a.begin(), a.end())
typedef long long int ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return true;} return false;}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return true;} return false;}

int main(){
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    string ans = "Yes";
    while(1){
        c -= b;
        if(c <= 0){
            break;
        }
        a -= d;
        if(a <= 0){
            ans = "No";
            break;
        }
    }
    cout << ans << endl;
    return 0;
}

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

int main() {
  vector<int>b(5);
  for(int i=0;i<5;i++){
    cin>>b.at(i);
  }
  for(int i=0;i<5;i++){
    if(b.at(0)==0){
      cout<<b.at(1)-1;
      break;
    }
    else if(b.at(i)==0){
      cout<<b.at(0)+i;
    }
  }
}


Measured memory_bytes: 3616
N = int(input())
A = [list(map(int,input().split())) for _ in range(N)]

INF = 10**10
E_list = []
for i in range(N):
    for j in range(i+1,N):
        E_list.append([A[i][j],i,j])
E_list.sort()
B = [[INF]*N for _ in range(N)]
ans = 0
for l,i,j in E_list:
    l_min = INF
    for k in range(N):
        l_min = min(l_min,B[i][k]+B[k][j])
    if l > l_min:
        ans = -1
        break
    elif l < l_min:
        ans += l
    B[i][j] = l
    B[j][i] = l
print(ans)

Measured memory_bytes: 48988
#define	_USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <vector>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cfloat>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <string>
#include <set>
#include <complex>
#include <utility>
#include <numeric>
#define  rep(i,n) for(int i=0;i<(n);i++)
#define  REP(i,a,n) for(int i=a;i<(n);i++)
#define  rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define  VI	vector<int>
#define	 VS vector<string>
#define  all(a) (a).begin(),(a).end()
#define  debug(x) cout<<#x<<": "<<x<<endl
using namespace std;
typedef pair<int,int> P;
typedef long long ll;

const int INF=1000000;
char fi[101][101];
int d[21][21];
int day[12]={31,28,31,30,31,30,31,31,30,31,30,31};
int N,M;
int sx,sy;
int gx,gy;
int w,h;
int ans;

int dx[4]={0,0,-1,1};
int dy[4]={-1,1,0,0};
const int MAX_V=100;
const int MAX_N=100;
char o[3]={'+','-','*'};
#define md 1000003

int dp[353][353]={0};
int bow[353][353]={0};


int main(){
	
	string s;
	int n;
	cin>>n;
	while(n>0){
		cin>>s;
		vector<string> p(10);
		p[1]=".,!? ";
		p[2]="abc";
		p[3]="def";
		p[4]="ghi";
		p[5]="jkl";
		p[6]="mno";
		p[7]="pqrs";
		p[8]="tuv";
		p[9]="wxyz";
		bool f=false;
		char c='0';
		int count=0;
		string a="";
		rep(i,s.size()){
			if(s[i]=='0'){
				if(f){
				if(c=='1'){
					count=(count-1)%5;
				}
				else if(c=='7'||c=='9'){
					count=(count-1)%4;
				}
				else{
					count=(count-1)%3;
				}
				a+=p[c-'0'][count];
				f=false;
				count=0;
				c='0';
				}
			}
			else{
				f=true;
				if(c!=s[i]){
					c=s[i];
					count=1;
				}
				else
					count++;
				
			}
			
		}
		cout<<a<<endl;
		n--;
	}
	
}

Measured memory_bytes: 1216
//quming
#include<bits/stdc++.h>
#define R register
#define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i)
#define fd(i,a,b) for(R int i=(a),I=(b)-1;i>I;--i)
#define go(u) for(int i=head[u],v=e[i].v;i;i=e[i].nx,v=e[i].v)
template<class T>inline bool cmax(T&a,const T&b){return a<b?a=b,1:0;}
template<class T>inline bool cmin(T&a,const T&b){return a>b?a=b,1:0;}
using namespace std;
int a,b;
int main(){
	scanf("%d%d",&a,&b);
	printf("%d\n",max(a-(b<<1),0));
	return 0;
}

Measured memory_bytes: 764
#include <string>
#include <map>
#include <cctype>
#include <iostream>

void wordProcess(std::map<std::string, int> &wordCount,
	std::string &word, std::string &modeWord, std::string &maxLenWord) {
	if (wordCount.find(word) == wordCount.end()) {
		wordCount[word] = 0;
		if (word.length() > maxLenWord.length()) {
			maxLenWord = word;
		}
	}
	++wordCount[word];
	if (wordCount[word] > wordCount[modeWord]) {
		modeWord = word;
	}
}

int main() {
	std::string sentence, word, modeWord, maxLenWord;
	std::map<std::string, int> wordCount;
	std::getline(std::cin, sentence);
	for (std::string::iterator it = sentence.begin(); it != sentence.end(); ++it) {
		if (isspace(*it)) {
			if (!word.empty()) {
				wordProcess(wordCount, word, modeWord, maxLenWord);
			}
			word = "";
		} else {
			word += tolower(*it);
		}
	}
	wordProcess(wordCount, word, modeWord, maxLenWord);
	std::cout << modeWord << ' ' << maxLenWord << '\n';
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
int n,k,r,s,p;
char c[100004];
int dp[100004][3],ans=0;
int main(){
	cin>>n>>k>>r>>s>>p;
	for (int i=1;i<=n;i++) cin>>c[i];
	for (int i=1;i<=n;i++){
		if (i<=k){
			for (int j=0;j<3;j++){
				if (c[i]=='r' && j==2)dp[i][j]=p;
				else if (c[i]=='s' && j==0)dp[i][j]=r;
				else if (c[i]=='p' && j==1)dp[i][j]=s;
				else dp[i][j]=0;
			}
			continue; 
		}
		for (int j=0;j<3;j++){
			if (c[i]=='r' && j==2)dp[i][j]=p+max(dp[i-k][0],dp[i-k][1]);
			else if (c[i]=='s' && j==0)dp[i][j]=r+max(dp[i-k][2],dp[i-k][1]);
			else if (c[i]=='p' && j==1)dp[i][j]=s+max(dp[i-k][0],dp[i-k][2]);
			else{
				for (int l=0;l<3;l++) if (l!=j) dp[i][j]=max(dp[i][j],dp[i-k][l]);
			}
		}
	}
	for (int i=n,j=0;j<k && i>0;j++,i--) ans+=max(max(dp[i][0],dp[i][1]),dp[i][2]);
	cout<<ans;
} 

Measured memory_bytes: 1536
#include <algorithm>
#include <climits>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <vector>

using namespace std;
constexpr long long int INF = std::numeric_limits<long long int>::max();
#define int long long int

void solve() {
  int A, B;
  cin >> A >> B;

  int ans = 0;
  if (A == B) {
    ans = A + B;
  } else {
    ans = max(A, B) * 2 - 1;
  }
  cout << ans << endl;
}

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define sz(x) (int)(x).size()
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<double> vd;
typedef pair<double,double> PD;
typedef pair<int,P> ed;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;
const double eps = 1e-10;
  
int main() {
  int N;
  cin >> N;
  vi c(N),s(N),f(N);
  rep(i,N-1) {
    cin >> c[i] >> s[i] >> f[i];
  }
  vi ans(N);
  rep(i,N-1) {
    int ti = s[i]+c[i];
    srep(j,i+1,N-1) {
      if(ti%f[j]!=0) {
        ti = (ti/f[j] + 1) * f[j];
      }
      ti += c[j];
    }
    ans[i] = ti;
  }
  ans[N-1] = 0;
  drep(i,N-1) {
    chmax(ans[i],ans[i+1]);
  }
  rep(i,N) {
    cout << ans[i] << endl;
  }
  return 0;
}

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

int main(){
    int n;
    cin >> n;
    vector<pair<int,int>> inp;
    vector<vector<int>> tr(n+1);
    vector<int> visited(n+1);
    map<pair<int,int>,int> mp;
    rep(i,n-1){
        int a,b;
        cin >> a >> b;
        inp.push_back({a,b});
        tr.at(a).push_back(b);
        tr.at(b).push_back(a);
    }
    queue<pair<int,int>> q;
    q.push({1,0});
    visited.at(1) = true;
    int mx=0;
    while(q.size()){
        auto p = q.front(); q.pop();
        // cout << p.first << " " << p.second << endl;
        int cl = 1;
        if(cl == p.second) cl++;
        for(int x : tr.at(p.first)){
            if(visited.at(x)) continue;
            
            mp[{p.first,x}] = cl;
            mp[{x,p.first}] = cl;
            visited.at(x) = true;
            q.push({x,cl});
            mx = max(mx,cl);

            cl++;
            if(cl == p.second) cl++;
        }
    }

    cout << mx << endl;
    for(auto p: inp){
        cout << mp[p] << endl;
    }
    return 0;
}

Measured memory_bytes: 19700
#include <iostream>

using namespace std;

int main(void)
{
    char S[5], T[5];

    cin >> S >> T;

    int i, j=0;

    for(i=0; i<3; i++){
	if(S[i] == T[i]){
	    j++;
	}
    }

    cout << j << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define e1 first
#define e2 second
#define pb push_back
#define mp make_pair
#define boost ios_base::sync_with_stdio(false)
#define eb emplace_back
#define OUT(x) {cout << x; exit(0); }
#define REYNA(i,a,b) for(int i=(a);i<(b);++i)
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define scanf(...) scanf(__VA_ARGS__)?:0
typedef long long int ll;
typedef unsigned long long ull;
typedef pair <int, int> PII;
typedef pair <ll, ll> PLL;
typedef pair <PLL, int> PLLI;
typedef pair <PLL, pair <int, ll> > PP;
typedef pair <PII, int> PPI;
typedef pair <int, PII> PIP;
typedef pair <ll, int> PLI;
typedef unsigned int ui;
const int mod = 1e9+7;
const int inf = 1e9+9;
const ll MOD = 1e9+696969;
const long long INF = 1e18+3;
int t;

bool fails(ll pos, ll c)
{
	if (pos > c) return 1;
	return 0;
}

ll mygcd(ll a, ll b)
{
	while (a > 0 && b > 0)
	{
		if (a > b) a = a % b;
		else b = b % a;
	}
	return a + b;
}

bool solve()
{
	ll a, b, c, d;
	cin >> a >> b >> c >> d;
	if (b > d) return 0;
	if (b > a) return 0;
	if (b <= c) return 1; //na pewno sie da
	if (fails(a % b, c)) return 0;
	ll p = mygcd(b, d);
	ll reszta = (a % p);
	if (c >= b - p + reszta%p) return 1;
	return 0;
}

int main()
{
	boost;
	cin >> t;
	while (t--)
	{
		if (solve()) cout << "Yes\n";
		else cout << "No\n";
	}
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<numeric>
#include<queue>
using namespace std;

int main(){
    int n,m;
    cin>>n>>m;
    priority_queue<pair<int,int>> q;
    for(int i=0;i<n;i++){
        int a; cin>>a;
        q.push(make_pair(a,1));
    }
    for(int i=0;i<m;i++){
        int b,c;
        cin>>b>>c;
        q.push(make_pair(c,b));
    }
    long long ans=0;
    for(int i=0;i<n;i++){
        auto p=q.top();
        q.pop();
        ans+=p.first;
        if(p.second>1){
            p.second--;
            q.push(p);
        }
    }
    cout<<ans<<endl;
}

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

using namespace std;

int main()
{
  int M, N;
  string S[100];

  cin >> M >> N;
  for(int i = 0; i < M; i++) {
    cin >> S[i];
  }

  int ret = 0;
  for(int i = 1; i < M; i++) {
    for(int j = 0; j < N; j++) {
      if(S[i][j] != '-') continue;
      if(j > 0 && S[i][j - 1] != '-') continue;
      if(j + 1 < N && S[i][j + 1] != '-') continue;
      bool f = false;
      for(int k = -1; k <= 1; k++) {
        for(int l = -1; l <= 1; l++) {
          int ny = i + k, nx = j + l;
          if(nx < 0 || nx >= N || ny < 0 || ny >= M) continue;
          if(S[ny][nx] == 'x') f = true;
        }
      }
      if(f) continue;
      ++ret;
    }
  }
  cout << ret << endl;
}

Measured memory_bytes: 1228
#include<bits/stdc++.h>
#define ll long long
#define ld long double

using namespace std;

void slove() {
	string s;
	cin >> s;
	for (int i = 0; i < s.size(); i++) {
		if (s[i] == '?') {
			s[i] = 'D';
		}
	}
	cout << s << endl;
}

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


Measured memory_bytes: 3756
#include<stdio.h>
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
int n,i,j,ans=1;
char s[500001];
scanf("%d%s",&n,s);
for(i=1;i<n;i++){
if(s[i-1]!=s[i])
ans++;
}
printf("%d\n",ans);
return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main() {
    int N,ans;cin>>N;
    ans=0;
    vector<int> d(N);
    for(int i=0;i<N;i++){
        cin>>d[i];
    }
    for(int i=0;i<N-1;i++){
        for(int j=i+1;j<N;j++){
            ans=ans+d[i]*d[j];
        }
    }
    cout<<ans;
    return 0;
}

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

#pragma warning(disable:4996)
using namespace std;


struct UnionFind {
	vector<int> data;
	UnionFind(int size) : data(size, -1) { }
	bool unionSet(int x, int y) {
		x = root(x); y = root(y);
		if (x != y) {
			if (data[y] < data[x]) swap(x, y);
			data[x] += data[y]; data[y] = x;
		}
		return x != y;
	}
	int root(int x) {
		return data[x] < 0 ? x : data[x] = root(data[x]);
	}
	int size(int x) {
		return -data[root(x)];
	}
};

int main() {
	int N;cin>>N;
	vector<int>as(N);
	map<int,vector<int>>mp;
	for (int i = 0; i < N; ++i) {
		cin>>as[i];
		mp[as[i]].push_back(i);
	}

	vector<int>sorted_as(as);
	sort(sorted_as.begin(),sorted_as.end());
	UnionFind uf(N);
	for (int i = 2; i <=sqrt(100000); ++i) {
		vector<int>v;
		for (int j = 0; j < N; ++j) {
			if (as[j] % i == 0) {
				v.push_back(j);
			}
		}
		if (v.size() >= 2) {
			for (int j = 0; j < v.size() - 1; ++j) {
				uf.unionSet(v[j],v[j+1]);
			}
		}
	}
	for (auto m : mp) {
		vector<int>v(m.second);
		if(v.size()<=1)continue;
		else {
			for (int i = 0; i < v.size() - 1; ++i) {
				uf.unionSet(v[i],v[i+1]);
			}
		}
	}
	bool ok=true;
	set<int>used;
	for (int i = 0; i < N; ++i) {
		auto lt=lower_bound(sorted_as.begin(),sorted_as.end(),as[i]);
		auto rt=upper_bound(sorted_as.begin(),sorted_as.end(),as[i]);
		if (used.find(as[i]) == used.end()) {

			for (auto it = lt; it != rt; ++it) {
				if (uf.root(it - sorted_as.begin()) ==
					uf.root(i)) {

				}
				else {
					ok=false;
				}
			}
			used.emplace(as[i]);

		}
		else {

		}

	}
	if(ok)cout<<"1"<<endl;
	else cout<<"0"<<endl;
	return 0;
}


Measured memory_bytes: 19612
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int inf = 1e9 + 7;
const ll longinf = 5LL << 60;
const ll mod = 1e9 + 7;

int main() {
	string A, B, C;
	cin >> A >> B >> C;
	if(A[A.size() - 1] == B[0] && B[B.size() - 1] == C[0])
		cout << "YES";
	else
		cout << "NO";
	return 0;
}


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

string S;
string x = "CODEFESTIVAL2016";
int main(){
  cin >> S;
  int res = 0;
  for(int i=0;i<(int)S.size();i++)
    if( S[i] != x[i] ) res++;
  cout << res << endl;
}


Measured memory_bytes: 764
#include <stdio.h>

int main() {
  char current;
  int letters[26];
  memset(letters, 0, sizeof(letters));

  while (1) {
    if (scanf("%c", &current) == EOF)
      break;

    if (current == 44 || current == 46)
      continue;

    if (current > 96)
      letters[current - 97]++;
    else
      letters[current - 65]++;
  }

  int i;

  for (i = 0; i < 26; i++) {
    printf("%c : %d\n", i + 97, letters[i]);
  }

  return 0;
}




Measured memory_bytes: 2040
#include <iostream>
#include <string>
#include <vector>
#include <climits>
#include <set>
#include <algorithm>
#include <unordered_map>
#include <queue>
#include <iomanip>
#include <map>
#include <utility>
#include <numeric>

#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define P pair<int, int>
#define debug(x) cout << #x << ": " << x << ", "
#define debugln(x) cout << #x << ": " << x << '\n'

using namespace std;
using ll = long long;
const int mod = 1e9+7;

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

  unordered_map<int, int> mp;
  rep(i, 3) {
    int a; cin >> a;
    mp[a]++;
  }
  for(auto e: mp) {
    if (e.second == 1) {
      cout << e.first << endl;
    }
  }
}

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

int main()
{
  int n;
  long long K;
  scanf("%d%lld",&n,&K);
  static char s[200010];
  scanf("%s",s);
  int x=0,p=0;
  while(x<n&&K>0){
    if(s[x]=='A'+p){
      s[x]='A'+!p;
    }
    else{
      x++;
      p=!p;
    }
    K--;
  }
  if(x==n&&n%2==1&&K%2==1){
    for(int i=0;i<n;i++){
      putchar('A'+(i==0||i%2==1?1:0));
    }
  }
  else{
    for(int i=x;i<n;i++){
      putchar('A'+((s[i]=='A')==p));
    }
    for(int i=0;i<x;i++){
      putchar('A'+((x-i)%2==0));
    }
  }
  putchar('\n');
  return 0;
}


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

int main(){
  int n;
  cin>>n;
  string s;
  long long int a[5]={};
  string march="MARCH";
  for(int i=0;i<n;i++){
    cin>>s;
    
    for(int j=0;j<5;j++)
      if(s.at(0)==march[j])
        a[j]++;
    
  }
  long long int ans=0;
 
  for(int i=0;i<3;i++)
    for(int j=i+1;j<4;j++)
      for(int k=j+1;k<5;k++){
        ans+=a[i]*a[j]*a[k];
       
      }
      
  
  cout<<ans;
  return 0;
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
const int N=200050;
using namespace std;
inline int gi(){
  char ch=getchar();int x=0,q=0;
  while(ch<'0' || ch>'9') ch=='-'?q=1:0,ch=getchar();
  while(ch>='0' && ch<='9') x=x*10+ch-'0',ch=getchar();
  return q?(-x):x;
}
int t[N],f[N],p[N],st[N],vis[N],cnt,tot,nxt[N],head[N],in[N];
int F(int x){
  ++cnt;
  for (int i=head[x]; i; i=nxt[i])
    t[f[i]]=cnt;
  for (int i=0; ; ++i)
    if (t[i]!=cnt)
      return i;
}
void dfs(int x){
  for (int i=head[x]; i; i=nxt[i])
    dfs(i);
  f[x]=F(x);
}
int main(){
  int n=gi();
  for (int i=1; i<=n; ++i)
    p[i]=gi();
  int k;
  for (k=1; !vis[k]; vis[k]=1,k=p[k]);
  in[st[++tot]=k]=1;
  for (int i=p[k]; i!=k; i=p[i])
    in[st[++tot]=i]=1;
  for (int i=1; i<=n; ++i)
    if (!in[i])
      nxt[i]=head[p[i]],head[p[i]]=i;
  for (int i=1; i<=tot; ++i)
    dfs(st[i]);
  int a=f[st[tot]],b=a+1;
  while(t[b]==cnt) ++b;
  for (int i=1; i<=tot; ++i)
    nxt[st[i]]=head[p[st[i]]],head[p[st[i]]]=st[i];
  f[st[tot]]=a;
  for (int i=1; i<tot; ++i) f[st[i]]=F(st[i]);
  if (f[st[tot-1]]!=a) return puts("POSSIBLE"),0;
  f[st[tot]]=b;
  for (int i=1; i<tot; ++i) f[st[i]]=F(st[i]);
  if (f[st[tot-1]]==a) return puts("POSSIBLE"),0;
  puts("IMPOSSIBLE");
  return 0;
}


Measured memory_bytes: 6400
using System;
using System.Collections.Generic;
using System.Linq;
 
static class MainClass {

  public static void Main (string[] args) {
    //var temp = Console.ReadLine().Split(' ').Select(long.Parse);
    var S = Console.ReadLine().ToCharArray().ToList();
    var ans = "WA";
   
    var count = 0;
    S.ForEach(c => {if(char.IsUpper(c)) count++; });

    if(S[0] == 'A' && 1 < S.IndexOf('C') && S.IndexOf('C') < S.Count() - 1 && count == 2){
       ans = "AC";
    }

    Console.WriteLine(ans);

  }
  
}

Measured memory_bytes: 13280
#include <stdio.h>

int main(void) {
	char s[200005] = { 0 };
	char t[200005] = { 0 };

	int n = 0;

	scanf("%s", s);
	scanf("%s", t);

	for (int i = 0; s[i] != 0; i++) {
		if (s[i] != t[i]) {
			n++;
		}
	}
	
	printf("%d", n);

	return 0;
}

Measured memory_bytes: 2540
/*
  A - Three-letter acronym
  Contest 059
  Rakesh Kumar --> 24/08/2020
 */

#include <bits/stdc++.h>

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

    std::string s;
    std::getline(std::cin, s);
    std::istringstream iss(s);
    std::string t;
    while (iss >> t)
        std::cout << static_cast<char>(t[0] - 32);
    std::cout << std::endl;

    return 0;
}


Measured memory_bytes: 3584
#include<map>
#include<set>
#include<list>
#include<cmath>
#include<queue>
#include<stack>
#include<cstdio>
#include<string>
#include<vector>
#include<complex>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<numeric>
#include<sstream>
#include<iostream>
#include<algorithm>
#include<functional>

#define MP make_pair
#define PB push_back
#define ALL(x) (x).begin(),(x).end()
#define REP(i,n) for(int i=0;i<(n);i++)
#define REP1(i,n) for(int i=1;i<(n);i++)
#define REP2(i,d,n) for(int i=(d);i<(n);i++)
#define RREP(i,n) for(int i=(n);i>=0;i--)

using namespace std;

int reverse_coin(int c){
    int cnt=0;
    while(1){
        if(c == 0){
            break;
        }
        if(500 <= c){
            c-=500;
            cnt++;
        }else if(100 <= c){
            c-=100;
            cnt++;
        }else if(50 <= c){
            c-=50;
            cnt++;
        }else if(10 <= c){
            c-=10;
            cnt++;
        }
    }
    return cnt;
}
int main(){
    int n,ju,goju,hya,gohya;
    bool firstcase=true;
    while(cin >> n&&n){
        if(firstcase){
             firstcase = false;
        }else{
             cout << endl;
        }
        int a=0,b=0,c=0,d=0,e=0;
        int max=10000;
        cin >> a >> b >> c >> d;
        e=a+b+c+d;
        for(int i=0;i<=a;i++){
            for(int j=0;j<=b;j++){
                for(int k=0;k<=c;k++){
                    for(int l=0;l<=d;l++){
                        if(n <= i*10+j*50+k*100+l*500){
                            int c = i*10+j*50+k*100+l*500 - n;
                            if(max > e+reverse_coin(c)-i-j-k-l){
                                max = e+reverse_coin(c)-i-j-k-l;
                                ju = i;
                                goju = j;
                                hya = k;
                                gohya = l;
                            }
                        }
                    }
                }
            }
        }
        if(ju > 0){
            cout << "10 " << ju << endl;
        }
        if(goju > 0){
            cout << "50 " << goju << endl;
        }
        if(hya > 0){
            cout << "100 " << hya << endl;
        }
        if(gohya > 0){
            cout << "500 " << gohya << endl;
        }
        
    }
    return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
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(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s; cin>>s;
    int ans1=0, ans2=0;

    for(int i=0; i<s.length(); i++){
        if(i%2==0) {
            if(s[i]=='0'){
                ans1++;
            }else {
                ans2++;
            }
        }else {
            if(s[i]=='1'){
                ans1++;
            }else {
                ans2++;
            }
        }
    }
    cout << min(ans1, ans2) << endl;
}

Measured memory_bytes: 512
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<queue>
#include<algorithm>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int flag=0;
    while(n){
        int t=n%10;
        if(t==9) flag=1;
        n/=10;
    }
    if(flag) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <algorithm>

using namespace std;

int main()
{
	int a[3];

	cin >> a[0] >> a[1] >> a[2];

	sort(a, a + 3);

	cout << a[0] << " " << a[1] << " " << a[2] << endl;

	return 0;
}

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

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

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


    //start from here

    readb(k, n);
    readarr(a, n);

    int flag[1000001] = {}; vi vec;
    fori(i, 1, n)
    {
    	if(!flag[a[i]]) {vec.pb(a[i]); flag[a[i]] = 1;}
    }

    sort1(vec);
    if(vec.size() == 1) cout << 0;

    int mx = 0;

    fori(i, 1, sz(vec)-1) mx = max(mx, vec[i]-vec[i-1]);

	mx = max(mx, k-vec[sz(vec)-1]+vec[0]);

    cout << k-mx;
    return 0;
}


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

int main() {
    int x;
    for(int i = 0; i < 10000; i++){
        cin >> x;
        if(x == 0)break;
        cout << "Case" << " ";
        cout << i+1 << ":";
        cout << " " << x;
        cout << endl;
    }
}


Measured memory_bytes: 3016
//Robs Code

/***********HEADER***************/
#include <iostream>
#include <bitset>
#include <deque>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <string>
#include <algorithm>
#include <list>
#include <vector>
#include <unordered_set>
#include <unordered_map>
#include <stack>
#include <set>
#include <queue>
#include <map>
#include <iomanip>

/***********MACROS***************/
#define int long long int
#define all(x) x.begin(),x.end()
#define allr(x) x.rbegin(),x.rend()
#define endl "\n"
#define pb push_back
#define _1 first
#define _2 second
#define pii pair<int,int>

using namespace std;

const int N = 1e5 + 1;
int n,m,i,j,k,l,x,y,z,cnt[3],sum[3];

/***********MAIN**************/
signed main(){
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	cin >> k;
	int sum = 0;
	for(int i = 1;i <= k;i++){
		sum = (sum*10 + 7)%k;
		if(sum == 0){
			cout << i;
			return 0;
		}
	}
	cout << "-1";
}
//.........

Measured memory_bytes: 3648
x = list(map(int,input().split(" ")))
n,m = x

# A = [int(input()) for _ in range(3)]

m_list = [n] * m
# print(m_list)

for i in range(n):
    ka = list(map(int,input().split(" ")))
    # print(ka)
    k = int(ka[0])
    # print(k)
    for j in range(k):
        m_list[ka[j+1]-1] -= 1
        # print(m_list)
# print(m_list)
count0 = m_list.count(0)
print(count0)

Measured memory_bytes: 3064