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

#define fs first
#define sc second
#define pb emplace_back
#define mp make_pair
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)

using pii = pair<int, int>;
using vi = vector<int>;
using lint = long long;

const int inf = 1001001001;
const lint linf = 1001001001001001001ll;
const int mod = 1e9 + 7;
const int dx[]{0, 1, 0, -1, -1, -1, 1, 1, 0}, dy[]{1, 0, -1, 0, -1, 1, -1, 1, 0};

template<typename T> inline bool chmin(T &a, T b) { if (a > b) { a = b; } return a > b; }
template<typename T> inline bool chmax(T &a, T b) { if (a < b) { a = b; } return a < b; }
template<typename T> inline void print(const T &x, string s = "\n") { cout << x << s; }
template<typename T> inline void print(const vector<T> &v, string s = " ")
{ if (!v.size()) puts(""); rep(i, v.size()) cout << v[i] << (i + 1 == v.size() ? "\n" : s); }
inline bool inside(int y, int x, int H, int W) { return 0 <= y && y < H && 0 <= x && x < W; }
inline lint in() { lint x; std::cin>>x; return x; }

signed main() {
  lint h = in(), w = in(), n = in();
  map<pii, int> cnt;
  vector<pii> v;
  lint ans[10] = {0};

  rep(i, n) {
    int a = in(), b = in();
    rep(j, 9) {
      int y = a + dy[j] - 2;
      int x = b + dx[j] - 2;
      if (!inside(y, x, h - 2, w - 2)) continue;
      cnt[mp(y, x)]++;
      v.pb(mp(y, x));
    }
  }

  sort(all(v));
  v.erase(unique(all(v)), v.end());

  for (int i = 0; i < v.size(); ++i) {
    ans[cnt[v[i]]]++;
  }

  ans[0] = (h - 2) * (w - 2);
  for (int i = 1; i < 10; ++i) {
    ans[0] -= ans[i];
  }

  rep(i, 10) cout << ans[i] << endl;

}


Measured memory_bytes: 64232
#include <iostream>
#include <string>
#include<vector>
#include<algorithm>
#include<utility>
#include<queue>
#include<math.h>
#include<stack>
#include<set>
#include<map>
#define INF 2e9
#define rep(i,n,m) for(int i=n;i<m;i++)

using namespace std;

vector<long long int>Ans;
int main()
{
	int N, Q, x;
	cin >> N;
	long long int ans = 0;
	vector<long long int>a(100001, 0);

	rep(i, 0, N)
	{
		cin >> x;
		ans += x;
		a[x]++;
	}
	cin >> Q;
	while (Q--)
	{
		int b, c;
		cin >> b >> c;
		ans = ans - b * a[b] + c * a[b];
		a[c] += a[b];
		a[b] = 0;
		Ans.push_back(ans);
	}
	for (auto n : Ans)cout << n << endl;

	return 0;
}


Measured memory_bytes: 5080
#include<bits/stdc++.h>
using namespace std;
int n,k;
int maxx=0,len=0,lenn=0;
int a[100010];
int sum[1100001];
int weizhi[1000010];
string s;

int main(){
	scanf("%d %d",&n,&k);
	cin>>s;
	int ans=1;
	char now=s[0];
	s[s.size()]=s[s.size()-1]=='0'?'1':'0';
	for (int i=1;i<=s.size();i++){
	    if (s[i]!=now){
		    a[++len]=ans;
		    if (now!='0') maxx=max(maxx,ans);
		    ans=1;
			if (now=='0') weizhi[++lenn]=len;
			now=s[i];
			continue;
		}
		ans++;
	}
	if (lenn==0 || lenn<=k) {printf("%d",n);return 0;}
	if (k==0) {cout<<maxx;return 0;}
	for (int i=1;i<=len;i++)
	  sum[i]=sum[i-1]+a[i];
	sum[len+1]=sum[len];
//	for (int i=1;i<=len;i++) cout<<sum[i]<<' ';
//	cout<<endl;
//	for (int i=1;i<=lenn;i++) cout<<weizhi[i]<<' ';
//	cout<<endl;
    maxx=0;
	for (int i=k;i<=lenn;i++)
	  maxx=max(maxx,sum[weizhi[i]+1]-sum[weizhi[i-k]]);
	printf("%d",maxx);
	return 0;
}

Measured memory_bytes: 5120
#include<stdio.h>
#include<string.h>
int main(){
    int l,i;
    char s[32],r[32];
    scanf("%s",s);
    l=strlen(s);
    for(i=0;i<l;i++){
        r[l-i-1]=s[i];
    }
    for(i=0;i<l;i++){
        printf("%c",r[i]);
    }
    printf("\n");
    return 0;
}

Measured memory_bytes: 524
#include <bits/stdc++.h>
using namespace std;
 
int main() {
   int N;
   int n;
   cin >> N;
   n = N % 1000;
   
    if (N % 1111 == 0) {
        cout << "Yes" << endl;
    }
    else if ( 0 <= N % 1110 && N % 1110 <= 9){
        cout << "Yes" << endl;
    }
    else if ( n % 111 == 0) {
        cout << "Yes" << endl;
    }  
        
    else {
        cout << "No" << endl;
    }
}

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

