akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <functional>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <climits>

#define all(c) (c).begin(), (c).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)
#define fr first
#define sc second

const int INF=100000000;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
using namespace std;
typedef pair<int ,int > P;
typedef long long ll;

int n;

int dfs(int cnt, int a, int sum) {
    // printf("%d %d %d\n", cnt, a, sum);
    if(sum == n) return 1;
    if(cnt == 4) return 0;
    if(a*a > n) return 0;
    if(sum > n) return 0;
    int res=0;

    for(int i=a;i*i<=n;i++) {
        if(sum+i*i > n) break;
        res += dfs(cnt+1,i, sum+i*i);
    }

    return res;
}

void solve() {
    cout<<dfs(0,1,0)<<endl;;

}

int main() {
    while(cin>>n) {
        if(n==0) break;
        solve();
    }
    return 0;
}

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

#define int long long
#define pii pair<int, int>
#define pb push_back
#define vi vector<int>

signed main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    string s;
    cin >> s;
    int ans = 0;
    int r = 0;
    for(int i = 0; i < s.size(); i++) {
        if(s[i] == 'R') {
            r++;
        }
        else {
            r = 0;
        }
        ans = max(ans, r);
    }
    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 3632
require 'prime'

N = $stdin.gets.to_i
fs = N.prime_division
#$stderr.puts fs.to_s
count = 0
fs.each do |pair|
  p, q = *pair
  n = 1
  while (q -= n) >= 0
    n += 1
    count += 1
  end
end
puts count


Measured memory_bytes: 14380
#include <bits/stdc++.h>
#define INF 1e18
#define int long long
#define Rep(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) Rep(i, 0, n)
#define all(a) (a).begin(), (a).end()
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;
const int mod = 1000000007;

int n, m, l;
vector<P> G[310];
P d[310][310];

void bfs(int s)
{
    d[s][s] = P(0, l);
    priority_queue<PP, vector<PP>, greater<PP>> que;
    que.push(PP(0, P(s, l))); //d, pos, l
    while (!que.empty())
    {
        PP pp = que.top();
        que.pop();
        P p = pp.second;
        int now = p.first;
        int L = p.second;
        if (d[s][now].first < pp.first)
            continue;
        else if (d[s][now].first == pp.first && d[s][now].second > L)
            continue;
        rep(i, G[now].size())
        {
            int to = G[now][i].first;
            int cost = G[now][i].second;
            if (L - cost >= 0)
            {
                if (d[s][to].first > d[s][now].first)
                {
                    d[s][to].first = d[s][now].first;
                    d[s][to].second = L - cost;
                    que.push(PP(d[s][to].first, P(to, L - cost)));
                }
                else if (d[s][to].first == d[s][now].first)
                {
                    if ((L - cost) > d[s][to].second)
                    {
                        d[s][to].first = d[s][now].first;
                        d[s][to].second = L - cost;
                        que.push(PP(d[s][to].first, P(to, L - cost)));
                    }
                }
            }
            if (l - cost >= 0)
            {
                if (d[s][to].first > d[s][now].first + 1)
                {
                    d[s][to].first = d[s][now].first + 1;
                    d[s][to].second = l - cost;
                    que.push(PP(d[s][to].first, P(to, l - cost)));
                }
                else if (d[s][to].first == d[s][now].first + 1)
                {
                    if ((l - cost) > d[s][to].second)
                    {
                        d[s][to].first = d[s][now].first + 1;
                        d[s][to].second = l - cost;
                        que.push(PP(d[s][to].first, P(to, l - cost)));
                    }
                }
            }
        }
    }
}

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

    cin >> n >> m >> l;
    rep(i, n) rep(j, n) d[i][j] = P(INF, -1);
    rep(i, m)
    {
        int a, b, c;
        cin >> a >> b >> c;
        a--, b--;
        G[a].push_back(P(b, c));
        G[b].push_back(P(a, c));
    }
    rep(i, n) bfs(i);
    int q;
    cin >> q;
    while (q--)
    {
        int s, t;
        cin >> s >> t;
        s--, t--;
        P res = d[s][t];
        if (res.first == INF)
            res.first = -1;
        cout << res.first << endl;
    }
}

Measured memory_bytes: 4480
#include <iostream>
#include <algorithm>
#include <cmath>

using namespace std;

int main(){
    int n;
    cin >> n;
    long long a[200010], min = 10000000000, max = -10000000000;

    for (int i = 0; i < n; i++){ 
        cin >> a[i]; 

        if (max < a[i] - min) { max = a[i] - min; }

        if (a[i] < min){
            min = a[i];
        }
    }

    cout << max << endl;
}


Measured memory_bytes: 4640
#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 repr(i,n) for(int i=(n)-1;0<=i;--i)
#define each(e,v) for(auto&& e:(v))
#define all(v) begin(v),end(v)
#define dump(x) cerr<<#x<<": "<<(x)<<endl
#define INF 999999999
#define IINF 9999999999999;
using vint = std::vector<int>;
using ll = long long;
using vll = std::vector<ll>;
template <class T> void chmin(T& a, const T& b) { a = std::min(a, b); }
template <class T> void chmax(T& a, const T& b) { a = std::max(a, b); }
#define output(x) cout << x << endl;
typedef pair<int, int> P;

int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int mass[501][501] = {false};

int main() {
    int H, W;
    cin >> H >> W;;
    rep(i, H) {
        rep(j, W) {
            cin >> mass[i][j];
        }
    }
    vector<pair<int, int>> answer;

    rep(i, H) {
        rep(j, W - 1) {
            if(mass[i][j] % 2 == 1) {
                --mass[i][j];
                ++mass[i][j + 1];
                answer.emplace_back(make_pair(i + 1, j + 1));
                answer.emplace_back(make_pair(i + 1, j + 2));
            }
        }
    }

    rep(i, H - 1) {
        if(mass[i][W - 1] % 2 == 1) {
            --mass[i][W - 1];
            ++mass[i + 1][W - 1];
            answer.emplace_back(make_pair(i + 1, W));
            answer.emplace_back(make_pair(i + 2, W));
        }
    }

    cout << answer.size() / 2 << endl;

    for (int i = 0; i < answer.size(); i += 2) {
        cout << answer[i].first << " " << answer[i].second << " " << answer[i + 1].first << " " << answer[i + 1].second << endl;
    }
}

Measured memory_bytes: 5232
#include <stdio.h>

