akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
using namespace std;

#define FAST ios_base::sync_with_stdio(false); cin.tie(0);
#define pb push_back
#define eb emplace_back
#define ins insert
#define f first
#define s second
#define cbr cerr<<"hi\n"
#define mmst(x, v) memset((x), v, sizeof ((x)))
#define siz(x) ll(x.size())
#define all(x) (x).begin(), (x).end()
#define lbd(x,y) (lower_bound(all(x),y)-x.begin())
#define ubd(x,y) (upper_bound(all(x),y)-x.begin())
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());    //can be used by calling rng() or shuffle(A, A+n, rng)
inline long long rand(long long x, long long y) { return rng() % (y+1-x) + x; } //inclusivesss
string inline to_string(char c) {string s(1,c);return s;} template<typename T> inline T gcd(T a,T b){ return a==0?llabs(b):gcd(b%a,a); }

using ll=long long; 
using ld=long double;
#define FOR(i,s,e) for(ll i=s;i<=ll(e);++i)
#define DEC(i,s,e) for(ll i=s;i>=ll(e);--i)
using pi=pair<ll,ll>; using spi=pair<ll,pi>; using dpi=pair<pi,pi>; 

#define LLINF ((long long)1e18)
#define INF int(1e9+1e6)
#define MAXN (500006)
ll n,m,f[MAXN],inv[MAXN],mod=1e9+7;
int main(){
	auto qexp=[&](ll x,ll e){ll sum=1;for(;e;e>>=1,x*=x,x%=mod)if(e&1)sum*=x,sum%=mod;return sum;};
	FAST
	cin>>n>>m;
	f[0]=inv[0]=1;
	FOR(i,1,MAXN-1)f[i]=f[i-1]*i%mod, inv[i]=qexp(f[i],mod-2);
	auto C=[&](ll n,ll k){
		return n < k ? 0 : f[n] * inv[k] % mod * inv[n-k] % mod;
	};
	auto P=[&](ll n,ll k){
		return n < k ? 0 : f[n] * inv[n-k] % mod;
	};
	ll ans = 0;
	FOR(i,0,n){
		// i positions same
		ll sign = (i&1) ? -1 : 1;
		ans += C(n, i) * P(m, i) % mod * P(m-i, n-i) % mod * P(m-i, n-i) % mod * sign;
		ans += mod;
		ans %= mod;
	}
	cout<<ans<<'\n';
}


Measured memory_bytes: 11424
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <stdio.h>
using namespace std;
#define int long long
int MOD = 1000000007;
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N, K;
	cin >> N >> K;
	vector<int> A(N);
	int res = 0;
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}
	int INF = (int)1 << 60;
	vector<int> dp(N, INF);
	dp[0] = 0;
	for (int i = 0; i < N; i++) {
		for (int j = 1; j <= K; j++) {
			if (i + j < N)dp[i + j] = min(dp[i + j], dp[i] + abs(A[i] - A[i + j]));
		}
	}
	cout << dp.back() << endl;
}

Measured memory_bytes: 1792
using System;
using System.Collections.Generic;
using System.Linq;

namespace CSharp
{
    class Program
    {
        static void Main(string[] args)
        {
            var inputs = Console.ReadLine()
                .Split(' ')
                .Select(s => int.Parse(s))
                .ToArray();
            var n = inputs[0];
            var a = inputs[1];
            var b = inputs[2];
            var train = n * a;
            var taxi = b;
            Console.WriteLine(Math.Min(train, taxi));
        }
    }
}


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

typedef long long ll;
typedef long double ld;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

#define f first
#define s second
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define pb push_back

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define F0R(i, a) FOR(i, 0, a)
#define ROF(i, a, b) for (int i = (b); i >= (a); i--)
#define R0F(i, a) ROF(i, 0, a-1)
#define trav(x, a) for (auto& x: a)

const int MX  = 2e5+5;
const int MOD = 1e9+7;
const ll  INF = 1061109567; // 4557430888798830399LL
const ld  EPS = 1e-9;
const ld  PI  = acos(-1);

int main() {

    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    char x;

    while(cin >> x) {
        if (x == ',') cout << " ";
        else cout << x;
    }

}


Measured memory_bytes: 256
import java.io.*;

class Main{
	public static void main(String[] args)throws IOException{
		InputStreamReader isr = new InputStreamReader(System.in);
		BufferedReader br = new BufferedReader(isr);
		String str;
		str = br.readLine();
		int n = Integer.parseInt(br.readLine());
		char[] arr = str.toCharArray();
		for(int i=0;i<str.length();i++){
			if(i!=str.length()-1){
				if(str.charAt(i)!='a' && n>=(26-(str.charAt(i)-'a'))){
					arr[i] = 'a';
					n-=(26-(str.charAt(i)-'a'));
				}
			}else{
				n%=26;
				arr[i] = (char)((int)'a'+(((int)str.charAt(i)-'a'+n)%26));
			}
		}
		System.out.println(String.valueOf(arr));
	}
}

Measured memory_bytes: 11476
package main

import (
	"bufio"
	"container/heap"
	"fmt"
	"os"
	"strconv"
)

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

func scanString() string   { sc.Scan(); return sc.Text() }
func scanRunes() []rune    { return []rune(scanString()) }
func scanInt() int         { a, _ := strconv.Atoi(scanString()); return a }
func scanInt64() int64     { a, _ := strconv.ParseInt(scanString(), 10, 64); return a }
func scanFloat64() float64 { a, _ := strconv.ParseFloat(scanString(), 64); return a }

func scanInts(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = scanInt()
	}
	return res
}

func debug(a ...interface{}) { fmt.Fprintln(os.Stderr, a...) }

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}
func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

//•*¨*•.¸¸♪main•*¨*•.¸¸♪(　-ω-)ノ　(　・ω・)
func main() {
	defer wr.Flush()
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 10000), 1001001)

	q := scanInt()

	pq0 := priorityQueue0{}
	pq1 := priorityQueue1{}
	heap.Init(&pq0)
	heap.Init(&pq1)

	ans := 0
	_ = scanInt()
	mid := scanInt()
	heap.Push(&pq0, mid)
	b := scanInt()
	c := 1

	for i := 0; i < q-1; i++ {
		query := scanInt()
		if query == 1 {
			a := scanInt()
			b += scanInt()
			c++

			if mid < a {
				heap.Push(&pq1, a)
			} else {
				heap.Push(&pq0, a)
			}

			if len(pq0) < len(pq1) {
				heap.Push(&pq0, heap.Pop(&pq1).(int))
			}

			if len(pq0) > len(pq1)+1 {
				heap.Push(&pq1, heap.Pop(&pq0).(int))
			}

			now := heap.Pop(&pq0).(int)
			heap.Push(&pq0, now)

			if c&1 == 0 {
				ans += abs(mid - now)
			}
			mid = now

			ans += abs(mid - a)

		} else {
			fmt.Fprintln(wr, mid, ans+b)
		}
	}

}

