akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define dbug(x) cout<<#x<<"="<<x<<endl
using namespace std;
template <typename T> void read(T &t) {
	t=0; char ch=getchar(); int f=1;
	while ('0'>ch||ch>'9') { if (ch=='-') f=-1; ch=getchar(); }
	do {(t*=10)+=ch-'0';ch=getchar();} while ('0'<=ch&&ch<='9'); t*=f;
}
typedef long long ll;
const ll mod=(1e9)+7;
const int maxn=2010;
int n,a[maxn],cnt[maxn];
ll ans,k,s;
int main() {
	//freopen("1.txt","r",stdin);
	read(n); read(k);
	for (int i=1;i<=n;i++) read(a[i]),cnt[a[i]]++;
	for (int i=1;i<=2000;i++) cnt[i]+=cnt[i-1];
	for (int i=1;i<=n;i++) {
		s=0;
		for (int j=i+1;j<=n;j++)
			if (a[i]>a[j]) s++;
		ans=(ans+k*s)%mod;
		ans=(ans+(k*(k-1)/2)%mod*cnt[a[i]-1])%mod;
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <iomanip>
#include <ios> 
#include <vector>
#include <string>
#include <algorithm>
//#include <functional>
#include <queue>
//#include <stack>
//#include <set>
#include <cmath>
//#include <bitset>
#include <map>
using namespace std;
typedef long long ll;

int main() {
  string b;
  cin >> b;
  if(b[0] == 'A') cout << "T" << endl;
  if(b[0] == 'T') cout << "A" << endl;
  if(b[0] == 'C') cout << "G" << endl;
  if(b[0] == 'G') cout << "C" << endl;

  return 0;

}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <limits>
#include <sstream>
#include <fstream>
#include <climits>

typedef long long int64;

int main(void) {
  int n, m;
  std::cin >> n >> m;
  std::vector<int> as;
  for (int i = 0; i < m; i++) {
    int a;
    std::cin >> a;
    as.push_back(a);
  }
  int sum = 0;
  for (int i = 0; i < as.size(); i++) {
    sum += as.at(i);
  }
  int ans = n - sum;
  std::cout << (ans >= 0 ? ans : -1) << std::endl;
  return 0;
}


Measured memory_bytes: 3732
from itertools import combinations_with_replacement
N,M,Q = (int(x) for x in input().split())
q = []
Max = 0
for i in range(Q):
    q.append(list(map(int, input().split())))
for x in combinations_with_replacement(range(1,M+1),N):
    temp = 0
    for y in q:
        if x[y[1]-1] - x[y[0]-1] == y[2]:
            temp += y[3]
    Max = max(temp,Max)
print(Max)

Measured memory_bytes: 9188
#include "bits/stdc++.h"
using namespace std;
using ll = long long int;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pll = pair<ll, ll>;

int N;
vector<pii> BA;

int main() {
	cin >> N;
	for (int i = 0; i < N; i++) {
		int a, b;
		cin >> a >> b;
		BA.emplace_back(b, a);
	}
	sort(BA.begin(), BA.end());

	ll t_sum = 0;
	bool is_yes = true;
	for (auto ba : BA)
	{
		t_sum += ba.second;
		if (t_sum > ba.first) {
			is_yes = false;
			break;
		}
	}

	cout << (is_yes ? "Yes" : "No") << endl;
	return 0;
}

Measured memory_bytes: 2420
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<ctype.h>
#include<cmath>
#include<iomanip>
using namespace std;

int main(void){
	int n,j,r,minv,maxv;
	cin>>n;
	cin>>minv;
	maxv=-1000000000;
	for(j=1;j<n;j++){
		cin>>r;
		if(maxv<r-minv){
			maxv=r-minv;
		}if(minv>r){
			minv=r;
		}
	}cout<<maxv<<endl;
	return 0;
}



Measured memory_bytes: 3100
import java.util.*;
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    long n = sc.nextLong();
    StringBuilder sb = new StringBuilder();
    while (true) {
      n--;
      sb.insert(0, (char) ('a' + n % 26));
      n /= 26;
      if (n == 0) {
        break;
      }
    }
    String ans = sb.toString();
    System.out.println(ans);
  }
}


Measured memory_bytes: 35692
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define ll long long
int main(){
	int n; cin>>n;
	int a,b;
	vector<vector<int>> g(n);
	vector<pair<int,int>> vp;
	for(int i=1;i<n;i++) cin>>a>>b,a--,b--,g[a].emplace_back(b),g[b].emplace_back(a),vp.emplace_back(a,b);
	int k=0;
	map<pair<int,int>,int> I;
	vector<int> cs(n,0);
	vector<int> used(n,0);
	queue<int> q;
	used[0]=1;
	q.emplace(0);
	while(!q.empty()){
		int v=q.front(); q.pop();
		if(k<(int)g[v].size()) k=g[v].size();
		int cur=1;
		for(int u:g[v]){
			if(used[u]) continue;
			if(cur==cs[v]) cur++;
			cs[u]=I[{u,v}]=I[{v,u}]=cur++;
			used[u]=1;
			q.emplace(u);
		}
	}
	cout<<k<<endl;
	for(auto p:vp) cout<<I[p]<<endl;
}


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

// why am I so weak

int n;
vector<int> g[100055];

int par[100055], depth[100055];
bool used[100055];

void dfs(int v, int par = -1, int d = 0) {
	::par[v] = par;
	depth[v] = d;

	for (auto u : g[v]) if (u != par) {
		dfs(u, v, d + 1);
	}
}
void rdfs(int v, int &tot) {
	if (used[v]) return;

	tot++;
	used[v] = true;

	for (auto u : g[v]) if (par[v] != u) {
		rdfs(u, tot);
	}
}
int main() {
	scanf("%d", &n);

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

	dfs(0);

	int v = n - 1, tot = 0;

	for (int i = 0; depth[v] + depth[v] > depth[n - 1]; i++) {
		rdfs(v, tot);
		v = par[v];
	}

	puts(tot * 2 >= n ? "Snuke" : "Fennec");

	return 0;
}


