akhauriyash/Code-Regression huggingface dataset:
H, W = map(int, input().split())
S = [list(input()) for _ in range(H)]
edge = []

# 横の比較
for i in range(H):
    for j in range(W-1):
        if S[i][j] != S[i][j+1]:
            edge.append((i*W+j,i*W+j+1))
# 縦の比較
for i in range(H-1):
    for j in range(W):
        if S[i][j] != S[i+1][j]:
            edge.append((i*W+j, (i+1)*W+j))

class UnionFind():
    '''
    UnionFindでグラフの状態を管理する
    '''
    def __init__(self, n):
        self.n = n
        self.root = [-1]*(n+1)
        self.rnk = [0]*(n+1)

    def is_root(self, x):
        return self.root[x] < 0

    def find_root(self, x):
        '''
        ルートのノードを見つける
        '''
        if(self.root[x] < 0):
            return x
        else:
            self.root[x] = self.find_root(self.root[x])
            return self.root[x]

    def unite(self, x, y):
        '''
        ノード同士を連結する
        '''
        x = self.find_root(x)
        y = self.find_root(y)
        if(x == y):
            return 
        elif(self.rnk[x] > self.rnk[y]):
            self.root[x] += self.root[y]
            self.root[y] = x
        else:
            self.root[y] += self.root[x]
            self.root[x] = y
            if(self.rnk[x] == self.rnk[y]):
                self.rnk[y] += 1

    def is_same_group(self, x, y):
        '''
        同一のルーツを持つかどうか調査する
        '''
        return self.find_root(x) == self.find_root(y)

    def count(self, x):
        return -self.root[self.find_root(x)]

union = UnionFind(H*W)
for l, r in edge:
    union.unite(l, r)
cnt = [0] * (H*W)
for i in range(H*W):
    c = union.find_root(i)
    if S[i//W][i%W] == "#":
        cnt[c] += 1

ans = 0
for i in range(H*W):
    if union.is_root(i):
        r = union.find_root(i)
        c = union.count(i)
        ans += cnt[r] * (c-cnt[r])
print(ans)


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

int main() {
    int H, W;
    long long int result;

    cin >> H >> W;

    if (H == 1 || W == 1)
        cout << 1 << endl;
    else {
        result = ((long long int) H * W + 1)/2;

        cout << result << endl;
    }
}


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

struct edge{
    int from, to;
    long long cost;
};

bool bellman_ford(int v, const vector<edge>& es, vector<long long>& cost, int s = 0, int g = -1){
    if(g == -1){
        g = v - 1;
    }

    const long long INF = 1LL << 61;

    cost.resize(v);
    fill(cost.begin(), cost.end(), INF);
    cost[s] = 0;

    for(int i = 0 ; i < v * 2 ; ++i){
        for(auto& e : es){
            if(cost[e.from] < INF && cost[e.from] + e.cost < cost[e.to]){
                cost[e.to] = cost[e.from] + e.cost;
                if(i >= v - 1 && e.to == g){
                    return false;
                }else if(i >= v - 1){
                    cost[e.to] = -INF;
                }
            }
        }
    }

    return true;
}

#include<iostream>

int main(){
    int n, m;
    long long p;
    cin >> n >> m >> p;

    vector<edge> es;
    for(int i = 0 ; i < m ; ++i){
        int a, b;
        long long c;
        cin >> a >> b >> c;
        es.push_back({a - 1, b - 1, p - c});
    }

    vector<long long> cost;
    if(bellman_ford(n, es, cost)){
        cout << max(-cost[n - 1], 0LL) << endl;
    }else{
        cout << -1 << endl;
    }

    return 0;
}

Measured memory_bytes: 512
package main

import (
	"fmt"
)

func main() {
	var S string
	fmt.Scan(&S)

	ans := func(s string) (ans string) {
		if len(S)%2 != 0 {
			return "No"
		}

		for i := 0; i < len(S)-1; i = i + 2 {
			if S[i] != 'h' || S[i+1] != 'i' {
				return "No"
			}
		}

		return "Yes"

	}(S)

	fmt.Println(ans)
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)

using namespace std;
using ll = long long;

void Main() {
	int n; cin >> n;
	vector<int> ds(n);
	REP(i, n) cin >> ds[i];
	long long res = 0;
	REP(i,n) {
		for (int j = i + 1; j < n; ++j) {
			res += ds[i] * ds[j];
		}
	}
	cout << res << endl;
}

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


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
def main():
    class UnionFindTree:
        def __init__(self, n):
            self.parent = [-1] * n

        def root(self, x):
            p, s = self.parent[x], list()
            while p >= 0:
                s.append(x)
                x, p = p, self.parent[p]
            for c in s: self.parent[c] = x
            return x

        def same(self, x, y): return self.root(x) == self.root(y)

        def count(self, x): return -self.parent[self.root(x)]

        def unite(self, x, y):
            xr, yr = self.root(x), self.root(y)
            if xr == yr: return
            if self.parent[xr] > self.parent[yr]: xr, yr = yr, xr
            self.parent[xr] += self.parent[yr]
            self.parent[yr] = xr

    N, M, K=map(int, input().split())
    friend_or_block = [0] * N
    friends_chain = UnionFindTree(N)

    for _ in range(M):
        a, b = map(int, input().split())
        a, b = a-1, b-1
        friends_chain.unite(a, b)
        friend_or_block[a] += 1
        friend_or_block[b] += 1

    for _ in range(K):
        c, d = map(int, input().split())
        c, d = c-1, d-1
        if friends_chain.same(c, d):
            friend_or_block[c] += 1
            friend_or_block[d] += 1

    print(*[friends_chain.count(i) - friend_or_block[i] - 1 for i in range(N)])

if __name__ == '__main__':
    main()



Measured memory_bytes: 62296
using System;

namespace ABC152
{
    public class EmptyClass
    {
        public static void Main(string[] args)
        {
            long n = long.Parse(Console.ReadLine());
            long[] p = Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse);

            long min = n;
            long cnt = 0;
            for (int i = 0; i < n; i++)
            {
                if (p[i] <= min)
                {
                    min = p[i];
                    cnt++;
                    if (min == 1) break;
                    continue;
                }
            }
            Console.WriteLine(cnt);
        }
    }
}


