akhauriyash/Code-Regression huggingface dataset:
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <bits/stdc++.h>
#define ll long long
using namespace std;
void put(int x){
	if(x<0) {
		putchar('-');
		x*=-1;
	}
	if(x==0) {
		putchar('0');
	}
	int num=0;
	char c[15];
	while(x) {
		c[++num]=(x%10)+48;
		x/=10;
	}
	while(num) {
		putchar(c[num--]);
	}
	putchar('\n');
}
inline void in(int &x){
	char ch=getchar();
	int flag=1;
	while(!(ch>='0'&&ch<='9')) {
		if(ch=='-')
			flag*=-1;
		ch=getchar();
	}
	x=ch-'0';
	ch=getchar();
	while(ch>='0'&&ch<='9') {
		x=((x<<3)+(x<<1))+ch-'0';
		ch=getchar();
	}
	x*=flag;
}
int n,a[200005];ll f[200005],ans=1000000000000000;
int main(){
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	in(n);for(int i=1;i<=n;i++){in(a[i]);f[i]=f[i-1]+a[i];}
	for(int i=1;i<=n-1;i++)
	ans=min(ans,abs(f[i]-(f[n]-f[i])));
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 2560
N,M=map(int,input().split())
S=list(map(int,input().split()))
T=list(map(int,input().split()))
MOD=10**9+7
dp=[[0]*(M+1) for i in range(N+1)]
dp[0][0]=1
for i in range(N):
    dp[i+1][0]=1
for j in range(M):
    dp[0][j+1]=1
for i in range(N):
    for j in range(M):
        if S[i]==T[j]:
            dp[i+1][j+1]+=dp[i][j]
        dp[i+1][j+1]+=dp[i+1][j]+dp[i][j+1]-dp[i][j]
        dp[i+1][j+1]%=MOD
print(dp[N][M])


Measured memory_bytes: 73052
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <cstdio>
#include <cmath>

using namespace std;

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define EPS 1e-14

#define all(v) v.begin(),v.end()
#define INF 1<<30
#define mp make_pair
#define pb push_back

#define fi first
#define se second

#define each(it,c) for(auto it=(c).begin();it!=(c).end();it++)

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

typedef long long ll;

int main(){
	string s;
	cin >> s;
	if((int)s.find("YAKI") == 0){
		cout << "Yes" <<endl;
	}else{
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i,n) for (int i = (0); i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define show(x) cout << #x << " = " << (x) << endl
#define show2(x,y) cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl
#define show3(x,y,z) cout << #x << " = " << (x) << ", " << #y << " = " << (y) <<  ", " << #z << " = " << (z) << endl
#define showv(v) rep(i,v.size()) printf("%d%c", v[i], i==v.size()-1?'\n':' ')
#define showv2(v) rep(j,v.size()) showv(v[j])
#define showt(t,n) rep(i,n) printf("%d%c", t[i], i==n-1?'\n':' ')
#define showt2(t,r,c) rep(j,r) showt(t[j],c)
#define showvp(p) rep(i,p.size()) printf("%d %d\n", p[i].first, p[i].second);
#define printv(v) rep(i,v.size()) printf("%d\n", v[i])
#define printt(t,n) rep(i,n) printf("%d\n", t[i])
#define incl(v,x) find(rng(v),x)!=v.end()
#define incls(s,c) s.find(c)!=string::npos
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define bit(n,k) ((n>>k)&1) // nのk bit目
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
typedef vector<P> vp;
typedef vector<T> vt;
const int mod = 1000000007;
const double EPS = 1e-9;
const int INF = (1<<30)-1;
const ll INFLL = (1LL<<62)-1;
#define dame { puts("No"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
inline int in() { int x; scanf("%d",&x); return x;}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

P f(int x) {
  // x = b...a
  int a = x%10;//xの末尾
  int b = 0;
  while (x) {
    b = x;
    x /= 10;
  }
  return P(a,b);
}

int main () {
  int n;
  cin >> n;
  map<P,int> freq;
  rrep(i,n) {
    P p = f(i);
    freq[p]++;
  }
  ll ans = 0;
  rrep(i,n) {
    P p = f(i);
    P q(p.se, p.fi);
    ans += freq[q];
  }
  
  cout << ans << endl;
  return 0;
}

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

int main(void){
    set<int> paper;
    int N;
    cin>>N;
    rep(i,N){
        int x;
        cin>>x;
        if(paper.find(x)==paper.end()){
            paper.insert(x);
        }else{
            paper.erase(x);
        }
    }
    cout<<paper.size()<<endl;
    return 0;
}


Measured memory_bytes: 4864
#include<bits/stdc++.h>
using namespace std;
#define ll long long
 
 ll ar[2000007];
int main()
{
    ll test,c=0,i;
    map<ll,ll> mp;

    cin>>test;

    for(i=0;i<test;i++)
    {
        cin>>ar[i];
        mp[ar[i]]++;

    }
    for(i=0;i<test;i++)
    {
        if(mp[ar[i]]>1)
        {
            c=1;
            break;
        }
    }

    if(c==0)cout<<"YES"<<endl;
    else cout<<"NO"<<endl;




    return 0;
}


Measured memory_bytes: 14336
import java.util.*;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt() % 10;
		
		if(n == 2 || n == 4 || n == 5 || n == 7 || n == 9) {
			System.out.println("hon");
		} else if (n == 0 || n == 1 || n == 6 || n == 8){
			System.out.println("pon");
		} else {
			System.out.println("bon");
		}
		
	}
}

Measured memory_bytes: 35752
#include<bits/stdc++.h>
using namespace std;
int main(){
	long long a[3]={},b[3]={};
	int n=2,m=2;
	for(int i=0;i<2;i++){
		scanf("%lld",&a[i]);
		
	}
	if(a[0]<=0&&a[1]>=0)n=3;
	for(int i=0;i<2;i++){
		scanf("%lld",&b[i]);
	}
	if(b[0]<=0&&b[1]>=0)m=3;
	long long res;
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			if(i==0&j==0||res<a[i]*b[j]){
				res=a[i]*b[j];
			}
		}
	}
	cout<<res;
	
}

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

typedef long long ll;

