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

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using WGraph = vector<vector<pair<int, ll>>>;

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

constexpr int dx[4] = {-1, 0, 0, 1}, dy[4] = {0, -1, 1, 0};
constexpr int INF = 1e9;
constexpr int MOD = 1e9 + 7;
constexpr long long LINF = 1e18;
constexpr double EPS = 1e-10;
constexpr double PI = M_PI;

bool check(const vector<pair<int, int>> &v) {
    int cur = 0;
    for (auto p : v) {
        if (cur + p.first < 0) {
            return false;
        }
        cur += p.second;
    }
    return true;
}

void solve() {
    int n;
    cin >> n;

    int total = 0;
    vector<pair<int, int>> up, down;
    for (int i=0; i<n; ++i) {
        string s;
        cin >> s;
        int cur = 0;
        int mini = INF;
        for (char c : s) {
            if (c == '(') ++cur;
            else --cur;
            chmin(mini, cur);
        }
        if (cur >= 0) {
            up.push_back({mini, cur});
        } else {
            down.push_back({mini-cur, -cur});
        }
        total += cur;
    }
    sort(up.rbegin(), up.rend());
    sort(down.rbegin(), down.rend());
    if (check(up) && check(down) && total == 0) cout << "Yes" << '\n';
    else cout << "No" << '\n';
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);

    solve();

    return 0;
}


Measured memory_bytes: 11304
#include<cstdio>
#include<algorithm>
#include<cstring>
#define ll long long
using namespace std;
const ll MOD=1e9+7;
ll n,k,a[2005];
int main()
{
	scanf("%lld%lld",&n,&k);
	for(int i=1;i<=n;i++)scanf("%lld",&a[i]);
	ll ans=0;
	for(int i=1;i<=n;i++)
	  for(int j=i+1;j<=n;j++)
	    if(a[i]>a[j])ans+=k;
	ans%=MOD;
	for(int i=1;i<=n;i++)
	{
		ll num=0;
		for(int j=1;j<=n;j++)
		  if(a[i]>a[j])num++;
		ans+=k*(k-1)/2%MOD*num%MOD;
	}
	ans%=MOD;
	printf("%lld\n",ans);
	return 0;
}

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

using ll = long long;
using ull = unsigned long long;

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

#define sz(s) (s).size()
#define pb push_back
#define fi first
#define se second
#define REP(i,n) for (int i = 0; i<n; i++)
#define ALL(a) begin(a), end(a)

int main (void) {
    int N,K;
    cin>>N>>K;
    map<int,int> mp;
    REP(i,N) {
        int t;
        cin>>t;
        if (mp.find(t) == mp.end()) mp[t] = 1;
        else mp[t]++;
    }
    vector<int> A;
    for (auto x:mp) {
        A.pb(x.se);
    }
    sort(ALL(A));
    int ans = 0;
    if (A.size() <= K) {
        cout<<ans<<endl;
        return 0;
    }
    REP(i,A.size()-K) {
        ans += A[i];
    }
    cout<<ans<<endl;
    return 0;
}

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

using namespace std;

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

const ll LongINF=1e13+7;
const int INF=1e9+7;
const int dx[]={0,1,0,-1};
const int dy[]={1,0,-1,0};

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;}
template <class T, class Y>T GCD(T a, Y b){if(a<b){int c=a;a=b;b=c;}if (a % b == 0){return b;}return GCD(b, a % b);}
template<class T,class Y>T LCM(T a,Y b){return (a*b)/GCD(a,b);}
void clear(queue<pair<int, int>> &q){queue<pair<int, int>> empty;swap(q, empty);} //queueの中身の型は適時変更を忘れない

using vi=vector<int>;
using vii=vector<vi>;

#define REP(i,a,b) for(ll i=(a);i<(b);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define rv reverse
#define ALL(a) (a).begin(),(a).end()
#define decimal(x) fixed<<setprecision(x)

int main(){
	int a;
    cin>>a;
    cout<<a+a*a+a*a*a<<endl;
    return 0;
}

//a=97,z=122

Measured memory_bytes: 3588
a = int(input())
b = int(input())
c = int(input())
x = int(input())
ans = 0
for i in range(a+1):
  for j in range(b+1):
    for k in range(c+1):
      if 500*i + 100*j + 50*k == x:
        ans += 1
print(ans)

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

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }
#define printpair(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<"{"<<_.first<<","<<_.second<<"}"<<", "; cerr<<"]"<<endl; }

typedef long long ll;

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

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

const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
int N;
vector<vector<pair<int,int>>> G;
vector<int> color;

void dfs(int i, int pre, int pre_c){
    int cnt = 1;
    for(auto ni: G[i]){
        if(ni.first == pre)continue;
        if(cnt == pre_c){
            cnt++;
        }
        color[ni.second] = cnt;
        dfs(ni.first, i, color[ni.second]);
        cnt++;
    }
}

int main() {
    cin>>N;
    G.resize(N);
    color.resize(N-1);
    rep(i,N-1){
        int a,b; cin>>a>>b;
        a--;b--;
        G[a].push_back({b,i});
        G[b].push_back({a,i});
    }
    int maxc = 0;
    int start = 0;
    rep(i,N){
        if(maxc < (int)G[i].size()){
            chmax(maxc, (int)G[i].size());
            start = i;
        }
    }
    cout<<maxc<<endl;

    dfs(0, -1, -1);
    rep(i,N-1){
        cout<<color[i]<<endl;
    }
}


Measured memory_bytes: 8320
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = (s); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) for(int i = (n); i >= 0; i--)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << '\n';
#define CFYN(n) cout << ( (n) ? "YES":"NO") << '\n';
#define OUT(n) cout << (n) << '\n';
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;

