akhauriyash/Code-Regression huggingface dataset:
using System;

class Plogram
{
    static void Main()
    {
        string str = Console.ReadLine();

        int num = 0;

        for(int i = 0; i < 4; i++)
        {
            if(str.Substring(i,1) == "+")
            {
                num++;
            }
            if(str.Substring(i,1) == "-")
            {
                num--;
            }
        }
        Console.WriteLine(num);
    }
}

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

using namespace std;

using int64 = long long;

struct Edge {
  const int from, to;
  Edge(int from, int to) : from(from), to(to) {}
};

vector<vector<Edge>> ReadUndirectedGraph(
    int n, int m, bool is_one_indexed=false) {
  vector<vector<Edge>> graph(n);
  for (int i = 0; i < m; i++) {
    int v1, v2;
    cin >> v1 >> v2;
    if (is_one_indexed) {
      v1--;
      v2--;
    }
    graph[v1].push_back(Edge({v1, v2}));
    graph[v2].push_back(Edge({v2, v1}));
  }
  return graph;
}

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

  int n, q;
  cin >> n >> q;
  auto graph = ReadUndirectedGraph(n, n - 1, true);
  vector<int> nodes(n);
  for (int i = 0; i < q; i++) {
    int v;
    int x;
    cin >> v >> x;
    v--;
    nodes[v] += x;
  }

  vector<int> values(n);
  function<void(int, int, int)> dfs = [&](int v, int parent, int value) {
    value += nodes[v];
    values[v] = value;
    for (const auto& edge : graph[v]) {
      if (edge.to == parent) continue;
      dfs(edge.to, v, value);
    }
  };
  dfs(0, -1, 0);

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

Measured memory_bytes: 30592
n = int(input())
S = [input() for i in range(n)]
check = set(S[0])
ans = []

for c in check:
    num = float('inf')
    for s in S:
        num = min(num, s.count(c))
        
    ans.append(num*c)
print(''.join(sorted(''.join(ans))))

Measured memory_bytes: 3060
#include <iostream>

using namespace std;

void solve()
{
	int a;
	while(cin >> a)
	{
		int b;
		cin >> b;
		int sum = a + b;
		int count = 0;
		while(sum)
		{
			sum /= 10;
			++count;
		}
		cout << count << endl;
	}
}

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

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

#define SIZE_OF_ARRAY(array) sizeof(array)/sizeof(array[0])

struct towers{
    vector<int> hei;
};

int main() {
    int N, M;
    cin >> N >> M;
    vector<towers> v;
    for(int i = 0; i < N; i++){
        vector<int> pro = {};
        v.push_back({pro});
    }
    vector<int> H;
    for(int i = 0; i < N; i++){
        int height;
        cin >> height;
        H.push_back(height);
    }
    for(int i = 0; i < M; i++){
        int start, goal;
        cin >> start >> goal;
        v.at(start-1).hei.push_back(goal-1);
        v.at(goal-1).hei.push_back(start-1);
    }
    int count = 0;
    for(int i = 0; i < N; i++){
        int isit = true;
        for(int k = 0; k < v.at(i).hei.size(); k++){
            if(H.at(i) <= H.at(v.at(i).hei.at(k))){
                isit = false;
                break;
            }
        }
        if(isit){
            count++;
        }
    }
    cout << count;
}

Measured memory_bytes: 8780
#include <iostream>
#include <algorithm>
using namespace std;
 
int gcd(int a, int b) {
    return b == 0? a:gcd(b, a%b);
}

int gcdt(int a, int b, int c) {
    return gcd(a, gcd(b, c));
}

int main()
{
    int a, b, c;
    int k;
    cin >> k;
    long long sum = 0;
    for (a = 1; a <= k; ++a)
        for (b = 1; b <= k; ++b)
            for (c = 1; c <= k; ++c){
                sum += gcdt(a, b, c);
            }
            cout << sum << endl;
    return 0;
}

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

int main(){
  int n = 0, m = 0;
  cin >> n >> m;
  int h[n] = {0};
  int r[n];
  for(int x=0; x<n; x++)	r[x] = 2;
  
  for(int i=0; i < n; i++){
    cin >> h[i];
  } // length record
  
  for(int j=0; j < m; j++){ // m pathes
    int a = 0, b = 0; // 2 buildings, a and b
    cin >> a >> b;
    if(h[a-1] > h[b-1]){ // find the higher one
      if(r[a-1] != 0)	r[a-1] = 1; // if no one is higher than a, sets to 1
      r[b-1] = 0; // once not the higher one, no chance to become a good buliding
    }
    else if(h[a-1] < h[b-1]){
      r[a-1] = 0;
      if(r[b-1] != 0)	r[b-1] = 1;
    }
    else{
      r[a-1] = 0;
      r[b-1] = 0;
    }
  }
  int count = 0;
  for(int k=0; k < n; k++){
    if(r[k] != 0)	count++;
  }
  cout << count << endl;
  return 0;
}


Measured memory_bytes: 4376
#include <iostream>
using namespace std;
int main()
{
    int n, max = 0, min = 1000000000, empty;
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        cin >> empty;
        if (empty >= max) max = empty;
        if (empty <= min) min = empty;
    }
    cout << max - min << endl;
    return (0);
}

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

int main(void){
        int zeni;
        int many1;

        cin>>zeni;
        cin>>many1;

        int jo = zeni % 500;
        if(jo > many1){
                cout<<"No";
        }else{
                cout<<"Yes";
        }
        cout<<endl;
        return 0;
}


Measured memory_bytes: 256
/*i-=-1*/
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#define in(n) for(int i=0;i<n;i++)
#define inj(n) for(int j=0;j<n;j++)
#define itn int
#define int ll int 
#define ll long long
#define ull unsigned ll
#define int ll int
#define S second 
#define F first 
#define mod 1000000007
#define globalbool 2000000
#define pii pair<int,int>
#define vi vector<int>
#define test int tc;for(cin>>tc;tc>0;tc--)
#define all(x) x.begin(),x.end()
#define pb push_back
using namespace std;
using namespace std::chrono;
int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);cout.tie(NULL);
	auto start = high_resolution_clock::now();
	string s,t;
	cin>>s>>t;
	s+=(t[t.size()-1]);
	if(s==t)
		cout<<"Yes"<<endl;
	else
		cout<<"No"<<endl;
	auto stop = high_resolution_clock::now();
    //auto duration = duration_cast<microseconds>(stop - start); 
  
    //cout << "Time taken by function: "
    //<< duration.count() << " microseconds" << endl;
}
//g++ -DLOCAL -std=c++17 -Wshadow -Wall -o "h" "h.cpp" -fsanitize=address
// -fsanitize=undefined -D_GLIBCXX_DEBUG -g

