akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define all(vec) vec.begin(), vec.end()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
template <class T>
using V = vector<T>;
template <class T>
inline void chmin(T &a, const T &b) { a = min(a, b); }
template <class T>
inline void chmax(T &a, const T &b) { a = max(a, b); }
template <class T>
inline bool kbit(const T &x, const int &k) { return ((x >> k) & 1LL); }
inline int popcount(const int &n) { return __builtin_popcount(n); }
inline ll popcountll(const ll &n) { return __builtin_popcountll(n); }
template <class T>
void zip(V<T> &v) {
    sort(all(v));
    v.erase(unique(all(v)), v.end());
}
void dump() {
    cerr << '\n';
}
template <class Head, class... Tail>
void dump(Head &&head, Tail &&... tail) {
    cerr << head << (sizeof...(Tail) == 0 ? " " : ", ");
    dump(std::move(tail)...);
}
template <class T>
void print(const vector<T> &v) {
    for (int i = 0; i < v.size(); i++) cout << v[i] << (i + 1 == v.size() ? '\n' : ' ');
}
template <class T>
void read(vector<T> &v) {
    for (int i = 0; i < v.size(); i++) cin >> v[i];
}
constexpr char sp = ' ', newl = '\n';
constexpr int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
constexpr ll INF = (1LL << 30) - 1LL;
constexpr ll MOD = 1e9 + 7;
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    V<V<int>> G(n);
    for (int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        --a;
        --b;
        G[a].eb(b);
        G[b].eb(a);
    }
    V<int> vis(n), pre(n);
    queue<int> q;
    q.emplace(0);
    vis[0] = 1;
    while (!q.empty()) {
        int v = q.front();
        q.pop();
        for (auto &e : G[v]) {
            if (vis[e]) continue;
            vis[e] = 1;
            pre[e] = v;
            q.emplace(e);
        }
    }
    cout << "Yes" << newl;
    for (int i = 1; i < n; i++) {
        cout << pre[i] + 1 << newl;
    }
}

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

using namespace std;

int main() {
  string str;
  cin >> str;
  for (auto itr = str.begin(); itr != str.end();) {
    if (*itr == '/')
      itr = str.erase(itr);
    else
      ++itr;
  }
  if (stoi(str) <= 20190430)
    cout << "Heisei" << endl;
  else
    cout << "TBD" << endl;
}

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

int main(){
    int N;
    cin >> N;
    int hai[200001];
    int cnt = 0;
    int an = 0;
    for(int i = 0;i < N;i++){
        cin >> hai[i];
        cnt++;
        if(hai[i] == 1) an++;
    }
    int sai = hai[cnt];
    int ans = 0;
    int unti = 1;
    for(int i = 0;i < N;i++){
        if(hai[i] != unti){
            ans++;
        }
        else unti++;
    }
    if(sai == 1){
        cout << '0';
    }
    else if(an == 0){
        cout << "-1";
    }
    else cout << ans;

    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops") 
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
#define int long long
#define fr(i,a,b) for(int i = a ; i <= b ; ++i)
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) begin(x), end(x)
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()
#define pb push_back
#define fst first
#define snd second
using namespace __gnu_pbds;
using ordered_set =
 tree<int, null_type,less<int>,
 rb_tree_tag,tree_order_statistics_node_update>;
//find_by_order(k):returns iterator to kth element starting from 0
//order_of_key(k):returns count of elements strictly smaller than k
typedef long long ll;typedef pair<int, int> pii;
typedef vector<int> vi;typedef long double ld;
template<class T>
using min_heap = priority_queue<T,vector<T>,greater<T>>; 
template<typename T> T gcd(T a, T b){return(b?__gcd(a,b):a);}
template<typename T> T lcm(T a, T b){return(a*(b/gcd(a,b)));}
template<typename T> 
void remdup(vector<T>& v) {
	sort(all(v)); v.erase(unique(all(v)), v.end());
}
template<typename T> void re(vector<T> &v) {trav(i,v) cin >> i;}
void unsyncIO() { ios_base::sync_with_stdio(0); cin.tie(0); }
#ifdef np
#include "C:\Users\navodit\Desktop\mycodes\pr.h"
#else
#define trace(...)
#endif

#define MOD 1000000007  





void solve(){
	string s; 
	cin >> s ; 
	sort(all(s));
	if(s[0]==s[1] and s[2]==s[3] and s[1]!=s[2]) cout << "Yes\n";
	else cout << "No\n";
}

signed main() {
	unsyncIO();
	int tt =1 ;
	// cin >> tt;
	rep(i,0,tt) solve();













#ifdef np
	cout <<endl<<endl<< "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
	return 0;
}


Measured memory_bytes: 3644
n, m = map(int, input().split())
goods = [tuple(map(int, input().split())) for _ in range(n)]
s = sum(list(map(lambda x: x[1], goods)))
dp = [[10 ** 15 for _ in range(s+1)] for _ in range(n+1)]
dp[0][0] = 0
for i in range(n):
    for j in range(s+1):
        w, v = goods[i]
        if j >= v:
            dp[i+1][j] = min(dp[i][j], dp[i][j - v] + w)
        else: dp[i+1][j] = dp[i][j]
maxv = 0
for j in range(s+1):
    if dp[n][j] <= m:
        maxv = j
print(maxv)

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

int main() {
    int d; cin >> d;
    switch (d) {
        case 22:
            cout << "Christmas Eve Eve Eve";
            break;
        case 23:
            cout << "Christmas Eve Eve";
            break;
        case 24:
            cout << "Christmas Eve";
            break;
        case 25:
            cout << "Christmas";
    }
    cout << '\n';
    
    return 0;
}


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

using namespace std;

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define EPS 1e-14

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

#define fi first
#define se second

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

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

typedef long long ll;

