akhauriyash/Code-Regression huggingface dataset:
//#pragma GCC optimize ("Ofast")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("avx,avx2,fma")

#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/rope>
#define pb push_back
#define F first
#define S second
#define ins insert
#define mp make_pair
#define fo(i, n1, n, x) for(int i = n1; i <= n; i += x)
#define foo(i, n, n1, x) for(int i = n; i >= n1; i -= x)
#define bit __builtin_popcount
#define md (l + ((r - l) / 2))
#define all(x) x.begin(),x.end()
#define eb emplace_back
#define ub upper_bound
#define lb lower_bound
#define ios ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define file(s) if (fopen(s".in", "r")) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout)

using namespace std;
//using namespace __gnu_pbds;
//using namespace __gnu_cxx;


using ll = long long;

//#define int ll

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



const int N = 2e3 + 11, mod = 1e9 + 7, mod2 = 998244353;
const int MAX = 1e5 + 11;
const int INF1 = 2e9 + 11;
const ll INF2 = 2e18 + 11;
const double INF3 = 1e8 + 11;
const int base = 500;
const int P = 31;
const int dx[] = {1, -1, 0, 0, 1, 1, -1, -1};
const int dy[] = {0, 0, 1, -1, 1, -1, 1, -1};
const double EPS = 1e-4;
const double PI = acos(-1.0);


//template<typename T> using ordered_set = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>;
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; }


mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int n, x, y, d[N][N], cnt[N];
vi g[N];
main() {
  file("threesum");
  ios;
  cin >> n >> x >> y;
  fo(i, 1, n - 1, 1) {
    g[i].eb(i + 1);
    g[i + 1].eb(i);
  }
  memset(d, INF1, sizeof d);
  g[x].eb(y);
  g[y].eb(x);
  fo(i, 1, n, 1) {
    queue<int> q;
    q.push(i);
    d[i][i] = 0;
    while (!q.empty()) {
      int v = q.front();
      q.pop();
      for (int to : g[v]) {
        if (d[i][to] > d[i][v] + 1) {
          d[i][to] = d[i][v] + 1;
          q.push(to);
        }
      }
    }
  }
  fo(i, 1, n, 1) fo(j, i + 1, n, 1) ++cnt[d[i][j]];
  fo(i, 1, n - 1, 1) {
    cout << cnt[i] << "\n";
  }
  return 0;
}
/**

*/


Measured memory_bytes: 16256
#include <bits/stdc++.h>
using namespace std;
const int N =16;
int n;
int a[N], x[N][N], y[N][N];
inline bool check(int s) {
for (int i = 0;i < n; ++i) if((s>>i)&1) {
for(int j=0;j<a[i];++j){
if (((s>>x[i][j])&1) != y[i][j])
return false;
}
}
return true;
}
inline int count(int x){
int res=0;
while (x) {
res += x&1;
x >>= 1;
}
return res;
}
int main()
{
cin >> n;
for (int i =0;i< n; ++i) {
cin>>a[i];
for(int j=0;j<a[i];++j){
cin>>x[i][j]>> y[i][j];
--x[i][j];
}
}
int res = 0;
for(int i=0;i<1<<n;++i){
if (check(i))
res = max(res, count(i));
}
cout << res << endl;
return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

#define NUM 100

int main()
{
  int i,j;
  int n,a[NUM],minj,k,count = 0;

  scanf("%d",&n);

  for(i = 0;i < n;i++){
    scanf("%d",&a[i]);
  }

  for(i = 0;i < n;i++){
    minj = i;
    for(j = i;j < n;j++){
      if(a[j] < a[minj]){
	minj = j;
      }
    }
    if(i != minj) count++;
    k = a[i];
    a[i] = a[minj];
    a[minj] = k;
  }

  printf("%d",a[0]);
  for(i = 1;i < n;i++){
    printf(" %d",a[i]);
  }
  printf("\n");
  printf("%d\n",count);

  return 0;
}



Measured memory_bytes: 2104
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
#define fi first
#define se second
#define endl '\n'
#define y1 holyshit
const int inf=0x3f3f3f3f;

ll N;

bool sex(ll X,ll K){
	if(K==1) return 0;
	while(1){
		if(X%K==0) X/=K;
		else break;
	}
	return X%K==1;
}

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin>>N; 
    ll ans=0;
    for(ll i=1;i*i<=N;i++){
    	if(N%i==0){
    		ans+=sex(N,i);
    		if(i*i!=N) ans+=sex(N,N/i);
    	}
    }
    N--;
    for(ll i=1;i*i<=N;i++){
    	if(N%i==0) ans+=2;
    	if(i*i==N) ans--;
    }
    cout<<ans-1;
    return 0;
}

Measured memory_bytes: 256
#include<vector>
#include<list>
#include<algorithm>
#include<iostream>
#include<string>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;
int main(){
  int i;
  int a[100001],m,n;
  int mx;
  a[0]=0;
  while(cin>>n>>m&&n+m){
    for(i=1;i<n+1;i++){
      cin>>a[i];
      a[i]+=a[i-1];
    }
    mx=-1000000000;
    for(i=0;i<n-m+1;i++){
      if(a[i+m]-a[i]>mx)
	mx=a[i+m]-a[i];
    }
    cout<<mx<<endl;
  }
  return 0;
}

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

int main(){
    string S; cin >> S;
    int N = S.size();

    vector<int> looppoint(N+1,0); // 1 or 0 ([0]==[N]==0)
    for( int i = 1; i < N; i++ ){
        if( S[i] == 'L' && S[i-1] == 'R' ) looppoint[i] = 1;
    }
    set<int> LPset;
    for( int i = 0; i < N; i++ ){
        if( looppoint[i] == 1 )LPset.insert(i);
    }
    LPset.insert(-10000000); LPset.insert(100000000);

    vector<int> ans(N,0);
    for( int i = 0; i < N; i++ ){
        auto itrR = LPset.upper_bound(i);
        auto itrL = itrR;
        itrL--;
        int goal = (S[i] == 'L') ? *itrL : *itrR, movecount = abs(goal - i);
        if( movecount % 2 == 0 )ans[goal]++;
        if( movecount % 2 == 1 )ans[goal - 1]++;
    }

    for(int i = 0; i < N; i++ ){
        cout << ans[i];
        if( i != N-1 )cout << " ";
    }
    cout << endl;
}

