akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
	
	public static void main(String[] args) throws IOException {
		Main mainObj = new Main();
		mainObj.solve();
	}

	public void solve() throws IOException {
		FastScanner fs = new FastScanner();
		String s = fs.next();
		String t = fs.next();
		
		int ans = 0;
		for(int i = 0; i < s.length(); i++) {
			char sAt = s.charAt(i);
			char tAt = t.charAt(i);
			if(sAt == tAt) {
				ans++;
			}
		}
		
		System.out.println(ans);
	}

	

	public class FastScanner {

		BufferedReader reader;
		private StringTokenizer st;

		public FastScanner() {
			st = null;
			reader = new BufferedReader(new InputStreamReader(System.in));
		}

		public String next() throws IOException {
			if (st == null || !st.hasMoreElements()) {
				st = new StringTokenizer(reader.readLine());
			}
			return st.nextToken();
		}

		public String nextLine() throws IOException {
			st = null;
			String readLine = null;
			readLine = reader.readLine();
			return readLine;
		}

		public int nextInt() throws NumberFormatException, IOException {
			return Integer.parseInt(next());
		}

		public long nextLong() throws NumberFormatException, IOException {
			return Long.parseLong(next());
		}

		public int[] nextIntArr(int n) throws NumberFormatException, IOException {
			int[] retArr = new int[n];
			for (int i = 0; i < n; i++) {
				retArr[i] = nextInt();
			}
			return retArr;
		}

		public long[] nextLongArr(int n) throws NumberFormatException, IOException {
			long[] retArr = new long[n];
			for (int i = 0; i < n; i++) {
				retArr[i] = nextLong();
			}
			return retArr;
		}

		public void close() throws IOException {
			reader.close();
		}
	}


}


Measured memory_bytes: 22740
use std::io::{stdin, Read, StdinLock};
use std::str::FromStr;
use std::cmp::min;

fn main() {
    let cin = stdin();
    let mut scan = Scanner::new(cin.lock());
    let n = scan.read::<usize>();
    let a = scan.readn::<i64>(n);
    let mut delta = 1i64 << 60;
    let sum = a.iter().map(|x| *x).sum::<i64>();
    let mut left = 0;
    for i in 0..n-1 {
        left += a[i];
        delta = min(delta, (sum - left - left).abs());
    }
    println!("{}", delta);
}

// region template
#[allow(dead_code)]
fn iu(i: i64) -> usize { i as usize }

#[allow(dead_code)]
fn ui(i: usize) -> i64 { i as i64 }

#[allow(dead_code, deprecated)]
fn join<T: std::fmt::Display>(slice: &[T], sep: &str) -> String {
    let strings = slice.iter().map(|t| format!("{}", t)).collect::<Vec<_>>();
    strings.connect(sep)
}

#[allow(dead_code)]
fn arr<'a, S, T>(n: usize, mut f: S) -> Vec<T> where S: FnMut(usize) -> T + 'a {
    (0..n).map(|i| f(i)).collect::<Vec<T>>()
}

struct Scanner<'a> {
    cin: StdinLock<'a>,
}

#[allow(dead_code)]
impl<'a> Scanner<'a> {
    fn new(cin: StdinLock<'a>) -> Scanner<'a> {
        Scanner { cin: cin }
    }

    fn read1<T: FromStr>(&mut self) -> Option<T> {
        let token = self.cin.by_ref().bytes().map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        token.parse::<T>().ok()
    }

    fn read<T: FromStr>(&mut self) -> T {
        self.read1().unwrap()
    }

    fn readn<T: FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read::<T>()).collect()
    }

    fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}
// endregion

Measured memory_bytes: 6396
#include <bits/stdc++.h>
#define loop(n) for (int ngtkana_is_genius = 0; ngtkana_is_genius < int(n); ngtkana_is_genius++)
#define rep(i, begin, end) for(int i = int(begin); i < int(end); i++)
#define all(v) v.begin(), v.end()
#define rand(l, r) std::uniform_int_distribution<>(l, r)(mt)
using lint = long long;
auto mt = std::mt19937_64(std::random_device{}());
auto cmn = [](auto& a, auto b){if (a > b) {a = b; return true;} return false;};
auto cmx = [](auto& a, auto b){if (a < b) {a = b; return true;} return false;};
void debug_impl() { std::cerr << std::endl; }
template <typename Head, typename... Tail>
void debug_impl(Head head, Tail... tail){
  std::cerr << " " << head;
  debug_impl(tail...);
}
#ifdef STOPIT
#define debug(...) 0
#else
#define debug(...)\
do {\
  std::cerr << std::boolalpha << "[" << #__VA_ARGS__ << "]:";\
  debug_impl(__VA_ARGS__);\
  std::cerr << std::noboolalpha;\
} while (false)
#endif

