akhauriyash/Code-Regression huggingface dataset:
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

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

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

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

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())
        
a = input().split()
N = int(a[0])
M = int(a[1])
tm = int(0)
tmp = int(0)


k = [input().split() for i in range(M)]

uf = UnionFind(N+1)

for i in range(M):
    tm = int(k[i][0])
    tmp = int(k[i][1])
    uf.union(tm, tmp)
    tm = 0
    tmp = 0

print(int(uf.group_count()) - 2)


Measured memory_bytes: 40584
#include <iostream>
#include <queue>
#include <algorithm>
#include <vector>
#include <climits>
#define int long long
using namespace std;
typedef pair <int,int> P;
#define to first
#define co second
#define fi first
#define se second
const int INF=INT_MAX;
const int MAX_V=100000;
vector <P> G[MAX_V];
int v,d[MAX_V];

void dijk(int s){
  priority_queue <P,vector<P>,greater<P> > que;
  fill(d,d+v,INF);
  d[s]=0;
  que.push(P(0,s));
  for(;!que.empty();){
    P p=que.top(); que.pop();
    int v=p.se;
    if (d[v]<p.fi) continue;
    for(int i=0;i<(int)G[v].size();i++){
      P e=G[v][i];
      if(d[e.to]>d[v]+e.co){
        d[e.to]=d[v]+e.co;
        que.push(P(d[e.to],e.to));
      }
    }
  }
}
signed main(){
  cin>>v;
  for(int i=0,u,k;i<v&&cin>>u>>k;i++) for(int j=0,a,b;j<k&&cin>>a>>b;j++) G[u].push_back(P(a,b));
  dijk(0);
  for(int i=0;i<v;i++) cout<<i<<" "<<d[i]<<endl;
  return 0;

}


Measured memory_bytes: 14176
#include <iostream>
#include <cstdio>
#define ll long long
using namespace std;

inline char gc(){
	static char buf[100000],*p1=buf,*p2=buf;
	return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
#define gc getchar
inline ll read(){
	ll x=0;char ch=gc();bool positive=1;
	for(;!isdigit(ch);ch=gc())if(ch=='-')positive=0;
	for(;isdigit(ch);ch=gc())x=x*10+ch-'0';
	return positive?x:-x;
}

inline void write(ll x){
	if(x<0)x=-x,putchar('-');
	if(x>9)write(x/10);putchar(x%10+'0');
}

inline void writeln(ll x){
	write(x);puts("");
}
#define Max 200005
ll n,ans,now,a[Max];

int main(){
	n=read();
	for(ll i=1;i<=n;i++)a[i]=read();
	for(ll i=n;i>=1;i--){
		now--;
		if(a[i]<now){
			puts("-1");
			return 0;
		}
		if(now<a[i]){
			ans+=a[i];
			now=a[i];
		}
	}
	if(now!=0){
		puts("-1");
		return 0;
	}
	write(ans);
	return 0;
}

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

int main(){
	string input;
	bool isFirst = true;
	while(cin >> input){
		if(!isFirst) cout << " ";
		if(input.find("apple", 0) != string::npos){
			for(int i=0; i < input.find("apple", 0); i++){
				cout << input[i];
			}
			cout << "peach";
			for(int i=input.find("apple", 0)+5; i < input.size(); i++){
				cout << input[i];
			}
		}
		else if(input.find("peach", 0) != string::npos){
			for(int i=0; i < input.find("peach", 0); i++){
				cout << input[i];
			}
			cout << "apple";
			for(int i=input.find("peach", 0)+5; i < input.size(); i++){
				cout << input[i];
			}
		}
		else cout << input;
		isFirst = false;
	}
	cout << endl;
}

Measured memory_bytes: 1176
#include <bits/stdc++.h>
#define R register
typedef unsigned long long ull;

const int MN = 2e5 + 5;

ull s[MN], x, ans = 0xffffffffffffffffull;

int n;

int main() {
	std::ios::sync_with_stdio(false);

	std::cin >> n >> x;
	for (R int i = 1, v; i <= n; ++i) {
		std::cin >> v;
		s[i] = s[i - 1] + v;
	}

	for (R int i = 1; ; ++i) {
		if ((i << 1) >= n) {
			ans = std::min(ans, x * i + 5 * s[n]);
			break;
		}
		R ull res = x * i, k = 7;
		res += 5 * (s[n] - s[n - (i << 1)]);
		for (R int j = n - (i << 1); ; k += 2, j -= i) {
			if (j <= i) {
				res += k * s[j];
				break;
			}
			res += (s[j] - s[j - i]) * k;
		}
		ans = std::min(ans, res);
	}
	
	std::cout << ans + x * n;

	return 0;
}

Measured memory_bytes: 1792
/*
 * Author: .-O_O-.
 */
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include<bits/stdc++.h>
using namespace __gnu_pbds;
using namespace std;
#define ll long long
#define pb push_back
#define vi vector<int>
#define rep0(a,b) for(int a=0;a<b;a++)
#define rep1(a,b) for(int a=1;a<=b;a++)
#define repp(a,b,c) for(int a=b;a<c;a++)
#define in insert
#define len length()
#define si size()
#define lb lower_bound
#define ub upper_bound
#define beg begin()
#define en end()
#define f first
#define s second
#define pr(a) cout<<a
#define pr2(a,b) cout<<a<<" "<<b<<"\n"
#define nx cout<<"\n"
#define int long long
// void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
                                                     
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]"<<endl;}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define deb(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define deb(x...)
#endif
const ll mod = 1000000007;
const ll N = 105;
const ll mm = 1e+18;
void solve()
{
    int n;
    cin>>n;
    cout<<n*800-(n/15)*200;
}
signed main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t=1;
    //cin>>t;
    rep1(_i,t){
        //cout<<"Case #"<<_i<<": ";
        solve();
        //nx;
    }
    return 0;
}

Measured memory_bytes: 3608
#include <iostream> // cout, endl, cin
#include <cmath> //sqrt pow
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
 
#define rep(i,n) for(int i = 0; i < n; i++)
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define mod 1000000007
using ll = long long;
using namespace std;
int main(){
  int n,m,x,y;
  cin >> n >> m >> x >> y;
  int mx = x;
  int mn = y;
  rep(i, n){
    int a;
    cin >> a;
    mx = mx < a ? a : mx;
  }
  rep(i, m){
    int a;
    cin >> a;
    mn = mn > a ? a : mn;
  }
  if(mx < mn){
    cout << "No War" << endl;
  }else cout << "War" << endl;
}

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

