akhauriyash/Code-Regression huggingface dataset:
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath>
#include <math.h> // sqrt()
#include <iomanip>
#define rep(i , n) for (int i = 1; i <= (int)(n); i++)
#define repz(i , n) for (int i = 0; i < (int) n; i++)
#define repi(i , r, n) for (int i = r; i <= (int)(n); i++)
#define repd(i , r, n) for (int i = r; i >= (int)(n); i--)
 
 
using namespace std;
 
 
int main(){
    int n, m , a, b;
    cin >> n >> m;
    int amount[n+1];
    rep( i , n) amount[i] = 1;
    bool red[n+1];
    red[1] = true;
    rep(i , m){
        cin >> a >> b;
        amount[a]--;
        amount[b]++;
        if ( red[a]) red[b] = true;
        if ( amount[a] == 0) red[a] = false;
        
        
    }
    int ans = 0;
    rep( i , n){
        if ( red[i] ) ans++;
    }
    
    cout << ans << endl;
    
    
}

Measured memory_bytes: 4068
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<math.h>
using namespace std;
#define N (1000000000+7)
#define INF 1e16
typedef long long ll;
typedef pair<ll,ll> P;

int main(void){
    int m1,m2,d1,d2;
    cin>>m1>>d1;
    cin>>m2>>d2;
    if(m1==m2)cout<<0<<endl;
    else cout<<1<<endl;
    return 0;
}


Measured memory_bytes: 256
def main():
    s = list(input())
    n = len(s)

    ans = 0
    l, r = 0, n-1
    while l < r:
        if s[l] == "x" or s[r] == "x":
            if s[l] == "x" and s[r] == "x":
                l += 1
                r -= 1
            elif s[l] == "x":
                l += 1
                ans += 1
            elif s[r] == "x":
                r -= 1
                ans += 1
        elif s[l] == s[r]:
            l += 1
            r -= 1
        else:
            print(-1)
            exit()
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 49392
#include<stdio.h>
#include<math.h>
 
int main(){
 
 double x1,x2,y1,y2,dst;
scanf("%lf%lf%lf%lf",&x1,&y1,&x2,&y2);
dst=sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
 
printf("%.08lf\n",dst);
return 0;
}


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

/*                    ॐ Shree ॐ                     */
/* ॐ ॐ ॐ
ॐ भूर् भुवः स्वः
तत् सवितुर्वरेण्यं
भर्गो देवस्य धीमहि
धियो यो नः प्रचोदयात्
*/
using namespace std;
typedef long long int ll;
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#else
// online submission
#endif
	ll a;
	cin>>a;
	string b;
	cin>>b;
	int m=(b[0]-'0')*100+(b[2]-'0')*10+(b[3]-'0');
	cout<<(a*m)/100;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
using namespace std;
#define int long long
#define pb push_back
#define pi pair <int, int>
#define f first 
#define s second

int n, a[100100], b, c;
map <int, int> mp;
vector <pi> v;
vector <int> ans;
int32_t main() {
	bool can = false, yes = false, chosen = false;
	cin >> n;
	for(int i = 0; i < n; ++i) {
		cin >> a[i];
		mp[a[i]]++;
	}
	for(auto it:mp) {
		if (it.second >= 4) can = true;
		else {
			if (it.second >= 2) {
				if (yes) {
					can = true;
				}
				else yes = true;
			}
		}
	}
	if (!can) {
		cout << 0;
	}
	else {
		for(auto it:mp) {
			v.pb(it);
		}
		sort(v.begin(), v.end(), [] (pi i, pi j) {
			return i.first > j.first;
		});
		for(auto it:v) {
			cerr << it.first <<' '<< it.second << '\n';
		}
		for(auto it:v) {
			if (it.s >= 4) {
				ans.pb(it.f*it.f);
			}
			if (it.s >= 2 && !chosen) {
				b = it.f;
				chosen = true;
			}
			if (it.s >= 2 && chosen) {
				c = it.f;
				if (c != b) {
					ans.pb(b*c);
					chosen = false;
				}
			}
		}
		cout << *max_element(ans.begin(), ans.end());
	}
}

Measured memory_bytes: 12288
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<cstring>
#include<cmath>
#include<ctime>
#include<algorithm>
#include<utility>
#include<stack>
#include<queue>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#define EPS 1e-9
#define PI acos(-1.0)
#define INF 0x3f3f3f3f
#define LL long long
const int MOD = 1E9+7;
const int N = 1000+5;
const int dx[] = {-1,1,0,0,-1,-1,1,1};
const int dy[] = {0,0,-1,1,-1,1,-1,1};
using namespace std;
char str[N][N];
int bucket[N][27];
int vis[27];
int main(){
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        scanf("%s",str[i]+1);
        int len=strlen(str[i]+1);
        for(int j=1;j<=len;j++){
            int temp=str[i][j]-'a'+1;
            bucket[i][temp]++;
        }
    }

    for(int i=1;i<=26;i++)
        vis[i]=bucket[1][i];
    for(int i=1;i<=n;i++){
        for(int j=1;j<=26;j++){
            vis[j]=min(vis[j],bucket[i][j]);
        }
    }
    
    for(int i=1;i<=26;i++){
        while(vis[i]--){
            char temp=(char)(i+'a'-1);
            printf("%c",temp);
        }
    }
    
    return 0;
}


Measured memory_bytes: 256
import java.util.List;
import java.util.Scanner;

public class Main {

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

	void run() {
		Scanner sc = new Scanner(System.in);

		String S=sc.next();
		String T=sc.next();

		for (int i = 0; i < S.length(); i++) {

			if(S.equals(T)) {
				System.out.println("Yes");
				return;
			}

			S=S.substring(S.length()-1, S.length())+S.substring(0,S.length()-1);

		}

		System.out.println("No");
	}

	//以下テンプレート

	public static int[] extgcd(int a, int b) {

		int x0 = 1;
		int x1 = 0;

		int y0 = 0;
		int y1 = 1;

		while (b != 0) {
			int q = a / b;
			int r = a % b;

			int x2 = x0 - q * x1;
			int y2 = y0 - q * y1;

			a = b;
			b = r;

			x0 = x1;
			x1 = x2;

			y0 = y1;
			y1 = y2;
		}

		return new int[] { a, x0, y0 };

	}

