akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int main(){
    int N,M;
    cin >> N >> M;
    int cnt[M]={0};
    for (int i=0;i<N;++i){
        int K;
        cin >> K;
        for (int j=0;j<K;++j){
            int tmp;
            cin >> tmp;
            ++cnt[tmp-1];
        }
    }
    int ans=0;
    for (int i=0;i<M;++i){
        if(cnt[i]==N) ++ans;
    }

    cout << ans << endl;

}





Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define lld long double
#define MOD 1000000007
#define CAP 10000000
#define inf 1000000000000000000LL
#define pii pair<ll,ll>
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define endl '\n'
#define all(v)    v.begin(),v.end()
#define fast  ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
using namespace std;
ll power(ll x,ll y, ll md=MOD){ll res = 1;x%=md;while(y>0){if(y&1)res = (res*x)%md;x = (x*x)%md;y = y>>1;}return res%md;}
#define dbg(x) cout <<#x<<":"<<x<<endl;
ll max1(ll a, ll b, ll c=-inf, ll d=-inf) {ll mx1=(a>b)?a:b, mx2=(c>d)?c:d; return ((mx1>mx2)?mx1:mx2);}
#define int ll

struct node {
	vector<int> v,w;
};

signed main() {
	fast;

	int n;
	cin>>n;

	for(int i=1;i<10;i++) {
		for(int j=1;j<10;j++) {
			if(i*j==n) {
				cout<<"Yes";
				return 0;
			}
		}
	}
	cout<<"No";
}

Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author Hamadneh
 */

#include <bits/stdc++.h>

using namespace std;

class BDistance {
public:
    void solve(istream &in, ostream &out) {
        int64_t N, D;
        in >> N >> D;
        int64_t c = 0;
        for (int i = 0; i < N; i++) {
            int64_t x, y;
            in >> x >> y;
            if (sqrt((x * x) + (y * y)) <= double(D))
                c++;
        }
        out << c;
    }
};


int main() {
    BDistance solver;
    std::istream &in(std::cin);
    std::ostream &out(std::cout);
    solver.solve(in, out);
    return 0;
}


Measured memory_bytes: 3676
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <regex>
#define rep(i,n) for(int i = 0; i < n; i++)
#define reps(i,j,n) for(int i = j; i < n; i++)
#define rrep(i,j,n) for(int i = j-1; i >= n; i--)
#define prec(n) fixed << setprecision(n)
#define print_array(v) rep(__k, v.size()) { cout << v[__k]; if(__k != v.size()-1) cout << " "; else cout << endl; }
#define YesorNo(a) printf(a?"Yes\n":"No\n")
#define fi first
#define se second
#define endl "\n"
using namespace std;

constexpr int inf = 2147483647;
constexpr int64_t inf64 = 9223372036854775807;
constexpr int mod = 1e9+7;

vector<pair<int64_t, int64_t> > factor;

void prime_factorize(int64_t n) {
  for (int64_t a = 2; a * a <= n; ++a) {
  if (n % a != 0) continue;
    int64_t ex = 0;
    while (n % a == 0) {
      ex++;
      n /= a;
    }
    factor.push_back({a, ex});
  }
  if (n != 1) factor.push_back({n, 1});
  return;
}


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

  int64_t n;
  cin >> n;

  int64_t res = 0;
  prime_factorize(n);
  for(auto p : factor) {
    int64_t ex = p.second;
    int64_t tmp = 0, cur = 1;
    while (ex >= cur) ex -= cur++, tmp++;
    res += tmp;
  }

  cout << res << endl;
  return 0;
}

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

const int MAXN = 1010;
const int MOD = 1e9 + 7;

char entrada[MAXN][MAXN];
int dp[MAXN][MAXN],vis[MAXN][MAXN];
int N,M;

int solve(int x,int y){

	if(x >= N || y >= M) return 0;
	if(entrada[x][y] == '#') return 0;

	if(vis[x][y]) return dp[x][y];
	if(x == N - 1 && y == M - 1) return dp[x][y] = 1;

	vis[x][y] = 1;
	return dp[x][y] = (solve(x+1,y) + solve(x,y+1)) % MOD;

}

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

	cout<<solve(0,0)<<endl;

	return 0;
}

Measured memory_bytes: 12400
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr long long MOD = 1000000007;
constexpr long long INF = 1LL << 60;
const long double PI = acosl(-1.0);
constexpr long double EPS = 1e-11;
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(){
    ll n;
    cin >> n;
    ll dp[100002];
    dp[0] = 0;
    for (ll i = 1; i <= 100001;i++){
        dp[i] = INF;
        ll power = 1;
		while(i>=power){
            chmin(dp[i], dp[i - power] + 1);
            power *= 6;
        }
        power = 1;
		while(i>=power){
            chmin(dp[i], dp[i - power] + 1);
            power *= 9;
        }
    }
    cout << dp[n] << endl;
}

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

int main(){
  while(1){
    int H,W;
    cin>>H>>W;
    if(H == 0 && W == 0) break;

    for (int i=0;i<H;i++){
      for(int j=0;j<W;j++){
	if((i + j) %2 == 0) cout<<"#";
	else cout<<".";
      }
      cout<<endl;
    }

    cout<<endl;
  }
  return 0;
}
 



Measured memory_bytes: 3100
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
long long mo = 1e9 + 7;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }

int main(){
    ll K,A,B;
    string S;
    cin >> K>>A>>B;
    REP(i,A,B+1){
        if(i%K==0){
            cout <<"OK"<<endl;
            return 0;
        }
    }
    cout << "NG" <<endl;
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  float ans=0;
  vector<float> A(n);
  for(int i=0;i<n;i++){
    cin>>A[i];
    ans+=1/A[i];
  }
  cout<<fixed<<setprecision(12)<<1/ans<<endl;
}

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

int main() {
  
  int a, b, c, d, e;
  cin >> a >> b >> c >> d >> e;
  
  if (a == 0) cout << 1;
  if (b == 0) cout << 2;
  if (c == 0) cout << 3;
  if (d == 0) cout << 4;
  if (e == 0) cout << 5;
  
}


Measured memory_bytes: 3560
N = int(input())

a = []
while N % 2 == 0:
    a.append(2)
    N //= 2

f = 3
while f * f <= N:
    if N % f == 0:
        a.append(f)
        N //= f
    else:
        f += 2
if N != 1:
    a.append(N)

b = []
x = 0

