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

int V;
vector<int> G[1200];
int match[1200];
bool used[1200];

void add_edge(int u, int v){
	G[u].push_back(v);
	G[v].push_back(u);
	return;
}

bool dfs(int v){
	used[v] = true;
	for (int i = 0; i < G[v].size(); i++){
		int u = G[v][i], w = match[u];
		if (w < 0 || !used[w] && dfs(w)){
			match[v] = u;
			match[u] = v;
			return true;
		}
	}

	return false;
}

int bipartite_matching(){
	int res = 0;
	memset(match, -1, sizeof(match));
	for (int v = 0; v < V; v++){
		if (match[v] < 0){
			memset(used, 0, sizeof(used));
			if (dfs(v)){
				res++;
			}
		}
	}
	return res;
}

int gcd(int x, int y) {
	if (y == 0) return x;
	return gcd(y, x%y);
}

int main(void){

	int m, n;

	while (cin >> m >> n, m, n){
		vector<int> mcard, ncard;

		V = m + n;
		for (int i = 0; i < m + n; i++){
			G[i].clear();
			match[i] = 0;
			used[i] = false;
		}

		for (int i = 0; i < m; i++){
			int buff; cin >> buff;
			mcard.push_back(buff);
		}
		for (int i = 0; i < n; i++){
			int buff; cin >> buff;
			ncard.push_back(buff);
		}

		for (int i = 0; i < m; i++){
			for (int j = 0; j < n; j++){
				if (gcd(mcard[i], ncard[j]) > 1) add_edge(i, m + j);
			}
		}

		cout << bipartite_matching() << endl;


	}

	return 0;
}

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


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

Measured memory_bytes: 3380
/*
title:

url:
*/

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <functional>
#include <queue>
#include <limits>
#include <string>
#include <utility>
#include <cstring>
#include <map>
#include <cmath>
#include <iterator>

using namespace std;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define INF 1000000007

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

struct Edge
{
    int to;
    Edge(int to) : to(to) {}
};

int main()
{
    int N;
    cin >> N;
    vector<Edge> Edges[N];
    rep(i, N - 1)
    {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        Edges[a].push_back(Edge(b));
        Edges[b].push_back(Edge(a));
    }

    //0->null, 1=black, -1=white
    int color[N] = {};
    queue<pint> q;
    q.push(pint(0, 1));
    q.push(pint(N - 1, -1));
    while (q.size())
    {
        pint p = q.front();
        q.pop();
        if (color[p.first] != 0)
            continue;
        color[p.first] = p.second;
        rep(i, Edges[p.first].size())
        {
            int v = Edges[p.first][i].to;
            q.push(pint(v, p.second));
        }
    }

    int black = 0;
    int white = 0;
    rep(i, N)
    {
        if (color[i] == 1)
        {
            black++;
        }
        else
        {
            white++;
        }
    }
    if (black > white)
    {
        cout << "Fennec" << endl;
    }
    else if (black < white)
    {
        cout << "Snuke" << endl;
    }
    else
    {
        if (N % 2 == 0)
        {
            cout << "Snuke" << endl;
        }
        else
        {
            cout << "Fennec" << endl;
        }
    }
    return 0;
}

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

int main(){
    ll a, b, k;
    cin >> a >> b >> k;

    rep(i, k){
        if (i % 2 == 0){
            if (a % 2 != 0) a--;
            b += a / 2;
            a /= 2;
        }
        else if (i % 2 != 0){
            if (b % 2 != 0) b--;
            a += b / 2;
            b /= 2;
        }
    }
    cout << a << " " << b << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <string>
#include <utility>
#include <algorithm>
#include <bitset>
#include <numeric>
#include <math.h>

using namespace std;

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

    int N, M;
    cin >> N >> M;

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

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

        vector<int> X_sub(M-1);
        for(int i = 0; i < M-1; ++i){
            X_sub[i] = X[i+1] - X[i];
        }

        vector<int> indices(X_sub.size());
        iota(indices.begin(), indices.end(), 0);

        sort(indices.begin(), indices.end(), [&X_sub](int i1, int i2) {
            return X_sub[i1] > X_sub[i2];
        });

        sort(indices.begin(), indices.begin()+(N-1));

        int cost = 0;
        int tmp_ind = 0;
        for(int i = 0; i < N-1; i++){
            cost += (X[indices[i]] - X[tmp_ind]);
            tmp_ind = indices[i] + 1;
        }
        cost += (X[M-1] - X[tmp_ind]);

        cout << cost << endl;
    } else{
        cout << 0 << endl;
    }

    return 0;
}


Measured memory_bytes: 1408
class BIT:
    def __init__(self, n):
        self.N = n
        self.n = 1<<n.bit_length()
        self.data = [0] * (self.n + 1)
        self.num = 0
    def sum(self, i):
        s = 0
        while i > 0:
            s += self.data[i]
            i -= i & -i
        return s
 
    def add(self, i, x):
        while i <= self.n:
            self.data[i] += x
            i += i & -i
        self.num+=1
    def search(self, value):
        if value<1:
            return 0
        if value >self.num:
            return self.N+1
        x,sx = 0,0
        step = self.n
        while step:
            y = x+step
            sy = sx+self.data[y]
            if sy < value:
                x,sx = y,sy
            step >>= 1
        return x+1

N = int(input())
P = list(map(int, input().split()))
index = [-1]*N
BIT = BIT(N)
ans = 0
for i in range(N):
    index[P[i]-1] = i+1
for num, p in enumerate(range(N, 0, -1)):
    i = index[p-1]
    BIT.add(i, 1)
    j = BIT.sum(i-1)+1
    a = BIT.search(j-2)
    b = BIT.search(j-1)
    c = BIT.search(j+1)
    d = BIT.search(j+2)
    ans+=p*((b-a)*(c-i)+(d-c)*(i-b))
print(ans)

Measured memory_bytes: 54764
#include <iostream>
#include <iomanip>
#include <string>
#include <map>
#include <unordered_map>
#include <cmath>
#include <algorithm>

typedef long long ll;
typedef long double ld;

using namespace std;
int main()
{
  string a, b;
  cin >> a >> b;
  cout << b << a << endl;
}


Measured memory_bytes: 3580
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>

using namespace std;
typedef long long ll;

int index(vector<ll> &v, ll x) {
    return lower_bound(v.begin(), v.end(), x) - v.begin();
}

template<typename T>
struct BinaryIndexedTree {
    vector<T> data;

    BinaryIndexedTree(int sz) {
        data.assign(++sz, 0);
    }