	static int gcd(int a, int b) {

		if (b == 0)
			return a;

		if (a < b) {
			int t = a;
			a = b;
			b = t;
		}

		return gcd(b, a % b);

	}

	static int lcm(int a, int b) {
		return a * b / gcd(a, b);
	}

	static void swap(int[] a) {
		int t;

		t = a[0];
		a[0] = a[1];
		a[1] = t;

		return;
	}

	static <T> void output(List<T> list) {

		for (int i = 0; i < list.size(); i++) {
			System.out.print(list.get(i));

			if (i != list.size() - 1) {
				System.out.print(" ");
			} else {
				nl();
			}
		}

	}

	static void output(String[][] str) {

		for (int i = 0; i < str.length; i++) {
			for (int j = 0; j < str[i].length; j++) {
				print(str[i][j]);
			}

			nl();
		}

	}

	static void output(boolean flg, String Yes, String No) {

		if (flg) {
			pln(Yes);
		} else {
			pln(No);
		}

	}

	static void output(String[][] str, int digit) {

		String dig = "%" + String.valueOf(digit) + "s";

		for (int i = 0; i < str.length; i++) {
			for (int j = 0; j < str[i].length; j++) {
				System.out.printf(dig, str[i][j]);
			}
			nl();
		}

	}

	static void pln(String str) {
		System.out.println(str);
	}

	static void pln(int x) {
		System.out.println(x);
	}

	static void print(String str) {
		System.out.print(str);
	}

	static void print(int x) {
		System.out.print(x);
	}

	static void print(String str, int times) {
		for (int i = 0; i < times; i++) {
			print(str);
		}
	}

	static void print(int x, int times) {
		for (int i = 0; i < times; i++) {
			print(x);
		}
	}

	static void nl() {
		System.out.println();
	}

}


Measured memory_bytes: 23508
// #include<bits/stdc++.h>
// using namespace std;
 
// const int N = 100, MAXI = N, D = 10;
 
// int main() {
//     freopen("output.txt", "r", stdin);
//     freopen("input.txt", "w", stdout);
//     srand(time(nullptr));
//     int tc = 100, flag = 1;
//     cout << tc << "\n";
//     while (tc--)
//     {
    	
//     	int n = rand()%D + 1, m = rand()%D + 1;

//     	n = m = 100;

//     	cout << n << " " << m << "\n";

//     	for(int i=1;i<=n;i++)
//     	{
//     		for(int j=1;j<=m;j++)
//     		{
//     			cout << (char)(rand()%2 + '0');
//     		}
//     		cout << "\n";
//     	}

//      	cout << "~\n";
//     }
 
//     return 0;
// }
 
 
 
 
 
 
 
 
//---------------------------------------------//
 
 
 
/*
#define int long long 
#define mod (int)(1e9+9)
#define endl '\n'
#define MAXI (int)(3e17+10)
#define N 200005
 */ 
 
 
 
 
 
 
//  /* while(!cin.eof()) */
 
#include<bits/stdc++.h>
using namespace std; 
#define int long long
#define mod (int)(1e9+9)
#define endl '\n'
#define MAXI (int)(3e17+10)
#define N 100105





// // Driver code to test above functions
int32_t main()
{
    
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);

   	
   	int dp[N];
   	for(int i=1;i<N;i++)
   		dp[i] = MAXI;

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

   	dp[1] = 0;
   	for(int i=1;i<=n;i++)
   	{
   		for(int j=1;j<=k;j++)
   		{
   			dp[i+j] = min(dp[i+j], dp[i] + abs(a[i]-a[i+j]));
   		}
   	}

   	cout << dp[n];
   	
   	
    
    return 0;
 
} 


Measured memory_bytes: 1792
#![allow(unused_macros)]
#![allow(unused_mut)]
#![allow(non_snake_case)]
#![allow(unused_variables)]
#![allow(unused_imports)]
//
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
//
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

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

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

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

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

macro_rules! max {
    ($x: expr) => ($x);
    ($x: expr, $($y: expr),+) => (::std::cmp::max($x, max!( $($y),+)));
}

macro_rules! min {
    ($x: expr) => ($x);
    ($x: expr, $($y: expr),+) => (::std::cmp::min($x, min!( $($y),+)));
}

// solution 
use std::cmp;
use std::collections::{HashMap, HashSet, BTreeMap, BTreeSet};
fn main() {
    input! {
        N: usize,
        K: usize,
        sosa: [(usize, usize); N],
    }

    let mut count = BTreeMap::new();

    for &(a, b) in sosa.iter() {
        *count.entry(a).or_insert(0) += b;
    }

    let mut sum = 0;
    for (key, value) in count {
        sum += value;
        if sum >= K {
            println!("{}", key);
            return
        }
    }
}


Measured memory_bytes: 6396
import sys

input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]

tin=lambda : map(int, input().split())
lin=lambda : list(tin())
mod=1000000007

#+++++

def main():
	#a = int(input())
	x, y = tin()
	#s = input()
	for i in range(x+1):
		t=i
		k=x-i
		ashi=t*2 + k*4
		if ashi == y:
			return 'Yes'
	return 'No'
	
	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

Measured memory_bytes: 62052
def digitSum(n):
    # 数値を文字列に変換
    s = str(n)
    # １文字ずつ数値化し配列にする。
    array = list(map(int, s))
    # 合計値を返す
    return sum(array)

n = int(input()) # list()でリスト化、それを変数に代入。
if n == 0:
    print('Yes')
    exit()
while(True):
    n = digitSum(n)
    if len(str(n))==1:
        if n == 9:
            print('Yes')
        else:
            print('No')
        exit()


Measured memory_bytes: 11092
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <string>
#include <numeric>
#include <cmath>

#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef vector<int> vec;
typedef vector<vector<int>> mat;
using P = pair<ll, ll>;

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

const ll MOD = 1000000007;
const int INF = 1<<29;

int main(){
  int N, M; cin >> N >> M;
  if (N == M) cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void){
	double a,b,c,d,e,f;

	while(scanf("%lf%lf%lf%lf%lf%lf",&a,&b,&c,&d,&e,&f)!=EOF)
		printf("%.3lf %.3lf\n",(e*c-b*f)/(a*e-b*d)+0,(-d*c+a*f)/(a*e-b*d)+0);

	return 0;
}

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

