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

using namespace std;

int main(){
    int n,t,ans = 10000;
    cin >> n >> t;

    for(int i = 0;i < n;i++){
        int c,t1;
        cin >> c >> t1;
        if(t1 <= t)
            ans = min(ans,c);
    }

    if(ans == 10000)cout << "TLE" << endl;
    else cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <bitset>
#include <complex>
#include <unistd.h>
#include <cassert>
#include <cctype>
#include <random>
#include <time.h>
#define _USE_MATH_DEFINES
#define _GLIBCXX_DEBUG
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef pair<double, ll> pdlg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
typedef tuple<double, double, double> tddd;
typedef complex<double> xy_t;
typedef vector<ll> vll;
typedef vector< vector<ll> > matrix;
#define REP(i, x, y) for(ll i = (ll)x; i < (ll)y; i++)
#define DREP(i, x, y, d) for(ll i = (ll)x; i < (ll)y; i += (ll)d)
#define PER(i, x, y) for(ll i = (ll)x; i > (ll)y; i--)
#define DPER(i, x, y, d) for(ll i = (ll)x; i > (ll)y; i -= (ll)d)
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
double pi = 3.141592653589793;
ll mod = 1000000007;
int intmax = 2147483647;
int intmin = -2147483648;
ll llmax = 9223372036854775807;
ll llmin = -9223372036854775807;
int iinf = intmax / 8;
ll inf = llmax / 8;
double eps = 1e-12;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N, A, B;
    cin >> N >> A >> B;
    ll num = N / (A + B);
    ll ans = num * A;
    ll rem = N % (A + B);
    if (rem >= A) {
        ans += A;
    } else {
        ans += rem;
    }
    cout << ans << endl;
}


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

using namespace std;

int a,b;

int search(int s_a,int s_b)
{
	if(s_b==0)
		return s_a;
	
	search(s_b,s_a%s_b);
	
}

int main()
{
	int a2,b2;
	
	for(;cin >> a;)
	{
		cin >> b;
		a2=a;
		b2=b;
		
		a=max(a2,b2);
		b=min(a2,b2);
		
		
		
		a=search(a,b);
		
		cout << a << " " << a2*(b2/a) << endl;
	}
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
int main() {
    int N;cin>>N;
    int ans;
    vector<int> A(N);

    for(int i=0;i<=N-1;i++) {
        cin >> A[i];
    }
    int max=*max_element(A.begin(),A.end());
    int min=*min_element(A.begin(),A.end());
    ans=max-min;
    cout<<ans;
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define base 1000000007LL
#define ll long long
#define ld double
#define X first
#define Y second
#define pb push_back
#define EPS 1e-22
#define all(a) (a).begin(), (a).end()
#define sz(a) int((a).size())
#define ms(s, n) memset(s, n, sizeof(s))
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORE(i,a,b) for (int i = (a); i >= (b); i--)
#define FORALL(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
using namespace std;
typedef pair<int, int> II;
typedef pair<II, int> III;

int main()
{
    ios::sync_with_stdio(0);
    //freopen("inp.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    string s, t, r;
    cin >> s >> t >> r;
    cout << char(toupper(s[0])) << char(toupper(t[0])) << char(toupper(r[0]));
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(int argc, const char** argv) {
    int i,j;
    string s,t;
    cin>>s>>t;
    int n = s.length()+1;
    int m = t.length()+1;
    int L[n][m];
    //string M[n][m];
    for(i=0;i<n;i++){
        for(j=0;j<m;j++){
            if(i==0 || j==0)
                L[i][j] = 0;
            else if(s[i-1]==t[j-1]){
                L[i][j] = L[i-1][j-1]+1;
            }
            else 
                L[i][j] = max(L[i-1][j],L[i][j-1]);
        }
    }
    int index = L[n-1][m-1];
    char ans[index+1];
    ans[index] = '\0';
    i = n-1, j = m-1;
    while(i>0 && j>0){
        if(s[i-1]==t[j-1]){
            ans[index-1]=s[i-1];
            i--;
            j--;
            index--;
        }
        else if(L[i-1][j]>L[i][j-1])
            i--;
        else 
            j--;
    }
    cout<<ans<<"\n";
    return 0;
}

Measured memory_bytes: 35456
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
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; }
const long long INF = 1LL << 60;
 
typedef pair<ll,ll> pairs;
vector<pairs> p;
bool pairCompare(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.first < secondElof.first;
}
#define MAX_N 1000100
bool x[MAX_N];
ll num[MAX_N];
ll fibl[MAX_N]={0};
 
ll fib(ll a){
    if (fibl[a]!=0)return fibl[a];
    if (a==0){
        return 0;
    }else if (a==1){
        return 1;
    }
    return fibl[a]=fib(a-1)+fib(a-2);
}
 
ll eratosthenes(ll n) {
    int p = 0;
    for (ll i=0; i<=n; ++i) x[i] = true;
    x[0] = x[1] = false;
    for(int i=2; i<=n; ++i) {
        if(x[i]) {
            p++;
            for(int j=2*i; j<=n; j+=i) x[j] = false;
        }
        
        num[i] = p;
    }
    return p;
}
 
ll gcd(ll a,ll b){
    if (a%b==0)return(b);
    else return(gcd(b,a%b));
}
 
ll keta(ll N){
    int tmp{};
    while( N > 0 ){
        tmp += ( N % 10 );
        N /= 10;
    }
    N = tmp;
    return N;
}

int main(){
    ll a,b,c,d;
    cin>>a>>b>>c>>d;
    
    if (a+b > c+d)cout << "Left" << endl;
    else if (a+b < c+d)cout << "Right" << endl;
    else if (a+b == c+d)cout << "Balanced" << endl;
    
    
    
    return 0;
}



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

int main() {
    int n;
    std::string s;
    std::cin >> n >> s;
    int ans = n;
    for (int i = 0; i < n - 1; ++i) {
        if (s[i] == s[i + 1]) --ans;
    }
    std::cout << ans << std::endl;
}

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

const double pi = 3.14159265358979323846;
const ll mod = 1000000007;


int main() {
	cin.tie(0);
   	ios::sync_with_stdio(false);
	int k; cin >> k;
	string s; cin >> s;
	int len = s.size();
	if(len <= k) cout << s << endl;
	else{
		for(int i = 0; i < k; i++){
		   cout << s.at(i);
		}
		cout << "...";
	}

} 

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

#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,x,n) for(int i=x; i<(n); i++)
#define rrep(i,n) for(int i=(n)-1; i>=0; i--)
#define all(X) (X).begin(),(X).end()
#define X first
#define Y second
#define pb push_back
#define eb emplace_back

using namespace std;
typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

template<class A, size_t N, class T> void Fill(A (&a)[N], const T &v){ fill( (T*)a, (T*)(a+N), v ); }

template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {os<<"{"; rep(i,t.size()) {os<<t[i]<<",";} os<<"}"; return os;}
template<class T,size_t n> ostream& operator<<(ostream &os, const array<T,n> &t) {os<<"{"; rep(i,n) {os<<t[i]<<",";} os<<"}"; return os;}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}

const ll INF = 1e9+7;


int main(){
        ios_base::sync_with_stdio(false);
        ll N, ans=0;
        string S;

        cin >> S;

        int l=0;
        rep(i,S.length()) if( S[i] == 'W' ){
                ans += i-l;
                l++;
        }

        cout << ans << endl;

        return 0;
}


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

#define ll long long
#define mod 1000000007

using namespace std;



int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,a,x=0,y=0,b,z=0,z2=0;
    cin>>n;
    ll l1[n+2];map<ll,ll>m1,m2;
    //cin>>l1[1]>>l1[2];
    for(int i=1;i<=n;i++){
        cin>>l1[i];
        if(i&1){
            m1[l1[i]]++;
            if(m1[l1[i]]>x)x=m1[l1[i]],a=l1[i];
        }
        else{
            m2[l1[i]]++;
            if(m2[l1[i]]>y)y=m2[l1[i]],b=l1[i];
        }
    }
    if(a==b&&x>y){
        for(int i=2;i<=n;i+=2){
            if(l1[i]!=b)z=max(z,m2[l1[i]]);
        }n/=2;
        cout<<(n-x)+(n-z)<<endl;
    }
    else if(a==b&&x==y){
        for(int i=2;i<=n;i+=2){
            if(l1[i]!=b)z=max(z,m2[l1[i]]);
        }
        for(int i=1;i<=n;i+=2){
            if(l1[i]!=a)z2=max(z2,m1[l1[i]]);
        }n/=2;
        if(z>=z2)cout<<(n-z)+(n-x)<<endl;
        else cout<<(n-z2)+(n-x)<<endl;
    }
    else if(a==b&&x<y){
        for(int i=1;i<=n;i+=2){
            if(l1[i]!=a)z=max(z,m1[l1[i]]);
        }n/=2;
        cout<<(n-y)+(n-z)<<endl;
    }
    else {n/=2;cout<<(n-x)+(n-y)<<endl;}
}


