akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin >> n;
    string s;
    cin >> s;
    int ans = 0;
    int var = 0;
    set<char> b;
    for(int i = 0; i < n; i++){
       
    }
    for (int i = 0; i < n; i++)
    {
        set<char> a;
        int cnt = 0;
        map<char,int> c;
        for(int d = 0; d < n; d++){
            if(c[s[d]] == 0)
            c[s[d]]++;
        }
        for (int j = 0; j <= i; j++)
        {
            a.insert(s[j]);
        }
        for (int k = i + 1; k < n; k++)
        {
            if (a.count(s[k]) && c[s[k]] == 1){
                cnt++;
                c[s[k]]++;
            }
        }
        ans = max(cnt, ans);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(){
	int ah, am, as;
	int Ah, Am, As;
	int bh, bm, bs;
	int Bh, Bm, Bs;
	int ch, cm, cs;
	int Ch, Cm, Cs;
	int AH, AM, AS;
	int BH, BM, BS;
	int CH, CM, CS;
	scanf("%d%d%d%d%d%d", &ah, &am, &as, &Ah, &Am, &As);
	scanf("%d%d%d%d%d%d", &bh, &bm, &bs, &Bh, &Bm, &Bs);
	scanf("%d%d%d%d%d%d", &ch, &cm, &cs, &Ch, &Cm, &Cs);
	if(As>=as)
	{
		AS=As-as;
	}
	else
	{
		AS=As+60-as;
		Am=Am-1;
	}
	if(Am>=am)
	{
		AM=Am-am;
	}
	else
	{
		AM=Am+60-am;
		Ah=Ah-1;
	}
	AH=Ah-ah;
	if(Bs>=bs)
	{
		BS=Bs-bs;
	}
	else
	{
		BS=Bs+60-bs;
		Bm=Bm-1;
	}
	if(Bm>=bm)
	{
		BM=Bm-bm;
	}
	else
	{
		BM=Bm+60-bm;
		Bh=Bh-1;
	}
	BH=Bh-bh;
	if(Cs>=cs)
	{
		CS=Cs-cs;
	}
	else
	{
		CS=Cs+60-cs;
		Cm=Cm-1;
	}
	if(Cm>=cm)
	{
		CM=Cm-cm;
	}
	else
	{
		CM=Cm+60-cm;
		Ch=Ch-1;
	}
	CH=Ch-ch;
	printf("%d %d %d\n", AH, AM, AS);
	printf("%d %d %d\n", BH, BM, BS);
	printf("%d %d %d\n", CH, CM, CS);
	return 0;
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
#define IOS                                                                    \
  ios::sync_with_stdio(0);                                                     \
  cin.tie(0);                                                                  \
  cout.tie(0)
#define pb push_back
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
using namespace std;
using ll = long long;
using vi = vector<int>;
using pii = pair<ll, ll>;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;
ll bpow(ll b, ll p, ll m = 1000000007LL) {
  ll rt = 1;
  for (; p; p >>= 1, b = b * b % m)
    if (p & 1)
      rt = rt * b % m;
  return rt;
}
int main() {
  IOS;
  ll x, k, d;
  cin >> x >> k >> d;
  if (x == 0) {
    cout << (k % 2 == 0 ? 0 : d) << endl;
  } else if (x < 0) {
    ll cntmv = min(k, (-x) / d);
    x += cntmv * d;
    k -= cntmv;
    cout << (k % 2 == 0 ? -x : x + d) << endl;
  } else if (x > 0) {
    ll cntmv = min(k, x / d);
    x -= cntmv * d;
    k -= cntmv;
    cout << (k % 2 == 0 ? x : abs(x - d)) << endl;
  }
}


Measured memory_bytes: 3648
#include<bits/stdc++.h>
#define EM 100000000
using namespace std;
using LL = long long;
using P = pair<LL, LL>;
LL LINF = 1e18;
int INF = 1e9;
using vint = vector<int>;
using vLL = vector<LL>;

int main(){
    int N;
    cin >> N;
    vector<int> a(N+1);
    for(int i = 1;i <= N;i++)    cin >> a[i];
    vector<int> ans(N+1, 0);
    for(int i = N;i >= 1;i--){
        int cnt = 0;
        for(int j = 2*i;j <= N;j += i){cnt += ans[j];}
        ans[i] = abs(cnt%2-a[i]);
    }
    int ball = 0;
    for(int i = 1;i <= N;i++)   ball += ans[i];
    cout << ball << endl;
    for(int i = 1;i <= N;i++)   if(ans[i]) cout << i << endl;
}

Measured memory_bytes: 2432
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cassert>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <unordered_map>
#include <set>
#include <map>
#define INCANT cin.tie(0), cout.tie(0), ios::sync_with_stdio(0), cout << fixed << setprecision(20);
#define rep(i,n) for (int i=0; i<n;++i)
#define ALL(a)  (a).begin(),(a).end()
#define PI 3.14159265358979
typedef long long ll;
using namespace std;
const ll MOD = 1e9+7LL;
const int INF = 2e9;
ll t1,t2,a1,a2,b1,b2;

int main() {
  INCANT;
  cin >> t1 >> t2;
  cin >> a1 >> a2;
  cin >> b1 >> b2;
  ll diff1 = (b1-a1)*t1; // bがaに着けた差
  ll diff2 = (b2-a2)*t2;
  if (diff1+diff2==0) {
    cout << "infinity" << "\n";
    return 0;
  }
  if (!((diff1>0ll) ^ (diff1+diff2 >0ll))) {
    cout << 0 << "\n";
    return 0;
  }
  ll diff = abs(diff2)-abs(diff1);
  ll cnt = 1ll; // 初回から最初にt1+t2分経過するまでに1回カウントする
  cnt += 2*(abs(diff1)/abs(diff));
  if (abs(diff1)%diff==0) cnt--; // 最後に会う時は１サイクルのなかで1回しかない

  cout << cnt << "\n";
  return 0;
}

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

void solve() {
  int m1,d1,m2,d2;
  cin >> m1 >> d1 >> m2 >> d2;
  if (m1 != m2) cout << "1" << endl;
  else cout << "0" << endl;
}

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

Measured memory_bytes: 256
from collections import deque
S = list(input())
Q = int(input())

dq1 = deque(S)
dq2 = deque(S[::-1])
isReversed = False

for _ in range(Q):
    l = input().split()
    if l[0] == "1":
        isReversed = not isReversed
    else:
        s = l[2]
        if l[1]=="1":
            if isReversed:
                dq1.append(s)
                dq2.appendleft(s)
            else:
                dq1.appendleft(s)
                dq2.append(s)
        else:
            if isReversed:
                dq1.appendleft(s)
                dq2.append(s)
            else:
                dq1.append(s)
                dq2.appendleft(s)

print("".join(dq2 if isReversed else dq1))


Measured memory_bytes: 11876
#include<bits/stdc++.h>
using namespace std;
double dp[301][301][301];
int n,a,b,c;
void init(){
	cin>>n;
	for(int i=1;i<=n;++i)
	{
		int d;
		cin>>d;
		if(d==1)a++;
		if(d==2)b++;
		if(d==3)c++;
	}
	return ;
}
double dfs(int a,int b,int c)
{
	if(a==0&&b==0&&c==0)return 0;
	if(dp[a][b][c]!=0)return dp[a][b][c];
	double ans=1.0*n/(a+b+c);
	if(a)ans+=(1.0*a/(a+b+c))*dfs(a-1,b,c);
	if(b)ans+=(1.0*b/(a+b+c))*dfs(a+1,b-1,c);
	if(c)ans+=(1.0*c/(a+b+c))*dfs(a,b+1,c-1);
	return dp[a][b][c]=ans;
}
int main()
{
	init();
	dfs(a,b,c);
	printf("%.10lf",dp[a][b][c]);
}

Measured memory_bytes: 213248
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(),(x).end()
#define LL long long

using namespace std;

int main(){

    int n,K;cin>>n>>K;
    LL a[n];REP(i,n)cin>>a[i];

    LL sum[n+1];
    sum[0]=0;
    REP(i,n)sum[i+1]=sum[i]+a[i];

    LL plus[n+1];
    plus[0]=0;
    REP(i,n)plus[i+1]=plus[i]+(a[i]>0 ? a[i]: 0);

    LL ans=-10000000000LL;
    for(int i=0;i+K<=n;i++){
        ans = max(ans,max(sum[i+K]-sum[i],0LL)+ plus[n]-plus[i+K] + plus[i]-plus[0]);
    }
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 2560
#include<cstdio>
int main(){
    int a[100];
    int s,m=0;
    for(int i=0;i<100;i++){
        a[i]=0;
    }
    while(~scanf("%d",&s)){
        a[s-1]++;
        if(m<a[s-1]) m=a[s-1];
    }
    for(int i=0;i<100;i++){
        if(a[i]==m) printf("%d\n",i+1);
    }
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,x;
  cin >> n >> x;
  vector<int> L(n);
  for(int i = 0; i < n; i++)
    cin >> L.at(i);
  vector<int> D(n+1);
  D.at(0) = 0;
  int bound = 1;
  for(int i = 1; i < n+1; i++){
    D.at(i) = D.at(i-1) + L.at(i-1);
    if(D.at(i) <= x)
      bound += 1;
  }
  cout << bound << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cmath>
#include <iomanip>
#include <vector>
#include <map>
#include <cstring>
#include <algorithm>
using namespace std;

struct Coordinate{
    int row;
    int col;
};
Coordinate mov_dir[4] = {{1, 0}, {0, -1}, {-1, 0}, {0, 1}};
bool mat[11][10001], one[11];
int R, C, ans;

void dfs(int row, bool flag)
{
    if (row == 10) {
        return;
    }
    if (flag) {
        for (int j = 0; j < C; j++) {
            mat[row][j] = !mat[row][j];
        }
    }
    for (int i = 0; i < C; i++) {
        int cnt_o = 0, cnt_z = 0;
        for (int j = 0; j < R; j++) {
            if (mat[j][i] == 1) {
                cnt_o++;
            }
            else {
                cnt_z++;
            }
        } 
        if (cnt_z > cnt_o) {
            for (int j = 0; j < R; j++) {
                mat[j][i] = !mat[j][i];
            }
        }
    }
        int cnt = 0;
        for (int i = 0; i < R; i++) {
            for (int j = 0; j < C; j++) {
                if (mat[i][j]) {
                    cnt++;
                }
            }
        }
    if (ans < cnt) {
        ans = cnt;
    }    
    dfs(row + 1, true);
    dfs(row + 1, false);

}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    while (cin >> R >> C && !(R == 0 && C == 0)) {
        ans = -1;
        for (int i = 0; i < R; i++) {
            int cnt_o = 0, cnt_z = 0;
            for (int j = 0; j < C; j++) {
                cin >> mat[i][j];
            }    
        }
        dfs(0, true);
        dfs(0, false);

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



Measured memory_bytes: 3236
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

typedef long long ll;
typedef uint64_t ull;
typedef pair<int, int> P;
constexpr double PI = 3.1415926535897932;   // acos(-1)
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)

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

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

    ll ans = 0;
    int left = 0, right = 0;
    int XorSum = 0;
    while(right < n){
        // cerr << bitset<3>(XorSum) << ' ' << bitset<3>(XorSum ^ a[right]) << '\n';
        if((XorSum & a[right]) == 0){
            XorSum ^= a[right++];
            continue;
        }

        int len = right - left;
        ans += (ll)len * (len + 1) / 2;
        while((XorSum & a[right]) != 0){
            XorSum ^= a[left++];
        }
        len = right - left;
        ans -= (ll)len * (len + 1) / 2;
        XorSum ^= a[right++];

        // cerr << left << ' ' << right << ' ';
        // cerr << ans << endl;
    }

    int len = right - left;
    ans += (ll)len * (len + 1) / 2;
    
    cout << ans << endl;
}

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

using namespace std;
using ll = long long;

//container util
#define SORT(c) sort((c).begin(),(c).end())

//repetition
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//print
#define pv(val) cerr << #val << '=' << (val) << endl

const int INF = 1e9;

int main(void){

	int K; cin >> K;
	int A, B; cin >> A >> B;

	FOR(i,A, B+1){
		if(i % K == 0){
			cout << "OK" << endl;
			return 0;
		}

	}

	cout << "NG" << endl;

	return 0;

}


Measured memory_bytes: 3632
#include<iostream>
#include<string>
using namespace std;
int main()
{
	
	string s,t;
	cin >> s >> t;
	t = t.erase(t.size() - 1);
	if(s == t){
		cout << "Yes";
	}
	else{
		cout << "No";
	}
	return 0;
}

Measured memory_bytes: 3612
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define cinf(n,x) for(int i=0;i<(n);i++)cin>>x[i];
#define ft first
#define sc second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define mod 1000000007
using namespace std;
typedef long long ll;
template<class T> using V=vector<T>;
using Graph = vector<vector<int>>;
typedef unsigned long long ull;
using P=pair<ull,ull>;
typedef long double ldouble;
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; }

const ll INF=1e18;

int main(){
    ull n;
    cin>>n;
    ull k;
    cin>>k;
    V<ull> w(n),d(n);
    V<P> p(n);
    rep(i,n){
        cin>>w[i]>>d[i];
        p[i]=P(w[i],d[i]);
    }
    sort(all(p));
    ull left=-1,right=1e19;
    while(right-left>1){
        ull mid=(left+right)/2;
        ull cnt=0;
        rep(i,n){
            if(mid>=p[i].ft) cnt+=(mid-p[i].ft)/p[i].sc+1;
        }
        if(cnt>=k) right=mid;
        else left=mid;
    }
    cout<<right<<endl;
}
//ペナルティ出しても焦らない　ACできると信じろ！！！
/*
V,P(大文字)使用不可
乗算の際にオーバーフローに注意せよ！(適切にmodをとれ)
制約をよく読め！
(全探索できるなら全探索しろ)
stringの計算量(扱い)注意
コーナー注意！(特に数値が小さいものについては要検証)
N行出力のときは'\n'
*/

Measured memory_bytes: 3328
#include<bits/stdc++.h>
using namespace std;
string to_string(const string& s) {
	return '"' + s + '"';
}
string to_string(const bool b) {
	return (b ? "true" : "false");
}
string to_string(const char* s) {
	return to_string((string)s);
}
string to_string(const char c) {
	string s = "'";
	s += c;
	s += "'";
	return s;
}
template<class T, class U>
string to_string(const pair<T, U>& p) {
	string s = "(";
	s += to_string(p.first);
	s += ", ";
	s += to_string(p.second);
	s += ")";
	return s;
}
template<class T>
string to_string(const T& a) {
	bool first = true;
	string s = "{";
	for (const auto& x : a) {
		if(!first){
			s += ", ";
		}
		first = false;
		s += to_string(x);
	}
	s += "}";
	return s;
}
void debug_out() {cerr << '\n';}
template<class Head, class... Tail>
void debug_out(Head head, Tail... tail) {
	cerr << ' ' << to_string(head);
	debug_out(tail...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "] = ", debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif
using ll = long long;
using ld = long double;
const int mod = 1e9 + 7;
const int inf = 2e9;
const ll inf64 = 7e18l;
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(20);
	string s;
	cin >> s;
	int n = s.size();
	vector<int> cnt(2019);
	++cnt[0];
	int cur = 0;
	int answer = 0;
	int pw = 1;
	for (int i = n - 1; i >= 0; --i) {
		cur += pw * (s[i] - '0');
		cur %= 2019; 
		answer += cnt[cur];
		++cnt[cur];
		pw *= 10;
		pw %= 2019;
	}
	cout << answer << '\n';
 	return 0;
}


Measured memory_bytes: 3740
S=input()
N=len(S)
a=ord('a')
alpha=['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']
K=[[N]*(N+1) for i in range(26)]
for i in range(N-1,-1,-1):
    x=ord(S[i])-a
    for j in range(26):
        if j==x:
            K[j][i]=i
            continue
        K[j][i]=K[j][i+1]
dp=[0]*(N+2)
L=[0]*(N+2)
dp[N]=1
for i in range(N-1,-1,-1):
    c=0
    b=2*N
    for j in range(26):
        t=K[j][i]
        if b>dp[t+1]+1:
            b=dp[t+1]+1
            c=t+1
    dp[i]=b
    L[i]=c
X=dp[0]
t=0
ans=''
while X>1:
    t=L[t]
    ans+=S[t-1]
    X-=1
    #print(t,X,ans)
for j in range(26):
    if K[j][t] ==N:
        ans+=alpha[j]
        break
print(ans)




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

#define int long long
#define REP(i,a,n) for(int i=a;i<n;++i)
#define RUP(a,b) ((a+b-1)/(b))
#define endl "\n"
#define SORTG(v) sort(v.begin(),v.end(),greater<>())
#define SORT(v) sort(v.begin(),v.end())
#define ALL(v) (v).begin(),(v).end()
#define MOD 1000000007
#define INF LLONG_MAX/3

typedef long long ll;
typedef pair<int,int> Pii;
typedef tuple<int,int,int> Tiii;
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef vector<string> Vs;

template<class T> void chmax(T& a, T b) {if(a < b){a=b;}}
template<class T> void chmin(T& a, T b) {if(a > b){a=b;}}
template<class T> void YesNo(T& a) {if(a){cout << "Yes" << endl;}else{cout << "No" << endl;}}
template<class T> void YESNO(T& a) {if(a){cout << "YES" << endl;}else{cout << "NO" << endl;}}
void start(){cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);}

signed main(){start();
    int n,a,ans=0;
    cin>>n>>a;
    Vi x(n);
    REP(i,0,n) cin>>x[i];
    
    const int maxh=3000,maxw=60;
    vector<VVi> dp(maxh,VVi(maxw,Vi(maxw,0)));
    dp[0][0][0]=1;
    REP(k,0,n){
    REP(i,0,n){
        REP(j,0,maxh){
            if(dp[j][i][k]>0){
                dp[j][i+1][k] += dp[j][i][k];
                dp[j+x[i]][i+1][k+1] += dp[j][i][k];
            }
        }
    }
    }
    REP(i,1,n+1) ans += dp[i*a][n][i];
    cout<<ans<<endl;
    return 0;
}



Measured memory_bytes: 91776
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
const int mod=1e9+7;
const int N=1e6+10;
void read(int &a)
{
    a=0;int d=1;char ch;
    while(ch=getchar(),ch>'9'||ch<'0') if(ch=='-') d=-1;
    a=ch^48;
    while(ch=getchar(),ch>='0'&&ch<='9') a=(a<<3)+(a<<1)+(ch^48);
    a*=d;
}
void read(ll &a)
{
    a=0;int d=1;char ch;
    while(ch=getchar(),ch>'9'||ch<'0') if(ch=='-') d=-1;
    a=ch^48;
    while(ch=getchar(),ch>='0'&&ch<='9') a=(a<<3)+(a<<1)+(ch^48);
    a*=d;
}
int main()
{
    string s;
    cin>>s;
    int sum=0;
    for(int i=0;i<s.size();i++)
        sum+=s[i]^48;
    if(sum%9==0) puts("Yes");
    else puts("No");
    return 0;
}


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

int main(){

int A, B, C, ma, mi;
  cin >> A >> B >> C;
  
  ma = max({A, B, C});
  mi = min({A, B, C});
  if(A + B + C == ma * 2 + mi) cout << mi << endl;
  else cout << ma << endl;
  
  return 0;
  
}

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

int main() {
  int X;
  cin>>X;
  for(int l=X;l>0;l--){
  for(int i=1;i<=35;i++){
    for(int j=2;j<10;j++){
      int test=pow(i,j);
      if(test==l){
        cout<<l<< endl;
        return 0;
      }
    }
  }
  }
}

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

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

  int n;
  cin >> n;
  int h;
  int m = 0;
  int cnt = 0;
  for (int i = 0; i < n; i++) {
    cin >> h;
    if (h >= m) {
      cnt++;
      m = h;
    }
  }
  cout << cnt << '\n';
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; i++)
#define RFOR(i, a, n) for (ll i = (ll)n - 1; i >= (ll)a; i--)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) RFOR(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define bra(first, second) '(' << first << ',' << second << ')'
constexpr ll MOD = 1000000007;
//constexpr ll MOD = 998244353;
ll INF = 1001001001001001001;
long double EPS = 1e-9;
long double PI = 3.141592653589793238;
template <typename T>
void remove(std::vector<T> &vector, unsigned int index)
{
   vector.erase(vector.begin() + index);
}

using Graph = vector<vector<tuple<ll, ll, ll>>>;

// MOD確認

int main(){
   ll N;
   cin >> N;
   FOR(i,1,N+1){
      ll ans = 0;
      for(ll j = 1;j * j <= i;j++){
         for(ll k = j;j * j + k * k + j * k <= i;k++){
            for(ll l = k;j * j + k * k + l * l + j*k+k*l+l*j <= i;l++){
               if(j*j+k*k+l*l+j*k+k*l+l*j == i){
                  if(j != k && k != l) ans += 6;
                  else if(j == k && k == l) ans += 1;
                  else ans += 3;
               }
            }
         }
      }
      cout << ans << endl;
   }
}

Measured memory_bytes: 3564
/*betaでやろう*/
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <numeric>
#include <cstdio>
#include <cstdlib>
#include <iterator>
#include <cstring>

using namespace std;

typedef pair<int, int> P;
typedef long long ll;
#define PB push_back
#define rep(i, a) for(ll i = 0; i < a; i++)
#define all(v) v.begin(),v.end()
#define FF first
#define SS second
#define mp make_pair
#define INT int_64
const ll INF = 1e17;
const ll NEGA=-INF; 

int J[300];
int main() 
{ 
 int a,b;
 cin>>a>>b;
 if((a%2)*(b%2)) cout<<"Yes"<<endl;
 else cout<<"No"<<endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
const long long mod = 1000000007;


// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
};

void solve(long long K, std::string S){
    ll N = S.size();
    mint ans = mint(26).pow(N+K);
    combination com = combination(int(1e6)*2+5);
    for(ll i=0;i<N;i++){
        ans -=com(K+N,i)*(mint(25).pow(K+N-i));
    }
    cout << ans << endl;

}

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long K;
    scanf("%lld",&K);
    std::string S;
    std::cin >> S;
    solve(K, S);
    return 0;
}


