akhauriyash/Code-Regression huggingface dataset:
/*
    Author:zeke
    
    pass System Test!
    GET AC!!
*/
#include <iostream>
#include <queue>
#include <vector>
#include <iostream>
#include <vector>
#include <string>
#include <cassert>
#include <algorithm>
#include <functional>
#include <cmath>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <map>
#include <iomanip>
#include <utility>
#include <stack>
#include <bitset>
using ll = long long;
using ld = long double;
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define rep3(var, min, max) for (ll(var) = (min); (var) < (max); ++(var))
#define repi3(var, min, max) for (ll(var) = (max)-1; (var) + 1 > (min); --(var))
#define Mp(a, b) make_pair((a), (b))
#define F first
#define S second
#define Icin(s) \
    ll(s);      \
    cin >> (s);
#define Scin(s) \
    ll(s);      \
    cin >> (s);
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef vector<V> VV;
typedef vector<P> VP;
ll mod = 1e9 + 7;
ll MOD = 1e9 + 7;
ll INF = 1e18;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin>>n;
    V vec(n);
    rep(i,n)cin>>vec[i];
    map<ll,ll> mp;
    rep(i,n){
        mp[vec[i]]++;
    }
    V reg(n+1);
    ll sum=0;
    rep(i,n+1){
        ll temp=mp[i];
        reg[i]=temp*(temp-1)/2;
        sum+=reg[i];
    }
    rep(i,n){
        ll temp=vec[i];
        ll temp2=mp[vec[i]];
        temp2--;
        ll tempsum=sum;
        tempsum-=reg[vec[i]];
        tempsum+=(temp2-1)*temp2/2;
        cout<<tempsum<<endl;
    }
}


Measured memory_bytes: 18432
#include        <map>
#include      <cmath>
#include      <queue>
#include     <string>
#include     <cstdio>
#include     <vector>
#include    <cstring>
#include   <iostream>
#include  <algorithm>
using namespace std;
#define ll long long
const ll inf = 0x3f3f3f3f;
const int maxn = 1e5+5;
const ll mod = 1e9+7;

int main(){
    int n;
    string s;
    map<string,int>M;
    std::ios::sync_with_stdio(false);
    cin>>n;

    for(int i=0;i<n;i++){

        cin>>s;
        sort(s.begin(),s.end());
        M[s]++;
    }
    ll ans = 0;
    for(map<string,int>::iterator its=M.begin();its!=M.end();its++){
        ll t = (*its).second;
        ans += (t-1)*t/2;
    }
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 11264
#include <bits/stdc++.h>
using namespace std;
#define all(v) v.begin(), v.end()
#define rep(a, b) for (a = 0, a < b, a++)

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  
  cout << c << " " << a << " " << b;
  return 0;

}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
	int x, y;
	cin >> x >> y;

	if(x==1||x==3||x==5||x==7||x==8||x==10||x==12){
		if(y==1||y==3||y==5||y==7||y==8||y==10||y==12){
			cout << "Yes" << endl;
		}
		else{
			cout << "No" << endl;
		}
	}
	if(x==4||x==6||x==9||x==11){
		if(y==4||y==6||y==9||y==11){
			cout << "Yes" << endl;
		}
		else{
			cout << "No" << endl;
		}
	}
	if(x==2) cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    private static int[] stack;
    private static int top=0;
    private static void push(int num){
        stack[++top]=num;
    }
    private static int pop(){
        return stack[top--];
    }
    public static void main(String[] args) {
        stack = new int[205];
        Scanner sc = new Scanner(System.in);
        String[] ss = sc.nextLine().split(" ");
        for (String s : ss) {
            switch (s) {
                case "+": {
                    int b = pop();
                    int a = pop();
                    push(a + b);
                    break;
                }
                case "-": {
                    int b = pop();
                    int a = pop();
                    push(a - b);
                    break;
                }
                case "*": {
                    int b = pop();
                    int a = pop();
                    push(a * b);
                    break;
                }
                default:
                    push(Integer.parseInt(s));
                    break;
            }
        }
        System.out.println(pop());
    }
}



Measured memory_bytes: 26280
#include<stdio.h>
int main(void){
    int h,w,i,j;
    char s[101][101];
    scanf("%d%d",&h,&w);
    for(i=0;i<h;i++){
        scanf("%s",s[i]);
    }
    for(i=0;i<h;i++){
        printf("%s\n%s\n",s[i],s[i]);
    }
    return 0;
}

Measured memory_bytes: 128
N = int(input())

ans = 1

dic = {}
ori = [2]#sosuu

dic[2] = 0

for i in range(998):

    i += 2

    flag = True

    for j in ori:

        if i % j == 0:
            flag = False

    if flag:
        dic[i] = 0
        ori.append(i)


for i in range(N):

    i += 1

    for j in ori:

        cnt = 1

        while True:

            if i % (j ** cnt) != 0:
                break

            cnt += 1

        dic[j] += cnt-1

for i in dic:

    ans *= (dic[i] + 1)

print (ans % ( 10 ** 9 + 7 ))

Measured memory_bytes: 3064
//#define __USE_MINGW_ANSI_STDIO 0
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define IN(a, b, x) (a<=x&&x<b)
#define MP make_pair
#define PB push_back
#define MOD 1000000007
#define INF (1LL<<30)
#define LLINF (1LL<<60)
#define PI 3.14159265359
#define EPS 1e-12
#define int ll

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

signed main(void)
{
	int h, w;
	cin >> h >> w;

	int ret = INF;
	FOR(i, 1, h) {
		int a = i*w, b=(h-i)*(w/2), c=(h-i)*(w-w/2);
		//cout << a << " " << b << " " << c << endl;
		ret = min(ret, max({a, b, c}) - min({a, b, c}));
		b = (h-i)/2*w, c = ((h-i)-(h-i)/2)*w;
		//cout << a << " " << b << " " << c << endl;
		ret = min(ret, max({a, b, c}) - min({a, b, c}));
	}

	FOR(i, 1, w) {
		int a = i*h, b=(w-i)*(h/2), c=(w-i)*(h-h/2);
		//cout << a << " " << b << " " << c << endl;
		ret = min(ret, max({a, b, c}) - min({a, b, c}));
		b = (w-i)/2*h, c = ((w-i)-(w-i)/2)*h;
		//cout << a << " " << b << " " << c << endl;
		ret = min(ret, max({a, b, c}) - min({a, b, c}));
	}
	cout << ret << endl;
	return 0;
}


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

