akhauriyash/Code-Regression huggingface dataset:
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
 
static const double EPS = 1e-8;
static const double PI = 4.0 * atan(1.0);
static const double PI2 = 8.0 * atan(1.0);
 
#define REP(i,n)	for(int i=0;i<(int)n;++i)
#define ALL(c)		(c).begin(),(c).end()
#define CLEAR(v)	memset(v,0,sizeof(v))
#define MP(a,b)		make_pair((a),(b))
#define ABS(a)		((a)>0?(a):-(a))
#define FOR(i,s,n)	for(int i=s;i<(int)n;++i)

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


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

h = [0] + h
a = [0] + a

dp = [0] * (n+1)

bit = [0] * (n+1)
def update(a, w):
    x = a
    while x <= n:
        bit[x] = max(bit[x], w)
        x += x & -x

def solve(a):
    res = 0
    x = a
    while x > 0:
        res = max(res, bit[x])
        x -= x & -x
    return res

for i in range(1, n+1):
    ma = solve(h[i]-1)
    update(h[i], ma + a[i])

print(max(bit))

Measured memory_bytes: 36044
#include <cstdio>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int main()
{
    int h, w;
    cin >> h >> w;

    vector<string> s(h);
    for(int i=0; i<h; ++i)
        cin >> s[i];

    vector<int> dp(1<<w, -1);
    dp[0] = 0;
    for(int y=0; y<h; ++y){
        for(int x=0; x<w; ++x){
            vector<int> next(1<<w, -1);
            for(int i=0; i<(1<<w); ++i){
                if(dp[i] == -1)
                    continue;

                bitset<32> bs(i);
                int a = (bs & bitset<32>((1 << x) - 1)).count();
                int b = (bs >> x).count();

                if(a + w - x - 1 >= s[y].size()){
                    bitset<32> bs2 = bs << 1;
                    bs2[w] = false;
                    next[bs2.to_ulong()] = max(next[bs2.to_ulong()], dp[i]);
                }

                if(a < s[y].size()){
                    int p = dp[i];
                    if(bs[w-1] && s[y-1][s[y-1].size()-b] == s[y][a])
                        p += 2;
                    if(a > 0 && bs[0] && s[y][a-1] == s[y][a])
                        p += 2;

                    bitset<32> bs2 = bs << 1;
                    bs2[w] = false;
                    bs2[0] = true;
                    next[bs2.to_ulong()] = max(next[bs2.to_ulong()], p);
                }
            }
            dp.swap(next);
        }
    }

    cout << *max_element(dp.begin(), dp.end()) << endl;
}

Measured memory_bytes: 1692
#include <iostream>
#include <vector>
#include <math.h>
#include <algorithm>

using namespace std;

int main()
{
	int i, j, k, l;
	int n, m, a;
	cin >> n >> m;
	vector<int> like;
	like.resize(m);

	for (i = 0; i < m; i++)
	{
		like[i] = 0;
	}

	for (i = 0; i < n; i++)
	{
		cin >> k;

		for (j = 0; j < k; j++)
		{
			cin >> a;
			like[a - 1]++;
		}
	}

	int num = 0;

	for (i = 0; i < m; i++)
	{
		if (like[i] == n)
		{
			num++;
		}
	}

	cout << num;

	return 0;
}


Measured memory_bytes: 888
//Written by Zhu Zeqi
//Come on,baby
//Hack,please
#include<cmath>
#include<math.h>
#include<ctype.h>
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<ciso646>
#include<climits>
#include<clocale>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<cwchar>
#include<cwctype>
#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>
#include<string.h>
#include<stdlib.h>
#include<stdio.h>
#define CLR(x) memset(x,0,sizeof x)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define pii pair<int,int>
#define vi vector<int>
#define MAX 1000000000000000000
#define MOD 1000000007
#define PI 3.141592653589793238462
#define INF 0x3f3f3f3f
typedef long long ll;
//orz yht
using namespace std;
string i_s(int x){
	if(x==0)
	return "0";
	string ret="";
	while(x){
		ret=ret+(char)(x%10+'0');
		x/=10;
	}
	reverse(ret.begin(),ret.end());
	return ret;
}
string add(string a,string b){
	if(a=="")
	a="0";
	if(b=="")
	b="0";
	if(a.length()<b.length())
	swap(a,b);
	while(b.length()<a.length()){
		b='0'+b;
	}
	for(int i=0;i<a.length();i++){
		a[i]=a[i]+(b[i]-'0');
	}
	bool big=false;
	for(int i=a.length()-1;i>=0;i--){
		if(big){
			a[i]++;
		}
		big=false;
		if(a[i]>'9'){
			a[i]=a[i]-10;
			big=true;
		}
	}
	if(big)
	a='1'+a;
	return a;
}
string mul(string a,string b){
	vector<int> va,vb;
	if(a=="0" || b=="0")
	return "0";
	string ans;
	for(int i=0;i<a.length();i++){
		va.push_back(a[i]-'0');
	}
	for(int i=0;i<b.length();i++){
		vb.push_back(b[i]-'0');
	}
	reverse(va.begin(),va.end());
	reverse(vb.begin(),vb.end());
	vector<int> res;
	res.clear();
	res.resize(1005);
	for(int i=0;i<a.length();i++){
		for(int j=0;j<b.length();j++){
			res[i+j]+=(va[i]*vb[j]);
		}
	}
	for(int i=0;i<1005;i++){
		if(res[i]>9){
			res[i+1]+=(res[i]/10);
			res[i]%=10;
		}
	}
	for(int i=0;i<1005;i++){
		ans+=(res[i]+'0');
	}
	reverse(ans.begin(),ans.end());
	int k=0;
	while(ans[k]=='0'){
		k++;
	}
	ans=ans.substr(k);
	return ans;
}
bool is_prime(int n){
	if(n<2)
    return false;
    for(int i=2;i*i<=n;i++)
    if(n%i==0)
    return false;
    return true;
}
int main(){
	//freopen("input.in","r",stdin);
	//freopen("output.out","w",stdout);
	int n,m,k;
	cin>>n>>m>>k;
	if(k%n==0 || k%m==0){
		cout<<"Yes";
		return 0;
	}
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			if(i*m+j*n-i*j*2==k){
				cout<<"Yes";
				return 0;
			}
		}
	}
	cout<<"No";
	//system("pause");
	return 0;
}

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