int main(void)
{
    IOS
    int N; cin >> N;
    int odd = 0;
    REP(i,N) {
        int a; cin >> a;
        if (a % 2 == 1) odd++;
    }

    CFYN(odd % 2 == 0)

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string.h>
#include <set>
#include <map>
#include <unordered_map>
#include <assert.h>
#include <algorithm>
#include <queue>
#include <bitset>
#include <stack>
#include <chrono>
#include <random>
#define all(x) x.begin(),x.end()
#define ff first
#define ss second
#define ll long long
#define INF 1000000000000000000
#define MOD 1000000000
#define rnd mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define FIO ios_base::sync_with_stdio(false); cin.tie(NULL);
#define uid uniform_int_distribution <int>
using namespace std;
// Read the question carefully and see all the given sample tests
// Think about the correctness before implementing

int main() {
	int n;
	cin >> n;
	int mn = MOD;
	int sum = 0;
	for (int i = 0; i < n; i++) {
		int x;
		cin >> x;
		if (x % 10 == 0) {
			sum += x;
		}
		else {
			sum += x;
			mn = min(mn, x);
		}
	}
	if (sum % 10 != 0) {
		cout << sum;
	}
	else {
		if (mn == MOD) {
			cout << 0;
		}
		else {
			cout << sum - mn;
		}
	}
}


Measured memory_bytes: 256
#include <iostream>
#include <set>
#include <map>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <deque>
#include <cstring>
#include <stack>
#include <climits>
#include <math.h>
#include <cassert>
#include <unordered_map>
using namespace std;
#pragma warning(disable : 4996)
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;



int main() {
#ifdef _DEBUG
	freopen("input1.txt", "r", stdin);
	freopen("output2.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	string s;
	cin >> s;
	ll ans = 0;
	map<ll, ll> m;
	m[0] = 1;
	ll cur = 0, p = 1;
	for (int i = s.size() - 1; i >= 0; i--) {
		cur += p * (s[i] - '0');
		cur %= 2019;
		ans += m[cur];
		m[cur]++;
		p = (p * 10) % 2019;
	}
	cout << ans;
} 

Measured memory_bytes: 3744
import Control.Monad
import Data.Maybe
import qualified Data.ByteString.Char8 as BS
import Data.List

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine

main = do
    [a, b, c, d] <- getIntList
    putStrLn $ takahashi a b c d

takahashi a b c d | a <= 0 = "No"
                  | otherwise = aoki a b (c-b) d
aoki a b c d | c <= 0 = "Yes"
             | otherwise = takahashi (a-d) b c d

Measured memory_bytes: 3672
import itertools
# import math
# import sys
# import numpy as np

# K = int(input())
# S = input()
# n, *a = map(int, open(0))
N, M, Q = map(int, input().split())
# A = list(map(int, input().split()))
# Q = list(map(int, input().split()))
# S = input()

# d = sorted(d.items(), key=lambda x:x[0]) # keyでsort

conditions = []
for i in range(Q):
    conditions.append(list(map(int, input().split())))

# all_cases = list(itertools.permutations(P))
a = list(itertools.combinations_with_replacement([i for i in range(1, M + 1)], N))
# print(a[0][0])
# print(conditions[0])

max_score = 0
for t in a:
    tot = 0
    for condition in conditions:
        if t[condition[1] - 1] - t[condition[0] - 1] == condition[2]:
            tot += condition[3]
    if tot > max_score:
        max_score = tot
print(max_score)

Measured memory_bytes: 21484
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <cassert>
using namespace std;
typedef long long ll;
const int INF = 1<<30;
const ll MOD = 1e9+7;
const double EPS = 1e-9;


int main(int argc, const char * argv[]) {
  int N; cin >> N;
  vector<int> a(N);
  for(int i=0; i<N; i++)
    cin >> a[i];
  
  
  multiset<int> s;
  s.insert(a[0]);
  for(int i=1; i<N; i++){
    auto it = s.lower_bound(a[i]);
    if (it != s.begin()) {
      it--;
      s.erase(it);
    }
    s.insert(a[i]);
  }
  cout << s.size() << endl;
  return 0;
}

Measured memory_bytes: 5376
from collections import defaultdict

n, m = [int(x) for x in input().split(' ')]
py = [tuple(input().split(' ')) for _ in range(m)]

d = defaultdict(list)

for x, y in py:
    d[x].append(int(y))

ans = {}

for k, v in d.items():
    for i, x in enumerate(sorted(v), start=1):
        ans[(k, str(x))] = k.zfill(6) + str(i).zfill(6)

for x in py:
    print(ans[x])


Measured memory_bytes: 71500
import java.util.*;
public class Main {
    static long gcd(long a, long b) {
        if(a<b) {
            long t = b;
            b = a;
            a = t;
        }
        if(b==0) {
            return a;
        }
        return gcd(a%b, b);
    }
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int  t = sc.nextInt();
        while(t-->0){
            long a = sc.nextLong();
            long b = sc.nextLong();
            long c = sc.nextLong();
            long d = sc.nextLong();
            long diff = a-b;
            if(diff<0){
                System.out.println("No");
            } else
            if(b>d){
                System.out.println("No");
            } else
            if(c>=b) System.out.println("Yes");
            else {
                long gc = gcd(b,d);
                if((a%gc+b-gc) > c) {
                    System.out.println("No");
                } else System.out.println("Yes");
            }
        }
    }
}


Measured memory_bytes: 25288
#include<iostream>
#include<iomanip>
#include<vector>
#include<algorithm>
#include<string>
using namespace std;
typedef long long ll;
#define MOD 1000000007

template<class T> inline void chmax(T& a, T b) { if (a < b) a = b; }
template<class T> inline void chmin(T& a, T b) { if (a > b) a = b; }


int main()
{
	int H, N; cin >> H >> N;
	vector<int> dp(H + 1, 1 << 30);//iダメージを与えるのに必要な最小魔力
	vector<int> A(N), B(N);
	for (int i = 0; i < N; ++i) {
		cin >> A[i] >> B[i];
	}
	dp[0] = 0;
	for (int h = 0; h <= H; ++h) {
		for (int n = 0; n < N; ++n) {
			if (h - A[n] < 0) {
				chmin(dp[min(A[n], H)], dp[0] + B[n]);
			}
			else {
				chmin(dp[min(h + A[n], H)], dp[h] + B[n]);
			}
		}
	}
	cout << dp[H] << endl;
	return 0;
}


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

#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define RFOR(i, a, b) for(int i=(a); i>=(b); i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, n, 0)
#define CEIL(n, m) ceil(n/pow(10.0, m))*pow(10.0, m)
#define FLOOR(n, m) floor(n/pow(10.0, m))*pow(10.0, m)
#define ROUND(n, m) round(n/pow(10.0, m))*pow(10.0, m)
#define ALL(x) (x).begin(),(x).end()
#define SORT(x) sort((x).begin(),(x).end())
#define RSORT(x) sort((x).begin(),(x).end(),greater<int>())
#define SZ(x) ((int)(x).size())
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define llong long long
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) " (L" << __LINE__ << ") " << __FILE__ << endl;

