akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#include <queue>
#define INF 1e9+7
#define rep(i,m,n) for(int i=m;i<n;i++)
#define mrep(i,m,n) for(int i=m;i>n;i--)
#define NO cout<<"NO"<<endl;
#define YES cout << "YES"<<endl;
#define No cout << "No"<<endl;
#define Yes cout << "Yes"<<endl;
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;


//(int)'a'は97 (int)'A'は65 (int)'1'は49
//おまじない

int main() {

	int a, b, ans = 0;
	cin >> a ;
	if (a == 25) {
		cout << "Christmas" << endl;
	}
	else if (a == 24) {
		cout << "Christmas Eve" << endl;
	}
	else if (a == 23) {
		cout << "Christmas Eve Eve" << endl;
	}
	else if (a == 22) {
		cout << "Christmas Eve Eve Eve" << endl;
	}

	return 0;
}

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

using namespace std;

int main() {

	int n;
	cin >> n;

	vector<long long> a(100002, 0);
	vector<long long> b(100002, 0);
	cin >> a[0];
	long long minn = abs(a[0]);
	long long oddcount=0;
	if (a[0] < 0) { oddcount = 1; }
	b[0] = abs(a[0]);
	for (int i = 1; i < n; i++) {
		cin >> a[i];
		b[i] =b[i-1]+abs(a[i]);
		if (a[i] <0) { oddcount++; }
		if (abs(a[i]) < minn) { minn = abs(a[i]); }
	}

	if (oddcount % 2 == 0) {
		cout << b[n - 1];
	}
	else {
		cout << b[n - 1] - minn - minn;
	}


}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
const int MAXN = 100000;
int t[MAXN], x[MAXN], y[MAXN];
int norm(int a, int b) {
  return abs(a) + abs(b);
}
int main() {
  int n, cx = 0, cy = 0, ct = 0; scanf("%d", &n);
  for (int i = 0; i < n; ++i) scanf("%d%d%d", t + i, x + i, y + i);
  for (int i = 0; i < n; ++i) {
    int dis = norm(cx - x[i], cy - y[i]);
    if (dis > t[i] - ct or ((t[i] - ct) ^ dis)&1) return 0 * puts("No");
    cx = x[i], cy = y[i], ct = t[i];
  }
  puts("Yes");
}


Measured memory_bytes: 1408
#include<bits/stdc++.h>
constexpr long long INFL = 1LL << 60;
constexpr int INF = 1 << 30;

using namespace std;

using ll = long long;
using P = tuple<int, int>;
using iarr = valarray<int>;

int main()
{
  int H,W,N;
  cin >> H >> W >> N;
  int cnt, num;
  if(H > W){
    cnt = W;
    num = H;
  }else{
    cnt = H;
    num = W;
  }
  int ans = 0;
  for(int i = 0; i < cnt; ++i){
    if(ans * num >= N) break;
    ans++;
  }
  cout << ans << endl;
  return 0;
}

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

int main() {
	string s;
	getline(cin, s);

	string t;
	getline(cin, t);

	map<char, int> freq_s;
	map<char, int> freq_t;
	int n = s.length();
	int m = t.length();

	int l = 0 , r;

	int resl = -1 , resr = 1e9;

	for (auto x : t)
		freq_t[x]++;

	for (r = 0; r < n; r++) {
		freq_s[s[r]]++;

		bool good = true;

		for (auto x : freq_t) {
			if (freq_s[x.first] < x.second) {
				good = false;
				break;
			}
		}

		if (!good)
			continue;

		while (l <= r && freq_s[s[l]] > freq_t[s[l]]) {
			freq_s[s[l]]--;
			l++;
		}

		if (resr - resl + 1 > r - l + 1) {
			resr = r;
			resl = l;
		}
	}

	if (resl == -1) {
		cout << "No String" << endl;
	}
	else
		cout << s.substr(resl , resr - resl + 1) << endl;
}



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

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

	vector<ll> v(n);
	for (int i = 0; i < n; i++) {
		cin >> v[i];
	}

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

	for (int i = 0; i < n && k > 0; i++) {
		if (v[i] == n - i)
			continue;
		swap(v[i] , v[pos[n - i]]);
		swap(pos[v[i]] , pos[n - i]);
		k--;

	}

	for (int i = 0; i < n; i++)
		cout << v[i] << " ";

}
*/

#include<iostream>
using namespace std;

int main() {
	int d, t, s;
	cin >> d >> t >> s;

	if (d / (s * 1.00) <= t)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;

}


Measured memory_bytes: 3644
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        int R = 0;
        for (int i = s.length() - 1; i >= 0; i--) {
            if (s.charAt(i) == 'Z') {
                R = i;
                break;
            }
        }
        for (int i = 0; i < s.length(); i++) {
            if (s.charAt(i) == 'A') {
                R = R - i + 1;
                break;
            }
        }
        System.out.println(R);
    }
}

Measured memory_bytes: 26756
N = int(input())
A = [int(input()) for i in range(N)]

from bisect import *

h = []

for a in A:
    x = bisect_right(h, -a)
    if len(h) <= x:
        h.append(-a)
    else:
        h[x] = -a

result = len(h)

print(result)



Measured memory_bytes: 55384
#include <bits/stdc++.h>
 
#define rep(i,n) for(ll i=0;i<n;++i)
#define all_map(itr,mp) for(auto itr=mp.begin();itr!=mp.end();itr++)
#define ALL(a) (a).begin(),(a).end()

using namespace std;
using ll  = long long;
using pll = pair<ll, ll>;

const ll MOD  = 1e9 + 7;
const ll LINF = 1LL << 62;
const int INF = 1e9 + 7;

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

    vector<ll> x(m);
    rep(i, m)cin >> x[i];
    sort(ALL(x));

    if(n >= m){
        cout << 0;
        return 0;
    }

    vector<ll> dif(m-1);
    ll sum = 0;
    rep(i, m-1){
        dif[i] = abs(x[i+1] - x[i]);
        sum += dif[i];
    }
    sort(ALL(dif), greater<ll>());

    sum -= accumulate(dif.begin(), dif.begin()+(n-1), 0);
    
    cout << sum << endl;
}

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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>bool chmin(T&a,const T&b){return a>b?(a=b,1):0;}
template<class T>bool chmax(T&a,const T&b){return a<b?(a=b,1):0;}


int nextInt() { int x; scanf("%d", &x); return x;}

int BIG = 1000 * 1000 * 100 + 1;
int R, C;
int on(int x, int y) {
  if (y == 0) return 0 * BIG + x;
  if (x == R) return 1 * BIG + y;
  if (y == C) return 2 * BIG + (R - x);
  if (x == 0) return 3 * BIG + (C - y);
  return -1;
}