Measured memory_bytes: 3712
#include<bits/stdc++.h>
#define rep(i,n) for(int (i) = 0;(i) < (n);(i)++)
#define SORT(c) sort((c).begin(),(c).end())
#define MOD 1000000007
using namespace std;
typedef long long ll;
int main(void){
	int n;
	string s;
	cin >> n >> s;

	s = s + '#';
	int ans = 0;
	for(int i = 0; i < n; i++){
		if(s[i] != s[i + 1]) ans++;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001;

int N,M,K;
char g[800][800];
int dist[800][800];
int xd[4] = {1,0,-1,0}, yd[4] = {0,1,0,-1};

bool valid(int x, int y) {
    if (x < 0 || x >= N || y < 0 || y >= M) return 0;
    if (g[x][y] == '#') return 0;
    if (dist[x][y] != MOD) return 0;
    return 1;
}

int dfs(int x, int y) {
    queue<pi> q; q.push({x,y});
    F0R(i,N) F0R(j,M) dist[i][j] = MOD;
    
    dist[x][y] = 0;
    int ans = MOD;
    while (sz(q)) {
        auto a = q.front(); q.pop();
        ans = min(ans,min(min(a.f,N-1-a.f),min(a.s,M-1-a.s)));
        if (dist[a.f][a.s] < K) {
            F0R(i,4) if (valid(a.f+xd[i],a.s+yd[i])) {
                dist[a.f+xd[i]][a.s+yd[i]] = dist[a.f][a.s]+1;
                q.push({a.f+xd[i],a.s+yd[i]});
            }
        }
    }

    return ans;
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> N >> M >> K;
    F0R(i,N) F0R(j,M) cin >> g[i][j];
    F0R(i,N) F0R(j,M) if (g[i][j] == 'S') {
        int x = dfs(i,j);
        cout << 1+(x+K-1)/K << "\n";
    }
}

// read the question correctly (is y a vowel? what are the exact constraints?)
// look out for SPECIAL CASES (n=1?) and overflow (ll vs int?) ARRAY OUT OF BOUNDSS

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

int main()
{
  int n;
  for(;cin>>n,n;)
    {
      vector<pair<int,int> > p;
      for(int i=0;i<n;i++)
	{
	  int a,b;
	  cin>>a>>b;
	  p.push_back(make_pair(b,a));
	}
      sort(p.begin(),p.end());
      int add=0;
      bool flag = true;
      for(int i=0;i<n;i++)
	{
	  //  cout<<i<<":"<<p[i].first<<p[i].second<<endl;
	  add+=p[i].second;
	  if(add>p[i].first)
	    {
	      flag=false;
	      break;
	    }
	}
      if(flag)
	cout<<"Yes"<<endl;
      else 
	cout<<"No"<<endl;
    }
}

  

Measured memory_bytes: 1192
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repa(i, a, n) for (int i = (int)(a); i < (int)(n); i++)
#define ALL(a) (a).begin(), (a).end()
#define COUT(x) cout << (x) << endl
#define _GLIBCXX_DEBUG

int main(){
  
  int a, b;
  cin >> a >> b;
  if (a+b < 10)
    cout << a+b << endl;
  else
    cout << "error" << endl;

}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
using uint = unsigned int;
using ull = unsigned long long;

int main(void){
    // Your code here!
    uint A, B;
    cin >> A >> B;
    
    if (A < B*2) {
        cout << 0;
    } else {
        cout << A - B*2;
    }
}


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


int main()
{
	int D, N;
	double answer;
	cin >> D >> N;

	answer = pow(100.0, (double)D)*N;

	if (N == 100) {
		answer = answer + pow(100.0, (double)D);
	}

	cout << (long long)answer << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
int x,A,B;
cin>>x>>A>>B;
if(abs(x-B)<abs(x-A))cout<<'B';
else cout<<'A';
  return 0;
}

Measured memory_bytes: 256
using namespace std;
#include<bits/stdc++.h>
#define BEGIN ios_base::sync_with_stdio(0);cin.tie(0);
#define END return EXIT_SUCCESS;
#define FOR(I,A,B) for((I)=(A);(I)<(B);(I)++)
#define REP(I,N) FOR((I),0,(N))
#define UP(I,A,B) for((I)=(A);(I)<=(B);(I)++)
#define DW(I,A,B) for((I)=(A);(I)>=(B);(I)--)
#define IN(P) cin>>(P)
#define IN2(P1,P2) cin>>(P1)>>(P2)
#define IN3(P1,P2,P3) cin>>(P1)>>(P2)>>(P3)
#define INS(I,N,V) REP((I),(N)) cin>>(V[I])
#define INS2(I,N,V1,V2) REP((I),(N)) cin>>(V1[I])>>(V2[I]);
#define INS3(I,N,V1,V2,V3) REP((I),(N)) cin>>(V1[I])>>(V2[I])>>(V3[I]);
#define OUT(P) cout<<(P)<<endl
#define OUT2(P1,P2) cout<<(P1)<<" "<<(P2)<<endl
#define OUT3(P1,P2,P3) cout<<(P1)<<" "<<(P2)<<" "<<(P3)<<endl
#define OUTS(I,N,V) REP((I),(N)) cout<<(V[i])<<endl
#define ALL(C) (C).begin(),(C).end()
#define RALL(C) (C).rbegin(),(C).rend()
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
template<class T>inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;}
template<class T>inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;}

int N,i;
string W[100];
set<string> s;
inline void solve(){
  IN(N);
  INS(i,N,W);
  s.insert(W[0]);
  FOR(i,1,N){
    s.insert(W[i]);
    if(W[i-1].back()!=W[i].front()||s.size()!=i+1){
      OUT("No");
      return;
    }
  }
  OUT("Yes");
}

int main(int argc,char**argv){
  BEGIN
  solve();
  END
}


Measured memory_bytes: 256
A, V = map(int,input().split())
B, W = map(int,input().split())
T = int(input())

if A < B:
    if A+V*T >= B+W*T:
        print('YES')
    else:
        print('NO')
else:
    if A-V*T <= B-W*T:
        print('YES')
    else:
        print('NO')

