akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define inf 1000000007
#define mod 1000000007
//#pragma GCC optimize(2)
//#define int long long
using namespace std;
template <typename T> void read(T &x){
	x=0;char ch=getchar();int fh=1;
	while (ch<'0'||ch>'9'){if (ch=='-')fh=-1;ch=getchar();}
	while (ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();
	x*=fh;
}
template <typename T> void write(T x) {
	if (x<0) x=-x,putchar('-');
	if (x>9) write(x/10);
	putchar(x%10+'0');
}
template <typename T> void writeln(T x) {
	write(x);
	puts("");
}
int n,m,k;
int pre[100005],cnt[100005];
vector<int> f[100005],b[100005];
int fnd(int x)
{
	if(pre[x]!=x) pre[x]=fnd(pre[x]);
	return pre[x];
}
signed main()
{
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin>>n>>m>>k;
	for(int i=1;i<=n;i++)
		pre[i]=i;
	for(int i=1;i<=m;i++)
	{
		int u,v;
		cin>>u>>v;
		if(fnd(u)!=fnd(v)) pre[fnd(u)]=fnd(v);
		f[u].push_back(v);
		f[v].push_back(u);
	}
	for(int i=1;i<=k;i++)
	{
		int u,v;
		cin>>u>>v;
		b[u].push_back(v);
		b[v].push_back(u);
	}
	for(int i=1;i<=n;i++)
		cnt[fnd(i)]++;
	for(int i=1;i<=n;i++)
	{
		int ans=0;
		for(int j:b[i])
			if(fnd(i)==fnd(j))
				ans++;
		cout<<cnt[fnd(i)]-1-ans-f[i].size()<<' ';
	}
	cout<<endl;
	return 0;
}


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

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    vector<int> Xs(3);
    cin >> n;
    for (auto& X : Xs) {
        cin >> X;
    }
    vector<int> ls(n);
    for (auto& l : ls) {
        cin >> l;
    }
    int smallest_mp = 1000000;
    for (int mask = 0; mask < (1 << (2*n)); ++mask) {
        int tmp_mask = mask;
        int mps = 0;
        int filled = 0;
        vector<int> xs(3, 0);
        for (int i = 0; i < n; ++i) {
            if (tmp_mask % 4 < 3) {
                if (xs[tmp_mask % 4] == 0) {
                    ++filled;
                } else {
                    mps += 10;
                }
                xs[tmp_mask % 4] += ls[i];
            }
            tmp_mask /= 4;
        }
        if (filled == 3) {
            for (int i = 0; i < 3; ++i) {
                mps += abs(Xs[i] - xs[i]);
            }
            smallest_mp = min(smallest_mp, mps);
        }
    }
    cout << smallest_mp << endl;
    return 0;
}


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

int main() {
  int k;
  cin >> k;
  rep(i,0,k) cout << "ACL";
  cout << endl;
}

Measured memory_bytes: 3560
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,k;
  cin>>n>>k;
  vector<int> p(n);
  for(int i=0;i<n;i++){
    cin>>p[i];
  }
  sort(p.begin(),p.end());
  int sum=0;
  for(int i=0;i<k;i++){
    sum+=p[i];
  }
  cout<<sum<<endl;
}

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

int a[100010];
long long dp[100010][2];