void solve()
{
  int n; cin >> n;
  vector<llong> t(n), a(n); REP(i, n) cin >> t[i] >> a[i];

  llong z=0;
  llong x=1, y=1;
  for (int i=0; i<n; i++) {
    z = max((x-1)/t[i]+1, (y-1)/a[i]+1);
    x = z * t[i];
    y = z * a[i];
  }

  cout << x+y << endl;
}

int main()
{
  solve();
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
 int main(void)
 {
     int N,i;
     double A,B;

     scanf("%d",&N);

     for(i=0;i<N;i++){
       scanf("%lf",&A);
       B+=1/A;
     }

     printf("%lf\n",1/B);

     return 0;
 }


Measured memory_bytes: 128
#include <iostream>
#include <cassert>
#include <limits>
#include <cmath>
#include <algorithm>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <string>
#include <array>
#include <map>
#include <set>
#include <deque>
#include <list>
#include <sstream>
#include <iomanip>
#include <numeric>
#include <climits>
#include <cstring>
#include <bitset>
#include <stack>
#include <queue>

#define MOD (1e9 + 7);
#define PI (3.14159265358979323846)

using ll = int64_t;
using ull = uint64_t;

using namespace std;

[[maybe_unused]] static auto __x = [](){ios_base::sync_with_stdio(0); cin.tie(0);};

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

    ull res = 0;
    for (int i = 1; i <= n; ++i) {
        if (i % 3 == 0 || i % 5 == 0) {
            continue;
        }
        else {
            res += i;
        }
    }
    cout << res;

    return 0;
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); 
    char s[100000];
    cin>>s;
    for(int i=0;i<strlen(s);i++){
        if(i==0 || i%2==0)
         cout<<s[i];
    }
    return 0;
}
   

Measured memory_bytes: 3728
#include<bits/stdc++.h>
#define ll long long int
#define ld long double
#define pb push_back
#define mp make_pair
#define test long long int t; cin>>t; while(t-->0)
#define fIO ios_base::sync_with_stdio(false); cin.tie(NULL);
#define loop(i,n) for (ll i = 0; i < n; i++)
 
#define sz(x) int(x.size())
#define F first
#define S second
 
#define mii map<ll,ll>
#define vi vector<ll>
#define seti set<ll>
#define pii pair<ll,ll>
 
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) (a/gcd(a,b))*b

#define endl '\n'
using namespace std;
const int N=1e6;
    

int main()
    {
        fIO
        ll n;
        cin>>n;
        ll a[n];
        ll mul=1,zero=0;
        loop(i,n) 
        {
            cin>>a[i]; 
        }
        bool f=true;
        loop(i,n)
        {
            if(a[i]==0)
            zero++;
        }
        if(zero>0)
        {
            cout<<0;
            return 0;
        }
        for(int i=0;i<n;i++)
        {
            if(a[i]<=1000000000000000000/mul)
            mul*=a[i];
            else
            {
                cout<<"-1";
                return 0;
            }
        }
        cout<<mul;
        
        
        
        
    }

Measured memory_bytes: 4392
n=int(input())
s=[input() for _ in range(n)]
m=int(input())
t=[input() for _ in range(m)]
ans=0
for i in set(s):
  tmp_pnt = s.count(i) - t.count(i)
  if tmp_pnt>ans:
    ans=tmp_pnt 
print(ans)

Measured memory_bytes: 61996
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            StringBuilder sb = new StringBuilder();

            int n = int.Parse(Console.ReadLine());

            for (int i = 0; i < n; i++)
            {
                string x = Console.ReadLine();
                string y = Console.ReadLine();

                int xLen = x.Length;
                int yLen = y.Length;

                int[,] lcs = new int[xLen + 1, yLen + 1];

                for (int j = 0; j < xLen; j++)
                {
                    for (int k = 0; k < yLen; k++)
                    {
                        if (x[j] == y[k]) lcs[j + 1, k + 1] = lcs[j, k] + 1;
                        else lcs[j + 1, k + 1] = Math.Max(lcs[j, k + 1], lcs[j + 1, k]);
                    }
                }
                sb.AppendLine(lcs[xLen, yLen].ToString());
            }
            Console.Write(sb);
        }
    }
}

Measured memory_bytes: 18376
<?php
function d($s,$t){
	$l=0;$r=2*(int)floor($s/$t);
	while($r-$l>1)
	{
		$m=$r+$l>>1;
		if($m*$t>$s)$r=$m;
		else $l=$m;
	}
	return $l;
}
	fscanf(STDIN,"%d%d%d",$a,$b,$c);
	echo d($b,$c)-d($a-1,$c)+($a<1);

Measured memory_bytes: 3576
use std::io::*;

fn main() {
    let mut s: String = String::new();
    std::io::stdin().read_to_string(&mut s).ok();
    let mut itr = s.trim().split_whitespace();
    let x: i64 = itr.next().unwrap().parse().unwrap();

    let mut a: Vec<i64> = vec![0; 6666];
    for i in 1..6000 {
        a[i] = (i as i64).pow(5);
    }

    for i in 0..6000 {
        for j in 0..6000 {
            if a[i] + a[j] == x {
                println!("{} -{}", i, j);
                return;
            }
            if a[i] - a[j] == x {
                println!("{} {}", i, j);
                return;
            }
        }
    }
}


