akhauriyash/Code-Regression huggingface dataset:
// inputに入力データ全体が入る
function Main(input) {
	input = input.split("\n");
  	
  	//夏休みの日数
	let tmpSummerWeek = input[0].split(" ");
  	let summerWeek = parseInt(tmpSummerWeek[0],10);
  	
  	//宿題のかかる日数を文字列で受け取る
	let syukudaiArray = input[1].split(" ");
  
	let syukudai = 0;  
  	syukudaiArray.forEach(function (value){
    	syukudai  += parseInt(value,10);
    })
  
  	let ans = summerWeek - syukudai ;

	//出力
	console.log('%d',ans > -1 ? ans : -1);
}

//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 33180
#include <algorithm>
#include <bitset>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <sstream>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#define rep(i, n) for (int i = 0; i < n; ++i)
#define debug(s, param) std::cerr << s << param << std::endl;

using namespace std;
using ll = long long;

bool isAvailable(const vector<int>& rc, int row, int col) {
  rep (r, 8) {
    if (r == row || rc[r] == -1) continue;
    if (rc[r] == col) return false;
    if (abs(r - row) == abs(rc[r] - col)) return false;
  }
  return true;
}

vector<int> backtrack(vector<int> rc, int row) {
  if (row == 8) return rc;
  if (rc[row] != -1) return backtrack(rc, row + 1);

  rep (col, 8) {
    if (isAvailable(rc, row, col)) {
      vector<int> newrc(8, -1);
      copy(rc.begin(), rc.end(), newrc.begin());
      newrc[row] = col;
      vector<int> res = backtrack(newrc, row + 1);
      if (res.size() == 8) return res;
    }
  }

  return vector<int>(0);
}

int main() {
  int k;
  cin >> k;
  vector<int> rc(8, -1);
  rep (i, k) {
    int r, c;
    cin >> r >> c;
    rc[r] = c;
  }
  vector<int> res = backtrack(rc, 0);
  rep (r, 8) {
    string line;
    rep (i, 8) {
      if (i == res[r]) line += "Q";
      else line += ".";
    }
    cout << line << endl;;
  }

  return 0;
}


Measured memory_bytes: 3208
def i():
	return int(input())
def i2():
	return map(int,input().split())
def s():
	return str(input())
def l():
	return list(input())
def intl():
	return list(int(k) for k in input().split())

n = i()
s = s()

cnt = 0
for i in range(n-2):
	if s[i]+s[i+1]+s[i+2] == "ABC":
		cnt += 1

print(cnt)

Measured memory_bytes: 9196
#include<stdio.h>
#include<stdlib.h>
#define MAX 1000000000

int main(){
  int i=0,k,n,q,*S,*T,count=0,j,flag,key;

  S = malloc(MAX);
  T = malloc(MAX);
  
  scanf("%d",&n);
  for(i=0;i<n;i++){ scanf("%d",&S[i]);

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

  for(i=0;i<q;i++){
    j=0;
    
    key = T[i];
    S[n] = key;

    flag=1;
    while(S[j] != T[i]){
      
      j++;
      if(j == n) flag=0;
    }

    if(flag == 1) count++;
  }

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

  free(S);
  free(T);
  
  return 0;
}



Measured memory_bytes: 2104
/** "Ever tried.
         Ever failed.
               No matter.
                   Try Again.
                        Fail again.
                             Fail better.**/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define ll long long
#define bp  __builtin_popcount
#define endl "\n"
#define oo 0x3f3f3f3f3f3f3f3fLL
#define pb push_back
#define loop(i,n) for(int i = 0;i < int(n);i++)
#define sz(s) (int)(s.size())
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()
#define setdp memset(dp,-1,sizeof(dp))
#define db(x) cout<<" LOOK "<<(#x)<<" = "<<x <<'\n'
#define NumofDigits(n)   ((long long)log10(n)+1)

using namespace std;
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag, tree_order_statistics_node_update> indexed_set;
const int maxn=1e5+5;
const  double EPS = 1e-9;
const int MOD = 1e9+7;
/*
ll gcd(ll a, ll b) { return !b ? a : gcd(b, a % b); }
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }
ll fastpow(ll b, ll p)
{if(!p)return 1;ll ret = fastpow(b, p >> 1);ret *= ret;if(p&1)ret*= b;return ret;}
int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};*/
inline void File()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
#endif
}


int main()
{
    ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    //File();
    string s;
    cin>>s;
    int ones=0,zeroes=0;
    for(int i=0;i<sz(s);i++)
    {
        if( s[i] == '1')ones++;
        else
            zeroes++;
    }
    cout<<min(ones,zeroes)*2;
}


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

using namespace std;

#define rep(i,a,b) for(int i = a; i<int(b);++i)
#define all(v) v.begin(),v.end()
#define sz(v) v.size()
#define trav(a,c) for(auto a: c)

typedef long long ll;
typedef vector<ll> vi;
typedef pair<ll,ll> pii;