    T sum(int k) {
        T ret = 0;
        for (++k; k > 0; k -= k & -k) ret += data[k];
        return (ret);
    }

    void add(int k, T x) {
        for (++k; k < data.size(); k += k & -k) data[k] += x;
    }
};

int main() {
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        a[i] -= k;
    }

    vector<ll> c_sum(n + 1);
    for (int i = 0; i < n; i++)c_sum[i + 1] = c_sum[i] + a[i];

    vector<ll> sorted = c_sum;
    sort(sorted.begin(), sorted.end());
    sorted.erase(unique(sorted.begin(), sorted.end()), sorted.end());

    BinaryIndexedTree<ll> bit(n + 1);
    ll ret = 0;
    for (int i = n; i >= 0; i--) {
        ret += (n - i) - bit.sum(index(sorted, c_sum[i]) - 1);
        bit.add(index(sorted, c_sum[i]), 1);
    }
    cout << ret << endl;
    return 0;
}



Measured memory_bytes: 5520
#include<stdio.h>
#include<string.h>
using namespace std;

char n;
char num[1000];
long long dp[1000][210];
int main(){
	memset(dp, 0, sizeof(dp));
	scanf("%d", &n);
	for (int i = 0; i < n; i++)
		scanf("%d", &num[i]);
	dp[0][num[0]] = 1;
	for (int i = 1; i < n - 1; i++){
		for (int j = 0; j < 21; j++){
			int a = j + num[i];
			int b = j - num[i];
			if (a <= 20)dp[i][a] += dp[i - 1][j];
			if (b >= 0)dp[i][b] += dp[i - 1][j];
		}
	}
	printf("%lld\n", dp[n - 2][num[n - 1]]);
	return 0;
}
//671013170798012928
//671013170798012928

Measured memory_bytes: 4332
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline

def main():
    from collections import defaultdict
    d = defaultdict(int)
    N, M, *sc = map(int, read().split())
    ans = [0] * N
    sc = iter(sc)
    for i,s in zip(sc,sc):
        if N != 1 and i == 1 and s == 0:
            print(-1)
            break
        elif d[i] == 0 or d[i] == s:
            d[i] = s
            ans[i-1] = s
        else:
            print(-1)
            break
    else:
        if N != 1 and ans[0] == 0:
            ans[0] = 1
        print(''.join(map(str,ans)))
    return
if __name__ == '__main__':
    main()



Measured memory_bytes: 3444
#include <iostream>
using namespace std;
typedef long long ll;
int N;
ll A[100010],dp[100010][2] = {};
const ll inf = -1e18;

int main(){
    cin >> N;
    for(int i=1;i<=N;i++){
        cin >> A[i];
        dp[i][0] = inf;
        dp[i][1] = inf;
    }
    for(int i=2;i<=N;i++){
        if(i==2){
            dp[i][0] = A[i-1]+A[i];
            dp[i][1] = -A[i-1]-A[i];
        }else{
            dp[i][0] = max(dp[i-1][0],dp[i-1][1])+A[i];
            dp[i][1] = max(dp[i-1][0]-2*A[i-1]-A[i],dp[i-1][1]+2*A[i-1]-A[i]);
        }
    }
    cout << max(dp[N][0],dp[N][1]) << endl;
}

Measured memory_bytes: 2560
def divisor(n):
    ass = float('inf')
    for i in range(1,int(n**0.5)+1):
        tmp = 0
        if n%i == 0:
            tmp += i
            tmp += n//i
            ass = min(ass, tmp)
    return ass

def main():
    N = int(input())
    tmp = divisor(N)
    print(tmp-2)

  

if __name__ == "__main__":
    main()

Measured memory_bytes: 39024
#include<stdio.h>
int main(void)
{
	int cards[4][13],n,k,i,j,number;
	char mark;
	for(j=0;j<4;j++){
		for(i=0;i<13;i++){
				cards[j][i]=0;
			}
		}
	scanf("%d",&n);
	for(k=0;k<n*2;k++){
		scanf("%c %d", &mark, &number);
		switch(mark){
			case'S':
				cards[0][number-1]=1;
				break;
			case'H':
				cards[1][number-1]=1;
				break;
			case'C':
				cards[2][number-1]=1;
				break;
			case'D':
				cards[3][number-1]=1;
				break;
		}
	}
	for(j=0;j<4;j++){
		for(i=0;i<13;i++){
			if(cards[j][i]==0){
				if(j==0)mark='S';
				if(j==1)mark='H';
				if(j==2)mark='C';
				if(j==3)mark='D';
				printf("%c %d\n",mark,i+1);
			}
		}
	}
return 0;
}

Measured memory_bytes: 596
import java.io.IOException;
import java.util.Scanner;

public class Main {

	public static void main(String[] args)throws IOException {

		Scanner sc = new Scanner(System.in);
		boolean[][] card = new boolean[4][13];

		int n = sc.nextInt();

		for (int k = 0; k < n; k++) { // ????????????????????????????????£??\
			
			String mark = sc.next();
			char c = mark.charAt(0);
			int num = sc.nextInt();
			

			if (c == 'S') {
				card[0][num - 1] = true;
			} else if (c == 'H') {
				card[1][num - 1] = true;
			} else if (c == 'C') {
				card[2][num - 1] = true;
			} else if (c == 'D') {
				card[3][num - 1] = true;
			}
		}

		for (int i = 0; i < 4; i++) {
			for (int j = 0; j < 13; j++) {
				if (card[i][j] == false) {
					if (i == 0) {
						System.out.println("S" + " " + (j + 1));
					} else if (i == 1) {
						System.out.println("H" + " " + (j + 1));
					} else if (i == 2) {
						System.out.println("C" + " " + (j + 1));
					} else if (i == 3) {
						System.out.println("D" + " " + (j + 1));
					}
				}
			}
		}
		sc.close();
	}
}

Measured memory_bytes: 26272
card = []
check = [[0, 0, 0] for i in range(3)]
for i in range(3):
    card.append(list(map(int, input().split())))

n = int(input())
for i in range(n):
    b = int(input())
    for j in range(3):
        for k in range(3):
            if b == card[j][k]:
                check[j][k] = 1

flag = 0

for i in range(3):
    if check[i][0] == check[i][1] == check[i][2] == 1:
        flag = 1
        break
    elif check[0][i] == check[1][i] == check[2][i] == 1:
        flag = 1
        break
    elif check[0][0] == check[1][1] == check[2][2] == 1:
        flag = 1
        break
    elif check[0][2] == check[1][1] == check[2][0] == 1:
        flag = 1
        break

