akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
/*#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
/*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<ll,ll> pl;
typedef pair<int,int> pii;

#define int ll
#define LOCAL 0
#define dbg(x) cout << #x << " is " << x << "\n"
#define gll(x) scanf("%d",&x)
#define gll2(x,y) scanf("%d%d",&x,&y)
#define gll3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define gllarr(arr,n) f(i,n) gll(arr[i]);
#define sz(x) ((int)x.size())
#define s(x) sort(x.begin(),x.end())
#define all(v) v.begin(),v.end()
#define rs(v) { s(v) ; r(v) ; }
#define r(v) {reverse(all(v));}
#define pb push_back
#define f(i,n) for(int i=0;i<n;i++)
#define fr(i,n) for(int i=n-1;i>=0;i--)
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define repr(i,a,b) for(int i=a;i>=b;i--)

const ll mod = (ll)1e9 + 7;
const ll inf = (ll)1e16;
const ld eps = 1e-12;
const ll N = (int)1e5 + 5;
const ll LOGN = 19;
const ld PI = 3.14159265358979323846;
inline ll mul(ll a, ll b, ll m = mod) { return (ll)(a * b) % m;}
inline ll add(ll a, ll b, ll m = mod) { a += b; if(a >= m) a -= m; if(a < 0) a += m; return a;}
inline ll power(ll a, ll b, ll m = mod) { if(b == 0) return 1; if(b == 1) return (a % m); ll x = power(a, b / 2, m); x = mul(x, x, m); if(b % 2) x = mul(x, a, m); return x;}

int n, to;
map< pair<int, int>, int> edges;
int ans[N];
vector<int> adj[N];

void dfs(int src = 0, int par = -1, int col = 0) {
    int curr = 1;
    for(int u: adj[src]) {
        if(u == par) continue;
        if(curr == col) curr++;
        ans[edges[{u, src}]] = curr;
        to = max(to, curr);
        dfs(u, src, curr);
        curr++;
    }
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    if (LOCAL) {
        freopen("C:\\Users\\Dishant\\Desktop\\Collection-DEV c++\\input.txt", "r", stdin);
        freopen("C:\\Users\\Dishant\\Desktop\\Collection-DEV c++\\output.txt", "w", stdout);
    }
    cin>>n;
    f(i, n - 1) {
        int u, v;
        cin>>u>>v;
        u--, v--;
        adj[u].pb(v);
        adj[v].pb(u);
        edges[{u, v}] = i;
        edges[{v, u}] = i;
    }
    dfs();
    cout<<to<<"\n";
    f(i, n - 1) cout<<ans[i]<<'\n';
    return 0;
}

Measured memory_bytes: 19840
n, k = map(int, input().split())
h = list(map(int, input().split()))

h.sort(reverse = True)

if k > n:
  k = n

for i in range(k):
  h[i] = 0

ans = 0
for i in range(n):
  ans += h[i]
  
print(ans)
  

Measured memory_bytes: 26764
#include <iostream>
#include <string>
#include <stdlib.h>

#define INC(i, a, b) for(int (i) = (a); (i) < (b); ++(i))
#define DEC(i, a, b) for(int (i) = (a); (i) > (b); --(i))
#define REP(i, n)    INC(i, 0, n)
#define comp(a, b) int comp(const void *(a), const void *(b))

typedef unsigned int uint;
typedef unsigned long ul;
typedef long long  ll;
typedef unsigned long long ull;

const int MOD = 1e9 + 7;

using namespace std;

void TFprint(bool b, std::string T, std::string F){
    if(b){
        cout << T << endl;
    }else{
        cout << F << endl;
    }
}

int abs(int x){
    return x > 0? x : -x;
}

int max(int a, int b){
    return a > b? a : b;
}

int min(int a, int b){
    return a < b? a : b;
}


int main(){
    int n; cin >> n;
    char direct[n]; cin >> direct;
    int numE = 0;

    for(int i = 0; i < n; ++i) {
        if(direct[i] == 'E') numE++;
    }
    int numW = n - numE;
    int ans = numE - (direct[0] == 'E'? 1 : 0);
    int ret = numE - (direct[0] == 'E'? 1 : 0);

    for(int leader = 1; leader < n; ++leader) {
        if(direct[leader] == 'E') ret--;
        if(direct[leader - 1] == 'W') ret++;
        if(ret < ans) ans = ret;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 512
<?php 
  fscanf(STDIN,"%d", $n);
  $cnt=0;

  for($i=0;$i<$n;$i++){
    fscanf(STDIN,"%d %d",$d_1,$d_2);
    if($d_1==$d_2){
      $cnt++;
    }else{
      $cnt=0;
    }
    if($cnt>=3) break;
  }

  if($cnt>=3){
    echo "Yes\n";
  }else{
    echo "No\n";
  }


Measured memory_bytes: 16280
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n,u,l;
    cin>>n>>l>>u;
    int p[n]={};
    int bg=0,al=0,m=0;
    for(int i=0;i<n;i++)
    {
        cin>>p[i];
        if(p[i]>u)
        bg++;
        else if(p[i]<=l)
        al++;
        else
        m++;
    }
    cout<<min({bg,al,m})<<endl;
}

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

int main() {
    int n, idtmp;
    string tmp;

    cin >> n;
    vector<int> id(n);
    vector<string> s(n);
    vector<int> p(n);
    for(int i = 0; i < n; i++) {
        id[i] = i;
        cin >> s.at(i);
        cin >> p.at(i);
    }

    rep(i, n) {
        rep(j, n) {
            if(i == j)
                break;
            if(s[i] < s[j]) {
                idtmp = id[i];
                id[i] = id[j];
                id[j] = idtmp;
                tmp = s[i];
                s[i] = s[j];
                s[j] = tmp;
                idtmp = p[i];
                p[i] = p[j];
                p[j] = idtmp;
            }
        }
    }

    rep(i, n) {
        for(int j = i + 1; j < n; j++) {
            if(i == j or s[i] != s[j])
                break;
            if(s[i] == s[j] and p[i] < p[j]) {
                idtmp = id[i];
                id[i] = id[j];
                id[j] = idtmp;
                idtmp = p[i];
                p[i] = p[j];
                p[j] = idtmp;
            }
        }
    }
    rep(i, n) cout << id[i] + 1 << endl;
    return 0;
}

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

string s;

int main(){

    cin >> s;
    map<string, int> week;
    
    week["SUN"] = 7;
    week["MON"] = 6;
    week["TUE"] = 5;
    week["WED"] = 4;
    week["THU"] = 3;
    week["FRI"] = 2;
    week["SAT"] = 1;
    
    cout << week[s] << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FI first
#define SE second
#define EPS 1e-9
#define ALL(a) a.begin(),a.end()
#define SZ(a) int((a).size())
#define MS(s, n) memset(s, n, sizeof(s))
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORE(i,a,b) for (int i = (a); i >= (b); i--)
#define FORALL(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
#define WHATIS(x) cout << #x << " is " << x << endl;
#define ERROR(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
//__builtin_ffs(x) return 1 + index of least significant 1-bit of x
//__builtin_clz(x) return number of leading zeros of x
//__builtin_ctz(x) return number of trailing zeros of x

using namespace std;
using ll = long long;
using ld = double;
typedef pair<int, int> II;
typedef pair<II, int> III;
typedef complex<ld> cd;
typedef vector<cd> vcd;

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cout << *it << " = " << a << endl;
    err(++it, args...);
}

const ll MODBASE = 1000000007LL;
const int MAXN = 510;
const int MAXM = 35;
const int MAXK = 510;
const int MAXQ = 200010;

// class ReconstructNumber {
// public:
//     string smallest(string);
// };

// string ReconstructNumber::smallest(string s) {
// }

int f[50];

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    string s;
    cin >> s;
    FOR(i,0,SZ(s)-1) f[s[i]-'A']++;
    FOR(i,0,25)
        if (f[i]) {
            if (f[i] != 2) {
                cout << "No";
                return 0;
            }
        }
    cout << "Yes";
    return 0;
}

Measured memory_bytes: 764
#include <cstdio>
#include <iostream>
#include <vector>
#include <string>
#include <utility>
using namespace std;

int main(){
	int num=0,d=0,ans=0;
	cin>>num>>d;
	ans=num/(2*d+1);
	if(num%(2*d+1)!=0){
		ans++;
	}
	cout<<ans;
	return 0;
}

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

#define REP(i,num) for(int i=0;i<(num);++i)
#define LOOP(i) while(i--)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto pitr=c.begin();pitr!=c.end();++pitr){cout<<*pitr;if(next(pitr,1)!=c.end())cout<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

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

	ll A=in<ll>(),B=in<ll>(),K=in<ll>();

	ll C = max(0LL,K-A);
	ll D = max(0LL,A-K);
	ll E = max(0LL,B-C);
	out(D,E);
	return 0;
}


Measured memory_bytes: 256
#[allow(unused_macros)]
macro_rules! scan {
    () => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().to_string()
        }
    };
    (;;) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().split_whitespace().map(|s| s.to_string()).collect::<Vec<String>>()
        }
    };
    (;;$n:expr) => {
        {
            (0..$n).map(|_| scan!()).collect::<Vec<_>>()
        }
    };
    ($t:ty) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty;;) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
    ($t:ty;;$n:expr) => {
        (0..$n).map(|_| scan!($t;;)).collect::<Vec<_>>()
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
                    scan!($t)
        ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
                    scan!($($t),*)
        ).collect::<Vec<_>>()
    };
}

fn main() {
    let s = scan!();
    println!("{}", s.replace(",", " "))
}


Measured memory_bytes: 4352
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <cstdio>
#include <string>
#include <cmath>
#include <queue>
#include <tuple>
#include <set>
#include <assert.h>
#include <sstream>
#include <string>
//#include <bits/stdc++.h>
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repr(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i,i0,n) for(int (i)=(i0);(i)<(n);(i)++)
#define FORR(i,i0,n) for(int (i)=(n)-1; (i)>=(i0);(i)--)
#define SORT(x) sort(x.begin(),x.end())
#define rn return
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
typedef std::pair<int,int> P;
using namespace std;
using ll = long long;


int main(){
    int n;
    vector<P> xy;
    cin >> n;
    rep(i,n){
        int x,y; cin >> x >> y;
        xy.pb(P(x,y));
    }
    vector<int> ind;
    rep(i,n){
        ind.pb(i);
    }
    auto dist = [&](int i, int j){
        double dx = xy[i].first-xy[j].first ;
        double dy = xy[i].second-xy[j].second;
        return sqrt(dx*dx+dy*dy);
    };
    double ans = 0;
    int cnt = 0;
    do{
        rep(i,n-1){
            ans += dist(ind[i],ind[i+1]);
        }
        cnt ++;
    } while (next_permutation(ind.begin(), ind.end()));
    printf("%.10f",ans/cnt);
}


Measured memory_bytes: 888
#include<iostream>
using namespace std;
#define int long long
#define rep(i,N) for(int(i)=0;(i)<(N);(i)++)

const int MOD = 1e9+7;
signed main(){
    int N;
    cin >> N;
    
    int dp[110][4][4][4];
    int A=0, G=1, C=2, T=3;

    rep(a,4)rep(b,4)rep(c,4) dp[3][a][b][c] = 1;

    dp[3][A][G][C] = 0;
    dp[3][A][C][G] = 0;
    dp[3][G][A][C] = 0;

    for(int i=4;i<=N;i++){
        rep(a,4)rep(b,4)rep(c,4)rep(d,4){
            if(b == A && c == G && d == C) continue;
            if(b == A && c == C && d == G) continue;
            if(b == G && c == A && d == C) continue;
            if(a == A && c == G && d == C) continue;
            if(a == A && b == G && d == C) continue;
            (dp[i][b][c][d] += dp[i-1][a][b][c]) %= MOD;
        }
    }

    int ans = 0;
    rep(a,4)rep(b,4)rep(c,4){
        (ans += dp[N][a][b][c]) %= MOD;
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/multi_array.hpp>
#include <boost/range/algorithm.hpp>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;

int main() {
  int a, b, ans;
  cin >> a >> b;
  ans = a * b;
  if ((a > 9) || (b > 9)) ans = -1;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<sstream>
using namespace std;
typedef  long long int lint;
typedef pair<int, int> IP;
typedef pair<lint, lint> LLP;
typedef pair<char, char>CP;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define sort(v) sort((v).begin(), (v).end())
#define reverse(v) reverse((v).begin(), (v).end())
#define upper(v,hoge) upper_bound(v.begin(),v.end(),hoge)
#define lower(v,hoge) lower_bound(v.begin(),v.end(),hoge)
#define llower(v,hoge) *lower_bound(v.begin(), v.end(), hoge)
#define lupper(v,hoge) *upper_bound(v.begin(), v.end(), hoge)
const lint MOD = pow(10, 9) + 7;

int main() {
	int N;
	cin >> N;
	vector<string>S(N);
	rep(i, N) {
		cin >> S[i];
	}
	sort(S);
	int cnt = 1;
	int M = 0;
	for (int i = 1; i < N; i++) {
		if (S[i] != S[i - 1]) {
			M = max(M, cnt);
			cnt = 1;
		}
		else {
			cnt++;
		}
	}
	M = max(M, cnt);
	cnt = 1;

	if (M == 1) {
		cout << S[0] << endl;
	}
	for (int i = 1; i < N; i++) {
		if (S[i] != S[i - 1]) {
			M = max(M, cnt);
			cnt = 1;
		}
		else {
			cnt++;
		}
		if (cnt == M) {
			cout << S[i] << endl;
		}
	}
}


Measured memory_bytes: 14208
#include "bits/stdc++.h"
#define MOD 1000000007
#define INF 11234567890
#define in std::cin
#define out std::cout
#define rep(i,N) for(int i=0;i<N;++i)
typedef long long int LL;
 
std::string A;
LL ans;
 
int main()
{
	in >> A;
 
	auto n = A.length() - 1;
	ans = (1 + n)*n / 2;
	std::sort(A.begin(), A.end());
	rep(i, A.length())
	{
		int j;
		for (j = i; j < A.length(); ++j)
		{
			if (A[j] != A[i]) { break; }
		}
		LL tmp = (j - i)*LL(j - i - 1) / 2;
		ans -= tmp;
		i = (j - 1);
	}
 
	out << ans + 1 << std::endl;
	return 0;
}

Measured memory_bytes: 640
/*____________________________Definitions__________________________*/
#include <bits/stdc++.h>
using namespace std;
#define fastIO ios_base::sync_with_stdio(0); cin.tie(0);
typedef long long ll;
typedef vector<int> vi;
#define Rep(i, a, b) for (int i=a; i<(b); i++)
#define trav(a,x) for(auto& a : x)
#define nl '\n'
#define ri(n) int n; scanf("%d", &n);
#define rll(n) ll n; scanf("%lld", &n);
/*__________________________________________________________________*/