int main(){
	cin.sync_with_stdio(false);
	ll x,y;
	cin>>x>>y;
	ll pw = 1;
	ll ans = 0;
	while(pw<=(y/x)) {
        ans++;
        pw<<=1;
	}
	cout<<ans<<endl;
}


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

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

    vector<pair<int, int>> a(n);
    for(int i=0; i<n; i++){
        cin >> a[i].first;
        a[i].second = i+1;
    }
    sort(a.begin(),a.end());

    set<int> pos = {0,n+1};
    long long int ans = 0;
    for(int i=0; i<n; i++){
        long long int p = a[i].second;
        long long int left = *pos.lower_bound(a[i].second);
        long long int right = *prev(pos.lower_bound(a[i].second));
        //cout << i+1 << " : " << left << " " << right << endl;
        
        ans += (i+1) * (p - left) * (right - p);
        pos.insert(a[i].second);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 13988
from collections import deque

N = int(input().strip("\n"))
ALL = N*(N-1)//2
A = [deque(list(map(lambda x :int(x)-1, input().split()))) for _ in range(N)]

day = 0
candidates = set(range(N))
while len(candidates)>0:
    day += 1
    nextday = set()
    checked = set()
    #print(candidates)
    for candidate in candidates:
        if len(A[candidate]) == 0:
            continue
        if candidate in checked:
            continue
        opponent = A[candidate][0]
        if opponent in checked:
            continue
        if A[opponent][0] == candidate:
            A[opponent].popleft()
            A[candidate].popleft()
            nextday.add(candidate)
            nextday.add(opponent)
            checked.add(candidate)
            checked.add(opponent)
    candidates = nextday

for p in A:
    if len(p) > 0:
        print(-1)
        break
else:
    print(day-1)

Measured memory_bytes: 77828
num_of_jewels = int(input())
value_list = input().split()
value_list_i = [int(s, 0) for s in value_list]
cost_list = input().split()
cost_list_i = [int(s, 0) for s in cost_list]
total_value = 0
for i in range(num_of_jewels):
    if value_list_i[i] - cost_list_i[i] > 0:
        total_value = total_value + value_list_i[i] - cost_list_i[i]
print('%d' % total_value)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define rep(i,m,n) for(int (i)=(int)(m);(i)<(int)(n);++(i))
#define rREP(i,m,n) for(int (i)=(n)-1;(i)>=(m);--(i))
#define all(x) (x).begin(),(x).end()
#define out(y,x,h,w) (y)<0||(x)<0||(y)>=(h)||(x)>=(w)
constexpr int INF = 1000000001;
constexpr ll mod = 1000000007;
constexpr double PI = 3.1415926535897932;

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;
}
inline void init() {
	cin.tie(nullptr); cout.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

int main() {
	init();

	int N, M; cin >> N >> M;
	vector<vector<pair<int, int>>>vec(N);
	rep(i, 0, M) {
		int a, b; cin >> a >> b;
		--a;
		vec[a].push_back(make_pair(b, i));
	}
	unordered_map<int, pair<int,int>>mp;
	vector<string>ans(M);
	rep(i, 0, N) {
		sort(all(vec[i]));
		rep(j, 0, vec[i].size()) {
			string p = to_string(i + 1), y = to_string(j + 1);
			string num = string(12, '0');
			rep(k, 0, p.size()) {
				num[5 - k] = p[p.size() - 1 - k];
			}
			rep(k, 0, y.size()) {
				num[11 - k] = y[y.size() - 1 - k];
			}
			ans[vec[i][j].second] = num;
		}
	}
	rep(i, 0, M) {
		cout << ans[i] << "\n";
	}

	return 0;
}

Measured memory_bytes: 12416
#include <stdio.h>
int main()
{
  int n;
  scanf("%d", &n);
  
  for(int i=1;i<10;i++){
    for(int j=i;j<10;j++){
      if(n == i*j){
        printf("Yes");
        return 0;
      }
    }
  }
  printf("No");
  return 0;
}

Measured memory_bytes: 128
// https://atcoder.jp/contests/abc144/tasks/abc144_a

#include "algorithm"
#include "iostream"
#include "queue"
#include "set"
#include "vector"
#define rep(i, to) for (ll i = 0; i < (to); ++i)
#define repf(i, from, to) for (ll i = from; i < (to); ++i)
using namespace std;
typedef long long ll;
template <typename T>
using V = vector<T>;
using VL = V<ll>;
using VVL = V<VL>;
template <typename T, typename U>
using P = pair<T, U>;
using PL = P<ll, ll>;
using VPL = V<PL>;
template <typename T>
inline bool chmax(T& a, T b);
template <typename T>
inline bool chmin(T& a, T b);
void print_ints(vector<ll> v);
template <typename T>
void drop(T a);

void solve() {
  ll A, B;
  cin >> A >> B;

  if (A <= 9 && B <= 9) {
    cout << A * B << endl;
  } else {
    cout << -1 << endl;
  }
}

struct exit_exception : public std::exception {
  const char* what() const throw() { return "Exited"; }
};

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

  try {
    solve();
  } catch (exit_exception& e) {
  }

  return 0;
}
#endif

template <typename T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}

template <typename T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

void print_ints(vector<ll> v) {
  rep(i, v.size()) {
    if (i > 0) {
      cout << " ";
    }

    cout << v[i];
  }

  cout << endl;
}

template <typename T>
void drop(T res) {
  cout << res << endl;
  throw exit_exception();
}


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

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define GET_MACRO(_1,_2,_3,_4,_5,_6,_7,_8,NAME,...) NAME
#define pr(...) cerr<< GET_MACRO(__VA_ARGS__,pr8,pr7,pr6,pr5,pr4,pr3,pr2,pr1)(__VA_ARGS__) <<endl
#define pr1(a) (#a)<<"="<<(a)<<" "
#define pr2(a,b) pr1(a)<<pr1(b)
#define pr3(a,b,c) pr1(a)<<pr2(b,c)
#define pr4(a,b,c,d) pr1(a)<<pr3(b,c,d)
#define pr5(a,b,c,d,e) pr1(a)<<pr4(b,c,d,e)
#define pr6(a,b,c,d,e,f) pr1(a)<<pr5(b,c,d,e,f)
#define pr7(a,b,c,d,e,f,g) pr1(a)<<pr6(b,c,d,e,f,g)
#define pr8(a,b,c,d,e,f,g,h) pr1(a)<<pr7(b,c,d,e,f,g,h)
#define prArr(a) {cerr<<(#a)<<"={";int i=0;for(auto t:(a))cerr<<(i++?", ":"")<<t;cerr<<"}"<<endl;}
using namespace std;
using Int = long long;
using _int = int;
using ll = long long;
using Double = long double;
const Int INF = (1LL<<60)+1e9; // ~ 1.15 * 1e18
const Int mod = (1e9)+7;
const Double EPS = 1e-8;
const Double PI = 6.0 * asin((Double)0.5);
using P = pair<Int,Int>;
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
template<class T1, class T2> ostream& operator<<(ostream& o,pair<T1,T2> p){return o<<"("<<p.first<<","<<p.second<<")";}
template<class T1, class T2, class T3> ostream& operator<<(ostream& o,tuple<T1,T2,T3> t){
  return o<<"("<<get<0>(t)<<","<<get<1>(t)<<","<<get<2>(t)<<")";}
template<class T1, class T2> istream& operator>>(istream& i,pair<T1,T2> &p){return i>>p.first>>p.second;}
template<class T> ostream& operator<<(ostream& o,vector<T> a){Int i=0;for(T t:a)o<<(i++?" ":"")<<t;return o;}
template<class T> istream& operator>>(istream& i,vector<T> &a){for(T &t:a)i>>t;return i;}
//INSERT ABOVE HERE