int main(){
	int n; scanf("%d", &n);
	for (int i = 1; i <= n; i++){
		scanf("%d", &a[i]);
	}
	for (int i = 1; i <= n; i++){
		for (int x = 0; x < 2; x++){
			if (a[i] < x) continue;
			for (int y = 0; y < 2; y++){
				if (a[i - 1] < x + y) continue;
				dp[i][x] = max(dp[i][x], dp[i - 1][y] + x + (a[i - 1] - x - y) / 2);
			}
		}
	}
	long long ans = 0;
	for (int i = 0; i < 2; i++){
		ans = max(ans, dp[n][i] + (a[n] - i) / 2);
	}
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 2176
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <list>
#include <cstring>
#include <map>
#include <queue>
#include <ctime>
#include <set>
#include <sstream>
#include <unordered_set>
#include <unordered_map>
#include <cmath>

#define pb push_back
#define mp make_pair
#define ll long long
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ull unsigned long long
#define iloop(a,b) for(ll i = a; i < b; ++i)
#define jloop(a,b) for(ll j = a; j < b; ++j)
#define sz(a) int((a).size()) 
#define pb push_back 
#define all(c) (c).begin(),(c).end() 
#define tr(c,i) for(typeofa((c).begin() i = (c).begin(); i != (c).end(); i++) 
#define present(c,x) ((c).find(x) != (c).end()) 
#define cpresent(c,x) (find(all(c),x) != (c).end()) 
#define p(a) cout << a << "\n";
#define p1(a) cout << a << " ";

#define PI 3.141592653589793
#define MOD (ll)(1e9 + 7)

using namespace std;
typedef vector<int> vi; 
typedef vector<vi> vvi; 
typedef pair<int,int> ii; 

void solve()
{
	int a,b,c,d;
	cin >> a >> b >> c >> d;
	if(a < c)	
	{
		if(c - b >= 0)
			p("0")
		else if(b > d)
			p(d-c)
		else
			p(b-c)
	}
	else
	{
		swap(a,c);
		swap(b,d);
		if(c - b >= 0)
			p("0")
		else if(b > d)
			p(d-c)
		else
			p(b-c)
	}	
}
int main()
{
	bool testing = false;
	IOS
	if(testing)
	{
		freopen("test.txt","rt",stdin);
		int start = clock();
		solve();
		int end = clock();
		cout << "time: " << (end - start)/(double)(CLOCKS_PER_SEC)*1000 << " milliseconds\n";
	}
	else
	{
		solve();
	}
} 

Measured memory_bytes: 256
n,k = map(int,input().split())

mod = 10**9 + 7
l = 10**7
fac = [1]*l
facr = [1]*l

for i in range(l-1):
    fac[i+1] = fac[i]*(i+1)%mod
facr[l-1] = pow(fac[l-1],mod - 2,mod)
for i in range(1,l)[::-1]:
    facr[i-1] = facr[i]*i%mod

def combi(N,K):
    return fac[N]*facr[N-K]%mod*facr[K]%mod

ans = 1
for i in range(1,min(n,k+1)):
    ans += combi(n,i)*combi(n-1,i)%mod
    ans %= mod
print(ans)


Measured memory_bytes: 223908
n = int(input())
xl = [list(map(int, input().split())) for _ in range(n)]
arms = [[xl[i][0] - xl[i][1], xl[i][0] + xl[i][1]] for i in range(n)]
arms.sort(key=lambda x: x[1])

ans = 1
ne = arms[0][1]
for i in range(n):
    if arms[i][0] >= ne:
        ne = arms[i][1]
        ans += 1
print(ans)


Measured memory_bytes: 104196
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i <= n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
 
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;

int main(){
    ll d, g;
    cin >> d >> g;
    vll p(d), c(d);
    REP(i, d) cin >> p[i] >> c[i];
    ll ans = 1e15, res, num;
    for(int i = 0; i < (1<<d); i++){
        res = 0, num = 0;
        vll last;
        REP(j, d){
            if((i>>j)&1){
                num += p[j];
                res += p[j] * 100 * (j + 1) + c[j];
            }
            else last.push_back(j);
        }
        if(res >= g){
            ans = min(ans, num);
            continue;
        }
        ll rest = g - res, len = last.size();
        REP(j, len){
            if((p[last[j]] - 1) * 100 * (last[j] + 1) >= rest){
                ans = min(ans, num + 1 + (rest - 1) / (100 * (last[j] + 1)));
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int N,K;
  cin >> N >> K;
  if(N%2==1)N++;
  N=N/2;
  if(N>=K)cout << "YES" << endl;
  if(K>N)cout << "NO" << endl;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define f(i,a,n) for(int i=a ; i<n ; i++)
#define inf 1e17
#define MAX_SIZE 1000005 

void pr(int arr[], int size) 
{ for (ll i=0; i < size; i++) {printf("%d ", arr[i]); }cout << endl;}

int main () {
  ll t = 1;
//   cin >> t;
  while(t--){
    ll n ;
    cin >> n;
    ll a[n];
    ll cnt = 0;
    bool x = true;
    for(ll i = 0;i < n; i++){
        cin >> a[i];
        if(a[i]%2){
            x = false;
        }
    }
    while(x){
        cnt++;
        for(ll i =0 ;i < n;i++){
            a[i] = a[i]/2;
            if(a[i]%2){
                x = false;
                break;
            }
        }
    }
    cout << cnt << endl;
    }
    return 0;
}


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

using namespace std;

#define Fast  ios::sync_with_stdio(false); cin.tie(0)
#define pb push_back
#define pf push_front
#define pp pop
#define ppb pop_back
#define ppf pop_front
#define mp make_pair
#define S second
#define F first
typedef long long ll;
const ll mod = 1e9 + 7;
const ll N = 1e6 + 5;
ll inf = 1e18;

ll a[N];

int main(){

    Fast;

    string s;
    cin >> s;

    int n = s.size();

    if(s[n-1] == 's'){
        cout << s + "es";
    }
    else{
        cout << s + 's';
    }

    return 0;
}


Measured memory_bytes: 3648
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using static System.Console;
namespace AtCoder.AGC019
{
    class IceTeaStore
    {
        public static void Main()
        {
            var sizes = new Decimal[] { 0.25M, 0.5M, 1, 2 };
            var price = ReadLine().Trim().Split(' ').Select((p,idx) => new IceTea(int.Parse(p), sizes[idx])).OrderBy(_ => _.Tanka);
            var demand = Decimal.Parse(ReadLine().Trim());
            decimal res = 0;
            while (demand != 0) {
                foreach(var p in price) {
                    if (demand == 0) break;
                    var count = Math.Floor(demand / p.Size);
                    res += count * p.Price;
                    demand -= count * p.Size;
                }
            }
            WriteLine(res);
        }
        struct IceTea
        {
            public IceTea(int p, Decimal s)
            {
                Price = p; Size = s;
            }
            public int Price { get; private set; }
            public Decimal Size { get; private set; }
            public Decimal Tanka
            {
                get { return Price / Size; }
            }
        }
    }
}


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

#define rng(i, a, b) for (int i = int(a); i < int(b); i++)
#define rep(i, b) rng(i, 0, b)
#define gnr(i, a, b) for (int i = int(b) - 1; i >= int(a); i--)
#define per(i, b) gnr(i, 0, b)

using namespace std;

using ll = long long;
using P = pair<int, int>;

int main() {
  string s, t;
  cin >> s >> t;
  int res = INT_MAX;
  for (int i = 0; i < s.size() - t.size() + 1; i++) {
    int diff = 0;
    rep(j, t.size()) {
      if (t[j] != s[j + i]) {
        diff++;
      }
    }
    res = min(res, diff);
  }
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 3596
from itertools import accumulate

n, k = list(map(int,input().split(" ")))
s = input()


def solve():
    cnt=0
    l=[]
    prev = '1'
    
    for c in s:
        if prev ==c:
            cnt+=1
        else:
            l.append(cnt)
            cnt = 1
        prev=c
    l.append(cnt)
    if prev=='0':
        l.append(0)

    w = 2*k+1

    if len(l)<=w:
        return n

    acc = [0]+list(accumulate(l))
    ans = 0
    for i in range(0, len(l)-w+1,2):
        ans = max(ans,acc[i+w]-acc[i])
    return ans
print(solve())


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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define all(x) (x).begin(),(x).end()
#define endl "\n"

using ll = long long;
using P = pair<int,int>;
using mp =  map<int,int>;

const int MOD = 1e9 + 7;

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

    int n, k;
    cin >> n >> k;

    if(n % k == 0) {
        cout << 0 << endl;
    }else{
        cout << 1 << endl;
    }

    return 0;
}


Measured memory_bytes: 256
//大文字->小文字 tolower(),逆はtoupper()
//int a = stoi(c); 文字列をintへ
//途中の出力をそのまま残さない
//数値計算 個数以外はdouble
//map<キー,値> p は辞書。p[キー] = 値
//map 全探索
//auto begin = p.begin(), end = p.end();
//for (auto it = begin; it != end; it++) {}
//mapのキー：it->first mapのバリュー：it->second
//絶対値 abs()
//入力は空白で切れる
//大文字判定 isupper(文字) 小文字判定 islower(文字)
//do{}while(next_permutation(ALL(配列)))
//while(N)で回すとき、Nはコピーを作っておく
#include <bits/stdc++.h>
#define rep(i,N) for(int i = 0; i < N;i++)
#define ALL(a) (a).begin(),(a).end()
#define ll long long int
using namespace std;

// K進数でのNの桁数
ll dig(ll N, ll K) {
	ll dig = 0;
	while (N) {
		dig++;
		N /= K;
	}
	return dig;
}
// x,yの最大公約数
ll gcd(ll x, ll y) {
	ll r;
	while (x%y) {
		r = x % y;
		x = y;
		y = r;
	}
	return y;
}

//nC2の計算
ll C(ll N) {
	return N * (N - 1) / 2;
}

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

	ll a = N % K;
	ll b = K * (N / K + 1) - N;
	cout << min(a, b) << endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long   ll;
int arr[105];
int main(){
    int n,x=1;
    cin >> n;
    for(int i=0;i<n;i++){
        cin >> arr[i];
    }
    for(int i=0;i<n;i++){
        if(arr[i] %2 ==0){
            if(arr[i]%3 == 0 || arr[i]%5 == 0){
                continue;
            }
            else{
                x--;
              break;
            }
        }
    }
    if(x){
        cout << "APPROVED" ;
    }
    else{
        cout  << "DENIED";
    }
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1000000000LL;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
    int n, m;
    cin >> n >> m;
    priority_queue<ll, vector<ll>, greater<ll>> que;
    rep(i, n){
        ll a; cin >> a;
        que.push(a);
    }
    vector<pll> vc;
    rep(i, m){
        ll b, c; cin >> b >> c;
        vc.push_back(pii(c, b));
    }
    sort(all(vc), greater<pll>());

    rep(i, m){
        int b = vc[i].second, c = vc[i].first;
        rep(j, b){
            int num = que.top(); 
            if(num < c) { que.pop(); que.push(c); }
            else break; 
        }
    }

    ll sum = 0;
    rep(i, n){
        sum += que.top(); que.pop();
    }
    cout << sum << ln;
}


Measured memory_bytes: 3188
import std.algorithm;
void main()
{
    import std.stdio, std.string, std.array, std.conv;

    auto buf = readln.chomp.split;
    immutable n = buf[0].to!size_t, c = buf[1].to!size_t;
    int[][] malaise;
    foreach (i; 0..c)
        malaise ~= readln.chomp.split.to!(int[]);
    ubyte[][] board;
    foreach (i; 0..n)
        board ~= readln.chomp.split.to!(ubyte[]);
    foreach (row; board)
        row[] -= 1;
    board.solve(malaise.transpose).writeln;
}

auto solve(in ubyte[][] board, in int[][] malaise)
{
    auto answer = int.max;
    enum size_t m = 3;
    immutable c = malaise.length;
    auto colorCount = new int[][](m, c);
    foreach (i, row; board)
        foreach (j, color; row)
            colorCount[(i+j) % m][color] += 1;
    foreach (color0; 0..c) foreach (color1; 0..c) foreach (color2; 0..c)
    {
        if (color0 == color1) continue;
        if (color0 == color2) continue;
        if (color2 == color1) continue;
        answer = answer.min(colorCount.simulate(malaise[color0], malaise[color1], malaise[color2]));
    }
    return answer;
}

auto simulate(in int[][] count, in int[][] val...)
{
    import std.numeric, std.range;
    int ret = 0;
    foreach (t; count.zip(val))
        ret += dotProduct(t.expand);
    return ret;
}

T[][] transpose(T)(in T[][] x)
{
    auto ret = new T[][](x[0].length, x.length);
    foreach (i, row; x)
        foreach (j, val; row)
            ret[j][i] = val;
    return ret;
}


Measured memory_bytes: 4604
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<algorithm>
#include<functional>
#include<utility>
#include<bitset>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<cstdio>

using namespace std;

#define REP(i,n) for(int i=0;i<int(n);i++)
#define foreach(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
typedef long long ll;
typedef pair<int,int> P;

char a[110][110];

int main(void){
	          int i,j,k;

	          int N,M,D;
	          cin >> N >> M >> D;
	          for(i=1;i<=N;i++){
	        	  for(j=1;j<=M;j++){
	        		  cin >> a[i][j];
	        	  }
	          }

	          int ans=0;
	          for(i=1;i<=N;i++){
	        	  for(j=1;j<=M;j++){
	        		  if(i+D-1<=N){
	        			  bool f=true;
	        			  for(k=i;k<=i+D-1;k++){
	        				  if(a[k][j]=='#'){
	        					  f=false;
	        					  break;
	        				  }
	        			  }
	        			  if(f) ans++;
	        		  }

	        		  if(j+D-1<=M){
	        			  bool f=true;
	        			  for(k=j;k<=j+D-1;k++){
	        				  if(a[i][k]=='#'){
	        					  f=false;
	        					  break;
	        				  }
	        			  }
	        			  if(f) ans++;
	        		  }

	        	  }
	          }

	          cout << ans << endl;

	          return 0;
}

Measured memory_bytes: 3084
#include <bits/stdc++.h>
#define rep(i,n) for (int i = (0); i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define show(x) cout << #x << " = " << (x) << endl
#define show2(x,y) cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl
#define show3(x,y,z) cout << #x << " = " << (x) << ", " << #y << " = " << (y) <<  ", " << #z << " = " << (z) << endl
#define showv(v) rep(i,v.size()) printf("%d%c", v[i], i==v.size()-1?'\n':' ')
#define showv2(v) rep(j,v.size()) showv(v[j])
#define showt(t,n) rep(i,n) printf("%d%c", t[i], i==n-1?'\n':' ')
#define showt2(t,r,c) rep(j,r) showt(t[j],c)
#define showvp(p) rep(i,p.size()) printf("%d %d\n", p[i].first, p[i].second);
#define printv(v) rep(i,v.size()) printf("%d\n", v[i])
#define printt(t,n) rep(i,n) printf("%d\n", t[i])
#define incl(v,x) find(rng(v),x)!=v.end()
#define incls(s,c) s.find(c)!=string::npos
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define bit(n,k) ((n>>k)&1) // nのk bit目
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vs = vector<string>;
using P = pair<int, int>;
using T = tuple<int, int, int>;
using vp = vector<P>;
using vt = vector<T>;
const int mod = 1000000007;
const double EPS = 1e-9;
//const long double EPS = 1e-14;
const int INF = (1<<30)-1;
//const ll INF = (1LL<<62)-1;
#define dame { puts("No"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
inline int in() { int x; scanf("%d",&x); return x;}
//template<class T = int> inline T in() { T x; cin >> x; return (x);}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
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; }

ll choose2(ll n) {
  return n*(n-1)/2;
}

int main () {
  int n;
  cin >> n;
  vi a(n);
  rep(i,n) cin >> a[i];
  rep(i,n) a[i]--;
  vi cnt(n);
  rep(i,n) cnt[a[i]]++;
  ll tot = 0;
  rep(i,n) {
    tot += choose2(cnt[i]);
  }
  rep(i,n) {
    ll ans = tot;
    ans -= choose2(cnt[a[i]]);
    ans += choose2(cnt[a[i]]-1);
    printf("%lld\n", ans);
  }
  return 0;
}

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


struct UnionFind{
  vector<int> data;
  UnionFind(int n) : data(n, -1) {}
  bool unite(int x, int y){
    x = find(x);
    y = find(y);
    if(x != y){
      if(data[y] < data[x]) swap(x,y);
      data[x] += data[y];//高さを更新
      data[y] = x;//親を更新
    }
    return x != y;
  }
  bool same(int x, int y){ return find(x) == find(y); }
  int find(int x){
    if(data[x] < 0) return x;
    return data[x] = find(data[x]);
  }
};

int main(){
  int N, M;
  cin >> N >> M;
  vector<int> P(N);
  for(int i = 0; i < N; ++i) cin >> P[i];
  vector<int> X(M), Y(M);
  UnionFind uf(N);
  for(int i = 0; i < M; ++i){
    cin >> X[i] >> Y[i];
    --X[i];
    --Y[i];
    uf.unite(X[i], Y[i]);
  }
  int ans = 0;
  for(int i = 0; i < N; ++i){
    if(uf.same(P[i]-1, i)) ++ans;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1792
#include <stdio.h>
int main()
{
  int n,i,j,min,max;
  int array[200000];

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

  min=array[0];
  max=array[1]-array[0];
  for(j=1;j<n;j++){
    if(max<array[j]-min){
      max=array[j]-min;
    }
    if(min>array[j]){
      min=array[j];
    }
  }

  printf("%d\n",max);
  return 0;
}

Measured memory_bytes: 1380
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define ALL(v) (v.begin(),v.end())
#define COUT(x) cout<<(x)<< "\n"


int main(){
    int n;
    cin >> n;
    map<int,int> m{};
    REP(i,n){
        int t;
        cin >> t;
        m[t]++;
    }
    int count = 0;
    for(const auto& i:m){
        if(i.second%2!=0)count++;
    }
    cout << count << endl;
    return 0;
}

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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
constexpr double EPS = 1e-12;
constexpr int INF = numeric_limits<int>::max()/2;
constexpr int MOD = 1e9+7;

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

    int a,b;cin>>a>>b;
    if((a*b)%2) cout<<"Odd"<<endl;
    else cout<<"Even"<<endl;
}


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

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

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcount

const long long M=1e9+7;
typedef vector<long long> vec;
typedef vector<vec> mat;
struct Matrix{
  int N;
  mat a;
  Matrix(int n){
    N=n;
    a=mat(N,vec(N));
    for(int i=0;i<N;i++)a[i][i]=1;
  }
  Matrix pow(long long b) const {
    Matrix res(N);
    Matrix d(N);
    for(int i=0;i<N;i++)for(int j=0;j<N;j++)d[i][j]=a[i][j];
    for(;b>0;b>>=1,d=d*d)if(b&1)res=d*res;
    return res;
  }
  Matrix operator+(const Matrix& r) const {
    Matrix s(N);
    for(int i=0;i<N;i++){
      for(int j=0;j<N;j++){
        s[i][j]=(a[i][j]+r.a[i][j])%M;
      }
    }
    return s;
  }
  Matrix operator*(const Matrix& r) const {
    Matrix s(N);
    for(int i=0;i<N;i++)s[i][i]=0;
    const long long modl=8*M*M;
    //for(int i=0;i<N;i++){
      for(int k=0;k<N;k++){
        for(int j=0;j<N;j++){
          s[0][j]+=a[0][k]*r.a[k][j];
          if(s[0][j]>=modl)s[0][j]-=modl;
        }
      }
      for(int j=0;j<N;j++)s[0][j]%=M;
    //}
    for(int i=0;i<N-1;i++){
      for(int j=0;j<N;j++){
        s[i+1][(j+1)%N]=s[i][j];
      }
    }
    return s;
  }

  vector<long long>& operator[](int i){
    return a[i];
  }
};


ll n,m,k;
ll cnt[888];

int main(){
	cin>>n>>m>>k;
  rep(i,m){
    ll p;
    cin>>p;
    cnt[p%n]++;
  }
  Matrix mat(n);
  rep(i,n)rep(j,n){
    mat[i][(i+j)%n]+=cnt[j];
  }
  Matrix res=mat.pow(k);

  rep(i,n){
    cout<<res[0][i]<<endl;
  }
	return 0;
}

Measured memory_bytes: 22980
#include<stdio.h>
#include<stdlib.h>

double expect()
{
	int N,M,V[105],i;
	double R[105],EXP=0.0,B=0.0;
	scanf("%d%d",&N,&M);
	for(i=0;i<M;i++)
	{
		scanf("%d%lf",&V[i],&R[i]);
		B+=R[i];
	}
	for(i=0;i<M;i++)
	{
		R[i]=R[i]/B;
		EXP+=V[i]*R[i];
	}
	return EXP;
}

int main()
{
	int i,T;
	double my[10]={0.0},hn=0;
	scanf("%d",&T);
	for(i=0;i<T;i++)
		my[i]=expect();
	hn=expect();
	for(i=0;i<T;i++)
		if(my[i]-hn>0.0000001)
		{
			puts("YES");
			return 0;
		}
	puts("NO");
	return 0;
}

Measured memory_bytes: 612
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  int m=n+1;
  long long int sum=0;
  for(int i=0;i<m;i++){
    if(i%3!=0&&i%5!=0) sum+=i;
  }
  cout<<sum<<endl;
}


Measured memory_bytes: 3544
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <string>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>

#define INF 1e09

using std::cin;
using std::cout;
using std::endl;
using std::setprecision;
using std::fixed;
using std::pair;
using std::make_pair;
using std::min;
using std::max;
using std::string;
using std::vector;
using std::list;
using std::map;
using std::set; // insert erase find count
using std::queue;
using std::priority_queue;
using std::stack;

typedef vector<int> VI;
typedef vector<vector<int> > VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<int, pair<int, int> > PIII;

int main(void) {
    while (1) {
        int n;
        int m;
        cin >> n >> m;
        if (n == 0 && m == 0) {
            break;
        }
        VI vn(n);
        VI vm(m);
        for (int i = 0; i < n; i++) {
            cin >> vn[i];
        }
        for (int i = 0; i < m; i++) {
            cin >> vm[i];
        }

        VI listn;
        for (int i = 0; i < n; i++) {
            int temp = vn[i];
            listn.push_back(temp);
            for (int j = i + 1; j < n; j++) {
                temp += vn[j];
                listn.push_back(temp);
            }
        }
        VI listm;
        for (int i = 0; i < m; i++) {
            int temp = vm[i];
            listm.push_back(temp);
            for (int j = i + 1; j < m; j++) {
                temp += vm[j];
                listm.push_back(temp);
            }
        }

        sort(listn.begin(), listn.end());
        sort(listm.begin(), listm.end());

        int count = 0;
        int now_i = 0;
        int now_j = 0;
        int size_i = (int)listn.size();
        int size_j = (int)listm.size();

        while (1) {
            if (now_i == size_i || now_j == size_j) {
                break;
            }
            if (listn[now_i] < listm[now_j]) {
                while (listn[now_i] < listm[now_j] && now_i != size_i) {
                    now_i++;
                }
                continue;
            } else if (listn[now_i] > listm[now_j]) {
                while (listn[now_i] > listm[now_j] && now_j != size_j) {
                    now_j++;
                }
                continue;
            } else {
                int count_i = 0;
                int count_j = 0;
                int temp_i = listn[now_i];
                int temp_j = listm[now_j];
                while (listn[now_i] == temp_i && now_i != size_i) {
                    now_i++;
                    count_i++;
                }
                while (listm[now_j] == temp_j && now_j != size_j) {
                    now_j++;
                    count_j++;
                }
                count += (count_i * count_j);
            }
        }
        cout << count << endl;
    }

    return 0;
}

Measured memory_bytes: 19720
N=int(input())
DATA = [tuple(map(int,input().split())) for i in range(N)]


for idx,datum in enumerate(DATA):
  if idx == 0:
    prev = datum
  else:
    a,b,c = datum
    prev = a+max(prev[1],prev[2]),b+max(prev[0],prev[2]),c+max(prev[0],prev[1])

print(max(prev))


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

#define dump(x)  cout << #x << " = " << (x) << endl;

typedef long long ll;
typedef pair<int, int> ii;
const int mod = 1e9+7;
const ll INF = 1e18;
const int inf = 1e9;

void solve()
{
  int p,q,r; cin>>p>>q>>r;
  cout << min(p+q, min(p+r, q+r)) << endl;
}

int main()
{
  solve();
  return 0;
}


Measured memory_bytes: 384
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

def main():
    A,B=map(int,input().split())
    ans=0
    for i in range(A,B+1):
        if str(i)==str(i)[::-1]:
            ans+=1
    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 40300
using System;
using System.Collections.Generic;
using System.Linq;

namespace Zero_Sum_Ranges
{
    class Program
    {
        static void Main(string[] args)
        {
            var _N = int.Parse(Console.ReadLine());
            var _As = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();
            var accumulation = new long[_N + 1];
            var association = new Dictionary<long, long>();
            accumulation[0] = 0;
            for (var i = 1; i <= _N; i++)
            {
                accumulation[i] = accumulation[i - 1] + _As[i - 1];
            }
            for(var i = 0; i < _N + 1; i++)
            {
                if (association.ContainsKey(accumulation[i]))
                {
                    association[accumulation[i]] = association[accumulation[i]] + 1;
                }
                else
                {
                    association.Add(accumulation[i], 1);
                }
            }

            long count = 0;
            foreach (var item in association)
            {
                count += (item.Value * (item.Value - 1) / 2);
            }

            Console.WriteLine(count);
        }
    }
}


Measured memory_bytes: 43576
#include<unordered_set>
#include<unordered_map>
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<vector>
#include<set>
#include<stack>
#include<map>
#include<algorithm>
using namespace std;

const static string ASCII("abcdefghijklmnopqrstuvwxyz");

size_t N;
string res;
char m[26];

string canonical(const string& s) {

    fill(m, m+26, '!');
    int i = 0;
    string r;
    for (char c : s) {
        if (m[c-'a'] == '!') {
            m[c-'a'] = ASCII[i++];
        }
        r += m[c-'a'];
    }
    return r;
}

int main() {    
    cin>>N;
    unordered_set<string> ans;
    res.reserve(26);    
    stack<string> stk;
    stk.push("");
    while(stk.size()) {
        string s = stk.top(); stk.pop();
        if (s.size()==N)
            ans.insert(canonical(s));
        else
            for (char c='a'; c <= ASCII[s.size()]; c++) stk.push(s + c);                                        
    }
    set<string> ss(ans.begin(), ans.end());
    for(auto& s : ss) printf("%s\n", s.c_str());
}

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

int main() {
    int N, M, X, Y;
    cin >> N >> M >> X >> Y;
    if (X > Y) {
        cout << "War" << endl;
        return 0;
    }
    vector<int> x(N);
    vector<int> y(M);
    for (int i = 0; i < N; i++) {
        cin >> x[i];
    }
    for (int i = 0; i < M; i++) {
        cin >> y[i];
    }
    int min = *max_element(x.begin(), x.end());
    int max = *min_element(y.begin(), y.end());
    if (min < max && X < min && max <= Y) {
        cout << "No War" << endl;
    } else {
        cout << "War" << endl;
    }
}



Measured memory_bytes: 256
#include <assert.h>
#include <limits.h>
#include <cmath>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <complex>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using ll = long long;
using P = std::pair<ll, ll>;

#define rep(i, a, b) for (ll(i) = (a); i < (b); i++)
#define all(i) i.begin(), i.end()
#define debug(i) std::cout << i << "\n"

//const ll MOD = 998244353;
const ll MOD = 1e9+7;

int main() {
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);
  //問題文中の添え字が0-indexか1-indexか確認!

  ll a,b,c;
  std::cin>>a>>b>>c;
  if(!(a%2)||!(b%2)||!(c%2)){
    std::cout<<0;
  }else{
    std::cout<<std::min(a*b,std::min(b*c,a*c));
  }
  return 0;
}

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

const int N = 1e5 + 10;
int a[N], dp[2][N];

int main() {
    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    int n;
    cin >> n;
    for (int i = 0; i < n; i++)
        cin >> a[i];
    dp[0][0] = dp[1][0] = 1;
    for (int i = 1; i < n; i++) {
        dp[1][i] = dp[0][i] = min(dp[0][i - 1], dp[1][i - 1]) + 1;
        if (a[i] >= a[i - 1])
            dp[1][i] = min(dp[1][i], dp[1][i - 1]);
        if (a[i] <= a[i - 1])
            dp[0][i] = min(dp[0][i], dp[0][i - 1]);
    }
    cout << min(dp[0][n - 1], dp[1][n - 1]) << "\n";
    return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i < (n); i++)
#define all(v) (v).begin(), (v).end()
using namespace std;
typedef long long LL;
const int INF = 999999999;
const LL mod = 1000000007;

int main(){
    int n, d;
    cin >> n >> d;
    int s = 0;
    rep(i, n){
        int a;
        cin >> a;
        a--;
        s ^= a%(d+1);
    }
    cout << (s ? "First" : "Second") << endl;

}



Measured memory_bytes: 3076
#include <stdio.h>
#define MAX 10
int main(){
    int n, count = 0, a, b, c, d;
    
    while (scanf("%d", &n) != -1) {

        for (a = 0; a < MAX; a++) {
            for (b = 0; b < MAX; b++) {
                for (c = 0; c < MAX; c++) {
                    for (d = 0; d < MAX; d++) {
                        if (n == a + b + c + d){ count++;}
                    }
                }
            }
        }
        printf("%d\n", count);
        count = 0;
    }
    return 0;
}

Measured memory_bytes: 592
from itertools import combinations_with_replacement
from itertools import product

def func(a,b,c):
  return a**2+b**2+c**2+a*b+b*c+c*a

num=list(range(1,42))
n = int(input())
p = 0
dic = {}
for i in list(product(range(1,100), repeat=3)):
  r = func(i[0], i[1], i[2])
  if r in dic:
    dic[r] += 1
  else:
    dic[r] = 1
for d in range(1,n+1):
  if d in dic:
    print(dic[d])
  else:
    print(0)

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

using namespace std;
typedef long long ll;
const long double pi=3.14159265358979323846;
int main()
{
    cin.tie(0);
    cin.sync_with_stdio(0);
    ll t=1;
    //cin>>t;
    while(t--)
    {
        long double a,b,h,m;
        cin>>a>>b>>h>>m;
        h+=m/60;
        h*=30;
        m*=6;
        //if(h==m){cout<<0;return 0;}
        long double theta = abs(m-h);
        long double sx=(a*a + b*b) - (2*a*b*cos(pi*(theta/180)));
        cout<<fixed<<setprecision(11)<<sqrt(sx);
    }
    return 0;
}


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

using namespace std;

const int NMAX = 100000 + 10;

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

    int dp[NMAX];
    for (int i = 0; i < NMAX; ++i) {
        dp[i] = i;//1円だけ使うとき
    }

    for (int i = 0; i <= n; ++i) {
        //6円も使う
        for (int j = 1; i - j >= 0; j *= 6) {
            dp[i] = min(dp[i], dp[i - j] + 1);
        }
        //9円も使う
        for (int j = 1; i - j >= 0; j *= 9) {
            dp[i] = min(dp[i], dp[i - j] + 1);
        }
    }

    cout << dp[n] << endl;
    return 0;
}

Measured memory_bytes: 640
N, K = map(int, input().split())
pts = []
ys = []
for _ in range(N):
    x, y = map(int, input().split())
    pts.append((x, y))
    ys.append(y)

pts.sort()
ys.sort()

ans = 10**20
for i, y1 in enumerate(ys):
    for y2 in ys[i+1:]:
        for j, (x1, _) in enumerate(pts):
            num = 0
            for x, y in pts[j:]:
                if y1 <= y <= y2:
                    num += 1
                if num >= K:
                    area = (x-x1) * (y2-y1)
                    ans = min(ans, area)
                    break

print(ans)


Measured memory_bytes: 3064
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;

#define MOD 1000000007

vector<int> g[100000];
vector<bool> visit(100000);
vector<int> col(100000);
int c = 1;

void dfs(int v) {
  col[v] = c;
  visit[v] = true;
  for (auto u : g[v]) {
    if (!visit[u]) {
      dfs(u);
    }
  }
}

int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; ++i) {
    int s, t;
    cin >> s >> t;
    g[s].push_back(t);
    g[t].push_back(s);
  }
  for (int i = 0; i < n; ++i) {
    if (!visit[i]) {
      dfs(i);
      c++;
    }
  }
  int q;
  cin >> q;
  for (int i = 0; i < q; ++i) {
    int s, t;
    cin >> s >> t;
    cout << (col[s] == col[t] ? "yes" : "no") << endl;
  }
  return 0;
}


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

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


