akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

const int MAXV { 1010 }, MAXN { 5 }, MAXM { (1 << 9) }, oo { (1 << 30) - 1 };

int st[MAXN][MAXV][MAXM];

int dp(int k, int N, int size, int mask, const vector<int>& as, const vector<int>& xs)
{
    if (k == 3)
        return 0;

    if (mask == (1 << N) - 1)
        return oo;

    if (st[k][size][mask] != -1)
        return st[k][size][mask];

    int ans = oo;

    for (int i = 0; i < N; ++i)
    {
        if (mask & (1 << i))
            continue;

        // Finaliza com este pedaço e continua
        int x = (size ? 10 : 0) + abs(size + xs[i] - as[k]) 
                + dp(k + 1, N, 0, mask | (1 << i), as, xs);

        // Soma este pedaço e continua, se valer a pena
        int y = oo;

        if (size + xs[i] < as[k])
            y = (size ? 10 : 0) + dp(k, N, size + xs[i], mask | (1 << i), as, xs);

        ans = min({ ans, x, y });
    }

    st[k][size][mask] = ans;
    return ans;
}

int solve(int N, const vector<int>& as, const vector<int>& xs)
{
    memset(st, -1, sizeof st);

    return dp(0, N, 0, 0, as, xs);
}

int main()
{
    ios::sync_with_stdio(false);

    int N;
    cin >> N;

    vector<int> as(3), xs(N);

    for (int i = 0; i < 3; ++i)
        cin >> as[i];

    for (int i = 0; i < N; ++i)
        cin >> xs[i];
 
    auto ans = solve(N, as, xs);

    cout << ans << '\n';

    return 0;
}


Measured memory_bytes: 10368
#include<bits/stdc++.h>
using namespace std;
 
#define IOS 		ios_base::sync_with_stdio(false);; cin.tie(0); cout.tie(0)
#define sd(n)       scanf("%d", &n)
#define sdd(a,b)    scanf("%d %d", &a, &b)
#define sddd(a,b,c) scanf("%d %d %d", &a, &b, &c)
#define sld(n)      scanf("%lld", &n)
#define slld(a,b)   scanf("%lld %lld", &a, &b)
#define sllld(a,b,c) scanf("%lld %lld %lld", &a, &b, &c)
#define slu(n)      scanf("%llu", &n)
#define sllu(a,b)   scanf("%llu %llu", &a, &b)
#define slllu(a,b,c) scanf("%llu %llu %llu", &a, &b, &c)
#define ss(a)		scanf("%s", a)
#define inStrAftInSome cin.ignore(numeric_limits<streamsize>::max(),'\n')		//input string(with whitespace) after input something(char, int, bool, str)
#define all(a) 		a.begin(),a.end()
#define unq(x)      x.erase(unique(all(x)), x.end()
#define mp 			make_pair
#define mt 			make_tuple
#define sz(av) 		int((av).size())					//return size of vec
#define CLR(arr)    memset(arr, 0, sizeof(arr))			//assign 0 to whole arr
#define SET(vec)    memset(arr, -1, sizeof(arr))		//assign -1 to whole arr
#define CLRV(vec)	fill(vec.begin(), vec.end(), 0)		//assign 0 to whole vec
#define SETV(vec,n,a) vec.assign(n, a)	
#define vtd(rowsize,colsize,type,name) 		vector < vector <type> > name(rowsize,vector <type> (colsize)); 	//assign to first n elements value a in vec
#define SETB(a)		memset(a, true, sizeof(a))			//boolean array initialize by true value
#define CLRB(a)		memset(a, false, sizeof(a))			//boolean array initialize by false value
#define vintitr 	vector<int>::iterator
#define vlnlnitr 	vector<long long>::iterator
#define sintitr 	set<int>::iterator
#define slnlnitr 	set<long long>::iterator
#define aa			first
#define bb			second
#define MOD 		1000000007
#define PI 			acos(-1.00)
#define psb 		push_back
#define ppb			pop_back
#define ppb			pop_back
#define psf			push_front
#define ppf			pop_front
#define in 			inset
#define rep(i, n) 	for(int i=0; i<n; i++)
#define repi(i,j,n) for(int i=j; i<n; i++)
#define rof(i, n)   for(int i=n-1; i>=0; i--)
#define roff(i, n, f)	for(int i = n-1; i>=f; i--)
#define min3(a,b,c) (min((c),min((a),(b))))
#define max3(a,b,c) (max((a),max((b),(c))))
#define __lcm(a, b)	a*b / __gcd(a, b)
#define __builtin_zerocount(a)	8*sizeof(a)-__builtin_popcount(a)-__builtin_clz(a)-__builtin_ctz(a)
#define D(t)        cerr << #t " = " <<t  << '\n'
#define DBG         cerr << "Hi!" << '\n'
#define dame { puts("-1"); return 0;}
#define yn {puts("YES");}else{puts("NO");}
 
 
typedef long long	 		ll;
typedef unsigned long long	llu;
typedef long double			ld;
typedef vector< int > 		vi;
typedef vector< vi >		vvi;
typedef pair<int, int> 		pii;
typedef tuple<int,int,int>  tiii;

int main()
{
	IOS;
	int n;	cin >> n;
	vector <vector<int>> dp(n+1, vi (3, 0));
	rep(i, n){
		vi h(3);
		rep(j, 3)	cin >> h[j];
		rep(j, 3)
			rep(k, 3)
				if(j != k)
					dp[i+1][j] = max(dp[i+1][j], dp[i][k]+h[j]);

	}
	cout << max3(dp[n][0], dp[n][1], dp[n][2]) << endl;
	
    return 0;
}


Measured memory_bytes: 5760
#include <stdio.h>

void bubbleSort(int *A, int N){
	int flag = 1, temp, count = 0, m, j;
	while(flag){
		flag = 0;
		for(j=N-1;j>0;j--){
			if(A[j] < A[j-1]){
				temp = A[j];
				A[j] = A[j-1];
				A[j-1] = temp;
				flag = 1;
				count++;
			}
		}
	}
	for(m=0; m<N; m++){
		printf("%d", A[m]);
		if(m < N-1){
			printf(" ");
		}else printf("\n");
	}
	printf("%d\n", count);
}
int main(void){
	int N, i;
	scanf("%d", &N);
	int A[N];
	for(i=0;i<N;i++){
		scanf("%d", &A[i]);
	}
	bubbleSort(A, N);

	
	return 0;
}