signed main(){
  srand((unsigned)time(NULL));
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  Int X, Y, Z;
  cin>>X>>Y>>Z;
  Int N = X + Y + Z;
  
  using T = tuple<Int,Int,Int>;
  vector<T> A(N);
  for(Int i=0;i<N;i++){
    Int a, b, c;
    cin>>a>>b>>c;
    A[i] = T(a, b, c);
  }


  sort(A.begin(), A.end(), [&](auto p, auto q){
      Int a, b, c; tie(a, b, c) = p;
      Int x, y, z; tie(x, y, z) = q;
      return b - a > y - x;
    });

  Int ofset = 0;

  vector<Int> used(N);
  priority_queue<P> BC; //BからCにしたい順
  for(Int i=0;i<Y;i++){
    Int a, b, c; tie(a, b, c) = A[i];
    used[i] = 1;
    ofset += b;
    BC.emplace(-b + c, i);
  }
  
  priority_queue<P> CA; //CからAにしたい順
  for(Int i=Y;i<N;i++){
    Int a, b, c; tie(a, b, c) = A[i];
    used[i] = 2;
    ofset += c;
    CA.emplace(-c + a, i);
  }

  for(Int i=0;i<X;i++){
    Int j = CA.top().second; CA.pop();
    Int a, b, c; tie(a, b, c) = A[j];
    used[j] = 0;
    ofset += -c + a;
  }

  Int ans = ofset;
  for(Int i=Y;i<N;i++){
    Int a, b, c; tie(a, b, c) = A[i];
        
    { 
      if(used[i] == 2) ofset -= c;
      else if(used[i] == 0){
	ofset -= a;
	Int j = -1;
	while(!CA.empty() && j < i) j = CA.top().second, CA.pop();
	if(j < i) break;
	Int x, y, z; tie(x, y, z) = A[j];
	ofset += -z + x;
	used[j] = 0;
      }
    }
    { 
      ofset += b;
      used[i] = 1;
      BC.emplace(-b + c, i);
      ofset += BC.top().first; used[BC.top().second] = 2, BC.pop();
    }
    
    Max(ans, ofset);
  }
  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 6132
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define SZ(X) ((int)(X).size())
#define endl "\n";
int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
	int a[3],k;
	cin>>a[0]>>a[1]>>a[2]>>k;
	sort(a,a+3);
for (int i = 0; i < k; ++i)
{
	a[2]*=2;
}
	cout<<a[0]+a[1]+a[2];

   return 0;
}


Measured memory_bytes: 3508
using System;

public class hello
{
    public static void Main()
    {
        string[] line = Console.ReadLine().Trim().Split(' ');
        var n = int.Parse(line[2]);
        string[] line2 = Console.ReadLine().Trim().Split(' ');
        var sx = int.Parse(line2[0]);
        var sy = int.Parse(line2[1]);
        var count = 0;
        for (int i = 1; i < n; i++)
        {
            string[] line3 = Console.ReadLine().Trim().Split(' ');
            var tx = int.Parse(line3[0]);
            var ty = int.Parse(line3[1]);
            var d = GetDelta(sx,sy,tx,ty);
            count += Math.Abs(d);
            count += GetNormal(tx, ty, sx + d, sy + d);
            sx = tx;
            sy = ty;
        }
        Console.WriteLine(count);
    }
    public static int GetNormal (int x1 , int y1 , int x2, int y2)
    {
        return Math.Abs(x1 - x2) + Math.Abs(y1 - y2);
    }
    public static int  GetDelta (int x1, int y1, int x2, int y2)
    {
        if (x2 - x1 > 0 && y2 - y1 > 0) return Math.Min(x2 - x1, y2 - y1);
        if (x2 - x1 < 0 && y2 - y1 < 0) return Math.Max(x2 - x1, y2 - y1);
        else return 0;
    }
}

Measured memory_bytes: 9180
N = int(input())
t = [0 for i in range(N)]
csf = [list(map(int, input().split())) for i in range(N - 1)]
for i in range(N - 1):
	tmp_t = 0
	for j in range(i, N - 1):
		c, s, f = csf[j]
		if s >= tmp_t:
			tmp_t += s - tmp_t + c
		else:
			a = (tmp_t - s + f - 1) // f
			tmp_t += s + f * a - tmp_t + c
	print(tmp_t)
print(0)


Measured memory_bytes: 44140
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int k = sc.nextInt();
        int[] a = new int[k];
        for(int i=0; i<k; i++){
            a[i] = sc.nextInt();
        }
        sc.close();

        if(a[k-1] != 2){
            System.out.println("-1");
            return;
        }
        
        long[] range = new long[]{2, 3};
        for(int i=k-2; i>=0; i--){
            range = step(range, a[i]);
            if(range[0] == -1){
                System.out.println("-1");
                return;
            }
        }
        
        System.out.println(range[0] + " " + range[1]);
    }

    public static long[] step(long[] range, long n){
        long[] ans = new long[]{-1, -1};
        long al = range[0] / n;
        long bl = range[0] % n;
        long ar = range[1] / n;
        long br = range[1] % n;

        if(ar - al == 0 && bl != 0){
            return ans;
        }

        if(bl == 0){
            ans[0] = range[0];
            ans[1] = ar*n + n-1;
        }else{
            ans[0] = al*n + n;
            ans[1] = ar*n+n-1;
        }

        return ans;
    }
}



// import java.math.BigInteger;
// import java.util.Scanner;

// public class BMain {
//     public static void main(String[] args) {
//         Scanner sc = new Scanner(System.in);
//         int k = sc.nextInt();
//         int[] a = new int[k];
//         for(int i=0; i<k; i++){
//             a[i] = sc.nextInt();
//         }
//         sc.close();
        
//         BigInteger[] range = new BigInteger[2];
//         range[0] = new BigInteger("2");
//         range[1] = new BigInteger("3");


//         for(int i=k-2; i>=0; i--){
//             range = step(range, BigInteger.valueOf(a[i]));
//             if(range[0].compareTo(BigInteger.valueOf(-1)) == 0){
//                 System.out.println("-1");
//                 return;
//             }
//         }
        
//         System.out.println(range[0] + " " + range[1]);
//     }

//     public static BigInteger[] step(BigInteger[] range, BigInteger n){
//         BigInteger[] ans = new BigInteger[2];
//         ans[0] = new BigInteger("-1");
//         ans[1] = new BigInteger("-1");
//         BigInteger al = range[0].divide(n);
//         BigInteger bl = range[0].mod(n);
//         BigInteger ar = range[1].divide(n);
//         BigInteger br = range[1].mod(n);

//         if(ar.compareTo(al) == 0 && bl.compareTo(BigInteger.ZERO) != 0){
//             return ans;
//         }

//         if(bl.compareTo(BigInteger.ZERO) == 0){
//             ans[0] = range[0];
//             ans[1] = ar.multiply(n).add(n).subtract(BigInteger.ONE);
//         }else{
//             ans[0] = al.multiply(n).add(n);
//             ans[1] = ar.multiply(n).add(n).subtract(BigInteger.ONE);
//         }

//         return ans;
//     }
// }

Measured memory_bytes: 51112
import heapq

