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

const int MOD = 1e9 + 7;
template<typename T>
vector<vector<T>> get_partition(int n, int m){
 
    vector<vector<T>> dp(n + 1, vector<T>(m + 1));
 
    dp[0][0] = 1;
    for(int i = 0; i <= n; ++i){
      for(int j = 1; j <= m; ++j){

        if(i-j >= 0) dp[i][j] = (dp[i][j-1] + dp[i-j][j])%MOD;
        else         dp[i][j] = dp[i][j-1];

      }
    }
    return dp;
}
 
int main() {
  int n, m;
  cin >> n >> m;
  cout << get_partition< int >(n, m)[n][m] << endl;
}


Measured memory_bytes: 6760
import java.util.Scanner

object Main extends App{
  val sc = new Scanner(System.in)
  
  val a = sc.nextInt
  val b = sc.nextInt
  
  val target = Math.min(a,b)
  val times = Math.max(a,b)
  
  val res = Seq.fill(times)(target).mkString("")
  
  println(res)
  
}

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

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> ii;
typedef tuple<ll, ll, ll> iii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
#define REP(i,n) for (ll i = 0; i < n; ++i)
#define REPR(i,n) for (ll i = n-1; i >= 0; --i)
#define FOR(i,m,n) for (int i = m; i < n; ++i)
#define FORR(i,m,n) for (ll i = n-1; i >= m; --i)
#define FORE(x,xs) for (const auto& x : xs)
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define ALL(v) v.begin(), v.end()
#define rALL(v) v.rbegin(), v.rend()

const int MAX = 1e5+10;
const ll INF = 1e9+10;

ll N;
vi A;

ll solve() {
    multiset<int> m;
    m.insert(-1);
    FORE (a, A) {
        auto it = m.lower_bound(a);
        it--;
        if (*it != -1) m.erase(it);
        m.insert(a);
    }
    return m.size() - 1;
}

int main() {
    cin >> N;
    A = vi(N);
    REP (i, N) cin >> A[i];
    cout << solve() << endl;
}

Measured memory_bytes: 5760
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int s=0;
	char a;
	for(int i=0;i<4;i++)
	{
		cin>>a;
		if(a=='+')
		{
			s+=1;
		}
		else
		{
			s-=1;
		}
	}
	cout<<s;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <math.h>
#include <queue>
#include <deque>
typedef long long ll;
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; }
using namespace std;

int main(){
	int r, g, b, n, ans = 0;
	cin >> r >> g >> b >> n;
	for (int i = 0; i < 3010; i++) {
		for (int j = 0; j < 3010; j++) {
			int num = n - (i * r + j * g);
			if(num >= 0 && num%b==0) ans++;
		}
	}
	cout << ans << endl;
	return 0;
}


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

using namespace std;

int main()
{
	int A, B, C, X;
  	cin >> A >> B >> C >> X;
	
	int res = 0;

	for(int i = 0; i <= A; i++){
		for(int j = 0; j <= B; j++){
			for(int k = 0; k <= C; k++){
				if(X == 500*i+100*j+50*k){
					res++;
				}
			}
		}
	}
	cout << res << endl;

	return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
    int n,a,i,st;
    cin>>n;
    st=1;
    for(i=0; i<n; i++)
    {
        cin>>a;
        if((a%2==0)&&(a%3!=0)&&(a%5!=0))
            {
                st=0;
            }
    }
    if(st==1)
        cout<<"APPROVED";
    else
        cout<<"DENIED";
    return 0;
}


Measured memory_bytes: 256
import java.util.*;
//import java.util.stream.Collectors;

public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		int n = Integer.parseInt(sc.next());
		int[] a = new int[n];
		int temp = 0;
		for(int x=1; x<100; x++){
			for(int y=1; y<100; y++){
				for(int z=1; z<100; z++){
					temp = x*x + y*y + z*z + x*y + y*z + z*x;
					if(temp <= n){
						a[temp - 1]++;
					}
				}
			}
		}
		Arrays.stream(a).forEach(System.out::println);
	}
}


Measured memory_bytes: 38928
# 二部グラフ判定
def bipartite_graph_check(n,edge):
  color = [-1] * n
  for i in range(n):
    if color[i] != -1:
      continue
    stack = [i]
    color[i] = 0
    for node in stack:
      for mode in edge[node]:
        if color[mode] == -1:
          stack.append(mode)
          color[mode] = color[node] ^ 1
        elif color[mode] == color[node]:
          return False
  #return True
  return color
n,m=map(int,input().split())
edge=[[]for _ in range(n)]
for _ in range(m):
  a,b=map(int,input().split())
  a-=1
  b-=1
  edge[a].append(b)
  edge[b].append(a)
if bipartite_graph_check(n,edge):
  color=bipartite_graph_check(n,edge)
  print(color.count(0)*color.count(1)-m)
else:
  print(n*(n-1)//2-m)

Measured memory_bytes: 27012
#!/usr/bin/env python3
#ABC65 C

import math
import sys
sys.setrecursionlimit(100000000)
n,m = map(int,input().split())
mod = 10**9+7

x = max(n,m)
y = min(n,m)
if n-1 > m or m-1 > n:
    print(0)
    quit()

def P(n,r):
    return math.factorial(n)//math.factorial(n-r)
def C(n,r):
    return P(n,r)//math.factorial(r)

a = math.factorial(x)
b = P(y,x-1)
if y-(x-1) == 0:
    c = 1
else:
    c = 2*math.factorial(y-(x-1))
print(a*b*c % mod)


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

typedef long long ll;
const ll MOD = 1e9 + 7;
const ll inf = 1LL<<60;
const double eps = 1e-9;

typedef pair<ll, ll> P;

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; }

int main()
{
	ll N, K;
	cin >> N >> K;
	ll res = 0;
	for (ll i = 1; i <= N; i++) {
		ll p = N / i;
		ll r = N % i;
		ll temp = max(0LL, i - K);
		res += p * temp;
		res += max(0LL, r - K + 1);
	}
    
	if (K == 0) {
		res -= N;
	}

	cout << res << endl;
	return 0;
}


