akhauriyash/Code-Regression huggingface dataset:
function main(){
  var i = 0;
  while(true){
    var fieldInfo = input[i].split(' ');
    var width = fieldInfo[0] - 0;
    var height = fieldInfo[1] - 0;
          
    if(!width && !height){
      break;
    }
          
    var start;
    var goal;
    var elem = [[],[],[],[],[]];
    var c;
    for(var y = height; y--;){
      i++;
      var ni = input[i];
      for(var x = 0; x < width; x++){
        c = ni[x];
        
        if(c === '.'){
        }else if(c === '1' || c === '2' || c === '3' || c === '4' || c === '5'){
          var e = elem[c - 1];
          e[e.length] = pos(x, y);
        }else if(c === 'S'){
          start = pos(x, y);
        }else{
          goal = pos(x, y);
        }
          
      }
    }
          
    var INF = 1 << 30;
    var bestElement = -1;
    var distance = INF;
    
    for (var startElem = 0; startElem < 5; startElem++) {
      
      var dp = [[],[],[],[],[]];
      for(var h = 0; h < 5; h++){
        var hLength = elem[h].length;
        var initdph = dp[h];
        dp[h].length = hLength;
        for(var hidx = 0; hidx < hLength; hidx++){
          initdph[hidx] = INF;
        }
      }
      
      var first = (startElem + 1) % 5;
      var firstLength = elem[first].length;
      var dpf = dp[first];
      var elemf = elem[first];
      for (var j = 0; j < firstLength; j++) {
        dpf[j] = dist(start, elemf[j]);
      }
      
      for (var e = 0; e < 3; e++) {
        var now = (first + e) % 5;
        var next = (now + 1) % 5;
        var dpnw = dp[now];
        var dpnx = dp[next];
        var elnw = elem[now];
        var elnx = elem[next];
        var nowLength = elnw.length;
        var nextLength = elnx.length;
        for (var j = 0; j < nowLength; j++) {
          var dpnwj = dpnw[j];
          var elnwj = elnw[j];
          for (var k = 0; k < nextLength; k++) {
            dpnx[k] = min(
              dpnx[k],
              dpnwj + 
                  dist(elnwj, elnx[k]));
          }
        }
      }

      var last = (first + 3) % 5;
      var dpl = dp[last];
      var ell = elem[last];
      var lastLength = ell.length;
      for (var j = 0; j < lastLength; j++) {
        var d = dpl[j] + dist(ell[j], goal);
        if (d < distance) {
          distance = d;
          bestElement = startElem + 1;
        }
                  
      }
                
    }
              
    if (distance == INF) {
      console.log("NA");
    } else {
      console.log(bestElement + " " + distance);
    }
          
    i++;
  }
            
          
}
          
function dist(from, to){
  return abs((from >> 11) - (to >> 11)) + abs((from & 2047) - (to & 2047));
}
          
function min(a, b){
  var t = a - b;
 return b + (t & (t >> 31));
}
          
function pos(a, b){
  return (a << 11) + b;
}
         
function abs(a){
 var mask = a >> 31;
 return (a ^ mask) - mask;
}
          
var
input = '';
          
process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', function(chunk) {
  input += chunk;
});
process.stdin.on('end', function() {
  input = input.split('\n');
  main();
});

Measured memory_bytes: 51440
package main

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

func main() {

	X := oneInt()

	var sum int
	unit := X / 500
	sum = unit * 1000
	sum += ((X - 500*unit) / 5) * 5
	fmt.Print(sum)
}

func exp(val int) float64 {
	var temp float64
	for index := 1; index <= val; index++ {
		temp += float64(index)
	}
	return temp / float64(val)
}

func searchAbove(slice []int, target int, index int) int {
	for i := index + 1; i < len(slice); i++ {
		v := slice[i]
		if v >= target {
			return i
		}
	}
	return -1
}

var sc = bufio.NewScanner(os.Stdin)

func oneInt() int {
	var a int
	fmt.Scan(&a)
	return a
}
func oneStr() string {
	var a string
	fmt.Scan(&a)
	return a
}

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

func scanNums() (nums []int) {
	s := nextLine()
	numStr := strings.Split(s, " ")

	for _, n := range numStr {
		i, _ := strconv.Atoi(n)
		nums = append(nums, i)
	}
	return nums
}

func scanStrings() (strs []string) {
	s := nextLine()
	list := strings.Split(s, " ")
	strs = append(strs, list...)
	return strs
}

func abs(a int) int {
	return int(math.Abs(float64(a)))
}

func pow(p, q int) int {
	return int(math.Pow(float64(p), float64(q)))
}

func min(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton min() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Min(float64(res), float64(nums[i])))
	}
	return res
}

func max(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton max() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Max(float64(res), float64(nums[i])))
	}
	return res
}

func strSearch(a []string, b string) bool {
	for i := 0; i < len(a); i++ {
		if a[i] == b {
			return true
		}
	}
	return false
}

func sortAsc(a []int) []int {
	sort.Ints(a)
	return a
}

func sortDesc(a []int) []int {
	sort.Sort(sort.Reverse(sort.IntSlice(a)))
	return a
}

func gcd(a, b int) int {
	if b == 0 {
		return a
	}
	return gcd(b, a%b)
}

func lcm(a, b int) int {
	if a == 0 && b == 0 {
		return 0
	}
	return a * b / gcd(a, b)
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main(){
  int n, y;
  cin >> n >> y;
  
  for(int i = 0; i < 2001; i++){
    for(int j = 0; j < 2001; j++){
      if(10000*i + 5000*j + 1000*(n-i-j) == y && n-i-j >= 0){
        cout << i << " " << j << " " << n-i-j << endl;
        return 0;
      }
    }
  }
  
  cout << -1 << " " << -1 << " " << -1 << endl;
  return 0;
}

Measured memory_bytes: 3612
import scala.io.StdIn.readInt

object Main {
  def fib(a:Int, b:Int, c:Int, n:Int):Int = {
    n match {
      case 0 => a
      case n => fib(a+b, a, b, n-1)
    }
  }

  def main(args: Array[String]) = {
    val n = readInt()
    println(fib(1, 0, 0, n))
  }
}

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

// @@ !! LIM()

int main(/* int argc, char *argv[] */) {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << setprecision(20);

  string S; cin >> S;
  ll K; cin >> K;
  ll cnt = 0;
  while (S[cnt] == '1') cnt++;
  cout << (cnt >= K ? '1' : S[cnt]) << endl;

  return 0;
}



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

long long int lcm(long long int a, long long int b){
    return (a *b) / __gcd(a, b);
}

int main(){
        long long int a, b, c, d; cin >> a >> b >> c >> d;
        a -= 1;
        long long int e = lcm(c, d);
        long long int r = (b / c) + (b / d) - (b / e);
        long long int l = a / c + a / d - a / e;
        long long int num = b - a;
        long long int div = r - l;
        num -= div;
        cout << num << endl;
    return 0;
}



Measured memory_bytes: 3600
S =input()

if S == "SUN":
    print(7)
elif S == "MON":
    print(6)
elif S == "TUE":
    print(5)
elif S == "WED":
    print(4)
elif S == "THU":
    print(3)
elif S == "FRI":
    print(2)
elif S == "SAT":
    print(1)

Measured memory_bytes: 9096
import java.util.Scanner;

public class Main {
    static long x;
    static int mod = 1000000007;
    static int[] dp;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        x = sc.nextLong();
        long ans = 2* (x/11);
        if (x%11 < 7 && x%11 > 0) {
            ans += 1;
        } else if (x%11 >= 7 ){
            ans += 2;
        }
        System.out.println(ans);
    }
}


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