def solve(n, v):
    v_pq = []
    for v_i in v:
        heapq.heappush(v_pq, v_i)

    while len(v_pq) > 1:
        v1 = heapq.heappop(v_pq)
        v2 = heapq.heappop(v_pq)
        heapq.heappush(v_pq, (v1 + v2) / 2)

    return heapq.heappop(v_pq)


if __name__ == "__main__":
    n = int(input())
    v = list(map(int, input().strip().split(" ")))
    print(solve(n, v))

Measured memory_bytes: 38384
import sys
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10**6)
def even(n): return 1 if n%2==0 else 0

n = int(readline())
g = [[] for i in range(n)] #g[i]:点iに隣接している点のリスト
for i in range(n-1):
    x,y = map(int,readline().split())
    x,y = x-1,y-1
    g[x].append(y)
    g[y].append(x)

dist_fe = [10**10]*n
dist_su = [10**10]*n

dist_fe[0] = 0
dist_su[n-1] = 0

def bfs(d,v,dist):
    for i in g[v]:
        if d[i] == 10**10:
            d[i] = dist+1
            bfs(d,i,dist+1)

bfs(dist_fe,0,0)
bfs(dist_su,n-1,0)

b = 0
w = 0

for i in range(n):
    if dist_fe[i] <= dist_su[i]: #先手優先
        b += 1
    else:
        w += 1

ans = "Fennec" if b > w else "Snuke"
print(ans)

Measured memory_bytes: 219056
N = gets.to_i
as = gets.split.map(&:to_i)
border = ((N*(N+1)/2)+1)/2
histo = Array.new(2*N+1, 0)
puts as.sort.uniq.reverse.bsearch{|mid|
    histo.fill(0)
    sum = N
    histo[N] += 1
    result = 0
    acum = 1
    N.times do |i|
        if as[i] >= mid
            sum += 1
            acum += histo[sum]
        else
            acum -= histo[sum]
            sum -= 1
        end
        result += acum
        histo[sum] += 1
        acum += 1
    end
    result >= border
}

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

int main() {
	int N, X;
	int minM = 1001;

	cin >> N >> X;
	for (int i = 0; i < N; i++) {
		int m;
		cin >> m;
		X -= m;
		minM = min(minM, m);
	}

	cout << N + X/minM << endl;
}

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


bool f(int n) {
    int i;
    for (i = 1; i*i <= n; i++)
        ;
    if ((i-1)*(i-1) == n)
        return true;
    return false;
}


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n, ans = -9;
    cin >> n;
    for (int i = n; i >= 1; i--) {
        if (f(i)) {
            cout << i << endl;
            return 0;
        }
    }
    
    
    return 0;
}





Measured memory_bytes: 256
// /*
#include <bits/stdc++.h>
using namespace std;
int dp [100003][4];
int n;
int arr [100003];
int brr [100003];
int crr [100003];
int main ()
{

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

{
cin >> arr [i]>>brr [i]>>crr [i];
}
dp [0][0] = arr [0];
dp [0][1] = brr [0];
dp [0][2] = crr [0];
for (int i = 1;i<n;i++)
{
dp [i][0] = arr [i] + max (dp [i - 1][1] , dp [i - 1][2]);
dp [i][1] = brr [i] + max (dp [i - 1][0] , dp [i - 1][2]);
dp [i][2] = crr [i] + max (dp [i - 1][0] , dp [i - 1][1]);
}
cout << max ({dp [n - 1][0],dp [n - 1][1],dp [n - 1][2]})<<'\n';
}



// */


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

int main() {
  string S,ans = "Yes";
  cin >> S;
  
  if(S=="AAA" || S=="BBB") ans="No";
  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
// #pragma GCC optimize ("O3")
// #pragma GCC target ("sse4")
using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int,int> PII;

#define REP(i,n) for(int i=0;i<(n);++i)
#define FOR(i,a,b) for (int i=(a); i<(b); ++i)
#define FORD(i,a,b) for (int i=(a)-1; i>=(b); --i)

#define pb push_back
#define mp make_pair
#define st first
#define nd second

const int MOD = 1000000007;

typedef LL T; const T EPS = 0;
//typedef double T; const T EPS = 1e-9;
typedef pair<T,T> Point;
//class Point:public pair<T,T>{public: int id;};

const int MAXN = 100000;

int N;                //IN: Liczba punktów
Point points[MAXN];   //IN: Punkty - psute! (sort)
int H;                //OUT:Wielkość otoczki
Point hull[MAXN+5];   //OUT:Kolejne punkty w kolejności CCW

inline bool ccw(Point& a, Point& b, Point& c){
  T A[] = {a.st-b.st,a.nd-b.nd,b.st-c.st,b.nd-c.nd};
  T det = A[0]*A[3] - A[1]*A[2];  //Dla T=int -> uwzględnić rozmiar (LL)!
  T cro = A[0]*A[2] + A[1]*A[3];  //Dla T=int -> uwzględnić rozmiar (LL)!
  return (det > EPS) || ((det>=-EPS) && (cro < -EPS));
}; //Zamienić na det>=-EPS dla "słabej" wypłuczki (uwaga na wszystkie współliniowe!)

inline void addPoint(int i){
  while((H > 1) && (!ccw(hull[H-2], hull[H-1], points[i])))H--;
  hull[H++] = points[i];
}
void computeHull(){
  int d = 0;
  sort(points, points+N);
  //N = unique(points, points+N)-points;// Potrzebne TYLKO jeśli N>1 i wszystkie równe
                                        //     (można obsłużyć inaczej)
  H = 0;
  REP(i,N)addPoint(i);
  if(N<2)return;
  FORD(i,N-1,0)addPoint(i);
  H--;
}

map<Point, int> mid;

double result[1000];

int main() {
  // ios_base::sync_with_stdio(0);

  scanf("%d", &N);
  REP(i,N) {
    scanf("%lld%lld", &points[i].st, &points[i].nd);
    mid[points[i]] = i;
  }

  if (N == 2) {
    printf("0.5\n0.5\n");
    return 0;
  }

  computeHull();

  REP(i, H) {
    Point pt = hull[i];
    Point prev = hull[(i+H-1)%H];
    Point next = hull[(i+1)%H];

    double angle = atan2(prev.nd - pt.nd, prev.st - pt.st)
                 - atan2(next.nd - pt.nd, next.st - pt.st);
    if (angle > 2*M_PI) angle -= 2*M_PI;
    if (angle < 0) angle += 2*M_PI;
    result[mid[pt]] = (M_PI - angle) / (2*M_PI);
  }

  REP(i,N) printf("%0.15lf\n", result[i]);
}


Measured memory_bytes: 640
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strconv"
	"strings"
)