Measured memory_bytes: 9188
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a,b,c;
  cin >> a;
  cin >> b;
  cin >> c;
  if(a*b<=c){
    cout << a*b << endl;
  }
  else if(a*b>c){
    cout << c << endl;
  }
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
	//freopen("in.txt","r",stdin);
	ll a;
	cin>>a;
	string s = "";
	//a--;
	while(a!=0){
		a--;
		s += (a%26) + 'a';
		a /= 26;
	}
	reverse(s.begin(),s.end());
	cout<<s<<endl;
    return 0;
}

Measured memory_bytes: 3652
#include <stdio.h>
int main(){
  int a, b, c, d;
  scanf("%d %d %d", &a, &b, &c);
  if(a > b){
    d=a; a=b; b=d;
  }
  if(b > c){
    d=b; b=c; c=d;
  }
  if(a > b){
    d=a; a=b; b=d;
  }
  printf("%d %d %d\n", a, b, c);
  return 0;
}

Measured memory_bytes: 1852
import java.util.*;
import java.io.*;

public class Main {
	static final int mod = (int) 1e9 + 7;
	static final int DX[] = { -1, 0, 1, 0 }, DY[] = { 0, -1, 0, 1 };
	static final int[] DX8 = { -1, -1, -1, 0, 0, 1, 1, 1 }, DY8 = { -1, 0, 1, -1, 1, -1, 0, 1 };
	static final int INF = Integer.MAX_VALUE / 3;
	static final long LINF = Long.MAX_VALUE / 3;
	static final String nextLine = "\n";

	public static void main(String[] args) {
		FastScanner fs = new FastScanner(System.in);
		int q = fs.nextInt();
		long sum = 0, suml = 0, sums = 0;
		PriorityQueue<Integer> ql = new PriorityQueue<>();//大きい方の集合を管理
		PriorityQueue<Integer> qs = new PriorityQueue<>((a1,a2)-> a2-a1);//小さい方の集合を管理
		for(int i=0;i<q;i++) {
			int t = fs.nextInt();
			if(t==1) {
				int a = fs.nextInt(), b = fs.nextInt();
				sum += b;

				suml += a;
				ql.add(a);
				int d = ql.poll();
				suml -= d;
				sums += d; 
				qs.add(d);
				if(qs.size()>ql.size()) {
					d = qs.poll();
					sums -= d;
					suml += d; 
					ql.add(d);
				}
		

			}
			else {//解答
				if(qs.size()==ql.size()) {
					long ans = sum + suml - sums;
					System.out.println(qs.peek() + " " + ans);
				}
				else {
					long p = ql.peek();//大きい集合の最小で、今回無視する値
					long ans = sum + (suml - p) - sums;
					System.out.println(p + " " + ans);
				}
			}
		}
	}

	//MOD culculations
	static long plus(long x, long y) {
		long res = (x + y) % mod;
		return res < 0 ? res + mod : res;
	}

	static long sub(long x, long y) {
		long res = (x - y) % mod;
		return res < 0 ? res + mod : res;
	}

	static long mul(long x, long y) {
		long res = (x * y) % mod;
		return res < 0 ? res + mod : res;
	}

	static long div(long x, long y) {
		long res = x * pow(y, mod - 2) % mod;
		return res < 0 ? res + mod : res;
	}

	static long pow(long x, long y) {
		if (y < 0)
			return 0;
		if (y == 0)
			return 1;
		if (y % 2 == 1)
			return (x * pow(x, y - 1)) % mod;
		long root = pow(x, y / 2);
		return root * root % mod;
	}
}

//高速なScanner
class FastScanner {
	private BufferedReader reader = null;
	private StringTokenizer tokenizer = null;

	public FastScanner(InputStream in) {
		reader = new BufferedReader(new InputStreamReader(in));
		tokenizer = null;
	}