int main() {
  std::cin.tie(0); std::cin.sync_with_stdio(false);
  int n, m; std::cin >> n >> m;
  if (n <= 0 || 9 < n || m <= 0 || 9 < m) {
    std::cout << -1 << std::endl;
  } else {
    std::cout << n * m << std::endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<set>
#include<unordered_set>
#include<map>
typedef long long int ll;
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define REP(i,n) for (int i=0;i<(n);i++)
#define EREP(i,n) for (int i=1;i<=(n);i++)
#define ALL(a) (a).begin(),(a).end()
//#define EVEL 1

#ifdef EVEL
#define DEB(X) cout << #X << ":" <<X<<" " ;
#define TF(f) f ? cout<<"true  " : cout<<"false ";
#define END cout<<"\n";
#else
#define DEB(X) {}
#define TF(f) {}
#define END {}
#endif
const ll MOD = 1000000007;
const int INF = 2000000000;
std::pair<string,pair<int,int>> Q[101];
    ll N,M,K;
    ll A,B,C,X;
    bool F[5][5];
    bool ad=false;
    ll ans=0;
    string S;
int main(){
    ios_base::sync_with_stdio(false);
    cin>>X;
    ans+=(X/500)*1000;
    X=X%500;
    ans+=(X/5)*5;
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
import itertools

a,b,c = map(int,input().split())
abc = list(itertools.permutations([a,b,c]))

#print(abc)

max_sum = 0

for i in range(len(abc)):
    max_tmp = abc[i][0]*10+abc[i][1]+abc[i][2]
    if max_tmp > max_sum:
        max_sum = max_tmp

print(max_sum)


Measured memory_bytes: 3060
n, w = [int(i) for i in input().split()]
a = [[int(n) for n in input().split()] for i in range(n)]


sv = {}
for ww, vv in a:
    if ww > w:
        continue
    added = {}
    for k, v in sv.items():
        if (ww+k) <= w:
            added[ww+k] = vv+v
    for k, v in added.items():
        sv[k] = max(v, sv.get(k, 0))

    sv[ww] = max(vv, sv.get(ww, 0))

print(max(sv.values()))

Measured memory_bytes: 166740
package main

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

func main() {
	f := bufio.NewScanner(os.Stdin)
	f.Split(bufio.ScanWords)

	N := read(f)
	A := make([]int, N)
	for i := range A {
		A[i] = read(f)
	}

	dp := make([][]int, N)
	weight := make([][]int, N)

	for i := range dp {
		dp[i] = make([]int, N)
		weight[i] = make([]int, N)
	}

	for w := 1; w <= N; w++ {
		for l := 0; l <= N-w; l++ {
			r := l + w - 1
			if w == 1 {
				dp[l][r] = 0
				weight[l][r] = A[l]
				continue
			}

			if w == 2 {
				dp[l][r] = A[l] + A[r]
				weight[l][r] = A[l] + A[r]
				continue
			}

			weight[l][r] = weight[l+1][r] + A[l]
			for wl := 1; wl < w; wl++ {
				n := dp[l][l+wl-1] + dp[l+wl][r] + weight[l][l+wl-1] + weight[l+wl][r]

				if dp[l][r] == 0 || dp[l][r] > n {
					dp[l][r] = n
				}
			}
		}
	}

	fmt.Println(dp[0][N-1])
}

func read(s *bufio.Scanner) int {
	s.Scan()
	res, _ := strconv.ParseInt(s.Text(), 10, 64)
	return int(res)
}

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


Measured memory_bytes: 3456
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import (division, absolute_import, print_function,
                        unicode_literals)
from sys import stdin

for line in stdin:
    n, m = (int(s) for s in line.split())
    if not (n or m):
        break
    ary = bytearray(b'\x01'*n)
    index = n - 1
    while any(ary):
        count = m
        while count:
            index = (index+1) % n
            if ary[index]:
                count -= 1
        ary[index] = 0
    print(index + 1)

Measured memory_bytes: 4248
#include<cstdio>
#include<functional>
#include<algorithm>
using namespace std;
int main(void)
{
	char c1[4],c2[4];
	scanf("%s",c1);
	scanf("%s",c2);
	if(c1[0]==c2[2] && c1[1]==c2[1] && c1[2]==c2[0])	printf("YES\n");
	else printf("NO\n");
	return 0;
}

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

using namespace std;

int main()
{
  //Aが白
  int A, B;
  cin >> A >> B;
  // # = black
  vector<char> M(10000);
  for (int i = 0; i < 5000; i++)
  {
    M[i] = '.';
  }
  for (int i = 5000; i < 10000; i++)
  {
    M[i] = '#';
  }
  if (A == 1 && B == 1)
  {
    cout << "1 2" << endl
         << ".#" << endl;
  }
  else
  {
    A--;
    B--;
    cout << "100 100";
    //白
    int count = 9999;
    while (A > 0)
    {
      M[count] = '.';
      if (count % 100 == 1)
      {
        count -= 102;
      }
      else
      {
        count -= 2;
      }
      A--;
    }
    count = 0;
    while (B > 0)
    {
      M[count] = '#';
      if (count % 100 == 98)
      {
        count += 102;
      }
      else
      {
        count += 2;
      }
      B--;
    }
    for (int i = 0; i < 10000; i++)
    {
      if (i % 100 == 0)
      {
        cout << endl;
      }
      cout << M[i];
    }
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
using namespace std;
int main(int argc, char* argv[])
{
	int N;
	cin>>N;
	vector<int> A(N);
	int i;
	for (i=0;i<N;i++){
		cin>>A[i];
	}
	sort(A.begin(),A.end(),greater<int>());
	int x=1;
	int Al=0;
	int Bo=0;
	for (i=0;i<N;i++){
		if (x%2==1){
			Al+=A[i];
		}else{
			Bo+=A[i];
		}
		x++;
	}
	cout<<Al-Bo<<endl;
	return 0;
}

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

def func(n, y):
    for a in range(n+1):
        for b in range(n+1):
            if a+b <= n and 10000*a + 5000*b + 1000*(n-a-b) == y:
                print('{} {} {}'.format(a,b,n-a-b))
                return 0
    print("-1 -1 -1")
    return 0

func(n, y)

Measured memory_bytes: 3064
using System;

namespace atcoderA
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            int[] input = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
            int A1 = input[0];
            int A2 = input[1];
            int A3 = input[2];
            int[] data = new int[3];
            data[0] = Math.Abs(A1 - A2);
            data[1] = Math.Abs(A2 - A3);
            data[2] = Math.Abs(A3 - A1);
            Array.Sort(data);
            Console.WriteLine(data[0] + data[1]);
        }
    }
}

Measured memory_bytes: 11220
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <cfloat>
#include <complex>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

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

int main() {
  ll N;

  cin >> N;

  string ans;
  if (N < 1200)
    ans = "ABC";
  else if (N < 2800)
    ans = "ARC";
  else
    ans = "AGC";

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  int arr[100];
  for(int i=0;i<n;i++)
  {
    cin>>arr[i];
  }int p=INT_MIN;
  for(int i=0;i<n;i++)
  {
    if(arr[i]>p)
      p=arr[i];
  }
  int r,d,s=INT_MAX;
  for(int i=1;i<=p;i++)
  {
    d=0;
    for(int j=0;j<n;j++)
    {
       r=(arr[j]-i);
       d+=pow(r,2);
    }
   if(d<s)
     s=d;
  }
  cout<<s<<endl;
  return 0;
}
      
      
      
      
      
      

Measured memory_bytes: 256
/*** author: yuji9511 ***/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using lpair = pair<ll, ll>;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i=(m);i<(n);i++)
#define rrep(i,m,n) for(ll i=(m);i>=(n);i--)
#define printa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};
void print() {}
template <class H,class... T>
void print(H&& h, T&&... t){cout<<h<<" \n"[sizeof...(t)==0];print(forward<T>(t)...);}

void solve(){
    ll A,B,C,K;
    cin >> A >> B >> C >> K;
    ll ans = 0;
    if(K > A){
        ans += A;
        K -= A;
    }else{
        ans += K;
        K = 0;
    }
    if(K > B){
        K -= B;
    }else{
        K = 0;
    }
    if(K > C){
        ans -= C;
    }else{
        ans -= K;
    }
    print(ans);
    

}

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

Measured memory_bytes: 3652
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<time.h>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double EPS=1e-10;
const int inf=1e8;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
int main(){
	int n,m=11;
	while(cin>>n,n){
		vector<vector<int> >cost(m,vector<int>(m));
		rep(i,m)rep(j,m)cost[i][j]=inf;
		rep(i,n){
			int a,b,c;cin>>a>>b>>c;
			cost[a][b]=c;
			cost[b][a]=c;
		}
		int mi=1e9,mii=-1;
		rep(k,m){
			vector<bool>used(m);
			vector<int>d(m,inf);
			d[k]=0;
			while(1){
				int v=-1;
				rep(i,m)if(!used[i]&&(v==-1||d[v]>d[i]))v=i;
				if(v==-1)break;
				used[v]=true;
				rep(i,m)d[i]=min(d[i],d[v]+cost[v][i]);
			}
			int sum=0;
			rep(i,m)if(d[i]!=inf)sum+=d[i];
			if(mi>sum&&sum){mi=sum;mii=k;}
		}
		cout<<mii<<" "<<mi<<endl;
	}
}

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

#define ll long long
#define int long long
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define vi vector<int>
#define pqb priority_queue<int>
#define pqs priority_queue<int, vi, greater<int>>
#define setbits(x) __builtin_popcountll(x)
#define zrobits(x) __builtin_ctzll(x)
#define mod 1000000007
#define inf (int)(1e18)
#define ps(x, y) fixed << setprecision(y) << x
#define w(x)  \
    int x;    \
    cin >> x; \
    while (x--)
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define all(p) p.begin(), p.end()
#define ub(a, b) upper_bound(all(a), b)
#define lb(a, b) lower_bound(all(a), b)
#define PI 3.14159265
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

void run()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}
void solution()
{
    int n;
    cin >> n;
    vector<int> a(n);
    vector<int> c(100001, 0);
    int sum = 0;
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
        sum += a[i];
        c[a[i]]++;
    }
    int q;
    cin >> q;
    for (int i = 0; i < q; i++)
    {
        int x, y;
        cin >> x >> y;
        int dif = y - x;
        sum += (c[x] * dif);
        c[y] += c[x];
        c[x] = 0;
        cout << sum << endl;
    }
    return;
}
int32_t main()
{
    run();
    solution();
    return 0;
}

