akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define rp(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;
    cin >> n;
    int sum=0,sqsum=0;
    rp(i,n){
        int d;
        cin >> d;
        sum += d;
        sqsum +=d*d;
    }
    cout << (sum*sum-sqsum)/2 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
int main(void){
    ll a,b,c,n,count=0;
    cin >>a>>b>>c>>n;
    
    if(n>=a){
        count=a;
        n=n-a;
    }
    else{
    count=n;
    n=0;
    }
   
    if(n>=b){
        n=n-b;
    }
    
    if(n>0)
        count=count-n;
    
    
    cout << count;
   
}

Measured memory_bytes: 3596
import java.util.Scanner;

public class Main {

    void run() {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] arr = new int[n];
        int max = 0;

        for (int i = 0; i < n; i++) {
            arr[i] = sc.nextInt();
            max = Math.max(arr[i], max);
        }

        int[] output = new int[n + 1];

        countingSort(arr, output, max);

        StringBuffer sb = new StringBuffer();
        for (int i = 1; i < output.length; i++) {
                sb.append(output[i]);
                sb.append(" ");
        }
        sb.setLength(sb.length() - 1);

        System.out.println(sb);

    }

    void countingSort(int[] A, int[] B, int k) {
        int[] C = new int[k + 1];
        for (int i = 0; i < C.length; i++) {
            C[i] = 0;
        }
        for (int j = 0; j < A.length; j++) {
            C[A[j]]++;
        }
        for (int i = 1; i < C.length; i++) {
            C[i] = C[i] + C[i - 1];
        }
        for (int j = A.length - 1; j >= 0; j--) {
            B[C[A[j]]] = A[j];
            C[A[j]]--;
        }
    }

    public static void main(String[] args) {
        new Main().run();
    }

}


Measured memory_bytes: 508736
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder.At_Coder_Beginner_Contest_169
{
    class D
    {
        static void Main(string[] args)
        {
            long N = long.Parse(Console.ReadLine());

            Console.WriteLine(Solve(N));
            //Console.ReadKey();
        }

        private static int Solve(long N)
        {
            if (N == 1)
            {
                return 0;
            }

            var primeList = GeneratePrime((long)Math.Sqrt(N));
            int count = 0;
            for (int i = 0; i < primeList.Count; i++)
            {
                long p = primeList[i];
                int e = 0;
                while (N % p == 0)
                {
                    e++;
                    N /= p;
                }

                //Console.WriteLine("p:" + p + ", e:" + e);

                int b = 1;
                while (b <= e)
                {
                    e -= b;
                    b++;
                    count++;
                }

                if (N < p)
                {
                    break;
                }
            }

            if (IsPrime(N))
            {
                count++;
            }

            return count;
        }

        public static bool IsPrime(long num)
        {
            if (num < 2) return false;
            else if (num == 2) return true;
            else if (num % 2 == 0) return false;

            double sqrtNum = Math.Sqrt(num);
            for (int i = 3; i <= sqrtNum; i += 2)
            {
                if (num % i == 0)
                {
                    return false;
                }
            }

            return true;
        }

        public static List<long> GeneratePrime(long max)
        {
            long prime;
            double sqrtMax = Math.Sqrt(max);
            var primeList = new List<long>();

            var list = new List<long>();
            list.Add(2);
            for (int i = 3; i <= max; i += 2)
            {
                list.Add(i);
            }

            do
            {
                prime = list.First();
                primeList.Add(prime);
                list.RemoveAll(n => n % prime == 0);
            } while (prime < sqrtMax);

            primeList.AddRange(list);

            return primeList;
        }
    }
}


Measured memory_bytes: 36696
#include <bits/stdc++.h>
#define ALL(v) v.begin(), v.end()
#define MOD 1000000007
#define INF 1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define req(i, j, n) for(int i = j; i <= (int)(n); i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
  vector<int> edge[100005]{};
 int fr1[100005];
  int fr2[100005];
int fr3[100005];
int fr4[100005];
int l1[100005];
int l2[100005];
int ans=0;
int cnt[100005];

void dfs1(int w, int l){
  fr1[w]=1;
  l1[w]=l;
  for(int j=0;j<edge[w].size();j++){
    int o=edge[w][j];
    if(fr1[o]==0){
      dfs1(o, l+1);}
  }
}

void dfs2(int w, int l){
  l2[w]=l;
  fr2[w]=1;
  for(int j=0;j<edge[w].size();j++){
    int o=edge[w][j];
    if(fr2[o]==0){
      dfs2(o, l+1);}
  }
}
  
void dfs3(int w ){
  fr4[w]=1;
  int z=max(l1[w], l2[w])-1;

  cnt[w]=z;
  
  for(int j=0;j<edge[w].size();j++){
    int o=edge[w][j];
    if(fr4[o]==0 && fr3[o]==0){
      dfs3(o);}
  }
}
  
  
  
  


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

  
  for(int i=1;i<=n;i++){
    int p,q;
    cin>>p>>q;
  edge[p].push_back(q);
    edge[q].push_back(p);
    fr1[i]=0;
    fr2[i]=0;
    fr3[i]=0;
    fr4[i]=0;
    l1[i]=0;
    l2[i]=0;
    cnt[i]=0;
  }
  
  
 
 
  
  dfs1(t, 0);
  dfs2(a, 0);
  

  
  int ans=0;
  for(int i=1;i<=n;i++){
    if(l1[i]>=l2[i]){
      fr3[i]=1;}
  }
  
  dfs3(t);
  
  for(int i=1;i<=n;i++){
    ans=max(ans, cnt[i]);}
     
  
  cout<<ans<<endl;
  
  

}


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

using namespace std;

int main()
{
    ios_base::sync_with_stdio(0);
    int n, m;
    cin >> n >> m;
    vector<int> a(n);
    int s = 0;
    for (int i = 0; i < n; ++i)
    {
        cin >> a[i];
        s += a[i];
    }
    sort(a.begin(), a.end());
    reverse(a.begin(), a.end());
    bool ok = true;
    for (int i = 0; i < m; ++i)
        if (a[i] * 4 * m < s)
            ok = false;
    if (ok)
        cout << "Yes";
    else
        cout << "No";
    return 0;
}


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

using namespace std;

#define int long long
using int64 = long long;

int N, M;
vector< int > g[100000];
bool used[100000];
int low[100000], ord[100000], comp[100000];
vector< pair< int, int > > bridge;

