akhauriyash/Code-Regression huggingface dataset:
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
#define rep(i,a,b) for (int i = (a); i < (b); i++)
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
typedef complex<double> com;
const int mod = 1e9 + 7;
const int MOD = 998244353;
const int inf = 2e9;



int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	string s; cin >> s;
	int cnt = 0;
	rep(i, 0, s.size()) if (s[i] == 'x') cnt++;
	if (cnt > 7) printf("NO");
	else printf("YES");
	return 0;
}


Measured memory_bytes: 256
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef double db;

#define fr first
#define sc second
#define pb push_back
#define rep(i,x) for(ll i=0;i<x;i++)
#define rep1(i,x) for(ll i=1;i<=x;i++)
#define rrep(i,x) for(ll i=x-1;i>=0;i--)
#define rrep1(i,x) for(ll i=x;i>0;i--)
#define plus asdgew
ll H,W;
string s[1000];
ll cnt[1000][1000];
string f[2];
char c[4]="JOI";
ll ans=0;
ll plus;
ll ok(ll y,ll x){
	rep(i,2) rep(j,2){
		if(f[i][j]!=s[y+i][x+j]) return 0;
	}
	return 1;
}

ll calc(ll y,ll x){
	ll res=0;
	auto jud = [](ll Y,ll X){
		return 0<=Y&&Y<H-1&&0<=X&&X<W-1;
	};
	char cc=s[y][x];
	rep(i,3){
		ll bs=0;
		if(cc==c[i]) continue;
		s[y][x]=c[i];
		if(jud(y-1,x-1)) bs+=ok(y-1,x-1);
		if(jud(y,x-1)) bs+=ok(y,x-1);
		if(jud(y-1,x)) bs+=ok(y-1,x);
		if(jud(y,x)) bs+=ok(y,x);
		res=max(res,bs);
	}
	s[y][x]=cc;
	return res-cnt[y][x];
}

int main()
{
	cin>>H>>W;
	rep(i,H) cin>>s[i];
	cin>>f[0]>>f[1];
	rep(i,H-1) rep(j,W-1){
		if(s[i][j]==f[0][0]&&s[i+1][j]==f[1][0]&&s[i][j+1]==f[0][1]&&s[i+1][j+1]==f[1][1]){
			ans++;
			cnt[i][j]++;
			cnt[i+1][j]++;
			cnt[i][j+1]++;
			cnt[i+1][j+1]++;
		}
	}
	plus=0;
	/*rep(i,H){
		rep(j,W){
			cout<<cnt[i][j];
		}
		cout<<endl;
	}*/
	rep(i,H) rep(j,W) plus=max(plus,calc(i,j));
	cout<<ans+plus<<endl;
}

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

using namespace std;

int main() {
	int k, a, b;
	cin >> k >> a >> b;
	if (a >= b - 2 || k <= a - 1) {
		cout << k + 1 << endl;
	} else {
		k -= a - 1;
		int kk = k / 2;
		long long ans = a;
		ans += 1LL * kk * (b - a);
		if (k & 1) {
			ans++;
		}
		cout << ans << endl;
	}
	return 0;
}

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

typedef struct{
  int p,r,l;
}Node;

Node T[N];
int n,D[N],H[N];

int depth(int);
int degree(int);
int hight(int);
int subiling(int);
void print(int);

int main()
{
int i,j,p,l,r,n;
	scanf("%d", &n);
	for(i=0; i<n; i++){
		T[i].p = -1;
		T[i].l = -1;
		T[i].r = -1;
	}
	for(i=0; i<n; i++){
		scanf("%d%d%d",&p,&l,&r);
		T[l].p = p;
		T[r].p = p;
		T[p].l = l;
		T[p].r = r;
	}
	for(i=0; i<n; i++){
		print(i);
	}
	return 0;
}
   
int depth(int c){
  int cnt = 0;
  if(T[c].p == -1){
    return 0;
  }
  else{
    cnt = depth(T[c].p) + 1;
    return cnt;
  }
}

int degree(int x){
  if(T[x].l ==-1 && T[x].r == -1){
    return 0;
  }
  else if(T[x].l !=-1 && T[x].r != -1){
    return 2;
  }
  else
    return 1;
}

int hight(int s){
	int h1 = 0, h2 = 0;
	if(T[s].l != -1){
		h1 = hight(T[s].l ) + 1;
	}
	if(T[s].r != -1){
		h2 = hight(T[s].r) + 1;
	}
 
	if(h1 < h2)return H[s] = h2;
	else return H[s] = h1;
}
 
int sibiling(int s){
	if(T[s].p == -1)return -1;
	if(T[T[s].p].l != -1 && T[T[s].p].l != s ){
		return T[T[s].p].l;
	}
	if(T[T[s].p].r != -1 && T[T[s].p].r != s ){
		return T[T[s].p].r;
	}
	return -1;
}

void print(int f){
	printf("node %d: parent = %d, sibling = %d, degree = %d, ",f, T[f].p, sibiling(f),degree(f));
	printf("depth = %d, height = %d, ",depth(f),hight(f));
	if(T[f].p == -1){
		printf("root\n");
	}
	else if(T[f].l == -1 && T[f].r == -1){
		printf("leaf\n");
	}
	else{
		printf("internal node\n");
	}
}

