akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

#define all(x) (x).begin(), (x).end()
#define init()                 \
  ios::sync_with_stdio(false); \
  cin.tie(0)

#define MOD 1000000007

using namespace std;

using ll = long long;
using ull = unsigned long long;

template <typename M, typename N>
constexpr common_type_t<M, N> gcd(M a, N b)
{
  return a == 0 ? b
                : b == 0 ? a
                         : gcd(b, a % b);
}

template <typename M, typename N>
constexpr common_type_t<M, N> lcm(M a, N b)
{
  return a * b / gcd(a, b);
}

template <long long MAX>
class CombinationCalculator
{
  long long mod_;
  long long fac[MAX];
  long long finv[MAX];
  long long inv[MAX];

public:
  CombinationCalculator(long long mi = MOD) : fac(), finv(), inv()
  {
    mod_ = mi;
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int 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 c(long long n, long long k) const
  {
    if (n < k)
      return 0;
    if (n < 0 || k < 0)
      return 0;
    return fac[n] * (finv[k] * finv[n - k] % mod_) % mod_;
  }
};

template <long long MAX = 210000>
using CC = CombinationCalculator<MAX>;

template <typename T>
T modpow(T a, T n, T mod = MOD)
{
  T res = 1;
  while (n > 0)
  {
    if (n & 1)
      res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

template <typename T>
T modinv(T a, T m = MOD)
{
  T b = m, u = 1, v = 0;
  while (b)
  {
    T t = a / b;
    a -= t * b;
    swap(a, b);
    u -= t * v;
    swap(u, v);
  }
  u %= m;
  if (u < 0)
    u += m;
  return u;
}

int main()
{
  init();

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

  double p = 0.;
  for (int i = 1; i <= n; i++)
  {
    int i2 = i;
    int q = 0;
    while (i2 < k)
    {
      i2 *= 2;
      q++;
    }
    p += 1. / n * pow(0.5, q);
  }
  cout << fixed << setprecision(12) << p << endl;

  return 0;
}


Measured memory_bytes: 384
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;
#define x first
#define y second
#define dbg(x) cout << #x << '=' << x << '\n';
#define ll long long
#define pi pair<int,int>
#define pl pair<ll,ll>
#define pd pair<double,double>
#define ld long double
#define pld pair<ld,ld>
#define lg length()
#define sz size()
#define pb push_back
#define MAXN 100005
#define INF 1000000005
#define LINF 1000000000000000005
#define x1 xdddddddddddddddddd
#define y1 ydddddddddddddddddd

int n,a[2005],s;

bitset <4000005> g;

int32_t main(){
    ios_base :: sync_with_stdio(0); cin.tie(); cout.tie();
    cin >> n; g[0]=1;
    for(int i=1;i<=n;i++){
        cin >> a[i];
        s+=a[i];
        g|=(g<<a[i]);
    }
    for(int i=(s+1)/2;i<=s;i++){
        if(g[i]){
            cout << i;
            return 0;
        }
    }

}


Measured memory_bytes: 1792
#include<cstdio>
#include<algorithm>
#define MAXN 100000
#define INF 0x3FFFFFFF
using namespace std;
struct node
{
	int to;
	node *next;
}edge[MAXN*2+5];
node *ncnt=&edge[0],*Adj[MAXN+5];
struct point
{
	int val;
	bool vis;
}poi[MAXN+5];
int minval=INF,minid,N,M;
bool visit[MAXN+5];
bool cmp(point a,point b)
{
	return a.val<b.val;
}
void AddEdge(int u,int v)
{
	node *p=++ncnt;
	p->to=v;
	p->next=Adj[u];
	Adj[u]=p;
	
	node *q=++ncnt;
	q->to=u;
	q->next=Adj[v];
	Adj[v]=q;
}
void dfs(int u)
{
	int v;
	visit[u]=true;
	if(poi[u].val<minval)
		minval=poi[u].val,minid=u;
	for(node *p=Adj[u];p!=NULL;p=p->next)
	{
		v=p->to;
		if(visit[v]==false)
			dfs(v);
	}
}
int main()
{
	scanf("%d %d",&N,&M);
	for(int i=0;i<N;i++)
		scanf("%d",&poi[i].val),poi[i].vis=false;
	int x,y;
	for(int i=1;i<=M;i++)
	{
		scanf("%d %d",&x,&y);
		AddEdge(x,y);
	}
	int cnt=0;
	long long ret=0LL;
	for(int i=0;i<N;i++)
		if(visit[i]==false)
		{
			minval=INF;
			cnt++;
			dfs(i);
			poi[minid].vis=true;
			ret+=1LL*minval;
		}
	if(cnt<=1)
	{
		printf("0\n");
		return 0;
	}
	cnt=cnt-2;
	sort(poi,poi+N,cmp);
	for(int i=0;i<N;i++)
	{
		if(cnt<=0)
			break;
		if(poi[i].vis==false)
			ret+=1LL*poi[i].val,cnt--;
	}
	if(cnt>0)
		printf("Impossible\n");
	else
		printf("%lld\n",ret);
	return 0;
}
/*
7 4
1 2 3 4 5 6 7
3 0
4 0
1 2
5 6

*/

Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    int a,b;
    cin >> a >> b;
    string ope = "==";
    if (a > b) {
        ope = ">";
    } else if (a < b) {
        ope = "<";
    }
    cout << "a " + ope + " b" << endl;
    return 0;
}


Measured memory_bytes: 3172
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
int main(){
    string a;
    cin >> a;
    list<char> q;
    q.insert(q.begin(),a.begin(),a.end());
    int n;
    cin >> n;
    int t,f;
    char f2;
    int flag=1;
    while(n-->0){
        scanf("%d",&t);
        if(t==1)
            flag=-flag;
        else{
            scanf("%d",&f);
            getchar();
            scanf("%c",&f2);
        if(flag==1){
            if(f==1)
                q.push_front(f2);
            else
                q.push_back(f2);
        }
        else{
            if(f==1)
                q.push_back(f2);
            else
                q.push_front(f2);
        }
        }
    }

    string k;
    if(flag==1)
    k.insert(k.begin(),q.begin(),q.end());
    else
    k.insert(k.begin(),q.rbegin(),q.rend());
    cout << k;
    return 0;
}


Measured memory_bytes: 10368
const main = input => {
    const query = input.split('\n');
    const N = parseInt(query[0]);

    const memo = {
        'AC': 0,
        'WA': 0,
        'TLE': 0,
        'RE': 0,
    };

    for (let i = 1; i <= N; i++) {
        memo[query[i]]++;
    }

    console.log('AC', 'x', memo['AC']);
    console.log('WA', 'x', memo['WA']);
    console.log('TLE', 'x', memo['TLE']);
    console.log('RE', 'x', memo['RE']);
};


// 標準入力
main(require("fs").readFileSync("/dev/stdin", "utf8"));
// main(require("fs").readFileSync("input.txt", "utf8"));

Measured memory_bytes: 37232
#include<iostream>
#include<fstream>
#include<sstream>
#include<algorithm>
#include<cstdio>
#include<cctype>
#include<cassert>
#include<cmath>
#include<ctime>
#include<cstdlib>
#include<cstring>
#include<string>
#include<queue>
#include<vector>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<iomanip>
#include<utility>
using namespace std;
#define mp make_pair
#define pb push_back
#define X first
#define Y second
#define rg register
#define il inline
#define lch(x) ((x)<<1)
#define rch(x) ((x)<<1^1)
#define eprintf(...) fprintf(stderr,__VA_ARGS__)
#define rep0(i,n) for(register int i=0;i<(n);++i)
#define per0(i,n) for(register int i=(n)-1;i>=0;--i)
#define rep(i,st,ed) for(register int i=(st);i<=(ed);++i)
#define per(i,ed,st) for(register int i=(ed);i>=(st);--i)
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef double dbl;
typedef long double ldb;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<typename T> il T qmin(const T &a,const T &b){return a<b?a:b;}
template<typename T> il T qmax(const T &a,const T &b){return a>b?a:b;}
template<typename T> il void getmin(T &a,const T &b){if(a>b) a=b;}
template<typename T> il void getmax(T &a,const T &b){if(a<b) a=b;}
il void fileio(string s){
	freopen((s+".in").c_str(),"r",stdin);
	freopen((s+".out").c_str(),"w",stdout);
}

const int inf=(int)1e9+7;
const ll linf=(ll)1e17+7;
const int N=1e5+7;

int a[N],n,l;

int main(){
	scanf("%d%d",&n,&l);
	rep(i,1,n) scanf("%d",a+i);
	int pos=0;
	rep(i,1,n-1) if(a[i]+a[i+1]>=l){
		pos=i;
		break;
	} 
	if(!pos) return puts("Impossible"),0;
	puts("Possible");
	rep(i,1,pos-1) printf("%d\n",i);
	per(i,n-1,pos) printf("%d\n",i);
	return 0;
}


Measured memory_bytes: 1152
#include<bits/stdc++.h>
#define mov(i,a,b) for(int i = a; i < b; i++)
#define MOD 1000000007
#define INF 1e9+5
typedef long long ll;
using namespace std;
bool isPowerOfTwo(ll n){
	return (ceil(log2(n)) == floor(log2(n)));
}
long long binpow(long long a, long long b){
	long long res = 1;
	while(b>0){
		if(b&1) res *= a;
		a = a*a;
		b >>= 1;
	}
	return res;
}
bool sortbysec(const pair<int,int> &a, 
              const pair<int,int> &b) 
{ 
	bool x = false;
	if((a.second*a.first) < b.second*b.first){
		x = true;
	}
    return x;
}
int main(){
	
	
	int n,k;
	cin>>n>>k;
	string s;
	cin>>s;
	
	if(s[k-1] == 'A') s[k-1] = 'a';
	if(s[k-1] == 'B') s[k-1] = 'b';
	if(s[k-1] == 'C') s[k-1] = 'c';
	cout<<s<<"\n";
	
	
	
}









Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int a=scan.nextInt();
		int b=scan.nextInt();
		int c=scan.nextInt();
		int d=a-b;
		if(c-d>0) System.out.println(c-d);
		else System.out.println("0");

	}

}


