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

int main(){
    int n,m,X,Y;
    cin>>n>>m>>X>>Y;

    vector<int> x(n);
    for(int i=0;i<n;i++){
        cin>>x.at(i);
    }
    vector<int> y(m);
    for(int i=0;i<m;i++){
        cin>>y.at(i);
    }
    sort(x.begin(),x.end());
    sort(y.begin(),y.end());

    if(x.at(n-1)>=y.at(0)){
        cout<<"War"<<endl;
        return 0;
    }

    vector<int> cnt(Y-X);
    for(int i=1;i<=Y-X;i++){
        cnt.at(i-1)=X+i;
    }

    for(int i=0;i<Y-X;i++){
        if(x.at(n-1)<cnt.at(i)&&cnt.at(i)<=y.at(0)){
            cout<<"No War"<<endl;
            return 0;
        }
    }

    cout<<"War"<<endl;

}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <tuple>
#include <stack>
#include <bitset>
#include <utility>
#include<iomanip>
// #include <numeric>
using namespace std;



typedef unsigned long ul;
typedef unsigned long long ull;
typedef long long ll;
typedef vector<ll> vint;
typedef vector<vector<ll>> vvint;
typedef vector<string> vstring;
typedef vector<vector<string>> vvstring;
typedef vector<char> vchar;
typedef vector<vector<char>> vvchar;
typedef vector<long double> vdouble;
typedef vector<vector<long double>> vvdouble;
typedef vector<vector<vector<long double>>> vvvdouble;
typedef pair<ll,ll> pint;
typedef vector<pint> vpint;
typedef vector<bool> vbool;

#define rep(i,n) for(ll i=0;i<n;i++)
#define repf(i,f,n) for(ll i=f;i<n;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define INT_MAX 2147483647
#define LLONG_MAX 9223372036854775807
#define vmax(vec) *max_element(vec.begin(), vec.end())
#define vmin(vec) *min_element(vec.begin(), vec.end())
#define vsort(vec) sort(vec.begin(), vec.end())
#define vsortgr(vec) sort(vec.begin(), vec.end(), greater<ll>())
#define DIVIDER 1000000007


//
// struct Node{
//   vint children;
//   ll index;
//   ll prop;
// };
// struct edge{ll to; ll cost;};



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

// ll X,Y,Z,K;
// ll pmax = 30000000000;
// vint A,B,C;




// struct UnionFind {
//     vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2
//
//     UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
//         for(int i = 0; i < N; i++) par[i] = i;
//     }
//
//     int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
//         if (par[x] == x) return x;
//         return par[x] = root(par[x]);
//     }
//
//     void unite(int x, int y) { // xとyの木を併合
//         int rx = root(x); //xの根をrx
//         int ry = root(y); //yの根をry
//         if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
//         par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
//     }
//
//     bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
//         int rx = root(x);
//         int ry = root(y);
//         return rx == ry;
//     }
// };
//
// vint divisor(ll n){ // nの約数
//   vint ret;
//   for(ll i=1;i*i<=n;i++){
//     if(n%i == 0){
//       ret.pb(i);
//       if(i*i!=n) ret.pb(n/i);
//     }
//   }
//   vsort(ret);
//   return ret;
// }
//
// ll get_digits_num(ll n){
//   ll ret=0;
//   while(n){
//     n/=10;
//     ret++;
//   }
//   return ret;
// }



int main() {
  cout<<fixed<<setprecision(10);

  ll N;cin>>N;
  vint a(N);rep(i,N){cin>>a[i];a[i]--;}

  ll ans = 0;
  set<pint> s;
  rep(i,N){
    pint p = mp(min(i,a[i]), max(i,a[i]));
    if(s.find(p)!=s.end()){
      ans++;
      s.erase(p);
    }else{
      s.insert(p);
    }
    // for(auto e:s) cout<<e.fi<<e.se<<" ";
    // cout<<endl;
  }
  cout << ans << endl;
}

















//


Measured memory_bytes: 7296
#include <iostream>

using namespace std;

int main(){
    int x, y;
    cin >> x;
    if (x==2) {
        cout << 2 << endl;
        return(0);
    }

    if (x % 2 == 0) {
        x++;
    }
    for (int i=x;;i+=2) {
        int result = -1;
        for (int j=3;j*j <= i;j+=2) {
            if (i % j == 0) {
                result = j;
                break;
            }
        }
//        cout << i << "\t" << result << endl;
        if (result == -1) {
            cout << i << endl;
            return(0);
        }
    }
}


Measured memory_bytes: 256
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=list(map(int,input().split()))
A.sort()
B.sort()
C.sort()
ans=0
small=0
large=0
for i in range(N):
  for k in range(small,N):
    if A[k]>=B[i]:
      small=k
      break
  else: small=N
  for k in range(large,N):
    if C[k]>B[i]:
      large=k
      break
  else: large=N
  ans+=small*(N-large)
print(ans)

Measured memory_bytes: 22720
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <vector>
#define REP(i, n) for(int i = 0; i < (n); ++i)
typedef long long ll;
const ll MOD = 1000000007;
using namespace std;

int main(){
    int n, T; cin >> n >> T;
    int mincos = 100000;
    REP(i, n){
        int c, t; cin >> c >> t;
        if(t <= T) mincos = min(mincos, c);
    }
    
    if(mincos <= 1000) cout << mincos;
    else cout << "TLE";
    cout << "\n";
    return 0;
}

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

int main()
{
    string a , b,  c;
        cin>>a>>b>>c;
    queue<char> A,B , C;
    for(int i=0;i<a.length() ;i++)
    {
        A.push( a[i] );
    }
    for(int i=0;i<b.length() ;i++)
    {
        B.push( b[i] );
    }
    for(int i=0;i<c.length() ;i++)
    {
        C.push( c[i] );
    }
    int curr = 1  ;
    while( true)
    {
        if( curr == 1 )
        {
            if( A.empty() ) {
                cout << "A";
                break;
            }
            char temp = A.front();
            A.pop();
            if( temp == 'a' )
            {
                curr = 1;
            }
            if( temp == 'b' )
            {
                curr = 2;
            }
            if( temp == 'c')
                curr = 3;
        }
        if( curr == 2 )
        {
            if( B.empty() ) {
                cout << "B";
                break;
            }
            char temp = B.front();
            B.pop();
            if( temp == 'a' )
            {
                curr = 1;
            }
            if( temp == 'b' )
            {
                curr = 2;
            }
            if( temp == 'c')
                curr = 3;
        }
        if( curr == 3 )
        {
            if( C.empty() ) {
                cout << "C";
                break;
            }
            char temp = C.front();
            C.pop();
            if( temp == 'a' )
            {
                curr = 1;
            }
            if( temp == 'b' )
            {
                curr = 2;
            }
            if( temp == 'c')
                curr = 3;
        }
    }
}