#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define ll long long

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

    vector<vector<int>> s(m);
    for(int i=0;i<m;i++){
        int k; cin>>k;
        for(int j=0;j<k;j++){
            int a; cin>>a;
            a--;
            s[i].push_back(a);
        }
    }

    vector<int> p(m);
    for(int i=0;i<m;i++) cin>>p[i];


    int ans=0;
    
    for(int i=0;i<1<<n;++i){
        bool ok=true;
        //どのスイッチがonか
        for(int j=0;j<m;++j){
            int x=0; //onの数をカウント
            for(auto on:s[j]){
                if(i&1<<on){ //マスクビット
                    x++;
                    //iのjが1のとき実行}
                }
            }
            if(x%2!=p[j]){
                ok=false;
            }
        }
        if(ok) ++ans;
    }

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

Measured memory_bytes: 256
# https://atcoder.jp/contests/agc022/tasks/agc022_a

from string import ascii_lowercase

s = input()
rems = [c for c in ascii_lowercase if c not in s]

if len(rems) > 0:
    print("{}{}".format(s, rems[0]))
    exit()
else:
    # 長さ26文字
    # S = [p1, ..., p26]

    # 右から見て照準である最長な文字列を探す
    j = len(s) - 1
    while s[j] < s[j - 1]:
        j -= 1

    if j == 0:
        print(-1)
    else:
        sj = s[:j - 1]
        pjm1 = s[j - 1]
        nc = min([c for c in s[j:] if c > pjm1])
        print(sj + nc)

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

using namespace std;
using lli = int_fast64_t;
using ulli = uint_fast64_t;
#define debug(x) cerr << #x << " : " << x << endl
#define debugv(x) cerr << #x << " : {";for(auto value_of_x:x){ cerr << value_of_x << ", ";}cerr << endl
#define debugst(x) auto xt = x;cerr << #x << " : {";for(int i=0;i<x.size();i++){ cerr << xt.top() << ", ";xt.pop();}cerr << endl
#define debugvp(x) cerr << #x << " : {";for(auto value_of_x:x){ cerr << value_of_x.first << " : " << value_of_x.second << ", ";}cerr << endl
#define HYPP(x) hypot(x.first,x.second)

const lli MOD = 1000000007;
const lli LIMIT = 1000000000000000000 * 5;
const int tenfive = 100000;



int main() {
	int N;
	cin >> N;
	for (int i = 1; i < 10; i++) {
		for (int j = 1; j < 10; j++) {
			if (i * j == N) {
				cout << "Yes" << endl;
				return 0;
			}
		}
	}
	cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <map>
#include <set>
#include <stack>
#include <queue>
 
using namespace std;
 
#define pb(n)	push_back(n)
#define mp(n,m) make_pair(n,m)
#define fi 	first
#define se 	second
#define all(r) (r).begin(),(r).end()
 
#define REP(i,s,e)	for(ll i=(s); i<(e); i++)
#define rep(i,n)	REP(i,0,n)
#define REPE(i,s,e)	for(ll i=s; i>e; i--)
#define repe(i,n)	REPE(i,n,-1)
 
 
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
 
typedef vector<vi> vvi;
 
const int IMAX=((1<<30)-1)*2+1;
const int INF=100000000;
const double EPS=1e-10;
//int mod=1000000007






int main(){
	int n;
	cin >> n;
	int a,b,c,d;
	vector<pii> v(n,pii(0,0));
	rep(i,n) v[i].se = i;
	
	rep(i,n*(n-1)/2){
		cin>>a>>b>>c>>d;
		a--; b--;
		if(c > d) v[a].fi -= 3;
		else if ( c < d) v[b].fi -= 3;
		else{
			v[a].fi--; v[b].fi--;
		}
	}
	
	sort(all(v));
	vi ans(n,0);
	int tmp = 0;
	for(int i = 0; i < n; i++){
		ans[v[i].se] = i;
		if(i != 0 && tmp == v[i].fi) ans[v[i].se] = ans[v[i-1].se];
		tmp = v[i].fi;
	}
	for(int i = 0; i < n; i++){
		cout<<ans[i]+1<<endl;
	}
}

Measured memory_bytes: 1200
#include <bits/stdc++.h>
using namespace std;
int n,k,sum=0,a[200004],d[200004];
int main(){
	cin>>n>>k; 
	for (int i=1;i<=n;i++) cin>>a[i],d[i]=d[i-1]+a[i];
	for (int i=k;i<=n;i++) sum=max(sum,d[i]-d[i-k]);
	printf("%.12lf",(double)(sum+k)/2.0);
}

Measured memory_bytes: 1792
#include <bits/stdc++.h> //library
#define rep(i, n) for(int i = 0; i < (int)(n); i++) //for-loop (from 0)
#define reps(i,n) for(int i = 1; i <= (int)(n); i++) //for-loop (from 1)
#define all(x) (x).begin(),(x).end() //start-to-end iteration, mainly in upper_bound, lower_bound
#define SZ(x) ((int)(x).size()) //unsigned to signed

using namespace std;
using ll = long long; //long long
ll M = 1000000000 + 7;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; } //compare a,b and replace by greater
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; } //compare a,b and replace by smaller
ll qp(int a, ll b) { int ans = 1; do { if (b & 1)ans = 1ll * ans*a; a = 1ll * a*a; } while (b >>= 1); return ans; } //power
ll qp(int a, ll b, ll Mod = M) { int ans = 1; do { if (b & 1)ans = 1ll * ans*a%Mod; a = 1ll * a*a%Mod; } while (b >>= 1); return ans; } //power(mod)
int gcd(int a, int b) { return b ? gcd(b, a%b) : a; } //gcd
int dx[4] = { 1,0,-1,0 }; //path
int dy[4] = { 0,1,0,-1 }; //path
ll RS(ll N, ll P, ll Mod = M) { if (P == 0)return 1; else if (P % 2 == 0) { ll sq = RS(N, P / 2, Mod); return sq*sq%Mod; } else { return N*RS(N, P - 1, Mod) % Mod; } } //power(mod)(repeat-square,fast)
ll nPr(ll n, ll r, ll Mod = M) { ll ans = 1; rep(i, r) { ans = ans * (n - i) % Mod; } return ans; } //permutation
ll nCr(ll n, ll r, ll Mod = M) { ll bunbo = 1; ll bunshi = 1; rep(i, r) { bunbo = bunbo * (i + 1) % Mod; bunshi = bunshi * (n - i) % Mod; } return bunshi * RS(bunbo, Mod - 2, Mod) % Mod; } //combination