Measured memory_bytes: 256
x, n = map(int, input().split())
listP = list(map(int, input().split()))

listP.sort()

minD = 200
val = 0
bef = None
for p in listP:
    if bef == None:
        bef = p
        minD = abs(p-1-x)
        val = p-1
    else:
        if p-1 == bef:
            pass
        else:
            if bef < x < p:
                minD = 0
                val = x
            elif x <= bef:
                if abs(bef+1-x) < minD:
                    minD = abs(bef+1-x)
                    val = bef+1
            else:
                if abs(p-1-x) < minD:
                    minD = abs(p-1-x)
                    val = p-1
        bef = p
if not x in listP:
    val = x
    minD = 0
elif val == 0:
    if abs(0-x) > abs(101-x):
        val = 101
        minD = abs(101-x)
    else:
        val = 0
        minD = abs(0-x)
elif bef!=None and abs(bef+1-x) < minD:
    val = bef+1

print(val)

Measured memory_bytes: 9260
import numpy as np
N,M =list(map(int, input().split()))
shops = []
for i in range(N):
    a,b = list(map(int, input().split()))
    shops.append((a,b))
    
cnt = 0
minp = 0
for shop in sorted(shops):
    if cnt + shop[1] >= M:
        minp += shop[0] * (M-cnt)
        break
    else:
        minp += shop[0] * shop[1]
        cnt += shop[1]
        
print(minp)

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

int main(void){
    int a = 0, b = 0, c = 0;
    int ans = 0;

    scanf("%d%d%d", &a, &b, &c);

    if(a == b && b != c){
        ans = 1;
    }else if(b == c && c != a){
        ans = 1;
    }else if(c == a && a != b){
        ans = 1;
    }else{
        ans = 0;
    }

    if(ans == 1){
        printf("Yes\n");
    }else{
        printf("No\n");
    }
 
    return 0;

} 


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long 
//動画解答例写し 
int main() {
  int k; cin >>k;
  vector<ll>a;
  for(int i=1;i<=9;i++)a.push_back(i);
  while(1){
    if(k<=a.size()){
      cout<<a[k-1]<<endl;
      return 0;
    }
    k -=a.size();
    vector<ll>old;
    swap(old,a);
    for(ll x:old){
      for(int i=-1;i<=1;++i){
        int d=x%10+i;
        if(d<0||d>9)continue;
        ll nx=x*10+d;
        a.push_back(nx);
      }
    }
  }
  return 0;
}

Measured memory_bytes: 1712
#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>

using namespace std;

