akhauriyash/Code-Regression huggingface dataset:
//Written by Zhu Zeqi
//Come on,baby
//Hack,please
#include<cmath>
#include<math.h>
#include<ctype.h>
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<ciso646>
#include<climits>
#include<clocale>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<cwchar>
#include<cwctype>
#include<deque>
#include<exception>
#include<fstream>
#include<functional>
#include<iomanip>
#include<ios>
#include<iosfwd>
#include<iostream>
#include<istream>
#include<iterator>
#include<limits>
#include<list>
#include<locale>
#include<map>
#include<memory>
#include<new>
#include<numeric>
#include<ostream>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<stdexcept>
#include<streambuf>
#include<string>
#include<typeinfo>
#include<utility>
#include<valarray>
#include<vector>
#include<string.h>
#include<stdlib.h>
#include<stdio.h>
#define CLR(x) memset(x,0,sizeof x)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define pii pair<int,int>
#define vi vector<int>
#define MAX 100000000000000000
#define MOD 1000000007
#define PI 3.141592653589793238462
#define INF 1000000000
typedef long long ll;
//orz yht
using namespace std;
string i_s(int x){
	if(x==0)
	return "0";
	string ret="";
	while(x){
		ret=ret+(char)(x%10+'0');
		x/=10;
	}
	reverse(ret.begin(),ret.end());
	return ret;
}
string add(string a,string b){
	if(a=="")
	a="0";
	if(b=="")
	b="0";
	if(a.length()<b.length())
	swap(a,b);
	while(b.length()<a.length()){
		b='0'+b;
	}
	for(int i=0;i<a.length();i++){
		a[i]=a[i]+(b[i]-'0');
	}
	bool big=false;
	for(int i=a.length()-1;i>=0;i--){
		if(big){
			a[i]++;
		}
		big=false;
		if(a[i]>'9'){
			a[i]=a[i]-10;
			big=true;
		}
	}
	if(big)
	a='1'+a;
	return a;
}
string mul(string a,string b){
	vector<int> va,vb;
	if(a=="0" || b=="0")
	return "0";
	string ans;
	for(int i=0;i<a.length();i++){
		va.push_back(a[i]-'0');
	}
	for(int i=0;i<b.length();i++){
		vb.push_back(b[i]-'0');
	}
	reverse(va.begin(),va.end());
	reverse(vb.begin(),vb.end());
	vector<int> res;
	res.clear();
	res.resize(1005);
	for(int i=0;i<a.length();i++){
		for(int j=0;j<b.length();j++){
			res[i+j]+=(va[i]*vb[j]);
		}
	}
	for(int i=0;i<1005;i++){
		if(res[i]>9){
			res[i+1]+=(res[i]/10);
			res[i]%=10;
		}
	}
	for(int i=0;i<1005;i++){
		ans+=(res[i]+'0');
	}
	reverse(ans.begin(),ans.end());
	int k=0;
	while(ans[k]=='0'){
		k++;
	}
	ans=ans.substr(k);
	return ans;
}
bool is_prime(int n){
	if(n<2)
    return false;
    for(int i=2;i*i<=n;i++)
    if(n%i==0)
    return false;
    return true;
}
int main(){
	//freopen("input.in","r",stdin);
	//freopen("output.out","w",stdout);;
	int n;
	cin>>n;
	cout<<"ABC"<<n; 
	//system("pause");
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h> 
using namespace std; 
  
// Function to find that number divisible by 9 or not 
int check(string str) 
{ 
    // Compute sum of digits 
    int n = str.length(); 
    int digitSum = 0; 
    for (int i=0; i<n; i++) 
        digitSum += (str[i]-'0'); 
  
    // Check if sum of digits is divisible by 9. 
    return (digitSum % 9 == 0); 
} 
  
// Driver code 
int main() 
{ 
    string str;
  cin>>str;
    check(str)?  cout << "Yes\n" : cout << "No\n"; 
    return 0; 
} 

Measured memory_bytes: 3776
#include<bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#include <ext/pb_ds/assoc_container.hpp>

#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

using namespace __gnu_pbds;
#define lli long long int
#define ulli unsigned long long int
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define pf pop_front()
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
#define loopl(i,a,b) for(lli i=a;i<b;i++) 
#define loop(i,a,b) for(int i=a;i<b;i++)
#define mod 1000000007
#define mo 998244353
#define inf 1000000000000000
#define lld long double
#define pll pair<long long int,long long int>
#define vll vector<lli>
#define eps 0.000001
#define ms 16
#define endl '\n'

 
using namespace std ;
 
#define N 400005

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


int main()
{
    
///////////////////////////////////////////
    fastio;

    string s;
    cin>>s;

    lli cnt=0,ans=0;
    loopl(i,0,s.size()-1)
    {
        if(s[i] == 'A') cnt++;
        else
        {
            if(s[i] == 'B' && s[i+1] == 'C')
            {
                ans+=cnt;
                i++;
            }

            else
                cnt=0;
        }

    }

    cout<<ans;

}

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

using namespace std;

const int N = 1e5 + 100;

int a[110];

bool dp[N];

int main() {
	int n, k;
	cin >> n >> k;
	for (int i = 0; i < n; ++i)
		cin >> a[i];
	for (int i = 0; i <= k; ++i)
		for (int j = 0; j < n; ++j)
			if (i - a[j] >= 0 && dp[i - a[j]] == false) {
				dp[i] = true;
				break;
			}
	if (dp[k])
		cout << "First\n";
	else
		cout << "Second\n";
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
using ll=long long;
using P = pair<int,int>;
int main(){
    ll N;
    ll MOD = 1000000007;
    cin >> N;
    ll A[N];
    ll sum =0;
    for(ll i=0;i<N;i++){
        cin >> A[i];
        sum=(sum+A[i])%MOD;
    }
    ll ans =0;
    for(ll i=0;i<N-1;i++){
        sum=(sum-A[i]+MOD)%MOD;
        ll a = (A[i]*sum)%MOD;
        ans=(ans+a)%MOD;
    }
    cout << ans << endl;
}


Measured memory_bytes: 5176
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstring>
#include <cctype>
#include <cassert>
#include <limits>
#include <functional>
#include <iomanip>
#include <complex>
#include <bitset>
#include <stack>
 
using namespace std;
 
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define repl(i,s,n) for(int i=s; i<=n; ++i)
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
#if defined(_MSC_VER) || __cplusplus > 199711L
#define aut(r,v) auto r = (v)
#else
#define aut(r,v) __typeof(v) r = (v)
#endif
#define each(it,o) for(aut(it, (o).begin()); it != (o).end(); ++ it)
#define ktya(x) sort(all(x))
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define all(o) (o).begin(), (o).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 INF 1000000007
#define INFLL 1000000000000000007LL
#define SIZE 200105
#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define mind(a,b) (a>b?b:a)
#define maxd(a,b) (a>b?a:b)

typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pair<int, int> > vpii; typedef long long ll;
typedef pair<int,ll> pill; typedef pair<ll,int> plli; 
typedef pair<double, int> pdi;
template<typename T, typename U> inline void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if(x < y) x = y; }
typedef complex<double> P;
ll MOD = 1000000007;
//ll MOD=998244353;
typedef ll Weight;
struct Edge {
	int src, dst;
	Weight weight;
};
bool operator < (const Edge &e, const Edge &f) {
	return e.weight != f.weight ? e.weight > f.weight : // !!INVERSE!!
	e.src != f.src ? e.src < f.src : e.dst < f.dst;
}
typedef vector<Edge> Edges;

ll M;
double N,d,x;
double ans=0.0;
int main(){
	cin>>M>>d>>x;
	N = (double)M;
	rep(i,M){
		
		ans+=d+(double)((2*N-1)/2)*x;
		d=(double)((2*N+2)*d/(2*N)) + 5*x/(2*N);
		x=x+(2*x)/N;
		N-=1.0;
	}
	printf("%.9lf\n",ans);
}

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

#define BR "\n"

int main() {
  int A1, A2, A3;
  cin >> A1 >> A2 >> A3;

  int ans = max(abs(A1-A2), abs(A2-A3));
  ans = max(ans, abs(A3-A1));
  ans = abs(A1-A2)+abs(A2-A3)+abs(A3-A1)-ans;

  cout << ans;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;
int n,a[200005],t,r,ans;
long long sum;
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
		cin>>a[i];
	t=1;
	ans=0;
	for(int r=1;r<=n;r++)
 	{
	 	while(ans & a[r])
   		{
  			ans^=a[t];
  			t++;
		}
		ans^=a[r];
		sum+=r-t+1;
  	}
	cout<<sum;
	//system("pause");
	return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<sstream>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<complex>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cassert>

#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define mp make_pair
#define pb push_back
#define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define dbg(x) cerr<<__LINE__<<": "<<#x<<" = "<<(x)<<endl

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
const int inf = (int)1e9;
const double INF = 1e12, EPS = 1e-9;

const int dy[] = {1, 0, -1, -1, -1, 0, 0}, dx[] = {0, 1, 1, 0, -1, -1, 0};
int sx, sy, gx, gy, n, lx, ly;
bool ob[300][300], v[300][300][6];

int main(){
	cin >> sx >> sy >> gx >> gy >> n;
	rep(i, n){
		int x, y;
		cin >> x >> y;
		ob[x + 150][y + 150] = 1;
	}
	cin >> lx >> ly;
	
	priority_queue<pair<pi, pi> > q;
	q.push(mp(mp(0, 0), mp(sx, sy)));
	while(!q.empty()){
		int x = q.top().second.first, y = q.top().second.second;
		int t = -q.top().first.second, co = q.top().first.first;
		assert(abs(x) <= lx && abs(y) <= ly);
		q.pop();
		if(v[x + 150][y + 150][t % 6]) continue;
		v[x + 150][y + 150][t % 6] = 1;
		
		if(x == gx && y == gy){
			cout << -co << endl;
			return 0;
		}
		int dd = abs(x * y * t) % 6;
		rep(d, 7){
			int nx = x + dx[d], ny = y + dy[d];
			if(dx[d] && x % 2) ny++;
			if(lx < abs(nx) || ly < abs(ny) || ob[nx + 150][ny + 150]) continue;
			q.push(mp(mp(co - (d != dd), -t - 1), mp(nx, ny)));
		}
	}
	cout << -1 << endl;
	return 0;
}

Measured memory_bytes: 2120
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <functional>
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000
#define int long long
vector<int> enum_div(int n)//nの約数を列挙
{
	vector<int> ret;
	for(int i=1 ; i*i<=n ; ++i)
	{
		if(n%i == 0)
		{
			ret.push_back(i);
			if(i*i!=n)
			{
				ret.push_back(n/i);
			}
		}
	}
	return ret;
}
typedef pair<int, int> P;
signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, K;
    cin >> N >> K;
    int A[510];
    rep(i, N) cin >> A[i];
    int sum = 0;
    rep(i, N) sum += A[i];
    int ans = 1;
    vector<int> v = enum_div(sum);
    for(auto& e: v) {
        vector<P> cost;
        int sumL = 0, sumH = 0;
        rep(i, N) {
            int H = A[i] % e;
            int L = e - A[i] % e;
            //cout << A[i] << " " << e << " " << H << " " << L << endl;
            cost.push_back({L, H});
            sumL += L;
        }
        bool ok = false;
        int c = INF;
        sort(cost.begin(), cost.end(), greater<P>());
        rep(i, N) {
            if(max(sumL, sumH) <= K) ok = true;
            c = min(c, max(sumL, sumH));
            sumL -= cost[i].first;
            sumH += cost[i].second;
        }
        if(ok) ans = max(ans, e);
        //cout << "*" << e << " " << c << endl;
    }
    cout << ans << endl;


    return 0;
}


Measured memory_bytes: 256
a, b = gets.split.map(&:to_i)
 
#f(0,a)を求める
def f(a)
  sum = 0
  i = 0
  #各桁の1の数を数える
  while (i < a.bit_length) do
    cnt = 0
    #周期2**(i+1)→一応ビット演算しとく
    cycle = 1 << (i+1)
    #周期内の1の数を数える
    cnt += (a+1)/cycle * cycle/2
    #はみ出た分を足す
    rest = (a+1)%cycle - cycle/2
    cnt += rest if rest > 0
    #1の数が奇数ならその桁にビットを立てる
    if (cnt%2 == 1) then
      sum += 1 << i
    end
    i += 1
  end
  return sum
end
#f(a,b) = f(0,a-1)^f(0,b)
puts f(a-1)^f(b)

Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
int power(int num)
{
    int p=1;
    for(int i=0;i<num;i++)p*=10;
    return p;
}
int main() {
    int n,m,a[3]={15,3,5};
    while(cin>>m>>n,n,m){
        string str,fb[3]={"FizzBuzz","Fizz","Buzz"};
        bool player[1000]={};
        for(int i=1,now=0,out=m;i<=n;i++,now=(now+1)%m){
			cin>>str;
			if(out>1){
				int num=0,co=-1;
				while(player[now])now=(now+1)%m;
				for(int j=0;j<3&&co<0;j++)if(i%a[j]<1)co=j;
				if(co<0)for(int j=0;j<str.size();j++)num+=(str[j]-'0')*power(str.size()-1-j);
				if(co>-1&&str!=fb[co]||co<0&&i!=num)player[now]=1;
				if(player[now])out--;
			}
		}
		for(int i=0,co=0;i<m;i++){
			if(!player[i]&&co>0)cout<<" ";
			if(!player[i]){
				cout<<i+1;
				co++;
			}
		}
		cout<<endl;
	}
}

Measured memory_bytes: 1220
import math
from math import gcd
INF = float("inf")

import sys
input=sys.stdin.readline
import itertools

def main():
    s = list(input().rstrip())
    n = len(s)
    h = n//2
    f = s[:h]
    l = s[h+1:]
    if s == s[::-1] and f == f[::-1] and l == l[::-1]:
        print("Yes")
    else:
        print("No")

if __name__=="__main__":
    main()


Measured memory_bytes: 62432
#pragma warning(disable:4996)
#include <iostream>
#include <stdio.h>
using namespace std;

int main()
{
	int N, cnt = 0, flag = 0;
	scanf("%d", &N);
	for (int i = 1; i <= N; i++)
	{
		int d1, d2;
		scanf("%d%d", &d1, &d2);
		if (d1 == d2)
			cnt++;
		else
			cnt = 0;
		if (cnt == 3)
			flag = 1;
	}
	if (flag == 1)
		printf("Yes");
	else
		printf("No");
}

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

int main(void){
    vector<int>a(3);
    int s = 0;
    for(int i = 0;i < 3;i++){
          cin >> a[i];
          s += a[i];
    }
    sort(a.begin(),a.end());
    int t = a[2] * 3;
    int ans = (t - s) / 2 + (t - s) % 2 * 2;
    cout << ans << endl;
}


Measured memory_bytes: 3564
#include<stdio.h>
int a[109];
int main(){
int n,m,p,i,j,tem;
   scanf("%d",&n);
   for(i=0;i<n;i++){
    scanf("%d",&a[i]);
   }
   for(i=1;i<=n;i++){
        for(j=0;j<n-1;j++){
        printf("%d ",a[j]);
    }
   printf("%d\n",a[n-1]);
    for(j=0;j<i;j++){
     if(a[j]>a[i]){
          tem=a[i];
          for(p=i;p>j;p--){
           a[p]=a[p-1];
          }
          a[j]=tem;
          break;
     }
    }
   }
return 0;
}

Measured memory_bytes: 2752
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string a;
    
    cin>>a;
    
	int kkk=0;  
    
	for(int i=0;i<a.size();i++)
	{
        if(a[i]=='C')
		{
            kkk=1;
        }
        if(a[i]=='F'&&kkk==1)
		{
            cout<<"Yes";
            
            return 0;
        }
    }
    
	cout<<"No";
    
	return 0;
}

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