namespace practice001
{
    class Program
    {
        static void Main(string[] args)
        {
            int money = int.Parse(Console.ReadLine());

            int shou500 = money / 500;
            int amari500 = money % 500;
            int shou5 = amari500 / 5;
            int ureshisaTotal = shou500 * 1000 + shou5 * 5;

            Console.WriteLine(ureshisaTotal);
        }
    }
}

Measured memory_bytes: 11092
from bisect import bisect_left, bisect_right

n = int(input())
l = sorted(map(int, input().split()))
ans = 0
for i1 in range(n - 2):
    for i2 in range(i1 + 1, n - 1):
        a = l[i1]
        b = l[i2]
        i3s = max(bisect_right(l, b - a), i2 + 1)
        i3e = bisect_left(l, a + b)
        ans += i3e - i3s
print(ans)


Measured memory_bytes: 46940
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)*}
    };
}

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, 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")
    };
}

fn main() {
    input!{
        x: i64,
        a: i64,
        b: i64,
    }
    println!(
        "{}",
        if b <= a {
            "delicious"
        } else if b <= x + a {
            "safe"
        } else {
            "dangerous"
        }
    );
}


Measured memory_bytes: 4352
#include<stdio.h>
int main(){
    long long int N,a,b,c;
    scanf("%lld",&N);
    for (a=1;a<=3500;a++){
        for (b=1;b<=3500;b++){
            if(4*a*b-N*(a+b)>0){
                if((N*a*b)%(4*a*b-N*(a+b))==0){
                    printf("%lld %lld %lld",a,b,(N*a*b)/(4*a*b-N*(a+b)));
                    return 0;
                }
            }
        }
    }
}

Measured memory_bytes: 128
#define _crt_secure_no_warnings

#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#ifdef __GXX_EXPERIMENTAL_CXX0X__
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif


#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#ifdef __GXX_EXPERIMENTAL_CXX0X__
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

using namespace std;

int main()
{
	int N;
	while (1)
	{
		cin >> N;
		if (N == 0)break;
		//int xnow = 0, ynow = 0;
		int xmax = INT_MIN, xmin = INT_MAX;
		int ymax = INT_MIN, ymin = INT_MAX;
		int a, b;
		map<int, pair<int, int>>data;
		pair<int, int>p;
		p.first = 0; p.second = 0;
		data[0] = p;
		for (size_t i = 1; i < N; i++)
		{
			cin >> a >> b;
			p.first = data[a].first;
			p.second = data[a].second;
			switch (b)
			{
				case 0:p.first--; break;
				case 1:p.second--; break;
				case 2:p.first++; break;
				case 3:p.second++; break;
			}
			data[i] = p;
		}
		for (auto x : data)
		{
			xmax = max(xmax, x.second.first);
			xmin = min(xmin, x.second.first);
			ymax = max(ymax, x.second.second);
			ymin = min(ymin, x.second.second);
		}
		cout << xmax - xmin + 1 << " " << ymax - ymin + 1 << endl;
	}
}

Measured memory_bytes: 1208
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>

using namespace std;
typedef long long ll;

int main() {
    int N; cin >> N;
    map<int, int> M;
    for(int i=0; i<N; i++){
        int a; cin >> a;
        M[a]++;
    }
    
    int e1 = 0;
    int e2 = 0;
    for(auto m:M){
        if(m.second>=2) e1 = max(e1, m.first);
    }
    
    for(auto m:M){
        if((m.second>=2 && m.first!=e1) || (m.second>=4 && m.first==e1)) e2 = max(e2, m.first);
    }

    cout << ll(e1)*e2 << endl;
    return 0;
}


Measured memory_bytes: 4992
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
using namespace std;
#define MOD 1000000007
#define INF (1<<29)
#define EPS (1e-10)
typedef long long Int;
typedef pair<Int, Int> P;

#define max(x, y) ((x)>(y)?(x):(y))
#define min(x, y) ((x)<(y)?(x):(y))

Int h, w;
char c;
char ans[2][600][600];

int main(){
  cin >> h >> w;
  for(int i = 0;i < h;i++){
    for(int j = 0;j < w;j++){
      ans[0][i][j] = ans[1][i][j] = '.';
      cin >> c;
      if(c == '#'){
	ans[0][i][j] = '#';
	ans[1][i][j] = '#';
      }
    
      if(i == 0)ans[0][i][j] = '#';
      else if(i == h-1)ans[1][i][j] = '#';
      else ans[j % 2][i][j] = '#';
    }
  }
  for(int k = 0;k < 2;k++){
    for(int i= 0;i < h;i++){
      for(int j = 0;j < w;j++){
	cout << ans[k][i][j];
      }cout << endl;
    }
    cout << endl;
  }
  
  return 0;
}

Measured memory_bytes: 1280
#include <cmath>
#include <iostream>
using namespace std;
typedef long long Int;

Int n, m, k[20], s[20][20], p[20];

int main() {
  cin >> n >> m;
  for (int j = 0; j < m; j++) {
    cin >> k[j];
    for (int k_ = 0; k_ < k[j]; k_++) cin >> s[j][k_];
  }
  for (int j = 0; j < m; j++) cin >> p[j];

  Int ans = 0;
  for (int bit = 0; bit < pow(2, n); bit++) {
    Int switches[n];
    for (int i = 0; i < n; i++) {
      switches[i] = 0;
      if (bit >> i & 1) {
        switches[i] = 1;
      }
    }

    int light_cnt = 0;
    for (int j = 0; j < m; j++) {
      int on_cnt = 0;
      for (int k_ = 0; k_ < k[j]; k_++) {
        if (switches[s[j][k_] - 1]) {
          on_cnt++;
        }
      }
      if (on_cnt % 2 == p[j]) {
        light_cnt++;
      }
    }
    if (light_cnt == m) {
      ans++;
    }
  }

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

Measured memory_bytes: 4104
#include<iostream>

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    int x[n], y[n], h[n];
    int id = -1;
    for (int i = 0; i < n; ++i) {
        cin >> x[i] >> y[i] >> h[i];
        if (h[i] != 0) id = i; // must exist
    }
    for (int i = 0; i <= 100; ++i) {
        for (int j = 0; j <= 100; ++j) {
            int H = h[id] + abs(x[id] - i) + abs(y[id] - j);
            int contflg = 0;
            for (int k = 0; k < n; ++k) {
                int tmp = abs(x[k] - i) + abs(y[k] - j);
                if (h[k] == 0) {
                    if (H - tmp > 0) { contflg = 1; break; } // 正だったら0にならない
                    else continue;
                }
                if (H == -1) {
                    H = h[k] + tmp;
                    if (H < 1) { contflg = 1; break; }
                } else {
                    if (h[k] + tmp != H) { contflg = 1; break; }
                }
            }
            if (contflg == 0) {
                cout << i << " " << j << " " << H << endl;
                return 0;
            }
        }
    }
}