Measured memory_bytes: 3624
import java.util.*;

class Main {
    public static void main(String args[]) {
        Scanner inp = new Scanner(System.in);
        int a = inp.nextInt();
        int b = inp.nextInt();
        int x = inp.nextInt();
        if (a <= x && x <= a + b) System.out.println("YES");
        else System.out.println("NO");
        inp.close();
    }
}


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

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

    int64_t ans = 0;
    for(int i=0; i<N-1; i++){
        int add = max(0, A[i] - A[i+1]);
        A[i+1] += add;
        ans += add;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4040
#include<bits/stdc++.h>
using namespace std;
#define lli long long int
#define rep(i,n) for(lli i=0;i<n;i++)
#define repb(i,n) for(lli i=n-1;i>=0;i--)
#define pb push_back
#define mp make_pair
#define bg() begin()
#define en() end()
#define ft first
#define sc second
#define vect_lli_it vector<lli>::iterator
#define set_lli_it set<lli>::iterator
#define inf 1e18
#define all(X) X.begin(),X.end()
#define iterate(X) for(it=X.begin();it!=X.end();it++)
lli combi(lli n,lli k)
{
    lli ans=1;
    k=k>n-k?n-k:k;
    lli j=1;
    for(;j<=k;j++,n--)
    {
        if(n%j==0)
        {
            ans*=n/j;
        }else
        if(ans%j==0)
        {
            ans=ans/j*n;
        }else
        {
            ans=(ans*n)/j;
        }
    }
    return ans;
}
lli gcd(lli a, lli b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}
lli findlcm(vector <lli> arr, lli n)
{
    lli ans = arr[0];
    for (lli i = 1; i < n; i++)
        ans = (((arr[i] * ans)) /
                (gcd(arr[i], ans)));

    return ans;
}
int main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    lli n;
    cin>>n;
    lli check=0;
    while(n>0){
    	lli r=n%10;
    	if(r==7){
    		check=1;
		}
		n=n/10;
	}
	if(check==1)
	cout<<"Yes";
	else
	cout<<"No";
    return 0;
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define loop(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  loop(i,0,n)
#define all(c) c.begin(),c.end()
#define rall(c) c.rbegin(),c.rend()
#define vi vector<int>
#define vl vector<ll>
#define pll pair<ll,ll>
#define vpll vector<pll>

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

    vector<bool> f(n+1);

    rep(i,m){
        int tmp;
        cin>>tmp;
        f[tmp]=true;
    }

    vl dp(n+2);
    ll int con=1000000007;
    dp[n]=1;
    for(int i=n-1;i>=0;i--){
        if(f[i]){
            dp[i]=0;
            continue;
        }
        dp[i]=(dp[i+1]+dp[i+2])%con;

    }
    cout<<dp[0]<<endl;


}


Measured memory_bytes: 1024
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);

    int l = sc.nextInt();

    BigDecimal a = new BigDecimal(l).divide(new BigDecimal(3), 6, RoundingMode.DOWN);
    BigDecimal w = a;
    BigDecimal h = a;
    BigDecimal d = a;

    BigDecimal cube = w.multiply(h).multiply(d);

    BigDecimal rect;
    BigDecimal oldRect = cube;
    while (true) {
      w = w.subtract(BigDecimal.valueOf(0.1));
      h = h.add(BigDecimal.valueOf(0.1));
      rect = w.multiply(h).multiply(d);
      if (cube.compareTo(rect) > 0) {
        System.out.println(oldRect.doubleValue());
        return;
      }
      oldRect = rect;
    }
  }
}

Measured memory_bytes: 23252
import           Data.List  (find)
import           Data.Maybe (fromJust)

main :: IO ()
main = print . solve . map fromChar =<< getLine

data Cube =
    Red
  | Blue
  deriving (Eq)

fromChar :: Char -> Cube
fromChar '0' = Red
fromChar '1' = Blue
fromChar _   = error "unexpected character"

solve :: [Cube] -> Int
solve cubes =
  let
    convergence' = fromJust $ convergence $ iterate annihilate'' cubes
  in
    length cubes - length convergence'

annihilate :: [Cube] -> [Cube]
annihilate []                = []
annihilate [c]               = [c]
annihilate (Red : Blue : cs) = annihilate cs
annihilate (Blue : Red : cs) = annihilate cs
annihilate (c : cs)          = c : annihilate cs

annihilate' :: [Cube] -> [Cube]
annihilate' cs = foldr f [] $ zip cs $ tail cs
  where
    f (Red, Blue) cs' = cs'
    f (Blue, Red) cs' = cs'
    f (c1, c2) cs'    = c2 : cs'