var (
	reader io.Reader = os.Stdin
	writer io.Writer = os.Stdout
)

func main() {
	reader = os.Stdin
	writer = os.Stdout
	run()
}

func run() {
	numArr := readIntsFromStdin()
	results := make([]string, 0, len(numArr))

	for _, nums := range numArr {
		if nums[0] == 0 && nums[1] == 0 {
			break
		}

		if nums[0] > nums[1] {
			nums[0], nums[1] = nums[1], nums[0]
		}

		results = append(results, strconv.Itoa(nums[0])+" "+strconv.Itoa(nums[1]))
	}

	fmt.Fprintln(writer, strings.Join(results, "\n"))
}

// readIntsFromStdin parses lines of inputs into 2D int array.
func readIntsFromStdin() [][]int {
	out := [][]int{}
	scanner := bufio.NewScanner(reader)

	for scanner.Scan() {
		var ints []int

		for _, s := range strings.Split(scanner.Text(), " ") {
			i, err := strconv.Atoi(s)

			if err != nil {
				fmt.Fprintln(os.Stderr, "Failed to parse string into int.", err)
				os.Exit(1)
			}

			ints = append(ints, i)
		}

		out = append(out, ints)
	}

	return out
}



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

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

    int N, K;
    cin >> N >> K;

    vector<int> A(N);

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

    int c = 0;

    vector<int> x;

    for(int i = 0; i < N; i++) {
        if(A[i]) {
            c++;
            x.push_back(A[i]);
        }
    }

    if(c <= K) {
        cout << 0 << endl;
        return 0;
    }

    sort(x.begin(), x.end());

    int ans = 0;

    for(int i = 0; i < c - K; i++) {
        ans += x[i];
    }

    cout << ans << endl;
}

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

using namespace std;
using llong = long long;
using P = pair<llong, llong>;

#define BE(x) x.begin(), x.end()

const llong inf = llong(1e18)+7;
const llong mod = 1e9+7;

int main(){
	int N;
	map<int,int> m;

	cin >> N;
	int in;
	for(int i = 0; i < N; i++){
		cin >> in;
		m[in-1]++;
		m[in]++;
		m[in+1]++;
	}

	int ans = 0;
	for(auto it = m.begin(); it != m.end(); it++)
		ans = max(ans, it->second);

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 4736
#include "bits/stdc++.h"
using namespace std;
#define F first
#define S second
#define show(x) cout<<#x<<" "<<x<<" ";
#define f(i,j,k) for(int i = j;i<=k;i++)
#define fr(i,j,k) for(int i = j;i>=k;i--)
#define ll long long
#define all(A)  A.begin(),A.end()  
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL);  
const int MSIZE = 4e2+5;
const int MOD = 1e9+7;


int mat[25][25];
int dp[25][(int)1e7];

int solve(int i,int S,int &n) {
    if(i==n)    return 1;
    if(dp[i][S]!=-1)    return dp[i][S];
    int ans = 0;
    f(j,0,n-1) {
        if(mat[i][j] and !((S>>j)&1)) {
            ans+=solve(i+1,S|(1<<j),n);
            ans%=MOD;
        }
    }
    return dp[i][S] = ans;
}
int main(){

    FIO
    int n; cin>>n;
    f(i,0,n-1) f(j,0,n-1) cin>>mat[i][j];
    memset(dp,-1,sizeof(dp));
    cout<<solve(0,0,n)<<endl;
    return 0;

}
    


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

int main() {
  int N;
  cin >> N;
  vector<char> vec(N);
  for(int i=0; i<N; i++){
    cin >> vec.at(i);
  }
  
  string ans = "Three";
  
  for(int j=0; j<N; j++){
    if(vec.at(j) == 'Y'){
      ans = "Four";
      break;
    }
  }
  
  cout << ans << endl;
}

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

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int main(){
    int n;
    cin >> n;
    int num=n%10;
    if(num==3) cout << "bon" << endl;
    else if(num==0 || num==1 || num==6 || num==8) cout << "pon" << endl;
    else cout << "hon" << endl;
}

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

using namespace std;

typedef long long ll;

const ll MOD = 1000000007;
const int MAX = 1000001;

vector<int> factor(MAX, -1);

int init() {
  for (int i = 2; i < MAX; i++) {
    if (factor[i] > 0) continue;

    for (int j = i; j < MAX; j += i) {
      if (factor[j] < 0) {
        factor[j] = i;
      }
    }
  }
}

ll powm(ll p, int n) {
  if (n == 0) return 1;
  if (n == 1) return p;

  if (n % 2 == 0) {
    return powm((p * p) % MOD, n / 2) % MOD;
  } else {
    return (p * (powm((p * p) % MOD, (n - 1) / 2) % MOD)) % MOD;
  }
}

int main() {
  int N;

  init();

  cin >> N;

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

  map<int, int> mp;
  for (int i = 0; i < N; i++) {
    ll a = A[i];
    map<int, int> f;
    while (a > 1) {
      f[factor[a]] += 1;
      a /= factor[a];
    }

    for (auto p: f) {
      mp[p.first] = max(mp[p.first], p.second);
    }
  }

  ll lcm = 1;
  for (auto p: mp) {
    lcm *= powm(p.first, p.second);
    lcm %= MOD;
  }

  ll ans = 0;
  for (int i = 0; i < N; i++) {
    ll inv = powm(A[i], MOD - 2);
    ans += (lcm * inv) % MOD;
    ans %= MOD;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 4736
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
#include <numeric>
#include <functional>
#include <sstream>
#include <iostream>
#include <iomanip>
#define _USE_MATH_DEFINES
#include <cmath>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cfloat>
#include <cmath>
#include <ctime>
#include <cassert>
#include <cctype>
#include <cstdio>
#include <cassert>
using namespace std;

#define EPS 1e-12
#define ull unsigned long long
#define ll long long
#define VI vector<ll>
#define PII pair<ll, ll> 
#define VVI vector<vector<ll> >
#define VVVI vector<vector<vector<ll>>>
#define VVVVI vector<vector<vector<vector<ll>>>>
#define REP(i,n) for(ll i=0,_n=(n);(i)<(ll)_n;++i)
#define REPR(i,n) for(ll i=(ll)(n)-1;0<=(i);--i)
#define RANGE(i,a,b) for(ll i=(ll)a,_b=(ll)(b);(i)<_b;++i)
#define RANGER(i,a,b) for(ll i=(ll)(b)-1,_a=(ll)(a);(_a)<=i;--i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define ALLR(c) (c).rbegin(), (c).rend()
#define PB push_back
#define MP(a, b) make_pair(a, b)
#define POPCOUNT __builtin_popcount
#define POPCOUNTLL __builtin_popcountll
#define CLEAR(table, v) memset(table, v, sizeof(table));
#define UNIFORM_DOUBLE(a, b) (((b-a)*(double)rand()/RAND_MAX)+a) // [a, b) 
#define UNIFORM_LL(a, b) (ll)UNIFORM_DOUBLE(a, b) // [a, b) 
#define IN(v, lo, hi) ((lo)<=(v) && (v)<(hi))
#define DD(v) cout<<#v<<": "<<v<<endl
#define FI first
#define SE second
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const map<T0, T1>& v) { for( typename map<T0, T1>::const_iterator p = v.begin(); p!=v.end(); p++ ){os << p->first << ": " << p->second << " ";} return os; }
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const pair<T0, T1>& v) { os << v.first << ": " << v.second << " "; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<T>& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << " "; } return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const set<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const deque<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<vector<T> >& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << endl; } return os; }
template<typename T>void maxUpdate(T& a, T b) {a = max(a, b);}
template<typename T>void minUpdate(T& a, T b) {a = min(a, b);}
string YN(bool v) { return v ? "Yes":"No"; }
void uniq(VI& es) { sort(ALL(es)); es.erase(unique(ALL(es)), es.end()); }