int main2() {
  R = nextInt();
  C = nextInt();
  int N = nextInt();

  vector<pair<int,int>> ps;

  REP(i, N) {
    int x1 = nextInt();
    int y1 = nextInt();
    int x2 = nextInt();
    int y2 = nextInt();
    int on1 = on(x1, y1);
    int on2 = on(x2, y2);
    if (on1 >= 0 && on2 >= 0) {
      ps.push_back(make_pair(on1, i));
      ps.push_back(make_pair(on2, i));
    }
  }
  sort(ALL(ps));
  // pv(ALL(ps));
  vector<int> stack;
  REP(i, ps.size()) {
    int v = ps[i].second;
    if (stack.empty()) {
      stack.push_back(v);
    } else {
      if (stack.back() == v) {
        stack.pop_back();
      } else {
        stack.push_back(v);
      }
    }
  }


  if (stack.size() > 0) {
    cout << "NO" << endl;
  } else {
    cout << "YES" << endl;
  }
  return 0;
}

int main() {
  for (;!cin.eof();cin>>ws) main2();
  return 0;
}



Measured memory_bytes: 2672
n, k = map(int, input().split())
xy = [list(map(int, input().split())) for _ in range(n)]

MAX = 10**9
MIN = -1 * MAX
def check(x_r, x_l, y_t, y_b):
    tl = [MIN, MAX]
    br = [MAX, MIN]
    if x_r == x_l or y_t == y_b:
        return False, -1

    tl[0] = max(tl[0], xy[x_l][0])
    tl[1] = min(tl[1], xy[y_t][1])
    br[0] = min(br[0], xy[x_r][0])
    br[1] = max(br[1], xy[y_b][1])

    # count k
    cnt = 0
    for i in range(n):
        if tl[0] <= xy[i][0] <= br[0] and br[1] <= xy[i][1] <= tl[1]:
            cnt += 1
    if cnt < k:
        return False, -1
    area = (br[0] - tl[0]) * (tl[1] - br[1])
    return True, area

INF = 10**20
ans = INF
for a in range(n):
    for b in range(n):
        if a == b:
            continue
        if xy[a][0] < xy[b][0]:
            continue
        for c in range(n):
            for d in range(n):
                if c == d:
                    continue
                if xy[c][1] < xy[d][1]:
                    continue
                f, area = check(a, b, c, d)
                if f:
                    ans = min(ans, area)
print(ans)

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

int n,c;
int a[35],b[35];
int dp[35][(1<<16)];


int dfs(int num,int bit){
  
  if(num == n) return 0;
  
  int rec = 0,cnt,on;
  bit |= a[num];
  
  for(int i=0;i<c;i++){
    
    cnt = __builtin_popcount(bit&b[i]);
    on = (bit& ~b[i]);
    rec = max(rec,dfs(num+1,on) + cnt);
    
  }
  
  return rec;
}

int main(){
  
  int d;
  
  while(cin >> n >> c,n!=0&&c!=0){
    
    for(int i=0;i<n;i++){
      a[i] = 0;
      for(int j=0;j<16;j++){
	cin >> d;
	a[i] |= (d<<j);
      }
    }
    
    for(int i=0;i<c;i++){
      b[i] = 0;
      for(int j=0;j<16;j++){
	cin >> d;
	b[i] |= (d<<j);
      }
    }
    
    int bit,cnt,on;
    fill_n(*dp,(n+1)*(1<<16),-1);
    dp[0][0] = 0;
    for(int i=0;i<n;i++){
      for(int j=0;j<(1<<16);j++){
	
	if(dp[i][j] == -1) continue;

	bit = a[i]|j;
	
	for(int k=0;k<c;k++){
	  cnt = __builtin_popcount(bit&b[k]);
	  on = (bit& ~b[k]);
	  dp[i+1][on] = max(dp[i+1][on],dp[i][j]+cnt);
	}
      }
    }
    
    int ans = 0;
    for(int i=0;i<(1<<16);i++) ans = max(ans,dp[n][i]);
    cout << ans << endl;

  }
 
  return(0);
}



Measured memory_bytes: 11048
#include <iostream>
#include <cstdio>
#include <cstdint>

using namespace std;

int64_t cnt(int64_t a, int64_t b, int64_t d)
{
    return b / d - (a + d - 1) / d + 1;
}

int64_t gcf(int64_t a, int64_t b)
{
    if (b == 0)
    {
        return a;
    }
    return gcf(b, a % b);
}

