akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <vector>
#include <utility>
#include <map>

/*
\cap_{u,v} \cup_{i\in (u,v) path} E_i

g(N) = |{E | {u,v\in M | \cup_{i\in (u,v) path} E_i} = N}|
G(N) = |{E | {u,v\in M | \cup_{i\in (u,v) path} E_i} \subseteq N}|
     = |{E | {u,v\in M-N | \cap_{i\in (u,v) path} !E_i}}|
*/

int n, m;
std::vector<int> E[50];
int D[50][50];

long long int M[20];
long long int A[1<<20];
std::map<std::pair<int, int>, int> edges;

long long int dfs(int u, int v, int p){
  if(u == v) return 0;
  for(int x: E[u]){
    if(x == p) continue;
    long long int b = dfs(x, v, u);
    if(b != -1) return (1LL << edges[{u, x}]) | b;
  }
  return -1;
}

int main(){
  scanf("%d", &n);
  for(int i = 0; i < n-1; i++){
    int a, b;
    scanf("%d%d", &a, &b);
    E[a-1].push_back(b-1);
    E[b-1].push_back(a-1);
    edges[{a-1,b-1}] = i;
    edges[{b-1,a-1}] = i;
  }
  scanf("%d", &m);
  for(int i = 0; i < m; i++){
    int a, b;
    scanf("%d%d", &a, &b);
    M[i] = dfs(a-1, b-1, -1);   
  }
  for(int i = 0; i < (1<<m); i++){
    A[i] = A[i&(i-1)] | M[__builtin_ctzll(i)];
  }
  long long int ans = 0;
  for(int i = 0; i < (1<<m); i++){
    A[i] = 1LL << (n-1-__builtin_popcountll(A[i]));
    if(__builtin_parity(i)) A[i] = -A[i];
    ans += A[i];
  }

  printf("%lld\n", ans);
  return 0;
}


Measured memory_bytes: 8448
// Hovalhagh
// Ya Aziz & Hakim
// AliReza Kaboli

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

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

ll LCM(ll a, ll b) {
	ll tmp = GCD(a, b);
	return a / tmp * b;
}

int main() {
	ll a, b;
	cin >> a >> b;
	cout << LCM(a, b) << '\n';
}


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

#define REP(i, x) for (int i = 0; i < (int)(x); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)

int main(int argc, char *argv[])
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int n, a, b, c;
    cin >> n;

    vector<int> l(3);
    REP(i, n)
    {
        cin >> l[0] >> l[1] >> l[2];
        sort(l.begin(), l.end());
        cout << (l[0] * l[0] + l[1] * l[1] == l[2] * l[2] ? "YES" : "NO") << endl;
    }

    return 0;
}



Measured memory_bytes: 3116
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n;
  cin>>n;
  if(n<10)
    cout<<n;
    else if(n>=10 && n<100)
      cout<<"9";
      else if(n>=100 && n<1000)
        cout<<(9+n-99);
        else if(n>=1000 && n<10000)
          cout<<"909";
          else if(n>=10000 && n<100000)
          cout<<(909+n-9999);
          else if(n>=100000 && n<1000000)
          cout<<"90909";
          else
          cout<<"90910";
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define PI acos(-1)
using namespace std;
const int N = 1e5+100;
const int MOD = 1e9+7;

int n,m,T;
string s;
int main()
{
	/*scanf("%d",&T);
	while(T--)
	{
	
	 } 
	 */
	//scanf("%d%d",&n,&m);
	getline(cin,s);
	int cnt = 0,ans = 0;
	for(int i=0;i<3;i++)
	{
		if(s[i] == 'R')	cnt++;
		ans = max(ans,cnt);
		if(s[i] == 'S')	cnt = 0;
	}
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 3560
import heapq

n = int(input())
edges = [None] * n
for _ in range(n):
    l = list(map(int, input().split()))
    edges[l[0]] = set((c, j) for j, c in (l[i:i + 2] for i in range(2, l[1] * 2 + 2, 2)))

min_costs = [0] * n
visited = [False] * n
visited[0] = True
queue = list(edges[0])
heapq.heapify(queue)

while queue:
    total_cost, vertex = heapq.heappop(queue)
    if visited[vertex]:
        continue
    visited[vertex] = True
    min_costs[vertex] = total_cost
    for cost, vertex2 in edges[vertex]:
        if not visited[vertex2]:
            heapq.heappush(queue, (total_cost + cost, vertex2))

for r in enumerate(min_costs):
    print(*r)

Measured memory_bytes: 8676
#include<iostream>
#include<string.h>
#include<string>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<math.h>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
typedef long double db;
typedef pair<int,int> pii;
const int N=100000;
const db pi=acos(-1.0);
#define lowbit(x) (x)&(-x)
#define sqr(x) (x)*(x)
#define rep(i,a,b) for (register int i=a;i<=b;i++)
#define per(i,a,b) for (register int i=a;i>=b;i--)
#define go(u,i) for (register int i=head[u];i;i=sq[i].nxt)
#define fir first
#define sec second
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define maxd 998244353
#define eps 1e-8
const int dx[]={-1,-1,-1,0,0,0,1,1,1},dy[]={-1,0,1,-1,0,1,-1,0,1};
int n,m,k;
ll ans[11];
map<pii,int> col,vis;
pii p[100100];

int read()
{
    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;
}

int calc(pii st)
{
	int cnt=0;
	rep(i,0,8)
	{
		pii now;now.fir=st.fir+dx[i];now.sec=st.sec+dy[i];
		if (col.count(now)) cnt++;
	}
	//cout << st.fir << " " << st.sec << " " << cnt << endl;
	return cnt;
}

bool ok(pii now)
{
	return ((now.fir>=2) && (now.fir<=n-1) && (now.sec>=2) && (now.sec<=m-1));
}

int main()
{
	n=read();m=read();k=read();
	rep(i,1,k)
	{
		p[i].fir=read();p[i].sec=read();
		col[p[i]]=1;
	}
	rep(i,1,k)
	{
		rep(j,0,8)
		{
			pii now;
			now.fir=p[i].fir+dx[j];now.sec=p[i].sec+dy[j];
			if ((vis[now]) || (!ok(now))) continue;
			vis[now]=1;int tmp=calc(now);ans[tmp]++;
		}
	}
	ans[0]=1ll*(n-2)*(m-2);
	rep(i,1,9) ans[0]-=ans[i];
	rep(i,0,9) printf("%lld\n",ans[i]);
	return 0;
}


Measured memory_bytes: 63488
INF = float("inf")


def bellman_ford(edges, num_v, sv):
    #グラフの初期化
    dist = [INF for i in range(num_v)]
    dist[sv]=0
    
    #辺の緩和
    for i in range(num_v):
        for edge in edges:
            s, t, d = edge[0], edge[1], edge[2]
            if dist[s] != INF and dist[t] > dist[s] + d:
                dist[t] = dist[s] + d
                if i == num_v - 1:
                    return -1       # 負の閉路が存在する
    
    return dist


def main():
    N, M, r = map(int, input().split())

    edges = []
    for _ in range(M):
        s, t, d = map(int, input().split())
        edges.append([s, t, d])
    
    dist = bellman_ford(edges, N, r)
    if dist == -1:
        print("NEGATIVE CYCLE")
    else:
        for i in range(N):
            ans = dist[i]
            if ans == INF:
                ans = "INF"
            print(ans)


if __name__ == '__main__':
    main()



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

typedef long long ll;

ll memo[1000000]={0};
const ll MOD = 1000000000+7;

ll factorial(ll n){
    if(memo[n] != 0){
        return memo[n];
    }else{
        if(n == 0){return 1;}
        else{
            memo[n] = ((n % MOD) * (factorial(n-1) % MOD)) % MOD;
            return memo[n];
        }
    }
}

ll power(ll a, ll n){
 	ll x = 1;
  	while(n > 0){
     	if (n & 1){
         	x = (a *x) % MOD; 
        }
      	a = (a * a) % MOD;
      	n >>= 1;
    }
  	return x;
}

ll comb(ll n, ll k){
 	ll a = factorial(n) % MOD;
  	ll b = factorial(n-k) % MOD;
  	ll c = factorial(k) % MOD;
  	return (((a * power(b, MOD-2)) % MOD) * power(c, MOD-2)) % MOD;
}

int main(void){

    ll X, Y;
    cin >> X >> Y;
    
    if((X+Y) % 3 != 0){
        cout << 0 << endl;
        return 0;
    }else{
        ll n = (2*Y - X) / 3;
        ll m = (2*X - Y) / 3;
        if (n < 0 || m < 0){
            cout << 0 << endl;
            return 0;
        }else{
            cout << comb(m+n, m) << endl;
        }
    }
}

Measured memory_bytes: 16768
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)n; ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cout<<*i<<" "; cout<<endl; }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
ll dp[1<<16] = {};