type priorityQueue0 []int

func (pq priorityQueue0) Len() int            { return len(pq) }
func (pq priorityQueue0) Swap(i, j int)       { pq[i], pq[j] = pq[j], pq[i] }
func (pq priorityQueue0) Less(i, j int) bool  { return pq[i] > pq[j] }
func (pq *priorityQueue0) Push(x interface{}) { *pq = append(*pq, x.(int)) }
func (pq *priorityQueue0) Pop() interface{} {
	res := (*pq)[len(*pq)-1]
	*pq = (*pq)[0 : len(*pq)-1]
	return res
}

type priorityQueue1 []int

func (pq priorityQueue1) Len() int            { return len(pq) }
func (pq priorityQueue1) Swap(i, j int)       { pq[i], pq[j] = pq[j], pq[i] }
func (pq priorityQueue1) Less(i, j int) bool  { return pq[i] < pq[j] }
func (pq *priorityQueue1) Push(x interface{}) { *pq = append(*pq, x.(int)) }
func (pq *priorityQueue1) Pop() interface{} {
	res := (*pq)[len(*pq)-1]
	*pq = (*pq)[0 : len(*pq)-1]
	return res
}


Measured memory_bytes: 8064
#include<bits/stdc++.h>
#define lld long long int
#define ld long double
#define mod 1000000007
#define MAX 100000
#define INF 1e9
#define EPS -1e9
using namespace std;

/*lld fastexp(lld a,lld b)
{
	lld ans = 1;
	while(b>0)
	{
		if(b%2==1)
		{
			ans = (ans*a)%mod;
		}
		a = (a*a)%mod;
		b/=2;
	}
	return ans%mod;
}*/

/*bool primes[MAX+1];
void seive()
{
	memset(primes,true,sizeof(primes));
	primes[0] = false;
	primes[1] = false;
	for(int p=2;p*p<=MAX;p++)
	{
		if(primes[p]==true)
		{
			for(int i=p*p;i<=MAX;i+=p)
			{
				primes[i] = false;
			}
		}
	}
	return;
}*/

/*lld fact(int n)
{
	int ans = 1;
	for(int i=2;i<=n;i++)
	{
		ans = ans*i;
	}
	return ans;
}*/

int main()
{
	//seive();
    ld r;
    cin >> r;
    ld pi = (ld)22/7;
    cout << fixed << setprecision(10) << (ld)2*pi*r << "\n";
	return 0;
}

Measured memory_bytes: 3780
#include <iostream>
#include <string>
using namespace std;
int main()
{
    string s,t;
    bool boolean=true;
    cin>>s>>t;
    int len = s.size();
    int sizet=t.size();
    for(int i=0;i<len;i++)
    {
        if(s[i]!=t[i])
        {
            boolean = false;
        }
    }
    if(boolean&&(sizet-len==1))
    {
        cout<<"Yes\n";
    }
    else
    {
        
        cout<<"No";
    }
    
}

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

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

  ans=(n/(a+b))*a;
  long long tmp=n%(a+b);
  //cout << "[" << ans << "," << tmp << endl;
  if(a>tmp)ans+=tmp;
  else ans+=a;

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


Measured memory_bytes: 256
#include <iostream>
#include <set>
#include <algorithm>
using namespace std;


int main() {
	string s;
	cin >> s;
	set<char> st(s.begin(), s.end());

	char c = 'a';
	while (find(st.begin(), st.end(), c) != st.end()) {
		c++;
	}
	
	if ('a' <= c && c <= 'z') cout << c << endl;
	else cout << "None" << endl;
	return 0;
}


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

vector<ll>par(2e5+10);
vector<ll>wei(2e5+10);
void init(ll n) {
  for(ll i=0;i<n;i++) {
    par[i]=i;
  }
}

ll root(ll x) {
  if(par[x]==x) {
    return x;
  }
  else {
    ll r=root(par[x]);
    wei[x]+=wei[par[x]];
    return par[x]=r;
  }
}

ll weight(ll x) {
  root(x);
  return wei[x];
}

bool same(ll x, ll y) {
  return root(x)==root(y);
}

void unite(ll x, ll y, ll w) {
  if(same(x,y)) return;
  w=weight(x)+w-weight(y);
  x=root(x);
  y=root(y);
  par[y]=x;
  wei[y]=w;
}

ll diff(ll x, ll y) {
  return weight(y)-weight(x);
}

int main() {
  ll n,m;
  cin >> n >> m;
  init(n);
  for(ll i=0;i<m;i++) {
    ll x,y,w;
    cin >> x >> y >> w;
    x--;
    y--;
    if(same(x,y)) {
      if(diff(x,y)!=w) {
        cout << "No" << endl;
        return 0;
      }
    }
    else {
      unite(x,y,w);
    }
  }
  cout << "Yes" << endl;
}

Measured memory_bytes: 3328
sub min {
    return $_[0] > $_[1] ? $_[1] : $_[0];
}

($A, $B, $K) = glob <>;
$n = min($A, $K);
$A -= $n;
$K -= $n;
$n = min($B, $K);
$B -= $n;
$K -= $n;
print $A. " " . $B;

Measured memory_bytes: 5264
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int K,A,B;
  cin >> K >> A >> B;
  int C=A;
  for (int i=0; i<B-A+1; i++) {
    if (C%K==0) {
      cout << "OK" <<endl;
      break;
    }
    if ((C%K!=0)&&(i==B-A)) {
      cout << "NG" << endl;
    }
    else {
      C++;
    }
  }
}

Measured memory_bytes: 3648
#include <stdio.h>
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>

using ll = long long int;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

int k,a[100100],ans=0,d[100100];
std::vector<int> g[100100];

int dfs(int u){
	int i,v;
	d[u] = 0;
	for(i=(g[u].l_ength()-1); i>=0; --i){
		v = g[u][i];
		d[u] = std::max(d[u],dfs(v));
	}
	if(a[u] && d[u]==k){
		++ans;
		return 0;
	}
	return d[u]+1;
}

int main(void){
	int n,i,j;
	std::cin >> n >> k; --k;
	for(i=0; i<n; ++i){
		std::cin >> a[i]; --a[i];
	}
	if(a[0]){
		++ans; a[0] = 0;
	}
	for(i=1; i<n; ++i){
		g[a[i]].push_back(i);
	}
	dfs(0);
	std::cout << ans << std::endl;
	return 0;
}


Measured memory_bytes: 11136
#include <cstdio>
#include <cstring>

#define M 1046527
#define NIL (-1)
#define L 14

