akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <queue>
#include <algorithm>

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define INF 2000000000000LL
using namespace std;

typedef long long Weight;
struct Edge {
  int src, dst;
  Weight weight;
  Edge(int src, int dst, Weight weight) :
    src(src), dst(dst), weight(weight) { }
};
bool operator < (const Edge &e, const Edge &f) {
  return e.weight != f.weight ? e.weight > f.weight : // !!INVERSE!!
    e.src != f.src ? e.src < f.src : e.dst < f.dst;
}
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
typedef vector<Weight> Array;
typedef vector<Array> Matrix;

bool shortestPath(Graph &g,
    Matrix &dist, vector<vector<int> > &prev) {
  int n = g.size();
  Array h(n);
  h.assign(n-1,INF);
  REP(i,n) g[n-1].push_back(Edge(n,i,0));
  REP(k,n) REP(i,n) FOR(e,g[i]) {
    if (h[e->src]<INF && e->weight<INF && h[e->dst] > h[e->src] + e->weight) {
      h[e->dst] = h[e->src] + e->weight;
      if (k == n-1) return false; // negative cycle
    }
  }
  REP(i,n) FOR(e,g[i]) e->weight += h[i] - h[e->dst];
  dist.assign(n, Array(n, INF));
  prev.assign(n, vector<int>(n, -2));
  REP(s, n) {
    priority_queue<Edge> Q;
    Q.push(Edge(s, s, 0));
    while (!Q.empty()) {
      Edge e = Q.top(); Q.pop();
      if (prev[s][e.dst] != -2) continue;
      prev[s][e.dst] = e.src;
      FOR(f,g[e.dst]) {
        if (e.weight<INF && f->weight<INF && dist[s][f->dst] > e.weight + f->weight) {
          dist[s][f->dst] = e.weight + f->weight;
          Q.push(Edge(f->src, f->dst, e.weight + f->weight));
        }
      }
    }
    REP(u, n) {
      if(dist[s][u]<INF)dist[s][u] += h[u] - h[s];
    }
  }
  return true;
}

int main(){
	int r,T,V,E,s,t,e,i,j;
	//for(scanf("%d",&T);T;putchar(--T?' ':'\n')){
		scanf("%d%d",&V,&E);
		Graph g(V+1);
		Matrix dist;
		vector<vector<int> > prev;
		for(i=0;i<V;i++)g[i].push_back(Edge(i,i,0));
		for(;E--;)scanf("%d%d%d",&s,&t,&e),g[s].push_back(Edge(s,t,e));
		if(!shortestPath(g,dist,prev))puts("NEGATIVE CYCLE");
		else for(i=0;i<V;i++)for(j=0;j<V;j++){
			/*if(i==j)printf("0");
			else*/ if(dist[i][j]>=INF)printf("INF");
			else printf("%lld",dist[i][j]);
			printf(j<V-1?" ":"\n");
		}
	//}
}

Measured memory_bytes: 1392
// 2015/06/23 Tazoe

#include <iostream>
using namespace std;

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

	int h[101], m[101];
	for(int i=0; i<N; i++){
		cin >> h[i] >> m[i];
	}
	h[N] = 24;  m[N] = 0;		// 番兵

	int M;
	cin >> M;

	int k[101], g[101];
	for(int j=0; j<M; j++){
		cin >> k[j] >> g[j];
	}
	k[M] = 24;  g[M] = 0;		// 番兵

	for(int i=0, j=0; i<N || j<M; ){
		if(h[i]==k[j] && m[i]==g[j]){
			cout << h[i] << ':' << m[i]/10 << m[i]%10;
			i++;  j++;
		}
		else if(h[i]<k[j] || (h[i]==k[j] && m[i]<g[j])){
			cout << h[i] << ':' << m[i]/10 << m[i]%10;
			i++;
		}
		else{
			cout << k[j] << ':' << g[j]/10 << g[j]%10;
			j++;
		}

		if(i==N && j==M){
			cout << endl;
		}
		else{
			cout << ' ';
		}
	}

	return 0;
}

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

int h[100]={0},ans=0;

void count(int l,int r,int m){
	if(r!=l){
		int min = 101,index;
		for(int i=l;i<r;i++){
			if(h[i] < min){
				min = h[i];
				index = i;
			}
		}
		ans += min-m;
		count(l,index,min);
		count(index+1,r,min);
	}
}

int main(void){
	int n,i;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d",&h[i]);
	}
	count(0,n,0);
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 128
n,k=map(int,input().split())
V=list(map(int,input().split()))
ans=0
for i in range(k+1):
    for j in range(k+1-i):
        if i+j<=n:
            remain=max(0,k-(i+j))
            kouho=V[:i]+V[n-j:]
            kouho.sort()
            if remain>0:
                for t in range(remain):
                    if t<i+j:
                        if kouho[t]<0:
                            kouho[t]=0
            ans=max(ans,sum(kouho))
print(ans)
        
            

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

int main() {
    int N,A,m=1e9+7;
    cin >> N;

    rep(i,N) {
        int c=0;
        cin >> A;
        while(A%2 == 0) {
            A /= 2;
            c++;
        }
        m = min(m,c);
    }

    cout << m << endl;
}

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

#define REP(i,num) for(int i=0;i<(num);++i)
#define LOOP(i) while(i--)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto pitr=c.begin();pitr!=c.end();++pitr){cout<<*pitr;if(next(pitr,1)!=c.end())cout<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

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

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

int count_substr(const string& word,const string& q) {
	int count = 0;
	for (string::size_type pos = 0; (pos = word.find(q, pos)) != string::npos; pos += q.size()) {
		++count;
	}
	return count;
}

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

	int N=in();
	string S=in<string>();
	auto res = count_substr(S,"ABC");
	out(res);
	return 0;
}

Measured memory_bytes: 256
N = int(input())

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

odd_count = 0
four_count = 0

ans = 'Yes'

for i in a:
    if i % 2 == 1:
        odd_count += 1
    if i % 4 == 0:
        four_count += 1

if len(a) % 2 == 0:
    if odd_count > four_count:
        ans = 'No'
else:
    if odd_count <= four_count or len(a) == odd_count + four_count and odd_count -1 <= four_count:
        pass
    else:
        ans = 'No'

print(ans)


