akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
int acs(const void *a, const void *b) { 
  return *(int*)a - *(int*)b;
} /* 1,2,3,4.. */
int des(const void *a, const void *b) {
  return *(int*)b - *(int*)a;
} /* 8,7,6,5.. */
int cmp_char(const void *a, const void *b) { 
  return *(char*)a - *(char*)b;
} /* a,b,c,d.. */
int cmp_str(const void *a, const void *b) {
  return strcmp(*(const char **)a, *(const char **)b);
} /* aaa,aab.. */
#define min(a,b) (a < b ? a : b)
#define max(a,b) (a > b ? a : b)
#define rep(i, l, r) for (int i = l; i < r; i++)
#define MAX 100001
#define MOD 1000000007
#define INF 1000000009
typedef long long int lli;

int main(void) {
  int n, m;
  scanf("%d %d", &n, &m);

  int s[6], c[6];
  rep(i, 0, m) scanf("%d %d", &s[i], &c[i]);

  int num[4];
  rep(i, 0, 4) num[i] = -1;

  int ans = -1;
  rep(i, 0, m) {
    if (num[s[i]-1] == -1) {
      num[s[i]-1] = c[i];
      continue;
    }
    if (num[s[i]-1] != c[i]) {
      printf("-1");
      return 0;
    }
  }
  if (n != 1 && num[0] == 0) {
    printf("-1");
    return 0;
  }
  if (n == 1 && num[0] == -1) printf("0");
  else if (n != 1 && num[0] == -1) printf("1");
  else printf("%d", num[0]);
  rep(i, 1, n) {
    if (num[i] == -1) num[i] = 0; 
    printf("%d", num[i]);
  }

  return 0;
}



Measured memory_bytes: 128
# -*- coding: utf-8 -*-S
x,y = [int(i) for i in input().split()]


if x == 2 or y == 2:
    print("No")
elif (x == 4 or x == 6 or x == 9) and (y == 6 or y == 9 or y == 11):
    print("Yes")
elif (x == 1 or x == 3 or x == 5 or x == 7 or x == 8 or x == 10) and (y == 3 or y == 5 or y == 7 or y == 8 or y == 10 or y == 12):
    print("Yes")
else:
    print("No")

"""
A = [1,3,5,7,8,10,12]
B = [4,6,9,11]
tmp = False

for i in range(7):
    if A[i] == x:
        for j in range(i,7):
            if A[j] == y:
                tmp = True
for i in range(4):
    if B[i] == x:
        for j in range(i,4):
            if B[j] == y:
                tmp = True
if tmp:
    print("Yes")
if not tmp:
    print("No")
"""



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

using namespace std;

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  int max1 = 0, ind = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (max1 < a[i]) {
      max1 = a[i];
      ind = i;
    }
  }
  a.erase(a.begin() + ind);
  int max2 = 0;
  for (int i = 0; i < n - 1; i++) {
     if (max2 < a[i]) max2 = a[i];
  }
  for (int i = 0; i < n; i++) {
    if (i != ind) cout << max1 << "\n";
    else cout << max2 << "\n";
  }
}  

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

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

	priority_queue<int>qu;
	string p = "";
	int x;

	while (p != "end")
	{
		cin >> p;
		if (p == "insert")
		{
			cin >> x;
			qu.push(x);
		}
		if (p == "extract")
		{
			cout << qu.top() << endl;
			qu.pop();
		}
	}

	return 0;
}


Measured memory_bytes: 6996
package main

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

func main() {
	solve(os.Stdin, os.Stdout)
}

func solve(in io.Reader, out io.Writer) {
	bs := NewBufScanner(in)
	bw := NewBufWriter(out)
	defer bw.w.Flush()
	n := bs.IntScan()

	if n == 2 {
		bw.Printf("1")
		return
	}
	if n == 3 {
		bw.Printf("2")
		return
	}

	count := 2
	var k int64
	for k = 2; k <= int64(math.Sqrt(float64(n))); k++ {
		x := n
		for x >= k && x % k == 0 {
			x /= k
		}
		if x % k == 1 {
			count++
		}

		if (n-1) % k != 0 {
			continue
		}
		t := (n - 1) / k
		if t <= k {
			continue
		}
		y := n
		for y >= t && y % t == 0 {
			y /= t
		}
		if y % t == 1 {
			count++
		}
	}

	bw.Printf("%v", count)
}

// BufScanner original scanner
type BufScanner struct {
	s *bufio.Scanner
}

// NewBufScanner constructer
func NewBufScanner(in io.Reader) *BufScanner {
	s := bufio.NewScanner(in)
	s.Buffer(make([]byte, 1024), 1e+9)
	s.Split(bufio.ScanWords)
	return &BufScanner{
		s: s,
	}
}

// Scan Scan Data
func (b *BufScanner) Scan() string {
	b.s.Scan()
	return b.s.Text()
}

// IntScan Scan Data
func (b *BufScanner) IntScan() int64 {
	v, err := strconv.ParseInt(b.Scan(), 10, 64)
	if err != nil {
		panic(err)
	}
	return v
}

// BufWriter original writer
type BufWriter struct {
	w *bufio.Writer
}

// NewBufWriter constructer
func NewBufWriter(out io.Writer) *BufWriter {
	w := bufio.NewWriter(out)
	return &BufWriter{
		w: w,
	}
}

// Printf Output file
func (b *BufWriter) Printf(format string, a ...interface{}) {
	fmt.Fprintf(b.w, format, a...)
}

Measured memory_bytes: 640
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <cstdio>
#include <limits>
#include <vector>
#include <cstdlib>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional> 
#include <iomanip>
#include <unordered_map>
#include <memory.h>
#include <cstring>
#include <fstream>

using namespace std;