Measured memory_bytes: 11264
#include <iostream>
#include<iomanip>
using namespace std;
int a,k,m,l,n;
double  i,w,e;
int main() {
  cin>>n;
  w=n;
  
  if(n%2==0){
    cout<<"0.5";
  }
  
  else {
    e=(n/2+1)/w;
  }
  cout<<setprecision(9)<<e;
}

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

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

  vector<ll> T(N),A(N);
  for(int i=0;i<N;i++){
    cin>>T[i]>>A[i];
  }
  ll tget=T[0],aget=A[0];

  for(int i=0;i<N;i++){
    ll k=max((tget-1)/T[i]+1,(aget-1)/A[i]+1);
    tget=k*T[i];
    aget=k*A[i];
  }  
  cout<<aget+tget<<endl;
}



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

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

	if((a==b && b!=c) || (a==c && b!=c) || (b==c && a!=b))
		cout<<"Yes";
	else
		cout<<"No";
return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll MOD=1000000007;
const double PI=3.14159265358979;
const ll INF= pow(10,18);
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";

int main() {
  ll r,g,b,n;
  cin >> r >> g >> b >> n;
  ll cnt=0;
  rep(i,n+1){
    rep(j,n+1){
      if(i*r+g*j<=n&&(n-(i*r+g*j))%b==0){
        cnt++;
      }
    }
  }
  cout << cnt << endl;
}

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

int main()
{
    string a,b;
    cin>>a>>b;
    int aaa=a.size();
    int bbb=b.size();
    for(int i=0;i<bbb;i++){
        cout<<a[i]<<b[i];
    }
    if(aaa-bbb==1){
        cout<<a[aaa-1];
    }
    cout << endl;
}

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

#define ll long long
#define ff first
#define ss second
#define pb push_back
#define rep(i,a,b) for(i=a;i<b;i++)
#define pii pair<ll , ll>
#define all(x) x.begin(),x.end()
#define nl "\n"
#define ump unordered_map
#define mtv(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)

vector<string> vec_splitter(string s) {
    s += ',';
    vector<string> res;
    while(!s.empty()) {
        res.push_back(s.substr(0, s.find(',')));
        s = s.substr(s.find(',') + 1);
    }
    return res;
}
void debug_out( 
vector<string> __attribute__ ((unused)) args,
__attribute__ ((unused)) int idx, 
__attribute__ ((unused)) int LINE_NUM) { cout << endl; } 
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
    stringstream ss; ss << H;
    cout << args[idx] << "- " << ss.str() << ", ";
    debug_out(args, idx + 1, LINE_NUM, T...);
}


void doit(){
	ll n,k,i,j,ans = 0,mod = 1e9+7;
	cin >> n >> k;
	vector< ll >v(n+5);
	v[1] = 0;
	rep(i,2,n+4){
		v[i] = v[i-1] + i - 1;
	}
	ll minsum,maxsum;
	rep(i,k,n+2){
		ll minsum = v[i];
		ll maxsum = v[n+1] - v[n-i+1];
		//mtv(minsum,maxsum);
		ans = (ans + maxsum - minsum + 1)%mod;
		ans %= mod;
	}
	cout << ans << nl;
}

int main() {
#ifndef ONLINE_JUDGE
    freopen("input1.txt","r",stdin);
    freopen("output1.txt","w",stdout);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll t = 1;
    // cin >> t;
    for(ll i = 1; i <= t; i++){
        doit();
    }
}


Measured memory_bytes: 4660
import java.lang.Math.max

fun main() {
    val (n, m, q) = readIntList()
    val a = Array(q + 1) { 0 }
    val b = Array(q + 1) { 0 }
    val c = Array(q + 1) { 0 }
    val d = Array(q + 1) { 0 }

    repeat(q) {
        val (i, j, k, l) = readIntList()
        a[it + 1] = i
        b[it + 1] = j
        c[it + 1] = k
        d[it + 1] = l
    }

    var ans = 0

    fun dfs(A: Array<Int>) {
        var tmp = A
        if (tmp.size == n + 1) {
            var now = 0
            for (i in 1..q) {
                if (A[b[i]] - A[a[i]] == c[i]) now += d[i]
            }
            ans = max(ans, now)
            return
        }
        tmp = tmp.plus(tmp.last())
        while (tmp.last() <= m) {
            dfs(tmp)
            val lastI = tmp.lastIndex
            tmp[lastI]++
        }
    }

    dfs(arrayOf(1))
    println(ans)
}

fun readString() = readLine()!!
fun readInt() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readIntList() = readLine()!!.split(" ").map(String::toInt)
fun readLongList() = readLine()!!.split(" ").map(String::toLong)
fun <T> Array<Array<T>>.print() {
    this.forEach {
        println(it.joinToString(" "))
    }
}

Measured memory_bytes: 46952
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <sstream>
#include <algorithm>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <climits>
#include <bitset>
#include <functional>
#include <numeric>
#include <ctime>
#include <cassert>
#include <cstring>
#include <fstream>
#include <iomanip>

using namespace std;

#define FOR(i, a, b) for(int (i)=(a);(i)<(b);(i)++)
#define IFOR(i, a, b) for(int (i)=(a);(i)<=(b);(i)++)
#define RFOR(i, a, b) for(int (i)=(a);(i)>=(b);(i)--)
#define REP(i, n) FOR((i), 0, (n))

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

template<class T>
void print_container(T &container, string delim=" ") {
    bool first = true;
    for(auto &t: container){
        if(!first){
            cout << delim;
        }
        first = false;
        cout << t;
    }
    cout << endl;
}

const double PI = acos(-1);

int main() {
    int a, b, h, m;
    cin >> a >> b >> h >> m;

    int elapsed = h * 60 + m;
    elapsed %= 720;

    double jisin =  elapsed / 720.0 * 2 * PI;
    double hunsin = elapsed / 60.0 * 2 * PI;

    double kakudo = hunsin - jisin;
    
    if(kakudo > PI)
        kakudo = 2*PI - kakudo;
    else if(kakudo < -PI)
        kakudo = 2*PI + kakudo;

    double ans = sqrt(a*a + b * b - 2 * a * b * cos(kakudo));

    printf("%.14f\n", ans);

    return 0;
}

Measured memory_bytes: 3648
using System;

class D
{
	static void Main()
	{
		var s = Console.ReadLine();
		var n = s.Length;

		var k = (n + 1) / 2;
		var m = (n - 1) / 2;
		if (n % 2 == 0)
		{
			if (s[m] == s[m + 1])
			{
				k++;
				for (int i = 1; i <= m && s[m - i] == s[m] && s[m + 1 + i] == s[m]; i++, k++) ;
			}
		}
		else
		{
			for (int i = 1; i <= m && s[m - i] == s[m] && s[m + i] == s[m]; i++, k++) ;
		}
		Console.WriteLine(k);
	}
}