Measured memory_bytes: 15020
#include <bits/stdc++.h>
using namespace std;
const int MD=1e9+7;
int main() {
    int n,m,a[100001],p1;
    long long dp[100001];
    memset(dp,0,sizeof(dp));
    cin>>n>>m;
    for (int i=0; i<m; i++) {cin>>p1; a[p1]=1;}
    dp[0]=1;
    for (int i=1; i<=n; i++) {
        if (a[i]) {dp[i]=0; continue;}
        if (i!=1) dp[i]+=dp[i-2];
        dp[i]+=dp[i-1];
        dp[i]%=MD;
    }
    cout<<dp[n]<<'\n';
}

Measured memory_bytes: 4756
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;

int main() {
    int n;
    ll z = 1;
    cin >> n;
    for(int i = 2; i <= n; i++) {
        int y = 0;
        for(int j = 2; j < i; j++) {
            if(i%j == 0) {
                y = 1;
            }
        }

        if(!y) {
            int c = 0;
            for(int k = i; k <= n; k += i) {
                int d = k;
                while(d%i == 0) {
                    d /= i;
                    c++;
                }
            }
            z = z*(c+1)%mod;
        }
    }

    cout << z;

    cout << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <bits/stdc++.h>
#define mod 1000000007
typedef long long ll;

using namespace std;

void Fastio(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}

ll fact[1000006], inv[1000006];

ll fp(ll base, ll exp)
{
    if (exp == 0)
        return 1;
    ll ans = fp(base, exp / 2);
    ans = (ans * ans) % mod;
    if (exp % 2 != 0)
        ans = (ans * (base % mod)) % mod;
    return ans;
}

void calcFacAndInv(ll n)
{
    fact[0] = inv[0] = 1;
    for (ll i = 1; i <= n; i++)
    {
        fact[i] = (i * fact[i - 1]) ;
        inv[i] = fp(fact[i], mod - 2);
    }
}

ll ncr(ll n, ll r)
{
    return ((fact[n] * inv[r]) % mod * inv[n - r]) % mod;
}

ll npr(ll n, ll r)
{
    return (fact[n] * inv[n - r]) % mod;
}

long double  NCR(int n, int m){
    long double res = 1;
    m = min(m, n - m);
    for(int i = 0; i < m; i++){
        res = res * ( n - i) / (i + 1);
 }
    return res;
}
ll tol(string a){
    ll res=0;
    while(a[0]=='0'){
        a.erase(a.begin());
    }
    if(a=="")a="0";
    for(int i=0; i<a.size(); i++){
        res*=10; res+=a[i]-'0';
    }
    return res;
}
int check(string a, string b){
    for(int i=0; i<a.size(); i++){
        if(a[i]>b[i])return 1;
        if(b[i]>a[i])return -1;
    }
    return 0;
}
class data{
public:
    ll v,d,p;
    data(){}
    data(ll vv, ll dd, ll pp){
        v=vv;  d=dd; p=pp;
    }
};

int primeFactors(int n)
{
    ll c=0;
    while (n % 2 == 0)
    {
        c++;
        n = n/2;
    }
    for (int i = 3; i*i <= n; i = i + 2)
    {
        while (n % i == 0)
        {
            c++;
            n = n/i;
        }
    }
    if (n > 2)
        c++;
    return c;
}
ll w[105], p[105], n, x;
ll dp[105][100005];
ll solve(int i, ll sum){
    if(i==n){
        if(sum==0)return 0;
        return 1e10;
    }
    if(dp[i][sum]!=-1)return dp[i][sum];
    ll res1=1e9,res2=1e9;
    if(sum>=p[i])res1=w[i]+solve(i+1,sum-p[i]);
    res2=solve(i+1,sum);
    return dp[i][sum]=min(res1,res2);
}

int main()
{
    Fastio();
    cin>>n>>x;
    ll sum=0, res=0;
    for(int i=0; i<n; i++){cin>>w[i]>>p[i]; sum+=p[i];}
    memset(dp,-1,sizeof(dp));
    for(int i=sum; i>=0; i--){
        if(solve(0,i)<=x){
            return cout<<i<<'\n',0;
        }
    }


    return 0;
}


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

using namespace std;

#define endl "\n"
#define F first
#define S second
#define B begin()
#define E end()
#define PB push_back
#define int long long

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

const int maxn = 1e5;
const int OO = 1e18;

int32_t main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	string s;
	int k;
	cin >> k >> s;
	if(k >= s.size())
	{
		cout << s;
		return 0;
	}
	for(int i=0;i<k;i++)
	cout<<s[i];
	cout << "...";
	
	return 0;
}


Measured memory_bytes: 3672
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <limits.h>
#include <math.h>
#define rep(i,n) for(int i=0; i<n; i++)
typedef long long ll;
const ll mod=1e9+7;

int main(){
	ll N,M,tmp,idx,sum=0;
	ll *A;
	// int i;

	scanf("%lld%lld",&N,&M);

	A = (ll*)malloc(sizeof(ll)*N);
	rep(i,N){
		scanf("%lld",&A[i]);
		sum+=A[i];
	}

	for(int i=0; i<N-1; i++){
		tmp = A[i];
		idx = i;
		for(int j=i+1; j<N; j++){
			if(A[j]>tmp){
				tmp = A[j];
				idx = j;
			}
		}
		A[idx] = A[i];
		A[i] = tmp;
	}

	printf(A[M-1] < (double)sum/(4*M) ? "No" : "Yes");

	free(A);
	return 0;
}

Measured memory_bytes: 128
#include"bits/stdc++.h"
using namespace std;
typedef long long ll;
#define int ll
int32_t main()
{
  #ifndef ONLINE_JUDGE
  freopen("in","r",stdin);
  freopen("out","w",stdout);
  #endif
  string s;

  cin>>s;
  int n=s.length();

  int ans=n;
  for(int i=1;i<n;i++)
  {
    if(s[i-1]!=s[i])ans=min(ans,max(i,n-i));
  }
  cout<<ans;
}

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

int main() {
    int n;
    cin >> n;
    int ans = 0;
    if (n%1000 == 0) {
        ans = 0;
    } else {
        ans = 1000 - (n % 1000);
    }
    cout << ans << endl;
}


Measured memory_bytes: 3648
#include <iostream>
#include <string>
#include <cstdlib>
#include <vector>
#include <array>
#include <map>
#include <algorithm>
#include <queue>
#include <stack>
#include <cmath>

using namespace std;
typedef long long int ll;