int main() {
	int n,A[100];
	double ans = 0;
	cin >> n;
	for(int i=0;i<n;i++)
		cin >> A[i];
	sort(A, A+n);
	ans = (A[0] + A[1]) * 0.5;
	for(int i=2;i<n;i++){
		ans = (ans + A[i]) * 0.5;
	}
	cout << ans << '\n';
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <queue>
#include <climits>
using namespace std;
#define INF INT_MAX
int G[30][30];
int c[4];
//
const int dirx[] = {-1, 0, 1, 0};
const int diry[] = { 0,-1, 0, 1};

class State{
  public:
    int x;
    int y;
    int dir;
    int cost;
    State(int x, int y, int dir, int cost){
      this->x=x;this->y=y;this->dir=dir;this->cost=cost;
    }
    bool operator < (const State &s)const{
      return cost > s.cost;
    }
};

int main(void){
  int w, h;
  while(cin >> w >> h, w | h){
    for(int i=0; i < h; i++){
      for(int j=0; j < w; j++){
        cin >> G[i][j];
      }
    }
    for(int i=0; i < 4; i++){
      cin >> c[i];
    }

    int d[30][30][4];
    vector<vector <bool> > used(30, vector<bool>(30, false));
    fill(d[0][0], d[0][0] + 30*30*4, INF);
    d[0][0][2] = 0;
    priority_queue<State> pq;
    pq.push(State(0, 0, 2, 0));
    while(!pq.empty()){
      State s = pq.top(); pq.pop();
      used[s.y][s.x] = true;
      for(int i=0; i < 4; i++){
        int ndir = (s.dir+i) % 4;
        int nx = s.x + dirx[ndir]; int ny = s.y + diry[ndir];
        if(!(nx >= 0 && nx < w && ny >= 0 && ny < h)) continue;
        if(G[s.y][s.x] == i){
          if(d[s.y][s.x][s.dir] < d[ny][nx][ndir]){
            d[ny][nx][ndir] = d[s.y][s.x][s.dir];
            pq.push(State(nx, ny, ndir, d[ny][nx][ndir]));
          }
        }else{
          if(d[s.y][s.x][s.dir] + c[i] < d[ny][nx][ndir]){
            d[ny][nx][ndir] = d[s.y][s.x][s.dir] + c[i];
            pq.push(State(nx, ny, ndir, d[ny][nx][ndir]));
          }
        }
      }
    }
    cout << min(d[h-1][w-1][0], min(d[h-1][w-1][1], min(d[h-1][w-1][2], d[h-1][w-1][3]))) << endl;
  }
  return 0;
}

Measured memory_bytes: 1328
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef set<int> si;
typedef set<ll> sl;
typedef pair<int,int> pii;
#define rep(i,a,b) for(int i=(a); i<(b); ++i)
#define per(i,a,b) for(int i=(b)-1; i>=(a); --i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define F first
#define S second

const int MOD = 1000000007;

int main(void) {
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	//freopen("in.txt", "r", stdin);
	
	int n;
	vi cnt;
	vi a;

	cin >> n;
	cnt.resize(n);
	a.resize(n);
	rep(i,0,n) {
		cin >> a[i];
	}

	if(a[0] != 0) {
		cout << 0 << endl;
		return 0;
	}
	
	ll ret = 3;
	cnt[0] = 1;
	rep(i,1,n) {
		int x = a[i];
		if(cnt[x] == 3) {
			ret = 0;
			break;
		}
		if(x != 0 && cnt[x-1] <= cnt[x]) {
			ret = 0;
			break;
		}

		if(x == 0) {
			ret *= (3 - cnt[x]);
			cnt[x]++;
		} else {
			ret *= (cnt[x-1] - cnt[x]);
			cnt[x]++;
		}
		ret %= MOD;

	}
	cout << ret << endl;
	return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;

const double g = 9.8;
const double EPS = 1.0e-6;
double K;
double v;

void kouhoth(int x, int y, vector<double> &TH)
{
	double K = 1.0*v*v/g;
	double d = K*K*x*x - x*x*(x*x+2*K*y);
	if(d<0) return;
	double kai1 = (K*x + sqrt(d)) / x / x;
	double kai2 = (K*x - sqrt(d)) / x / x;
	if(kai1+EPS>0) TH.push_back(atan(kai1+EPS));
	if(kai1-EPS>0) TH.push_back(atan(kai1-EPS));
	if(kai2+EPS>0) TH.push_back(atan(kai2+EPS));
	if(kai2-EPS>0) TH.push_back(atan(kai2-EPS));
}

double f(double th, int x)
{
	double K = 1.0*v*v/g;
	double si = sin(th);
	double co = cos(th);
	double ta = tan(th);
	double alpha = -0.5*(1.0+ta*ta)/K;
	double beta = 0.5*K*si*si;
	double naka = 1.0*x - K*si*co;
	return alpha * naka*naka + beta;
}

int main(){
	int n;
	int x, y;
	pair<double, double> buf;
	while(cin>>n>>v>>x>>y){
		vector<int> L, B, R, T;
		vector<double> TH;
		K = 1.0*v*v/g;
		for(int i=0; i<n; i++){
			int l, b, r, t;
			cin>>l>>b>>r>>t;
			if(x<l) continue;
			if(x<r) r = x;
			L.push_back(l);
			B.push_back(b);
			R.push_back(r);
			T.push_back(t);
			kouhoth(l,b,TH);
			kouhoth(r,b,TH);
			kouhoth(l,t,TH);
			kouhoth(r,t,TH);
		}
		kouhoth(x,y,TH);

		bool okflg = false;
		for(int i=0; i<TH.size(); i++){
			double th = TH[i];
			double mauey = f(th,x);
			if(mauey < y) continue;
			bool dameflg = false;
			for(int j=0; j<L.size(); j++){
				if(
					(f(th,L[j])<B[j]&&f(th,R[j])<B[j]) ||
					(f(th,L[j])>T[j]&&f(th,R[j])>T[j]) ){
						continue;
				} else {
					dameflg = true;
					break;
				}
			}

			if(!dameflg){
				bool butukaruflg = false;
				for(int j=0; j<L.size(); j++){
					if(R[j]==x){
						if(y<T[j] && T[j]<mauey){
							butukaruflg = true;
							break;
						}
					}
				}
				if(!butukaruflg){
					okflg = true;
					break;
				}
			}
		}
		if(okflg) cout<<"Yes"<<endl;
		else cout<<"No"<<endl;
	}
}

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

using ll = int64_t;
#define int ll

#define FOR(i, a, b) for (int i = int(a); i < int(b); i++)
#define REP(i, b) FOR(i, 0, b)
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define ALL(x) x.begin(), x.end()

using pi = pair<int, int>;
using vi = vector<int>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  REP(i, (int)v.size()) {
    if (i)
      os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}

ll read() {
  ll i;
  scanf("%" SCNd64, &i);
  return i;
}

void printSpace() { printf(" "); }

void printEoln() { printf("\n"); }

void print(ll x, int suc = 1) {
  printf("%" PRId64, x);
  if (suc == 1)
    printEoln();
  if (suc == 2)
    printSpace();
}

string readString() {
  static char buf[3341000];
  scanf("%s", buf);
  return string(buf);
}

char *readCharArray() {
  static char buf[3341000];
  static int bufUsed = 0;
  char *ret = buf + bufUsed;
  scanf("%s", ret);
  bufUsed += strlen(ret) + 1;
  return ret;
}

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

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

template <class T> T Sq(const T &t) { return t * t; }

const int mod = 1e9 + 7;

signed main() {
  int n, m;
  std::cin >> n >> m;
  vi cnt(n + 1);
  REP(i, m) {
    int a, b;
    std::cin >> a >> b;
    cnt[a]++;
    cnt[b]++;
  }
  FOR(i, 1, n + 1) { print(cnt[i]); }
}


Measured memory_bytes: 256
from sys import stdin
import sys
from math import isinf
INF = float("inf")
sys.setrecursionlimit(100000)
def dfs(v, tm):
    dts[v] = est[v] = tm + 1
    child = 0
    for i in adj[v]:
        if isinf(est[i]):
            child += 1
            parents[i] = v
            dfs(i, tm + 1)
            est[v] = min(est[v], est[i])
            if parents[v] is None and child > 1: aps[v] = True
            if parents[v] is not None and est[i] >= dts[v]: aps[v] = True
        elif parents[v] != i:
            est[v] = min(est[v], dts[i])
n, m = map(int, stdin.readline().split())
adj = [[] for _ in range(n)]
est = [float('inf')] * n
parents = [None] * n
aps = [False] * n
dts = [0] * n
for _ in range(m):
    s, t = map(int, stdin.readline().split())
    adj[s].append(t)
    adj[t].append(s)
dfs(0, 0)
for i in range(n):
    if aps[i]:
        print(i)

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

using namespace std;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	int n;
	cin >> n;
	vector<vector<pair<int,int>>> a(n);
	for(int i=0;i<n;i++){
		int m;
		cin >> m;
		for(int j=0;j<m;j++){
			int x,y;
			cin >> x >> y;
			x--;
			a[i].push_back(make_pair(x,y));
		}
	}
	
	int res=0;
	for(int i=0;i<(1<<n);i++){
		bool bo=true;
		for(int j=0;j<n;j++){
			if(!((i>>j)&1)) continue;
			for(int k=0;k<a[j].size();k++){
				pair<int,int> p0=a[j][k];
				if(((i>>p0.first)&1)!=p0.second) bo=false;
			}
		}
		if(bo){
			//cout << i << "\n";
			res=max(res,__builtin_popcount(i));
		}
	}
	cout << res << "\n";
	return 0;
}

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

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

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

namespace AOJ {
	class Program {
		static void Main(string[] args) {
			var line = Utils.GetLineInts();
			int A = line[0], B = line[1];

			while (A != 0 && B != 0) {
				new Calc().Solve(A,B);
				var next = Utils.GetLineInts();
				A = next[0];
				B = next[1];
			}


		}

		public class Calc {
			
			public void Solve(int A,int B) {
				var coin = new int[3] { 100, 500, 1000 };
				var cnt = new int[3] { 0, 0, 0 };
				int target = B - A;
				for (int i = 2; i >=0&&target!=0; i--) {
					var div = target / coin[i];
					cnt[i] = div;
					target -= coin[i] * div;
				}
				(cnt[0] + " " + cnt[1] + " " + cnt[2]).WL();
				return;
			}
		}
	}

	public static class Utils {
		public static int GetInt() {
			return int.Parse(Console.ReadLine());
		}
		public static long GetLong() {
			return long.Parse(Console.ReadLine());
		}
		public static void WL(this object obj) { Console.WriteLine(obj); }
		public static void WL(this string obj) {
			Console.WriteLine(obj);
		}
		public static void WL<T>(this IEnumerable<T> ie) {
			foreach (var item in ie) {
				item.WL();
			}
		}
		public static List<int> GetLineInts() {
			return Console.ReadLine().Split().Select(int.Parse).ToList();
		}
	}
}

Measured memory_bytes: 9700
#include<bits/stdc++.h>
#define LiangJiaJun main
#define ll long long
#define INF 1999122700
using namespace std;
int n,W,a[104],b[104];
ll f[100004];
int w33ha(){
    for(int i=0;i<=100000;i++)f[i]=INF;
    for(int i=1;i<=n;i++)scanf("%d%d",&a[i],&b[i]);
    f[0]=0;
    for(int i=1;i<=n;i++){
        for(int j=100000;j>=b[i];j--){
            f[j]=min(f[j],f[j-b[i]]+a[i]);
        }
    }
    for(int j=100000;j>=0;j--){
        if(f[j]<=W)return printf("%d\n",j),0;
    }
    return 0;
}
int LiangJiaJun(){
    while(scanf("%d%d",&n,&W)!=EOF)w33ha();
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include <typeinfo>
#include <cxxabi.h>
#ifdef LOCAL
  #include "dbgtoki.hpp"
  #define DUMP(i) dump((string)TOSTRING(i), demangle(typeid(i).name()), __LINE__ , i) 
DbgTimer D_t;
  #define TSTART() D_t.start()
  #define TSTOP() D_t.stop()
#else
  #define DUMP(i) 
  #define TSTART()
  #define TSTOP()  
#endif
 
#define TOSTRING(x) #x
#define SZ(x) (int)(x).size()
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(s) (s).begin(), (s).end()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()) , v.end());