int main(void) {
  ll n,a,b; cin >> n >> a >> b;
  ll ans = RS(2,n,M);
  
  //nCa
  ll bunbo=1; ll bunshi=1;
  rep(i,a){
    bunbo = bunbo * (i+1) % M;
    bunshi = bunshi * (n-i) % M;
  }
  ll nCa = bunshi * RS(bunbo,M-2,M) % M;
  //nCb
  bunbo=1; bunshi=1;
  rep(i,b){
    bunbo = bunbo * (i+1) % M;
    bunshi = bunshi * (n-i) % M;
  }
  ll nCb = bunshi * RS(bunbo,M-2,M) % M;
  
  ans -= (nCa+nCb+1)%M;
  if (ans < 0) ans += M;
  cout << ans << "\n";
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int  X ;
    int N ;
    int min = 101;
    int ans=101;
    cin >> X >> N;
    int p[N];
    if(N==0){
        cout << X <<endl;
    }
    else{
        for(int i =0;i<N;i++){
            cin >> p[i] ;
        }
        int pre;
        for(int j=-10 ; j<=110;j++){
            pre = j;
            for(int k = 0;k<N;k++){
                if(p[k] == j){
                    pre = 101;
                }
            }
            if(min > abs(pre-X)){
                min = abs(pre-X);
                ans = pre;
            }
            
        }
        cout << ans << endl;
    }
}


Measured memory_bytes: 3600
import collections
N = int(input())
ans = 0

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

num = 0
for i in so :
  num =c[i] 
  for j in range(1, num+1):
    if num >= j :
      num -= j
      ans += 1
    else :
      break
      
print(ans)

Measured memory_bytes: 9452
#include<stdio.h>

int main(void){


int W,H,x,y,r;;


scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);


if(W>=x+r&&x-r>=0&&H>=y+r&&y-r>=0){


printf("Yes\n");


}


else{


printf("No\n");


}


return 0;


}

Measured memory_bytes: 584
#include <iostream>
#include <cstdio>
using namespace std;
long long fact(long long n){
	long long m;
	if(n==0) return 1;
	m = fact(n-1);
	return n*m;
}
int main(){
	long long n;
	cin >> n;
	cout << fact(n) << endl;
}

Measured memory_bytes: 1156
#include <bits/stdc++.h>
#define int long long 
using namespace std;

const int N = 2e5 + 7;

vector <int> nxt[N];

int32_t main() {
	ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int n, cur = 0, ans = 0; cin >> n;
	for(int i = 1; i < n; i++) {
		int l, r; cin >> l >> r;
		if(l > r) {
			swap(l, r);
		}
		nxt[l].push_back(r);
		cur += (n - r + 1);
	}

	for(int i = 1; i <= n; i++) {
		int x = n - i + 1;
		ans += x * (x + 1) / 2 - cur;
		for(auto j: nxt[i]) {
			cur -= n - j + 1;
		}
	}

	cout << ans << endl;
}

Measured memory_bytes: 14524
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	a, _ := strconv.Atoi(next())
	return a
}

func max(a, b int) int {
	return int(math.Max(float64(a), float64(b)))
}

func min(a, b int) int {
	return int(math.Min(float64(a), float64(b)))
}

func abs(a, b int) int {
	return int(math.Abs(float64(a) - float64(b)))
}

func main() {
	sc.Split(bufio.ScanWords)
	a, b := next(), next()

	if a[0] < b[0] {
		bi, _ := strconv.Atoi(b)
		for i := 0; i < bi; i++ {
			fmt.Print(a)
		}
	} else {
		ai, _ := strconv.Atoi(a)
		for i := 0; i < ai; i++ {
			fmt.Print(b)
		}
	}
}


Measured memory_bytes: 640
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        Scanner in = new Scanner(System.in);
        String[] params = in.nextLine().split(" " );
        long a = Long.parseLong( params[0] );
        long b = Long.parseLong( params[1] );
        long k = Long.parseLong( params[2] );
        
        if( a == 0 && b == 0 ){
            System.out.println( "0 0" );   
        }
        else if( a > k ){
            System.out.println( "" + ( a - k ) + " " + b );
        }
        else if( a == k ){
            System.out.println( "" + 0 + " " + b );
        }
        else {
            System.out.println( "0 " + ( ( b - ( k - a ) ) > 0 ? ( b - ( k - a ) ) : 0 ) );
        }

    }

}

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