Measured memory_bytes: 2160
#include <bits/stdc++.h>
using namespace std;
#define int long long

signed main(){
    // cout << fixed << setprecision(10) << flush;

    int R, C, K;
    cin >> R >> C >> K;
    vector<vector<int>> dist(R+1, vector<int>(C+1, 0));
    for(int i=0; i<K; i++){
        int r, c, v;
        cin >> r >> c >> v;
        dist[r][c] = v;
    }
    
    // dp[i][j][k] は i で k 個アイテムを拾った時のmax
    vector<vector<vector<int>>> dp(R+1, vector<vector<int>>(C+1, vector<int>(4, 0)));
    // for(int i=0; i<=R; i++){
    //     for(int j=0; j<=C; j++){
    //         for(int k=0; k<4; k++){
    //             dp[i][j][k] = 0;
    //         }
    //     }
    // }

    // 範囲チェック
    for(int i=1; i<=R; i++){
        for(int j=1; j<=C; j++){
            for(int k=0; k<4; k++){
                dp[i][j][k] = max(dp[i][j][k], dp[i][j-1][k]);
                dp[i][j][0] = max(dp[i][j][0], dp[i-1][j][k]);
                dp[i][j][1] = max(dp[i][j][1], dp[i-1][j][k] + dist[i][j]);
                if(k != 0 && dist[i][j] != 0){
                    dp[i][j][k] = max(dp[i][j-1][k-1] + dist[i][j], dp[i][j][k]);
                }            
            }
        }
    }

    int ans = 0;
    for(int k=0; k<4; k++){
        ans = max(ans, dp[R][C][k]);
    }
    cout << ans << endl;

    return 0;
}

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

int main() {
    string S;
    cin >> S;
    string l = "abcdefghijklmnopqrstuvwxyz";
    bool flag2 = true;
    for (int i = 0; i < l.length(); i++){
        bool flag = true;
        for (int j = 0; j < S.length(); j++){
            if (S[j] == l[i]){
                flag = false;
                break;
            }
        }
        if (flag){
            cout << l[i] << endl;
            flag2 = false;
            break;
        }
    }
    if (flag2){
        cout << "None" << endl;
    }
}


Measured memory_bytes: 512
n=int(input())
a=list(map(int,input().split()))
cnt=0
ans=0
while True:
	for i in range(n):
		r=a[i]//n
		a[i]%=n
		a[i]-=r
		cnt+=r
	ans+=cnt
	if cnt==0:
		break
	for i in range(n):
		a[i]+=cnt
	cnt=0
print(ans)

Measured memory_bytes: 3064
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

public class Main
{

  public static void main
  (
    String[] args
  )
  {
    BufferedReader in_stream;
    String         in_str;
    String[]       in_str_split;

    int   N;
    int[] a;

    int                       cnt;
    int                       ans;
    HashMap<Integer, Integer> kind_num;
    int                       kind_len;
    int                       tmp;

    try
    {
      in_stream    = new BufferedReader(new InputStreamReader(System.in));
      in_str       = new String(in_stream.readLine());
      in_str_split = in_str.split(" ");

      N = Integer.parseInt(in_str_split[0]);

      in_str       = new String(in_stream.readLine());
      in_str_split = in_str.split(" ");

      a        = new int[N];
      kind_len = 0;
      for(cnt=0; cnt<N; cnt++)
      {
        a[cnt] = Integer.parseInt(in_str_split[cnt]);
        kind_len++;
      }

      kind_num = new HashMap<Integer, Integer>();
      for(cnt=0; cnt<N; cnt++)
      {
        kind_num.put(a[cnt], 0);
      }

      for(cnt=0; cnt<N; cnt++)
      {
        kind_num.put(a[cnt], kind_num.get(a[cnt])+1);
      }

      ans = 0;
      for(HashMap.Entry<Integer, Integer> entry : kind_num.entrySet())
      {
        cnt = entry.getKey();
        tmp = entry.getValue();
        if(cnt == tmp)
        {
          /* Nothing to do. */
        }
        else if(cnt < tmp)
        {
          ans += tmp - cnt;
        }
        else
        {
          ans += tmp;
        }
      }


      UtilLog.ans_ln("" + ans);
    }
    catch(Exception e)
    {
      e.printStackTrace();
    }
  }
}

class UtilLog
{
  private static boolean is_debug_mode = false;



  public static void ans_ln
  (
    String i_message
  )
  {
    System.out.println(i_message);
  }



  public static void ans_f
  (
    String i_message
  )
  {
    System.out.printf(i_message);
  }



  public static void inf_ln
  (
    String i_message
  )
  {
    StackTraceElement[] stack;


    if(is_debug_mode)
    {
    stack = new Throwable().getStackTrace();

    System.out.println
      (
        String.format
          (
            "[inf][%s:%s():%5d]",
            stack[1].getClassName(),
            stack[1].getMethodName(),
            stack[1].getLineNumber(),
            i_message
          )
      );
    }
  }
}


Measured memory_bytes: 46556
#include "bits/stdc++.h"
using namespace std;

signed main() { 
        int n, m, i, j;
        cin >> n >> m;
        bool ans[404][404];
        for (i = 0; i < n; i ++) for (j = 0; j < n; j ++) if (i != j) ans[i][j] = true;
        while (m --) {
                int x, y;
                cin >> x >> y;
                x --;
                y --;
                if (ans[x][y]) {
                        for (j = 0; j < n; j ++) {
                                if (x != j && !ans[x][j]) {
                                        ans[y][j] = false;
                                        ans[j][y] = false;
                                }
                        }
                        for (j = 0; j < n; j ++) {
                                if (y != j && !ans[y][j]) {
                                        ans[x][j] = false;
                                        ans[j][x] = false;
                                }
                        }
                } else {
                        for (j = 0; j < n; j ++) {
                                ans[x][j] = false;
                                ans[j][x] = false;
                                ans[y][j] = false;
                                ans[j][y] = false;
                        }
                }
                ans[x][y] = false;
                ans[y][x] = false;
        }
        int res = 0;
        for (i = 0; i < n; i ++) for (j = i + 1; j < n; j ++) if (ans[i][j]) res ++;
        cout << res << endl;
        return 0;
}               


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