const ll MOD = 1e9 + 7;
string L;
ll N;
vector<vector<ll>> Dp;

int main() {
  cin >> L;
  N = L.size();
  Dp.resize(N + 1);
  for (auto &dp : Dp) dp.resize(2);
  Dp[0][true] = 1;
  for (ll i = 0; i < N; ++i) {
    for (bool fit : {true, false}) {
      for (ll bit : {0, 1}) {
        if (bit <= L[i] - '0' || !fit)
          (Dp[i + 1][fit && bit == L[i] - '0'] +=
           (bit == 0 ? 1 : 2) * Dp[i][fit]) %= MOD;
      }
    }
  }
  cout << (Dp[N][0] + Dp[N][1]) % MOD << endl;
  return 0;
}


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

int main(void)
{
	int r,g,b;
	int n;
	scanf("%d %d %d\n",&r,&g,&b);
	n = r * 100 + g * 10 + b;
	if ((n % 4) == 0){
		printf("YES\n");
	}
	else {
		printf("NO\n");
	}
	return 0;
}


Measured memory_bytes: 128
#include<stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#define N 200001
#define MAX 100000
int A[MAX], n;

int partition(int p, int r) {
  int x, m, i, j;
    i = p-1;
  x = A[r];

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

int main() {
  int i, m;
  scanf("%d", &n);
  for ( i = 0; i < n; i++ ) scanf("%d", &A[i]);
  m = partition(0, n - 1);
  for ( i = 0; i < n; i++ ) {
    if ( i ) printf(" ");
    if ( i == m ) printf("[");
    printf("%d", A[i]);
    if ( i == m ) printf("]");
  }
  printf("\n");
  return 0;
}



Measured memory_bytes: 2144
import java.util.*;
public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        if (b - a == c - b) System.out.println("YES");
        else System.out.println("NO");
    }
}


Measured memory_bytes: 21972
a,o,r = 0,0,0
while 1:
    s = list(map(int,input().split()))
    s.sort()
    if(sum(s[:2]) <= s[2] or sum(s[1:3]) <= s[0] or s[0] + s[2] <= s[1]): break
    b = s[0]**2 + s[1]**2 - s[2]**2
    if b > 0: a+=1
    elif b < 0:o+=1
    else: r+=1         
print("{} {} {} {}".format(sum([a,o,r]),r,a,o))

Measured memory_bytes: 7620
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
const int INF = 1e9;
const int EPS = 1e-9; 

int main() {
  int N;
  cin >> N;
  vector<string> S(N);
  for (int i = 0; i < N; ++i) cin >> S.at(i), sort(S.at(i).begin(), S.at(i).end());
  
  map<string, long long int> m;
  for (int i = 0; i < N; ++i) m[S.at(i)] += 1;
  
  long long int cnt = 0;
  for (auto p : m) {
    cnt += (p.second-1) * p.second/2;
  }
  cout << cnt << endl;
}

Measured memory_bytes: 18176
package main

import (
	"bufio"
	"fmt"
	"io"
	"math"
	"os"
	"sort"
	"strconv"
)

var (
	readString func() string
	stdout     *bufio.Writer
)

func init() {
	readString = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readIntSlice(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = readInt()
	}
	return b
}

func readLengthAndSlice() []int {
	n := readInt()
	return readIntSlice(n)
}

func printf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(stdout, f, args...)
}

func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(stdout, args...)
}

func vi(n int, args ...int) []int {
	res := make([]int, n)
	if len(args) == 0 {
		return res
	}
	v := args[0]
	if v == 0 {
		return res
	}
	for i := 0; i < n; i++ {
		res[i] = v
	}
	return res
}

func vvi(n int, args ...int) [][]int {
	res := make([][]int, n)
	m := n
	if len(args) > 0 {
		m = args[0]
	}
	v := 0
	if len(args) > 1 {
		v = args[1]
	}
	for i := 0; i < n; i++ {
		res[i] = vi(m, v)
	}
	return res
}

// readString() string
// readInt() int
// readIntSlice(n int) []int
// readLengthAndSlice() []int
func max(a, b int) int {
	if a < b {
		return b
	}
	return a
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func abs(a int64) int64 {
	if a < 0 {
		return -a
	}
	return a
}

func main() {
	defer stdout.Flush()
	n := readInt()
	a := make([]int, n)
	b := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = readInt()
		b[i] = a[i] - (i + 1)
	}
	sort.Ints(b)
	var ans uint64 = math.MaxUint64
outer:
	for i := max(0, n/2-1); i < min(n, n/2+1); i++ {
		x := make([]int64, n)
		for j := 0; j < n; j++ {
			x[j] = abs(int64(a[j]) - int64(b[i]+j+1))
		}
		var sum uint64
		for j := 0; j < n; j++ {
			tmp := sum + uint64(x[j])
			if tmp < sum {
				continue outer
			}
			sum = tmp
		}
		if sum < ans {
			ans = sum
		}
	}

	println(uint64(ans))

}


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

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine(ABC088_C());
        }

        static string ABC088_C()
        {
            var C = new int[3, 3];
            var x = new int[3];
            var y = new int[3];
            for (var i = 0; i < 3; i++)
            {
                var c = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
                C[i, 0] = c[0];
                C[i, 1] = c[1];
                C[i, 2] = c[2];
            }

            x[0] = 0;

            for (var i = 0; i < 3; i++) y[i] = C[0, i] - x[0];
            for (var i = 1; i < 3; i++) x[i] = C[i, 0] - y[0];

            for (var i = 0; i < 3; i++)
            {
                for (var j = 0; j < 3; j++)
                {
                    if (C[i, j] != x[i] + y[j])
                        return "No";
                }
            }
            return "Yes";
        }
    }
}

Measured memory_bytes: 11348
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#define FOR(i,n,a) for(int i = a;i<n;i++)
#define rep(i,n) FOR(i,n,0)
#define UNFOR(i,n,a) for(int i = a;i>n;i--)
#define unrep(i,n) UNFOR(i,0.n)
typedef long long ll;
using namespace std;
int x, n;
string s;
int main() {
	cin >> n >> s;
	int ans = 0;
	rep(i, n) {
		map<char,bool> moji;
		int num = 0;
		FOR(j, i,0) {
			moji[s[j]] = true;
		}
		FOR(k,n,i) {
			if (moji[s[k]] == true) {
				num++;
				moji[s[k]] = false;
			}
		}
		ans = max(ans, num);
	}
	cout << ans << endl;
	return 0;
}


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