using namespace std;
typedef long long unsigned int llu;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;

struct Edge{
public:
  int from,to,cost;
  Edge(){}
  Edge(int _from,int _to,int _cost){
    from = _from;
    to = _to;
    cost = _cost;
  }
};

typedef vector<Edge> Edges;
typedef vector<Edges> Graph;


const int EPS = 1e-9;
const int MOD = 1e9+7;



int main (){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n,m;
  while(cin >> n >> m){
    TSTART();
    bool A[n][n];
    bool B[m][m];
    string s;
    REP(i,n){
      cin >> s;
      REP(j,n){
    	A[i][j] = (s[j] == '#');
      }
    }
    REP(i,m){
      cin >> s;
      REP(j,m){
	B[i][j] = (s[j] == '#');
      }
    }

    bool ans = false;
    bool b = true;
    REP(i,n-m+1){
      REP(j,n-m+1){
	int x = i;
	int y = j;
	REP(ii,m){
	  REP(ij,m){
	    if(A[x][y] != B[ii][ij]){
	      b = false;
	    }
	    y++;
	  }
	  x++;
	}
	if(b){
	  ans = true;
	  break;
	}
	b = true;
      }
    }
    if(ans)cout << "Yes" << endl;
    else cout << "No" << endl;
    TSTOP();
  }
  return 0;
}



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