long long int dp[100001][3];
const long long int MOD = 1e9 + 7;

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

	string s;

	cin >> s;
	
	int n = s.length();
	long long int x = 1;

	if (s[0] == '?' || s[0]=='A')
	{
		dp[0][0] = 1;
		if (s[0] == '?')
		{
			x = (x * 3) % MOD;
		}
	}

	for (int i = 1; i < n; i++)
	{
		if (s[i] == '?')
		{
			for (int j = 0; j < 3; j++)
			{
				dp[i][j] = ((dp[i][j] % MOD) + ((3*dp[i - 1][j]) % MOD) % MOD);
				dp[i][j] %= MOD;
			}
			dp[i][0] = ((dp[i][0] % MOD) + (x % MOD)) % MOD;
			dp[i][0] %= MOD;
			dp[i][1] = ((dp[i][1] % MOD + (dp[i - 1][0]) % MOD) % MOD);
			dp[i][1] %= MOD;
			dp[i][2] = ((dp[i][2] % MOD) + (dp[i - 1][1] % MOD)) % MOD;
			dp[i][2] %= MOD;
			x = (x * 3) % MOD;
			x %= MOD;
		}
		else
		{
			for (int j = 0; j < 3; j++)
			{
				dp[i][j] = ((dp[i][j] % MOD) + (dp[i - 1][j] % MOD) % MOD);
				dp[i][j] %= MOD;
			}
			if (s[i] == 'A')
			{
				dp[i][0] = ((dp[i][0] % MOD) + (x % MOD)) % MOD;
				dp[i][0] %= MOD;
			}
			else if (s[i] == 'B')
			{
				dp[i][1] = ((dp[i][1] % MOD) + (dp[i-1][0] % MOD)) % MOD;
				dp[i][1] %= MOD;
			}
			else
			{
				dp[i][2] = ((dp[i][2] % MOD) + (dp[i-1][1] % MOD)) % MOD;
				dp[i][2] %= MOD;
			}
		}
	}

	cout << dp[n - 1][2] << '\n';

	return 0;
}


Measured memory_bytes: 2896
#include<stdio.h>

int main(){
  char b;
  scanf("%c",&b);
  if(b =='A'){
    printf("T\n");
  }
  else if(b == 'C'){
    printf("G\n");
  }
  else if(b == 'G'){
    printf("C\n");
  }
  else if(b == 'T'){
    printf("A");
  }
  else{
    printf("error");
  }
  return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner std = new Scanner(System.in);
		int defaultpip[] = new int[6];
		for(int i=0; i<6; i++){
			defaultpip[i] = Integer.parseInt(std.next());
		}

		Dice dc1 = new Dice(defaultpip);

		String queue = std.next();
		for(int j=0; j<queue.length(); j++){
			dc1 = dc1.newnowpips(dc1, queue.substring(j, j+1));
//			System.out.println(dc1.showdice());
		}
		System.out.println(dc1.pips[dc1.nowpip]);
	}
}

class Dice {
	int pips[];
	int nowpip;
	int spip;
	int epip;
	int wpip;
	int npip;
	int rpip;

	public Dice(int pip[]){
		this(pip, 0, 1, 2, 3, 4, 5);
	}

	public Dice(int pip[], int now, int s, int e, int w, int n, int r){
		pips = pip;
		nowpip = now;
		spip = s;
		epip = e;
		wpip = w;
		npip = n;
		rpip = r;
	}

	public Dice newnowpips(Dice d, String query){
		if(query.equals("N")){
			return new Dice(d.pips,d.spip,d.rpip,d.epip,d.wpip,d.nowpip,d.npip);
		}else if(query.equals("E")){
			return new Dice(d.pips,d.wpip,d.spip,d.nowpip,d.rpip,d.npip,d.epip);
		}else if(query.equals("S")){
			return new Dice(d.pips,d.npip,d.nowpip,d.epip,d.wpip,d.rpip,d.spip);
		}else{				// W
			return new Dice(d.pips,d.epip,d.spip,d.rpip,d.nowpip,d.npip,d.wpip);
		}
	}

	public String showdice(){
		return pips[nowpip] + " " + pips[spip] + " " + pips[epip] + " " + pips[wpip] + " " + pips[npip] + " " + pips[rpip];
	}
}

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

      int main(){
       int N =0;
       cin >> N;
       if(N==1){
          cout << "Hello World" <<endl;
       }
       else if(N==2){
          int A,B;
          cin >> A >> B ;
          if(A<1 && A>9 || B <1 && B >9)return 1;
            cout <<A+B;
        }
        else return 1;

        return 0;
      }


Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define MOD 1000000007
using namespace std;

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

int main() {
    int N;
    cin >> N;
    vector<int> W;
    int sum = 0;
    for (int i = 0; i < N; i++) {
        int temp;
        cin >> temp;
        W.push_back(temp);
        sum += temp;
    }
    int minimum = sum;
    int partsum = 0;
    for (int i = 0; i < N; i++) {
        partsum += W[i];
        minimum = min(minimum, abs(2 * partsum - sum));
    }
    cout << minimum << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/trie_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef trie<string, null_type, trie_string_access_traits<>, pat_trie_tag, trie_prefix_search_node_update> pref_trie;
typedef unsigned long long BITMASK; typedef long long ll; typedef long double ld;
#define has_bit(bit_mask, x) ((bit_mask) & (1Uint << (x)))
#define turn_on_bit(bit_mask, x) (bit_mask |= (1Uint << (x)))
#define turn_off_bit(bit_mask, x) (bit_mask &= (~(1Uint << (x))))
#define smallest_on_bit(bit_mask) (__builtin_ctzint((bit_mask) & (-(bit_mask))))
#define CLOCK_START clock_t chrono_clk_beg = clock()
#define CLOCK_END clock_t chrono_clk_end = clock(); cerr << (double(chrono_clk_end - chrono_clk_beg) / CLOCKS_PER_SEC) << " sec"
#define bug(args ...) cerr << __LINE__ << ">> ", err(new istringstream(string(#args)), args), cerr << '\n'
#define all(x) x.begin(), x.end()
#define mapfind(mp, x) (mp.find(x) != mp.end())
#define removeDuplicates(vec) sort(vec.begin(), vec.end()); vec.erase(unique(vec.begin(), vec.end()), vec.end())
#define int ll
#define double ld
void err(istringstream *iss) {} template<typename T, typename ... Args> void err(istringstream *iss, const T &_val, const Args & ... args) { string _name; *iss >> _name; if (_name.back()==',') _name.pop_back(); cerr << _name << " = " << _val << "; ", err(iss, args ...); }
#define MOD 1000000007

signed main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    int a, b;
    cin >> a >> b;
    cout << (a*b)/(__gcd(a, b)) << '\n';
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#define  boost ios_base::sync_with_stdio(false);cin.tie(NULL);
#define ull unsigned long long
#define deb(x) cout<<#x<<" "<<x<<endl;
#define deb2(x,y) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<endl;
#define deb2l(x,y,i) cout<<#x<<i<<" "<<x<<" "<<#y<<i<<" "<<y<<endl;

#define fr(i,l,r) for(ll i=l;i<r;i++)
#define mems(a,x) memset(a,x,sizeof(a))
#define mod 1000000007
#define ff first
#define ss second
#define pb(x) push_back(x)
#define vll vector<ll>
#define pbp(x,y) push_back(make_pair(x,y))
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
ll dp[10001][1001];
ll find(ll h,ll idx,vector<pair<ll,ll>> &v){
    if(idx>=v.size())
    return mod;
    if(h<=0)
    return 0;
    if(dp[h][idx]!=-1)
    return dp[h][idx];
    dp[h][idx]=min(find(h-v[idx].ff,idx,v)+v[idx].ss,find(h,idx+1,v));
    return dp[h][idx];
}
void solve(){
    memset(dp,-1,sizeof(dp));
    ll h,n;
    cin>>h>>n;
    vector<pair<ll,ll>>v(n);
    fr(i,0,n)
    cin>>v[i].ff>>v[i].ss;
    cout<<find(h,0,v);
}

int main(){
    ll t=1;
//cin>>t;
    while(t--){
     solve();
     cout<<endl;
    }
    return 0;
}


Measured memory_bytes: 79104
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)
#define VS vector<string>