int main() {

	fastIO
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	int T = 1;
	while (T--) {
		/*_____________________Code Here____________________________*/

		int n, x , t ; cin >> n >> x >> t;
		cout << t*((n + x - 1) / x);




		/*_____________________End Here____________________________*/
	}
	return 0;
}



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

#define int long long
#define ff first
#define ss second
#define endl "\n"
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x.size())
int powmod(int a,int l, int md){a%=md; int res=1;while(l){if(l&1)res=res*a%md;l/=2;a=a*a%md;}return res;}
int binpow(int a,int l){int res=1;while(l){if(l&1)res=res*a;l/=2;a=a*a;}return res;}
int invmod(int a, int md){return powmod(a,md-2,md);}
typedef long long ll; typedef unsigned long long ull; typedef long double ld;
typedef vector<int> vi; typedef pair<int, int> ii; typedef vector< ii > vii;
#define pb push_back
int __set(int b, int i) {return b|(1LL<<i);} //set ith bit
int __unset(int b, int i) {return b&(~(1UL<<i));}
int __check(int b, int i) {return b&(1LL<<i);} //returns 0 if ith bit is 0
int mulmod(int a, int b, int md) {return (((a%md)*(b%md))%md+md)%md;}
int addmod(int a, int b, int md) {return ((a%md+b%md)%md+md)%md;}
int submod(int a, int b, int md) {return (((a%md-b%md)%md)+md)%md;}
int divmod(int a, int b, int md) {return mulmod(a, powmod(b, md-2, md), md);} //if md is prime;
const ll inf = 0xFFFFFFFFFFFFFFFL; //very large number
priority_queue<int, vector<int>, greater<int> > pq; //for min priority_queue
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int MOD = 1e9+7;
const int MX = 400010;

