akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
// #include<ext/pb_ds/assoc_container.hpp>
// #include<ext/pb_ds/tree_policy.hpp>
// #include<ext/pb_ds/tag_and_trait.hpp>
// using namespace __gnu_pbds;
using namespace std;
using ll=long long;
#define double long double
using datas=pair<ll,ll>;
using ddatas=pair<double,double>;
using tdata=pair<ll,datas>;
using vec=vector<ll>;
using mat=vector<vec>;
using pvec=vector<datas>;
using pmat=vector<pvec>;
// using llset=tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>;
#define For(i,a,b) for(i=a;i<(ll)b;i++)
#define bFor(i,a,b) for(i=a-1;i>=(ll)b;i--)
#define rep(i,N) For(i,0,N)
#define rep1(i,N) For(i,1,N)
#define brep(i,N) bFor(i,N,0)
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define vsort(v) sort(all(v))
#define vrsort(v) sort(allr(v))
#define endl "\n"
#define pb push_back
#define eb emplace_back
#define print(v) cout<<v<<endl
#define printyes cout<<"Yes"<<endl
#define printno cout<<"No"<<endl
#define printYES cout<<"YES"<<endl
#define printNO cout<<"NO"<<endl
#define output(v) do{bool f=0;for(auto outi:v){cout<<(f?" ":"")<<outi;f=1;}cout<<endl;}while(0)
const ll mod=1000000007;
// const ll mod=998244353;
const ll inf=1LL<<60;
const double PI = acos(-1);
const double eps = 1e-9;
template<class T> inline bool chmax(T& a,T b){bool x=a<b;if(x)a=b;return x;} 
template<class T> inline bool chmin(T& a,T b){bool x=a>b;if(x)a=b;return x;} 

void startupcpp(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(15);
}

double distance(ddatas x,ddatas y){
  double a=x.first-y.first,b=x.second-y.second;
  return sqrt(a*a+b*b);
}

ll modinv(ll a) {
  ll b=mod,u=1,v=0,t;
  while(b){
    t=a/b;
    a-=t*b; swap(a,b);
    u-=t*v; swap(u,v);
  }
  return (u+mod)%mod;
}

ll moddevide(ll a,ll b){return (a*modinv(b))%mod;}

vec modncrlistp,modncrlistm;

ll modncr(ll n,ll r){
  ll i,size=modncrlistp.size();
  if(size<=n){
    modncrlistp.resize(n+1);
    modncrlistm.resize(n+1);
    if(!size){
      modncrlistp[0]=modncrlistm[0]=1;
      size++;
    }
    For(i,size,n+1){
      modncrlistp[i]=modncrlistp[i-1]*i%mod;
      modncrlistm[i]=modinv(modncrlistp[i]);
    }
  }
  return modncrlistp[n]*modncrlistm[r]%mod*modncrlistm[n-r]%mod;
}

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

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

ll countdigits(ll n){
  ll ans=0;
  while(n){n/=10;ans++;}
  return ans;
}

ll sumdigits(ll n){
  ll ans=0;
  while(n){ans+=n%10;n/=10;}
  return ans;
}

int main(){
  startupcpp();
  // ll test;cin>>test;while(test--){
  ll i,j,N,H,W,ans=0;
  cin>>N;
  map<ll,ll> mp;
  vec v(N);
  rep(i,N){
    cin>>v[i];
    mp[v[i]]++;
  }
  for(auto x:mp){
    ans+=x.second*(x.second-1)/2;
  }
  rep(i,N){
    H=mp[v[i]];
    W=H-1;
    print(ans-W);
  }
}

Measured memory_bytes: 11136
n, m, k = map(int, input().split())
clusterN = [1] * n
clusterI = list(range(n))
out = [0] * n
def generateC(x):
  if clusterI[x] != x:
    minI = generateC(clusterI[x])
    clusterI[x] = minI
    return minI
  else:
    return x

def unite(x, y):
  CX = generateC(x)
  CY = generateC(y)
  if CX != CY:
    if CX > CY:
      CX, CY = CY, CX
      x, y = y, x
    clusterN[CX] += clusterN[CY]
    clusterI[CY] = CX
    generateC(y)
    

for _ in range(m):
  a, b = map(int, input().split())

  unite(a-1, b-1)
  out[a-1] -= 1
  out[b-1] -= 1

for _ in range(k):

  a, b = map(int, input().split())
  if generateC(a-1) == generateC(b-1):
    out[a-1] -= 1
    out[b-1] -= 1
out = [out[i] + clusterN[generateC(i)] - 1 for i in range(n)]
print(*out)

Measured memory_bytes: 112652
#include <algorithm>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
#include <stack>
#include <sstream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

using namespace std;
typedef long long int ll;

int main()
{
	int L,R,d;
	cin>>L>>R>>d;
	ll ans = 0;
	for(int i = L; i <= R; i++){
		if(i % d == 0){
			ans++;
		}
	}
	cout<<ans<<endl;
	return 0;
}


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

// syntax sugar: `for (int i = 0; i < N; ++i)`
#define rep(i, N) for (int i = 0; i < (int)(N); ++i)
#define rep2(i, startValue, N) for (int i = (int)(startValue); i < (int)(N); ++i)
// syntax sugar: `for (int i = 0; i < N; ++i)`
#define REP(type, name, beginValue, endCondValue) \
  for (type name = beginValue; name < endCondValue; ++name)
// syntax sugar: 多次元vector
#define VECTOR_DIM3(T, name, d1, d2, d3, initValue) \
    std::vector<std::vector<std::vector<T>>> name(d1, std::vector<std::vector<T>>(d2, std::vector<int>(d3, initValue)));
#define VECTOR_DIM2(T, name, d1, d2, initValue) \
    std::vector<std::vector<T>> name(d1, std::vector<T>(d2, initValue));
#define VECTOR_DIM1(T, name, d1, initValue) \
    std::vector<T> name(d1, initValue);
#define ll long long
#define ld long double

// ARC099 C - Minimization
int main(){
  int n, k;
  cin >> n >> k;
  vector<int> a(n,0);
  int ione = 0;
  rep(i,n) {
    cin >> a[i];
    if (a[i] == 1) {
      ione = i;
    }
  }

  //cout << "ione:" << ione << endl;

  int ans = 1;
  n -= k;
  ans += n / (k-1);
  if (n % (k-1) > 0) {
    ans++;
  }

  cout << ans << endl;
  return 0;
}


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

long long n, a, b, ans;

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

	cin >> n >> a >> b;
	if(a < b)
		swap(a, b);
	if((a - b) % 2 == 0) {
		ans = (a - b) / 2;
	} else {
		ans = min(b + (a - b - 1) / 2, n - a + 1 + (a - b - 1) / 2);
	}
	cout << ans << "\n";
	return 0;
}

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

using namespace std;