Measured memory_bytes: 620
#include <bits/stdc++.h>
using namespace std;
int main() {
  double a,b;
  cin >> a >> b;
  
  double x = (a + b)/2;
  int d = x;//小数点以下を捨てる
  int e = 1 + d - x;//割り切れてたら1、割り切れてなかったら0
  int Answer = d - e + 1;
  cout << Answer << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
 int main() {
   string b;

	cin >> b;
	if (b == "A")
	{
		cout << "T" << endl;
	}
	else if (b == "T")
	{
		cout << "A" << endl;
	}
	else if (b == "G")
	{
		cout << "C" << endl;
	}
	else
	{
		cout << "G" << endl;

	}

}

Measured memory_bytes: 256
import math

while True:
    n = int(input())
    if n == 0:
        break
    sum=0
    m=math.factorial(n)
    m=str(m)
    for i in range(len(m)-1,-1,-1):
        if m[i]==str(0):
            sum+=1
        else:
            break
    print(sum)


Measured memory_bytes: 5808
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define FOR(i,n,j) for(int i=(j);i<(n);++i)
#define rrep(i,n) for(int i=(n);i>=0;--i)
#define ssort(n) sort((n).begin(),(n).end())
using ll=long long;
using ld=long double;
typedef pair<int,int> P;
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define INF 10101010

int main()
{
    int n;
    cin >> n;
    string s;
    int count_ac=0;
    int count_wa=0;
    int count_tle=0;
    int count_re=0;
    rep(i,n){
        cin >> s;
        if(s=="AC"){
            count_ac++;
        }else if(s=="WA"){
            count_wa++;
        }else if(s=="TLE"){
            count_tle++;
        }else{
            count_re++;
        }
    }
    printf("AC x %d\n",count_ac);
    printf("WA x %d\n",count_wa);
    printf("TLE x %d\n",count_tle);
    printf("RE x %d\n",count_re);
}

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

const int nmax=8;
bool graph[nmax][nmax];

int dfs(int v,int N,bool visited[nmax]){

bool all_visited=true;

for(int i=0;i<N;++i){
if(visited[i]==false)
all_visited=false;
}

if(all_visited){
return 1;
}

int ret=0;

for(int i=0;i<N;++i){
if(graph[v][i]==false) continue;
if(visited[i]) continue;

visited[i]=true;
ret+=dfs(i,N,visited);
visited[i]=false;
}
 return ret;
}

int main(void){
int N,M;
cin >> N >> M;

for(int i=0;i<M;++i){
int A,B;
cin >> A >> B;
graph[A-1][B-1]=graph[B-1][A-1]=true;
}

bool visited[nmax];
for(int i=0;i<N;++i){
visited[i]=false;
}
visited[0]=true;
cout << dfs(0,N,visited) << endl;
return 0;
 }

Measured memory_bytes: 256
// https://atcoder.jp/contests/abc109/tasks/abc109_d
#include <bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int h, w, t;
    cin >> h >> w;
    vector<vector<int>> v(h);
    REP(i, h) REP(j, w) {
        cin >> t;
        v[i].push_back(t);
    }
    bool coin = false;
    vector<pii> ans, tmp;
    REP(i, h) REP(j, w) {
        int k = (i % 2 == 0 ? j : (w - j - 1));
        if (coin) {
            tmp.push_back({i + 1, k + 1});
        }
        if (v[i][k] % 2 == 1) {
            if (coin) {
                coin = false;
                // 出力は1-indexed
                for (auto &x : tmp) {
                    ans.push_back(x);
                }
                tmp.clear();
            } else {
                coin = true;
            }
        }
        if (coin) {
            tmp.push_back({i + 1, k + 1});
        }
    }
    // 最後に移動させるためにボールを持ったまま終わることを考慮
    cout << ans.size() / 2 << "\n";
    REP(i, ans.size()) {
        cout << ans[i].first << " " << ans[i].second << (i % 2 ? "\n" : " ");
    }

    return 0;
}


Measured memory_bytes: 5232
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define leading zero str.erase(0, min(str.find_first_not_of('0'), str.size()-1));
using namespace __gnu_pbds;
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
string text="abcdefghijklmnopqrstuvwxyz";
const int maxn=1e6+7;
//        .--------------.
//        | Try First One|
//        '--------------'
//                |     .--------------.
//                |     |              |
//                V     V              |
//              .--------------.       |
//              |      AC.     |<---.  |
//              '--------------'    |  |
//              (True)|  |(False)   |  |
//           .--------'  |          |  |
//           |           V          |  |
//           |  .--------------.    |  |
//           |  |   Try Again  |----'  |
//           |  '--------------'       |
//           |                         |
//           |  .--------------.       |
//           '->| Try Next One |-------'
//              '--------------'
ll bin_pow(ll a,ll b,ll m)
{
    ll res=1;
    a%=m;
    while(b>0)
    {
        if(b&1)
            res=res*a%m;
        b>>=1;
        a=a*a%m;
    }
    return res;
}
bool miller_rabin(ll d,ll n)
{
    ll a=2+rand()%(n-4);
    ll x=bin_pow(a,d,n);
    if(x==1 || x==n-1)
        return true;
    while(d!=n-1)
    {
        x=(x*x)%n;
        d*=2;
        if(x==1)
            return false;
        if(x==n-1)
            return true;
    }
    return false;
}
bool prime(ll n,ll k)
{
    if(n==1 || n==4)
        return false;
    if(n<=3)
        return true;
    ll d=n-1;
    while(d%2==0)
        d/=2;
    for(int i=0; i<k; i++)
    {
        if(!miller_rabin(d,n))
            return false;
    }
    return true;
}
int n;
string s;
ll ans = 0;

void solve(ll x,ll y){
    if(x==n+1){
        ans += y;
        return;
    }
    ll cur = 0;
    for(ll i=x;i<=n;i++){
        cur = (10*cur) + (s[i]-'0');
        solve(i+1,y+cur);
    }
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll a,b;
    cin>>a>>b;
    if(abs(a-b)>1)return 0*puts("0");
    ll mod=1e9+7;
    ll f=1;
    if(a==b)f=2;
    for(ll i=2;i<=a;i++){
        f*=i;
        f%=mod;
    }
    for(ll i=2;i<=b;i++){
        f*=i;
        f%=mod;
    }
    cout<<f<<endl;
}


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

#define REP(i,n) for(int i = 0;i < n;i++)
#define REPR(i,n) for(int i = n-1;i >= 0;i--)
#define FOR(i,m,n) for(int i = m;i < n;i++)
#define INF 2e9
#define ALL(v) v.begin(),v.end()
#define ll long long
#define GREATER greater<int>()

using namespace std;

string pop_back(string s){
    string t = s.substr(0,s.size()-1);
    return t;
}

int gcd(int max,int min){
    
    if(max<min){
        int tmp=max;
        max=min;
        min=tmp;
    }

    if(max%min==0)return min;
    else return gcd(min,max%min);

}

int main(void){

    int x;
    cin>>x;
    int ans=1;
    for(int i=2;i<=x;i++){
        int now = i;
        while(now<=x){
            now*=i;
            if(now<=x)
            ans=max(ans,now);
        }
    }
    cout<<ans<<endl;

    return 0;
}




Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int n,m;
vector<int>G[10005];
vector<int>rG[10005];
vector<int>vs;
bool used[10005];
int cmp[10005];
int s[100005],t[100005];
int in[10005],out[10005];
void dfs(int v){
    used[v]=true;
    for(int i=0;i<G[v].size();i++){
        if(!used[G[v][i]])dfs(G[v][i]);
    }
    vs.push_back(v);
}
void rdfs(int v,int k){
    used[v]=true;
    cmp[v]=k;
    for(int i=0;i<rG[v].size();i++){
        if(!used[rG[v][i]])rdfs(rG[v][i],k);
    }
}
int main(void){
    cin>>n>>m;
    for(int i=0;i<m;i++){
        cin>>s[i]>>t[i];
        G[s[i]].push_back(t[i]);
        rG[t[i]].push_back(s[i]);
    }
    for(int i=0;i<n;i++)used[i]=false;
    for(int i=0;i<n;i++)if(!used[i])dfs(i);
    for(int i=0;i<n;i++)used[i]=false;
    int k=0;
    for(int i=vs.size()-1;i>=0;i--){
        if(!used[vs[i]])rdfs(vs[i],k++);
    }
    if(k==1){
        cout<<0<<endl;
        return 0;
    }
    int ain=k,aout=k;
    for(int i=0;i<m;i++){
        if(cmp[s[i]]!=cmp[t[i]]){
            if(out[cmp[s[i]]]==0){
                aout--;
                out[cmp[s[i]]]=1;
            }
            if(in[cmp[t[i]]]==0){
                ain--;
                in[cmp[t[i]]]=1;
            }
        }
    }
    cout<<max(ain,aout)<<endl;
}