int main(int argc, char const *argv[])
{
	ll n;
	cin >> n;
	vector<ll> v(n), c(n), t;

	for(ll i = 0; i < n; i++)
	{
		cin >> v[i];
	}

	vector<pair<ll, ll> > p;
	for (ll i = 0; i < n; i++)
	{
		cin >> c[i];
		t.push_back(v[i] - c[i]);
	}

	sort(t.begin(), t.end(), greater<int>());

	ll ans = 0;
	ll i = 0;
	while (t[i] > 0)
	{
		ans += t[i];
		i++;
	}

	cout << ans << endl;
}

Measured memory_bytes: 256
import sys
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 10 ** 9 + 7

a, b, c, k = LI()

# m = max[a, b, c]
# if k - m >

x = k - a
y = x - b
z = y - c

if x <= 0:
    print(k)
    sys.exit()
elif (x > 0) and (y <= 0):
    print(a)
    sys.exit()
elif (y > 0):
    print(a - y)
    sys.exit()


Measured memory_bytes: 9184
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <queue>

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

    std::map<
        std::string,
        std::priority_queue<std::pair<int, int>>
    > m;

    for (int i = 1; i <= N; i++) {
        std::string S;
        int P;
        std::cin >> S >> P;
        m[S].push(std::make_pair(P, i));
    }

    for (auto p: m) {
        auto que = p.second;
        while (!que.empty()) {
            std::cout << que.top().second << "\n";
            que.pop();
        }
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstring>
#include <climits>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;

constexpr ll INF = 1e18;
constexpr ll MOD = 1e9 + 7;
constexpr double PI = 3.14159265358979323846;
constexpr int di[] = {0, 0, 1, -1};
constexpr int dj[] = {1, -1, 0, 0};

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

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

    cout << (t / a) * b << endl;

    return 0;
}

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

typedef long long ll;

using namespace std;

int main(void){
	int n; cin >> n;
	ll a=0, b=1;
	while(n--){
		int q, x; cin >> q >> x;
		if(q == 1){
			b *= x;
			a *= x;
		} else if(q == 2) a -= x;
		else a += x;
	}
	cout << a << " " << b << endl;
	return 0;
}


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

//template
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(a);i>(b);i--)
#define ALL(v) (v).begin(),(v).end()
typedef long long int ll;
const int inf = 0x3fffffff; const ll INF = 0x1fffffffffffffff; const double eps=1e-12;
string to_str(ll x){string res; while(x)res+=('0'+(x%10)),x/=10; reverse(ALL(res)); return res;}
template<class T> inline bool chmax(T& a,T b){ if(a<b){a=b;return 1;}return 0; }
template<class T> inline bool chmin(T& a,T b){ if(a>b){a=b;return 1;}return 0; }
//template end

typedef complex<double> com;
void fft(vector<com>& a,bool inv=false){
    int n=a.size(),mask=n-1; vector<com> tmp(n);
    for(int i=n>>1;i;i>>=1){
        double theta=2*M_PI*i*(inv?-1:1)/n;
        com z(1),z_0(cos(theta),sin(theta));
        for(int j=0;j<n;j+=i){
            rep(k,0,i)tmp[j|k]=a[((j<<1)&mask)|k]+z*a[(((j<<1)|i)&mask)|k];
            z*=z_0;
        } swap(a,tmp);
    }
    if(inv)rep(i,0,n)a[i]/=n;
}
void v_mul(vector<ll>& a,vector<ll> b){
    int n=a.size(),m=b.size(),maxx=1; while(maxx<=n+m)maxx*=2;
    vector<com> x(maxx),y(maxx);
    rep(i,0,n)x[i]=com(a[i],0); rep(i,0,m)y[i]=com(b[i],0);
    fft(x,0), fft(y,0); rep(i,0,maxx)x[i]*=y[i];
    fft(x,1); a.resize(maxx); rep(i,0,maxx)a[i]=(x[i].real()+0.5);
}

int main(){
    int n; ll m; scanf("%d%lld",&n,&m);
    vector<ll> a(100010);
    rep(i,0,n){
        int tmp; scanf("%d",&tmp);
        a[tmp]++;
    }
    v_mul(a,a); ll cnt=0,res=0;
    rrep(i,200010,-1){
        if(cnt+a[i]>m){
            res+=(m-cnt)*i;
            break;
        }
        cnt+=a[i]; res+=a[i]*i;
    }
    printf("%lld\n",res);
    return 0;
}

Measured memory_bytes: 14464
package main

import (
	"fmt"
	"strings"
		)