int main() {
    int n;
    cin >> n;
    vector<pair<int,int>> p(n);
    for(int i = 0; i < n; i++){
        int a,b;
        cin >> a >> b;
        p.at(i) = make_pair(a,b);
    }
    sort(p.begin(),p.end());
    reverse(p.begin(), p.end());
    int answer = p.at(0).first + p.at(0).second;
    cout << answer;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define P pair<int,int>
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1000000000000000000
#define MOD 1000000007
#define all(v) v.begin(),v.end()
#define pb push_back
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
int kaijo[2000010];
int gcd(int a,int b){
    if(b==0)return a;
    return gcd(b,a%b);
}
int lcm(int a,int b){
    return a/gcd(a,b)*b;
}
bool prime(int a){
    if(a==1)return false;
    for(int i=2;i*i<=a;i++){
        if(a%i==0)return false;
    }
    return true;
}
void init_fact(){
    kaijo[0]=1;
    for(int i=1;i<=2000000;i++){
        kaijo[i]=kaijo[i-1]*i;
        kaijo[i]%=MOD;
    }
}
int modpow(int a,int b){
    if(b==0)return 1;
    if(b%2)return modpow(a,b-1)*a%MOD;
    int memo=modpow(a,b/2);
    return memo*memo%MOD;
}
int comb(int a,int b){
    if(!kaijo[0])init_fact();
    return kaijo[a]*modpow(kaijo[a-b],MOD-2)%MOD*modpow(kaijo[b],MOD-2)%MOD;
}
int inv(int x){
    x=modpow(x,MOD-2);
    return x;
}
bool kosa(double ax,double ay,double bx,double by,double cx,double cy,double dx,double dy){
    double ta=(cx-dx)*(ay-cy)+(cy-dy)*(cx-ax);
    double tb=(cx-dx)*(by-cy)+(cy-dy)*(cx-bx);
    double tc=(ax-bx)*(cy-ay)+(ay-by)*(ax-cx);
    double td=(ax-bx)*(dy-ay)+(ay-by)*(ax-dx);
    return tc*td<0&&ta*tb<0;
}
int n,ans;
string s;
signed main(){
    cin>>n>>s;
    rep(i,n-2){
        if(s.substr(i,3)=="ABC")ans++;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
from collections import deque
N=int(input())
G=[[]for _ in range(N)]
cnt=[0]*N
for i in range(N-1):
    a,b=map(int,input().split())
    a-=1
    b-=1
    G[a].append(b)
    G[b].append(a)
    cnt[a]+=1
    cnt[b]+=1

C=list(map(int,input().split()))
C.sort(reverse=True)

root=0
v=0
for i in range(N):
    if v>cnt[i]:
        root=i
        v=cnt[i]

def bfs(s):
    que=deque()
    que.append(s)
    nodes=[-1]*N
    k=0
    ans=0
    while len(que)>0:
        q=que.pop()
        nodes[q]=C[k]
        k+=1

        for v in G[q]:
            if nodes[v]<0:
                que.append(v)
    print(sum(C[1:]))
    print(*nodes)

bfs(root)

Measured memory_bytes: 6292
n, m = map(int, input().split())
a = []
b = []
for _ in range(n):
    ai, bi = map(int, input().split())
    a.append(ai)
    b.append(bi)
c = []
d = []
for _ in range(m):
    ci, di = map(int, input().split())
    c.append(ci)
    d.append(di)
ans = [float('inf')] * n
cnt = [float('inf')] * n

for i in range(n):
    for j in range(m):
        now = abs(a[i] - c[j]) + abs(b[i] - d[j])
        if cnt[i] > now:
            cnt[i] = now
            ans[i] = j + 1
print(*ans, sep='\n')

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
constexpr int maxn = 200;
constexpr int inf = 1000000001;
 
int dis[maxn][maxn];
int n, m, r;
vector<int> r_vector;
 
void floyd() {
	for (int k = 0; k < n; ++k)
		for (int i = 0; i < n; ++i)
			for (int j = 0; j < n; ++j)
				dis[i][j] = min(dis[i][j], dis[i][k] + dis[k][j]);
}
 
int main() {
	cin >> n >> m >> r;
	for (int i = 0, a; i < r; ++i) {
		cin >> a;
		r_vector.emplace_back(a - 1);
	}
	for (size_t i = 0; i < maxn; i++)
	{
		for (size_t j = 0; j < maxn; j++)
		{
			dis[i][j] = inf;
		}
	}
	for (int i = 0, a, b, c; i < m; ++i) {
		cin >> a >> b >> c;
		a--; b--;
		dis[a][b] = dis[b][a] = min({ dis[b][a], dis[a][b], c });
	}
	floyd();
	std::sort(r_vector.begin(), r_vector.end());
	int ans = inf;
	do {
		int tmp = 0;
		for (int i = 0; i < r_vector.size() - 1; ++i)
			tmp += dis[r_vector[i]][r_vector[i + 1]];
		ans = min(ans, tmp);
	} while (next_permutation(r_vector.begin(), r_vector.end()));
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 384
from __future__ import print_function

import sys
sys.setrecursionlimit(500000)

import re
import array
import copy
import functools
import operator

import math
import string
import fractions
from fractions import Fraction

import collections
import itertools
import bisect

import random
import time

import heapq
from heapq import heappush
from heapq import heappop
from heapq import heappushpop
from heapq import heapify
from heapq import heapreplace
from queue import PriorityQueue as pq
from queue import Queue

from itertools import accumulate

from collections import deque
from collections import Counter

from operator import mul
from functools import reduce

input = sys.stdin.readline


def eprint(*args, **kwargs):
    print(*args, file=sys.stderr, **kwargs)
    return

# from fractions import gcd
# from math import gcd

# def lcm(n, m):
#     return int(n * m / gcd(n, m))


# def coprimize(p, q):
#     common = gcd(p, q)
#     return (p // common, q // common)


# def find_gcd(list_l):
#     x = reduce(gcd, list_l)
#     return x


def combinations_count(n, r):
    r = min(r, n - r)
    numer = reduce(mul, range(n, n - r, -1), 1)
    denom = reduce(mul, range(1, r + 1), 1)
    return numer // denom


def main():
    S = input().strip()
    if S=="ABC":
        print("ARC")
    else:
        print("ABC")


if __name__ == '__main__':
    main()

Measured memory_bytes: 78376
#include <stdio.h>
#include <string.h>
typedef struct
{
    char str[10];
    int num;
}ball;

int main(void)
{
    ball s,t;
    char u[10];
    scanf("%s%s%d%d",s.str,t.str,&s.num,&t.num);
    scanf("%s",u);
    if(strcmp(s.str,u) == 0)
        s.num--;
    else if(strcmp(t.str,u) == 0)
        t.num--;
    
    printf("%d %d",s.num,t.num);
    return 0;
}

Measured memory_bytes: 128
from scipy.sparse import csr_matrix
from scipy.sparse.csgraph import dijkstra
from collections import defaultdict
h, w = map(int, input().split())
table = [list(map(int, input().split())) for _ in range(10)]
dd = defaultdict(int)
for _ in range(h):
    for x in map(int, input().split()):
        if x == -1:
            continue
        dd[x] += 1

trans_table = list(zip(*table))
scores = dijkstra(csr_matrix(trans_table), indices=1)
ans = 0
for k, v in dd.items():
    ans += int(scores[k])*v
print(ans)


Measured memory_bytes: 26700
import sys
n,w,h = map(int,input().split())
Yoko = []
Tate = []
for i in range(n):
    x,y,r = map(int,input().split())
    Yoko.append([x - r,x + r])
    Tate.append([y - r,y + r])
Yoko = sorted(Yoko)
Tate = sorted(Tate)

if Yoko[0][0] > 0 and Tate[0][0] > 0:
    print("No")
    sys.exit()

Yoko_han = [Yoko[0][0],Yoko[0][1]]
Tate_han = [Tate[0][0],Tate[0][1]]
if Yoko[0][0] <= 0:
    if Yoko_han[1] >= w:
        print("Yes")
        sys.exit()
    else:
        for j in range(1,len(Tate)):
            if Yoko[j][0] <= Yoko_han[1] and Yoko_han[1] < Yoko[j][1]:
                Yoko_han[1] = Yoko[j][1]
                if Yoko_han[1] >= w:
                    print("Yes")
                    sys.exit()
                
            elif Yoko_han[1] < Yoko[j][0]:
                break
if Tate[0][0] > 0:
    print("No")
    sys.exit()
else:
    if Tate_han[1] >= h:
            print("Yes")
            sys.exit()
    else:
        for k in range(1,len(Yoko)):
            if Tate[k][0] <= Tate_han[1] and Tate_han[1] < Tate[k][1]:
                Tate_han[1] = Tate[k][1]
                if Tate_han[1] >= h:
                    print("Yes")
                    sys.exit()
                
            elif Yoko_han[1] < Yoko[k][0]:
                print("No")
                sys.exit()
print("No")

Measured memory_bytes: 42012
#include <bits/stdc++.h>
#ifdef __DEBUG__
    #define DBG(X) cout << #X << " = " << (X) << endl;
    #define SAY(X) cout << (X) << endl;
#else
    #define DBG(X)
    #define SAY(X)
#endif

using namespace std;
using pii = pair<int, int>;

inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };

int N,M;
vector<vector<int>> G,revG;
vector<pii> Edge;
void input(){
    fast_io();
    cin >> N >> M;
    G.resize(N);
    revG.resize(N);
    for (int i = 0; i < M; i++)
    {
        int s,t; cin >> s >> t;
        s--,t--;
        Edge.emplace_back(s,t);
        G[s].push_back(t);
        revG[t].push_back(s);
    }
    for (int i = 0; i < N; i++)
    {
        sort(G[i].begin(),G[i].end(),greater<int>());
    }
    
}

void chmin(double &a, double b){if(a>b) a=b;}

int solve(){
    vector<double> dp(N,0);
    dp[N-1] = 0;
    for (int i = N-1; i >= 0; i--)
    {
        for(auto t:G[i]){
            dp[i] += (dp[t]+1)/G[i].size();
        }
    }
    double ans = dp[0];

    for (int i = N-1; i >= 0; i--)
    {
        if(G[i].size()<=1) continue;
        double dp_max = 0;
        int idx = 0;
        for(auto t:G[i]){
            if(dp[t] > dp_max){
                idx = t;
                dp_max = dp[t];
            }
        }
        vector<double> dp_i(N, 0);
        for (int s = N-1; s >= 0; s--)
        {
            for(auto t:G[s]){
                if(s==i && t==idx) continue;
                if(s==i) dp_i[s] += (dp_i[t]+1)/(G[s].size()-1);
                else dp_i[s] += (dp_i[t]+1)/(G[s].size());
            }
        }
        chmin(ans, dp_i[0]);
    }
    cout << fixed << setprecision(10) << ans << endl;
    return 0;
}

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

Measured memory_bytes: 7116
w[25],i;main(d){for(;i<9;i++){if(i&1)for(d=0;d<5;d++)getchar()-'0'?w[i/2*5+d]|=2,w[i/2*5+d+5]|=8:0;else for(d=0;d<4;d++)getchar()-'0'?w[i/2*5+d]|=1,w[i/2*5-~d]|=4:0;getchar();}d=!putchar(82);for(i=1;d|i;d&=3)w[i]&1<<d?i+="GKEA"[d]-70,putchar("RDLU"[d]),w[i]&1<<(d+3&3)&&--d:++d;i=!puts("");}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define ll long long
#define lf double
#define E complex<lf>
#define inf 0x3f3f3f3f
#define eps 1e-8
#define pa pair<int,int>
#define pb push_back
#define ms(x,y) memset(x,y,sizeof(x))
#define l(x) (x<<1)
#define r(x) (x<<1|1)
#define mod 1000000007
#define N
using namespace std;
inline ll read() {
	ll x=0,f=1;char c=getchar();
	while (c<'0'||c>'9') f=(c=='-')?-1:1,c=getchar();
	while (c>='0'&&c<='9') x=x*10+c-'0',c=getchar();
	return x*f;
}
ll n,x;
int main() {
	n=read(),x=read();
    ll a=x,b=n-x;
    if (a<b) swap(a,b);
    ll ans=n;
    while (b) {
        ll k=a/b;
        ans+=(2*k)*b;
        ll c=a%b;
        a=b,b=c;
    }
    ans-=a;
    cout << ans << endl;
}

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

int main(void){
	std::int64_t N;//,A,B;
	std::cin >> N;

	printf("ABC%ld\n",N);
	return 0;
}
	/*
	std::cin >> A;
	std::cin >> B;
	std::int64_t h[N+1];
	for(auto i = decltype(N)(1); i <= N; i++){
		std::cin >> h[i];
	}
	std::int64_t h_max=0;
	std::int64_t h_sum=0;
	for(auto i = decltype(N)(1); i <= N; i++){
		if(h[i] > h_max){
			h_max = h[i];
		}
		h_sum += h[i];
	}

	// ctr²ó¿ô¤ÎËâË¡¤ÇÁ´ÌÇ¤·¤Æ¤ë¤«
	auto func = [&](const std::int64_t ctr){
		if((h_sum - B*ctr*N - (A-B)*ctr )> 0 ){
			return false;
		}

		std::int64_t rem = ctr;
		std::int64_t tmp;
		for(auto i = decltype(N)(1); i <= N; i++){
			tmp = h[i] - B * ctr;
			if(tmp > 0){
				if(tmp%(A-B)==0){
					rem-= tmp/(A-B);
				}
				else{
					rem-= tmp/(A-B)+1;
				}
			}
			if(rem < 0){
				return false;
			}
		}
		if(rem >= 0){
			return true;
		}
		else{
			return false;
		}
	};



	std::int64_t hi = h_max/B;
	while(func(hi) != true){
		hi *= 2;
	}
	std::int64_t lo = 0;
	while((hi - lo) > 1){
		if(func((hi+lo)/2)){
			hi = (hi+lo)/2;
		}
		else{
			lo = (hi+lo)/2;
		}
	}

	std::cout << hi << std::endl;
	return 0;
	*/


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
long long n,test,p[4];
string s,st[4];
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);


    //cin>>test;
    test=1;
    st[0]="AC";
    st[1]="WA";
    st[2]="TLE";
    st[3]="RE";
    while (test--)
    {
        cin>>n;
        for (int i=1;i<=n;i++) { cin>>s;
        for (int i=0;i<4;i++) 
        if (s==st[i]) p[i]++;
        }
        for (int i=0;i<4;i++) cout<<st[i]<<" x "<<p[i]<<endl;
    }


 }

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

namespace B
{
    class Program
    {
        static void Main(string[] args)
        {
            var ab = Console.ReadLine().Split().Select(int.Parse).ToArray();
            var dist = Math.Abs(ab[0] - ab[1]);

            var list = new List<int>();
            for (int i = 0; i < 1000; i++)
            {
                if (i > 1) list.Add(i + list.Last());
                else list.Add(i);
            }

            var BHeight = list[dist];

            var ans = BHeight - ab[1];
            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 13396
N = int(input())
A = list(map(int,input().split()))

def gcd(x,y):
    c = x%y
    if c == 0:
        return y
    else:
        return gcd(y,c)
    
left = [0] * N
right = [0] * N
left[0] = A[0]
right[N-1] = A[N-1]

for i in range(1,N):
    left[i] = gcd(left[i-1],A[i])
for i in reversed(range(N-1)):
    right[i] = gcd(right[i+1],A[i])

ans = 0
for i in range(N):
    if i==0:
        ans = max(ans,right[i+1])
    elif i==N-1:
        ans = max(ans,left[i-1])
    else:
        ans = max(ans,gcd(left[i-1],right[i+1]))
    
print(ans)

Measured memory_bytes: 14428
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include <cmath>
#include <limits>
#include <utility>
#include <map>
#include <iomanip>
#include <queue>
#include <cctype>
#include <stack>


#define rep(p,q) for(int i = p;i < q;i++)
#define ll long long

using namespace std;

//128 C
int main(void) {
	int n, m;
	cin >> n >> m;
	vector<vector<int>> k = vector<vector<int>>(m);
	rep(0, m) {
		int kn;
		cin >> kn;
		for (int j = 0; j < kn; j++) {
			int s;
			cin >> s;
			k[i].push_back(s);
		}
		
	}
	vector<int>p = vector<int>(m);
	rep(0, m)cin >> p[i];

	int ans = 0;
	for (int i = 0b0; i < pow(2,n); i++) {

		vector<int>s = vector<int>(n);
		for(int j = 0; j < n; j++){
			if (i & (1 << j))s[j] = 1;
			else s[j] = 0;
		}
		
		bool isAns = true;
		for (int j = 0; j < m; j++) {
			int sum = 0;
			for (int t = 0; t < k[j].size(); t++) {
				sum += s[k[j][t] - 1];
			}

			if (sum % 2 != p[j]) {
				isAns = false;
				break;
			}
		}
		if (isAns)ans++;
	}

	cout << ans << endl;
}


Measured memory_bytes: 512
#include "iostream"
#include "vector"
#include "string"
#include "algorithm"
#include "stack"

using namespace std;
typedef long long ll;

int main()
{
  string s;
  cin >> s;
  ll size = s.size();
  ll count = 0;
  ll ans = 0;
  for (ll i = 0; i < size; i++)
  {
    if (s[i] == 'W')
    {
      count++;
      ans += i + 1 - count;
    }
  }
  cout << ans << "\n";
}

Measured memory_bytes: 640
public class Main {
	public static void main(String[] args){
		java.util.Scanner scan = new java.util.Scanner(System.in);
			int n = scan.nextInt();
			long min,max,sum = 0;
			long[] arr = new long[n];

			for(int i = 0;i < n;i++){
				arr[i] = scan.nextInt();
			}

			min = arr[0];
			max = arr[0];

			for(int i = 0; i < arr.length; i++){
				if(min > arr[i]){
					min = arr[i];
				}
				if(max < arr[i]){
					max = arr[i];
				}
			}
			for(int i = 0; i < arr.length; i++){
				sum += arr[i];
			}
			System.out.println(min + " " + max + " " + sum);

	}

}

Measured memory_bytes: 41424
#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>
#include <cstring>
using namespace std;

using ll = long long;
using P = pair<int, int>;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

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

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

    int T;
    cin >> T;
    auto calc = [&](vector<P>& data) -> ll {
        ll res = 0;
        int n = data.size();
        vector<vector<int>> table(n + 1);
        for(int i = 0; i < n; ++i){
            int k = data[i].first, val = data[i].second;
            chmin(k, n);
            table[k].emplace_back(val);
        }
        priority_queue<int> que;
        for(int i = n; i >= 1; --i){
            for(int x : table[i])   que.emplace(x);
            if(!que.empty()){
                res += que.top();
                que.pop();
            }
        }
        return res;
    };
    for(int loop = 0; loop < T; ++loop){
        int N;
        cin >> N;
        vector<P> NL, NR;
        ll ans = 0;
        for(int i = 0; i < N; ++i){
            int K, L, R;
            cin >> K >> L >> R;
            int X = min(L, R);
            ans += X;
            L -= X, R -= X;
            if(L > 0)   NL.emplace_back(K, L);
            else    NR.emplace_back(N - K, R);
        }
        ans += calc(NL);
        ans += calc(NR);
        cout << ans << '\n';
    }
}

Measured memory_bytes: 9704
# n, m, l = map(int, input().split())

# list_n = list(map(int, input().split()))

# n = input()
# list = [input() for i in range(N)

# list = [[i for i in range(N)] for _ in range(M)]

import sys
input = sys.stdin.readline

S = list(input().rstrip('\n'))
T = list(input().rstrip('\n'))

n = len(S)
for i in range(n):
    SS = S[i:] + S[:i]
    if SS == T:
        print("Yes")
        exit()
print("No")


Measured memory_bytes: 9072
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <string>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;

int main() {
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    cout << n * (n + 1) / 2;
}


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

typedef long long ll;

#define INF 10e10
#define rep(i,n) for(int i=0; i<n; i++)
#define rep_r(i,n,m) for(int i=m; i<n; i++)
#define MAX 10000

ll N;
std::vector<ll> v;

int main() {
  cin >> N;
  rep(i,N) {
    ll temp;
    scanf("%lld", &temp);
    if (!(temp % 2)) v.push_back(temp);
  }

  ll ans = 0;

  for (auto itr = v.begin(); itr != v.end(); ++itr) {
    ll tar = *itr;
    while (tar % 2 == 0) {
      tar /= 2;
      ans++;
    }
  }

  cout << ans << endl;
}


Measured memory_bytes: 512
#include <stdio.h>

int main(void)
{
	int x1,x2,kyori;
	scanf("%d %d",&x1,&x2);
	if(x1>x2)
		kyori=x1-x2;
	else{
		kyori=x2-x1;
	}
	printf("%d\n",kyori);
	return 0;
}


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

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

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

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

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

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

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

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

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

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

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

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

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

test! {
r#""# => r#""#,
}

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

    if a >= 10 || b >= 10 {
        -1
    } else {
        (a * b) as isize
    }.to_string()
}

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

int main() {
    string S;
    cin >> S;
    deque<char> dS(S.size());
    for (int i = 0; i < S.size(); ++i) dS[i] = S[i];

    int Q; cin >> Q;
    int rev = 0;
    for (int i = 0; i < Q; ++i) {
        int type; cin >> type;
        if (type == 2) {
            int f; char c;
            cin >> f >> c; --f;
            if (rev) f = 1 - f; // 反転状態だったら、フラグを反転
            if (f == 0) dS.push_front(c);
            else dS.push_back(c);
        }
        else rev = 1 - rev;
    }
    if (rev) reverse(dS.begin(), dS.end());
    for (auto c : dS) cout << c;
    cout << endl;
}

Measured memory_bytes: 896
//#include <tourist>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <string>
#include <iomanip>
#include <limits>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <list>
#include <queue>
#include <tuple>
#include <deque>
#include <algorithm>
#include <numeric>
#include <iomanip>
#include <utility>
#include <complex>
#include <functional>
using namespace std;
const int MOD = 1000000007;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = (1 << 28);
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
//setprecision(15)有効数字15桁
//-std=c++14
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);
}
struct edge {
    int to, cost;
};
int n, b, c;
vector<int> a;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
  string s, t;
    cin >> s>>t;
	int ans = 0;
    for (int i = 0; i < 3; i++)
    {
        if(s[i]==t[i])ans++;
    }
    cout << ans << "\n";
}



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

