akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <complex>
#include <vector>
#include <algorithm>
#include <cmath>
#include <array>
using namespace std;
const double EPS = 1e-8;
const double INF = 1e12;
const double PI = acos(-1);
#define EQ(n,m) (abs((n)-(m)) < EPS)
#define X real()
#define Y imag()

typedef complex<double> P;
typedef vector<P> VP;
struct L : array<P, 2>{
    L(const P& a, const P& b){ at(0)=a; at(1)=b; }
    L(){}
};

double dot(P a, P b){
    return (conj(a)*b).X;
}
double cross(P a, P b){
    return (conj(a)*b).Y;
}
double distanceLP(const L &l, const P &p) {
    return abs(cross(l[1]-l[0], p-l[0])) /abs(l[1]-l[0]);
}
double distanceSP(const L &s, const P &p) {
    if(dot(s[1]-s[0], p-s[0]) < EPS) return abs(p-s[0]);
    if(dot(s[0]-s[1], p-s[1]) < EPS) return abs(p-s[1]);
    return distanceLP(s, p);
}

int main(){
    int n;
    cin >> n;
    vector<double> r(n);
    vector<L> p(n);
    for(int i=0; i<n; i++){
        double sx,sy,tx,ty;
        cin >> r[i] >> sx >> sy >> tx >> ty;
        p[i] = L(P(sx, sy), P(tx, ty));
    }
    bool canmove[16][16][2] = {};
    for(int i=0; i<n; i++){
        for(int j=0; j<n; j++){
            for(int d=0; d<2; d++){
                canmove[i][j][d] = (distanceSP(p[i], p[j][d]) +EPS > r[i]+r[j]);
            }
        }
    }

    vector<int> dp(1<<n, -1);
    dp[0] = 0;
    for(int i=0; i<(1<<n); i++){
        if(dp[i] == -1) continue;
        for(int j=0; j<n; j++){
            if(i>>j & 1) continue;
            bool ok = true;
            for(int k=0; k<n; k++){
                if(j == k) continue;
                if(!canmove[j][k][i>>k&1]){
                    ok = false;
                    break;
                }
            }
            if(ok){
                dp[i | 1<<j] = dp[i]+1;
            }
        }
    }
    cout << *max_element(dp.begin(), dp.end()) << endl;
    return 0;
}


Measured memory_bytes: 3392
x1, y1, x2, y2 = map(int, input().split())
x = x1 - x2
y = y1 - y2
point3 = [x2 + y, y2 - x]
point4 = [x1 + y, y1 - x]
print(point3[0], point3[1], point4[0], point4[1])


Measured memory_bytes: 2940
#include<iostream>
#include<cmath>
#include<vector>
#define INF 2147483647

using namespace std;

class segtree{
public:
  int Node;
  vector<int> table;
  segtree(int);
  int ope(const int,const int);
  void update(int index,const int value){ // index is 0-indexed.
    index += Node; // query function
    table[index] = value;
    while(index > 0){
      index /= 2;
      table[index] = ope(table[2*index],table[2*index+1]);
    }
  }
  int find(int l, int r);
};
int segtree::find(int l,int r){ // l,r is 0-indexed.
    if(l == r) return table[r+Node];
    l += Node; r += Node;
    long long ans = INF;
    for(; l <= r;l >>=1, r >>=1){
      if(r == l){ans=ope(ans,table[l]); return ans;}
      if(r%2 == 0){ ans=ope(ans,table[r]);--r;}
      if(l%2){ ans=ope(ans,table[l]);++l;}
    }
    return ans;
}
segtree::segtree(int Max_Node){  // initialize
  Node = 2;
  while(Node < Max_Node)
    Node *= 2;
  table.resize(2*Node);
  for(int i = Node;i < Node*2; i++){
    table[i] = INF; // initialize
    //cout<<table[i]<<endl;
  }
  for(int i= Node-1; i > 0; i--){
    table[i] = ope(table[i*2],table[i*2+1]);
      //cout<<table[i]<<endl;
  }
}

int segtree::ope(const int a,const int b){
  return min(a,b);
}

int main(){
  int n,q;
  cin>>n>>q;
  segtree seg(n);
  for(int i=0;i<q;i++){
    int com,x,y;
    cin>>com>>x>>y;
    if(com){
      cout<<seg.find(x,y)<<endl;
    }else{
      seg.update(x,y);
    }
  }
  return 0;
}

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

using namespace std;


//i posle 10 dana on se javio iz zatvora
const int maxi =1e6+10;
#define pb push_back
#define pii pair<int,int>

int a[maxi];
string s;
int n;
vector<int> v[maxi];
int cnt[maxi];
int main()
{
    cin>>n;

    for (int i = 2;i<maxi;i++)
    {
        if (!a[i])
        {
            for (int j = i; j<maxi;j+=i){
                v[j].pb(i);
               a[j] = 1;
            }
        }
    }

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

    int bad = 0;

    for (int i = 1;i<=n;i++)
        for (int j:v[a[i]]){
        if (cnt[j]) bad = 1;
        cnt[j] = 1;
    }

   if (!bad) printf("pairwise coprime\n"); else
    if (gc==1) printf("setwise coprime"); else
    printf("not coprime\n");
    return 0;
}


Measured memory_bytes: 67016
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 400000;


int main() {

	int N, M;
	cin >> N >> M;
	vector<int> g[1000];

	int s, t;
	rep(i, M) {
		cin >> s >> t;
		g[s].push_back(t);
	}

	double e[1000] = {};

	
	for (int v = N-1; v > 0; v--) {
		rep(j, g[v].size()) {
			int w = g[v][j];
			e[v] += e[w]+1;
		}

		
		e[v] /= g[v].size();

	}

	double p[1000] = {};

	p[1] = 1;

	for (int v = 1; v <= N; v++) {
		rep(j, g[v].size()) {
			int w = g[v][j];
			p[w] += p[v] / g[v].size();
		}
	}

	double elim = 0;

	for (int v = 1; v < N; v++) {
		
		if (g[v].size() >= 2) {
			rep(j, g[v].size()) {
				int w = g[v][j];

				double x = (e[w] + 1 - e[v]) / (g[v].size() - 1);
				x *= p[v];
				elim = max(x, elim);
			}
		}
	}

	cout << fixed << setprecision(10);

	cout << e[1] - elim;

	system("PAUSE");

}