if flag:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 62048
#include <bits/stdc++.h>
using namespace std;
#define int long long

int r[200000],m[200000],c,a,b,n,x,y;
int minr=200000, minm=200000;

int32_t main()
{
	cin >> a >> b >> n;
	for(int i=0; i<a; i++)
	{
		cin >> r[i];
		if(r[i] < minr)
			minr = r[i];
	}
	
	for(int i=0; i<b; i++)
	{
		cin >> m[i];
		if(m[i] < minm)
			minm = m[i];
	}
	
	int ans = minr + minm;
	
	for(int i=0; i<n; i++)
	{
		cin >> x >> y >> c;
		int aux = r[x-1] + m[y-1] - c;
		if(aux < ans)
			ans = aux;
	}
	
	cout << ans << '\n';
}

Measured memory_bytes: 1792
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <numeric>
#include <cmath>

using namespace std;
typedef long long LL;
template <typename F, typename S> std::ostream& operator<<(ostream& os, const pair<F,S>& p) {
    os << "(" << p.first << "," << p.second << ")"; return os; }
template <typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
    os << "["; for(const T& a: v){ os << a << ", "; } os << "]"; return os; }
template <typename K, typename V> ostream& operator<<(ostream& os, const map<K,V>& m) {
    os << "{"; for(const auto& p: m){ os << p.first <<":"<< p.second << ", "; } os << "]"; return os; }


// import here

int main(){
    LL n, k;
    cin >> n >> k;
    LL ans = 0;
    for(LL b = k+1; b <= n; ++b){
        LL cnt = n / b;
        ans += cnt * (b-k);
        ans += max<LL>(0, n - (cnt*b + k-1));
    }
    if(k == 0) ans = n*n;
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 256
import Data.List
import Data.Bool

main = print . (`mod` (10^9 + 7)) . solve . map read . drop 1 . words =<< getContents

solve :: [Integer] -> Integer
solve as
    | (odd $ length as) && length a' == 1 && a == 0 = bool 0 r . ssolve 2 $ tail as'
    | otherwise = bool 0 r $ ssolve 1 as'
    where
        a = head a'
        a' = head as'
        as' = group $ sort as
        r = (2^) . bool (length as') (length as' - 1) $ odd (length as)

ssolve n as = all (\(a,x) -> length a == 2 && head a == x) $ zip as [n,n+2..]


Measured memory_bytes: 36220
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		
		Scanner in = new Scanner(System.in);
		int input = in.nextInt();
		int S[] = new int[input];
		
		for (int i = 0; i < input; i++)
			S[i] = in.nextInt();
			int nextInput = in.nextInt();
		
		int T[] = new int[nextInput];
		for (int i = 0; i < nextInput; i++)
			T[i] = in.nextInt();
		
		int C = 0;
		for (int i = 0; i < nextInput; i++) {	
			if (linearSearch(S, T[i]))	
				C++;		
		}
		
		System.out.println(C);
		
		}
	public static boolean linearSearch(int arr[], int param) {
		for (int i : arr) {
			if (i == param) {
				return true;
			}
		}
		return false;
		 
	}
}



Measured memory_bytes: 40388
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

import numpy as np
from heapq import heappush, heappop

N,M,S,T = map(int,input().split())
graph = [[] for _ in range(N+1)]
for _ in range(M):
    u,v,a,b = map(int,input().split())
    graph[u].append((v,a,b))
    graph[v].append((u,a,b))

def dijkstra(start, mode):
    INF = 10 ** 15
    dist = [INF] * (N+1)
    dist[start] = 0
    q = [(0,start)]
    while q:
        d,v = heappop(q)
        if dist[v] < d:
            continue
        for w,*a in graph[v]:
            d1 = d + a[mode]
            if dist[w] > d1:
                dist[w] = d1
                heappush(q, (d1,w))
    return dist

d1 = np.array(dijkstra(S,0))
d2 = np.array(dijkstra(T,1))

d1 += d2
answer = 10 ** 15 - np.minimum.accumulate(d1[::-1])[::-1][1:]
print('\n'.join(answer.astype(str)))

Measured memory_bytes: 78388
#include <bits/stdc++.h>
using namespace std;
#define inf 999999999
#define loop(i, a, b) for (int i = (a), i##len = (b); i < i##len; ++i)
#define rep(i, n) loop(i, 0, n)
#define lin long long
#define lfl long double

vector<vector<int>> res;

void calc(int m)
{
    rep(i, m+1)
    {
        vector<int> v;
        res.push_back(v);
    }

    int p = 0;
    rep(i, m)
    {
        rep(j, i+1)
        {
            int q = p + j;

            res[j].push_back(q);
            res[i+1].push_back(q);
        }

        p += i+1;
    }
}

bool solve(int n)
{
    int i = 0;
    int c = 0;
    while(c < n)
    {
        c = (i+1) * (i+2) /2;
        if(c == n)
        {
            calc(i+1);
            return true;
        }

        i++;
    }

    return false;
}

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

    if(!solve(n))
    {
        cout << "No" << endl;
        return 0;
    }

    cout << "Yes" << endl;
    cout << res.size() << endl;
    rep(i, res.size())
    {
        cout << res[i].size();

        rep(j, res[i].size())
        {
            cout << " " << (res[i][j]+1);
        }

        cout << endl;
    }

    return 0;
}


Measured memory_bytes: 2304
#define _USE_MATH_DEFINES
#define INF 10000000
#include <cstdio>
#include <iostream>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>

using namespace std;

typedef long long ll;
typedef pair <int,int> P;
typedef pair <int,P> PP;
typedef pair <int,PP> PPP;

static const double eps = 1e-8;

int main(){
  int duration;
  while(~scanf("%d",&duration)){
    int current_cars;
    scanf("%d",&current_cars);
    
    int max_cars = current_cars;
    bool isok = true;
    for(int i=0;i<duration;i++){
      int in,out;
      scanf("%d %d",&in,&out);
      max_cars = max(current_cars + (in-out),max_cars);
      current_cars += (in-out);
      if(current_cars < 0){
	isok = false;
      }
    }
    printf("%d\n",isok ? max_cars : 0);
  }
}

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

using namespace std;

int n, m;
int num[100100];
int pos[100100];

int main() {
    int i;

    scanf("%d%d",&n,&m);
    for (i=0;i<n;i++) num[i] = 1;
    pos[0] = 1;
    for (i=0;i<m;i++) {
        int x, y;
        scanf("%d%d",&x,&y); x--; y--;
        if (pos[x]) {
            if (num[x]==1) pos[x] = 0;
            pos[y] = 1;
        }
        num[x]--; num[y]++;
    }
    int c = 0;
    for (i=0;i<n;i++) c += pos[i];
    printf("%d\n",c);

    return 0;
}