bool check[64];

int main() {
	int a, b, c;
	cin >> a >> b >> c;
	bool t = false;
	int now = 0;
	int ans = 0;
	while(1){
		if(t){
			now = (now + b) % 60;
			ans += b;
		}
		else{
			if(check[now]){
				cout << "-1" << endl;
				return 0;
			}
			check[now] = true;
			if(now > c){
				if(now <= c + 60 && c + 60 <= now + a){
					cout << ans + (c + 60 - now) << endl;
					return 0;
				}
			}
			else{
				if(now <= c && c <= now + a){
					cout << ans + (c - now) << endl;
					return 0;
				}
			}
			now = (now + a) % 60;
			ans += a;
		}
		t = !t;
	}
	return 0;
}

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

#define debug(x) cerr << "-------- [ " << (#x) << " ] = " << x << endl
//#define bjq

using namespace std;

const int N = 10;

bool f[N][N];
int n, m, k; 
bool row[N], col[N];

long long res = 0;

inline bool bjq() {
	bool p[N][N];
	memcpy(p, f, sizeof(f));
	for (int i = 1; i <= n; i++)
		if (row[i]) for (int j = 1; j <= m; j++) 
			p[i][j] = 0;
	for (int i = 1; i <= m; i++)
		if (col[i]) for (int j = 1; j <= n; j++)
			p[j][i] = 0;
	int pl = 0;
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= m; j++)
			pl += p[i][j];
	/*
	if (pl == k) {
		cout << "-----\n";
		for (int i = 1; i <= n; i++)
			if (row[i]) cout << i << " ";
		cout << endl;
		for (int i = 1; i <= m; i++)
			if (col[i]) cout << i << " ";
		cout << endl;
		for (int i = 1; i <= n; i++, putchar('\n'))
			for (int j = 1; j <= m; j++)
				cout << p[i][j];
	}
	*/
	return pl == k;
}