char  H[M][L];

 int getChar(char ch){
   if(ch=='A')return 1;
   else if(ch == 'C') return 2;
   else if(ch == 'G')return 3;
   else if(ch == 'T')return 4;
   else return 0;
 }

 long long getKey(char str[]){
   long long sum = 0,p=1,i;

   for(i=0;i<strlen(str);i++){
     sum +=p*(getChar(str[i]));
     p *= 5 ;
   }
   return sum;
 }

  int h1(int key){return key % M;}
  int h2(int key){return 1+ (key % (M-1));}

  int find(char str[]){
    long long key , i,h;
    key = getKey(str);
    for(i=0;;i++){
      h = (h1(key)+i*h2(key)) %M;
      if(strcmp(H[h],str)==0)return 1;
      else if (strlen(H[h])==0)return 0;
    }
    return 0;
  }

  int insert(char str[]){
    long long key,i,h;
    key = getKey(str);
    for(i=0; ; i++){
      h = (h1(key)+i*h2(key))% M;
      if (strcmp(H[h],str)==0)return 1;
      else if (strlen(H[h])==0){
        strcpy(H[h],str);
        return 0;
      }
    }
     return 0;
  }


int main(){
  int i,n;
  //int top = 0;
  char str[L],com[9];

  for(i=0;i<M;i++)H[i][0]='\0';
  scanf("%d",&n);

  for(i=0;i<n;i++){
    scanf("%s %s",com,str);
    if(com[0]=='i'){
      insert(str);
    }
    else{
      if(find(str)){
        printf("yes\n");
      }
      else{
        printf("no\n" );
      }
    }
  }
return 0;
}

Measured memory_bytes: 16964
using System;
using System.Linq;
class Program
{
    static void Main(string[] args)
    {
        int[] a = Console.ReadLine().Split().Select(int.Parse).ToArray();
        int A = a[0]*a[1];
        int B = a[2];
        if(A > B)
        {
            Console.WriteLine(B);
        }
        else
        {
            Console.WriteLine(A);
        }


    }
}

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

int main(){
  string s;
  cin>>s;
  int cnt =0;
  int ans=0;
  for(int i=0;i<s.size();i++){
    if(s.at(i)=='A'||s.at(i)=='C'||s.at(i)=='G'||s.at(i)=='T')
      cnt++;
    else
      cnt=0;
    if(cnt>ans)
      ans=cnt;
    }
  cout<<ans<<endl;
  }
      


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define zero_pad(num) setfill('0') << std::right << setw(num)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;