Measured memory_bytes: 1024
/*
 * 2つの整数が入力される。それらの最大公約数を出力する。
 *
 * input
 * 147 105
 *
 * output
 * 21
 */

#include <stdio.h>

int gcd(int x, int y)
{
	int r;

	//ユークリッドの互除法
	while (y > 0) {
		r = x % y;
		x = y;
		y = r;
	}

	return x;

}

int main()
{
	int x,y;

	scanf("%d %d", &x, &y);

	if (x > y)
		printf("%d\n", gcd(x,y));
	else
		printf("%d\n", gcd(y,x));

	return 0;
}


Measured memory_bytes: 2028
#include <bits/stdc++.h>
#define N 101
#define INF 1e9
using namespace std;
string mp[N];
int D[101][101][1<<5];
int used[101][101];
typedef pair<int,int> P;
typedef pair<P,P> PP;
int dx[] ={0,0,1,-1};
int dy[] ={1,-1,0,0};
int w,h;

void bfs(){
  memset(used,-1,sizeof(used));
  queue<P> Q;
  for(int i=0;i<h;i++)
    for(int j=0;j<w;j++)if(mp[i][j]=='#')Q.push(P(i,j)),used[i][j] = 0;
  
  while(!Q.empty()){
    P t = Q.front();Q.pop();
    int y = t.first;
    int x = t.second;
    for(int i=-1;i<=1;i++)
      for(int j=-1;j<=1;j++){
	if(i==0&&j==0)continue;
	int nx = x+i;
	int ny = y+j;
	if(nx<0||ny<0||nx>=w||ny>=h||used[ny][nx]!=-1)continue;
	used[ny][nx] = used[y][x] + 1;
	Q.push(P(ny,nx));
      }
  }

  for(int i=0;i<h;i++)
    for(int j=0;j<w;j++)if(used[i][j] == -1) used[i][j]=INF;
  
} 


int visited[N][N][1<<5];
int dijkstra(int sy,int sx){
  map<P,int> M;
  int cnt=0;
  for(int i=0;i<h;i++)
    for(int j=0;j<w;j++)if(mp[i][j] == 'M') M[P(i,j)] = cnt++;
  
  for(int i=0;i<101;i++)
    for(int j=0;j<101;j++)
      for(int k=0;k<(1<<5);k++) D[i][j][k] = INF;
  
  priority_queue<PP,vector<PP>,greater<PP> >Q;  
  Q.push(PP(P(0,sy),P(sx,0)));
  D[sy][sx][0] = 0;
 
  while(!Q.empty()){
    PP t = Q.top();Q.pop();
    int cost = t.first.first;
    int y = t.first.second;
    int x = t.second.first;
    int bit = t.second.second;
    if(mp[y][x] =='G' && bit==(1<<cnt)-1)return cost;
    if(D[y][x][bit]<cost||visited[y][x][bit]++) continue;
    
    for(int i=0;i<4;i++){
      int nx = x+dx[i];
      int ny = y+dy[i];
      int nbit = bit;
      int ncost = cost+max(1,4-used[y][x]);
      if(nx<0||ny<0||nx>=w||ny>=h||mp[ny][nx] == '#')continue;
      if(D[ny][nx][nbit]<=ncost||visited[ny][nx][nbit])continue;
      if(mp[ny][nx] == 'M') nbit |= 1<<(M[P(ny,nx)]); 
      Q.push(PP(P(ncost,ny),P(nx,nbit)));
      D[ny][nx][nbit] = ncost;
    }
  }
  assert(0);
}


int main(){

  cin>>w>>h;
  for(int i=0;i<h;i++) cin>>mp[i];

  bfs();
  for(int i=0;i<h;i++)
    for(int j=0;j<w;j++)
      if(mp[i][j] == 'S') cout<<dijkstra(i,j)<<endl;

  return 0;
}

Measured memory_bytes: 5764
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        String str = sc.next();
        char[] a = str.toCharArray();
        int sum = 0;
        for (char c : a) {
            sum += Character.getNumericValue(c);
        }
        if (Integer.parseInt(str) % sum == 0) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}


Measured memory_bytes: 23124
#include <algorithm>
#include <functional>
#include <iostream>
#include <queue>
#include <tuple>
#include <vector>
using namespace std;

#define rep(i, n) for (int i = 0; i < (n); i++)

int main() {

  int n;
  cin >> n;
  struct E {
    int to, cost;
    E(int to, int cost) : to(to), cost(cost) {}
  };
  vector<vector<E>> g(n);
  rep(i, n - 1) {
    int a, b, c;
    cin >> a >> b >> c;
    g[a].emplace_back(b, c);
    g[b].emplace_back(a, c);
  }

  // 0 を根とする
  // dp[i]: 部分木 i の中で i から最も遠い頂点までの距離
  vector<int> dp(n);
  function<int(int, int)> dfs = [&](int i, int p) -> int {
    for (auto e : g[i]) {
      if (e.to != p) { dp[i] = max(dp[i], dfs(e.to, i) + e.cost); }
    }
    return dp[i];
  };
  dfs(0, -1);

  vector<int> dist(n);
  queue<tuple<int, int, int>> q;
  q.emplace(0, -1, 0);
  while (q.size() > 0) {
    int i, p, a;
    tie(i, p, a) = q.front();
    q.pop();
    int c = g[i].size();
    vector<int> le(c + 1);
    rep(o, c) {
      auto j = g[i][o].to;
      le[o + 1] = max(le[o], (j == p ? a : dp[j]) + g[i][o].cost);
    }
    vector<int> ri(c + 1);
    for (int o = c - 1; o >= 0; o--) {
      auto j = g[i][o].to;
      ri[o] = max(ri[o + 1], (j == p ? a : dp[j]) + g[i][o].cost);
    }
    rep(o, c) {
      auto j = g[i][o].to;
      if (j != p) { q.push(make_tuple(j, i, max(le[o], ri[o + 1]))); }
    }
    dist[i] = le[c]; // = ri[0]
  }
  int ans = 0;
  for (auto d : dist) {
    ans = max(ans, d);
  }
  cout << ans << endl;

  return 0;
}



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

typedef unsigned long long ULLONG;
typedef long long LLONG;
static const LLONG MOD_NUM = 1000000007; //998244353;

