akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
                using namespace std;
                typedef long long ll;
                #define INPUT()              freopen("input.txt", "r", stdin)
                #define OUTPUT()             freopen("output.txt", "w", stdout)
                #define F                    first
                #define S                    second
            //Templatefunctions
                template<typename T>T gcd(T x, T y) { if (y == 0)return x; else return gcd(y, x%y);}
                template <class T> T euclideanDistance(T x1 , T x2 , T y1 , T y2){return sqrt(( x1 - x2 ) * ( x1 - x2 ) + ( y1 - y2 ) * ( y1 - y2 ));}
                template <class T> T digitSum(T n){T sum = 0;while(n > 0)sum += n % 10,n /= 10;return sum;}
            //datatypes
                typedef long long int ll;
                typedef unsigned long long int ull;
                typedef long double ld;
            //constants
                const double INF = 1e+9;
                const double INFLL = 1e+18;
                const double EPS = 1e-9;
                const double PI = acos(-1);
                const int knightDir[8][2] = {{-2,-1},{-2,1},{-1,2},{1,2},{2,-1},{2,1},{-1,-2},{1,-2}};
                       //const int dx[]={0,0,0,1,1,1,-1,-1,-1};
                       //const int dy[]={-1,0,1,-1,0,1,-1,0,1};
                const int dx[] = {0 , 1 , 0 , -1};
                const int dy[] = {1 , 0 , -1 , 0};
            //helpers
                //#define MOD         1000000007LL
                #define MAX         1000005
                const ll MOD = 998244353;
                int arr[MAX];
            //Global Variables

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

                        int len = s.length();
                        stack<char> ans;
                        for(int i = 0 ; i < len ; i++)
                        {
                            if(s[i] == '0')
                            {
                                ans.push('0');
                            }else if(s[i] == '1')
                            {
                                ans.push('1');
                            }
                            else if(s[i] == 'B')
                            {
                                if(!ans.empty())
                                {
                                    ans.pop();
                                }
                            }
                        }
                        string a = "";
                        while(!ans.empty())
                        {
                            a += ans.top();
                            ans.pop();
                        }
                        reverse(a.begin(),a.end());
                        cout<<a<<endl;
                }


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;
const int MOD = 1000000007;

int main() {
  int n,m;
  cin >> n >> m;
  queue<int> a;
  rep(i,m) {
    int q;
    cin >> q;
    a.push(q);
  }
  vector<int> dp(n+1);
  dp[0] = 1;
  dp[1] = 1;
  if(1 == a.front()) {
    dp[1] = 0;
    a.pop();
  }
  rep(i,n-1) {
    dp[i+2] = (dp[i+1] + dp[i]) % MOD;
    if(i+2 == a.front()) {
      dp[i+2] = 0;
      a.pop();
    }
  }
  cout << dp[n]%MOD << endl;
  return 0;
}

Measured memory_bytes: 1024
import sys


# \n
def input():
    return sys.stdin.readline().rstrip()


def main():

    N,K=map(int,input().split())
    A=list(map(int,input().split()))

    current = sum(A[:K])
    ans =(current+K)/2

    for i in range(1,N-K+1):
        current = current - A[i-1] + A[i+K-1]
        ans = max(ans, (current+K)/2 )
    print(ans)



if __name__ == "__main__":
    main()


Measured memory_bytes: 98868
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<string>

using namespace std;

int main(){
    int n,i=0,ans=0;
    cin >> n;
    vector<int>v(n);
    vector<int>c(n);

    while(i<n){
        cin >> v[i];
        i++;
    }
    i = 0;
    while(i<n){
        cin >> c[i];
        i++;
    }

    for(int i=0;i<n;i++){
        if((v[i]-c[i]) >=0)ans+=(v[i]-c[i]);
    }
    cout << ans << endl;

    return 0;
}

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

using namespace std;
#define PI              3.1415926536

#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod 100000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define REP(i,n) for(i=0;i<n;i++)
#define FIO             ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());
#define ll long long

void c_p_c()
{
#ifndef  ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}

void solve()
{


}

int32_t main()
{
//	c_p_c();
	FIO;

	int n, w;
	cin >> n >> w;

	int weighs[n + 1];

	int values[n + 1];

	int i;

	int dp[n + 1][w + 1];
	for (i = 1; i <= n; i++)
		cin >> weighs[i] >> values[i];


	// for (i = 1; i <= n; i++)
	// 	cout << weighs[i] << " ";
	// cout << endl;
	// for (i = 1; i <= n; i++)
	// 	cout << values[i] << " ";


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

		for (int sum = 0; sum <= w; sum++)
		{

			if (sum == 0 || i == 0)
			{
				dp[i][sum] = 0;
			}
			else
			{
				int i2 = (i == 1) ? 0 : dp[i - 1][sum];

				int i1 = sum < weighs[i] ? 0 : values[i] + dp[i - 1][sum - weighs[i]];


				dp[i][sum] = max(i1, i2);
			}
		}
	}
	// for (i = 1; i <= n; i++)
	// {
	// 	for (int j = 1; j <= w; j++)
	// 	{
	// 		cout << dp[i][j] << " ";
	// 	}
	// 	cout << endl;
	// }
	cout << dp[n][w];


}

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

int H,W,D;
char A[2000][2000];
int main(){
	cin >> H >> W >> D;
	for(int i=0;i<2000;i++){
		for(int j=0;j<2000;j++){
			if((i/D)%2==0 && (j/D)%2==0) A[i][j] = 'R';
			if((i/D)%2==0 && (j/D)%2==1) A[i][j] = 'Y';
			if((i/D)%2==1 && (j/D)%2==0) A[i][j] = 'G';
			if((i/D)%2==1 && (j/D)%2==1) A[i][j] = 'B';
		}
	}
	int count = 0;
	while(count<H){
		int i = 510-count,j = count,c = 0;
		while(c<W){
			cout << A[i][j] << (c!=W-1? "":"\n");
			i++;j++;
			c++;
		}
		count++;
	}
}

Measured memory_bytes: 4352
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <array>
#include <queue>
#include <map>
#include <set>
#include <sstream>
#include <stdio.h>
#include <cstdio>
#include <cstring>
#include <math.h>
#include <list>
#include <numeric>

using namespace std;