	public String next() {
		if (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				tokenizer = new StringTokenizer(reader.readLine());
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken();
	}

	public String nextLine() {
		if (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				return reader.readLine();
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken("\n");
	}

	public long nextLong() {
		return Long.parseLong(next());
	}

	public int nextInt() {
		return Integer.parseInt(next());
	}

	public double nextDouble() {
		return Double.parseDouble(next());
	}

	public int[] nextIntArray(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = nextInt();
		return a;
	}

	public long[] nextLongArray(int n) {
		long[] a = new long[n];
		for (int i = 0; i < n; i++)
			a[i] = nextLong();
		return a;
	}
}

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

#include<algorithm>

int main(){

	int a, b, c, d, e, f;
	int sum;

	cin >> a >> b >> c >> d >> e >> f;

	sum = a + b + c + d;
	sum -= min(a, min(b, min(c, d)));
	sum += max(e, f);

	cout << sum << endl;
}

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

typedef long long ll;

int main() {
    string T;
    cin >> T;
    rep(i, T.size()) {
        if (T[i] == '?') T[i] = 'D';
    }
    cout << T << "\n";
}

Measured memory_bytes: 3752
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define vvi vector<vector<int>> 
#define vi vector<int> 
#define vpii vector<pair<int,int>> 
#define ff first
#define ss second
#define all(x) x.begin(),x.end()
#define ffor(i,n) for(int i = 0; i < n; ++i)

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    mt19937_64 rngl(chrono::steady_clock::now().time_since_epoch().count());
    
    int a,b,k;
    cin >> a >> b >> k;
    int ans = 0;
    int x = min(k,a);
    k -= x;
    a -= x;
    int y = min(k,b);
    b -= y;
    cout << a << " " << b;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define inf INFINITY
#define file freopen( "input.txt" , "r" , stdin) ; freopen( "output.txt" , "w" , stdout) ;
#define Gamed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define _3102_ main()
#define endl '\n'
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
using namespace std;
const int N = 1e5 + 100;
const ll MX = 1e9;
const ll mod = 1e9 + 7;
const double eps = 1e-9 ;

ll n, tot,  w[N] , v[N] , dp[2][N]  ;

void show(){
	for ( int i = 0; i < 2 ; i ++){
		for ( int j = 0 ; j <= tot ; j ++){
			cout << dp[i][j] << " " ;
		}
		cout << endl ;
	}
	cout << "--------------------\n" ;
}

int _3102_{
	Gamed
	cin >> n >> tot ;
	for ( int i = 0 ; i < n ; i ++){
		cin >> w[i] >> v[i] ;
	}
	for ( int i = 0 ; i < n ; i ++ ){
		for ( int j = 1 ; j <= tot ; j ++  ){
				if ( i & 1 ){
					dp[1][j] = dp[0][j] ;
					if ( j >= w[i]){
						dp[1][j] = max ( dp[0][j] , dp[0][j-w[i]]+ v[i]) ;
					}
				}
				else {
					dp[0][j] = dp[1][j] ;
					if ( j >= w[i]){
						dp[0][j] = max ( dp[1][j] , dp[1][j-w[i]] + v[i]) ;
					}
				}
		}
	}
	cout << (n % 2 != 0 ? dp[0][tot] : dp[1][tot] )<< endl ;
	return 0;
}


Measured memory_bytes: 5148
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author NikuKyabe
 */

#include <iostream>
#include <fstream>

#include "bits/stdc++.h"

using namespace std;
#define D double
#define int long long
#define FOR(i, a, b) for(int i=(int)(a);i<(int)(b);++i)
#define outdicimal out << fixed << setprecision(12)//TODO 小数点以下の桁数の変更


class CDiceAndCoin {
public:
    void solve(std::istream &in, std::ostream &out) {
      int n, k;
      in >> n >> k;

      double ans = 0;
      FOR(i, 1, min(n + 1, k + 1)) {
        ans += (1.0 / n) * pow(0.5, ceil(log2((D) k / i)));
      }
      FOR(i, k + 1, n + 1) {
        ans += (1.0 / n);
      }
      outdicimal << ans << endl;
    }
};


signed main() {
  ios::sync_with_stdio(false);
  cout.tie(0);
  cout << fixed;
  CDiceAndCoin solver;
  std::istream &in(std::cin);
  std::ostream &out(std::cout);
  solver.solve(in, out);
  return 0;
}


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

int main() {
    string S;
    cin >> S;
    bool judge = false;
    if (S[0] == S[1] && S[1] == S[2]) judge = true;
    if (S[1] == S[2] && S[2] == S[3]) judge = true;
    if (judge) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


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

using namespace std;

#define endl "\n"
#define maxn 100000
#define OO 1e5
#define F first
#define S second
#define B begin()
#define E end()
#define PB push_back
#define int long long

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

int32_t main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

//	freopen("name.in","r",stdin);
//	freopen("name.out","w",stdout);

    string a;
    cin >> a;
    if(a[2]==a[3]&&a[4]==a[5])
        cout << "Yes";
    else
        cout << "No";

	return 0;
}


Measured memory_bytes: 256
import sys
from itertools import combinations

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60


def main():
    N, K, *A = map(int, read().split())

    ans = INF
    for comb in combinations(range(1, N), K - 1):
        included = [False] * N
        for i in comb:
            included[i] = True

        total = 0
        max_height = A[0]
        for i, a in enumerate(A[1:], 1):
            if a <= max_height:
                if included[i]:
                    total += max_height - a + 1
                    max_height += 1
            else:
                max_height = a

        if ans > total:
            ans = total

    print(ans)

    return


if __name__ == '__main__':
    main()


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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<ll> vl;
typedef vector<char> vc;
typedef vector<string> vs;
const ll mod = 1e9+7;
const ll inf = 1e17;
const int INF = 1e9;
const double PI = acos(-1);
#define fo(i, a, b) for(int i = a; i < b; i++)
#define re(i, n) fo(i, 0, n)
#define pb push_back
#define mp make_pair
#define all(s) s.begin(), s.end()
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { ll g = gcd(a, b); return a / g * b; }
int main()
{
  int n;
  cin >> n;
  vi a(n);
  re(i, n) cin >> a[i];

  sort(all(a));
  cout << a.back() - a.front() << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define F first
#define S second
int main()
{
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    ll n, ans = 0;
    cin >> n;
    vector<ll>v[3];
    for(int i = 0;i < 3;++i)
    {
        v[i].resize(n);
        for(int j = 0;j < n;++j)
            cin >> v[i][j];
        sort(v[i].begin(), v[i].end());
    }
    for(int i = 0;i < n;++i)
    {
        ll x = lower_bound(v[0].begin(), v[0].end(), v[1][i]) - v[0].begin();
        ll y = upper_bound(v[2].begin(), v[2].end(), v[1][i]) - v[2].begin();
        y = v[2].size() - y;
        ans += x * y;
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 2560
//Author- VMAX


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_multiset tree<long long , null_type,less_equal<long long >, rb_tree_tag,tree_order_statistics_node_update>
#define ordered_set tree<long long , null_type,less<long long >, rb_tree_tag,tree_order_statistics_node_update>
using namespace std;
#define ll long long int
#define YES cout<<"YES"<<"\n";
#define NO cout<<"NO"<<"\n";
#define ld     long double 
#define yes cout<<"yes"<<"\n";
#define no cout<<"no"<<"\n";
#define No cout<<"No"<<"\n";
#define Yes cout<<"Yes"<<"\n";
#define f(i,a) for(i=0;i<a;i++)
#define fo(i,a) for(i=1;i<=a;i++)
#define fa(i,a) for(auto i:a)
#define r(i,a) for(auto i=a.rbegin();i!=a.rend();i++)
#define en cout<<"\n";
#define ull unsigned long long int
#define o(x) cout<<x<<"\n";
#define o1(x) cout<<x<<" ";
#define pb push_back
#define F first
#define in insert
#define mp make_pair
#define S second
#define pre(n) cout<<fixed<<setprecision(n);
#define      gcd(a,b)    __gcd(a,b)
#define bs            binary_search
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define test ll t;cin>>t;while(t-->0)
const ll Mod = 998244353;
#define mod 1000000007
#define pi 3.14159265358979323846
#define all(x) x.begin(),x.end()
#define re return 0;
// *#######################################################################################*

/*
bool isp(ll n)
{
    ll i;
    for(i=2;i*i<=n;i++)
    {
        if(n%i==0)
        {
            return false;
        }
        
    }
}
  */
  ll powerm(ll x, unsigned ll y, ll p)  
{  
    ll res = 1;    
  
    x = x % p; 
   
    if (x == 0) return 0;
  
    while (y > 0)  
    {  
        if (y & 1)  
            res = (res*x) % p;  
   
        y = y>>1; // y = y/2  
        x = (x*x) % p;  
    }  
    return res;  
}
  long long lcm(long long a, long long b){//最小公倍数を求める
   return a * b / gcd(a, b);
}
//ll ss[2][(1<<22)+10];
       int main()
       
       {
        fast
    
         
       ll n;
       cin>>n;
       ll a[n],i;
       f(i,n)
       {
           cin>>a[i];
       }
    ll c=0;
    for(i=1;i<n-1;i++)
    {
        if((a[i]>a[i-1]&&a[i]<a[i+1])||(a[i]<a[i-1]&&a[i]>a[i+1]))
        {
            c++;
        }
    }
    
    o(c)
    
        
       
          re
}


Measured memory_bytes: 3632
N, Y = map(int, input().split())
n_10, n_5, n_1 = -1, -1, -1

r_1 = Y % 5000 // 1000
for i in range(r_1, N+1, 5):
    M = Y - 1000 * i
    r_5 = M % 10000 // 5000
    for j in range(r_5, N+1-i, 2):
        if Y == (1000 * i + 5000 * j + 10000 * (N - i - j)):
            n_1, n_5, n_10 = i, j, N-i-j
            print(n_10, n_5, n_1)
            exit()
else:
    print(n_10, n_5, n_1)


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

typedef pair<int,int> P;
#define ll long long
#define ld long double
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
#define sz(x) ((int)(x).size())
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
#define all(x) (x).begin(),(x).end()

const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;
int main()
{
    int n;cin >> n;
    if (n % 1000==0)
    {
        cout << 0 << endl;
        return 0;
    }
    cout << 1000 - n % 1000 << endl;
}

Measured memory_bytes: 3592
from collections import deque
import sys

input = sys.stdin.buffer.readline
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))

n, d, a = MAP()
xh = [LIST() for i in range(n)]

xh = sorted(xh, key=lambda x:(x[0]))
q = deque()
ca = 0
cnt = 0
for i in range(n):
    cx, ch = xh[i][0], xh[i][1]
    
    while q and q[0][0] < cx:
        qx, qa = q.popleft()
        ca -= qa
    
    if ch - ca <= 0:
        continue
    
    cn = (ch - ca + a - 1) // a
    cnt += cn
    ca += cn * a
    q.append([cx+2*d, cn*a])
    
print(cnt)

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

const int maxn = 100;
unsigned long long g[maxn];

unsigned long long f(int n)
{
   // printf("1\n");
    if(n == 0) return 2;
    if(n == 1) return 1;
    if(g[n] != 0) return g[n];

    return g[n] = f(n - 1) + f(n - 2);
}

void init()
{
    memset(g,0,sizeof(g));
    g[1] = 1; g[0] = 2;
    f(86);
}

int main()
{
    int n;
    init();
    while(scanf("%d",&n) == 1)
    {
        printf("%lld\n",g[n]);
    }
    return 0;
}


Measured memory_bytes: 128
import math


def count_number_of_prime_number(v):
    ans = 0
    for x in v:
        if is_prime(x):
            ans += 1
    return ans


def is_prime(x):
    for n in range(2, math.floor(math.sqrt(x)) + 1):
        if x % n == 0:
            return False
    return True


n = int(input())
v = []
for i in range(n):
    v.append(int(input()))

print(count_number_of_prime_number(v))


Measured memory_bytes: 6008
n = int(input())
al = list(map(int, input().split()))
al.sort()

if n==2:
    print(al[1]-al[0])
    print(al[1],al[0])
    exit()

res = []
neg = []
pos = []
for a in al:
    if a>=0:
        pos.append(a)
    else:
        neg.append(a)

if len(pos)==0:
    res.append((neg[-1],neg[-2]))
    pos.append(neg[-1]-neg[-2])
    neg = neg[:-2]
if len(neg)==0:
    res.append((pos[0],pos[1]))
    neg.append(pos[0]-pos[1])
    pos = pos[2:]


# len(pos)>0 and len(neg)>0
n = neg[0]
for i in range(1,len(pos)):
    res.append((n,pos[i]))
    n = n - pos[i]
p = pos[0]
for i in range(1,len(neg)):
    res.append((p,neg[i]))
    p = p - neg[i]
res.append((p,n))
print(p-n)
for x,y in res:
    print(x,y)

Measured memory_bytes: 20396
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<n;i++)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define ALL(a) a.begin(),a.end()
typedef long long ll;
#define INF 1<<30
#define MOD 1000000007

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

int main()
{
    ll N;
    cin >> N;
    ll S = 0;
    S = (S + (modpow(10,N) % MOD) ) % MOD;
    S = (S - ((2*modpow(9,N)) % MOD) ) % MOD;
    if(S<0)S += MOD;
    S = (S + (modpow(8,N) % MOD) ) % MOD;
    cout << S << endl;
    return 0;
}

Measured memory_bytes: 3612
import io.StdIn._
import math._

object Main extends App {
  val n = readInt()
  val abcs = for (_ <- 1 to n) yield readLine() split(' ') map(_.toInt)

  val dp = Array.ofDim[Int](n, 3)
  dp(0) = abcs.head

  val combi = Seq((0,1), (0,2), (1,0), (1,2), (2,0), (2,1))

  for (i <- 1 until n) {
    val prev = dp(i-1)
    val just = abcs(i)
    dp(i)(0) = max(just(0)+prev(1), just(0)+prev(2))
    dp(i)(1) = max(just(1)+prev(0), just(1)+prev(2))
    dp(i)(2) = max(just(2)+prev(0), just(2)+prev(1))
  }

  println(dp.last.max)
}

Measured memory_bytes: 64124
N = int(input())
az = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
def norm(n, in_list):
	out_list = []
	for line in in_list:
		for i in range(len(set(line))+1):
			new_line = line + az[i]
			out_list.append(new_line)
	return out_list
init_line = ['a']
for _ in range(N-1):
	init_line = norm(1, init_line)
for line in init_line:
	print(line)


Measured memory_bytes: 12980
//Author ::  ABHINAV3010 ::

#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define fast ios_base::sync_with_stdio(false)
typedef long long ll;
typedef pair<ll,ll> p;
ll mod=1000000007;
ll gcd(ll a,ll b)
{
    return (b==0)?a:gcd(b,a%b);
}
int main()
{
fast;
ll n;
cin>>n;
vector<ll>v;
for(ll i=0;i<n;i++)
{
    ll a;
    cin>>a;
    v.pb(a);
}
sort(v.begin(),v.end());
ll x=n/2;
ll a=v[x-1];
ll b=v[x];
ll ans=b-a;
cout<<ans<<endl;

return 0;
}


Measured memory_bytes: 1400
import collections
import math
import operator as op
from functools import reduce

import numpy as np
import math
from bisect import bisect


def main():
    N = int(input())
    L = list(map(int, input().split()))

    L.sort()
    # M = [L[i] + L[j] for i in range(N) for j in range(i+1, N)]
    # M.sort()

    ans = 0
    for i in range(N-2):
        for j in range(i+1, N-1):

            ans += bisect(L,L[i]+L[j]-1)-j-1

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 12488
import sys
import numpy as np

input = sys.stdin.readline
N, L, T = map(int, input().split())
XW = [tuple(map(int, input().split())) for _ in range(N)]
X = np.array([x for x, w in XW], dtype=int)
W = np.array([(w%2)*2-1 for x, w in XW], dtype=int)
X += W*T
cnt = np.sum(X//L)%N
X %= L
X = sorted(X)
print('\n'.join(map(str, X[cnt:])))
print('\n'.join(map(str, X[:cnt])))


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

#define pout(n)  printf ("%d\n", n)

#define rep(i,a,n) for (int i = a;i < n;i++)
#define per(i,n,a) for (int i = n-1;i >= a;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());

const int d4x[4] = {1, 0, -1, 0};
const int d4y[4] = {0, 1, 0, -1};
const int d8x[8] = { 1,1,0,-1,-1,-1,0,1 };
const int d8y[8] = { 0,1,1,1,0,-1,-1,-1 };

#define MAX_N (int)2e5+20
#define INF 1e12+20

typedef long long ll;
using namespace std;

string s;
int main() {
	cin >> s;
	bool ans = false;
	rep(i,0,s.size()){
		if(s[i] == 'C'){
			rep(j,i,s.size()){
				if(s[j] == 'F') ans = true;
			}
		}
	}
	if(ans == true) printf("Yes\n");
	else printf("No\n");
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
    int i,j,n,s,count=0;
    scanf("%d",&n);
    int A[n];
    for(i=0;i<n;i++) scanf("%d",&A[i]);
    for(i=0;i<n;i++){
     for(j=n-1;j>=1;j--){
      if(A[j] < A[j-1]){
          count++;
          s = A[j-1];
          A[j-1] = A[j];
          A[j] = s;
      }
     }
    }
    for(i=0;i<n-1;i++) printf("%d ",A[i]);
    printf("%d\n%d\n",A[n-1],count);
    return 0;
}




Measured memory_bytes: 2128
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        StringBuilder str = new StringBuilder(sc.nextLine());
        int n = sc.nextInt();
        for (int i = 0; i < n; i++) {
            String com = sc.next();
            int a = sc.nextInt();
            int b = sc.nextInt()+1;
            if ("replace".equals(com)) {
                String str2 = sc.next();
 
                str = str.replace(a,b, str2);
            } else if ("reverse".equals(com)) {
 
                StringBuilder temp  = new StringBuilder(str.substring(a, b));
                temp.reverse();
                str.replace(a, b, temp.toString());
 
            } else if ("print".equals(com)) {
 
                System.out.println(str.substring(a, b));
            }
        }
        sc.close();
    }
    
}

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

const int maxN = 5e5 + 10, mod = 998244353;

int n, m;
int fac[maxN + 1], inv[maxN + 1];

inline int ADD(int x, int y) { return x + y >= mod ? x + y - mod : x + y; }

inline int SUB(int x, int y) { return x - y < 0 ? x - y + mod : x - y; }

inline int mpow(int a, int x)
{
	int ans = 1;
	while(x)
	{
		if(x & 1) ans = 1ll * ans * a % mod;
		a = 1ll * a * a % mod;
		x >>= 1;
	}
	return ans;
}

inline int C(int n, int m)
{
	if(n < m) return 0;
	return 1ll * fac[n] * inv[m] % mod * inv[n - m] % mod;
}

int main()
{
	scanf("%d %d", &n, &m);
	int lim = max(n, m), ans = 0;

	fac[0] = 1;
	for(int i = 1; i <= lim; i++) fac[i] = 1ll * fac[i - 1] * i % mod;
	inv[lim] = mpow(fac[lim], mod - 2);
	for(int i = lim - 1; i >= 0; i--) inv[i] = 1ll * inv[i + 1] * (i + 1) % mod;

	lim = min(n, m);
	for(int i = 0; i <= lim; i++)
	{
		int res = 1ll * C(n, i) * C(m, i) % mod * fac[i] % mod * mpow(n + 1, m - i) % mod * mpow(m + 1, n - i) % mod;
		ans = (i & 1) ? SUB(ans, res) : ADD(ans, res);
	}

	printf("%d", ans);
	return 0;
}


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

int main() {
    int n;
    cin >> n;
    ll a[n];
    rep(i, n) cin >> a[i];
    sort(a, a + n);

    ll maxv = a[n - 1];
    double half = maxv / 2.0;
    auto iter = lower_bound(a, a + n, half);
    int idx = distance(a, iter);

    ll r = a[idx];
    double error = abs(half - r);
    if (idx - 1 >= 0 && error > abs(half - a[idx - 1])) r = a[idx - 1];
    if (idx + 1 < n && error > abs(half - a[idx + 1])) r = a[idx + 1];
    if (r == maxv) r = a[idx - 1];

    cout << maxv << ' ' << r << endl;
    return 0;
}


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

multiset<int> edge[100005];
int memo[100005]={};

void dfs(int now)
{
	for (auto i = edge[now].begin(); i != edge[now].end(); ++i)
	{
		if (memo[*i]==0)
		{
			memo[*i]=1;
			dfs(*i);
		}
	}
}

int main(int argc, char const *argv[])
{
	int n,m;
	cin>>n>>m;
	int x,y,z;
	for (int i = 0; i < m; ++i)
	{
		cin>>x>>y>>z;--x;--y;
		edge[x].insert(y);
		edge[y].insert(x);
	}
	int ans=0;
	for (int i = 0; i < n; ++i)
	{
		if(memo[i]==0)
		{
			memo[i]=1;
			++ans;
			dfs(i);
		}
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 17792
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*);
    }
}