int main() {
    int n; cin >> n;
    ll sum = 0;
    vector<int> a(n+2,0),b(n+2,0);
    for(int i = 1; i <= n; i ++) {
        cin >> a[i];
    }

    for(int i = 1; i <= n; i ++){
        if((a[i-1] <= a[i] && a[i] <= a[i+1]) || (a[i-1] >= a[i] && a[i] >= a[i+1])){
            b[i] = 1;
        }
        sum += abs(a[i] -a[i-1]);
    }
    sum += abs(a[n]);

    for(int i = 1; i <= n; i ++){
        if(b[i] == 1) cout << sum << endl;
        else{
            cout << sum - abs(a[i]-a[i-1]) - abs(a[i]-a[i+1]) + abs(a[i-1]-a[i+1])<< endl;
        }
    }


    return 0;
}











Measured memory_bytes: 4052
def orderN(N,L,ices):
    upPeak = L - ices[0]
    downPeak = L - ices[0]
    peaks = []
    append = peaks.append
    for i in xrange(len(ices)):
        if i < N-1:
            if ices[i] < ices[i+1]:
                append(downPeak)
                downPeak = L - ices[i+1]
                upPeak += L - ices[i+1]
            else:
                append(upPeak)
                upPeak = L - ices[i+1]
                downPeak += L - ices[i+1]
        else:
            append(upPeak)
            append(downPeak)
    print(max(peaks))

N,L = map(int,raw_input().strip().split())
ices = [int(raw_input().strip()) for _ in xrange(N)]

orderN(N,L,ices)

Measured memory_bytes: 12540
n,m=map(int,input().split())
keys = []
A = [0]*m
for i in range(m):

    a,b=map(int,input().split())
    A[i] = a
    k = 0
    for c in map(int,input().split()):
        k = k| 2**(c-1)
        ## 鍵kがc番目の宝箱を開けられる--> k & 2**(c-1) == 1
    keys.append(k)



dp = [[10**9]*2**n for i in range(m+1)] #dp[i][j] iまで使って状態jを実現する最小コスト
dp[-1][0] = 0
for i in range(m):
    a = A[i]
    k = keys[i]
    for j in range(2**n):
        dp[i][j|k] = min(dp[i-1][j|k],dp[i-1][j]+a,dp[i][j|k])
        ## j|k -->jにkを使って開けられる宝箱の種類
        ## 前のまま(dp[i][j|k]) or jに鍵を使う(dp[i-1][j]+a)
        dp[i][j] = min(dp[i][j],dp[i-1][j]) # 鍵を使わない場合の更新
ans = dp[m-1][2**n-1]
if ans ==10**9:
    print(-1)
else:
    print(ans)


Measured memory_bytes: 80472
#include <algorithm>
#include <iostream>
#include <string>

int main() {
    std::string s1, s2;
    std::cin >> s1 >> s2;
    
    std::sort(s1.begin(), s1.end());
    std::sort(s2.rbegin(), s2.rend());
    const auto ret = (s1 < s2) ? "Yes" : "No";

    std::cout << ret << std::endl;
}


Measured memory_bytes: 256
#include"bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef vector<int> vi;

int main(void) {
	
	ll N;
	cin >> N;

	ll a = sqrt(N) +1000;
	vector<int> b(a);

	for (int i = 2; i < a;i++) {
		b[i] = 0;
	}

	for (ll i = 2; i < a; i++) {
		int c = 0;
		while (c==0) {
			if (N%i==0) {
				N /= i;
				b[i] += 1;
			}
			else {
				c = 1;
			}
		}

	}

	int count = 0;

	if (N>1) {
		count++;
	}

	for (int i = 2; i < a; i++) {
		if (b[i]!=0) {
			int d = 1;
			int e = 1;
			while (d==1) {
				if (b[i]>=e) {
					b[i] -= e;
					e++;
					count++;
				}
				else {
					d = 0;
				}
			}
		}
	}

	cout << count << endl;

	return 0;
}

Measured memory_bytes: 7220
use proconio::fastout;
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;
use std::cmp::min;

#[fastout]
fn main() {
    input! {
        n: isize,
        k: isize,
    }
    let i = n % k;
    println!("{}", min(i, (k - i).abs()));
}


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

int main() {
	int a, b;
	string s;
	for (int i = 0; i < 9; i++) {
		cin >> s >> a >> b;
		cout << s << " " << a + b << " " << a * 200 + b * 300 << endl;
	}
	return 0;
}

Measured memory_bytes: 1200
# define _CRT_SECURE_NO_WARNINGS 1
# define _USE_MATH_DEFINES
# include <iostream>
# include <numeric>
# include <string>
# include <bitset>
# include <vector>
# include <algorithm>
# include <cstdlib>
# include <cstdio>
# include <cstring>
# include <cstdlib>
# include <iomanip>
# include <queue>
# include <sstream>
# include <climits>
# include <complex>
# include <cmath>
# include <list>
# include <functional>
# include <string>
# include <ctime>
# include <set>
# include <forward_list>
# include <map>
# include <stack>
using namespace std;
# define INF ((int)(1<<25))
# define REP(i,n) for(int i=0;i<(int)n;i++)
# define FOR(i,n) REP(i,n)
# define FORI(i,k,n) for(int i=k;i<(int)n;i++)
# define TORAD 2.0*M_PI/360.0
# define INT(x) int x;cin>>x;
# define STR(x) string x;cin>>x;
# define ALL(x) begin(x),end(x)
# define RALL(x) (x).rbegin(),(x).rend()
# define DEBUG(x) cout<<#x<<":"<<x<<endl;
# define EPS 1e-12
#ifdef _MSC_VER
#include <intrin.h>
#define __builtin_popcount __popcnt
#endif
typedef long long lint;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<int> vi;
typedef vector<lint> vl;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
const int dx[4] = { 0,1,0,-1 }, dy[4] = { -1,0,1,0 };
template<class T> void debug(T a) { for (auto i : a)cout << i << endl; }