#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define EPS (1e-7)
#define equals(a,b) (fabs((a)-(b)) < EPS)

using namespace std;

const int IINF = INT_MAX;

// Library - template - begin

class Point{
public:
  double x,y;
  Point(double x = -IINF,double y = -IINF): x(x),y(y){}
  Point operator + (Point p){return Point(x+p.x,y+p.y);}
  Point operator - (Point p){return Point(x-p.x,y-p.y);}
  Point operator * (double a){return Point(a*x,a*y);}
  Point operator / (double a){return Point(x/a,y/a);}
  bool operator < (const Point& p) const{ return !equals(x,p.x)?x<p.x:y<p.y; }
};

struct Segment{
  Point p1,p2;
  Segment(Point p1 = Point(),Point p2 = Point()):p1(p1),p2(p2){}
};

typedef Point Vector;
typedef Segment Line;

double cross(Point a,Point b){ return a.x*b.y - a.y*b.x; }
double norm(Point a){ return a.x*a.x+a.y*a.y; }
double abs(Point a){ return sqrt(norm(a)); }

// Library - template - end

// Library - intersect - begin
Point crosspoint(Line l, Line m) {
  double A = cross(l.p2 - l.p1, m.p2 - m.p1);
  double B = cross(l.p2 - l.p1, l.p2 - m.p1);
  if (abs(A) < EPS && abs(B) < EPS) return m.p1; // same line
  if (abs(A) < EPS) assert(false); // !!!PRECONDITION NOT SATISFIED!!!
  return m.p1 +   (m.p2 - m.p1) * (B / A);
}
// Library - intersect - end

int V;
double vw,vc;
Point ps[1010];
bool here[1010]; // here is the point
double mincost[1010];

inline bool LT(double a,double b) { return !equals(a,b) && a < b; }

int main(){

  while( cin >> V, V ){
    cin >> vw >> vc;
    rep(i,V) cin >> ps[i].x >> ps[i].y;

    rep(i,V) mincost[i] = IINF;
    mincost[0] = 0;
    REP(i,1,V) mincost[i] = mincost[i-1] + abs(ps[i]-ps[i-1]) / vw;

    rep(i,V-2){
      if( !( LT(ps[i].y,ps[i+1].y) ) ) continue;
      double lower = ps[i+1].y;
      REP(k,i+2,V){
        if( !( ps[k-1].y > ps[k].y ) ) {
          lower = min(lower,ps[k].y);
          continue;
        }
        if( ps[k].y < lower ){
          double Y = max(ps[i].y,ps[k].y);
          Line line = Line(Point(-10100,Y),Point(10100,Y));
          Point sp = ps[i], gp = ps[k];
          Point np = crosspoint(line,Line(ps[i  ],ps[i+1]));
          Point mp = crosspoint(line,Line(ps[k-1],ps[k]));
          double dist1 = abs(np-sp);
          double dist3 = abs(np-mp);
          double dist4 = abs(gp-mp);
          double time1 = dist1 / vw + dist3 / vc + dist4 / vw;
          if( LT(mincost[i]+time1,mincost[k]) ){
            mincost[k] = mincost[i]+time1;
            REP(j,k,V) mincost[j] = min(mincost[j],mincost[j-1] + abs(ps[j]-ps[j-1])/vw);
          }
        }
        lower = min(lower,ps[k].y);
        if( lower < ps[i].y ) break; //これ忘れてた
      }
    }
    printf("%.8f\n",mincost[V-1]);
  }
  return 0;
}

Measured memory_bytes: 1272
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int a = scanner.nextInt();
		int b = scanner.nextInt();
		int c = scanner.nextInt();
		int x = scanner.nextInt();
		int y = scanner.nextInt();

		if (a+b<=2*c) {
			System.out.println((a*x)+(b*y));
		}else if (a>2*c) {
			if (b>2*c) {
				System.out.println(2*c*Math.max(x, y));
			}else {
				System.out.println((2*c*x)+(b*Math.max(0, y-x)));
			}
		}else if (b>2*c) {
			System.out.println((2*c*y)+(a*Math.max(0, x-y)));
		}else {
			if (x<=y) {
				System.out.println((2*c*x)+(b*(y-x)));
			}else {
				System.out.println((2*c*y)+(a*(x-y)));
			}
		}
	}

}

Measured memory_bytes: 21332
n, k = map(int, input().split())
s=list(map(int, list(input())))
tmp=s[0]
cnt=[]
c=0
for i in range(n):
    if tmp==s[i]:
        c+=1
    else:
        tmp=s[i]
        cnt.append( c)
        c=1
    if i==n-1:
        cnt.append( c)
ans=0
S=[0]*len(cnt)
S[0]=cnt[0]
for i in range(1, len(cnt)):
    S[i]=S[i-1]+cnt[i]
S=[0]+S

for i in range(len(cnt)):
    if i%2==s[0]:
        if i+k*2<=len(cnt):
            ans=max(ans, S[i+k*2]-S[i])
        else:
            ans=max(ans, S[len(cnt)]-S[i])
    else:
        if i+k*2+1<=len(cnt):
            ans=max(ans, S[i+k*2+1]-S[i])
        else:
            ans=max(ans,S[len(cnt)]-S[i])