func main() {
	var a string
	fmt.Scan(&a)

	if strings.Contains(a, "a") && strings.Contains(a, "b") && strings.Contains(a, "c") {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}

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

using namespace std;

typedef long long ll;
typedef long double ld;

ll niz[1000005];

int main(){
    ios_base::sync_with_stdio(false);
	cout.precision(10);
	cout << fixed;

    int n;
    cin >> n;
    n *= 3;
    for(int i=1; i<=n; i++){
        cin >> niz[i];
    }
    sort(niz+1, niz+1+n);
    ll sum = 0;
    for(int i=n-1; i>n/3; i-=2){
        sum += niz[i];
    }
    cout << sum;
    return 0;
}


Measured memory_bytes: 4352
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <algorithm>
#include <set>
#include <stdio.h>
using namespace std;

int main(){
	int N; cin >> N;
	int ac = 0;
	int wa = 0;
	int tle = 0;
	int re = 0;
	for (int i = 0; i < N; i++) {
		string S; cin >> S;
		if (S == "AC") ac++;
		else if(S == "WA") wa++;
		else if (S == "TLE") tle++;
		else if (S == "RE") re++;
	}
	cout << "AC x " << ac << endl;
	cout << "WA x " << wa << endl;
	cout << "TLE x " << tle << endl;
	cout << "RE x " << re << endl;
}

Measured memory_bytes: 3604
let pair =
    function
    | [| x; y |] -> x, y
    | _ -> failwith "Error in pair"

let input isDev =
    if isDev then
        //let n = 2
        //let a = [| 1; 2 |]
        //let b = [| 2; 3 |]
        let n = 3
        let a = [| 100; 10; 1 |]
        let b = [| 100; 10000; 1000000000 |]
        n, a, b
    else
        let n = stdin.ReadLine() |> int

        let ab =
            [| for _ in 1 .. n -> stdin.ReadLine().Split() |> Array.map int |> pair |]

        n, ab |> Array.map fst |> Array.sort, ab |> Array.map snd |> Array.sort

let n, a, b = input false

let cnt =
    if n % 2 = 0 then
        // 変数なしで配列の添え字にそのまま入れると
        // 2 回計算することになるのではじめに計算しておく
        let i = n / 2 - 1
        let j = n / 2
        // 0 オリジンで計算していることに注意
        // 本来のメジアンの定義はこの 1/2 だが求める個数の勘定で 2 倍する
        // そこではじめから 1/2 をつけずに計算している
        let amed2 = a.[i] + a.[j]
        let bmed2 = b.[i] + b.[j]
        bmed2 - amed2 + 1
    else
        let i = n / 2
        let amed = a.[i]
        let bmed = b.[i]
        bmed - amed + 1

cnt |> printfn "%d"

Measured memory_bytes: 52632
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const double PI = 3.141592653589793238;
const double EPS = 1e-10;
ll a[1000];
int main() {
	int N, K;
	cin >> N >> K;
	for (int i = 0; i < N; i++) {
		cin >> a[i];
	}
	for (int i = 1; i < N; i++) a[i] += a[i - 1];
	vector<ll> vec;
	for (int i = 0; i < N; i++) {
		for (int j = i; j < N; j++) {
			ll sum = a[j];
			if (i > 0) sum -= a[i - 1];
			vec.push_back(sum);
		}
	}
	vector<bool> ok(vec.size(), true);
	ll ans = 0;
	for (int i = 50; i >= 0; i--) {
		int cnt = 0;
		for (int j = 0; j < vec.size(); j++) {
			if (!ok[j]) continue;
			if (vec[j] & (1LL << i)) cnt++;
		}
		if (cnt < K) continue;
		for (int j = 0; j < vec.size(); j++) {
			if (!ok[j]) continue;
			if (!(vec[j] & (1LL << i))) ok[j] = 0;
		}
		ans |= 1LL << i;
	}
	cout << ans << endl;

}


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

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

#define pb push_back
#define rep(i, n) for(int i = 0; i < (n); i++)
#define dep(i, a, n) for(int i = a; i >= (n); i--)
#define FOR(i, a, n) for(int i = a; i < (n); i++)
#define mod (ll)(1e9+7)
#define int ll
#define INF 100000000

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

signed main() {
	ll a, b;
  cin >> a >> b;
  if(a + b == 15) cout << '+' << endl;
  else if(a * b == 15) cout << '*' << endl;
  else cout << 'x' << endl;
	return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using static MyIO;


public class D
{
	public static void Main()
	{
		int N = GetInt();

		List<int> primeList = sieve(55555);
		int numPuts = 0;
		for(int i = 0; i < primeList.Count; i++)
		{
			if(primeList[i] % 5 != 1)
				continue;
			Console.Write("{0} ", primeList[i]);
			numPuts++;
			if(numPuts == N)
				break;
		}
		Console.WriteLine();
	}

	private static List<int> sieve(int N)
	{
		List<int> primeList = new List<int>();
		bool[] isPrime = new bool[N+1];
		for(int i = 2; i <= N; i++)
			isPrime[i] = true;

		for(int i = 2; i <= N; i++)
		{
			if(isPrime[i])
			{
				primeList.Add(i);
				for(int j = 2 * i; j <= N; j += i)
					isPrime[j] = false;
			}
		}

		return primeList;
	}
}


public static class MyIO
{
	private static string[] args = null;
	private static int num = -1;
	private static int used = -1;

	private static string getArg()
	{
		if(used == num)
		{
			args = Console.ReadLine().Split(' ');
			num = args.Length;
			used = 0;
		}
		return args[used++];
	}

	public static int GetInt(){ return int.Parse(getArg()); }
	public static long GetLong(){ return long.Parse(getArg()); }
	public static double GetDouble(){ return double.Parse(getArg()); }
	public static string GetString(){ return getArg(); }
}


Measured memory_bytes: 11216
S = list(map(int,list(input())))

if 1 <= S[0] * 10 + S[1] <= 12 and 1 <= S[2] * 10 + S[3] <= 12:
    print("AMBIGUOUS")
    exit()
if 1 <= S[0] * 10 + S[1] <= 12 and 0 <= S[2] * 10 + S[3]:
    print("MMYY")
    exit()
if 0 <= S[0] * 10 + S[1] and 1 <= S[2] * 10 + S[3] <= 12:
    print("YYMM")
    exit()

print("NA")


Measured memory_bytes: 38384
#include<cstdio>
#include<cstring>
#include<algorithm>
#define ll long long
const int Max=210;
using namespace std;
int prim[Max],phi[Max],vis[Max];
int cnt=0;
int n;
void init(){
	phi[1]=1;
	for(int i=2;i<Max;i++){
		if(!vis[i]){
			prim[++cnt]=i;
			phi[i]=i-1;
		}
		for(int j=1;j<=cnt&&i*prim[j]<Max;j++){
			vis[i*prim[j]]=1;
			if(i%prim[j]==0){
				phi[i*prim[j]]=phi[i]*prim[j];
				break;
			}
			else{
				phi[i*prim[j]]=phi[i]*(prim[j]-1);
			}
		}
	}
	for(int i=2;i<Max;i++){
		phi[i]+=phi[i-1];
	}
}
ll sum(int x){
	return 1ll*x*x*x;
}
ll solve(){
	ll ans=0;
	for(int l=1,r;l<=n;l=r+1){
		r=n/(n/l);
		ans+=(phi[r]-phi[l-1])*sum(n/l);
	}
	return ans;
}
int main(){
	init();
	scanf("%d",&n);
	printf("%lld\n",solve());
	return 0;
}

Measured memory_bytes: 1708
#include <cstdio>

typedef long long ll;
const int MAXN = 5005, MOD = 1000000007;

int N; ll g[MAXN], f[MAXN][MAXN], tmp[MAXN], ans;
struct node { int v, next; } E[MAXN << 1]; int head[MAXN], Elen;
void add(int u, int v) { ++Elen, E[Elen].v = v, E[Elen].next = head[u], head[u] = Elen; }

int siz[MAXN];
void dfs(int u, int ff) {
	f[u][1] = 1, siz[u] = 1;
	for (int i = head[u]; i; i = E[i].next) if (E[i].v != ff) {
		dfs(E[i].v, u);
		//printf("(%d, %d)\n", u, E[i].v);
		for (int j = 1; j <= siz[u]; ++j) for (int k = 1; k <= siz[E[i].v]; ++k) tmp[j + k] = (tmp[j + k] + f[u][j] * f[E[i].v][k]) % MOD;
		//for (int j = 1; j <= siz[u] + siz[E[i].v]; ++j) printf("tmp[%d] = %lld\n", j, tmp[j]);
		ll ovo = 0;
		for (int j = 1; j <= siz[E[i].v]; ++j) ovo = (ovo + f[E[i].v][j] * g[j]) % MOD;
		siz[u] += siz[E[i].v];
		for (int j = 1; j <= siz[u]; ++j) f[u][j] = (tmp[j] - f[u][j] * ovo) % MOD, tmp[j] = 0;
	}
	//for (int i = 1; i <= siz[u]; ++i) printf("f[%d][%d] = %lld\n", u, i, f[u][i]);
}

int main() {
	scanf("%d", &N); int u, v;
	for (int i = 1; i < N; ++i) scanf("%d%d", &u, &v), add(u, v), add(v, u);
	g[0] = 1;
	for (int i = 2; i <= N; i += 2) g[i] = g[i - 2] * (i - 1) % MOD;
	dfs(1, 0);
	for (int i = 1; i <= N; ++i) ans = (ans + f[1][i] * g[i]) % MOD;
	printf("%lld\n", (ans + MOD) % MOD);
	return 0;
}

Measured memory_bytes: 194944
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define reps(i,s,n) for(int (i)=(s);(i)<(n);(i)++)
#define repr(i,n) for(int (i)=(n)-1;(i)>=0;(i)--)
#define all(v) (v).begin(),(v).end()
#define chmax(a, b) a = max((a),(b))
#define chmin(a, b) a = min((a),(b))
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define inf 1000000000
#define llinf 1000000000000000
 
 
typedef long long ll;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef pair<int,int> pint;
typedef pair<ll,ll> pll;
typedef vector<pint> vpint;
 

 
int main() {
    int n;
    cin>>n;
    vint a(n+3);
    vint table(n+3);
    reps(i,1,n+1)cin>>a[i];
    
    for(int i=n;i>=1;i--){
        int sum=0;
        for(int j=i+i;j<=n;j+=i){
            sum+=table[j];
        }
        table[i]=(a[i]+2-sum%2)%2;
    }
    int anssum=0;
    reps(i,1,n+1){
        anssum+=table[i];
        //cout<<table[i]<<endl;
    }
    cout<<anssum<<endl;
    int count=0;
    reps(i,1,n+1){
        if(table[i]==1){
            cout<<i;
            count++;
            if(count==anssum){
                cout<<endl;
            }
            else{
                cout<<" ";
            }
        }
    }
}

Measured memory_bytes: 2432
import java.io.*;
import java.util.*;
public class Main{
    public static void main(String[] args) throws IOException{
        MyReader r = new MyReader();  
        int M, D; {int[] a = r.ii(); M = a[0]; D = a[1];}
        int ans = 0;
        for(int m = 1; m <= M; m++){
            for(int d = 22; d <= D; d++){
                int d1 = d%10;
                int d10 = d/10;
                if(d1 >= 2 && d10 >= 2 && d1*d10 == m)
                    ans++;
            }
        }
        println(ans);
    }
    static void print(Object o){
        System.out.print(o.toString());
    }
    static void println(Object o){
        System.out.println(o.toString());
    }
    static int Int(String s){
        return Integer.parseInt(s);
    }
    static long Long(String s){
        return Long.parseLong(s);
    }
    static class MyReader extends BufferedReader{
        MyReader(){
            super(new InputStreamReader(System.in));
        }
        String s() throws IOException{
            return readLine();
        }
        String[] ss() throws IOException{
            return s().split(" ");
        }
        int i() throws IOException{
            return Int(s());
        }
        int[] ii() throws IOException{
            String[] ss = ss();
            int size = ss.length;
            int[] ii = new int[size];
            for(int j = 0; j < size; j++) ii[j] = Integer.parseInt(ss[j]);
            return ii;
        }
        long l() throws IOException{
            return Long(s());
        }
        long[] ll() throws IOException{
            String[] ss = ss();
            int size = ss.length;
            long[] ll = new long[size];
            for(int j = 0; j < size; j++) ll[j] = Long.parseLong(ss[j]);            
            return ll;
        }
    }
}

Measured memory_bytes: 21332
#include <iostream>

int main() {
    while (true) {
        uint32_t x, y;
        std::cin >> x >> y;
        if (x == 0 && y == 0) {
            break;
        }
        if (x > y) {
            std::swap(x, y);
        }
        std::cout << x << ' ' << y << std::endl;
    }
}


Measured memory_bytes: 3100
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
const long long INF = 1LL << 60;

long power(long a, long b) {
    return b ? power(a*a%MOD, b/2) * (b%2?a:1)%MOD:1;
}

long perm(int N, int K) {
    long x = 1;
    for(int i = 1; i <= K; i++) x = x * (N-i+1) % MOD;
    return x % MOD;
}

long comb(int N,int K) {
    long x = 1, y = 1;
    for(int i = 1; i <= K; i++) {
        x = x * (N-i+1) % MOD;
        y = y * i % MOD;
    }
    return x * power(y, MOD-2) % MOD;
}

bool isprime(int n) {
    if(n < 2) return false;
    for(int i = 2; i*i <= n; ++i) {
        if (n % i ==  0) return false;
    }
    return true;
}

void dfs(const vector<vector<int> > &G, int v, vector<int> &seen) {
    seen[v] = true;

    for(int next_v : G[v]) {
        if(seen[next_v]) continue;
        dfs(G, next_v, seen);
    }
}

void yes() { cout << "Yes" << endl;}
void no() { cout << "No" << endl;}



int main() {
  int a, b, h, m; cin >> a >> b >> h >> m;
  double const PI = acos(-1);
  double arg_h = (60*h + m) * 2 * PI / (60*12);
  double arg_m = (m * PI) / 30;
  double theta = arg_h - arg_m;
  double dist = sqrt(a*a + b*b - 2*a*b*cos(theta));
  //cout << dist << endl;
  printf("%.20f", dist);
}

Measured memory_bytes: 4056
X, Y = 0, 1

W, H, N = gets.split.map &:to_i
P = N.times.map{gets.split.map &:to_i}

p P.each_cons(2).map{|from ,to|
  dx = to[X] - from[X]
  dy = to[Y] - from[Y]
  dx * dy < 0 ? dx.abs + dy.abs : [dx.abs, dy.abs].max
}.inject(:+)

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

using namespace std;

void solve()
{
    int n, ans = 1;
    cin >> n;
    while (ans * 2 <= n)
    {
        ans *= 2;
    }
    cout << ans << endl;
}

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



Measured memory_bytes: 3104
#include <iostream>
#include <bitset>
#include <algorithm>
 
using namespace std;
 
bitset<10000> cookie[10];
 
///////////////////////////SubMain//////////////////////////////////
int main(int argc, char *argv[])
{
 
    int R, C;
    while(cin >> R >> C && R > 0)
    {
        int i, j;
        for (i = 0; i < R; ++i)
        {
            for (j = 0; j < C; ++j)
            {
                bool upwards;
                cin >> upwards;
                cookie[i][j] = upwards;
            }
        }
 
        // 在横向一共有2^R&#31181;&#21464;&#25442;
        int permute_r = 1 << R;
        int result = 0;
        for (i = 0; i < permute_r ; ++i)
        {
            // 完成当前的&#21464;&#25442;
            for (j = 0; j < R; ++j)
            {
                // &#36825;一行是否&#24212;当翻个面
                if (i & (1 << j))
                {
                    cookie[j].flip();
                }
            }
             
 
            // &#23545;&#27599;一列分&#21035;算出朝上和朝下的煎&#39292;个数，取其最大&#20540;
            int possible_answer = 0;
            for (j = 0; j < C; ++j)
            {
                int up_cookie_count = 0;
                for (int k = 0; k < R; ++k)
                {
                    if (cookie[k][j])
                    {
                        ++up_cookie_count;
                    }
                }
                possible_answer += max(up_cookie_count, R - up_cookie_count);
            }
            // &#32467;果取最大&#20540;
            result = max(result, possible_answer);
             
            // &#22797;原
            for (j = 0; j < R; ++j)
            {
                if (i & (1 << j))
                {
                    cookie[j].flip();
                }
            }
        }
        cout << result << endl;
    }
 
    return 0;
}

Measured memory_bytes: 1172
from collections import deque
H,W = map(int,input().split())
grid = [0] * H
num_black = 0
for i in range(H):
    s = input()
    for j in range(len(s)):
        if s[j] == '#':
            num_black += 1
    grid[i] = list(s)
time_grid = [[-1] * W for _ in range(H)]
time_grid[0][0] = 0
queue = deque()
queue.append([0,0,0])
while queue:
    y,x,t = queue.popleft()
    for next_y, next_x in [[y+1,x],[y,x+1],[y-1,x],[y,x-1]]:
        if 0 <= next_x < W and 0 <= next_y < H and grid[next_y][next_x] == '.':
            queue.append([next_y,next_x,t+1])
            time_grid[next_y][next_x] = t+1
            grid[next_y][next_x] = '#'
if time_grid[H-1][W-1] != -1:
    print(H*W-time_grid[-1][-1]-1-num_black)
else:
    print(-1)




Measured memory_bytes: 9484
S = input()
T = input()

ans = len(T)
f = 0
for i in range(len(S)-len(T)+1):
  st = S[f:f+len(T)]
  iti = sum([1 for i,j in zip(st, T) if i == j])
  ans = min(ans, len(T)-iti)
  f += 1
  
print(ans)

Measured memory_bytes: 9124
import java.util.Arrays;
import java.util.Scanner;

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

    long N = scanner.nextLong();
    int M = 1_000_000_007;

    int t = 0;
    long n = N;
    while (n > 0) {
      n /= 2;
      t++;
    }

    long[][] dp = new long[t + 1][3];
    dp[0][0] = 1;
    for (int i = 1; i <= t; i++) {
      if ((N >> (i - 1)) % 2 == 0) {
        dp[i][0] = dp[i - 1][0];
        dp[i][1] = dp[i - 1][2];
        dp[i][1] += dp[i - 1][0] * 2 % M;
        dp[i][1] %= M;
        dp[i][1] += dp[i - 1][1] * 2 % M;
        dp[i][1] %= M;
        dp[i][2] = dp[i - 1][1];
        dp[i][2] += dp[i - 1][2] * 2;
        dp[i][2] %= M;
      } else {
        dp[i][0] = dp[i - 1][1];
        dp[i][0] += dp[i - 1][0] * 2;
        dp[i][0] %= M;
        dp[i][1] = dp[i - 1][0];
        dp[i][1] += dp[i - 1][1] * 2;
        dp[i][1] %= M;
        dp[i][1] += dp[i - 1][2] * 2;
        dp[i][1] %= M;
        dp[i][2] = dp[i - 1][2];
      }
    }

    System.out.println(dp[t][0]);
  }
}