Measured memory_bytes: 4804
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		String a = sc.next();
		String b = sc.next();
		
		String res = a+b;
		
		if(res.equals("HH")) {
			System.out.println("H");
		}else if(res.equals("DD")) {
			System.out.println("H");
		}else {
			System.out.println("D");
		}
	}
}


Measured memory_bytes: 21716
n = int(input())
s = [input() for i in range(n)]
m = int(input())
t = [input() for i in range(m)]
count = {'':0}
for i in s:
  count.setdefault(i, 0)
  count[i] += 1
for i in t:
  count.setdefault(i, 0)
  count[i] -= 1
print(max(count.values()))

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

typedef long long ll;
int const N = 200020;
ll a[N], f[N], n, k;

bool checa(ll qtd){
    ll ans = 0;
    for (int i=1; i<=n; i++){
        ans += max(0LL, (a[i]*f[i] - qtd + f[i] - 1)/f[i]);
        if (ans > k) return false;
    }
    return ans <= k;
}

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

    cin >> n >> k;
    for (int i=1; i<=n; i++) cin >> a[i];
    for (int i=1; i<=n; i++) cin >> f[i];
    sort(a+1, a+n+1);
    sort(f+1, f+n+1);
    reverse(f+1, f+n+1);

    ll l = 0, r = (ll)1e18, resp = r;
    
    while(l <= r){
        ll m = (l+r)>>1;
        if (checa(m)){
            resp = m;
            r = m-1;
        } else l = m+1;
    }
    cout << resp << endl;

}

Measured memory_bytes: 3328
A = [list(map(int,input().split())) for i in range(3)]

N = int(input())
B = [[0]*3 for i in range(3)]

for i in range(N):
    b = int(input())
    for j in range(3):
        for k in range(3):
            if A[j][k] == b:
                B[j][k] = 1

flag = 0
for i in range(3):
    if B[i][0]==B[i][1]==B[i][2]==1:
        flag = 1
    if B[0][i]==B[1][i]==B[2][i]==1:
        flag = 1
if B[0][0]==B[1][1]==B[2][2]==1:
    flag = 1
if B[0][2]==B[1][1]==B[2][0]==1:
    flag = 1

if flag == 1:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 38256
#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() {
	int n, m;
	cin >> n >> m;
	vector<vector<int> > vec(m);
	vector<int> P(m);
	rep(i, m) {
		int k;
		cin >> k;
		vector<int> S(k);
		rep(i, k) cin >> S.at(i);
		vec.at(i) = S;
	}
	rep(i, m) cin >> P.at(i);

	int ans = 0;
	rep(k, pow(2, n)) {
		bool counter = true;
		rep(i, m) {
			int sum = 0;
			rep(j, vec.at(i).size()) {
				if ((1<<vec.at(i).at(j)-1) & k) sum++;
			}
			if (sum%2!=P.at(i)) counter = false;
		}
		if (counter==true) ans += 1;
	}
	cout << ans << endl;
}

Measured memory_bytes: 4096
from collections import Counter