namespace abc058
{
    class Program
    {
        static void Main(string[] args)
        {
            var odd = Console.ReadLine();
            var even = Console.ReadLine();
            var password = string.Empty;
            if (odd.Length == even.Length)
            {
                for (int i = 0; i < odd.Length; i++)
                {
                    password += odd[i].ToString();
                    password += even[i].ToString();
                }
            }
            else
            {
                for (int i = 0; i < even.Length; i++)
                {
                    password += odd[i].ToString();
                    password += even[i].ToString();
                }

                password += odd.Last().ToString();
            }
            Console.WriteLine(password);
        }
    }
}


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

int main(){
    int ans=0,sum=0;
    int n,m;
    char c;
    string s;
    cin >>s;
    map<char,int> data;

    for (int i = 0; i < s.length(); i++){
        data[s[i]]++;
    }

    for (int i = 0; i < 26; i++)
    {
        if(data[(char)('a'+i)]==0){
            cout << (char)('a'+i) << endl;
            return 0;
        }
    }
    
    
    


    //cout <<fixed<<setprecision(16)<< << endl;
    cout << "None" << endl;
    //if(flag==1)cout << "Yes" <<endl;
    //else cout << "No" <<endl;
    
    return 0;
}


Measured memory_bytes: 512
n, m, x, y = [int(x) for x in input().split()]
X = [int(x) for x in input().split()]
Y = [int(x) for x in input().split()]
isOK = max(X)< min(Y) and x < max(X) and min(Y) <= y
print('No War' if isOK else 'War')


Measured memory_bytes: 38256
using namespace std;
#define _CRT_SECURE_NO_WARNINGS
#pragma target("avx")
#pragma optimize("O3")
#pragma optimize("unroll-loops")
#include<iostream>
#include<algorithm>
#include<ctime>
#include<vector>
#include<string>
#include<cmath>
#include<map>
#include<iomanip>
#include<numeric>
#include<queue>
#include<deque>
#include<cfloat>
#include<functional>
#include<tuple>
#include<math.h>
#include<bitset>
#include<stack>
#include<set>
#include<random>
#include<stdlib.h>
#define rip(i,n) for(ll i=0;i<n;i++)
#define Rip(i,n) for(ll i=1;i<n;i++)
#define all(V) V.begin(),V.end()
#define ll long long
#define ld long double
#define MOD 998244353
#define mod MOD
#define sec setprecision
constexpr double eps = 1e-9;
constexpr double PI = 3.141592653589793238462643383279;
ll gcd(ll a, ll b) {
	if (a % b == 0)	return(b);
	else return(gcd(b, a % b));
}
ll lcm(ll a, ll b)
{
	return a * b / gcd(a, b);
}
int ketasuu(ll h) {
	if (h < 0)return(-(ketasuu(-h)));
	else if (h < 10)return(1);
	else return(1 + ketasuu(h / 10));
}
const int MAX = 510000;
long long fac[MAX], finv[MAX], inv[MAX];
void cominit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (ll i = 2; i < MAX; 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;
	}
}
vector<ll> soinnsuubunnkai(ll n) {
	vector<ll>a;
	while (n % 2 == 0) {
		a.push_back(2);
		n /= 2;
	}
	ll f = 3;
	while (f * f <= n) {
		if (n % f == 0) {
			a.push_back(f);
			n /= f;
		}
		else f += 2;
	}
	if (n != 1)
		a.push_back(n);
	return(a);
}
// 二項係数計算
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 pow(ll a, ll b) {
	a = a % mod;
	if (b == 0)return(1);
	else if (b % 2 == 0)return(pow((a * a) % mod, b / 2));
	else return(a * (pow(a, b - 1)));
}
void solve() {
	int a, b;
	cin >> a >> b;
	if (a >= 13)cout << b << endl;
	else if (a >= 6)cout << b / 2 << endl;
	else cout << 0 << endl;
}
int main() {
	solve();
}


Measured memory_bytes: 256
#include <stdio.h>
#define N 100000
int a[N];

void swap(int s, int t){
  int tmp;
  a[s] = tmp;
  a[s] = a[t];
  a[t] = tmp;
}
int i;

int main(){
  int n;
  scanf("%d", &n);
  for(i=0;i<n;i++){
    scanf("%d", &a[i]);
  }
  int ans = 0;
  for(i=0;i<n-1;i++){
    if(a[i]==i+1){
      ans+=1;
      swap(i, i+1);
    }
  }

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


Measured memory_bytes: 512
loop do
  n, m = gets.chomp.split.map(&:to_i)

  break if n == 0 && m == 0

  nums = {}
  board = [0]

  n.times do
    num = gets.to_i
    board << num
    nums[num] = true
  end

  max_value = 0
  second_scores = board.repeated_combination(2).map(&:sum).uniq.sort

  second_scores.each do |n|
    a = 0
    b = second_scores.size - 1

    rem = m - n
    next if rem < 0

    while a < b
      c = (a + b) / 2

      if rem > second_scores[c]
        a = c + 1
      elsif rem < second_scores[c]
        b = c
      else
        break
      end
    end

    v = second_scores[b - 1]
    max_value = [max_value, n + v].max
  end

  puts max_value
end




Measured memory_bytes: 39964
import java.util.Arrays;
import java.util.Scanner;

class Main{

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int w = sc.nextInt();
		int h = sc.nextInt();

		boolean[] width = new boolean[w];
		boolean[] height = new boolean[h];

		Arrays.fill(width, false);
		Arrays.fill(height, false);

		for (int i = 0; i < n; i++) {
			int x = sc.nextInt();
			int y = sc.nextInt();
			int wireless = sc.nextInt();

			for(int j = Math.max(0, x - wireless); j < Math.min(w, x + wireless); j++) {
				width[j] = true;
			}

			for(int j = Math.max(0, y - wireless); j < Math.min(h, y + wireless); j++ ) {
				height[j] = true;
			}

		}

		sc.close();

		if( isFilledWithTrue(width) || isFilledWithTrue(height)) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}


	}

	public static boolean isFilledWithTrue(boolean[] bool) {

		for(int i=0; i<bool.length; i++) {
			if(bool[i] == false) {
				return false;
			}
		}
		return true;

	}

}

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

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