Measured memory_bytes: 3648
#include <stdlib.h>
#include <stdio.h>
 
int main(void)
{
	int i, n;
	long taka = 1, aoki = 1;
	long cuntt = 0, cunta = 0; 
	int t[1001], a[1001];
	
	scanf("%d", &n);
	for (i = 0; i < n; i++)
		scanf("%ld %ld", &t[i], &a[i]);
	
	for (i = 0; i < n; i++)
	{
		cuntt = taka / t[i];
		if (taka % t[i] != 0) cuntt++;
		cunta = aoki / a[i];
		if (aoki % a[i] != 0) cunta++;
	
		taka = ((cuntt <= cunta) ? cunta : cuntt) * t[i];
		aoki = ((cuntt <= cunta) ? cunta : cuntt) * a[i];
	}
	
	printf("%ld\n", taka + aoki);
	
	return 0;
}

Measured memory_bytes: 128
s = input() + "0"
t = "AKIHABARA" + "0"

i = 0
j = 0
ng = 0
while i < len(s) and j < len(t):
    if s[i] == t[j]:
        i += 1
        j += 1
    elif t[j] == "A" and s[i] == t[j+1]:
        j += 1
    else:
        ng = 1
        break

if i == len(s) and j == len(t) and ng == 0:
    print("YES")
else:
    print("NO")

Measured memory_bytes: 38256
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
ll x[55],y[55];
ll xx[55],yy[55];
int n,kk;
ll ans=9223372036854775807;
inline ll check(int u,int v,int k,int l)
{
ll x1=min(x[u],x[v]),x2=max(x[u],x[v]);
ll y1=min(y[k],y[l]),y2=max(y[k],y[l]);
int tot=0;
for(int i=1;i<=n;i++)
  if(x1<=x[i]&&x[i]<=x2&&y1<=y[i]&&y[i]<=y2) tot++;
return tot;
}
int main()
{
	scanf("%d%d",&n,&kk);
	for(int i=1;i<=n;i++)
	  scanf("%lld%lld",&x[i],&y[i]);
	for(int i=1;i<=n;i++)
	  for(int j=i;j<=n;j++)
	    for(int k=1;k<=n;k++)
	      for(int l=k;l<=n;l++)
			if(check(i,j,k,l)>=kk) ans=min(ans,1ll*abs(x[i]-x[j])*abs(y[k]-y[l]));
	printf("%lld",ans);
	return 0;
}

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

int main() {
    int N, P; cin >> N >> P;
    int odd = 0;
    rep(i,N) {
        int a; cin >> a;
        if (a % 2 == 1) odd++;
    }
    ll res = 0;
    res = (odd == 0) ? ((P == 1) ? 0 : 1LL << N) : 1LL << N-1;
    cout << res << endl;
}


Measured memory_bytes: 3632
#include <iostream>
#include <string>
#include <cmath>
#include <vector>
#include <set>
#include <utility>
#include <algorithm>
#include <bits/c++io.h>
#include <cmath>
#define maxn 100000+5
using namespace std;
typedef long long ll;

int main()
{
    ios::sync_with_stdio(0);

  ll n,a,b,sum=0;
  cin>>a>>b;
  bool d=false;
  for(int i=1;i<=b;i++)
  {
      cin>>n;
      sum+=n;
      if(sum>=a)
        d=true;
  }
  if(d)
    cout<<"Yes";
  else
    cout<<"No";
 }


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

using namespace std;

#define forn(i, n) for (ll i = 0; i < (ll) (n); ++i)
#define sz(a) static_cast<int>((a).size())
#define pb emplace_back
#define mp make_pair
#define endl '\n'
#define f first
#define s second

#ifdef SEREZHKA
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define dbg(...)
#endif

template<typename T>
void _dbg(const char* _s, T _h) { cerr << _s << " = " << _h << "\n"; }

template<typename T, typename... Ts>
void _dbg(const char*_s, T _h, Ts... _t) {
    int _b = 0;
    
    while (((_b += *_s == '(') -= *_s == ')') != 0 || *_s != ',')
        cerr << *_s++;
    
    cerr << " = " << _h << ",";
    _dbg(_s + 1, _t...);
}

using ll = long long;

const ll INF = static_cast<ll>(1e9) + 7ll;
const ll LINF = INF * INF;
const int MAXN = static_cast<int>(4e2) + 17;

ll n, s;

bool read() {
    if (!(cin >> n >> s))
        return false;

    return true;
}

ll f(ll b, ll n) {
    ll sum = 0;
    for (; n > 0; sum += n % b, n /= b) { }
    return sum;
}

void solve() {
    if (n == s) {
        cout << n + 1 << endl;
        return ;
    }

    ll ans = INF * INF;

    for (ll b = 2; b * b <= n; ++b)
        if (f(b, n) == s)
            ans = min(ans, b);

    if (n - s > 0) {
        ll t = n - s;

        for (ll d = 1; d * d <= t; ++d)
            if (t % d == 0) {
                if (f(d + 1, n) == s) ans = min(ans, d + 1);
                if (f(t / d + 1, n) == s) ans = min(ans, t / d + 1);
            }
    }

    cout << (ans == INF * INF ? -1 : ans) << endl;
}