#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))

int dx4[4] = {1,0,-1,0}, dy4[4] = {0,1,0,-1};


int main()
{
    int n;
    cin>>n;
    bool ok=false;
    while(n>0)
    {
        if(n%10==7)
        {
            ok=true;
            break;
        }
        n/=10;
    }
    if(ok) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    
    return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define db(x) cout << (x) << '\n';
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define f first
#define s second
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pii;
typedef pair<double,ll> pdi;
typedef pair<ld,ld> pdd;
typedef pair<double,ll> pdi;
typedef pair<double,pii> pdp;
typedef pair<string,ll> psi;
typedef pair<ll,string> pls;
typedef pair<string,string> pss;
typedef pair<ll,pii> pip;
typedef pair<pii,pii> ppp;
typedef complex<ld> point;
#define mod (ll)(1e9+7)
#define eps (1e-9)
#define oo (ll)(0x3f3f3f3f)
#define pi acos(-1)
#define MAXN (ll)(5e5+5)

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

    string s;
    cin >> s;
    cout << s[0] << s[1] << s[2] << '\n';

    return 0;
}


Measured memory_bytes: 3652
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const int INF = 1e9;

int n, a, b, c;
vector<int> l;

int dfs(int i, int A, int B, int C, int None, int cost){
    int ret = INF;
    if(i == n){
        ret = cost;
        ret += abs(A - a) + abs(B - b) + abs(C - c);
        if(A == 0 || B == 0 || C == 0) ret = INF;
        return ret;
    }
    chmin(ret, dfs(i+1, A+l[i], B, C, None, cost+(A==0 ? 0 : 10)));
    chmin(ret, dfs(i+1, A, B+l[i], C, None, cost+(B==0 ? 0 : 10)));
    chmin(ret, dfs(i+1, A, B, C+l[i], None, cost+(C==0 ? 0 : 10)));
    chmin(ret, dfs(i+1, A, B, C, None+l[i], cost));
    return ret;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n >> a >> b >> c;
    l.resize(n);
    rep(i,n) cin >> l[i];
    int ans = dfs(0, 0, 0, 0, 0, 0);
    cout << ans << endl;
    return 0;
}

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

