akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define GET_MACRO(_1,_2,_3,_4,_5,_6,_7,_8,NAME,...) NAME
#define pr(...) cerr<< GET_MACRO(__VA_ARGS__,pr8,pr7,pr6,pr5,pr4,pr3,pr2,pr1)(__VA_ARGS__) <<endl
#define pr1(a) (#a)<<"="<<(a)<<" "
#define pr2(a,b) pr1(a)<<pr1(b)
#define pr3(a,b,c) pr1(a)<<pr2(b,c)
#define pr4(a,b,c,d) pr1(a)<<pr3(b,c,d)
#define pr5(a,b,c,d,e) pr1(a)<<pr4(b,c,d,e)
#define pr6(a,b,c,d,e,f) pr1(a)<<pr5(b,c,d,e,f)
#define pr7(a,b,c,d,e,f,g) pr1(a)<<pr6(b,c,d,e,f,g)
#define pr8(a,b,c,d,e,f,g,h) pr1(a)<<pr7(b,c,d,e,f,g,h)
#define prArr(a) {cerr<<(#a)<<"={";int i=0;for(auto t:(a))cerr<<(i++?", ":"")<<t;cerr<<"}"<<endl;}
using namespace std;
using Int = long long;
using _int = int;
using ll = long long;
using Double = long double;
const Int INF = (1LL<<60)+1e9; // ~ 1.15 * 1e18
const Int mod = (1e9)+7;
const Double EPS = 1e-8;
const Double PI = 6.0 * asin((Double)0.5);
using P = pair<Int,Int>;
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
template<class T1, class T2> ostream& operator<<(ostream& o,pair<T1,T2> p){return o<<"("<<p.first<<","<<p.second<<")";}
template<class T1, class T2, class T3> ostream& operator<<(ostream& o,tuple<T1,T2,T3> t){
  return o<<"("<<get<0>(t)<<","<<get<1>(t)<<","<<get<2>(t)<<")";}
template<class T1, class T2> istream& operator>>(istream& i,pair<T1,T2> &p){return i>>p.first>>p.second;}
template<class T> ostream& operator<<(ostream& o,vector<T> a){Int i=0;for(T t:a)o<<(i++?" ":"")<<t;return o;}
template<class T> istream& operator>>(istream& i,vector<T> &a){for(T &t:a)i>>t;return i;}
//INSERT ABOVE HERE

template<typename T>
class CumulativeSum{
public:
  Int n;
  vector<T> sum;
  vector<T> A;
  Int added;
  CumulativeSum():n(-1),added(0){}
  CumulativeSum(Int n):n(n), sum(n+1), A(n+1),added(0){}
  CumulativeSum(const vector<T> &B):n(B.size()), sum(n+1), A(n+1),added(0){
    for(Int i=1;i<=n;i++) sum[i] = sum[i-1] + B[i-1];
  }

  void apply(){
    for(Int i=1;i<=n;i++) A[i] = A[i] + A[i-1];
    for(Int i=1;i<=n;i++) A[i] = A[i] + A[i-1];
    for(Int i=1;i<=n;i++) sum[i] = sum[i] + A[i-1];
    added = 0; A.clear(); A.resize(n+1);
  }

  //[l, r)にxを加算
  void add(Int l, Int r, T x){
    added = 1;
    assert(l <= r && 0 <= l && r <= n);
    A[l] = A[l] + x;
    A[r] = A[r] - x;
  }

  //[l, r)の和を得る
  T get(Int l,Int r){
    assert(l<=r && 0<=l && r<=n);
    if(added) apply();
    return sum[r] - sum[l];
  }
};