int main() {
    cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    
    while (read())
        solve();
    
    return 0;
}



Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
///////////////////////////////////////////
const long long int INF = 1LL<<60;
const long long int Mod = 1000000007;
using ll = long long int; using ci = const int;
using vi = vector<int>;  using Vi = vector<long long int>;
using P = pair<int, int>;  using PLL = pair<ll, ll>;
using matrix = vector<vector<ll>>;
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define rep(i,N) for(ll i = 0; i < (ll)N; i++)
#define repi(i,a,b) for(ll i = ll(a); i < ll(b); ++i)
template<class T>bool chmax(T &former, const T &b) { if (former<b) { former=b; return true; } return false; }
template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return true; } return false; }
template<class T>T sqar(T x){ return x*x; }//sqrt(x)は平方根;
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(v[0])>()) //降順でVをソート
#define p_queue(v) priority_queue<v, vector<v>, greater<v> >
template<class T> inline void princ(T x){cout<<x<<" ";}; 
template<class T> inline void print(T x){cout<<x<<"\n";};
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
///////////////////////////////////////////////////////////////////////////////////

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    std::cout<<std::fixed<<std::setprecision(30);
    ll r;
    cin>>r;
    print(3*r*r);
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = long.Parse(Console.ReadLine());

            var ans = long.MaxValue;

            for (var i = 1L; i * i <= N ; i++)
            {
                if(N % i == 0)
                {
                    ans = Math.Min(Math.Max(i.ToString().Length, (N / i).ToString().Length), ans);
                }
            }

            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 27560
#include <iostream>

int main() {
    std::string S;
    std::cin >> S;
    int result = 0;
    for (int i = 0; i < S.size() / 2; ++i) {
        if (S[i] != S[S.size() - i - 1]) {
            ++result;
        }
    }
    std::cout << result << std::endl;
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <map>

#define ST_ARR_LEN(array) (sizeof(array)/sizeof(*array))

typedef std::stack<int> IntStack;
typedef std::queue<int> IntQueue;
typedef std::vector<int> IntVector;
typedef std::list<int> IntList;

using namespace std;
  
int main(){
  int N;
  cin >> N;
  string S;
  map<string, int> mp;
  for(int i=0;i<N;i++){
    cin >> S;
    mp[S]++;
  }
  
  int maxCount = 0;
  for(auto i=mp.begin();i!=mp.end();i++){
    maxCount = max(maxCount, i->second);
  }
  
  for(auto i=mp.begin();i!=mp.end();i++){
    if(i->second == maxCount){
      cout << i->first << endl;
    }
  }
  
} 

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

using namespace std;

typedef long long ll;

const int INF = 1000000000;

int main()
{
  vector<vector<int> > grid(3, vector<int>(3));
  vector<int> hsum(3, 0), vsum(3, 0);
  for (int i = 0; i < 3; ++i) {
    for (int j = 0; j < 3; ++j) {
      scanf("%d", &grid[i][j]);
      hsum[i] += grid[i][j];
      vsum[j] += grid[i][j];
    }
  }
  string ans = "Yes";
  for (int i = 0; i < 3; ++i) {
    if (abs(hsum[i] - hsum[(i + 1) % 3]) % 3 != 0) {
      ans = "No";
    }
    if (abs(vsum[i] - vsum[(i + 1) % 3]) % 3 != 0) {
      ans = "No";
    }
  }
  printf("%s\n", ans.c_str());
  return 0;
}


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

using namespace std;

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


#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define INF 1<<30
#define mp make_pair
#define pb push_back

#define fi first
#define se second

#define each(it,c) for(auto it=(c).begin();it!=(c).end();it++)

typedef vector<int> vi;
typedef vector<vi> vii;
typedef pair<int,int> pii;

typedef long long ll;

class team{
public:
	int id;
	int clear;
	vi fail;
	int time;
	team(){
		// id=0;
		// clear=0;
		// fail = vi(10,0);
		// time=0;
	}
};

int main(){
	while(1){
		int M,T,P,R;
		int m,t,p,j;
		vector<team> tev;
		vector<pii> ap;
		cin>>M>>T>>P>>R;
		if(M==0)break;
		rep(i,T){
			team te;
			te.id=i+1;
			te.clear=0;
			te.time=0;
			rep(j,10){
				te.fail.pb(0);
			}
			tev.pb(te);
			//????????§id??????????????°??????????????????clear,time???0??§?????????
		}
		rep(i,R){
			cin>>m>>t>>p>>j;
			if(j==0){
				int time=m;
				//????????§?????£?§£??°????????????????????????????????£?§£??°??¨????????????????????????
				time += tev[t-1].fail[p-1]*20;
				tev[t-1].clear++;
				tev[t-1].time+=time;
			}else{
				//????????§???????????????????????¨????????£?§£?????°?????????
				tev[t-1].fail[p-1]++;
			}
		}
		rep(i,T){
			ap.pb(mp(tev[i].clear*100000+(90000-tev[i].time),tev[i].id));
		}
		sort(rall(ap));

		cout<<ap[0].se;
		REP(i,1,T){
			if(ap[i-1].fi==ap[i].fi) cout<<"=";
			else cout<<",";
			cout<<ap[i].se;
		}
		cout<<endl;
		// rep(i,T){
		// 	cout<<"debug clear:"<<tev[i].clear<<" time:"<<tev[i].time;
		// 	cout<<endl;
		// 	rep(j,P){
		// 		cout<<" fail:"<<tev[i].fail[j];
		// 	}
		// 	cout<<endl;
		// }

	}
	return 0;
}

Measured memory_bytes: 3096
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define cans cout << ans << endl
#define cyes cout << "Yes" << endl 
#define cno cout << "No" << endl
typedef long long ll;


int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    int ans = 0;
    int now = 0;
    rep(i,n-1){
        if(a[i] >= a[i+1]) now++;
        else now = 0;
        ans = max(ans,now);
    }
    cans;
    return 0;
}   

Measured memory_bytes: 3700
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        String s = sc.next();
        String t = sc.next();
        int start = n;
        outside : for(int i = 0; i < n; i++){
            for(int j = 0; j < n - i; j++){
                if(s.charAt(i + j) != t.charAt(j)){
                    break;
                }
                if(j == n - i - 1){
                    start = i;
                  	break outside;
                }
            }
        }
        System.out.println(n + start);
    }
}

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

