akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define err(args...) {}
#ifdef DEBUG
#include "_debug.cpp"
#endif
using namespace std;
using ll = long long;
using ld = long double;
template <typename T> using lim = numeric_limits<T>;
template <typename T> istream& operator>>(istream& is, vector<T>& a) { for(T& x : a) { is >> x; } return is; }
template <typename X, typename Y> istream& operator>>(istream& is, pair<X, Y>& p) { return is >> p.first >> p.second; }
template <typename T, typename TEachPrime, typename TEachUniquePrime = function<void(T)>>
constexpr void factorize(T n, TEachPrime&& each_prime, TEachUniquePrime&& each_unique_prime = [](T) {}) {
    static_assert(is_convertible<decltype(each_prime), function<void(T)>>::value, "each_prime must be void(T)");
    static_assert(is_convertible<decltype(each_unique_prime), function<void(T)>>::value, "each_unique_prime must be void(T)");
    for(T i = 2; i * i <= n; i++) {
        if(n % i == 0) {
            each_unique_prime(i);
            while(n % i == 0) {
                each_prime(i);
                n /= i;
            }
        }
    }
    if(n > 1) {
        each_prime(n);
        each_unique_prime(n);
    }
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    ll n;
    cin >> n;
    map<int, int> fac;
    factorize(n, [&](int p) {
        fac[p]++;
    });
    int ans = 0;
    for(auto [p, e] : fac) {
        for(int i = 1, j = 0; j + i <= e; j += i, i++) {
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3672
// {{{
#include <iostream>
#include <iomanip>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <complex>
#include <vector>
#include <list>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <string>
#include <algorithm>
#include <numeric>
using namespace std;

#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define FOR(i, a, b) for(ll i = static_cast<ll>(a); i < static_cast<ll>(b); i++)
#define FORR(i, a, b) for(ll i = static_cast<ll>(a); i >= static_cast<ll>(b); i--)
#define REP(i, n) for(ll i = 0ll; i < static_cast<ll>(n); i++)
#define REPR(i, n) for(ll i = static_cast<ll>(n); i >= 0ll; i--)
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> IP;
typedef pair<ll, LP> LLP;

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

constexpr int INF = 100000000;
constexpr ll LINF = 10000000000000000ll;
constexpr int MOD = static_cast<int>(1e9 + 7);
constexpr double EPS = 1e-9;

static inline ll mod(ll x, ll m)
{
    ll y = x % m;
    return (y >= 0 ? y : y+m);
}

// }}}

int N;
int v[50];

void solve()
{
    priority_queue<double, vector<double>, greater<double> > q;
    REP(i, N) q.push((double)v[i]);
    while(q.size() > 1){
        double x = q.top(); q.pop();
        double y = q.top(); q.pop();
        q.push((x+y)/2.);
    }
    cout << fixed << setprecision(10) << q.top() << endl;
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N;
    REP(i, N) cin >> v[i];
    solve();
    return 0;
}

// vim:set foldmethod=marker:


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

func min(a, b int) int {
	if a >= b {
		return b
	}
	return a
}

func main() {
	var n, k int
	fmt.Scan(&n, &k)
	h := make([]int, n)
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	for i := range h {
		sc.Scan()
		h[i], _ = strconv.Atoi(sc.Text())
	}
	sort.Ints(h)
	ans, diff := 10000000000, 0
	for i := 0; i+k-1 < n; i++ {
		diff = h[i+k-1] - h[i]
		ans = min(ans, diff)
	}
	fmt.Println(ans)
}


Measured memory_bytes: 3072
import heapq

n = int(input())
A = list(map(int, input().split()))
Left_top = A[:n]
Right_bottom = [-i for i in A[-n:]]
L = [0]*(n+1)
R = [0]*(n+1)
L[0] = sum(Left_top)
R[-1] = sum(Right_bottom)
heapq.heapify(Left_top)
heapq.heapify(Right_bottom)
for i in range(n, 2*n):
  L[i-n+1] = L[i-n] - heapq.heappushpop(Left_top, A[i]) + A[i]
  R[2*n-i-1] = R[2*n-i] - heapq.heappushpop(Right_bottom, -A[-(i+1)]) - A[-(i+1)]
ans = -float("inf")
for i in range(n+1):
  ans = max(ans, L[i] + R[i])
print(ans)

Measured memory_bytes: 40196
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;

class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Task solver = new Task();
        solver.solve(in, out);
        out.close();
    }

    static class Task {
        void solve(InputReader in, PrintWriter out) {
            int N = in.nextInt();
            out.println(N > 999 ? "ABD" : "ABC");
        }
    }

    static class InputReader {
        BufferedReader reader;
        StringTokenizer tokenizer;

        InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream));
            tokenizer = null;
        }

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

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

Measured memory_bytes: 22996
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;

int main() {
	int n;
	string s;
	cin >> n >> s;
	int ans = 0, cnt = 0;
	for(int i = 0 ; i < n ; i++){
		if(s[i] == 'R') cnt++;
	}
	ans = cnt;
	for(int i = 0 ; i < cnt ; i++){
		if(s[i] == 'R') ans--;
	}
	cout << ans;
	return 0;
}

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