typedef vector<vi> P;
int h, w, c;

int hoge(P &a,int t)
{
	int o = a[1][1];
	a[1][1] = t;
	queue<pii> que;
	que.push(pii(1, 1));
	int ans = 0;
	while (!que.empty())
	{
		pii now = que.front(); que.pop();
		FOR(j, 4)
		{
			int x = now.first + dx[j];
			int y = now.second + dy[j];
			if (a[x][y] == o)
			{
				a[x][y] = t;
				que.push(pii(x, y));
				ans++;
			}
		}
	}
	return ans+1;
}


int calc(P p,int now)
{
	int ans = 0;
	if (now == 5)
	{
		if (p[1][1] != c)return 0;
		return hoge(p, 0);
	}
	FORI(i, 1, 6 + 1)
	{
		P a=p;
		if (i == a[1][1])continue;
		hoge(a, i);
		ans = max(ans, calc(a, now + 1));
	}
	return ans;
}

int main()
{
	while (true)
	{
		cin >> h >> w >> c;
		if (!h)break;
		vi wall(10, -1);
		P a(10, wall);
		FORI(i, 1, h + 1)
		{
			FORI(j, 1, w + 1)
			{
				cin >> a[i][j];
			}
		}
		cout << calc(a,0) << endl;
	}
}

Measured memory_bytes: 3136
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
using namespace std;
const int mod = 1000000007;
#define ll long long

int main()
{
	int X; cin >> X;
	if (X == 3 || X == 5 || X == 7) cout << "YES" << endl;
	else cout << "NO" << endl;

}

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

int main(void)
{
    string check = "Hoshino";
    int n; cin >> n;

    for (int i = 0; i < n; i++) {
        string str; 
        if(i == 0) cin.ignore();
        getline(cin, str);
        if( str.length() < 7) {
            cout << str << endl;
            continue;
        }
        for (int j = 0; j < str.length()-6; j++) {
            for (int k = 0; k < 7; k++) {
                //printf("%c %c\n", check[k], str[j+k]);
                if (check[k] == str[j+k] && k < 6) continue;
                else if (check[k] == str[j+k] && k == 6) {
                    str[j+k] = 'a';
                } else break;
            }
        }
        cout << str << endl;
    }
    return 0;
}

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

using namespace std;

int main() {

  int n,k;
  
  cin >> n >> k;
  
  int arr[1000];
  
  for (int i = 0; i < n; i++) {
	cin >> arr[i];
  }
  
  sort(arr, arr+n);
  
  int sum = 0;
  for (int i = 0; i< k; i++) {
	sum += arr[i];

  }
  
  cout << sum << "\n";

}









Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
int main(){
  ll n;
  cin >> n;
  vector<int> a(n);
  rep(i,n){
    cin >> a.at(i);
  }
  ll ans=1,sum=1;
  rep(i,n){
    sum*=3;
    if(a.at(i)%2==0){
      ans*=2;
    }
  }
  cout << sum-ans;
  
}


Measured memory_bytes: 3520
a=int(input())
b=[input() for i in range(a)]
c=0
d=0
e=0
f=0
for i in range(a):
  if b[i]=="AC":
    c=c+1
  if b[i]=="WA":
    d=d+1
  if b[i]=="TLE":
    e=e+1
  if b[i]=="RE":
    f=f+1
print("AC","x",c)
print("WA","x",d)
print("TLE","x",e)
print("RE","x",f)

Measured memory_bytes: 16084
#include <algorithm>
#include <cassert>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

#include <limits.h>

using namespace std;

typedef long long ll;

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;
}

const int MAX_N = 500;

// trains[i][j] means the number of trains which starts from i (=L) to j (=R)
vector<vector<int>> trains;

vector<vector<int>> acc;

int main(void) {
    int N, M, Q;
    cin >> N >> M >> Q;

    trains.resize(N + 1, vector<int>(N + 1, 0));
    for (int i = 0; i < M; i++) {
        int L, R;
        cin >> L >> R;
        trains[L][R]++;
    }

    acc.resize(N + 1, vector<int>(N + 1, 0));
    for (int l = 1; l <= N; l++) {
        for (int r = 1; r <= N; r++) {
            acc[l][r] = acc[l][r - 1] + acc[l - 1][r] - acc[l - 1][r - 1] + trains[l][r];
        }
    }

    // for (int l = 1; l <= N; l++) {
    //     for (int r = 1; r <= N; r++) {
    //         acc[l][r] += trains[l][r];
    //     }
    // }
    // for (int l = 1; l <= N; l++) {
    //     for (int r = 1; r <= N; r++) {
    //         acc[l][r] += acc[l - 1][r];
    //         acc[l][r] += acc[l][r - 1];
    //         acc[l][r] -= acc[l - 1][r - 1];
    //     }
    // }

    // for (int l = 0; l <= N; l++) {
    //     for (int r = 0; r <= N; r++) {
    //         cout << acc[l][r] << " ";
    //     }
    //     cout << endl;
    // }

    for (int i = 0; i < Q; i++) {
        int p, q;
        cin >> p >> q;
        // printf("[%d, %d]\n", p, q);
        p--;

        cout << acc[q][q] - acc[p][q] - acc[q][p] + acc[p][p] << endl;
    }

    return 0;
}


Measured memory_bytes: 2944
#include <bits/stdc++.h>
using namespace std;
int main(){
	int a, b;
	cin>>a>>b;
	if(a + b == 15){cout<<"+"<<endl;return 0;}
	if(a * b == 15){cout<<"*"<<endl; return 0;}
	cout<<"x"<<endl;
	return 0;
}


Measured memory_bytes: 256
use std::error::Error;
use std::io::{self, BufRead, BufWriter, Write};

type AppResult<T> = Result<T, Box<dyn Error>>;