int build(int idx, int k = 0, int par = -1) {
  used[idx] = true;
  ord[idx] = k++;
  low[idx] = ord[idx];
  int cnt = 0;
  for(auto &to : g[idx]) {
    if(!used[to]) {
      ++cnt;
      k = build(to, k, idx);
      low[idx] = min(low[idx], low[to]);
      if(ord[idx] < low[to]) bridge.emplace_back(minmax(idx, to));
    } else if(to != par) {
      low[idx] = min(low[idx], ord[to]);
    }
  }
  return k;
}


using int64 = long long;


vector< vector< pair< int, pair< int, int > > > > uku;
map< pair< int, int >, int > cost;


vector< vector< pair< int, pair< int, int > > > > latte() {
  build(0);
  int k = 0;
  function< void(int, int) > dfs = [&](int idx, int par) {
    if(~par && ord[par] >= low[idx]) comp[idx] = comp[par];
    else comp[idx] = k++;
    for(auto &to : g[idx]) {
      if(comp[to] == -1) dfs(to, idx);
    }
  };
  memset(comp, -1, sizeof(comp));
  dfs(0, -1);
  vector< vector< pair< int, pair< int, int > > > > t(k);
  int ptr = 0;
  for(auto &e : bridge) {
    int x = comp[e.first], y = comp[e.second];
    int c = cost[minmax(e.first, e.second)];
    if(x != y) {
      t[x].emplace_back(y, make_pair(c, ptr));
      t[y].emplace_back(x, make_pair(c, ptr));
      ++ptr;
    }
  }
  return t;
}

int64 sum = 0;
int64 weight[100000];
pair< int64, pair< int, int > > ret(1LL << 60, make_pair(1333, 1333));

void usa(int idx, int par) {
  for(auto &e : uku[idx]) {
    if(e.first == par) continue;
    usa(e.first, idx);
    weight[idx] += weight[e.first];
    weight[idx] += e.second.first;
  }
  for(auto &e : uku[idx]) {
    if(e.first == par) continue;
    int64 Latte = weight[e.first];
    int64 Malta = sum - Latte - e.second.first;
    ret = min(ret, make_pair(llabs(Latte - Malta), bridge[e.second.second]));
  }
}

signed main() {
  cin >> N >> M;
  for(int i = 0; i < M; i++) {
    int u, v, w;
    cin >> u >> v >> w;
    --u, --v;
    g[u].emplace_back(v);
    g[v].emplace_back(u);
    cost[minmax(u, v)] = w;
    sum += w;
  }
  uku = latte();

  for(int i = 0; i < N; i++) {
    for(auto &j : g[i]) {
      if(i < j) {
        if(comp[i] == comp[j]) {
          weight[comp[i]] += cost[{i, j}];
        }
        ret = min(ret, make_pair(sum - cost[{i, j}], make_pair(i, j)));
      }
    }
  }

  usa(0, -1);

  cout << ret.second.first + 1 << " " << ret.second.second + 1 << endl;


}


Measured memory_bytes: 28888
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <list>
#include <set>
#include <numeric>
#include <map>
#include <math.h>
#include <iomanip>
#include <stack>
#include <queue>
#include <bitset>
#include <math.h>

#define INF 100100100

typedef long long int llint;

using namespace std;

typedef pair<llint, llint>Pii;

#define pi 3.141592653589793)
#define mod 1000000007

int main() {
	llint n;
	cin >> n;
	vector<llint>a(n+2);
	a[0] = 0;
	llint sum = 0;
	for (llint i = 1; i <= n; i++) {
		cin >> a[i];
		sum += abs(a[i - 1] - a[i]);
	}
	a[n + 1] = 0;
	sum += abs(a[n]);
	for (llint i = 1; i <= n; i++) {
		llint ans = sum;
		ans += abs(a[i - 1] - a[i + 1]);
		ans -= abs(a[i - 1] - a[i]);
		ans -= abs(a[i] - a[i + 1]);
		cout << ans << endl;
	}
	return 0;
}

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

using namespace std;

#define M 1000000007
#define pb push_back
#define f first
#define s second
#define rep(i, st, ed) for(int i=st; i<ed; i++)
#define repn(i, st, ed) for(int i=st; i<=ed; i++)
#define repb(i, ed, st) for(int i=ed; i>=st; i--)

typedef long long ll;
typedef unsigned long long int llt;
typedef long double ld;

const long double PI  =3.141592653589793238463;
const int N = 5e5 + 10;
const ll INF = 1LL << 60;

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


vector<int> g[N];
bool viss[N];
int vis[N];

// Normal DFS
void dfs(int curr, int par)
{
  for(auto x: g[curr])
    if(x != par)
      dfs(x, curr);
}

// DFS with visiting status
void dfs1(int curr, int par)
{
  viss[curr] = 1;
  for(auto x: g[curr])
    if(!viss[x])
      dfs1(x, curr);
}

// DFS with strongly connected component
void dfs2(int curr, int par, int num)
{
  vis[curr] = num;
  for(auto x: g[curr])
    if(vis[x] == 0)
      dfs2(x, curr, num);
}

// XOR from 0 to n
ll fxor(ll n)
{
  if(n < 0) return 0;
  if(n % 4 == 3) return 0;
  else if(n % 4 == 0) return n;
  else if(n % 4 == 1) return n^(n-1);
  else if(n%4 == 2) return n^(n-1)^(n-2);
}

// Power in logn with mod 1000000007
llt ppow(llt x, llt y)
{
  llt res = 1;
  while(y > 0){
    if(y&1)
      res = (res * x)%M;
    y = y >> 1;
    x = (x * x)%M;
  }
  return res;
}

// Factorial with dp
llt factdp[N];
llt fact(llt x)
{
  if(x == 0) return 1;
  if(x == 1) return 1;
  if(factdp[x] != -1) return factdp[x];
  return factdp[x] = (x*fact(x-1))%M;
}

// String return to base b
string ansConv ="";
void convert10tob(llt N, int b)
{
     if (N == 0)
        return;
     int x = N % b;
     N /= b;
     if (x < 0)
        N += 1;
     convert10tob(N, b);
     ansConv += to_string(x);
     return;
}

// Convert string to num wiht base b
llt convertstrtob(string a, int b)
{
  llt aa = 0;
  llt mul = 1;
  for(int i=a.length()-1; i>=0; i--)
  {
    int curr = a[i] - '0';
    aa += (curr * mul);
    mul *= b;
  }
  return aa;
}