Measured memory_bytes: 6420
#ifndef BZ
#pragma GCC optimize "-O3"
#endif
#include <bits/stdc++.h>

#define FASTIO
#define ALL(v) (v).begin(), (v).end()
#define rep(i, l, r) for (int i = (l); i < (r); ++i)

#ifdef FASTIO
#define scanf abacaba
#define printf abacaba
#endif

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

using namespace std;


/*
ll pw(ll a, ll b) {
	ll ans = 1; while (b) {
		while (!(b & 1)) b >>= 1, a = (a * a) % MOD;
		ans = (ans * a) % MOD, --b;
	} return ans;
}
*/

const ll MOD = 998244353;
const ll MAXN = 4100;

int n, k;

ll dp[MAXN][MAXN];
ll pl[MAXN][MAXN];

int main() {
#ifdef FASTIO
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#endif
	cin >> k >> n;
	dp[0][0] = 1;
	for (int i = 1; i <= k; ++i) {
		ll sum = 0;
		for (int j = 0; j <= n; ++j) {
			sum = (sum + dp[i - 1][j]) % MOD;
			dp[i][j] = sum;
		}
	}
	pl[0][0] = 1;
	for (int i = 1; i <= k; ++i) {
		pl[i][0] = (MOD - pl[i - 1][0]) % MOD;
		for (int j = 1; j <= i; ++j)
			pl[i][j] = (2 * pl[i - 1][j - 1] - pl[i - 1][j] + MOD) % MOD;
	}
	for (int i = 2; i <= 2 * k; ++i) {
		int c0 = 0;
		int c1 = 0;
		for (int j = 1; j <= k; ++j) {
			if (j * 2 == i)
				continue;
			if (j >= i || j + k < i)
				++c0;
			else if (j < i - j)
				++c1;
		}
		ll ans = 0;
		for (int j = 0; j <= k; ++j)
			ans = (ans + pl[c1][j] * dp[c0 + j][n]) % MOD;
		if (i % 2 == 0) {
			for (int j = 0; j <= k; ++j)
				ans = (ans + pl[c1][j] * dp[c0 + j][n - 1]) % MOD;
		}
		cout << ans << "\n";
	}
	return 0;
}




Measured memory_bytes: 129536
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>

#define rep(i,n) for(int i=0;i<n;i++)
#define ll long long int
#define MAX 1000000007

using namespace std;

int main(void){
  int n;
  cin >> n;
  ll a[n];
  rep(i,n) cin >> a[i];
  sort(a,a+n);
  ll ans = 0, idx = n-1;
  for(int i=0;i<n-1;i++){
    ans += a[idx];
    if(i%2 == 0)idx--;
  }  
  cout << ans << endl;

}


Measured memory_bytes: 5196
#include <iostream>
#include <vector>
#include <complex>
#include <algorithm>
#include <cmath>
#include <cstdio>

using namespace std;

const double EPS = 1e-8;
typedef complex<double> P;
double rot(P a, P b) { return arg(conj(a)*b); }

namespace std{
	bool operator < (const P &a, const P &b){
		return make_pair(real(a),imag(a)) < make_pair(real(b),imag(b));
	}
}

int main(){
	int n;
	while(cin >> n, n){
		vector<P> vp1(n), vp2(n);
		P g1 = P(0,0), g2 = P(0,0);
		double x, y;
		for(int i=0;i<n;i++){
			cin >> x >> y; vp1[i] = P(x,y);
			g1 += vp1[i];
		}
		for(int i=0;i<n;i++){
			cin >> x >> y; vp2[i] = P(x,y);
			g2 += vp2[i];
		}
		g1 /= n;
		g2 /= n;
		for(int i=0;i<n;i++){
			vp1[i] -= g1;
			vp2[i] -= g2;
		}
		sort(vp1.begin(), vp1.end());
		double ans = 1e12;
		for(int i=0;i<n;i++){
			if(abs(abs(vp1[0])-abs(vp2[i])) < EPS){
				double r = rot(vp2[i], vp1[0]);
				vector<P> tmp(n);
				for(int j=0;j<n;j++){					
					tmp[j] = P(real(vp2[j])*cos(r)-imag(vp2[j])*sin(r),real(vp2[j])*sin(r)+imag(vp2[j])*cos(r));
				}
				sort(tmp.begin(), tmp.end());
				bool flag = true;
				for(int j=0;j<n;j++){
					flag &= (abs(vp1[j]-tmp[j]) < EPS);
				}
				if(flag) ans = min(ans, abs(r));
			}
		}
		printf("%.10lf\n", ans);
	}
}

Measured memory_bytes: 1024
#![allow(unused_macros)]
#![allow(dead_code)]
#![allow(unused_imports)]

use itertools::Itertools;
use num_integer::gcd;
use proconio::*;
use text_io::*;
use std::collections::HashSet;

const U_INF: usize = 1 << 60;
const I_INF: isize = 1 << 60;

fn main() {
    input! {
        n:usize,
        a:[usize;n],
    }

    let mut sum = 0;
    for &ai in &a {
        sum = gcd(sum, ai);
    }

    let max = a.iter().max().unwrap();

    let pf = prime_factorization(*max);
    let mut primes = vec![0; max + 10];

    for ai in a {
        for &p in &pf[ai] {
            primes[p] += 1;
        }
    }

    let pairwise = *primes.iter().max().unwrap() <= 1;
    let setwise = sum == 1;

    let ans = if pairwise {
        "pairwise coprime"
    } else if setwise {
        "setwise coprime"
    } else {
        "not coprime"
    };
    
    println!("{}", ans);
}

fn prime_factorization(n: usize) -> Vec<HashSet<usize>> {
    let mut v = vec![HashSet::new(); n + 10];

    for i in 2..=n {
        if v[i].len() <= 1 {
            v[i].insert(i);
            let mut j = 2;
            while i * j <= n {
                v[i * j].insert(i);
                j += 1;
            }
        }
    }

    v
}


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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

int n, a, b;