Measured memory_bytes: 26336
#include <iostream>
using namespace std;
int main(){
	int a, b;
	cin >> a >> b;
	if ((a + b) % 2 == 0){
		cout << (a + b) / 2 << endl;
	}
	else{
		cout << (a + b + 1) / 2 << endl;
	}
	return 0;
}

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

using namespace std;

int main() {

    // int a, b, c, d, e;
    vector<int> A(5);
    int k;

    for (int i = 0; i < 5; ++i) {
        cin >> A.at(i);
        // cin >> a >> b >> c >> d >> e >> k;
    }
    cin >> k;
    bool can = true;

    int diff;


    diff = A[4] - A[0];

    if (diff > k){
        can = false;
    }
//    for (int i = 0; i < 4; ++i) {
//        diff = A[i+1] - A[i];
//        if (diff <= k){
//            can = true;
//        }
//        if (diff > k){
//            can = false;
//            break;
//        }
//    }
    
    
    string s;
    if (can){
        s = "Yay!";
    }
    if (!can){
        s =":(";

    }
    cout << s << endl;
}


Measured memory_bytes: 256
<?php
fscanf(STDIN, "%s", $s);
$x = $y = $c = 0;
for ($i = 0; $i < strlen($s); $i++) {
	if ($s[$i] == $c) {
		$x++;
	} else {
		$y++;
	}
	$c = 1 - $c;
}
echo min($x, $y);

Measured memory_bytes: 4604
import sys
input = sys.stdin.readline

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    N=I()
    A,B=MI()
    P=LI()
    P.sort()
    L=[0,0,0]
    for i in range(N):
        if P[i]<=A:
            L[0]+=1
        elif A+1<=P[i]<=B:
            L[1]+=1
        else:
            L[2]+=1
            
    print(min(L))
            
    

main()


Measured memory_bytes: 61920
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=8e3+5;
vector<int> a,b;
char s[N];
int d[2][N*3];
bool solve(vector<int> a,int z)
{
	memset(d,0,sizeof(d));
	d[0][N]=1;
	int now=1;
	for(int i=0;i<a.size();i++)
	{
		for(int j=0;j<N*2;j++)
		{
			d[now][j]=0;
			if((j>=a[i]&&d[now^1][j-a[i]])||d[now^1][j+a[i]])
				d[now][j]=1;
			
		}	
		now^=1;
	}	
	return d[now^1][N+z];
}
int main()
{
	int cnt=0,flag=1,x,y,i=0,now=0;
	scanf("%s%d%d",s,&x,&y);
	while(s[i]&&s[i]=='F')
		now++,i++;
	for(;s[i];i++)
	{
		if(s[i]=='F')
			cnt++;
		else
		{
			if(flag)
				a.push_back(cnt);
			else
				b.push_back(cnt);
			cnt=0,flag^=1;
		}
	}
	if(flag)
		a.push_back(cnt);
	else
		b.push_back(cnt);
//	for(int i=0;i<a.size();i++)
//		cout<<a[i]<<' ';
	puts((solve(a,x-now)&&solve(b,y))?"Yes":"No");
	return 0;
}

Measured memory_bytes: 512
import sys
input = sys.stdin.readline

N, K = map(int, input().split())
H = [0]+list(map(int, input().split()))
dp = [[10**18]*(N+1) for _ in range(N-K+1)]
dp[0][0] = 0

for i in range(N-K):
    for j in range(N+1):
        for k in range(j):
            dp[i+1][j] = min(dp[i+1][j], dp[i][k]+max(0, H[j]-H[k]))

print(min(dp[N-K]))

Measured memory_bytes: 43628
#include<iostream>
#include<cstdio>
#include<cmath>
#include<string>
#include<vector>
#include<map>

using namespace std;

int main(){
	double xx,yy;
	int x,y,pt=0;
	double y_t;
	scanf("%d %d",&x,&y);
	xx=x;
	yy=y;
	for(int x=2;x<2*xx;x+=2){
		y_t=((-yy)/(2*xx))*x+yy;
		if(ceil(y_t)==floor(y_t))
		pt++;
	}
	printf("%d\n",x+y-pt);
}


Measured memory_bytes: 3232
#include <iostream>
#include <string>
#include <vector>
#include <iomanip>
#include <algorithm>
#include <ios>
#include <vector>
#include <cmath>
using namespace std;
int main(void){
  int N;
  cin >> N;

  vector<int>w(N,0);
  for(int i=0;i<N;i++){
    cin >> w[i];
  }

  int ans = 999999999;

  for(int i=1;i<N;i++){
    int sum_p = 0;
    int sum_b = 0;
    for(int j=0;j<i;j++){
      sum_p += w[j];
    }
    for(int j=i;j<N;j++){
      sum_b += w[j];
    }

    int gap = abs(sum_p - sum_b);
    if(gap < ans)
      ans = gap;
  }

  cout << ans << endl;

  return 0;
}


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

using namespace std;
typedef long long ll;
using Pll = pair<ll,ll>;

const ll INF = 1LL<<60;
const ll MOD = 1000000007;

//cout << fixed << setprecision(10);