Measured memory_bytes: 27076
#include<stdio.h>

int main(void){
    int n;
    int year, month, day;

    scanf("%d",&n);

    while(n > 0){
        scanf("%d %d %d", &year, &month, &day);

        int ans = 0;
        if(month % 2 != 0){
            ans += 21 - day;
        }
        else{
            if(year % 3 == 0){
                ans += 21 - day;
            }
            else{
                ans += 20 - day;
            }
        }
        if(month != 10){
            month++;
            if(year % 3 == 0){
                ans += (11 - month) * 20;
            }
            else{
                int i;
                for(i = month; i <= 10; i++){
                    if(i % 2 == 0){
                        ans += 19;
                    }
                    else{
                        ans += 20;
                    }
                }
            }
        }
        year++;
        int i;
        for(i = year; i < 1000; i++){
            if(i % 3 == 0){
                ans += 200;
            }
            else{
                ans += 195;
            }
        }

        printf("%d\n", ans);
        n--;
    }

    return 0;
}


Measured memory_bytes: 2112
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>

using namespace std;

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

int main() {
	int a, b;
	string op;
	cin >> a >> op >> b;
	if (op == "+") printf("%d\n", a + b);
	else printf("%d\n", a - b);
	return 0;
}

Measured memory_bytes: 256
N = int(input())
T,A = map(int,input().split())
H = list(map(int,input().split()))
d = {}
for x in H:
    d[x] = abs(A-(T-x*0.006))
counter = 1
counter_x = 1
min_ = 100000
for i in d.values():
    if(min_>=i):
        min_ = i
        counter_x = counter
    counter += 1
print(counter_x)

Measured memory_bytes: 9256
#include <cstdio>
#include <queue>
#include <vector>
#include <algorithm>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<string>
#include<map>
#include<set>
#include<cmath>
using namespace std;
#define ll long long
#define ull unsigned long long
#define INF 1e9
#define eps 1e-6
#define PI acos(-1.0)
#define M 10010
typedef pair<int, int> pii;
const int mod = 1e9 + 7;
const int maxn = 3e5 + 10;

int h,w;
int a[110][110];

