akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define for_bitset(variable, bitset) for (variable = bitset._Find_first(); variable != N; variable = bitset._Find_next(variable))

const int N = 2054, M = 2000054;
typedef std::bitset <N> bitset;

int V, E, h, t = 0;
bitset G[N], subtree[N], path[N];
bitset ALL, allow[M], Gr[N];
int p[N], S[N], lca[N][N];
int que[M];

inline void addedge(int u, int v) {G[u].set(v), G[v].set(u);}

inline void link(int x, int y) {Gr[x].set(y), Gr[y].set(x), que[t++] = x << 16 | y;}

void dfs(int x) {
	int u, v, y; path[x].set(x), subtree[x].set(x);
	for_bitset(y, G[x]) if (y != p[x]) {
		p[y] = x, path[y] = path[x], dfs(y);
		for_bitset(u, subtree[x])
			for_bitset(v, subtree[y])
				lca[u][v] = lca[v][u] = x;
		subtree[x] |= subtree[y];
	}
	G[x].reset(p[x]);
}

inline void direct_path(bitset &r, int top, int bottom) {
	int la = (G[top] & path[bottom])._Find_first();
	r = subtree[bottom], r |= path[bottom], r |= ~subtree[la], r &= ALL;
}

int main() {
	int i, u, v, w; bitset can;
	scanf("%d%d", &V, &E), S[1] = -1;
	for (i = 1; i < V; ++i) scanf("%d%d", &u, &v), addedge(u, v), S[i + 1] = S[i] + i - 1;
	for (i = 1; i <= V; ++i) ALL.set(i);
	dfs(1), i = 0;
	for (u = 1; u <= V; ++u)
		for (v = 1; v < u; ++v, ++i) {
			bitset &r = allow[i];
			if (w = lca[u][v], w == u || w == v) direct_path(r, w, w ^ u ^ v);
			else
				r = subtree[u], r |= path[u],
				r |= subtree[v], r |= path[v], r &= ~path[p[w]];
		}
	for (i = 0; i < E; ++i) scanf("%d%d", &u, &v), link(u, v);
	for (h = 0; h < t; ++h) {
		u = que[h] >> 16, v = que[h] & 65535;
		if (u > v) std::swap(u, v); w = S[v] + u;
		can = allow[w], can &= Gr[u], can &= ~Gr[v], can.reset(v);
		for_bitset(i, can) link(i, v);
		can = allow[w], can &= Gr[v], can &= ~Gr[u], can.reset(u);
		for_bitset(i, can) link(i, u);
	}
	printf("%d\n", t);
	return 0;
}

Measured memory_bytes: 542464
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>

typedef long long ll;
const int N=1010,M=2020,MOD=1000000007;
ll qpow(ll a,ll b){ll c=1;for(;b;b>>=1,a=a*a%MOD)if(b&1)c=c*a%MOD;return c;}

struct dus
{
	int q[N];
	void reset(int n){for(int i=1;i<=n;i++)q[i]=i;}
	int ask(int p){return p==q[p]?p:q[p]=ask(q[p]);}
	bool uni(int u,int v){return ask(u)==ask(v);}
	void link(int u,int v){q[ask(u)]=ask(v);}
}d;

struct edge
{
	int u,v,w;
	edge(int u0=0,int v0=0,int w0=0):u(u0),v(v0),w(w0){}
	bool operator < (const edge &A)const {return w<A.w;}
};

int begin[N],next[M],to[M],w[M];
int n,m,e;
ll wmst,lim;

void add(int x,int y,int z,bool k=1)
{
	to[++e]=y;
	next[e]=begin[x];
	begin[x]=e;
	w[e]=z;
	if(k)add(y,x,z,0);
}

int dis[N][N];

void dfs(int p,int h)
{
	for(int i=begin[p],q;i;i=next[i])
		if(dis[h][q=to[i]]==0)
			dis[h][q]=std::max(dis[h][p],w[i]),dfs(q,h);
}


edge E[M],_E[M];
int tot;

int cnt0,cnt1;

void work_counter()
{
	cnt0=cnt1=0;
	for(int i=1;i<=tot;i++)
	{
		ll x=_E[i].w-dis[_E[i].u][_E[i].v];

		if(wmst+x==lim)cnt0++;
		else if(wmst+x>lim)cnt1++;
	}
}

int main()
{
	scanf("%d%d%lld",&n,&m,&lim);
	for(int i=1,u,v,h;i<=m;i++)
		scanf("%d%d%d",&u,&v,&h),E[i]=edge(u,v,h);
	std::sort(E+1,E+m+1);
	d.reset(n),wmst=0;
	for(int i=1;i<=m;i++)
		if(!d.uni(E[i].u,E[i].v))add(E[i].u,E[i].v,E[i].w),d.link(E[i].u,E[i].v),wmst+=E[i].w;
		else _E[++tot]=E[i];

	if(lim<wmst){printf("0\n");return 0;}

	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++)
			dis[i][j]=0;
	for(int i=1;i<=n;i++)
		dis[i][i]=-1,dfs(i,i);

	work_counter();

	int ans=2ll*(qpow(2,cnt0)-1)%MOD*qpow(2,cnt1)%MOD;
	if(lim==wmst)ans=(ans+(qpow(2,n-1)-2)*qpow(2,m-n+1)%MOD)%MOD;

	ans=(ans+MOD)%MOD;
	printf("%d\n",ans);

	return 0;
}


Measured memory_bytes: 4352
#include<iostream>
#include<cstdio>
#include<vector>
using namespace std;
long long int dp[100][21];
int main(){
  int n;
  vector<int> lot;
  cin >>n;
  for(int i=0,a; i<n; i++){cin >>a; lot.push_back(a);}
  dp[0][lot[0]] = 1;
  for(int i=1; i<n-1; i++){
    for(int j=0; j<21; j++){
      if(j-lot[i]>=0) dp[i][j-lot[i]]+=dp[i-1][j];
      if(j+lot[i]<=20) dp[i][j+lot[i]]+=dp[i-1][j];
    }
  }
  cout <<dp[n-2][lot[n-1]]<<endl;
  return 0;
}

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