using namespace std;

ll num[10];

int main()
{


    ll n,i,j,k,x,y,p,d,m;

    for(i=1;i<=3;i++)cin>>num[i];

    sort(num+1,num+3+1);

    d=num[2]-num[1];

    x=d/2;
    if(d%2==1)
    {
        x++;
        num[3]++;
    }

    x+=(num[3]-num[2]);

    cout<<x<<endl;


    return 0;
}



Measured memory_bytes: 256
#include <stdio.h>
#define N 101
void visit(int);
int T=1,m[N][N],d[N]={0},a[N],b[N],n;
#include<stdio.h>
int main(){
  int k,i,j,u,v;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      m[i][j]=0;
    }
  }
 for(i=0;i<n;i++){
    scanf("%d%d",&u,&k);
    for(j=0;j<k;j++){
      scanf("%d",&v);
       m[u-1][v-1]=1;      
   }
 }
 for(i=0;i<n;i++){
   if(d[i]==0) visit(i);
 }
 for(i=0;i<n;i++){
   printf("%d %d %d\n",i+1,a[i],b[i]);
 }
 return 0;
}
void visit(int u){
  int v; 
  a[u]=T++;
  d[u]=1;
  for(v=0;v<n;v++){
    if(m[u][v]==1&&d[v]==0){ 
      visit(v);
    }
  }   
  b[u]=T++;  
}