Measured memory_bytes: 10600
s = gets.chomp.chars
yymm = true
mmyy = true

if (s[2] == '0' && s[3] == '0')
  yymm = false
end
if (s[0] == '0' && s[1] == '0')
  mmyy = false
end
if (s[0] + s[1]).to_i > 12
  mmyy = false 
end
if (s[2] + s[3]).to_i > 12
  yymm = false
end

if yymm && mmyy
  puts 'AMBIGUOUS'
elsif yymm && !mmyy
  puts 'YYMM'
elsif !yymm && mmyy
  puts 'MMYY'
else
  puts 'NA'
end

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

int main(){
  int n;
  cin >>n;
  int yen=1000;
  while(1){
    if(yen>=n){
      cout <<yen-n<<endl;
      return 0;
    }
    else{
      yen+=1000;
    }
  }
}

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

#define rep(i, N) for (ll i = 0; i < N; i++)
#define rep1(i, N) for (ll i = 1; i <= N; i++)
#define repr(i, N) for (ll i = N-1; i >= 0; i--)
#define repr1(i, N) for (ll i = N; i > 0; i--)

#define INF (int)1e9+7

using ll = long long;
using namespace std;

typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<P> vpi;
typedef pair<ll,ll> Pl;
typedef vector<ll> vl;
typedef vector<Pl> vpl;

ll gcd(ll a, ll b){
    if(a < b) swap(a, b);
    if(b <= 0) return -1;
    ll r = a % b;
    while(r != 0){
        a = b;
        b = r;
        r = a % b;
    }
    return b;
}

ll lcm(ll a, ll b){
    return (a/gcd(a,b)*b);
}

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

    ll ABgcd = gcd(A, B);
    ll ans = 1;
    for (ll i = 2; i*i <= ABgcd; i++) {
        if(ABgcd%i == 0) {
            while(ABgcd%i == 0) {
                ABgcd /= i;
            }
            ans++;
        }
    }
    if(ABgcd > 1) ans++;

    //string ans = ( flag ? "Yes" : "No" );
    //printf("%.8lf\n", ans);
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main{
        public static void main(String[] args){
                Scanner sc = new Scanner(System.in);
                int n = sc.nextInt();
                if(n % 2 != 0) n *= 2;
                System.out.println(n);
        }
}//0=48
 //a=97 a -> +26 = 123
//鶏になれ

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

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

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

    cout << a << " " << b << endl;
    return 0;
}

Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;
import java.util.HashSet;
import java.util.Set;

public class Main{
	public static void main(String[] args){
    	InputStream inputStream = System.in;
    	OutputStream outputStream = System.out;
    	Scanner sc = new Scanner(inputStream);
    	PrintWriter out = new PrintWriter(outputStream);
      	int N = Integer.parseInt(sc.next());
      	Set<String> list = new HashSet<String>();
      	for(int i = 0; i < N; i++){
          	list.add(sc.next());
        }
      	System.out.println(list.size());
    	out.close();
    }
}

Measured memory_bytes: 21716
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<bitset>
#include<deque>
#include<cstdlib>
#include<set>
#include<ctime>
#define N 100003
#define mod 1000000007
#define ll long long
#define mp make_pair
using namespace std;
ll read()
{
	ll x=0,f=1;
	char c=getchar();
	while(c>'9'||c<'0')
	{
		if(c=='-') f=-1;
		c=getchar();
	}
	while(c>='0'&&c<='9')
	{
		x=x*10+c-'0';
		c=getchar();
	}
	return f*x;
}
int n;
ll ans;
int as[27];
char s[N];
int main()
{
	n=read();
	scanf("%s",s+1);
	for(int i=1;i<=n;++i) as[s[i]-'a']++;
	ans=1;
	for(int i=0;i<26;++i) ans=ans*(as[i]+1)%mod;
	cout<<ans-1;
	return 0;
 }


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define int long long
using namespace std;