def f(b,n):
    if n//b==0:
        return n
    else:
        return n%b + f(b,n//b)

ans = -1
if S==N:
    ans = N+1
else:
    for b in range(2,int(N**.5)+1):
        if f(b,N)==S:
            ans = b
            break

if ans == -1:
    for i in range(int(N**.5)+1,0,-1):
        b = (N-S)//i + 1
        if b>1:
            if f(b,N)==S:
                ans = b
                break

print(ans)


Measured memory_bytes: 3064
#include<stdio.h>
int main()
{
    int a,b,c,d=0,i;

    scanf("%d%d%d",&a,&b,&c);
    for(i = a;i <= b;i++)
    {
        if(c%i==0)
        {
            d++;
        }
    }
    printf("%d\n",d);
    return 0;
}

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

using namespace std;

int main() {
    int N;
    cin >> N;
    string s, t;
    cin >> s >> t;

    int cnt = N * 2;
    for (int i = 1; i <= N; ++i) {
        string ss = s.substr(N-i,i);
        string tt = t.substr(0,i);
        if (ss == tt) cnt = N*2-i;
    }

    cout << cnt << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
bool cards[4][13];
int main(){
      //ここにプログラムを書いていく
	char type;
	int a,b;
	cin>>a;
	for(int c=0;c<a;c++){
		cin>>type>>b;
		if(type=='S'){
			cards[0][b-1]=true;
		}else if(type=='H'){
			cards[1][b-1]=true;
		}else if(type=='C'){
			cards[2][b-1]=true;
		}else if(type=='D'){
			cards[3][b-1]=true;
		}
	}
	for(int c=0;c<13;c++){
		if(cards[0][c]==false){
			cout<<"S "<<c+1<<endl;
		}
	}
	for(int c=0;c<13;c++){
		if(cards[1][c]==false){
			cout<<"H "<<c+1<<endl;
		}
	}
	for(int c=0;c<13;c++){
		if(cards[2][c]==false){
			cout<<"C "<<c+1<<endl;
		}
	}
	for(int c=0;c<13;c++){
		if(cards[3][c]==false){
			cout<<"D "<<c+1<<endl;
		}
	}

}



Measured memory_bytes: 3084
#include <iostream>
#include <stdio.h>
#include <string>
#include <math.h>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cassert>
#include <utility>
#include <numeric>
#include <cstring>
#include <map>
#include <set>
#define rep(i,n) for (int i=0; i<(n); ++i)

using namespace std;
using ll = long long;

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

    int d[N];
    for (int i=0;i<N;i++){
        cin >> d[i];
    }
    int sum = 0;
    for (int i=0;i<N;i++){
        for (int j=i+1;j<N;j++){
            // cout << d[i] * d[j] << endl;
            sum += d[i] * d[j];
        }
    }
    cout << sum;

}

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

#define REP(i, n) for(int i=0; i<int(n); ++i)
using ll = long long;


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

	std::vector<int> a(n);
	REP(i, n) std::cin >> a[i];

	REP(i, n) {
		a[i] -= i;
	}

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

	ll b = a[n / 2];

	ll ans = 0;
	REP(i, n) {
		ans += std::abs(b - a[i]);
	}
	std::cout << ans << std::endl;
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ul unsigned long int
#define ld long double
#define f(t) for(ll i =0;i<t;i++)
#define vi vector<int>
#define vl vector<ll>
#define pri pair<int,int>
#define mpi map<int,int>
#define prl pair<ll,ll>
#define mp make_pair
#define mpl map<ll,ll>
#define umpl unordered_map<ll,ll>
#define pb push_back
#define ff first
#define ss second
#define MOD 1000000007
#define inf 2e18
#define EPS 1e-3
#define PI 3.1415926535897932385
#define display(v) f(v.size())cout << v[i]<<" "
const double h = 1e-6;
const int MAX_  = 100005;
#define all(v) v.begin(),v.end()

inline ll mul(ll a, ll b){ return (a * 1ll * b) % MOD; }
inline ll sub(ll a, ll b){ ll c = a - b; if(c < 0) c += MOD; return c; }
inline ll add(ll a, ll b){ ll c = a + b; if(c > MOD) c -= MOD; return c; }
 //////////////////////*********CODE***********/////////////////////
 //////////////////////////////////////////////////////////////////


int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  string s;  cin>>s;
  if(s[0] == '7' || s[1] == '7' || s[2] == '7')cout << "Yes";
  else cout << "No";
  
  return 0;
 }