Measured memory_bytes: 2108
def main():
    N = list(map(int, input().split()))
    K = int(input())
    cnt = 0
    i = 0
    while cnt < K:
        if i >= 2:
            break
        if N[i] < N[i+1]:
            i += 1
            continue
        N[i+1] *= 2
        cnt += 1 
        
    if N[0] < N[1] and N[1] < N[2]:
        return "Yes"
    else:
        return "No"

if __name__ == '__main__':
    print(main())

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

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringBuilder sb = new StringBuilder();

		while(true) {
			String num = br.readLine();
			String[] set = num.split(" ");

			int a = Integer.parseInt(set[0]);
			int b = Integer.parseInt(set[1]);

			if (a==0 && b==0) {
				break;
			}

			for (int i = 0; i < a ; i++) {
				for (int j = 0; j < b ; j++) {
					if(i==0 || j==0 || i==a-1 || j==b-1) {
						sb.append("#");
					}else {
						sb.append(".");
					}
				}
				sb.append("\n");
			}
			sb.append("\n");
		}

		System.out.print(sb);

	}

}

Measured memory_bytes: 25232
# coding: utf-8
# Your code here!

k, n = map(int, input().split())
A = list(map(int, input().split()))
AA = sorted(A)
AA.append(AA[0]+k)
dif_AA = []