Measured memory_bytes: 256
n=int(input())
ans=float("INF")
for i in range(n+1):
  d=0
  temp=n-i
  while (i>0):
    d+=i%6
    i//=6
  while(temp>0):
    d+=temp%9
    temp//=9
  ans=min(d,ans)
print(ans)

Measured memory_bytes: 40940
#include <iostream>
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <cctype>
#include <string>
#include <map>
#include <set>
#include <math.h>
#include <cmath>
#define ll long long

using namespace std;

int main(){

  string S;
  cin >> S;
  int N = S.size();

  // 前半を切り出す
  string bs = S.substr(0,(N-1)/2);
  string brs = S.substr(0,(N-1)/2);
  reverse(brs.begin(), brs.end());

  bool flag1 = true;
  for (int i = 0; i < bs.size(); i++) {
    if(bs[i] != brs[i]){
      flag1 = false;
    }
    if(flag1 == false) break;
  }

  // 後半を切り出す
  string as = S.substr((N+3)/2-1,N/2);
  string ars = S.substr((N+3)/2-1,N/2);
  reverse(ars.begin(), ars.end());

  bool flag2 = true;
  for (int i = 0; i < as.size(); i++) {
    if(as[i] != ars[i]){
      flag2 = false;
    }
    if(flag2 == false) break;
  }

  // 全体の判定をする
  string rs = S;
  reverse(rs.begin(), rs.end());
  bool flag3 = true;
  for (int i = 0; i < rs.size(); i++) {
    if(S[i] != rs[i]){
      flag3 = false;
    }
    if(flag3 == false) break;
  }

  if(flag1 == true && flag2 == true && flag3 == true) cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;
}

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

int main(){
	int a, b, c, x;
	cin >> a; // 500円玉
	cin >> b; // 100円玉
	cin >> c; // 50円玉
	cin >> x;

	int total,res;
	res=0;
	
	for(int i=0;i<a+1;i++) {
		for(int j=0;j<b+1;j++){
			for(int k=0;k<c+1;k++){
				total = 500*i+100*j+50*k;
				if(total==x)res++;
			}
		}
	}
	cout << res << endl;
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
template<class T = int> using V  = vector<T>;
template<class T = int> using VV = V< V<T> >;
struct M {
  using T = int; using U = int;
  static void ap(T &a, const U &g) { a += g; }
  // static void ap(U &f, const U &g) { f += g; }
  static constexpr U id() { return 0; }
};
template<class M> struct ST {
  using T = typename M::T; using U = typename M::U; int n; V<T> t; V<U> u;
  ST(int n) : n(n) { t.resize(n); u.assign(n, M::id()); }
  void _ap(int i, const U &f) { if (i < n) M::ap(u[i], f); else M::ap(t[i - n], f); }
  void set(int l, int r, const U &f) {
    stack<int> s; for (int i = l + n; i >>= 1;) s.push(i); for (int i = r + n - 1; i >>= 1;) s.push(i);
    while (not s.empty()) { int i = s.top(); s.pop(); _ap(2 * i, u[i]); _ap(2 * i + 1, u[i]); u[i] = M::id(); }
    for (l += n, r += n; l < r; l >>= 1, r >>= 1) { if (l & 1) _ap(l++, f); if (r & 1) _ap(--r, f); }
  }
  T get(int i) { T res = t[i]; for (i += n; i >>= 1;) M::ap(res, u[i]); return res; }
};
int main() {
  cin.tie(NULL); ios::sync_with_stdio(false);
  int n, q; cin >> n >> q;
  ST<M> st(n); fill(st.t.begin(), st.t.end(), 0);
  for (int i = 0; i < q; i++) {
    int c; cin >> c;
    if (c) {
      int j; cin >> j, j--;
      cout << st.get(j) << '\n';
    } else {
      int l, r, x; cin >> l >> r >> x, l--, r--;
      st.set(l, r + 1, x);
    }
  }
}


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

int main(){
    vector<vector<int>> A(3, vector<int>(3));
    for(int i=0; i<3; i++){
        for(int j=0; j<3; j++){
            cin >> A[i][j];
        }
    }
    int N;
    cin >> N;
    vector<int> b(N);
    for(int i=0; i<N; i++){
        cin >> b[i];
    }

    vector< vector<bool> > C(3, vector<bool>(3, false));
    for(int i=0; i<3; i++){
        for(int j=0; j<3; j++){
            for(int k=0; k<N; k++){
                if(A[i][j] == b[k]){
                    C[i][j] = true;
                }
            }
        }
    }

    for(int i=0; i<3; i++){
        if(C[i][0] && C[i][1] && C[i][2]){
            cout << "Yes" << endl;
            return 0;
        }
    }
    for(int i=0; i<3; i++){
        if(C[0][i] && C[1][i] && C[2][i]){
            cout << "Yes" << endl;
            return 0;
        }
    }
    if(C[0][0] && C[1][1] && C[2][2]){
        cout << "Yes" << endl;
        return 0;
    }
    if(C[2][0] && C[1][1] && C[0][2]){
        cout << "Yes" << endl;
        return 0;
    }

    cout << "No" << endl;


    return 0;
}

Measured memory_bytes: 256
#include <iostream>

int A, B, C, X, count, x;

int main()
{
    std::cin >> A >> B >> C >> X;
    for(int i = 0;i <= A;i++)//500*i
    {
        for(int j = 0;j <= B;j++)//100*j
        {
            x = X;
            if(x >= 500 * i) x -= 500*i;
            else break;
            if(x >= 100 * j) x -= 100*j;
            else break;
            if(50*C >= x) count++;
        }
    }
    std::cout << count << std::endl;

}

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

using namespace std;

string s;
int64_t a,n;

int main()
{
      cin>>n;
     vector<long long int>v;
      for(int i=0;i<n;i++)
        {
            cin>>a;
            v.push_back(a);
        }
        sort(v.begin(),v.end());
        cout<<v[n-1]-v[0];
   return 0;
}


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

int main(){
  int x;
  int max=1;
  int b=2;
  int p=2;
cin >> x;

while(x>=pow(b,p)){
  while(x>=pow(b,p)){
    if(max<pow(b,p)){
      max=pow(b,p);
    }
      p += 1;
  }
  p=2;
  b += 1;
}

cout<< max <<endl;


}

Measured memory_bytes: 640
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
    long long b[10],c[10],a[10],i,n,s,h=0,l=0,k=0,d,e;
    cin>>n;
    for(i=1;i<=n;i++)
    {
        a[i]=i;
    }
    for(i=1;i<=n;i++)
    {
        cin>>b[i];
    }
    for(i=1;i<=n;i++)
    {
        cin>>c[i];
    }
    s=0;
    while(s!=2)
    {
        k++;
        h=0;
        for(i=1;i<=n;i++)
        {
            if(a[i]==b[i])
            {
                h++;
            }
        }
        l=0;
        for(i=1;i<=n;i++)
        {
            if(a[i]==c[i])
            {
                l++;
            }
        }
        if(h==n)
        {
            s++;
            d=k;
        }
        if(l==n)
        {
            s++;
            e=k;
        }     
        next_permutation(a+1,a+1+n);   
    }   
    cout<<max(d,e)-min(d,e)<<endl;
    return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define int long long
typedef long long ll;
const int MOD = 1000000007;
const int INF = 1010000000;
const double EPS5 = 1e-10;
using namespace std;
const pair<int,int> fd[] = {make_pair(1,0),make_pair(-1,0),make_pair(0,1),make_pair(0,-1)}; 

signed main() {
  int n,k,a[100000];cin>>n>>k;rep(i,n)cin>>a[i];
  int g = __gcd(a[0],a[1]);
  rep(i,n-2){
    g = __gcd(g,a[i+2]);
  }
  int mm = *max_element(a,a+n);
  if(k % g == 0 && mm >= k){
    cout << "POSSIBLE" << endl;
  }else{
    cout << "IMPOSSIBLE" << endl;
  }
}


Measured memory_bytes: 1024
#include <stdio.h>

int main(void)
{
	int n, i, j, random;
	scanf("%d", &n);
	for (i = 1; i <= n; i++)
	{
		scanf("%d", &random);
		printf("Case %d:\n", i);
		for (j = 0; j < 10; j++)
		{
			random = random * random / 100 % 10000;
			printf("%d\n", random);
		}
	}
	return 0;
}

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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  sort(a.begin(),a.end());
  int res = 0;
  vector<int> p(pow(10,6),0);
  rep(i,n){
    if (p[a[i]]==0){
      for(int j=1;j<=pow(10,6)/a[i];++j){
        p[j*a[i]]=1;
      }
      if ( i==n-1 || a[i+1]!=a[i] ){
        res+=1;
      }
    }
  }
  cout << res << endl;
  return 0;
}


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