int main() {
	int res[] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
	int k;
	cin >> k;
	cout << res[k - 1]; 
	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#define M 111
#define N 51
inline int min(int x,int y){return x<y?x:y;}
int A[N],B[M],C[M],F[N],Q[N],a[N],b[M],c[M],f[N],g[M],l,n,o[N],p[M],q[N],r,s,t;bool d[N],e[N],h[N];
bool check(int u)
{
    d[u]=e[u]=true;
    for(int i=o[u];i;i=p[i])
    if(!d[g[i]])
    if(!check(g[i]))return e[u]=false;
    else;
    else if(e[g[i]])return e[u]=false;
    return e[u]=false,true;
}
int i,u,v;
inline int get()
{
    for(i=1;i<=n;i++)d[i]=o[i]=0;
    for(f[q[l=0]=s]=0,r=1;l<r;)for(i=a[u=q[l++]];i;i=b[i])if(c[i]!=f[u]&&c[i]!=s)f[q[r++]=c[i]]=u;
    for(F[Q[l=0]=s]=0,r=1;l<r;)for(i=A[u=Q[l++]];i;i=B[i])if(C[i]!=F[u])F[Q[r++]=C[i]]=u;
    for(i=1,*h=true,r=0;i<=n;i++)h[i]=f[i]==F[i],r+=!h[i];
    for(i=1;i<=n;i++)if(h[i]&&!h[f[i]])return n+1;
    for(i=1,l=0;i<=n;i++)if(!h[i]&&!h[f[i]])p[++l]=o[i],g[o[i]=l]=f[i];
    for(i=1;i<=n;i++)if(!h[i]&&!h[F[i]])p[++l]=o[F[i]],g[o[F[i]]=l]=i;
    for(i=1;i<=n;i++)if(!d[i]&&!check(i))return n+1;
    return r;
}
int j,x,y;
inline void solve()
{
    for(scanf("%d",&n),i=1,x=n+1;i<n;i++)scanf("%d%d",&u,&v),b[i<<1]=a[u],c[a[u]=i<<1]=v,b[i<<1|1]=a[v],c[a[v]=i<<1|1]=u;
    for(i=1;i<n;i++)scanf("%d%d",&u,&v),B[i<<1]=A[u],C[A[u]=i<<1]=v,B[i<<1|1]=A[v],C[A[v]=i<<1|1]=u;
    for(s=1,j=0;s<=n;s++)x=min(x,get());
    for(s=1;s<=n;s++)if(!b[a[s]])
    {
        for(y=c[a[s]],j=1;j<=n;j++)if(j!=y)c[a[s]]=j,x=min(x,get()+1);
        c[a[s]]=y;
    }
    for(printf("%d\n",x==n+1?-1:x),i=1;i<=n;a[i]=A[i]=0,i++);
}
int main()
{
    for(scanf("%d",&t);t--;solve());
    return 0;
}

Measured memory_bytes: 256
using System;

namespace AOJ0066
{
    class Program
    {
        char[,] table;

        public void Proc()
        {
            while (true)
            {
                string input = Console.ReadLine();
                if (string.IsNullOrEmpty(input)) break;
                this.table = new char[3, 3];
                int result = 0;
                for (int i = 0; i < 9; i++)
                {
                    this.table[i / 3, i % 3] = char.Parse(input.Substring(i, 1));
                }

                result += checkColumn();
                result += checkRow();
                result += checkCross();

                if (result == 1) Console.WriteLine("o");
                if (result == 0) Console.WriteLine("d");
                if (result == -1) Console.WriteLine("x");
            }
        }
        static void Main(string[] args)
        {
            Program prg = new Program();
            prg.Proc();
        }

        public int checkColumn()
        {
            for (int i = 0; i < 3; i++)
            {
                if (this.table[i,0] == this.table[i,1] && this.table[i,0] == this.table[i, 2])
                {
                    switch (this.table[i,0])
                    {
                        case 'o':
                            return 1;
                        case 'x':
                            return -1;
                    }
                }
            }

            return 0;
        }

        public int checkRow()
        {
            for (int i = 0; i < 3; i++)
            {
                if (this.table[0, i] == this.table[1, i] && this.table[0, i] == this.table[2, i])
                {
                    switch (this.table[0, i])
                    {
                        case 'o':
                            return 1;
                        case 'x':
                            return -1;
                    }
                }
            }

            return 0;
        }

        public int checkCross()
        {
            if ((this.table[1, 1] == this.table[0, 0] && this.table[1, 1] == this.table[2, 2]) || (this.table[1, 1] == this.table[2, 0] && this.table[1, 1] == this.table[0, 2]))
            {
                switch (this.table[1, 1])
                {
                    case 'o':
                        return 1;
                    case 'x':
                        return -1;
                }
            }
            return 0;
        }
    }
}

Measured memory_bytes: 8552
#include<bits/stdc++.h>
using namespace std;
int main()
{
  string s;
  cin>>s;
  int n=s.size();
  int p=0;
  string z="hi";
  int fl=0;
  for(int i=0;i<n;i++)
  {
    if(s[i]!=z[p])
    {
      fl=1;
    break;
    }
    p^=1;
  }
  if(fl==0 and s[n-1]=='i')
    cout<<"Yes\n";
  else
    cout<<"No\n";
  return 0;
}
    

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <utility>
using namespace std;

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

  bool f = true;

  if(s[0] != 'A') f = false;

  int cnt = 0;
  for(int i=2; i<=s.length()-2; i++){
    if(s[i] == 'C') cnt++;
  }

  for(int i=0; i<s.length(); i++){
    if(s[i] == 'A' || s[i] == 'C') continue;

    if(tolower(s[i]) != s[i]) f = false;
  }

  if(f && cnt == 1) cout << "AC" << endl;
  else cout << "WA" << endl;

  return 0;
}


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

int main() {
  int n, m, q;
  cin >> n >> m >> q;
  vector<vector<int>> a(n + 1, vector<int>(n + 1));
  for (int i = 0; i < m; i++) {
    int l, r;
    cin >> l >> r;
    a[l][r]++;
  }

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      a[i + 1][j + 1] += a[i + 1][j];
    }
  }

  for (int i = 0; i < q; i++) {
    int l, r;
    cin >> l >> r;
    int m = 0;
    for (int j = l; j <= r; j++) {
      m += a[j][r];
    }
    cout << m << endl;
  }
}