int main() {
  string key;
  cin >> key;
  for (int i=1; i<4; i++) {
    if ( key[i] == key[i-1] ) {
      cout << "Bad" << endl;
      return 0;
    }
  }
  cout << "Good" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <vector>
#include <queue>
#include <string>
#include <limits>
#include <algorithm>
#include <map>
#include <sstream>
#include <unordered_map>

using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
static ull tenq = 1000000000;
static ull mod = tenq + 7;

using namespace std;

int main()
{
  ull N, X;
  cin >> N >> X;

  vector<ull> pati(51);
  vector<ull> pan(51);

  pati[0] = 1;
  pan[0] = 0;
  for (auto i = 1; i <= 50; i++) {
    pati[i] = pati[i-1] + pati[i-1] + 1;
    pan[i] = pan[i-1] + pan[i-1] + 2;
  }

  ull level = N;
  ull res = 0;
  while (1) {
    if (level == 0) {
      res++;
      break;
    }
    ull rec_size = pati[level-1] + pan[level-1];
    ull mid = 1llu + rec_size + 1llu;
    if (X == 1) break;
    else if (X < mid) {
      X--;
    }
    else if (X == mid) {
      res += pati[level-1] + 1llu;
      break;
    }
    else if (X < (mid + rec_size + 1llu)) {
      X -= mid;
      res += pati[level-1] + 1llu;
    } else {
      res += pati[level-1] + pati[level-1] + 1llu;
      break;
    }
    level--;
  }

  cout << res << endl;

  return 0;
}


Measured memory_bytes: 888
#include <iostream>
#include <cmath>
#include <cstring>
#include <climits>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <list>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <cassert>
#include <unordered_map>

#define DEBUG false
#define OJ_DEBUG

#define $(x) {if (DEBUG) {cout << __LINE__ << ": "; {x} cout << endl;}}
#define _(x) {cout << #x << " = " << x << " "; }
const double E = 1e-8;
const double PI = acos(-1);

using namespace std;

typedef long long ll;
typedef std::pair<int, int> pii;
typedef unsigned long ul;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    ll N, A, B;
    cin >> N >> A >> B;
    cout << A * (N / (A + B)) + min(A, N % (A+B)) << '\n';
    return 0;
}

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

//#define Saiyan

using namespace std;