Measured memory_bytes: 1656
import Control.Monad                                                                                                       
                                                                                                                           
main :: IO ()                                                                                                              
main = do                                                                                                                  
  _ <- read <$> getLine :: IO Int                                                                                          
  ts <- map read . words <$> getLine :: IO [Int]                                                                           
  m <- read <$> getLine :: IO Int                                                                                          
  pxs <- replicateM m (map read . words <$> getLine) :: IO [[Int]]                                                         
  let ps = map (!!0) pxs                                                                                                   
      xs = map (!!1) pxs                                                                                                   
      pxt = zip ps xs                                                                                                      
      sumts = sum ts                                                                                                       
  forM_ pxt $ \px -> do                                                                                                    
    print $ sumts - (ts!!(fst px - 1) - (snd px))

Measured memory_bytes: 1020
/*
https://atcoder.jp/contests/dp/tasks/dp_i
Space n+1 Time n*n
#probability #dp #bottomUp
*/

#include <bits/stdc++.h>
using namespace std;

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
  int n; cin >> n;
  double p[n];
  for(int i=0;i<n;i++)
    cin >> p[i];
  double m[n+1] = {0};
  m[0] = 1-p[n-1];
  m[1] = p[n-1];
  for(int coin=n-2;coin>=0;coin--) {
    for(int heads=n;heads>=0;heads--) {
      if (heads == 0)
        m[heads] = (1-p[coin]) * m[heads];
      else {
        m[heads] = p[coin]*m[heads-1] + (1-p[coin])*m[heads];
      }
    }
  }

  double res = 0;
  for(int heads=n/2+1;heads<=n;heads++) {
    res += m[heads];
  }
  cout << setprecision(10) << res;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define F first
#define S second
#define Tsetso ios_base::sync_with_stdio(0) ; cin.tie(0) ;
using namespace std;
const ll N = 2e5+50, inf = 1e3+5, mod = 1e9+7, NN = 1e5+10;
int a[N];
int main()
{
    Tsetso
    int n, k, ans = 0;
    cin >> n >> k ;
    for( int i = 1 ; i <= n ; i++)
        cin >> a[i] ;
    n-- , k-- ;
    cout << n / k + (n%k != 0) ;
}


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

using namespace std;
typedef long long ll;
typedef long long LL;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef pair<ll,int> li;
#ifdef DEBUG
    #define cek(x) cout<<x
#else
    #define cek(x) if(false){}
#endif // DEBUG

#define fi first
#define se second
#define INF 1000000000
#define INFLL 1000000000000000000LL
#define EPS 1e-9
#define PI acos(-1.0)
#define pb push_back
#define TC() while(tc--)
#define FOR(i,n) for(int i=0;i<n;i++)
#define FORN(i,n) for(int i=0;i<=n;i++)
#define REP(i,a,b,c) for(int i=a;i<b;i+=c)
#define REPN(i,a,b,c) for(int i=a;i<=b;i+=c)
#define reset(a,b) memset(a,b,sizeof(a))

int main(void) {
  std::ios::sync_with_stdio(false);
  int n,a,b;
  cin >> n >> a >> b;
  cout << (((b - a - 1) % 2 == 0) ? "Borys" : "Alice") << "\n";
  return 0;
}


Measured memory_bytes: 256
#include <array>
#include <deque>
#include <forward_list>
#include <list>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <iterator>
#include <algorithm>
#include <cfenv>
#include <random>
#include <numeric>
#include <cmath>
#include <iosfwd>
#include <iostream>
#include <ios>
#include <streambuf>
#include <istream>
#include <ostream>
#include <iomanip>
#include <sstream>
#include <fstream>


typedef long long ll;

using namespace std;

int main(){
    ll N,sum=0;
    cin >> N;
    for(ll i = 1 ; i <= N ; i++){
        if(i % 3 != 0 && i % 5 != 0){
            sum += i;
        }
    }
    cout << sum ;
    return 0;
}

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

using namespace std;

int main()
{
  int n;
  while(cin >> n, n) {
    vector<int> taro(n);
    vector<int> hana;
    for(int i = 0; i < n; i++) cin >> taro[i];
    for(int i = 1; i <= 2*n; i++) {
      if(find(taro.begin(), taro.end(), i) == taro.end()) hana.push_back(i);
    }
    sort(taro.begin(), taro.end());
    sort(hana.begin(), hana.end());
    int last = 0;
    while(1) {
      auto ti = upper_bound(taro.begin(), taro.end(), last);
      if(ti != taro.end()) last = *ti, taro.erase(ti);
      else last = 0;
      if(taro.size() == 0) break;      
      auto hi = upper_bound(hana.begin(), hana.end(), last);
      if(hi != hana.end()) last = *hi, hana.erase(hi);
      else last = 0;
      if(hana.size() == 0) break;
    }
    cout << hana.size() << endl << taro.size() << endl;
  }
  return 0;
}

Measured memory_bytes: 3040
import sys
from collections import Counter

sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7


def input():
    return sys.stdin.readline().strip()


def main():
    S = list(input())
    c = Counter(S)
    ans = (c["g"] - c["p"]) // 2
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 4332
#include <algorithm>
#include <iostream> //入出力
#include <stdio.h>
#include <map>
#include <set>
#include <string>
#include <math.h> //算術演算子
#include <vector>
#include <cstdlib>
#include <queue>
#include <stack>
#include <list>
#include <iomanip> //小数点以下を表示させる(setprecision())
// #include <bits/stdc++.h>
using namespace std;
typedef long long ll; //64bit型

#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(a) (a).begin(), (a).end()
#define debug(x) cerr << x << " " \
                      << "(L:" << __LINE__ << ")" << '\n'
#define PRINT(V)                                   \
        {                                          \
                for (int i = 0; i < V.size(); i++) \
                {                                  \
                        cout << V[i] << " ";       \
                }                                  \
                cout << endl;                      \
        }