Measured memory_bytes: 31836
#pragma GCC optimize(3)
#include<bits/stdc++.h>
#define MAXN 100005
#define INF 1000000000
#define MOD 1000000007
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int n,a[MAXN],b[MAXN];
int main()
{
    scanf("%d",&n);
    ll ans=0;
    for(int i=0;i<n;i++)
    {
        scanf("%d%d",&a[i],&b[i]);
        ans+=a[i];a[i]+=b[i];
    }
    sort(a,a+n,greater<int>());
    for(int i=1;i<n;i+=2) ans-=a[i];
    printf("%lld\n",ans);
    return 0;
}



Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using Map = map<ll,ll>;
using T = tuple<ll,ll,ll>;
using vvl = vector<vector<ll>>;
#define all(v) v.begin(), v.end()
#define print(v) cout<<v<<endl;
#define first(v) get<0>(v)
#define second(v) get<1>(v)
#define third(v) get<2>(v)
template <typename T> bool chmax(T &a, const T &b){if (a<b){a=b;return 1;}return 0;}
template <typename T> bool chmin(T &a, const T &b){if (a>b){a=b;return 1;}return 0;}
const ll INF=1LL<<60;
const ll MOD=1000000007;


int main(){
    ll H;
    cin >> H;
    ll W;
    cin >> W;
    vector<vector<char>> S(H, vector<char>(W));
    for(ll i=0;i<H;i++){
       for(ll j=0;j<W;j++){
           cin>>S[i][j]
       ;}
    ;}
    vector<vector<ll>> dp(H, vector<ll>(W, INF));
    if(S[0][0]=='.')dp[0][0]=0;
    else dp[0][0]=1;
    for(ll i=0;i<H;i++){
       for(ll j=0;j<W;j++){
           if(S[i][j]=='.'){
               if(i-1>=0){
                   chmin(dp[i][j],dp[i-1][j]);
               }
               if(j-1>=0){
                   chmin(dp[i][j],dp[i][j-1]);
               }
           }
           else{
               if(i-1>=0){
                   if(S[i-1][j]=='#'){
                       chmin(dp[i][j],dp[i-1][j]);
                   }
                   else chmin(dp[i][j],dp[i-1][j]+1);
               }
               if(j-1>=0){
                   if(S[i][j-1]=='#'){
                       chmin(dp[i][j],dp[i][j-1]);
                   }
                   else chmin(dp[i][j],dp[i][j-1]+1);
               }
           }
       ;}
    ;}
    print(dp[H-1][W-1]);

    return 0;
}


Measured memory_bytes: 3728
#include<stdio.h>
int main(void){
	int H, W;
	int i, j;
	while(1){
		//値を2つ入力
		scanf("%d %d", &H, &W);
		//値が2つとも0なら終了
		if(H == 0 && W == 0){
			break;
		}
		//長方形を出力
		for(i = 0; i < H; i++){
			for(j = 0; j < W; j++){
				if(i == 0 || i == (H - 1)){
					if(j == (W - 1)){
						printf("#\n");
					}else{
						printf("#");
					}
				}else{
					if(j == 0){
						printf("#");
					}else if(j == (W - 1)){
						printf("#\n");
					}else{
						printf(".");
					}
				}
			}
		}
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 588
import java.util.*;
public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		String[] a = new String[n];
		String[] b = new String[m];
		for(int i = 0; i < n; i++) {
			a[i] = sc.next();
		}
		for(int i = 0; i < m; i++) {
			b[i] = sc.next();
		}
		boolean search = false;
		for(int i = 0; i < n - m + 1 && !search; i++) {
			for(int j = 0; j < n - m + 1 && !search; j++) {
				boolean ok = true;
				for(int k = 0; k < m && ok; k++) {
					for(int l = 0; l < m && ok; l++) {
						if(a[i + k].charAt(j + l) != b[k].charAt(l)){
							ok = false;
						}
					}
				}
				if(ok) {
					search = true;
				}
			}
		}
		System.out.println(search ? "Yes" : "No");

	}

}

Measured memory_bytes: 21716
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,d[1000],h[1000000]={};
  cin>>n;
  for(int i=0;i<n;i++)cin>>d[i];
  for(int i=n-1;i>=0;i--){
    int t=0,t10=1;
    for(int j=i;i-j<6&&j>=0;j--,t10*=10){
      t+=d[j]*t10;
      h[t]++;
    }
  }
  for(int i=0;;i++){
    if(h[i]==0){
      cout<<i<<endl;
      break;
    }
    }
  return 0;
}

Measured memory_bytes: 7008
/**
 * author: Dhakad_123
 * created: 26.04.2020
**/

#include<bits/stdc++.h>
using namespace std;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    
    
    
    int n;
    cin >> n;
    set<string>ans;
    for(int i = 0; i < n; i++){
        string nums;
        cin >> nums;
        ans.insert(nums);
    }
    
    cout << ans.size() << "\n";
   
    return 0;
}

Measured memory_bytes: 19204
#include <bits/stdc++.h>
#define fastIO (cin.tie(0), cout.tie(0), ios::sync_with_stdio(false))
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define precise(i) fixed << setprecision(i)
using namespace std;