#[allow(unused_imports)]
use std::cmp::{min, max};
#[allow(unused_imports)]
use std::io::{stdout, stdin, BufWriter, Write};

fn main() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($($format:tt)*) => (writeln!(out,$($format)*).unwrap());
    }

    input!{
      n: usize,
    }
    if n <= 2 {
        return puts!("{}", "No");
    }
    let mut tmp = 1;
    while tmp*2 <= n {
        tmp *= 2;
    }
    if tmp == n {
        return puts!("{}", "No");
    }

    use std::collections::HashSet;
    let mut set = HashSet::new();

    let mut ans = vec![];
    ans.push((3, 1+n));
    for i in 1..(n-1)/2+1 {
        let a = i*2;
        let b = i*2+1;
        ans.push((1, a));
        ans.push((a, b));
        ans.push((1, b+n));
        ans.push((b+n, a+n));

        set.insert(a);
        set.insert(b+n);
    }

    if n%2 == 0 {
        let mut a = 1;
        while a*2 < n {
            a *= 2;
        }
        let b = n^a^1;

        if set.contains(&a) {
            ans.push((a, n));
        } else {
            ans.push((a+n, n));
        }

        if set.contains(&b) {
            ans.push((b, n+n));
        } else {
            ans.push((b+n, n+n));
        }
    }

    puts!("{}", "Yes");
    for a in ans {
        puts!("{} {}", a.0, a.1);
    }
}


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