int gcd(int a, int b)
{
        return b ? gcd(b, a % b) : a;
}
string trans(int N)
{
        string S;
        while (N != 0)
        {
                if (N % 2 == 1)
                {
                        N--;
                        S = '1' + S;
                }
                else
                {
                        S = '0' + S;
                }
                N /= 2;
        }
        return S;
}

bool binary(vector<int> vec, int key)
{
        int left = 0;
        int right = vec.size();

        while (left < right)
        {
                int mid = (left + right) / 2;
                if (vec[mid] == key)
                {
                        return true;
                }
                else if (vec[mid] > key)
                {
                        right = mid;
                }
                else
                {
                        left = mid + 1;
                }
        }
        return false;
}

int main() //input->compute->output
{
        int s, t, u;
        cin >> s >> t >> u;

        cout << (t + u) - min(t + u, s) << endl;

        return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<stdio.h>
#include<string>
#include<cmath>
#include<cstdio>

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
#define repn(i, n) for(int i = 1; i <= n; i++)
#define repr(i, n) for(int i = n-1; i >=0; i--)
#define lint long long
#define all(x) (x).begin(), (x).end()


int main(){
    int X; cin>>X;
    bool dp[100001] = {};
    for(int i = 100; i <= 105; i++) dp[i] = true;
    for(int i = 200; i <= X; i++){
        if(dp[i-100]||dp[i-101]||dp[i-102]||dp[i-103]||dp[i-104]||dp[i-105]) dp[i] = true;
    }
    cout<<dp[X]<<endl;
}

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

using namespace std;

typedef long long int LLI;


int main() { 
    string str;
    while (cin >> str) {
        int n =str.length();
        int st = n, en = 0;
        for (int i = 0; i < n; ++i) {
            if (str[i] == 'A') st = min(st, i);
            if (str[i] == 'Z') en = i;
        }
        cout << en-st+1 << "\n";
    }

    return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <algorithm>

using namespace std;

char alph[26];

void solve() {
    string s;
    cin >> s;
    for (char c: s) {
        ++alph[c - 'a'];
        if (alph[c-'a'] > 1) {
            cout <<"no";
            return;
        }
    }
    cout << "yes";

}

int main() {

	solve();
    return 0;
}



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

int main()
{
	int n;
	cin >> n;
	cout << n << ":";
	int p = 2;
	int m = n;
	do
	{
		if (n % p == 0) {
			cout << " " << p;
			n /= p;
		}
		else
		{
			p++;
		}
	} while ((n > 1) && (p * p <= m));
	if (n > 1) {
		cout << " " << n;
	}
	cout << endl;
	return 0;
}


Measured memory_bytes: 3120
/* ---------- STL Libraries ---------- */
// IO library
#include <cstdio>
#include <fstream>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm library
#include <algorithm>
#include <cmath>
#include <numeric>
#include <random>

// container library
#include <array>
#include <bitset>
#include <deque>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>

/* ---------- Namespace ---------- */
using namespace std;

/* ---------- Type ---------- */
using ll = long long;
#define int ll
#define P pair<ll, ll>

/* ---------- Constants  */
const ll MOD = 1e9 + 7;
const int INF = 1LL << 55;
// const double PI = acos(-1);
// const double EPS = 1e-10;
// mt19937 mert(LL(time(0)));

/* v-v-v-v-v-v-v-v-v Main Part v-v-v-v-v-v-v-v-v */

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

    int ret = S[0] == T[0] ? 3 : 6;
    int prev_num = S[0] == T[0] ? 1 : 2;
    int ptr = S[0] == T[0] ? 1 : 2;

    while (ptr <= N - 1) {
        if (S[ptr] == T[ptr]) {
            int next_num = 1;

            if (prev_num == 1) {
                ret = (ret * 2) % MOD;
            } else {
                ret = (ret * 1) % MOD;
            }

            ptr++;
            prev_num = next_num;
        } else {
            int next_num = 2;

            if (prev_num == 1) {
                ret = (ret * 2) % MOD;
            } else {
                ret = (ret * 3) % MOD;
            }

            ptr += 2;
            prev_num = next_num;
        }
    }

    cout << ret << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int) n; i++)
using ll = long long;
template <class T>
using vt = vector<T>;
using vvi = vector<vector<int>>;

void svtr(vector<int> &a){
  sort(a.begin(),a.end());
  reverse(a.begin(),a.end());
}