int main(){
        int h, m, s;

        do{
                        scanf("%d", &s);
                }while(!(0 <= s || s <= 86400));

        h = s / (60*60);
        m = (s%(60*60)) / 60;
        s = s % 60;

        printf("%d:%d:%d\n", h, m, s);
        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 m1, d1, m2, d2;
    cin >> m1 >> d1 >> m2 >> d2;
    if (m1 != m2) cout << 1 << endl;
    else cout << 0 << endl;
    return 0;
}

Measured memory_bytes: 3608
#include <algorithm>
#include <deque>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unordered_map>
#include <vector>

int main(){
  int N, M;
  scanf("%d", &N);
  scanf("%d", &M);
  std::vector<int > A(M), B(M);
  std::vector<int > edge[N+4];
  for (int i=0; i<M; i++) {
    scanf("%d", &A[i]);
    scanf("%d", &B[i]);
    A[i]--;
    B[i]--;
    edge[A[i]].push_back(B[i]);
    edge[B[i]].push_back(A[i]);
  }
  std::queue<std::pair<int, int> > queue;
  queue.push(std::make_pair(0, 0));
  std::vector<int > src(N+4, -1);
  src[0]=0;
  while(queue.size()>0){
    int v=queue.front().first;
    int d=queue.front().second;
    queue.pop();
    for (int i=0; i<edge[v].size(); i++){
      if (src[edge[v][i]]!=-1){
        continue;
      }
      queue.push(std::make_pair(edge[v][i], d+1));
      src[edge[v][i]]=v;
    }
  }

  
  for (int i=0; i<N; i++){
    if (src[i]==-1){
      printf("No\n");
      return 0;
    }
  }
  printf("Yes\n");
  for (int i=1; i<N; i++){
    printf("%d\n", src[i]+1);
  }
  return 0;
}


Measured memory_bytes: 11672
import math
from functools import reduce

def gcd(*num):
    return reduce(math.gcd, num)

k = int(input())

sum_count = 0
for i in range(1, k+1):
    a = i
    for j in range(1, k+1):
        b = j
        for l in range(1, k+1):
            c = l
            sum_count = sum_count + gcd(a,b,c)

print(sum_count)

Measured memory_bytes: 74836
#include<stdio.h>

int main(){
  int i, j, n, ball, hole_b, hole_c, check;

  scanf("%d", &n);

  for(i=0; i<n; i++){
    check = 0;
    hole_b = 0;
    hole_c = 0;
    for(j=0; j<10; j++){
      scanf("%d", &ball);

      if(check == 0){
	if(ball > hole_b)
	  hole_b = ball;
	else if(ball > hole_c)
	  hole_c = ball;
	else
	  check = ball;
      }
    }

    if(check == 0)
      printf("YES\n");
    else
      printf("NO\n");
  }

  return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <vector>
#include <iterator>
#include <cmath>

using namespace std;

int main(){
	
	int n, l;
	
	while(true){
		cin >> n >> l;
		if(n == 0){
			break;
		}
		string d[30];
		int p[30] = {};
		for(int i = 0; i < n; i++){
			cin >> d[i] >> p[i];
		}
		int ans = 0;
		int num;
		for(int i = n - 1; i >= 0; i--){
			if(d[i][0] == 'L'){
				ans = p[i];
				int rest = p[i] % 2;
				int count = 0;
				for(int j = i; j >= 0; j--){
					if(p[j] % 2 == rest && d[j][0] == 'L'){
						count++;
					}
				}
				for(int j = 0; j < n; j++){
					if(p[j] % 2 == rest){
						count--;
					}
					if(count == 0){
						num = j + 1;
						break;
					}
				}
				break;
			}
		}
		for(int i = 0; i < n; i++){
			if(d[i][0] == 'R'){
				if(ans >= l - p[i]){
					break;
				}
				ans = l - p[i];
				int rest = p[i] % 2;
				int count = 0;
				for(int j = i; j < n; j++){
					if(p[j] % 2 == rest && d[j][0] == 'R'){
						count++;
					}
				}
				for(int j = n - 1; j >= 0; j--){
					if(p[j] % 2 == rest){
						count--;
					}
					if(count == 0){
						num = j + 1;
						break;
					}
				}
				break;
			}
		}
		cout << ans << " " << num << endl;
	}
	
	return 0;
}

Measured memory_bytes: 3168
#include <bits/stdc++.h>
using namespace std;
#define all(x) x.begin(),x.end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
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 ll = long long;

ll n,m,k,a,sum;
string s,t;

int main() {
  cin >> n >> m;
  rep(i,m) cin >> a, sum+=a;
  cout << (n-sum>=0 ? n-sum : -1) << endl;
}

Measured memory_bytes: 3616
import math
total = 0
N,M = list(map(int,input().split()))
M = M-1
n_l = "".join(input().split())
A = n_l.find("1")
before = A
after = N-A-1
while before > 0:
    before-=M
    total +=1
if before < 0:
    before = abs(before)
    after -= before
while after > 0:
    after-=M
    total +=1
print(total)

Measured memory_bytes: 10420
A = [[int(i) for i in input().split()] for _ in range(3)]
N = int(input())
b = [int(input()) for _ in range(N)]

def check() :
  # TATE
  for x in range(3) :
    if all(A[y][x] in b for y in range(3)) :
      return True
      
  # YOKO
  for y in range(3) :
    if all(A[y][x] in b for x in range(3)) :
      return True
      
  # NANAME
  if all(A[i][i] in b for i in range(3)) : return True
  if all(A[2-i][i] in b for i in range(3)) : return True
    
  return False
  
if check() :
  print('Yes')
else :
  print('No')

Measured memory_bytes: 38384
N = int(input())
a = [(int(input()), 1) for _ in range(N)]
b = [(int(input()), 0) for _ in range(N)]
X = sorted(a + b)

mod = 10 ** 9 + 7
ls = 0
stack = []
ans = 1
for v, f in X:
    if stack and stack[-1] != f:
        ans = ans * ls % mod
        stack.pop()
        ls -= 1
    else:
        stack.append(f)
        ls += 1

print(ans)

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

#define fi first
#define se second
#define be begin
#define en end
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define ALL(a) (a).be() , (a).en()
#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)        //repeat n times
#define REP2(i,s,n) for(int (i)=(s);(i)<(n);(i)++)   //repeat from s to n 
#define REPD(i,n) for(int (i)=(n);(i)>=0;(i)--)      //repeat from n to 0
#define REPD2(i,s,e) for(int (i)=(s);(i)>=(e);(i)--) //repeat from s to e
#define RANGE(i,v) for(auto &(i):v)                  //repeat range
#define ASIZE(a) (sizeof(a) / sizeof(a[0]))          //array size

using LL = long long;

template<typename T> using V = vector< T >;
using Vi = V<int>;
using Vll = V<LL>;
using Vs = V<string>;

template<typename T>
T vec_min(V<T> v){return *min_element(ALL(v));}

template<typename T>
T vec_max(V<T> v){return *max_element(ALL(v));}

int main(){
    string S,T;
    cin>>S>>T;
    
    V<char> kanji_S(26,-1);
    V<char> kanji_T(26,-1);
    REP(i,S.size()){
        // if(S[i] == T[i]) continue;
        int s = S[i] - 'a';
        int t = T[i] - 'a';
        if(kanji_S[s]>=0){
            if(kanji_S[s] != T[i]){
                cout<<"No"<<endl;
                return 0;
            }
        }else{
            kanji_S[s] = T[i];
        }

        if(kanji_T[t]>=0){
            if(kanji_T[t] != S[i]){
                cout<<"No"<<endl;
                return 0;
            }
        }else{
            kanji_T[t] = S[i];
        }

    }

    cout<<"Yes"<<endl;
    return 0;
}

Measured memory_bytes: 776
#include<bits/stdc++.h>
using namespace std;
int main(void)
{
	int a,b;
	int n;
	int s,f;
	int flg;
	int i;
	
	cin>>a>>b>>n;
	
	flg=0; //重複しない
	for(i=0;i<n;i++){
		cin>>s>>f;
		if(flg==1) continue;
		if((a>=s&&b<=f)||(a<=s&&b>=f)||(a>s&&a<f)||(b>s&&b<f)){
			flg=1; //重複する
			//cout<<"i="<<i<<endl;
		}
		//sとfの間にaかbがあれば重複する
	}
	
	if(flg==0) cout<<"0"<<endl;
	else cout<<"1"<<endl;
	
	return 0;
}


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

#define FOR0(i,n) for (int i = 0; i < n; i++)
#define FOR(i,j, n) for (int i = j; i < n; i++)
// bool isEven(ll n) {return (n%2!=0)?false:true;};
#define INF 1000000000 // 1 billion, safer than 2B for Floyd Warshall’s

#define f(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) f(i,0,n)
#define fd(i,a,b) for(i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define vi vector< int >
#define vl vector< ll >
#define ss second
#define ff first
#define ll long long
#define pii pair< int,int >
#define pll pair< ll,ll >
#define sz(a) a.size()
#define inf (1000*1000*1000+5)
#define all(a) a.begin(),a.end()
#define tri pair<int,pii>
#define vii vector<pii>
#define vll vector<pll>
#define viii vector<tri>
#define mod (1000*1000*1000+7)
#define pqueue priority_queue< int >
#define pdqueue priority_queue< int,vi ,greater< int > >
// #define int ll

using namespace std;

//atcoder
//abc166

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

    if(s=="ABC")
        cout<<"ARC"<<endl;
    else
        cout<<"ABC"<<endl;
}

