akhauriyash/Code-Regression huggingface dataset:
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<unordered_map>
#include<array>
#include<map>
#include<bitset>
#include<iomanip>
#include<list>
#include <numeric>
using namespace std;
typedef unsigned long long int ulint;
typedef long long int llint;
typedef long double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
#define RE return 0
//ios::sync_with_stdio(false);
//std::cin.tie(0);
//<< setprecision(20)
const int mod=(int)1e9+7;
const llint big=(llint)(2.19e15+1);
const long double pai=3.141592653589793238462643383279502884197;
const long double ena=2.71828182845904523536;
const long double eps=1e-7;
template <class T,class U>bool mineq(T& a,U b){if(a>b){a=b;return true;}return false;}
template <class T,class U>bool maxeq(T& a,U b){if(a<b){a=b;return true;}return false;}
template <class T> void soun(T& ar)
{sort(ar.begin(),ar.end());ar.erase(unique(ar.begin(),ar.end()),ar.end());}
llint gcd(llint a,llint b){if(a%b==0){return b;}else{return gcd(b,a%b);}}
llint lcm(llint a,llint b){return a/gcd(a,b) *b;}
template<class T,class U> auto LB(T& ve,U in){return lower_bound(ve.begin(),ve.end(),in);}
template<class T,class U> auto UB(T& ve,U in){return upper_bound(ve.begin(),ve.end(),in);}
template<class T,class U> auto LBI(T& ve,U in){return LB(ve,in)-ve.begin();}
template<class T,class U> auto UBI(T& ve,U in){return UB(ve,in)-ve.begin();}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());}
int main(void){
	string s;cin>>s;s+=s;
	string p;cin>>p;
	int i,j;
	for(i=0;i<s.size()/2;i++){
		bool ok=true;
		for(j=0;j<p.size();j++){
			if(s[i+j]!=p[j]){ok=false;break;}
		}
		if(ok){cout<<"Yes"<<endl;RE;}
	}
	cout<<"No"<<endl;
	RE;
}


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