Measured memory_bytes: 3668
abcd = input()
a = int(abcd[0])
b = int(abcd[1])
c = int(abcd[2])
d = int(abcd[3])
if a+b+c+d == 7:
    print('{0}+{1}+{2}+{3}=7'.format(a, b, c, d))
elif a+b+c-d == 7:
    print('{0}+{1}+{2}-{3}=7'.format(a, b, c, d))
elif a+b-c+d == 7:
    print('{0}+{1}-{2}+{3}=7'.format(a, b, c, d))
elif a+b-c-d == 7:
    print('{0}+{1}-{2}-{3}=7'.format(a, b, c, d))
elif a-b-c-d == 7:
    print('{0}-{1}-{2}-{3}=7'.format(a, b, c, d))
elif a-b-c+d == 7:
    print('{0}-{1}-{2}+{3}=7'.format(a, b, c, d))
elif a-b+c-d == 7:
    print('{0}-{1}+{2}-{3}=7'.format(a, b, c, d))
else:
    print('{0}-{1}+{2}+{3}=7'.format(a, b, c, d))


Measured memory_bytes: 3064
import numpy as np
N = int(input())
S = input()

res = 0
for i in range(N-2):
    n = 1
    while True:
        j = i+n
        k = j+n
        if k > N-1: break
        res += (S[i] != S[j] and S[j] != S[k] and S[k] != S[i])
        n += 1
    
    