fn solve<R, W>(reader: R, mut writer: W) -> AppResult<()>
where
    R: BufRead,
    W: Write,
{
    let mut lines = reader.lines();
    let a_line = lines.next().ok_or("no lines")??;
    let mut splited = a_line.trim().split_whitespace();
    let n: u32 = splited.next().ok_or("N not found")?.parse()?;
    let m: u32 = splited.next().ok_or("M not found")?.parse()?;
    // let a: u32 = splited.next().ok_or("a not found")?.parse()?;
    // let b: u32 = splited.next().ok_or("b not found")?.parse()?;

    writeln!(&mut writer, "{}", if n == m { "Yes" } else { "No" })?;
    Ok(())
}

fn main() -> AppResult<()> {
    let stdio = io::stdin();
    let input = stdio.lock();

    let stdout = io::stdout();
    let output = BufWriter::new(stdout.lock());

    solve(input, output)
}

#[cfg(test)]
mod tests {
    use super::*;

    const TESTS: &'static [(&'static [u8], &'static [u8])] = &[
        (
            br"3 3", br"Yes
",
        ),
        (
            br"3 2", br"No
",
        ),
        (
            br"1 1", br"Yes
",
        ),
    ];

    #[test]
    fn test_a() -> AppResult<()> {
        for &(input, expected) in TESTS {
            let mut output = Vec::new();
            solve(input, &mut output)?;
            let expected_str = String::from_utf8(expected.to_vec())?;
            let output_str = String::from_utf8(output)?;
            assert_eq!(expected_str, output_str);
        }
        Ok(())
    }
}


Measured memory_bytes: 2112
import sys
import numpy as np
import numba
from numba import jit

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

@jit
def main(n, a):
  ans = np.zeros(n)
  for i, j in enumerate(a):
    ans[j-1] = i+1
  for i in ans:
    print(int(i), end=' ')
n = int(readline())
a = np.array(readline().split(), np.int64)
main(n,a)

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

public class Main {

	public static void main(String[] args) {
		new Main().solveA();
		// new Main().solveB();
		// new Main().solveC();
		// new Main().solveD();
	}

	private void solveA() {
		Scanner scanner = null;

		try {
			scanner = new Scanner(System.in);
			int[] line = new int[3];
			for (int i = 0; i < 3; i++) {
				line[i] = scanner.nextInt();
			}

			Arrays.sort(line);

			int result = line[2] * 10 + line[1] + line[0];

			System.out.println(result);

		} finally {
			if (scanner != null) {
				scanner.close();
			}
		}
	}

	private void solveB() {
		Scanner scanner = null;
		int lineAB = 0;
		int lineBC = 0;
		int lineCA = 0;

		try {
			scanner = new Scanner(System.in);
			lineAB = scanner.nextInt();

			System.out.println("");

		} finally {
			if (scanner != null) {
				scanner.close();
			}
		}
	}

	private void solveC() {
		Scanner scanner = null;
		int lineAB = 0;
		int lineBC = 0;
		int lineCA = 0;

		try {
			scanner = new Scanner(System.in);
			lineAB = scanner.nextInt();

			System.out.println("");

		} finally {
			if (scanner != null) {
				scanner.close();
			}
		}
	}

	private void solveD() {
		Scanner scanner = null;
		int lineAB = 0;
		int lineBC = 0;
		int lineCA = 0;

		try {
			scanner = new Scanner(System.in);
			lineAB = scanner.nextInt();

			System.out.println("");

		} finally {
			if (scanner != null) {
				scanner.close();
			}
		}
	}
}

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

using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end) for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define eprintf(...) 42
#endif

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


    int n, k;
    cin >> n >> k;

    int ans=0;

    vector<int> v(n);
    REP(i, k) {
        int d;
        cin >> d;
        vector<int> a(d);
        REP(j,d)cin >> a[j];
        REP(j, d)
            v[a[j]-1]=1;
        }

    REP(i, n){
        ans += v[i];
    }
    
    cout << n-ans <<"\n";

    return 0;
}

Measured memory_bytes: 3664
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n; cin >> n;
  vector<int> a(n);
  REP(i,n) cin >> a[i];
  
  int total = 1;
  int ex = 1;
  REP(i,n){
    total *= 3;
    if(a[i]%2==0) ex *= 2;
  }
  cout << total - ex << '\n';
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#define fo(i,a,b) for(LL i=a;i<=b;++i)
#define fod(i,a,b) for(int i=a;i>=b;--i)
#define efo(i,q) for(int i=A[q];i;i=B[i][0])
#define max(q,w) ((q)>(w)?(q):(w))
using namespace std;
typedef long long LL;
const int N=100500,mo=998244353;
int read(int &n)
{
	char ch=' ';int q=0,w=1;
	for(;(ch!='-')&&((ch<'0')||(ch>'9'));ch=getchar());
	if(ch=='-')w=-1,ch=getchar();
	for(;ch>='0' && ch<='9';ch=getchar())q=q*10+ch-48;n=q*w;return n;
}
int n;
LL f[N][3];
int B[2*N][3],A[N],B0;
int Si[N];
void link(int q,int w,int e)
{
	B[++B0][0]=A[q],A[q]=B0,B[B0][1]=w,B[B0][2]=e;
	B[++B0][0]=A[w],A[w]=B0,B[B0][1]=q,B[B0][2]=e;
}
int dfs(int q,int fa)
{
	Si[q]=1;
	efo(i,q)if(B[i][1]!=fa)Si[q]+=dfs(B[i][1],q),f[q][0]+=f[B[i][1]][0]+(LL)B[i][2]*min(Si[B[i][1]]*2,(n-Si[B[i][1]])*2-2);
	efo(i,q)if(B[i][1]!=fa)
	{
f[q][2]=max(f[q][2],f[q][1]-(LL)B[i][2]*min(Si[B[i][1]]*2,(n-Si[B[i][1]])*2-2)-f[B[i][1]][0]+f[B[i][1]][1]+(LL)B[i][2]*min(Si[B[i][1]]*2-1,(n-Si[B[i][1]])*2-1));
f[q][1]=max(f[q][1],f[q][0]-(LL)B[i][2]*min(Si[B[i][1]]*2,(n-Si[B[i][1]])*2-2)-f[B[i][1]][0]+f[B[i][1]][1]+(LL)B[i][2]*min(Si[B[i][1]]*2-1,(n-Si[B[i][1]])*2-1));
f[q][2]=max(f[q][2],f[q][0]-(LL)B[i][2]*min(Si[B[i][1]]*2,(n-Si[B[i][1]])*2-2)-f[B[i][1]][0]+f[B[i][1]][2]+(LL)B[i][2]*min(Si[B[i][1]]*2-2,(n-Si[B[i][1]])*2));
	}
	f[q][2]=max(f[q][2],f[q][1]);
	f[q][1]=max(f[q][1],f[q][0]);
	return Si[q];
}
int main()
{

	int q,w,e;
	read(n);
	fo(i,1,n-1)read(q),read(w),read(e),link(q,w,e);
	dfs(1,0);
	printf("%lld\n",f[1][2]);
	return 0;
}

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