int main(){
  int N;
  while(cin>>N && N){
    ll ans = 0;
    memset(dp, 0, sizeof(dp));
    REP(i, N){
      int M; ll L;
      cin>>M>>L;
      int mask = 0;
      REP(t, M){
        int S, E;
        cin>>S>>E;
        S -= 6; E -= 6;
        for(int j = S; j < E; j++) mask |= (1 << j);
      }
      for(int S = 0; S < 1<<16; S++)if((mask & S) == 0){
        int next = S | mask;
        dp[next] = max(dp[next], dp[S] + L);
      }
    }
    REP(i, 1<<16)ans = max(ans, dp[i]);
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 1376
INF = float('inf')

def solve():
    N, Ma, Mb = map(int, input().split())
    l = []
    for _ in range(N):
        a, b, c = map(int, input().split())
        l.append((a, b, c))
 
    dp = [[[INF] * 401 for _ in range(401)] for _ in range(N + 1)]
    dp[0][0][0] = 0
    
    for i in range(N):
        for ca in range(401):
            for cb in range(401):
                if dp[i][ca][cb] != INF:
                    dp[i + 1][ca][cb] = min(dp[i + 1][ca][cb], dp[i][ca][cb])
                    dp[i + 1][ca + l[i][0]][cb + l[i][1]] = min(dp[i + 1][ca + l[i][0]][cb + l[i][1]], dp[i][ca][cb] + l[i][2])
 
    ans = INF
    for i in range(N+1):
        for ca in range(1, 401):
            for cb in range(1, 401):
                if dp[i][ca][cb] != INF:
                    if Ma * cb == Mb * ca:
                        ans = min(ans, dp[i][ca][cb])
 
    print(-1 if ans == INF else ans)
 
 
if __name__ == '__main__':
    solve()

Measured memory_bytes: 59504
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <utility>
#include <sys/time.h>
#include <cmath>
#include <tuple>
#include <queue>

using namespace std;

template<typename T>
class Dinic {
    struct edge {
        int to;
        T cap;
        int rev;
    };

    const T INF;
    vector< vector<edge> > graph;
    vector<T> min_cost;
    vector<int> iter;

    bool bfs(int s, int t) {
        min_cost.assign(graph.size(), -1);
        queue<int> que;
        min_cost[s] = 0;
        que.push(s);
        while (!que.empty()) {
            int q = que.front();
            que.pop();
            for (edge &e : graph[q]) {
                if (e.cap > 0 && min_cost[e.to] == -1) {
                    min_cost[e.to] = min_cost[q] + 1;
                    que.push(e.to);
                }
            }
        }
        return (min_cost[t] != -1);
    }

    T dfs(int idx, const int t, T flow) {
        if (idx == t) return flow;
        for (int &i = iter[idx]; i < graph[idx].size(); i++) {
            edge &e = graph[idx][i];
            if (e.cap > 0 && min_cost[idx] < min_cost[e.to]) {
                T d = dfs(e.to, t, min(flow, e.cap));
                if (d > 0) {
                    e.cap -= d;
                    graph[e.to][e.rev].cap += d;
                    return d;
                }
            }
        }
        return 0;
    }

    public:
        Dinic(int n) : INF(numeric_limits<T>::max()/100) {
            graph.resize(n);
        }

        void add_edge(int from, int to, T cap) {
            graph[from].push_back((edge){to, cap, static_cast<int>(graph[to].size())});
            graph[to].push_back((edge){from, 0, static_cast<int>(graph[from].size())-1}); //add reverse edge
        }

        T max_flow(int s, int t) {
            T flow = 0;
            while (bfs(s, t)) {
                iter.assign(graph.size(), 0);
                T f = 0;
                while ((f = dfs(s, t, INF)) > 0) {
                    flow += f;
                }
            }
            return flow;
        }
};


void solve(long long N, vector<long long> a){
    Dinic<long long> G(N+2);
    long long ret = 0;
    const long long INF = numeric_limits<long long>::max()/100;
    for (int i = 0; i < N; i++) {
        if (a[i] > 0) {
            ret += a[i];
            G.add_edge(0, i+1, a[i]);
            G.add_edge(i+1, N+1, 0);
        } else {
            G.add_edge(0, i+1, 0);
            G.add_edge(i+1, N+1, - a[i]);
        }
        for (int j = i+i+1; j < N; j += i+1) {
            G.add_edge(j+1, i+1, INF);
        }
    }
    ret -= G.max_flow(0, N+1);
    std::cout << ret << std::endl;
}

int main(){	
    struct timeval start,end;
    long long span;
    gettimeofday(&start,NULL);

    long long N;
    scanf("%lld",&N);
    vector<long long> a(N-1+1);
    for(int i = 0 ; i <= N-1 ; i++){
        scanf("%lld",&a[i]);
    }
    solve(N, a);

    gettimeofday(&end,NULL);
    span = (end.tv_sec -start.tv_sec)*1000000LL + (end.tv_usec - start.tv_usec);
    std::cerr << "--Total Time: " << span/1000 << "ms" << endl;
    return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
using namespace std;

const int N=2e5+5;
int n,k,a[N][7],c[32][7];
pii ST[32][N*4];

void update(int mask,int id,int l,int r,int pos,int val)
{
    if(pos>r||pos<l) return ;
    if(l==r)
    {
        ST[mask][id].fi=ST[mask][id].se=val;
        return ;
    }
    int mid=(l+r)/2;
    update(mask,id*2,l,mid,pos,val);
    update(mask,id*2+1,mid+1,r,pos,val);
    ST[mask][id].fi=max(ST[mask][id*2].fi,ST[mask][id*2+1].fi);
    ST[mask][id].se=min(ST[mask][id*2].se,ST[mask][id*2+1].se);
}

pii get(int mask,int id,int l,int r,int u,int v)
{
    if(u>r||v<l) return mp(-1e9,1e9);
    if(u<=l&&r<=v) return ST[mask][id];
    int mid=(l+r)/2;
    pii lson=get(mask,id*2,l,mid,u,v);
    pii rson=get(mask,id*2+1,mid+1,r,u,v);
    return mp(max(lson.fi,rson.fi),min(lson.se,rson.se));
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cin>>n;
    k=2;
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=k;j++) cin>>a[i][j];
    }
    for(int mask=0;mask<(1<<k);mask++)
    {
        for(int i=1;i<=k;i++)
        {
            c[mask][i]=(mask>>(i-1)&1);
            if(!c[mask][i]) c[mask][i]--;
        }
        for(int i=1;i<=n;i++)
        {
            int val=0;
            for(int j=1;j<=k;j++) val+=c[mask][j]*a[i][j];
            update(mask,1,1,n,i,val);
        }
    }
    int q;
    q=1;
    while(q--)
    {
        int type;
        type=2;
        if(type==2)
        {
            int l,r;
            l=1,r=n;
            int res=0;
            for(int mask=0;mask<(1<<k);mask++)
            {
                pii cur=get(mask,1,1,n,l,r);
                res=max(res,cur.fi-cur.se);
            }
            cout<<res<<'\n';
            continue;
        }
        int i;
        cin>>i;
        for(int j=1;j<=k;j++) cin>>a[i][j];
        for(int mask=0;mask<(1<<k);mask++)
        {
            int val=0;
            for(int j=1;j<=k;j++) val+=c[mask][j]*a[i][j];
            update(mask,1,1,n,i,val);
        }
    }
}


Measured memory_bytes: 25536
use std::cmp::*;
use std::io::*;

fn main() {
    let mut s: String = String::new();
    stdin().read_to_string(&mut s).ok();
    let mut itr = s.trim().split_whitespace();
    let h: usize = itr.next().unwrap().parse().unwrap();
    let w: usize = itr.next().unwrap().parse().unwrap();
    let d: usize = itr.next().unwrap().parse().unwrap();
    let mut a: Vec<(i64, i64)> = vec![(0i64, 0i64); h * w + d + 1];
    let mut dp: Vec<i64> = vec![0i64; h * w + d + 1];
    for i in 0..h {
        for j in 0..w {
            let b: usize = itr.next().unwrap().parse().unwrap();
            a[b] = (i as i64, j as i64);
        }
    }
    for i in 0..h * w {
        let from = a[i];
        let to = a[i + d];
        dp[i + d] = dp[i] + (from.0 - to.0).abs() + (from.1 - to.1).abs();
    }

    let q: usize = itr.next().unwrap().parse().unwrap();
    let mut out = Vec::new();
    for _ in 0..q {
        let l: usize = itr.next().unwrap().parse().unwrap();
        let r: usize = itr.next().unwrap().parse().unwrap();
        writeln!(out, "{}", dp[r] - dp[l]).ok();
    }
    stdout().write_all(&out).unwrap();
}


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

#define LL long long
#define LD long double
#define Mod 1000000007
#define L_Mod 17100000013

const double eps = 1e-9;
const int INF = 0x3f3f3f3f;
const double PI = 3.1415926535;

#define NO_TLE std::ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

#define ree(a,n) memset(a,n,si 2)

#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define red(i,l,u) for(int (i)=(int)(l);(i)>=(int)(u);--(i))


int main()
{
    LL n,m,M4=0,M2=0;
    cin>>n;
    LL  a[100002]= {0};
    for(int i=0; i<n; i++)
        cin>>a[i];
    for(int i=0; i<n; i++)
    {
        if(a[i]%4==0)
            M4++;
        else if(a[i]%2==0)
            M2++;
    }
    M2=M2/2*2;
    if(M4*2+1+M2>=n)
        cout<<"Yes";
    else
        cout<<"No";
}


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

using namespace std;

int a[5];

int main(){
    scanf("%d%d%d", &a[0], &a[1], &a[2]);
    sort(a, a + 3);
    int ans = a[2] - a[1];
    a[0] += ans;
    ans += (a[2] - a[0]) / 2 + ((a[2] - a[0]) % 2) * 2;
    printf("%d\n", ans);
}

Measured memory_bytes: 256
sd = input()
t = input()

n = len(sd)
m = len(t)
s = []

# sd を後ろから見ていき、 t の入りそうな場所を探す
for i in range(n - m, -1, -1):
    t_kamo = sd[i:i + m]
    for j in range(m + 1):
        # 1文字ずつ順に入りうるか調べ、最後まで入るなら "?" を "a" に置き換えて出力
        if j == m:
            print((sd[:i] + t + sd[i + len(t):]).replace("?", "a"))
            exit()
        if t_kamo[j] == "?":
            continue
        elif t_kamo[j] != t[j]:
            break

print("UNRESTORABLE")

Measured memory_bytes: 38428
#include <iostream>
#include <string>
#include <algorithm>
// #include <vector>
// #include <algorithm>
// #include <cmath>
// #include <math.h>
using namespace std;

int main(){
    int N;
    cin >> N;
    int AA[N];
    int Alice = 0;
    int Bob = 0;

    int a;
    for (int i=0; i<N; i++){
        cin >> a;
        AA[i] = a;
    }

    // sort(AA, AA + N);
    sort(AA, AA + N, greater<int>());

    for (int i=0; i<N; i++){
        if (i % 2 == 0){
            Alice += AA[i];
        } else {
            Bob += AA[i];
        }
    }
    cout << Alice - Bob << endl;
}

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

int main(int argc, char *argv[]) {
	int sr;
	int K, X;
	int i, j;

	sr=scanf("%d %d", &K, &X);

	for (i=X-(K-1); i<X+(K-1); i++) {
		printf("%d ",i);
	}
	printf("%d\n", X+(K-1));
	fflush(stdout);

	return 0;

}


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

int main(){
	int x, y;
	cin >> x >> y;
	int ans = 0;
	if(x==1 and y==1) ans += 400000;
	if(x==1) ans += 300000;
	if(y==1) ans += 300000;
	if(x==2) ans += 200000;
	if(y==2) ans += 200000;
	if(x==3) ans += 100000;
	if(y==3) ans += 100000;
	cout << ans << endl;
}

Measured memory_bytes: 256
n = int(input())
nums = [int(input()) for _ in range(n)]
cnt = {}
ans = 0
for x in nums:
    if x not in cnt:
        cnt[x] = 1
    else:
        cnt[x] += 1
for y in cnt.values():
    if y % 2 != 0:
        ans += 1

print(ans)

Measured memory_bytes: 16272
#!/usr/bin/env python3
import sys, math, fractions, itertools


def solve(X: int):
    print(math.ceil((math.sqrt(8*X+1)-1) / 2))
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    X = int(next(tokens))  # type: int
    solve(X)

if __name__ == '__main__':
    main()


Measured memory_bytes: 5048
#include<bits/stdc++.h>
#include <stdio.h>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define popb pop_back()
#define sz size()
using namespace std;
typedef long long ll;
///////////////////////////////////////////
int x,t;
int main(){
    cin>>x>>t;
    cout<<max(0,x-t);
}


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

using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=s;i<n;i++)
#define all(a) (a).begin(),(a).end()
int cnt;
void select_sort(int a[], int n){
    rep(i,n){
        int minj = i;
        bool change = false;
        REP(j,i,n)if(a[j] < a[minj]){
            minj = j;
            change = true;
        }
        swap(a[i], a[minj]);
        if(change)cnt++;
    }
}