int main()
{
    #ifdef Saiyan
  freopen("inp.txt","r",stdin) ;
  freopen("out.txt","w",stdout) ;
  #endif


    long long int i,j,ans=0,c=0,n,a[100][26],l,mn[100];

    string s;
    char ca[1];

    for(i=0;i<100;i++)
    {
        mn[i]=1000000;
    }

    for(i=0;i<100;i++)
    {
        for(j=0;j<26;j++)
        {
            a[i][j]=0;
        }
    }

    cin>>n;

    for(i=0;i<n;i++)
    {
        cin>>s;

        l=s.length();

        for(j=0;j<l;j++)
        {
            a[i][s[j]-'a']++;
        }

    }

    for(i=0;i<26;i++)
    {
        for(j=0;j<n;j++)
        {
            mn[i]=min(mn[i],a[j][i]);
        }
        //cout<<mn[i]<<" ";
    }

    for(i=0;i<26;i++)
    {
        if(mn[i]==0)
        {
            continue;
        }
        else
        {
            while(mn[i]!=0)
            {
                mn[i]--;
                ca[0]='a';
                ca[0]+=i;
                cout<<ca[0];
            }
        }
    }

	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
 
class Main {
 
	public static void main(String[] args) {
		
		Scanner stdIn = new Scanner(System.in);
 
		int A = stdIn.nextInt();
		int B = stdIn.nextInt();

		if(A == B ){
			System.out.print("Yes");
		}else{
			System.out.print("No");
		}

	}
    
}

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

void solve(int p, int q) {
    map<int,int> r;
    int rr;
    vector<int> d;
    r[p] = -1;
    for (int i=0; ; ++i) {
        p *= 10;
        d.push_back(p / q);
        p %= q;
        if (p == 0) {
            for (int x: d) cout << x;
            cout << endl;
            return;
        }
        if (r.count(p)) {
            rr = r[p];
            break;
        }
        r[p] = i;
    }

    for (int x: d) cout << x;
    cout << endl;
    for (int i=0; i<(int)d.size(); ++i) {
        cout << (rr < i ? "^": " ");
    }
    cout << endl;
}

int main() {
    ll p, q;
    while (cin >> p >> q) {
        solve(p, q);
    }
    return 0;
}


Measured memory_bytes: 3128
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
 
using namespace std;
using ll = long long;

bool test = false;

void print_vector(vector<int> vec){
    for (int item : vec){
        cout << item << flush;
    }
    cout << endl << flush;
}

void print_mat(vector<vector<int>> mat){
    for (vector<int> vec : mat){
        print_vector(vec);
    }
}

int _div2(int n1){
    int cnt = 0;
    while (n1%2==0){
        n1 = n1 / 2;
        cnt += 1;
    }
    return cnt;
}

int _sub(vector<int> a){
    int n = a.size();
    vector<int> res(n, 0);
    res[0] = 1;
    int prv = 0;
    for (int i=0; i<n-1; i++){
        prv += -_div2(i+1) + _div2(n-i-1);
        if (prv==0) res[i+1] = 1;
        else res[i+1] = 0;
    }
    int out = 0;
    for (int i=0; i<n; i++){
        out += res[i] * a[i];
        out %= 2;
    }
    if (test){
        print_vector(a);
        print_vector(res);
        cout << out << endl;
    }
    return out;
}

void Main(){
    int n;
    cin >> n;
    vector<int> a(n);
    string line;
    cin >> line;
    for (int i=0; i<n; i++){
        a[i] = line[i] - '1';
    }
    int out = _sub(a);
    if (out) {
        cout << 1;
        return ;
    }
    auto found = find(a.begin(), a.end(), 1);
    if ((found==a.end())){
        vector<int> b(n);
        for (int i=0; i<n; i++){
            b[i] = a[i]/2;
        }
        int out = _sub(b);
        if (out) {
            cout << 2;
        }
        else cout << 0;
    }
    else{
        cout << 0;
    }
}

int main(void){
    std::cin.tie(nullptr);
	std::ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
    Main();
}

Measured memory_bytes: 16916
#include<bits/stdc++.h>
#define V vector
#define VI vector<int>
#define VVI vector<vector<int>>
#define REP(i,n) for(ll i=0;i<(n);i++)
#define FOR(i,m,n) for(ll i=m;i<n;i++)
#define MOD 1000000007
#define INF 1e9
#define F first
#define S second
#define All(x) (x).begin(),(x).end()
typedef long long ll;
const double PI = acos(-1);
using namespace std;



int main(void){
    int N;cin>>N;
    VI a(N);
    VVI idx(N);
    int m_a=0;
    REP(i,N){
        cin>>a[i];
        a[i]--;
        idx[a[i]].push_back(i);
        m_a=max(m_a,a[i]);
    }

    if(idx[0].size()==0){
        cout<<-1<<endl;
        return 0;
    }

    int now_idx=-1,cnt=0;
    //cout<<idx[1][0]<<endl;
    REP(j,m_a+1){
        int check=0;
        for(int i=0;i<idx[cnt].size();i++){
            //cout<<"!"<<endl;
            if(idx[cnt][i]>now_idx){
                //cout<<"!!"<<i<<endl;
                now_idx=idx[cnt][i];
                cnt++;
                check=1;
                break;
            }
        }
        if(check==0){
            cout<<N-cnt<<endl;
            return 0;
        }
    }

    cout<<N-cnt<<endl;


}




Measured memory_bytes: 12032
n,m,c=map(int,input().split())
b=list(map(int,input().split()))
a=[list(map(int,input().split())) for k in range(n)]
 
count=0
 
for i in range(n):
  absum=0
  for j in range(m):
    absum +=a[i][j]*b[j]
   
  ans=absum+c
  if ans>0:
    count+=1
      
print(count)

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>
#include <bitset>
#include <time.h>
#include <tuple>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = (1LL << 60) - 1;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,N) for(int i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1
#define MAX_N 100100 * 3

int n;

int main() {
	cin >> n;
	int ans = 0;
	int cnt = 0;
	rep(i, n) {
		int a;
		cin >> a;
		if (a % 4 == 0)ans += 2;
		else if (a % 2 == 0)cnt++;
	}
	if (cnt > 0)ans += (cnt - 1);
	if (ans >= n - 1)cout << "Yes" << endl;
	else cout << "No" << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<cstdlib>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>
#include<map>
#include<iomanip>

using namespace std;

typedef long long ll;

const int MAX_V = 100010;
const int MAX_LOG_V = 17;
vector<int> G[MAX_V];

class TREE {

   public:
      int parent[MAX_LOG_V][MAX_V];
      int depth[MAX_V];

      void dfs(int v, int p, int d) {
         parent[0][v] = p;
         depth[v] = d;
         for (int i = 0; i < G[v].size(); i++) {
            if (G[v][i] != p) dfs(G[v][i], v, d + 1);
         }
      }

      void init(int V, int root) {
         dfs(root, -1, 0);
         for (int k = 0; k + 1 < MAX_LOG_V; k++) {
            for (int v = 0; v < V; v++) {
               if (parent[k][v] < 0) parent[k + 1][v] = -1;
               else parent[k + 1][v] = parent[k][parent[k][v]];
            }
         }
      }

      int lca(int u, int v) {
         if (depth[u] > depth[v]) swap(u, v);
         for (int k = 0; k < MAX_LOG_V; k++) {
            // if k th digit of depth[v] - depth[u] is 1
            if ((depth[v] - depth[u]) >> k & 1) {
               v = parent[k][v];
            }
         }
         if (u == v) return u;
         for (int k = MAX_LOG_V - 1; k >= 0; k--) {
            if (parent[k][u] != parent[k][v]) {
               u = parent[k][u];
               v = parent[k][v];
            }
         }
         return parent[0][u];
      }
};

int main() {
   int N;
   cin >> N;
   int k;
   for (int i = 0; i < N; i++) {
      cin >> k;
      int c;
      for (int j = 0; j < k; j++) {
         cin >> c;
         G[i].push_back(c);
         G[c].push_back(i);
      }
   }
   TREE tree;
   tree.init(N, 0);

   int Q;
   cin >> Q;
   int u, v;
   for (int q = 0; q < Q; q++) {
      cin >> u >> v;
      cout << tree.lca(u, v) << endl;
   }


   

   return 0;
}



Measured memory_bytes: 18464
#include<iostream>
int gcd(int x,int y){
	if(x%y==0) return y;
	else return gcd(y,x%y);
	}
int main(){
	int x,y;
	std::cin>>x>>y;
	if(x<y){
		int tmp=y;
		y=x;
		x=tmp;
	}
	std::cout<<gcd(x,y)<<'\n';
	 return 0;
}


Measured memory_bytes: 3072
/// Thank you tanakh!!!
/// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

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

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

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

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

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

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

use std::cmp;

fn main() {
    input!(n: usize, a: [usize; (1 << n)]);

    let mut top2 = a.iter().map(|&a| (a, 0)).collect::<Vec<_>>();
    for i in 0..n {
        for j in 0..(1 << n) {
            if j & (1 << i) != 0 {
                let (cur1, cur2) = top2[j];
                let (t1, t2) = top2[j ^ (1 << i)];
                let mut t = [cur1, cur2, t1, t2];
                t.sort();
                top2[j] = (t[3], t[2]);
            }
        }
    }

    let mut max = 0;
    for i in 1..(1 << n) {
        let (s, t) = top2[i];
        max = cmp::max(max, s + t);
        println!("{}", max);
    }
}


Measured memory_bytes: 17276
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n, l;cin>>n>>l;
    string temp;
    map<string, int>mp;
    for(int i=0; i<n; i++){
        cin>>temp;
        mp[temp]++;
    }
    for(auto it=mp.begin(); it!=mp.end(); it++){
        while(it->second!=0){
            cout<<it->first;
            mp[it->first]--;
        }
    }
    cout<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string> 
#include <vector> 
#include <algorithm> 
#include <utility> 
#include <tuple> 
#include <cstdint> 
#include <cstdio> 
#include <map> 
#include <queue> 
#include <set> 
#include <stack> 
#include <deque> 
#include <unordered_map> 
#include <unordered_set> 
#include <bitset> 
#include <cctype> 
#include<math.h>
using namespace std;
//#define int long long
#define m_p make_pair
#define mod 1000000007
#define rep(i,n)  for(int i=0; i<(int) (n); i++)
#define all(v)  v.begin(),v.end()
#define vecin(v) for(int i=0; i<(int)v.size(); i++)cin>>vec[i];
using namespace std;

int jousu(int, int);
int jousu(int x00, int y00) {
	int z00 = 1;
	for (int i = 0; i < y00; i++) {
		z00 *= x00;
	}
	return z00;
}
int kurai(int x00, int y00) {
	int z00 = (x00 % jousu(10, y00)) / jousu(10, y00 - 1);
	return z00;
}
int keta(int x00) {
	int z00 = x00;
	int w00 = 0;
	while (z00 != 0) {
		z00 /= 10;
		w00++;
	}
	return w00;
}

string s, fr, ba,ans;
int q, a, b, rev = 0;
char c;

int main() {
	cin >> s >> q;
	for (int i = 0; i < q; i++) {
		cin >> a;
		if (a == 1) {
			rev++;
		}
		else {
			cin >> b >> c;
			if (b == 1) {
				if (rev % 2 == 0) {
					fr += c;
				}
				else {
					ba += c;
				}
			}
			else {
				if (rev % 2 == 0) {
					ba += c;
				}
				else {
					fr += c;
				}
			}
		}
	}
	if (rev % 2 == 0) {
		reverse(all(fr));
		ans = fr + s + ba;
		cout << ans << endl;
	}
	else {
		reverse(all(ba));
		reverse(all(s));
		ans = ba + s + fr;
		cout << ans << endl;
	}
}


Measured memory_bytes: 1348
#include<stdio.h>
int main(){
int a[102];
int b,i,c=0;
for(i=1;i<=100;i++){
a[i]=0;
}
while(scanf("%d\n",&b)!=EOF){
a[b]++;
}
for(i=1;i<=100;i++){
if(a[i]>c){
c=a[i];
}
}
for(i=1;i<=100;i++){
if(c==a[i]){
printf("%d\n",i);
}
}
return 0;
}


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

typedef long long ll;

ll power(ll x, ll y)
{
    ll res = 1;
    while (y)
    {
        if (y&1) res = ((res)*(x));

        y>>=1;
        x = x*x;
    }
    return res;
}

int main(){

    ios::sync_with_stdio(false);
    cin.tie(0);

    ll x;
    cin >> x;

    ll y;
    bool flag = true;
    for(int i=-500; i<=500; i++){
        for(int j=-500; j<=500; j++){
            y = power(i,5)-power(j,5);
            if(y==x){
                cout<<i<<" "<<j<<'\n';
                flag=false;
                break;
            }else if(y==-x){
                cout<<j<<" "<<i<<'\n';
                flag=false;
                break;
            }
        }
        if(!flag) break;
    }    

    return 0;
}


Measured memory_bytes: 3652
#include "bits/stdc++.h"

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,j) FOR(i,0,j)
#define VI vector<int>

//#define DEBUG 3

const int INF = 1 << 24;
const int dx[8] = {0, 0, 1, -1, 1, 1, -1, -1}, dy[8] = {1, -1, 0, 0, 1, -1, 1, -1};

using namespace std;
using ll = long long;
typedef pair<int,int> P;

void run() {
	const int differ = 20000;
	int n; cin >> n;
	VI p(n), a(n), b(n);
	REP(i, n) {
		cin >> p[i];
		a[p[i]-1] += i + 1;
		a[i] += differ * (i+1);
		b[i] += differ * (n-i);
	}

	REP(i, n) {
		if(i) cout << " ";
		cout << a[i];
	}
	cout << endl;

	REP(i, n) {
		if(i) cout << " ";
		cout << b[i];
	}
	cout << endl;
}

int main() {
#ifdef DEBUG
	ifstream in("input.txt");
	cin.rdbuf(in.rdbuf());
	REP(i, DEBUG) {
		cout <<"--------------: i=" << i << endl;
		run();
	}
#else
	run();
#endif
	return 0;
}


Measured memory_bytes: 896
#include<iostream>
#include<vector>
#include<map>
using namespace std;
 
int main(){
  int N;
  cin >> N;
 
  string a;
  cin >> a;
 
  for(auto& c: a){
    c -= 1;
  }
 
  bool has_1 = any_of(a.begin(), a.end(),
                      [](char c){return c == '1'; });
  vector<int> two_cnt(N);
  two_cnt[0] = 0;
  for(int k = 1; k <= N - 1; k++){
    int two_cnt_diff = 0;
    int up = N - 1 - k + 1;
    while(up % 2 == 0){
      up /= 2;
      two_cnt_diff++;
    }
    int down = k;
    while(down % 2 == 0){
      down /= 2;
      two_cnt_diff--;
    }
    two_cnt[k] = two_cnt[k - 1] + two_cnt_diff;
  }
  if(has_1){ // 0 or 1
    for(auto& c: a){
      if(c == '2'){
        c = '0';
      }
    }
  }else{ // 0 or 2
    for(auto& c: a){
      if(c == '2'){
        c = '1';
      }
    }
  }
  bool one = false;
  for(int i = 0; i < N; i++){
    if(a[i] == '1' && two_cnt[i] == 0){
      one = !one;
    }
  }
  if(has_1 && one){
    cout << 1 << endl;
  }else if(one){
    cout << 2 << endl;
  }else{
    cout << 0 << endl;
  }
 
}

Measured memory_bytes: 5236
#include <iostream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <tuple>

struct UnionFind {
    std::vector<int> par, sz;
    std::vector<bool> namori;
    int gnum;

    explicit UnionFind(int n)
        : par(n), sz(n, 1), namori(n, false), gnum(n) {
        std::iota(par.begin(), par.end(), 0);
    }

    int find(int v) {
        return (par[v] == v) ? v : (par[v] = find(par[v]));
    }

    void unite(int u, int v) {
        u = find(u), v = find(v);
        if (u == v) return;

        if (sz[u] < sz[v]) std::swap(u, v);
        sz[u] += sz[v];
        par[v] = u;
        namori[u] = (namori[u] || namori[v]);
        --gnum;
    }

    bool same(int u, int v) { return find(u) == find(v); }
    bool ispar(int v) { return v == find(v); }
    int size(int v) { return sz[find(v)]; }
};

using lint = long long;

void solve() {
    int n, h, w;
    std::cin >> n >> h >> w;

    std::vector<std::tuple<lint, int, int>> es;
    while (n--) {
        int x, y;
        lint a;
        std::cin >> x >> y >> a;
        --x, --y;
        es.emplace_back(a, x, y + h);
    }
    std::sort(es.rbegin(), es.rend());

    UnionFind uf(h + w);
    lint ans = 0;
    for (auto e : es) {
        int u, v;
        lint a;
        std::tie(a, u, v) = e;

        u = uf.find(u);
        v = uf.find(v);
        if (u == v) {
            if (uf.namori[u]) continue;
            ans += a;
            uf.namori[u] = true;
        } else {
            if (uf.namori[u] && uf.namori[v]) continue;
            ans += a;
            uf.unite(u, v);
        }
    }

    std::cout << ans << std::endl;
}

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

    solve();

    return 0;
}