Measured memory_bytes: 1920
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <clocale>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i, s, n) for(int i = (s), i##_len=(n); i < i##_len; ++i)
#define FORS(i, s, n) for(int i = (s), i##_len=(n); i <= i##_len; ++i)
#define VFOR(i, s, n) for(int i = (s); i < (n); ++i)
#define VFORS(i, s, n) for(int i = (s); i <= (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) FORS(i, 0, n)
#define VREP(i, n) VFOR(i, 0, n)
#define VREPS(i, n) VFORS(i, 0, n)
#define RFOR(i, s, n) for(int i = (s), i##_len=(n); i >= i##_len; --i)
#define RFORS(i, s, n) for(int i = (s), i##_len=(n); i > i##_len; --i)
#define RREP(i, n) RFOR(i, n, 0)
#define RREPS(i, n) RFORS(i, n, 0)
#define ALL(v) (v).begin(), (v).end()
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v), greater<decltype(v[0])>())
#define SZ(x) ((int)(x).size())
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define BIT(n) (1LL<<(n))
#define UNIQUE(v) v.erase(unique(ALL(v)), v.end())

using ll = long long;
using Pi_i = pair<int, int>;
using VI = vector<int>;
using VD = vector<double>;
using VLL = vector<ll>;
using VS = vector<string>;
using VC = vector<char>;
using VB = vector<bool>;

const int MOD = 1000000007;
const int INF = 1000000000;

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(b < a){
        a = b; return true;
    }
    return false;
}



int main(){
    int n, cnt = 0; cin >> n;
    VI S(n);
    REP(i, n) cin >> S[i];
    int q; cin >> q;
    REP(i, q){
        int t; cin >> t;
        auto itr = lower_bound(ALL(S), t);
        if(itr == S.end()) continue;
        if(*itr == t)
            ++cnt;
    }
    cout << cnt << "\n";
    return 0;
}



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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

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

using ll = long long;
using R = long double;
const R EPS = 1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r) {return (r > EPS) - (r < -EPS);}
inline R sq(R x) {return sqrt(max(x, 0.0L));}

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

// Problem Specific Parameter:

bool react(int x) {
	cout << x << endl;
	string ret;
	cin >> ret;
	if (ret == "Vacant") exit(0);
	return (ret == "Male");
}

int main(void) {
	int n;
	cin >> n;

	bool start = react(0);
	int low = 1, high = n;

	while (1) {
		const int mid = (low + high) / 2;
		bool cur = react(mid);
		if (mid % 2 == (start != cur)) {
			low = mid + 1;
		} else {
			high = mid;
		}
	}

	return 0;
}

Measured memory_bytes: 852
#include <iostream>
#include <string>
#include <algorithm> 
#include <cstdlib>
#include <map>
#include <queue>
#include <vector>
#include <utility>
#include <climits>
#include <numeric>
#define ll long long
#define INF INT_MAX 
using namespace std;
int main(){
	int a,b,c;
	cin >> a >> b >> c;
	int ans = min(a+b,min(a+c,b+c));
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ff { ios_base::sync_with_stdio(false);cin.tie(NULL);}
using namespace std;

typedef long long ll;
 ll  p=1e9+7; 
double pi=3.141592653589793238;
  

 int main() {
        ff;
        string s,t;
        cin>>s>>t;
        
        if(s.length()+1==t.length() ){
            s.push_back(t[t.length()-1]);
            if(s==t)
            cout<<"Yes"<<endl;
            else{
                cout<<"No"<<endl;
            }
        }else{
            cout<<"No"<<endl;
        }
        
            
            
        
           
       
    return 0;
}


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

int main(){
    int nums[20];
    int n;

    int ans=0;

    cin >> n;
    rep(i, n) cin >> nums[i];

    rep(i, n-2) {
        if (nums[i] < nums[i+1] && nums[i+1] < nums[i+2]) ans++;
        if (nums[i] > nums[i+1] && nums[i+1] > nums[i+2]) ans++;
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
#define all(x) (x).begin(), (x).end()
ll inf = LLONG_MAX;
long double pi = M_PI;
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}

int main() {
  ll n, p = 1000000007;
  cin >> n;

  vector<string> d(2);
  cin >> d[0] >> d[1];
  ll m = d[0].size();

  vll dp(m, 0);
  if (d[0][0] == d[1][0]) {
    dp[0] = 3;
    for (ll i = 1; i < m; i++) {
      if (d[0][i - 1] == d[1][i - 1]) {
        if (d[0][i] == d[1][i]) {
          dp[i] = dp[i - 1] * 2 % p;
        }
        else {
          dp[i + 1] = dp[i - 1] * 2 % p;
          dp[i] = dp[i - 1];
          i++;
        }
      }
      else {
        if (d[0][i] == d[1][i]) dp[i] = dp[i - 1];
        else {
          dp[i + 1] = dp[i - 1] * 2 % p + dp[i - 1];
          dp[i + 1] %= p;
          dp[i] = dp[i + 1];
          i++;
        }
      }
    }
  }
  else {
    dp[1] = 6;
    for (ll i = 2; i < m; i++) {
      if (d[0][i - 1] == d[1][i - 1]) {
        if (d[0][i] == d[1][i]) {
          dp[i] = dp[i - 1] * 2 % p;
        }
        else {
          dp[i + 1] = dp[i - 1] * 2 % p;
          dp[i] = dp[i - 1];
          i++;
        }
      }
      else {
        if (d[0][i] == d[1][i]) dp[i] = dp[i - 1];
        else {
          dp[i + 1] = dp[i - 1] * 2 % p + dp[i - 1];
          dp[i + 1] %= p;
          dp[i] = dp[i + 1];
          i++;
        }
      }
    }
  }
  cout << dp[m - 1] << endl;
}

Measured memory_bytes: 256
num = int(input())
str = input()
char_list = list(str)
counter_b = 0
counter_r = 0
for item in char_list:
    if item == 'R':
        counter_r += 1
    else:
        counter_b += 1

if(counter_r > counter_b):
  print('Yes')
else:
  print('No')


Measured memory_bytes: 2940
#include<iostream>
using namespace std;
static const int MAX=100;
static const int INFTY=(1<<21);
static const int WHITE=0;
static const int GRAY=1;
static const int BLACK=2;

int n,M[MAX][MAX];

void dijkstra(){
  int minv;
  int d[MAX],color[MAX];

  for(int i=0;i<n;i++){
    d[i]=INFTY;
    color[i]=WHITE;
  }

  d[0]=0;
  color[0]=GRAY;
  while(1){
    minv=INFTY;
    int u=-1;
    for(int i=0;i<n;i++){
      if(minv>d[i]&&color[i]!=BLACK){
	u=i;
	minv=d[i];
      }
    }
    if(u==-1) break;
    color[u]=BLACK;
    for(int v=0;v<n;v++){
      if(color[v]!=BLACK&&M[u][v]!=INFTY){
	if(d[v]>d[u]+M[u][v]){
	  d[v]=d[u]+M[u][v];
	  color[v]=GRAY;
        }
      }
    }
  }

  for(int i=0;i<n;i++){
    cout << i << " " << (d[i]==INFTY?-1:d[i]) << endl;
  }
}

int main(){
  cin >> n;
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      M[i][j]=INFTY;
    }
  }

  int k,c,u,v;
  for(int i=0;i<n;i++){
    cin >> u >> k;
    for(int j=0;j<k;j++){
      cin >> v >> c;
      M[u][v]=c;
    }
  }

  dijkstra();

  return 0;
}