for i in range(len(a)):
    if i == 0:
        b.append(1)
    elif a[i-1] == a[i]:
        b[x] += 1
    else:
        x += 1
        b.append(1)

count = 0

for i in range(len(b)):
    j = 1
    while b[i] > 0:
        if (b[i] - j) >=0:
            count += 1
        b[i] = b[i] - j
        j += 1

print(count)


Measured memory_bytes: 9240
//AtCoder 
#include <bits/stdc++.h>
using namespace std;
using ll=int64_t;

vector<ll> vtbl(4);
vector<ll> ans;
ll search(int i, bool minus, vector<ll> tbl){
    if(i >= vtbl.size()){
        ll sum=0;
        for(const auto& t:tbl){
            sum+=t;
        }
        if (sum==7){
            //ans
            ans=tbl;
            return 1;
        }
        return 0;
    }

    ll v=minus?-vtbl[i]:vtbl[i];
    tbl[i]=v;
    if(search(i+1, false, tbl)){
        return 1;
    }
    if(search(i+1, true, tbl)){
        return 1;
    }
    return 0;
}
int main() {
#if LOCAL&0
    std::ifstream in("input.txt");
    std::cin.rdbuf(in.rdbuf());
#endif
    string S;
    cin>>S;
    for(int i=0;i<S.length();++i){
        vtbl[i] = S[i]-'0';
    }

    search(0,false,vtbl);
    for(ll i=0;i<ans.size();++i){
        if(i==0)cout<<ans[i];
        else {
            cout<<(ans[i]>=0?"+":"")<<ans[i];
        }
    }
    cout<<"=7"<<endl;
    return 0;
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int,input().split()))
Q = int(input())
Dict = {}
for i in A:
    if i not in Dict:
        Dict[i] = 1
    else:
        Dict[i]+=1
ans = sum(A)
for i in range(Q):
    B, C = map(int,input().split())
    if B in Dict and Dict[B]!=0:
        b = Dict[B]
        Dict[B]=0
        if C not in Dict:
            Dict[C]=0
        Dict[C]+=b
        
        ans+=(C-B)*b
    print(ans)

Measured memory_bytes: 83404
using System;
using System.Collections.Generic;
using System.Text;
using System.Numerics;
using System.IO;

namespace SolutionCS
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            string[] s = Console.ReadLine().Split(' ');

            bool found = false;
            int ans = 0;
            int target = 1;

            for (int i = 0; i < s.Length; i++)
            {
                if(int.Parse(s[i]) != target)
                {
                    ans++;
                }
                else
                {
                    target++;
                    found = true;
                }
            }

            if(!found)
            {
                ans = -1;
            }

            Console.WriteLine(ans);
        }
    }
}



Measured memory_bytes: 30300
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
#define chmax(x, y) { x = max(x, y); }
#define chmin(x, y) { x = min(x, y); }

int main() {
    int n, x, t;
    cin >> n >> x >> t;
    int xinit = x;
    int tinit = t;
    while(x < n){
        x += xinit;
        t += tinit;
    }
    cout << t << endl;
    return 0;
}

Measured memory_bytes: 3612
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

public class Main {
	public static void main(String[] args) {
		FastScanner sc = new FastScanner();

		int A = Integer.parseInt(sc.next());
		int B = Integer.parseInt(sc.next());
		int C = Integer.parseInt(sc.next());
		int K = Integer.parseInt(sc.next());
		int sum,num;
		int max;

		max = Math.min(A, K);
		if(0 < K - A - B) {
			max += Math.min(C, K - A - B) * -1;
		}

		System.out.print(max);
	}

}

class FastScanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;
	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		}else{
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}
	private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
	private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
	public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
	public String next() {
		if (!hasNext()) throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while(isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}
}

Measured memory_bytes: 32344
#include <bits/stdc++.h>
using namespace std;
#define int long long
int n,a[88],dp[88];
signed main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
	}
	dp[0]=1000;
	for(int i=1;i<=n;i++)
	{
		dp[i]=dp[i-1];
		for(int j=1;j<i;j++)
		{
			int tmp=dp[j-1]/a[j];
			dp[i]=max(dp[i],tmp*a[i]+dp[j-1]%a[j]);
		}
	}
	cout<<dp[n]<<endl;
	return 0;
}

Measured memory_bytes: 3592
n = int(input())
nn = pow(2, n)

k = list(map(int, input().split()))
mask = k[1:k[0]+1]

if k[0] == 0:
    for i in range(nn):
        if i == 0:
            print("0:")
        else:
            bin_str = "0" + str(n) + "b"
            bin_i = format(i, bin_str)
            ilist = list(bin_i)
            tmplist = []
            for j, bini in enumerate(ilist):
                if bini == '1':
                    tmplist.append(n - j - 1)
            tmplist.sort()
            tmp_str = ' '.join(str(tmp) for tmp in tmplist)
            print(str(i) + ": " + tmp_str)

else:
    for i in range(nn):
        if i == 0:
            continue
        bin_str = "0" + str(n) + "b"
        bin_i = format(i, bin_str)
        ilist = list(bin_i)
        tmplist = []
        for j, bini in enumerate(ilist):
            if bini == '1':
                tmplist.append(n - j - 1)
        if len(set(mask) & set(tmplist)) == k[0]:
            tmplist.sort()
            tmp_str = ' '.join(str(tmp) for tmp in tmplist)
            print(str(i) + ": " + tmp_str)



Measured memory_bytes: 5732
#include <algorithm>
#include <iostream>

using namespace std;

int main()
{
    while (true) {
        int n;
        cin >> n;
        if (n == 0) {
            break;
        }

        int sum{0};
        int max_{-1};
        int min_{10000};
        for (int i = 0; i < n; ++i) {
            int s;
            cin >> s;
            sum += s;
            max_ = max(max_, s);
            min_ = min(min_, s);
        }
        cout << ((sum - max_ - min_) / (n - 2)) << endl;
    }
}

Measured memory_bytes: 3072
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     @hamayanhamayan0
　　　　／　　　＼　 　  |　|
　　　 /　　 /￣￣￣￣/　　|
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿
　 　　　＼/＿＿＿＿/　（u　⊃
---------------------------------------------------------------------------------------------------*/