int main(){
  int N, L;
  cin >> N >> L;
  
  vector<string> vec(N);
  for(int i=0; i<N; i++){
    cin >> vec.at(i);
  }
  sort(vec.begin(), vec.end());
  
  for(int i=0; i<N; i++){
    cout << vec.at(i);
  }
  cout << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
string d = "keyence";
int main()
{
    string s;cin >> s;
    int del = s.size() - 7;
    if(del == 0){
        if(s == d) puts("YES");
        else puts("NO");
        return 0;
    }
    for(int i = 0;i + del - 1 < s.size();i++){
        string a;
        for(int j = 0;j < i;j++) a+= s[j];
        for(int j = i + del;j < s.size();j++) a += s[j];
        if(a == d){puts("YES");return 0;}
    }
    puts("NO");
    return 0;
}


Measured memory_bytes: 256
#36 C - Skip
import bisect
import math
N,X = map(int,input().split())
x = list(map(int,input().split()))
x = sorted(x,reverse = False)

bisect.insort_left(x,X)
# 間隔の最小の素数
d_lis = []
for i in range(len(x)-1):
    d = x[i+1] - x[i]
    d_lis.append(d)
d_lis = sorted(d_lis,reverse = False)

ans = d_lis[0]
for j in range(1,len(d_lis)):
    ans = math.gcd(ans,d_lis[j])
print(ans)

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

typedef long long ll;

ll n,k;
ll a[200005];
ll f[200005];

bool check(ll bound){
    ll res=0;
    for(int i=1;i<=n;i++){
        res+=max(0ll,(a[i]*f[n+1-i]-bound+f[n+1-i]-1)/f[n+1-i]);
    }
    return res<=k;
}

int main(){

    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    cin>>n>>k;
    for(int i=1;i<=n;i++){
        cin>>a[i];
    }
    for(int i=1;i<=n;i++){
        cin>>f[i];
    }
    sort(a+1,a+1+n);
    sort(f+1,f+1+n);
    ll l=0,r=1e12,m,ans;
    while(l<=r){
        m=(l+r)>>1;
        if(check(m)){
            ans=m;
            r=m-1;
        }else{
            l=m+1;
        }
    }
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 3328
#include<iostream>
#include <string.h>
#include "stdio.h"

using namespace  std;
int main()
{
	string s;
	cin>>s;
	if(s.length()<6)
		cout<<"No";
	else if(s[2]==s[3]&&s[4]==s[5])
	{
		cout<<"Yes";
	}
	else
		cout<<"No";
	return 0;
}

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

namespace AtCoder
{
    public class Amemo
    {
        public long value;
        public long sum;
    }

    class Program
    {

        static void Main()
        {
            //ここから
            int[] STR = ReadLineToIntArray();
            int[] str = ReadLineToIntArray();
            int H = STR[0];
            int W = STR[1];
            int h = str[0];
            int w = str[1];

            int ans = (H - h) * (W - w);


            //ここまで

            Console.WriteLine(ans);
            Console.ReadKey();
        }


        static public void Swap<T>(ref T a,ref T b) { T temp = a;a = b;b = temp; }
        static public long GCD(int a, int b){ return b != 0 ? GCD(b, a % b) : a;}
        static public long LCM(int a, int b){ return (long)a * b / GCD(a, b); }



        
        static public string ReadLineToString(){return Console.ReadLine();}
        static public int ReadLineToInt(){return int.Parse(Console.ReadLine());}
        static public long ReadLineToLong() { return long.Parse(Console.ReadLine()); }
        static public string[] ReadLineToStringArray(){return Console.ReadLine().Split(' ').ToArray();}
        static public int[] ReadLineToIntArray(){return Console.ReadLine().Split(' ').Select(int.Parse).ToArray();}
        static public long[] ReadLineToLongArray() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); }
        static public List<string> ReadLineToStringList(){return Console.ReadLine().Split(' ').ToList();}
        static public List<int> ReadLineToIntList(){return Console.ReadLine().Split(' ').Select(int.Parse).ToList();}
        static public List<long> ReadLineToLongList() { return Console.ReadLine().Split(' ').Select(long.Parse).ToList(); }



    }
}


Measured memory_bytes: 11220
#include<bits/stdc++.h>
using namespace std;
#define LL long long
const int N=200005;
const LL MOD=1e9+7;

int n,cnt;
LL ans=1;
string s;
bool ok[N];

int main()
{
	ios_base::sync_with_stdio(0);
	
	cin>>n>>s;
	for(int i=0;i<2*n;i++)
		ok[i]=((s[i]=='B')?0:1)==(i&1);
	for(int i=0;i<2*n;i++)
		if(!ok[i]) ans=ans*cnt--%MOD;
		else cnt++;
	if(cnt) ans=0;
	for(int i=2;i<=n;i++)
		ans=ans*i%MOD;
	cout<<ans<<'\n';
	
	return 0;
}

Measured memory_bytes: 788
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define MOD 1000000007ULL;
#define rep(i,n) for(int i=0;i<n;i++)

int main() {
	int W,H,N;
  	cin>>W>>H>>N;
  	int minx=0; int maxx=W;
  	int miny=0; int maxy=H;
  
  	rep(i,N){
      	int x,y,a;
      	cin>>x>>y>>a;
      	if(a==1) minx=max(x,minx);
      	if(a==2) maxx=min(x,maxx);
      	if(a==3) miny=max(y,miny);
      	if(a==4) maxy=min(y,maxy);
      
    }	
  	
  	if(maxx<minx) maxx=minx;
  	if(maxy<miny) maxy=miny;
  	
  	cout<<(maxx-minx)*(maxy-miny)<<endl;
  	
}