signed main()
{
    string s;
    cin >> s;
    int n = s.size();
    vector < int > a(n);
    vector < int > pos;
    for (int i = 0; i < n; ++i)
    {
        char x = s[i];
        if (x == '<')
        {
            a[i] = 0;
        }
        else
        {
            a[i] = 1;
        }
    }
    int len = 0;
    for (int i = 0; i < n; ++i)
    {
        if (i == 0 || a[i - 1] == a[i])
        {
            len++;
        }
        else
        {
            if (a[i - 1] == 0)
                pos.push_back(len);
            else
                pos.push_back(-len);
            len = 1;
        }
    }

    if (a[n - 1] == 0)
        pos.push_back(len);
    else
        pos.push_back(-len);
//    for (auto i : pos)
//        cout << i << ' ';
    int ans = 0;
    int l = 0, r = pos.size() - 1;
    if (pos[l] < 0)
    {
        pos[l] = abs(pos[l]);
        ans += pos[l] * (pos[l] + 1) / 2;
      	pos[l] = -pos[l];
        l++;
    }
    if (pos[r] > 0)
    {
        ans += pos[r] * (pos[r] + 1) / 2;
        r--;
    }
    for (int i = l; i + 1 <= r; i += 2)
    {
        int len1 = abs(pos[i]), len2 = abs(pos[i + 1]);
        int ad = max(len1, len2), bc = min(len1, len2);
        ans += ad * (ad + 1) / 2;
        ans += bc * (bc - 1) / 2;
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 7932
#include <iostream>
#include <climits>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <deque>
#define INF_INT (INT_MAX / 2)
#define INF_LONG (LONG_MAX / 2)
//#define DEBUG true
#define DEBUG false
using namespace std;

const int MAX = 100001;
const int MOD = 1000000007;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;

int ceil(int x, int y) { return (x % y == 0) ? x / y : x / y + 1; }

int gcd(int x, int y) { return y ? gcd(y, x % y) : x; }

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

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

  int h, a;
  cin >> h >> a;

  int ans;
  if(h % a == 0) {
    ans = h / a;
  } else {
    ans = h / a + 1;
  }

  cout << ans << endl;

  return 0;
}


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

int main() {
ll n; cin>>n;
  ll m[5]={0};
  string name[n];
  rep(i, n){
    cin>>name[i];}
  
  rep(i, n){
    string p=name[i];
    char q=p[0];
    if(q=='M') m[0]++;
    if(q=='A') m[1]++;
    if(q=='R') m[2]++;
    if(q=='C') m[3]++;
    if(q=='H') m[4]++;
}
  
  ll com=0;
  for(int i=0;i<=2;i++){
    for(int j=i+1;j<=3;j++){
      for(int k=j+1;k<=4;k++){
        com+=m[i]*m[j]*m[k];
      }
    }
  }
  
  cout<<com<<endl;
}

Measured memory_bytes: 6144
def readInts():
  return list(map(int,input().split()))
mod = 10**9 + 7
def gcd(a,b):
  if b == 0:
    return a
  return gcd(b, a % b)
def main():
  k = int(input())
  ans = 0
  for a in range(1,k+1):
    for b in range(1,k+1):
      for c in range(1,k+1):
        ans += gcd(a,gcd(b,c))
  print(ans)
if __name__ == '__main__':
  main()

Measured memory_bytes: 74280
#include<algorithm>
#include<iostream>
#include<string>


using namespace std;

int main(void){
	long long N,C;
	long long x[100100];
	long long v[100100];
	long long f[100100];
	long long fmx[100100];
	long long g[100100];
	long long gmx[100100];

	cin >> N >> C;
	x[0] = 0;
	f[0] = 0;
	fmx[0] = 0;
	g[0] = 0;
	gmx[0] = 0;
	for(int i=1; i <= N; i++){
		cin >> x[i] >> v[i];
	}

	// 時計周りに計算、maxも計算
	for(int i = 1;i<=N; i++){
		f[i] = f[i-1] + v[i] - (x[i] - x[i-1]);
		fmx[i] = max(fmx[i-1], f[i]);
	}
	x[N+1] = C;
	// 逆時計周りに計算
	for(int i=N; i>=1; i--){
		g[N-i+1] = g[N-i] + v[i] - (x[i+1] - x[i]);
		gmx[N-i+1] = max(gmx[N-i], g[N-i+1]);
	}
	long long ans = 0;

	for(int i =0; i< N; i++){
		ans = max(ans, f[i] - x[i] + gmx[N-i]);
		ans = max(ans, g[i] - (C - x[N-i+1]) + fmx[N-i]);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 4992
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

fn main() {
    let v:Vec<usize> = read_vec();
    let (n, ma, mb) = (v[0], v[1], v[2]);
    let mut a = vec![0usize; n];
    let mut b = vec![0usize; n];
    let mut c = vec![0usize; n];

    for i in 0..n {
        let v:Vec<usize> = read_vec();
        a[i] = v[0];
        b[i] = v[1];
        c[i] = v[2];
    }

    let sum_a: usize = a.iter().sum();
    let sum_b: usize = b.iter().sum();
    // println!("sum_a {0} sum_b {1}", sum_a, sum_b);
    let mut dp = vec![vec![std::usize::MAX; sum_b + 1]; sum_a + 1];
    dp[0][0] = 0;

    for ni in 0..n {
        for ai in (0..sum_a + 1).rev() {
            for bi in (0..sum_b + 1).rev() {
                if dp[ai][bi] == std::usize::MAX {
                    continue;
                }
                dp[ai + a[ni]][bi + b[ni]] = std::cmp::min(dp[ai + a[ni]][bi + b[ni]],
                                                           dp[ai][bi] + c[ni]);
            }
        }
    }

    let mut ans = std::usize::MAX;
    for ai in 1..sum_a + 1 {
        for bi in 1..sum_b + 1 {
            if ai % ma == 0 && bi % mb == 0  && ai != 0 && ai * mb == bi * ma {
                // println!("{0} {1}", ai, bi);
                ans = std::cmp::min(ans, dp[ai][bi]);
            }
        }
    }
    if ans == std::usize::MAX {
        println!("-1");
    } else {
        println!("{:?}", ans);
    }
}


Measured memory_bytes: 4352
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
int main() {
  int a[4]={},b[4]={},A=0,B=0;
  for(int i=0; i<4; i++) {
      cin >> a[i];
      A+=a[i];
  }
  for(int i=0; i<4; i++) {
      cin >> b[i];
      B+=b[i];
  }
  cout << max(A,B) << endl;
}


Measured memory_bytes: 3084
//25
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

int dfs(vector<int> l){
  int p=l.size();
  for(int i=0;i<l.size();i++){
    for(int j=0;j<4;j++){
      int dx[]={1,-1,0,1};
      int dy[]={0,1,1,1};
      int nx=i%4+dx[j];
      int ny=i/4+dy[j];
      if(ny*4+nx<l.size()&&0<=nx&&nx<4&&l[i]==l[ny*4+nx]){
	vector<int> n=l;
	n.erase(n.begin()+ny*4+nx);
	n.erase(n.begin()+i);
	p=min(p,dfs(n));
	if(p==0)return 0;
      }
    }
  }
  return p;
}

int main(){
  int n;
  cin>>n;
  while(n--){
    vector<int> l(20);
    for(int i=0;i<20;i++){
      cin>>l[i];
    }
    cout<<dfs(l)<<endl;
  }
  return 0;
}

Measured memory_bytes: 1216
m=(""+require("fs").readFileSync(0)).split`
`;n=m[a=0];s=m[1];for(b=1<<n;b--;m[u]=-~m[u])for(u=[i=n];i--;)u[(b>>i)&1]+=s[i];for(b=1<<n;b--;a+=~~m[u])for(u=[i=n];i--;)u[(b>>i)&1]+=s[2*n+~i];console.log(a)

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

bool digitSame(int n)
{
  bool same = false;
  int a, b, c;
  a = n % 10;
  n /= 10;
  b = n % 10;
  n /= 10;
  c = n % 10;
  if (a == b and b == c)
    same = true;
  return same;
}

int main()
{
  int N;
  cin >> N;
  int ans = 0;
  for (int i = N; i < 2000; i++)
  {
    if (digitSame(i))
    {
      ans = i;
      break;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <map>
#define MAXN (200000 + 5)
#define INF (0x7ffffff)
#define LS(dq) ((dq) << 1)
#define RS(dq) (((dq) << 1) | 1)
#define LL long long
#define pii pair<int, int>
using namespace std;
int n, a[MAXN];
LL fr[MAXN], ans;
map<LL, int> qwq;
int main()
{
    scanf("%d", &n);
    for (int i = 1; i <= n; i++)
		scanf("%d", &a[i]), fr[i] = fr[i - 1] + a[i];
	qwq[0] = 1;
    for (int i = 1; i <= n; i++)
	{
		if (!qwq.empty() && qwq.find(fr[i]) != qwq.end())
			ans += qwq[fr[i]];
		if (qwq.find(fr[i]) == qwq.end())
			qwq[fr[i]] = 1;
		else
			++qwq[fr[i]];
	}
	printf("%lld", ans);
    return 0;
}


Measured memory_bytes: 15104
#include <stdio.h>

typedef struct {
    int state[2][7];
    int assign[7];
    int p; // 次に代入すべきインデックス
} dice;

int rot[6][7] = {
    {0,1,2,3,4,5,6},
    {0,2,6,3,4,1,5},
    {0,4,2,1,6,5,3},
    {0,3,2,6,1,5,4},
    {0,5,1,3,4,6,2},
    {0,1,3,5,2,4,6},
};
int tr['Z'];
char str[6] = "NEEEN";

void dice_init(dice *d, int *a) {
    int i;
    int t[6] = {0, 'N', 'E', 'W', 'S', 'L'};
    for (i = 1; i <= 6; i++) d->assign[i] = a[i];
    for (i = 1; i <= 5; i++) tr[t[i]] = i;
    for (i = 1; i <= 6; i++) d->state[0][i] = rot[0][i];
    d->p = 1;
}

int get_d_num(dice *d, int i) {
    return d->assign[d->state[!(d->p)][i]];
}

void dice_rotate(dice *d, char dir) {
    int i;
    for (i = 1; i <= 6; i++) {
        d->state[d->p][i] = d->state[!(d->p)][rot[tr[dir]][i]];
    }
    d->p = !(d->p);
}

void set_top(dice *d, int t) {
    char s[] = "NEEEN";
    char *ps = s;
    while (*ps) {
        if (get_d_num(d, 1) == t) return;
        dice_rotate(d, *ps);
        ps++;
    }
}

void set_front(dice *d, int f) {
    while (get_d_num(d, 2) != f) dice_rotate(d, 'L');
}

int sub_equals(dice *d1, dice *d2) {
    int i;
    for (i = 1; i <= 6; i++) {
        if (get_d_num(d1, i) != get_d_num(d2, i)) return 0;
    }
    return 1;
}

int dice_equals(dice *d1, dice *d2) {
    int i, j;
    char *p = str;
    for (i = 1; i<= 6; i++) {
        for (j = 1; j <= 4; j++) {
            if (sub_equals(d1, d2)) {
                return 1;
            }
            dice_rotate(d2, 'L');
        }
        dice_rotate(d2, *p);
        p++;
    }
    return 0;
}

dice d[100];
int a[100][7];
int main(void) {
    int n, i, j;
    scanf("%d", &n);
    for (i = 0; i < n; i++) {
        for (j = 1; j <= 6; j++) scanf("%d", a[i] + j);
        dice_init(d + i, a[i]);
    }
    for (i = 0; i < n; i++) {
        for (j = i + 1; j < n; j++) {
            if (dice_equals(d + i, d + j)) {
                printf("No\n");
                return 0;
            }
        }
    }
    printf("Yes\n");
    return 0;
}



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

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int h, w;cin>>h>>w;
	string s[h];
	for(int i = 0; i < h;++i) cin>>s[i];
	int L[h][w], R[h][w], D[h][w], U[h][w];
	for(int i = 0; i < h; ++i){
		for(int j = 0; j < w;++j){
			if(s[i][j]=='#'){
				L[i][j] = 0;
				R[i][j] = 0;
				D[i][j] = 0;
				U[i][j] = 0;
			}
			else{
				if(j==0){
					L[i][j] = 1;
				} else{
					L[i][j] = L[i][j-1] + 1;
				}
				if(i==0){
					U[i][j] = 1;
				} else{
					U[i][j] = U[i-1][j] + 1;
				}
			}
		}
	}
	for(int i = h - 1; i >=0;--i){
		for(int j = w - 1; j>=0; --j){
			if(s[i][j]=='.'){
				if(j==w-1){
					R[i][j] = 1;
				} else{
					R[i][j] = R[i][j + 1] + 1;
				}
				if(i==h-1){
					D[i][j] = 1;
				} else{
					D[i][j] = D[i+1][j] + 1;
				}
			}
		}
	}
	int mx = 0;
	for(int i =0; i < h;++i){
		for(int j = 0; j < w; ++j){
			mx = max(mx, L[i][j] + R[i][j] + U[i][j] + D[i][j]);
		}
	}
	cout<<mx - 3<<endl;
	return 0;
}
//21398

Measured memory_bytes: 67072
// Problem : D - Replacing
// Contest : AtCoder - AtCoder Beginner Contest 171
// URL : https://atcoder.jp/contests/abc171/tasks/abc171_d
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
#define int long long
#define sz(a) int((a).size())
#define pb push_back
#define mp make_pair
#define db1(x) cout<<#x<<"="<<x<<endl
#define db2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<endl
#define db3(x,y,z) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<endl
#define rep(i,a,b) for(int i = a; i <= b; i++)
#define rep2(i,a,b) for(int i = a; i >= b; i--)
#define die return 0;

using namespace std;

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

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

int testcases;
testcases=1;
//cin>>testcases;

while(testcases--)
{
	int n;
	cin>>n;
	vector<int> vec(n);
	unordered_map<int,int> cnt;
	int sum=0;
	rep(i,0,n-1)
		{
			cin>>vec[i];
			cnt[vec[i]]++;
			sum+=vec[i];
		}
	int q;
	cin>>q;
	while(q--)
	{
		int b,c;
		cin>>b>>c;
		sum+=(c-b)*cnt[b];
		cout<<sum<<'\n';
		cnt[c]+=cnt[b];
		cnt[b]=0;
	}	
}

return 0;
}


Measured memory_bytes: 7796
n = int(input())
an = list(map(int,input().split()))
four = 0
odd = 0
for a in an:
    if a%4==0:
        four+=1
    if a%2!=0:
        odd+=1
if odd+four!=n:
    odd+=1
if four >= odd - 1:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 14252
// In the name of God

#include <bits/stdc++.h>

using namespace std;

const int mod = 1e9+7;

long long n, c[61], pw[61];

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	pw[0] = 1;
	for(int i=1;i<61;i++) pw[i] = (pw[i-1]*2)%mod;
	cin >> n;
	for(int i=0;i<n;i++) {
		long long x;
		cin >> x;
		for(int j=0;j<61;j++) {
			if((x>>j)&1)c[j]++;
		}
	}

	long long ans = 0;
	for(int i=0;i<61;i++) {
		ans += ( (n-c[i]) * ((c[i]*pw[i])%mod) )%mod;
		ans %= mod;
	}
	cout << ans;
	return 0;
}


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

int main(){
  int n;
  cin >> n;
  vector<vector<int>> vv(n, vector<int>(26, 0));
  for(int i=0;i<n;i++){
    string s;
    cin >> s;
    int len = s.length();
    for(int j=0;j<len;j++){
      vv[i][s[j]-'a']++;
    }
  }
  int flag=0;
  for(int i=0;i<26;i++){
    int mi=vv[0][i];
    for(int j=1;j<n;j++){
      mi = min(mi, vv[j][i]);
    }
    char x = i + 'a';
    for(int j=0;j<mi;j++){
      flag=1;
      cout << x;
    }
  }
  if (flag == 0){
    cout << "" << endl;
  }else{
    cout << endl;
  }
  return 0;
}

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

using namespace std;

int main(){

  while(1){
    int n,cnt=0,sum=0;
    cin >> n;
    if(n==0) break;
    for(int i=1;i<n;i++){
      for(int j=i;j<n;j++){
	sum+=j;
	if(sum > n) break;
	if(sum==n){
	  cnt++;
	  break;
	}
      }
      sum=0;
    }
    cout << cnt << endl;
  }
  return 0;
}

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

#define int long long

#define ii pair<int,int>
#define fi first
#define sc second

#define all(x) (x).begin(),(x).end()

signed main() {
#ifdef _DEBUG
  // freopen("in" , "r", stdin );
#endif
  ios::sync_with_stdio(0); cin.tie(0);
  int n, a, b;
  cin >> n >> a >> b;
  string s; cin >> s;
  int cnt = 0, flg = 0;
  for (int i = 0; i < n; i++) {
    if (s[i] == 'c') {
      cout << "No" << '\n';
    }
    if (s[i] == 'b') {
      flg++;
      if (cnt < a + b && flg <= b) {
        cout << "Yes" << '\n';
        cnt++;
      } else {
        cout << "No" << '\n';
      }
    }
    if (s[i] == 'a') {
      if (cnt < a + b) {
        cout << "Yes" << '\n';
        cnt++;
      } else {
        cout << "No" << '\n';
      }
    }
  }
}


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

using ll = long long;
#define int long long

// [a -> b-1]
#define reps(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
// [0 -> a-1]
#define rep(i, a) reps(i, 0, (a))
// [a-1 -> b]
#define rreps(i, a, b) for (int i = (int)((a)-1); i >= (int)(b); i--)
// [a-1 -> 0]
#define rrep(i, a) rreps(i, a, 0)
#define all(v) (v).begin(), (v).end()
// next_permutation(all(v))
#define PERM(v) next_permutation(all(v))
/*sort(all(v));
 * (v).erase(unique(all(v)), v.end())*/
#define UNIQUE(v)\
	sort(all(v));\
	(v).erase(unique(all(v)), v.end())
#define MINV(v) min_element(all(v))
#define MAXV(v) max_element(all(v))
#define MIN3(a, b, c) min(min(a, b), c)
#define MIN4(a, b, c, d) min(MIN3(a, b, c), d)
#define MIN5(a, b, c, d, e) min(MIN4(a, b, c, d), e)
#define MIN6(a, b, c, d, e, f) min(MIN5(a, b, c, d, e), f)
#define MAX3(a, b, c) max(max(a, b), c)
#define MAX4(a, b, c, d) max(MAX3(a, b, c), d)
#define MAX5(a, b, c, d, e) max(MAX4(a, b, c, d), e)
#define MAX6(a, b, c, d, e, f) max(MAX5(a, b, c, d, e), f)
// b is [a, c)
#define RANGE(a, b, c) ((a) <= (b) && (b) < (c))
// c is [a, e) && d is [b, f)
#define RANGE2D(a, b, c, d, e, f) (RANGE((a), (c), (e)) && RANGE((b), (d), (f)))
#define chmin(a, b) a = min(a, (b))
#define chmin3(a, b, c) a = MIN3(a, (b), (c))
#define chmin4(a, b, c, d) a = MIN4(a, (b), (c), (d))
#define chmin5(a, b, c, d, e) a = MIN5(a, (b), (c), (d), (e))
#define chmin6(a, b, c, d, e, f) a = MIN6(a, (b), (c), (d), (e), (f))
#define chmax(a, b) a = max(a, (b))
#define chmax3(a, b, c) a = MAX3(a, (b), (c))
#define chmax4(a, b, c, d) a = MAX4(a, (b), (c), (d))
#define chmax5(a, b, c, d, e) a = MAX5(a, (b), (c), (d), (e))
#define chmax6(a, b, c, d, e, f) a = MAX6(a, (b), (c), (d), (e), (f))
#define fcout cout << fixed << setprecision(15)
#define YES(f) cout << ((f) ? YES_STR : NO_STR) << endl;


void solve(long long N, std::vector<std::string> s) {
	rep(i, N) {
		sort(all(s[i]));
	}
	sort(all(s));
	int res = 0;
	int cnt = 1;
	reps(i,1, N) {
		if (s[i] == s[i-1]) {
			cnt++;
		} else {
			res += cnt * (cnt - 1) / 2;
			cnt = 1;
		}
	}
	res += cnt * (cnt - 1) / 2;
	cout << res << endl;
}

signed main() {
	long long N;
	scanf("%lld",&N);
	std::vector<std::string> s(N);
	for(int i = 0 ; i < N ; i++){
		std::cin >> s[i];
	}
	solve(N, std::move(s));
	return 0;
}


Measured memory_bytes: 7296
def ge(arr):
    for i in range(len(arr)):
        tmp = int(arr[i])
        if tmp >= 4:
            tmp += 1
        if tmp >= 6:
            tmp += 1
        arr[i] = str(tmp)
    return arr


while True:
    n = int(input())
    if n == 0:
        break
    print("".join(ge(list(oct(n))[2:])))



Measured memory_bytes: 5620
#include <stdio.h>

int main ()
{
	long long a, b, c, d;

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

	if (a >= 0 && b >= 0 && c >= 0 && d >= 0) printf ("%lld", b * d);

	if (a < 0 && b >= 0 && c < 0 && d >= 0) {
		if (a * c > b * d) printf ("%lld", a * c);
		else printf ("%lld", b * d);
	}

	if (a < 0 && b < 0 && c >= 0 && d >= 0) printf ("%lld", b * c);

	if (a >= 0 && b >= 0 && c < 0 && d < 0) printf ("%lld", a * d);

	if (a >= 0 && b >= 0 && c < 0 && d >= 0) printf ("%lld", b * d);

	if (a < 0 && b >= 0 && c >= 0 && d >= 0) printf ("%lld", b * d);

	if (a < 0 && b < 0 && c < 0 && d < 0) printf ("%lld", a * c);

	if (a < 0 && b >= 0 && c < 0 && d < 0) printf ("%lld", a * c);

	if (a < 0 && b < 0 && c < 0 && d >= 0) printf ("%lld", a * c);

	return 0;
}


Measured memory_bytes: 2112
n, a = map(int, input().split())
x = list(map(int, input().split()))

dp = [[[0] * (50 * (n + 10)) for _ in range(n + 10)] for _ in range(n + 10)]
dp[0][0][0] = 1

for i in range(n):
    for use in range(n):
        for total in range(n * a):
            if dp[i][use][total]:
                dp[i + 1][use][total] += dp[i][use][total]
                dp[i + 1][use + 1][total + x[i]] += dp[i][use][total]

ans = 0
for i in range(1, n + 1):
    ans += dp[n][i][a * i]

print(ans)


Measured memory_bytes: 96628
package main

import (
	"fmt"
	"os"
	"strings"
)
func main() {
	var n int
	fmt.Scan(&n)

	var old string
	list := make(map[string]bool)
	i := 0
	for i < n{
		var temp string
		fmt.Scan(&temp)


		if !list[temp]{
			list[temp] = true
		}else{
			fmt.Println("No")
			os.Exit(0)
		}
		if i == 0{
			old = temp
			i++
			continue
		}

		if old[len(old) - 1:] != strings.Split(temp,"")[0]{
			fmt.Println("No")
			os.Exit(0)
		}
		old = temp
		i++
	}
	fmt.Println("Yes")
}


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

int main(){
  int n,tmp,count=1;
  cin >> n;
  vector<int> vec(n);
  
  for(int i=0; i<n; i++){
    cin >> vec.at(i);
  }
  
  for(int i=0; i<n; i++){
    for(int j=i+1; j<n; j++){
      if(vec.at(i) < vec.at(j)){
		tmp = vec.at(i);
        vec.at(i) = vec.at(j);
        vec.at(j) = tmp;
      }
    }
  }
  
  for(int i=0; i<n-1; i++){
    if(vec.at(i) != vec.at(i+1)){
      count++;
    }
  }
  
  cout << count << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define REPr(i,n) for(int i=(n)-1;i>=0; --i)
#define FORq(i, m, n) for(int i = (m);i <= (n);++i)
#define rFORq(i, m , n) for(int i = (n);i >=(m);--i)
#define SCD(n) scanf("%d",&n)
#define SCD2(m,n) scanf("%d%d",&m,&n)
#define SCD3(m,n,k) scanf("%d%d%d",&m,&n,&k)
#define SCLLD(n) scanf("%lld",&n)
#define SCLLD2(m,n) scanf("%lld%lld",&m,&n)
#define SCLLD3(m,n,k) scanf("%lld%lld%lld",&m,&n,&k)
#define PB push_back
#define MP make_pair
#define ARSCD(A,N) REP(i,N){SCD(A[i]);}
#define ARSCD1(A,N) FORq(i,1,N){SCD(A[i]);}
#define VSCD(v,N) REP(i,N){int x; SCD(x); v.PB(x);}
#define VSCLLD(v,N) REP(i,N){long long x; SCLLD(x); v.PB(x);}
#define PRINTD(n) printf("%d\n",n)
#define PRINTLLD(n) printf("%lld\n",n)
#define DEBUG printf("%s\n","debug")
#define fst first
#define snd second
#define SIN(x,S) (S.count(x) != 0)
using namespace std;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector < VI > VVI;
typedef vector<long long> VL;
typedef long long ll;
typedef long long integer;
////////////////////////////////////////////////////////////////////
int main(){
    string s;
    cin >> s;

    int l = s.length();
    bool ans;
    bool chk;
    if (s[0] == s[l-1]) chk = true;
    else chk = false;

    if (l % 2 == 0){ //even
        if (chk) ans = true;
        else ans = false;
    }else{
        if (chk) ans = false;
        else ans = true;
    }

    if (ans) printf("First\n");
    else printf("Second\n");
}

Measured memory_bytes: 512
#include  <stdio.h>
int mi(int a,int b)
{
    if(a>b) return a-b;
    return b-a;
}
int main ()
{
    int a,b,w;
    scanf("%d %d %d",&w,&a,&b);
    a=mi(a,b);
    if(a<=w) printf("0\n");
    else printf("%d\n",a-w);
    return 0;
}


Measured memory_bytes: 128
#include<stdio.h>

#define N 8
#define FREE -1
#define NOTFREE 1

int row[N],col[N],dpos[2 * N - 1],dneg[2 * N - 1];

int X[N][N];

void printBoard()
{
    int i,j;

    for(i=0;i<N;i++)
    {
        for(j=0;j<N;j++)
        {
            if(X[i][j])
            {
                if(row[i] != j) return;
            }
        }
    }

    for(i=0;i<N;i++)
    {
        for(j=0;j<N;j++)
        {
            if(row[i] == j)printf("Q");
            else printf(".");
        }
       printf("\n");
    }
}

void recursive(int i)
{
    int j;

    if(i == N)
    {
        printBoard(); return;
    }

    for(j=0;j<N;j++)
    {
        if(NOTFREE == col[j] || 
           NOTFREE == dpos[i + j] ||
           NOTFREE == dneg[i-j + N-1]) continue;

       row[i] = j;
       col[j] = dpos[i+j] = dneg[i-j + N-1] = NOTFREE;

       recursive(i+1);

       row[i] = col[j] = dpos[i+j] = dneg[i-j + N-1] = FREE;
    }
}

int main()
{
    int i,j,k,r,c;
    
    for(i=0;i<N;i++)
    {
        row[i] = FREE;
        col[i] = FREE;
    }
    for(i=0;i<2*N-1;i++)
    {
        dpos[i] = FREE;
        dneg[i] = FREE;
    }

    for(i=0;i<N;i++)
    {
        for(j=0;j<N;j++)
        {
            X[i][j] = 0;
        }
    }

    scanf("%d",&k);
    for(i=0;i<k;i++)
    {
        scanf("%d%d",&r,&c);
        X[r][c] = 1;
    }

    recursive(0);

    return 0;

}


Measured memory_bytes: 2132
#include <iostream>
//#include <iomanip>
//#include <string>
#include <vector>
#include <algorithm>
//#include <utility>
//#include <set>
//#include <map>
#include <queue>
//#include <deque>
//#include <bitset>
//#include <math.h>
using namespace std ;
using ll = long long ;
//using ld = long double ;
using vll = vector<ll> ;
using vvll = vector<vll> ;
//using vc = vector<char> ;
//using vvc = vector<vc> ;
//using vb = vector<bool> ;
//using vvb = vector<vb> ;
//using pll = pair<ll,ll> ;
//#define all(v) v.begin(),v.end()
//ll mod = 1000000007 ;
//long double pie = acos(-1) ;
//ll INF = 1000000000000 ;

//void yorn(bool a){if(a) cout << "Yes" << endl ; else cout << "No" << endl ;}
//void YorN(bool a){if(a) cout << "YES" << endl ; else cout << "NO" << endl ;}
//ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
//ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
//ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;}
//void fix_cout(){cout << fixed << setprecision(20) ;}

int main(){
	ll n ; cin >> n ;
	vvll g(n,vll(n)) ;
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			char c ; cin >> c ;
			g.at(i).at(j) = (c=='1') ;
		}
	}
	vll ok(n,-1) ;
	queue<int> q ;
	q.push(0) ;
	ok.at(0) = 0 ;
	bool flag = true ;
	while(!q.empty()){
		int p = q.front() ;
		q.pop() ;
		int c = 1-ok.at(p) ;
		for(int i=0;i<n;i++){
			if(g.at(p).at(i)==0) continue ;
			if(ok.at(i)==-1){
				ok.at(i) = c ;
				q.push(i) ;
			}else if(ok.at(i)!=c) flag = false ;
		}
	}
	if(!flag) cout << -1 << endl ;
	else{
		ll ans = 0 ;
		for(int i=0;i<n;i++){
			vll d(n,-1) ;
			d.at(i) = 0 ;
			q.push(i) ;
			while(!q.empty()){
				int p = q.front() ;
				q.pop() ;
				int sub = d.at(p)+1 ;
				for(int j=0;j<n;j++){
					if(g.at(p).at(j)==0) continue ;
					if(d.at(j)==-1){
						d.at(j) = sub ;
						q.push(j) ;
					}
				}
			}
			for(int j=0;j<n;j++) ans = max(ans,d.at(j)) ;
		}
		cout << ans+1 << endl ;
	}
}


Measured memory_bytes: 3968
#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>;

int main() {
  int N,P=0,W=0,G=0,Y=0;
  cin >> N;
  string s;
  int a = 0;

  for(int i = 0; i < N; i++){
    cin >> s;
    if(s == "P"){
      P = 1;
    }else if(s == "W"){
      W = 1;
    }else if(s == "G"){
      G = 1;
    }else if(s == "Y"){
      Y = 1;
    }
  }
  a = P + W + G + Y;
  if(a == 3){
    cout << "Three" << endl;
  }else{
    cout << "Four" << endl;
  }

}




Measured memory_bytes: 3640
#include <stdio.h>
int range;
int num;
int sum;
int ans;
void f(int n,int k,int s){
	int i;
	if(k==num){
		ans+=(s==sum);
		return ;
	}
	if(n>range){
		return ;
	}
	for(i=n;i<=range;i++){
		f(i+1,k+1,s+i);
	}
}
int main(void){
	while(1){
		scanf("%d %d %d",&range,&num,&sum);
		if(range==0){
			break;
		}
		ans=0;
		f(1,0,0);
		printf("%d\n",ans);
	}
	return 0;
}

Measured memory_bytes: 600
#include<bits/stdc++.h>
using namespace std;
int main(){
int n,t;
  cin>>n>>t;
  vector<string> st;
  while(n--){
    string s;
    cin>>s;
  st.push_back(s);
  }
  sort(st.begin(),st.end());
  for(int i=0;i<st.size();i++){
  cout<<st[i];
  }
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define fi first
#define se second
#define ll long long
#define dbg(v) cerr<<#v<<" = "<<v<<'\n'
#define vi vector<int>
#define vl vector <ll>
#define pii pair<int,int>
#define mp make_pair
#define db long double
#define pb push_back
#define all(s) s.begin(),s.end()
template < class T > T smin(T &a,T b) {if (a > b) a = b;return a;}
template < class T > T smax(T &a,T b) {if (a < b) a = b;return a;}
const int N = (int)(1e6) + 5;
vi g[N];
int deg[N];
int dfs(int node,int prev)
{
    int ans = 0;
    int cnt = 0;
    for (auto it : g[node])
    if (it != prev)
    {
        const int now = dfs(it,node);
        if (!now)
        {
            if (cnt)
                ++ans;
            else
                cnt = 1;
        }
        ans += now;
    }
    return ans;
}
int main(void)
{
    int n;
    cin>>n;
    for (int i = 1;i < n;++i)
    {
        int a,b;
        cin>>a>>b;
        ++a;++b;
        g[a].pb(b);
        g[b].pb(a);
        ++deg[a];
        ++deg[b];
    }
    queue < int > q;
    for (int i = 1;i <= n;++i)
        if (deg[i] == 1)
            q.push(i);
    int ans = 0;
    vi vertices;
    while (!q.empty())
    {
        int node = q.front();
        q.pop();
        vertices.pb(node);
        deg[node] = 0;
        for (auto it : g[node])
            if (deg[it])
            {
                --deg[it];
                if (deg[it] == 1)
                    q.push(it);
            }
    }
    reverse(all(vertices));
    vertices.resize(2);
    cout << max({1,dfs(vertices[0],0),dfs(vertices[1],0)}) << '\n';
    return 0;
}


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

using namespace std;
typedef long long ll;
typedef string str;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector <pii> vpii;
typedef vector <pll> vpll;
typedef map <str,int> mapsi;
typedef map <str,int> :: iterator mapsitr;
typedef map <int , int> mint;
typedef map <ll , ll> mll;
typedef set <int> si;
typedef set <ll> sll;
typedef si :: iterator sitr;
typedef si :: reverse_iterator rsitr;
typedef sll :: iterator sltr;
typedef sll :: reverse_iterator rsltr;
#define mset multiset

typedef mset <int> msi;
typedef mset <ll> msll;
typedef msi :: iterator msitr;
typedef msi :: reverse_iterator msritr;
typedef msll :: iterator msltr;
typedef msll :: reverse_iterator mslritr;

#define mp make_pair
#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define fi first
#define se second
#define fs first.second
#define ss second.second
#define ff first.first
#define sf second.first
#define newl '\n'

char to_upper (char x){
    if( 97 <= int(x) && int(x) <= 126)return char(x-32);
    else if( 65 <= int(x) && int(x) <= 90)return x;
}
char to_lower (char x){
    if( 97 <= int(x) && int(x) <= 126)return x;
    else if( 65 <= int(x) && int(x) <= 90)return char(x+32);
}
int numerize (char x){
    if(48 <= int(x) && int(x) <= 57)return int(x-'0');
    else if( 97 <= int(x) && int(x) <= 126)return int(x-96);
    else if( 65 <= int(x) && int(x) <= 90)return int(x-64);
}
// end of Template

int mn = 1e8;
int n,a[300];
int main(){

//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        int f = 0;
        while(a[i]%2==0){
            f++;
            a[i]/=2;
        }
        mn = min(f,mn);
    }
    cout<<mn<<newl;

}


Measured memory_bytes: 256
#pragma region template 1.0
#pragma region def
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vi;
typedef pair<ll, ll> ii;
#define REP(i, n) for (ll i = 0; i < (n); ++i)
#define REP1(i, n) for (ll i = 1; i <= (n); ++i)
#define OUT(x) cout << (x) << endl;
#define OUTA(a) \
    REP(i, (a).size()) { cout << (a[i]) << (i == (a).size() - 1 ? "\n" : " "); }
#define ALL(a) (a).begin(), (a).end()
#define SORT(a) sort(ALL(a))
#define RSORT(a) \
    SORT(a);     \
    reverse(ALL(a))

const ll INF = 1e18;
const ll MOD = 1e9 + 7;
#pragma endregion enddef

int main()
{
    ll N;
    cin >> N;
    vi a(N);
    REP(i, N)
    {
        cin >> a[i];
    }

    vector<vi> dp(N + 1, vi(N + 1));
    REP1(i, N)
    {
        REP1(j, i)
        {
            if ((N - j) & 1)
            {
                dp[i][j] = min(dp[i - 1][j - 1] - a[i - 1], dp[i][j - 1] - a[i - j]);
            }
            else
            {
                dp[i][j] = max(dp[i - 1][j - 1] + a[i - 1], dp[i][j - 1] + a[i - j]);
            }
        }
    }
    ll ans = dp[N][N];
    OUT(ans);
}
#pragma endregion template

Measured memory_bytes: 70784
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<numeric>
#include<algorithm>

using namespace std;

int main() {
  cin.tie(0);

  int time[5][2];
  int keep[5];

  for(int i = 0; i < 5; i++){
    cin >> time[i][0];
    if(time[i][0]%10 != 0){
      time[i][1] = 10 - time[i][0]%10;
    }else time[i][1]=0;
  }

  for(int i = 0 ; i < 5 ; i++){
    for(int j = 4 ; j > i ; j--){
      if(time[j][1] < time[j-1][1]){
          swap(time[j][1],time[j-1][1]);
      }
    }
  }

  int ans = 0;
  for(int  i =  0; i < 5; i++ ){
    ans += time[i][0];
    if(i!=4)ans += time[i][1];
  }

  cout << ans <<endl;
  return 0;

  }


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

Measured memory_bytes: 4792
N, M, K = map(int, input().split())
"""
N=3, M=5

xxxxx
xxxxx
xxxxx
"""

def check(KS):
  for i in range(N+1):
    # (i * M) + (j * (N-2i)) == K のjが存在する。0,Mの整数として。
    # 全探索よりもjを整数として求めて頑張ればオーダN
    if N == 2*i:
      if i*M == KS:
        print("Yes")
        exit(0)
      else:
        continue
    if (KS - i*M) % (N-2*i) == 0 :
      sho = (KS - i*M) // (N-2*i)
      if 0 <= sho and sho <= M:
        print('Yes')
        exit(0)

check(K)
#N,M = M,N
#check(K)

print('No')

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

using namespace std;

#define sqr(x) ((x) * (x))
#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define fin(name) freopen(name, "r", stdin)
#define fout(name) freopen(name, "w", stdout)
#define I(x, a) for(auto x : a)
#define F(i, l, r) for(auto i = l; i < r; ++i)
#define E(i, l, r) for(auto i = l; i <= r; ++i)
#define DF(i, l, r) for(auto i = l; i >= r; --i)
#define clean(a) memset((a),0,sizeof (a))
#define sync ios_base::sync_with_stdio(0);cin.tie(0)
#define all(x) (x).begin(),(x).end()
#define ret return
#define cont continue
#define brk break
#define ins insert
#define sz(a) ((int)(a).size())

typedef long long ll;
typedef unsigned long long ull;
typedef long double dbl;
typedef pair <int, int> pii;

const int inf = (int)1e9;
const ll linf = (ll)1e18;
const int mod = (int)1e9 + 7;
const dbl eps = (dbl)1e-8;
const int maxn = (int)1e5 + 5;
const dbl pi = acos(-1);

void add(ll a, ll& b) {
	b += a;
	if (b >= mod)
		b -= mod;
}

ll pw(ll x, ll y) {
	if (y == 0)
		return 1;
	if (y & 1)
		return pw(x, y - 1) * x % mod;
	x = pw(x, y / 2);
	return x * x % mod;
}

ll d[105][105];
int n, h[105], sh[105], pos[105];

int main() {
//	fin("t.in");
	sync;
	cin >> n;
	E(i, 1, n) {
		cin >> h[i];
//		h[i] = 100 * i;
		sh[i] = h[i];
	}
	sh[0] = h[0] = 1;
	sort(sh, sh + n + 1);
	E(i, 0, n) {
		pos[i] = 0;
		while (sh[pos[i]] < h[i])
			++pos[i];
	}

	clean(d);
	d[0][0] = 1;
	F(i, 0, n) {
		E(j, 0, n) {
			if (d[i][j] == 0)
				cont;
			if (h[i + 1] <= h[i]) {
				if (j < pos[i + 1])
					add(d[i][j], d[i + 1][j]);
				else
					add(2ll * d[i][j] % mod, d[i + 1][pos[i + 1]]);
			} else {
				if (j < pos[i]) {
					add(pw(2, h[i + 1] - h[i]) * d[i][j] % mod, d[i + 1][j]);
				} else {
					F(k, j, pos[i + 1]) {
						ll x = 2ll * (pw(2, h[i + 1] - sh[k]) - pw(2, h[i + 1] - sh[k + 1])) * d[i][j];
						x %= mod;
						x += mod;
						x %= mod;
						add(x, d[i + 1][k]);
					}
					add(2ll * d[i][j] % mod, d[i + 1][pos[i + 1]]);
				}
			}
		}

	}


	ll ans = 0;
	E(i, 0, n) {
//		cout << i << " " << d[2][i] << endl;
		add(d[n][i], ans);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 384
package main

import "fmt"

func main() {
	var N int
	fmt.Scanf("%d", &N)
	count := 0
	for i := 1; i <= N; i++ {
		if 1 <= i && i < 10 || 100 <= i && i < 1000 || 10000 <= i && i < 100000 {
			count++
		}
	}
	fmt.Println(count)
}


Measured memory_bytes: 512
def f(L,X=[]):
    if L==1:
        return ["3","5","7"]
    else:
        X=f(L-1)
        Y=[]
        for x in X:
            Y+=[x+"3",x+"5",x+"7"]
        return Y
    
N=int(input())
G=[]
for k in range(1,10):
    V=f(k)
    
    for v in V:
        if ("3" in v) and ("5" in v) and ("7" in v):
            G.append(int(v))

T=0
for x in G:
    if x<=N:
        T+=1

print(T)


Measured memory_bytes: 5876