Measured memory_bytes: 3072
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;

int has[1005];
int perfect[1005];
int tot = 0;
int main() {
	for(int i = 2; i < 40; ++i) {
		int tmp = i * i;
		while(1) {
			if(tmp > 1005) break;
			has[tmp] = 1;
			tmp *= i;
		}
	}
	has[1] = 1;
	for(int i = 1; i < 1001; ++i) {
		if(has[i]) {
			perfect[tot ++] = i;
		}
	}
//	for(int i = 0; i < tot; ++i) printf("%d ", perfect[i]); printf("\n");
	int x;
	while(~scanf("%d", &x)) {
		int id = upper_bound(perfect, perfect + tot, x) - perfect;
		printf("%d\n", perfect[id - 1]);
	}
}


Measured memory_bytes: 256
R, G, B, N = map(int, input().split())
cnt = 0
for i in range(int(N/R)+1):
    r = i*R
    for j in range(int(N/G)+1):
        g = j*G
        b = N - g - r
        if b >= 0 and b % B == 0:
            cnt += 1
print(cnt)

Measured memory_bytes: 40812
#include<iostream>
using namespace std;
int main ()
{
    long long int n,m,a,i;
long long    int sum=0,sum1=0,sum2=0;
    cin>>n;
    cin>>m;
 long long   int arr[m];
    for (int i=0; i<m; i++)
    {
        cin>>arr[i];
    }
    for (int i=0; i<m; i++)
    {
        if(i%2==0)
        {
            sum1=sum1+arr[i];
        }
        if (i%2==1)
        {
            sum2=sum2+arr[i];
        }
        sum=sum +arr[i];

    }

    if (sum>=n || sum1>=n || sum2>=n)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 4376
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using pll = pair<ll, ll>;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define Rep(i, m, n) for(ll i = m; i < n; i++)
#define all(vec) vec.begin(), vec.end()
#define lmax(x, y) max<ll>(x, y)
#define lmin(x, y) min<ll>(x, y)
#define tmax(x, y, z) lmax((x), lmax((y), (z)))
#define tmin(x, y, z) lmin((x), lmin((y), (z)))
#define MINUS(a) memset(a, 0xff, sizeof(a))
#define ZERO(a) memset(a, 0, sizeof(a))
const ll INF = 1LL << 60;
const ll MM = 1000000000; const ll MOD = MM + 7; const ll MMM=9223372036854775807;//2^63 -1
#define ADD(a,b) a = (a + ll(b)) % MOD
#define MUL(a,b) a = (a * ll(b)) % MOD
ll GCD(ll x, ll y){ if(y == 0) return x; else return GCD(y, x % y);}
ll LCM(ll x, ll y){ return x / GCD(x, y) * y;}
template<class T> inline bool chmin(T& a, T b){ if(a > b){ a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b){ if(a < b){ a = b; return true;} return false;}
template<typename A, size_t N, typename T> void FILL(A (&array)[N], const T &val){ fill( (T*)array, (T*)(array+N), val );}
// struct edge{ ll from, to, cost; };
// struct edge{ ll to, cost; };
// using Graph = vector<vector<ll>>;  // 重み無し
// using Graph = vector<edge>;  // 辺
// using Graph = vector<vector<edge>>;  // 重み付き
ll dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
ll ddx[8] = {1, 1, 0, -1, -1, -1, 0, 1}, ddy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
//cout << fixed << setprecision(10);
// priority_queue<ll, vector<ll>, greater<ll>> pq;

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


Measured memory_bytes: 6396
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
//BEGIN CUT HERE
int expression(string,int&);
int term(string,int&);
int factor(string,int&);
int number(string,int&);

bool f;

int expression(string s,int& p){
  int res=term(s,p);
  while(p<(int)s.size()){
    if(s[p]=='+'){
      p++;
      res+=term(s,p);
      continue;
    }
    if(s[p]=='-'){
      p++;
      res-=term(s,p);
      continue;
    }
    break;
  }
  return res;
}

int term(string s,int& p){
  int res=factor(s,p);
  while(p<(int)s.size()){
    if(s[p]=='*'){
      p++;
      res*=factor(s,p);
      continue;
    }
    if(s[p]=='/'){
      p++;
      int tmp=factor(s,p);
      if(tmp==0){
	f=1;
	break;
      }
      res/=tmp;
      continue;
    }
    break;
  }
  return res;
}

int factor(string s,int& p){
  int res;
  if(s[p]=='('){
    p++;
    res=expression(s,p);
    p++;
  }else{
    res=number(s,p);
  }
  return res;
}

int number(string s,int& p){
  int res=0;
  while(p<(int)s.size()&&isdigit(s[p]))
    res=res*10+s[p++]-'0';
  return res;
}
//END CUT HERE

signed main(){
  int n;
  cin>>n;
  while(n--){
    string s;
    int p=0;
    cin>>s;s.pop_back();
    cout<<expression(s,p)<<endl;
  }
  return 0;
}

/*
verified on 2017/11/20
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?lang=jp&id=0109
*/

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

#define ll long long

int main() {
  int N;
  cin >> N;
  
  vector<ll> a(N);
  for (int i = 0; i < N; i++) cin >> a[i];
    
  ll dp[3100][3100];
  
  for (int i = 0; i < N; i++) {
    dp[i][i] = 0;
  }
  
  for (int i = 1; i <= N; i++) {
    for (int j = 0; j <= N-i; j++) {
      
      if ((N-i) % 2) {
        dp[j][j+i] = min(dp[j][j+i-1] - a[j+i-1], dp[j+1][j+i] - a[j]);
      } else {
        dp[j][j+i] = max(dp[j][j+i-1] + a[j+i-1], dp[j+1][j+i] + a[j]);      
      }
    }
      
  }

  
  cout << dp[0][N] << endl;
  
}

Measured memory_bytes: 74752
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
int main(){
	long long int n,w;
  	cin>>n>>w;
  	long long int weight[n+1],value[n+1];
	for(ll int i=1;i<=n;i++){
      cin>>weight[i]>>value[i];
    }
  	ll int dp[n+1][w+1];
    for(ll int i=0;i<=n;i++){
        dp[i][0]=0;
    }
    for(ll int i=0;i<=w;i++){
        dp[0][i]=0;
    }
    for(ll int i=1;i<=n;i++){
        for(ll int j=1;j<=w;j++){
            if(j>=weight[i]){
                ll int cap=j-weight[i],add=0;
                add=dp[i-1][cap];
                dp[i][j]=max(value[i]+add,dp[i-1][j]);
            }
            else{
                dp[i][j]=dp[i-1][j];
            }
        }
    }
    /*for(int i=0;i<=n;i++){
        for(int j=0;j<=w;j++){
            cout<<dp[i][j]<<" ";
        }
        cout<<endl;
    }*/
    ll int ans=0;
    for(ll int i=0;i<=n;i++){
        if(dp[i][w]>ans){
            ans=dp[i][w];
        }
    }
    cout<<ans<<endl;
}

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

struct edge{
	int to,next;
}e[1000005];
int n,N,cnt,ans,head[1000005],a[1005][1005],q[1000005],pre[1000005],dis[1000005];

void add_edge(int u,int v){
	e[++cnt].next=head[u];
	e[cnt].to=v;
	head[u]=cnt;
}

int main(){
	scanf("%d",&n);
	for (int i=1;i<n;i++){
		for (int j=i+1;j<=n;j++){
			a[i][j]=++N;
		}
	}
	int be,af,h=1,t=0;
	for (int i=1;i<=n;i++){
		scanf("%d",&be);
		for (int j=1;j<n-1;j++){
			scanf("%d",&af);
			add_edge(a[min(i,be)][max(i,be)],a[min(i,af)][max(i,af)]);
			pre[a[min(i,af)][max(i,af)]]++;
			be=af;
		}
	}
	
	for (int i=1;i<=N;i++){
		if (!pre[i]){
			q[++t]=i;
			dis[i]=1;
		}
	}
	while (h<=t){
		int u=q[h];
		for (int i=head[u];i;i=e[i].next){
			int v=e[i].to;
			pre[v]--;
			dis[v]=max(dis[v],dis[u]+1);
			if (!pre[v]) q[++t]=v;
		}
		pre[u]=0x7ffffff;
		h++;
	}
	if (t<N) printf("%d",-1);
	else{
		ans=0;
		for (int i=1;i<=N;i++){
			ans=max(ans,dis[i]);
		}
		printf("%d",ans);
	}
	return 0;
}

Measured memory_bytes: 27520
#include<iostream>
#include<algorithm>
#include<math.h>
#include<map>
#include<set>
#include<vector>
#include<bits/stdc++.h>

using namespace std;
#define ll long long 
#define mod 1000000007

string s;
int dp[100009][13];

int solve(int idx, int sum) {
	// cout<<idx<<" "<<sum<<endl;
	if(idx == s.length())
		return sum == 5;

	if(dp[idx][sum] != -1) 
		return dp[idx][sum];
	

	int sm = sum;
	int ans = 0;

	sum *= 10;
	if(s[idx] != '?') {
		sum += (s[idx] - '0');
		sum %= 13;
		ans += solve(idx + 1, sum);
		ans %= mod;
	} else {
		for(int i = 0; i <= 9; i++){
			int ssum = sum;
			ssum += i;
			ssum %= 13;
			ans += solve(idx + 1, ssum);
			ans %= mod;
		}
	}

	return dp[idx][sm] = ans%mod;
}


int main() {
	memset(dp, -1, sizeof(dp));
	cin>>s;
	cout<<solve(0, 0)<<endl;;

}


Measured memory_bytes: 13312
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	int n,count=0;
	int a[1001];
	int flag = 1;
	cin >> n;
	for (int i = 0; i < n; i++){
		cin >> a[i];
	}
	while (flag){
		flag = 0;
		for (int i = n - 1; i >= 1; i--){
			if (a[i] < a[i - 1]){
				swap(a[i], a[i - 1]);
				flag = 1;
				count++;
			}
		}
	}
	for (int i = 0; i < n; i++){
		if (i == n - 1)cout << a[i] << endl;
		else cout << a[i] << " ";
	}
	cout << count << endl;
}

Measured memory_bytes: 1164
#include<bits/stdc++.h>
using namespace std;
typedef  long long ll;
using vll=vector<ll>;
using vvll=vector<vll>;
using vi=vector<int>;
using vvi=vector<vector<int>>;
using vb=vector<bool>;
using pii=pair<int,int>;
using vpii=vector<pair<int,int>>;

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

//pow(llpow,modpow)
template<class T> ll llpow(ll x,T n){ll ans=1;if(x==0)ans=0;while(n){if(n&1)ans*=x;x*=x;n>>=1;}return ans;}
long long modpow(long long a, long long n, long long mod) {long long res = 1;while (n > 0) {if (n & 1) res = res * a % mod;a = a * a % mod;n >>= 1;}return res;}
//最大公約数
template<class T> inline T gcd(T x,T y){if(y==0)return x; else {return gcd(y,x%y);}}
//最小公倍数
template<class T> inline T lcm(T x,T y){return x/gcd(x,y)*y;}
//逆元
long long modinv(long long a, long long m) {long long b = m, u = 1, v = 0;while (b) {long long t = a / b;a -= t * b; swap(a, b);u -= t * v; swap(u, v);}u %= m;if (u < 0) u += m;return u;}

#define rep(i, begin_i, end_i) for (ll i = (ll)begin_i; i < (ll)end_i; i++)
//試験導入
#define irep(i, end_i, begin_i) for (ll i = (ll)begin_i-1; i >= (ll)end_i; i--)

long long INF = 1LL<<60;
int main( ){
    int n,m;
    cin>>n>>m;
    vi res(n);
    vector<vb> is_connected(n,vb(n,false));
    rep(i,0,m){
        int a,b;
        cin>>a>>b;
        a--,b--;
        is_connected[a][b]=true;
        is_connected[b][a]=true;
    }
    rep(i,0,n)res[i]=i;
    int cnt=0;
    do{
        if(res[0]==0){
            bool check=true;
            rep(i,0,n-1){
                if(is_connected[res[i]][res[i+1]]==false)check=false;
            }
            if(check)cnt++;
        }
    }
    while(next_permutation(res.begin(),res.end()));
    cout<<cnt<<endl;
    return 0;
}




Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <utility>
#include <numeric>

using namespace std;

const uint64_t MOD = 1000000000 + 7;

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

	vector<int> a(100005);
	vector<int> a0(100005);
	vector<int> a1(100005);
	for (int i = 0; i < n; i++)
	{
		int x;
		cin >> x;

		a.at(x + 1) ++;
		a0.at(x)++;
		a1.at(x + 2)++;
	}

	int maxs = -1;
	for (int i = 0; i < a.size(); i++)
	{
		maxs = max(maxs, a.at(i) + a0.at(i) + a1.at(i));
	}

	cout << maxs << endl;
}