int main()
{
  int n, m;
  cin >> n >> m;
  int n1 = (n + 1) / 0.08;
  //int m1 = (m + 1) / 0.10;
  vector<int> v8;
  for (int i=n1; i>0; --i) {
    int x = i * 0.08;
    if (x == n) v8.push_back(i);
  }
  if (v8.size() == 0) {
    cout << -1 << endl;
    return 0;
  }
  int ans = -1;
  for (int i=0;i<(int)v8.size();++i) {
    int tmp = v8.at(i) * 0.10;
    if (tmp == m) {
      ans = v8.at(i);
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
# include <cstdio>
# include <cstring>
# include <cstdlib>
# include <iostream>
# include <vector>
# include <queue>
# include <stack>
# include <map>
# include <bitset>
# include <set>
# include <cmath>
# include <algorithm>
using namespace std;
# define lowbit(x) ((x)&(-x))
# define pi acos(-1.0)
# define eps 1e-8
# define MOD 1000000007
# define INF 1000000000
# define mem(a,b) memset(a,b,sizeof(a))
# define FOR(i,a,n) for(int i=a; i<=n; ++i)
# define FDR(i,a,n) for(int i=a; i>=n; --i)
# define bug puts("H");
# define lch p<<1,l,mid
# define rch p<<1|1,mid+1,r
# define mp make_pair
# define pb push_back
typedef pair<int,int> PII;
typedef vector<int> VI;
# pragma comment(linker, "/STACK:1024000000,1024000000")
typedef long long LL;
inline int Scan() {
    int x=0,f=1; char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-') f=-1; ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0'; ch=getchar();}
    return x*f;
}
inline void Out(int a) {
    if(a<0) {putchar('-'); a=-a;}
    if(a>=10) Out(a/10);
    putchar(a%10+'0');
}
const int N=200005;
//Code begin....

int main ()
{
    int n;
    LL x;
    scanf("%d",&n);
    LL ans=0;
    FOR(i,1,n) {
        scanf("%lld",&x);
        if (i==1) ans=x;
        else ans=ans/__gcd(ans,x)*x;
    }
    printf("%lld\n",ans);
    return 0;
}


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

using namespace std;

int main() {
	int n, k,tmp,tmp2;
	cin >> n >> k;
	bool* okasi = new bool[n];
	for (int i = 0;i < n;i++) {
		okasi[i] = false;
	}
	for (int i = 0;i < k;i++) {
		cin >> tmp;
		for (int i = 0;i < tmp;i++) {
			cin >> tmp2;
			okasi[tmp2 - 1] = true;
		}
	}
	int cnt = 0;
	for (int i = 0;i < n;i++) {
		if (!okasi[i])cnt++;
	}
	cout << cnt << endl;
}


Measured memory_bytes: 3192
ALP = ('a'..'z').to_a
INF = 0xffffffffffffffff
# mod = 998244353
# mod = 10 ** 9 + 9
mod = 10 ** 9 + 7
PI = Math::PI
dx = [ 1,  0, -1,  0,  1,  1, -1, -1]
dy = [ 0,  1,  0, -1,  1, -1,  1, -1]
eight = [0, 1, 1, 0, -1, -1, 1, -1, 0]
def max(a,b);       a > b ? a : b                              end
def min(a,b);       a < b ?  a : b                             end
def swap(a,b);      a, b = b, a                                end
def gi;             gets.to_i                                  end
def gf;             gets.to_f                                  end
def gs;             gets.chomp                                 end
def gmi(n=nil); n.nil? ? gets.split.map(&:to_i) : n.times.map{ gets.to_i } end
def gmf(n=nil); n.nil? ? gets.split.map(&:to_f) : n.times.map{ gets.to_f } end
def gms(n=nil); n.nil? ? gets.split : n.times.map{ gets.chomp } end
def ga2(h);        h.times.map{ gets.split.map(&:to_i) }      end
def gm(h);        h.times.map{ gets.chomp }      end
def yn(f); puts f ? "Yes" : "No" end
def YN(f); puts f ? "YES" : "NO" end
def yes(f=nil); f.nil? ? (puts "Yes"; exit) : (puts f ? "Yes" : "No") end
def no(f=nil); f.nil? ? (puts "No"; exit) : (puts f ? "Yes" : "No") end
def yay(f=nil); f.nil? ? (puts "Yay!"; exit) : (puts f ? "Yay!" : ":(") end

x,y,z = gmi
puts "#{z} #{x} #{y}"

Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, N) for (int i = 0; i < (int)N; ++i)
#define all(a) (a).begin(), (a).end()

int N;
int c[3];

int main() {
  cin >> N;
  rep(i, N) {
    int a;
    cin >> a;
    if (a % 4 == 0) {
      c[2]++;
    } else if (a % 2 == 0) {
      c[1]++;
    } else {
      c[0]++;
    }
  }

  cout << ((c[2] >= c[0] + (c[1] >= 1) - 1) ? "Yes" : "No") << endl;
  return 0;
}


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

#define FOR(i, a, b) for(int i = int(a); i < int(b); ++i)
#define REP(i, n) FOR(i, 0, n)
template <class T> T& CHMIN(T& a, const T b) { return a = (a > b) ? b : a; }

int dp[100005];

signed main() {
	int n;
	std::cin >> n;
	std::vector<std::string> s(n);
	REP(i, n) std::cin >> s[i];

	std::vector<std::vector<int>> pos(26);
	REP(i, n) pos[s[i][0] - 'a'].emplace_back(i);

	std::vector<int> next(n, n + 1);
	REP(i, 26) {
		REP(j, (int)pos[i].size() - 1) {
			next[pos[i][j]] = pos[i][j + 1];
		}
	}

	REP(i, n + 1) dp[i] = 1e9;
	dp[0] = 1;
	REP(i, n) {
		CHMIN(dp[i + 1], dp[i] + 1);
		CHMIN(dp[next[i]], dp[i]);
	}
	std::cout << dp[n - 1] << std::endl;
}


Measured memory_bytes: 10636
from collections import Counter
N = int(input())
def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a
c = Counter(prime_factorize(N))

ans = 0
for v in c.values():
    n = 1
    while n <= v:
        v -= n
        ans += 1
        n+=1
print(ans)

Measured memory_bytes: 65812
#include <iostream>
#include <fstream>
#include <iomanip>

#include <vector>
#include <set>
#include <bitset>
#include <map>
#include <deque>
#include <string>
#include <queue>

#include <algorithm>
#include <numeric>
#include <random>

#include <cstdio>
#include <cassert>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>

using namespace std;

#define forn(i, n) for (ll i = 0; i < static_cast<ll>(n); ++i)
#define sz(a) static_cast<int>((a).size())
#define pb emplace_back
#define endl '\n'
#define f first
#define s second

#ifdef LOCAL
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define dbg(...)
#endif

template<typename T>
void _dbg(const char* _s, T _h) { cerr << _s << " = " << _h << "\n"; }

template<typename T, typename... Ts>
void _dbg(const char*_s, T _h, Ts... _t) {
    int _b = 0;

    while (((_b += *_s == '(') -= *_s == ')') != 0 || *_s != ',')
        cerr << *_s++;

    cerr << " = " << _h << ",";
    _dbg(_s + 1, _t...);
}

using ll = long long;

const ll INF = static_cast<ll>(1e9) + 7ll;
const ll LINF = INF * INF;
const int MAXN = static_cast<int>(1e6) + 17;

int n;
ll a[MAXN];
vector<int> g[MAXN];

bool read() {
    if (!(cin >> n))
        return false;

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

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

    return true;
}

bool dfs(int v, int pr) {
    if (sz(g[v]) == 1)
        return true;

    ll sum = 0;

    for (auto to : g[v]) {
        if (to != pr) {
            if (!dfs(to, v))
                return false;

            sum += a[to];
        }
    }

    ll y = sum - a[v];
    ll x = a[v] - y;
    sum = 0;

    for (auto to : g[v]) {
        if (to != pr) {
            sum += min(y, a[to]);
        }
    }

    if (x < 0 || y < 0 || sum < 2 * y)
        return false;

    a[v] = x;
    return true;
}

void solve() {
    int root = -1;

    for (int i = 0; i < n; ++i) {
        if (sz(g[i]) > 1 && root == -1)
            root = i;
    }

    if (root == -1) {
        cout << (count(a, a + n, 1) == n ? "YES\n" : "NO\n");
        return ;
    }

    cout << (dfs(root, -1) && a[root] == 0 ? "YES\n" : "NO\n");
}

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

#ifdef LOCAL
    //freopen("/Users/leemonage/CLionProjects/proj/file.in", "r", stdin);
#endif

    while (read())
        solve();

    return 0;
}