Measured memory_bytes: 3628
#include <iostream>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <stdlib.h>
#include <functional>
#include <sstream>
#include <bitset>
#include <map>

using namespace std;

typedef long long ll;

int main() {
  int N,K;
  cin>>N>>K;
  map<int, vector<int> > mp;
  for (int i = 0; i < N; i++) {
    int t,d;
    cin>>t>>d;
    mp[t].push_back(d);
  }
  vector<int> maxes,others;
  for (auto& p : mp) {
    auto nums = p.second;
    sort(nums.rbegin(),nums.rend());
    maxes.push_back(nums[0]);
    for (int i = 1; i < nums.size(); i++) others.push_back(nums[i]);
  }
  sort(maxes.rbegin(),maxes.rend());
  sort(others.rbegin(),others.rend());
  vector<ll> maxesum(N+1,0),othersum(N+1,0);
  for (int i = 0; i < maxes.size(); i++) maxesum[i+1] = maxesum[i] + maxes[i];
  for (int i = 0; i < others.size(); i++) othersum[i+1] = othersum[i] + others[i];
  int kmax = min(K, (int) mp.size());
  ll ans = 0;
  for (ll k = 1; k <= kmax; k++) {
    ll tmp;
    tmp = maxesum[k] + othersum[K-k] + k * k;
    ans = max(ans,tmp);
  }
  cout<<ans<<endl;
  return 0;
}

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

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define Task ""

using namespace std;
typedef long long ll;

const int mod = 1e9 + 7;

int n, x, y, z;
int ans = 1;

signed main(void)
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    if (fopen("A.INP", "r")){
        freopen("A.INP", "r", stdin);
        freopen("A.OUT", "w", stdout);
    }
    if (fopen(Task".INP", "r")){
        freopen(Task".INP", "r", stdin);
        freopen(Task".OUT", "w", stdout);
    }
    cin >> n;
    bool can = 1;
    while (n--){
        int a;
        cin >> a;
        int cnt = 0;
        if (a == x) ++cnt;
        if (a == y) ++cnt;
        if (a == z) ++cnt;
        if (cnt == 0){
            return cout << 0, 0;
        }
        ans = 1ll * ans * cnt % mod;
        if (a == x) ++x;
        else if (a == y) ++y;
        else ++z;
    }
    cout << ans << '\n';
}


Measured memory_bytes: 256
//by Himanshu Shukla
#pragma GCC optimize("O2")
#include <bits/stdc++.h>
using namespace std;
#define FASTIO ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define ll long long
#define v32 vector<int>
#define v64 vector<ll>
#define s32 set<int>
#define s64 set<ll>
#define graph vector<s32>
#define p32 pair<int,int>
#define p64 pair<ll,ll>
#define fi first
#define se second
#define ln '\n'
#define debug(x) cout << (#x) << ": " << (x) << ln
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
inline ll add(ll a, ll b, ll m) { return (((a % m + b % m) % m + m) % m); }
inline ll mul(ll a, ll b, ll m) { return (((a % m * b % m) % m + m) % m); }
const double EPS = 1e-6;
const ll MOD = 1e9 + 7;
template <typename T, typename U>
ostream& operator<<(ostream& out, const pair<T,U>& p){
	out << '[' << p.fi << ", " << p.se << ']';
	return out;
}
template <template <typename, typename...> class ContainerType, typename ValueType, typename ...Args>
void print_container(const ContainerType<ValueType, Args...>& c){
	cout << "{ ";
	for(const auto& v : c)
		cout << v << ' ';
	cout << '}' << ln;
}