print(ans)

Measured memory_bytes: 9240
#include <bits/stdc++.h>
#define maxn 401
using namespace std;
typedef long long LL;

int n;
LL sum[maxn];
LL dp[maxn][maxn];

int main() {
	cin >> n;
	for( int i = 1 ; i <= n ; i++ ) {
		cin >> sum[i];
		sum[i] += sum[i-1];
	}
	for( int len = 2 ; len <= n ; len++ )
		for( int i = 1 ; i+len-1 <= n ; i++ ) {
			int j = i+len-1;
			dp[i][j] = (1LL << 62);
			for( int k = i ; k < j ; k++ ) {
				LL left = sum[k] - sum[i-1];
				LL right = sum[j] - sum[k];
				dp[i][j] = min( dp[i][j] , dp[i][k] + dp[k+1][j] + left + right );
			}
		}
	cout << dp[1][n];
}


Measured memory_bytes: 1536
package main

import (
    "fmt"
    "strconv"
)

func main() {
    var bs []byte
    fmt.Scan(&bs)
    is := make([]int, 4)
    for i := 0; i < 4; i++ {
        is[i], _ = strconv.Atoi(string([]byte{bs[i]}))
    }   
    for i := 0; i < 8; i++ {
        ans := []byte{bs[0]}
        sum := is[0]
        if i%2 == 0 { 
            sum += is[1]
            ans = append(ans, []byte{'+', bs[1]}...)
        } else {
            sum -= is[1]
            ans = append(ans, []byte{'-', bs[1]}...)
        }   
        if i%4 == 0 || i%4 == 1 { 
            sum += is[2]
            ans = append(ans, []byte{'+', bs[2]}...)
        } else {
            sum -= is[2]
            ans = append(ans, []byte{'-', bs[2]}...)
        }   
        if i < 4 { 
            sum += is[3]
            ans = append(ans, []byte{'+', bs[3]}...)
        } else {
            sum -= is[3]
            ans = append(ans, []byte{'-', bs[3]}...)
        }   
        if sum == 7 { 
            fmt.Printf("%s=7\n", ans)
            break
        }   
    }   
}


Measured memory_bytes: 512
import java.util.Scanner;
class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int sum = 0;
        int[] d = new int[N];

        for (int i = 0; i < N; i++) {
            d[i] = sc.nextInt();
        }

        for (int i = 0; i < N; i++) {
            for (int j = i + 1; j < N; j++) {
                sum += d[i] * d[j];
            }
        }
        System.out.println(sum);
    }
}

Measured memory_bytes: 23124
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
typedef long long LL;
const LL N = 1000000007;

LL fac[500005],inv[500005];

LL kpw(LL x,LL y){
	LL ans = 1,tmp = x;
	while(y){
		if(y & 1) ans = (ans * tmp) % N;
		tmp = (tmp * tmp) % N;
		y >>= 1;
	}
	return ans;
}

LL comb(LL x,LL y){
	return (((fac[x] * inv[y]) % N) * inv[x - y]) % N;
}

void init(){
	fac[0] = 1; for(LL i = 1;i <= 500000;i ++) fac[i] = (fac[i - 1] * i) % N;
	for(LL i = 0;i <= 500000;i ++) inv[i] = kpw(fac[i],N - 2);
}

int main() {
	LL n,k,ans = 0; init();
	cin >> n >> k;
	if(k >= n) k = n - 1;
	for(LL i = 0;i <= k;i ++) ans = (ans + (comb(n,i) * comb(n - 1,i)) % N) % N;
	cout << ans << endl;
	return 0;
}
//

Measured memory_bytes: 8064
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

ans = 0
for i in range(N):
  a = A[i]
  ans += B[a-1]
  if (i!=N-1) and (A[i]+1==A[i+1]):
    ans += C[a-1]
    
print(ans)

Measured memory_bytes: 9192
#include<algorithm>
#include <iostream>
#include<cstdio>
#include<cmath>
#include<iomanip>
#include<string>
#include<cstdlib>
#include<ctime>
#include<vector>
#include<map>
using namespace std;

int main(){
//srandom((unsigned long)time(NULL));

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

for(int i=0;i<n;i++){
    cnt+=1;
    nw=a[nw]-1;
    //cout<<"now"<<nw<<"desu"<<endl;
    if(nw==1){
        cout<<cnt<<endl;
        return 0;
    }

}

cout<<-1<<endl;

return 0;
}