rgb = S.count("R") * S.count("G") * S.count("B")
print(rgb - res)


Measured memory_bytes: 27148
import math

while True:
    n = int(input())
    if not n:
        break
    l = list(map(int, input().split()))
    m = sum(l) / n
    count = 0
    for i in range(n):
        diff = (l[i] - m)
        count += diff ** 2
    ans = math.sqrt(count / n)
    print(ans)


Measured memory_bytes: 5700
N = int(input())
S = str(input())

cusum_e = [0] * (N+1)
cusum_w = [0] * (N+1)
for i in range(N):
  cusum_e[i+1] = cusum_e[i]
  cusum_w[i+1] = cusum_w[i]
  if S[i] == 'E':
    cusum_e[i+1] += 1
  else:
    cusum_w[i+1] += 1

ans = 1e9
for i in range(N):
  turn_w = cusum_w[i]
  turn_e = cusum_e[N] - cusum_e[i+1]
  ans = min(ans, turn_w + turn_e)
  #print(i, turn_w, turn_e)

print(ans)

Measured memory_bytes: 17568
#include <cstdio>
#include <cmath>
#include <algorithm>

using namespace std ;

int a[ 100007 ] ;
int h[ 100007 ] ;

int main( void ) {
        int n, k ;
        scanf( "%d %d", &n, &k ) ;
        for( int i = 0 ; i < n ; ++i ) {
                int h1, a1 ;
                scanf( "%d", &h1 ) ;
                h[ i ] = h1 ;
                a1 = i?1000000007:0 ;
                for( int j = max( 0, i - k ); j < i ; ++j ) {
                        a1 = min( a1, a[ j ] + abs( h1 - h[ j ] ) ) ;
                }
                a[ i ] = a1 ;
        }

        printf( "%d\n", a[ n - 1 ] ) ;
        return 0 ;
}