int main() {
    ll K,x;
    cin >> K >> x;
    for(int i=x-K+1;i<=x+K-1;i++){
        cout << i << " ";
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <deque>
#include <math.h>
#include <stdlib.h>
#include <algorithm>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;

template<class T> inline bool chmin(T &a, T b) { if(a > b){ a = b; return true; } return false; }
template<class T> inline bool chmax(T &a, T b) { if(a < b){ a = b; return true; } return false; }

//INT_MAX	2,147,483,647 = 2*1.0e9

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

  vector<int> A(N);
  for(int i = 0; i < N; i++) cin >> A[i];

  deque<int> q;
  q.push_front(A[0]);
  for(int i = 1; i < N; i++){
    int pos = lower_bound(q.begin(), q.end(), A[i]) - q.begin();
    if(pos == 0) q.push_front(A[i]);
    else q[pos-1] = A[i];
  }

  int ans = q.size();

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1024
import java.util.*;


public class Main {
    public static void main(String[] args) {
        // 自分の得意な言語で
        // Let's チャレンジ！！

        Scanner sc = new Scanner(System.in);
        String line = sc.nextLine();
      String line2 = sc.nextLine();
      int n=line.length();
      int n2=line2.length();
      if(n!=n2){
        System.out.println("No");
      }
      else{
        int count=0;
        boolean f=false;
      	while(count!=n){
      		if(line.equals(line2)){
            	f=true;
              	break;
            }
          String l=line.substring(0,1);
            line=line.substring(1,line.length());
          line+=l;
            count++;
      	}
        if(f){
        	System.out.println("Yes");
        }
        else System.out.println("No");
        
      }
 
    }
}

Measured memory_bytes: 23764
def instr():
    s = input()
    return(list(s[:len(s)]))
# For taking space seperated integer variable inputs.


def invr():
    return(map(int, input().split()))


a, b = invr()
s = instr()

check = "1234567890-"
res = "Yes"

n = len(s)
if n != a+b+1:
    res = "No"
if s[a] != "-":
    res = "No"
for i in range(n):
    if s[i] not in check:
        res = "No"
        break
    if i != a and s[i] == "-":
        res = "No"
        break
print(res)


Measured memory_bytes: 3064
#define _USE_MATH_DEFINES
#include<iostream>
#include<string>
#include<queue>
#include<cmath>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<random>
#include<functional>
#include<algorithm>
#include<stack>
#include<cstdio>
#include<bitset>
#include<unordered_map>
#include<climits>
#include<fstream>
using namespace std;
typedef long long ll;
typedef long double ld;
#define all(a) (a).begin(),(a).end()
#define EPS (1e-5)
#define bit(n,k) ((n>>k)&1)
const ll Mod = 1000000007;
const ll mod = 998244353;
struct H {
	ll x, y;
	bool operator<(const H& b) const {
		if (x != b.x) return x < b.x;
		return y < b.y;
	}
	bool operator>(const H& b) const {
		if (x != b.x) return x > b.x;
		return y > b.y;
	}
	bool operator==(const H& b) const { return x == b.x && y == b.y; }
	bool operator!=(const H& b) const { return (*this) != b; }
};
struct P {
	ll pos, cost;
	bool operator<(const P& b) const { return cost < b.cost; }
	bool operator>(const P& b) const { return cost > b.cost; }
};
struct B {
	ll to, cost;
};
struct E {
	ll from, to, cost;
	bool operator<(const E& b) const { return cost < b.cost; }
	bool operator>(const E& b) const { return cost > b.cost; }
};
template<typename T, typename U>
void chmin(T& a, U b) {
	if (a > b) a = b;
}
template<typename T, typename U>
void chmax(T& a, U b) {
	if (a < b) a = b;
}
template<typename T>
T max_0(T a) {
	if (a < 0) return 0;
	return a;
}
template<typename T>
T min_0(T a) {
	if (a > 0) return 0;
	return a;
}
ll read() {
	ll u;
	ll k = scanf("%lld", &u);
	return u;
}
ll gcd(ll i, ll j) {
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcd(j % i, i);
}
ll mod_pow(ll x, ll n, ll p) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res * x % p;
		x = x * x % p;
		n >>= 1;
	}
	return res;
}//x^n%p
const ll Inf = 3023372036854775807;
const int inf = 1500000000;
#define int long long
//----------------------------------------------------
signed main() {
	int m, d;
	cin >> m >> d;
	int ans = 0;
	for (int i = 1; i <= m; i++) {
		for (int j = 10; j <= d; j++) {
			if (j % 10 < 2 || j / 10 < 2) continue;
			if ((j % 10) * (j / 10) == i) {
				ans++;
			}
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>

int main(){
  long long n,p;
  scanf("%lld %lld",&n,&p);
  long long i,fl=floor(pow(p,1.0/(double)n));
  for(i=fl+1;i>=1;i-=1){
    if(p%(long long)pow(i,n)==0){
      break;
    }
  }
    printf("%lld",i);
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(n) begin(n), end(n)
using ll = long long;
using namespace std;

int main(){
	int n;
	cin >> n;
	map<int, int> m;
	rep(i, n){
		int in;
		cin >> in;
		m[in]++;
	}
	int ans = 0;
	for(auto p : m){
		if(p.first > p.second){
			ans += p.second;
		}else if(p.first < p.second){
			ans += p.second - p.first;
		}
	}
	cout << ans << endl;
	return 0;
}

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

using namespace std;

const long double pi = acos(-1), eps = 0.000845;

long double toRad(long double d) {
  return (long double) d * pi / 180;
}

int val[4][4] = {{1, 2, 4, 3}, {4, 2, 1, 3}, {4, 3, 1, 2}, {1, 3, 4, 2}};

int get(int d, long double l) {
  long double y = l * cos(toRad(fabs(d-30)));
  long double dy = (long double)0.5*sqrt((long double)3);
  int lantai = int (y/dy);
  // assert(int(y/dy + eps) == lantai); 
  // assert(int(y/dy - eps) == lantai); 
  long double sin120 = sin(toRad(120)), sind = sin(toRad(d)), sin60d = sin(toRad(60-d));
  int kanan = - int ((long double)l * sin60d / sin120) + int((long double)l * sind / sin120);
  // assert(int ((long double)l * sin60d / sin120) == int ((long double)l * sin60d / sin120 + eps));
  // assert(int ((long double)l * sin60d / sin120) == int ((long double)l * sin60d / sin120 - eps));
  // assert(int ((long double)l * sind / sin120) == int ((long double)l * sind / sin120 + eps));
  // assert(int ((long double)l * sind / sin120) == int ((long double)l * sind / sin120 - eps));
  kanan %= 4;
  if (kanan < 0) kanan += 4;
  // cerr << val[lantai % 4][kanan % 4] << endl;
  return val[lantai % 4][kanan % 4];
}

int kanan(int v) {
  if (v == 4) return 4;
  if (v == 1) return 2;
  if (v == 2) return 3;
  if (v == 3) return 1;
  assert(false);
}

string s, t;
int a, b;
long double x, y;

int main() {
  cin >> s >> a >> x;
  cin >> t >> b >> y;
  int le = get(a, x), ri = get(b, y);
  if (s != t) {
    if (s[1] == t[0])
      ri = kanan(ri);
    else
      le = kanan(le);
  }
  puts(le == ri ? "YES" : "NO");

  return 0;
}

Measured memory_bytes: 3560
#include "bits/stdc++.h"

#define rep(i, a) for (int i = 0; i < (a); ++i)
#define REP(i, a, b) for (int i = (a); i < (b); ++i)

// debug methods
// usage: debug(x,y);
#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;
using P = pair<int, int>;

void Main() {
  string s, t;
  cin >> s >> t;
  int a, b;
  cin >> a >> b;
  string u;
  cin >> u;
  if (s==u) a--;
  else b--;
  cout << a << " " << b << endl;
}

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

Measured memory_bytes: 256
using System;

namespace abc164
{
    class Program
    {
        static void Main(string[] args)
        {
            var nm = Console.ReadLine().Split(' ');
            var s = int.Parse(nm[0]);
            var w = int.Parse(nm[1]);
            Console.WriteLine((w >= s ? "un" : "") + "safe");
        }
    }
}


Measured memory_bytes: 17860
#include <iostream>
#include <cmath>
#include <vector>
#include <queue>
#include <string>
#include <map>
#include <algorithm>
#include <limits>
#include <ios>
#include <iomanip>
using namespace std;

#define rep(i,N) for(int i=0; i<N; i++)
#define revrep(i,N) for(int i=N-1; i>=0; i--)

typedef long long ll;
typedef unsigned int uint;


map<string,ll> m_map;

const ll E = 1000000000+7;

ll func(string s1, string s2, string s3, int idx){
    //cout << "IN " << s1 << "," << s2 << ", " << s3 << ", " << idx << endl; 

    string key = s1+s2+s3+to_string(idx);
    if (m_map.count(key) == 1){
        return m_map[key];
    }

    if (idx == 0) {
        //cout << "OUT " << idx << endl;
        return 1;
    }

    bool isA = true;
    bool isC = true;
    bool isG = true;
    bool isT = true;
    if(s1 == "G" && s2 == "C") {
        isA = false;
    }
    if(s1 == "A" && s2 == "C") {
        isG = false;
    }
    if(s1 == "C" && s2 == "G") {
        isA = false;
    }
    if(s1 == "G" && s3 == "C") {
        isA = false;
    }
    if(s2 == "G" && s3 == "C") {
        isA = false;
    }

    ll allret = 0;
    if(isA){
        ll ret = 0;
        ret = func("A",s1,s2,idx-1);
        allret += ret % E;
    }
    if(isC){
        ll ret = 0;
        ret = func("C",s1,s2,idx-1);
        allret += ret % E;
    }
    if(isG){
        ll ret = 0;
        ret = func("G",s1,s2,idx-1);
        allret += ret % E;
    }
    if(isT){
        ll ret = 0;
        ret = func("T",s1,s2,idx-1);
        allret += ret % E;
    } 

    
    m_map[key] = allret;

    //cout << "OUT " << idx << endl;
    return allret;
}


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

    ll ret = 0;
    ret += func("A", "", "", N-1);
    ret += func("C", "", "", N-1);
    ret += func("G", "", "", N-1);
    ret += func("T", "", "", N-1);
    cout << ret % E << endl;
    return 0;
}


Measured memory_bytes: 896
#abc136 c
n=int(input())
h=list(map(int,input().split()))
if n==1:
    print("Yes")
else:
    for i in range(n-2,-1,-1):
        if h[i]>h[i+1]:
            h[i]-=1
    flag=True
    for i in range(n-1):
        if h[i]>h[i+1]:
            flag=False
            break
    if flag:
        print("Yes")
    else:
        print("No")

Measured memory_bytes: 14252
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <numeric> 
using namespace std;
typedef long long ll;
const int INF = 1<<30; 
const int MOD = 1e9 + 7;
const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};
int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
    int n;
    cin >> n;
    int tmp = n / 15;
    cout << n * 800 - tmp * 200 << endl;
	return 0;
}



Measured memory_bytes: 256
#include <stdio.h>

int main(){
	int a,b,sum,keta=1;
	
	while(scanf("%d%d",&a,&b)!=EOF){
		keta=1;
		sum=a+b;
	

	while (sum/10!=0){
		sum=sum/10;
		keta=keta+1;
	}
	printf("%d\n",keta);
	
	}
	return 0;
}

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

using namespace std;

#define fi first
#define se second
#define eb emplace_back
#define mt make_tuple
#define all(x) (x).begin(), (x).end() 
#define MOD 1000000007

typedef long long ll;
typedef pair <int, int> ii;
typedef pair <ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef long double ld;

const ll INF=LLONG_MAX;

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    //freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
	int x,y;
	cin >> x >> y;
	int mn = x*2;
	int mx = x*4;
	if(y%2==1||y<mn||y>mx)cout << "No" << endl;
	else cout << "Yes" << endl;
}
	
