akhauriyash/Code-Regression huggingface dataset:
#include<algorithm>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<cstdio>
#include<iomanip>
#include<cmath>
using namespace std;

int main(){
//    cout << fixed << setprecision(10);
    int N;
    cin >> N;
    
    bool hasSeven = false;
    
    while (N > 0) {
        hasSeven |= (7 == N % 10);
        N /= 10;
    }
    
    cout << (hasSeven ? "Yes" : "No");
    return 0;
}


Measured memory_bytes: 3624
#include <iostream>
#include <algorithm>
#include <cstring>
 
using namespace std;
const int K = 1e5+10;
int n, k;
int a[K], dp[K];
 
int main() 
{
  cin >> n >> k;
  memset(dp, 0, sizeof dp);

  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
  }
  
  for (int i = 0; i <= k; i++) {
    for (int j = 0; j < n; j++) {
      if (i >= a[j] && !dp[i-a[j]]) {
        dp[i] = 1;
        break;
      }
    }
  }
  
  cout << (dp[k] ? "First" : "Second") << endl;
  
  return 0;
  
}

Measured memory_bytes: 768
N,M,*abs = $<.read.split.map(&:to_i)
e = Array.new(N+1) { Array.new }
abs.each_slice(2) do |a,b|
  e[a] << b
  e[b] << a
end

ret = 0
while n = e.index(&:one?)
  ret += 1
  e.each { |i| i.delete(n) }
  e[n] = []
end

p ret

Measured memory_bytes: 14208
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stdio.h>
#include <string.h>
#include <math.h>
using namespace std;

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

    int n;
    cin >> n;

    cout << ((n % 10 == n / 100) ? "Yes" : "No") << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  int n, m;
  cin >> n >> m;
  vi l(n, 0);
  rep(i, m) {
    int a, b;
    cin >> a >> b;
    l[a - 1]++;
    l[b - 1]++;
  }
  bool ok = true;
  rep(i, n) if(l[i] % 2) ok = false;
  cout << (ok ? "YES" : "NO") << endl;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#define Ms(a,b) memset(a,b,sizeof a)
#define db(x) cout<<#x<<"="<<x<<endl;
#define db2(x,y) cout<<#x<<"="<<x<<" "<<#y<<"="<<y<<endl;
#define db3(x,y,z) cout<<#x<<"="<<x<<" "<<#y<<"="<<y<<" "<<#z<<"="<<z<<endl;
using namespace std;
char tmp[3][5];
int main() {
	int ans=0;
	scanf("%s%s",tmp[1],tmp[2]);
	for(int i=0;i<3;i++)ans+=tmp[1][i]==tmp[2][i];
	printf("%d\n",ans);
	return 0;
}


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

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

  double radian = C * M_PI / 180;

  // ### 高さh
  // * sin(C) = h / b
  // * h = b * sin(C)
  double h = b * sin(radian);
  // ### 面積S
  // * S = 底辺 * 高さ * 1/2
  double S = a * h / 2;
  // 周の長さL
  // x**2 = h**2 + (a - b * cos(C))**2
  double square_x = (h * h) + (a * a) + (a * b * cos(radian) * -2) + (b * cos(radian) * b * cos(radian));
  double L = a + b + sqrt(square_x);

  printf("%.8f\n", S);
  printf("%.8f\n", L);
  printf("%.8f\n", h);
  return 0;
}



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

using namespace std;

typedef unsigned long long ullong;

ullong power(ullong x, ullong n, ullong M) {
  ullong res = 1;
  if (n > 0) {
    res = power(x, n / 2, M);
    if (n % 2 == 0) {
      res = (res * res) % M;
    } else {
      res = (((res * res) % M) * x) % M;
    }
  }
  return res;
}

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

  cout << power(m, n, 1000000007) << endl;

  return 0;
}



Measured memory_bytes: 3120
#include <bits/stdc++.h>
#define um unordered_map
#define us unordered_set
#define f first
#define s second
#define pb push_back
#define MOD 998244353
#define eps 1e-9
#define INF 1000000002

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<int, pii> piii;
const int N = 303;

int n;
int main() {
    int n,k;
    cin>>n>>k;
    int cnt =0;
    for(int i =0;i<n;i++) {
        int x;
        cin>>x;
        if(x>=k)
            cnt++;
    }
    cout<<cnt;
    return 0;
}


Measured memory_bytes: 256
a, b, c, d = map(int, list(input()))
if a+b+c+d==7:
    print(str(a)+'+'+str(b)+'+'+str(c)+'+'+str(d)+'=7')
elif a+b+c-d==7:
    print(str(a)+'+'+str(b)+'+'+str(c)+'-'+str(d)+'=7')
elif a+b-c+d==7:
    print(str(a)+'+'+str(b)+'-'+str(c)+'+'+str(d)+'=7')
elif a+b-c-d==7:
    print(str(a)+'+'+str(b)+'-'+str(c)+'-'+str(d)+'=7')
elif a-b+c+d==7:
    print(str(a)+'-'+str(b)+'+'+str(c)+'+'+str(d)+'=7')
elif a-b+c-d==7:
    print(str(a)+'-'+str(b)+'+'+str(c)+'-'+str(d)+'=7')
elif a-b-c+d==7:
    print(str(a)+'-'+str(b)+'-'+str(c)+'+'+str(d)+'=7')
elif a-b-c-d==7:
    print(str(a)+'-'+str(b)+'-'+str(c)+'-'+str(d)+'=7')

Measured memory_bytes: 3064
import sys

import numba as nb
import numpy as np

input = sys.stdin.readline


@nb.njit("i8[:](i8,i8,i8,i8[:,:],i8[:,:])", cache=True)
def solve(N, M, Q, LR, pq):
    S = np.zeros(shape=(N + 1, N + 1), dtype=np.int64)
    for i in range(M):
        L, R = LR[i]
        S[L][R] += 1
    for i in range(N + 1):
        S[i] = np.cumsum(S[i])

    ans = np.zeros(shape=Q, dtype=np.int64)
    for i in range(Q):
        p, q = pq[i]
        for j in range(p, q + 1):
            ans[i] += S[j][q] - S[j][p - 1]

    return ans


def main():
    N, M, Q = map(int, input().split())
    LR = np.zeros(shape=(M, 2), dtype=np.int64)
    for i in range(M):
        LR[i] = input().split()
    pq = np.zeros(shape=(Q, 2), dtype=np.int64)
    for i in range(Q):
        pq[i] = input().split()

    ans = solve(N, M, Q, LR, pq)

    print("\n".join(map(str, ans)))