vector<int> arr, ans;
vector<int> two[3]={{0, 1, 3, 2}, {2, 3, 1, 0}, {2, 0, 1, 3}};

int s, d;
vector<int> av, bv, dpos, spos;

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

    scanf("%d%d%d", &n, &a, &b);
    int ca, cb;
    ca=__builtin_popcount(a); cb=__builtin_popcount(b);
    if((ca-cb)%2==0) return !printf("NO");
    printf("YES\n");

    arr.push_back(0); arr.push_back(1);

    for(i=0; i<n; i++)
    {
        av.push_back((a&(1<<i))!=0);
        bv.push_back((b&(1<<i))!=0);
        if(av[i]!=bv[i]) d++, dpos.push_back(i);
        else s++, spos.push_back(i);
    }

    for(i=3; i<=d; i+=2)
    {
        vector<int> V;
        int t=0;
        for(j=0; j<arr.size(); j++)
        {
            if(j==arr.size()-1) t=2;
            int now=arr[j]<<2;
            for(k=0; k<4; k++)
            {
                V.push_back(now+two[t][k]);
            }
            t=1-t;
        }
        arr=V;
    }

    //for(int i : arr) printf("%d\n", i);
    //printf("----------\n");

    for(i=0; i<arr.size(); i++)
    {
        int now=0;
        for(j=0; j<d; j++) if(av[dpos[j]]) arr[i]^=(1<<j);
        for(j=0; j<d; j++)
        {
            int t=(arr[i]&(1<<j))!=0;
            now+=t<<dpos[j];
        }
        ans.push_back(now);
    }

    //for(int i : ans) printf("%d\n", i);

    for(j=0; j<s; j++)
    {
        vector<int> V;
        for(i=0; i<ans.size(); i++) V.push_back(ans[i]), V.push_back(ans[i]);
        for(i=0; i<V.size(); i+=4)
        {
            int t=spos[j];
            if(av[t])
            {
                V[i]+=(1<<t);
                V[i+3]+=(1<<t);
            }
            else
            {
                V[i+1]+=(1<<t);
                V[i+2]+=(1<<t);
            }
        }
        ans=V;
    }

    for(int i : ans) printf("%d ", i);

    return 0;
}


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

template <typename T, typename _ = void>
struct is_container : std::false_type {};
template <typename T>
struct is_container<T, std::void_t<decltype(std::declval<T>().begin()),
                                   decltype(std::declval<T>().end())>>
    : std::true_type {};
template <typename T, typename _ = void>
struct is_pair : std::false_type {};
template <typename T>
struct is_pair<T, std::void_t<decltype(std::declval<T>().first),
                              decltype(std::declval<T>().second)>>
    : std::true_type {};
template <typename T>
void debug(const T& v) {
  if constexpr (is_pair<T>::value) {
    std::cerr << "{";
    debug(v.first);
    std::cerr << ", ";
    debug(v.second);
    std::cerr << "}";
  } else if constexpr (is_container<T>::value) {
    std::cerr << "{";
    for (auto it = v.begin(); it != v.end(); ++it) {
      if (it != v.begin()) std::cerr << ", ";
      debug(*it);
    }
    std::cerr << "}";
  } else {
    std::cerr << v;
  }
}
template <typename T, typename... Ts>
void debug(const T& value, const Ts&... args) {
  debug(value);
  std::cerr << ", ";
  debug(args...);
}
#if DEBUG
#define dbg(...)                        \
  do {                                  \
    cerr << #__VA_ARGS__ << ": ";       \
    debug(__VA_ARGS__);                 \
    cerr << " (L" << __LINE__ << ")\n"; \
  } while (0)
#else
#define dbg(...)
#endif

void read_from_cin() {}
template <typename T, typename... Ts>
void read_from_cin(T& value, Ts&... args) {
  std::cin >> value;
  read_from_cin(args...);
}
#define rd(type, ...) \
  type __VA_ARGS__;   \
  read_from_cin(__VA_ARGS__);

template <typename T>
void write_to_cout(const T& value) {
  if constexpr (std::is_same<T, bool>::value) {
    std::cout << (value ? "Yes" : "No");
  } else {
    std::cout << value;
  }
}
template <typename T, typename... Ts>
void write_to_cout(const T& value, const Ts&... args) {
  write_to_cout(value);
  std::cout << ' ';
  write_to_cout(args...);
}
#define wt(...)                 \
  do {                          \
    write_to_cout(__VA_ARGS__); \
    cout << '\n';               \
  } while (0)

#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rrep(i, n) for (int i = (int)(n)-1; i >= 0; --i)

template <typename T>
std::istream& operator>>(std::istream& is, std::vector<T>& v) {
  for (T& vi : v) is >> vi;
  return is;
}

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

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

#include <boost/hana/functional/fix.hpp>
auto Fix = boost::hana::fix;

using ll = long long;

template <typename T>
using low_priority_queue =
    std::priority_queue<T, std::vector<T>, std::greater<T>>;

template <typename T>
using V = std::vector<T>;
template <typename T>
using VV = V<V<T>>;

using namespace std;

int main() {
  rd(int, n);
  wt(n / 3);
}


Measured memory_bytes: 3544
object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val h, w = sc.nextInt()
  val a = Array.fill(h)(sc.next())
  println("#" * (w+2))
  a.map(s => s"#$s#").foreach(println)
  println("#" * (w+2))
}


Measured memory_bytes: 56016
#include <iostream>
#include <cstdint>
#include <vector>
#include <numeric>
#include <map>

class RuntimeModInt {
    using u64 = std::uint_fast64_t;
    
    static u64 &mod() {
        static u64 mod_ = 0;
        return mod_;
    }

public:
    u64 num;
    
    RuntimeModInt(const u64 x = 0) : num(x % get_mod()) {}
    u64 &value() noexcept { return num; }
    const u64 &value() const noexcept { return num; }
    RuntimeModInt operator+(const RuntimeModInt rhs) const {
        return RuntimeModInt(*this) += rhs;
    }
    RuntimeModInt operator-(const RuntimeModInt rhs) const {
        return RuntimeModInt(*this) -= rhs;
    }
    RuntimeModInt operator*(const RuntimeModInt rhs) const {
        return RuntimeModInt(*this) *= rhs;
    }
    RuntimeModInt operator/(const RuntimeModInt rhs) const {
        return RuntimeModInt(*this) /= rhs;
    }

    RuntimeModInt &operator+=(const RuntimeModInt rhs) {
        num += rhs.num;
        if (num >= get_mod()) {
            num -= get_mod();
        }
        return *this;
    }
    RuntimeModInt &operator-=(const RuntimeModInt rhs) {
        if (num < rhs.num) {
            num += get_mod();
        }
        num -= rhs.num;
        return *this;
    }
    RuntimeModInt &operator*=(const RuntimeModInt rhs) {
        num = num * rhs.num % get_mod();
        return *this;
    }
    RuntimeModInt &operator/=(RuntimeModInt rhs) {
        u64 exp = get_mod() - 2;
        while (exp) {
            if (exp % 2) {
                *this *= rhs;
            }
            rhs *= rhs;
            exp /= 2;
        }
        return *this;
    }