int main(){
    int n;
    cin >> n;
    int r[n];
    rep(i,n)cin >> r[i];
    select_sort(r, n);
    rep(i,n){
        cout << r[i];
        if(i < n-1)printf(" ");
        else printf("\n");
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 3096
console.log((args=>{
  const S = args.trim();
  const N = S.length;
  let b = 0, f = 0;
  for ( let i = 0; i < N; i++ ) {
    if ( S[i] === 'B' ) b++;
    else f += b;
  }
  return `${f}`;
})(require('fs').readFileSync('/dev/stdin', 'utf8')));


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

bool is_month(int i)
{
  return i >= 1 && i <= 12;
}

std::string solve(const std::string& s)
{
  int first = std::stoi(s.substr(0, 2));
  int second = std::stoi(s.substr(2, 2));

  if (is_month(first)) {
    return is_month(second) ? "AMBIGUOUS" : "MMYY";
  } else {
    return is_month(second) ? "YYMM" : "NA";
  }
}

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

  std::cout << solve(s) << std::endl;
}


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

typedef vector< ll > 	vi;
typedef vector< vi > 	vvi;
typedef pair< ll,ll > 	ii;
#define pb 		push_back
#define all(c) 		(c).begin(),(c).end()
#define tr(c,i) 	for(typeof((c).begin() i = (c).begin(); i != (c).end(); i++)
#define present(c,x) 	((c).find(x) != (c).end())

#define MOD 	1000000007
#define INF 	(int)1e9
#define MEM(a, b) memset(a, (b), sizeof(a))

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

	bool flag=true;
	ll n,x,cnt=0;
	cin>>n;
	for(ll i=0; i<n; i++)
	{
		cin>>x;
		
		if(flag==true && x%2==0 && (x%3==0 || x%5==0) )
			{  flag=true; }
		else if (flag==true && x%2) {} 
			else flag=false;
	}

	//cout<<cnt;
	if(!flag)
		cout<<"DENIED";
	else cout<<"APPROVED";
	
	return 0;
}

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