annihilate'' :: [Cube] -> [Cube]
annihilate'' cs = foldr f [] cs
  where
    f Red (Blue : cs') = cs'
    f Blue (Red : cs') = cs'
    f c cs'            = c : cs'

converge :: Eq a => [a] -> [a]
converge [] = []
converge [x] = [x]
converge (x : xs@(y: _))
  | x == y    = [x]
  | otherwise = x : converge xs

convergence :: Eq a => [a] -> Maybe a
convergence = fmap fst . find (uncurry (==)) . (zip <*> tail)


Measured memory_bytes: 13692
#include<stdio.h>

int Fibonacci(int);

int f[44];

int main(){

  int i,n;

  for(i=0;i<45;i++){
    f[i] = -1;
  }

  scanf("%d",&n);
  printf("%d\n",Fibonacci(n));

  return 0;
}

int Fibonacci(int n){

  if(n == 0 || n == 1) return f[n] = 1;
  if(f[n] != -1) return f[n];
  return f[n] = Fibonacci(n-2) + Fibonacci(n-1);
  
}



Measured memory_bytes: 2084
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ll n,i,j;
    cin>>n;
    string s;
    vector< pair< string,ll > >v;
    v.push_back({"AC",0});
    v.push_back({"WA",0});
    v.push_back({"TLE",0});
    v.push_back({"RE",0});
    for(i=0;i<n;i++)
    {
        cin>>s;
        for(j=0;j<4;j++)
        {
            if(v[j].first==s)
            {
                v[j].second++;
            }
        }
    }
    for(i=0;i<4;i++)
        cout<<v[i].first<<" x "<<v[i].second<<endl;
}


Measured memory_bytes: 3628
#!/usr/bin/ruby
def insertionSort(a, n, g)
    for i in g..n-1
        v = a[i]
        j = i - g
        while j >= 0 && a[j] > v
            a[j+g] = a[j]
            j = j - g
            $cnt+=1
            a[j+g] = v
        end
    end
end
 
def shellSort(a, n)
    $cnt = 0
    g = []
    h = 1
    while h <= n
        g << h
        h = 3*h+1
    end
    g.reverse!
    m = g.size
    p m
    puts g*' '
    for i in 0..m-1
        insertionSort(a, n, g[i])
    end
end
 
#a=[9,8,5,1,7,4,6,3,2]
a=gets.to_i.times.map{gets.to_i}
shellSort(a,a.size)
p $cnt
puts a

Measured memory_bytes: 14056
//INCLUDE
//------------------------------------------
#include <bits/stdc++.h>
//DEFINE
//------------------------------------------
#define ll long long
#define ALLv(a)  (a).begin(),(a).end()
#define ALL(a,n)  (a),(a)+n
#define vi vector<long long>
#define vd vector<long double>
#define vs vector<string>
//CONST
//------------------------------------------
#define INF 1010000000000000017LL
#define MOD 1000000007LL
#define EPS 1e-12
#define PI 3.14159265358979323846
//REPEAT
//------------------------------------------
#define   FOR(i,m,n) for(ll (i)=(m);   (i)<(n);  (i)++)
#define   REP(i,n)   for(ll (i)=0;     (i)<(n);  (i)++)
#define  REPS(i,x)   for(ll (i)=1;     (i)<=(x); (i)++)
#define  RREP(i,x)   for(ll (i)=(x)-1; (i)>=0;   (i)--)
#define RREPS(i,x)   for(ll (i)=(x);   (i)> 0;   (i)--)
#define  WREP(i,in,j,jn) REP(i,in)REP(j,jn)
using namespace std;
//-------------------------------------------

int main(void){
  ll N,M;cin>>N>>M;
  ll ans=0;
  if(N>=2)ans+=N*(N-1)/2;
  if(M>=2)ans+=M*(M-1)/2;
  cout<<ans;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
using vi = vector<int64_t>;
using vvi = vector<vi>;

int main(int argc, const char * argv[]) {
    // fasten cin
    cin.tie(0);
    ios::sync_with_stdio(false);
    // implement
    int64_t k,a,b;
    cin >> k >> a >> b;
    if(a/k != b/k || a%k==0 || b%k==0){
        cout << "OK" << endl;
    }else{
        cout << "NG" << endl;
    }
}

Measured memory_bytes: 3652
#include <iostream>
#include <algorithm>
#include <queue>
#include <stack>
#include <deque>
#include <climits>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
//#include <tuple>

#define INF INT_MAX>>1 
#define SIZE 100010
#define MOD 1000000007
#define rep(i, n) for(int i=0; i<(int)(n); i++)
#define rep2(i, from, to) for(int i=(from); i<(int)(to); i++)
#define repr(i, n) for(int i=(n-1); 0<=i; i--)
#define repr2(i, from, to) for(int i=(from-1); (int)(to)<=i; i--)
#define ALL(obj) (obj).begin(), (obj).end()
typedef long long ll;

using namespace std;

struct Point { int x, y; };
struct Edge { int to, cost; };
struct Node { int from, to, cost; };

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

int gcd(int a, int b){ return a % b == 0 ? b : gcd(b, a%b); }
int lcm(int a, int b){ return a * b/ gcd(a, b); }
int extgcd(int a, int b, int& x, int& y){
	int d = a;
	if(b != 0){
		d = extgcd(b, a%b, y, x);
		y -= (a/b) * x;
	} else{
		x = 1; y = 0;
	}
	return d;
}
ll mod_pow(ll x, ll n){
	if(n == 0) return 1;
	ll res = mod_pow(x*x % MOD, n/2);
	if(n & 1) res = res * x % MOD;
	return res;
}

int main(void){
	int n; cin >> n;
	vector<double> v(n);
	rep(i, n){
		cin >> v[i];
	}
	sort(v.begin(), v.end());

	double prev = (v[0]+v[1]) / 2;
	rep2(i, 2, n){
		prev = (prev+v[i]) /2;
	}
	cout << prev << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>
#include <random>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define RREP(i,m,n) for(int i=int(n)-1;i>=int(m);--i)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
//#define int long long

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

void solve() {
    int n;
    cin >> n;
    VLL a(n);
    REP(i,0,n) cin >> a[i];
    REP(i,0,n) if (a[i] == 0) {
        cout << 0 << endl;
        return;
    }
    LL mul = 1,in;
    REP(i,0,n) {
        in = a[i];
        LL rem = 1'000'000'000'000'000'000 / mul;
        if (in > rem || mul * in > 1'000'000'000'000'000'000LL) {
            cout << -1 << endl;
            return;
        }
        mul *= in;
    }   
    cout << mul << endl;
}

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

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

int main() {
  ll a,v,b,w,t;
  cin>>a>>v>>b>>w>>t;
  if(v<=w){cout<<"NO";}
  else{
    if((v-w)*t>=max(a-b,b-a)){cout<<"YES";}
    else{cout<<"NO";}
  }
}
   

Measured memory_bytes: 3624
a, b, k = map(int, input().split())
for i in range(1, k + 1):
    if i % 2 != 0:
        if a % 2 != 0:
            a -= 1
        a = a // 2
        b += a
    else: 
        if b % 2 != 0:
            b -= 1
        b = b // 2
        a += b
print(a,b)

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

typedef long long ll;
typedef pair<ll, ll> P;

const ll MOD = 1e9 + 7;
const ll inf = 1LL<<60;
const int int_inf = 100000000;
const double eps = 1e-9;

const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };
 
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }


int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n;
    cin >> n;

    vector<int> a(n, 0);

    for (int i = 0; i < n-1; i++) {
        int tmp;
        cin >> tmp;
        a[tmp-1]++;
    }

    for (int i = 0; i < n; i++) cout << a[i] << endl;
    return 0;
}



