akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <numeric>
#include <stdio.h>
#include <stack>
#include <queue>
#include <cstdio>
#include <cmath>
#include <iterator>
#include <map>

using namespace std;

#define Int int64_t

void printVec(std::vector<int>& vec) {
	std::cout << "";
	for (auto it = vec.begin(); it != vec.end(); ++it) {
		std::cout << *it << " ";
	}
	std::cout << std::endl;
}
void printVec1(std::vector<string>& vec) {
	std::cout << "";
	for (auto it = vec.begin(); it != vec.end(); ++it) {
		std::cout << *it << " ";
	}
	std::cout << std::endl;
}

template<typename T>
void remove(std::vector<T>& vector, unsigned int index)
{
	vector.erase(vector.begin() + index);
}




int main() {
	//int n; cin >> n;
	vector<int> h(5);
	vector<int> amari(5);
	vector<pair<int, int>> sub(5);
	for (int i = 0; i < 5; i++) {
		cin >> h[i];
		amari[i] = h[i] % 10;
		if (amari[i]==0) sub[i].first = 10;
		else sub[i].first = amari[i];
		sub[i].second = h[i];
	}
	
	sort(sub.begin(), sub.end());

	
	int sum = 0;
	for (int i = 1; i < 5; i++) {
		if (sub[i].first!=10) sum += ((sub[i].second / 10) + 1) * 10;
		else sum += sub[i].second;
	}
	sum += sub[0].second;

	cout << sum <<endl;

	return 0;
}

Measured memory_bytes: 256
from math import sqrt, floor

X = int(input())

if X in (1, 2, 3):
    print(1)
    exit(0)


max_beki = 1
base_list = [i for i in range(2, floor(sqrt(X)) + 1)]

for base in base_list:
    beki = base
    while beki <= X:
        beki *= base
        if beki > max_beki and beki <= X:
            max_beki = beki

print(max_beki)


Measured memory_bytes: 3060
#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
inline void rd(int &x){
  int k;
  int m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline int rd_int(void){
  int x;
  rd(x);
  return x;
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(const char c[]){
  int i=0;
  for(i=0;c[i]!='\0';i++){
    putchar_unlocked(c[i]);
  }
}
int main(){
  int Lj4PdHRW;
  int A;
  int KL2GvlyY = rd_int();
  for(Lj4PdHRW=(0);Lj4PdHRW<(KL2GvlyY);Lj4PdHRW++){
    rd(A);
    if(A%2==0 && (A%3!=0 && A%5!=0)){
      wt_L("DENIED");
      wt_L('\n');
      return 0;
    }
  }
  wt_L("APPROVED");
  wt_L('\n');
  return 0;
}
// cLay varsion 20200214-1

// --- original code ---
// 
// {
//   int A;
//   REP(rd_int()){
//     rd(A);
//     if(A%2==0 && (A%3!=0 && A%5!=0)) wt("DENIED"), return 0;
//   }
//   wt("APPROVED");
// }


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define dd(x) cout<<#x<<" = "<<x<<" "
#define de(x) cout<<#x<<" = "<<x<<"\n"
#define sz(x) int(x.size())
#define All(x) x.begin(),x.end()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef priority_queue<int> BQ;
typedef priority_queue<int,vector<int>,greater<int> > SQ;
const int maxn=3e5+10,mod=1e9+7,INF=0x3f3f3f3f;
const double pi=acos(-1);
int main()
{
	int a,b,h,m;
	cin>>a>>b>>h>>m;
	double A=2*pi*double(h*60+m)/(12*60);
	double B=2*pi*double(m)/60;
	double C=fabs(A-B);//dd(A),de(B);de(C);
	if (C-pi>1e-9)
		C=2*pi-C;
	double ans=sqrt(a*a+b*b-cos(C)*2*a*b);
	cout<<fixed<<setprecision(12)<<ans;
	return 0;
}


Measured memory_bytes: 4188
///RAIYAN_MAHIN
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int a,b; cin >> a >> b;
    int d = min(a,b);
    for(int i = 1; i <= max(a,b); i++)
    {
        printf("%d",d);
    }


}


Measured memory_bytes: 256
#include <stdio.h>
int main (){
	int n;
	scanf ("%d", &n);
	int c, r;
	scanf ("%d %d", &c, &r);
	for (int i = c; i <= r; i++){
		if (i % n == 0){
			printf ("OK");
			return 0;
		}else{
		continue;
		}
	}
	printf ("NG");
	return 0;
}

Measured memory_bytes: 1680
from bisect import bisect_left as bs
n = int(input())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
c = [int(i) for i in input().split()]
a.sort()
b.sort()
c.sort()
ab = [0]*(n+1)
for i in range(1,n+1): ab[i] += bs(a,b[i-1]) + ab[i-1]
ans = 0
for i in range(n): ans += ab[bs(b,c[i])]
print(ans)

Measured memory_bytes: 23232
#![allow(unused_imports)]
use std::cmp::*;
use std::collections::*;
use itertools::Itertools;
use num_traits::clamp;
use ordered_float::OrderedFloat;
use proconio::{input, marker::*, fastout};
use superslice::*;

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

    let mut cum = vec![0; n+1];
    let mut map = HashMap::new();
    map.insert(0, 1);
    for i in 0..n {
        cum[i+1] = cum[i] + a[i];
        cum[i+1] %= m;
        *map.entry(cum[i+1]).or_insert(0usize) += 1;
    }
    
    let mut ans = 0usize;
    for i in 0..n {
        let pivot = cum[i];
        let v = map.get_mut(&pivot).unwrap();
        *v -= 1;
        ans += *v;
    }
    println!("{}", ans);
}


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

#define int long long
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define REP(i, n) for (int i = 0; i < n; ++i)
#define range(i,a,b) ((a)<=(i) && (i)<(b))
#define debug(x) cout << #x << " = " << (x) << endl;
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define SP << " " <<

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
typedef vector<int> vec;
typedef vector<P> pvec;
typedef vector<vector<int>> vvec;
typedef vector<vector<P>> pvvec;
typedef priority_queue<int> PQI;
typedef priority_queue<P> PQP;
typedef priority_queue<int,vector<int>,greater<int>> PQIG;
typedef priority_queue<P,vector<P>,greater<P>> PQPG;