const int MAX = 2e5 + 5;
ll inv[MAX],fact[MAX],ifact[MAX];

void pre()
{
	fact[0] = fact[1] = ifact[0] = ifact[1] = inv[1] = 1;
	for(int i = 2;i < MAX;i++)
	{
		inv[i] = mul(MOD - (MOD / i),inv[MOD % i],MOD);
		fact[i] = mul(i,fact[i - 1],MOD);
		ifact[i] = mul(ifact[i - 1],inv[i],MOD);
	}
}

ll nCr(ll a,ll b)
{
	if(a < b) return 0;
	ll ans = 1;
	for(ll i = 0;i < b;i++)
		ans = mul(ans,(a - i),MOD);
	ans = mul(ans,ifact[b],MOD);
	return ans;
}

int main()
{
	FASTIO;
	ll n,m,k;
	cin >> n >> m >> k;
	pre();
	ll temp = nCr(n * m - 2,k - 2);
	ll mm = mul(m,m,MOD),nn = mul(n,n,MOD);
	ll ans1 = mul(mm,add(mul(nn,n,MOD),MOD - n,MOD),MOD);
	ans1 = mul(ans1,inv[6],MOD);
	ll ans2 = mul(nn,add(mul(mm,m,MOD),MOD - m,MOD),MOD);
	ans2 = mul(ans2,inv[6],MOD);
	cout << mul(temp,add(ans1,ans2,MOD),MOD) << ln;
	return 0;
}


Measured memory_bytes: 4992
#include "bits/stdc++.h"
using namespace std;
int main() {
	int N;
	cin >> N;
	vector<long long>A(N);
	for (int i = 0; i < N; i++) {
		cin >> A.at(i);
	}
	int M;
	cin >> M;
	vector<int>P(M);
	vector<long long>X(M);
	for (int i = 0; i < M; i++) {
		cin >> P.at(i) >> X.at(i);
		vector<long long>tmp = A;
		tmp.at(P.at(i) - 1) = X.at(i);
		int ans = 0;
		for (int j = 0; j < N; j++) {
			ans += tmp.at(j);
		}
		cout << ans << endl;
	}
}

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

int main()
{

	double a, b, C;
	cin >> a >> b >> C;

	double S, L, h;
	double rad = C * M_PI / 180;

	S = a * b * sin(rad) / 2;
	L = sqrt(a*a + b*b - 2 * a*b*cos(rad)) + a + b;
	h = 2 * S / a;

	printf("%.4f\n", S);
    printf("%.4f\n", L);
    printf("%.4f\n", h);



    return 0;
}

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

int solve() {
    int n;
    string N0;
    cin >> n >> N0;
    vector<int> N(n-1);
    for ( int i = 0; i < n-1; i++ ) {
        N[i] = abs((int)N0[i+1] - (int)N0[i]);
    }
    vector<int> ct(3);
    for ( int i = 0; i < n-1; i++ ) {
        ct[N[i]]++;
    }
    if ( ct[1] > 0 ) {
        for ( int i = 0; i < n-1; i++ ) {
            if ( N[i] == 2 ) N[i] = 0;
        }
    } else {
        for ( int i = 0; i < n-1; i++ ) {
            if ( N[i] == 2 ) N[i] = 1;
        }
    }
    int b = 0;
    for ( int i = 0; i < n-1; i++ ) {
        int odd = ((n-2) ^ i ^ (n-2-i)) == 0 ? 1 : 0;
        b ^= N[i] * odd;
    }
    int ans = b;
    if ( b != 0 && ct[1] == 0 ) {
        ans = 2;
    }
    return ans;
}

int main() {
    auto ans = solve();
    cout << ans << "\n";
    return 0;
}

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

ll MOD = 1e9+7;
ll dp[1005][1005];
char grid[1005][1005];

int main()
{
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    int H, W;
    scanf("%d %d",&H, &W);
    for(int i = 1; i <= H; i++)
    {
        for(int j = 1; j <= W; j++)
        {
            char ch;
            cin>>ch;
            if(i==1 && j==1)
                dp[1][1] = 1;
            else if(ch=='.')
                dp[i][j] = (dp[i-1][j] + dp[i][j-1]) % MOD;
            else if(ch=='#')
                dp[i][j] = 0;
        }
    }

    printf("%lld\n", dp[H][W]);

    return 0;
}


Measured memory_bytes: 8064
A, B = map(int, input().split())

cand = [i for i in range(1, 1001)]
res = []
flg = False
for i in cand:
  if int(i * 0.08) == A and int(i * 0.10) == B:
    res.append(i)
    flg = True

if flg:
  print(res[0])
else:
  print(-1)

Measured memory_bytes: 9216
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)n;i++)
//E-Crested Ibils vs Monster
const int inf=1e+9;
int main(){
    int h,n;cin>>h>>n;
    vector<pair<int,int>> P(n);
    rep(i,n) cin>>P[i].first>>P[i].second;
    int maxa=0;
    rep(i,n){
        maxa=max(P[i].first,maxa);
    }
    vector<int> dp(h+maxa+1,inf);
    dp[0]=0;
    rep(i,n){
        int a=P[i].first,b=P[i].second;
        rep(j,h){
            if(dp[j]!=inf&&j+a<=h+maxa) dp[j+a]=min(dp[j+a],b+dp[j]);
        }
    }
    int res=inf;
    for(int i=h;i<=maxa+h;i++){
        res=min(res,dp[i]);
    }
    cout<<res<<endl;
}

Measured memory_bytes: 256
// https://atcoder.jp/contests/caddi2018/tasks/caddi2018_b

fun main() {
    caddi2018b()
}

fun caddi2018b() {
    val n = readLine()!!.toInt()
    for (i in 0 until n) {
        val a = readLine()!!.toLong() % 2 == 1L
        if (a) {
            println("first")
            return
        }
    }
    println("second")
}