int K, Q, D[5010];
int DD[5010];
//---------------------------------------------------------------------------------------------------
void _main() {
	cin >> K >> Q;
	rep(i, 0, K) cin >> D[i];
	rep(_, 0, Q) {
		int N, X, M; cin >> N >> X >> M;

		rep(k, 0, K) {
			DD[k] = D[k] % M;
			if (DD[k] == 0) DD[k] = M;
		}
		X %= M;

		ll tot = 0;
		rep(k, 0, K) tot += DD[k];
		
		ll start = X;
		ll end = X;

		N--;
		end += 1LL * (N / K) * tot;
		rep(i, 0, (N%K)) end += DD[i];

		ll ng = end / M - start / M;
		ll ans = N - ng;
		printf("%lld\n", ans);
	}
}







Measured memory_bytes: 384
#include<iostream>
#include<vector>
#include<algorithm>
#define Fast ios_base :: sync_with_stdio(false), cin.tie(0), cout.tie(0)
using namespace std;
int main() {
    Fast;
    int n;
    cin >> n;
    vector<int> stairs;
    int i;
    for(i=0; i<n; i++){
        int x;
        cin >> x;
        stairs.push_back(x);
    }
    bool ok = true;
    int h = stairs[0];
    for(i=1; i<n; i++){
        if(stairs[i]<(h-1)){
            ok = false;
            break;
        }
        else{
            h = max(h, stairs[i]);
        }
    }
    /*for(i=1; i<n; i++){
        if(stairs[i]<stairs[i-1]){
            ok = false;
            break;
        }
    }*/
    if(ok) cout << "Yes\n";
    else cout << "No\n";
    return 0;
}

Measured memory_bytes: 3896
#include <iostream>
#include <cstdint>

using ::std::uint8_t;
using ::std::uint16_t;
using ::std::uint32_t;

bool is_prime(uint32_t n)
{
	/* 0 ～ 3 は個別に判定しておく */
	if (n < 2)
	{
		/* 0, 1 は素数ではない */
		return false;
	}
	if (n < 4)
	{
		/* 2, 3 は素数 */
		return true;
	}

	/* 5以上の整数において、6で割った余りが 1 と 5 以外は素数ではない */
	uint32_t remain = n % 6;
	if( remain != 1 && remain != 5 )
	{
		return false;
	}
	
	/* 合成数nはp≦√nを満たす素因子pを持つ → nの平方根の値まで試し割すれば判定できる */
	for (uint32_t i = 5; i*i <= n; i+=6)
	{
		if( (n %  i    == 0) ||	/* 6n-1 (6で割った余りが5の値) */
			(n % (i+2) == 0) )	/* 6n+1 (6で割った余りが1の値) */
		{
			return false;
		}
	}
	
	return true;
}

int main(void)
{
	int prime_counter = 0;
	int num_of_questions;
	uint32_t n;
	
	std::cin >> num_of_questions;
	for (int i = 0; i < num_of_questions; ++i)
	{
		std::cin >> n;
		if (is_prime(n))
		{
			++prime_counter;
		}
	}
	
	std::cout << prime_counter << std::endl;

	return 0;
}



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

int64_t MOD = 1000000007;
int64_t MAX = 9223372036854775807;
double PI = 3.141592653589793;

int main()
{
    map<char, char> list;
    list['A'] = 'T', list['T'] = 'A', list['C'] = 'G', list['G'] = 'C';
    char x;
    cin >> x;
    cout << list[x];
}

Measured memory_bytes: 256
N = int(input())
# N = int(input())
A = list(map(int, input().split()))


ans = 0

d1 = {}
d2 = {}
for i in range(N):
    if i+1 + A[i] in d1:
        d1[i+1 + A[i]] += 1
    else:
        d1[i+1 + A[i]] = 1
    if i+1 - A[i] in d2:
        d2[i+1 - A[i]] += 1
    else:
        d2[i+1 - A[i]] = 1


for a in d1.keys():
    if a in d2:
        # print(d2[a])
        ans += d2[a]*d1[a]


# print(d1)
# print(d2)
print(ans)




Measured memory_bytes: 56760
#include <iostream>

using namespace std;

int main() {
	int r, c;
	cin >> r >> c;
	int A[110][110] = {0};

	for(int i = 0; i < r; i++) {
		for(int j = 0; j < c; j++) {
			int num;
			cin >> num;
			A[i][j] = num;
		}
	}

	//計算処理
	for(int i = 0; i < r; i++) {
		for(int j = 0; j < c; j++) {
			A[r][c] += A[i][j];
			A[i][c] += A[i][j];
			A[r][j] += A[i][j];
		}
	}

	//最後の表示
	for(int i = 0; i <= r; i++) {
		for(int j = 0; j <= c; j++) {
			if(j == c) cout << A[i][j]; 
			else cout << A[i][j] << ' ';
		}
		cout << endl;
	}

	return 0;
}


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

#define dforsn(i,s,n) for(int i=int(n-1);i>=int(s);i--)
#define forsn(i,s,n) for(int i=int(s);i<int(n);i++)
#define dforn(i,n) for(int i=int(n-1);i>=0;i--)
#define forn(i,n) for(int i=0;i<int(n);i++)
#define D(a) cerr << #a << " = " << a << endl
#define all(a) a.begin(),a.end()
#define si(a) int((a).size())
typedef pair<int,int> pii;
typedef long long int ll;
typedef vector<int> vi;
#define pb emplace_back
#define mp make_pair
#define snd second
#define fst first

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0);
    
    int n; cin >> n, n %= 10;
    string ans = "hon";
    if (n == 3) ans = "bon";
    else if (n == 0 || n == 1 || n == 6 || n == 8) ans = "pon";
    cout << ans << endl;
    return 0;
}


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

int main(){
    string s; cin >> s;
    int n = s.length();
    int I_A,I_Z;
    rep(0,i,n){
        if(s[i]=='A'){
            I_A = i+1;
            break;
        } 
    }
    reverse(s.begin(),s.end());
    rep(0,i,n){
        if(s[i]=='Z'){
            I_Z = n-i;
            break;
        }
    }

    cout << I_Z - I_A + 1 << endl;
}

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

int main(){
    int A, B, C; cin >> A >> B >> C;
    int mx = max({A, B, C});
    //max関数を使うには、{}でくくってリスト構造の中に入れる
    int ans  =  A + B + C + 9 * mx;
    cout << ans << endl;
    return 0;
}

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

using namespace std;

int main(){
    int N,K,Q;
    cin >> N >> K >> Q;
    vector<int> A(N);
    for(int i=0;i<Q;i++){
        int a;
        cin >> a;
        A[a-1]++;
    }

    for(int i=0;i<N;i++){
        if(0<K-Q+A[i]){
            cout << "Yes" << endl;
        }else{
            cout << "No" << endl;
        }
    }
}