const vector<int> DX = {0, -1, 0, 1, 1, 1, -1, -1};
const vector<int> DY = {1, 0, -1, 0, 1, -1, 1, -1};
constexpr int MOD = (1000000007);
// const int MOD = (998244353);
// const int INF = (1 << 30); // 1073741824
const ll INF = (1LL << 60); // 1152921504606846976
const double PI = (3.141592653589794);
const double EPS = (0.0000000001); // 10^(-10)

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return 1;} return 0;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return 1;} return 0;}
template<class T> inline T ceil(T a, T b) {return T((a + b - 1) / b);}
template<class T> inline T round(T a, T b) {return T(a / b);}
template< typename T1, typename T2 > istream &operator>>(istream &is, pair< T1, T2 > &p) { is >> p.first >> p.second; return is; }
template <class T> inline void out(T &a) { bool flag=true; for(auto&x:a){if(flag) {flag=false;} else{ cout << ' '; } cout<<x; } cout << endl; }



//----------------------------------------------------------------
int nmax=200000; // 2*(10^5)
vvec G(nmax);

int ax(vec &a,int &x,int num){
    switch(num){// 1…以下 2…以上 3…未満 4…超過 5…個数
        case 1: return upper_bound(all(a),x)-a.begin();
        case 2: return a.end()-lower_bound(all(a),x);
        case 3: return lower_bound(all(a),x)-a.begin();
        case 4: return a.end()-upper_bound(all(a),x);
        case 5: return upper_bound(all(a),x)-lower_bound(all(a),x);
    }
}


int n,m,k;


void solve4ts()
{
  
  
  cin>>n>>m>>k;
  vector<int> a(n+1);
  rep(i,n) cin >> a[i+1];
  vector<int> b(m+1);
  rep(i,m) cin >> b[i+1];
  
  rep(i,n) a[i+1]+=a[i];
  rep(i,m) b[i+1]+=b[i];


  int ans=0;
  rep(i,n+1){
    if(a[i]<=k){
      int nokori=k-a[i];
      int memo=i;
      memo+=ax(b,nokori,1LL)-1;
      chmax(ans,memo);
    }
  }
  cout<<ans<<endl;
  
}
//-----------------------------------------------------------------

signed main(){ ios::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(15);
    int repeat = 1;
    // cin >> repeat;
    while(repeat--) solve4ts();
}

Measured memory_bytes: 11112
#include<bits/stdc++.h>
typedef long long int ll;
#define ios ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define mod 1000000007
using namespace std;
 
vector<vector<ll>> multiply(vector<vector<ll>> a,vector<vector<ll>> b){
	vector<vector<ll>> res(a.size(),vector<ll>(a[0].size(),0));

	ll i,j,k,n=a.size();
	for(i=0;i<n;i++){
		for(j=0;j<n;j++){
			for(k=0;k<n;k++){
				res[i][j]=(res[i][j]%mod+(a[i][k]*b[k][j])%mod)%mod;
			}
		}
	}

	return res;
}

vector<vector<ll>> power(vector<vector<ll>> g,ll x){
	
	if(x==1){
		return g;
	}

	vector<vector<ll>> res;
	res = power(g,x/2);
	res = multiply(res,res);

	if(x%2==1)
		res = multiply(res,g);

	return res;
}
int main(){
	ll n,k,i,s=0,j;
	cin>>n;
	cin>>k;

	vector<vector<ll>> g(n,vector<ll>(n));
	vector<vector<ll>> res(n,vector<ll>(n));

	for(i=0;i<n;i++){
		for(j=0;j<n;j++){
			cin>>g[i][j];
		}
	}
	res = power(g,k);

	for(i=0;i<n;i++){
		for(j=0;j<n;j++){
			s=(s%mod+res[i][j]%mod)%mod;
		}
	}

	cout<<s<<endl;
}

Measured memory_bytes: 4776
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstring>
using namespace std;

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

int main() {
	int n;
	while(cin >> n, n) {
		bool know[101][101] = {};
		rep(i, n) {
			int m;
			cin >> m;
			rep(j, m) {
				int p;
				cin >> p;
				know[i+1][p] = true;
			}
		}
		int k;
		cin >> k;
		bool no[101] = {};
		rep(i, k) {
			int l;
			cin >> l;
			for(int j=1; j<=n; j++) {
				if(!know[j][l]) {
					no[j] = true;
				}
			}
		}
		int cri = 0;
		for(int i=1; i<=n; i++) {
			if(!no[i]) {
				if(cri==0)
					cri = i;
				else
					cri = -1;
			}
		}
		if(cri==0) cri = -1;
		cout << cri << endl;
	}
	return 0;
}

Measured memory_bytes: 1176
#include<bits/stdc++.h>
using namespace std;
void solve(){
	int d,t,s;
  	cin>>d>>t>>s;
  	if(t*s>=d) cout<<"Yes";
  	else cout<<"No";
}
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	solve();

}

Measured memory_bytes: 3652
import java.util.Scanner;

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

		int N = Integer.parseInt(sc.next());
		int Y = Integer.parseInt(sc.next());
		int[] result = {-1, -1, -1};
		for(int sen=0; sen<=N; sen++) {
			for(int go=0; go<=N-sen; go++) {
				int sum = sen*1000 + go*5000 + (N-sen-go)*10000;
				if(sum == Y) {
					result[0] = sen;
					result[1] = go;
					result[2] = N-sen-go;
				}
			}
		}

		System.out.println(result[2] + " " + result[1] + " " + result[0]);
	}
}

Measured memory_bytes: 21844
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<tuple>
#include<map>
#include<queue>
#include<math.h>
#include<numeric>
#include<iomanip>
#define rep(i, n) rep2(i,0,n)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define PI acos(-1);
typedef long long ll;
using namespace std;
const int MOD = 1000000007;
//scanf("%d", &a); '\n';

int main() {
	//ios::sync_with_stdio(false);
	//cin.tie(0);
	string s;
	cin >> s;
	rep(i, s.size())cout << 'x';
}



Measured memory_bytes: 256
#include <vector>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>
#include <tuple>
#include <set>
#include <map>
#include <complex>
#include <iomanip>
#include <cmath>
using namespace std;
typedef long long ll;

int main()
{
  string a, b, c;
  cin >> a >> b >> c;
  if (a[a.size() - 1] == b[0] && b[b.size() - 1] == c[0]) cout << "YES" << endl;
  else cout << "NO" << endl;
}

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

#define EPS (1e-10)
#define rep(i, a, b) for (int i = a; i < (int)(b); ++i)
#define rrep(i, a, b) for (int i = b - 1; i >= (int)(a); --i)

