akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;

namespace NotFounds
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve();
        }

        public void Solve()
        {
            Console.ReadLine().Split(' ').Select(s => s[0]).Where(c => 'A' <=c && c <= 'Z').ToList().ForEach(Console.Write);
            Console.WriteLine();
        }
    }

    public class MyInputStream
    {
        private char separator = ' ';
        private Queue<string> inputStream;
        public MyInputStream(char separator = ' ')
        {
            this.separator = separator;
            inputStream = new Queue<string>();
        }

        public string Read()
        {
            if (inputStream.Count != 0) return inputStream.Dequeue();
            string[] tmp = Console.ReadLine().Split(separator);
            for (int i = 0; i < tmp.Length; i++)
            {
                inputStream.Enqueue(tmp[i]);
            }
            return inputStream.Dequeue();
        }
        public string ReadLine()   { return Console.ReadLine(); }
        public int    ReadInt()    { return int.Parse(Read()); }
        public long   ReadLong()   { return long.Parse(Read()); }
        public double ReadDouble() { return double.Parse(Read()); }
    }

    public class MyUtility
    {
        /// <summary>2値を入れ替える</summary>
        public static void Swap<T>(ref T m, ref T n)
        {
            T tmp = m;
            m = n;
            n = tmp;
        }

        public static void PutYN(bool f)
        {
        	Console.WriteLine(f ? "YES" : "NO");
        }
    }
}

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

int main() {
  ios::sync_with_stdio(false);
  set<int> S;
  int N, A;
  cin >> N;
  while (cin >> A) {
    if (S.count(A)) S.erase(A);
    else S.insert(A);
  }

  cout << S.size() << "\n";
}

Measured memory_bytes: 4992
import sys
from scipy.sparse.csgraph import dijkstra
from scipy.sparse import csr_matrix
read = sys.stdin.read

N, M, *abc = map(int, read().split())
a, b, c = zip(*zip(*[iter(abc)] * 3))

graph = csr_matrix((c, (a, b)), shape=(N + 1, N + 1))
distance = dijkstra(graph, directed=False)

answer = 0

for i, j, k in zip(a, b, c):
    k = float(k)
    if k != distance[i][j]:
        answer += 1

print(answer)

Measured memory_bytes: 22880
#include <bits/stdc++.h>
#define MAX 100005
using namespace std;

const int inf = 2147483647;
int n, k, dp[MAX][4], a[MAX], b[MAX], c[MAX];

int solve(int pos, int idx)
{
    if(pos >= n)
        return 0;
    if(dp[pos][idx] != -1)
        return dp[pos][idx];
    int ret = 0;
    if(idx == 0){
        ret = max(ret, a[pos] + solve(pos + 1, 1));
        ret = max(ret, a[pos] + solve(pos + 1, 2));
    }
    else if(idx == 1){
        ret = max(ret, b[pos] + solve(pos + 1, 0));
        ret = max(ret, b[pos] + solve(pos + 1, 2));
    }
    else{
        ret = max(ret, c[pos] + solve(pos + 1, 0));
        ret = max(ret, c[pos] + solve(pos + 1, 1));
    }

    return dp[pos][idx] = ret;
}

int main()
{
    // #ifndef ONLINE_JUDGE
    //     freopen("input.txt", "r", stdin);
    //     freopen("output.txt", "w", stdout);
    // #endif
    cin>>n;

    for(int i = 0; i < n; i++){
        cin>>a[i]>>b[i]>>c[i];
    }

    memset(dp, -1, sizeof(dp));
    int result = max(solve(0, 0), max(solve(0, 1), solve(0, 2)));

    cout<<result<<endl;

    return 0;
}

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

int main() {
  int N; cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++) cin >> A.at(i);
  long long ans = 0;
  map<int, int> M;
  for (int i = 0; i < N; i++) {
    if (M.count(i - A.at(i))) ans += M[i - A.at(i)];
    if (M.count(A.at(i) + i)) M[A.at(i) + i]++;
    else M[A.at(i) + i] = 1;
  }
  cout << ans << endl;
}

Measured memory_bytes: 13536
#include<iostream>

using namespace std;

int main()
{
    int n,a[20],b[20],c[20],s=0;

    cin>>n;

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

     for(int k=0;k<n;k++){
        cin>>b[k];
    }

     for(int l=0;l<n-1;l++){
        cin>>c[l];
    }

    for(int j=0;j<n;j++){
       int x=a[j];
       s+=b[x-1];
       if(j<n-1&&a[j+1]==x+1)
        s+=c[x-1];
    }

    cout<<s;


}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
#define ll long long
#define ld long double
#define F first
#define S second
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define pb push_back
#define mp  make_pair
#define all(v) (v).begin(), (v).end()
#define pb push_back
#define mp make_pair
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
ll INF = 1e6;

int gcd(int a, int b) 
{ 
    if (a == 0) 
        return b; 
    return gcd(b % a, a); 
} 
void solve()
{
    ll n, ans=0;
    cin>>n;
    for(ll i=1;i<=n;i++)
    {
        for(ll j=1;j<=n;j++)
        {
            ll temp=gcd(i,j);
            for(ll k=1;k<=n;k++)
                ans+=gcd(temp,k);
        }
    }
    cout<<ans;
}

 
int main()
{
    SPEED;
    ll t = 1;
    //cin>>t;
    while(t--) solve();
   return 0;
}


Measured memory_bytes: 3640
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
//#include<cctype>
#include<climits>
#include<iostream>
#include<string>
#include<vector>
#include<map>
//#include<list>
#include<queue>
#include<deque>
#include<algorithm>
//#include<numeric>
#include<utility>
#include<complex>
//#include<memory>
#include<functional>
#include<cassert>
#include<set>
#include<stack>

const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;

const int MAXN = 515;
int r[MAXN];
double pos[MAXN];