// READ & UNDERSTAND
// ll, int overflow, array bounds, memset(0)
// special cases (n=1?), n+1 (1-index)
// do smth instead of nothing & stay organized
// WRITE STUFF DOWN


Measured memory_bytes: 3604
#include<bits/stdc++.h>
using namespace std;
unsigned int N;
vector<unsigned long long> A;
unsigned long long tmp;
unsigned long long sum = 1;
int main() {
  cin >> N;
  for (unsigned int i = 0; i < N; i++) {
    cin >> tmp;
    if (tmp == 0) {
      cout << 0 << endl;
      return 0;
    }
    A.push_back(tmp);
  }
  for (unsigned int i = 0; i < N; i++) {
        if (A[i] < 1000000000000000000) {
      sum *= A[i];
      if (sum > 1000000000000000000 || sum < A[i]) {
        cout << -1 << endl;
        return 0;
      }
    }
  }
  cout << sum << endl;
  return 0;
}

Measured memory_bytes: 4296
#include <bits/stdc++.h>
using namespace std;
int main()
{
    //sync_with_stdio(NULL);
    //cin.tie(NULL);
    //cout.tie(NULL);
    int n, k;
    long long s;
    cin >> n >> k >> s;
    if(s<1000000000)
    {
        for(int i=1;i<=k;i++)
        {
            cout << s << " ";
        }
        for(int j=1;j<=n-k;j++)
        {
            cout << s+1 << " ";
        }
    }
    else if(s==1000000000)
    {
        for(int i=1;i<=k;i++)
        {
            cout << s << " ";
        }
        for(int j=1;j<=n-k;j++)
        {
            cout << 1 << " ";
        }
    }
    cout << endl;
    return 0;
}


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

using namespace std;