Measured memory_bytes: 1408
# ダイクストラ法
from heapq import heappop, heappush

N = int(input())
links = [[] for _ in range(N + 1)]
for _ in range(N - 1):
    a, b, c = map(int, input().split())
    links[a].append((b, c))
    links[b].append((a, c))

Q, K = map(int, input().split())

d = [float('inf')] * (N + 1)
d[K] = 0
#prev = [None] * (N + 1)
q = [(0, K)]
while q:
    _, u = heappop(q)
    for v, c in links[u]:
        alt = d[u] + c
        if d[v] > alt:
            d[v] = alt
            #prev[v] = u
            heappush(q, (alt, v))

result = []
for _ in range(Q):
    x, y = map(int, input().split())
    result.append(d[x] + d[y])
#print(*result, sep='\n')
print('\n'.join(str(v) for v in result))


Measured memory_bytes: 61332
#include <iostream>

using namespace std;

int main() {
    int height[10];
    for (int i = 0; i < 10; i++) {
        cin >> height[i];
    }

    for (int i = 0; i < 10; i++) {
        for (int j = 0; j < i; j++) {
            if (height[j] < height[i]) {
                int temp = height[j];
                height[j] = height[i];
                height[i] = temp;
            }
        }
    }

    for (int i = 0; i < 3; i++) {
        cout << height[i] << endl;
    }
}