Measured memory_bytes: 1024
#include <algorithm>
#include <iostream>
#include <string>
#include <random>
#include <cassert>
#include <cstring>
#include <chrono>
#include <set>
#include <map>

using namespace std;

typedef long long ll;

const int inf = 1000 * 1000 * 100;

int main()
{
  int N, M, n, m;
  cin >> N >> M >> n >> m;
  if (N % n == 0 && M % m == 0) {
    cout << "No\n";
    return 0;
  }
  cout << "Yes\n";
  for (int i = 0; i < N; ++i) {
    for (int j = 0; j < M; ++j) {
      int cur = 0;
      if (M % m != 0) {
        if (i % n == 0) {
          if (j % m == 0) cur = inf;
          if ((j + 1) % m == 0) cur = -inf - 1;
        }
      } else {
        if (j % m == 0) {
          if (i % n == 0) cur = inf;
          if ((i + 1) % n == 0) cur = -inf - 1;
        }
      }
      if (j > 0) cout << " ";
      cout << cur;
    }
    cout << endl;
  }
  return 0;
}


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

using namespace std;

int zeller(int Y, int M, int D)
{
    if (M < 3) {
	Y--;
	M += 12;
    }
    return (Y+Y/4-Y/100+Y/400+(13*M+8)/5+D)%7;
}

int main()
{
    const string w[] = {
        "Sunday",
        "Monday",
        "Tuesday",
        "Wednesday",
        "Thursday",
        "Friday",
        "Saturday",
        "Sunday"
    };
        
    int M, D;
    while (cin >> M >> D, M) {
        cout << w[zeller(2004, M, D)] << endl;
    }
    return 0;
}

Measured memory_bytes: 3152
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
#include <list>
#include <stack>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#define mkp(a, b) make_pair(a, b)
#define pb(t) push_back(t)
#define ft first
#define sc second
#define pt(num) cout << num << "\n"
#define moC(a, s, b) (a)=((a)s(b)+MOD)%MOD
#define max(a, b) ((a)>(b) ? (a):(b))
#define min(a, b) ((a)<(b) ? (a):(b))
#define chmax(a, b) (a<b ? a=b : 0)
#define chmin(a, b) (a>b ? a=b : 0)
#define INF 1000000000000000000
#define MOD 1000000007LL
#define MAX 101010
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef map<ll, ll> Map;

class Edge {
public:
    ll t, cap, rev;
    Edge(ll t, ll cap, ll rev): t(t), cap(cap), rev(rev) {}
};

ll N;
vector<Edge> g[222];
ll used[222];

ll dfs(ll v, ll goal, ll f) {
    if(v==goal) return f;
    used[v]=1;
    ll i;
    for(i=0; i<g[v].size(); i++) {
        Edge &e=g[v][i];
        
        if(!used[e.t] && e.cap>0) {
            ll d=dfs(e.t, goal, min(f, e.cap));
            if(d>0) {
                e.cap-=d;
                g[e.t][e.rev].cap+=d;
                return d;
            }
        }
    }
    
    return 0;   //goalまでのパスが見つからなかったとき
}

void addEdge(ll from, ll to, ll cap) {
    g[from].pb(Edge(to, cap, g[to].size()));
    g[to].pb(Edge(from, 0, g[from].size()-1));
}

int main(void) {
    cin >> N;
    ll i, j;
    ll a[222], b[222];
    
    for(i=0; i<N; i++) {
        cin >> a[i] >> b[i];
        addEdge(N*2, i, 1);     //N*2番目の頂点をsとした
    }
    
    for(i=N; i<N*2; i++) {
        cin >> a[i] >> b[i];
        addEdge(i, N*2+1, 1);   //N*2+1番目の頂点をtとした
    }
    
    for(i=0; i<N; i++) {
        for(j=N; j<N*2; j++) {
            if(a[i]<a[j] && b[i]<b[j]) addEdge(i, j, 1);
        }
    }
    
    
    ll flow=0;
    while(1) {
        memset(used, 0, sizeof(used));
        
        ll f=dfs(N*2, N*2+1, INF);  //s(N*2番目)からt(N*2+1番目)に流す
        if(f>0) flow+=f;
        else break;
    }
    
    pt(flow);
}






Measured memory_bytes: 512
H,W = map(int, input().split())
grid = []
for i in range(H):
    grid.append(input())
horiz = [[0]*W for _ in range(H)]
for i in range(H):
    cur = 0
    for j in range(W):
        if grid[i][j] == '#':
            for k in range(cur, j):
                horiz[i][k] = j-cur
            cur = j+1
    for k in range(cur, W):
        horiz[i][k] = W-cur

maxv = 0
for c in range(W):
    cur = 0
    besth = 0
    for r in range(H):
        if grid[r][c] == '.':
            besth = max(besth, horiz[r][c])
        else:
            maxv = max(maxv, r-cur + besth - 1)
            cur = r+1
            besth = 0
    maxv = max(maxv, H-cur + besth - 1)

print(maxv)

Measured memory_bytes: 96472
#include<iostream>
// #include<bits/stdc++.h>
#include<vector>
using namespace std;
#define lli long long int
#define fo(i,b,n) for(int i=b;i<n;++i)
#define si(x) scanf("%d",&x)
#define sll(x) scanf("%lld",&x)
#define ss(s) scanf("%s",s)
#define pi(x) printf("%d\n",x)
#define pl(x) printf("%lld\n",x)
#define ps(s) printf("%s\n",s)
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define endl "\n"
#define PI 3.1415926535897932384626
const int mod = 1000000007;
/*===================================================================*/


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

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
#endif
	int n; cin >> n;
	int ans = n % 10;

	if (ans == 2 || ans == 4 || ans == 5 || ans == 7 || ans == 9) cout << "hon" << endl;
	if (ans == 0 || ans == 1 || ans == 6 || ans == 8) cout << "pon" << endl;
	if (ans == 3) cout << "bon" << endl;






	return 0;
}

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

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define LCM(a, b) (a) / __gcd((a), (b)) * (b)
#define CEIL(a, b) (a)/(b)+(((a)%(b))?1:0)
#define ln '\n'

using namespace std;
using LL = long long;
using ldouble = long double;
using P = pair<int, int>;
using LP = pair<LL, LL>;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1e9 + 7;
static const int SIZE = 200005;

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