Measured memory_bytes: 35968
#include<stdio.h>

int main(){
	int a,b,h,w;
	char board[100][100];
	while(1){
		scanf("%d",&h);
		scanf("%d",&w);
		if(w==0&&h==0) break;
		for(a=0;a<h;a++){
			scanf("%s",board[a]);
		}
		for(a=0,b=0;;){
			if(board[a][b]=='>'){
				board[a][b]='l';
				b++;
			}
			else if(board[a][b]=='<'){
				board[a][b]='l';
				b--;
			}
			else if(board[a][b]=='^'){
				board[a][b]='l';
				a--;
			}
			else if(board[a][b]=='v'){
				board[a][b]='l';
				a++;
			}
			else if(board[a][b]=='.'){
				printf("%d %d\n",b,a);
				break;
			}
			else if(board[a][b]=='l'){
				printf("LOOP\n");
				break;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 624
#define ll long long
#define MOD 1000000007
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#include <bits/stdc++.h>
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n;
    cin >> n;
    cout << n * n * n;
    return 0;
}

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

int main() {
    int sx, sy, tx, ty;
    cin >> sx >> sy >> tx >> ty;
    string x1, x2, y1, y2;
    x1 = 'R';
    x2 = 'L';
    y1 = 'U';
    y2 = 'D';
    string ans;
    ans = "";
    int dx, dy;
    dx = tx - sx;
    dy = ty - sy;
    for (int i=0; i<dx; i++) ans += x1;
    for (int i=0; i<dy; i++) ans += y1;
    for (int i=0; i<dx; i++) ans += x2;
    for (int i=0; i<dy; i++) ans += y2;
    // 2週目
    ans += y2;
    for (int i=0; i<dx; i++) ans += x1;
    ans += x1;
    for (int i=0; i<dy; i++) ans += y1;
    ans += y1;
    ans += x2;
    ans += y1;
    for (int i=0; i<dx; i++) ans += x2;
    ans += x2;
    for (int i=0; i<dy; i++) ans += y2;
    ans += y2;
    ans += x1;
    cout << ans << endl;
}

Measured memory_bytes: 3644
import java.util.*;
import java.lang.Math;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int m = sc.nextInt();
    int d = sc.nextInt();
    int count = 0;
    int d1,d10;
    
    for(int i = 4; i <= m; i++){
    	for(int j = 22;j <= d;j++){
          d1 = j%10;
          d10 = j/10;
          if(d1*d10 == i && d1 > 1 && d10 > 1) count++;
        }
    } 
   	
  	System.out.println(count);

  }
}


Measured memory_bytes: 35764
#include <iostream>
using namespace std;
int main(void){
    string s;
    int n, k;
    cin >> n >> s >> k;
    char c = s[k-1];
    for(int i=0; i<n; i++){
        if (s[i] != c)
            s[i] = '*';
    }
    cout << s << endl;
}


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)=0;(i)<=(int)(n);(i)++)
#define rep1(i,x,n) for(int (i)=(x);(i)<(int)(n);(i)++)
#define REP1(i,x,n) for(int (i)=(x);(i)<=(int)(n);(i)++)
#define rrep(i,x) for(int i=((int)(x)-1);i>=0;i--)
using namespace std;
using ll = long long;
using ull = unsigned long long;
using Int = long long;

//INT_MAX = 2147483647;
//LLONG_MAX = 9223372036854775807;
//ULLONG_MAX = 18446744073709551615;
const int MOD = 1000000007;
const ll INF = numeric_limits<ll>::max();
const int inf = 1e8;
typedef pair<int,int> P;
typedef std::priority_queue<int> IntPrioQueue;
typedef std::priority_queue<int, std::vector<int>, std::greater<int> > IntReversePrioQueue;

//少数点表示
//cout << std::fixed << std::setprecision(14) << 値

int main(){
    cin.tie( 0 ); ios::sync_with_stdio( false );
    int x;
    cin >> x;
    if(x == 7 || x == 5 || x == 3) cout << "YES" << endl;
    else cout << "NO" << endl;
    
    
    return 0;
}

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

bool graph[10][10];