using namespace std;
using namespace __gnu_pbds;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key

typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef long double ld;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

const long long mod = 1000000007;
const long long inf = 1e18;

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    int n,d,x;
    cin>>n>>d>>x;
    ll ans=0;
    for(int i=0;i<n;i++){
        int a;
        cin>>a;
        ans+=(d-1)/a+1;
    }
    cout<<ans+x<<endl;
    return 0;
}


Measured memory_bytes: 3640
# -*- coding: utf-8 -*-
A_500 = int(input()) #10
B_100 = int(input()) #2
C_50 = int(input()) #1
X = int(input())


cnt = 0
for a in range(0,A_500+1):
    for b in range(0,B_100+1):
        for c in range(0,C_50+1):
            if a * 500 + b * 100 + c * 50 == X:
                cnt += 1

print(cnt)

Measured memory_bytes: 3060
#include <iostream>
#include <sstream>
#include <string>
#include <cmath>
#include <array>
#include <vector>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <utility>
#include <iomanip>
#include <numeric>
#include <climits>
#include <algorithm>
#include <cstdint>
using namespace std;

int main()
{
    int n, m;
    cin >> n >> m;
    if (n == m)
        cout << "Yes";
    else cout << "No";
}

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


using namespace std;
const int maxn=10002;
int fa[maxn];
int n;
void init(){
    for(int i=1;i<=n;i++)
        fa[i]=i;
}

int find(int x){
    int y=fa[x];
    for(;fa[y]!=y;y=fa[y]);
    while(x!=y){
        int temp=fa[x];
        fa[x]=y;
        x=temp;
    }
    return y;
}

void merge(int x,int y){
    int nx=find(x);
    int ny=find(y);
    if(nx!=ny){
        fa[nx]=ny;
    }
}

int main(){
    int q;
    cin>>n>>q;
    init();
    while(q--){
        int com,x,y;
        cin>>com>>x>>y;
        if(com==0)
            merge(x,y);
        else{
            if(find(x)!=find(y)) cout<<"0"<<endl;
            else cout<<"1"<<endl;
        }


    }
}

Measured memory_bytes: 3124
# -*- coding: utf-8 -*-
from math import gcd

N = int(input())

dict_F = {}
count_0 = 0

def insert(A,B,s): # A>=0, B>0, s=0or1
  if (A,B) not in dict_F.keys():
    dict_F[(A,B)] = [0,0]
  dict_F[(A,B)][s] += 1

def make_power2(N):
  result = 1
  list_result = [1]
  for _ in range(N):
    result = (2*result)%mod
    list_result.append(result)
  return list_result