Measured memory_bytes: 896
#include <iostream>

int main(void) {
  std::string cards;

  std::cin >> cards;

  while (!((cards.size() == 1) && (cards[0] == '-'))) {
    int m = 0;

    std::cin >> m;

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

      cards = cards.substr(h) + cards.substr(0, h);
    }

    std::cout << cards << std::endl;
    
    std::cin >> cards;
  }
  
  return 0;
}

Measured memory_bytes: 1212
import java.util.Scanner;
public class Main {
	static Scanner scan=new Scanner(System.in);
	static int gcd (int a, int b) {return b>0?gcd(b,a%b):a;}
	static long lcm (int a, int b) {return a*b/gcd(a,b);}
	static int max(int a,int b) {return a>b?a:b;}
	static int min(int a,int b) {return a<b?a:b;}
	static long factorial(int i) {return i==1?1:i*factorial(i-1);}
	static int lower_bound(int a[],int key) {
		int low=0,high=a.length;
		while(low<high) {
			int mid=((high-low)/2)+low;
			if(a[mid]<=key)low=mid+1;
			else high=mid;
		}
		return high;
		}
	static int upper_bound(int a[],int key) {
		int low=0,high=a.length;
		while(low<high) {
			int mid=((high-low)/2)+low;
			if(a[mid]<key)low=mid+1;
			else high=mid;
		}
		return high;
		}
	static boolean isPrime (int n) {
		if (n==2) return true;
		if (n<2 || n%2==0) return false;
		double d = Math.sqrt(n);
		for (int i=3; i<=d; i+=2)if(n%i==0){return false;}
		return true;
	}
		public static void main(String[] args) {
			int a=scan.nextInt();
			int b[]=new int[a+1];
			int c[]=new int[a];
			for(int i=0;i<a+1;i++) {
				b[i]=scan.nextInt();
			}
			for(int i=0;i<a;i++) {
				c[i]=scan.nextInt();
			}
			long kill=0;
			for(int i=0;i<a;i++) {
				if(b[i]<c[i]) {
					kill+=b[i];
					c[i]-=b[i];
					b[i]=0;
				}
				else {
					kill+=c[i];
					b[i]-=c[i];
					c[i]=0;
				}
				if(b[i+1]<c[i]) {
					kill+=b[i+1];
					b[i+1]=0;
				}
				else {
					b[i+1]-=c[i];
					kill+=c[i];
				}
			}
			System.out.println(kill);
		}
}