int n, k, h[100001], f[100001];
int abs(int a) {return (a>0)?a:(-a);}
int way(int a)
{
    int mins = 2147483647, minp = 0;
    for (int i = ((a-k > 0) ? (a-k) : 1);  i < a; i++)
    {
        if (f[i] + abs(h[a] - h[i]) < mins)
        {
            mins = f[i] + abs(h[a] - h[i]);
            minp = i;
        }
    }
    return minp;
}
int main()
{
    //freopen("FROG2.inp", "r", stdin);
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> k;
    for (int i = 1; i <= n; i++)
    {
        cin >> h[i];
    }
    f[1] = 0, f[2] = abs(h[2] - h[1]);
    for (int i = 3; i <= n; i++)
    {
        f[i] = f[way(i)] + abs(h[i] - h[way(i)]);
    }
    cout << f[n];
    return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
#include<math.h>
#include<cstring>
#include<vector>

using namespace std;

#define long long long
#define ft(i, a, b) for (long i = (long)a ; i <= (long)b ; i++)
#define fd(i, a, b) for (long i = (long)a ; i >= (long)b ; i--)
#define X first
#define Y second

const int mxN = 1e5 + 5;
const long oo = 1e15;
const long MOD = 1e9 + 7;
const int base = 311;

long x , a , b;
pair < bool , int > cnt[mxN];

long check(long x) {
    long t = pow(x,(double)1/5);   
    if (t * t * t * t * t == x) return t;
    return -1;
}

void Solve() {
    //ft(i , 0 , 63) cnt[i * i * i * i * i].X = true , cnt[i * i * i * i * i].Y = i;
    ft(i , -150 , 150) {
        a = i * i * i * i * i;
        if (a == x) {
            cout << i << ' ' << 0;
            return;
        }
        if (a > x) {
            if (check(a - x) != -1) {
                cout << i << " " << check(a - x);
                return;
            }
        }
        if (a < x) {
            if (check(x - a) != -1) {
                cout << i << " -" << check(x - a);
                return;
            }
        }
    }
}

void FastInput() {
    ios_base::sync_with_stdio(NULL);
    cin.tie(NULL);
    cout.tie(NULL);
    //freopen(".inp", "r", stdin);
    //freopen(".out", "w", stdout);
}

void Input() {
    cin >> x;
}

int main() {
    FastInput();
    Input();
    Solve();
}

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

int main(){
    int n, m;
    cin >> n >> m;
    rep(i, m){
        int a;
        cin >> a;
        n -= a;
    }
    if(n < 0) cout << "-1" << endl;
    else cout << n << endl;
}

Measured memory_bytes: 3596
#include<stdio.h>
#include<stdlib.h>
#define N 1000000

int partiton(int *,int,int);

main(){

  int n,r,p,i,q;
  int A[N];

  scanf("%d",&n);
  for( i=0 ; i<n ; i++){
    scanf("%d",&A[i]);
  }

  r=n-1;
  p=0;

  if(p < r){
   q = partiton(A, p, r);
  }
  for( i=0 ; i<n ; i++){
    if(i == q) printf("[%d]",A[i]);
    else printf("%d",A[i]);
    if( i!= n-1)printf(" ");
  }
  printf("\n");

  return 0;
}


int partiton(int *A,int p,int r){

  int x,i,j,n,m;

    x = A[r];
    i = p-1;
    for( j=p ; j<=r-1; j++){
      if(A[j] <= x){
	i = i+1;
	n=A[i];
	A[i]=A[j];
	A[j]=n;
	
      }
    }
    n=A[i+1];
    A[i+1]=A[r];
    A[r]=n;
   
    return i+1;
}

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

// Begin {{{
using namespace std;

#ifndef DEBUG
#define dump(...)
#endif

template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }

template <class T>
inline vector<T> make_v(const T &initvalue, size_t sz) {
    return vector<T>(sz, initvalue);
}

template <class T, class... Args>
inline auto make_v(const T &initvalue, size_t sz, Args... args) {
    return vector<decltype(make_v<T>(initvalue, args...))>(sz, make_v<T>(initvalue, args...));
}

constexpr int INF = 0x3f3f3f3f;
constexpr int64_t LINF = 0x3f3f3f3f3f3f3f3fLL;

constexpr size_t    operator""_sz(unsigned long long value) { return value; };
constexpr intmax_t  operator""_im(unsigned long long value) { return value; };
constexpr uintmax_t operator""_um(unsigned long long value) { return value; };
// }}} End

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

    size_t N;
    cin >> N;

    set<int> st;
    for (size_t i = 0; i < N; ++i) {
        int a; cin >> a;
        st.insert(a);
    }

    cout << (st.size() % 2 ? st.size() : st.size() - 1) << "\n";

    return 0;
}


Measured memory_bytes: 4992
#include <stdio.h>
#include <string.h>

int main(void)
{
    char A[11];
    char B[11];
    char C[11];

    scanf("%s %s %s", A, B, C);

    if (A[strlen(A) - 1] == B[0] && B[strlen(B) - 1] == C[0]){
        puts("YES");
    } else {
        puts("NO");
    }

    return 0;
}


Measured memory_bytes: 128
a,b=gets.split.map &:to_i
g=->x{
y=0
x.bit_length.times{|i|
y|=(i==0?x&3==1||x&3==2:x[i]==1&&x%2==0)?1<<i:0
}
y
}
p g[b]^g[a-1]

Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define boost ios_base::sync_with_stdio(false)
#define pb push_back
#define e1 first
#define e2 second
#define x first
#define y second
#define tysiac 1010
#define milion 1000100
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define OUT(x) { cout << x; return 0; }
#define PRINT(x, y) {printf("%d %d\n", x, y); return;} 
#define scanf(...) scanf(__VA_ARGS__)?:0
typedef long long int ll;
typedef unsigned int ui;
typedef unsigned long long ull;
typedef double ld;
typedef pair <int, int> PII;
typedef pair <ll, ll> PLL;
typedef pair <ld, ld> PDD;
typedef pair <PII, PII> PP;
typedef pair <ll, int> PLI;
typedef pair <double, int> PDI;

const int mod = 1e9+7;
const int inf = 1e9+9;
const int MOD = 1e9+696969;
const ll INF = 1e18+3;
int T, n, m, K, a, b, c, k, d, g, Q, DL;
#define maxn 510

char s[maxn][maxn];
char blue[maxn][maxn], red[maxn][maxn];

int main() {
	scanf("%d%d", &n, &m);
	FOR(i, 1, n) scanf("%s", s[i] + 1);
	FOR(i ,1, n) {
	  FOR(j, 1, m) {
	    if (i % 2 == 0 || s[i][j] == '#' || j == 1) blue[i][j] = '#';
	    else blue[i][j] = '.';
	    if (j == m) blue[i][j] = '.';
	    putchar(blue[i][j]);
	}
	puts("");
	}
	puts("");
	FOR(i, 1, n) {
	  FOR(j, 1, m) {
	    if (i % 2 == 1 || s[i][j] == '#' || j == m) red[i][j] = '#';
	    else red[i][j] = '.';
	    if (j == 1) red[i][j] = '.';
	    putchar(red[i][j]);
	}
	puts("");
}

}


Measured memory_bytes: 1536
using System;

namespace test
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var str = "No";
            for(var i = 0; i < 25; i++){
                for (var j = 0; j < 15; j++){
                    var num = 4 * i + 7 * j;
                    if(i == 0 && j == 0){
                        continue;
                    }
                    if(N % num == 0){
                        str = "Yes";
                    }
                    
                }
            }
            Console.WriteLine(str);


        }
    }
}


Measured memory_bytes: 13140
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,m;
	cin>>n>>m;
	int h[n+1];
	h[0]=0;
	for(int i=1;i<=n;i++)
	{
		cin>>h[i];
	}
	vector<pair<int,int> >v[n+1];
	for(int i=0;i<m;i++)
	{
		int x,y;
		cin>>x>>y;
		v[x].push_back(make_pair(y,h[y]));
		v[y].push_back(make_pair(x,h[x]));
	}
	int ans=0;
	for(int i=1;i<=n;i++)
	{
		if(v[i].size()==0)
		ans++;
		for(int j=0;j<v[i].size();j++)
		{
			if(h[i]<=v[i][j].second)
			{
				break;
			}
			if(j==v[i].size()-1)
			ans++;
		}
	}
	cout<<ans;
}