int f[MX];
int rf[MX];

int C(int l,int k, int md) 
{
    if (k<0||k>l){
        return 0;
    }
    return f[l]*rf[k]%md*rf[l-k]%md;
}

void precfac() {
    f[0]=1;
    for (int i=1;i<MX;i++){
        f[i]=f[i-1]*i%MOD;
    }
    rf[MX-1]=powmod(f[MX-1],MOD-2, MOD);
    for (int i=MX-2;i>=0;i--){
        rf[i]=rf[i+1]*(i+1)%MOD;
    }
}
signed main(void)
{
	IOS;
	int a,b,c,d; cin>>a>>b>>c>>d;
	if(b >= d) {
		swap(a,c);
		swap(b,d);
	}
	cout<<max({a*c,a*d,b*c,b*d})<<endl;
	return 0;
}

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

using namespace std;

int main()
{
    string  N;
    cin >> N;

    if (N.find('7') == string::npos)
        cout << "No\n";
    else
        cout << "Yes\n";
    return 0;
}

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

int par[100010],N,M; bool used[100010];

void Initialize(){
	for(int i=0; i<=N; i++){
		par[i]=i;
	}
}

int FindPar(int x){
	if(par[x]==x){
		return x;
	}else{
		par[x]=FindPar(par[x]);
		return par[x];
	}
}

void Join(int a, int b){
	int RepA=FindPar(a),RepB=FindPar(b);
	par[RepA]=RepB;
}

int main(){
	cin>>N>>M;
	Initialize();
	for(int i=0; i<M; i++){
		int a,b;
		cin>>a>>b;
		Join(a,b);
	}
	int total=0;
	for(int i=1; i<=N; i++){
		if(!used[FindPar(i)]){
			used[FindPar(i)]=true;
			total++;
		}
	}
	cout<<total-1<<'\n';
}

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

using namespace std;

int main()
{
	int n;
	cin>>n;
	int a[n];
	for(int i=0; i<n; i++)
	{
		cin>>a[i];
	}
	double ans =0;
	for(int i=0; i<n; i++)
	{
		ans += 1.0/a[i];
	}
	cout<<1.0/ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)  for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define pb emplace_back