Measured memory_bytes: 1968
N = int(input())
memo = [{} for i in range(N + 1)]
MOD = 10 ** 9 + 7

def ok(last4):
    for i in range(4):
        t = list(last4)
        if i >= 1:
            t[i], t[i - 1] = t[i - 1], t[i]
        if "".join(t).count("AGC") >= 1:
            return False
    return True

def dfs(cur, last3):
    if last3 in memo[cur]:
        return memo[cur][last3]
    if cur == N:
        return 1
    ret = 0
    for c in "ACGT":
        if ok(last3 + c):
            ret = ret + dfs(cur + 1, last3[1:] + c)
    memo[cur][last3] = ret
    return ret
    
print(dfs(0, "TTT") % MOD)

Measured memory_bytes: 3948
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {
		Scanner sc = new Scanner(System.in);
		InputStreamReader isr = new InputStreamReader(System.in);
		BufferedReader br = new BufferedReader(isr);
		String buf = br.readLine();

		// 整数の入力

		System.out.println(buf.charAt(2) == buf.charAt(3) && buf.charAt(4) == buf.charAt(5) ? "Yes" : "No");
	}
}

Measured memory_bytes: 22996
S = input()
q = int(input())
Q = []
for _ in range(q):
    Q.append(input().split())

Q = Q[::-1]

cnt = 0
left = []
right = []
for x in range(q):
    if len(Q[x]) == 1:
        cnt += 1
    else:
        if (int(Q[x][1]) + cnt) % 2 == 0:
            right.append(Q[x][2])
        else:
            left.append(Q[x][2])

#print(left, right)

for l in left:
    print(l, end="")
if cnt % 2 == 0:
    for s in S:
        print(s, end="")
else:
    for s in S[::-1]:
        print(s, end="")
for r in right[::-1]:
    print(r, end="")

print()


Measured memory_bytes: 122032
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace AtCoder
{
	public class ABC
	{
		static int mod = 1000000007;  // 10^9+7

		static void Main(string[] args)
		{
			Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });


			//int n = int.Parse(Console.ReadLine());
			string s = Console.ReadLine();
			//int[] vs = Console.ReadLine().Split().Select(int.Parse).ToArray();
			string ans = "";
			switch (s) {
			case "25":
				ans = "Christmas";
				break;
			case "24":
				ans = "Christmas Eve";
				break;
			case "23":
				ans = "Christmas Eve Eve";
				break;
			case "22":
				ans = "Christmas Eve Eve Eve";
				break;
			}
			Console.WriteLine(ans);



			Console.Out.Flush();
		}
	}
}


Measured memory_bytes: 11092
import Data.List
import Data.Function
import Control.Monad
main = do
    (n,m) <- inputPair
    as <- replicateM n inputPair
    cs <- replicateM m inputPair
    mapM print $ map (solve cs) as

inputPair :: IO (Int,Int)
inputPair = (\[x,y] -> (x,y)).(map read).words <$> getLine

manDist :: (Int ,Int) -> (Int,Int) -> Int
manDist (a,b) (c,d) = abs (a-c) + abs (b-d)

solve :: [(Int,Int)] -> (Int,Int) -> Int
solve xs a=fst $ minimumBy (compare `on` (manDist a).snd) (zip [1..] xs)

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

using namespace std;

using ll = long long;
using ld = long double;

using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vs = vector<string>;
using vld = vector<ld>;
using vvld = vector<vld>;

typedef pair<ll, ll> P;

#define bit(n) (1LL << (n))

//#define int long long

#define all(v) v.begin(), v.end()

#define rep(i, n) for (ll i = 0; i < n; i++)
#define REP(i, n) for (ll i = 1; i < n; i++)

#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define FORm(i, m) for (auto i = m.begin(); i != m.end(); i++)

template <class T>
inline void chmax(T& a, T b) {
  a = std::max(a, b);
}
template <class T>
inline void chmin(T& a, T b) {
  a = std::min(a, b);
}

#define mod (ll)(1e9 + 7)
const long long INF = 1LL << 60;

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(20);

  ll h, w, n;
  cin >> h >> w >> n;

  vector<P> p(n);
  rep(i, n) {
    cin >> p[i].first >> p[i].second;
  }
  // sort(all(p));

  map<P, ll> m;
  for (const auto& it : p) {
    FOR(x, -1, 2) {
      FOR(y, -1, 2) {
        if (it.first + y >= 2 && it.first + y <= h - 1) {
          if (it.second + x >= 2 && it.second + x <= w - 1) {
            m[make_pair(it.first + y, it.second + x)]++;
          }
        }
      }
    }
  }

  vll ans(10);
  for (const auto& it : m) {
    ans[it.second]++;
  }
  ans[0] = (w - 2) * (h - 2) - accumulate(all(ans), 0ll);

  rep(i, 10) {
    cout << ans[i] << endl;
  }

  return 0;
}


Measured memory_bytes: 58112
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n)     for (ll i = 0; i < (n); ++i)
#define rep2(i, a, b) for (ll i = (a); i < (b); ++i)
#define repin(a, n)  \
    vector<ll> a(n); \
    rep(i, n) { cin >> a[i]; }
#define repins(a, n)     \
    vector<string> a(n); \
    rep(i, n) { cin >> a[i]; }
#define repind(a, n)     \
    vector<double> a(n); \
    rep(i, n) { cin >> a[i]; }
#define in(a) \
    ll a;     \
    cin >> a;
#define ins(a) \
    string a;  \
    cin >> a;
#define ind(a) \
    double a;  \
    cin >> a;
template <class T>
inline void out(T a) {
    cout << a << endl;
}
inline void out(double a) { printf("%.10f\n", a); }
#define all(x)  (x).begin(), (x).end()    //昇順
#define rall(x) (x).rbegin(), (x).rend()  //降順
#define yes     out("Yes");
#define no      out("No");

int main() {
    in(n);
    in(d);
    ll ans = 0;
    rep(i, n) {
        in(x);
        in(y);
        if (d * d >= x * x + y * y) {
            ans++;
        }
    }
    out(ans);
}

Measured memory_bytes: 3628
x = [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]
i = int(input())
print(x[i-1])

Measured memory_bytes: 3060
main :: IO()
main = do
    str <- getLine
    putStrLn $ if (countx str < 8) then "YES" else "NO"