int main() {
	int n, m;
	cin >> n >> m;
	int a, b;
	int sum,ans=0;
	for (int i = 0; i < m; ++i) {
		cin >> a >> b;
		graph[a][b] = true;
		graph[b][a] = true;
	}
	vector<int>v;
	for (int i = 2; i <= n; ++i)v.push_back(i);
	do{
		sum = 0;
		if (graph[v[0]][1] == false)continue;
		for (int i = 0; i < n - 2; ++i) {
			if (graph[v[i]][v[i + 1]] == true)++sum;
		}
		if (sum == n - 2)++ans;
	} while (next_permutation(v.begin(), v.end()));
	cout << ans << endl;
	return 0;
}

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

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define each(i,c) for(__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define all(v) v.begin(), v.end()
#define mset(a, n) memset(a, n, sizeof(a))

typedef long long ll;

const int INF = 1000000000;
const int MOD = 1000000007;

int main(int argc, char const *argv[]) {
	int N; cin >> N;
	int ans = 0, max_p = 0;
	rep(i, N) {
		int p; cin >> p;
		max_p = max(max_p, p);
		ans += p;
	}
	cout << ans - max_p / 2 << endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
#define M 100000000
int p[5010][2];
double dpl(int p0[2],int p1[2],int p2[2]){
  int a=p0[1]-p1[1],b=p0[0]-p1[0],c=p0[0]*p1[1]-p1[0]*p0[1];
  int d=p2[1]-p1[1],e=p2[0]-p1[0];
  int f=p2[1]-p0[1],g=p2[0]-p0[0];
  if(a*d+b*e<0||a*f+b*g>0)return -1;
  return abs(p2[0]*a-p2[1]*b+c)/hypot(a,b);
}
double hyp(int a,int b){return hypot(p[a][0]-p[b][0],p[a][1]-p[b][1]);}
double MIN(double a,double b){return a<b?a:b;}
int main(){
  int n,m,i,mi,ni,Mi,c[5010]={1};
  double Min,min,s=0.0,l[5010],d;
  scanf("%d %d %d %d",&n,&m,&p[0][0],&p[0][1]);
  Min=min=M;
  for(i=1;i<=n;i++){
    //c[i]=-1;
    scanf("%d %d",&p[i][0],&p[i][1]);
    l[i]=hyp(0,i);//printf("%d %f\n",i,l[i]);
    if(Min>l[i])Min=l[mi=i];      
  }
  Mi=0;
  while(m--){//printf("\n%d %d ",Mi,mi);
    c[mi]=1;
    s+=Min;//printf("%f\n",s);
    min=Min=M;
    for(i=1;i<=n;i++){
      if(c[i])continue;
      d=dpl(p[Mi],p[mi],p[i]);//printf("%d %f\n",i,d);
      //printf("::%d %d %f %f\n",Mi,mi,hyp(Mi,i),hyp(mi,i));
      if(d<-0.5)d=MIN(hyp(Mi,i),hyp(mi,i));//printf("%d %f\n",i,d);
      l[i]=MIN(l[i],d);
      if(min>l[i])min=l[ni=i];
    }
    mi=ni;
    for(i=0;i<=n;i++){
      if(c[i]-1)continue;
      d=hyp(i,mi);
      if(Min>d){
	Min=d;
	Mi=i;
      }//printf("%f\n",Min);
    }//printf("%f\n",Min);
  }
  printf("%f\n",s);
  return 0;
}

Measured memory_bytes: 748
import java.util.Scanner;
public class Main{
	public static void main(String[]args) {
		Scanner input=new Scanner(System.in);
		int N=input.nextInt();
		int K=input.nextInt();
		int X=input.nextInt();
		int Y=input.nextInt();
		if(N<=K) {
			System.out.println(N*X);
		}else if(N>K){
			System.out.println(K*X+(N-K)*Y);
		}
	}
}

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


#define rep(i,a,b) for(ll i=ll(a);i<ll(b);i++)
#define irep(i,a,b) for(ll i=ll(a);i>=ll(b);i--)
#define pb push_back
#define mp make_pair
#define pll pair<ll,ll>
#define endl "\n"
using ll=long long;
using ld=long double;
using namespace std;
const ll mod=1e9+7;
ll GCD(ll a, ll b) { return b ? GCD(b, a%b) : a; }
char s[55][55];

//ll sx=0,sy=0,gx=h-1,gy=w-1;
ll d[55][55];
ll dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
ll h,w;

ll bfs(){
  ll sx=0,sy=0,gx=h-1,gy=w-1;
  queue<pll> que;
  que.push(pll(sx,sy));
  rep(i,0,h){
    rep(j,0,w){
     d[i][j]=-1e5;
    }
  }
  d[sx][sy]=0;
  while(que.size()){
    pll p=que.front();
    que.pop();
    //if(p.first==gx&&p.second==gy)break;
    rep(i,0,4){
      ll nx=p.first+dx[i],ny=p.second+dy[i];
      if(0<=nx&&nx<h&&0<=ny&&ny<w&&s[nx][ny]!='#'&&d[nx][ny]==-1e5){
        que.push(pll(nx,ny));
        d[nx][ny]=d[p.first][p.second]+1;
      }
    }
  }
  return d[gx][gy];
}
main(){
  ll sum=-1;
  cin>>h>>w;
  rep(i,0,h){
    rep(j,0,w){
      cin>>s[i][j];
      if(s[i][j]=='.')sum++;
    }
  }
  ll tmp=bfs();
  if(tmp==-1e5)cout<<-1;
  else cout<<sum-tmp;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <vector>
#include <iomanip>
#include <sstream>
#include <bitset>
#define ALL(x) (x).begin(), (x).end()
#define sz(a) int(a.size())
#define rep(i,x,n) for(int i=x;i<n;i++)
#define repd(i,x,n) for(int i=x;i<=n;i++)
#define pii pair<int,int>
#define pll pair<long long ,long long>
#define gbtb ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define MS0(X) memset((X), 0, sizeof((X)))
#define MSC0(X) memset((X), '\0', sizeof((X)))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define eps 1e-6
#define chu(x)  if(DEBUG_Switch) cout<<"["<<#x<<" "<<(x)<<"]"<<endl
#define du3(a,b,c) scanf("%d %d %d",&(a),&(b),&(c))
#define du2(a,b) scanf("%d %d",&(a),&(b))
#define du1(a) scanf("%d",&(a));
using namespace std;
typedef long long ll;
ll gcd(ll a, ll b) {return b ? gcd(b, a % b) : a;}
ll lcm(ll a, ll b) {return a / gcd(a, b) * b;}
ll powmod(ll a, ll b, ll MOD) { if (a == 0ll) {return 0ll;} a %= MOD; ll ans = 1; while (b) {if (b & 1) {ans = ans * a % MOD;} a = a * a % MOD; b >>= 1;} return ans;}
ll poww(ll a, ll b) { if (a == 0ll) {return 0ll;} ll ans = 1; while (b) {if (b & 1) {ans = ans * a ;} a = a * a ; b >>= 1;} return ans;}
void Pv(const vector<int> &V) {int Len = sz(V); for (int i = 0; i < Len; ++i) {printf("%d", V[i] ); if (i != Len - 1) {printf(" ");} else {printf("\n");}}}
void Pvl(const vector<ll> &V) {int Len = sz(V); for (int i = 0; i < Len; ++i) {printf("%lld", V[i] ); if (i != Len - 1) {printf(" ");} else {printf("\n");}}}
inline long long readll() {long long tmp = 0, fh = 1; char c = getchar(); while (c < '0' || c > '9') {if (c == '-') fh = -1; c = getchar();} while (c >= '0' && c <= '9') tmp = tmp * 10 + c - 48, c = getchar(); return tmp * fh;}
inline int readint() {int tmp = 0, fh = 1; char c = getchar(); while (c < '0' || c > '9') {if (c == '-') fh = -1; c = getchar();} while (c >= '0' && c <= '9') tmp = tmp * 10 + c - 48, c = getchar(); return tmp * fh;}
const int maxn = 1000010;
const int inf = 0x3f3f3f3f;
/*** TEMPLATE CODE * * STARTS HERE ***/
#define DEBUG_Switch 0
int n, m;
int a[maxn];
int main()
{
#if DEBUG_Switch
    freopen("C:\\code\\input.txt", "r", stdin);
#endif
    //freopen("C:\\code\\output.txt","r",stdin);
    n = readint();
    m = readint();
    ll sum = 0;
    repd(i, 1, n)
    {
        a[i] = readint();
        sum += a[i];
    }
    int ans = 0;
    repd(i, 1, n)
    {
        if (1ll * a[i] * 4 * m >= sum)
        {
            ans++;
        }
    }
    if (ans >= m)
    {
        printf("Yes\n");
    } else
    {
        printf("No\n");
    }

    return 0;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,r,l, sum=0;
  cin >> N;
  
  for(int i=0; i<N; i++){
  	cin >> l >> r;
    sum += r-l+1;
  }
  
  cout << sum << endl;
}

Measured memory_bytes: 256
a, b, c = map(int, input().split())
from math import sqrt

def check(a, b, c):
    n = c - a - b
    if n <= 0:
        return False
    else:
        return 4 * a * b < n**2


if check(a, b, c):
    print("Yes")
else:
    print("No")


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

long long int knapsack(long long int W, long long int wt[], long long int val[],long long int n)
 { long long int i,w;
   long long int k[n+1][W+1]={0};

      for(i=0; i<=n; i++)
       {   for(w=0; w<=W; w++)
             {  if(i==0 || w==0)
                k[i][w]=0;
                else if (wt[i-1] <= w)
                  k[i][w] = max(val[i-1] + k[i-1][w-wt[i-1]],k[i-1][w]);
                else
                  k[i][w] = k[i-1][w];
             }
       }
        return(k[n][W]);

 }
 int main()
{ long long int i,n,W;
  cin>>n>>W;
  long long int wt[n+2], val[n+2];
   for(i=0; i<n; i++)
   cin>>wt[i]>>val[i];
   cout<<knapsack(W,wt,val,n);




return(0);

}


Measured memory_bytes: 79104
#include <iostream>
#include <vector>
#include <cmath>
#include <typeinfo>
#include <set>
#include <bitset>
#include <string>
#include <map>
#include <algorithm>
#include <numeric>
using namespace std;
typedef long long ll;



int main(){
  int n, m;
  cin >> n >> m;
  vector<bool> t(n,true);
  vector<int> h(n,0);
  for(int i=0; i<n; i++){
    cin >> h[i];
  }
  int ai, bi;
  for(int i=0; i<m; i++){
    cin >> ai >> bi;
    if(h[ai-1]<=h[bi-1]){
      t[ai-1] = false;
    }
    if(h[bi-1]<=h[ai-1]){
      t[bi-1] = false;
    }
  }

  int count = 0;
  for(int i=0; i<n; i++){
    if(t[i]){
      count += 1;
    }
  }
  cout << count << endl;
}

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

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

#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define isYES(x) printf("%s\n",(x) ? "YES" : "NO")

#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define isYes(x) printf("%s\n",(x) ? "Yes" : "No")
int main(void){
  int H1,M1,H2,M2,K;
  cin>>H1>>M1>>H2>>M2>>K;
  int t1,t2,ans;
  t1=H1*60+M1;
  t2=H2*60+M2;
  ans=t2-t1-K;
  cout << ans <<endl;
  return 0;
}

Measured memory_bytes: 3672
#include<bits/stdc++.h>
using namespace std;
int main()
{

    int k;
    cin>>k;
    int n=0;
    set<int> ss;
    int c=1;
    while(true)
    {
        n=((n*10)+7)%k;
        if(n==0)
        {
            cout<<c;
            break;
        }
        if(ss.count(n))
        {
            cout<<-1;
            break;
        }
        ss.insert(n);
        c++;
    }
}




Measured memory_bytes: 50404
#define _CRT_SECURE_NO_WARNINGS

#include<iostream>
#include<string>
#include<vector>
#include<list>
#include<stack>
#include<queue>
#include<map>
#include<tuple>
#include<algorithm>
#include<numeric>
#include<math.h>

#define REPS(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define print(x) cout << #x << " = " << x << endl;

using namespace std;

using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;

const int mod = 1e9 + 7;
const long double pi = acos(-1);
const long double eps = 1e-7;


const int MAX = 100001;

int n, m;
int l, r, d;
int vs;
vector<pii> terms[MAX];	// 条件（first: エッジの先のインデックス、second：距離）
bool nl[MAX];			// 左に人がいるかどうか
bool bSearched[MAX];	// 探索をすでにしているかどうか
int dis[MAX];			// 距離を保存
bool bWrong;			// 矛盾が発生しているかどうか

// 深さ優先探索
void dfs(int p) {
	bSearched[p] = 1;
	vs++;

	// インデックスpのノードにおける条件すべてをループ
	for (pii term : terms[p]) {
		// どのノードを探索しているか
		//printf("%2d->%2d\n", p, term.first);

		if (!bSearched[term.first]) {	// エッジの先がまだ探索されていない場合
			dis[term.first] = dis[p] + term.second;	// 距離を保存
			dfs(term.first);	// 次のエッジを探索
		}
		else {	// エッジの先がすでに探索済みである場合
			if (dis[p] + term.second != dis[term.first]) {	// 既に探索した道のりと現在辿ってきた道のりが異なる場合
				bWrong = true;
				return;
			}
		}
	}
}

int main() {
	scanf("%d %d", &n, &m);

	while (m--) {
		scanf("%d %d %d", &l, &r, &d);

		terms[l].push_back(pii({ r, d }));
		nl[r] = true;
	}

	for (int i = 1; i <= n; i++) {
		// 左に人がいる時はスキップ
		if (nl[i]) continue;

		// 一番右になりえる要素から探索スタート
		dfs(i);
	}

	if (bWrong || vs < n) printf("No\n");
	else printf("Yes\n");

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

Measured memory_bytes: 9472
#include<bits/stdc++.h>
#include<cctype>
using namespace std;
#define rep(i,n) for (int i=0;i<(n);i++)
#define all(v) (v).begin(),(v).end()
typedef long long int ll;
#define pi 3.1415926535897932384
#define E9 1000000000
#define eps 1e-4
#define pii pair<int,int>


int main(){
  int X; cin >> X;
  int x = X%100;
  if ((x+4)/5<=X/100) cout << 1 << endl;
  else cout << 0 << endl;
  

  // cout << fixed << setprecision(6);
  return 0;
}



Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int a, b, c;
    cin >> a >> b >> c;
    a = a * 100;
    b = b *10;
    int ans = a + b + c;
    if(ans % 4 != 0){
        cout << "NO" << endl; 
    }
    else{
        cout << "YES" << endl;
    }
    
        
    
        
    
   
    
    
    
    
    
}



Measured memory_bytes: 3548
#include <algorithm>
#include <iostream>
#include <climits>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <set>
#include <map>

using namespace std;

#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define ll long long
#define mod 1000000007
#define vi vector<int>
#define vll vector<ll>
#define pb push_back

ll power(int x, unsigned int y){
    ll res = 1;
    while(y > 0){
        if(y & 1) res = res * x;
        y >>= 1;
        x *= x;
    }
    return res;
}

// Check for number of Cases!!
void solve() {
    int n, x, t;
    cin >> n >> x >> t;

    cout << (int)ceil(n*1.0/x) * t << '\n';
}

int main(){


    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    int t = 1;
    // cin >> t;
    while(t--) {
      solve();
    }
}

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

using lint = long long;
template <typename T> using V = vector<T>;
template <typename T> using VV = vector<vector<T>>;
#define rep(i, n) for(int i = 0; i < int(n); i++)
#define repu(i, a, b, s) for(int i = int(a); i < int(b); i += int(s))
#define repd(i, a, b, s) for(int i = int(a); i > int(b); i += int(s))
#define endl "\n"
constexpr lint INF = 2e18;
constexpr lint MOD = 1e9 + 7;

void solve() {

    static lint grid[3001][3001];
    static lint dp[3001][3001][4];

    lint R, C, K;
    cin >> R >> C >> K;

    rep(i, R) {
        rep(j, C) { grid[i][j] = -1; }
    }

    rep(i, K) {
        lint r, c, v;
        cin >> r >> c >> v;
        r--;
        c--;
        grid[r][c] = v;
    }

    rep(y, R) {
        rep(x, C) {
            rep(i, 4) { dp[y][x][i] = 0; }
        }
    }

    if(grid[0][0] != -1)
        dp[0][0][1] = grid[0][0];

    rep(y, R) {
        rep(x, C) {

            // 選ばない
            if(0 <= y - 1) {
                rep(i, 4) { dp[y][x][0] = max(dp[y][x][0], dp[y - 1][x][i]); }
            }
            if(0 <= x - 1) {
                rep(i, 4) { dp[y][x][i] = max(dp[y][x][i], dp[y][x - 1][i]); }
            }

            // 選ぶ
            if(grid[y][x] != -1) {
                if(0 <= y - 1) {
                    rep(i, 4) { dp[y][x][1] = max(dp[y][x][1], dp[y - 1][x][i] + grid[y][x]); }
                }
            }
            if(0 <= x - 1) {
                repu(i, 1, 4, 1) { dp[y][x][i] = max(dp[y][x][i], dp[y][x - 1][i - 1] + grid[y][x]); }
            }
        }
    }

    lint ans = -INF;
    rep(i, 4) { ans = max(ans, dp[R - 1][C - 1][i]); }
    cout << ans << endl;
}

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


Measured memory_bytes: 355328
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <algorithm>
using namespace std;

int n, m;
char s1[55][55], s2[55][55];
bool check(int x, int y)
{
	for(int i = 1; i <= m; i++)
	{
		for(int j = 1; j <= m; j++)
		{
			if(s1[x + i - 1][y + j - 1] != s2[i][j])
				return 0;
		}
	}
	return 1;
}

int main()
{
	while(scanf("%d %d", &n, &m) != EOF)
	{
		bool flag = 0;
		for(int i = 1; i <= n; i++)
			for(int j = 1; j <= n; j++)
				scanf(" %c", &s1[i][j]);
		for(int i = 1; i <= m; i++)
			for(int j = 1; j <= m; j++)
				scanf(" %c", &s2[i][j]);
		for(int i = 1; i <= n; i++)
		{
			for(int j = 1; j <= n; j++)
			{
				if(s1[i][j] == s2[1][1])
				{
					if(check(i, j))
					{
						flag = 1;
						i = j = n + 1;
					}
				}
			}
		}
		if(flag) printf("Yes\n");
		else printf("No\n");
		memset(s1, 0, sizeof(s1));
		memset(s2, 0, sizeof(s2));
	}
	return 0;
}

Measured memory_bytes: 128
a = Hash.new(0)

words = gets.chomp.split
words.each do |word|
  a[word] += 1
end

mode_value = a.sort { |a, b| b[1] <=> a[1] }
max_size = a.sort { |a, b| b[0].size <=> a[0].size }

puts "#{mode_value[0][0]} #{max_size[0][0]}"

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

using namespace std;

#define ok1 printf("ok1\n");
#define ok2 printf("ok2\n");
#define M 1000000000000000000LL
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define pb push_back
#define pf push_front
#define MIN(a,b) a=min((a),(b))
#define MAX(a,b) a=max((a),(b))
#define SIZE(v) (int)v.size()
#define Eunique(v) v.erace(unique(all(v)),v.end())
#define pvec(v)　rep(i,v.size()){cout << v[i] << " ";}
#define INF 0x3f3f3f3f
#define mset(m,v) memset(m,v,sezeof(m))
#define mod 1e9 +7;

const double pi = acos(-1.0);

typedef string ss;
typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef deque<ll> dll;
typedef pair<ll,ll> P;
ll dx[4] = {1,0,-1,0},dy[4] = {0,1,0,-1};

ll gcd(ll x,ll y)
{
    ll r;
    while((r = x % y) != 0)
    {
        x = y;
        y = r;
    }
    return y;
}

ll lcm(ll x,ll y)
{
    x /= gcd(x,y);
    y /= gcd(x,y);
    return (x*y);
}

int main()
{
    ll n;
    cin >> n;
    vvll dp(n, vll(3));
    rep(i,n)rep(j,3)cin >> dp[i][j];

    REP(i,1,n){
        rep(j,3){
            ll m = -1;
            rep(k,3)if(j != k)m = max(dp[i-1][k], m);
            dp[i][j] += m;
        }
    }
    cout << *max_element(all(dp[n-1])) << endl;
    return 0;
}

Measured memory_bytes: 5760
#include <iostream>
#include<string.h>
#include<string>
using namespace std;
int main()
{
    string s;int n;
    cin>>n>>s;
    int c=0;
    for(int i=0;i<n-2;i++)
      {
          if(s[i]=='A' && s[i+1]=='B' && s[i+2]=='C')
                 c++;
      }
    
  cout<<c;
}

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

using namespace std;

int main(){

	int n;
	while(cin>>n&&n!=0){
		int nums[15];
		int cnts[10000];
		fill(cnts,cnts+10000,0);
		for(int i = 0; i < n; i++){
			cin>>nums[i];
			cnts[nums[i]]++;
		}
		int cnt=0;
		while(1){
			bool f=false;
			for(int i = 0; i < n; i++){
				if(nums[i]!=cnts[nums[i]]){
					nums[i]=cnts[nums[i]];
					f=true;
				}
			}
			if(!f)
				break;

			fill(cnts,cnts+10000,0);
			for(int i = 0; i < n; i++){
				cnts[nums[i]]++;
			}
			cnt++;
		}
		cout<<cnt<<endl;
		for(int i = 0; i < n; i++){
			cout<<nums[i];
			if(i==n-1)
				cout<<endl;
			else
				cout<<" ";
		}
	}

	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#define rep(i,n) for(int i=0; i<n; i++)
typedef long long ll;
typedef pair<int,int> P;
const ll MOD = (int)1e9+7;
const ll INF = MOD*MOD;
ll n,m,k,ans;
string s,t;
const ll powll = 1LL<<1;

int main(){
  int a,b; cin >> a >> b;
  int f[3] = {};
  f[a-1] = 1; f[b-1] = 1;
  rep(i,3) if(f[i] == 0) cout << i+1 << "\n";
  // vector<int> v = {};
  // while(t--){}
  // rep(i,v.size()) cout << v[i] << "\n";
}

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

void disp(vector<int>& v) {
    for (int i=0; i<v.size()-1; i++) {
        cout << v[i] << " ";
    }
    cout << v[v.size()-1] << endl;
}

int main() {
    int i, j, minj, n, tmp;
    int swap_count = 0;
    vector<int> v;

    cin >> n;
    for (i=0; i<n; i++) {
        cin >> tmp;
        v.push_back(tmp);
    }

    for (i=0; i<n; i++) {
        minj = i;
        for (j=i; j<n; j++) {
            if (v[j] < v[minj]) {
                minj = j;
            }
        }
        if (i != minj) {
            swap(v[i], v[minj]);
            swap_count++;
        }
    }

    disp(v);
    cout << swap_count << endl;
}

Measured memory_bytes: 1220
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <limits>
#include <iostream> 
#include <iomanip>  
#include <string>
#include <sstream>  
#include <algorithm>
#include <numeric>
#include <complex>
#include <functional>
#include <cstring>
#include <cmath>
#include <cassert>


#define INF              (int)1000000007
#define EPS              1e-9
#define pb               push_back
#define mp               make_pair
#define all(c)           c.begin(), c.end()
#define forall(i,a,b)    for(int i=a;i<(b);++i)
#define trav(a,x)        for(auto & a: x)
#define in(a,b)          ((b).find(a) != (b).end())
#define sz(c)            (int)(c).size()
#define input(a)         for(auto & x : a) cin >> x;

using namespace std;

typedef vector<int>      vi;
typedef pair<int,int>    ii;
typedef vector<vi>       vvi;
typedef vector<ii>       vii;
typedef long long        ll;

#ifdef DEBUG
#define trace(...)       __f(#__VA_ARGS__, __VA_ARGS__)
#define debug(args...)   {dbg,args; clog<<endl;}
#define print_( a )      for( auto & x : a ) clog << x << ' '; clog << '\n';
#define printPair_( a )  for( auto & x : a ) clog << '(' << x.first << ',' << x.second << ')' << ' '; clog << '\n';
#else
#define trace(...)       
#define debug(args...)            
#define print_( a )               
#define printPair_( a )           
#endif

struct debugger {
  template<typename T> debugger& operator , (const T& x) {    
    clog << x << " ";    return *this;    
  }
}dbg;

template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << ": " << arg1 << endl;
}

template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');
    cerr.write(names, comma - names) << ": " << arg1 << " | ";
    __f(comma + 1, args...);
}

auto ____ =[]() { std::ios::sync_with_stdio(0); cin.tie(0); return nullptr; }();

int n;
vector<vector<vector<double>>> dp(
    301, vector<vector<double>>(301, vector<double>(301, -1)));

double solve( int x, int y, int z ){
  // x ones, y twos, z threes
  if( dp[x][y][z] > 0.0 ) return dp[x][y][z];
  int w = n - x - y - z;
  double ans = 1.0;
  trace(x,y,z,w,ans);
  if( z > 0 ){
    ans += (double)z / n * solve(x, y+1, z-1);
  }
  if( y > 0 ){
    ans += (double)y / n * solve(x+1, y-1, z);
  }
  if( x > 0 ){
    trace(x,y,z,n,ans,"before x>0");
    ans += (double)x / n * solve(x-1, y, z);
    trace(x,y,z,n,ans,"after x>0");
  }

  trace(x,y,z, n, "before", ans);
  if( w > 0 ){
    ans = ans * (n) / (n-w);
  }
  trace(x,y,z, '=', ans);
  return dp[x][y][z] = ans;
}

int main( int argc, char * argv[] ){
  cin >> n; 
  vector<double> v(n);
  input(v);

  dp[0][0][0] = 0;
  dp[1][0][0] = n;
  trace(dp[1][0][0]);
  vi cnt(3,0);
  for(auto x : v) cnt[x-1]++;
  print_(cnt);
  cout << setprecision(16) << solve(cnt[0], cnt[1], cnt[2]) << endl;

  return 0;
}


Measured memory_bytes: 216960
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <vector>
#include <string>
using namespace std;
#define MAX 1000000010

int dp[1000010];
int solve(int n, int m, string str){
	int ans = 0;
	fill(dp, dp+1000010, 0);
	char c;
	for(int i = 2;i < m;i++){
		if(str.substr(i-2, 3) == "IOI"){
			dp[i] += dp[i-2] + 1;
			if(dp[i] >= n)ans++;
		}
	}
	/*for(int i = 0;i < m;i++){
		cout << dp[i] << " ";
	}cout << endl;*/
	return ans;
}

int main(){
	int n, m;
	string str;
	while(cin >> n, n){
		cin >> m >> str;
		cout << solve(n, m, str) << endl;
	}
	
	return 0;
}
//for(it = a.begin();it != a.end();it++)
/*
20 4 1
12 8 16
*/

Measured memory_bytes: 7776
#define _CRT_SECURE_NO_WARNINGS
// #define _USE_MATH_DEFINES
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <locale>
#include <cctype>
#include <sstream>
#include <iomanip>    // 10????????? cout << setprecision(10) << double;
#include <queue>
using namespace std;

typedef long long LL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef map<int, int> MAPII;
typedef multimap<int, char, greater<int> > MuMAPIC;
typedef vector<pair<int, int> > VPII;
typedef multimap<int, string, greater<int> > MuMIS;
typedef pair<int, int> P;
typedef pair<int, pair<P, P> > PP;

#define MP make_pair
#define FAST_IO  cin.tie(0); ios::sync_with_stdio(false);
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
//for gcc (???test)
// #define FOREACH_IT(it,c) for(typeof(c)::iterator it=(c).begin(); it!=(c).end(); ++it)
//for Visual Studio
#define foreach_it(type,it,c) for(type::iterator it=c.begin(),c_end=c.end();it!=c_end;++it)
// for Debug.
#define DUMP_VVI(b) FOR(i,0,b.size()){FOR(j,0,b[i].size())printf("%d ",b[i][j]);puts("");}
#define D_OUT(str,value) if(dbgF){cout<<str<<" : "<<value<<endl;}
// ??\??????push_back(d)???array[d]???????????????1??????§?????????
// int INPUT_INT() {int d;cin>>d;return d;}
template<class T>T IN() { T d; cin >> d; return d; }
// ??????§????¢??´????°???Greatest Common Divisor???
LL gcd(LL a, LL b) { return (b > 0) ? gcd(b, a%b) : a; }
// ?????°?????¢??????°???Least Common Multiple???
LL lcm(LL a, LL b) { return a / gcd(a, b) * b; }
// Y???´???????????????´?????????
bool uruu(LL Y) { return (((Y % 4 == 0 && Y % 100 != 0) || Y % 400 == 0) ? true : false); }

// vector???¨???
// vec[i][j]?????????????\????????\?????????¨??????vec???????????????????????????????????????.

#define INF 1000000

// ????????????????°???????????????§???

// ------------------- include, typedef, define END. -------------------



int main() {
	int n = 0;

	while (cin >> n, n) {
		VI k(n + 1, 0);
		string s;
		FOR(i, 0, n) {
			k[i] = IN<int>();
		}
		cin >> s;

		int j = -1;
		FOR(i, 0, s.length()) {
			j++;
			if (j >= n) {
				j = 0;
			}

			FOR(a, 0, k[j]) {
				s[i]--;
				if (s[i] == 96)s[i] = 90;
				if (s[i] == 64)s[i] = 122;
			}

			cout << s[i];
		}
		cout << endl;

	}

	return 0;
}

Measured memory_bytes: 1204
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int a = scanner.nextInt();
		int b = scanner.nextInt();
		if (a==2 || b==2) System.out.println("No");
		else System.out.println("Yes");
	}
}