Measured memory_bytes: 36760
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
const ll INF = 1LL << 60;

int main(){
    ll a, b, c;
    cin >> a >> b >> c;
    if(a%2==0 || b%2==0 || c%2==0){
        cout << 0 << endl;
        return 0;
    }
    else{
        ll big=max(max(a,b),c);
        if(big==a){
            cout << b*c << endl;
            return 0;
        }
        else if(big==b){
            cout << a*c << endl;
            return 0;            
        }
        else if(big==c){
            cout << a*b << endl;
            return 0;            
        }
    }
}

Measured memory_bytes: 3604
defmodule Main do
  def main do
    IO.gets("")
    |> String.trim()
    |> String.to_integer()
    |> solve()
    |> IO.puts()
  end

  @doc ~S"""
  Sove

  ## Examples

      iex> Main.solve(1900)
      100
      iex> Main.solve(3000)
      0

  """
  def solve(n) do
    1..10
    |> Enum.reduce_while(0, fn _, payment ->
      if payment < n, do: {:cont, payment + 1000}, else: {:halt, payment}
    end)
    |> Kernel.-(n)
  end
end

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

/* using */
using namespace std;

/* main constructor */
struct Fast
{
    Fast()
    {
        std::cin.tie(0);
        ios::sync_with_stdio(0);
        //cout << fixed << setprecision(12);
    }
} fast;