Measured memory_bytes: 4000
program tenquestiontwo
 implicit none
 character(3) s
 integer i, n, res
 res = 0
 read(*,*) s
  do 10 i = 1,3
  read(s(i:i),*) n
   if (n.EQ.1) then
   res = res + 1
   end if
  10 continue
 write(*,*) res 
end program

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <iomanip>
#include <vector>
#include <cstdlib>
#include <cmath>
#include <numeric>
#include <algorithm>
#include <sstream>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <deque>
#include <bitset>
using namespace std;

#define rep(i, n) for (int i=0; i<int(n); i++)
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))
using ll = long long;


int main() {
	ll n, k;
	cin >> n >> k;

	ll s = n/k;
	ll res;
	if (k%2==0) {
		ll t = (n+k/2)/k;
		res = s*s*s + t*t*t;
	}
	else {
		res = s*s*s;
	}
	cout << res << endl;
}

Measured memory_bytes: 3616
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#define LL long long
#define double long double
using namespace std;
const double pi=acos(-1);
struct poLL {LL  x,y,num;}p[110],a[110];
double ans[110];
LL multi(poLL  p1,poLL  p2,poLL  p0)
{
	LL x1=p1.x-p0.x,y1=p1.y-p0.y;
	LL x2=p2.x-p0.x,y2=p2.y-p0.y;
	return x1*y2-x2*y1;
}
LL  n,top=0,sta[110];
LL  dis(poLL  a,poLL  b) {return (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y);}
//double dis(double x,double y,double x1,double y1) {return sqrt((x-x1)*(x-x1)+(y-y1)*(y-y1));}
bool cmp(poLL a,poLL b)
{
	LL t1=multi(b,a,p[1]);
	return t1==0?dis(p[1],a)<dis(p[1],b):t1<0;
}
/*void solve()
{
	for(LL  i=2;i<=n;i++)
		if((p[1].x==p[i].x)?(p[i].y<p[1].y):(p[i].x<p[1].x)) swap(p[1],p[i]);
	sort(p+2,p+n+1,cmp);
	sta[++top]=1;
	for(LL  i=2;i<=n;i++)
	{
		while(top>1&&multi(p[sta[top]],p[sta[top-1]],p[i])<=0) top--;
		sta[++top]=i;
	}
}
bool cmp(poLL A,poLL b)
{
    double tmp=multi(A,b,p[1]);
    return tmp==0?dis(A.x,A.y,p[1].x,p[1].y)<dis(b.x,b.y,p[1].x,p[1].y):tmp>0;
}*/
void solve()
{
	for(int i=2;i<=n;i++)
        if(p[i].y<p[1].y||p[i].y==p[1].y&&p[i].x<p[1].x) swap(p[1],p[i]);
    sort(p+2,p+n+1,cmp);
    sta[1]=1;sta[2]=2;top=2;
    for(int i=3;i<=n;i++)
    {
        while(top>1&&multi(p[sta[top]],p[i],p[sta[top-1]])<0) top--;
        sta[++top]=i;
    }
}
double get(poLL  p1,poLL  p2,poLL  p0)
{
	LL x1=p1.x-p0.x,y1=p1.y-p0.y;
	LL x2=p2.x-p0.x,y2=p2.y-p0.y;
	return (double)(x1*x2+y1*y2)/(sqrt(x1*x1+y1*y1)*sqrt(x2*x2+y2*y2));
}
void calc()
{
	if(top==0) for(LL  i=1;i<=top;i++) ans[p[sta[i]].num]=0.5;
	else
	{
		sta[0]=sta[top];sta[top+1]=sta[1];
		for(LL  i=1;i<=top;i++)
		{
			double tmp=get(p[sta[i-1]],p[sta[i+1]],p[sta[i]]);
			double s=pi-acos(tmp);
			ans[p[sta[i]].num]=s/(pi*2);
		}
	}
}
int  main()
{
	scanf("%lld",&n);
	for(LL  i=1;i<=n;i++) scanf("%lld %lld",&p[i].x,&p[i].y),p[i].num=i;
	if(n==1) return puts("1.000000000000"),0;
	solve();calc();
	for(LL i=1;i<=n;i++) printf("%.9Lf\n",ans[i]);
}

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

using namespace std;

typedef long long int ll;
typedef pair<int,int> P;

#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<(b);i++)
#define repr(i,b,a) for(int i=int(b);i>=(a);i--)
#define all(x) x.begin(),x.end()

const ll mod = 1e9+7;
const ll INF = 1e9;

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
bool valid(int lx,int ux,int ly,int uy,int x,int y){
	return lx<=x&&x<ux&&ly<=y&&y<uy; 
}
ll power(ll x,ll p){
	if(p==0)return 1;
	ll res=power(x*x%mod,p/2);
	if(p%2==1)res=res*x%mod;
	return res;
}

int main()
{
	int n,m;
	cin>>n>>m;
	vector<vector<int>> g(n,vector<int>());
	vector<int> in_deg(n,0);
	rep(i,m){
		int x,y;
		cin>>x>>y;
		x--,y--;
		g[x].push_back(y);
		in_deg[y]+=1;
	}

	vector<int> dp(n,0);

	queue<int> S;
	rep(i,n)if(in_deg[i]==0)S.push(i);
	while(!S.empty()){
		int cur=S.front();S.pop();
		for(auto next: g[cur]){
			in_deg[next]--;
			if(in_deg[next]==0){
				S.push(next);
				dp[next] = max(dp[next],dp[cur]+1);
			}
		}
	}
	cout<<*max_element(all(dp))<<endl;
	return 0;
}

Measured memory_bytes: 9412
# D - Triangles

import bisect

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

sum = 0

length.sort()