def main():
    """
    1 <= N <= 10 ** 3
    N! の正の約数の個数を10**9+7 で割った余り

    (10 ** 3)! => loopじゃ無理

    1000 * 999 * 998 * ... * 2 * 1
    →それぞれの約数を求める(1000以下なので問題なし)

    素因数分解:
    e.g. 72
        2^3 * 3^2 * 1 => 6つの要素
        6C1,6C2,6C3,6C4,6C5,6C6
        重複除外(どうする) => 6C2: 2_1,2_2と2_2,2_3

        71についても同様かつ、72の約数との組合せ => 膨大な数になる

    解説:
    ある整数 x が、素因数分解によって x = p^n × q^m × ... (p, q, ...は素数) と表せる時、
    x の約数の個数は(n + 1) × (m + 1) × ... となります。
    """
    N = int(input())

    if N == 1:
        print(1)
        return

    table = eratosthenes(N)
    factors = Counter()
    for i in range(2, N + 1):
        factors += factorize(i, table)

    ans = 1
    for count in factors.values():
        ans = ans * (count + 1) % (10 ** 9 + 7)
    print(ans)


def factorize(N, table):
    factors = Counter()
    x = N
    for i in [2] + list(range(3, N + 1, 2)):
        if table[i]:
            while x % i == 0:
                if i in factors:
                    factors[i] += 1
                else:
                    factors[i] = 1
                x = x // i

    return factors


def eratosthenes(N):
    a = [True for _ in range(N + 1)]
    a[0] = False
    a[1] = False

    for i in range(2, N + 1):
        if a[i]:
            for j in range(i + 1, N + 1):
                if j % i == 0:
                    a[j] = False

    return a

if __name__ == '__main__':
    main()


Measured memory_bytes: 3316
from bisect import bisect_right as right
import sys
readline = sys.stdin.buffer.readline

N = int(input())
A = [int(input()) for _ in range(N)][::-1]

INF = 10**10
dp = [INF] * (N+1)

answer = 0
for a in A:
  r = right(dp, a)
  if dp[r] > a:
    if dp[r] == INF:
      answer += 1
    dp[r] = a
print(answer)

Measured memory_bytes: 52952
N, X = gets.split.map(&:to_i)

HEIGHTS = [1]
PATES = [1]
1.upto(N) do |l|
  HEIGHTS[l] = HEIGHTS[l - 1] * 2 + 3
  PATES[l] = PATES[l - 1] * 2 + 1
end
# p HEIGHTS, PATES

def f(l, x)
  if l == 0
    x > 0 ? 1 : 0
  elsif x <= HEIGHTS[l - 1] + 1 # バーガー＋前レベルの階層
    f(l - 1, x - 1)
  else # バーガー＋前のレベル＋真ん中パティ＋前のレベルの階層
    PATES[l - 1] + 1 + f(l - 1, x - HEIGHTS[l - 1] - 2)
  end
end

puts f(N, X)

Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (ll i = a; i < b; i++)
#define REP(i,b) FOR(i,0,b)
#define RFOR(i,a,b) for (ll i = a-1; i >= b; i--)
#define RREP(i,a) RFOR(i,a,0)
#define REPALL(i,x) for (ll i = 0; i < x.size(); i++)
#define RREPALL(i,x) for (ll i = x.size()-1; i >= 0; i--)
#define REPITR(itr,x) for (auto itr = (x).begin(); itr != (x).end(); itr++)
#define ALL(x) (x).begin(), (x).end()
#define SORT(x) sort(ALL(x))
#define MIN_ELEMENT(x) min_element(ALL(x))
#define MAX_ELEMENT(x) max_element(ALL(x))
#define COUNT(x,num) count(ALL(x), num)
#define MEMSET(x,val) memset(x, val, sizeof(x))
#define MAX(a,b) a = max(a,b)
#define MIN(a,b) a = min(a,b)
#define debug(x) cerr<<__LINE__<<": "<<(#x)<<" = "<<(x)<<endl;
void YES(bool flag) {cout<<(flag ? "YES" : "NO")<<endl;}
void Yes(bool flag) {cout<<(flag ? "Yes" : "No")<<endl;}
void yes(bool flag) {cout<<(flag ? "yes" : "no")<<endl;}
#define e1 first
#define e2 second
#define nextline putchar('\n')
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> VI;
typedef vector<vector<int>> VVI;
typedef vector<ll> VLL;
typedef vector<vector<ll>> VVLL;
const int INF = 1e7;
const ll MOD = 1e9 + 7;
const double pi = 3.141592653589793;

ll mypow(ll a, ll b)
{
    ll r = 1ll;
    while(b != 0){
        if(b&1) r = r * a % MOD;
        a = a * a % MOD;
        b /= 2;
    }
    return r;
}

string l;
ll ans, tans;

int main()
{
    cin>>l;

    ans = 1ll;
    tans = 1ll;
    REP(i,l.size()) {
        if (l[i] == '1') {
            if (i != l.size() - 1) {
                ans = (ans + tans * (2 + mypow(3, l.size() - 1 - i) - 1)) % MOD;
            } else {
                ans = (ans + tans * 2) % MOD;
            }
            //cout<<ans<<endl;
            tans = (2 * tans) % MOD;
        }
    }

    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
#define fast ios::sync_with_stdio(false);cin.tie(NULL)
using namespace std;
#define int long long
#define MOD 1000000007
typedef vector<int> vi;
typedef pair<int,int> pi;
#define inf 1e18
#define For(i,a,b) for (int i = a; i < b; i++)
#define Rep(i,a,b) for (int i = a; i <= b; i++)
#define ps(x,y) fixed << setprecision(y) << x 
#define pb push_back 
#define mp make_pair 
 
int32_t main()
{
    fast;
    char b; cin >> b;
    if(b == 'A') cout << 'T';
    else if(b == 'C') cout << 'G';
    else if(b == 'T') cout << 'A';
    else if(b == 'G') cout << 'C';
    
    
    
    return 0;
}

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

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

    ll m = 0;
    for (int i=0; i<N; ++i) {
        for (int j=0; j<N; ++j) {
            m = max( m, abs(A[i] - A[j]) );
        }
    }

    cout << m << endl;
}




Measured memory_bytes: 256
import heapq
N,K=map(int, input().split())
V=list(map(int, input().split()))

ans=-10**9
for l in range(min(N,K)+1):
    for r in range(max(1,min(N,K)+1-l)):
        for d in range(max(1,K+1-l-r)):
            h=V[:l]
            heapq.heapify(h)
            for i in range(r): heapq.heappush(h, V[-1-i])
            for i in range(min(d,len(h))): heapq.heappop(h)
            ans=max(ans,sum(h))