countx :: String -> Int
countx str
    | str == []			= 0
    | head str == 'x'	= 1 + countx (tail str)
    | otherwise			= countx (tail str)

Measured memory_bytes: 380
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define all(v) v.begin(), v.end()
#define mod 1000000007
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

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

    vector<int> t;
    int now = 1;
    int cnt = 0;
    rep(i, 0, n) {
        if (s[i] == (char)(now + '0')) cnt++;
        else {
            t.push_back(cnt);
            now = 1 - now;
            cnt = 1;
        }
    }
    t.push_back(cnt);
    if ((int)t.size() % 2 == 0) t.push_back(0);

    int ans = 0;
    int len = t.size();
    for (int i = 0; i < len; i += 2) {
        int left = i;
        int right = min(left + 2 * k, len - 1);
        int tmp = 0;
        for (int j = left; j <= right; j++) {
            tmp += t[j];
        }
        ans = max(ans, tmp);
    }

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


Measured memory_bytes: 1020
package main

import (
	"fmt"
)

func main() {
	var a, b, x int64
	fmt.Scan(&a, &b, &x)

	if a == 0 {
		fmt.Println(b/x + 1)
	} else {
		fmt.Println(b/x - (a-1)/x)
	}
}


Measured memory_bytes: 512
n = int(input())
A = [int(x) for x in input().split()]
print(" ".join([str(x) for x in A]))

for i in range(1, n):
    key = A[i]
    j = i-1
    while j >=0 and A[j] > key:
        A[j+1] = A[j]
        j -= 1
    A[j+1] = key
    print(" ".join([str(x) for x in A]))

Measured memory_bytes: 5608
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] x = new int[n];
        float ave = 0;
        for (int i = 0; i < n; i++) {
            x[i] = sc.nextInt();
            ave += x[i];
        }
        ave = Math.round(ave / x.length);

        int count;
        int counter = 0;
        for (int j = 0; j < x.length; j++) {
            count = x[j] - (int) ave;
            counter += count * count;
        }
        System.out.println(counter);
    }
}

Measured memory_bytes: 23892
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>
#include <cstring>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define all(c) begin(c),end(c)

template<typename T1, typename T2>
inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }

template<typename T1, typename T2>
inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

//改造
typedef long long int ll;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007


//ここから編集する
class Solve {
public:
    void input() {

    }

    void solve() {
        input();
        string s;
        cin >> s;
        for (int i = 0; i + 1 < 4; ++i) {
            if (s[i] == s[i + 1]) {
                cout << "Bad" << endl;
                return;
            }
        }
        cout << "Good" << endl;


    }
};


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    Solve().solve();


    return 0;
}


Measured memory_bytes: 888
/*
	Name:
	Author: xiaruize
	Date:
*/

#include<bits/stdc++.h>
using namespace std;
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define LL long long

int main()
{
 	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	int n;
	cin>>n;
	string s1,s2;
	cin>>s1>>s2;
	forn(i,n)
	{
		cout<<s1[i]<<s2[i];	
	}	
	return 0;
}


Measured memory_bytes: 256
from collections import deque
que=deque(input())
q=int(input())
rev=False
for i in range(q):
    s=input()
    if s=="1":
        rev= not rev
    else:
        t,f,c=s.split()
        if (f=='1' and rev==False) or (f=='2' and rev):
            que.appendleft(c)
        else:
            que.append(c)
if rev:
    que.reverse()
print("".join(que))
        

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

int main()
{
    char init_a[5] = {'M', 'A', 'R', 'C', 'H'};
    int n;
    cin >> n;

    map<char, int> m_cnt;
    rep(i, 0, n)
    {
        string s;
        cin >> s;
        m_cnt[s[0]]++;
    }

    ll ans = 0;
    rep(i, 0, 5)
    rep(j, i + 1, 5)
    rep(k, j + 1, 5)
     ans += (ll)m_cnt[init_a[i]] * m_cnt[init_a[j]] * m_cnt[init_a[k]];

    cout << ans << endl;


    return 0;
}

Measured memory_bytes: 384
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    try {
      String s = scanner.next();
      int n = s.length();
      int ans = 999;
      for (int i = 0; i < n - 2; i++) {
        String t = s.substring(i, i+3);
        // System.out.println(t);
        int a = Integer.parseInt(t);
        int diff = Math.abs(a - 753);
        if (diff < ans) ans = diff;
      }
      System.out.println(ans);
    } finally {
      scanner.close();
    }
  }
}




Measured memory_bytes: 21584
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
#define FOR(i,a,b) for(long long int i=a;i<b;i++)
#define sz(s) (long long int)(s).size()
#define pb push_back
#define mp make_pair
const ll inf = 1000000000;
const ll MOD = 1000000007;