using namespace std;

typedef long long ll;

long long GCD(long long a, long long b){if(b==0)return a;return GCD(b,a%b);}

int main() {
    int C[3][3];
    for (int i = 0; i < 3; i++) {
        for (int j = 0; j < 3; j++) cin >> C[i][j];
    }

    int a[3], b[3];
    a[0] = 0;
    b[0] = C[0][0] - a[0];
    b[1] = C[0][1] - a[0];
    b[2] = C[0][2] - a[0];
    a[1] = C[1][0] - b[0];
    a[2] = C[2][0] - b[0];

    bool is_correct = true;

    for (int i = 0; i < 3; i++) {
        for (int j = 0; j < 3; j++) is_correct &= C[i][j] == a[i] + b[j];
    }
    if (is_correct) cout << "Yes" << endl;
    else cout << "No" << endl;

}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**9)
N=int(input())
T=[[] for _ in range(N)]
for i in range(N-1):
  a,b,c=map(int, input().split())
  T[a-1].append((b-1,c))
  T[b-1].append((a-1,c))
Q,K=map(int, input().split())

dist=[-1]*N
dist[K-1]=0

def dfs(start, nown):
  to=T[start]
  for t in to:
    next_node,c=t
    if dist[next_node]!=-1:
      continue
    nextn=nown+c
    dist[next_node]=nextn
    dfs(next_node, nextn)