Measured memory_bytes: 21716
#include<stdio.h>
int main()
{
	int a,b,c,x;
	int i,j,k,n=0,m=0;
	scanf("%d %d %d %d",&a,&b,&c,&x);
	if(a*500+b*100+c*50<=0){
		printf("0\n");
	}
	for(i=0;i<=a;i++){
		for(j=0;j<=b;j++){
			for(k=0;k<=c;k++){
				n=i*500+j*100+k*50;
				if(n==x) m++;
			}
		}
	}
	printf("%d\n",m);
	return 0;
}

Measured memory_bytes: 1728
// AOJ 0539: Pizza
// 2017.9.1 bal4u@uu
// 2017.11.14

#include <stdio.h>
#include <stdlib.h>

#define MIN(a,b) ((a)<=(b)?(a):(b))

int p[100003]; int n;

int cmp(int *a, int *b) { return *a - *b; }

int bsrch(int x)
{
	int m, l = 0, r = n;
    while (l < r) {
        m = (l + r) >> 1;
		if (p[m] == x) return 0;
		if (p[m] < x) l = m + 1; else r = m;
    }
	return MIN(x-p[l-1], p[l]-x); 
}

char buf[15], *bp;
int getint()
{
	int n = 0;
	while (*bp >= '0') n = (n<<3) + (n<<1) + (*bp++ & 0xf);
	return n;
}