inline void ddfs(int dep) {
	if (dep > m) {
		res += bjq();
		return;
	}
	col[dep] = 1;
	ddfs(dep + 1);
	col[dep] = 0;
	ddfs(dep + 1);
}

inline void dfs(int dep) {
	if (dep > n) {
		ddfs(1);
		return;
	}
	row[dep] = 1;
	dfs(dep + 1);
	row[dep] = 0;
	dfs(dep + 1); 
}

int main() {
#ifdef bjq
	freopen(".in", "r", stdin);
	freopen(".out", "w", stdout);
#endif
	
	cin >> n >> m >> k;
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= m; j++) {
			char c;
			cin >> c;
			f[i][j] = c == '#';
		}
	dfs(1);
	cout << res << endl;

	return 0;
}



Measured memory_bytes: 3644
#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
    int i;
    vector<int> W;
    vector<int> K;

    for (i=0;i<10;i++) {
        int k;

        scanf("%d", &k);
        W.push_back(k);
    }

    
    for (i=0;i<10;i++) {
        int k;

        scanf("%d", &k);
        K.push_back(k);
    }

    sort(W.begin(), W.end());
    sort(K.begin(), K.end());

    printf("%d %d\n", W[9] + W[8] + W[7], K[9] + K[8] + K[7]);
}