int main() {
    int N;
    cin >> N;
    for (int i = 0; i < N; i++) {
        cin >> r[i];
    }
    for (int i = 0; i < N; i++) {
        double p = r[i];
        for (int j = 0; j < i; j++) {
            double tmp = sqrt((r[i]+r[j])*(r[i]+r[j]) - (r[i]-r[j])*(r[i]-r[j])) + pos[j];
            p = max(p, tmp);
        }
        pos[i] = p;
    }
    double ans = 0;
    for (int i = 0; i < N; i++) ans = max(ans, pos[i]+r[i]);
    printf("%.15lf\n", ans);
    return 0;
}

Measured memory_bytes: 3208
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(300000)


def solve(S: str):
    if S[0] == S[1] or S[1] == S[2] or S[2] == S[3]:
        ret = "Bad"
    else:
        ret = "Good"
    print(ret)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = str(next(tokens))  # type: int
    solve(S)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include<bits/stdc++.h>
#include<string>
#include<vector>
using namespace std;
typedef pair<int, int>P;
typedef long long ll;
#define rep(i,n)for(ll i=0;i<n;++i)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll MOD = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 5000100;
//max=({});
//条件式が真ならwhileの中身を回し続ける
//printf("%d\n", ans);

//pairの入力
//vector<pair<ll, ll>>work(n);
//rep(i, n) {
//	ll a, b;
//	cin >> a >> b;
//	work[i] = make_pair(a, b);
//for(auto p:mp)(mapの探索)
//printf("%.10f\n",なんちゃら)
//最大公約数
ll gcd(ll x, ll y) {
	return y ? gcd(y, x % y) : x;
}

ll lcm(ll x, ll y) {
	if (x == 0 || y == 0)return 0;
	return (x / gcd(x, y) * y);
}