typedef long long ll;
const ll N = 100005, L = 262144;

ll n, a[N], b[N];

struct segtree {
	ll v[2*L];
	void init () {
		for(ll i=2*L;i--;) {
			v[i] = 0;
		}
	}
	void upd (ll P, ll V) {
		P += L;
		while(P) {
			v[P] += V;
			P /= 2;
		}
	}
	ll get (ll S, ll E) {
		S += L;
		E += L;
		ll R = 0;
		while(S <= E) {
			if(S%2 == 1) R += v[S++];
			if(E%2 == 0) R += v[E--];
			S /= 2;
			E /= 2;
		}
		return R;
	}
} seg;

ll cnt () {
	seg.init();
	ll C = 0, R = 0;
	seg.upd(N, 1);
	for(ll i=1;i<=n;i++) {
		C += (b[i] == 1 ? -1 : 1);
		seg.upd(N+C, 1);
	}
	C *= -1;
	for(ll i=n;i>=1;i--) {
		seg.upd(N-C, -1);
		R += seg.get(N-C, 2*N);
		C += (b[i] == 1 ? -1 : 1);
	}
	return R;
}

int main()
{
	scanf("%lld",&n);
	ll S = 0, E = 0;
	for(ll i=1;i<=n;i++) {
		scanf("%lld",&a[i]);
		E = max(E, a[i]);
	}
	while(S<E) {
		ll M = (S+E)/2 + 1;
		for(ll i=1;i<=n;i++) {
			b[i] = (a[i] >= M);
		}
		ll C = cnt();
		C < (n*(n+1)/2+1)/2 ? E = M-1 : S = M;
	}
	E = 0;
	for(ll i=1;i<=n;i++) {
		if(a[i] <= S) E = max(E, a[i]);
	}
	printf("%lld\n", E);
}


Measured memory_bytes: 5888
#include<bits/stdc++.h>
using namespace std;
#define all(v) ((v).begin()),((v).end())
#define ll long long
#define fastIO cout << fixed << setprecision(12), ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)
double const EPS = 1e-9, PI = acos(-1);
const int N = 1e5 + 9, M = 1e2 + 9, OO = 1e9 + 7, MOD = 1e9 + 7;
const ll inf = 1e18;

ll mem[(1 << 16)], arr[16][16], val[(1 << 16)];
int n;

ll solve(int mask) {
  if(__builtin_popcount(mask) == n)
    return 0;
  ll& ret = mem[mask];
  if(~ret)
    return ret;
  ret = -inf;
  vector<int> vv;
  for (int i = 0; i < n; ++i)
    if(!(mask & (1 << i) ))
      vv.push_back(i);
  int m = vv.size();
  for (int i = 0; i < (1 << m); ++i) {
    ll nwMask = 0;
    for (int j = 0; j < m; ++j) {
      if(i & (1 << j))
        nwMask |= (1 << vv[j]);
    }
    ret = max(solve(nwMask | mask) + val[nwMask], ret);
  }
  return ret;
}

int main() {
  fastIO;
#ifdef LOCAL
  freopen("input.in", "rt", stdin);
#endif
  cin >> n;
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < n; ++j)
      cin >> arr[i][j];
  for (int mask = 0; mask < (1<<n); ++mask) {
    for (int j = 0; j < n; ++j) {
      if(mask & (1 << j)) {
        for (int k = j + 1; k < n; ++k) {
          if(mask & (1 << k))
            val[mask] += arr[j][k];
        }
      }
    }
  }

  for (int mask = 0; mask < (1 << n); ++mask) {
    vector<int> vv;
    for (int i = 0; i < n; ++i)
      if(!(mask & (1 << i) ))
        vv.push_back(i);
    int vvSZ = vv.size();
    for (int submask = 0; submask < (1 << vvSZ); ++submask) {
      ll nwMask = 0;
      for (int j = 0; j < vvSZ; ++j) {
        if(submask & (1 << j))
          nwMask |= (1 << vv[j]);
      }
      mem[mask | nwMask] = max(mem[mask | nwMask], mem[mask] + val[nwMask]);
    }
  }

  cout << mem[(1 << n) - 1];
  return 0;
}


Measured memory_bytes: 1280
#include<bits/stdc++.h>
#define ll long long

using namespace std;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(NULL);
	int n, k;
	cin >> n >> k;
	vector<int> a(n);
	for(int i = 0; i < n; ++i)
		cin >> a[i];
	//nth_element(a.begin(), a.end(),a.begin()+k);
	sort(a.begin(),a.end());
	int s = 0;
	for(int i = 0; i < k; ++i){
		s += a[i];
	}
	cout<<s;
}


Measured memory_bytes: 3660
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
	int n;
	cin >> n;
	int a[n],sum=0,s=0;
	for(int i=0;i<n;i++) {cin >> a[i]; sum+=a[i];}
	s+=sum*sum;
	for(int i=0;i<n;i++) {s -= a[i]*a[i];}
	cout << s/2;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <chrono>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <string>
#include <tuple>
#include <unordered_map>
#include <vector>
using namespace std;

#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
/*----------------------------------------*/
int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  // freopen("input.txt", "r", stdin);

  int n, d, x; cin >> n >> d >> x;
  REP(i, n) {
    int a; cin >> a;
    for (int day = 1; day <= d; day += a) ++x;
  }
  cout << x << '\n';
  return 0;
}


Measured memory_bytes: 256
package main

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

const (
	initialBufSize = 100000
	maxBufSize     = 10000000
)

var (
	sc = bufio.NewScanner(os.Stdin)
	wt = bufio.NewWriter(os.Stdout)
)

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

func nextInt() int {
	i, _ := strconv.Atoi(next())
	return i
}

func nextInts(n int) []int {
	slice := make([]int, n)
	for i := 0; i < n; i++ {
		slice[i] = nextInt()
	}
	return slice
}