#define eb emplace_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define ub(v,k) (upper_bound(all(v),k)-v.begin())
#define fi first
#define se second
#define pi M_PI
#define PQ(T) priority_queue<T>
#define SPQ(T) priority_queue<T,vector<T>,greater<T>>
#define dame(a) {out(a);return 0;}
#define decimal cout<<fixed<<setprecision(15);
#define dupli(a) a.erase(unique(all(a)),a.end())
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> PP;
typedef tuple<ll,ll,ll,ll> PPP;
typedef multiset<ll> S;
using vi=vector<ll>;
using vvi=vector<vi>;
using vvvi=vector<vvi>;
using vvvvi=vector<vvvi>;
using vp=vector<P>;
using vvp=vector<vp>;
using vb=vector<bool>;
using vvb=vector<vb>;
const ll inf=1001001001001001001;
const ll INF=1001001001;
const ll mod=1000000007;
const double eps=1e-10;
template<class T> bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<class T> bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<class T> void out(T a){cout<<a<<'\n';}
template<class T> void outp(T a){cout<<'('<<a.fi<<','<<a.se<<')'<<'\n';}
template<class T> void outvp(T v){rep(i,v.size())cout<<'('<<v[i].fi<<','<<v[i].se<<')';cout<<'\n';}
template<class T> void outvvp(T v){rep(i,v.size())outvp(v[i]);}
template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<'\n';}
template<class T> void outvv(T v){rep(i,v.size())outv(v[i]);}
template<class T> bool isin(T x,T l,T r){return (l)<=(x)&&(x)<=(r);}
template<class T> void yesno(T b){if(b)out("yes");else out("no");}
template<class T> void YesNo(T b){if(b)out("Yes");else out("No");}
template<class T> void YESNO(T b){if(b)out("YES");else out("NO");}
template<class T> void noyes(T b){if(b)out("no");else out("yes");}
template<class T> void NoYes(T b){if(b)out("No");else out("Yes");}
template<class T> void NOYES(T b){if(b)out("NO");else out("YES");}
void outs(ll a,ll b){if(a>=inf-100)out(b);else out(a);}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll modpow(ll a,ll b){ll res=1;a%=mod;while(b){if(b&1)res=res*a%mod;a=a*a%mod;b>>=1;}return res;}
int main(){
    ll n,m;cin>>m>>n;
    vvi v(n,vi(m));
    rep(i,n)rep(j,m)cin>>v[i][j];
    vi a,b;
    rep(i,m){
        if(v[0][i])b.pb(i);
        else a.pb(i);
    }
    if(abs((ll)(a.size())-(ll)(b.size()))>1)dame("no");
    ll c=0,d=0;
    rep(i,n){
        ll k=-1;
        rep(j,m){
            if(v[i][j]==v[0][j]){
                if(k==1)dame("no");
                k=0;
            }
            else{
                if(k==0)dame("no");
                k=1;
            }
        }
        if(k)c++;
        else d++;
    }
    yesno(abs(c-d)<2);
}


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

int main(){
  int n, b, c, i, j;
  int a=0;
  cin >> n;
  b=n;
  if(n!=0){
    for(i=7;i>0;i--){
    j=pow(10, i);
    a+=b/j;
    c=b%j;  
    b=c;
     }
     a+=c%10;
     if(n%a==0){
       cout << "Yes" << endl;
     }
     else{
       cout << "No" << endl;
     }
  }
  else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cmath>
#include <queue>
#include <vector>
#include <set>
#include <algorithm>
#include <functional>
using namespace std;

const int INF = 1<<28;

struct edge_t {
    int from, to;
    double cost;
    edge_t(int from, int to, double cost) : from(from), to(to), cost(cost) {}
    bool operator<(const edge_t &o) const {
        return (cost < o.cost);
    }
    bool operator>(const edge_t &o) const {
        return (cost > o.cost);
    }
};
struct state_t {
    int v;
    double min_cost;
    state_t(int v, double min_cost) : v(v), min_cost(min_cost) {}
    bool operator<(const state_t &o) const {
        return (min_cost < o.min_cost);
    }
    bool operator>(const state_t &o) const {
        return (min_cost > o.min_cost);
    }
};
typedef vector<edge_t> vertex_t;
struct graph_t {
    vector<vertex_t> g;

    graph_t() {}

    graph_t(int vertex_count) {
        g.resize(vertex_count);
    }
    graph_t(vector<vertex_t> g) : g(g) {}

    inline vertex_t& operator[](int index) {
        return g[index];
    }

    inline void push_back(vertex_t v) {
        g.push_back(v);
    }

    inline void add_edge(int from, int to, double cost) {
        g[from].push_back(edge_t(from, to, cost));
    }

    double prim() {
        bool used[g.size()];
        double min_span_cost = 0;
        priority_queue< edge_t, vector<edge_t>, greater<edge_t> > q;

        fill(used, used+g.size(), false);

        used[0] = true;
        for (int i = 0; i < g[0].size(); i++) {
            q.push(g[0][i]);
        }

        while (!q.empty()) {
            edge_t e = q.top(); q.pop();
            if (used[e.to]) continue;
            used[e.to] = true;
            min_span_cost += e.cost;
            for (int i = 0; i < g[e.to].size(); i++) {
                q.push(g[e.to][i]);
            }
        }

        return min_span_cost;
    }
};

struct Point {
    double x, y, z;
    Point() {}
    Point(double x, double y, double z) : x(x), y(y), z(z) {}
    double distance (const Point &o) const {
        return sqrt((x - o.x) * (x - o.x) + (y - o.y) * (y - o.y) + (z - o.z) * (z - o.z));
    }
};

int main() {
    int n; 
    while (cin >> n) {
        if (n == 0) break;
        double rs[n];
        Point ps[n];
        graph_t graph(n);
        for (int i = 0; i < n; i++) {
            cin >> ps[i].x >> ps[i].y >> ps[i].z >> rs[i];
        }
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                if (i == j) continue;
                double distance = ps[i].distance(ps[j]);
                double cost = 0;
                if (distance > rs[i] + rs[j]) cost = distance - rs[i] - rs[j];
                graph.add_edge(i, j, cost);
            }
        }
        printf("%.3f\n", graph.prim());
    }
    return 0;
}

Measured memory_bytes: 1592
#include "bits/stdc++.h"

using namespace std;

//int N,M,K,L,R,H,W;
long long int N,M,K,L,R,H,W;

constexpr long long int MOD=1000000007;
//constexpr  int MOD=1000000007;
//constexpr int MOD=998244353;
//constexpr long long int MOD=998244353;

constexpr long double EPS=1e-8;

struct Edge{
	int to;
	long long int cost;
	Edge(const int tt,const long long int cc){
		to=tt,cost=cc;
		return;
	}	
};

