akhauriyash/Code-Regression huggingface dataset:
import sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
import math
import collections
MOD = 10**9+7
class UnionFind():
    
    def __init__(self,n):
        self.n = n
        self.parents = [-1]*n #各要素の親要素の番号を格納するリスト
    
    #要素xが属するグループの根を返す
    def find(self,x):
        if self.parents[x]<0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]
    
    #要素xと要素yが属するグループを併合する   
    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

    #要素xが属するグループのサイズを返す
    def size(self,x):
        return -self.parents[self.find(x)]
    
    #要素x,yが同じグループかどうかを返す
    def same(self,x,y):
        return self.find(x) == self.find(y)
    
    #要素xと同じグループのメンバーを返す
    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())


n,m,k = map(int,input().split())
fb = [0]*n
uf = UnionFind(n)
for i in range(m):
    a,b = map(int,input().split())
    uf.union(a-1,b-1)
    fb[a-1] += 1
    fb[b-1] += 1
for i in range(k):
    c,d = map(int,input().split())
    if uf.same(c-1,d-1):
        fb[c-1] += 1
        fb[d-1] += 1
Ans = []
for i in range(n):
    ans = uf.size(i) - fb[i] - 1
    Ans.append(ans)
print(*Ans)

Measured memory_bytes: 14616
package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scan(&n)
	crt := 0
	x := 0
	y := 0
	possible := true
	for i := 0; i < n; i++ {
		var t, newX, newY int
		fmt.Scan(&t)
		fmt.Scan(&newX)
		fmt.Scan(&newY)
		dist := 0
		diffX := newX - x
		diffY := newY - y
		if diffX >= 0 {
			dist += diffX
		} else {
			dist -= diffX
		}
		if diffY >= 0 {
			dist += diffY
		} else {
			dist -= diffY
		}
		rest := t - crt - dist
		if rest < 0 || rest%2 == 1 {
			possible = false
		}
		crt = t
		x = newX
		y = newY
	}
	if possible {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


Measured memory_bytes: 5504
#include<stdio.h>
int main(void)
{
	int a,b,n,s[100],f[100],i,j,flg;
	scanf("%d %d",&a,&b);
	scanf("%d",&n);
	flg=0;
	for(i=0;i<n;i++)	scanf("%d %d",&s[i],&f[i]);
	for(i=0;i<n;i++){
		if(a>s[i]&&a<f[i])	flg=1;
		if(b>s[i]&&b<f[i])	flg=1;
		if(a<s[i]&&b>f[i])	flg=1;
		if(a==s[i]&&b==f[i])	flg=1;
	}
	if(flg==0)	printf("0\n");
	else	printf("1\n");
	return 0;
}



Measured memory_bytes: 2692
#include<stdio.h>

#define N 1000000

int calcPrime(int);

int main(){

  int prime_num[N],i,num;

  for(i=0;i<N;i++)prime_num[i]=0;

  for(i=0;i<N;i++){
    if(calcPrime(i))prime_num[i]=prime_num[i-1]+1;
    else prime_num[i]=prime_num[i-1];
  }

  while(scanf("%d",&num)!=EOF){
    printf("%d\n",prime_num[num]);
  }
  return 0;
}

int calcPrime(int num){
  int i;
  if(num<2)return 0;
  else if(num==2)return 1;
  else if(num%2==0)return 0;
  for(i=3;i*i<=num;i=i+2){
    if(num%i==0)return 0;
  }
  return 1;
}

Measured memory_bytes: 4500
N = int(input())
A = list(map(int,input().split()))
n = len(A)
Flag = True
i = 0
while Flag == True and i<n:
  a = A[i]
  if a%2 ==0:
    if a%3 !=0 and a%5 != 0:
      Flag = False
  i += 1
if Flag == True:
  print('APPROVED')
else:
  print('DENIED')

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

int main(void){
	int H, W;

	while (true){
		cin >> H >> W;

		if (H == 0 && W == 0) break;

		for (int y = 0; y < H; y++){
			for (int x = 0; x < W; x++){
				cout << "#";
			}
			cout << "\n";
		}
		cout << "\n";
	}

	return 0;
}

Measured memory_bytes: 1120
#include <stdio.h>
#include<math.h>
#define N 100
#define INFTY 2000000

int main()
{

  int i,j,l,k,n,p[N+1],m[N+1][N+1],q;

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

  p[n]=j;
  for(i=1 ; i <= n ; i++) m[i][i]=0;

  for(l=2 ; l<=n ; l++)
    {
      for(i=1 ; i<=n-l+1 ; i++)
        {
          j = i + l - 1;
          m[i][j] = INFTY;
          for(k=i ; k<=j-1 ; k++)
            {
              q=m[i][k] + m[k+1][j] + p[i-1]*p[k]*p[j];
              if(m[i][j] > q) m[i][j]=q;
                }
        }
    }

  printf("%d\n",m[1][n]);

  return 0;
}


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

#define REP(i, a, b) for (int i = (a); i <= (b); ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define FORV(a, A) for (auto &a : A)

using namespace std;

using ll = long long;

const ll MAX = 510000;
const int MOD = 1E9 + 7;

ll fac[MAX], finv[MAX], inv[MAX];

void COMinit()
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < MAX; i++)
    {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

long long COM(ll n, ll k)
{
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

void Main()
{
    ll N, M, K;
    cin >> N >> M >> K;
    COMinit();
    ll ans = 0;
    REP(d, 1, M - 1)
    {
        ans += d * (M - d) * N * N;
        ans %= MOD;
    }
    REP(d, 1, N - 1)
    {
        ans += d * (N - d) * M * M;
        ans %= MOD;
    }

    ans = (ans * COM(N * M - 2, K - 2)) % MOD;
    cout << ans << endl;
}

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

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

int main() {
  int64_t N,a=2,b=1,c;
  cin>>N;
  if(N==1){cout<<1<<endl;}
  else{
  for(int i=1;i<N;i++){
    c=a+b;
    a=b;
    b=c;
  }
  cout<<c<<endl;
  }
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
using namespace std;
#define _dg cout << "debug" << endl;
int main(){
    int a,b,k;
    int cnt=0;
    cin >> a >> b >> k;
    for(int i=max(a,b); i>=1; i--){
        if(a%i==0 && b%i==0){
            cnt++;
        }
        
        if(cnt==k){
            cout << i << endl;
            break;
        }
    }
}

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

int main(){
    string x, y;cin >> x >> y;

    if (x < y) {
        cout << "<" << endl;
    } else if (x == y){
        cout << "=" << endl;
    } else {
        cout << ">" << endl;
    }

    return 0;
}

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

#define REP(i,num) for(int i=0;i<(num);++i)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto& x:c){cout<<x<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

class Data{
public:
	int v,w;
	ll d;
	char t;
	string name;
	bool operator<(const Data& rhs){
		if(v==rhs.v){
			if(w==rhs.w){
				if(t==rhs.t){
					if(d==rhs.d){
						return name<rhs.name;
					}
					return d<rhs.d;
				}
				return t<rhs.t;
			}
			return w<rhs.w;
		}
		return v<rhs.v;
	}
};

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int N=in();
	vector<int> P(N);
	iota(ALL(P),1);
	REP(i,N-1){
		cout << P[i] << ' ';
	}
	out(P[N-1]);
	
	while(next_permutation(ALL(P))){
		REP(i,N-1){
			cout << P[i] << ' ';
		}
		out(P[N-1]);
	}
	
	return 0;
}


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

using namespace std;

int main(){
    int n,total=0;
    cin >>n;
    if(n<10){
        total=n;
    }else if(n<100){
        total=9;
    }else if(n<1000){
        total=n-90;
    }else if(n<10000){
        total=909;
    }else if(n<100000){
        total=n-9090;
    }else if(n==100000){
        total = 90909;
    }
    cout << total <<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double D;
typedef pair<int,int> P;
typedef tuple<ll,ll,ll> T;
#define M 1000000007
#define F first
#define S second
#define PB push_back
#define INF 1000000000000000000
int n,m,t,x[100005],y[100005],fl[50005];
char ans[100005];
set<int>g[50005];
vector<P>in[100005];
bitset<50005>bs[50005];
int main(void){
    scanf("%d%d%d",&n,&m,&t);
    for(int i=0;i<m;i++)scanf("%d%d",&x[i],&y[i]),x[i]--,y[i]--,ans[i]='v';
    if(t==1){
		for(int i=0;i<n;i++)bs[i][i]=1;
		for(int i=m-1;i>=0;i--)bs[x[i]]|=bs[y[i]],bs[y[i]]|=bs[x[i]];
		for(int i=1;i<n;i++)bs[0]&=bs[i];
		int p=-1;
		for(int i=0;i<n;i++)if(bs[0][i]==1)p=i;
		if(p==-1){
			printf("-1\n");
			return 0;
		}
		fl[p]=true;
		for(int i=m-1;i>=0;i--){
			if(fl[x[i]]){
				ans[i]='^';
				fl[y[i]]=true;
			}else if(fl[y[i]]){
				ans[i]='v';
				fl[x[i]]=true;
			}
		}
		for(int i=0;i<m;i++)printf("%c",ans[i]);
		printf("\n");
		return 0;
	}
	for(int i=0;i<m;i++){
		for(auto it=g[x[i]].begin();it!=g[x[i]].end();it++){
			if(*it==y[i])continue;
			in[i].PB(P(x[i],*it));
			g[*it].erase(x[i]);
		}
		g[x[i]].clear();
		for(auto it=g[y[i]].begin();it!=g[y[i]].end();it++){
			if(*it==x[i])continue;
			in[i].PB(P(y[i],*it));
			g[*it].erase(y[i]);
		}
		g[y[i]].clear();
		g[x[i]].insert(y[i]);
		g[y[i]].insert(x[i]);
	}
	int a,b;
	bool ok=false;
	for(a=0;a<n;a++){
		for(b=a+1;b<n;b++){
			if(g[a].find(b)==g[a].end())ok=true;
			if(ok)break;
		}
		if(ok)break;
	}
	if(!ok){
		printf("-1\n");
		return 0;
	}
	P cur={a,b};
	for(int i=m-1;i>=0;i--){
		bool ch=false;
		for(int j=0;j<in[i].size();j++){
			if(in[i][j].F>in[i][j].S)swap(in[i][j].F,in[i][j].S);
			if(cur==in[i][j]){
				if(x[i]==cur.F||x[i]==cur.S){
					ans[i]='^';
					if(x[i]==cur.F)cur.F=y[i];
					else cur.S=y[i];
				}else if(y[i]==cur.F||y[i]==cur.S){
					ans[i]='v';
					if(y[i]==cur.F)cur.F=x[i];
					else cur.S=x[i];
				}
				ch=true;
				if(cur.F>cur.S)swap(cur.F,cur.S);
			}
		}
		if(!ch){
			if(cur.F==x[i]||cur.S==x[i])ans[i]='^';
			else ans[i]='v';
		}
	}
	for(int i=0;i<m;i++)printf("%c",ans[i]);
	printf("\n");
}


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

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;
    t=1;
    while(t--)
    {
       
       int n;
       cin>>n;
       li a[n];
       for(int i=0;i<n;i++)
       cin>>a[i];
       sort(a,a+n);
      
       int cnt=0;
       for(int i=0;i<n-2;i++)
       {
           for(int j=i+1;j<n-1;j++)
           {
               for(int k=j+1;k<n;k++)
               {
                   if(a[k]<(a[j]+a[i]) && a[k]!=a[j] && a[k]!=a[i] && a[j]!=a[i])
                   {
                    // cout<<i<<" "<<j<<" "<<k<<endl;
                      cnt++;
                   }
                   
               }
           }
       }
       cout<<cnt;
      
       
    }
}

Measured memory_bytes: 3652
import java.util.Scanner;

class Main{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		int S = scan.nextInt();
		
		int h = S / 3600;
		int m = ( S - ( h * 3600) ) / 60;
		int s = S - ( h * 3600) - ( m * 60 );

		System.out.println(h + ":" + m + ":" + s);

		scan.close();
	}
}


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

#define se second
#define fi first
#define mk(a,b) make_pair(a,b)

typedef pair<int,int> pii;
typedef pair<pii,int> iii;

int N,M,Q;
int N_;
int fid[510];
vector<int> mem[510];
vector<iii> query;
int ans[200010];
int seg[800010];

void init()
{
    N_ = 1;
    while(N_ <= N)N_ *= 2;
    for(int i = 0; i < N_ * 2 - 1; i++)seg[i] = 0;
    return;
}

void add(int i,int x)
{
    i += N_ - 1;
    seg[i] += x;
    while(i)
    {
        i = (i - 1) / 2;
        seg[i] = seg[i * 2 + 1] + seg[i * 2 + 2];
    }
    return;
}

int sum(int a,int b,int k = 0,int l = 0,int r = N_)
{
    if(a <= l && r <= b)return seg[k];
    if(b <= l || r <= a)return 0;

    return sum(a,b,k * 2 + 1,l,(l + r) / 2) +
           sum(a,b,k * 2 + 2,(l + r) / 2,r);
}

int main()
{
    scanf("%d%d%d",&N,&M,&Q);
    init();
    for(int i = 0; i < M; i++)
    {
        int r,l;
        scanf("%d%d",&l,&r);
        mem[l].push_back(r);
        add(r,1);
    }

    for(int i = 0; i < Q; i++)
    {
        int p,q;
        scanf("%d%d",&p,&q);
        query.push_back(mk(mk(p,q),i));
    }

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

    int id = 0;
    for(int i = 1; i <= N; i++)
    {
        while(id != Q && query[id].fi.fi == i)
        {
            iii now = query[id];
            ans[now.se] = sum(now.fi.fi,now.fi.se + 1);
            id++;
        }

        while(mem[i].size())
        {
            int tmp = mem[i].back();
            add(tmp,-1);
            mem[i].pop_back();
        }
    }

    for(int i = 0; i < Q; i++)printf("%d\n",ans[i]);

    return 0;
}


Measured memory_bytes: 3836
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr int dx[4] = { 0, 1, 0, -1 };
constexpr int dy[4] = { 1, 0, -1, 0 };
constexpr int INF = 0x3f3f3f3f;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    vector<array<int, 3>> a(n), b(m);
    vector<int> x = { -INF, 0, INF }, y = { -INF, 0, INF };
    x.reserve(n + 3);
    y.reserve(m + 3);
    for (int i = 0; i < n; i++) {
        cin >> a[i][0] >> a[i][1] >> a[i][2];
        x.push_back(a[i][0]);
        x.push_back(a[i][1]);
        y.push_back(a[i][2]);
    }
    for (int i = 0, t; i < m; i++) {
        cin >> b[i][0] >> b[i][1] >> b[i][2];
        x.push_back(b[i][0]);
        y.push_back(b[i][1]);
        y.push_back(b[i][2]);
    }
    sort(x.begin(), x.end());
    sort(y.begin(), y.end());
    x.resize(unique(x.begin(), x.end()) - x.begin());
    y.resize(unique(y.begin(), y.end()) - y.begin());
    int xsize = x.size(), ysize = y.size();
    vector<vector<int>> d(xsize, vector<int>(ysize));
    auto idx = [&](const vector<int>& v, int target) {
        return int(lower_bound(v.begin(), v.end(), target) - v.begin());
    };
    for (const auto& seg : a) {
        int x1 = idx(x, seg[0]);
        int x2 = idx(x, seg[1]);
        int y1 = idx(y, seg[2]);

        for (int j = x1; j < x2; j++) {
            d[j][y1 - 1] |= (1 << 0);
            d[j][y1] |= (1 << 2);
        }
    }
    for (const auto& seg : b) {
        int x1 = idx(x, seg[0]);
        int y1 = idx(y, seg[1]);
        int y2 = idx(y, seg[2]);

        for (int j = y1; j < y2; j++) {
            d[x1 - 1][j] |= (1 << 1);
            d[x1][j] |= (1 << 3);
        }
    }
    queue<pair<int, int>> q;
    vector<vector<bool>> vis(xsize, vector<bool>(ysize, false));
    int sx = idx(x, 0), sy = idx(y, 0);
    q.emplace(sx, sy);
    vis[sx][sy] = 1;
    auto check = [&](int vx, int vy) {
        return vx >= 0 && vx < xsize && vy >= 0 && vy < ysize && !vis[vx][vy];
    };
    while (!q.empty()) {
        int ux, uy;
        tie(ux, uy) = q.front();
        q.pop();
        for (int i = 0; i < 4; i++) {
            if (~d[ux][uy] & (1 << i)) {  // not a fence
                int vx = ux + dx[i];
                int vy = uy + dy[i];
                if (check(vx, vy)) {
                    q.emplace(vx, vy);
                    vis[vx][vy] = true;
                }
            }
        }
    }

    for (int i = 0; i < ysize; i++) {
        if (vis[0][i] || vis[xsize - 1][i]) {
            cout << "INF\n";
            return 0;
        }
    }
    for (int i = 0; i < xsize; i++) {
        if (vis[i][0] || vis[i][ysize - 1]) {
            cout << "INF\n";
            return 0;
        }
    }

    ll ans = 0;
    for (int i = 0; i < xsize; i++) {
        for (int j = 0; j < ysize; j++) {
            if (vis[i][j]) {
                ans += 1LL * (x[i + 1] - x[i]) * (y[j + 1] - y[j]);
            }
        }
    }
    cout << ans << '\n';
    return 0;
}

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

