akhauriyash/Code-Regression huggingface dataset:
#define _CRT_SECURE_NO_WARNINGS

#include <vector>
#include <iostream>
#include <string>
#include <functional>
#include <set>
#include <map>
#include <unordered_map>
#include <fstream>
#include <iomanip>
#include <ctime>
#include <queue>
#include <deque>
#include <math.h>
#include <cmath>
#include <stack>
#include <algorithm>
#include <list>
#include <array>
#include <valarray>
#include <unordered_map>
#include <cassert>
#include <random>
#include <cstring>
#include <sstream>
#include <numeric>
#include <iterator>

using namespace std;

#define x first
#define y second
#define mp make_pair
#define pb push_back
#define sqr(a) ((a) * (a))
#define sz(a) int((a).size())
#define all(a) a.begin(), a.end()
#define forn(i, n) for(int i = 0; i < int(n); i++) 
#define fore(i, l, r) for(int i = int(l); i < int(r); i++)

typedef long long li;
typedef long double ld;
typedef pair<int, int> pt;

template <class A, class B> ostream& operator << (ostream& out, const pair<A, B> &a) {
	return out << "(" << a.x << ", " << a.y << ")";
}

template <class A> ostream& operator << (ostream& out, const vector<A> &v) {
	out << "[";
	forn(i, sz(v)) {
		if (i) out << ", ";
		out << v[i];
	}
	return out << "]";
}

mt19937 rnd(time(NULL));

const int INF = int(1e9);
const li INF64 = li(1e18);
const int MOD = INF + 7;
const ld EPS = 1e-9;
const ld PI = acos(-1.0);
//const li MOD = 100055128505716009;
//const li P = 3e4 + 11;


const int N = 1e3 + 7;

int m, n;

vector<int> g[N];

bool read() {
	if (!(cin >> n >> m))
		return false;

	forn(i, m) {
		int x, y;
		cin >> x >> y;
		x--, y--;
		g[x].pb(y);
	}

	return true;
}

int used[N];
int pr[N];
vector<vector<int>> cs;

void dfs(int v, int p) {
	used[v] = 1;
	pr[v] = p;
	for (int to : g[v]) {
		if (!used[to]) {
			dfs(to, v);
			continue;
		}

		if (used[to] == 1) {
			vector<int> ans;
			int x = v;
			ans.pb(x);
			while (x != to) {
				x = pr[x];
				ans.pb(x);
			}
			cs.pb(ans);
		}
	}

	used[v] = 2;
}

bool good(vector<int>& x) {
	vector<bool> in(n);
	for (int v : x) {
		in[v] = true;
	}

	vector<int> din(n), dout(n);
	for (int v : x) {
		for (int to : g[v]) {
			if (!in[to]) {
				continue;
			}

			din[to]++;
			dout[v]++;
		}
	}

	for (int v : x) {
		if (din[v] != 1 || dout[v] != 1) {
			return false;
		}
	}

	return true;
}

void solve() {
	forn(i, n) {
		if (!used[i]) {
			dfs(i, i);
		}
	}

	sort(all(cs), [](auto& i, auto& j) {
		return sz(i) < sz(j);
	});

	for (auto& a : cs) {
		if (good(a)) {
			cout << a.size() << endl;
			for (int x : a) {
				cout << x + 1 << endl;
			}
			return;
		}
	}

	cout << -1 << endl;
}

int main() {
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);

	int tt = clock();

#endif

	ios::sync_with_stdio(0);
	cin.tie(0);

	cerr.precision(15);
	cout.precision(15);
	cerr << fixed;
	cout << fixed;

#ifdef _DEBUG
	while (read()) {
#else
	if (read()) {
#endif

		solve();

#ifdef _DEBUG
		cout << "TIME = " << clock() - tt << endl;
		tt = clock();
#endif
	}
	}


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

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

typedef long long ll;
using namespace std;
int mod = 1000000007;

int main(void){
    ll N; cin >> N;
    ll A[N]; rep(i, N) cin >> A[i];
    ll K[N] = {};
    ll acc = 0;
    ll ans = 0;
    while(true){
        acc = 0;
        rep(i, N){
            if(A[i] <= N-1) K[i] = 0;
            else{
                K[i] = (A[i]+1-N)/N;
                if((A[i]+1-N) % N) K[i]++;
                acc += K[i];
            }
        }
        if(acc == 0) break;
        rep(i, N){
            A[i] += (acc-K[i])-K[i]*N;
        }
        ans += acc;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i,a,b)  for(ll i=a;i<b;i++)
#define nl cout<<endl

#define pii pair<ll,ll>
#define vi  vector<ll>
#define vii vector<pii>
#define mi  map<ll,ll>
#define all(a)  (a).begin(),(a).end()

#define pb push_back
#define ff first
#define ss second
#define hell 1000000007

#define test4(x,y,z,a) cout<<"x is "<<x<<"		y is "<<y<<"		z is "<<z<<"		a is "<<a<<endl;
#define test3(x,y,z) cout<<"x is "<<x<<"		y is "<<y<<"		z is "<<z<<endl;
#define test2(x,y) cout<<"x is "<<x<<"		y is "<<y<<endl;
#define test1(x) cout<<"x is "<<x<<endl;
#define N 3002

ll power(ll a,ll b,ll m)
{
	ll ans=1;
	while(b)
	{
		if(b&1)
			ans=(ans*a)%m;
		b/=2;
		a=(a*a)%m;
	}
	return ans;
}
ld a[N];
ll n;
ld dp[N][N];
ld go(ll ind,ll heads)
{
	if(ind==(n+1))
	{
		ll tails=n-heads;
		return heads>tails;
	}
	if(dp[ind][heads]!=-1.00000)
		return dp[ind][heads];
	ld ans=0.00;
	ans+=a[ind]*go(ind+1,heads+1);
	ans+=(1.0000-a[ind])*go(ind+1,heads);

	//test3(ind,heads,ans);
	return dp[ind][heads]=ans;
}
int main()
{	
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
        
	cin>>n;
	rep(i,0,n+2)
		rep(j,0,n+2)
			dp[i][j]=-1.00000;
	rep(i,1,n+1)
		cin>>a[i];
	ld ans=go(1,0);
	//test1(ans);
	std::cout << std::setprecision(10) << ans << '\n';
}

Measured memory_bytes: 141312
#include <bits/stdc++.h>
#pragma GCC optimize("O2")
using namespace std;

# define mp make_pair
# define pb push_back
# define PI acos(-1)
# define ff first 
# define ss second 
# define endl '\n'
# define vt vector
# define all(c) (c).begin(), (c).end()
# define rep(i,a,b) for(int i = a ; i < b ; ++i)

typedef long long ll ; 
typedef long double ld ; 
typedef pair<int,int> pii ; 
typedef pair<ll,ll> pll ;

template<class T> bool umin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool umax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }

const int MOD = 1e9+9 ;
const ll inf = 1e18 ;  
const ll mod = 1e9+7 ;  

ll nCr(ll n,ll r){ll t=1;if(r>n)return 0;if(r>n-r)r=n-r;for(ll i=0;i<r;i++){t*=(n-i);t/=(i+1);}return t;}
ll power(ll a, ll n) { ll r=1;while(n){if(n&1)r=(r*a)%MOD;n>>=1;a=(a*a)%MOD;}return r%MOD;}



vt<pii> dir =  {{-1,0} , {1, 0} , {0,-1} , {0,1}} ; 

// ==========Start Here==============

const int N = 2e5+1; 
vt<int> adj[N] ; 
vt<ll> val(N) ; 

void dfs(int u, int par) {
    val[u] += val[par] ;
    for(int x : adj[u]) {
        if(x == par) 
            continue ; 
        dfs(x, u) ; 
    }   
}

int main() 
{ 
	int n , q ; 
    cin >> n >> q ; 
    int x , y ; 
    rep(i,0,n-1) {
        cin >> x >> y ; 
        adj[x].pb(y) ; 
        adj[y].pb(x) ; 
    }
    ll u,v ; 
    while(q--) {
        cin >> u >> v ; 
        val[u] += v ; 
    }

    dfs(1,0) ; 
    rep(i,1,n+1) {
        cout << val[i] << " " ; 
    }
    return 0; 
} 

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

int main(){
  ll n,d;
  cin>>n>>d;
  int ans=0;
  rep(i,n){
    ll x,y;
    cin>>x>>y;
    if(x*x+y*y<=d*d) ans++;
  }
  cout<<ans<<endl;
}



Measured memory_bytes: 3628
n = int(input())

d = []

x = 2
while n > 1 and x <= 1000000:
    t = 0
    while n % x == 0:
        t += 1
        n //= x
    if t > 0:
        d.append(t)
    x += 1
if n > 1:
    d.append(1)

def f(t):
    l, r = 0, t + 3
    while r - l > 1:
        c = (r + l) // 2
        if c * (c + 1) // 2 > t:
            r = c
        else:
            l = c
    return l
print(sum(f(ti) for ti in d))


Measured memory_bytes: 9208
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <functional>

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
    #define eprintf(...) 42
#endif

#define rep_(i, a_, b_, a, b, ...) for (int i = (a), i##_len = (b); i < i##_len; ++i)
#define rep(i, ...) rep_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define reprev_(i, a_, b_, a, b, ...) for (int i = (b-1), i##_min = (a); i >= i##_min; --i)
#define reprev(i, ...) reprev_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define all(x) (x).begin(), (x).end()
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 (b < a) { a = b; return 1; } return 0; }
template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair <int,int> P;
typedef long double ld;

struct edge {
    int from, to;
    ll cost;
};
int main (void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m, p; cin >> n >> m >> p;
    // vector<vector<P> > graph(n);
    vector<edge> graph;
    rep (i, m) {
        int a, b, c; cin >> a >> b >> c; a--; b--;
        graph.push_back({a, b, p - c});
    }
    vector<ll> dist(n);
    ll INF = 1001001001001001001;
    rep (i, 1, n) dist[i] = INF;
    rep (i, 3 * n) {
        for (auto e : graph) {
            if (chmin(dist[e.to], dist[e.from] + e.cost)) {
                if (i >= n - 1) {
                    if (e.to == n - 1) {
                        cout << -1 << "\n";
                        return 0;
                    }
                    dist[e.to] -= 10000000;
                }
            }
        }
    }
    rep (i, n) eprintf("%lld ", max(-dist[i], 0LL)); eprintf("\n");
    cout << max(-dist[n - 1], 0LL) << "\n";
    return 0;
}

Measured memory_bytes: 560
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define P pair<ll,ll>
#define lvector vector<ll> 
#define rep(i,n) for(ll (i)=0; i<(n); ++(i))
#define print(a) cout << (a) << endl

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll n,sum=0,ans=0;cin>>n;
  lvector v(n,0);rep(i,n) {cin>>v[i];sum+=v[i];}
  ans=sum-2*(*max_element(v.begin(),v.end()));
  if(ans>0) puts("Yes");else puts("No");
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define IOS ios_base::sync_with_stdio(NULL);cin.tie(0);cout.tie(0)
using namespace std;
long long k;
vector<string> ans;
queue<string> q;
void f(string a){
    char b = a[a.size()-1];
    b--;
    if(b>='0'){
        ans.pb(a+b);
        q.push(a+b);
    }
    b++;
    ans.pb(a+b);
    q.push(a+b);
    b++;
    if(b<='9'){
        ans.pb(a+b);
        q.push(a+b);
    }
    
}
int main(){
    IOS;
    cin>>k;
    for(int i =1;i<=9;i++){
        string yak = to_string(i);
       
        // string yak = now+"";
        ans.pb(yak);
        q.push(yak); 
        // cout<<ans[i-1]<<endl;
    }
    while(!q.empty()&&ans.size()<k){
        f(q.front());
        q.pop();

    }
    cout<<ans[k-1]<<endl;

}