#define Rep(i,a,b) for(int i = a; i < b; i++)
#define rep(i,b) Rep(i,0,b)
#define rrep(i,a) for(int i = a; i >= 0; i--)
#define allof(a) (a).begin(), (a).end()

typedef long long ll;
const int inf = 1e9 + 7;
const ll infll = 1ll << 60ll;
const ll mod = 1e9 + 7;
// 0~3までは右左下上 4~7までは斜め
constexpr int dx[] = { 1, 0, -1, 0, 1, 1, -1, -1 };
constexpr int dy[] = { 0, -1, 0, 1, 1, -1, -1, 1 };

/*
// 最大公約数
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}

// 最小公倍数
ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}*/

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

	int a, p;
	cin >> a >> p;
	a *= 3;
	a += p;

	cout << a / 2 << endl;

	return 0;
}


Measured memory_bytes: 892
#include<bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; i++)
#define repo(i, n) for(int i=1; i<=n; i++)
#define INF 1001001001
#define INFll 100100100100100
// debug用
#define PrintVec(x) for (auto elementPrintVec: x) { cout << elementPrintVec << " "; } cout << endl;

using namespace std;
using ull = unsigned long long;
using ll = long long;
using P = pair<int, int>;
const int mod = 1000000007;

int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n){
    cin >> a[i];
  }
  vector<int> ans(n);
  int a0=0;
  repo(i, n-1){
    a0^=a[i];
  }
  ans[0]=a0;
  repo(i, n-1){
    int ai=a[i];
    ai^=ans[i-1];
    ans[i]=a[i-1]^ai;
  }
  rep(i, n){
    cout << ans[i] << " ";
  }
  return 0;
}


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


int main(){
    long long int a,b,k;
    cin >> a >> b >>k;
    if(a<k){
        k=k-a;
        a=0;
        if(b<=k){
            cout << 0 << " "<< 0 << endl;
        }else{
            cout << 0 << " " << b-k <<endl;
        }
    }else{
        cout << a-k << " " << b <<endl;
    }


}

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

using namespace std;