Measured memory_bytes: 57188
fn main() {
    let mut sc = Scanner::new();
    let mut s: Vec<usize> = sc.read::<String>().chars().map(|c| (c as usize) - ('a' as usize)).collect();

    if s.len() < 26 {
        let mut used = vec![false; 26];
        for c in &s {
            used[*c] = true;
        }

        for c in &s {
            print!("{}", ((*c as u8) + ('a' as u8)) as char);
        }
        for i in 0..26 {
            if used[i] { continue; }
            println!("{}", ((i as u8) + ('a' as u8)) as char);
            return;
        }
    }

    let mut used = vec![true; 26];
    for i in (0..26).rev() {
        let c = s[i];
        let mut back = 26;
        for j in c..26 {
            if !used[j] {
                back = j;
                break;
            }
        }
        if back == 26 {
            used[c] = false;
        } else {
            for j in 0..i {
                print!("{}", ((s[j] as u8) + ('a' as u8)) as char);
            }
            println!("{}", ((back as u8) + ('a' as u8)) as char);
            return;
        }
    }

    println!("-1");
}

struct Scanner {
    ptr: usize,
    length: usize,
    buf: Vec<u8>,
    small_cache: Vec<u8>,
}

impl Scanner {
    fn new() -> Scanner {
        Scanner { ptr: 0, length: 0, buf: vec![0; 1024], small_cache: vec![0; 1024] }
    }

    fn load(&mut self) {
        use std::io::Read;
        let mut s = std::io::stdin();
        self.length = s.read(&mut self.buf).unwrap();
    }

    fn byte(&mut self) -> u8 {
        if self.ptr >= self.length {
            self.ptr = 0;
            self.load();
            if self.length == 0 {
                self.buf[0] = b'\n';
                self.length = 1;
            }
        }

        self.ptr += 1;
        return self.buf[self.ptr - 1];
    }

    fn is_space(b: u8) -> bool { b == b'\n' || b == b'\r' || b == b'\t' || b == b' ' }

    fn read<T>(&mut self) -> T where T: std::str::FromStr, T::Err: std::fmt::Debug, {
        let mut b = self.byte();
        while Scanner::is_space(b) {
            b = self.byte();
        }

        for pos in 0..self.small_cache.len() {
            self.small_cache[pos] = b;
            b = self.byte();
            if Scanner::is_space(b) {
                return String::from_utf8_lossy(&self.small_cache[0..(pos + 1)]).parse().unwrap();
            }
        }

        let mut v = self.small_cache.clone();
        while !Scanner::is_space(b) {
            v.push(b);
            b = self.byte();
        }
        return String::from_utf8_lossy(&v).parse().unwrap();
    }
}



Measured memory_bytes: 4352
#include<bits/stdc++.h>
#define rep(i,a,n) for(int i=a;i<=n;++i)
#define per(i,a,n) for(int i=n;i>=a;--i)
#define hr putchar(10)
#define pb push_back
#define lc (o<<1)
#define rc (lc|1)
#define mid ((l+r)>>1)
#define ls lc,l,mid
#define rs rc,mid+1,r
#define fi first
#define se second
#define io std::ios::sync_with_stdio(false)
#define endl '\n'
#define DB(a) ({REP(__i,1,n) cout<<a[__i]<<',';hr;})
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int P = 1e9+7, INF = 0x3f3f3f3f;
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll qpow(ll a,ll n) {ll r=1%P;for (a%=P;n;a=a*a%P,n>>=1)if(n&1)r=r*a%P;return r;}
ll inv(ll x){return x<=1?1:inv(P%x)*(P-P/x)%P;}
inline int rd() {int x=0;char p=getchar();while(p<'0'||p>'9')p=getchar();while(p>='0'&&p<='9')x=x*10+p-'0',p=getchar();return x;}
//head
const int N = 1e6+10;
char s[N];
int main() {

    scanf("%s",s+1);
    int len=strlen(s+1);
    if(s[1]=='0'||s[len]=='1') return puts("-1"),0;
    rep(i,1,len-1) if(s[i]!=s[len-i]) return puts("-1"),0;
    int rt=1;
    rep(i,2,len)
    {
        cout<<rt<<' '<<i<<endl;
        if(s[i-1]=='1')
            rt=i;
    }

}


Measured memory_bytes: 3900
N = input()

n = len(N)
if n == 1:
    print(int(N))
elif n == 2:
    print(9)
elif n == 3:
    print(9 + int(N) - 99)
elif n == 4:
    print(9 + 900)
elif n == 5:
    print(9 + 900 + int(N) - 9999)
else:
    print(9 + 900 + 90000)

Measured memory_bytes: 38256
N = gets.to_i
AS = gets.split.map(&:to_i)

MIN = 8

counts = Array.new(9, 0)
AS.each do |a|
  case a
  when 1..399
    counts[0] += 1
  when 400..799
    counts[1] += 1
  when 800..1199
    counts[2] += 1
  when 1200..1599
    counts[3] += 1
  when 1600..1999
    counts[4] += 1
  when 2000..2399
    counts[5] += 1
  when 2400..2799
    counts[6] += 1
  when 2800..3199
    counts[7] += 1
  when 3200..4800
    counts[8] += 1
  end
end

special_color = counts.delete_at(8)
zero_count = counts.count { |c| c == 0 }
if zero_count == MIN
  min_count = 1
  max_count = special_color
else
  min_count = counts.count { |c| c != 0 }
  max_count = min_count + special_color
end
puts("#{min_count} #{max_count}")

Measured memory_bytes: 1788
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define YES cout<<"YES"<<endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define ANS cout << ans << endl
#define all(a) a.begin(),a.end()
#define SORT(a) sort(all(a))
#define REVERSE(a) reverse(all(a))
#define int long long
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define VIin(a) for(int i=0; i<a.size(); i++) cin >> a[i]
#define OUT(a) cout << a << endl
typedef vector<int> VI;
typedef vector<VI> VVI;
const int MOD=1e9+7;
const long long INF = 1LL << 60;
/*最大公約数*/int gcd(int x, int y) { return y ? gcd(y,x%y) : x;}
/*最小公倍数*/int lcm(int a, int b) { int g = gcd(a, b); return a / g * b; }
/*素数判定*/int isPrime(int n){if(n<2){return 0;}for(int i=2; i*i<=n; i++){if(n%i==0){return 0;}}return 1;}
/*約数列挙*/vector<int> getDivisor(int n){vector<int> v; for(int i=1; i*i<=n; i++){if(n%i==0){v.push_back(i);if(i!=n/i){v.push_back(n/i);}}}sort(v.begin(),v.end()); return v;}
//----------------------------------------------
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int n,k; cin >> n >> k;
    VI x(n); VIin(x);
    int ans = INF;
    rep(i,n-k+1){
        ans = min(ans,abs(x[i]) + abs(x[i+k-1] - x[i]));
        ans = min(ans,abs(abs(x[n-i-1]) + abs(x[n-i-1] - x[n-i-k])));
    }
    ANS;

    return 0;
}