for a in range(len(AA)-1) : 
    tmp = AA[a+1] - AA[a]
    dif_AA.append(tmp)
    
dif_max = dif_AA.index(max(dif_AA))
ans = AA[dif_max] - AA[0] + AA[-1] - AA[dif_max+1]

print(ans)

# candidate_1 = AA[-1] - AA[1]
# candidate_2 = AA[-2] - AA[0]

# print(min(candidate_1, candidate_2))

Measured memory_bytes: 26444
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int N,M;
  cin >> N >> M;
  vector<vector<char>> A(N,vector<char>(N));
  vector<vector<char>> B(M,vector<char>(M));
  for(int i=0;i<N;i++){
    for(int h=0;h<N;h++){
      cin >> A.at(i).at(h);
    }
  }
  for(int i=0;i<M;i++){
    for(int h=0;h<M;h++){
      cin >> B.at(i).at(h);
    }
  }
  
  int check = 0;
  int ok = 0;
  
  for(int y=0;y<(N-M+1);y++){
    for(int x=0;x<(N-M+1);x++){
      if(ok != 1){
      check = 0;
      for(int w=0;w<M;w++){
        for(int z=0;z<M;z++){
          if(A.at(y+w).at(x+z) == B.at(w).at(z)){
            check++;
          }
        }
      }
      
      if(check == M*M){
        ok += 1;
      }
      }
    }
  }
  
      if(ok == 1){
        cout << "Yes";
      }else{
        cout << "No";
      }
}
    
    


  



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define show(x) cout<<x<<'\n'
#define showh(x) cout<<x<<' '
#define go(i,a,n) for(ll i=a;i<n;i++)
#define gor(i,a,n) for(ll i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define mod 1000000007
bool prime[100001];
ll pre[2001][2001];
bool ispoweroftwo(ll x)
{
    return x && !(x & (x-1));
}
ll xorcal(ll n)
{
    if(n%4==0)
        return n;
    if(n%4==1)
        return 1;
    if(n%4==2)
        return n+1;
    if(n%4==3)
        return 0;
}
void sieve(ll n)
{
    memset(prime,true,sizeof(prime));
    prime[0]=false;
    prime[1]=false;
    for(ll i=2;i*i<=n;i++)
    {
        if(prime[i]==true)
        {
            for(ll j=i*i;j<=n;j+=i)
            {
                prime[j]=false;
            }
        }
    }
}
bool isprime(ll n)
{
    if (n<=1) return false;
    if (n<=3) return true;

    if(n%2==0 or n%3==0) return false;

    for(ll i=5;i*i<=n;i+=6)
    {
        if(n%i==0 or n%(i+2)==0) return false;
    }
    return true;
}