int main() {
  //freopen("in.txt", "r", stdin);
  //freopen("out.txt","w",stdout);
  std::ios::sync_with_stdio(false);
  cin >> h >> w;
  for(int i = 0 ; i < h ; i++)
  {
     for(int j = 0 ;  j < w; j++)
     {
        char c;
        cin >> c;
        if(c == '.') a[i][j] = 1;
        else a[i][j] = 0;
     }
  }
  for(int i = 0 ; i < h ; ++i)
  {
     int flag = 1;
     for(int j = 0 ; j < w; j++)
     {
        if(!a[i][j]) 
        {
           flag = 0;
           break;
        }
     }
     if(flag)
     {
         for(int j = 0 ; j < w; j++)
           a[i][j] = -1;
     }


  }
  for(int i = 0 ; i < w ; ++i)
  {
     int flag = 1;
     for(int j = 0 ; j < h; j++)
     {
        if(!a[j][i]) 
        {
           flag = 0;
           break;
        }
     }
     if(flag)
     {
         for(int j = 0 ; j < h; j++)
           a[j][i] = -1;
     }
  }
  
  for(int i = 0 ; i < h;  ++i)
  {
    int flag = 0;
    for(int j = 0 ; j < w; j++)
    {
       if(a[i][j] == 1) 
        {
          cout << '.';
          flag = 1;
        }
       if(a[i][j] == 0) 
        {
          cout << '#';
          flag = 1;
        }
    }
    if(flag)cout << endl;
  }

  //system("pause");
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
static const long long mod = 1e9 + 7;
using namespace std;

int main() {
	int n;
	long long ans = 1;
	cin >> n;
	vector<int>a(n);
	for (int i = 0; i < n; ++i)cin >> a[i];
	sort(a.begin(), a.end());
	vector<int>b;
	if (n % 2 == 1) {
		for (int i = 0; i < n; ++i) {
			b.push_back(i + i % 2);
		}
	}
	else {
		for (int i = 0; i < n; ++i) {
			b.push_back(i + (i + 1) % 2);
		}
	}
	for (int i = 0; i < n; ++i) {
		if (a[i] != b[i]) {
			cout << "0" << endl;
			return 0;
		}
	}
	for (int i = 0; i < n/2; ++i) {
		ans *= 2;
		ans %=mod;
	}
	cout << ans<< endl;
	return 0;
}

Measured memory_bytes: 1276
import java.util.*;

public class Main{
	private static final Scanner scan = new Scanner(System.in);

	public static void main(String[] args){
		List<Integer> list = new ArrayList<Integer>();
		while(scan.hasNext()){
			int n = scan.nextInt();
			int cnt = 0;
			for(int a = 0; a <= 9; a++){
				for(int b = 0; b <= 9; b++){
					for(int c = 0; c <= 9; c++){
						for(int d = 0; d <= 9; d++){
							if(a + b + c + d == n){
								cnt++;
							}
						}
					}
				}
			}
			list.add(cnt);
		}

		for(int n : list){
			System.out.printf("%d\n", n);
		}
	}
}

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

#define endl '\n'
#define rep(i,n)       for(int i=0; i<n; i++)
#define clr(arr)       memset(arr, 0, sizeof arr)
#define all(x)         x.begin(), x.end()
const int MOD = 1e9 + 7;
#ifdef SMIT
template<class F, class S> ostream& operator<<(ostream &out, const pair<F, S> &p)
{
	return out << '(' << p.first << ", " << p.second << ')';
}
template<class T> auto operator<<(ostream &out, T &&x) -> decltype(x.begin(), out)
{
	out << '{';
	for (auto i = x.begin(); i != x.end(); i++)
		out << *i << (i == prev(x.end()) ? "" : ", ");
	return out << '}';
}
void dmp() {}
template<class T, class... Args> void dmp(T &&x, Args... args)
{
	cerr << x << ";  "; dmp(args...);
}
struct Nl {~Nl() {cerr << '\n';}};
#define debug(x...) cerr << (strcmp(#x, "") ? #x ":  " : ""), dmp(x), Nl(), cerr << ""
#else
#define debug(...) {}
#endif
// Yes you CAN
const int N = 3001;

string s, t, ans;
int n, m;
int dp[N][N];
int lcs(int i, int j)
{
	if (i == 0 or j == 0)
		return dp[i][j] = 0;
	if (dp[i][j] != -1)
		return dp[i][j];
	if (s[i - 1] == t[j - 1])
	{
		return dp[i][j] = 1 + lcs(i - 1, j - 1);
	}
	return dp[i][j] = max(lcs(i - 1, j), lcs(i, j - 1));
}
void solve()
{
// #define TEST
	cin >> s >> t;
	n = s.size(); m = t.size();
	memset(dp, -1, sizeof dp);
	int i = n, j = m;
	if (lcs(n, m))
	{
		while (i > 0 and j > 0)
		{
			if (s[i - 1] == t[j - 1])
			{
				// if (s[i - 2] == t[j - 2])
				ans = s[i - 1] + ans;
				i--;
				j--;
			}
			else if (dp[i - 1][j] > dp[i][j - 1])
				i--;
			else
				j--;
		}
	}
	cout << ans << endl;
}

int32_t main()
{
#ifdef SMIT
	freopen("/home/smit/Desktop/in.txt", "r", stdin);
#endif
	ios_base::sync_with_stdio(false); cin.tie(nullptr);

	int t = 1;
#ifdef TEST
	cin >> t;
#endif
	while (t--)
		solve();
}

Measured memory_bytes: 39148
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

typedef struct {
	int tate;
	int yoko;
} xy_t;

int qsort_comp(const void* x,const void* y) {
	const xy_t* a=(const xy_t*)x;
	const xy_t* b=(const xy_t*)y;
	if((a->tate)>(b->tate))return 1;
	if((a->tate)<(b->tate))return -1;
	if((a->yoko)>(b->yoko))return 1;
	if((a->yoko)<(b->yoko))return -1;
	return 0;
}

int yz_num,xz_num,xy_num;
xy_t yz[200];/* tate:z yoko:y */
xy_t xz[200];/* tate:z yoko:x */
xy_t xy[200];/* tate:x yoko:y */
int yz_pos[501][2];
int xz_pos[501][2];

int findit(const xy_t* from,int start,int end,int target) {
	int left,right,mid;
	left=start;right=end-1;
	while(left<=right) {
		mid=(left+right)/2;
		if(from[mid].yoko==target)return mid;
		else if(from[mid].yoko<target)left=mid+1;
		else right=mid-1;
	}
	return -1;
}

int main(void) {
	int i,j;
	int prev;
	int n,h;
	char type[4];
	int result,temp;
	while(1) {
		scanf("%d%d",&n,&h);
		if(n==0 && h==0)break;
		yz_num=xz_num=xy_num=0;
		for(i=0;i<h;i++) {
			int a,b;
			scanf("%s%d%d",type,&a,&b);
			if(type[0]=='x' && type[1]=='y') {
				xy[xy_num].tate=a;
				xy[xy_num].yoko=b;
				xy_num++;
			} else if(type[0]=='x' && type[1]=='z') {
				xz[xz_num].tate=b;
				xz[xz_num].yoko=a;
				xz_num++;
			} else if(type[0]=='y' && type[1]=='z') {
				yz[yz_num].tate=b;
				yz[yz_num].yoko=a;
				yz_num++;
			}
		}
		qsort(xz,xz_num,sizeof(xy_t),qsort_comp);
		qsort(yz,yz_num,sizeof(xy_t),qsort_comp);
		memset(xz_pos,0,sizeof(xz_pos));
		memset(yz_pos,0,sizeof(yz_pos));
		prev=0;
		for(i=0;i<xz_num;i++) {
			if(xz[prev].tate!=xz[i].tate) {
				xz_pos[xz[prev].tate][1]=i;
				xz_pos[xz[i].tate][0]=i;
				prev=i;
			}
		}
		xz_pos[xz[prev].tate][1]=i;
		prev=0;
		for(i=0;i<yz_num;i++) {
			if(yz[prev].tate!=yz[i].tate) {
				yz_pos[yz[prev].tate][1]=i;
				yz_pos[yz[i].tate][0]=i;
				prev=i;
			}
		}
		yz_pos[yz[prev].tate][1]=i;
		result=0;
		for(i=1;i<=n;i++) {
			temp=n*n;
			temp-=(xz_pos[i][1]-xz_pos[i][0])*n;
			temp-=(yz_pos[i][1]-yz_pos[i][0])*n;
			temp+=(xz_pos[i][1]-xz_pos[i][0])*(yz_pos[i][1]-yz_pos[i][0]);
			temp-=xy_num;
			for(j=0;j<xy_num;j++) {
				if(findit(xz,xz_pos[i][0],xz_pos[i][1],xy[j].tate)>=0 ||
					findit(yz,yz_pos[i][0],yz_pos[i][1],xy[j].yoko)>=0)temp++;
			}
			result+=temp;
		}
		printf("%d\n",result);
	}
	return 0;
}

Measured memory_bytes: 612
#include <algorithm>
#include <iostream>
#include <limits>
#include <map>
#include <set>
#include <vector>

int main() {
    int N, W;
    std::cin >> N >> W;

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

    // dp[i][j]: pick from the first i items, with j capacity
    std::vector<std::vector<long long>> dp(N + 1,
                                           std::vector<long long>(W + 1));
    for(int i = 1; i <= N; ++i) {
        for(int j = 1; j <= W; ++j) {
            dp[i][j] = dp[i - 1][j];
            if(j >= w[i - 1]) {
                dp[i][j] =
                    std::max(dp[i][j], v[i - 1] + dp[i - 1][j - w[i - 1]]);
            }
        }
    }

    std::cout << dp[N][W] << "\n";
}

Measured memory_bytes: 80256
#ifdef DEBUG

#else

#    pragma GCC optimize("O3,no-stack-protector")
#    pragma GCC optimize("unroll-loops")

#    if __cplusplus >= 201703L
#        pragma GCC target("avx2")
#    else
#        pragma GCC target("avx")
#    endif

#endif
// 実数の場合
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define dump(x) cout << x << endl
typedef int64_t Int;

using namespace std;
using Graph = vector<vector<Int>>;

const double pi = M_PI;
const Int MOD = 1000000007;

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

    Int L, R;
    cin >> L >> R;
    const Int mod = 2019;

    Int ans = INT64_MAX;
    R = min(L + mod, R);
    for (Int l = L; l <= R; l++) {
        for (Int r = l + 1; r <= R; r++) {
            ans = min(ans, l * r % mod);
        }
    }

    cout << ans << endl;

    return 0;
}


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