Measured memory_bytes: 23380
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
int main(){
    int n; 
    
    int ans=-1;
    string s;
    cin >> n >> s;
    string a,b;
    for(int i=1; i<n; i++){
        int syrui=0;
        map<char,int> cnt_1;
        map<char,int> cnt_2;
        a = s.substr(0,i);
        b = s.substr(i,n-i);
       rep(i,a.size()){
           cnt_1[a[i]] ++ ;
       }
       rep(i,b.size()){
           cnt_2[b[i]] ++;
       }
        for(auto c: cnt_1 ){
           if( cnt_2[c.first] > 0) syrui++;
        }
       
        ans = max(ans,syrui);
    }
    cout << ans << endl;
}

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

int main()
{
    int x, num;
    int Min = 9999;
    int cnt = 0;
    int minNum = 9999;
    bool exists;
    cin >> x >> num;

    vector<int> vec(num);
    for (int i = 0; i < num; i++)
        cin >> vec.at(i);

    if (vec.size() == 0)
    {
        cout << x;
        return 0;
    }

    for (int i = -100; i <= 200; i++)
    {
        exists = find(vec.begin(), vec.end(), i) != vec.end();
        if (exists == true)
        {
            continue;
        }

        if (Min == abs(x - i))
        {
            cnt++;
            minNum = min(minNum, i);
        }
        else
        {
            if (Min > abs(x - i))
            {
                Min = min(Min, abs(x - i));
                minNum = i;
                cnt = 1;
            }
        }
    }

    cout << minNum;
}