struct Node{
	int node,nx,goal;
	Node(const int no,const int nnx,const int go){
		node=no,nx=nnx,goal=go;
		return;
	}
	bool operator<(const Node&n)const{
		return node<n.node;
	}
};

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	cin>>N>>M;
	vector<vector<Edge>>edge(N);
	for(int i=0;i<M;i++){
		cin>>L>>R>>K;
		L--;
		R--;
		edge[L].push_back(Edge(R,K));
		edge[R].push_back(Edge(L,K));
	}
	vector<int>v(50*500+1);
	cin>>v[0];
	int a,b,c;
	cin>>a>>b>>c;
	vector<vector<vector<long long int>>>dp(N,vector<vector<long long int>>(50,vector<long long int>(2,MOD*MOD)));
	dp[0][v[0]][0]=0;
	priority_queue<pair<long long int ,Node>,vector<pair<long long int ,Node>>,greater<pair<long long int ,Node>>>PQ;
	PQ.push({0,Node(0,v[0],0)});
	while(!PQ.empty()){
		long long int co=PQ.top().first;
		auto box=PQ.top().second;
		//cout<<a<<" "<<b<<" "<<c<<endl;
		//cout<<co<<" "<<box.node<<" "<<box.nx<<" "<<box.goal<<endl;
		PQ.pop();
		int nx=box.nx*a+b;
		nx%=c;
		//cout<<"nx "<<nx<<endl;
		for(auto i:edge[box.node]){
			//cout<<"edge "<<i.to<<" "<<i.cost<<endl;
			if(dp[i.to][nx][box.goal]>co+box.nx*i.cost){
				dp[i.to][nx][box.goal]=co+box.nx*i.cost;
				PQ.push({dp[i.to][nx][box.goal],Node(i.to,nx,box.goal)});
			}
			if(i.to==N-1){
				//cout<<"goal"<<endl;
				//cout<<dp[i.to][nx][1]<<" "<<co+box.nx*i.cost<<endl;
				if(dp[i.to][nx][1]>co+box.nx*i.cost){
					dp[i.to][nx][1]=co+box.nx*i.cost;
					PQ.push({dp[i.to][nx][1],Node(i.to,nx,1)});
				}
			}
		}
	}
	long long int ans=MOD*MOD;
	for(int i=0;i<50;i++){
		ans=min(ans,dp[0][i][1]);
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 9868
#include <bits/stdc++.h>
using namespace std;
#define  rep(i, n) for(int i = 0; i < n; i++) 
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  INF 1LL << 60
typedef long long int LL;
typedef long long int ll;
#define pll pair<ll, ll>
#define F first
#define S second
const int MOD = 1000000007;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }
//sort(all(x))とするとソートできるよ
// 10^x は pow(10,(x)) 
// 任意のlogは　対数の底の変換を使う    log(N) / log(任意の底)

int main(){
    string s;cin >> s;
    int N = s.size();
    int lim = (N+2-1)/2;

    int fir = 0;
    int sec = 0;
    for(int i = 0;i < lim;++i){
        if(s[i] == 'p')fir++;
    }
    for(int i = lim;i < N;++i){
        if(s[i] == 'g')sec++;
    }

    int ans = sec - fir;
    if(ans < 0)ans = 0;
    cout << ans << endl;
}


Measured memory_bytes: 512
import sys
sys.setrecursionlimit(10**9)

read=sys.stdin.read
class Unionfind():
    def __init__(self,n):
        self.parents=[-1]*n
        self.dist=[0]*n 
    
    def find(self,x):
        if self.parents[x]<0:
            return self.dist[x],x
        else:
            tmp=self.find(self.parents[x])
            self.dist[x]+=tmp[0]
            self.parents[x]=tmp[1]
            return self.dist[x],self.parents[x]
    
    def union(self,x,y,d):
        rx=self.find(x)[1]
        ry=self.find(y)[1]
        diff=self.dist[y]-self.dist[x]-d
        if rx==ry:
            if diff!=0:
                return True
            return False
        if diff<0:
            rx,ry=ry,rx
            diff=-diff
        self.parents[ry]=min(self.parents[ry],self.parents[rx]-diff)
        self.parents[rx]=ry
        self.dist[rx]=diff
        return False
    
def main():
    n,m,*lrd=map(int,read().split())
    v=Unionfind(n)
    for l,r,d in zip(*[iter(lrd)]*3):
        if v.union(l-1,r-1,d):
            print('No')
            break
    else:
        print('Yes')
if __name__=='__main__':
    main()


Measured memory_bytes: 74152
import java.util.Scanner;

fun main (args: Array<String>) {
  val input = Scanner(System.`in`)
  
  while (input.hasNext()) {
    val N = input.nextInt()
    val M = input.nextInt()
    val ways = (N * (N - 1)) / 2 + (M * (M - 1)) / 2
    
    println(ways)
  }
}

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

#define ll long long
#define fw(p) for(int w=0;w<(p);w++)
#define fx(p) for(int x=0;x<(p);x++)
#define fy(p) for(int y=0;y<(p);y++)
#define fz(p) for(int z=0;z<(p);z++)
#define fyg(p,g) for(int y=(g);y<(p);y++)
#define fzg(p,g) for(int z=(g);z<(p);z++)
#define ce(d) cout<<d<<endl;
#define vecp(p) int aa;cin>>aa;(p).push_back(aa);
#define vecpl(p) long long aa;cin>>aa;(p).push_back(aa);
#define vecps(p) string aa;cin>>aa;(p).push_back(aa);
#define vecp2(p) cin>>aa;(p).push_back(aa);
#define vecpl2(p) long long a	b;cin>>ab;(p).push_back(ab);
#define vecps2(p) string ab;cin>>ab;(p).push_back(ab);
#define sorts(c) sort((c).begin(),(c).end());
#define reverses(c) reverse((c).begin(),(c).end());
#define vec(b) vector<int> (b);
#define vecl(b) vector<long long> (b);
#define vecs(b) vector<string> (b);
#define pb(b,a) (b).push_back((a));
#define doublece(a,b) cout<<(a)<<' '<<(b)<<endl;
#define pairs(s) vector<pair<int,int>> (s);
#define pairsp(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define MOD 998244353
#define cey ce("Yes")
#define cen ce("No")
#define ceY ce("YES")
#define ceN ce("NO")


ll inv(ll a, ll p) {

	ll res = 1;
	while (p > 0) {
		if ((p & 1) == 1) { res *= a; res %= MOD; }
		a = a * a % MOD;
		p >>= 1;
	}
	return res;
}

int main()
{
	int N;
	cin >> N;
	map<int, int> K;
	int maxi = 0;
	fx(N) {
		int a;
		cin >> a;
		K[a]++;
		if (x==0&&a!=0) {
			ce(0);
			return 0;
		}
		maxi = max(maxi, a);
	}
	if (K[0]!=1) {
		ce(0);
		return 0;
	}

	ll ans = 1;
	fyg(maxi+1,2) {
		ans *= inv(K[y-1],K[y]);
		ans %= MOD;
	}
	ce(ans)
    return 0;
}



Measured memory_bytes: 4992
#include<stdio.h>
#include<string>
#include<utility>
#include<iostream>
#include<queue>
#include<math.h>
#include<algorithm>
#include<vector>
#include<map>
#include<stack>
#include<bitset>

using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0;i<(int)(n);i++)