    RuntimeModInt &operator=(const u64 num) noexcept {
        this->num = num % get_mod();
        return *this;
    }

    RuntimeModInt pow(u64 k){
        return pow(num, k);
    }

    RuntimeModInt pow(RuntimeModInt x, u64 k) {
		if (k == 0) return 1;
		if (k % 2 == 0) return pow((x * x).num % get_mod(), k / 2);
		else return (x * pow(x, k - 1)).num % get_mod();
	}
    static void set_mod(const u64 x) { mod() = x; }
    static u64 get_mod() { return mod(); }
};

std::ostream &operator<<(std::ostream &out, const RuntimeModInt &m)
{
    out << m.num;
    return out;
}

std::istream &operator>>(std::istream &in, RuntimeModInt &m)
{
    in >> m.num;
    if(m.num >= m.get_mod()){
        m.num %= m.get_mod();
    }
    return in;
}

using namespace std;

int main(){
    int n, m;
    cin >> n >> m;
    RuntimeModInt::set_mod(m);
    vector<RuntimeModInt> a(n), b(n + 1);
    for(auto&& i : a){
        cin >> i;
    }
    for(int i = 0; i < n; i++){
        b[i + 1] = b[i] + a[i];
    }
    map<uint_fast64_t, int> cnt;
    long long ans = 0;
    for(auto&& i : b){
        ans += cnt[i.num];
        cnt[i.num]++;
    } 
    cout << ans << "\n";
}

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