int main() {
    int N, K, M=0, max, branch=0, k=1, l=1;
    cin >> N >> K;
    vector<pair<int, int>> ans;

    max = (N-1)*(N-2)/2;

    if(K>max || K<0) {
        cout << -1 << endl;
        return 0;
    }

    for(int i=2; i<N+1; i++) {
        ans.push_back(make_pair(1, i));
        M++;
    }

    for(int i=0; i<max-K; i++) {
        if(l > N-2) {
            k++;
            l=k;
        }
        ans.push_back(make_pair(ans[k-1].second,ans[l++].second));
        M++;
    }

    cout << M << endl;
    for(size_t i=0; i<ans.size(); i++) {
        cout << ans[i].first << " " << ans[i].second << endl;
    }

    return 0;

}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define GET_MACRO(_1,_2,_3,_4,_5,_6,NAME,...) NAME
#define pr(...) cerr<< GET_MACRO(__VA_ARGS__,pr6,pr5,pr4,pr3,pr2,pr1)(__VA_ARGS__) <<endl
#define pr1(a) (#a)<<"="<<(a)<<" "
#define pr2(a,b) pr1(a)<<pr1(b)
#define pr3(a,b,c) pr1(a)<<pr2(b,c)
#define pr4(a,b,c,d) pr1(a)<<pr3(b,c,d)
#define pr5(a,b,c,d,e) pr1(a)<<pr4(b,c,d,e)
#define pr6(a,b,c,d,e,f) pr1(a)<<pr5(b,c,d,e,f)
#define pr7(a,b,c,d,e,f,g) pr1(a)<<pr6(b,c,d,e,f,g)
#define pr8(a,b,c,d,e,f,g,h) pr1(a)<<pr7(b,c,d,e,f,g,h)
using namespace std;
using Int = long long;
using ll = long long;
using Double = long double;
const Int INF = (1LL<<55)+1e9; // ~ 3.6 * 1e16
const Int mod = (1e9)+7;
const Double EPS = 1e-8;
const Double PI = 6.0 * asin((Double)0.5);
using P = pair<Int,Int>;
using T = tuple<Int,Int,Int>;
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
ostream& operator<<(ostream& o,P p){return o<<"("<<p.first<<","<<p.second<<")";}
ostream& operator<<(ostream& o,T t){return o<<"("<<get<0>(t)<<","<<get<1>(t)<<","<<get<2>(t)<<")";}
istream& operator>>(istream& i,P &p){return i>>p.first>>p.second;}
ostream& operator<<(ostream& o,vector<auto> &a){Int i=0;for(auto t:a)o<<(i++?" ":"")<<t;return o;}
istream& operator>>(istream& i,vector<auto> &a){for(auto &t:a)i>>t;return i;}
void prArr(auto a,string s=" "){Int i=0;for(auto t:a)cout<<(i++?s:"")<<t;cout<<endl;}