int main() {
    ll N;
    cin >> N;
    vector<ll> v(N);
    for(int i = 0; i < N; ++i) {
        cin >> v[i];
    }
    ll res = 0;
    ll add = 0;
    bool loop = true;
    while(loop) {
        loop = false;
        for(int i = 0; i < N; ++i) {
            res += v[i] / N;
            add += v[i] / N;
            v[i] = v[i] - N * (v[i] / N) - v[i] / N;
        }
        for(int i = 0; i < N; ++i) {
            v[i] += add;
            loop |= v[i] > N - 1;
        }
        add = 0;
    }
    cout << res << endl;
}


Measured memory_bytes: 256
N, M = list(map(int, input().split()))
ab = [list(map(int, input().split())) for _ in range(M)]
Q = int(input())
vdc = [list(map(int, input().split())) for _ in range(Q)]

L = [[] for _ in range(N)]
for a, b in ab:
  a -= 1
  b -= 1
  L[a].append(b)
  L[b].append(a)

D = [[0] * 11 for _ in range(N)]
Ans = [0] * N

def check(v, d, c):
  if D[v][d] != 0: return
  if d == 0:
    D[v][d] = c
    return
  for i in range(d, -1, -1):
    if D[v][i] != 0: break
    D[v][i] = c
  for i in L[v]:
    pass

import queue
Que = queue.Queue
get = queue.Queue.get
put = queue.Queue.put
emp = queue.Queue.empty

for v, d, c in vdc[::-1]:
  v -= 1
  if D[v][d] != 0: continue
  t = (d << 18) + v
  S = Que()
  put(S, t)
  while not emp(S):
    t = get(S)
    dd = t >> 18
    vv = t & ((1 << 18) - 1)
    if Ans[vv] == 0: Ans[vv] = c
    if dd == 0:
      D[vv][dd] = c
      continue
    for i in range(dd, -1, -1):
      if D[vv][i] != 0: break
      D[vv][i] = c
    for i in L[vv]:
      if D[i][dd - 1] != 0: continue
      t = ((dd - 1) << 18) + i
      put(S, t)

for i in Ans:
  print(i)

Measured memory_bytes: 150144
#[allow(dead_code)]
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}
#[allow(dead_code)]
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}
#[allow(dead_code)]
fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}
#[allow(dead_code)]
fn yn(result: bool) {
    if result {
        println!("Yes");
    } else {
        println!("No");
    }
}

fn main() {
    let v = read_vec::<u32>();
    let ab = v[0];
    let bc = v[1];
    let ca = v[2];

    println!("{}", ab*bc/2);
}


Measured memory_bytes: 4352
// by Balloons
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define mpr make_pair
#define debug() puts("okkkkkkkk")
#define rep(i,a,b) for(int (i)=(a);(i)<=(b);(i)++)

using namespace std;

typedef long long LL;

const int inf = 1e9;

int n,m,g[705][705],col[705],vis[705],num[705][705],bk,f[705][705];

void dfs(int x){
	vis[x] = 1;++ num[col[x]][bk];
	for(int i=1;i<=n;i++)
		if(i!=x && !g[x][i]){
			if(!vis[i])col[i] = col[x] ^ 1, dfs(i);
			else if(col[i] == col[x]){puts("-1");exit(0);}
		}
}
int c(int x,int y){return (x*(x-1) + y*(y-1)) / 2;}

int main(){
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;i++){
		int x,y;scanf("%d%d",&x,&y);
		g[x][y] = g[y][x] = 1;
	}
	for(int i=1;i<=n;i++)
		if(!vis[i])++bk, dfs(i);
	f[0][0] = 1;
	for(int i=0;i<bk;i++)for(int j=0;j<=n;j++)
		f[i+1][j+num[0][i+1]] |= f[i][j],
		f[i+1][j+num[1][i+1]] |= f[i][j];
	int ans = inf;
	for(int i=0;i<=n;i++)if(f[bk][i])ans = min(ans,c(i,n-i));
	printf("%d\n",ans);

	return 0;
}


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

int main(){
    int n;
    cin>>n;
    ll int sum=0;
    for(int i=1;i<=n;++i){
        if(i%3!=0 && i%5!=0)
            sum+=i;
    }
    cout<<sum<<endl;
    return 0;
}

Measured memory_bytes: 3596
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n, i, j, k;
    scanf("%d",&n);
    int a[n+5], b[n+5], c[n+5];
    for(i=1;i<=n;i++)
    {
        scanf("%d %d %d",&a[i],&b[i],&c[i]);
    }
    int dp[n+5][3];
    memset(dp, 0, sizeof(dp));
    for(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];
    }
    int ans = 0;
    ans = max(dp[n][0], dp[n][1]);
    ans = max(ans, dp[n][2]);
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 2560
#include<stdio.h>
int main(){
	int a,b;
	char op;
	while(1){
		scanf("%d %c %d",&a,&op,&b);
		if(op=='+'){
			printf("%d\n",a+b);
		}
		else if(op=='-'){
			printf("%d\n",a-b);
		}
		else if(op=='*'){
			printf("%d\n",a*b);
		}
		else if(op=='/'){
			printf("%d\n",a/b);
		}
		else if(op=='?'){
			break;
		}
	}
	return 0;
}


Measured memory_bytes: 2104
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

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

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

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

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

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

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

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

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

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

#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::{BinaryHeap, HashMap};

#[allow(dead_code)]
type Graph = Vec<Vec<usize>>;