int main() {
  char c;
  cin >> c;
  if(c == 'a'|| c == 'i'|| c == 'u'|| c == 'e'|| c == 'o'){
    cout << "vowel" << endl;
  }else{
    cout << "consonant" << endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define  pb push_back
#define  xx first
#define  yy second
#define ll long long
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

using namespace std;
int h,n;
int dp[1001][100100];
int a[4000],b[4000];

int go(int i,int sum){

         if(i>n) return 1e9;
         if(sum<=0) return 0;
        if(dp[i][sum]!=-1) return dp[i][sum];
       dp[i][sum] =min(b[i]+go(i,sum-a[i]),go(i+1,sum));
       return dp[i][sum];
}
 int main()
{
    fast;
       cin >> h >> n;

     for(int i = 1; i<=n; i++){
        cin >> a[i] >> b[i];
     }
     memset(dp,-1,sizeof dp);
     cout << go(1,h) << '\n';

   return 0;
}


Measured memory_bytes: 392448
a, v = map(int, input().split())
b, w = map(int, input().split())
t = int(input())

if a == b:
  print('YES')
elif a < b:
  if b + w * t <= a + v * t:
    print('YES')
  else:
    print('NO')
else:
  if a - v * t <= b - w * t:
    print('YES')
  else:
	  print('NO')
  


Measured memory_bytes: 61940
# -*- coding: utf-8 -*-

class Stack: 
  
    def __init__(self): 
        self.items = [] 

    def isEmpty(self): 
        return len(self.items)==0  

    def push(self, item): 
        self.items.append(item) 

    def pop(self): 
        return self.items.pop()  

    def peek(self): 
        if not self.isEmpty(): 
            return self.items[len(self.items)-1] 

    def size(self): 
        return len(self.items) 



V, E = list(map(int, input().split()))

L = []

for e in range(E):
  L.append(list(map(int, input().split())))
  
innode = []
stack = Stack()

for v in range(V):
  indegree = 0
  for l in L:
    if l[1] == v:
      indegree += 1
  innode.append(indegree)
  if indegree == 0:
    stack.push(v)
count = 0  
while not stack.isEmpty():
  node = stack.pop()
  count += 1
  for i in L:
    if i[0] == node:
      innode[i[1]] -= 1
      if innode[i[1]] == 0:
        stack.push(i[1])
  if count == V:
    print(0)
    break
else:
  print(1)


Measured memory_bytes: 5624
N = int(input())
S = input()
R = [0]*(N+1)
G = [0]*(N+1)
B = [0]*(N+1)
for i in range(N-1, -1, -1):
    R[i] = R[i+1]+1 if S[i] == "R" else R[i+1]
    G[i] = G[i+1]+1 if S[i] == "G" else G[i+1]
    B[i] = B[i+1]+1 if S[i] == "B" else B[i+1]
ans = 0
for i in range(N):
    for j in range(i+1, N):
        if S[i] != S[j]:
            c = ["R","G","B"]
            c.remove(S[i])
            c.remove(S[j])
            c = c[0]
            if c == "R":
                ans += R[j+1]
                if 2*j-i < N and S[2*j-i] == "R":
                    ans -= 1
            if c == "G":
                ans += G[j+1]
                if 2*j-i < N and S[2*j-i] == "G":
                    ans -= 1
            if c == "B":
                ans += B[j+1]
                if 2*j-i < N and S[2*j-i] == "B":
                    ans -= 1
print(ans)

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

int main(){
  string s; cin>>s;
  map<char,int> mp;
  rep(i,s.length()){
    mp[s[i]]++;
  }
  if(mp.size()%2==1) cout<<"No"<<endl;
  else if(mp.size()==2){
    if(mp['N']>0&&mp['S']>0) cout<<"Yes"<<endl;
    else if(mp['E']>0&&mp['W']>0) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
  }else cout<<"Yes"<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int N,W;
int v[101],w[101];
int dp[101][10001];

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


Measured memory_bytes: 7044
n,a,b = map(int,input().split())
s = list(input())

yes_num = 0
gai = 0

for i in s:
    if i == "a":
        if yes_num < a + b:
            yes_num += 1
            print("Yes")
        else:
            print("No")
    
    elif i == "b":
        if yes_num < a+b and gai < b:
            yes_num += 1
            gai += 1
            print("Yes")
        else:
            print("No")
    
    elif i == "c":
        print("No")

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

int main(){
    double n,t,a;
    cin >> n >> t >> a;
    double h;
    int ans;
    double near = 1000;
    for (int i = 0; i < n; i++){
        cin >> h;
        if (near > abs(a-t+h*0.006)){
            near = abs(a-t+h*0.006);
            ans = i + 1;
        }
    }

    cout << ans << endl;
}

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

int main(){
    int L;
    cin >> L;
    L--;
    int L1=L;
    int digit=0;
    int cnt =0; //0以外に貼る辺の本数
    while(L1>0){
        if(L1%2==0){
            cnt +=2;
            L1 = (L1-2)/2;
            digit++; continue;
        }
        else{
            cnt++;
            L1 = (L1-1)/2;
            digit++;
        }
    }

    int N=digit+1;
    cout << N << " " << cnt +N-1 << " " << endl;

    //1,....,Nを使う
    for(int i=0; i<N-1;i++){
        cout << i+1<< " " << i+2 << " " << 0 <<endl;
    }
    while(L>0){
        if(L%2==1){
            cout << N-1 << " "  << N << " " << (L+1)/2 << endl;
            L = (L-1)/2; N--; continue;
        }
            cout << 1 << " " << N << " " << L << endl;
            cout << N-1 << " " << N << " " << L/2 << endl;
            L = L/2-1; N--;
    }
}

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

using namespace std;


int main() {

    int K, X;
    cin >> K >> X;

    if ((500 * K) >= X) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
template<class T> inline bool chmax(T &a, T b) {if (a < b) {a = b;return 1;}return 0;}
template<class T> inline bool chmin(T &a, T b) {if (a > b) {a = b;return 1;}return 0;}

int main() {
  int a,b;
  cin >> a >> b;
  cout << (3*a + b) / 2 << endl;
}


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

signed main(void)
{
	int n, m, l;

	cin >> n;
	m = n / 100;
	l = n % 100;
	if (m * 5 >= l)
		cout << 1 << endl; 
	else
		cout << 0 << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int MAX1=100;
const int MAX2=10000000;
const int INF=0x3f3f3f3f;
int n,a[MAX1+5],p[MAX2+5],chk[MAX1*2+5],dir[MAX1*2+5][MAX1*2+5],ans;
vector<int> cx,c[2],seq;
vector<pii> conn[2*MAX1+5];
int dfs(int x,int y){
    int flow=0;
    if(x==y) return INF;
    chk[x]=1;
    for(int i=0;i<conn[x].size();i++) if(chk[conn[x][i].first]==0&&conn[x][i].second>0){
        int t=dfs(conn[x][i].first,y);
        if(t>0){
            flow=min(t,conn[x][i].second);
            seq.push_back(x);
            break;
        }
    }
    return flow;
}
int fflow(int x,int y){
    seq.clear(); seq.push_back(y);
    for(int i=0;i<c[0].size()+c[1].size()+2;i++) chk[i]=0;
    int flow=dfs(x,y);
    for(int i=0;i<seq.size()-1;i++) {
        int a=seq[i+1],b=seq[i];
        conn[a][dir[a][b]].second-=flow;
        conn[b][dir[b][a]].second+=flow;
        //for(int j=0;j<conn[a].size();j++) if(conn[a][j].first==b) conn[a][j].second-=flow;
        //for(int j=0;j<conn[b].size();j++) if(conn[b][j].first==a) conn[b][j].second+=flow;
    }
    return flow;
}
int main(){
    scanf("%d",&n);
    for(int i=0;i<n;i++) scanf("%d",&a[i]);
    cx.push_back(a[0]), cx.push_back(a[0]+1);
    for(int i=1;i<n;i++){
        if(cx[cx.size()-1]==a[i]) cx.pop_back();
        else cx.push_back(a[i]);
        cx.push_back(a[i]+1);
    }
    for(int i=2;i<=MAX2;i++){
        if(p[i]==0){
            p[i]=1;
            if(i<=3163) {for(int j=i*i;j<=MAX2;j+=i) p[j]=-1;}
        }
    }
    p[2]=-1;
    for(int i=0;i<cx.size();i++) c[cx[i]%2].push_back(cx[i]);
    for(int i=0;i<c[0].size();i++) for(int j=0;j<c[1].size();j++) if(p[abs(c[0][i]-c[1][j])]==1) {
        dir[i][c[0].size()+j]=conn[i].size();
        dir[c[0].size()+j][i]=conn[c[0].size()+j].size();
        conn[i].push_back(make_pair(c[0].size()+j,1));
        conn[c[0].size()+j].push_back(make_pair(i,0));
    }
    for(int i=0;i<c[0].size();i++) {
        dir[c[0].size()+c[1].size()][i]=conn[c[0].size()+c[1].size()].size();
        dir[i][c[0].size()+c[1].size()]=conn[i].size();
        conn[c[0].size()+c[1].size()].push_back(make_pair(i,1));
        conn[i].push_back(make_pair(c[0].size()+c[1].size(),0));
    }
    for(int i=0;i<c[1].size();i++) {
        dir[i+c[0].size()][c[0].size()+c[1].size()+1]=conn[i+c[0].size()].size();
        dir[c[0].size()+c[1].size()+1][i+c[0].size()]=conn[c[0].size()+c[1].size()+1].size();
        conn[i+c[0].size()].push_back(make_pair(c[0].size()+c[1].size()+1,1));
        conn[c[0].size()+c[1].size()+1].push_back(make_pair(i+c[0].size(),0));
    }
    while(fflow(c[0].size()+c[1].size(),c[0].size()+c[1].size()+1)) ans++;
    printf("%d\n",c[0].size()+c[1].size()-ans+(c[0].size()-ans)%2);
}


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

const int mod = 1e9 + 7;

map<int, int> prime_factor(int n) {
  map<int, int> res;
  for (int i = 2; i * i <= n; ++i) {
    while (n % i == 0) {
      ++res[i];
      n /= i;
    }
  }

  if (n != 1) res[n] = 1;
  return res;
}

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

  map<int, int> m;
  for (int i = 1; i <= n; ++i) {
    map<int, int> v = prime_factor(i);
    for (auto i : v) {
      m[i.first] += i.second;
    }
  }

  long long ans = 1;
  for (auto i : m) {
    ans *= (i.second + 1);
    ans %= mod;
  }

  cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
string s;
cin >> s;
if (s[0] == 'A')
    cout << "T";
if (s[0] == 'T')
    cout << "A";
if (s[0] == 'C')
    cout << "G";
if (s[0] == 'G')
    cout << "C";
}


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

int main(){
	int n,m,k ;
	cin >> n >> m >> k ;
	for(int i=0;i<=n;i++){
		for(int j=0;j<=m;j++){
			int sub = i*(m-j)+j*(n-i) ;
			if(sub==k){
				cout << "Yes" << endl ;
				return 0 ;
			}
		}
	}
	cout << "No" << endl ;
}


Measured memory_bytes: 256
n=int(input())
s=input()
data=[0]*(n+1)
for i in range(n):
  if s[i]=='E':
    data[i+1]=data[i]+1
  else:
    data[i+1]=data[i]
print(min(i-data[i]+data[n]-data[i+1] for i in range(n)))

Measured memory_bytes: 21000
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int[][] ty = new int[10000][2];
		int t = 1;
		int y = 1;

		int count = 0;

		for (int i = 0; t != 0 || y != 0; i++) {

			String line = sc.nextLine();
			String[] HW = line.split(" ");
			t = Integer.parseInt(HW[0]);
			y = Integer.parseInt(HW[1]);
			ty[i][0] = t;
			ty[i][1] = y;

			count++;

		}

		for (int i = 0; i < count-1; i++) {



			//ここを分岐させる
			StringBuilder x = new StringBuilder();
			for (int j = 0; j < ty[i][1]; j++) {

				x.append("#");


			}

			String z = x.toString();


			StringBuilder a = new StringBuilder();

			for (int j = 0; j < ty[i][1]; j++) {
				if (j == 0 || j== ty[i][1]-1) {
					a.append("#");
				}else{
					a.append(".");
				}

			}


			String b = a.toString();



			for (int j = 0; j < ty[i][0]; j++) {
				if (j == 0 || j== ty[i][0]-1) {
					System.out.println(z);
				} else {
					System.out.println(b);
				}

			}
			System.out.println("");


		}

	}

}



Measured memory_bytes: 27640
#include <iostream>
//#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
//#include <utility>
//#include <set>
//#include <map>
//#include <queue>
//#include <deque>
//#include <bitset>
//#include <math.h>
using namespace std ;
using ll = long long ;
//using ld = long double ;
using vll = vector<ll> ;
//using vvll = vector<vll> ;
//using vc = vector<char> ;
//using vvc = vector<vc> ;
//using vb = vector<bool> ;
//using vvb = vector<vb> ;
//using pll = pair<ll,ll> ;
//#define all(v) v.begin(),v.end()
//ll mod = 1000000007 ;
//long double pie = acos(-1) ;
//ll INF = 1000000000000 ;

//void yorn(bool a){if(a) cout << "Yes" << endl ; else cout << "No" << endl ;}
//void YorN(bool a){if(a) cout << "YES" << endl ; else cout << "NO" << endl ;}
//ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
//ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
//ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;}
//void mysort(vector<long long> &a){sort(a.begin(),a.end()) ;}
//void myrev(vector<long long> &a){reverse(a.begin(),a.end()) ;}
//void fix_cout(){cout << fixed << setprecision(20) ;}

int main(){
	string s ; cin >> s ;
	vll x ;
	string sub ;
	ll cnt = 0 ;
	for(int i=0;i<s.size();i++){
		if(s.at(i)=='x') cnt++ ;
		else{
			sub += s.at(i) ;
			x.emplace_back(cnt) ;
			cnt = 0 ;
		}
	}
	x.emplace_back(cnt) ;
	string ch = sub ;
	reverse(ch.begin(),ch.end()) ;
	if(ch!=sub) cout << -1 << endl ;
	else{
		ll ans = 0 ;
		for(int i=0;i<x.size()/2;i++){
			ans += abs(x.at(i)-x.at(x.size()-1-i)) ;
		}
		cout << ans << endl ;
	}
}


Measured memory_bytes: 1656
package main

import "fmt"

func main() {
	stack := []int{}
	for {
		var a int
		i, _ := fmt.Scan(&a)
		if i == 0 {
			break
		}
		if a == 0 {
			fmt.Println(stack[len(stack)-1])
			stack = stack[:len(stack)-1]
			continue
		}
		stack = append(stack, a)
	}
}



Measured memory_bytes: 1124
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#define debug(x) cerr << #x << " = " << x << endl;


#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 1010

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

int main(){
  int h,w,k;
  char a[SIZE][SIZE];
  int sx,sy;
  
  scanf("%d%d%d",&h,&w,&k);

  for(int i=0;i<h;i++){
    scanf("%s",a[i]);
    for(int j=0;j<w;j++){
      if(a[i][j] == 'S'){
        sy = i; sx = j;
      }
    }
  }

  queue<pair<int,int> > que;
  bool used[SIZE][SIZE] = {};
  
  que.push({sy,sx});

  for(int i=0;i<k;i++){
    queue<pair<int,int> > que2;

    while(que.size()){
      int y = que.front().first;
      int x = que.front().second;
      que.pop();
      
      if(used[y][x]) continue;
      used[y][x] = 1;
      
      for(int i=0;i<4;i++){
        if(0 <= dx[i]+x && dx[i]+x < w && 0 <= dy[i]+y && dy[i]+y < h){
          if(a[dy[i]+y][dx[i]+x] == '.'){
            que2.push({dy[i]+y,dx[i]+x});
          }
        }
      }
    }

    que = que2;
  }
  
  bool used2[SIZE][SIZE] = {};

  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      if(used[i][j])
        que.push({i,j});
    }
  }
  
  que.push({sy,sx});

  for(int i=0;que.size();i++){
    queue<pair<int,int> > que2;
    while(que.size()){
      int y = que.front().first;
      int x = que.front().second;
      que.pop();
      
      if(used2[y][x]) continue;
      used2[y][x] = 1;

      if(x==0 || x==w-1 || y==0 || y==h-1){
        printf("%d\n",(i+k-1)/k + 1);
        return 0;
      }
      
      for(int i=0;i<4;i++){
        if(0 <= dx[i]+x && dx[i]+x < w && 0 <= dy[i]+y && dy[i]+y < h){
          que2.push({dy[i]+y,dx[i]+x});
        }
      }
    }

    que = que2;
  }

  puts("-1");
  
  return 0;
}