template <class T>
inline void read(T &x) {
    x = 0;
    char c = getchar();
    bool f = 0;
    for (; !isdigit(c); c = getchar()) f ^= c == '-';
    for (; isdigit(c); c = getchar()) x = x * 10 + (c ^ 48);
    x = f ? -x : x;
}

template <class T>
inline void write(T x) {
    if (x < 0) {
        putchar('-');
        x = -x;
    }
    T y = 1;
	int len = 1;
    for (; y <= x / 10; y *= 10) ++len;
    for (; len; --len, x %= y, y /= 10) putchar(x / y + 48);
}

const int MAXN = 50;
int n;
double a[MAXN + 5];

int main() {
	read(n);
	for (int i = 1; i <= n; ++i) read(a[i]);
	sort(a + 1, a + n + 1);
	for (int i = 1; i < n; ++i)
		a[i + 1] = (a[i] + a[i + 1]) / 2.0;
	cout << a[n] << '\n';
	return 0;
}

Measured memory_bytes: 256
import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

class nCrMod():
  def __init__(self,n,mod):
    self.n=n
    self.mod=mod
    self.fact=[0]*(n+1)
    self.ifact=[0]*(n+1)
    self.fact[0]=1  
    for i in range(1,n+1):
      self.fact[i]=self.fact[i-1]*i
      self.fact[i]%=self.mod
    self.ifact[n]=pow(self.fact[n],self.mod-2,self.mod)
    for i in range(1,n+1)[::-1]:
      self.ifact[i-1]=self.ifact[i]*i
      self.ifact[i-1]%=self.mod
  def comb(self,n,k):
    if k<0 or n<k:
      return 0
    return self.fact[n]*(self.ifact[k]*self.ifact[n-k]%self.mod)%self.mod