dfs(K-1,0)
for i in range(Q):
  x,y=map(int, input().split())
  print(dist[x-1]+dist[y-1])

Measured memory_bytes: 135960
use std::io;
use std::cmp;

// read a line(without line feed)
fn read_line() -> String {
    let mut in_str = String::new();
    io::stdin().read_line(&mut in_str).unwrap();
    return in_str.trim().to_string();
}

// read wods on a line
pub fn read_words_in_line() -> Vec<String> {
    let s = read_line();
    return s.split_whitespace().map(|x| x.to_string()).collect::<Vec<String>>()
}

// read type t on a line
pub fn read_t_in_line<T : std::str::FromStr>() -> Vec<T> {
    let mut v : Vec<T> = Vec::new();
    for e in read_words_in_line().iter().map(|x| x.parse::<T>()) {
        if let Ok(r) = e {
            v.push(r);
        }
        else{
            return Vec::new();
        }
    }
    return v;
}

// sort slice
pub fn sort<T : std::cmp::Ord>(slice : &mut [T]) {
    slice.sort();
}
// sort slice by reverse order
pub fn sort_rev<T : std::cmp::Ord>(slice : &mut [T]) {
    slice.sort_by(|x, y| y.cmp(x));
}

pub fn min<T : std::cmp::Ord>(a : T, b : T) -> T{
    return cmp::min(a, b);
}

pub fn max<T : std::cmp::Ord>(a : T, b : T) -> T{
    return cmp::max(a, b);
}



fn main() {

    const UNRESTORABLE : &'static str = "UNRESTORABLE";

    let s = read_line().into_bytes();
    let t = read_line().into_bytes();

    if s.len() < t.len() {
        println!("{}", UNRESTORABLE);
    }
    else{
        let mut res = vec![];

        for i in (0..(s.len() - t.len()) + 1).rev() {
            let mut ok = true;
            for j in 0..t.len() {
                if !(s[i + j] == '?' as u8 || s[i + j] == t[j]) {
                    ok = false;
                }
            }
            if ok {
                let mut v = vec![];
                
                for j in 0..s.len() {
                    if j >= i && j - i < t.len() {
                        v.push(t[j - i]);
                    }
                    else if s[j] == '?' as u8 {
                        v.push('a' as u8);
                    }
                    else{
                        v.push(s[j]);
                    }
                }
                res.push(v);
            }
        }

        if res.len() == 0 {
            println!("{}", UNRESTORABLE);
        }
        else{
            res.sort();
            for r in &res[0] {
                print!("{}", *r as char);
            }
            println!("");
        }
    }
}


Measured memory_bytes: 4352
n = gets.chomp

puts 'hon' if n[-1].to_i == 2 || n[-1].to_i == 4 || n[-1].to_i == 5 || n[-1].to_i == 7 || n[-1].to_i == 9
puts 'pon' if n[-1].to_i == 0 || n[-1].to_i == 1 || n[-1].to_i == 6 || n[-1].to_i == 8
puts 'bon' if n[-1].to_i == 3

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

using namespace std;

#define ll long long
#define ull unsigned long long
#define PI acos(-1.0)
#define eps 1e-12
#define fi first
#define se second
#define MEM(a,b) memset((a),(b),sizeof(a))
#define mod(x) ((x)%MOD)
#define pii pair<int,int>