Measured memory_bytes: 3628
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
 
int main() {
  string divide[4] = {"dream","dreamer","erase","eraser"};
  string s;
  cin >> s;
  reverse(s.begin(), s.end());
  for (int i = 0; i < 4; i++) reverse(divide[i].begin(), divide[i].end());
  
  bool can = true;
  for (int i = 0; i < s.size();) {
    bool can2 = false;
    for (int j = 0; j < 4; j++) {
      string d = divide[j];
      if (s.substr(i, d.size()) == d) {
        can2 = true;
        i += d.size();
      }
    }
    if (!can2) {
      can = false;
      break;
    }
  }
  if (can) cout << "YES" << endl;
  else cout << "NO" << endl;
}

Measured memory_bytes: 512
a,b,k = map(int,input().split(" "))
if b - a + 1 >= 2*k:
    for i in range(k):
        print(a+i)
    for i in range(k):
        print(b-k+i+1)
else:
    for i in range(a,b+1):
        print(i)

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

import static java.lang.Integer.parseInt;

public class Main {

	static final int CHARS = 31;
	static final int[] WORDS = new int[]{5, 7, 5, 7, 7};

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

		while ((line = br.readLine()) != null && !line.isEmpty()) {

			int n = parseInt(line);
			if (n == 0) break;

			int[] words = new int[n + 1];
			for (int i = 1; i <= n; i++) {
				words[i] = br.readLine().length();
				words[i] += words[i - 1];
			}

			int k = 0;
			outer:
			for (int i = 1; i <= n; i++) {
				for (int j = n; j >= i; j--) {
					if (words[j] - words[i - 1] == CHARS) {
						//check
						if (check(words, i, j)) {
							k = i;
							break outer;
						}
					}
				}
			}
			System.out.println(k);
		} //end while
	} //end main

	static boolean check(int[] words, int from, int to) {
		boolean ret = true;
		int _j = from;
		for (int i = 0; i < WORDS.length; i++) {
			for (int j = _j; j <= to; j++) {
				int len = words[j] - words[_j - 1];
				if (len == WORDS[i]) {
					_j = j + 1;
					break;
				} else if (len > WORDS[i]) {
					ret &= false;
				}
			}
		}
		return ret;
	}
}