#define INF (1LL<<60)

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll N;
	while(cin>>N) {
		VI A(N);
		REP(i, N) cin>>A[i];
		__int128 acc = 1;
		REP(i, N) {
			acc *= A[i];
			if(1000000000000000000LL<acc) {acc=-1;break;}
		}
		ll ans=acc;
		REP(i, N) if(A[i]==0) ans=0;
		cout<<ans<<endl;
	}
	
	return 0;
}


Measured memory_bytes: 3580
from fractions import gcd
def inverse(a):
    return pow(a, mod - 2, mod)


def usearch(x, a):
    lft = 0
    rgt = len(a) + 1
    while rgt - lft > 1:
        mid = (rgt + lft) // 2
        if a[mid] <= x:
            lft = mid
        else:
            rgt = mid
    return lft



def main():
    n = int(input())
    a=list(map(int, input().split()))
    a.sort()
    ans = 0
    for i in range(n):
        ans += a[-2*(i+1)]
    print(ans)
main()

Measured memory_bytes: 39140
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<cmath>
#include<math.h>
#include<algorithm>
#include<string.h>
#include <iomanip>
#include <sstream>
using namespace std;

int main() {
  int x1, x2,x3,x4,y1,y2,y3,y4;
  int ans = 0;
  int x12,y12;
  
  cin >> x1 >> y1 >> x2 >> y2;

  x12 = x2 -x1;
  y12 = y2 -y1;

  if(x12 == 0){
    //かんたんパターン
    if(y12 > 0){
        x3 = x2 - y12;
        y3 = y2 + x12;
        x4 = x3 - x12;
        y4 = y3 - y12;
    }else{
        x3 = x2 - y12;
        y3 = y2 + x12;
        x4 = x3 - x12;
        y4 = y3 - y12;
    }
  }else if(y12 == 0){
    //かんたんパターン2
    if(x12 > 0){
        x3 = x2 - y12;
        y3 = y2 + x12;
        x4 = x3 - x12;
        y4 = y3 - y12;
    }else{
        x3 = x2 - y12;
        y3 = y2 + x12;
        x4 = x3 - x12;
        y4 = y3 - y12;      
    }
  }else{
    if(x12 > 0){
      if(y12 > 0){
        //star1
        x3 = x2 - y12;
        y3 = y2 + x12;
        x4 = x3 - x12;
        y4 = y3 - y12;
      }else{
        //star4
        x3 = x2 - y12;
        y3 = y2 + x12;
        x4 = x3 - x12;
        y4 = y3 - y12;
      }
    }else{
      if(y12 < 0){
        //star3
        x3 = x2 - y12;
        y3 = y2 + x12;
        x4 = x3 - x12;
        y4 = y3 - y12;
      }else{
        //star2
        x3 = x2 - y12;
        y3 = y2 + x12;
        x4 = x3 - x12;
        y4 = y3 - y12;
      }
    }
  }

  cout << x3 << " " << y3 << " " ;
  cout << x4 << " " << y4 << endl;
}


Measured memory_bytes: 256
# https://atcoder.jp/contests/abc113/tasks/abc113_d
# あみだくじは, 日本に古くから伝わる伝統的なくじ引きである.
# あみだくじを作るには, まず W 本の平行な縦線を引き, 次にそれらを繋ぐ横線を引いていく.
# それぞれの縦棒の長さは H+1 [cm] であり、
# 横線の端点となれるのは上から 1,2,3,...,H [cm] の位置のみである.
# ここで,「正しいあみだくじ」とは, 以下のような条件を満たすあみだくじのことである.
# どの 2 つの横棒も端点を共有しない.
# それぞれの横棒の 2 つの端点は同じ高さになければならない.
# 横棒は隣り合う縦線を繋がなければならない.

# 縦棒 1 の上端から, 横線があれば必ずそれを通るというルールで下へたどったときに,
#  最終的にたどり着く縦棒の番号が K となるような「正しいあみだくじ」の本数を 1 000 000 007 で割った余りを求めなさい.
# H は 1 以上 100 以下の整数
# W は 1 以上 8 以下の整数
# K は 1 以上 W 以下の整数
# H W K
# 15 8 5
# 437760187
H, W, K = gets.split.map(&:to_i)

FIB = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89]
MOD = (10**9) + 7

def getc(a,b)
  # p "#{a} #{b} #{FIB[a] * FIB[W-b-1]}"
  FIB[a] * FIB[W-1-b]
end

dp = Array.new(H+1) { Array.new(W, 0) }
dp[0][0] = 1
1.step(H) do |h|
  W.times do |w|
    dp[h][w]   += (dp[h-1][w]%MOD * getc(w,   w))%MOD
    dp[h][w-1] += (dp[h-1][w]%MOD * getc(w-1, w))%MOD if w != 0
    dp[h][w+1] += (dp[h-1][w]%MOD * getc(w, w+1))%MOD if w != W-1
  end
end
p dp[H][K-1]%MOD