Measured memory_bytes: 3444
#include <iostream>
#include <ctype.h>
using namespace std;
int main() {
    string s = "abcdefghijklmnopqrstuvwxyz";
    string d;
    int k[26] = {};
    while(getline(cin, d)) {
        
        for(int i=0;i<d.size();i++) {
            d[i] = tolower(d[i]);
        }
        for(int i=0;i<s.size();i++) {
            for(int j=0;j<d.size();j++) {
                if(s[i] == d[j]) {
                    k[i]++;
                }
            }
        }
    }
    for(int i=0;i<s.size();i++) {
        cout << s[i] << " : " << k[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 3192
#include <iostream>
#include <string>
#include <stack>
#include <vector>
#include <queue>
#include <math.h>
#include <algorithm>
#include <numeric>
#include <set>

using namespace std;

void solve();

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

//////////////////////////////////////////////////
//////////////////////////////////////////////////

int times[5];

void solve() {
	for (int k = 0; k < 5; k++)cin >> times[k];
	int arr[5];
	for (int k = 0; k < 5; k++)arr[k] = k;
	int m = 130*5;
	do {
		int t = 0;
		for (int k = 0; k < 5; k++) {
			if (t % 10 != 0)t = (int)(10 * ceil((double)t/10));
			t += times[arr[k]];
		}
		m = min(m,t);
	} while (next_permutation(arr,arr+5));
	cout << m << endl;
	return;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
#define eps 1e-8
#define eq(x,y) (fabs((x)-(y)) < eps)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int>pii;
const ll mod= 1e9+7;
long double PI = acosl(-1);
const ll infl = 1e17;
const int inf = 2e9+100;
const int nmax = 2e5+10;
const int MAXLG = log2(nmax)+1;
//mt19937 rng(chrono::system_clock::now().time_since_epoch().count());
//typedef tree< int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ost;


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

    char ch;
    cin>>ch;
    ch++;
    cout<<ch<<endl;

}


Measured memory_bytes: 256
package main

import (
        "bufio"
        "fmt"
        "os"
        "strconv"
        "strings"
)

////////////////////////////////////////
///        templates                 ///
////////////////////////////////////////

var sc = bufio.NewScanner(os.Stdin)

func nextLine() string {
        sc.Scan()
        return sc.Text()
}

var rdr = bufio.NewReaderSize(os.Stdin, 1000000)

func readBigLine() string {
        buf := make([]byte, 0, 1000000)
        for {
                l, p, e := rdr.ReadLine()
                if e != nil {
                        panic(e)
                }
                buf = append(buf, l...)
                if !p {
                        break
                }
        }
        return string(buf)
}

func strSprit(str string) []string {
        cols := strings.Split(str, " ")
        return cols
}

func parseInt(str string) int {
        n, _ := strconv.Atoi(str)
        return n
}

func intSprit(str string) []int {
        strs := strSprit(str)
        cols := make([]int, len(strs))
        for i, v := range strs {
                cols[i] = parseInt(v)
        }
        return cols
}

type SortSlice []int

func (s SortSlice) Len() int {
        return len(s)
}

func (s SortSlice) Swap(i, j int) {
        s[i], s[j] = s[j], s[i]
}

func (s SortSlice) Less(i, j int) bool {
        return s[i] < s[j]
}

func reverseString(str string) string {
        buf := []rune(str)
        for i, j := 0, len(buf)-1; i < j; i, j = i+1, j-1 {
                buf[i], buf[j] = buf[j], buf[i]
        }
        return string(buf)
}

////////////////////////////////////////
///        end templates             ///
////////////////////////////////////////

func main() {
        line := nextLine()

        A := parseInt(line)

        if A < 1000 {
                fmt.Println("ABC")
        } else {
                fmt.Println("ABD")
        }
}

Measured memory_bytes: 640
import java.util.*;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
    sc.useDelimiter("");
    int count = 0;
    for(int i=0; i<3; i++){
      if(sc.nextInt()==1)
        count++;
    }

    System.out.println(count);
	}
}


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

// #define deb(x) cout << #x << " " << x << endl;
#define fo(i, n) for(i=0; i<n; i++)
#define Fo(i, k, n) for(i=k; i<n; i++)
#define w(x)  int x; cin>>x; while(x--)
#define watch(x) cout << (#x) << " is " << (x) << "\n"
#define watch2(x,y) cout <<(#x)<<" is "<<(x)<<" and "<<(#y)<<" is "<<(y)<<"\n"

#define ll  long long
#define all(c) (c).begin(),(c).end()
#define nl "\n"

typedef vector<int> vl;
typedef vector< vl > vvl;
typedef pair< int, int> pll; typedef map< int, int> mll;
int t[100][100];

void c_p_c()
{
#ifndef ONLINE_JUDGE
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}





int main() {
 
    int i;

    c_p_c();
    int n,k;
    cin>>n>>k;
    int mi=2*n;
    int ma=4*n;
    for (int i = mi; i <=ma; i+=2)
    {
       if(i==k){
        cout<<"Yes"<<endl;
        return 0;
       }
    }
    cout<<"No"<<endl;


  return 0;

}

Measured memory_bytes: 3684
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<LL,LL> P;
const LL mod=1000000007;
const LL LINF=1LL<<60;
const int INF=1<<30;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};




