akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;

const long long MOD = 998244353;

class Combination {
    //a^p%mod
    ll powmod(ll a, ll p) {
        ll ans = 1LL;
        ll mul = a;
        // p >>=1 <-> p=(p >> 1)
        for (; p > 0; p >>= 1, mul = (mul * mul) % mod) {
            if ((p & 1) == 1) ans = (ans * mul) % mod;
        }

        return ans;
    }
public:
    int N;
    ll mod;
    vector<ll> fact;
    vector<ll> revFact;

    Combination(int n, ll m) : N(n), mod(m), fact(n+1), revFact(n+1) {
        fact[0] = 1;
        for (int i = 1; i <= N; i++) {
            fact[i] = fact[i-1] * i;
            fact[i] %= mod;
        }

        // Fermat's little theorem
        revFact[N] = powmod(fact[N], mod - 2);

        for (int i = N-1; i >= 0; i--) {
            revFact[i] = revFact[i+1] * (i+1);
            revFact[i] %= mod;
        }
    }

    ll get(int a, int b) {
        if (a < 0 || b < 0) return 0;
        if (b > a) return 0;
        return (((fact[a] * revFact[b]) % mod) * revFact[a-b]) % mod;
    }
};

int main() {
    ll N, M, K;
    cin >> N >> M >> K;

    ll ans = 0;

    Combination cm = Combination(N + 5, MOD);

    //(M - 1)^i
    vector<ll> pow(N, 1);
    for(int i = 1; i < N; i++) pow[i] = pow[i - 1] * (M - 1) % MOD;

    for(int k = 0; k <= K; k++) {
        ll tmp = M * pow[N - k - 1];
        tmp %= MOD;
        tmp *= cm.get(N - 1, k);
        tmp %= MOD;
        ans += tmp;
        ans %= MOD;
    }

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

Measured memory_bytes: 7924
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<string>
using namespace std;

int main(){
  
  string a,b,c;

  cin >> a >> b >> c;

  if(a[a.size()-1] == b[0] && b[b.size()-1] == c[0]){
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
  
  return 0;
}


Measured memory_bytes: 256
def main():
  s=input()
  flg=0
  for i in range(0,len(s)):
    if i%2==1:
      if s[i]=='R':
        flg=1
        break
    else:
      if s[i]=='L':
        flg=1
        break
  if(flg==1):
    print('No')
  else:
    print('Yes')
    
main()

Measured memory_bytes: 9032
n,*a=map(int,open(0).readlines())
a.sort()
if n%2:
  b=a[:n//2]
  c=a[n//2:]
  for i in range(n//2):
    b[i]*=2
  for i in range(2,n//2+1):
    c[i]*=2
  m=sum(c)-sum(b)
  b=a[:n//2+1]
  c=a[n//2+1:]
  for i in range(n//2-1):
    b[i]*=2
  for i in range(n//2):
    c[i]*=2
  m=max(m,sum(c)-sum(b))
else:
  b=a[:n//2]
  c=a[n//2:]
  for i in range(n//2-1):
    b[i]*=2
  for i in range(1,n//2):
    c[i]*=2
  m=sum(c)-sum(b)
print(m)

Measured memory_bytes: 60508
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef pair<ll, P> Pi;
const int MAX_N=1<<18;
int m; ll mx[2][2*MAX_N], ind[2][2*MAX_N];
const ll INF=1e18;
void init(int m_){
	m=1;
	while(m<m_) m<<=1;
	for(int i=1; i<=2*m-1; i++) mx[0][i]=mx[1][i]=INF, ind[0][i]=ind[1][i]=-1;
}

void update(int k, ll a, int i){
	k+=m;
	mx[i][k]=a;
	ind[i][k]=k-m;
	while(k>1){
		k>>=1;
		if(mx[i][2*k]<mx[i][2*k+1]){
			ind[i][k]=ind[i][2*k];
		}else{
			ind[i][k]=ind[i][2*k+1];
		}
		mx[i][k]=min(mx[i][2*k], mx[i][2*k+1]);
	}
}

int query(int a, int b, int i){
	a+=m, b+=m;
	ll ans=INF; int ind0=-1;
	for(;a<b; a>>=1, b>>=1){
		if(b&1){
			b--;
			if(ans>mx[i][b]){
				ans=mx[i][b];
				ind0=ind[i][b];
			}
		}
		if(a&1){
			if(ans>mx[i][a]){
				ans=mx[i][a];
				ind0=ind[i][a];
			}
			a++;
		}
	}
	return ind0;
}
int par[200002];
int rk[200002];
 
void init1(int n){
	for(int i=0; i<n; i++){
		par[i]=i;
	}
}
 
int find(int x){
	if(par[x]==x){
		return x;
	}else{
		return par[x]=find(par[x]);
	}
}
 
void unite(int x, int y){
	x=find(x);
	y=find(y);
	if(x==y) return;
	if(rk[x]<rk[y]){
		par[x]=y;
	}else{
		par[y]=x;
		if(rk[x]==rk[y]) rk[x]++;
	}
}
 
bool same(int x, int y){
	return find(x)==find(y);
}
int main()
{
	int n;
	ll d;
	cin>>n>>d;
	ll a[200001];
	int ind0[200001];
	for(ll i=0; i<n; i++){
		cin>>a[i]; ind0[i]=i;
	}
	if(n==1){
		cout<<0<<endl;
		return 0;
	}
	if(n==2){
		cout<<a[0]+a[1]+d<<endl;
		return 0;
	}
	sort(ind0, ind0+n, [&](int i, int j){ return a[i]<a[j];});
	ll ans=0;
	init(n);
	vector<Pi> e;
	for(int i=1; i<n; i++){
		update(ind0[i-1], a[ind0[i-1]]-(ll)ind0[i-1]*d, 0);
		update(ind0[i-1], a[ind0[i-1]]+(ll)ind0[i-1]*d, 1);
		if(ind0[i]>0){
			int ind1=query(0, ind0[i], 0);
			if(ind1>=0){
				e.push_back(Pi(a[ind0[i]]+a[ind1]+(ll)(ind0[i]-ind1)*d, P(ind0[i], ind1)));
			}
		}
		if(ind0[i]<n-1){
			int ind1=query(ind0[i], n, 1);
			if(ind1>=0){
				e.push_back(Pi(a[ind0[i]]+a[ind1]+(ll)(ind1-ind0[i])*d, P(ind0[i], ind1)));
			}
		}
	}
	sort(e.begin(), e.end());
	init1(n);
	for(int i=0; i<e.size(); i++){
		int x=e[i].second.first, y=e[i].second.second;
		if(!same(x, y)){
			unite(x, y);
			ans+=e[i].first;
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 29292
#include<bits/stdc++.h>
using namespace std;
#define next Next
/*char buf[1<<21],*p1=buf,*p2=buf;
inline int gc(){return p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++;}*/
#define gc getchar
inline int read()
{
	int ret=0,f=0;char c=gc();
	while(!isdigit(c)){if(c=='-')f=1;c=gc();}
	while(isdigit(c)){ret=ret*10+c-48;c=gc();}
	if(f)return -ret;return ret;
}
const int N=200005;
const int inf=0x3f3f3f3f;
int n,top,head[N],ma1[N],ma2[N],d[N],size[N];
long long ans;
char s[N];
struct node{
	int too,next;
}edge[N*2];
void add(int a,int b)
{
	edge[++top].too=b;edge[top].next=head[a];head[a]=top;
}
void dfs1(int u,int fa)
{
    if(s[u]=='1')d[u]=0,size[u]=1;
    else d[u]=inf;
    for(int i=head[u];i;i=edge[i].next)
	{
        int v=edge[i].too;
		if(v==fa)continue;
        dfs1(v,u);
		size[u]+=size[v];
        if(ma1[v]+1>ma1[u])
		{
			ma2[u]=ma1[u];
			ma1[u]=ma1[v]+1;
		}
        else if(ma1[v]+1>ma2[u])ma2[u]=ma1[v]+1;
        if(size[v])d[u]=min(d[u],ma1[v]+1);
    }
}
void dfs2(int u,int fa)
{
    int R=min(ma2[u]+1,ma1[u]-1);
    if(d[u]<=R)ans+=(long long)(R-d[u]+1);
    for(int i=head[u];i;i=edge[i].next)
	{
        int v=edge[i].too;
		if(v==fa)continue;
        int xu=(ma1[v]+1==ma1[u]?ma2[u]+1:ma1[u]+1);
        if(xu>ma1[v])
		{
			ma2[v]=ma1[v];
			ma1[v]=xu;
		}
        else if(xu>ma2[v])ma2[v]=xu;
        if(size[1]-size[v])d[v]=min(d[v],xu);
        dfs2(v,u);
    }
}
int main()
{
    n=read();
    for(int i=1;i<n;i++)
	{
		int x=read(),y=read();
		add(x,y),add(y,x);
	}
    scanf("%s",s+1);
    dfs1(1,0);
	dfs2(1,0);
    printf("%lld\n",ans+1);
    return 0;
}

Measured memory_bytes: 14592
#include <stdio.h>

int main(void)
{
	int n,m;
	
	m=100000;
	scanf("%d",&n);
	
	while(n>0)
	{
		m=(m*105)/100;
		if(m%1000>0)
		{
			m=((m/1000)+1)*1000;
		}
		n--;
	}
	
	printf("%d\n",m);
	return 0;
}

Measured memory_bytes: 1020
package main

import (
	"fmt"
)

const n = 7

var (
	b2i = map[bool]int{false: 0, true: 1}
	i2b = map[int]bool{0: false, 1: true}
	seq = []int{}
	flg bool
)

func dfs(left, i int, ops []bool) {
	if i == len(seq) {
		if left == 0 && !flg {
			for i := range seq {
				if i != 0 {
					fmt.Print([...]string{"-", "+"}[b2i[ops[i]]])
				}
				fmt.Print(seq[i])
			}
			fmt.Printf("=%d\n", n)
			flg = true
		}
		return
	}
	for j := range make([]struct{}, 2) {
		if j == 1 || i != 0 {
			dfs(left-seq[i]*[...]int{-1, 1}[j], i+1, append(ops, i2b[j]))
		}
	}
}

func main() {
	var abcd string
	fmt.Scan(&abcd)

	for _, c := range abcd {
		seq = append(seq, int(c)-'0')
	}
	dfs(n, 0, []bool{})
}


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

int main(){
	int n,k;
	cin >> n >> k;
	int sum = 0;
	for (int i=0; i<n; i++){
		int xi;
		cin >> xi;
		sum += 2*min(xi,k-xi);
	}
	cout << sum;
}


Measured memory_bytes: 256
#include <stdio.h>

void magic(int square[17][17], int c, int height, int y, int x){
  if(c > height * height) return;
  y == height ? y = 1 : y++;
  x == height ? x = 1 : x++;
  if(square[y][x] != 0){
    y == height ? y = 1 : y++;
    x == 1 ? x = height : x--;
  }
  square[y][x] = c;
  return magic(square, ++c, height, y, x);
}

int main(){
  int n, i, j;
  while(scanf("%d", &n) != EOF && n){
    int square[17][17] = {};
    square[n / 2 + 2][n / 2 + 1] = 1;
    magic(square, 2, n, n/2+2, n/2+1);

    for(i = 1;i <= n;i++){
      for(j = 1;j <= n;j++){
	if(square[i][j] / 10 == 0) printf("  ");
	else if(square[i][j] / 100 == 0) printf(" ");
	printf(" %d", square[i][j]);
      }
      puts("");
    }
  }
  return 0;
}

Measured memory_bytes: 616
n = int(input())
s = input()

ms = n
a = 0
b = s.count('E')
for i in range(n):
	if(i != 0 and s[i-1] == 'W'):
		a += 1
	if(s[i] == 'E'):
		b -= 1
	# print(s[0:i], s[i+1:n], s[0:i].count('W'), s[i+1:n].count('E'), a, b)
	# c = s[0:i].count('W')
	# c += s[i+1:n].count('E')
	c = a + b
	if(ms > c):
		ms = c

print(ms)

Measured memory_bytes: 3700
from collections import defaultdict, deque
def inpl(): return list(map(int, input().split()))

class UnionFind():

    def __init__(self, N):
        self.parent = [-1] * (N+1)
        self.size = [1] * (N+1)

    def find(self, x):
        if self.parent[x] == -1:
            return x
        else:
            self.parent[x] = self.find(self.parent[x])
            return self.parent[x]

    def unite(self, x, y):
        x_p = self.find(x)
        y_p = self.find(y)
        if x_p != y_p:
            if self.size[x_p] < self.size[y_p]:
                x_p, y_p = y_p, x_p
            self.size[x_p] += self.size[y_p]
            self.parent[y_p] = x_p

N, M = inpl()
UFT = UnionFind(N)

for _ in range(M):
    x, y, z = inpl()
    UFT.unite(x, y)

print(UFT.parent[1:].count(-1))

Measured memory_bytes: 72792
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);i++)
#define all(x) (x).begin(), (x).end()
using ll = long long;
using namespace std;
template <typename T>
using vec = std::vector<T>;

int main() {
    int N,A,B;
    cin >> N >> A >> B;
    int ans = 0;
    for(int i=1;i<=N;++i){
        int now = i;
        int sm = 0;
        while(now){
            sm += now%10;
            now /=10;
        }
        if(sm>=A&&B>=sm) ans+=i;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cmath>
#include <climits>
#include <algorithm>
#include <sstream>
#include <iostream>
#include <vector>
#include <map>
#include <set>

using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef vector<int> vi;
typedef vector<long> vl;

int
main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n, k;
    cin >> n >> k;
    vi d;
    for (int i = 0; i < k; ++i) {
        int tmp;
        cin >> tmp;
        d.push_back(tmp);
    }

    for (int i = n; i < INT_MAX; ++i) {
        int num = i;
        bool invalid = false;
        while (num > 0) {
            int tmp = num % 10;
            for (int i = 0; i < k; ++i) {
                if (d[i] == tmp) {
                    invalid = true;
                }
            }
            if (invalid) break;
            num /= 10;
        }
        if (invalid) continue;

        cout << i << endl;
        return 0;
    }
    return 1;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-

S = input()
N = len(S)
left = S[:int((N-1)/2)]
right = S[int((N+3)/2-1):]

def is_kaibun(kaibun):
    for i in range(len(kaibun)//2):
        if kaibun[i] != kaibun[-i-1]:
            return False
    return True

if is_kaibun(S) == False:
    print('No')
elif is_kaibun(left) == False:
    print('No')
elif is_kaibun(right) == False:
    print('No')
else:
    print('Yes')


Measured memory_bytes: 3064
import java.util.Scanner;

 public class Main {
    public static void main (String[] args) {
        Scanner sc = new Scanner(System.in);
        int r = sc.nextInt();
        int D = sc.nextInt();     
        int x = sc.nextInt();   
        int res ;

        for (int count = 0; count < 10; count++) {
        	
            res = r*x-D;   
            x = res;
            System.out.println(res);
        }

    }
}

Measured memory_bytes: 25300
// by adiforluls
#pragma GCC optimize ("-O2")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define FAST         ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define ll           long long
#define ld           long double
#define pb           push_back
#define mp           make_pair
#define pii          pair<int,int>
#define mii          map<int,int>
#define vi           vector<int>
#define vll          vector<long long>
#define all(a)       (a).begin(),(a).end()
#define clz(a)       __builtin_clz(a) // count leading zeroes
#define ctz(a)       __builtin_ctz(a) // count trailing zeroes
#define popc(a)      __builtin_popcount(a) // count set bits (for ints only diff for ll)
#define lul          1000000007
#define rep(i,a,b)   for(int i=a;i<b;i++)
#define rfor(i,a,b)  for(int i=a; i>=b; i--)
#define SIZE         1000005
#define F            first
#define S            second
#define mod          998244353

#define TRACE

#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    std::cerr << name << " = " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');std::cerr.write(names, comma - names) << " = " << arg1<<" |";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

#define endl         '\n'
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
// order_of_key(k)
// find_by_order(k)
const ld PI = acos(-1.0);
const int INF = 0x3f3f3f3f;


void solve()
{ 
    int n; cin>>n;
    vector<int> a(n);
    rep(i,0,n) cin>>a[i];
    if(n&1) {cout<<0; return;}
    sort(all(a));
    int ans = a[n/2]-a[n/2-1];
    cout<<ans;
}
int main()
{   
    FAST;
   //  #ifndef ONLINE_JUDGE
     // freopen("input.txt", "r", stdin);
     // freopen("output.txt", "w", stdout);
   //  #endif
    int t; t=1;
    while(t--){
       solve();
    }
    return 0;
}

Measured memory_bytes: 640
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Iterator;
import java.util.PrimitiveIterator;
import java.util.Scanner;
import java.util.stream.IntStream;
import java.util.stream.Stream;

class Main{
	private void solve(){
		System.out.println(ints(gInt()).distinct().count());
	}

	public static void main(String[] $){
		new Main().solve();
		System.out.flush();
	}


	static class System{
		private static final InputStream	in	=java.lang.System.in;
		private static final PrintWriter	out	=new PrintWriter(java.lang.System.out,false);
	}

	static Scanner s=new Scanner(System.in);


	static int gInt(){
		return s.nextInt();
	}

	static long gLong(){
		return s.nextLong();
	}

	static long gDouble(){
		return s.nextLong();
	}


	static Range rep(int i){
		return new Range(i);
	}

	static Range rep(int f,int t){
		return new Range(f,t);
	}

	static class Range implements Iterable<Integer>,PrimitiveIterator.OfInt{
		int from,to,c;
		Range(int from,int to){
			this.from=from;
			this.to=to;
			this.c=from;
		}
		Range(int n){
			this(0,n-1);
		}
		@Override
		public Iterator<Integer> iterator(){
			return this;
		}
		@Override
		public boolean hasNext(){
			return c<=to;
		}
		@Override
		public int nextInt(){
			return c++;
		}
	}


	static IntStream REPS(int v){
		return IntStream.range(0,v);
	}

	static IntStream REPS(int l,int r){
		return IntStream.rangeClosed(l,r);
	}


	static IntStream ints(int n){
		return REPS(n).map(i->gInt());
	}

	static Stream<String> strs(int n){
		return REPS(n).mapToObj(i->s.next());
	}

}

Measured memory_bytes: 29140
a = int(input())
b = int(input())
c = int(input())
x = int(input())

ok = set()

for a_num in range(a + 1):
    for b_num in range(b + 1):
        for c_num in range(c + 1):
            price = a_num * 500 + b_num * 100 + c_num * 50
            if price == x:
                ok.add((a_num, b_num, c_num))

print(len(ok))


Measured memory_bytes: 3060
#include<stdio.h>
int main(){
  int n,number,card[4][14];
  int i,j;
  char s;
  for(i=0;i<=13;i++){
    card[0][i]=1;
    card[1][i]=1;
    card[2][i]=1;
    card[3][i]=1;
  }
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf(" %c %d",&s,&number);
         if(s=='S')card[0][number]=0;
    else if(s=='H')card[1][number]=0;
    else if(s=='C')card[2][number]=0;
    else if(s=='D')card[3][number]=0;
  }
  for(i=0;i<4;i++){
    for(j=1;j<=13;j++){
      if(card[i][j]==1){
    if(i==0)s='S';
    else if(i==1)s='H';
    else if(i==2)s='C';
    else if(i==3)s='D';
    printf("%c %d\n",s,j);
      }
    }
  }
  return(0);
}

Measured memory_bytes: 596
#include <iostream>
#include <cstdint>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int, int>> vpii;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvc;
typedef vector<vector<string>> vvs;
typedef vector<vector<ll>> vvll;

#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rrep(i, n) for (ll i = 1; i <= (n); ++i)
#define irep(it, stl) for (auto it = stl.begin(); it != stl.end(); it++)
#define drep(i, n) for (ll i = (n)-1; i >= 0; --i)
#define mes(a) cout << (a) << endl
#define dmes(a, b) cout << (a) << " " << (b) << endl
#define re0 return 0
#define mp(p, q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define rSort(a) sort(a.rbegin(), a.rend())
#define Rev(a) reverse(a.begin(), a.end())
#define MATHPI acos(-1)
#define itn int
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return 1;
    }
    return 0;
}
struct io
{
    io()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
};
const int INF = INT_MAX;
const ll LLINF = 1LL << 60;
const ll MOD = 1000000007;
const double EPS = 1e-19;



signed main() {
    ll n;
    cin >> n;
    
    vll a(n), b(n), c(n), d(n);
    
    rep(i, n) {
        cin >> a[i] >> b[i];
        
        c[i] = a[i] + b[i];
        d[i] = a[i] - b[i];
    }
    
    Sort(c);
    Sort(d);
    
    mes(max(abs(c[n-1]-c[0]), abs(d[n-1]-d[0])));
    
   
    
    
    
}
    
    
    
    
    


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

const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;
const int MOD=1000000007;

int d[6000];
int main(){
	int K,Q;cin>>K>>Q;
	rep(i,K)scanf("%d",&d[i]);
	rep(loop,Q){
		ll n,x,m;scanf("%lld%lld%lld",&n,&x,&m);
		ll all=0;
		ll sum=x;
		rep(i,K){
			if(d[i]%m){
				ll cnt=(n-1)/K+((n-1)%K>i);
				all+=cnt;
				sum+=(d[i]%m)*cnt;
			}
		}
		printf("%lld\n",all-((sum/m)-(x/m)));
	}
}

Measured memory_bytes: 384
#include <stdio.h>

int solve(int,int,int *,int);

int main()
{
  int i, n, a[20], q, m[200];

  scanf("%d",&n);
  for(i = 0; i < n; i++) {
    scanf("%d",&a[i]);
  }

  scanf("%d",&q);
  for(i = 0; i < q; i++) {
    scanf("%d",&m[i]);
  }

  for(i = 0; i < q; i++) {
    if(solve(0, n, a, m[i])) printf("yes\n");
    else printf("no\n");
  }
  
  return 0;
}

int solve(int i, int n, int *a, int m)
{
  int res;
  if(m == 0) return 1;
  if(i >= n) return 0;
  res = solve(i + 1, n, a, m) + solve(i + 1, n, a, m - a[i]);
  return res;  
}



Measured memory_bytes: 2104
#include <bits/stdc++.h>
using namespace std;
 
#define F first
#define S second 
#define mp make_pair
#define pb push_back
#define pf push_front
#define speed_up ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define debug cerr << "OK\n";
#define ub upper_bound
#define lb lower_bound
#define treap_pair pair<treap*, treap*>
 
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vpii;
typedef set <int> si;
typedef set <ll> sll;
typedef multiset <int> msi;
typedef multiset <ll> msll;
typedef map <int, int> mi;
typedef map <ll, int> mll;
 
const int N = 2e5 + 2;
const int M = 1e5 + 2;
const int mod = 998244353;
const int inf = 1e9;
const ll INF = 1e16;

void data() {
	#ifdef PC
		freopen("main.in", "r", stdin);
		freopen("main.out", "w", stdout);
	#endif
}

vector <pll> lines;
int n;
ll c, h[N], dp[N];

ld cross(pll a, pll b) {
	return (b.S - a.S + 0.0) / (a.F - b.F + 0.0);
}

void add(pll new_line) {
	while (sz(lines) > 1) {
		int last = sz(lines) - 1;
		if (cross(lines[last], lines[last - 1]) < cross(new_line, lines[last - 1]))
			break;
		lines.pop_back();
	}
	lines.pb(new_line);
}

ll get_min(ll x) {
	int l = 0;
	for (int pos = sz(lines); pos >= 1; pos /= 2)
		while (l + pos < sz(lines) && x + 0.0 > cross(lines[l + pos], lines[l + pos - 1]))
			l += pos;
	return lines[l].F * x + lines[l].S;
}

int main() {
	data();
	scanf("%d %lld", &n, &c);
	for (int i = 1; i <= n; ++i)
		scanf("%lld", &h[i]);
   	add({-2 * h[1], h[1] * h[1]});
   	for (int i = 2; i <= n; ++i) {
   		dp[i] = get_min(h[i]) + h[i] * h[i] + c;		
   		add({-2 * h[i], dp[i] + h[i] * h[i]});
   	}
   	printf("%lld", dp[n]);
}

/*
	
*/                             

Measured memory_bytes: 9200
#include <bits/stdc++.h>
#include<stdio.h>
using namespace std;
 
int main(){
int n,m;
long long a[51],b[51],c[51],d[51];
cin>>n>>m;
for(int i=0;i<n;i++){
cin>>a[i]>>b[i];
}
for(int i=0;i<m;i++){
cin>>c[i]>>d[i];
}
for(int i=0;i<n;i++){
long long ans=10000000000;
int an=0;
for(int j=0;j<m;j++){
if(abs(a[i]-c[j])+abs(b[i]-d[j])<ans)an=j;
ans=min(abs(a[i]-c[j])+abs(b[i]-d[j]),ans);
}
cout<<an+1<<endl;
}
 
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define SORT(a) sort(a.begin(), a.end())
#define RSORT(a) sort(a.rbegin(), a.rend())
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, start, end) for (int i = start; i < end; i++)
#define ALL(a) a.begin(), a.end()
#define MOD(a) a %= 1'000'000'007
using ll = long long;
using namespace std;
const int INF32       = 1'050'000'000;
const long long INF64 = 4'000'000'000'000'000'000;
const int MOD7        = 1'000'000'007;
const int MOD9        = 1'000'000'009;
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 main() {
    cin.tie(0);
    ios::sync_with_stdio(false);

    int D, G;
    cin >> D >> G;
    vector<int> p(D), c(D);
    REP(i, D) cin >> p[i] >> c[i];

    int ans = INF32;
    REP(bit, (1 << D)) {
        ll sum  = 0;
        int cnt = 0;
        vector<pair<int, int>> vv;
        REP(i, D) {
            if (bit & (1 << i)) {
                sum += (i + 1) * 100 * p[i] + c[i];
                cnt += p[i];
            } else {
                vv.emplace_back(100 * (i + 1), p[i] - 1);
            }
        }
        if (G <= sum) {
            chmin(ans, cnt);
            continue;
        }
        RSORT(vv);
        int now = 0;
        while (sum < G && now < vv.size()) {
            if (vv.at(now).second == 0) {
                now++;
                continue;
            }
            int dist = G - sum;
            sum += vv[now].first *
                   min(((dist + vv[now].first - 1) / vv[now].first),
                       vv[now].second);
            cnt += min(((dist + vv[now].first - 1) / vv[now].first),
                       vv[now].second);
            vv[now].second = 0;
            if (G <= sum) {
                chmin(ans, cnt);
                break;
            }
        }
    }
    std::cout << ans << '\n';

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>

int main()
{
    int a,h,m,s;
    scanf("%d",&a);
    h=a/3600;
    a=a-h*3600;
    m=a/60;
    a=a-m*60;
    s=a;
    printf("%d:%d:%d\n",h,m,s);
}


Measured memory_bytes: 2016
n = int(input())
num_list = list(map(int,input().split()))
ans = 1
if 0 in num_list:
    print(0)
    
else:
    for i in num_list:
        ans *= i
        if ans > 10**18:
            break

    if ans > 10**18:
        print(-1)

    else:
        print(ans)


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

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
#define hash dhsjakhd
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef long double ld;

ll n,m,T,k,q;
ll DEG[4] = {0};

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    //freopen("input.txt","r",stdin);
    //freopen("autput.txt","w",stdout);
    ll a,b,c;

    cin >> k >> a >> b;

    if(a >= b-1 || k < a-1){
        cout << k+1 << "\n";
    }
    else{
        k -= (a-1);
        ll ans = a;
        ans += (b-a) * (k/2);
        ans += k%2;
        cout << ans << "\n";
    }

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void){
	int c, h, i, n, o;
	h = 0;
	c = 556;
	for (i = 0; i < 6; i++) {
		scanf("%d", &o);
		h += o;
		if (o < c) c = o;
		switch (i) {
		case 3:
		case 5:
			h -= c;
			c = 556;
			break;
		}
	}
	printf("%d\n", h);
	return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const long long INF = 1LL << 60;

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

    sort(h.begin(), h.end(), greater<ll>());
    ll out = INF;
    for (int i = 0; i <= N - K; i++) out = min(out, h[i] - h[i + K - 1]);
    cout << out << endl;

    return 0;
}

Measured memory_bytes: 4032
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int num = 000;
  cin >> num ;
  cout << num % 9 <<endl;
  //各位に足されるのは10^n(=9*111... + 1)なので9で割ったあまりがそのまま各位の1の合計数となる(9桁以上除く)
}

Measured memory_bytes: 512
import java.util.*;
import java.math.*;

public class Main {
	static long gcd(int[] a) {
		long gcd = a[0];
		for(int i = 1; i < a.length; i++) {
			gcd = gcd(a[i],gcd);
		}
		return gcd;
		
	}
	static long lcm(int[] a) {
		long lcm = a[0];
		for(int i = 1; i < a.length; i++) {
			lcm = lcm(lcm,a[i]);
		}
		return lcm;
	}
	static long lcm(long m, long n) {
		return (m * n) / gcd(m,n);
	}
	
	static long gcd(long m, long n) {
		if(m < n) {
			long tmp = m;
			m = n;
			n = tmp;
		}
		if(n == 0) return m;
		
		return gcd(n,m % n);
		
	}
	
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(true) {
			int n = sc.nextInt();
			if(n == 0) break;
			int[] d = new int[n];
			int[] v = new int[n];
			for(int i = 0; i < n; i++) {
				d[i] = sc.nextInt();
				v[i] = sc.nextInt();
				int T = (int)gcd(d[i],v[i]);
				d[i] = d[i] / T; v[i] = v[i] / T;
			}
			long dd = lcm(d);
			long vv = gcd(v);
			
			long T = dd/vv;
			
			for(int i = 0; i < n; i++) {
				System.out.println((v[i] / vv) * (dd/ d[i]));
			}
			
		}
	}
}

Measured memory_bytes: 35592
/*
	Name:
	Author: xiaruize
	Date:
*/
#pragma GCC optimize(2)
#include<algorithm>
#include<bitset>
#include<cctype>
#include<cerrno>
#include<clocale>
#include<cmath>
#include<complex>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<deque>
#include<exception>
#include<fstream>
#include<functional>
#include<limits>
#include<list>
#include<map>
#include<iomanip>
#include<ios>
#include<iosfwd>
#include<iostream>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<stdexcept>
#include<streambuf>
#include<string>
#include<utility>
#include<vector>
#include<cwchar>
#include<cwctype>
using namespace std;
#define ull unsigned long long
#define MOD 1000000007
#define ALL(a) (a).begin(), (a).end()
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define ll long long
#define form(i,j,n) for(int i=int(j);i<=int(n);i++)
#define pb push_back
#define mk make_pair
#define pii pair<int,int>
#define pis pair<int,string>
#define sec second
#define sz(a) int((a).size())

inline int read()
{
    char ch=getchar();
    int x=0,f=1;
    while(ch<'0'||ch>'9'){if(ch=='-') f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9') x=x*10+(ch^48),ch=getchar();
    return x*f;
}

int main()
{
 	ios::sync_with_stdio(false);
	cin.tie(0);
 	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	int n,m;
	cin>>n>>m;
    for(int gap=m,i=1;gap>=1;gap-=2){
        cout<<i<<' '<<i+gap<<endl;
        i++;
    }
    for(int gap=m-1,i=1+m+1;gap>=1;gap-=2){
        cout<<i<<' '<<i+gap<<endl;
        i++;
    }
	return 0;
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
#include <chrono>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repl(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define rep2l(i, s, n) for (ll i = (ll)(s); i < (ll)n; i++)

int main() {
    int X, Y;
    cin >> X >> Y;
    rep(i, X+1) {
        if(i*2+(X-i)*4 == Y) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
}

Measured memory_bytes: 3652
#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);
  }
  sort(a.begin(),a.end());
  int med=n/2;
  int ans=a.at(med)-a.at(med-1);
  cout << ans << endl;
}


Measured memory_bytes: 768
n, m, c = map(int, input().split())
b = list(map(int, input().split()))
a = [list(map(int, input().split())) for _ in range(n)]
lst = []
tmp = 0

for i in range(n):
    
    x = c
    for j in range(m):
        x += a[i][j]*b[j]
    lst.append(x)

for i in range(n):
    if lst[i] > 0:
        tmp += 1

print(tmp)

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

int main(){
  int N,a=0;
  cin >> N;
  vector<int> d(N);
  for(int i=0;i<N;i++){
    cin >> d[i];
  }
  for(int i=0;i<N;i++){
    for(int j=i+1;j<N;j++){
      a += d[i]*d[j];
    }
  }
  cout << a <<endl;
}

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

int main(){
    int x,a; cin >> x >> a;
    if(x<a) cout << 0 << endl;
    else if(x>=a) cout << 10 << endl;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int) n; i++)
using ll = long long;
template <class T>
using vt = vector<T>;
using vvi = vector<vt<int>>;

int main(){
  int a,b,c,k;
  cin >> a >> b >> c >> k;
  int ans = 0;
  ans += min(a,k);
  k -= min(a,k);
  if(k>0){
    k -= min(b,k);
  }
  if(k>0){
    ans -= k;
  }

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


Measured memory_bytes: 3624
#include<iostream>
#include <string> 
#include <vector>  
#include<math.h>

#define INF 1000000000
using namespace::std;



long Lmax(long x, long y) {
	if (x > y)return x;
	return y;
}

int max(int x, int y) {
	if (x > y)return x;
	return y;
}

long Lmin(long x, long y) {
	if (x < y)return x;
	return y;
}


int min(int x, int y) {
	if (x < y)return x;
	return y;
}

int abs(int x) {
	if (x < 0) {
		return -x;
	}
	return x;
}

void m_sort(int a[], int tmp[], int left, int right);
void m_sort(int a[], int tmp[], int left, int right);
void sort(int a[], int total) {
	int tmp;
	for (int i = 0; i < total; i++) {
		for (int j = i + 1; j < total; j++) {
			if (a[i] < a[j]) {
				tmp = a[i];
				a[i] = a[j];
				a[j] = tmp;
			}
		}
	}

}

void mergeSort(int a[], int tmp[], int size)
{
	m_sort(a, tmp, 0, size - 1);
}
void merge(int a[], int tmp[], int left, int mid, int right)
{
	int i, left_end, num_elements, tmp_pos;

	left_end = mid - 1;
	tmp_pos = left;
	num_elements = right - left + 1; // 要素 

	while ((left <= left_end) && (mid <= right))
	{
		if (a[left] <= a[mid])
		{
			tmp[tmp_pos] = a[left];
			tmp_pos = tmp_pos + 1;
			left = left + 1;
		}
		else
		{
			tmp[tmp_pos] = a[mid];
			tmp_pos = tmp_pos + 1;
			mid = mid + 1;
		}
	}


	while (left <= left_end)
	{
		tmp[tmp_pos] = a[left];
		left = left + 1;
		tmp_pos = tmp_pos + 1;
	}

	while (mid <= right)
	{
		tmp[tmp_pos] = a[mid];
		mid = mid + 1;
		tmp_pos = tmp_pos + 1;
	}


	for (i = 0; i <= num_elements; i++)
	{
		a[right] = tmp[right];
		right = right - 1;
	}
}
void m_sort(int a[], int tmp[], int left, int right)
{
	int mid;

	if (right > left)
	{
		mid = (right + left) / 2;
		m_sort(a, tmp, left, mid);
		m_sort(a, tmp, mid + 1, right);

		merge(a, tmp, left, mid + 1, right);
	}
}

int  H,W,ans,N,B,num,T[100001],a[100001],sa[100001];
string s,t,tt,ss;

int main() {
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> a[i];
		if (a[i] < 100001) {
			T[a[i]]++;
		}
		else {
			ans++;
		}
	}

	for (int i = 1; i <= 100000; i++) {
		if (T[i] != 0) {
			if (T[i] < i) {
				ans += T[i];
			}
			else {
				ans += T[i] - i;
			}
		}
	}
		cout << ans << endl;
	return 0;
}




Measured memory_bytes: 640
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#include<tuple>
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-15
#define mp(a1,a2) make_pair(a1,a2)
typedef long long ll;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=1e+18+1;
int INF=1e+9+1;
int S[4000][4000];
int main(){
	int N;
	scan(N);
	if(N==1){
		prin("Yes");prin(2);printf("1 1\n1 1\n");
	}
	else{
		if(fabs(round(sqrt(N*8+1))*round(sqrt(N*8+1))-(N*8+1))<eps){
			prin("Yes");
			int k=(int)((1.0+sqrt(N*8+1))/2+eps);
			prin(k);
			int Snum=k-1;
			int count=1;
			rep(i,k){
				rep(j,Snum){
					if(j>=i){
						S[i][j]=count;
						count++;
					}
					else{
						S[i][j]=S[j][i-1];
					}
				}
			}
			rep(i,k){
				printf("%d ",Snum);
				rep(j,Snum){
					printf("%d ",S[i][j]);
				}
				kaigyo;
			}
		}
		else{
			prin("No");
		}
	}
	return 0;
}


Measured memory_bytes: 8320
#include<iostream>
#include<algorithm>
#define ios ios::sync_with_stdio(false),cin.tie(0),cout.tie(0); 
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const int maxn=2010;
ll a[maxn];
int S;

void cal()
{
	a[1]=0,a[2]=0;
	for(int i=3;i<=5;i++) a[i]=1;
	a[6]=2,a[7]=3;
	for(int i=8;i<=2000;i++) a[i]=(a[i-1]+a[i-3])%MOD;
}



int main()
{
	ios;
	cal();
	cin>>S;
	cout<<(a[S]+MOD)%MOD<<"\n";
	return 0;
}


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

int main()
{
int N;
cin>>N;
int counter=0;
for(int i=1;i<=N;++i)
{
    int n;
    cin>>n;
    if(i%2!=0&&n%2!=0)
        counter++;
}
cout<<counter;
    return 0;
}


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


ull gcd(ull a,ull b){
	if(!b) return a;
	return gcd(b,a%b);
}


int main(){
	ull n,m,cnt = 0;
	cin >> n >> m;
	if(n < m/2){
		cnt += n;
		m -= 2*n;
		cnt += m / 4;
	}
	else{
		cnt += m/2;
	}
	
	cout << cnt << endl;
	return 0;
}

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

using namespace std;

int main() {
  int n, k, x, y;
  cin >> n >> k >> x >> y;
  if( n <= k )
    cout << x * n << endl;
  else {
    cout << x * k + y * ( n - k ) << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
// 任意のi,jの符号ひっくり返せる
// 負が偶数個なら絶対値総和
// 負が奇数個なら絶対値最小のやつだけマイナスにする
// zeroがあればソイツをスケープゴートに出来る
int main() {
    #ifdef DEBUG
    std::ifstream in("/home/share/inputf.in");
    std::cin.rdbuf(in.rdbuf());
    #endif
    int N;
    cin >> N;
    vector<int64_t> A(N), X(N);
    int minus = 0;
    int zero = 0;
    int64_t S = 0;
    for(int i = 0; i < N; i++) {
        cin >> A[i];
        if(A[i] < 0) {
            minus++;
        }
        if(A[i] == 0) zero++;
        X[i] = abs(A[i]);
        S += X[i];
    }
    if(zero || (minus % 2 == 0)) {
        cout << S << endl;
    } else {
        cout << S - 2 * (*min_element(X.begin(), X.end())) << endl;
    }
    return 0;
}

Measured memory_bytes: 1792
#define _USE_MATH_DEFINES
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <numeric>
#include <functional>
#include <cctype>
#include <list>
#include <limits>
#include <cassert>
#include <random>
#include <time.h>
#include <unordered_set>
//#include <boost/multiprecision/cpp_int.hpp>



using namespace std;
using Int = long long;
//using namespace boost::multiprecision;

const double EPS = 1e-10;
long long const MOD = 998244353;

long long mod_pow(long long x, long long n) {
    long long res = 1;
    for (int i = 0;i < 60; i++) {
        if (n >> i & 1) res = res * x % MOD;
        x = x * x % MOD;
    }
    return res;
}

template<typename T>
T gcd(T a, T b) {
    return b != 0 ? gcd(b, a % b) : a;
}

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

void fastInput() {
    cin.tie(0);
    ios::sync_with_stdio(false);
}

int main(void) {
    long long r; cin >> r;
    cout << r * r << endl;
}




Measured memory_bytes: 888
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <utility>
#include <tuple>
#include <cctype>
#define INF 0x3f3f3f3f
#define MOD 1000000007
#define PI 4*atan(1.0)
typedef long long ll;
typedef long double ld;
using namespace std;
int dx[4]={0,0,-1,1};
int dy[4]={-1,1,0,0};
const int SIZE=200001+5000;
//int arr[SIZE]={};
 
int main(){
	ll N;
	cin>>N;
	ll a[51]={};
	for(int i=0;i<N;i++){
		cin>>a[i];
	}
	ll zouka=0;
	bool flag=1;
	ll prev=0;
	while(flag){
		prev=zouka;
		flag=0;
		for(int i=0;i<N;i++){
			if(a[i]+prev>N-1){
				ll times=(a[i]+prev-(N-1)+N)/(N+1);
				a[i]-=times*(N+1);
				zouka+=times;
				flag=1;
				//cout<<times<<endl;
			}
		}
	}
	cout<<zouka<<endl;
	return 0;
}

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

typedef int64_t ll;

template <class T1, class T2>
using dict = std::unordered_map<T1, T2>;

int main(){
    int N,L;
    cin >> N >> L;
    vector<string> vec;
    string s;
    for (int i=0;i<N;i++){
        cin >> s;
        vec.push_back(s);
    }
    sort(vec.begin(),vec.end());
    string ans = "";
    for(auto s: vec){
        ans += s;
    }
    cout << ans << "\n";
}

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

// macro
#define rep(i,n) for(i=0;i<n;i++)
#define ll long long
#define all(v) v.begin(), v.end()

// code starts
int main()
{
  int a;
  cin >> a;
  cout << a+a*a+a*a*a << "\n";
}


Measured memory_bytes: 3632
import numpy as np

N = int(input())
A = [int(x) for x in input().split()]

for i in range(N):
    A[i] -= (i + 1)

b = int(np.median(A))
ans = float('inf')
for j in [0, 1]:
    v = 0
    for i in range(N):
        v += abs(A[i] - (b + j))
    ans = min(ans, v)
print(ans)


Measured memory_bytes: 34188
#include <stdio.h>

int main(void) {
  int a, b, c;

  scanf("%d %d %d", &a, &b, &c);

  if (a == b) {
    printf("%d\n", c);
  } else if (a == c) {
    printf("%d\n", b);
  } else {
    printf("%d\n", a);
  }

  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define sz size()
#define all(a) a.begin(), a.end()
#define allr(a) a.rbegin(), a.rend()
#define mod 1000000007
#define _for(it, a) \
  for (__typeof(a.begin()) it = a.begin(); it != a.end(); ++it)

using namespace std;

int main() {
  int a, b;
  cin >> a >> b;
  if (b <= 0) {
    if (b < 0) {
      int dist = (abs(a) - abs(b) + 1);
      if (dist % 2 == 0)
        cout << "Positive" << endl;
      else
        cout << "Negative" << endl;
    } else {
      cout << "Zero" << endl;
    }
  } else {
    if (a <= 0) {
      cout << "Zero" << endl;
    } else {
      cout << "Positive" << endl;
    }
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
int arr[100010];
int d[100010];
int f(int a, int b ){
	return a-b>0 ? a-b: b-a ;
	
}
int main(){
	int n,i,sum=0; 
	scanf("%d",&n);
	for(i=1;i<=n;i++){
		scanf("%d",&arr[i]);
		sum+=f(arr[i-1],arr[i]);
	}
	sum+=f(arr[i-1],arr[i]);
	for(i=1;i<=n;i++){
		d[i]=f(arr[i-1],arr[1+i])-f(arr[i-1],arr[i])-f(arr[i+1],arr[i]);
		printf("%d\n",sum+d[i]);
	}
	return 0;
}

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

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

#define rep(i, n) for (int i = 0; i < n; i++)
#define rep_op(i, a, n) for (int i = a; i < n; i++)
#define rep_d(j, n) for (int j = n; j >= 0; j--)
#define rep_d_op(j, n, a) for (int j = n; j >= a; j--)

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 int MOD = 1000000007;

const vector<int> dx = {1, 0};
const vector<int> dy = {0, 1};
const ll INF = 1LL << 60;

// int max = *std::max_element(vec.begin(), vec.end());
// int sum = accumulate(list, list + size, 0);

ll h, w;
vector<string> s;

ll dp_min()
{
    vector<vector<ll>> dp(h, vector<ll>(w, INF));
    if (s[0][0] == '#')
    {
        dp[0][0] = 1;
    }
    else
    {
        dp[0][0] = 0;
    }

    rep(i, h)
    {
        rep(j, w)
        {
            rep(dir, 2)
            {
                int ni = i + dx[dir];
                int nj = j + dy[dir];
                if (ni >= h || nj >= w)
                {
                    continue;
                }
                int add = 0;
                if (s[ni][nj] == '#' && s[i][j] == '.')
                {
                    add = 1;
                }
                chmin(dp[ni][nj], dp[i][j] + add);
            }
        }
    }
    return dp[h - 1][w - 1];
}

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

    cin >> h >> w;
    s.resize(h);
    rep(i, h) cin >> s[i];
    cout << dp_min() << endl;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
int main(){
	int a,b,ans=0;
	cin>>a>>b;
	for(int i=1;i<=a;i++){
		for(int j=1;j<=b;j++){
			if(j/10>=2&&j%10>=2){
				if((j/10)*(j%10)==i)ans++;
			}
		}
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
H, W = map(int,input().split())

a = [list(input()) for i in range(H)]
b = ['.']*W

while b in a:
    a.remove(b)

for j in range(W):
    flag = 0
    for i in a:
        if i[j] == '#':
            flag = 1
            break
    if flag == 0:
        for i in a:
            i[j] = ''
    
for i in a:
    print(''.join(i))

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#include <climits>
//#define local
#ifdef local
    #include "dbg-macro/dbg.h"
#endif
//#define hacks
#ifdef hacks
    #include <boost/multiprecision/cpp_int.hpp>
#endif
#define p std::pair
#define ll long long
#define ld long double
#define ull unsigned long long
#define pi std::pair<int, int>
#define mp std::make_pair
#define stdabs std::abs
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (unsigned long long i = 0; i < (unsigned long long)(n); ++i)
#define vec std::vector
#define oreq |=
#define npm next_permutation
#define Yes std::cout << "Yes" << std::endl
#define No std::cout << "No" << std::endl
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
using namespace std;
std::vector<unsigned ll> genprimevec(const unsigned ll N);
ll extgcd(ll a, ll b, ll& x, ll& y);
ll nCr(ll n, ll r);
void stat();
template <typename T> T fact(T num);
constexpr ll mod = 1000000000 + 7;
int main()
{
    stat();
    ll a,b,c,d;cin>>a>>b>>c>>d;
    ll ans=LLONG_MIN;
    ans=max(max(a*c,b*c),max(b*d,a*d));
    cout<<ans<<endl;
    return 0;
}
ll extgcd(ll a, ll b, ll& x, ll& y)
{
    if (b == 0) {
        x = 1, y = 0;
        return a;
    }
    ll d = extgcd(b, a % b, y, x);
    y -= a / b * x;
    return d;
}


std::vector<unsigned ll> genprimevec(const unsigned ll N)
{
    std::vector<bool> is_prime(N + 1);
    for (unsigned ll i = 0; i <= N; i++) {
        is_prime[i] = true;
    }
    std::vector<unsigned ll> P;
    for (unsigned ll i = 2; i <= N; i++) {
        if (is_prime[i]) {
            for (unsigned ll j = 2 * i; j <= N; j += i) {
                is_prime[j] = false;
            }
            P.emplace_back(i);
        }
    }
    return P;
}

void stat(){
#ifdef local
    rep(i, 2){std::cout << "local enable" << std::endl;
}
#endif
#ifdef hacks
rep(i, 2) { std::cout << "boost enable" << std::endl; }
#endif
}

ll nCr(ll n, ll r)
{
    ll num = 1;
    for (ll i = 1; i <= r; i++) {
        num = num * (n - i + 1) / i;
    }
    return num;
}

template <typename T> T fact(T num)
{
    if (num == 1) { return 1; }
    return num * fact(num - 1);
}


Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define aall(x,n) (x).begin(),(x).begin()+(n)
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define sum accumulate
#define keta fixed<<setprecision
#define vvector(name,t,m,n,a)vector<vector<t> > name(m,vector<t> (n,a))
#define vvvector(name,t,l,m,n,a) vector<vector<vector<t> > > name(l, vector<vector<t> >(m, vector<int>(n,a)));
int main(){
  int n,m;
  std::cin >> n;
  std::cout << n*n << std::endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<string>
#include<array>
#include<cmath>
using namespace std;

int main() {
	int n,ans=0;
	array <int, 25> p;
	cin >> n;
	for (int i = 1; i <= n;i++) {
		cin >> p[i];
	}
	for (int i = 2; i < n;i++) {
		if ((p[i-1]<p[i]&&p[i]<p[i+1])|| (p[i + 1] < p[i] && p[i] < p[i - 1])) {
			ans++;
		}
	}
	cout << ans;
}

Measured memory_bytes: 256
n, t = map(int, input().split())
L = [int(i) for i in input().split()]
s = 0
end = 0
 
for i in range(n):
  if (L[i] + t) > end:
    if L[i] < end:
      s += (L[i] + t - end)
    else:
      s += t
  end = (L[i] + t)
print(s)

Measured memory_bytes: 25200
using System;

namespace AtCoder.ABC._112
{
    class a
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine().Trim());
            if (N == 1)
            {
                Console.WriteLine("Hello World");
            }
            else
            {
                var A = int.Parse(Console.ReadLine().Trim());
                var B = int.Parse(Console.ReadLine().Trim());
                Console.WriteLine(A + B);
            }
        }
    }
}


Measured memory_bytes: 11092