vector<vector<Int> > G;
vector<Int> used;
Int dfs(Int pos,Int col,Int &cnt1,Int &cnt2){
  if(used[pos] != -1) return col == used[pos];
  used[pos] = col;
  col==0? cnt1++:cnt2++;
  for(Int to:G[pos]) if(dfs(to, !col,cnt1,cnt2) == 0) return 0;
  return 1;
}

vector<P> A;
const Int N = 800;
Int dfs2(Int i,Int a,Int b){
  static Int used[N][N], mem[N][N];
  if(i == (Int)A.size()) return (a*(a-1)/2) + (b*(b-1)/2);
  if(used[i][a]++) return mem[i][a];
  Int x = A[i].first;
  Int y = A[i].second;
  Int p = dfs2(i+1, a+x, b+y);
  Int q = dfs2(i+1, a+y, b+x);
  Int res = min(p,q);
  return mem[i][a] = res;
}

signed main(){
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  Int n,m;
  cin>>n>>m;
  vector<vector<Int> > g(n,vector<Int>(n));
  for(Int i=0;i<m;i++){
    Int a,b;
    cin>>a>>b; a--,b--;
    g[a][b] = g[b][a] = 1;
  }
  G.resize(n);

  for(Int i=0;i<n;i++)
    for(Int j=0;j<n;j++)
      if(i != j && g[i][j] == 0) G[i].push_back(j);

  used.resize(n,-1);
  Int valid = 1;
  for(Int i=0;i<n;i++){
    Int cnt1=0,cnt2=0;
    if(used[i] == -1) valid &= dfs(i, 0,cnt1,cnt2);
    A.push_back(P(cnt1,cnt2));
  }
  
  if(valid == 0){
    cout<<-1<<endl;
    return 0;
  }
  Int ans = dfs2(0,0,0);
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 14080
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int D = sc.nextInt();
        int X = sc.nextInt();
        int ans = X;
        for(int i=1;i<=N;i++){
            int cur =sc.nextInt();
            ans += (D-1)/cur+1;
            
        }
        

        System.out.println(ans);
    }
}

Measured memory_bytes: 21972
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define int long long
using namespace std;
typedef vector<int>   vint;
typedef pair<int,int> pint;

int c[3][3];
int a[3],b[3];

signed main()
{   
    REP(i,3) REP(j,3) cin>>c[i][j];

    a[0]=0;
    REP(i,3) b[i]=c[0][i]-a[0];
    REP(i,3) a[i]=c[i][0]-b[0];

    bool ok=true;
    REP(i,3) REP(j,3){
        if(c[i][j]!=a[i]+b[j]) ok=false;
    }
    cout<<(ok? "Yes":"No")<<endl;

}


Measured memory_bytes: 256
from copy import deepcopy
def gcd(a,b):
    while b != 0:
        a, b = b, a % b
    return(a)

def factors(n):
    Ret = []
    for i in range(2, int( n**(1/2))+1):
        if n%i == 0:
            Ret.append([])
            t = i
            while n%i == 0:
                Ret[-1].append(t)
                n //= i
                t *= i
    if n != 0:
        Ret.append([n])
    return Ret
    
N = int( input())
A = list( map( int, input().split()))
ans = A[1]
for i in range(1,N):
    ans = gcd(ans, A[i])
Fact = factors(A[0])
C = [1]
for F in Fact:
    D = deepcopy(C)
    for f in F:
        for d in D:
            C.append(d*f)
for g in C:
    check = 0
    for i in range(1,N):
        if A[i]%g != 0:
            check += 1
    if check <= 1:
        if ans < g:
            ans = g
print(ans)


Measured memory_bytes: 64476
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pli = pair<ll, int>;
using Graph = vector<vector<int>>;
const int MOD = 1e9 + 7;

int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    for (int i = 0; i < N; ++i)
        cin >> A[i];

    int exor = 0;
    ll ans = 0;
    for (int l = 0, r = 0; l < N; ++l) {
        int cnt = 0;
        while (r < N && !(exor & A[r])) {
            exor ^= A[r];
            cnt++;
            r++;
        }
        ll tmp = r - l;
        ans += tmp * (tmp + 1) / 2;
        tmp -= cnt;
        ans -= tmp * (tmp + 1) / 2;
        exor ^= A[l];
    }

    cout << ans << endl;

    return 0;
}


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


#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define MOD 1000000007
#define pii pair<int,int>
#define ll long long
#define el '\n'

using namespace std;


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

    int a,b;
    cin >> a >> b;
    cout << max(a+b,max(a-b,a*b));

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
#define bit(n) (1LL << (n))
#define len(x) ((ll)(x).size())
#define debug(var) cout << "[" << #var << "]\n" << var << "\n"
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1000000007;
const double EPS = 1e-9;

template <typename T>
ostream& operator<<(ostream& s, const vector<T>& v) {
  int len = v.size();
  for (int i = 0; i < len; ++i) {
    s << v[i];
    if (i < len - 1)
      s << ' ';
  }
  return s;
}

template <typename T>
ostream& operator<<(ostream& s, const vector<vector<T>>& vv) {
  int len = vv.size();
  for (int i = 0; i < len; ++i) {
    s << vv[i];
    if (i != len - 1)
      cout << '\n';
  }
  return s;
}

template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

__attribute__((constructor)) void initial() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}