int main(){
    int a,b;
    scanf("%d%d",&a,&b);
    if(a<10 && b<10){
        printf("%d\n",a*b);
    }
    else printf("-1\n");
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
using namespace std;
vector <int> n;

int main(){
	string s;
	int n,sum=0;
	cin>>s;
	for(int i=0;i<s.size();i++){
		sum+=s[i]-48;
	}
	if(sum%9==0){
		cout<<"Yes"<<endl;
	}else{
		cout<<"No"<<endl;
	}
	return 0;
}

Measured memory_bytes: 3744
#include <bits/stdc++.h> 
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> vec(n);
  for (int i = 0; i < n; i++) cin >> vec.at(i);
  sort(vec.begin(), vec.end(), greater<int>());
  int bob, alice = 0;
  for (int i = 0; i < n; i++) {
    if (i % 2 == 0) alice += vec.at(i);
    else bob += vec.at(i);
  }
  cout << alice - bob << endl;
}

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

using namespace std;
typedef long long int lli;

lli n, a, b;

lli minTries(lli A, lli B)
{
	lli ans = A - 1;
	ans++;

	B -= A;
	ans += ( B - 1 )/2;

	return ans;
}

int main()
{
	scanf("%lld %lld %lld",&n,&a,&b);

	if( (b - a)%2 == 0 )
	{
		printf("%lld\n",( b - a )/2);
		return 0;
	}

	lli curAns = minTries( a , b );

	a = n - a + 1;
	b = n - b + 1;
	swap( a , b );

	curAns = min( curAns , minTries( a , b ) );

	printf("%lld\n",curAns);
}

Measured memory_bytes: 256
#include<stdio.h>
 
int main(){
	int a, b, n, step = 1;
	while(scanf("%d %d", &a, &b) != 0){
		if(a == 0 || b == 0) break;
		if(a <= b){
			n = a;
			a = b;
			b = n;
		}
		if(a % b == 0) n = b;
		while(a % b != 0){
			step++;
			if(a % b == 0){
				n = b;
				break;
			}
			a = a % b;
			n = a;
			a = b;
			b = n;
		}
		printf("%d %d\n", n, step);
		step = 1;
	}
	return 0;
}

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

int main() {
    char c;
    cin >> c;
    
    if (c == 'a' or c == 'i' or c == 'u' or c == 'e' or c == 'o') {
        cout << "vowel" << endl;
    }
    else {
        cout << "consonant" << endl;
    }
}


Measured memory_bytes: 256
#include<iostream>
#include<stdlib.h>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
using namespace std;