for i in range(n):
    for j in range(n):

            a = length[i]
            b = length[j]

            if i < j:
                k = bisect.bisect_left(length, a + b)
                sum += k - j - 1

print(max(0, sum))

Measured memory_bytes: 3316
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#include <fstream>
#include <chrono>
#include <random>
#include <bitset>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) ((int)(x).size())
#define pb push_back
#define mod 1000000007
using ll = long long;
using namespace std;
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}


vector<ll> fac(202000), finv(202000), inv(202000);
void initcom(){
  fac[0] = fac[1] = finv[0] = finv[1] = inv[1] = 1;
  for(int i=2; i<202000; i++){
    fac[i] = (fac[i-1]*i) % mod;
    inv[i] = mod - inv[mod%i] * (mod/i) % mod;
    finv[i] = finv[i-1] * inv[i] % mod;
  }
}
ll nCr(ll n,ll r){
  ll res = 1;
  for(ll i=0; i<r; i++){
    res *= (n-i);
    res %= mod;
  }
  for(ll i=1; i<=r; i++){
    res *= inv[i];
    res %= mod;
  }
  return res%mod;
}

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

int main(){
  initcom();
  ll N; cin >> N;
  ll A, B; cin >> A >> B;
  ll ans = mpow(2,N)-1;
  ans -= (nCr(N,A)+nCr(N,B));
  ans += mod;
  ans += mod;
  ans += mod;
  cout << ans%mod << endl;
  return 0;
}


Measured memory_bytes: 4992
#include<bits/stdc++.h>
    using namespace std;
    int n,q;
    vector<int> edge[200010];
    int f[200010];
    bool book[200010];
    int ans[200010];
    void solve(int x,int tot)
    {
    	if(book[x]) return;
    	book[x]=1;
    	tot+=f[x];
    	ans[x]=tot;
    	for(vector<int>::iterator it=edge[x].begin();it!=edge[x].end();it++)
    	solve(*it,tot);
    }
    int main()
    {
    	cin>>n>>q;
    	for(int i=1;i<n;i++)
    	{
    		int x,y;
    		scanf("%d%d",&x,&y);
    		edge[x].push_back(y);
    		edge[y].push_back(x);
    	}
    	for(int i=1;i<=q;i++)
    	{
    		int x,y;
    		scanf("%d%d",&x,&y);
    		f[x]+=y;
    	}
    	solve(1,0);
    	for(int i=1;i<=n;i++)
    	printf("%d ",ans[i]);
    }

Measured memory_bytes: 21120
import java.io.*;
import java.nio.CharBuffer;
import java.util.NoSuchElementException;

public class Main {

    public static void main(String[] args) {
        SimpleScanner scanner = new SimpleScanner(System.in);
        PrintWriter writer = new PrintWriter(System.out);

        int n = scanner.nextInt();
        int x = scanner.nextInt();
        int cur = 0, ans = 0;
        for (int i = 0; i < n; ++i) {
            int t = scanner.nextInt();
            cur += t;
            if (cur <= x)
                ++ans;
        }
        writer.println(ans + 1);

        writer.close();
    }

    private static class SimpleScanner {

        private static final int BUFFER_SIZE = 10240;

        private Readable in;
        private CharBuffer buffer;
        private boolean eof;

        SimpleScanner(InputStream in) {
            this.in = new BufferedReader(new InputStreamReader(in));
            buffer = CharBuffer.allocate(BUFFER_SIZE);
            buffer.limit(0);
            eof = false;
        }


        private char read() {
            if (!buffer.hasRemaining()) {
                buffer.clear();
                int n;
                try {
                    n = in.read(buffer);
                } catch (IOException e) {
                    n = -1;
                }
                if (n <= 0) {
                    eof = true;
                    return '\0';
                }
                buffer.flip();
            }
            return buffer.get();
        }

        void checkEof() {
            if (eof)
                throw new NoSuchElementException();
        }

        char nextChar() {
            checkEof();
            char b = read();
            checkEof();
            return b;
        }

        String next() {
            char b;
            do {
                b = read();
                checkEof();
            } while (Character.isWhitespace(b));
            StringBuilder sb = new StringBuilder();
            do {
                sb.append(b);
                b = read();
            } while (!eof && !Character.isWhitespace(b));
            return sb.toString();
        }

        int nextInt() {
            return Integer.valueOf(next());
        }

        long nextLong() {
            return Long.valueOf(next());
        }

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

Measured memory_bytes: 21332
#include <stdio.h>


int main ()
{
    int a,b,c,abc,bca,cab;
    scanf("%d%d%d",&a,&b,&c);
    abc=a+b;
    bca=b+c;
    cab=c+a;
    if(abc<= bca && abc<= cab)
    {
        printf("%d\n",abc);
    }
    else if(bca<= abc && bca<= cab)
    {
        printf("%d\n",bca);
    }
    else
    {
        printf("%d\n",cab);
    }

    return 0;
}


Measured memory_bytes: 128
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char) 
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let s: String = read();

    let v: Vec<char> = s.chars().collect();

    if v[2] == v[3] && v[4] == v[5] {
        println!("Yes");
    } else {
        println!("No");
    }
}


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

using ll = long long;
using pii = pair<int, int>;
template <class T>
using V = vector<T>;
template <class T>
using VV = V<V<T>>;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i, n) rep2(i, 0, n)
#define rep2(i, m, n) for (int i = m; i < (n); i++)
#define per(i, b) per2(i, 0, b)
#define per2(i, a, b) for (int i = int(b) - 1; i >= int(a); i--)
#define ALL(c) (c).begin(), (c).end()
#define SZ(x) ((int)(x).size())

constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); }

template <class T, class U>
void chmin(T& t, const U& u) {
    if (t > u) t = u;
}
template <class T, class U>
void chmax(T& t, const U& u) {
    if (t < u) t = u;
}

template <class T, class U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
    os << "(" << p.first << "," << p.second << ")";
    return os;
}

template <class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
    os << "{";
    rep(i, v.size()) {
        if (i) os << ",";
        os << v[i];
    }
    os << "}";
    return os;
}