for i in range(N):
  A,B = map(int, input().split())
  if A==0 and B==0:
    count_0 += 1
    continue
  g = gcd(A,B)
  A //= g
  B //= g
  if A>=0 and B>0:
    insert(A,B,0)
  elif A>0 and B<=0:
    insert(-B,A,1)
  elif A<=0 and B<0:
    insert(-A,-B,0)
  elif A<0 and B>=0:
    insert(B,-A,1)

mod = 1000000007
power2 = make_power2(N)
answer = 1

for A,B in dict_F.values():
  answer = (answer*(power2[A]+power2[B]-1))%mod
answer = (answer+count_0-1)%mod

print(answer)

Measured memory_bytes: 68032
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using E = tuple<ll, int, ll>;
const ll inf = numeric_limits<ll>::max()/3;
const ll mod = 1e9 + 7;

int n;
vector< ll > v;

ll maxl(int bound,int k){
  ll res = 0;
  for(int i = 0;i <= min(bound,k);++i){
    ll calc = 0;
    vector< ll > elem;
    for(int j = 0;j < i;++j){
      elem.push_back(v[j]);
      calc += elem[j];
    }
    sort(elem.begin(),elem.end());
    for(int j = 0;j < min(i,k - i);++j){
      if(elem[j] < 0){
        calc -= elem[j];
      }else {
        break;
      }
    }
    res = max(res,calc);
  }
  return res;
}

ll maxr(int bound,int k){
  ll res = 0;
  for(int i = 0;i <= min(bound,k);++i){
    ll calc = 0;
    vector< ll > elem;
    for(int j = 0;j < i;++j){
      elem.push_back(v[n-1-j]);
      calc += elem[j];
    }
    sort(elem.begin(),elem.end());
    for(int j = 0;j < min(i,k - i);++j){
      if(elem[j] < 0){
        calc -= elem[j];
      }else {
        break;
      }
    }
    res = max(res,calc);
  }
  return res;
}