if __name__ == "__main__":
    main()


Measured memory_bytes: 119548
n=int(input())
a=[]
b=[]
for i in range(n):
    ai,bi=map(int,input().split())
    a.append(ai)
    b.append(bi)
a.sort()
b.sort()
if n%2==0:
    i=int(n/2)
    ans_a=(a[i]+a[i-1])/2
    ans_b=(b[i]+b[i-1])/2
    ans=(ans_b-ans_a+1)*2-1
    print(int(ans))
else:
    i=int((n-1)/2)
    ans_a=a[i]
    ans_b=b[i]
    ans=ans_b-ans_a+1
    print(ans)

Measured memory_bytes: 25344
#include <iostream>
#include <fstream>
#include <cassert>
#include <typeinfo>
#include <vector>
#include <stack>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <iomanip>
#include <cctype>
#include <random>
#include <complex>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<58;
const double pi=acos(-1);
const double eps=1e-7;
const ll mod=1e9+7;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

const int M=26;

int n;
string s;

int main(){
	cin>>s;
	n=s.size();
	vi dp(n+1);
	vvi a(n+1,vi(M,n));
	dp[n]=-1;
	for(int i=n-1;i>=0;i--){
		int m=inf;
		for(int j=0;j<M;j++) m=min(m,dp[a[i+1][j]]);
		dp[i]=m+1;
		a[i]=a[i+1];
		a[i][s[i]-'a']=i;
	}
	int N=inf;
	for(int i=0;i<M;i++) N=min(N,dp[a[0][i]]);
	N++;
	int I=0;
	for(int i=0;i<=N;i++){
		for(int j=0;j<M;j++) if(dp[a[I][j]]==N-i-1){
			char c='a';
			for(int k=0;k<j;k++) c++;
			cout<<c;
			I=a[I][j]+1;
			break;
		}
	}
	cout<<endl;
}