ll modinverse(ll a,ll m)
{
    ll m0 = m;
    ll y = 0, x = 1;

    if (m == 1)
      return 0;

    while (a > 1)
    {
        ll q = a / m;
        ll t = m;

        m = a % m; a = t;
        t = y;

        y = x - q * y;
        x = t;
    }

    if (x < 0)
       x += m0;

    return x;
}

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

ll power(ll A, ll B)
{
    if (A == 0)
        return 0;
    if (B == 0)
        return 1;

    ll y;
    if (B % 2 == 0) {
        y = power(A, B / 2);
        y = (y * y) % mod;
    }

    else {
        y = A % mod;
        y = (y * power(A, B - 1) % mod) % mod;
    }

    return (ll)((y + mod) % mod);
}
ll fib(ll n)
{
    if(n<=1)
    {
        return n;
    }
    return fib(n-1)+fib(n-2);
}
void ncr()
{
    pre[0][0]=1;
    go(i,1,2001)
    {
        pre[i][0] = 1;
        go(j,1,2001)
        {
            pre[i][j] = pre[i-1][j] + pre[i-1][j-1];
        }
    }
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n;
    cin>>n;
    ll b[n+1],a[n];
    go(i,0,n+1)
    {
        cin>>b[i];
    }
    go(i,0,n)
    {
        cin>>a[i];
    }
    ll grand_tot=0;
    go(i,1,n+1)
    {
        if(b[i-1]+b[i]<=a[i-1])
        {
            grand_tot += b[i-1]+b[i];
            b[i-1]=0;
            b[i]=0;
            continue;
        }
        else
        {
            if(b[i-1]>=a[i-1])
            {
                grand_tot += a[i-1];
                b[i-1] -= a[i-1];
                a[i-1]=0;
            }
            else
            {
                grand_tot += b[i-1];
                a[i-1] -= b[i-1];
                b[i-1] = 0;
            }
            if(b[i]>=a[i-1])
            {
                grand_tot += a[i-1];
                b[i] -= a[i-1];
                a[i-1]=0;
            }
            else
            {
                grand_tot += b[i];
                a[i-1] -= b[i];
                b[i] = 0;
            }
        }
    }
    show(grand_tot);
    return 0;
}