Measured memory_bytes: 9832
#include<cstdio>
#include<cstring>
using namespace std;
int main(){
    int a,b,c;
    while(1){
        scanf("%d%d%d",&a,&b,&c);
        if(a == -1 && b == -1 && c == -1)break;
        int g=0;
        g = a*3600+b*60+c;
        g = 7200 - g;
        printf("%02d:%02d:%02d\n",g/3600,g%3600/60,g%60);
        printf("%02d:%02d:%02d\n",(g*3)/3600,(g*3)%3600/60,(g*3)%60);
    }
    return 0;
}

Measured memory_bytes: 1040
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=1;i<=(n);i++)
using ll = long long;
typedef pair<int,int> P;
const int INF=1e9;
const int MOD= 1000000007;
int main(){
    ll N,W;
    cin>>N>>W;
    vector<ll> w(N+1),v(N+1);
    rep(i,N) cin>>w[i]>>v[i];
    vector<vector<ll>> dat(N+1,vector<ll> (W+1));
    rep(i,N){
        rep(j,W){
            if(w[i]<=j){
                dat[i][j]=max(dat[i-1][j],dat[i-1][j-w[i]]+v[i]);
            }
            else dat[i][j]=dat[i-1][j];
        }
    }
    cout<<dat[N][W];
}

Measured memory_bytes: 83180
s = input().strip()
t = input().strip()

if len(s) < len(t):
  print('UNRESTORABLE')
else:
  cands = []
  for i in range(len(s) - len(t) + 1):
    is_match = True
    for _s, _t in zip(s[i:i+len(t)], t):
      if _s != '?':
        if _s != _t:
          is_match = False
          break
    if is_match:
      cand = s.replace('?', 'a')
      cand = cand[:i] + t + cand[i+len(t):]
      cands.append(cand)
  if cands:
    print(list(sorted(cands))[0])
  else:
    print('UNRESTORABLE')


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

//Math/ModInt
template<long long mod = 1000000007>
struct modint{
	long long a;

	constexpr modint() : a(0){}
	constexpr modint(long long t){
		a = t % mod;
		if(a < 0) a += mod;
	}

	constexpr operator long long() const{ return a; }

	constexpr bool operator==(const modint &x) const{ return a == x.a; }
	constexpr bool operator!=(const modint &x) const{ return a != x.a; }

	constexpr modint operator-() const{ return modint(a ? (mod - a) : 0); }
	constexpr modint operator~() const{ return pow(mod - 2); }

	constexpr modint operator+(const modint &x) const{ return modint(*this) += x; }
	constexpr modint operator-(const modint &x) const{ return modint(*this) -= x; }
	constexpr modint operator*(const modint &x) const{ return modint(*this) *= x; }
	constexpr modint operator/(const modint &x) const{ return modint(*this) /= x; }

	constexpr modint &operator+=(const modint &x){
		a += x.a;
		if(a >= mod) a -= mod;
		return *this;
	}
	constexpr modint &operator-=(const modint &x){
		a -= x.a;
		if(a < 0) a += mod;
		return *this;
	}
	constexpr modint &operator*=(const modint &x){
		a = a * x.a % mod;
		return *this;
	}
	constexpr modint &operator/=(const modint &x){
		a = a * (~x).a % mod; 
		return *this;
	}

	constexpr modint &operator++(){ return (*this) += 1; }
	constexpr modint &operator--(){ return (*this) -= 1; }
	constexpr modint &operator++(int){
		modint tmp = *this;
		(*this) += 1;
		return tmp;
	}
	constexpr modint &operator--(int){
		modint tmp = *this;
		(*this) -= 1;
		return tmp;
	}

	friend ostream &operator<<(ostream &os,const modint &x){
		return os << x.a;
	}
	friend istream &operator>>(istream &is,modint &x){
		long long t;
		is >> t;
		x = modint(t);
		return is;
	}

	constexpr modint pow(long long x) const{
		modint ret = 1,tmp = a;
		for(;x;tmp *= tmp,x >>= 1){
			if(x & 1) ret *= tmp;
		}
		return ret;
	}
};

//Math/Combination
template<class T>
struct Combination{
	vector<T> fact,factinv;
	Combination(int n) : fact(n + 1),factinv(n + 1){
		fact[0] = 1;
		for(int i = 1;i <= n;i++) fact[i] = fact[i - 1] * T(i);
		factinv[n] = ~fact[n];
		for(int i = n;i >= 1;i--) factinv[i - 1] = factinv[i] * T(i);
	}
	T nCr(int n,int r){
		if(r < 0 || n < r) return 0;
		return fact[n] * factinv[r] * factinv[n - r];
	}
};

const int MOD = 1000003;

signed main(){
	int q;
	scanf("%d",&q);
	Combination<modint<MOD>> comb(MOD - 1);
	for(int i = 0;i < q;i++){
		int x,d,n;
		scanf("%d %d %d",&x,&d,&n);
		modint<MOD> mx = x,md = d;
		if(!d) printf("%d\n",mx.pow(n));
		else if(n >= MOD) puts("0");
		else printf("%d\n",comb.fact[n] * comb.nCr(-mx / md,n) * (-md).pow(n));
	}
}


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

using namespace std;

#ifdef DEBUG_MODE
	#define DBG(n) n;
#else
	#define DBG(n) ;
#endif
#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int W = 0;W < (n);W++)cerr << v[W] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int aaa = 0;aaa < i;aaa++){for(int bbb = 0;bbb < j;bbb++)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 1000000007

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

int num[555][555];
int mp[555];

int main(){

	ll n;cin >> n;

	int seica = -1;

	REP(i,500){
		if(i * (i-1) / 2 == n){
			seica = i;
		}
	}

	if(seica == -1){
		cout << "No" << endl;
		return 0;
	}

	DBG(cout << seica << endl;)

	cout << "Yes" << endl;
	cout << seica << endl;
	int pla = 1;
	REP(i,seica){
		cout << seica - 1 << " ";
		REP(j,i){
			cout << num[j][i-1] << " ";
			num[i][j] = num[j][i-1];
		}
		for(int j = i;j < seica-1;j++){
			cout << pla << " ";
			num[i][j] = pla;
			pla++;
		}
		cout << endl;
	}



	return 0;
}