#ifdef LOCAL
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << H;
    debug_out(T...);
}
#define debug(...) \
    cerr << __LINE__ << " [" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#define dump(x) cerr << __LINE__ << " " << #x << " = " << (x) << endl
#else
#define debug(...) (void(0))
#define dump(x) (void(0))
#endif

int main() {
    ll A, V, B, W, T;
    cin >> A >> V >> B >> W >> T;
    ll d = abs(A - B);
    if (d <= T * (V - W)) {
        puts("YES");
    } else {
        puts("NO");
    }
    return 0;
}

Measured memory_bytes: 3652
import java.util.*;
import java.util.stream.*;

public class Main {
	Scanner sc;
	String S;
	int[] count;
	
//=============
// constructor
//
	public Main() {
		sc = new Scanner(System.in);
	}
	
//==================
// instance methods
//
	/**
	 * アルゴリズム本体
	 */
	private void calc() {
		S = sc.next();
		count = new int[S.length()];
		for (int i = 0; i < S.length();) {
			int j;
			for (j = i; j < S.length(); j++) {
				if (S.charAt(j) == 'L') break;
			}
			for (int k = i; k < j; k++) {
				if ( (j-k)%2 == 0 ) count[j]++;
				else count[j-1]++;
			}
			i = j;
			if (i >= S.length()) break;
			for (j = i+1; j < S.length(); j++) {
				if (S.charAt(j) == 'R') break;
			}
			for (int k = i; k < j; k++) {
				if ( (k-i)%2 == 0 ) count[i]++;
				else count[i-1]++;
			}
			i = j;
		}
		out(IntStream.of(count)
					.mapToObj(c -> String.valueOf(c))
					.collect(Collectors.joining(" ")));
	}
	
	private void out(Object o) {
		System.out.println(o);
		System.out.flush();
	}
	
//======
// main
//
	public static void main(String[] args) {
		Main m = new Main();
		m.calc();
	}

}

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

using namespace std;

int main(int argc, const char *argv[]) {
  int n;
  string s;
  cin >> n >> s;

  int ans = 0;
  for (int i = 0; i <= s.size() - 3; i++) {
    if (s.substr(i, 3) == "ABC") {
      ans++;
    }
  }

  cout << ans << "\n";
  return 0;
}

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

#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")

//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

#define XX              first
#define YY              second
#define PB              push_back
#define MP              make_pair

#define NEWLINE         cerr << "\n";
#define HOISE           cerr << "hoise " << __LINE__ << "\n"
#define PAUSE           system("pause")
#define DEBUG(x)        cerr << #x << " = " << x << "\n"
#define FASTIO          ios_base::sync_with_stdio(false);cin.tie(NULL)

typedef long long ll;
typedef pair<int, int > pii;
typedef pair<ll, ll> pll;

const int INF = 1e9 + 23;
const ll INFL = 2e18 + 23;

int32_t main()
{
    FASTIO;

    int n, m, k;
    cin >> n >> m >> k;
    vector<string> s(n);
    for(int i = 0; i < n; i++)
        cin >> s[i];

    int ans = 0;

    for(int m1 = 0; m1 < (1<<n); m1++){
        for(int m2 = 0; m2 < (1<<m); m2++){
            for(int i = 0; i  < n; i++)
                for(int j = 0; j < m; j++)
                    if(((m1&(1<<i)) or (m2&(1<<j))) and s[i][j]=='#') s[i][j] = 'r';
        
            int cnt = 0;
            for(int i = 0; i < n; i++)
                for(int j = 0; j < m; j++)
                    cnt += (s[i][j]=='#');
        
            if(cnt == k)
                ans++;
        
            for(int i = 0; i  < n; i++)
                for(int j = 0; j < m; j++)
                    if(((m1&(1<<i)) or (m2&(1<<j))) and s[i][j]=='r') s[i][j] = '#';
        }
    }

    cout << ans;

    return 0;
}

Measured memory_bytes: 3628
/*
  Compete against Yourself.
  Author - Aryan Choudhary (@aryanc403)
*/

#pragma GCC optimize ("Ofast")
#pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize ("-ffloat-store")

#include<iostream>
#include<bits/stdc++.h>
using namespace std;
#define fo(i,n)   for(i=0;i<(n);++i)
#define repA(i,j,n)   for(i=(j);i<=(n);++i)
#define repD(i,j,n)   for(i=(j);i>=(n);--i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define endl "\n"

typedef long long int lli;
typedef long double mytype;
typedef pair<lli,lli> ii;
typedef vector<ii> vii;
typedef vector<lli> vi;

clock_t time_p=clock();
void aryanc403()
{
#ifdef ARYANC403
    time_p=clock()-time_p;
    cerr<<"Time Taken : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";
#endif
}

#ifdef ARYANC403
#include "/home/aryan/codes/PastCodes/header.h"
#else
    #define dbg(args...)
#endif

const lli INF = 0xFFFFFFFFFFFFFFFL;

lli seed;
mt19937 rng(seed=chrono::steady_clock::now().time_since_epoch().count());
inline lli rnd(lli l=0,lli r=INF)
{return uniform_int_distribution<lli>(l,r)(rng);}

class CMP
{public:
bool operator()(ii a , ii b) //For min priority_queue .
{    return ! ( a.X < b.X || ( a.X==b.X && a.Y <= b.Y ));   }};

void add( map<lli,lli> &m, lli x,lli cnt=1)
{
    auto jt=m.find(x);
    if(jt==m.end())         m.insert({x,cnt});
    else                    jt->Y+=cnt;
}

void del( map<lli,lli> &m, lli x,lli cnt=1)
{
    auto jt=m.find(x);
    if(jt->Y<=cnt)            m.erase(jt);
    else                      jt->Y-=cnt;
}

bool cmp(const ii &a,const ii &b)
{
    return a.X<b.X||(a.X==b.X&&a.Y<b.Y);
}

const lli mod = 1000000007L;
// const lli maxN = 1000000007L;

    lli T,n,i,j,k,in,cnt,l,r,u,v,x,y;
    lli m;
    string s;
    vi a;
    //priority_queue < ii , vector < ii > , CMP > pq;// min priority_queue .