int main(void){
	int n;
	while(cin >> n && n){
		vector<int> cand;
		double mindiff = 1e+10;
		double bmi;
		int i,h,w;
		for(int j=0;j<n;j++){
			cin >> i >> h >> w;
			bmi = (double)w / (((double)h/100)*((double)h/100));
			//cout << i << " " << h  << " " << w << endl;
			//cout << bmi << endl;
			if(fabs(22-bmi) < mindiff){
				cand.clear();
				mindiff = fabs(22-bmi);
				cand.push_back(i);
			}else if(fabs(mindiff - fabs(22-bmi)) < 1e-4 ){
				cand.push_back(i);
			}
		}
		sort(cand.begin(),cand.end());
		cout << cand[0] << endl;
	}
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define shosu(n) setprecision(n)
using namespace std;
int main() {
  long long N, A, B;
  cin >> N >> A >> B;
  if (A == B || N == 2)
    cout << 1 << endl;
  else if (N == 1 || A > B)
    cout << 0 << endl;
  else
    cout << ((B - A) * (N - 2 )+1) << endl;
  return 0;
}

Measured memory_bytes: 256
A, B, C = map(int, input().split())
count = 0
while True:
    if (A == B == C) and (A%2 == 0):
        print("-1")
        exit()
    if A%2 == 1 or B%2 == 1 or C%2 == 1:
        break
    else:
        A, B, C = B/2+C/2, A/2+C/2, A/2+B/2
        count += 1
print(count)


Measured memory_bytes: 3060
import java.util.List;
import java.util.Scanner;



public class Main {


	static List<Integer> ansset;

    public static void main(String[] args) {

    	Main main=new Main();

    	main.run();

    }

    void run() {
    	Scanner sc=new Scanner(System.in);

    	String S=sc.next();

    	String[] input=S.split("");

    	String result="";

    	for(int i=0;i<input.length;i++) {

    		if(input[i].equals("B")) {

    			if(result.length()>0) {
    				result=result.substring(0, result.length()-1);
    			}

    		}else {

    			result+=input[i];
    		}

    	}

    	System.out.println(result);

    }
}



Measured memory_bytes: 22996
<?php
$N = intval(trim(fgets(STDIN)));
$A = array_map("intval", explode(" ", trim(fgets(STDIN))));
$B = array_map("intval", explode(" ", trim(fgets(STDIN))));
$dp = array_fill(0, 1<<$N, array_fill(0,51,PHP_INT_MAX));
$dp[0][0] = 0;
for($bit = 0, $NN = 1<<$N; $bit < $NN; ++$bit){
    $con = 0;
    for ($i = $N - 1; $i >= 0; --$i) if ($bit & (1<<$i)) ++$con;
    $ords = [];
    $iter = $con - 1;
    for($i = 0; $i < $N; ++$i)
        if(!($bit & (1<<$i)))
            $ords[$i] = ++$iter;
    for($s = 0; $s <= 50; ++$s){
        if($dp[$bit][$s] == PHP_INT_MAX)continue;
        foreach($ords as $p0 => $p1){
            $ns = ($p0-$con) & 1 ? $B[$p0] : $A[$p0];
            if($ns >= $s){
                $dp[$bit | (1<<$p0)][$ns] = min($dp[$bit|(1<<$p0)][$ns], $dp[$bit][$s] + abs($p1 - $con));
            }
        }
    }
}
$min = min($dp[(1<<$N)-1]);
if($min == PHP_INT_MAX){
    echo -1;
}else{
    echo $min;
}


Measured memory_bytes: 682488
#include <bits/stdc++.h>
using namespace std;
int main(){
    string s,t;
    
    cin >> s >> t;
    int slen = (int)(s.length());
    int tlen = (int)(t.length());
    int count;
    int answer=tlen;
    for(int i=0; i<slen-tlen+1; i++){
        count = 0;
        for(int j=0; j<tlen; j++){
            if(s[i+j]!=t[j]){
                count++;
            }
        }
        answer = min(answer,count);
    }

    cout << answer;
}

Measured memory_bytes: 3604
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <functional>

using namespace std;

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int,int> PII;
typedef long long ll;
typedef unsigned long long ull;

#define REP( i, m, n ) for ( int i = (int)( m ); i < (int)( n ); i++ )
#define UREP( i, m, n ) for ( unsigned int i = (unsigned int)( m ); i < (unsigned int)( n ); i++ )

#define ITER( c ) __typeof( (c).begin() )
#define IREP( c, it ) for ( ITER(c) it = c.begin(); it != c.end(); ++it )
#define ALL( c ) (c).begin(), (c).end()
#define RALL( c ) (c).rbegin(), (c).rend()

#define PB( n ) push_back( n )
#define MP( a, b ) make_pair( ( a ), ( b ) )
#define EXIST( c, e ) ( (c).find( e ) != (c).end() )

#define fst first
#define snd second

#define DUMP( x ) cerr << #x << " = " << ( x ) << endl
#define DEBUG( x ) cerr << __FILE__ << ":" << __LINE__ << ": " << #x << " = " << ( x ) << endl

int main()
{
	vector< vector< pair<double,int> > > runners( 3 );

	REP( i, 0, 3 )
	{
		runners[i].resize( 8 );

		REP( j, 0, 8 )
		{
			cin >> runners[i][j].snd >> runners[i][j].fst;
		}
	}

	vector< pair<double,int> > passed;
	vector< pair<double,int> > nokori;

	REP( i, 0, 3 )
	{
		sort( ALL( runners[i] ) );

		REP( j, 0, 8 )
		{
			if ( j < 2 )
			{
				passed.PB( runners[i][j] );
			}
			else
			{
				nokori.PB( runners[i][j] );
			}
		}
	}

	sort( ALL( nokori ) );
	passed.PB( nokori[0] );
	passed.PB( nokori[1] );

	cout.precision( 2 );

	REP( i, 0, 8 )
	{
		cout << passed[i].snd << ' ' << setiosflags( ios::fixed ) << passed[i].fst << endl;
	}

	return 0;
}

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

int main() {
  string s;
  cin >> s;
  int count = 0;
  rep(i, 3) {
    if(s.at(i) == '1') count++;
  }
  cout << count << endl;
}

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

ll gcd(ll a, ll b){
  return (b != 0) ? gcd(b, a%b) : a;
}

int main(){
  int n;
  cin >> n;
  ll x[n];
  ll c[n];
  rep(i, n){
    cin >> x[i];
    c[i] = x[i];
  } 
  sort(x, x+n);
  rep(i, n){
    if(c[i] <= x[n/2-1]) cout << x[n/2] << endl;
    else  cout << x[n/2-1] << endl;
  }
}

Measured memory_bytes: 5248
// 6/14 リアルタイム参加
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using Graph = vector<vector<int>>;
using ll = long long;

struct Edge {
    int to, id;
    Edge(int to, int id): to(to), id(id) {}
};

vector<Edge> g[55];

// パス上の辺を記録したい。
vector<int> es;

// aからbまでのパスを求めるdfs。pはparent。同じ頂点を２回たどらないように。
// 上記のesを埋める。
bool dfs(int v, int tv, int p=-1) {
    // 終点の条件
    if (v == tv) {
        es = vector<int>();
        return true;
    }

    // vに繋がる辺をなめる
    for (Edge e : g[v]) {
        if (e.to == p) continue;
        if (dfs(e.to, tv, v)){
            es.push_back(e.id);  // これで途中のパスが全て取れる。
            return true;
        }
    }

    // 上の探索の中でtrueがなければfalseを返す。
    return false;
}

int main() {
    int N, M;
    cin >> N;
    rep(i, N-1) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        g[a].emplace_back(b, i);
        g[b].emplace_back(a, i);
    }

    cin >> M;
    vector<ll> eset(M);  // 辺の集合をllで管理する。もしi個目の辺を使うときは、そのビットを1にする。

    rep(i, M) {
        int a, b;
        cin >> a >> b;
        --a; --b;
        // aからbのパス上にある辺のIDを列挙したい
        dfs(a, b);
        // esetに格納する。
        for (int e : es) {
            // eビット目を1にする。
            eset[i] |= 1ll<<e;
        }
    }

    ll ans = 0;

    // ホウジョ原理を使う
    rep(i, 1<<M) {
        ll mask = 0;
        rep(j, M) {
            if (i>>j&1) {
                mask |= eset[j];
            }
        }
        int white = __builtin_popcountll(mask);
        ll now = 1ll<<(N-1-white);  // 2^(n-1-white)
        // これをansに足すかどうか
        if (__builtin_popcountll(i)%2 == 0) ans += now;  // 偶数個なら足す
        else ans -= now;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define lper(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};
int main(){
    ll N;cin>>N;
    vvl F(N,vl(10)),P(N,vl(11));
    rep(i,N)rep(j,10)cin>>F[i][j];
    rep(i,N)rep(j,11)cin>>P[i][j];
    ll ans=-inf;
    rep(bit,1<<10){
        if(bit==0)continue;
        ll now=0;
        rep(i,N){
            ll count=0;
            rep(j,10){
                if(bit&(1<<j) and F[i][j])count++;
            }
            now+=P[i][count];
        }
        ans=max(ans,now);
    }
    cout<<ans<<endl;
    return 0;
}

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

int main(){
    int a, b; scanf("%d%d", &a, &b);
    if(b == 1){
        cout<<0;
        return 0;
    }
    if(a == b){
        cout<<1;
        return 0;
    }
    if((b - 1) % (a - 1) == 0){
        cout<<(b - 1)/(a - 1);
        return 0;
    }
    else{
        cout<<(b - 1)/(a - 1) + 1;
    }
    return 0;
}

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

int main(){
    int N;
    int sum=0;
    int index;
    double ave,sa;
    int a[101];
    cin >> N;
    for(int i=0;i<N;i++){
        cin >> a[i];
        sum+=a[i];
    }
    ave=(double)sum/(double)N;
    sa=ave;
    for(int i=0;i<N;i++){
        if(sa>fabs(a[i]-ave)){
            sa=fabs(a[i]-ave);
            index=i;
        }
    }
    cout << index;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)	{
	
	int n, s, smax, smin, ssum, mean;
	
	while (true)	{
		
		scanf("%d", &n);
		
		if (n == 0)	{
			break;
		}
		
		smax = 0;
		smin = 1000;
		ssum = 0;
		
		for (int i = 1; i <= n; i++)	{
			
			scanf("%d", &s);
			
			if (smax < s)	{
				smax = s;
			}
			if (smin > s)	{
				smin = s;
			}
			
			ssum += s;
		}
		
		mean = (ssum - smax - smin) / (n - 2);
		
		printf("%d\n", mean);
	}
	
	return 0;
}


Measured memory_bytes: 2724
#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <math.h>
#include <numeric>
#include <iomanip>
#include <map>
#include <queue>
#include <list>

#define REP(i, n ,N) for(ll i = (n); i < (N); i++)
//#define RREP(i, n ,N) for(ll i = (N-1); i >= (n); i--)
#define p(s) cout<<(s)<<endl
#define p2(a, b) cout<<(a)<<" "<<(b)<<endl

#define vint vector<int>
#define vll vector<ll>

#define INF 1e9
#define PI 3.14159265359

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

using namespace std;
typedef long long  ll;

const long long MOD = 1e9+7;


int main(){

    ll n, w;
    cin >> n >> w;

    vll weighs(n);
    vll values(n);

    REP(i, 0, n){
        cin >> weighs[i] >> values[i];
    }

    vector<vector<ll>> dp(n+1, vector<ll>(w+1, 0));

    REP(i, 0, n){
        REP(j, 0, w+1){

            if (j - weighs[i] >= 0){
                chmax(dp[i+1][j], dp[i][j - weighs[i]] + values[i]);
            }

            chmax(dp[i+1][j], dp[i][j]);

        }
    }

    p(dp[n][w]);

}


Measured memory_bytes: 83004
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N, M;
  cin >> N >> M;
  vector<vector<int>> E(N);
  for (int i = 0; i < M; i++){
    int X, Y, Z;
    cin >> X >> Y >> Z;
    X--;
    Y--;
    E[X].push_back(Y);
    E[Y].push_back(X);
  }
  int ans = 0;
  vector<bool> used(N, false);
  for (int i = 0; i < N; i++){
    if (!used[i]){
      ans++;
      used[i] = true;
      queue<int> Q;
      Q.push(i);
      while (!Q.empty()){
        int v = Q.front();
        Q.pop();
        for (int w : E[v]){
          if (!used[w]){
            used[w] = true;
            Q.push(w);
          }
        }
      }
    }
  }
  cout << ans << endl;
}

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

using namespace std;

typedef long long int llint;
typedef pair<int, int> pii;
typedef pair<llint, llint> pll;
typedef vector<int> vi;
typedef vector<llint> vli;
typedef vector<pii> vpii;
typedef vector<pll> vpll;

#define I cin
#define O cout
#define EN endl
#define ln cout<<endl
#define pb(a) push_back(a)
#define x first
#define y second
#define MOD 1000000007

template<typename Tn> Tn gcd(Tn a, Tn b)
{
  return (b ? gcd(b, a % b) : a);
}

template<typename Tn> Tn lcm(Tn a, Tn b)
{
  return a / gcd(a, b) * b;
}

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

map<int, char> m[51];

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

  string s;
  for(int i = 0; i < n; i++) {
    I >> s;

    for(int j = 0; j < 26; j++) m[i]['a' + j] = 0;
    for(int j = 0; j < s.size(); j++) m[i][s[j]]++;
  }

  string ans = "";
  
  for(int i = 0; i < 26; i++) {
    int mn = 51;
    
    for(int j = 0; j < n && mn; j++) {
      int tmp = m[j]['a' + i];
      mn = min(mn, tmp);
    }
    for(int j = 0; j < mn; j++) ans += 'a' + i;
  }

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

  O << ans << EN;
  
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main() {
  char a, b;
  cin >> a >> b;
  
  if (a == 'H') {
    cout << b << endl;
  } else if (a == 'D') {
    if (b == 'H')
      cout << 'D' << endl;
    else
      cout << 'H' << endl;
  }
  
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
#include<complex>
#include<numeric>
using namespace std;

typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef pair<int, int>P;
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
typedef vector<vector<ll>> mat;
typedef vector<int> vec;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
const ll mod = 1000000007;
const ll INF = mod * mod;
const ld eps = 1e-12;
const ld pi = acos(-1.0);
//int qp(int a,ll b){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
ll qp(ll a,ll b,int mo){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
int dx[4] = { 0,1,0,-1 };
int dy[4] = { 1,0,-1,0 };

void solve() {
    ll n;
    string s;
    cin >> n >> s;
    ll ans = 0;

    rep(i, s.size()-2){
        if(s[i] == 'A' && s[i+1] == 'B' && s[i+2] == 'C') ans++;
    }

    cout << ans << endl;
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    //cout << fixed << setprecision(10);
    solve();
    // stop
        return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ff first
#define ss second
#define pb push_back
#define endl "\n"
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
ll mod=1e9+7;


	   
int main() {
			fast
			// #ifndef ONLINE_JUDGE
			// freopen("input.txt","r",stdin);
			// freopen("output.txt","w",stdout);
			// #endif

			ll a,b,n;
			cin>>a>>b>>n;

			if(n>=b)
			{
			ll x=(a*(b-1))/b;
			cout<<x;
			return 0;
			}
			else
			{
				ll x=(a*(n))/b-a*(n/b);
				cout<<x;
			}
			

			
			 
			return 0;
		 }	


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

using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
int N,W;
int v[101];
int w[101];
int dp[101][10001] = {0};
int main(){
    cin >> N >> W;
    rep(i,N){
        cin >> v[i] >> w[i];
    }
    rep(i,N)rep(j,W+1){
        dp[i+1][j] = dp[i][j];
        if(j>=w[i])dp[i+1][j] = max(dp[i][j],dp[i+1][j-w[i]]+v[i]);
    }
    cout << dp[N][W]<< endl;
    
    
    return 0;

}


Measured memory_bytes: 6988
package main

import (
	"bufio"
	"fmt"
	"math/bits"
	"os"
	"strconv"
)

var scanner = bufio.NewScanner(os.Stdin)

func nextString() string {
	scanner.Scan()
	return scanner.Text()
}

func nextInt() uint64 {
	n, err := strconv.Atoi(nextString())
	if err != nil {
		fmt.Printf("strconv.Atoi failed: %v\n", err)
	}
	return uint64(n)
}

func printOneOrZero(ok bool) {
	if ok {
		fmt.Println(1)
	} else {
		fmt.Println(0)
	}
}

func compress(b []bool) uint64 {
	n := len(b)

	queryBits := uint64(0)
	for i := n - 1; i >= 0; i-- {
		if b[i] {
			queryBits++
		}
		if i != 0 {
			queryBits = queryBits << 1
		}
	}

	return queryBits
}

func main() {
	scanner.Split(bufio.ScanWords)

	nMasks := nextInt()
	masks := make([]uint64, nMasks)
	for i := uint64(0); i < nMasks; i++ {
		k := nextInt()
		b := make([]bool, 64)
		for j := uint64(0); j < k; j++ {
			b[nextInt()] = true
		}
		masks[i] = compress(b)
	}

	nQueries := int(nextInt())
	n := uint64(0)
	for i := 0; i < nQueries; i++ {
		queryType := nextInt()
		qi := nextInt()
		// fmt.Printf("%v %b\n", queryType, n)
		if queryType == 0 { // test
			mask := uint64(1) << qi
			// fmt.Printf("qi=%v, n & mask = %v", qi, n&mask)
			printOneOrZero(n&mask != 0)
		} else if queryType == 1 { // set
			n |= masks[qi]
		} else if queryType == 2 { // clear
			// https://stackoverflow.com/questions/23192262/how-would-you-set-and-clear-a-single-bit-in-go
			n &= ^masks[qi]
		} else if queryType == 3 { // flip
			n ^= masks[qi]
		} else if queryType == 4 { // all
			printOneOrZero(n&masks[qi] == masks[qi])
		} else if queryType == 5 { // any
			printOneOrZero(n&masks[qi] != 0)
		} else if queryType == 6 { // none
			printOneOrZero(n&masks[qi] == 0)
		} else if queryType == 7 { // count
			fmt.Println(bits.OnesCount64(n & masks[qi]))
		} else if queryType == 8 { // val
			fmt.Println(n & masks[qi])
		}
	}
}



Measured memory_bytes: 4028
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>

using namespace std;

vector<int> intervalVector;
long long swapCount;
int A[1000000];
int N;

void Insertion(int* A, int N, int interval) {

	for (int i = interval; i < N; i++) {
		int targetValue = A[i];
		int j = i - interval;

		while (j >= 0 && A[j] > targetValue) {
			A[j + interval] = A[j];
			j -= interval;
			swapCount++;
		}
                A[j+interval] = targetValue;
	}
	return;
}

void Shell(int* A, int N) {

	for (int i = 1; ; ){
            if(i > N) break;
            intervalVector.push_back(i);
            i = i * 3 + 1;
        }

	for (int i = intervalVector.size() - 1; i >= 0; i--) Insertion(A, N, intervalVector[i]);

	return;
}



int main() {


	swapCount = 0;

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

	cout << intervalVector.size() << endl;
	for (int i = intervalVector.size() - 1; i >= 0; i--) {
		printf("%d",intervalVector[i]);
		if (i) printf(" ");
	}

	printf("\n");
	printf("%d\n",swapCount);

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


	return 0;
}


Measured memory_bytes: 7188
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Diagnostics;

class Myon
{
    public Myon() { }
    public static int Main()
    {
        new Myon().calc();
        return 0;
    }

    Scanner cin;
    Func cin2;
    void calc()
    {
        cin = new Scanner();
        cin2 = new Func();
        string S=cin.next();
        string ans="YES";
        int count=0;
        for(int i=0;i<S.Length;i++)
        {
            if(S[i]=='x')count++;
        }
        if(count>=8)ans="NO";
        Console.WriteLine(ans);
        
    }

}



class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }


    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}

class Answer
{
    public static void Int2DArrayAns(int[,]x,char c)
    {
        for(int i=0;i<x.GetLength(0);i++)
        {
            for(int j=0;j<x.GetLength(1)-1;j++)
            {
                Console.Write(x[i,j]);
                Console.Write(c);
            }
            Console.WriteLine(x[i,x.GetLength(1)-1]);
        }
    }//Answer.IntArrayAns(x);
    public static void Char2DArrayAns(char[,]x,char c)
    {
        for(int i=0;i<x.GetLength(0);i++)
        {
            for(int j=0;j<x.GetLength(1)-1;j++)
            {
                Console.Write(x[i,j]);
                Console.Write(c);
            }
            Console.WriteLine(x[i,x.GetLength(1)-1]);
        }
    }
}

class Func
{
    public long GCDLong(long a, long b)
    {
        while(a!=0)
        {
          long t=a;
          a=b%a;
          b= t;
        }
      
        return b;        
    }
}



Measured memory_bytes: 11092
n, m, x = list(map(int, input().split()))
a = list(map(int, input().split()))
ans = []
pos = x
cost = 0
for i in range(0, x):
  pos -= 1
  if pos in a:
    cost += 1
ans.append(cost)
pos = x
cost = 0
for i in range(x, n):
  pos += 1
  if pos in a:
    cost += 1
ans.append(cost)
print(min(ans))

Measured memory_bytes: 3064
#include<iostream>
using namespace std;
int cnt[26];
int S[10];
string t;
int N;
main()
{
	cin>>N>>t;
	for(int i=0;i<N;i++)
	{
		if(t[i]!='+')
		{
			cnt[t[i]-'a']++;
		}
	}
	int ans=-1;
	for(int i=0;i<26;i++)
	{
		S[cnt[i]]++;
	}
	ans+=2*S[1];
	for(int i=2;i<10;i++)
	{
		if(S[i]==0);
		else if(S[i]==1)ans+=4;
		else ans+=4+S[i]*2;
	}
	cout<<ans<<endl;
}



Measured memory_bytes: 3216
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<(n);++i)
#define dunk(a) cout << (a) << endl
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
using namespace std;
typedef long long ll;

int main() {
	ll a, b, k; cin >> a >> b >> k;

	if (a >= k) a -= k;
	else if (a < k && a + b >= k) {
		b = b - k + a;
		a = 0;
	}
	else if (a + b < k) {
		a = 0;
		b = 0;
	}

	dunk(a);
	dunk(b);
	return 0;
}


Measured memory_bytes: 256
object Main extends App {
  val input = io.Source.stdin.getLines.toIndexedSeq.head
  val A=input(0)-'0'
  val B=input(1)-'0'
  val C=input(2)-'0'
  val D=input(3)-'0'
  
  if     (A+B+C+D==7) println(A+"+"+B+"+"+C+"+"+D+"=7")
  else if(A+B+C-D==7) println(A+"+"+B+"+"+C+"-"+D+"=7")
  else if(A+B-C+D==7) println(A+"+"+B+"-"+C+"+"+D+"=7")
  else if(A+B-C-D==7) println(A+"+"+B+"-"+C+"-"+D+"=7")
  else if(A-B+C+D==7) println(A+"-"+B+"+"+C+"+"+D+"=7")
  else if(A-B+C-D==7) println(A+"-"+B+"+"+C+"-"+D+"=7")
  else if(A-B-C+D==7) println(A+"-"+B+"-"+C+"+"+D+"=7")
  else if(A-B-C-D==7) println(A+"-"+B+"-"+C+"-"+D+"=7")
}

Measured memory_bytes: 25432
import java.util.*;
import java.io.*;

public class Main 

{ 
static int mod=(int)Math.pow(10, 9)+7;
	 static FastReader sc=new FastReader(); 
	 
		  public static void main(String[] args) 
    {
			  int n=i();
			  if(n==0)
				  System.out.println("1");
			  else
				  System.out.println("0");
			 
			  
		  
    }
		  
		  
static int[] input(int n) {
	int A[]=new int[n];
	   for(int i=0;i<n;i++) {
		   A[i]=sc.nextInt();
	   }
	   return A;
   }
static long[] inputL(int n) {
	long A[]=new long[n];
	   for(int i=0;i<n;i++) {
		   A[i]=sc.nextLong();
	   }
	   return A;
   }
static String[] inputS(int n) {
	String A[]=new String[n];
	   for(int i=0;i<n;i++) {
		   A[i]=sc.next();
	   }
	   return A;
   }


static void input(int A[],int B[]) {
	   for(int i=0;i<A.length;i++) {
		   A[i]=sc.nextInt();
		   B[i]=sc.nextInt();
	   }
}
static long mod(long x) {
	  return ((x%mod + mod)%mod);
}

     static int i() {
    	 return sc.nextInt();
     }
     static String s() {
    	 return sc.next();
     }
     static long l() {
    	 return sc.nextLong();
     }  
     static void sort(int[] arr){
        int n = arr.length;
        Random rnd = new Random();
        for(int i=0; i<n; ++i){
            int tmp = arr[i];
            int randomPos = i + rnd.nextInt(n-i);
            arr[i] = arr[randomPos];
            arr[randomPos] = tmp;
        }
        Arrays.sort(arr);
     }
  
        
        
    static class FastReader 
    { 
        BufferedReader br; 
        StringTokenizer st; 
  
        public FastReader() 
        { 
            br = new BufferedReader(new
                     InputStreamReader(System.in)); 
        } 
  
        String next() 
        { 
            while (st == null || !st.hasMoreElements()) 
            { 
                try
                { 
                    st = new StringTokenizer(br.readLine()); 
                } 
                catch (IOException  e) 
                { 
                    e.printStackTrace(); 
                } 
            } 
            return st.nextToken(); 
        } 
  
        int nextInt() 
        { 
            return Integer.parseInt(next()); 
        } 
  
        long nextLong() 
        { 
            return Long.parseLong(next()); 
        } 
  
        double nextDouble() 
        { 
            return Double.parseDouble(next()); 
        } 
  
        String nextLine() 
        { 
            String str = ""; 
            try
            { 
                str = br.readLine(); 
            } 
            catch (IOException e) 
            { 
                e.printStackTrace(); 
            } 
            return str; 
        } 
    } 
} 





Measured memory_bytes: 25332
#include<cstdio>
using namespace std;




int main(){

    int m[2000];
    int a,b,c;

    m[0] = 0;
    for(int i = 0;i < 1000;i++){
        m[i + 1] = m[i] + i;
    }
    scanf("%d%d",&a,&b);

    c = b - a;

    printf("%d\n",m[c] - a);
}


Measured memory_bytes: 128
package main

import (
	"fmt"
)

func main() {
	var a, b, c, k int
	var sum = 0

	k = 0

	fmt.Scan(&a, &b, &c, &k)

	if a > k {
		sum += k
	} else if a <= k{
		sum += a
	}

	if a + b < k {
		sum -= k - a - b
	}


	fmt.Println(sum)
}




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


def main():
    N = int(input())
    As = [int(input()) for _ in range(N)]
    max1 = max(As)
    max_idx = As.index(max1)
    As.remove(max1)
    max2 = max(As)
    max_list = [max1] * N
    max_list[max_idx] = max2
    for m in max_list:
        print(m)


if __name__ == '__main__':
    main()


Measured memory_bytes: 14080
using System;

namespace ABC079_B
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            long L0 = 2;
            long L1 = 1;
            for (int i = 2; i <= N; i++)
            {
                long L2 = L1 + L0;
                L0 = L1;
                L1 = L2;
            }
            Console.WriteLine(L1);
        }
    }
}


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