int main()
{
	int d, m, i, ans;

	while (fgets(bp=buf, 15, stdin) && *buf != '0') {
		d = getint();
		fgets(bp=buf, 15, stdin), n = getint();
		fgets(bp=buf, 15, stdin), m = getint();

		p[0] = 0, p[n] = d;
		for (i = 1; i < n; i++) fgets(bp=buf, 15, stdin), p[i] = getint();
		n++; qsort(p, n, sizeof(int), cmp);

		ans = 0; while (m--) {
			fgets(bp=buf, 15, stdin);
			ans += bsrch(getint());
		}
		printf("%d\n", ans);
	}
	return 0;
}

Measured memory_bytes: 2468
#include <stdio.h>

int main(void){
	
	int a,b,c,d,e,f;
	int g,h,i,j,k,l;
	
	scanf("%d %d %d %d %d %d",&g,&h,&i,&j,&k,&l);
	
	a=1*g,b=5*h,c=10*i,d=50*j,e=100*k,f=500*l;
	
	if(a+b+c+d+e+f>=1000){
		printf("%d\n",1);
	}else{
		printf("%d\n",0);
		
	}
	return 0;
	
}
	
	

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

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

typedef long long ll;
using namespace std;
int mod = 1000000007;

int main(void){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N, M; cin >> N >> M;
    cout << N*(N-1)/2 + M*(M-1)/2 << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
int H,W,N;
  cin>>H>>W>>N;
  int r,c;
  cin>>r>>c;
  string s,t;
  cin>>s>>t;
  bool x=true;
  int a=r;
  for(int i=0;i<N;i++){
    if(s.at(i)=='U')
      a--;
    if(a<=0)x=false;
    if(t.at(i)=='D'){
    if(a<H)
      a++;
    }
     }int a1=r;
  for(int i=0;i<N;i++){
    if(s.at(i)=='D')
      a1++;
    if(H<a1)x=false;
    if(t.at(i)=='U'){
    if(1<a1)
      a1--;
    }
     }int a2=c;
  for(int i=0;i<N;i++){
    
    if(s.at(i)=='R')
      a2++;
    if(W<a2)x=false;
    if(t.at(i)=='L'){
    if(1<a2)
      a2--;
    }
     }int a3=c;
  for(int i=0;i<N;i++){
    
    if(s.at(i)=='L')
      a3--;
    if(a3<=0)x=false;
    if(t.at(i)=='R'){
    if(a3<W)
      a3++;
    }
     }if(x)
    cout<<"YES"<<endl;
  else
    cout<<"NO"<<endl;
   return 0;
}