using namespace std;
using ll = long long;
using vi = vector<int>;
using vb = vector<bool>;
using vll = vector<ll>;
using vd = vector<double>;
using vvi = vector<vi>;
using vvb = vector<vb>;

constexpr int MOD = 1000000007;

ll mpow(ll x, ll p) {
    if (p == 0) { return 1; }
    if (p % 2 == 1) { return (x * mpow(x, p - 1)) % MOD; }
    ll sub = mpow(x, p / 2);
    return (sub * sub) % MOD;
}

ll mod_combination(const vll& fac, const vll& inv, int n, int r) {
    if (r == 0 || r == n) { return 1; }
    return (((fac[n] * inv[r]) % MOD) * inv[n - r]) % MOD;
}

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

    int x, y;
    cin >> x >> y;

    int a = (x + y) / 3;
    int b = x - a;

    if ((x + y) % 3 != 0 || b < 0 || b > a) {
        cout << 0 << endl;
        return 0;
    }

    vll fac(a + 1, 0), inv(a + 1, 0);

    fac[0] = 1;
    rep(i, 1, a + 1) { fac[i] = (i * fac[i - 1]) % MOD; }

    inv.back() = mpow(fac.back(), MOD - 2);
    rrep(i, 0, a) { inv[i] = (inv[i + 1] * (i + 1)) % MOD; }

    cout << mod_combination(fac, inv, a, b) << endl;

    return 0;
}

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

#define NDEBUG
#ifdef DEBUG
#include "../cout11.h"
#undef NDEBUG
#endif
#include <cassert>

typedef long long ll;
typedef long double Double;
typedef unsigned long long ull;
typedef pair<int,int> ii;
typedef pair<ll,ll> llll;
typedef pair<double,double> dd;

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ii> vii;
typedef vector<vector<ii>> vvii;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<long double> vD;

#define sz(a)  int((a).size())
#define pb  push_back
#define FOR(var,from,to) for(int var=(from);var<=(to);++var)
#define rep(var,n)  for(int var=0;var<(n);++var)
#define rep1(var,n)  for(int var=1;var<=(n);++var)
#define repC2(vari,varj,n)  for(int vari=0;vari<(n)-1;++vari)for(int varj=vari+1;varj<(n);++varj)
#define ALL(c)  (c).begin(),(c).end()
#define RALL(c)  (c).rbegin(),(c).rend()
#define tr(i,c)  for(auto i=(c).begin(); i!=(c).end(); ++i)
#define found(s,e)  ((s).find(e)!=(s).end())
#define mset(arr,val)  memset(arr,val,sizeof(arr))
#define mid(x,y) ((x)+((y)-(x))/2)
#define IN(x,a,b) ((a)<=(x)&&(x)<=(b))
#define cons make_pair


long long max_box_area_in_histogram(vector<int>& a) {
    int N = a.size();

    vector<int> L(N);
    stack<int> st;

    for (int i=0; i<N; ++i) {
        while (!st.empty() && a[st.top()] >= a[i]) {
            st.pop();
        }
        L[i] = (st.empty() ? -1 : st.top())+1;
        st.push(i);
    }

    while (!st.empty()) st.pop();

    vector<int> R(N);
    for (int i=N-1; i>=0; --i) {
        while (!st.empty() && a[st.top()] >= a[i]) {
            st.pop();
        }
        R[i] = (st.empty() ? N : st.top())-1;
        st.push(i);
    }

    long long smax = 0;
    for (int i=0; i<N; ++i) {
        // ll s = (long long)a[i] * (R[i] - L[i] + 1);
        ll s = (long long)(a[i] + 1) * (R[i] - L[i] + 1 + 1);
        smax = max(smax, s);
    }

    return smax;
}


ll solve(int H, int W, vector<string>& s) {
    vvi a(H, vi(W-1, 0));
    rep(r, H) {
        rep(c, W-1) {
            a[r][c] = (s[r][c] == '#') ^ (s[r][c+1] == '#');
        }
    }
    vvi b(H-1, vi(W-1, 0));
    rep(c, W-1) {
        rep(r, H-1) {
            b[r][c] = a[r][c] ^ a[r+1][c];
        }
    }

    ll best = max(W, H);

    vi histo(W-1, 0);
    rep(r, H-1){
        rep(c, W-1) {
            if (b[r][c]) histo[c] = 0;
            else histo[c]++;
        }
        // cerr << histo << endl;
        best = max(best, max_box_area_in_histogram(histo));
    }

    return best;
}

int main() {
    int H, W; cin >> H >> W;
    vector<string> s(H);
    rep(i, H) cin >> s[i];
    cout << solve(H,W,s) << endl;
    return 0;
}


Measured memory_bytes: 35712
//的場梨沙★担当
//結城晴★副担当
//日野茜★副担当
#include <vector>
#include <list>
#include <map>
#include <climits>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string.h>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
#include <random>
#include <cctype>
#include <complex>
#include <regex>
#include <unordered_map>
#include <string>
#include <algorithm>
#include <cctype>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <iomanip>
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <stdio.h>


using namespace std;