// Union Find algo with array
// Find()
int findpar(int curr, int arr[])
{
  while(arr[curr] != curr) curr = arr[curr];
  return curr;
}
// Union()
void Union(int b, int spa, int arr[])
{
  while(arr[b] != b)
  {
    int c = arr[b];
    arr[b] = spa;
    b = c;
  }
  arr[b] = spa;
}

// Main Code

int main()
{
  int minn = INT_MAX;
  int maxx = INT_MIN;
  int n;
  cin>>n;
  rep(i, 0, n)
  {
    int a;
    cin>>a;
    chmin(minn, a);
    chmax(maxx, a);
  }
  cout<<(maxx-minn)<<endl;
  return 0;
}


Measured memory_bytes: 12160
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod = 1000000007;
const int INF = INT_MAX / 2;

int main(){
    int x1, y1, x2, y2; cin >> x1 >> y1 >> x2 >> y2;
    int a = x2 - x1;
    int b = y2 - y1;

    cout << x2 - b << " " << y2 + a << " " << x1 - b << " " << y1 + a << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(x) begin(x), end(x)
#define dbg(x) cerr << #x << " = " << x << endl
#define _ << ' ' <<
using namespace std;
using ll = long long;
using vi = vector<int>;


int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    vi f(m);
    iota(all(f), 1);
    for (int i = 0; i < n; ++i)
    {
        int k;
        cin >> k;
        vi g(k), r(k);
        for (int j = 0; j < k; ++j)
            cin >> g[j];

        sort(all(g));
        r.resize(set_intersection(all(f), all(g), r.begin()) - r.begin());
        f = r;
    }
    cout << f.size();
}


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