long int MOD = 1000000007;

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

    vector<long int> f(4);
    f[0] = a * c;
    f[1] = a * d;
    f[2] = b * c;
    f[3] = b * d;

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

    cout << f[3] << endl;
    return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define REP(i,a,b) for(int i=(a);i<(b);i++)
#define RREP(i,a,b) for(int i=(a);i>=(b);i--)
#define pq priority_queue
#define P pair<int,int>
#define P2 pair<int,P>
#define P3 pair<int,P2>
typedef long long ll; typedef long double ld;
using namespace std;
const int INF=1e9, MOD=1e9+7, around[]={0,1,1,-1,-1,0,-1,1,0,0};
const ll LINF=1e18;
const ld PI=abs(acos(-1));
int n,m,a,b,c;
string s,w;
 
int main(){
	cin >> n >> a >> b;
	
	
	cout << min(a*n,b) << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin >> n;
    long long int v = 1;
    for (int i = 1; i <= n; i++)
    {
        v = (v * i) % (1000000000 + 7);
    }
    cout << v << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
const double eps = 1e-8;
const int NINF = 0xc0c0c0c0;
const int INF  = 0x3f3f3f3f;
const ll  mod  = 1e9 + 7;
const ll  N = 1e6 + 5;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll x,k,d;
	cin>>x>>k>>d;
	x=abs(x);
	ll t=x/d;
	ll p=x%d;
	if(t>k) cout<<x-k*d<<'\n';
	else{
		ll nt=k-t;
		if(nt%2==0){
			cout<<min(abs(x-t*d),abs(x-(t+2)*d));
		}else{
			cout<<min(abs(x-t*d-d),abs(x-t*d+d));
		}
	}
	return 0;
}

Measured memory_bytes: 3648
def I(): return int(input())
N = I()
ans = 0
for i in range(105,N+1,2):
    count_yakusuu = 0
    for j in range(1,int(i**0.5)+1):
        if i%j==0:
            count_yakusuu += 2
    if count_yakusuu==8:
        ans += 1
print(ans)


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

#define LL long long
const int mod = 1e9 + 7;
LL n, k, sign = 1, a[200005], x, y, l, r, ans = 1LL;

int main() {
    ios::sync_with_stdio(0), cin.tie(0);
    
    cin >> n >> k;
    for(int i = 0; i < n; i++) cin >> a[i];
    sort(a, a+n);
    r = n - 1;

    if(k % 2) {
        ans = a[r]; 
        --r, --k;
        sign = (ans < 0 ? -1 : 1);
    }        

    while(k > 0) {
        x = a[l] * a[l+1], y = a[r] * a[r-1];
        if(x * sign > y * sign) (ans *= (x % mod)) %= mod, l += 2;
        else (ans *= (y % mod)) %= mod, r -= 2;
        k -= 2; 
    }
    cout << (ans + mod) % mod;
}

Measured memory_bytes: 5216
{-
ITP1_4-B
Computation - Circle
Time Limit : 1 sec, Memory Limit : 65536 KB
????????¢?????¨?????¨

?????? r ???????????¢?????¨?????¨?????????????±???????????????°?????????????????????????????????
Input

??????????????° r ????????????????????????
Output

??¢?????¨?????¨?????????????????????????????§????????£????????????????????????????????????????????????????°???°?????°??¨??????0.00001 ??\???????????????????????§?????????????????¨????????????
Sample Input

2

Sample Output

12.566371 12.566371
-}

import Data.List.Split
import Text.Printf
import Text.Regex
main = do
  s <- getLine
  putStrLn $ aux s

aux :: String -> String
aux s = printf "%.6f %.6f" (pi*r*r) (pi*2.0*r) :: String
    where
    pi = 3.14159265359
    r = read s :: Double

Measured memory_bytes: 3976
import java.math.BigInteger;
import java.util.*;
import java.util.stream.Collectors;

public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    Map<Long, Long> map = new HashMap<>();
    long result = 0L;
    for (int i = 0; i < n; i++) {
      long a = sc.nextLong();
      result += a;
      Long aLong = map.get(a);
      if (aLong == null) {
        aLong = 0L;
      }
      map.put(a, aLong + 1);
    }
    int q = sc.nextInt();
    for (int i = 0; i < q; i++) {
      long b = sc.nextLong();
      long c = sc.nextLong();
      Long aCount = map.get(b);
      if (aCount != null) {
        Long cCount = map.get(c);
        if (cCount == null) {
          cCount = 0L;
        }
        map.put(c, cCount + aCount);
        map.put(b, 0L);
        
        result += (c - b) * aCount;
      }
      System.out.println(result);
    }
  }
}


Measured memory_bytes: 62148
#include "bits/stdc++.h"
using namespace std;
int main()
{
	int l, n = 19;
	scanf("%d", &l);
	for(int i = 1 << n; i > l; i = 1 << --n){}
	vector<vector<int>> a(0, vector<int>(3));
	for(int i = 0; i < n; ++i)
	{
		a.push_back(vector<int>{i, i + 1, 0});
		a.push_back(vector<int>{i, i + 1, 1 << i});
	}
	for(int i = n - 1; i >= 0; --i)
	{
		if(l - (1 << i) >= 1 << n)
		{
			a.push_back(vector<int>{i, n, l -= (1 << i)});
		}
	}
	printf("%d %d\n", n + 1, a.size());
	for(vector<int> i : a)
	{
		printf("%d %d %d\n", i[0] + 1, i[1] + 1, i[2]);
	}
}

Measured memory_bytes: 256
s = input()
if s[0]==s[1] and s[1]!=s[2] and s[2]==s[3]:
    print("Yes")
elif s[0]==s[2] and s[1]!=s[2] and s[1]==s[3]:
    print("Yes")
elif s[0]==s[3] and s[1]==s[2] and s[1]!=s[0]:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i,n) for (ll i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
const ll INF=ll(1e18)+1;


// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;

struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}


// combination mod prime
// https://www.youtube.com/watch?v=8uowVvQ_-Mo&feature=youtu.be&t=1619
struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
}comb(1000005);

//繰り返し2乘法、２＾n
mint f(int n) {
  if (n == 0) return 1;
  mint x = f(n/2);
  x *= x;
  if (n%2 == 1) x *= 2;
  return x;
}





