akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <queue>
#include <climits>
#include <algorithm>

struct Edge {
	int s;
	int t;
	int weight;
};

bool comp_s(const Edge& e, const Edge& f) { return e.s < f.s; }

struct Vertex {
	int id;
	int weight;
	std::vector<int> sink;
	std::vector<int> weight_to_sink;
};

typedef std::pair<int,int> W_ID;

int main ()
{
	int n, m, r;
	std::cin >> n >> m >> r;
	
	Edge* edge_list = new Edge[m];
	for (int i=0; i<m; i++) std::cin >> edge_list[i].s >> edge_list[i].t >> edge_list[i].weight;
	std::sort(edge_list, edge_list + m, comp_s);
	
	Vertex* vertex = new Vertex[n];
	int index = 0;
	for (int i=0; i<n; i++) {
		vertex[i].id = i;
		vertex[i].weight = INT_MAX;
	//	vertex[i].done = false;
		while (edge_list[index].s == i) {
			vertex[i].sink.push_back(edge_list[index].t);
			vertex[i].weight_to_sink.push_back(edge_list[index].weight);
			index++;
		}
	}
	vertex[r].weight = 0;
	
	//std::priority_queue<W_ID, std::vector<W_ID>, std::greater<W_ID> > pq;
	//pq.push( std::make_pair(0,r) );
	
	bool negative_cycle = false;
	/*
	while (!pq.empty()) {
		int s = pq.top().second; pq.pop();
		if (vertex[s].done) continue;
		// std::cout << s << std::endl;
		vertex[s].done = true;
		for (int i=0; i<vertex[s].sink.size(); i++) {
			int t = vertex[s].sink[i];
			if (vertex[t].done) continue;
			int w = vertex[s].weight_to_sink[i];
			if (vertex[t].weight > vertex[s].weight + w) {
				vertex[t].weight = vertex[s].weight + w;
				pq.push ( std::make_pair(vertex[t].weight, t) );
			}
		}
	}
	*/
	
	for (int i=0; i<n; i++) {
		for (int j=0; j<m; j++) {
			int s = edge_list[j].s;
			int t = edge_list[j].t;
			int w = edge_list[j].weight;
			if (vertex[s].weight == INT_MAX) continue;
			if (vertex[t].weight > vertex[s].weight + w) {
				vertex[t].weight = vertex[s].weight + w;
			}
		}
	}
	
	for (int i=0; i<m; i++) {
		int s = edge_list[i].s;
		int t = edge_list[i].t;
		int w = edge_list[i].weight;
		if (vertex[s].weight == INT_MAX) continue;
		if (vertex[t].weight > vertex[s].weight + w) {
			negative_cycle = true; break;
		}
	}
	
	if (negative_cycle) {
		std::cout << "NEGATIVE CYCLE" << std::endl;
	}
	else {
		for (int i=0; i<n; i++) {
			if(vertex[i].weight < INT_MAX) std::cout << vertex[i].weight << std::endl;
			else std::cout << "INF" << std::endl;
		}
	}
	
	delete[] vertex;
	delete[] edge_list;
	
	return 0;
}



Measured memory_bytes: 3260
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

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

    int q;
    cin >> q;
    vector<int> t(q);
    for(int i = 0; i < q; i++) cin >> t[i];

    int count = 0;
    for(int i = 0; i < q; i++){
        for(int j = 0; j < n; j++){
            if(t[i] == s[j]){
                count++;
                break;
            }
        }
    }
    cout << count << endl;
}


Measured memory_bytes: 3112
n = int(input())
s = [input() for _ in range(n)]
d = {}
for w in s:
    if w not in d:
        d[w] = 0
    d[w] += 1
d2 = sorted(d.items(), key=lambda x:x[1], reverse=True)
maxcnts = [w[0] for w in d2 if w[1] == d2[0][1]]
maxcnts.sort()
for ans in maxcnts:
    print(ans)

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

#define pb push_back
#define rb  pop_back
#define rf  pop_front
#define ins insert
#define f   first
#define s   second
#define um  unordered_map
#define us  unordered_set
#define pq  priority_queue

typedef vector< int > vi;
typedef vector< vi > vvi;
typedef pair< int,int > ii;
typedef pair< long long int ,long long int > iil;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef vector< ll > vl;
typedef vector< vl > vvl;
typedef vector<double> vd;
typedef pair<double,double> pd;
typedef queue<int> qi;
typedef queue<double> qd;
typedef queue<ll> qll;
typedef us<int> si;
typedef us<double> sd;
typedef us<ll> sll;
typedef vector<vd> md;


const int MAX = 1e6;
const int N = 200043;
const int MOD = 998244353;

#define IO ios_base::sync_with_stdio(false); cin.tie(NULL);
#define sz(a) int((a).size())
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for( auto i = (c).begin(); i != (c).end(); i++)
#define present(c,x) ((c).find(x) != (c).end())
#define EE endl
#define PI 3.14159265
#define g(a,b) a>b?a:b
#define l(a,b) a<b?a:b
#define SOT(A) sort(A.begin(),A.end())
#define SOTR(A) sort(A.rbegin(),A.rend())
#define REV(a) reverse(ALL(a))

// LOOP Control Statements
#define forn(i,j,n) for ( auto i=j ; i<n ; i++ )
#define fornd(i,j,n) for ( auto i=j ; i>n ; i-- )
#define FORE(i, b) for(auto &i:b)


#define SQ(i) (i*i)
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define IN(a, b) (a.find(b) != a.end())
#define BACK(a) a.back(); a.RB()
#define QBACK(a) a.top(); a.pop()
#define PRINT(a) FORE(i, a) cout << i << " "; cout << endl
#define take(V,f,n) for(int i=f;i<f+n;i++) cin>>V[i]
#define tcase(term) int tc;cin>>tc;for(int term=0; cout<<"CASE "<<term+1<<EE,term<tc;term++)





int main()
{
	// #ifndef ONLINE_JUDGE
	// freopen("input.txt","r",stdin);
	// freopen("output.txt","w",stdout);
	// #endif
	// tcase(terms)
	{
		int n;
		cin>>n;
		vi A(n);
		forn(i,0,n) cin>>A[i];
		SOT(A);
		set<int> S;
		int ans=0;
		forn(i,0,n){
			if(i!=n and A[i]==A[i+1]){
				S.insert(A[i]);
				continue;

			}
			set<int> P;
			bool can=true;
			for(int j=1;j*j<=A[i];++j){
				if(A[i]%j==0){
					if(S.count(j) or S.count(A[i]/j)){
						can=false;
						break;
					}
				}
			}
			if(can) ans++;
			S.insert(A[i]);

		}
		cout<<ans<<endl;

	}

}