int main(void) {
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    // freopen("txt.in", "r", stdin);
    // freopen("txt.out", "w", stdout);
// cout<<std::fixed<<std::setprecision(35);
// cin>>T;while(T--)
{

    cin>>n;
    cin>>s;
    fo(i,n)
    {
        if(s.substr(i,3)=="ABC")
            cnt++;
    }
    cout<<cnt<<endl;
}   aryanc403();
    return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <stdlib.h>
#include <vector>
#include <stack>

using namespace std;


int main(){

	int n, p;

	while(1){
		cin >> n;
		cin >> p;
		if(n ==0 && p==0) break;

		int sum[n];
		int win=p;
		int winner;
		int flag = 0;

		for(int i=0 ; i<n ; i++){
			sum[i] = 0;
		}

		while(1){
			for(int i=0 ; i<n ; i++){
				if(p>0){
					sum[i]++;
					p--;
					if(sum[i]==win){
						flag = 1;
						winner = i;
						break;
					}
				}else{
					p = sum[i];
					sum[i] = 0;
				}
			}

			if(flag == 1) break;
		}

		cout << winner << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iomanip>
#include <numeric>
#include <queue>
#include <cmath>
using namespace std;

const int mod = 1e9 + 7;
    
long long int mygcd(long long int a, long long int b) {
    a = abs(a);
    b = abs(b);
    while (a % b != 0 && b % a != 0) {
        if (a > b) {
            a %= b;
        } else {
            b %= a;
        }
    }
    return min(a, b);
}

long long int mypow(long long int a, long long int b) {
    if (b == 0) return 1;
    if (b == 1) return a;
    long long int res = mypow(a, b / 2);
    res = res * res % mod;
    if (b % 2 == 1) res = res * a % mod;
    return res;
}

int main() {
    int n;
    cin >> n;
    int two_zero = 0;
    int left_zero = 0, right_zero = 0;
    unordered_map<long long int, unordered_map<long long int, long long int>> um;
    for (int i = 0; i < n; i++) {
        long long int a, b;
        cin >> a >> b;
        if (a == 0 && b == 0) {
            two_zero++;
            continue;
        }
        if (a == 0) {
            left_zero++;
            continue;
        }
        if (b == 0) {
            right_zero++;
            continue;
        }
        long long int c = mygcd(a, b);
        a /= c;
        b /= c;
        if (a < 0) {
            a = -a;
            b = -b;
        }
        um[a][b]++;
    }
    vector<long long int> v;
    auto um2 = um;
    for (auto p1 : um) {
        for (auto p2 : p1.second) {
            long long int a = p1.first, b = p2.first;
            long long int c = um2[a][b];
            if (c == 0 || a == 0 || b == 0) continue;
            long long int next_a = abs(b), next_b = a;
            if (b < 0) 
                next_b = a; 
            else 
                next_b = -a;
            if (um2[next_a].find(next_b) == um2[next_a].end()) {
                v.push_back(mypow(2, c));
            } else {
                v.push_back((mypow(2, c) + mypow(2, um2[next_a][next_b]) - 1) % mod);
                um2[next_a][next_b] = 0;
            }
            um2[a][b] = 0;
        }
    }
    if (um.size() == 0 && left_zero == 0 && right_zero == 0) {
        cout << n << endl;
        return 0;
    }

    long long int res = (mypow(2, left_zero) + mypow(2, right_zero) - 1 + mod) % mod;
    for (auto num : v) {
        res = res * ((num + mod) % mod) % mod;
    }
    res += two_zero;
    res--;
    res += mod;
    res %= mod;
    cout << res << endl;
}


Measured memory_bytes: 82416
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,x,n) for(int i=x;i<n;i++)
#define pb push_back
#define mp make_pair
#define fir first
#define sec second
#define MAX 100005
#define int long long
using namespace std;
const int MOD=1000000007;
const int INF=1000000009;



signed main(){
  string s;
  cin>>s;
  bool v[4]={};
  rep(i,s.size()){
    if(s[i]=='N')v[0]=true;
    else if(s[i]=='W')v[1]=true;
    else if(s[i]=='S')v[2]=true;
    else v[3]=true;
  }
  if((v[0]==true&&v[2]==false)||(v[2]==true&&v[0]==false)||(v[1]==true&&v[3]==false)||(v[3]==true&&v[1]==false)){
    cout<<"No"<<endl;
  }else{
    cout<<"Yes"<<endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ALL(A) (A).begin(), (A).end()
#define ll long long
#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int dx[] = { 0, 1, -1, 0, 1, -1, 1, -1 };  // i<4:4way i<8:8way
int dy[] = { 1, 0, 0, -1, 1, -1, -1, 1 };

const ll mod = 1e9 + 7;
const ll INF = -1 * ((1LL << 63) + 1);
const int inf = 1e9+7;

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    int n,query,k;
    cin >> n;
    vector<vector<ll>> to(n),cost(n);
    rep(i,n-1){
        int a,b,c;
        cin >> a >> b >> c;
        a--;b--;
        to[a].push_back(b);
        to[b].push_back(a);
        cost[a].push_back(c);
        cost[b].push_back(c);
    }
    cin >> query >> k;
    k--;
    vector<ll> d(n,0);
    d[k] = 0;
    queue<int> q;
    q.push(k);
    while(!q.empty()){
        int now = q.front();q.pop();
        for(int i=0;i<to[now].size();i++){
            int next = to[now][i];
            if(d[next])continue;
            d[next] = d[now] + cost[now][i];
            q.push(next);
        }
    }
    rep(_,query){
        int x,y;
        cin >> x >> y;
        x--;y--;
        cout << d[x] + d[y] << endl;
    }
}

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

using ll = long long;

vector<int> a;
int n, M;
int Q(int k){
	int f = -1;
	for(int i = 0; i < k; i++){
		f = max(f, (a[i] + a[2*k-1-i]) % M);
	}
	for(int i = 0; i < (n - k); i++){
		int r = a[2*k + i] + a[2*n-1-i];
		if(r < M) return -1;
		f = max(f, r - M);
	}
	assert(f < M);
	return f;
}
int main(){
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	cin >> n >> M;
	a.resize(2*n);
	for(int i = 0; i < 2*n; i++) cin >> a[i];
	sort(a.begin(), a.end());
	int s = -1; // not
	int e = n; // fine
	while(s + 1 < e){
		int m = (s + e) / 2;
		if(Q(m) == -1){
			s = m;
		} else {
			e = m;
		}
	}
	s++;
	e = n;
	int ans = M;
	ans = min(ans, Q(e));
	ans = min(ans, Q(s));
	while(s + 3 < e){
		int m1 = (s + s + e) / 3;
		int m2 = (s + e + e) / 3;
		if(Q(m1) <= Q(m2)){
			e = m2;
		} else {
			s = m1;
		}
	}
	for(int m = s; m <= e; m++){
		ans = min(Q(m), ans);
	}
	cout << ans << endl;
}


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

int main() {
  int n;cin>>n;
  vector<int> h(n);
  rep(i,n)cin>>h[i];
  int cnt=0;;
  rep(i,n){
    if(cnt<h[i])h[i]--;
    if(cnt>h[i]){
      cout<<"No"<<endl;
      return 0;
    }
    cnt=max(cnt,h[i]);
  }
  cout<<"Yes"<<endl;
}

Measured memory_bytes: 3768
#include <bits/stdc++.h>
#define int long long
#define all(x) x.begin(),x.end()
#define ini(x,y) memset(x,y,sizeof(x))
#define cauto const auto &
#define cint const int &
#define F(x, y, z) for (int x = y; x <= z; x++)
#define D(x, y, z) for (int x = y; x >= z; x--)
using namespace std;
const int INF = 0x3f3f3f3f3f3f3f3f;
const int MAXN = static_cast<int>(1e5 + 25);
inline int read()
{
  int x = 0, y = 1, c = getchar();
  while (c > '9' || c < '0')
  {
    if (c == '-')
    {
      y = -1;
    }
    c = getchar();
  }
  while (c >= '0' && c <= '9')
  {
    x = x * 10 + c - '0';
    c = getchar();
  }
  return x * y;
}
/*
 * 用最短的时间取得胜利！！！！
*/
struct road{
    int to,v;
    road(int to=0,int v=0):to(to),v(v){}
};

static vector<road> edge[MAXN];
struct heapnode{
    int to,val;
    heapnode(int T=0,int V=0):to(T),val(V){}
    bool operator<(const heapnode r)const{
        return val>r.val;
    }
};
static priority_queue<heapnode> q;
static int d[MAXN];
void dijkstra(){
    ini(d,0x3f);
    d[0]=0;
    q.push(heapnode(0,0));
    while(!q.empty()){
        int pos=q.top().to;
        q.pop();
        for(auto to:edge[pos]){

            if(d[pos]+to.v<d[to.to]){
                d[to.to]=d[pos]+to.v;//cout<<pos<<" "<<to.to<<" "<<d[to.to]<<endl;
                q.push(heapnode(to.to,d[to.to]));
            }
        }
    }
}
signed main(){
    int k=read();
    F(i,1,k-1){
        int now=i;
        F(j,1,9){
            edge[(i+j)%k].push_back(road(i,j));
            now*=10;
            edge[now%k].push_back(road(i,0));
        }
    }
    dijkstra();
//    int minn=INF;
    printf("%lld",d[1]+1);
    return 0;
}


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
    int N;
    cin >> N;
    vector<int> H(N);

    rep(i, N)
        cin >> H.at(i);
    
    int ans = 0;
    int minv = 0;
    rep(i, N) {
        if (H.at(i) >= minv) {
            ans++;
            minv = H.at(i);
        }
    }

    cout << ans << endl;
}

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

#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define MIN(a) *min_element(all(a))
#define MAX(a) *max_element(all(a))
#define SUM(a) accumulate(all(a), 0LL)
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define RREP(i, n) for(int (i)=(n)-1; (i)>=0; (i)--)
#define FOR(i, m, n) for(int (i)=(m); (i)<(n); i++)
#define FORR(i, m, n) for(int (i)=(n)-1; (i)>=(m); i--)
#define debug(x) cerr << #x << " = " << x << endl
//#define int long long

typedef long long ll;
ll const MOD = 998244353;
//ll const MOD = 1e9+7;
int const inf = 1e9;
ll const INF = 1e18;

inline void ios_(){cin.tie(0); ios::sync_with_stdio(false);}
template<typename T> int size(const T& a){return (int)a.size();}
template<typename T> T Div(T a, T b){return (a + b - 1) / b;}
template<typename T> bool chmin(T& a, const T& b){if(a > b){a = b; return true;} return false;}
template<typename T> bool chmax(T& a, const T& b){if(a < b){a = b; return true;} return false;}



signed main(){
    int n;
    string s;
    cin >> n >> s;

    vector<int> left, right;
    int r = 0, g = 0, b = 0;
    REP(i, 3*n){
        if(s[i] == 'R') r++;
        else if(s[i] == 'G') g++;
        else b++;

        if(r > 0 && g > 0 && b > 0){
            right.push_back(i);
            r--;
            g--;
            b--;
        }
    }

    r = g = b = 0;

    RREP(i, 3*n){
        if(s[i] == 'R') r++;
        else if(s[i] == 'G') g++;
        else b++;

        if(r > 0 && g > 0 && b > 0){
            left.push_back(i);
            r--;
            g--;
            b--;
        }
    }

    vector<int> v(3*n);
    for(auto i : left){
        v[i] = 1;
    }
    for(auto i : right){
        v[i] = 2;
    }

    ll ans = 1;

    int cnt = 0;
    REP(i, 3*n){
        if(v[i] == 0){
            ans *= cnt;
            ans %= MOD;
            cnt--;
        }else if(v[i] == 1){
            cnt++;
        }
    }

    cnt = 0;
    RREP(i, 3*n){
        if(v[i] == 0){
            ans *= cnt;
            ans %= MOD;
            cnt--;
        }else if(v[i] == 2){
            cnt++;
        }
    }

    for(int i=1; i<=n; i++){
        ans *= i;
        ans %= MOD;
    }
    
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 2688
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, core.bitop;


void main() {
    int d, n;
    scan(d, n);

    if (n == 100) {
        writeln(100^^(d+1) + 100^^d);
        return;
    }

    writeln(100^^d * n);
}













































void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}



void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}


Measured memory_bytes: 256