Measured memory_bytes: 12020
#include <bits/stdc++.h>
#define rep(i, start, end) for (long long i = start; i < end; ++i)
#define repreverse(i, start, end) for (long long i = start; i >= end; --i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define len(x) ((long long)(x).size())
#define lcm(a, b) ((a) / __gcd((a), (b)) * (b))
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vllvll = vector<vll>;
using vc = vector<char>;
using pll = pair<ll, ll>;
template<class T> void print1d(T x,ll n=-1){if(n==-1)n=x.size();rep(i,0,n){cout<<x[i]<<' ';}cout<<'\n';}
template<class T> void print2d(T x,ll r=-1,ll c=-1){if(r==-1)r=x.size();if(c==-1)c=x[0].size();rep(i,0,r)print1d(x[i],c);}
template<class T, class U> bool haskey(T mp, U key) { return mp.find(key) != mp.end(); }
template<class T, class U> bool isin(T el, U container) { return find(all(container), el) != container.end(); }
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 (b < a) { a = b; return 1; } return 0; }
template<class T> bool even(T n) { return ! (n & 1); }
template<class T> bool odd(T n) { return n & 1; }
template<class T> ll rup(T a, T b) { return a % b ? a / b + 1 : a / b; }
template<class T> ld deg2rad(T deg) { return M_PI * deg / 180.0; }
template<class T> ld rad2deg(T rad) { return 180.0 * rad / M_PI; }
const long double pi = M_PI;
const long long big = 1LL << 50;
const long long inf = 1LL << 60;
const long long mod = 1e9 + 7;
ll intpow(ll a, ll n, ll _mod=numeric_limits<ll>::max()) { ll p=1; while (n) { if (n&1) p=p*a%_mod; a=a*a%_mod; n>>=1; } return p; } 
ll modc(ll a, char op, ll b, ll _mod=mod)
{
        a %= _mod; b %= _mod; ll res = 1;
        switch (op) {
        case '+': res = (a + b) % _mod; break;
        case '-': res = (a - b) % _mod; break;
        case '*': res = a * b % _mod; break;
        case '/': res = modc(a, '*', modc(b, '^', _mod-2, _mod), _mod); break;
        case '^': res = intpow(a, b, _mod); break;
        case 'P': rep(i, a-b+1, a+1) res = modc(res, '*', i, _mod); break;
        case 'C': res = modc(modc(a, 'P', b, _mod), '/', modc(b, 'P', b, _mod)); break;
        } 
        if (res < 0) { res += _mod; } return res;
}



int main()
{
        ll N, x;
        cin >> N >> x;

        vll a(N);
        rep(i, 0, N) cin >> a[i];

        ll ans = 0;
        sort(all(a));
        rep(i, 0, N) {
                if (i != N-1) {
                        if (x >= a[i]) {
                                x -= a[i];
                                ++ans;
                        }
                } else {
                        if (a.back() == x) ++ans;
                }
        }

        cout << ans << endl;
}


Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
  int n;
  string a, b;
  cin >> n;
  cin >> a >> b;
  
  for (int i = 0; i < n; i++)
  {
    cout << a[i] << b[i];
  }
  
  
  return 0;
}



Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
//#include<iostream>
using namespace std;

int a=0,b=0,n;
int small,big;
#define maxn 200011
int num[maxn];
bool ans;
int main()
{
	scanf("%d",&n);
	for (int i=1;i<=n;i++) scanf("%d",&num[i]);
	small=big=0;ans=0;
	for (int i=1;i<=n;i++)
	{
		if (!small) small=num[i],a++;
		else if (num[i]==small) a++;
		else if (!big)
		{
			if (num[i]<small)
			{
				big=small;
				small=num[i];
				b=a;
				a=1;
			}
			else
			{
				big=num[i];
				b++;
			}
		}
		else if (num[i]==big) b++;
		else ans=1;
	}
//	cout<<"small"<<small<<endl;
//	cout<<"a"<<a<<endl;
//	cout<<"big"<<big<<endl;
//	cout<<"b"<<b<<endl;
	if (big-small>1) ans=1;
	if (ans) printf("No\n");
	else
	{
		if (b)
		{
			int p=big-a;
			if (p>0 && p<=b/2) printf("Yes\n");
			else printf("No\n");
		}
		
		else if (small<=a/2 || small==n-1) printf("Yes\n");
		else printf("No\n");
	}
	return 0;
}

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

#define ff first
#define ss second
#define int long long
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define pb push_back
#define mp make_pair
#define endl "\n"      // Comment in INTERACTIVE(there just use endl which flushes output , no need of fflush(sdtout)).
//  for counting setbits -> __builtin_popcountll(x)
// for counting zerobits -> __builtin_ctzll(x)
#define fastio() ios_base::sync_with_stdio(false);        cin.tie(NULL); //(unties i/o buffer).
            // DON'T USE SCANF/PRINTF WITH IT (c/c++ -> seperates buffer).

const int mod = 1000000007;
const int inf = 1000000009;
 const int N = (1e5) + 2;
 int w[102] ;
 int v[102];
 int dp[100 + 2][N];
 int memo[100 + 2][N];

 int cnt;

// Recursive
int knapsack(int left,int i,int n){
    if(i > n)
        return 0;
    int ans = knapsack(left,i+1,n);
    if(left >= w[i])
        ans = max(ans,knapsack(left - w[i], i+1,n) + v[i]);
    return ans;
    // Here have 2 attributes that decide state -> i and left.
    // Hence in memo , store state using them.
}

int knapmemo(int i,int left,int n){
    if(i > n)
        return 0;
    if(memo[i][left] != -1)
        return memo[i][left];

    int ans = knapmemo(i+1,left,n);
    if(left >= w[i]){
        ans = max(ans,knapmemo(i+1, left - w[i], n) + v[i]);
    }
    
    cnt++;

    return memo[i][left] = ans;
}

int32_t main(){
    fastio();

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

     // ***** AC_chahiye EK BAR MEIN

     // BEGIN CODE HERE
     memset(memo,-1,sizeof(memo));  // set memo as -1.
    int n , net;
    cin>>n>>net;


    for(int i = 1;i <= n; ++i){
        cin>>w[i]>>v[i];
    }
    
    cout<<knapmemo(1,net,n);
    //getch();
}


Measured memory_bytes: 80256
#include <iostream>