vector<LL> Div(LL n) {
    vector<LL> ret;
    for(LL i = 1; i * i <= n; ++i) {
        if(n % i == 0) {
            ret.pb(i);
            if(i * i != n) ret.pb(n / i);
        }
    }
    sort(all(ret));
    return ret;
}

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

    int H, W, N;
    cin >> H >> W >> N;
    P s;
    cin >> s.F >> s.S;

    string S, T;
    cin >> S >> T;

    int nh, nw;
    nh = s.F;
    nw = s.S;
    // takahashi : L
    // aoki      : R
    for(int i = 0; i < N; ++i) {
        if(S[i] == 'L') --nw;
        if(nw == 0) {
            cout << "NO" << endl;
            return 0;
        }
        if(T[i] == 'R' && nw < W) ++nw;
    }

    nh = s.F;
    nw = s.S;
    // takahashi : R
    // aoki      : L
    for(int i = 0; i < N; ++i) {
        if(S[i] == 'R') ++nw;
        if(nw == W + 1) {
            cout << "NO" << endl;
            return 0;
        }
        if(T[i] == 'L' && nw > 1) --nw;
    }

    nh = s.F;
    nw = s.S;
    // takahashi : U
    // aoki      : D
    for(int i = 0; i < N; ++i) {
        if(S[i] == 'U') --nh;
        if(nh == 0) {
            cout << "NO" << endl;
            return 0;
        }
        if(T[i] == 'D' && nh < H) ++nh;
    }

    nh = s.F;
    nw = s.S;
    // takahashi : D
    // aoki      : U
    for(int i = 0; i < N; ++i) {
        if(S[i] == 'D') ++nh;
        if(nh == H + 1) {
            cout << "NO" << endl;
            return 0;
        }
        if(T[i] == 'U' && nh > 1) --nh;
    }
    
    cout << "YES" << endl;
    return 0;
}


Measured memory_bytes: 3900
#include<stdio.h>
#define N 256

int main(){
  int H[N],W[N];
  int i=0,j,k,l,m,n,h,w;
  while(1){
    scanf("%d %d",&H[i],&W[i]);
    if(H[i]==0 && W[i]==0){
      break;
    }
    i++;
  }
  for(j=0;j<i;j++){
    for(k=0;k<W[j];k++){
      printf("#");
    }
    printf("\n");
    h = H[j]-1;
    w = W[j]-1;
    for(l=1;l<h;l++){
      printf("#");
      for(m=1;m<w;m++){
        printf(".");
      }
      printf("#\n");
    }
    for(n=0;n<W[j];n++){
      printf("#");
    }
    printf("\n\n");
  }
  return 0;
}

Measured memory_bytes: 1016
// In the name of God

#include <bits/stdc++.h>

using namespace std;

#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL);
#define debug(x) cout << #x << ": " << x << endl;
#define rep(i, a, b) for(int i=(a); i<(b); i++)

long long ans(long long x) {
	if(x < 9) {
		int a = 0;
		rep(i, 0, x+1) a^=i;
		return a;
	}
	long long tmp=x-9; tmp%=4;
	if(tmp==0) return 1;
	if(tmp==1) return x+1;
	if(tmp==2) return 0;
	if(tmp==3) return x;
}

int main() {
	IOS
	long long a, b;
	cin >> a >> b;
	long long p = ans(a-1)^ans(b);
	cout << p;
	return 0;
}


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

int main() {
	long x;
	cin>>x;
	long a=0;
	map<long,int> m;
	//bool found=true;
	map<long,ll>mp;
	while(1) {
		long num=(long)pow(a,5);
		m[num]=1;
		m[-1*num]=1;
		mp[num]=a;
		mp[-num]=-a;
		a++;
		if(m[num-x]==1) {
			cout<<mp[num]<<" "<<mp[num-x]<<endl;
			break;
		}
	}
	//cout<<"a: "<<a<<endl;
	return 0;
}



Measured memory_bytes: 4104
class BIT: #0-indexed
    def __init__(self, n):
        self.size = n
        self.tree = [0]*(n+1)
        self.depth = n.bit_length()
        self.n0 = 1<<self.depth
#        self.element = [0]*(n+1)
    def get_sum(self, i): #a_0 + ... + a_{i} #閉区間
        s = 0; i += 1
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s
    def query(self,l,r): #a_l + ... + a_r 閉区間
        return self.get_sum(r) - self.get_sum(l-1) 
    def add(self, i, x):
        i += 1
        while i <= self.size:
            self.tree[i] += x
            i += i & -i
        # self.element[i] += x
    #def get(self,i): return element[i]        
    def bisect_left(self,w):
        #和が w 以上になる最小の index
        #w が存在しない場合 self.size を返す
        if w <= 0: return 0
        x,k = 0,self.n0
        for _ in range(self.depth):
            k >>= 1
            if x+k <= self.size and self.tree[x+k] < w:
                w -= self.tree[x+k]
                x += k
        return x
    

# coding: utf-8
# Your code here!
import sys
read = sys.stdin.read
readline = sys.stdin.readline

n,m,*lr = map(int,read().split())

mp = iter(lr)
dlr = [(r-l+1,l,r) for l,r in zip(mp,mp)]
dlr.sort(reverse=True)

ans = [0]*(m+1)

b = BIT(m+2)

for i in range(1,m+1):
    while dlr and dlr[-1][0] < i:
        d,l,r = dlr.pop()
        b.add(l,1)
        b.add(r+1,-1)
        #print(i,l,r)
    
    v = 0
    for j in range(i,m+1,i):
        v += b.get_sum(j)
    #print(b.get_sum(1),b.get_sum(2),b.get_sum(3), b.get_sum(4))   
            
    ans[i] = len(dlr) + v

print(*ans[1:],sep="\n")








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


typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef long double ld;

typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;

const int INF = 1e9 + 7;
const int MOD = 1e9 + 7;
const int MAXN = 1e6 + 3;

#define _  %  MOD
#define __ %= MOD

#define      each(it,s)        for(auto it = s.begin(); it != s.end(); ++it)
#define      sortA(v)          sort(v.begin(), v.end())
#define      sortD(v)          sort(v.begin(), v.end(), greater<auto>())
#define      fill(a)           memset(a, 0, sizeof (a))