int main(void){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);   
    cout.tie(NULL);
    register ll i,j,k,x,y,m,n,t,q,temp,sum=0,count=0,f=1;
    cin>>x;
    for(i=-177; i<= 177; i++){
        for(j=-177; j<= 177; j++){
            if(i*i*i*i*i - j*j*j*j*j == x){

            // if(i == j)continue;
            // if(x%(i-j) == 0){
            //     temp = i*i*i*i + i*i*i*j + i*i*j*j + i*j*j*j + j*j*j*j;
            //     if(temp == 0)continue;
            //     if(x%temp == 0){
                    cout<<i << " "<<j;
                    goto end;
                }
            // }
        }
    }
    end:;
}    
    

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

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

		int N = sc.nextInt();
		int p[] = new int[N];
		for(int i = 0; i < N; i++) {
			p[i] = sc.nextInt();
		}

		Arrays.sort(p);
		p[N-1] = p[N-1] / 2;

		int ans = 0;
		for(int i = 0; i < N; i++) {
			ans = ans + p[i];
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 23124
# 2019/07/12
# DFS ver
# リストにしてみた

import sys

sys.setrecursionlimit(10**9)
input=sys.stdin.readline

n=int(input())
edge=[[] for _ in range(n)]
for _ in range(n-1):
    u,v,c=map(int,input().split())
    u-=1 ; v-=1
    edge[u].append([c,v])
    edge[v].append([c,u])

q,k=map(int,input().split())
k-=1

d=[0]*n
visited=[False]*n

def dfs(s,p):
    visited[s]=True
    for c,v in edge[s]:
        if visited[v] or p==v:continue
        d[v]=c+d[s]
        visited[v]=True
        dfs(v,s)
    return 


dfs(k,-1)
for _ in range(q):
    x,y=map(int,input().split())
    x-=1 ; y-=1
    print(d[x]+d[y])



Measured memory_bytes: 138828
N = int(input())
p = list(map(int, input().split()))
ans = 0
for i in range(N):
    
    if i == N-1:
        if p[i] == i+1:
            tmp = p[i]
            p[i] = p[i-1]
            p[i-1] = tmp
            ans += 1

    elif p[i] == i+1:
        tmp = p[i]
        p[i] = p[i+1]
        p[i+1] = tmp
        ans += 1

print(ans)

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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define MAXN 1000010
#define rep(i,n) for (int i = 0; i < (n); ++i)
const ll mod = 1e9+7;

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

bool is_integer( double x ){
  return std::floor(x)==x;
}
int main() {
    int N;
    cin >> N;
    double ans = N * 100.0/108;
    if (is_integer(ans)) {
        cout << ans << endl;
    } else {
        if (floor(ceil(ans)*1.08) == N) {
            cout << ceil(ans) << endl;
        } else if (floor(floor(ans)*1.08) == N) {
            cout << floor(ans) << endl;
        } else {
        cout << ":(" << endl;
        }
    }
}



Measured memory_bytes: 256
#include <bits/stdc++.h> 
#define lb lower_bound 
#define ub upper_bound 
#define sqr(x) (x)*(x) 
#define lowbit(x) (x)&(-x) 
#define mem(a,x) memset(a,x,sizeof(a));
using namespace std; 
typedef long long ll;

int main(){
	int a,b;
	scanf("%d %d",&a,&b);
	if(b<=4*a&&b>=2*a&&b%2==0) printf("Yes\n");
	else printf("No\n"); 
}

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

int main() {
  char c;
  cin >> c;

  if (c == 'a' || c == 'e' || c == 'i' || c == 'u' || c == 'o') {
    cout << "vowel" << endl;
  }
  else {
    cout << "consonant" << endl;
  }
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;
int N;

int main()
{
    while(cin >> N)
    {
    int Sum = 0;
    for(int a=0; a<=9; a++)
    {
        for(int b=0; b<=9; b++)
        {
            for(int c=0; c<=9; c++)
            {
                for(int d=0; d<=9; d++)
                {
                    if(a+b+c+d == N)
                    {
                        Sum++;
                    }
                }
            }
        }
    }
        cout << Sum << endl;
    }

}

Measured memory_bytes: 1160
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <algorithm>
#include <cmath>
#include <iomanip>

using namespace std; 

int main()
{
    int n, m;
    cin >> n >> m;
    vector<vector<int>> vec(m);
    
    for(int i=0; i<m; i++)
    {
        int k; cin >> k;
        vec[i].resize(k);
        for(int j=0; j<k; j++)
        {
            cin >> vec[i][j];
            --vec[i][j];
        }
    }

    vector<int> p(m);

    for(int i=0; i<m; i++) cin >> p[i];

    int ans = 0;
    
    for(int i=0; i<(1 << n); i++)
    {
        bool ok = true;
        for(int j=0; j<m; j++)
        {
            int c = 0;
            for (int id : vec[j])
            {
                if((i >> id) & 1)
                {
                    c++;
                }
            }
            c%=2;
            if(c!=p[j]) ok = false;
        }
        if(ok) ++ans;
    }

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


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
#define MAXN 100000
#define LL long long
LL n,m;
char s[MAXN+5],t[MAXN+5];
int gcd(int m,int n)  
{  
    while(m>0)  
    {int c=n%m;n=m,m=c;}
    return n;  
}  
int main()
{
    scanf("%lld%lld",&n,&m);
    scanf("%s%s",s+1,t+1);
    LL G=gcd(n,m);
    LL ans=n*m/G;
    LL k1=ans/n,k2=ans/m;
    LL G2=k1*k2/gcd(k1,k2);
    for(LL L=0;L<ans;L+=G2)
    {
        LL pos1=L/k1+1,pos2=L/k2+1;
        if(s[pos1]!=t[pos2]){printf("-1");return 0;}
    }
    printf("%lld",ans);
}

Measured memory_bytes: 384
BIT=[0]*200001
def add x,v;(BIT[x]+=v;x+=x&-x)while BIT[x];end
def sum x;s=0;(s+=BIT[x];x&=x-1)while x>0;s;end

n,k=gets.split.map &:to_i
ar=(1..n).map{gets.to_i}

list = ar.inject([0]){|s,r|s<<(s[-1]+r-k)}[1..-1]

rank = list.sort

ans = list.count{|i|i>=0}

list.each{|i|
  x=rank.bsearch_index{|j|j>=i}+1
  ans += sum(x)
  add(x,1)
}
p ans


Measured memory_bytes: 10800
#include<stdio.h>
 
int main(){
    int a,b,ans,k,t;
     
    while((scanf("%d",&a))!=EOF){
        scanf("%d",&b);
        t=a+b;
        for(ans=1;;){
            t=(t-t%10)/10;
            if(t>0)
            ans++;
            else{
                printf("%d\n",ans);
                break;
            }
        }
    }
         
     
    return 0;
}

Measured memory_bytes: 600
<?php
 
$stdin  = trim(fgets(STDIN));
$stdin1 = trim(fgets(STDIN));
$target_array = explode(' ', $stdin1);
$res = '';
 
echo isUniqueArray($target_array);
 
function isUniqueArray ($target_array) {
  $unique_array = array_unique($target_array);
  if (count($unique_array) === count($target_array)) {
    $res = 'YES';
  }
  else {
    $res = 'NO';
  }
    return $res;
}

Measured memory_bytes: 39028
import itertools
import numpy as np

n, d = map(int, input().split())
Dist = [list(map(int, input().split())) for _ in range(n)]

ans = 0
for d_list in list(itertools.combinations(Dist, 2)):
  x = np.array(d_list[0])
  y = np.array(d_list[1])
  tmp = 0
  for i in (x-y):
    tmp += i*i
  k = tmp**0.5
  if k == int(k):
    ans += 1

print(ans)

Measured memory_bytes: 27216
#include <bits/stdc++.h>
#include <chrono> 
 
using namespace std;
using namespace std::chrono; 
 
// #pragma GCC target ("avx2")
// #pragma GCC optimization ("O3")
// #pragma GCC optimization ("unroll-loops")
// #pragma optimization_level 3
// #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
 
#define f0r(a, b) for (long long a = 0; a < (b); ++a)
#define f1r(a, b, c) for (long long a = (b); a < (c); ++a)
#define f0rd(a, b) for (long long a = (b); a >= 0; --a)
#define f1rd(a, b, c) for (long long a = (b); a >= (c); --a)
#define ms(arr, v) memset(arr, v, sizeof(arr))
#define pb push_back
#define send {ios_base::sync_with_stdio(false);}
#define help {cin.tie(NULL); cout.tie(NULL);}
#define fix(prec) {cout << setprecision(prec) << fixed;}
#define mp make_pair
#define f first
#define s second
#define presum(p, a, n) {p[0] = a[0]; for (int i = 1; i < (n); i++) p[i] = a[i] + p[i-1];}
#define all(v) v.begin(), v.end()
#define getunique(v) {sort(all(v)); v.erase(unique(all(v)), v.end());}
#define readgraph(list, edges) for (int i = 0; i < edges; i++) {int a, b; cin >> a >> b; a--; b--; list[a].pb(b); list[b].pb(a);}
#define ai(a, n) for (int ele = 0; ele < n; ele++) cin >> a[ele];
#define ain(a, lb, rb) for (int ele = lb; ele <= rb; ele++) cin >> a[ele];
#define ao(a, n) {for (int ele = 0; ele < (n); ele++) { if (ele) cout << " "; cout << a[ele]; } cout << '\n';}
#define aout(a, lb, rb) {for (int ele = (lb); ele <= (rb); ele++) { if (ele > (lb)) cout << " "; cout << a[ele]; } cout << '\n';}
typedef long long ll;
typedef double ld;
typedef long double lld;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vpi;
typedef vector<pll> vpl;
 
template<typename A> ostream& operator<<(ostream &cout, vector<A> const &v);
template<typename A, typename B> ostream& operator<<(ostream &cout, pair<A, B> const &p) { return cout << "(" << p.f << ", " << p.s << ")"; }
template<typename A> ostream& operator<<(ostream &cout, vector<A> const &v) {
  cout << "["; for(int i = 0; i < v.size(); i++) {if (i) cout << ", "; cout << v[i];} return cout << "]";
}
template<typename A, typename B> istream& operator>>(istream& cin, pair<A, B> &p) {
  cin >> p.first;
  return cin >> p.second;
}
 
mt19937 rng(steady_clock::now().time_since_epoch().count());
// mt19937 rng(61378913);
/* usage - just do rng() */
 
void usaco(string filename) {
  // #pragma message("be careful, freopen may be wrong")
	freopen((filename + ".in").c_str(), "r", stdin);
	freopen((filename + ".out").c_str(), "w", stdout);
}
 
const lld pi = 3.14159265358979323846;
const ll mod = 1000000007;
// const ll mod = 998244353;
// ll mod;

ll n, m;

void solve(int tc) {
  cin >> n; m = 0; ll r = 1;
  while (n) {
    m += r; n /= 2; r *= 2;
  }
  cout << m << '\n';
}
 
int main() {
  send help
 
  // usaco("file");

  
 
  int tc;
  tc = 1;
  // cin >> tc;
  for (int t = 0; t < tc; t++) solve(t);
} 

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

int main() {
    int A, B, C;
    cin >> A >> B >> C;
    int M = max({A, B, C});
    int sum = A + B + C;

    if (M % 2 == sum % 2) {
        cout << (3 * M - sum) / 2 << endl;
    } else {
        cout << (3 * (M + 1) - sum) / 2 << endl;
    }
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		double pi = 3.141592653589;
		double r;
		Scanner scan = new Scanner(System.in);
		r = scan.nextDouble();

		System.out.printf("%6f %6f",(pi*r*r),(2*pi*r));

	}

}

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

using LL = long long int;
constexpr LL MOD = 1e9 + 7;
pair<int, int> directions[] = { {0, 1}, {0, -1}, {1, 0}, {-1, 0} };

class Solution {
public:

};

void test() {
    Solution s;
}

void run() {
    Solution s;
}

int main() {
//    test();
//    run();
    string str;
    cin >> str;
    cout << (str.find("AC") != string::npos ? "Yes" : "No") << endl;
    return 0;
}


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

using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
#define rep(i,n) for(ll i = 0;i < (ll)n;i++)
#define ALL(x) (x).begin(),(x).end()
#define MOD 1000000007


const ll mod = 998244353;
vector<ll> fact(200100,1),refact(200100,1);
ll comb(ll n,ll r){
  if(n < r)return 0;
  return (((fact[n]*refact[r])%mod)*refact[n-r])%mod;
}
ll modpow(ll n,ll r){
  ll res = 1;
  while(r){
    if(r & 1)res = res*n%mod;
    n = n*n%mod;
    r >>= 1;
  }
  return res;
}

int main(){

  rep(i,200010)fact[i+1] = fact[i]*(i+1)%mod;
  refact[200010] = modpow(fact[200010],mod-2);
  for(ll i = 200009;i > 0;i--)refact[i] = refact[i+1]*(i+1)%mod;

  ll n,m,k;
  cin >> n >> m >> k;
  ll res = 0;
  ll M = m;
  for(int i = n-1;i >= 0;i--){
    ll now = M;
    (now *= comb(n-1,i))%= mod;
    if(i <= k)(res += now)%= mod;
    (M *= m-1)%=mod;
  }
  cout << res << endl;
  
  




  return 0;
}

Measured memory_bytes: 6284
def gcd(a, b):
  while b:
    a, b = b, a % b
  return a
def lcm(a, b):
  return a // gcd(a, b) * b
def f(n, a, b):
  return n - n // a - n // b + n // lcm(a, b)

a, b, c, d = map(int, input().split())
print(f(b, c, d) - f(a-1, c, d))


Measured memory_bytes: 3060
#include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <numeric>
#include <iomanip>
#define ll long long int
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
using namespace std;
int mx4[] = {0,1,0,-1};
int my4[] = {1,0,-1,0};
int mx2[] = {1,0};
int my2[] = {0,1};

class A2 {
public:
	void solve(istream& in, ostream& out) {
        vector<int> a(3);
        rep(i,3) in >> a[i];
        sort(a.begin(),a.end());
        if(a[0] + a[1] == a[2]) out << "Yes" << endl;
        else out << "No" << endl;

	}
};

int main() {
	A2 solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}

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

#define mod      1e9+7;
#define INF      1e9+9;
#define ps(x,y)  fixed<<setprecision(y)<<x
# define PI 3.14159265358979323846264338327950 L
typedef long long ll;
typedef unsigned long long ull;
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
#endif
	int n;
	cin>>n;
	int a[n];
	int xo=0;
	for(int i=0;i<n;i++){
		cin>>a[i];
		xo^=a[i];
	}
	//cout<<xo<<endl;
	int b1,b2;
	for(int i=0;i<n;i++){
		int ans=0;
		for(int j=0;j<32;j++){
			b1=(a[i]&(1<<j));
			b2=(xo&(1<<j));
			//cout<<b1<<"  "<<b2<<endl;
			if(b1!=b2)
				ans+=(1<<j);
		}
		cout<<ans<<endl;
	}
	cout<<endl;

	return 0;
}

Measured memory_bytes: 4364
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define INF ((1LL<<62)-(1LL<<31))
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define bit(n,m)(((n)>>(m))&1)
int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}
ll pom(ll a,ll n,int m){ll x=1;for(a%=m;n;n/=2)n&1?x=x*a%m:0,a=a*a%m;return x;}
//#define MOD 998244353
#define MOD 1000000007
#define invp(a,p)pom(a,p-2,p)