int main() {
	long long n, k;
	cin >> n >> k;
	long long half_k = k / 2;
	long long remainder = n % k;
	if (remainder > half_k) remainder = k - remainder;
	cout << remainder << endl;
	return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
typedef long long ll;
#define _GLIBCXX_DEBUG
typedef vector<int> vec;
typedef vector<ll> lvec;
typedef vector<char> cvec;
typedef vector<double> dvec;
typedef pair<ll, ll> LP;
typedef tuple<ll, ll, ll> LT;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
#define fs first
#define sc second

int main()	{
  ll a,b,n;
  cin>>a>>b>>n;
  ll c;
  if(n>b-1) c=b-1;
  else c=n;
  ll ans=a*(c%b)/b;
  cout<<ans<<endl;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
#define ll long long int
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define vi vector<int>
#define vvi vector<vector<int> >
#define mii map<int,int>
#define pb push_back
#define pii pair<int,int>
#define mkp make_pair
#define scan(a,n) for(int i =0 ; i<n ; i++) cin>>a[i]
#define print(a,n) for(int i = 0 ; i < n ; i++) cout<<a[i]<<' '
#define mem(a,v) memset(a,v,sizeof(a))
#define loop(i,a,n) for (int i = a; i < n; i++)
#define FastIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define PRECISION std::cout.unsetf ( std::ios::floatfield );std::cout.precision(15)
double PI=acos(-1.0);
using namespace std;
int mod = 1000000007;
int inf=INT_MAX;
int minf = INT_MIN;

/*int main()
{
    int x;
    cin>>x;
    if(x>=30)
        cout<<"Yes";
    else
        cout<<"No";
}*/

/*int main()
{
    ll n,d;
    cin>>n>>d;
    int cnt=0;
    while(n--)
    {
        ll x,y;
        cin>>x>>y;
        ll temp=x*x+y*y;
        ll ans=ceil(sqrt(temp));
        //cout<<ans<<endl;
        if(ans<=d)
            cnt++;
    }
    cout<<cnt;
}*/

/*int main()
{
    int k;
    cin>>k;
    if(k%2==0 || k%5==0)
    {
        cout<<"-1";
        return 0;
    }
    int first=7,cnt=1;
    while(k>first)
    {
        first=first*10+7;
        cnt++;
    }
    while(first>0)
    {
        first=first%k;
        if(first>0)
        {
            first=first*10+7;
            cnt++;
        }
    }
    cout<<cnt;
}*/

/*int main()
{
    int n;
    cin>>n;
    string s;
    cin>>s;
    int white=0,red=0,posw=-1,posr=n;
    for(int i=0;i<n;i++)
    {
        if(s[i]=='W')
        {
            white++;
            if(posw==-1)
                posw=i;
        }
        else
        {
            red++;
            posr=i;
        }
    }
    if(white==0 || red==0 || posw>posr)
    {
        cout<<"0";
        return 0;
    }
    queue<int> q;
    int cnt=0;
    for(int i=0;i<n;i++)
    {
        if(s[i]=='R')
        {
            if(i>=red && q.size())
            {
                s[q.front()]='R';
                s[i]='W';
                q.pop();
                cnt++;
            }
        }
        else
            q.push(i);
    }
    cout<<cnt;
}*/
ll n,k;
vector<ll> a;
bool check(ll mid)
{
    ll steps=0;
    for(ll x : a)
        steps+=(x-1)/mid;
    return steps<=k;
}

int main()
{
    cin>>n>>k;
    a.resize(n);
    loop(i,0,n)
    {
        cin>>a[i];
    }
    ll lo=1,hi=1e9,ans;
    while(lo<=hi)
    {
        ll mid=(lo+hi)/2;
        if(check(mid))
        {
            hi=mid-1;
            ans=mid;
        }
        else
            lo=mid+1;
    }
    cout<<ans;
}


Measured memory_bytes: 4780
#include<iostream>
#include<cstring>
#include<string>
#include<cstdio>
#include<algorithm>
#define g getline
using namespace std;
int main()
{
	string a,b;
	g(cin,a);
	g(cin,b);
	sort(a.begin(),a.end());
	sort(b.begin(),b.end(),greater<char>());
	if(a<b)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define rrep(i,a,b) for(int i=(a);i>=(b);--i)
#define PB push_back
#define MP make_pair
#define PII pair<int, int>
typedef long long LL;
const LL P = 998244353;
const int INF = 0x3fffffff;
const int N = 200010;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

char s[N];
int dp[N][2], n;

int main(){
	cin>>(s+1);
	n = strlen(s+1);
	dp[0][0] = dp[0][1] = 0;
	rep(i,1,n){
		if(i>1) dp[i][1] = max(dp[i-2][0], dp[i-2][1]) + 1;
		if(i>=3) dp[i][0] = dp[i-1][1] + 1;
		if(i==1 || i>1 && s[i]!=s[i-1])
			dp[i][0] = max(dp[i][0], dp[i-1][0] + 1);
		//cout<<i<<" "<<dp[i][0]<<" "<<dp[i][1]<<endl;
	}
	cout<<max(dp[n][0], dp[n][1])<<endl;
	return 0;
}

Measured memory_bytes: 2048
#include <iostream>
#include <cctype>
#include <queue>
#include <string.h>
using namespace std;
const int DIRECTSIZE = 4;
struct _direct {
    int drow;
    int dcol;
} direct[DIRECTSIZE] = {{0, -1}, {0, 1}, {-1, 0}, {1, 0}};

const int N = 1000;
const int N2 = 10;
char grid[N][N], visited[N][N];
int h, w, n;
struct _factory {
    int row, col;
} factory[N2];

struct _node {
    int row, col, level;
};

int bfs(int n, char goal)
{
    memset(visited, 0, sizeof(visited));

    _node start={factory[n-1].row, factory[n-1].col, 0}, temp;

    visited[start.row][start.col] = 1;

    queue<_node> q;
    q.push(start);

    while(!q.empty()) {
        _node front = q.front();
        q.pop();

        for(int i=0; i<DIRECTSIZE; i++) {
            int nextrow = front.row + direct[i].drow;
            int nextcol = front.col + direct[i].dcol;
            if( 0 <= nextrow && nextrow < h && 0 <= nextcol && nextcol < w) {
                if(grid[nextrow][nextcol] == goal) {
                    return front.level + 1;
                } else if(visited[nextrow][nextcol] == 0 && grid[nextrow][nextcol] != 'X') {
                    visited[nextrow][nextcol] = 1;
                    temp.row = nextrow;
                    temp.col = nextcol;
                    temp.level = front.level + 1;
                    q.push(temp);
                }
            }
        }
    }

    return 0;
}

int main()
{
    while(cin >> h >> w >> n) {
        for(int i=0; i<h; i++)
            for(int j=0; j<w; j++) {
                cin >> grid[i][j];

                if(grid[i][j] == 'S') {
                    factory[0].row = i;
                    factory[0].col = j;
                } else if(isdigit(grid[i][j])) {
                    factory[grid[i][j] - '0'].row = i;
                    factory[grid[i][j] - '0'].col = j;
                }
            }

        int minstep = 0;
        char goal = '1';
        for(int i=1; i<=n; i++) {
            minstep += bfs(i, goal);
            goal++;
        }

        cout << minstep << endl;
    }

    return 0;
}


Measured memory_bytes: 5060
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<queue>
#include<set>
#include<string>
#include<vector>
#include<ctime>
#include<stack>
using namespace std;
typedef long long ll;
#define mm(a,b) memset(a,b,sizeof(a))
const int maxn = 1e6 + 50;
int n, vis[10];
int dp[10][2];
int d[10], num;
int main()
{
	int k;
	int x;
	scanf("%d%d", &n, &k);
	for (int i = 0; i < k; ++i)
	{
		scanf("%d", &x);
		vis[x] = 1;
	}
	x = n;
	num = 1;
	while (x)
	{
		d[num++] = x % 10;
		x /= 10;
	}
	int a, b;
	k = 1;
	mm(dp, -1);
	dp[0][0] = dp[0][1] = 0;
	for (int i = 1; i < num; ++i)
	{
		a = 10;
		for (int j = 0; j < 10; ++j)
		{
			if (!vis[j])
			{
				a = min(a, j);
				b = j;
				if (j > d[i]) break;
			}
		}
		if (dp[i - 1][1] != -1 && b>=d[i])
		{
			if (!vis[d[i]]) dp[i][1] = dp[i - 1][1] + d[i] * k;
			else dp[i][1] = dp[i - 1][0] + b * k;
		}
		if (a <= d[i] && dp[i - 1][0] != -1) dp[i][0] = dp[i - 1][0] + a * k;
		k *= 10;
	}
	if (dp[num - 1][1] != -1)
		cout << dp[num - 1][1];
	else
	{
		for (int j = 1; j < 10; ++j)
		{
			if (!vis[j])
			{
				a = j;
				break;
			}
		}
		cout << dp[num - 1][0] + a * k;
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <functional>

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
    #define eprintf(...) 42
#endif

#define rep_(i, a_, b_, a, b, ...) for (int i = (a), i##_len = (b); i < i##_len; ++i)
#define rep(i, ...) rep_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define reprev_(i, a_, b_, a, b, ...) for (int i = (b-1), i##_min = (a); i >= i##_min; --i)
#define reprev(i, ...) reprev_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define all(x) (x).begin(), (x).end()
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 <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair <int,int> P;
typedef long double ld;

int main (void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, k; cin >> n >> k;
    vector<P> su(n); for (auto &e : su) cin >> e.first >> e.second;
    sort(all(su), [](P a, P b){return (a.second!=b.second ? a.second>b.second : a.first>b.first);});
    ll base = 0, bonus = 0;
    stack<int> doubling;
    map<int, bool> used;
    rep (i, k) {
        base += (ll)su[i].second;
        if (used[su[i].first]) {
            doubling.push(i);
        } else {
            used[su[i].first] = true;
            bonus++;
        }
    }
    ll ans = base + bonus * bonus;
    eprintf("%lld %lld %lld\n", ans, base, bonus);
    rep (i, k, n) {
        if (doubling.empty()) break;
        if (used[su[i].first]) continue;
        int t = doubling.top(); doubling.pop();
        base += (ll)su[i].second - su[t].second;
        bonus++;
        used[su[i].first] = true;
        eprintf("%lld %lld %lld\n", base + bonus * bonus, base, bonus);
        chmax(ans, base + bonus * bonus);
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 4096
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define ROF(i,a,b) for(int i=(a);i>=(b);i--)
#define MEM(x,v) memset(x,v,sizeof(x))
template<typename T>
inline void read(T &x){
	x=0;
	char ch=getchar();bool f=false;
	while(ch<'0' || ch>'9') f|=ch=='-',ch=getchar();
	while(ch>='0' && ch<='9') x=x*10+ch-'0',ch=getchar();
	if(f) x=-x;
}
int a,b,c; 
int main(){
	read(a);read(b);read(c);
	puts(a+b+c>=22?"bust":"win");
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
using ll = long long;
int main() {
  int d;
  cin >> d;
  int c[26];
  for(int i = 0; i < 26; i++) {
    cin >> c[i];
  }
  vector<vector<int>> s(d, vector<int>(26));
  for(int i = 0; i < d; i++) {
    for(int j = 0; j < 26; j++) {
      cin >> s[i][j];
    }
  }
  vector<int> last(26, 0);
  int score = 0;
  for(int i = 0; i < d; i++) {
    int idx = 0;
    int maxi = 0;
    for(int j = 0; j < 26; j++) {
      int tmp = c[j] * ((i + 1) - last[j]);
      if(tmp > maxi){
        maxi = tmp;
        idx = j;
      }
    }
    last[idx] = i + 1;
    score += s[i][idx];
    cout << idx + 1 << endl;
  }
  return 0;
}

Measured memory_bytes: 3684
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
using namespace std;

int main(){
    long long N;
    cin >> N;

    long long ans=N+100;
    long long need;
    for(long long i=1;i<=sqrt(N);i++){
        if(N%i==0){
            long long j = N/i;
            need = (i-1)+(j-1);
            ans = min(ans,need);
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
from collections import defaultdict

N = int(input())
D = list(map(int, input().split()))

depth = defaultdict(int)
for d in D:
    depth[d] += 1

# つながらない
if D[0] != 0 or depth[0] != 1:
    print(0)
    exit()

mod = 998244353
ans = 1
for d in range(1, max(D) + 1):
    ans *= pow(depth[d - 1], depth[d], mod)
    ans %= mod
print(ans)

Measured memory_bytes: 62004
#include<stdio.h>
#include<string.h>
int main(){
	int a[10000],b[1000],n,m,i,j,t;
	char s1[1010],s2[1010];
	while(scanf("%d",&n)!=EOF){
		int sum=0;
		for(i=0;i<n;i++){
			scanf("%d",&a[i]);
			sum=sum+a[i]-1;
		}
		printf("%d\n",sum);
	}
	return 0;	
}

Measured memory_bytes: 128
#define _USE_MATH_DEFINES

//#include <bits/stdc++.h>
#include <cmath>
#include <iostream>
#include <vector>
    
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;

int main(){
    long double a,b,h,m;
    cin>>a>>b>>h>>m;

    long double xa = a * cos(M_PI/180.0 * (60.0*h+m)/720.0 * 360.0);
    long double ya = a * sin(M_PI/180.0 * (60.0*h+m)/720.0 * 360.0);

    long double xb = b * cos(M_PI/180.0 * m/60.0 * 360.0);
    long double yb = b * sin(M_PI/180.0 * m/60.0 * 360.0);
    //printf("%Lf,%Lf,%Lf,%Lf\n", xa,xb,ya,yb);

    //cout<<sqrt((xb-xa)*(xb-xa)+(yb-ya)*(yb-ya))<<endl;
    printf("%.20Lf\n", sqrt((xb-xa)*(xb-xa)+(yb-ya)*(yb-ya)));
    return 0;

} // end of main
    
//実行は、Opt + Ctl + N


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

using ll = long long;
using ull = unsigned long long;

const double PI = acos(-1);
const int inf = 2e9;
const long long INF = 2e18;
const long long MOD = 1e9+7;

#define sx(s) (s).size()
#define pb push_back
#define fi first
#define se second
#define REP(i,n) for (int i = 0; i < n; i++)
#define ALL(a) begin(a),end(a)

int main(void) {
    ll N;
    cin >> N;
    ll ok = 1e9+10;
    ll ng = -1;
    while(abs(ok-ng) > 1) {
        ll mid = (ok+ng)/2;
        if (mid*(mid+1)/2 >= N) {
            ok = mid;
        }
        else {
            ng = mid;
        }
    }
    cout << ok << endl;
    return 0;
}

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

using namespace std;
struct I{
    I(){
        ios::sync_with_stdio(false);cin.tie(0);
        //cout<<fixed<<setprecision(10);
    }
}init;

typedef long long LL;
const LL MOD=1e9+7;

#define SPACE " "
template<typename T>
ostream& operator<<(ostream &os,vector<T> v){
    for(int i =0,sz=v.size();i<sz;i++)os<<(!i)+SPACE<<v[i];
    return os;
}
template<typename T>
istream& operator>>(istream &is,vector<T>& v){
    for(int i =0,sz=v.size();i<sz;i++)is>>v[i];
    return is;
}


int main(){
    int N;LL x;
    cin>>N>>x;
    vector<LL> a(N);
    cin>>a;
    LL res=1e18;
    LL sum=0;
    for(int i=0;i<2*N;i++){
        LL ans=sum;
        for(int j=0;j<N;j++)
            ans+=a[j];
        res=min(ans,res);
        auto b=a;
        for(int j=0;j<N;j++)
            b[(j+1)%N]=min(b[(j+1)%N],a[j]);
        swap(a,b);
        sum+=x;
    }
    cout<<res<<endl;
    return 0;
}


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

int main()
{
    std::unordered_map<std::string, int> map;
    int n;
    std::cin >> n;

    for (int i = 0; i < n; i++) {
        std::string temp;
        std::cin >> temp;

        map[temp]++;
    }

    int m;
    std::cin >> m;

    for (int i = 0; i < m; i++) {
        std::string temp;
        std::cin >> temp;

        map[temp]--;
    }

    int max = 0;
    for (auto i = map.begin(); i != map.end(); i++) {
        max = std::max(max, i->second);
    }

    std::cout << max << std::endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#define LL long long
#define num (LL)1000000000000000000
using namespace std;
LL a[100010];

int main(){
	int n,i;
	LL ans=1;
	scanf("%d",&n);
	for(i=1;i<=n;i++)scanf("%lld",&a[i]);
	sort(a+1,a+1+n);
	if(a[1]==0){printf("0\n");return 0;}
	for(i=1;i<=n;i++)
		if(a[i]>num/ans){printf("-1\n");return 0;}
		//if(a[i]>num/ans){printf("i=%d a[i]=%lld num=%lld ans=%lld %lld\n",i,a[i],num,ans,num/ans),printf("-1\n");return 0;}
		else ans*=a[i];
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 2516
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <string>
#include <iostream>

int main()
{
	std::string s, t;
	int a, b;
	std::string u;
	std::cin >> s >> t;
	std::cin >> a >> b;
	std::cin >> u;
	if (s == u)
	{
		printf("%d %d\n", a - 1, b);
	}
	else
	{
		printf("%d %d\n", a, b - 1);
	}
	return 0;
}

Measured memory_bytes: 256
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;

class Main{
    public static void main(String[] args) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        
        String line;
        
        while((line = br.readLine()) != null){
            StringBuilder sb = new StringBuilder();
            int index = 0;
            while(index < line.length()){
                char c = line.charAt(index);
                if(c == '@'){
                    int times = (int)(line.charAt(++index) - '0');
                    char repeat = line.charAt(++index);
                    for(int i = 0; i < times; i++){
                        sb.append(repeat);
                    }
                }else{
                    sb.append(c);
                }
                index++;
            }
            System.out.println(sb);
        }
    }
}


Measured memory_bytes: 24116
import java.util.Scanner;

class Main{
	public static void main(String args[]){	

		Scanner scan = new Scanner(System.in);

		int n = scan.nextInt();
		for(int i = 1; i <= n;i++){
			int x = i;
			if(x % 3 == 0){
				System.out.print(" " + i);
			}else {
				for(x = i; x != 0; x/=10){
					if(x % 10 == 3){
						System.out.print(" " + i);
						break;
					}
				}
			}
		}
		System.out.println();
	}
}

Measured memory_bytes: 28696
#include <cstdio>
#include <stack>
#include <algorithm>
using namespace std;
static const int MAX = 501;
struct Rectangle { int height, pos; };
int H, W;
int buffer[MAX][MAX];
int T[MAX][MAX];

void printT() {
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) printf("%d ", T[i][j]);
        printf("\n");
    }
}

int getLargestRectangleR(int idx, int size) {
    stack<Rectangle> S;
    int maxv = 0;
    T[idx][size] = 0;

    Rectangle rect, pre;
    for (int i = 0; i <= size; i++) {
        rect.height = T[idx][i];
        rect.pos = i;
        if ( S.empty() ) {
            S.push(rect);
        } else {
            if (S.top().height < rect.height) S.push(rect);
            else if (S.top().height > rect.height) {
                int target = i;
                while ( !S.empty() && S.top().height >= rect.height) {
                    pre = S.top(); S.pop();
                    int area = pre.height * (i - pre.pos);
                    maxv = max(maxv, area);
                    target = pre.pos;
                }
                rect.pos = target;
                S.push(rect);
            }
        }
    }
    return maxv;
}

int getLargestRectangle() {
    for (int j = 0; j < W; j++) {
        for (int i = 0; i < H; i++) {
            if (buffer[i][j]) T[i][j] = 0;
            else T[i][j] = (i > 0) ? T[i-1][j] + 1 : 1;
        }
    }
    //printT();
    int maxv = 0;
    for (int i = 0; i < H; i++) maxv = max(maxv, getLargestRectangleR(i, W));
    return maxv;
}


int main()
{
    char ch[501];
    for (; ;) {
        scanf("%d %d", &H, &W);
        if (H == 0 && W == 0) break;
        for (int i = 0; i < H; i++) {
            scanf("%s", ch);
            for (int j = 0; j < W; j++) {
                if (ch[j] == '.') buffer[i][j] = 0;
                else buffer[i][j] = 1;
            }
        }
        printf("%d\n", getLargestRectangle());
    }
    return 0;
}



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

int main() {

  int N,a,b;
  int x=0;
  
  cin >> N;
   for(int i = 0; i < N; i++){
  
     cin >> a >> b;
  
  
       x +=(b-a+1);
       
   }
  cout<<x<<endl;
  }


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

char Grading(int m, int f, int r){
    int sum = m + f;
    char grade;
    if (m == -1 || f == -1){
        grade = 'F';
        
    } else if (80 <= sum) {
        grade = 'A';
    } else if (65 <= sum && sum < 80){
        grade = 'B';
    } else if (50 <= sum && sum < 65){
        grade = 'C';
    } else if (30 <= sum && sum < 50){
        if (50 <= r)grade = 'C';
        else grade = 'D';
    } else if (sum <30){
        grade = 'F';
    }
    return grade;
}

int main(){
    int m, f, r;
    while(1){
        cin >> m >> f >> r;
        if (m == -1 && f == -1 && r == -1)break;
        cout << Grading(m, f, r) << endl;
    }
    return 0;
    
}


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



int main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int N, K;
  cin >> N >> K;
  vector<int> A(N);
  int d;
  int t;
  
  rep(i, K){
    cin >> d;
    rep(j, d){
      cin >> t;
      t--;
      A[t]++;
    }
  }

  int count = 0;
  rep(i, N){
    if(A[i] == 0) count++;
  }
    
    cout << count << endl;

  }




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

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)
#define TO_STRING(VariableName) # VariableName
#define LOG(x) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<endl;
#define LOG2(x,y) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<endl;
#define LOG3(x,y,z) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<endl;
#define LOG4(w,x,y,z) if(DEBUG)cout<<TO_STRING(w)<<"="<<w<<" "<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<endl;

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; }



void func(std::string S){
    if(S=="ABC")cout<<"ARC"<<endl;
    else cout<<"ABC"<<endl;
}

int main(){
    // cout << fixed << setprecision(5);

    std::string S;
    std::cin >> S;
    func(S);
    return 0;
}


Measured memory_bytes: 3628
//
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
#define MOD 1000000007
#define rp(i,n) for(int i=0;i<(n);i++)
#define up(i,s,e,d) for(int i=(s);i<(e);i+=(d))
#define ot(x) cout<<(x)
#define ote(x) cout<<(x)<<endl

void vprn(vector<int> &v){ for(int i=0;i<v.size();i++) cout<<v[i]<<(i<v.size()-1?",\t":"\n"); }
void vvprn(vector<vector<int>> &vv){ for(auto v:vv) vprn(v); }

int main(){
	int a,p;
	cin>>a>>p;
	ote((a*3+p)/2);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define EPS (1e-9)
#define INF (1e17)
#define PI (acos(-1))
//const double PI = acos(-1);
//const double EPS = 1e-15;
//long long INF=(long long)1E17;
#define i_7 (long long)(1e9+7)
//#define i_7 998'244'353
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
using namespace std;

bool prime_(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}

long long gcd_(long long a, long long b){
  if(a<b){
    swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd_(b,a%b);
  }
}
 
long long lcm_(long long x, long long y){
  return (x/gcd_(x,y))*y;
}


int main(){
  
  int n,x;
  cin>>n>>x;
  int a[n];
  REP(i,n){
    cin>>a[i];
  }
  sort(a,a+n);
  int ans = 0;
  REP(i,n){
    if(x>=a[i]){
      x -= a[i];
      if(i == n-1){
        if(x>0)continue;
      }
      ans++;
    }
  }
  cout<<ans<<endl;
  return 0; 
}


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

using namespace std;

#define SZ(v) ((int)(v).size())
#define ALL(v) (v).begin(),(v).end()
#define one first
#define two second
typedef long long ll;
typedef pair<int, int> pi;
const int INF = 0x3f2f1f0f;
const ll LINF = 1ll * INF * INF;

vector<int> F(8, 0);
int getP(vector<int> &o) {
	int k=-1; F[0] = -1;
	for(int i=1; i<8; i++) {
		while(k>=0 && F[k+1] != o[i%4]) k = F[k];
		if(F[k+1] == o[i%4]) k++;
		F[i] = k;
	}
	return 8 / (8 - (k+1)) / 2;
}
void rotate(vector<int> &o) {
	int temp = o.front();
	for(int i=0; i<3; i++) o[i] = o[i+1]; o.back() = temp;
}

const int MAX_N = 4e2 + 10;

int N; 
vector<int> Nr[MAX_N];
map<vector<int>, int> Cnt;

int main() {
	cin >> N;
	for(int i=0; i<N; i++) {
		for(int k=0, x; k<4; k++) scanf("%d", &x), Nr[i].push_back(x);
		for(int k=0; k<4; k++) Cnt[Nr[i]]++, rotate(Nr[i]);
	}
	
	vector<int> cube(8, 0);
	vector<vector<int>> faceIx({vector<int>({5, 4, 1, 0}), vector<int>({4, 7, 2, 1}), vector<int>({7, 6, 3, 2}), vector<int>({6, 5, 0, 3})});
	ll ans = 0;
	for(int l=0; l<N; l++) {
		for(int k=0; k<4; k++) cube[k] = Nr[l][k];
		for(int k=0; k<4; k++) Cnt[Nr[l]]--, rotate(Nr[l]);
		for(int r=l+1; r<N; r++) {
			for(int k=0; k<4; k++) Cnt[Nr[r]]--, rotate(Nr[r]);
			for(int rt=0; rt<4; rt++) {
				for(int k=0; k<4; k++) cube[4+k] = Nr[r][(k+rt)%4];
				ll now = 1;
				vector<vector<int>> faces;
				for(int f=0; f<4; f++) {
					vector<int> face(4, 0);
					for(int k=0; k<4; k++) face[k] = cube[faceIx[f][k]];
					if((now *= Cnt[face]) == 0) break;
					faces.push_back(face);
					for(int k=0; k<4; k++) Cnt[face]--, rotate(face);
				}
				ans += now;
				for(int f=0; f<SZ(faces); f++) for(int k=0; k<4; k++) Cnt[faces[f]]++, rotate(faces[f]);
			}
			for(int k=0; k<4; k++) Cnt[Nr[r]]++, rotate(Nr[r]);
		}
	}
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 35328
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>

using namespace std;

int cmp(const void *a,const void *b)
{
    return *(int *)b - *(int *)a;
}

int main()
{
    int n,m;
    int num[50]={};
    int i,sum;
    while (scanf("%d%d",&n,&m)!=EOF)
    {
        memset(num,0,sizeof (num));
        for (i=0;i<n;i++)
        {
            scanf("%d",&num[i]);
        }
        qsort(num,n,sizeof(num[i]),cmp);
        sum=0;
        for (i=0;i<m;i++)
        {
            sum+=num[i];
        }
        printf("%d\n",sum);
    }
    return 0;
}

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

int main()
{
	int x;
	cin >> x;
	if (x >= 30)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
	return 0;
}


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

int main() {
    int N;
    cin >> N;
    vector<int> cards(N);

    for (int i = 0; i < N ; i++) {
        cin >> cards.at(i);
    }

    sort(cards.begin(), cards.end());
    reverse(cards.begin(), cards.end());

    int alice = 0; 
    int bob = 0;
    for (int i = 0; i < N; i++) {
        if (i % 2 == 0) {
            alice += cards.at(i);
        } else {
            bob += cards.at(i);
        }
    }

    cout << alice - bob << endl;
}

Measured memory_bytes: 256
n, x = map(int, input().split())
a_list = list(map(int, input().split()))

count = 0
for i in range(n):
    x -= sorted(a_list)[i]
    if i < n - 1 and x >= 0:
        count += 1
    elif i == n - 1 and x == 0:
        count += 1

print(count)

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

#define ll long long
#define fw(p) for(int w=0;w<(p);w++)
#define fx(p) for(int x=0;x<(p);x++)
#define fy(p) for(int y=0;y<(p);y++)
#define fz(p) for(int z=0;z<(p);z++)
#define fyg(p,g) for(int y=(g);y<(p);y++)
#define fzg(p,g) for(int z=(g);z<(p);z++)
#define ce(d) cout<<d<<endl;
#define vecp(p) int aa;cin>>aa;(p).push_back(aa);
#define vecpl(p) long long aa;cin>>aa;(p).push_back(aa);
#define vecps(p) string aa;cin>>aa;(p).push_back(aa);
#define vecp2(p) cin>>aa;(p).push_back(aa);
#define vecpl2(p) long long a	b;cin>>ab;(p).push_back(ab);
#define vecps2(p) string ab;cin>>ab;(p).push_back(ab);
#define sorts(c) sort((c).begin(),(c).end());
#define reverses(c) reverse((c).begin(),(c).end());
#define vec(b) vector<int> (b);
#define vecl(b) vector<long long> (b);
#define vecs(b) vector<string> (b);
#define pb(b,a) (b).push_back((a));
#define doublece(a,b) cout<<(a)<<' '<<(b)<<endl;
#define pairs(s) vector<pair<int,int>> (s);
#define pairsp(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define MOD 1000000007
#define cey ce("Yes")
#define cen ce("No")
#define ceY ce("YES")
#define ceN ce("NO")

int main()
{
	string S, T;
	cin >> S >> T;
	int ans = 0;
	fx(S.size()) {
		if (S[x]!=T[x]) {
			ans++;
		}
	}
	ce(ans)
    return 0;
}



Measured memory_bytes: 3900
#include <cstdio>
#include <vector>
#include <iostream>

using namespace std;

vector< bool > isprime( 100000000, 1 );
int n, ret = 0;

int main()
{
    isprime[0] = isprime[1] = 0;
    for( int i = 2; i * i < 100000000; i++ )
    {
        if( isprime[i] )
        {
            for( int j = 1; i * ( j + 1 ) < 100000000; j++ )
            {
                isprime[ i * ( j + 1 ) ] = 0;
            }
        }
    }

    while( scanf( "%d\n", &n ) != EOF )
    {
        if( isprime[n] ){
            ret++;
        }
    }
    printf( "%d\n", ret );
    return 0;
}


Measured memory_bytes: 14800
n, m = map(int, input().split())

ans = list(' '*n)

for i in range(m):
  a, b = map(int, input().split())
  
  if n != 1 and a==1 and b ==0:
    print(-1)
    exit()
  if ans[a-1] != ' ' and ans[a-1] != str(b):
    print(-1)
    exit()
    
  ans[a-1] = str(b)

if ans[0] == ' ' and n != 1:
  ans[0] = '1'
ans = ''.join(ans)

print(int(ans.replace(' ', '0')))


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

using namespace std;

#define int long long 
#define INF 1e9
#define LINF 1e18

typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<int, P> Pi;
typedef pair<P, P> PP;

const int MOD = 1e9 + 7;
const int dy[] = { 0, 0, 1, -1 };
const int dx[] = { 1, -1, 0, 0 };

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

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

    int N;
    cin >> N;
    vector<P> p(2 * N);
    for(int i = 0; i < N; ++i) {
        cin >> p[i].first;
        p[i].second = 0;
    }
    for(int i = 0; i < N; ++i) {
        cin >> p[i + N].first;
        p[i + N].second = 1;
    }
    sort(p.begin(), p.end());
    int res = 1, cnt = 0;
    for(auto i : p) {
        //cout << i.second << endl;
        int add = i.second ? 1 : -1;
        //cout << add << endl;
        if(cnt != 0 && (cnt > 0) != i.second) {
            res = (res * abs(cnt)) % MOD;
        }
        cnt += add;
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 3456
// #pragma GCC optimize ("O3")
// #pragma GCC target ("sse4")

#include <bits/stdc++.h>
using namespace std;
const int INF = 1 << 29;
const int NINF = -1*INF;
const long long LLINF = 1ll << 60;
const long long LLNINF = -1*LLINF;

template <class Ch, class Tr, class Container>
basic_ostream <Ch, Tr> & operator << (basic_ostream <Ch, Tr> & os, Container const& x) {
    os << "{ ";
    for(auto& y : x) os << y << " ";
    return os << "}";
}

template <class X, class Y>
ostream & operator << (ostream & os, pair <X, Y> const& p) {
	return os << "[ " << p.first << ", " << p.second << "]" ;
}

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef vector<ld> vld;
typedef vector<pi> vpi;
typedef vector<pll> vpll;
typedef vector<vector<int>> vvi;
typedef vector<vll> vvll;
typedef vector<vd> vvd;
typedef vector<vld> vvld;
 
#define mp make_pair
#define pb push_back
#define pf push_front
#define all(x) x.begin(), x.end()
#define revAll(x) x.rbegin(), x.rend()
#define gcd(a, b) __gcd(a, b)
#define popcount(x) __builtin_popcount(x)
#define isize(x) (int)(x.size())
#define rep(i,n) for(int i = 0; i < n; i++)
#define rep1(i, n) for(int i = 1; i < n+1; i++)
#define umap unordered_map

const ll MOD = 1e9 + 7;

// points type 0, queries type 1
struct Event{
	int type, start, end, val;

	Event(int t, int s, int e, int v){
		type = t, start = s, end = e, val = v;
	}

	bool operator<(const Event& other){
		return mp(end, type) < mp(other.end, other.type);
	}

};

inline int lastbit(int x) {
  return x & (-x);
}

template <int... ArgsT> struct BIT {
  int val = 0;
  void update(int val) {
    this->val += val;
  }
  int query() {
    return val;
  }
};

template <int N, int... Ns>
struct BIT<N, Ns...> {
  BIT<Ns...> bit[N + 1];
  template<typename... Args>
  void update(int pos, Args... args) {
  	pos++;
    for (; pos <= N; bit[pos].update(args...), pos += lastbit(pos));
  }
  template<typename... Args>
  int query(int l, int r, Args... args) {
    int ans = 0; l++; r++;
    for (; r >= 1; ans += bit[r].query(args...), r -= lastbit(r));
    for (--l; l >= 1; ans -= bit[l].query(args...), l -= lastbit(l));
    return ans;
  }
};

int main(){
	ios_base::sync_with_stdio(false);cin.tie(0);
	int n, q; cin >> n >> q;
	vector<Event> events = vector<Event>();
	vi ans = vi(q);
	rep(i, n){
		int x; cin >> x;
		events.pb(Event(0, i, i, x));
	}
	rep(orig_index, q){
		int l, r; cin >> l >> r;
		l--, r--;
		events.pb(Event(1, l, r, orig_index));
	}
	sort(all(events));
	BIT<5*100000+100> bit;
	umap<int, int> last = umap<int, int>();
	for(const Event& event : events){
		if (event.type == 0){
			if (last.find(event.val) != last.end()){
				bit.update(last[event.val], -1);
			}
			last[event.val] = event.start;
			bit.update(event.start, 1);
		}else{
			int cnt = bit.query(event.start, event.end);
			ans[event.val] = cnt;
		}
	}
	rep(i, isize(ans)){
		cout << ans[i] << "\n";
	}
}

Measured memory_bytes: 43016
def f(p, xs):
    r = 0
    for x in xs:
        r += (x-p)**2
    return r

N, = map(int, input().split())
X = list(map(int, input().split()))
r = 10**18
for i in range(101):
    r = min(r, f(i, X))
print(r)


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

void decPrime(int x, vector<int> &dec_prime)
{
    for (int i = 1; i * i <= x; i++)
    {
        if (x % i == 0)
            dec_prime.push_back(i);
    }
}
int f(int a, int b)
{
    return a * a * a * a + a * a * a * b + a * a * b * b + a * b * b * b + b * b * b * b;
}

int main(void)
{
    int x;
    cin >> x;
    vector<int> dec_prime;
    decPrime(x, dec_prime);
    for (auto p : dec_prime)
    {
        int a = p / 2;
        int b = a - p;
        while (f(a, b) <= x / p)
        {
            if (x / p == f(a, b))
            {
                cout << a << ' ' << b << endl;
                return 0;
            }
            a++;
            b++;
        }
    }
    /*
    int a = 0;
    int b = -x;
    while (f(a, b) < 1)
    {
        if (1 == f(a, b))
        {
            cout << a << ' ' << b << endl;
            return 0;
        }
        a++;
        b++;
    }
    */
    cout << "error" << endl;
    for (auto p : dec_prime)
        cout << p << ' ';
    cout << endl;
    return 0;
}

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

using i64 = int64_t;

int main(){
    string s;
    cin >> s;
    set<char> st;
    bool ok = true;
    for(auto c: s){
        if(st.count(c))ok = false;
        st.insert(c);
    }

    cout << (ok ? "yes" : "no") << endl;

    return 0;
}


Measured memory_bytes: 256
using System;

class MainClass
{
    public static void Main(string[] args)
    {
        var x = int.Parse(Console.ReadLine());

        var d = new bool[100005];

        for (int i = 2; i < d.Length; i++)
        {
            for (int j = 2; i * j < d.Length; j++)
            {
                d[i * j] = true;
            }
        }

        for (int i = x; i < d.Length; i++)
        {
            if (!d[i])
            {
                Console.WriteLine(i);
                return;
            }
        }
    }
}


Measured memory_bytes: 11112
#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 MOD 1000000007
const int INF = 1LL<<30;
 
int main(){
    double w,h,x,y;
    cin>>w>>h>>x>>y;

    double ans=w*h/2;
    cout<<fixed<<setprecision(10)<<ans<<" ";

    if(2*x==w && 2*y==h) cout<<1<<endl;
    else cout<<0<<endl;
}

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

int main() {
  int64_t N, K;
  cin >> N >> K;

  vector<int64_t> A(N + 1);
  for (int64_t i = 1; i <= N; i++) {
    cin >> A[i];
  }

  int64_t pos = 1;
  set<int64_t> check;
  while (true) {
    if (!check.insert(pos).second) {
      break;
    }
    pos = A[pos];
  }
  int64_t loop_start_pos = pos;
  
  pos = 1;
  int64_t count = 0;
  while (pos != loop_start_pos) {
    pos = A[pos];
    count++;
    if (count == K) {
      cout << pos << endl;
      return 0;
    }
  }
  int64_t loop_start_count = count;

  vector<int64_t> rotation;
  do {
    rotation.push_back(pos);
    pos = A[pos];
  } while (pos != loop_start_pos);

  cout << rotation[(K - loop_start_count) % rotation.size()] << endl;

  return 0;
}


Measured memory_bytes: 14308
#include <iostream>
#include <cstdio>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>

using namespace std;

int a[8];

int main()
{
    int n;

    cin >> n;

    int mi = 0;
    int ma = 0;

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

        int num = ai / 400;
        if(num >= 8){
            ma++;
            continue;
        }

        if(a[num] == 0){
            ma++;
            mi++;
            a[num] = 1;
        }
    }
    if(mi == 0) mi = 1;

    cout << mi << " " << ma << endl;
    return 0;
}

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

int main()
{
	int n,h,s=0;
	cin>>n;
	int a,b;
	cin>>a>>b;
	for (int i=1;i<=n; i++)
	{
		int p=0;
		h=i;
		while (h!=0)
		{
			p+=h%10;
			h/=10;
		}
		if(p>=a&&p<=b)
		{
			s+=i;
		}
	}
	cout<<s<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

const int N = 2e4 + 7;

int n,a[N], b[N];
char s[N], t[N];

int calc() 
{
	int t1 = 0, t2 = 0;
	for (int i = 1; i < n; ++i)
		if (s[i] == '0' && s[i + 1] =='1') a[++t1] = i;
	for (int i = 1; i <= n; ++i) b[++t2] = 0;
	for (int i = 1; i < n; ++i) 
		if (t[i] == '0' && t[i + 1] == '1') b[++t2] = i;
	for (int i = 1; i <= n; ++i) b[++t2] = n;
	int ret = n * n;
	for (int i = 1; i <= t2 - t1 + 1; ++i)
	{
		int now = 0;
		for (int j = 1; j <= i - 1; ++j) now += b[j];
		for (int j = 1; j <= t1; ++j) now += abs(a[j] - b[i + j - 1]);
		for (int j = i + t1; j <= t2; ++j)
			now += n - b[j];
		ret = min(ret, now);
	}
	return ret;
}

int main() 
{
	scanf("%d", &n);
	scanf("%s", s + 1);
	scanf("%s", t + 1);
	if (n <= 2) 
	{
		int ans = 0;
		for (int i = 1; i <= n; ++i) ans += s[i] != t[i];
		printf("%d\n", ans);
		return 0;
	}
	int tmp = calc();
	for (int i = 1; i <= n; ++i) 
		s[i] = '0' + '1' - s[i], t[i] = '0' + '1' - t[i];
	printf("%d\n", tmp + calc());
	return 0;
}

Measured memory_bytes: 384