int main() {
  int n;
  set<char> s;
  cin>>n;
  for (int i = 0; i < n; ++i) {
    char c;
    cin>>c;
    s.insert(c);
  }
  puts(s.size()==3?"Three":"Four");
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<bitset>
using namespace std;
typedef long long int ll;
static const int MAX_N = 40;
static const int MAX_X = 5;
static const int MAX_Y = 7;
static const int MAX_Z = 5;
static const int MOD = 1000000007;

int N, X, Y, Z;
ll memo[MAX_N][1 << (MAX_X + MAX_Y + MAX_Z - 1)];

int main(){
	cin >> N >> X >> Y >> Z;
	fill(memo[0], memo[N], 0);
	for(int i = 1; i <= 10; i++){
		memo[0][1 << (i - 1)]++;
	}
	for(int i = 0; i < N - 1; i++){
		for(int j = 0; j < (1 << (MAX_X + MAX_Y + MAX_Z - 1)); j++){
			for(int k = 1; k <= 10; k++){
				if(memo[i][j] == 0) continue;
				int num = j;
				num = num << k;
				num |= (1 << (k - 1));
				if((num & (1 << (X + Y + Z - 1))) && (num & (1 << (Y + Z - 1))) && (num & (1 << (Z - 1)))) continue;
				num &= ((1 << (MAX_X + MAX_Y + MAX_Z - 1)) - 1);
				memo[i + 1][num] += memo[i][j];
				memo[i + 1][num] %= MOD;
			}
		}
	}
	ll cnt = 0;
	for(int i = 0; i < (1 << (MAX_X + MAX_Y + MAX_Z - 1)); i++){
		cnt += memo[N - 1][i];
		cnt %= MOD;
	}
	ll num = 1;
	for(int i = 1; i <= N; i++){
		num *= 10;
		num %= MOD;
	}
	cout << (num - cnt + MOD) % MOD << endl;
	return 0;
}

Measured memory_bytes: 20736
N = int(input())
P = list(map(int, input().split()))
cnt = 1
min_P = P[0]
for i in range(1, N):
        #print('P[i]', P[i])
        #print('min_P', min_P)
        #print('cnt',cnt)
        if min_P>=P[i]:
            cnt += 1
            min_P = P[i]

print(cnt)

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

using namespace std;
typedef long long  ll;
#define rep(i,s,n)for(ll i = s;i<n;i++)

int main() {
	int N; cin >> N;
	int p = 0;

	rep(i, 0, 100000) {
		if (i*i <= N) {
			p = i * i;
		}
		else {
			break;
		}
	}
	cout << p << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define pi acos(-1.0)
#define eps 1e-9
#define ll long long
#define ull unsigned long long
#define sf scanf
#define pf printf
#define nl printf("\n")
#define ps(s) printf("%s",s.c_str())
#define inf (ll)1e15
#define mod 1000000007
#define mem(x,val) memset(x,val,sizeof x)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend() 
#define sz(x) (int)(x).size()
#define test_case int ___t;scanf("%d", &___t);for(int cs=1;cs<=___t;cs++)

using namespace __gnu_pbds;
using namespace std;

inline string getString(int n){char ch[n+5];sf(" %s",ch);return string(ch);}
inline string getLine(int n)
{char ch[n+5];fgets(ch,n+5,stdin);string s=string(ch);s.pop_back();return s;}

//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> new_data_set;
typedef pair<ll,int>pli;

const int S=100100;
int main()
{
    //#ifndef ONLINE_JUDGE
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    //#endif
   	
   	int n;
   	while(~sf("%d",&n))
   	{
   		ll ara[3*n+5];
   		for(int i=1;i<=3*n;i++)sf("%lld",&ara[i]);


   		ll sum;

   		ll mx[2*n+5];
   		set<pli>mxSet;
   		sum=0;
   		for(int i=1;i<=2*n;i++)
   		{
   			mxSet.insert(pli(ara[i],i));
   			sum+=ara[i];
   			if(i==n)mx[i]=sum;
   			else if(i>n)
   			{
   				pli mnElement=*mxSet.begin();
   				mxSet.erase(*mxSet.begin());

   				sum-=mnElement.first;
   				mx[i]=sum;
   			}
   		}

   		ll mn[2*n+5];
   		set<pli>mnSet;
   		sum=0;
   		for(int i=3*n;i>n;i--)
   		{
   			mnSet.insert(pli(ara[i],i));
   			sum+=ara[i];
   			if(i==2*n+1)mn[i]=sum;
   			else if(i<=2*n)
   			{
   				pli mxElement=*mnSet.rbegin();
   				mnSet.erase(*mnSet.rbegin());

   				sum-=mxElement.first;
   				mn[i]=sum;
   			}
   		}

   		ll ans=-inf;
   		for(int i=n;i<=2*n;i++)
   		{
   			ll mxSum=mx[i];
   			ll mnSum=mn[i+1];
   			ans=max(ans,(mxSum-mnSum));
   		}
   		pf("%lld\n",ans);
   	}
    return 0;
}
 






































Measured memory_bytes: 20204
#include "bits/stdc++.h"
// Begin Header {{{
#define all(x)          (x).begin(), (x).end()
#define rep(i, s, n)    for (i64 i = (s), i##_limit = (n); i < i##_limit; ++i)
#define repr(i, s, t)   for (i64 i = (s), i##_limit = (t); i >= i##_limit; --i)
#define var(type, ...)  type __VA_ARGS__; read(__VA_ARGS__);
#ifndef DBG
#define dump(...)
#endif
using namespace std;
using i64 = int_fast64_t;
using pii = pair<i64, i64>;
template <class T, class U> inline bool chmax(T &a, const U &b) { return b > a && (a = b, true); }
template <class T, class U> inline bool chmin(T &a, const U &b) { return b < a && (a = b, true); }
constexpr int INF  = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;

template <class T>
inline vector<T> makeV(const T &initValue, size_t sz) {
    return vector<T>(sz, initValue);
}

template <class T, class... Args>
inline auto makeV(const T &initValue, size_t sz, Args... args) {
    return vector<decltype(makeV<T>(initValue, args...))>(sz, makeV<T>(initValue, args...));
}

template <class T>
inline istream& operator>> (istream &is, vector<T> &vec) {
    for (auto &e : vec) is >> e;
    return is;
}

inline void read() {}

template <class Head, class... Tail>
inline void read(Head &head, Tail&... tail) { cin >> head; read(tail...); }

inline void print() { cout << "\n"; }

template <class Head, class... Tail>
inline void print(Head &&head, Tail&&... tail) {
    cout << head;
    if (sizeof...(tail)) cout << ' ';
    print(forward<Tail>(tail)...);
}

template <class T>
inline ostream& operator<< (ostream &os, const vector<T> &vec) {
    static constexpr const char *delim[] = { " ", "" };
    for (const auto &e : vec) os << e << delim[&e == &vec.back()];
    return os;
}

template <class Container>
struct Rev {
    Container &x_;
    inline Rev(Container &x): x_(x) {}
    inline auto begin() { return rbegin(x_); }
    inline auto end() { return rend(x_); }
};
// }}} End Header

signed main() {
    ios_base::sync_with_stdio(false); cin.tie(nullptr);

    var(int, N);

    vector<i64> p(N);
    rep(i, 0, N) {
        read(p[i]);
        --p[i];
    }


    vector<int> a(N), b(N);
    rep(i, 0, N) {
        const int x = 30000 * (i + 1);
        a[i] = b[N - 1 - i] = x;
    }

    rep(i, 0, N) {
        a[p[i]] += i;
    }

    print(a);
    print(b);

    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
using namespace std;
using ll = long long;
const ll mod = 1e9 + 7;

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

ll dp[100005][4];

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

    dp[0][0] = 1;
    rep(i, s.size()){
        // 選ばない場合
        rep(j, 4){
            if(s[i] != '?') add(dp[i+1][j], dp[i][j]);
            else add(dp[i+1][j], (dp[i][j] * 3) % mod);
        }

        // 選ぶ場合
        if(s[i] == '?' || s[i] == 'A') add(dp[i+1][1], dp[i][0]);
        if(s[i] == '?' || s[i] == 'B') add(dp[i+1][2], dp[i][1]);
        if(s[i] == '?' || s[i] == 'C') add(dp[i+1][3], dp[i][2]);
    }

    cout << dp[s.size()][3] << endl;
}

Measured memory_bytes: 3712
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define INF 1<<30
#define LINF 1LL<<60

/*
 <url:https://github.com/kei1107/algorithm/blob/master/template/template_for_problems.cpp>
 ?????????============================================================
 n????????´??°a1, a2, ???, an??¨n????????´??°p1, p2, ???, pn?????´??°m?????????????????????
 k???????????´??°ak???pk[%]????¢??????§?????¶?????¨??????????????????k(1 ??? k ??? n)?????????????????????
 0?????\???n?????\????????´??°??????????????????1??\???m??\????????´??°????????§???
 ?????°????????´??°????°?????????¨???1?????§?????????????????????????????°????????????????±??????????
 =================================================================
 ?§£??¬=============================================================
 ????????????( := ????????????????????????)
 ================================================================
 
 
 <reference:http://d.hatena.ne.jp/simezi_tan/20130522/1369203086>
 
 ???????????????????????????????????? < rep(j, 0, n) if(j & (1 << i)) f[j] -= f[j ^ (1 << i)]; >
 ????????????????????????????????? <rep(j, 0, n) if(j & (1 << i)) f[j] += f[j ^ (1 << i)];>
 */

inline ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
inline ll lcm(ll a, ll b) { return a / gcd(a, b)*b; }

int main(void) {
    cin.tie(0); ios::sync_with_stdio(false);
    ll n,m; cin >> n >> m;
    vector<ll> a(n);
    vector<long double> p(n);
    for(auto &x:a) cin >> x;
    for(auto &x:p) {
        cin >> x;
        x/=100;
    }
    
    // Preprocessing
    // probability
    // ??????????±???????????????????????????£??????????????????
    vector<long double> dp1((1<<n),1.0);
    for(int i = 0; i < n;i ++){
        for(int j = 0; j < (1<<n);j++){
            if((j>>i)&1){
                dp1[j] *= p[i];
            }else{
                dp1[j] *= (1-p[i]);
            }
        }
    }
    
    // ????????????????????????
    /* ?????????????????? +=??¨?????? -=???????????°??????*/
    vector<ll> dp2((1<<n),0);
    for(int i = 0; i <(1<<n);i++){
        ll LCM = 1;
        for(int j = 0; j < n;j++){
          //  if(LCM > m) continue;
            if((i>>j)&1){
                ll tmp = a[j] / gcd(LCM,a[j]);
                if(1.0 * tmp * LCM < 1.5e18) LCM*=tmp;
                else LCM = m+1;
            }
        }
        dp2[i] = m/LCM;
    }
    for(int i = 0; i < n;i++){
        for(int j = 0;j < (1<<n);j++){
            if((j>>i)&1){
                dp2[j] -= dp2[j^1 << i];
            }
        }
    }
    
    long double res = 0;
    for(int i = 0; i < (1<<n);i++){
        res += dp1[i] * (m - abs(dp2[i])); // ??¶???????????¨???
    }
    cout << fixed << setprecision(10) << res << endl;
    return 0;
}

Measured memory_bytes: 27468
parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)
function main()
    n=parseInt(readline())
    x=parseMap(split(readline()))
    ans=1000000000
    for i in 1:100
        res=0
        for j in x
            res+=(j-i)^2
        end
        ans=min(ans,res)
    end
    println(ans)
end
main()

Measured memory_bytes: 113020
#!/usr/bin/env python3
import sys


def solve(X: int):
    ans = X // 500 * 1000
    X %= 500
    return ans + (X // 5 * 5)


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    X = int(next(tokens))  # type: int
    print(solve(X))

if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <fstream>
#include <string>
#include <math.h>
#include <cstdlib>
#include <cstdint>
#include <istream>
#include <sstream>
#include <cctype>
#include <functional>
#include <iomanip>
#define rep(i,N) for(ll i=0;i<N;i++)
#define disp(a) cout << a << endl;
#define PI 3.1415926535897932384626433
//cout << fixed << setprecision(20) << ** << endl;
typedef long long ll;
using namespace std;
double deg2rad(double degree)
{
    return degree * PI / 180.0000000000;
}
int main()
{
	vector<int>V;
	ll t;
	cin>>t;
	V.push_back(t);
	cin>>t;
	V.push_back(t);
	cin>>t;
	V.push_back(t);
	cin>>t;
	V.push_back(t);
	sort(V.begin(),V.end());
	if(V[0]==1&&V[1]==4&&V[2]==7&&V[3]==9){
		cout<<"YES"<<endl;
	}
	else{
		cout<<"NO"<<endl;
	}

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(i64 (i) = (s);(i) < (e);(i)++)
#define all(x) x.begin(),x.end()
#define STRINGIFY(n) #n
#define TOSTRING(n) STRINGIFY(n)
#define PREFIX "#" TOSTRING(__LINE__) "| "
#define debug(x) \
{ \
  std::cout << PREFIX << #x << " = " << x << std::endl; \
}

std::ostream& output_indent(std::ostream& os, int ind) {
  for(int i = 0; i < ind; i++) os << " ";
  return os;
}

template<class S, class T> std::ostream& operator<<(std::ostream& os, const std::pair<S, T>& p);
template<class T> std::ostream& operator<<(std::ostream& os, const std::vector<T>& v);

template<class S, class T> std::ostream& operator<<(std::ostream& os, const std::pair<S, T>& p) {
  return (os << "(" << p.first << ", " << p.second << ")");
}
template<class T> std::ostream& operator<<(std::ostream& os, const std::vector<T>& v) {
  os << "[";
  for(int i = 0;i < v.size();i++) os << v[i] << ", ";
  return (os << "]");
}

template<class T>
static inline std::vector<T> ndvec(size_t&& n, T val) { return std::vector<T>(n, std::forward<T>(val)); }
template<class... Tail>
static inline auto ndvec(size_t&& n, Tail&&... tail) {
  return std::vector<decltype(ndvec(std::forward<Tail>(tail)...))>(n, ndvec(std::forward<Tail>(tail)...));
}
template<class Cond> struct chain {
  Cond cond; chain(Cond cond) : cond(cond) {}
  template<class T> bool operator()(T& a, const T& b) const { if(cond(a, b)) { a = b; return true; } return false; }
};
template<class Cond> chain<Cond> make_chain(Cond cond) { return chain<Cond>(cond); }

int main() {
  string s, t;
  cin >> s >> t;
  i64 ans = 0;
  rep(i,0,s.size()) {
    if(s[i] != t[i]) {
      ans++;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 3832
N = int(input())
a = list(map(int, input().split()))

def f(a, b, c):
    if a ^ b == c and a ^ c == b and b ^ c == a:
        return True
    else:
        return False

if N % 3 != 0:
    x = a[0]
    for i in range(len(a)):
        if a[i] != x:
            print("No")
            exit()
    if f(x, x, x):
        print("Yes")
    else:
        print("No")

else:
    flag = 0
    x = [-1, -1, -1]
    for i in range(len(a)):
        if a[i] not in x:
            if flag == 3:
                print("No")
                exit()

            x[flag] = a[i]
            flag += 1

    if flag == 3:
        if f(x[0], x[1], x[2]) and a.count(x[0]) == a.count(x[1]) == a.count(x[2]):
            print("Yes")
        else:
            print("No")
    elif flag == 1:
        if f(x[0], x[0], x[0]):
            print("Yes")
        else:
            print("No")
    else:
        if a.count(x[0]) == 2 * a.count(x[1]) and f(x[0], x[0], x[1]):
            print("Yes")
        elif a.count(x[1]) == 2 * a.count(x[0]) and f(x[0], x[1], x[1]):
            print("Yes")
        else:
            print("No")







Measured memory_bytes: 14116
h, m, H, M, K = map(int, input().split())

if M >= m :
    k = (H - h) * 60
    k += M - m
    
else :
    k = (H - h - 1) * 60
    k += 60 - m
    k += M
    
if k - K <= 0 :
    print(0)
else :
    print(k - K)

Measured memory_bytes: 61588
#include <bits/stdc++.h>
#include <boost/dynamic_bitset.hpp>

using namespace std;

#define INF 100000000
#define YJ 1145141919
#define INF_INT_MAX 2147483647
#define INF_LL 9223372036854775
#define INF_LL_MAX 9223372036854775807
#define EPS 1e-10
#define MOD 1000000007
#define MOD9 998244353
#define Pi acos(-1)
#define LL long long
#define ULL unsigned long long
#define LD long double

#define int long long

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(a)  begin((a)), end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())

const int MAX_N = 205;
const int MAX_X = 100005;

int N, X;
int S[MAX_N];

int dp[MAX_N][MAX_X];

signed main()
{
  cin >> N >> X;
  REP(n,N) {
    cin >> S[n];
  }

  sort(S, S+N, greater<int>());

  memset(dp, 0, sizeof(dp));

  dp[0][X] = 1;

  REP(n,N) {
    REP(x,X+1) {
      //使う
      dp[n+1][x%S[n]] += dp[n][x]; dp[n+1][x%S[n]] %= MOD;

      //使わない
      dp[n+1][x] += dp[n][x] * (N-n-1); dp[n+1][x] %= MOD;
    }
  }

  int ans = 0;
  REP(x,X+1) {
    ans += dp[N][x]*x;
    ans %= MOD;
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 160512
#include<iostream>
#include<string>
#include<cstdio>
using namespace std;
int main(){
  string s;
  cin >> s;
  string tmp;
  int N=0;
  
  tmp = s.substr(0, 1);
  N++;
  int i=1, l=1;
  while((i+l)<=s.size()){
    if(tmp != s.substr(i,l)){
      N++;
      tmp = s.substr(i,l);
      i+=l;
      l=1;
    }
    else l++;
  }
  
  printf("%d\n", N);
  return 0;
}

Measured memory_bytes: 640
import java.lang.Exception

fun main(args:Array<String>?): Unit {
    repeat(readLine()!!.trim().toInt()){
        println(readLine()!!.trim().split(' ').map(String::asMCXI).sum().toMCXI())
    }
}
fun String.asMCXI(): Int {
    fun sub(i: Int, digit: Int = 1): Int {
        return when{
            i >= this.length -> 0
            this[i].isDigit() -> sub(i + 1, this[i] - '0')
            else -> when(this[i]) {
                'm' -> 1000 * digit
                'c' -> 100 * digit
                'x' -> 10 * digit
                'i' -> digit
                else -> throw Exception()
            } + sub(i + 1)
        }
    }
    return sub(0)
}
fun Int.toMCXI(): String {
    val digit = listOf('m' to 1000, 'c' to 100, 'x' to 10, 'i' to 1)
    var rest = this
    var result = ""
    for ((c, d) in digit){
        if (rest >= d){
            if (rest / d == 1){
                result += c
            }else {
                result += (rest / d).toString() + c
            }
            rest %= d
        }
    }
    return result
}


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

#define ll long long
#define PB push_back
#define PII pair<int, int>
#define MP make_pair
#define all(x) x.begin(), x.end()
#define REP(x, y, z) for(int x = (y); x <= (z); x++)
#define REPP(x, y, z) for(int x = (y); x >= (z); x--)
#define F first
#define S second
#define MSET(x, y) memset(x, y, sizeof(x)) 
#define EB emplace_back
#define maxn 100000+5

//structure

//declaration
bool flag[maxn];
int wa[maxn];
//functions

int main(void)
{
	#ifdef DBG
	freopen("in.in", "r", stdin);
	freopen("out.out", "w", stdout);
	#endif

    
	ll AC = 0, WA = 0;
  	ll n, m;
  	ll tmp;
 	string str;

  	while(cin >> n >> m)
    {
        AC = WA = 0;
        memset(flag, false, sizeof(flag));
        MSET(wa, 0);
        for(ll i = 0; i < m; i++)
        {
            cin >> tmp >> str;
        
            if(str == "WA" && !flag[tmp])
                wa[tmp]++;
            if(str == "AC" && !flag[tmp])
            {
                AC++;
                flag[tmp]=true;
            }
        }

        for(ll i = 1; i <= n; i++)
        {
            if(flag[i])
                WA+=wa[i];
        }
    
        cout << AC << ' ' << WA << '\n';
    }
  
   
	return 0;
}


Measured memory_bytes: 768
#include <iostream>                                     
using namespace std;                                    
                                                        
int main() {                                            
  int a, b;                                             
  cin >> a >> b;                                        
  if (a<b) {                                            
    cout << "a < b" << endl;                            
  } else if (a>b) {                                     
    cout << "a > b" << endl;                            
  } else {                                              
    cout << "a == b" << endl;                           
  }                                                     
  return 0;                                             
}                                                       
                

Measured memory_bytes: 3100
"use strict";
process.stdin.resume();
process.stdin.setEncoding("utf8");
var reader = require("readline").createInterface({
  input: process.stdin,
  output: process.stdout
});

reader.on("line", line => {
  const lines = line.split(/\s/).map(i => parseInt(i));
  const a = lines[0], b = lines[1], t = lines[2];
  console.log(parseInt(t / a) * b);
});


Measured memory_bytes: 7628
m,d = map(int, input().split())

ans = 0

for i in range(m):
    for j in range(d):
        d10 = int((j+1)/10)
        d1 = j+1-d10*10
        if d1 >= 2 and d10 >= 2 and d1*d10 == i+1:
            ans += 1
print(ans)

Measured memory_bytes: 3060
#[allow(unused_imports)]
use std::collections::HashMap;

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

#[allow(dead_code)]
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

const MOD : usize = 1000_000_007;

fn main() {
    let nm = read_vec::<usize>();
    let n = nm[0];
    let m = nm[1];
    let mut amap = HashMap::new();
    let mut prev = 0;
    for _i in 0..m {
        let ai = read::<usize>();
        if ai <= prev {
            println!("0");
            return;
        }
        let key = ai - 1 - prev;
        let count = amap.entry(key).or_insert(0);
        *count += 1;
        prev = ai + 1;
    }
    let key = n - prev;
    {
        let count = amap.entry(key).or_insert(0);
        *count += 1;
    }
    let answer = solve(n, &mut amap);
    println!("{}", answer);
}

fn solve(n: usize, aset:&HashMap<usize, i32>) -> usize {
    if n <= 1 {
        return 1;
    }



    let mut c : usize= 1;
    let mut f0 :usize= 0;
    let mut f1 :usize = 1;
    for i in 1..n+1 {
        //println!("i={}", i);
        let f : usize = f0 + f1;
        if let Some(count) = aset.get(&i) {
            for _j in 0..*count {
                c *= f;
                c %= MOD;
            }
            //aset.remove(&i);
            //println!("  c -> {}", c);
        }
        f0 = f1;
        f1 = f % MOD;
    }
    
    return c;
}


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


int main(){
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  int n;
  cin>>n;
  int a[n];
  for(int i=0;i<n;i++){
    cin>>a[i];
  }
  int dp[n];
  dp[0]=0;
  dp[1]=abs(a[1]-a[0]);
  for(int i=2;i<n;i++){
  dp[i]=min(abs(a[i]-a[i-2])+dp[i-2],abs(a[i]-a[i-1])+dp[i-1]);
  }
  cout<<dp[n-1]<<endl;
 
  

}
       
  


Measured memory_bytes: 4424
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

#define MOD 1000000007
#define MOD2 998244353
#define int long long
#define double long double
#define EPS 1e-9
//#define PI 3.14159265358979

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

using namespace std;

template < typename T >
ostream &operator<<(ostream &os, const vector< T > &A) {
	for (int i = 0; i < A.size(); i++)
		os << A[i] << " ";
	os << endl;
	return os;
}
template <>
ostream &operator<<(ostream &os, const vector< vector< int > > &A) {
	int N = A.size();
	int M;
	if (N > 0)
		M = A[0].size();
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < M; j++)
			os << A[i][j] << " ";
		os << endl;
	}
	return os;
}

typedef pair< int, int > pii;
typedef long long ll;

struct edge {
	int from, to, d, c;
	edge(int _from = 0, int _to = 0, int _d = 0, int _c = 0) {
		from = _from;
		to = _to;
		d = _d;
		c = _c;
	}
	bool operator<(const edge &rhs) const {
		return (d == rhs.d) ? (c < rhs.c) : (d < rhs.d);
	}
};
struct aabb {
	int x1, y1, x2, y2;
	aabb(int x1, int y1, int x2, int y2) : x1(x1), y1(y1), x2(x2), y2(y2) {}
};

typedef vector< edge > edges;
typedef vector< edges > graph;
struct flow {
	int to, cap, rev, cost;
	flow(int to = 0, int cap = 0, int rev = 0, int cost = 0) : to(to), cap(cap), rev(rev), cost(cost) {}
};
typedef vector< vector< flow > > flows;

const int di[4] = {0, -1, 0, 1};
const int dj[4] = {-1, 0, 1, 0};
const int ci[5] = {0, 0, -1, 0, 1};
const int cj[5] = {0, -1, 0, 1, 0};
const ll LINF = LLONG_MAX / 2;
const int INF = INT_MAX / 2;
const double PI = acos(-1);

int pow2(int n) { return 1LL << n; }
template < typename T, typename U >
bool chmin(T &x, const U &y) {
	if (x > y) {
		x = y;
		return true;
	}
	return false;
}
template < typename T, typename U >
bool chmax(T &x, const U &y) {
	if (x < y) {
		x = y;
		return true;
	}
	return false;
}

struct initializer {
	initializer() {
		cout << fixed << setprecision(20);
	}
};
initializer _____;

int N, M, K, T, Q, H, W;
signed main() {
	cin >> N >> M;

	int l = 1, r = N / 2 + 1 + (N & 1);
	int d = M;
	rep(_, M) {
		cout << l << " " << l + d << endl;
		l++;
		swap(l, r);
		d--;
	}
	return 0;
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

using namespace std;
using ll = long long;

vector<vector<int> > friends;
vector<vector<int> > blocks;

vector<int> visited;
int dfs(int v, int id) {
  if (visited[v] != -1) {
    return 0;
  }
  visited[v] = id;
  int ans = 1;
  for (auto nv : friends[v]) {
    if (visited[nv] != -1) {
      continue;
    }
    ans += dfs(nv, id);
  }
  return ans;
}

int main() {
  int n, m, k;
  cin >> n >> m >> k;
  friends.assign(n, vector<int>());
  blocks.assign(n, vector<int>());
  visited.assign(n, -1);

  rep(i, m) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    friends[a].emplace_back(b);
    friends[b].emplace_back(a);
  }
  rep(i, k) {
    int c, d;
    cin >> c >> d;
    c--;
    d--;
    blocks[c].emplace_back(d);
    blocks[d].emplace_back(c);
  }
  int id = 0;
  vector<int> s;
  rep(i, n) {
    if (visited[i] != -1) {
      continue;
    }
    int cnt = dfs(i, id);
    s.emplace_back(cnt);
    id++;
  }
  rep(i, n) {
    int id = visited[i];
    int ans = s[id] - 1;
    for (auto f : friends[i]) {
      if (id == visited[f]) {
        ans--;
      }
    }
    for (auto b : blocks[i]) {
      if (id == visited[b]) {
        ans--;
      }
    }
    if (i != n - 1) {
      cout << ans << " ";
    } else {
      cout << ans << endl;
    }
  }
  return 0;
}


Measured memory_bytes: 15300
#include<bits/stdc++.h>
using namespace std;
int main(){
string S;
  int64_t K;
  cin>>S>>K;
  int64_t N=S.size();
  int64_t Min=min(N-1,K-1);
  char c='1';
  for(int64_t i=0;i<=Min;i++){
  if(S.at(i)!='1'){
   c=S.at(i); break;
  }
  
  }cout<<c<<endl;
 
return 0;
}


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

int main() {
	// your code goes here
	int n, m=0, max=0;
	string s;
	
	cin >> n >> s;
	
	while(s.size() != 0){
		if(s.front() == 'I') m++;
		else if(s.front() == 'D') m--;
		if(max <= m) max = m;
		s.erase(0, 1);
	}
	cout << max << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<map>
#define int long long int

using namespace std;

signed main(){

    int A, B, ans = 0;
    cin >> A >> B;

    if(A >= B){
        ans = ans + A;
        A = A - 1;
    }else{
        ans = ans + B;
        B = B - 1;
    }

    if(A >= B){
        ans = ans + A;
        cout << ans << endl;
        return 0;
    }else{
        ans = ans + B;
        cout << ans << endl;
        return 0;
    }


}

Measured memory_bytes: 256
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

class adj_list implements Comparable<adj_list>{
    public int u,k,d;
    public int[] v;
    public boolean find_flg = false;
    public int compareTo (adj_list a){return this.u - a.u;}
}

public class Main {

    private static ArrayList<adj_list>  ar = new ArrayList<adj_list>();

    private static final int U          =  0,
                             K          =  1,
                             UNREARCHED = -1,
                             START      =  1,
                             S          =  0;

    public static void main(String[] args) {

        //input
         Scanner sc = new Scanner(System.in).useDelimiter(System.getProperty("line.separator"));
         int      N = sc.nextInt();

         adj_list a;String[] s;
         for(int i = 0;i < N;i++){
             s = sc.next().split("\\s");
             a = new adj_list();
             a.u = Integer.parseInt(s[U]);
             a.k = Integer.parseInt(s[K]);
             a.v = new int[a.k];
             for(int j=0;j<a.k;j++){a.v[j] = Integer.parseInt(s[j+2]);}
             a.d = UNREARCHED;
             ar.add(a);
         }
         Collections.sort(ar);

         //calculation
       	 BFS();

         //output
         for (adj_list d:ar) {System.out.println(d.u + " " + d.d);}
    }

    private static void BFS(){
    	ArrayDeque<adj_list> q = new ArrayDeque<adj_list>();
    	adj_list s = get_list(START);
    	s.d = S;
    	s.find_flg = true;
    	q.add(s);

    	while(!q.isEmpty()){
    		adj_list u = q.poll();

    		for(int v:u.v){
    			adj_list a = get_list(v);
    			if(a.find_flg){continue;}
    			a.d = u.d+1;
    			a.find_flg = true;
    			q.add(a);
    		}
    	}
    }

    private static adj_list get_list(int id){
        adj_list ret = null;
        for(adj_list a:ar){if(a.u == id){ret = a;}}
        return ret;
    }
}

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

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

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()

int N;
vi g[200010];
int pr[200010];
int gr[200010];
int ot[200010];
set<int> st[200010];

int main() {
	cin >> N;

	rep(i, N) {
		int p;
		cin >> p;
		--p;
		g[p].pb(i);
		pr[i] = p; 
	}

	queue<int> que;

	memset(gr, -1, sizeof(gr));

	rep(i, N) {
		ot[i] = (int)g[i].size();
		if (ot[i] == 0) {
			que.push(i);
		}
	}

	while (!que.empty()) {
		int v = que.front(); que.pop();
		int x = 0;
		while (st[v].count(x)) ++x;
		gr[v] = x;

		if (--ot[pr[v]] == 0) {
			que.push(pr[v]);
		}

		st[pr[v]].insert(x);
	}

	int rt;
	rep(i, N) {
		if (gr[i] == -1) {
			rt = i;
			break;
		}
	}

	vi cand;

	rep(i, N) {
		if (!st[rt].count(i)) {
			cand.pb(i);
			if (cand.size() == 2) {
				break;
			}
		}
	}

	bool ok = 0;

	rep(ii, 2) {
		gr[rt] = cand[ii]; 
		int v = rt;

		while (pr[v] != rt) {
			int x = 0;
			while (st[pr[v]].count(x) || gr[v] == x) ++x;
			gr[pr[v]] = x;
			v = pr[v];
		}

		int x = 0;

		set<int> ss;
		for (int to : g[rt]) {
			ss.insert(gr[to]);
		}

		while (ss.count(x)) ++x;
		if (gr[rt] == x) {
			ok = 1;
			break;
		}
	}

	puts(ok ? "POSSIBLE" : "IMPOSSIBLE");

	return 0;
}

Measured memory_bytes: 28416
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<cmath>
using namespace std;
typedef long long ll;
ll mod = 1e9+7;
#define rep(i,n) for(int i = 0; i < (n); ++i)
int main() {
    string s, t;
    cin >> s >> t;
    if ( s == t ) {
        cout << "No" << endl;
        return 0;
    }
    sort(s.begin(), s.end());
    sort(t.begin(), t.end());
    reverse(t.begin(), t.end());
    vector<string> tmp;
    tmp.push_back(s);
    tmp.push_back(t);
//    cout << s << endl;
//    cout << t << endl;
    sort(tmp.begin(), tmp.end());
    if ( tmp[0] == s ) cout << "Yes" << endl;
    else               cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) (v).begin(),(v).end()
#define out(a) cout << (a) << endl
using namespace std;
using ll = long long;
int main(){
    int n, m;
    cin >> n >> m;
    vector<int> vec(n);
    vector<bool> good(n, true);
    for (int i=0; i<n; i++){
        cin >> vec[i];
    }
    int cnt=0;
    for (int i=0; i<m; i++){
        int a, b;
        cin >> a >> b;
        if (vec[a-1] > vec[b-1]){
            good[b-1] = false;
        }
        else if(vec[a-1] < vec[b-1]){
            good[a-1] = false; 
        }
        else{
            good[a-1] = false;
            good[b-1] = false;
        }
    }
    for (int i=0; i<n; i++){
        if(good[i]) cnt++;
    }
    out(cnt);
}

Measured memory_bytes: 3788
#include<bits/stdc++.h>
#define ll long long
#define double long double
#define rep(i,n) for(ll i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define pi (double) acos(-1)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;

int main() {
    ll n, ans = 0;
    cin >> n;
    vector<ll> a(n);
    rep(i, n)cin >> a.at(i);
    rep(i, 60){
        ll cnt0 = 0, cnt1 = 0;
        rep(j, n){
            if((1LL<<i)&a.at(j))cnt1++;
            else cnt0++;
        }
        ans += ((((((1LL<<i) % mod) * (cnt1 % mod)) % mod) * (cnt0 % mod))) % mod;
        ans %= mod;
    }
    cout << ans % mod<< endl;
}


Measured memory_bytes: 2560
#include <iostream>
#include <string>
using namespace std;
const char* solve() {
    size_t N, A, B, C, D;
    string S;
    cin >> N >> A >> B >> C >> D >> S;
    if (C < D) {
        if (S.find("##", B - 1) <= D - 1) return "No";
        if (S.find("##", A - 1) <= C - 1) return "No";
    }
    else {
        auto pos = S.find("...", B - 2);
        if (pos == string::npos || pos >= D - 1) return "No";
        if (S.find("##", B - 1) <= pos) return "No";
        S[pos + 1] = '#';
        if (S.find("##", A - 1) <= C - 1) return "No";
        if (S.find("##", pos + 1) <= D - 1) return "No";
    }
    return "Yes";
}
int main() {
    cout << solve() << endl;
}


Measured memory_bytes: 640
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int A[] = new int[N];
    int c[] = new int[100000];
    int zeroC=0;
    int eC=0;
    int oC=0;
    for(int i=0;i<N;i++){
      A[i]=sc.nextInt();
      c[A[i]-1]++;
    }
    Arrays.sort(c);
    for(int i=0;i<100000;i++){
      if(c[i]==0){
        zeroC++;
      }else if(c[i]>1&&c[i]%2==0){
        eC++;
      }else{
        oC++;
      }
    }
    if(eC%2==1){
      System.out.println(100000-zeroC-1);
    }else{
      System.out.println(100000-zeroC);
    }
    
  }
  

  
}

Measured memory_bytes: 58600
#include <iostream>
#include <cstring>
using namespace std;
int main(){
	string s;
	int n;
	while(cin>>s){
		int ans=0;
		for(int i=0;i<10;i++){
			n=s[i]-'0';
			if(i==0||i==9){
				ans+=n;
			}else if(i==1||i==8){
				ans+=n*9;
			}else if(i==2||i==7){
				ans+=n*36;
			}else if(i==3||i==6){
				ans+=n*84;
			}else ans+=n*126;
			ans%=10;
		}
		cout<<ans<<endl;
	}
}

Measured memory_bytes: 1180