print(ans)

Measured memory_bytes: 84188
#define _CRT_SECURE_NO_WARNINGS

#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <list>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_set>
#include <unordered_map>
#include <array>
#include <cassert>
#include <bitset>
using namespace std;
using LL = long long;


int N;
vector<LL>A, B;

int main() {
	cin >> N;
	for (int i = 0; i < N; ++i) {
		LL a;
		cin >> a;
		if (a > 0)
			A.push_back(a);
		else
			B.push_back(a);
	}
	vector<pair<LL, LL>>avec;
	LL ans = 0;
	if (A.size() && B.size()) {
		if (A.size() >= B.size()) {
			vector<LL>P;
			for (int i = 0; i < (int)B.size() - 1; ++i) {
				//cout << A[i] << " " << B[i] << endl;
				avec.push_back({ A[i],B[i] });
				P.push_back(A[i] - B[i]);
			}
			for (int i = (int)B.size() - 1; i < A.size(); ++i) {
				P.push_back(A[i]);
			}
			P.push_back(B.back());
			while (P.size() > 2) {
				//cout << P.back() << " " << P[P.size() - 2] << endl;
				avec.push_back({ P.back() , P[P.size() - 2] });
				LL tmp = P.back() - P[P.size() - 2];
				P.pop_back();
				P.pop_back();
				P.push_back(tmp);
			}
			//cout << P[0] << " " << P[1] << endl;
			avec.push_back({ P[0],P[1] });
			ans = P[0] - P[1];
		}
		else {
			vector<LL>P;
			for (int i = 0; i < (int)A.size(); ++i) {
				//cout << A[i] << " " << B[i] << endl;
				avec.push_back({ A[i],B[i] });
				P.push_back(A[i] - B[i]);
			}
			for (int i = (int)A.size(); i < B.size() - 1; ++i) {
				avec.push_back({ P.back(),B[i] });
				P.back() -= B[i];
			}
			P.push_back(B.back());
			while (P.size() > 2) {
				//cout << P.back() << " " << P[P.size() - 2] << endl;
				avec.push_back({ P.back() , P[P.size() - 2] });
				LL tmp = P.back() - P[P.size() - 2];
				P.pop_back();
				P.pop_back();
				P.push_back(tmp);
			}
			//cout << P[0] << " " << P[1] << endl;
			avec.push_back({ P[0],P[1] });
			ans = P[0] - P[1];
		}
	}
	else if (A.size()) {
		//全部正
		sort(A.rbegin(), A.rend());
		auto P = A;
		while (P.size() > 2) {
			//cout << P.back() << " " << P[P.size() - 2] << endl;
			avec.push_back({ P.back() , P[P.size() - 2] });
			LL tmp = P.back() - P[P.size() - 2];
			P.pop_back();
			P.pop_back();
			P.push_back(tmp);
		}
		//cout << P[0] << " " << P[1] << endl;
		avec.push_back({ P[0],P[1] });
		ans = P[0] - P[1];
	}
	else {
		//全部負
		sort(B.begin(), B.end());
		auto P = B;
		while (P.size() > 2) {
			//cout << P.back() << " " << P[P.size() - 2] << endl;
			avec.push_back({ P.back() , P[P.size() - 2] });
			LL tmp = P.back() - P[P.size() - 2];
			P.pop_back();
			P.pop_back();
			P.push_back(tmp);
		}
		//cout << P[0] << " " << P[1] << endl;
		avec.push_back({ P[1],P[0] });
		ans = P[1] - P[0];
	}
	cout << ans << endl;
	for (auto p : avec) {
		cout << p.first << " " << p.second << endl;
	}
	return 0;
}

Measured memory_bytes: 5136
#include <iostream>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <utility>
#include <stack>
#include <queue>
#include <sstream>
#include <fstream>
#include <float.h>
#include <cmath>
#include <cstring>

using namespace std;
#define int long long

signed main() {
	int N;
	cin >> N;
	int tmp = 0;
	tmp = N / 15;
	cout << (N * 800) - (tmp * 200) << endl;;
	return 0;
}


Measured memory_bytes: 764
#include<bits/stdc++.h>
using namespace std;
#define next Next
#define last Last
#define int long long
const int N=1e5+5;
int n,m,a[N],b[N],c[N],dp[N];
vector<int>g[N];
/*char buf[1<<21],*p1=buf,*p2=buf;
inline int gc(){return p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++;}*/
#define gc getchar
inline int read()
{
	int ret=0,f=0;char c=gc();
	while(!isdigit(c)){if(c=='-')f=1;c=gc();}
	while(isdigit(c)){ret=ret*10+c-48;c=gc();}
	if(f)return -ret;return ret;
}
signed main()
{
	n=read();m=read();
	for(int i=1;i<=m;i++)
	{
		a[i]=read();
		b[i]=read();
		for(int j=1;j<=b[i];j++)
		{
			int x=read();
			c[i]|=(1<<(x-1));
			g[x].push_back(i);
		}
	}
	for(int i=1;i<=n;i++)
		if(g[i].size()==0){puts("-1");return 0;}
	memset(dp,0x3f,sizeof(dp));
	dp[0]=0;
	for(int i=0;i<(1<<n);i++)
	{
		for(int j=1;j<=n;j++)
			if(!(i&(1<<j)))
			{
				for(int k=0;k<g[j].size();k++)
				{
					int v=g[j][k];
					dp[i|c[v]]=min(dp[i|c[v]],dp[i]+a[v]);
				}
			}
	}
	cout<<dp[(1<<n)-1];
}


Measured memory_bytes: 4480
#include <stdio.h>
int main(){

  int a,b,c;

  scanf("%d %d %d",&a,&b,&c);

  if(a == 1 && b == 1 && c != 1) printf("Open\n");
  else if (a != 1 && b != 1 && c == 1) printf("Open\n");
  else printf("Close\n");

  return 0;

}