int main(){
    double a,b,h,m;
    cin>>a>>b>>h>>m;
    double x,y;
    x=h*30+m/2;
    y=m*6;
    double pi=acos(-1);
    double r1=x*pi/180,r2=y*pi/180;
    double dx1=a*cos(r1);
    double dy1=a*sin(r1);
    double dx2=b*cos(r2);
    double dy2=b*sin(r2);
    double dx=dx1-dx2,dy=dy1-dy2;
    printf("%.15f",sqrt(dx*dx+dy*dy));
    return 0;
}


Measured memory_bytes: 4148
using System;
					
public class Program
{
	public static void Main()
	{
		int n = int.Parse(Console.ReadLine());
		
		int[] heap = Array.ConvertAll(Console.ReadLine().Split(" ".ToCharArray()), int.Parse);
		
		for(int i = 0; i < n; i ++)  {
			Console.WriteLine(ConvertString(heap, i));
		}
	}
	
	public static string ConvertString(int[] heap, int i)
	{
		string result = "node " + (i + 1) ;
		
		result += ": key = " + heap[i];
		
		if(i > 0) {
			result += ", parent key = " + heap[(i-1)/2];
		}
		
		if( 2*i+1 < heap.Length) {
			result += ", left key = " + heap[2*i+1];
		}
		
		if( 2 * (i+1) < heap.Length) {
			result += ", right key = " + heap[2*i + 2];
		}
		
		return result + ", ";
	}
}

Measured memory_bytes: 9256
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <unordered_map>
#include <string>
#include <queue>
#include <cmath>
#define ll long long
#define finish(x) cout<<x<<endl
#define all(x) (x).begin(), (x).end()
using namespace std;

ll mod = 998244353;
int main()
{
    ll n;
    cin>>n;
    ll val = sqrt(n);
    ll ans = 1;
    for(ll i = 0;i<=val;i++){
        if(i*i <= n){
            ans = i*i;
        }
    }
    cout<<ans<<endl;
    return 0;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define REP(i, n) for(int i=0; i<n; i++)
#define REPi(i, a, b) for(int i=int(a); i<int(b); i++)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll MOD = 1e9+7;

ll A[20][20];
ll DP[1LL << 17];
ll X[1LL << 17];

int main(){
    int N;
    cin >> N;
    REP(i,N){
        REP(j,N){
            cin >> A[i][j];
        }
    }

    for(ll s = 0; s < (1LL << N); s++){
        vector<int> T;
        REP(i,N){
            if((s >> i) & 1){
                T.push_back(i);
            }
        }

        int sz = T.size();
        ll tmp = 0;
        REP(i,sz){
            REPi(j,i+1,sz){
                int x = T[i];
                int y = T[j];
                tmp += A[x][y];
            }
        }
        X[s] = tmp;
    }

    DP[0] = 0;
    for(ll s = 0; s < (1LL << N); s++){
        //REP(k, s+1){
            //ll bit = k & s;
        for(int bit = s; bit > 0; bit = (bit-1)&s){
            chmax(DP[s], DP[s & ~bit] + X[bit]);
        }
    }

    //REP(i,1LL << N){
    //    printf("%d : %lld, %lld\n", i, X[i], DP[i]);
    //}

    ll ans = 0;
    ans = DP[(1LL << N) - 1];
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1280
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; (i) < (n); ++ (i))
#define loop(i,a,n) for (int i = (a); (i) < (n); ++ (i))
#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF (int)1e9
#define MOD 0
//#define int ll
using namespace std;
typedef vector<long long> vl;

signed main() {
  int n,sum=0;
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n;
  int v[100];
  int c[100];
  rep(i,n) {
    cin >> v[i];
  }
  rep(i,n) {
    cin >> c[i];
  }
  rep(i,n) {
    if(v[i]>c[i]) sum+=v[i]-c[i];
  }
  cout << sum << endl;
}



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

using namespace std;

static const int N = 100;

int main() {
    int n, P[N + 1], m[N + 1][N + 1];
    cin >> n;

    for (int i = 1; i <= n; i++) {
        cin >> P[i - 1] >> P[i];
    }

    for (int i = 1; i <= n; i++) m[i][i] = 0;

    for (int l = 2; l <= n; l++) {
        for (int i = 1; i <= n - l + 1; i++) {
            int j = i + l - 1;
            m[i][j] = (1 << 21);
            for (int k = i; k <= j - 1; k++) {
                m[i][j] = min(m[i][j], m[i][k] + m[k + 1][j] + P[i - 1] * P[k] * P[j]);
            }
        }
    }

    cout << m[1][n] << endl;

    return 0;
}


Measured memory_bytes: 3108
#include <bits/stdc++.h>
using namespace std;
int INF = 10000;
int main(){
  while (1){
    int N;
    cin >> N;
    if (N == 0){
      break;
    }
    vector<int> l(N);
    for (int i = 0; i < N; i++){
      cin >> l[i];
    }
    double m = INF;
    int s, a, c;
    for (int S = 0; S < 16; S++){
      for (int A = 0; A < 16; A++){
        for (int C = 0; C < 16; C++){
          vector<int> R(N + 1);
          R[0] = S;
          for (int i = 0; i < N; i++){
            R[i + 1] = (R[i] * A + C) % 256;
          }
          vector<int> O(N);
          for (int i = 0; i < N; i++){
            O[i] = (l[i] + R[i + 1]) % 256;
          }
          vector<int> cnt(256, 0);
          for (int i = 0; i < N; i++){
            cnt[O[i]]++;
          }
          double tmp = 0;
          for (int i = 0; i < 256; i++){
            if (cnt[i] > 0){
              double r = (double) cnt[i] / N;
              tmp -= r * log(r);
            }
          }
          if (tmp < m - 0.001){
            m = tmp;
            s = S;
            a = A;
            c = C;
          }
        }
      }
    }
    cout << s << ' ' << a << ' ' << c << endl;
  }
}


Measured memory_bytes: 3200
#include<cstdio>
using namespace std;
int main()
{
	int a[40],b[40],i;
	for(i=0;i<7;i++){
		scanf("%d %d",&a[i],&b[i]);
		a[i]-=b[i];
		if(a[i]<0){
			a[i]*=-1;
		}
	}
	for(i=0;i<7;i++){
		printf("%d\n",a[i]);
	}
	return 0;
}



Measured memory_bytes: 2764
#include <stdio.h>
int main(void)
{
	int i,a,b,c,sum=0;
	scanf("%d %d %d",&a,&b,&c);
	for(i=a;i<=b;i++)
	{
		if(c%i==0)
		{
			sum++;
		}
	}
	printf("%d\n",sum);
	return 0 ;
}

Measured memory_bytes: 596
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;
 
public class Main implements Runnable {
	public static void main(String[] args) {
		new Main().solve();
	}
 
	public void run() {
		new Thread(null, new Main(), "", Runtime.getRuntime().maxMemory()).start();
	}
 
	void solve() {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int[] a = new int[m];
		int[] b = new int[m];
		ArrayList<Integer>[] g = new ArrayList[n];
		for (int i = 0; i < g.length; ++i)
			g[i] = new ArrayList<>();
		for (int i = 0; i < m; ++i) {
			a[i] = sc.nextInt();
			b[i] = sc.nextInt();
			--a[i];
			--b[i];
			g[a[i]].add(b[i]);
			g[b[i]].add(a[i]);
		}
		int[] col = new int[n];
		Arrays.fill(col, -1);
		col[0] = 0;
		boolean f = isBibartite(0, col, g);
		if (!f) {
			System.out.println((long) n * (n - 1) / 2 - m);
		} else {
			long u = 0;
			long v = 0;
			for (int i = 0; i < n; ++i) {
				if (col[i] == 0)
					++u;
				else
					++v;
			}
			System.out.println(u * v - m);
		}
	}
 
	boolean isBibartite(int cur, int[] col, ArrayList<Integer>[] g) {
		boolean ret = true;
		for (int dst : g[cur]) {
			ret &= col[cur] != col[dst];
			if (col[dst] == -1) {
				col[dst] = col[cur] ^ 1;
				ret &= isBibartite(dst, col, g);
			}
		}
		return ret;
	}
 
	void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}
 
}