Measured memory_bytes: 2304
#include <cstdint>
#include <iostream>

using namespace std;

int main()
{
  uint64_t N, K;
  cin >> N >> K;

  if (K == 0) {
    cout << (N * N) << endl;
    return 0;
  }

  uint64_t S = 0;
  for (uint64_t b = K + 1; b <= N; ++b) {
    // 1 <= a <= N
    // a = x * b + k, k >= K
    uint64_t d = N / b, r = N % b, t = b - K;
    
    S += d * t;
    if (r + 1 > K) {
      S += r - K + 1;
    }
  }
  cout << S << endl;

  return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
const double PI  =3.141592653589793238463;
long long mod = 1000000007;
int stringToInteger(string x){
    int gg=0;
    stringstream geek(x);
    geek >> gg;
    return gg;
}

ll powmod(ll a,ll b,ll m)
{
    ll ans=1;
    while(b>0){ if(b%2)
        {ans*=a; ans%=m;}
         b/=2; a=a*a; a=a%m;
        }
        return ans%m;
}
ll gcd(ll a,ll b)
{

    return __gcd(a,b);
}

int main()
{
    int n;
    cin>>n;
    int arr[n];
    int pref[n];
    for(int i=0;i<n;i++){
        cin>>arr[i];
        if(i==0) pref[i]=arr[i];
        else pref[i]=arr[i]+pref[i-1];
    }
    int ans  = abs(pref[0]-pref[n-1]+pref[0]);
    for(int i=1;i<n-1;i++)
    {
        ans=min(ans,abs(pref[i]-pref[n-1]+pref[i]));
    }
    cout<<ans;
    
}








Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second
 
#define bit(n,k) ((n>>k)&1) //*n no k bit me 1 or 0*/

const int mx=100010;
const ll mod=1e9+7;


int main(){
  int n,k;
  cin >> n >> k;
  if(k>(n-1)*(n-2)/2){ cout << -1 << endl; return 0; }
  int cnt = (n-1)*(n-2)/2;
  cnt -= k;
  int ans = n-1 + cnt;
  vector<int> v[n];
  rep(i,n-1){ v[0].emplace_back(i+1); }
  for(int i=1; i<n && cnt>0; i++){
    for(int j=i+1; j<n && cnt>0; j++){
      v[i].emplace_back(j);
      cnt--;
    }
  }

  cout << ans << endl;
  rep(i,n)for(auto it:v[i]){
    cout << i+1 << " " << it+1 << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//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; }
 
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
*/

int main(){
    double x, t; cin >> t >> x;
    printf("%.8lf\n", t/x);

}

Measured memory_bytes: 256
import copy
s=input()

if s[:len(s)//2]==s[1+len(s)//2:]:
    fi=list(s[:len(s)//2])
    fis = copy.copy(fi)
    fis.reverse()
    se=list(s[1+len(s)//2:])
    ses = copy.copy(se)
    ses.reverse()
    if fi==fis and se==ses:
            print('Yes')
    else:
        print('No')
else:
    print('No')

Measured memory_bytes: 38628
n = int(input())
As = list(map(int, input().split()))

from collections import defaultdict
d = defaultdict(int)

for a in As:
    d[a] += 1

cnt = 0
ans = []
for k in sorted(list(d.keys()),reverse=True):
    if d[k] > 1:
        cnt += 1
        ans.append(k)
    if cnt == 2:break


if len(ans) < 2:
    A = 0
else:
    A = ans[1]*ans[0]
# print(A)
cnt_sqr = 0
ans = []
for k in sorted(list(d.keys()),reverse=True):
    if d[k] > 3:
        cnt_sqr += 1
        ans.append(k)
    if cnt == 1:break

if len(ans) < 1:
    A = max(A,0)
else:
    A = max(A,ans[0]**2)
print(A)



Measured memory_bytes: 18216
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll>pi;
const int MAXN=200005;
const int MOD=1000000007;
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define DEC(i,a,b) for(int i=(a);i>=(b);i--)
#define fst first
#define snd second
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define sz(v) ((int)(v).size())
#define db(x) cerr<<#x<<" = "<<x<<"\n"
#define LOW(v,x) (lower_bound(all(v),(x))-(v).begin())

int N;
vector<int>adj[MAXN];
int dist[MAXN];
void dfs(int v, int p, int d){
	dist[v]=d;
	for(auto i:adj[v])if(i!=p)dfs(i,v,d+1);
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	cin>>N;
	FOR(i,1,N-1){
		int a,b;cin>>a>>b;
		adj[a].pb(b);
		adj[b].pb(a);
	}
	dfs(1,-1,0);
	int v1=1;
	FOR(i,1,N)if(dist[v1]<dist[i])v1=i;
	dfs(v1,-1,0);
	int v2=v1;
	FOR(i,1,N)if(dist[v2]<dist[i])v2=i;
	//~ cout<<v1<<' '<<v2<<"\n";
	if(dist[v2]%3==1)cout<<"Second\n";
	else cout<<"First\n";
}
/*
3
2 5
6 1
3 7
Ans:6

4
3 7
2 9
8 16
10 8
Ans:9
*/


Measured memory_bytes: 21376
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>

using namespace std;

int main() {
  int n,Q;
  cin >> n >> Q;
  string s;
  cin >> s;
  int a[n+10]={0};
  int d[n+10]={0};
  for (int i = 0; i < n - 1; i++) {
    if (s[i] == 'A' && s[i + 1] == 'C') a[i] = 1;
  }
  d[0] = a[0];
  for ( int i = 1; i < n; i++) d[i] = d[i -1] + a[i];
  for (int q = 0; q < Q; ++q) {
    int l,r;
    cin >> l >> r;
    l--;
    r--;
    int ans = d[r - 1];
    if(l) ans -= d[l - 1];
    cout << ans << endl;
  }
  
}

Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <algorithm>
#include <utility>
#define INF 1000000000
#define MOD 1000000007

using namespace std;

int main()
{
    int n, m;
    int a, b;
    int g[55] = {};

    cin >> n >> m;
    for (int i = 0; i < m; i++) {
        cin >> a >> b;

        g[a]++;
        g[b]++;
    }

    for (int i = 1; i <= n; i++) {
        cout << g[i] << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
#define FOR(i, l, r) for(int i = (l); i <= (r); ++i)
#define REP(i, n) FOR(i, 0, (n) - 1)
#ifdef DEBUG
  template<class A, class B> ostream& operator<<(ostream &out, const pair<A, B> &p) {
	  return out << '(' << p.first << ", " << p.second << ')';
  }
  template<class T> auto operator<<(ostream &out, T &&x) -> decltype(x.begin(), out) {
	  out << '{';
	  for(auto it = x.begin(); it != x.end(); ++it)
		  out << *it << (it == --x.end() ? "" : ", ");
	  return out << '}';
  }
  void dump() {}
  template<class T, class... Args> void dump(T &&x, Args... args) {
	  cerr << x << ";  ";
	  dump(args...);
  }
  const int seed = 1;
  struct Nl{~Nl(){cerr << '\n';}};
# define debug(x...) cerr << (#x != "" ? #x ":  " : ""), dump(x), Nl(), cerr
#else
  const int seed = chrono::system_clock::now().time_since_epoch().count();
# define debug(...) 0 && cerr
#endif
mt19937_64 rng(seed);
int rd(int l, int r) {
	return uniform_int_distribution<int>(l, r)(rng);
}
template<class T> int size(T a) { return a.size(); }

struct FindUnion {
	vector<int> rep;
	bool sameSet(int a, int b) { return find(a) == find(b); }
	int size(int x) { return -rep[find(x)]; }
	int find(int x) { return rep[x] < 0 ? x : rep[x] = find(rep[x]); }
	bool join(int a, int b) {
		a = find(a), b = find(b);
		if(a == b) return false;
		if(-rep[a] < -rep[b]) swap(a, b);
		rep[a] += rep[b];
		rep[b] = a;
		return true;
	}
	FindUnion(int n) : rep(n, -1) {}
};

#define ST first
#define ND second
LL absolute(LL a) { if(a < 0) return -a; return a; }

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

	int n;
	cin >> n;
	vector<pair<LL, LL>> pts(n);
	for(auto &p : pts)
		cin >> p.ST >> p.ND;

	auto get = [&](LL a, LL b)
	{
		if(a == 0 && b == 0) return n;
		FindUnion s(n);
		int ret = n;
		REP(i, n) REP(j, n)
			if(pts[i].ST - pts[j].ST == a && pts[i].ND - pts[j].ND == b)
				ret -= s.join(i, j);
		return ret;	
	};

	int ans = n;
	REP(i, n) REP(j, n)
		ans = min(ans, get(pts[i].ST - pts[j].ST, pts[i].ND - pts[j].ND));
	cout << ans << "\n";
}


Measured memory_bytes: 256
#include<bits/stdc++.h>                                                                                               
using namespace std;
 
#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define all(x) (x).begin(),(x).end()
#define int long long
#define mk_p(a,b)   make_pair((a),(b))
using pii = pair<int,int>;
constexpr int INF  = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;

int gcd(int a,int b){return b ? gcd(b,a%b) : a;} 
int lcm(int a,int b){return a/gcd(a,b)*b;}

vector<int> a(300050,0);
signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    rep(i,n*3){
        cin >> a[i];
    }   
    int ans = 0;
    sort(all(a),greater<int>());
    for(int i = 1;i<=n*2-1;i += 2){ 
        ans += a[i];
    }   
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 2560
use proconio::{fastout, input};
const MOD: u64 = 1_000_000_000 + 7;

pub fn mpow(mut b: u64, mut e: u64, m: u64) -> u64 {
    let mut result = 1;

    while e > 0 {
        if e & 1 == 1 {
            result = result * b % m;
        }
        e >>= 1;
        b = (b * b) % m;
    }

    result
}

#[fastout]
fn main() {
    input! {
        n: u64,
    }

    println!(
        "{}",
        (mpow(10, n, MOD) + 2 * (MOD - mpow(9, n, MOD)) + mpow(8, n, MOD)) % MOD
    );
}


Measured memory_bytes: 2204
#include <stdio.h>

int main(void){
  int x,y;
  scanf("%d %d",&x,&y);

 while(x != 0 || y != 0){
   if(x < y){
   printf("%d %d\n",x,y);
   } else {
   printf("%d %d\n",y,x);
 }
   scanf("%d %d",&x,&y);
 }

 return 0;
}

Measured memory_bytes: 600
#include <iostream>
#include <string>
#include <algorithm>
#include <math.h>
#include <vector>
#include <iomanip>
#include <map>
#include <queue>

using namespace std;

#define fori(x) for (int i = 0; i < x; ++i)
#define forj(x) for (int j = 0; j < x; ++j)

typedef long long ll;

const int INF = 2e9 + 5;
const int alength=100100;

int main() {
	int a,b;
	cin>>a>>b;
	cout<<a*b-a-b+1;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    string s;
     cin>> s;
    if(s == "Sunny")
        cout<<"Cloudy";
    else if (s== "Cloudy")
        cout<<"Rainy";
    else if (s=="Rainy")
        cout<<"Sunny";
    return 0;
}


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

using namespace std;

using int64 = long long;

int main() {
  int H, W;
  cin >> H >> W;
  if(H > W) swap(H, W);

  if(H == 1) {
    if(W == 1) cout << 1 << endl;
    else cout << W - 2 << endl;
  } else if(H == 2) {
    cout << 0 << endl;
  } else {
    H -= 2;
    W -= 2;
    cout << 1LL * H * W << endl;
  }
}

Measured memory_bytes: 256
import bisect
from collections import defaultdict
from itertools import product

N = int(input())
S = input()

d = defaultdict(list)
for i, c in enumerate(S):
    num = int(c)
    d[num].append(i)

counter = 0
for a, b, c in product(range(10), repeat=3):
    if not d[a]:
        continue
    ia = d[a][0]
    ib = bisect.bisect_right(d[b], ia)
    if len(d[b]) <= ib:
        continue
    ib = d[b][ib]
    ic = bisect.bisect_right(d[c], ib)
    if len(d[c]) <= ic:
        continue
    ic = d[c][ic]
    counter += 1

print(counter)

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

using namespace std;

#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;

int main() {
	string s, t;
	cin >> s >> t;
	rep(i, s.size()) {
		cout << s[i];
		if (i < t.size()) cout << t[i];
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 256
#include <map>
#include <set>
#include <ctime>
#include <queue>
#include <stack>
#include <cmath>
#include <vector>
#include <bitset>
#include <cstdio>
#include <cctype>
#include <string>
#include <cstring>
#include <cassert>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std ;
#define rep(i, a, b) for (int (i) = (a); (i) <= (b); (i)++)
#define per(i, a, b) for (int (i) = (a); (i) >= (b); (i)--)
#define clr(a) memset(a, 0, sizeof(a))
#define ass(a, sum) memset(a, sum, sizeof(a))
#define lowbit(x) (x & -x)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define enter cout << endl
#define siz(x) ((int)x.size())
typedef long long ll ;
typedef unsigned long long ull ;
typedef vector <int> vi ;
typedef pair <int, int> pii ;
typedef pair <ll, ll> pll ;
typedef map <int, int> mii ;
typedef map <string, int> msi ;
const int N = 100010 ;
const int INF = 0x3f3f3f3f ;
const int iinf = 1 << 30 ;
const ll linf = 2e18 ;
const int MOD = 1000000007 ;
void print(int x) { cout << x << endl ; exit(0) ; }
void PRINT(string x) { cout << x << endl ; exit(0) ; }
void douout(double x){ printf("%lf\n", x + 0.0000000001) ; }

int n, k ;
ll a, b ;

int main() {
	scanf("%d%d", &n, &k) ;
	for (int i = 1; i <= n; i++) {
		if (i % k == 0) a++ ;
		if (i % k == k / 2) b++ ;
	}
	if (k % 2 == 1) {
		printf("%lld\n", 1ll * a * a * a) ;
	} else {
		printf("%lld\n", 1ll * a * a * a + 1ll * b * b * b) ;
	}
}

/*
写代码时请注意：
	1.ll？数组大小，边界？数据范围？
	2.精度？
	3.特判？
	4.至少做一些
思考提醒：
	1.最大值最小->二分？
	2.可以贪心么？不行dp可以么
	3.可以优化么
	4.维护区间用什么数据结构？
	5.统计方案是用dp？模了么？
*/


Measured memory_bytes: 256
use std::cmp;

fn main() {
    let sc = std::io::stdin();
    let mut sc = Scanner { reader: sc.lock() };
    let n: usize = sc.read();
    let mut graph = vec![vec![]; n];
    for _ in 1..n {
        let a = sc.read::<usize>() - 1;
        let b = sc.read::<usize>() - 1;
        graph[a].push(b);
        graph[b].push(a);
    }

    let k: usize = sc.read();
    let mut has_num = vec![false; n];
    let mut num = vec![0; n];
    let mut root = n;
    for _ in 0..k {
        let v = sc.read::<usize>() - 1;
        num[v] = sc.read::<i64>();
        has_num[v] = true;
        root = v;
    }

    let mut min_max = vec![(0, 0); n];
    dfs(root, root, &graph, &num, &has_num, &mut min_max);
    if !answer_dfs(root, root, &graph, &mut num, &mut min_max) {
        println!("No");
        return;
    } else {
        println!("Yes");
        for i in 0..n {
            println!("{}", num[i]);
        }
    }
}

fn answer_dfs(
    v: usize,
    p: usize,
    graph: &Vec<Vec<usize>>,
    num: &mut Vec<i64>,
    min_max: &mut Vec<(i64, i64)>,
) -> bool {
    let (min, max) = min_max[v];
    let is_root = v == p;
    if !is_root {
        if min <= num[p] + 1 && num[p] + 1 <= max {
            num[v] = num[p] + 1
        } else if min <= num[p] - 1 && num[p] - 1 <= max {
            num[v] = num[p] - 1
        } else {
            return false;
        }
    }

    for &next in graph[v].iter() {
        if next == p {
            continue;
        }
        let (mut next_min, mut next_max) = min_max[next];
        next_min = cmp::max(next_min, num[v] - 1);
        next_max = cmp::min(next_max, num[v] + 1);
        min_max[next] = (next_min, next_max);
        if !answer_dfs(next, v, graph, num, min_max) {
            return false;
        }
    }
    true
}

fn dfs(
    v: usize,
    p: usize,
    graph: &Vec<Vec<usize>>,
    num: &Vec<i64>,
    has_num: &Vec<bool>,
    min_max: &mut Vec<(i64, i64)>,
) {
    let (mut min, mut max) = if has_num[v] {
        (num[v], num[v])
    } else {
        (-1e15 as i64, 1e15 as i64)
    };
    for &next in graph[v].iter() {
        if p == next {
            continue;
        }
        dfs(next, v, graph, num, has_num, min_max);
        let (next_min, next_max) = min_max[next];
        min = cmp::max(next_min - 1, min);
        max = cmp::min(next_max + 1, max);
    }
    min_max[v] = (min, max);
}

pub struct Scanner<R> {
    reader: R,
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .reader
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n')
            .take_while(|&b| b != b' ' && b != b'\n')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn read_vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 24572
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define nl "\n"
#define rep(i,n) for(ll i=0; i<(n); i++)
#define INF ((1LL<<62)-(1LL<<31))
#define MOD 1000000007 //998244353
typedef vector<ll> vl;
typedef vector<vl> matrix;//A(n, vl(m)); //n*m行列
typedef vector<string> vs;
typedef pair<ll,ll> pl;
typedef vector<pl> vp;
typedef vector<bool> vb;
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define Sortup(V) sort(V.begin(), V.end())
#define Sortdown(V) sort(V.rbegin(), V.rend())
template<class T>bool chmax(T &a, const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a, const T &b){if(b<a){a=b;return 1;}return 0;}
void CumuSum(vl &A){rep(i,A.size())if(i)A[i]+=A[i-1];}
ll llpow(ll e,ll x){ll res=1LL;while(x){if(x&1)res*=e;e*=e;x/=2;}return res;}
ll llpowMOD(ll e,ll x){ll res=1LL;while(x){if(x&1)res*=e;e*=e;x/=2;res%=MOD;e%=MOD;}return res;}


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

    // solution comes here

    ll N, M;
    cin >> N >> M;

    if(1==N) {
        cout << M << nl;
        return 0;
    }

    ll ans=1;
    for(ll i=2; i*i<=M; i++) {
        if(M%i==0 and M>=i*N) {
            chmax(ans, i);
            if(i>=N) chmax(ans, M/i);
        }
    }

    cout << ans << nl;
}

Measured memory_bytes: 256