int main(void){
  int k;
  cin >> n >> k;
  v = vector<ll>(n);
  for(int i = 0;i < n;++i){
    cin >> v[i];
  }
  ll res = 0;
  for(int a = 0;a <= k;++a){
    int b = k - a;
    for(int i = 0;i <= n;++i){
      ll calc = maxl(i,a) + maxr(n - i,b);
      res = max(res,calc);
    }
  }
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
int main() {
    int n; cin >> n;
    string s; cin >> s;
    vector<bool> v(2*n);
    long long curr = 0; long long ans = 1;
    for (int i = 0; i < 2*n; i++) {
        if (curr % 2 == 0) {
            if (s[i] == 'B') {
                v[i] = 1; curr++;
            } else {
                v[i] = 0; ans = ans * curr % mod;
                curr--;
            }
        } else {
            if (s[i] == 'W') {
                v[i] = 1; curr++;
            } else {
                v[i] = 0; ans = ans * curr % mod;
                curr--;
            }
        }
        if (curr < 0) {
            cout << 0 << endl;
            return 0;
        }
    }
    if (curr != 0) {
        cout << 0 << endl;
        return 0;
    }

    for (int i = 1; i <= n; i++) {
        ans = ans * i % mod;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
ll ans=0;
void primefactor(ll n)
 {
     int x=0;
     while(n%2==0)
      {
          x++;
          n/=2;
      }
     int y=1;
     while(x>=y)
       {
           ans++;
           x-=y;
           y++;
       }
    for(ll i=3;i*i<=n;i++)
      {
          x=0;
          while(n%i==0)
           {
               x++;
               n/=i;
           }
        y=1;
      while(x>=y)
       {
           ans++;
           x-=y;
           y++;
       }
      }
  if(n>2)
    ans++;
 }
int main()
{
  ll n;
  cin>>n;
  primefactor(n);
  cout<<ans<<"\n";
}   

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

using namespace std;

const int max_size = 101;
int que[max_size];
int top = 0;

bool isFull()
{
	return top == max_size;
}

bool isEmpty()
{
	return top == 0;
}

void push(int key)
{
	if (isFull())
		cout << "Stack is Full" << endl;
	que[top++] = key;
}

int pop()
{
	if (isEmpty())
		cout << "Stack is EMPTY" << endl;
	return (que[--top]);
}
int main(int argc, char** argv)
{
	string s;
	while (cin >> s) {
		if (s == "+") {
			int a, b;
			a = pop();
			b = pop();
			push(a + b);
		}
		else if (s == "-") {
			int a, b;
			a = pop();
			b = pop();
			push(b - a);
		}
		else if (s == "*") {
			int a, b;
			a = pop();
			b = pop();
			push(b * a);
		}
		else
			push(atoi(s.c_str()));
	}
        cout << pop() << endl;

	return 0;
}

Measured memory_bytes: 3204
#include<cstdio>
#include<iostream>
#include<cmath>
#include<ctype.h>
#include<vector>
#include<cstdlib>
#include<cstdlib>
#include<string>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<time.h>

#define ll long long
#define LL long long
#define ULL unsigned long long 
#define ull unsigned long long 
#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(int i=0;i<n;i++)
#define RREP(i,n) for(int i=(n)-1;i>=0;i--)
const ll INF = -10000000000;
using namespace std;
ll dp[10001][101] = {};
int N, W;
int v[1000], w[1000];

int main()
{
	cin >> N >> W;
	REP(i, N) cin >> v[i] >> w[i];

	for (int i = 0; i <= W; i++) { //??\??????????????§??????
		for (int j = 0; j < N; j++) { //j????????\????????????
			if (i == 0) dp[i][j] = 0;
			else if (i >= w[j]) dp[i][j] = max(dp[i][j-1],dp[i-w[j]][j-1]+v[j]);
			else dp[i][j] = dp[i][j - 1];
		}
	}
	/*
	REP(i, W+1) {
		REP(j, N) {
			cout << dp[i][j] << " ";
		}
		cout << endl;
	}
	*/
	cout << dp[W][N - 1] << endl;

	return 0;
}

Measured memory_bytes: 9056
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define all(in) in.begin(), in.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define all(in) in.begin(), in.end()
#define MP make_pair
#define INF (sizeof(int) == 4 ? 1e9:1e18)
#define EPS 0.0000000001
using namespace std;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<typename Head, typename Value> auto vectors(const Head &head, const Value &v) { return vector<Value>(head, v); }
template<typename Head, typename... Tail> auto vectors(Head x, Tail... tail) { auto inner = vectors(tail...); return vector<decltype(inner)>(x, inner); }
template<class T> void join(T a){int b=0;for(auto itr :a){if(b++!=0)cout << " "; cout << itr;} }
using ll  = long long;
using ld  = long double;
using pii = pair<int,int>;
using piii = pair<int,pii>;
#define int ll
int W,H;
int dx[]={0,0,1,-1}, dy[]={1,-1,0,0};
bool valid(int x,int y){return (0<=x&&x<W)&&(0<=y&&y<H);}
int ans = -INF;
int h,w,c;
vector<vector<int>>graph;
void dfs2(int x,int y,int nc,int pc){
    if(nc == pc)return;
    graph[y][x] = nc;
    rep(k,4){
        int nx = dx[k] + x;
        int ny = dy[k] + y;
        if(valid(nx, ny) and graph[ny][nx] == pc){
            dfs2(nx, ny, nc,pc);
        }
    }
    return;
}
void dfs(int cnt){
    if(cnt == 5){
        dfs2(0, 0,c,graph[0][0]);
        dfs2(0, 0,INF,graph[0][0]);
        int temp = 0;
        rep(i,graph.size()){
            rep(j,graph[i].size()){
                //cout << graph[i][j];
                if(graph[i][j] == INF)temp++;
            }
         //   cout << endl;
        }
        cmax(ans,temp);
    } else {
        rep(i,6){
            auto g = graph;
            dfs2(0,0,i+1,graph[0][0]);
            dfs(cnt+1);
            graph = g;
        }
    }
}
signed main(){
    while(cin >> h >> w >> c,h+w+c){
        H = h;
        W = w;
        graph = vectors(h,w,0LL);
        ans =  -INF;
        rep(i,h)rep(j,w){
            cin >> graph[i][j];
        }
        dfs(1);
        cout << ans << endl;
    }
    
}




Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define lp3(i,a,b) for(int i=a;i<b;i++)
#define lp2(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
	int a[3];
	lp2(i,3)cin>>a[i];
	lp2(i,3){
		lp3(j,i+1,3){
			if(a[i]>=a[j])swap(a[i],a[j]);
		}
	}
	cout<<a[2]-a[0]<<endl;
		return 0;
}

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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"

using namespace std;
using ll = long long;
using P = pair<ll, ll>;

const ll MOD = 1000000007LL; // = 10^9 + 7
const double PI = 3.14159265358979;

void solve()
{
	ll n, a, b;
	cin >> n;
	vector<P> task(n);
	for(int i = 0; i < n; ++i)
	{
		cin >> a >> b;
		task[i] = P(b, a);
	}
	sort(task.begin(), task.end());

	ll sum_a = 0, now_b = 0;
	for(int i = 0; i < n; ++i)
	{
		now_b = task[i].first;
		sum_a += task[i].second;
		if (now_b < sum_a)
		{
			cout << "No";
			return;
		}
	}
	cout << "Yes";
}

int main()
{
	fastio;
	solve();

	return 0;
}

Measured memory_bytes: 6348
N=int(input())
S=[]
res=[]
for i in range(round(N**0.5)):
    if N%(i+1)==0:
        S.append([i+1,int(N/(i+1))])
for j in range(len(S)):
    res.append(len(str(S[j][1])))
print(min(res))

Measured memory_bytes: 39152
inpl = lambda: list(map(int,input().split()))
N, M = inpl()
fav = [1]*M
for _ in range(N):
    A = inpl()[1:]
    for m in range(M):
        if m+1 in A:
            pass
        else:
            fav[m] = 0
print(sum(fav))

Measured memory_bytes: 3060
#include "bits/stdc++.h"
using namespace std;
int main() {
	long long n, i, total = 0;

	cin >> n;

	for (i = 1; i <= n; i++) {
		if (i % 3 == 0 && i % 5 == 0) {
		}
		else if (i % 3 == 0) {
		}
		else if (i % 5 == 0) {
		}
		else {
			total += i;
		}
	}

	cout << total << endl;
	return 0;
}


Measured memory_bytes: 3632
n= int(input())
a = list(map(int,input().split()))
from collections import defaultdict

d = defaultdict(int)

for i in range(n):
    d[a[i]] += 1

ans = []

for i in range(-100,101):
    cnt = 0
    for j in d.keys():
        cnt += d[j]*(i-j)**2
    ans.append(cnt)

print(min(ans))


Measured memory_bytes: 39280
// vvvvvvvvvvvv TEMPLATE vvvvvvvvvvvv
#include <bits/stdc++.h>
using namespace std; using ll = long long; using P = pair<ll, ll>;
const ll linf = 1e18; const double eps = 1e-12, pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define each(i,a) for (auto&& i : a)
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
#define pb push_back
#define eb emplace_back
#define all(a) begin(a),end(a)
#define chmin(x,v) x = min(x, v)
#define chmax(x,v) x = max(x, v)
#define min(x,y) (x < y ? x : y)
#define max(x,y) (x < y ? y : x)
template<typename Head> void out(Head h) { cout << h << endl; } template<typename Head, typename... Tail>void out(Head h, Tail... t) { cout << h << " "; out(t...); }
template<typename T> istream& operator>>(istream& is, vector<T>& v) { each(x,v) is >> x; return is; }
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) { rep(i,v.size()) { if (i) os << " "; os << v[i]; } return os; }
template<typename T> ostream& operator<<(ostream& os, const vector<string>& v) { rep(i,v.size()) { if (i) os << endl; os << v[i]; } return os; }
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) { rep(i,v.size()) { if (i) os << endl; os << v[i]; } return os; }
struct yes_no : std::numpunct<char> { string_type do_truename() const { return "Yes"; } string_type do_falsename() const { return "No"; } };
void solve(); int main() {
  ios::sync_with_stdio(false); cin.tie(0); locale loc(locale(), new yes_no); cout.imbue(loc); cout << fixed << setprecision(10) << boolalpha;
  solve();
}
// ^^^^^^^^^^^^ TEMPLATE ^^^^^^^^^^^^

struct Log {
  // 0: pop
  // 1: push x
  // 2: nop
  ll type, val, diff;
};