Measured memory_bytes: 1048
#include <bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;

int H, W;

bool check(int i, int j, int dx, int dy, vector<vector<int>> &field) {
    int x = i + dx;
    int y = j + dy;
    return (x >= 0 && x < H && y >= 0 && y < W && (field[x][y] == -1));
}

int main() {
    cin >> H >> W;
    vector<vector<int>> field(H, vector<int>(W));
    int white = 0;
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            char c; cin >> c;
            if (c == '.') {
                field[i][j] = -1;
                white++;
            }
            else field[i][j] = -2;
        }
    }
    vector<int> dx = {-1, 1, 0, 0};
    vector<int> dy = {0, 0, -1, 1};
    field[0][0] = 0;
    queue<pii> que;
    que.push({0, 0});
    while (!que.empty()) {
        int i = que.front().first;
        int j = que.front().second;
        que.pop();
        if (i == (H - 1) && j == (W - 1)) {
            cout << white - field[H-1][W-1] - 1 << endl;
            return 0;
        }
        for (int k = 0; k < 4; k++) {
            if (check(i, j, dx[k], dy[k], field)) {
                que.push({i + dx[k], j + dy[k]});
                field[i + dx[k]][j + dy[k]] = field[i][j] + 1;
            }
        }
    }
    cout << -1 << endl;
}

Measured memory_bytes: 3596
#include<bits/stdc++.h>
using namespace std;
#define Set(a,b) memset(a,b,sizeof(a))
template<class T>inline void init(T&x){
	x=0;char ch=getchar();bool t=0;
	for(;ch>'9'||ch<'0';ch=getchar()) if(ch=='-') t=1;
	for(;ch>='0'&&ch<='9';ch=getchar()) x=(x<<1)+(x<<3)+(ch-48);
	if(t) x=-x;return;
}typedef long long ll;
const int N=2e5+10;
int f[N],V[N],X[N];
struct pegion{
	int X,V;
	inline bool operator <(const pegion b)const{return X<b.X;}
}P[N];
int id[N],L[N],R[N];
int n;
inline int cmp(int i,int j){return P[i].V<P[j].V;}
inline int cmp2(int i,int j){return R[i]<R[j]||(R[i]==R[j]&&L[i]<L[j]);}
int Pfast[N],Sslow[N],pos[N];
const int mod=1e9+7;
template<class T>inline void Inc(T&x,int y){x+=y;if(x>=mod) x-=mod;}
template<class T>inline void Dec(T&x,int y){x-=y;if(x < 0 ) x+=mod;}
int tr[N];
#define lowbit(a) ((a)&(-a))
inline void Update(int p,int x){for(;p<=n;p+=lowbit(p)) Inc(tr[p],x);return;}
inline int  Query(int p){if(p<0) return 0;int re=1;for(;p;p-=lowbit(p)) Inc(re,tr[p]);return re;}
inline int Lower(int x){
	int l=1,r=n,pos=n;
	while(l<=r){
		int mid=(l+r)>>1;
		if(P[id[mid]].V>=x) pos=mid,r=mid-1;
		else l=mid+1;
	}
	return pos;
}

int main()
{
	init(n);
	for(int i=1;i<=n;++i) {init(P[i].X),init(P[i].V);id[i]=i;}
	sort(P+1,P+1+n);sort(id+1,id+1+n,cmp);
	for(int i=1;i<=n;++i) {
		pos[id[i]]=i;
		Pfast[i]=max(Pfast[i-1],P[i].V);
	}Sslow[n]=P[n].V;
	for(int i=n-1;i;--i) Sslow[i]=min(Sslow[i+1],P[i].V);
	for(int i=1;i<=n;++i) {R[i]=Lower(Pfast[i]);L[i]=Lower(Sslow[i]);}
	sort(id+1,id+1+n,cmp2);
	int sum=0;
	for(int i=1;i<=n;++i) {
		int p=id[i];
		sum=Query(R[p]);Dec(sum,Query(L[p]-2));
		Update(R[p],sum);
	}
	int ans=Query(n);Dec(ans,Query(n-1));
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 8448
N = int(input())

from collections import Counter

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    return divisors

div = [len(make_divisors(i)) for i in range(N+1)][1:N+1:2]
d = Counter(div)

print(d[8])

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

int main(void) {
  int a, b, c;
  cin >> a >> b >> c;
  if (b < c) swap(b, c);
  if (a < b) swap(a, b);

  int cnt = 0;
  if ((a - b) % 2 == 0) cnt++;
  if ((a - c) % 2 == 0) cnt++;
  
  if (cnt == 0) {
    cout << (2*a - (b + c)) / 2 << endl;
  } else if(cnt == 1) {
    int ret = 0;
    if ((a - b) % 2 == 0) swap(b, c);
    ret += ((a-1) - b) / 2;
    ret += (a - c) / 2;
    cout << ret + 2 << endl;
  } else {
    cout << (2*(a-1) - (b + c)) / 2 + 1 << endl;
  }

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i=0;i < (int)(n);i++)


int main(){
   int n,m,x;
   cin >> n >> m >> x;
   vector<int> v(n+1,0);
   rep(i,m){
       int tmp;
       cin >> tmp;
       v[tmp]++;
   }
   int ans = 0,fans = 0;
   for (int i = x;i <= n;i++){
       ans +=v[i];
   }
   for (int j = x; j >= 0;j--){
       fans +=v[j];
   }
   fans = min(ans,fans);
   cout << fans << endl;
    return 0;
    
}

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

int main()
{
    int n, m;
    std::cin >> n >> m;
    
    std::vector<int> digitClue(n);
    
    for(int& i : digitClue)
    {
        i = -1;
    }
    
    for(int i = 0; i < m; ++i)
    {
        int s, c;
        std::cin >> s >> c;
        if(digitClue[s - 1] == -1)
        {
            digitClue[s - 1] = c;
        }
        else if(digitClue[s - 1] != c)
        {
            std::cout << -1 << std::endl;
            return 0;
        }
    }
    
    int begin = 0;
    int end = 9;
    
    if(n == 2)
    {
        begin = 10;
        end = 99;
    }
    else if(n == 3)
    {
        begin = 100;
        end = 999;
    }
    
    for(int i = begin; i <= end; ++i)
    {
        bool isOK = true;
        const std::string str = std::to_string(i);
        for(int j = 0; j < n; ++j)
        {
            if(digitClue[j] == -1)
            {
                continue;
            }
            
            if(digitClue[j] != (str[j] - '0'))
            {
                isOK = false;
                break;
            }
        }
        if(isOK)
        {
            std::cout << str << std::endl;
            return 0;
        }
    }
    std::cout << -1 << std::endl;
}

Measured memory_bytes: 256
import sys
# import re
import math
import collections
# import decimal
import bisect
import itertools
import fractions
# import functools
import copy
# import heapq
import decimal
# import statistics
import queue

# import numpy as np

sys.setrecursionlimit(10000001)
INF = 10 ** 16
MOD = 10 ** 9 + 7
# MOD = 998244353

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))