int main()
{
    int64_t a, b, c, d;
    cin >> a >> b >> c >> d;

    const int64_t u = cnt(a, b, 1);
    const int64_t uc = cnt(a, b, c);
    const int64_t ud = cnt(a, b, d);
    const int64_t ucd = cnt(a, b, c * d / gcf(c, d));

    const int64_t res = u - uc - ud + ucd;
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <climits>
#include <string>
#include <vector>
#include <cmath>

using namespace std;

#define str to_string
#define rep(i, n) for (int i=0; i<int(n); i++)
#define all(c) (c).begin(), (c).end()

#define MAX_N 11

int n, k;
int list[MAX_N];

int solve() {

  int ans = 0;
  vector<int> v;
  do {
    int score = 0;
    rep(i, k) {
      int x = list[i];
      if (x < 10) score = score*10 + x;
      else        score = score*100 + x;
    }
    if (!binary_search(v.begin(), v.end(), score)) {
      ans++;
      v.push_back(score);
      sort(v.begin(), v.end());
    }
  } while (next_permutation(list, list+n));
  return ans;
}

int main() {
  while (true) {
    cin >> n >> k;
    if (n == 0 && k == 0) break;
    rep(i, n) cin >> list[i];
    sort(list, list+n);

    cout << solve() << '\n';
  }
  return 0;
}

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

vector<int> to[2000005];
vector<int> ans;
void dfs(int v,int p=-1){
  for(int u : to[v]){
    if(u==p) continue;
    ans[u] += ans[v];
    dfs(u,v);
  }
}

int main(){
  int n,q;
  cin >> n >> q;
  rep(i,n-1){
    int a,b;
    cin >> a >> b;
    --a; --b;
    to[a].push_back(b);
    to[b].push_back(a);
  }
  ans.resize(n);
  rep(i,q){
    int p,x;
    cin >> p >> x;
    --p;
    ans[p]+=x;
  }
  dfs(0);
  rep(i,n){
    cout << ans[i] << endl;
  }
  return 0;
}


Measured memory_bytes: 65664
import java.util.*;

public class Main {
public static void main(String[] args){

Scanner sc = new Scanner(System.in);
int a = sc.nextInt(),b = sc.nextInt();
if(a % 2 == 0 || b % 2 == 0){
System.out.println("No");
}else{
System.out.println("Yes");
}

}
}

Measured memory_bytes: 22996
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
int n,a[1000100],pos[1000100],f[1000010];
long long ans=0;
int main()
{
	cin>>n;
	int ans=1e9;
	for(register int i=1;i<=n;++i)
	{
	  cin>>a[i];pos[a[i]]=i;
}
	int maxx=0;
	for(register int i=1;i<=n;++i)
	{
		if(pos[a[i]-1]<i)
		{
			f[i]+=f[pos[a[i]-1]]+1;
		}
		else f[i]=1;
		maxx=max(f[i],maxx);
	}
	cout<<n-maxx;
	return 0;
}

Measured memory_bytes: 9344
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<map>
using namespace std;
#define ll long long
const int mod = 1000000007;
const ll INF = 1000000000000000000;

int main()
{
	ll x, K;
	cin >> x >> K;
	if (x * 2 <= K) {
		cout << x << endl;
	}
	else {
		ll num = x % K;
		cout << min(num, abs(num - K)) << endl;
	}
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

public static void main(String[] args) {

		//??\??????????????????????????????Scanner???????????§???????????????
		Scanner scan = new Scanner(System.in);

		//??????????????????????????????
		String str = scan.next();

		//????????°?????????????????????
		int q = scan.nextInt();

		//????????°?????°???????????????
		for(int i = 0; i < q; i++){
			//?????????????????????
			String order = scan.next();
			//????????????????????????????????????
			int num1 = scan.nextInt();
			int num2 = scan.nextInt();

			if(order.equals("replace")){
				//??\??????????????????????????????????????????
				String rep = scan.next();
				//??\????????????????????????str?????£??\?????????
				str = str.substring(0 , num1) + rep + str.substring(num2 + 1);
			} else if(order.equals("reverse")){
				//??????????????§??????????????\???????????????
				String r = textRevers(str.substring(num1, num2 + 1));
				//??????????????¨????????°?????£?¨??????????
				String temp = "";
				//reverse?????????????????????????????????????????£??\?????????
				temp += str.substring(0 , num1);
				//?????????????????????????????£????????????
				temp += r;
				//?????£?????????????????£????????????
				temp += str.substring(num2 + 1);
				//??£?????????????????????str?????£??\?????????
				str = temp;

			} else if(order.equals("print")){
				//???????????????????????£?????????
				System.out.println(str.substring(num1 , num2 + 1));
			}
		}

	}

	/**
	 * ?????????????????????????????????????????????
	 * @String r
	 */
	public static String textRevers(String r){

		//??????????????£?¨?
		String rev = "";

		//???????????£??????????????????????????????????????????????????????????????????
		for(int i = r.length()- 1; 0 <= i; i--){
			rev += r.charAt(i);
			//System.out.println(rev);
		}
		return rev;
	}

}

Measured memory_bytes: 46968
#include<bits/stdc++.h>
using namespace std;
const int MAXQ = 1e7 + 5;
const int MAXN = 1e3 + 5;
const int MAXP = 5e3 + 5;
const int INF = 1e9;
const long long INFLL = 1e18;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
template <typename T> void chkmax(T &x, T y) {x = max(x, y); }
template <typename T> void chkmin(T &x, T y) {x = min(x, y); } 
template <typename T> void read(T &x) {
	x = 0; int f = 1;
	char c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
	for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
	x *= f;
}
template <typename T> void write(T x) {
	if (x < 0) x = -x, putchar('-');
	if (x > 9) write(x / 10);
	putchar(x % 10 + '0');
}
template <typename T> void writeln(T x) {
	write(x);
	puts("");
}
struct edge {int dest, flow, pos, cost; };
vector <edge> a[MAXP];
int s, t, tot, flow; ll cost;
ll dist[MAXP]; int path[MAXP], home[MAXP];
void FlowPath() {
	int p = t, ans = INF;
	while (p != s) {
		ans = min(ans, a[path[p]][home[p]].flow);
		p = path[p];
	}
	flow += ans;
	cost += ans * dist[t];
	p = t;
	while (p != s) {
		a[path[p]][home[p]].flow -= ans;
		a[p][a[path[p]][home[p]].pos].flow += ans;
		p = path[p];
	}
}
bool spfa() {
	static int q[MAXQ];
	static bool inq[MAXP];
	static int l = 0, r = 0;
	for (int i = 0; i <= r; i++)
		dist[q[i]] = -INFLL;
	q[l = r = 0] = s, dist[s] = 0, inq[s] = true;
	while (l <= r) {
		int tmp = q[l];
		for (unsigned i = 0; i < a[tmp].size(); i++)
			if (a[tmp][i].flow != 0 && dist[tmp] + a[tmp][i].cost > dist[a[tmp][i].dest]) {
				dist[a[tmp][i].dest] = dist[tmp] + a[tmp][i].cost;
				path[a[tmp][i].dest] = tmp;
				home[a[tmp][i].dest] = i;
				if (!inq[a[tmp][i].dest]) {
					q[++r] = a[tmp][i].dest;
					inq[q[r]] = true;
				}
			}
		l++, inq[tmp] = false;
	}
	return dist[t] != -INFLL;
}
void addedge(int x, int y, int z, int c) {
	a[x].push_back((edge){y, z, a[y].size(), c});
	a[y].push_back((edge){x, 0, a[x].size() - 1, -c});
}
int n, mid[4], cntx[MAXN], cnty[MAXN];
pair <int, int> posx[MAXN], posy[MAXN];
int main() {
	read(n), tot = 2 * n;
	s = ++tot, t = ++tot;
	for (int i = 0; i <= 3; i++)
		mid[i] = ++tot;
	for (int i = 1; i <= n; i++) {
		read(posx[i].first), read(posx[i].second), read(cntx[i]);
		addedge(s, i, cntx[i], 0);
		addedge(i, mid[0], INF, -posx[i].first - posx[i].second);
		addedge(i, mid[1], INF, posx[i].first - posx[i].second);
		addedge(i, mid[2], INF, -posx[i].first + posx[i].second);
		addedge(i, mid[3], INF, posx[i].first + posx[i].second);
	}
	for (int i = 1; i <= n; i++) {
		read(posy[i].first), read(posy[i].second), read(cnty[i]);
		addedge(n + i, t, cnty[i], 0);
		addedge(mid[0], n + i, INF, posy[i].first + posy[i].second);
		addedge(mid[1], n + i, INF, -posy[i].first + posy[i].second);
		addedge(mid[2], n + i, INF, posy[i].first - posy[i].second);
		addedge(mid[3], n + i, INF, -posy[i].first - posy[i].second);
	}
	for (int i = 1; i <= tot; i++)
		dist[i] = -INFLL;
	while (spfa()) FlowPath();
	writeln(cost);
	return 0;
}

Measured memory_bytes: 896
//inlclude前用define 
#define _USE_MATH_DEFINES

//include
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<cstdio>
#include<type_traits>
#include<numeric>
//#include<deque>
#include<limits>
#include<iomanip>
#include<set>
#include<tuple>
#include<map>

using namespace std;

//typedef
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<char> VC;
typedef long long int ll;

//define
#define INF 1000000000 
#define NUM 1000000007
#define all(x) begin(x), end(x)
#define rep(i,n) for(int i=0;i<(int)(n);i++)

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

	int size = s.size();

	rep(i, size) {
		if (i % w == 0) {
			cout << s[i];
		}
	}
	cout << "\n";
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
	int n,p,d1,d2,i,m,a;
	while(1){
		scanf("%d",&n);
		if(n==0){
			break;
		}
		m=0;
		for(i=0;i<n;i++){
			scanf("%d%d%d",&p,&d1,&d2);
			if(d1+d2>m){
				a=p;
				m=d1+d2;
			}
		}
		printf("%d %d\n",a,m);
	}
	return 0;
}