fn main() {
    input! {
        n: usize,
        edges: [(usize1, usize1); n-1],
    }

    let mut graph = vec![vec![]; n];

    for &(f, t) in &edges {
        graph[f].push(t);
        graph[t].push(f);
    }

    let mut queue = BinaryHeap::new();
    let mut color = vec![None; n];
    queue.push((-1, 0));
    queue.push((-2, n-1));

    while !queue.is_empty() {
        let q = queue.pop().unwrap();
        let turn = q.0;
        let cur = q.1;
        if color[cur].is_some() {
            continue;
        }
        color[cur] = Some(turn & 1);

        for &n in &graph[cur] {
            if color[n].is_some() {
                continue;
            }
            queue.push((turn - 2, n));
        }
    }
    let black = color.iter().filter(|c| c.unwrap() == 1).count();
    let white = n - black;

    if black > white {
        println!("Fennec");
    } else {
        println!("Snuke");
    }
}


Measured memory_bytes: 14588
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <list>
#include <set>
#include <numeric>

#include <map>
#include <math.h>
#include <iomanip>
#include <stack>
#include <queue>
#include <bitset>
#include <math.h>

#define INF 100100100

typedef long long int llint;

using namespace std;

typedef pair<int, int>Pii;

#define pi 3.141592653589793)
#define mod 1000000007

int a;

int find(int n) {
	int value = a;
	int res = 0;
	for (int i = 0; i < n+1; i++) {
		res = value % 10;
		value /= 10;
	}
	return res;
}



int main() {
	cin >> a;
	if (find(3) + find(2) + find(1)+find(0) == 7)cout << find(3) << "+" << find(2) << "+" << find(1) << "+" << find(0);
	else if(find(3)+find(2) - find(1) + find(0) == 7)cout << find(3) << "+" << find(2) << "-" << find(1) << "+" << find(0);
	else if (find(3) + find(2) + find(1) - find(0) == 7)cout << find(3) << "+" << find(2) << "+" << find(1) << "-" << find(0);
	else if (find(3) + find(2) - find(1) - find(0) == 7)cout << find(3) << "+" << find(2) << "-" << find(1) << "-" << find(0);
	else if (find(3) - find(2) + find(1) + find(0) == 7)cout << find(3) << "-" << find(2) << "+" << find(1) << "+" << find(0);
	else if (find(3) - find(2) + find(1) - find(0) == 7)cout << find(3) << "-" << find(2) << "+" << find(1) << "-" << find(0);
	else if (find(3) - find(2) - find(1) + find(0) == 7)cout << find(3) << "-" << find(2) << "-" << find(1) << "+" << find(0);
	else if (find(3) - find(2) - find(1) - find(0) == 7)cout << find(3) << "-" << find(2) << "-" << find(1) << "-" << find(0);
	cout << "=7";
	return 0;
}


Measured memory_bytes: 256
# A - Kenken Race

N,A,B,C,D = map(int,input().split())
S = input()

should_change = int(C>D)
can_change = 0
space = 1
ans = 'Yes'

for i in range(A,max(C,D)):
    if S[i]=='.':
        space += 1
        if B<=i<=D and space==3:
            can_change = 1
    else:
        if space==0:
            ans = 'No'
            break
        space = 0

if can_change<should_change:
    ans = 'No'
print(ans)

Measured memory_bytes: 3572
#include <iostream>
#include <vector>
#include <string>
#include <cstdio>
using namespace std;
template<class A> struct UnionFind {
       vector<int> p;
       vector<int> rank;
       vector<A> diff_weight;
       UnionFind(int n = 1, A UNITY = 0) {
              init(n, UNITY);
       }
       void init(int n = 1, A UNITY = 0) {
              p.resize(n); rank.resize(n); diff_weight.resize(n);
              for (int i = 0; i < n; ++i) p[i] = i, rank[i] = 0, diff_weight[i] = UNITY;
       }
       int root(int x) {
              if (p[x] == x) {
                     return x;
              }
              else {
                     int r = root(p[x]);
                     diff_weight[x] += diff_weight[p[x]];
                     return p[x] = r;
              }
       }
       A weight(int x) {
              root(x);
              return diff_weight[x];
       }
       bool same(int x, int y) {
              return root(x) == root(y);
       }
       bool unite(int x, int y, A w) {
              w += weight(x); w -= weight(y);
              x = root(x); y = root(y);
              if (x == y) return false;
              if (rank[x] < rank[y]) swap(x, y), w = -w;
              if (rank[x] == rank[y]) ++rank[x];
              p[y] = x;
              diff_weight[y] = w;
              return true;
       }
       A diff(int x, int y) {
              return weight(y) - weight(x);
       }
};

int main() {
  int N, M;
  cin >> N >> M;
  UnionFind<int> uf(N);
  for (int i = 0; i < M; ++i) {
     int a, b, c, d;
     cin >> a;
     if (a == 0) {
      cin >> b >> c >> d;
       uf.unite(b, c, d);
     }
   else {
   cin >> b >> c;
   if (!uf.same(b, c)) cout << "?" << endl;
    else cout << uf.diff(b, c) << endl;
   }
  }
}



Measured memory_bytes: 3884
N = int(input())
R = []
for i in range(N):
    s = input().split()
    s.append(i+1)
    s[1] = int(s[1])
    R.append(s)
R.sort(key=lambda x:x[1], reverse=True)
R.sort(key=lambda x:x[0])
for i in range(len(R)):
    print(R[i][2])

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

int n,m;
int f[20][20];
int tmp[20][20];
void copy(){
	for(int i=0;i<400;i++)tmp[i/20][i%20]=f[i/20][i%20];
}

void rot(int r,int c,int s,int t){
	if(t==90)t=1;
	if(t==180)t=2;
	if(t==270)t=3;
	if(t==360)t=4;
	while(t--){
		copy();
		for(int y=r,X=c;y<=r+s-1;y++,X++){
			for(int x=c,Y=r+s-1;x<=c+s-1;x++,Y--){
				f[x][y]=tmp[X][Y];
			}
		}
	}
}

void rev(int r,int c,int s){
	for(int y=r;y<=r+s-1;y++){
		for(int x=c;x<=c+s-1;x++){
			f[x][y]^=1;
		}
	}
}

void lsft(int r){
	int t=f[1][r];
	for(int x=1;x<n;x++)f[x][r]=f[x+1][r];
	f[n][r]=t;
}

void rsft(int r){
	int t=f[n][r];
	for(int x=n;x>1;x--)f[x][r]=f[x-1][r];
	f[1][r]=t;
}