Measured memory_bytes: 106544
/*ANKON GHOSH
  KUET,ECE 2K16*/
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define inf 1e10
#define MAX 100005
#define mod 998244353
#define sf(a) scanf("%lld",&a)
#define sff(a,b) scanf("%lld %lld",&a,&b)
#define sfff(a,b,c) scanf("%lld %lld %lld",&a,&b,&c)
#define Case(i) printf("Case %lld:\n",i)
#define pf(a) printf("%lld ",a)
#define pfsn printf("NO\n")
#define pfs  printf("YES\n")
#define pff(a,b) printf("%lld %lld\n",a,b)
#define FOR(i,n) for(ll i=0;i<n;i++)
#define FOR1(i,n) for(ll i=1;i<=n;i++)
#define LOOP(x,y) for(ll r=x;r<=y;r++)
#define RFOR(i,n) for(ll i=n-1;i>=0;i--)
#define RFOR1(i,n) for(ll i=n;i>0;i--)
#define RLOOP(x,y) for(ll i=y;i>=x;i--)
#define m_p(a,b) make_pair(a,b)
#define p_b(a) push_back(a)
#define ff first
#define ss second
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL)
map<ll,ll>mp,mp1;
vector<pair<ll,pair<ll,pair<ll,ll> > > >vpp,vpp1;
vector<pair<ll,ll> >vp,fin;
vector<ll>v,v1,v2,dummy;
map<pair<ll,ll>,ll>mpp;
///map<ll,bool>mb;
ll n,x,k,a,b,c,d,ta,sum=0,cnt=0,m,l,req,sz,w;
bool sortbysec(const pair<pair<ll,ll>,ll> &a,const pair<pair<ll,ll>,ll> &b)
{
    return (a.second < b.second);
}
struct data
{
    ll weight,value;
} arr[MAX];
ll dp[110][MAX+4];
ll ok;
ll calc(ll pos,ll nisi)
{
    if(pos>n)
    {
        if(nisi==0)
            return 0;
        else
            return inf;
    }
    else if(dp[pos][nisi]!=-1)
        return dp[pos][nisi];
    ll ret=0;
    if(pos==1 or nisi==ok)
    {
        if(nisi-arr[pos].value>=0)
            ret+=min(arr[pos].weight+calc(pos+1,nisi-arr[pos].value),calc(pos+1,nisi));
        else
            ret+=calc(pos+1,nisi);
    }
    else
    {
        if(nisi-arr[pos].value>=0)
            ret=min(ret,min(ret+arr[pos].weight+calc(pos+1,nisi-arr[pos].value),ret+calc(pos+1,nisi)));
        else
            ret=min(ret,ret+calc(pos+1,nisi));
    }
    return dp[pos][nisi]=ret;
}
int main()
{
    fast;
    cin>>n>>w;
    v.clear();
    memset(arr,0,sizeof arr);
    ll sum=0,tot=0;
    FOR1(i,n)
    {
        cin>>arr[i].weight>>arr[i].value;
    }
    memset(dp,-1,sizeof dp);
    FOR1(i,100000LL)
    {
        if(dp[1][i]==-1)
        {
            ok=i;
            ll x=calc(1,i);
            ///if(i<=20)
            ///cout<<dp[1][i]<<" ";
        }
        ///cout<<x<<" ";
    }
        ///cout<<endl;
    ll ans=0;
    FOR1(i,100000LL)
    {
        if(dp[1][i]<=w and dp[1][i]!=-1)
            ans=i;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 87808
package main

import "fmt"

func main() {
	var N string
	fmt.Scan(&N)
	ans := false

	for _, c := range N {
		if c == '7' {
			ans = true
		}
	}
	if ans {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


Measured memory_bytes: 1752
#include <iostream>

using namespace std;

int main(void) {
	string S;
	cin >> S;
	int length = 0, max = 0; 
	for(int i=0; S[i]!='\0'; i++){
		if(S[i]=='A' || S[i]=='C' || S[i]=='G' || S[i]=='T')
			length++;
		else
			length=0;
		if(length>max)
			max = length;
	}
	cout << max;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
signed main(){
  int a,b[1000],c=0;
  cin>>a;
  for(int i=0;i<a;i++){
    cin>>b[i];
  }
  sort(b,b+a);
  for(int i=0;i<a;i++){
    if(b[i]<b[i+1]){
      c++;
    }
  }
  cout<<c+1<<"\n";
}


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

int main() {
  vector<int> a(5);
  int k;
  rep(i, 0, 5) cin >> a[i];
  cin >> k;
  bool f = true;
  int mx = *max_element(a.begin(), a.end());
  int mn = *min_element(a.begin(), a.end());
  cout << (mx - mn <= k ? "Yay!" : ":(") << endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string>
#include <iomanip>
#include <math.h>
#include <utility>
#include <vector>
#include <map>
#include <unordered_map>
#include <cstdlib>
#define div1 1000000007
const long long INF = 1LL << 60;
using namespace std;
using ll = long long;
// a>b -> a==b;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
// a<b -> a==b;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

template <class T> void swap(T& a, T& b) { T t = std::move(a); a = std::move(b); b = std::move(t); }

int main(void)
{
    string S, a;
    ll Q, i, T[300000], F[300000], reverse_count=0, reverse_sum=0, r;
    char C[300000];

    cin >> S >> Q;

    for(i=1; i<=Q; i++){
        cin >> T[i];

        if(T[i]==1){
            reverse_sum++;
        }

        else if(T[i]==2){
            cin >> F[i] >> C[i];
        }
    }

    if(reverse_sum % 2 == 1){
        reverse(S.begin(), S.end());
    }

    for(i=1; i<=Q; i++){
        if(T[i]==1){
            reverse_count++;
        }

        else if(T[i]==2){
            r = reverse_sum - reverse_count;

            if(F[i]==1){ // 前
                if(r%2==0){
                    //S = C[i] + S;
                    a = C[i];
                    S.insert(0, a);
                }
                else{
                    //S = S + C[i];
                    //S += C[i];
                    S.push_back(C[i]);
                }
            }
            else if(F[i]==2){ // 後
                if(r%2==0){
                    //S = S + C[i];
                    // S += C[i];
                    S.push_back(C[i]);
                }
                else{
                    //S = C[i] + S;
                    a = C[i];
                    S.insert(0, a);
                }
            }
        }
    }

    cout << S << endl;

    return 0;
}

Measured memory_bytes: 5892
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
using namespace std;
typedef long long ll;

int N;
ll a[51];

int main(){
    cin >> N;

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

    sort(a, a + N);

    ll ans = 0;
    while(a[N - 1] >= N){
        ll sum = 0;
        vector<ll> x;
        for(int i = 0; i < N; ++i){
            if(a[i] > N - 1)
                x.push_back(a[i] / N);
            else 
                x.push_back(0);
            sum += x[i];
        }
        for(int i = 0; i < N; ++i){
            a[i] -= N * x[i];
            a[i] += (sum - x[i]);
        }

        ans += sum;
        sort(a, a + N);
    }
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define mo 1000000007
#define pi 3.1415926535898
#define eps 1e-9 
using namespace std;
long long read(){
    long long xx=0,flagg=1;
    char ch=getchar();
    while((ch<'0'||ch>'9')&&ch!='-')
        ch=getchar();
    if(ch=='-'){
        flagg=-1;
        ch=getchar();
    }
    while(ch>='0'&&ch<='9'){
        xx=xx*10+ch-'0';
        ch=getchar();
    }
    return xx*flagg;
}
void pus(long long xx,long long flagg){
    if(xx<0){
        putchar('-');
        xx=-xx;
    }
    if(xx>=10)
        pus(xx/10,0);
    putchar(xx%10+'0');
    if(flagg==1)
        putchar(' ');
    if(flagg==2)
        putchar('\n');
    return;
}
int X,n,m,i,r[100005],L,R,ti,a,flag,x,sum;
int cz(int u,int v,int w){
	return max(u,min(v,w));
}
int main(){
   	X=read();n=read();
    for(i=1;i<=n;i++)
    	r[i]=read();
    m=read();
   	R=X;i=0;flag=-1;
    while(m--){
        ti=read();a=read();
        while(i<n&&r[i+1]<=ti){
            x=flag*(r[i+1]-r[i]);
            L=cz(0,X,L+x);
            R=cz(0,X,R+x);
            flag=-flag;
            sum+=x;
            i++;
        }
        pus(cz(0,X,cz(L,R,a+sum)+flag*(ti-r[i])),2);
    }
    return 0;
}

Measured memory_bytes: 1536
#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 fi first
#define se second
#define mp make_pair
#define pb push_back
 
typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef long double ld; 
typedef tree<ii, null_type, less<ii>, rb_tree_tag, tree_order_statistics_node_update> pbds;

const int MOD = (1e9 + 7);
int add(int a, int b)
{
	a+=b;
	while(a>=MOD) a-=MOD;
	return a;
}
int mult(int a, int b)
{
	return (a*1LL*b)%MOD;
}
int modpow(int a, int b)
{
	int r=1;
	while(b)
	{
		if(b&1) r=mult(r,a);
		a=mult(a,a);
		b>>=1;
	}
	return r;
}

int z[555555];

void calcZ(string s)
{
	int n=s.length();
	int L = 0, R = 0;
	for (int i = 1; i < n; i++) {
	  if (i > R) {
		L = R = i;
		while (R < n && s[R-L] == s[R]) R++;
		z[i] = R-L; R--;
	  } else {
		int k = i-L;
		if (z[k] < R-i+1) z[i] = z[k];
		else {
		  L = i;
		  while (R < n && s[R-L] == s[R]) R++;
		  z[i] = R-L; R--;
		}
	  }
	}
}

vi divi[555555];
int pre[555555];
int suf[555555];

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	string s; cin>>s;
	int n=s.length();
	bool pos=0;
	for(int i=0;i<n;i++)
	{
		if(s[i]!=s[0]){pos=1; break;}
	}
	for(int i=1;i<=500000;i++)
	{
		for(int j=2*i;j<=500000;j+=i)
		{
			divi[j].pb(i);
		}
	}
	if(!pos){cout<<n<<'\n'<<1<<'\n'; return 0;}
	calcZ(s);
	for(int i=0;i<n;i++)
	{
		for(int d:divi[i+1])
		{
			if(z[d]>=i-d+1)
			{
				pre[i]=1;
			}
		}
	}
	reverse(s.begin(),s.end());
	calcZ(s);
	for(int i=0;i<n;i++)
	{
		for(int d:divi[i+1])
		{
			if(z[d]>=i-d+1)
			{
				suf[i]=1;
			}
		}
	}
	reverse(suf,suf+n);
	if(!pre[n-1]){cout<<1<<'\n'<<1<<'\n'; return 0;}
	int ans=0;
	for(int i=0;i+1<n;i++)
	{
		if(!pre[i]&&!suf[i+1]) ans++;
	}
	cout<<2<<'\n'<<ans<<'\n';
}


Measured memory_bytes: 64308
"""2020/7/2再挑戦"""
#幅優先探索 親の頂点と色を覚えておく。親の色を除く＋1ずつ足していく。color_maxを超えたら余りをとる。
from collections import deque
N = int(input())
connection ={i:set() for i in range(1,N+1)}
connection_parent =[]
for i in range(1,N):
    a,b = (int(i) for i in input().split())
    connection[a].add(b)
    connection[b].add(a)
    connection_parent.append(b)

#最小の色数
c =[]
for i in connection.values():
    c.append(len(i))
color_min =max(c)

#幅優先探索
start =1
color={i:0 for i in range(1,N+1)} #P:今の頂点と次への辺の色を記録(tuple)。
passed =set() # 通過した記録
dq =deque([start]) #スタートは1でいいのか？
color[start] =0
while len(dq) >0:
    now =dq.popleft()
    passed.add(now)
    c1 =color[now]
    for next in connection[now]:
        if next not in passed:
            c1 +=1
            c1 %=color_min
            color[next] =c1  #0 <=c <= color_min-1のため　＋１
            dq.append(next)
print(color_min)
for i in connection_parent:
    print(color[i] +1)

Measured memory_bytes: 68748
/*
  AOJ 0551
  Title:Icecles
  @kankichi573
*/
#include <stdio.h>
#define max(x,y) (((x)>(y))?(x):(y))
#define min(x,y) (((x)<(y))?(x):(y))
int N,L,a[100002],fold_time[100002];

void calc(int n)
{
  if(a[n]==0 || a[n] < a[n-1] || a[n] < a[n+1])
    return;

  fold_time[n]=max(fold_time[n-1],fold_time[n+1])+(L-a[n]);
  a[n]=0;
  //printf(":%d %d\n",n,fold_time[n]);
  calc(n-1);
  calc(n+1);
}

main()
{
  int i,ret;
  
  scanf("%d %d",&N,&L);
  for(i=1;i<=N;i++)
    scanf("%d",&a[i]);

  for(i=1;i<=N;i++)
    calc(i);

  ret=fold_time[1];
  for(i=2;i<=N;i++)    
    ret=max(ret,fold_time[i]);

  printf("%d\n",ret);

  return(0);
}

Measured memory_bytes: 2548
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi vector<vector<int> >
#define vvl vector<vector<ll> >
#define vl vector<ll>
#define vvv vector<vector<vector<long long int>>>
#define vvvl(a, b, c, d) vector<vector<vector<long long int>>>(a, vector<vector<long long int>>(b, vector<long long int> (c, d)));
typedef long long int ll;
typedef long double ld;
using namespace std;

int main(int argc, char const *argv[]) {
  ll n, K;std::cin >> n >> K;
  std::vector<ll> h(n);
  map<ll, ll> mp;
  mp.emplace(0, 0);
  for(int i=0;i<n;i++){
    std::cin >> h[i];
    mp.emplace(h[i], 0);
  }
  ll c = 0;
  std::vector<ll> cost(mp.size());
  for(auto itr=mp.begin();itr!=mp.end();itr++, c++) {
    (*itr).second = c;
    cost[c] = (*itr).first;
  }
  for(int i=0;i<n;i++) h[i] = mp.at(h[i]);
  ll st = 0;
  for(int i=0;i<n;i++){
    if(i==0) st += cost[h[i]];
    else if(cost[h[i]]>cost[h[i-1]]) st+= cost[h[i]] - cost[h[i-1]];
  }

  vvv dp = vvvl(n+1, mp.size(), K+1, -100000000000000);
  dp[0][0][0] = 0;
  for(int i=1;i<=n;i++){
    for(int j=0;j<mp.size();j++){
      for(int k=0;k<=K;k++){
        dp[i][h[i-1]][k] = max({dp[i][h[i-1]][k], dp[i-1][j][k]});
        if(k==0) continue;
        ll down = 0;
        if(cost[h[i-1]]>cost[j]) down += cost[h[i-1]] - cost[j];
        if(i!=n&&cost[h[i]]>cost[h[i-1]]) down += cost[h[i]] - cost[h[i-1]];
        if(i!=n&&cost[h[i]]>cost[j]) down -= cost[h[i]] - cost[j];
        down = max((ll)0, down);
        dp[i][j][k] = max(dp[i][j][k], dp[i-1][j][k-1] + down);
      }
    }
  }
  ll ans = 0;
  for(int i=0;i<mp.size();i++) ans = max(ans, dp[n][i][K]);
  std::cout << st - ans << '\n';
  return 0;
}


Measured memory_bytes: 216832
#include<iostream>
#include<math.h>

#define REP(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)

using namespace std;

int main () {
  int n, s[1000], i;
  double m, d;
  
  cout.precision(8);
  while (1) {
    cin >> n;
    if (n == 0) break;
    m = 0;
    d = 0;
    rep(i, n) {
      cin >> s[i];
      m += s[i];
    }
    m = m / n;
    rep(i, n) d += pow(s[i]-m, 2.0);
    d = sqrt(d / n);
    cout << fixed << d << endl;
  }
  return 0;
}

Measured memory_bytes: 1236
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ii = pair<int, int>;
using iii = pair<ii, int>;
#define vt vector
#define pq priority_queue
#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define __lcm(a, b) a * b / __gcd(a, b)
const int MOD = 1e9 + 7;
const int INF = 2e9;
const int N = 1e5 + 5;

int n;
int a[N], dp[N];

void getDP() {
    for(int idx = 1; idx <= n; idx++) {
        if(idx == 1) dp[idx] = 0;
        else {
            dp[idx] = dp[idx - 1] + abs(a[idx] - a[idx - 1]);
            if(idx >= 3) 
                dp[idx] = min(dp[idx], dp[idx - 2] + abs(a[idx] - a[idx - 2]));
        }
    }
}

void solve() {
    cin >> n;
    for(int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    getDP();
    cout << dp[n] << "\n";
}

int main() {
 
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    
    solve();
    
}

Measured memory_bytes: 4424
// 2014/06/16 Tazoe

#include <iostream>
using namespace std;

const int INF = 1000000000;

int main()
{
	while(true){
		int n;
		cin >> n;

		if(n==0)
			break;

		int T[10][10];
		for(int i=0; i<10; i++){
			for(int j=0; j<10; j++){
				if(i==j){
					T[i][j] = 0;
				}
				else{
					T[i][j] = INF;
				}
			}
		}

		int m = 0;		// ???????????°

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

			T[a][b] = T[b][a] = c;

			if(a+1>m){
				m = a+1;
			}
			if(b+1>m){
				m = b+1;
			}
		}
		
		for(int k = 0; k < m; k++){
			for(int i = 0; i < m; i++){
				for(int j = 0; j < m; j++){
					if(T[i][j] > T[i][k] + T[k][j]){
						T[i][j] = T[i][k]+ T[k][j];
					}
				}
			}
		}

		int town = m - 1;
		int value = INF;
		for(int i = m - 1; i >= 0; i--){
			int tempValue = 0;
			for(int j = 0; j < m; j++){
				tempValue += T[i][j];
			}
			if(value >= tempValue){
				value = tempValue;
				town = i;
			}
		}
		cout << town << ' ' << value << endl;
	}

	return 0;
}

Measured memory_bytes: 3000
//Bismillahirrahmanirrahim
//█▀█─█──█──█▀█─█─█
//█▄█─█──█──█▄█─█▄█
//█─█─█▄─█▄─█─█─█─█

#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>

using namespace std;

typedef long long lo;
typedef pair< lo,lo > PII;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define FOR for(int i=1;i<=n;i++)
#define mid ((start+end)/2)
#define ort ((bas+son)/2)

const lo MAX = -1000000000000000000;
const lo MIN = 1000000000000000000;
const lo inf = 1000000000;
const lo KOK = 100000;
const lo LOG = 30;
const lo li = 500005;
const lo mod = 1000000007;

int n,m,b[li],a[li],k,flag,t;
int cev;
string s;
vector<int> v;

int main(void){
	scanf("%d",&n);
	double at=n/3.0;
	printf("%.18lf\n",at*at*at);
	return 0;
}



Measured memory_bytes: 256
#include<stdio.h>

int main()
{
  int length;
  int n[100];
  int i, j, min_i;
  int tmp;
  int count = 0;

  scanf("%d", &length);
  for(i = 0; i < length; i++)
    {
      scanf("%d",&n[i]);
    }
  
  for(i = 0; i < length; i++)
    {
      min_i = i;
      for(j = i; j < length; j++)
	{
	  if(n[j] < n[min_i]) min_i = j;
	}
      if(i != min_i)
	{
	  tmp = n[i];
	  n[i] = n[min_i];
	  n[min_i] = tmp;
	  count++;
	}
    }

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

  return 0;
}

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

vector<vector<int> >a(200005,vector<int>());

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,m,i,j,k;
    cin>>n>>m;
    for(i=0;i<m;i++)
    {
        cin>>j>>k;
        a[j].push_back(k);
        a[k].push_back(j);
    }
     for(i=2;i<=n-1;i++)
     {
         k=0;
         for(j=0;j<a[i].size();j++)
         {
             if(a[i][j]==1 || a[i][j]==n)
             {
                 k++;
             }
         }
         if(k==2)
         {
             cout<<"POSSIBLE"<<endl;
             return 0;
         }
     }
     cout<<"IMPOSSIBLE"<<endl;


}


Measured memory_bytes: 14916
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 998244353;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-11;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
typedef pair<ld, ld> LDP;
int main() {
	string s; cin >> s;
	int used[26] = {};
	int n = s.length();
	rep(i, n) {
		int t = s[i] - 'a';
		used[t] = 1;
	}
	bool f = false;
	rep(i, 26) {
		if (!used[i]) {
			cout << (char)('a' + i) << endl; f = true; break;
		}
	}
	if (!f)cout << "None" << endl;
	return 0;
}

Measured memory_bytes: 512
{-# LANGUAGE ScopedTypeVariables #-}
import Control.Monad
import qualified Data.ByteString.Char8 as BS
 
main = do
    [a, b, c] :: [Int] <- map ( read . BS.unpack ) . BS.words <$> BS.getLine
    putStrLn $ show $ min c (b `div` a)

Measured memory_bytes: 508
#include <iostream>
using namespace std;
int main(){
    int a,b,c,x,y,z;
    cin >>a>>b>>c;
    if(a<b){
        if(a<c){
            x = a;
            if(c<b){
                y = c;
                z = b;
            }else{
                y = b;
                z = c;
            }
        }else{
            y = a;
            if(b<c){
                x = b;
                z = c;
            }else{
                x = c;
                z = b;
            }
        }
    }else if (a<c){
        y = a;
        if(b<c){
            x = b;
            z = c;
        }else{
            x = c;
            z = b;
        }
    }else{
        z = a;
        if(b<c){
            x = b;
            y = c;
        }else{
            x = c;
            y = b;
        }
    }
    cout << x << " " << y << " " << z << endl;
}


Measured memory_bytes: 3084
#include<stdio.h>
int main (void) {
int i,j,a,n,ans;
  char s[200];
  scanf("%s",s);
  i=0,j=0,ans;
  while(s[n]!='\0'){n++;}
  
  for(i=2;i<n;i+=2){a=0;
    for(j=0;j<(n-i)/2;j++){
      if(s[j]!=s[(n-i)/2+j]){a++;}  
    }
    if(a==0){ans=n-i;break;}
  }
  printf("%d\n",ans);
  return 0;

}


Measured memory_bytes: 1700
C = [[int(i) for i in input().split()] for i in range(3)]
minList = []

for i in range(3):
    if i == 0:
        minList = C[i]
    else:
        for j in range(3):
            minList[j] = min(minList[j], C[i][j])

for i in range(3):
    diff = [x-y for (x,y) in zip(C[i], minList)]
    if diff[0] == diff[1] == diff[2]:
        if i == 2:
            print("Yes")
    else:
        print("No")
        break

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

int main()
{
  long long int n,p;
  cin>>n>>p;
  vector <pair <long long int,long long int>> points;
  for(int j = 0 ; j < n; j++)
  {
    long long int a,b;
    cin>>a>>b;
    points.push_back(make_pair(a,b));
  }
  double d = d * (1.00);
  long long int counts = 0;
  for(int j = 0 ; j < n; j++)
  {
    long long int dis = points[j].first * points[j].first;
    dis += (points[j].second * points[j].second);
    double sq = sqrt(dis);
    if(sq <= p)
    {
      counts += 1;
    }
  }
  cout<<counts<<"\n";
  return 0;
}

Measured memory_bytes: 7436
#include<iostream>
#include<vector>
#include<string>
#define ll long long
using namespace std;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
  	string S,T,U;
  	cin>>S>>T;
  	int A,B;
  cin>>A>>B>>U;
 	if(U==S)
      A--;
  	else 
      B--;
  cout<<A<<" "<<B<<'\n';
}

Measured memory_bytes: 256
#include <stdio.h>
#define N 100

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



Measured memory_bytes: 2108
import java.util.ArrayList;
import java.util.Scanner;

class Main{
	public static void main(String[] args){
		Scanner insert = new Scanner(System.in);
		ArrayList<Integer> result = new ArrayList<Integer>();
		while(true) {
			int n = insert.nextInt();
			if(n==0) {
				break;
			}
			int count2 = 0;
			for(int i =(n+1); i <= 2 * n;i++) {
				if(i==1 || i==2) {
					count2++;
				}
				else if(i%2==1) {
					if(isSosu(i)==true) {
						count2++;
					}			
				}
			}
			result.add(count2);
			
		}
		for(int a:result) {
			System.out.println(a);
		}
	}
	public static boolean isSosu(int n){
		for(int i = 2; i <= Math.sqrt(n);i++) {
			if(n%i == 0) {
				return false;
			}
		}
		return true;
	}
	
}


Measured memory_bytes: 27620
import java.util.*;

public class Main {
	static boolean search(String tar , String str){
		boolean f = false;
		for(int j=0;j<str.length();j++){
			if(tar.equals(str))return true;
			if(tar.charAt(0)==str.charAt(j)){//ターゲットの先頭文字と一致する文字をstrから探す
				int cnt=0;
//				System.out.println(j + "   " +" " +tar.charAt(0) + " " + str.charAt(j));
				for(int i=j+1;i<str.length();i++){//２文字目の探索
					cnt++;
					if(str.length()<j+cnt)continue;
					if(tar.charAt(1)==str.charAt(i)){
						if((j+tar.length()-1*cnt)>str.length())break;//
//						System.out.println(j + "   " +" " +tar.charAt(1) + " " + str.charAt(i));
						for(int k=2;k<tar.length();k++){//３文字目以降の文字の探索
							if(j+k*cnt>=str.length()){f=false;break;}//
//							System.out.println(j + " " + cnt + " "+ tar.charAt(k) + " " + str.charAt(j+k*cnt));
							if(tar.charAt(k)==str.charAt(j+k*cnt))f = true;
							else {
								f = false;
								break;
							}
						}
						if(f==true) return f;
					}
				}
			}
		}		
		return f;
	}

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int ans = 0;
		String tar = sc.next();
		for(int i=0;i<n;++i){
			String s = sc.next();
			if(search(tar,s))ans++;
//			System.out.println("----" + i + " " + ans);
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 20592
def dijkstra(g, s)

  # inf = 10 ** 12
  inf = Float::INFINITY
  dist = Array.new(g.size, inf)
  dist[s] = 0

  # que = PriorityQueue.new
  q = []
  q << [0, s]

  while q.any?

    d, v = q.pop
    # next if dist[v] < d
    # p g[v]
    g[v].each do |(u, c)|
      if dist[u] >= inf
        t = d + c
        dist[u] = t
        q.push( [t, u ] )
      end
    end
    # p que
  end

  # dist.map!{|d| d == inf ? "INF" : d }
  dist
end

n = gets.to_s.to_i
# n = gets.to_s.split.map{|t|t.to_i}

G = Array.new(n){ [] }
(n-1).times do
  s, t, d = gets.to_s.split.map{|t|t.to_i}
  s -= 1
  t -= 1
  G[s] << [t, d]
  G[t] << [s, d]
end
# pp G
q, k = gets.to_s.split.map{|t|t.to_i}
k -= 1
dist = dijkstra(G, k)
ans = []
q.times do
  x, y = gets.to_s.split.map{|t|t.to_i-1}
  ans << (dist[x] + dist[y])
end

puts ans


# judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=GRL_1_A
# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=GRL_1_A
# http://judge.u-aizu.ac.jp/onlinejudge/review.jsp?rid=4445328


Measured memory_bytes: 29240
#include <iostream>
#include <vector>
#include <math.h>
#define eol '\n'
using namespace std;

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

  int N;
  cin >> N;

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

  int avg = round((double)sum / (double)N);

  long var = 0;
  for (int i = 0; i < N; i++) {
    var += (a[i] - avg) * (a[i] - avg);
  }

  cout << var << eol;
  
  return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;


typedef tree<int, null_type, less<int>, rb_tree_tag,
        tree_order_statistics_node_update>
        new_data_set;


#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define PSET(x,y) fixed<<setprecision(y)<<x
#define pb push_back
#define pf push_front
#define pii pair<int,int>
#define mp make_pair
#define vi vector<int>
#define vip vector<pair<int,int> >
#define ff first
#define ss second
#define int long long
#define SIZE 200010
#define mod 1000000007
#define BIG 998244353
#define s(t) scanf("%d",&t)
#define p(t) printf("%d\n",t)
#define mii map<int,int>
#define MSET(table,i) memset(table, i, sizeof(table))
#define endl '\n'
#define tc int t;cin>>t;while(t--)
#define pi  3.1415926358
#define print(x) for(auto el: x) cout<<el<<" ";cout<<endl
#define bits(x) __builtin_popcount(x)
#define minimum(a,n) min_element(a,a+n)-a
#define maximum(a,n) max_element(a,a+n)-a
#define pqbig priority_queue<int>
#define pqsmall priority_queue<int,vector<int>,greater<int> >
#define all(v) v.begin(),v.end()
#define sitr set<int>:: iterator
#define mitr map<int,int>:: iterator


#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl


int32_t main()
{
    fast;
    int m,d;cin>>m>>d;
    int ans=0;
    for(int i=1;i<=m;i++)
    {
        for(int j=22;j<=d;j++)
        {
            if(j/10>=2 and j%10>=2 and (j/10)*(j%10)==i)
                ans++;
        }
    }
    cout<<ans;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <vector>

static const int IINF = 1 << 30;
static const long long LINF = 1LL << 60;
static const long long MOD = 1.0e+9 + 7;

template <typename T> std::vector<T> vectors(std::size_t n, T val) {
  return std::vector<T>(n, val);
}

template <typename T, typename... Args>
auto vectors(std::size_t n, Args... args) {
  return std::vector<decltype(vectors<T>(args...))>(n, vectors<T>(args...));
}

template <class T> inline bool chmin(T &a, const T &b) {
  return (a > b) ? a = b, true : false;
}

template <class T> inline bool chmax(T &a, const T &b) {
  return (a < b) ? a = b, true : false;
}

template <class T> inline void chadd(T &a, const T &b) {
  a += b, a %= MOD;
  // TODO minus case
}

template <class T>
std::ostream &operator<<(std::ostream &s, const std::vector<T> &v) {
  if (v.empty())
    return s;
  s << *v.begin();
  for (auto iter = v.begin() + 1; iter != v.end(); ++iter)
    if (std::is_fundamental<T>::value)
      s << " " << *iter;
    else
      s << std::endl << *iter;
  return s;
}

int main() {
  // Input
  int N, D;
  std::cin >> N >> D;

  std::cout << (N + 2 * D) / (2 * D + 1) << std::endl;

  // Output

  return 0;
}


Measured memory_bytes: 256
// https://atcoder.jp/contests/abc086/tasks/arc089_a

#include <algorithm>
#include <cmath>   // abs() for float, and fabs()
#include <cstdlib> // abs() for integer
#include <iostream>
#include <string>
using namespace std;
#define max(a, b) (((a) > (b)) ? (a) : (b))
#define min(a, b) (((a) < (b)) ? (a) : (b))

int main() {
    int n, t, x, y, dt, ans = 0, X = 0, Y = 0, T = 0;
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> n;

    for (int i = 0; i < n; i++) {
        cin >> t >> x >> y;
        // 前回から移動できるか確認
        if (ans == 0) {
            dt = abs((X - x) + (Y - y));
            // 時間内にたどり着けて、余りが２の倍数の場合
            if (dt <= (t - T) && (t - T) % 2 == dt % 2) {
                X = x;
                Y = y;
                T = t;
            } else {
                ans = -1;
            }
        }
    }

    if (ans == 0) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int Euclidean(int a, int b);

int main(void){
  int a, b, gcd, lcm;

  while(scanf("%d%d", &a, &b) != EOF){
    gcd = Euclidean(a, b);
    lcm = b * (a / gcd);
    printf("%d %d\n", gcd, lcm);
  }
  return 0;
}


int Euclidean(int a, int b){
  int r;

  if(a < b){
    r = a;
    a = b;
    b = r;
  }
  while(b != 0){
    r = a % b;
    a = b;
    b = r;
  }
  return a;
}

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

using namespace std;


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

	int child[n+1]={0};

	for(int i=0;i<n-1;i++)
	{
		int x;
		cin>>x;
		child[x]++;
	}

	for(int i=1;i<=n;i++)
	{
		cout<<child[i]<<endl;
	}

	return 0;

}


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

bool is_105(const int n) {
  if(n % 2 == 0) {
    return false;
  }
  int count = 0;
  for(int i = 1; i <= n; ++i) {
    if(n % i == 0) {
      count++;
    }
  }
  return count == 8;
}

int main() {
  int N;
  cin >> N;
  int ans = 0;
  for(int i = 1; i <= N; ++i) {
    if(is_105(i)) {
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline
ra = range
enu = enumerate


def read_ints():
    return list(map(int, read().split()))


def read_a_int():
    return int(read())


def read_tuple(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(tuple(map(int, read().split())))
    return ret


def read_col(H, n_cols):
    '''
    H is number of rows
    n_cols is number of cols
    A列、B列が与えられるようなとき
    '''
    ret = [[] for _ in range(n_cols)]
    for _ in range(H):
        tmp = list(map(int, read().split()))
        for col in range(n_cols):
            ret[col].append(tmp[col])
    return ret


def read_matrix(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return ret
    # return [list(map(int, read().split())) for _ in range(H)] # 内包表記はpypyでは遅いため


def read_map(H):
    '''
    H is number of rows
    文字列で与えられた盤面を読み取る用
    '''
    return [read()[:-1] for _ in range(H)]


def read_map_as_int(H):
    '''
    #→1,.→0として読み込む
    '''
    ret = []
    for _ in range(H):
        ret.append([1 if s == '#' else 0 for s in read()[:-1]])
        # 内包表記はpypyでは若干遅いことに注意
        # #numpy使うだろうからこれを残しておくけど
    return ret


MOD = 10**9 + 7
INF = 2**31  # 2147483648 > 10**9
# default import
from collections import defaultdict, Counter, deque
from operator import itemgetter
from itertools import product, permutations, combinations
from bisect import bisect_left, bisect_right  # , insort_left, insort_right
from math import gcd


def lcm(a, b):
    # 最小公倍数
    g = gcd(a, b)
    return a * b // g


N = read_a_int()
S = read()[:-1]
# 3文字選んで全部違う文字かつ、同じ分離れてるものじゃない
# 全通り-同じ分離れてる通り

# 全通り→sum_i i文字
# i文字目は何通りできるか？→(i:]文字の中でi文字目と違う文字の数nに対してnC2

# 同じ分離れている通り(削除する分)はどうやって数えるか？
# →O(n^2)かけてスライドさせて見てみるか...
# n_diff = []  # i文字目と違う文字が何文字あるか
n_r = S.count('R')
n_g = S.count('G')
n_b = S.count('B')
tmp = {'R': n_r,
       'G': n_g,
       'B': n_b}
total = 0
for s in S:
    tmp[s] -= 1
    if s == 'R':
        n_diff = tmp['G'] * tmp['B']
    elif s == 'G':
        n_diff = tmp['R'] * tmp['B']
    if s == 'B':
        n_diff = tmp['G'] * tmp['R']
    total += n_diff


# O(nn)かけて条件を満たさない個数を探す
# 条件がないときに違う組み合わせの通りの数はわかっている
# 条件を満たしてしまうときは？組み合わせの中で
rem = 0
for add in ra(1, N + 1):
    if add * 2 >= N:
        break
    for i in ra(N):
        j = i + add
        k = j + add
        if k >= N:
            break
        # if S[i] == S[j] or S[j] == S[k] or S[k] == S[i]:
        if S[i] != S[j] and S[j] != S[k] and S[k] != S[i]:

            # print(i, j, k)
            # print(S[i], S[j], S[k])
            rem += 1

print(total - rem)
# print(total, rem)


Measured memory_bytes: 68700
#include <stdio.h>          // putchar(), scanf()
#include <stdbool.h>

int
main(int argc, char **argv)
{
	char abacus[10][8] = {"* = ****",  "* =* ***",  "* =** **",  "* =*** *",  "* =**** ",  " *= ****",  " *=* ***",  " *=** **",  " *=*** *",  " *=**** "};
	int x;

	bool f = false;
	while (scanf("%d", &x) != EOF)
	{
		int a[5];
		for (int i = 4; i >= 0; --i)
		{
			a[i] = x % 10;
			x /= 10;
		}

		if (f)
			putchar('\n');

		for (int i = 0; i < 8; ++i)
		{
			for (int j = 0; j < 5; ++j)
				putchar(abacus[a[j]][i]);

			putchar('\n');
		}

		f = true;
	}

	return 0;
}

Measured memory_bytes: 1740