Measured memory_bytes: 600
# coding: utf-8
# Your code here!
while 1:
    n,x = list(map(int,input().split()))
    if n == x == 0:
        break
    c = 0
    for i in range(1,n+1):
        for j in range(i+1,n+1):
            for k in range(j+1,n+1):
                if i+j+k ==x:
                    c += 1
                    #print(i,j,k)
    print(c)


Measured memory_bytes: 5596
#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
}




void solve()
{
  
  int n;
  cin >> n;
  string s;
  cin >> s;

  if(n%2!=0)
  {
    cout<<"No\n";
    return ;
  }

  string s1 = s.substr(0,n/2);
  string s2 = s.substr(n/2,n/2);

  if(s1==s2)
  {
    cout<<"Yes\n";

  }else cout<<"No\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: 3584
#include<bits/stdc++.h>
using namespace std;
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define rep(i,n) for(int i=0; i<(n); ++i)
#define per(i,n) for(int i=n-1;i>=0;++i)
#define rep1(i,n) for(int i=1; i<=n; ++i)
#define per1(i,n) for(int i=n; i>=1; ++i)
#define debug cout << "line : " << __LINE__ << " debug" << endl
#define Dcout(N) cout << setprecision(20) << N << endl
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() ) //被り削除
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define INF 1e9
const int mod = 1000000007;
typedef long long ll;
//------------------------------------------------------------------------


bool is_prime(int n){
    switch(n){
        case 0: // fall-through
        case 1: return false;
        case 2: // fall-through
        case 3: return true;
    } // n > 3 が保証された

    if(n%2 == 0) return false;
    if(n%3 == 0) return false;
    // 2と3の倍数でないので6の倍数ではないことが保証された

    if(n%6 != 1 && n%6 != 5) return false;
    // 6の倍数前後の数(素数かもしれない数)であることが保証された

    // 6の倍数前後の数を使って試し割りをする
    for(unsigned i=5;i*i<=n;i+=6){
        if(n%i     == 0) return false; // 6n-1
        if(n%(i+2) == 0) return false; // 6n+1
    }

    return true;
}


int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int x; cin >> x;
  
  
  for(int i=x;;i++){
    if(is_prime(i)){
      cout << i << endl;
      return 0;
    }
  }
    
  
  
  return 0;
}









Measured memory_bytes: 256
N, M = list(map(int, input().split()))
AB = [tuple(map(int, input().split())) for _ in range(M)]

uf = [-1]*N

def find(x):
    if uf[x]<0: return x
    uf[x] = find(uf[x])
    return uf[x]

def size(x):
    return -uf[find(x)]

def union(x, y):
    x, y = find(x), find(y)
    if size(x) > size(y): x, y = y, x
    uf[y] += uf[x]
    uf[x] = y

c = [N*(N-1)//2]
for a, b in reversed(AB):
    if find(a-1) != find(b-1):
        sa, sb = size(a-1), size(b-1)
        union(a-1, b-1)
        c.append(c[-1]-sa*sb)
    else:
        c.append(c[-1])

for t in reversed(c[:-1]):
    print(t)

Measured memory_bytes: 26380
#include <iostream>
#include <vector>
#include <map>
using namespace std;
typedef long long ll;

int main() {
	int N;
	char S[4096];
	cin >> N >> S;
	int cR=0, cG=0, cB=0;
	for (int i = 0; i < N; i++) {
		switch (S[i]) {
		case 'R':
			cR++;
			break;
		case 'G':
			cG++;
			break;
		case 'B':
			cB++;
			break;
		}
	}
	ll ans = (ll)cR * cG * cB;

	for (int i = 0; i < N-2; i++) {
		for (int sa = 1; sa < (N-i+1)/2; sa++) {
			if (S[i] != S[i+sa] && S[i+sa] != S[i+sa+sa] && S[i] != S[i + sa + sa]) ans--;
		}
	}
	cout << ans << "\n";

	return 0;
}

Measured memory_bytes: 3572
import java.util.*;

class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		String t = sc.next();
		int sol = t.length();
		for (int i = 0; i <= s.length() - t.length(); i++) {
			int count = 0;
			int k = i;
			for (int j = 0; j < t.length(); j++) {
				if (s.charAt(k) != t.charAt(j)) {
					count++;
				}
				k++;
			}
			sol = Math.min(count, sol);
		}
		System.out.println(sol);
	}

}

Measured memory_bytes: 35472
#pragma GCC optimize "03"
#include "bits/stdc++.h"
using namespace std;
 
#define int long long int
#define ld long double
#define pi pair<int, int>
#define pb push_back
#define fi first
#define se second
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#ifndef LOCAL
#define endl '\n'
#endif
 
const int N = 1e5 + 5;
const int mod = 1e9 + 7;
const int inf = 1e9 + 9;

int dp[N], dp1[N];
 
signed main() {
    IOS;
    #ifdef LOCAL
        freopen("input.txt","r", stdin);
        freopen("output.txt","w",stdout);
    #endif
    string s;   cin >> s;
    int len = s.length();
    s = "#" + s;
    dp1[0] = 1;
    for(int i = 1; i <= len; i++){
        if(s[i] == '1'){
            dp1[i] = (2*dp1[i-1]) % mod;
            dp[i] = (dp1[i-1] + 3*dp[i-1]) % mod;
       }
       else{
            dp1[i] = dp1[i-1];
            dp[i] = (3*dp[i-1]) % mod;
        }
    }   
    cout << (dp1[len] + dp[len]) % mod;
    return 0;
}

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