void ilnd(int r,int c){
	int t=f[c][r];
	stack<int>X,Y;
	X.push(c);Y.push(r);
	int dx[4]={0,1,0,-1};
	int dy[4]={1,0,-1,0};
	while(!X.empty()){
		int x=X.top(),y=Y.top();
		X.pop();Y.pop();
		if(f[x][y]==t){
			f[x][y]^=1;
			for(int i=0;i<4;i++){
				if(f[x+dx[i]][y+dy[i]]==t){
					X.push(x+dx[i]);Y.push(y+dy[i]);
				}
			}
		}
	}
}

int main(){
	
	while(cin>>n>>m){
		for(int i=0;i<400;i++)f[i/20][i%20]=2;
		for(int y=1;y<=n;y++){
			for(int x=1;x<=n;x++){
				cin>>f[x][y];
			}
		}
		while(m--){
			int o;cin>>o;
			int r,c,s,a;
			if(o==0){
				cin>>r>>c>>s>>a;
				rot(r,c,s,a);
			}
			if(o==1){
				cin>>r>>c>>s;
				rev(r,c,s);
			}
			if(o==2){
				cin>>r;
				lsft(r);
			}
			if(o==3){
				cin>>r;
				rsft(r);
			}
			if(o==4){
				cin>>r>>c;
				ilnd(r,c);
			}
		}
		for(int y=1;y<=n;y++){
			for(int x=1;x<=n;x++){
				cout<<f[x][y]<<" \n"[x==n];
			}
		}
	}
	
	return 0;
}


Measured memory_bytes: 1204
#include<bits/stdc++.h>
#include <array>
using namespace std;
using ULL = unsigned long long;
using UL = unsigned;
using LL = long long;
#define rep(i, n) for(UL i = 0; i < (n); i++)

template<class Ty>
using passive_queue = priority_queue<Ty, vector<Ty>, greater<Ty>>;

struct UF {
	UL N;
	vector<UL> V;
	UF(UL n) { N = n; V.resize(N); rep(i, N) V[i] = i; }
	UL root(UL a) { if (V[a] == a) return a; return V[a] = root(V[a]); }
	void unite(UL a, UL b) { V[root(a)] = root(b); }
};

struct Problem {

	void Solve() {
		UL N, M; cin >> N >> M;
		vector<UL> P(N); rep(i, N) { cin >> P[i]; P[i]--; }
		vector<UL> F(N);
		UF G(N);
		rep(i, M) {
			UL u, v; cin >> u >> v; u--; v--;
			G.unite(u, v);
		}
		UL ans = 0;
		rep(i, N) {
			UL p = P[i];
			if (F[p]) continue;
			if (G.root(i) == G.root(p)) { ans++; F[p] = 1; }
		}
		cout << ans << endl;
	}
	
	Problem();
};
int main() {
	unique_ptr<Problem> p(new Problem());
	p->Solve();
	return 0;
}
Problem::Problem() {
	cout << fixed << setprecision(10);
}


Measured memory_bytes: 1408
def scan_row(row):
    if row[0] == row[1] == row[2]:
        if row[2] == row[3]:
            if row[3] == row[4]:
                return (row[0]*5, 0, 5)
            else:
                return (row[0]*4, 0 ,4)
        else:
            return (row[0]*3, 0 ,3)
    elif row[1] == row[2] == row[3]:
        if row[3] == row[4]:
            return (row[1]*4, 1, 4)
        else:
            return (row[1]*3, 1, 3)
    elif row[2] == row[3] == row[4]:
        return (row[2]*3 , 2, 3)
    return (-1,-1,-1)

while True:
    H = int(input())
    if H == 0: break
    src = [list(map(int,input().split())) for i in range(H)]
    mem = [[] for i in range(5)]
    for row in reversed(src):
        for x in range(5):
            mem[x].append(row[x])
    ans = 0
    while True:
        erase = []
        for h in range(max(map(len,mem))):
            row = tuple(map(lambda x:x[h] if h < len(x) else -1, mem))
            score,start,l = scan_row(row)
            if score <= 0: continue
            ans += score
            erase.append((h,start,l))
        if not erase: break
        for h,start,l in reversed(erase):
            for i in range(start,start+l):
                mem[i].pop(h)
    print(ans)

Measured memory_bytes: 5728
#include <stdio.h>
#include <math.h>


int main()
{
    char s[100];
    long int a;
    int flag = 1;
    int i = 0;
    int cnt = 0;
    scanf("%s",s);
    scanf("%ld",&a);
    
    while(flag)
    {
        if(s[i]  == '1'){
            cnt++;
            i++;
            continue;
        }
        
        flag = 0;
            
    }
    
    if(a>cnt)
    {
        printf("%c\n",s[cnt]);
        return 0;
    }
    
    else
    {
        printf("1\n");
        return 0;
        
    }
    
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define ll long long int
#define mod 1000000007
#define f(i,a,b) for(ll i=a;i<b;i++)
#define rf(i,a,b) for(ll i=a;i>=b;i--)
#define rep(i,n) f(i,0,n)
#define rrep(i,n) rf(i,n-1,0)
#define w(t) ll t; cin>>t; while(t--)
#define vi vector<ll>
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define mii map<ll,ll>
#define mci map<char,ll>
using namespace std;

void fast_IO_file()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}

int main()
{
	fast_IO_file();

	int n, m, sum = 0;
	cin >> n >> m;

	int a[n + 1];

	rep(i, n)
	cin >> a[i];


	sort(a, a + n);

	rep(i, m)
	sum += a[i];


	cout << sum << endl;



	return 0;
}

Measured memory_bytes: 3656
n,m,k = map(int,input().split()) 
Al=list(map(int,input().split()) )
Bl=list(map(int,input().split()) )
bmax=0
A=[0]
B=[0]
for i in range(1,n+1):
    A.append(A[i-1]+Al[i-1])  
for i in range(1,m+1):
    B.append(B[i-1]+Bl[i-1])
    if B[i]<=k:
        bmax=i

ans=0
b=bmax
for a in range(len(A)):
    if A[a]>k:
        break
    # ans = max(ans, a+1)
    
    while A[a] + B[b] >k and b>=0:
        b -= 1
        
        
    ans = max(ans, a+b)
        