Measured memory_bytes: 640
#include<cstdio>
using namespace std;
#define N 4050
int n,m,st[N],fg,head[N],cnt,vl[N],ct,s,t,as,v[N][2],ct2,is[N],nt[N],v2[N][2];
struct edge{int t,next,id;}ed[N*2];
struct sth{int f,t,v;};bool operator <(sth a,sth b){return a.v<b.v;}
void adde(int f,int t,int id){ed[++cnt]=(edge){t,head[f],id};head[f]=cnt;ed[++cnt]=(edge){f,head[t],id};head[t]=cnt;}
void adde2(int f,int t,int id){ed[++cnt]=(edge){t,head[f],id*2};head[f]=cnt;ed[++cnt]=(edge){f,head[t],id*2+1};head[t]=cnt;}
void dfs(int u,int fa)
{
	if(!fg)st[++ct]=u;
	if(u==t)fg=1;
	for(int i=head[u];i;i=ed[i].next)if(ed[i].t!=fa)dfs(ed[i].t,u);
	if(!fg)ct--;
}
void dfs2(int u,int fa)
{
	for(int i=head[u];i;i=ed[i].next)if(ed[i].t!=fa)dfs2(ed[i].t,u);
	int ls=0;
	for(int i=1;i<=ct2;i++)
	if(v[i][0]==u||v[i][1]==u)
	{
		if(!ls)ls=i;
		else
		{
			int l=v[ls][0],r=v[i][1];
			if(v[ls][0]==u)l=v[ls][1],is[ls]=1;
			if(v[i][1]==u)r=v[i][0],is[i]=1;
			nt[ls]=nt[i]=++ct2;
			v[ct2][0]=l;v[ct2][1]=r;
			v[ls][0]=v[ls][1]=v[i][0]=v[i][1]=0;ls=0;
			if(v[ct2][0]==v[ct2][1])v[ct2][0]=v[ct2][1]=0;
		}
	}
	if(ls)
	{
		if(v[ls][0]==u)v[ls][0]=fa;
		else v[ls][1]=fa;
		if(v[ls][0]==v[ls][1])v[ls][0]=v[ls][1]=0;
	}
}
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<n;i++)scanf("%d%d",&s,&t),adde(s,t,i);
	for(int r=1;r<=m;r++)
	{
		scanf("%d%d",&s,&t);ct=fg=0;dfs(s,0);v[r][0]=s,v[r][1]=t;v2[r][0]=s;v2[r][1]=t;
		for(int i=1;i<ct;i++)for(int j=head[st[i]];j;j=ed[j].next)if(ed[j].t==st[i+1]&&vl[ed[j].id]<2)vl[ed[j].id]++,as++;
	}
	printf("%d\n",as);
	ct2=m;dfs2(1,0);
	for(int i=ct2;i>=1;i--)
	is[i]^=is[nt[i]];
	for(int i=1;i<=m;i++)if(is[i])printf("%d %d\n",v2[i][1],v2[i][0]);
	else printf("%d %d\n",v2[i][0],v2[i][1]);
}//

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr long long INFL = numeric_limits<long long>::max() / 2;
constexpr int MOD = 1000000007;
using Graph = vector<vector<int>>;



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

    int N;
    cin >> N;
    int V[N],C[N];
    rep(i,N) cin >> V[i];
    rep(i,N) cin >> C[i];
    int ans=0;
    rep(i,N){
        int x=V[i]-C[i];
        if(x>0) ans+=x;
    }
    cout << ans << endl;



}


Measured memory_bytes: 256
use proconio::input;

fn main() {
    input! {
        n: usize,
        mut ab: [(usize, usize); n],
        mut cd: [(usize, usize); n],
    }

    cd.sort_by_key(|&(c, _d)| c);

    ab.sort_by_key(|&(_a, b)| b);
    ab.reverse();

    let mut used = vec![false; n];

    let mut ans = 0;

    for (c, d) in cd {
        for (i, &(a, b)) in ab.iter().enumerate() {
            if !used[i] && a < c && b < d {
                ans += 1;
                used[i] = true;
                break;
            }
        }
    }

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


Measured memory_bytes: 2184
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep2(i, n) for (int i = 1; i <= (n); ++i)
using namespace std;
typedef pair<int, int> p;
typedef long long ll;
int main() {
  int n, k;
  cin >> n >> k;
  double res = 0;
  rep2(i, n) {
    double tmp = (double)1 / n;
    int now = i;
    while (now < k) {
      now *= 2;
      tmp /= 2;
    }
    res += tmp;
  }
  cout << setprecision(15) << res << endl;
  return 0;
}

Measured memory_bytes: 3744
//temprates
#include <iostream>
#include <tuple>
#include <sstream>
#include <vector>
#include <cmath>
#include <ctime>
#include <cassert>
#include <cstdio>
#include <queue>
#include <set>
#include <map>
#include <fstream>
#include <cstdlib>
#include <string>
#include <cstring>
#include <algorithm>
#include <numeric>

using ll = long long;
using namespace std;

#define FOR(i,a,b) for(int i = (int)(a); i <= (int)(b); i++)
#define LFOR(i,a,b) for(ll i = (ll)(a); i <= (ll)(b); i++)
#define FORR(i,a,b) for(int i = (int)(a); i >= (int)(b); i--)
#define LFORR(i,a,b) for(ll i = (int)(a); i >= (ll)(b); i--)
#define REP(i,n) FOR(i,0,(int)(n)-1)
#define LREP(i,n) LFOR(i,0,(ll)(n)-1)
#define REPR(i,n) FORR(i,(int)(n)-1,0)
#define LREPR(i,n) LFORR(i,(ll)(n)-1,0)

#define SIZ(v) int(v.size())
const int INF = 1e8;
const ll LINF = 1e15;
const int MOD = 1e9+7;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  vector<ll> a,x;
  cin >> n;
  REP(i,n){
    ll k; cin >> k; a.push_back(k);
  }
  x.assign(n,0);
  REP(i,n){
    x[0] += a[i]*((i%2)?-1:1);
  }
  FOR(i,1,n-1){
    x[i] = 2*a[i-1] - x[i-1];
  }
  REP(i,n){
    cout << x[i] << " ";
  }
  cout << endl;
}


Measured memory_bytes: 3060
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
    int n;
    long[] as;
    long sum;

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

    void run() {
        FastReader sc = new FastReader();
        n = sc.nextInt();
        as = new long[n];
        sum = 0;
        for (int i = 0; i < n; i++) {
            as[i] = sc.nextLong();
            sum += as[i];
        }
        solve();
    }

    void solve() {
        if (check(as)) {
            System.out.println(0);
            return;
        }
        long count = 0;
        while (true) {
            long tempCount = 0;
            boolean flag = true;
            long[] memo = new long[n];
            for (int i = 0; i < n; i++) {
                memo[i] = as[i] / n;
                tempCount += memo[i];
                as[i] %= n;
            }
            count += tempCount;
            long max = Long.MIN_VALUE;
            for (int i = 0; i < n; i++) {
                as[i] += tempCount - memo[i];
                if (as[i] > max) {
                    max = as[i];
                }
            }
            if (max < n) {
                break;
            }
        }
        System.out.println(count);
    }

    boolean check (long[] as) {
        boolean flag = true;
        for (int i = 0; i < as.length; i++) {
            if (as[i] >= as.length) {
                flag = false;
                break;
            }
        }
        return flag;
    }

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt()
        {
            return Integer.parseInt(next());
        }

        long nextLong()
        {
            return Long.parseLong(next());
        }

        double nextDouble()
        {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }
}


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

int main(){
  
  int a, b;
  cin >> a >> b;
  
  a *= b;
  a &= 1;
  
  if(a == 1)
    cout << "Odd" << endl;
  else
    cout << "Even" << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  vector<int> v(n);
  for(int i=0;i<n;i++){
    cin>>v[i];
  }
    int dp[n];
    dp[0]=0;
    dp[1]=abs(v[1]-v[0]);
    for(int i=2;i<n;i++){
      dp[i]=min(dp[i-1]+abs(v[i]-v[i-1]), dp[i-2]+abs(v[i]-v[i-2]));
    }
    cout<<dp[n-1]<<endl;
    return 0;
}


