akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;
int main()
{
	char S[6];
	
	for (int i = 1; i <= 6; i++)
		cin >> S[i];

	if (S[3] == S[4] && S[5] == S[6]) 

		cout << "Yes";
	
	else
		cout << "No";

		return 0;
}

Measured memory_bytes: 256
def abc122_b():
    s = input()
    acgt = ['A', 'C', 'G', 'T']

    check = [1 if s[i] in acgt else 0 for i in range(len(s))]

    result = 0
    for i in range(len(check)):
        for j in range(i, len(check)):
            if check[i : j + 1].count(0) == 0:
                if result < len(check[i:j + 1]):
                    result = len(check[i:j + 1])

    print(result)

if __name__ == '__main__':
    abc122_b()

Measured memory_bytes: 9108
ABC=list(map(int,input().split()))

ans,flag=0,True
cnt=[0]*3
while flag:
  ABC.sort()
  for i in range(3):
    if ABC[i]+2<=max(ABC):
      ABC[i]+=2
      ans+=1
    elif sum(cnt)==3:
      flag=False
    else:
      cnt[i]=1
if sum(ABC)==3*max(ABC):
  print(ans)
elif sum(ABC)==3*max(ABC)-1:
  print(ans+2)
elif sum(ABC)==3*max(ABC)-2:
  print(ans+1)

Measured memory_bytes: 3064
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readlines
from math import sqrt

def isSquare(n):
    m = int(sqrt(n))
    for x in range(m-2, m+2):
        if x**2 == n:
            return True

def getDistance(xi, xj, dimention):
    d = 0
    for i in range(dimention):
        d += (xi[i] - xj[i])**2
    return d

def main():
    lines = input()

    n, d = list(map(int, lines[0].split()))
    x = []
    for i, xi in enumerate(lines[1:]):
        x.append(list(map(int, xi.split())))

    cnt = 0

    for i, xi in enumerate(x):
        for j, xj in enumerate(x[i+1:]):
            dist = getDistance(xi, xj, d)
            if isSquare(dist):
                cnt += 1
    print(cnt)

main()

Measured memory_bytes: 9172
n=int(input())
list_a=[]
m1=0
m2=0
for i in range(n):
    a=int(input())
    list_a.append(a)
    if a>m1:
        m2=m1
        m1=a
    elif a>=m2:
        m2=a
for i in range(n):
    if list_a[i]==m1:
        print(m2)
    else:
        print(m1)

Measured memory_bytes: 12640
#include <stdio.h>
#include <string.h>

int
main(void)
{
	char line[80];
	char out[80] = { 0 };

	if (fgets(line, sizeof line, stdin)) {
		size_t len = strlen(line);
		if (line[len-1] == '\n') {
			line[len-1] = 0;
			len --;
		}
		
		for (size_t i = 0; i  < len; i++) {
			out[i] = line[len - 1 - i];
		}
			
		printf("%s\n",out);
	}

	return 0;
}

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


int main(){
    long long int N;
    long long int A,B;
    cin>>A>>B;
    int eight=(A*25+1)/2;
    int ten=B*10;
    int minn=max(eight,ten);
    while(true){
        int a=minn*8/100;
        int b=minn*10/100;
        if(a==A && b==B){
            cout<<minn<<endl;
            break;
        }else if(a!=A && b!=B){
            cout<<"-1"<<endl;
            break;
        }else{
            minn++;
        }
    }
}

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

template <class T>
inline void read(T &x) {
    x = 0;
    char c = getchar();
    bool f = 0;
    for (; !isdigit(c); c = getchar()) f ^= c == '-';
    for (; isdigit(c); c = getchar()) x = x * 10 + (c ^ 48);
    x = f ? -x : x;
}

template <class T>
inline void write(T x) {
    if (x < 0) {
        putchar('-');
        x = -x;
    }
    T y = 1;
	int len = 1;
    for (; y <= x / 10; y *= 10) ++len;
    for (; len; --len, x %= y, y /= 10) putchar(x / y + 48);
}

LL a, b, ans = 1;

int main() {
	read(a), read(b);
	LL p = __gcd(a, b);
	for (int i = 2; 1ll * i * i <= p; ++i)
		if (p % i == 0) {
			for (; p % i == 0; p /= i);
			++ans;
		}
	if (p > 1) ++ans;
	write(ans);
	putchar('\n');
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stack>
#include <string>
using namespace std;
typedef unsigned long long ULL;
int main()
{
    stack<int> st;
    string s;
    int tmp=0,tmp2=0;
    while(cin >> s)
    {
        if(s == "+") 
        {
            tmp = st.top();
            st.pop();
            tmp2 = st.top();
            st.pop();
            st.push(tmp2 + tmp);
        }
        else if(s == "-")
        {
            tmp = st.top();
            st.pop();
            tmp2 = st.top();
            st.pop();
            st.push(tmp2 - tmp);
        }
        else if(s == "*")
        {
            tmp = st.top();
            st.pop();
            tmp2 = st.top();
            st.pop();
            st.push(tmp2 * tmp);
        }
        else
        {
            st.push(stoi(s));
        }
    }
        cout << st.top() << endl;
    return 0;   
}

Measured memory_bytes: 1204
//
// Created by 伊東麻沙美 on 2019/10/22.
//

#include<iostream>
#include<algorithm>
using namespace std;


int main(){

    int r;
    cin>>r;

    cout<<3*r*r<<endl;

    //cin>>a>>b>>x;
    //scanf("%d%s%d",&i,&x,&j);


       // printf("%d",i+j);
       //cout<<i+j<<endl;

    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<ll, ll>P;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
void SAY(bool YES){cout<<(YES?"YES":"NO")<<endl;};
void Say(bool Yes){cout<<(Yes?"Yes":"No")<<endl;};

const ll MOD = 1000000007;

int main(){

    ll r, g, b;
    cin >> r >> g >> b;
    SAY((r * 100 + g * 10 + b) % 4 == 0);

    return 0;
}

Measured memory_bytes: 256
// clang-format off
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979;
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
bool odd(const int &n) { return n & 1; }
bool even(const int &n) { return ~n & 1; }
template<typename T> int len(const T &v) { return v.size(); }
template<typename T = int> T in() { T x; cin >> x; return x; }
template<typename T = int> T in(T &&x) { T z(forward<T>(x)); cin >> z; return z; }
template<typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &x : v) is >> x; return is; }
template<typename A, typename B> istream &operator>>(istream &is, pair<A, B> &p) { return is >> p.first >> p.second; }
template<typename T> ostream &operator<<(ostream &os, const vector<vector<T>> &v) { int n = v.size(); rep(i, n) os << v[i] << (i == n - 1 ? "" : "\n"); return os; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &v) { int n = v.size(); rep(i, n) os << v[i] << (i == n - 1 ? "" : " "); return os; }
template<typename A, typename B> ostream &operator<<(ostream &os, const pair<A, B> &p) { return os << p.first << ' ' << p.second; }
template<typename Head, typename Value> auto vectors(const Head &head, const Value &v) { return vector<Value>(head, v); }
template<typename Head, typename... Tail> auto vectors(Head x, Tail... tail) { auto inner = vectors(tail...); return vector<decltype(inner)>(x, inner); }
// clang-format on

