akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
using namespace std;
#define ll long long

ll d[100009], td[100009], v[100009];
int c[100009];

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	int n; ll w; cin >> n >> w;
	for (int i = 0; i < n; i++)
		cin >> v[i] >> c[i];
	for (int i = 0; i <= 100000; i++)
		d[i] = 1000000000000000LL;
	d[0] = 0;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j <= 100000; j++) {
			if (j - c[i] >= 0 && d[j - c[i]] != 1000000000000000LL)
				td[j] = min(d[j], d[j - c[i]] + v[i]);
			else
				td[j] = d[j];
		}
		for (int j = 0; j <= 100000; j++) {
			d[j] = td[j]; td[j] = 1000000000000000LL;
		}
	}
	int mx = 0;
	for (int i = 0; i <= 100000; i++)
		if (d[i] != 1000000000000000LL && d[i] <= w)
			mx = max(mx, i);
	cout << mx << '\n';
	return 0;
}

Measured memory_bytes: 1792
#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<cstring>
#include<bitset>
#include<unordered_map>
#include<climits>
#include<fstream>
#include<time.h>
#include<cassert>

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
ll bitcount(ll x) {
	int sum = 0;
	for (int i = 0; i < 20; i++)
		if ((1ll << i) & x) sum++;
	return sum;
}
ll fact_[200000];
ll comb(ll x, ll y, ll mod = Mod) {
	if (!fact_[0]) {
		fact_[0] = 1;
		for (int i = 1; i < 200000; i++) {
			fact_[i] = fact_[i - 1] * i % mod;
		}
	}
	if (x < y) return 0;
	return mod_pow(fact_[x], mod, mod) *
		mod_pow(fact_[x - y], mod - 2, mod) % mod *
		mod_pow(fact_[y], mod - 2, mod) % mod;
}//xCy
const ll Inf = 3023372036854775807;
const int inf = 1500000000;
#define int long long
//----------------------------------------------------
int a, b;
signed main() {
	string s;
	cin >> s;
	if (s == "SUN") cout << 7 << endl;
	if (s == "MON") cout << 6 << endl;
	if (s == "TUE") cout << 5 << endl;
	if (s == "WED") cout << 4 << endl;
	if (s == "THU") cout << 3 << endl;
	if (s == "FRI") cout << 2 << endl;
	if (s == "SAT") cout << 1 << endl;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**8)
input = sys.stdin.readline

sa = input() + "#"
sb = input() + "#"
sc = input() + "#"
ia = 0
ib = 0
ic = 0
who = 0
for i in range(300):
  if who == 0:
    if sa[ia] == "#":
      print("A")
      exit()
    elif sa[ia] == "b":
      who = 1
    elif sa[ia] == "c":
      who = 2
    ia += 1
  elif who == 1:
    if sb[ib] == "#":
      print("B")
      exit()
    elif sb[ib] == "a":
      who = 0
    elif sb[ib] == "c":
      who = 2   
    ib += 1
  elif who == 2:
    if sc[ic] == "#":
      print("C")
      exit()
    elif sc[ic] == "a":
      who = 0
    elif sc[ic] == "b":
      who = 1  
    ic += 1

Measured memory_bytes: 3064
bingo = [list(map(int,input().split())) for i in range(3)]
n = int(input())
num = [int(input()) for i in range(n)]
for i in num:
  for row in range(3):
    for col in range(3):
      if bingo[row][col] == i:
        bingo[row][col] = 0
if sum(bingo[0]) == 0 or sum(bingo[1]) == 0 or sum(bingo[2]) == 0 or sum([hoge[0] for hoge in bingo]) == 0 or sum([hoge[1] for hoge in bingo]) == 0 or sum([hoge[2] for hoge in bingo]) == 0 or sum([bingo[i][i] for i in range(3)]) == 0 or sum([bingo[i][2-i] for i in range(3)]) == 0:
  print('Yes')
else:
  print('No')

Measured memory_bytes: 3064
eval"N,*T,Z=#{`tr ' 
' ,`}1"
T<<0
N.times{|i|a,b=T[N+i,2]
Z=Z*[[[a,t=T[i]].min,0,-1[a-t]][s=T[i-1]<=>t],0,(s%3-1)[t-a]][b<=>a]%(10**9+7)}
p Z
##########

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

for i in range(n):
    a[i] = a[i]-(i+1)