int main() {
  int x,y,a,b,c;
  cin >> x >> y >> a >> b >> c;
  vt<int> p(a),q(b),r(c);
  vt<int> d;

  rep(i,a)
    cin >> p[i];
  rep(i,b)
    cin >> q[i];
  rep(i,c){
    cin >> r[i];
    d.push_back(r[i]);
  }

  svtr(p);
  svtr(q);

  rep(i,x)
    d.push_back(p[i]);

  rep(i,y)
    d.push_back(q[i]);

  svtr(d);

  ll ans=0;
  rep(i,x+y){
    ans += d[i];
  }

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


Measured memory_bytes: 3572
#include <bits/stdc++.h>
	
using namespace std;
    
#define endl "\n"
#define ll unsigned long long
#define int long long int
#define vi vector <int >
#define vvi vector < vector < int >  >
#define vii vector < pii >
#define vll vector <ll >
#define all(x) x.begin(),x.end()
#define pii pair <int, int>
#define pdd pair< double, double>
#define piii pair < pii, int > 
#define pll pair<ll, ll >
#define umap unordered_map
#define pb push_back
#define pq priority_queue
#define forn(i, n) for(int i = 0; i < (int)n; i++)
#define rep(i,b,c) for(int i = (int)b; i < (int)c; i++)
#define double long double
#define a first
#define b second

double f(int n){
    return  ((1 + n)*n)/2;
}


int32_t main(){
    ios::sync_with_stdio(0),cin.tie(0);
    
    int n, k, m;
    cin >> n >> m;
    vector < double > arr(n);
    forn(i, n){
        cin >> k;
        arr[i] = f(k)/k;
    }

    double ax = 0;
    forn(i, m){
        ax += arr[i];
    }
    double ans = ax;
    rep(i, 1, n - m + 1){
        ax -= arr[i - 1];
        ax += arr[i + m - 1];
        ans = max(ans, ax);
    }
    //printf(f
    cout << setprecision(12)<< ans << endl;

    return 0;
}

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

int main() {
  vector<long long> E(3);
  bool all_odd = true;
  for (int i = 0; i < 3; i++) {
    cin >> E.at(i);
    if (E.at(i) % 2 != 1) all_odd = false;
  }
  if (all_odd) {
    sort(E.begin(), E.end());
    cout << E.at(0) * E.at(1) << endl;
  }
  else cout << 0 << endl;
}


Measured memory_bytes: 256
from sys import stdin
def I(): return int(stdin.readline().rstrip())
def LI(): return list(map(int,stdin.readline().rstrip().split()))

n = I()
a = LI()

la = list(a)
if 0 in la:
    print(0)
    exit()
tmp = 1
for i in range(n):
    if pow(10,18)<tmp*a[i]:
        print(-1)
        exit()
    else:
        tmp *= a[i]

print(tmp)

Measured memory_bytes: 21468
// #define _CRT_SECURE_NO_WARNINGS
// #define _USE_MATH_DEFINES	// M_PI=3.1415...
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <locale>
#include <cctype>
#include <sstream>
#include <iomanip>	// 20桁出力 cout << setprecision(20) << double;
#include <queue>
#include <bitset>	// bitset<8> bs1(131uL); // 10000011 bs1[0]は1 01stringからビット集合生成可
using namespace std;

typedef long long LL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<LL> VL;
typedef map<int, int> MAPII;
typedef multimap<int, char, greater<int> > MuMAPIC;
typedef vector<pair<int, int> > VPII;
typedef multimap<int, string, greater<int> > MuMIS;
typedef pair<int, int> P;
typedef pair<int, pair<P, P> > PP;

#define INF 999999999999999997;
#define MP make_pair
#define FAST_IO  cin.tie(0); ios::sync_with_stdio(false);
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORL(i,a,b) for(LL i=(a);i<(b);i++)
#define FOR_REV(i,a,b) for(int i=(a);i>=(b);i--)
//for gcc (未test)
// #define FOREACH_IT(it,c) for(typeof(c)::iterator it=(c).begin(); it!=(c).end(); ++it)
//for Visual Studio
#define foreach_it(type,it,c) for(type::iterator it=c.begin(),c_end=c.end();it!=c_end;++it)
#define FOR_ITR(d) for(auto itr=d.begin(),d_end=d.end();itr!=d_end;++itr)	// C++11
// for Debug.
#define DUMP_VVI(b) FOR(i,0,b.size()){FOR(j,0,b[i].size())printf("%d ",b[i][j]);puts("");}
#define D_OUT(str,value) if(dbgF){cout<<str<<" : "<<value<<endl;}
// 入力をpush_back(d)やarray[d]に使う時に1行で書ける
// int INPUT_INT() {int d;cin>>d;return d;}
template<class T>T IN() { T d; cin >> d; return d; }
// 最大公約数（Greatest Common Divisor）
LL gcd(LL a, LL b) { return (b > 0) ? gcd(b, a%b) : a; }
// 最小公倍数（Least Common Multiple）
LL lcm(LL a, LL b) { return a / gcd(a, b) * b; }
// Y年はうるう年か否か
bool uruu(LL Y) { return (((Y % 4 == 0 && Y % 100 != 0) || Y % 400 == 0) ? true : false); }

int dx[4] = { 0,1,0,-1 };
int dy[4] = { 1,0,-1,0 };

// vector注意
// vec[i][j]の形に入力を入れるとき、vecは初期化してある必要がある.

// ------------------- include, typedef, define END. -------------------

int main() {
	FAST_IO;
	// for D_OUT(str, value)  ... cout<< str <<" : "<< value <<endl;
	bool dbgF = true;

	//コードはここから書く.
  string s;
  cin>>s;
  cout<<"2018/01/";
  cout<<s[8]<<s[9]<<endl;


	return 0;
}

Measured memory_bytes: 256
#pragma region include
#include <iostream>
#include <iomanip>
#include <stdio.h>

#include <sstream>
#include <algorithm>
#include <cmath>
#include <complex>

#include <string>
#include <cstring>
#include <vector>
#include <tuple>
#include <bitset>

#include <queue>
#include <complex>
#include <set>
#include <map>
#include <stack>
#include <list>

#include <fstream>
#include <random>
//#include <time.h>
#include <ctime>
#pragma endregion //#include
/////////
#define REP(i, x, n) for(int i = x; i < n; ++i)
#define rep(i,n) REP(i,0,n)
/////////
#pragma region typedef
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
#pragma endregion //typedef
////定数
const int INF = (int)1e9;
const LL MOD = (LL)1e9+7;
const LL LINF = (LL)1e18+20;
const double PI = acos(-1.0);
const double EPS = 1e-9;
/////////
using namespace::std;

void solve(){
	int A,B,C;
	cin >>A>>B>>C;
	A = (A%B);
	for(int i=0;i<B;++i){
		if( (A*i)%B == C ){
			cout << "YES" << endl;return;
		}
	}
	cout << "NO" << endl;
}

#pragma region main
signed main(void){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	std::cout << std::fixed;//小数を10進数表示
	cout << setprecision(16);//小数点以下の桁数を指定//coutとcerrで別	

	solve();
}
#pragma endregion //main()


Measured memory_bytes: 256
#include <bits/stdc++.h> 
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#include<cmath>
#include<string>
#define pb push_back
#define ll long long
#define ull unsigned long long
#define deb(x) cerr<<#x<<" "<<x<<"\n"
#define debi cerr<<"hey sparky\n"
#define x first
#define y second
#define fast ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define newline cout<<"\n"
#define yes cout<<"YES"<<"\n"
//#define no cout<<"NO"<<"\n"
#define INF (int)1e5+5
#define nax (int)1e6+3
#define eps (double)1e-9
#define all(x) x.begin(),x.end()
#define MAX_N (int)1e6+2
#define int long long
using namespace std;
using namespace __gnu_pbds; 
typedef tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> pdbs;
 
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
 
// look for  all edge cases
//search for a pattern
 
 


	
signed main() {	
	ios::sync_with_stdio(0);
	cout.tie(0);
	cin.tie(0);	

	int n;
	cin >> n;
	vector<int> v(n);
	for(int i =0 ; i< n; i++){
		cin >> v[i];
	}
	sort(all(v));
	reverse(all(v));
	
	
	int ans = v[0];
	int cnt = 2;
	
	
	int l = 1;
	while(cnt != n){
		cnt++;
		ans += v[l];
		if(cnt%2 == 0){
			l++;
		}
	}
	cout<<ans;
	
	return 0;
}


Measured memory_bytes: 4724
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Math;

namespace D_ABC148
{
    class MainClass
    {

        static int[] s, a;

        public static void Main(string[] args)
        {
            s = Array.ConvertAll(ReadLine().Split().ToArray(), int.Parse);
            a = Array.ConvertAll(ReadLine().Split().ToArray(), int.Parse);
            int ans = 0;
            int cnt = 1;
            for(int i = 0;i<s[0];i++){
                if(a[i]==cnt){
                    cnt++;
                }else{
                    ans++;
                }
            }
            if(ans==s[0]){
                WriteLine(-1);
            }else{
                WriteLine(ans);
            }
        }
    }
}


Measured memory_bytes: 36956
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <utility>
#include <vector>
#include <tuple>

#define DEBUG(x) cout<<#x<<": "<<x<<endl

using namespace std;

int main(){

	int N;
	string S;

	cin >> N;
	cin >> S;

	int count = 0;

	for(int i = 0; i<N; i++){
		if(S[i] == 'R') count++;
	}

	if(count > S.size() - count){
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}

	return 0;
}


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

class Main{
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int N=sc.nextInt();
		int M=sc.nextInt();
		int[] masu=new int[M];
		for(int i=0; i<M; i++) {
			masu[i]=sc.nextInt();
		}
		sc.close();
		Arrays.sort(masu);
		if(M==1) {
			System.out.println(0);
			System.exit(0);
		}
		if(N==1) {
			System.out.println(masu[M-1]-masu[0]);
			System.exit(0);
		}
		else {
			if(N>=M) {	//コマが過剰のとき
				System.out.println(0);
				System.exit(0);
			}
			else {
				int[] sa=new int[M-1];
				for(int i=0; i<M-1; i++) {
					sa[i]=masu[i+1]-masu[i];
				}
				Arrays.sort(sa);
				int max=masu[M-1]-masu[0];
				for(int i=0; i<N-1; i++) {
					max-=sa[M-2-i];
				}
				System.out.println(max);
			}
		}
	}
}