int main(void) {
    int N,M,X;
    cin>>N>>M>>X;
    vector<int>A(M);
    for(int i=0;i<M;i++)cin>>A[i];
    int L=0;
    int R=0;
    for(int i=0;i<M;i++){
        if(A[i]<X){
            L++;
        }
        else{
            R++;
        }
    }

    int ans=min(L,R);

    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include<stdio.h>

int main()
{
    int a,b,e;
    char op;
    scanf("%d %c %d",&a,&op,&b);
    if(op=='+')
    {
          printf("%d",a+b);
    }
     else
    {
          printf("%d",a-b);
    }
    return 0;
}

Measured memory_bytes: 1680
#include<stdio.h>
#include<algorithm>
using namespace std; 
int a[100010];
int main()
{
	int n,i;
	scanf("%d",&n);
	for(i=1;i<=n;i++)
	scanf("%d",&a[i]);
	sort(a+1,a+n+1);
	if(n%2!=0) printf("0\n");
	else
	{
		int m=n/2;
		m=a[m+1]-a[m];
		printf("%d\n",m);
	}

}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = std::int_fast64_t;
using std::cout;
using std::endl;
using std::cin;

template<typename T>
std::vector<T> make_v(size_t a){return std::vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return std::vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

int main() {
	i64 n; scanf("%lld", &n);

	i64 ans = 1LL << 60;
	for(i64 i = 1; i * i <= n; i++) {
		if(n % i) continue;

		ans = std::min(ans, (i - 1) + (n / i - 1));
	}
	printf("%lld\n", ans);
	return 0;
}


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

using namespace std;

int dp[3010][3010];

int32_t main() {
    int n;
    cin >> n;
    vector<int> a(n);
    vector<int> sum(n + 1);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        dp[i][i + 1] = a[i];
        sum[i + 1] = sum[i] + a[i];
    }
    for (int len = 2; len <= n; len++) {
        for (int l = 0; l + len <= n; l++) {
            int r = l + len;
            dp[l][r] = max(
                            sum[r] - sum[l] - dp[l + 1][r],
                            sum[r] - sum[l] - dp[l][r - 1]
                           );
        }
    }
    cout << dp[0][n] - (sum[n] - dp[0][n]) << endl;
}


Measured memory_bytes: 49772
N = int(input())
c = input()

ws = [i for i in range(N) if c[i] == 'W']
rs = [i for i in range(N) if c[i] == 'R']

if len(ws) == 0 or len(rs) == 0:
    print(0)
else:
    ans = 0
    while ws and rs and ws[0] < rs[-1]:
        del ws[0]
        del rs[-1]
        ans += 1
    print(ans)


Measured memory_bytes: 17380
#include <inttypes.h>
#include <math.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(void)
{
    intmax_t N, A[100];
    intmax_t ans = 0;

    scanf("%jd", &N);
    for (size_t i = 0; i < N; i++) {
        scanf("%jd", &A[i]);
    }

    for (size_t i = 0; i < N; i++) {
        if (A[i] % 2 == 0) {
            if ((A[i] % 3 != 0) && (A[i] % 5 != 0)) {
                puts("DENIED");
                return 0;
            }
        }
    }

    puts("APPROVED");

    return 0;
}


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

int main(){
  int N;
  cin >> N;
  string S;
  cin >> S;
  int count = 0;
  
  for (int i = 0; i < N / 2; i++){
    
    if (S.at(i) != S.at(i + N / 2)){
      break;
    }
    else{
      count++;
    }
  }
  
  if (count == N / 2 && N % 2 == 0){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}
        

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a,b;
  cin >>a >>b;
  if( a %3 == 0 || b%3==0||(a+b)%3==0){
    cout << "Possible";
  }
  else{
    cout << "Impossible";
  }
}

Measured memory_bytes: 256
n, k = map(int, input().split())
all_sunuke = [1]*n

for i in range(0,k):
  d = int(input())
  a = list(map(int, input().split()))
  for j in range(0,d):
      all_sunuke[(a[j]-1)] =all_sunuke[(a[j]-1)]*0

print(sum(all_sunuke))

Measured memory_bytes: 9196
#include <algorithm>
#include <iostream>
#include <queue>
#include <vector>

using namespace std;

typedef long long ll;
// typedef pair<ll, ll> P;
typedef pair<int, int> P;

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

int main() {
  int H, W;
  cin >> H >> W;
  char s[H][W];
  int dist[H][W];
  int black = 0;
  REP(i, H) REP(j, W) {
    cin >> s[i][j];
    dist[i][j] = 1e9;
    if (s[i][j] == '#') black++;
  }
  int dy[4] = {-1, 0, 1, 0};
  int dx[4] = {0, 1, 0, -1};
  queue<P> que;
  que.push(P(0, 0));
  dist[0][0] = 0;
  while (que.size()) {
    P p = que.front();
    que.pop();
    REP(i, 4) {
      int ny = p.first + dy[i];
      int nx = p.second + dx[i];
      if (0 <= ny && ny < H && 0 <= nx && nx < W && s[ny][nx] != '#' &&
          dist[ny][nx] == 1e9) {
        que.push(P(ny, nx));
        dist[ny][nx] = dist[p.first][p.second] + 1;
      }
    }
  }
  if (dist[H - 1][W - 1] == 1e9)
    cout << -1 << endl;
  else
    cout << H * W - (black + dist[H - 1][W - 1] + 1) << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <iomanip>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;


#define rep(i,n) for (int i=0; i<(n); i++)
const int INF =2*1e5+5;
const ll BIG = 1e9+7;
const double PI = 3.141592653589793;

P f(int x){
    int a = x%10;
    int b = 0;
    while(x){
        b = x;
        x /= 10;
    }
    return P(a,b);
}


int main(){
    int n;
    cin >> n;
    map<P,int> freq;
    for(int i=1; i<=n; i++){
        P p = f(i);
        freq[p]++;
    }
    ll ans = 0;
    for(int i=1; i<=n; i++){
        P p = f(i);
        P q(p.second, p.first);
        ans += freq[q];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3588
#define _CRT_SECURE_NO_WARNINGS

#include<iostream>
#include<string>
#include<vector>
#include<list>
#include<stack>
#include<queue>
#include<map>
#include<tuple>
#include<algorithm>
#include<numeric>
#include<math.h>
#include <iomanip>

#define REPS(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) for (int i = 0; i < (n); i++)

using namespace std;

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

const long double pi = 3.141592653589793238462643383279502884197;
const long double eps = 1e-7;

int main() {
	ll n, m, d;
	cin >> n >> m >> d;
	double ans = 0;
	if (d == 0) {
		ans = (double)(m - 1) / n;
	}
	else {
		ans = 2.0 * (m - 1)*(n - d) / (n*n);
	}
	cout << fixed;
	cout << setprecision(7) << ans;
	system("pause");
	return 0;
}

Measured memory_bytes: 504
#include<bits/stdc++.h>
using namespace std;
int a[100];
bool b[100];
int s[100],c[100];
int main()
{
	memset(b,0,sizeof(b));
	memset(a,0,sizeof(a));
	int n,m,i,p=0;
	scanf("%d %d",&n,&m);
	for(i=0;i<m;i++)
	{
		scanf("%d %d",&s[i],&c[i]);
	}
	for(i=0;i<m;i++)
	{
		if(b[s[i]]==1&&a[s[i]]!=c[i])
		{
			p=1;
			break;
		}
		else
		{
			a[s[i]]=c[i];
			b[s[i]]=1;
		}
	}
	if(n>1&&a[1]==0&&b[1]==1)
	p=1;
	if(n>1&&b[1]==0&&a[1]==0)
	{
		a[1]=1;
	} 
	
	if(p)
	printf("-1");
	else
	{
		if(n>1)
		{
			for(i=1;i<=n;i++)
		{
			printf("%d",a[i]);
		}
		}
		if(n==1)
		{
			printf("%d",a[1]);
		}
	}
}

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

using ll = int64_t;
#define int ll

#define FOR(i, a, b) for (int i = int(a); i < int(b); i++)
#define REP(i, b) FOR(i, 0, b)
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define ALL(x) x.begin(), x.end()

using pi = pair<int, int>;
using vi = vector<int>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  REP(i, (int)v.size()) {
    if (i)
      os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}

ll read() {
  ll i;
  scanf("%" SCNd64, &i);
  return i;
}

void printSpace() { printf(" "); }

void printEoln() { printf("\n"); }

void print(ll x, int suc = 1) {
  printf("%" PRId64, x);
  if (suc == 1)
    printEoln();
  if (suc == 2)
    printSpace();
}

string readString() {
  static char buf[3341000];
  scanf("%s", buf);
  return string(buf);
}

char *readCharArray() {
  static char buf[3341000];
  static int bufUsed = 0;
  char *ret = buf + bufUsed;
  scanf("%s", ret);
  bufUsed += strlen(ret) + 1;
  return ret;
}

template <class T, class U> void chmax(T &a, U b) {
  if (a < b)
    a = b;
}

template <class T, class U> void chmin(T &a, U b) {
  if (b < a)
    a = b;
}

template <class T> T Sq(const T &t) { return t * t; }

const int mod = 1e9 + 7;

signed main() {
  int n = read(), ans = 1e9;
  REP(i, n) {
    int tmp = read(), cnt = 0;
    while ((tmp & 1) == 0 && tmp != 0) {
      tmp /= 2;
      cnt++;
    }
    chmin(ans, cnt);
  }
  print(ans);
}


Measured memory_bytes: 256
import Control.Monad
f x = do
  hw_in <- (return . words) =<< getLine
  let h:w:[] = map (read::String->Int) hw_in
  if (h==0) && (w==0)
    then return () else do
      forM_ [1..h] (\i->putStrLn ['#'|j<-[1..w]])
      putStrLn ""
      f (x+1)

main = f 0


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

using namespace std;

int main()
{
	int n;
	cin >> n;
	
	// 奇数番目の値の個数のカウント用
	vector<int> odds(100001, 0);
	// 偶数番目の値の個数のカウント用
	vector<int> evens(100001, 0);
	// 入力されたvの値が何個あるのかを数えるための対応
	// iが奇数の場合は、奇数番目の配列へ、iが偶数のの場合は偶数番目の配列へ
	for (int i = 0; i < n; i++)
	{
		int v;
		cin >> v;
		if (i % 2 == 0)
		{
			odds[v]++;
		}
		else {
			evens[v]++;
		}
	}
	
	// 奇数番目の配列の最大値と最小値を出す
	int minOdds = 0;
	int maxOdds = 0;
	// 偶数番目の配列の最大値と最小値を出す
	int minEvens = 0;
	int maxEvens = 0;
	
	for (int i = 1; i <= 100000; i++)
	{
		// 奇数番目の配列の計算
		if (odds[i] >= odds[maxOdds])
		{
			minOdds = maxOdds;
			maxOdds = i;
		}
		else if (odds[i] >= odds[minOdds])
		{
			minOdds = i;
		}
		
		// 偶数番目の配列の計算
		if (evens[i] >= evens[maxEvens])
		{
			minEvens = maxEvens;
			maxEvens = i;
		}
		else if (evens[i] >= evens[minEvens])
		{
			minEvens = i;
		}
	}
	
	// 出力
	int answer = 0;
	if (maxOdds != maxEvens)
	{
		answer = n - odds[maxOdds] - evens[maxEvens];
	}
	else {
		if (odds[maxOdds] - odds[minOdds] <= evens[maxEvens] - evens[minEvens])
		{
			answer = n - odds[minOdds] - evens[maxEvens];
		}
		else {
			answer = n - odds[maxOdds] - evens[minEvens];
		}
	}
	cout << answer << endl;
	
	return 0;
}

Measured memory_bytes: 1152
#include <iostream>
#include <stack>
#include <queue>
#include <vector>
#include <algorithm>
#include <string>
#include <iomanip>
#include <functional>
#include <map>
#include <math.h>
#include <list>

using namespace std;

int main(void) {

   long long int a,v,b,w,t;
    cin >> a >> v >> b >> w >> t;
    
    long long int la,lb;
if(a < b){
    la = a + v*t;
    lb = b + w*t;
}
else {
    la = a - v*t;
    lb = b - w*t;

}

    if(a < b && la >= lb) cout << "YES" << endl;
    else if(a > b && la <= lb) cout << "YES" << endl;
    else cout << "NO" << endl;




	return 0;
}


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

int main()
{
    string s;
    cin >> s;

    map<char, int> mp;
    rep(i, int(s.size())) mp[s.at(i)]++;

    int max_v = 0, min_v = s.size();
    for (char c = 'a'; c <= 'c'; c++)
    {
        max_v = max(max_v, mp[c]);
        min_v = min(min_v, mp[c]);
    }

    string answer = "NO";
    if (s.size() % 3 == 0 && max_v - min_v == 0)
    {
        answer = "YES";
    }
    else if (s.size() % 3 == 1 && max_v - min_v == 1)
    {
        answer = "YES";
    }
    else if (s.size() % 3 == 2 && max_v - min_v == 1)
    {
        answer = "YES";
    }

    cout << answer << endl;
}

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

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

  int ans = L;
  ans -= max((A + C - 1) / C, (B + D - 1) / D);

  cout << ans << endl;

  return 0;
}


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

int main() {
    /* 入力受け取り */
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; ++i) cin >> a[i];

    /* しゃくとり法 */
    long long res = 0;
    int right = 0;
    int sum = 0; // AND 和
    for (int left = 0; left < n; ++left) {
        while (right < n && (sum ^ a[right]) == (sum + a[right])) {
            sum += a[right];
            ++right;
        }
        res += right - left;
        if (left == right) ++right;
        else {
            sum -= a[left]; // a[left] を削除 (sum ^= a[left] でも OK)
        }
    }

    cout << res << endl;
}

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

#define REP(i,n) for(int i=0; i < (n); ++i)
#define REPR(i,n) for(int i=(n); i >=0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)

typedef long long ll;
#define INF 1e9

int main(){
  int N;
  ll mini = 1e16;
  cin >> N;
  vector<ll> a(N), sum(N+1);
  sum[0] = 0;
  REP(i, N){
    cin >> a[i];
    sum[i+1] = sum[i] + a[i];
  }

  FOR(i, 1, N){
    ll x = sum[i];
    ll y = sum[N] - x;
    mini = min(mini, abs(x-y));
  }
  cout << mini << endl;
  return 0;
}

Measured memory_bytes: 3456
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(300000)


def solve(N: int):
    ret = 800 * N - (N // 15) * 200
    print(ret)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    solve(N)

if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<cassert>

typedef long long ll;
typedef unsigned long long ull;

using namespace std;

int n;
set<string> s;

int main()
{
	cin>>n;
	string  tmp,lst;
	for(int i=1;i<=n;i++)
	{
		cin>>tmp;
		if(i!=1)
		{
			if(*(lst.end()-1)!=*tmp.begin()) return puts("No"),0;
		}
		if(s.find(tmp)!=s.end()) return puts("No"),0;
		s.insert(tmp);lst=tmp;
	}
	puts("Yes");
}

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

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repp(i, l, r) for(int i = (l); i < (r); i++)
#define per(i, n) for(int i = ((n)-1); i >= 0; i--)
#define perr(i, l, r) for(int i = ((r)-1); i >= (l); i--)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define IINF 1000000000
#define LINF 1000000000000000000
#define SP <<" "<<
#define CYES cout<<"Yes"<<endl
#define CNO cout<<"No"<<endl
#define CFS cin.tie(0);ios::sync_with_stdio(false)

typedef long long LL;
typedef long double LD;

int main(){
  while(1){
    LL n,m,q;
    cin >> n >> m >> q;
    if(n==0) return 0;
    vector<LL> v(m,(1LL<<n)-1);
    vector<int> swi(n,0);
    rep(tt,q){
      string s,t;
      cin >> s >> t;
      rep(i,n){
        if(s[i]=='1') swi[i]=1-swi[i];
      }
      rep(i,m){
        LL x=(1LL<<n)-1;
        if(t[i]=='1'){
          rep(j,n){
            if(swi[j]==0) x^=(1LL<<j);
          }
        }else{
          rep(j,n){
            if(swi[j]==1) x^=(1LL<<j);
          }
        }
        v[i]&=x;
      }
    }
    rep(i,m){
      int ans=-1;
      rep(j,n){
        if(v[i]&(1LL<<j)){
          if(ans==-1) ans=j;
          else ans=-2;
        }
      }
      if(ans==-2) cout << '?';
      else if(ans<10) cout << ans;
      else cout << (char)(ans-10+'A');
    }
    cout << endl;
  }
  return 0;
}



Measured memory_bytes: 3148
#include <iostream>
#include <vector>
#include <map>
#include <tuple>
#include <utility>
#include <algorithm>
#include <limits>
using i64 = long long;
using Ps = std::vector<std::pair<int, int>>;

enum { R, L, D, U };
constexpr int inf = std::numeric_limits<int>::max() / 100;

auto calc(const Ps &xs, const Ps &ys, const int sgn, const bool flg = false) {
    int ret = inf;
    std::map<int, std::vector<int>> p, q;
    for (const auto [x, y] : xs) p[x + sgn * y].push_back(x);
    for (const auto [x, y] : ys) q[x + sgn * y].push_back(x);

    for (const auto &[d, v] : p) {
        const auto it = q.find(d);
        if (it == q.end()) continue;
        auto &w = it->second;
        std::sort(w.begin(), w.end());
        for (const int e : v) {
            auto jt = std::upper_bound(w.begin(), w.end(), e);
            if (flg) {
                if (jt != w.begin()) ret = std::min(ret, e - *--jt);
            } else {
                if (jt != w.end()) ret = std::min(ret, *jt - e);
            }
        }
    }

    // fprintf(stderr, "ret = %d\n", ret);

    return ret;
}

auto calcx(const Ps &rs, const Ps &ls) {
    int ret = inf;

    std::vector<std::vector<int>> p(202020), q(202020);
    for (const auto [x, y] : rs) p[y].push_back(x);
    for (const auto [x, y] : ls) q[y].push_back(x);

    for (int i = 0; i <= 200000; i++) {
        if (p[i].empty() || q[i].empty()) continue;
        auto &v = p[i], &w = q[i];
        std::sort(w.begin(), w.end());
        for (const int e : v) {
            const auto jt = std::upper_bound(w.begin(), w.end(), e);
            if (jt != w.end()) ret = std::min(ret, *jt - e);
        }
    }

    // fprintf(stderr, "ret = %d\n", ret);

    return ret;
}

auto calcy(const Ps &us, const Ps &ds) {
    int ret = inf;

    std::vector<std::vector<int>> p(202020), q(202020);
    for (const auto [x, y] : us) p[x].push_back(y);
    for (const auto [x, y] : ds) q[x].push_back(y);

    for (int i = 0; i <= 200000; i++) {
        if (p[i].empty() || q[i].empty()) continue;
        auto &v = p[i], &w = q[i];
        std::sort(w.begin(), w.end());
        for (const int e : v) {
            const auto jt = std::upper_bound(w.begin(), w.end(), e);
            if (jt != w.end()) ret = std::min(ret, *jt - e);
        }
    }

    // fprintf(stderr, "ret = %d\n", ret);

    return ret;
}

int main() {
    int n;
    std::cin >> n;
    std::vector<Ps> v(4);
    for (int i = 0; i < n; i++) {
        int x, y;
        char c;
        std::cin >> x >> y >> c;
        const int d = c == 'L' ? L : c == 'R' ? R : c == 'D' ? D : U;
        v[d].emplace_back(x, y);
    }

    int ret = std::min({
        calc(v[R], v[U], 1) * 10,
        calc(v[L], v[D], 1, true) * 10,
        calc(v[R], v[D], -1) * 10,
        calc(v[L], v[U], -1, true) * 10,
        calcx(v[R], v[L]) * 5,
        calcy(v[U], v[D]) * 5,
    });

    if (ret >= 5 * inf) std::cout << "SAFE" << std::endl;
    else std::cout << ret << std::endl;

    return 0;
}


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

using namespace std;

bool is_prime(int n, int k = 2)
{
    if(n < k * k) { return true; }
    
    if(n % k == 0) { return false; }
    
    return is_prime(n, k + 1);
}

int main()
{
    vector<int> prime = {2};
    
    for(int i = 3; i < 105000; i += 2)
    {
        if(is_prime(i))
        {
            prime.push_back(i);
        }
    }
    
    int n, m;
    
    while(true)
    {
        scanf("%d", &n);
        scanf("%d", &m);
        
        if(n == -1 && m == -1) { break; }
        
        int ptr = distance(prime.begin(), lower_bound(prime.begin(), prime.end(), n + 1));
        
        vector<int> c;
        
        for(int i = ptr; i < ptr + m; i++)
        {
            for(int j = i; j < ptr + m; j++)
            {
                c.push_back(prime[i] + prime[j]);
            }
        }
        
        sort(c.begin(), c.end());
        
        printf("%d\n", c[m - 1]);
    }
    
    return 0;
}

Measured memory_bytes: 3216
#include <bits/stdc++.h>
#define fast ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define N  100000
#define mod 998244353


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

using namespace std;


int main() {
	fast;
	int n,m;
	cin>>n;
	vector<int> t(n+1);
	for(int i=1;i<=n;i++) cin>>t[i];
	cin>>m;
	for(int i=1;i<=m;i++){
		int p,x,sum=0;
		cin>>p>>x;
		for(int i=1;i<=n;i++){
			if(i==p) sum+=x;
			else sum+=t[i];
		}
			cout<<sum<<endl;
	}
	
}


Measured memory_bytes: 256
#include <cstdio>
#include <map>
using namespace std;
typedef long long ll;
ll n, a, s, ans;
map<ll, ll> mp;
int main() {
	scanf("%lld", &n);
	mp[0] = 1;
	while(n--) {
		scanf("%lld", &a);
		s += a;
		ans += mp[s];
		mp[s]++;
	}
	printf("%lld", ans);
	return 0;
}

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

using namespace std;

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

	int n, k;
	cin >> n >> k;
	unsigned int res = k;
	--k;
	for (int i = 1; i < n; i++) {
		res *= k;
	}
	cout << res << '\n';

	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include<numeric>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; 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()
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int main(){
    cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	//cout << fixed << setprecision(15);
    string S,T;
    cin >> S;
    cin >> T;
    bool flag = true;
    REP(i,S.size()){
        if(S[i] != T[i]) {flag = false; break;}
    }
    cout <<(flag ? "Yes" : "No") << endl;
}

Measured memory_bytes: 3644
n=int(input())
a=list(map(int,input().split()))
# 元の数列から連続する区間[i,j) を抜き出した状態から、
# 最善を尽くした場合のX-Yの最大値
dp=[[0]*(n+1) for i in range(n+1)]

for i in range(n + 1):
    dp[i][i] = 0

for length in range(1,n+1):
  for i in range(n+1):
    j=length+i
    if j<=i or j>n:continue
    if (n-length)%2==0:
      # 先手
      dp[i][j]=max(dp[i+1][j]+a[i],dp[i][j-1]+a[j-1])
    else:
      # 後手
      dp[i][j]=min(dp[i+1][j]-a[i],dp[i][j-1]-a[j-1])

print(dp[0][n])

Measured memory_bytes: 113628
#include <bits/stdc++.h>
#define ll long long
#define lsb(x) (x & -x)

using namespace std;

const int NMAX = 100003;
int MOD;
vector<ll> pl[NMAX], pr[NMAX];

void dfsdown(int node, int dad, const vector<vector<int>> &g, vector<ll> &black_down) {
    black_down[node] = 1;
    for(auto it : g[node]) {
        if(it == dad)
            continue;
        dfsdown(it, node, g, black_down);

        black_down[node] = (black_down[node] * (black_down[it] + 1)) % MOD;
    }

    pl[node][0] = 1;
    for(int i = 0; i < g[node].size(); i ++) {
        if(g[node][i] == dad)
            pl[node][i + 1] = pl[node][i + 1 - 1];
        else
            pl[node][i + 1] = (pl[node][i + 1 - 1] * (black_down[g[node][i]] + 1)) % MOD;
    }

    pr[node][g[node].size() + 1] = 1;
    for(int i = g[node].size() - 1; i >= 0; i --) {
        if(g[node][i] == dad)
            pr[node][i + 1] = pr[node][i + 1 + 1];
        else
            pr[node][i + 1] = (pr[node][i + 1 + 1] * (black_down[g[node][i]] + 1)) % MOD;
    }
}

void dfsup(int node, int dad, const vector<vector<int>> &g, vector<ll> &black_up) {
    for(int i = 0; i < g[node].size(); i ++) {
        int it = g[node][i];
        if(it == dad)
            continue;

        black_up[it] =  (pl[node][i + 1 - 1] * pr[node][i + 1 + 1]) % MOD;
        black_up[it] = (black_up[it] * black_up[node] + 1) % MOD;

        dfsup(it, node, g, black_up);
    }
}

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

    cin.tie(0);
    cout.tie(0);
    //freopen("a.in", "r", stdin);

    int n;
    cin >> n >> MOD;
    vector<vector<int>> g(n + 1);
    vector<vector<int>> partialproduct(n + 1);
    for(int i = 1; i < n; i ++) {
        int x, y;
        cin >> x >> y;
        g[x].push_back(y);
        g[y].push_back(x);
    }

    for(int i = 1; i <= n; i ++) {
        pl[i].resize(g[i].size() + 3, 1);
        pr[i].resize(g[i].size() + 3, 1);
    }

    vector<ll> black_down(n + 1, 0);
    dfsdown(1, 0, g, black_down);

    vector<ll> black_up(n + 1, 0);
    black_up[1] = 1;
    dfsup(1, 0, g, black_up);

    for(int i = 1; i <= n; i ++)
        cout << (black_down[i] * black_up[i]) % MOD << "\n";


    return 0;
}


Measured memory_bytes: 31488
#include<bits/stdc++.h>
using namespace std;
int main(){
  int64_t N;
  cin >> N;
  //約数列挙
  vector<int64_t> div(0);
  for(int64_t n=1; n*n<=N; n++){
    if(N %n == 0){
      div.push_back(n);
      if(N /n != n){
        div.push_back(N /n);
      }
    }
  }
  int64_t ans = 0;
  for(int i=1; i<div.size(); i++){
    int64_t n = N;
    while(n %div.at(i) == 0){
      n /= div.at(i);
    }
    if(n %div.at(i) == 1){
      ans++;
    }
  }
  vector<int64_t> div1(0);
  N--;
  for(int64_t n=1; n*n<=N; n++){
    if(N %n == 0){
      div1.push_back(n);
      if(N /n != n){
        div1.push_back(N /n);
      }
    }
  }
  cout << ans + div1.size() - 1 << endl;
}

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

class BFS
{
    private: 
    int h,w;
    int dx[4] = {0,1,0,-1};
    int dy[4] = {1,0,-1,0};

    public:
    vector<string> field;
    vector<vector<int>> cost;

    BFS(vector<string> f): field(f)
    {
        h = f.size();
        w = f[0].size();
        cost.assign(h,vector<int>(w,-1));
    }

    void bfs(queue<pair<int,int>> starts)
    {
        queue<pair<int,int>> que = starts;
        while(!que.empty())
        {
            auto top = que.front();
            que.pop();
            int ny = top.first, nx = top.second;
            for(int i=0;i<4;++i)
            {
                int tx = nx + dx[i], ty = ny + dy[i];
                if(ty < h && tx < w && ty > -1 && tx > -1)
                {
                    if(cost[ty][tx] == -1)
                    {
                        cost[ty][tx] = cost[ny][nx]+1;
                        que.push({ty,tx});
                    }
                }
            }
        }
    }
};

int main()
{
    int h,w;
    cin >> h >> w;
    vector<string> a(h);
    queue<pair<int,int>> starts;
    for(int i=0;i<h;++i)cin >> a[i];
    BFS bfs(a);
    for(int i=0;i<h;++i)
    {
        for(int j=0;j<w;++j)
        {
            if(a[i][j] == '#')
            {
                starts.push({i,j});
                bfs.cost[i][j] = 0;
            }
        }
    }
    bfs.bfs(starts);
    int ans = 0;
    for(int i=0;i<h;++i)
    {
        for(int j=0;j<w;++j)
        {
            ans = max(ans,bfs.cost[i][j]);
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 30864
#include<cstdio>

using namespace std;

int main(){
	char s[20]; scanf("%s", s);
	char t[20]; int l = 0;
	for(int i = 0; s[i] != '\0'; i++){
		if(s[i] == '0') t[l++] = '0';
		if(s[i] == '1') t[l++] = '1';
		if(s[i] == 'B' && l > 0) l--;
	}
	t[l] = '\0'; puts(t);
	return 0;
}

Measured memory_bytes: 128
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"

using namespace std;

const long long int MOD = 1000000007;
const long double EPS = 1e-8;

long long int N, M, K, H, W, L, R;

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

	string s;
	cin >> s;
	vector<int>a;
	vector<int>b;
	vector<int>c;
	while (s.size()>3) {
		map<char, int>m;
		for (auto i : s) {
			m[i]++;
		}
		a.push_back(m['A']);
		b.push_back(m['B']);
		c.push_back(m['C']);
		char nx = 'A';
		if (m[nx] > m['B'])nx = 'B';
		if (m[nx] > m['C'])nx = 'C';
		int l = -100;
		string t;
		for (int i = 0; i < s.size(); i++) {
			if (s[i] == 'A') {
				l = i;
				t.push_back('A');
			}
			if (s[i] == 'B') {
				if (l != i - 1) {
					l = -100;
				}
				t.push_back('B');
			}
			if (s[i] == 'C') {
				if (l == i - 2) {
					t.pop_back();
					t.pop_back();
					t.push_back(nx);
				}
				else {
					t.push_back('C');
				}
				l = -100;
			}
		}
		if (s == t)break;
		s = t;
	}
	N = a.size();
	bool ans = true;
	for (int i = N - 1; i > 0; i--) {
		bool box = false;
		if (a[i] + b[i] == b[i - 1] && a[i] + c[i] == c[i - 1])box |= true;
		if (b[i] + a[i] == a[i - 1] && b[i] + c[i] == c[i - 1])box |= true;
		if (c[i] + a[i] == a[i - 1] && c[i] + b[i] == b[i - 1])box |= true;
		ans &= box;
	}
	if (ans&&s=="ABC")cout << "Yes\n";
	else cout << "No\n";
	return 0;
}


Measured memory_bytes: 3264
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int ll
typedef vector<int> vi;
#define endl '\n'
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define rf(i,a,b) for(int i=a;i>=b;i--) 
#define fast_io ios_base::sync_with_stdio(0);
#define show(x) cout<<x<<endl;
#define pret(x) cout<<x<<endl; return 0;
#define disp(x) cout<<x<<" ";
#define let(x,y) cout<<x<<" "<<y<<endl;
ll MOD=1e9+7;
const int maxn=2e5+5;

int cnt[maxn];

int32_t main(){
    fast_io;
    int n;
    cin >> n;
    int a[n + 1];
    int tot = 0;
    fo(i, 1, n) cin >> a[i], tot += a[i], cnt[a[i]]++;
    int q;
    cin >> q;
    while(q--){
    	int x,y;
    	cin >> x >> y;
    	int k = cnt[x];
    	tot -= k * x;
    	tot += k * y;
    	cnt[x] -= k;
    	cnt[y] += k;
    	show(tot);
    }
    return 0;
}

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

int ans = 1e9 + 7;
int N, A, B, C;
vector<int> l;

void dfs(int a, int b, int c, int ac, int bc, int cc, int nc) {
    int index = ac + bc + cc + nc;
    if (index == N) {
      if(ac*bc*cc == 0) return;
      int tmpans = 0;
      tmpans += 10 * (ac - 1);
      tmpans += 10 * (bc - 1);
      tmpans += 10 * (cc - 1);
      tmpans += abs(A - a);
      tmpans += abs(B - b);
      tmpans += abs(C - c);
      ans = min(ans,tmpans);
    } else {
        dfs(a + l[index], b, c, ac + 1, bc, cc, nc);
        dfs(a, b + l[index], c, ac, bc + 1, cc, nc);
        dfs(a, b, c + l[index], ac, bc, cc + 1, nc);
        dfs(a, b, c, ac, bc, cc, nc + 1);
    }
}

int main() {
    cin >> N >> A >> B >> C;
    l.resize(N);
    rep(i, N) cin >> l[i];
    dfs(0, 0, 0, 0, 0, 0, 0);
    cout << ans << endl;
}

Measured memory_bytes: 256
object Main {
  class Solver(n: Int, s: String) {
    def nChar: (String, String) => Int = (x, y) => {
      val charCollection = 'a' to 'z' filter { (c) => (x.contains(c) && y.contains(c)) }
      charCollection.length
    }

    def solve: Int = {
      val li = for (i <- 1 to n-1) yield nChar(s.slice(0, i), s.slice(i, n))
      li.max
    }
  }
  
  def main(args: Array[String]): Unit = {
    val n = io.StdIn.readLine().toInt
    val s = io.StdIn.readLine()
    val solver = new Solver(n, s)
    println(solver.solve)
  }
}



Measured memory_bytes: 25540