Measured memory_bytes: 1024
import Control.Applicative

import Data.List
    (sort)
    
solve :: [Int] -> [Int]

solve xs
    = sort xs

input :: Read a => IO [a]

input
    = map read.words <$> getLine

output :: Show a => [a] -> String

output xs
    = init $ concat [show x ++ " " | x <- xs]

loop :: IO ()
    
loop
    = do
        xs <- input
        case xs of
            [0, 0]
                -> return ()
            
            _
                -> do
                    putStrLn $ output $ solve xs
                    loop
                
main :: IO ()
    
main
    = loop

Measured memory_bytes: 4148
#include <stdio.h>

void Z_algorithm(char S[], int Z[])
{
	int i, j, k, l;
	for (l = 0; S[l] != 0; l++);
	Z[0] = l;
	for (i = 1, j = 0; i < l; i++) {
		for (; i + j < l && S[i+j] == S[j]; j++);
		Z[i] = j;
		if (j == 0) continue;
		
		for (k = 1; k < j && k + Z[k] < j; k++) Z[i+k] = Z[k];
		i += k - 1;
		j -= k;
	}
}

int main()
{
	int N;
	char S[5001];
	scanf("%d", &N);
	scanf("%s", S);
	
	int i, j, Z[5001], ans = 0, tmp;
	for (i = 0; S[i] != 0; i++) {
		Z_algorithm(&(S[i]), Z);
		for (j = 1; S[i+j] != 0; j++) {
			tmp = (Z[j] < j)? Z[j]: j;
			if (ans < tmp) ans = tmp;
		}
	}
	printf("%d\n", ans);
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 1732
/*suri_kumkaran*/

#include <bits/stdc++.h>

using namespace std;

#define UB upper_bound
#define LB lower_bound
#define BS binary_search
#define MP make_pair
#define EB emplace_back
#define endl "\n"
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
#define F first
#define S second
#define ALL(a) (a).begin(),(a).end()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)

typedef long long int int64;
typedef vector<int64> VI64;
typedef vector<pair<int64,int64>> VII64;
typedef vector<string> VS;
typedef vector<vector<int64>> VVI;

int main()
{
    IOS;
    int64 T=1;
    //cin>>T;
    while(T--)
    {
        int64 n,i,j,with;
        cin>>n;
        int64 fix[n+1][n+1];
        for(i=1;i<=n;i++)
            for(j=1;j<n;j++)
                cin>>fix[i][j];
        int64 days[n+1]={0};
        int64 ans=1;
        int64 ttl=0;
        for(i=1;i<=(n*(n-1))/2;i++)
        {
            int done[n+1]={0};
            bool b=true;
            for(j=1;j<=n;j++)
            {
                if(days[j]>=n-1||done[j]==1)
                    continue;
                with=fix[j][days[j]+1];
                if(days[with]>=n-1||done[with]==1)
                    continue;
                if(fix[with][days[with]+1]==j)
                {
                    done[j]=done[with]=1;
                    days[with]++;
                    days[j]++;
                    ttl++;
                    b=false;
                }
                    
            }

            if(ttl>=((n-1)*n)/2||b)
                break;
        }
        if(ttl>=((n-1)*n)/2)
        cout<<i;
        else
            cout<<-1;
    }

    return 0;
}

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

using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()

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

    cout << n * n * n << '\n';
    return 0;
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;

static const double EPS = 1e-8;
static const double PI = 4.0 * atan(1.0);
static const ll INF = 1023456789;

#define REP(i,n)	for(int i=0;i<n;++i)
#define REPR(i,n)	for(int i=n-1;i>=0;--i)
#define FOR(i,s,n)	for(int i=s;i<n;++i)
#define FORR(i,s,n)	for(int i=n-1;i>=s;--i)
#define ALL(c)		(c).begin(),(c).end()
#define CLEAR(v)	memset(v,0,sizeof(v))
#define MP(a,b)		make_pair((a),(b))
#define ABS(a)		((a)>0?(a):-(a))
#define F			first
#define S			second

int n;
ll a[100000];

int main(int argc, char **argv) {
	cin >> n;
	REP(i, n) cin >> a[i];
	sort(a, a + n);
	ll res = 1, p = 0;
	REPR(i, n - 1) if (a[i] == a[i + 1]) {
		res *= a[i];
		--i; ++p;
		if (p == 2) break;
	}
	cout << (p == 2 ? res : 0) << endl;
	return 0;
}


Measured memory_bytes: 1024
using System;
using System.Collections.Generic;
class Solve{
    public int n;
    int[] x;
    public Solve(){}
    public static int Main(){
        new Solve().Calc();
        return 0;
    }
    void Calc(){
        getinput();
        int count = 0;
        for(int i=0;i<n;i++){
            if(x[i]>i && x[x[i]] == i){
                count++;
            }
        }
        Console.WriteLine(count);
    }
    void getinput(){
        n = int.Parse(Console.ReadLine());
        string[] str = Console.ReadLine().Split(' ');
        x = new int[n];
        for(int i=0;i<n;i++){
            x[i] = int.Parse(str[i])-1;
        }
    }    
}

Measured memory_bytes: 9688
// Template from https://techracho.bpsinc.jp/jhonda/2019_08_05/78537

// input macro for competive-programming from https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        input_inner!{$s, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

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

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

#[allow(unused_macros)]
macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

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

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

    ($iter:expr, bytes) => {
        read_value!($iter, String).into_bytes()
    };

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

fn main() {
    use std::io::Read;
    let mut s = String::new();
    std::io::stdin().read_to_string(&mut s).unwrap();

    println!("{}", solve(&s));
}

macro_rules! test {
    ($($exp_input:expr => $output:expr),* $(,)*) => {
        #[test]
        fn solve_test() {
            $(
                let start = std::time::Instant::now();
                let input = solve($exp_input);
                let end = start.elapsed();
                assert_eq!(input, $output, "{}.{:03}", end.as_secs(), end.subsec_millis());
                assert!(end.as_secs() <= 2, "expected_sec: {}sec, actual_sec: {}sec", 2, end.as_secs());
                assert!(end.as_secs() <= 1, "expected_sec: {}sec, actual_sec: {}sec", 1, end.as_secs());
                assert!(end.subsec_millis() <= 10, "expected_ms: {}ms, actual_ms: {}ms", 10, end.subsec_millis());
                assert!(end.subsec_millis() <= 2, "expected_ms: {}ms, actual_ms: {}ms", 2, end.subsec_millis());
            )*
        }
    };
}

test! {
r#"5 7 5"# => r#"Yes"#,

r#"4 4 4"# => r#"No"#,

r#"4 9 6"# => r#"No"#,

r#"3 3 4"# => r#"Yes"#,
}

fn solve(src: &str) -> String {
    let mut src_iter = src.split_whitespace();
    input! {
        source = src_iter,
        mut n: [usize; 3],
    }

    n.sort();
    n.dedup();

    if n.len() == 2 {
        "Yes"
    } else {
        "No"
    }.to_string()
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> lpair;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define print2(x,y) cout << (x) << " " << (y) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " ";} cout<<endl;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S;
    cin >> S;
    rep(i,0,3){
        if(S[i] == S[i+1]){
            print("Bad");
            return 0;
        }
    }
    print("Good");
    
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <iomanip>
#include <bitset>
#include <set>
#include <map>
#include <stdio.h>
#include <numeric>
#include <cstring>

#define rep(i,n) for (int i = 0; i < (n); i++)
#define rep1(i,n) for (int i = 1; i < (n); i++)
#define FOR(i,a,b) for (int i=(a); i < (b); i++)
#define MOD 1000000007 //10^9+7
#define ALL(a)  (a).begin(),(a).end()
using namespace std;
using ll = long long;
using PII = pair<int, int>;
using PLL = pair<long long, long long>;
const int INF = numeric_limits<int>::max();
const ll INFL = numeric_limits<ll>::max();
constexpr ll TEN(int n) { return (n==0) ? 1 : 10*TEN(n-1); }
const double PI = acos(-1);

// 負の数にも対応した % 演算
long long mod(long long val, long long m) {
    long long res = val % m;
    if (res < 0) res += m;
    return res;
}

//greatest common divisor
long long gcd(ll a, ll b) 
{
    if (a % b == 0) {
        return b;
    } else {
        return gcd(b, a % b);
    }
}

//least common multiple
long long lcm(ll a, ll b)
{
    return a / gcd(a, b) * b ;
}

ll factorial(ll n) {
    ll res = 1;
    for (ll i = 1; i <= n; i++) {
        res *= i;
    }
    return res;
}

bool fn_is_prime(ll n) {
    for (ll i = 2; i * i <= n; i++) {
        if (n % i == 0) return false;
    }
    return n != 1;
}

bool isOK(int index, int key, vector<ll>& a) {
    if (a[index] >= key) return true;
    else return false;
}

int binary_search(int key, vector<ll>& a) {
    int ng = -1;
    int ok = a.size();

    while (abs(ok - ng) > 1) {
        int mid = (ok + ng) / 2;

        if (isOK(mid, key, a)) ok = mid;
        else ng = mid;
    }
    return ok;
}

struct UnionFind {
    vector<int> r;

    UnionFind(int N) {
        r = vector<int>(N, -1);
    }

    int root(int x) {
        if (r[x] < 0) return x;
        return r[x] = root(r[x]);
    }

    bool unite(int x, int y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        if (r[x] > r[y]) swap(x, y);
        r[x] += r[y];
        r[y] = x;
        return true;
    }

    int size(int x) {
        return -r[root(x)];
    }

    bool same(int x, int y) {
        return root(x) == root(y);
    }
};

//素因数分解
vector<pair<long long, long long> > prime_factorize(long long N) {
    vector<pair<long long, long long> > res;
    for (long long a = 2; a * a <= N; ++a) {
        if (N % a != 0) continue;
        long long ex = 0;
        while (N % a == 0) {
            ++ex;
            N /= a;
        }
        res.push_back({a, ex});
    }
    if (N != 1) res.push_back({N, 1});
    return res;
}
//const auto &pf = prime_factorize(i);
//for (auto p : pf) cout << p.first << " " << p.second;

long long pow(long long x, long long n) {
    long long ret = 1;
    while (n > 0) {
        if (n & 1) ret = ret * x % MOD;  // n の最下位bitが 1 ならば x^(2^i) をかける
        x = x * x % MOD;
        n >>= 1;  // n を1bit 左にずらす
    }
    return ret;
}

int main()
{
    int n;cin >> n;
    int ans = 0;
    rep(i,n)
        ans += i+1;
    cout << ans << endl;

    return 0;
}


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

using namespace std;

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

  int x1, y1, x2, y2;
  cin >> x1 >> y1 >> x2 >> y2;
  int x3 = x2 + (y1 - y2);
  int y3 = y2 + (x2 - x1);
  int x4 = x1 + (y1 - y2);
  int y4 = y1 + (x2 - x1);
  cout << x3 << " " << y3 << " " << x4 << " " << y4 << "\n";
}


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