int main() {
	// your code goes here
	int i=0,j=0;
	for(i=1;i<=9;i++){
		for(j=1;j<=9;j++){
			cout << i << "x" << j << "=" << i*j << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1116
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <string>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>

#define INF (int)1e09

using std::cin;
using std::cout;
using std::endl;
using std::setprecision;
using std::fixed;
using std::pair;
using std::make_pair;
using std::min;
using std::max;
using std::string;
using std::vector;
using std::list;
using std::map;
using std::set; // insert erase find count
using std::queue;
using std::priority_queue;
using std::stack;

template <typename T> using Vec = vector<T>; // c++11
typedef pair<int, int> PII;
typedef pair<int, pair<int, int> > PIII;

int main(void) {
    int q;
    cin >> q;
    string s = "";

    long long int left = 0;
    long long int right = 0;
    int p;
    char c;
    int n;
    for (int i = 0; i < q; i++) {
        cin >> p >> c >> n;
        if (c == '(') {
            left += n;
        } else {
            right += n;
        }
        if (left != right) {
            cout << "No" << endl;
            continue;
        } else {
            cout << "Yes" << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 3148
// https://atcoder.jp/contests/agc003/tasks/agc003_c
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
#define EPS (1e-9)
#define INF (1e9)
#define INFL (1e18)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = (n - 1); i >= 0; --i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define BIT(n) (1LL << (n))
// ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
// ll lcm(ll c, ll d) { return c / gcd(c, d) * d; }

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, t;
    cin >> n;
    vector<PII> v(n);
    REP(i, n) {
        cin >> t;
        v[i] = {t, i};
    }
    sort(ALL(v));
    ll cnt = 0;
    REP(i, n) {
        if ((i % 2 == 0) ^ (v[i].second % 2 == 0)) {
            cnt++;
        }
    }
    cout << cnt / 2 << endl;

    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <queue>
using namespace std;
typedef long long int ll;


int n,q;
ll add[200100];
vector<int> G[200100];
void dfs(int s,int b){
	if(b==-1){
		for(auto p:G[0]){
			dfs(p,0);
		}
	}
	else{
		add[s]+=add[b];
		for(auto p:G[s]){
			if(p!=b)dfs(p,s);
		}
	}
}
int main(){
	cin >> n >> q;
	for(int i=0;i<n-1;i++){
		int a,b; cin >> a >> b;
		a--;b--;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	vector<int>p(q),x(q);
	for(int i=0;i<q;i++){
		cin >> p[i] >> x[i];
		add[p[i]-1]+=x[i];
	}
	dfs(0,-1);
	for(int i=0;i<n;i++){
		cout << add[i] << " ";
	}
	cout << endl;
}


Measured memory_bytes: 25856
#include<bits/stdc++.h>
#define INF 2147483647
#define LLINF 9223372036854775807
typedef long long ll;
using namespace std;
int n;
vector<int> v[100010];
vector<int> Root;
bool vis[100010];
int none;
int cnt=0;
bool dfs(int x){
	vis[x]=1;
	if(x==n)return 1;
	for(int i=0;i<v[x].size();i++){
		if(!vis[v[x][i]]){
			Root.push_back(v[x][i]);
			if(dfs(v[x][i]))return 1;
			Root.erase(Root.begin()+Root.size()-1);
		}
	}
	return 0;
}
void dfs2(int x){
	vis[x]=1;
	cnt++;
	for(int i=0;i<v[x].size();i++){
		if(!vis[v[x][i]]&&v[x][i]!=none){
			dfs2(v[x][i]);
		}
	}
}
int main(){
	cin>>n;
	for(int i=0;i<n-1;i++){
		int a,b;
		cin>>a>>b;
		v[a].push_back(b);
		v[b].push_back(a);
	}
	Root.push_back(1);
	dfs(1);
	none=Root[(Root.size()+1)/2];
	memset(vis,0,sizeof(vis));
	dfs2(1);
	if(cnt*2>n)cout<<"Fennec"<<endl;
	else cout<<"Snuke"<<endl;
	return 0;
}

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


int main() {
    ll n; cin >> n;
    vector<ll> a(n+1);
    rep(i,n){
        cin >> a[i+1];
    }
    int k;
    if(n%2==0){
        rep(i,n/2){
            k=n-2*i;
            cout << a[k] << " ";
        }
        rep(i,n/2){
            k=2*i+1;
            cout << a[k];
            if(i<n/2-1) cout << " ";
        }
        cout << endl;
        return 0;
    }
    if(n%2==1){
        rep(i,n/2+1){
            k=n-2*i;
            cout << a[k] << " ";
        }
        rep(i,n/2){
            k=2*(i+1);
            cout << a[k];
            if(i<n/2-1) cout << " ";
        }
        cout << endl;
        return 0;
    }
}

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

int main(){
    long n,a[5]={0,0,0,0,0},r=0;
    scanf("%ld", &n);
    for(int i=0;i<n;i++){
      char s[10];
      scanf("%s",s);
      if (s[0]=='M'){
      a[0]++;}
      else if (s[0]=='A'){
      a[1]++;}
      else if (s[0]=='R'){
      a[2]++;}
      else if (s[0]=='C'){
      a[3]++;}
      else if (s[0]=='H'){
      a[4]++;}    
      }

      for(int k=0;k<3;k++){
          for(int l=k+1;l<4;l++){
              for(int m=l+1;m<5;m++){
                 r+=a[k]*a[l]*a[m];
           }
}
}
printf("%ld",r);
return 0;
}

Measured memory_bytes: 256
//解けなかった　解答例を載せておく
#include <iostream>
using namespace std;
int main(){
    int D, G, p[11], c[11];
    cin >> D >> G;
    for(int i = 0; i < D; ++i){
        cin >> p[i] >> c[i];
    }

    int ans = 1e9;
    for(int mask = 0; mask < (1 << D); ++mask){
        int s = 0, num = 0, rest_max = -1;
        for(int i = 0; i < D; ++i){
            if(mask >> i & 1){
                s += 100 * (i+1) * p[i] + c[i];
                num += p[i];
            }else{
                rest_max = i;
            }
        }
        if(s < G){
            int s1 = 100 * (rest_max + 1);
            int need = (G - s + s1 - 1) / s1;
            if(need >= p[rest_max]){
                continue;
            }
            num += need;
        }
        ans = min(ans, num);
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
const int Mod=1e9+7;
const int Maxn=2*100000;
int H,W,A,B;
ll f[Maxn+10],inv[Maxn+10];
int N;
ll PowMod(ll a,int b) {
	ll ret=1;
	while(b) {
		if(b&1)ret=ret*a%Mod;
		a=a*a%Mod;
		b>>=1;
	}
	return ret;
}
void Init() {
	f[0]=1;
    for(int i=1;i<=N;i++)
        f[i]=f[i-1]*i%Mod;
    inv[0]=1;
    inv[N]=PowMod(f[N],Mod-2);
    for(int i=N-1;i>0;i--)
        inv[i]=inv[i+1]*(i+1)%Mod;
}
ll C(int a,int b) {
	if(a<0||b<0)return 1;
	return f[a]*inv[b]%Mod*inv[a-b]%Mod;
}
int main() {
	#ifdef LOACL
	freopen("in.txt","r",stdin);
	freopen("out.txt","w",stdout);
	#endif
	scanf("%d %d %d %d",&H,&W,&A,&B);
	N=H+W-2;
	Init();
	ll ans=C(H+W-2,H-1);
	for(ll i=1;i<=B;i++) {
		ans-=C(H-A+i-2,H-A-1)*C(A-1+W-i,A-1)%Mod;
		ans=(ans%Mod+Mod)%Mod;
	}
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 3328
while true
  n = gets.chomp.to_i
  break if n == 0

  n2 = 0
  n5 = 0

  for k in (2..n)
    while k % 2 == 0
      n2 += 1
      k /= 2
    end
    while k % 5 == 0
      n5 += 1
      k /= 5
    end
  end

  n10 = [n2, n5].min
  puts n10
end

Measured memory_bytes: 6092
from collections import deque
n=int(input())
S=list(input().split())[::-1]
b=deque([])
for i in range(n//2):
  b.append(S.pop())
  b.appendleft(S.pop())
if n%2:
  b.append(S.pop())
  print(' '.join(list(b)[::-1]))
else:print(' '.join(list(b)))

Measured memory_bytes: 112532
import java.util.Scanner;

public class Main{
    
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int[] arr = new int[10000];
        for(int i = 0;;i++){
            int x = sc.nextInt();
            if(x != 0)  arr[i] = x;
            else break;
        }
        for(int i = 0 ; i < arr.length ; i++){
            System.out.println("Case "+(i+1)+": "+arr[i]);
        }
    }
}


Measured memory_bytes: 43420
n = int(input())
a = list(map(int, input().split()))
cnt = 0
flag = True

def calc_half(n):
    return n / 2

while flag:
    for i in a:
        if i % 2 == 1:
            flag = False
    if flag:
        a = list(map(calc_half, a))
        cnt += 1
print(cnt)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define pb push_back
const int maxn=2e5+10;
const int mod=998244353;



int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s;
    cin>>s;
    if(s=="SUN")
        cout<<7<<'\n';
    else if(s=="MON")
    {
        cout<<6<<'\n';
    }
    else if(s=="TUE")
    {
        cout<<5<<'\n';
    }
    else if(s=="WED")
    {
        cout<<4<<'\n';
    }
    else if(s=="THU")
    {
        cout<<3<<'\n';
    }
    else if(s=="FRI")
    {
        cout<<2<<'\n';
    }
    else if(s=="SAT")
    {
        cout<<1<<'\n';
    }




}


Measured memory_bytes: 3608
using System;
using System.Collections.Generic;
class Program
{
	static void Main(string[] args)
	{
		string str = Console.ReadLine();
		long N = long.Parse(str);
		string[] str2 = Console.ReadLine().Split();
		long[] A = new long[N];
		long[] AN = new long[N];
		for(var i=0;i<N;i++){
			A[i] = long.Parse(str2[i]);
			AN[A[i]] += 1;
		}
		long ans = -1;
		if(N%2==0 && AN[0]!= 0){
			ans = 0;
		} else if(N%2==1 && AN[0]!= 1){
			ans = 0;
		}
		if(ans == -1){
			for(var i=1;i<N;i++){
				if(N%2==0){
					if(i%2==0 && AN[i]!=0){
						ans = 0;
						break;
					} else if(i%2==1 && AN[i]!=2){
						ans = 0;
						break;
					}
				} else {
					if(i%2==0 && AN[i]!= 2){
						ans = 0;
						break;
					} else if(i%2==1 && AN[i]!= 0){
						ans = 0;
						break;
					}
				}
			}
			if(ans != 0){
			ans = 1;
			for(var i=0;i<N/2;i++){
				ans *= 2;
				ans %= 1000000007;
			}
			}
		}
		Console.WriteLine(ans);
	}
}

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

int guki(int x){
    if(x%2==0){
        return 2;
    }
    else{
        return 1;
    }
}
//gukiは偶数なら2を奇数なら1を出力



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

    vector<int> A(N);
    for(int i=0;i<N;i++){
        cin>>A.at(i);
    }

    vector<int> B(N);
    //B(1)=B.at(0)を決める。
    for(int i=0;i<N;i++){
        if(guki(i)==2){
            B.at(0)+=A.at(i);
        }
        else{
            B.at(0)-=A.at(i);
        }
    }

    //B(2)=B.at(1)を決める。
    B.at(1)=A.at(0);
    for(int i=1;i<N;i++){
        if(guki(i)==1){
            B.at(1)+=A.at(i);
        }
        else{
            B.at(1)-=A.at(i);
        }
    }


    //その他のB.at(i)を指定していく。
    for(int i=2;i<N;i++){
        B.at(i)=B.at(i-2)+2*(A.at(i-1)-A.at(i-2));
    }



    //出力する。
    for(int i=0;i<N;i++){
        if(i<N-1){
            cout<<B.at(i)<<" ";
        }
        else{
            cout<<B.at(i)<<endl;
        }
    }
}


//gukiの動作確認
/*
int main(){
    int x;
    cin>>x;

    cout<<guki(x);
    
}
*/

Measured memory_bytes: 2048
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
typedef long long ll;
const int MAX=71;
const int MOD=1000000007;
int a,b,c,fin=MOD;
int mycnt(int x){
    if(x==0) return 0;
    if(x<0){
        if(x%2==0) return -x/2;
        return -x/2+2;
    }
    return x;
}
int main(){
    scanf(" %d %d %d",&a,&b,&c);
    for(int i=-100;i<=200;i++){
        int q=0;
        q+=mycnt(a-i)+mycnt(b-i)+mycnt(c-i);
        fin=min(q,fin);
    }
    printf("%d\n",fin);
}


Measured memory_bytes: 256
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
    n: usize,
    s: [usize; n],
    q: usize,
    t: [usize; q]
    }
    let mut ans = 0;
    for i in t {
        let k = s.lower_bound(&i);
        if k < n && s[k] == i {
            ans += 1;
        }
    }
    println!("{}", ans);
}
use std::cmp::Ordering;

pub trait BinarySearch<T> {
    fn lower_bound(&self, x: &T) -> usize;
    fn upper_bound(&self, x: &T) -> usize;
}

impl<T: Ord> BinarySearch<T> for [T] {
    fn lower_bound(&self, x: &T) -> usize {
        let mut low = 0;
        let mut high = self.len();

        while low != high {
            let mid = (high + low) / 2;
            match self[mid].cmp(x) {
                Ordering::Less => {
                    low = mid + 1;
                }
                Ordering::Equal | Ordering::Greater => {
                    high = mid;
                }
            }
        }
        low
    }
    fn upper_bound(&self, x: &T) -> usize {
        let mut low = 0;
        let mut high = self.len();
        while low != high {
            let mid = (low + high) / 2;
            match self[mid].cmp(x) {
                Ordering::Less | Ordering::Equal => {
                    low = mid + 1;
                }
                Ordering::Greater => {
                    high = mid;
                }
            }
        }
        low
    }
}





Measured memory_bytes: 5052
using System;
using System.Collections.Generic;
using System.Text;

namespace Kyoupro
{
    class Plactice
    {
        static void Main()
        {
            int count = 0;
            string S = Console.ReadLine();
            int len = S.Length;
            int Solidlen = len;

            for(int i = 0;i < Solidlen/2; i++)
            {
                if (S[i] != S[len-1])
                {
                    count++;
                }
                len--;
            }
            Console.WriteLine(count);
        }
    }
}


Measured memory_bytes: 13140
#include "bits/stdc++.h"
using namespace std;
typedef long long lint;
#define rep(i,n) for(int i=0;i<n;++i)
#define MAXN 100010
#define all(v) v.begin(),v.end()
#define inf 2147483647
#define linf 1152921504606846976

int main(){
	lint n;cin>>n;
	vector<pair<lint,lint> >a(n);
	rep(i,n){
		cin>>a[i].first;
		a[i].second=i;
	}sort(all(a),greater<pair<lint,lint> >());
	vector<lint>ans(n);lint mnpos=inf;
	rep(i,n-1){
		mnpos=min(mnpos,a[i].second);
		ans[mnpos]+=(a[i].first-a[i+1].first)*(i+1);
	}ans[0]+=a[n-1].first*n;
	rep(i,n)cout<<ans[i]<<endl;
}

Measured memory_bytes: 3456
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

const int MOD = 998244353;

int n;

string ex4[4] = {
"aabc",
"ddbc",
"efgg",
"efhh"
};

string ex5[5] = {
"abbc.",
"a..ce",
"ddf.e",
"g.fxx",
"ghhyy"
};

string ans[2000];

void draw4(int x, int y)
{
    for (int i = 0; i < 4; i++)
    {
        for (int j = 0; j < 4; j++)
        {
            ans[i + x][j + y] = ex4[i][j];
        }
    }
}

void draw5(int x, int y)
{
    for (int i = 0; i < 5; i++)
    {
        for (int j = 0; j < 5; j++)
        {
            ans[i + x][j + y] = ex5[i][j];
        }
    }
}


int main()
{
    cin >> n;
    if (n == 2)
    {
        cout << -1;
        exit(0);
    }
    if (n == 7)
    {
        cout << "aabbc..\n";
        cout << ".dd.c.e\n";
        cout << "..n..fe\n";
        cout << "..n..fg\n";
        cout << "mm.jj.g\n";
        cout << "l..kii.\n";
        cout << "l..k.hh\n";
        exit(0);
    }
    if (n == 11)
    {
        cout << "abccdd..yyz\n";
        cout << "abeeffxx..z\n";
        cout << "gh..mn..yyt\n";
        cout << "gh..mnxx..t\n";
        cout << "iijjop..yyz\n";
        cout << "kkllopxx..z\n";
        cout << "x.x.x.abbc.\n";
        cout << "x.x.x.a..cd\n";
        cout << ".y.y.yiih.d\n";
        cout << ".y.y.yj.hee\n";
        cout << "zzttzzjggff\n";
        exit(0);
    }
    if (n == 3)
    {
        cout << "aab\n";
        cout << "c.b\n";
        cout << "cdd\n";
        exit(0);
    }
    if (n == 6)
    {
        cout << "aab...\n";
        cout << "c.b...\n";
        cout << "cdd...\n";
        cout << "...aab\n";
        cout << "...c.b\n";
        cout << "...cdd\n";
        exit(0);
    }
    if (n == 9)
    {
        cout << "aab......\n";
        cout << "c.b......\n";
        cout << "cdd......\n";
        cout << "...aab...\n";
        cout << "...c.b...\n";
        cout << "...cdd...\n";
        cout << "......aab\n";
        cout << "......c.b\n";
        cout << "......cdd\n";
        exit(0);
    }
    for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) ans[i] += ".";
    for (int a = 0; a <= 1000; a++)
    {
        if (n - 4 * a >= 0 && (n - 4 * a) % 5 == 0)
        {
            int b = (n - 4 * a) / 5;
            int x = 0, y = 0;
            for (int i = 0; i < a; i++, x+=4, y+=4) draw4(x, y);
            for (int i = 0; i < b; i++, x+=5, y+=5) draw5(x, y);
            for (int i = 0; i < n; i++) cout << ans[i] << "\n";
            return 0;
        }
    }
}


Measured memory_bytes: 2304
#include "bits/stdc++.h"
#define ed cout<<"\n";
#define speed ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long int

using namespace std;


int main() {
	speed;
	int n , k;
	string s;

	cin >> n >> k;
	cin >> s;
	k -= 1;
	if (s[k] == 'A')s[k] = 'a';
	if (s[k] == 'B')s[k] = 'b';
	if (s[k] == 'C')s[k] = 'c';

	cout << s;
	ed;
	return 0;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(114514)

n, z, w = map(int, input().split())
aa = list(map(int, input().split()))

memo = {}
def act(last, turn):
    if (last, turn) in memo:
        return memo[(last, turn)]

    if turn == 0:
        # x turn
        y = w if last == -1 else aa[last]
        ans = abs(y - aa[n - 1])
        for i in range(last + 1, n - 1):
            ans = max(ans, act(i, 1))
    else:
        # y turn
        x = z if last == -1 else aa[last]
        ans = abs(x - aa[n - 1])
        for i in range(last + 1, n - 1):
            ans = min(ans, act(i, 0))
    
    memo[(last, turn)] = ans
    return ans


print(act(-1, 0))


Measured memory_bytes: 5236
#include <bits/stdc++.h>
 
using namespace std;
 
#define rep(i, n) for(int i=0; i<(n); i++)
#define FOR(i, m, n) for(int i=(m);i<(n);i++)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define SORT(x) sort((x).begin(),(x).end())
#define REVE(x) reverse((x).begin(),(x).end())
#define mp make_pair
#define pb push_back
#define chmax(x,y) x = max(x,y)

 
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<vector<int> > VVI;
typedef pair<int, int> PII;
typedef long long LL;
typedef vector<bool> VB;
typedef vector<LL> VL;
typedef vector<vector<long long>> VVLL;
const int MOD = 1e9+7;
const int INF = 1e9;
const LL LINF = 1e18;
int gcd(int a, int b)
{
   if (a%b == 0)
   {
       return(b);
   }
   else
   {
       return(gcd(b, a%b));
   }
}

int lcm(int a, int b)
{
   return a * b / gcd(a, b);
}

int main() {
    string s;
    cin >> s;
    if(s[2] == s[3] && s[4] == s[5]) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 256
#!/usr/bin/env python3


M = 10 ** 9 + 7


def solve(n, m, s, lst):

    cnt = [0] * n
    t = 0
    for i in range(n):
        if s[i] == '1':
            t += 1
        cnt[i] = t


    dp = [[0] * (n + 1) for _ in range(n + 1)]
    dp[0][0] = 1
    r = 0
    j = 0
    for i in range(n):
        while j < m:
            lj, rj = lst[j]
            if lj <= i:
                r = max(r, rj)
                j += 1
            else:
                break
        if r <= i:
            c = cnt[i]
            if 0 < c:
                dp[i + 1][cnt[i]] = (dp[i][c] + dp[i][c - 1]) % M
            else:
                dp[i + 1][0] = dp[i][0]
        else:
            for k in range(max(0, cnt[r] - r + i), min(i + 1, cnt[r]) + 1):
                if 0 < k:
                    dp[i + 1][k] = (dp[i][k] + dp[i][k - 1]) % M
                else:
                    dp[i + 1][0] = dp[i][0]

    return dp[n][cnt[n - 1]]


def main():
    n, m = input().split()
    n = int(n)
    m = int(m)
    s = input()
    lst = []
    for _ in range(m):
        l, r = input().split()
        l = int(l) - 1
        r = int(r) - 1
        lst.append((l, r))

    print(solve(n, m, s, lst))


if __name__ == '__main__':
    main()



Measured memory_bytes: 76012
#include <bits/stdc++.h>
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Weverything"
#include <boost/multi_array.hpp>
#include <boost/optional.hpp>
#include <boost/range/adaptors.hpp>
#include <boost/range/algorithm.hpp>
#include <boost/range/irange.hpp>
#pragma clang diagnostic pop

using namespace std;

static int h;
static int w;

std::pair<int, int> paint(boost::multi_array<int8_t, 2>& ss, int y, int x) {
  auto ret = std::pair<int, int>(0, 0);
  auto const currentColor = ss[y][x];
  assert(currentColor == 0 || currentColor == 1);
  ss[y][x] = -1;
  if (currentColor == 0) {
    ret.first++;
  } else {
    ret.second++;
  }
  auto const alternativeColor = 1 - currentColor;
  if (x < w - 1 && ss[y][x + 1] == alternativeColor) {
    auto painted = paint(ss, y, x + 1);
    ret.first += painted.first;
    ret.second += painted.second;
  }
  if (y < h - 1 && ss[y + 1][x] == alternativeColor) {
    auto painted = paint(ss, y + 1, x);
    ret.first += painted.first;
    ret.second += painted.second;
  }
  if (x > 0 && ss[y][x - 1] == alternativeColor) {
    auto painted = paint(ss, y, x - 1);
    ret.first += painted.first;
    ret.second += painted.second;
  }
  if (y > 0 && ss[y - 1][x] == alternativeColor) {
    auto painted = paint(ss, y - 1, x);
    ret.first += painted.first;
    ret.second += painted.second;
  }
  return ret;
}

int64_t solve(boost::multi_array<int8_t, 2>& ss) {
  int64_t ret = 0;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (ss[i][j] < 0) {
        continue;
      }
      auto painted = paint(ss, i, j);
      ret += static_cast<int64_t>(painted.first) *
             static_cast<int64_t>(painted.second);
    }
  }
  return ret;
}

int main() {
  std::cin.tie(nullptr);
  std::ios::sync_with_stdio(false);
  std::cin >> h;
  std::cin >> w;
  boost::multi_array<int8_t, 2> ss(boost::extents[h][w]);
  for (int i = 0; i < h; i++) {
    std::string s;
    std::cin >> s;
    for (int j = 0; j < w; j++) {
      ss[i][j] = static_cast<int8_t>(s[j] == '#');
    }
  }
  auto const res = solve(ss);
  std::cout << res << std::endl;
  return 0;
}


Measured memory_bytes: 12928
import sys
m=500000;a=[1]*m
for i in range(3,999,2):
 if a[i//2]:a[i*i//2::i]=[0]*len(a[i*i//2::i])
p=[]
for i in range(m*2):p.append(i-1 if i<4 else p[i-1]+[0,a[i//2]][i%2])
for e in sys.stdin:print(p[int(e)])


Measured memory_bytes: 50420
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>

using namespace std;
#define rep(i, s, e) for (int(i) = (s); (i) <= (e); ++(i))

int main()
{
	int n, a, b;
	cin >> n >> a >> b;
	if ((b - a) % 2 == 0)
	{
		cout << "Alice" << endl;
	}
	else
	{
		cout << "Borys" << endl;
	}
}

Measured memory_bytes: 256
K, N = list(map(int,input().split()))
A = list(map(int,input().split()))
for i in range(len(A)):
    now_point = A[i]
    last_point = A[i-1]
    if last_point == 0:
        last_point = K
    if last_point - now_point <= 0:
        now_min = (K-now_point) + last_point
    else:
        now_min = last_point - now_point
    if i==0:
        total_min = now_min
    else:
        if now_min < total_min:
            total_min = now_min
print(total_min)

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

#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(v) reverse((v).begin(),(v).end())
#define ANS(ans) cout<<(ans)<<endl;
#define UNIQUE(v) (v).erase(unique((v).begin(), (v).end()), (v).end());
typedef vector<int> VI;
typedef pair<int, int> P;
 
//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  for (int i = 0; i < (n); ++i)

int main() {
  int n,r;
  cin>>n>>r;

  if(n>=10){
    ANS(r);
  }
  else{
    int naibu = r+100*(10-n);
    ANS(naibu);
  }
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#define For(x) for(int h=head[x],o=V[h],w=W[h]; h; o=V[h=to[h]],w=W[h])
using namespace std;
int head[100005],to[1000005],V[1000005],W[1000005],num;
int q[10000005],l,r,f[100005],dis[100005];
int k;
void Add(int x,int y,int z){
	to[++num]=head[x],head[x]=num,V[num]=y,W[num]=z;
}

void SPFA(){
	memset(dis,0x7f,sizeof(dis));
	for (int i=1; i<10; i++) q[++r]=dis[i]=f[i]=i;
	for (l=1; l<=r; l++){
		For(q[l]) if (dis[o]>dis[q[l]]+w){
			dis[o]=dis[q[l]]+w;
			if (!f[o]){
				f[o]=1;
				q[++r]=o;
			}
		}
		f[q[l]]=0;
	}
}

void debug(){
	for (int i=0; i<k; i++){
		printf("%d\t",i);
		For(i) printf("(%d %d) ",o,w);
		puts("");
	}
	puts("");
}

int main(){
	scanf("%d",&k);
	
	for (int i=1; i<k; i++)
		for (int j=0; j<10; j++)
			Add(i,(i*10+j)%k,j);
	
	//debug();
	SPFA();
	printf("%d",dis[0]);
}

Measured memory_bytes: 19328
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#define rep(i,n) for (int i = 0; i <= (n); ++i)
#define rip(i,n) for (int i = 1; i <= (n); ++i)
using namespace std;
int main() {
	int p, q, r;
	cin >> p >> q >> r;
	vector<int>a(6);
	a[0] = p + q;
	a[1] = r + q;
	a[2] = p + r;
	a[3] = q + r;
	a[4] = r + p;
	a[5] = p + q;
	cout << min({a[0],a[1],a[2],a[3],a[4],a[5] }) << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int P = 1e4;
const ll MOD = 1e9 + 7;

int F[P], pnum, prime[P];
int main() {
  ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  for (int i = 2; i < P; ++i) {
    if (F[i] == 0) F[i] = prime[++pnum] = i;
    int j = 1;
    while (j <= pnum && prime[j] <= F[i] && i * prime[j] < P)
      F[i * prime[j]] = prime[j], ++j;
  }

  int n; cin >> n;
  ll ans = 1;
  for (int i = 1; i <= pnum; ++i) {
    int x = n, cnt = 0;
    while (x) {
      x /= prime[i];
      cnt += x;
    }
    (ans *= cnt + 1) %= MOD;
  }
  cout << ans;
  return 0;
}

Measured memory_bytes: 256
fun main(args: Array<String>) {

    val N = readLine()!!.toInt()
    val AX = readLine()!!.split(" ").map(String::toLong)

    fun gcd(a: Long, b: Long): Long {
        return if (b > 0) gcd(b, a % b) else a
    }

    AX.reduce { acc, e -> gcd(acc, e) }.let(::println)

}


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


int main() {
  int a;
  cin >> a;
  if(400<=a && a<=599){
    cout << 8;
  }
  if(600<=a && a<=799){
    cout << 7;
  }
  if(800<=a && a<=999){
    cout << 6;
  }
  if(1000<=a && a<=1199){
    cout << 5;
  }
  if(1200<=a && a<=1399){
    cout << 4;
  }
  if(1400<=a && a<=1599){
    cout << 3;
  }
  if(1600<=a && a<=1799){
    cout << 2;
  }
  if(1800<=a && a<=1999){
    cout << 1;
  }
}

Measured memory_bytes: 3632
//#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<set>
#include<map>

/*
#include<boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/rational.hpp>
namespace mp = boost::multiprecision;
using Real = mp::number<mp::cpp_dec_float<1024>>;
using Bint = mp::cpp_int;
*/

using namespace std;

#define int long long
#define REP(i,s,e) for((i)=(s);(i)<(e);(i)++)
#define RREP(i,s,e) for((i)=((s)-1);(i)>=(e);(i)--)
#define FOR(i,n) for((i)=(0);(i)<(n);(i)++)
#define RFOR(i,n) for((i)=((n)-1);(i)>=(0);(i)--)
#define MOD 1000000007


signed main(){
    string s;
    int n;
    cin>>n;
    cin>>s;
    s+="QQQQQ";
    int c=0;
    for(int i=0;i<n;i++){
        if(s.substr(i,3)=="ABC") c++;
    }
    cout<<c<<endl;
}


Measured memory_bytes: 3640