signed main() {
  string S;
  cin >> S;
  int w;
  cin >> w;

  string ans;
  for (int i = 0; i < len(S); i += w) {
    ans.pb(S[i]);
  }
  cout << ans << "\n";
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <iomanip>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
using namespace std;

vector <string> getNum(string str) {
    vector <string> ret;
    string last;

    for (int i = 0; i < str.size(); ++i) {
        if (str[i] == '.') {
            if (last.size()) {
                ret.push_back(last);
            }
            last = "";
        } else {
            last += str[i];
        }
    }

    if (last.size()) {
        ret.push_back(last);
    }

    return ret;
}

int main() {
    long long A;
    string B;

    cin >> A >> B;
    vector <string> nums = getNum(B);

    long long res = 0;
    res += A * atoll(nums[0].c_str());
    res += A * atoll(nums[1].c_str()) / 100;

    cout << res << endl;



    return 0;
}

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

#define ll long long
#define N 310
const ll p = 998244353; 
int n, a[N];
ll f[N * N], g[N * N], all;

int main() {
	while (scanf("%d", &n) != EOF) {
		ll sum = 0, mid;
		all = 1;
		for (int i = 1; i <= n; ++i) {
			scanf("%d", a + i);
			sum += a[i];	
			all = (all * 3) % p; 
		}
		mid = sum / 2;  
		memset(f, 0, sizeof f);  
		f[0] = 1;   
		for (int i = 1; i <= n; ++i) {
			for (int j = sum - a[i]; j >= 0; --j) {
				f[j + a[i]] = (f[j + a[i]] + f[j] * 2 % p) % p;  
			}		 
		}
		
		ll res = 0; 
		for (int i = 0; i <= mid; ++i) {      
			res = (res + f[i]) % p;
		}
		if (sum % 2 == 0) {
			memset(g, 0, sizeof g);
			g[0] = 1;
			for (int i = 1; i <= n; ++i) {
				for (int j = sum - a[i]; j >= 0; --j) {
					g[j + a[i]] = (g[j + a[i]] + g[j]) % p;
				}
			}
			res = (res - g[mid] + p) % p;    
		}
		printf("%lld\n", (all - (res * 3) % p + p) % p); 
	}
	return 0;
}


Measured memory_bytes: 1792
#include<stdio.h>
int main() {
    long long c[33], ans = 1,n,i;
    char s[111111];
    scanf("%lld%*c%s",&n, s);
    for (i = 0; i < 26; i++)
        c[i] = 0;
    for (i = 0; i < n; i++) 
        c[s[i]-'a']++;
    for (i = 0; i < 26; i++){
        ans = ans * (c[i] + 1);
        if (ans > 1000000007)
            ans =ans% 1000000007;
    }
    ans--;
    if (ans == -1)
        ans += 1000000007;
    printf("%lld\n", ans);
    return 0;
}


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

# define ll long long int 

const int md = 1e9+7;
ll Parent[200005];
ll sze[200005];

void Build(int n)
{ for(ll i=1;i<=n;i++)
   { Parent[i]=i;
     sze[i]=1;
   }
}


ll find(ll u)
{
    if(Parent[u]==u) return u;
    else
    {
        return Parent[u]=find(Parent[u]);
    }
}



void Union(ll a, ll b)
{
  ll P_a=  find(a);
  ll P_b=  find(b);
  
  if(P_a!=P_b)
  {
  	sze[P_b]+=sze[P_a];
  	Parent[P_a]=Parent[P_b];
  }

}

int main()
{
    ll n,m;
    cin>>n>>m;
    
     //std::vector<Edge> E(m) ;
     Build(n);
     
     // for(ll i=0;i<m;i++)
     // {
     //     cin>>E[i].src;
     //     E[i].src--;
     //     cin>>E[i].dest;
     //     E[i].dest--;
     //     cin>>E[i].wt;
     // }

     for(int i=0;i<m;i++)
     {
     	ll x,y;
     	cin>>x>>y;
     	Union(x,y);
     }
      
      unordered_map<int,int> mp;
      ll mx=0;

     for(int i=1;i<=n;i++)
     {
     	int p=find(i);
     	//cout<<p<<endl;
     	if(mp.find(p)==mp.end())
     	{
     		mp[p]=1;
     		mx= max(mx,sze[p]);

     	}
     }


     
     
 
     
     cout<<mx<<endl;
    
    
}





Measured memory_bytes: 14492
import java.util.Scanner;
 
public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();
		
		int times = B / A;
		int r = times < C ? times : C;
		System.out.println(r);
	}
 
}

Measured memory_bytes: 22612
#include<iostream>
#include<bits/stdc++.h>
#include<string>
using namespace std;
int main()
{
  string s ;
  cin >> s ;
  
  int cnt = 0 ; 
  int prev = 0 ;
  for(int i=0;i<s.length();i++){
    if(s[i] == 'A' || 
       s[i] == 'T' || 
       s[i] == 'G' || 
       s[i] == 'C'){
      cnt++ ;
    }else{
      if(prev<cnt){
        prev = cnt ;
      }
      cnt = 0 ; 
    }
  }
  
  cout << max(cnt,prev) << endl ;
  return 0 ;
}

Measured memory_bytes: 256
# coding: utf-8
S = input()
L = []
r, l = 0, 0
cnt = 0
tl = 0
ans = [1 for _ in range(len(S))]
for i in range(len(S)-1):
    if S[i] == "R" and S[i+1] == "L":
        r, l = i, i+1
    if S[i] == "L" and S[i+1] == "R":
        if cnt != 0:
            tl += 1
        for j in range(tl, i+1):
            if j == r or j == l:
                continue
            if (j - r) % 2 == 0:
                ans[r] += 1
            else:
                ans[l] += 1
            ans[j] -= 1
        cnt += 1
        tl = i
    if i == len(S) - 2:
        if cnt != 0:
            tl += 1
        for j in range(tl, i+2):
            if j == r or j == l:
                continue
            if (j-r-1) % 2 == 0:
                ans[l] += 1
            else:
                ans[r] += 1
            ans[j] -= 1
print(*ans)