Measured memory_bytes: 1792
// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools

#include <bits/stdc++.h>

using namespace std;

using i64 = long long;

const i64 MOD = 1e9 + 7;
const i64 INF = i64(1e18) + 7;

const string YES = "Yes";
const string NO = "No";

template <typename T>
bool chmin(T& x, T y){
    if(x > y){
        x = y;
        return true;
    }
    return false;
}

template <typename T>
bool chmax(T& x, T y){
    if(x < y){
        x = y;
        return true;
    }
    return false;
}


void solve(long long d, long long t, long long s){
    if(t * s >= d)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}


signed main(){
    long long D;
    scanf("%lld",&D);
    long long T;
    scanf("%lld",&T);
    long long S;
    scanf("%lld",&S);
    solve(D, T, S);
    return 0;
}


Measured memory_bytes: 3732
#include <cstdio>
#include <iostream> 
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <typeinfo>
#include <numeric>
 
using namespace std;
using ll = long long;
 
const ll INF = 1e9;
const ll MOD = 1e9 + 7;
int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };


int main()
{
	ll n, t, a, tt, aa;

	cin >> n >> tt >> aa;
	for(int i = 0; i < n - 1; i++){
		cin >> t >> a;

		if(tt <= t && aa <= a){
			tt = t;
			aa = a;
		}
		else if(tt > t && aa <= a){
			tt = (tt % t == 0)? t * (tt / t) : t * (tt / t + 1);
			aa = (tt % t == 0)? a * (tt / t) : a * (tt / t + 1);
		}
		else if(tt <= t && aa > a){
			aa = (aa % a == 0)? a * (aa / a) : a * (aa / a + 1);
			tt = (aa % a == 0)? t * (aa / a) : t * (aa / a + 1);
		}
		else{
			ll k;
			k = max((tt % t == 0)? tt / t : tt / t + 1, (aa % a == 0)? aa / a : aa / a + 1);
			tt = t * k;
			aa = a * k;
		}
	}

	cout << tt + aa << endl;
}

Measured memory_bytes: 256
import collections

n, k = map(int, input().split())
a = list(map(int, input().split()))

c = collections.Counter(a)
cval = sorted([i for i in c.values()])

if len(cval) <= k:
  print(0)
else:
  ans = 0
  for i in range(len(cval) - k):
    ans += cval[i]
  print(ans)

Measured memory_bytes: 32568