#define      swap(a,b)        {a=a+b;b=a-b;a=a-b;}
#define      rep(i, n)         for(ll i = 0; i < (n); ++i)
#define      repA(i, a, n)     for(ll i = a; i <= (n); ++i)
#define      repD(i, a, n)     for(ll i = a; i >= (n); --i)
#define watch(x) cout << (#x) << " is " << (x) <<endl

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

#define fbo find_by_order
#define ook order_of_key

ll gcd(ll a,ll b){if(b==0) return a; else return gcd(b,a%b);}
ll power(ll x,ll y){ll res=1; while(y>0){if(y&1) res=res*x;y=y>>1;x=x*x;}return res;} // modular exponent

int main()
{
    ios_base::sync_with_stdio(false); // don't use printf and scanf
    cin.tie(NULL); // cout<<fixed<<setprecision
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    int flag=1;
    while(1)
    {
        c-=b;
        if(c<=0)
        {
            cout<<"Yes\n";
            break;
        }
        a-=d;
        if(a<=0)
        {
            cout<<"No\n";
            break;
        }
    }
    return 0;
}
// JUST ASK YOURSELF DID YOU GIVE YOUR BEST ? ISSE ZYADA
// KUCH KAR BHI NAHI SAKTE !! ENJOY AND GIVE YOUR BEST!!


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

int main(){
    int N;
    cin >> N;
    int K = N/100;
    int M = N%100;
    bool judge = false;
    for (int i = 0; i*5 <= M; i++) {
        for (int j = 0; j*2 <= M; j++) {
            for (int k= 0; k*3 <= M; k++) {
                for (int l = 0; l*4 <= M; l++) {
                    int C = i*5 + j*2 + k*3 + l*4;
                    int F = M-C;
                    if (F < 0) continue;
                    int cnt = i+j+k+l+F;
                    if (cnt <= K) {
                        judge = true;
                    }
                }
            }
        }
    }
    
    if (judge) cout << 1 << endl;
    else cout << 0 << endl;
}

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