Measured memory_bytes: 13488
fn main () {
    let mut ab = String::new();
    std::io::stdin().read_line(&mut ab).unwrap();
    let ab: Vec<isize> = ab.trim().split_whitespace().flat_map(str::parse).collect();

    println!("{}", if ab[0] * ab[1] % 2 != 0 { "Yes" } else { "No" });
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define sz(x) ((int) (x).size())

typedef long long ll;

const int n = 2e5+10;

int N;
ll A[n], B[n];

int main(){
	cin >> N;
	for(int i=0; i<N; i++){
		cin >> A[i];
	}
	for(int i=0; i<N; i++){
		cin >> B[i];
	}
	ll cnt = 0;
	while(true){
		bool f = true;
		bool changed = false;
		for(int i=0; i<N; i++){
			ll sum = B[(i+N-1)%N]+B[(i+1)%N];
			if(B[i] >= sum){
				if((B[i]-A[i]) % sum == 0){
					cnt += (B[i]-A[i])/sum;
					if(B[i] != A[i])
						changed = true;
					B[i] = A[i];
				}
				else{
					cnt += B[i]/sum;
					changed = true;
					B[i] %= sum;
				}
				if(B[i] < A[i]){
					cout << -1 << endl;
					return 0;
				}
			}
			if(B[i] != A[i])
				f = false;
		}
		if(f){
			cout << cnt << endl;
			break;
		}
		if(!changed){
			cout << -1 << endl;
			break;
		}
	}

  return 0;
}


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

int main(){
    int abc[3] = {};
    int k;
    for(int i=0;i<3;i++){
        cin >> abc[i];
    }
    cin >> k;
    sort(abc,abc+3,greater<int>());
    abc[0] *= pow(2,k);
    int ans = 0;
    for(int i=0;i<3;i++)
    {
        ans += abc[i];
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<typename T>
vector<T> table(int n, T v) { return vector<T>(n, v); }

template <class... Args>
auto table(int n, Args... args) {
    auto val = table(args...);
    return vector<decltype(val)>(n, move(val));
}
const ll INF = 1e9;
const ll MOD = 1000000007;
typedef pair<ll,ll> P;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int train[505][505] = {0};
    int n,m,q,l,r,c;
    cin >> n >> m >> q;
    rep(i,m){
        cin >> l >> r;
        train[l][r]++;
    }
    rep(i,1,n+1){
        c = 0;
        rep(j,1,n+1){
            c += train[i][j];
            train[i][j] += c-train[i][j]+train[i-1][j];
        }
    }
    rep(i,q){
        cin >> l >> r;
        PRINT(train[r][r]-train[l-1][r]-train[r][l-1]+train[l-1][l-1]);
    }
}

Measured memory_bytes: 1920
// 2016/04/30 Tazoe

#include <iostream>
using namespace std;

int main()
{
	int H, W;
	cin >> H >> W;

	int T[100][100];
	for(int y=0; y<H; y++){
		for(int x=0; x<W; x++){
			char C;
			cin >> C;

			if(C=='c'){
				T[y][x] = 0;
			}
			else{
				if(x==0){
					T[y][x] = -1;
				}
				else{
					if(T[y][x-1]==-1){
						T[y][x] = -1;
					}
					else{
						T[y][x] = T[y][x-1]+1;
					}
				}
			}
		}
	}

	for(int y=0; y<H; y++){
		for(int x=0; x<W; x++){
			cout << T[y][x];

			if(x!=W-1){
				cout << ' ';
			}
			else{
				cout << endl;
			}
		}
	}

	return 0;
}

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

namespace _1_11_D_2
{
    class Program
    {
        static void Main(string[] args)
        {
            Dice dice1 = new Dice();
            int n = int.Parse(Console.ReadLine());
            string[,] dice = new string[n, 6];
            List<string> answerList = new List<string>();
            for (int i = 0; i < n; i++)
            {
                string[] diceLine = Console.ReadLine().Split();
                for (int j = 0; j < 6; j++)
                {
                    dice[i, j] = diceLine[j];
                }
            }
            for (int i = 0; i < n - 1; i++)
            {
                for (int g = i + 1; g < n; g++)
                {
                    dice1.IsAllCompare(dice, i, g, answerList);

                }
            }
            if (answerList.Contains("No") == true)
            {
                Console.WriteLine("No");
            }
            else
            {
                Console.WriteLine("Yes");
            }
        }
    }
    class Dice
    {
        //i番目のdiceとn番目のdiceの一致判定。一致したときanswerはNo
        internal void IsAllCompare(string[,] dice, int i, int n, List<string> answerList)
        {
            string[] order = { "S", "S", "S", "N", "S", "S", "S", "N", "S", "S", "S", "E","S","S","S"
            ,"E","S","S","S","N","S","S","S"};

            for(int j = 0; j < order.Length; j++)
            {
                Order(order, dice, j, n);
                answerList.Add(IsSame(dice, i, n));
            }
        }
        internal string IsSame(string[,] dice, int i, int n)
        {

            if (dice[i, 0] == dice[n, 0] && dice[i, 1] == dice[n, 1] && dice[i, 2] == dice[n, 2]
                && dice[i, 3] == dice[n, 3] && dice[i, 4] == dice[n, 4] && dice[i, 5] == dice[n, 5])
            {
                return "No";
            }
            else
            {
                return "Yes";
            }
        }
        //g番目の文字でi番目のdiceの転がす方向を決める
        internal void Order(string[] order, string[,] dice, int g, int i)
        {
            if (order[g] == "S") Roll_South(dice, i);
            if (order[g] == "N") Roll_Noth(dice, i);
            if (order[g] == "E") Roll_East(dice, i);
        }
        //サイコロを東西南北に転がす
        internal void Roll_South(string[,] dice, int i)
        {
            string str = dice[i, 0];
            dice[i, 0] = dice[i, 2];
            dice[i, 2] = dice[i, 5];
            dice[i, 5] = dice[i, 3];
            dice[i, 3] = str;
        }
        internal void Roll_Noth(string[,] dice, int i)
        {
            string str = dice[i, 0];
            dice[i, 0] = dice[i, 1];
            dice[i, 1] = dice[i, 5];
            dice[i, 5] = dice[i, 4];
            dice[i, 4] = str;
        }
        internal void Roll_East(string[,] dice, int i)
        {
            string str = dice[i, 0];
            dice[i, 0] = dice[i, 4];
            dice[i, 4] = dice[i, 5];
            dice[i, 5] = dice[i, 1];
            dice[i, 1] = str;
        }
    }
}



Measured memory_bytes: 19552
#include<stdio.h>
int main(){
  int a,b,c,d,e,f;
  scanf("%d %d %d",&a,&b,&c);
  if(a<b)d=a;
  else   d=b;
  if(c<d)d=c;
  if(a<b)e=b;
  else   e=a;
  if(e<c)e=c;
  printf("%d %d %d\n",d,a+b+c-d-e,e);
  return 0;
}

Measured memory_bytes: 596
#include <iostream>

using namespace std;

int main()
{
    int n;
    cin>>n;
    int even=0;
    int odd=0;
    for(int i=0;i<n;i++){
        if (i%2==0){
            even+=1;
        }
        else{
            odd+=1;
        }
    }
    int result=odd*even;
    cout<<result;
    return 0;
}


Measured memory_bytes: 256
import sys
from collections import defaultdict
from heapq import heappop, heappush

input = sys.stdin.readline

N = int(input())


class Graph(object):
    def __init__(self):
        self.graph = defaultdict(list)

    def __len__(self):
        return len(self.graph)

    def add_edge(self, src, dst, weight=1):
        self.graph[src].append((dst, weight))

    def get_nodes(self):
        return self.graph.keys()


class Dijkstra(object):
    def __init__(self, graph, start):
        g = graph.graph

        self.dist = defaultdict(lambda: float('inf'))
        self.dist[start] = 0
        self.prev = defaultdict(lambda: None)

        Q = []
        heappush(Q, (self.dist[start], start))

        while Q:
            dist_u, u = heappop(Q)
            if self.dist[u] < dist_u:
                continue
            for v, weight in g[u]:
                alt = dist_u + weight
                if self.dist[v] > alt:
                    self.dist[v] = alt
                    self.prev[v] = u
                    heappush(Q, (alt, v))

    def shortest_distance(self, goal):
        return self.dist[goal]


g = Graph()
for _ in range(N - 1):
    a, b = map(int, input().split())
    g.add_edge(a - 1, b - 1)
    g.add_edge(b - 1, a - 1)

d1 = Dijkstra(g, 0)
d2 = Dijkstra(g, N - 1)

cnt1, cnt2 = 0, 0
for i in range(1, N - 1):
    x = d1.shortest_distance(i)
    y = d2.shortest_distance(i)
    if x <= y:
        cnt1 += 1
    else:
        cnt2 += 1

if cnt1 > cnt2:
    print('Fennec')
else:
    print('Snuke')


Measured memory_bytes: 77720
// inputに入力データ全体が入る
function Main(input) {
    var a = input[0].split(" ")[0]-0;
    var b = input[0].split(" ")[1]-0;
    var ans = 0;
    for(var i=a;i<=b;i++){
        var tmp = i.toString().split("");
        if(tmp.join("") == tmp.reverse().join("")) ans ++;
    }
    console.log(ans);
}

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

Measured memory_bytes: 27292
#include<iostream>

using namespace std;

int main(){
    string s;
    cin >> s;
    int i,n,k;

    for(i=0; i<s.size(); i++){
        if(s[i] == 'A'){
            n=i;
            break;
        }
    }

     for(i=s.size()-1; i>n; i--){
        if(s[i] == 'Z'){
            k=i;
            break;
        }
    }

    cout << k-n+1 <<endl;
    return 0;
}

Measured memory_bytes: 640
#include<stdio.h>
int main(void){
    int a, b, d, r;
    double f;

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

    d = a/b;
    r = a%b;
    f = (double)a/(double)b;

    printf("%d %d %f\n", d, r, f);

    return 0;
}


Measured memory_bytes: 2104
s = input()
t = input()
cnt = 0
ans = 0
while cnt < len(s) - len(t) + 1:
    chk = 0
    for i, j in zip(range(cnt,cnt+len(t)),range(len(t))):
        if s[i] == t[j]:
            chk += 1
    ans = max(ans,chk)
    cnt += 1

print(len(t) - ans)

Measured memory_bytes: 9052
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define endl "\n"
#define se second
#define ls( s) (s&(-s))
#define ll long long
#define inf 0x3f3f3f3f
const ll N = 200030;
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
const ll mod =    1e9+7;

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

ll k,x;
cin>>k>>x;
if(500*k>=x)
cout<<"Yes";
else
cout<<"No";




}

Measured memory_bytes: 256
# import sys
# input = sys.stdin.readline

def mp(): return map(int, input().split())
def lmp(): return list(map(int, input().split()))

n = int(input())
a = lmp()
a.sort(reverse=True)
ans = 0
u = [a[0]]
for i in range(1, n):
    u.append(a[i])
    u.append(a[i])
print(sum(u[:n-1]))







Measured memory_bytes: 118896
{-# LANGUAGE BangPatterns #-}
import           Control.Exception           (assert)
import           Control.Monad
import           Control.Monad.Primitive
import qualified Control.Monad.ST            as ST
import qualified Data.Array.IO               as IO
import qualified Data.Array.ST               as ST
import qualified Data.Array.Unboxed          as A
import           Data.Bits
import qualified Data.ByteString.Char8       as BS
import           Data.Char
import           Data.Foldable
import           Data.List
import qualified Data.Map.Strict             as Map
import           Data.Maybe
import qualified Data.Sequence               as Seq
import qualified Data.Set                    as Set
import qualified Data.Vector                 as VB
import qualified Data.Vector.Mutable         as VBM
import qualified Data.Vector.Unboxed         as V
import qualified Data.Vector.Unboxed.Mutable as VM
import           Debug.Trace

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine
getIntVec n = V.unfoldrN n (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine

readInteger = fst . fromJust . BS.readInteger
readIntegerList = map readInteger . BS.words
getInteger = readInteger <$> BS.getLine
getIntegerList = readIntegerList <$> BS.getLine

inf :: Int
inf = 10^18

main = do
  a <- getInt
  print $ a + a^2 + a^3


Measured memory_bytes: 3732
#include <stdio.h>

int main(void) {
	double a, b, c, d, e, f;
	double x, y;

	while(scanf("%lf", &a) != EOF) {
		scanf("%lf", &b);
		scanf("%lf", &c);
		scanf("%lf", &d);
		scanf("%lf", &e);
		scanf("%lf", &f);

		x = (c*e-b*f)/(a*e-b*d);
		y = (a*f-c*d)/(a*e-b*d);

		x += 0.0;
		y += 0.0;

		printf("%.3f %.3f\n", x, y);
	}

	return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define rep(i,n) for(int i=0;i<n;i++)
#define mod 1000000007 // 10^9+7
string s[3];
int l[3];
signed main(){
    cin>>s[0]>>s[1]>>s[2];
    rep(i,3){
        l[i]=s[i].size();
    }
    int turn=0;
    while(s[turn].size()){
        char f=s[turn][0];
        int l=s[turn].size();
        if(l>1)s[turn]=s[turn].substr(1);
        else s[turn]="";
        turn=f-'a';
    }
    char ans='A'+turn;
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
//hinagata.cpp
//作成日
//更新日
//目的
//手段
/*includes*/
#include <bits/stdc++.h>
/*namespace*/
using namespace std;
using ll= long long;
/*define macro*/
#define REP(i,n) for(ll i=0;i<(n);i++)
#define REPi(i,a,b) for(ll i=(a);i<(b);i++)
#define REPRi(i,a,b) for(ll i=(a);i>(b);i--)
#define ALL(x) (x).begin(),(x).end()


int main(){
int N,M;
cin>>N>>M;
vector<vector<int>> E(N,vector<int>(N,0));
REP(i,M){
    int a,b;
    cin>>a>>b;
    E[a-1][b-1]=1;
    E[b-1][a-1]=1;
}
//input end
vector<int> P(N);
REP(i,N){
    P[i]=i+1;
}
int count=0;
do{
    int flag=0;
    REPi(i,1,N){
        if(E[P[i]-1][P[i-1]-1]==0){
            flag=1;
        }
    }
    if(flag==0){
        count+=1;
    }
}while(next_permutation(P.begin()+1,P.end()));
cout<<count<<endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <sstream>
#ifndef M_PI
#define M_PI 3.1415926535897932384626433832795
#endif
using namespace std;
static const double EPS = 1e-5;
typedef long long ll;
typedef pair<int,int> PI;
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define F first
#define S second

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

int ans[100];
int mod[100];

main(){
  int p,q;
  while(cin>>p>>q){
    int pos=0;

    p*=10;
    while(pos<100){
      ans[pos]=p/q;
      mod[pos]=p;
      p%=q;
      p*=10;
      ++pos;
    }


    if(mod[99]){
      int ms=0,mt;
      for(;;ms++){
	for(mt=ms+1;mt<100;mt++){
	  if(mod[ms]==mod[mt])break;
	}
	if(mt<100)break;
      }

      rep(i,mt)cout<<ans[i];
      cout<<endl;
      rep(i,ms)cout<<' ';
      rep(i,mt-ms)cout<<'^';
      cout<<endl;
    }else{
      for(int i=0;mod[i];i++)cout<<ans[i];
      cout<<endl;
    }
  }
}

Measured memory_bytes: 0
#include <cstddef>
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <vector>
#include <array>
#include <list>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <bitset>
#include <valarray>
#include <utility>
#include <tuple>
#include <cmath>
#include <memory>
#include <random>
#include <fstream>
#include <locale>
#include <regex>
#include <complex>

using ll = long long;
using ull = unsigned long long;
using ld = long double;

//vector
template <class T>
using vec = std::vector<T>;

template <class T>
using vvec = vec<vec<T>>;

constexpr std::size_t operator""_sz(ull n) { return std::size_t(n); }

template <class T>
constexpr bool in(T min, T max, T t)
{
    return t >= min && t <= max;
}

template <class T>
constexpr bool nin(T min, T max, T t)
{
    return !in(min, max, t);
}

template <class T>
void ninDebug(T min, T max, T t)
{
    using namespace std;
    if (nin(min, max, t))
    {
        cout << "ERROR" << endl;
    }
}

int main()
{
    using namespace std;
    // cerr.rdbuf(nullptr);

    string str;
    int q;
    cin >> str >> q;

    for (int i = 0; i < q; ++i)
    {
        string order;
        int a, b;
        cin >> order;
        cin >> a >> b;
        if (order == "print")
        {
            cout << str.substr(a, b - a + 1) << endl;
        }
        else if (order == "replace")
        {
            string r;
            cin >> r;

            for (int j = 0; j < r.size(); ++j)
            {
                str[j + a] = r[j];
            }
        }
        else
        {
            reverse(str.begin() + a, str.begin() + b + 1);
        }
    }

    

    return 0;
}


Measured memory_bytes: 3228
s=list(input())
t=list(input())

a = [] #kouho
tl = len(t)
sl = len(s)

for i in range(sl-tl+1):
    k = 0
    for j in range(tl):
        if t[j] == s[i+j] or s[i+j] == '?':
            k += 1
        else:
            break
    if k == tl:
        if i == 0 and i == sl-tl:
            w = t
        elif i == 0:
            w =  t + ['a' if hj == '?' else hj for hj in s[i+tl::]]
        elif i == sl-tl:
            w =  ['a' if hj == '?' else hj for hj in s[:i:]] + t
        else:
            w = ['a' if hj == '?' else hj for hj in s[:i:]] + t + ['a' if hj == '?' else hj for hj in s[i+tl::]]
        ass = ''
        for jkl in range(len(w)):
            ass += w[jkl]
        a.append(ass)
        
#print(a)

if len(a)== 0:
    print('UNRESTORABLE')
else:
    print(min(a))

Measured memory_bytes: 3064
//Nihal Mittal - nihal_47
//Strike First , Strike Hard , No Mercy !!

/**⠀⠀⠀⠀⠀⠀⣀⣤⣤⣄⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⣠⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣦⣀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⣰⣿⣿⣿⣿⠿⠿⣿⣿⣿⣿⣿⣿⣿⣧⢀⠀⠀⠀⠀
⠀⠀⠀⣿⣿⣿⠋⠀⠀⠀⠀⠀⠙⠀⠙⣿⣿⣿⣷⢳⢀⠀⠀⠀
⠀⠀⣠⣿⣿⣿⢸⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣿⣿⣿⣿⣿⢀
⠀⠀⣸⣿⣿⣿⠸⠀⠀⠀⠒⠒⠒⠐⠀⠀⢿⣿⣿⣿⣿⣿⠀⠀
⠀⣴⣿⣿⣿⡿⠀⠒⣋⣙⡒⢰⠀⠤⣖⠒⢾⣿⣿⣿⣿⣧⠀⠀
⢺⣿⣿⣿⣿⢀⠀⠀⠉⠉⠉⠸⠀⡇⠉⠉⠀⢿⣿⣿⣿⣄⠀⠀
⠀⠙⣿⣿⣧⢻⠀⠀⠀⠀⠀⠠⠀⠰⠀⠀⠀⣸⠸⣿⣿⠿⠰⠀
⠀⠀⠀⠹⣿⣿⣿⣷⠀⡠⠙⣲⣔⣅⢡⣰⣷⣿⣿⣿⣧⠀⠀⠀
⠀⠀⠀⣼⣿⣿⣿⣿⠀⡿⠭⠭⠭⠭⢿⠀⣿⢻⣿⣿⠃⠀⠀⠀
⠀⠀⠀⠙⠛⣿⢻⠹⣿⠐⠙⠛⠟⠉⢀⣴⡟⢿⣿⡏⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⡟⠀⠀⠻⣦⣤⣶⠾⠋⠀⠀⠁⡦⢄⢀⠀⠀⠀
⠀⠀⠀⠀⡠⠁⡇⠑⢄⠀⠀⠀⠀⠀⠀⠔⠀⠀⠁⠀⠀⠀⠉⠁
⠀⠔⠊⠁⠀⠀⣇⠀⠀⠀⠑⡤⠤⢎⠁⠀⠀⡘⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⢢⠠⠀⡠⢆⠀⠀⡠⠙⢄⠀⡸⠀
**/
#include<bits/stdc++.h>
#define ll long long
#define l long
#define mk make_pair
#define pb push_back
#define in insert
#define se second
#define fi first
#define mod 1000000007
#define watch(x) cout << (#x) << " is " << (x) << "\n"
#define all(v) (v).begin(),(v).end()
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(0);
#define pii pair<int,int>
#define maxn 100005
using namespace std;
signed main()
{
    fast;
    
    ll n,i,j;
    cin>>n;
    ll a[n+2],sum=0;
    for(i=0;i<n;i++) cin>>a[i];
    for(i=0;i<n;i++)
    {
    	for(j=i+1;j<n;j++)
    	{
    		sum += a[i]*a[j];
    	}
    }
    cout<<sum;
}


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

using namespace std;

#define REP(i, a, b) for (int i = (a), i##_end_ = (b); i < i##_end_; ++i)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define mp make_pair
#define x first
#define y second
#define pb push_back
#define SZ(x) (int((x).size()))
#define ALL(x) (x).begin(), (x).end()
#define EXIT(...) printf(__VA_ARGS__), exit(0)

template<typename T> inline bool chkmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; }
template<typename T> inline bool chkmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }

typedef long long LL;

const int oo = 0x3f3f3f3f;

const int maxn = 10;

int n, m;

int main()
{
#ifdef matthew99
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	scanf("%d%d", &n, &m);
	int lstl = 0, lstr = 0;
	REP(i, 0, n)
	{
		static char a[maxn + 5];
		scanf("%s", a);
		int l = m, r = 0;
		REP(j, 0, m) if (a[j] == '#') chkmin(l, j), chkmax(r, j);
		if (l > r) EXIT("Impossible");
		if (l != lstr) EXIT("Impossible");
		REP(j, l, r) if (a[j] != '#') EXIT("Impossible");
		if (!i && l) EXIT("Impossible");
		lstl = l, lstr = r;
	}
	if (lstr != m - 1) EXIT("Impossible");
	puts("Possible");
	return 0;
}


Measured memory_bytes: 256
n=gets.to_i
s=gets.chomp
cnt=0
["0","1","2","3","4","5","6","7","8","9"].repeated_permutation(3) do |a,b,c|
  if s.index(a)
    if s.index(b,s.index(a)+1)
      if s.index(c,s.index(b,s.index(a)+1)+1)
        cnt+=1
      end
    end
  end
end
puts cnt

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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
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 INF = (1<<30) - 1;
const ll LINF = (1LL<<60) - 1;

int main(){
    ll n, m;
    cin >> n >> m;
    vector<ll> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    sort(all(a));

    ll ok = -1, ng = LINF;
    while(abs(ok - ng) > 1) {
        ll mid = (ok + ng) / 2;

        ll num = 0;
        for (int i = 0; i < n; ++i) {
            num += n - (lower_bound(all(a), mid - a[i]) - a.begin());
        }

        if (num >= m) ok = mid;
        else ng = mid;
    }

    vector<ll> sum(n+1, 0);
    for (int i = 0; i < n; ++i) {
        sum[i+1] += sum[i] + a[i];
    }
    ll res = 0;
    ll mval = LINF;
    ll num = 0;
    for (int i = 0; i < n; ++i) {
        auto itr = lower_bound(all(a), ok - a[i]);
        res += (n - (itr - a.begin())) * a[i];
        res += sum[n] - sum[itr - a.begin()];
        if (itr != a.end()) chmin(mval, a[i] + *itr);
        num += n - (itr - a.begin());
    }
    if (num > m) res -= (num - m) * mval; // m個からはみ出し

    cout << res << endl;
}

Measured memory_bytes: 4844
#include <iostream>
#include <vector>
#define llint long long
#define mod 1000000007

using namespace std;

int n;
vector<int> G[100005];
llint dp[100005][2];

void dfs(llint v, llint pre)
{
	dp[v][0] = dp[v][1] = 1;
	for(int i = 0; i < G[v].size(); i++){
		if(G[v][i] != pre) dfs(G[v][i], v);
	}
	
	for(int i = 0; i < G[v].size(); i++){
		if(G[v][i] == pre) continue;
		dp[v][0] *= (dp[G[v][i]][0] + dp[G[v][i]][1])%mod, dp[v][0] %= mod;
	}
	for(int i = 0; i < G[v].size(); i++){
		if(G[v][i] == pre) continue;
		dp[v][1] *= dp[G[v][i]][0], dp[v][1] %= mod;
	}
}

int main(void)
{
	cin >> n;
	int u, v;
	for(int i = 0; i< n-1; i++){
		cin >> u >> v;
		G[u].push_back(v);
		G[v].push_back(u);
	}
	
	dfs(1, -1);
	cout << (dp[1][0] + dp[1][1])%mod << endl;
	return 0;
}

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

int main() {

  long int a,b,c,d;
  cin>>a>>b>>c;
  
  if(a>=c)
    cout<<a-c<<" "<<b<<endl;
  else if(a<c&&c-a<=b)
    cout<<0<<" "<<b+a-c<<endl;
  else
    cout<<0<<" "<<0<<endl;
  
  
  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
using namespace std;
const int N = 2e5 + 100;
int n;
void nhap()
{
    cin >> n;
}
int Get(int X) {
    int Res = 0;
    while (X) {
        Res += X % 10;
        X /= 10;
    }
    return Res;
}
void solve()
{
    int Res = n;
    for (int i = 1; i < n; i++) {
        Res = min(Res,Get(i) + Get(n - i));
    }
    cout << Res;
}
int main()
{
    nhap();
    solve();
}


Measured memory_bytes: 256
require 'prime'
s = gets.split.map { |i| i.to_i }
ans = 1
prime_num =  Prime.prime_division(s[1])
prime_num.each do |num|
	if num[1] / s[0] >= 1
		ans *= num[0] ** (num[1]/s[0])
	end
end

puts ans

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

using namespace std;

#define INF 100000000
#define YJ 1145141919
#define INF_INT_MAX 2147483647
#define INF_LL 9223372036854775
#define INF_LL_MAX 9223372036854775807
#define EPS 1e-10
#define MOD 1000000007
#define MOD9 998244353
#define Pi acos(-1)
#define LL long long
#define ULL unsigned long long
#define LD long double

#define int long long

using II = pair<int, int>;

int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a * b / gcd(a, b); }
int extgcd(int a, int b, int &x, int &y) { int g = a; x = 1; y = 0; if (b != 0) g = extgcd(b, a % b, y, x), y -= (a / b) * x; return g; }

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(a)  begin((a)), end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())

string S = "1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51";

signed main()
{
  int K;
  cin >> K;
  int ans = 0;
  int k = 1;
  REP(n,S.size()) {
    if (S[n] == ' ') continue;
    if('0' <= S[n] && S[n] <= '9') {
      ans *= 10;
      ans += S[n] - '0';
    } else if(S[n] == ',') {
      if (k == K) {
        cout << ans << endl;
        return 0;
      } else {
        k++;
        ans = 0;
      }
    }
  }

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a) for(int i=0;i<int(a);++i)
#define REP(i,a,b) for(int i=int(a);i<int(b);++i)
using ll = long long;
using itn = int;
using namespace std;
int GCD(int a, int b){
    return b ? GCD(b, a%b) : a;
}
int main() {
	int n;
	cin >> n;
	ll a[n];
	int odd=0,even=0;
	for(int i=0; i<n; i++){
		cin >> a[i];
	}
	for(int i=0; i<n; i++){
		if(a[i]%2) odd++;
		else even++;
	}
	if(odd%2==0) cout << "YES" <<endl;
	else cout << "NO" << endl;
	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
const int MAX_N = 100010;

int N;
vector<int> h;

int dp[MAX_N];

int Solve(int pos)
{
    if (dp[pos] >= 0) return dp[pos];

    if (pos == N - 1) return 0;
    if (pos >= N) return inf;

    return dp[pos] = min(abs(h[pos] - h[pos + 1]) + Solve(pos + 1), abs(h[pos] - h[pos + 2]) + Solve(pos + 2));
}

void _main()
{
    cin >> N;
    h.resize(N);
    rep(i, 0, N) cin >> h[i];
    memset(dp, -1, sizeof(dp));
    cout << Solve(0) << endl;
}


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

using namespace std;

#define sz(x) ((int) ((x).size()))
typedef long long ll;
typedef long double ld;

const int inf = 1 << 25;

string s;
int dp[300000][2];

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(10);
  cin >> s;
  int n = sz(s);
  if (n == 1) {
    cout << 1 << "\n";
    return 0;
  }
  dp[0][0] = 1, dp[0][1] = -inf;
  dp[1][1] = 1, dp[1][0] = (s[0] != s[1] ? 2 : -inf);
  for (int i = 2; i < n; i++) {
    for (int j = 0; j < 2; j++) {
      dp[i][j] = -inf;
      for (int k = 0; k < 2; k++)
        if (i - j - 1 - k >= 0 && (j != k || s[i] != s[i - j - 1] || (j == 1 && s[i - 1] != s[i - j - 2])))
          dp[i][j] = max(dp[i][j], dp[i - j - 1][k] + 1);
    }
  }
  cout << max(dp[n - 1][0], dp[n - 1][1]) << "\n";
}


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

int main(){
  int x1, x2, x3, x4, x5;
  cin >> x1 >> x2 >> x3 >> x4 >> x5;
  int ans = 0;
  if(x1 == 0) ans = 1;
  if(x2 == 0) ans = 2;
  if(x3 == 0) ans = 3;
  if(x4 == 0) ans = 4;
  if(x5 == 0) ans = 5;
  
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3548
#include<stdio.h>

int main() {
  int H, W, i, j;

  while (1) {
    scanf("%d %d", &H, &W);

    if (H == 0 && W == 0) {
      return 0;
    }
    
    for (i = 0; i < H; i++) {
      for (j = 0; j < W; j++) {
        printf ("#");
      }
      printf ("\n");
    }
    printf ("\n");
  }
  return 0;
}


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

typedef long long ll;
const ll mod = 1e9 + 7;
const int N=2000000;
const int M=2000;

void Run()
{
     ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
}
int main()
{
    Run();
    int a,b,c,k;
    cin>>a>>b>>c>>k;
    while(b<=a&&k)
    {
        b*=2;
        k--;
    }
    while(c<=b&&k)
    {
        c*=2;
        k--;
    }
    if(a<b&&b<c)
        cout<<"Yes";
    else
        cout<<"No";
}


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

using namespace std;

int main() {
#ifdef _DEBUG
	freopen("_in" , "r", stdin );
	freopen("_out", "w", stdout);
#endif
	int n; cin >> n;
	int s = 0;
	vector<int> a(n);
	for (int i = 0; i < n; i++) cin >> a[i];
	for (int i = 0; i < n - 1; i++)
	for (int j = i + 1; j < n; j++) {
		s += a[i] * a[j];
	}
	cout << s << '\n';
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a) for(int i=0;i<(int)(a);i++)
#define all(a) (a).begin(),(a).end()
#define pb push_back
#define sz size()
using namespace std;
typedef vector<int> vi;

const int INF = 1e9;

struct edge{
  int from,to,cost,cap,rev;
  edge(int a,int b,int c,int d,int e)
    :from(a),to(b),cost(c),cap(d),rev(e){}
};

struct FordFulkerson{
  int n;
  vector< vector<edge> > graph;
  vi use;

  FordFulkerson(int a=0):n(a){
    graph.resize(a); use.resize(a);
  }

  void init_use(void){fill(all(use),0);}

  void AddEdge(int s,int g,int c,int p){
    graph[s].pb( edge(s,g,c,p,graph[g].sz) );
    graph[g].pb( edge(g,s,-c,0,graph[s].sz-1) );
  }

  void DeleteEdge(int s, int g){
    int id = -1, rev = -1;
    rep(e,graph[s].sz){
      if(graph[s][e].to == g && graph[s][e].cost>0){
	id = e; rev = graph[s][e].rev;
      }
    }
    if(id<0)return;

    swap(graph[s][id],graph[s].back());
    swap(graph[g][rev],graph[g].back());

    edge e = graph[s][id];
    if(id+1!=(int)graph[s].size())graph[e.to][e.rev].rev = id;
    e = graph[g][rev];
    if(rev+1!=(int)graph[g].size())graph[e.to][e.rev].rev = rev;
    graph[s].pop_back(); graph[g].pop_back();
  }
  
  int dfs(int v, int t, int f){
    if(v==t)return f;
    use[v] = 1;
    rep(i,graph[v].sz){
      edge &e = graph[v][i];
      if(!use[e.to] && e.cap > 0){
	int d = dfs(e.to,t,min(f,e.cap));
	if(d > 0){
	  e.cap -= d;
	  graph[e.to][e.rev].cap += d;
	  return d;
	}
      }
    }
    return 0;
  }
  
  int max_flow(int s, int t){
    int res = 0;
    for(;;){
      init_use();
      int f = dfs(s,t,INF);
      if(!f)return res;
      res += f;
    }
  }
};

int main(){
  int n,E,q;
  cin >> n >> E >> q;
  FordFulkerson mf(n);
  rep(i,E){
    int f,t;
    cin >> f >> t; f--; t--;
    mf.AddEdge(f,t,1,1);
    mf.AddEdge(t,f,1,1);
  }

  int F = mf.max_flow(0,n-1);
  rep(i,q){
    int m,a,b;
    cin >> m >> a >> b; a--; b--;
    if(m==1){
      mf.AddEdge(a,b,1,1);
      mf.AddEdge(b,a,1,1);
      F += mf.max_flow(0,n-1);
    }else{
      int use = 0;
      for(edge e : mf.graph[a]){
	if(e.to == b && e.cost>0 && e.cap == 0)use |= 1;
      }
      for(edge e : mf.graph[b]){
	if(e.to == a && e.cost>0 && e.cap == 0)use |= 2;
      }
      mf.DeleteEdge(a,b);
      mf.DeleteEdge(b,a);

      if(use==1 || use==2){
	rep(i,n)mf.use[i] = 0;
	int another = 0;
	if(use==1)another = mf.dfs(a,b,1);
	if(use==2)another = mf.dfs(b,a,1);

	if(!another){
	  mf.init_use();
	  mf.dfs(use==1?a:b,0,1);
	  mf.init_use();
	  mf.dfs(n-1,use==1?b:a,1);
	  F--;
	}
      }
    }

    cout << F << endl;
  }
}

Measured memory_bytes: 3388
#include <algorithm>
#include <vector>
#include <iostream>

typedef std::vector<int> TTree;
struct TPath
{
    int Id1;
    int Id2;
    int Cost;
    TPath(int AId1, int AId2, int ACost)
     : Id1(AId1), Id2(AId2), Cost(ACost)
    {}
};
bool Compare(const TPath& Left, const TPath& Right)
{
    if(Left.Cost  < 0) return false;
    if(Right.Cost < 0) return true;
    return Left.Cost < Right.Cost;
}


int main()
{
    int n;
    std::cin >> n;
    std::vector<TTree*> Table(n, NULL);
    for(std::size_t i = 0; i < n; ++i){
        Table[i] = new std::vector<int>(1, i);
    }
    std::vector<TPath> PathList;
    PathList.reserve(n*n);
    
    for(int i = 0; i < n; ++i){
        for(int j = 0; j < n; ++j){
            int Cost;
            std::cin >> Cost;
            PathList.push_back(TPath(i, j, Cost));
        }
    }
    std::sort(PathList.begin(), PathList.end(), Compare);
    
    int Total = 0;
    for(std::vector<TPath>::const_iterator It = PathList.begin();
        It != PathList.end(); ++It)
    {
        const TPath& Path = *It;
        TTree* Tree1 = Table[Path.Id1];
        TTree* Tree2 = Table[Path.Id2];
        if(Tree1 == Tree2){
            continue;
        }
        Tree1->insert(Tree1->end(), Tree2->begin(), Tree2->end());
        for(std::size_t j = 0; j < Tree2->size(); ++j){
            int Id = (*Tree2)[j];
            Table[Id] = Tree1;
        }
        delete Tree2;
        Total += Path.Cost;
        // std::cout << "[" << Path.Id1 << "]" << "[" << Path.Id2 << "] = " << Path.Cost << std::endl;
    }
    std::cout << Total << std::endl;
    return 0;
}

Measured memory_bytes: 3256
from collections import Counter

N = int(input())
D = Counter(list(map(int, input().split())))
M = int(input())
T = Counter(list(map(int, input().split())))

flag = True

for t, num in T.items():
    # print(t, num)
    if D[t] < num:
        flag = False
if flag:
    print("YES")
else:
    print("NO")


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

using namespace std;


int main() {




  int a,b,c,d;
  cin >> a>>b>>c>>d;

  while(true){
    c -= b;
    if(c <= 0){
      cout << "Yes" << endl;
      return 0;
    }
    a -= d;
    if(a <= 0){
      cout << "No" << endl;
      return 0;
    }
  }
  
 
  
  return 0;
}



Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
const ll inf = numeric_limits<ll>::max()/3;

int main(void){
  int a,b;
  cin >> a >> b;
  if(a == b){
    puts("Draw");
  }else if(a == 1){
    puts("Alice");
  }else if(b == 1){
    puts("Bob");
  }else if(a > b){
    puts("Alice");
  }else{
    puts("Bob");
  }
  return 0;
}



Measured memory_bytes: 384
#include<complex>
#include<cmath>
#include<iostream>
#include<cstdio>
#define EPF 1e-10
#define PI 3.14159265358979323846264338
using namespace std;

typedef complex<double> P;

int main(){
  int n,ans;
  double x,y;
  while(cin >> n && n){
    P inf[n];
    ans = 1;
    for(int i=0;i<n;i++){
      scanf("%lf,%lf",&x,&y);
      inf[i] = P(x,y);
    }

    int cnt;
    for(int i=0;i<n;i++){
      for(int j=0;j<n;j++){
	if(abs(inf[i]-inf[j]) >= 2.0+EPF)continue;
	double MD = sqrt(1-0.25*norm(inf[i]-inf[j]));
	P mid = (inf[i]+inf[j])*0.5;
	P p1 = mid + (inf[i]-inf[j])/abs(inf[i]-inf[j])*polar(MD,M_PI/2);
	P p2 = mid + (inf[i]-inf[j])/abs(inf[i]-inf[j])*polar(MD,-M_PI/2);
	cnt = 0;
	for(int k=0;k<n;k++)if(abs(p1-inf[k]) < EPF+1.0)cnt++;
	
	ans = ans<cnt?cnt:ans;
	cnt = 0;
	for(int k=0;k<n;k++)if(abs(p2-inf[k]) < EPF + 1.0)cnt++;
	ans = ans<cnt?cnt:ans;
      }
    }
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 976
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi std::vector<std::vector<int> >
#define vvl std::vector<std::vector<ll> >
#define MODs 1000000007;
typedef long long int ll;
using namespace std;

vvi G = vv(100001, 0, 0, int);
int dfs(int from, int now){
  int ret = 0;
  if((from==-1&&G[now].size()==1)||(from!=-1&&G[now].size()==2)){
    for(int i=0;i<G[now].size();i++){
      if(G[now][i]==from) continue;
      ret = dfs(now, G[now][i]) + 1;
    }
  }
  else{
    for(int i=0;i<G[now].size();i++){
      if(from==G[now][i]) continue;
      ret ^= (dfs(now, G[now][i])+1);
    }
  }
  return ret;
}
int main(int argc, char const *argv[]) {
  int N, a, b;
  std::cin >> N;
  for(int i=0;i<N-1;i++){
    std::cin >> a >> b;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  std::cout << (dfs(-1, 1)==0?"Bob":"Alice")<< '\n';
  return 0;
}


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

using namespace std;

#define forn(i, n) for (ll i = 0; i < (ll) (n); ++i)
#define sz(a) static_cast<int>((a).size())
#define pb emplace_back
#define mp make_pair
#define endl '\n'
#define f first
#define s second

#ifdef SEREZHKA
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define dbg(...)
#endif

template<typename T>
void _dbg(const char* _s, T _h) { cerr << _s << " = " << _h << "\n"; }

template<typename T, typename... Ts>
void _dbg(const char*_s, T _h, Ts... _t) {
    int _b = 0;
    
    while (((_b += *_s == '(') -= *_s == ')') != 0 || *_s != ',')
        cerr << *_s++;
    
    cerr << " = " << _h << ",";
    _dbg(_s + 1, _t...);
}

using ll = long long;

const ll INF = static_cast<ll>(1e9) + 7ll;
const ll LINF = INF * INF;
const int MAXN = static_cast<int>(2e4) + 17;

int n, d;
string s;
ll dp[MAXN][101][2];

bool read() {
    if (!(cin >> s >> d))
        return false;

    return true;
}

ll add(ll a, ll b) { return (a += b) >= INF ? a - INF : a; }

void solve() {
    n = sz(s);
    s = "0" + s;
    dp[0][0][1] = 1;

    for (int i = 0; i < n; ++i)
        for (int nc = 0; nc < 10; ++nc)
            for (int j = 0; j < d; ++j) {
                dp[i + 1][(j + nc) % d][0] = add(dp[i + 1][(j + nc) % d][0], dp[i][j][0]);

                if (nc < s[i + 1] - '0')
                    dp[i + 1][(j + nc) % d][0] = add(dp[i + 1][(j + nc) % d][0], dp[i][j][1]);

                if (nc == s[i + 1] - '0')
                    dp[i + 1][(j + nc) % d][1] = add(dp[i + 1][(j + nc) % d][1], dp[i][j][1]);
            }

    ll res = dp[n][0][0] + dp[n][0][1] - 1;
    res = (res % INF + INF) % INF;
    cout << res << endl;
}

int main() {
    cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    
#ifdef SEREZHKA
    freopen("file.in", "r", stdin);
#endif
    
    while (read())
        solve();
    
    return 0;
}



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

int main() {
  int N;
  cin >> N;
  vector<int> a(N);
  for(int i=0;i<N;i++){
    cin >> a.at(i);
  }
  sort(a.begin(),a.end(),greater<int>());
  int alice=0,bob=0;
  for(int i=0;i<N;i++){
    if(i%2==0){
      alice += a.at(i);
    }
    else{
      bob += a.at(i);
    }
  }
  cout << alice - bob << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main(){
    int A, B, C;
    scanf("%d%d%d", &A, &B, &C);
    if(A==B){
        if(B!=C)
            printf("Yes\n");
        else
            printf("No\n");
    }
    else if(B==C){
        if(A!=C)
            printf("Yes\n");
        else
            printf("No\n");
    }
    else if(A==C){
        if(A!=B)
                printf("Yes\n");
        else
            printf("No\n");
    }
    else
        printf("No\n");

return 0;
}


Measured memory_bytes: 128
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
using namespace std;

const int Maxn = 1e9+7;
long long t[109];

long long slove (long long x, long long y)
{
	long long  a,b;
	a = x,b = y;
	long long c;
	while (b != 0)
	{
		c = a%b;
		a = b;
		b = c;
	}
	long long k = x/a*y;
	return k;
}

int main ()
{
	int n;
	scanf("%d",&n);
	for (int i = 1; i <= n; i++)
		scanf("%lld",&t[i]);
		if (n == 1){
			printf("%lld",t[1]);
			return 0;
			}
	long long s;
	s = slove(t[1],t[2]);
	for (int i = 3; i <= n; i++)
		s = slove(s,t[i]);
		printf("%lld",s);
	return 0;
}

Measured memory_bytes: 128
#if 0
2020.03.18

将 prufer 序列推广到环套树上，
那么一个环套树可以一一对应到以下要素：
一个确定的环和一个任意的 prufer 序列和一个钦定的环上的关键点。
其中非环上的点在序列中出现 d - 1 次，环上非关键点出现 d - 2 次，关键点出现 d - 3 次。
（事实上这个关键点少了一次就是因为要原本钦定它在 prufer 序列最后一个）
通过 DP 计数，设 f[i][j][0/1] 表示考虑前 i 个点，选了 j 个环上的点，是否选了关键点的情况。
#endif
#include <cstdio>
#include <algorithm>
#define debug(...) fprintf(stderr, __VA_ARGS__)

typedef long long ll;
struct {
	inline operator int () { int x; return scanf("%d", &x), x; }
	inline operator ll () { ll x; return scanf("%lld", &x), x; }
} read;

const int maxn = 5050, mod = 1000000007;
int deg[maxn];
ll fac[maxn], ifac[maxn];
ll f[2][maxn][2];

ll power(ll x, int k) {
	if(k < 0) k += mod - 1;
	ll res = 1;
	while(k) {
		if(k & 1) (res *= x) %= mod;
		(x *= x) %= mod;
		k >>= 1;
	}
	return res;
}

int main() {
	int n = read;
	for(int i = 1; i <= n; i ++)
		deg[i] = read;

	fac[0] = 1;
	for(int i = 1; i <= n; i ++)
		fac[i] = fac[i - 1] * i % mod;
	ifac[n] = power(fac[n], -1);
	for(int i = n; i; i --)
		ifac[i - 1] = ifac[i] * i % mod;

	f[0][0][0] = 1;
	for(int i = 1; i <= n; i ++) {
		int o = i & 1;
		for(int j = 0; j <= i; j ++)
			f[o][j][0] = f[o][j][1] = 0;
		for(int j = 0; j < i; j ++)
			for(int p = 0; p < 2; p ++) {
				ll x = f[!o][j][p];
				if(deg[i] >= 1)
					f[o][j][p] += x * ifac[deg[i] - 1];
				if(deg[i] >= 2)
					f[o][j + 1][p] += x * ifac[deg[i] - 2];
				if(deg[i] >= 3 and !p)
					f[o][j + 1][1] += x * ifac[deg[i] - 3];
			}
		for(int j = 0; j <= i; j ++)
			f[o][j][0] %= mod, f[o][j][1] %= mod;
	}

	ll ans = f[n & 1][n][0] * fac[n - 1] % mod * ifac[2] % mod;
	for(int k = 3; k < n; k ++)
		(ans += f[n & 1][k][1] * fac[n - k - 1] % mod *
		 fac[k - 1] % mod * ifac[2]) %= mod;
	printf("%lld\n", ans);
}


Measured memory_bytes: 128
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<map>
#include<iostream>
using namespace std;
#define rep(i,n) for(int i=0;i<((int)(n));i++)
#define reg(i,a,b) for(int i=((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i=((int)(n))-1;i>=0;i--)
#define ireg(i,a,b) for(int i=((int)(b));i>=((int)(a));i--)
typedef long long int lli;
typedef pair<int,int> mp;
#define fir first
#define sec second
#define IINF INT_MAX
#define LINF LLONG_MAX
#define eprintf(...) fprintf(stderr,__VA_ARGS__)
#define pque(type) priority_queue<type,vector<type>,greater<type> >
#define memst(a,b) memset(a,b,sizeof(a))
#define iter(v,ite) for(auto ite=(v).begin();ite!=(v).end();ite++)
#define mimunum(v,x) distance((v).begin(),lower_bound((v).begin(),(v).end(),x))

char s[200005];

int dp[1<<26];

int main(void){
	memset(dp,-1,sizeof(dp));
	scanf("%s",s);
	int ls=strlen(s);
	dp[0]=0;
	int np=0;
	rep(i,ls){
		np ^= (1<<(s[i]-'a'));
		int na=dp[np];
		rep(j,26){
			int tp=np ^ (1<<j);
			if(dp[tp]>=0 && (na<0 || dp[tp]<na)){
				na=dp[tp];
			}
		}
		if(na>=0){
			if(dp[np]<0 || na+1<dp[np])dp[np]=na+1;
		}
		//printf("%d %d\n",np,na);
	}
	
	printf("%d\n",max(dp[np],1));
	return 0;
}






Measured memory_bytes: 262656