int main() {
    long a, b;
    cin>>a>>b;
    long x;
    cin>>x;
    long ans = 0;
    long start = a + (x - a%x)%x;
    long end = b - b%x;
    if(start <= end){
        ans += (end - start)/x + 1;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
/*https://atcoder.jp/contests/dp/tasks/dp_e*/
#include <iostream>
#include <vector>
using namespace std;
int min(int a, int b){
	return a < b ? a : b;
}
int main(){
	int n, W, S = 0;
	cin >> n >> W;
	vector<int>w(n), v(n);
	for (int i = 0; i < n; i++){
		cin >> w[i] >> v[i];
		S += v[i];
	}
	int inf = 1e9 + 7;
	vector<int>dp(S + 1, inf);
	/*dp[i][j]: weight nho nhat voi i phan tu va co gia tri la j*/
	dp[0] = 0;
	
	for (int i = 0; i < n; i++){
		for (int j = S - v[i]; j >= 0; j--){
			dp[j + v[i]] = min(dp[j + v[i]], dp[j] + w[i]);
		}
	}
	for (int i = S; i >= 0; i--){
		if (dp[i] <= W){
			cout << i;
			return 0;
		}
	}
	
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
};



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


vector<ll> fac(3000001); //n!(mod M)
vector<ll> ifac(3000001); //k!^{M-2} (mod M)
//a,bの範囲的にこれだけ配列を用意していけば十分

ll mpow(ll x, ll n){ //x^n(mod M) ←普通にpow(x,n)では溢れてしまうため，随時mod計算
    ll ans = 1;
    while(n != 0){
        if(n&1) ans = ans*x % mod;
        x = x*x % mod;
        n = n >> 1;
    }
    return ans;
}

ll comb(ll a, ll b){ //aCbをmod計算
    if(a == 0 && b == 0)return 1;
    if(a < b || a < 0)return 0;
    ll tmp = ifac[a-b]* ifac[b] % mod;
    return tmp * fac[a] % mod;
}




int main() {
  int x,y;
  cin >> x >> y;
  if((x+y)%3!=0){
    cout << 0 << endl;
    return 0;
  }
  int n=(x+y)/3;
  x-=n;y-=n;
  if(x<0||y<0){
    cout << 0 << endl;
    return 0;
  }
  fac[0] = 1;
    ifac[0] = 1;
    for(ll i = 0; i<3000000; i++){
        fac[i+1] = fac[i]*(i+1) % mod; // n!(mod M)
        ifac[i+1] = ifac[i]*mpow(i+1, mod-2) % mod; // k!^{M-2} (mod M) ←累乗にmpowを採用
    }
  cout << comb(n,x) << endl;
}
  

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

#define debug(x) cout << #x << " = " << x << endl
#define fori(i, ini, lim) for(int i = int(ini); i < int(lim); i++)
#define ford(i, ini, lim) for(int i = int(ini); i >= int(lim); i--)

using namespace std;

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

const int MAX = 700 + 5;
bool memo[MAX][MAX], visited[MAX][MAX];
int adj[MAX][MAX], color[MAX];
int n, m;

void die() {
	puts("-1");
	exit(0);
}

ii bfs(int source) {
	queue<int> q;
	q.push(source);
	color[source] = 0;
	int c[2] = {0};
	while(!q.empty()) {
		int cur = q.front(); q.pop();
		c[color[cur]]++;
		fori(i, 1, n + 1) {
			if(!adj[cur][i]) {
				continue;
			}
			if(color[i] == -1) {
				color[i] = !color[cur];
				q.push(i);
			}
			else if(color[cur] == color[i]) {
				die();
			}
		}
	}
	return ii(c[0], c[1]);
}

vector<ii> pairs;
bool roll(int idx, int got) {
	if(got < 0) {
		return false;
	}
	else if(idx == -1) {
		return got == 0;
	}
	bool &ans = memo[idx][got];
	if(visited[idx][got]) {
		return ans;
	}
	visited[idx][got] = true;
	ans = roll(idx - 1, got - pairs[idx].first) || roll(idx - 1, got - pairs[idx].second);	
	return ans;
}

int main() {
	scanf("%d %d", &n, &m);

	fori(i, 1, n + 1) {
		fori(j, 1, n + 1) {
			adj[i][j] = 1;
		}
		adj[i][i] = 0;
	}

	fori(i, 0, m) {
		int u, v;
		scanf("%d %d", &u, &v);
		adj[u][v] = adj[v][u] = 0;
	}

	memset(color, -1, sizeof color);
	fori(i, 1, n + 1) {
		if(color[i] == -1) {
			ii p = bfs(i);
			pairs.push_back(p);
		}
	}

	int half = n / 2; 
	int ans = 0;
	ford(i, half, 0) {
		if(roll((int) pairs.size() - 1, i)) {
			int a = i;
			int b = n - i;
			ans = (a * (a - 1)) / 2 + (b * (b - 1)) / 2;
			break;
		}
	}

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

	return 0;
}


Measured memory_bytes: 3200
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; ++i)
#define rrep(i, n) for(int i = n-1; i >= 0; --i)
#define fi first
#define se second
using namespace std;
using lint = long long;
using uint = unsigned int;
using ulint = unsigned long long;
using ldouble = long double;
using pii = pair<int, int>;
using pli = pair<lint, lint>;
using pdd = pair<double, double>;
using pld = pair<ldouble, ldouble>;
using v1i = vector<int>;
using v1li = vector<lint>;
using v2i = vector<vector<int>>;
using v2li = vector<vector<lint>>;
using v3i = vector<vector<vector<int>>>;
using v3li = vector<vector<vector<lint>>>;
using v1b = vector<bool>;
using v2b = vector<vector<bool>>;
using v3b = vector<vector<vector<bool>>>;
using v1c = vector<char>;
using v2c = vector<vector<char>>;
using v3c = vector<vector<vector<char>>>;
constexpr lint mod1 = 1e9+7;
constexpr lint mod2 = 998244353;

int main() {
  int a, b, n, m, mp = 1e9, mq = 1e9, mi;
  cin >> a >> b >> m;
  v1i p(a), q(b), x(m), y(m), c(m);
  rep(i, a){
    cin >> p[i];
    mp = min(mp, p[i]);
  }
  rep(i, b){
    cin >> q[i];
    mq = min(mq, q[i]);
  }
  mi = mp + mq;
  rep(i, m){
    cin >> x[i] >> y[i] >> c[i];
    mi = min(mi, p[x[i]-1] + q[y[i]-1] - c[i]);
  }
  cout << mi << endl;
  return 0;
}

Measured memory_bytes: 2176
#include <vector>
#include <iostream>
#include <complex>
#include <cmath>
using namespace std;
typedef complex<double> P;
typedef pair<P, double> C;
#define X real()
#define Y imag()

const double pi = acos(-1), EPS = (1e-7);

double dot(P a, P b){
  return a.X*b.X + a.Y*b.Y;
}

vector<P> cpcc(C a, C b){
  //円と円の交点
  double d = abs(a.first-b.first), ra = a.second, rb = b.second;
  double t = (ra*ra-rb*rb+d*d)/2/d, h = sqrt(ra*ra-t*t);
  P m = t/abs(b.first-a.first)*(b.first-a.first)+a.first;
  vector<P> cp(2,m);
  P n = (a.first-b.first)*P(0,1);
  n /= abs(n);
  cp[0] -= h*n;
  cp[1] += h*n;
  return cp;
}

vector<P> tangent_to_C(P p, C c){
  //点pから円cに伸ばした接線の接点を求める
  C c2 = C((p+c.first)/2.0,abs(p-c.first)/2.0);
  return cpcc(c,c2);
}

bool in_sector(P c, double r, double theta, double a, double b){
  if(abs(c) < r + EPS) return false;
  if(abs(c) + r > a + EPS) return false;
  vector<P> cps = tangent_to_C(P(0,0), C(c, r));
  if(cps.empty()) return false;
  P d = P(cos(b), sin(b));
  for(int i = 0; i < (int)cps.size(); ++i){
    P cp = cps[i];
    if(dot(cp, d)/abs(cp) < cos(theta/2) - EPS) return false;
  }
  return true;
}

void dfs(vector< vector<int> > &G, int v, vector<int> &P, vector<int> &R, int t){
  for(int i = 0; i < (int)G[v].size(); ++i){
    int v_ = G[v][i];
    int d = min(P[v_], R[v_]+t) - R[v_];
    R[v_] += d;
    if(d > 0) dfs(G, v_, P, R, d);
  }
}

int solve(vector< vector<int> > &G, vector<int> P){
  int n = G.size();
  vector<int> R(n, 0);
  R[0] = P[0];
  dfs(G, 0, P, R, R[0]);
  return R.back();
}

int main(){
  int N;
  cin >> N;
  double theta, a;
  vector<int> Power(N+2, 0);
  Power.back() = (int)1e9;
  cin >> theta >> a >> Power[0];
  theta *= pi/180.0;
  vector<P> L(N+1);
  vector<double> R(N+1), A(N), T(N), B(N);
  for(int i = 0; i < N; ++i){
    double x, y;
    cin >> x >> y >> R[i] >> T[i] >> A[i] >> B[i] >> Power[i+1];
    L[i] = P(x, y);
    T[i] *= pi/180.0;
    B[i] *= pi/180.0;
  }
  double x, y;
  cin >> x >> y >> R[N];
  L[N] = P(x, y);
  vector< vector<int> > G(N+2);
  for(int i = 0; i < N; ++i){
    for(int j = 0; j <= N; ++j){
      if(i == j) continue;
      if(in_sector(L[j]-L[i], R[j], T[i], A[i], B[i])){
        G[i+1].push_back(j+1);
      }
    }
  }

  int ans = 0;
  for(int i = 0; i <= N; ++i){
    if(abs(L[i]) + R[i] > a) continue;
    if(abs(L[i]) - R[i] < EPS) continue;
    vector<P> cps = tangent_to_C(P(0,0), C(L[i], R[i]));
    if(cps.empty()) continue;
    P cp = cps[0];
    if(arg(cps[0]) > arg(cps[1])) swap(cps[0], cps[1]);
    double b = arg(cp*P(cos(theta/2), sin(theta/2)));
    G[0] = vector<int>();
    for(int j = 0; j <= N; ++j){
      if(in_sector(L[j], R[j], theta, a, b)){
        G[0].push_back(j+1);
      }
    }
    ans = max(ans, solve(G, Power));
  }
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 3724
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<iostream>
#define db double
#define LL long long
#define inf 0x3f3f3f3f
using namespace std;
LL a,b,c,k;
int main()
{
    scanf("%lld%lld%lld%lld",&a,&b,&c,&k);
    if(k&1) printf("%lld\n",b-a);
    else printf("%lld\n",a-b);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
#include <iomanip>
#include <set>
#include <functional>
#include <stdio.h>
#include <ctype.h>
#include <random>
#include <string.h>
#include <unordered_map>
#include <cstdio>
using namespace std;
#define all(vec) vec.begin(),vec.end()
typedef long long ll;

ll gcd(ll x, ll y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
ll lcm(ll x, ll y) {
	return x / gcd(x, y)*y;
}
ll kai(ll x, ll y, ll m) {
	ll res = 1;
	for (ll i = x - y + 1; i <= x; i++) {
		res *= i; res %= m;
	}
	return res;
}
ll mod_pow(ll x, ll y, ll m) {
	ll res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}

ll comb(ll x, ll y, ll m) {
	if (y > x)return 0;
	return kai(x, y, m) * mod_pow(kai(y, y, m), m - 2, m) % m;
}

int n, a[1000010];
vector<int> vec[1000010];
int cnt[1000010];
bool bl[1000010];

signed main() {
	std::random_device rnd;
	std::mt19937_64 mt(rnd());
	cin >> n;
	for (int i = 0; i < n; i++)scanf("%d", &a[i]);
	for (int i = 2; i <= 1000000; i++) {
		if (bl[i])continue;
		for (int j = i; j <= 1000000; j += i) {
			vec[j].push_back(i);
			bl[j] = true;
		}
	}
	for (int i = 0; i < n; i++)for (int j = 0; j < (int)vec[a[i]].size(); j++)cnt[vec[a[i]][j]]++;
	bool bo = false;
	for (int i = 2; i <= 1000000; i++)if (2 <= cnt[i])bo = true;
	if (!bo) {
		cout << "pairwise coprime" << endl;
		return 0;
	}
	int p = a[0];
	for (int i = 1; i < n; i++)p = (int)gcd(p, a[i]);
	if (p == 1)cout << "setwise coprime" << endl;
	else cout << "not coprime" << endl;
}

Measured memory_bytes: 67808
L, R = map( int, input().split() )


if L <= 2019 & R >= 2019:
	print(0)
elif R - L <= 2019:
	list_modulus_ij_one = []

	for i in range(L, R):
		for j in range(i+1, R+1):
			i_modulus = i % 2019
			j_modulus = j % 2019
			ij_modulus = (i_modulus * j_modulus) % 2019
			list_modulus_ij_one.append(ij_modulus) 

	mini_modulus_ij_one = min(list_modulus_ij_one)
	print(mini_modulus_ij_one)
else:
	list_modulus_ij_two = []

	for i in range(L, L+2019):
		for j in range(i+1, L+2019+1):
			i_modulus = i % 2019
			j_modulus = j % 2019
			ij_modulus = (i_modulus * j_modulus) % 2019
			list_modulus_ij_two.append(ij_modulus)
	
	mini_modulus_ij_two = min(list_modulus_ij_two)
	print(mini_modulus_ij_two)

Measured memory_bytes: 75416
lines = input().split(" ")
K = int(lines[0])
X = int(lines[1])
arr = []

if K == 1:
  print(X)
else:
  for i in range(X , X + K):
    arr.append(i)
    
  for j in range(X - K + 1 , X):
    arr.append(j)
    
arr.sort()
map_result = map(str, arr)
result = ' '.join(map_result)
print(result)

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

int main(){
	int H, W;
	cin >> H >> W;
	vector<vector<char>> P(H, vector<char>(W));
	vector<bool> Y(H, false);
	vector<bool> X(W, false);
	
	for(int i = 0; i < H; i++){
		for(int j = 0; j < W; j++){
			cin >> P[i][j];
			if(P[i][j] == '#')Y[i] = true;
		}
	}
	
	for(int j = 0; j < W; j++){
		for(int i = 0; i < H; i++){
			if(P[i][j] == '#')X[j] = true;
		}
	}
	
	for(int i = 0; i < H; i++){
		if(Y[i]){
			for(int j = 0; j < W; j++){
				if(X[j]){
					cout << P[i][j];
				}
			}
			cout << '\n';
		}
	}
}


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

typedef pair<int, int> pi;
typedef vector<vector<int>> vv;

int32_t main() 
{ 
	int n;
	cin >> n;
	int prev = INT_MAX;
	int ans = 1;
	for (int i = 0; i < n; ++i)
	{
		int x;
		cin >> x;
		if(i > 0){
			if(x <= prev)
				ans++;
		}
		prev = min(prev, x);
	}

	cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back((a))
#define all(x) (x).begin(),(x).end()
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

#define INF 2147483600
#define long long long // for codeforces

int main(){
  int n;
  cin>>n;
  vector<int> r(n), s(n), p(n), c(n);
  rep(i,n) cin>>r[i];
  rep(i,n) cin>>s[i]>>p[i]>>c[i];
  rep(i,n) s[i]*=-1,p[i]*=-1,c[i]*=-1;

  auto calc = [&](){
    vector<int> ss(s), pp(p), cc(c);
    sort(all(ss)); sort(all(pp)); sort(all(cc));
    vector<pair<int,int>> vec(n);
    rep(i,n) vec[i] = mp(0,((i==0)?n:i));
    rep(i,n) vec[i].fi += r[lower_bound(all(ss),s[i])-ss.begin()];
    rep(i,n) vec[i].fi += r[lower_bound(all(pp),p[i])-pp.begin()];
    rep(i,n) vec[i].fi += r[lower_bound(all(cc),c[i])-cc.begin()];
    sort(all(vec), greater<pair<int,int>>());
    rep(i,n) if(vec[i].se==n) return i+1;
  };

  assert(calc()==9);

  auto f = [&](vector<int> &v){
    int org = v[0];
    for(int i=v[0]-1; i>=-110; i--){
      v[0] = i;
      if(calc()<9){v[0]=org; return org-i;}
    }
    v[0]=org;
    return INF;
  };

  int ans = INF;
  ans = min(f(s), f(p));
  ans = min(ans, f(c));

  if(ans==INF) cout <<"Saiko"<<endl;
  else cout<<ans << endl;

  return 0;
}

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

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

    ll n;
    cin >> n;

    ll res = 1;
    rep1(b, n-1){
        for(int nc = b; nc <= n-1; nc += b){
            ++res;
        }
    }

    cout << res << endl;

    return 0;
}

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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}

int nextInt() { int x; scanf("%d", &x); return x;}
ll nextLong() { ll x; scanf("%lld", &x); return x;}


int R, S, P;

const int MAX_N = 112345;
ll dp[MAX_N][3];

ll solve(string T) {
  const int N = T.size();

  REP(i, N+1) REP(j, 3) dp[i][j] = 0;

  if (T[0] == 's') dp[0][0] = R;
  if (T[0] == 'p') dp[0][1] = S;
  if (T[0] == 'r') dp[0][2] = P;

  for (int i = 1; i < N; i++) {
    for (int j = 0; j < 3; j++) {
      for (int k = 0; k < 3; k++) if (j != k) {
        int add = 0;
        if (T[i] == 's' && k == 0) add = R;
        if (T[i] == 'p' && k == 1) add = S;
        if (T[i] == 'r' && k == 2) add = P;
        chmax(dp[i][k], dp[i-1][j] + add);
      }
    }
  }


  ll ans = 0;
  chmax(ans, dp[N-1][0]);
  chmax(ans, dp[N-1][1]);
  chmax(ans, dp[N-1][2]);
  return ans;
}

int main2() {
  int N = nextInt();
  int K = nextInt();
  R = nextInt();
  S = nextInt();
  P = nextInt();
  string T; cin >> T;

  ll ans = 0;
  REP(i, K) {
    string sub;
    for (int j = i; j < N; j += K) {
      sub += T[j];
    }
    ans += solve(sub);
  }
  cout << ans << endl;
  return 0;
}

int main() {

#ifdef LOCAL
  for (;!cin.eof();cin>>ws)
#endif
    main2();
  return 0;
}


Measured memory_bytes: 2944
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
#include<iomanip>
#include<list>
#include<deque>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define DEB2(X) cout<<X<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define DEB2(X) {}
#define END {}
#endif
typedef long long ll;
#define int ll
#define uset unordered_set
#define umap unordered_map
//typedef std::pair<int,int> P;
struct edge{int to,cost;};
const int INF=100000000000000000;
const int INF2=9223372036854775807;
const int MOD=1000000007;
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define min(X,Y) (((int)(X)<(int)(Y))?(X):(Y))
#define max(X,Y) (((int)(X)>(int)(Y))?(X):(Y))
#define NP(X,Y) next_permutation(X,Y)
#define setdouble(X,Y) cout<<fixed<<setprecision(X)<<Y
int ceil2(int a,int b){if(a%b==0){return a/b;}else{return a/b+1;}}
int pow2(int a,int b){int r=1;for(int i=1;i<=b;i++){r*=a;}return r;}
int Log2(int a){int t=0;while(1){if(a==0||a==1){break;}a/=2;t++;}return t;}

int N;
vector<int> v,v2,p;

signed main(){
	cin>>N;
	REP(i,N){
		int a;
		cin>>a;
		v.push_back(a);
	}
	REP(i,N){
		int a;
		cin>>a;
		v2.push_back(a);
	}
	for(int i=1;i<=N;i++){
		p.push_back(i);
	}
	int cnt=1;
	int P,Q;
	do{
		if(v==p){
			P=cnt;
		}
		if(v2==p){
			Q=cnt;
		}
		cnt++;
	}while(NP(p.begin(),p.end()));
	cout<<abs(P-Q)<<endl;
	
	return 0;
}


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

int main() {
  int A, B, C, K;
    cin >> A >> B >> C >> K;
    bool flg = true;
    
   rep(i, K){
        if(A>=B) B *= 2;
        else if(B>=C) C *= 2;
    }
  	if(A<B && B<C) cout << "Yes" << endl;
    else cout << "No" << endl;
}


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

using ll = long long;

struct status {
    ll h, a, d, s;
};

int main() {
    int n;
    cin >> n;
    vector<status> v(1);
    cin >> v[0].h >> v[0].a >> v[0].d >> v[0].s;
    bool check = true;
    for(int i = 1; i <= n; ++i) {
        status s;
        cin >> s.h >> s.a >> s.d >> s.s;
        if(i != 0) {
            if(v[0].d >= s.a) {
                continue;
            }
            v.push_back(s);
            check &= s.d < v[0].a;
        }
    }
    if(!check) {
        cout << -1 << endl;
        return 0;
    }
    n = v.size();
    sort(v.begin() + 1, v.end(), [&](auto const& s1, auto const& s2) {
        ll damage1 = max(s1.a - v[0].d, 0LL), damage2 = max(s2.a - v[0].d, 0LL);
        ll t1 = (s1.h + v[0].a - s1.d - 1) / (v[0].a - s1.d) - (s1.s < v[0].s);
        ll t2 = (s2.h + v[0].a - s2.d - 1) / (v[0].a - s2.d) - (s2.s < v[0].s);
        return (t1 + t2 + (s1.s < v[0].s)) * damage2 + t1 * damage1 < (t1 + t2 + (s2.s < v[0].s)) * damage1 + t2 * damage2;
    });
    ll total_damage = 0;
    ll total_turn = 0;
    for(int i = 1; i < n; ++i) {
        auto& s = v[i];
        total_turn += (s.h + v[0].a - s.d - 1) / (v[0].a - s.d) - (s.s < v[0].s);
        total_damage = min(v[0].h, total_damage + total_turn * max(0LL, s.a - v[0].d));
        total_turn += (s.s < v[0].s);
    }
    if(total_damage >= v[0].h) {
        cout << -1 << endl;
    } else {
        cout << total_damage << endl;
    }
}


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

typedef long long ll;

int main()
{
    int A, B, C, D;
    cin >> A >> B >> C >> D;

    while (true)
    {
        C -= B;
        if (C <= 0)
        {
            cout << "Yes" << endl;
            return 0;
        }
        A -= D;
        if (A <= 0)
        {
            cout << "No" << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp> 
using namespace std;
//using namespace __gnu_pbds;
#define rep(i,a,b) for(i=(a);i<=(b);i++)
#define ll long long
#define pll pair<ll, ll>
#define pii pair<int,int>
#define pb push_back
#define F first
#define S second
#define mod 10000007
#define maxn 100005
#define inf 1e18
#define boost ios::sync_with_stdio(false);cin.tie(0)
#define fr freopen("source.txt","r",stdin),freopen("output.txt","w",stdout)
#define SET(a,b) memset(a,b,sizeof(a))
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define all(x) x.begin(), x.end()
//template<typename T>
//using ordered_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;

int main()
{
    boost;
    ll n,i,j,x,t,k,s;
    cin>>n>>k>>s;
    for(i=0;i<k;i++) cout<<s<<" ";
    ll sum=0;
    x=1000000000;
    for(i=k;i<n;i++) {
        if(x==s) x--;
        cout<<x<<" ";
        x--;
    }
}

Measured memory_bytes: 1280
#include<bits/stdc++.h>
using namespace std;
#define llt long long int
int main(){
int n;
cin>>n;
int count=0;
count+=(n/500)*1000;
n=n%500;
//cout<<n<<endl;
count+=(n/5)*5;
cout<<count<<endl;
return 0;
}
//-------------------------------------IND------------------------------------

Measured memory_bytes: 256
program ABC158_C
  integer:: A,B,BR
  read(5,*)A,B
  AL=A*12.5
  AR=(A+1)*12.5
  BL=B*10
  BR=(B+1)*10
  if(AL > int(AL)) then
     AL=int(AL+1)
  else
     AL=int(AL)
  end if
  if(AR > int(AR)) then
     AR=int(AR+1)
  else
     AR=int(AR)
  end if
  if( AL <= BL .and. BL < AR ) then
     write(6,*) int(BL)
  else
     if( AL >= BL .and. AL < BR )  then
        write(6,*) int(AL)
     else
        write(6,*)'-1'
     end if
  end if
end program ABC158_C

Measured memory_bytes: 512
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

const int MOD = 1e9 + 7;
const int iINF = 1000000000;
const long long int llINF = 1000000000000000000;

using namespace std;
using ll = long long int;
using edge = struct {
  int to;
  int cost;
};
#define REP(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define AUTO(i, m) for (auto &i : m)
#define ALL(a) (a).begin(), (a).end()
#define MAX(vec) *std::max_element(vec.begin(), vec.end());
#define MIN(vec) *std::min_element(vec.begin(), vec.end());
#define MAXI(vec)                                                              \
  std::distance(vec.begin(), *std::max_element(vec.begin(), vec.end()));
#define MINI(vec)                                                              \
  std::distance(vec.begin(), *std::min_element(vec.begin(), vec.end()));
#define BIT(n, num) std::bitset<(n)>((num)).to_string()
#define MATMUL(a, b, c)                                                        \
  REP(i, a.size())                                                             \
  REP(j, b[0].size()) REP(k, a[0].size()) c[i][j] += a[i][k] * b[k][j];
#define CLA2(a) REP(i, a.size()) REP(j, a[0].size()) a[i][j] = 0;
#define REV(T) greater<T>()

ll pow_(ll a, ll n) {
  ll x = 1;
  while (n > 0) {
    if (n & 1)
      x = (x * a) % MOD;
    a = (a * a) % MOD;
    n >>= 1;
  }
  return x;
}

vector<ll> divisor(ll n) {
  vector<ll> ret;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n)
        ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}

map<ll, int> prime_factor(ll n) {
  map<ll, int> ret;
  for (ll i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if (n != 1)
    ret[n] = 1;
  return ret;
}

ll factorial(int n) {
  ll ans = 1;
  for (int i = 2; i <= n; i++) {
    ans *= i;
    ans %= MOD;
  }
  return ans;
}
ll P(int n, int m) {
  ll ans = 1;
  for (int i = m + 1; i <= n; i++) {
    ans *= i;
    ans %= MOD;
  }
  return ans;
}
ll power(int n, int m) {
  if (m == 0) {
    return 1;
  } else if (m % 2 == 0) {
    ll tmp = power(n, m / 2);
    return (tmp * tmp) % MOD;
  } else {
    return (n * power(n, m - 1)) % MOD;
  }
}
ll C(int n, int m) {
  return (P(n, n - m) * power(factorial(m), MOD - 2)) % MOD;
}
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int main() {
  ll A[5];
  ll a = 0, b = 0, c = 0, d = 0;
  REP(i, 4) {
    cin >> A[i];
    if (A[i] == 1)
      a = 1;
    if (A[i] == 7)
      b = 1;
    if (A[i] == 9)
      c = 1;
    if (A[i] == 4)
      d = 1;
  }

  if (a + b + c + d == 4)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;

  return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
string S,T;
inline int read() {
	int x=0,f=1;char c=getchar();
	while (c<'0'||c>'9') {if (c=='-') f=-1;c=getchar();}
	while (c>='0'&&c<='9') x=x*10+c-'0',c=getchar();
	return x*f;
}

int main() {
	cin>>S>>T;
	int n=S.length();
	int ans=0;
	for (register int i=0;i<n;++i)
		ans+=(S[i]!=T[i]);
	cout<<ans<<endl;
	return 0;
}

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

int main()
{
  int a = 0, b = 0, c = 0, total = 1;
  cin >> a >> b >> c;
  
  if(b!=a && c!=b && c!=a)
    total = 3;
  if(b!=a && c==a)
    total=2;
  if(b==a && c!=a)
    total = 2;
  if(b==c && b!=a)
	total=2;
  
  cout << total << endl;
}

Measured memory_bytes: 3128
#include<stdio.h>
int main(void)
{
	int a,b,i,j,c[1001],x[1001],s=-1,X=0,d;
	scanf("%d%d",&a,&b);
	for(i=0;i<a;i++){
		scanf("%d",&c[i]);
		x[i]=0;
	}
	for(j=0;j<b;j++){
		scanf("%d",&d);
		for(i=0;i<a;i++){
			if(d>=c[i]){
				x[i]++;
				break;
			}
		}
	}
	for(i=0;i<a;i++){
		if(s<x[i]){
			s=x[i];
			X=i+1;
		}
	}
	printf("%d\n",X);
	return 0;
}

Measured memory_bytes: 1032
import numpy as np
def main():
    NAB = [np.int64(i) for i in input().split(" ")]
    N = NAB[0]
    A = NAB[1]
    B = NAB[2]
    ans = 0

    if abs(A - B) % 2 == 0:
        ans += abs(A - B) // 2
        ans = np.int64(ans)
    else:
        if A - 1 <= N - B:
            if (B - 1) >= (A - 1) + 1:
                ans += (((B - 1) - (A - 1)) // 2) + A
            else:
                ans += B - 1
        else:
            if (B - 1) >= (A - 1) + 1:
                ans += (((N - A) - (N - B)) // 2) + N - B + 1
            else:
                ans += N - A
    print(ans)
 
if __name__ == '__main__':
    main()

Measured memory_bytes: 21748
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int N;
    cin >> N;
    
    string S;
    cin >> S;
    
    int K;
    cin >> K;
    
    char s = S[K - 1];
    
    string ans = "";
    
    for (int i = 0; i < N; i++){
        if (S[i] == s){
            ans += S[i];
        }
        else {
            ans += '*';
        }
    }
    
    cout << ans << endl;
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
typedef vector<pii > vii;
typedef vector<pair<int, pair<int, int> > > viii;
typedef pair<ll,ll> pll;
typedef vector<string> vs;
typedef vector<vii> vvii;

#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define MEM(a,b) memset(a,(b),sizeof(a))
#define all(a) a.begin(),a.end()
#define loop(x,a,b) for(int (x) = (a);(x)<(b);(x)++)
#define rep(x,n)   for(int (x)=0;(x)<(n);(x)++)
#define tr(c,it) for(typeof((c).begin()) it = (c).begin(); it != (c).end(); it++)
#define present(c,x) ((c).find(x) != (c).end()) 
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define ain(a,n) int ((a)[(n)]); for(int i=0; i<(n); i++) cin>>((a)[i])  
#define md 1000000007
#define MAXN 200005

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

    ll n, m, x;
    cin >> n >> m >> x;
    ll c[n];
    ll a[n][m];
    rep(i, n) {
    	cin >> c[i];
    	rep(j, m) {
    		cin >> a[i][j];
    	}
    }
    ll mxn = (1<<13)-1;
    // cout << mxn << endl;
    ll ans = 1e9;
    int found = 0;
    int f = 1;
    for (int i = 0 ; i < mxn ; i++) {
    	ll cost = 0;
    	ll in[m];
    	memset(in, 0, sizeof(in));
    	f = 1;
    	for (int j = 0 ; j < n ; j++) {
	
    		//check if jth bit is set
    		if (i&(1<<j)) {
    			// cout << i << " " << j << endl;
    			cost += c[j];
    			// cout << "cost: " << cost << endl;
    			rep(jj, m) {
    				in[jj] += a[j][jj];
    				// cout << in[jj] << " ";
    			}
    			// cout << endl;
    		}
    		
    	}
    	ll cnt = 0;
    	rep(j, m) {
    		cnt += (in[j] >= x);
    	}
    	if (cnt == m) {
    		// cout << i << endl;
    		found = 1;
    		ans = min(ans, cost);
    	}
    }
    if (found > 0)
    	cout << ans << endl; 
    else
    	cout << -1 << endl;
    return 0;
}




Measured memory_bytes: 3652
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String[] line1 = sc.nextLine().split("");
		String[] line2 = sc.nextLine().split("");
		String[] line3 = sc.nextLine().split("");
		System.out.println(line1[0] + line2[1] + line3[2]);
		sc.close();
	}
}


Measured memory_bytes: 21204
#include <algorithm>
#include <iostream>
using namespace std;
int main(void){
    string x;
    cin >> x;
    transform(x.begin(), x.end(),x.begin(), ::tolower);

    int cnt=0;
    while(true){
        string t;
        cin >> t;
        if(t == "END_OF_TEXT")break;
        transform(t.begin(), t.end(),t.begin(), ::tolower);
        
        if(t==x){
            cnt++;            
        }
    }

    cout << cnt << endl;
}

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

int main() {
  int N;
  cin >> N;
  
  vector<int> p(N),q(N);
  for(int i=0;i<N;i++){
    cin >> p.at(i);
    p.at(i)--;
  }
  for(int i=0;i<N;i++){
    cin >> q.at(i);
    q.at(i)--;
  }
  
  vector<int> junretu(N);
  for(int i=0;i<N;i++){
    junretu.at(i)=i;
  }
  
  int a=1,b=1;
  do{
    bool flag=true;
    for(int i=0;i<N;i++){
      if(junretu.at(i)!=p.at(i)){
        flag=false;
        break;
      }
    }
    if(flag){
      break;
    }
    a++;
  }while(next_permutation(junretu.begin(),junretu.end()));
  
  for(int i=0;i<N;i++){
    junretu.at(i)=i;
  }
  
  do{
    bool flag=true;
    for(int i=0;i<N;i++){
      if(junretu.at(i)!=q.at(i)){
        flag=false;
        break;
      }
    }
    if(flag){
      break;
    }
    b++;
  }while(next_permutation(junretu.begin(),junretu.end()));
  
  cout << abs(a-b);
}


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

int f(vector<int> a) {
	while(a.size() > 1) {
		vector<int> b;
		for(int i = 0; i < a.size() - 2; i++) {
			int c[3] = { a[i], a[i + 1], a[i + 2] };
			sort(c, c + 3);
			b.push_back(c[1]);
		}
		a = b;
	}
	return a[0];
}


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

	int N, x;
	cin >> N >> x;
	if(x == 1 || x == 2 * N - 1) {
		cout << "No" << endl;
		return 0;
	}

	deque<int> b;
	for(int i = 0; i < 2 * N - 1; i++) {
		b.push_back(i + 1);
	}

	if(x < b[b.size() / 2]) {
		int d = abs((x - 1) - (int)b.size() / 2);
		vector<int> c;
		for(int i = 0; i < d; i++) {
			c.push_back(b.back());
			b.pop_back();
		}
		for(int i = d - 1; i >= 0; i--) {
			b.push_front(c[i]);
		}
	}
	else if(x > b[b.size() / 2]) {
		int d = abs((x - 1) - (int)b.size() / 2);
		vector<int> c;
		for(int i = 0; i < d; i++) {
			c.push_back(b.front());
			b.pop_front();
		}
		for(int i = d - 1; i >= 0; i--) {
			b.push_back(c[i]);
		}
	}

	//vector<int> bb(b.begin(), b.end());
	//cout << f(bb) << endl;
	cout << "Yes" << endl;
	for(int i = 0; i < b.size(); i++) {
		cout << b[i] << endl;
	}
}

Measured memory_bytes: 2488
#include<iostream>
#include<cstdio>
#include<vector>
#include<cstring>
#include<algorithm>

#define Lens 500010
using namespace std;
struct Node
{
	int key;
	Node *p, *l, *r;
};
int N;
Node *root, *Nil;
char A[20];

void insert(int i)
{
	Node *x = root;
	Node *y = Nil;
	Node *z;
	z = (Node*)malloc(sizeof(Node));
	z->l = z->p = z->r = Nil;
	z->key = i;
	while (x != Nil)
	{
		y = x;
		if (z->key < x->key)
			x = x->l;
		else
			x = x->r;
	}
	if (y == Nil)
		root = z;
	else
	{
		if (z->key < y->key)
		{
			y->l = z;
			z->p = y;
		}
		else
		{
			y->r = z;
			z->p = y;
		}
	}
}

bool Find(int i)
{
	Node *x = root;
	while (x != Nil)
	{
		if (x->key == i)
			return true;
		else if (i < x->key)
			x = x->l;
		else
			x = x->r;
	}
	return false;
}

void Pre(Node *x)
{
	if (x == Nil)
		return;
	cout << ' ' << x->key;
	Pre(x->l);
	Pre(x->r);
}

void In(Node *x)
{
	if (x == Nil)
	{
		return;
	}
	In(x->l);
	cout << ' ' << x->key;
	In(x->r);
}

Node *findnode(int i)
{
	Node *x = root;
	while (x != Nil)
	{
		if (x->key == i)
			return x;
		else if (i < x->key)
			x = x->l;
		else
			x = x->r;
	}
	return 0;
}

Node *findleft(Node *x)
{
	while (x->l != Nil)
		x = x->l;
	return x;
}

void Delete(int i)
{
	Node *x = findnode(i);
	if (x->l == Nil&&x->r == Nil)
	{
		Node*p = x->p;
		if (x == p->l)
		{
			p->l = Nil;
		}
		else
		{
			p->r = Nil;
		}
		return;
	}

	else if (x->l != Nil&&x->r == Nil)
	{
		Node*p = x->p;
		Node*y = x;
		if (x == p->l)
		{
			p->l = x->l;
		}
		else
		{
			p->r = x->l;
		}
		y->l->p = p;
		return;
	}
	else if (x->l == Nil&&x->r != Nil)
	{
		Node*p = x->p;
		Node*y = x;
		if (x == p->l)
		{
			p->l = x->r;
		}
		else
		{
			p->r = x->r;
		}
		y->r->p = p;
		return;
	}
	else
	{
		Node *r = findleft(x->r);
		Node*p = x->p;
		x->key = r->key;
		if (x->r == r&&r->r != Nil)
		{
			x->r = r->r;
			r->r->p = x;
			return;
		}
		else if (x->r == r&&r->r == Nil)
		{
			x->r = Nil;
			return;
		}
		else
		{
			if (r->r == Nil)
				r->p->l = Nil;
			else
			{
				r->p->l = r->r;
				r->r->p = r->p;
			}
			return;
		}
	}
}

void Print()
{
	In(root);
	cout << endl;
	Pre(root);
	cout << endl;
}

int main()
{
	int k;
	cin >> N;
	for (int i = 0; i < N; i++)
	{
		cin >> A;
		if (A[0] == 'i')
		{
			cin >> k;
			insert(k);

		}
		else if (A[0] == 'f')
		{
			cin >> k;
			if (Find(k))
				cout << "yes" << endl;
			else
				cout << "no" << endl;
		}
		else if (A[0] == 'p')
			Print();
		else if (A[0] == 'd')
		{
			cin >> k;

			Delete(k);
		}

	}
	return 0;
}


Measured memory_bytes: 21744
#include<cstdio>
#include<cstring>
#include<vector>
#include<algorithm>
using namespace std;
const long long MAXN=100005;

long long N,M;
vector<long long> adj[MAXN];
long long dep[MAXN],sum[MAXN],k[MAXN];
bool vis[MAXN];
long long cU,cV,clen;
vector<long long> num;

void dfs(long long u,long long fa=0)
{
	vis[u]=true;
	for(auto v:adj[u])
	{
		if(v==fa)
			continue;
		if(vis[v])
		{
			cU=u;
			cV=v;
			clen=dep[u]-dep[v]+1;
			continue;
		}
		dep[v]=dep[u]+1;
		dfs(v,u);
	}
}
void Calc(long long u,long long fa=0)
{
	vis[u]=true;
	for(auto v:adj[u])
	{
		if(v==fa||vis[v])
			continue;
		Calc(v,u);
		sum[u]+=sum[v];
		k[u]+=k[v];
	}
}

int main()
{
	scanf("%lld%lld",&N,&M);
	for(long long i=1;i<=M;i++)
	{
		long long a,b;
		scanf("%lld%lld",&a,&b);
		adj[a].push_back(b);
		adj[b].push_back(a);
	}
	dep[1]=0;
	dfs(1);
	long long val=0;
	long long ans=0;
	for(long long i=1;i<=N;i++)
	{
		sum[i]=(dep[i]&1)?1:-1;
		val+=sum[i];
	}
	if(M==N-1)
	{
		if(val!=0)
		{
			puts("-1");
			return 0;
		}
	}
	else
	{
		if(clen&1)
		{
			if(val&1)
			{
				puts("-1");
				return 0;
			}
			else
			{
				ans+=(abs(val)/2);
				sum[cU]-=val/2;
				sum[cV]-=val/2;
			}
		}
		else
		{
			if(val!=0)
			{
				puts("-1");
				return 0;
			}
			else
			{
				k[cU]=1;
				k[cV]=-1;
			}
		}
	}
	memset(vis,0,sizeof vis);
	Calc(1);
	for(long long i=1;i<=N;i++)
	{
		if(k[i]==0)
			ans+=abs(sum[i]);
		else
		{
			if(k[i]==1)
				sum[i]=-sum[i];
			num.push_back(sum[i]);
		}
	}
	num.push_back(0);
	sort(num.begin(),num.end());
	long long x=num[(num.size()-1)/2];
	for(auto s:num)
		ans+=1LL*abs(s-x);
	printf("%lld\n",ans);
	
	fclose(stdin);
	fclose(stdout);
	return 0;
}


Measured memory_bytes: 13944
#include <iostream>
#include <vector>

using namespace std;

const int MOD = 998244353;

int main(){
    const int maxSize = 2000001;
	vector<long long> inv(maxSize);
	vector<long long> fact(maxSize);
	vector<long long> factInv(maxSize);
	for(int i=0;i<2;i++) inv[i] = fact[i] = factInv[i] = 1;
	for(int i=2;i<maxSize;i++){
		inv[i] = inv[MOD % i] * (MOD - MOD / i) % MOD;
		fact[i] = fact[i-1] * i % MOD;
		factInv[i] = factInv[i-1] * inv[i] % MOD;
	}
	auto comb = [&](int n, int r){
		if(n < r || r < 0) return 0LL;
		return fact[n] * factInv[n-r] % MOD * factInv[r] % MOD;
	};
    auto perm = [&](int n, int r){
        if(n < r || r < 0) return 0LL;
        return fact[n] * factInv[n-r] % MOD;
    };
    int N, M;
    while(cin >> N >> M){
        long long res = (N * comb(M+N-2, N-2)) % MOD;
        long long sum = 0;
        for(int i=0;i<=M/2;i++){
            int m2 = M+i;
            long long cur = comb(m2+N-1, N-1);
            sum += N * comb(m2-M+N-2, N-2);
            sum %= MOD;
            cur = (cur + MOD - sum) % MOD;
            res += cur * comb(N, M-2*i);
            res %= MOD;
        }
        cout << res << endl;
    }
}

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

using namespace std;
using ll = long long;

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define debug(x) cout << #x << ": " << x << endl;
#define popcnt __builtin_popcount

char grid[100][100];

int main() {
    int H, W; cin>>H>>W;
    for(int i = 0; i < H; i++)
    {
        for(int j = 0; j < W; j++)
        {
            cin>>grid[i][j];
        }
    }
    
    for(int i = 0; i < 2*H; i++)
    {
        for(int j = 0; j < W; j++)
        {
            cout<<grid[i/2][j];
        }
        cout<<endl;
    }
    

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb emplace_back
#define fi first
#define se second
using namespace std;
mt19937_64 rang(chrono::high_resolution_clock::now().time_since_epoch().count());
int rng(int l) { uniform_int_distribution<int> uid(0, l - 1); return uid(rang); }

int32_t main() {
	ios::sync_with_stdio(false); cin.tie(NULL); cout.precision(10); srand(chrono::high_resolution_clock::now().time_since_epoch().count());
	int n; cin >> n;
	int a; cin >> a;
	int b; cin >> b;
	cout << min(a * n, b);
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
int dp[101][10001];
int main(void)
{
	int n,w,v[100],ww[100],i,j,mx;
	scanf("%d %d",&n,&w);
	for(i=0;i<n;i++)	scanf("%d %d",&v[i],&ww[i]);
	for(i=0;i<=n;i++)
		for(j=0;j<=w;j++)	dp[i][j]=-1;
	dp[0][0]=0;
	for(i=0;i<n;i++)	{
		for(j=0;j<=w;j++)	{
			if(j+ww[i]<=w && dp[i][j]!=-1)	{
				dp[i+1][j+ww[i]]=max(dp[i+1][j+ww[i]],dp[i][j]+v[i]);
			}
			if(dp[i][j]!=-1)	{
				dp[i+1][j]=max(dp[i+1][j],dp[i][j]);
			}			
		}
	}
//	for(i=0;i<=n;i++)	{
//		for(j=0;j<=w;j++)	printf("%d ",dp[i][j]);	
//		printf("\n");	
//	}
	
	mx=-1;
	for(i=0;i<=w;i++)	{
		mx=max(mx,dp[n][i]);
	}
	printf("%d\n",mx);
	return 0;
}


Measured memory_bytes: 4968
N,M,C = map(int,input().split())
B = [int(i) for i in input().split()]
A = []
for n in range(N):
    A.append([int(i) for i in input().split()])
cnt = 0
for a in A:
    temp = 0
    for i in range(M):
        temp += a[i] * B[i]
    temp += C
    cnt = cnt + 1 if temp > 0 else cnt
print(cnt)

Measured memory_bytes: 3064
using System;

class _1
{
    static void Main(string[] args)
    {
        string[] input = Console.ReadLine().Split(' ');
        int H = int.Parse(input[0]);
        int W = int.Parse(input[1]);

        input = Console.ReadLine().Split(' ');
        int h = int.Parse(input[0]);
        int w = int.Parse(input[1]);

        Console.WriteLine(H * W - (h * W + w * H - h * w)); 
    }
}

Measured memory_bytes: 13140
#include <cstdio>
#include <algorithm>
#include <string>
using namespace std;
 
int main(){
    int n;
    scanf("%d", &n);
    char buf[16];
    for(int i = 0; ; ++i){
        sprintf(buf, "%d", n - i);
        string s = buf, t = s;
        reverse(s.begin(), s.end());
        if(s == t){
            printf("%d\n", n - i);
            return 0;
        }
 
        sprintf(buf, "%d", n + i);
        s = buf, t = s;
        reverse(s.begin(), s.end());
        if(s == t){
            printf("%d\n", n + i);
            return 0;
        }
    }      
}

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

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

int main(){
  long long int n,k;
  cin >> n >> k;

  long long int a;
  a = n%k;

  cout << min(a, k-a) << endl;
  return 0;
}

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

using namespace std;

#define fst first
#define snd second
#define mp make_pair
#define squ(x) ((LL)(x) * (x))
#define debug(...) fprintf(stderr, __VA_ARGS__)

typedef long long LL;
typedef pair<int, int> pii;

template<typename T> inline bool chkmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }
template<typename T> inline bool chkmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; }

template<typename T> inline T read() {
	T sum = 0, fg = 1; char c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') fg = -1;
	for (; isdigit(c); c = getchar()) sum = (sum << 3) + (sum << 1) + (c ^ 0x30);
	return fg * sum;
}

const int maxn = 5e5 + 10;
const int mod = 998244353;

int n, m;

inline void Add(int &x, int y) { y += (y < 0 ? mod : 0), x += y, x -= (x >= mod ? mod : 0); }
inline int Pow(int x, int y) {
	int res = 1;
	for (; y; y >>= 1, x = squ(x) % mod) if (y & 1) res = (LL) res * x % mod;
	return res;
}

int fac[maxn], ifac[maxn];
inline void init(int N) {
	fac[0] = 1;
	for (int i = 1; i <= N; i++) fac[i] = (LL) fac[i - 1] * i % mod;
	ifac[N] = Pow(fac[N], mod - 2);
	for (int i = N - 1; ~i; i--) ifac[i] = (LL) ifac[i + 1] * (i + 1) % mod;
}
inline int C(int _n, int _m) { return (LL) fac[_n] * ifac[_n - _m] % mod * ifac[_m] % mod ; }

inline int f(int k) { return (LL) C(n, k) * C(m, k) % mod * fac[k] % mod * Pow(m + 1, n - k) % mod * Pow(n + 1, m - k) % mod; }

int main() {
#ifdef xunzhen
	freopen("calc.in", "r", stdin);
	freopen("calc.out", "w", stdout);
#endif

	n = read<int>(), m = read<int>(), init(max(n, m));

	int ans = 0;
	for (int i = 0, e = min(n, m); i <= e; i++) Add(ans, (i & 1 ? -1 : 1) * f(i));
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 4096
/**
 ____ ____ ____ ____ ____
||a |||t |||o |||d |||o ||
||__|||__|||__|||__|||__||
|/__\|/__\|/__\|/__\|/__\|

**/

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

string a, b;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> a >> b;
    int ans = 0;
    for(int i = 0; i < a.size(); i++)
        ans += (a[i] != b[i]);
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 3812
n, x = map(int, input().split())
a = list(map(int, input().split()))
a.append(0)
count = 0
if a[0] > x:
        count += a[0] - x
        a[0] = x
for i in range(n):
        t = a[i] + a[i+1]
        if t > x:
                count += t - x
                a[i+1] -= t - x
print(count)

Measured memory_bytes: 14052
#include<bits/stdc++.h>
using namespace std;
string res[1005];
bool cmp(string const &a,string const &b)
{
    if(a.length()<b.length())
        return a<b;
    return a<b;
}
int has[10000000];
long long DJBHash(string str)
{
    long Hash = 5381;
    for(int i = 0; i < str.length(); i++)
    {
        Hash = ((Hash << 5) + Hash) + str[i];
    }
    return Hash%1000000;
}
int main()
{
    int n,i,ch[5005],xx[1005],len,vis[30],temp,cnt=0;
    char s[5005];
    scanf("%s",s);
    scanf("%d",&n);

    memset(has,0,sizeof(has));
    memset(xx,0,sizeof(xx));
    memset(vis,0,sizeof(vis));
    for(i = 0; s[i]!='\0'; i++)
    {
        int num=s[i]-96;

        if(!vis[num])
            vis[num]=1;
    }
    len=i;
    for(i = 1; i<=26; i++)
        if(vis[i])
            break;
    temp=i;
    bool f=0;
    for(; temp<=26&&!f; temp++)
    {
        if(vis[temp])
        {
            for(i = 0; s[i]!='\0'; i++)
            {
                if(s[i]==temp+96)
                {
                    //cout<<s[i]<<endl;
                    for(int j = i; s[j]!='\0',j<i+5; j++)
                    {
                        char t[6];
                        int tc=0,h=1;
                        for(int u= i; u<=j; u++)
                            t[tc++]=s[u];
                        t[tc]='\0';
                        string sx=t;
                        h=DJBHash(sx);//cout<<h<<endl;
                        if(!has[h])
                        {
                            has[h]=1;


                            //  cout<<sx<<endl;
                            res[cnt++]=sx;
                        }
                    }
                }
            }
            sort(res,res+cnt,cmp);
            int ans=0;
            for(i = 0; i<cnt; i++)
            {
                if(res[i]==res[i+1])
                    continue;
                ans++;
                if(ans==n)
                {
                    cout<<res[i]<<endl;
                    f=1;
                    break;
                }
            }

        }
    }


}


Measured memory_bytes: 39296
N=int(input())
B=list(map(int,input().split()))

from collections import deque


A=deque([])

for i in range(N-1):
    B_i = B[i]

    #初回は2つ入れる
    if i==0:
        A.append(B_i)
        A.append(B_i)

    #初回以降
    else:
        if B_i<=pre_B_i:
            A.pop()
            A.append(B_i)
            A.append(B_i)
        else:
            A.append(B_i)

    #前に入れたものの記録
    pre_B_i = B[i]

print(sum(A))

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

using namespace std;

int main(){
  string str;
  int N,D;
  cin >> N >> str >> D;
  string str2=str;
  for(int i=0;i<str.size();i++){
    if(D==0){
      break;
    }
    if(str[i]=='0'){
      str[i]='1';
      D--;
    }
  }
  for(int i=str.size()-1;i>=0;i--){
    if(D==0){
      break;
    }
    if(str2[i]=='1'){
      str[i]='0';
      D--;
    }
  }
  cout << str <<endl;
}

Measured memory_bytes: 3172