Measured memory_bytes: 1788
from collections import*
INF=10**18
h,w=map(int,input().split())
sh,sw=map(int,input().split())
gh,gw=map(int,input().split())
s=[input() for _ in range(h)]
q=deque([(sh-1,sw-1,0)])
d=[[INF]*w for _ in range(h)]
dx=[1,0,-1,0]
dy=[0,-1,0,1]
wx=[-2,-1,0,1,2]
wy=[-2,-1,0,1,2]
while q:
  x,y,c=q.popleft()
  if d[x][y]!=INF:continue
  d[x][y]=c
  for i,j in zip(dx,dy):
    nx=x+i
    ny=y+j
    if not(0<=nx<h and 0<=ny<w):continue
    if s[nx][ny]=='.' and d[nx][ny]==INF:
      q.appendleft((nx,ny,c))
  for i in wx:
    nx=x+i
    if not(0<=nx<h):continue
    for j in wy:
      ny=y+j
      if not(0<=ny<w):continue
      if s[nx][ny]=='.' and d[nx][ny]==INF:
        q.append((nx,ny,c+1))
print(d[gh-1][gw-1]if d[gh-1][gw-1]!=INF else -1)

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

using namespace std;
typedef long long ll;

#define FAST ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define mp make_pair
#define pb push_back
#define lp(i,s,f) for(ll i = s; i < ll(f); i++)
#define inF freopen("input.in", "r", stdin);
#define outF freopen("output.in", "w", stdout);
#define endl '\n'
#define MOD 1000000007
#define mm(arr) memset(arr, 0, sizeof(arr))
#define int ll

ll fastpow(int v,  int p){
    v %= MOD;
    if (p == 0)return 1;
    if (p == 1)return v%MOD;
    long long ans = fastpow(v, p/2)%MOD;
    long long res = (ans * ans)%MOD;
    if(p&1)res = (res * v)%MOD;
    return res;

}

int32_t main(){
    FAST
    int n; cin >> n;
    int ans = fastpow(10, n);
    ans -= (2 * fastpow(9, n))%MOD;
    if(ans < 0)ans += MOD;
    ans += fastpow(8, n);
    ans %= MOD;
    cout << ans;;
    return 0;
}


Measured memory_bytes: 3572
N,x = map(int,input().split())
A = list(map(int,input().split()))
A.sort()
k = 0; ans = 0
while A[k] <= x:
    ans += 1
    x -= A[k]
    if k+1 == N:
        A[k] = x+1
        if x > 0:
            ans -= 1
    else:
        k += 1
print(ans)

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

vector<int> G[200];
 
int main(){
    long long N;
    cin >> N;
    if(N%2 == 1){
        cout << 0 << endl;
        return 0;
    }
    N /= 2;
    long long res = 0;
    while(N){
        res += N / 5;
        N /= 5;
    }
    cout << res << endl;
 
    return 0;
}

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

using ll=long long;
#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 ALL(x) x.begin(),x.end()
#define REACH cerr<<"reached line "<<__LINE__<<endl
#define DBG(x) cerr<<"line "<<__LINE__<<" "<<#x<<":"<<x<<endl

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;
}

int read(){
	int i;
	scanf("%lld",&i);
	return i;
}

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

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

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

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

char* readCharArray(){
	static char buf[3341919];
	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(a>b)
		a=b;
}

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

const int inf=LLONG_MAX/3;

signed main(){
	int n=read();
	vi a;
	REP(i,n)
		a.PB(read());
	if(n==1){
		cout<<"YES"<<endl;
		return 0;
	}
	int sum=accumulate(ALL(a),0LL);
	if(sum%(n*(n+1)/2)){
		cout<<"NO"<<endl;
		return 0;
	}
	int k=sum/(n*(n+1)/2);
	vi c(n,0);
	REP(i,n){
		int j=(i+1)%n;
		int dif=a[j]-a[i];
		dif-=k;
		if(dif>0){
			cout<<"NO"<<endl;
			return 0;
		}
		c[i]=-dif;
		if(c[i]%n){
			cout<<"NO"<<endl;
			return 0;
		}
		c[i]/=n;
	}
	if(accumulate(ALL(c),0LL)==k)
		cout<<"YES"<<endl;
	else
		cout<<"NO"<<endl;
}


Measured memory_bytes: 2036
n,t = map(int,input().split())
a = [list(map(int,input().split())) for i in range(n)]
c = [i[0] for i in a]
tc = [i[1] for i in a]
ans = []
for i in tc:
  if i <= t:
    ans.append(tc.index(i))
if ans == []:
  print('TLE')
  exit()
b = []
for i in ans:
  b.append(c[i])
print(min(b))

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