Measured memory_bytes: 3596
#include<bits/stdc++.h>
#define ll long long
#define x first
#define y second
using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    string s; cin>>s;
    int n=s.length();
    int a=0;
    for(int i=0;i<n;i++)
        if(s[i]=='o')a++;
    a+=15-n;
    if(a>=8)cout<<"YES";
    else cout<<"NO";

      return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define Nmax 51
#define ll long long

using namespace std;

const long long INF=1e18l+2;
const ll MOD = 1e9+7;

ifstream f("1.in");

ll a[Nmax][Nmax];
ll r[Nmax][Nmax];
ll r_[Nmax][Nmax];

int main()
{
    ios::sync_with_stdio(0); cin.tie(0);
    ll n, k;
    cin >> n >> k;
    for (int i = 1; i <= n; i++)
    {
        r[i][i]=1;
        for (int j = 1; j <= n; j++)
            cin >> a[i][j];
    }

    while(k)
    {
        if(k&1)
        {
            for (int i = 1; i <= n; i++)
                for (int j = 1; j <= n; j++)
                {
                    r_[i][j]=0;
                    for (int k = 1; k <= n; k++)
                        (r_[i][j] += r[i][k]*a[k][j]) %= MOD;

                }
            for (int i = 1; i <= n; i++)
                for (int j = 1; j <= n; j++)
                     r[i][j] = r_[i][j];
        }

        for (int i = 1; i <= n; i++)
            for (int j = 1; j <= n; j++)
            {
                r_[i][j]=0;
                for (int k = 1; k <= n; k++)
                 (r_[i][j] += a[i][k]*a[k][j]) %= MOD;

            }
        for (int i = 1; i <= n; i++)
            for (int j = 1; j <= n; j++)
                a[i][j]=r_[i][j];

        k >>= 1;
    }

    ll s=0;
    for (int i = 1; i <= n; i++)
    {
        for (int j = 1; j <= n; j++)
            s=(s+r[i][j])%MOD;
    }
    cout << s;

    return 0;
}


Measured memory_bytes: 384
#include <stdio.h>
int main(void)
{
    int S;
    int h,m,s;
    scanf("%d",&S);
    h =(int)S/3600;
    m =(int)(S-3600*h)/60;
    s = S-3600*h-60*m;
    printf("%d:%d:%d\n",h,m,s);
    return 0;
}

Measured memory_bytes: 592
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;
const int MAXN = 2e5 + 5;

inline void chk_max(int &a,int b){ if(a<b) a=b;}

char s[MAXN];
int pre[MAXN],suf[MAXN];
ll dif[MAXN];
inline void update(int l,int r){ ++dif[l]; --dif[r+1];}

int main(void)
{
	int n,d,c;
	scanf("%d%d%d%s",&n,&d,&c,s+1);
	
	for(int i=1; i<=n; ++i)
	{
		pre[i] = pre[i-1];
		if(s[i]=='x') continue;
		chk_max(pre[i],1);
		if(i-c-1 >= 1) chk_max(pre[i], pre[i-c-1]+1);
	}
	for(int i=n; i>=1; --i)
	{
		suf[i] = suf[i+1];
		if(s[i]=='x') continue;
		chk_max(suf[i],1);
		if(i+c+1 <= n) chk_max(suf[i], suf[i+c+1]+1);
	}
	
	//for(int i=1; i<=n; ++i) printf("%d %d\n",pre[i],suf[i]);
	
	for(int i=1; i<=n; ++i)
		if(pre[i-1]+suf[i+1] < d)
			printf("%d\n",i);
	
//	for(int i=1; i<=n; ++i)
//	{
//		if(pre[i-1]>=d || suf[i+1]>=d)
//			update(i,i);
//	}
//	for(int i=1; i+c-1<=n; ++i)
//	{
//		int j = i+c-1;
//		if(pre[i-1] + suf[j+1] >= d)
//			update(i,j);
//	}
//	for(int i=1; i<=n; ++i) dif[i] += dif[i-1];
//	
//	for(int i=1; i<=n; ++i)
//		if(s[i]=='o' && !dif[i])
//			printf("%d\n",i);
	return 0;
}

Measured memory_bytes: 3200
#include <bits/stdc++.h>
#define ref1(i,s,e,c) for(int i=s;i<e;i=i+c)
#define ref2(i,s,e,c) for(int i=s;i<=e;i=i+c)
#define ref3(i,e,s,c) for(int i=e;i>=s;i=i-c)
using namespace std;
typedef long long ll;
int main()
{
	ll n,ans=0,mn;
	cin>>n;
	ref1(i,0,5,1){
		ll num;
		cin>>num;
		if(i==0) mn=num;
		else mn=min(mn,num);
	}
	cout<<5+(n-1)/mn<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
#define chmin(a, b) ((a)=min((a), (b)))
#define chmax(a, b) ((a)=max((a), (b)))
#define fs first
#define sc second
#define eb emplace_back
using namespace std;

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

const ll MOD=1e9+7;
const ll INF=1e18;
const double pi=acos(-1);
const double eps=1e-10;

int dx[]={1, 0, -1, 0};
int dy[]={0, -1, 0, 1};

int gcd(int x, int y){
    if(y == 0) return x;
    else return gcd(y, x % y);
}

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

    vector<int> l(n, a[0]), r(n, a[n-1]);
    for(int i=1; i<n; i++){
        l[i] = gcd(a[i], l[i-1]);
        r[n-1-i] = gcd(a[n-1-i], r[n-i]);
    }

    int ans=max(l[n-2], r[1]);
    for(int i=1; i<n-1; i++){
        int num = gcd(l[i-1], r[i+1]);
        chmax(ans, num);
    }

    cout << ans << endl;
}

Measured memory_bytes: 1408
import java.util.*;

public class Main{
    public static void main(String[] args) {
      Scanner sc = new Scanner(System.in);

      long n = Long.parseLong(sc.next());

      long root = (long)Math.sqrt(n)+1;
      long ans2 = 0;
      while(true){
        if(n%root==0){
          ans2 = n/root;
          break;
        }
        root--;
      }


      long ans = root + ans2 -2;
      System.out.println(ans);

    }
}