int main() {
    fastIO;
    int n, k;
    cin >> n >> k;
    if (n % k == 0)
        cout << 0;
    else
        cout << 1;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define rep(i,ini,n) for(int i=ini;i<n;i++)
#define _rep(i,ini,n) for(int i=ini;i>=n;i--)
#define ToEnd(a) a.begin(),a.end()
uint64_t MOD=1000000007;

int64_t CalcCmb(int64_t n, int64_t m=2){
    return n*(n-1)/2;
}

int main(){
    int N; cin>>N;
    vector<int> A(N,N);
    rep(n,0,N) cin>>A.at(n);

    vector<int> CntA(N,0);
    for(auto a:A) CntA.at(a-1)++;

    int64_t sumCmb=0;
    for(auto ca:CntA) if(ca>=2) sumCmb+=CalcCmb(ca);

    for(auto a:A){
        int64_t ans=sumCmb;
        if(CntA.at(a-1)>=2) ans-=CalcCmb(CntA.at(a-1));
        if(CntA.at(a-1)-1>=2) ans+=CalcCmb(CntA.at(a-1)-1);
        cout<<ans<<endl;
    }
}

Measured memory_bytes: 4096
#include <bits/stdc++.h>
using namespace std;
 
int main() {
	int i,j,N,M,Max;
  	int A = 0;
    vector<int> Ans(0);
  cin >> N;
  vector<string> s(N);
  for(i=0;i<N;i++){
  cin >> s.at(i);
  }
  cin >> M;
  vector<string> t(M);
  for(i=0;i<M;i++){
  cin >> t.at(i);
  }
  
  for(i=0;i<N;i++){
    for(j=0;j<N;j++){
      if(s.at(i)==s.at(j)){
      A++;
      }
    }
    for(j=0;j<M;j++){
      if(s.at(i)==t.at(j)){
      A--;
      }
    }
    Ans.push_back(A);
    A = 0;
  }
    
  sort(Ans.begin(),Ans.end());
  reverse(Ans.begin(),Ans.end());
  if(Ans.at(0)>0){
  cout << Ans.at(0) <<endl;
  }else{cout <<0 << endl;}
  
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back
#define INF (1e9+1)
//#define INF (1LL<<59)

int main(){
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	
	cout<<max(a*b,c*d)<<endl;
}


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

struct sakumotu {
	string name;
	double kouritu;
};
bool operator < (sakumotu a,sakumotu b) {
	if (a.kouritu != b.kouritu)return a.kouritu > b.kouritu;
	return a.name < b.name;
}
int main() {
	int a;
	while (cin >> a, a) {
		sakumotu b[50];
		for (int c = 0; c < a; c++) {
			sakumotu d;
			string e;
			int f[9];
			cin >> e;
			for (int g = 0; g < 9; g++)cin >> f[g];
			d.name = e;
			d.kouritu = double(f[6] * f[7] * f[8] - f[0])/(f[1]+f[2]+f[3]+f[8]*(f[4]+f[5]));
			b[c] = d;
		}
		sort(b, b + a);
		for (int i = 0; i < a; i++) {
			cout << b[i].name << endl;
		}
		cout << '#' << endl;
	}
}

Measured memory_bytes: 3108
using System;

class Task4
{
    public static void Main(string[] args)
    {
        string[] max = Console.ReadLine().Split(' ');
        int N = int.Parse(max[0]);
        int A = int.Parse(max[1]);
        int B = int.Parse(max[2]);
        int taxi = N * A;
        int ans = Math.Min(taxi, B);
        Console.WriteLine(ans);
    }
}

Measured memory_bytes: 13140
import itertools
import sys
X = int(input())
A = [i for i in range(100, 106)]
num = int(X/100)
if X < 100: print(0)
elif X > 105*num: print(0)
else:
    for comb in itertools.combinations_with_replacement(A, num):
        if X == sum(comb):
            print(1)
            sys.exit()
    print(0)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    long long N,result=0;
    cin >> N;
 
    for (long i = 1 ; i<=N; i++) {
        if (i%3!=0 && i%5!=0) {
            result += i;
        }
    }

    cout << result << endl;



  	return 0;
}


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

using namespace std;
struct _ { ios_base::Init i; _() { ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); } } _;

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c> {i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef HOME
	~debug() { cerr << endl; }
	eni( != ) cerr << boolalpha << i; ris;
}
eni( == ) ris << range(begin(i), end(i));
}
sim, class b dor(pair < b, c > d) {
	ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
	*this << "[";
	for (auto it = d.b; it != d.e; ++it)
		*this << ", " + 2 * (it == d.b) << *it;
	ris << "]";
}
#else
	sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

long long  x, y, a, b, c;
vector<long long > red, green, cless;
vector<long long > pred, pgreen, pcless;

long long  f(long long  i, long long  j) {
	if (i<0 or i > a or j<0 or j > b or x - i + y - j < 0 or x - i + y - j > c) return 0;
	return pred[i] + pgreen[j] + pcless[x - i + y - j];
}
/*
2 2 1
9 6 4 1
9 8 7 3 1

i, j, x-i+y-j
0<=i<=x, 0<=j<=y
0<=x-i+y-j<=c
-x-y<=-i-j<=c-x-y
x+y>=i+j>=x+y-c
x+y-i>=j>=x+y-c-i
x+y-c-i<=j<=x+y-i
*/

int main() {

	cin >> x >> y >> a >> b >> c;
	red.resize(a + 1, 0), green.resize(b + 1, 0), cless.resize(c + 1, 0);

	for (long long  i = 1; i <= a; i++) cin >> red[i];
	for (long long  i = 1; i <= b; i++) cin >> green[i];
	for (long long  i = 1; i <= c; i++) cin >> cless[i];

	sort(red.begin() + 1, red.end(), greater<long long >());
	sort(green.begin() + 1, green.end(), greater<long long >());
	sort(cless.begin() + 1, cless.end(), greater<long long >());

	pred.resize(a + 1, 0), pgreen.resize(b + 1, 0), pcless.resize(c + 1, 0);

	for (int i = 1; i <= a; i++) pred[i] = pred[i - 1] + red[i];
	for (int i = 1; i <= b; i++) pgreen[i] = pgreen[i - 1] + green[i];
	for (int i = 1; i <= c; i++) pcless[i] = pcless[i - 1] + cless[i];

	// debug() << imie(pred);
	// debug() << imie(pgreen);
	// debug() << imie(pcless);

	// for (int i = 0; i <= x; i++) {
	// 	debug() << imie(i);
	// 	for (int j = 0; j <= y; j++) {
	// 		if (x - i + y - j > c) continue;
	// 		debug() << imie(j) imie(pred[i] + pgreen[j] + pcless[x - i + y - j]);
	// 	}
	// }

	long long ans = 0;

	for (int i = 0; i <= x; i++) {
		long long  lo = max(0ll, x + y - c - i), hi = min(y, x + y - i);
		debug() << imie(i) imie(lo) imie(hi);
		while (hi - lo >= 3) {
			long long  m1 = lo + (hi - lo) / 3;
			long long  m2 = hi - (hi - lo) / 3;
			// debug() << imie(lo) imie(hi) imie(m1) imie(f(i, m1)) imie(m2) imie(f(i, m2));

			if (f(i, m1) <= f(i, m2)) lo = m1;
			else hi = m2;
		}
		// debug() << imie(lo) imie(hi);
		for (int j = lo; j <= hi; j++) ans = max(ans, f(i, j));
	}

	cout << ans;

	return 0;
}

Measured memory_bytes: 7640
#include <iostream>
#include <cmath>

using namespace std;