int main(){
  int n;
  cin >> n;
  vector<int> v(n);
  for(int i=0;i<n;i++){
    cin >> v.at(i);
  }
  int ans=999999;
  for(int p=0;p<100;p++){
    int a=0;
    for(int i=0;i<n;i++){
      a+=(v.at(i)-p)*(v.at(i)-p);
    }
    if(ans>a){
      ans=a;
    }
  }
  cout << ans << endl;
}


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

using namespace std;

#define ll long long
#define ld long double

int n;
ld E[301][301][301];

ld calc(int cnt1, int cnt2, int cnt3) {
	if (cnt1 == 0 && cnt2 == 0 && cnt3 == 0)
		return 0.0;
	if (E[cnt1][cnt2][cnt3] > 0.0)
		return E[cnt1][cnt2][cnt3];
	ld res = (ld)n;
	if (cnt1 > 0)
		res += ((ld)cnt1) * calc(cnt1 - 1, cnt2, cnt3);
	if (cnt1 < n && cnt2 > 0)
		res += ((ld)cnt2) * calc(cnt1 + 1, cnt2 - 1, cnt3);
	if (cnt2 < n && cnt3 > 0)
		res += ((ld)cnt3) * calc(cnt1, cnt2 + 1, cnt3 - 1);
	res /= ((ld)cnt1 + (ld)cnt2 + (ld)cnt3);
	E[cnt1][cnt2][cnt3] = res;
	return res;
}

signed main() {
	int cnt[4] = {};
	cin >> n;
	for (int i = 0; i < n; ++i) {
		int ai; cin >> ai;
		++cnt[ai];
	}

	cout << setprecision(15) << calc(cnt[1], cnt[2], cnt[3]) << endl;

	return 0;
}

Measured memory_bytes: 426368
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(int (i) = (s);(i) <= (e);(i)++)

int N,M;

vector<vector<int>> edges;

int main(){
  cin >> N >> M;
  edges.resize(N);
  rep(i,0,M - 1){
    int a,b;
    cin >> a >> b;
    a--;
    b--;
    edges[a].push_back(b);
    edges[b].push_back(a);
  }

  vector<int> ans;

  vector<int> ans2;

  vector<bool> vis(N,false);

  vis[0] = true;
  vis[edges[0][0]] = true;
  ans.push_back(0);
  ans2.push_back(edges[0][0]);

  while(true){
    int next = -1;
    {
      for(auto to : edges[ans.back()]){
        if(!vis[to]) next = to;
      }
    }

    if(next == -1){
      break;
    }
    ans.push_back(next);
    vis[next] = true;
  }
  while(true){
    int next = -1;
    {
      for(auto to : edges[ans2.back()]){
        if(!vis[to]) next = to;
      }
    }

    if(next == -1){
      break;
    }
    ans2.push_back(next);
    vis[next] = true;
  }

  reverse(ans2.begin(),ans2.end());

  cout << ans.size() + ans2.size() << endl;

  for(int i : ans2){
    cout << i + 1 << " ";
  }

  for(int i : ans){
    cout << i + 1 << " ";
  }
  cout << endl;
}


Measured memory_bytes: 6844
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
#include <string>
#include <set>
#include <bitset>
#include <unordered_map>
#include <cmath>
#include <functional>
#include <map>

using namespace std;
using ll = long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;
template <class T>
using Vvec = vector<vector<T> >;

template <class T>
void debug(T& v)
{
    for(auto& x: v) cout << x << " ";
    cout << endl;
}

