akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Numerics;
using System.Linq;
using System.Collections.Generic;
using System.Text;

namespace debug
{

    class ProgramA
    {
        static void Main(string[] args)
        {
            //入力
            string s = Console.ReadLine();
            string t = Console.ReadLine();

            //もしABCならARC,ARCならABC
            for (int i = 0; i < s.Length; i++)
            {
                if (s[i] != t[i])
                {
                    Console.WriteLine("No");
                    return;
                }
            }

            Console.WriteLine("Yes");
        }
    }
}


Measured memory_bytes: 25896
import math
N = int(input())

ans = N
for i in range(N+1):
  count = 0
  t=i
  while t>0:
    count+=t%6
    t=math.floor(t/6)

  t = N-i

  while t>0:
    count += t%9
    t=math.floor(t/9)

  if ans>count:
    ans = count

print(ans)


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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

bool solve(int N,int Y){
    Y/=1000;


    int m=Y-N;
    if(m<0)return false;
    int x=m/9;
    if((m-9*x)%4!=0)x-=4-(m-9*x)%4;
    if(x<0)return false;
    int y=(m-9*x)/4;

    int z=N-x-y;
    if(z<0)return false;
    cout<<x<<" "<<y<<" "<<z<<endl;
    return true;
}

signed main(){
    int N,Y;cin>>N>>Y;
    if(!solve(N,Y))cout<<"-1 -1 -1"<<endl;



}


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

int main() {
	int right[4]={},left[4]={};
	float r,l;
	
	while(cin>>l>>r){
		if(r>=1.1)++right[0];
		else if(r>=0.6)++right[1];
		else if(r>=0.2)++right[2];
		else ++right[3];
		
		if(l>=1.1)++left[0];
		else if(l>=0.6)++left[1];
		else if(l>=0.2)++left[2];
		else ++left[3];
	}
	for(int i=0;i<4;++i){
		cout<<left[i]<<" "<<right[i]<<endl;
	}
	
	
	
	return 0;
}

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

#define MAX 10

int N;
double x[MAX];
string u[MAX];

int main() {
	cin >> N;
	for( int i = 0; i < N; i++ ) {
		cin >> x[i] >> u[i];
	}

	double ans = 0;
	for( int i = 0; i < N; i++ ) {
		if( u[i] == "JPY" ) {
			ans += x[i];
		}
		else {
			ans += (x[i] * 380000);
		}
	}

	cout << fixed << setprecision(5) << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#ifdef LOCAL111
#else
	#define NDEBUG
#endif
#include <bits/stdc++.h>
const int INF = 1e8;
using namespace std;

#define endl '\n'
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) int((a).size())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define RBP(i,a) for(auto& i : a)
#ifdef LOCAL111
	#define DEBUG(x) cout<<#x<<": "<<(x)<<endl
	template<typename T> void dpite(T a, T b){ for(T ite = a; ite != b; ite++) cout << (ite == a ? "" : " ") << *ite; cout << endl;}
#else
	#define DEBUG(x) true
	template<typename T> void dpite(T a, T b){ return; }
#endif
#define F first
#define S second
#define SNP string::npos
#define WRC(hoge) cout << "Case #" << (hoge)+1 << ": "
#define rangej(a,b,c) ((a) <= (c) and (c) < (b))
#define rrangej(b,c) rangej(0,b,c)
template<typename T> void pite(T a, T b){ for(T ite = a; ite != b; ite++) cout << (ite == a ? "" : " ") << *ite; cout << endl;}
template<typename T> bool chmax(T& a, T b){if(a < b){a = b; return true;} return false;}
template<typename T> bool chmin(T& a, T b){if(a > b){a = b; return true;} return false;}

typedef long long int LL;
typedef unsigned long long ULL;
typedef pair<int,int> P;
typedef pair<LL,LL> LP;

void ios_init(){
	//cout.setf(ios::fixed);
	//cout.precision(12);
#ifdef LOCAL111
	return;
#endif
	ios::sync_with_stdio(false); cin.tie(0);	
}

int main()
{
	ios_init();
	int n;
	while(cin >> n){
		vector<P> a(n);
		REP(i,n) cin >> a[i].F, a[i].S = i;
		sort(ALL(a));
		set<int> s;
		LL ans = 0;
		REP(i,n){
			auto ite = s.upper_bound(a[i].S);
			int l = -1, r = n;
			DEBUG(a[i].S);
			dpite(ALL(s));
			if(ite == s.end()){
				DEBUG(111);
				if(!s.empty()) l = *(--s.end());
			}else{
				DEBUG(222);
				r = *ite;
				if(ite != s.begin()){
					ite--;
					l = *ite;
				}	
			}
			DEBUG(a[i].F);
			DEBUG((a[i].S-l));
			DEBUG(r-a[i].S);
			DEBUG(l); DEBUG(r); DEBUG(LL(a[i].S-l)*(r-a[i].S)*a[i].F);
			ans += LL(a[i].S-l)*(r-a[i].S)*a[i].F;
			s.insert(a[i].S);
		}
		cout << ans << endl ;
	}
	return 0;
}


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

typedef long long ll;
#define PB push_back

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0);
	int n, m; cin >> n >> m;
	double votes = 0;
	vector<int> a;
	for (int i = 0; i < n; ++i) {
		int ai; cin >> ai; a.PB(ai);
		votes += ai;
	}
	int result = 0;
	for (auto i : a) {
		if (i >=( votes / (4 * m))) result++;
	}
	if (result >= m) cout << "Yes";
	else cout << "No";
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <stack>
#include <iomanip>
#include <numeric>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <cassert>
#include <map>
#include <set>
#include <vector>
#include <utility>
#include <queue>
#include <cmath>

#define BEGIN(x) x.begin()
#define END(x) x.end()
#define ALL(x) BEGIN(x), END(x)
#define PAIR make_pair
#define VEC(type) vector<type >
#define endl '\n'
#define FIR first
#define SEC second
#define PB push_back
#define SZ(x) ((int)x.size())

#define FOR(i, A, B) for(auto i = (A);i != (B); i++)
#define FORD(i, A, B) for(auto i = (A);i != (B); i--)

