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

using namespace std;

// func
// ------------------------------------------------
int CalcSumOfDigit(int n);      // 各桁の和を計算する。
string upper(string str);       // 英字を大文字に変換する。
string lower(string str);       // 英字を小文字に変換する。

// define
// ------------------------------------------------
#define all(a)        (a).begin(),(a).end()
#define rall(a)       (a).rbegin(),(a).rend()
#define pb            push_back
#define sz(a)         int((a).size())
#define rep(i,n)      for(int(i)=0;(i)<(n);(i)++)
#define repe(i,n)     for(int(i)=0;(i)<=(n);(i)++)
#define vsort(v)      sort((v).begin(),(v).end())
#define rvsort(v)     sort(rall((v)))
#define vi            vector<int>
#define GCD(a,b)      __gcd((a),(b))
#define LCM(a,b)      (a)/GCD((a),(b))*(b)
#define kiriage(a,b)  ((a)+(b)-1)/(b)

const int INF = 1e9;

// code
// ------------------------------------------------
int main() {

  int n,m;
  cin >> n >> m;

  int food[m] = {0};

  rep(i,n)
  {
    int k;
    cin >> k;
    rep(j,k)
    {
      int like;
      cin >> like;
      food[like - 1]++;
    }
  }

  int cnt = 0;

  rep(i,m)
  {
    if(food[i] == n)
      cnt++;
  }

  cout << cnt << endl;

  return 0;
}
// funcの実体
// ------------------------------------------------
int CalcSumOfDigit(int n)
{
  int s = 0;
  while(n)
  {
    s += n % 10;
    n = n / 10;
  }
  return s;
}

string upper(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(97 <= *itr && *itr <= 122)
    {
      *itr = *itr - 32;
    }
  }
  return str;
}

string lower(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(65 <= *itr && *itr <= 90)
    {
      *itr = *itr + 32;
    }
  }
  return str;
}


Measured memory_bytes: 256
a,b,c,x,y=map(int,input().split())