int main() {
    int n;
    std::cin >> n;
    std::vector<int> as(n);
    int max = 0, secondMax = 0;
    for (int i = 0; i < n; i++) {
        int a;
        std::cin >> a;

        as[i] = a;

        if (a >= max) {
            secondMax = max;
            max = a;
        } else if (a >= secondMax) {
            secondMax = a;
        }
    }

    for (int i = 0; i < n; i++) {
        int ans = (as[i] == max) ? secondMax : max;
        std::cout << ans << std::endl;
    }
}


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

int main() {
    long long N, M, K;
    cin >> N >> M >> K;
    vector <long long> A(N+1,0);     
    vector <long long> B(M);     
    for (long long i=0; i<N; i++) cin >> A.at(i+1);
    long long wat_b=0;
    long long anst_b=0;
    for (long long i=0; i<M; i++) {
        cin >> B.at(i);
        wat_b+=B.at(i);
        anst_b++;
    }
    long long ans=0;
    long long wat_a=0;
    long long anst_a=0;
    long long anst_b2=anst_b;
    for (long long i=0; i<=N; i++) {
        long long wat=0;
        long long anst=0;
        wat_a+=A.at(i);
        if (i!=0) anst_a++;
        if (wat_a<=K) {
            wat=wat_a;
            anst = anst_a;
            for (long long j=anst_b2-1; j>=0; j--) {
                if (wat+wat_b<=K) break;
                wat_b-=B.at(j);
                anst_b--;
            }
            anst_b2=anst_b;
            wat += wat_b; 
            anst += anst_b;
        }
        ans = max(ans, anst);
    }
    cout << ans << endl;
}

Measured memory_bytes: 6432
// Aizu 2440: Kagisys
// 2017.9.25 bal4u@uu

#include <stdio.h>
#include <string.h>

#define HASHSIZ 1009
typedef struct { char *s; } HASH;
HASH hash[HASHSIZ+2];				// Hash table

char name[260][12];

int insert(char *s, int w)
{
	int i = (101 * *s + 103 * *(s+w-1) + 107 * w) % HASHSIZ;
	HASH *tp;

	tp = hash + i;
	if (tp->s != NULL) {
		int inc = *s + (*(s + 1) << 1);
		while (1) {
			if (!memcmp(tp->s, s, w)) return 0;
			i += inc;
			if (i >= HASHSIZ) i -= HASHSIZ;
			tp = hash + i;
			if (tp->s == NULL) break;
		}
	}
	tp->s = s;
	return 1;
}

int lookup(char *s, int w)
{
	int i = (101 * *s + 103 * *(s+w-1) + 107 * w) % HASHSIZ;
	HASH *tp;

	tp = hash + i;
	if (tp->s != NULL) {
		int inc = *s + (*(s + 1) << 1);
		while (1) {
			if (!memcmp(tp->s, s, w)) return 1;
			i += inc;
			if (i >= HASHSIZ) i -= HASHSIZ;
			tp = hash + i;
			if (tp->s == NULL) break;
		}
	}
	return 0;
}

int main()
{
	int n, m, i, k, open;
	char str[15], *p;
	char *msg[3] = { "Closed by %s", "Opened by %s", "Unknown %s" };

	scanf("%d", &n);
	for (i = 0; i < n; i++) {
		scanf("%s", p = name[i]);
		insert(p, strlen(p));
	}
	scanf("%d", &m);
	open = 0;
	while (m-- > 0) {
		scanf("%s", str);
		if (!lookup(str, strlen(str))) k = 2;
		else open = !open, k = open;
		printf(msg[k], str);
		putchar('\n');
	}
	return 0;
}

Measured memory_bytes: 1852
#include<bits/stdc++.h>
using namespace std;
#define N 1111116
#define mod 1000000007
#define next nxt

int n,x[N],y[N],z[N],next[N],p[N],h[N],g[N],s[N],cnt,cmt,cir;
long long fac[N],inv[N],f[N],ans;

long long C(int x,int y){
	return fac[x]*inv[y]%mod*inv[x-y]%mod;
}