Measured memory_bytes: 3104
#include<bits/stdc++.h>
using namespace std;
const int N=1005;
const long long inf=6000000000000000000ll;
int Q,n,m,D,c[27],a[N][27],t[N],as[N],su[27],ans,i,j,x,y,s=-1000000000;
set<int> p[27];
int cal(int x,int y)
{
	int sum=ans;
	sum-=a[x][t[x]];
	sum+=a[x][y];
	auto it=p[t[x]].find(x);
	auto e=it;
	--e;
	++it;
	sum+=c[t[x]]*(-(*it-*e)*(*it-*e-1)/2+(x-*e)*(x-*e-1)/2+(*it-x)*(*it-x-1)/2);
	it=p[y].lower_bound(x);
	e=it;
	--e;
	sum-=c[y]*(-(*it-*e)*(*it-*e-1)/2+(x-*e)*(x-*e-1)/2+(*it-x)*(*it-x-1)/2);
	return sum;
}
void Change(int x,int y)
{
	ans-=a[x][t[x]];
	ans+=a[x][y];
	auto it=p[t[x]].find(x);
	auto e=it;
	--e;
	++it;
	ans+=c[t[x]]*(-(*it-*e)*(*it-*e-1)/2+(x-*e)*(x-*e-1)/2+(*it-x)*(*it-x-1)/2);
	p[t[x]].erase(x);
	t[x]=y;
	p[t[x]].insert(x);
	it=p[t[x]].find(x);
	e=it;
	--e;
	++it;
	ans-=c[t[x]]*(-(*it-*e)*(*it-*e-1)/2+(x-*e)*(x-*e-1)/2+(*it-x)*(*it-x-1)/2);
}
void up()
{
	if(s<ans)
	{
		s=ans;
		for(int i=1;i<=D;++i)
			as[i]=t[i];
	}
}
mt19937 rnd(time(0));
double rand_f() {return double(rnd())/double(RAND_MAX);}
int u=0;
void SA()
{
	double T=10000;
	while(T>0.001)
	{
		int a=rnd()%D+1,b=rnd()%26+1;
		while(b==t[a])
			b=rnd()%26+1;
		int tmp=cal(a,b);
		if(tmp>ans||rand_f()<exp((tmp-ans)/T))
		{
			Change(a,b);
			up();
		}
		T=T*0.9995;
	}
	//cout<<s<<' '<<ans<<endl;
}
void Find()
{
	int i,j;
	for(i=1;i<=26;++i)
	{
		p[i].clear(); 
		p[i].insert(D+1);
		p[i].insert(0);
	}
	memset(su,0,sizeof(su));
	ans=0;
	for(i=1;i<=D;++i)
	{
		for(j=1;j<=26;++j)
			++su[j];
		t[i]=1;
		for(j=2;j<=26;++j)
			if(su[t[i]]*c[t[i]]+a[i][t[i]]<su[j]*c[j]+a[i][j])
				t[i]=j;
		ans+=a[i][t[i]];
		su[t[i]]=0;
		for(j=1;j<=26;++j)
			ans-=su[j]*c[j];
		p[t[i]].insert(i);
		//as[i]=t[i];
	}
}
int main()
{
	scanf("%d",&D);
	for(i=1;i<=26;++i)
		scanf("%d",&c[i]);
	for(i=1;i<=D;++i)
		for(j=1;j<=26;++j)
			scanf("%d",&a[i][j]);
	Find();
	up();
	while(1.0*clock()/CLOCKS_PER_SEC<1.85)
	{
		SA();
		SA();
		SA();
		SA();
		SA();
		SA();
		SA();
		SA();
		SA();
		SA();
		SA();
		SA();
		SA();
		SA();
		Find();
		up();
		//cout<<'?'<<' '<<s<<' '<<ans<<endl;
	}
	for(i=1;i<=D;++i)
	{
		cout<<as[i]<<endl;
		assert(as[i]>=1&&as[i]<=26);
	}
}

Measured memory_bytes: 4424
#include<iostream>
#include<algorithm>
#include<stack>
#include<queue>
#include<string>
using namespace std;
#define INFTY 1<<21

int main() {
  long long N;
  long long ans;
  int ANS=0;
  cin >> N;

  for (long long i = 1; i*i <= N; i++) {
	if (N%i == 0) {
	  ans = N / i;
	}
  }

  while (ans != 0) {
	ans /= 10;
	ANS++;
  }
  cout << ANS << endl;

}

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

using namespace std;

int main(void){
	string x;
	cin >> x;
	stack<char> xs;
	for(int i=0;i<x.length();i++){
		if(!xs.empty() && xs.top()=='S' && x[i] == 'T'){
			xs.pop();
		}else{
			xs.push(x[i]);
		}
	}
	cout << xs.size() << endl;
}

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

int main(){
    int h, m, s;
    cin >> s;
    
    h = s / 3600; s %= 3600;
    m = s / 60; s %= 60;
    
    cout << h << ":" << m << ":" << s << endl;
    
    return 0;
    
}


Measured memory_bytes: 3096
#include<stdio.h>