void solve(){
	int H,W;
	int a[110][110];
	map<char,int> mp;
	cin >> H >> W;
	rep(i,H){
		string s;
		cin >> s;
		rep(j,W){
			mp[s[j]] += 1;
		}
	}
	int val1 = 0;
	int val2 = 0;
	for(auto itr = mp.begin();itr != mp.end(); ++ itr){
		// cout << itr->first << itr->second << endl;
		if(itr->second %4 != 0){
			val1+=(itr->second%4)/2;
			val2+=itr->second%2;
		}
	}
	// cout <<val1<<":"<<val2<< endl;
		
	if(H%2==0 && W%2 == 0){
		if(val1==0&&val2==0){
			cout << "Yes" << endl;
		}else{
			cout << "No" << endl;	
		}
		return;
	}else if(W%2==0){
		if(val1 <= W/2 && val2==0){
			cout << "Yes" << endl;
		}else{
			cout << "No" << endl;
		}
		return;
	}else if(H%2==0){
		if(val1 <= H/2 && val2==0){
			cout << "Yes" << endl;
		}else{
			cout << "No" << endl;
		}
		return;
	}else{
		if(val1 <= H/2+W/2 && val2 == 1){
			cout << "Yes" << endl;
		}else{
			cout << "No" << endl;
		}
		return;
	}
}

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

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<iomanip>
#include <string>
#include <math.h>
using namespace std;

int main(){
    long long int n,k,ans=0,s=0,b=0;
    cin>>n;
    vector<long long int>a(1000000);
    for(long long int i=0;i<n;i++){
        cin>>a[i];
        a[i]-=(i+1);
    }
    sort(a.begin(),a.begin()+n);
    if(n%2==0){
        b=(a[n/2]+a[(n-1)/2])/2;
    }
    else{
        b=a[n/2];
    }
    for(long long int i=0;i<n;i++){
        ans+=abs(a[i]-b);
    }
    cout<<ans<<endl;
    
    return 0;
}


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

using namespace std;
using ll = long long;