using namespace std;

int main()
{
    int a,b,x,y,z;
    cin >>a>>b;
    x=a+b;
    y=a-b;
    z=a*b;

    if (x>=y&& x>=z)
        cout <<x;
    else if (y>=x&& y>z)
        cout<<y;
    else if (z>=y && z>=x)
        cout<<z;


    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <tuple>
#include <algorithm>
#include <functional>
#include <cstring>
#include <limits.h>
#define FOR(i,k,n)  for (int i=(k); i<(int)(n); ++i)
#define REP(i,n)    FOR(i,0,n)
#define FORIT(i,c)	for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define SZ(i) ((int)i.size())
#define GI(i) (scanf("%d",&i))
#define pb          push_back
#define mp          make_pair
#define mt          make_tuple
#define get0(x)     (get<0>(x))
#define get1(x)     (get<1>(x))
#define get2(x)     (get<2>(x))
#define ALL(X)      (X).begin(),(X).end()
#define LLMAX       9223372036854775807LL
#define LLMIN       -9223372036854775808LL
#define IMAX        2147483647
#define IMIN        -2147483648
typedef long long LL;
using namespace std;

string A;
string DP[26];

int main(void){
    cin>>A;
    REP(i,26){
        DP[i]="a";
        DP[i][0]+=i;
        // cout<<DP[i]<<endl;
    }
    for(int i=SZ(A)-1;0<=i;i--){
        string m=DP[0];
        // cout<<m<<endl;
        REP(j,26){
            if(SZ(DP[j])<SZ(m))
                m=DP[j];
            else if(SZ(DP[j])==SZ(m))
                m=min(m,DP[j]);
        }
        // cout<<A[i]<<endl;
        DP[A[i]-'a']=A[i]+m;
    }
    string ans=DP[0];
    REP(i,26){
        if(SZ(DP[i])<SZ(ans))
            ans=DP[i];
        else if(SZ(DP[i])==SZ(ans))
            ans=min(ans,DP[i]);
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 644
#include <bits/stdc++.h>
#define INF 1000000001
#define ll long long
using namespace std;
using pll = pair<ll, ll>;

bool comp(pair<ll, ll> a, pair<ll, ll> b)
{
  if (a.second > b.second)
  {
    return false;
  }
  return true;
}

int main()
{
  ll N, M;
  cin >> N >> M;
  vector<pair<ll, ll>> se(M);
  for (ll i = 0; i < M; ++i)
  {
    ll x, l;
    cin >> x >> l;
    se.at(i) = {x, l};
  }
  sort(se.begin(), se.end(), [](pll a, pll b) {
    return a.second < b.second;});
  // for (ll i = 0; i < M; ++i)
  // {
  //   cout << se.at(i).first << ' ' << se.at(i).second << endl;
  // }
  ll ans = 0;
  ll last = -1000000010000000000;
  for (ll i = 0; i < M; ++i)
  {
    if (se.at(i).first < last)
    {
      continue;
    }
    ans += 1;
    last = se.at(i).second;
  }
  cout << ans << endl;
}


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

typedef long long ll;

using namespace std;


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

    int N, C;
    cin >> N >> C;

    ll tmp;

    vector<vector<int>> strangeness(C, vector<int>(C)), distribution(3, vector<int>(C, 0));
    for (auto &&row: strangeness) {
        for (auto &element: row) {
            cin >> element;
        }
    }

    for (int i = 1; i <= N; i++) {
        for (int j = 1; j <= N; j++) {
            cin >> tmp;
            distribution[(i + j) % 3][tmp - 1] += 1;
        }
    }

    ll answer = -1;
    for (int i = 1; i <= C; i++) {
        for (int j = 1; j <= C; j++) {
            for (int k = 1; k <= C; k++) {
                // 同じ色については調べる必要はない
                if (i == j || j == k || k == i) {
                    continue;
                }

                tmp = 0;
                for (int l = 1; l <= C; l++) {
                    // 色lを色i,j,kに変換した時の違和感の変化を計算
                    tmp += distribution[0][l - 1] * strangeness[l - 1][i - 1];
                    tmp += distribution[1][l - 1] * strangeness[l - 1][j - 1];
                    tmp += distribution[2][l - 1] * strangeness[l - 1][k - 1];
                }
                answer = (answer == -1) ? tmp : min(tmp, answer);
            }
        }
    }

    cout << answer << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <queue>
#include <algorithm>
#include <cstring>
#include <string>
#include <stack>
#include <stdlib.h>
#include <cctype>
#include <vector>
#include <map>
#include <set>
#include <cmath>
#include <iomanip>
using namespace std;
const int INF=1000000000;
const int max_n=1005;
typedef pair<int,int>P;
char maze[max_n][max_n+1];
int n,m,sx,sy;
int d[max_n][max_n];
int dx[4]={-1,0,0,1};
int dy[4]={0,-1,1,0};
int bfs(char e)
{
    queue<P>que;
    for(int i=0;i<n;i++)
        for(int j=0;j<m;j++)d[i][j]=INF;
    que.push(P(sx,sy));
    d[sx][sy]=0;
    while(!que.empty())
    {
        P q=que.front();
        que.pop();
        if(maze[q.first][q.second]==e){sx=q.first;sy=q.second;break;}
        for(int i=0;i<4;i++)
        {
            int nx=q.first+dx[i],ny=q.second+dy[i];
            if(0<=nx&&nx<n&&ny>=0&&ny<m&&maze[nx][ny]!='X'&&d[nx][ny]==INF)
            {
                que.push(P(nx,ny));
                d[nx][ny]=d[q.first][q.second]+1;
            }
        }
    }
return d[sx][sy];
}
int main()
{
    int t;
    while(cin>>n>>m>>t)
    {
       for(int i=0;i<n;i++)
        for(int j=0;j<m;j++)
       {
           cin>>maze[i][j];
           if(maze[i][j]=='S')sx=i,sy=j;
       }

       int res=0;
       for(int i=1;i<=t;i++){
        res+=bfs(i+'0');
       }
        cout<<res<<endl;
    }
    return 0;
}

Measured memory_bytes: 8016
n = int(input())
a = list(map(int, input().split()))
for i in range(n):
    v = a[i]
    j = i - 1
    while j >= 0 and a[j] > v:
        a[j+1] = a[j]
        j -= 1
    a[j+1] = v
    print(*a)

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

using namespace std;

vector <int> V[101010], S, E;
bool chk[101010];
int n,m;

int main()
{
	int a,b,i,s,e;
	
	scanf("%d%d",&n,&m);
	
	for(i=0;i<m;i++){
		scanf("%d%d",&a,&b);
		V[a].push_back(b);
		V[b].push_back(a);
	}
	
	s = e = 1;
	chk[1] = 1;
	
	for(;;){
		for(i=0;i<V[s].size();i++){
			if(!chk[V[s][i]]) break;
		}
		if(i == V[s].size()) break;
		
		s = V[s][i];
		chk[s] = 1;
		S.push_back(s);
	}
	
	for(;;){
		for(i=0;i<V[e].size();i++){
			if(!chk[V[e][i]]) break;
		}
		if(i == V[e].size()) break;
		
		e = V[e][i];
		chk[e] = 1;
		E.push_back(e);
	}
	
	printf("%d\n",(int)(S.size() + E.size() + 1));
	
	for(i=1;i<=S.size();i++){
		printf("%d ",S[S.size()-i]);
	}
	
	printf("1 ");
	
	for(i=0;i<E.size();i++){
		printf("%d ",E[i]);
	}
	
	printf("\n");
	
	return 0;
}

Measured memory_bytes: 6904
#include<stdio.h>
/* 配列の要素を順番に出力 */
void trace(int A[], int N)
{
  for (int i=0; i < N; i++ )
  {
    if(i> 0 )printf(" "); /* 隣接する要素の間に1つの空白を出力 */
    printf("%d", A[i]);
  }
  printf("\n");
}

/* 挿入ソート(0オリジン配列)*/
void insert(int A[], int N)
{
  int j, k;
  for (int i = 1; i < N; i++ )
  {
    k = A[i];
    j = i - 1;
    while (j >= 0 && A[j] > k)
    {
      A[j + 1] = A[j];
      j--;
    }
    A[j + 1] = k;
    trace(A, N);
  }
}

int main()
{
  int N, j; 
  int A[100];

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

  return 0;

}



Measured memory_bytes: 2084
#include <cstdio>
#include <algorithm>
using namespace std;
int n,m,i,a[100100];
long long c[100100],s[100100],r;
int main() {
  scanf("%d%d",&n,&m);
  for (i=1; i<=n; i++) {
    scanf("%d",&a[i]);
    s[i]=s[i-1]+a[i];
    c[i]=c[i-1]+max(a[i],0);
  }
  for (i=1; i+m-1<=n; i++) r=max(r,c[i-1]+c[n]-c[i+m-1]+max(0LL,s[i+m-1]-s[i-1]));
  printf("%lld\n",r);
  return 0;
}


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

#define printl(s) cout << s << endl;
#define print(s) cout << s << endl; return 0;
#define yes cout << "Yes" << endl; return 0;
#define no cout << "No" << endl; return 0;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rep2(i,n) for (int i = 1; i < (n)+1; ++i)
#define birep(i,n) for (int i = 0; i < (1<<(n));i++)
using ll = long long;
using pint = pair<int, int>;

const ll modseed = pow(10,9) + 7;

template <typename T>
vector<T> getValues(ll num){
    vector<T> values(num);
    for(ll i=0;i<num;i++){
        cin >> values.at(i);
    }
    return values;
}

string S;
int N,cnt;
vector<vector<pint>> v;

bool judge(int bit){
  rep(i,N){
    if(!(bit & (1 << i))) continue;
    for(pint xy : v.at(i)){
      int x = xy.first;
      int y = xy.second;

      if(y==1 && !(bit &(1<<x))) return false;
      if(y==0 && (bit &(1<<x))) return false;
    }
  }
  return true;
}

int main(){
  cin >> N;
  v.resize(N);
  rep(i,N){
    int A; cin >> A;
    v.at(i).resize(A);
    rep(j,A){
      cin >> v.at(i).at(j).first >> v.at(i).at(j).second;
      --v.at(i).at(j).first;
    }
  }
  cnt=0;
  birep(bit,N){
    if(judge(bit)){
      int count = 0;
      rep(i,N){
        if(bit & (1 << i)) ++count;
      }
      cnt = max(cnt,count);
    }
  }
  printl(cnt);
}


Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------


string S;
int N;
const ll mo=998244353;

ll dp[303][303][303];

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>S;
	N=S.size();
	
	dp[0][0][0]=1;
	FOR(i,N) {
		FOR(x,N) FOR(y,N) if(dp[i][x][y]) {
			if(x) {
				dp[i+1][x][y]=1;
				if(S[i]=='1') dp[i+1][x-1][y+1]=1;
			}
			if(y) {
				dp[i+1][x][y]=1;
				if(S[i]=='0') dp[i+1][x+1][y-1]=1;
			}
			if(i+2<=N) {
				if(S[i]=='0') dp[i+2][x+1][y]=1;
				else dp[i+2][x][y+1]=1;
				if(S[i+1]=='0') dp[i+2][x+1][y]=1;
				else dp[i+2][x][y+1]=1;
			}
		}
	}
	
	for(i=N;i>=0;i--) {
		FOR(x,N) FOR(y,N) if(dp[i][x][y]) {
			int a=x,b=y;
			for(j=i-1;j>=0;j--) {
				if(S[j]=='0') a--;
				else b--;
				if(a>=0 && b>=0) dp[j][a][b]=0;
			}
		}
	}
	
	FOR(i,N) {
		if(S[i]=='0') {
			FOR(y,N+1) for(x=N;x>=1;x--) (dp[i][y][x-1]+=dp[i][y][x])%=mo;
		}
		else {
			FOR(y,N+1) for(x=N;x>=1;x--) (dp[i][x-1][y]+=dp[i][x][y])%=mo;
		}
		FOR(y,N+1) {
			FOR(x,N+1) (dp[i+1][x][y]+=dp[i][x][y])%=mo;
		}
	}
	for(int t=N;t>=0;t--) FOR(x,t+1) {
		y=t-x;
		if(x) (dp[N][x-1][y]+=dp[N][x][y])%=mo;
		if(y) (dp[N][x][y-1]+=dp[N][x][y])%=mo;
		
	}
	cout<<dp[N][0][0]<<endl;
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 219236
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0,i##_len=int(n);i<i##_len;++i)
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define All(x) (x).begin(),(x).end()
#define rAll(x) (x).rbegin(),(x).rend()
using namespace std;
using ll = long long;

int main(){
    int N;cin>>N;
    cout<<(1000-N%1000)%1000<<endl;
}


Measured memory_bytes: 3632
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout<<(ans)<<endl
#define STI(s) atoi(s.c_str())
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int
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;}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);};};
const ll MOD = 1000000007;
const int INF = INT_MAX;
const ll LLINF = 1LL<<62;