a.sort()
b = (a[n//2]+a[(n-1)//2])//2

ans = 0
for i in range(n):
    ans += abs(a[i]-b)
print(ans)


Measured memory_bytes: 86612
//g++ -std=c++14 test.cpp -o test.out
//問題URL
//https://atcoder.jp/contests/aising2019/tasks/aising2019_c

//参考
//https://betrue12.hateblo.jp/entry/2019/01/13/030527

//マスをグラフの頂点、色の異なるマス同士に辺がかかっている
//森だとみなすと考えやすい

#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <vector>
#include <queue>
#include <map> 
#include <utility>
#include <limits.h>
#include <bitset>
#include <set>
using namespace std;
 
#define LL long long int
const LL INF = (1LL<<60);
const int INF_INT = 2147483647-1e6-1;
const LL mod = 1000000007ll;
const int mod_int = 1000000007;

LL H,W;
string S[400];

LL ans = 0;

void solve(){
	vector<vector<int>> used(H,vector<int>(W,0));
	auto dfs = [&](int h,int w){
		LL color[2] = {0,0};//color[0]を白のマスの数、color[1]を黒のマスの数とおく
		//pair<h,w>
		queue<pair<int,int>> q;
		q.push(pair<int,int>(h,w));
		used[h][w] = 1;
		color[(S[h][w]=='#')]++;
		while(!q.empty()){
			int y = q.front().first;
			int x = q.front().second;
			q.pop();

			auto make_next_point = [&](){
				vector<pair<int,int>> ret;
				if(y+1<H){
					if(S[y+1][x]!=S[y][x] && !used[y+1][x])ret.push_back(pair<int,int>(y+1,x));
				}
				if(y-1>=0){
					if(S[y-1][x]!=S[y][x] && !used[y-1][x])ret.push_back(pair<int,int>(y-1,x));
				}
				if(x+1<W){
					if(S[y][x+1]!=S[y][x] && !used[y][x+1])ret.push_back(pair<int,int>(y,x+1));
				}
				if(x-1>=0){
					if(S[y][x-1]!=S[y][x] && !used[y][x-1])ret.push_back(pair<int,int>(y,x-1));
				}
				return ret;
			};

			for(pair<int,int> next : make_next_point()){
				int next_y = next.first;
				int next_x = next.second;
				used[next_y][next_x] = 1;
				color[(S[next_y][next_x]=='#')]++;
				q.push(pair<int,int>(next_y,next_x));
			}
		}
		ans += color[0]*color[1];
	};

	for(int h=0;h<H;h++){
		for(int w=0;w<W;w++){
			if(!used[h][w]) dfs(h,w);
		}
	}
}
 
int main(){
    cin >> H >> W;
    for(int h=0;h<H;h++){
    	cin >> S[h];
    }
 
    solve();

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

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

template <typename InputIterator>
typename InputIterator::value_type summation(InputIterator first,
                                             InputIterator last) {
  return std::accumulate(first, last, typename InputIterator::value_type());
}
template <typename T>
std::istream &operator>>(std::istream &stream, std::vector<T> &v);
template <typename T1, typename T2>
std::istream &operator>>(std::istream &stream, std::pair<T1, T2> &p);
template <typename T>
std::istream &operator>>(std::istream &stream, std::vector<T> &v) {
  for (auto &i : v) {
    stream >> i;
  }
  return stream;
}
template <typename T1, typename T2>
std::istream &operator>>(std::istream &stream, std::pair<T1, T2> &p) {
  stream >> p.first >> p.second;
  return stream;
}

int main() {
  int64_t n;
  std::cin >> n;
  std::vector<int64_t> p(n);
  std::cin >> p;

  std::vector<int64_t> pos(n);

  for (int64_t i = 0; i < n; i++) {
    pos[p[i] - 1] = i;
  }
  std::set<int64_t> s;
  s.insert(pos.back());

  int64_t ans = 0;
  for (int64_t i = n - 2; 0 <= i; i--) {
    const auto cur = pos[i];
    auto up = s.upper_bound(cur);
    if (up != s.cend()) {
      const auto r = *up;
      auto itr1 = up;
      itr1++;
      int64_t r_max = n - 1;
      if (itr1 != s.cend()) {
        r_max = *itr1 - 1;
      }
      int64_t l = cur, l_min = 0;
      auto itr2 = up;
      if (itr2 != s.cbegin()) {
        itr2--;
        l_min = *itr2 + 1;
      }
      ans += (l - l_min + 1) * (r_max - r + 1) * (i + 1);
    }
    auto down = up;
    if (down != s.cbegin()) {
      down--;
      const auto l = *down;
      auto itr1 = down;
      int64_t l_min = 0;
      if (itr1 != s.cbegin()) {
        itr1--;
        l_min = *itr1 + 1;
      }

      int64_t r = cur, r_max = n - 1;
      auto itr2 = down;
      itr2++;
      if (itr2 != s.cend()) {
        r_max = *itr2 - 1;
      }
      ans += (l - l_min + 1) * (r_max - r + 1) * (i + 1);
    }
    s.insert(cur);
  }
  std::cout << ans << std::endl;
  return 0;
}


Measured memory_bytes: 6528
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF (2e9)
#define EPS (1e-7)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int main() {
    int n;
    string s;
    cin >> n;
    cin >> s;
    
    int r=0, b=0;
    for (int i = 0; i < (int)s.size(); i++) {
        char ch =s[i];
        ch == 'R' ? r++ : b++;
    }
    if (r > b) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <map>

using namespace std;

int main(){
    bool flag = false;
    int count = 0;
    string s;
    map<char,int>m;

    cin >> s;

    for(int i = 0;i < s.size();i++){
        if(m.find(s[i]) == m.end()){
            m[s[i]]++;
            count++;
        }else{
            m[s[i]]++;
            if(m[s[i]] > 2) flag = true;
        }
    }

    if(count > 2 || flag){
        cout << "No" << endl;
    }else{
        cout << "Yes" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
	
	ll n;
	cin>>n;
	string arr;
	ll i;
	cin>>arr;
	ll j,sum=0,l=arr.length();
	ll r[l+2]={0},g[l+2]={0},b[l+2]={0};
	if(arr[l-1]=='R')
		r[l-1]=1;
	else if(arr[l-1]=='G')
		g[l-1]=1;
	else
		b[l-1]=1;

    for(i=l-2;i>=0;i--)
    {
    	if(arr[i]=='R')
    	{
    		r[i]=r[i+1]+1;
    		b[i]=b[i+1];
    		g[i]=g[i+1];
    	}
    	else if(arr[i]=='B')
    	{
    	    r[i]=r[i+1];
    		b[i]=b[i+1]+1;
    		g[i]=g[i+1];	
    	}
    	else
    	{
    	     r[i]=r[i+1];
    		b[i]=b[i+1];
    		g[i]=g[i+1]+1;		
    	}
    }
     for(i=0;i<l;i++)
     {
     	if(arr[i]=='R')
     {
     	for(j=i+1;j<l;j++)
     	{
               if(arr[j]=='G'&&arr[j+j-i]=='B')
               {
               	sum=sum+b[j+1]-1;
               }
               else if(arr[j]=='G'&&arr[j+j-i]!='B')
               {
               	sum=sum+b[j+1];
               }
               if(arr[j]=='B'&&arr[j+j-i]=='G')
               {
               	sum=sum+g[j+1]-1;
               }
               else if(arr[j]=='B'&&arr[j+j-i]!='G')
               {
               	sum=sum+g[j+1];
               }
     	}
     }
      else if(arr[i]=='B')
     {
     	for(j=i+1;j<l;j++)
     	{
               if(arr[j]=='G'&&arr[j+j-i]=='R')
               {
               	sum=sum+r[j+1]-1;
               }
               else if(arr[j]=='G'&&arr[j+j-i]!='R')
               {
               	sum=sum+r[j+1];
               }
               if(arr[j]=='R'&&arr[j+j-i]=='G')
               {
               	sum=sum+g[j+1]-1;
               }
               else if(arr[j]=='R'&&arr[j+j-i]!='G')
               {
               	sum=sum+g[j+1];
               }
     	}
     }   
       else if(arr[i]=='G')
     {
     	for(j=i+1;j<l;j++)
     	{
               if(arr[j]=='B'&&arr[j+j-i]=='R')
               {
               	sum=sum+r[j+1]-1;
               }
               else if(arr[j]=='B'&&arr[j+j-i]!='R')
               {
               	sum=sum+r[j+1];
               }
               if(arr[j]=='R'&&arr[j+j-i]=='B')
               {
               	sum=sum+b[j+1]-1;
               }
               else if(arr[j]=='R'&&arr[j+j-i]!='B')
               {
               	sum=sum+b[j+1];
               }
     	}
     }    
     }
     cout<<sum;
	return 0;
}

Measured memory_bytes: 3720
n = int(input())
t = list(map(int, input().split()))
m = int(input())
px = [list(map(int, input().split())) for _ in range(m)]

for p, x in px:
    ans = 0
    for i in range(n):
        if i == p - 1:
            ans += x
        else:
            ans += t[i]
    print(ans)


Measured memory_bytes: 3060
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10**6)

class union_find():
    
    def __init__(self,n):
        self.n=n
        self.root=[-1]*(n+1)
        self.rank=[0]*(n+1)

    def find_root(self,x):
        if self.root[x]<0:
            return x
        else:
            self.root[x]=self.find_root(self.root[x])
            return self.root[x]

    def unite(self,x,y):
        x=self.find_root(x)
        y=self.find_root(y)

        if x==y:
            return 
        elif self.rank[x]>self.rank[y]:
            self.root[x]+=self.root[y]
            self.root[y]=x
        else:
            self.root[y]+=self.root[x]
            self.root[x]=y

            if self.rank[x]==self.rank[y]:
                self.rank[y]+=1

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

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

n,q=map(int,input().split())
g=union_find(n)

for _ in range(q):
    t,u,v=map(int,input().split())
    if t:print(int(g.same(u,v)))
    else:g.unite(u,v)

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

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define debug(x) cerr << #x << " " << x << '\n'
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using pli = pair<ll,int>;
const int INF = 0x3f3f3f3f, N = 2e5 + 5;
const ll LINF = 1e18 + 5;
int n, m;
pii p[N];
int main()
{
 	ios::sync_with_stdio(false);
 	cin.tie(0);
 	cin >> n >> m;
 	for(int i=1; i<=n; i++) cin >> p[i].first >> p[i].second;
 	multiset <int> st;
 	sort(p+1, p+n+1);
 	int cur = 1, d = m;
 	while(cur<=n && p[cur].first+d<=m+1) st.insert(p[cur++].second);
 	ll ans = 0;
 	while(d>=1)
 	{
 		if(sz(st))
		{
			ans += *st.rbegin();
			//debug(*st.rbegin());
	 		st.erase(--st.end());
	 	}
 		d--;
 		while(cur<=n && p[cur].first+d<=m+1) st.insert(p[cur++].second);
 	}
 	cout << ans;
	return 0;
}


Measured memory_bytes: 5632
S = input().split("/")
#print(S)
if list(S[1][0]) == '0':
    S[1] = list(S[1][1])
#print(int(S[1]))
if int(S[0]) <= 2019 and int(S[1]) <= 4 and int(S[2]) <= 30:
    print("Heisei")
else:
    print("TBD")

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
//KASRA FOULADI;
int main(){
    int n, ans = 0;
    char c;
    cin >> n;
    int cnt[256] = {};
    for(int i = 0; i < n; ++i){
        cin >> c;
        cnt[c] = 1;
    }
    for(int i = 0; i < 256; ++i)
        ans += cnt[i];
    if(ans == 1)
        cout << "One" << '\n';
    else if(ans == 2)
        cout << "Two" << '\n';
    else if(ans == 3)
        cout << "Three" << '\n';
    else
        cout << "Four" << '\n';
}

Measured memory_bytes: 3568
#include <bits/stdc++.h>
#include <string.h>
#include <vector>
//s#define rep(i, n) for (int i = 0; i < (n); i++)
#define MAX 10000

using namespace std;

#define ll long long
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define rep(i,a,n) for(int i=a; i<n; i++)
#define r0 return 0
#define INF (int)1e15
#define MOD 1000000007

 int main(){

 string s,t;
 cin>>s>>t;

  int n = s.size();
  map<char,char>ms,mt;

  for(int i=0;i<n;i++){
    ms[s[i]]++;
    mt[t[i]]++;
  }

  if(ms.size() == mt.size()){

     for(int i=0;i<n;i++)
     {
        if(ms[s[i]] == mt[t[i]])
            continue;
        else {
            cout<<"No"<<endl;
            return 0;
           }
     }
       cout<<"Yes"<<endl;
       return 0;
  }

  cout<<"No"<<endl;

 return 0;
 }

Measured memory_bytes: 3920
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using datas=pair<ll,ll>;
using tdata=pair<ll,datas>;
using vec=vector<ll>;
using mat=vector<vec>;
using pvec=vector<datas>;
using pmat=vector<pvec>;
#define For(i,a,b) for(i=a;i<b;i++)
#define bFor(i,a,b) for(i=a;i>=b;i--)
#define rep(i,N) For(i,0,N)
#define rep1(i,N) For(i,1,N)
#define brep(i,N) bFor(i,N-1,0)
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define vsort(v) sort(all(v))
#define vrsort(v) sort(allr(v))
#define mod 1000000007
#define endl "\n"
#define output(v) do{bool f=0;for(auto i:v){cout<<(f?" ":"")<<i;f=1;}cout<<endl;}while(0)

long mmid(long a,long b,long c){return a<b?(b<c?b:max(a,c)):(b>c?b:min(a,c));}

ll modinv(ll a) {
  ll b=mod,u=1,v=0,t;
  while(b){
    t=a/b;
    a-=t*b; swap(a,b);
    u-=t*v; swap(u,v);
  }
  return (u+mod)%mod;
}

ll moddevide(ll a,ll b){return (a*modinv(b))%mod;}

ll modncr(ll n,ll r){
  ll i,plus=1;
  rep(i,r){
    plus=(plus*(n-i))%mod;
    plus=moddevide(plus,i+1);
  }
  return plus;
}

ll modncrlistp[200000],modncrlistm[200000];

ll modncrs(ll n,ll r){
  ll i,j;
  if(modncrlistp[n]==0){
    for(i=n;i>=0;i--){
      if(modncrlistp[i])break;
    }
    if(i<0){
      modncrlistp[0]=1;
      rep1(i,n+1){
        modncrlistp[i]=(modncrlistp[i-1]*i)%mod;
      }
    }else{
      For(j,i+1,n+1){
        modncrlistp[j]=(modncrlistp[j-1]*j)%mod;
      }
    }
  }
  if(modncrlistm[n]==0){
    for(i=n;i>=0;i--){
      if(modncrlistm[i])break;
    }
    if(i<0){
      modncrlistm[0]=1;
      rep1(i,n+1){
        modncrlistm[i]=(modncrlistm[i-1]*modinv(i))%mod;
      }
    }else{
      For(j,i+1,n+1)modncrlistm[j]=(modncrlistm[j-1]*modinv(j))%mod;
    }
  }
  return (((modncrlistp[n]*modncrlistm[r])%mod)*modncrlistm[n-r])%mod;
}

ll gcd(ll a,ll b){if(!b)return a;return (a%b==0)?b:gcd(b,a%b);}

ll countdigits(ll n){
  ll ans=0;
  while(n){n/=10;ans++;}
  return ans;
}

ll sumdigits(ll n){
  ll ans=0;
  while(n){ans+=n%10;n/=10;}
  return ans;
}

vec eratosthenes(ll N){
  ll i;
  vec ch(N+1,1),p;
  ch[0]=ch[1]=0;
  rep(i,N+1){
    if(ch[i]){
      p.push_back(i);
      for(ll j=2;i*j<=N;j++){
        ch[i*j]=0;
      }
    }
  }
  return ch;
}
ll N,K;
vec d;
mat v;

ll solve(ll now){
  ll i,ans=1,cnt=2;
  rep(i,(ll)v[now].size()){
    if(d[v[now][i]])continue;
    d[v[now][i]]=1;
    ans=ans*solve(v[now][i])%mod*(K-cnt)%mod;
    cnt++;
  }
  return ans;
}

int main(){
  ll i,a,b,ans;
  cin>>N>>K;
  ans=K;
  d.resize(N,0);
  v.resize(N);
  rep1(i,N){
    cin>>a>>b;
    a--;b--;
    v[a].push_back(b);
    v[b].push_back(a);
  }
  d[0]=1;
  rep(i,(ll)v[0].size()){
    d[v[0][i]]=1;
    ans=ans*solve(v[0][i])%mod*(K-i-1)%mod;
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 9088
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

template <typename T>
void print(T x) {
    cout << x << endl;
}

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REVFOR(i, m, n) for (int i = (n - 1); i >= (m); --i)
#define REP(i, n) FOR(i, 0, n)
#define REVREP(i, n) REVFOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    
    int N, Q;
    cin >> N >> Q;

    vector<vector<int>> G(N);
    REP(i, N - 1) {
        int a, b;
        cin >> a >> b;
        --a; --b;
        G[a].pb(b);
        G[b].pb(a);
    }

    vector<ll> x(N, 0);
    REP(i, Q) {
        int a, b;
        cin >> a >> b;
        --a;
        x[a] += b;
    }

    vector<bool> used(N, false);
    queue<pair<int, ll>> q;
    q.emplace(0, 0);
    used[0] = true;

    while(!q.empty()) {
        auto p = q.front(); q.pop();
        x[p.fi] += p.se;

        for(auto e: G[p.fi]) {
            if (used[e]) continue;
            used[e] = true;
            q.emplace(e, x[p.fi]);
        }
    }

    REP(i, N) {
        if (i > 0) cout << " ";
        cout << x[i];
    }
    cout << endl;
}


Measured memory_bytes: 19796
// ===========================================
// 20.03.11. Atcdoer DP まとめコンテスト. B - Frog 2 (dp)
// 
// 
// ===========================================

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define rep(i,n) for(int i=1; i<=n; i++)
#define rez(i,n) for(int i = 0; i<n; i++)
#define ET "\n"
#define CLR(arr) memset(&arr, 0, sizeof(arr))
#define PAIR pair<int, int>
const ll INF = 1LL << 50;
const int mini = 10e5+5;



int main(){
    
    int n; cin >> n;
    
    int a[n+1], b[n+1], c[n+1];
    rep(i,n){
        cin >> a[i] >> b[i] >> c[i];
    }
    
    ll dp[n+1][3];
    dp[1][0] = a[1];
    dp[1][1] = b[1];
    dp[1][2] = c[1];
    
    for(int i=2; i<=n; i++){
        
        dp[i][0] = max(dp[i-1][1] + a[i], dp[i-1][2] + a[i]);
        dp[i][1] = max(dp[i-1][0] + b[i], dp[i-1][2] + b[i]);
        dp[i][2] = max(dp[i-1][0] + c[i], dp[i-1][1] + c[i]);
    }
    
    cout << max({dp[n][0], dp[n][1], dp[n][2]});
    
}



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

int main()
{
    std::string hoge;
    std::cin >> hoge;
    for (int i = 0; i < 19; i++) {
        std::cout << (hoge.at(i) == ',' ? ' ' : hoge.at(i));
    }
    std::cout << std::endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define pll pair<ll,ll>
#define sll set<ll>
#define msll multiset<ll>
#define mll map<ll,ll>
#define vll vector<ll>
#define vpl vector<pll>
#define gll greater<ll>
#define gpl greater<pll>
#define spl set<pll>
#define mspl multiset<pll>
#define lb lower_bound
#define bp __builtin_popcount
#define ub upper_bound
#define prq priority_queue
#define mp make_pair
#define pb push_back
#define mem(x,y) memset(x, y, sizeof x)
#define endl "\n"
#define sz(x) (ll)x.size()
#define sqr(x) x*x
#define rapido ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
typedef int ll;
typedef long double ld;
ll mx=INT_MAX;
ll mn=INT_MIN;
ll MOD=1e9+7;
const ll maxs=1e5+10;
ll max2d=1e3+3;
// ll INF = 1e18;
const ll lg=22; 

void code_idhr_h(){
    ll X,Y; cin>>X>>Y;
    if(Y>4*X) cout<<"No";
    else if(Y<2*X) cout<<"No";
    else if((4*X-Y)%2==0) cout<<"Yes";
    else cout<<"No";
}

int main(){
    rapido;
    ll T=1; //cin>>T;
    while(T--){
        code_idhr_h();
    }
    return 0;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
const ll MOD = 1000000007;

ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}

ll lcm(ll a, ll b)
{
    ll g = gcd(a, b);
    return a / g * b;
}

ll mulMod(ll a, ll b)
{
    return (((a % MOD) * (b % MOD)) % MOD);
}

void solve(long long N, long long T, std::vector<long long> t)
{
    ll ans = T * N;
    for (int i = 1; i <= N - 1; i++)
    {
        if (t[i] - t[i - 1] < T)
        {
            ans -= (T - (t[i] - t[i - 1]));
        }
    }

    cout << ans << endl;
}

int main()
{
    long long N;
    scanf("%lld", &N);
    long long T;
    scanf("%lld", &T);
    std::vector<long long> t(N);
    for (int i = 0; i < N; i++)
    {
        scanf("%lld", &t[i]);
    }
    solve(N, T, std::move(t));
    return 0;
}


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

using ll = long long;

int main() {
  vector<int> x(5);
  for (int i = 0; i < 5; i++) cin >> x.at(i);

  for (int i = 0; i < 5; i++) {
    if (x[i] == 0) cout << i+1 << endl;
  }
  return 0;
}


Measured memory_bytes: 3624
use std::io::stdin;
use std::collections::VecDeque;

fn main() {
    let mut st = String::new();
    stdin().read_line(&mut st).unwrap();
    let n:usize = st.trim().parse().unwrap();
    let mut tree:Vec<Vec<usize>> = Vec::with_capacity(n);

    for _i in 0..n {tree.push([].to_vec())};

    for _i in 0..(n-1) {
        let mut st = String::new();
        stdin().read_line(&mut st).unwrap();
        let (a, b) = {
            let ab:Vec<usize> = st.trim().split(" ").map(|x| x.parse::<usize>().unwrap()).collect();
            (ab[0]-1, ab[1]-1)
        };
        tree[a].push(b);
        tree[b].push(a);
    };

    let mut f_queue:VecDeque<usize> = VecDeque::with_capacity(n);
    let mut s_queue:VecDeque<usize> = VecDeque::with_capacity(n);
    
    f_queue.push_back(0);
    s_queue.push_back(n-1);

    let mut visit:[i64;100002] = [-1; 100002];
    visit[0] = 0;
    visit[n-1] = 0;
    
    let mut f:i64 = 0;
    let mut f_h:bool = true;

    let mut s_h:bool = true;
    let mut s:i64 = 0;

    while s_h || f_h {
        if f_h {
            let mut g:Vec<usize> = Vec::new();
            while f_queue.len() != 0 {
                let p:usize = f_queue.pop_front().unwrap();
                for i in &tree[p] {
                    let num = *i as usize;
                    if visit[num] < 0 {
                        visit[num] = 0;
                        f += 1;
                        g.push(num);
                    };
                };
            };
            if g.len()==0{
                f_h = false;
            } else {
                f_queue = g.into_iter().collect();
            };
        };

        if s_h {
            let mut g:Vec<usize> = Vec::new();
            while s_queue.len() != 0 {
                let p:usize = s_queue.pop_front().unwrap();
                for i in &tree[p] {
                    let num = *i as usize;
                    if visit[num] < 0 {
                        visit[num] = 0;
                        s += 1;
                        g.push(num);
                    };
                };
            };
            if g.len()==0 {
                s_h = false;
            } else {
                s_queue = g.into_iter().collect();
            };
        };
    };
    if f > s {
        println!("Fennec");
    } else {
        println!("Snuke");
    };
}

Measured memory_bytes: 15356
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<ll,ll> P;

set<ll> s;
vector<ll> v;

void dfs(ll x) {
  if(x>=10000000000) return;
  s.in(x);
  ll y=x%10;
  x*=10;
  rep(i,10) {
    if(abs(y-i)<=1) dfs(x+i);
  }
}

void Main() {
  ll k;
  cin >> k;
  REP(i,1,10) dfs(i);
  tr(it,s) v.pb(*it);
  pr(v[k-1]);
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}


Measured memory_bytes: 11764
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String s = sc.nextLine();
    int result = 0;
    for (int i = 0; i < s.length(); i++) {
      if (Character.getNumericValue(s.charAt(i)) == 1) {
        result += 1;
      }
    }
    System.out.println(result);
  }
}

Measured memory_bytes: 21588
#include <stdio.h>

int main(void){
  int y = 2004, m, d, w;

  scanf("%d%d", &m, &d);
  while(m != 0){
    if(m < 3){
      y--;
      m += 12;
    }
    w = (y + y/4 - y/100 + y/400 + (13*m+8)/5 + d)%7;
    switch(w){
    case 0:
      printf("Sunday\n");
      break;
    case 1:
      printf("Monday\n");
      break;
    case 2:
      printf("Tuesday\n");
      break;
    case 3:
      printf("Wednesday\n");
      break;
    case 4:
      printf("Thursday\n");
      break;
    case 5:
      printf("Friday\n");
      break;
    case 6:
      printf("Saturday\n");
      break;
    }
    if(m > 12){
      y++;
    }
    scanf("%d%d", &m, &d);
  }
  return 0;
}

Measured memory_bytes: 584
#include <bits/stdc++.h>
using namespace std;
int n,x=0,y=0,t,a,b,tt;
int main()
{
    cin >>n;
    for (int i=0;i<n;i++)
    {
        cin >>tt>>a>>b;
        int c= (tt-t)%2;
        if ((abs(a-x)+abs(y-b))%2==c&&(abs(a-x)+abs(y-b))<=tt-t)
        {

        }
        else
        {
            cout <<"No";
            return 0;
        }
        t=tt;
        x=a;
        y=b;
    }
    cout <<"Yes";;
    return 0;
}


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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)

#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

#define ll long long
#define ld long double
#define pb(a) push_back(a)
#define eb(a) emplace_back(a)

#define xx first
#define yy second
#define mp make_pair
#define pll pair<ll,ll>
#define mll map<ll,ll>
#define vll vector<ll>
#define pdd pair<double,double>
#define ALL(v) (v).begin(), (v).end()

const ll MOD=1e9+7; ;
const ll inf=1e18;

#define MODSET(d) if ((d) >= MOD) d %= MOD;
#define MODNEGSET(d) if ((d) < 0) d = ((d % MOD) + MOD) % MOD;
#define put(x) cout<<#x<<" = "<<x<<endl;

ll power(ll a,ll n){
    ll ans=1;
    while(n){
        if(n&1)
            ans=(ans*a);
        n>>=1;
        a=(a*a);
    }
    return ans;
}


ll powerMod(ll a,ll n){
    ll ans=1;
    while(n){
        if(n&1)
            ans=(ans*a)%MOD;
        n/=2;
        a=(a*a)%MOD;
    }
    return ans;
}

ll powerMod1(ll a,ll n,ll mod){
    ll ans=1;
    while(n){
        if(n&1)
            ans=(ans*a)%mod;
        n>>=1;
        a=(a*a)%mod;
    }
    return ans;
}

ll lcm(ll a,ll b){
    return a*(b/__gcd(a,b));
}

ll sumdigit(ll n){
    ll sum=0;
    while(n){
        sum+=n%10;
        n=n/10;
    }
    return sum;
}

ll countSetBit(ll a){
    return __builtin_popcount(a);
}
ll countBit(ll a){
    ll sum=0;
    while(a){
        sum++;
        a>>=1;
    }
    return sum;
}

ll length(ll a){
    ll ans=0;
    while(a){
        ans++;
        a=a/10;
    }
    return ans;
}

bool isVowel(char c){
	if(c=='a' or c=='e' or c=='i' or c=='o' or c=='u')
		return true;
	return false;
}



int main()
{
    fast;
    ll t;
    //~ cin>>t;
    t=1;
    while(t--){
			ll n,k;
			cin>>n>>k;
			ll a[n];
			for(int i=0;i<n;i++)
				cin>>a[i];
			sort(a,a+n);
			ll ans=0;
			for(int i=0;i<n-k;i++){
				ans+=a[i];
			}
			
			cout<<ans;
    }
    return 0;
}


Measured memory_bytes: 1792
#include <iostream>
using namespace std;
int main(){
	int N,i;
 	cin>>N;	
  	for(i=1;i<10;i++){
  	if(N%i==0&&1<=N/i&&N/i<10){
    	cout<<"Yes";
    	break;
  	}	
  }
	if(i==10)cout<<"No";
  cout<<endl;
}

Measured memory_bytes: 256
x = int(input())
if 400<=x<=599:
  print(8)
elif 600<=x<=799:
  print(7)
elif 800<=x<=999:
  print(6)
elif 1000<=x<=1199:
  print(5)
elif 1200<=x<=1399:
  print(4)
elif 1400<=x<=1599:
  print(3)
elif 1600<=x<=1799:
  print(2)
elif 1800<=x<=1999:
  print(1)

Measured memory_bytes: 9136
#include <iostream>
#include <cstdlib>
#include <vector>

int main()
{
    int n(0);
    std::cin >> n;

    std::vector<int> p(n, 0), p_ref(n);
    std::vector<int> pos(2, -1);
    auto pos_it = std::begin(pos);
    for(int i=0; i < n; ++i){
        auto& v = p[i];
        std::cin >> v;
        p_ref[i] = i+1;
        
        if(v != i+1){
            if(pos_it != std::end(pos)){
                *pos_it = i;
                ++pos_it;
            }
        }
    }
    
    bool b_sort = false;
    if(p != p_ref){
        std::swap(p[pos[0]], p[pos[1]]);
    }
    if(p == p_ref){
        b_sort = true;
    }
    
    if(b_sort){
        std::cout << "YES" << std::endl;
    }else{
        std::cout << "NO" << std::endl;
    }
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
int K;
cin >> K;
string S;
cin >> S;
if(S.size()<=K){
  cout << S << endl;
  return 0;
}
else{
  for(int i = 0; i < K; i++){
    cout << S.at(i) ;
  }
  cout << "..." << endl;
}
}

Measured memory_bytes: 3628
def getN():
    return int(input())

def getIntList():
    return list(map(int, input().split()))


def main():

    N,M= map(int,input().split())

    H = getIntList()

    # input AB
    ABlist = []
    for i in range(M):
        AB = list(map(int,input().split()))
        ABlist.append(AB)
    
    
    wlist = [1] * N
    for i in ABlist:
        if H[i[0]-1] < H[i[1]-1]:
            wlist[i[0]-1] = 0
        elif H[i[0]-1] == H[i[1]-1]:
            wlist[i[0]-1] = 0
            wlist[i[1]-1] = 0
        else:
            wlist[i[1]-1] = 0

    #print(wlist)
    print(wlist.count(1))

    return

if __name__ == "__main__":
    main()

Measured memory_bytes: 31892
n = int(input())

a_li = list(map(int, input().split()))

ans = 0
li = [0]*(n+1)

for i,a in enumerate(a_li):
  ans += (i+1)*a

for i,a in enumerate(a_li[::-1]):
  if i >= 1:
    li[i] = li[i-1]+a
  else:
    li[i] = a

li = li[::-1]

flag = True
ne = 0.5
for i in range(n+1):
  if li[i]  > 2*ne:
    ans -= li[i] -int(2*ne)

  
  ne = min(li[i] - a_li[i],int(2*ne)-a_li[i])

  if (i == n and ne != 0) or (i != n and ne <= 0):
    flag = False

  
if flag:
  print(ans)
else:
  print(-1)

Measured memory_bytes: 20136
n = int(input())
C = input()
idx_l = 0
idx_r = len(C) - 1
cnt = 0
while True:
    if idx_l >= idx_r:
        break
    if C[idx_l] == 'R':
        idx_l += 1
        continue
    if C[idx_r] == 'W':
        idx_r -= 1
        continue
    cnt += 1
    idx_l += 1
    idx_r -= 1
print(cnt)


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

#define ALL(a) (a).begin(), (a).end()
#define llong long long

using namespace std;

signed main(){
	int n,m;
	cin >> n >> m;
	int mid = (n&1) ? (n+1)/2 : n/2+1;
	vector<int> a;
	for(int i = 0; i < mid; i++){
		a.push_back(0);
	}
	for(int i = 0; i < n-mid; i++){
		a.push_back(m);
	}
	for(size_t i = 0; i < a.size(); i++){
		cout << a[i];
		if(i != a.size() -1)cout << " ";
	}
	cout << endl;

	return 0;
}




Measured memory_bytes: 3152
// 为啥这玩意在我本地能跑 在你的测评机上就不行？ 
#include<stdio.h>
#include<malloc.h>
#include<string.h> 
int cnt = 0;
char s1[] = "insert";
char s2[] = "delete";
char s3[] = "deleteFirst";
char s4[] = "deleteLast";
typedef struct node
{
	int data;
	struct node * pre, *next;	
}LinkNode;

void init(LinkNode * &L)
{
	L  = (LinkNode *)malloc(sizeof(LinkNode));
	L->pre = L;
	L->next = L;
}

void insert(LinkNode * L, int x)
{
	LinkNode * t = (LinkNode *)malloc(sizeof(LinkNode));
	t->data = x;
	t->next = L->next;
	t->pre = L;
	L->next->pre = t;
	L->next = t;
}

LinkNode * search(LinkNode * L, int x)
{
	LinkNode * p;
	p = L->next;
	while (p != L && p->data != x)
	{
		p = p->next;
	}
	return p;
}

void destroyNode(LinkNode * L, LinkNode * n)
{
	if (L == n)
		return;
	n->pre->next = n->next;
	n->next->pre = n->pre;
	free(n);
}

void destroyFirst(LinkNode * L)
{
	destroyNode(L, L->next);
}

void destroyLast(LinkNode * L)
{
	destroyNode(L, L->pre);
}

void display(LinkNode * L)
{
	LinkNode * p = L->next;
	while (p != L)
	{
		if(cnt) printf(" ");
		printf("%d", p->data);
		p = p->next;
		cnt++;
	}
	printf("\n");
}


int main()
{
	LinkNode * L;
	init(L);
	int T;
	char s[10];
	scanf("%d", &T);
	while (T--)
	{
		scanf("%s", s);
		if (!strcmp(s, s1))
		{
			int x;
			scanf("%d", &x);
			insert(L, x);
		}
		else if (!strcmp(s, s2))
		{
			int x;
			scanf("%d", &x);
			LinkNode * t = search(L, x);
			destroyNode(L, t);
		}
		else if (!strcmp(s, s3))
		{
			destroyFirst(L);
		}
		else if(!strcmp(s, s4))
		{
			destroyLast(L);
		}
	}
	
	display(L);
	
	LinkNode * p = L->next;
	while (p != L)
	{
		LinkNode * t;
		t = p->next;
		free(p);
		p = t;
	}
	free(L);
	return 0;
 } 


Measured memory_bytes: 33820
#include <bits/stdc++.h>
using namespace std;
#define N 100009
#define INF 1000000009
#define MOD 1000000007
typedef long long int ll;
#define sd(x) scanf("%d",&x)
#define sd2(x,y) scanf("%d%d",&x,&y)
#define sd3(x,y,z) scanf("%lld%lld%lld",&x,&y,&z)
#define pf(x) printf("%d",x);
#define pf2(x,y) printf("%d %d\n",x,y);
#define pf3(x,y,z) printf("%d %d %d\n",x,y,z);
#define fi first
#define se second
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define tr(x) cout<<x<< endl;
#define tr2(x,y) cout<<x<<" "<<y<<" " << endl;
#define tr3(x,y,z) cout<<x<<" "<<y<<" "<<z<<endl;
#define tr4(x,y,z,a) cout<<x<<" "<<y<<" "<<z<<  " " << a << " " << endl;
int a[N],b[N],t;
vector<int> v[N],temp;
bool visit1[N],visit2[N];
void dfs1(int i){
    visit1[i]=1;
    for(auto j:v[i]){
        if(!visit1[j])dfs1(j);
    }
    // tr(i);
    temp.pb(i);
}
int ans=0;
void dfs2(int i){
    visit2[i]=1;
    for(auto j:v[i]){
        if(!visit2[j])dfs2(j);
        a[i] = max(a[i],a[j]+1);
    }
    ans=max(ans,a[i]);
}
int main(){
    int i,j,n,m,t,k,x,y;
    sd2(n,m);
    for(i=0;i<m; i++){
        sd2(x,y);
        v[x].push_back(y);
    }
    for(i=1; i<=n; i++){
        if(!visit1[i]){
            dfs1(i);
        }
    }
    reverse(temp.begin(),temp.end());
    for(auto i:temp){
            if(!visit2[i]){
                dfs2(i);
            }

    }
    tr(ans);
}

Measured memory_bytes: 11512
#include<bits/stdc++.h>
#include<boost/variant.hpp>
using namespace std;
typedef long long ll;
typedef vector<boost::variant<bool, ll, int, string, double, char*, const char*>> any;
template<typename T> inline void pr(const vector<T> &xs){
	for(int i=0; i<xs.size()-1; i++) cout<<xs[i]<<" ";
	(xs.empty()?cout:(cout<<xs[xs.size()-1]))<<endl;
}
#ifdef DEBUG
#define debug(...) pr(any{__VA_ARGS__})
#define debugv(x) pr((x))
#else
#define debug(...)
#define debugv(x)
#endif

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

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

	int i=1;
	while(i<N&&cnt[i]==0) i++;
	if(i==1){
		if(cnt[i]==1&&cnt[i+1]==N-1){
			cout << "Possible" << endl;
		} else if(cnt[i]==2&&N==2){
			cout << "Possible" << endl;
		} else {
			cout << "Impossible" << endl;
		}
		return 0;
	}

	if(cnt[i]>2){
		cout << "Impossible" << endl;
		return 0;
	}

	if(i==N-1 || (cnt[i]==1&&N<=2*i) || (cnt[i]==2&&N<=2*i-1)) {
		cout << "Impossible" << endl;
		return 0;
	}

	for(int j=i+1; j<=(cnt[i]==1?2*i:2*i-1); j++){
		if(cnt[j]<2) {
			cout << "Impossible" << endl;
			return 0;
		}
	}
	for(int j=(cnt[i]==1?2*i+1:2*i); i<N; i++){
		if(cnt[j]>0) {
			cout << "Impossible" << endl;
			return 0;
		}
	}

	cout << "Possible" << endl;

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	ll n;
	cin >> n;
	ll a[n];
	ll sum = 0;
	for(ll i=0;i<n;i++)
	{
		cin >> a[i];
	}

	for(ll i=0;i<n;i++)
	{
		for(ll j=i+1;j<n;j++)
		{
			sum += (a[i]*a[j]);
		}
	}
	cout << sum;
	return 0;
}

Measured memory_bytes: 256
// dfmt off
T lread(T=long)(){return readln.chomp.to!T;}T[] lreads(T=long)(long n){return iota(n).map!((_)=>lread!T).array;}
T[] aryread(T=long)(){return readln.split.to!(T[]);}void arywrite(T)(T a){a.map!text.join(' ').writeln;}
void scan(L...)(ref L A){auto l=readln.split;foreach(i,T;L){A[i]=l[i].to!T;}}alias sread=()=>readln.chomp();
void dprint(L...)(lazy L A){debug{auto l=new string[](L.length);static foreach(i,a;A)l[i]=a.text;arywrite(l);}}
static immutable MOD=10^^9+7;alias PQueue(T,alias l="b<a")=BinaryHeap!(Array!T,l);import std;
// dfmt on

void main()
{
    long N = lread();
    writeln(0);
    stdout.flush();
    long ok = 0;
    long ng = N;
    auto S = sread();
    if (S == "Vacant")
        return;
    while (true)
    {
        long m = (ok + ng) / 2;
        writeln(m);
        stdout.flush();
        auto s = sread();
        if (s == "Vacant")
            return;
        if ((S != s) == (m & 1))
        {
            ok = m;
        }
        else
        {
            ng = m;
        }
    }
}


Measured memory_bytes: 3844
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <math.h>
#include <stack>
#include <set>
#include <deque>

using namespace std;
typedef long long ll;
ll mod = 1e9+7;
#define rep(i,n) for(int i = 0; i < (n); ++i)

int main(){
    ll n, k;
    cin >> n >> k;
    ll ans = 0;
    for ( int i = 1; i <= n; ++i ) {
        ll num = 0;
        if ( i % k == 0 ) {
            num = n / k;
        }
        if ( k % 2LL == 0 && i % k == k / 2LL ) {
            num += n / k;
            if ( n - n / k * k >= k / 2LL ) {
                ++num;
            }
        }
        ans += num * num;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>

inline long long GetMulti(int val)
{
  return (long long)val * val * val * val * val;
}

int main()
{
  unsigned int X;
  std::cin >> X;
  while(X <= 0)
  {
    
  }
  
  for(int A = -200; ; ++A)
  {
    const long long mulA = GetMulti(A);
    const long long result = mulA - X;
    
    if(result < 0)
    {
      long long mulB = 0;
      for(int B = 0; mulB >= result; --B)
      {
        mulB = GetMulti(B);
        if(result == mulB)
        {
          std::cout << A << " " << B << std::endl;
          return 0;
        }
      }
    }
    else
    {
      long long mulB = 0; 
      for(int B = 0; mulB <= result; ++B)
      {
        long long mulB = GetMulti(B);
        if(result == mulB)
        {
          std::cout << A << " " << B << std::endl;
          return 0;
        }
      }
    }
  }
  return 0;
}


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

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

ll A, B, C, D;

int main(){
    cin >> A >> B >> C >> D;

    ll num = B - A + 1;

    ll mulC = B / C - (A - 1) / C;
    ll mulD = B / D - (A - 1) / D;
    ll CD = C * D / __gcd(C, D);
    ll mulCD = B / CD - (A - 1) / CD;

    ll ans = num - (mulC + mulD - mulCD);

    cout << ans << endl;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
//#include <tchar.h>
//#include <intrin.h>

#define F first
#define S second
#define LL long long
#define MOD 1000000007
#define INF 2000000000
#define LINF 1000000000000000000

using namespace std;

const int N = 2e5 + 10;

LL a[N];

bool cmp(LL a, LL b) {

	return abs(a) < abs(b);
}

LL mult(LL a, LL b) {

	return (a*b% MOD + MOD) % MOD;
}

int main()
{
	int n, cnt = 0, k;
	cin >> n >> k;

	LL ans = 1;

	for (int i = 1;i <= n;i++)
		cin >> a[i], cnt += a[i] < 0;

	sort(a + 1, a + n + 1);

	bool q = 0;
	for (int i = 0;i <= min(k, cnt) / 2;i++)
		q |= i * 2 + n - cnt >= k;

	if (!q) {

		sort(a + 1, a + n + 1, cmp);
		for (int i = 1;i <= k;i++)
			ans = mult(ans, a[i]);
	}

	else {

		int l = 1, r = n;
		if (k & 1)r--, k--, ans = a[n];

		while (k) {

			if (l >= cnt || k < 2)ans = mult(ans, max(a[r],a[l])), r--, k--;

			else {
				if (a[l] * a[l + 1]>a[r] * a[r - 1])ans = mult(ans, mult(a[l], a[l + 1])), l += 2, k -= 2;
				else ans = mult(ans, mult(a[r], a[r - 1])), r -= 2, k -= 2;
			}
		}
	}

	cout << ans << endl;
	cin >> n;
}


Measured memory_bytes: 4764
# データ読み込み

import sys
from collections import deque

def input_data(d=""):
  t = sys.stdin.read()
  if t:
    return t
  else:
    if d[0] == "\n":
      d = d[1:]
    if d[-1] == "\n":
      d = d[:-1]    
    return d

A, B  = map(int,input_data().split())

if B == 100:
  B = 101

out = 100 ** A * B

print(out)

Measured memory_bytes: 3316
import numpy as np
from scipy.special import comb
n,d=map(int,input().split())
x=[]
total=0
for i in range(n):
    x.append(list(map(int,input().split())))
for i in range(n):
    for j in range(n):
        if i!=j:
            a=np.array(x[i])
            b=np.array(x[j])
            u=b-a
            if np.linalg.norm(u)==int(np.linalg.norm(u)):
                total+=1
print(int(total/2))

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

int main(){
	int N,K,X,Y;
	scanf("%d%d%d%d", &N,&K,&X,&Y);
    int ans=0;
	for(int i=1;i<=N;i++){
		if(i<=K)ans+=X;
		if(i>K)ans+=Y;
	}
	printf("%d\n",ans);
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <list>
#include <cstdio>
#define INF 1LL<<60
#define MOD 1000000007ll
#define EPS 1e-10
#define REP(i,m) for(long long i=0; i<m; i++)
#define FOR(i,n,m) for(long long i=n; i<m; i++)
#define pb push_back
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
typedef long double ld;

int main(){
  int n, z, w;
  cin >> n >> z >> w;
  int a[n];
  REP(i, n) cin >> a[i];
  if(n == 1) cout << abs(a[0] - w) << endl;
  else cout << max(abs(a[n-1]-w), abs(a[n-1] - a[n-2])) << endl;
	return 0;
}


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

int main() 
{
	int n;
    cin >> n;
    bool ok = false;
    for(int i=1;i<=9;i++) {
        int comp = n / i;
        if(comp * i == n && comp >= 1 && comp <= 9) {
            ok = true;
            break;
        }
    }
    if(ok) cout << "Yes\n";
    else cout << "No\n";
    return 0;
}


Measured memory_bytes: 256