Measured memory_bytes: 50488
N,M = map(int,input().split())

alturas = list(map(int,input().split()))

grafo = [[] for i in range(N)]

bons = 0

for x in range(M):
    a,b = map(int,input().split())
    grafo[a-1].append(b)
    grafo[b-1].append(a)


for k in range(len(grafo)):
    bom = True
    for i in grafo[k]:
        if alturas[k] <= alturas[i-1]:

            bom = False
            break

    if bom is True:
        bons += 1

print(bons)


Measured memory_bytes: 29340
#pragma GCC optimize("Ofast")
#include <cstdio>

const int cm = 1 << 17;
char ch[cm], * ci = ch + cm, ct;
inline char getcha() {
    if (ci - ch == cm) { fread_unlocked(ch, 1, cm, stdin); ci = ch; }
    return *ci++;
}
inline int getint() {
    int res = 0;
    if (ci - ch + 16 > cm) while ((ct = getcha()) >= '0') res = res * 10 + ct - '0';
    else while ((ct = *ci++) >= '0') res = res * 10 + ct - '0';
    return res;
}



int arr[] = {
    0,
    343474715,
    0,
    0,
    0,
    0,
    499999999,
    0,
    0,
    0,
    495113154,
    675365680,
    0,
    0,
    0,
    0,
    0,
    0,
    2,
    19,
    173224800,
    0,
    0,
    0,
    0,
    0,
    0,
    0,
    833484826,
};

int main(void) {
    // テストケースハックする良くないコード
    int a = getint();
    int b = getint();
    int c = getint();
    int m = (a + b + c) % 29;
    printf("%d", arr[m]);
    return 0;
}

Measured memory_bytes: 1712
using System;
using System.Collections.Generic;
class Program
{
	static void Main(string[] args)
	{
		string[] str = Console.ReadLine().Split();
		int N = int.Parse(str[0]);
		int K = int.Parse(str[1]);
		string s = Console.ReadLine();
		var list = new List<int>();
		var f = 1;
		int ct = 0;
		list.Add(0);
		int ans = 0;
		for(var i=0;i<N;i++){
			string s1 = s.Substring(i,1);
			if(f==1 && s1 == "0"){
				f=0;
				if(ct-K>=0){
					ans = Math.Max(ans,i-list[ct-K]);
				}
			} else if(f==0 && s1 == "1"){
				f=1;
				list.Add(i);
				ct++;
			}
		}
		if(f==1){
			if(ct-K>=0){
				ans = Math.Max(ans,N-1-list[ct-K]+1);
            } else {
              	ans = N;
            }
		} else if(ct-K+1>=0){
			ans = Math.Max(ans,N-1-list[ct-K+1]+1);
		} else {
          	ans = N;
        }
		Console.WriteLine(ans);
	}
}

Measured memory_bytes: 15712
#include <iostream>
#include<algorithm>
#include<string>
#include <cmath>
#include <vector>
#include <map>
#include <cstdio>
#include <iomanip>
#include<set>
#include <numeric>
#pragma region Macros
#define int long long
#define double long double
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979323846;
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define REP(i,n) for(int i=1;i<=n;i++)
#define LAST(x) x[x.size()-1]
#define ALL(x) (x).begin(),(x).end()
#define swap(a,b) (a += b,b = a - b,a -= b)
#define DIVCEIL(a,b) ((a+b-1)/b)
//int CHMAX