ll a[50];
ll c[50];
int main(){
	int n;
	scanf("%d",&n);
	for(int i=0;i<n;i++)scanf("%d",a+i);
	ll s=0;
	for(int i=0;i<n;i++){
		int t;
		scanf("%d",&t);
		s+=t;
	}
	for(int i=0;i<n-1;i++)scanf("%d",c+i);
	for(int i=1;i<n;i++)if(a[i-1]+1==a[i])s+=c[a[i-1]-1];
	printf("%lld",s);
}

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

#define ONLINE_JUDGE
#define pb(a) push_back(a)
#define all(a) (a.begin(), a.end())

using ll = long long;

const int E5 = 1e5;

//////////// Solution /////////////////////////////////

int cnts[26],cntt[26];
	
void solve() {
	string s,t;
	cin >> s >> t;
	for (auto ch : s) {
		cnts[ch-'a']++;
	}
	for (auto ch: t) {
		cntt[ch-'a']++;
	}

	multiset<int> ss,st;
	for (int i = 0; i < 26; ++i) {
		if (cnts[i]) {
			ss.insert(cnts[i]);
		}
		if (cntt[i]) {
			st.insert(cntt[i]);
		}
	}

	if (ss == st) {
		cout << "Yes\n";
	} else {
		cout << "No\n";
	}
}	