int func(int x)
{
    if(x%2==0)
    {
        return x/2;
    }
    else
    {
        return 3*x+1;
    }
}
int main()
{
    int n;
    cin>>n;
    vector <int> p(n);
    vector <int> q(n);
   

    for(int i=0;i<n;i++)
    {
        cin>>p[i];
    }
    

    for(int i=0;i<n;i++)
    {
        cin>>q[i];
    }
    
    vector<int> c(n);
    for( int i = 0; i < n; i++ ) c[i] = i+1;
    
    //pが辞書順で何番目かカウント
    int countp=1;
    do
    {
        bool flag = true;
        for (int i = 0; i < n; i++) {
            if(c[i]!=p[i])
            {
                flag = false;
            }
        }
        if(flag==true)
        {
            break;
        }
        else
        {
            countp++;
        }
    } while (next_permutation(c.begin(),c.end()));

    sort(c.begin(),c.end());

    //qが辞書順で何番目かカウント
    int countq=1;
    do
    {
        bool flag = true;;
        for (int i = 0; i < n; i++) {
            if(c[i]!=q[i])
            {
                flag = false;
            }
        }
        if(flag==true)
        {
            break;
        }
        else
        {
            countq++;
        }
    } while (next_permutation(c.begin(),c.end()));

    cout<<abs(countp-countq)<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <algorithm>
#define _USE_MATH_DEFINES
#include <cmath>
#include <numeric>
#include <iomanip>
#include <deque>
#include <tuple>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <cstdint>
#include <unordered_map>
#include <sstream>
#include <boost/multiprecision/cpp_int.hpp>

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define pb push_back
#define pf push_front

namespace mp = boost::multiprecision;
using cpp_int = mp::cpp_int;
using ll = long long;
using namespace std;

ll M = 1000000007;

typedef pair<int, int> P;

bool ps1(const P &element1, const P &element2)
{ //first昇順
	return element1.first < element2.first;
}
bool ps2(const P &element1, const P &element2)
{ //first降順
	return element1.first > element2.first;
}
bool ps3(const P &element1, const P &element2)
{ //second昇順
	return element1.second < element2.second;
}
bool ps4(const P &element1, const P &element2)
{ //second降順
	return element1.second > element2.second;
}
int digits(int n)
{
	int count = 0;
	
	while (n > 0)
	{
		n /= 10;
		
		count++;
	}
	return count;
}
int digit(int n)
{
	
	int ans=0;
	while (n > 0)
	{
		ans+=n%10;
		n /= 10;
		
		
	}
	return ans;
}
ll combination(ll n, ll r)
{
	if (r * 2 > n)
		r = n - r;
	ll dividend = 1;
	ll divisor = 1;
	for (ll i = 1; i <= r; ++i)
	{
		dividend *= (n - i + 1);
		divisor *= i;
	}
	return dividend / divisor;
}
int GCD(int x, int y)
{
	return x ? GCD(y % x, x) : y;
}
vector<int> divisor(int n)
{
	vector<int> value;
	FOR(i, 1, pow(n, 0.5) + 1)
	{
		if (i <= sqrt(n))
		{
			if (n % i == 0)
			{
				value.push_back(i);
				if (i * i != n)
				{
					value.push_back(n / i);
				}
			}
		}
	}
	return value;
}

int main()
{
	int n;
	cin>>n;
	vector<pair<int,int>>ab(n);
	rep(i,n){
		cin>>ab[i].F>>ab[i].S;
	}
	sort(all(ab),ps2);
	cout<<ab[0].F+ab[0].S<<endl;
	

}


Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <vector>
#define int long long
using namespace std;

signed main(){
	int n;
	while(cin >> n,n){
		int a[40000],b[40000],ans;
		for(int i = 0;i < n;i++) cin >> a[i];
		for(int i = 0;i < n;i++) cin >> b[i];
		sort(a,a + n,greater<int>());
		sort(b,b + n,greater<int>());
		for(ans = 1;ans < n;ans += 2){
			if(b[ans / 2] < a[ans - 1]) break;
		}
		if(ans >= n) cout << "NA" << endl;
		else cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 3704
#include <bits/stdc++.h>
#include <ctype.h>
using namespace std;
 
 
int main(){
    int A,B,C,K;
    cin>>A>>B>>C>>K;
    int s=max({A,B,C});
    for(int i=0;i<K;i++)s*=2;
    cout<<s+A+B+C-max({A,B,C})<<endl;
}

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

int main(){
    int n, k;
    string s;
    cin >> n >> s >> k;
    char c = s.at(k-1);
    string ans = "";
    for(int i = 0; i < s.size(); i++){
        if(s.at(i) != c) {
            ans += "*";
        } else {
            ans += s.at(i);
        }
    }
    cout << ans << endl;
    return 0;
}

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

int main() {
    ll H;
    cin >> H;
    ll ans = 1;
    while(H > 1){
        ans *= 2;
        ans++;
        H /= 2;
    }
    cout << ans << endl;
    return 0;
}


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

using namespace std;

int main() {
	int a, b;
	cin >> a >> b;
	if (a >= 13) {
		cout << b;
	}
	else if (13 > a && a >= 6) {
		cout << b / 2;
	}
	else
	{
		cout << 0;
	}

	return 0;
}

Measured memory_bytes: 256
from collections import Counter

n = int(input())
a = list(map(int, input().split()))

cnt = Counter(a)

ans = []
sum_ = sum(a)
q = int(input())
for i in range(q):
    b, c = map(int, input().split())
    bv, cv = cnt[b], cnt[c]
    sum_ += c*(cv+bv) - b*bv - c*cv
    cnt[c] += bv
    cnt[b] = 0
    ans.append(sum_)

print("\n".join(map(str, ans)))


Measured memory_bytes: 33584
#include<iostream>
using namespace std;
int H,W;
string s;
main()
{
  cin>>H>>W;
  for(int i=1;i<=H;i++)
  {
    for(int j=1;j<=W;j++)
    {
      cin>>s;
      if(s=="snuke")cout<<(char)(j+64)<<i<<endl;
    }
  }
}

Measured memory_bytes: 256
#include <stdio.h>
#define N 100
#define WHITE 0
#define GRAY 1
#define BLACK 2

int n,m[N][N];
int color[N],d[N],f[N],tt;

void dfs_visit(int u){

  int v;
  color[u] = GRAY;
  d[u]=++tt;
  for(v=0;v<n;v++){
    if(m[u][v]==0) continue;
    if(color[v]==WHITE) {
      dfs_visit(v);
    }
  }
  color[u] = BLACK;
  f[u] = ++tt;
}

void dfs(){
  int u;

  for(u=0;u<n;u++){
    color[u]=WHITE;
    tt = 0;
  }
  
  for(u=0;u<n;u++){
    if(color[u]==WHITE) dfs_visit(u);
  }
  for(u=0;u<n;u++){
    printf("%d %d %d\n",u+1,d[u],f[u]);
  }
}

int main(){
  int u,v,k;
  int i,j;

  scanf("%d",&n);
  for(i=0;i<n;i++){
    for(j=0;j<n;j++) m[i][j]=0;
  }
  for(i=0;i<n;i++){
    scanf("%d%d",&u,&k);
    u--;
    for(j=0;j<k;j++){
      scanf("%d",&v);
      v--;
      m[u][v]=1;
    }
  }

  dfs();

  return 0;
}

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

int n, m, a[100], b[100][100];

int main(){
	int c[100] = { 0 };
	int wa = 0;
	cin >> n >> m;
	for (int i = 0; i < m; i++)
		cin >> a[i];
	for (int i = 0; i < m; i++) {
		for (int j = 0; j < n; j++)
			cin >> b[i][j];
	}
	for (int i = 0; i < m; i++) {
		wa = 0;
		for (int j = 0; j < n; j++) {
			if (b[i][j] == a[i]) {
				c[j]++;
			}
			else {
				wa++;
			}
		}
		c[a[i] - 1] += wa;
	}
	for (int i = 0; i < n; i++) {
		cout << c[i] << endl;
	}

	return 0;
}

Measured memory_bytes: 3120
from collections import deque
import sys


def input():
    return sys.stdin.readline().rstrip()


N = int(input())
v = list(map(int, input().split()))

ans, nd = 0, 0
lim = [1 for _ in range(N + 2)]
for i in range(N):
    lim[i+1] = (lim[i] - v[i]) * 2

for i in range(N, -1, -1):
    if v[i] + nd > lim[i] * 2 or lim[i] - v[i] < 0:
        print(-1)
        sys.exit(0)
    if v[i] + nd > lim[i]:
        nd = lim[i] - v[i]

    nd += v[i]
    ans += nd

print(ans)

Measured memory_bytes: 674656
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
using namespace std;

typedef pair <int, int> PII;
typedef pair <int, PII> PIP;
typedef set <PIP> SET;

int main() {
    int n, h;
    while ( cin >> n >> h && n && h ) {
        SET S;
        for ( int i = 0; i < h; ++ i ) {
            string c;
            int a, b;
            cin >> c >> a >> b;
            a --;
            b --;
            if ( c == "xy" ) {
                for ( int i = 0; i < n; ++ i ) {
                    S.insert( PIP( a, PII( b, i ) ) );
                }
            } else if ( c == "xz" ) {
                for ( int i = 0; i < n; ++ i ) {
                    S.insert( PIP( a, PII( i, b ) ) );
                }
            } else if ( c == "yz" ) {
                for ( int i = 0; i < n; ++ i ) {
                    S.insert( PIP( i, PII( a, b ) ) );
                }
            }
        }
        cout << n * n * n - S.size() << endl;
    }
	return 0;
}

Measured memory_bytes: 2332
#include<iostream>
    #include<cstdio>
    #include<cstring>
    #include<algorithm>
    using namespace std;
    inline int read(){
        int re=0,flag=1;char ch=getchar();
        while(ch>'9'||ch<'0'){
            if(ch=='-') flag=-1;
            ch=getchar();
        }
        while(ch>='0'&&ch<='9') re=(re<<1)+(re<<3)+ch-'0',ch=getchar();
        return re*flag;
    }
    int n,m;
    bool a[510][510],b[510][510];
    int main(){
        int i,j;char s[510];
        n=read();m=read();
        for(i=1;i<=n;i++){
            scanf("%s",s);
            for(j=1;j<=m;j++){
                if(s[j-1]=='#') a[i][j]=b[i][j]=1;
            }
        }
        for(i=1;i<=n;i++) a[i][1]=1,b[i][m]=1;
        for(i=1;i<=n;i++){
            for(j=2;j<m;j++){
                if(i%2) a[i][j]=1;
                else b[i][j]=1;
            }
        }
        for(i=1;i<=n;i++){
            for(j=1;j<=m;j++){
                if(a[i][j]) putchar('#');
                else putchar('.');
            }
            putchar('\n');
        }
        putchar('\n');
        for(i=1;i<=n;i++){
            for(j=1;j<=m;j++){
                if(b[i][j]) putchar('#');
                else putchar('.');
            }
            putchar('\n');
        }
    }

Measured memory_bytes: 1280
#include <bits/stdc++.h>
typedef long long ll;

using namespace std;
using P = pair<int, int>;

int main() {
	int N, M;
	cin >> N >> M;
	vector<P> v(M);
	for (int i = 0; i < M; ++i) {
		int a, b;
		cin >> a >> b;
		v[i] = P(a, b);
	}
	sort(v.begin(), v.end());

	int res = 1;
	int r = N;
	for (int i = 0; i < M; ++i) {
		int a = v[i].first, b = v[i].second;
		if (b <= r) {
			r = b;
		} else if (a >= r) {
			++res;
			r = b;
		}
	}

	cout << res << endl;

	return 0;
}


Measured memory_bytes: 1024
N, K = map(int, input().split())
Vs = list(map(int, input().split()))
lV = [0]*(N+1)
rV = [0]*(N+1)
lm = [[] for _ in range(N+1)]
rm = [[] for _ in range(N+1)]
for i in range(1, N+1):
    lV[i] += Vs[i-1]+lV[i-1]
    rV[i] += Vs[-i] + rV[i-1]
    if Vs[i-1] < 0:
        for j in range(i, N+1):
            lm[j].append(Vs[i-1])
    if Vs[-i] < 0:
        for j in range(i, N+1):
            rm[j].append(Vs[-i])
ans = 0
for i in range(min(N+1, K+1)):#左からi個とる
    for j in range(min(N+1-i, K+1-i)):
        for k in range(max(1, K+1-i-j)):#k個負の数を捨てる
            SUM = lV[i]+rV[j]
            minus = lm[i]+rm[j]
            minus.sort()
            SUM -= sum(minus[:k])
            if ans < SUM:
                ans = SUM
print(ans)
    

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

int main(){
  int n, m, l;
  cin>>n>>m>>l;

  int a[100][100];
  for(int i=0;i<n;i++)
    for(int j=0;j<m;j++) cin>>a[i][j];

  int b[100][100];
  for(int i=0;i<m;i++)
    for(int j=0;j<l;j++) cin>>b[i][j];

  long long c[100][100] = {};
  for(int i=0;i<n;i++)
    for(int j=0;j<l;j++)
      for(int k=0;k<m;k++) c[i][j] += a[i][k] * b[k][j];

  for(int i=0;i<n;i++){
    for(int j=0;j<l;j++){
      if(j) cout<<" ";
      cout<<c[i][j];
    }
    cout<<endl;
  }
  return 0;
}



Measured memory_bytes: 3216
use std::io;

fn main() {
    let line = parse_line::<String>();
    let mut sp = line.split_whitespace();
    let a1 = sp.next().unwrap().parse::<u32>().unwrap();
    let a2 = sp.next().unwrap().parse::<u32>().unwrap();
    let a3 = sp.next().unwrap().parse::<u32>().unwrap();
    if a1 + a2 + a3 <= 21 {
        println!("win");
    } else {
        println!("bust");
    }
}

fn parse_line<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}


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

using namespace std;
using ll = long long;
using ld = long double;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define reps(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
const ll mod = ll(1e9) + 7;
const int INF = int(1e9);


int main() {
	cin.sync_with_stdio(false);
	int N;
	cin >> N;
	bool flag = false;
	rep(i, N) {
		char s;
		cin >> s;
		if (s == 'Y')flag = true;
	}
	if (flag)cout << "Four" << endl;
	else cout << "Three" << endl;
	return 0;
}


Measured memory_bytes: 256
#include<map>
#include<queue>
#include<time.h>
#include<limits.h>
#include<cmath>
#include<ostream>
#include<iterator>
#include<set>
#include<stack>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
#define rep_1(i,m,n) for(int i=m;i<=n;i++)
#define mem(st) memset(st,0,sizeof st)
inline int read()
{
	int num=0, w=0;
	char ch=0;
	while (!isdigit(ch))
	{
		w|=ch=='-';
		ch = getchar();
	}
	while (isdigit(ch))
	{
		num = (num<<3) + (num<<1) + (ch^48);
		ch = getchar();
	}
	return w? -num: num;
}
typedef long long ll;
typedef pair<int,int> pii;
typedef unsigned long long ull;
typedef pair<double,double> pdd;
const int inf = 0x3f3f3f3f;
const int N=100100;
int n;
int a[N];
int q[N];
int ans[N];
void solve()
{
	int  l,r,k;
	cin>>l>>r>>k;
	int ans=r/k-l/k;
	if(l%k==0)
		ans++;
	cout<<ans<<endl;
}
signed main()
{
	int t=1;
	while(t--)
		solve();
	return 0;
}


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

int recursive(int col,vector<int> &current, int n, int m, int q, vector<vector<int>> &aa, vector<vector<int>> &cc, vector<vector<int>> &dd);

int main()
{
	int n,m,q;
	cin >> n >> m >> q;
	vector<int> a(q),b(q),c(q),d(q);

	for (int i=0;i<q;++i)
	{
		cin >> a[i] >> b[i] >> c[i] >> d[i];
	}

	vector<vector<int>> aa(n+1),cc(n+1),dd(n+1);
	for (int i=0;i<q;++i)
	{
		aa.at(b[i]).push_back(a[i]);
		cc[b[i]].push_back(c[i]);
		dd[b[i]].push_back(d[i]);
	}

	vector<int> current(n+1);
	current[0]=1;
	//fprintf(stderr,"prepared completedn");
	cout << recursive(1,current,n,m,q,aa,cc,dd) << endl;
}

int recursive(int col,vector<int> &current, int n, int m, int q, vector<vector<int>> &aa, vector<vector<int>> &cc, vector<vector<int>> &dd)
{
	int score, maxscore;

	//fprintf(stderr,"col %d, current %d\n",col,current[col-1]);
	maxscore=0;
	for (int i=current[col-1];i<=m;++i)
	{
		score=0;
		for (int j=0;j<aa[col].size();++j)
		{
			if (i-current[aa[col][j]]==cc[col][j])
			{
				score+=dd[col][j];
			}
		}
		current[col]=i;
		if (col<n)
		{	
			score+=recursive(col+1,current,n,m,q,aa,cc,dd);
		}
		if (score>maxscore)
		{
			maxscore=score;
		}
	}
	return maxscore;
}






Measured memory_bytes: 3632