akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <stdio.h>
#include <time.h>
#include <numeric>
#include <random>
#include <unordered_map>
#include <unordered_set>
#define all(a) a.begin(),a.end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define pb push_back
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> P;
typedef complex<ld> com;
constexpr int inf = 1000010;
constexpr ll INF = 1000000000000000010;
constexpr ld eps = 1e-12;
constexpr ld pi = 3.141592653589793238;
template<class T, class U> inline bool chmax(T &a, const U &b) { if (a < b) { a = b; return true; } return false; }
template<class T, class U> inline bool chmin(T &a, const U &b) { if (a > b) { a = b; return true; } return false; }

vector<vector<int>> graph(2010, vector<int>());
vector<int> dis(2010);
string s;

void dfs1(int n, int p, int d) {
	dis[n] = d;
	for (int i : graph[n]) {
		if (i == p) continue;
		dfs1(i, n, d + 1);
	}
}

vector<int> dp(2010), cnt(2010), sum(2010);

void dfs2(int n, int p) {
	for (int i : graph[n]) {
		if (i == p) continue;
		dfs2(i, n);
		cnt[n] += cnt[i];
		sum[n] += sum[i] + cnt[i];
	}
	if (s[n] == '1') cnt[n]++;
}

int dfs3(int n, int p) {
	int m = 0; int su = 0; int idx = -1;
	for (int i : graph[n]) {
		if (i == p) continue;
		if (chmax(m, sum[i] + cnt[i])) idx = i;
		su += sum[i] + cnt[i];
	}
	//if (n == 2) cerr << su << ' ' << m << '\n';
	if (m <= su / 2) dp[n] = su / 2;
	else dp[n] = min(su / 2, dfs3(idx, n) + su - sum[idx] - cnt[idx]);
	return dp[n];
}

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

	int n;
	cin >> n >> s;
	rep(i, n - 1) {
		int u, v;
		cin >> u >> v;
		u--; v--;
		graph[u].pb(v);
		graph[v].pb(u);
	}
	int ans = inf;
	rep(i, n) {
		dfs1(i, -1, 0);
		dfs2(i, -1);
		int tmp = dfs3(i, -1);
		if (!(sum[i] & 1) && tmp == sum[i] / 2) chmin(ans, tmp);
		rep(j, n) cnt[j] = sum[j] = 0;
	}
	cout << (ans == inf ? -1 : ans) << '\n';
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
const int N=100010;
int n,a[N],b[N],ca[N],cb[N],p[N],ans;
map<int,int> mp;
bool vis[N];
int find(int x)
{
	while(p[x]!=x)
	{
		p[x]=p[p[x]];
		x=p[x];
	}
	return x;
}
int main()
{
	ans=0;
	memset(vis,0,sizeof(vis));
	scanf("%d",&n);
	a[n]=b[n]=0;
	int ind=1;
	for(int i=0;i<N;i++)
	{
		p[i]=i;
	}
	for(int i=0;i<n;i++)
	{
		scanf("%d",a+i);
		mp[a[i]];
		a[n]^=a[i];
		ca[i]=a[i];
	}
	for(int i=0;i<n;i++)
	{
		scanf("%d",b+i);
		mp[b[i]];
		b[n]^=b[i];
		cb[i]=b[i];
	}
	cb[n]=b[n];
	ca[n]=a[n];
	mp[a[n]];
	mp[b[n]];
	sort(ca,ca+n+1);
	sort(cb,cb+n+1);
	for(int i=0;i<n+1;i++)
	{
		if(ca[i]!=cb[i])
		{
			printf("-1");
			return 0;
		}
	}
	for( auto& it : mp)
	{
		it.second=ind++;
	}
	for(int i=0;i<n+1;i++)
	{
		a[i]=mp[a[i]];
		b[i]=mp[b[i]];
	}
	for(int i=0;i<n;i++)
	{
		if(a[i]!=b[i])
		{
			ans++;
			int x=find(a[i]);
			int y=find(b[i]);
			if(x!=y)
			{
				p[x]=y;
			}
		}
	}
	int x=find(a[n]);
	int y=find(a[n]);
	if(x!=y)
	p[x]=y;
	for(int i=0;i<n+1;i++)
	{
		if(a[i]!=b[i]||i==n)
		{
			if(!vis[find(a[i])])
			{
				ans++;
				vis[find(a[i])]=1;
			}
		}
	}
	ans--;
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 7040
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <queue>

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

using namespace std;

int main(){
    int n,k; cin >> n >> k;
    string s; cin >> s;
    int diff = 'A' - 'a';
    s[k-1] = s[k-1] - diff;
    cout << s<< endl;
}



Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
  int a,b,c,d,i;
  cin >> a >> b >> c;
  d = 0;
  for (i = b; i >= a; i--) {
    if(c%i == 0){
      d = d+1;
    }
    /* code */
  }

  cout << d << '\n';

  return 0;
}