int main() {
    int a, b, x;
    cin >> a >> b >> x;
    if(a <= x && x <= a + b) cout << "YES" << endl;
    else cout << "NO" << endl; 
    
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int main() {
    int a, b;
    cin >> a >> b;
    
    cout << (a % 3 == 0 || b % 3 == 0 || (a+b) % 3 == 0 ? "Possible" : "Impossible") << endl;


    return 0;
}

Measured memory_bytes: 256
def readinput():
    n,m,x,y=map(int,input().split())
    xx=list(map(int,input().split()))
    yy=list(map(int,input().split()))
    return n,m,x,y,xx,yy

def main(n,m,x,y,xx,yy):
    xx.append(x)
    yy.append(y)
    xx.sort()
    yy.sort()
    if xx[-1]<yy[0]:
        return 'No War'
    else:
        return 'War'

if __name__=='__main__':
    n,m,x,y,xx,yy=readinput()
    ans=main(n,m,x,y,xx,yy)
    print(ans)


Measured memory_bytes: 9204
#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<int, int>;

int main() {
    int A,B,H,M;
    cin >> A >> B >> H >> M;

    double L = 30 * H + 0.5 * M;
    int S = 6 * M;
    double sita = abs(L - S);
    double C = sqrt((double)A*A + B*B - 2*A*B*cos((double)sita / 180 * acos(-1)));
    
    cout << fixed << setprecision(15) << C<< endl;
	return 0;
}


Measured memory_bytes: 4228
main :: IO ()
main = do
  (n:a:b:_) <- fmap (map read . words) getLine :: IO [Int]
  putStrLn . unwords . map show $ solve n a b

solve :: Int -> Int -> Int -> [Int]
solve n a b = [x, y]
  where
    x = min a b
    y = max 0 (a + b - n)

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

int main(){
    int T[101][101], r, c;
    
    cin >> r >> c;
    for(int i = 0; i < r; i++){
        for(int j = 0; j < c; j++) cin >> T[i][j];
    }
    
    for(int i = 0; i <= r; i++) T[i][c] = 0;
    for(int j = 0; j <= c; j++) T[r][j] = 0;
    
    for(int i = 0 ; i < r; i++){
        for(int j = 0; j < c; j++){
            T[i][c] += T[i][j];
            T[r][j] += T[i][j];
            T[r][c] += T[i][j];
        }
    }
    
    for(int i = 0; i <= r; i++){
        for(int j = 0; j <= c; j++){
            if(j) cout << " ";
            cout << T[i][j];
        }
        cout << endl;
    }
    
    return 0;
}


Measured memory_bytes: 3112
Option Strict On

Module Module1
    Dim T, A, B As Long


    Sub Main()
        Dim tmp() As Long = Array.ConvertAll(Of String, Long) _
            (Console.ReadLine().Split(), AddressOf Long.Parse)

        'let'
        T = tmp(0) : A = tmp(1) : B = tmp(2)

        Console.WriteLine(
            Math.Min(A * T, B)
        )

    End Sub

End Module

Measured memory_bytes: 11220
#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<int, int>;

int main() {
  ll n, a, b;
  cin >> n >> a >> b;
  cout << a * (n / (a + b)) + min(a, n % (a + b)) << endl;
  return 0;
}


Measured memory_bytes: 256
import qualified Data.ByteString.Char8 as BS
import Data.Function
import Data.List
import Data.Maybe
import Data.Ord

readInt = fst . fromJust . BS.readInt

readIntList = map readInt . BS.words

getIntList = readIntList <$> BS.getLine

prod = foldl1' (\x y -> mod1G7 (x * y))

mod1G7 n = n `mod` (10 ^ 9 + 7)

main :: IO ()
main = do
  [n, k] <- getIntList
  as <- getIntList
  if k == n
    then print $ prod as
    else
      if all (<= 0) as
        then
          if odd k
            then print $ prod (take k (sortBy (compare `on` Down) as))
            else print $ prod (take k (sort as))
        else do
          let as' = sortBy (comparing (\a -> (- (abs a)))) as
          let bs = take k as'
          if elem 0 bs
            then print 0
            else
              if even (length (filter (\x -> x < 0) bs))
                then print $ prod bs
                else do
                  let bsr = reverse bs
                  let asr = drop k as'
                  let bs' = filter (\b' -> b' < 0) bsr
                  let as'' = filter (\a -> a >= 0) asr
                  let c = if length as'' == 0 || length bs' == 0 then 0 else prod ((head as'') : (delete (head bs') bs))
                  let bs'' = filter (\b' -> b' > 0) bsr
                  let as''' = filter (\a -> a <= 0) asr
                  let c' = if length as''' == 0 || length bs'' == 0 then 0 else prod ((head as''') : (delete (head bs'') bs))
                  if c == 0 || c' == 0
                    then
                      if c == 0 && c' == 0
                        then print 0
                        else print $ maximum [c, c']
                    else do
                      if head as'' *  head bs'' > head as''' * head bs'
                        then print c
                        else print c'


Measured memory_bytes: 44376
use std::io::Read;

fn run() {
    let mut s = String::new();
    std::io::stdin().read_to_string(&mut s).unwrap();
    let mut it = s.trim().split_whitespace();
    it.next();
    let a: Vec<usize> = it.map(|s| s.parse().unwrap()).collect();
    for a in a {
        if a % 2 == 0 && (a % 3 != 0 && a % 5 != 0) {
            println!("DENIED");
            return;
        }
    }
    println!("APPROVED");
}

fn main() {
    run();
}

Measured memory_bytes: 4352
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <utility>
#include <numeric>

using namespace std;

using ll = long long;
using ull = unsigned long long;

const ll inf = (ll)1e9;
const ll mod = (ll)1e9 + 7;

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

	int n;
	cin >> n;

	vector<ll> b(n - 1);

	for (int i = 0; i < n - 1; i++)
	{
		cin >> b.at(i);
	}
	vector<ll> a(n);
	a.at(0) = b.at(0);

	ull sum = 0;
	for (int i = 1; i < n; i++)
	{
		a.at(i) = b.at(i - 1);
		sum += min(a.at(i - 1), a.at(i));
	}
	sum += a.at(n - 1);

	cout << sum << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <vector>
using namespace std;
typedef long long ll;
struct mob {
    int l, r, a, b;
    mob () {}
    mob (int l, int r, int a, int b) : l(l),r(r),a(a),b(b) {}
};
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a; }
ll lcm(ll a, ll b) { return a*b/gcd(a,b); }

vector<int> to[101];
mob mobs[101];
int n;

ll dfs(int id) {
    ll a=1, b=1;
    if (mobs[id].a) a=dfs(mobs[id].a);
    if (mobs[id].b) b=dfs(mobs[id].b);
    ll x=lcm(a*mobs[id].l, b*mobs[id].r);
    return x/mobs[id].r+x/mobs[id].l;
}

int main() {
    while (scanf("%d",&n)) {
        if (!n) break;
        for (int i=0; i<101; i++) {
            to[i].clear();
        }
        for (int i=1; i<=n; i++) {
            int l, r, a, b; scanf("%d%d%d%d",&l,&r,&a,&b);
            mobs[i]=mob(l,r,a,b);
            if (a) to[a].push_back(i);
            if (b) to[b].push_back(i);
        }
        ll res=0;
        for (int i=1; i<=n; i++) {
            if (to[i].size()==0) {
                res=dfs(i);
                break;
            }
        }
        printf("%lld\n",res);
    }
}

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

const int N = 55;

long long dp[N][N][N * N];

void solve() {
    int n, A;
    cin >> n >> A;
    vector<int> vt(n + 1);
    for (int i = 1; i <= n; i++)
        cin >> vt[i];

    dp[0][0][0] = 1;
    for (int i = 1; i <= n; i++) {
        for (int j = 0; j <= i - 1; j++) {
            for (int sum = 0; sum <= 50 * j; sum++) {
                dp[i][j][sum] += dp[i - 1][j][sum];
                dp[i][j + 1][sum + vt[i]] += dp[i - 1][j][sum];
            }
        }
    }
    long long ans = 0;
    for (int i = 1; i <= n; i++) {
        ans += dp[n][i][A * i];
    }
    cout << ans;
}

int main() {
    ios::sync_with_stdio(NULL), cin.tie(0), cout.tie(0);
    cout.setf(ios::fixed), cout.precision(20);
    solve();
    return 0;
}


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

int main()
{
    int A, B, K;
    cin >> A >> B >> K;

    int cnt = 0;

    int m = min(A, B);
    for (int i = m; i >= 1; i--)
    {
        if (A % i == 0 && B % i == 0)
            cnt++;
        if (cnt == K)
        {
            cout << i << endl;
            break;
        }
    }
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
//#define Fast ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long
typedef vector<int>Vl;
typedef pair<int,int>pii;
typedef vector<pii>Vll;
#define S second
#define F first
#define mp make_pair
#define ms(x,y) memset(x,y,sizeof(x))
#define pb push_back
#define sl(n) scanf("%lld",&n)
#define pl(n) printf("%lld",n)
#define sz(a) (int)(a).size()
const int mod=1e9+7;
const int maxn=1e3+2;

signed main()
{
	int n,k;
	sl(n);sl(k);
	int arr[n];
	for(int i=0;i<n;i++)sl(arr[i]);
	bool dp[k+1];
	ms(dp,false);
	for(int i=0;i<=k;i++){
		for(int j=0;j<n;j++){
	      if(i>=arr[j] && !dp[i-arr[j]])dp[i]=!dp[i-arr[j]];		
			
		}
	}
	if(dp[k]==true)cout<<"First"<<endl;
	else cout<<"Second"<<endl;
  return 0;
}




Measured memory_bytes: 384
#include <algorithm>
#include <array>
#include <cstddef>
#include <cstdint>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <vector>

using namespace std;

int main()
{
    string s;
    cin >> s;
    int ans = 700;
    for (auto ch : s)
    {
        if (ch == 'o')
        {
            ans += 100;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <iomanip>
#include <queue> 
 
using namespace std;
 
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	int N;

	cin >> N;

	vector<int> X(N);

	for(int i = 0; i < N; i++) {
		cin >> X[i];
	}

	sort(X.begin(), X.end());

	int l = X[0];
	int r = X[N - 1];

	int min = 100000000;

	int count = 0;

	for(int i = l; i <= r; i++) {
		for(int j = 0; j < N; j++) {
			count += pow(X[j] - i, 2);
		}
		if(count < min) {
			min = count;
		}
		count = 0;
	}

	cout << min << endl;
}

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

int main(){
  int N;cin>>N;
  string S;cin>>S;
  priority_queue<int> A;
  for(int j=1;j<N;j++){
    vector<bool> X(26,false);
    int ans=0;
    for(int i=0;i<j;i++) X.at(S.at(i)-'a')=true;
    for(int i=j;i<N;i++){
      if(X.at(S.at(i)-'a')){
        X.at(S.at(i)-'a')=false;
        ans++;
      }
    }
    A.push(ans);
  }
  cout<<A.top()<<endl;
  
}



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

#define FOR(i,a,b)    for (int i=(a)  ;i<(b) ;i++)
#define RFOR(i,a,b)   for (int i=(b)-1;i>=(a);i--)
#define REP(i,n)      for (int i=0    ;i<(n) ;i++)
#define RREP(i,n)     for (int i=(n)-1;i>=0  ;i--)
#define EACH(i,a,b)   for (int i=(a)  ;i<=(b);i++)
#define REACH(i,a,b)  for (int i=(b)  ;i>=(a);i--)
#define ALL(a)        (a).begin(),  (a).end()
#define RALL(a)       (a).rbegin(), (a).rend()
#define YES()         printf("YES\n")
#define NO()          printf("NO\n")
#define Yes()         printf("Yes\n")
#define No()          printf("No\n")
#define in(a,x,b)     ((a) <= (x) && (x) < (b))

const int MOD = 1e9 + 7;
const int INF = 1 << 29;
const double EPS = 1e-10;

using ll = long long;
using P = pair<int,int>;
template<class T = int> using V = vector<T>;

template<class T> bool inline chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool inline chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T = int> T inline input() { T x; cin >> x; return (x); }
template<class T> void inline print(T& x) { cout << x << '\n'; }
#define debug(x) cerr << #x << ": " << x << endl;

const int dxs[] = { 1, 0, -1, 0, 1, 1, -1, -1 };
const int dys[] = { 0, -1, 0, 1, 1, -1, -1, 1 };

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

  ll a,b,x;
  cin >> a >> b >> x;

  cout << (b/x) - (a+(x-1))/x + 1 << endl;
}


Measured memory_bytes: 3656
#include<cstdio>
#include<iostream>
#include<vector>
#include<string>
#include<queue>
#include<algorithm>
#include<functional>


using namespace std;

int main()
{
	int n;
	cin >> n;
	int s[3] = { 0,0,0 };
	for (int i = 0; i < n; i++) {
		int j;
		cin >> j;
		if (j % 4 == 0)s[0]++;
		else if (j % 4 == 2)s[2]++;
		else s[1]++;
	}
	if (s[2]>0&& s[1] - s[0] <= 0)cout << "Yes" << endl;
	else if(s[2]==0&&s[1]-s[0]<=1) cout << "Yes" << endl;
	else cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x ,n) for(int i = x; i < n; i++)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main(){
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    cout << (( ((c+(b-1))/b) <= ((a+(d-1))/d) ) ? "Yes":"No");
	return 0;
}

Measured memory_bytes: 3552
#pragma GCC optimize("Ofast")
#include<iostream>
#include<cstdlib>
#include<cstdio>
#include<string>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<math.h>
#include<utility>
#include<queue>
using namespace std;

int main(){
    long long int a, b;
    cin >> a >> b;

    cout << a*b << endl;
}

Measured memory_bytes: 3672
N = int(input())
X = [int(x) for x in input().split()]
result = list(filter(lambda x: x % 2 == 0, X))
count = 0
for i in result:
    if i % 3 == 0 or i % 5 == 0:
        count += 1
print('APPROVED' if count == len(result) else 'DENIED')

Measured memory_bytes: 3060
N, T = [int(i) for i in input().split()]
c_t = [list(map(int, input().split())) for i in range(N)]
c_t = sorted(c_t)
#print(c_t)

for i in range(N):
    if c_t[i][1] <= T:
        print(c_t[i][0])
        exit()

print('TLE')





Measured memory_bytes: 2940
#pragma region include
#include <iostream>
#include <iomanip>
#include <stdio.h>

#include <sstream>
#include <algorithm>
#include <iterator>
#include <cmath>
#include <complex>

#include <string>
#include <cstring>
#include <vector>
#include <tuple>
#include <bitset>

#include <queue>
#include <set>
#include <map>
#include <stack>
#include <list>

#include <fstream>
#include <random>
//#include <time.h>
#include <ctime>
#pragma endregion //#include
/////////
#define REP(i, x, n) for(int i = x; i < n; ++i)
#define rep(i,n) REP(i,0,n)
#define ALL(X) X.begin(), X.end()
/////////
#pragma region typedef
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
typedef std::pair<LL,LL> PLL;//
typedef std::pair<int,int> PII;//
#pragma endregion //typedef
////定数
const int INF = (int)1e9;
const LL MOD = (LL)1e9+7;
const LL LINF = (LL)4e18+20;
const LD PI = acos(-1.0);
const double EPS = 1e-9;
/////////
using namespace::std;

void solve(){
	int N;
	cin >> N;
	int L = 0;
	int R = N;
	string str;
	cout << L << endl;
	cin >> str;
	string ANS = "Vacant";
	string S[2];
	S[0] = "Male";
	S[1] = "Female";
	int pat;
	if( str == S[0] ){
		pat = 0;
	}else if( str == S[1]){
		pat = 1;
	}else{
		return;
	}
	while(R-L>1){
		int mid = (L+R)/2;
		cout << mid << endl;
		cin >> str;
		if( str == ANS ) return;
		int now;
		if( str == S[0] ){
			now = 0;
		}else{
			now = 1;
		}
		if( mid&1 ){
			if( now != pat ){
				L = mid;
			}else{
				R = mid;
			}
		}else{//mid%2 = 0
			if( now == pat ){
				L = mid;
			}else{
				R = mid;
			}
		}
	}
}

#pragma region main
signed main(void){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	std::cout << std::fixed;//小数を10進数表示
	cout << setprecision(16);//小数点以下の桁数を指定//coutとcerrで別	

	solve();
}
#pragma endregion //main()

Measured memory_bytes: 852
import itertools

n, m, q = map(int,input().split())

x = []

for _ in range(q):
    x.append(list(map(int,input().split())))

res = 0

for l in itertools.combinations_with_replacement([x for x in range(m)], n):
    temp = 0
    
    for temp_x in x:
        if l[temp_x[1] - 1] - l[temp_x[0] - 1] == temp_x[2]:
            temp += temp_x[3]

    if res <= temp:
        res = temp

print(res)


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

int main()
{
	int n, k;
	cin >> n >> k;
	int d;
	vector<int> sunuke(n);
	for (int i = 0; i < k; i++) {
		cin >> d;
		for (int j = 0; j < d; j++) {
			int a;
			cin >> a;
			sunuke[a - 1]++;
		}
	}
	int cnt = 0;
	for (int i = 0; i < n; i++) {
		if (sunuke[i] == 0)
			cnt++;
	}
	cout << cnt << endl;
}

Measured memory_bytes: 3628
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;

#define LET(name, value) __typeof(value) name = value
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define FOR(i, a, b) for (int i = (a); i < (int)(b); ++i)
#define FOREQ(i, a, b) for (int i = (a); i <= (int)(b); ++i)
#define ALL(c) (c).begin(), (c).end()
#define FOREACH(i, c) for (LET(i, (c).begin()); i != (c).end(); ++i)

char field[30][30];

int dfs(int y, int x) {
  static int dy[] = {-1, 0, 1, 0};
  static int dx[] = {0, -1, 0, 1};

  if (field[y][x] == '.') {
    field[y][x] = '#';
    int sum = 1;
    REP(k, 4) { sum += dfs(y + dy[k], x + dx[k]); }
    return sum;
  } else {
    return 0;
  }
}

int main() {
  int W, H;
  while (scanf("%d%d", &W, &H), W|H) {
    int sy = -1, sx = -1;
    memset(field, '#', sizeof(field));
    FOREQ(y, 1, H) FOREQ(x, 1, W) {
      scanf(" %c", &field[y][x]);
      if (field[y][x] == '@') {
        sy = y; sx = x;
        field[y][x] = '.';
      }
    }
    printf("%d\n", dfs(sy, sx));
  }
}

Measured memory_bytes: 0
#include <iostream>
#include <vector>
#include <set>
using namespace std;

int main() {
	int n;cin >> n;
	vector<int> t(n);
	for (int i=0;i<n;++i) cin >> t[i];
	int m;cin >> m;
	vector<pair<int, int>> p;
	for (int j=0;j<m;++j) {
		int pi, xi;
		cin >> pi >> xi;
		p.push_back(make_pair(pi, xi));
	}
	for (int l=0;l<m;++l) {
		int sum =0;
		for (int k=0;k<n;++k) {
			if (k + 1==p[l].first) {
				sum += p[l].second;
			} else {
				sum += t[k];
			}
		}
		cout << sum << endl;
	}
	return 0;
}

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

int a, b;

int main() {
    cin >> a >> b;

    if (a+b == 15) cout << "+" << endl;
    else if (a*b == 15) cout << "*" << endl;
    else cout << "x" << endl;

    return 0;
}


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

int main() {
    map<int, int> A;
    int n;
    cin >> n;

    rep(i, n) {
        int tmp;
        cin >> tmp;
        tmp--;

        if (A.count(tmp)) {
            A[tmp]++;
        } else {
            A[tmp] = 1;
        }
    }

    int cnt = 0;
    for (auto a : A) {
        int x = a.first + 1;
        int y = a.second;

        if (x < y) {
            cnt += (y - x);
        } else if (x > y) {
            cnt += y;
        }
    }
    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 8064
#include <iostream>
#include <algorithm>
#include <set>
#include <string>
#include <vector>

int main(void){
    int n;
    std::cin >> n;

    long long int box1 = 2;
    long long int box2 = 1;
    long long int tmp = box1 + box2;
    if(n > 2){
        for(int i = 2; i < n; i++){
            box1 = tmp;
            tmp = tmp + box2;
            box2 = box1;
        }
    }

    if(n==1){
        std::cout << 1;
        return 0;
    }
    std::cout << tmp;
    return 0;
}



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

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

    vector<int> cnt(2);
    for (int i = 0; i < 3; i++)
        cnt[s[i] - 'A']++;

    if (cnt[0] != 0 && cnt[1] != 0)
        cout << "Yes\n";
    else
        cout << "No\n";

    return 0;
}


Measured memory_bytes: 256
from sys import exit, stderr, stdin
input = stdin.readline
# setrecursionlimit(10**7)

def debug(var, name="hoge"):
    print(name +":" + str(type(var)) + " = " + repr(var), file=stderr)
    return


def main():
    N = int(input())
    p = [int(n) for n in input().split()]
    sp = sorted(p)
    cnt = 0
    for i in range(N):
        if p[i] != sp[i]:
            cnt += 1

    print("YES" if cnt <= 2 else "NO")





if __name__ == "__main__":
    main()


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

int main(void){
    vector<int> A;
    vector<bool> Bingo(9, false);
    int Abuf, N, Bbuf;
    for(int i=0; i<9; i++){
        cin >> Abuf;
        A.push_back(Abuf);
    }
    cin >> N;
    for(int i=0; i<N; i++){
        cin >> Bbuf;
        for(int j=0; j<9; j++){
            if(Bingo[j])continue;
            if(A[j] == Bbuf)Bingo[j]=true;
        }
    }
    bool res = false;
    for(int i=0; i<3; i++){
        if(Bingo[3*i]&&Bingo[3*i+1]&&Bingo[3*i+2]){
            res = true;
            break;
        }
        if(Bingo[i]&&Bingo[i+3]&&Bingo[i+6]){
            res = true;
            break;
        }
    }
    if(!res){
        if(Bingo[4]){
            if(Bingo[0]&&Bingo[8])res = true;
            if(Bingo[2]&&Bingo[6])res = true;
        }
    }
    if(res){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include"bits/stdc++.h"
using namespace std;
#define ll long long
#define LL long long
#define MOD 1000000007
#define INF 2000000000000
int dx[4] = { 0,1,0,-1 };
int dy[4] = { 1,0,-1,0 };
ll N, M, K, H, W, L, R, l, r, u, d, sum, Q;
LL ans;
LL no;
bool b, bb[100001];
string s, t;
int main() {
	cin >> N >> M;
	LL p;
	vector<LL> v(N + 1);
	for (int i = 0; i < N; i++) {
		bb[i + 1] = false;
		v[i + 1] = 0;
	}
	v[0] = 0;
	ans = 0;
	for (int i = 0; i < M; i++) {
		cin >> p >> s;
		if (bb[p] == false) {
			if (s == "WA")v[p]++;
			else {
				bb[p] = true;
				ans++;
			}
		}
	}
	sum = 0;
	for (int i = 1; i <= N; i++) {
		if (bb[i])sum += v[i];
	}

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



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

int max(std::vector<int> &a)
{
    if (a.size()==0) return 0;
    int m=a[0];
    for (int i=1; i<a.size(); i++)
        if (a[i]>m) m=a[i];
    return m;
}

int main()
{
    int k,n;
    std::cin>>k>>n;
    std::vector<int> a(n);
    for (int i=0; i<n; i++)
        std::cin>>a[i];
    std::vector<int> v;
    for (int i=1; i<n; i++)
        v.push_back(a[i]-a[i-1]);
    v.push_back(k-a[n-1]+a[0]);
    std::cout<<k-max(v);
    return 0;
}


Measured memory_bytes: 5084
#include <iostream>
using namespace std;
typedef long long ll;

int main() {
	
	ll n;
	cin >> n;
	ll a[n+1], m[n+1];
	m[1] = 0;
	for(ll i = 1; i  < n+1; i++)
	{
		cin >> a[i];
		if(i%2 == 1) m[1] += a[i];
		else m[1] -= a[i];
	}
	
	for(int i = 2; i < n+1; i++)
	{
		m[i] = 2 * ( a[i-1]- (m[i-1]/2) );
	}
	for(ll i = 1; i  < n+1; i++) cout << m[i] << " ";
	
	// your code goes here
	return 0;
}

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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, pii> pipii;
typedef pair<pii, int> piipi;
typedef pair<pii, pii> piipii;

#define mp make_pair
#define fi first
#define se second
#define all(a) (a).begin(), (a).end()
#define sz(a) (int)(a).size()
#define eb emplace_back
const int mod = 1e9+7;

ll c[205][205];
int a[105], b[105];
int cnt[55], sz[55];

int ti = 1;
int disc[55], low[55], par[55];
vector<int> g[55];
vector<vector<pii> > fin;
vector<pii> st, bridge;

void BCCUtil(int u){
    disc[u] = low[u] = ++ti;
    int child = 0;

    for(int i=0;i<g[u].size();i++){
        int v = g[u][i];
        if(disc[v] == -1){
            child++;
            par[v] = u;
            st.emplace_back(make_pair(u, v));
            BCCUtil(v);
            low[u] = min(low[u], low[v]);

            if(disc[u] < low[v]) bridge.emplace_back(make_pair(u, v));

            if((disc[u] == 0 && child > 1) || (disc[u] != 0 && disc[u] <= low[v])){
                vector<pii> tmp;
                while (st.back() != make_pair(u, v)) tmp.emplace_back(st.back()), st.pop_back();
                tmp.emplace_back(st.back()), st.pop_back();
                fin.emplace_back(tmp);
            }
        }
        else if(disc[v] < disc[u]){
            low[u] = min(low[u], disc[v]);
            st.emplace_back(make_pair(u, v));
        }
    }
}

void solve(int n){
    for(int i=1;i<=n;i++) par[i] = disc[i] = low[i] = -1;
    for(int i=1;i<=n;i++){
        if(disc[i] == -1){
            BCCUtil(i);
            if(st.size() > 0) fin.emplace_back(st);
            st.clear();
        }
    }
}
ll fpow(ll a, ll b){
    ll ans = 1;
    while(b){
        if(b%2 == 1) ans = ans*a%mod;
        a = a*a%mod;
        b/=2;
    }
    return ans;
}
int main(){
    c[0][0] = 1;
    for(int i=1;i<=200;i++){
        c[i][0] = c[i][i] = 1;
        for(int j=1;j<i;j++) c[i][j] = (c[i-1][j] + c[i-1][j-1])%mod;
    }
    int n, m, k;
    scanf("%d%d%d", &n, &m, &k);
    for(int i=1;i<=m;i++){
        scanf("%d%d", &a[i], &b[i]);
        g[a[i]].eb(b[i]);
        g[b[i]].eb(a[i]);
    }
    solve(n);
    int ans1 = 1, ans2 = 1, ans3 = 1;
    for(int i=0;i<sz(fin);i++){
        vector<pii> co = fin[i];

        set<pii> edge;
        set<int> node;
        for(int i=0;i<co.size();i++){
            int u = min(co[i].fi, co[i].se);
            int v = max(co[i].fi, co[i].se);
            edge.insert(mp(u, v));
            node.insert(u);
            node.insert(v);
        }
        if(sz(edge) == 1){
            ans1 = ans1*1ll*k%mod;
        }
        else if(sz(node) == sz(edge)){
            int res = 0;
            for(int j=0;j<sz(edge);j++){
                res = (res + fpow(k, __gcd(j, sz(edge))))%mod;
            }
            ans2 = ans2*1ll*res%mod*fpow(sz(edge), mod-2)%mod;
        }
        else{
            ans3 = ans3*1ll*c[sz(edge)+k-1][k-1]%mod;
        }
    }
    int ans = ans1*1ll*ans2%mod*ans3%mod;
    printf("%d\n", ans);
}

Measured memory_bytes: 4108
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <functional>
#include <sstream>
#include <string>
#include <utility>
#include <map>
#include <memory>
#include <set>
#include <vector>
#include <deque>
#include <list>
#include <stack>
#include <queue>

using namespace std;

class MaxHeap
{
public:
  vector<int> a;
  int solve();
  int maxHeapify( int x );
  int buildMaxHeap();
};

int MaxHeap::maxHeapify( int x )
{
  int l = x * 2;
  int r = l + 1;
  int s = a.size();
  int largest;
  
  if ( l < s && a[l] > a[x] )
    largest = l;
  else
    largest = x;

  if ( r < s && a[r] > a[largest] )
    largest = r;

  if ( largest != x )
    {
      swap( a[x], a[largest] );
      maxHeapify( largest );
    }
       
  return 0;
}

int MaxHeap::buildMaxHeap()
{
  int s = a.size() - 1;

  for ( auto i = s / 2; i >= 1; --i )
    maxHeapify( i );
  
  return 0;
}

int MaxHeap::solve()
{
  int n, x;
  cin >> n;

  a.push_back( 0 );
  
  for ( auto i = 0; i < n; ++i )
    {
      cin >> x;
      a.push_back( x );
    }
  
  buildMaxHeap();
  
  for ( auto i = 1; i <= n; ++i )
    cout << " " << a[i];

  cout << endl;
  
  return 0;
}

int main()
{
  MaxHeap mh;

  mh.solve();

  return 0;
}

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

using namespace std;

#define all(v)				((v).begin()), ((v).end())
#define allr(v)				((v).rbegin()), ((v).rend())
#define sz(v)				((int)((v).size()))
#define rep(i, v)		for(int i=0;i<sz(v);++i)
#define lp(i, n)		for(int i=0;i<(int)(n);++i)
#define lpi(i, j, n)	for(int i=(j);i<(int)(n);++i)
#define lpd(i, j, n)	for(int i=(j);i>=(int)(n);--i)
#define ll long long
#define pb					push_back
#define fIO ios_base::sync_with_stdio(0);cin.tie(0);

const ll inf = 1e8;
const double pi = 3.1415926535897;


const double EPS = (1e-7);
int dcmp(double x, double y) {	return fabs(x-y) <= EPS ? 0 : x < y ? -1 : 1;	}


typedef vector<int>                vi;
typedef vector<pair<int,int>>      vii;
typedef vector<ll>                 vll;
typedef vector<double>             vd;
typedef vector< vi >               vvi;
typedef vector< vd >               vvd;
typedef vector<string>             vs;

/**
    * PLEASEEE READDD PROBLEEEM CARFULLY ****
    * Always check for OVERFLOW ll vs int
    * Always check for array bounds
    * Check for function return
    * READ OUTPUT SECTION AGAIN!!!
**/


int main(){
    fIO

    int a;
    cin >> a;

    for(int i = 1; i < 10; i++){
        if(a % i == 0 && a / i <= 9) return cout << "Yes\n", 0;
    }
    cout << "No";
}









Measured memory_bytes: 256
#include<stdio.h>

int main(){
  int i,j,n,c=0,mini,t;
  int a[100];
  scanf("%d",&n);
  for(i=0;i<n;i++) scanf("%d",&a[i]);
  
  for(i=0;i<n-1;i++){
    mini=i;
    for(j=i;j<n;j++){
      if(a[j]<a[mini])mini=j;
    }
    t=a[i];
    a[i]=a[mini];
    a[mini]=t;
    if(i!=mini)c++;
  }

  
  for(i=0;i<n-1;i++) printf("%d ",a[i]);
  printf("%d\n",a[n-1]);
  printf("%d\n",c);

  return 0;
}



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

int main(){
  int i,j,n,m,ans;
  int h[200],r[200],dp[200];
  for(;;){
    cin >> n;
    if(!n)break;

    for(i=0;i<n;i++)cin >> h[i] >> r[i];
    cin >> m;
    for(i=n;i<n+m;i++)cin >> h[i] >> r[i];

    for(i=0;i<n+m;i++)
      for(j=i+1;j<n+m;j++)
	if(h[i]>h[j] || (h[i]==h[j] && r[i]>r[j])){
	  swap(h[i],h[j]);
	  swap(r[i],r[j]);
	}
   
    ans = 0;
    dp[0] = 1;
    for(i=1;i<n+m;i++){
      dp[i] = 1;
      for(j=0;j<i;j++)
	if(h[i]>h[j] && r[i]>r[j])dp[i] = max(dp[i],dp[j]+1);
      ans = max(ans,dp[i]);
    }
    cout << ans << endl;
  }
}

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

using namespace std;

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

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

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

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

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

const double EPS=1e-11;
#define EQ0(x) (abs((x))<EPS)
#define EQ(a, b) (abs((a)-(b))<EPS)

ll ma[114514], mb[114514];

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, a[364364];
	cin>>n;
	priority_queue<int, vector<int>, greater<int>> pqa;
	priority_queue<int> pqb;
	REP(i, n*3){
		cin>>a[i];
		if(i<n){
			pqa.push(a[i]);
			ma[0]+=a[i];
		}
		if(i>=n*2){
			pqb.push(a[i]);
			mb[n]+=a[i];
		}
	}
	FOR(i, n, n*2){
		pqa.push(a[i]);
		ma[i-n+1]=ma[i-n]+a[i]-pqa.top();
		pqa.pop();
	}
	FORR(i, n, n*2){
		pqb.push(a[i]);
		mb[i-n]=mb[i-n+1]+a[i]-pqb.top();
		pqb.pop();
	}
	ll ans=-1e18;
	REP(i, n+1){
		ans=max(ans, ma[i]-mb[i]);
		// DEBUG(ma[i]);
		// DEBUG(mb[i]);
	}
	cout<<ans<<'\n';
	return 0;
}


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

int main (){
    int N;
    cin >> N;
    LL dp[N+1];
    fill(dp,dp+N+1,0);
    dp[0]=2;
    dp[1]=1;
    for(int i=2;i<N+1;i++){
        dp[i]=dp[i-1]+dp[i-2];
    }
    cout << dp[N] << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <utility>
#include <vector>
#include <algorithm>
#include <cstring>

typedef std::pair<int, int> ii;
typedef std::pair<ii, char> ic;
typedef long long ll;

const ii INF = ii(1e9, 1e9);
const ll MOD = 1e9 + 7;
std::vector<ii> pt[256];
std::vector<ii> piece;
int dec[256];
int step[256], cur_step = 0, step2[256][2];

int n;
std::string dom[2];

std::vector<int> to[256];
ll memo[256][3][3];

ll dp(int on, int f1, int f0)
{
	if(on == piece.size())
		return 1;
	ll &ans = memo[on][f1][f0];
	if(ans != -1)
		return ans;
	ans = 0;
	bool b1 = false, b0 = false;
	for(int i = 0; i < to[on].size(); i++)
	{
		if(to[on][i] == 1)
			b1 = true;
		else if(to[on][i] == 0)
			b0 = true;
	}
	for(int i = 0; i < 3; i++)
	{
		if(b1 && f1 == i)
			continue;
		if(b0 && f0 == i)
			continue;
		ans += dp(on + 1, f0, i);
	}
	ans %= MOD;
	return ans;
}

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

void dfs(ii pos, char x)
{
	if(step2[pos.first][pos.second] == cur_step)
		return;
	step2[pos.first][pos.second] = cur_step;
	step[dec[dom[pos.second][pos.first]]] = cur_step;
	//std::cout << "on (" << pos.second << ", " << pos.first << ")\n";
	if(dom[pos.second][pos.first] != x)
		return;
	for(int i = 0; i < 4; i++)
	{
		ii to = ii(pos.first + dx[i], pos.second + dy[i]);
		if(to.first < 0 || to.first >= dom[0].size())
			continue;
		if(to.second < 0 || to.second >= 2)
			continue;
		dfs(to, x);
	}
}

int main()
{
	std::cin >> n >> dom[0] >> dom[1];
	for(int i = 0; i < n; i++)
	{
		for(int j = 0; j < 2; j++)
		{
			pt[dom[j][i]].push_back(ii(i, j));
		}
	}
	for(int i = 0; i < 256; i++)
	{
		std::sort(pt[i].begin(), pt[i].end());
		if(pt[i].size() != 0)
			piece.push_back(pt[i][0]);
	}
	std::sort(piece.begin(), piece.end());
	for(int i = 0; i < piece.size(); i++)
		dec[dom[piece[i].second][piece[i].first]] = i;
	for(int i = 0; i < piece.size(); i++)
	{
		cur_step++;
		//std::cout << i << ": (" << piece[i].second << ", " << piece[i].first << "), " << dom[piece[i].second][piece[i].first] << "\n";
		dfs(piece[i], dom[piece[i].second][piece[i].first]);
		for(int j = 0; j < i; j++)
		{
			if(step[j] == cur_step)
			{
				to[i].push_back(i - j - 1);
				//std::cout << "got (" << i << ", " << j << ")\n";
			}
		}
	}
	memset(memo, -1, sizeof memo);
	std::cout << dp(0, 0, 0) << '\n';
}

Measured memory_bytes: 256
MAX_N = 110
MAX_W = 10 ** 5 + 100
N, W = map(int, input().split())
w = [0] * MAX_N
v = [0] * MAX_N
for i in range(N):
    w[i], v[i] = map(int, input().split())
dp = [[0] * (W + 1) for _ in range(N + 1)]
for i in range(N):
    for sum_w in range(W + 1):
        if sum_w - w[i] >= 0:
            dp[i + 1][sum_w] = max(dp[i + 1][sum_w], dp[i][sum_w - w[i]] + v[i])
        dp[i + 1][sum_w] = max(dp[i + 1][sum_w], dp[i][sum_w])
print(dp[N][W])

Measured memory_bytes: 120684