long long solve(int x,int pre){
	f[x]=1;s[x]=0;long long ans=1;
	for (int t=p[x];t;t=next[t])
		if (t/2!=pre/2&&t/2!=cir/2){
			ans=ans*solve(y[t],t)%mod;
			if (z[t]>z[pre]) ans=ans*inv[s[y[t]]]%mod*f[y[t]]%mod;
			else s[x]+=s[y[t]],f[x]=f[x]*f[y[t]]%mod*C(s[x],s[y[t]])%mod;
		}
	s[x]++;return ans;
}

void travel(int x,int pre){
	h[x]=true;cnt++;
	for (int t=p[x];t;t=next[t],cmt++)
		if (!h[y[t]]) g[y[t]]=t,travel(y[t],t);
		else if (t/2!=pre/2) cir=t;
}

int read(){
	int x=0,f=1;char ch=getchar();
	for (;!isdigit(ch);ch=getchar()) if (ch=='-')  f=-f;
	for (;isdigit(ch);ch=getchar()) x=x*10+ch-'0';
	return x*f;
}

int main(){
	n=read();
	for (int i=1;i<=2*n;i++){
		x[2*i]=y[2*i+1]=read();
		y[2*i]=x[2*i+1]=n+read();
		z[2*i]=z[2*i+1]=x[2*i]+y[2*i];
		next[2*i]=p[x[2*i]];p[x[2*i]]=2*i;
		next[2*i+1]=p[x[2*i+1]];p[x[2*i+1]]=2*i+1;
	}
	fac[0]=fac[1]=inv[0]=inv[1]=1;
	for (int i=2;i<N;i++) fac[i]=fac[i-1]*i%mod;
	for (int i=2;i<N;i++) inv[i]=-(mod/i)*inv[mod%i]%mod;
	for (int i=2;i<N;i++) inv[i]=inv[i-1]*inv[i]%mod;
	ans=fac[2*n];
	for (int i=1;i<=2*n;i++)
		if (!h[i]){
			cnt=cmt=0;travel(i,0);
			if (cmt!=cnt*2) {printf("0\n");return 0;}
			for (int u=y[cir],v=x[cir];u!=v;u=x[g[u]])
				if (z[g[u]]>z[cir]) cir=g[u];
			long long tmp1=solve(y[cir],cir)*inv[s[y[cir]]]%mod*f[y[cir]]%mod;
			long long tmp2=solve(x[cir],cir)*inv[s[x[cir]]]%mod*f[x[cir]]%mod;
			ans=ans*(tmp1+tmp2)%mod;
		}
	printf("%lld\n",(ans+mod)%mod);
	return 0;
}

Measured memory_bytes: 50176
#include <iostream>
#include <algorithm>
#include <cstring>

using namespace std;


int main(){
    int health1, health2;
    int str1, str2;
    cin >> health1 >> str1;
    cin >> health2 >> str2;
    bool is_win;
    while(true){
        health2 -= str1;
        if(health2 <= 0){
            is_win = true;
            break;
        }
        health1 -= str2;
        if(health1 <= 0){
            is_win = false;
            break;
        }
    }
    if(is_win){
        cout << "Yes\n";
    }
    else{
        cout << "No\n";
    }
}

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

#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
typedef long long ll;

const long long INF = 1LL << 60;

int main()
{
    int A, B;
    cin >> A >> B;

    if (A <= 8 && B <= 8) cout << "Yay!" << endl;
    else cout << ":(" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stdio.h>
#include <string>
#include <vector>

#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using LP = pair<ll, ll>;
const double PI = 3.1415926535897932;

int main()
{
	int X;
	cin >> X;
	if (X >= 30) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;

	}
	return 0;
} 

Measured memory_bytes: 3620
#include<iostream>
#include<algorithm>
using namespace std;
long A[300][300];
int n;
long all;
bool f[300][300];
main()
{
	cin>>n;
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<n;j++)
		{
			cin>>A[i][j];
		}
	}
	for(int k=0;k<n;k++)
	{
		for(int i=0;i<n;i++)
		{
			for(int j=0;j<n;j++)
			{
				if(A[i][k]+A[k][j]<A[i][j])
				{
					cout<<-1<<endl;
					return 0;
				}
				f[i][j]|=A[i][k]+A[k][j]==A[i][j]&&i!=k&&j!=k;
			}
		}
	}
	for(int i=0;i<n;i++)for(int j=i;j<n;j++)
	{
		all+=(!f[i][j])*A[i][j];
	}
	cout<<all<<endl;
}


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

int main(){
  int n; cin >> n;
  int a[n],b[n],c[n-1];
  
  for(int i=0; i<n; i++){
    cin >> a[i];
  }
  
  int sum = 0;
  for(int i=0; i<n; i++){
    cin >> b[i]; sum = sum + b[i];
  }
  
  for(int i=0; i<n-1; i++){
    cin >> c[i];
  }
  
  for(int i=0; i<n-1; i++){
    if(a[i+1]==(a[i]+1)){
      sum = sum + c[a[i]-1];
    }
  }
  
  cout << sum;
  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define vout(x) rep(i,x.size()) cout << x[i] << " "
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return 1;}return 0;}
using namespace std;
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int,int>;
const int inf = 1e9;
const ll inf_l = 1LL<<62;
const int MAX = 1e5;

int main() {
    int n; cin >> n;
    bool ok = false;
    while (n > 0) {
        if (n % 10 == 9) ok = true;
        n /= 10;
    }
    printf(ok?"Yes\n":"No\n");
}

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

# define x first    
# define y second
# define mp make_pair
// everything go according to my plan      
# define pb push_back
# define sz(a) (int)(a.size())
# define vec vector         
// shimkenttin kyzdary, dzyn, dzyn, dzyn...
# define y1    Y_U_NO_y1
# define left  Y_U_NO_left
# define right Y_U_NO_right  

using namespace std;

typedef pair <int, int> pii; 
typedef long long ll;
typedef long double ld;

const int Mod = (int)1e9 + 7;
const int MX = 1073741822;
const ll MXLL = 4e18;
const int Sz = 1110111;
// a pinch of soul
inline void Read_rap () {
  ios_base :: sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
}
inline void randomizer3000 () {
  unsigned int seed;
  asm ("rdtsc" : "=A"(seed));
  srand (seed);
}
void files (string problem) {   
  if (fopen ((problem + ".in").c_str(),"r")) {
    freopen ((problem + ".in").c_str(),"r",stdin);
    freopen ((problem + ".out").c_str(),"w",stdout);
  }
}
void localInput(const char in[] = "s") { 
  if (fopen (in, "r")) {
    freopen (in, "r", stdin);
  }
  else
    cerr << "Warning: Input file not found" << endl;
}
int n;

int a[Sz];
                    