/* template */
template <class T>
bool chmax(T &a, const T &b) { return (a < b) ? (a = b, 1) : 0; }
template <class T>
bool chmin(T &a, const T &b) { return (b < a) ? (a = b, 1) : 0; }

/* define */
#define REP(i, x, n) for (int i = x; i < (int)(n); ++i)
#define RREP(i, x, n) for (int i = x - 1; i >= (int)(n); --i)
#define rep(i, n) REP(i, 0, n)
#define reps(i, n) REP(i, 1, n + 1)
#define rrep(i, n) RREP(i, n, 0)
#define each(i, n) for (auto &i : n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define eunique(x) \
    sort(all(x));  \
    (x).erase(unique(all(x)), (x).end())
#define int long long
#define mp make_pair
#define r0 return 0

/* function */
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a * b / gcd(a, b); }

/* const */
const int inf = 1e9 + 7;
const int dxl[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dyl[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dxs[4] = {1, 0, -1, 0};
const int dys[4] = {0, 1, 0, -1};

/* main */
signed main(void)
{
    vector<int> a(3);
    rep(i, 3)
    {
        cin>>a[i];
    }
    sort(all(a));
    cout << a[0] + a[1] << endl;
    return 0;
}


Measured memory_bytes: 764
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>

using namespace std;
typedef long long ll;

#define REP(i,n) for(ll i=0;i<ll(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<ll(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=b;i--)
#define ALL(x) x.begin(),x.end()
#define SIZE(x) ll(x.size())

#define INF 1000000000000 //10^12
#define MOD 1000000007 //10^9+7:合同式の法
 
int main(){
    string a,b;
    cin >> a >> b;

    if(a == "H"){
        if(b == "H"){
            cout << "H" << endl;
        }
        else{
            cout << "D" << endl;
        }
    }
    else{
        if(b == "D"){
            cout << "H" << endl;
        }
        else{
            cout << "D" << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 3572
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

public class Main{

	static List<Integer> primes = findPrimes(50021);

	private static List<Integer> findPrimes(int n){
		boolean[] isPrime = new boolean[n];
		Arrays.fill(isPrime, true);

		isPrime[0] = false;
		for(int i = 0; i < isPrime.length; i++){
			if(isPrime[i]){
				for(int j = 2; (i + 1) * j < isPrime.length; j++){
					isPrime[(i + 1) * j - 1] = false;
				}
			}
		}
		List<Integer> result = new ArrayList<Integer>();
		for(int i = 1 - 1; i < isPrime.length; i++)
			if(isPrime[i]){
				result.add(i + 1);
			}
		return result;
	}

	static int getPrimeLessThan(int n){
		int i;
		for(i = 0; i < primes.size(); i++){
			if(primes.get(i) >= n){
				break;
			}
		}
		return primes.get(i - 1);
	}

	static int getPrimeMoreThan(int n){
		int i;
		for(i = 0; i < primes.size(); i++){
			if(primes.get(i) > n){
				break;
			}
		}
		return primes.get(i);
	}

	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		while(sc.hasNextInt()){
			int n = sc.nextInt();
			System.out.println(getPrimeLessThan(n) + " " + getPrimeMoreThan(n));
		}
		sc.close();
		
	}
}

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

int main() {
	int n;
	cin >> n;
	vector <pair<pair<string,int>,int>> a;
	for (int i=0; i<n; i++){
		string s;
		int x;
		cin >> s >> x;
		a.push_back(make_pair(make_pair(s,100-x),i+1));
	}
	sort(a.begin(),a.end());
	for (int i=0; i<n; i++){
		cout << a[i].second << endl;
	}
	return 0;
}

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

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

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

	if(b/a<=c)
		cout<<b/a<<endl;
	else if(b/a>c)
		cout<<c<<endl;
	else
		cout<<0<<endl;

}

Measured memory_bytes: 256
#include <iostream>
#include <deque>

inline std::deque<int> create_integer_list(size_t count) {
	std::deque<int> lst(count);
	for (size_t i = 0; i < count; ++i) {
		std::cin >> lst.at(i);
	}
	return lst;
}

int main() {
	std::deque<int> antenna = create_integer_list(5);
	int k;
	std::cin >> k;
	bool result{ true };
	for (int i = 0; i < antenna.size(); ++i) {
		for (int j = 0; j < antenna.size(); ++j) {
			if (i != j) {
				if (abs(antenna.at(i) - antenna.at(j)) > k) {
					result = false;
				}
			}
		}
	}
	if (result) {
		std::cout << "Yay!" << std::endl;
	}else{
		std::cout << ":(" << std::endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cctype>
#include <cstdio>
#include <string>
#include <algorithm>
#include <vector>
#include <complex>
using namespace std;

char e[1000];

typedef long long ll;
typedef complex<ll> C;

inline bool valid(C x){
    ll t = max(abs(x.real()),abs(x.imag()));
    return t <= 10000;
}

class OverFlow {};

C expr(char* &p);
C term(char* &p);
C fact(char* &p);
C num(char* &p);

inline bool ispm(char c){
    return c=='+' || c=='-';
}
inline bool ispd(char c){
    return c=='*' || c=='/';
}

C num(char* &p){
    C res = 0;
    if(isdigit(*p) || *p == 'i'){
        ;
    }else{
        throw "num begin";
    }
    if(isdigit(*p)){
        while (isdigit(*p)){
            res*=10;
            res+=*p-'0';
            if(!valid(res)) throw OverFlow();
            p++;
        }
    }else{
        res = C(0,1);
        p++;
    }

    if(*p=='\0' || *p==')' || ispm(*p) || ispd(*p)){
        ;
    }else{
        throw "num end";
    }

    if(!valid(res)) throw OverFlow();
    return res;
}

C fact(char* & p){
    C res = 0;
    if(*p=='(' || isdigit(*p) || *p == 'i'){
        ;
    }else{
        throw "fact begin";
    }

    if(*p=='('){
        p++;
        res += expr(p);
        p++;
    }else if(isdigit(*p) || *p == 'i'){
        res += num(p);
    }
    if(*p=='\0' || *p==')' || ispm(*p) || ispd(*p)){
        ;
    }else{
        cout << p-e << endl;
        throw "fact end";
    }

    if(!valid(res)) throw OverFlow();
    return res;
}

C term(char* & p){
    C res;
    if(*p=='(' || isdigit(*p) || *p == 'i'){
        res = fact(p);
    }else{
        throw "term begin";
    }
    while(1){
        if(*p=='*'){
            p++;
            res *= fact(p);
        }else if(*p=='/'){
            p++;
            res /= fact(p);
        }else if(*p=='\0' || *p==')' || *p=='+' || *p=='-'){
            break;
        }else{
            throw "term end";
        }
        if(!valid(res)) throw OverFlow();
    }

    if(!valid(res)) throw OverFlow();
    return res;
}

C expr(char* & p){
    C res;
    if(*p=='(' || isdigit(*p) || *p == 'i'){
        res=term(p);
    }else{
        throw "exp begin";
    }

    while(1){
        if(*p=='+'){
            p++;
            res += term(p);
        }else if(*p=='-'){
            p++;
            res -= term(p);
        }else if(*p=='\0' || *p==')' || ispm(*p) || ispd(*p)){
            break;
        }else{
            throw "exp end";
        }
        if(!valid(res)) throw OverFlow();
    }

    return res;
}

void print(C c){
    int a=c.real(), b=c.imag();
    if(a==0 && b==0) cout << 0 << endl;
    else if(a==0) cout << b << "i" << endl;
    else if(b==0) cout << a <<endl;
    else if(b>0) cout << a << "+" << b << "i" << endl;
    else cout << a << b << "i" << endl;
}

int main(){
    while(cin>>e){
        try {
            char* p = e;
            print(expr(p));
        } catch(const OverFlow e){
            cout << "overflow" << endl;
        }
    }
}

Measured memory_bytes: 1252
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		int n = stdIn.nextInt();
		for(int i = 0; i < n; i++) {
			String a1 = stdIn.next();
			String a2 = stdIn.next();
			int b1 = toDec(a1);
			int b2 = toDec(a2);
			String ans = toMCXI(b1 + b2);
			
			System.out.println(ans);
		}
	}
	public static int toDec(String a) {
		int op = 1;
		int ans = 0;
		for(int i = 0; i < a.length(); i++) {
			if(a.charAt(i) == 'm') {
				ans += op * 1000;
				op = 1;
			}
			else if(a.charAt(i) == 'c') {
				ans += op * 100;
				op = 1;
			}
			else if(a.charAt(i) == 'x') { 
				ans += op * 10;
				op = 1;
			}
			else if(a.charAt(i) == 'i') {
				ans += op * 1;
				op = 1;
			}
			else {
				op = Integer.parseInt(String.valueOf(a.charAt(i)));
			}
		}
		return ans;
	}
	
	public static String toMCXI(int a) {
		String ans = "";
		if(a/1000 == 1) {
			ans += "m";
			a -= 1000;
		}
		if(a/1000 != 0){
			ans += a/1000+"m";
			a -= a/1000*1000;
		}
		if(a/100 == 1) {
			ans += "c";
			a -= 100;
		}
		if(a/100 != 0) {
			ans += a/100+"c";
			a -= a/100 * 100;
		}
		
		if(a / 10 == 1) {
			ans += "x";
			a -= 10;
		}
		if(a/10 != 0) {
			ans += a/10+"x";
			a -= a/10 * 10;
		}
		
		if(a == 1) {
			ans += "i";
			a -= 1;
		}
		if(a != 0) {
			ans += a+"i";
			a-= a;
		}
		
		return ans;
	}
}

Measured memory_bytes: 27412
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())

int main(){
  string s;
  int n,h;
  while(1){
    cin>>s;
    if (s=="-"){break;}
    cin>>n;
    rep(i,n){
      cin>>h;
      s = s.substr(h) + s.substr(0,h);
    }
    cout << s << endl;
  }
}


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

int main() {

    while (true) {
        int n; cin >> n;
        if (n == 0)
            break;
        rep(i, n) {
            int m, e, j; cin >> m >> e >> j;
            if (m == 100 || e == 100 || j == 100) {
                puts("A");
            }
            else if ((m+e)/2 >= 90) {
                puts("A");
            }
            else if ((m+e+j)/3 >= 80) {
                puts("A");
            }
            else if ((m+e+j)/3 >= 70) {
                puts("B");
            }
            else if ((m+e+j)/3 >= 50 && (m >= 80 || e >= 80)) {
                puts("B");
            }
            else {
                puts("C");
            }
        }
    }
}


Measured memory_bytes: 3024
#include  <iostream>
#include  <cstdlib>


int main(void)
{
	int N, M;

	std::cin >> N >> M;

	int a[M], b[M];
	int ans[N] = {0};

	for(int i = 0; i < M; i++){
		std::cin >> a[i] >> b[i];
		ans[a[i]-1]++;
		ans[b[i]-1]++;
	}

	for(int i = 0; i < N; i++)
		std::cout << ans[i] << std::endl;

	return EXIT_SUCCESS;
}


Measured memory_bytes: 256
#include <stdio.h>
 
int main(){
    int N,T,E,x[10000],first=0,i,num=-1,flg=0;
 
    scanf("%d%d%d" ,&N ,&T ,&E);
    for( i = 0 ; i < N ; i++ ){
	scanf("%d" ,&x[i]);
     
	first = x[i];
	if( flg == 0 ){
	    while( x[i] <= (T+E) ){
		if( (T-E) <= x[i] && x[i] <= (T+E) ){
		    num = i+1; flg = 1;
		}
		x[i] += first;
	    }
	}
    }
    printf("%d\n" ,num); 
    return 0;
}

Measured memory_bytes: 2748
import java.util.ArrayList;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		
		// テキスト入力
		Scanner sc = new Scanner(System.in);
		StringBuilder all_out = new StringBuilder();
		StringBuilder out= new StringBuilder();;

		while (true) {

			int height = sc.nextInt();
			int width = sc.nextInt();

			if (height == 0 && width == 0){
				break;
			}
			// #を出す処理
			// 行の数
			for (int h = 0; h < height; h++) {

				// 列の数
				for (int w = 0; w < width; w++) {
					out = out.append("#");
				}
				out = out.append("\n");
			}
			all_out = all_out.append(out+"\n");
			out.delete(0, out.length());
		}
		System.out.print(all_out);
	}
}

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