void solve() {
  string s; cin >> s;
  const ll n = s.size();
  stack<ll> S;
  stack<Log> logs;
  vector<ll> memo(n+1, 0);
  ll len = 0, ans = 0;
  rep(i, n) {
    if (s[i] == '(') {
      S.push(len);
      memo[len+1] = 0;
      ++len;
      logs.push({0});
    }
    else if (s[i] == ')') {
      if (S.empty()) {
        memo[len+1] = 0;
        logs.push({2});
      }
      else {
        ll l = S.top(); S.pop();
        memo[len+1] = 1 + memo[l];
        ans += memo[len+1];
        logs.push({1, l, memo[len+1]});
      }
      ++len;
    }
    else {
      auto log = logs.top(); logs.pop();
      if (log.type == 0) {
        S.pop();
      }
      else if (log.type == 1) {
        S.push(log.val);
        ans -= log.diff;
      }
      --len;
    }
    cout << ans << endl;
  }
}



Measured memory_bytes: 11180
(defn solve
  ([s t] (solve s t 0))
  ([s t acc]
   (if (nil? s)
     acc
     (if (= (first s) (first t))
       (solve (next s) (next t) (inc acc))
       (solve (next s) (next t) acc)))))

(println (solve (str (read)) (str (read))))


Measured memory_bytes: 61880
#include <stdio.h>

int main(void) {
  int a, b;
  scanf("%d %d", &a, &b);

  if ( a > 12 ) printf("%d", b);
  else if ( a >= 6 ) {
    printf("%d", b/2);
  }
  else if ( a <= 5 ) {
    printf("%d", 0);
  }

  return 0;
}

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

int main()
{
	int n;
	
	while( cin >> n &&  n ){
		int* table = new int[ (n+1) * (n+1) ]();
		for( int i = 0; i < n; ++i ){
			int sum_col = 0;
			for( int j = 0; j < n; ++j ){
				int d;
				cin >> d;
				table[ i * (n+1) + j ] = d;
				table[ i * (n+1) + n ] += d;
				table[ n * (n+1) + j ] += d;
				table[ n * (n+1) + n ] += d;
			}
		}

		for( int i = 0; i < n+1; ++i ){
			for( int j = 0; j < n+1; ++j ){
				cout.width( 5 );
				cout << table[ i * (n+1) + j ];
			}
			cout << endl;
		}

		delete[] table;
	}
	return 0;
}

Measured memory_bytes: 0
from numpy import*
n,*a=map(int,open(0).read().split())
*s,=t=arange(n-1)
for i in a[-a[n]:]:t[[i-2,i-1]]=t[[i-1,i-2]]
k=a[n+1]
while k:s=[s,t[s]][k%2];t=t[t];k//=2
print(*cumsum(a[:1]+list(diff(a[:n])[s])))

Measured memory_bytes: 33352
n = int(input())
c = input()
f = 0
ans = 0
if 'W' not in c:
    f = 1

r_count = c.count("R")
for i in range(r_count):
    if c[i] == "R":
        ans -= 1

if f == 1:
    print("0")
else:
    print(ans+r_count)

Measured memory_bytes: 65064
#include <stdio.h>
 
int main(void)
{
  int N,K,X,Y;
  scanf("%d\n%d\n%d\n%d",&N,&K,&X,&Y);
  if (1 <= N && N <= 10000 && 1 <= K && K <= 10000 && 1 <= Y && Y < X && X <= 10000) {
    if (N > K) {
      printf("%d\n",K * X + (N - K) * Y);
    } else {
      printf("%d\n",N * X);
    }
  }
  return 0;
}

Measured memory_bytes: 128
N = int(input())
X = sorted([list(map(int, input().split())) for _ in range(N)], key = lambda x: x[1])
a = [0] * N
a[0] = X[0][0]
for i in range(1, N):
	a[i] = a[i - 1] + X[i][0]
for j in range(N):
	if a[j] > X[j][1]:
		print("No")
		exit()
print("Yes")


Measured memory_bytes: 58260
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n)for(int i=0;i<(n);i++)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
using ll = long long;
using P = pair<int, int>;
using Graph = vector<vector<int>>;