int main(){
    string ch[3];
    cin >> ch[0]>> ch[1]>> ch[2];
    cout << ch[0][0]<< ch[1][1]<< ch[2][2];
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <sstream>

using ll = long long;

using namespace std;

int main() {
    long k;
    cin >> k;
    vector<long> comb(500);
    comb[0] = 1;
    for (int i=1; i<500; i++) comb[i] = comb[i-1] * (i+7) / i;
    reverse(comb.begin(), comb.end());
    string ans = "";
    for (auto c:comb) {
        ans += string(k / c, 'F') + "ESTIVAL";
        k %= c;
    }
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 256
n=int(input())

redlist=[list(map(int,input().split())) for _ in range(n)]
bluelist=[list(map(int,input().split())) for _ in range(n)]

redlist.sort(key = lambda x : x[1], reverse = True)
bluelist.sort(key = lambda x : x[0])


output=0

for blue in bluelist:
	for red in redlist:
		if blue[1] > red[1] and blue[0] > red[0]:
			output+=1
			redlist.remove(red)
			break

print(output)


Measured memory_bytes: 3064
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <cstdlib>

using namespace std;

int f_primeNumber2(int x)
{
    int i; 
 
    for ( i = 2; i <= sqrt(x); ++i){
        if (x % i == 0 && x != i) return 1;
    }
    
    return 0;
}

int main(){
    int n;
    int x[10000];
    int i;
    int c=0;
    
    cin >> n;
    for ( i = 0;i < n; ++i ){
        cin >> x[i];    
    }

    for ( i = 0;i < n; ++i ){
        if (f_primeNumber2(x[i]) == 1){
            c = c +1;
        }
    }
    cout << n-c << endl;
    
    return 0;
}

Measured memory_bytes: 3112
def main():
    N = int(input())
    A = [int(a) for a in input().split()]
    ave = sum(A) // N
    min_cost = float('inf')
    for v in [ave, ave+1]:
        cost = 0
        for a in A:
            cost += pow(a-v, 2)
        min_cost = min(min_cost, cost)

    return min_cost

if __name__ == '__main__':

    print(main())


Measured memory_bytes: 3060
#include <iostream>
#include <iomanip>
#include <string>
#include <stack>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <iterator>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <regex>
using namespace std;
using pii  = pair<int,int>;
using ll=long long;
using ld=long double;
#define pb push_back
#define mp make_pair
#define sc second
#define fr first
#define stpr setprecision
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define rep(i,n) for(ll i=0;i<(n);++i)
#define Rep(i,a,b) for(ll i=(a);i<(b);++i)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define rRep(i,a,b) for(int i=a;i>=b;i--)
#define crep(i) for(char i='a';i<='z';++i)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define ALL(x) (x).begin(),(x).end()
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define endl '\n'
int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}
ll gcd(ll a,ll b){return (b == 0 ? a : gcd(b, a%b));}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
constexpr ll MOD=1000000007;
constexpr ll INF=1000000011;
constexpr ll MOD2=998244353;
constexpr ll LINF = 1001002003004005006ll;
constexpr ld EPS=10e-8;
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; }
template<typename T> istream& operator>>(istream& is,vector<T>& v){for(auto&& x:v)is >> x;return is;}
template<typename T,typename U> istream& operator>>(istream& is, pair<T,U>& p){ is >> p.first; is >> p.second; return is;}
template<typename T,typename U> ostream& operator>>(ostream& os, const pair<T,U>& p){ os << p.first << ' ' << p.second; return os;}
template<class T> ostream& operator<<(ostream& os, vector<T>& v){
  for(auto i=begin(v); i != end(v); ++i){
    if(i !=begin(v)) os << ' ';
    os << *i;
  }
  return os;
}