typedef long long int ll;
ll MOD = 1000000007;
ll INFL = 1ll << 60;
ll INF = 1 << 28;

// ====================================================================

int main() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  int count = 0;
  for (int i = 0; i < s.size() - 2; i++) {
    if (s[i] == 'A' && s[i + 1] == 'B' && s[i + 2] == 'C') count++;
  }
  cout << count << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<int,pii> pr;
const ll mod = 1e9L+7;
ll numberOfWays(int x,int y,vector<string> &grid,int m,int n,vector<vector<ll>> &dp){
	if(x >=m || y>=n){
		return 0;
	}
	if(x == m-1 && y == n-1){
		return 1;
	}
	if(dp[x][y]!=-1){
		return dp[x][y];
	}
	if(grid[x][y] == '#'){
		return dp[x][y] = 0;
	}
	ll ans1 = numberOfWays(x+1,y,grid,m,n,dp);
	ll ans2 = numberOfWays(x,y+1,grid,m,n,dp);
	return dp[x][y] = (ans1+ans2)%mod;
}
int main(int argc,char const* argv[]){
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	int m,n;
	cin>>m>>n;
	vector<string> grid(m);
	for(int i=0;i<m;i++){
		cin>>grid[i];
	}
	vector<vector<ll>>dp(m,vector<ll>(n,-1));
	cout<<numberOfWays(0,0,grid,m,n,dp);
	return 0;
}