/////////// End Solution ///////////////////////////////////////

//////// Initialization ////////////////////////////////////

int main() {

	#ifndef ONLINE_JUDGE
	FILE *FIN = freopen("/home/danil/prog/input.txt", "r", stdin);
	clock_t time_start = clock();
	#endif

	ios::sync_with_stdio(false);
	cin.tie(NULL);

	solve();

	#ifndef ONLINE_JUDGE
	fclose(FIN);
	cerr << "\x1b[031m\n-----------------\nTime=" << (ll)((double)(clock()-time_start) / CLOCKS_PER_SEC * 1000) << "ms\n\x1b[0m";
	#endif

	return 0;
}

//////// End Initialization ///////////////////////////////////////

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

using namespace std;

int a[1005][1005], idx[1005];
bool flag[1005][1005];

int main() {
	int n;
	scanf("%d", &n);
	
	for (int i = 1; i <= n; i++) {
		for (int j = 0; j < n - 1; j++) scanf("%d", &a[i][j]);
	}
	
	vector <int> update;
	
	for (int i = 1; i <= n; i++) {
		if (flag[a[i][idx[i]]][i]) {
			update.push_back(i);
			update.push_back(a[i][idx[i]]);
		}
		flag[i][a[i][idx[i]]] = 1;
	}
	
	int res = 0;
	
	while (update.size()) {
		vector <int> tmp;
		res++;
		
		for (int i = 0; i < update.size(); i++) {
			int id = update[i];
			idx[id]++;
			if (idx[id] < n - 1 && flag[a[id][idx[id]]][id]) {
				tmp.push_back(id);
				tmp.push_back(a[id][idx[id]]);
			}
			flag[id][a[id][idx[id]]] = 1;
		}
		
		update = tmp;
	}
	
	bool ok = 1;
	
	for (int i = 1; i <= n; i++) ok &= (idx[i] == n - 1);
	
	if (ok) printf("%d\n", res);
	else printf("-1\n");
}


Measured memory_bytes: 5120
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
 
//const int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
//const int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};
 
int main()
{
	int n;
	cin >> n;
	int match = n * (n-1) / 2;
	int team[n] = {};

	REP(i, match){
		int a, b, c, d;
		cin >> a >> b >> c >> d;
		if (c == d){
			team[a-1]++;
			team[b-1]++;
		}
		else if (c > d) team[a-1] += 3;
		else team[b-1] += 3;
	}

	int ans[n] = {};
	REP(i, n){
		REP(j, n){
			if (team[i] < team[j]) ans[i]++;
		}
	}

	for (auto x : ans) cout << x+1 << endl;


}



Measured memory_bytes: 3120
MOD = 10**9 + 7
def permutation(n,k):
	ret = 1
	for i in range(n-k+1,n+1):
		ret *= i
	return ret

N,K = map(int,input().split())
edge = [[] for i in range(N)]
for i in range(N-1):
	a,b = map(int,input().split())
	edge[a-1].append(b-1)
	edge[b-1].append(a-1)
searched = [False for i in range(N)]
searched[0] = True
dp = [1 for i in range(N)]
dp[0] = K
search = [(0,0)]
while len(search) > 0:
	x = search.pop()
	d,n = x[0], x[1]
	colors = K - min(2, d+1)
	for n2 in edge[n]:
		if not searched[n2]:
			searched[n2] = True
			dp[n2] = colors
			colors -= 1
			search.append((d+1,n2))
ans = 1
for i in dp:
	ans = (ans * i) % MOD
print(ans)

Measured memory_bytes: 33900
#include <iostream>
#include <string>

using namespace std;

int d;
int x, y;
bool data[9][5];