func puts(a ...interface{}) {
	fmt.Fprintln(wt, a...)
}

func modPow(a, n, mod int) int {
	ret := 1
	for n > 0 {
		if n&1 == 1 {
			ret = (ret * a) % mod
		}
		a = (a * a) % mod
		n >>= 1
	}
	return ret
}

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, initialBufSize), maxBufSize)
	defer wt.Flush()

	const mod = 1000000007

	n := nextInt()
	a := nextInts(n)

	ans := 0
	for i, pow2 := 0, 1; i < 60; i++ {
		one := 0
		bit := 1 << uint(i)
		for j := 0; j < n; j++ {
			if (a[j] & bit) != 0 {
				one++
			}
		}
		add := (((one * (n - one)) % mod) * pow2) % mod
		ans = (ans + add) % mod
		pow2 = (pow2 << 1) % mod
	}

	puts(ans)
}


Measured memory_bytes: 9112
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
 
int main(){
  long long a, b, x;
  cin >> a >> b >> x;
  long long ans;
  if(a==0) ans=b/x+1;
  else ans=b/x-(a-1)/x;
  cout << ans << endl;
}

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

#define INF 1E18



int main(){
    int n;
    cin>>n;
    int v[n];
    int c[n];
    rep(i,n) cin>>v[i];
    rep(i,n) cin>>c[i];

    int ans = 0;
    rep(i,n){
        if(v[i] - c[i] > 0) ans += v[i] - c[i];
    }

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

Measured memory_bytes: 256
def solve():
    import sys
    f_i = sys.stdin
    
    n, q = map(int, f_i.readline().split())
    A = [[] for i in range(n)]
    ans = []
    
    for l in (line.split() for line in f_i):
        op = l[0]
        if op == '0':
            A[int(l[1])].append(l[2])
        elif op == '1':
            ans.append(' '.join(A[int(l[1])]))
        else:
            A[int(l[1])].clear()
    print('\n'.join(ans))

solve()


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

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



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

using namespace std;

int main(){

	int n, k;
	cin >> n >> k;
	if(n == 1){
		cout << k;
	}
	else{
		for(int i = k - (n-1); i < k + n; i++){
			cout << i << " ";
		}
	}


	return 0;
}


Measured memory_bytes: 256
// #pragma GCC target("avx,avx2,fma")
// #pragma GCC optimization ("Ofast")
// #pragma GCC optimization ("unroll-loops")
#include<bits/stdc++.h>

using namespace std;
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// template <typename T>
// using ordered_set = tree <T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
// #define sfind(i) (*find_by_order(i))
// #define ord(i) order_of_key(i)
typedef long long ll;
typedef pair<int , int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
using cd = complex<double>;
const double pi = acos(-1);
#define mod 1000000007
#define rep(i, a, b) for(ll i = a; i < b; i++)
#define repc(i, a, b, c) for (ll i = a; (c > 0 ? i < b : i > b) and c != 0; i += c)
#define vi vector<int>
#define vl vector<ll>
#define _max(vec) (*max_element(all(vec)))
#define _min(vec) (*min_element(all(vec)))
#define fi first
#define si second
#define pb push_back
#define all(name) name.begin(), name.end()
#define ral(name) name.rbegin(), name.rend()
#define fact(n) rep(i, 1, n+1)ft.pb((ft[i-1]*i)%mod)
#define mod_in(a) power(a, mod - 2)
#define ncr(n, r) (n>=r?((ft[n]*mod_in((ft[r]*ft[(n)-(r)])%mod))%mod):0LL)
#define deb(x) cerr << "[" << #x << " " << x << "]" << endl;
#define endl '\n'  //....????
#define int ll
vector<ll> ft(1, 1LL);

/*======================================================================*/

void solve(){
    int n, x = 0;
    cin >> n;
    vi v(n);
    rep(i, 0, n)cin >> v[i], x ^= v[i];
    rep(i, 0, n){
        cout << (x^v[i]) << " ";
    }
}
signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    int t = 1;
    // cin >> t;
    while(t--){
        solve();
    }
}

Measured memory_bytes: 4780
#include <cstdio>
#include <queue>
#include <algorithm>
#include <tuple>
using namespace std;

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

pii inp[100005];
int siz[100005];
ll dp[100005];
vector<pii> ans;

int main() {
	int N; scanf("%d", &N);
	for (int i = 1; i <= N; i++) {
		ll x; scanf("%lld", &x);
		inp[i] = {x, i};
		siz[i] = 1;
	}
	sort(inp + 1, inp + N + 1);
	for (int i = N; i >= 2; i--) {
		ll cur; int id;
		tie(cur, id) = inp[i];
		int del = N - 2 * siz[id];
		auto it = *lower_bound(inp + 1, inp + i, pii(cur - del, 0));
		if (it.first != cur - del || del <= 0) return !printf("-1");
		siz[it.second] += siz[id];
		dp[it.second] += dp[id] + siz[id];
		if (id > it.second) swap(id, it.second);
		ans.push_back({id, it.second});
	}
	if (dp[inp[1].second] != inp[1].first) return !printf("-1");
	sort(ans.begin(), ans.end());

	for (pii &x : ans) {
		printf("%lld %d\n", x.first, x.second);
	}
}

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

/// Defining variable types.
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef double dl;

/// Defining usable key words
#define endl '\n'
#define PB push_back
#define F first
#define S second
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define sz(x) (int)x.size()
#define mem(a,b) memset(a, b, sizeof(a) )
#define sqr(a) ((a) * (a))

/// Defining constant variables.
const double PI = acos(-1);
const double eps = 1e-9;
const int inf = 2000000000;
const ll infLL = 9000000000000000000;
#define MOD 1000000007

/// Defining some useful lines.
#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define fraction() cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed,ios::floatfield);
#define file() freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);


/// Code of debugger.
#define dbg(args...) do {cerr << #args << " : "; faltu(args); } while(0)
void faltu () {            cerr << endl;}
template < typename T, typename ... hello>void faltu( T arg, const hello &... rest) {cerr << arg << ' ';faltu(rest...);}


int main()
{
    optimize();

    string s,t,j;

    cin>>s;
    cin>>t;

    j=t+s;

    cout<<j;



    return 0;
}


Measured memory_bytes: 256
import sys

import numpy as np