template<class _T> static void get(_T& a) {
	std::cin >> a;
}
template<class _T> static void get(_T& a, _T& b) {
	std::cin >> a >> b;
}
template<class _T> static void get(_T& a, _T& b, _T& c) {
	std::cin >> a >> b >> c;
}
template <class _T> static _T tp_abs(_T a) {
	if (a < (_T)0) {
		a *= (_T)-1;
	}
	return a;
}

static void exec();

int main()
{
	exec();
	fflush(stdout);
	return 0;
}

static void in(int& D, std::vector<int>& ci, std::vector<std::vector<int>>& sdi)
{
	get(D);

	for (auto& c : ci) {
		get(c);
	}
	
	sdi.resize(D);
	for (int i = 0; i < D; i++) {
		sdi[i].resize(26);
		for (auto& s : sdi[i]) {
			get(s);
		}
	}
}

static std::vector<int> calc(int& D, std::vector<int>& ci, std::vector<std::vector<int>>& sdi, std::vector<int>& ti)
{
	LLONG ans = 0;
	std::vector<int> last(26, 0), vi(D, 0);
	
	for (int d = 0; d < D; d++) {
		if (d) vi[d] = vi[d - 1];
		int held = ti[d];
		vi[d] += sdi[d][held];
		last[held] = d + 1;
		for (int c = 0; c < 26; c++) {
			vi[d] -= ci[c] * ((d + 1) - last[c]);
		}
	}
	return vi;
}

static void exec()
{
	int D = 0;
	std::vector<int> ci(26);
	std::vector<std::vector<int>> sdi;

	in(D, ci, sdi);
	std::vector<int> ti(D);
	for (auto& t : ti) {
		get(t);
		t--;
	}
	auto vi = calc(D, ci, sdi, ti);
	for (auto v : vi) {
		printf("%d\n", v);
	}
}


Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define mfill(x,y) memset(x,y,sizeof(x))
#define all(v) v.begin(), v.end()
#define in(x,y,h,w) if(0<=x&&x<h&&0<=y&&y<w)
#define y0 y12345
#define y1 y54321

#ifdef LOCAL
#define debug(...) fprintf(stderr,__VA_ARGS__)
#else
#define debug(...) 42
#endif

using ul = unsigned long;
using ll = long long;
using P = pair<int, int>;
using vint = vector<int>;using vvint = vector<vector<int>>;
using vll = vector<ll>;using vvll = vector<vector<ll>>;
template<class T>bool chmax(T &a, const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a, const T &b){if(a>b){a=b;return 1;}return 0;}
template <class T>void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
    v.assign(a, vector<T>(b, t));
}
template <class T>T gcd(T &a, T &b){if(a<b){swap(a,b);} T r = a%b; while(r!=0){a=b;b=r;r=a%b;} return b;}

vint dx = {-1, 0, 1, 0}, dy = {0, -1, 0, 1};
vint dx8 = {-1, -1, -1, 0, 1, 1, 1, 0}, dy8 = {-1, 0, 1, 1, 1, 0, -1, -1};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    debug("debug test\n");
    int n,m;cin>>n;
    int ans = 0;
    vint a(n), c(n);
    rep(i, n){
        cin>>a[i];
    }
    rep(i, n){
        int tmp;cin>>tmp;
        ans += tmp;
    }
    rep(i, n){
        cin>>c[i];
    }
    rep(i, n){
        if(a[i]+1==a[i+1]){
            ans += c[a[i]-1];
        }
    }
    cout << ans << endl;
    return 0;
}


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

const long INF = 1L << 60;

long memo[100010];

long rec(int x){
	if(x == 0) return 0;
	if(memo[x] != 0) return memo[x];
	long res = INF;
	for(int i = 1; i <= x; i*=6)
		res = min(res, rec(x-i) + 1);
	for(int i = 1; i <= x; i*=9)
		res = min(res, rec(x-i) + 1);
	return memo[x] = res;
}

int main(){
	int n;
	scanf("%d", &n);
	printf("%ld\n", rec(n));
}

Measured memory_bytes: 4096
#include <bits/stdc++.h>
using namespace std;
#define m_p make_pair
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define fi first
#define se second
typedef long long ll;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
mt19937 rnf(2106);
const int N = 200005;
struct ban
{
    int k, l, r;
};
bool operator<(const ban& a, const ban& b)
{
    return abs(a.l - a.r) < abs(b.l - b.r);
}

int n;
ban a[N];

void ubd(int tl, int tr, int x, int y, int pos, vector<int>& s, vector<int>& p)
{
    if (tl == tr)
    {
        s[pos] += y;
        p[pos] = min(p[pos], 0);
        return;
    }
    int m = (tl + tr) / 2;
    if (x <= m)
        ubd(tl, m, x, y, pos * 2, s, p);
    else
        ubd(m + 1, tr, x, y, pos * 2 + 1, s, p);
    s[pos] = s[pos * 2] + s[pos * 2 + 1];
    p[pos] = min(p[pos * 2], s[pos * 2] + p[pos * 2 + 1]);
}

void solv()
{
    scanf("%d", &n);
    for (int i = 1; i <= n; ++i)
        scanf("%d%d%d", &a[i].k, &a[i].l, &a[i].r);
    sort(a + 1, a + n + 1);
    reverse(a + 1, a + n + 1);

    vector<int> sl, pl, sr, pr;
    sl.assign(n * 4 + 5, 0);
    pl.assign(n * 4 + 5, 0);
    sr.assign(n * 4 + 5, 0);
    pr.assign(n * 4 + 5, 0);

    for (int i = 1; i <= n; ++i)
    {
        ubd(1, n, i, 1, 1, sl, pl);
        ubd(1, n, i, 1, 1, sr, pr);
    }

    ll ans = 0;
    for (int i = 1; i <= n; ++i)
    {
        if (a[i].l > a[i].r)
        {
            ubd(1, n, a[i].k, -1, 1, sl, pl);
            if (pl[1] < 0)
            {
                ubd(1, n, a[i].k, 1, 1, sl, pl);
                ans += a[i].r;
            }
            else
                ans += a[i].l;
        }
        else
        {
            if (n - a[i].k == 0)
            {
                ans += a[i].l;
                continue;
            }
            ubd(1, n, n - a[i].k, -1, 1, sr, pr);
            if (pr[1] < 0)
            {
                ubd(1, n, n - a[i].k, 1, 1, sr, pr);
                ans += a[i].l;
            }
            else
                ans += a[i].r;
        }
        //ubd(1, n, n, -2, 1, sl, pl);
        //ubd(1, n, 1, -2, 1, sr, pr);
    }
    printf("%lld\n", ans);
}