int main() {
	ll n;
	cin >> n;
	vector<int> a(3 * n);
	for (int i = 0; i < 3 * n; i++) {
		cin >> a[i];
	}
	ll ans = 0;
	sort(a.begin(), a.end());
	for (int i = n; i < 3 * n; i+=2) {
		ans += a[i];

	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1408
import java.util.Scanner;

public class Main {
	static Scanner s = new Scanner(System.in);

	public static void main(String[] args) {
		String in=s.next();
		int depth=0;
		int count=0;
		for(int i=0;i<in.length();i++) {
			switch (in.charAt(i)) {
			case'T':
				if(depth==0) count++;
				else depth--;
				break;
			case'S':
				depth++;
				break;
			}
		}
		System.out.println(count*2);
	}
}


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

int main() {
    int a, b, c, k;
    cin >> a >> b >> c >> k;

    int sum = 0;
    if (k > a) {
        sum += a;
    } else {
        sum += k;
    }
    k -= a;
    if (k > 0) {
        k -= b;
        if (k > 0) {
            if (k > c) {
                sum -= c;
            } else {
                sum -= k;
            }
            k -= c;
        }
    }
    cout << sum << endl;
}

Measured memory_bytes: 3596
#include<bits/stdc++.h>
using namespace std;
#define int long long
struct StarrySky{
  int n;
  const int def=0;
  vector<int> datm,data;
  StarrySky(){}
  StarrySky(int n_){init(n_);}
  void init(int n_){
    n=1;
    while(n<n_) n*=2;
    datm.clear();
    datm.resize(n*2-1,def);
    data.clear();
    data.resize(n*2-1,0);
  }
  void add(int a,int b,int x,int k,int l,int r){
    if(r<=a||b<=l) return;
    if(a<=l&&r<=b){
      data[k]+=x;
      return;
    }
    add(a,b,x,k*2+1,l,(l+r)/2);
    add(a,b,x,k*2+2,(l+r)/2,r);
    datm[k]=max(datm[k*2+1]+data[k*2+1],datm[k*2+2]+data[k*2+2]);
  }
  int query(int a,int b,int k,int l,int r){
    if(r<=a||b<=l) return def;
    if(a<=l&&r<=b) return datm[k]+data[k];
    int vl=query(a,b,k*2+1,l,(l+r)/2);
    int vr=query(a,b,k*2+2,(l+r)/2,r);
    return max(vl,vr)+data[k];
  }
  void add(int a,int b,int x){
    add(a,b,x,0,0,n);
  }
  int query(int a,int b){
    return query(a,b,0,0,n);
  }
};
signed main(){
  int n,q;
  cin>>n>>q;
  StarrySky ss(n);
  for(int i=0;i<q;i++){
    int c,s,t,x;
    cin>>c;
    if(c){
      cin>>x;
      cout<<ss.query(x-1,x)<<endl;
    }else{
      cin>>s>>t>>x;
      ss.add(s-1,t,x);
    }
  }
  return 0;
}

/*
verified on 2017/02/24
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DSL_2_E
*/

Measured memory_bytes: 7064
///mAAria...
#include<bits/stdc++.h>
 
using namespace std;
 
#define int long long
typedef pair<int,int> pii;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define mod 1000000007
#define inf 1000000000

const long double PI = acos(-1);

int powm(int a, int b) {
    int res=1;
    while(b) {
        if(b&1)
            res=(res*a)%mod;
        a=(a*a)%mod;
        b>>=1;
    }
    return res;
}

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


void solve(){
    int a,b;
    cin >> a >> b;

    int ans = max(a+b,max(a-b,a*b));
    cout << ans << endl;

}

signed main() 
{   
    IOS;
    int t = 1;
    //cin >> t;

    for(int i = 1;i<=t;i++){
        solve();
    }
    return 0;
} 

 


Measured memory_bytes: 256
/**
 * @author karayuu
 */
fun main(args: Array<String>) {
    val input = readLine()!!.split(" ").map { it.toInt() }

    /* list内からある条件に適する物の個数を数えるときはcountを使うと良い */
    val five = input.count { it == 5 }
    val seven = input.count { it == 7 }

    if (five == 2 && seven == 1) {
        println("YES")
    } else {
        println("NO")
    }
}

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

int main(){
	string s;
	cin >> s;
	for(int i = 0; i<s.length(); i++){
		if (s[i] == s[i+1]) {
			cout << i+1 << " " << i+2 << endl;
			return 0;
		}else if(s[i] == s[i+2]) {
			cout << i+1 << " " << i+3 << endl;
			return 0;
		}
	}



	cout << "-1 -1" << endl;
	return 0;
}


Measured memory_bytes: 640
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cstdlib>
#include<cstdio>
#include<cmath>
#include<string>
using namespace std;
int main()
{
  string s;
  long long k;
  cin>>s;cin>>k;
  for (int i=0;i<s.size();i++)
  if (s[i]!='1')
  {
  	 if (i+1>k) cout<<1<<endl;
  	 else cout<<s[i]<<endl;
  	 return 0;
  }
  cout<<1<<endl;
  return 0;
}

Measured memory_bytes: 256
N, T = map(int, raw_input().split())
A = map(int, raw_input().split())

X = [0]*N
for i in xrange(N - 2, -1, -1):
    X[i] = max(X[i + 1], A[i + 1])

mx, cnt = 0, 0
for i, a in enumerate(A):
    tmp = X[i]
    if tmp - a > mx:
        mx = tmp - a
	cnt = 1
    elif tmp - a == mx:
        cnt += 1
print cnt


Measured memory_bytes: 11304
#A1, A2, ..., AN の最大公約数を g とします。すると、以下で示すように g が答えになります。
#入力例 1 において、なぜどのように攻撃を行っても体力 1 にならないのでしょうか。これは、どのモンス
#ターも初期体力が偶数なので、攻撃して体力が変化しても偶数にしか変化しないためです。これを一般化す
#ると、体力 a のモンスターが体力 b (b > a) のモンスターに攻撃したときに攻撃されたモンスターの体力は
#b − a となりますが、a も b も x の倍数であるなら b − a も x の倍数です。したがって、常に x として g を
#取れるので、生きているモンスターの体力は必ず g の倍数となり、g 未満になることはありません。
#逆に、次のように最後に生き残ったモンスターの体力を g にすることができます。体力 a のモンスターと
#体力 b のモンスターがお互いの体力が等しくなるまで体力の低いほうが高い方を攻撃し続けるとユークリッ
#ドの互除法と同じ遷移になるため最終的な体力はお互いに a と b の最大公約数になります。これを 1 番目の
#モンスターと 2 番目のモンスター, 2 番目のモンスターと 3 番目のモンスター, ... と順に行うと、最終的に N
#番目のモンスターの体力が A1, A2, ..., AN の最大公約数 g になります。最後に N 番目のモンスターが他の
#モンスターを攻撃し続ければ、最後に生き残ったモンスター (N 番目のモンスター) の体力が g になります。
#実装は、ユークリッドの互除法により A1, A2, ..., AN の最大公約数を求めて出力すればよく、これは
#O(N + logA1) で動作します。

import fractions
n = int(input())
a = list(map(int,input().split()))

g =a[0]

for i in range(n-1):
  g = fractions.gcd(g,a[i+1])
  
print(g)

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

int main() {
    int a,b,c,divisors;
    
    cin >> a;
    cin >> b;
    cin >> c;
    divisors = 0;
    
    for (;a<=b;a++) {
       if (c%a==0) divisors++;  
    }
    
    cout << divisors << endl;
}


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

int main() {
	int i,k,n,ans=0;
	cin >> n >> k;
	
	vector<int> p(n);
	for(i=0; i<n; i++){
		cin >> p[i];
	}
	sort(p.begin(),p.end());
	
	for(i=0; i<k; i++){
		ans+=p[i];
	}
	
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3576
#include<iostream>
#include<cstdlib>
#include<string>
#include<map>
#include<algorithm>
#include<vector>
#include<cmath>
#include<iomanip>
using namespace std;
#define rep(i,n) for(int i(0);i<n;i++)
typedef long long ll;

int main(){
	int N(0);
    cin >> N;
    int smallest(200001);
    int cnt(0);
    rep(i,N){
        int tmp;
        cin >> tmp;
        if(tmp <= smallest){
            smallest = tmp;
            cnt++;
        }
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define vi vector<int>
#define vl vector<ll>
#define rep(a,n) for(int i=a;i<n;i++)
#define rep1(a,n) for(int i=a;i<=n;i++)
#define bada 1000000007

int main()
{
   int n,a,b;
   cin>>n>>a>>b;

   if((n*a)>=b)
       cout<<b<<"\n";
   else
      cout<<n*a<<"\n";
   return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bits/stdc++.h>
#include <cstdint>
#include <iostream>
#include <iterator>
#include <vector>

// lib/util.hpp
#ifndef UTIL_HPP
#define UTIL_HPP


using i64 = ::std::int_fast64_t;
using u64 = ::std::uint_fast64_t;
using i32 = ::std::int_fast32_t;
using u32 = ::std::uint_fast32_t;

namespace tools {
  template <typename T>
  void read(::std::istream& is, ::std::vector<T>& vector, const typename ::std::vector<T>::size_type size) {
    vector.reserve(size);
    ::std::copy_n(::std::istream_iterator<T>(is), size, ::std::back_inserter(vector));
  }
  template <typename T>
  void read(::std::vector<T>& vector, const typename ::std::vector<T>::size_type size) {
    ::tools::read(::std::cin, vector, size);
  }

  template <typename T, ::std::size_t N>
  void read(::std::istream& is, ::std::array<T, N>& array) {
    ::std::copy_n(std::istream_iterator<T>(is), N, array.begin());
  }
  template <typename T, ::std::size_t N>
  void read(::std::array<T, N>& array) {
    ::tools::read(::std::cin, array);
  }
}

#endif

// main.cpp

int main() {
  i64 N;
  std::cin >> N;
  std::vector<i64> A;
  tools::read(A, N);

  std::vector<i64> B;
  std::partial_sum(A.begin(), A.end(), std::back_inserter(B), [](const i64& lhs, const i64& rhs) { return std::max(lhs, rhs); });

  std::vector<i64> C;
  for (i64 i = 0; i < N; ++i) {
    C.push_back(B[i] - A[i]);
  }

  std::cout << std::accumulate(C.begin(), C.end(), static_cast<i64>(0)) << std::endl;
  return 0;
}

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

void solve(ll x,ll y){
    if(x==n+1){
        ans += y;
        return;
    }
    ll cur = 0;
    for(ll i=x;i<=n;i++){
        cur = (10*cur) + (s[i]-'0');
        solve(i+1,y+cur);
    }
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin>>n;
    int a[n+2];
    for(int i=0;i<n;i++)cin>>a[i];
    sort(a,a+n);
    multiset<int>s;
    int j=0,mx=0;
    for(int i=0;i<n;i++){
        s.emplace(a[i]);
        while(*s.rbegin()-*s.begin()>2){
            s.erase(s.find(a[j]));
            j++;
        }
        mx=max(mx,(int)s.size());
    }
    cout<<mx<<endl;
}


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

int main(){
	int n,m,a,b;
	cin >> n >> m;
	vector<vector<int>> p(m);
	rep(i,n){
		cin >> a >> b;
		a--;
		if(m-a>0){
			p[a].push_back(b);
		}
	}
	priority_queue<int> q;
	ll ans(0);
	rep(i,m){
		rep(j,p[i].size()){
			q.push(p[i][j]);
		}
		if(!q.empty()){
			ans += q.top();q.pop();
		}
	}
	cout << ans << endl;
	return 0;
}

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

int main() {
  int H, W;
  cin >> H >> W;
  vector<vector<char>> a(H+2, vector<char>(W+2));
  
  for(int i=0; i<H+2; i++) {
    for(int j=0; j<W+2; j++) {
      if(i==0 || i==H+1 || j==0 || j==W+1)
        a[i][j] = '#';
      else
        cin >> a[i][j];
      cout << a[i][j];
    }
    cout << endl;
  }
}

Measured memory_bytes: 256
import java.util.Scanner;


public class Main{

	public static void main(String args[]){

		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int a = sc.nextInt();
        int min = a;
        int max = a;
        
        for(int i = 1; i < n; i ++) {
        	a = sc.nextInt();
        	if(min > a) {
        		min = a;
        	}else if(max < a) {
        		max = a;
        	}
        }
        System.out.println(max - min);
	}
}

Measured memory_bytes: 20052
#include <bits/stdc++.h>
#define rep1(i,n) for(int i=1;i<=n;i++)
#define rep(i,n)  for(int i=0;i<n;i++)
#define fast_io() ios_base::sync_with_stdio(false); cin.tie(NULL)
using namespace std;
typedef long long ll;


int main(){
    fast_io();
    int n; cin >> n;
    string S; cin >> S;
    ll Rs = 0,Gs = 0,Bs = 0;
    rep(i,n){
        if(S[i] == 'R') Rs++;
        if(S[i] == 'G') Gs++;
        if(S[i] == 'B') Bs++;
        
    }
    ll ans = Rs * Gs * Bs;
    rep(i,n){
        rep1(j,n){
            if(i - j < 0 || i + j >= n) break;
            if(S[i] != S[i - j] && S[i] != S[i + j] && S[i - j] != S[i + j]) ans--;
        }
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 3652
//Link : https://codeforces.com/contest/1253

#include <bits/stdc++.h>
using namespace std;
#define ll long long
/*
#include <limits.h>
INT_MAX
LLONG_MAX
*/

#define N 200005
#define mod 1000000007

vector<int> weight[N];

int add(int x,int y) {
  return ((x+y)%mod+mod)%mod;
}
int mul(int x,int y) {
  return (ll)x*y%mod;
}
int mypow(int x,int c) {
  int ret = 1;
  while(c>0) {
    if(c&1) {
      ret = mul(ret,x);
    }
    c/=2;
    x = mul(x,x);
  }
  return ret;
}

int per[N],invPer[N];
int minWei[N];

void solve() {
  per[0] = invPer[0] = 1;
  for(int i=1;i<N;++i) {
    per[i] = mul(per[i-1],i);
    invPer[i] = mypow(per[i],mod-2);
  }
  int n,x,y;
  scanf("%d %d %d ", &n,&x,&y);
  for(int i=0;i<n;++i) {
    int c,w;
    scanf("%d %d ", &c,&w);
    weight[c].push_back(w);
    if(minWei[c]==0) {
      minWei[c] = w;
    }
    minWei[c] = min(minWei[c],w);
  }
  vector<int> mws;
  for(int i=n;i;--i) {
    if(minWei[i]!=0) {
      mws.push_back(minWei[i]);
    }
    sort(mws.begin(),mws.end());
    if(mws.size()>2) {
      mws.pop_back();
    }
  }
  ll ret = 1;
  int totalNum = 0;
  for(int i=n;i;--i) {
    if(weight[i].size()==0) {
      continue;
    }
    int anotherColor = mws[0];
    if(anotherColor== minWei[i]) {
      if(mws.size()>1) {
        anotherColor = mws[1];
      } else {
        continue;
      }
    }

    if(anotherColor + minWei[i] <=y) {
      int num = 0;
      for(int w : weight[i]) {
        if(w + anotherColor <=y || w + minWei[i]<=x) {
          ++num;
        }
      }
      ret = mul(ret, invPer[num]);
      totalNum += num;
    }
  }
  ret = mul(ret, per[totalNum]);
  printf("%d\n", ret);
}

int main() {
  //freopen("input.txt","r",stdin);
  solve();
  return 0;
}


Measured memory_bytes: 15156
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
typedef long long ll;
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REP(i,num,n) for(int i=num, i##_len=(n); i<i##_len; ++i)
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; }
#define print(x) (cout << (x) << endl)
#define pb push_back
#define mp make_pair
#define sz(x) int(x.size())
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class itr> void cins(itr first, itr last){ for(auto i = first; i != last; i++){ cin >> (*i); } }
template<class itr> void array_output(itr start, itr goal){ string ans; for(auto i = start; i != goal; i++) ans += to_string(*i) + " "; if(!ans.empty()) ans.pop_back(); cout << ans << endl; }
#define fs first
#define sc second

const int INF = 1e9;
const ll LLINF = 1e16;
const ll MOD = 1e9+7;
template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};

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

// 指定した文字cが文字列に何文字入ってるか
ll stringcount(string s, char c) {
    return count(s.cbegin(), s.cend(), c);
}


// 割り算の切り上げ処理
template<typename T>
T rp(T a, T b) {
  return (a + b - 1) / b;
}

// 桁和
template<typename T>
T digsum(T n) {
    T res = 0;
    while(n > 0) {
        res += n%10;
        n /= 10;
    }
    return res;
}

// 回文判定
bool kai (string s) {
    string t{s};
    reverse(begin(t), end(t));
    return s == t;
}

using pint = pair<int, int>;
using pll = pair<ll, ll>;



int main(void)
{
    cout.tie(0);
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    string s;
    cin >> s;
    int count = 0;
    rep(i, sz(s)){
        if(s[i] == 'o') count++;
    }
    if(count + (15 - sz(s)) >= 8){
        print("YES");
    } else {
        print("NO");
    }


}



Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>

using namespace std;

int main(){
    int sum = 0, cnt = 0, n = 0, x, y;
    while(~scanf("%d,%d", &x, &y)){
	sum += x * y;
	cnt++;
	n += y;
    }
    n *= 10;
    n /= cnt;
    n += 5;
    n /= 10;
    printf("%d\n%d\n", sum, n);
    return 0;
}

Measured memory_bytes: 1020
#include<iostream>
#include<cstring>
#include<cstdio>

using namespace std;

int main()
{
   char str[1001];
   
   while(1)
   {
       scanf("%s",str);
       
       if(str[0] == '0'){ break; }
       
       int sum = 0;
       
       for(int i = 0; i < strlen(str); i++)
       {
           sum += (str[i] - '0');
       }
       
       printf("%d\n", sum);
   }
}


Measured memory_bytes: 3204
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <sstream>
#include <functional>
#include <map>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <list>
#include <numeric>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> P;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const ll INF = 1LL<<29;
const ll mod = 1e9+7;
#define rep(i,n) for(int (i)=0;(i)<(ll)(n);++(i))
#define repd(i,n,d) for(ll (i)=0;(i)<(ll)(n);(i)+=(d))
#define all(v) (v).begin(), (v).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset((m),(v),sizeof(m))
#define chmin(X,Y) ((X)>(Y)?X=(Y),true:false)
#define chmax(X,Y) ((X)<(Y)?X=(Y),true:false)
#define fst first
#define snd second
#define UNIQUE(x) (x).erase(unique(all(x)),(x).end())
template<class T> ostream &operator<<(ostream &os, const vector<T> &v){int n=v.size();rep(i,n)os<<v[i]<<(i==n-1?"":" ");return os;}

int main(){
	string s;
	cin>>s;
	bool c, f;
	c = f = false;
	rep(i, s.size()){
		if(s[i]=='C') c = true;
		if(c && s[i]=='F') f = true;
	}
	cout<<(f?"Yes":"No")<<endl;
	return 0;
}


Measured memory_bytes: 256
from itertools import count, combinations, product

H,W = map(int,input().split())

grid = [[False]*(W+2) for _ in range(H+2)]

for i in range(1,H+1):
    S = input()
    for j,v in zip(range(1,W+1),S):
        grid[i][j] = v == '.'

visited = [[0 if v else float('inf') for v in row] for row in grid]
cnt = 1
res = 0
for i,j in product(range(H+2),range(W+2)):
    if not grid[i][j]:
        continue
    q = [(i,j)]
    visited[i][j] = cnt 
    for d in count():
        if not q:
            break
        nq = []
        for x,y in q:
            for dx,dy in ((1,0),(-1,0),(0,1),(0,-1)):
                if visited[x+dx][y+dy] < cnt:
                    visited[x+dx][y+dy] = cnt
                    nq.append((x+dx,y+dy))
        q = nq
    cnt += 1
    res = max(d-1, res)

print(res)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <iostream>
#include <utility> // pair
#include <string>
#include <vector>
#define MAX_N 100001
#define MOD 1000000007
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
#define FOR(i, a, b) for(ll i=a; i<b; i++)
#define REP(i, n) for(ll i=0; i<n; i++)
#define REV(i, n) for(ll i=n-1; i>=0; i--)
#define ALL(v) v.begin(), v.end()
#define pb push_back
const ll INF = 9e18;
ll n, a[MAX_N], cnt[3];

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

	cnt[0] = 1;
	ll ret;
	if(a[0] == 0) ret = 3;
	else ret = 0;
	for(int i=1; i<n; i++){
		ll j = 0;
		bool cnt_flag = true;
		if(a[i] == cnt[0]){
			if(cnt_flag) cnt[0]++;
			j++;
			cnt_flag = false;
		}
		if(a[i] == cnt[1]){
			if(cnt_flag) cnt[1]++;
			j++;
			cnt_flag = false;
		}
		if(a[i] == cnt[2]){
			if(cnt_flag) cnt[2]++;
			j++;
			cnt_flag = false;
		}
		ret *= j;
		ret %= MOD;
	}
	cout << ret << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include <stdio.h>
#include <numeric>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define repone(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define Rep(j,n) for(int j=0;j<(int)(n);++j)
#define Repo(j,o,n) for(int j=o;j<(int)(n);++j)
#define Repone(j,n) for(int j=1;j<(int)(n);++j)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define int long long
#define pb(a) push_back(a)
#define eraser(v,i) (v).erase(v.begin()+(i))
#define pbpair(a,b) push_back(make_pair(a,b))
#define MOD 1000000007
#define INF 9223372036854775807
#define pairint pair<int,int>
int num[12] = {31,28,31,30,31,30,31,31,30,31,30,31};
bool uru(int checkyear){if(checkyear%4==0){if(checkyear%100!=0||checkyear%400==0)return true;}return false;}
int gcd( int x, int y ){return y ? gcd(y, x%y) : x;}
bool pairCompare(const pairint& firstElof, const pairint& secondElof)
{
  if(firstElof.second!= secondElof.second)    return firstElof.second> secondElof.second;
  else return firstElof.first< secondElof.first;
}
signed main() {
int x=0,y=0,z=0,w=0,n=0,m=0;
std::cin >> x>>y>>z>>w;
if(x+y>z+w)std::cout << "Left" << '\n';
else if(x+y<z+w) std::cout << "Right" << '\n';
else std::cout << "Balanced" << '\n';
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define P pair<int,int>
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1000000000
#define MOD 1000000007
#define all(v) v.begin(),v.end()
#define pb push_back
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
int kaijo[200010];
struct edge{int to,cost;};
int gcd(int a,int b){
	if(b==0)return a;
	return gcd(b,a%b);
}
int lcm(int a,int b){
	return a/gcd(a,b)*b;
}
bool prime(int a){
	if(a==1)return false;
	for(int i=2;i*i<=a;i++){
		if(a%i==0)return false;
	}
	return true;
}
bool kosa(double ax,double ay,double bx,double by,double cx,double cy,double dx,double dy){
	double ta=(cx-dx)*(ay-cy)+(cy-dy)*(cx-ax);
	double tb=(cx-dx)*(by-cy)+(cy-dy)*(cx-bx);
	double tc=(ax-bx)*(cy-ay)+(ay-by)*(ax-cx);
	double td=(ax-bx)*(dy-ay)+(ay-by)*(ax-dx);
	return tc*td<0&&ta*tb<0;
}
void init_fact(int n){
	kaijo[0]=1;
	for(int i=1;i<=n;i++){
		kaijo[i]=kaijo[i-1]*i;
		kaijo[i]%=MOD;
	}
}
int modpow(int a,int b){
	if(b==0)return 1;
	if(b%2)return modpow(a,b-1)*a%MOD;
	int memo=modpow(a,b/2);
	return memo*memo%MOD;
}
int comb(int a,int b){
	return kaijo[a]*modpow(kaijo[a-b],MOD-2)%MOD*modpow(kaijo[b],MOD-2)%MOD;
}
int inv(int x){
	x=modpow(x,MOD-2);
	return x;
}
int n;
signed main(){
	cin>>n;
	for(int i=1;i<=9;i++){
		for(int j=1;j<=9;j++){
			if(i*j==n){
				puts("Yes");
				return 0;
			}
		}
	}
	puts("No");
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define int ll
#define rep(i,n) for(int i=0;i<n;i++)
#define all(in) in.begin(), in.end()
#define INF (sizeof(int) == 4 ? (int)1e9:(int)1e18)
#define EPS 0.0000000001
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
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); }
using ld  = long double;
using pii = pair<int,int>;
using piii = pair<int,pii>;
int W,H;
int dx[]={0,0,1,-1}, dy[]={1,-1,0,0};
bool valid(int x,int y){return (0<=x&&x<W)&&(0<=y&&y<H);}
void YN(bool f){ cout << (f ? "YES" : "NO");}
void yn(bool f){ cout << (f ? "yes" : "no");}
void YeNo(bool f) {cout << (f ? "Yes" : "No");}
signed main(){
    int n,b;cin >> n >> b;
    string s; cin >> s;
    s[--b] = tolower(s[b]);
    cout << s << endl;
}


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

using namespace std;
#define N 666666
#define int long long
#define mod 1000000007
int f(int a,int b){
	int s=1;
	while(b){
		if(b%2) s=(s*a)%mod;
		a=(a*a)%mod;
		b/=2;
	}
	return s;
}
int res[N];
signed main(){
	int n,k;
	cin>>n>>k;
	int ans=0;
	for(int i=k;i>=1;i--){
		res[i]=f(k/i,n);
		for(int j=2;j*i<=k;j++) res[i]-=res[i*j];
	}
	for(int i=1;i<=k;i++) ans=(ans+i*res[i])%mod;
	cout<<ans;
	return 0;
} 

Measured memory_bytes: 4368
#include <iostream>
#include <vector>
#include<algorithm>
#include<string>
#include<stdio.h>
#include<map>
#include<math.h>
#include<queue>
using namespace std;
int main() {
	char a[1000]="", b[1000]="";
	cin >> a[0] >> b[0];
	for (int i = 1; i < b[0]-'0'; i++) {
		a[i] = a[0];
	}
	for (int i = 1; i < a[0]-'0'; i++) {
		b[i] = b[0];
	}
	cout << min((string)a,(string) b) << endl;
		return 0;
	
}

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

int main() {
  int n,m;
  cin>>n>>m;
  int a[m];
  for(int i=0;i<m;i++) a[i]=0;
  for(int i=0;i<n;i++){
    int k;
    cin>>k;
    for(int j=0;j<k;j++){
      int t;
      cin>>t;
      a[t-1]++;
    }
  }
  int ans=0;
  for(int i=0;i<m;i++){
    if(a[i]==n) ans++;
  }
cout<<ans<<endl;
  }


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

int main(){
    int a, b, c, i, j;
    j = 0;
    cin >> a >> b >> c;
    for ( i = a; i < b+1; i++ ){
        if (c % i == 0) j++;
    }
    cout << j << endl;    
    return 0;
}


Measured memory_bytes: 3120
#include <bits/stdc++.h>
using namespace std;
int main(){
	int a, b; cin >> a >> b;
	if(a <= 0 && 0 <= b) cout << "Zero" << endl;
	else if(a >= 1 || (b - a + 1)%2 == 0) cout << "Positive" << endl;
	else cout << "Negative" << endl;
	return 0;
}


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

int main(){
   long long int h,a,s=0,b;
   cin>>h>>a;


   for(int i=0;i<a;i++){
    cin>>b;
    s+=b;
   }


   if(s>=h)
    cout<<"Yes"<<endl;

   else
    cout<<"No"<<endl;



}


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

public class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        while(scan.hasNext()){
            int n = scan.nextInt();
            int[] team = new int[n];
            for(int i = 0;i < n*(n-1)/2;i++){
            	int a = scan.nextInt() - 1;
            	int b = scan.nextInt() - 1;
            	int c = scan.nextInt();
            	int d = scan.nextInt();
            	if(c == d){
            		team[a]++;
            		team[b]++;
            	}else if(c > d){
            		team[a]+=3;
            	}else{
            		team[b]+=3;
            	}
            }
            int[] sort = new int[team.length];
            for(int i = 0;i < sort.length;i++){
            	sort[i] = team[i];
            }
            Arrays.sort(sort);
            for(int i = 0;i < team.length/2;i++){
            	int t = sort[i];
            	sort[i] = sort[team.length - 1 - i];
            	sort[team.length - 1 - i] = t;
            }
            for(int i = 0;i < team.length;i++){
            	for(int j = 0;j < sort.length;j++){
            		if(team[i] == sort[j]){
            			team[i] = j+1;
            			break;
            		}
            	}
            }
            for(int i = 0;i < team.length;i++){
            	System.out.println(team[i]);
            }
        }
    }
}

Measured memory_bytes: 42092
#include<algorithm>
#include<cmath>
#include<fstream>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<random>
#include<set>
#include<sstream>
#include<sys/time.h>
#include<unordered_map>
#include<unordered_set>
#include<vector>
using ll = long long;
enum : int { M = (int)1e9 + 7 };
enum : ll { MLL = (ll)1e18L + 9 };
using namespace std;
#ifdef LOCAL
#include"rprint2.hpp"
#else
#define FUNC(name) template <ostream& out = cout, class... T> void name(T&&...){ }
FUNC(prints) FUNC(printw) FUNC(printwe) FUNC(printb) FUNC(printbe) FUNC(printd) FUNC(printde) FUNC(printdu);
#endif
template <class S, class T>
istream& operator >> (istream& in, pair<S, T>& p){ return in >> p.first >> p.second; }
template <class T>
istream& operator >> (istream& in, vector<T>& v){ for(auto& e : v){ in >> e; } return in; }

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    vector<int> ns(4); cin >> ns;
    sort(ns.begin(), ns.end());
    cout << (ns == vector<int>{1, 4, 7, 9} ? "YES" : "NO") << '\n';
}


Measured memory_bytes: 892
#include <bits/stdc++.h>
#include <stdio.h>
typedef long long int LL;
#define fr(i,p,n) for(LL i=p;i<n;i++)
#define fr1(i,p,n) for(LL i=p;i>=n;i--)
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define PI 3.14159265358979323846
#define MOD 1000000007
#define MOD1 998244353
#define INF 1e18
#define precise cout << std::setprecision(10) << std::fixed;

using namespace std;
 
int main()
{
        LL n;
        cin>>n;
        LL a[n+1];
        LL ans=0;
        fr(i,1,n+1){
            cin>>a[i];
            if(i%2==1 && a[i]%2==1) ans++;
        }
        cout<<ans<<endl;
    return 0;
}

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

using namespace std;

#define all(x) (x).begin(), (x).end()

typedef long long ll;

const int N = 5e5;
string s[N];
int id[N];
int p[26];
int res = 0;

struct TRIE {
  struct vertex {
    int go[26];
    int sumsubtree = 0;
    int leaf = 0;
  };

  vertex t[N];
  int h[N];
  int jmp[N];
  int sz = 1;

  int addString(string s) {
    int v = 0, depth = 0;
    for (auto x : s) {
      int c = x - 'a';
      t[v].sumsubtree++;
      h[v] = depth++;
      if (t[v].go[c] == -1) {
        t[v].go[c] = sz;
        memset(t[sz].go, -1, sizeof t[sz].go);
        sz++;
      }
      v = t[v].go[c];
    }
    t[v].sumsubtree++;
    h[v] = depth;
    t[v].leaf = 1;
    return v;
  }

  void dfs(int v) {
    jmp[v] = v;
    int cntc = 0, u = 0;
    for (int c = 0; c < 26; c++) {
      if (t[v].go[c] != -1) {
        cntc++;
        u = t[v].go[c];
        dfs(u);
      }
    }
    if (cntc == 1 && t[v].leaf == 0) {
      jmp[v] = jmp[u];
    }
    //cout << v << " " << jmp[v] << endl;
  }

  void go(int v, int k) {
    //cout << "go " << v << " " << k << " " << id[k] << " " << h[id[k]] << " " << res << endl;
    if (h[v] == h[id[k]]) return;
    if (jmp[v] != v) {
      go(jmp[v], k); return;
    }
    int myc = s[k][h[v]] - 'a';
    res += t[v].leaf;
    for (int c = 0; c < 26; c++) {
      int u = t[v].go[c];
      if (u != -1) {
        if (p[c] < p[myc]) {
          res += t[u].sumsubtree;
          //cout << "opa " << v << " " << u << " " << t[u].sumsubtree << endl;
        }
        else if (p[c] == p[myc]) {
          go(u, k);
        }
      }
    }
  }
} trie;

void solve() {
  memset(trie.t[0].go, -1, sizeof trie.t[0].go);
  int n; cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> s[i];
    id[i] = trie.addString(s[i]);
    //cout << id[i] << endl;
  }
  trie.dfs(0);
  int q; cin >> q;
  for (int iter = 0; iter < q; iter++) {
    int k; cin >> k; k--;
    string order; cin >> order;
    for (int i = 0; i < 26; i++) {
      p[order[i] - 'a'] = i;
    }
    res = 0;
    trie.go(0, k);
    cout << res + 1 << "\n";
  }
}

// CHECK LIMITS (n <= 10^5)
// CHECK CORNER CASES (n == 1)

int main() {
  ios::sync_with_stdio(NULL), cin.tie(0), cout.tie(0);
  cout.setf(ios::fixed), cout.precision(2);
  //cout << 1.0 * clock() / CLOCKS_PER_SEC << endl;
  solve();
}


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

using namespace std;

int main() {
	int n;
	cin >> n;
	vector<int> given(n);	// the given sequence
	vector<int> prev(n);	// the previous permutation
	vector<int> next(n);	// the next permutation
	for_each(given.begin(),given.end(),[](int &_e){cin >> _e;});
	prev.assign(given.begin(),given.end());
	next.assign(given.begin(),given.end());
	if (prev_permutation(prev.begin(),prev.end())) {
		int i = 1;
		for_each(prev.begin(),prev.end(),[&i,n](int _e){cout << _e << (i++ == n ? "\n" : " ");});
	}
	int j = 1;
	for_each(given.begin(),given.end(),[&j,n](int _e){cout << _e << (j++ == n ? "\n" : " ");});
	if (next_permutation(next.begin(),next.end())) {
		int i = 1;
		for_each(next.begin(),next.end(),[&i,n](int _e){cout << _e << (i++ == n ? "\n" : " ");});
	}
}


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



int gcd_3 (int i, int j, int k){
  int a = std::gcd (i,j);
  return std::gcd(a,k);
}

int main() {
  int N;
  cin >> N;
  
  int result = 0;
  
  for (int i=1; i < N+1; i++) {
    for (int j=1; j < N+1; j++){
      for (int k=1; k < N+1; k++){
        int a = gcd_3(i,j,k);
        result = result + a;
      }
    }
  }
  cout << result << endl;
}

Measured memory_bytes: 3632
from collections import Counter

n=int(input())
A=list(map(int,input().split()))

sum=0
b=[]
for a in A:
    a//=400
    if a<8:
        b.append(a)
    else:
        sum+=1
b=Counter(b).most_common()
m=len(b)
if m==0:
    x=1
else:
    x=m
y=m+sum
print(x,y)

Measured memory_bytes: 3316
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e5+5;
int n,a[N];
ll pre[322][N],bk[322][N];
set<int>s;
void solve()
{
    ll ans=0;
    for(int x=1;x<n;x++)
        for(int y=1;y<x;y++)
    {
        ll res=0;
        if((n-1-x)%(x-y)!=0) continue;
        for(int k=x;k<n;k+=x-y)
            res+=a[k],s.insert(k);
        for(int k=n-1-x;k>=0;k-=x-y)
        {
            if(s.count(k)) {res=0;break;}
            res+=a[k];
        }
        s.clear();
        ans=max(ans,res);
    }
    printf("%lld\n",ans);
}
int main()
{
    scanf("%d",&n);
    for(int i=0;i<n;i++)
        scanf("%d",&a[i]);
    if(n<500) {solve();return 0;}
    ll ans=0;
    int t=sqrt(n);
    for(int i=1;i<=t;i++)
    {
        for(int j=i;j<n;j+=i)
            pre[i][j]=a[j];
        for(int j=i;j<n;j++)
            pre[i][j]+=pre[i][j-1];
        for(int j=n-1-i;j>=0;j-=i)
            bk[i][j]=a[j];
        for(int j=n-1-i;j>=0;j--)
            bk[i][j]+=bk[i][j+1];
    }
    for(int i=1;i<n;i++)
    {
        int x=i,y=n-1-i,s=y-x;
        if(s<0)
        {
            int l=1,r=1;
            while(l<=y)
            {
                if(y%l==0)
                {
                    ll res=0;
                    if(l<=t)
                        res=bk[l][i]+pre[l][n-1-i];
                    else
                    {
                        for(int j=i;j<n;j+=l)
                            res+=a[j];
                        for(int j=n-1-i;j<n;j+=l)
                            res+=a[j];
                    }
                    ans=max(ans,res);
                }
                l=r+1;
                if(l>y) break;
                r=y/(y/l);
            }
        }
        else if(s>0)
        {
            int l=1,r=1;
            while(l<=y)
            {
                if(y%l==0&&s%l!=0)
                {
                    ll res=0;
                    if(l<=t)
                        res=bk[l][i]+pre[l][n-1-i];
                    else
                    {
                        for(int j=i;j<n;j+=l)
                            res+=a[j];
                        for(int j=n-1-i;j<n;j+=l)
                            res+=a[j];
                    }
                    ans=max(ans,res);
                }
                l=r+1;
                if(l>y) break;
                r=y/(y/l);
            }
        }
    }
    printf("%lld\n",ans);
}
/*
a=6,b=4
11
0 -4 0 -99 31 14 -15 -39 43 18 0
*/


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

using namespace std;

typedef long long int ll;
const int INF = 1<<30;
const long long LINF = 1LL<<60;
const long long MOD = (long long)1e9 + 7;

int main(){
    ll n, ans = 0;
    cin >> n;
    for(ll i = 2; i * i <= (n - 1); i++){
        if((n - 1) % i == 0){
            ans++;
            if((n - 1) / i != i){
                ans++;
            }
        }
    }
    if(n > 2){ ans++; }
    vector<ll> a;
    for(ll i = 1; i * i <= n; i++){
        if(n % i == 0){
            ll t = n / i;
            a.push_back(i);
            if(i != t){ a.push_back(t); }
        }
    }
    for(int i = 1; i < a.size(); i++){
        ll t = n;
        while(t % a[i] == 0){
            t /= a[i];
        }
        if(t % a[i] == 1){
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}


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

#define endl '\n'
#define lfs cout<<fixed<<setprecision(10)
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define test cout<<"test"<<endl;
#define fi first
#define se second
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define rep(i,n,m) for(ll i = (n); i < (ll)(m); i++)
#define rrep(i,n,m) for(ll i = (m) - 1; i >= (ll)(n); i--)
using ll = long long;
using ld = long double;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const ll INF = 1e18;
using P = pair<ll, ll>;
template<typename T>
void chmin(T &a,T b){if(a>b)a=b;}
template<typename T>
void chmax(T &a,T b){if(a<b)a=b;}
void pmod(ll &a,ll b){a=(a+b)%MOD;}
void pmod(ll &a,ll b,ll c){a=(b+c)%MOD;}
void qmod(ll &a,ll b){a=(a*b)%MOD;}
void qmod(ll &a,ll b,ll c){a=(b*c)%MOD;}
ll median(ll a,ll b, ll c){return a+b+c-max({a,b,c})-min({a,b,c});}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
template<typename T1,typename T2>
void ans(bool x,T1 y,T2 z){if(x)cout<<y<<endl;else cout<<z<<endl;}  
template<typename T>
void debug(vector<vector<T>>&v,ll h,ll w){for(ll i=0;i<h;i++)
{cout<<v[i][0];for(ll j=1;j<w;j++)cout spa v[i][j];cout<<endl;}};
void debug(vector<string>&v,ll h,ll w){for(ll i=0;i<h;i++)
{for(ll j=0;j<w;j++)cout<<v[i][j];cout<<endl;}};
template<typename T>
void debug(vector<T>&v,ll n){if(n!=0)cout<<v[0];
for(ll i=1;i<n;i++)cout spa v[i];cout<<endl;};
template<typename T>
vector<vector<T>>vec(ll x, ll y, T w){
  vector<vector<T>>v(x,vector<T>(y,w));return v;}
ll gcd(ll x,ll y){ll r;while(y!=0&&(r=x%y)!=0){x=y;y=r;}return y==0?x:y;}
vector<ll>dx={1,0,-1,0,1,1,-1,-1};
vector<ll>dy={0,1,0,-1,1,-1,1,-1};
template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}
ostream &operator<<(ostream &os, pair<ll, ll>&p){
  return os << p.first << " " << p.second;
}  
int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  ll res=0,buf=0;
  bool judge = true;
  ll n,m;cin>>n>>m;
  vector<ll>a(n);
  rep(i,0,n)cin>>a[i];
  sort(ALL(a));
  ll l=0,r=INF;
  while(r-l>=2){
    ll num=0;
    ll mid=(r+l)/2;
    rep(i,0,n){
      ll idx=lower_bound(ALL(a),mid-a[i])-a.begin();
      num+=n-idx;
    }
    //cout<<mid spa num<<endl;
    if(num<m)r=mid;
    else l=mid;
  }
  //cout<<l<<endl;
  vector<ll>b(n+1);
  rep(i,0,n)b[i+1]=b[i]+a[i];
  ll num=0;
  rep(i,0,n){
    ll idx=lower_bound(ALL(a),l-a[i])-a.begin();
    num+=n-idx;
    res+=a[i]*(n-idx);
    res+=b[n]-b[idx];
    //cout<<a[i] spa n-idx spa b[n]-b[idx]<<endl;
  }
  res+=(m-num)*l;
  cout<<res<<endl;
  return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define pb push_back
using namespace std;

const int mn=1e5+7;
int h[mn],n,m,f,ans;
vector<int> to[mn];

int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;++i) scanf("%d",h+i);
	for(int i=1;i<=m;++i) {int u,v;scanf("%d%d",&u,&v);to[u].pb(v);to[v].pb(u);}
	for(int x=1;x<=n;++x) {
		f=1;
		for(int i=0;i<to[x].size();++i) {int t=to[x][i];f&=(h[x]>h[t]);}
		ans+=f;
	}
	cout<<ans;
}

Measured memory_bytes: 9272