//組み合わせの数nCrを計算
   int calcNumOfCombination(int n, int r){
       int num = 1;
       for(int i = 1; i <= r; i++){
           num = num * (n - i + 1) / i;
       }
       return num;
   }


int main() {
  ios::sync_with_stdio(false);
	cin.tie(0);
  ll n,a,b;
  cin>>n>>a>>b;
//  mint c1=comb(n,a);
//  mint c2=comb(n,b);
  mint ans=f(n);

  ans-=1;
//  cout<<ans<<endl;
  mint g1=1,g2=1;
  for(ll i=n;i>n-a;i--){
    g1*=i;
  }
  for(ll i=1;i<=a;i++){
    g1/=i;
  }
  for(ll i=n;i>n-b;i--){
    g2*=i;
  }
  for(ll i=1;i<=b;i++){
    g2/=i;
  }
  ans-=g1;
  ans-=g2;
cout<<ans;
}


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

int main(){
    int n;
    cin >> n;
    vector<int> d(n);
    rep(i,n) cin >> d[i];
    int sum = 0;
    rep(i,n){
        rep(j,n){
            if(i != j) sum += d[i] * d[j];
        }
    }
    cout << sum/2 << endl;
}

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

using namespace std;

int main(){
	string s,w,z;
	ll n,hana=0,taro=0,i,q,x,y,j;
	
	cin>>s;
	
	cin>>q;
	
	for(i=1;i<=q;i++){
		cin>>w;
		if(w=="replace"){
			cin>>x>>y;
			cin>>z;
			s.replace(x,y-x+1,z);
		}
		  else if(w=="reverse"){
		  	cin>>x>>y;
		  	for(j=0;j<=(y-x)/2;j++){
		  		swap(s[x+j],s[y-j]);
			  }
		  }
		    else{
		    	cin>>x>>y;
		    	for(j=x;j<=y;j++){
		    		cout<<s[j];
				}
				cout<<"\n";
			}
	}
}


Measured memory_bytes: 3228
// This file is a "Hello, world!" in C++ language by GCC for wandbox.
#include <iostream>
#include <cstdlib>
#include <bits/stdc++.h>

using namespace std;
int main()
{
    string  s, t;
    cin >> s >> t;
    int a, b;
    cin >> a >> b;
    
    string u;
    cin >> u;
    if (s == u) {
        a--;
    } else if (t == u) {
        b--;
    }
    cout << a << " " << b << "\n";
}

// GCC reference:
//   https://gcc.gnu.org/

// C++ language references:
//   https://cppreference.com/
//   https://isocpp.org/
//   http://www.open-std.org/jtc1/sc22/wg21/

// Boost libraries references:
//   https://www.boost.org/doc/


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <vector>
#include <stack>
using namespace std;
const int num = 100001;
vector<int> v[num];
int n;
int co[num];
inline void dfs(int t, int c) {
	stack<int> st;
	st.push(t);
	co[t] = c;
	while (!st.empty()) {
		int u = st.top(); st.pop();
		for (int i = 0; i < v[u].size(); i++) {
			int g = v[u][i];
			if (co[g] == 0) {
				co[g] = c;
				st.push(g);
			}
		}
	}
}
int main() {
	int m, s, t, q, id = 0, a, b;
	cin >> n >> m;
	for (int i = 0; i < n; i++)
		co[i] = 0;
	for (int i = 0; i < m; i++) {
		cin >> s >> t;
		v[s].push_back(t);
		v[t].push_back(s);
	}
	for (int i = 0; i < n; i++) {
		if (co[i] == 0) {
			id++;
			dfs(i, id);
		}
	}
	cin >> q;
	for (int i = 0; i < q; i++) {
		cin >> a >> b;
		if (co[a] == co[b])
			cout << "yes" << endl;
		else cout << "no" << endl;
	}
	return 0;
}

Measured memory_bytes: 8936
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef map<int, int> mii;
typedef map<char,int> mci;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<pair<int,int>> vii;
typedef vector<char> vc;
typedef vector<vc> vcc;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define in insert
#define sz(v) v.size()
#define mina(a,b) (a)=min((a),(b));
#define maxa(a,b) (a)=max((a),(b));
const int INF = 1e9 + 7;
vvi v;
ll ans;
int n,k;
void rec(int ind,int cur,int parent){
    for(auto i : v[ind]){
        if(i==parent) continue;
        ans=(ans*(ll)(k-cur))%INF;
        cur++;
        rec(i,2,ind);
    }
}

void solve(){
    cin>>n>>k;
    ans=k;
    v = vvi(n+1,vi());
    for(int i = 1; i < n; i++){
        int a,b; cin>>a>>b;
        v[a].pb(b);
        v[b].pb(a);
    }
    rec(1,1,-1);
    cout<<ans;
}
int main(){
    int T=1;
    //cin>>T;
    for(int i = 0; i < T; i++) solve(); 
}