Measured memory_bytes: 23252
import java.util.*;

class Main {
	Scanner sc = new Scanner(System.in);

	public void run() {
		LinkedList<Integer> primes=new LinkedList<Integer>();
		
		for(int i=2;i<1000000;i++){
			boolean isprime=true;
			for(int prime:primes){
				if(i%prime==0){
					isprime=false;
					break;
				}
				if( prime*prime>i){
					break;
				}
			}
			if(isprime){
				primes.add(i);
			}
		}
		while(sc.hasNext()){
			int n=sc.nextInt();
			
			int c=0;
			for(int prime:primes){
				if(prime<=n){
					c++;
				}else{
					break;
				}
			}
			ln(c);
		}
	}

	public static void main(String[] args) {
		new Main().run();
	}

	public static void pr(Object o) {
		System.out.print(o);
	}

	public static void ln(Object o) {
		System.out.println(o);
	}

	public static void ln() {
		System.out.println();
	}
}

Measured memory_bytes: 15000
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <fstream>
using namespace std;
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v;}
template<class T> inline string toStr(T x) { ostringstream sout; sout << x; return sout.str();}
typedef vector<int> vi;
typedef vector<vi>  vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n) FOR(i,0,(n)-1)
const double EPS = 1e-12;
const double PI = acos(-1.0);
const int INF = INT_MAX;

typedef vector<ll> vl;
typedef vector<vl> vvl;

int main() {
	int N, M;
	while(cin >> N >> M, N) {
		vvl ldist(N, vl(N, INF));
		vvl sdist(N, vl(N, INF));
		ll x, y, t;
		char sl;
		REP(i, M) {
			cin >> x >> y >> t >> sl;
			x--;
			y--;
			if(sl == 'L') {
				ldist[x][y] = min(ldist[x][y], t);
				ldist[y][x] = min(ldist[y][x], t);
			} else {
				sdist[x][y] = min(sdist[x][y], t);
				sdist[y][x] = min(sdist[y][x], t);
			}
		}

		int R;
		cin >> R;
		vi z(R);
		int tmp;
		REP(i, R) {
			cin >> tmp;
			z[i] = tmp-1;
		}

		REP(i, N) {
			REP(j, N) {
				REP(k, N) {
					ldist[j][k] = min(ldist[j][k], ldist[j][i]+ldist[i][k]);
					sdist[j][k] = min(sdist[j][k], sdist[j][i]+sdist[i][k]);
				}
			}
		}

		REP(i, N) {
			ldist[i][i] = sdist[i][i] = 0;
		}

		vvl dp(R, vl(N, INF));
		dp[0][z[0]] = 0;
		REP(i, R-1) {
			int from = z[i], to = z[i+1];
			REP(before, N) {
				if(dp[i][before] == INF) {
					continue;
				}

				REP(after, N) {
					ll cost = INF;
					cost = min(cost, ldist[from][before] + sdist[before][after] + ldist[after][to]);
					if(before == after) {
						cost = min(cost, ldist[from][to]);
					}
					dp[i+1][after] = min(dp[i+1][after], dp[i][before]+cost);
				}
			}
		}

		ll ans = INF;
		REP(i, N) {
			ans = min(ans, dp[R-1][i]);
		}

		cout << ans << endl;
	}

	return 0;
}

Measured memory_bytes: 3452
#include<cstdio>
using namespace std;
int main(void)
{
	int a,b,c,i,j,k,x,cnt;
	scanf("%d %d %d %d",&a,&b,&c,&x);
	cnt=0;
	for(i=0;i<=a;i++)	{
		for(j=0;j<=b;j++)	{
			for(k=0;k<=c;k++)	{
				if(i*500+j*100+k*50==x)	cnt++;
			}
		}
	}
	printf("%d\n",cnt);
	return 0;
}

Measured memory_bytes: 128
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    import heapq
    from collections import defaultdict
    from copy import copy
    n, m = map(int, readline().split())

    used = dict()
    for i in range(n):
        used[i] = dict()

    edge = defaultdict(list)

    for i in range(m):
        a, b, c = map(int, readline().split())
        edge[a].append((b, c))
        edge[b].append((a, c))
        if a < b:
            used[a][b] = False
        else:
            used[b][a] = False

    for i in range(1,n+1):
        dist = [100000000000] * (n+1)
        dist[i] = 0
        prev = defaultdict(list)
        hq = []
        heapq.heappush(hq, (0, i))
        while hq:
            cur, u = heapq.heappop(hq)
            for v, w in edge[u]:
                if dist[v] > cur + w:
                    dist[v] = cur + w
                    prev[v] = [u]
                    heapq.heappush(hq, (cur + w, v))
                elif dist[v] == cur + w:
                    prev[v].append(u)
                    heapq.heappush(hq, (cur + w, v))

        for v, val in prev.items():
            for u in val:
                if u < v:
                    used[u][v] = True
                else:
                    used[v][u] = True

    ans = 0

    for val in used.values():
        for x in val.values():
            if not x:
                ans += 1

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 76536
A,B=map(int,input().split())
ans=0
b1=int(B/0.1)
b2=int((B+1)/0.1)
for i in range(b1,b2):
    a=int(i*0.08)
    if a==A:
        ans=i
        break
if ans==0:
    print(-1)
else:
    print(ans)

Measured memory_bytes: 3060
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int count = 0;
		while(true){
			int n = sc.nextInt();
			int x = sc.nextInt();

			if(n==0&&x==0){
				break;
			}

			for(int i = 1; i<=n; i++){
				for(int j = 1; j<=n; j++){
					for(int k = 0; k<=n; k++){
						if(i+j+k==x){
							if(i<j&&j<k){
								count++;
							}
						}
					}
				}
			}
			System.out.println(count);
			count = 0;
		}
	}
}