print(ans)


Measured memory_bytes: 134168
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<set>
#include<map>
#include<iostream>
using namespace std;
#define re register
#define ll long long
inline int gi(){
	int f=1,sum=0;char ch=getchar();
	while(ch>'9' || ch<'0'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0' && ch<='9'){sum=(sum<<3)+(sum<<1)+ch-'0';ch=getchar();}
	return f*sum;
}
int main(){
	int n=gi();
	printf("%lld\n",1ll*(n-2)*180);
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define P pair<long,long>
#define INF 1000000000000000000
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; }
const long long MOD = 1000000007;
using namespace std;
typedef long long ll;
map<int, int> mp;
//最大公約数
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
//最小公倍数
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
class Union_Find {
private:
	vector<int> par;
	vector<int> rank;
public:
	Union_Find(int n) {
		rep(i, n) {
			par.push_back(i);
			rank.push_back(0);
		}
	}
	int find(int x) {
		if (par.at(x) == x) return x;
		else return par.at(x) = find(par.at(x));
	}
	void unite(int x, int y) {
		x = find(x);
		y = find(y);
		if (x == y) return;
		if (rank.at(x) < rank.at(y)) {
			par.at(x) = y;
		}
		else {
			par.at(y) = x;
			if (rank.at(x) == rank.at(y)) rank.at(x)++;
		}
	}
	bool same(int x, int y) {
		return find(x) == find(y);
	}
};

signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n; cin >> n;
	vector<int>a(n), b(n); rep(i, n) { cin >> a[i]; b[i] = a[i]; }
	sort(b.begin(), b.end());
	rep(i, n) {
		if (i == n - 1)cout << b[i] << endl;
		else cout << b[i] << " ";
	}
	int minj = 0;
	int ans = 0;
	rep(i, n) {
		minj = i;
		for (int j = i; j < n; j++) {
			if (a[j] < a[minj]) minj = j;
		}
		swap(a[i], a[minj]);
		if(a[i]!=a[minj])ans++;
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 3216
#include <cstdio>
int n, m, k, i, j;
int main() {
	scanf("%d%d%d", &n, &m, &k);
	for(i=0; i<=n; i++) for(j=0; j<=m; j++)
		if((n-i)*j + (m-j)*i == k) return puts("Yes"), 0;
	puts("No");
}

Measured memory_bytes: 128
#include <cstdio>
#include <vector>
#include <cmath>
using namespace std;


struct point3{
	double x, y, z;
	point3(double x, double y, double z): x(x), y(y), z(z) {}
};

double dot(const point3 &p1, const point3 &p2){
	return p1.x * p2.x + p1.y * p2.y + p1.z * p2.z;
}

double abs(const point3 &p1){
	return sqrt( dot(p1, p1) );
}


int main(){
	int n, m;
	double x, y, z;
	while( scanf("%d", &n), n != 0 ){
		vector<point3> s, t;
		s.reserve(n);
		
		for(int i = 0; i < n; ++i){
			scanf("%lf%lf%lf", &x, &y, &z);
			s.push_back( point3(x, y, z) );
		}

		scanf("%d", &m);
		t.reserve(m);
		vector<double> phi(m);
		for(int i = 0; i < m; ++i){
			scanf("%lf%lf%lf%lf", &x, &y, &z, &phi[i]);
			t.push_back( point3(x, y, z) );
		}
		
		int cnt = 0;
		for(int i = 0; i < n; ++i){
			for(int j = 0; j < m; ++j){
				double theta = acos( dot(s[i], t[j]) / abs(s[i]) / abs(t[j]) );
				if( theta < phi[j] ){
					++cnt;
					break;
				}
			}
		}
		printf("%d\n", cnt);
	}
}

Measured memory_bytes: 1156
// Author: HarshKumar

#include <bits/stdc++.h>
using namespace std;
#define ll int64_t
const ll N = 1e6 + 6, M = 1e9 + 7;
int main()
{
    ios::sync_with_stdio(false), cin.tie(nullptr);
    ll x, ans = 0;
    cin >> x;
    ans += x / 500 * 1000;
    x %= 500;
    ans += x / 5 * 5;
    cout << ans;
    return 0;
}

Measured memory_bytes: 256
import math
n = int(input())
m = math.ceil(math.sqrt(n))*2

ans = len(str(n))
for i in range(1, m+1):
    if n % i == 0:
        tmp = max(len(str(i)), len(str(int(n/i))))
        ans = min(ans, tmp)

print(ans)


Measured memory_bytes: 3060
// https://abc007.contest.atcoder.jp/tasks/abc007_4

#include <iostream>
#include <vector>
#include <array>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <algorithm>
#include <iomanip>

using namespace std;

static const long long mod = 1000000007;

void add_mod(long long& lhs, long long rhs) {
	auto res = (lhs + rhs) % mod;
	if (res < 0) res += mod;
	lhs = res;
}

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

	vector<vector<vector<long long>>> dp(s.size() + 1, vector<vector<long long>>(2, vector<long long>(d, 0)));
	dp[0][0][0] = 1;
	for (int i = 0; i < s.size(); i++) {
		int c_num = s[i] - '0';
		for (int j = 0; j < 2; j++) {
			for (int k = 0; k < d; k++) {
				for (int l = 0; l <= (j == 1 ? 9 : c_num); l++) {
					int next_mod = (k + l) % d;
					add_mod(dp[i + 1][(j || l < c_num) ? 1 : 0][next_mod], dp[i][j][k]);
				}
			}
		}
	}

	long long res = 0;
	add_mod(res, dp[s.size()][0][0]);
	add_mod(res, dp[s.size()][1][0]);
	add_mod(res, -1);

	cout << res << endl;
}


Measured memory_bytes: 17024
#include<iostream>
#include<algorithm>
using namespace std;
static const int MAX = 200000;

int main() {
  int n, max_prof, R_min, cur;

  cin >> n;
  max_prof = 1 - 1e9;

  // 最初だけ例外処理
  cin >> R_min;

  for(int i = 1; i < n; i++){
    cin >> cur;
    max_prof = max(cur - R_min, max_prof);
    R_min = min(cur, R_min);
  }

  cout << max_prof << endl;
  return 0;
}


Measured memory_bytes: 3112
# -*- coding: utf-8 -*-
a,b,c,d=map(int,input().split())
cntC=b//c-(a-1)//c
cntD=b//d-(a-1)//d
c1,d1=c,d
if c1<d1:
    c1,d1=d1,c1
while c1%d1!=0:
    c1,d1=d1,c1%d1
d1=int(c*d/d1)
cntCandD=b//d1-(a-1)//d1
ans=int(b - a + 1 - cntC - cntD + cntCandD)
print(ans)

Measured memory_bytes: 3316
#include <algorithm>
#include <climits>
#include <complex>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

// using
using namespace std;

// typedef
typedef long long ll;

// define
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REVERSE(c) reverse(ALL(c))
#define UNIQ(c) unique(ALL(c))
#define FOR(i, a, b, c) for (int i = (int)(a); i < (int)(b); i += (int)(c))
#define REP(i, n) FOR(i, 0, n, 1)
#define RFOR(i, a, b, c) for (int i = (int)(a); i >= (int)(b); i -= (int)(c))
#define RREP(i, n) RFOR(i, n, 0, 1)

// functions
template <class T>
T ceil(T a, T b) {
    return (a + b - 1) / b;
}
template <class T>
T round(T a, T b) {
    return (a + b / 2) / b;
}
template <class T>
T gcd(T a, T b) {
    return b ? gcd(b, a % b) : a;
}
template <class T>
T lcm(T a, T b) {
    return a / gcd(a, b) * b;
}
template <class T>
bool amax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T>
bool amin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}