n, t = map(int, input().split())
knapsack = np.zeros(t, dtype=np.int64)
cuisines = [tuple(map(int, line.split())) for line in sys.stdin]
cuisines.sort()
tmp_ans = 0
for a, b in cuisines:
    tmp_ans = max(tmp_ans, knapsack.max() + b)
    knapsack[a:] = np.maximum(knapsack[a:], knapsack[:-a] + b)

print(max(tmp_ans, knapsack.max()))


Measured memory_bytes: 12512
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.InputMismatchException;
import java.util.StringTokenizer;

public class Main {

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

	static int INF = 1 << 30;
	static long LINF = 1L << 55;
	static int MOD = 1000000007;
	static int[] mh4 = { 0, -1, 1, 0 };
	static int[] mw4 = { -1, 0, 0, 1 };
	static int[] mh8 = { -1, -1, -1, 0, 0, 1, 1, 1 };
	static int[] mw8 = { -1, 0, 1, -1, 1, -1, 0, 1 };

	static class TaskX {

		public void solve(int testNumber, InputReader in, PrintWriter out) {

			int n = in.nextInt(), k = in.nextInt();

			long s = k;
			for (int i = 1; i < n; i++) {
				s *= k-1;
			}

			out.println(s);
		}
	}

	static class InputReader {
		BufferedReader in;
		StringTokenizer tok;

		public String nextString() {
			while (!tok.hasMoreTokens()) {
				try {
					tok = new StringTokenizer(in.readLine(), " ");
				} catch (IOException e) {
					throw new InputMismatchException();
				}
			}
			return tok.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(nextString());
		}

		public long nextLong() {
			return Long.parseLong(nextString());
		}

		public double nextDouble() {
			return Double.parseDouble(nextString());
		}

		public int[] nextIntArray(int n) {
			int[] res = new int[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextInt();
			}
			return res;
		}

		public int[] nextIntArrayDec(int n) {
			int[] res = new int[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextInt() - 1;
			}
			return res;
		}

		public long[] nextLongArray(int n) {
			long[] res = new long[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextLong();
			}
			return res;
		}

		public long[] nextLongArrayDec(int n) {
			long[] res = new long[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextLong() - 1;
			}
			return res;
		}

		public InputReader(InputStream inputStream) {
			in = new BufferedReader(new InputStreamReader(inputStream));
			tok = new StringTokenizer("");
		}
	}

}


Measured memory_bytes: 22612
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long ll;
const int maxn = 100005;
const int inf = 1000000007;

int n,m;
struct P {
    int val,l,r;
    bool fail,has;
} p[maxn];
vector<int>e[maxn];

void init() {
    for(int i=1; i<=n; i++) {
        p[i].val = -1;
        p[i].fail=false;
        p[i].has = false;
    }
}

void cal(int u,int fa) {
    for(int i=0; i<e[u].size(); i++) {
        int v = e[u][i];
        if(v==fa)continue;
        cal(v,u);
        if(p[v].fail){
            p[u].fail=true;
            return;
        }
        if(p[v].has){
            if(!p[u].has){
                p[u].has=true;
                p[u].l=p[v].l-1,p[u].r=p[v].r+1;
            } else {
                if(abs(p[u].l-p[v].l+1)&1){
                    p[u].fail=true;
                    return;
                }
                if(p[u].l>p[v].r+1||p[v].l-1>p[u].r){
                    p[u].fail=true;
                    return;
                }
                p[u].l=max(p[u].l,p[v].l-1);
                p[u].r=min(p[u].r,p[v].r+1);
            }
        }
    }
}

void dfs(int u,int fa){
    if(fa==0){
        p[u].val=p[u].l;
    } else {
        if(p[u].has){
            if(p[fa].val-1>=p[u].l&&p[fa].val-1<=p[u].r){
                p[u].val=p[fa].val-1;
            } else p[u].val=p[fa].val+1;
        } else {
            p[u].val=p[fa].val+1;
        }
    }
    for(int i=0;i<e[u].size();i++){
        int v=e[u][i];
        if(v==fa)continue;
        dfs(v,u);
    }
}

int main() {
  //  freopen("in.cpp","r",stdin);
    cin>>n;
    for(int i=1; i<n; i++) {
        int x,y;
        cin>>x>>y;
        e[x].push_back(y);
        e[y].push_back(x);
    }
    cin>>m;
    for(int i=0; i<m; i++) {
        int x,y;
        cin>>x>>y;
        p[x].has = 1;
        p[x].val=p[x].l=p[x].r=y;
    }
    cal(1,0);
    if(p[1].fail)cout<<"No"<<endl;
    else{
        cout<<"Yes"<<endl;
        dfs(1,0);
        for(int i=1;i<=n;i++){
            cout<<p[i].val<<endl;
        }
    }
    return 0;
}


Measured memory_bytes: 15744
s = list(str(input()))

odd = s[0::2]
even = s[1::2]

flag=0
for i in list(set(odd)):
    if i not in ["R", "U", "D"]:
        flag=1

for i in list(set(even)):
    if i not in ["L", "U", "D"]:
        flag=1
if flag==0:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll inf=1e9+7;
const ll mod=1e9+7;
int main(){
    ll n,q;cin>>n>>q;
    rep(i,q){
        ll v,w;cin>>v>>w;
        if(n==1){
            cout<<min(v,w)<<endl;
        }else{
        ll pv=v,pw=w;
        while(pv!=pw){
            if(pv<pw){
                pw=(pw-2)/n+1;
            }else{
                pv=(pv-2)/n+1;
            }
        }
        cout<<pv<<endl;
        }
    }
}