Measured memory_bytes: 3076
#include<iostream>
#include<string>
#include<vector>
#include<sstream>
using namespace std;
template < typename T > string to_string( const T& n ){
    {
        ostringstream oss ;
        oss << n ;
        return oss.str() ;
    }
}
int main(){
    int n;
    vector<string> a(5);
    for(int i = 0; i < 5;i++){
        a[i] = "";
    }
    int k = 0;
    while(1){
        cin >> n;
        if(n == 0)break;
        string s;
        string f = "";
        cin >> s;
        for(int i = 0;i < n;i++){
            int size = s.size();
            //cout << s << " *" <<endl;
            for(int j = 0;j < size;j++){
                int l = 1;
                while(1){
                    if(s[j] == s[j+l] && j + l < size){
                        l++;
                    }
                    else {
                        j += l - 1;
                        string b = to_string(l);
                        f += b;
                        f += s[j];
                        
                        break;
                    }
                }
            }
            s = f;
            //cout << k << " " << i << " " << s << endl; 
            f = "";
        }
        a[k] = s;
        k++;
    }
    for(int i = 0;i < k;i++){
        cout << a[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 3280
n = int(input())
dg = input().split(' ')
dg.append(0)
dg  = [0] + dg
sum_0 = sum([abs(int(dg[x]) - int(dg[x+1])) for x in range(len(dg)-1)])
for i in range(1, len(dg)-1):
    
    print(sum_0 - abs((abs(int(dg[i-1])-int(dg[i+1])) - (abs(int(dg[i-1])-int(dg[i])) + abs(int(dg[i])-int(dg[i+1]))))))

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

int main() {
    string S;
    cin >> S;
    cout << ( 
    	S[0] == S[1] 
    	|| S[1] == S[2] 
    	|| S[2] == S[3] 
    	? "Bad" : "Good") << endl;
}

Measured memory_bytes: 256
n,k = map(int, input().split())

lose=0
ans=0
for i in range(1,n+1):
    if i>=k:
        lose=0
        lose+=n
        ans+=float(1/lose)

    elif i<k:
        lose=0
        count=n
        while i<k:
            count*=2
            i*=2
        lose+=count
        ans+=float(1/lose)

print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <fstream>
#include <cstring>
#include <stdio.h>
#include <algorithm>
#include <sstream>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <cstdlib>
#include <cmath>

typedef long long ll;

#define reps(i, s, e) for (ll i = s; i < e; ++i)
#define rep(i, n) reps(i, 0, n)
#define rreps(i, s, e) for (ll i = e-1; i >= s; --i)
#define rrep(i, n) rreps(i, 0, n)

// const ll LL_INF = 1LL<<60;

template <class T> inline void chmin(T& a, T b) {if (a > b) {a = b;}}
template <class T> inline void chmax(T& a, T b) {if (a < b) {a = b;}}

using namespace std;

int n, q;
ll S[100000];

int main() {
    cin >> n;
    int num = 0;
    rep(i, n) {
        ll x;
        cin >> x;
        if (num == 0 || x != S[num-1]) S[num++] = x;
    }

    int cnt = 0;
    cin >> q;
    rep(i, q) {
        ll x;
        cin >> x;
        int left = 0, right = num;
        while(left < right) {
            int mid = (left + right)/2;
            if(S[mid] > x) right = mid;
            else if(S[mid] < x) left = mid+1;
            else {cnt++; break;}
        }
    }
    cout << cnt << endl;
}


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

int main(){
    int n;
    cin >> n;
    double v[n];
    for(int i=0;i<n;i++){
        cin >> v[i];
    }
//    sort(v,v+n,greater<int>());
//    for(int i=0;i<n;i++) cout<<v[i]<<" ";
    while(n!=1){
        sort(v,v+n,greater<int>());
//        for(int i=0;i<n;i++) cout<<v[i]<<" ";
        n-=1;
        v[n-1]=(v[n]+v[n-1])/2;
    }
    cout << v[0];
}




Measured memory_bytes: 888
/**
 *  author:   TakeruOkuyama
 *  created:  2020-04-09 14:53:46
**/
#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>;

const int MOD = 1000000007;

int main(){
    string N;
    cin >> N;
    rep(i, 3){
        if(N[i] == '7'){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
return 0;}

/**
 * g++ code.cpp
 * ./a.out
 * shift + ctrl + i
**/ 


Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define INF 2 << 29
#define MOD 1000000007
#define Yes(f) puts((f)? "Yes" : "No")
#define YES(f) puts((f)? "YES" : "NO")
int gcd(int a, int b) {
	if (b != 0)return gcd(b, a % b);
	return a;
}
int lcm(int a, int b) {
	return a / gcd(a, b) * b;
}
using Graph = vector<vector<int>>;

int main(){
	int n, s, m = INF, sum = 0;
	cin >> n;
	rep(i, n) {
		cin >> s;
		sum += s;
		if(s % 10 != 0) m = min(m, s);
	}
	if(sum % 10 != 0) cout << sum << endl;
	else if(m != INF) cout << sum - m << endl;
	else cout << 0 << endl;
}

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

int main() 
{
    int n;
    cin >> n;
    if (n==0)
    {
        cout << 0;
        return 0;
    }
    string str = "";
    while (n!=0)
    {
        int res = n % -2;
        n = n / -2;
        if (res < 0)
        {
            res = res + 2;
            n = n + 1;
        }
        str = to_string(res) + str;
    }
    cout << str;
    return 0;
}

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

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    ll sm = 0;    
    for(int i=0;i<n;i++){
        cin >> a[i];
        sm += a[i];
    }
    ll ans = MAX;
    ll tsm = 0;
    for(int i=0;i<n;i++){
        tsm += a[i];
        sm -=a[i];
        ans = min(ans,  abs(sm - tsm));
    }
    cout << ans << endl;
}

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

int main(){
  vector<string> a(4);
  a={"Sunny","Cloudy","Rainy","Sunny"};
  string s;
  cin >> s;
  
  for(int i=0;i<4;i++){
    if(s==a.at(i)){
      cout << a.at(i+1) << endl;
      break;
    }
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ldb = long double;
using pa = pair < ll, ll >;
using vec = vector < ll >;
#define pb push_back
#define po pop_back
#define mp make_pair
#define mt make_tuple
#define F  first
#define S  second
#define f(i,x,n) for(ll i=x;i<n;i++) 
#define unique_sort(x) sort(all(x)), x.resize(distance(x.begin(), unique(all(x))))
#define all(c) c.begin(),c.end()
#define str string
#define edl "\n"
#define add insert
#define cot continue
#define fast() ios_base::sync_with_stdio(false);cin.tie(NULL)
const int MOD = 1e9 + 7, INF = INT_MAX, N = 1e5 + 10;
const double PI = acos(-1);
const ll LINF = LLONG_MAX;

int main() 
{

 fast();

  ll n,w;
  cin>>n>>w;
  ll dp[n+1][w+1];
  ll val[n+1],wt[n+1];
  memset(dp,0,sizeof(dp));
  memset(val,0,sizeof(val));
  memset(wt,0,sizeof(wt));
  f(i,1,n+1)
  {
    cin>>wt[i]>>val[i];
  }

  f(i,1,n+1)
  {
        f(j,1,w+1)
        {

            if(wt[i]<=j)
            {
                dp[i][j]=max(dp[i-1][j],dp[i-1][j-wt[i]]+val[i]);
            }
            else
                dp[i][j]=dp[i-1][j];
        }
  }
  cout<<dp[n][w];

 
  cerr << "Time taken: " << int((clock() * 1000.) / CLOCKS_PER_SEC) << "ms\n";
  
  return 0;
}
 

Measured memory_bytes: 79104
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define IFOR(i, m, n) for (ll i = n - 1; i >= m; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define FOREACH(x, a) for (auto&(x) : (a))
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) ll(x.size())

void yes() {
  cout << "Yes" << endl;
  exit(0);
}

void no() {
  cout << -1 << endl;
  exit(0);
}

void print_ans(ll a, ll b, ll c) { cout << a << " " << b << " " << c << endl; }

int main() {
  ll n, k;
  cin >> n >> k;
  if (n - 2 * k + 1 < 0) {
    no();
  }

  ll t = 2 * n - k;
  ll ub = t % 3 == 0 ? t / 3 : t / 3 + 1;
  set<ll> st;
  FOR(i, k, k + 2 * n) { st.insert(i); }
  FOR(i, 1, ub + 1) {
    ll a = k + 2 * i - 2;
    ll b = 2 * n - i + 1;
    ll c = k + 2 * n + i - 1;
    print_ans(a, b, c);
    st.erase(a);
    st.erase(b);
  }

  FOR(i, ub + 1, n + 1) {
    ll a = *st.begin();
    ll b = *st.rbegin();
    ll c = k + 2 * n + i - 1;
    print_ans(a, b, c);
    st.erase(a);
    st.erase(b);
  }
}

Measured memory_bytes: 11648
#include <algorithm>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string>
#include <utility>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define loop(i, x, n) for (int i = (x); i < (n); i++)
#define all(v) (v).begin(), (v).end()
#define int long long
using namespace std;
const int MOD = 1e9 + 7;
const int INF = 1e9;
template<typename T> void cmax(T &a, T b) { a = max(a, b); }
template<typename T> void cmin(T &a, T b) { a = min(a, b); }

signed main() {
  int d, w;
  while (cin >> d >> w) {
    if (d == 0 && w == 0) break;
    int mp[20][20] = {};
    rep(i, d) rep(j, w) cin >> mp[i][j];
    int ans = 0;
    rep(y, d - 2) {
      rep(x, w - 2) {
        loop(i, y + 2, d) {
          loop(j, x + 2, w) {
            int wall = INF;
            loop(k, x, j + 1) {
              cmin(wall, mp[y][k]);
              cmin(wall, mp[i][k]);
            }
            loop(k, y, i + 1) {
              cmin(wall, mp[k][x]);
              cmin(wall, mp[k][j]);
            }
            bool flag = true;
            int tmp = 0;
            loop(iny, y + 1, i) {
              loop(inx, x + 1, j) {
                if (wall <= mp[iny][inx]) flag = false;
                tmp += wall - mp[iny][inx];
              }
            }
            if (flag) cmax(ans, tmp);
          }
        }
      }
    }
    cout << ans << endl;
  }
  return 0;
}



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

char S;
vector<int> memo;
int temp = 0,ans = 0;

int main() {
  while(cin>> S) {
    if(S == 'A' || S=='C'||S=='G'||S=='T') {
	  temp++;
	}else{
	  ans = max(temp,ans);
	  temp = 0;
	}
  }
  ans = max(temp,ans);
  cout << ans << endl;
}


Measured memory_bytes: 256
// #pragma GCC target("avx")  // CPU 処理並列化
// #pragma GCC optimize("O3")  // CPU 処理並列化
// #pragma GCC optimize("unroll-loops")  // 条件処理の呼び出しを減らす
// #define BEGIN_STACK_EXTEND(size) void * stack_extend_memory_ = malloc(size);void * stack_extend_origin_memory_;char * stack_extend_dummy_memory_ = (char*)alloca((1+(int)(((long long)stack_extend_memory_)&127))*16);*stack_extend_dummy_memory_ = 0;asm volatile("mov %%rsp, %%rbx\nmov %%rax, %%rsp":"=b"(stack_extend_origin_memory_):"a"((char*)stack_extend_memory_+(size)-1024));
// #define END_STACK_EXTEND asm volatile("mov %%rax, %%rsp"::"a"(stack_extend_origin_memory_));free(stack_extend_memory_);

#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
#include<numeric>
#include<unordered_set>
#include<unordered_map>
#include<complex>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const long double EPS=1e-9;
const long double INF=1e+10;
const long double PI=acos(-1.0);
const int C_SIZE = 3100000;
const int UF_SIZE = 3100000;
namespace{
	long long fact[C_SIZE];
	long long finv[C_SIZE];
	long long inv[C_SIZE];
	inline long long Comb(int a,int b){
	 	if(a<b||b<0)return 0;
	 	return fact[a]*finv[b]%mod*finv[a-b]%mod;
	}
	void init_C(int n){
		fact[0]=finv[0]=inv[1]=1;
		for(int i=2;i<n;i++){
			inv[i]=(mod-(mod/i)*inv[mod%i]%mod)%mod;
		}
		for(int i=1;i<n;i++){
			fact[i]=fact[i-1]*i%mod;
			finv[i]=finv[i-1]*inv[i]%mod;
		}
	}
	long long pw(long long a,long long b){
		if(a<0LL)return 0;
		if(b<0LL)return 0;
		long long ret=1;
		while(b){
			if(b%2)ret=ret*a%mod;
			a=a*a%mod;
			b/=2;
		}
		return ret;
	}
	long long pw_mod(long long a,long long b,long long M){
		if(a<0LL)return 0;
		if(b<0LL)return 0;
		long long ret=1;
		while(b){
			if(b%2)ret=ret*a%M;
			a=a*a%M;
			b/=2;
		}
		return ret;
	}
	int pw_mod_int(int a,int b,int M){
		if(a<0)return 0;
		if(b<0)return 0;
		int ret=1;
		while(b){
			if(b%2)ret=(long long)ret*a%M;
			a=(long long)a*a%M;
			b/=2;
		}
		return ret;
	}
	int ABS(int a){return max(a,-a);}
	long long ABS(long long a){return max(a,-a);}
	double ABS(double a){return max(a,-a);}
	int sig(double r) { return (r < -EPS) ? -1 : (r > +EPS) ? +1 : 0; }
	int UF[UF_SIZE];
	void init_UF(int n){
		for(int i=0;i<n;i++)UF[i]=-1;
	}
	int FIND(int a){
		if(UF[a]<0)return a;
		return UF[a]=FIND(UF[a]);
	}
	void UNION(int a,int b){
		a=FIND(a);b=FIND(b);if(a==b)return;
		if(UF[a]>UF[b])swap(a,b);
		UF[a]+=UF[b];UF[b]=a;
	}
}
// ここから編集しろ

int main(){
	int a;scanf("%d",&a);
	long long ret=0;
	for(int i=1;i<=a;i++){
		if(i%3&&i%5)ret+=i;
	}
	printf("%lld\n",ret);
}

Measured memory_bytes: 1700
// Zhupengfei 2018
// This program / source file is in public domain.

// Solution for problem: Rearranging

#include <bits/stdc++.h>

using namespace std;

// Main segment

const int MAXN = 2010;
const int MAXV = 40020;

int a[MAXN] = {};
vector<int> g[MAXV] = {};

unordered_map<int, int> primeMp = {};
int m, N;

bool inAns[MAXN] = {};

int getId(int x) {
    if (primeMp.count(x)) {
        return primeMp[x];
    }
    primeMp[x] = ++m;
    return m;
}

int color[MAXV] = {};
int C = 0;

void dfs(int u) {
    color[u] = C;
    for (int v : g[u]) {
        if (color[v] != -1)
            continue;
        if (v <= N && inAns[v])
            continue;
        dfs(v);
    }
}

void recolor() {
    C = 0;
    memset(color, -1, sizeof(color));
    for (int i = 1; i <= N; i++) {
        if (!inAns[i] && color[i] == -1) {
            dfs(i);
            C++;
        }
    }
}

bool f[MAXN][MAXN] = {};
int last[MAXN] = {};
int suffmin[MAXN] = {};
int ans[MAXN] = {};
int best[MAXN] = {};
int cnt = 0;

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

    cin >> N;
    m = N;
    for (int i = 1; i <= N; i++) {
        cin >> a[i];
        int x = a[i];
        for (int y = 2; y * y <= x; y++) {
            if (x % y != 0)
                continue;
            int id = getId(y);
            g[i].push_back(id);
            g[id].push_back(i);
            while (x % y == 0)
                x /= y;
        }
        if (x != 1) {
            int id = getId(x);
            g[i].push_back(id);
            g[id].push_back(i);
        }
    }

    for (int i = 1; i <= N; i++) {
        for (int j = 1; j <= N; j++) {
            if (i != j)
                f[i][j] = (__gcd(a[i], a[j]) != 1);
        }
    }

    memset(last, -1, sizeof(last));
    memset(suffmin, 0x7f, sizeof(suffmin));

    while (cnt < N) {
        recolor();
        memset(best, -1, sizeof(best));

        for (int i = 1; i <= N; i++) {
            if (inAns[i] || suffmin[last[i] + 1] < a[i])
                continue;
            if (best[color[i]] == -1 || a[best[color[i]]] > a[i])
                best[color[i]] = i;
        }

        int mi = -1;
        for (int i = 0; i < C; i++) {
            if (best[i] == -1)
                continue;
            if (mi == -1 || a[mi] < a[best[i]])
                mi = best[i];
        }

        assert(mi != -1);
        inAns[mi] = 1;
        ans[++cnt] = a[mi];

        for (int i = 0; i <= cnt; i++) {
            suffmin[i] = min(suffmin[i], a[mi]);
        }
        for (int i = 1; i <= N; i++) {
            if (f[i][mi]) {
                last[i] = cnt;
            }
        }
    }
    for (int i = 1; i <= N; i++) {
        cout << ans[i] << (i < N ? " " : "\n");
    }

    cout << flush;

#ifdef LOCAL
    system("pause");
#endif
    return 0;
}


Measured memory_bytes: 5632
N,T= [int(x) for x in input().split()]
c=0
t=0
z=0
x=0
mini=0
lcost=[]
ltime=[]
cost=[]
time=[]
for i in range(N):
    c,t=[int(x) for x in input().split()]
    cost.append(c)
    time.append(t)
for i in time:
    z+=1
    if i <= T:
        ltime.append(i)
        lcost.append(cost[z-1])

if ltime==[] and lcost==[]:
    print("TLE")
else:
    
    for i in lcost:
        if x==0:
           mini=i
           x+=1
        if i < mini:
           mini=i
    print(mini)

Measured memory_bytes: 3064
<?php

fscanf(STDIN, "%d", $in_x);
$yen = 100;
//var_dump($in_x);

for($y = 0; $yen < $in_x; $y++){
    $yen = floor($yen * 1.01);
//    var_dump($yen);
}

echo "$y\n";


Measured memory_bytes: 16080
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <numeric>
#include <limits>
#include <cmath>
#include <iomanip>
#include <sstream>
 
#define ALL(a)  (a).begin(),(a).end()
 
using namespace std;
typedef long long int ll;
typedef pair <int,int> P;

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

    ll ans = 0;
    string s;

    cin >> s;

    (s == "AAA" || s == "BBB") ? (cout << "No" << endl) : (cout << "Yes" << endl);

}

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

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define each(i, mp) for (auto &i : mp)

int main()
{
  ll n, m;
  cin >> n >> m;
  vector<ll> h;
  vector<vector<ll>> paths(n);
  rep(i, n)
  {
    ll th;
    cin >> th;
    h.push_back(th);
  }
  // rep(i, n)
  // {
  //   cout << 111111111 << endl;
  //   cout << h[i] << endl;
  //   cout << 111111111 << endl;
  // }
  rep(i, m)
  {
    ll a, b;
    cin >> a >> b;
    a--;
    b--;
    // if (a == 0 || b == 0)
    // {
    //   cout << "" << endl;
    //   cout << a << endl;
    //   cout << b << endl;
    // }
    paths[a].push_back(h[b]);
    paths[b].push_back(h[a]);
  }
  // rep(i, paths[0].size())
  // {
  //   cout << paths[0][i] << endl;
  // }
  ll ans = 0;
  rep(i, n)
  {
    bool best = true;
    // if (i == 0)
    // {
    //   rep(j, paths[i].size())
    //   {
    //     cout << h[i] << endl;
    //     cout << paths[i][j] << endl;
    //   }
    // }
    rep(j, paths[i].size())
    {
      if (h[i] <= paths[i][j])
      {
        best = false;
      }
    }
    if (best)
    {
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 9824
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
#include<bitset>
#include<stack>
#include<memory>
using namespace std;
using namespace std::chrono;
typedef long long int llint;
typedef double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
/*cout<<fixed<<setprecision(20);cin.tie(0);ios::sync_with_stdio(false);*/
const llint mod=998244353;
const llint big=2.19e15+1;
const long double pai=3.141592653589793238462643383279502884197;
const long double eps=1e-15;
template <class T,class U>bool mineq(T& a,U b){if(a>b){a=b;return true;}return false;}
template <class T,class U>bool maxeq(T& a,U b){if(a<b){a=b;return true;}return false;}
llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);}
llint lcm(llint a,llint b){if(a==0){return b;}return a/gcd(a,b)*b;}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());}
template<class T>llint LBI(vector<T>&ar,T in){return lower_bound(ar.begin(),ar.end(),in)-ar.begin();}
template<class T>llint UBI(vector<T>&ar,T in){return upper_bound(ar.begin(),ar.end(),in)-ar.begin();}
//  10:00-
//A 10:05 AC
//B 10:15 AC
//C 10:21 AC
//F 10:49 AC
//D 10:59 RE
//D 11:04 TLE
//D 11:10 TLE
//D 11:13 AC
//E 11:34 RE
/*
3
2
1
*/
int solve(void){
	int n,m,i,j,ans=0;cin>>n>>m;
	if(n==0){return 0;}
	vector<string>mat(n+2);
	//どこの部屋を消しても連結ならいける
	for(i=1;i<=n;i++){cin>>mat[i];mat[i].insert(mat[i].begin(),'#');mat[i].pub('#');}
	mat[0]=string(m+2,'#');
	mat[n+1]=string(m+2,'#');
	for(i=1;i<=n;i++){
		for(j=1;j<=m;j++){
			if(mat[i][j]=='#'){continue;}
			if(i==1&&j==1){continue;}
			mat[i][j]='#';
			queue<pair<int,int>>que;
			vector<vector<bool>>ren(n+2,vector<bool>(m+2));
			ren[1][1]=true;ren[i][j]=true;
			que.push(mp(1,1));
			while(que.size()){
				int y=que.front().fir;
				int x=que.front().sec;
				que.pop();
				if(mat[y+1][x]=='.'&&(!ren[y+1][x])){ren[y+1][x]=1;que.push(mp(y+1,x));}
				if(mat[y-1][x]=='.'&&(!ren[y-1][x])){ren[y-1][x]=1;que.push(mp(y-1,x));}
				if(mat[y][x+1]=='.'&&(!ren[y][x+1])){ren[y][x+1]=1;que.push(mp(y,x+1));}
				if(mat[y][x-1]=='.'&&(!ren[y][x-1])){ren[y][x-1]=1;que.push(mp(y,x-1));}
			}
			if(!ren[1][m]){cout<<"NO"<<endl;return 1;}
			if(!ren[n][1]){cout<<"NO"<<endl;return 1;}
			if(!ren[n][m]){cout<<"NO"<<endl;return 1;}
			mat[i][j]='.';
		}
	}
	cout<<"YES"<<endl;
	return 1;
}
int main(void){
	while(solve()){}
}



Measured memory_bytes: 3132
nums = {}

for w_tax in range(1, 50000+1):
    nums[w_tax] = ":("

for wo_tax in range(1, 50000+1):
    w_tax = int(wo_tax * 1.08)
    nums[w_tax] = wo_tax

#for w_tax in range(1, 50000+1):
#    wo_tax = int(w_tax * 100 / 108)
#    nums[w_tax] = wo_tax

a = int(input()) 
out = nums[a]
print(out)

Measured memory_bytes: 9452
//#include"pch.h"
//#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<algorithm>
#include<iostream>

using namespace std;
int main() {
	int A, B, C, D;
	int l, r;
	cin >> A >> B >> C >> D;
	l = A + B;
	r = C + D;
	if (l > r)puts("Left");
	else if (r > l)puts("Right");
	else puts("Balanced");





	return(0);
}

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

using namespace std;

int main(int argc, const char *argv[]) {
  int a, b;
  cin >> a >> b;

  auto solve = [](string &s) {
    bool res = true;
    for (int i = 0; i < s.size() / 2; ++i) {
      if (s[i] != s[s.size() - i - 1]) {
        res = false;
        break;
      }
    }

    return res;
  };

  int ans = 0;
  for (int i = a; i <= b; ++i) {
    string s = to_string(i);
    if (solve(s)) {
      ans++;
    }
  }

  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define PI 3.14159265359
#define NIL (-1)
#define LL long long
using namespace std;
const int64_t MOD = 1e9 + 7;

int main() {
	int A, B, C, K;
	cin >> A >> B >> C >> K;

	vector<int> v(3);
	v.at(0) = A;
	v.at(1) = B;
	v.at(2) = C;
	sort(v.begin(), v.end());

	int n = v.back();
	while (K) {
		n *= 2;
		K--;
	}

	cout << v.at(0) + v.at(1) + n << endl;
}

Measured memory_bytes: 3516
#include<stdio.h>
#include<stdlib.h>
#define NIL NULL

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;

Node root;


void treeinsert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x != NIL) {
    y = x;
    if(z->key < x->key) x = x->left;
    else x = x->right;
  }
  z->parent = y;
  if(y == NIL) root = z;
  else if(z->key < y->key) y->left = z;
  else y->right = z;
}

Node treeSearch(Node u, int k) {
  if( u == NIL || k == u->key) return u;
  if(k < u->key) return treeSearch(u->left, k);
  else return treeSearch(u->right, k);
}

Node treeMnimum(Node u) {
  while(u->left != NIL) {
    u = u->left;
  }
  return u;
}

Node treeSuccessor(Node u) {
  Node y = NIL;
  if( u->right != NIL ) return treeMnimum(u->right);
  y = u->parent;
  while(y != NIL && u == y->right) {
    u = y;
    y = y->parent;
  }
  return y;
}

void treeDelete(Node u) {
  Node y = NIL;
  Node x = NIL;

  if( u->left == NIL || u->right == NIL ) y = u;
  else y = treeSuccessor(u);

  if( y->left != NIL ) x = y->left;
  else x = y->right;

  if( x != NIL ) x->parent = y->parent;

  if( y->parent == NIL) root = x;
  else if( y == y->parent->left ) y->parent->left = x;
  else y->parent->right = x;

  if( y != u ) {
    u->key = y->key;
  }
}


void printInorder(Node u) {
  if(u->left != NIL)printInorder(u->left);
  printf(" %d", u->key);
  if(u->right != NIL)printInorder(u->right);
}

void printPreorder(Node u) {
  printf(" %d", u->key);
  if(u->left != NIL)printPreorder(u->left);
  if(u->right != NIL)printPreorder(u->right);
}


int main(){
  int n, i, x;
  char command[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", command);
    if ( command[0] == 'i' ){
      scanf("%d", &x);
      treeinsert(x);
    }
    else if( command[0] == 'f' ) {
      scanf("%d", &x);
      if( treeSearch(root, x) != NIL) printf("yes\n");
      else printf("no\n");
    }
    else if( command[0] == 'd') {
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
    else if ( command[0] == 'p' ){
      printInorder(root);
      printf("\n");
      printPreorder(root);
      printf("\n");
    }
  }

  return 0;
}

Measured memory_bytes: 19364
#include <stdio.h>

int main(int argc, const char * argv[]) {
    int a,b,x;
    char op;
    while(1){
    scanf("%d %c %d",&a,&op,&b);
    if(op=='+'){
        x=a+b;
        printf("%d\n",x);
    }else if(op=='-'){
        x=a-b;
        printf("%d\n",x);
    }else if(op=='*'){
        x=a*b;
        printf("%d\n",x);
    }else if(op=='/'){
        x=a/b;
        printf("%d\n",x);
    }else if(op=='?'){
        break;
    }}
    return 0;
}

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

using namespace std;

int main(){

  int H,W;

  cin >> H >> W;

  vector<string> c(H);
  int max = 0;
  
  for(int i = 0;i < H;++i)
    cin >> c[i];

  for(int i = 0;i < H;++i){
    for(int j = 0;j < W;++j){
      for(int k = 0;k < H;++k){
	for(int l = 0;l < W;++l){
	  if(c[i][j] == 'B' && c[k][l] == 'B' && abs(i - k) + abs(j - l) > max)
	    max = abs(i - k) + abs(j - l);
	}
      }
    }
  }

  cout << max << endl;

}



Measured memory_bytes: 3200
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<stdbool.h>

#define sz 1<<20
#define mod 998244353
#define pr 3

long modpow(long x, long y, long m){
	long res = 1l, tmp = x;
	while(y){
		if(y&1)res = res * tmp % m;
		tmp = tmp * tmp % m;
		y >>= 1;
	}
	return res;
}
int bit_rev(int x, int h){
	int res = 0;
	for(int i=0; i<h; i++){
		res <<= 1;
		res |= x&1;
		x >>= 1;
	}
	return res;
}
void dft(long a[], int h, bool sign){
	for(int i=0; i<1<<h; i++){
		int j = bit_rev(i, h);
		if(i < j){
			long tmp = a[i];
			a[i] = a[j];
			a[j] = tmp;
		}
	}
	for(int s=1; s<=h; s++){
		int m = 1<<s;
		long zeta = modpow(pr, (mod-1)>>s, mod);
		if(!sign)zeta = modpow(zeta, mod-2, mod);
		for(int k=0; k<1<<h; k+=m){
			long pow_zeta = 1;
			for(int j=0; j<m/2; j++){
				long t = pow_zeta * a[k+j+m/2] % mod,
					 u = a[k+j];
				a[k+j] = (u + t) % mod;
				a[k+j+m/2] = (mod + u - t) % mod;
				pow_zeta = zeta * pow_zeta % mod;
			}
		}
	}
}
int N, M;
long A[sz], B[sz];
int main(){
	scanf("%d%d", &N, &M);
	for(int i=0; i<N; i++)scanf("%ld", &A[i]);
	for(int i=0; i<M; i++)scanf("%ld", &B[i]);
	dft(A, 20, true); dft(B, 20, true);
	for(int i=0; i<sz; i++)A[i] = A[i] * B[i] % mod;
	dft(A, 20, false);
	long inv = modpow(sz, mod-2, mod);
	for(int i=0; i<N+M-1; i++){
		if(i)putchar(32);
		printf("%ld", A[i] * inv % mod);
	}putchar(10);
	return 0;
}

Measured memory_bytes: 27104
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 100;
int n;
vector<int> adjList[N];
long long mod, dp[N], ans[N];

void dfs1(int v, int p) {
	dp[v] = 1;

	for (int u : adjList[v]) {
		if (u == p) continue;
		dfs1(u, v);
		dp[v] = (dp[u] * dp[v]) % mod;
	}
	dp[v] = (dp[v] + 1) % mod;
}

void dfs2(int v, int p) {
	ans[v] = dp[v];

	int s = adjList[v].size();

	long long pref[s + 1];
	pref[0] = 1;
	for (int i = 0; i < s; i++) {
		int u = adjList[v][i];
		pref[i + 1] = (dp[u] * pref[i]) % mod;
	}
	
	long long suff[s + 2];
	suff[s + 1] = 1;
	for (int i = s - 1; i >= 0; i--) {
		int u = adjList[v][i];
		suff[i + 1] = (dp[u] * suff[i + 2]) % mod;
	}

	for (int i = 0; i < s; i++) {
		int u = adjList[v][i];
		if (u == p) continue;

		long long dpv = dp[v];
		long long dpu = dp[u];

		dp[v] = (suff[i + 2] * pref[i]) % mod;

		dp[u] = (dp[u] + mod - 1LL) % mod;
		dp[v] = (dp[v] + 1LL) % mod;
		dp[u] = (dp[u] * dp[v]) % mod;
		dfs2(u, v);
		dp[v] = dpv;
		dp[u] = dpu;
	}
}

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

	cin >> n >> mod;

	int a, b;
	for (int i = 1; i < n; i++) {
		cin >> a >> b;
		adjList[a].emplace_back(b);
		adjList[b].emplace_back(a);
	}

	dfs1(1, -1);
	dp[1] = (dp[1] + mod - 1LL) % mod;
	dfs2(1, -1);

	for (int i = 1; i <= n; i++) {
		cout << ans[i] << '\n';
	}

	return 0;
}


Measured memory_bytes: 23040
N,K=int(input()),int(input())
def f(n,k):
  if k<1: return 1
  if n<10:
    if k<2: return n
    return 0
  d,m=n//10,n%10
  return f(d,k-1)*m+f(d-1,k-1)*(9-m)+f(d,k)
print(f(N,K))

Measured memory_bytes: 3060
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<time.h>
#include<vector>
using namespace std;
int main()
{
    //ios::sync_with_stdio(false);
    //cin.tie(0);
    //cout.tie(0);
    int n,x,t;
    int ans;
    scanf("%d%d%d",&n,&x,&t);
    if(n%x==0)
        ans = n/x*t;
    else
        ans = n/x*t + t;
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 3696
n = int(input())
x = [int(x) for x in input().split()]
x_sorted = sorted(x)

m_large = x_sorted[n // 2]
m_small = x_sorted[n // 2 - 1]

for i in range(n):
    if x[i] <= m_small:
        print(m_large)
    else:
        print(m_small)


Measured memory_bytes: 25224
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pdd pair<double,double>
#define X first
#define Y second
#define REP(i,a) for(int i=0;i<a;++i)
#define REPP(i,a,b) for(int i=a;i<b;++i)
#define FILL(a,x) memset(a,x,sizeof(a))
#define foreach( gg,itit )  for( typeof(gg.begin()) itit=gg.begin();itit!=gg.end();itit++ )
#define mp make_pair
#define pb push_back
#define all(s) s.begin(),s.end()
#define present(c,x) ((c).find(x) != (c).end())
const double EPS = 1e-8;
const int mod = 1e9+7;
const int N = 1e6+10;
const ll INF = 1e18;

//#define DEBUG
ll power(ll x,ll y){
  ll t=1;
  while(y>0){
    if(y%2) y-=1,t=t*x%mod;
    else y/=2,x=x*x%mod;
  }
  return t;
}
#ifdef DEBUG
#define dprintf(fmt,...) fprintf(stderr,fmt,__VA_ARGS__)
#else
#define dprintf(fmt,...)
#endif

char s[N];
int main(){
  int n; scanf("%s",s); 
  n=strlen(s);
  //printf("%d\n",n);
  int sc=0;
  REP(i,n){
    int x = (s[i]=='g');
    //printf("%c %d\n",s[i],x);
    if(i%2==0&&x==0) sc--; 
    if(i%2==1&&x==1) sc++;
  }
  printf("%d\n",max(sc,0));
  return 0;
}


Measured memory_bytes: 384
#include <stdio.h>
#define N 100

void printA(int *A,int n){
	int i;
	for(i=0;i<n;i++){
		printf("%d",A[i]);
		if(i!=n-1)printf(" ");
		else printf("\n");
	}
}

void insertionSort(int *A,int n){
	int i,v,j;
	printA(A,n);
	for(i=1;i<n;i++){
		v = A[i];
		j = i-1;
		while(j>=0 && A[j]>v){
			A[j+1] = A[j];
			j--;
		}
		A[j+1] = v;
		printA(A,n);
	}
}

int main(){
	int n;
	int i;
	int A[N];

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

	insertionSort(A,n);

	return 0;
}

Measured memory_bytes: 1848
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N,A,B,C,D; 
  cin >> N >> A >> B >> C >> D; A--; B--; C--; D--;
  string S; cin >> S;
  bool flag = true;
  if( D > C){
    
    for(int i = B; i < D; i++){
      if( S[i] == '#' && S[i+1] == '#'){ flag = false;}}
    
    for(int j = A; j < C; j++){
      if( S[j] == '#' && S[j+1] == '#'){ flag = false;}}
    
    if(flag){ cout << "Yes" << endl; return 0;}
    
    }
  
  else{ // C > D (!=)
    
    for(int i = B; i < D; i++){
      if(S[i] == '#' && S[i+1] == '#'){ flag = false;}}
    bool f = false;
    for(int k = B-1; k < D; k++){
      if(S[k] == '.' && S[k+1] == '.' && S[k+2] == '.'){ f = true; S[k+1] = '#'; break;}}
    if(!f){ flag = false;}
    
    for(int j = A; j < C; j++){ 
      if(S[j] == '#' && S[j+1] == '#'){ flag = false;}}
    
    if(flag){ cout << "Yes" << endl; return 0;}
  }
  
  cout << "No" << endl; return 0;}


Measured memory_bytes: 640
#include <stdio.h>
//#define debug

int main (int argv, char *argc[]){
	int a, b, c;
	int idx=0;
	int count=0;
	scanf("%d %d %d", &a, &b, &c);
	#ifdef debug
		printf("count before for:%d\n", count);
	#endif
	/* cの約数割り出し */
	for(idx = a; b >= idx; idx++){
		if(!(c % idx))count++;
		if(idx > c) break;
		#ifdef debug
			printf("idx:%d\n", idx);
			printf("count:%d\n", count);
		#endif
	}
	
	printf("%d\n", count);	
	return 0;
}

Measured memory_bytes: 596
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#define PR pair<int,int>
#define F first
#define S second
using namespace std;

int n, l, r, cl, cr;
string s;
vector<PR> vt;

bool cmp(PR p, PR q) {return p.F - p.S > q.F - q.S;}

int main() {
	int i;
	cin >> n;
	while(n--) {
		cin >> s;
		l = r = 0;
		for(i=0; s[i]; i++) {
			if(s[i] == '(') l++;
			else {
				if(l) l--;
				else r++;
			}
		}
		if(l && !r) cl += l;
		else if(!l && r) cr += r;
		else if(l && r) vt.push_back({l, r});
	}
	sort(vt.begin(), vt.end(), cmp);
	for(i=0; i<vt.size(); i++) {
		if(cl < vt[i].S) return puts("No"),0;
		cl -= vt[i].S - vt[i].F;
	}
	puts(cl==cr ? "Yes" : "No");
	return 0;
}

Measured memory_bytes: 5240
N=int(input())
for i in range(1,3501):
    for j in range(i,3501):
        if (4*i*j-N*i-N*j)>0:
            if (N*i*j)%(4*i*j-N*i-N*j)==0:
                print(i,j,(N*i*j)//(4*i*j-N*i-N*j))
                exit()

Measured memory_bytes: 3060
///Astalavista Code........~CodeSlayer007
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define Br cout<<endl;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define int long long
#define double long double
#define all(v) v.begin(),v.end()
#define allr(v) v.rbegin(),v.rend()
#define PT(x) cout << (#x) << " is " << (x) << endl;
#define SPD_emergency ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
const int M = 1e9 + 7;
int IM = 1e17;
void PV(vi v) { for (int i = 0 ; i < v.size() ; i++) cout << v[i] << " "; cout << endl;}
void PA(int v[], int n) {for (int i = 0 ; i < n ; i++)cout << v[i] << " " ; cout << endl;}
void IN(int a[], int n) {for (int i = 0; i < n; i++)cin >> a[i];}
inline void PTN(int n = 1, int a = 0, int b = 0, int c = 0) { if (n--)cout << a << " "; if (n--)cout << b << " "; if (n--)cout << c << " "; cout << endl; }
inline void open() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}
// <-------------------------------------------------------------------------------------------------------------------------------------------------------------------------> Ignore This-->  tuple first second push_back string continue make_pair break deque stack queue sort reverse accumulate  count lower_bound upper_bound next_permutation copy_n __builtin_popcount make_tuple
// <========================================================================================================================================================================

signed  main() {
    SPD_emergency

   // int t; cin >> t; int tt = 1; while (t--)
    {
        int n, k;
        map<int,int> m;
        int d, i, j, l;
        set<int> s;
        cin >> n >> k;
        while( k-- ){
            cin >> d;
            while(d--){
                cin >> i;
                s.insert(i);
            }

        }
        cout << n - s.size();
    }
    return 0;
}

Measured memory_bytes: 3656
n=int(input())
d={i:list(input().split()) for i in range(n)}

def roll(Dice,Vector):
    if Vector == "N":
        c=Dice[0]
        Dice[0]=Dice[1]
        Dice[1]=Dice[5]
        Dice[5]=Dice[4]
        Dice[4]=c
    elif Vector == "W":
        c=Dice[0]
        Dice[0]=Dice[2]
        Dice[2]=Dice[5]
        Dice[5]=Dice[3]
        Dice[3]=c
    elif Vector == "E":
        c=Dice[0]
        Dice[0]=Dice[3]
        Dice[3]=Dice[5]
        Dice[5]=Dice[2]
        Dice[2]=c
    elif Vector == "S":
        c=Dice[0]
        Dice[0]=Dice[4]
        Dice[4]=Dice[5]
        Dice[5]=Dice[1]
        Dice[1]=c

v=list("NNNNWNNNWNNNENNNENNNWNNN")
f=0
for i in range(n):
    if f==0:
        for item in v:
            roll(d[i],item)
            if f==0:
                for j in range(i+1,n):
                    if d[i]==d[j]:
                        f+=1
                        break
if f==0:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 5616
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
 
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=(n)-1;i>=0;i--)
#define VSORT(v) sort(v.begin(), v.end())
#define DVSORT(v) sort(v.begin(), v.end(),greater<int>())
#define SORT(v, n) sort(v, v+n)
#define DSORT(v,n) sort(v, v+n,greater<int>())
#define vi vector<int>
#define pb push_back
#define P pair<int,int>
#define Pll pair<ll,ll>

template <class T> void chmin(T&a,const T&b) { a = min(a,b); }
template <class T> void chmax(T&a,const T&b) { a = max(a,b); }
 
void print(){cout<<endl;}
template <class Head, class... Tail>
void print(Head&& h,Tail&&... t){ 
	if(sizeof...(t)==0)
		cout<<h;
	else
		cout<<h<<' ';
	print(move(t)...);
}
 
const double EPS =1e-9;
const int INF =2e+9;
const ll INFL =9e+18;
const long MOD =1e+9+7;
#define PI 3.14159265258979

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

int main(void){
	string S;
	int N;
	ll sum=0,cn[5];

	cin>>N;
	REP(i,5) cn[i]=0;

	REP(i,N){
		cin>>S;
		switch(S[0]){
			case 'M':
				cn[0]++;
				break;
			case 'A':
				cn[1]++;
				break;
			case 'R':
				cn[2]++;
				break;
			case 'C':
				cn[3]++;
				break;
			case 'H':
				cn[4]++;
				break;
			default:
				break;
		}
	}
	
	REP(i,5)
		FOR(j,i+1,5)
			FOR(r,j+1,5)
				sum+=cn[i]*cn[j]*cn[r];
			
	print(sum);
	return 0;
}




Measured memory_bytes: 256
def main():
    N = input()
    ans = 0
    carry = 0
    prev_5 = False
    for c in N[::-1]:
        if prev_5 and int(c) >= 5:
            carry = 1
        if int(c) + carry <= 4:
            ans += int(c) + carry
            carry = 0
            prev_5 = False
        elif int(c) + carry == 5:
            ans += 10 - (int(c) + carry)
            carry = 0
            prev_5 = True
        else:
            ans += 10 - (int(c) + carry)
            carry = 1
            prev_5 = False
    if carry == 1:
        ans += 1
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 60272
#include <iostream>
#include <vector>

using  namespace std;

int main(){
  int x, y;
  cin >> x >> y;
  
  char gx, gy;
  if(x == 1 || x == 3 || x == 5 || x == 7 || x == 8 || x == 10 || x == 12) gx = 'a';
  else if(x == 4 || x == 6 || x == 9 || x == 11) gx = 'b';
  else gx = 'c';
  if(y == 1 || y == 3 || y == 5 || y == 7 || y == 8 || y == 10 || y == 12) gy = 'a';
  else if(y == 4 || y == 6 || y == 9 || y == 11) gy = 'b';
  else gy = 'c';
  
  if(gx == gy) cout << "Yes";
  else cout << "No";
}

Measured memory_bytes: 256
// デバッグ実行：Ctrl+F5

using System;

class Program
{
    static void Main(string[] args)
    {
        String line;
        line = Console.ReadLine();
        String[] words = line.Split(' ');
        int N = int.Parse(line);
        line = Console.ReadLine();
        words = line.Split(' ');
        double T = double.Parse(words[0]);
        double A = double.Parse(words[1]);
        double[] H = new double[N];
        line = Console.ReadLine();
        words = line.Split(' ');
        for(int i = 0; i < N; i++)
        {
            H[i] = double.Parse(words[i]);
        }
        int TOP = 0;
        double TOPsa = A - (T - H[0] * 0.006);
        TOPsa = Math.Abs(TOPsa);
        for (int i = 1; i < N; i++)
        {
            double sa = A - (T - H[i] * 0.006);
            sa = Math.Abs(sa);
            if (TOPsa > sa)
            {
                TOPsa = sa;
                TOP = i;
            }
        }

        Console.WriteLine(TOP + 1);
    }
}

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

#define ll long long
#define vvi vector< vector<int> >
#define vi vector<int>
#define All(X) X.begin(),X.end()
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back
#define pii pair<int,int>
#define mp make_pair
#define pi 3.14159265359
#define shosu(X) fixed << setprecision(X)
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
const ll int INF = 1e9;
int ti[101][101];//time
int co[101][101];//cost
int n,m;
int main(){
	while(1){
		cin >> n >> m; 
		if(n == 0 && m == 0) break;
		REP(i,101) REP(j,101) ti[i][j] = co[i][j] = INF;
		REP(i,101) ti[i][i] = co[i][i] = 0;

		REP(i,n){
			ll int a,b,cost,tim;
			cin >> a >> b >> cost >> tim;
			a--; b--;
			co[a][b] = co[b][a] = cost;
			ti[a][b] = ti[b][a] = tim;
		}
		//Warshall???Floyd Algorithm
		REP(k,m){
			REP(i,m){
				REP(j,m){
					ti[i][j] = min(ti[i][j], ti[i][k] + ti[k][j]);
					co[i][j] = min(co[i][j], co[i][k] + co[k][j]);
				}
			}
		}
		int k;
		cin >> k;
		REP(i,k){
			int a,b,r;
			cin >> a >> b >> r;
			a--; b--;
			if(r == 0) cout << co[a][b] << endl;
			else cout << ti[a][b] << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1248
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define MOD 1000000007
ll isPrime[1000010]={0};
vector<ll> Prime;

void sieve(){
	ll i,j;
	isPrime[0] = isPrime[1] = 1;
	for( i=2; i<1000010; i++)if(isPrime[i]==0)for(j=2*i; j<1000010; j+=i)isPrime[j]=1;
	for( i=1; i<1000010; i++)if(isPrime[i]==0)Prime.push_back(i);
}
ll modMul(ll a,ll b,ll mod){
	ll res=0;
	if(mod<=MOD){
        return ((a%mod)*(b%mod))%mod;
	}
	while(b){
		if(b&1)res = (res+a)%mod;
		a = (2*a)%mod;
		b = b/2;
	}
	return res;
}
ll modPow(ll x,ll n,ll mod){
	ll r = 1;
	while(n){
		if(n&1)r = modMul(r,x,mod);
		x = modMul(x,x,mod);
		n = (n>>1);
	}
	return r;
}
vector<int>v;
void printDivisors(int n) 
{ 
    // Vector to store half of the divisors 3343434 
    for (int i=1; i<=sqrt(n); i++) 
    { 
        if (n%i==0) 
        { 
            if (n/i == i) // check if divisors are equal 
                if (i%2!=0){
                	v.push_back(i);
				} 
            else
            { 
                if (i%2!=0){
                	v.push_back(i);
				}  
  
                // push the second divisor in the vector 
                if ((n/i)%2!=0){
                	v.push_back(n/i);
				} 
            } 
        } 
    } 
  
    // The vector will be printed in reverse 
} 
int sum=0;
long long int knapsack(int a[],int w[],int n,int W){
	long long int dp[n+1][sum+1];
	for (int i=1;i<=sum;i++){
		dp[0][i]=INT_MAX;
	}
	for (int i=0;i<=n;i++){
		dp[i][0]=0;
	}
	for (int i=1;i<=n;i++){
		for (int j=1;j<=sum;j++){
			if (a[i-1]>j){
				dp[i][j]=dp[i-1][j];
			}
			else{
				dp[i][j]=min(dp[i-1][j],w[i-1]+dp[i-1][j-a[i-1]]);
			}
		}
	}

	int m=-1;
	for (int i=n;i>=1;i--){
		for (int j=sum;j>=0;j--){
			if (dp[i][j]<=W){
				if (m<j){
					m=j;
				}
			}			
		}
		
	}
	return m;
	
}
void solve (){
	int n,W;
	cin>>n>>W;
	int a[n],w[n];
	for(int i=0;i<n;i++){
		cin>>w[i];
		cin>>a[i];
		sum+=a[i];
	}
	cout<<knapsack(a,w,n,W)<<endl;
	
}
	
	

int main(){
	int t;
	//cin>>t;
	t=1;
	while(t--){
		solve();
		}
		
	}


Measured memory_bytes: 82404
from collections import Counter
N,M=map(int,input().split())
A=list(map(int,input().split()))
A.insert(0,0)
cnt = Counter()
for i in range(N): A[i+1] += A[i]
for i in range(N+1): cnt[A[i]%M] += 1
print(sum(n*(n-1)//2 for n in cnt.values()))


Measured memory_bytes: 14628