int main()
{
    #ifdef SOMETHING
    freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    #endif // SOMETHING
    int tt;
    scanf("%d", &tt);
    while (tt--)
        solv();
    return 0;
}

//while ((double)clock() / CLOCKS_PER_SEC <= 0.9){}


Measured memory_bytes: 18004
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1000000007;
const ll LINF=1LL<<60;
const int INF=1<<30;

int main(){
	int a,b,x;
	cin >> x >> a >> b;
	x -= a;
	while(x - b >=0){
		x -= b;
	}
	cout << x << endl;
	return 0;
}

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

using namespace std;

#ifdef WIN32
	#define I64 "%I64d"
#else
	#define I64 "%lld"
#endif

typedef long long ll;

#define f first
#define s second
#define mp make_pair
#define pb push_back
#define all(s) s.begin(), s.end()
#define sz(s) (int(s.size()))
#define fname "a"
#define MAXN 4000004

int n;
int a[MAXN];

int main()
{
	#ifdef LOCAL
	freopen(fname".in", "r", stdin);
	freopen(fname".out", "w", stdout);
	#endif

	scanf("%d", &n);
	for (int i = 0; i < n; ++i) {
		scanf("%d", &a[i]);
	}

	sort(a, a + n);

	vector <int> ans;
	for (int i = n - 2; i >= 0 && sz(ans) < 2; --i) {
		if (a[i] == a[i + 1]) {
			ans.pb(a[i]);
			i--;
			continue;
		}
	}

	printf(I64"\n", sz(ans) < 2 ? 0LL : 1LL * ans[0] * ans[1]);

	return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace __gnu_pbds;
using namespace std;
#define pb push_back
#define ll long long
#define mp make_pair
#define vip vector
#define ss second
#define ff first 
#define pii pair<int,int>
#define pll pair<ll,ll>
#define M 1000000007
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
   double a,b;
  cin>>a>>b;
  double r=a*b;
  cout<<floor(r*1.0);
  cout<<"\n";
}

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


int main () {
    int a, b;
    cin >> a >> b;
    int ans = a - b * 2 ;
    if (ans > 0){
        cout << ans << endl;
    }
    else {
        cout << 0 << endl;
    }

}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cmath>
#include <string>
#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 <tuple>
#include <numeric>
#define rep(i, s, g) for ((i) = (s); (i) < (g); ++(i))
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll MOD = 1e9 + 7;
const ll INF = (1ll << 60);

int main(void)
{
    int n;
    cin >> n;
    vector<int> a(n);

    for (auto &&i : a)
    {
        cin >> i;
    }

    ll money = 1000;
    ll stock = 0;

    for (int i = 0; i < n; i++)
    {
        if (stock)
        {
            money += a[i] * stock;
            stock = 0;
        }

        if (i == n - 1)
        {
            break;
        }

        if (a[i] < a[i + 1])
        {
            stock += money / a[i];
            money %= a[i];
        }
    }

    cout << money << endl;
}


Measured memory_bytes: 3564
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#include <iostream>
#include <string>
#include <algorithm>
#include <unordered_set>
using namespace std;

int main(){
    int n,m,l;
    cin >> n >> m >> l;
    cout <<((n-1)/m+1)*l<< endl;
}

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, from, to) for (int i = from; i < (to); ++i)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
using ll = long long;
using vin=vector<int>;
using vll=vector<ll>;
using P = pair<int, int>;
const int inf=1e9+7;
const ll INF=1e18;
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() {
  int p,q,r;
  cin>>p>>q>>r;
  cout<<p+q+r-max(max(p,q),r)<<endl;
}









Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.ComponentModel.Design.Serialization;
using System.Linq;

namespace ABC161F
{
    class Program
    {
        static void Main(string[] args)
        {
            long N = long.Parse(Console.ReadLine());

            int root = (int)Math.Pow(N, 0.5);

            long N1 = N;
            long N2 = N - 1;
            var set = new HashSet<long> { N };
            for (int i = 2; i <= root; i++)
            {
                long n = N1;
                while (n % i == 0) n /= i;
                if (n % i == 1) set.Add(i);
            }
            for (int i = 1; i <= root; i++)
            {
                long n = N2;
                if (n % i == 0)
                {
                    if (i != 1) set.Add(i);
                    if (i != n / i) set.Add(n / i);
                }
            }

            Console.WriteLine(set.Count);
            Console.ReadKey();
        }

        static int[] ReadInt()
        {
            int[] ret = Console.ReadLine().Split().Select(int.Parse).ToArray();
            return ret;
        }
        static long[] ReadLong()
        {
            long[] ret = Console.ReadLine().Split().Select(long.Parse).ToArray();
            return ret;
        }
    }
}


Measured memory_bytes: 13524
#include<bits/stdc++.h>
using namespace std;
int main(){
  int w, h, n;
  cin >> w >> h >> n;
  int l, r, u, d;
  l = 0; r = w; u = h; d = 0;
  for(int i = 0, x, y, a; i < n; ++i){
    cin >> x >> y >> a;
    if(a == 1){
      l = max(x, l);
    }
    else if(a == 2){
      r = min(x, r);
    }
    else if(a == 3){
      d = max(y, d);
    }
    else {
      u = min(y, u);
    }
  }
  if(r - l <= 0 || u - d <= 0) cout << 0 << endl;
  else cout << (r - l) * (u - d) << endl;
}

Measured memory_bytes: 256
import math
n, d = map(int, input().split())
x = []
ans = 0
for i in range(n):
    x.append(list(map(int, input().split())))

def jadge(one ,two):
    z = 0
    for i in range(d):
        z += (one[i] - two[i]) ** 2
    z = math.sqrt(z)
    if z == int(z):
        return 1
    else:
        return 0
for one in range(n-1):
    for two in range(one+1,n):
        ans += jadge(x[one], x[two])
print(ans)



Measured memory_bytes: 3064
#include <stdio.h>