Measured memory_bytes: 584
n = int(input())
a = list(map(int, input().split()))  # 初期のモンスターの数
b = list(map(int, input().split()))  # 各勇者が倒せるモンスターの数
num = 0
for i in range(n):
    # 倒したモンスターの数をnumに追加
    num += min(a[i], b[i])
    if b[i] - a[i] > 0:  # モンスターが残っていないとき
        # 隣町の勇者が倒せるモンスターの数か，隣町のモンスター全てか．
        num += min(b[i] - a[i], a[i + 1])
        # 隣町のモンスター数は残っているか，全滅しているか．
        a[i + 1] = max(a[i+1]-(b[i] - a[i]), 0)
print(num)

Measured memory_bytes: 18476
N = int(input())
h = list(map(int, input().strip().split()))

c = [0] * N
c[1] = abs(h[1] - h[0])
for i in range(2, N):
  c[i] = min(abs(h[i - 2] - h[i]) + c[i - 2], abs(h[i - 1] - h[i]) + c[i - 1])

print(c[N - 1])


Measured memory_bytes: 13928
import sys
input = sys.stdin.readline

def main():
	n = int(input().strip())
	a = [0] * n
	for i in range(n):
		a[i] = int(input().strip())
	b = sorted(a, reverse=True)
	first = b[0]
	second = b[1]
	for i in range(n):
		if a[i] == first:
			print(second)
		else:
			print(first)

if __name__ == '__main__':
	main()


Measured memory_bytes: 55004
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace abc168_b
{
    class Program
    {
        static void Main(string[] args)
        {
            int k = int.Parse(Console.ReadLine()); 
            string s = Console.ReadLine();
            int S = s.Length;
            if(S<=k)
            {
                Console.WriteLine(s);
            }
            else
            {
                string output = s.Substring(0, k);
                Console.WriteLine(output+ "...");
            }
            Console.ReadLine();
        }
    }
}


Measured memory_bytes: 27440
//                             In The Name Of Allah
#include <bits/stdc++.h>
#define ss second
#define ff first
#define use_fast ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define ret(n) return cout << n, 0
#define se(n) cout << setprecision(n) << fixed
#define pb push_back
#define int long long 
using namespace std; 

const long long N = 1e6 + 100, OO = 1e18, M = 1e9 + 7, M2 = 998244353, sq = 31622, lg = 23;
typedef pair <int, int> pii;
int a[N];

int32_t main() {
	use_fast;
	int a, b;
	cin >> a >> b;
	int t = __gcd(a, b), ans = 1;
	for(int i = 2; i * i <= t; i++) {
		int k = 0;
		while(t % i == 0)
			t /= i, k++;
		if(k)
			ans++;
	}
	if(t != 1)
		ans++;
	cout << ans << endl;
	return 0;
}
/*
be carefull :
1- if not solve after 20 min, read again twice
2- after submit read the code again
3- fun with contest
4- ... 
*/

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define vi vector<int>
#define vll vector<ll>
#define vvll vector<vll>
#define vvi vector<vector<int>>
#define vvb vector<vector<bool>>
#define vb vector<bool>
#define pii pair<int, int>
#define vpli vector<pair<long long, int>>
#define deb(x) cout << "deb " << #x << " " << x << endl
#define all(x) x.begin(), x.end()
#define endl "\n"
int cycle_len;
vi ord;

void dfs(int s,vi& vis,vvi &adj,int& tot)
{
    tot++;
    for(int x : adj[s])
    {
        if(!vis[x])
        {
            ord.pb(x);
            vis[x] = vis[s]+1;
            dfs(x,vis,adj,tot);
        }
        else
        {
            cycle_len = vis[s] - vis[x]+1;
            return;
        }
        
    }
}
int dfs2(int s,vvi& adj,int k)
{
    if(k==0) return s+1;
    for(int x : adj[s])
    {
        return dfs2(x,adj,k-1);
    }
}
void solve()
{
    int n;
    ll k;
    cin>>n>>k;
    vvi adj(n);
    int u;
    for(int i=0;i<n;i++)
    {
        cin>>u;
        u--;
        adj[i].pb(u);
    }
    vi vis(n,0);
    vis[0] =1;
    int tot = 0;
    ord.pb(0);
    dfs(0,vis,adj,tot);
    int non_cyc = tot-cycle_len; 
    if(k>=tot)
    {
        k -= non_cyc;
        k = k%cycle_len;
        k += non_cyc;
    }
    cout<<ord[k]+1<<endl;
    //cout<<dfs2(0,adj,k); 
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    //pre();
    int t = 1;
    //cin >> t;
    //cout<<__gcd(-5,0)<<endl;
    while (t--)
        solve();
    return 0;
}


Measured memory_bytes: 34360
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  ll n;
  cin >> n;
  vl a(n);
  rep(i, n) cin >> a[i];
  map<ll, ll> mp;
  ll ans = 0;
  rep(i, n) {
    ans += mp[i - a[i]];
    mp[i + a[i]]++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 27484
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <climits>
#include <cstdlib>
#include <vector>
using namespace std;
#define ALL(a) (a).begin(),(a).end()
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define INF (INT_MAX/3)
#define PSB push_back
#define M 1000000007
typedef long long LL;
//#define int long long

/*
//booooooooooooost
#include <boost/multiprecision/cpp_int.hpp>
namespace mp = boost::multiprecision;	//多倍長整数(mp::cpp_int)
*/

int inv_mod(int a, int m)
{
	int b, x, u, q, tmp;

	b = m; x = 1; u = 0;
	while (b > 0) {
		q = a / b;
		tmp = u; u = x - q * u; x = tmp;
		tmp = b; b = a - q * b; a = tmp;
	}

	return (x < 0) ? m + x : x;
}



signed main() {


	string s;
	string ans = "";
	cin >> s;
	REP(i, s.size()) {
		if (s[i] != 'B') {
			ans.PSB(s[i]);
		}
		else {
			if (ans.size() != 0) {
				ans.pop_back();
			}
		}
	}

	cout << ans << endl;

	return 0;
}

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

using namespace std;


template<class M, class F = std::function<M(M, M)>>
class SegmentTree{
private:
  std::vector<M> data;
  F op;
  M e;
  int length;

public:
  SegmentTree(int n, const F op, const M& e) : op(op), e(e){
    length = 1;
    while(length < n) length <<= 1;
    data = std::vector<M>((length << 1) - 1, e);
  }

  void update(int index, const M& x){
    index += length - 1;
    data[index] = x;

    while(index){
      (--index) >>= 1;
      data[index] = op(data[(index << 1) + 1], data[(index << 1) + 2]);
    }
  }

  M query(int left, int right){
    M l = e, r = e;

    for(left += length - 1, right += length - 1; left < right; (--left) >>= 1, (--right) >>= 1){
      if((left ^ 1) & 1) l = op(data[left++], l);
      if((right ^ 1) & 1) r = op(data[--right], r);
    }

    return op(l, r);
  }
};

const long long INF = (1ll << 31) - 1;

int main(){
  int n, q;
  cin >> n >> q;
  
  SegmentTree<long long> segTree(n + 1, [](int a, int b){
    return min(a, b);
  }, INF);
  
  while(q--){
    int com, x, y;
    cin >> com >> x >> y;
    
    if(com) cout << segTree.query(x, y + 1) << endl;
    else segTree.update(x, y);
  }
  
  return 0;
}


Measured memory_bytes: 4916
#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;
    string s,t;
    cin >> n >> s >> t;
    REP(i,0,n) cout << s[i] << t[i];
    cout << endl;
}

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

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(a) (a).begin(), (a).end()