def main():
  n,m,k=LI()
  res=0
  mod=998244353
  tmp=m*pow(m-1,n-k-1,mod)

  c=nCrMod(200005,mod)
  for r in range(n-k-1,n):
    res=(res+tmp*c.comb(n-1,r)%mod)%mod
    tmp=tmp*(m-1)%mod
  return res

# main()
print(main())


Measured memory_bytes: 76572
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define mod 1000000007
#define LIM 100005
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define endl '\n'
#define ff first
#define ss second
#define vi vector <int>
#define pb push_back
#define sz(x) x.size()
#define all(x) x.begin(), x.end()

int32_t main()
{
  IOS;
  int t,n,m,i,j,k;
  cin>>n;
  double p;
  double dp[n+1];
  for(i=1;i<=n;i++)
  dp[i]=0;
  dp[0]=1;
  for(i=1;i<=n;i++)
  {
    cin>>p;
    for(j=i;j>=0;j--)
    {
      dp[j]= dp[j-1]*p + dp[j]*(1-p);
    }
  }
  double ans=0;
  for(i=n/2+1;i<=n;i++)
  ans+=dp[i];
  cout<<fixed<<setprecision(10)<<ans;
    return 0;
}


Measured memory_bytes: 3732
//

#include <bits/stdc++.h>
#define ld long double
#define ll long long int
#define mod 1000000007
#define ll_inf 1000000000000000
#define int_inf 1000000000
#define pb push_back
#define endl '\n'
#define Endl '\n'
#define eps 1e-9
#define PI acos(-1.0)
#define ii pair<int,int>
#define iii pair<int,ii>
#define se second
#define fi first
using namespace std;
bool vis[15];
bool ch(int n){
    while(n){
        int x=n%10;
        if(vis[x])return 0;
        n/=10;
    }
    return 1;
}
int main(){
    //cout.precision(12);
    //ifstream fin("in");
    int n, k;
    cin>>n>>k;
    for(int i=0;i<k;i++){
        int x; cin>>x; vis[x]=1;
    }
    for(int i=n;;i++){
        if(ch(i)){
            cout<<i<<endl;
            return 0;
        }
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

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

  int m1, d1, m2, d2;
  cin >> m1 >> d1 >> m2 >> d2;
  if (d2 == 1)
    cout << 1 << endl;
  else
    cout << 0 << endl;
}


Measured memory_bytes: 256
// بِسمِ اللہِ  الرَّحم?نِ  الرَّ حِیم
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define MOD 1000000007
#define ll long long
#define pb push_back
#define all(v) v.begin(),v.end()
#define INF 1e18
#define N 9999999
typedef pair<ll,ll> pll;
ll power(ll a,ll b)
{
    if(b==1)return a;
    if(b==0)return 1;
    ll temp=power(a,b/2);
    ll ans=temp*temp;
    if(b&1)
        ans*=a;
    return ans;
}
ll power(ll a,ll b,ll p)
{
    a=a%p;
    if(b==1)return a;
    if(b==0)return 1;

    ll temp=power(a,b/2,p);
    ll ans=(temp*temp)%p;
    if(b&1)
        ans=(a*ans)%p;
    return ans;
}
ll inv(ll a)
{
    return power(a,MOD-2,MOD);
}
//code begins

signed main()
{

//    freopen("input.txt","r",stdin);
//    freopen("output.txt","w",stdout);

    ios_base::sync_with_stdio (false);
    ll t;
    t=1;
//    cin>>t;
    while(t--)
    {
        ll n;cin>>n;
        map<string,ll> cnt;
        vector<string> v;
        for(ll i=0;i<n;i++)
        {
            string s;cin>>s;
            cnt[s]++;
        }
        ll val=-INF;
        for(auto it:cnt)
        {
            if(it.second>val)
                val=it.second;
        }
        for(auto it:cnt)
            v.pb(it.first);
        vector<string> ans;
        for(auto it:v)
        {
            if(cnt[it]==val)
                ans.pb(it);
        }
        sort(all(ans));
        for(auto it:ans)
            cout<<it<<endl;
    }
}


Measured memory_bytes: 27120
#include <bits/stdc++.h>
using namespace std;
 
#define int long long
#define REP(i, l, r) for (int i=(l); i<(r); ++i)
#define RREP(i, r, l) for (int i=(r); i>(l); --i)
#define CASET int _T; cin >> _T; REP(caset, 0, _T)
#define print(x) cout << to_string(x) << '\n'
#define vi vector<int>
#define vb vector<bool>
#define vs vector<string>
#define pii pair<int,int>
#define t3i tuple<int,int,int>
#define mii map<int,int>
#define sq(x) (x)*(x)
#define inv(x) powa(x, MOD-2)
 
int INF = 1LL<<60;
int MOD = 998244353;
 
string to_string(char &c) {string x(1, c); return x;}
string to_string(string &s) {return s;}
string to_string(const char s[]) {return (string)s;}
template <class C> string to_string(C &v) {
    string res;
    for (auto &x : v) res += to_string(x) + ' ';
    return res;
}
template <typename A> istream &operator>>(istream &is, vector<A> &v) {
    for (auto &x : v) is >> x;
    return is;
}
template <typename A, typename B> ostream &operator<<(ostream &os, pair<A, B> pr) {
    os << '(' << pr.first << ", " << pr.second << ')';
    return os;
}
ostream &operator<<(ostream &os, char &c) {os << (char)c; return os;}
ostream &operator<<(ostream &os, string &s) {for (char &c : s) os << (char)c; return os;}
ostream &operator<<(ostream &os, const char s[]) {os << (string)s; return os;}
template <class Container> ostream &operator<<(ostream &os, Container &v) {
    bool first = true;
    os << '[';
    for (auto &x : v) {
        if (!first) os << ',' << ' ';
        first = false;
        os << x;
    }
    os << ']';
    return os;
}
string bin_string(int x) {
    const int d = 32;
    string res(d, ' ');
    REP(i, 0, d) res[d-1-i] = '0'+(x>>i & 1LL);
    return res;
}
int powa(int base, int exp) {
    int res = 1;
    while (exp) {
        if (exp&1) res = res*base % MOD;
        base = base*base % MOD;
        exp >>= 1;
    }
    return res;
}
 
main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    
    int n, m;
    cin >> n >> m;
    vi occ(n+1);
    int score=0, penalties=0;
    REP(i, 0, m) {
        int p; string s;
        cin >> p >> s;
        if (occ[p] != -1) {
            if (s=="AC") {
                penalties += occ[p];
                occ[p] = -1;
                ++score;
            } else ++occ[p];
        }
    }
    cout << score << ' ' << penalties;
}