Measured memory_bytes: 64916
import java.util.*;
import java.io.*;
import java.math.*;
 
public class Main
{
    public static void process()throws IOException
    {
        int a=ni();
        pn(a+a*a+a*a*a); 
    }
 
 
    static FastReader sc;
    static PrintWriter out;
    public static void main(String[]args)throws IOException
    {
        out = new PrintWriter(System.out);
        sc=new FastReader();
 
        long s = System.currentTimeMillis();
        int t=1;
        //t=ni();
        while(t-->0)
            process();
 
        out.flush();
        System.err.println(System.currentTimeMillis()-s+"ms");
    }
    
    
    static void pn(Object o){out.println(o);}
    static void p(Object o){out.print(o);}
    static int ni()throws IOException{return Integer.parseInt(sc.next());}
    static long nl()throws IOException{return Long.parseLong(sc.next());}
    static double nd()throws IOException{return Double.parseDouble(sc.next());}
    static String nln()throws IOException{return sc.nextLine();}
    static long gcd(long a, long b)throws IOException{return (b==0)?a:gcd(b,a%b);}
    static int gcd(int a, int b)throws IOException{return (b==0)?a:gcd(b,a%b);}
    static int bit(long n)throws IOException{return (n==0)?0:(1+bit(n&(n-1)));}
    
    static long mod=(long)1e9+7l;
    
/////////////////////////////////////////////////////////////////////////////////////////////////////////
    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(); 
        } 
  
        String nextLine(){ 
            String str = ""; 
            try{ str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } 
            return str; 
        } 
    } 
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
}

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

int main(){
  long long N,M,ans=0,cnt=0;
  cin >> N >> M;
  vector<pair<long long,long long>> vec(N);
  for(long long i=0;i<N;i++){
    cin >> vec[i].first >> vec[i].second;
  }
  sort(vec.begin(),vec.end());
  for(long long j=0;j<N;j++){
    ans+=vec[j].first*vec[j].second;
    cnt+=vec[j].second;
    if(cnt>=M){
      ans-=vec[j].first*(cnt-M);
      break;
    }
  }
    cout << ans << endl;
}

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

int main () {
  int n;
  int a[200];
  cin>>n;
  for(int i=0;i<n;i++) cin>>a[i];
  bool wareru = true;
  int c=0;
  while(wareru){
    for(int i=0;i<n;i++){
      if(a[i]%2==0) a[i]/=2;
      else wareru=false;
    }
    if(!wareru) break;
    c++;
  }
  cout << c;
}

Measured memory_bytes: 256
#[allow(unused_macros)]
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)*}
    };
}

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

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

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

#[allow(unused_macros)]
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, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

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

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

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

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

const M : usize = 998244353;

fn main() {
    input! {
        n: usize,
        d: [usize; n],
    }
    let height = d.iter().max().unwrap() + 1;
    let mut nodes = vec![0; height];
    for &di in d.iter() {
        nodes[di] += 1;
    }
    if d[0] != 0 || nodes[0] != 1 {
        println!("0");
        return;
    }
    // println!("{:?}", nodes);
    let mut result = 1;
    for i in 1..height {
        let mut x = 1;
        for _ in 0..nodes[i] {
            x = x * nodes[i - 1] % M;
        }
        result = result * x % M;
    }
    println!("{}", result);
}


Measured memory_bytes: 6396
#include <cstring>
#include <sstream>
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <iomanip>
#include <map>
#include <unordered_map>
#include <cmath>
#include <queue>
#include <set>
#include <numeric>
#include <stack>

using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(ll i = n - 1; i >= 0; i--)
#define repone(i, n) for(ll i = 1; i <= (ll)(n); i++)
#define each(i, mp) for(auto i:mp)
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll half_inf = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);
typedef unordered_map<char, ll> ump;
typedef pair<ll, ll> P;

ump mp;