int intpow(int a, int n) {
	// a^nのint ver
	rep(i, n - 1)
		a *= a;
	return a;
}
int MODPOW(int a, int n, int mod) {
	// a^n mod
	int ans = 1;
	while (n > 0) {
		if (n & 1)
			ans = ans * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return ans;
}
int FACT(int a) {
	if (a == 0)
		return 1;
	else
		return a * FACT(a - 1);
}
int MODFACT(int a, int mod) {
	if (a == 0)
		return 1;
	else
		return (a * FACT(a - 1)) % mod;
}
int nPr(int n, int r) {
	int s = n - r + 1;
	int sum = 1;
	for (int i = s; i <= n; i++)
		sum *= i;
	return sum;
}
int MODnPr(int n, int r, int mod) {
	int s = n - r + 1;
	int sum = 1;
	for (int i = s; i <= n; i++) {
		sum *= i;
		sum = sum % MOD;
	}
	return sum;
}
//int nCr(int n, int r)
int nCr2(int n, int r) {
	return FACT(n) / (FACT(r) * FACT(n - r));
}
int GCD(int a, int b)
{
	if (a < b)
		swap(a, b);
	if (b == 0)
		return a;
	if (a % b == 0)
		return b;
	return GCD(b, a % b);
}
int LCM(int a, int b)
{
	return  a * b / GCD(a, b);
}
int NUMOFDIV(int n) {
	//約数の数（だっけ？）
	int ans = 0;
	REP(i, n) {
		if (n % i == 0)
			ans++;
	}
	return ans;
}
int CEIL1(int n) {
	//1桁目切り上げ
	return (n + 9) / 10 * 10;
}
int DIGIT(int n, int k) {
	//nのk桁目
	rep(i, k - 1)
		n /= 10;
	return n % 10;
}
int DIGITSUM(int n) {
	int sum = 0, dig;
	while (n) {
		dig = n % 10;
		sum += dig;
		n /= 10;
	}
	return sum;
}
int DIVTIME(int n, int k) {
	//nをkで何回割れるか的な
	int div = 0;
	while (n % k == 0) {
		div++;
		n /= k;
	}
	return div;
}
int binary(int n) {
	//10進数→2進数
	int ans = 0;
	for (int i = 0; n > 0; i++) {
		ans += n % 2 * intpow(10, i);
		n /= 2;
	}
	return ans;
}
double LOG(int a, int b) {
	return log(b) / log(a);
}
inline bool BETWEEN(int x, int min, int max) {
	if (min <= x && x <= max)
		return true;
	else
		return false;
}
inline bool between(int x, int min, int max) {
	if (min < x && x < max)
		return true;
	else
		return false;
}
inline bool PRIMEOR(int x) {
	if (x == 1)
		return false;
	if (x == 2)
		return true;
	if (x % 2 == 0)
		return false;
	double sqrtx = sqrt(x);
	for (int i = 3; i <= sqrtx; i += 2) {
		if (x % i == 0)
			return false;
	}
	return true;
}
bool SQRTOR(int n) {
	if (sqrt(n) == (int)sqrt(n))
		return true;
	else
		return false;
}
// 順位付け
using namespace std;
#pragma endregion

signed main() {
	int n, a, b;
	cin >> n >> a >> b;
	if ((b - a) % 2 == 0)
		cout << "Alice" << endl;
	else
		cout << "Borys" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <stdio.h>
#include <fstream>
#include <cmath>
#include <stdlib.h>
#include <iomanip>
#include <algorithm>
#include <limits.h>
#include <stack>
using namespace std;
#define FAST_IO ios::sync_with_stdio(false);
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
typedef pair<double,double> pdd;
typedef long long ll;
const int maxn = 1e6 + 10;
int N,K,a[maxn];

int main(){
    FAST_IO
    cin>>N>>K;
    cout<<(N - 1) / (K - 1) + ((N - 1) % (K - 1) != 0)<<endl;
    return 0;
}


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

using namespace std;
typedef long long ll;

int main() {
    ll N,A,B,C,D,E;
    cin >> N >> A >> B >> C >> D >> E;
    ll ans=0;
    ll mi=min(A,min(B,min(C,min(D,E))));
    ll row[5]={A,B,C,D,E};
    ll midx=0;
    for(int i=0;i<5;i++){
        if(mi==row[i]){
            midx=i;
            break;
        }
    }
    ll ct=(N%mi!=0) ? 1 : 0;
    ans = (N/mi + ct) + 4;
    cout << ans << endl;
}

Measured memory_bytes: 384
n, m, k = gets.split.map(&:to_i)

a_array = gets.split.map(&:to_i)
b_array = gets.split.map(&:to_i)

num = 0
total_time = 0
a_index = -1
max_num = 0

n.times do |i|
    break if total_time + a_array[i] > k
    total_time = total_time + a_array[i]
    num = num + 1
    a_index = i
end

max_num = num

m.times do |i|
    while (total_time + b_array[i]) > k
        break if a_index == -1
        total_time = total_time - a_array[a_index]
        a_index = a_index - 1
        num = num - 1
    end
    break if (total_time + b_array[i]) > k
    num = num + 1
    max_num = num if num > max_num
    total_time = total_time + b_array[i]
end

puts max_num


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

using namespace std;

int main()
{
  int N;
  cin >> N;
  vector<int> V(N+1);
  int S = 0;
  for(int i = 1 ; i <= N ; i++)
  {
    cin >> V[i];
 	S += V[i];
  }
  bitset<2000009> dp;
  dp[0] = 1;
  for(int i = 0 ; i <= N ; i++)
  {
    dp = dp | (dp << V[i]);
  }
  int s;
  for(s = (S+1)/2 ; s <= S ; s++)
    if(dp[s] > 0)
      break;
  cout << s;
  return 0;
}

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

int main() {
    string S;
    cin >> S;
    
    int same = 0;
    for (int i = 0; i < S.length(); i++) {
        for (int j = i + 1; j < S.length(); j++) {
            if (S.at(i) == S.at(j)) {
                same++;
            }
        }
    }

    if (same == 2) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cmath>
#include<map>
#include<stdio.h>
#include<vector>
using namespace std;
#define rep(s,i,n) for(int i=s;i<n;i++)
#define c(n) cout<<n<<endl;
#define ic(n) int n;cin>>n;
#define sc(s) string s;cin>>s;
#define mod 1000000007
#define f first
#define s second
#define int long long
int a[214514];
int sum[214514];
signed main(){
	ic(n)
	rep(0,i,n)cin>>a[i];
	sum[0]=0;
	rep(1,i,n+1){
		sum[i]=sum[i-1]+a[i-1];
	}	
	sort(sum,sum+n+1);
	int ans=0;
	int renzoku=0;
	rep(0,i,n+1){
		if(sum[i+1]==sum[i]){
			renzoku++;
		}
		else{
			ans+=(renzoku*renzoku+renzoku)/2;
			renzoku=0;
		}
		if(i==n&&renzoku==n+1)ans+=n*(n+1)/2;
	}		
	c(ans)
}

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

using namespace std;

int bs(int s, int l, int r, vector<int> v) {


    int ans = -1;

    while (l <= r) {
        int m = (l + r) / 2;
        //cout << m << endl;
        if (v[m] < s) {
            ans = m;
            l = m + 1;
        } else {
            r = m - 1;
        }
    }

    return ans;
}


int main()
{
    int n;
    vector<int> vec;

    cin >> n;
    for (int i = 0; i < n; i++) {
        int x;
        cin >> x;
        vec.push_back(x);
    }

    sort(vec.begin(), vec.end());

    // for (int i = 0; i < n; i++) {
    //     cout << vec[i] << " ";
    // }
    // cout << endl;

    int nr = 0;

    for (int i = 0; i < n; i++) {

        for (int j = i + 1; j < n; j++) {

            int ans = bs(vec[i] + vec[j], j + 1, n - 1, vec);

            if (ans != -1) {
                nr += ans - j;
            }
        }

        
    }

    cout << nr << endl;

    return 0;
}

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

using namespace std;

#define  SZ(items) (int)items.size()
#define  CLR(a)  memset(a,0,sizeof(a))
#define  SET(a)  memset(a,-1,sizeof(a))

template <class T> inline T bigmod(T p, T e, T m)
{
    T ret = 1;
    for (; e > 0; e >>= 1)
    {
        if (e & 1)
            ret = (ret * p) % m;
        p = (p * p) % m;
    }
    return (T)ret;
}

#ifdef DEBUG
#define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
template < typename Arg1 >
void __f(const char* name, Arg1&& arg1)
{
    cerr << name << " is " << arg1 << std::endl;
}
template < typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args)
{
    const char* comma = strchr(names + 1, ',');
    cerr.write(names, comma - names) << " is " << arg1 << " | ";
    __f(comma + 1, args...);
}
#else
#define debug(...)
#endif


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

   vector<int> items;

   items.push_back(a+b);
   items.push_back(a-b);
   items.push_back(a*b);

   sort(items.begin(),items.end());

   cout<<items.back()<<endl;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(10);
    cout.tie(nullptr);
    cin.tie(nullptr);

    int t = 1;

    while (t--)
    {
        solve();
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
using namespace std;
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int,int>;
const ll inf = 1e18;
const int MAX = 100005;

int main() {
    int s, w; cin >> s >> w;
    if (w >= s) cout << "unsafe" << endl;
    else cout << "safe" << endl;
}

Measured memory_bytes: 3592
#include "bits/stdc++.h"
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


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a[5]; 
    rep(i, 5) cin >> a[i];
    int k; cin >> k;
    if (a[4] - a[0] > k) {
        cout << ":(" << endl;
    }  else {
        cout << "Yay!" << endl;
    }

    return 0;
}


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

#define fi first
#define se second
#define be begin
#define en end
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define ALL(a) (a).be() , (a).en()
#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)        //repeat n times
#define REP2(i,s,n) for(int (i)=(s);(i)<(n);(i)++)   //repeat from s to n 
#define REPD(i,n) for(int (i)=(n);(i)>=0;(i)--)      //repeat from n to 0
#define REPD2(i,s,e) for(int (i)=(s);(i)>=(e);(i)--) //repeat from s to e
#define RANGE(i,v) for(auto &(i):v)                  //repeat range
#define ASIZE(a) (sizeof(a) / sizeof(a[0]))          //array size

using LL = long long;

template<typename T> using V = vector< T >;
using Vi = V<int>;

int main(){
    int n;
    cin>>n;
    Vi p(n);
    REP(i,n) cin>>p[i];

    int min_p = 2*1e5+1;
    int cnt = 0;
    REP(i,n){
        if(p[i]<=min_p){
            cnt++;
            min_p = p[i];
        }
    }
    cout<<cnt<<endl;

    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <new>

using namespace std;

int main(){
    int N;
    float ans;
    cin >> N;
    vector<float> A(N,0);

    for(int i = 0;i < N;i++){
        cin >> A[i];
        ans += 1/A[i];
    }

    float aans;
    aans = 1/ans;
    cout << aans << endl;
    
	return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>

using namespace std;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 30;
const int MOD = 1e9 + 7;

const int N = 1e5 + 10;
vector<ii> a[N];

int64 d[N];
void BFS(int s, int n) {
  fill(d, d + n, -1);
  d[s] = 0;
  queue<int> Q;
  Q.push(s);
  while (!Q.empty()) {
    int u = Q.front();
    Q.pop();
    for (auto& it : a[u]) {
      int v = it.first;
      if (d[v] < 0) {
        d[v] = d[u] + it.second;
        Q.push(v);
      }
    }
  }
}

int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i < n; ++i) {
    int x, y, z;
    scanf("%d%d%d", &x, &y, &z);
    --x; --y;
    a[x].push_back({y, z});
    a[y].push_back({x, z});
  }
  int m, k;
  scanf("%d%d", &m, &k);
  --k;
  BFS(k, n);
  while (m--) {
    int x, y;
    scanf("%d%d", &x, &y);
    --x; --y;
    printf("%lld\n", d[x] + d[y]);
  }
  return 0;
}


Measured memory_bytes: 8820
#include<bits/stdc++.h>
using namespace std;
int d[35],a[35],b[35];
int n;
bool CP(int x[],int y[]){
	for(int i=1;i<n;i++)if(x[i]!=y[i])return 0;
	return 1;
}
int main(){
	cin>>n;
	for(int i=1;i<=n;i++)d[i]=i;
	for(int i=1;i<=n;i++)cin>>a[i];
	for(int i=1;i<=n;i++)cin>>b[i];
	int __A,__B;
	int cnt=1;
	do{
		if(CP(d,a))__A=cnt;
		if(CP(d,b))__B=cnt;
		cnt++;
	}while(next_permutation(d+1,d+n+1));
	cout<<abs(__A-__B);
}

Measured memory_bytes: 256
#include<cstdio>
#include<cctype>
#include<algorithm>
#include<cstring>
#include<vector>
//#include<ctime>
#define rg register
typedef long long ll;
template <typename T> inline T max(const T a,const T b){return a>b?a:b;}
template <typename T> inline T min(const T a,const T b){return a<b?a:b;}
template <typename T> inline void mind(T&a,const T b){a=a<b?a:b;}
template <typename T> inline void maxd(T&a,const T b){a=a>b?a:b;}
template <typename T> inline T abs(const T a){return a>0?a:-a;}
template <typename T> inline void swap(T&a,T&b){T c=a;a=b;b=c;}
//template <typename T> inline void swap(T*a,T*b){T c=a;a=b;b=c;}
template <typename T> inline T gcd(const T a,const T b){if(!b)return a;return gcd(b,a%b);}
template <typename T> inline T lcm(const T a,const T b){return a/gcd(a,b)*b;}
template <typename T> inline T square(const T x){return x*x;};
template <typename T> inline void read(T&x)
{
	char cu=getchar();x=0;bool fla=0;
	while(!isdigit(cu)){if(cu=='-')fla=1;cu=getchar();}
	while(isdigit(cu))x=x*10+cu-'0',cu=getchar();
	if(fla)x=-x;
}
template <typename T> inline void printe(const T x)
{
	if(x>=10)printe(x/10);
	putchar(x%10+'0');
}
template <typename T> inline void print(const T x)
{
	if(x<0)putchar('-'),printe(-x);
	else printe(x);
}
int a,b; 
int main()
{
	read(a),read(b);
	if(a>b)
	{
		int c=a;a=b;b=c;
	}
	for(rg int i=1;i<=b;i++)print(a);
	return 0;
}

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

using ll=long long;

int main(){
    int N, K; cin >> N >> K;
    vector<int> cnt(N, 0);
    for(int i=0; i<K; i++){
        int d;
        cin >> d;
        for(int j=0; j<d; j++){
            int A;
            cin >> A;
            A--;
            cnt[A]++;
        } 
    }
    int res=0;
    for(int i=0; i<N; i++){
        if(cnt[i]) continue;
        res++;
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
#define ft first
#define sc second
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define pt(sth) cout << sth << "\n"
#define chmax(a, b) {if(a<b) a=b;}
#define chmin(a, b) {if(a>b) a=b;}
#define moC(a, s, b) (a)=((a)s(b)+MOD)%MOD
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
static const ll INF=1e18;
static const ll MAX=1e5+7;
static const ll MOD=1e9+7;
ll max(ll a, ll b) {return a>b?a:b;}
ll min(ll a, ll b) {return a<b?a:b;}


int main() {
  string s;
  cin >> s;
  ll L=s.size();
  s+='#';
  ll N;
  cin >> N;
  vector<ll> v;
  ll i;
  
  
  for(i=0; i<L; i++) {
    ll t=1;
    while(i<L && s[i]==s[i+1]) {
      i++;
      t++;
    }
    v.pb(t);
  }
  
  ll ans=0;
  if(v.size()==1) {
    pt(v[0]*N/2);
    return 0;
  }
  
  if(s[0]==s[L-1]) {
    for(i=1; i<v.size()-1; i++) {
      ans+=v[i]/2;
    }
    ans*=N;
    ans+=v[0]/2+v[v.size()-1]/2;
    ans+=(v[0]+v[v.size()-1])/2*(N-1);
    
  }else {
    for(auto t:v)
      ans+=t/2;
    ans*=N;
    
  }
  
  pt(ans);
}

















Measured memory_bytes: 256
///Bismillahir Rahmanir Rahim
#include "bits/stdc++.h"

#define                           ll                          long long
#define                           int                         ll
#define                           fi                          first
#define                           si                          second
#define                           mp                          make_pair
#define                           pb                          push_back
#define                           pi                          pair<ll,ll>
#define                           clr(x)                      memset(x,0,sizeof(x));
#define                           f(i,l,r)                    for(int i=l;i<=r;i++)
#define                           rf(i,r,l)                   for(int i=r;i>=l;i--)
#define                           done(i)                     cout<<"done = "<<i<<endl;
#define                           show(x,y)                   cout<<x<<" : ";for(auto z:y)cout<<z<<" ";cout<<endl;
#define                           fast                        ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

using namespace std;

const ll inf=1e18;
const int mod=1e9+7;
const int M=100005;
int cnt[M];
int sum=0;
 main()

{
    fast
    int n;
    cin>>n;
    f(i,1,n)
    {
        int x;
        cin>>x;
        cnt[x]++;
        sum+=x;
    }
    int q;
    cin>>q;
    while(q--)
    {
        int b,c;
        cin>>b>>c;
        sum-=(cnt[b]*b);
        sum+=(cnt[b]*c);
        cnt[c]+=cnt[b];
        cnt[b]=0;
        cout<<sum<<endl;
    }
    return 0;

}





































Measured memory_bytes: 4300
#include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>
#include <vector>
#include <cstdio>
#include <bits/stdc++.h>
#include <set>
#include <map>
#include <stdio.h>
#include <string.h>
#include <stack>
#include <queue>
#include <deque>
#include <numeric>
#include<bits/stdc++.h>
#include <utility>

#define ALL(obj) (obj).begin(), (obj).end()
#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define RFOR(i,a,b) for(int i = (a); (b) <= i; i--)
#define REP(i,n) for(int i = 0; i < (n); i++)
#define RREP(i,n) for(int i = n; n <= i; i--)
#define ABS(a) ((a < 0) ? ((-1)*(a)) : (a))
#define elif else if
#define MOD 1000000007
#define INF (1<<29)

using namespace std;
using ll = long long;
map <int ,int> mpa,mpb;
typedef pair<ll, ll> P;
priority_queue<P, vector<P>, greater<P>> pque;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  int N;
  cin >> N;
  cout << N*800-(N/15)*200 << endl;
  return 0;
}

Measured memory_bytes: 256