Measured memory_bytes: 24504
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

	private static int[] getStrings(Scanner sc, int num) {
		int[] stringList = new int[num];
		int i = 0;
		while(i<num) {
			int nextInt = sc.nextInt();
			stringList[i] = nextInt;
			i++;
		}
		return stringList;
	}

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		int[] m = getStrings(sc, n);
		for (int i = 0; i < k; i++) {
			int[] two = new int[n+1];

			for (int j = 0; j < n; j++) {
				int l = Math.max(j - m[j], 0);
				int max = Math.min(j + m[j], n-1) + 1;
				two[l]++;
				two[max]--;
			}
			for (int o = 0; o < n; o++) {
				two[o+1] += two[o];
			}
			if (isSame(m, two)) {
				break;
			}
			m = two;
		}
		for (int j = 0; j < n; j++) {
			System.out.println(m[j]);
		}
	}

	private static boolean isSame(int[] m, int[] n) {
		for (int i = 0; i < m.length; i++) {
			if (m[i] != n[i]) {
				return false;
			}
		}
		return true;
	}

}


Measured memory_bytes: 62420
#include <iostream>
#include <sstream>
#include <string>
#include <cmath>
#include <array>
#include <vector>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <utility>
#include <iomanip>
#include <numeric>
#include <climits>
#include <algorithm>
#include <cstdint>
using namespace std;

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

    vector<int> niz(n);
    int max = INT_MIN, max_idx = -1;
    int max2 = INT_MIN, max2_idx = -1;
    for (int i = 0; i < n; i++)
    {
        cin >> niz[i];
        if (niz[i] > max)
        {
            max = niz[i];
            max_idx = i;
        }
    }
    for (int i = 0; i < n; i++)
    {
        if (niz[i] > max2 && i != max_idx)
        {
            max2 = niz[i];
            max2_idx = i;
        }
    }

    for (int i = 0; i < n; i++)
    {
        if (i != max_idx)
            cout << niz[max_idx] << endl;
        else cout << niz[max2_idx] << endl;
    }
}

Measured memory_bytes: 4048
x, n = gets.split.map(&:to_i)
if n == 0
  puts x
  exit
end
p = gets.split.map(&:to_i)
h = Hash.new(0)
p.each do |v|
  h[v] += 1
end
min = Float::INFINITY
-1.upto(101) do |i|
  next if h[i] > 0
  min = (x - i).abs if min > (x - i).abs
end
if h[x - min] == 0
  puts x - min
else
  puts x + min
end

Measured memory_bytes: 14380
sel='C'
#A
if sel=='A':
    N,M=map(int,input().split())
    ans=0
    ans+=M*(M-1)//2
    ans+=N*(N-1)//2
    print(ans)