const int maxn = 4e5 + 10, INF = 0x3f3f3f3f;
const ll MOD = 1000000007LL;
const int Move[4][2] = {-1,0,1,0,0,1,0,-1};
const int Move_[8][2] = {-1,-1,-1,0,-1,1,0,-1,0,1,1,-1,1,0,1,1};

inline int read(){
    int x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}

ll a[maxn];
ll p[maxn];

int main(){
//    freopen("C:\\Users\\Administrator\\Desktop\\in.txt","r",stdin);
//    freopen("C:\\Users\\Administrator\\Desktop\\out.txt","w",stdout);
    ll n; cin>>n;
    bool flg = false;
    for (int i = 0; i < n; i++) {
        cin>>a[i];
        if (i == 0) continue;
        if (a[i] - a[i - 1] > 1) flg = true;
    }
    if (flg || a[0]) puts("-1");
    else {
        ll res = 0;
        ll r = 0;
        ll g = 0;
        for (ll i = n - 1; i >= 0; i--) {
            if (a[i]) {
                if (g < a[i]) {
                    res += a[i];
                    g = a[i] - 1;
                } else g = a[i] - 1;
            }
        }
        cout<<res<<endl;
    }



    return 0;
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<algorithm>
#include<iostream>
using namespace std;

int main()
{
	long long int a,b,k;
	scanf("%lld %lld %lld",&a,&b,&k);
	for(int i = 1; i <= k; i++){
	if((i + 2)%2 != 0){
		    a = a/2;
		    b = b + a;
     	}
    else{
    	b = b/2;
    	a = a + b;
	     }   
	}
	printf("%lld %lld\n",a,b);
}


Measured memory_bytes: 256
import java.io.*;
import java.util.*;
class Program{
    char[] change(char c[]){
        char temp = '\0', chng = c[c.length-1];
        for(int i = 0;i<c.length;i++){
            temp = c[i];
            c[i] = chng;
            chng = temp;
        }
        return c;
    }
}
class Main{
    public static void main(String args[])throws IOException{
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        Program obj = new Program();
        String S = in.readLine(), T = in.readLine();
        char s []= S.toCharArray(), t[] = T.toCharArray();
        boolean flag = false;
        for(int i=0;i<s.length;i++){
            //System.out.println(Arrays.toString(obj.change(s)));
            if (Arrays.toString(obj.change(s)).equals(Arrays.toString(t))){
                flag = true;
                break;
            }
        }
        if (flag) System.out.println("Yes");
        else System.out.println("No");
    }
}

Measured memory_bytes: 22100
using System;
using System.Collections.Generic;
class Program
{
	static void Main(string[] args)
	{
		int N = int.Parse(Console.ReadLine());
		int[]A = new int[N];
		for(var i=1;i<=100;i++){
			for(var j=1;j<=100;j++){
				for(var k=1;k<=100;k++){
					int a = i*i+j*j+k*k+i*j+j*k+k*i;
					if(a>=1 && a<=N){
						A[a-1]++;
					}
				}
			}
		}
		for(var i=0;i<N;i++){
			Console.WriteLine(A[i]);
		}
	}
}

Measured memory_bytes: 17876
#include<iostream>
#include<stdio.h>
#include<math.h>
using namespace std;
int main()
{
    double x1,y1,x2,y2,x3,y3;
    int n;cin>>n;
    while(n--)

    {
        cin>>x1>>y1>>x2>>y2>>x3>>y3;
         double  d1 = x1*x1+y1*y1;
      double  d2 = x2*x2+y2*y2;
      double  d3 = x3*x3+y3*y3;
      double  u = 0.5/(x1*y2-x2*y1+x2*y3-x3*y2+x3*y1-x1*y3);
      double  xp = u*(d1*y2-d2*y1+d2*y3-d3*y2+d3*y1-d1*y3);
      double  yp = u*(x1*d2-x2*d1+x2*d3-x3*d2+x3*d1-x1*d3);
      double  r = sqrt((xp-x1)*(xp-x1)+(yp-y1)*(yp-y1));
      printf("%.3f %.3f %.3f\n",xp,yp,r);
    }



    return 0;
}

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

int main() {
    int n; cin >> n;
    int t, a; cin >> t >> a;
    vector<int> h(n); 
    for (int i = 0; i < n; i++) cin >> h[i];

    double num = 100000;
    int ans = 0;
    for (int i = 0; i < n; i++) {
        if (num > abs(a - (t - h[i] * 0.006))) ans = i + 1;
        num = min(num, abs(a - (t - h[i] * 0.006)));
    }

    cout << ans << endl;
    return 0;
}


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

string s;

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

	cin >> s;

	for (int i = s.size()-1; i >= 0; i--) {
		if (i+1 >= 5 && s.substr(i-4, 5) == "dream") {
			i -= 4;
		}
		else if (i+1 >= 7 && s.substr(i-6, 7) == "dreamer") {
			i -= 6;
		}
		else if (i+1 >= 5 && s.substr(i-4, 5) == "erase") {
			i -= 4;
		}
		else if (i+1 >= 6 && s.substr(i-5, 6) == "eraser") {
			i -= 5;
		}
		else {
			cout << "NO\n";
			return 0;
		}
	}

	cout << "YES\n";

	return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)

struct Student {
	int num;
	int pri;
};

bool f(const Student& s1, const Student& s2) {
	return s1.pri < s2.pri;
}


int main() {
	int N;
	cin >> N;
	vector<Student> A(N);
	rep(i, N) {
		A[i].num = i + 1;
		cin >> A[i].pri;
	}
	sort(A.begin(), A.end(), f);
	rep(i, N) {
		cout << A[i].num << " ";
	}
	cout << endl;
}

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

int main() {
	int n, q;
	cin >> n;
	vector<int> S(n);
	for (int i = 0; i < n; i++) cin >> S[i];
	cin >> q;
	vector<int> T(q);
	for (int i = 0; i < q; i++) cin >> T[i];
	sort(S.begin(), S.end());

	int ans = 0;
	for (int i = 0; i < q; i++) {
		int left = 0, right = n, center;
		while (left < right) {
			center = (left + right) / 2;
			if (T[i] == S[center]) {
				ans++; break;
			}
			else if (T[i] < S[center]) {
				right = center;
			}	
			else {
				left = center + 1;
			}
		}
	}
	cout << ans << endl;
}



Measured memory_bytes: 3280