akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

ll n, m;
vector<int> lis[100100];
ll D[100100];

void dfs(int here, int p) {
    D[here] = 1;
    int i, t = -1;
    for (i=0;i<lis[here].size();i++) {
        int there = lis[here][i];
        if (there==p) t = i;
        else {
            dfs(there,here);
            D[here] = D[here]*(D[there]+1)%m;
        }
    }
    if (~t) lis[here].erase(lis[here].begin()+t);
}

void rdfs(int here, int p, ll val) {
    vector<ll> pre, suf;
    pre.push_back(1); suf.push_back(1);
    D[here] = D[here]*(val+1)%m;
    for (int i=0;i<lis[here].size();i++) pre.push_back(pre.back()*(D[lis[here][i]]+1)%m);
    for (int i=(int)lis[here].size()-1;~i;i--) suf.push_back(suf.back()*(D[lis[here][i]]+1)%m);
    for (int i=0;i<lis[here].size();i++) rdfs(lis[here][i],here,(val+1)*pre[i]%m*suf[(int)lis[here].size()-1-i]%m);
}

int main() {
    int i;

    scanf("%d%d",&n,&m);
    for (i=0;i<n-1;i++) {
        int a, b;
        scanf("%d%d",&a,&b); --a; --b;
        lis[a].push_back(b);
        lis[b].push_back(a);
    }
    dfs(0,-1);
    rdfs(0,-1,0);
    for (i=0;i<n;i++) printf("%lld\n",D[i]);

    return 0;
}


Measured memory_bytes: 22400
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <sstream>
#include <cassert>
using namespace std;
static const double EPS = 1e-5;
typedef long long ll;
typedef pair<int,int> PI;
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define MP make_pair
#define PB push_back

double cal(double l,double r,char op){
  switch(op){
  case '+':return l+r;
  case '-':return l-r;
  case '*':return l*r;
  case '/':return l/r;
  }
}

main(){
  string str;
  while(getline(cin,str)){
    stringstream ss(str);
    stack<double> por;
    string op;
    while(ss>>op){
      if(isdigit(op[0]) || op.size()>1)por.push(atof(op.c_str()));
      else{
        double r=por.top();por.pop();
        double l=por.top();por.pop();
        por.push(cal(l,r,op[0]));
      }
    }
    double ans=por.top();
    printf("%.8f\n",ans);
  }
}

Measured memory_bytes: 0
//INCLUDE
//------------------------------------------
#include <bits/stdc++.h>
//DEFINE
//------------------------------------------
#define ll long long
#define ld long double
#define ALLv(a)  (a).begin(),(a).end()
#define ALL(a,n)  (a),(a)+n
#define vi vector<long long>
#define vd vector<long double>
#define vs vector<string>
#define dcml(n) fixed<<setprecision(n)
//CONST
//------------------------------------------
const ll INF=1010000000000000017LL;
const ll MOD=1000000007LL;
const ld EPS=1e-12;
const ld PI=3.14159265358979323846;
//REPEAT
//------------------------------------------
#define   FOR(i,m,n) for(ll (i)=(m);   (i)<(n);  (i)++)
#define  FORS(i,m,n) for(ll (i)=(m);   (i)<=(n); (i)++)
#define  RFOR(i,m,n) for(ll (i)=(n)-1; (i)>=(n); (i)--)
#define RFORS(i,m,n) for(ll (i)=(n);   (i)>(n);  (i)--)
#define   REP(i,n)   for(ll (i)=0;     (i)<(n);  (i)++)
#define  REPS(i,x)   for(ll (i)=1;     (i)<=(x); (i)++)
#define  RREP(i,x)   for(ll (i)=(x)-1; (i)>=0;   (i)--)
#define RREPS(i,x)   for(ll (i)=(x);   (i)> 0;   (i)--)
#define  WREP(i,in,j,jn) REP(i,in)REP(j,jn)
#define WREPS(i,in,j,jn) REPS(i,in)REPS(j,jn)
//-----------------------------------------
//namespace
using namespace std;
//ライブラリはここに
//↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓

//-----------------------------------------
int main(void){
    ll N,K;
    priority_queue<ll,vector<ll>,greater<ll>> que;
    cin>>N>>K;ll p;
    REP(i,N){
        cin>>p;
        que.push(p);
    }
    ll ans=0;
    REP(i,K){
        auto r=que.top();que.pop();
        ans+=r;
    }
    cout<<ans<<"\n";
}

Measured memory_bytes: 3600
#include<bits/stdc++.h>
using namespace std;
 
#define int long long
 
main(){
 
	int n,a,b;
	cin>>n>>a>>b;
 
	int aa=(n-1)*a+b;int bb=(n-1)*b+a;
	int ans=max((int)0,bb-aa+1);
 
	cout<<ans<<endl;
 
	return(0);
}

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

using namespace std;

int N, M, Q, CurNum;
int Numbers[200000], Ans[1000];
list<int> StuID;
list<int>::iterator CurPos;

void solve() {
	
	if ((CurNum & 1) == 1) {
		for (int i = 0; i < CurNum; ++i) {
			if (CurPos == StuID.begin()) {
				CurPos = StuID.end();
			}
			--CurPos;
		}
	}
	else {
		for (int i = 0; i < CurNum; ++i) {
			++CurPos;
			if (CurPos == StuID.end()) {
				CurPos = StuID.begin();
			}
		}
	}
	Ans[*CurPos] = 0;
	CurPos = StuID.erase(CurPos);
	if (CurPos == StuID.end()) {
		CurPos = StuID.begin();
	}
}

int main() {
	int q;

	StuID.clear();
	cin >> N >> M >> Q;
	for (int i = 0; i < N; ++i) {
		StuID.push_back(i);
	}

	fill(Ans, Ans + N, 1);
	CurPos = StuID.begin();
	for (int i = 0; i < M; ++i) {
		cin >> CurNum;
		solve();
	}

	for (int i = 0; i < Q; ++i) {
		cin >> q;
		cout << Ans[q] << endl;
	}
	
	return 0;
}