// main
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<ll> A(N);
    REP(i, N) {
        cin >> A[i];
    }
    ll res = A[0];
    REP(i, N) {
        res = gcd(res, A[i]);
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 1024
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define EPS (1e-7)
#define INF (1e9)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
const double PI = acos(-1);
const ll MOD = 1000000007;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}
 
template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
///////////////////////////////////////////////////////////////

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int N,K; cin >> N >> K;
    vector<ll> x(N),y(N);
    rep(i,N) cin >> x[i] >> y[i];
    vector<ll> xx = x;
    vector<ll> yy = y;
    sort(all(x)); sort(all(y));
    
    ll ans = 5e18;
    rep (i,N-1) {
        for (int j = i+1; j < N; j++) {
            rep(k,N-1) {
                for (int l = k+1; l < N;l++) {
                    int count = 0;
                    rep(m,N) {
                        if (x[i] <= xx[m] && xx[m] <= x[j] && y[k] <= yy[m] && yy[m] <= y[l]) count++;
                    }
                    if (count >= K) {
                        ll S = (x[j] - x[i]) * (y[l] - y[k]);
                        chmin(ans,S);
                    }
                }
            }
        }
    }

    cout << ans << endl;
}


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



//------------------------3-------------------------
#define rep(i,l,r) for(ll i=l;i<r;i++)
using namespace std;
typedef long long ll;


int main()
{
    ll  n,m,k; std::cin >> n >> m >> k;
    ll  a[200001], b[200001];
    // std::vector<long long>  a(n+1), b(m+1);
    a[0]=0; b[0]=0;
    rep(i,1,n+1) 
    {
        cin >> a[i];
        a[i]+=a[i-1];
    }
    rep(i,1,m+1)
    {
        cin >> b[i];
        b[i]+=b[i-1];
    } 
    
    ll ans=0, r=m;

    rep(i,0,n+1)
    {
        if(a[i]>k) break;
        while (a[i]+b[r]>k)
            r--;
        ans = max(ans, i+r);
    }
    
    cout << ans;

    return 0;
}

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

using namespace std;

#define FAST_IO ios_base::sync_with_stdio(0); cin.tie(nullptr)
#define FOR(i, a, b) for(int i = (a); i <= (b); i++)
#define REP(n) FOR(O, 1, (n))
#define pb push_back
#define f first
#define s second
typedef long double ld;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef vector<int> vi;
typedef vector<pii> vii;
typedef vector<ll> vl;
typedef vector<piii> viii;

const int MAXN = 500100, MAXK = 35;
const ll MOD = 998244353;
const ld INF = 2*1e18;
const ld PI = asin(1) * 2;

ll cnt[MAXN];
int n;
ll ans = 1;

ll pwr (ll a, ll p) {
    if (p == 0) return 1ll;
    if (p == 1) return a%MOD;
    ll ret = pwr(a, p/2);
    ret *= ret;
    ret %= MOD;
    if (p%2 == 1) ret *= a;
    ret %= MOD;
    return ret;
}

int main() {
	FAST_IO;

    cin >> n;
    ll maxD = 0;
    FOR(i, 1, n) {
        ll d; cin >> d;
        maxD = max(maxD, d);
        if (i == 1 && d != 0) ans = 0;
        else if (i != 1 && d == 0) ans = 0;
        else cnt[d]++;
    }

    FOR(i, 1, maxD-1) {
        if (cnt[i] == 0 || cnt[i+1] == 0) ans = 0;
        ans *= pwr(cnt[i], cnt[i+1]);
        ans %= MOD;
    }

    cout << (ans%MOD);


	return 0;
}


Measured memory_bytes: 1024
n=int(input())
a=[int(i) for i in input().split()]
b=[0 for i in range(n+1)]
for i in range(n):
  b[i+1]=b[i]+a[i]
b.sort()
res=0
now=b[0]
cnt=1
for i in range(n):
  if now==b[i+1]:
    cnt+=1
  else:
    res+=(cnt-1)*cnt//2
    cnt=1
    now=b[i+1]
res+=(cnt-1)*cnt//2
print(res)

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

int s(string str)
{
	int ret=0;
	for(int i=0;i<str.size();i++)
	{
		ret+=(str[i]-'0');
	}
	return ret;
}

int main()
{
	string str;
	int n;
	
	cin >> str;
	n=atoi(str.c_str());
	
	if(n%s(str)==0)cout << "Yes";
	else cout << "No";
	
	cout << endl;
	return 0;
}



Measured memory_bytes: 256