Measured memory_bytes: 27780
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Main {

	public static void main(String[] args) {
		InputStreamReader isr = new InputStreamReader(System.in);
		BufferedReader br = new BufferedReader(isr);
		try {
			String input = br.readLine();
			int num = Integer.parseInt(input);
			int i, b, r, f, v;
			int[][][] hoge = new int[4][3][10];
			for (i = 0; i < num; i++) {
				String[] list = br.readLine().split(" ");
				b = Integer.parseInt(list[0]) - 1;
				r = Integer.parseInt(list[1]) - 1;
				f = Integer.parseInt(list[2]) - 1;
				v = Integer.parseInt(list[3]);

				int temp = hoge[b][r][f] + v;
				if (temp > 9) {
					temp = 9;
				} else if (temp < 0) {
					temp = 0;
				}
				hoge[b][r][f] = temp;
			}

			int x, y, z;
			for (x = 0; x < hoge.length; x++) {
				int[][] xlist = hoge[x];
				for (y = 0; y < xlist.length; y++) {
					int[] ylist = xlist[y];
					for (z = 0; z < ylist.length; z++) {
						System.out.print(" " + ylist[z]);
					}
					if (y != ylist.length - 1) {
						System.out.println();
					}
				}
				if (x != hoge.length - 1) {
					System.out.println("####################");
				}
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}

Measured memory_bytes: 19304
#include <iostream>
#include<algorithm>
#include<string>
#include<vector>
#define _USE_MATH_DEFINES
#include <math.h>
#include <iomanip>
#include <stdio.h>
#include <numeric>
#include <cmath>
#include <limits>
using namespace std;


int main()
{
	int s,cnt=0,cnt2=0,tmp=0;
	cin >> s;
	vector<int>c;
	c.push_back(s);
	while (true) {
		if (c[cnt] == 1) { 
			c.push_back(4);
			c.push_back(2);
			c.push_back(1);
			break; 
		}
		c.push_back((c[cnt] % 2 == 0 ? c[cnt] / 2 : 3 * c[cnt] + 1));
		cnt++;
	}
	for (int i = 0; i < c.size(); i++) {
		if (count(c.begin(), c.end(), c[i]) == 2) { tmp = c[i]; break; }
	}
	for (int i = 0; i < c.size(); i++) {
		if (tmp == c[i]) {
			cnt2++;
			if (cnt2 == 2)return cout << i+1 << endl,0;
		}
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
int main(){
    int n;
    cin>>n;
    vector<int> d1(n),d2(n);
    for(int i=0; i<n; i++) cin>>d1[i]>>d2[i];
    int tmp=0;
    for(int i=0; i<n; i++){
        if(d1[i]==d2[i]){
            tmp++;
            if(tmp==3){
                cout<<"Yes"<<endl;
                return 0;
            }
        }else{
            tmp=0;
        }
    }
    cout<<"No"<<endl;
}

Measured memory_bytes: 3632
import { readFileSync } from "fs";

const read = () =>
  readFileSync(0, "utf8")
    .split("\n")
    .map((line) => line.split(" "));

const main = (input: string[][]) => {
  const N = Number(input[0][0]);

  let answer = 0;

  for (let i = 1; i; i++) {
    const squareNumber = i * i;

    if (squareNumber > N) {
      break;
    }

    answer = squareNumber;
  }

  return answer;
};

console.log(main(read()));


Measured memory_bytes: 32212
//By Vlgd
//By Vlgd
#include<bits/stdc++.h>
using namespace std;
const int N=100000;
int n,m,d[N],t=0;
vector<int>G[N];
stack<int>S;
void dfs(int r,int cnt){
	S.push(r);
	d[r]=cnt;
	while(!S.empty()){
		int u=S.top();S.pop();
		for (int i=0;i<G[u].size();i++){
			int v=G[u][i];
			if (d[v]==-1){
				d[v]=cnt;
				S.push(v);
			}
		}
	}
}
int main(){
	scanf("%d%d",&n,&m);
	int u,v;
	for (int i=0;i<m;i++){
		scanf("%d%d",&u,&v);
		G[u].push_back(v);
		G[v].push_back(u); 
	}
	memset(d,-1,sizeof(d));
	for (int i=0;i<n;i++) if (d[i]==-1) dfs(i,t++);
	int q;
	scanf("%d",&q);
	for (int i=0;i<q;i++){
		scanf("%d%d",&u,&v);
		if (d[u]==d[v]) printf("yes\n");
		else printf("no\n");
	} 
} 


Measured memory_bytes: 9068
#include<bits/stdc++.h>
using namespace std;
int n,a[100001],x,ans;
int main() {
	cin>>n;
	for(int i=1; i<=n; i++) {
		cin>>x;
		if(x>n) ans++;
		else a[x]++;
	}
	for(int i=1; i<=n; i++) {
		if(a[i]==0) continue;
		if(a[i]<i) ans=ans+a[i];
		else if(a[i]>i) ans=ans+a[i]-i;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define reps(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; --i)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; --i)
#define INF 1000000000000
#define MOD 1000000007
#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0, a1, a2, a3, a4, x, ...) x
#define debug_1(x1) cout << #x1 << ": " << x1 << endl
#define debug_2(x1, x2) \
    cout << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << endl
#define debug_3(x1, x2, x3)                                                 \
    cout << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " \
         << x3 << endl
#define debug_4(x1, x2, x3, x4)                                             \
    cout << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " \
         << x3 << ", " #x4 << ": " << x4 << endl
#define debug_5(x1, x2, x3, x4, x5)                                         \
    cout << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " \
         << x3 << ", " #x4 << ": " << x4 << ", " #x5 << ": " << x5 << endl
#ifdef _DEBUG
#define debug(...)                                                        \
    CHOOSE((__VA_ARGS__, debug_5, debug_4, debug_3, debug_2, debug_1, ~)) \
    (__VA_ARGS__)
#else
#define debug(...)
#endif

using namespace std;
using ll = long long;
vector<ll> ans;
ll n;

template <class T>
void printVector(const vector<T>& v) {
    for (auto value : v) {
        cout << value << " ";
    }
    cout << endl;
}

void dfs(ll p) {
    if (p > n) {
        return;
    }
    if (to_string(p).find("3") != string::npos &&
        to_string(p).find("5") != string::npos &&
        to_string(p).find("7") != string::npos) {
        ans.push_back(p);
    }
    dfs(p * 10 + 3);
    dfs(p * 10 + 5);
    dfs(p * 10 + 7);
}

int main() {
    cin >> n;
    dfs(3);
    dfs(5);
    dfs(7);

    // printVector(ans);
    cout << ans.size() << endl;
    return 0;
}

Measured memory_bytes: 3352
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
//#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int cm = 1 << 17;
char cn[cm], * ci = cn + cm, ct;
inline char getcha() {
	if (ci - cn == cm) { fread(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}
inline int getint() {
	int A = 0;
	int pn = 1;
	if (ci - cn + 16 > cm) {
		if ((ct = getcha()) == '-') { pn = -1; ct = getcha(); }
		A = ct - '0';
		while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';;
		return pn * A;
	}
	else {
		if ((ct = *ci++) == '-') { pn = -1; ct = *ci++; }
		A = ct - '0';
		while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';;
		return pn * A;
	}
}

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


	int N = getint(), K = getint(), A[100000];
	ll naka = 0;
	ll m = 0;
	ll mgoukei = 0;
	rep(i, K) {
		A[i] = getint();
		naka += A[i];
		mgoukei += max(A[i], 0);
	}
	ll kotae = max(naka, 0ll) - mgoukei;
	int k = 0;
	for (int i = K; i < N; i++, k++) {
		if (k >= K) k -= K;
		naka -= A[k];
		m += max(A[k], 0);
		A[k] = getint();
		mgoukei += max(A[k], 0);
		naka += A[k];

		chmax(kotae, max(naka, 0ll) + m - mgoukei);
	}

	printf("%lld\n", kotae + mgoukei);

	Would you please return 0;
}

Measured memory_bytes: 640
import collections

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

n = int(input())
a = prime_factorize(n)
c = collections.Counter(a)
num = 0
for v in c.values():
    for i in range(1,n):
        v -= i
        if v >=0:
            num +=1
        else:break

print(num)

Measured memory_bytes: 9336
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

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

        int middleScore = 0;    //??????????¨?????????°
        int finalScore = 0;     //??????????¨?????????°
        int revengeScore = 0;   //???????¨?????????°

        try{

            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

            while(true){
                String input = br.readLine();
                String[] strArray = input.split(" ");

                middleScore = Integer.parseInt(strArray[0]);
                finalScore = Integer.parseInt(strArray[1]);
                revengeScore = Integer.parseInt(strArray[2]);

//              ??????????????????????????¨???-1?????¨??????????????????
                if(middleScore == -1 && finalScore == -1 && revengeScore == -1){
                    break;
                }

                System.out.println(grading(middleScore, finalScore, revengeScore));
            }
        }catch (Exception e) {
            System.err.println(e);
        }
    }

    private static String grading(int middleScore, int finalScore, int revengeScore){

        int sum = middleScore + finalScore;
        String grade = null;

        if(middleScore == -1 || finalScore == -1){
            return "F";
        }

        if(80 <= sum){
            return "A";

        }else if(65 <= sum){
            return "B";

        }else if(50 <= sum){
            return "C";

        }else if(30 <= sum){
            if(50 <= revengeScore){
                return "C";
            }else{
                return "D";
            }
        }else{
            return "F";
        }

    }
}

Measured memory_bytes: 24272
//{{{
#include <bits/stdc++.h>
using namespace std;
#define repX(a,b,c,x,...) x
#define repN(a) repX a
#define rep(...) repN((__VA_ARGS__,rep3,rep2,loop))(__VA_ARGS__)
#define rrep(...) repN((__VA_ARGS__,rrep3,rrep2))(__VA_ARGS__)
#define loop(n) rep2(i_,n)
#define rep2(i,n) rep3(i,0,n)
#define rep3(i,begin,end) for(int i=(int)(begin),i##_end=(int)(end);i<i##_end;++i)
#define rrep2(i,n) rrep3(i,n,0)
#define rrep3(i,begin,end) for(int i=(int)(begin-1),i##_end=(int)(end);i>=i##_end;--i)
#define foreach(x,a) for(auto&x:a)
using ll=long long;
const ll mod=(ll)1e9+7;
//}}}

vector<pair<int, int>> v[100000];
int colors[100000];
int finished[100000];

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

  rep(i, N - 1){
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    v[a].push_back(make_pair(b, i));
    v[b].push_back(make_pair(a, i));
  }

  int start = 0;
  int maxColor = 0;
  rep(i, N){
    if(v[i].size() > maxColor){
      maxColor = v[i].size();
      start = i;
    }
  }

  cout << maxColor << endl;

  queue<pair<int, int>> q;
  q.push(make_pair(start, 0));
  while(q.size()){
    pair<int, int> p = q.front();
    q.pop();
    int id = p.first;
    int color = p.second;
    rep(i, v[id].size()){
      int pp = v[id][i].first;
      int branchId = v[id][i].second;
      if(!finished[branchId]){
        finished[branchId] = 1;
        color++;
        color %= maxColor;
        colors[branchId] = color;
        q.push(make_pair(pp, color));
      }
    }
  }

  rep(i, N - 1){
    if(colors[i] == 0) colors[i] = maxColor;
    cout << colors[i] << endl;
  }
  return 0;
}


Measured memory_bytes: 7424
int main() {
    int i = 0, k, x;
    int data[10000];
    while(1) {
        scanf("%d", &x);
        if(x == 0) break;
        data[i] = x;
        i++;
    }
    for(k = 0; k < i; k++) {
        printf("Case %d: %d\n", k + 1, data[k]);
    }
    return 0;
}

Measured memory_bytes: 1748
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod = 1e9 + 7;

ll fact(ll n) {
	ll res = 1;
	for (int i = 1; i <= n; i++) {
		res = (res * i) % mod;
	}
	return res;
}

int main()
{
	ll N, M;
	cin >> N >> M;
	if (N > M) swap(N, M);
	if (M - N > 1) {
		cout << 0 << endl;
	}
	else if (M - N == 1) {
		cout << fact(N) * fact(M) % mod << endl;
	}
	else {
		cout << fact(N) * fact(N) % mod * 2 % mod << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <list>
#include <math.h>
#include <algorithm>
#include <functional>
#include <string>
#include <iomanip>
#include <queue>
#include <map>
#include <unordered_map>
typedef long long ll;
using namespace std;


int main()
{
	int N,Y;
	std::cin >> N >> Y;

	for(int x=0; x<N+1; x++){
		for(int y=0; y<N+1; y++){
			int z = N-x-y;
//				std::cout << x << " " << y << " " << z <<std::endl;
			if(z>=0 && x+y+z == N && 10000*x+5000*y+1000*z == Y){
				std::cout << x << " " << y << " " << z <<std::endl;
				return 0;
			}
		}
	}


	std::cout << -1 << " " << -1 << " " << -1 <<std::endl;

	return 0;

}

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

int main(){
int a,b,c;
cin>>a>>b>>c;
if(a==b&&a!=c&&b!=c){
  cout<<"Yes"<<endl;
}
else if(a==c&&a!=b&&b!=c){
  cout<<"Yes"<<endl;
}
else if(c==b&&a!=c&&b!=a){
  cout<<"Yes"<<endl;
}
else{
  cout<<"No"<<endl;
}
    return 0;
}





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

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

    for(int i = 0; i < s.size(); i++){
        s.at(i) += n;
        if(s.at(i) > 90){
            s.at(i) = (char)s.at(i) % 90 + 64;
        }
    }
    cout << s << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
  int H,A;
  int D[100000];
  int M[100000];
int DP[10001];
int main() {
  cin>>H>>A;
    for(int i=0;i<H;i++){
    cin>>D[i]>>M[i];
  }
  for(int i=1;i<=H;i++){
    DP[i]=INT_MAX;
      for(int j=0;j<A;j++){
   DP[i]=min(DP[i],DP[max(0,i-D[j])]+M[j]);
  }
  }
	cout<<DP[H];
}

Measured memory_bytes: 256
(*
 * 西=左 
 * 東=右
 *)

let () = Scanf.scanf "%d\n%s\n" @@ fun n s ->
  let west = Array.make (n + 2) 0
  in
  let east = Array.make (n + 2) 0
  in
  for i = 0 to n - 1 do
    (if s.[i] = 'W' then
      west.(i + 2) <- 1);
    (if s.[i] = 'E' then
      east.(i) <- 1)
  done;
  for i = 1 to n + 1 do
    west.(i) <- west.(i) + west.(i - 1);
  done;
  for i = n downto 0 do
    east.(i) <- east.(i) + east.(i + 1)
  done;
  Array.init n (fun i -> west.(i + 1) + east.(i + 1))
  |> Array.fold_left min max_int
  |> Printf.printf "%d\n"


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

const int INF = 1 << 12;

int main(){
  int N ;
  cin >> N ;
  
  pair<pair<string,int>,int> p[110];
  for(int i = 0; i < N; i++){
    int a; string s;
    cin >> s >> a;
    p[i] = make_pair(make_pair(s, -a),i);
  }
  
  sort(p,p + N);
  for(int i = 0; i < N; i++) cout << p[i].second + 1 << endl;
  
  
}

Measured memory_bytes: 3656
#include <bits/stdc++.h>
using namespace std;
const int maxn=200005,INF=0x7FFFFFFF;
int n,m,ansL,ansR,a[maxn],b[maxn];
int main()
{
	scanf("%d",&n);
	m=(n+1)>>1;
	for (int i=1;i<=n;i++) scanf("%d%d",&a[i],&b[i]);
	sort(a+1,a+1+n);
	sort(b+1,b+1+n);
	ansL=(n&1)?a[m]:a[m]+a[m+1];
	ansR=(n&1)?b[m]:b[m]+b[m+1];
	//cerr<<">>>>>>"<<ansL<<" "<<ansR<<endl;
	printf("%d\n",ansR-ansL+1);
	return 0;
}


Measured memory_bytes: 5328
#include<bits/stdc++.h>
#define rep(i,n) for(int (i) = 0;(i) < (n);(i)++)
#define SORT(c) sort((c).begin(),(c).end())
#define MOD 1000000007
using namespace std;
typedef long long ll;
int main(void){
	int a,b;
	cin >> a >> b;
	cout << (a - b * 2 > 0 ?  a-b*2 : 0) << endl;
	return 0;
}


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

// Shortcut

//#define int long long
#define endl '\n'
#define eb emplace_back
#define pb push_back
#define pob pop_back
#define mp make_pair
#define upb upper_bound
#define lwb lower_bound
#define fi first
#define se second
#define For(i, l, r) for (int i = l; i < r; i++)
#define ForE(i, l, r) for (int i = l; i <= r; i++)
#define Ford(i, r, l) for (int i = r; i > l; i--)
#define FordE(i, r, l) for (int i = r; i >= l; i--)
#define Fora(i, a) for (auto i : a)

// I/O & Debug

#define PrintV(a) for (int iiii = 0; iiii < a.size(); iiii++) cout << a[iiii] << ' ';
#define PrintVl(a) for (int iiii = 0; iiii < a.size(); iiii++) cout << a[iiii] << endl;
#define PrintA(a, n) for (int iiii = 0; iiii < n; iiii++) cout << a[iiii] << ' ';
#define PrintAl(a, n) for (int iiii = 0; iiii < n; iiii++) cout << a[iiii] << endl;
#define Ptest(x) return cout << x, 0;
#define gl(s) getline(cin, s);
#define setpre(x) fixed << setprecision(x)
/*
#define debug(args...){ string _sDEB = #args; replace(_sDEB.begin(), _sDEB.end(), ',', ' '); stringstream _ssDEB(_sDEB); istream_iterator<string> _itDEB(_ssDEB); DEB(_itDEB, args); }
void DEB(istream_iterator<string> it) {}
template<typename T, typename... Args>
void DEB(istream_iterator<string> it, T a, Args... args){
    cout << *it << " = " << a << endl;
    DEB(++it, args...);
}
*/

// Functions

//#define isvowel(a) (a == 'a' || a == 'e' || a == 'i' || a == 'o' || a == 'u')
#define bend(a) a.begin(), a.end()
#define rbend(a) a.rbegin(), a.rend()
#define mset(a) memset(a, 0, sizeof(a));
//mt19937 rando(chrono::steady_clock::now().time_since_epoch().count());

// Data Structure

#define pque priority_queue
#define mts multiset
typedef long long ll;
typedef long double ld;
typedef vector <int> vi;
typedef vector <ll> vll;
typedef vector <ld> vld;
typedef vector <string> vs;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef vector <vi > vvi;
typedef vector <vll > vvll;
typedef vector <pii > vpii;
typedef vector <pll > vpll;

const int N = 2e5 + 5, mod = 1e9 + 7, inf = 1e9 + 7;

int n, ans;
int a[N];

signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    cin >> n;
    ForE(i, 1, n){
        cin >> a[i];
    }
    ForE(i, 1, n){
        if (a[i] == i){
            ans++;
            i++;
        }
    }
    cout << ans;
}

/*
==================================+
INPUT:                            |
------------------------------    |

------------------------------    |
==================================+
OUTPUT:                           |
------------------------------    |

------------------------------    |
==================================+
*/

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
signed main(){
  int s;
  cin>>s;
  if(s/100!=0&&s%100!=0){
    if(s/100<=12){
      if(s%100<=12) cout<<"AMBIGUOUS";
      else cout<<"MMYY";
    }
    else {
      if(s%100<=12) cout<<"YYMM";
      else cout<<"NA";
    }
  }
  else{
    if(s/100!=0||s%100!=0){
      if(s/100!=0&&s/100<=12) cout<<"MMYY";
      else if(s%100!=0&&s%100<=12)cout<<"YYMM";
      else cout<<"NA";
    }
    else cout<<"NA";
  }
  cout<<"\n";
}

Measured memory_bytes: 256
s = input()
looking_for = 'L'
right_side_n = 0
left_side_n = 0
ans = ''
for char in s[1:]:
  if looking_for == 'L':
      if char == 'L':
        looking_for = 'R'
        ans += left_side_n * '0 '
      else:
        left_side_n += 1
  else:
      if char == 'R':
        left_side_n += 1
        ll = left_side_n >> 1
        lr = left_side_n - ll
        rr = (right_side_n+1) >> 1
        rl = (right_side_n+1) - rr
        ans += str(rr + lr) + ' '
        ans += str(rl + ll) + ' '
        ans += right_side_n * '0 '
        left_side_n = 0
        right_side_n = 0
        looking_for = 'L'
      else:
        right_side_n += 1
left_side_n += 1
ll = left_side_n >> 1
lr = left_side_n - ll
rr = (right_side_n+1) >> 1
rl = (right_side_n+1) - rr
ans += str(rr + lr) + ' '
ans += str(rl + ll) + ' '
ans += right_side_n * '0 '
print(ans)

Measured memory_bytes: 3836
// Sakhiya07 - Yagnik Sakhiya
 
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long int
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define all(x) x.begin(),x.end()
 
#define mp make_pair
#define bp __builtin_popcountll
#define MOD  1000000007
const int N = 62;
#define FAST ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);srand(time(NULL));
ll cnt = 0;

void solve()
{
     ll n,m;
     cin >> n >> m;
     ll cnt = 0;
     ll a[n];
     ll sum = 0;
     for(ll i=0;i<n;i++)
     {
          cin >> a[i];
          sum += a[i];
     }
     ld hova = sum/(ld)(4*m);
     for(ll i=0;i<n;i++)
     {
          if(a[i]>=hova)   cnt++;
     }
     if(cnt>=m)   cout<<"Yes\n";
     else         cout<<"No\n";
}

int main()
{
     FAST;
     ll t = 1;
    // cin >> t;
     while(t--)
     {
         
          solve();
     }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,start,lim) for(lld i=start;i<lim;i++)
#define repd(i,start,lim) for(lld i=start;i>=lim;i--)
#define scan(x) scanf("%lld",&x)
#define print(x) printf("%lld ",x)
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define br printf("\n")
#define sz(a) lld((a).size())
#define YES printf("YES\n")
#define NO printf("NO\n")
#define all(c) (c).begin(),(c).end()
using namespace std;
#define INF         1011111111
#define LLINF       1000111000111000111LL
#define EPS         (double)1e-10
#define MOD         1000000007
#define PI          3.14159265358979323
using namespace std;
typedef long double ldb;
typedef long long lld;
lld powm(lld base,lld exp,lld mod=MOD) {lld ans=1;while(exp){if(exp&1) ans=(ans*base)%mod;exp>>=1,base=(base*base)%mod;}return ans;}
typedef vector<lld> vlld;
typedef pair<lld,lld> plld;
typedef map<lld,lld> mlld;
typedef set<lld> slld;
#define N 100005
lld a[10];
int main()
{
	lld n,x;
	cin>>n;
	rep(i,1,n+1) {
		cin>>x;
		if(x>=1 and x<=399) a[0]++;
		else if(x>=400 and x<=799) a[1]++;
		else if(x>=800 and x<=1199) a[2]++;
		else if(x>=1200 and x<=1599) a[3]++;
		else if(x>=1600 and x<=1999) a[4]++;
		else if(x>=2000 and x<=2399) a[5]++;
		else if(x>=2400 and x<=2799) a[6]++;
		else if(x>=2800 and x<=3199) a[7]++;
		else a[8]++;
	}
	lld minm=LLINF,maxm=0,cnt=0;
	rep(i,0,8) if(a[i]) cnt++;
	if(cnt==0) cout<<1<<" "<<a[8];
 	else cout<<cnt<<" "<<cnt+a[8];
	return 0;
}

Measured memory_bytes: 256
n = input()
a = n[0::2]
b = n[1::2]
odd = ['R', 'U', 'D']
even  = ['L', 'U', 'D']
core = 0
for i in a:
    if not i in odd:
        core +=1
for j in b:
    if not j in even:
        core += 1
        
if core ==0:
    print('Yes')
else:
    print('No')
    


Measured memory_bytes: 3060
import java.util.Scanner;
class Main{
    int n,i;
    int max = -9999999;
    int min = 9999999;
    long sam = 0;

    public void solve(){
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        int a[] = new int[n];
        for(i = 0; i < n; i++){
            a[i] = sc.nextInt();
            sam = sam + a[i];
            if(n == 0){
                min = 0;
                max = 0;
            }else if(n == 1){
                max = a[i];
                min = a[i];
            }else if(a[i] < min){
                min = a[i];
            }else if(a[i] > max){
                max = a[i];
            }else if(a[i] == min || a[i] == max){
                continue;
            }
           
        }
    System.out.println(min + " " + max + " " + sam);
    }
    public static void main(String[] args){
        new Main().solve();
    }
}

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

int main(){
  int n,x,i;
  int c = 1;
  int s = 0;
  int l[100] = {};

  cin >> n >> x;

  for (i = 0; i < n; i++){
    cin >> l[i];
    s += l[i];
    if (s <= x){c++;}
  }

  cout << c;

}


Measured memory_bytes: 256
import scala.collection.mutable
import scala.collection.mutable.ArrayBuffer
import scala.io.StdIn._
object Main extends App {

  val Array(v, e, f) = readLine.trim.split(' ').map(_.toInt)
  val nodes = Array.fill(v){ArrayBuffer[Edge]()}
  for (_ ← 0 until e) {
    val Array(u, v, c, d) = readLine.trim.split(' ').map(_.toInt)
    nodes(u).append(Edge(v, c, d))
    nodes(v).append(Edge(u, 0, -d))
    nodes(u).last.pair = nodes(v).last
    nodes(v).last.pair = nodes(u).last
  }
  val potential = Array.fill(v){0L}
  val minCost = Array.fill(v){Long.MaxValue}
  val prev = Array.fill(v){nodes.head.head}
  val queue = mutable.PriorityQueue[(Int, Long)]()(Ordering.by[(Int, Long), Long](_._2).reverse)
  var flow = 0
  var wholeCost = 0L
  var hasFlow = true
  while(hasFlow && flow < f) {
    hasFlow = false
    minCost.indices.foreach(i ⇒ minCost(i) = Long.MaxValue)
    queue.enqueue((0, 0L))
    minCost(0) = 0L
    while (queue.nonEmpty) {
      val (current, cost) = queue.dequeue()
      if (current != v - 1 && minCost(current) == cost) {
        for (e@Edge(next, flow, distance) ← nodes(current) if flow > 0) {
          if (minCost(next) > potential(current) - potential(next) + distance + cost) {
            minCost(next) = potential(current) - potential(next) + distance + cost
            prev(next) = e
            queue.enqueue((next, minCost(next)))
          }
        }
      }
    }
    hasFlow = minCost(v - 1) != Long.MaxValue
    if (hasFlow) {
      for (i ← 0 until v) potential(i) += minCost(i)
      var minFlow = Int.MaxValue
      var last = v - 1
      while (last != 0) {
        minFlow = math.min(minFlow, prev(last).flow)
        last = prev(last).pair.to
      }
      val addFlow = math.min(f - flow, minFlow)
      wholeCost += addFlow * potential(v - 1)
      flow += addFlow
      last = v - 1
      while (last != 0){
        prev(last).flow -= addFlow
        prev(last).pair.flow += addFlow
        last = prev(last).pair.to
      }
    }
  }
  println(if (flow == f) wholeCost else -1)
  case class Edge(to: Int, var flow: Int, cost: Int) {
    private var mPair: Option[Edge] = None
    def pair: Edge = mPair.get
    def pair_=(edge: Edge): Unit = mPair = Some(edge)
  }
}


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

using namespace std;

const int Nmax = 1e5+5;

int n, m, q, colour[Nmax], i, maxdist[Nmax], x, y;
vector<int> v[Nmax];

struct query
{
    int v, d, c;
} a[Nmax];


void paint(int node, int dist, int col)
{
    if(!colour[node]) colour[node] = col;
    if(maxdist[node] >= dist) return;

    queue< pair<int,int> > Q;
    Q.push({node, dist});
    maxdist[node] = dist;

    while(Q.size())
    {
        node = Q.front().first;
        dist = Q.front().second - 1;
        Q.pop();

        for(auto it : v[node])
        {
            if(maxdist[it] < dist)
            {
                maxdist[it] = dist;
                Q.push({it, dist});
            }

            if(!colour[it]) colour[it] = col;
        }

    }
}

int main()
{
  
    scanf("%d%d", &n, &m);
    for(i=1; i<=m; ++i)
    {
        scanf("%d%d", &x, &y);
        v[x].push_back(y);
        v[y].push_back(x);
    }

    scanf("%d", &q);
    for(i=1; i<=q; ++i)
        scanf("%d%d%d", &a[i].v, &a[i].d, &a[i].c);

    for(i=q; i; --i)
        paint(a[i].v, a[i].d, a[i].c);

    for(i=1; i<=n; ++i) printf("%d\n", colour[i]);

    return 0;
}


Measured memory_bytes: 8912
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define REP(i,b) FOR(i,0,b)
#define RFOR(i,a,b) for (int i = a-1; i >= b; i--)
#define RREP(i,a) RFOR(i,a,0)
#define REPALL(i,v) for (int i = 0; i < v.size(); i++)
#define SORT(v) sort(v.begin(), v.end())
#define MIN_ELEMENT(v) min_element(v.begin(), v.end())
#define MAX_ELEMENT(v) max_element(v.begin(), v.end())
#define COUNT(v,n) count(v.begin(), v.end(), n);
typedef long long ll;
typedef unsigned long long ull;
const int INF = 1e7;
const ll MOD = 1e9 + 7;

ll dp[111][10];

bool check(int k)
{
    while (k) {
        if ((k & 3) == 3)
            return false;
        k /= 2;
    }
    return true;
}

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

    dp[0][0] = 1;

    REP(i,H) {
        REP(j,W) {
            int kmax = 1 << (W-1);
            for (int k = 0; k < kmax; ++k) {
                if (!check(k)) continue;

                //left
                if (j != 0 && (k >> (j - 1) & 1) == 1) {
                    dp[i+1][j-1] += dp[i][j];
                    dp[i+1][j-1] %= MOD;
                }
                //right
                else if (j != W - 1 && (k >> j & 1) == 1) {
                    dp[i+1][j+1] += dp[i][j];
                    dp[i+1][j+1] %= MOD;
                }
                //straight
                else {
                    dp[i+1][j] += dp[i][j];
                    dp[i+1][j] %= MOD;
                }
            }
        }
    }
    cout<<dp[H][K-1]<<endl;

    return 0;
}


Measured memory_bytes: 256
import Control.Applicative
import Control.Monad

main :: IO ()
main = do
  cs <- lines <$> getContents
  forM_ cs $ \w -> putStrLn $ unwords $ reverse $ map show $ weigh (read w)

weigh :: Int -> [Int]
weigh w = f w a
  where
    f :: Int -> Int -> [Int]
    f w v
      | w == 0    = []
      | w >= v    = v : f (w-v) v
      | otherwise = f w (v`div`2)

    a = until (>=w) (*2) 1 

Measured memory_bytes: 3740
#include <stdio.h>
#include <string.h>
int main(void) {
	char s[20];
	int a, i, b;
	scanf("%s", s);
	a = strlen(s);
	for (i = 0; i < a; i++) {
		if (s[i] == s[a - 1 - i]) {
			b = 1;
		}
		else {
			b = 0;
			break;
		}
	}
	if(b == 1){
			printf("Yes");
	}
	else {
			printf("No");
	}

}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin >> s;
    long long ans=0, sum, p1, p2, po, po1, l, j, i, n = s.size(), ara[ s.size() ], x;
    for(i = 0; i < n ; i++){
        ara[n-i-1] = s[i]-'0' ;
    }

    int n1=(1<<n)/2;

    for( i = 0 ; i < n1 ; i++){
        sum = 0;

        for(j = 0; j < n ; j++){

            x = 1;
            p1 = 0;
            p2 = 0;
            po = 0;

            if(i & (1 << j)){

                for(l = j; l < n ; l++){

                    if((i & (1 << l)) == 0) break;

                    po1 = po;

                    while(po1){

                        x *=10;
                        po1--;

                    }

                    p1 += ara[l] * x;
                    po++;
                    x = 1;

                }

                j = l - 1;

            }
            else{

                for(l = j; l < n ; l++){

                    if(i & (1 << l )) break;

                    po1 = po;

                    while(po1){

                        x *=10;
                        po1--;

                    }

                    p2 += ara[l] * x;
                    po++;
                    x = 1;

                }

                j = l - 1;

            }

            sum += p1 + p2;

        }

        ans += sum;

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

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
  int n;
  while(cin >> n){
    int cur = 100000;
    for(int i=0;i<n;i++){
      cur = 1.05*cur;
      cur = (cur+999)/1000*1000;
    }
    cout << cur << endl;
  }
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
#ifdef DEBUG
#define display(x) cerr << #x << " = " << x << endl;
#define displaya(a, st, n)\
	{cerr << #a << " = {";\
	for(int qwq = (st); qwq <= (n); ++qwq) {\
		if(qwq == (st)) cerr << a[qwq];\
		else cerr << ", " << a[qwq];\
	} cerr << "}" << endl;}
#define displayv(v) displaya(v, 0, (int)(v).size() - 1)
#endif
template<typename T> bool chmin(T &a, const T &b) { return a > b ? a = b, true : false; }
template<typename T> bool chmax(T &a, const T &b) { return a < b ? a = b, true : false; }

const int maxN = 2000 + 5;
int n, m;
vector<int> G[maxN];
int pa[maxN][maxN];
int neib[maxN][maxN];

void DFS(int rt, int u, int fa) {
	pa[rt][u] = fa;
	for(int v : G[u]) if(v != fa) {
		DFS(rt, v, u);
	}
}

void link(int x, int y) {
	assert((neib[x][y] == y) == (neib[y][x] == x));
	if(neib[x][y] == y) return;
	else if(neib[x][y]) link(neib[x][y], y);
	else if(neib[y][x]) link(neib[y][x], x);
	else {
		neib[x][y] = y;
		neib[y][x] = x;
		vector<pii> vp;
		int T = 2;
		while(T--) {
			queue<int> Q;
			Q.push(y);
			while(Q.size()) {
				int u = Q.front(); Q.pop();
				for(int v : G[u]) if(v != pa[x][u]) {
					if(neib[x][v]) {
						assert(neib[x][v] == v);
						vp.emplace_back(y, v);
					} else {
						neib[x][v] = y;
						Q.push(v);
					}
				}
			}
			swap(x, y);
		}
		for(auto p : vp) link(p.first, p.second);
	}
}

int cnt = 0;
void Answer(int tag, int u, int fa) {
	if(neib[tag][u] == u) {
		tag = u;
		++cnt;
	}
	for(int v : G[u]) if(v != fa) Answer(tag, v, u);
}

int main() {
	ios::sync_with_stdio(false);
	cin >> n >> m;
	for(int i = 1; i < n; ++i) {
		int x, y; cin >> x >> y;
		G[x].push_back(y);
		G[y].push_back(x);
	}
	for(int u = 1; u <= n; ++u) DFS(u, u, 0);
	memset(neib, 0, sizeof(neib));
	for(int u = 1; u <= n; ++u) neib[u][u] = u;
	for(int i = 1; i <= m; ++i) {
		int x, y; cin >> x >> y;
		link(x, y);
	}
	for(int u = 1; u <= n; ++u) Answer(u, u, 0);
	cnt -= n;
	// display(cnt);
	assert(cnt % 2 == 0);
	cout << (cnt / 2) << endl;
	return 0;
}



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

int main() {
    int n, m;
    cin >> n >> m;
    int v1[n][m];
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            cin >> v1[i][j];
        }
    }
    int v2[m];
    int i = 0;
    while (i < m) {
        cin >> v2[i];
        i++;
    }

    int pro;
    for (int i = 0; i < n; i++) {
        pro = 0;
        for (int j = 0; j < m; j++) {
            pro += v1[i][j] * v2[j];
        }
        cout << pro << endl;
    }
}



Measured memory_bytes: 3124
N,X,Y = map(int,input().split())
X -=1
Y-=1

dist_dict = {i:0 for i in range(1,N)}
for i in range(N-1):
    for j in range(i+1,N):
        # XYパスを使わない場合
        d0 = j -i
        # XY パスを使う場合
        d1 = abs(X-i) + 1 + abs(j-Y)

        d = min(d0,d1)
        dist_dict[d] += 1
for i in range(1,N):
    print(dist_dict[i])




Measured memory_bytes: 3572
/*
    問題をよく読もう！
    論理的に考えよう！
    サンプルを確認しよう!
    絶対に諦めるな！
    工夫をしろ！
    配列は少し多めにとっておく

    Twitterは終わるまでログアウト！
    （間違えて解法をツイートしてはいけないから）

*/
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <functional>
#include <cmath>
using namespace std;
#define rep(i, n) for(int i=0; i<n; ++i)
typedef long long ll;
//必要な宣言

int main() {
  ll n, m;
  cin >> n >> m;
  ll a[51]; ll b[51]; ll c[51]; ll d[51];
  rep(i, n) cin >> a[i] >> b[i];
  rep(i, m) cin >> c[i] >> d[i];

  for(int i=0; i<n; ++i) {
    ll min = abs(a[i]-c[0]) + abs(b[i]-d[0]);
    ll index = 0;
    for(int j=1; j<m; ++j) {
      if(min > abs(a[i]-c[j]) + abs(b[i]-d[j])) {
        min = abs(a[i]-c[j]) + abs(b[i]-d[j]);
        index = j;
      }
    }
    cout << index+1 << endl;
  }

  return 0;
}

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

bool kaibunn(int a, int b,string c) {
	int check = 0;
	for (int i = a; i < b / 2; i++) {
		if (c[i] != c[b - 1 - i]) {
			check++;
		}
	}
	if (check != 0) {
		return false;
	}
	else {
		return true;
	}
}

int main() {
	string kai;
	bool first,second;
	cin >> kai;
	first=kaibunn(0, kai.size(), kai);
	second=kaibunn(0, (kai.size()) / 2, kai);
	if (first == true && second == true) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main
{
    public static void main(String[] args)
    {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Task solver = new Task();
        solver.solve(1, in, out);
        out.close();
    }

    static class Task
    {
        public void solve(int testNumber, Scanner in, PrintWriter out)
        {
            int A = in.nextInt();
            int B = in.nextInt();
            int C = in.nextInt();
            int K = in.nextInt();

            int sum = 0;

            while (A > 0 && K > 0)
            {
                sum += 1;
                A--;
                K--;
            }
            while (B > 0 && K > 0)
            {
                B--;
                K--;
            }
            while (C > 0 && K > 0)
            {
                sum -= 1;
                C--;
                K--;
            }
            out.println(sum);
        }

    }
}



Measured memory_bytes: 27240
import java.util.Scanner;

class Main{

  static boolean isIncluded(int[] a, int n){
    int i = 0;
    while(a[i] != a[n])
      i++;

    if(i == n)
      return false;
    else
      return true;

  }

  public static void main(String[] arsg){
    Scanner stdIn = new Scanner(System.in);
    int n = stdIn.nextInt();
    int[] a = new int[n+1];

    for(int i = 0; i < n; i++)
      a[i] = stdIn.nextInt();

    int q = stdIn.nextInt();
    int count = 0;
    for(int i = 0; i < q; i++){
      a[n] = stdIn.nextInt();
      if(isIncluded(a, n))
        count++;
    }

    System.out.println(count);
  }
}

Measured memory_bytes: 39944
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var nk = ReadInts();
            var l = ReadInts();
            Array.Sort(l);
            for (int i = 0; i < nk[0]-nk[1]; i++)
            {
                l[i] = 0;
            }
            WriteLine(l.Sum());
        }
        

        private static string Read() { return ReadLine(); }
        private static string[] Reads() { return (Read().Split()); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }

        //最大公約数
        
        public static int Gcd(int a, int b)
        {
            if (a < b)
            {
                return Gcd(b, a);
            }
            while (b != 0)
            {
                var reminder = a % b;
                a = b;
                b = reminder;
            }
            return a;
        }

        //最小公倍数
        public static int Lcm(int a, int b)
        {
            return a * b / Gcd(a, b);
        }

        //文字数を数える
        public static int CountChar(string s, char c)
        {
            return s.Length - s.Replace(c.ToString(), "").Length;
        }
    }
}


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

long long int solve(long long int h){
	if(h==1){
		return 1;
	}
	else{
		return 2*solve(floor(h/2))+1;
	}
}

int main(){
	long long int h;
	cin>>h;
	long long int res = solve(h);
	cout<<res<<endl;
}

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

#define NREP() for(ll i = 0; i < n; i++)
#define MREP() for(ll j = 0; j < m; j++)
#define REP(i, n) for(ll i = 0; i < n; i++)
#define ALL(x) (x).begin(), (x).end()
#define MSG(x) cout << x << endl;
#define IPT(t, x) t ipt; cin >> ipt; x.push_back(ipt);
#define YN(x) x ? cout << "YES" << endl : cout << "NO" << endl;
#define Yn(x) x ? cout << "Yes" << endl : cout << "No" << endl;
#define yn(x) x ? cout << "yes" << endl : cout << "no" << endl;

using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;

const static ll MOD = 1e9 + 7;
ll n, cnt, ans, tmp, sum, a, b, c, d, k, m, h, w, q, x, y;
string s, t;

int main() {
    cin >> n >> k;
    vector<bool> a(n);
    NREP() {
        a[i] = false;
    }

    REP(i, k) {
        cin >> d;
        REP(j, d) {
            ll tmp;
            cin >> tmp;
            a[tmp - 1] = true;
        }
    }

    NREP() {
        if (a[i] == false) ans++;
    }

    MSG(ans)
}


Measured memory_bytes: 3596
#include <iostream>

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"

using namespace std;
using ll = long long;

const ll MOD = 1000000007LL; // = 10^9 + 7
const double PI = 3.14159265358979;

void solve()
{
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  cout << (min( abs(a - c), max( abs(a - b), abs(b - c) ) ) <= d ? "Yes" : "No");
}

int main()
{
  fastio;
  solve();

  return 0;
}

Measured memory_bytes: 3604