yenmin=a*x+b*y
for zz in range(2*10**5+1):
    xx=max(x-zz//2,0)
    yy=max(y-zz//2,0)
    yen=a*xx+b*yy+c*zz
    if yen<yenmin:
        yenmin=yen
print(yenmin)
#print(xx,yy,zz)

Measured memory_bytes: 3060
import java.util.Scanner;

// ナップザック問題を解くプログラム
class Solver{
    int num;
    int capacity, answer;
    int[] weight, value;
    int[][] dp;
    boolean[] knapsack;
    // コンストラクタ
    public Solver(int num, int[] weight, int[] value, int capacity) {
        this.num = num;
        this.weight = weight;
        this.value = value;
        this.capacity = capacity;
        dp = new int[num + 1][capacity + 1];
        knapsack = new boolean[num + 1];
    }
    int solve() {
        for (int i = 0; i < dp.length; i++) {
            for (int j = 0; j < dp[0].length; j++) {
                dp[i][j] = -1;
            }
        }
        if (weight[0] <= capacity) {
            dp[1][weight[0]] = value[0];
        }
        dp[1][0] = 0;
        dp[0][0] = 0;
 
        for (int i = 2; i <= num; i++) {
            for (int k = 0; k <= capacity; k++) {
                if (k < weight[i - 1]) {
                    dp[i][k] = dp[i - 1][k];
                }
                else {
                    dp[i][k] = Math.max(dp[i - 1][k], dp[i - 1][k - weight[i - 1]] + value[i - 1]);
                }
            }
        }
        int res = 0;
        for (int x : dp[num]) {
            res = Math.max(x, res);
        }
 
        return answer = res;
    }
 
    // 価値の総和がsumValueとなる組み合わせすべて出力する
    // [1, n]までの品物を出力する
    void showKnapsack(int sumValue, int n) {
        if (n < 1) {
            int cnt = 0;
            for (int i = 0; i < knapsack.length; i++) {
                if (knapsack[i]) {
                    System.out.print((cnt++ > 0 ? " " : "") + i);
                }
            }
            System.out.println();
            return;
        }
        for (int i = 0; i <= capacity; i++) {
            if (dp[n][i] == sumValue) {
                int sub = i - weight[n - 1];
                if (dp[n - 1][i] == sumValue) {
                    knapsack[n] = false;
                    showKnapsack(sumValue, n - 1);
                }
                if (sub >= 0 && dp[n - 1][sub] >= 0) {
                    knapsack[n] = true;
                    showKnapsack(sumValue - value[n - 1], n - 1);
                }
            }
        }
    }
}
 
// ナップザック問題を解くプログラム
 
 
public class Main{
    public static void main(String[] args) {
        int num, capacity, answer;  //データ数
        int[] weight, value;
        // 入力
        Scanner stdIn = new Scanner(System.in);
        num = stdIn.nextInt();
        capacity = stdIn.nextInt();
        weight = new int[num];
        value = new int[num];
        for (int i = 0; i < num; i++) {
            value[i] = stdIn.nextInt();
            weight[i] = stdIn.nextInt();

        }
 
        Solver s = new Solver(num, weight, value, capacity);
        answer = s.solve();
        System.out.println(answer);
        // s.showKnapsack(answer, num);
    }
}


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

N=[i for i in range(int(-(-A//0.08)),int(-(-(A+1)//0.08)))]
M=[i for i in range(int(-(-B//0.1)),int(-(-(B+1)//0.1)))]

if N[0] in M:
    print(int(-(-A//0.08)))
elif M[0] in N:
    print(int(-(-B//0.1)))
else:
    print(-1)

Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#include <math.h>

using namespace std;

typedef long long int ll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
const int MOD = 1000000007;
const int INF = INT_MAX;



int main(int argc, char const *argv[])
{
    string s;
    cin >> s;

    int len = s.length();

    int cnt1 = 0;
    for (int i=0; i < len; i++){
        if (i%2 == 0 && s[i] == '0'){
            cnt1++;
        }
        else if (i%2 == 1 && s[i] == '1'){
            cnt1++;
        }
    }

    int cnt2 = 0;
    for (int i=0; i < len; i++){
        if (i%2 == 0 && s[i] == '1'){
            cnt2++;
        }
        else if (i%2 == 1 && s[i] == '0'){
            cnt2++;
        }
    }

    int res = min(cnt1, cnt2);

    cout << res << endl;
    

    



    return 0;
}




//              g++ -std=c++1z  

Measured memory_bytes: 512
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <iomanip>
#include <array>
#include <numeric>
#include <regex>
#include <bitset>
#include <deque>

using namespace std;
typedef long long ll;
typedef pair<int, int> p_ii;

const int INF = 1e9;
const double PI = acos(-1.0);
const ll MOD = 1e9 + 7;

ll pow2(ll x) {
	ll ret = 1;
	for (int i = 0; i < x; i++) {
		ret *= 2;
	}
	return ret;
}


int main() {
	int N, K;
	cin >> N >> K;
	vector<ll> a(N), p2(45);
	for (int i = 0; i < N; i++) {
		cin >> a[i];
	}

	for (int i = 0; i <43; i++)p2[i] = pow2((ll)i);

	vector<ll> cum(N + 2, 0), b;
	for (int i = 1; i <= N; i++) {
		cum[i] += cum[i - 1] + a[i - 1];
	}

	for (int i = 0; i <= N-1; i++) {
		for (int j = i+1; j <= N; j++) {
			b.push_back(cum[j] - cum[i]);
		}
	}

	ll res = 0;

	for (int i = 40; i > 0; i--) {
		int c = 0;
		for (int j = 0; j < b.size(); j++) {
			if (((res + p2[i - 1])&b[j]) == (res + p2[i - 1]))c++;
		}
		if (c >= K) {
			res += p2[i - 1];
		}
	}


	cout << res << endl;

	return 0;
}

Measured memory_bytes: 6132
{-# LANGUAGE DataKinds      #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE TypeOperators  #-}

import           Data.List    (group)
import           Data.Ratio   (denominator, numerator)
import           GHC.TypeLits (KnownNat, Nat, natVal, type (+), type (^))

main :: IO ()
main = do
  [n, m] <- map read . words <$> getLine
  print $ f n m

type Modulus = 10 ^ 9 + 7

f :: Int -> Int -> Int
f n m = unModular $ g $ map (fromIntegral . length) $ group $ factors m
  where
    g :: [Modular Int Modulus] -> Modular Int Modulus
    g = product . map (\b -> nCombinations (b + fromIntegral n - 1) b)

factors :: Integral a => a -> [a]
factors = factors' primes
  where
    factors' pps@(p:ps) n
      | n < 2              = []
      | n < p ^ (2 :: Int) = [n]  -- stop early
      | n `mod` p == 0     = p : factors' pps (n `div` p)
      | otherwise          = factors' ps n
    factors' _ _ = error "`primes` is a infinite list"

primes :: Integral a => [a]
primes = 2 : filter (\n -> head (factors n) == n) [3, 5 ..]

nCombinations :: (Eq a, Fractional a) => a -> a -> a
nCombinations n k = factorial n / factorial k / factorial (n - k)

factorial :: (Eq a, Num a) => a -> a
factorial 0 = 1
factorial n = n * factorial (n - 1)

tests, test1, test2, test3 :: Bool
tests = test1 && test2 && test3
test1 = f 2 6 == 4
test2 = f 3 12 == 18
test3 = f 100000 1000000000 == 957870001

newtype Modular a (modulus :: Nat) =
  Modular { unModular :: a }
  deriving (Eq)

instance Show a => Show (Modular a modulus) where
  show (Modular n) = show n

instance (Integral a, KnownNat modulus) => Num (Modular a modulus) where
  fromInteger           = toModular . fromInteger
  Modular n + Modular m = toModular $ n + m
  Modular n * Modular m = toModular $ n * m
  negate (Modular n)    = toModular $ negate n
  abs (Modular n)       = toModular $ abs n
  signum (Modular n)    = toModular $ signum n

instance (Integral a, KnownNat modulus) => Fractional (Modular a modulus) where
  recip m@(Modular n) = toModular $ modularReciprocal (fromInteger (natVal m)) n
  fromRational r = fromInteger (numerator r) / fromInteger (denominator r)

toModular :: (Integral a, KnownNat modulus) => a -> Modular a modulus
toModular n = let m = Modular $ n `mod` fromInteger (natVal m) in m

modularReciprocal :: Integral a => a -> a -> a
modularReciprocal modulus n = snd $ modularReciprocal' modulus n
  where
    -- modularReciprocal' n m = (x, y)
    -- n * x + m * y = 1
    modularReciprocal' _ 0 = notCoprimeError
    modularReciprocal' _ 1 = (0, 1)
    modularReciprocal' m l = (y, x - q * y)
      where
        (q, r) = m `divMod` l
        (x, y) = modularReciprocal' l r
    notCoprimeError =
      error $ unwords
        [ "divider"
        , parentheses $ showIntegral n
        , "must be coprime to modulus"
        , parentheses $ showIntegral modulus
        ]
    parentheses s = "(" ++ s ++ ")"
    showIntegral = show . toInteger


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

using namespace std;
using ll = long long;

int main() {
  ll a;
  double b;
  cin >> a >> b;
  ll ib = b * 100 + 0.5;
  a *= ib;
  a /= 100;
  cout << a << endl;
  
}
  

Measured memory_bytes: 3716
#include<iostream>
#include<algorithm>
using namespace std;
static const int MAX = 1000;
static const int VMAX = 10000;

int n, A[MAX], s;
int B[MAX],T[VMAX + 1];

int solve(){
  int ans = 0;
  bool V[VMAX];
  for( int i = 0 ; i < n ; i++ ){
    B[i] = A[i];
    V[i] = false;
  }
  sort( B, B + n );
  for( int i = 0 ; i < n ; i++ )T[B[i]] = i;
  for( int i = 0 ; i < n ; i++ ){
    if( V[i] )continue;
    int cur = i;
    int S = 0;
    int m = VMAX;
    int an = 0;
    while( 1 ){
      V[cur] = true;
      an++;
      int v = A[cur];
      m = min( m, v);
      S += v;
      cur = T[v];
      if( V[cur] )break;
    }
    ans += min( S + ( an - 2 ) * m, m + S  + ( an + 1 ) * s);
  }
  return ans;
}

int main( void ){
  cin >> n;
  s = VMAX;
 
  for( int i = 0 ; i < n ; i++ ){
    cin >> A[i];
    s = min(s,A[i]);
  }
  int ans = solve();
  cout << ans << endl;

  return 0 ;
}

Measured memory_bytes: 1208
#include<bits/stdc++.h>
using namespace std;
int a, b;
int main(void)
{
	cin >> a >> b;
	if (a > 0 && a < 10 && b>0 && b < 10)
	{
		cout << a * b << endl;
	}
	else
	{
		cout << "-1" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int mod=998244353;
typedef long long ll;
ll power(ll m,ll n){
    ll ret =1,N=n;
    while(N){
        ret=(ret*m)%mod;
        N--;
    }
    return ret;
}
signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    ll n,a,ans=1,ma=-1;
    cin>>n;
    vector<ll> d(n,0);
    for(int i=0;i<n;i++){
        cin>>a;
        d[a]++;
        if(a>ma){ma=a;}
        if(i!=0&&a==0){cout<<0;return 0;}
    }
    if(d[0]!=1){cout<<0;return 0;}
    for(int i=0;i<ma;i++){
        ans=(ans*power(d[i],d[i+1]))%mod;
    }
    cout<<ans%mod;
}

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

int main() {
int N;//青いカード(利益)の枚数
  cin >> N;
vector<string> vecb(N);//vector-blue
  int i;
  for (i = 0; i < N; i++)
    cin >> vecb.at(i);//青いカード群の入力完了
  int M;//赤いカード(損失)の枚数
  cin >> M;
  vector<string> vecr(M);//vector-red
  for (i = 0; i < M; i++)
    cin >> vecr.at(i);//赤いカード群の入力完了
  int k, l, profit;//k,lはカウンター、profitは差し引き
  profit = 0;
  for (i = 0; i < N; i++){//青いカードごとに繰り返す
    l = 0;
  for (k = 0; k < N; k++){//青いカードの中で同じものがあるか探す
   if (vecb.at(i) == vecb.at(k) )
     l++;//同じものがあれば+1
  }
  for (k = 0; k < M; k++){//赤いカードの中で同じものがあるか探す
    if (vecb.at(i) == vecr.at(k))
      l--;
  }
  if (profit < l)
    profit = l;
  }
  cout << profit << endl;
}

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

int main(){
    string N;
    cin >> N;
    if((N[0]==N[1] && N[1]==N[2]) || (N[1]==N[2] && N[2]==N[3])){
        cout << "Yes" << endl;
    }else
    {
        cout << "No" << endl;
    }
    
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
 
const ll INF = 1e18;
const ll MOD = 1000000007;
const ll MX = 0; //最大値
 
ll dp[MX][MX];
inline void chmax(ll& a, ll b) {
  a = max(a, b);
}
 
#define rep(i,n) for(ll i=0; i<(ll)(n); i++)
#define ALL(x) (x).begin(),(x).end()
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))
#define PB push_back
 
 
int main(){
    ll n,q;
    cin >> n;
    vector<ll> a(n);
    rep(i,n) cin >> a.at(i);
    cin >> q;
    vector<ll> b(q), c(q);
    rep(i,q) cin >> b.at(i) >> c.at(i);
    ll cnt = 0;
    rep(i,n) cnt += a.at(i);
    
    vector<ll> set(100005, 0);
    rep(i,n) {
        set.at(a.at(i))++;
    }
    
    rep(i,q){
        ll tmp = set.at(b.at(i));
        set.at(c.at(i)) += tmp;
        cnt += (c.at(i)-b.at(i))*tmp;
        set.at(b.at(i)) = 0;
        cout << cnt << endl;
    }
}

Measured memory_bytes: 6412
#prag\
ma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;

#define f first
#define s second
pair<int,int> fa[100001];

int find(int x){
	if(fa[x].f==x&&fa[x].s==0) return x;
	int t=find(fa[x].f);
	fa[x]=make_pair(t,fa[fa[x].f].s+fa[x].s);
	fa[x].f=t;
	return t;
}

int main()
{
	ios::sync_with_stdio(false);
	int n,m;
	cin>>n>>m;
	for(int i=1;i<=n;++i) fa[i]=make_pair(i,0);
	for(int i=1;i<=m;++i){
		int l,r,d;
		cin>>l>>r>>d;
		int x=find(l),y=find(r);
		if(x!=y){
			if(x>y) fa[x]=make_pair(y,-(fa[l].s-fa[r].s+d));
			else fa[y]=make_pair(x,fa[l].s-fa[r].s+d);
		}
		else{
			if(fa[r].s-fa[l].s!=d){
				cout<<"No";
				return 0;
			}
		}
	}
	cout<<"Yes";
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
//ios::sync_with_stdio(false);
//cin.tie(0);
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
typedef pair<int,pii> pipi;
typedef pair<ll,ll> pll;
typedef pair<pll,ll> ppll;
typedef pair<ll,pll> plpl;
typedef tuple<ll,ll,ll> tl;
ll mod=1000000007;
ll mod2=998244353;
ll inf=1000000000000000000;
double pi=2*acos(0);
#define rep(i,m,n) for(int i=m;i<n;i++)
#define rrep(i,n,m) for(int i=n;i>=m;i--)
int dh[4]={1,-1,0,0};
int dw[4]={0,0,1,-1};
int ddh[8]={-1,-1,-1,0,0,1,1,1};
int ddw[8]={-1,0,1,-1,1,-1,0,1};
ll lmax(ll a,ll b){
    if(a<b)return b;
    else return a;
}
ll lmin(ll a,ll b){
    if(a<b)return a;
    else return b;
}
int main(){
    int n;cin>>n;
    int h[n];rep(i,0,n)cin>>h[i];
    h[0]--;
    rep(i,1,n){
        if(h[i]<h[i-1]){
            cout<<"No"<<endl;
            return 0;
        }
        if(h[i]>h[i-1])h[i]--;
    }
    cout<<"Yes"<<endl;
}


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

int main() {
 int x, y;
  cin >> x >> y;
  if(y % 2 != 0) cout <<"No" << endl;
  else if(x*4 >= y && y >= x*2) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 3636
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <set>
#include <utility>
#include <cstdio>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repp(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define rrep(i, n, m) for (int i = n; i >= m; i--)
typedef long long LL;
template <class T>
bool contain(const std::string &s, const T &v)
{
    return s.find(v) != std::string::npos;
}

int main()
{
    int N,K,h[100005]={},dp[100005]={};
    cin>>N>>K;
    rep(i,N){
        cin>>h[i];
    }
    int vmin;
    dp[0] = 0;
    repp(i,1,K){
        vmin = 1e9;
        rep(j,i){
            vmin = min(vmin, dp[j] + abs(h[i] - h[j]));
            
        }
        dp[i] = vmin;
    }
    repp(i,K,N){
        vmin = 1e9;
        repp(k,1,K+1){
            vmin = min(vmin, dp[i - k] + abs(h[i] - h[i - k]));
        }
        dp[i] = vmin;
    }
    cout<<dp[N-1]<<endl;
}

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

using namespace std;

const int N = 2e5 + 5;
const int M = 1e6 + 9;
const long long INF = 1e9 + 7;
const int SM = 1e3 + 4;
const double EPS = 3e-16;
const int K = 25;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    
    double n; cin >> n;
    
    int f = int(n);
    cout << fixed << setprecision(10) << double((f + 1) / 2) / n;
    
    return 0;
}

Measured memory_bytes: 256
import math
a,b = map(int,input().split())
ans = 1
while True:
    if math.floor(ans*0.08) == a:
        while math.floor(ans*0.08) == a:
            if math.floor(ans*0.1) == b:
                print(ans)
                exit()
            ans+=1
        print(-1)
        exit()
    ans+=1

Measured memory_bytes: 3060
/*
 * I won't be broken
 * I won't be tortured
 * I won't be beaten down
 * I have the answer
 * I can take the pressure
 * I will turn it all around
 * Lift me up above this
 * The flames and the ashes
 * Lift me up and help me to fly away
*/
#include <bits/stdc++.h>
using namespace std;
int n,y,b[3]={10000,5000,1000},a[3]={0,0,0};
int main(){
        scanf("%d%d",&n,&y);
        for(int i = 0; i<=n; i++){
                for(int j = 0;j<=n; j++){
                        if(i+j<=n&&10000*i+5000*j+1000*(n-i-j)==y){
                                printf("%d %d %d\n",i,j,n-i-j);
                                return 0;
                        }
                }
        }
        printf("-1 -1 -1\n");

        return 0;
}

Measured memory_bytes: 256
n, d = gets.split(' ').map(&:to_i)
lr = []
output = 0

def hoge(l, r)
  sum = 0
  for i in 0..(l.length-1)
    sum += (l[i] - r[i]) ** 2
  end
  (sum ** 0.5).denominator == 1
end

for i in 0..(n-1)
  lr << gets.split(' ').map(&:to_i)
end

  for i in 0..(n-1)
    for j in (i+1)..(n-1)
      output = output + 1 if hoge(lr[i], lr[j])
    end
  end

puts output


Measured memory_bytes: 1788
#include <bits/stdc++.h>
#define PI 3.14159265359
#define NIL (-1)
#define LL long long
using namespace std;
const int64_t MOD = 1e9 + 7;
const int INF = INT_MAX;

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

	vector<int> v = { s };
	int ans = 0;

	while (1) {
		int n, p;
		p = v.at(v.size() - 1);
		if (p % 2) n = 3 * p + 1;
		else n = p / 2;
		if (count(v.begin(), v.end(), n)) {
			ans = v.size() + 1;
			break;
		}
		else {
			v.push_back(n);
		}
	}

	cout << ans << endl;
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
#define dbug(x) cout<<#x<<"="<<x<<endl
using namespace std;
template <typename T> void read(T &t) {
	t=0; char ch=getchar(); int f=1;
	while ('0'>ch||ch>'9') { if (ch=='-') f=-1; ch=getchar(); }
	do {(t*=10)+=ch-'0';ch=getchar();} while ('0'<=ch&&ch<='9'); t*=f;
}
typedef long long ll;
const int maxn=(1e5)+10;
int n,a[maxn],mn=(1e9),mx;
ll s1,k,s2;
int main() {
	//freopen("1.txt","r",stdin);
	read(n);
	for (int i=1;i<=n;i++) {
		read(a[i]),s1+=a[i];
		mn=min(mn,a[i]);
		mx=max(mx,a[i]);
	}
	s2=(ll)n*(n+1)/2;
	if (s1%s2!=0) { printf("NO\n"); return 0; }
	k=s1/s2;
	if (mn<k||mx>k*n) { printf("NO\n"); return 0; }
	for (int i=1;i<=n;i++)
		a[i]=(a[i]-k*i%n+n)%n;
	for (int i=1;i<=n;i++)
		if (a[i]!=a[1]) { printf("NO\n"); return 0; }
	printf("YES\n");
	return 0;
}

Measured memory_bytes: 640
from collections import defaultdict

N = int(input())
d = defaultdict(int)

for _ in range(N):
    d[input()] += 1

d = sorted(d.items(), key=lambda x: x[1])[::-1]

M = d[0][1]

A = []
for k, v in d:
    if v == M:
        A.append(k)
    else:
        break

for a in sorted(A):
    print(a)


Measured memory_bytes: 43476
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); i++)
using namespace std;
using ll = long long;
int main()
{
    int n;
    string s;
    cin >> n >> s;
    vector<int> a(n);
    rep(i,n){
        if(s[i] =='R') a[i] = 0;
        if(s[i] =='G') a[i] = 1;
        if(s[i] =='B') a[i] = 2;
    }
    vector<ll> cnt(3);
    rep(i, n) cnt[a[i]]++;
    ll ans = 1;
    rep(i, 3) ans *= cnt[i];
    rep(j,n) {
        rep(i,j){
            int k = j + (j-i);
            if(k < n){
                if(a[i] == a[j]) continue;
                if(a[i] == a[k]) continue;
                if(a[k] == a[j]) continue;
                ans--;
            }
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3584
#include <iostream>
#include <algorithm>
#include <math.h>
using namespace std;
int main() {
	long long int a, b, c, d, e, f;
	cin >> a >> b >> c >> d >> e >> f;
	a *= 100;
	b *= 100;
	long double max = -1;
	int yan = 0, yojo = 0;
	for (int i = 0; i*a <= f; i++) {
		for (int j = 0; i*a + j*b <= f; j++) {
			for (int k = 0; i*a + j*b + k*c <= f; k++) {
				for (int l = 0; i*a + j*b + k*c + l*d <= f; l++) {
					long double mizu = i*a + j*b + k*c + l*d;
					long double sato = k*c + l*d;
					if ((i*a + j*b)*e / 100<sato) break;
					double siri = sato / mizu;
					if (siri>max) {
						yan = mizu; yojo = sato; max = siri;
					}
				}
			}
		}
	}
	cout << yan << ' ' << yojo << endl;
	return 0;
}

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

using namespace std;

const int maxn = 1e6 + 6;
char input[maxn];
int Num[maxn], tmp[maxn], mx, mx_tmp, Tot;

void Add() {
  if (mx_tmp > mx) swap(Num, tmp), swap(mx, mx_tmp);
  for (int i = 0; i <= mx_tmp; i++) {
    Num[i] += tmp[i], Tot += tmp[i];
    while (Num[i] >= 10) Num[i + 1]++, Num[i] -= 10, Tot -= 9;
  }
  for (int i = mx_tmp + 1; i <= mx && Num[i] >= 10; i++)
    while (Num[i] >= 10) Num[i + 1]++, Num[i] -= 10, Tot -= 9;
  while (Num[mx + 1]) mx++;
}

int main() {
  scanf("%s", input), mx = strlen(input);
  reverse(input, input + mx), mx--;
  for (int i = 0; i <= mx; i++) Tot += Num[i] = input[i] - '0';
  memcpy(tmp, Num, sizeof(tmp)), mx_tmp = mx;
  for (int i = 1; i <= 8; i++) Add();
  memset(tmp, 0, sizeof(tmp)), tmp[mx_tmp = 0] = 9;
  for (int i = 0; i <= 528180; i++) {
    if (Tot <= i * 9) return printf("%d\n", i), 0;
    Add();
  }
  printf("-1");
  return 0;
}


Measured memory_bytes: 8576
#include<bits/stdc++.h>
using namespace std;
int main(){
    string s;
    cin>>s;
    int c1=0,c0=0,ans=0;
    for(int i=0;i<s.size();i++)
    {
        if(s[i]=='1')
        c1++;
        if(s[i]=='0')
        c0++;
    }
    while(c0>0&&c1>0)
    {
        ans+=2;
        c0--;c1--;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 512
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <vector>
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define fi first
#define se second
using namespace std;
inline char nc()
{
    return getchar();
	static char buf[100000], *l = buf, *r = buf;
	return l==r&&(r=(l=buf)+fread(buf,1,100000,stdin),l==r)?EOF:*l++;
}
template<class T> void read(T &x)
{
	x = 0; int f = 1, ch = nc();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=nc();}
	while(ch>='0'&&ch<='9'){x=x*10-'0'+ch;ch=nc();}
	x *= f;
}
typedef long long ll;
typedef pair<int, ll> pil;
const int MAXN = 2e5 + 5;
const int MAXA = 2e5 + 5;
ll K;
int N;
int A[MAXN];
int L[MAXA], R[MAXA];
bool vis[MAXA];
pil nex[MAXN][45];
vector<int> an;
inline pil add(pil a, pil b)
{
    return make_pair(b.fi, a.se + b.se);
}
void FIND(pil &a)
{
    if(a.se) return;
    FIND(nex[a.fi][0]);
    a = nex[a.fi][0];
}
void COUNT()
{
    int m = *max_element(A, A + N);
    for(int i = 1; i <= m; ++i) if(R[i] != -1)
    {
        nex[ R[i] ][0] = make_pair((L[i] + 1) % N, 1 + (L[i] + 1) / N);
    }
    for(int i = 0; i < N; ++i)
    {
        FIND(nex[i][0]);
    }
    for(int k = 1; k < 45; ++k)
    {
        for(int i = 0; i < N; ++i)
        {
            nex[i][k] = add(nex[i][k - 1], nex[ nex[i][k - 1].first ][k - 1]);
        }
    }
}
void work(int st)
{
    for(int i = st; i < N; ++i)
    {
        int x = A[i];
        if(!vis[x])
        {
            an.push_back(x);
            vis[x] = 1;
        }
        else
        {
            while(true)
            {
                int y = an.back();
                vis[y] = 0;
                an.pop_back();
                if(x == y) break;
            }
        }
    }
}
void solve()
{
    int u = 0;
    for(int i = 44; ~i; --i)
    {
        while(K > nex[u][i].second)
        {
            K -= nex[u][i].second;
            u = nex[u][i].first;
        }
    }
    work(u);
    if(K == 2) work(0);
}
int main()
{
    read(N), read(K);
    memset(L, -1, sizeof(L));
    memset(R, -1, sizeof(R));
    for(int i = 0; i < N; ++i)
    {
        read(A[i]);
        if(L[ A[i] ] == -1) L[ A[i] ] = i;
        if(R[ A[i] ] != -1)
        {
            nex[ R[ A[i] ] ][0] = make_pair((i + 1) % N, (i + 1) / N);
        }
        R[ A[i] ]= i;
    }
    COUNT();
    solve();
    for(unsigned int i = 0; i < an.size(); ++i)
    {
        if(i) printf(" ");
        printf("%d", an[i]);
    }
    printf("\n");
    return 0;
}


Measured memory_bytes: 145524
fun main(arg: Array<String>) {
    val (N, A, B) = tripleIntIntLong()
    val X = listOfLong()
    val F = LongArray(N)
    for (n in 1 until N) F[n] = (X[n] - X[n - 1]) * A
    val ans = F.sumByLong { if (it < B) it else B }
    println(ans)
}
inline fun LongArray.sumByLong(selector: (Long) -> Long): Long {
    var sum = 0L
    for (element in this) sum += selector(element)
    return sum
}
fun next() = readLine()!!
fun nextInt(offset: Int = 0) = Integer.parseInt(next()) + offset
fun nextLong() = next().toLong()
fun listOfString() = next().split(" ")
fun listOfInt() = listOfString().map(String::toInt)
fun listOfInt(offset: Int = 0) = listOfString().map { Integer.parseInt(it) + offset }
fun listOfLong() = listOfString().map(String::toLong)
fun tripleIntIntLong() = listOfLong().let { Triple(it[0].toInt(), it[1].toInt(), it[2]) }


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

using namespace std;

#ifdef DGC
#include "debug.h"
#else
#define debug(...) 9715
#endif
typedef long long ll;
typedef long double ld;
typedef complex<ll> point;
#define F first
#define S second



int main()
{
	#ifdef DGC
		//freopen("a.in", "r", stdin);
		//freopen("b.out", "w", stdout);
	#endif

	ios_base::sync_with_stdio(0), cin.tie(0);

	int n, r;
	cin >> n >> r;
	if (n >= 10) cout << r << "\n";
	else cout << r + 100 * (10 - n) << "\n";

	return 0;
}


Measured memory_bytes: 256
// https://atcoder.jp/contests/abc145/tasks/abc145_b

#include "algorithm"
#include "functional"
#include "iostream"
#include "numeric"
#include "queue"
#include "set"
#include "vector"
#define rep(i, to) for (ll i = 0; i < (to); ++i)
#define repf(i, from, to) for (ll i = from; i < (to); ++i)
#define repr(i, from) for (ll i = from - 1; i >= 0; --i)
#define all(vec) vec.begin(), vec.end()
#define fi first
#define se second
using namespace std;
typedef long long ll;
template <typename T>
using V = vector<T>;
using VL = V<ll>;
using VVL = V<VL>;
template <typename T, typename U>
using P = pair<T, U>;
using PL = P<ll, ll>;
using VPL = V<PL>;
template <typename T>
inline bool chmax(T& a, T b);
template <typename T>
inline bool chmin(T& a, T b);
void print_ints(vector<ll> v);
template <typename T>
void drop(T a);

const ll INF = 1e18;

void solve() {
  ll N;
  cin >> N;
  string S;
  cin >> S;

  string Yes = "Yes";
  string No = "No";

  if (N % 2 != 0) drop(No);

  rep(i, N / 2) {
    if (S[i] != S[i + N / 2]) drop(No);
  }

  cout << Yes << endl;
}

struct exit_exception : public std::exception {
  const char* what() const throw() { return "Exited"; }
};

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

  try {
    solve();
  } catch (exit_exception& e) {
  }

  return 0;
}
#endif

template <typename T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}

template <typename T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

void print_ints(vector<ll> v) {
  rep(i, v.size()) {
    if (i > 0) {
      cout << " ";
    }

    cout << v[i];
  }

  cout << endl;
}

template <typename T>
void drop(T res) {
  cout << res << endl;
  throw exit_exception();
}


Measured memory_bytes: 256
N, M, R = gets.split.map(&:to_i)
r = gets.split.map(&:to_i).map{ |i| i-=1 }

d = Array.new(N){ Array.new(N,10**9) }

M.times do
  a, b, c = gets.split.map(&:to_i)
  a-=1
  b-=1
  d[a][b] = d[b][a] = c
end

(0...N).each{ |i| d[i][i] = 0 }

N.times do |k|
  N.times do |i|
    N.times do |j|
      v = d[i][k]+d[k][j]
      d[i][j] = v if d[i][j] > v
    end
  end
end

p = r.permutation(R).to_a
ans = 10**9

p.each do |k|
  dist = 0
  (1...R).each do |i|
    dist += d[k[i]][k[i-1]]
  end
  ans = dist if ans > dist
end

p ans

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

int main() {
  int x;
  cin >> x;
  
  int a = x / 100;
  int b = x % 100;
  
  bool ok = false;
  for (int i = 0; i <= 5*a; i++) {
    if (i == b) ok = true;
  }
  if (ok)
    cout << 1 << endl;
  else
    cout << 0 << endl;
}

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

int main() {
	int	N, Q;
	cin >> N >> Q;
	vector<list<int>> vec(N);
	list<int>::iterator	itr;
	rep(i, Q)
	{
		int a, b;
		cin >> a >> b;
		if (a == 0)
		{
			int	c;
			cin >> c;
			vec.at(b).push_back(c);
		}
		else if (a == 1)
		{
			for (itr = vec.at(b).begin(); itr != vec.at(b).end(); itr++)
			{
				if (itr != vec.at(b).begin())
					cout << ' ';
				cout << *itr;
			}
			cout << endl;
		}
		else if (a == 2)
		{
			int	c;
			cin >> c;
			itr = vec.at(c).end();
			vec.at(c).splice(itr, vec.at(b));
		}
	}
}



Measured memory_bytes: 18732
#include "bits/stdc++.h"
 
typedef long long ll;
#define int ll
#define fi first
#define se second
#define SORT(a) sort(a.begin(),a.end())
#define rep(i,n) for(int i = 0;i < (n) ; i++) 
#define REP(i,n) for(int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define INF LLONG_MAX/2
#define all(x) (x).begin(),(x).end()
#define debug(x) cerr<<#x<<": "<<x<<endl
#define debug_vec(v) cerr<<#v<<":";rep(i,v.size())cerr<<" "<<v[i];cerr<<endl
using namespace std;
int MOD = 1000000007;

signed main(){
    int n;
    cin >> n;
    int cnt = 0;
    for(int i = 1;i <= n;i++){
        if(i <= 9 || (100 <= i && i <= 999) || (10000 <= i && i <= 99999))cnt++;
    }
    cout << cnt << endl;


    return 0;
}

// g++ -std=c++14 code1.cpp
// rm -r -f test;oj dl https://cf17-final-open.contest.atcoder.jp/tasks/cf17_final_a
// rm -r -f test;oj dl http://abc136.contest.atcoder.jp/tasks/abc136_b


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

def bubbleSort(A, N):
    cnt = 0
    flag = True
    while flag:
        flag = False
        for j in range(N-1, 0, -1):
            if A[j] < A[j-1]:
                A[j], A[j-1] = A[j-1], A[j]
                cnt += 1
                flag = True
    return A, cnt
    
result = bubbleSort(a, n)
print(' '.join(map(str, result[0])))
print(result[1])



Measured memory_bytes: 5604
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ProblemB
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            var ps = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
            int ret = 0;
            for (int i = 0; i < n - 2; i++)
            {
                if (ps[i + 1] > ps[i] && ps[i + 1] < ps[i + 2])
                    ret++;
                else if (ps[i + 1] < ps[i] && ps[i + 1] > ps[i + 2])
                    ret++;
            }
            Console.WriteLine(ret);
        }
    }
}


Measured memory_bytes: 13268
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cmath>
#include <set>
#include <queue>
#include <deque>
#include <vector>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;

void getPrime(int n, vector<int>& list)
{
	vector<bool> isPrime(n + 1, true);

	for (auto i = 2; i <= n; ++i)
	{
		if (isPrime[i])
		{
			list.push_back(i);
			for (auto j = 2; (ll)i * j <= n; ++j)
			{
				isPrime[i * j] = false;
			}
		}
	}
}


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

	vector<int> list;
	getPrime(55555, list);
	auto num = 0;
	for (auto i = 0; i < (int)list.size(); ++i)
	{
		if (list[i] % 10 == 1)
		{
			if (num > 0)
			{
				cout << " ";
			}
			cout << list[i];
			++num;
			if (num >= N)
			{
				break;
			}
		}
	}
	cout << endl;
	
	return 0;
}

Measured memory_bytes: 256
//#pragma GCC optimize ("Ofast")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("avx,avx2,fma")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
#define pb push_back
#define F first
#define S second
#define ins insert
#define mp make_pair
#define fo(i, n1, n, x) for(int i = n1; i <= n; i += x)
#define foo(i, n, n1, x) for(int i = n; i >= n1; i -= x)
#define bit __builtin_popcount
#define md (l + ((r - l) / 2))
#define all(x) x.begin(),x.end()
#define eb emplace_back
#define ub upper_bound
#define lb lower_bound
#define ios ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define file(s) if (fopen(s".in", "r")) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout)

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;


using ll = long long;

//#define int ll


const int N = 1e3 + 11, mod = 1e9 + 7, mod2 = 998244353;
const int MAX = 1e5 + 11;
const int INF1 = 2e9 + 11;
const ll INF2 = 2e18 + 11;
const double INF3 = 1e8 + 11;
const int base = 500;
const int P = 31;
const int dx[] = {1, -1, 0, 0, 1, 1, -1, -1};
const int dy[] = {0, 0, 1, -1, 1, -1, 1, -1};
const double EPS = 1e-4;
const double PI = acos(-1.0);


template<typename T> using ordered_set = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }


typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef vector <int> vi;


mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int h, a;
main() {
    file("threesum");
    ios;
    cin >> h >> a;
    cout << (h + a - 1) / a;
    cerr << "\nTime elapsed: " << (clock() + 0.0) / CLOCKS_PER_SEC;
    return 0;
}
/**

*/


Measured memory_bytes: 256
import bisect,collections,copy,heapq,itertools,math,string
import sys
def S(): return sys.stdin.readline().rstrip()
def M(): return map(int,sys.stdin.readline().rstrip().split())
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())
N = I()
a = LI()
a.sort()
print(abs(a[0]-a[-1]))

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

#define int long long
using namespace std;

int32_t main() {

    int n;
    cin >> n;

    vector<int> h(n + 1, 0), dp(n, LLONG_MAX);
    dp[0] = 0;
    for (int i = 0; i < n; i++)
        cin >> h[i];
    for (int i = 0; i < n; i++) {
        for (int j : {i + 1, i + 2}) {
            if (j < n)
                dp[j] = min(dp[j], abs(h[i] - h[j]) + dp[i]);
        }
    }
    cout << dp[n - 1];
}





Measured memory_bytes: 1792
#ABC131
N,L = map(int,input().split())
f = 0
k = 0
j = []
for i in range(1,N+1):
    f += L+i-1
for i in range(1,N+1):
    k = L+i-1
    n = f-k
    p = abs(f-n)
    j.append(p)
if f >0:
    print(int(f-min(j)))
else:
    print(int(f+min(j)))

Measured memory_bytes: 3064
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc *bufio.Scanner
var out *bufio.Writer

func main() {
	sc = bufio.NewScanner(os.Stdin)
	//bytes, _ := ioutil.ReadFile("./stdin.txt")
	//sc = bufio.NewScanner(strings.NewReader(string(bytes)))
	out = bufio.NewWriter(os.Stdout)
	buf := make([]byte, 1<<20)
	sc.Buffer(buf, bufio.MaxScanTokenSize)
	sc.Split(bufio.ScanWords)
	defer out.Flush()

	n, m := nextInt(), nextInt()
	s := make([][]int, m)
	for i := 0; i < m; i++ {
		k := nextInt()
		s[i] = nextInts(k)
	}
	p := nextInts(m)

	result := 0
	for i := 0; i < 1<<n; i++ {
		light := 0
		for k := 0; k < m; k++ {
			bit := 0
			for j := 0; j < len(s[k]); j++ {
				if (1<<(s[k][j]-1))&i > 0 {
					bit++
				}
			}
			if bit&1 == p[k] {
				light++
			}
		}
		if light == m {
			result++
		}
	}

	fmt.Fprintln(out, result)

}

func next() string {
	sc.Scan()
	return sc.Text()
}
func nextInt() int {
	a, _ := strconv.Atoi(next())
	return a
}
func nextInts(n int) []int {
	ret := make([]int, n)
	for i := 0; i < n; i++ {
		ret[i] = nextInt()
	}
	return ret
}
func intMin(a, b int) int {
	if a > b {
		return b
	}
	return a
}
func intMax(a, b int) int {
	if a > b {
		return a
	}
	return b
}


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

#ifdef _MSC_VER
#pragma warning(disable:4996)
#endif

using namespace std;

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

	vector<int> length(n, 0);
	
	cin >> length[0];

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

		length[i] -= prev;
		prev += length[i];
	}

	length[0] += k - prev;

	int max_len = 0;
	for (int i = 0; i < n; i++) {
		max_len = max(max_len, length[i]);
	}

	cout << k - max_len;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for(int i = 0; i < n; i++)
#define all(a) a.begin(), a.end()
#define mod 1000000007
#define MOD 998244353
#define INF 40000000000000000
int dx8[8] = {-1, 0, 1, 1, 1, 0, -1, -1};
int dy8[8] = {1, 1, 1, 0, -1, -1, -1, 0};
int dx4[4] = {-1, 0, 1, 0};
int dy4[4] = {0, -1, 0, 1};
template <class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return 1;
    }
    return 0;
}
signed main() {
    int N, R;
    cin >> N >> R;
    if(N >= 10)
        cout << R << endl;
    else
        cout << R + 100 * (10 - N) << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;
int b[1010][4];
long long a[1010][4];
map<long long, int> m, m2, m4;
int mul2[5] = {1, 2, 4, 8, 16};
int mul4[5] = {1, 4, 16, 64, 256};
long long pp[1010][5];
long long go(long long v, int t) {
	long long res = 0;
	for (int i = 0; i <= t; i++) {
		if (m[v] < i) break;
		for (int j = 0; j <= t - i; j++) {
			if (m2[v] < j) break;
			int k = t - i - j;
			if (m4[v] >= k) {
				res += pp[m[v]][i] * pp[m2[v]][j] * pp[m4[v]][k] * mul2[j] * mul4[k];
			}
		}
	}
	return res;
}
int ti[1010];
void reg(int i, int x) {
	if (ti[i] == 4) {
		m4[a[i][0]] += x;
	}
	if (ti[i] == 2) {
		m2[*min_element(a[i], a[i] + 2)] += x;
	}
	if (ti[i] == 1) {
		m[*min_element(a[i], a[i] + 4)] += x;
	}
}
int main() {
	int n;
	scanf("%d", &n);
	pp[0][0] = 1;
	for (int i = 1; i < 1010; i++) {
		pp[i][0] = 1;
		for (int j = 1; j < 5; j++) {
			pp[i][j] = pp[i][j-1] * (i - j + 1);
		}
	}
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < 4; j++) {
			scanf("%d", &b[i][j]);
		}
		for (int j = 0; j < 4; j++) {
			for (int k = 0; k < 4; k++) {
				a[i][j] = (a[i][j] << 10) | b[i][(j+k)%4];
			}
		}
		int *v = b[i];
		if (v[0] == v[1] && v[1] == v[2] && v[2] == v[3]) {
			ti[i] = 4;
		} else if (v[0] == v[2] && v[1] == v[3]) {
			ti[i] = 2;
		} else {
			ti[i] = 1;
		}
		reg(i, 1);
	}
	long long ans = 0;
	for (int i = 0; i < n; i++) {
		int v[4];
		for (int j = 0; j < 4; j++) {
			v[j] = (a[i][0] >> ((3-j) * 10)) & 1023;
		}
		reg(i, -1);
		for (int j = i + 1; j < n; j++) {
			int w[4];
			for (int l = 0; l < 4; l++) {
				w[l] = (a[j][0] >> ((3-l) * 10)) & 1023;
			}
			reg(j, -1);
			for (int k = 0; k < 4; k++) {
				swap(w[0], w[1]);
				swap(w[2], w[3]);
				map<long long, int> f;
				for (int l = 0; l < 4; l++) {
					int u[4];
					u[0] = w[l];
					u[1] = w[(l+1)%4];
					u[2] = v[(l+1)%4];
					u[3] = v[l];
					long long z = 1ll << 61;
					for (int r = 0; r < 4; r++) {
						long long tmp = 0;
						for (int q = 0; q < 4; q++) {
							tmp = (tmp << 10) | u[(r+q)%4];
						}
						z = min(z, tmp);
					}
					f[z]++;
				}
				long long tmp = 1;
				for (map<long long, int>::iterator it = f.begin(); it != f.end(); it++) {
					tmp *= go(it->first, it->second);
				}

				ans += tmp;
				swap(w[0], w[1]);
				swap(w[2], w[3]);
				rotate(w, w + 1, w + 4);
			}
			reg(j, 1);
		}
		reg(i, 1);
	}
	printf("%lld\n", ans / 3);
	return 0;
}


Measured memory_bytes: 239744
#include<algorithm>
#include<climits>
#include<cmath>
#include<iomanip>
#include<iostream>
#include<list>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<utility>
#include<vector>

#define lint long long
#define REP(i, x, n) for(int i = x ; i < n ; i++)
#define rep(i, n) REP(i, 0, n)
#define repr(i, n) for(int i = n - 1 ; i >= 0 ; i--)
#define SORT(c) sort((c).begin(), (c).end())
#define SORT_INV(c) sort((c).begin(), (c).end(), greater<int>())
#define IINF (int)(1e9+10)
#define LLINF (lint)(1e18+10)

using namespace std;

struct Edge{
    int from, to, cost;
};

int n, m;
vector<Edge> edges;
vector<bool> done;
int dis[110][110];

int main(){
    cin >> n >> m;
    edges.resize(m);
    done.resize(m, false);
    rep(i, n){
        rep(j, n){
            if(i == j){
                dis[i][j] = 0;
            }else{
                dis[i][j] = IINF;
            }
        }
    }
    rep(i, m){
        int a, b, c;
        cin >> a >> b >> c;
        a--;
        b--;
        edges[i].from = a;
        edges[i].to = b;
        edges[i].cost = c;
        dis[a][b] = c;
        dis[b][a] = c;
    }
    rep(k, n){
        rep(i, n){
            rep(j, n){
                dis[i][j] = min(dis[i][j], dis[i][k] + dis[k][j]);
            }
        }
    }
    rep(i, m){
        if(dis[edges[i].from][edges[i].to] == edges[i].cost){
            done[i] = true;
        }
    }
    int ans = 0;
    rep(i, m){
        if(!done[i]){
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fo(i,a,b) for(int i=(a);i<(b);i++)
#define qi queue<int>
#define vi vector<int>
#define ll long long
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define pii pair<int,int>
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define fi first
#define se second
#define prq priority_queue
#define foreach(it,c) for(__typeof((c).begin()) it=c.begin();it!=c.end();it++)
//#define KEY_DOWN(VK_NONAME) ((GetAsyncKeyState(VK_NONAME) & 0x8000) ? 1:0)
using namespace std;
inline ll read(){
	ll x=0;
	int f=1;
	char c=getchar();
	for(;!isdigit(c);c=getchar()) if(c=='-')f=-f;
	for(;isdigit(c);c=getchar())x=x*10+(c-'0');
	return x*f;
}
inline void out(int x){
	if(x>=10)out(x/10);
	putchar(x%10+'0');
}
int main(){
	//freopen("a.in","r",stdin);
	//freopen("a.out","w",stdout);
	string s;
	cin>>s;
	if(s=="MON")cout<<6;
	if(s=="TUE")cout<<5;
	if(s=="WED")cout<<4;
	if(s=="THU")cout<<3;
	if(s=="FRI")cout<<2;
	if(s=="SAT")cout<<1;
	if(s=="SUN")cout<<7;
	return 0;
}

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


def num2alpha(num):
    if num <= 26:
        return chr(64+num)
    elif num % 26 == 0:
        return num2alpha(num//26-1)+chr(90)
    else:
        return num2alpha(num//26)+chr(64+num % 26)


print(num2alpha(n).lower())

Measured memory_bytes: 9172
#include <bits/stdc++.h>
#define SIZE 100005
#define MOD 1000000007
using namespace std;
typedef long long int ll;

int A[SIZE];
ll cnt[SIZE];

int main()
{
	int n;
	scanf("%d",&n);
	for(int i=0;i<n;i++) scanf("%d",&A[i]);
	cnt[0]=3;
	ll ret=1;
	for(int i=0;i<n;i++)
	{
		int a=A[i];
		ret=ret*cnt[a]%MOD;
		cnt[a]--;
		cnt[a+1]++;
	}
	printf("%lld\n",ret);
	return 0;
}

Measured memory_bytes: 1408
import java.util.*;
public class Main{
 public static void main(String[] args){
   Scanner sc = new Scanner(System.in);
 
   char[] c = sc.next().toCharArray();
   
   StringBuilder sb = new StringBuilder();
   for(int i=0;i<c.length;i++)
   {
     if(c[i]=='0') sb.append(0);
     else if(c[i]=='1') sb.append(1);
     else if(c[i]=='B'&&sb.length()!=0) sb.deleteCharAt(sb.length()-1);
   }
   System.out.println(sb.toString());
 }
}

Measured memory_bytes: 21716
#include <bits/stdc++.h>
using namespace std; inline void fileio(const char* in, const char* out) { freopen(in, "r", stdin); freopen(out, "w", stdout); }
#define TD typedef
#define forx(i,n) for(int i = 0; i < (n); ++i)
#define forxr(i,n) for(int i = (n)-1; i >= 0; --i)
TD long long ll; TD long double ld; TD pair<int,int> pii; TD pair<ll,ll> pll; TD vector<int> VI; TD vector<bool> VB; TD vector<ll> VL;
const char nl = '\n'; const int INF = 0x3f3f3f3f; const ll LINF = 0x3f3f3f3f3f3f3f3fll; const ld EPS = 1e-9, PI = acos(-1);
#define ff first
#define ss second
#define all(c) c.begin(),c.end()

const int N = 3005;
bool vis[N][N];
ll dp[N][N];
ll a[N], n;

ll solve(int l, int r) {
  if (l == r) return 0;
  if (!vis[l][r]) {
    dp[l][r] = max(
      a[r-1]-solve(l, r-1),
      a[l]-solve(l+1, r)
    );
    vis[l][r] = 1;
  }
  return dp[l][r];
}

int main() { // Emily <3
  atexit([](){ cerr << "Time: " << (ld)clock() / CLOCKS_PER_SEC << nl; });
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  cout << fixed << setprecision(12);
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  cout << solve(0, n) << nl;

  return 0;
}



Measured memory_bytes: 79872
#include <algorithm>
#include <bits/stdc++.h>
#include <cstdint>
#include <iostream>
#include <iterator>
#include <vector>

// lib/util.hpp
#ifndef UTIL_HPP
#define UTIL_HPP


typedef std::int_fast64_t i64;

namespace tools {
  template <typename T>
  void read(std::vector<T>& vector, const typename std::vector<T>::size_type size) {
    vector.reserve(size);
    std::copy_n(std::istream_iterator<T>(std::cin), size, std::back_inserter(vector));
  }

  template <typename T, std::size_t N>
  void read(std::array<T, N>& array) {
    std::copy_n(std::istream_iterator<T>(std::cin), N, array.begin());
  }
}

#endif

// main.cpp

int main() {
  std::string S;
  std::cin >> S;
  std::cout << 700 + 100 * std::count_if(S.begin(), S.end(), [](const char c) { return c == 'o'; }) << std::endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstring>
#include <vector>
#include <algorithm>
#include <set>
#include <stack>
#include <deque>
#include <cmath>
#include <map>
using namespace std;
using ll = long long;
#define rep(i, n) for (ll i = 0; i < n; i++)
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

int main() {
    ll n;
    cin >> n;
    vector<ll> a(n), b(n), c(n);
    rep(i, n) cin >> a[i] >> b[i] >> c[i];
    ll dp[100001][3];

    dp[0][0] = a[0];
    dp[0][1] = b[0];
    dp[0][2] = c[0];
    for(ll i = 1; i < n; i++) {
        dp[i][0] = max(dp[i-1][1], dp[i-1][2]) + a[i];
        dp[i][1] = max(dp[i-1][0], dp[i-1][2]) + b[i];
        dp[i][2] = max(dp[i-1][0], dp[i-1][1]) + c[i];
    }

    ll ans=0;
    rep(j, 3) chmax(ans, dp[n-1][j]);
    cout << ans << endl;
}

Measured memory_bytes: 4992