Measured memory_bytes: 6520
/* package whatever; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
public class Main
{
	public static void main (String[] args) throws java.lang.Exception
	{
		Scanner scan = new Scanner(System.in);
		String a = scan.next();
		int n = a.length();
		String ans = "";
		for(int i=0;i<n;i++){
			ans += "x";
		}
		System.out.println(ans);
		// your code goes here
	}
}

Measured memory_bytes: 23764
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <inttypes.h>
#include <string.h>
#include <math.h>

int main (void)
{
    intmax_t N;
    double ans;

    scanf("%jd", &N);

    ans = (N / 2 + (N % 2)) / (double)N;

    printf("%f\n", ans);

    return 0;
}


Measured memory_bytes: 128
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
int main(){
    int n,dp[200001],h[200000];
    scanf("%d",&n);
    for(int i=0;i<=n;i++){
        dp[i]=1000000001;
    }
    for(int i=0;i<n;i++){
        scanf("%d",&h[i]);
    }
    dp[1]=0;
    for(int i=1;i<=n-2;i++){
        dp[i+1]=min(dp[i+1],dp[i]+abs(h[i]-h[i-1]));
        dp[i+2]=min(dp[i+2],dp[i]+abs(h[i+1]-h[i-1]));
    }
    dp[n]=min(dp[n],dp[n-1]+abs(h[n-2]-h[n-1]));
    printf("%d\n",dp[n]);
}

Measured memory_bytes: 896
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N,K;
  cin >> N >> K;
  vector<int> l(N);
  for(int i=0;i<N;i++){
    cin >> l[i];
  }
  sort(l.begin(),l.end());
  int a=0;
  for(int i=0;i<K;i++){
    a+=l[N-1-i];
  }
  cout << a << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main(){
  string s;
  cin>>s;
  transform(s.begin(),s.end(),s.begin(),::tolower);
  if(s.length()>=3 && s.length()<=20)
  {
  string sub=s.substr(0,3);
  cout<<sub;
  }
}


Measured memory_bytes: 3132
#include<stdio.h>

int main(){
  int i,j,N,v;
  int A[1000];

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

  for(j=0;j<N;j++){
      printf("%d",A[j]);
      if(j+1==N)break;
      printf(" ");
    }
  printf("\n");

  for(i=1;i<N;i++){
    v=A[i];
    j=i-1;
    while(j>=0 && A[j]>v){
      A[j+1]=A[j];
      j--;
    }
    A[j+1]=v;
  
    for(j=0;j<N;j++){
      printf("%d",A[j]);
      if(j+1==N)break;
      printf(" ");
    }
    printf("\n");
  }
  
  return 0;
}



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

using namespace std;
using ll = long long;
using ld = long double;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define reps(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
const ll mod = ll(1e9) + 7;
const int INF = int(1e9);

int w, h;
int ww[31][31], wh[31][31];
bool m[31][31];
int solve() {
	queue <pair<pair<int, int>, int>>que;
	que.push({ {0,0},1 });
	while (que.size()) {
		int x = que.front().first.first;
		int y = que.front().first.second;
		int cnt = que.front().second;
		//cout << x << " " << y << endl;
		que.pop();
		if (x == w - 1 && y == h - 1)return cnt;
		if (x != 0) {
			if (wh[x - 1][y] != 1&&m[x-1][y]!=1) {
				que.push({ {x - 1,y},cnt + 1 });
				m[x - 1][y] = 1;
			}
		}
		if (x != w - 1) {
			if (wh[x][y] != 1 && m[x+1][y] != 1) {
				que.push({ {x + 1,y},cnt + 1 });
				m[x + 1][y] = 1;
			}
		}
		if (y != 0) {
			if (ww[x][y - 1] != 1 && m[x][y - 1] != 1) {
				que.push({ {x,y - 1},cnt + 1 });
				m[x][y - 1] = 1;
			}
		}
		if (y != h - 1) {
			if (ww[x][y] != 1 && m[x][y + 1] != 1) {
				que.push({ {x,y + 1},cnt + 1 });
				m[x][y + 1] = 1;
			}
		}
	}
	return 0;
}

int main() {
	cin.sync_with_stdio(false);
	while (1) {
		cin >> w >> h;
		if (w == 0)return 0;
		rep(i, 31) {
			rep(j, 31) {
				ww[i][j] = 0;
				wh[i][j] = 0;
				m[i][j] = 0;
			}
		}
		int cnth = 0;
		while (cnth < h) {
			rep(i, w-1) cin >> wh[i][cnth];
			if (cnth + 1 < h) {
				rep(i, w)cin >> ww[i][cnth];
			}
			cnth++;
		}
		cout << solve() << endl;

	}

	return 0;
}


Measured memory_bytes: 3068
n = int(input())
x = 1
while x <= n:
    a = [int(x % 10), int((x/10) % 10), int((x/100) % 10), int((x/1000) % 10)]
    if x % 3 == 0 or ("3" in (" ".join(map(str, a)))):
        print (f" {x}", end = "")
    x += 1
print ()


Measured memory_bytes: 5892
#include <bits/stdc++.h>
using namespace std;
#define rep(i,l,r) for(int i = l; i < (r); i++)
#define pb push_back
#define ALL(a) a.begin(), a.end()
#define fastio ios::sync_with_stdio(0);cin.tie(0)
using ll = long long;
using ull = unsigned long long;

int main() {
  fastio;
  int R; cin >> R;
  cout << 2*atan(1)*4*R << endl;
}


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

using namespace std;

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

using _loop_int = int;
#define REP(i,n) for(_loop_int i=0; i<(_loop_int)(n); i++)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a); i<(_loop_int)(b); i++)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1; i>=(_loop_int)(a); i--)

#define CHMIN(a,b) (a)=min((a),(b))
#define CHMAX(a,b) (a)=max((a),(b))
#define ALL(v) (v).begin(),(v).end()

#define DEBUG(x) cerr<<#x<<": "<<(x)<<endl
#define DEBUG_VEC(v) cerr<<#v<<": ";REP(__i,(v).size())cerr<<((v)[__i])<<", ";cerr<<endl

const ll MOD = 1000000007ll;

int main(){
    string s;
    cin>>s;
    sort(ALL(s));
    if(s[0]==s[1] && s[1]!=s[2] && s[3]==s[2]){
        puts("Yes");
    }else{
        puts("No");
    }
    return 0;
}


Measured memory_bytes: 256
L=input()
#L 最大100000桁
N=len(L)
p=10**9+7
#iけた目が１
#1~N-1まで
ans1=0
for i in range(1,N):
    now=(2*pow(3, (i-1), p))%p
    ans1+=now
    ans1%=p

#Nけた目が１
dp=[0]*N
equals=[0]*N
dp[0]=0
equals[0]=2
for i in range(1,N):
    if L[i]=="0":
        equals[i]=equals[i-1]
        dp[i]=(dp[i-1]*3)%p
    else:
        equals[i]=(equals[i-1]*2)%p
        dp[i]=((dp[i-1]*3)+equals[i-1])%p

print((1+ans1+dp[-1]+equals[-1])%p)
#print(dp, equals)

Measured memory_bytes: 42224
#!/usr/bin/env python3

import sys
# import math
# from string import ascii_lowercase, ascii_upper_case, ascii_letters, digits, hexdigits
# import re                                    # re.compile(pattern) => ptn obj; p.search(s), p.match(s), p.finditer(s) => match obj; p.sub(after, s)
# from operator import itemgetter              # itemgetter(1), itemgetter('key')
# from collections import deque                # deque class. deque(L): dq.append(x), dq.appendleft(x), dq.pop(), dq.popleft(), dq.rotate()
# from collections import defaultdict          # subclass of dict. defaultdict(facroty)
# from collections import Counter              # subclass of dict. Counter(iter): c.elements(), c.most_common(n), c.subtract(iter)
# from heapq import heapify, heappush, heappop # built-in list. heapify(L) changes list in-place to min-heap in O(n), heappush(heapL, x) and heappop(heapL) in O(lgn).
# from heapq import nlargest, nsmallest        # nlargest(n, iter[, key]) returns k-largest-list in O(n+klgn).
# from itertools import count, cycle, repeat   # count(start[,step]), cycle(iter), repeat(elm[,n])
# from itertools import groupby                # [(k, list(g)) for k, g in groupby('000112')] returns [('0',['0','0','0']), ('1',['1','1']), ('2',['2'])]
# from itertools import starmap                # starmap(pow, [[2,5], [3,2]]) returns [32, 9]
# from itertools import product, permutations  # product(iter, repeat=n), permutations(iter[,r])
# from itertools import accumulate             # accumulate(iter[, f])
# from functools import reduce                 # reduce(f, iter[, init])
# from functools import lru_cache              # @lrucache ...arguments of functions should be able to be keys of dict (e.g. list is not allowed)
# from bisect import bisect_left, bisect_right # bisect_left(a, x, lo=0, hi=len(a)) returns i such that all(val<x for val in a[lo:i]) and all(val>-=x for val in a[i:hi]).
# from copy import deepcopy                    # to copy multi-dimentional matrix without reference
# from fractions import gcd                    # for Python 3.4 (previous contest @AtCoder)


def main():
    mod = 1000000007                # 10^9+7
    inf = float('inf')              # sys.float_info.max = 1.79...e+308
    inf = 2 ** 64 - 1               # (for fast JIT compile in PyPy) 1.84...e+19
    sys.setrecursionlimit(10**6)    # 1000 -> 1000000
    def input(): return sys.stdin.readline().rstrip()
    def ii():    return int(input())
    def mi():    return map(int, input().split())
    def mi_0():  return map(lambda x: int(x)-1, input().split())
    def lmi():   return list(map(int, input().split()))
    def lmi_0(): return list(map(lambda x: int(x)-1, input().split()))
    def li():    return list(input())
    
    
    x = ii()
    year = 0
    money = 100
    while money < x:
        money = (money * 1.01) // 1
        year += 1
    print(year)


if __name__ == "__main__":
    main()


Measured memory_bytes: 9284
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
using namespace std;
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;}
typedef long long ll;

const ll INF = 1LL<<60;
const int NMAX = 100000;
int N,K;
int h[NMAX];
ll dp[NMAX];

int main() {
    int N,K;
    cin >> N >> K;
    rep(i,N) cin >> h[i];
    rep(i,NMAX) dp[i]=INF;
    dp[0] = 0;
    rep(i,N) {
        int k_max = max(K,i);
        for(int j=max(i-K,0); j<i; j++) {
            chmin(dp[i], dp[j] + abs(h[i] - h[j]));
        }
    }
    cout << dp[N-1] << '\n';
    return 0;
}

Measured memory_bytes: 1408
#include<bits/stdc++.h>
const long long mod = 1000000007;

int main()
{
    int n,m;
    std::cin>>n>>m;
    bool res = true;
    if(std::abs(n-m)>=2)res = false;
    long long nk = 1,mk = 1;
    int ans;
    for(long long i=n;i!=1;i--){nk*=i;nk%=mod;}
    for(long long i=m;i!=1;i--){mk*=i;mk%=mod;}
    ans = (mk*nk)%mod;
    if((n+m)%2==0){ans*=2;ans%=mod;}
    std::cout<<(res?ans:0)<<std::endl;
}

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

#ifdef LOCAL
#define debug(var) cerr << (#var) << " = " << (var) << endl;
#else
#define debug(var)
#endif

void init() {
  ios_base::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
}

const int N = 10;

int p[N], l[N];

void solve() {
  int n, a, b, c; scanf("%d%d%d%d", &n, &a, &b, &c);
  for (int i = 0; i < n; ++i) scanf("%d", l+i);
  int ans = 1e9;
  for (int i = 0, lmt = 1 << (n*2); i < lmt; ++i) {
    int h[4] = {0};
    int z[4] = {0};
    int cur = 0;
    for (int x = i, j = 0; j < n; ++j) {
      p[j] = x%4;
      x /= 4;
      ++h[p[j]];
      if (p[j] == 3) continue;
      cur += 10;
      z[p[j]] += l[j];
    }
    if (!h[0] || !h[1] || !h[2]) continue;
    cur -= 30;
    sort(z, z+3);
    do {
      ans = min(ans, cur+abs(a-z[0])+abs(b-z[1])+abs(c-z[2]));
    } while (next_permutation(z, z+3));
  }
  printf("%d", ans);
}

int main() {
  init();
  int t = 1; //scanf("%d", &t);
  while (t--) {
    solve();
  }
  return 0;
}


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

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

    int ans = 0;

    for (auto a = 0; a < 10; a++)
    {
        for (auto b = 0; b < 10; b++)
        {
            bool is_a = false;
            bool is_b = false;
            vector<bool> c(10, false);

            for (auto i = 0; i < s.size(); i++)
            {
                if (!is_a)
                {
                    if ((s[i] - 48) == a)
                    {
                        is_a = true;
                    }
                    continue;
                }

                if (!is_b)
                {
                    if ((s[i] - 48) == b)
                    {
                        is_b = true;
                    }
                    continue;
                }

                if (!c[s[i] - 48])
                {
                    c[s[i] - 48] = true;
                    ans += 1;
                }
            }
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <iostream>
using namespace std;
int main() {
	string m,n;
	cin>>m>>n;
    int dp[m.size()+1][n.size()+1];
	//memset(dp,0,sizeof(dp));
	for(int i=0;i<=m.size();i++){
		for(int j=0;j<=n.size();j++){
			if(i==0||j==0)dp[i][j]=0;
			else if(m[i-1]==n[j-1])dp[i][j]=1+dp[i-1][j-1];
			else dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
		}
	}
	//cout<<dp[m.size()][n.size()]<<endl;
	int i=m.size();
	int j=n.size();
	string a;
	a.clear();
	while(i!=0&&j!=0){
		if(m[i-1]==n[j-1]){
			a.push_back(m[i-1]);
			i--;
			j--;
		}
		else{
			if(dp[i-1][j]>dp[i][j-1])i--;
			else j--;
		}
	}
    reverse(a.begin(),a.end());
    cout<<a;
	return 0;
}

Measured memory_bytes: 35456