Measured memory_bytes: 8320
#include <bits/stdc++.h>
using namespace std;
#define int long long
int MOD = (int)1e9 + 7;
int INF = (int)2e18;
// Comment out below and program paste

// #include "UnionFind.hpp"
// #include "power.hpp"

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N;
    cin >> N;
    vector<int> A(5);
    for (int i = 0; i < 5; i++) cin >> A[i];
    sort(A.begin(), A.end());
    int ans = N / A[0] + (N % A[0] != 0);
    cout << ans + 4 << endl;
}


Measured memory_bytes: 256
#include <stdio.h>


int main(void){
    int N;
    scanf("%d",&N);
    int a[N];
    for(int i=0;i<N;i++)scanf("%d",&a[i]);
    int b[N];
    int po[N];
    for(int i=0;i<N;i++)po[i]=0;
    for(int i=0;i<N;i++){
        scanf("%d",&b[i]);
        po[b[i]-1]++;
    }
    for(int i=0;i<N;i++){
        if(po[i]==0){
            printf("No\n");
            for(int j=0;j<N;j++){
                if(a[j]==i+1){
                    printf("1");
                }
                else printf("%d",a[j]);
                if(j!=N-1)printf(" ");
            }
            printf("\n");
            for(int j=0;j<N;j++){
                if(a[j]==i+1){
                    printf("2");
                }
                else printf("%d",a[j]);
                if(j!=N-1)printf(" ");
            }
            printf("\n");
            return 0;
        }
    }
    printf("Yes\n");
    return 0;
}