main() {
  int n, m;
  cin >> n >> m;
  int ans = m;
  rep(i, n) {
    int a, b;
    cin >> a >> b;
    m += a - b;
    cmax(ans, m);
    if (m < 0) {
      cout << 0 << endl;
      return 0;
    }
  }
  cout << ans << endl;
}



Measured memory_bytes: 3080
n, m = list(map(int, input().split()))
a = []
b = []
for i in range(n):
    a.append(input())
for i in range(m):
    b.append(input())
ax = len(a[0])
ay = len(a)
bx = len(b[0])
by = len(b)
ans = False
for i in range(ax - bx + 1):
    for j in range(ay - by + 1):
        flag = True
        for x in range(bx):
            if not flag:
                break
            nx = x + i
            for y in range(by):
                ny = y + j
                if a[nx][ny] != b[x][y]:
                    flag = False
                    break
        if flag:
            ans = True
if ans:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define SIZE 200005
#define INF 1000000005LL
#define MOD 1000000007
using namespace std;
typedef long long int ll;
typedef pair <int,int> P;
int main(){
    ll n;
    cin >> n;
    stack<char> name;
    int check = 1;
    ll i = 1;
    n--;
    while(check){
        if(n-pow(26,i)<0){
            check = 0;
        }else{
            n-=pow(26,i);
        }
        i++;
        
    }
    //cout<<n<<endl;
    rep(k,0,i-1){
        ll a = n%26;
        name.push(a+'a');
        n/=26;
    }

    while(!name.empty()){
        cout<<name.top();
        name.pop();
    }
    cout<<endl;

  return 0;
}

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

int main() {
    int n;
    vector<int> H(100005);
    cin >> n;
    H[0] = 0;
    for (int i = 1; i <= n; i++) {
        cin >> H[i];
    }

    if (n == 1) {
        cout << "Yes" << endl;
        return 0;
    }

    bool can_modify = true;
    for (int i = n - 1; i >= 1; i--) {
        if (H[i] > H[i + 1]) {
            H[i]--;
            if (H[i] > H[i + 1]) {
                can_modify = false;
                break;
            }
        }
    }

    if (can_modify == true) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <cassert>
#include <cstdarg>
#include <sys/time.h>
#include <fstream>
//#include "cout.h"

using namespace std;

#define SZ(x) ((int)x.size())
#define MSET(x,a) memset(x, a, (int)sizeof(x))
#define PB push_back
#define VI vector < int >
#define PII pair < int, int >
#define LL long long
#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(), (v).end()
#define FIT(it,v) for (__typeof((v).begin()) it = (v).begin(); it != (v).end(); it++)
#define OUT(A) cout << #A << " = "<< (A) << endl
#define OUT2(A, B) cout << "(" << #A << ", " << #B << ") = (" << (A) << ", "<< (B) << ")" << endl
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }

#define present(c, e) ((c).find((e)) != (c).end())
#define cpresent(c, e) (find(ALL(c), (e)) != (c).end())



void init() {

}

void input() {

}

void solve() {
  int n;
  string a, b, c;
  cin >> n >> a >> b >> c;
  int res = 0;
  REP(i, n) {
    set<char> s;
    s.insert(a[i]);
    s.insert(b[i]);
    s.insert(c[i]);
    res += SZ(s) - 1;
  }
  cout << res << endl;
}