int main()
{
    ll K, N;
    cin >> K >> N;
    vector<ll> A(N);
    for(auto& x: A) cin >> x;
    A.emplace_back(A[0] + K);

    ll ans = K;
    for(int i=0; i<N; i++){
        ans = min(ans, K - A[i+1] + A[i]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 4864
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int N;
ll A[200100];
ll B[200100];
int main(){
	cin >> N;
	for(int i=0;i<N;i++){
		cin >> A[i];
		if(A[i]>i){
			cout << -1 << endl;
			return 0;
		}
		B[i]=i-A[i];
	}
	for(int i=1;i<N;i++){
		if(A[i]-A[i-1]>1){
			cout << -1 << endl;
			return 0;
		}
	}
	for(int i=0;i<N-1;i++){
		if(B[i+1]-B[i]<0){
			cout << -1 << endl;
			return 0;
		}
	}
	ll ans = 0ll;
	for(int i=N-1;i>=0;i--){
		if(i+1<N&&B[i+1]==B[i])continue;
		ans += A[i];
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
#define debug(x) cerr << #x << ": " << x << endl
#define debugArray(x, n)                           \
  for (long long hoge = 0; (hoge) < (n); ++(hoge)) \
  cerr << #x << "[" << hoge << "]: " << x[hoge] << endl
using namespace std;

long long D;
long long c[26];
long long s[366][26];
long long t[366];
long long score() {
  long long last[D + 1][26];
  fill(last[0], last[0] + 26, 0);
  long long ret = 0;
  for (int d = 0; d < D; d++) {
    ret += s[d][t[d]];
    for (int i = 0; i < 26; i++) {
      last[d + 1][i] = last[d][i];
    }
    last[d + 1][t[d]] = d + 1;
    for (int i = 0; i < 26; i++) {
      ret -= c[i] * (d + 1 - last[d + 1][i]);
    }
  }
  return ret;
}

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> D;
  for (int i = 0; i < 26; i++) cin >> c[i];
  for (int d = 0; d < D; d++) {
    for (int i = 0; i < 26; i++) {
      cin >> s[d][i];
    }
  }
  for (int d = 0; d < D; d++) {
    long long last[26];
    fill(last, last + 26, 0);
    for (int d = 0; d < D; d++) {
      int max_i = 0;
      long long max_v = 0;
      for (int i = 0; i < 26; i++) {
        long long tmp = c[i] * (d + 1 - last[i]) + s[d][i];
        if (max_v < tmp) {
          max_v = tmp;
          max_i = i;
        }
        last[max_i] = d + 1;
        t[d] = max_i;
      }
    }
  }
  long long cur_score = score();
  int M = 100000;
  random_device seed_gen;
  mt19937 engine(seed_gen());
  for (int i = 0; i < M; i++) {
    int d, q;
    d = engine() % D;
    q = engine() % 26;
    int old = t[d];
    t[d] = q;
    long long new_score = score();
    if (cur_score > new_score) {
      t[d] = old;
    } else {
      cur_score = new_score;
    }
  }
  for (int d = 0; d < D; d++) cout << t[d] + 1 << endl;
  return 0;
}


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

int main() {
  //ある数字の配列で、何回それが出現したかカウントする
  // mapで格納して、数字を添え字で隣にカウントを作るイメージ
  int N;
  cin >> N;
  vector<string> vec(N);
  for (int i = 0; i < N; i++) {
    cin >> vec.at(i);
  }

  vector<map<char, int>> cnt(N);

  for (int i = 0; i < N; i++) {
    for (auto x : vec.at(i)) {
      if (cnt.at(i).count(x)) {
        cnt.at(i).at(x)++;
      } else {
        cnt[i][x] = 1;
      }
    }
  }
  long long count = 0;
  map<map<char,int>, long long> mp;
  for(int i=0; i<N; i++){
    mp[cnt[i]]++;
  }

  for(auto& x : mp){
    long long v = x.second;
    count += v*(v-1)/2;
  }
  cout << count << endl;
}

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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
//#define int long long int

#define M 1e18

void solve() {
	set<int> s;
	int n = 3,num;
	while(n-- && cin >> num) {
		s.insert(num);
	}
	cout << s.size() << endl;
}
		
			
		

int32_t main() {
	IOS;
	solve();
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define SIZE 200005
using namespace std;
typedef long long int ll;
typedef pair <int,int> P;

int A[SIZE];
int n,m,v,p;
bool check(int d)
{
	if(d>=n-p) return true;
	int lim=A[d]+m;
	ll zan=(ll) m*(ll) (v-p);
	int cnt=0;
	for(int i=0;i+p<=n;i++)
	{
		if(i==d) continue;
		ll c=min((ll) m,(ll) lim-A[i]);
		if(c<0) return false;
		zan-=c;
	}
	return zan<=0;
}
int main()
{
	scanf("%d %d %d %d",&n,&m,&v,&p);
	for(int i=0;i<n;i++) scanf("%d",&A[i]);
	sort(A,A+n);
	int l=-1,r=n;
	while(r-l>1)
	{
		int d=(l+r)/2;
		if(check(d)) r=d;
		else l=d;
	}
	printf("%d\n",n-r);
	return 0;
}

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

typedef long long ll;
typedef long double ld;
typedef pair <ll, ll> pll;

#define pb push_back
#define mp make_pair
#define all(_c) _c.begin(), _c.end()

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

    int n;
    cin >> n;
    
    int a[n][3];
    for (int i = 0; i < n; i++)
        for (int j = 0; j < 3; j++)
            cin >> a[i][j];
    
    vector <vector <int> > dp(n, vector <int> (3, 0));
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < 3; j++) {
            if (!i)
                dp[i][j] = a[i][j];
            else
                dp[i][j] = a[i][j] + max(dp[i - 1][(j + 1) % 3], dp[i - 1][(j + 2) % 3]);
        }
    }

    cout << *max_element(all(dp.back())) << '\n';
    return 0;
}


Measured memory_bytes: 6912
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>
#include <cstring>
#include <cmath>
#include <stack>
#include <iomanip>
#include <tuple>
#include <functional>
#include <cfloat>
#include <map>
#include <stdio.h>
#include <string.h>
using ll = long long;

//LLONG_MAX
#define int long long
#define CONTAINS(v,n) (find((v).begin(), (v).end(), (n)) != (v).end())
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ARY_SORT(a, size) sort((a), (a)+(size))
#define MAX(a,b) (((a) > (b)) ? (a) : (b))
#define MIN(a,b) (((a) < (b)) ? (a) : (b))
#define REMOVE(v,a) (v.erase(remove((v).begin(), (v).end(), (a)), (v).end()))
#define REVERSE(v) (reverse((v).begin(), (v).end()))
#define LOWER_BOUND(v,a) (lower_bound((v).begin(), (v).end(), (a)))
#define UPPER_BOUND(v,a) (upper_bound((v).begin(), (v).end(), (a)))
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define CONTAINS_MAP(m, a) (m).find((a)) != m.end()
using namespace std;

int N;
int H[100001];

signed main()
{
	cin >> N;
	REP(i, N) cin >> H[i];

	int cur = H[0];
	for (int i = 1; i < N; i++)
	{
		if (cur <= H[i] - 1)
		{
			cur = H[i] - 1;
		}
		else if (cur <= H[i])
		{
			cur = H[i];
		}
		else
		{
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
}











Measured memory_bytes: 1024
import sys
sys.setrecursionlimit(10**7) #再帰関数の上限,10**5以上の場合python
import math
from copy import copy, deepcopy
from copy import deepcopy as dcp
from operator import itemgetter
from bisect import bisect_left, bisect, bisect_right#2分探索
#bisect_left(l,x), bisect(l,x)#aはソート済みである必要あり。aの中からx未満の要素数を返す。rightだと以下
from collections import deque, defaultdict
#deque(l), pop(), append(x), popleft(), appendleft(x)
#q.rotate(n)で → にn回ローテート
from collections import Counter#文字列を個数カウント辞書に、
#S=Counter(l),S.most_common(x),S.keys(),S.values(),S.items()
from itertools import accumulate,combinations,permutations,product#累積和
#list(accumulate(l))
from heapq import heapify,heappop,heappush
#heapify(q),heappush(q,a),heappop(q) #q=heapify(q)としないこと、返り値はNone
from functools import reduce,lru_cache#pypyでもうごく
#@lru_cache(maxsize = None)#maxsizeは保存するデータ数の最大値、2**nが最も高効率
from decimal import Decimal
from argparse import ArgumentParser

args=ArgumentParser()
args.add_argument('-loc', '--local', type=bool,default=False)
LOCAL=args.parse_args().local

def input(): 
    x=sys.stdin.readline(); 
    if x[-1]=="\n": 
        return x.rstrip() 
    return x
    
def printe(*x):_=print("## ",*x,file=sys.stderr) if LOCAL else 0
def printl(li): _=print(*li, sep="\n") if li else None
def argsort(s, return_sorted=False): 
    inds=sorted(range(len(s)), key=lambda k: s[k])
    if return_sorted: return inds, [s[i] for i in inds]
    return inds
def alp2num(c,cap=False): return ord(c)-97 if not cap else ord(c)-65
def num2alp(i,cap=False): return chr(i+97) if not cap else chr(i+65)
def matmat(A,B):
    K,N,M=len(B),len(A),len(B[0])
    return [[sum([(A[i][k]*B[k][j]) for k in range(K)]) for j in range(M)] for i in range(N)]
def matvec(M,v):
    N,size=len(v),len(M)
    return [sum([M[i][j]*v[j] for j in range(N)]) for i in range(size)]
def T(M):
    n,m=len(M),len(M[0])
    return [[M[j][i] for j in range(n)] for i in range(m)]
def binr(x): return bin(x)[2:]
def bitcount(x): #xは64bit整数
    x= x - ((x >> 1) & 0x5555555555555555)
    x= (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333)
    x= (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f 
    x+= (x >> 8); x+= (x >> 16); x+= (x >> 32) 
    return x & 0x7f

def main():
    mod = 1000000007
    #w.sort(key=itemgetter(1),reverse=True)  #二個目の要素で降順並び替え

    #N = int(input())
    #N, K = map(int, input().split())
    #A = tuple(map(int, input().split())) #1行ベクトル
    #L = tuple(int(input()) for i in range(N)) #改行ベクトル
    #S = tuple(tuple(map(int, input().split())) for i in range(N)) #改行行列
    s=input()
    cnt=0
    for si in s:
        cnt+=int(si)
    if cnt%9==0:
        print('Yes')
    else:
        print('No')


if __name__ == "__main__":
    main()

Measured memory_bytes: 74004
#include <iostream>
#include <vector>
#include <algorithm>
#include <vector>
#include <queue>
#include <stdio.h>
#include <functional>
#define int long long
using namespace std;
 
signed main(){
    int n;
    int max=0;
    int min=0;
    cin>> n;
    int N=3*n;
    int a[N];
 
    priority_queue<int> PQ1;
    priority_queue<int, vector<int>, greater<int> >PQ2;
 
    int max_arr[n+2]={0};
    int min_arr[n+2]={0};
    
    for(int i=0;i<3*n;i++){
        cin>>a[i];
        
    }
 
    for(int i=0;i<n;i++){
        max+=a[i];
        min+=a[i+2*n];
    }
 
    // cout<<max<<" "<<min<<endl;
 
    max_arr[0]=max;
    
    for(int i=0;i<n;i++){
        PQ2.push(a[i]);
    }
 
    for(int i=n;i<2*n+1;i++){
        PQ2.push(a[i]);
        max+=a[i];
        max-=PQ2.top();
        PQ2.pop();
        max_arr[i-n+1]=max;
 
    }
 
    // for(int i=0;i<n+1;i++){
    //     cout<<max_arr[i]<<" ";
    // }
 
    min_arr[n]=min;
    for(int i=2*n;i<3*n;i++){
        PQ1.push(a[i]);
    }
    for(int i=3*n;i>2*n;i--){
        // cout<<i-n-1<<endl;
        PQ1.push(a[i-n-1]);
        min+=a[i-n-1];
        min-=PQ1.top();
 
        // cout<<PQ1.top()<<endl;
        PQ1.pop();
        min_arr[(i-2*n)-1]=min;
    }
    // cout<<count<<endl;
 
 
    // for(int i=0;i<n+1;i++){
    //     cout<<min_arr[i]<<" ";
    // }
 
 
    // for(int i=0;i<n+1;i++){
    //     max[i]=
    // }
 
    int ans=-1e19;
    for(int i=0;i<n+1;i++){
        if(ans<max_arr[i]-min_arr[i]){
            ans=max_arr[i]-min_arr[i];
        }
        // ans=max(ans,);
    }
    // cout<<ans<<endl;
    

    cout<<ans<<endl;
 
}

Measured memory_bytes: 6516
#include <bits/stdc++.h>
typedef long long ll;
#define mod 1000000007
#define pb push_back
#define mp(a,b) make_pair(a,b)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vll vector <ll>
#define vii vector <int>
#define vpii vector <pii>
#define vpll vector <pll>
#define ff first
#define ss second
#define matrix vector <vll>
#define all(v) v.begin(),v.end()
#define PQ priority_queue
using namespace std;
vii graph[100005];
bool visited[100005];
ll inv(ll a){
	ll b = mod -2,res  = 1;
	a%=mod;
	while(b > 0){
		if(b&1) res = (res * a)%mod;
		a = (a*a)%mod;
		b/=2;
	}
	return res%mod;
}
int main()
{
	//ios::sync_with_stdio(0);
	//cin.tie(0);
	int n, k;
	cin >> n >> k;
	for(int i = 0; i < n-1; i++){
		int x,y;
		cin >> x >> y;
		graph[x].pb(y);
		graph[y].pb(x);
	}
	queue <int> q;
	q.push(1);
	ll ans = 1;
	ll p[n+1] = {0};
	for(int i = 0; i <= n; i++) p[i] = -1;
	p[0] = k;
	p[1] = 1;
	ll pr = 1;
	ll fact[k+1];
	fact[0] = 1;
	for(ll i = 1; i <= k; i++){
		pr  = (pr * i)%mod;
		fact[i] = pr;
	}
	ll num = k - graph[1].size() - 1;
	if(num < 0){
		p[1] =  0;
		cout << "0\n";
		return 0;
	}
	else p[1] = (fact[k-1]*inv(fact[num]))%mod;
	while(!q.empty()){
		int f = q.front();
		q.pop();
		if(f != 1){
			p[f] = 1;
			ll num = k - graph[f].size() - 1;
			if(k >= 2 && num >= 0) p[f] = (fact[k-2]*inv(fact[num]))%mod;
			else {
				p[f] = 0;
				cout << "0\n";
				return 0;
			}
		}
		for(int u: graph[f]){
			if(p[u] == -1) q.push(u);
		}
	}
	for(int i = 0; i <= n; i++){
		// cout << p[i] << "\n";
		ans = (ans * p[i])%mod;
	}
	cout << ans << "\n";
	return 0;
}



Measured memory_bytes: 8056
module Main where
import qualified Data.ByteString.Char8         as BS
import           Data.Vector.Unboxed            ( (!) )
import qualified Data.Vector.Unboxed           as VU
import qualified Data.Vector.Unboxed.Mutable   as VUM
import           Debug.Trace

main :: IO ()
main = do
  n <- readLn
  s <- VU.fromList <$> getLine
  let nof c = VU.length . VU.filter (== c)
  let rgb = 'R' `nof` s * 'G' `nof` s * 'B' `nof` s
  let ixs =
        [ (i, j, k)
        | i <- [0 .. n - 1]
        , j <- [i .. n - 1]
        , let k = 2 * j - i
        , k < n
        ]
  let f v (i, j, k) = v ! i /= v ! j && v ! j /= v ! k && v ! k /= v ! i
  let comp = length (filter (f s) ixs)
  print $ rgb - comp


Measured memory_bytes: 4744
//Dragon_warrior7(IITK)
#pragma GCC optimize ("Ofast")
#pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize ("-ffloat-store")
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
using namespace std;
//using namespace __gnu_pbds;
#define umap unordered_map
#define ll long long
#define pb push_back
#define nl cout << '\n'
#define sor(x) sort(x.begin(), x.end())
#define rev(v) reverse(v.begin(), v.end())
#define lb(v, temp) lower_bound(v.begin(), v.end(), temp)
#define ub(v, temp) upper_bound(v.begin(), v.end(), temp)
#define fi first
#define se second
#define llmax 1000000000000000000
#define pll pair<ll, ll> 
#define ull unsigned ll
#define vll vector<ll> 
#define rub cout << "\n------------------------------------\n"
#define deb(x) cout<<#x<<' '<<'='<<' '<<x<<'\n'
//typedef  tree < int ,  null_type ,  greater<int> ,  rb_tree_tag ,  tree_order_statistics_node_update > oset;
void read(vector<ll> &v)
{
	for (int i = 0; i < v.size(); i++)
		cin >> v[i];
}
// const int mod=1e9+7;
// ll power(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
// ll modInverse(ll a){return power(a,mod-2);}
ll n,m,a,b,c,k,temp,x,y;
void solveforthiscase(const int & test)
{//deb(test);
cin>>n;
vll v(n);
read(v);
umap <ll,ll> count;
for(int i=0;i<n;i++)
{
    count[v[i]]++;
}
sort(v.begin(),v.end(),greater<>());
ll ans=0;
ll l=-1,b=-1;
for(int i=0;i<n;i++)
{
    if(l!=-1 && b!=-1)
    break;
    if(count[v[i]]==1)
    {
        continue;
    }
    if(count[v[i]]>3 && l==-1)
    {
        l=v[i];
        b=v[i];
    }
    else if(count[v[i]]>1)
    {
      if(l==-1)
      l=v[i];
      else if(l!=v[i])
      b=v[i];
    }
}
if(l!=-1 && b!=-1)
{
    ans=l*b;
    //deb(l);
    //deb(b);
}
cout<<ans;
return ;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int test=1;
// 	cin>>test;
    for(int i=1;i<=test;i++)
    {
        solveforthiscase(i);
    }
}

Measured memory_bytes: 5156
with Ada.Text_IO, Ada.Integer_Text_IO, Ada.Float_Text_IO;
 use Ada.Text_IO, Ada.Integer_Text_IO, Ada.Float_Text_IO;

procedure main is
   N: Integer;
   R: Integer;
begin
   get(N);
   get(R);
   if (N > 10) then put(R);
   else put(R + (10 - N) * 100, 0);
   end if;
end main;

Measured memory_bytes: 3696
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const long double EPS=1e-9;
const long double PI=acos(-1.0);
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}
long double ABS(long double a){return max(a,-a);}
char in[1100000];

int main(){
	int a;scanf("%d",&a);
	scanf("%s",in);
	int b;scanf("%d",&b);
	while(b--){
		int K;scanf("%d",&K);
		long long ret=0;
		long long sum=0;
		int at=0;
		int nm=0;
		for(int i=0;i<a;i++){
			if(i-K>=0){
				if(in[i-K]=='D'){
					sum-=at;
					nm--;
				}else if(in[i-K]=='M'){
					at--;
				}
			}
			if(in[i]=='D'){
				nm++;
			}else if(in[i]=='M'){
				at++;
				sum+=nm;
			}else if(in[i]=='C'){
				ret+=sum;
			}
		}
		printf("%lld\n",ret);
	}
}

Measured memory_bytes: 1152
package main

import (
	"bufio"
	"fmt"
	"strconv"
)

var sc *bufio.Scanner

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	// sc = bufio.NewScanner(os.Stdin)
	// sc.Split(bufio.ScanWords)
	var s string
	fmt.Scan(&s)
	ans := 0
	cntA := 0
	flgB := false
	for _, r := range s {
		switch {
		case r == 'A':
			if flgB {
				cntA = 0
				flgB = false
			}
			cntA++
		case r == 'B' && !flgB:
			flgB = true
		case r == 'C' && flgB:
			ans += cntA
			flgB = false
		default:
			cntA = 0
			flgB = false
		}
	}
	fmt.Println(ans)
}


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

#ifdef LOCAL
#include "../dump.hpp"
#else
#define dump(...)
#define showvv(v)
#endif

using namespace std;

#define rep(i,n) for(int i=0,i##_len=(n);i<i##_len;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define ROF(i,a,b) for(int i=(a)-1;i>=(b);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend() //sortで大きい順
#define UNIQUE(v) v.erase(unique(all(v)),v.end())
#define SUM(a) accumulate(all(a),0)
#define sz(x) ((int)(x).size())
#define pb push_back
#define fst first
#define snd second

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef long long ll;

int main(){
  int n,m,R; cin >> n >> m >> R;
  vi r(R);
  rep(i,R){
    cin >> r[i];
    r[i]--;
  }
  sort(all(r));

  vector<vector<ll>> g(n,vector<ll>(n,1ll<<59));
  ll a,b,c;
  rep(i,m){
    cin >> a >> b >> c;
    a--; b--;
    g[a][b] = g[b][a] = c;
  }
  
  rep(k,n) rep(i,n) rep(j,n) g[i][j] = min(g[i][j], g[i][k] + g[k][j]);

  ll ans = 1ll << 59;
  do{
    ll d = 0;
    rep(i,R-1) d += g[r[i]][r[i+1]];
    ans = min(ans, d);
  }while(next_permutation(all(r)));

  cout << ans << endl;
}

Measured memory_bytes: 512
n=int(input())
a=list(map(int,input().split()))

increase_flag=False
decrease_flag=False
answer=0
if n!=1:
  for i in range(len(a)-1):
    if increase_flag==False and decrease_flag==False:

      if a[i+1]>a[i]:
        increase_flag=True
        answer+=1
      elif a[i+1]<a[i]:
        decrease_flag=True
        answer+=1
      
    else:
      if decrease_flag==True and a[i+1]>a[i]:
        decrease_flag=False
      elif increase_flag==True and a[i+1]<a[i]:
        increase_flag=False

  if increase_flag==False and decrease_flag==False:
    if a[-1]>a[-2]:
      increase_flag=True
      answer+=1
    elif a[-1]<a[-2]:
      decrease_flag=True
      answer+=1
  print(answer)
else:
  print(1)
    

Measured memory_bytes: 14224
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = (s); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) for(int i = (n); i >= 0; i--)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << '\n';
#define CFYN(n) cout << ( (n) ? "YES":"NO") << '\n';
#define OUT(n) cout << (n) << '\n';
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;

int main(void)
{
    IOS
    int H, W, K;
    cin >> H >> W >> K;
    vector<string> hw(H);
    REP(i,H) cin >> hw[i];
    int bh = pow(2,H),bw = pow(2,W);
    int ans = 0;
    REP(i,bh) REP(j,bw) {
        int count = 0;
        bitset<6> bsh(i),bsw(j);
        REP(y,H) REP(x,W) {
            if (bsh[y] || bsw[x]) continue;
            if (hw[y][x] == '#') count++;
        }
        if (count == K) ans++;
    }

    cout << ans << '\n';

    return 0;
}

Measured memory_bytes: 4064
import java.util.Scanner;
class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        if(a<b && b<c){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
    }
}



Measured memory_bytes: 26200