#define ld			long double
#define int         long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define x           first
#define y           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define MOD         1000000007
#define sd(t) 		scanf("%d",&(t))
#define rep(i,a,b)  for(int i=a;i<b;i++)
#define hii 		cout << "hii" << endl
#define okay 		cout << "okay" << endl
#define hey 		cout << "hey" << endl

template <class T> ostream& operator << (ostream &os, const vector<T> &v) { for (T i : v) os << i << ' '; return os; }
template <class T> ostream& operator << (ostream &os, const set<T> &v) { for (T i : v) os << i << ' '; return os; }
template <class T, class S> ostream& operator << (ostream &os, const pair<T, S> &v) { os << v.first << ' ' << v.second; return os; }
template <class T, class S> ostream& operator << (ostream &os, const unordered_map<T, S> &v) { for (auto i : v) os << '(' << i.first << "=>" << i.second << ')' << ' '; return os; } 
 
 
#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <class Arg1> void __f(const char* name, Arg1&& arg1) { cerr << name << " : " << arg1 << endl; }
    template <class Arg1, class... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args) {
        const char* sep = strchr(names + 1, ',');
        cerr.write(names, sep - names) << " : " << arg1 << "  ";
        __f(sep + 1, args...);
    }
#else
#define trace(...) 
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("avx2,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define _CRT_SECURE_NO_WARNINGS
#endif // ifndef ONLINE_JUDGE

void fast()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
} 