int main() {
	init();
	input();
	solve();
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_poizcy.hpp>
typedef long long   ll;
#define pb                push_back
#define mp                make_pair
#define all(a)            (a).begin(), (a).end()
#define clr(a,h)          memset(a, (h), sizeof(a))
#define mem(a,h)          memset(a, (h), sizeof(a))
#define fi first
#define se second
#define por(a,b) (((a%MOD) * (b%MOD))%MOD)
#define forg(i, b, e, c)    for (ll i = (ll)b; i < (ll)e; i+=c)
#define forr(i, b, e)    for (ll i = b; i < e; i++)
 
 
using namespace std;
//using namespace __gnu_pbds;
typedef double lldb;
typedef pair<ll, ll>  ii;
typedef pair<ll, ii>  iii;
typedef vector<ll>     vi;
typedef vector<vi>     vvi;
typedef vector<ii>      vii;
typedef vector<ll>      vll;
//typedef tree<ii,null_type,less<ii>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
const ll INF = 1e9;
const double PI = acos(-1);
#define offset 
const ll MOD= 1e9+7;
#define initseg ll new_nodo=(nodo*2),mid=(iz+der)/2;
 
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define tam 1003455
ll n,k;
ll go[tam],vis[tam];
deque<ll> cola,camino;
void dfs(ll u)
{
    cola.push_back(u);
    vis[u]=1;
    ll v=go[u];
    if (vis[v]==1)
    {
        camino=cola;
        while(cola.front()!=v)
            cola.pop_front();
    }
    else
        dfs(v);
}
int  main()
{
    ios::sync_with_stdio(false);cin.tie(0);
    cin>>n>>k;
    ll der;
    forr(i,0,n)
    {
        cin>>der;
        go[i+1]=der;
    }    
    dfs(1);
    ll cnt=0;der=camino.front();
    while(k>0)
    {
        
        if (der==cola.front())
            break;
        der=camino[++cnt];
        k--;
    }
    /*cout<<"mira "<<der<<' '<<k<<endl;
    for(auto v:camino)
        cout<<v<<' ';
    cout<<endl;
    for(auto v:cola)
        cout<<v<<' ';
    cout<<endl;*/
    if (k>0)
    {
        k%=(ll)cola.size();
        cout<<cola[k]<<endl;
    }
    else
        cout<<der<<endl;
}
// PLUS ULTRA!!

Measured memory_bytes: 9780
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <cstdio>
#include <numeric>
#include <utility>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <stack>
#include <functional>
#include <ctime>
#include <queue>
#include <string>
#include <map>
#include <utility>
#include <sstream>
#include <cmath>
#define MAX_U   10
#define MIN_U   0
#define rep(i,n) for(int i=0;i<n;i++)
#define pb push_back
#define form(i,a,b) for(int i=(a);i<(b);i++)
#define sz(x) ((int)(x).size())
#define CLR(a) memset((a), 0 ,sizeof(a))
using namespace std;
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<char> vc;
typedef vector<string> vs;
typedef queue<int> qi;
const int INF=numeric_limits<int>::infinity();
void printa(){cout<<"\n";}
template<class T, class... A>void printa(const T&first,const A&... rest){cout<<first;printa(rest...);}
template<class... A>void printa(const A&... rest){printa(rest...);}
void prints(){cout<<" ";}
template<class T, class... A>void prints(const T&first,const A&... rest){cout<<first;prints(rest...);}
template<class... A>void prints(const A&... rest){prints(rest...);}
int factorial(int x){int f=1;for(int i=1;i<x+1;i++)f=f*i;return f;}
int sigma(int x){int s;for(int i=1;i<x+1;i++)s=s+i;return s;}
int middle(int x){if(x%2==0)return x/2;else return x/2+1;}
double heron(int a,int b,int c){double s;s=(a+b+c)/2;return sqrt(s*(s-a)*(s-b)*(s-c));}
double trapezium(int a,int b,int h){return (a+b)*h/2;}
double triangle(int a,int h){return a*h/2;}
void sorm(vector<int> vec){sort(vec.begin(),vec.end());}
void sorg(vector<int> vec){sort(vec.begin(),vec.end(),greater<int>());}
int cmp( const void *p, const void *q ) {if( *(double*)p > *(double*)q ) return 1;if( *(double*)p < *(double*)q ) return -1;return 0;}

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    double a,b,c,d;
    //string st;
    //vi ad,bd,cd,dd;
    //vs as,bs,cs,ds;
    cin>>a>>b>>c>>d;
    if(a+b>c+d)printa("Left");
    else if(a+b<c+d)printa("Right");
    else if(a+b==c+d)printa("Balanced");
    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
int main(int argc, char const *argv[]) {
    int N; std::cin >> N;
    int partition[9]={400,800,1200,1600,2000,2400,2800,3200,100000};
    int counts[9]={0,0,0,0,0,0,0,0,0};
    for (size_t i = 0; i < N; i++) {
        int rate;
        std::cin >> rate;
        for (size_t j = 0; j < 9; j++) {
            if (rate<partition[j]) {
                counts[j]++;
                break;
            }
        }
    }

    int min=0;
    int max;
    for (size_t i = 0; i < 8; i++) {
        if (counts[i]!=0) {
            min++;
        }
    }

    if(min==0){
        min=1;
        max=counts[8];
        std::cout << min << " "<< max << '\n';
    }else{
        max=min+counts[8];
        std::cout << min << " "<< max <<'\n';
    }
    return 0;
}


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

int pdx[12] = {2,2,2,1,0,-1,-2,-2,-2,-1,0,1};
int pdy[12] = {-1,0,1,2,2,2,1,0,-1,-2,-2,-2};
int sdx[9] = {0,1,0,-1,0,1,1,-1,-1};
int sdy[9] = {0,0,1,0,-1,-1,1,1,-1};
int N;
pair<int,int> sp[10];

bool dfs(int x, int y, int d) {
	if (d == N) return true;
	for (int i=0; i<12; i++) {
		int px=x+pdx[i], py=y+pdy[i];
		if (px<0||py<0||px>9||py>9) continue;
		for (int j=0; j<9; j++) {
			int sx=sp[d].first+sdx[j], sy=sp[d].second+sdy[j];
			if (sx<0||sy<0||sx>9||sy>9) continue;
			if (px==sx&&py==sy)
				if (dfs(px,py,d+1)) return true;
		}
	}
	return false;
}

int main() {
	int x, y;
	while (cin >> x >> y, x||y) {
		cin >> N;
		for (int i=0; i<N; i++) {
			int a, b;
			cin >> a >> b;
			sp[i] = make_pair(a,b);
		}

		cout << (dfs(x,y,0) ? "OK" : "NA") << endl;
	}
	return 0;
}

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

using namespace std;
using ll = long long;

const int N = 202;

const int LOG_MAX = 60;

struct Gauss {
    array<ll, LOG_MAX> vet;
    int size;
    Gauss() : size(0) {
		fill(vet.begin(), vet.end(), 0);
	}
    bool add(ll val) {
        for(int i = 0; i < LOG_MAX; i++) if(val & (1LL << i)) {
            if(vet[i] == 0) {
                vet[i] = val;
                size++;
                return true;
            }
            val ^= vet[i];
        }
        return false;
    }
    bool is_in(ll val) {
        for(int i = 0; i < LOG_MAX; i++) if(val & (1LL << i)) {
            if(vet[i] == 0) {
                return false;
            }
            val ^= vet[i];
        }
        return true;
    }
};

int n;
ll a[N];
char s[N];

int solve() {
	if(s[n - 1] == '1') return 1;
	Gauss p[2];
	for(int i = n - 1; i >= 0; i--) {
		int j = i;
		while(j - 1 >= 0 and s[j - 1] == s[i]) j--;
		for(int k = i; k >= j; k--) {
			p[int(s[i] - '0')].add(a[k]);
		}
		if(s[i] == '1') {
			for(ll v : p[1].vet) if(v) {
				if(!p[0].is_in(v)) {
					return 1;
				}
			}
		}
		i = j;
	}
	return 0;
}

int main() {
	int t;
	scanf("%d", &t);
	while(t--) {
		scanf("%d", &n);
		for(int i = 0; i < n; i++) scanf("%lld", a + i);
		scanf(" %s", s);
		printf("%d\n", solve());
	}
}


Measured memory_bytes: 3816
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("O3")
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define EPS (1e-9)
#define INF (1e17)
#define PI (acos(-1))
//const double PI = acos(-1);
//const double EPS = 1e-15;
//long long INF=(long long)1E17;
#define i_7 (long long)(1e9+7)
//#define i_7 998'244'353
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
long long po(long a, long b){
    if(b==0){
        return 1;
    }
    
    long long z = po(a,b/2);
    z = mod(z*z);
    if(b%2!=0){
        z = mod(a*z);
    }
    return z;
}
 
bool prime_(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=std::sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}
 
long long gcd_(long long a, long long b){
  if(a<b){
    std::swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd_(b,a%b);
  }
}
 
long long lcm_(long long x, long long y){
  return (x/gcd_(x,y))*y;
}
 
//using namespace std;
//using namespace boost::multiprecision;
//using namespace __gnu_pbds;

int main(){
  using namespace std;
  int s;
  cin>>s;
  vector<long long> dp(s + 1, 0);
  dp[0] = 1;
  REP(i, s + 1){
    for(int x = 3; x <= i; x++){
      dp[i] += dp[i - x];
      dp[i] = mod(dp[i]);
    }
  }
  long long ans = dp[s];
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3624
import java.util.*;
public class Main {
    public static void main(String[] args){
      // 入力
      Scanner sc = new Scanner(System.in);
      String S = sc.next();
      
      // 回文判定
      int N = S.length();
      String frontStr = S.substring(0, (N-1)/2);
      String backStr = S.substring((N+1)/2, N);
      boolean judge1 = isPalindrome(S);
      boolean judge2 = isPalindrome(frontStr);
      boolean judge3 = isPalindrome(backStr);
      
      String result = "No";
      if(judge1 && judge2 && judge3){
        result = "Yes";
      }
      
      // 出力
      System.out.println(result);
    }
    
    // 文字列が回文であるか判定する関数
    public static boolean isPalindrome(String str){
      int length = str.length();
      boolean result = true;
      for(int i = 0; i < length / 2; i++){
        int index1 = i;
        int index2 = length - i - 1;
        char c1 = str.charAt(index1);
        char c2 = str.charAt(index2);
        if(c1 != c2){
          result = false;
          break;
        }
      }
      
      return result;
    }
    
    // 文字列のx文字目を取得する関数
    public static String strAt(String str, int x){
      return String.valueOf(str.charAt(x));
    }
    

}

Measured memory_bytes: 22612
# 最大の友達集団の人の数ぶんだけグループに分ける必要がある。
# union-findを使用する必要がある。

class UnionFind:
    # この時点でそれぞれのノードは自分を親としている
    # 初期化時に問題が0の頂点を認めるかに注意すること
    def __init__(self, n):
        self.N = n
        self.parent = [i for i in range(n)]
        self.rank = [0 for _ in range(n)]

    # xの根を返す関数
    def root(self, x):
        visited_nodes = []
        while True:
            p = self.parent[x]
            if p == x:
                # 縮約
                for node in visited_nodes:
                    self.parent[node] = x
                return x
            else:
                visited_nodes.append(x)
                x = p

    # 木の結合を行う。親の配下に入る
    def unite(self, x, y):
        if not self.root(x) == self.root(y):
            if self.rank[x] > self.rank[y]:
                self.parent[self.root(y)] = self.root(x)
            else:
                self.parent[self.root(x)] = self.root(y)
                if self.rank[x] == self.rank[y]:
                    self.rank[self.root(y)] += 1

    def ifSame(self, x, y):
        return self.root(x) == self.root(y)

    # 木の根に到達すまでにたどるノードの配列を返す
    def printDebugInfo(self):
        print([self.root(i) for i in range(self.N)])


N, M = map(int, input().split())
tree = UnionFind(N)
for i in range(M):
    A, B = map(int, input().split())
    tree.unite(A-1, B-1)


bag = {}
for i in range(N):
    boss = tree.root(i)
    if not boss in bag.keys():
        bag[boss] = 1
    else:
        bag[boss] += 1

print(max(bag.values()))


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

int main() {
	int a, b, c, k;
	cin >> a >> b >> c >> k;
	if (a >= b && a >= c) {
		for (int i = 0; i < k; i++) a = 2*a;
	}
	else if (b >= a && b >= c) {
		for (int i = 0; i < k; i++)b = 2 * b;
	}
	else {
		for (int i = 0; i < k; i++)c = 2 * c;
	}
	cout << a + b + c << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define show(x) {for(auto i: x){cout << i << " ";} cout << endl;}
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    rep(i, N) cin >> A[i];
    int ma = 0;
    ll ans = 0;
    for (int a : A) {
        if (a < ma) {
            ans += ma - a;
        }
        ma = max(ma, a);
    }
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 3956
/*
 
Coded and Decoded by : Yash Kapoor
 
*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

//s.find_by_order(index);
//s.order_of_key(value);
 
#define ll          long long
#define ld          long double
#define pb          push_back
#define pf          push_front
#define mp          make_pair
#define pll         pair<ll,ll>
#define vl          vector<ll>
#define sl          set<ll> 
#define vll         vector<pll>
#define ml          map<ll,ll>
#define mll         map<pll,ll>
#define all(a)      a.begin(),a.end()
#define x           first
#define y           second
#define sz(x)       (ll)x.size()
#define dl          '\n'
#define why         (ll)1000000007
//#define why         (ll)998244353
#define lp(i,a,b)   for(ll i=a;i<b;++i)
#define lpr(i,a,b)  for(ll i=a;i>=b;i--)
#define lpd(i,x)    for(auto i:x)
#define ios         ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

typedef tree<ll,null_type,less<ll>,rb_tree_tag,
tree_order_statistics_node_update> indexed_set;

ll inf = 1e18;
ld pi = 3.141592653589;
ll mod = why;
ll fast_power(ll base,ll power,ll mod){
    ll result=1;
    while(power){
        if(power%2)
        result=(result*base)%mod;
        base=(base*base)%mod;
        power/=2;
    }
    return result;
}
 
ll inverse(ll base,ll mod){
    return fast_power(base,mod-2,mod);
}

void solve() {
    ll n; cin>>n;
    vl a(n); lp(i,0,n) cin>>a[i];
    sort(all(a),greater<ll>());
    ll ans = a[0];
    lp(i,1,(n-1)/2+(n-1)%2){
        ans+=2*a[i];
    }
    if((n-1)%2==0){
        ans+=a[(n+1)/2-1];
    }
    cout<<ans;
}
int main(){
    ios
    ll t=1; 
    //cin>>t;
    while(t--){
        solve();
    }
}  

Measured memory_bytes: 4788
#include<bits/stdc++.h>
using namespace std;
map<int,bool> M;
int main()
{
  int N,X;
  cin>>X>>N;
  while(N--)
  {
    int Y;
    cin>>Y;
    M[Y]=true;
  }
  for(int i=0;;i++)
  {
    if(!M[X-i])
    {
      cout<<X-i<<endl;
      return 0;
    }
    if(!M[X+i])
    {
      cout<<X+i<<endl;
      return 0;
    }
  }
  return 0;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
int w, h, n;
const int N = 800000;
int xi[N], yi[N], ord[N];
int ans;
int comp(int a, int b) {return xi[a] < xi[b];}
int tagL[N], tagR[N], vaL[N], vaR[N], val[N], mxL[N], mxR[N], mnL[N], mnR[N];
int lc[N], rc[N], lb[N], rb[N], tot;
void upd(int t)
{
    vaL[t] = max(vaL[lc[t]], vaL[rc[t]]);
    vaR[t] = max(vaR[lc[t]], vaR[rc[t]]);
    val[t] = max(val[lc[t]], val[rc[t]]);
    mnL[t] = min(mnL[lc[t]], mnL[rc[t]]);
    mnR[t] = min(mnR[lc[t]], mnR[rc[t]]);
    mxL[t] = max(mxL[lc[t]], mxL[rc[t]]);
    mxR[t] = max(mxR[lc[t]], mxR[rc[t]]);
}
void psdw(int t)
{
    if (~tagL[t])
    {
        vaL[lc[t]] = h - xi[ord[lb[lc[t]]]] - tagL[t];
        val[lc[t]] = vaR[lc[t]] - tagL[t];
        tagL[lc[t]] = mnL[lc[t]] = mxL[lc[t]] = tagL[t];
        vaL[rc[t]] = h - xi[ord[lb[rc[t]]]] - tagL[t];
        val[rc[t]] = vaR[rc[t]] - tagL[t];
        tagL[rc[t]] = mnL[rc[t]] = mxL[rc[t]] = tagL[t];
        tagL[t] = -1;
    }
    if (~tagR[t])
    {
        vaR[lc[t]] = h - xi[ord[lb[lc[t]]]] - tagR[t];
        val[lc[t]] = vaL[lc[t]] - tagR[t];
        tagR[lc[t]] = mnR[lc[t]] = mxR[lc[t]] = tagR[t];
        vaR[rc[t]] = h - xi[ord[lb[rc[t]]]] - tagR[t];
        val[rc[t]] = vaL[rc[t]] - tagR[t];
        tagR[rc[t]] = mnR[rc[t]] = mxR[rc[t]] = tagR[t];
        tagR[t] = -1;
    }
}
void modify_L(int t, int l, int r, int v)
{
    if (mnL[t] >= v) return;
    if (l <= lb[t] && rb[t] <= r && mxL[t] <= v)
    {
        vaL[t] = h - xi[ord[lb[t]]] - v;
        val[t] = vaR[t] - v;
        tagL[t] = mnL[t] = mxL[t] = v;
        return;
    }
    psdw(t);
    if (l <= rb[lc[t]]) modify_L(lc[t], l, r, v);
    if (r >= lb[rc[t]]) modify_L(rc[t], l, r, v);
    upd(t);
}
void modify_R(int t, int l, int r, int v)
{
    if (mnR[t] >= v) return;
    if (l <= lb[t] && rb[t] <= r && mxR[t] <= v)
    {
        vaR[t] = h - xi[ord[lb[t]]] - v;
        val[t] = vaL[t] - v;
        tagR[t] = mnR[t] = mxR[t] = v;
        return;
    }
    psdw(t);
    if (l <= rb[lc[t]]) modify_R(lc[t], l, r, v);
    if (r >= lb[rc[t]]) modify_R(rc[t], l, r, v);
    upd(t);
}
int build(int l, int r)
{
    int t = ++ tot;
    lb[t] = l; rb[t] = r;
    tagL[t] = tagR[t] = -1;
    mnL[t] = mxL[t] = mnR[t] = mxR[t] = 0;
    if (l != r)
    {
        lc[t] = build(l, (l + r) / 2);
        rc[t] = build((l + r) / 2 + 1, r);
        upd(t);
    }
    else
    {
        val[t] = vaL[t] = vaR[t] = h - xi[ord[l]];
    }
    return t;
}

void solve()
{
    for (int i = 1; i <= n; ++ i) ord[i] = i;
    sort(ord + 1, ord + n + 1, comp);
    tot = 0;
    build(0, n);
    for (int i = 1; i <= n; ++ i)
    {
        ans = max(ans, xi[ord[i]] + val[1]);
        if (yi[ord[i]] <= h / 2)
            modify_L(1, 0, i - 1, yi[ord[i]]);
        else
            modify_R(1, 0, i - 1, h - yi[ord[i]]);
    }
    ans = max(ans, w + val[1]);
}
int main()
{
    scanf("%d%d%d", &w, &h, &n);
    for (int i = 1; i <= n; ++ i)
        scanf("%d%d", &xi[i], &yi[i]);
    solve();
    swap(w, h);
    for (int i = 1; i <= n; ++ i)
        swap(xi[i], yi[i]);
    solve();
    printf("%d\n", ans * 2);
}


Measured memory_bytes: 49408
#include <iostream>
#include<stdio.h>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
using namespace std;

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

    int count=0;
    for(int i=0; i<M; i++){
        int j;
        cin>>j;
        if(j>M){
        count++;
        }
    }
    printf("%d\n", count);
}



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

using namespace std;

int main() {
  string s; cin >> s;
  if (s[0] == s[s.size()-1]) {
    if (s.size() % 2 == 0) {
      cout << "First" << endl;
    } else {
      cout << "Second" << endl;
    }
  } else {
    if (s.size() % 2 == 0) { 
      cout << "Second" << endl;
    } else {
      cout << "First" << endl;
    }
  }
  return 0;
}

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

int main() {

  int H, W;
  cin >> H >> W;
  vector<vector<char>> data(H, vector<char>(W));
  vector<bool>unspace(H, true);

  // 入力 (2重ループを用いる)
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      cin >> data.at(i).at(j);
    }
  }

  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {

      // 上からi番目、左からj番目
      if (data.at(i).at(j) == '#') {
        break;
      }
      else if(j==W-1) {
        unspace.at(i) = false;
        for (int k = 0; k < W; k++) 
           data.at(i).at(k)='o';
      }

    }
  }

  for (int j = 0; j < W; j++) {
    for (int i = 0; i < H; i++) {
       if (data.at(i).at(j) == '#') {
        break;
      }
      else if(i==H-1) {
        for (int m = 0; m < H; m++) 
           data.at(m).at(j)='o';
      }

    }
  }

  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (data.at(i).at(j) == 'o') {
        continue;
      }
      else {
        cout << data.at(i).at(j) ;
      }
    }
    if(unspace.at(i))
      cout << endl;
  }

}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<math.h>


int main(void){
	long long int N,i,ans(0);
	scanf("%lld",&N);
	long long int A[N+1],B[N];
	for(i = 0 ; i < N + 1 ; i ++){
		scanf("%lld",&A[i]);
	}
	for(i = 0 ; i < N ; i ++){
		scanf("%lld",&B[i]);
	}
	for(i = N - 1 ; i >= 0 ; i --){
		if(B[i] > A[i + 1]){
			ans += A[i + 1];
			B[i] = B[i] - A[i + 1];
			if(B[i] > A[i]){
				ans += A[i];
				A[i]= 0;
			} else {
				ans += B[i];
				A[i] = A[i] - B[i];
			}
		} else {
			ans += B[i];
		}
	}
	printf("%lld\n",ans);
	return 0;
}


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

using namespace std;

int main(){

    int N, K;
    string S;
    cin >> N >> S >> K;

    for(int i = 0; i < N; i++){
        if (S[i] != S[K-1]) {
            S[i] = '*';
        }
    }
    
    cout << S << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
using ll = long long;
#define pi 3.1415926


int main(){
    int n, m;
    cin >> n >> m;
    int x;
    x = n * (n - 1) / 2 + m * (m - 1) / 2;
    cout << x;
    
    
    
}

    

	


Measured memory_bytes: 256
n, k = map(int, input().split())
a = list(map(int, input().split()))
cnt = [0] * n

now = 0
cnt[now] += 1
root_to_loop = [now]
while cnt[now] != 2:
    now = a[now] - 1
    root_to_loop.append(now)
    cnt[now] += 1

loop = [now]
while cnt[now] != 3:
    now = a[now] - 1
    loop.append(now)
    cnt[now] += 1

if k <= len(root_to_loop):
    print(root_to_loop[k] + 1)
else:
    k = k - len(root_to_loop) + 1
    print(loop[k % (len(loop)-1)] + 1)

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

int main(){

  int x;
  cin>>x;

  int h = x / 3600;
  int m = (x / 60) % 60;
  int s = x % 60;
  cout<<h<<":"<<m<<":"<<s<<endl;

  return 0;
}


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

typedef long long ll;

ll x[55];
ll y[55];

int main() {
  int n;
  cin >> n;
  for(int i = 0; i < n; i++) cin >> x[i] >> y[i];


  int ans = n;

  for(int i = 0; i < n; i++) {
    for(int j = 0; j < n; j++) {
      if(i == j) continue;
      ll X = x[i] - x[j];
      ll Y = y[i] - y[j];
      int t = 0;
      for(int k = 0; k < n; k++) {
	for(int l = 0; l < n; l++) {
	  if(k == l) continue;
	  ll K = x[k] - x[l];
	  ll L = y[k] - y[l];
	  if(K == X && Y == L) t++;
	}
      }
      ans = min(ans,n - t);
    }
  }

  cout << ans << endl;
}


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

ll gcd(ll a, ll b){
	if(b == 0) return a;
    return gcd(b, a%b);
}

vector<pair<ll, int>> factorize(ll n){
	vector<pair<ll, int>> res;
  	for(ll i = 2; i*i <= n; i++){
    	if(n%i) continue;
      	res.emplace_back(i, 0);
      	while(n%i == 0){
        	n /= i;
          	res.back().second++;
        }
    }
  	if(n != 1) res.emplace_back(n, 1);
  	return res;
}

int main(){
	ll a, b;
  	cin >> a >> b;
  
	ll g = gcd(a, b);
  	auto f = factorize(g);
  	int ans = f.size() + 1;
  	cout << ans << endl;
}

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

using namespace std;


int main(){
 long n,m;
  cin >> n>> m;
  
  map<long,long> mp;
  
  long sum=0;
   mp[0]++;
  for(int i=0;i<n;i++){
   long a;
    cin >> a;
    sum+=a;
    mp[sum%m]++;
  }
  long res=0;
  for(auto v:mp) res+=v.second*(v.second-1)/2;
  
   cout << res << endl;
}  

Measured memory_bytes: 4224
fun main(args: Array<String>) {
    val c = mutableListOf<List<Int>>()
    for (i in 0 until 3) {
        c.add(readLine()!!.split(' ').map(String::toInt))
    }
    for ( i in 1 until 3) {
        for ( j in 1 until 3) {
            if (c[i][j] - c[i-1][j] != c[i][j-1] - c[i-1][j-1]) {
                println("No")
                return
            }
        }
    }
    for ( j in 1 until 3) {
        for ( i in 1 until 3) {
            if (c[i][j] - c[i][j-1] != c[i-1][j] - c[i-1][j-1]) {
                println("No")
                return
            }
        }
    }
    println("Yes")
}

Measured memory_bytes: 38384
#include <bits/stdc++.h>
using namespace std;
int A=0,B=0;
int n,a,b;

int check(char c,int r){
  if(c=='c')return 0;
  if(c=='a'&&a+b>A+B){
    A++;
    return 1;
  }
  if(c=='b'&&a+b>A+B&&b>B){
    B++;
    return 1;
  }
  return 0;
}


int main(){
  string str;
  cin>>n>>a>>b>>str;
  for(int i=0;i<str.size();i++)cout <<(check(str[i],i)? "Yes":"No")<<endl;
  

  return 0;
}


Measured memory_bytes: 896
#include <iostream>
using namespace std;
int city[50];
int main(void){
    // Your code here!
    int n, m;
    cin >> n >> m;
    for (int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        city[a - 1]++;
        city[b - 1]++;
    }
    for (int i = 0; i < n; i++) cout << city[i] << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<stack>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<vector>
#define MAXN 100007

using namespace std;
typedef long long ll;

char mayRed[MAXN];
int numOfBall[MAXN];

int main()
{
    int i,n,m;
    int x,y;
    scanf("%d%d",&n,&m);
    for(i=1;i<=n;i++){
        numOfBall[i]=1;
        mayRed[i]=0;
    }
    mayRed[1]=1;
    for(i=0;i<m;i++){
        scanf("%d%d",&x,&y);
        if(mayRed[x])
            mayRed[y]=1;
        numOfBall[y]++;
        numOfBall[x]--;
        if(numOfBall[x]==0)
            mayRed[x]=0;
    }
    int r=0;
    for(i=1;i<=n;i++)
        r+=mayRed[i];
    printf("%d\n",r);
    return 0;
}



Measured memory_bytes: 768
/* Coached by rainboy */
#include <stdio.h>

#define N 8

int aa[N][N], kk[N];

char used[N];

int cnt;

void branch(int n, int i, int k) {
	int h;

	used[i] = 1;
	if (k == n)
		cnt++;
	else
		for (h = 0; h < kk[i]; h++) {
			int j = aa[i][h];

			if (!used[j])
				branch(n, j, k + 1);
		}
	used[i] = 0;
}

int main() {
	int n, m;

	scanf("%d%d", &n, &m);
	while (m--) {
		int a, b;

		scanf("%d%d", &a, &b), a--, b--;
		aa[a][kk[a]++] = b;
		aa[b][kk[b]++] = a;
	}
	branch(n, 0, 1);
	printf("%d\n", cnt);
	return 0;
}


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

int main()
{
	int N, x = 0;
	cin >> N;
	for (int n = N; n != 0; n /= 10)
	{
		x += n % 10;
	}
	if (N % x == 0)
		cout << "Yes"s;
	else
		cout << "No"s;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p_ll;
 
template<class T>
void debug(T itr1, T itr2) { auto now = itr1; while(now<itr2) { cout << *now << " "; now++; } cout << endl; }
#define repr(i,from,to) for (int i=(int)from; i<(int)to; i++)
#define rep(i,N) repr(i,0,N)
#define per(i,N) for (int i=(int)N-1; i>=0; i--)
 
const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,30)-1;
  

int main() {
    int N;
    cin >> N;
    string S, T;
    cin >> S >> T;

    string res = "";
    rep(i,N) {
        res += S[i];
        res += T[i];
    }
    
    cout << res << endl;
    return 0;
}


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

#define ll long long
#define f first
#define s second
#define pb push_back
#define mp make_pair()
#define FOR(i, a, b) for (int i=a; i<(b); i++)
int main()
{
    ios_base::sync_with_stdio (false) ;
    cin.tie(0) ; cout.tie(0) ;
    ll n; cin>>n;
    cout<<(3*n*n);
}


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

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define rep2(i, a, b) for (ll i = (a); i < (b); i++)
#define chmax(x, v) do { x = max(x, v); } while (0)
#define chmin(x, v) do { x = min(x, v); } while (0)
typedef uint64_t ull;
typedef int64_t ll;
typedef std::pair<ll, ll> PLL;

using namespace std;

// {{{ Modint
// using mint = modint<1000000007>;
// mint x = 2;
// std::cout << x.a << std::endl;
template <std::int64_t M>
class modint {
 public:
  int64_t a;

  explicit constexpr modint(const int64_t x = 0) noexcept :
    a((x % M + M) % M) {}
  constexpr int64_t &value() noexcept { return a; }
  constexpr const int64_t &value() const noexcept { return a; }
  constexpr modint operator+(const modint rhs) const noexcept {
    return modint(*this) += rhs;
  }
  constexpr modint operator-(const modint rhs) const noexcept {
    return modint(*this) -= rhs;
  }
  constexpr modint operator*(const modint rhs) const noexcept {
    return modint(*this) *= rhs;
  }
  constexpr modint operator/(const modint rhs) const noexcept {
    return modint(*this) /= rhs;
  }
  constexpr modint &operator+=(const modint rhs) noexcept {
    a += rhs.a;
    if (a >= M) {
      a -= M;
    }
    return *this;
  }
  constexpr modint &operator-=(const modint rhs) noexcept {
    if (a < rhs.a) {
      a += M;
    }
    a -= rhs.a;
    return *this;
  }
  constexpr modint &operator*=(const modint rhs) noexcept {
    a = a * rhs.a % M;
    return *this;
  }
  constexpr modint &operator/=(modint rhs) noexcept {
    int64_t exp = M - 2;
    while (exp) {
      if (exp % 2) {
        *this *= rhs;
      }
      rhs *= rhs;
      exp /= 2;
    }
    return *this;
  }
  constexpr modint pow(ll t) const {
    if (!t) return modint(1);
    modint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
};
// }}}
using mint = modint<1000000007>;

ll N;
mint fact[300000];
mint dp[300000];
mint adp[300000];
ll size[300000];
vector<ll> edges[300000];

void dfs2(ll v, ll par = -1){
  if (par == -1) {
    adp[1] = dp[1];
  } else {
    ll sizeE = N - size[v];
    mint E = adp[par] * fact[N-1-size[v]] / fact[N-1] * fact[size[v]] / dp[v];
    adp[v] = dp[v] * fact[N-1] / fact[size[v]-1] * E / fact[sizeE];
  }
  for (auto u: edges[v]) {
    if (u == par)
      continue;
    dfs2(u, v);
  }
}

void dfs(ll v, ll par = -1) {
  if (edges[v].size() == 1 && edges[v][0] == par) {
    // 葉
    size[v] = 1;
    dp[v] = mint(1);
    return;
  }

  dp[v] = mint(1);
  size[v] = 1;
  for (auto u: edges[v]) {
    if (u == par)
      continue;
    dfs(u, v);
    size[v] += size[u];
    dp[v] *= dp[u];
    dp[v] /= fact[size[u]];
  }
  dp[v] *= fact[size[v]-1];
}

signed main() {
  fact[0] = fact[1] = mint(1);
  for (ll i=2; i<=300000; i++) {
    fact[i] = mint(i) * fact[i-1];
  }
  cin >> N;
  rep(i, N-1){
    ll a, b;
    cin >> a >> b;
    edges[a].push_back(b);
    edges[b].push_back(a);
  }
  dfs(1);
  dfs2(1);
  for (ll i=1; i<=N; i++) {
    // cout << i << " " << dp[i].value() << " " << adp[i].value() << " " << size[i] << endl;
    cout << adp[i].value() << endl;
  }
  return 0;
}


Measured memory_bytes: 26352
package main

import (
	"bufio"
	"fmt"
	"io"
	"log"
	"math"
	"os"
	"strconv"
)

func main() {
	n := readInt()
	ans := make([]int, n+1)
	maxn := int(math.Sqrt(float64(n)))
	for i := 1; i <= maxn; i++ {
		for j := 1; j <= maxn; j++ {
			for k := 1; k <= maxn; k++ {
				x := i*i + j*j + k*k + i*j + j*k + k*i
				if x <= n {
					ans[x]++
				}
			}
		}
	}
	for i := range ans[1:] {
		fmt.Println(ans[i+1])
	}
}

var (
	readString func() string
	readBytes  func() []byte
)

func init() {
	log.SetFlags(log.Lshortfile)
	readString, readBytes = newReadString(os.Stdin)
}

func newReadString(ior io.Reader) (func() string, func() []byte) {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	f1 := func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
	f2 := func() []byte {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Bytes()
	}
	return f1, f2
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 10, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readInt() int {
	return int(readInt64())
}

func readFloat64() float64 {
	f, err := strconv.ParseFloat(readString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func sum(a []int) int {
	var ret int
	for i := range a {
		ret += a[i]
	}
	return ret
}

func sumFloat64(a []float64) float64 {
	var ret float64
	for i := range a {
		ret += a[i]
	}
	return ret
}

func gcd(m, n int) int {
	for m%n != 0 {
		m, n = n, m%n
	}
	return n
}

func lcm(m, n int) int {
	return m / gcd(m, n) * n
}


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

int main()  
{  
    int a[101];
    for(int i=1;i<=5;i++)
    cin>>a[i];

    for(int i=1;i<=5;i++)
        if(a[i]==0)
            cout<<i;


    return 0;  
}  
  


Measured memory_bytes: 3576
#include<bits/stdc++.h>
using namespace std;
#define INF 1e9
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
const int MOD = 1000000007;

void solve() {
  int a, b;
  cin >> a >> b;
  if (a >= 13) cout << b;
  else if (a > 5) cout << b / 2;
  else cout << "0" << endl;
}

int main() {
  solve();
  return 0;
}

Measured memory_bytes: 3620
using System;
using System.Linq;
using System.Collections.Generic;

class Program
{
  /// <summary>
  ///   The main entry point for the application
  /// </summary>
  [STAThread]
  public static void Main(string[] args)
  {
    int n = int.Parse(Console.ReadLine());
    long[] a = new long[n];
    long[] b = new long[n];
    long[] c = new long[n];
    for (int i = 0; i < n; i ++)
    {
      string[] s = Console.ReadLine().Split(' ');
      a[i] = int.Parse(s[0]);
      b[i] = int.Parse(s[1]);
    }
    for (int i = 0; i < n; i ++)
    {
      c[i] = a[i] + b[i];
    }
    var ans = Enumerable.Range(0, n).Select(i => a[i] + b[i]).OrderByDescending(x => x).Where((value, index) => index % 2 == 0).Sum() - b.Sum();
    Console.WriteLine(ans);
  }
}


Measured memory_bytes: 22848
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	Scanner sc = new Scanner(System.in);

	void run() {
		int N = sc.nextInt();
		int W = sc.nextInt();
		int[] v = new int[N];
		int[] w = new int[N];
		for (int i = 0; i < N; i++) {
			v[i] = sc.nextInt();
			w[i] = sc.nextInt();
		}
		int[][] dp = new int[2][W + 1];
		for (int i = 0; i < N; i++) {
			for (int j = 0; j <= W; j++) {
				if (j - w[i] >= 0) {
					dp[(i + 1) & 1][j] = Math.max(dp[i & 1][j], dp[i & 1][j - w[i]] + v[i]);
				} else {
					dp[(i + 1) & 1][j] = dp[i & 1][j];
				}
			}
		}
		int max = 0;
		for (int i = 0; i <= W; i++) {
			max = Math.max(max, dp[N & 1][i]);
		}
		System.out.println(max);
	}

	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 27220
#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef long long LL;

int main() {
  string S, T; cin >> S >> T;
  int cnt = 0;
  for (int i = 0; i < S.size(); ++i) {
    if (S[i] != T[i]) ++cnt;
  }
  cout << cnt << endl;
}


Measured memory_bytes: 3916
def main():
    N = int(input())
    cnt = 0
    for _ in range(N):
        d1, d2 = map(int, input().split())
        if d1 == d2:
            cnt += 1
        else:
            cnt = 0
        if cnt >= 3:
            print("Yes")
            return
    print("No")


if __name__ == "__main__":
    main()


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

ll C[500];
ll S[500];
ll F[500];

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
#ifdef LOCAL
	std::ifstream in("in");
	std::cin.rdbuf(in.rdbuf());
#endif

	int n;
	cin >> n;
	for(int i = 0; i < n - 1; i++){
		cin >> C[i] >> S[i] >> F[i];
	}

	for(int i = 0; i < n; i++){
		ll t = 0;
		for(int j = i; j < n - 1; j++){
			t = max(t, S[j]);
			t = (t + F[j] - 1) / F[j] * F[j] + C[j];
		}
		cout << t << endl;
	}
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
typedef long long ll ;
#define rep(i, a, b) for (int i = a ; i <= b ; ++ i) 
const int N = 5e5 + 5 ;
const double eps = 1e-12 ;
using namespace std ;

int n, L ;
struct poi {
	long double x, y ;
} st[N], delta ;

long double cross(poi p0, poi p1, poi p2) {
	return (p1.x - p0.x) * (p2.y - p0.y) - (p2.x - p0.x) * (p1.y - p0.y) ;
}

int main() {
	scanf("%d%d", &n, &L) ;
	int he = 1, ta = 1 ; poi u = {0.0, 0.0} ; st[1] = u ;
	rep(i, 1, n) {
		scanf("%Lf%Lf", &u.y, &u.x), u.y *= u.x ;
		delta.x += u.x, delta.y += u.y ;
		u.x = - delta.x, u.y = - delta.y ;
		for ( ; he < ta && st[he + 1].x + delta.x > L ; ++ he) ;
		if (he == ta) st[he + 1] = u ; 
		st[he].y = st[he + 1].y + (st[he].y - st[he + 1].y) * (1.0 * L - st[he + 1].x - delta.x) / (st[he].x - st[he + 1].x) ;
		st[he].x = 1.0 * L - delta.x ;
		for ( ; he < ta && cross(u, st[ta], st[ta - 1]) > 0 ; -- ta) ;
		st[++ ta] = u ;
		printf("%.10Lf\n", (st[he].y + delta.y) / L) ;
	}
	return 0 ; 
}

Measured memory_bytes: 26112
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include<algorithm>
#include<string>
#include <map>
#include <queue>
#include <stack>
#include<set>
#include<math.h>

#define DIV 1000000007
using namespace std;
using ll = long long;

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

    int N = s.size();
    int t = 1e6;
    int temp = 1e6;
    for (int i = 1; i < N; i++) {
        if (s[i-1] != s[i]) {
           temp = max(i, N - i);
        }
        t = min(t, temp);
    }
    
    if (t == 0 || t == 1e6)
        cout << N << endl;
    else
        cout << t << endl;
}

Measured memory_bytes: 512