#define READRANGE(begin, end) FOR(it, begin, end) cin >> *it
#define READVEC(V) READRANGE(BEGIN(V), END(V))

using namespace std;

typedef long long lint;
typedef pair<int, int> Pii;
typedef pair<int, lint> Pil;
typedef pair<lint, lint> Pll;
typedef pair<lint, int> Pli;

template<class U, class V>
istream& operator >>(istream& in, pair<U, V>& pr) {
    return in >> pr.first >> pr.second;
}

template<class U, class V>
ostream& operator <<(ostream& out, pair<U, V>& p) {
    return out << p.first << " " << p.second;
}

template<class T>
ostream& operator <<(ostream& out, vector<T> vec) {
    for (T& e : vec)
        out << e << " ";
    return out << endl;
}

// ---- BEGIN LIBRARY CODE ----
// ---- END LIBRARY CODE ----
void io_init()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
};

void solveSingleCase(int caseNo)
{
    int A, B, C, X, Y;
    cin >> A >> B >> C >> X >> Y;

    lint ret = 1LL << 55;
    FOR(c, 0, 200010) {
        int x = c / 2, y = c / 2;
        lint cost = c * 1LL * C;
        if (X > x)
            cost += (X - x) * 1LL * A;
        if (Y > y)
            cost += (Y - y) * 1LL * B;
        ret = min(ret, cost);
    }

    cout << ret << endl;
};

int main(int argc, char **argv)
{
    io_init();

    // Actual program code starts here.
    int T = 1;
    // cin >> T;
    FOR(tcase, 1, T + 1) {
        solveSingleCase(tcase);
    }
    return 0;
};


Measured memory_bytes: 256
#include<iostream>

using namespace std;


int main(){
    int n;
    int i;
    int T[1000];
    int A[1000];
    long long iT,iA;
    long long rat1,rat2;
    long long mag1,mag2;
    long long ans;

    cin >> n;

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

    iA = A[0];
    iT = T[0];

    for( i = 1; i < n ; i++){
        rat1 = T[i];
        rat2 = A[i];
        while(1){
            if( iT * A[i] == iA * T[i] ){
                //cout << "iT:" << iT << " iA:" << iA << endl;
                break;
            }else{
                if(iT <= rat1 && iA <= rat2 ){
                    iT = rat1;
                    iA = rat2;
                }else{
                    if(iT > rat1){
                        mag1 = 0;
                        mag1 = iT/rat1;
                        if(iT % rat1 != 0){
                            mag1++;
                        }

                    }
                    if(iA > rat2){
                        mag2 = 0;
                        mag2 = iA/rat2;
                        if( iA % rat2 != 0){
                            mag2++;
                        }
                    }
                    if(mag1 >= mag2){
                        rat1 *= mag1;
                        rat2 *= mag1;
                    }else{
                        rat1 *= mag2;
                        rat2 *= mag2;
                    }
                }
            }
        }
    }

    ans = iA + iT;
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
  int N;
cin >> N;
  if(((N%4==1)&&(N<21))||((N%4==2)&&(N<14))||((N%4==3)&&(N<7)))
  {
  cout << "No";
  }else
  {
  cout << "Yes";
  }
  return 0;
}

Measured memory_bytes: 256
pub fn floor_sum(n: i64, m: i64, mut a: i64, mut b: i64) -> i64 {
    let mut ans = 0;
    if a >= m {
        ans += (n - 1) * n * (a / m) / 2;
        a %= m;
    }
    if b >= m {
        ans += n * (b / m);
        b %= m;
    }

    let y_max = (a * n + b) / m;
    let x_max = y_max * m - b;
    if y_max == 0 {
        return ans;
    }
    ans += (n - (x_max + a - 1) / a) * y_max;
    ans += floor_sum(y_max, a, m, (a - x_max % a) % a);
    ans
}


use std::io::Read;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();
    let mut input = buf.split_whitespace();

    for _ in 0..input.next().unwrap().parse().unwrap() {
        let n = input.next().unwrap().parse().unwrap();
        let m = input.next().unwrap().parse().unwrap();
        let a = input.next().unwrap().parse().unwrap();
        let b = input.next().unwrap().parse().unwrap();
        println!("{}", floor_sum(n, m, a, b));
    }
}


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