Measured memory_bytes: 3988
def draw_max_card(card_list):
    max_card = max(card_list)
    card_list.remove(max_card)
    return max_card

n = int(input())
card_list = list(map(int, input().split(" ")))
points_alice = 0
points_bob  = 0
for count in range(1, n + 1):
    if count % 2 != 0:
        points_alice += draw_max_card(card_list)
    else:
        points_bob += draw_max_card(card_list)

print(points_alice - points_bob)


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

#define rep(i, x, n) for (int i = x; i < n; i++)
typedef long long ll;

const int INF = 1e9 + 7;

using namespace std;

/* greatest common divisor */
template <typename T> // ll or int
T gcd(T x, T y) {
  T res = 0;
  T mod = x % y;
  if (mod == 0)
    res = y;
  else
    res = gcd(y, mod);

  return res;
}

bool isPrime(ll num)
{
  if (num < 1)
    return false;
  else if (num == 1)
    return true;
  else if (num == 2)
    return true;
  else if (num % 2 == 0)
    return false;

  double limit = sqrt(num);
  for (ll i = 3; i <= limit; i += 2) {
    if (num % i == 0)
      return false;
  }

  return true;
}

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

  ll a, b;
  cin >> a >> b;

  ll gcd_v = gcd(a, b);
  vector<ll> gcd_num;
  set<ll> gcd_set;
  // ll res = 0;
  for (ll i = 1; i * i <= gcd_v; i++) {
    if (gcd_v % i == 0) {
      if (isPrime(i))
        gcd_set.insert(i);
        //        gcd_num.push_back(i);
      if (i != 1 && i * i != gcd_v) {
        ll tmp = gcd_v / i;
        if (isPrime(tmp))
          gcd_set.insert(tmp);
          //          gcd_num.push_back(tmp);
      }
    }
  }

  if (isPrime(gcd_v))
    gcd_set.insert(gcd_v);
    //    gcd_num.push_back(gcd_v);


  cout << gcd_set.size() << endl;

	return 0;
}


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

int main() {
  int a, b, c;
  cin >> a;
  cin >> b;
  cin >> c;
  int x;
  cin >> x;

  int count = 0;
  for(int i=0; i<=a; i++) {
    for(int j=0; j<=b; j++) {
      for(int k=0; k<=c; k++) {
        int total = 500*i + 100*j + 50*k;
        if(total == x) count++;
      }
    }
  }

  cout << count << endl;
}

Measured memory_bytes: 256
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

void main()
{
    auto nab = readln.split.to!(long[]);
    auto N = nab[0];
    auto A = nab[1];
    auto B = nab[2];

    if (N <= A) {
        writeln(N);
    } else {
        auto c = N / (A+B);
        writeln(A * c + min(A, N % (A+B)));
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <vector>
#include <regex>
#include <map>
#include <set>
#include <iomanip>

using namespace std;
#define int long long

signed main(){
    int N,M;
    cin >> N >> M;
    
    map<int,int> mp;
    int A;
    for(int i=0;i<M*2;i++){
        cin >> A;
        mp[A]++;
    }
    
    for(int i=1;i<=N;i++){
        cout << mp[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 256
void main(){
	string n = readln().chomp();
	char[] ans;
	foreach(elm; n){
		ans ~= (elm=='9')? '1': '9';
	}
	ans.writeln();
}

import std.stdio, std.conv, std.algorithm, std.numeric, std.string, std.math;

// 1要素のみの入力
T _scan(T= int)(){
	return to!(T)( readln().chomp() );
}

// 1行に同一型の複数入力
T[] _scanln(T = int)(){
	T[] ln;
	foreach(string elm; readln().chomp().split()){
		ln ~= elm.to!T();
	}
	return ln;
}


Measured memory_bytes: 2580
#include<string>
#include<iostream>
#include<algorithm>
#include<set>
#include<math.h>
#include<vector>
#include<sstream>
#include<queue>
#include<functional>
#include<bitset>
#include<cstdio>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include <string.h>
using ll = long long;

#define rep(i, n) for(ll i = 0; i < (int)(n); i++)
#define reps(i,x) for(ll i=1;i<=(int)(x);i++)
#define rrep(i,x) for(ll i=((int)(x)-1);i>=0;i--)
#define rreps(i,x) for(ll i=(int)(x);i>0;i--)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))
#define vll vector<ll>
#define vi vector<int>
#define mp make_pair
#define vpll vector<pair<ll,ll>>
#define vpi vector<pair<int,int>>
#define mod 1000000007 
using namespace std;
int n, k;
int main() {
	string s;
	cin >> n >>s;
	int ans = 0;
	reps(i, n-1) {
		set<char> st1;
		set<char> st2;
		rep(j, i) {
			st1.insert(s[j]);
		}
		for (int j = i; j < n; j++) {
			st2.insert(s[j]);
		}
		int cnt = 0;
		for (auto c : st1) {
			if (find(st2.begin(), st2.end(), c) != st2.end())
				cnt++;
		}
		ans = max(ans, cnt);

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

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

const long long INF= (long long)(1e18)+1;

void Main() {
  int n;
  long long k;
  cin >> n >> k;

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

  long long l = -INF, r = INF;
  while (l + 1 < r) {
    long long x = (l + r) / 2;
    bool ok = [&]{
      long long tot = 0;
      for (int i = 0; i < n; i++) {
        if (a[i] < 0) {
          int l = -1, r = n;
          while (l + 1 < r) {
            int c = (l + r) / 2;
            if (a[c] * a[i] < x) r = c;
            else l = c;
          }
          tot += n - r;
        } else {
          int l = -1, r = n;
          while (l + 1 < r) {
            int c = (l + r) / 2;
            if (a[c] * a[i] < x) l = c;
            else r = c;
          }
          tot += r;
        }
        if (a[i] * a[i] < x) tot--;
      }
      tot /= 2;
      return tot < k;
    }();
    if (ok) l = x;
    else r = x;
  }
  cout << l << endl;
}

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  Main();
  return 0;
}


Measured memory_bytes: 1792