Measured memory_bytes: 10368
#include<bits/stdc++.h>
using namespace std;
#define se second
#define fi first
#define ll long long
#define ld long double
#define pll pair<ll ,ll >
#define pii pair<int, int> 
#define mod 1000000007
ll power(ll a,ll b){
    ll res=1;
    while(b>0){
        if(b%2!=0) res=(res*a);
        a=(a*a);
        b/=2;
    }
    return res;
}
ll ncr(ll n,ll k){
    if(k==0||k==n) return 1ll;
    if(k>n-k) k=n-k;
    ll pro=1;
    for(ll i=0;i<k;i++){
        pro=(pro*(n-i))%mod;
        pro/=(i+1);
    }
    return (pro%mod);
}
vector<int> prime;
void seive(){
    vector<bool > isprime(101,true);
    for(int i=2;i*i<=100;i++){
        if(isprime[i]){
            for(int j=i*i;j<=100;j+=i){
                isprime[j]=false;
            }
        }
    }
    for(int i=2;i<=100;i++){
        if(isprime[i]) prime.push_back(i);
    }
}
ll digitSum(ll b,ll n){
    if(n<b) return n;
    return digitSum(b, (n/b))+(n%b);
}
int main(void){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll a,b,c;
    cin>>a>>b>>c;
    if(a%2==0 || b%2==0 || c%2==0) cout<<"0";
    else{
        ll ans=min(a*b,min(b*c,a*c));
        cout<<ans;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include<limits.h>
#include<iomanip>
#include <cassert>
#define rep(i, n) for(int i = 0; i < n; i++)
#define rrep(i, n) for(int i = n-1; i >= 0; i--)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(),v.end()
#define RALL(v) v.rbegin(),v.rend()
#define Cout(x) cout << x << endl;
#define check(v) rep(i,v.size()) cout << v[i] << endl;
#define vint(x) vector<int> x
#define vll(x) vector<long long> x
#define vstr(x) vector<string> x
const long long LLINF = 1LL<<60;
const int INF = 1e9;
const long long mod = 1000000007;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
typedef long long ll;
#define pint pair<int,int>
using namespace std;
//オーバーフローに気をつけろよおおおおおお
//確認忘れるなよおおおおおお

const int MAX = 300001;
 
ll fc[MAX];
ll fci[MAX];
 
long long powmod(ll a,ll b){
  return b?powmod(a*a%mod,b/2)*(b%2?a:1)%mod:1;
}
 
void init_fact() {
    fc[0] = fc[1] = 1;
    for (int i=2; i<MAX; ++i) {
        fc[i] = (fc[i-1] * i) % mod;
    }
    fci[1] = 1;
    for (int i=2; i<MAX; ++i) {
        fci[i] = (fci[i-1] * powmod(i, mod-2)) % mod;
    }
}
 
ll C(ll n, ll k) {
    if (k == 0 || n == k) return 1;
    if(k < 0 || k > n) return 0;
    return ((fc[n] * fci[k] % mod) * fci[n-k]) % mod;
}
 
ll add(ll a, ll b) { return (a + b) % mod; }
ll sub(ll a, ll b) { return (a - b + mod) % mod; }
ll mul(ll a, ll b) { return (a * b) % mod; }
 
int main() {
    init_fact();
    int n, K; cin >> n >> K;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    sort(ALL(a));

    ll res = 0;

    rep(i,n) res = add(res, mul(a[i], C(i, K-1)));
    reverse(ALL(a));
    rep(i,n) res = sub(res, mul(a[i], C(i, K-1)));
    cout << res << endl;
    return 0;
}

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

using ll = long long;

int main() {
    // dpx[i][j] Xの番で一番上がa[i]で相手がa[j]を持っているときの最終スコア
    // dpy[i][j] Yの番で一番上がa[i]で相手がa[j]を持っているときの最終スコア
    // dpx[i][j] = max(dpx[i + 1][j], dpy[i + 1][i])
    // dpy[i][j] = min(dpy[i + 1][j], dpx[i + 1][i])
    // A[0] = Z, A[1] = Wとしてdpx[2][1]が答
    // dpx[N + 1][j] = abs(A[N + 1] - A[j]);
    // dpy[N + 1][j] = abs(A[N + 1] - A[j]);
    int N;
    cin >> N;
    vector<int> A(N + 2);
    rep(i, N + 2) cin >> A[i];
    vector<vector<int>> dpx(N + 2, vector<int>(N + 2)), dpy(N + 2, vector<int>(N + 2));
    rep(j, N + 2) {
        dpx[N + 1][j] = abs(A[N + 1] - A[j]);
        dpy[N + 1][j] = abs(A[N + 1] - A[j]);
    }
    for (int i = N; i >= 0; i--) {
        for (int j = N; j >= 0; j--) {
            dpx[i][j] = max(dpx[i + 1][j], dpy[i + 1][i]);
            dpy[i][j] = min(dpy[i + 1][j], dpx[i + 1][i]);
        }
    }
    cout << dpx[2][1] << "\n";
}

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

struct point {
    int id, x, y;
    point() : id(-1), x(0), y(0) {}
    point(int id, int x, int y) : id(id), x(x), y(y) {}
    point(int id, pair<int,int> xy) : id(id), x(xy.first), y(xy.second) {}
    bool operator < (const point &p) const {
        return id < p.id;
    }
};
class kdtree {
private:
    struct node {
        // int p;
        int location;
        node *left;
        node *right;
        node() : left(nullptr), right(nullptr) {}
    };

    static bool lessX(const point &a, const point &b) { return a.x < b.x; }
    static bool lessY(const point &a, const point &b) { return a.y < b.y; }

    node *root;
    int np;
    int N;
    vector<point> &P;

    node *make_kd_tree(int l, int r, int depth) {
        if (!(l < r)) return nullptr;
        int mid = (l + r) / 2;

        if (depth) sort(begin(P) + l, begin(P) + r, lessY);
        else       sort(begin(P) + l, begin(P) + r, lessX);

        node *t = new node();
        t->location = mid;
        t->left = make_kd_tree(l, mid, !depth);
        t->right = make_kd_tree(mid+1, r, !depth);
        return t;
    }
    void find(node *v, int sx, int sy, int tx, int ty, int depth, vector<point> &ans) {
        int x = P[v->location].x;
        int y = P[v->location].y;

        if (sx <= x && x <= tx && sy <= y && y <= ty) {
            ans.push_back(P[v->location]);
        }

        if (depth) {
            if(v->left != nullptr && sy <= y)  find(v->left, sx, sy, tx, ty, !depth, ans);
            if(v->right != nullptr && y <= ty) find(v->right, sx, sy, tx, ty, !depth, ans);
        } else {
            if(v->left != nullptr && sx <= x)  find(v->left, sx, sy, tx, ty, !depth, ans);
            if(v->right != nullptr && x <= tx) find(v->right, sx, sy, tx, ty, !depth, ans);
        }
    }

public:
    kdtree(vector<point> &p) : P(p) {
        np = 0;
        N = p.size();
        root = make_kd_tree(0, N, 0);
    }
    void query(int sx,int sy,int tx,int ty, vector<point> &p) {
        find(root, sx, sy, tx, ty, 0, p);
    }
};

int main() {
    int n;
    cin >> n;
    vector<point> p(n);
    for (int i = 0; i < n; i++) {
        p[i].id = i;
        scanf("%d %d", &p[i].x, &p[i].y);
    }
    kdtree tree(p);
    int q;
    cin >> q;
    while (q--) {
        int sx, tx, sy, ty;
        scanf("%d %d %d %d", &sx, &tx, &sy, &ty);

        vector<point> ans;
        tree.query(sx, sy, tx, ty, ans);

        sort(begin(ans), end(ans));
        for (int i = 0; i < (int)ans.size(); i++) {
            printf("%d\n", ans[i].id);
        }
        printf("\n");
    }
    return 0;
}

Measured memory_bytes: 23648