using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;

int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;

  int res = 0;
  for (int i = A; i <= B; i++) {
    for (int j = C; j <= D; j++) {
      if (i == j) res++;
    }
  }

  res = (res > 0) ? res - 1 : 0;
  cout << res << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int N;   //参加回数 
    int R;   //表示
    int X;   //内部

    scanf("%d", &N);
    scanf("%d", &R);

    if(N >= 10){
        X = R;

    }else{
        X = R + 100 * (10-N);

    }
    printf("%d", X);

    return 0;

}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define INF (2e9)
#define NIL (-1)

struct Node { int parent, left, right; };

Node Tree[30];
int Depth[30], Height[30], Sibling[30], Degree[30];

void print(int node) {
  cout << "node " << node << ": ";
  cout << "parent = " << Tree[node].parent << ", ";
  cout << "sibling = " << Sibling[node] << ", ";
  cout << "degree = " << Degree[node] << ", ";
  cout << "depth = " << Depth[node] << ", ";
  cout << "height = " << Height[node] << ", ";

  if (Tree[node].parent == NIL) cout << "root";
  else if (Tree[node].left == NIL && Tree[node].right == NIL) cout << "leaf";
  else cout << "internal node";

  cout << endl;
}

int searchDepth(int node, int depth){
  Depth[node] = depth;
  if(Tree[node].left != NIL) searchDepth(Tree[node].left, depth+1);
  if(Tree[node].right != NIL) searchDepth(Tree[node].right, depth+1);
}

int main() {
  int n, id, left_child, right_child, root_node; cin >> n;

  for(int i = 0; i < n; ++i) Tree[i].parent = Tree[i].left = Tree[i].right = NIL;
  
  for(int i = 0; i < n; ++i){
    cin >> id >> left_child >> right_child;
    Tree[id].left = left_child;
    Tree[id].right = right_child;
    if(left_child != NIL){
      Tree[left_child].parent = id;
      Sibling[left_child] = right_child;
    }
    if(right_child != NIL){
      Tree[right_child].parent = id;
      Sibling[right_child] = left_child;
    }
    
    Degree[id] = !signbit(left_child) + !signbit(right_child);
  }

  for(int i = 0; i < n; ++i){
    if(Tree[i].parent == NIL) root_node = i;
  }

  Sibling[root_node] = NIL;

  for(int i = 0; i < n; ++i){
    if(Tree[i].left == NIL && Tree[i].right == NIL){
      int cnt = 0, now = i;
      Height[now] = 0;
      while(Tree[now].parent != NIL){
        ++cnt;
        now = Tree[now].parent;
        Height[now] = max(Height[now], cnt);
      }
    }
  }

  searchDepth(root_node, 0);

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

  return 0;
}


Measured memory_bytes: 3096
#include <bits/stdc++.h>
using i64 = long long;

int main() {
    constexpr i64 inf = std::numeric_limits<i64>::max() / 3;
    int n, m, l;
    std::cin >> n >> m >> l;
    std::vector<std::vector<i64>> dist(n, std::vector<i64>(n, inf));
    for (int i = 0; i < n; i++) dist[i][i] = 0;
    auto d2(dist);
    for (int i = 0; i < m; i++) {
        int a, b;
        i64 c;
        std::cin >> a >> b >> c;
        --a; --b;
        dist[a][b] = dist[b][a] = c;
    }

    for (int k = 0; k < n; k++) for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) {
        dist[i][j] = std::min(dist[i][j], dist[i][k] + dist[k][j]);
    }

    for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) {
        if (dist[i][j] <= l) d2[i][j] = 1;
    }

    for (int k = 0; k < n; k++) for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) {
        d2[i][j] = std::min(d2[i][j], d2[i][k] + d2[k][j]);
    }

    int q;
    std::cin >> q;
    while (q--) {
        int s, t;
        std::cin >> s >> t;
        auto d = d2[s - 1][t - 1];
        std::cout << (d == inf ? -1 : d - 1) << std::endl;
    }

    return 0;
}


Measured memory_bytes: 1920
N = int(input())
a = list(map(int,input().split()))

x = a[0]
y = sum(a[1:])
res = abs(x - y)

for i in range(1, N - 1):
	x += a[i]
	y -= a[i]
	res = min(res, abs(x - y))

print(res)

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

using namespace std;

int main() {
    int n;
    cin >> n;
    int plus[n];
    for (int i=0; i<n; i++) {
        int pi;
        cin >> pi;
        plus[pi-1] = i;
    }
    for (int i=0; i<n; i++) 
        cout << n * i       + plus[i] + 1 << (i < n-1 ? ' ' : '\n');
    for (int i=0; i<n; i++) 
        cout << n * (n-i-1) + plus[i] + 1 << (i < n-1 ? ' ' : '\n');
    return 0;
}

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

using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int,int>;
using pll = pair<ll,ll>;

#define FOR(k,m,n) for(ll (k)=(m);(k)<(n);(k)++)
#define REP(i,n) FOR((i),0,(n))
#define WAITING(str) int str;std::cin>>str;
#define DEBUGING(str) cout<< #str << " " str<<endl