int main() {
  
  int x, y;
  cin >> x >> y ;

  set<int> B;
  B.insert(4);
  B.insert(6);
  B.insert(9);
  B.insert(11);
  
  if (x == 2 || y == 2) {
    cout << "No" << endl;
  }
  else if (B.count(x) > 0 && B.count(y) > 0) {
    cout << "Yes" << endl;
  }
  else if (B.count(x) == 0 && B.count(y) == 0) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
  
  
return 0;
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
int a,b,c,a1,b1,c1,cnt=0;
int main(){
	scanf("%d%d%d",&a,&b,&c);
	if(a==b&&a==c&&b==c&&a%2==0&&b%2==0&&c%2==0){
		printf("-1");
	}else{
		while(1){
			if(a%2==1||b%2==1||c%2==1){
				printf("%d",cnt);
				break;
			}
			++cnt;
			a1=(b+c)/2;
			b1=(a+c)/2;
			c1=(a+b)/2;
			a=a1;
			b=b1;
			c=c1;
		}
	}
}

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

constexpr double eps = 1e-8;

int main() {
    int r, n;
    cout << fixed << setprecision(5);
    while(cin >> r >> n, r) {
        vector<double> v(2*r+1);
        vector<double> lh(2*r+1), rh(2*r+1), gh(2*r+1);
        for(int i=0; i<n; ++i) {
            int x1, x2;
            double h;
            cin >> x1 >> x2 >> h;
            for(int j=x1+r; j<=x2+r; ++j) {
                if(0 <= j && j < v.size()) {
                    if(j == x1+r) {
                        lh[j] = max(lh[j], h);
                    } else if(j == x2+r) {
                        rh[j] = max(rh[j], h);
                    } else {
                        gh[j] = max(gh[j], h);
                    }
                }
            }
        }
        for(int i=0; i<v.size(); ++i) {
            v[i] = max(gh[i], min(rh[i], lh[i]));
        }
        v[0] = v[2*r] = 100;
        //cout << endl;
        //for(int i=0; i<v.size(); ++i) {
        //    cout << "x = " << i-r << "   h = " << v[i] << endl;;
        //}
        //cout << "\n" << endl;
        double L = -r, R = 1000;
        for(int i=0; i<100; ++i) {
            double c = (L+R)/2;
            //cout << "(L, R) = " << L << " " << R << endl;
            bool ok = true;
            for(int i=0; i<v.size(); ++i) {
                if(r > sqrt((i-r)*(i-r) + (c-v[i])*(c-v[i])) + eps) {
                    ok = false;
                    break;
                } else if(c > v[i] + eps) {
                    ok = false;
                    break;
                }
            }
            if(ok) {
                L = c;
            } else {
                R = c;
            }
        }
        if(L + r < eps) {
            cout << 0 << endl;
        } else {
            cout << L + r << endl;
        }
    }
}


Measured memory_bytes: 3172
using System;
using System.Collections.Generic;
public class ABC142C {
    public static void Main() {
        long N;
        N = long.Parse(Console.ReadLine());
        List<int[]> A = new List<int[]>();
        string[] str = Console.ReadLine().Split(' ');
        for (int i = 0; i < str.Length; i++) {
            A.Add(new int[2] { int.Parse(str[i]), i + 1 });
        }

        A.Sort((a, b) => a[0] > b[0] ? 1 : (a[0] == b[0] ? 0: -1));

        for (int i = 0; i < A.Count; i ++) {
            Console.Write(A[i][1]);
            Console.Write(' ');
        }
    }
}

Measured memory_bytes: 28248
#include <iostream>
#include <cmath>
#include <climits>
#include <string>
#include <numeric>
#include <vector>
#include <queue>
#include <map>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <set>

using namespace std;
using ll = long long;

template<typename T> void print(T t) { cout << t << endl; }
ll MOD = 1000000007;

int main() {
	int X;
	cin >> X;
	print(X >= 30 ? "Yes" : "No");
}


Measured memory_bytes: 3612
n = int(input())
l = list(map(int, input().split()))

flag = 1
e = 0
while flag:
    flag = 0
    for j in range(n-1, 0, -1):
        if l[j] < l[j-1]:
            v = l[j]
            l[j] = l[j-1]
            l[j-1] = v
            flag = 1
            e += 1
print(*l)
print(e)


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

constexpr const int maxn = 1 << 20;
int vis[maxn];

int main() {
	vector<int> prime;
	for (int i = 2; i != maxn; ++i) if (!vis[i]) {
		prime.push_back(i);
		for (int j = i + i; j < maxn; j += i) vis[j] = 1;
	}
	long long a, b;
	cin >> a >> b;
	long long c = __gcd(a, b);
	int res = 0;
	for (int p : prime) if (c % p == 0) {
		++res;
		for (c /= p; c % p == 0; c /= p);
	}
	res += c == 1 ? 1 : 2;
	cout << res << endl;
}


Measured memory_bytes: 4988
import java.util.*;

class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		int N = sc.nextInt();
		int[] T = new int[N];
		for(int i = 0;i<N;i++) {
			T[i] = sc.nextInt();
		}
		int M = sc.nextInt();
		int[] P = new int[M];
		int[] X = new int[M];
			
		for(int i=0;i < M;i++){
			P[i] = sc.nextInt();
			X[i] = sc.nextInt();
		}

		for(int i=0;i<M;i++){
			int sum = 0;
			for(int j=0;j<N;j++){
				if(P[i] - 1 == j){
					sum += X[i];
				} else {
					sum += T[j];
				}
			}
			System.out.println(sum);
		}	
	}
}


Measured memory_bytes: 22996
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <cmath>

using namespace std;

#define REP(i,n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef pair<int, int> pint;

int main() {
  ll N ; cin>>N;
  ll ans = 0;
  for(ll x = 1; x * x <= N; x++) {
    ll y = N-x;
    if(y > 0) {
      ll m = y / x;
      if(N/m == N%m) {
        ans += m;
      }
    }
  }
  cout << ans << endl;
  return 0;
}


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

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<ll> vll;
// #define int long long
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000               // 2e9
#define LLINF 2000000000000000000ll  // 2e18 (llmax:9e18)
#define fi first
#define sec second
#define all(x) (x).begin(), (x).end()
#define sq(x) ((x) * (x))
#define dmp(x) cerr << #x << ": " << x << endl;

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

template <class T>
using MaxHeap = priority_queue<T>;
template <class T>
using MinHeap = priority_queue<T, vector<T>, greater<T>>;
template <class T>
vector<T> vect(int len, T elem) {
  return vector<T>(len, elem);
}

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << p.fi << ',' << p.sec;
  return os;
}
template <class T, class U>
istream &operator>>(istream &is, pair<T, U> &p) {
  is >> p.fi >> p.sec;
  return is;
}
template <class T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
  for (int i = 0; i < vec.size(); i++) {
    os << vec[i];
    if (i + 1 < vec.size()) os << ' ';
  }
  return os;
}
template <class T>
istream &operator>>(istream &is, vector<T> &vec) {
  for (int i = 0; i < vec.size(); i++) is >> vec[i];
  return is;
}
void fastio() {
  cin.tie(0);
  ios::sync_with_stdio(0);
  cout << fixed << setprecision(20);
}

struct UnionFind {
  vector<int> par, rank, sz;
  UnionFind(int n) {
    par.assign(n, 0);
    rank.assign(n, 0);
    sz.assign(n, 1);
    for (int i = 0; i < n; i++) { par[i] = i; }
  }
  int find(int x) {
    if (par[x] == x)
      return x;
    else
      return par[x] = find(par[x]);
  }
  void unite(int x, int y) {
    x = find(x);
    y = find(y);
    if (x == y) return;
    if (rank[x] < rank[y]) {
      par[x] = y;
      sz[y] += sz[x];
    } else {
      par[y] = x;
      sz[x] += sz[y];
      if (rank[x] == rank[y]) rank[x]++;
    }
  }
  bool same(int x, int y) { return find(x) == find(y); }
};

#define endl "\n"

void solve() {
  int N, K, L;
  cin >> N >> K >> L;
  UnionFind uf1(N), uf2(N);
  for (int i = 0; i < K; i++) {
    int p, q;
    cin >> p >> q;
    p--;
    q--;
    uf1.unite(p, q);
  }
  for (int i = 0; i < L; i++) {
    int p, q;
    cin >> p >> q;
    p--;
    q--;
    uf2.unite(p, q);
  }
  map<P, int> m;
  for (int i = 0; i < N; i++) {
    int a = uf1.find(i);
    int b = uf2.find(i);
    m[P(a, b)]++;
  }
  vector<int> ans(N);
  for (int i = 0; i < N; i++) {
    int a = uf1.find(i);
    int b = uf2.find(i);
    ans[i] = m[P(a, b)];
  }
  cout << ans << endl;
  return;
}

signed main() {
  fastio();
  solve();
  // int t; cin >> t; while(t--)solve();
  return 0;
}


Measured memory_bytes: 17408