main(){
  for(int i=0;i<9;i++){
    for(int j=0;j<5;j++){
      data[i][j]=false;
    }
  }
  for(int i=0;i<9;i++){
    for(int j=0;j<=5;j++){
      char c;
      scanf("%c", &c);
      if(c=='\n') break;
      if(c=='1') data[i][j]=true;
    }
  }
  
  x=0;
  y=0;
  d=0;
  for(int i=0;;i++, d++){
    //    printf("(%d,%d,%d)\n", x, y, d);
    if(d==4) d=0;
    if(d==0){
      if(y==0) continue;
      if(data[2*(y-1)+1][x]){
	cout << 'U';
	y--;
	d=2;
      }
    }else if(d==1){
      if(x==4) continue;
      if(data[2*y][x]){
	cout << 'R';
	x++;
	d=-1;
      }
    }else if(d==2){
      if(y==4) continue;
      if(data[2*y+1][x]){
	cout << 'D';
	y++;
	d=0;
      }
    }else if(d==3){
      if(x==0) continue;
      if(data[2*y][x-1]){
	cout << 'L';
	x--;
	d=1;
      }
    }
    if(y==0 && x==0) break;
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 0
A_B_K = list(map(int, input().split()))
for i in range(A_B_K[2]):
    if A_B_K[i%2] % 2 == 1:
        A_B_K[i%2] -= 1

    A_B_K[i%2] = A_B_K[i%2]/2
    A_B_K[(i+1)%2] = A_B_K[(i+1)%2] + A_B_K[i%2]

out_list = [A_B_K[0],A_B_K[1]]
out_list = list(map(int, out_list))
out_list = list(map(str, out_list))
out = ' '.join(out_list)
print(out)

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

#define SIZE_OF_ARRAY(array) sizeof(array)/sizeof(array[0])

int main() {
    long long K ,N;
    cin >> K >> N;
    std::vector<long long> A;
    for(long long i = 0; i < N; i++){
        long long l;
        cin >> l;
        A.push_back(l);
    }
    A.push_back(A.at(0) + K);
    std::vector<long long> D;
    for(long long i = 0; i < N; i++){
        long long d = A.at(i+1) - A.at(i);
        D.push_back(d);
    }
    std::vector<long long>::iterator iter = std::max_element(D.begin(), D.end());
    size_t index = std::distance(D.begin(), iter);
    D.at(index) = 0;
    long long distance = 0;
    for(long long i=0; i < N; i++){
        distance += D.at(i);
    }
    cout << distance << endl;
}

Measured memory_bytes: 4848
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
using namespace std;
typedef long long ll;

int main(){

    string s; cin >> s;

    int cnt = 0;
    for(int i=1; i<s.size(); i++){
        if(s[i] != s[i-1]){
            cnt++;
        }
    }

    cout << cnt;

    return 0;
}

Measured memory_bytes: 512
const stdin = require('fs').readFileSync('/dev/stdin', 'utf8').trim()

const s = stdin.split('\n')[0]

const ans = () => {
  const exp = s.length - 1
  const pattern = 2 ** exp

  let sum = 0
  for (let i = 0; i < pattern; i++) {
    const calc = []

    for (let j = 0; j < s.length; j++) {
      calc.push(s[j])

      if ((i >> j) & 1) {
        calc.push('+')
      }
    }

    sum += calc
      .join('')
      .split('+')
      .map(Number)
      .reduce((p, c) => p + c)
  }

  return sum
}

console.log(ans())


Measured memory_bytes: 7868
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
using namespace std;
typedef long long ll;

const int INF = 1001001001;

int main(){
    int A[3];

    rep(i,3)
        cin >> A[i];   
    
    cout << A[2] << ' ' << A[0] << ' ' << A[1] << endl;
}

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

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;

int MOD=1e9+7;
ll INF=1e18;

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

int par[100010];
int ranks[100010];

void init(int n){
    for(int i=0; i<n; i++){
        par[i]=i;
        ranks[i]=0;
    }
}

int find(int x){
    if(par[x] == x){
        return x;
    }
    else{
        return par[x]=find(par[x]);
    }
}

bool same(int x, int y){
    return find(x) == find(y);
}

void unite(int x, int y){
    x=find(x);
    y=find(y);
    if(x == y) return;

    if(ranks[x] < ranks[y]){
        par[x]=y;
    }
    else{
        par[y]=x;
    }
    
    if(ranks[x] == ranks[y]){
        ranks[x]++;
    }
}

int kruskal(int n, vector<T> edge){
    sort(edge.begin(), edge.end());
    init(n);
    int res=0;
    for(int i=0; i<2*n-2; i++){
        int cost, cv, nv;
        tie(cost, cv, nv)=edge[i];
        if(!same(cv, nv)){
            unite(cv, nv);
            res+=cost;
        }
    }
    return res;
}

int main(){
    int n; cin>>n;
    vector<P> xsort(n), ysort(n);
    vector<T> edge(2*n-2);
    for(int i=0; i<n; i++){
        int x, y; cin>>x>>y;
        xsort[i]=P(x, i);
        ysort[i]=P(y, i);
    }

    sort(xsort.begin(), xsort.end());
    sort(ysort.begin(), ysort.end());

    for(int i=0; i<n-1; i++){
        int cx, cv, nx, nv;
        tie(cx, cv)=xsort[i];
        tie(nx, nv)=xsort[i+1];
        int cost=abs(nx-cx);
        edge[i]=T(cost, cv, nv);
    }
    for(int i=0; i<n-1; i++){
        int cy, cv, ny, nv;
        tie(cy, cv)=ysort[i];
        tie(ny, nv)=ysort[i+1];
        int cost=abs(ny-cy);
        edge[i+n-1]=T(cost, cv, nv);
    }

    cout << kruskal(n, edge) << endl;
}

Measured memory_bytes: 7296
#include <iostream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <cassert>
#include <string>
#include <memory.h>
#include <queue>
#include <cstdio>
#include <cstdlib>
#include <set>
#include <map>
#include <cctype>
#include <iomanip>
#include <sstream>
#include <cctype>
#include <fstream>
#include <cmath>
using namespace std;

#define REP2(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define REP(i, n) REP2(i, 0, n)
#define ALL(c) (c).begin(), (c).end()
#define ITER(c) __typeof((c).begin())
#define PB(e) push_back(e)
#define FOREACH(i, c) for(ITER(c) i = (c).begin(); i != (c).end(); ++i)
#define MP(a, b) make_pair(a, b)
#define PARITY(n) ((n) & 1)

typedef long long ll;
typedef pair<ll, ll> P;
const int INF = 1000 * 1000 * 1000 + 7;
const double EPS = 1e-10;


char dir[4] = {'N', 'E', 'S', 'W'};
int dx[4]   = {-1, 0, 1, 0};
int dy[4]   = {0, 1, 0, -1};

char field[110][110];
ll memo[110][110][4];

int main(){
  ll H, W, L;
  while(cin >>H >> W >> L && H + W + L){
    
    fill(&field[0][0], &field[0][0] + 110 * 110, '#');
    memset(memo, -1, sizeof(memo));
    
    int x, y, d;
    REP(i, H)REP(j, W){
      cin >> field[i+1][j+1];
      if(isalpha(field[i+1][j+1])){
        x = i + 1;
        y = j + 1;
        d = find(dir, dir + 4, field[i+1][j+1]) - dir;
      }
    }

    ll T = 0;
    bool flag = false;
    
    while(L > 0){    
      int nx = x + dx[d];
      int ny = y + dy[d];
      memo[x][y][d] = T++;
      
      while(field[nx][ny] == '#'){
        d = (d + 1) % 4;
        nx = x + dx[d];
        ny = y + dy[d];
      } 

      L--;
      x = nx;
      y = ny;
      if(memo[x][y][d] >= 0 && !flag){
        ll S = T - memo[x][y][d];
        L %= S;
        flag = true;
      }
    }
    cout << x<< " " << y<< " " << dir[d] << endl;
  }
  
  return 0;
}

Measured memory_bytes: 1556
N, W = [int(i) for i in input().split(" ")]
VW = [[int(j) for j in input().split(" ")] for i in range(N)]

dp = [[0 for i in range(W + 1)] for j in range(N + 1)]

for i in range(N):
    for w in range(1, W + 1):
        if w < VW[i][1]:
            dp[i + 1][w] = dp[i][w]
        else:
            dp[i + 1][w] = max([dp[i][w], dp[i][w - VW[i][1]] + VW[i][0]])

print(max(dp[N]))



Measured memory_bytes: 25952
from collections import deque
n,k = map(int,input().split())
a = list(map(int,input().split()))
mod = 10**9+7
p = []
m = []
ans = 1
for i in a:
    if i < 0:
        m.append(-i)
    else:
        p.append(i)
cp = len(p)
cm = len(m)
m.append(0)
m.append(0)
p.append(0)
p.append(0)
p.sort()
m.sort()
p = deque(p)
m = deque(m)
if cm == n and k%2 == 1:
    f = 1
else:
    f = 0 
if f == 0:
    while k:
        # print(k,cm,m)
        if k%2 == 1 and cp:
            p1 = deque.pop(p)
            ans *= p1
            k -= 1
            cp -= 1
        elif f == 0 and m[-1] * m[-2] > p[-1] * p[-2] and cm > 1 and k>1:
            m1 = deque.pop(m)
            m2 = deque.pop(m)
            ans *= m1 * m2
            cm -= 2
            k -= 2
        elif cp > 0:
            p1 = deque.pop(p)
            ans *= p1
            k -= 1
            cp -= 1
        else:
            
            ans *= -m[2]
            m1 = deque.popleft(m)
            m2 = deque.popleft(m)
            m3 = deque.popleft(m)
            deque.appendleft(m,m1)
            deque.appendleft(m,m2)
            cm -= 1
            k -= 1
        ans %= mod
else:
    m1 = deque.popleft(m)
    m2 = deque.popleft(m)
    m1 = deque.popleft(p)
    m2 = deque.popleft(p)
    deque.append(m,10**10)
    deque.append(p,10**10)
    while k:
        k-=1
        # print(p,m)
        if p[0] < m[0]:
            ans *= deque.popleft(p)
        else:
            ans *= -deque.popleft(m)
        ans %= mod

print(ans)
    

Measured memory_bytes: 33548
#include<bits/stdc++.h>
using namespace std;
int a,b,k;
int main()
{
	scanf("%d%d%d",&k,&a,&b);
	for(int i=a;i<=b;++i)
		if(i%k==0) {
			printf("OK");
			return 0;
		}
	printf("NG");
	return 0;
}

Measured memory_bytes: 3720
N = int(input())
numbers = list(map(int, input().split()))

result = 0

for count in range(N-2):
    sliced_list = numbers[:3]
    if min(sliced_list) != sliced_list[1] and max(sliced_list) != sliced_list[1]:
        result = result + 1
    numbers.pop(0)
print(result)

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

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

using namespace std;

int main()
{
    string str; cin >> str;

    if( str[1] == str[2] && ( str[1] == str[0] || str[2] == str[3] ) )
        cout << "Yes" << endl;
    else
        cout << "No" << endl;


    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
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; }

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ for(auto it : P) { s << "<" << it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ for(auto it : P) { s << "<" << it.first << "->" << it.second << "> "; } return s << endl; }


long long dp[55][3000][55];
int main() {
    int N, A;
    cin >> N >> A;
    vector<int> x(N);
    for (int i = 0; i < N; ++i) cin >> x[i];

    memset(dp, 0, sizeof(dp));
    dp[0][0][0] = 1;
    for (int i = 0; i < N; ++i) {
        for (int s = 0; s <= N*A; ++s) {
            for (int k = 0; k <= N; ++k) {
                if (dp[i][s][k] == 0) continue;
                dp[i+1][s][k] += dp[i][s][k];
                dp[i+1][s+x[i]][k+1] += dp[i][s][k];
            }
        }
    }
    long long res = 0;
    for (int k = 1; k <= N; ++k) res += dp[N][A*k][k];
    cout << res << endl;
}

Measured memory_bytes: 71168
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

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

  int n, m;
  cin >> n >> m;
  cout << (n - 1) * (m - 1) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define M0D 1000000007
int B[100001];
int main(){

    long long ans=1;
    bool one=true;
    int N;
    cin >> N;
    int A[N];
    for(int i=0; i<N; i++) cin >> A[i];
    for(int i=0; i<100001; i++) B[i] = 0;

    for(int i=0; i<N; i++){
      if(A[i]!=0) ans *= B[A[i]-1] - B[A[i]];
      ans %= M0D;
      B[A[i]]++;
    }
    if(B[0]!=1) one=false;
    for(int i=0; i<100001; i++){
      if(B[i]>3) ans *= 0;
    }

    if(one) ans *= 3;
    else ans *= 6;

    cout << ans%M0D << endl;

  return 0;
}


Measured memory_bytes: 1024