Measured memory_bytes: 1024
s = input()
s1 = s[:2]
s2 = s[2:]
r1 = 1 <= int(s1) <= 12
r2 = 1 <= int(s2) <= 12
if r1 and r2:
    print('AMBIGUOUS')
elif r1:
    print('MMYY')
elif r2:
    print('YYMM')
else:
    print('NA')

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

int main(void) {
  long long H, W, a, ans;
  cin >> H >> W;
  
  if(W%2 == 0) a = W/2;
  else a = W/2+1;
  
  if(H%2 == 0 && W%2 != 0) ans = (a + (a-1)) * (H/2);
  else if(H%2 == 0 && W%2 == 0) ans = (a + a) * (H/2);
  else if(H%2 != 0 && W%2 != 0) ans = (a + (a-1)) * (H/2) + a;
  else ans = (a + a) * (H/2) + a;
  
  if(H==1 || W==1) ans = 1;
  
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <utility>

using namespace std;

#define mk make_pair
#define fi first
#define se second

typedef pair<long long, long long> pll;

const long long INF = 1ll << 60;
const int MAXN = 200005;

long long sum[MAXN], res = INF;

int A[MAXN], n;

void find(int L, int R, pll &p1, pll &p2)
{
	int l = L, r = R - 1;
	while (l < r)
	{
		int m = (l + r + 1) >> 1;
		long long x = sum[m] - sum[L - 1], y = sum[R] - sum[m];
		if (x <= y)
			l = m;
		else
			r = m - 1;
	}
	if (sum[l] - sum[L - 1] > sum[R] - sum[l])
		p1 = p2 = mk(sum[R] - sum[l], sum[l] - sum[L - 1]);
	else
	{
		p1 = mk(sum[l] - sum[L - 1], sum[R] - sum[l]);
		++l;
		p2 = (l == R ? p1 : mk(sum[R] - sum[l], sum[l] - sum[L - 1]));
	}
}

int main()
{
	ios::sync_with_stdio(false);
	cin >> n;
	for (int i = 1; i <= n; i++)
		cin >> A[i];
	for (int i = 1; i <= n; i++)
		sum[i] = sum[i - 1] + A[i];
	for (int i = 2; i < n - 1; i++)
	{
		pll a[2], b[2];
		find(1, i, a[0], a[1]);
		find(i + 1, n, b[0], b[1]);
		long long cur = INF;
		for (int j = 0; j < 2; j++)
			for (int k = 0; k < 2; k++)
				cur = min(cur, max(a[j].se, b[k].se) - min(a[j].fi, b[k].fi));
		if (cur < res)
			res = cur;
	}
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 2560
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
#include <ctype.h>
#include <stdint.h>
#include <string.h>
#include <wchar.h>
#include <math.h>

#define N_MAX (100)
#define P_MAX (100)
#define DP_ARRAY_SIZE (N_MAX * P_MAX / 32 + 1)

#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define ABS(a) ((a) < 0 ? -(a) : (a))
#define ABSS(a, b) ((a) > (b) ? (a) - (b) : (b) - (a))

int compare_sz_asc(const void* a, const void* b) {
    return *((size_t*)a) < *((size_t*)b) ? -1 : 1;
}

int compare_sz_desc(const void* a, const void* b) {
    return *((size_t*)a) > * ((size_t*)b) ? -1 : 1;
}

int compare_i64_asc(const void* a, const void* b) {
    return *((int64_t*)a) < *((int64_t*)b) ? -1 : 1;
}

int compare_i64_desc(const void* a, const void* b) {
    return *((int64_t*)a) > * ((int64_t*)b) ? -1 : 1;
}

int compare_c_asc(const void* a, const void* b) {
    return *((char*)a) < *((char*)b) ? -1 : 1;
}

int compare_c_desc(const void* a, const void* b) {
    return *((char*)a) > * ((char*)b) ? -1 : 1;
}

static size_t powSz(const size_t base, const size_t exp) {
    if (exp == 0) {
        return 1;
    }

    if (exp == 1) {
        return base;
    }

    if (exp % 2 == 0) {
        return powSz(base * base, exp / 2);
    }
    else {
        return base * powSz(base, exp - 1);
    }
}

static size_t comb(const size_t n, const size_t r) {
    size_t result = 1;

    for (size_t i = 0; i < r; i++) {
        result *= n - i;
        result /= i + 1;
    }

    return result;
}

static uint64_t combU64(const uint64_t n, const uint64_t r) {
    uint64_t result = 1;

    for (uint64_t i = 0; i < r; i++) {
        result *= n - i;
        result /= i + 1;
    }

    return result;
}

static size_t gcdZu(size_t m, size_t n) {
    size_t temp;

    while (m % n != 0) {
        temp = n;
        n = m % n;
        m = temp;
    }

    return n;
}

static uint64_t gcdU64(uint64_t m, uint64_t n)
{
    uint64_t temp;

    while (m % n != 0) {
        temp = n;
        n = m % n;
        m = temp;
    }

    return n;
}

int main(void) {
    uint64_t S;
    uint64_t x[2], y[2];

    scanf("%"PRIu64, &S);

    y[1] = UINT64_C(1000000000);
    x[0] = (S + y[1] - 1) / y[1];

    y[0] = 1;
    x[1] = x[0] * y[1] - S;

    printf("0 0 %"PRIu64" %"PRIu64" %"PRIu64" %"PRIu64, x[0], y[0], x[1], y[1]);

    return 0;
}


Measured memory_bytes: 128
/*input
10 10
3 1 4 1 5 9 2 6 5 3
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define int long long 
#define double long double
#define f first
#define s second
#define mp make_pair
#define pb push_back

#define RE(i,n) for (int i = 1; i <= n; i++)
#define RED(i,n) for (int i = n; i > 0; i--)
#define REPS(i,n) for(int i = 1; (i*i) <= n; i++)
#define REP(i,n) for (int i = 0; i < (int)n; i++)
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define REPD(i,n) for (int i = n-1; i >= 0; i--)
#define FORD(i,a,b) for (int i = a; i >= b; i--)

#define all(v) v.begin(),v.end()
#define pii pair<int,int>
#define vi vector<int>
#define vvi vector<vi>
#define print(arr) for (auto it = arr.begin(); it != arr.end(); ++it) cout << *it << " "; cout << endl;
#define debug(x) cout << x << endl;
#define debug2(x,y) cout << x << " " << y << endl;
#define debug3(x,y,z) cout << x << " " << y << " " << z << endl;

typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;

const int INF = 1e18+1;
const int MOD = 998244353;
const double PI = 3.14159265358979323846264338;

int raise(int a,int n,int m = MOD){
  if(n == 0)return 1;
  if(n == 1)return a;
  int x = 1;
    x *= raise(a,n/2,m);
    x %= m;
    x *= x;
    x %= m;
    if(n%2)x*= a;
    x %= m;
    return x;
}

int floor1(int n,int k){
    if(n%k == 0 || n >= 0)return n/k;
    return (n/k)-1;
}

int ceil1(int n,int k){
    return floor1(n+k-1,k);
}

const int N = 3001;
int dp[N][N];
int n,s;
int a[N];

void solve(){
  	cin >> n >> s;
  	RE(i,n){
  		cin >> a[i];
  	}
  	dp[0][0] = raise(2,n,MOD);
  	int inv2 = raise(2,MOD-2,MOD);
  	RE(i,n){
  		REP(j,s+1){
  			dp[i][j] = dp[i-1][j];
  			if(a[i] <= j){
  				int what = dp[i-1][j-a[i]];
  				what *= inv2;
  				what %= MOD;
  				dp[i][j] += what;
  				dp[i][j] %= MOD;
  			}

  		}
  	}
  	cout << dp[n][s];
}

signed main(){
  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  //freopen(".in","r",stdin);freopen(".out","w",stdout);
  int t = 1;
  //cin >> t;
  while(t--){
    solve();
  }
  return 0;
}

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

string s;
string last;
string curr;
int ans;

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

    for(int i=0; i<s.size(); i++) {
        curr += s[i];
        if(curr != last) {
            //cout << curr << endl;
            ans++;
            last = curr;
            curr = "";
        }
    }

    cout << ans;
}


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


template <typename T>
void array_printer(vector<T> A){
    rep(i,A.size()) cout << A[i] << " ";
    cout << endl;   
}
int main(){
    int A,B,K;
    cin >> A >> B >> K;
    vector<int> ans;
    for (int i = max(A,B); i > 0; i--){
        if ( A % i == 0 && B % i == 0 ){
            ans.push_back(i);
        }
    }
    //array_printer(ans);
    cout << ans[K-1] << endl;
    return 0;
}

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

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

const ll MOD = 1e9 + 7;

int n, m;

int main() {
	cin.tie(0)->sync_with_stdio(0);
	cin >> n >> m;
	vi a(n), b(m);
	for (auto& i : a) cin >> i;
	for (auto& i : b) cin >> i;
	
	ll s1 = 0, s2 = 0;
	for (int i = 1; i < n; ++i) {
		ll len = a[i] - a[i - 1];
		ll before = i, after = n - i;
		ll tot = before * after % MOD;
		s1 = (s1 + ((len % MOD) * tot) % MOD) % MOD;
	}
	
	for (int i = 1; i < m; ++i) {
		ll len = b[i] - b[i - 1];
		ll before = i, after = m - i;
		ll tot = before * after % MOD;
		s2 = (s2 + ((len % MOD) * tot) % MOD) % MOD;
	}
	cout << ((s1 % MOD) * (s2 % MOD) % MOD);
}


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

int main(){
  int n,k,q;
  cin >> n >> k >> q;
  int c[100000]={0};
  int x;
  for(int i=0; i<q; i++){
    cin >> x;
    c[x-1] += 1;
  }
  for(int i=0; i<n; i++){
    if(k-q+c[i] > 0){
      cout << "Yes" << endl;
    } else {
      cout << "No"  << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n)for(int i=0;i<(n);i++)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
using ll = long long;
using P = pair<int, int>;

int main(){
    int a, b, c;
    cin >> a >> b >> c;
    cout << a * b / 2 << endl;
}

Measured memory_bytes: 3624
/*
    ThunderClap and Flash.
    Raunaq Singh
*/
#include "bits/stdc++.h" 
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
#define ThunderClap ios::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL);
#define debugg(something)   cout<<#something<<" - "<<something<<"\n";
#define vi vector
#define umap unordered_map
#define uset unordered_set
#define mset multiset
#define LB lower_bound
#define UB upper_bound
#define mp make_pair
#define pb push_back
#define in insert
#define s second
#define f first
#define pQueue priority_queue
#define maxElement *max_element
#define minElement *min_element
#define MAX 100000LL
#define mod 1000000007LL
#define inf 1000000000000000000LL
#define mI2 500000004LL
inline ll add(ll a, ll b){ return ((a%mod)+(b%mod))%mod;}
inline ll mul(ll a, ll b){ return ((a%mod)*(b%mod))%mod;}
inline ll sub(ll a, ll b){ return ((a%mod)-(b%mod)+mod)%mod;}

bool chk(ll mid, ll n){
    ll fb=(mid/3 + mid/5 - mid/15);
    return (mid>=n);
}

ll sum(ll x){
    return (x*(x+1))/2;
}

void Flash(){
    ll n;
    cin>>n;
    ll high=inf/1000,low=1;
    ll mid,ans=low;
    while(high>=low){
        mid=(high+low)>>1;
        if(chk(mid,n)){
            ans=mid;
            high=mid-1;
        }else{
            low=mid+1;
        }
    }
    ll three=(ans/3);
    ll five=(ans/5);
    ll fifteen=(ans/15);
    ans=(sum(ans)-3*sum(three)-5*sum(five)+15*sum(fifteen));
    cout<<ans<<"\n";
}

int main(int argc, char const *argv[]){
    ThunderClap;
    ll t=1;
    //cin>>t;
    for(ll i=1;i<=t;i++){
        //cout<<"Case #"<<i<<": ";
        Flash();
    }
    return 0;
}

Measured memory_bytes: 3648
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define F first
#define S second
//#define int long long
#define ll long long
//#define int  unsigned long long
#define pb push_back
#define double long double

using namespace std;
using namespace __gnu_pbds;
typedef  tree< int , null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
const int N = 300000;
const int K = 19;
int a[N];

main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    //freopen("input.txt", "r", stdin);
    cin >> a[0] >> a[1] >> a[2] >> a[3];
    sort(a, a + 4);
    if (a[0] == 1 && a[1] == 4 && a[2] == 7 && a[3] == 9){
        cout << "YES";
        return 0;
    }
    cout << "NO";

}


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

using namespace std;

int main() {
	int N, M;
	cin >> N;
	vector<int> T(N);
	for (int i = 0; i < N; i++) {
		cin >> T.at(i);
	}
	cin >> M;
	vector<int> P(M);
	vector<int> X(M);
	for (int i = 0; i < M; i++) {
		cin >> P.at(i) >> X.at(i);
	}

	int sum = 0;
	for (int i = 0; i < N; i++) {
		sum += T.at(i);
	}

	for (int i = 0; i < M; i++) {
		int ans = sum + X.at(i) - T.at(P.at(i) - 1);
		cout << ans << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

#define N 100001

int main(void)
{
  int cnt1=0,cnt2=0,i;
  char S[N];

  scanf("%s",S);

  for (i = 0; i < N; i++) {
    if(S[i]=='1'||S[i]=='0')
    {
    if(i%2==0 &&(S[i]=='1'||S[i]=='0'))
    {
      if(S[i]=='1') {cnt1++;}
    }
    else if(i%2==1)
    {
      if(S[i]=='0') {cnt1++;}
    }
  }
    else
      break;
  }

  for (i = 0; i < N; i++) {
    if(S[i]=='1'||S[i]=='0')
    {
    if(i%2==0)
    {
      if(S[i]=='0') {cnt2++;}
    }
    else if(i%2==1)
    {
      if(S[i]=='1') {cnt2++;}
    }
  }
    else
      break;
  }


  if(cnt1>cnt2)
    printf("%d\n",cnt2);
  else
    printf("%d\n",cnt1);

  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

class Main{
    public static void main(String args[]){
        
        Scanner sc = new Scanner(System.in);

        while(true){
            String x = sc.nextLine();

            if(x.equals("0")){
                break;
            }

            String str[] = x.split("", 0);

            int sum = 0;

            for(int i = 0; i < str.length; i++){
                sum += Integer.parseInt(str[i]);
            }
            System.out.println(sum);
        }
    }
}


Measured memory_bytes: 27468
#include<stdio.h>
#include<math.h>
#include <limits.h>
#include<stdlib.h>
#include<string.h>

int main() {
	int n;
	scanf("%d", &n);
	long int* a = (long int*)malloc(sizeof(long int) * n);
	long int mini=0;
	long int total=0;
	for (int i = 0; i < n; i++) {
		scanf("%ld", a + i);
		if (mini <= *(a + i)) {
			mini = *(a + i);
		}
		else
		{
			total += mini - *(a + i);
		}
	}

	printf("%ld\n", total);

	return 0;
}

Measured memory_bytes: 3252
N, K = map(int, input().split())
A = list(map(int, input().split()))
tele = [0] * N
for i in range(N):
    tele[i] = A[i] - 1
now = 0
cnt = 0
exp = [False] * N
period = 0
loop = False
start = -1
while cnt < K:
    exp[now] = True
    now = tele[now]
    cnt += 1
    if loop:
        period += 1
        if now == start:
            loop = False
            cnt = K - ((K - cnt) % period)
    if exp[now] and (not loop):
        loop = True
        start = now
    # print(now, exp, cnt, period, start)
print(now+1)

Measured memory_bytes: 100136
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define len(v) ll(v.size())
#define fi first
#define se second

template <class T>
void cout_vec(const vector<T> &vec){
  for(auto itr:vec) cout<<itr<<' ';
  cout<<endl;
}

typedef pair<ll,ll> P;
const ll mod=1e9+7;
const ll inf=1e15;

struct edge{
  int to,cost;
};

int n,m,r;

vector<vector<int>> d(210,vector<int>(210,1e9));//d[u][v]は辺e=(u,v)のコスト　存在しなければinf,d[i][i]=0

void warshall_floyd(){
	rep(k,n+1)rep(i,n+1)rep(j,n+1){
		d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
	}
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin>>n>>m>>r;
  vector<int> q(r);
  rep(i,r){
    cin>>q[i];
    q[i]--;
  }
  sort(begin(q),end(q));
  rep(i,m){
    int a,b,c;
    cin>>a>>b>>c;
    a--,b--;
    d[a][b]=min(d[a][b],c);
    d[b][a]=min(d[b][a],c);
  }
  warshall_floyd();
  int ans=1e9;
  do{
    int cnt=0;
    rep(i,r-1){
      int u=q[i],v=q[i+1];
      cnt+=d[u][v];
    }
    ans=min(ans,cnt);
  }while(next_permutation(begin(q),end(q)));
  cout<<ans<<endl;
}

Measured memory_bytes: 384
using System;
using System.Collections;
using System.Linq;
class Program
{
    static int Main()
    {
        //int n = int.Parse(Console.ReadLine());
        string[] s = Console.ReadLine().Split(' ');
        int a, b, x;
        a = int.Parse(s[0]);
        b = int.Parse(s[1]);
        x = int.Parse(s[2]);
        if (a <= x && x <= a + b)
            Console.WriteLine("YES");
        else
            Console.WriteLine("NO");

        return 0;
    }
}

Measured memory_bytes: 11092
MOD = 10**9 + 7
K = int(input())
S = len(input())

FCT = [1]
for i in range(1, K+S+1):
    FCT.append((FCT[-1] * i)%MOD)

def pmu(n, r, mod=MOD):
    return (FCT[n] * pow(FCT[n-r], mod-2, mod)) % mod

def cmb(n, r, mod=MOD):
    return (pmu(n, r) * pow(FCT[r], mod-2, mod)) % mod

def solve():
    ans = 1
    for i in range(S+1, K+S+1):
        ans = (ans*26) % MOD
        add = pow(25, i-S, MOD)
        add = (add * cmb(i-1, i-S)) % MOD
        ans = (ans + add) % MOD
    return ans

if __name__ == "__main__":
    print(solve())


Measured memory_bytes: 211452
#include<stdio.h>
int MIN(int a,int b){return a<b?a:b;}
int E,ta[1010],to[1000010],nt[1000010],co[1000010],F[1010];
int MF(int s,int t,int min){
  if(s==t||min==0)return min;
  int i,r;
  F[s]=1;
  for(i=ta[s];i+1;i=nt[i]){
    if(F[to[i]])continue;
    r=MF(to[i],t,MIN(min,co[i]));
    co[i]-=r;
    co[(i+E)%(2*E)]+=r;
    if(r)return r;
  }
  return 0;
}
int maxf(int s,int t,int v,int *a,int *b,int *c){
  int i,f,r,j;
  for(i=0;i<v;i++)ta[i]=-1;
  for(i=0;i<E;i++){
    nt[i  ]=ta[to[i+E]=a[i]];
    nt[i+E]=ta[to[i  ]=b[i]];
    co[ta[a[i]]=i  ]=c[i];
    co[ta[b[i]]=i+E]=0;
  }
  /*for(i=0;i<v;i++){printf("%d\n",i);
    for(j=ta[i];j+1;j=nt[j])printf("%d %d\n",to[j],co[j]);
    printf("\n");
    }//*/
  for(f=0;r=MF(s,t,1000000000);f+=r){
    /*for(i=0;i<v;i++){printf("%d\n",i);
      for(j=ta[i];j;j=nt[j])printf("%d %d\n",to[j],co[j]);
      printf("\n");
      }//*/
    for(i=0;i<v;i++)F[i]=0;
  }
  return f;
}   
int main(){
  int v,a[1010],b[1010],c[1010],i;
  scanf("%d %d",&v,&E);
  for(i=0;i<E;i++)scanf("%d %d %d",&a[i],&b[i],&c[i]);
  printf("%d\n",maxf(0,v-1,v,a,b,c));
  return 0;
}

Measured memory_bytes: 4716
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string N;
  cin >> N;
  if (N.at(0) == '7') {
    cout << "Yes" << endl;
  }
    else if (N.at(1) == '7') {
    cout << "Yes" << endl;
  }
    else if (N.at(2) == '7') {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

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

using ll = long long;

#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 ddrep(i, n) for (int i = n; i > 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define ssrep(i, s, t) for (int i = s; i <= t; ++i)

#define rng(a) a.begin(), a.end()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))

using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  rep(i, (int)v.size()) {
    if (i)
      os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}

template <typename T, size_t S> void printArray(const T (&array)[S]) {
  for (auto val : array)
    std::cout << val << ", ";
  std::cout << "\n";
}

const int mod = 1e9 + 7;
const int inf = 1e9 + 5;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << std::setprecision(10);

  int n, a, b; std::cin >> n >> a >> b;
  vi h(n); rep(i, n) std::cin >> h[i];
  int l = 0, r = 1'000'000'000;
  auto available = [&](int x) {
    ll aa = a - b, bb = 1ll * b * x;
    ll sum = 0;
    rep(i, n) {
      if (h[i] > bb) sum += (h[i] - bb + aa - 1) / aa;
    }
    return (sum <= x);
  };
  while (l+1 < r) {
    int mid = (l + r) / 2;
    if (available(mid)) r = mid; else l = mid;
  }
  std::cout << r << "\n";
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 7;
const int mod = 1e9 + 7;
typedef long long ll;
int n, m, x;


int main()
{
    scanf("%d", &n);
    printf("%d\n", (n + 1) / 2);

    return 0;
}


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

using namespace std;

#define SZ(x) (int)(x.size())

using ll = long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;

template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  int h, w; cin >> h >> w;
  vector<string> a(h);
  for(int i=0;i<h;++i) {
    cin >> a[i];
  }
  
  vvll dp(h, vll(w, 0));
  dp[0][0] = 1;
  for(int i=0;i<h;++i) {
    for(int j=0;j<w;++j) {
      if(a[i][j] == '#') continue;
      if(i+1 < h && a[i+1][j] == '.') {
        dp[i+1][j] += dp[i][j];
        dp[i+1][j] %= MOD;
      }
      if(j+1 < w && a[i][j+1] == '.') {
        dp[i][j+1] += dp[i][j];
        dp[i][j+1] %= MOD;
      }
    }
  }
  cout << dp[h-1][w-1] % MOD << endl;

}


Measured memory_bytes: 9216
a, s = [0]*100003, [0]*100003
while True:
	n, k = map(int, input().split())
	if n == 0: break
	s[0] = a[0] = int(input())
	for i in range(1, n):
		a[i] = int(input())
		s[i] = s[i-1] + a[i]
		if i >= k: s[i] -= a[i-k]
	ans = s[k-1]
	for i in range(k, n):
		if s[i] > ans: ans = s[i]
	print(ans)


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

using namespace std;

int n, m, q;
int quer[55][4];
int ans = INT_MIN;

int calc(vector<int> &vec);

void helper(int x, vector<int> &vec);


int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t = 1;
    // cin >> t;
    while (t--) {

        cin >> n >> m >> q;
        for (int i = 0; i < q; i++) {
            for (int j = 0; j < 4; j++) {
                cin >> quer[i][j];
            }
        }
        vector<int> vec(1, 1);
        helper(1, vec);
        cout << ans;
    }
    return 0;
}

void helper(int x, vector<int> &vec) {
    if (vec.size() > n) {
        ans = max(ans, calc(vec));
        return;
    }

    for (int i = x; i <= m; i++) {
        vec.push_back(i);
        helper(i, vec);
        vec.pop_back();
    }

}

int calc(vector<int> &vec) {
    int ret = 0;
    for (int i = 0; i < q; i++) {
        int a = quer[i][0], b = quer[i][1], c = quer[i][2], d = quer[i][3];
        if (vec[b] - vec[a] == c) ret += d;
    }
    return ret;
}

Measured memory_bytes: 3660
#include <iostream>
#include <iterator>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
#include <numeric>
#include <iomanip>
#include <limits>

using namespace std;

int main(){

    int ans=0;
    //string s;
    int N;

    cin>>N;

    if(N%2==0){
        ans=N/2;
    }else{
        ans=N/2+1;
    }

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

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

// DAG
vector<long long int> dp;
vector<vector<int>> graph;

long long int DFS(int v){
    if(dp[v] != -1) return dp[v];

    dp[v] = 0;// if no next_v (i.e. sink) dp[v] = 0, visited[v] = true
    for(int next_v : graph[v]){
        dp[v] = max(dp[v], DFS(next_v) + 1);
    }
    return dp[v];
}

int main(){
    int n, m;
    cin >> n >> m;
    graph.resize(n);
    dp.assign(n,-1);

    vector<int> in_degree(n);
    for(int i=0; i<m; i++){
        int u, v;
        cin >> u >> v;
        u -= 1;
        v -= 1;
        graph[u].push_back(v);
        in_degree[v] += 1;
    }

    long long int ans = 0;
    for(int i=0; i<n; i++){
        if(in_degree[i] == 0){
            ans = max(ans, DFS(i));
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 11520