Measured memory_bytes: 9344
/**
 *    author:  otera    
**/
#include<iostream>
#include<string> 
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm> 
#include<functional>
#include<iomanip>
#include<queue>
#include<deque>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

//#define int long long
typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const int inf=1e9+7;
const ll INF=1LL<<60 ;
const ll mod=1e9+7 ;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
#define debug(x)  cerr << #x << " = " << (x) << endl;
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; }

void solve() {
	int a, b; cin >> a >> b;
    cout << a * b << endl;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//int t; cin >> t; rep(i, t)solve();
	solve();
    return 0;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
//#define s second
#define f first
long long const mod = 1000000007; 
#define inf 1000000000000000000
inline ll add(ll a, ll b){ return ((a%mod)+(b%mod)+mod)%mod;}
inline ll mul(ll a, ll b){ return (((a%mod)*(b%mod))%mod+mod)%mod;}
inline ll sub(ll a, ll b){ return ((a%mod)-(b%mod)+mod)%mod;}

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

ll power(ll x,ll y,ll m) 
{ 
    if (y == 0) 
        return 1; 
    ll p = power(x, y/2, m) % m;
    p = (p * p) % m; 
    return (y%2 == 0)? p : (x * p) % m; 
}

ll modInv(ll x)
{
    return power(x,mod-2,mod)%mod;
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
        
   
    ll n;
    cin>>n;
    bool f=false;
    while(n)
    {
        ll x=n%10;
        if(x==7)
        {
            f=true;
            break;
        }
        n=n/10;
    }
    if(f)
        cout<<"Yes\n";
    else
    {
        cout<<"No\n";
    }
    

    return 0;
}

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

#define task "C"
#define all(v) (v).begin(), (v).end()
#define rep(i, l, r) for (int i = (l); i <= (r); ++i)
#define Rep(i, r, l) for (int i = (r); i >= (l); --i)
#define DB(X) { cerr << #X << " = " << (X) << '\n'; }
#define DB1(A, _) { cerr << #A << "[" << _ << "] = " << (A[_]) << '\n'; }
#define DB2(A, _, __) { cerr << #A << "[" << _ << "][" << __ << "] = " << (A[_][__]) << '\n'; }
#define DB3(A, _, __, ___) { cerr << #A << "[" << _ << "][" << __ << "][" << ___ << "] = " << (A[_][__][___]) << '\n'; }
#define PR(A, l, r) { cerr << '\n'; rep(_, l, r) DB1(A, _); cerr << '\n';}
#define SZ(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back
#define pf push_front
#define F first
#define S second
#define by(x) [](const auto& a, const auto& b) { return a.x < b.x; } // sort(arr, arr + N, by(a));
#define next ___next
#define prev ___prev
#define y1 ___y1
#define left ___left
#define right ___right
#define y0 ___y0
#define div ___div
#define j0 ___j0
#define jn ___jn

using ll = long long;
using ld = long double;
using ull = unsigned long long;
using namespace std;
typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<ll> vl;
const int N = 2e5 + 2, NN = 1e6 + 2, mod = 998244353;
int n, cnt[NN], w[NN];
int main()
{
#ifdef HynDuf
    freopen(task".in", "r", stdin);
    //freopen(task".out", "w", stdout);
#else
    ios_base::sync_with_stdio(false); cin.tie(nullptr);
#endif
    cin >> n;
    rep(i, 1, n)
    {
        int x;
        cin >> x;
        cnt[x]++;
    }
    w[1] = 1;
    rep(i, 2, NN - 2) w[i] = (mod - mod / i) * 1LL * w[mod % i] % mod;
    rep(i, 1, NN - 3) for (int j = 2; j * i < NN - 1; j++) w[j * i] = (w[j * i] - w[i] + mod) % mod;
    int ans = 0;
    rep(d, 1, NN - 2)
    {
        int sum = 0, res = 0;
        for (int j = 1; j * d < NN - 1; j++) rep(i, 1, cnt[j * d])
        {
            (res += (j * d) * 1LL * sum % mod) %= mod;
            (sum += j * d) %= mod;
        }
        (ans += w[d] * 1LL * res % mod) %= mod;
    }
    cout << ans;
    return 0;
}


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

int N, Q;
vector<int> edges[200000];
int64_t num[200000];

void dfs(int i, int p){
    for(int j : edges[i]) if(j != p){
        num[j] += num[i];
        dfs(j, i);
    }
}

int main(){
    cin >> N >> Q;
    for(int i=0; i<N-1; i++){
        int a, b;
        cin >> a >> b;
        edges[a-1].push_back(b-1);
        edges[b-1].push_back(a-1);
    }
    for(int i=0; i<Q; i++){
        int p, x;
        cin >> p >> x;
        num[p-1] += x;
    }
    dfs(0, -1);
    for(int i=0; i<N; i++) cout << num[i] << " \n"[i==N-1];
    return 0;
}

Measured memory_bytes: 28536
S = input()

s1 = int(S[0:2])
s2 = int(S[2:4])

if 1 <= s1 <= 12 :
    if 1<= s2 <= 12:
        print("AMBIGUOUS")
    else :
        print("MMYY")
elif 1 <= s2 <= 12:
    print("YYMM")
else :
    print("NA")


Measured memory_bytes: 2940
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
#include <cstdio>
#include <cmath>
using namespace std;
int main(){
	long long a,b,x,y,count=0;
	while(cin>>a>>b){
		if(a==0&&b==0)break;
		if(a>=b){
			x=a;y=b;
		}else{
			x=b;y=a;
		}
		while(1){
			if(y==0)break;
			x=x%y;
			swap(x,y);
			count++;
		}
		cout<<x<<" "<<count<<endl;
		count=0;
	}
	return 0;
}

Measured memory_bytes: 3096
MAX_TIME = 10

N = int(input())

F = [[int(j) for j in input().split()] for i in range(N)]

P = [[int(j) for j in input().split()] for i in range(N)]


def main():
    ans = -11000000001

    # 営業時間帯 最低でも ひとつの時間帯
    # 選択パターン
    for i in range(1, 2 ** MAX_TIME):
        tmp = 0

        # 他の店
        for j in range(N):
            # 各時間帯
            cnt = sum([F[j][k] for k in range(MAX_TIME) if i >> k & 1])
            tmp += P[j][cnt]

        ans = max(ans, tmp)

    print(ans)
    return


main()


Measured memory_bytes: 3064
import java.util.*;

public class Main{

	public static void main(String[] args){
	
		Scanner scan = new Scanner(System.in);
		
		int allNum = scan.nextInt();
		
		long fStock = 0;
		long buy = 0;
		long aCheck = 0;
		long pStock = 0;
		
		for(int i=0; i < allNum; i++){
			
			fStock = scan.nextLong();
			buy = scan.nextLong();
			aCheck = scan.nextLong();
			pStock = scan.nextLong();
			
			if(check(fStock,buy,aCheck,pStock)) System.out.println("Yes");
			else System.out.println("No");
			
		}
		scan.close();
	
	}	
	
	private static boolean check(long fStock,long buy,long aCheck,long pStock){
		
		if(fStock < buy) return false;
		if(buy > pStock) return false;
		if(aCheck >= buy) return true;
		
		long ba = baCheck(buy,pStock);
		
		if(buy - ba + (fStock % ba) > aCheck) return false;
		else return true;
	}
	
	private static long baCheck(long buy,long pStock){
		long c = buy % pStock;
		if(c==0) return pStock;
		return baCheck(pStock,c);
	}

}

Measured memory_bytes: 23268
import java.util.Scanner;

class Solver {
	static final Solver INSTANCE = new Solver();

	void solve(Scanner sc) {
		int N = sc.nextInt();
		int M = sc.nextInt();
		String[] A = new String[N];
		String[] B = new String[M];
		for (int i = 0; i < N; i++) {
			A[i] = sc.next();
		}
		for (int i = 0; i < M; i++) {
			B[i] = sc.next();
		}
		for (int i = 0; i < N - M + 1; i++) {
			block:
			for (int index = A[i].indexOf(B[0]); index < N && index >= 0; index = A[i].indexOf(B[0], index + 1)) {
				for (int j = 1; j < M; j++) {
					if (!A[i + j].substring(index).startsWith(B[j])) continue block;
				}
				System.out.println("Yes");
				return;
			}
		}
		System.out.println("No");
	}
}

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

		Solver.INSTANCE.solve(in);

		in.close();
	}
}

Measured memory_bytes: 21844
import bisect


n = int(input())
a = [0] * n
for i in range(n):
    a[i] = int(input())
L = []
L.append(a[0])
for i in range(1,n):
    p = bisect.bisect_right(L, a[i])
    if L[-1] == a[i]:
        continue;
    elif p == len(L):
        L.append(a[i])
    else:
        if L[p-1] != a[i]:
            L[p] = a[i]
print(len(L))



Measured memory_bytes: 10444
def solve():
  s = input()
  n = len(s)
  odd = ""
  even = ""
  for i in range(n):
    if i%2 == 0:
      odd += s[i]
    else:
      even += s[i]
  
  oddzero = odd.count("0")
  oddone = odd.count("1")
  evenzero = even.count("0")
  evenone = even.count("1")
  ans = min(oddzero+evenone,oddone+evenzero)
  
  print(ans)
solve()

Measured memory_bytes: 3188