signed main() {
  int n;
  string s;
  cin >> n >> s;
  int ans = 0;
  rep(i, n) {
    vector<int> ft(26, 0), bk(26, 0);
    int tmp = 0;
    rep(j, i + 1) ft[s[j] - 'a']++;
    loop(j, i + 1, n) bk[s[j] - 'a']++;
    rep(i, 26) {
      if (0 < ft[i] && 0 < bk[i]) tmp++;
    }
    cmax(ans, tmp);
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String {
            bytes
                .by_ref()
                .map(|r| r.unwrap() as char)
                .skip_while(|c| c.is_whitespace())
                .take_while(|c| !c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

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

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

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

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

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

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

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

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

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

#[allow(unused_imports)]
use std::cmp::{min, max};

fn main() {
    input!{
        n: usize,
        s: String
    }
    if n >= 3200 {
        println!("{}", s);
    } else {
        println!("red");
    }
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
#define maxs(x, y) (x = max(x, y))
#define mins(x, y) (x = min(x, y))
using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;
using T = tuple<int, int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;

int main() {
  int x;
  cin >> x;
  cout << (x ? 0 : 1) << endl;
  return 0;
}


Measured memory_bytes: 3624
using System;
using System.Linq;
using System.Collections.Generic;

namespace d
{
    class Program
    {
        static void Main(string[] args)
        {
            var _ = Console.ReadLine().Split();
            var n = int.Parse(_[0]);
            var k = int.Parse(_[1]);
            var p = Console.ReadLine().Split().Select(i => double.Parse(i)).ToArray();

            var p2 = new double[p.Length+1];
            p2[0] = 0;

            for(var i = 1; i < p2.Length; i++){
                p2[i] = ((1.0 + p[i-1]) / 2.0) + p2[i-1];
            }

            var maxVal = 0.0;
            for(var i = k; i < p2.Length; i++){
                maxVal = Math.Max(p2[i] - p2[i-k], maxVal);
            }

            Console.WriteLine(string.Format("{0:f11}",maxVal));
        }
    }
}


Measured memory_bytes: 35548
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>
#include <assert.h>
#include <unordered_set>
#include <random>



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

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

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













#include <boost/multiprecision/cpp_int.hpp>
using namespace boost::multiprecision;

int main(){
    ios::sync_with_stdio(false);
    int n;
    char s[11];
    cin >> n;
    int128_t k[26];
    k[0] = 1;
    for(int i = 1; i < 26; i++){
        k[i] = k[i - 1] * 11;
    }
    map<int128_t, ll> mp;
    ll ans = 0;
    for(int i = 0; i < n; i++){
        cin >> s;
        int128_t x = 0;
        for(int j = 0; j < 10; j++){
            x += k[s[j] - 'a'];
        }
        ans += mp[x]++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 9600
import qualified Data.Text.Lazy as T
import qualified Data.Text.Lazy.IO as T
import qualified Data.Text.Lazy.Read as T
import qualified Data.Vector.Unboxed as VU

main :: IO ()
main = do
  n <- unsafeTextToInt <$> T.getLine :: IO Int
  as <- map unsafeTextToInt . T.words <$> T.getContents :: IO [Int]
  let
    as' = VU.fromList as :: VU.Vector Int
    x1 = VU.sum . VU.zipWith (*) (VU.iterateN n negate 1) $ as' :: Int
    xs = VU.prescanl subtract x1 . VU.map (2 *) $ as' :: VU.Vector Int
  putStrLn . unwords . map show . VU.toList $ xs

unsafeTextToInt :: T.Text -> Int
unsafeTextToInt s = case T.signed T.decimal s of
  Right (n, _) -> n
{-# INLINE unsafeTextToInt #-}


Measured memory_bytes: 7252
// ABC080-D
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define debugB(x, y) cerr<<#x<<": "<<bitset<y>(x) << endl;
#define line() cerr << "---------------" << endl;

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

const int NN = 1e5+10;
int N, C;
ll chan[32][NN];

int main() {
   cin >> N >> C;
   rep (i, N) {
      ll s, t, c;
      cin >> s >> t >> c;
      chan[c][s]++, chan[c][t+1]--;
   }

   for (int i = 1; i <= C; i++) {
      for (int j = 1; j < NN; j++) {
         chan[i][j] += chan[i][j-1];
      }
      for (int j = 1; j < NN; j++) {
         if (chan[i][j] >= 2) chan[i][j] = 1;
      }
   }

   for (int i = 1; i < NN; i++) {
      for (int j = 1; j <= C; j++) {
         chan[j][i] += chan[j-1][i];
      }
   }

   ll ans = 0;
   for (int i = 1; i < NN; i++) {
      ans = max(ans, chan[C][i]);
   }
   cout << ans << endl;

   return 0;
}

Measured memory_bytes: 24064
#include<bits/stdc++.h>
#define ll long long int
#define M 1000000007
#define mod 998244353
#define mp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define pi pair<ll,ll>
using namespace std;
const ll N=100010;

ll dis(ll x,ll y,ll n)
{
    return n-min(abs(x-y),n-abs(x-y));
}

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

    ll n,m;
    cin>>n>>m;
    ll ar[m];
    for(ll i=0;i<m;++i){
        cin>>ar[i];
    }
    ll ans=INT_MAX;
    for(ll i=0;i<m;++i){
        ans=min(ans,dis(ar[i],ar[(i+1)%m],n));
        ans=min(ans,dis(ar[i],ar[(i-1+m)%m],n));
    }
    cout<<ans;

    return (0);
}


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

template <typename T>
class segment_tree{
    T *tree;
    std::size_t len;
    T e;
    T (*op)(T, T);
public:
    segment_tree(std::size_t n, T (*f)(T, T), T ident=T{}) : op(f), e(ident){
        len = n;
        tree = new T[2 * len];
        for(std::size_t i = 1; i < 2 * len; ++i){
            tree[i] = ident;
        }
    }
    ~segment_tree(){
        delete[] tree;
    }

    void update(std::size_t pos, T val){
        tree[len + pos] = val;
        for(pos = (len + pos) / 2; pos > 0; pos >>= 1){
            tree[pos] = op(tree[2 * pos], tree[2 * pos + 1]);
        }
    }
    
    T query(std::size_t left, std::size_t right){
        left += len;
        right += len;

        T v_l = e, v_r = e;
        while(left < right){
            if(left  & 1) v_l = op(v_l, tree[left++]);
            if(right & 1) v_r = op(tree[right - 1], v_r);
            left >>= 1;
            right >>= 1;
        }
        return op(v_l, v_r);
    }
};

int main(){
    size_t n;
    string s;
    cin >> n;
    cin >> s;
    segment_tree<unsigned int> st{n, [](auto x, auto y){ return x | y; }};
    for(size_t i=0;i<n;++i) st.update(i, 1U << (s[i] - 'a'));
    int q;
    cin >> q;
    while(q--){
        int t;
        cin >> t;
        if(t == 1){
            int pos;
            char c;
            cin >> pos >> c;
            st.update(pos - 1, 1U << (c - 'a'));
        }else{
            int l, r;
            cin >> l >> r;
            cout << __builtin_popcount(st.query(l - 1, r)) << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 4868
from math import sqrt
from math import ceil
def prime_factorization(n):
    pfs = [1]
    i = 2
    for i in range(2, int(ceil(sqrt(n)))):
        while n % i == 0:
            pfs.append(i)
            n //= i
    if n > 0:
        pfs.append(n)
    return pfs


a, b = map(int, input().split())


def bit_search(pfs):
    m = len(pfs)
    ds = set([])
    for i in range(1 << m):
        d = 1
        for j in range(m):
            if i & (1 << m) > 0:
                d *= pfs[m]
        ds.add(d)
    return ds

def gcd(a, b):
    if b == 0:
        return a
    else:
        return gcd(b, a % b)

gcdab = gcd(a, b)
#print (gcdab)
pfsab = prime_factorization(gcdab)
#print (pfsab)
pfsabset =set(pfsab)
print (len(pfsabset))

Measured memory_bytes: 9124
use proconio::{input, fastout, marker::Usize1};
use std::collections::VecDeque;

#[fastout]
fn main() {
    input! {
        n: usize, q: usize,
        arr: [(Usize1, Usize1); n-1],
        ops: [(Usize1, usize); q],
    }

    let mut ans: Vec<usize> = vec![0; n];
    for &(p, x) in &ops {
        ans[p] += x;
    }

    let mut graph = vec![vec![]; n];
    for &(a, b) in &arr {
        graph[a].push(b);
        graph[b].push(a);
    }

    let mut visited = vec![false; n];
    let mut queue: VecDeque<usize> = VecDeque::new();
    queue.push_back(0);
    while let Some(cur) = queue.pop_front() {
        visited[cur] = true;
        for &c in &graph[cur] {
            if !visited[c] {
                queue.push_back(c);
                ans[c] += ans[cur];
            };
        }
    }

    for a in &ans {
        print!("{} ", a);
    }
}


Measured memory_bytes: 28900
#include <iostream>
#include <string>
#include <map>
#include <algorithm>
#define MSI map<string,int>
#define MIS map<int,string,greater<int> >
using namespace std;
int main()
{
  string word;
  MSI msi;
  MIS mis;
  while(cin >> word){
    msi[word]++;
    mis[word.length()] = word;
  }
  int arise = 0;
  for(MSI::iterator it = msi.begin(); it != msi.end(); it++){
    if(arise < (*it).second) {
      arise = (*it).second;
      word = (*it).first;
    }
  }
  cout << word << " " << mis.begin()->second << endl;
  return 0;
}

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

using ll = long long;
using P = pair<int, int>;

const int INF = 1e9;
const int MOD = 1e9 + 7;

// 4近傍、8近傍
int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};

int main() {
  // 入力
  int N;
  cin >> N;
  ll a[N], b[N];
  for (int i = 0; i < N; i++) cin >> a[i] >> b[i];

  // N項目から決めていく
  ll ans = 0;
  for (int i = N - 1; i >= 0; i--) {
    a[i] += ans;
    if (a[i] % b[i] == 0) continue;

    ll s = a[i] / b[i] + 1;
    ans += s * b[i] - a[i];
  }

  // 解答
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1920
n = int(input())
s = list(map(int,input().split()))
count = 0
 
def merge(a, left, mid, right):
    global count
    l = a[left:mid] + [float("inf")]
    r = a[mid:right] + [float("inf")]
    i = j = 0
    for k in range(left, right):
        if l[i] <= r[j]:
            a[k] = l[i]
            i += 1
        else:
            a[k] = r[j]
            j += 1
    count += right - left
 
def mergeSort(a, left, right):
    if left + 1 < right:
        mid = right + (left - right)//2
        mergeSort(a, left, mid)
        mergeSort(a, mid, right)
        merge(a, left, mid, right)
 
mergeSort(s, 0, n)
 
print(*s)
print(count)



Measured memory_bytes: 61644
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <map>
using namespace std;

int main(){
	string S;
	cin >> S;
	int A, B;
	A = ((S[0] - '0') *10) + (S[1] - '0');
	B = ((S[2] - '0') *10) + (S[3] - '0');
	bool AM = false, BM = false;
	if(A <= 12 && 1 <= A)AM = true;
	if(B <= 12 && 1 <= B)BM = true;
	if(AM && BM) cout << "AMBIGUOUS" << endl;
	else if(AM) cout << "MMYY" << endl;
	else if(BM) cout << "YYMM" << endl;
	else cout << "NA" << endl;	
}

Measured memory_bytes: 256
# ABC146a


def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**6)

    # map(int,input().split())
    yo = ['SUN', 'MON', 'TUE', 'WED', 'THU', 'FRI', 'SAT']
    #n = int(input())
    s = input()[:-1]
    if yo.index(s) == 0:
        print(7)
    else:
        print(7-yo.index(s))


if __name__ == '__main__':
    main()


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

int main(){
	int N;
	cin >> N ;
	bool left =(N/1000 == N%1000/100) && (N%1000/100 == N%1000%100/10);
	bool right=( N%1000/100 == N%1000%100/10) && (N%1000%100/10 == N%1000%100%10 );
		
		if(left or right){
			
			cout << "Yes" << endl;
	}
	
	else{
		cout << "No" << endl;
	}
	}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>

#define MAX 100005
#define NIL -1
void print(int);
void rec(int,int);

typedef struct{
  int p,l,r;
}Node;
Node T[MAX];
int n,D[MAX];

int main(){
  int i,j,d,v,c,l,r;

  scanf("%d",&n);

  for(i=0;i<n;i++){
    T[i].p=T[i].l=T[i].r=NIL;
  }
  for(i=0;i<n;i++){
    scanf("%d%d",&v,&d);
    for(j=0;j<d;j++){
      scanf("%d",&c);
      if(j==0)T[v].l=c;
      else T[l].r=c;
      l=c;
      T[c].p=v;
    }
  }
  for(i=0;i<n;i++){
    if(T[i].p==NIL)r=i;
  }

  rec(r,0);

  for(i=0;i<n;i++)print(i);
  
  return 0;
}

void print(int u){
  int i,c;
  printf("node %d: parent = %d, depth = %d, ",u,T[u].p,D[u]);

  if(T[u].p==NIL)printf("root, ");
  else if(T[u].l==NIL)printf("leaf, ");
  else printf("internal node, ");
  printf("[");

  for(i=0,c=T[u].l;c>NIL;i++,c=T[c].r){
    if(i) printf(", ");
    printf("%d",c);
  }
  printf("]\n");
}

void rec(int u,int p){
  D[u]=p;
  if (T[u].r!=NIL)rec(T[u].r,p);
  if (T[u].l!=NIL)rec(T[u].l,p+1);
}



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

int main()
{
  long int N;
  long int i=0;

  cin >> N;
  
  for(i=1;;i++)
  {
    if(i*i>N){
      cout << "" << (i-1)*(i-1);
      break;
  }
  }
  return 0;
}


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

#define REP(i, x) REPI(i, 0, x)
#define REPI(i, a, b) for (int i = int(a); i < int(b); ++i)
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
using namespace std;

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

  int N, A;
  cin >> N >> A;

  N %= 500;
  if (N <= A) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}


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

using namespace std;

#define MAX_N 10000 + 1

int n, m, a;
string dp[MAX_N];
map<int, char> cvmap; // cvmap[cost] = value;

int getCost(const char value)
{
    switch (value)
    {
    case '1':
        return 2;
    case '7':
        return 3;
    case '4':
        return 4;
    case '2':
    case '3':
    case '5':
        return 5;
    case '6':
    case '9':
        return 6;
    case '8':
        return 7;
    default:
        return 0;
    }
}

void inputCVMap(const char value)
{
    int c = getCost(value);
    if (cvmap.count(c) == 0 || (cvmap.count(c) > 0 && cvmap[c] < value))
        cvmap[c] = value;
}

string cmp(string &a, string &b)
{
    if (a.size() < b.size())
        return b;
    else if (a.size() > b.size())
        return a;

    return a < b ? b : a;
}

void printans()
{
    sort(dp[n].begin(), dp[n].end(), greater<char>());
    cout << dp[n] << "\n";
}

int main()
{
    scanf("%d %d", &n, &m);
    for (int i = 0; i < m; i++)
    {
        int a;
        scanf("%d", &a);
        inputCVMap(a + '0' - 0);
    }

    // Initialize
    for (auto cvp : cvmap)
    {
        dp[cvp.first] += cvp.second;
    }

    for (int i = 1; i <= n; i++)
    {
        if (dp[i] == "")
            continue;

        for (auto cvp : cvmap)
        {
            if (i + cvp.first <= n)
            {
                string v = dp[i];
                v += cvp.second;
                dp[i + cvp.first] = cmp(dp[i + cvp.first], v);
            }
        }
    }

    printans();
    return 0;
}


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

#define watch(x) cerr << (#x) << ": " << (x) << endl
#define int long long



int32_t main() {

    int n, m; cin >> n >> m;
    vector<int> counts(m+1, 0);
    for(int i = 0; i < n-1; ++i) {
        int k; cin >> k;
        for(int j = 0; j < k; ++j) {
            int aij; cin >> aij;
            counts[aij]++;
        }
    }

    int ans = 0;
    int lastk; cin >> lastk;
    for(int i = 0; i < lastk; ++i) {
        int cur; cin >> cur;
        if(counts[cur] == n-1) ans++;
    }

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


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


int dp[110][10010];


int main(){
  int n,i,W,j,w;
  cin >> n >> W;
  vector<int> v(n),weight(n);
  for(i=0;i<n;++i){
    cin >> v[i] >> weight[i];
  }
  for(i=0;i<10010;++i){
    dp[0][i]=0;
  }
  for(i=0;i<n;++i){
    for(j=0;j<=W;++j){
      if(j>=weight[i])dp[i+1][j]=max(dp[i][j-weight[i]]+v[i],dp[i][j]);
      else dp[i+1][j]=dp[i][j];
    }
  }
  cout << dp[n][W] << endl;
}



Measured memory_bytes: 7044
#include<bits/stdc++.h>
#include <math.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define lper(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9;
const ll INF=4e18;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};
int main() {
ll N;
  cin >>N;
  vl vec(N);
  rep(i,N) {
    cin >>vec.at(i);
  }
  vl A(3*N) ;
    rep(i,N) {
A.at(3*i)=vec.at(i)-1;
      A.at(3*i+1)=vec.at(i);
      A.at(3*i+2)=vec.at(i)+1;
    }
  sort(all(A));
  ll count=1;
  ll a=1;
  rep(i,3*N-1) {
    if(A.at(i)==A.at(i+1)) {
      count++;
    }
    if(A.at(i)!=A.at(i+1)) {
      a=max(a,count);
      count=1;
    }
  }
  
  if(A.at(3*N-2)==A.at(3*N-1)) {
a=max(a,count);
  }
else if(A.at(3*N-2)!=A.at(3*N-1)) {
a=max(a,count);
  }
  
  cout<<a<<endl;
}
  
  
 

Measured memory_bytes: 3328
#include <stdio.h>

int main(void)
{
	int ans[4];
	int input[4];
	int i, j;
	int hit, blow;
	
	while (scanf("%d %d %d %d %d %d %d %d", &ans[0], &ans[1], &ans[2], &ans[3], &input[0], &input[1], &input[2], &input[3]) != EOF){
		hit = blow = 0;
		for (i = 0; i < 4; i++)for (j = 0; j < 4; j++)if (ans[i] == input[j]) (i == j) ? hit++ : blow++;
		printf("%d %d\n", hit, blow);
	}
	
	return (0);
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
char a[100001];
int main()
{
	int lena=0,p=0,g=0,deer=0;
	scanf("%s",a);
	lena=strlen(a);
	for(int i=0;i<=lena-1;i++)
	{
		if(i==0)
		{
			if(a[0]=='p')
				deer--;
			g++;
			continue;
		}
		if(p<g)
		{
			if(a[i]=='g')
				deer++;
			p++;
			continue;
		}
		if(p==g)
		{
			if(a[i]=='p')
				deer--;
			g++;
		}
	}
	cout<<deer;
}

Measured memory_bytes: 384
import java.io.*;
import java.util.*;

public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(reader.readLine());
		int[] ts = new int[n+1];
		int[] xs = new int[n+1];
		int[] ys = new int[n+1];
		for (int i = 1; i <= n; i++) {
			String[] line = reader.readLine().split(" ");
			ts[i] = Integer.parseInt(line[0]);
			xs[i] = Integer.parseInt(line[1]);
			ys[i] = Integer.parseInt(line[2]);
		}
		for (int i = 1; i <= n; i++) {
			int dt = ts[i] - ts[i-1];
			int dx = Math.abs(xs[i] - xs[i-1]);
			int dy = Math.abs(ys[i] - ys[i-1]);
			int d = dx + dy;
			if (d > dt || d % 2 != dt % 2) {
				System.out.println("No");
				return;
			}
		}
		System.out.println("Yes");
	}
}


Measured memory_bytes: 46064
s = input()
acnt = 999999
zcnt = 0

for i in range(len(s)):
    if s[i] == 'A':
        acnt = min(acnt, i)
    elif s[i] == 'Z':
        zcnt = max(zcnt, i)
    else:
        next
print(zcnt - acnt + 1)

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

int main(){
    string S,T;
    cin >> S >> T;
    int ans = 0;
    for(int i=0; i<S.size(); i++){
        if(S.at(i) != T.at(i)){
            ans++;
        }
    }
    cout << ans << endl;
}

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

constexpr int N = 1e6 + 1;
bool visited[N];
bool divisible[N];

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

    vector<int> v(n);
    for (int i = 0; i < n; i++)
        cin >> v[i];

    for (auto x : v)
    {
        if (visited[x]) divisible[x] = true;

        visited[x] = true;
        if (divisible[x])
            continue;

        for (int i = 2 * x; i < N; i += x)
            divisible[i] = true;
    }

    int count = 0;
    for (auto x : v)
        if (!divisible[x])
            count++;

    cout << count << endl;
}


Measured memory_bytes: 5488
/// In The Name Of God

#include <bits/stdc++.h>

#define f first
#define s second

#define pb push_back
#define pp pop_back
#define mp make_pair

#define sz(x) (int)x.size()
#define sqr(x) ((x) * 1ll * (x))
#define all(x) x.begin(), x.end()

#define rep(i, l, r) for (int i = (l); i <= (r); i++)
#define per(i, l, r) for (int i = (l); i >= (r); i--)

#define Kazakhstan ios_base :: sync_with_stdio(0), cin.tie(0), cout.tie(0);

#define nl '\n'
#define ioi exit(0);

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

const int N = (int)2e5 + 7;
const int inf = (int)1e9 + 7;
const int mod = (int)1e9 + 7;
const ll linf = (ll)1e18 + 7;

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

using namespace std;

int n;
char s[N];
int nxt[26][N];

int dp[N], go[N];
int calc(int v = 0) {
	if (v > n) return 0;
	if (~dp[v]) return dp[v];

	int res = inf;
	rep(i, 0, 25) {
		int j = nxt[i][v + 1];
		int cur = calc(j) + 1;
		if (cur < res) {
			res = cur;
			go[v] = i;
		}
	}

	return dp[v] = res;
}
int main() {
	#ifdef IOI2018
		freopen ("in.txt", "r", stdin);
	#endif
	Kazakhstan
	cin >> (s + 1);
	n = strlen(s + 1);
	// end of input
	
	rep(i, 0, 25) nxt[i][n + 1] = n + 1;
	per(i, n, 1) {
		rep(j, 0, 25) nxt[j][i] = nxt[j][i + 1];
		nxt[s[i] - 'a'][i] = i;
	}
	memset(dp, -1, sizeof(dp));
	calc();
	int p = 0;
	string ans;
	while (p <= n) {
		ans += go[p] + 'a';
		p = nxt[go[p]][p + 1];
	}
	cout << ans;
	ioi
}


Measured memory_bytes: 22656
S = input()[::-1]
words = {w[-1]:w[::-1] for w in ['dream', 'erase', 'er']}
i = 0
flag = True
#print(words)
while i < len(S):
  c = S[i]
  if c in words:
    if S[i:i+len(words[c])] == words[c]:
      i += len(words[c])
    else :
      flag = False
      break
    if c == 'r':
       if S[i:i+len(words['m'])] == words['m']:
         i += len(words['m'])
       elif S[i-1:i-1+len(words['e'])] == words['e']:
         i += len(words['e']) - 1
       else :
         flag = False
         break
  else :
    break
  if not flag:
    break
print('YES' if flag else 'NO')

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

vector<long long> S;
int total;

void merge(vector<long long>& A, int left, int mid, int right) {
    int n1 = mid - left;
    int n2 = right - mid;
    vector<long long> L(n1+1);
    vector<long long> R(n2+1);
    int i;
    rep(i, n1) {
        L[i] = A[left + i];
    }
    rep(i, n2) {
        R[i] = A[mid + i];
    }
    L[n1] = 1000000001;
    R[n2] = 1000000001;
    int x = 0, y = 0;
    for (int k = left; k < right; k++) {
        if (L[x] <= R[y]) {
            A[k] = L[x];
            x++;
            total++;
        } else {
            A[k] = R[y];
            y++;
            total++;
        }
    }
}

void mergeSort(vector<long long>& A, int left, int right) {
    if (left + 1 < right) {
        int mid = (left + right) / 2;
        mergeSort(A, left, mid);
        mergeSort(A, mid, right);
        merge(A, left, mid, right);
    }
}

int main() {
    int n;
    cin >> n;
    int i;
    rep(i, n) {
        long long input;
        cin >> input;
        S.push_back(input);
    }
    mergeSort(S, 0, n);
    rep(i, n-1) {
        cout << S[i] << " ";
    }
    cout << S[n-1] << endl;
    cout << total << endl;

    return 0;
}



Measured memory_bytes: 10720
#include<stdio.h>
#include<cstdio>
#include<algorithm>
using namespace std;

int main() {
  int N;
  scanf("%d", &N);
  int A[N+1];
  A[0] = 0;
  for (int i=1 ; i<N+1 ; i++) {
    scanf("%d", &A[i]);
  }
  sort(A, A+N+1);
  int num = A[N];
  long long a = 0;
  long long b = 0;
  int cnt = 0;
  for (int i=N ; i>=0 ; i--) {
    if (A[i] != num) {
      if (cnt >= 4 && a == 0) {
        a = A[i+1];
        b = A[i+1];
        break;
      } else if (cnt >= 2 && a == 0) {
        a = A[i+1];
      } else if (cnt >= 2 && a != 0) {
        b = A[i+1];
        break;
      }
      num = A[i];
      cnt = 1;
    } else {
      cnt++;
    }
  }
  printf("%lld\n", a*b);
}

Measured memory_bytes: 512
import java.util.Scanner;

import static java.lang.System.in;

public class Main {
    final static  int MOD = (int)1E9 + 7;
    public static void main(String[] args) {
        Scanner scanner = new Scanner(in);
        int n = scanner.nextInt();
        int[][] can = new int[n][n];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                can[i][j] = scanner.nextInt();
            }
        }
        int[] dp = new int[1 << n];
        dp[0]=1;
        for (int mask = 0; mask < (1 << n); mask++) {
            int x = Integer.bitCount(mask);
            for (int i = 0; i < n; i++) {
                if((mask & (1 << i)) == 0 && can[x][i] == 1)
                    dp[mask | (1 << i)] = (dp[mask | (1 << i)]%MOD + dp[mask] %MOD) % MOD;
            }
        }
        System.out.println(dp[(1 << n) -1]);
    }
}


Measured memory_bytes: 45680
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int a,b;
  int c;
  
  cin >> a >> b;
  
  c = (a * b) % 2;
  
  if (c == 0){
    cout << "Even" << endl;
  }
  else{
    cout << "Odd" << endl;
  }
  
}

Measured memory_bytes: 3548
def hashSearch(n):
    l = {}
    res = []
    for x in range(n):
        order = input().split()
        if order[0] == 'insert':
            l[order[1]] = x
        elif order[0] == 'find':
            if order[1] in l:
                res.append('yes')
            else:
                res.append('no')
    print('\n'.join(res))


if __name__ == '__main__':
    N = int(input())
    hashSearch(N)



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

#define ALL(a) (a).begin(), (a).end()
#define ll long long

using namespace std;

signed main(){
	string raw;
	while(getline(cin,raw)){
		string str;
		for(auto e : raw){
			if(isalpha(e))str.push_back((char)toupper(e));
		}
		string rev;
		for(auto i = str.rbegin(); i != str.rend(); ++i){
			rev.push_back(*i);
		}
		int n = str.size();
		set<string> anss;
		for(int i = 0; i < n; i++){
			string temp;
			for(int j = 1; 1+2*j <= n; j++){
				if(i-j < 0 || i+j >= n)break;
				if(str.substr(i-j,j) == rev.substr(n-i-1-j,j)){
					temp = str.substr(i-j,2*j+1);
				}
			}
			if(temp.size() != 0 && anss.find(temp) == anss.end()){
				anss.insert(temp);
			}
		}
		for(int i = 0; i < n; i++){
			string temp;
			for(int j = 2; 2*j <= n; j++){
				if(i-j+1 < 0 || i+j >= n)break;
				if(str.substr(i-j+1,j) == rev.substr(n-i-j-1,j)){
					temp = str.substr(i-j+1,2*j);
				}
			}
			if(temp.size() != 0 && anss.find(temp) == anss.end()){
				anss.insert(temp);
			}
		}
//		cerr << "aa" << endl;
		for(auto itr = anss.begin(); itr != anss.end(); ++itr){
			bool flag = false;
			for(auto ritr = anss.rbegin(); ritr != anss.rend(); ++ritr){
				auto s = (*ritr).size();
				auto is = (*itr).size();
				if(s < is || s % 2 != is % 2 || *itr == *ritr)continue;
				if(*itr == (*ritr).substr((s-is)/2,is)){
					flag = true;

				}
			}
			if(flag)itr = anss.erase(itr);
		}
		for(auto itr = anss.begin(); itr != anss.end(); ++itr){
			if(itr != anss.begin())cout << " ";
			cout << *itr;
		}
		cout << endl;
	}
	return 0;
}


Measured memory_bytes: 3036
n = int(input())
s = '.'+input()
lb, rw = 0, s.count('.')-1
ans = lb+rw
for i in range(1,n+1):
  if s[i] == '#':
    lb += 1
  elif s[i] == '.':
    rw -= 1
  if lb+rw < ans:
    ans = lb+rw
print(ans)

Measured memory_bytes: 3500
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<cctype>
#include<cstring>
#define maxn 200007
#define ll long long 
#define SDOI2020 RP++ 
using namespace std;
ll n,a[maxn],cnt[maxn],ans; 
inline int read()
{
	int x=0;
	int flag=0;
	char ch;
	ch=getchar();
	while(!isdigit(ch)) 
	{
		if(ch=='-') flag=1;
	ch=getchar();	
	}
	while(isdigit(ch))
	{
		x=(x<<3)+(x<<1)+ch-48;
		ch=getchar();
		}
		if(flag==1) x=-x;	
		return x;
}


int main()
{
	n = read();
	for(register int i = 1;i <= n;i++)
	{
		int x = read();
		a[i] = x;
		cnt[x]++;
	}
	for(register int i = 1;i <= n;i++)
	{
		ans += (ll) cnt[i] * (cnt[i] - 1) / 2;
	}
	for(register int i = 1;i <= n;i++)
	{
		printf("%lld\n",ans - cnt[a[i]] + 1);
	}
	return 0;
} 

Measured memory_bytes: 4736
N = int(input())
alp = list("MARCH")
data = [0]*5
for i in range(N):
    s = list(input())
    for i in range(5):
        if alp[i] == s[0]: data[i] += 1

flag = 0
for i in range(5):
    if data[i] != 0: flag += 1

if flag < 3:
    print(0)
else:
    ans = 0
    for a in range(3):
        for b in range(a+1,4):
            for c in range(b+1,5):
                ans += data[a]*data[b]*data[c]
    print(ans)


Measured memory_bytes: 3064
n=int(input())
A=[(i) for i in input().split()]

B=[]

if n%2==0:
    for i in range(n//2):
        B.append(A[n-2*i-1])
    for i in range(n//2):
        B.append(A[2*i])
else:
    for i in range(n//2+1):
        B.append(A[n-2*i-1])
    for i in range(n//2):
        B.append(A[2*i+1])
    


print(" ".join(B))
        

Measured memory_bytes: 25668
#include <bits/stdc++.h>
#include <string>
#include <cmath>
using namespace std;
 
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<ll> vll;
 
#define all(v) v.begin(),v.end()
#define test() int t;cin>>t;while(t--) 
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int mod = 1e9+7;

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

Measured memory_bytes: 3648
import java.io.*;
import java.util.*;

class ContestReader {
  private BufferedReader reader;
  private StringTokenizer tokenizer;
  
  ContestReader(InputStream in) {
    reader = new BufferedReader(new InputStreamReader(in));
  }
  
  public String next() {
    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
      try {
        tokenizer = new java.util.StringTokenizer(reader.readLine());
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
    return tokenizer.nextToken();
  }
  
  public int nextInt() {
    return Integer.parseInt(next());
  }
  
  public long nextLong() {
    return Long.parseLong(next());
  }
  
  public double nextDouble() {
    return Double.parseDouble(next());
  }
  
  public int[] nextIntArray(int n) {
    int[] array = new int[n];
    for (int i = 0; i < n; i++) {
      array[i] = nextInt();
    }
    return array;
  }
  
  public long[] nextLongArray(int n) {
    long[] array = new long[n];
    for (int i = 0; i < n; i++) {
      array[i] = nextLong();
    }
    return array;
  }
}

class Algorithm {
  private static void swap(Object[] list, int a, int b) {
    Object tmp = list[a];
    list[a] = list[b];
    list[b] = tmp;
  }
  
  public static <T extends Comparable<? super T>> boolean nextPermutation(T[] ts) {
    int rightMostAscendingOrderIndex = ts.length - 2;
    while (rightMostAscendingOrderIndex >= 0 &&
        ts[rightMostAscendingOrderIndex].compareTo(ts[rightMostAscendingOrderIndex + 1]) >= 0) {
      rightMostAscendingOrderIndex--;
    }
    if (rightMostAscendingOrderIndex < 0) {
      return false;
    }
    
    int rightMostGreatorIndex = ts.length - 1;
    while (ts[rightMostAscendingOrderIndex].compareTo(ts[rightMostGreatorIndex]) >= 0) {
      rightMostGreatorIndex--;
    }
    
    swap(ts, rightMostAscendingOrderIndex, rightMostGreatorIndex);
    for (int i = 0; i < (ts.length - rightMostAscendingOrderIndex - 1) / 2; i++) {
      swap(ts, rightMostAscendingOrderIndex + 1 + i, ts.length - 1 - i);
    }
    return true;
  }
}

public class Main {
  private static String solve(int[] a) {
    boolean possible = true;
    for (int n : a) {
      if (n % 2 == 1) {
        possible = !possible;
      }
    }
    return possible ? "YES ": "NO";
  }
  
  private static void execute(ContestReader reader, PrintWriter out) {
    int n = reader.nextInt();
    int[] a = reader.nextIntArray(n);
    out.println(solve(a));
  }
  
  public static void main(String[] args) {
    ContestReader reader = new ContestReader(System.in);
    PrintWriter out = new PrintWriter(System.out);
    execute(reader, out);
    out.flush();
  }
}



Measured memory_bytes: 35888
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<array>
using namespace std;

int main(){

    int a, b;
    cin >> a >>b;

    int sum = 0;

    for(int i = 0; i < 2; ++i){
        if (a >= b){
            sum += a;
            --a;
        }else{
            sum += b;
            --b;
        }
    }
    cout << sum << endl;

    return 0;
}

Measured memory_bytes: 256
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <unordered_map>
#include <climits>
#include <set>
#include <unordered_set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
#include <random>
#include <complex>
#include <regex>
#include <locale>
#include <random>
#include <type_traits>
#include <chrono>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); --i)
#define REP(i, n) FOR(i, 0, (n))
#define RREP(i, n) for (int i = (n) - 1; i >= 0; i--)

#define FOREACH(x, arr) for (auto &(x) : (arr))
#define FORITER(x, arr) for (auto(x) = (arr).begin(); (x) != (arr).end(); ++(x))

#define SHOW_VECTOR(v) {std::cerr << #v << "\t:";for(const auto& xxx : v){std::cerr << xxx << " ";}std::cerr << "\n";}
#define SHOW_MAP(v){std::cerr << #v << endl; for(const auto& xxx: v){std::cerr << xxx.first << " " << xxx.second << "\n";}}

using LL = long long;

//------------------------------------------
//------------------------------------------

vector<LL> DIVISORS(LL x) {
    vector<LL> ret;
    for (LL i = 1; i * i <= x; i++) {
        if (x % i == 0) {
            ret.push_back(i);
            if (i != x / i) {
                ret.push_back(x / i);
            }
        }
    }
    return ret;
}

int main() {

    LL N;
    cin >> N;

    auto divisors = DIVISORS(N);

    LL ans = LONG_LONG_MAX;
    for(auto x: divisors){
        LL y = N / x;
        ans = min(ans, y + x - 2);
    }
    cout<<ans << endl;

}



































Measured memory_bytes: 384
integer N
integer,allocatable,dimension(:)::A
integer ans,baseline,l,r
read*,N
allocate(A(N+1))
read*,A(1:N)
A(N+1)=0
ans=0
do while(maxval(A)/=0)
  do i=1,N
    if(A(i)/=0)then
      l=i
      exit
    endif
  end do
  do i=L+1,N+1
    if(A(I)==0)then
      r=i-1
      exit
    endif
  end do
  baseline=minval(A(l:r))
  ans=ans+baseline
  do i=l,r
    A(i)=A(i)-baseline
  end do
end do
print"(I0)",ans
end

Measured memory_bytes: 256
#include <iostream>
#include <climits>
#include <set>
#include <string>
#include <algorithm>
#include <vector>
#define MAX 1000000007


using namespace std;
#define ll long long
#define dbg if(0)
#define ISRANGE(val,lo,hi) ((lo<=val)&&(val<hi))


ll gcd(ll a,ll b){
    if(a%b==0)return b;
    return gcd(b,a%b);

}


int main(){
    ll ans,a,b;
    cin>>a>>b;


    cout <<(a*b/gcd(a,b))<<endl;
    return 0;

}

Measured memory_bytes: 256