int main()
{
  # ifdef Local
    //localInput();
  # endif
  Read_rap();
  cin >> n;
  for (int i = 1; i <= n; i++)
    cin >> a[i];
          
  int N = *max_element (a + 1, a + n + 1);
  int R = 0;
  int mn = MX;
  int mx = -1;
  sort (a + 1, a + n + 1);
  for (int i = 1; i <= n; i++) {
    int val = (a[i] <= N/2 ? a[i] : N - a[i]);
    if (mx < val) {
      R = a[i];
      mx = val;
    }           
  }
  cout << N << ' ' << R;                          


  return 0;
}






// Coded by Z..



Measured memory_bytes: 640
#include<bits/stdc++.h>
#define int long long
using namespace std;
char s[200010];
int num[30],ans;
main(){
	cin>>s+1;
	for (int i=1;i<=strlen (s+1);i++) 
	ans+=num[s[i]-'a'],num[s[i]-'a']++;
	printf ("%lld",strlen(s+1)*(strlen(s+1)-1)/2-ans+1);
}

Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <stack>
#include <deque>
#include <cmath>
#include <map>
using ll = long long;
using namespace std;

int main() {
  int n;
  cin >> n;
  int ans = 0;
  for (int i = 0; i < n; i++) {
    int l, r;
    cin >> l >> r;
    ans += r - l + 1;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
# encoding: utf-8


import sys


class Solution:
    def __init__(self):
        """
        init input array
        """
        self.__input = sys.stdin.readlines()

    @property
    def solution(self):
        length_1 = int(self.__input[0])
        array_1 = list(map(int, self.__input[1].split()))
        length_2 = int(self.__input[2])
        array_2 = list(map(int, self.__input[3].split()))

        assert length_1 == len(array_1) and length_2 == len(array_2)

        count = 0
        for each in array_2:
            if self.linear_search(key=each, array=array_1, array_length=length_1):
                count += 1

        return str(count)

    @staticmethod
    def linear_search(key, array, array_length):
        # print(len(set(array_1).intersection(set(array_2))))
        for i in range(array_length):
            if array[i] == key:
                return True
        return False


if __name__ == '__main__':
    case = Solution()
    print(case.solution)

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

#define INX(x) (cin >> x)
#define INXV(vec, cnt) for(ll i; i < cnt; i++) INX(vec[i])
#define OUTX(x) (cout << x << endl)
#define OUTXV(vec) for(ll i; i < (ll)vec.size(); i++) OUTX(vec[i])

#define ADD emplace_back
#define MP make_pair
#define VVEC(type) vector<vector<type>>

#define MAXNUM 1000001 //10^6 + 1

int main()
{
    ll N;
    INX(N);

    vector<ll> A(N);
    for (ll i = 0; i < N; i++)
    {
        INX(A[i]);
    }
    
    bool dp[MAXNUM];
    for (ll i = 0; i < MAXNUM; i++)
    {
        dp[i] = true;
    }
    
    sort(A.begin(), A.end());

    ll prev = 0;
    ll continuecount = 0;
    for (ll i = 0; i < N; i++)
    {
        if(A[i] == prev)
        {
            if(continuecount++ == 0)
            {
                dp[A[i]] = false;
            }
            continue;
        }
        continuecount = 0;
        
        ll tmp = A[i] + A[i];
        while(tmp <= MAXNUM)
        {
            dp[tmp] = false;
            tmp += A[i];
        }
        prev = A[i];
    }
    
    ll result = 0;
    for (ll i = 0; i < N; i++)
    {
        if(dp[A[i]])
        {
            result++;
        }
    }
    OUTX(result);
    

    return 0;
}


Measured memory_bytes: 5896
#include <iostream>
#include <vector>
#include <cstdio>
#include <queue>
#include <algorithm>
#include <functional>
#include <string>
#include <queue>
#include <cmath>
#include <iomanip>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <random>
#include <unordered_map>
#include <unordered_set>
#define ll long long
#define fr(i,k,N) for(ll i=k; i<N;i++)
#define rep(i,N) for(ll i=0; i<N;i++)
#define alll(v) v.begin(),v.end()
using namespace std;
template <class X> void pr(X test){cout<<test<<endl;}
template <class X> void prr(X test){for(auto it:test){cout<<it<<endl;}cout<<endl;}

int main() {
    ll n,m;
    cin >>n>>m;
    vector<pair<ll,ll>> v;
    rep(i, n){
        ll a,b;
        cin>>a>>b;
        v.push_back(make_pair(a,b));
    }
    auto comp = []( pair<ll,ll> a, pair<ll,ll> b ) { return a.first < b.first; };
    sort(v.begin(), v.end(), comp);
    ll sum = 0;
    for(auto it:v){
        if (it.second >= m){
            while(m>0){
                m--;
                sum+=it.first;
            }
        }else{
            m -= it.second;
            sum+= it.first * it.second;
        }
    }
    pr(sum);
    return 0;
}



Measured memory_bytes: 2420
package main

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

/*
var sc = bufio.NewScanner(os.Stdin) exceed MaxScanTokenSize
func read() string {
    sc.Scan()
    return sc.Text()
}
*/

var rdr = bufio.NewReaderSize(os.Stdin, 1000000)

func readLine() string {
    buf := make([]byte, 0, 1000000)
    for {
        l, p, e := rdr.ReadLine()
        if e != nil {
            panic(e)
        }
        buf = append(buf, l...)
        if !p {
            break
        }
    }
    return string(buf)
}

func toInt(str string) int {
    n, _ := strconv.Atoi(str)
    return n
}

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

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

func main() {
    nm := strings.Split(readLine(), " ")
    n := toInt(nm[0])
    var infoDist [100000]int
    for i := 0; i < n; i++ {
        infoDist[i] = 100000
    }
    haveInfo := strings.Split(readLine(), " ")
    for _, value := range haveInfo {
        infoDist[toInt(value) - 1] = 0
    }

    for i := 0;i < n - 1; i++ {
        infoDist[i + 1] = min(infoDist[i] + 1, infoDist[i + 1])
    }

    for i := n - 1;i > 0; i-- {
        infoDist[i - 1] = min(infoDist[i] + 1, infoDist[i - 1])
    }

    ans := 0
    for i := 0;i < n;i++ {
        ans = max(ans, infoDist[i])
    }

    fmt.Println(max(ans, infoDist[0]))

}


Measured memory_bytes: 4180
#include<bits/stdc++.h>
using namespace std;
#define il inline
#define ll long long
#define outy printf("Yes\n")
#define outn printf("No\n")
#define outf printf("First\n")
#define outs printf("Second\n")
#define FOR(a,b,c) for(int a=b;a<=c;a++)
#define FORD(a,b,c) for(int a=b;a>=c;a--)
#define FORL(a,b) for(int a=head[b];a;a=nxt[a])
#define in(a)  a=read()
#define in2(a,b)  in(a),in(b)
#define in3(a,b,c)  in2(a,b),in(c)
#define in4(a,b,c,d)  in2(a,b),in2(c,d)
#define out(a) printf("%d\n",a)
#define out2(a,b) printf("%d %d\n",a,b)
#define out3(a,b,c) printf("%d %d %d\n",a,b,c)
#define out4(a,b,c,d) printf("%d %d %d %d\n",a,b,c,d)
#define outl(a) printf("%lld\n",a)
#define outl2(a,b) printf("%lld %lld\n",a,b)
#define outl3(a,b,c) printf("%lld %lld %lld\n",a,b,c)
#define outl4(a,b,c,d) printf("%lld %lld %lld %lld\n",a,b,c,d)
#define clr(x,y) memset(x,y,sizeof(x))
ll read(){
    ll f=1,x=0;char c=getchar();
    while(c>'9'||c<'0'){if(c=='-')f=-1;c=getchar();}
    while(c>='0'&&c<='9')x=x*10+c-'0',c=getchar();
    return x*f;
}
/*------------------------------------------------------------*/
#define mod 1000000007
#define maxn 200010
#define inf 0x7fffffff
/*------------------------------------------------------------*/
int n;ll m;
struct node{ll x,y;}a[maxn*2];
ll dp[maxn*2],f[maxn],q[maxn];
bool cmp(node a,node b){return a.x<b.x;}
int main(){
	in2(n,m);
	FOR(i,1,n)in2(a[i].x,a[i].y);
	sort(a+1,a+n+1,cmp);
//	sort(a+n+1,a+n*2+1,cmp);
	ll ans=0,ans2=0;
	FOR(i,1,n){
		dp[i]=dp[i-1]-(a[i].x-a[i-1].x)+a[i].y;
//		outl(a[i].x-a[i-1].x);
		ans=max(ans,dp[i]);
		f[i]=max(f[i-1],dp[i]-a[i].x);
		q[i]=max(q[i-1],dp[i]);
	}
//	out(ans);
//	int c=0;
//	FOR(i,1,n){
//		if(dp[i-1]-(a[i].x-a[i-1].x)<0){
//			dp[i]=dp[i-1]-(a[i].x-a[i-1].x)+a[i].y;
//		}
//		 else dp[i]=a[i].y,c=i;
//		ans2=max(ans2,sum-(a[c-1].x+m-a[i+1].x)-dp[i]);
//	}
	
	a[n+1].x=m;
	ans=max(ans,f[n]); 
	FORD(i,n,1){
		dp[i]=dp[i+1]-(a[i+1].x-a[i].x)+a[i].y;
		ans=max(ans,dp[i]);
		ans=max(ans,dp[i]+f[i-1]);
		ans=max(ans,dp[i]-(m-a[i].x)+q[i-1]); 
	}
	outl(ans);
}


Measured memory_bytes: 5632
package main

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

const mod = 1000000007

// 1MB
const ioBufferSize = 1 * 1024 * 1024
var sc = func() *bufio.Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Buffer(make([]byte, ioBufferSize), ioBufferSize)
	sc.Split(bufio.ScanWords)
	return sc
}()

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

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	a, b := nextInt(), nextInt()
	count := 0

	for plug := 1; plug < b; plug += a-1 {
		count++
	}

	fmt.Println(count)
}