Measured memory_bytes: 1280
#include<stdio.h>
int main(void)
{
  int i,A,B,N,K,x[100],kyori=0;

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

  for(i=0; i<N; i++){
    scanf("%d",&x[i]);
  }
  

  for(i=0; i<N; i++){
    A=2*x[i];
    if(K>x[i]){
      B=2*(K-x[i]);
    } else {
      B=2*(x[i]-K);
    }
    if(A < B){
      kyori=kyori+A;
    } else {
      kyori=kyori+B;
    }
  }
  
  printf("%d\n",kyori);
  
  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<bool> vb;
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define in insert
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int INF = 1e9 + 5;
const int  N = 2e5 + 314;
void foo(){
    string s;
    cin>>s;
    for(int i = 0; i < s.size(); i++){
        if((i+1)%2){
            if(s[i]=='L'){
                cout<<"No";
                return;
            }
        }
        else{
            if(s[i]=='R'){
                cout<<"No";
                return;
            }
        }
    }
    cout<<"Yes";
}
int main(){
    speed;
    int t=1;
    //cin>>t;
    while(t--)foo();
}

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

int main(){
    long N, W; cin >> N >> W;
    vector<vector<long>> dp(N+1, vector<long>(W+1, 0));
    for(int i=0; i<N; i++){
        int w, v; cin >> w >> v;
        for(int j=0; j<W+1; j++){
            if( j-w >=0 ) dp[i+1][j] = max(dp[i][j], dp[i][j-w]+v);
            else dp[i+1][j] = max(dp[i][j], dp[i][0]);
        }
    }
    cout << dp[N][W] << endl;
}


Measured memory_bytes: 80256
// ABC 087

// inputに入力データ全体が入る
function Main(input) {
  input = input.split("\n");
  const five_hundreds = parseInt(input[0],10); //500円硬貨の数
  const hundreds = parseInt(input[1],10); //100円硬貨の数
  const fifty = parseInt(input[2],10); //50円硬貨の数
  const total = parseInt(input[3],10); //合計金額

  var count = 0; //何通りかをカウントする
  for (var a=0;a<=five_hundreds;a++) {
    for (var b=0;b<=hundreds;b++) {
      for(var c=0;c<=fifty;c++) {
        var sum = (a*500) + (b*100) + (c*50);
        if(total == sum) count++;
      }
    }
  }

  console.log(count)
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));


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

int main()
{
    int h, w;
    cin >> h >> w;

    int cnt = 0;
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            char c; cin >> c;
            cnt += c == '#';
        }
    }

    cout << (cnt == h + w - 1 ? "Possible" : "Impossible") << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h> 
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
ll INFL = 1000000000000000010;//10^18 = 2^60
int INF = 2100000000;//10^9
ll MOD  = 1000000007;
int N;
ll A,B;
vector<ll> h(100010);
bool Judge(int K){
    ll ans = 0;
    for(int i = 0; i < N; i++){
        if(h.at(i) - K * B > 0){
            ans += ( (h.at(i) - K * B) + (A-B-1) ) / (A-B);
        }
    }
    return ans <= K;
}

int main(void){
    cin >> N >> A >> B;
    for(int i = 0; i < N; i++) cin >> h.at(i);
    
    int left = 0,right = INF,mid;
    while(abs(right - left) > 1){
        mid = (left + right) / 2;
        if(Judge(mid)) right = mid;
        else left = mid;
    }
    
    cout << right << endl;
}


Measured memory_bytes: 1024
// ACM-ICPCà\I2007 D. Roè

#include <iostream>
#include <queue>
#include <cstring>

using namespace std;

const int INF = 999999;

class Node{
public:
	int x, y, foot, cost;
	Node(int x, int y, int foot, int cost) : x(x), y(y), foot(foot), cost(cost) {}
	bool operator < (const Node &n) const { return cost > n.cost; }
};

int main(){
	int w, h;
	char b[60][30];
	bool visit[2][60][30];
	int dist[2][60][30];
	while(cin >> w >> h, w){
		int ans = INF;
		priority_queue<Node> qu;
		memset(visit, false, sizeof(visit));
		for(int i=0;i<h;i++){
			for(int j=0;j<w;j++){
				cin >> b[i][j];
				if(b[i][j] == 'S'){
					qu.push(Node(j,i,0,0));
					qu.push(Node(j,i,1,0));
					dist[0][i][j] = dist[1][i][j] = 0;
				} else {
					dist[0][i][j] = dist[1][i][j] = INF;
				}
			}
		}
		while(!qu.empty()){
			Node e = qu.top(); qu.pop();
			if(visit[e.foot][e.y][e.x]) continue;
			if(b[e.y][e.x]=='T'){
				ans = e.cost;
				break;
			}
			visit[e.foot][e.y][e.x] = true;
			for(int dx=1;dx<=3;dx++){
				for(int dy=dx-3;dy<=3-dx;dy++){
					int x = e.x + (e.foot ? -dx : dx);
					int y = e.y + dy;
					if(x<0||w<=x||y<0||h<=y||visit[1-e.foot][y][x]) continue;
					if(b[y][x]=='X'||b[y][x]=='S') continue;
					if(dist[1-e.foot][y][x] > e.cost + (b[y][x]!='T'?b[y][x]-'0':0)){
						dist[1-e.foot][y][x] = e.cost + (b[y][x]!='T'?b[y][x]-'0':0);
						qu.push(Node(x, y, 1-e.foot, dist[1-e.foot][y][x]));
					}   
				}   
			}
		}
		cout << (ans == INF ? -1 : ans) << endl;  
	}
}

Measured memory_bytes: 944
a,b,c,x,y = [int(i) for i in input().split()]

maxxy = max([x,y])
price = 0

prices=[]

for i in range(maxxy+1):
  amai = x-i
  bmai = y-i
  
  if amai<0:
    amai = 0
  if bmai<0:
    bmai = 0
  
  price = i*2*c + amai*a + bmai*b
  prices.append(price)
  
print(min(prices))
  
  
  

Measured memory_bytes: 7064
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const int mod=1000000007;

int main() {
  int N;
  cin>>N;
  vector<int64_t>L(N);
  for(int i=0;i<N;i++){
    cin>>L[i];
  }
  sort(L.begin(),L.end());
  int cnt=0;
  for(int i=0;i<N;i++){
    for(int j=i+1;j<N;j++){
      for(int k=j+1;k<N;k++){
        if(L[i]==L[j]||L[j]==L[k]||L[k]==L[i]){continue;}
        if(L[i]+L[j]>L[k]){cnt++;}//cout<<i+1<<" "<<j+1<<" "<<k+1<<endl;}
      }
    }
  }
  cout<<cnt<<endl;
  return 0;
}


Measured memory_bytes: 3632
#!/usr/bin/env python3

import sys, math, copy
# import fractions, itertools
# import numpy as np
# import scipy

HUGE = 2147483647
HUGEL = 9223372036854775807
ABC = "abcdefghijklmnopqrstuvwxyz"

def main():
    n = int(input())
    ai = list(map(int, input().split()))
    assert len(ai) == n
    ones = 0
    twos = 0
    fours = 0
    for a in ai:
        if a % 4 == 0:
            fours += 1
        elif a % 2 == 0:
            twos += 1
        else:
            ones += 1
    if twos > 0:
        twos = 1
    if fours == 0 and (ones > 0):
        return False
    if fours + 1 < ones + twos:
        return False
    return True

print("Yes" if main() else "No")


Measured memory_bytes: 14612