int main(void){

    int a,b,c,d;
    cin>>a>>b>>c>>d;
    if(a!=c)fin(1);
    else fin(0);

}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>


using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define REP(i, n) for(ll i = 0; i < n; i++)




vector<vector<ll>> g;
deque<ll> ans;
bool used[100005];

void dfs1(ll p){
    for(auto &x : g[p]){
        if(!used[x]){
            used[x] = true;
            ans.push_back(x);
            dfs1(x);
            return;
        }
    }
}

void dfs2(ll p){
    for(auto &x : g[p]){
        if(!used[x]){
            used[x] = true;
            ans.push_front(x);
            dfs2(x);
            return;
        }
    }
}

int main() {
    ll n, m;
    cin >> n >> m;
    
    g.resize(n);
    REP(i, m){
        ll a, b;
        cin >> a >> b;
        a--;b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    
    used[0] = true;
    ans.push_back(0);
    dfs1(0);
    dfs2(0);
    
    cout << ans.size() << endl;
    while(!ans.empty()){
        cout << ans.front() + 1 << ' ';
        ans.pop_front();
    }
    cout << endl;
}


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

int main()
{
    string s,t;
    cin >> s >> t;
    int ans = 100000;
    for (int i = 0; i <= s.length() - t.length(); i++)
    {
        int temp = 0;
        for (int j = 0; j < t.length(); j++)
        {
            if (s.at(i+j) != t.at(j))
            {
                temp++;
            }
            
        }
        ans = min(ans,temp);
    }
    cout << ans << endl;
}

Measured memory_bytes: 3624
import sys
N=int(input())
alist=list(map(int,input().split()))

if 0 in alist:
  print(0)
  sys.exit(0)

answer=1
e18=10**18
for a in alist:
  answer*=a
  if answer>e18:
    print(-1)
    break
else:
  print(answer)

Measured memory_bytes: 21792
#include <bits/stdc++.h>
#define rep(a,n) for (ll a = 0; a < (n); ++a)
using namespace std;
//using namespace atcoder;
using ll = long long;
typedef pair<ll,ll> P;
typedef pair<ll,P> PP;
typedef vector<vector<int> > Graph;
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 ll INF = 1e18;

// auto mod int
// depends on Template

const int mod = 1000000007;
//const int mod = 998244353;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

long long modpow(long long a, long long n) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}