ll C[100007];

int main(){
  ll N;
  cin >> N ;
  ll A[100007];
  rep(i,N){
    cin >> A[i];
  }



  sort(A,A+N);
  ll T=0;
  Rep(i,N/2,N){
    if((i-N/2)%2==0){
      C[i]=A[T];
    }
    else{
      C[i]=A[N-T-1];
    }
    T++;
  }
  T=0;
  rRep(i,(N-2)/2,0){
    if(((N-2)/2-i)%2==0){
      C[i]=A[N-T-1];
    }
    else{
      C[i]=A[T];
    }
    T++;
  }
  ll sum=0;
  rep(i,N-1){
    sum+=abs(C[i]-C[i+1]);
  }



  reverse(A,A+N);
  T=0;
  Rep(i,N/2,N){
    if((i-N/2)%2==0){
      C[i]=A[T];
    }
    else{
      C[i]=A[N-T-1];
    }
    T++;
  }
  T=0;
  rRep(i,(N-2)/2,0){
    if(((N-2)/2-i)%2==0){
      C[i]=A[N-T-1];
    }
    else{
      C[i]=A[T];
    }
    T++;
  }
  ll sum1=0;
  rep(i,N-1){
    sum1+=abs(C[i]-C[i+1]);
  }
  cout << max(sum1,sum) << endl;
}


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

using namespace std;

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

#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<(b);i++)
#define repr(i,b,a) for(int i=int(b);i>=(a);i--)
#define all(x) x.begin(),x.end()

const ll mod = 1e9+7;
const ll INF = 1e9;

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
bool valid(int lx,int ux,int ly,int uy,int x,int y){
	return lx<=x&&x<ux&&ly<=y&&y<uy; 
}
ll power(ll x,ll p){
	if(p==0)return 1;
	ll res=power(x*x%mod,p/2);
	if(p%2==1)res=res*x%mod;
	return res;
}



//反転数を求める
int inverse_number(vector<int> z){
	int cnt = 0;

	int n = z.size();
	rep(i,n){
		repr(j,n-1,i+1){
			if(z[j] < z[j-1]){
				cnt++;
				int tmp = z[j];
				z[j] = z[j-1];
				z[j-1] = tmp;
			}
		}
	}

	return cnt;
}

int main()
{
	int n;
	cin>>n;
	vector<vector<int>> card(n,vector<int>(2));
	rep(j,2){
		rep(i,n)cin>>card[i][j];
	}

	int ans = INF;
	for (int bit = 0; bit < (1<<n); bit++){
		int count_even = 0;
		vector<P> target_even, target_odd;
		for (int i = 0; i < n; i++){
			if(bit&(1<<i)){
				count_even++;
				if(i%2==0)target_even.push_back(P(card[i][0],i));
				else target_even.push_back(P(card[i][1],i));
			}else{
				if(i%2!=0)target_odd.push_back(P(card[i][0],i));
				else target_odd.push_back(P(card[i][1],i));								
			}
		}

		if(count_even!=(n+1)/2)continue;
		sort(all(target_even));
		sort(all(target_odd));
		vector<int> target(n);
		int cur = 0;
		int pos_even=0, pos_odd=0;
		for (int i = 0; i < n; i++){
			if(i%2==0){
				target[i] = target_even[pos_even].second;
				if(cur > target_even[pos_even].first){
					cur = INF;
					break;
				}
				cur = target_even[pos_even].first;
				pos_even++;
			}else{
				target[i] = target_odd[pos_odd].second;
				if(cur > target_odd[pos_odd].first){
					cur = INF;
					break;
				}
				cur = target_odd[pos_odd].first;
				pos_odd++;
			}
		}
		if(cur==INF)continue;
		ans = min(ans,inverse_number(target));
	}

	if(ans==INF)cout<<-1<<endl;
	else cout<<ans<<endl;


	return 0;
}

Measured memory_bytes: 256
N = int(input())
S = input()

ans = 0

R = []
G = []
B = [0 for _ in range(N+1)]
B_cnt = 0

for i in range(1, N+1):
    if S[i-1] == "R":
        R.append(i)

    if S[i-1] == "G":
        G.append(i)

    if S[i-1] == "B":
        B[i] = 1
        B_cnt += 1

for rr in R:
    for g in G:
        l = min(rr, g)
        r = max(rr, g)
        d = r - l
        ans += B_cnt
        if d + r <= N and B[d+r] == 1:
            ans -= 1
        if d % 2 == 0 and B[l + d//2] == 1:
            ans -= 1
        if B[l - d] == 1 and 1 <= l - d:
            ans -= 1


print(ans)


Measured memory_bytes: 9248