int main(){
  int N,K;
  char S[11];
  scanf("%d %s %d",&N,S,&K);
  int i;
  for(i=0;i<=N-1;i++)
    if(S[i] != S[K-1]) S[i] = '*';
  printf("%s",S);
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
//using namespace __gnu_pbds;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
//typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;

#define fread           freopen("input.txt","r",stdin)
#define fwrite          freopen("output.txt","w",stdout)
#define eb              emplace_back
#define em              emplace
#define pb              push_back
#define Mp              make_pair
#define ff              first
#define ss              second
#define all(a)          a.begin(),a.end()
#define Unique(a)       sort(all(a)),a.erase(unique(all(a)),a.end())
#define FastRead        ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define memo(ara,val)   memset(ara,val,sizeof(ara))
#define II              ( { int a ; read(a) ; a; } )
#define LL              ( { ll a ; read(a) ; a; } )
#define DD              ({double a; scanf("%lf", &a); a;})
#define rep(i,n)        for(int i=0;i<n;i++)
#define rep1(i,n)       for(int i=1;i<=n;i++)
#define rrep(i,a,n)     for(int i=a;i<=n;i++)
#define per(i,n,a)      for(int i=n;i>=a;i--)
#define pf(n)           printf("%lld",n)
#define pfi(n)          printf("%d",n)
#define sp              printf(" ")
#define ln              printf("\n")
#define sc(x)           scanf("%lld",&x)
#define scw(x)          scanf("%I64d",&x)
#define sci(x)          scanf("%d",&x)
#define sc2(x,y)        scanf("%lld %lld",&x,&y)
#define sc3(x,y,z)      scanf("%lld %lld %lld",&x,&y,&z)
#define Found(a, b)     a.find(b) != a.end()
// bool operator< (const node& sx) const { return sx.val < val; }
//set<ll,greater<ll> >st;
//priority_queue<ll , vector<ll> , greater<ll> >
template<class T>inline bool read(T &x){ int c=getchar();int sgn=1;
  while(~c&&c<'0'|c>'9'){if(c=='-')sgn=-1;c=getchar();}
  for(x=0; ~c&&'0'<=c&&c<='9'; c=getchar())x=x*10+c-'0';x*=sgn;return ~c;
}
const ll N = 300005;
const ll MOD = 1e9+7;
ll cost[N];
ll dp[N];
ll n;
ll solve(ll pos){
   if(dp[pos]!=-1) return dp[pos];
   if(pos==n) return 0;
   ll f = 1e18;
   for(ll j = pos+1, k1 = 1; j<=n && k1<=2; ++j, ++k1){
        f = min(f, solve(j)+abs(cost[pos]-cost[j]));
    }
    return dp[pos] = f;
}
int main(){
   //fread;
    n = LL;
    rep1(i,n) cost[i] = LL;
    memset(dp, -1, sizeof(dp));
    pf(solve(1)),ln;
}











Measured memory_bytes: 7424
#include <iostream>
#include <utility>
#include <tuple>
#include <vector>
#include <string>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <algorithm>
#include <functional>
#include <climits>
#include <numeric>
#include <queue>
#include <cmath>
#include <iomanip>
#include <array>
#include <string>
#include <stack>
#include <cassert>
#include <memory>
#include <random>

int main() {
	constexpr long long int MOD = 998244353;
	int a, b, c, d; std::cin >> a >> b >> c >> d;
	std::vector<std::vector<long long int>> normal(c - a + 1, std::vector<long long int>(d - b + 1, 0));
	normal[0][0] = 1;
	for (auto i = 1; i < normal.size(); ++i) {
		normal[i][0] = normal[i - 1][0] * b % MOD;
	}
	for (auto i = 1; i < normal[0].size(); ++i) {
		normal[0][i] = normal[0][i - 1] * a % MOD;
	}
	for (auto i = 1; i <= c - a; ++i) {
		for (auto j = 1; j <= d - b; ++j) {
			normal[i][j] = (MOD + (normal[i][j - 1] * (i + a) + normal[i - 1][j] * (j + b) - normal[i - 1][j - 1] * (i + a - 1) * (j + b - 1)) % MOD) % MOD;
		}
	}
	std::cout << normal.back().back() % MOD << '\n';

}

Measured memory_bytes: 73648
#include<bits/stdc++.h>
#define re register
inline int read(){
	re int t=0;
	re char v=getchar();
	while(v<'0')v=getchar();
	while(v>='0'){
		t=(t<<3)+(t<<1)+v-48;
		v=getchar();
	}
	return t;
}
using namespace std;
int n,x,y,m,k,a[100002],b[100002],c[100002],l;
long long ans;
signed main(){
	x=read();y=read();
	n=read();	m=read();	k=read();for(re int i=1;i<=n;++i)a[i]=read();sort(a+1,a+n+1);x=n-x+1;
for(re int i=1;i<=m;++i)b[i]=read();sort(b+1,b+m+1);y=m-y+1;
for(re int i=1;i<=k;++i)c[i]=read();sort(c+1,c+k+1);
	l=k;b[m+1]=a[n+1]=1e9;
	while(l){
		if(a[x]<b[y]&&x<=n){
			if(c[l]>a[x])ans+=c[l],--l,++x;
			else break;
		}
		else if(y<=m){
			if(c[l]>b[y])ans+=c[l],--l,++y;
			else break;
		}
		else break;
	}
	for(re int i=x;i<=n;++i)ans+=a[i];
	for(re int i=y;i<=m;++i)ans+=b[i];
	printf("%lld",ans);
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define pb push_back
#define xx first
#define yy second
#define sz(x) ((int)x.size())
#define all(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define repp(i,k,n) for(int i=k;i<n;i++)
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> iv;
typedef pair<int,int> iip;
typedef map<int,int> mii;
template <typename T>
void dbg(T t){cerr<<t<<endl ;}
template<typename T, typename... Args>
void dbg(T t, Args... args) {cerr << t <<" ";dbg(args...) ;}


int main(){
	int n;
	cin>>n;
	cout<<"ABC"<<n;
	return 0;
}

Measured memory_bytes: 256
import Control.Monad

main = do
  n <- readLn
  cards <- replicateM n $ fmap ((\(t:h:_) -> (t,h)) . words) getLine
  putStrLn . (\(t,h) -> (show t) ++ " " ++ (show h)) $ solve3 cards

data ResultOneGame = TWin | HWin | Draw deriving Show

compereDict ([],[]) = Draw
compereDict ([],_) = HWin
compereDict (_,[]) = TWin
compereDict ((t:ts), (h:hs)) = case t `compare` h of
                                 GT -> TWin
                                 LT -> HWin
                                 EQ -> compereDict (ts, hs)

solve3 :: [(String,String)] -> (Int,Int)
solve3 list = foldl f (0,0) list
  where
    f :: (Int,Int) -> (String, String) -> (Int,Int)
    f (tScore, hScore) (tCard, hCard) = case compereDict (tCard, hCard) of
                                         TWin -> (tScore+3, hScore)
                                         HWin -> (tScore, hScore+3)
                                         Draw -> (tScore+1, hScore+1)



Measured memory_bytes: 4392
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){

    int N,A;
    cin >>N;
    vector<int> vec(N);
    vector<int> ori(N);
    for(int i=0;i<N;i++){ 
        cin >> A;
        vec[i] = A;
        ori[i] = A;
    }
 
    sort(vec.begin(),vec.end(),greater<int>());
    
    for(int i=0;i<N;i++){
        for(int j=0;j<N;j++){
            
            if(ori[i] != vec[j]){
                cout << vec[j] << endl;
                break;
            }
            else if(ori[i] == vec[j]){
                cout << vec[j+1] << endl;
                break;
            }
        }
    }
}

Measured memory_bytes: 4756
#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
#define emp emplace
 
using namespace std;
using ll = long long int;
using ii = pair<int, int>;
 
const int MOD = 1000 * 1000 * 1000 + 7;
const int N = 2*100000;

int main()
{
    int n; ll k;cin>>n>>k;
    ll arr[n][n], temp[n][n], ans[n][n];

    for (int i = 0; i < n; ++i)
    {
        for (int j = 0; j < n; ++j)
        {
            cin>>arr[i][j];
            ans[i][j] = arr[i][j];
        }
    }

    stack<ll> s, t;

    while(k>1){
        s.push(1);
        t.push(k%2);
        k /= 2;
    }

    while(!s.empty()){
        for (int i = 0; i < n; i++) 
        { 
            for (int j = 0; j < n; j++) 
            { 
                temp[i][j] = 0; 
                for (k = 0; k < n; k++) 
                    temp[i][j] = (temp[i][j] + ans[i][k] * ans[k][j])%MOD; 
            } 
        } 
        if(t.top()==1){
            for (int i = 0; i < n; i++) 
            { 
                for (int j = 0; j < n; j++) 
                { 
                    ans[i][j] = 0; 
                    for (k = 0; k < n; k++) 
                        ans[i][j] = (ans[i][j] + temp[i][k] * arr[k][j])%MOD; 
                } 
            } 
        }
        else
        {
            for (int i = 0; i < n; i++) 
            { 
                for (int j = 0; j < n; j++) 
                {  
                        ans[i][j] = temp[i][j]; 
                } 
            }    
        }
        s.pop();
        t.pop();
    }

    ll count = 0;
    for (int i = 0; i < n; ++i)
    {
        for (int j = 0; j < n; ++j)
        {
            count += ans[i][j];
            count = count%MOD;
        }
    }
    cout<<count;
    return 0;
} 



Measured memory_bytes: 256
(function main() {
  let line = require('fs').readFileSync('/dev/stdin', 'utf8').trim().split('');
  // 初めの上昇と平坦を除去
  while (line.length > 0 && line[0] !== '\\') line.shift();
  // 終わりの下降と平坦を除去
  while (line.length > 0 && line[line.length - 1] !== '/') line.pop();

  let height_list = [0];
  let current_height = 0;
  line.forEach(function(e, i){
      if (e === '\\') current_height--;
      else if (e === '/') current_height++;
      height_list.push(current_height);
  });

  let h, sum = 0;
  let holes = [];
  while (height_list.length > 1) {
    if (h = makeHole(height_list)) {
      sum += h;
      holes.push(h);
    }
  }

  console.log(sum);
  console.log(holes.length && holes.length + ' ' + holes.join(' '));
})();

function makeHole(list) {
    begin = list.shift();
    if (list[0] < begin && begin <= list.reduce((a, b) => Math.max(a, b), -100000)) {
    let area = 0;
      while (!(list.length === 0 || begin <= list[0])) area += begin - list.shift();
      return area;
    }
    return 0;
}



Measured memory_bytes: 21004
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define ios ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define so sizeof
#define cf cout.flush()
int main()
{
    ios;
    ll n , x;
    cin >> n >> x;
    ll d1 = n;
    ll a = x, b  = n-x;
    ll t1 = min(a, b);
    ll t2  = max(a, b);
    a = t1 ;
    b = t2 ;
    ll sum = n;
    while(true)
    {
        if(b%a == 0){
            //cout<<"here a is "<<a <<" b is "<<b<<" sum is "<<sum<<endl;
            sum = sum + (b/a)*(2*a)-a;
            break;
        }

        ll times = b/a ;
        //cout << "sum is "<<sum << " a is "<<a <<" times is "<<times <<" b is "<<endl;
        sum = sum + 2*a*times;
        //cout <<" now sum is "<<sum<<endl ;
        b = b - times * a ;
        a = a ;
        //cout<<"now b is "<<b<<endl;
        ll t1 = min(a, b);
        ll t2  = max(a, b);
        a = t1 ;
        b = t2 ;
        //cout<<"finally a is "<<a<<" b is "<<b<<endl;
        continue;

    }
    cout<<sum<<endl;
    //cout<<"true sum is "<<3* (n-__gcd(n , x))<<endl;
    cf ;
    return 0 ;

}


Measured memory_bytes: 256
/*
       Hi there <3 
──────▄▀▄─────▄▀▄
─────▄█░░▀▀▀▀▀░░█▄
─▄▄──█░░░░░░░░░░░█──▄▄
█▄▄█─█░░▀░░┬░░▀░░█─█▄▄█

*/
#include <bits/stdc++.h>
#define MOD 1000000007
#define re return
#define fi first
#define se second
#define mp make_pair
#define pb emplace_back
#define all(x) x.begin(), x.end()
#define sz(x) ((int)(x).size())
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repa(i,a,n) for(int i=a;i<n;i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define rrepa(i,a,n) for (int i = n; i >= a; i--)
#define fill(x, y) memset(x, y, sizeof(x))
#define sqr(x) ((x) * (x))
#define sqrt(x) sqrt(abs(x))
#define unq(x) (x.resize(unique(all(x)) - x.begin()))
#define ba back()
#define popcount __builtin_popcountll
#define fastIO()                 \
    {                            \
        ios::sync_with_stdio(0); \
        cin.tie(0);              \
        cout.tie(0);             \
    }
#define in(x) \
    int x;    \
    cin >> x;
#define in1(x) \
    int x;     \
    cin >> x;  \
    x--;
#define inll(x) \
    ll x;       \
    cin >> x;
#define ins(x) \
    string x;  \
    cin >> x;

using namespace std;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<string> vs;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef vector<ll> vll;
typedef pair<double, double> pdd;
typedef long double LD;
typedef double D;

void Solve()
{
     ll n;
     cin>>n;
     unordered_map<ll,ll> m;
     ll total=0;
      for(ll i=0;i<n;i++)
     {
         ll temp;
         cin>>temp;
         m[temp]++;
         total+=temp;
     }
     ll q;
     cin>>q;

     for(ll i=0;i<q;i++)
     {
         ll b,c;
         cin>>b>>c;
         ll temp=0;
         temp= m[b]*b;
         ll count=m[b];
         m[c]+=m[b];
         m[b]=0;
         ll temp2=c*count;
         total=total -temp +temp2;
         cout<<total<<endl;
     }
} 

int main()
{
    fastIO();
    int t;
    t=1;
    while (t--)
    {
        Solve();
    }
    return 0;
}

Measured memory_bytes: 7100
#include<iostream>
#include<cstdio>
#include<string>
using namespace std;
int main(){
    string str;
    while(cin >> str){
        int cnt = 0;
        for(int i = 0;i < str.length();++i){
            if(cnt == 0&&str[i] == 'C')
                cnt ++;
            if(cnt == 1&&str[i] == 'F')
                cnt ++;
        }
        if(cnt == 2) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
}


Measured memory_bytes: 256