Measured memory_bytes: 2916
#include <bits/stdc++.h>
#define MAXN 200100
#define pii pair<int, int>
#define pb push_back
typedef long long ll;

using namespace std;

int pai[MAXN][2];

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

int find(int i, int t){
	if(pai[i][t]==i)return i;
	return pai[i][t]=find(pai[i][t], t);
}

int join(int a, int b, int t){
	a=find(a, t);
	b=find(b, t);
	pai[a][t]=pai[b][t];
}

int n, k, l;
map<pii, int> m;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
    cin >> n >> k >> l;
	init(n);
    for(int i = 0; i < k; i++){
    	int a, b;
    	cin >> a >> b;
    	join(a, b, 0);
    }
    for(int i = 0; i < l; i++){
    	int a, b;
    	cin >> a >> b;
    	join(a, b, 1);
    }
    for(int i = 1; i <= n; i++){
    	m[{find(i, 0), find(i, 1)}]++;
    }
    for(int i = 1; i <= n; i++){
    	cout << m[{find(i, 0), find(i, 1)}] << " ";
    }
}

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

typedef pair<int, int> pii;
typedef long long ll;
typedef vector<int> vi;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()

const int MN = 300010;

int X, Y, Z, N;
ll A[MN], B[MN], C[MN];
ll dpl[MN], dpr[MN];

int main() {
	cin >> X >> Y >> Z;
	N = X + Y + Z;

	vector<pair<ll, int>> vec(N);

	rep(i, N) {
		cin >> A[i] >> B[i] >> C[i];
		vec[i] = mp(B[i] - A[i], i);
	}

	sort(ALL(vec));

	priority_queue<ll, vector<ll>, greater<ll>> que;

	ll sl = 0;
	ll in = 0;

	for (int ii = 0; ii < N; ++ii) {
		int i = vec[ii].se;
		sl += C[i];

		if (que.size() < X) {
			que.push(A[i] - C[i]);
			in += A[i] - C[i];
		} else {
			ll t = que.top();
			ll d = A[i] - C[i];

			if (t < d) {
				que.pop();
				que.push(d);
				in = in - t + d;
			}
		}

		if (que.size() < X) {
			dpl[ii] = -1;
		} else {
			dpl[ii] = sl + in;
		}
	}

	while (que.size()) {
		que.pop();
	}

	ll sr = 0;
	in = 0;

	for (int ii = N-1; ii >= 0; --ii) {
		int i = vec[ii].se;
		sr += C[i];

		if (que.size() < Y) {
			que.push(B[i] - C[i]);
			in += B[i] - C[i];
		} else {
			ll t = que.top();
			ll d = B[i] - C[i];

			if (t < d) {
				que.pop();
				que.push(d);
				in = in - t + d;
			}
		}

		if (que.size() < Y) {
			dpr[ii] = -1;
		} else {
			dpr[ii] = sr + in;
		}
	}

	ll ret = 0;
	rep(i, N-1) {
		if (dpl[i] != -1 && dpr[i+1] != -1) {
			ret = max(ret, dpl[i] + dpr[i+1]);
		}
	}
	cout << ret << endl;

	return 0;
}

Measured memory_bytes: 11640
# -*- coding: utf-8 -*-


def main():
    h, w = map(int, input().split())
    alpha = [0 for _ in range(26)]

    # 各アルファベットの個数を数える
    for i in range(h):
        ai = list(input())

        for aii in ai:
            # アルファベットを数値に変換
            index = ord(aii) - ord('a')
            alpha[index] += 1

    mod = [0 for _ in range(4)]

    for a in alpha:
        mod[a % 4] += 1

    # 回文となる条件
    # 1. hとwがともに偶数：
    # アルファベットの個数が全て4の倍数のとき，Yes
    # 2. hとwのどちらかが偶数：
    # アルファベットの個数が全て2の倍数のとき，Yes
    # 3. hとwがともに奇数：
    # (h - 1) * (w - 1)マス分，アルファベットの個数が4の倍数であり，
    # かつ，1種類を除いて，2の倍数のとき，Yes
    if h % 2 == 0 and w % 2 == 0:
        for a in alpha:
            if a % 4 != 0:
                print('No')
                exit()

        print('Yes')
    elif h % 2 == 1 and w % 2 == 1:
        # 気がつけなかった点
        # 4で割ったときに2余る数が使われるのが，(h - 1) // 2 + (w - 1) // 2以下
        # See:
        # https://www.hamayanhamayan.com/entry/2017/09/24/012523
        if mod[3]:
            print('No')
        elif mod[1] != 1:
            print('No')
        elif mod[2] > ((h - 1) // 2 + (w - 1) // 2):
            print('No')
        else:
            print('Yes')
    else:
        if w % 2 == 1:
            h, w = w, h

        # 気がつけなかった点
        if mod[3] or mod[1]:
            print('No')
        elif mod[2] > w // 2:
            print('No')
        else:
            print('Yes')


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
//using System.Text;
//using System.Text.RegularExpressions;
//using System.Globalization;
//using System.Diagnostics;
using static System.Console;
//using System.Numerics;
//using static System.Math;
//using pair = Pair<int, int>;

class Program
{
    static void Main()
    {
        //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
        new Program().solve();
        Out.Flush();
    }
    Scanner cin = new Scanner();
    readonly int[] dd = { 0, 1, 0, -1, 0 }; //→↓←↑
    readonly int mod = 1000000007;


    void solve()
    {
        int a = cin.nextint;
        int b = cin.nextint;
        int cnt = 0;
        for (int i = a; i <= b; i++)
        {
            var s = i.ToString();
            if (s[0] == s[4] && s[1] == s[3]) cnt++;
        }
        WriteLine(cnt);
    }

}

class Scanner
{
    string[] s; int i;
    char[] cs = new char[] { ' ' };
    public Scanner() { s = new string[0]; i = 0; }
    public string[] scan { get { return ReadLine().Split(); } }
    public int[] scanint { get { return Array.ConvertAll(scan, int.Parse); } }
    public long[] scanlong { get { return Array.ConvertAll(scan, long.Parse); } }
    public double[] scandouble { get { return Array.ConvertAll(scan, double.Parse); } }
    public string next
    {
        get
        {
            if (i < s.Length) return s[i++];
            string st = ReadLine();
            while (st == "") st = ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            i = 0;
            return next;
        }
    }
    public int nextint { get { return int.Parse(next); } }
    public long nextlong { get { return long.Parse(next); } }
    public double nextdouble { get { return double.Parse(next); } }
}

Measured memory_bytes: 13140