int main(){
    ll N, M;
    cin>>N;
    VS s(N); rep(i,0,N)cin>>s[i];
    cin>>M;
    VS t(M); rep(i,0,M)cin>>t[i];

    ll ans=0;
    rep(i,0,N){
        ll cnt=0;
        rep(j,0,N+M){
            if(j<=N-1){
                if(s[i]==s[j])cnt++;
            }
            else if(j>=N){
                if(t[j-N]==s[i])cnt--;
            }
        }
        ans=max(ans,cnt);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define db double
#define pii pair<int,int>
#define pli pair<ll,int>
#define pil pair<int,ll>
#define pll pair<ll,ll>
#define mat vector<vector<int>>
const int inf = 1 << 30;
const ll linf = 1e18;
const db EPS = 1e-7;
template<class T> void chmin(T& x, T y){if(x > y) x = y;}
template<class T> void chmax(T& x, T y){if(x < y) x = y;}

template<class T>
struct seg_tree{
    T N;
    vector<T> node;
    T init = 0;

    seg_tree(int n){
        N = 1;
        while(N < n) N *= 2;
        node.resize(N * 2 - 1, 0);
    }

    void update(int i, T x){
        i += N - 1;
        node[i] = x;
        while(i > 0){
            i = (i - 1) / 2;
            node[i] = max(node[i * 2 + 1], node[i * 2 + 2]);
        }
    }

    T get_max(int a, int b, int k = 0, int l = 0, int r = -1){
        if(r == -1) r = N;
        if(b <= l || r <= a) return init;
        if(a <= l && r <= b) return node[k];

        T vl = get_max(a, b, k * 2 + 1, l, (l + r) / 2);
        T vr = get_max(a, b, k * 2 + 2, (l + r) / 2, r);
        return max(vl, vr);
    }
};

int N;
int ans[200010];
vector<int> as;
seg_tree<int> seg(200010);
vector<int> G[200010];

void comp(vector<int>& a){
    auto tmp = a;
    sort(tmp.begin(), tmp.end());
    tmp.erase(unique(tmp.begin(), tmp.end()), tmp.end());
    for(int i = 0; i < (int)a.size(); i++){
        a[i] = lower_bound(tmp.begin(), tmp.end(), a[i]) - tmp.begin();
    }
}

void dfs(int v, int p){
    int res = seg.get_max(0, as[v - 1]) + 1;
    ans[v] = max(seg.get_max(0, N), res);
    int pre = seg.get_max(as[v - 1], as[v - 1] + 1);
    seg.update(as[v - 1], res);
    for(auto u : G[v]){
        if(u == p) continue;
        dfs(u, v);
    }
    seg.update(as[v - 1], pre);
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> N;
    for(int i = 0; i < N; i++){
        int a;
        cin >> a;
        as.push_back(a);
    }
    for(int i = 1; i < N; i++){
        int u, v;
        cin >> u >> v;
        G[u].push_back(v);
        G[v].push_back(u);
    }
    comp(as);
    dfs(1 , 0);
    for(int i = 1; i <= N; i++) cout << ans[i] << endl;
    return 0;
}

Measured memory_bytes: 46556
#import sys
MOD = 10 ** 9 + 7
#input = sys.stdin.readline
import math

#import bisect

def sosuhante(n):
    for k in range(2, int(math.sqrt(n))+1):
        if n% k ==0:
            return False
    return True
def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

def main():
#    h,w,a,b = map(int, input().split())
    n=int(input())
    a=list(map(int,input().split()))
    s=0
    suma=sum(a)
    temp=0
    for i in range(len(a)):
        temp+=a[i]
        if temp>= suma//2:
            p=i
            break
        p=i
    x=temp
    y=suma- temp
#    print(x,y)
    if abs(x-y)>abs(temp-a[p]-abs(suma-temp+a[p])):
        x=temp-a[p]
        y=suma-temp+a[p]
#    print(temp-a[p],suma-temp+a[p])
#    print(x, y)
    s=min(abs(suma//2-x),abs(suma//2-y))
    s*=2
    if suma%2!=0:
        s+=1
    print(s)

if __name__ == "__main__":
    main()

Measured memory_bytes: 26080
#include<iostream>

using namespace std;

long long int dp[112345];

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


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

class Solver {
    Scanner sc = new Scanner();

    public void Solve() {
        var H = sc.nextInt();
        var W = sc.nextInt();
        var S = new string[H];
        for (int i = 0; i < H; i++) {
            S[i] = sc.next();
        }

        var L = new int[H, W];
        var R = new int[H, W];
        for (int i = 0; i < H; i++) {
            for (int j = 0; j < W; j++) {
                if (S[i][j] == '.') {
                    L[i, j] = 1;
                    if (j > 0) L[i, j] += L[i, j - 1];
                }
            }

            for (int j = W-1; j >= 0; j--) {
                if(S[i][j] == '.') {
                    R[i, j] = 1;
                    if (j < W - 1) R[i, j] += R[i, j + 1];
                }
            }
        }

        var U = new int[H, W];
        var D = new int[H, W];
        for (int j = 0; j < W; j++) {
            for (int i = 0; i < H; i++) {
                if (S[i][j] == '.') {
                    U[i, j] = 1;
                    if (i > 0) U[i, j] += U[i - 1, j];
                }
            }

            for (int i = H-1; i >= 0; i--) {
                if (S[i][j] == '.') {
                    D[i, j] = 1;
                    if (i < H-1) D[i, j] += D[i + 1, j];
                }
            }
        }
        var ans = 0;
        for (int i = 0; i < H; i++) {
            for (int j = 0; j < W; j++) {
                ans = Math.Max(L[i, j] + R[i, j] + U[i, j] + D[i, j] - 3, ans);
            }
        }
        WriteLine(ans);
    }
}

class Scanner {
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner() {
        s = new string[0];
        i = 0;
    }

    public string next() {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt() {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0) {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++) {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong() {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0) {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++) {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble() {
        return double.Parse(next());
    }

    public double[] ArrayDouble(int N, double add = 0) {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++) {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}

class Program {
    static void Main(string[] args) {
        Solver s = new Solver();
        s.Solve();
    }
}


Measured memory_bytes: 91152
#include <algorithm>
#include <bitset>
#include <iomanip>
#include <ios>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
using namespace std;

int main()
{
    int count = 1;
    int a, b, c;
    cin >> a >> b >> c;
    if (b != a) {
        count++;
    }
    if (c != b && c != a) {
        count++;
    }
    cout << count << "\n";
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <functional>
#include<vector>
#include<math.h>
#include<bitset>
#include<string>
#include <deque>
#include<queue>
#include<map>
using namespace std;



int main() {
	int A[105];
	int N;
	cin >> N;
	int X = 0;
	int Y = 10000000;
	for (int i = 0; i < N; i++) {
		cin >> A[i];
		X = max(X, A[i]);
		Y = min(Y, A[i]);
	}
	int Q=100000000000;
	for (int i = Y; i <= X; i++) {
		int R=0;
		for (int k = 0; k < N; k++) {
			R += pow(A[k] - i, 2);
		}
		Q = min(Q, R);
	}

	
	cout << Q << endl;

	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	public static boolean isPrime(int x) {
		if(x<=1)return false;
		for(int i = 2; i*i <= x; i++) {
			if(x % i == 0) {
				return false;
			}
		}
		return true;
	}
	
	
	
	
	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		int x = stdIn.nextInt();
		while(!isPrime(x)) {
			x++;
		}
		System.out.println(x);
	}

}


Measured memory_bytes: 22740
import sys
sys.setrecursionlimit(100000)

def ins(): return input().split()
def ii(): return int(input())
def iil(): return list(map(int,ins()))
def lin(): return list(input())
def iin(): return map(int,ins())

n = ii()
b = iil()
ans = b[0]+b[-1]
for i in range(n-2):
    ans += min(b[i],b[i+1])
print(ans)

Measured memory_bytes: 3064
#![allow(non_snake_case)]

use std::io;
use std::cmp::min;

fn main() {
    let mut line = String::new();
    io::stdin().read_line(&mut line).unwrap();
    line.clear();
    io::stdin().read_line(&mut line).unwrap();
    let S: Vec<char> = line.chars().collect();

    let mut cnt = 0;
    for i in 1..S.len() {
        if S[i] == 'E' {
            cnt += 1;
        }
    }
    let mut ret = cnt;
    for i in 1..S.len() - 1 {
        if S[i - 1] == 'W' {
            cnt += 1;
        }
        if S[i] == 'E' {
            cnt -= 1;
        }
        ret = min(ret, cnt);
    }

    println!("{}", ret);
}

Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
#define lp(i,n) for(int i=0;i<n;i++)
#define DEKAI 1000000007
/* ┗(^o^)┛ｗｗｗｗｗ┏(^o^)┓ﾄﾞｺﾄﾞｺﾄﾞｺﾄﾞｺｗｗｗｗｗ */

int main(){
	int a,b;
	cin>>a>>b;
	if(a*b%2==0) cout<<"No"<<endl;
	else cout<<"Yes"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
long long inf=(long long)1E17;
#define i_7 (long long)(1E9+7)
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
using namespace std;

bool prime_(long long n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(long long i=2;i<=sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}

//typedef long long ll;
long long po(long a, long b){
    if(b==0){
        return 1;
    }
    
    long long z = po(a,b/2);
    z = mod(z*z);
    if(b%2!=0){
        z = mod(a*z);
    }
    return z;
}

//配列のSIZEは問題ごとに定義する必要がある。
const int SIZE= 100100;
long long inv[SIZE+1];//各iの逆元を格納する配列。
long long kai[SIZE+1];//i!のmodを格納する配列。
long long invkai[SIZE+1];//各i!の逆元を格納する配列。
const int MOD=i_7;
void invinit(){//上の配列を初期化する関数。
    inv[1]=1;
    for(int i=2;i<=SIZE;i++){
        inv[i] = MOD - ((MOD/i)*inv[MOD%i])%MOD;
    }
    
    kai[0]=invkai[0]=1;
    for(int i=1;i<=SIZE;i++){
        kai[i]=(kai[i-1]*i)%MOD;
        invkai[i]=(invkai[i-1]*inv[i])%MOD;
    }
}

long long comb(long long a, long long b){
    if(b<0 || a<b){
        return 0;
    }
    return mod(kai[a]*mod(invkai[b]*invkai[a-b]));
}

int main(){
    invinit();
    long long n;
    long long m;
    cin>>n>>m;
    
    vector<long long> primes;
    for(long long i=1;i<=100000;i++){//100'000以下の素数を全て事前に知っておく。
      if(prime_(i)){
        primes.push_back(i);
      }
    }
    
    int s = primes.size();
    int powers[s]={};
    int temp;
    REP(i,s){
      if(m==1)break;
      if(m%primes[i]!=0)continue;
      temp = 0;
      while(m%primes[i]==0){
        m /= primes[i];
        temp++;
      }
      powers[i] = temp;
    }
    int cnt = 0;
    if(m!=1){//100'000より大きい素数を因数に含む時
      cnt++;
    }
    
    long long ans=1;
    REP(i,s){
      if(powers[i]==0)continue;
      ans = ans*comb(n+(long long)powers[i]-1,(long long)powers[i]);
      ans = mod(ans);
    }
    if(cnt==1){
      ans *= n;
      ans = mod(ans);
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 2816
#include<iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int main(){
  	int N;
  	string S;
  	cin >> N >> S;
  	
  	if(N%2==1){
  		cout << "No" <<endl;
  		return 0;
  	}
  	for(int i=0;i<N/2;i++){
  		if(S[i]!=S[i+N/2]){
  			cout << "No" <<endl;
  			return 0;
  		}
  	}
  	
  	cout << "Yes" <<endl;

  	return 0;
}



Measured memory_bytes: 256
fun main(args: Array<String>){
    val n = readLine()!!.split(" ").map(String::toInt)
    val a = n[0]
    val b = n[1]
    val c = n[2]
    if(a + b + c < 22){
        println("win")
    }else{
        println("bust")
    }
}

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

int main()
{
    string S;
    long long K;
    cin >> S >> K;

    long long cnt1 = 0;
    for (int i = 1; i < S.size(); i++)
    {
        if (S[i] == S[i - 1])
        {
            cnt1++;
            i++;
        }
    }

    long long cnt2 = 0;
    string S2 = S + S;
    for (int i = 1; i < S2.size(); i++)
    {
        if (S2[i] == S2[i - 1])
        {
            cnt2++;
            i++;
        }
    }

    long long cnt3 = 0;
    string S3 = S + S + S;
    for (int i = 1; i < S3.size(); i++)
    {
        if (S3[i] == S3[i - 1])
        {
            cnt3++;
            i++;
        }
    }

    long long ans = cnt1;
    K--;
    ans += ((cnt3 - cnt2) + (cnt2 - cnt1)) * (K / 2);
    if (K % 2 == 1)
    {
        ans += cnt2 - cnt1;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); ++i)
int main(void) {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  int x;
  int max1 = 0;
  rep(i, n) {
    if(max1 < a[i]) {
      max1 = a[i];
      x = i;
    }
  }
  int max2 = 0;
  rep(i, n) {
    if(i == x) continue;
    max2 = max(max2, a[i]);
  }
  rep(i, n) {
    if(i == x)
      printf("%d\n", max2);
    else
      printf("%d\n", max1);
  }
  return 0;
}

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

A = [list(map(int, input().split())) for i in range(N)]  # N*M配列の取得
B = [list(map(int, input().split())) for i in range(M)]  # M*L配列の取得
ANS = [[0] * L for i in range(N)]  # N*L

for i in range(N):
    for j in range(L):
        for k in range(M):
            ANS[i][j] += A[i][k] * B[k][j]

for i in range(N):
    print("%d" % ANS[i][0], end="")
    for j in range(1, L):
        print(" %d" % (ANS[i][j]), end="")
    print()



Measured memory_bytes: 7052
#include<iostream>
#include<cassert>
#include <string>
#include <cctype>

using namespace std;

#if 0
所用時間:

感想:

#endif

string S;
size_t cur;

int expression();
int factor();

char readchar(){
    assert(cur < S.size());
    char ret =  S[cur];
    cur += 1;
    return ret;
} 

char peek(){
    // assert(cur < S.size());
    return S[cur];
}

int digit(){
    // assert(isdigit(peek()));
    int n = readchar() - '0';
    return n;
}

int number(){
    int n = digit();
    while( cur < S.size() && isdigit(peek()))
        n = n * 10 + digit();
    return n;
}

int term(){
    int a = factor();
    while(cur < S.size() && (peek()=='*' || peek()=='/')){
        char op = readchar();
        int b = factor();
        if(op=='*') a*= b;
        else a /= b;
        // cout << "calc: " << a << " " << op << " " << b << endl;
    }
    return a;
}

int factor(){
    if (peek() == '('){
        cur += 1;
        int n = expression();
        assert(peek() == ')');
        cur += 1;
        return n;
        }
    else return number();
}

int expression(){
    int a = term();
    while(cur < S.size() && (peek()=='+' || peek()=='-')){
        char op = readchar();
        int b = term();
        // cout << "calc: " << a << " " << op << " " << b << endl;
        if(op == '+'){
            a += b;
        }else{
            a -= b;
            }
    }
    return a;
}


int parse(){
    return expression();
}

int main(){
    int N;
    cin >> N;
    for(int i = 0; i < N; ++i){
        cin >> S;
        cur = 0;
        S.resize(S.size()-1); // 最後の=を無視
        int a = parse();
        cout << a << endl;
    }
}



Measured memory_bytes: 3060
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
//#include<bits/stdc++.h>
#include<cstdio>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

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

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


	int N = getint(), M = getint();

	ll B[100001] = {};
	int mae = getint();
	int a1 = mae;
	int nanshuu = 0;
	ll kihon = 0;
	rep1(i, N - 1) {
		int a = getint();
		int sa = a - mae;
		if (sa < 0) {
			sa += M;
			nanshuu++;
			kihon -= M - mae;
		}
		B[a] += sa;
		mae = a;
	}
	int aN = mae;
	kihon += (ll)nanshuu * M + aN - a1;

	ll saishou = kihon;
	rep1(x, M - 1) {
		kihon += B[x] - nanshuu - (x > a1) + (x > aN);
		if (saishou > kihon) saishou = kihon;
	}

	printf("%lld\n", saishou);

	Would you please return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>

void swap(int* pInput1, int* pInput2)
{
	int temp = *pInput1;
	*pInput1 = *pInput2;
	*pInput2 = temp;
} 

int main()
{
    int x,y;
    while(1)
    {
        scanf("%d", &x);
        scanf("%d", &y);
        
        if((x==0)&&(y==0))
        {
            break;
        }
        else if(x>y)
        {
            swap(&x,&y);
        }
        printf("%d %d\n",x,y);
    }
    return 0;
}


Measured memory_bytes: 2052
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#define MOD 1000000007
typedef long long ll;
using namespace std;

int main(){
  int n;
  cin>>n;
  vector<int> b(n+1);
  for(int i=0;i<n;i++){
    cin>>b[i];
    if(b[i]>i+1){
      cout<<-1<<endl;
      return 0;
    }
  }

  vector<int> ans;
  bool used[n+1]={};

  for(int i=1;i<=n;i++){
      int it=0;
      for(int j=0;j<b.size();j++){
          if(b[j]==j+1){
              it=j;
          }
      }
      ans.push_back(b[it]);
      b.erase(b.begin()+it);
  }
  
  reverse(ans.begin(),ans.end());
  for(int i=0;i<n;i++){
    cout<<ans[i]<<endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include<string>
#include<iostream>
#include<set>
#include<cmath>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<functional>
//#define scanf scanf_s
#define fir first
#define sec second
#define mp make_pair
#define mt make_tuple
#define pub push_back
using namespace std;
typedef long long int llint;
const llint one = 1;
const llint big = (one<<30);

int main(void){
	int n,i,j;
	string S;
	int alf[26];
	int alfa[26]={0};
	char c;
	scanf("%d",&n);
	for(i=0;i<26;i++){
		alf[i]=9999;
	}
	for(i=0;i<n;i++){
		cin>>S;
		for(j=0;j<S.size();j++){
			alfa[S[j]-'a']++;
		}
		for(j=0;j<26;j++){
			alf[j]=min(alf[j],alfa[j]);
			alfa[j]=0;
		}
	}
	for(i=0;i<26;i++){
		c=i+'a';
		for(j=0;j<alf[i];j++){
			printf("%c",c);
		}
	}
	printf("\n");
	return 0;
}


Measured memory_bytes: 256
MAX = 1000001

import sys

input = sys.stdin.readline


class Query:
    def __init__(self, l, r, idx):
        self.l = l
        self.r = r
        self.idx = idx

    # updating the bit array


def update(idx, val, bit, n):
    while idx <= n:
        bit[idx] += val
        idx += idx & -idx

    # querying the bit array


def query(idx, bit, n):
    summ = 0
    while idx:
        summ += bit[idx]
        idx -= idx & -idx
    return summ


def answeringQueries(arr, n, queries, q):
    # initialising bit array
    bit = [0] * (n + 1)

    # holds the rightmost index of  
    # any number as numbers of a[i] 
    # are less than or equal to 10^6 
    last_visit = [-1] * MAX

    # answer for each query 
    ans = [0] * q

    query_counter = 0
    for i in range(n):

        # If last visit is not -1 update -1 at the 
        # idx equal to last_visit[arr[i]] 
        if last_visit[arr[i]] != -1:
            update(last_visit[arr[i]] + 1, -1, bit, n)

            # Setting last_visit[arr[i]] as i and
        # updating the bit array accordingly 
        last_visit[arr[i]] = i
        update(i + 1, 1, bit, n)

        # If i is equal to r of any query store answer 
        # for that query in ans[] 
        while query_counter < q and queries[query_counter].r == i:
            ans[queries[query_counter].idx] = \
                query(queries[query_counter].r + 1, bit, n) - \
                query(queries[query_counter].l, bit, n)
            query_counter += 1

    # print answer for each query 
    for i in range(q):
        print(ans[i])


if __name__ == "__main__":
    N, Q = [int(x) for x in input().split()]
    a = [int(x) for x in input().split()]

    n = N
    queries = []
    for i in range(Q):
        l, r = [int(x) for x in input().split()]
        queries.append(Query(l - 1, r - 1, i))
    q = Q

    queries.sort(key=lambda x: x.r)
    answeringQueries(a, n, queries, q)


Measured memory_bytes: 232288
import java.util.*;

public class Main
{
	public static void main(String[] args) {
	    
	    Scanner sc = new Scanner(System.in);
	    String ip = sc.next();
	    
	    if (ip.length() == 2 ){
	        System.out.println(ip);
	    }
	    else if(ip.length() == 3){
	        StringBuilder ipr = new StringBuilder();
	        ipr.append(ip);
	        ipr = ipr.reverse();
	        System.out.println(ipr);
	    }else{
	        System.out.println();
	    }
	    
	}
}


Measured memory_bytes: 23248
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>

using namespace std;

#define FAST       			ios_base :: sync_with_stdio(false); cin.tie(NULL); 
#define endl "\n"

typedef long long int  ll;
typedef unsigned long long int ull;


int main()
{
	FAST;
	int n;
	cin >> n;
    int ans = 0;
    for(int i=1 ; i<=n ; i+=2)
    {
        int temp = i;
        int now = 1;
        
        for(int j=2 ; j<=temp ; j++)
        {
            int count = 0;
            while(temp%j == 0)  temp/=j,count++;
            now *= (count+1);
        }
        
        if(now == 8)    ans++;
    }
    cout << ans;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <stack>
#include <numeric>
#include <algorithm>
#include <bitset>
#include <complex>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef long long int llint;
#define MM 1000000000
#define MOD MM+7
#define pi pair<int,int>
#define pl pair<ll,ll>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
const long double PI = acos(-1);
const long long INF = 1e15;
const ll DEP = (1LL << 50);
int dx[4] = {-1,0,1,0};
int dy[4] = {0,-1,0,1};
template<typename T>
T GCD(T x,T y){
    return y ? GCD(y,x%y) : x;
}
int main(){
    int N; cin >> N;
    string s1,s2; cin >> s1 >> s2;
    vector<char> pattern;
    for(int i = 0; i < N; i++){
        if (s1[i] == s2[i]) pattern.emplace_back('v');
        else {
            pattern.emplace_back('h');
            i++;
        }
    }
    ll res = (pattern[0] == 'v' ? 3: 6);
    for (int i = 1; i < pattern.size(); i++) {
        if (pattern[i-1] == 'v' && pattern[i] == 'v') res *= 2;
        if (pattern[i-1] == 'v' && pattern[i] == 'h') res *= 2;
        if (pattern[i-1] == 'h' && pattern[i] == 'v') continue;
        if (pattern[i-1] == 'h' && pattern[i] == 'h') res *= 3;
        res %= MOD;
    }
    cout << res << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define lli long long int
#define inf 1000000000
#define pb push_back
#define mp make_pair
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define yoi cout<<"yo"<<endl;
#define debug(i) cout<<i<<endl;
const int mod=1e9 +7;
bool comp(pair<lli,lli> a,pair<lli,lli> b){
if(a.second!=b.second){
    return a.second<b.second;
}
else return a.first<b.first;
}
int main(){
IOS;
lli n,i;
cin>>n;
lli a,b;
vector<pair<lli,lli> > v;
for(i=0;i<n;i++){
    cin>>a>>b;
    v.pb({a,b});
}
sort(v.begin(),v.end(),comp);
lli t=0;
for(i=0;i<n;i++){
    if(t+v[i].first<=v[i].second){
        t+=v[i].first;
    }
    else break;
}
if(i==n){
    cout<<"Yes"<<endl;
}
else cout<<"No"<<endl;
}


Measured memory_bytes: 6512
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,c;
    cin>>a>>b>>c;
    if(b<a)
    {
        swap(a,b);
    }
    if(c<b)
    {
        swap(c,b);
    }
    if(c<a)
    {
        swap(a,c);
    }
    if(a==5 && b==5 && c==7)
    {
        cout<<"YES"<<endl;
    }
    else
    {
        cout<<"NO"<<endl;
    }
    return 0;
}


Measured memory_bytes: 3584
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
// *テンプレート*
#define int long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define P pair<long long,long long>
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 long long MOD = 1000000007;
const long long INF = 1LL << 60;
using namespace std;
typedef long long ll;
map<int, int> mp;
using Graph = vector<vector<int>>; 
//最大公約数
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	return gcd(b, a % b);
}
//最小公倍数
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}

// *テンプレートここまで*

// pair -> vector<pair<int,int>> 
//		   AandB.push_back(make_pair(a[i],b[i]))

signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n, a, b; cin >> n >> a >> b;
	cout << min(a*n, b) << endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int N,A[111];

int main()
{
	scanf ("%d",&N);
	for (int i=0;i<N;i++) scanf ("%d",&A[i]);
	int ans = 0x7fffffff;
	for (int c=-100;c<=100;c++){
		int s = 0;
		for (int i=0;i<N;i++) s += (A[i] - c) * (A[i] - c);
		if (ans > s)
			ans = s;
	}
	printf ("%d\n",ans);

	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <utility>
#include <numeric>
#include <queue>
#include <stack>

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9 + 7);

ll cnt(const vector<ll> &b, const vector<ll> &p, int n, ll x) {
	if( n == 0 ) {
		if( x <= 0 ) return 0;
		else return 1;
	} else if( x <= 1LL + b[n - 1] ) {
		return cnt(b, p, n - 1, x - 1);
	} else {
		return p[n - 1] + 1LL + cnt(b, p, n - 1, x - 2LL - b[n - 1]);
	}
}

int main(void) {
	int n;
	ll x;
	cin >> n >> x;
	
	vector<ll> b(n + 1), p(n + 1);
	b[0] = 1LL; 
	p[0] = 1LL;
	
	for(int i = 1; i <= n; ++i) {
		b[i] = b[i - 1] * 2LL + 3LL;
		p[i] = p[i - 1] * 2LL + 1LL;
	}

	cout << cnt(b, p, n, x) << endl;
	
	return 0;
}


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


vector<vector<P>> g(51);
vector<ll> es;
bool dfs(ll v, ll tv, ll p=-1){
  if (v==tv)return true;
  for(P e:g[v]){
    ll to=e.first;
    if(to==p) continue;
    ll id=e.second;
    if (dfs(to,tv,v)){
      es.push_back(id);
      return true;
    }
  }
  return false;
}
int main() {
  ll n, m;
  cin >> n;
  rep(i,n-1) {
    ll a, b;
    cin >> a >> b;
    --a; --b;
    g[a].emplace_back(make_pair(b, i));
    g[b].emplace_back(make_pair(a, i));
  }
  cin>>m;
  vector<ll> ebit(m);
  rep(i,m){
    ll a1,b1;
    cin>>a1>>b1;
    a1--;b1--;
    es=vector<ll>();
    dfs(a1,b1);
    for(auto enow:es){
      ebit[i]|=(1ll<<enow);
    }
  }
//  cout<<ebit[0]<<'k'<<endl;
  ll ans=0;
  for(ll i=0;i<(1ll<<m);i++){

    ll cnt=0;
    rep(j,m){
      if ((i>>j)&1){
        cnt|=ebit[j];
      //  cout<<cnt<<'c'<<j<<'j'<<ebit[j]<<endl;
      }
    }
    ll white = __builtin_popcountll(cnt);
  //  cout<<white<<endl;
    ll now=(1ll<<(n-1-white));
     if (__builtin_popcount(i)%2==0){
       ans+=(1ll<<(n-1-white));
     }
     if (__builtin_popcount(i)%2==1){
       ans-=(1ll<<(n-1-white));
     }
  //   cout<<i<<'i'<<now<<endl;
  }
cout<<ans;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, init, n) for(int i = (int)(init); i < (int)(n); i++)

#define vi vector<int>
#define vl vector<long>
#define vvi vector<vector<int>>
#define vvl vector<vector<long>>
#define pint pair<int, int>
#define plong pair<long, long>

int main() {
    int H, W, K;
    cin>> H >> W >> K;
    vector<string> S(H, (W, "."));
    REP(i, 0, H){
        cin>>S[i];
    }
    int ans = 0;
    int rep_H = pow(2, H);
    int rep_W = pow(2, W);
    REP(i, 0, rep_H){
        REP(j, 0, rep_W){     
            vector<string> T = S;
            int h = i, w = j;
            REP(k, 0, H){
                if(h%2){
                    REP(l, 0, W){
                        T[k][l] = 'R';
                    }
                }
                h = h >> 1;
            }
            REP(k, 0, W){
                if(w%2){
                    REP(l, 0, H){
                        T[l][k] = 'R';
                    }
                }
                w = w >> 1;
            }
            int count = 0;
            REP(k, 0, H){
                REP(l, 0, W){
                    if(T[k][l] == '#') count++;
                }
            }
            if(count == K){
                ans++;
            }
        }

    }
    cout << ans << endl;
}

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

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N;
    cin >> N;
    vector<ll> A(N);
    for(int i=0; i<N; i++) cin >> A[i];
    vector<ll> B(N);
    for(int i=0; i<N; i++) cin >> B[i];

    string ans = "Yes";
    ll asum = accumulate(A.begin(), A.end(), 0LL);
    ll bsum = accumulate(B.begin(), B.end(), 0LL);
    if(asum > bsum) ans = "No";

    ll difsum = 0;
    for(int i=0; i<N; i++)
    {
        if(A[i] < B[i]) difsum += (B[i] - A[i] + 1) / 2;
    }
    if(bsum - asum < difsum) ans = "No";
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3788
import java.util.*;

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

		while(true){
			int n = sc.nextInt();
			int m = sc.nextInt();
			if(n == 0 && m == 0) break;

			HashMap<String,Integer> map = new HashMap<String,Integer>();
			for(int i=0;i<n;i++){
				String s = sc.next().replace("*",".");
				int price = sc.nextInt();
				map.put(s,price);
			}

			int ans = 0;
			for(int i=0;i<m;i++){
				String x = sc.next();
				for(String s : map.keySet()){
					if(x.matches(s)){
						ans += map.get(s);
						break;
					}
				}
			}

			System.out.println(ans);
		}
	}
}

Measured memory_bytes: 13000
#include <stdio.h>
#include <string.h>
#include <math.h>
int main(void)
{
	int a[101],i;
	for(i=0;i<=100;i++)
	a[i]=1;
	int sum=0;
	int k=2;
	while(k--)
	{
		int m,n;
		scanf("%d %d",&m,&n);
		for(i=m;i<=n;i++)
		a[i]-=1;
	 } 
	 for(i=0;i<=100;i++)
	 {
	 	if(a[i]<0)
	 	sum++;
	 }
	 if(sum>0)
	 sum-=1;
	 printf("%d\n",sum);
 } 

Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
int dp[10005]={0};
int main()
{
    int n;
    cin >> n;

    for(int i=1;i*i<=n;i++)
    for(int j=1;j*j<=n;++j){
        for(int k=1;k*k<=n;++k){
            int num = i*i+j*j+k*k+i*j+j*k+k*i;
            if(num<=n){
                dp[num]++;
            }
        }
    }
    for(int i=1;i<=n;i++){
        cout << dp[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 3592
#include <iostream>
#include <string>
#include <vector>
#include <cstring>
#include <climits>
#include <algorithm>
#include <map>
#include <sstream>
using namespace std;

string time_format(int h, int m) {
    stringstream ss;
    ss << h << ":" << (m < 10 ? "0" : "") << m;
    return ss.str();
}

int main() {
    vector<pair<int, string> > v;

    int N, h, m;
    cin >> N;
    for (int i=0; i<N; ++i) {
        cin >> h >> m;
        v.push_back(make_pair(h*60+m, time_format(h, m)));
    }

    int M, k, g;
    cin >> M;
    for (int i=0; i<M; ++i) {
        cin >> k >> g;
        v.push_back(make_pair(k*60+g, time_format(k, g)));
    }

    sort(v.begin(), v.end());
    for (int i=0; i<(int)v.size(); ++i) {
        if (1 <= i && v[i-1].second == v[i].second) continue;
        cout << (i==0 ? "" : " ") << v[i].second;
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 1248
n, m = [ int(v) for v in input().split() ]
num_list = sorted([ int(v) for v in input().split() ])
diff_list = sorted([ abs(num_list[i] - num_list[i+1]) for i in range(m-1) ])

ans = 0
if n < m:
    for i in range(m-n):
        ans += diff_list[i]    
print(ans)


Measured memory_bytes: 58408
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define UNIQUE(v) v.erase(unique(all(v)), v.end());
#define ZIP(v) sort(all(v)),UNIQUE(v)
#define ADD(a, b) a = (a + b) % mod
#define SUB(a, b) a = (a+mod-b)%mod
#define MUL(a, b) a = (a * b) % mod
#define repi(i,m,n) for(int i = m;i < n;i++)
#define drep(i,n,m) for(int i = n;i >= m;i--)
#define rep(i,n) repi(i,0,n)
#define rrep(i,n) repi(i,1,n+1)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(), v.rend()
#define dmp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define fi first
#define se second
typedef pair<int,int> P;
typedef pair<int, P> PP;
typedef pair<P, int> Pi;
typedef vector<int> vi;
typedef deque<int> dq;
const int inf = 1e9+7;
const int INF = 1e18+7;

int a[200][200];
signed main(){
	int h, w;
	scanf("%lld%lld", &h, &w);
	rep(i,h){
		string str;
		cin >> str;
		rep(j,w){
			if(str[j] == '#')a[i][j] = 2;
			else a[i][j] = 1;
		}
	}
	
	rep(i,h){
		int f = 1;
		rep(j,w){
			if(a[i][j] == 2)f = 0;
		}
		if(f)rep(j,w){
			a[i][j] = 0;
		}
	}
	rep(j,w){
		int f = 1;
		rep(i,h){
			if(a[i][j] == 2)f = 0;
		}
		if(f)rep(i,h){
			a[i][j] = 0;
		}
	}
	
	rep(i,h){
		int f = 0;
		rep(j,w){
			if(a[i][j] == 1)printf(".");
			else if(a[i][j] == 2)printf("#");
			if(a[i][j])f = 1;
		}
		if(f)printf("\n");
	}
	return 0;
}






Measured memory_bytes: 384
N = int(input())
A, B = map(int, input().split())

c = [0] * 3
for P in map(int, input().split()):
    if P <= A:
        c[0] += 1
    elif A < P <= B:
        c[1] += 1
    else:
        c[2] += 1

print(min(c))

Measured memory_bytes: 9112