Measured memory_bytes: 640
n,d=map(int,input().split())
x=[[0]*d]*n
for i in range(n):
    x[i]=list(map(int,input().split()))
z = 0
for i in range(n-1):
    for j in range(i+1,n):
        s = 0
        for a in range(d):
            s += (x[i][a] - x[j][a])**2
        s = s**0.5
        if s == int(s):
            z += 1
print(z)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (int)(k); i < (int)(n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) a.begin(), a.end()
#define MS(m,v) memset(m,v,sizeof(m))
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
const int MOD = 1e9 + 7;
template<class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<class T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template<class T>
istream& operator >> (istream& is, vector<T>& v)
{
	for (auto &i : v) is >> i;
	return is;
}
template<class T>
ostream& operator<<(ostream& os, vector<T>& v)
{
	const string delimiter = "\n";
	REP(i, v.size())
	{
		os << v[i];
		if (i != v.size() - 1) os << delimiter;
	}
	return os;
}
/*--------------------template--------------------*/

typedef int Weight;
struct Edge
{
	int from, to; Weight cost;
	bool operator < (const Edge& e) const { return cost < e.cost; }
	bool operator > (const Edge& e) const { return cost > e.cost; }
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
typedef vector<Weight> Array;
typedef vector<Array> Matrix;
void add_edge(Graph &g, int from, int to, Weight cost)
{
	g[from].push_back(Edge{ from, to, cost });
}
const int INF = 1e9;
void dijkstra(Graph &g, int s, Array &d)
{
	d.assign(g.size(), INF);
	d[s] = 0;
	typedef pair<Weight, int> P;
	priority_queue<P, vector<P>, greater<P>> que;
	que.push(P(0, s));
	while (!que.empty())
	{
		Weight dist = que.top().first;
		int v = que.top().second;
		que.pop();
		if (d[v] < dist) continue;
		REP(i, g[v].size())
		{
			Edge e = g[v][i];
			if (d[e.to] > d[v] + e.cost)
			{
				d[e.to] = d[v] + e.cost;
				que.push(P(d[e.to], e.to));
			}
		}
	}
}


int main()
{
	cin.sync_with_stdio(false); cout << fixed << setprecision(10);
	int n, m, k;
	cin >> n >> m >> k;
	vi dark, id(n, -1);
	REP(i, m)
	{
		int a; cin >> a;
		a--;
		dark.push_back(a);
		id[a] = i;
	}
	Graph g(n);
	REP(i, n)REP(j, k)
	{
		int a; cin >> a; a--;
		add_edge(g, i, a, 0);
	}
	Graph h(1 << m);
	REP(bit, 1 << m)
	{
		vi v;
		REP(i, m)
		{
			if ((bit >> i) & 1) v.push_back(dark[i]);
		}
		REP(i, k)
		{
			int nex = 0;
			REP(j, v.size())
			{
				int u = g[v[j]][i].to;
				if (id[u] == -1) continue;
				nex |= (1 << id[u]);
			}
			add_edge(h, bit, nex, 1);
		}
	}
	Array dist;
	dijkstra(h, (1 << m) - 1, dist);
	cout << dist[0] << endl;
	return 0;
}


Measured memory_bytes: 104860
#include <stdio.h>
using namespace std;

int n;
const int size = 100005;
int a[size];
int main()
{
    scanf("%d",&n);
    for(int i = 1 ; i <= n ; i++)
    {
        int temp;
        scanf("%d",&temp);
        a[temp] = i;
    }
    for(int i = 1 ; i <= n ; i++)
    {
        printf("%d ",a[i]);
    }
    printf("\n");
    return 0;
}

Measured memory_bytes: 1152
from heapq import heapify, heappush, heappop
import sys
input = sys.stdin.readline

Q = int(input())
querys = [tuple(map(int, input().split())) for _ in range(Q)]

anss = []
PQL, PQR = [], []
sumL = sumR = 0
numL = numR = 0
sumB = 0
for query in querys:
    if query[0] == 1:  # 更新
        a, b = query[1:]
        sumB += b
        if numL == 0:
            heappush(PQL, -a)
            sumL += a
            numL += 1
        elif numL == numR:
            if a <= -PQL[0]:
                heappush(PQL, -a)
                sumL += a
                numL += 1
            else:
                heappush(PQR, a)
                c = heappop(PQR)
                sumR += a-c
                heappush(PQL, -c)
                sumL += c
                numL += 1
        else:
            if a < -PQL[0]:
                heappush(PQL, -a)
                c = -heappop(PQL)
                sumL += a-c
                heappush(PQR, c)
                sumR += c
                numR += 1
            else:
                heappush(PQR, a)
                sumR += a
                numR += 1