int main(){
    long long n, k;
    cin >> n >> k;

    long long s1 = n%k;
    long long s2 = k-s1;
    if(s1>=s2){
      cout << s2 << endl;
    }
    else{
      cout << s1 << endl;
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int maxn = 2e5+7;
int f1[maxn],f2[maxn];
int n,k,l,x,y;
map<pair<int,int>,int >o;
int getf(int a[],int x)
{
  if(x==a[x])return x;
  else
  {
      a[x] = getf(a,a[x]);
      return a[x];
  }
}
void amerge(int a[],int x,int y)
{
        int x1 = getf(a,x);
        int x2  = getf(a,y);
        if(x1==x2)
            return;
        else
            a[x1] =x2;
}
void init(int a[])
{
    for(int i=1;i<=n;i++)
        a[i]  = i;
}
int main()
{
    while(cin>>n>>k>>l)
    {
        init(f1);
        init(f2);
        for(int i=1;i<=k;i++)
        {
            scanf("%d%d",&x,&y);
            amerge(f1,x,y);
        }
        for(int i=1;i<=l;i++)
        {
            scanf("%d%d",&x,&y);
            amerge(f2,x,y);
        }
        for(int i=1;i<=n;i++)
        {
            ++o[{getf(f1,i),getf(f2,i)}];
        }
        int top = 1;
        for(int i=1;i<=n;i++)
        {
                if(top)top = 0;
               else printf(" ");
            printf("%d",o[{getf(f1,i),getf(f2,i)}]);
        }
        printf("\n");
    }
    return 0;
}


Measured memory_bytes: 13568
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <string>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (a); i > (b); i--)
#define ALL(a) (a).begin(), (a).end()

int main() {
    int N, A, B, P, p1 = 0, p2 = 0, p3 = 0;
    cin >> N >> A >> B;
    REP(i, N) {
        cin >> P;
        if (P <= A) p1++;
        else if (P <= B) p2++;
        else p3++;
    }
    cout << min(p1, min(p2, p3)) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using pll = pair<ll, ll>;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define rrep(i, m, n) for(ll i = m; i > n; i--)
#define Rep(i, m, n) for(ll i = m; i < n; i++)
#define all(vec) vec.begin(), vec.end()
#define lmax(x, y) max<ll>(x, y)
#define lmin(x, y) min<ll>(x, y)
#define tmax(x, y, z) lmax((x), lmax((y), (z)))
#define tmin(x, y, z) lmin((x), lmin((y), (z)))
#define MINUS(a) memset(a, 0xff, sizeof(a))
#define ZERO(a) memset(a, 0, sizeof(a))
const ll INF = 1LL << 60;
const ll MM = 1000000000; const ll MOD = MM + 7; const ll MMM=9223372036854775807;//2^63 -1
#define ADD(a,b) a = (a + ll(b)) % MOD
#define MUL(a,b) a = (a * ll(b)) % MOD
ll GCD(ll x, ll y){ if(y == 0) return x; else return GCD(y, x % y);}
ll LCM(ll x, ll y){ return x / GCD(x, y) * y;}
template<class T> inline bool chmin(T& a, T b){ if(a > b){ a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b){ if(a < b){ a = b; return true;} return false;}
template<typename A, size_t N, typename T> void FILL(A (&array)[N], const T &val){ fill( (T*)array, (T*)(array+N), val );}
// struct edge{ ll from, to, cost; };
// struct edge{ ll to, cost; };
// using Graph = vector<vector<ll>>;  // 重み無し
// using Graph = vector<edge>;  // 辺
// using Graph = vector<vector<edge>>;  // 重み付き
ll dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
ll ddx[8] = {1, 1, 0, -1, -1, -1, 0, 1}, ddy[8] = {0, 1, 1, 1, 0, -1, -1, -1};


int main(){
    ll n, m; cin >> n >> m;
    ll ans = n;
    if(abs(n - m) > 1){
        cout << 0 << endl;
        return 0;
    }
    Rep(i, 1, n) MUL(ans, i);
    Rep(i, 1, m+1) MUL(ans, i);
    if(n == m) MUL(ans, 2);
    cout << ans << endl;
}


Measured memory_bytes: 3592
#間違い
inf=float("inf")
from heapq import heappop,heappush 
n=int(input())
a=[int(input()) for _ in range(n)]
dp=[-1]*(n)
dp[0]=a[0]
for i in range(1,n):
    m=0
    M=n-1
    while M-m>1:
        if dp[(M+m)//2]<a[i]:
            M=(M+m)//2
        else:
            m=(M+m)//2
    if dp[m]>=a[i]:
        dp[M]=a[i]
    else:
        dp[m]=a[i]
count=0
for i in range(n):
    if dp[i]!=-1:
        count+=1
    else:
        break
print(count)

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

int main() {
  int n, p;
  vector<vector<int>> v(31);
  vector<int> ans(100);
  while(scanf("%d,%d", &n, &p), n+p) {
    v[p].push_back(n);
  }

  int cnt = 1;
  for(int i = 30; i >= 0; i--) {
    if(v[i].size() != 0) {
      for(int j = 0; j < v[i].size(); j++) {
        ans[v[i][j]] = cnt;
      }
      cnt++;
    }
  }

  while(cin >> n) {
    cout << ans[n] << endl;
  }
}
  

Measured memory_bytes: 3136
# coding: utf-8
# Your code here!
x,y=map(int,input().split())
if abs(x)==abs(y):
    print(1)
elif x<0 and y<0:
    if abs(x)<abs(y):
        print(abs(abs(x)-abs(y))+2)
    else:
        print(abs(x)-abs(y))
elif x>=0 and y>=0:
    if x>y:
        if y==0:
            print(x-y+1)
        else:
            print(x-y+2)
    else:
        print(y-x)
elif x>=0 and y<0:
    if x>=abs(y):
        print(x-abs(y)+1)
    else:
        print(abs(y)-x+1)
elif x<0 and y>=0:
    if abs(x)>=y:
        if y==0:
            print(abs(x))
        else:
            print(abs(x)-y+1)
    else:
        print(y-abs(x)+1)


Measured memory_bytes: 38256
n = int(input())
li = []
c = 0
for i in range(1, n + 1):
    if i % 2 == 1:
        for j in range(1, i + 1):
            if i % j == 0:
                    li.append(j)
        if len(li) == 8:
            c += 1
            li = []
        else:
            li = []
print(c)

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

int main() {
  int s;
  cin >> s;
  int f = s / 100;
  int l = s % 100;
  if (1 <= f && f <= 12 && 1 <= l && l <= 12) cout << "AMBIGUOUS" << endl;
  else if (1 <= f && f <= 12) cout << "MMYY" << endl;
  else if (1 <= l && l <= 12) cout << "YYMM" << endl;
  else cout << "NA" << endl;
  return 0;
}

Measured memory_bytes: 256
N, x = map(int, input().split())
a = sorted(map(int, input().split()))

ans = 0
for i in range(N):
    ans += 1
    x -= a[i]
    if x < 0:
        ans -= 1
        break
if x > 0:
    ans -= 1
print(max(ans, 0))

Measured memory_bytes: 3060
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
//void p(vector<int> A){rep(i,A.size()){cout << A[i] << " ";}cout << "\n";}

int main(){
    vector<string> S = {"Sunny","Cloudy","Rainy","Sunny"};
    string s;
    cin >> s;
    rep(i,s.size()){
        if(s == S[i]){
            cout << S[i+1];
          exit(0);
        }
    }
}


Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<algorithm>

using namespace std;
int main()
{
    vector<int> v = {0,0,0};
    for(int i=0;i<v.size();i++){
        cin >> v[i];    
    }
    sort(v.begin(),v.end());
    cout << v[0] << " " << v[1] << " " << v[2] << endl;
}


Measured memory_bytes: 3124
#include <bits/stdc++.h>
#pragma gcc optimize("ofast")
using namespace std;

#define ll long long //data types used often, but you don't want to type them time by time
#define ull unsigned long long
#define ui unsigned int
#define mod 1000000007
#define us unsigned short
#define IOS ios_base::sync_with_stdio(0); //to synchronize the input of cin and scanf
#define INF LONG_MAX
#define PI 3.1415926535897932384626
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define rep(x,j,n)for(int x=j;x<n;x++)
typedef vector<pair<ll,ll>> vpi;
typedef vector<ll> vi;
typedef vector<vi> vvi;

ll modexp(ll a,ll b,ll m)
{
	ll r=1;
	a=a%m;
	while(b>0)
	{
		if(b&1)
		r=(r*a)%m;
		b=b/2;
		a=(a*a)%m;
	}
	return r%m;
}

int main(){
    string s,t; cin>>s>>t;
    ll ans = 0;
    for(ll i=0;i<3;i++)
    {
        if(s[i]==t[i])
            ans++;
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h> 
#define F(i,a,b) for(int i=a;i<=(b);++i)
#define dF(i,a,b) for(int i=a;i>=(b);--i)
#define inf 0x3f3f3f3f
#define infll 0x3f3f3f3f3f3f3f3f
#define pb push_back
#define maxnkp make_pair
#define fi first
#define se second
#define eps 1e-10
using namespace std;
typedef long long ll;
const int mods = 998244353;
const int maxn = 3e5+10;
const int N = 1e5+10;
const int E = 2e5+10;  
ll n;

int main(){
	string s;
	cin>>s;
	bool flg = 0;
	for(int i=0;i<s.size();i++) if(s[i]=='7') flg = 1;
	if(flg) printf("Yes\n");
	else printf("No\n");
}

Measured memory_bytes: 3628
#include<iostream>
#include<cstdio>
#include<string>
#include<vector>
#include<queue>
#include<cmath>
#include<algorithm>
#include<iomanip>
#include<functional>
#include<set>
#include<map>
#include<climits>
#include<utility>
#define ul unsigned long long int
#define ll long long int
#define MAX 1000000+1
using namespace std;
#define F first
#define S second
#define pi 2*acos(0.0)
#define PB push_back
#define CL clear()







int main()
{
       map<ll, ll> v;
       ll n;
       cin >> n;
       for(ll i = 0; i <n; i++)
       {
           ll r;
           cin >> r;
           if(!v.count(r))
           {
               v[r] = 0;
           }
           v[r]++;
       }
       map<ll, ll> :: iterator it;
       ll r = 0;
       for(it = v.begin(); it!= v.end(); it++)
       {
           if(it->F< it->S) r+=(it->S- it->F);
           else if(it->S < it ->F) r+= it->S;

       }
       cout << r;

    return 0;
}


Measured memory_bytes: 6272
#include <bits/stdc++.h>
#define maxn 300005
#define MP make_pair
#define PB push_back
#define fore(i, l, r) for(int i = int(l); i < int(r); i++)
#define forn(i, n) fore(i, 0, n)

#define sz(a) int((a).size())

using namespace std;

mt19937 rnd(chrono::system_clock::now().time_since_epoch().count());
// shuffle(begin, end, rnd), rnd() % n

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

int main() {
    int A, B, C;
    cin >> A >> B >> C;
    if (A == B && B == C)
        printf ("Yes\n");
    else
        printf ("No\n");

    return 0;
}



Measured memory_bytes: 256
import java.util.Scanner

fun main(args: Array<String>) {
	val scn = Scanner(System.`in`)
	val k = scn.nextInt()
	var sum = 0L
	for (a in 1..k){
		for(b in a..k){
			val ab = gcd(b, a)
			for (c in b..k){
				val t = when{
					a==c -> 1
					a==b || b==c -> 3
					else -> 6
				}
				sum += t*gcd(ab, c)
			}
		}
	}
	println(sum)
}

fun gcd(a: Int, b: Int): Int{
	var a = a; var b = b
	if (a<b) {
		val tmp = a; a = b; b = tmp
	}
	if (a%b==0) return b
	else return gcd(b, a%b)
}


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

#define PI 3.1415926

typedef struct{

  double x,y;
}pxy_t;

void kock(int n,pxy_t p1 , pxy_t p2){

  if(n==0)return;

  pxy_t s,t,u;

  s.x = (2*p1.x + p2.x)/3.0;
  s.y = (2*p1.y + p2.y)/3.0;

  t.x = (p1.x + 2*p2.x)/3.0;
  t.y = (p1.y + 2*p2.y)/3.0;    

  u.x = (t.x-s.x)*cos(60.0/180*PI) - (t.y-s.y)*sin(60.0/180*PI) + s.x;
  u.y = (t.x-s.x)*sin(60.0/180*PI) + (t.y-s.y)*cos(60.0/180*PI) + s.y;

  kock(n-1,p1,s);
  printf("%.8f %.8f\n",s.x,s.y);
  kock(n-1,s,u);
  printf("%.8f %.8f\n",u.x,u.y);
  kock(n-1,u,t);
  printf("%.8f %.8f\n",t.x,t.y);
  kock(n-1,t,p2);

}


int main(){

  int n;

  cin >> n;

  pxy_t begin={0,0} , end={100,0};

  printf("%.8f %.8f\n",begin.x,begin.y);

  kock(n,begin,end);

  printf("%.8f %.8f\n",end.x,end.y);

  return 0;
}

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

int main() {
    int a, b, product;

    cin >> a >> b;
    product = a * b;

    if (product % 2 == 0){
        cout << "Even" << endl;
    }

    else
    {
        cout << "Odd" << endl;
    }
}

Measured memory_bytes: 256
import java.io.InputStream;
import java.io.PrintStream;
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    resolve(System.in, System.out);
  }

  static void resolve(InputStream is, PrintStream pw) {
    Scanner sc = new Scanner(is);
    String s = sc.next();
    pw.println(
      s.charAt(2) == s.charAt(3) && s.charAt(4) == s.charAt(5) ?
        "Yes" : "No"
    );
  }
}


Measured memory_bytes: 21844
#include <iostream>
#include <string>
#include <math.h>

using namespace std;

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

    if (s == "Sunny")
    {
        cout << "Cloudy" << endl;
    }
    else if (s == "Cloudy")
    {
        cout << "Rainy" << endl;
    }
    else
    {
        cout << "Sunny" << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,n) for(int i=1;i<=n;i++)
const ll MOD = 1000000007;
long long modinv(long long a, long long m=MOD) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m; 
    if (u < 0) u += m;
    return u;
    /*MODの割り算の際に
    a/＝b;
    を
    a *= modinv(b,MOD);
    とする。
        */
}

int N;
const int MAXN=200000;

int A[MAXN];

bool rev(const int &a, const int &b) {
    return (a>b);
}

int main(){
    cin >> N;
    rep(i,N)cin >> A[i];

    sort(A,A+N,rev);
    
    if(N==2){
        cout << A[0] << endl;
        return 0;
    }

    ll ans  = A[0];
    int counter = 1;
    bool nxt = false;
    for(int i=1;i<=N-2;i++) {
        ans += A[counter];
        if(nxt)counter++;
        nxt = !nxt;
    }   

    cout << ans << endl;

    
    
    return 0;
}

Measured memory_bytes: 4372
#include<iostream>
#include<cstdio>
#include<string>
using namespace std;
int main(){
  int d,a,sum;
  while(cin >> d &&d){
    a = 600 / d;
    sum = 0;
    for(int i=1;i<a;i++){
      sum += d*d*i*d*i;
    }
    cout << sum << endl;
  }
}

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

int main()
{
  vector<int> abc;
  rep(i, 3)
  {
    int tmp;
    cin >> tmp;
    abc.push_back(tmp);
  }
  
  sort(abc.begin(), abc.end());
  
  if ((abc[0] == abc[1] && abc[1] != abc[2]) || (abc[0] != abc[1] && abc[1] == abc[2]))
  {
    printf("Yes");
  }
  else
  {
    printf("No");
  }
    
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(long long int i = 0; i < n; i++)
#define _rep(i, m, n) for(long long int i = m; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int N = 1000000;
const ll mod = 1000000007;
using Graph = vector<vector<int>>;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

ll gcd(ll A, ll B){
    if(B == 0)return A;
    return gcd(B, A % B);
}
ll lcm(ll A, ll B){
    return A * B / gcd(A, B);
}

/*------------------------------------------------------------------*/

int main(){
    int n, k; cin >> n >> k;
    vector<int> d(k);
    vector<vector<int>> a(110);
    vector<bool> flag(n, 0);
    rep(i, k){
        cin >> d[i];
        a[i].resize(d[i]);
        rep(j, a[i].size()){
            int b; cin >> b;
            b--;
            flag[b] = true;
        }
    }
    int count = 0;
    rep(i, n){
        if(!flag[i])count++;
    }
    cout << count << endl;
}

Measured memory_bytes: 3604
import java.util.Scanner;
public class Main {


    public static void main(String[] args) {


        Scanner scan = new Scanner(System.in);
String S=scan.next();

String T=scan.next();
int p=0;
for(int i=0;i<S.length();i++)
{
    if (S.substring(i, i + 1).equals(T.substring(i, i + 1))) {
    p++;
    }
    }
p=S.length()-p;

System.out.println(p);
    }
    }


Measured memory_bytes: 45940
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <map>
#include <string>
#include <tuple>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;

const int MAX_RCS = 20;

int calc_indent(const string& s) {
	for(int i = 0; i < static_cast<int>(s.size()); ++i) {
		if(s[i] != '.') return i;
	}

	return s.size();
}

void calc_nest(int& nest_r, int& nest_c, int& nest_s, const string& line) {
	for(int i = 0; i < static_cast<int>(line.size()); ++i) {
		switch(line[i]) {
		case '(': ++nest_r; break;
		case ')': --nest_r; break;
		case '{': ++nest_c; break;
		case '}': --nest_c; break;
		case '[': ++nest_s; break;
		case ']': --nest_s; break;
		}
	}
}

bool ok(int r, int c, int s, const map<tuple<int, int, int>, int>& conditions) {
	for(const pair<tuple<int, int, int>, int>&e : conditions) {
		const tuple<int, int, int>& nest = e.first;
		const int indent = r * get<0>(nest) + c * get<1>(nest) + s * get<2>(nest);
		if(indent != e.second) return false;
	}

	return true;
}

inline int gcd(int a, int b, int c) {
	return __gcd(a, __gcd(b, c));
}

int get_value(int r, int c, int s, const map<tuple<int, int, int>, int>& conditions) {
	const int g = max(1, gcd(r, c, s));
	const tuple<int, int, int> t(r / g, c / g, s / g);
	if(conditions.count(t)) return g * conditions.at(t);
	return -1;
}

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

	for(int p, q; cin >> p >> q && p;) {
		map<tuple<int, int, int>, int> conditions;
		int nest_r = 0, nest_c = 0, nest_s = 0;
		for(int i = 0; i < p; ++i) {
			string line;
			cin >> line;
			const int g = max(1, gcd(nest_r, nest_c, nest_s));
			conditions[make_tuple(nest_r / g, nest_c / g, nest_s / g)] = calc_indent(line) / g;
			calc_nest(nest_r, nest_c, nest_s, line);
		}

		unordered_set<int> R, C, S;
		for(int r = 1; r <= MAX_RCS; ++r) {
			for(int c = 1; c <= MAX_RCS; ++c) {
				for(int s = 1; s <= MAX_RCS; ++s) {
					if(ok(r, c, s, conditions)) {
						R.insert(r);
						C.insert(c);
						S.insert(s);
					}
				}
			}
		}

		nest_r = 0, nest_c = 0, nest_s = 0;
		vector<int> ans(q);
		for(int i = 0; i < q; ++i) {
			string line;
			cin >> line;
			const int indent = calc_indent(line);

			if((!nest_r || R.size() == 1) && (!nest_c || C.size() == 1) && (!nest_s || S.size() == 1)) {
				ans[i] = abs(nest_r * (*R.begin()) + nest_c * (*C.begin()) + nest_s * (*S.begin()) - indent);
			}
			else if(ans[i] = get_value(nest_r, nest_c, nest_s, conditions), ans[i] != -1) {
				ans[i] = abs(ans[i] - indent);
			}
			else if(S.size() == 1 && (ans[i] = get_value(nest_r, nest_c, 0, conditions), ans[i] != -1)) {
				ans[i] = abs(ans[i] + (*S.begin()) - indent);
			}
			else if(C.size() == 1 && (ans[i] = get_value(nest_r, 0, nest_s, conditions), ans[i] != -1)) {
				ans[i] = abs(ans[i] + (*C.begin()) - indent);
			}
			else if(R.size() == 1 && (ans[i] = get_value(0, nest_c, nest_s, conditions), ans[i] != -1)) {
				ans[i] = abs(ans[i] + (*R.begin()) - indent);
			}
			calc_nest(nest_r, nest_c, nest_s, line);
		}

		for(int i = 0; i < q; ++i) {
			cout << ans[i] << (i == q - 1 ? "\n" : " ");
		}
	}

	return EXIT_SUCCESS;
}

Measured memory_bytes: 1224
/*
    Vora Mahammadasim
*/

#include<bits/stdc++.h>
#include<stdio.h>
#define int long long
#define pb emplace_back
#define Mod 1000000007
#define all(a) a.begin(),a.end()
#define ps(a) partial_sum(all(a),a.begin())
using namespace std;





signed main(){

    ios::sync_with_stdio(false);
    cin.tie(0);
    int a,b,c;cin>>a>>b>>c;
    int ans = 0;
    for(int i = a;i<=b;i++){
        if(i % c == 0) ans++;
    }
    cout<<ans;
}


Measured memory_bytes: 3596
import random
import math
LI = lambda: list(map(int,input().split()))
MI = lambda: map(int,input().split())
yes = lambda: print("Yes")
no = lambda: print("No")
I = lambda: list(input())
J = lambda x: "".join(x)
II = lambda: int(input())
SI = lambda: input()
#---khan17---template
a,b,n = MI()
if n >= b:
	n = b-1
print(int(a*n/b)-a*int(n/b))


Measured memory_bytes: 9588
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#define N 654321
using namespace std;
struct sb
{
    int m;
    sb* next=NULL;
};
sb **a;
int la[100005],lb[100005];
int dfsa(int x,int syg,int ii)
{
    for(sb *p=a[x];p->next!=NULL;p=p->next)
    {
        if(p->m==syg)continue;
        la[p->m]=ii;
        dfsa(p->m,x,ii+1);
    }
}
int dfsb(int x,int syg,int ii)
{
    for(sb *p=a[x];p->next!=NULL;p=p->next)
    {
        if(p->m==syg)continue;
        lb[p->m]=ii;
        dfsb(p->m,x,ii+1);
    }
}
int main()
{

    int n,aa,bb,k=0;
    sb *q,*p;
    cin>>n;
    a=new sb*[n+1];
    for(int i=1;i<=n;i++)a[i]=new sb;
    for(int i=1;i<n;i++){
            scanf("%d%d",&aa,&bb);
            p=a[aa];
            q=a[bb];
            for(;;)
            {
                if(p->next==NULL){p->m=bb;p->next=new sb;break;}
                else p=p->next;
            }
            for(;;)
            {
                if(q->next==NULL){q->m=aa;q->next=new sb;break;}
                else q=q->next;
            }
    }

    dfsa(1,0,1);
    dfsb(n,0,1);
    for(int i=1;i<=n;i++){if(la[i]<=lb[i])k++;else k--;}
    if(k>0)cout<<"Fennec";
    else cout<<"Snuke";

}


Measured memory_bytes: 15872
c=[0,2,5,5,4,5,6,3,7,6];N=gets.split[0].to_i;A=gets.split.map &:to_i;d=[0]+Array.new(N);0.upto(N){|i|q=A.map{|x|c[x]<=i&&d[t=i-c[x]]?d[t]*10+x:p}.compact;q.any?&&d[i]=q.max};p d[N]

Measured memory_bytes: 36220
#define _USE_MATH_DEFINES

#include <iostream>
#include <cstdio>
#include <string>
#include <cstdlib>
#include <set>
#include <utility>
#include <vector>
#include <list>
#include <algorithm>
#include <regex>
#include <cmath>
#include <map>
#include <iterator>
#include <climits>
#include <numeric>
#include <bitset>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <queue>
#include <deque>
#include <stack>
#include <array>
#include <valarray>
#include <complex>
#include <random>
#include <functional>
#include <cassert>
#include <chrono>
#include <memory>

using namespace std;

#define int long long
//region TEMPLATE
////@formatter:off
#define double long double
typedef long long ll;
typedef unsigned long long ull;
template<typename T>void __read(T &a) { cin >> a; }
template<typename T, typename ... Args> void __read(T &a, Args &... args) { cin >> a;__read(args...);}
#define make(t, ...) t __VA_ARGS__; __read(__VA_ARGS__)
#define makev(a, n) VI a(n); FOR(n) cin >> a[i];
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define FORIT(p) for(auto it = p.begin(); it != p.end(); it++)
#define FOR(b) for(signed i = 0; i <(b); i++)
#define FORE(i, l, r) for(int i = (l); i < (r); i++)
#define NFOR(i, n) for(int i = (((int) n)-1); i >= 0; i--)
typedef vector<int> VI;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
typedef pair<pair<int, int>, int> PPII;
constexpr ll M7 = 1000000007ll;
constexpr ll M9 = 1000000009ll;
constexpr ll MFFT = 998244353ll;
template<class T> void outv(T &a) { for (auto &x : a) cout << x << ' '; }
static mt19937 rnd(static_cast<unsigned>(chrono::steady_clock::now().time_since_epoch().count())); // NOLINT(cert-err58-cpp)
////@formatter:on
//endregion

VVI g;
VI p;

void dfs(int v) {
    for (auto &u : g[v]) {
        if (u != p[v]) {
            p[u] = v;
            dfs(u);
        }
    }
}

int32_t main() {
    ios_base::sync_with_stdio(false), cin.tie(nullptr);

    make(int, n);
    g.assign(n, {});
    vector<PII> e(n - 1);
    for (int i = 0; i + 1 < n; ++i) {
        cin >> e[i].first >> e[i].second;
        e[i].first--, e[i].second--;
        if (e[i].first > e[i].second){
            swap(e[i].first, e[i].second);
        }
        g[e[i].first].push_back(e[i].second);
        g[e[i].second].push_back(e[i].first);
    }
    make(int, m);
    VI a(n - 1);
    for (int i = 0; i < m; ++i) {
        make(int, v, u);
        v--, u--;
        p.assign(n, -1);
        dfs(v);
        VI path{u};
        while (path.back() != v) {
            path.push_back(p[path.back()]);
        }
        for(int j = 0; j + 1 < path.size(); ++j){
            int st = path[j], en = path[j + 1];
            if (st > en){
                swap(st, en);
            }
            auto k = find(ALL(e), PII(st, en)) - e.begin();
            a[k] |= 1 << i;
        }
    }
    VI dp(1 << m);
    dp[0] = 1;
    for(int i = 0; i < a.size(); ++i){
        for(int mask = static_cast<int>(dp.size()) - 1; mask >= 0; --mask){
            dp[mask | a[i]] += dp[mask];
        }
    }
    cout << dp.back();

    return 0;
}

Measured memory_bytes: 8448
#include "bits/stdc++.h"
#define rep(i,a,n) for(int i = a;i < n;i++)
typedef unsigned long long ull;
typedef long long ll;
using namespace std;

int main(){
    int n,q;
    cin >> n >> q;
    vector<queue<int> > vec(n);
    
    int a,b,c;
    
    rep(i,0,q){
        cin >> a;
        
        if(a == 0){
            cin >> b >> c;
            vec[b].push(c);
        }
        else if(a == 1){
            cin >> b;
            if(!vec[b].empty()) cout << vec[b].front() << endl;
        }
        else{
            cin >> b;
            if(!vec[b].empty()) vec[b].pop();
        }
    }
    return 0;
}


Measured memory_bytes: 4380
#include<bits/stdc++.h>
 #include <ext/pb_ds/tree_policy.hpp>
 #include <ext/pb_ds/assoc_container.hpp>
 #include<chrono>
 using namespace std;
 using namespace std::chrono;      
 using namespace __gnu_pbds; 
 #define fastio     ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
 #define fi         first
 #define se         second
 #define int         long long 
 #define pb         push_back
 #define emp        emplace_back
 #define vv(x)      vector<x>
 #define mp(x,y)    map<x,y>
 #define dq(x)      deque<x>
 #define pql(x)     priority_queue<x>
 #define pqs(x)     priority_queue<x,vv(x),greater<x> >
 #define M          1000000007
 #define forf(i,a,b) for(int i=a;i<b;i++)
 #define it(x)      x::iterator
 #define ll         long long 
 #define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
 #define time__(d)  for(long blockTime = 0; (blockTime == 0 ? (blockTime=clock()) != 0 : false); debug("%s time : %.4fs", d, (double)(clock() - blockTime) / CLOCKS_PER_SEC))
 #define vii        vector<int>
 #define big        3e18
 #define sm         -2e9
 #define mkr        make_pair
 #define vpi        vector<pair<int,int> >
 #define pii        pair<int,int>
 #define rng        500005
 #define sz(x)      (int)x.size()
 #define rv(x)      reverse(x.begin(),x.end())
 #define out(x)     cout<<x.fi<<" "<<x.se<<endl;

//#define ordered_set tree<pii, null_type,less<pii>, rb_tree_tag,tree_order_statistics_node_update> 
  
void pr_init()
{
   
    #ifndef ONLINE_JUDGE
    freopen("gin.txt", "r", stdin);
    freopen("gout.txt", "w", stdout);
   
    #endif
}


int adj[301][301],dupli[301][301];

void solve()
{
   
   int n,m,l;
   cin >> n >> m >> l;
   
   forf(i,0,n+1) 
   {
    forf(j,0,n+1)
    {
      adj[i][j]= big;
      if(i==j) adj[i][j]= 0;
    }
  }

   forf(i,0,m)
   {
    int u,v,c;
    cin >> u >> v >> c;
    adj[u][v] = adj[v][u]= c;
   }

   for(int i=1;i<=n;i++)
   {
    for(int j=1;j<=n;j++)
    {
      for(int k=1;k<=n;k++)
      {
        adj[j][k] = min(adj[j][k] , adj[j][i] + adj[i][k]);
      }
    }
   }

   forf(i,1,n+1)
   {
    forf(j,1,n+1)
    {
      if(adj[i][j] <= l)dupli[i][j] = 1;
      else dupli[i][j] = big;  
    }
   }

  forf(i,1,n+1)
  {
    forf(j,1,n+1)
    {
      forf(k,1,n+1)
      {
        dupli[j][k] =  min(dupli[j][k] , dupli[j][i] + dupli[i][k]);
      }
    }
  }



  int q;
  cin >> q;
  while(q--)
  {
    int s,t;
    cin >> s >> t;
    if(dupli[s][t] >= big)
    {
      cout<<"-1\n";
      continue;
    }

    cout<<dupli[s][t]-1<<"\n";
  }


}


int32_t main()
{
  pr_init();
  fastio;
  
  auto start = high_resolution_clock::now(); 
 
  solve();
  auto stop = high_resolution_clock::now();
  auto duration = duration_cast<microseconds>(stop - start); 
   // cout << "Time taken by function: "
   //       << duration.count() << " microseconds" << endl; 

 }
      
      

Measured memory_bytes: 5080
#pragma GCC optimize ("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse4")
#include"bits/stdc++.h"
using namespace std;
typedef long long ll;
#define int ll
#define all(x) x.begin(), x.end()
#define trav(i,a) for(auto &i:a) 
inline int in(){int x;scanf("%lld",&x);return x;}
int32_t main()
{
	int n=in();
	vector<int> a(n),b(n);
	for(int i=0;i<n;i++){a[i]=in();b[i]=in();}
	sort(all(a));sort(all(b));
	int x,y;
	if(n&1)
	{
		x=a[n/2];y=b[n/2];
	}
	else
	{
		x=a[n/2-1]+a[n/2];
		y=b[n/2-1]+b[n/2];
	}
	
	cout<<y-x+1;
	
}

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

typedef long long ll;

int main(){
  ll n,p;
  cin >> n >> p;
  ll a[n];
  for(int i=0;i<n;i++) cin >> a[i];
  ll x=0,y=0;
  for(int i=0;i<n;i++){
    if(a[i]%2==0){
      x++;
    }
    else{
      y++;
    }
  }
  if(y!=0){
    cout << (ll)pow(2,n-1) << endl;
  }
  else{
    if(p==0){
      cout << (ll)pow(2,n) << endl;
    }
    else{
      cout << 0 << endl;
    }
  }
}
      


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


int main()
{
    int N;
    cin >> N;
    vector<string> s(N);
    for(int i = 0; i < N; ++i){
        cin >> s[i];
        sort(s[i].begin(), s[i].end());
    }
    sort(s.begin(), s.end());

    long long ans = 0, tmp = 1;
    for(int i = 1; i < N; ++i){
        if(s[i] == s[i-1]) ++tmp;
        else{
            ans += (tmp*(tmp-1)) / 2;
            tmp = 1;
        }
    }
    ans += (tmp*(tmp-1)) / 2;
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 7296