Measured memory_bytes: 904
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
 
#define int long long
#define ll long long
#define vi vector <int>
#define vii vector <pair<int,int> >
#define vvi vector <vi>
#define rep(i,a,b) for (int i=a;i<b;i++)
#define repD(i,a,b) for (int i=a;i>b;i--)
#define pb push_back
#define pii pair <int,int>
#define ff first
#define ss second
#define all(a) a.begin(),a.end()
#define MOD 1000000007
#define PI 3.14159265359
 
typedef tree<int,null_type,less<int>,rb_tree_tag, tree_order_statistics_node_update> ordered_set;
///*X.find_by_order("index")
///X.order_of_key("key")
 
#define deb(x) {x}
#ifndef local
	#define deb(x) ;
#endif
 
///----------------------------------------------------------------------------------

int n, k, l;
vi roads[200005], rails[200005];
int root[200005], ans[200005], vis[200005];

void dfs1(int so, int r)
{
	vis[so] = true;
	root[so] = r;
	for (auto x:roads[so]) if (!vis[x]) dfs1(x, r);
}

map<int, vi> who;
void dfs2(int so)
{
	vis[so] = true;
	who[root[so]].pb(so);
	for (auto x:rails[so]) if (!vis[x]) dfs2(x);
}
void solve()
{
	cin >> n >> k >> l;
	int u, v;
	rep(i,0,k)
	{
		cin >> u >> v;
		roads[u-1].pb(v-1);
		roads[v-1].pb(u-1);
	}
	rep(i,0,l)
	{
		cin >> u >> v;
		rails[u-1].pb(v-1);
		rails[v-1].pb(u-1);
	}
	
	memset(vis, 0, sizeof vis);
	fill(ans, ans+n, 1);
	memset(root, -1, sizeof root);
	rep(i,0,n)
	{
		if (!vis[i])dfs1(i,i);
	}
	
	memset(vis, 0, sizeof vis);
	rep(i,0,n)
	{
		if (!vis[i]) 
		{
			who.clear();
			dfs2(i);
			for (auto x:who)
			{
				int sz = x.ss.size();
				for (auto y:x.ss) ans[y] = sz;
			}
		}
	}
	
	rep(i,0,n) cout << ans[i] << " ";
}
signed main()
{
	ios_base::sync_with_stdio(false);cin.tie(NULL);
 	
 	#ifdef local
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	clock_t qwertyuiop = clock();
	#endif
 
	int t = 1;
	//cin >> t;	
	rep(a,0,t)
	{
		//cout<<"Case #"<<a+1<<": ";
		solve();
		#ifdef local
			cout << "\n";
		#endif

	}
	
	#ifdef local
	{qwertyuiop = clock() - qwertyuiop;int time_taken = ((int)qwertyuiop)/CLOCKS_PER_SEC;cerr<<fixed<<setprecision(5)<<"\n\nTime Taken : "<<time_taken<<" seconds\n";}
	#endif
}

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