signed main(){
  srand((unsigned)time(NULL));
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  Int N, M;
  cin>>N>>M;
  vector<P> A(N);
  for(Int i=0;i<N;i++){
    Int a, b;
    cin>>a>>b;
    A[i] = P(a, b);
  }
  sort(A.begin(), A.end());
  Int idx = 0;
  Int ans = 0;
  priority_queue<Int> Q;
  for(Int i=M;i>=0;i--){
    while(idx < N && i + A[idx].first <= M) Q.push(A[idx].second), idx++;
    if(!Q.empty()) ans += Q.top(), Q.pop();
  }
  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 2936
def examC():
    N = I()
    x = LI(); num = [i for i in range(N)]
    X = list(zip(x,num)); X.sort()
    ans = [0]*N
    mid0 = X[(N)//2-1][0]; mid1 = X[(N)//2][0]
    for i in range(N):
        if X[i][0]<mid1:
            ans[X[i][1]] = mid1
        else:
            ans[X[i][1]] = mid0
    for v in ans:
        print(v)

import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

examC()


Measured memory_bytes: 99484
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <iostream>
#include <queue>
#include <unordered_map>
#include <cmath>
#include <queue>
#include <string>
#include <random>
using namespace std;
typedef long long ll;
const int maxn = 100005;

int n,m,q;
ll a[maxn],b[maxn];

void pd(ll &ret, ll val){
  if(ret==-1L||ret>val)ret=val;
}

int bs(ll a[], int n, ll val){
  int l =0,r=n-1,ret=-1;
  while(l<=r){
    int m=(l+r)>>1;
    if(a[m]>=val){
      ret=m;
      r=m-1;
    } else l=m+1;
  }
  return ret;
}

int main() {
#ifdef suiyuan2009
  freopen("/Users/suiyuan2009/CLionProjects/icpc/input.txt", "r", stdin);
  //freopen("/Users/suiyuan2009/CLionProjects/icpc/input.txt", "w", stdout);
#endif
  cin>>n>>m>>q;
  for(int i=0;i<n;i++)cin>>a[i];
  for(int i=0;i<m;i++)cin>>b[i];
  while(q--) {
    ll x;
    cin >> x;
    ll ret = -1;
    int pa = bs(a, n, x);
    int pb = bs(b, m, x);
    int la = -1;
    if (pa == -1)la = n - 1;
    else la = pa - 1;
    int lb = -1;
    if (pb == -1)lb = m - 1;
    else lb = pb - 1;
    vector<int> va = {pa, la};
    vector<int> vb = {pb, lb};
    for (int aa : va)
      for (int bb:vb) {
        if (aa == -1 || bb == -1)continue;
        ll tmp = abs(a[aa] - b[bb]) + min(abs(x - a[aa]), abs(x - b[bb]));
        pd(ret, tmp);
      }
    cout<<ret<<endl;
  }
  return 0;
}

Measured memory_bytes: 2816
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()


int main() {
  int k, a, b;
  cin >> k >> a >> b;
  bool flag = false;
  for (int i = a; i <= b; i++) {
    if (i%k == 0) flag = true;
  }
  if (flag) puts("OK");
  else puts("NG");
}

Measured memory_bytes: 3652
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <functional>
using namespace std;

#define Rep(b, e, i) for(int i = b; i <= e; i++)
#define rep(n, i) Rep(0, n-1, i)
#define MAX 200000
#define INF (ll)1e10
#define MOD 1000000007

typedef long long ll;
typedef pair<ll, ll> P;
typedef std::priority_queue<int> IntPrioQueue; //Z->A
typedef std::priority_queue<int, std::vector<int>, std::greater<int> > IntReversePrioQueue; //A->Z


void solve(void){
    ll x;
    cin >> x;
    string sx = to_string(x);
    ll ans = 0;
    if (sx[0] == '9') {
        bool flag = true;
        rep(sx.length(), i){
            if (sx[i] != '9') flag = false;
        }
        if (flag) ans = 9 * sx.length();
        else ans = (sx.length() - 1) * 9 + 8;
    }
    else {
        bool flag = true;
        Rep(1, sx.length()-1, i){
            if (sx[i] != '9') flag = false;
        }
        if (flag) rep(sx.length(), i) ans += sx[i] - '0';
        else ans = (sx.length() - 1) * 9 + (sx[0] - '1');
    }
    cout << ans << '\n';
}

int main(void){
  solve();
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int MXN = 500010;

int n, f[MXN];
char str[MXN];

void solve() {
	cin >> n;
	cin >> str + 1;
	for (int i = 2; i <= n; ++i) {
		f[i] = max(f[i], f[i - 1]);
		if (str[i] == '0' && str[i - 1] == '1' && str[i + 1] == '1') {
			for (int k = i - 1; str[k] == '1'; --k)
				f[i + 1] = max(f[i + 1], f[k - 1] + i - k);
			for (int k = i + 1; str[k] == '1'; ++k)
				f[k] = max(f[k], f[i - 2] + k - i);
		}
	}
	cout << f[n] << endl;
}
int main() {
	solve();
	return 0;
}


Measured memory_bytes: 2688
N, K = map(int, input().split())
S = input()

nowLR = S[0]
group_num = 1
for i in range(1, N):
    if S[i] != nowLR:
        group_num += 1
        nowLR = S[i]

max_rev = int(group_num / 2)
if max_rev <= K:
    print(N-1)
else:
    print(N - (group_num - 2 * K))

Measured memory_bytes: 39408
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
using namespace std;

template<typename T>
ostream& operator << (ostream& os, vector<T>& v){
	rep(i,v.size()){ os << v[i] << (i == v.size() - 1 ? "" : " "); } return os;
}
template<typename T>
istream& operator >> (istream& is, vector<T>& v){
	for(T& x: v){ is >> x; } return is;
}

int main(){
	double n, m, d;
	cin >> n >> m >> d;

	double a;
	if(d == 0) a = n;
	else {
		a = 2 * (n - 1) - (2 * (d - 1));
	}
	//a *= n * (m - 2);

	cout << fixed << setprecision(8) << a / (n * n) * (m - 1) << endl;
}


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

using namespace std;

int main(void) {
	int ans = 0, ma;
	vector<int> d(3);
	scanf("%d%d%d", &d[0], &d[1], &d[2]);
	if ((d[0] & 1) != (d[1] & 1)) {
		if ((d[0] & 1) == (d[2] & 1))
			d[0]++;
		else
			d[1]++;
		d[2]++;
		ans++;
	}
	else if ((d[0] & 1) != (d[2] & 1)) {
		d[0]++;
		d[1]++;
		ans++;
	}
	ma = max(d[0], d[1]);
	ma = max(ma, d[2]);
	ans += (ma - d[0]) / 2 + (ma - d[1]) / 2 + (ma - d[2]) / 2;
	cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define rep(i, n) for(int i=0; i<n; i++)
#define REP(i, n) for(int i=0; i<=n; i++)
#define repr(i, n) for(int i=n; i>0; i--)
#define REPR(i, n) for(int i=n; i>=0; i--)
const ll INF = 1LL<<60;
const int INT_INF = 1e9;
const ll MOD = 1e9+7;
template<class T> void puts(T x) { std::cout << x << std::endl; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using namespace std;

ll N, M;

int main() {
    cin >> N >> M;
    ll a = (2 * N + M) / 4;
    cout << min(a, M / 2) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rrep(i, n) for(int i = (n-1); i >= 0; i--)
using namespace std;
typedef long long ll;
const int MOD = 1000000007;
const ll INF = 1LL<<62;
const int IINF = 1000000000;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using Graph = vector<vector<int>>;

typedef pair<int, int> P;

int main(){
    int N, K, S; cin >> N >> K >> S;
    vector<int> ans(N);

    rep(i,N){
        if (S < 1e9){
            if(K > 0){
                ans[i] = S;
            }
            else{
                ans[i] = 1e9;
            }
        }
        else{
            if(K > 0){
                ans[i] = S;
            }
            else{
                ans[i] = 1;
            }
        }
        K--;
    }
    rep(i,N){
        printf("%d%c", ans[i], i==N-1?'\n':' ');
    }
}


Measured memory_bytes: 3836
#include <iostream>
#include <algorithm>
#include <vector>
#define rep(i, n) for(int i =0; i < n ;i++)
using namespace std;

int main(){
    int N,n, ss=0;
    cin >>N;
    n=N;

    while(true){
        ss += n%10;
        n /= 10;
        if(n==0)break;
    }
    
    if(N%ss==0) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

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

#define REP(i, n) for(int (i) = 0; (i) < (n); ++(i))
#define REPR(i, n) for(int (i) = (n); (i) >= 0; --(i))
#define FOR(i, n, m) for(int (i) = (n); (i) < (m); ++(i))

constexpr int INF = 1e9;
//constexpr ll INF = 1LL<<61;
constexpr ll mod = 1e9+7;



int main(){
  int N, M;
  cin >> N >> M;
  vector<int> H(N);
  REP(i, N){
    cin >> H[i];
  }
  vector<vector<int>> g(N);
  REP(i, M){
    int a, b;
    cin >> a >> b;
    a--, b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  int ans = 0;
  REP(i, N){
    bool flag = true;
    for(auto nv : g[i]){
      if(H[i] <= H[nv]){
        flag = false;
      }
    }
    if(flag){
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}


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

int digsum(int n){
  int res = 0;
  while(n > 0){
    res++;
    n /= 10;
  }
  return res;
}

int main(){
  int N;
  int cnt = 0;

  cin >> N;

  for(int i = N; i > 0; i--){
    if((digsum(i)) % 2 == 1) cnt++;
  }

  cout << cnt << endl;

}

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

using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using vint = vector<int>;
using vvint = vector<vint>;
using vvvint = vector<vvint>;
using vdouble = vector<double>;
using vvdouble = vector<vdouble>;
using vvvdouble = vector<vvdouble>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using uint = unsigned int;
using ull = unsigned long long;

template<typename T> using uset = unordered_set<T>;
template<typename T1, typename T2> using umap = unordered_map<T1, T2>;

constexpr int INF = (1 << 30) - 1;
constexpr ll LLINF = 1LL << 60;
constexpr int dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr char el = '\n';
constexpr int mod = 1000000007;
constexpr int mod2 = 998244353;
template<typename T> T gcd(T a, T b) { return (b ? gcd(b, a % b) : a); }
template<typename T> T lcm(T a, T b) { return (a / gcd(a, b) * b); }
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) { return (a > b && (a = b, true)); }
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) { return (a < b && (a = b, true)); }

template<typename T>
vector<T> makeVector(size_t a, T b) { return (vector<T>(a, b)); }
template<typename... Ts>
auto makeVector(size_t a, Ts... ts) { 
	return (vector<decltype(makeVector(ts...))>(a, makeVector(ts...)));
}

template<typename T>
bool isin(T y, T x, T h, T w) { return (0 <= y && 0 <= x && y < h && x < w); }
template<typename T>
bool isin1(T y, T x, T h, T w) { return (0 < y && 0 < x && y <= h && x <= w); }

template<typename T>
ostream& operator <<(ostream &os, vector<T> &v) {
	os << v[0];
	for (int i = 1; i < v.size(); i++) os << " " << v[i];
	return (os);
}

template<typename T>
istream& operator >>(istream &is, vector<T> &v) {
	for (auto &u : v) is >> u;
	return (is);
}

template<typename T1, typename T2>
istream& operator >>(istream &is, pair<T1, T2> &p) {
	return (is >> p.first >> p.second);
}


void Main() {
	int N, M, K; cin >> N >> M >> K;
	vll A(N), B(M); cin >> A >> B;
	
	ll maxv = 0;
	ll sum = 0;
	int j;
	for (j = 0; j < M; j++) {
		if (sum + B[j] <= K) {
			sum += B[j];
		} else {
			break;
		}
	}
	chmax(maxv, j);
	j--;
	
	for (int i = 0; i < N; i++) {
		sum += A[i];
		while (j >= 0 && sum > K) {
			sum -= B[j];
			j--;
		}
		if (sum <= K) {
			chmax(maxv, i + j + 2);
		}
	}
	cout << maxv << endl;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(0);
	cout << fixed << setprecision(20);
	Main();
	return (0);
}


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

typedef long long LL;
const int MO=1e9+7;
const int MB=65;
// x<=y x^y==y%x

// highbit() Most Significant Bit
// highbit(x) != highbit(y)
// x^y>x && x%y<x no solution
// so highbit(x) == highbit(y)
// so floor(y/x) == 1
// x^y==y%x -> x^y == y-x

// for y-x
// i-th bit 
// 1-1 0-0 = 0 -> xor same
// 1-0 = 1 -> xor same

// 0-1 change higher bit! impossible!

void add(int &x,int y)
{
	x+=y;
	if(x>=MO) x-=MO;
}

int dp[MB][2][2][2]; 
// dp[i-th digit][upperbound][lowerbound][leading zero] 

LL L,R;

int getdp(int d,int llim,int rlim,int lead)
{
	if(d==-1)
		return 1;
	int &ans=dp[d][llim][rlim][lead];
	if(ans!=-1) return ans;
	ans=0;
	for(int i=0;i<2;i++)
		for(int j=0;j<2;j++)
		{
			if(i==0&&j==1) continue;
			if(lead&&(i!=j)) continue;
			int l=((L>>d)&1);
			int r=((R>>d)&1);
			if(llim&&j<l) continue;
			if(rlim&&i>r) continue;
			add(ans,getdp(d-1,llim&&l==j,rlim&&r==i,lead&&!i&&!j));
		}
	return ans;
}

int main()
{
	cin>>L>>R;
	memset(dp,-1,sizeof(dp));
	cout<<getdp(61,1,1,1)<<endl;
	return 0;
}

Measured memory_bytes: 256
function Main(input) {
  var lines = input.split('\n');
  var line_1 = lines[0].split(' ');
  var line_2 = lines[1].split(' ');
  var N = Number(line_1[0]);
  var M = Number(line_1[1]);
  var count = 0;
  var all = 0;
  for (var j = 0; j < N; j ++) {
    all += Number(line_2[j]);
  }
  for (var i = 0; i < N; i ++) {
    var A = Number(line_2[i]);
    if ((1/(4*M)*all) <= A ) {
      count ++;
    }
  }
  if (M <= count) {
    console.log('Yes');
  } else {
    console.log('No');
  }
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 7500
from itertools import *
g=lambda a,x,b:a+b if x=='+'else a-b if x=='-'else a*b
def f(s):
 for a,b,c,d in permutations(s):
  for x,y,z in product('+-*',repeat=3):
   if g(g(g(a,x,b),y,c),z,d)==10:return f"((({a} {x} {b}) {y} {c}) {z} {d})"
   if g(g(a,x,b),y,g(c,z,d))==10:return f"(({a} {x} {b}) {y} ({c} {z} {d}))"
 return 0
[print(f(list(map(int,e.split()))))for e in iter(input,'0 0 0 0')]


Measured memory_bytes: 5656
#include<stdio.h>
int main(){
  int i=0,x[10000];
  while (1) {
    scanf("%d\n", &x[i]);
    if(x[i] == 0){
      break;
    }else if (1 <= x || x >= 10000) {
      printf("Case %d: %d\n", i+1, x[i]);
    }else{
      break;
    }
    i++;
  }
  return 0;
}

Measured memory_bytes: 644
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();
        long k = sc.nextLong();
        if(k == 1 || n == k){
            System.out.println("0");
        }else if(n > k){
            long t = n % k;
            long t1 = k - t;
            System.out.println(Long.min(t, t1));
        }else{
            long t = k - n;
            System.out.println(Long.min(t, n));
        }
    }
}

Measured memory_bytes: 23764
#include<iostream>
#include<algorithm>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;

int main(){
	int n;
	cin>>n;
	int d[n];
	rep(i,n)cin>>d[i];
	sort(d,d+n);
	int now=0,tmp=-1,cnt=0;
	while(now<n){
		if(tmp!=d[now]){
			tmp=d[now];
			cnt++;
		}
		now++;
	}
	cout<<cnt<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
int flag=0;char ch;
int main()
{
ch=getchar();
do
	{
	if(ch=='C')flag=1;
	if(flag&&ch=='F'){puts("Yes");return 0;}
	ch=getchar();
	}while(ch!=-1);
puts("No");
return 0;
}

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

#define REP(i, n) for (ll (i) = 0 ; (i) < (ll)(n) ; ++(i))
#define REPN(i, m, n) for (ll (i) = m ; (i) < (ll)(n) ; ++(i))
#define REP_REV(i, n) for (ll (i) = (ll)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (ll (i) = (ll)(n) - 1 ; (i) >= m ; --(i))

#define INF 2e9
#define INF_LL 1LL<<60
#define ll long long

typedef pair<int, int> P;

int main(){
    int n;
    cin >> n;
    vector<P> a(n);

    REP(i, n) {
        int x, l;
        cin >> x >> l;
        a[i].first = x+l;
        a[i].second = x-l;
    }

    sort(a.begin(), a.end());

    int ans = 1, end = a[0].first;

    REPN(i, 1, n) {
        if(a[i].second >= end) {
            ans++;
            end = a[i].first;
        }

    }

    cout << ans << endl;


    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int num[100010],r[100010],same[100010];
int main(){
	ios::sync_with_stdio(false);
	int n,m;
	cin>>n>>m;
	for(int i=1;i<=n;i++){
		int x;
		cin>>x;
		num[x]++;
	}
	for(int i=1;i<=100000;i++){
		r[i%m]+=num[i];
		same[i%m]+=num[i]/2;
	}
	if(m%2){
		int ans=r[0]/2;
		for(int i=1;2*i<=m;i++){
			if(r[i]>=r[m-i]){
				ans+=r[m-i];
				r[i]-=r[m-i];
				ans+=min(r[i]/2,same[i]);
			}
			else{
				ans+=r[i];
				r[m-i]-=r[i];
				ans+=min(r[m-i]/2,same[m-i]);
			}
		}
		cout<<ans;
	}
	else{
		int ans=r[0]/2;
		for(int i=1;2*i<m;i++){
			//cout<<i<<" "<<r[i]<<" "<<r[m-i]<<endl;
			if(r[i]>=r[m-i]){
				ans+=r[m-i];
				r[i]-=r[m-i];
				ans+=min(r[i]/2,same[i]);
			}
			else{
				
				ans+=r[i];
				r[m-i]-=r[i];
				ans+=min(r[m-i]/2,same[m-i]);
			}
			//cout<<ans<<endl;
		}
		ans+=r[m/2]/2;
		cout<<ans;
	}
	
}


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


def solve(H: int, W: int, N: int, a: "List[int]", b: "List[int]"):
    count = [0] * 10
    count[0] = (H-2) * (W-2)
    nutta = {}
    for i in range(N):
        for h in range(max([a[i]-2, 0]), min(a[i]+1,H-2)):
            for w in range(max(b[i]-2, 0), min(b[i]+1, W-2)):
                if (h, w) in nutta:
                    n = nutta[(h, w)]
                else:
                    n = 0
                count[n] -= 1
                count[n+1] += 1
                nutta[(h, w)] = n + 1
    for c in count:
        print(c)
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    H = int(next(tokens))  # type: int
    W = int(next(tokens))  # type: int
    N = int(next(tokens))  # type: int
    a = [int()] * (N)  # type: "List[int]" 
    b = [int()] * (N)  # type: "List[int]" 
    for i in range(N):
        a[i] = int(next(tokens)) - 1
        b[i] = int(next(tokens)) -1 
    solve(H, W, N, a, b)

if __name__ == '__main__':
    main()


Measured memory_bytes: 159612
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
count = 0
for i, atc in enumerate(b):
    if a[i] >= atc:
        a[i] = a[i] - atc
        count+=atc
    else:
        atc = atc - a[i]
        count+=a[i]
        a[i] = 0
        if a[i+1] >= atc:
            a[i+1] = a[i+1] - atc
            count+=atc
        else:
            atc = atc - a[i+1]
            count+=a[i+1]
            a[i+1] = 0
print(count)

Measured memory_bytes: 82020
using System;
using System.Text;
using System.Collections.Generic;
using System.Collections;
using static System.Math;
using System.Linq;
using static System.Array;

namespace ConsoleApp2
{
    class Program
    {

        static void Main(string[] args)
        {
            //var N = long.Parse(Console.ReadLine());
            var S = Console.ReadLine();
            //var T = Console.ReadLine();

            var ans = new List<char>();

            for (int i = 0; i < S.Length; i++)
            {
                if (S[i] == '0')
                {
                    ans.Add('0');
                }else if(S[i] == '1')
                {
                    ans.Add('1');
                }
                else
                {
                    if(ans.Count() > 0) ans.RemoveAt(ans.Count()-1);
                }
            }


            Console.WriteLine(String.Join("",ans));
            

            
            
        }


    }


}


Measured memory_bytes: 26472
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rep2(i,n) for (int i = 1; i < (n); ++i)
using namespace std;
typedef long long ll;
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int A, B, C;
    cin >> A >> B >> C;
    int max_num = max(max(A, B), C);
    cout << max_num * 9 + A + B + C << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define all(x) (x).begin(),(x).end()


ll combination(ll n, ll r){
    if(n < r) return 0;
    if(r == 0||r == n) return 1;
    else if(r == 1) return n;
    return (combination(n - 1, r - 1) + combination(n - 1, r));
}

bool checkKaibun(string str){
    string checkStr = str;
    reverse(checkStr.begin(), checkStr.end());
    if(str == checkStr) return true;
    else return false;
}


int main(){
    ll N;
    cin >> N;
    ll ans = 0;
    for(int i = 1; i <= N; i++){
        if(i < 10) ans++;
        if(i > 99 && i < 1000) ans++;
        if(i > 9999 && i < 100000) ans++;
        if(i > 999999 && i < 1000000) ans++;
    }
    cout << ans << endl;
    
}
    




Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<map>
#include<set>
#include<cassert>
#include<deque>
using namespace std;

#define sz(x) (int)(x.size())
#define fr(i,a,b) for(int i=a;i<b;++i)
#define fdr(i,a,b) for(int i=b-1;i>=a;--i)
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
//////////////////////



void solve(){
	deque<int> q;
	int n;
	cin >> n;
	bool b = true;
	fr(i, 0, n){
		int v;
		cin >> v;
		if(b) q.pb(v);
		else q.push_front(v);
		b ^= 1;
	}
	if(!b) reverse(q.begin(), q.end());
	fr(i, 0, sz(q)) cout << q[i] << " ";
}

int main(){
#ifdef _DEBUG
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
#endif

	solve();

	return 0;
}

Measured memory_bytes: 2944
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define mkt make_tuple
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;

ll N,M;
vector<ll> A;

vector<ll> sum;

bool judge(ll lim){
  ll res=0;
  int itr=0;
  for(int i=N-1;i>=0;i--){
    while(itr<N&&A[i]+A[itr]>=lim){
      itr++;
    }
    res+=itr;
  }

  if(res>=M) return true;
  else return false;
}

int main(){
    cin>>N>>M;
    A.resize(N);
    rep(i,N) cin>>A[i];

    sort(A.rbegin(),A.rend());

    sum.resize(N+1,0);
    rep(i,N) sum[i+1]=sum[i]+A[i];

    ll ok=0,ng=(A[0]*2+1)*M;
    while(abs(ok-ng)>1){
        ll mid=(ok+ng)/2;
        if(judge(mid)) ok=mid;
        else ng=mid;
    }

    ll ans=0;
    ll itr=0;
    ll num=0;
    for(int i=N-1;i>=0;i--){
        while(itr<N && A[i]+A[itr]>=ok) itr++;
        ans+=A[i]*itr+sum[itr];
        num+=itr;
    }
    ans-=ok*(num-M);
    cout<<ans<<endl;

    return 0;
}

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

int main() {
    int N; cin >> N;
    map<string, int> cnt;
    for(int i=0; i<N; ++i) {
        string s; cin >> s;
        cnt[s] += 1;
    }

    int len = -1;
    for(auto p : cnt) len = max(len, p.second);
    vector<string> res;
    for(auto p : cnt) {
        if(p.second == len) res.emplace_back(p.first);
    } 
    sort(begin(res), end(res));
    for(int i=0; i<res.size(); ++i) cout << res[i] << '\n';
}

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

public class Main {
    public static void main(String[] args) {
        MyScanner sc = new MyScanner();

        int a = sc.nextInt();
        int b = sc.nextInt();

        if (a < 10 && b < 10)
            System.out.println(a * b);
        else
            System.out.println(-1);
    }

    static class MyScanner {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in), 1 << 15);
        StringTokenizer tokenizer;

        String next() {
            try {
                while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                    tokenizer = new StringTokenizer(reader.readLine());
                }
            } catch (IOException ignored) {
            }
            return tokenizer.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }
    }
}

Measured memory_bytes: 23124
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb emplace_back
typedef long long ll;
typedef pair<int,int> pint;

int main(){
    string s;
    cin>>s;
    int cnt=0;
    rep(i,s.size())if(s[i]=='1')++cnt;
    cout<<cnt<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;
long double x,n, a, b, m, s;
long double pi = acos(-1);
int main()
{
	cin >> a >> b >> x;
	if (a*a * b >= x * 2) {
		n = x /( a * b)*2.0;
		cout << fixed << setprecision(10) << atan(b / n) / pi * 180;
	}
	else {
		n = ((a * a * b) - x) / (a * a)*2;
		cout << fixed << setprecision(10) << atan(n / a) / pi * 180;
	}
}

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

using namespace std;

#define sqr(x) ((x) * (x))
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()

typedef vector<int> vi;
typedef map<int, int> mi;
typedef pair<int, int> pi;
typedef long long ll;

void solve() {
  int N, K;
  cin >> N >> K;
  double ans = 0;
  for (int i = 1; i < N + 1; i++) {
    int cur = i;
    double p = 1. / N;
    while (cur < K) {
      cur *= 2;
      p *= 0.5;
    }
    ans += p;
  }
  printf("%.12f", ans);
}

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

  solve();

  return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define ll long long
#define mk make_pair
#define pb push_back
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pil pair<int,ll>
#define pli pair<ll,int>
using namespace std;
const int MAXN=2e5+9;
map<int,int> mp;
vector<int> v;
vector<int> g[MAXN];
int tree[4*MAXN];
int ctr=0;
int fans[MAXN],a[MAXN];
int maxx[MAXN];
stack<int> st;
inline void update(int nod,int st,int end,int pos,int val,int check)
{
	if(pos>end||pos<st)
	{
		return;
	}
	else if(pos==st&&st==end)
	{
		// cout<<"hi "<<st<<" "<<val<<endl;
		if(!check)
		{
			tree[nod]=val;
		}
		else
		{
			tree[nod]=max(tree[nod],val);
		}
	}
	else
	{
		int mid=(st+end)>>1;
		update(nod<<1,st,mid,pos,val,check);
		update((nod<<1)+1,mid+1,end,pos,val,check);
		tree[nod]=max(tree[nod<<1],tree[(nod<<1)+1]);
		// cout<<nod<<" "<<tree[nod]<<" nod"<<endl;
	}
}
inline int query(int nod,int st,int end,int l,int r)
{
	if(r<st||l>end)
	{
		return 0;
	}
	else if(l<=st&&end<=r)
	{
		// cout<<tree[nod]<<" tree[nod] "<<st<<" "<<end<<endl;
		return tree[nod];
	}
	else
	{
		int mid=(st+end)>>1;
		return max(query(nod<<1,st,mid,l,r),query((nod<<1)+1,mid+1,end,l,r));
	}
}
inline void dfs(int pos, int prev)
{
	// cout<<pos<<endl;
	int ans=query(1,1,ctr,1,a[pos]-1);
	// cout<<ans<<" ans"<<endl;
	update(1,1,ctr,a[pos],ans+1,1);
	st.push(maxx[a[pos]]);
	st.push(a[pos]);
	maxx[a[pos]]=ans+1;
	fans[pos]=query(1,1,ctr,1,ctr);
	// cout<<a[pos]<<" a[pos]"<<endl;
	// cout<<fans[pos]<<" fans[pos]"<<endl;
	for(int i=0;i<g[pos].size();i++)
	{
		if(g[pos][i]!=prev)
		{
			dfs(g[pos][i],pos);
		}
	}
	//pop
	int id=st.top();
	st.pop();
	int val=st.top();
	st.pop();
	maxx[id]=val;
	update(1,1,ctr,id,val,0);
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int n;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
		v.pb(a[i]);
	}
	for(int i=1;i<n;i++)
	{
		int x,y;
		cin>>x>>y;
		g[x].pb(y);
		g[y].pb(x);
	}
	sort(v.begin(),v.end());
	for(int i=0;i<v.size();i++)
	{
		if(mp.find(v[i])==mp.end())
		{
			mp[v[i]]=(++ctr);
		}
	}
	// cout<<ctr<<" ctr"<<endl;
	for(int i=1;i<=n;i++)
	{
		a[i]=mp[a[i]];
	}
	dfs(1,0);
	for(int i=1;i<=n;i++)
	{
		cout<<fans[i]<<endl;
	}
	return 0;
}

Measured memory_bytes: 43096
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <queue>
typedef long long ll;
using namespace std;
const ll mod = 1000000007;
void Product() {
	int a, b;
	cin >> a >> b;
	cout << ((a *b) % 2 == 0 ? "Even" : "Odd") << endl;
}

int main() {
	Product();
	return 0;
}

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

bool isPalindrome(string this_){
	string also = this_;
	reverse(also.begin(), also.end());
	return also == this_;
}

int main()
{
	string hello;
	cin >> hello;
	int n = hello.size();
	string first = hello.substr(0, n/2);
	string second = hello.substr(n/2+1, n/2);
	if (isPalindrome(first) and isPalindrome(second) and isPalindrome(hello)){
		cout << "Yes" << endl;
	}
	else cout << "No" << endl;
}

Measured memory_bytes: 3616
#include <iostream>
#include <string>    
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long ll;
ll n;
string a, b, c;

int main() {
	cin >> n >> a >> b >> c;
	ll ans = 0;
	for(ll i = 0; i < n; i++){
		if(a[i] == b[i] && b[i] != c[i]){ans++;}
		if(a[i] != b[i] && b[i] == c[i]){ans++;}
		if(a[i] == c[i] && b[i] != c[i]){ans++;}
		if(a[i] != b[i] && b[i] != c[i] && c[i] != a[i]){ans += 2;}
	}
	
	cout << ans << endl;
	return 0;
}

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

int main () {
  int N;
  cin >> N;
  
  map<string, int> vote;
  for (int i = 0; i < N; i++) {
    string temp;
    cin >> temp;
    if (vote.count(temp)) {
      vote[temp]++;
    } else {
      vote.emplace(temp, 1);
    }
  }
  
  //カウント回数の最大値を見つける
  int maxv = 1;
  for (auto x : vote) {
    if (x.second > maxv) maxv = x.second;
  }
  
  for (auto x : vote) {
    if (x.second == maxv) {
      cout << x.first << endl;
    }
  }
}

Measured memory_bytes: 25216
#include <iostream>
#include <vector>

using namespace std;

int main(){

  int n,m;
  cin >> n >> m;

  vector<int> c(m);
  for(int i = 0; i < m; i++)
    cin >> c[i];

  vector<int> dp(n+1);
  dp[0] = 0;
  for(int j = 1; j <= n; j++){
    dp[j] = j; 
    for(int i = 0; i < m; i++)
      if(j >= c[i]) dp[j] = min( dp[j], dp[ j - c[i] ] + 1 ); 
    
  }

  cout << dp[n] << endl;

}



Measured memory_bytes: 3160
from itertools import groupby

n = int(input())
dic = []
for i in range(n):
    (c, r) = input().split(" ")
    dic.append({"index": i+1, "city": c, "rating": int(r)})

std_dic= sorted(dic, key=lambda x:x['city'])
grp_dic = groupby(std_dic, key=lambda x:x["city"])
result = []
for key, group in grp_dic:
    # print(key, list(group))
    for s in sorted(group, key=lambda x:x["rating"], reverse=True):
        result.append(s)

for r in result:
    print(r["index"])



Measured memory_bytes: 3064
import bisect

n = int(input())
l = list(map(int, input().split()))


ans = 0

l.sort()
# print(l)
for x in range(n):
    for y in range(x+1, n):
        t = bisect.bisect_left(l, max(l[x] - l[y], l[y] - l[x])+1, y+1)
        #print(l[x], l[y], max(l[x] - l[y], l[y] - l[x]), t, l[t])
        t2 = bisect.bisect_left(l, l[x] + l[y], y+1)
        #print(t2, l[t2] if t2 < n else None)
        #print(t2 - t)
        t3 = t2 - t
        if t3 > 0:
            ans += t3
print(ans)


Measured memory_bytes: 46940
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
typedef vector<ll> VI;
typedef vector<VI> VVI;
const ll MOD = 1000000007;
const ll INF = 2147483647;
const ll LINF = 9223372036854775807;
#define REP(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()

int main() {
	ll x; cin >> x;
	ll a=100; int i;
	for(i=0;a<x;i++){
		a=a*1.01;
	}
	cout << i << endl;
	return 0;
}

Measured memory_bytes: 3620
N, M = map(int, input().split())
H = list(map(int, input().split()))
li = []
count = 0
for i in H:
    li.append([i])
for i in range(M):
    s1, s2 = map(int, input().split())
    li[s1-1].append(s2)
    li[s2-1].append(s1)
for i in range(len(li)):
    flag = 1
    for j in range(1, len(li[i])):
        if li[i][0] <= H[li[i][j]-1]:
            flag = 0
    if flag == 1:
        count += 1
print(count)

Measured memory_bytes: 95924
#include <bits/stdc++.h>
using namespace std;
#define ll long long 
#define GIO ios_base::sync_with_stdio(0);cin.tie(0);

int main()
{ GIO;
 int n;
 cin>>n;
int A[n];
 for(int i=0;i<n;i++) cin>>A[i];
 sort(A,A+n);
cout<<A[n-1]-A[0]<<endl;

return 0;
}

Measured memory_bytes: 256
N=int(input())
dp=[0]*9
a=list(map(int,input().split()))
for i in range(N):
  if a[i]>=3200:
    a[i]=3200
  dp[a[i]//400]+=1
s=0
for i in range(8):
  if dp[i]==0:
    s+=1
b=sum(dp[8:])
if s==8:
  print(1,b)
else:
  print(8-s,8-s+b)

Measured memory_bytes: 9112
package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scan(&n)

	nb := make([]int,n)
	for i := 0; i < n; i++ {
		var val int
		fmt.Scan(&val)
		nb[i] = val
	}

	diff := 0
	for i := 0; i < n; i++ {
		if nb[i] == i + 1 {
			continue
		}
		diff++
	}
	if diff < 3 {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}

Measured memory_bytes: 512
def gcd(x, y):
 
   while(y):
       x, y = y, x % y
 
   return x

   
n = int(input())

a = list(map(int,input().split()))
lcm = a[0]
for i in a[1:]:
  lcm = (lcm * i) // int(gcd(lcm, i)) 

lcm -= 1
ans = 0
for i in a:
	ans += lcm % i 
print(ans)

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

int main() {

    int a, b, c, k;
    cin >> a >> b >> c >> k;

    vector<int> input = {a, b, c};
    sort(input.begin(), input.end());
    int max_input = input.back();

    while (k > 0) {
        max_input *= 2;
        k--;
    }

    cout << input[0] + input[1] + max_input << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
const string emp = "Vacant";
const string M = "Male";
const string F = "Female";
 
void out(int N, string &S) {
    cout << N << endl;
    fflush(stdout);
    cin >> S;
    return;
}
 
int main() {
    int N;
    cin >> N;
    int L = 0, R = N;
    string Sl, Sr;
    out(0, Sl);
    if (Sl == emp) return 0;
    
    while (abs(L-R) > 1) {
        int mid = (L + R) / 2;
        string Sm;
        out(mid, Sm);
        if (Sm == emp) return 0;
        if ((abs(mid-L) % 2 == 0 && Sl != Sm) || (abs(mid-L) % 2 == 1 && Sl == Sm)) {
            R = mid; Sr = Sm;
        } else {
            L = mid; Sl = Sm;
        }
    }
    
    return 0;
}

Measured memory_bytes: 852
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(),v.end()
#define INF INT_MAX;
typedef long long ll;
using namespace std;

int main(){
  string s;
  cin >> s;
  for(int i=0;i<s.size();i++){
    if(s.at(i)==','){
      printf(" ");
    }else{
      printf("%c",s.at(i));
    }
  }
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
const int maxn=200010;
char s[maxn],t[maxn];
int len;
int main(){
    scanf("%s%s",s,t);
    len=strlen(s);
    int ans=0;
    for (int i=0;i<len;++i){
        if (s[i]!=t[i]) ++ans;
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 4112
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <numeric>
typedef long long Int;
#define rep(i,a,b) for(Int i=a;i<b;++i)
#define rrep(i,a,b) for(Int i=a;i>=b;--i)
using namespace std;

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

    int n, m; cin >> n >> m;
    cout << (n-1)*(m-1) << endl;
}


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

int main() {
  int N, A, B;
  cin >> N;
  
  A = N % 1000;
    
  B = N / 10;
  
  if (A % 111 == 0){
    cout << "Yes" << endl;
  }

  else if (B % 111 == 0){
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define finish(x) return cout << x << endl, 0
#define ll long long

int n, mod = 998244353;
string s;

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> n >> s;
    int ans = 1;
    map <string, int> mp;
    for(auto &i : s){
        string all = "BGR";
        all.erase(find(all.begin(), all.end(), i));
        if(mp[all] > 0){
            ans = 1LL * ans * mp[all] % mod;
            mp[all]--;
            mp["BGR"]++;
            continue;
        }
        bool done = 0;
        for(auto &j : all){
            string s;
            s += j;
            if(mp[s] > 0){
                ans = 1LL * ans * mp[s] % mod;
                mp[s]--;
                s += i;
                sort(s.begin(), s.end());
                mp[s]++;
                done = 1;
            }
            if(done) break;
        }
        if(done) continue;
        string s;
        s += i;
        mp[s]++;
    }
    for(int i = 1 ; i <= n ; i++){
        ans = 1LL * ans * i % mod;
    }
    cout << ans << endl;
}


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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<string, string> pss;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vii;
typedef vector<ll> vl;
typedef vector<vl> vvl;

double EPS=1e-9;
int INF=1000000005;
long long INFF=1000000000000000005ll;
double PI=acos(-1);
int dirx[8]={ -1, 0, 0, 1, -1, -1, 1, 1 };
int diry[8]={ 0, 1, -1, 0, -1, 1, -1, 1 };
const ll MOD = 1000000007;

ll sum() { return 0; }
template<typename T, typename... Args>
T sum(T a, Args... args) { return a + sum(args...); }

#define DEBUG fprintf(stderr, "====TESTING====\n")
#define VALUE(x) cerr << "The value of " << #x << " is " << x << endl
#define OUT(x) cout << x << endl
#define OUTH(x) cout << x << " "
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define READ(x) for(auto &(z):x) cin >> z;
#define FOR(a, b, c) for (int(a)=(b); (a) < (c); ++(a))
#define FORN(a, b, c) for (int(a)=(b); (a) <= (c); ++(a))
#define FORD(a, b, c) for (int(a)=(b); (a) >= (c); --(a))
#define FORSQ(a, b, c) for (int(a)=(b); (a) * (a) <= (c); ++(a))
#define FORC(a, b, c) for (char(a)=(b); (a) <= (c); ++(a))
#define EACH(a, b) for (auto&(a) : (b))
#define REP(i, n) FOR(i, 0, n)
#define REPN(i, n) FORN(i, 1, n)
#define MAX(a, b) a=max(a, b)
#define MIN(a, b) a=min(a, b)
#define SQR(x) ((ll)(x) * (x))
#define RESET(a, b) memset(a, b, sizeof(a))
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ALL(v) v.begin(), v.end()
#define ALLA(arr, sz) arr, arr + sz
#define SIZE(v) (int)v.size()
#define SORT(v) sort(ALL(v))
#define REVERSE(v) reverse(ALL(v))
#define SORTA(arr, sz) sort(ALLA(arr, sz))
#define REVERSEA(arr, sz) reverse(ALLA(arr, sz))
#define PERMUTE next_permutation
#define TC(t) while (t--)
#define FAST_INP  ios_base::sync_with_stdio(false);cin.tie(NULL)
#define what_is(x) cerr << #x << " is " << x << endl;

void solve() {

}

int main()
{
    FAST_INP;
//    #ifndef ONLINE_JUDGE
//    freopen("input.txt","r", stdin);
//    freopen("output.txt","w", stdout);
//    #endif

//    int tc; cin >> tc;
//    TC(tc) solve();
	int l, r;
	cin >> l >> r;
	if((l-1)/2019!=r/2019) {
		OUT(0);
		return 0;
	}
	l%=2019, r%=2019;
	int ans=2018;
	FORN(i,l,r){
		FORN(j,i+1,r){
			ans=min(ans, (i*j)%2019);
		}
	}
	OUT(ans);
    return 0;
}

Measured memory_bytes: 3620
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    int a;
    cin >> a;
    int ans = 0;
    for (int i = 1; i <= a; ++i) {
        for (int j = 1; j <= a; ++j) {
            for (int k = 1; k <= a; ++k) {
                ans += gcd(i, gcd(j, k));
            }
        }
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 3676
inline long long in() {
  long long n = 0;
  char c = getchar_unlocked();
  while ('0' <= c && c <= '9') {
    n *= 10;
    n += (c - '0');
    c = getchar_unlocked();
  }
  return n;
}

inline void out(long long n) {
  long long N = n, rev; int count = 0;
  rev = N;
  if (N == 0) { putchar_unlocked('0'); return; }
  while ((rev % 10) == 0) { count++; rev /= 10;}
  rev = 0;
  while (N != 0) { rev = (rev<<3) + (rev<<1) + N % 10; N /= 10; }
  while (rev != 0) { putchar_unlocked(rev % 10 + '0'); rev /= 10; }
  while (count--) putchar_unlocked('0');
}

int main() {
  long long I = in(), O = in(), T = in(), J = in(), L = in();
  long long n = (I&1?I-1:I) + (J&1?J-1:J) + (L&1?L-1:L);
  if (I && J && L) {
    long m = (I&1?I-1:I-2) + (J&1?J-1:J-2) + (L&1?L-1:L-2) + 3;
    out((n<m?m:n) + O);
  } else {
    out(n + O);
  }
}

Measured memory_bytes: 128
#include <stdio.h>
#define N 120
int main(void)
{
  char o[N]={0},e[N]={0},pwd[N]={0};
  int i,o_i=0,e_i=0,o_flag=0,e_flag=0;
  scanf("%s",o);
  scanf("%s",e);
  for(i=0;;i++)
  {
    if((i+1)%2)
    {
      pwd[i]=o[o_i];
      o_i++;
    }
    else
    {
      pwd[i]=e[e_i];
      e_i++;
    }
    if(o[o_i]==0)
    {
      o_flag=1;
    }
    if(e[e_i]==0)
    {
      e_flag=1;
    }
    if(o_flag==1 && e_flag==1)
    {
      break;
    }
  }
  printf("%s\n",pwd);
  return 0;
}


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

int h, w, mn = INF, mx = 0, a[2000][2000];
bool ok(int t) {
    int prv = 0;
    rep(i, h) {
        int j;
        for (j = w - 1; j >= prv && a[i][j] <= mn + t; j--); j++;
        for (int k = 0; k < j; k++) {
            if (a[i][k] < mx - t)return false;
        }
        prv = j;
    }
    return true;
}
int main() {
    scanf("%d%d", &h, &w);
    rep(i, h)rep(j, w) {
        scanf("%d", &a[i][j]);
        mn = min(mn, a[i][j]); mx = max(mx, a[i][j]);
    }
    int l = 0, r = INF;
    while (l != r) {
        int t = (l + r) / 2;
        rep(k, 4) {
            if (k & 1)rep(i, h)rep(j,w/2)swap(a[i][j], a[i][w - j - 1]);
            else rep(i, w)rep(j,h/2)swap(a[j][i], a[h - j - 1][i]);
            if (ok(t)) {
                r = t; goto g;
            }
        }
        l = t + 1;
    g:;
    }
    printf("%d\n", l);
}

Measured memory_bytes: 18848
#include<stdio.h>

static const int N = 1000;

void trace(int A[], int n){
  int i;
  for ( i = 1; i <= n; i++ ){
    if ( i > 1 ) printf(" ");
    printf("%d", A[i]);
  }
  printf("\n");
}

int main(){
  int n, i, j, key;
  int A[N+1];
  scanf("%d", &n);

  for ( i = 1; i <= n; i++ ) scanf("%d", &A[i]);
  
  trace(A, n);

  for( i = 2; i <= n; i++){
    key = A[i];
    /* insert A[i] into the sorted sequence A[0,...,j-1] */
    j = i - 1;

      while( j >= 0 && A[j] > key){
        A[j+1] = A[j];
        j--;
	A[j+1] = key;
      }
      trace(A,n);
  }

  return 0;
}

Measured memory_bytes: 608
#include <bits/stdc++.h>
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 (int i=0    ;i<(n) ;i++)
#define RREP(i,n)     for (int i=(n)-1;i>=0  ;i--)
#define EACH(i,a,b)   for (int i=(a)  ;i<=(b);i++)
#define REACH(i,a,b)  for (int i=(b)  ;i>=(a);i--)
#define ALL(a)        (a).begin(),  (a).end()
#define RALL(a)       (a).rbegin(), (a).rend()
#define YES()         printf("YES\n")
#define NO()          printf("NO\n")
#define Yes()         printf("Yes\n")
#define No()          printf("No\n")
#define in(a,x,b)     ((a) <= (x) && (x) < (b))

const int MOD = 1e9 + 7;
const int INF = 1 << 29;
const double EPS = 1e-10;

using ll = long long;
using P = pair<int,int>;
template<class T = int> using V = vector<T>;

template<class T> bool inline chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool inline chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T = int> T inline input() { T x; cin >> x; return (x); }
template<class T> void inline print(T& x) { cout << x << '\n'; }
#define debug(x) cerr << #x << ": " << x << endl;

const int dxs[] = { 1, 0, -1, 0, 1, 1, -1, -1 };
const int dys[] = { 0, -1, 0, 1, 1, -1, -1, 1 };

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

  int N,M;
  cin >> N >> M;
  int A[N];
  REP(i,N) cin >> A[i];

  priority_queue<double> pq;
  REP(i,N) pq.push(A[i]);

  REP(i,M) {
    double x = pq.top() / 2;
    pq.pop();
    pq.push(x);
  }

  ll ans = 0;
  REP(i,N) {
    ans += (ll)pq.top();
    pq.pop();
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 4604
import java.util.Scanner;

public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        while (true) {
            String s = sc.next();
            if (s.length() < 2 && Integer.parseInt(s) == 0) {
                break;
            }

            int sum = 0;

            String[] strArr = s.split("");
            for (int i=0; i<strArr.length; ++i) {
                sum += Integer.parseInt(strArr[i]);
            }

            System.out.println(sum);
        }
    }
}


Measured memory_bytes: 27328