//組み合わせの余りを求める
ll fac[MAX_N], finv[MAX_N], inv[MAX_N];
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX_N; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 二項係数計算
long long COM(ll n, ll k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

ll dx[8] = { 0,0,-1,1 };
ll dy[8] = { -1,1,0,0 };
ll dp[101010];

//union-find木について
ll par[101010];
ll rank2[101010];

void init(ll n) {
	rep(i, n) {
		par[i] = i;
		rank2[i] = 0;
	}
}

ll find(ll x) {
	if (par[x] == x) {
		return x;
	}
	else {
		return par[x] = find(par[x]);
	}
}

void unite(ll x, ll y) {
	x = find(x);
	y = find(y);
	if (x == y)return;
	if (rank2[x] < rank2[y]) {
		par[x] = y;
	}
	else {
		par[y] = x;
		if (rank2[x] == rank2[y]) {
			rank2[x]++;
		}
	}
}

long long modpow(long long a, long long n, long long mod) {
	long long res = 1;
	while (n > 0) {
		if (n & 1) res = res * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}

bool graph[101][101];
vector<ll> to[101010];
vector<ll>ball(101010, 1);
char c[10][10];
bool visited[10][10];

//long longしか使わない
//素数は1より大きい
int main() {
	ll h, w;
	cin >> h >> w;
	rep(i, h) {
		rep(j, w) {
			cin >> c[i][j];
		}
	}
	ll j = 0;
	rep(i, h) {
		bool flag = false;
		while (1) {
			if (c[i][j] == '#') {
				visited[i][j] = true;
				flag = true;
				j++;
			}
			else if(c[i][j]!='#'&&flag==true) {
				j--;
				flag = false;
				break;
			}
			else {
				puts("Impossible");
				return 0;
			}
		}
	}
	rep(i, h) {
		rep(j, w) {
			if (c[i][j] == '#' && visited[i][j] == false) {
				puts("Impossible");
				return 0;
			}
		}
	}
	puts("Possible");
	return 0;
}


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

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

typedef long long LL;
const LL mod=1000000007;
#define MAX 10000
#define NIL -1
const double PI  = acos(-1.0);
const int INF = 1e9 + 7;
//-------------------------------------------


int main(){

    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,d,x;
    cin >> n >> d >> x;
    int a[n+1];
    int sum ,cho = 0;

    REP(i, n){
        cin >> a[i];
    }

    REP(i, n){

        sum = 1;
        for ( int j = 1; j <= d; j++){
            if( a[i]*j >= d){ break;}
            sum++;
            //dump(sum);

        }
        //dump(i);
        cho += sum;
        //dump(cho);
    }

    cout << cho + x << endl;

    return 0;
}


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

int main(){
    int k,s;
    int cnt;
    int z=0;

    cin >> k >> s;

    for(int x=0;x<=k;x++){
        for(int y=0;y<=k;y++){
            z = s-x-y;
            if(z>=0&&z<=k){
                cnt++;
            }
        }
    }
    cout << cnt << endl;
}

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

int main() {
    int n;
    string s;
    cin >> n >> s;
    int reds = 0;
    rep(i,n){
        if(s[i] == 'R'){
            reds++;
        }
    }
    int ans = 0;
    rep(i, reds) {
        if (s[i] == 'W') ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3748
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctype.h>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>

using namespace std;

#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i, n) REP(i, 0, n)
#define lengthof(x) (sizeof(x) / sizeof(*(x)))
#define FILL(ptr, value) FILL_((ptr), sizeof(ptr)/sizeof(value), (value))
template <typename T>
void FILL_(void * ptr, size_t size, T value){
  std::fill((T*)ptr, (T*)ptr+size, value);
}
//4方向ベクトル→↑←↓
int dx[] ={1,0,-1,0};
int dy[] ={0,-1,0,1};

int main()
{
  char s[]="012345678954321012345678";
 int len=24;
  int n;
  cin >>n;
  while(n--){
        int start,goal; cin>>start>>goal;
        int ans=100,ans_st,ans_finish;
        for(int i=0;i<len;i++){
            if(s[i]!=start+'0') continue;
            for(int j=i+1;j<len;j++){
                if(s[j]==goal+'0'){
		  if(ans>j-i){
		  ans=j-i;
		  ans_st=i;
		  ans_finish =j;
		  }
                }
            }
        }
	cout <<s[ans_st];
	cout <<" ";
	for(int i =ans_st+1;i <ans_finish;i++){
	  cout <<s[i]<<" ";
	}
	cout <<s[ans_finish];
	cout <<endl;
  }
  return 0;
}

Measured memory_bytes: 1152
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int[] array = new int[6];
        for (int i = 0; i < 6; i++) {
            array[i] = sc.nextInt();
        }
        if (array[4] - array[0] > array[5]) {
            System.out.println(":(");
        } else {
            System.out.println("Yay!");
        }
    }
}

Measured memory_bytes: 21972
object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val A, B, M = sc.nextInt()
  val as = Array.fill(A)(sc.nextInt())
  val bs = Array.fill(B)(sc.nextInt())
  val bargains = List.fill(M)(sc.nextInt() -> sc.nextInt() -> sc.nextInt()).map {
    case ((x, y), c) => as(x - 1) + bs(y - 1) - c
  }
  println(((as.min + bs.min) :: bargains).min)
}


Measured memory_bytes: 79496
use std::io::Read;
use std::collections::HashSet;
use std::cmp::min;

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

    let answer = solve(&buf);

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

fn solve(input: &str) -> String {
    let mut iterator = input.split_whitespace();

    let n: isize = iterator.next().unwrap().parse().unwrap();
    let k: isize = iterator.next().unwrap().parse().unwrap();

    let mut history: HashSet<isize> = HashSet::new();
    let mut x: isize = if n >= k { n % k } else { n };
    let mut ans: isize = x;
    while !history.contains(&x) {
        history.insert(x);

        x = (x - k).abs();
        ans = min(ans, x);
    }

    return ans.to_string();
}


Measured memory_bytes: 4352
#include<iostream>

using namespace std;

int main()
{
  long long n,b,r;
  cin >> n >> b >> r;
  
  long long one_num = b + r;
  
  
  long long ans;
  
  //if (one_num <= n/1000)
  //{
   // ans = b * 1000;
  //}else
  {
  
  long long num = n / one_num;
  long long amari = n % one_num;
  
  ans = num * b;
  ans += amari < b ? amari: b;
  }
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <random>
#include <tuple>
#include <iomanip>
#include <cstring>

using namespace std;

typedef long long ll;
//typedef pair<int,int> Pint;
//typedef pair<ll, ll> P;
typedef pair<ll, pair<ll, ll>> P;
//typedef tuple<int,int,int> T;
typedef vector<ll> vec;
typedef vector<vec> mat;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define revrep(i, n) for(ll i = (n-1); i >= 0; i--)
#define pb push_back
#define f first
#define s second
const ll INFL = 1LL << 60;//10^18 = 2^60
const int INF = 1 << 30;//10^9
const ll MOD = 1e9 + 7;
//ll MOD  = 998244353;
vector<ll> dy = {0, 0, 1, -1, 1, 1, -1, -1, 0};
vector<ll> dx = {1, -1, 0, 0, 1, -1, 1, -1, 0};

ll max(ll a, ll b){return (a > b) ? a : b;}
ll min(ll a, ll b){return (a < b) ? a : b;}
ll pow_long(ll x, ll k){
  ll res = 1;
  while(k > 0){
    if(k % 2) res *= x;
    x *= x;
    k /= 2;
  }
  return res;
}
ll pow_mod(ll x, ll k){
  x %= MOD; x += MOD; x %= MOD;
  ll res = 1;
  while(k > 0){
    if(k % 2){
      res *= x; res %= MOD;
    }
    x *= x; x %= MOD;
    k /= 2;
  }
  return res;
}
ll inverse(ll x){return pow_mod(x, MOD - 2);};

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

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


ll N, H, W;
int main(void){
   cin >> N >> H >> W;
   cout << (N-H+1) * (N-W+1) << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stack>
#include <bitset>

#define rep(i,n) for (int (i) = 0; (i) < (n); i++)
#define rep1(i,n) for (int (i) = 1; (i) <= (n); i++)
typedef long long int llint;

using namespace std;

const llint inf = pow(10, 12);

int main(void) {
	long double a, b, x;
	cin >> a >> b >> x;

	long double rad = 57.2957795131;

	if (2 * x > a * a * b) cout << std::setprecision(10) << (long double)atan((2 * a * a * b - 2 * x) / (a * a * a)) * rad << endl;
	else cout << std::setprecision(10) << (long double)atan((a * b * b) / (2 * x)) * rad << endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int N = 1000000 + 10;
const int p = 2019;
char s[N];
long long exgcd(long long a, long long b, long long &x, long long &y) {
    if (!b) {x = 1, y = 0;  return a; }
    else {long long g = exgcd(b, a % b, y, x); y -= x * (a / b); return g; }
}
long long dp[2][2050];
int main () {
    scanf("%s", s + 1);
    int n = strlen(s + 1), now = 0, nxt = 1;
    long long ans = 0;
    for (int i = 1; i <= n; i++, now ^= 1, nxt ^= 1) {
        int c = s[i] - '0';
        for (int j = 0; j < 2019; j++)  dp[nxt][(j * 10 + c) % p] = dp[now][j];
        dp[nxt][c]++;
        ans += dp[nxt][0];
    }
    printf("%lld\n", ans);
#ifndef ONLINE_JUDGE
    system("pause");
#endif
    return 0;
}

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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
string char_to_string(char val) {
    return string(1, val);
}

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

    ll res = pow(100, D) * N;

    if(D == 0 && N == 100) {
        cout << 101 << endl;
    } else if(D == 1 && N == 100) {
        cout << 10100 << endl;
    } else if(D == 2 && N == 100) {
        cout << 1010000 << endl;
    } else {
        cout << res << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// Welcome to my source code!

int main() {
    int n, color[9] = {};
    cin >> n;
    for (int i = 0, a; i < n; i++) {
        cin >> a;
        if (a <= 399) color[0]++;
        else if (a <= 799) color[1]++;
        else if (a <= 1199) color[2]++;
        else if (a <= 1599) color[3]++;
        else if (a <= 1999) color[4]++;
        else if (a <= 2399) color[5]++;
        else if (a <= 2799) color[6]++;
        else if (a <= 3199) color[7]++;
        else color[8]++;
    }
    int minc = 0, maxc = 0;
    for (int i = 0; i <= 8; i++) {
        if (i == 8) maxc += color[i];
        else if (color[i]) {
            minc++;
            maxc++;
        }
    }
    if (minc == 0) minc++;
    cout << minc << ' ' << maxc << endl;
}

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

#define ll long long int
#define vi vector<int>
using namespace std;

int main(){
    int n,k;
    cin >>n>> k;
    vector<int> v(n+1,0);
    for(int i=0;i<k;i++){
        int k1;
        cin >> k1;
        for(int j=0;j<k1;j++){
            int a;
            cin >> a;
            v[a]++;
        }
        
    }

        cout << (count(v.begin(),v.end(),0)) -1;
    
}

Measured memory_bytes: 3620
#include <iostream>
#include <algorithm>
#include <bitset>

int n, c;
int beats[31], types[31];
int dp[31][65536];

int bitCount(int n) {
    std::bitset<32> bit(n);

    return bit.count();
}

int main() {
    while(std::cin >> n >> c, n + c) {
        std::fill((int*)dp, (int*)dp + 31 * 65536, -1);

        for(int i = 0; i < n; ++i) {
            int a = 0, tmp;

            for(int j = 0; j < 16; ++j) {
                std::cin >> tmp;
                a |= tmp * (1 << j);
            }

            beats[i] = a;
        }

        for(int i = 0; i < c; ++i) {
            int a = 0, tmp;

            for(int j = 0; j < 16; ++j) {
                std::cin >> tmp;
                a |= tmp * (1 << j);
            }

            types[i] = a;
        }

        int res = 0;
        dp[0][0] = 0;
        for(int i = 0; i < n; ++i) {
            for(int j = 0; j < 65536; ++j) {
                if(dp[i][j] == -1)
                    continue;
                
                int pat = j | beats[i];

                for(int k = 0; k < c; ++k) {
                    int rem = pat & types[k];

                    dp[i + 1][pat - rem] = std::max(dp[i][j] + bitCount(rem), dp[i + 1][pat - rem]);
                }
                dp[i + 1][pat] = std::max(dp[i + 1][pat], dp[i][j]);
            }
        }

        for(int j = 0; j < 65536; ++j) {
            res = std::max(dp[n][j], res);
        }

        std::cout << res << std::endl;
    }
}

Measured memory_bytes: 9100
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define ll  long long int
#define pb push_back
#define IO ios::sync_with_stdio(false);
typedef vector<int> vi;
#define H return 0;
#define C continue;
#define B break;
#define sec second

int main()
{IO
  int a,b;
  cin>>a>>b;
  cout<<a*b-a-b+1;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,t,a,h,i,ans;
  double v=1000.0,w;
  cin>>n>>t>>a;
  for(i=1;i<=n;i++){
    cin>>h;
    w=abs(-0.006*h+t-a);
    if(w<v){
      v=w;
      ans=i;
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3628
#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <utility>
using namespace std;
using ll = long long;
 
int main() {
	string str;
	int n;
	cin >> n;
	cin >> str;
	if (n %2 == 1) {
		cout << "No" << endl;
		return 0;
	}
	int a = n/2;
	for (int i = 0;i < a; i++) {
		if (str[i] != str[i+a]) {
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	return 0;
}


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

using namespace std;

int a, b, c;

int main () {
  	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  	cin >> a >> b >> c;

  	if (a + b + 1 >= c) cout << b + c;
  	else cout << a + 2 * b + 1;

 	return 0;
}


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

int main(){
  
int N;
  cin >> N;
double x, sum;
string S;  
  sum == 0;
  
  for(int i = 0;i < N;i++){
  cin >> x >> S;
    if(S == "BTC") sum += x * 380000.0;
    else sum += x;
  }
    
  cout << sum << endl;  
  return 0;
  
}

Measured memory_bytes: 256
h, w, k = map(int, input().split())

c = [input() for i in range(h)]
count = 0

for a in range(2**(h)):
    for x in range(2**w):
        black = 0
        for b in range(h):
            for y in range(w):
                if ((a >> b) & 1) and (x >> y & 1) and c[b][y] == '#':
                    black += 1
        if black == k:
            count += 1

print(count)


Measured memory_bytes: 9144
H,W = map(int,input().split())
def trans(x):
    if x == '.':
        return False
    else:
        return True
a = []
for i in range(H):
    v = input()
    if v == '.'*W:
        H -= 1
    else:
        a.append(v)
test = [True for j in range(W)]
d = 0
for i in range(H):
    test = [True if test[j] and a[i][j] == '.' else False for j in range(W)]
for j in range(W):
    if test[j]:
        a = [a[i][:(j-d)]+a[i][(j-d+1):] for i in range(H)]
        d += 1
for i in range(H):
    print(a[i])

Measured memory_bytes: 3064
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// #include <ext/pb_ds/assoc_container.hpp>
//#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
//using namespace boost::multiprecision;
// using namespace __gnu_pbds;

#define all(c) (c).begin(),(c).end()
#define endl "\n"
#define ff first
#define ss second
#define allr(c) (c).rbegin(),(c).rend()
#define fr(x,in,n,r) for(ll x=in;x<n;x+=r)
#define ifr(x,n) for(ll x=0;x<n;x++)
#define dfr(x,n) for(ll x=n-1;x>=0;x--)
#define pb(a) push_back(a)
#define pf(a) push_front(a)
#define pof(a) pop_front(a)
#define pob(a) pop_back(a)
#define eb(a) emplace_back(a)
#define ef(a) emplace_front(a)
typedef long long ll;
typedef map<ll,ll> mll;
typedef map<string,ll> msll;
typedef vector<ll> vll;
typedef pair<ll,ll> pll;
typedef long double ld;
#define mod 1000000007

vll v[100001];
bool vis[100001]={0};
bool ans[100001];
map<pll,bool> m;

void dfs(ll u){
	vis[u]=1;
	ifr(i,v[u].size()){
		if(!vis[v[u][i]]){
			ans[v[u][i]]=ans[u] ^ m[pll(u,v[u][i])];
			dfs(v[u][i]);
		}
	}
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    //freopen("input.txt","r",stdin);
    ll n;
	cin>>n;
	ll x,y,r;
	ifr(i,n-1){
		cin>>x>>y>>r;
		m[pll(x,y)]=r&1;
		m[pll(y,x)]=r&1;
		v[x].pb(y);
		v[y].pb(x);
	}
	ans[1]=0;
	dfs(1);
	fr(i,1,n+1,1)
		cout<<ans[i]<<endl;
	return 0;
}

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

vector <int> G[100006];
vector <int> EDGE[100006];
int v[100006];

void dfs(int i,int c,int p){
  int k = 1;
  int j;

  for(j = 0;j < G[i].size();j++){
    int u = G[i][j]; int t = EDGE[i][j];
    if(u == p) continue;
    if(k == c) k++;
    v[t] = k; k++;
    dfs(u,v[t],i);
  }
}

int main(){
  int n;
  int i,t;
  int a,b;
  int d = -999999;

  scanf("%d", &n);
  for(i = 0;i < n - 1;i++){
    scanf("%d %d", &a, &b);
    G[a].push_back(b);
    EDGE[a].push_back(i);
    G[b].push_back(a);
    EDGE[b].push_back(i);
  }

  for(i = 1;i <= n;i++){
    t = G[i].size();
    if(d < t){
      d = t;
    }
  }

  dfs(1,-1,-1);

  printf("%d\n", d);
  for(i = 0;i < n - 1;i++){
    printf("%d\n", v[i]);
  }

  return 0;
}

Measured memory_bytes: 13440
S = input()

if len(S)%2:
    S = S[:len(S)-1]
else:
    S = S[:len(S)-2]
N = len(S)

while True:
    now = S[:N]
    L = len(now)
    if now[:L//2] == now[L//2:]:
        break
    N -= 2
print(N)


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

def f(n):
    print(n, flush = True)
    S = input()
    if S == 'Vacant':
        exit()
    return S

l = 0
r = N
S = f(l)
for i in range(20):
    mid = (l + r) // 2
    U = f(mid)
    len = mid - l + 1
    if (len % 2 == 0 and S != U) or (len % 2 and S == U):
        l = mid
        S = U
    else:
        r = mid


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

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  for (int& a : A) cin >> a;
  int tmp, ans = -1;
  for (int t = -100; t <= 100; t++) {
    tmp = 0;
    for (int a : A) {
      tmp += (a - t) * (a - t);
    }
    if (ans == -1 || tmp < ans) {
      ans = tmp;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define x first
#define y second
#define all(v) v.begin(), v.end()
#define compress(v) sort(all(v)), v.erase(unique(all(v)), v.end())
using namespace std;

typedef long long ll;

int n, a[202020], sum;

int main(){
    ios_base::sync_with_stdio(false); cin.tie(nullptr);
    cin >> n;
    for(int i=1; i<=n; i++){
        cin >> a[i]; sum ^= a[i];
    }
    for(int i=1; i<=n; i++) cout << (sum ^ a[i]) << " ";
}

Measured memory_bytes: 4324
# coding: utf-8
import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

A, B = lr()
mi8 = -(-A*25//2)
ma8 = -(-(A+1)*25//2)
mi10 = -(-B*10)
ma10 = -(-(B+1)*10)
mi = max(mi8, mi10)
ma = min(ma8, ma10)
if mi >= ma:
    answer = -1
else:
    answer = mi

print(answer)
# 58

Measured memory_bytes: 3064
if __name__ == "__main__":
    n, m = [int(x) for x in input().strip().split(' ')]
    hyp = set()
    for i in range(n):
        line = [int(x) for x in input().strip().split(' ')]
        if i == 0:
            hyp = set(line[1:])
            continue
        hyp = hyp.intersection(set(line[1:]))
    print(len(hyp))


Measured memory_bytes: 3060
#include <iostream>

using namespace std;

int main() {
string weather;
cin >> weather;
if (weather=="Sunny") {
    cout<< "Cloudy";
}
else if (weather== "Cloudy") {
    cout<< "Rainy";

}
else if (weather== "Rainy"){
    cout<< "Sunny";
    return 0;
}
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
	int m, f, r, sum;
	while (true) {
		cin >> m >> f >> r;
		if (m == -1 && f == -1 && r == -1) break;
		if(m == -1 || f == -1) cout << "F" << endl;
		else {
			sum = m + f;
			if      (sum >= 80) cout << "A" << endl;
			else if (sum >= 65) cout << "B" << endl;
			else if (sum >= 50) cout << "C" << endl;
			else if (sum >= 30) cout << (r >= 50 ? "C" : "D") << endl;
			else cout << "F" << endl;
			
		}
	}
	return 0;
}

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

using namespace std;

#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pair<int, int>> vpii;
typedef vector<pair<ll, ll>> vpll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

template<class T>
void print(vector<T>& V, bool spaced = true) {
    string space;
    spaced ? space = " " : space = "";
    for(int i = 0; i < V.size(); i++) {
        cout<< V[i] << space;
    }cout<< '\n';
}

template<class T>
void printendl(vector<T>& V) {
    for(int i = 0; i < V.size(); i++) {
        cout<< V[i] << '\n';
    }
}

template<class T>
T gcd(T a, T b) {
    T r;
    while (b != 0) {
        r = a % b;
        a = b;
        b = r;
    }
    return a;
}

template <class T>
T lcm (T a, T b) {
    return a / gcd(a, b) * b;
}

template<class T>
T Max(T a, T b) {
    return (a < b) ? b : a;
}

template<class T>
T Min(T a, T b) {
    return (a < b) ? a : b;
}

//str

bool isPalindrome(string str){
    
    int length = str.length();
 
    for (int i = 0; i < (length / 2); i++)
        if (str[i] != str[length - 1 - i])
            return false;
 
    return true;    
}

void reverseStr(string& str) 
{ 
    int n = str.length(); 
    for (int i = 0; i < n / 2; i++) 
        swap(str[i], str[n - i - 1]); 
}
 

//Read through the messages at the end when you're done

int main() {

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

    int n, m; cin>> n>>m;
    int sum = 0;
    rep(i, 0, m) {
        int x; cin>> x;
        sum += x;
    }

    if(sum > n) {
        cout << -1 << '\n';
    }else {
    cout << n-sum << '\n';

    
    }
    
    

    return 0;
}

    //Use long long da5eel rabbak!
    //Dont use endl;
    //DONT SUBMIT IZA UR NOT SURE WALLAHI BTENDAM
    //Dear Amine, just because it worked for the test cases doesnt necessarily mean it is correct.
    //Dear Amine, try it on ur own test cases iza ur not SURE
    //In case u didnt use long long, CHECK FOR POTENTIAL OVERFLOWS
    //DONT FORGET TO MOD EVERYTHING IZA U NEED TO MOD



Measured memory_bytes: 3628
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main(){
  char s[10],c[4];
  scanf("%s",&s);
  c[0]=s[5];
  c[1]=s[6];
  c[2]=s[8];
  c[3]=s[9];
  if (atoi(c)<431){
    printf("Heisei\n");
  }
  else {
    printf("TBD\n");
  }
  return 0;
}

Measured memory_bytes: 128
a, b, c = map(int, input().split())

if (a >= 1 and a <= 10000) and (b >= 1 and b <= 10000) and (c >= 1 and c <= 10000):
    listed = []
    listed.append(a)
    listed.append(b)
    listed.append(c)

    sorted = listed.sort()

    print(str(listed[0]) + " " + str(listed[1]) + " " + str(listed[2]))

Measured memory_bytes: 7696
N = int(input())
list_b = list(map(int, input().split()))
ans = [0 for i in range(N)]

finish = False

for i in range(N-1, -1, -1):
  mx = -1
  for k in range(i+1):
    if list_b[k] == k+1:
      mx = max(mx, k+1)
  if mx == -1:
    finish = True
    break
  else:
    ans[i] = mx
    for j in range(mx-1, i):
      list_b[j] = list_b[j+1]
    
if not finish:
    for i in range(N):
        print(ans[i])
else:
    print(-1)

Measured memory_bytes: 3064
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include <cmath>
#include <limits>
#include<set>
#include <iomanip>
#include <queue>
#include <map>
#include <string>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long long ll;
const long long INF=(1LL<<62);
const double inf=pow(10,10);
double pi=3.141592653589793;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const ll MOD = 1000000007;
void init(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
}

ll modper(ll n){
	if(n==1)return 1;
	else return n*modper(n-1)%MOD;
}

int main(){
	init();
	ll a,b;cin>>a>>b;
	ll N=max(a,b);
	ll M=min(a,b);
	if(N-M>1){
		cout<<0<<endl;
		return 0;
	}
	if(N==M){
		cout<<2*modper(N)*modper(M)%MOD<<endl;
	}else 
		cout<<modper(N)*modper(M)%MOD<<endl;
}


Measured memory_bytes: 1152
#include "bits/stdc++.h"

using namespace std;

typedef pair<int, int> P;
#define int long long
#define ll long long
#define mod 1000000007
#define INF (1LL<<60)

#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)


signed main(){


	int N, M;
	int cnt[31] = { 0 };

	cin >> N >> M;
	rep(i, N){
		int K; cin >> K;
		rep(j, K){
			int t; cin >> t;
			cnt[t]++;
		}
	}
	int ans = 0;
	for (int i = 1; i <=M; i++){
		if (cnt[i] == N) ans++;
	}
	cout << ans << endl;


	return 0;
}

Measured memory_bytes: 764
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <set>
#include <algorithm>
#include <array>
#include <complex>
#include <string>
#include <utility>
#include <map>
#include <queue>
#include <list>
#include <functional>
#include <numeric>
#include <stack>
#include <tuple>

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

int dx[4] = { -1,0,1,0 };
int dy[4] = { 0,1,0,-1 };
const int INF = 100000000;
const long long LINF = 1000000000000000000;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-6;
using pii = std::pair<int, int>;
using pLL = std::pair<long long, long long>;
using ll = long long;
#define SORT(v) std::sort(v.begin(), v.end())

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

    string S;
    cin >> S;
	ll dp[100010][4] = {};
    for (int i = (int)S.size(); i >= 0; --i) {
        for (int j = 3; j >= 0; --j) {
            if (i == S.size()) {
                if (j == 3)dp[i][j] = 1;
                else dp[i][j] = 0;
            }
            else {
                if (S[i] == '?') dp[i][j] = dp[i + 1][j] * 3;
                else dp[i][j] = dp[i + 1][j] * 1;

                if (j < 3 && (S[i] == '?' || S[i] == "ABC"[j])) {
                    dp[i][j] += dp[i + 1][j + 1];
                }
                dp[i][j] %= MOD;
            }
        }
    }
    cout << dp[0][0] << endl;
    return 0;
}

Measured memory_bytes: 3664
#!/usr/bin/env python3
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf')
ans = 0 ;count = 0 ;pro = 1

k,s=map(int,input().split())
for i in range(k+1):
    for j in range(k+1):
        if 0<=s-i-j<=k:
            count+=1
print(count)

Measured memory_bytes: 3316
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
#define rop(i,n) for(int i=1;i<n+1;i++)

using namespace std;
using std::swap;

vector<long long int> p;
vector<long long int> q;



int main() {
	int n;
	long long int ans=0;
	cin >> n;
	p.resize(n);
	rep(i, n)cin >> p[i];
	rep(i, n) {
		for (int j = i + 1; j < n; ++j) {
			ans += p[i] * p[j];
		}
	}
	cout << ans << "\n";
	return 0;

}

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

typedef long long ll;
typedef pair<ll, ll> pll;

#define m0(x) memset(x, 0, sizeof(x))
#define all(x) x.begin(), x.end()
#define rep(i, n) for(int i = 0; i < (n); i++)
#define asort(x) sort(all(x));
#define dsort(x, t) sort(x.begin(), x.end(), greater<t>());
#define dump(x) cout << #x << " = " << (x) << endl
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
#define MINS(m, s) m.insert(make_pair(s, 1));
#define MFIN(m, s) m.find(s) != m.end()
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl

const int INF = 1e9;
const ll LINF = 1e18;
const int mod = 1e9 + 7;

int main() {
    string s;
    cin >> s;
    if(s == "Sunny") {
        cout << "Cloudy" << endl;
    } else if(s == "Cloudy") {
        cout << "Rainy" << endl;
    } else {
        cout << "Sunny" << endl;
    }
    return 0;
}

Measured memory_bytes: 3544
#include<bits/stdc++.h>
#define re register
inline int read(){
	re int t=0;re char v=getchar();
	while(v<'0')v=getchar();
	while(v>='0')t=(t<<3)+(t<<1)+v-48,v=getchar();
	return t;
}
int n,m,a[1000002];
char s[1000002];
int main(){
	n=read();
	printf("%d",10-n/200);
}

Measured memory_bytes: 3748
#include <iostream>

using namespace std;
typedef long long ll;

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


int count2(int x)
{
    int c;
    for(c = 0;  x % 2 ==0; c++,x/=2);
    return c;
}


int min(int a , int b)
{
    return a < b ? a : b;
}

int main(void)
{
    int N,A[210];
    int m = 1000000000;
    cin >> N;
    REP(i, N) cin >> A[i];
    REP(i, N) m = min( count2(A[i]),m);
    cout << m << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void){
  int s,count=0,out_x[200],out_y[200],move_x[200]={},move_y[200]={},n,d,i,max_x,max_y,min_x,min_y,x,y;
  while(1){
    scanf("%d",&s);
    if(s==0){
      break;
    }
    
    move_x[0]=0;
    move_y[0]=0;
    min_x=0;
    min_y=0;
    max_x=0;
    max_y=0;
    for(i=0;i<s-1;i++){
      scanf("%d %d",&n,&d);
      if(n!=0){
	x=move_x[n-1];
	y=move_y[n-1];
      }
      else{
	x=0;
	y=0;
      }
      if(d==0)
	x--;
      if(d==1)
	y--;
      if(d==2)
	x++;
      if(d==3)
	y++;
      move_x[i]=x;
      move_y[i]=y;
      //printf("move %d %d\n",move_x[i],move_y[i]);
    }
    for(i=0;i<s-1;i++){
      if(max_x<move_x[i])
	max_x=move_x[i];
      if(max_y<move_y[i])
	max_y=move_y[i];
      if(min_x>move_x[i])
	min_x=move_x[i];
      if(min_y>move_y[i])
	min_y=move_y[i];
    }
    //    printf("max=%d %d\n",max_x,min_x);
    //printf("y=%d %d\n",max_y,min_y);
    if(min_x < 0)
    min_x=min_x*-1;
    if(min_y < 0)
    min_y=min_y*-1;
    
    max_x=max_x+min_x;
    max_y=max_y+min_y;
    out_x[count]=max_x+1;
    out_y[count]=max_y+1;
    count++;
    printf("%d %d\n",out_x[count-1],out_y[count-1]);
  }
  return 0;
}

Measured memory_bytes: 1028
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int K;
  int X;
  cin >> K >> X;
    
  if (X+K-1 >= 1000000) {
    for (int i= X-K+1; i<= 1000000; i++) {
      cout << i << " ";
    }
  }
  
  else if (X-K+1 <= -1000000) {
    for (int i= X+K-1; i>= -1000000; i--) {
      cout << i << " ";
    }
  }
  
  else {
    for (int i= X-K+1; i<= X+K-1; i++) {
      cout << i << " ";
    }
  }
  
    
}


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

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

typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, double> Pid;
typedef pair<double, int> Pdi;
const double PI = 3.1415926535897932;   // acos(-1)
const double EPS = 1e-15;
const int INF = 1001001001;
const int mod = 1e+9 + 7;

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

    int n;
    cin >> n;
    vector<ll> a(n);
    // bool flag = true;
    for(int i = 0; i < n; ++i){
        cin >> a[i];
        // if(a[i] >= n)   flag = false;
    }
    // if(flag){
    //     cout << 0 << endl;
    //     return 0;
    // }

    ll sum = accumulate(a.begin(), a.end(), 0ll);
    int limit = n * (n - 1);
    auto C = [](ll num, ll judge, vector<ll>& v){
        ll res = 0;
        int sz = v.size();
        for(int i = 0; i < sz; ++i){
            res += max(0ll, (v[i] - num) / (sz + 1));
        }
        return (res <= judge) && (res >= judge - sz);
    };
    
    ll res = 0;
    ll x = max(sum - limit, 0ll);
    if(sum > limit){
        for(int i = 0; i < n; ++i){
            a[i] += x;
        }
        ll lb = 0, ub = 1e+16 + 1001;
        while(ub - lb > 1){
            ll mid = (lb + ub) / 2;
            bool bs = C(mid, x, a);
            if(bs)  lb = mid;
            else    ub = mid;
        }
        for(int i = 0; i < n; ++i){
            ll cnt = max(0ll, (a[i] - lb) / (n + 1));
            res += cnt;
            a[i] -= cnt * (n + 1);
        }
    }
    
    auto processed = [](vector<ll>& v){
        int sz = v.size();
        for(int i = 0; i < sz; ++i){
            if(v[i] >= sz)  return false;
        }
        return true;
    };
    while(!processed(a)){
        sort(a.begin(), a.end(), greater<ll>());
        if(res >= x){
            a[0] -= n;
            for(int i = 1; i < n; ++i){
                a[i] += 1;
            }
            ++res;
        }
        else{
            a[0] -= n + 1;
            ++res;
        }
    }

    cout << res << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <complex>
using namespace std;

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

#define all(c) (c).begin(),(c).end()
#define pb push_back
#define mp make_pair
#define ERASE(v,i) (v).erase(remove(all(v),i),(v).end())
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define each(c,it) for(typeof((c).begin()) it=(c).begin();it!=(c).end();++it)
#define debug(x) cerr<<#x<<" = "<<(x)<<endl;
#define LINE cerr<<"LINE: "<<__LINE__<<endl;

inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}
template<class T> void preview(T a,T b){for(T it=a;it!=b;++it)cerr<<*it<<" ";cerr<<endl;}

const int INF = 100000000;
const double PI = acos(-1.0), EPS = 1e-10;

int main() {
	double ax,ay,bx,by,cx,cy,dx,dy;
	for(; cin>>ax>>ay>>bx>>by>>cx>>cy>>dx>>dy;) {
		cout << (fabs((bx - ax) * (dx - cx) + (by - ay) * (dy - cy)) < EPS ? "YES" : "NO") << endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define FOR(I,X,Y) for(int (I)=(X);(I)<(Y);(I)++)
#define REP(I,X,Y) for(int (I)=(Y)-1;(I)>=(X);(I)--)
#define ALL(X) (X).begin(),(X).end()
#define INF 1000000007
#define LINF 1000000000000000007
typedef long long ll;
using namespace std;

int main(){
  string S;
  cin >> S;
  FOR(i,0,4)cout << S[i];
  cout << ' ';
  FOR(i,4,12)cout << S[i];
  cout << endl;
}


Measured memory_bytes: 256
#include <stdio.h>

int A[100001];
int n;

int pratition(int *,int,int);

int main(){
    int i,j,q;

    scanf("%d",&n);

    for(i=0;i<n;i++){
      scanf("%d",&A[i]);  
    }
    q = pratition(A,0,n-1);

    for(i=0;i<n;i++){
        if(i==q) printf("[%d]",A[q]);
        else if(i!=q) printf("%d",A[i]);
        if(i != n-1) printf(" ");
    }
    printf("\n");
    return 0;
}

int pratition(int A[],int p,int r){
    int i,j;
    int temp,x;

    x=A[r];
    i=p-1;
    for(j=p;j<r;j++){
        if(A[j]<=x){
            i++;
            temp=A[j];
            A[j] = A[i];
            A[i] = temp; 
        }
    }
    temp = A[r];
    A[r] = A[i+1];
    A[i+1] = temp;
    return (i+1);
}



Measured memory_bytes: 2108
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,x,a[100],sum=0;
	cin>>n>>x;
	for(int i=0;i<n;i++)
		cin>>a[i];
	sort(a,a+n);
	for(int i=0;i<n;i++){
		sum+=a[i];
		if(sum>x){
			cout<<i<<endl;
			return 0;
		}
		if(sum==x){
			cout<<i+1<<endl;
			return 0;
		}
	}
	cout<<n-1<<endl;
}


Measured memory_bytes: 764
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define repr(i,n) for(ll i=(n-1);i>=0;i--)
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define br cout << endl;
using namespace std;
const int INF = 1e9;
const int MOD = 1e9+7;
using Graph = vector<vector<ll>>;
template<class T> inline bool chmin(T &a, T b) { if(a > b){ a = b; return true;} return false;}
template<class T> inline bool chmax(T &a, T b) { if(a < b){ a = b; return true;} return false;}

// 0 false, 1 true 
// stringの数字をint型にしてアスキーコードになったら -48する
// 切り上げ　ceil(a)



int main() {
    ll n;
    cin >> n;

    vector<vector<ll>> vec(n+1, vector<ll>(3));
    vector<vector<ll>> dp(n+1, vector<ll>(3));

    rep(i,n){
        rep(j,3){
            cin >> vec.at(i).at(j);
        }
    }

    //dp配列だけ[1]は1日目。他は[0]が1日目
    for(ll i = 0; i < n; i ++){
        for(ll j = 0; j < 3; j++){
            for(ll k = 0; k < 3; k++){
                if(j == k) continue;
                chmax(dp.at(i + 1).at(k), dp.at(i).at(j) + vec.at(i).at(k));
            }
        }
    }

    ll res = 0;
    rep(i,3){
        chmax(res, dp.at(n).at(i));
    }
    cout << res << endl;

}


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

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define repb(i, n) for (ll i = (n)-1; i >= 0; i--)
#define rep(i, n) repd(i, 0, n)

using namespace std;

using ll = long long;
using ul = unsigned long long;
using ld = long double;
ll mod = 1000000007;

int main() {
    ll n, k;
    cin >> n >> k;
    ll a[n];
    rep(i, n) { cin >> a[i]; }
    ll s[n + 1];
    s[0] = 0;
    rep(i, n) { s[i + 1] = s[i] + a[i]; }
    ll judge[n + 1];
    rep(i, n + 1) { judge[i] = (s[i] - i) % k; }

    map<ll, ll> num;
    ll ans = 0;
    rep(i, n + 1) {
        ans += num[judge[i]];
        num[judge[i]]++;

        ll index = i - k + 1;
        if (index >= 0) {
            num[judge[index]]--;
        }
    }

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



Measured memory_bytes: 20664
n=input()
for _ in xrange(n):
    b=[0]
    c=[0]
    a=map(int,raw_input().split())
    for i in a:
        if b[-1]<=c[-1]:
            if c[-1]<=i:
                c.append(i)
            elif b[-1]<=i:
                b.append(i)
        else:
            if b[-1]<=i:
                b.append(i)
            elif c[-1]<=i:
                c.append(i)
    if len(b)+len(c)==len(a)+2:
        print('YES')
    else:
        print('NO')

Measured memory_bytes: 6336