int main()
{
   int k;
   int x;
   scanf("%d %d", &k, &x );
   
   if (k*500 < x){
       printf("%s\n", "No");
   }
   else{
       printf("%s\n", "Yes");
   }
   
   return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
#include<iomanip>

#define fast_io ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

using namespace std;

#define debug(x) cout<<(#x)<<"="<<(x)<<", ";
#define debug1(x) debug(x) cout<<'\n';
#define debug2(x1, x2) debug(x1) debug(x2) cout<<'\n';
#define debug3(x1, x2, x3) debug(x1) debug(x2) debug(x3) cout<<'\n';
#define debug4(x1, x2, x3, x4) debug(x1) debug(x2) debug(x3) debug(x4) cout<<'\n';
#define debug5(x1, x2, x3, x4, x5) debug(x1) debug(x2) debug(x3) debug(x4) debug(x5) cout<<'\n';

#define fcout cout<<fixed<<setprecision(15)
#define repp(i,j,k) for(int i=j; i<k; ++i)
#define rep(i,j) repp(i,0,j)
#define rrep(i,j,k) for(int i=j; i>=k; --i)
#define all(x) (x).begin(), (x).end()
#define sort(x) sort(x.begin(), x.end())
#define lb(x,val) lower_bound(x.begin(), x.end(), val)
#define ub(x,val) upper_bound(x.begin(), x.end(), val)
#define pb(x) emplace_back(x);

typedef long long int lli;
typedef pair<int,int> pii;
typedef pair<lli,lli> pll;
typedef vector<int> vi;
typedef vector<lli> vl;
typedef tuple<int, int, lli> tiil;

//const lli M=998244353ll;
const lli M=1000000007ll;
const double D=1.0;

int main(){
	fast_io
	char a,b; cin>>a>>b;
	if(a=='H') cout<<b;
	else if(b=='D') cout<<'H';
	else cout<<'D';
	return 0;
}

Measured memory_bytes: 256
import sys
INF = 1 << 60
MOD = 10**9 + 7 # 998244353
sys.setrecursionlimit(2147483647)
input = lambda:sys.stdin.readline().rstrip()
def resolve():
    n = int(input())
    C = [complex(*map(int, input().split())) for _ in range(n)]

    res = INF
    for k in range(n):
        p1 = C[k]
        for j in range(k):
            p2 = C[j]
            for i in range(j):
                p3 = C[i]
                a = abs(p2 - p3) ** 2
                b = abs(p3 - p1) ** 2
                c = abs(p1 - p2) ** 2
                numerator = a * (b + c - a) * p1 + b * (c + a - b) * p2 + c * (a + b - c) * p3
                denominator = a * (b + c - a) + b * (c + a - b) + c * (a + b - c)
                if denominator == 0.0:
                    continue
                center = numerator / denominator
                radius = -INF
                for p in C:
                    radius = max(radius, abs(center - p))
                res = min(radius, res)

    for j in range(n):
        for i in range(n):
            center = (C[i] + C[j]) / 2
            radius = -INF
            for p in C:
                radius = max(radius, abs(center - p))
            res = min(radius, res)

    print(res)
resolve()

Measured memory_bytes: 42608
#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 n;
  cin >> n;
  vector<int> a(n+1);
  rep(i,n) cin >> a[i+1];
  
  int ans = 0;
  rep(i,n){
    if((i+1) % 2 == 0) continue;
    if(a[i+1] % 2 != 0) ans++;
  }
  
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3588
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n,i;
   string s,ans; 
   cin>>s;
   n=s.length();
   for(i=0;i<n;i+=2){
      if(s[i]=='L') ans="No";
   }
   for(i=1;i<n;i+=2){
      if(s[i]=='R') ans="No";
   }
   if(ans=="No"){
    cout<<ans<<endl;
	}
   else {
   cout<<"Yes"<<endl;
   }
   return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
int main(void){
	char m[4];
	char n[4];
	int i;
	int cnt = 0;
	scanf("%s",m);
	scanf("%s",n);
	for(i=0;i<3;i++){
		if(m[i] == n[2-i]){
			cnt++;
		}
	}
	if(cnt == 3){
		printf("YES");
	}else{
		printf("NO");
	}
	return 0;
}

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

using namespace std;

int main(){
    string a,b;
    cin >> a >> b;
    for(int i = 0; i < 3; i++){
        if(a[i] != b[2-i]){
            cout << "NO\n";
            return 0;
        }
    }
    cout << "YES\n";
    return 0;
}

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

template<class S>S sum(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
ll min(int a,ll b){return min((ll)a,b);} ll min(ll a,int b){return min(a,(ll)b);}
template <class S> void print(vector<S> &v){for(ll i=0; i<(ll)v.size(); i++){cerr << v[i] << ' ';}cerr << endl;}
template <class S> void print(vector<vector<S>> &v) {for (ll i = 0; i < (ll)v.size(); i++) {for (ll j = 0; j < (ll)v[i].size(); j++) {cerr << v[i][j] << ' ';}cerr << endl;}}

void Main();

int main(){
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(20);
	Main();
	return 0;
}

struct UnionFind {
  vector<int> d;
  UnionFind(int n=0): d(n,-1) {}
  int find(int x) {
    if (d[x] < 0) return x;
    return d[x] = find(d[x]);
  }
  bool unite(int x, int y) {
    x = find(x); y = find(y);
    if (x == y) return false;
    if (d[x] > d[y]) swap(x,y);
    d[x] += d[y];
    d[y] = x;
    return true;
  }
  bool same(int x, int y) { return find(x) == find(y);}
  int size(int x) { return -d[find(x)];}
};

void Main(){
	int n,m; cin >> n >> m;
	UnionFind uf(n);
	int ans = n;
	Rep(m){
		int x,y,z; cin >> x >> y >> z;
		x--; y--;
		ans -= uf.unite(x,y);
	}
	cout << ans << endl;
}

Measured memory_bytes: 3696
//Created by:Coding_lover(17-06-2020 09:50:41)
#include <bits/stdc++.h>
#define ll long long
#define FASTER ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define endl '\n'
#define INF LLONG_MAX
#define f first
#define s second
#define LB lower_bound
#define UB upper_bound
#define pi pair<long long,long long>
#define pii pair<long long,pi>
#define pb push_back
#define all(v) v.begin(),v.end()
#define sz(v) v.size()
#define vc vector
#define vll vector<long long>
#define rep(i, a, n) for (ll i = a; i < (long long)n; ++i)
#define repe(i, a, n) for (ll i = a; i <= (long long)n; ++i)
#define repr(i, n, a) for (ll i = n; i > (long long)a; --i)
#define repre(i, n, a) for (ll i = n; i >= (long long)a; --i)
using namespace std;
int main() {
  FASTER;
  ll t;
  t=1;
  //cin >> t;
  while (t--) {
  	ll n,k;
  	cin>>n>>k;
  	vll h(n);
  	rep(i,0,n)cin>>h[i];
  	vll dp(n,INF);
  	dp[0]=0;
  	dp[1]=abs(h[0]-h[1]);
  	rep(i,0,n)
  	{
  		ll j=(i-k)>=0?i-k:0;
  		for(;j<=i;j++)
  		{
  			dp[i]=min(dp[i],dp[j]+abs(h[i]-h[j]));
  		}
  		//cout<<i<<" "<<dp[i]<<endl;
  	}
  	cout<<dp[n-1]<<endl;
  }
  return 0;
}


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

using namespace std;

int main()
{
    int number;
    cin >> number;

    while (number > 0)
    {
        if (number % 10 == 7)
        {
            cout << "Yes";
            return 0;
        }

        number = number / 10;
    }

    cout << "No";

    return 0;
}

Measured memory_bytes: 3588
#include<bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
//long long int countt[200003];
#include<ext/pb_ds/assoc_container.hpp> // include the associative containers or group of templates such as set, multimap, map etc.
#include<ext/pb_ds/tree_policy.hpp> // include the tree_order_statistics_node update
using namespace __gnu_pbds; //necessary for the GNU based Policy based data structures.
typedef tree<pair<int,int> ,null_type,less<pair<int,int>>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

#define int long long
#define endl "\n"


signed main()
{
    FAST;
    
    int i=0,j=0,k=0,n=0,m=0,count=0,temp=0;
    int temp1=0,temp2=0,temp3=0,x=0,l=0,y=0,sum=0;
    int left=0,up=0,anss=0,start=0,end=0,r=0,q=0,total=0;
    int maxx=0,minn=0,curr=0,ans=0,places=0,zeroes=0,low=0,high=0;
    int prev=0,mid=0,z=0,d=0,val=0,pos=0,shift=0,h=0,right=0,var=0;
    
    cin>>n;
    while(n!=0)
    {
        temp = n%10;
        n=n/10;
        
        if(temp==7){ cout<<"Yes"<<endl;
        return 0;}
    }
    
    cout<<"No"<<endl;
    return 0;
    
    
    
    
        
    
}

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

namespace _20191021
{
    class Program
    {
        static void Main(string[] args)
        {
            int a;
            string s;

            a = int.Parse(Console.ReadLine());
            s = Console.ReadLine();

            if (a >= 3200)
                Console.WriteLine(s);

            else
                Console.WriteLine("red");
            
        }
    }
}


Measured memory_bytes: 13140
#include<iostream>

using namespace std;

char pattern[51][51];
char input[51][51];

int main() {
	
	ios_base::sync_with_stdio(0);
	cin.tie(0);
		
	int n,m; cin >> n >> m;
	
	for(int i = 0; i < n; i++) cin >> input[i];
	for(int i = 0; i < m; i++) cin >> pattern[i];
	
	for(int i = 0; i < n; i++) {
		for(int j = 0; j < n; j++) {
			if(i+m <= n && j+m <= n) {
				bool can = true;
				
				for(int k = 0; k < m && can; k++) {
					for(int l = 0; l < m && can; l++) {
						if(input[i+k][j+l] != pattern[k][l]) {
							can = false;
						}
					}
				}
				if(can) {
					cout << "Yes\n";
					return 0;
				}
			}
		}
	}
	
	cout << "No\n";
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int MOD = pow(10, 9) + 7;
//const int MOD = 998244353;
//const int MOD = ;
int mod(int A, int M) {return (A % M + M) % M;}
const int INF = 1LL << 60;
const string ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const string abc = "abcdefghijklmnopqrstuvwxyz";
template <class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template <class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
int divCeil(int A, int B) {return (A + (B - 1)) / B;}

signed main()
{
  int N;
  cin >> N;
  vector<int> a(N);
  for (int i = 0; i < N; i++)
  {
    cin >> a.at(i);
  }
  a.push_back(0);
  
  int ans = 0;
  int c = 0, l = 0;
  for (int i = 0; i < N + 1; i++)
  {
    if (c == a.at(i)) l++;
    else
    {
      //cerr << i << " " << divCeil(l, 2) << endl;
      ans += divCeil(l, 2);
      l = 0;
    }
    c = a.at(i);
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a) for(int i=0; i<(a); i++)
typedef long long ll;
template<typename T>
struct edge {
  int src, to;
  T cost;
  edge(int to, T cost) : src(-1), to(to), cost(cost) {}
  edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}
  edge &operator=(const int &x) {
    to = x;
    return *this;
  }
  operator int() const { return to; }
};
template<typename T>
using Edges = vector<edge<T>>;
template<typename T>
using WeightedGraph = vector<Edges<T>>;
using UnWeightedGraph = vector<vector<int>>;
template<typename T>
using Matrix = vector<vector<T>>;

/////////////////////////////////////////////////////////////////////
const ll inf = 1LL<<60;
const ll mod = 1000000007;

struct mint {
  ll x;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x); }
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this; }
  mint operator+(const mint a) const { return mint(*this)+=a; }
  mint operator-(const mint a) const { return mint(*this)-=a; }
  mint operator*(const mint a) const { return mint(*this)*=a; }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
  mint inv() const { return pow(mod-2); }
  mint& operator/=(const mint a) { return (*this) *= a.inv(); }
  mint operator/(const mint a) const { return mint(*this)/=a; }
  bool operator==(const mint a) const { return x == a.x; }
  bool operator!=(const mint a) const { return x != a.x; }
  friend ostream &operator<<(ostream &os, const mint &p) { return os << p.x; }
  friend istream &operator>>(istream &is, mint &a) {
    ll t;
    is >> t;
    a = mint(t);
    return (is);
  }
};

template<typename T>
struct Comb {
  vector<T> fact, finv, inv;
  Comb(int n) : fact(n, 1), finv(n, 1), inv(n, 1) { init(n); }
  void init(int n) {
    fact.assign(n, 1), finv.assign(n, 1), inv.assign(n, 1);
    for (ll i=2; i<n; i++) {
      fact[i] = fact[i-1] * i % mod;
      inv[i] = mod - inv[mod%i] * (mod/i) % mod;
      finv[i] = finv[i-1] * inv[i] % mod;
    }
  }
  T nck(int n, int k) {
    if (n<k || n<0 || k<0) return 0;
    return fact[n] * (finv[k] * finv[n-k] % mod) % mod;
  }
  T nhk(int n, int k) { return nck(n+k-1, k); }
  T npk(int n, int k) {
    if (n<k || n<0 || k<0) return 0;
    return fact[n] * finv[n-k] % mod;
  }
};

int main()
{
  ll n, k; cin>>n>>k;
  Comb<ll> c(100005);
  for (int i=1; i<=k; i++) {
    mint t = c.nck(n-k+1, i) * c.nhk(i, k-i);
    cout << t << endl;
  }

  return 0;
}


Measured memory_bytes: 5620