int main(){
    LL n;cin >> n;
    vector<LL> a(3),b(3);
    for (int i = 0; i < 3; i++) {
        cin >> a[i];
    }
    for (int i = 0; i < 3; i++) {
        cin >> b[i];
    }
    vector<LL> dp1(50000,0),dp2(25100000,0);
    for (int i = 0; i < 3; i++) {
        for (int j = 0; j < n+1; j++) {
            if(j==0||dp1[j]>0) dp1[j+a[i]] = max(dp1[j+a[i]],dp1[j] + b[i]);
        }
    }
    LL N=0;
    for (int i = 0; i <= n; i++) {
        N=max(N,n-i+dp1[i]);
    }
    for (int i = 0; i < 3; i++) {
        for (int j = 0; j < N+1; j++) {
            if(j==0||dp2[j]>0) dp2[j+b[i]] = max(dp2[j+b[i]],dp2[j] + a[i]);
        }
    }
    LL ans=0;
    for (int i = 0; i <= N; i++) {
        ans=max(ans,N-i+dp2[i]);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 196864
#include <cstdio>
#include<iostream>
#include<map>
#include<algorithm>
#include<vector>
#include <cmath>
#include <iomanip>
#include <regex>
#include <bits/stdc++.h>
#include <string>
using namespace std;

int main(){
    int c[3][3];
    for(int i=0;i<3;i++){
        for(int j=0;j<3;j++){
            cin>>c[i][j];
        }
    }
    bool flag = true;
    for(int i=1;i<3;i++){
        if(c[0][i] - c[0][0] != c[1][i]- c[1][0] || c[0][i] - c[0][0] != c[2][i]- c[2][0]){
            flag = false;
        }
    }
    for(int i=1;i<3;i++){
        if(c[i][0] - c[0][0] != c[i][1]- c[0][1] || c[i][0] - c[0][0] != c[i][2]- c[0][2]){
            flag = false;
        }
    }
    if(flag){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = (0); i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define show(x) cout << #x << " = " << (x) << endl
#define show2(x,y) cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl
#define show3(x,y,z) cout << #x << " = " << (x) << ", " << #y << " = " << (y) <<  ", " << #z << " = " << (z) << endl
#define showv(v) rep(i,v.size()) printf("%d%c", v[i], i==v.size()-1?'\n':' ')
#define showv2(v) rep(j,v.size()) showv(v[j])
#define showt(t,n) rep(i,n) printf("%d%c", t[i], i==n-1?'\n':' ')
#define showt2(t,r,c) rep(j,r) showt(t[j],c)
#define showvp(p) rep(i,p.size()) printf("%d %d\n", p[i].first, p[i].second);
#define printv(v) rep(i,v.size()) printf("%d\n", v[i])
#define printt(t,n) rep(i,n) printf("%d\n", t[i])
#define incl(v,x) find(rng(v),x)!=v.end()
#define incls(s,c) s.find(c)!=string::npos
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
typedef vector<pii> vp;
typedef vector<tiii> vt;
const int mod = 1000000007;
const double EPS = 1e-9;
const int INF = (1<<30)-1;
const ll INFLL = (1LL<<62)-1;
#define dame { puts("No"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
inline int in() { int x; scanf("%d",&x); return x;}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main () {
  int n, d, x;
  cin >> n >> d >> x;

  int cnt = 0;
  rep(i,n) {
    int a;
    cin >> a;
    rep(j,d) {
      rep(k,d) {
        if (k*a == j) cnt++;
      }
    }
  }
  int ans = cnt + x;
  cout << ans << endl;
  return 0;
}

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

#define debug(s) cout << s << endl
#define debug1(s, t) cout << s << " " << t << endl
#define debug2(s, t, u) cout << s << " " << t << " " << u << endl
#define printvec(v)       \
    for (auto &&i : v)    \
        cout << i << " "; \
    cout << endl

using namespace std;
using i64 = long long;

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

    i64 ans;
    if (n >= b)
    {
        ans = (a * (b - 1LL)) / b;
    }
    else
    {
        ans = (a * n) / b;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repe(i,n) for (int i = 0; i <= (n); ++i)
#define repe1(i,n) for (int i = 0; i <= (n); ++i)
#define all(x) (x).begin(),(x).end()
#define pb(x) push_back(x)
#define eb(k,v) emplace_back(k,v)
using namespace std;
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; }
typedef long long ll;
const int INF = 1e9;
const ll mod = 1000000007;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a * b / gcd(a, b);}

ll pow_kai(ll a, ll n) {
    ll x = 1;
    while(n > 0) {
        if(n&1) {
            x = x*a;
        }
        a = a*a;
        n >>= 1;
    }
    return x;
}

int main() {
    ll a,b,x;
    cin >> a >> b >> x;
    ll cnt = 0;
    if (a==0) {
        cout << b/x+1; "\n";
    } else {
        cout << b/x-(a-1)/x << "\n";
    }
}


Measured memory_bytes: 256
# https://atcoder.jp/contests/abc152/tasks/abc152_d

s = gets.chomp
N = s.to_i
l = s.size

css = Array.new(10) { Array.new(10) }

10.times do |i|
  10.times do |j|
    if i == 0 || j == 0
      css[i][j] = 0
      next
    end
    ix = s[0].to_i
    jx = s[-1].to_i
    c = 0
    c += (i <= N ? 1 : 0) if i == j
    (l - 2).times { |k| c += 10**k }
    if l >= 2
      if i < ix
        c += 10**(l - 2)
      elsif i == ix
        c += ('0' + s[1..-2]).to_i
        c += 1 if j <= jx
      end
    end
    css[i][j] = c
  end
end

# p css

ans = 0
10.times do |i|
  10.times do |j|
    ans += css[i][j] * css[j][i]
  end
end

puts ans


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

int main(void) {
	int n; cin >> n;
	cout << n * 800 - (n / 15*200) << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)
const ll MAX_N=2e5;
ll N,A[MAX_N],dp[MAX_N],psm[MAX_N];
int main(){
	cin.tie(0);
	cin.sync_with_stdio(false);
	cin>>N;
	REP(i,N){
		cin>>A[i];
	}
	psm[0]=A[0];
	for(ll i=2;i<N;i+=2){
		psm[i]=psm[i-2]+A[i];
	}
	dp[0]=0;
	dp[1]=max(A[0],A[1]);
	FOR(i,2,N){
		if(i%2==0){
			dp[i]=max(dp[i-1],A[i]+dp[i-2]);
		}else{
			dp[i]=max(psm[i-1],A[i]+dp[i-2]);
		}
	}
	cout<<dp[N-1]<<endl;
}


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

using namespace std;

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

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)
typedef complex<Real> P;

int n;
char s[52];

int main(){
  scanf("%d",&n);
  scanf("%s",s);
  assert(strlen(s) == 2*n);
  map<pair<string,string>,int> M;
  REP(m,1<<n){
    string a, b;
    REP(i,n){
      if((m>>i)&1)a += string(1,s[i]);
      else b += string(1,s[i]);
    }
    M[make_pair(a,b)]++;
  }
  ll ans = 0;
  REP(m,1<<n){
    string c, d;
    REP(i,n){
      if((m>>i)&1)c += string(1,s[n+i]);
      else d += string(1,s[n+i]);
    }
    string a = d;
    reverse(ALL(a));
    string b = c;
    reverse(ALL(b));
    ans += M[make_pair(a,b)];
  }
  printf("%lld\n",ans);
  return 0;
}


Measured memory_bytes: 87040
#include <iostream>
#include <stdio.h>
#define _USE_MATH_DEFINES
#include <cmath>
#include<algorithm>
using namespace std;
int main()
{
    double d;
    int s;
    while(cin >> d){
        s = 0;
        for(int i = 1;d*i < 600;i++){
            s = s + i*i*d*d*d ;
        }cout << s << endl;
        
    }
}

Measured memory_bytes: 1220
#include <iostream>
#include <map>

using namespace std;

int64_t gcd(int64_t a, int64_t b){
	return (b > 0)? gcd(b, a % b) : a ;
}

map< int64_t, int > prime_factor(int64_t n) {
    map< int64_t, int > ret;
    for(int64_t i = 2; i * i <= n; i++) {
        while(n % i == 0) {
        ret[i]++;
        n /= i;
        }
    }
    if(n != 1) ret[n] = 1;
    return ret;
}

int main(void) {
    int64_t A, B;
    cin >> A >> B;
    auto P = prime_factor(gcd(A, B));
    cout << P.size()+1 << endl;
    return 0;
}


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

#define MAX_N 100010

struct arrow {int v, w;};
vector <arrow> adj[MAX_N];
int64_t dis[MAX_N] = {0};
bool vis[MAX_N] = {0};

void dfs(int v)
{
    vis[v] = true;
    for (int i = 0; i < adj[v].size(); i++) {
        int u = adj[v][i].v;
        int w = adj[v][i].w;
        if (!vis[u]) {
            dis[u] = dis[v] + w;
            dfs(u);
        }
    }
}

int main(void)
{
    int n, k, q;
    scanf("%d", &n);
    for (int i = 1; i < n; i++) {
        int a, b, c;
        scanf("%d%d%d", &a, &b, &c);
        arrow s = {b, c}, t = {a, c};
        adj[a].push_back(s);
        adj[b].push_back(t);
    }
    scanf("%d%d", &q, &k);
    dfs(k);
    while (q--) {
        int x, y;
        scanf("%d%d", &x, &y);
        printf("%lld\n", dis[x] + dis[y]);
    }
    return 0;
}


Measured memory_bytes: 12800
#include<bits/stdc++.h>
using namespace std;
int n,sol,fr[1<<11],v[1<<11];
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cin>>n;
    for(int i=1;i<=n;++i) cin>>v[i];
    ///  a < b + c
    /// -a < c - b * (-1)
    /// -a < b - c * (-1)
    ///  a > b - c
    ///  a > c - b
    ///  a > max(b-c,c-b) !!!!!
    for(int i=1;i<=n;++i)
    {
        for(int j=i+1;j<=n;++j)
            sol+=fr[v[i]+v[j]-1] - fr[max(v[i]-v[j],v[j]-v[i])];
        for(int j=v[i];j<=2000;++j) fr[j]++;
    }
    cout<<sol;
    return 0;
}


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

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

// グラフ表現
using Graph = vector<vector<int>>;

// グラフの辺表現
using Edge = map<pair<int,int>,int>;

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

// 最大公約数
ll gcd(ll a,ll b){
   if (a%b == 0) return(b);
   else return(gcd(b, a%b));
}

// 最小公倍数
ll lcm(ll a, ll b){
    return a*b/gcd(a, b);
}

int main()
{
    cout << fixed << setprecision(15);
    string S;
    ll K;

    cin >> S;
    cin >> K;

    ll now = 0;
    REP(i, S.length()){
        if(S[i] == '1'){
            now += 1;
        }
        else{
            cout << S[i] << endl;
            return 0;
        }
        if(now >= K){
            cout << '1' << endl;
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 256
import math

X,K,D = map(int,input().split())

X = abs(X)

if X//D > K:
    ans = X - D*K
    print(abs(ans))
elif (K-(X//D))%2 == 0:
    Y = X - (X//D)*D
    print(abs(Y))
else:
    Y = X - (X//D)*D
    print(abs(D-Y))


Measured memory_bytes: 9092
n, l = map(int, input().split())
tastes = [i + l for i in range(n)]
taste_sum = sum(tastes)
t = 0
if tastes[0] > 0:
    t = tastes[0]
elif tastes[-1] < 0:
    t = tastes[-1]
print(taste_sum - t)


Measured memory_bytes: 3064
def cmb(n, r, mod):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return (fact[n] * factinv[r] * factinv[n-r]) % mod

def prm(n,r,mod):
    if (r < 0) or (n < r):
        return 0
    return (fact[n] * factinv[n-r])%mod
mod = 10**9 + 7

fact = [1, 1]
factinv = [1, 1]
inv = [0,1]

s = int(input())
na = s//3
ans = 0

for i in range(2,s):
    fact.append((fact[-1] * i) % mod)
    inv.append((inv[mod % i] * (mod - (mod // i))) % mod)
    factinv.append((factinv[-1] * inv[-1]) % mod)

for i in range(1,na+1):
    ans += cmb(s - 3*i + i - 1, i-1 , mod)
    ans %= mod
print(ans%mod)

Measured memory_bytes: 65748
import java.util.*;
	public class Main{
        public static void main(String[] args){
            Scanner sc = new Scanner(System.in);
            //入力
            int n = Integer.parseInt(sc.next());
            int a = Integer.parseInt(sc.next());
            
            //出力
            if(n%500 > a){
            	System.out.println("No");
            }else{
            	System.out.println("Yes");
            }
            sc.close();
        }
    }

Measured memory_bytes: 21844
package main

import (
	"bufio"
	"os"
	"fmt"
)

func main() {
	scanner :=bufio.NewScanner(os.Stdin)
	scanner.Scan()
	input := scanner.Text()
	scanner.Scan()
	target := scanner.Text()
	n := len(input)
	m := len(target)
	ans := make([]int, 0)
	var p int
	for i := 0; i <= n-m; i++ {
		for p = 0; p < m; p++ {
			if input[i+p] != target[p] {
				break
			}
		}
		if p == m {
			ans = append(ans, i)
		}
	}
	for i :=range ans{
		fmt.Println(ans[i])
	}
}


Measured memory_bytes: 1140
#include <iostream>
#include <algorithm>
#include <map>
#include <utility>
#include <string>
#include <vector>

using namespace std;

int main() {
    int n, m, f;
    string s[10];
    map<pair<string, string>, int> mp;
    
    cin >> n >> f;
    while (n--) {
        cin >> m;
        for (int i = 0; i < m; ++i) {
            cin >> s[i];
        }
        for (int i = 0; i < m; ++i) {
            for (int j = i + 1; j < m; ++j) {
                mp[make_pair(min(s[i], s[j]), max(s[i], s[j]))]++;
            }
        }
    }
    
    vector<pair<string, string>> ans;
    for (auto elem : mp) {
        if (elem.second >= f) {
            ans.push_back(elem.first);
        }
    }
    
    sort(ans.begin(), ans.end());
    cout << ans.size() << endl;
    for (auto elem : ans) {
        cout << elem.first << " " << elem.second << endl;
    }
    
    return 0;
}

Measured memory_bytes: 3556
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define forn(i,a,b) for(ll i=a;i<b;i++)
#define pb push_back
#define mp make_pair

int main()
{
	int n; cin >> n;
	int h[n]; 
	forn(i,0,n) cin >> h[i];
	int dp[n];
	dp[0] = 0;
	dp[1] = abs(h[1]- h[0]);

	forn(i,2,n)
		dp[i] = min( (abs(h[i]-h[i-1])+dp[i-1]) , (abs(h[i]-h[i-2])+dp[i-2]) );

	cout << dp[n-1] << endl;
}

Measured memory_bytes: 4420
def main():
    a,b,c,d,e,f= map(int,input().split())

    # 100gあたりE [g]溶ける
    # ビーカーにF [g]いれられる
    # 濃度は100*砂糖 / (水＋砂糖)


    mizu=[]
    sato=[]


    x = int(f/100/a) +1
    y = int(f/100/b) +1

    for i in range(x):
        for j in range(y):
            mizu.append(i*100*a + j*100*b)

    mizu = [i for i in mizu if i <= f]
    mizu = list(set(mizu))
    mizu.sort()

    tokeru = int(f/100) * e
    x = int(tokeru / c) +1
    y = int(tokeru / d) +1

    for i in range(x):
        for j in range(y):
            sato.append(i*c + j*d)

    sato = [i for i in sato if i < tokeru]
    sato = list(set(sato))
    sato.sort()
#    sato.remove(0)
#    mizu.remove(0)

    tmp =0

    for i in mizu:
        for j in sato:
            if i + j <= f and i + j !=0:
                if int(i/100)*e >=j:
                    if tmp <= (100*j) / (i + j):
                        tmp = (100*j) / (i + j)
                        ans = str(i+j) + " " + str(j)

    print(ans)


if __name__ == "__main__":
        main()


Measured memory_bytes: 24364