Measured memory_bytes: 10120
#include<iostream>
#include <string>
#include<algorithm>
#include <set>
#include <cmath>
using namespace std;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rep0(i,n) rep(i,0,n)

int gcd(int a, int b) {
	if (a == 0) return b;
	if (b == 0) return a;
	int m = max(a, b);
	int n = min(a, b);
	if (m%n == 0) return n;
	else return gcd(n, m%n);

}

int main(void) {
	ios::sync_with_stdio(false);
	int N, i, j, k, re;
	cin >> N;
	int A[N];
	cin >> A[0];
	re = A[0];
	rep(i, 1, N) {
		cin >> A[i];
		re = gcd(re, A[i]);
	}
	cout << re;
	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include<algorithm>
//#include <string>
//#include <cassert>
//#include <cmath>
//#include <limits>
using namespace std;

int N;
string S;


int solve() {


    return 1;
}

int main() {

    cin >> S;

    auto ans = "ABC";
    if (S == "ABC") ans = "ARC";


    cout << ans << endl;

    return 0;
}

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

int main(){
    int A,B,C;cin>>A>>B>>C;
    int K;cin>>K;
    if(A>=B && A>=C) A*=pow(2,K);
    else if(B>=A && B>=C) B*=pow(2,K);
    else C*=pow(2,K);

    cout<<A+B+C<<endl;
}

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

works = []
for _ in range(N):
    A, B = map(int, input().split())
    works.append((A,B))

works.sort(key=lambda w: w[1])

t = 0
for w in works:
    t += w[0]
    if w[1] < t:
        print('No')
        exit()

print('Yes')

Measured memory_bytes: 31860
#include <algorithm>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int(i) = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define pb push_back
#define MP(a, b) make_pair((a), (b))
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;

// UnionFind
struct UnionFind {
    vector<ll> par;
    vector<ll> siz;

    UnionFind(ll N) : par(N), siz(N, 1LL) {
        for(int i = 0; i < N; i++)
            par[i] = i;
    }
    int root(int x) {
        if(par[x] == x)
            return x;
        return par[x] = root(par[x]);
    }
    void unite(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        if(rx == ry)
            return;
        if(siz[rx] < siz[ry])
            swap(rx, ry);
        siz[rx] += siz[ry];
        par[ry] = rx;
    }
    bool same(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
    ll size(ll x) { return siz[root(x)]; }
};

int main() {
    int N, M;
    cin >> N >> M;
    UnionFind uf(N);
    rep(i, M) {
        int x, y, z;
        cin >> x >> y >> z;
        x--, y--;
        uf.unite(x, y);
    }
    set<int> par;
    rep(i, N) { par.insert(uf.root(i)); }
    cout << par.size() << endl;
    return 0;
}

Measured memory_bytes: 6528
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <set>
#include <string>
#include <queue>
#include <deque>
#include <vector>
#include <map>
#include <limits.h>
using namespace std;

int main() {
	int n;
	cin >> n;
	string str;
	cin >> str;
	char last = str[0];
	int ans = 1;
	for (int i = 1; i < n; i++) {
		if (str[i] != last) {
			ans++;
			last = str[i];
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 512
#include <stdio.h>
int main(void){
  
  char s[100];
  scanf("%s",s);
  if(s[0]=='M'){printf("6");}
  else if(s[0]=='T'&&s[1]=='U'){printf("5");}
    else if(s[0]=='W'){printf("4");}
  else if(s[0]=='T'&&s[1]=='H'){printf("3");}
  else if(s[0]=='F'){printf("2");}
  else if(s[0]=='S'&&s[1]=='A'){printf("1");}
  else{printf("7");}
  return 0;
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
//#define int long long

signed main(){
    int a, b, c;
    cin >> a >> b >> c;
    cout << c << " " << a << " " << b << endl;
}

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

namespace Test
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            var str = Console.ReadLine();
            var areas=new List<int>();

            for (int i = 0; i < str.Length; i++)
            {
                if (str[i] == '\\')
                {
                    var num = 0;
                    for (int j = i+1; j < str.Length; j++)
                    {
                        if (str[j] == '\\')
                        {
                            num++;
                        }
                        else if (str[j] == '/')
                        {
                            if (num == 0)
                            {
                                //水たまりができた
                                areas.Add(CalculatePoolArea(str.Substring(i,j-i+1)));
                                i = j;
                                break;
                            }
                            else
                            {
                                num--;
                            }
                        }
                    }
                }
            }

            Console.WriteLine(areas.Sum());
            Console.Write("{0}", areas.Count);
            if (areas.Count != 0)
            {
                Console.Write(" ");
                Console.WriteLine(string.Join(" ", Array.ConvertAll(areas.ToArray(), x => x.ToString())));
            }
            else
            {
                Console.WriteLine();
            }

            Console.Read();
        }

        private static int CalculatePoolArea(string p)
        {
            var depth = 0;
            var result = 0.0;
            foreach (var item in p)
            {
                if (item == '\\')
                {
                    result = result+ 0.5 + depth;
                    depth++;
                }
                else if (item == '/')
                {
                    depth--;
                    result = result + 0.5 + depth;
                }
                else
                {
                    result = result + depth;
                }
            }
            return (int)result;
        }
    }
}

Measured memory_bytes: 18092
#include <bits/stdc++.h>
#define pb push_back 
#define x first 
#define y second 
#define MOD 998244353LL

#if 1
#define pi(x) printf("%s = %i; ", #x, x)
#define ps(x) printf("%s = %s; ", #x, x.c_str())
#define pn printf("\n");
#else  
#define pi(x)
#define ps(x)
#define pn
#endif

using namespace std;
typedef unsigned long long ll;
typedef pair< int , int > PII;
const int dirx[] = {0,1,0,-1};
const int diry[] = {1,0,-1,0};
inline void debugMode() {
    #ifndef ONLINE_JUDGE
    freopen("input.in", "r", stdin);
    freopen("output.out", "w", stdout);
    #endif
}

int n, x, y, a[2010], idx;
PII p[2010];
int v = 1;
int main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> n >> x >> y;
    int Y = y;
    for (int i = 1; i <= n; i++) cin >> a[i];
	for (int i = 1; i <= n; i++) p[i].x = INT_MAX;
	for (int i =1; i < n; i++)
		for (int j = i + 1; j <= n; j++)
			p[i].x = min(p[i].x, abs(a[i] - a[j])),
			p[i].y = max(p[i].y, abs(a[i] - a[j]));
	p[n].x = abs(a[n] - y); p[n].y = abs(a[n] - x);
	for (int i = 1; i <= n; i++){
		int mx = 0, mn = INT_MAX;
		for (int j = i; j <= n; j++){
			if(v == 1 && p[j].x > mx) mx = p[j].x,idx = j;
			if(v == 2 && p[j].y < mn) mn = p[j].y,idx = j;
		}
		if(v==1)x=a[idx],v=2;
		else if(v==2)y=a[idx],v=1;
		p[n].x=abs(a[n]-y),p[n].y=abs(a[n]-x),i=idx;
	}
	cout << max(abs(x - y), abs(a[n] - Y));
	return 0;
}


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

int main(void) {

  long n;
  scanf("%ld", &n);
  long h[n];
  for (long i = 0; i < n; i++) {
    scanf("%ld", &h[i]);
  }
  long min[n];
  min[0] = 0;
  min[1] = labs(h[1]-h[0]);
  for (long i = 2; i < n; i++) {
    min[i] = min[i-1]+labs(h[i]-h[i-1]);
    if (min[i-2]+labs(h[i]-h[i-2]) < min[i]) {
      min[i] = min[i-2]+labs(h[i]-h[i-2]);
    }
  }
  printf("%ld\n", min[n-1]);

  return 0;
}

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

using namespace std;

#define S scanf
#define P printf
#define G getline
#define SZ size()
#define C clear()
#define B begin()
#define F front()
#define T top()
#define E end()
#define EM empty()
#define V vector
#define Q queue
#define DQ deque
#define PQ priority_queue
#define ST stack
#define FI first
#define SE second
#define PI acos(-1)
#define PS push
#define PP pop()
#define PSF push_front
#define PSB push_back
#define PPF pop_front()
#define PPB pop_back()
#define MP make_pair
#define LL long long int
#define ULL unsigned long long int
#define PII pair<int,int>
#define PSI pair<string,int>
#define PIS pair<int,string>
#define PLI pair<long long int,int>
#define PLL pair<long long int,long long int>
#define MII map<int,int>
#define MSI map<string,int>
#define MIS map<int,string>
#define MLI map<long long int,int>
#define FAST() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)





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




int r,c;
char grid[22][22];
int cost[22][22];
PQ<pair<int,PII>,V<pair<int,PII> >,greater<pair<int,PII> > >pq;

void run_dijkstra()
{
    int i,x,x1,y,y1,bal;
    while(!pq.EM)
    {
        bal=pq.T.FI;
        x=pq.T.SE.FI;
        y=pq.T.SE.SE;
        pq.PP;
        for(i=0;i<4;i++)
        {
            x1=x+dx[i];
            y1=y+dy[i];
            if(x1 > 0  &&  x1 <= r  &&  y1 > 0  &&  y1 <= c  &&  grid[x1][y1] != '#')
            {
                if(cost[x1][y1] > bal+1)
                {
                    cost[x1][y1]=bal+1;
                    pq.PS({bal+1,{x1,y1}});
                }
            }
        }
    }
}

int main()
{
    FAST();

//    freopen("input.txt","r",stdin);
//    freopen("output.txt","w",stdout);

    int i,j,x,y,ans=0;
    cin >> r >> c;
    for(i=1;i<=r;i++)cin >> grid[i]+1;
    for(i=1;i<=r;i++)
    {
        for(j=1;j<=c;j++)
        {
            if(grid[i][j] != '#')
            {
                for(x=1;x<=r;x++)
                {
                    for(y=1;y<=c;y++)cost[x][y]=INT_MAX;
                }
                cost[i][j]=0;
                pq.PS({0,{i,j}});
                run_dijkstra();
                for(x=1;x<=r;x++)
                {
                    for(y=1;y<=c;y++)
                    {
                        if(cost[x][y] < INT_MAX)ans=max(ans,cost[x][y]);
                    }
                }
            }
        }
    }
    cout << ans;
    return 0;
}


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

int main(int argc, char const *argv[]) {
  std::string s;
  std::cin >> s;
  int a=0, b=0;
  for (size_t i = 0; i < s.size(); i++) {

    if (s.at(i) == '0') {
      if (i % 2 ==1) a++;
      else b++;
    }
    else {
      if (i % 2 ==1) b++;
      else a++;
    }
  }
  std::cout << std::min(a,b) << '\n';
  return 0;
}


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

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = mod * mod;
const int INF_N = 1e+9;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-12;
const ld pi = acos(-1.0);
//typedef vector<vector<ll>> mat;
typedef vector<int> vec;

//繰り返し二乗法
ll mod_pow(ll a, ll n, ll m) {
	ll res = 1;
	while (n) {
		if (n & 1)res = res * a%m;
		a = a * a%m; n >>= 1;
	}
	return res;
}

struct modint {
	ll n;
	modint() :n(0) { ; }
	modint(ll m) :n(m) {
		if (n >= mod)n %= mod;
		else if (n < 0)n = (n%mod + mod) % mod;
	}
	operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
modint operator+=(modint &a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; }
modint operator-=(modint &a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; }
modint operator*=(modint &a, modint b) { a.n = ((ll)a.n*b.n) % mod; return a; }
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, int n) {
	if (n == 0)return modint(1);
	modint res = (a*a) ^ (n / 2);
	if (n % 2)res = res * a;
	return res;
}

//逆元(Eucledean algorithm)
ll inv(ll a, ll p) {
	return (a == 1 ? 1 : (1 - p * inv(p%a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }

const int max_n = 1 << 18;
modint fact[max_n], factinv[max_n];
void init_f() {
	fact[0] = modint(1);
	for (int i = 0; i < max_n - 1; i++) {
		fact[i + 1] = fact[i] * modint(i + 1);
	}
	factinv[max_n - 1] = modint(1) / fact[max_n - 1];
	for (int i = max_n - 2; i >= 0; i--) {
		factinv[i] = factinv[i + 1] * modint(i + 1);
	}
}
modint comb(int a, int b) {
	if (a < 0 || b < 0 || a < b)return 0;
	return fact[a] * factinv[b] * factinv[a - b];
}
using mP = pair<modint, modint>;

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




void solve() {
	int N; cin >> N;
    vector<ll> hv(N);
    rep(i, N) cin >> hv[i];

    bool flg = true;
    rep(i, N-1){
        if(hv[i] < hv[i+1]){
            hv[i+1]--;
        }else if(hv[i] > hv[i+1]){
            flg = false;
            break;
        }
    }

    if(flg){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  //cout << fixed << setprecision(10);
  //init_f();
  //init();
  //int t; cin >> t; rep(i, t)solve();
  solve();
//   stop
    return 0;
}


Measured memory_bytes: 5120
#include <bits/stdc++.h>
using namespace std;
int main(){
  int a,b;
  cin>>a>>b;
  vector<int> vec={0,13,1,2,3,4,5,6,7,8,9,10,11,12};
  if(vec.at(a)<vec.at(b)){
    cout<<"Bob"<<endl;
  }else if(vec.at(a)>vec.at(b)){
    cout<<"Alice"<<endl;
  }else{
    cout<<"Draw"<<endl;
  }
   
}

Measured memory_bytes: 256
K = int(input())
S = input()
r = 0
g = 0
b = 0
for c in S:
  if c=="R":
    r+=1
  if c=="G":
    g+=1
  if c=="B":
    b+=1
    
ans = r*g*b

for i in range(1,2000):
  tail = i*2
  if tail>(K-1):
    break
  head = 0
  mid = i
  while tail<=(K-1):
    if S[head]!=S[mid] and S[tail]!=S[mid] and S[head]!=S[tail]:
      ans = ans-1
    head+=1
    mid+=1
    tail+=1
    
print(ans)

  

Measured memory_bytes: 9220
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#define max(x,y)(x>y?x:y)
#define min(x,y)(x>y?y:x)
typedef long long int ll;
typedef unsigned long long int ull;
int asc_cmp(const void* X,const void* Y){int x=*(int*)X,y=*(int*)Y;if(x<y)return -1;else if(x==y)return 0;else return 1;}
int desc_cmp(const void* X,const void* Y){int x=*(int*)X,y=*(int*)Y;if(x<y)return 1;else if(x==y)return 0;else return -1;}

int main(){
    int n;scanf("%d",&n);
    int b[n];for(int i=0;i<n;i++)scanf("%d",&b[i]);

    int flg[1000]={},ans=0;
    for(int i=0;i<n;i++){
        if(flg[b[i]])continue;
        flg[b[i]]=1;
        ans++;
    }
    printf("%d\n",ans);
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int gcd(int a, int b) {  
  return b != 0 ? gcd(b, a % b) : a;
}//MAX
int lcm(int a, int b) { 
   return a * b / gcd(a, b);
   }
//MIN

 main() {
vector<int>a(4);
for(int i=0;i<4;i++){
   cin >> a.at(i);
}
sort(a.begin(),a.end());
if(a.at(0)==1&&a.at(1)==4&&a.at(2)==7&&a.at(3)==9){
   cout << "YES"<<endl;
}
else{
   cout<<"NO"<<endl;
}
 }


Measured memory_bytes: 256
n=gets.chomp.to_i
a=gets.chomp.split(" ").map{|s| s.to_i}
c={}

a.each{|m|
  if c[m]==nil
    c[m]=1
  else
    c[m]+=1
  end
}
ans=0
c.each{|k,v|
  if k < v
    ans+=v-k
  elsif v < k
    ans+=v
  end
}
puts ans

Measured memory_bytes: 15492
#include <bits/stdc++.h>
#define ll long long int
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define pb emplace_back
#define vi vector<int>
#define all(x) (x).begin(), (x).end()
#define pb emplace_back
#define deb(x) cout << #x << " - " << x << endl;

using namespace std;

int main()
{	IOS;
/*#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif*/
	int n, k; cin >> n >> k;
	string s; cin >> s;
	k--;
	for (int i = 0; i < n; i++) {
		if (i == k) {
			if (s[i] == 'A') cout << "a";
			else if (s[i] == 'B') cout << "b";
			else cout << "c";
		}
		else cout << s[i];
	}

	return 0;

}

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

const ll P = 1000000007;
int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
vector<char> Alphabet = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'};
vector<char> alphabet = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};

int main()
{
  cout << fixed << setprecision(10);
  int N;
  cin >> N;
  string S;
  cin >> S;
  int ans = 0;
  rep(i,N)
  {
    int cnt = 0;
    set<char> se;
    set<char> se2;
    for(int j=0;j<N;j++)
    {
      if(i<=j)
      {
        se.insert(S[j]);
      }
      else
      {
        se2.insert(S[j]);
      }
    }
    rep(j,26)
    {
      if(se.count(alphabet[j]))
      {
        if(se2.count(alphabet[j])) 
        {
          cnt ++;
        }
      }
    }
    ans = max(ans,cnt);
  }
  cout << ans << endl;
  return 0;
}


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

ll f[5010][5010],a,b;
int num[5010],p[5010],n;

inline int rd()
{
	int x=0;char ch=getchar();
	for (;ch<'0'||ch>'9';ch=getchar());
	for (;ch>='0'&&ch<='9';ch=getchar()) x=x*10+ch-'0';
	return x;
}

int main()
{
	n=rd();a=rd();b=rd();
	for (int i=1;i<=n;i++) num[i]=rd(),p[num[i]]=i;
	for (int i=1;i<=n;i++)
	{
		if (i==p[1]) f[1][i]=0;
		else if (i<p[1]) f[1][i]=b;
		else f[1][i]=a;
	}
	for (int i=2;i<=n;i++)
	{
		for (int j=1;j<=n;j++) f[i][j]=inf;
		ll mn=inf;
		for (int j=1;j<=n;j++)
		{
			mn=min(mn,f[i-1][j]);
			if (j<p[i]) f[i][j]=min(f[i][j],mn+b);
			else if (j==p[i]) f[i][j]=min(f[i][j],mn);
			else f[i][j]=min(f[i][j],mn+a);
		}
	}
	ll ans=inf;
	for (int i=1;i<=n;i++) ans=min(ans,f[n][i]);
	printf("%lld\n",ans);
	return 0;
}

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

int main(){
      string s;cin >> s;
      int n = s.length();
      if(s[0] != 'A')return cout << "WA", 0;
      if(s[1] == 'C' || s[n - 1] == 'C')return cout << "WA", 0;
      bool c = false;
      for(int i = 1;i < n;i++){
            if(i >= 2 && s[i] == 'C' && i < n - 1){
                  if(!c)c = true;
                  else return cout << "WA", 0;
            }
            if(s[i] != 'C' && s[i] != 'A'){
                  if(isupper(s[i]))return cout << "WA", 0;
            }
      }
      if(c)cout << "AC";
      else cout << "WA";
}

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

public class Main {

	BufferedReader br;
	PrintWriter out;
	StringTokenizer st;
	boolean eof;

	void solve() throws IOException {
		int n = nextInt();
		double[] a = new double[n];
		for (int i = 0; i < n; i++) {
			a[i] = nextDouble();
		}
		
		int m = nextInt();
		long k = nextLong();
		
		int[] b = new int[m];
		
		for (int i = 0; i < m; i++) {
			b[i] = nextInt() - 1;
		}
		
		int[] perm = new int[n - 1];
		for (int i = 0; i < n - 1; i++) {
			perm[i] = i;
		}
		
		for (int pos : b) {
			pos--;
			int tmp = perm[pos];
			perm[pos] = perm[pos + 1];
			perm[pos + 1] = tmp;
		}
		
		int[] res = pow(perm, k);
		
		double[] deltas = new double[n - 1];
		for (int i = 0; i < n - 1; i++) {
			int idx = res[i];
			deltas[i] = a[idx + 1] - a[idx];
		}
		
		double tmp = a[0];
		out.println(tmp);
		for (double d : deltas) {
			tmp += d;
			out.println(tmp);
		}
	}
	
	int[] mult(int[] a, int[] b) {
		int[] c = new int[a.length];
		for (int i = 0; i < a.length; i++) {
			c[i] = b[a[i]]; // or???
//			c[i] = a[b[i]];
		}
		return c;
	}
	
	int[] pow(int[] p, long k) {
		int[] ret = new int[p.length];
		for (int i = 0; i < p.length; i++) {
			ret[i] = i;
		}
		
		for (; k > 0; k >>= 1) {
			if ((k & 1) == 1) {
				ret = mult(ret, p);
			}
			p = mult(p, p);
		}
		return ret;
	}

	Main() throws IOException {
		br = new BufferedReader(new InputStreamReader(System.in));
		out = new PrintWriter(System.out);
		solve();
		out.close();
	}

	public static void main(String[] args) throws IOException {
		new Main();
	}

	String nextToken() {
		while (st == null || !st.hasMoreTokens()) {
			try {
				st = new StringTokenizer(br.readLine());
			} catch (Exception e) {
				eof = true;
				return null;
			}
		}
		return st.nextToken();
	}

	String nextString() {
		try {
			return br.readLine();
		} catch (IOException e) {
			eof = true;
			return null;
		}
	}

	int nextInt() throws IOException {
		return Integer.parseInt(nextToken());
	}

	long nextLong() throws IOException {
		return Long.parseLong(nextToken());
	}

	double nextDouble() throws IOException {
		return Double.parseDouble(nextToken());
	}
}

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

int main() {

    int n;
    cin >> n;

    int *r = new int[n];
    int maxv = -2000000000;
    int minv = 1000000000;

    if (n == 2) {
        cin >> r[0] >> r[1];
        maxv = r[1] - r[0];
        cout << maxv << endl;
        return 0;
    }

    for (int i = 0; i < n; ++i) {
        cin >> r[i];
        maxv = max(maxv, r[i] - minv);
        minv = min(minv, r[i]);
    }

    cout << maxv << endl;

    delete[] r;
    return 0;
}

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

#define pb push_back
#define mp make_pair

#define mod 1000000007LL
#define IN freopen("input.txt","r",stdin)
#define OUT freopen("output.txt","w",stdout)
#define FOR(i,a,b) for(i=a ; i<=b ; i++)
#define DBG printf("Hi\n")
#define INF 2000000000000000000LL
#define i64 long long int
#define eps (1e-8)
#define xx first
#define yy second
#define ln 17
#define off 2
#define SZ(z) ((int)z.size())
#define sq(x) ((x)*(x))

#define FastIO ios_base::sync_with_stdio(false); cin.tie(NULL)

#define EPS 1e-7

// using namespace __gnu_pbds;
using namespace std ;

// typedef tree< i64, null_type, less<i64>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

#define maxn 200005

char s[maxn] ;

int main()
{
    int n ;
    scanf("%d",&n) ;
    scanf("%s",s) ;

    for(int i=0 ; i<2*n ; i++)
    {
        if( s[i]=='W' ) s[i] = 0 ;
        else s[i] = 1 ;

        s[i] ^= (i%2) ;
    }

    int ans = 1 ;
    for(int i=1 ; i<=n ; i++) ans= (1LL*ans*i)%mod ;

    int ocnt= 0 ;
    for(int i=0 ; i<2*n ; i++)
    {
        if( s[i]==1 ) ocnt++ ;
    }

    if(ocnt !=n)
    {
        printf("0\n") ;
        return 0 ;
    }

    int cnt = 0 ;

    for(int i=2*n-1 ; i>=0 ; i--)
    {
        if( s[i]==0 ) cnt++ ;
        else{
            ans = (1LL*ans*cnt)%mod ;
            cnt-- ;
        }
    }

    printf("%d\n",ans) ;

    return 0 ;
}


Measured memory_bytes: 384
#include<iostream>
#include<vector>
using namespace std;
int main()
{
	int N{}, x{};
	cin >> N >> x;
	vector<int>a(N);
	for (size_t i = 0;i < N;++i)
	{
		cin >> a.at(i);
	}
	long long oper = 0;
	for (size_t i = 0;i < N - 1;++i)
	{
		if (a.at(i) + a.at(i + 1) > x)
		{
			int d = a.at(i) + a.at(i + 1) - x;
			if (d <= a.at(i + 1))
			{
				a.at(i + 1) = a.at(i + 1) - d;
				oper += d;
			}
			else
			{
				a.at(i + 1) = 0;
				a.at(i) = a.at(i) - (d - a.at(i + 1));
				oper += d;
			}
		}
	}
	cout << oper << endl;
}

Measured memory_bytes: 888
from collections import defaultdict
from operator import mul
from functools import reduce

def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under

cnt = defaultdict(int)

N = int(input())

buff = []
for i in range(N):
    _b = list(input())
    _b.sort()
    cnt[''.join(_b)] += 1

ans = 0
for el in cnt:
    if cnt[el] > 1:
        ans += cmb(cnt[el], 2)
print(ans)

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

public class Main {

    public static void main(String[] args) throws Exception{

        FastReader fs = new FastReader();
        out = new PrintWriter(new BufferedOutputStream(System.out));

        int n = fs.nextInt();
        int m = fs.nextInt();
        int[] inp = new int[n];
        long sum = 0 ;
        for(int i=0 ; i<n ; i++){
            inp[i]=fs.nextInt();
            sum+=inp[i];
        }
long ans = n ;
        for(int i=0 ; i<n ; i++){
            long val = 4*m*inp[i];
            if(val<sum){
               ans--; 
            }
        }
        if(ans>=m){
            out.println("Yes");
        }else{
            out.println("No");
        }








        out.close();
    }
    //-----------PrintWriter for faster output---------------------------------
    public static PrintWriter out;

    //-----------MyScanner class for faster input----------
    public static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

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

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }

    }
    //--------------------------------------------------------
}


Measured memory_bytes: 21332
//abc165-D//

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

int main(){
    int n,m;
    cin >> n>>m;
    vector<int>h(n);
    vector<vector<int> >path(n,vector<int>(0));
    rep(i,n){
        cin>>h[i];
    }
    rep(i,m){
        int a,b;
        cin >>a>>b;
        path.at(a-1).push_back(b-1);
        path.at(b-1).push_back(a-1);
    }
    int ans =0;
    rep(i,n){
        int num = (int)path.at(i).size();
        if(num==0){
            ans++;
        }
        else{
        rep(j,num){
            int num1 =(int)(path.at(i).size());
            if(h[i]<=h[path[i][j]]){
                      break;
            }
            else if(j==num1-1){
                ans++;
                //cout << i <<endl;
            }
        }
        }
    }
    
    
    cout << ans <<endl;

}


Measured memory_bytes: 8800
#include <iostream>
#include <map>
#include <queue>
#include <cmath>
#include <vector>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
#pragma warning (disable: 4996)

long long N, K, A[1 << 18];
long long dp[309][309];

int main() {
	cin >> N >> K;
	for (int i = 1; i <= N; i++) cin >> A[i];
	for (int i = 0; i <= N + 1; i++) {
		for (int j = 0; j <= N + 1; j++) dp[i][j] = (1LL << 60);
	}

	dp[0][0] = 0;
	for (int i = 0; i <= N; i++) {
		for (int j = 0; j <= N; j++) {
			if (dp[i][j] == (1LL << 60)) continue;
			for (int k = i + 1; k <= N + 1; k++) {
				dp[k][j + 1] = min(dp[k][j + 1], dp[i][j] + abs(A[k] - A[i]));
			}
		}
	}

	cout << dp[N + 1][N - K + 1] / 2 << endl;
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <cstring>
#include <algorithm> // sort

#define REP(i, n) for (long long i = 0; i < (n); i++) 
typedef long long ll;
static const ll MOD = 1000000007;
static const ll INF = 1000000000000000000LL;
using namespace std;

int main(){
    string S;
    cin >> S;
    int a = S.size();

    cout << S[0]  << a - 2 << S[a-1] << endl;

    return 0;    

}



Measured memory_bytes: 256
#include <iostream>

#include <algorithm>

#define FLASH ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

#define int long long int

#define MAX 1e9

#define MIN -1e9

#define mod 1000000007

#define pb push_back

#define all(x) (x).begin(), (x).end()

#define debug(x) cerr<<#x<<'='<<(x)<<endl;

#define output(x) cout << ( x ? "YES" : "NO" ) << '\n' ;

#define mxn 100005

using namespace std;

void solve(){

    double n;

    cin>>n;

      if(n==0)

    cout<<1;

    else if(n==1)

    cout<<0;

}

int32_t main()

{

    FLASH

    int t = 1;

    //cin>>t;

    while(t--){

        solve();

        cout<<"\n";

    }

    return 0;

}

Measured memory_bytes: 3792
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
long long a[3];
int main() {
	cin >> a[0] >> a[1] >> a[2];
	sort(a, a + 3);
	if (a[0] % 2==0 || a[1] % 2==0 || a[2] % 2==0)cout << 0 << endl;
	else cout << a[0] * a[1] << endl;
}

Measured memory_bytes: 256
#pragma GCC optimize(2)
#include<bits/stdc++.h> 
using namespace std;
#define ll long long
#define endl "\n"
const int MAX=1e6+7;
const int mod=1e9+7;
const int inf=0x3f3f3f3f;

ll qpow(ll a, ll b, ll mod) {
	ll ans = 1;
	while (b) {
		if (b & 1) ans = (ans*a)%mod;
		a = (a*a)%mod;
		b >>= 1;
	}
	return ans;
}
int main(){
    ios_base::sync_with_stdio(0);cin.tie(0),cout.tie(0);
	ll n,ans=0;cin>>n;
	ans=qpow(10,n,mod)+qpow(8,n,mod)-2ll*qpow(9,n,mod);
	while(ans>mod)ans-=mod;
	while(ans<0)ans+=mod; 
	cout<<ans; 
   return 0;
} 

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

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

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

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

int main() {
  // 入力
  int D, N;
  cin >> D >> N;

  int diff = 1;
  if (D == 1) diff = 100;
  if (D == 2) diff = 10000;

  // 解答
  cout << (N == 100 ? diff * N + diff : diff * N) << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main () {
  int n;
  int m;
  cin >> n;
  cin >> m;
  while (n>0){
    int sn[n];
    int sm[m];
    int sumn = 0;
    int summ = 0;
    int min = 200;
    int x = 200;
    int y = 200;
    for (int i=0; i < n; i++){
      cin >> sn[i];
      sumn += sn[i];
    }
    for (int i=0; i < m; i++){
      cin >> sm[i];
      summ += sm[i];
    }
    for (int i=0; i < n; i++){
      for (int j=0; j < m; j++){
	int a = sumn - sn[i] + sm[j];
	int b = summ - sm[j] + sn[i];
	if (a==b && sn[i]+sm[j] < min){
	  min = sn[i]+sm[j];
	  x = i;
	  y = j;
	}
      }
    }
    if (x==200)
      cout << "-1" << endl;
    else{
      cout << sn[x] << " " << sm[y] << endl;
    }
    cin >> n;
    cin >> m;
  }
}

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

int main(){
  int N; cin >> N;
  vector<int> A(N);
  for(int i = 0; i <N; i++){
    cin >> A[i];
  }
  int max = *max_element(A.begin(), A.end());
  int count = 0;
  for(int i = 0; i < N; i++){
    if(A[i] == max){
      A[i] = 0;
      count++;
    }
  }
  int max1 = *max_element(A.begin(), A.end());
  
  for(int i = 0; i < N; i++){
    if(count == 1){
      if(A[i] == 0) cout << max1 << endl;
      else cout << max << endl;
    }
    if(count != 1) cout << max << endl;
  }
}

Measured memory_bytes: 2432
n=int(input())
a=[int(input()) for i in range(n)]
b=list(sorted(a))
dict={}
for i in range(n):
  dict.setdefault(b[i],i)
cnt=0

for i,v in enumerate(a):
  if abs(dict[v]-i)%2==1:
    cnt+=1
    

print(cnt//2)

Measured memory_bytes: 96744
#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, m;
    cin >> n >> m;
    vector<int> a(m), b(m), per(n);
    rep(i, m) cin >> a[i] >> b[i];
    rep(i, n) per[i] = i + 1;

    int ans = 0;
    do
    {
        if (per[0] != 1)
        {
            continue;
        }
        bool all_path = true;
        rep(i, n - 1)
        {
            bool ck = false;
            rep(j, m)
            {
                if ((per[i] == a[j] && per[i + 1] == b[j]) || (per[i + 1] == a[j] && per[i] == b[j]))
                {
                    ck = true;
                }
            }
            if (!ck)
            {
                all_path = false;
            }
        }
        if (all_path)
        {
            ans++;
        }
    } while (next_permutation(all(per)));

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


Measured memory_bytes: 3628
#include <iostream>
using namespace std;
int main()
{
	int a,ans{};
	int times;
	cin >> a >> times;
	for(times; 0<times; times--){
		int x;
		cin >> x;
		ans += x;
	}
	if(a-ans<0){
		cout << "-1" << "\n";
	}else{
		cout << a-ans << "\n";
	}
}



Measured memory_bytes: 3640
n = int(input())
s = list(input())
output = 0
count = 0

for i in range(1, n):
    x = set(s[0:i:])
    y = set(s[i::])
    count = 0
    for k in x:
        for l in y:
            if k == l:
                count += 1

    if count > output:
        output = count

print(output)


Measured memory_bytes: 3060
#include "iostream"
#include "vector"
#include "algorithm"
using namespace std;


vector <char> get_input() {
	string s;
	cin >> s;
	vector <char> x;
	x.push_back('\0');
	for (char i: s) {
		x.push_back(i);
	}
	return x;
}


int main() {
	// dp[i][j] = LCS of s[:i] & t[:j]
	// answer = dp[s][t]
	auto s = get_input(), t = get_input();
	vector < vector <int> > dp(s.size(), vector <int> (t.size(), 0));
	for (int i=1; i<s.size(); i++) {
		for (int j=1; j<t.size(); j++) {
			if (s[i] == t[j]) {
				// if characters match, add them
				// to LCS of strings without them
				dp[i][j] = dp[i-1][j-1] + 1;
			} else {
				// else, at least one of i, j is irrelevant
				// NOTE: we cannot say if both i & j are irrelevant
				dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
			}
		}
	}
	int i = s.size() - 1, j = t.size() - 1;
	string ans = "";
	while (i > 0 && j > 0) {
		if (s[i] == t[j]) {
			ans += s[i];
			i--; j--;
		} else if (dp[i-1][j] > dp[i][j-1]) {
			i--;
		} else {
			j--;
		}
	}
	reverse(ans.begin(), ans.end());
	cout << ans << endl;
}


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

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

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

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

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

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

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

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

// solution 
use std::cmp;
#[allow(unused_mut)]
#[allow(non_snake_case)]
fn main() {
    input! {
        N: usize,
        S: chars,
    }

    let mut prev = 0;
    let mut count = 0;
    let mut min = 0;
    for ind in 0..N {
        if S[ind] == '.' {
            count += 1;
        }
    }
    min = count;
    prev = count;

    for shiro_ind in 0..N {
        if S[shiro_ind] == '#' {
            count = prev + 1;
        } else {
            count = prev - 1;
        }
        min = cmp::min(min, count);
        prev = count;
    }

    println!("{}", min);
}



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

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> H(n);
  for (int& h : H)
    cin >> h;
  
  vector<bool> good(n, true);
  for (int i = 0; i < m; ++i) {
    int a, b;
    cin >> a >> b;
    --a;
    --b;
    if (H[a] <= H[b])
      good[a] = false;
    if (H[a] >= H[b])
      good[b] = false;
  }
  cout << count_if(good.begin(), good.end(), [](bool x) { return x; }) << "\n";

  return 0;
}


Measured memory_bytes: 3416
#include <bits/stdc++.h>
using namespace std;
int main(){


  int k;
  cin >> k ;
  int x = 7 % k;
  for(int i=1;i<=k;i++){
    if(x == 0){
      cout << i << endl;
      return 0;
    }
    x = (x*10+7)%k;
  }
  cout << -1 << endl;
  return 0;
  /*
  if(k % 2 == 0){
    cout << -1 << endl;
    return 0;
  }
  int n=7,count=1;
  while(1){
    if(n % k == 0){
      cout << count << endl;
      return 0;
    }else{
      n = (n*10 + 7 )% k;
      count++;
    }
  */
  }
  


Measured memory_bytes: 3572
#include "bits/stdc++.h"
using namespace std;

#define ASC(vec) vec.begin(), vec.end()		// 昇順ソート 例：sort(ASC(vec));
#define DESC(vec) vec.rbegin(), vec.rend()	// 降順ソート 例:sort(DESC(vec));
#define rep(i, n) for(int i = 0; i < n; i++)
#define Rep(i, n) for(int i = 1; i < n; i++)

const int mod = 1000000007;
const int inf = (int)1e9 + 7;
const long long INF = 1LL << 60;

using ii = pair<int, int>;
using ll = long long;
using vi = vector<int>;
using vd = vector<double>;
using vb = vector<bool>;
using vl = vector<ll>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
using vvb = vector<vector<bool>>;
using vii = vector<pair<int, int>>;

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }
ll LCM(ll a, ll b) { return (a * b) / GCD(a, b); }
int round_int(int a, int b) { return (a + (b - 1)) / b; }

// 素因数分解; 返り値は(素数, 乗数)のvector配列
vector<pair<ll, int>> factorize(ll n) {
	vector<pair<ll, int>> res;
	for (ll i = 2; i * i <= n; ++i) {
		if (n % i) continue;
		res.emplace_back(i, 0);
		while (n % i == 0) {
			n /= i;
			res.back().second++;
		}
	}
	if (n != 1) res.emplace_back(n, 1);
	return res;
}

constexpr array<int, 9> dx = { 0, 1, 0, -1, -1, 1, 1, -1, 0 };
constexpr array<int, 9> dy = { 1, 0, -1, 0, 1, 1, -1, -1, 0 };
constexpr auto MAX = 100010;

// ──────────────────────────────────────────────────────────────────────────────

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

	string t = "ACGT";
	int ans = 0;
	for (int i = 0; i < s.size(); ++i) {
		int cnt = 0;
		for (int j = i; j < s.size(); ++j) {
			bool flg = false;
			rep(k, 4) {
				if (s[j] == t[k]) flg = true;
			}

			if (flg) {
				cnt++;
			}
			else {
				break;
			}
		}
		ans = max(ans, cnt);
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
import math

N = int(input())
ans = [0] *(N+1)
a = int(math.sqrt(N)) + 1

for i in range(1,a) :
    for j in range(1,a) :
        for k in range(1,a) :
            n = i**2 + j**2 + k**2 + i*j + i*k + j*k
            if n <= N :
                ans[n] += 1

for m in range(N) :
    print(ans[m+1])




Measured memory_bytes: 9308
#define _CRT_SECURE_NO_WARNINGS

#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <vector>
#include <queue>
#include <set>
#include <map>

using namespace std;

#define N_MAX 200000

void solv()
{
	int N, K; scanf("%d%d", &N, &K);
	long long int A[N_MAX], S[N_MAX], sum = 0;
	for (int i = 0; i < N; i++){
		scanf("%lld", A + i);
		sum += A[i];
		S[i] = (sum - (i + 1)) % K;
	}

	long long int ret = 0;

	if (1 == N){
		if (1 == A[0] % K){
			ret = 1;
		}
		else{
			ret = 0;
		}
	}
	else{
		map<long long int,int> m;
		for (int i = 0; i < min(N, K); i++){
			if (m.end() == m.find(S[i])){
				m.insert(make_pair(S[i], 0));
			}
			m[S[i]]++;
		}

		for (int i = 0; i < N - 1; i++){
			ret += m[S[i]] - 1;
			if (i + 1 < K && 0 == S[i]){
				ret++;
			}

			m[S[i]]--;
			if (i + K < N){
				if (m.end() == m.find(S[i+K])){
					m.insert(make_pair(S[i+K], 0));
				}
				m[S[i+K]]++;
			}
		}

		if (N < K && 0 == S[N - 1]){
			ret++;
		}
	}



	printf("%lld", ret);

	return;
}

int main()
{
	FILE *fin = NULL, *fout = NULL;
	//fin = freopen("input.txt", "r", stdin);
	//fout = freopen("output.txt", "w", stdout);

	solv();

	//finalize
	if (NULL != fin) fclose(fin);
	if (NULL != fout) fclose(fout);

	return 0;
}

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

signed main(){

  int N,M,A,B; cin >> N >> M >> A >> B;
  vector<int> D(N);
  for(int i = 0; i < N; i++){
    cin >> D[i];
  }

  stack<int> s;
  for(int i = 0; i < N; i++){
    if(D[i] < A) break;
    s.push(D[i]);
  }
  if(N - s.size() >= M){
    cout << s.size() << endl;
    return 0;
  }

  for(int i = 0; !s.empty(); i++){
    if(s.top() > B) break;
    s.pop();
  }
  cout << s.size() << endl;

  return 0;
}



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

int main(void){
    int a, b, k, i;
    scanf("%d %d %d", &a, &b, &k);
    for(i=a; 1; i--){
        if(a%i==0&&b%i==0) k--;
        if(k==0){
            printf("%d", i);
            break;
        }
    }
}

Measured memory_bytes: 128