int main(){
    int n; cin >> n;
    string s; cin >> s;
    int ans = 0;
    rep(i,1000){
        //3桁の整数全探索
        int digit[3] = {i/100, (i/10)%10, i%10};
        int cnt = 0;
        rep(j, s.size()){
            if(s[j]=='0'+digit[cnt]) cnt++;
            if(cnt==3) break;
        }
        if(cnt == 3) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
    int D;
    cin>>D;
    if(D == 25)
    {
        cout<<"Christmas"<<endl;
    }
    else if(D == 24)
    {
        cout<<"Christmas Eve"<<endl;
    }
    else if(D == 23)
    {
        cout<<"Christmas Eve Eve"<<endl;
    }
    else if(D == 22)
    {
        cout<<"Christmas Eve Eve Eve"<<endl;
    }


    return 0;

}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include <stdio.h>
#include<algorithm>
#include<cstring>
#include <string>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<map>
#include<vector>
#include<bits/stdc++.h>
#include <set>
#define ll long long
#define IO ios::sync_with_stdio(false);cin.tie();cout.tie(0)
#define inf 0x3f3f3f3f
#define pi 3.1415926535898
using namespace std;
int dx[]= {0,0,1,-1};
int dy[]= {1,-1,0,0};
int main()
{
    int h,w,k;
    cin>>h>>w>>k;
    int x1,y1,x2,y2;
    cin>>x1>>y1>>x2>>y2;
    char maps[h][w];
    int dis[h][w];
    for(int i=0; i<h; i++)
    {
        for(int j=0; j<w; j++)
        {
            cin>>maps[i][j];
            dis[i][j]=inf;
        }
    }
    x1--,x2--,y1--,y2--;
    queue <pair<int,int> > q;
    dis[x1][y1]=0;
    q.push({x1,y1});
    while(!q.empty())
    {
        int x=q.front().first;
        int y=q.front().second;
        q.pop();
        for(int i=0; i<4; i++)
        {
            int nx=x;
            int ny=y;
            int nd=dis[x][y]+1;
            for(int j=1; j<=k; j++)
            {
                nx+=dx[i];
                ny+=dy[i];
                if (nx<0 || nx>=h || ny<0 || ny>=w || '@'==maps[nx][ny] || dis[nx][ny]<nd)
                {
                    break;
                }
                if(dis[nx][ny]>nd)
                {
                    dis[nx][ny]=nd;
                    q.push({nx,ny});
                }

            }
        }


    }
    int ans = dis[x2][y2];
    if(ans==inf)
    {
        cout<<-1<<endl;
    }
    else
    {
        cout<<ans<<endl;
    }
    return 0;
}


Measured memory_bytes: 9192
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define MOD 1000000007LL
#define REP(i,n) for(ll i=0;i<(n);i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,n) for(ll i=(n);i>=0;i--)
#define pb push_back
#define mp make_pair
#define ii pair<ll,ll>
#define iii pair<ll,ii>
#define vi vector<ll>
#define vii vector<ii> 
#define viii vector<iii>
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);
#define endl "\n"
#define MAX 2e5
#define MAXV 1e7
#define deb(x) cout<<"#"<<x<<endl;
using namespace __gnu_pbds; 
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds; 
ll modexpo(ll a,ll b){
    a%=MOD;
    ll res=1;
    while(b>0){
         if (b%2==1)
            res=(res*a)%MOD;
        a=(a*a)%MOD;
        b/=2;
    }
    return res;
}
string to_s(ll t) {
  stringstream ss;
  ss << t;
  return ss.str();
}
ll modinv(ll a){
    return modexpo(a,MOD-2);
}
int main()
{
    fastio
    ll n;
    cin>>n;
    double p[n+1];
    FOR(i,1,n+1){
        cin>>p[i];
    }
    double dp[n+1][n+1];
    dp[1][0]=1-p[1];
    dp[1][1]=p[1];
    FOR(i,2,n+1){
        dp[i][0]=(1-p[i])*dp[i-1][0];
        FOR(j,1,i+1){
            dp[i][j]=p[i]*dp[i-1][j-1]+(1-p[i])*dp[i-1][j];
        }
    }
    ll mid=n/2;
    double ans=0;
    FOR(i,mid+1.,n+1){
        ans+=dp[n][i];
    }
    cout<<setprecision(10)<<ans;
    return 0;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

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

#define DEBUG(x) cout<<#x<<": "<<(x)<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";REP(i, v.size())cout<<' '<<v[i];cout<<'\n'
#define ALL(a) (a).begin(), (a).end()

template<typename T> inline void CHMAX(T& a, const T b) {if(a<b) a=b;}
template<typename T> inline void CHMIN(T& a, const T b) {if(a>b) a=b;}

constexpr ll MOD=1000000007ll;
// constexpr ll MOD=998244353ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

const double EPS=1e-9;
#define EQ0(x) (abs((x))<EPS)
#define EQ(a, b) (abs((a)-(b))<EPS)

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  // cout<<setprecision(10)<<fixed;
  int n, k, p[1252];
  cin>>n>>k;
  REP(i, n){
    cin>>p[i];
  }
  sort(p, p+n);
  int ans=0;
  REP(i, k){
    ans+=p[i];
  }
  cout<<ans<<'\n';
  return 0;
}


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

int main(){
  int n, a, b, c;
  cin >> n;

  if(n / 100 == 1)
    a = 9;
  else if(n / 100 == 9)
    a = 1;

  if((n%100)/10 == 1)
    b = 9;
  else if((n%100)/10 == 9)
    b = 1;

  if(n % 10 == 1)
    c = 9;
  else if(n % 10 == 9)
    c = 1;

  cout << a << b << c << endl;

  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int n,a[1000],i,t,min,s;
	
	while(scanf("%d",&n))
	{
		if(n==0)
		{
			break;
		}
		
		for(i=0;i<n;i++)
		{
			scanf("%d",&a[i]);
		}
		
		min = 10000000;
		
		for(i=0;i<n;i++)
		{
			for(t=0;t<n;t++)
			{
				if(t!=i)
				{
					if(a[i]<a[t])
					{
					    s = a[t] - a[i];
					}
					else
					{
						s = a[i] - a[t];
					}
					if(s<min)
					{
						min = s;
					}
				}
			}
		}
		
		printf("%d\n",min);
	}
	
	return 0;
}
		


Measured memory_bytes: 2076
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repi(i, s, n) for (int i = (s); i < (n); i++)
#ifdef LOCAL
#define INPUT_FILE                   \
  ifstream in("abc179/abc179_a.txt"); \
  cin.rdbuf(in.rdbuf());
#define print_vec(v) \
rep(l, v.size()) { cout << v[l] << " "; } \
cout << endl;
#else
#define INPUT_FILE
#define print_vec(v)
#endif
#define CIN_OPTIMIZE \
  cin.tie(0);        \
  ios::sync_with_stdio(false);
typedef pair<int, int> P;
typedef long long ll;
typedef pair<ll, ll> pl;
const int INF = 100100100;
const ll LINF = 1e18+100;
const int MOD = 1e9 + 7;

int main() {
  INPUT_FILE CIN_OPTIMIZE;

  string s;
  cin >> s;

  int N = s.size();
  string c = "s";
  if (s[N - 1] == 's') {
    c = "es";
  }

  cout << s << c << endl;
}

Measured memory_bytes: 3664
#include<bits/stdc++.h>
using namespace std;
long long n,s,cnt,i;
int main() {
	cin>>n;
	while(i<n) {
		++i;
		if(i%3==0) continue;
		if(i%5==0) continue;
		s+=i;
	}
	cout<<s;
}

Measured memory_bytes: 3588
import java.util.*;
class Main{
  public static void main(String[] args){
       Scanner sc = new Scanner(System.in);
   String a = sc.next();
    if(a.equals("SUN")){
      System.out.println(7);
    } else if(a.equals("MON")) {
     System.out.println(6);
    } else if (a.equals("TUE")){
     System.out.println(5);
    } else if(a.equals("WED")){
    System.out.println(4);
    } else if(a.equals("THU")){
      System.out.println(3);
    } else if(a.equals("FRI")){
     System.out.println(2);
    } else if(a.equals("SAT")){
      System.out.println(1);
    }
 }
}

Measured memory_bytes: 21844