using namespace std;

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

Measured memory_bytes: 256
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize ("Ofast")
#pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include <bits/stdc++.h>
using namespace std;

#define rep(i, n) for(int i = 0; i < (n); ++i)
#define repA(i, a, n) for(int i = a; i <= (n); ++i)
#define repD(i, a, n) for(int i = a; i >= (n); --i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
#define fill(a) memset(a, 0, sizeof (a))
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

const int maxn = 1e5 + 19;
int n,a,b; 
vi h;

bool chk(ll t){
	ll cnt = 0;
	rep(i,n){
		if((h[i]+b-1)/b > t){
		   cnt += (h[i]-t*b + a - b - 1)/(a-b);
		}
	}
	return cnt <= t;
}	

int main() {
	cin.sync_with_stdio(0); cin.tie(0);
	cin.exceptions(cin.failbit);
	cin >> n >> a >> b;
	h.resize(n);
	rep(i,n) cin >> h[i];
	sort(all(h));
	reverse(all(h));
	ll lo = 0, hi = LLONG_MAX/100, mid = (lo+hi)/2;	
	while(hi-lo>1){
		if(chk(mid)){
			hi = mid;
		}else{
			lo = mid;
		}
		mid = (hi+lo)/2;
	}
	cout << hi << endl;
	return 0;
}



Measured memory_bytes: 640