int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    //input
    ll n;
    cin >> n;
    mint ans = 0;
    ans += modpow(10,n);
    ans -= modpow(9,n);
    ans -= modpow(9,n);
    ans += modpow(8,n);
    cout << ans << endl;

    return 0;
}


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

int main (){
	int H,W;
	while(true){
		cin >> H >>W;
		if(H==0 &&W==0) break;
		for(int i = 0;i<H;++i){
			for(int j=0;j<W;++j){
				cout <<"#";
			};
			cout << "\n";
		}
		cout << "\n";
	}
	return 0;
}

Measured memory_bytes: 1120
#include <iostream>
#include <math.h>

using namespace std;


int main() {
	int n, x, l[100];
	int ans = 1;
	cin >> n >> x;
	for (int i = 0; i < n; ++i) {
		cin >> l[i];
	}
	int m = 0;
	for (int i = 0; i < n; ++i) {
		m += l[i];
		if (m > x) {
			break;
		}
		++ans;
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <queue>

#include <stdio.h>
#include <math.h>
#include <stdlib.h>

using namespace std;

int n, a[100005];
vector<int> v(100005);
int main() {
	cin >> n;
	
	a[0] = 0;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
	}
	for (int i = 1; i <= n; i++) {
		v[a[i]] = i;
	}
	for (int i = 1; i <= n; i++) {
		cout << v[i] << " ";
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 1536
import java.util.Scanner;

public class Main{

	public static void main(String[] args){
		Scanner s = new Scanner(System.in);
		int w=s.nextInt();
		int n=s.nextInt();
		int[] values = new int[w];
		for(int i=0;i<values.length;i++){
			values[i]=i+1;
		}
		for(int i=0;i<n;i++){
			String str =s.next();
			String[] ab=str.split(",");
			int a = Integer.parseInt(ab[0])-1;
			int b = Integer.parseInt(ab[1])-1;

			int x =values[a];
			values[a]=values[b];
			values[b]=x;

		}
		for(int i=0;i<values.length;i++){
			System.out.println(values[i]);
		}
	}
}

Measured memory_bytes: 26188
#include<bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define pii pair<int, int>
#define pll pair<long long , long long>
#define pb push_back
#define ll long long
#define ld long double
#define precision(x,d) cout<<fixed<<setprecision(d)<<x
#define fill(a,b) memset((a),(b),sizeof((a)))
#define FAST ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);srand(time(NULL));
ll power(ll x,ll y,ll m){ll r=1;for(;y;y>>=1){if(y&1)r=r*x%m;x=x*x%m;}return r;}
const ll mod = 1e9 + 7;
const ld pi = 3.14159265358979;
    
int run_test(){
    int n;
    cin >> n;
    int arr[n], count[n + 1];
    for(int i=0; i<n + 1; i++){
        count[i] = 0;
    }
    for(int i=0; i<n-1; i++){
        cin >> arr[i];
        count[arr[i]]++;
    }
    for(int i=1; i<=n; i++){
        cout << count[i] << "\n";
    }
    return 0;
}
    
int main(){
   FAST;
    ll t;
    t = 1;
     
    while(t--){
        run_test();
    }
}

Measured memory_bytes: 5176
fun main(args:Array<String>):Unit{
    while (true){
        val (n, m, s, t1, t2) = readLine()!!.split(' ').map(String::toInt)
        if (n == 0 && m == 0 && s == 0 && t1 == 0 && t2 == 0) break
        val minCost = Array(n){from -> Array(n){to -> if (from == to) 0 else Int.MAX_VALUE.toLong()}}
        repeat(m){
            val (b1, b2, c) = readLine()!!.split(' ').map(String::toInt)
            if (minCost[b1 - 1][b2 - 1] > c){
                minCost[b1 - 1][b2 - 1] = c.toLong()
            }
        }
        for (mid in 0 until n) for (from in 0 until n) for (to in 0 until n){
            if (minCost[from][to] > minCost[from][mid] + minCost[mid][to])
                minCost[from][to] = minCost[from][mid] + minCost[mid][to]
        }
        println((0 until n).map{mid ->
            minCost[s - 1][mid] + minCost[mid][t1 - 1] + minCost[mid][t2 - 1]
        }.min()!!)
    }
}


Measured memory_bytes: 75204
import sys
# from collections import defaultdict, deque
# import math
# import copy
# from bisect import bisect_left, bisect_right
# import heapq

# sys.setrecursionlimit(1000000)

# input aliases
input = sys.stdin.readline

getS = lambda: input().strip()
getN = lambda: int(input())
getList = lambda: list(map(int, input().split()))
getZList = lambda: [int(x) - 1 for x in input().split()]

INF = 10 ** 20
MOD = 1000000007


class Segtree_op():
    def __init__(self, n):
        self.size = 1
        while (n >= 1):
            self.size = self.size << 1
            n = n // 2

        self.arr = [self.unit() for i in range(self.size * 2)]

    def op(self, lch, rch):
        # update min with holding index
        return max(lch, rch)

    def unit(self):
        return -INF

    def update(self, k, val):
        k += self.size - 1
        self.arr[k] = val
        while (k):
            k = (k - 1) // 2
            self.arr[k] = self.op(self.arr[k * 2 + 1], self.arr[k * 2 + 2])

    def query(self, l, r):
        L = l + self.size
        R = r + self.size
        s = self.unit()
        while L < R:
            if R & 1:
                R -= 1
                s = self.op(s, self.arr[R - 1])

            if L & 1:
                s = self.op(s, self.arr[L - 1])
                L += 1
            L >>= 1
            R >>= 1
        return s

    def show(self):
        idx = 1
        while (idx <= self.size):
            print(self.arr[idx - 1:idx * 2 - 1])
            idx *= 2


def solve():
    n, m = getList()
    baito = []
    for i in range(n):
        a, b = getList()
        baito.append((b, a))

    baito.sort(reverse=True)
    st = Segtree_op(m)
    for i in range(m):
        st.update(i, i)

    ans = 0
    for kin, hi in (baito):
        if hi > m:
            continue
        tgt = st.query(0, m - hi + 1)
        if tgt != -INF:
            ans += kin
            st.update(tgt,-INF)

    # st.show()
    # st.update(0, -10)
    # print(st.query(0, 1))
    print(ans)

def main():
    n = getN()
    for _ in range(n):
        solve()
if __name__ == "__main__":
    # main()
    solve()


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


int main(){
	int i, j, n, m, k;
	int ans = 0;
	int kuro;

	scanf("%d%d%d", &n, &m, &k);

	
	for (i = 0; i <= n; i++) {
		for (j = 0; j <= m; j++) {
			kuro = m*i + n*j - i*j*2;
			if (kuro == k) break;
		}
		if (kuro == k) break;
	}
	
	printf("%s\n", (i == n+1 && j == m+1) ? ("No") : ("Yes"));
	
	return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize ("Ofast")
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
 
using namespace __gnu_pbds;
using namespace std;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key
 
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
 
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<long long,long long> ii; 	
typedef complex<long double> com;

const ll mod = 1e9+7;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
    ll n,m,k;
    cin >> n >> m >> k;
    vector <vector<ll>> grid(n,vector<ll>(m,0));
    vector <ll> cost(n);
    for (int z=0;z<n;z++){
        cin >> cost[z];
        for (int x=0;x<m;x++){
            cin >> grid[z][x];
        }
    }
    ll ans = LLONG_MAX;
    for (int z=1;z<(ll(1) << n);z++){
        ll temp = 0;
        vector <ll> skill(m);
        for (int x=0;x<n;x++){
            if (z & ll(1) << x){
                temp += cost[x];
                for (int y=0;y<m;y++){
                    skill[y] += grid[x][y];
                }
            }
        }
        bool ok = true;
        for (int x=0;x<m;x++){
            if (skill[x] < k) ok = false;
        }
        if (ok){
            ans = min(ans,temp);
        }
    }
    if (ans == LLONG_MAX) cout << -1 << endl;
    else cout << ans << endl;
} 

Measured memory_bytes: 3656
// ----- In the name of ALLAH, the Most Gracious, the Most Merciful -----

#include<bits/stdc++.h>
using namespace std;

#define NINJA ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define fo(i,n) for(int i=0;i<n;i++)
#define Fo(i,k,n) for(int i=k;i<n;i++)
#define for1(i,n) for(int i=1;i<=n;i++)
#define dloop(i,n) for(int i=n-1;i>=0;i--)
#define iii tuple<int,int,int>
#define vi vector<int>
#define ii pair<int,int>
#define vii vector<ii>
#define int long long
#define pb push_back
#define endl "\n"
#define setbits __builtin_popcountll
#define mp map<int,int>
#define F first
#define S second
#define sz(v) (int)v.size()
#define mod 1000000007
#define inf (int)1e18

const int mxn = 3010;
int dp[mxn][mxn];

int32_t main(){
	NINJA;

	string a,b; cin >> a >> b;
	int n = sz(a);
	int m = sz(b);

	for(int i=0;i<=n;i++){
		for(int j=0;j<=m;j++){
			if(i==0 || j==0) dp[i][j] = 0;
			else if(a[i-1]==b[j-1]) dp[i][j] = dp[i-1][j-1] +1;
			else dp[i][j] = max(dp[i-1][j],dp[i][j-1]);
		}
	}

	string ans = "";
	int i=n,j=m;
	while(i>0 && j>0){
		if(a[i-1]==b[j-1]){
			ans += a[i-1];
			i--;
			j--;
		}else if(dp[i][j-1] > dp[i-1][j]){
			j--;
		}else i--;
	}

	reverse(ans.begin(), ans.end());
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 70912
n,m=map(int,input().split())
xy = [ list(map(int,input().split())) for _ in range(m) ]

ans=0
jagh=[0]*n#あかがはいった事あるかどうか
jagh[0]=1
now=[1]*n#ボールの個数
for i in range(m):
    if jagh[xy[i][0]-1]==1:
        jagh[xy[i][1]-1]=1
        now[xy[i][0]-1]-=1
        if now[xy[i][0]-1]==0:
            jagh[xy[i][0]-1]=0
        now[xy[i][1]-1]+=1
    else:
        now[xy[i][0]-1]-=1
        if now[xy[i][0]-1]==0:
            jagh[xy[i][0]-1]=0
        now[xy[i][1]-1]+=1

#print(jagh,now)
for i in range(n):
    if jagh[i]==1 and 0<now[i]:
        ans+=1
print(ans)

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

int main(){
  ll N;
  string S;
  cin >> N >> S;  
  int cnt = 1;
  char pre = S[0];
  for(int i=1; i<N; i++){
    if(pre==S[i]) continue;
    else{
      pre = S[i];
      cnt ++;
    }
  
  }
  
  cout << cnt << endl;
  
  
  return 0;
}

Measured memory_bytes: 3748
import java.util.*;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] v = new int[n];
        int[] c = new int[n];
        int cnt = 0;

        for(int i = 0;i<n;i++){
            v[i] = sc.nextInt();
        }
        for(int i = 0;i<n;i++){
            c[i] = sc.nextInt();
        }
        
        for(int i = 0;i<n;i++){
            if(v[i]-c[i]>0){
                cnt+=(v[i]-c[i]);
            }
        }

        System.out.println(cnt);
        
    }
}


Measured memory_bytes: 21716
#include<bits/stdc++.h>
using namespace std;
int b[30];
int main(){
	int n, m, c, ans1 = 0;
	cin >> n >> m >> c;
	for(int i = 0; i < m; i++)
		cin >> b[i];
	for(int i = 0; i < n; i++){
		int ans = 0;
		for(int j = 0; j < m; j++){
			int x;
			cin >> x;
			ans += x * b[j];
			
		}
		if(ans + c > 0)
			ans1 ++;
	}
	cout << ans1;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <unordered_map>
#include <utility>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <cstdio>
#include <math.h>
#include <stdio.h>

using namespace std;

#define REP(i,n,m) for( long long int i = (n); i < (m); i++ )
#define ll long long
#define ALL(a) (a).begin(), (a).end()
#define SORT(v) sort( ALL(v) );
#define LAST(v) v[v.size()-1]
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,-1,sizeof(a))
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define pi pair<int, int>
#define MP make_pair
#define PB push_back
#define IIN(a) int a; cin >> a;
#define LIN(a) ll a; cin >> a;
#define SIN(a) string a; cin >> a;
#define EPS (1e-10)
#define INF 1000000000000LL

int MOD=1000000007;
int dx[4] = {0, 0, -1, 1};
int dy[4] = {1, -1, 0, 0};
//I ASCII code: '0' = 48; 'A' = 65; 'a' = 97


ll func(ll a){
  ll deq = a + 1;
  deq /= 2;
  if( deq % 2 == 1 && a % 2 == 0 )return a ^ 1;
  else if ( deq % 2 == 1 && a % 2 == 1 ) return 1;
  else if( deq % 2 == 0 && a % 2 == 0 ) return a;
  else return 0 ;
}
signed main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    LIN(a)
    LIN(b)
    ll ans = 0;

  
    ans = func(a - 1)^func(b);

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
# https://atcoder.jp/contests/abc162/tasks/abc162_c
from math import gcd

K = int(input())

ans = 0

for i in range(1, K + 1):
    for j in range(1, K + 1):
        for k in range(1, K + 1):
            ans += gcd(gcd(i, j), k)

print(ans)


Measured memory_bytes: 67768
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        n: usize,
    }
    println!("{}", n / 3);
}


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