#B
if sel=='B':
    def ispal(s):
        for i in range(len(s)//2+1):
            if s[i]!=s[-(i+1)]:
                return False
        return True

    S=input()
    if ispal(S) and ispal(S[:(N-1)//2]) and ispal(S[(N+3)//2-1:]):
        print('Yes')
    else:
        print('No')

#C
if sel=='C':
    L=int(input())
    print((L**3)/27)

#D
if sel=='D':    
    N=int(input())
    A=[int(i) for i in input().split()]
    kin=list(set(A))
    cnt={}
    for k in kin:
        cnt[k]=0
    for a in A:
        cnt[a]+=1
    SUM=0
    for k in kin:
        SUM+=cnt[k]*(cnt[k]-1)//2
    for a in A:
        if cnt[a]>=2:
            print(SUM-cnt[a]+1)
        else:
            print(SUM)
        
#E
if sel=='E':
    a=0

#F
if sel=='F':
    N,S=map(int,input().split())
    A=[int(i) for i in input().split()]

    for l in range(N):
        for r in range(l,N):
            print(tab[l][r])



Measured memory_bytes: 3064
#define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f

#include <iostream>
#include <cstdio>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>
  
using namespace std;
  
typedef long long ll;
typedef pair <int,int> P;
typedef pair <int,P> PP;
  
static const double EPS = 1e-8;
  
static const int tx[] = {0,1,0,-1};
static const int ty[] = {-1,0,1,0};

int dp[5000001]; //dp[capacity] ::= min_price

int main(){
  int total_manju;
  int total_box;
  while(~scanf("%d %d",&total_manju,&total_box)){
    vector<int> manju;
    for(int manju_idx=0;manju_idx<total_manju;manju_idx++){
      int price;
      scanf("%d",&price);
      manju.push_back(price);
    }

    sort(manju.begin(),manju.end(),greater<int>());
    int sum[10001];
    memset(sum,0,sizeof(sum));
    for(int manju_idx=0;manju_idx<total_manju;manju_idx++){
      sum[manju_idx + 1] = sum[manju_idx] + manju[manju_idx];
    }


    memset(dp,0x3f,sizeof(dp));

    dp[0] = 0;
    for(int box_idx=0;box_idx<total_box;box_idx++){
      int capacity;
      int price;
      scanf("%d %d",&capacity,&price);
      for(int prev_manju_num = 500*10000; prev_manju_num >=0; prev_manju_num--){
        if(prev_manju_num + capacity > 500*10000) continue;
        dp[prev_manju_num + capacity]
          = min(dp[prev_manju_num + capacity],
                dp[prev_manju_num] + price);
      }
    }

    for(int prev_manju_num = 500*10000; prev_manju_num >=0; prev_manju_num--){
      if(prev_manju_num + 1 >= 500*10000) continue;
      dp[prev_manju_num] = min(dp[prev_manju_num],dp[prev_manju_num + 1]);
    }
    
    int res = 0;
    for(int manju_num=1;manju_num<=total_manju;manju_num++){
      res = max(sum[manju_num] - dp[manju_num],res);
    }

    printf("%d\n",res);
  }
}

Measured memory_bytes: 20888
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <string>
#include <iostream>
#include <algorithm>
#include <queue>
#include <map>
using namespace std;
const int maxn = 1e2 + 10;
char A[maxn];
int main()
{
	int N;
	while( ~scanf(" %d",&N) ){
		int flag1 = 0, flag2 = 0 , flag3 = 0 , flag4 = 0;
		int check = 0;
		for( int i = 0 ; i < N ; i++ ){
			scanf(" %c",&A[i]);
			if( A[i] == 'P' && flag1 == 0 ){
				flag1 = 1;
				check += 1;
			}
			if( A[i] == 'W' && flag2 == 0 ){
				flag2 = 1;
				check += 1;
			}
			if( A[i] == 'G' && flag3 == 0 ){
				flag3 = 1;
				check += 1;
			}
			if( A[i] == 'Y' && flag4 == 0 ){
				flag4 = 1;
				check += 1;
			}
		}
		if( check == 3 )
		printf("Three\n");
		else if( check == 4 )
		printf("Four\n");
	}
}

Measured memory_bytes: 256
// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
//#define int ll
typedef ll Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
//#define mt make_tuple
//typedef tuple<int,int,int> tp;
//typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
//template<class C>constexpr int size(const C &c){return (int)c.size();}
//template<class T,size_t N> constexpr int size(const T (&xs)[N])noexcept{return (int)N;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
int main(){
	int n;
	cin>>n;
	vi in(n);
	rep(i,n)cin>>in[i];
	
	vi dp(n),f(n);
	ll ma=-inf,mai;
	rep(i,n){
		dp[i]=in[i];
		f[i]=i;
		rep(j,i)if((i-j)%2==0){
			if(dp[i]<dp[j]+in[i]){
				dp[i]=dp[j]+in[i];
				f[i]=j;
			}
		}
		if(ma<dp[i]){
			ma=dp[i];
			mai=i;
		}
	}
	cout<<ma<<endl;
	vi out;
	rep(i,n-mai-1)out.pb(n-i);
	while(f[mai]-mai){
		int t=f[mai];
		while(mai-t!=2){
			out.pb(t+3);
			mai-=2;
		}
		out.pb(t+2);
		mai-=2;
	}
	rep(i,mai)out.pb(1);
	
	cout<<out.size()<<endl;
	rep(i,out.size())cout<<out[i]<<endl;
}




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

int main() {
    int n;
    cin >> n;
    vector<vector<int>> ps(n, vector<int>(3));
    for(int i = 0; i < n; ++i) {
        for(int j = 0; j < 3; ++j) {
            cin >> ps[i][j];
        }
        sort(begin(ps[i]), end(ps[i]));
    }
    sort(begin(ps), end(ps));
    ps.erase(unique(begin(ps), end(ps)), end(ps));
    cout << n - ps.size() << endl;
}



Measured memory_bytes: 3196
A,B = map(int,input().split())
def factorize2(n): # 素因数分解　2次元素数リスト([素数,指数])
    i = 2
    m = 1
    table = []
    sign = -1
    while i * i <= n:
        j = 0
        while n % i == 0:
            n //= i
            j += 1
        if j != 0:
            table.append([i,j])
        if i >= 5:
            if sign < 0:
                sign = 1
                i = 6*m + sign
            else:
                m += 1
                sign = -1
                i = 6*m + sign
        elif i == 2:
            i += 1
        elif i == 3:
            i = 5
    if n > 1:
        table.append([n,1])
    return table # list
AL = [i[0] for i in factorize2(A)]
BL = [i[0] for i in factorize2(B)]
ans = len(set(AL)&set(BL))+1
print(ans)





Measured memory_bytes: 40172
#include <stdio.h>
#include <iostream>
#include <queue>
#include <string>
#include <algorithm>
#include <cstdio>
#include <stack>
#include <vector>
#include <map>
#include <ctime>
#include <string.h>
#define inf 0x7fffffff
using namespace std;


long long d,a,b,c,n,m,k,l[300010],o[300100],i;

int j[201000][10]={{1,0,-1,0},{0,-1,0,1}};
long long z[110][60],x,y;
char r[300],r1[600];
//deque<int> d;
vector<int> v[101000];
//A 65 a 97
//z 122 Z 90
/*struct P
{
    int x,y;
    bool operator<(const P &a)const
    {
        //printf("#%d %d\n",o[x],o[y]);
        return min(o[x],o[y])>min(o[a.x],o[a.y]);
    }
};*/
queue<int> q;

long long f(long long t,long long w)
{
    if(t==a&&w==b) return 1;
    if(t==a) return 0;
    if(z[t][w]>=0) return z[t][w];
    return z[t][w]=f(t+1,(w+o[t])%2)+f(t+1,w);
}

int main()
{
    scanf("%lld %lld %lld %lld %lld",&n,&a,&b,&c,&d);
    //printf("%d %d %d %d %d",n,a,b,c,d);
    if(a>b) swap(a,b);
    if((b-a)>d*(n-1))
    {
        //printf("%lld %lld",b-a,d*(n-1));
        puts("NO");
        return 0;
    }
    if((b-a)<=d*(n-1)&&(b-a)>=c*(n-1))
    {
        puts("YES");
        return 0;
    }
    n--;
    for(int t=1;t<=n;t++)
    {
        if((b-a)+t*c<=(n-t)*d&&(b-a)+t*d>=(n-t)*c)
        {
            //printf("%d",t);
            puts("YES");
            return 0;
        }
    }
    puts("NO");
}




Measured memory_bytes: 2688