Measured memory_bytes: 26636
/*---> 04 April 2020 <--- > 20:43:25 <---*/
// #pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
// #pragma GCC optimize("unroll-loops")
// #pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
//#pragma GCC target ("sse4")
#include <bits/stdc++.h>
//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
using namespace std;
//template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;
#define int long long
#define F first
#define S second
#define mod 1000000007
#define inf (int)1e18+5
#define sz(x) (int)x.size()
#define PI 3.141592653589793238510
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define __ ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define vi vector<int>
#define vpii vector<pair<int,int> > 
#define vvi vector<vector<int> >
#define PRINT_TIME cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s." <<endl;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename   enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
typedef long double ld;
typedef pair<int,int> pii;
///////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////
const int N=1e5+5;

int32_t main(){__
	int ans=0;
	int n;
	cin>>n;
	vi a(n);
	vi cnt(n+1);
	for(int i=0;i<n;i++){
		cin>>a[i];
		cnt[a[i]]++;
	}
	for(int i=1;i<=n;i++){
		ans+=(cnt[i]*(cnt[i]-1))/2;
	}
	vi res(n);
	for(int i=0;i<n;i++){
		int t=i;
		i=a[i];
		ans-=(cnt[i]*(cnt[i]-1))/2;
		cnt[i]--;
		ans+=(cnt[i]*(cnt[i]-1))/2;
		res[t]=ans;
		ans-=(cnt[i]*(cnt[i]-1))/2;
		cnt[i]++;
		ans+=(cnt[i]*(cnt[i]-1))/2;
		i=t;
	}
	for(int i=0;i<n;i++)
		cout<<res[i]<<"\n";
	// cout<<"\n";
return 0;
}

Measured memory_bytes: 7296
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;

int main() {
	ll a,b,c;
	ll day = 1,coin=0;
	cin >> a >> b >> c;

	while (true) {
	
		if (day % 7 == 0)
			coin += a + b;
		else
			coin += a;

		if (c <= coin)
			break;

		day++;
	}

	cout << day << endl;
		
}



Measured memory_bytes: 3092
fun main(args: Array<String>) {
    val (h,w)= readLine()!!.split(" ").map { it.toInt() }
    val a = (1..h).map { readLine()!! }

    val sb = StringBuilder()
    sb.append("#".repeat(w+2)).append("\n")
    a.forEach { sb.append("#").append(it).append("#\n") }
    sb.append("#".repeat(w+2)).append("\n")

    println(sb)
}

Measured memory_bytes: 36072
#include <bits/stdc++.h>
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
using namespace std;

typedef long long ll;
typedef unsigned long long llu;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;
typedef pair<string, int> psi;
typedef pair<char, int> pci;
typedef pair<int, char> pic;
const ll MOD = (ll)1e9 + 7;
const long double PI = 3.141592653589793238462643383279502884197;

ll fac[1], inv[1];
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll mp(ll a,ll b){ll ret=1;while(b){if(b&1)ret=ret*a%MOD;a=a*a%MOD;b>>=1;}return ret;}
ll cmb(ll r, ll c) {return fac[r] * inv[c] % MOD * inv[r - c] % MOD;}

priority_queue<int, vector<int>, greater<int>> pq;
vector<int> v;

int n;
int vec[1 << 18];
pii dp[1 << 18][2];

int main() {
    memset(dp, -1, sizeof(dp));
    scanf("%d", &n);

    // 0인덱스고,
    // k에 대해 그렇다는 건..
    // 사실 이번에 추가되는 쌍만 누적시켜주면 되는건데..
    // or값이 k인 어떤 비트들 중 두 인덱스 값의 합이 가장 큰거.

    // 1. 모든 쌍 비교 가능?
    // 2. OR값이 정확히 K인 쌍들의 max를 빠르게 구하자.
    // 최상위 비트? 그 비트외에 다른 것이 안켜져 있는 subset들의 max?

    // 나보다 하나 더 켜져있는 것들로 보낸다.
    // 잘못하면 중복됨.
    // 차라리 상위비트의 max를 구하면?
    // 나도 그 하위비트들은 다 봤던거고..
    // 그렇게하면 distinct 해지나?
    // max 두개까지..
    // 그게 어떤 쌍이든 상관없다..
    // pair<>의 max를 저장해서 second까지 함.

    int mav = 0;
    for (int i = 0; i < (1<<n); i++) {
        scanf("%d", &vec[i]);

        pii now = {vec[i], i};
        if (dp[i][1] < now) {
            swap(dp[i][1], now);
            if (dp[i][0] < dp[i][1])
                swap(dp[i][0], dp[i][1]);
        }

        for (int j = 0; j < n; j++) {
            int bit = i | 1 << j;
            if (i == bit) continue;

            now = dp[i][0];
            if (dp[bit][1].second == now.second || dp[bit][0].second == now.second);
            else {
                if (dp[bit][1] < now) {
                    swap(dp[bit][1], now);
                    if (dp[bit][0] < dp[bit][1])
                        swap(dp[bit][0], dp[bit][1]);
                }
            }

            now = dp[i][1];
            if (dp[bit][1].second == now.second || dp[bit][0].second == now.second);
            else {
                if (dp[bit][1] < now) {
                    swap(dp[bit][1], now);
                    if (dp[bit][0] < dp[bit][1])
                        swap(dp[bit][0], dp[bit][1]);
                }
            }
        }

        mav = max(mav, dp[i][0].first + dp[i][1].first);
        if (i) printf("%d\n", mav);
    }
}

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

int main() {
  string s;
  cin >> s;
  ll n = s.size();
  ll p = 2019;
  if (10%p == 0) { // 2,5
    ll ans = 0;
    rep(r,n) {
      if ((s[r]-'0') % p == 0) {
        ans += r+1;
      }
    }
    cout << ans << endl;
    return 0;
  }

  vector<int> d(n+1);
  int ten = 1;
  for (int i = n-1; i >= 0; --i) {
    int a = (s[i]-'0') * ten % p;
    d[i] = (d[i+1]+a) % p;
    ten *= 10; ten %= p;
  }
  vector<int> cnt(p);
  ll ans = 0;
  for (int i = n; i >= 0; --i) {
    ans += cnt[d[i]];
    cnt[d[i]]++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 4388