int main() {
	string str;
	int m, h;
    
	while(cin >> str,str != "-"){
		cin >> m;
		for (int i = 0; i < m; ++i) {
			cin >> h;
			str.append(str.substr(0, h)).erase(0, h);
		}
		cout << str << endl;
	}
    
	return 0;
}

Measured memory_bytes: 1228
f = lambda :[int(i) for i in input().split()]
from sys import stderr
f = lambda :[int(i) for i in input().split()]
from functools import reduce
from operator import add
debug = lambda *x:stderr.write(reduce(add,repr(x))+'\n')

num = int(input())
a = f()
a.sort()
# Pascalの三角形を思うと、nは大きく、rはn/2に近いほうがいい
n = a[-1]
half = int(n/2)
r = a[0]
for po in a:
    if abs(half - po) < abs(half - r) or (r == half - 1 and po == r + 2):
        r = po
print(n,r)

Measured memory_bytes: 14556
def resolve():
    s = input()
    rs = s[::-1]
    if rs != s:
        print("No")
        exit()
    
    if len(s) == 3:
        print("Yes")
        exit()
    s1 = s[:((len(s)-1)//2)]
    s2 = s[((len(s)+3)//2)-1:]
    rs1 = s1[::-1]
    rs2 =s2[::-1]
    if s1 == rs1 and s2 == rs2:
        print("Yes")
    else:
        print("No")
resolve()

Measured memory_bytes: 38460