    else:  # 求値
        x = -PQL[0]
        fx = numL*x - sumL + sumR - numR*x + sumB
        anss.append((x, fx))

print('\n'.join(map(lambda x: str(x[0])+' '+str(x[1]), anss)))


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

public class P
{
    public int from { get; set; }
    public int to { get; set; }
    public bool watched { get; set; }
}

public class Hello
{
    public static void Main()
    {
        var n = int.Parse(Console.ReadLine().Trim());
        var mo = new List<int>[32];
        for (int i = 1; i <= 31; i++) mo[i] = new List<int>();
        var ps = new P[n];
        for (int i = 0; i < n; i++)
        {
            string[] line = Console.ReadLine().Trim().Split(' ');
            var a = int.Parse(line[0]);
            var b = int.Parse(line[1]);
            for (int j = a; j <= b; j++) mo[j].Add(i);
            ps[i] = new P { from = a, to = b };
        }
        var ret = getAns(ps, mo);
        Console.WriteLine(100 * ret + 50 * (31 - ret));

    }
    public static int getAns(P[] ps, List<int>[] mo)
    {
        var count = 0;
        for (int i = 1; i <= 31; i++)
        {
            var wlist = new List<int>();
            foreach (var x in mo[i])
                if (!ps[x].watched) wlist.Add(x);
            if (wlist.Count() == 1) { count++; ps[wlist[0]].watched = true; }
            else if (wlist.Count() > 1)
            {
                var a = getMovie(wlist, ps);
                count++;
                ps[a].watched = true;
            }
        }
        return count;
    }
    public static int getMovie(List<int> a, P[] ps)
    {
        var tomin = ps[a[0]].to;
        var ret = a[0];
        for (int i = 1; i < a.Count(); i++)
            if (ps[a[i]].to < tomin) { tomin = ps[a[i]].to; ret = a[i]; }
        return ret;
    }
}


Measured memory_bytes: 9592
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define x first
#define y second

using namespace std;

typedef long long ll;

int main()
{
 	//freopen("input.txt", "r", stdin);
 	//freopen("output.txt", "w", stdout);
 	ios_base::sync_with_stdio(0); cin.tie(0);
 	string s;
 	cin >> s;
 	bool fl = ((int) s.length() % 2 == 0);
 	for (int i = 0; i < (int) s.length(); i++)
 	{
 	 	if (i % 2 == 0)
 	 	{
 	 		if (s[i] != 'h') fl = false;
 	 	}
 	 	else
 	 	{
 	 	 	if (s[i] != 'i') fl = false;
 	 	}
 	}
 	if (!fl) cout << "No\n";
 	else cout << "Yes\n";
 	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstddef>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

// clang-format off
template <typename T> T gcd(T a, T b) { return b == 0 ? a : gcd(b, a % b); }
template <typename T> T lcm(T a, T b) { return a * b / gcd(a, b); }
template <typename T> T clamp(T val, T min, T max) { return val < min ? min : (max < val ? max : val); }
template <typename T> size_t max_index(T begin, T end) { return distance(begin, max_element(begin, end)); }
template <typename T> size_t min_index(T begin, T end) { return distance(begin, min_element(begin, end)); }
// clang-format on

#define int long long
#define YES "Yes"
#define NO  "No"

using namespace std;

signed main(void) {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);

  int num = 0;

  int a, b, t;
  cin >> a >> b >> t;

  for (int i = 1; i <= t; ++i) {
    if (i % a == 0) num += b;
  }

  cout << num << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
using namespace std;
const int maxx=10010;

vector<int> A[maxx],ans;
queue<int> task;
int f[maxx];
bool flag[maxx];
int v,e;

int main (){
	int x,y;
	bool xx=false;
	cin>>v>>e;
	for(int i=0;i<maxx;i++){
		f[i]=0;
		flag[i]=false;
	}
	while(e--){
		cin>>x>>y;
		A[x].push_back(y);
		f[y]++;
	}
	while(1){
		xx=false;
		for(int i=0;i<v;i++) {
			if(f[i]==0&&flag[i]==false) {
				xx=true;
				task.push(i);
			}
		}
		if(xx==false) break;
		while(task.empty()==0){
			x=task.front();
			flag[x]=true;
			ans.push_back(x);
			for(int k=0;k<A[x].size();k++){
				f[A[x][k]]--;
			}
			task.pop();
		}
	}
	for(int i=0;i<ans.size();i++){
		cout<<ans[i]<<endl;
	}
	return 0;
	
	
}


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

const int MOD=1000000007;
const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;



int h,w; 
int sx,sy;

char maze[1000][1000];
int  dist[1000][1000];

int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};

void bfs(){
  queue<P> que;
  rep(i,h){
    rep(j,w){
      if(maze[i][j]=='#'){
        dist[i][j]=0;
        que.push(P(i,j));     
      }      
      else dist[i][j]=-1;
    }
  }
  
  while(que.size()){
    P p=que.front(); que.pop();
    rep(i,4){
      int ny=p.first+dy[i], nx=p.second+dx[i];
      if(0<=nx && nx<w && 0<=ny && ny<h && maze[ny][nx]=='.' && dist[ny][nx]==-1){
        que.push(P(ny,nx));
        dist[ny][nx]=dist[p.first][p.second]+1;
      }
    }
  }
}
int main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  
  cin>>h>>w;
  rep(i,h){
    rep(j,w){
      cin>>maze[i][j];
    }
  }
  bool can=false;
  rep(i,h){
    rep(j,w){
      if(maze[i][j]=='#'){
        sx=j,sy=i;
        bfs();
        can=true;
        break;
      }
    }
    if(can) break;
  }
  int ans=-1;
  rep(i,h){
    rep(j,w){
      if(ans<dist[i][j]) ans=dist[i][j];
    }
  }
  cout<<ans<<endl;
}
  



Measured memory_bytes: 13328