int main()
{
  int n,m;
  int count_1=0;
  int count_2=0;
  
  cin>>n>>m;
  
  for(int i=1;i<n;i++)
  {
    count_1=count_1+n-i;
  }
  
  for(int j=1;j<m;j++)
  {
    count_2=count_2+m-j;
  }
  
  cout<<count_1+count_2<<endl;
  
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define PI pair<int,int>
const int maxm=1e5+5;
vector<int>g[maxm];
int mark[maxm][3];
int dp[maxm][3];
int n,m;
int S,T;
void bfs(){
    queue<PI>q;
    mark[S][0]=1;
    dp[S][0]=0;
    q.push({S,0});
    while(!q.empty()){
        int x=q.front().first,y=q.front().second;
        q.pop();
        int yy=(y+1)%3;
        for(int v:g[x]){
            if(!mark[v][yy]){
                mark[v][yy]=1;
                dp[v][yy]=dp[x][y]+1;
                q.push({v,yy});
            }
        }
    }
}
signed main(){
    cin>>n>>m;
    for(int i=1;i<=m;i++){
        int a,b;cin>>a>>b;
        g[a].push_back(b);
    }
    cin>>S>>T;
    bfs();
    if(!mark[T][0]){
        cout<<-1<<endl;
    }else{
        cout<<dp[T][0]/3<<endl;
    }
    return 0;
}
/*
令dp[i][3]表示点S到达点i,步数%3=0,1,2的最短路,
只需要计算出dp[T][0]即可.
bfs一下就行了.
*/


Measured memory_bytes: 13764
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <math.h>
#include <string>
#include <string.h>
#include <stack>
#include <queue>
#include <vector>
#include <utility>
#include <set>
#include <map>
#include <stdlib.h>
#include <iomanip>

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


\
int main() {
	ll s;
	ll sum;
	sum = 0;
	cin >> s;
	if (6 < s % 11) {
		sum += 1;
	}
	sum += s / 11 *2;
	sum += 1;
	if (0 == s % 11) {
		sum -= 1;
	}
	cout << sum;
	return 0;
}

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

using namespace std;

long long MOD = 1e9 + 7;
string s;
long long d[100000][13];

int main(){
    cin >> s;
    int l = s.size();
    reverse(s.begin(),s.end());
    if(s[0] == '?'){
        for(int i=0;i<10;i++) d[0][i] = 1;
    }else{
        for(int i=0;i<13;i++) d[0][i] = 0;
        d[0][(int)s[0]-'0']++;
    }
    long long p = 10;
    for(int i=1;i<l;i++){
        if(s[i]=='?'){
            for(int j=0;j<13;j++) d[i][j] = 0;
            for(int j=0;j<10;j++){
                long long q = p * j;
                q %= 13;
                for(int k=0;k<13;k++){
                    d[i][(k+q)%13] += d[i-1][k];
                    d[i][(k+q)%13] %= MOD;
                }
            }
        }else{
            long long q = p * ((int)s[i] - '0');
            q %= 13;
            for(int j=0;j<13;j++){
                d[i][(j+q)%13] = d[i-1][j];
            }
        }
        p *= 10;
        p %= 13;
    }
    cout << d[l-1][5] << endl;
    return 0;
}

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

t = list(map(int,input().split()))

t.sort()

memo = []
check = 1
for i in range(n-1):
    if t[i] == t[i+1] and i == n-2:
        check += 1
        memo.extend([t[i]]*(check//2))
    elif t[i] == t[i+1]:
        check += 1
    elif t[i] != t[i+1] and check>1:
        memo.extend([t[i]]*(check//2))
        check = 1

memo.sort(reverse=True)

if len(memo)>1:
    print(memo[0]*memo[1])
else:
    print(0)

Measured memory_bytes: 62704
// j;main(i){for(;9/i;i+=!(j%=9))printf("%dx%d=%d\n",i,j,++j*i);}

// k;main(a,b){for(;k=~scanf("%d%d",&a,&b);printf("%.f\n",a+b?log10(a+b)+1:1.));}
// k;main(a,b){for(;k=~scanf("%d%d",&a,&b);printf("%.f\n",a+b?floor(log10(a+b))+1:1.));}
// k;main(a,b){for(;k=~scanf("%d%d",&a,&b);printf("%.f\n",a+b?floor(log10(a+b)+.5)+1:1.));}
// k;main(a,b){for(;k=~scanf("%d%d",&a,&b);printf("%d\n",a+b?(int)log10(a+b)+1:1));}
// k;main(a,b){for(;k=~scanf("%d%d",&a,&b);printf("%d\n",a+b?(int)log10(a+b)+1:1));}
k;main(a,b){for(;k=~scanf("%d%d",&a,&b);printf("%d\n",(int)log10(a+b)+1));}////////////

// k;main(a,b){for(;k=~scanf("%d%d",&a,&b);printf("%d\n",b))for(a+=b,b=1;a/=10;b++);}

// #include <stdio.h>
 
// int main( void ) {
//     int a, b, d, tmp;
 
//     for ( ; scanf( "%d %d", &a, &b ) == 2; printf( "%d\n", d ) ) {
//         tmp = a + b;
//         for ( d = 1; tmp /= 10; d++ ) ;
//     }
 
//     return 0;
// }

// main(i,a,t,p,j){for(;~scanf("%d",&t)?i++<4?t<p?p=t:1:t<j?j=t:1:!printf("%d\n",p+j-50););}




// double a,b,c,d;i;main(){scanf("%lf%lf%lf%lf",&a,&b,&c,&d);i=!printf("%f\n",hypot(a-c,b-d));}
// double c[4];i;main(){for(;~scanf("%lf",c+i++););i=!printf("%f\n",hypot(*c-c[2],c[1]-c[3]));}
// double c[4],*p=c;i;main(){for(;~scanf("%lf",p++););i=!printf("%f\n",hypot(*c-c[2],c[1]-c[3]));}
// double c[],*p=c;main(){for(;~scanf("%lf",p++););p=!printf("%f\n",hypot(*c-c[2],c[1]-c[3]));}
// double a,b,c,d,*p=&d;main(){for(;~scanf("%lf",p++););p=!printf("%f\n",hypot(d-c,b-a));}




// s,n,i;main(x,y){for(;~scanf("%d,%d",&x,&y)?s+=x*y:!printf("%d\n%.f\n",s,.5+1.*n/i);i++)n+=y;}
// s,n,i;main(x,y){for(;~scanf("%d,%d",&x,&y)?s+=x*y:!printf("%d\n%.f\n",s,floor(.5+1.*n/i));i++)n+=y;}////
// s,n,i;main(x,y){for(;~scanf("%d,%d",&x,&y)?s+=x*y:!printf("%d\n%d\n",s,(int)(.5+1.*n/i));i++)n+=y;}////


// L;main(A,B,C,D){scanf("%d%d%d%d%d",&L,&A,&B,&C,&D);L=!printf("%.f\n",L-fmax(--A/C,--B/D)-1);}
// a,b,c,d,e,*p=&d;main(){for(;~scanf("%d",p++););p=!printf("%.f\n",d-fmax(--b/c,--e/a)-1);}



// char c[];p;main(t){for(;gets(c)**c;p=!puts(strncat(c,c,p%=strlen(c))+p))for(gets(&t);scanf("%d ",&t);p+=t);}

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

int main() {
    int n;
    string s;
    cin >> n >> s;
    int ans = 0;
    rep(i,1000) {
        string t;
        int x = i;
        rep(j,3) {
            t += ('0' + x % 10);
            x /= 10;
        }
        int turn = 0;
        rep(j,n) {
            if(s[j] == t[turn]) {
                turn++;
            }
            if(turn == 3) {
                break;
            }
        }
        if(turn == 3) {
            ans++;
        }
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  long long a[300000],b[300000],c,e[300000]={};
  int n,m;
  cin>>n;
  for(int i=0;i<n;i++) cin>>a[i];
  sort(a,a+n);
  e[0]=a[0];
  for(int i=1;i<n;i++)e[i]+=e[i-1]+a[i];
  cin>>m;
  for(int i=0;i<m;i++) cin>>b[i];
  for(int i=0;i<m;i++){
    cin>>c;
    int hi=n-1,lo=0;
    while(hi>lo){
      int mid=(hi+lo)/2;
      if(a[mid]>b[i]) hi=mid;
      else lo=mid+1;
    }
    if(a[hi]<=b[i])hi++;
    if(c<=e[hi-1]) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
  }
 
  return 0;
}

Measured memory_bytes: 8216
use std::io::*;
use std::str::FromStr;

//https://qiita.com/tubo28/items/e6076e9040da57368845
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

trait Joinable {
    fn join(self, sep: &str) -> String;
}

//to_string()メソッドの要素を持つイテレータに対して、分割文字列を与えられるようにする
impl<U: ToString, T: Iterator<Item = U>> Joinable for T {
    fn join(self, sep: &str) -> String {
        self.map(|x| x.to_string()).collect::<Vec<_>>().join(sep)
    }
}

//参考
//https://onlinejudge.u-aizu.ac.jp/solutions/problem/ALDS1_5_B/review/4236610/core2duoe6320/Rust
//https://onlinejudge.u-aizu.ac.jp/solutions/problem/ALDS1_5_B/review/2709881/arsenic28/Rust

fn mergesort(a: &mut Vec<u32>, left: usize, right: usize) -> usize {
    //両端のインデックスが隣り合う。2要素になるまで分割する。
    //分割の順番はDFSの順番
    if right - left > 1 {
    //if left + 1 < right {
        let mid = (left + right) / 2;
        let count =
            //左側を分割
            mergesort(a, left, mid)
            //右側を分割
            + mergesort(a, mid, right)
            //統合
            + merge(a, left, mid, right);
        count
    } else {
        0
    }
}

fn merge(a: &mut Vec<u32>, left: usize, mid: usize, right: usize) -> usize {
    //左右に2分割。末尾に番兵を設定。
    let l: Vec<u32> = a[left..mid].iter().cloned().chain(std::iter::once(std::u32::MAX)).collect();
    let r: Vec<u32> = a[mid..right].iter().cloned().chain(std::iter::once(std::u32::MAX)).collect();

    let mut i = 0;
    let mut j = 0;
    let mut count = 0;  

    //println!("left:{} right{}",left,right);
    //left..right部分をソートする
    //lとrの左端を比較し小さい方を選んでいく
    for k in left..right {
        //println!("l:{} r:{}",l[i],r[j]);
        count += 1;
        if l[i] <= r[j] {
            a[k] = l[i].clone();
            i += 1;
        } else {
            a[k] = r[j].clone();
            j += 1;
        }
    }
    count
}

fn main() {
    let n: usize = read();
    let mut a: Vec<u32> = (0..n).map(|_| read()).collect();

    //ベクタ、左端インデックス、右端インデックス
    let count = mergesort(&mut a, 0, n);
    println!("{}", a.iter().join(" "));

    /*
    println!(
        "{}",
        a.iter()
            .map(|x| x.to_string())
            .collect::<Vec<_>>()
            .join(" ")
    );
    */

    println!("{}", count);
}



Measured memory_bytes: 31648
#include <bits/stdc++.h>
#define r(i,n) for(int i = 0; i<n; i++)
using namespace std;
int main(){
  bool flag = false;
  string s;
  cin >> s;
  r(i,s.length()-1){
    if(s.at(i)=='A'&&s.at(i+1)=='C'){
      cout << "Yes"<<endl;
      flag=true;
      break;
    }
  }
  if(!flag)cout << "No"<<endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<iostream>
#include<algorithm>
using namespace std;
char s[100010];
char s1[100010];
int main(void)
{
     int i,j,k,n,m,l;
     scanf("%s",s);
     l=strlen(s);
     k=0;
     for(i=0;i<l;i++)
     {
          if(s[i]!='x')
               s1[k++]=s[i];
     }
     m=0;
     for(i=0;i<k;i++)
     {
          if(s1[i]!=s1[k-i-1])
          {
               m=1;
               break;
          }
     }
     if(m==1)
          printf("-1\n");
     else
     {
          i=0;
          j=l-1;
          k=0;
          while(i<j)
          {
               if(s[i]==s[j])
               {
                    i++;
                    j--;
               }
               else
               {
                    k++;
                    if(s[i]=='x')
                         i++;
                    else
                         j--;
               }
          }
          printf("%d\n",k);
     }
     return 0;
}


Measured memory_bytes: 384
#include <iostream>

//CÓ¶ðÁ·Ö
int clear(std::string s, std::string f){
	int pos;
	while(pos = s.find(f), pos != std::string::npos)
		s.replace(pos,f.size(),"");
	if(s == "")return 1;
	return 0;
}

int main(){
	int n;
	std::cin >> n;
	while(n--){
		std::string sn, res = "";
		std::cin >> sn;

		//Type A
		//ªª>'CKöª~C©Â¨ ÌªªïÅ é
		if(sn.substr(0,2) == ">'" &&
			 sn[sn.size()-1] == '~' && (sn.size()-3) % 2 == 1){
			std::string st = sn.substr(2,sn.size()-3);
			//¨ Ì^ñª#
			if(st[st.size()/2] == '#'){
				st.replace(st.size()/2,1,"");
				
				//#ÈOª·×Ä=
				// int eq = 1;
				// for(int i=0;i<st.size();i++){
				// 	if(st[i] != '='){eq = 0;break;}
				// }
				// if(eq)std::cout << "A" << std::endl;
				if(st != "")
					if(clear(st,"="))res = "A\n";
			}
		}

		//Type B
		if(sn.substr(0,2) == ">^" &&
			 sn.substr(sn.size()-2,2) == "~~" &&
			 (sn.size()-4) % 2 == 0){
			std::string st = sn.substr(2,sn.size()-4);
			if(st != "")
				if(clear(st,"Q="))res = "B\n";
		}

		if(res == "")res = "NA\n";
		std::cout << res;
	}
}

Measured memory_bytes: 0
#include <iostream>
#include <set>
#include <vector>
#include <algorithm>

using namespace std;

int main (){
  int q,x;
  set<int> a,b;
  vector<int> result;

  cin >> q;

  for (int i = 0; i < q; i++){
    cin >> x;
    a.insert(x);
  }

  cin >> q;

  for (int i = 0; i < q; i++){
    cin >> x;
    b.insert(x);
  }
  set_intersection(begin(a),end(a),begin(b),end(b),inserter(result,end(result)));

  for_each(begin(result), end(result), [](int x) {
    cout << x << endl;
  });
  return 0;
}



Measured memory_bytes: 22024
#include <iostream>
using namespace std;
int c[13],cod[13];
int a[13][13];
int n,m,x,ans=0,ans1=99999999;
void rekursia(int i){
  if(i==n+1){
    int x1=0;
    for(int g=1;g<=m;g++)
      if(cod[g]>=x)
        x1++;
    if(x1==m){
      ans1=min(ans1,ans);
    }
    return;
  }
  rekursia(i+1);
  ans+=c[i];
  for(int g=1;g<=m;g++)
    cod[g]+=a[i][g];
  rekursia(i+1);
  for(int g=1;g<=m;g++)
    cod[g]-=a[i][g];
  ans-=c[i];
}
int main() {
  cin>>n>>m>>x;
  for(int i=1;i<=n;i++){
    cin>>c[i];
    for(int g=1;g<=m;g++)
      cin>>a[i][g];
  }
  rekursia(1);
  if(ans1==99999999)
    cout<<-1;
  else
    cout<<ans1;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
const int N=1e6+10;
int n,m,a[N],b[N],match[N];
char s[N],t[N];
int main()
{
	scanf("%d%s%s",&n,s+1,t+1);
	if (!strcmp(s+1,t+1)) return puts("0"),0;
	for (int p=n,q=n;p;p--){
		while (t[p]==t[p-1]) p--;
		while (q&&(q>p||s[q]!=t[p])) q--;
		if (!q) return puts("-1"),0;
		match[p]=q;
	}
	for (int i=1;i<=n;i++)
		if (match[i]) m++,a[m]=match[i],b[m]=i;
	a[m+1]=b[m+1]=n+1;
	int ans=0,Max=0;
	for (int i=1;i<=m;i++)
		for (int j=a[i];j<a[i+1]-1;j++)
			if (s[j]!=s[j+1]) ans=1;
	for (int i=1;i<=m;i++){
		int l=0,r=m+1-i;
		while (l<r){
			int mid=(l+r)>>1;
			if (a[i+mid]-mid>=b[i]) r=mid;else l=mid+1;
		}
		Max=max(Max,l);
	}
	printf("%d\n",ans+Max);
	return 0;
}

Measured memory_bytes: 13952
#include <cstdio>
#include <algorithm>

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

using namespace std;

int n, m;
char x[50][51];
int dp[50][50];

int main(){
	scanf("%d%d", &n, &m);
	rep(i, n){
		scanf("%s", x[i]);
		rep(j, m){
			x[i][j] -= '0';
		}
	}
	dp[0][0] = x[0][0];
	rep(i, m - 1){
		dp[0][i + 1] = dp[0][i] + x[0][i + 1];
	}
	rep(i, n - 1){
		dp[i + 1][0] = dp[i][0] + x[i + 1][0];
	}
	rep(i, n - 1){
		rep(j, m - 1){
			dp[i + 1][j + 1] = min(dp[i][j + 1], dp[i + 1][j]) + x[i + 1][j + 1];
		}
	}

	printf("%d\n", dp[n - 1][m - 1]);
	return 0;
}

Measured memory_bytes: 1040