int main() {
#ifdef MY_DEBUG
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wmissing-noreturn"
    while (true) {
        mp = ump();
#pragma clang diagnostic pop
#endif
        string a;
        cin >> a;
        rep(i, a.size()) {
            mp[a[i]]++;
        }
        ll ans = a.size() * (a.size() - 1) / 2;
        each(m, mp) {
            ans -= m.second * (m.second - 1) / 2;
        }
        cout << ans + 1 << endl;


#ifdef MY_DEBUG
    }
#endif
    return 0;
}

Measured memory_bytes: 640
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		while(true){

			int a = sc.nextInt();
			String op = sc.next();
			int b = sc.nextInt();

			if(op.equals("?"))break;

			int ans = 0;

			switch(op){
			case "+":
				ans = a+b;
				break;
			case "-":
				ans = a-b;
				break;
			case "*":
				ans = a*b;
				break;
			case "/":
				ans = a/b;
				break;
			}

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




Measured memory_bytes: 26328
#include<bits/stdc++.h>
using namespace std;
int n,m,c;
int main(){
  cin >> n >> m >> c;
  int b[m];
  for(int i=0;i<m;i++){
    cin >> b[i];
  }
  int a[n][m],sums=0;
  int can=0;
  for(int i=0;i<n;i++){
    for(int l=0;l<m;l++){
      cin >> a[i][l];
      sums += a[i][l]*b[l];
    }
    if(sums+c > 0){
      can++;
    }
    sums = 0;
  }
  cout << can;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long 
using namespace std;
const int N=55;
int n,m,a[N];
ll f[N][N*N][N];
int main(){
//	freopen("b.in","r",stdin);
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++) scanf("%d",&a[i]);
	f[0][0][0]=1;
	for(int i=1;i<=n;i++){
		for(int k=0;k<=i;k++){
			for(int j=n*m+1;j>=0;j--){
				f[i][j][k]+=f[i-1][j][k];
				if(k>=1 && j>=a[i]) f[i][j][k]+=f[i-1][j-a[i]][k-1];
			}
		}	
	}
	ll ans=0;
	for(int i=1;i<=n;i++) ans+=f[n][m*i][i];
	printf("%lld\n",ans);
	return 0;
} 

Measured memory_bytes: 66560
use proconio::input;


fn solve(_: i32, x: i32, l: Vec::<i32>) {
    let mut ans: i32 = 1;
    let mut cur: i32 = 0;

    for li in l {
        if cur + li <= x {
            ans += 1;
        }
        cur += li;
    }

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


fn main() {
    input! {
        n: i32,
        x: i32,
        l: [i32; n],
    }

    solve(n, x, l);
}


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

int main(){
    int tmp=0,ans=0;
    string s;
    cin >> s;
    for(int i=0;i<s.size();i++){
        if(s[i]=='A'||s[i]=='C'||s[i]=='G'||s[i]=='T'){tmp++;if(tmp>ans)ans=tmp;}
        else tmp=0;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, begin, end) for(ll i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(ll i=(begin)-1;i>=(end);i--)
#define IREP(i, n) IFOR(i,n,0)
#define SORT(a) sort(a.begin(), a.end())
#define ISORT(a) sort(a.begin(), a.end(),greater<ll>())
#define REVERSE(a) reverse(a.begin(), a.end())
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v) cout << #v << "=(" << v[0]; FOR(i_debug, 1, v.size()){ cout << "," << v[i_debug]; } cout << ")" << endl;
#define mdebug(m) cout << #m << "=" << endl; REP(i_debug, m.size()){ REP(j_debug, m[i_debug].size()){ cout << m[i_debug][j_debug] << ","; } cout << endl;}
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)

#define ll long long
#define f first
#define s second
#define mp make_pair
#define pb push_back
#define INF 1000000000000000000

using vec = vector<ll>;
using mat = vector<vec>;
using Pii = pair<ll, ll>;
using PiP = pair<ll, Pii>;
using PPi = pair<Pii, ll>;
using bvec = vector<bool>;
using Pvec = vector<Pii>;


template<typename T> void readv(vector<T> &a) { REP(i, a.size()) cin >> a[i]; }
void readv_m1(vector<int> &a) { REP(i, a.size()) {cin >> a[i]; a[i]--;} }

ll mod = 1000000007;

int main()
{
	ll N, A;
	cin >> N >> A;

	N %= 500;
	if (N > A)cout << "No" << endl;
	else cout << "Yes" << endl;

	return 0;
}

Measured memory_bytes: 256
// Author : Chi
// created :

//header files
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

//macros
#define ll 		    long long
#define ss          second
#define ff          first
#define vi          vector<int>
#define vll         vector<long long>
#define pb          push_back
#define TEST  	    int TesT;cin>>TesT;while(TesT--)solve();
#define TEST1       solve();
#define mod         998244353
#define r0n(i,n)    for(ll i = 0; i < n; ++i)
#define r1n(i,n)    for(ll i = 1; i <= n; ++i)
#define CHI         ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
//namespaces
using    namespace __gnu_pbds;
using    namespace std;

typedef tree <int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update > ordered_set;
void solve(){
    int n;
    int m=3;
    cin>>n;
    int mat[n+1][m+1];
    r1n(i,n)
        r1n(j,m)
            cin>>mat[i][j];
    ll ans[n+1][m+1];
    r1n(i,n){
        r1n(j,m)
            if(i==1)
                ans[i][j]=mat[i][j];
            else{
                ans[i][j]=INT_MIN;
                r1n(k,m)
                    if(k!=j)
                        ans[i][j]=max(ans[i][j],ans[i-1][k]+mat[i][j]);
                }
    }
    ll sum=0;
    r1n(i,m)
        sum=max(sum,ans[n][i]);
    cout<<sum<<"\n";
}
// Driver Code
int main()
{
    TEST1
    return 0;
}



Measured memory_bytes: 4992
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>


int main(void){
	char string[11] = {0, };
	int flag = 0;

	scanf("%s", string);

	for(int i = 0; i < 10; i += 2){
		if(string[i] == 0)
			break;
		else if(!(string[i] == 'h' && string[i+1] == 'i'))
			flag = 1;
	}

	if(flag)
		printf("No");
	else
		printf("Yes");
	return 0;
}

Measured memory_bytes: 128