clock_t time_p=clock();
void starboy1299()
{
    time_p=clock()-time_p;
    cerr<<"Time Taken : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";
}

const int mod = 1e9+7;
const int N = 1e3+5;
const int inf = 1e18;

void solve()
{
    int a, b, n;
    cin >> a >> b >> n;
    int x = min(n, b-1);

    int val = (a*x)/b;

    cout << val << endl;
}			 	      		        

int32_t main(){
	fast();
    int t = 1;
    // cin>> t;
    for(int i=1; i<=t; i++){
    	// cout << "Case #" << i << ": ";
    	solve();
    }
    //starboy1299();
}

Measured memory_bytes: 3652
#include <iostream>
#include <unordered_set>
using namespace std;
int main()
{
  long long s;
  cin >> s;
  unordered_set<long long> U;
  U.insert(s);
  int m = 1;
  while(true) {
    if(s%2==0) s = s/2;
    else s = 3*s + 1;
    if(U.find(s)!=U.end()) break;
    U.insert(s);
    m++;
  }
  cout << m+1 << endl;
}

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

int main() {
	int n, sum = 0;
	cin >> n;
	string s = to_string(n);
	for (int i = 0; i < s.length(); i++) {
		sum += s[i] - '0';
	}

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
 
struct UnionFind {
  vector<int> d;
  UnionFind(int n): d(n,-1) {}
  int root(int x) {
    if (d[x] < 0) return x;
    return d[x] = root(d[x]);
  }
  bool unite(int x, int y) {
    x = root(x); y = root(y);
    if (x == y) return false;
    if (d[x] > d[y]) swap(x,y);
    d[x] += d[y];
    d[y] = x;
    return true;
  }
  bool same(int x, int y) { return root(x) == root(y);}
  int size(int x) { return -d[root(x)];}
};
 
int deg[100005];
vector<int> to[100005];
 
int main() {
  int n, m, k;
  cin >> n >> m >> k;
  UnionFind uf(n);
  rep(i,m) {
    int a, b;
    cin >> a >> b;
    --a; 
    --b;
    deg[a]++;
    deg[b]++;
    uf.unite(a,b);
  }
  rep(i,k) {
    int a, b;
    cin >> a >> b;
    --a; --b;
    to[a].push_back(b);
    to[b].push_back(a);
  }
  rep(i,n) {
    int ans = uf.size(i)-1-deg[i];
    for (int u : to[i]) {
      if (uf.same(i,u)) --ans;
    }
    printf("%d%c", ans, i==n-1?'\n':' ');
  }
  return 0;
}

Measured memory_bytes: 9132
import java.util.Scanner;

public class Main {
	final boolean DEBUG = false;
	class Node {
		int key;
		Node p, l, r;
		Node(int key) {
			this.key = key;
		}
		void insert(Node z) {
			Node y = null;
			Node x = this;
			while (x != null) {
				y = x;
				if (z.key < x.key)
					x = x.l;
				else
					x = x.r;
			}
			z.p = y;
			
			if (z.key < y.key)
				y.l = z;
			else
				y.r = z;
		}
		void print() {
			this.inorder();
			System.out.println();
			this.preorder();
			System.out.println();
		}
		void preorder() {
			System.out.print(" " + this.key);
			if (this.l != null)
				this.l.preorder();
			if (this.r != null)
				this.r.preorder();
		}
		void inorder() {
			if (this.l != null)
				this.l.inorder();
			System.out.print(" " + this.key);
			if (this.r != null)
				this.r.inorder();
		}
	}
	void run() {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		Node t = null;
		for (int i = 0; i < n; i++) {
			String inst = scan.next();
			// set a root node
			if (i == 0) {
				int key = scan.nextInt();
				t = new Node(key);
				continue;
			}
			
			switch(inst) {
			case "insert":
				int key = scan.nextInt();
				if (DEBUG)
					System.out.println("insert: " + key);
				t.insert(new Node(key));
				break;
			case "print":
				if (DEBUG)
					System.out.println("print");
				t.print();
				break;
			}
		}
	}
	public static void main(String[] args) {
		new Main().run();
	}
}



Measured memory_bytes: 224208
import java.io.BufferedReader;
import java.io.InputStreamReader;

import java.util.Arrays;
import java.util.Collections;
import java.util.ArrayList;
import java.util.List;
import java.util.HashSet;
import java.io.PrintWriter;
import java.io.OutputStream;

public class Main {
    // 標準入力
    static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

    // 標準入力数値配列用 int
    static int[] inputval() throws Exception {
        String[] strarray = br.readLine().trim().split(" ");
        int[] intarray = new int[strarray.length];
        for (int i = 0; i < intarray.length; i++) {
            intarray[i] = Integer.parseInt(strarray[i]);
        }
        return intarray;
    }

    // 標準入力数値配列用 integer ソート用
    static Integer[] inputvalInteger() throws Exception {
        String[] strarray = br.readLine().trim().split(" ");
        Integer[] intarray = new Integer[strarray.length];
        for (int i = 0; i < intarray.length; i++) {
            intarray[i] = Integer.parseInt(strarray[i]);
        }
        return intarray;
    }

    public static void main(String[] args) throws Exception {
        // write your code here
        String s = br.readLine().trim();

        System.out.println(s.substring(0,1) + (s.length()-2) + s.substring(s.length()-1));


    }

}



Measured memory_bytes: 37152
import sys
#import numpy as np
#from collections import defaultdict
import math
#from collections import deque




def main():
    N, K = map(int,input().split())
    R,S,P = map(int,input().split())
    T =  sys.stdin.readline().rstrip()
    tt =[0]*(N+ K)
    ans =0
#    d = deque()
    score = 0
    for i in range(N):
        current = T[i]
        if current == tt[i]:
            pass
        else:
            tt[i + K] = current
            if current == "r":
                ans +=P
            elif current =="s":
                ans +=R
            else:
                ans +=S
 #       print(ans)
    print(ans)





if __name__ == "__main__":
    main()

Measured memory_bytes: 10584
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cassert>
#include <iostream>
#include <cctype>
#include <sstream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <utility>
#include <numeric>
#include <algorithm>
#include <iterator>
#include <bitset>
#include <complex>
#include <fstream>
#include <iomanip>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T> T RoundOff(T a){ return int(a+.5-(a<0)); }
template<class T, class C> void chmax(T& a, C b){ if(a < b) a = b; }
template<class T, class C> void chmin(T& a, C b){ if(b < a) a = b; }
template<class T, class C> pair<T, C> mp(T a, C b){ return make_pair(a, b); }

int main()
{
	int n, m;

	while(cin >> n >> m && (n || m))
	{
		vint nv(n), mv(m);

		rep(i, n)
			cin >> nv[i];
		rep(i, m)
			cin >> mv[i];

		int sn = accumulate(ALL(nv), 0), sm = accumulate(ALL(mv), 0);


		rep(i, n) rep(j, m)
			if(sn - nv[i] + mv[j] == sm + nv[i] - mv[j])
			{
				cout << nv[i] << " " << mv[j] << endl;
				goto ng;
			}
		cout << -1 << endl;
ng:
		;

		/*
		// ±Ìp^[Í -1 mè
		if((sm - sn) % 2)
		{
			cout << -1 << endl;
			continue;
		}

		// K¸snÌÙ¤ª¬³­Èé
		bool flag = true;
		if(sm < sn)
		{
			swap(nv, mv);
			swap(sn, sm);
			flag = false;
		}

		// i ðìégÝí¹ª éÈç true
		vector<bool> dpn(sn + 1), dpm(sm + 1);
		fill(ALL(dpn), false); dpn[0] = true;
		fill(ALL(dpm), false); dpm[0] = true;

		// OvZ
		rep(i, n)
		{
			vector<bool> prv = dpn;
			REP(j, nv[i], sn + 1)
				dpn[j] = prv[j - nv[i]];
		}
		rep(i, m)
		{
			vector<bool> prv = dpm;
			REP(j, mv[i], sm + 1)
				dpm[j] = prv[j - mv[i]];
		}


		// taro ª hanako Én·J[hÌvðßÅ¿
		for(int i = 1; i <= sn; i++)
		{
			if(dpn[i] && dpm[(sm - sn) / 2 + i])
			{
				if(flag)cout << i << " " << (sm - sn) / 2 + i << endl;
				else	cout << (sm - sn) / 2 + i << " " << i << endl;
				break;
			}
			else if(i == sn)
			{
				cout << -1 << endl;
			}
		}
		*/
	}
}

Measured memory_bytes: 0
import Control.Monad
import Control.Applicative

solve :: Int -> Int -> Int -> Int
solve a b c = 
  if (c - (a - b)) < 0
    then 0
    else (c - (a - b))

main :: IO ()
main = do
  [a,b,c] <- map read . words <$> getLine
  print $ solve a b c

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

int main() {
  int64_t X;
  cin >> X;
  int64_t T = 100LL;
  int year = 0;
  
  while (T < X) {
    T = T * 1.01;
    year++;
  }
  cout << year << endl;
}

Measured memory_bytes: 3624
import sys
input=sys.stdin.readline

n,W=map(int,input().split())
items=[list(map(int,input().split())) for i in range(n)]
weight=[items[i][0] for i in range(n)]
value=[items[i][1] for i in range(n)]
import numpy as np

limit=sum(value)
inf=10**9
dp=np.array([[0]+[inf]*limit for i in range(n+1)])
#print(dp)
for i in range(n):
  w=weight[i]
  v=value[i]
  dp[i+1][:v]=dp[i][:v]
  dp[i+1][v:]=np.minimum(dp[i][v:],dp[i][:-v]+w)

ans=max([i for i in range(limit+1) if dp[n][i]<=W])
print(ans)
           

Measured memory_bytes: 170880
#include <stdio.h>
#include <cstdio>
int main(){
	int input[10000],i,j;
	i=0;
	do {
		scanf("%d",&input[i]);
		i++;
	}while (input[i-1]!=0);
	for(j=1;j<=i-1;j++){
		printf("Case %d: %d\n",j,input[j-1]);
	}
	return 0;
}


Measured memory_bytes: 2664
def modpow(x, y, mod)
    res = 1
    y.times do
        res *= x
        res %= mod
    end
    return res
end

MOD = 1000000007
n = gets.chomp.to_i
ans = modpow(10, n, MOD) - modpow(9, n, MOD) * 2 + modpow(8, n, MOD)
ans %= MOD
puts (ans+MOD) % MOD

Measured memory_bytes: 14360
use proconio::input;

use std::collections::HashSet;

fn main() {
    input! {
        n: i32,
        k: i32,
        a: [[i32]; k],
    }

    let main = (1..n + 1).collect::<HashSet<i32>>();
    let sub = a.concat().into_iter().collect::<HashSet<i32>>();

    println!("{}", main.difference(&sub).collect::<Vec<&i32>>().len());
}


Measured memory_bytes: 2248
#include <cstdio>
#include <cmath>
#include <iostream>
#include <set>
#include <algorithm>
#include <vector>
#include <map>
#include <cassert>
#include <string>
#include <cstring>
#include <queue>

using namespace std;

#define rep(i,a,b) for(int i = a; i < b; i++)
#define S(x) scanf("%d",&x)
#define S2(x,y) scanf("%d%d",&x,&y)
#define P(x) printf("%d\n",x)
#define all(v) v.begin(),v.end()
#define FF first
#define SS second

typedef long long int LL;
typedef pair<int, int > pii;
typedef vector<int > vi;

const int N = 200005;

int A[N], L[N], R[N];
vector<int > st;

int main() {
  int n;
  S(n);
  rep(i,1,n+1) S(A[i]);
  A[0] = A[n+1] = 0;
  st.push_back(0);
  rep(i,1,n+1) {
    while(A[st.back()] > A[i]) st.pop_back();
    L[i] = st.back();
    st.push_back(i);
  }

  st.clear();
  st.push_back(n+1);
  for(int i = n; i >= 1; i--) {
    while(A[st.back()] > A[i]) st.pop_back();
    R[i] = st.back();
    st.push_back(i);
  }

  // rep(i,1,n+1) printf("%d %d\n",i - L[i], R[i] - i);

  LL ans = 0;
  rep(i,1,n+1) {
    ans += (i - L[i]) * 1LL * (R[i] - i) * 1LL * A[i];
  }
  cout << ans << "\n";

  return 0;
}

Measured memory_bytes: 3576