# ===CODE===

eps = 10 ** (-9)


def main():
    def popcounter(n):
        cnt = 0
        if n == 0:
            return 0
        for _ in range(INF):
            tmp = bin(n).count("1")
            n = n % tmp
            cnt += 1
            if n == 0:
                return cnt

    n = ni()
    x = sys.stdin.readline()
    x_1 = x.count("1")

    num = int(x, 2)
    num1 = num % (x_1 - 1) if x_1 - 1 > 0 else 0
    num0 = num % (x_1 + 1)

    ans = []
    for i in range(n):
        if x[n - 1 - i] == "1":
            if x_1 - 1 < 1:
                ans.append(0)
                continue
            else:
                tmp_n = (num1 - pow(2, i, x_1 - 1)) % (x_1 - 1)
        else:
            tmp_n = (num0 + pow(2, i, x_1 + 1)) % (x_1 + 1)
        ans.append(popcounter(tmp_n) + 1)

    l = len(ans)
    for i in range(l - 1, -1, -1):
        print(ans[i])


if __name__ == '__main__':
    main()


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

int main() {
    int h, w;
    cin >> h >> w;
    vector<vector<int>> c(10, vector<int>(10));
    for (auto& e : c) for (auto& f : e) cin >> f;
    vector<int> m(10);
    for (int i = 0; i < h * w; i++) {
        int a;
        cin >> a;
        if (a != -1) m[a]++;
    }

    int ans = 0;
    bitset<10> done;
    while (!done.all()) {
        vector<int> can(10, 1e9);
        for (int i = 0; i < 10; i++) if (!done[i]) can[i] = c[i][1];
        int mi = min_element(begin(can), end(can)) - begin(can);
        done.set(mi);
        for (int i = 0; i < 10; i++) c[i][1] = min(c[i][1], c[mi][1] + c[i][mi]);
        ans += c[mi][1] * m[mi];
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
int max(int x, int y) {
	return x > y ? x : y;
}
int main() {
	int a, b, c, d;
	scanf("%d%d%d%d", &a, &b, &c, &d);
	printf("%d\n", max(a * b, c * d));
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <limits>
#include <numeric>
#include <algorithm>
#include <functional>

using namespace std;

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

	int X, A;
	cin >> X >> A;

	if (X < A)
	{
		cout << 0;
	}
	else
	{
		cout << 10;
	}

	return 0;
}


Measured memory_bytes: 3616
fn read1<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

pub fn readn<T: std::str::FromStr>(delimiter: &str) -> Vec<T> {
    let s = read1::<String>();
    s.split(delimiter).map(|e| e.parse().ok().unwrap()).collect::<Vec<T>>()
}

const MOD: usize = 1_000_000_007;

fn main() {
    let n = read1::<usize>();
    let a = readn::<usize>(" ");
    let mut c = vec![1, 0, 0];
    let mut dp = vec![0; n];
    dp[0] = 3;

    if a[0] != 0 {
        println!("0");
        return;
    }

    for i in 1..n {
        let mut k = 0;
        for j in 0..3 {
            if c[j] == a[i] {
                if k == 0 {
                    c[j] += 1;
                }
                k += 1;
            }
        }
        if k == 0 {
            println!("0");
            return;
        }
        dp[i] = dp[i-1] * k % MOD;
    }

    println!("{}", dp[n-1]);
}

Measured memory_bytes: 6396
#include <bits/stdc++.h>
#define _for(i,a,b) for(int i=(a),_b=(b);i<_b;++i)

using namespace std;
const int maxn=20;
int a[maxn];
int b[maxn];
int n;
void enter()
{
    cin>>n;
    _for(i,0,n) cin>>a[i];
    _for(i,0,n) cin>>b[i];
}
const int oo = 1000000;
int ans =oo;
int f[(1<<maxn)][18];
bool d[(1<<maxn)][18];
int dp(int tt,int las)
{
    if (__builtin_popcount(tt)==1) return 0;
    else if (d[tt][las]) return f[tt][las];
    else
    {
        f[tt][las] = oo;
        int sbit = __builtin_popcount(tt),cnt =0 ;
        int val1 = (sbit%2==(las+1)%2) ? a[las] : b[las];
        for(int i = n-1; i>=0; --i)
        {
            if (((tt>>i)&1)==1) ++cnt;
            if (i==las) break;
        }
        cnt--;
        _for(i,0,n)
        {
            if (i!=las && ((tt>>i)&1)==1)
            {
                int val2 = ((sbit-1)%2==(i+1)%2) ? a[i] : b[i];
                if (val2<=val1)
                    f[tt][las] = min(f[tt][las], dp(tt - (1<<las), i) + cnt );
            }
        }
        d[tt][las] = true;
        return f[tt][las];
    }
}
void solve()
{
    _for(i,0,n)
    {
        ans = min(ans, dp((1<<n)-1, i));

    }
    if (ans==oo) cout<<"-1";
    else cout<<ans;
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie();
    cout.tie();
    enter();
    solve();
}


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

//マクロ
#define REP(i, n) for(ll i=0; i<(ll)n; i++)
#define REPD(i, n) for(ll i=(ll)(n)-1; i>=0; i--)
#define FOR(i, a, b) for(ll i=(ll)(a); i<=b; i++)
#define INF 100000000000000
#define all(x)
#define MAX(x) *max_element(ALL(x))



//変数定義
ll N;

unordered_map<int, int> count_num;

int main(){
    cin >> N;
    vector<int> nums(N);
    for(int i=0; i<N; ++i){
        cin >> nums[i];
        ++count_num[nums[i]];
    }

    ll total =0;
    for(auto&p : count_num){
        long long n = p.second;
        total += n*(n-1)/2;
    }
    for(int i=0; i<N; ++i){
        cout << total-count_num[nums[i]]+1<< endl;
    }

    return 0;
}

Measured memory_bytes: 9416
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#define FOR(i,k,n) for((i)=(k);(i)<(n);(i)++)
#define REP(i,n) for (int i=0;i<(n);i++)
#define pb push_back
#define all(a) (a).begin(),(a).end()  //greater<int>()
#define ll long long
using namespace std;

int main(){
	int N,M,i,a,b;
	cin>>N>>M;

	vector<int> A,B,C;

	REP(i,M){
		cin>>a>>b;
		A.pb(a);
		B.pb(b);
	}

	REP(i,N){
		C.pb(0);
	}

	REP(i,M){
		C[A[i]-1]++;
		C[B[i]-1]++;
	}

	REP(i,N){
		cout<<C[i]<<endl;
	}

	return 0;
}

Measured memory_bytes: 256
n = int(input())
h = list(map(int, input().split()))

cost0 = 0
cost1 = abs(h[1]-h[0])
if n ==1:
    print(cost0)
else:
    for i in range(n-2):
        cost0, cost1 = cost1, min(cost0+abs(h[i+2]-h[i]), cost1+abs(h[i+2]-h[i+1]))
    print(cost1)

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

#define F first
#define S second
#define PB push_back
#define MP make_pair
#define REP(i,a,b) for (int i = a; i <= b; i++)
#define debug(i) cout << i << endl;
#define debugarr(a) for(auto i : a) cout << i << " ";

#define ll long long
#define vi vector<int>
#define vll vector<ll>
#define pi pair<int,int>
#define pll pair<ll, ll>
#define vpi vector<pi>

using namespace std;

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

    int a, b;
    cin >> a >> b;
    cout << max({a-b, a+b, a*b}) << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;
class Main{
    public static void main(String[] args) {
        Scanner scn=new Scanner(System.in);
        int a = scn.nextInt();
        int b = scn.nextInt();
        String answer = "Odd";
        if(a%2==0||b%2==0) answer = "Even";
        System.out.println(answer);
    }
}


Measured memory_bytes: 21716
#include<stdio.h>

int main(void){
   int x,y,i,j;
   for(;;){
      scanf("%d %d",&y,&x);
      if(x+y==0) break;
      for(i=0;i<y;i++){
         for(j=0;j<x;j++)
            if((i+j)%2==0)
               printf("#");
            else
               printf(".");
         printf("\n");
      }
   printf("\n");
   }
   return 0;
}


Measured memory_bytes: 2104
n,k=map(int,input().split())
R,S,P=map(int,input().split())
t=input()

v=[]
ans=0
for i in t:
  if i=='r':
    v.append('p')
    ans+=P
  if i=='s':
    v.append('r')
    ans+=R
  if i=='p':
    v.append('s')
    ans+=S

for i in range(k,n):
  if v[i]==v[i-k]:
    if v[i]=='r':
      ans-=R
    if v[i]=='s':
      ans-=S
    if v[i]=='p':
      ans-=P

    v[i]='?'

print(ans)

Measured memory_bytes: 4212
#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(obj) (obj).begin(), (obj).end()
#define INF 1e9
typedef long long ll;

template<class T> void warshall_floyd(vector<T>& G){
    int N = G.size();
    REP(k,N){
        REP(i,N){
            REP(j,N){
                G[i][j] = min(G[i][j], G[i][k]+G[k][j]);
            }
        }
    }
}

int main() {
    int H,W; cin >> H >> W;
    vector<vector<int>> c(10,vector<int>(10,0));
    vector<vector<int>> A(H,vector<int>(W,0));

    REP(i,10){
        REP(j,10){
            cin >> c[i][j];
        }
    }

    warshall_floyd(c);
    int ans = 0;
    REP(i,H){
        REP(j,W){
            int a; cin >> a;
            if(a != -1){
                ans += c[a][1];
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3736
#include <iostream>
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
typedef long long int ll;
typedef long double dl;
#define PI  3.14159265358979323846
#define M   1000000009
ll fast(ll n,ll a,ll m)
{
    if(n==0)
        return 1;
    else if(n==1)
        return a;
    else
    {
        ll r=fast(n/2,a,m);
        if(n%2==0)
        {
            return (((r%m)*(r%m))%m);
        }
        else
        {
            return (((((r%m)*a)%m)*r)%m);
        }

    }
}
dl sqt(dl n)
{
    dl lo=0.0,hi=100000000000.0;
    dl mid,ans;
    while(hi-lo>=0.0000001)
    {
        mid=(lo+hi)/2;
        dl r=mid*mid;
        if(r<=n)
        {
            ans=mid;
            lo=mid;
        }
        else
        {
            hi=mid;
        }
    }
    return ans;
}
int main()
{


  ll n,m;
   cin>>n>>m;
   ll p=(m/2)+(m%2);
   if(n==1||m==1)
   {

       cout<<1;
   }
   else
   {
    if(m%2==0)
   {

       cout<<n*(p);
   }
   else
   {
       ll k,t;
       if(n%2==0)
       {
           k=n/2;
           t=n/2;
       }
       else
       {
           k=(n/2)+1;
           t=(n/2);
       }
       cout<<k*p+t*(p-1);
   }
   }
}




Measured memory_bytes: 256
//
//  atc1019.cpp
//  National Olympiad in Informatics in Provinces
//
//  Created by 黄子齐 on 2019/10/19.
//  Copyright © 2019 黄子齐. All rights reserved.
//

#include <stdio.h>
const int N = 2e2+10;
int a[N], n;
long long sum;
int main() {
//    freopen("mytestdata.in", "r", stdin);
    scanf("%d", &n);
    for (int i=1; i<=n; i++) {
        scanf("%d", &a[i]);
    }
    for (int i=1; i<=n; i++) {
        for (int j=i+1; j<=n; j++) {
            sum += a[i]*a[j];
        }
    }
    printf("%lld\n", sum);
    return 0;
}


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

int main() {
    
    int A, B;
    cin >> A >> B;
    
    
    cout << A * B << endl;
    
    return 0;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
int main(){
  double x=0,y=0,s=90;
  int a,b;
  while(scanf("%d,%d",&a,&b),a){
    x+=a*cos(s*M_PI/180);
    y+=a*sin(s*M_PI/180);
    s-=b;
  }
  cout<<(int)x<<endl;
  cout<<(int)y<<endl;
}

Measured memory_bytes: 3528
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <queue>

using namespace std;

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

const int INF = 1e9+100;

bool isnum(char c){
  return '0' <= c && c <= '9';
}

bool isop(char c){
  const string op = "+*-/";
  return op.find(c) != string::npos;
}

int find_paren(const string& s, int i){
  int cnt = 0;
  for(;i<SZ(s);++i){
	if(s[i] == '(') ++cnt;
	else if(s[i] == ')')
	  if(--cnt == 0) return i;
  }
  return -1;
}

set<int> eval(const string& s){
  VS terms;
  vector<char> ops;
  string term;
  for(int i=0;i<SZ(s);++i){
	if(isnum(s[i]))
	  term += string(1,s[i]);
	else if(s[i] == '('){
	  if(!term.empty()){
		//cout << term << endl;
		terms.PB(term);
	  }
	  int j = find_paren(s, i);
	  term = s.substr(i, j-i+1);
	  i = j;
	}
	else{
	  if(!term.empty()){
		//cout << term << endl;
		terms.PB(term);
	  }
	  term = "";
	  ops.PB(s[i]);
	}
  }
  if(!term.empty())
	terms.PB(term);

  set<int> res;
  if(ops.empty()){
	if(terms[0][0] == '(')
	  return eval(terms[0].substr(1, SZ(terms[0])-2));
	else
	  res.insert(atoi(terms[0].c_str()));
  }
  else{
	for(int i=0;i<SZ(ops);++i){
	  string lhs;
	  for(int j=0;j<=i;++j){
		if(j != 0) lhs += ops[j-1];
		lhs += terms[j];
	  }
	  set<int> l = eval(lhs);
	  string rhs;
	  for(int j=i+1;j<SZ(terms);++j){
		if(j != i+1) rhs += ops[j-1];
		rhs += terms[j];
	  }
	  set<int> r = eval(rhs);
	  for(int lx: l){
		for(int rx: r){
		  int x;
		  switch(ops[i]){
		  case '+': x = lx+rx; break;
		  case '-': x = lx-rx; break;
		  case '*': x = lx*rx; break;
		  case '/': x = (rx != 0? lx/rx: INF); break;
		  }
		  if(x != INF) res.insert(x);
		}
	  }
	}
  }
  return res;
}

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

  string expr;
  while(cin>>expr,expr!="#"){
	//	cout<<expr<<endl;
	cout << SZ(eval(expr)) << endl;
  }
  
  return 0;
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#define rep(i,n) for(int i=0;i<n;i++)
const long long MOD = 1000000007;
typedef pair<int,int> P;

string s[1000];
int h,w;
int dx[4] = {1,0,-1,0};int dy[4] = {0,1,0,-1};


int main(){
  int n; cin >> n;
  string s; cin >> s;
  if(n % 2 == 0){
    bool frag = true;
    rep(i,n/2){
      if(s.at(i) != s.at(i+n/2)) frag = false;
    }
    if(frag) cout << "Yes\n";
    else cout <<"No\n";
  }else{
    cout << "No\n";
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cstdio>
#include <algorithm>
#include <utility>
#include <string>
#include <cmath>
#include <set>
#include <functional>
#include <map>
#include <queue>
#include <cstring>
#include <stack>
#include <iomanip>
#include <climits>
#include <numeric>
#include <cassert>
#include <unordered_map>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define show(x) cout << #x << " = " << x << endl;
typedef long long ll;
typedef pair<int,int> pii;
struct edge{
    int to, cost;
};
vector<edge>g[100005];
long long d[100005];
void dfs(int k){
    for(auto x:g[k]){
        if(d[x.to] == -1){
            d[x.to] = d[k] + x.cost;
            dfs(x.to);
        }
    }
}
int main(){
    int n;
    cin >> n;
    int a,b,c;
    rep(i,n-1){
        cin >> a >> b >> c;
        g[a].push_back(edge{b,c});
        g[b].push_back(edge{a,c});
    }
    int q,k;
    cin >>q >> k;
    memset(d,-1,sizeof(d));
    d[k] = 0;
    dfs(k);
    int x,y;
    rep(i,q){
        cin >> x >> y;
        cout << d[x] + d[y] << endl;
    }
    return 0;
}

Measured memory_bytes: 11136
import java.util.*;
 public class Main
{
public static void main(String[] args)
{
 
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
  int l=sc.nextInt();
  ArrayList<String> ar=new ArrayList<String>();
  for(int i=0;i<n;i++)
    ar.add(sc.next());
  Collections.sort(ar);
  for(int i=0;i<n;i++)
    System.out.print(ar.get(i));
}}


Measured memory_bytes: 22384
import sys
from io import StringIO
import unittest


def resolve():
    N = int(input())
    S = {}
    maxs = 0
    for _ in range(N):
        s = input()
        if s in S.keys():
            S[s] += 1
            maxs = max(maxs, S[s])
        else:
            S[s] = 1
            maxs = max(maxs, S[s])
    # S.keys().sort()
    keys = sorted(S.keys())
    for key in keys:
        if S[key] == maxs:
            print(key)


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """7
beat
vet
beet
bed
vet
bet
beet"""
        output = """beet
vet"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """8
buffalo
buffalo
buffalo
buffalo
buffalo
buffalo
buffalo
buffalo"""
        output = """buffalo"""
        self.assertIO(input, output)

    def test_入力例_3(self):
        input = """7
bass
bass
kick
kick
bass
kick
kick"""
        output = """kick"""
        self.assertIO(input, output)

    def test_入力例_4(self):
        input = """4
ushi
tapu
nichia
kun"""
        output = """kun
nichia
tapu
ushi"""
        self.assertIO(input, output)


if __name__ == "__main__":
    # unittest.main()
    resolve()


Measured memory_bytes: 34796
#include<bits/stdc++.h>
#pragma GCC optimize ("Ofast")
#define ll long long int
#define FOR(i,a,b) for(int (i)=(a);i<(int)(b);i++)
#define rep(i,n) FOR(i,0,n)
#define outi(a) printf("%lld\n",(a))
#define ind(a) scanf("%lf", (a))
using namespace std;

int read()
{
  char c = getchar_unlocked();
  while(c < '0' || c > '9')
  c = getchar();
  int sum = 0;
  while(c >= '0' && c <= '9')
  sum = sum*10 + c - '0', c = getchar_unlocked();
  return sum;
}

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(NULL);
 //reopen("input.txt", "r", stdin);
  string ami, tumi;
  cin >> ami >> tumi;
  ami += ami;
  int c = tumi.size();
  rep(i, ami.size())
  if(ami.substr(i, c) == tumi)
  {
    cout << "Yes" << endl;
    return 0;
  }
  cout << "No" << endl;
}


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

int main() {
  string str;
  cin>>str;
  vector<string> zen((str.size()-1)/2);
  for(int i; i<(str.size()-1)/2; i++){
    zen.at(i)=str.at(i);
  }
   vector<string> kou((str.size()-1)/2);
  for(int i; i<(str.size()-1)/2; i++){
    kou.at(i)=str.at(i+(str.size()+1)/2);
  }
  if(zen==kou){
    reverse(zen.begin(), zen.end());
    if(zen==kou)
      cout<<"Yes"<<endl;
  }
  else
    cout<<"No"<<endl;
  
                           
}

Measured memory_bytes: 256
N = int(input())
quat=[]

addstr=''
if N<0:
    addstr=str(N%2)
    N-=N%2
    N//=-2

while N>0:
    quat.append(N%4)
    N//=4
quat.append(0)

ans = [0]*(2*len(quat)+2)

for i in range(len(quat)):
    if quat[i]<=1:
        ans[2*i]=quat[i]
    elif quat[i]<=3:
        ans[2*i]=quat[i]%2
        ans[2*i+1]=1
        quat[i+1]+=1
    else:
        quat[i+1]+=1

ansstr=''

i=len(ans)-1

while ans[i]==0:
    i-=1
    if i==-1:
        break

while i>=0:
    ansstr += str(ans[i])
    i-=1


if len(ansstr)>0:
    print(ansstr+addstr)
else:
    print(0)





Measured memory_bytes: 38256
import java.util.*;

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

	public void run() {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		Map<Integer, Integer> m = new HashMap<Integer, Integer>();
		for(int i=0; i<s.length(); i++) {
			char c = s.charAt(i);
			m.put(c-'A', m.containsKey(c-'A') ? m.get(c-'A')+1 : 1);
		}
		if(m.size()!=2) {
			System.out.println("No");
			sc.close();
			return;
		}else {
			for(Map.Entry<Integer, Integer> e : m.entrySet()) {
				if(e.getValue() != 2) {
					System.out.println("No");
					sc.close();
					return;
				}
			}
		}
		System.out.println("Yes");
		sc.close();
	}
}


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

using namespace std;

int main() {
    int n;
    cin >> n;

    vector<int> v;
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;
        v.push_back(a);
    }

    long long ans = 0;
    for (int e: v) ans += e;
    ans -= n;

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 888
#include <cstdio>
#include <algorithm>
#define N 2002

using namespace std;

struct edge{
	int to, nxt;
}e[N << 1];

int n, cnt, sum;
int f[N], sz[N], fir[N];
char s[N];

void add(int ,int);
void dfs(int ,int ,int);

int main(){
	scanf("%d%s", &n, s + 1);
	for(int i = 1; i < n; ++i){
		int u, v; scanf("%d%d", &u, &v);
		add(u, v); add(v, u);
	} int ans = 999999999;
	for(int i = 1; i <= n; ++i){
		sum = 0; dfs(i, 0, 0); 
		if(f[i] * 2 == sum && sum % 2 == 0)
			ans = min(ans, sum / 2);
//		printf("%d %d\n", i, ans);
	}
	if(ans == 999999999) ans = -1;
	printf("%d\n", ans);
	return 0;
}

void add(int u, int v){
	e[++cnt] = (edge){v, fir[u]}; fir[u] = cnt;
	return ;
}

void dfs(int u, int fa, int dis){
	sz[u] = 0; int tmp = sum, mson = 0, mx = 0, lst = sum;
	for(int i = fir[u]; i; i = e[i].nxt){
		int v = e[i].to; if(v == fa) continue;
		dfs(v, u, dis + 1);
		if(sum - lst > mx) mson = v, mx = sum - lst;
		lst = sum; sz[u] += sz[v];
	}
	tmp = sum - tmp - dis * sz[u]; mx -= dis * sz[mson];
	if(tmp - mx >= mx) f[u] = tmp / 2;
	else f[u] = tmp - mx + min(f[mson], (2 * mx - tmp) / 2);
	int p = s[u] - '0'; sz[u] += p; sum += p * dis;
	return ;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
# define ll long long int
#define M 998244353
#define pb push_back
#define ss second
#define ff first
#define inf 1000000000000000
 
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x ;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
 
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
 
												//nestedcode
 
ll binpow(ll a, ll b, ll m) {
    a %= m;
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % m;
        a = a * a % m;
        b >>= 1;
    }

}


int main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    ll n,i,r = 0, ans = 0;
    cin>>n;
    string c;
    cin>>c;
    for(i=0;i<n;i++){
    	if(c[i] == 'R')	r++;
	}
	for(i=r;i<n;i++){
		if(c[i] == 'R')	ans++;
	}
	cout<<ans<<endl;
}
   
  

	  


Measured memory_bytes: 3732
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String S = sc.next();
        int n=0;
        char flag = ' ';
        for(int i=0;i<S.length();i++){
            if(S.charAt(i)==flag){

            }else{
                flag = S.charAt(i);
                n++;
            }
        }
        System.out.println(n-1);
        sc.close();

    }

}


Measured memory_bytes: 13420