constexpr int INF = (1 << 30);
constexpr ll INFL = (1ll << 60);
constexpr ll MOD = 1000000007;// 10^9+7



int main()
{
    ll N,K;
    cin>>N>>K;
    vector<ll> a(N);
    vector<vector<ll>> dp(N,vector<ll>(K+1));
    REP(i,N)cin>>a[i];
    REP(i,min(a[0],K)+1)dp[0][i]=1;
    FOR(i,1,N)
    {
        REP(j,K)dp[i-1][j+1]=(dp[i-1][j+1]+dp[i-1][j])%MOD;
        REP(j,K+1)dp[i][j]=(MOD+dp[i-1][j]-(j-a[i]-1>=0?dp[i-1][j-a[i]-1]:0))%MOD;
    }
    cout<<dp.back().back()<<endl;
    return 0;
}


Measured memory_bytes: 79360
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<deque>
#include<cmath>
#include<map>
#include<cstring>

using namespace std;
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LLINF = 1LL<<60;
#define P pair<int, int>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define print(x) cout << (x) << endl

class mint {
    long long x;
public:
    mint(long long x=0) : x((x%MOD+MOD)%MOD) {}
    mint operator-() const {
      return mint(-x);
    }
    mint& operator+=(const mint& a) {
        if ((x += a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator-=(const mint& a) {
        if ((x += MOD-a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator*=(const  mint& a) {
        (x *= a.x) %= MOD;
        return *this;
    }
    mint operator+(const mint& a) const {
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint& a) const {
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint& a) const {
        mint res(*this);
        return res*=a;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    // for prime MOD
    mint inv() const {
        return pow(MOD-2);
    }
    mint& operator/=(const mint& a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint& a) const {
        mint res(*this);
        return res/=a;
    }

    friend ostream& operator<<(ostream& os, const mint& m){
        os << m.x;
        return os;
    }
};
/* -- template -- */


//一回の操作で，必ず２人を幸せにできる
int main() {
    int N, K; cin >> N >> K;
    string S; cin >> S;
    int ans = 0;
    rep(i, N - 1) {
        if(S[i] == S[i + 1]) ++ans;
    }
    cout << min(N - 1, ans + K * 2);
}


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

using namespace std;

bool isPrime(int x)
{
    if (x == 2)
        return true;
    else if (x <= 1 || x % 2 == 0)
        return false;
    for (int i = 3; i * i <= x; i += 2)
        if (x % i == 0)
            return false;
    return true;
}

int main()
{
    int n, x, ans = 0;
    cin >> n;
    rep(i, n)
    {
        cin >> x;
        if (isPrime(x))
            ans++;
    }
    printf("%d\n", ans);
}


Measured memory_bytes: 3128
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int start = 1;
  int finish = 2;
  bool finished = false;
  int N;
  cin >> N;
  vector<int> button(N);
  vector<bool> pushed(N);//default is false
  
  for(int i = 0; i < N; i++){
    cin >> button.at(i);
  }
  
  int n = 0;
  int count = 0;
  while(pushed.at(n) == false){
    count++;
    if(button.at(n) == 2){
      finished = true;
      break;
    }
    pushed.at(n) = true;
    n = button.at(n) - 1;
  }
  if(finished)
    cout << count << endl;
  else cout << -1 << endl;
}

Measured memory_bytes: 3768
#include<iostream>

using namespace std;


int main(){

//	Input数値　例題のgoto文の引数
	int n;
	cin >> n;

	for(int i = 1;i <= n;i++)
	{
//		CHECK_NUM
		if(i % 3 == 0)
		{
			cout << " " << i;
			continue; //	END_CHECK_NUM
		}


//		INCLUDE3
//		for文のループ→ goto INCLUDE3
		for(int k = i;k != 0; k /=10)
		{
			if((k%10) == 3)
			{
				cout << " " << i;
				break; //	END_CHECK_NUM
			}
		}
	}
	cout << endl;

	return 0;
}



Measured memory_bytes: 3112
#include<bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define int long long
#define vec(a,n) vector<int> (a)((n));
#define Vec(a,n) vector<string> (a)((n));
#define twovec(a,n,m) vector<vector<int>> a(n,vector<int>(m,0));
#define Twovec(a,n,m) vector<vector<double>> a(n,vector<double>(m,0));
#define P pair<int,int>
#define All(a) (a).begin(),(a).end()
#define Sort(a) sort(All(a));
#define Reverse(a) reverse(All(a));
#define PQ(n) priority_queue<P,vector<P>,greater<P>> (n)
#define pq(n) priority_queue<int> (n)
#define print(a) cout << (a) << endl;
#define printD(a) cout << setprecision(10) << ans << endl;
using namespace std;
int max_int = 1000000007;
void Debug(auto a);
int nibul(auto a,auto b);
int nibuu(auto a,auto b);
void input(vector<int>& a,int n);

int n;
struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

signed main(){
    string s;
    cin >> s;
    n = s.size()-1;
    int ans = 0;
    for(int bit = 0;bit < (1 << n); ++bit){
        deque<int> S;
        for (int i = 0; i < n; ++i) {
            if (bit & (1<<i)) { // i が bit に入るかどうか
                S.push_back(i);
            }
        }
        //Debug(S);
        int tmp = 0;
        REP(i,n+1){
            int t = s[i] - '0';
            //print(t)
            tmp = tmp * 10 + t;
            if(S.size() == 0) continue;
            if(i==S[0]){
                S.pop_front();
                ans += tmp;
                //print(tmp);
                tmp = 0;
            }
        }
        ans += tmp;
        
        //Debug(S);

    }
    print(ans)
    return 0;
}

void Debug(auto a){
    cout << "{ ";
    for(auto b: a){
        cout << b << " ";
    }
    cout << "}" << endl;
}
int nibul(auto a,auto b){
    int x = lower_bound(All(a),b) - a.begin();
    //key以上の初めてのitr
    return x;
}
int nibuu(auto a,auto b){
    int x = upper_bound(All(a),b) - a.begin();
    //key以下の最後のitr
    return x-1;
}

void input(vector<int>& a,int n){
    REP(i,n){
        cin >> a[i];
    }
}


Measured memory_bytes: 256