akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define dup(x,y) (((x)+(y)-1)/(y))
#define v(T) vector<T>
#define vv(T) v(v(T))
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<pii> vp;
inline int getInt() { int x; scanf("%d",&x); return x;}
template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>inline ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MX = 200005;
#define M 1000000007
//---------------------------------------------------------------
#define fastio cin.tie(nullptr); std::ios::sync_with_stdio(false);
#define myio ifstream iofi; if(argc>1){iofi.open(argv[1]); std::cin.rdbuf(iofi.rdbuf());}
#define myloopset int loop = 1; if(argc>2) loop =stoi(argv[2]); rep(i,loop)

//--------------------------------------------------------------

void Main(){
  vl c(4);
  cin>>c;
  ll n;
  cin>>n;
  ll b1 = c[2] ,b2 = c[3];
  mins(b1,c[0]*4);
  mins(b1,c[1]*2);
  mins(b2,b1*2);
  cout<<(n/2)*b2+(n%2)*b1<<endl;

} int main(int argc,char** argv)
{fastio; myio; myloopset Main();}


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

int main()
{
	int N, M;
	cin >> N >> M;
	int sum = 0;
	for (int i = 0; i < M; ++i) {
		int tmp;
		cin >> tmp;
		sum += tmp;
	}
	if (N >= sum) cout << N - sum << endl;
	else cout << -1 << endl;
}

Measured memory_bytes: 3168
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

int64_t euclid(int64_t a, int64_t b) {
    if (b == 0) {
        return a;
    }
    return euclid(b, a%b);
}


int main(int argc, char** argv) {
    int n;
    cin >> n;
    std::vector<int64_t> a(n), l(n), r(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    l[0]=a[0];
    r[n-1]=a[n-1];
    for (int i = 1; i < n; ++i) {
        l[i] = euclid(l[i-1], a[i]);
    }
    for (int i = n-2; i >= 0; --i) {
        r[i] = euclid(r[i+1], a[i]);
    }
    int64_t ans{0};
    for (int i = 0; i < n; ++i) {
        int64_t gcd{0};
        if (i==0) gcd = r[1];
        else if (i==n-1) gcd = l[n-2];
        else gcd = euclid(l[i-1], r[i+1]);

        ans = max(ans, gcd);
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 2560
import sys
readline = sys.stdin.readline

N = int(readline())
A = list(map(int,readline().split()))

from functools import reduce

import math

alls = reduce(math.gcd, A)

if alls != 1:
  print("not coprime")
  exit(0)
  
# 素因数のペアが存在するかを探す
facts = [False] * (10 ** 6 + 1)

def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

for a in A:
  cur = factorization(a)
  for f in cur:
    if f[0] != 1 and facts[f[0]]:
      print("setwise coprime")
      exit(0)
    else:
      facts[f[0]] = True
else:
  print("pairwise coprime")


Measured memory_bytes: 175336
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int len = scanner.nextInt();
		Cards input[] = new Cards[len];
		int count = 0;
		Main main = new Main();

		for (int i = 0; i < len; i++) {
			input[i] 		= main.new Cards();
			input[i].suits 	= scanner.next();
			input[i].num 	= Integer.parseInt(input[i].suits.substring(1));
		}
		Cards buble[] = new Cards[len];
		System.arraycopy(input, 0, buble, 0, input.length);
		
		//buble sort
		for (int i = 0; i < buble.length; i++) {
			for (int j = 1; j < buble.length; j++) {
				if (buble[j-1].num > buble[j].num) {
					Cards tmp = buble[j-1];
					buble[j-1] = buble[j];
					buble[j] = tmp;
				}
			}
		}
		new Main().arrayToString(buble);
		System.out.println("Stable");
		
		Cards select[] = new Cards[len];
		System.arraycopy(input, 0, select, 0, input.length);
		
		//selection sort
		for (int i = 0; i < select.length; i++) {
			int minIdx = i;
			for (int j = i+1; j < select.length; j++) {
				if(select[j].num < select[minIdx].num) {
					minIdx = j; 					
				}
			}
			if(minIdx != i) {
				Cards tmp = select[i];
				select[i] = select[minIdx];
				select[minIdx] = tmp;
			}
		}
		new Main().arrayToString(select);
		
		Boolean isSame = true;
		for (int i = 0; i < select.length; i++) {
			if(select[i].suits != buble[i].suits) {
				isSame = false;
			}
		}
		if (isSame) {
			System.out.println("Stable");
		}else {
			System.out.println("Not stable");
		}
	}

	public void arrayToString(Cards[] arr) {
		for (int i = 0; i < arr.length; i++) {
			if (i == arr.length - 1) {
				System.out.println(arr[i].suits);
			} else {
				System.out.print(arr[i].suits + " ");
			}
		}
	}
	
	class Cards{
		int num;
		String suits;
	}
	
	public void isStable() {
		
		System.out.println();
	}
	
//	public Map<String, Integer> heartsToNum(String[]	hearts ) {
//		Map<String, Integer> retMap = new HashMap<>();
//		for (int i = 0; i < hearts.length; i++) {
//			int	num  = 	Integer.parseInt(hearts[i].substring(1, 1));
//			retMap.put(hearts[i], num);
//		}
//		return retMap;
//	}

}


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

int main(){
  int n;
  cin >> n;
  long long line[n];
  for(int i =0;i<n;i++){
    cin >> line[i];
  }
  int ans = 0;
  for(int i=0;i<n-2;i++){
    for(int j=i+1;j<n-1;j++){
      for(int k = j+1;k<n;k++){
        if(line[i]!=line[j] && line[j]!=line[k] && line[i] != line[k]){
          if(line[i]+line[j]>line[k] && line[i]+line[k]>line[j] && line[k]+line[j]>line[i]){
            //cout << i<< j << k << endl;
            ans++;
          }
        }
      }
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 3624
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <set>
#include <algorithm>
#include <array>
#include <complex>
#include <string>
#include <utility>
#include <map>
#include <queue>
#include <list>
#include <functional>
#include <numeric>
#include <stack>
#include <tuple>

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


int dx[4] = { -1,0,1,0 };
int dy[4] = { 0,1,0,-1 };
const int INF = 100000000;
const long long LINF = 1LL << 60;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-6;
using pii = std::pair<int, int>;
using pLL = std::pair<long long, long long>;
using ll = long long;
#define SORT(v) std::sort(v.begin(), v.end())
#define rSORT(v) std::sort(v.begin(), v.end(),std::greater<int>())

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<int> x(N);
    for (int i = 0; i < N; ++i) {
        cin >> x[i];
    }
    int ans = 1;
    for (int i = 1; i < N; ++i) {
        bool watch = true;
        for (int j = 0; j < i; ++j) {
            if (x[i] < x[j]) watch=false;
        }
        if (watch != false) ans++;
    }
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <cmath>
using namespace std;
using ll = long long;

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

    cout << min((n + h - 1) / h, (n + w - 1) / w) << endl;

    return 0;
}

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

int main () {
    int N, K; cin >> N >> K;
    vector<int> A(N);
    vector<int> S(N+1, 0);
    int a; cin >> a; a--;
    S[0] = a % K;
    for (int i = 1; i < N; i++) {
        int a; cin >> a; a--;
        S[i] = (S[i - 1] + a) % K;
    }
    long long ans = 0;
    int t = 1;
    map<int, int> m{};
    m[0] = 1;
    if (N < K) {
        for (int i = 0; i < N; i++) {
            ans += m[S[i]];
            m[S[i]] += 1;
        }
    } else {
        for (int i = 0; i < K - 1; i++) {
        ans += m[S[i]];
        m[S[i]] += 1;
        }
        m[0]--;
        for (int i = K - 1; i < N; i++) {
            ans += m[S[i]];
            m[S[i]] += 1;
            m[S[i - (K - 1)]] -= 1;
        }
    }
    std::cout << ans << endl;
}

Measured memory_bytes: 11136
n, k = list(map(int, input().split()))

a = list(map(int, input().split()))


dp = [0]*(k + 1)

for i in range(1, k + 1):
    for move in a:
        if i - move >= 0:
            if dp[i - move] == 0:
                dp[i] = 1


if dp[i] == 1:
    print("First")

else:
    print("Second")

Measured memory_bytes: 3828
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
	char s[100];
	scanf("%s",s);
	int n=strlen(s);
	int gg=s[n-1]-'0';
	if(gg==2||gg==4||gg==5||gg==7||gg==9)
	{
		cout<<"hon"<<endl;
	}else if(gg==0||gg==1||gg==6||gg==8){
		cout<<"pon"<<endl;
	}else if(gg==3){
		cout<<"bon"<<endl;
	}
	
 	return 0;
}

Measured memory_bytes: 3764
import java.util.*;
class Main {
 public static void main (String[] args) throws java.lang.Exception {
  Scanner sc = new Scanner(System.in);
  int a, c = 0;
  while(true) {
   a = sc.nextInt();
   if(a == 0) break;
   System.out.println("Case " + (++c) + ": " + a);
  }
 }
}


Measured memory_bytes: 41244
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
typedef long long i64;
int main(){
  int N;
  cin >> N;
  int count=0;
  int prev=-1;
  rep(i,N){
    int a;
    cin >> a;
    if(prev==a){
      count++;
      prev=-1;
    }else{
      prev=a;
    }
  }
  cout << count << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define debug(x) cout << '>' << #x << ':' << x << endl;
char arr[60][60];
int ans[60][60];
int main() {
	int n, m;
	scanf("%d%d", &n, &m);
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			cin >> arr[i][j];
		}
	}
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			if (arr[i][j] == '.')
				for (int k = -1; k <= 1; k++) {
					for (int l = -1; l <= 1; l++) {
						if (i + k >= 0 && i + k < n && j + l >= 0 && j + l < m)
							if (arr[i + k][j + l] == '#')
								ans[i][j]++;
					}
				}

		}
	}

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			if (arr[i][j] == '#')
				cout << arr[i][j];
			else
				cout << ans[i][j];
		}
		printf("\n");
	}
}



Measured memory_bytes: 3736
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<limits.h>

int max(int a, int b){
  return a >= b ? a : b;
}
int min(int a, int b){
  return b >= a ? a : b;
}
int sei(int a){
  return a>0 ? a : 0;
}
int factorial(int n) {
    if (n > 0) return n*factorial(n - 1);
		else return 1;
}
int compare_up_int(const void *a, const void *b){
   return *(int*)a - *(int*)b;
}
int compare_down_int(const void *a, const void *b){
   return *(int*)b - *(int*)a;
}
int euclid(int a, int b){
  if(a < b){int tmp = a;a = b;b = tmp;}
  int r = a % b;
  if(r < 0) r += b;
  while(r != 0){
    a = b;b = r;r = a % b;
    if(r < 0) r += b;
  }
  return b;
}

int main(){
  int N,A;
  scanf("%d",&N);
  scanf("%d",&A);
  if(N%500<=A)printf("Yes");
  else printf("No");
  return 0;
}


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

int main(){
  int N,W;
  cin >> N >> W;

  vector<pair<int, int64_t>> data(N);
  int buf_w;
  int64_t buf_v;
  for(int i=0; i<N; i++){
    cin >> buf_w >> buf_v;
    data.at(i)= make_pair(buf_w, buf_v);
  }

  vector<int64_t> dp(W+1);
  for(auto [weight, value]:data){
    for(int w=W; w>= weight; w--){
      dp.at(w)= max(dp.at(w), dp.at(w- weight)+ value);
    }
  }

  cout << dp.at(W) << endl;
}

Measured memory_bytes: 3948
def main():
    n = int(input())
    s=[]
    for i in range(n):
        s.append(input())
    # print(s)
    s.sort()
    stemp = s[0]
    ans = []
    cnt =1
    # print(s)
    for i in range(1,n):
        if stemp == s[i]:
            cnt += 1
            continue
        else:
            ans.append([cnt, stemp])
            cnt = 1
            stemp = s[i]
    ans.append([cnt, stemp])
    ans.sort()
    aa = []
    if len(ans) != 1:
        temp = ans[-1][0]
        aa.append(ans[-1][1])
    else:
        print(ans[0][1])
        return


    for i in range(2,n+1):
        if ans[-i][0] == temp:
            aa.append(ans[-i][1])
        else:
            break
    aa.sort()
    for i, ss in enumerate(aa):
        print(ss)

if __name__=='__main__':
    main()


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

//#define DEBUG

using namespace std;

template <class T>
void print_vect(std::vector<T> v){
    for(int i = 0 ; i < v .size(); i++) cout << v[i] << " ";
    cout << endl;
}


void solve(){
    uint32_t N ;
    cin >> N;
    std::vector<uint32_t> A;
    A.reserve(N);
    for(uint32_t i = 0; i < N ;i++){
        uint32_t a;
        cin >> a;
        A.push_back(a);
    }
    uint32_t all_xor = 0;
    for(int i = 0 ; i < N ; i++){
        all_xor = all_xor ^ A[i];
    }
    for(int i = 0 ; i < N ; i++){
        uint32_t val = all_xor ^ A[i];
        cout << val << endl;
    }
}

int main()
{
    //making data IO Fast
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(NULL);
    /****************************/

    #ifdef DEBUG
    int TEST_CASES = 4;
    while(TEST_CASES--){
    #endif // DEBBUG

    solve();

    #ifdef DEBUG
    }
    #endif // DEBUG
    
    return 0;
}


Measured memory_bytes: 3972
#map(int,input().split())
#int(x) for x in input().split()
#for _ in range(int(input())):
k,n=map(int,input().split())
p=[int(x) for x in input().split()]
if n==0:
	print(k)
else:
	diff=500
	ans=0
	for i in range(0,105):
		if i not in p:
			if diff>abs(k-i):
				diff=abs(k-i)
				ans=i
	print(ans)





Measured memory_bytes: 61724
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1000000007;
#define INF 1LL<<30
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()

int main(){
    int h,w;
    cin>>h>>w;
    int c[10][10];
    rep(i,10) rep(j,10) cin>>c[i][j];
    rep(k,10){
        rep(i,10){
            rep(j,10){
                c[i][j]=min(c[i][j],c[i][k]+c[k][j]);
            }
        }
    }
    int ans=0;
    rep(i,h){
        rep(j,w){
            int a;
            cin>>a;
            if(a==-1) continue;
            ans+=c[a][1];
        }
    }

    cout<<ans<<endl;
}


 

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <cassert>
#include <memory>
#include <stack>
#include <set>
#include <map>
#include <tuple>

#define MAX_SIZE 100000000
typedef long long ll;
typedef unsigned long long ull;
using namespace std;

int main() {
  string s; cin>>s;
  int cnt = count(s.begin(), s.end(), '1');
  cout << cnt << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
int main()
{
	int i;
	char str[25];
	
	fscanf(stdin, "%s", str);
	
	for(i = strlen(str)-1; i >= 0; i--)
		printf("%c", str[i]);
	puts("");
	
	return 0;
}

Measured memory_bytes: 524
#include<bits/stdc++.h>
using namespace std;
int main(){
    string s;
    int n;
    cin >> n >> s;
    for(int i=0;i<s.length();i++){
        int x=s[i]-'A';
        x=(x+n)%26;
        putchar('A'+x);
    }
    return 0;
}

Measured memory_bytes: 256
import numpy as np

lenA, lenB, M = map(int, input().split())

A = np.array(list(map(int, input().split())))
B = np.array(list(map(int, input().split())))
X = np.zeros((M, 3), dtype=int)

for i in range(M):
    X[i] = list(map(int, input().split()))

ans = min(A) + min(B)

for xi in X:
    tmp = A[xi[0] - 1] + B[xi[1] - 1] - xi[2]
    ans = min(ans, tmp)

print(ans)

Measured memory_bytes: 39396
import math
N = int(input())
#sum_ = 1+N
sum_ = 0
for i in range(1, 1+N):
    for j in range(1, 1+N):
        a = math.gcd(i, j)
        for k in range(1, 1+N):
            sum_ += math.gcd(a, k)
            
print(sum_)

Measured memory_bytes: 9140
import std.stdio;
import std.conv, std.array, std.algorithm, std.string;
import std.math, std.random, std.range, std.datetime;
import std.bigint;
import std.container;
string read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }

void main(){
	int n = read.to!int;
	
	int[] ss;
	foreach(i; 0 .. n) ss ~= read.to!int;
	
	int sum = ss.reduce!"a + b"();
	
	int ans;
	if(sum % 10 != 0) ans = sum;
	else{
		int m = sum;
		foreach(s; ss){
			if(s < m && (sum - s) % 10 != 0) m = s;
			}
		ans = sum - m;
		}
	
	ans.writeln;
	
	}

Measured memory_bytes: 256
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <limits>
#include <vector>

long count(
    int k,
    const std::vector<int>& positions,
    std::vector<int>& values,
    int start)
{
  auto location = positions[start] - 1;
  long sum = values[location];
  long result = sum;
  int count = 1;
  for (; count < k && location != start; ++count) {
    location = positions[location] - 1;
    sum += values[location];
    result = std::max(result, sum);
  }
  if (count >= k) return result;

  const auto rem = k % count;
  sum = sum > 0 ? sum * (k / count - 1) : 0;
  result = std::numeric_limits<long>::min();
  for (int i = 0; i < count + rem; ++i) {
    location = positions[location] - 1;
    sum += values[location];
    result = std::max(result, sum);
  }
  return result;
}

long solve(
    int n,
    int k,
    const std::vector<int>& positions,
    std::vector<int>& values)
{
  long result = std::numeric_limits<long>::min();
  for (int i = 0; i < n; ++i) {
    result = std::max(result, count(k, positions, values, i));
  }
  return result;
}

int main()
{
  int n, k;
  std::cin >> n >> k;
  std::vector<int> positions(n);
  std::vector<int> values(n);
  for (auto& p : positions) {
    std::cin >> p;
  }
  for (auto& v : values) {
    std::cin >> v;
  }

  std::cout << std::setprecision(20);
  std::cout << solve(n, k, positions, values) << std::endl;
}


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

int main()
{
  int N; cin >> N;
  vector<int> P(N + 2, -1);
  for (int i = 0; i < N; i++) cin >> P[i + 1];
  vector<int> Lx(N + 1, 1), Rx(N + 1, 1);

  vector<int> Q(N + 1);
  for (int i = 1; i <= N; i++)
  {
    Q[P[i]] = i;
  }
  long long ans = 0;
  for (int i = 1; i <= N; i++)
  {
    int now = Q[i];
    int L = now - Lx[now];
    int R = now + Rx[now];

    if (P[L] != -1) {
      int L2 = L - Lx[L];
      ans += (long long)i * (L - L2) * (R - now);
    }

    if (P[R] != -1) {
      int R2 = R + Rx[R];
      ans += (long long)i * (now - L) * (R2 - R);
    }

    if (P[L] != -1) Rx[L] += Rx[now];
    if (P[R] != -1) Lx[R] += Lx[now];
  }
  cout << ans << endl;
}

Measured memory_bytes: 1792
N = int(input())
A = list(map(int, input().split()))

C = {}

for i in range(N):
  if not A[i] in C:
    C[A[i]] = 1
  else:
    C[A[i]] += 1

ans = 0
count = 0
for key, value in C.items():
  ans += 1
  if(value % 2 == 0):
    count += 1

if(count % 2 == 0):
  print(ans)
else:
  print(ans-1)


Measured memory_bytes: 18272
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define USE_LLONG_AS_INT
#ifdef USE_LLONG_AS_INT
#define int long long
#define inf (1ll<<60)
#else
#define inf (1<<30)
#endif
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define Yes(f) cout<<(f?"Yes":"No")<<endl
#define yes(f) cout<<(f?"yes":"no")<<endl
#define YES(f) cout<<(f?"YES":"NO")<<endl
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v), greater<int>())

using namespace std;

const int mod=1e9+7;
const string sp=" ";

void run();

void init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(12);
}

signed main(){
    init();
    run();
    return 0;
}

void run(){
    int n;
    cin>>n;
    vector<double> x(n),y(n);
    rep(i,n)cin>>x[i]>>y[i];
    vi a(n);
    iota(all(a),0);
    double ans=0;
    do{
        rep(i,n-1){
            ans+=hypot(x[a[i]]-x[a[i+1]],y[a[i]]-y[a[i+1]]);
        }
    }while(next_permutation(all(a)));
    int m=1;
    REP(i,1,n)m*=i;
    cout<<ans/m<<endl;
}

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

int main()
{
	int i, N, P[9], Q[9];
	scanf("%d", &N);
	for (i = 1; i <= N; i++) scanf("%d", &(P[i]));
	for (i = 1; i <= N; i++) scanf("%d", &(Q[i]));
	
	int j, p = 1, q = 1, fact = 1;
	for (i = 1; i <= N - 1; i++) fact *= i;
	for (i = 1; i <= N - 1; i++) {
		p += (P[i] - 1) * fact;
		q += (Q[i] - 1) * fact;
		for (j = i + 1; j <= N; j++) {
			if (P[j] > P[i]) P[j]--;
			if (Q[j] > Q[i]) Q[j]--;
		}
		fact /= N - i;
	}
	
	printf("%d\n", abs(p - q));
	fflush(stdout);
	return 0;
}

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

#define REP(i, n) for(int i = 0;i < (int)(n);i++)

int main() {
  REP(i, 5) {
    int x;
    cin >> x;
    if (x == 0) cout << i + 1 << endl;
  }
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define rrep(i,a,b) for(int i=(a);i>=(b);--i)
#define fore(i,a) for(auto &i:a)
#define all(a) (a).begin(),(a).end()
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
using ll = long long; constexpr int inf = INT_MAX / 2; constexpr ll infl = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }

void _main() {
  int N, Q;
  string S;
  cin >> N >> Q >> S;
  vector<int> l(Q);
  vector<int> r(Q);
  rep(i, 0, Q) cin >> l[i] >> r[i];

  set<int> ci_set;
  vector<int> sum(N, 0);
  if (S[0] == 'A' && S[1] == 'C') {
    sum[0] = 1;
    ci_set.insert(0);
  }
  rep(i, 2, N) {
    if (S[i-1] == 'A' && S[i] == 'C') {
      sum[i-1] = sum[i-2] + 1;
      ci_set.insert(i-1);
    } else {
      sum[i-1] = sum[i-2];
    }
  }
  sum[N-1] = sum[N-2];

  vector<int> ans(Q);
  rep(i, 0, Q) {
    int t = sum[r[i]-1] - sum[l[i]-2];
    if (ci_set.count(r[i]-1) == 1) --t;
    ans[i] = t;
  }

  fore(x, ans) cout << x << endl;
}

Measured memory_bytes: 4816
import sys
from collections import defaultdict

mod = 10 ** 9 + 7


def factorization(n):
    """ n の素因数分解

    Args:
        n (int): [description]

    Returns:
        [type]: [description]
    """

    arr = []
    tmp = n
    for i in range(2, int(-(-n**0.5 // 1)) + 1):  # sqrt(n) まで
        # i で割れるだけ割る、を繰り返す
        if tmp % i == 0:
            cnt = 0
            while tmp % i == 0:
                cnt += 1
                tmp //= i
            arr.append([i, cnt])  # 結果を追加

    if tmp != 1:
        arr.append([tmp, 1])  # まだ余っていれば追加しておく

    if arr == []:
        arr.append([n, 1])  # このブロック、必要か？

    return arr


def main():

    N = int(sys.stdin.readline().rstrip())
    A = [int(x) for x in sys.stdin.readline().rstrip().split()]

    # 最小公倍数を作る
    p = defaultdict(int)  # p に 因数 : 指数 でもたせる
    for a in A:
        for x, y in factorization(a):
            p[x] = max(p[x], y)

    # 一旦、全部の掛け合わせを作る
    U = 1
    for x, y in p.items():
        U = (U * pow(x, y, mod)) % mod

    # 足す
    ans = 0
    for a in A:
        ans = (ans + U * pow(a, mod - 2, mod)) % mod  # 逆元を

    print(ans)


main()

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


int main()
{
	int N;
	cin>>N;
	map<int,int> m;
	ll ans=0;
	rep(i,N)
	{
		int a;
		cin>>a;
		m[a]++;
		ans+=a;
	}
	int Q;
	cin>>Q;
	rep(i,Q)
	{
		int b,c;
		cin>>b>>c;
		int n=m[b];
		m[b]=0;
		m[c]+=n;
		ans+=(c-b)*n;
		cout<<ans<<endl;
	}
	return 0;
}


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

using namespace std;

typedef long long ll;

const ll MOD = 1e9 + 7;

int N;
string s;
vector<ll> dp, pp;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> N >> s;
    dp.resize(N);
    dp[0] = 1;
    for (int i = N - 2; i >= 0; i--) {
        pp.assign(N + 1, 0);
        for (int j = 0; j < N; j++)
            pp[j + 1] = (pp[j] + dp[j]) % MOD;
        dp.assign(N, 0);
        for (int j = 0; j < N - i; j++)
            dp[j] = s[i] == '<' ? (pp[N] - pp[j] + MOD) % MOD : pp[j];
    }
    ll result = 0;
    for (ll x : dp)
        result = (result + x) % MOD;
    cout << result << endl;
}


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

string divide[4] = {"dream", "dreamer", "erase", "eraser"};

int main (){
    string S;
    cin >> S;

    reverse(S.begin(), S.end());
    for (int i=0; i<4; i++) reverse(divide[i].begin(), divide[i].end());

    bool can = true;
    for (int i=0; i<S.size();) {
        bool can2 = false;
        for (int j=0; j<4; j++) {
            string d = divide[j];
            if (S.substr(i, d.size()) == d) {
                can2 = true;
                i += d.size();
            }
        }
        if (!can2) {
            can = false;
            break;
        }
    }

    if(can) cout << "YES" << endl;
    else cout << "NO" << endl;
}

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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(a)     (a).begin(),(a).end()
#define MOD 1000000007

typedef long long int ll;

const ll INF=(ll)1e19;
//const int INF=(1<<30);


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

  vector<int> x(N);
  vector<int> y(N);

  REP(i,N){
    int t;
    scanf("%d", &t);
    x[i] = y[i] = t;;
  }
  sort(ALL(y));

  REP(i,N){
    if(x[i]<=y[N/2-1]){
      printf("%d\n",y[N/2]);
    }else{
      printf("%d\n",y[N/2-1]);
    }
  }

}



Measured memory_bytes: 3712
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii; 
const int N = 2e5+10, mod = 1e9+7;

void solve() {
    int n, m, k; cin >> n >> m >> k; 

    ll a[n + 1], b[m + 1]; 
    a[0] = 0, b[0] = 0;

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

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

    int ans = 0; int j = m;
    for (int i = 0; i <= n && a[i] <= k; ++i) {
        while (a[i] + b[j] > k) {
            --j;
        }

        ans = max(ans, i + j);
    }

    cout << ans << endl;
}

int main(void) {
    int t = 1; 
    while (t--) solve();
    return 0;
}

Measured memory_bytes: 6724
for _ in range(input()):
	asset = ans = input()
	year = input()
	n = input()
	for i in range(n):
		plan,rate,cost = map(float,raw_input().split())
		if plan == 0.0:
			ans = max(ans,sum(int(rate*(asset - y*cost)) for y in range(year)) + asset - year*cost)
		else:
			cur = asset
			for y in range(year):
				cur = int(cur*(1 + rate) - cost)
			ans = max(ans,cur)
	print int(ans)

Measured memory_bytes: 4256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

int d[200][200];
const int INF = 123456789;

int main()
{
    int n,m,R;
    cin >>n >>m >>R;
    vector<int> r(R);
    rep(i,R)
    {
        cin >>r[i];
        --r[i];
    }
    sort(all(r));

    fill(d[0],d[200],INF);
    rep(i,n) d[i][i] = 0;
    rep(i,m)
    {
        int a,b,c;
        cin >>a >>b >>c;
        --a;
        --b;
        d[a][b] = d[b][a] = c;
    }

    rep(k,n)rep(i,n)rep(j,n) d[i][j] = min(d[i][j],d[i][k]+d[k][j]);

    int ans = INF;
    do {
        int t = 0;
        rep(i,R-1) t+=d[r[i]][r[i+1]];
        ans = min(ans,t);
    } while(next_permutation(all(r)));
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

ll dp[200];

int main() {
    int l, k;
    cin >> l >> k;

    dp[1] = 1;
    dp[k] = 1;
    REP(i,l){
        dp[i+2] += dp[i];
        dp[i+k+1] += dp[i];
    }

    ll ans = 0;
    FOR(i,1,l) ans += dp[i];
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3100
#include<iostream>
#include<string>
#include<algorithm>
#include<bits/stdc++.h>
#include<iomanip>
using namespace std;

int MOD=1000000007;

int main()
{
 long long N,ans=0;
 cin >> N;
 long long C[N+10]={},S[N+10]{},F[N+10]={};
 for(long long i=0; i<N-1; i++){ cin >> C[i] >> S[i] >> F[i]; }
 for(long long j=1; j<N; j++){
   ans+=S[j-1]+C[j-1];
 for(long long i=j; i<N-1; i++){
   if(ans%F[i]==0 && ans>S[i]) ans+=C[i];
   else if(ans<S[i]) ans=S[i]+C[i];
   else ans+=(F[i]-ans%F[i])+C[i];
 }
 cout << ans << endl;
 ans=0;
 }
 cout << 0 << endl;
}



Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String data[] = sc.nextLine().split("/",0);

		data[0] = "2018";

		System.out.println(data[0] + "/" + data[1] + "/" + data[2]);
	}
}


Measured memory_bytes: 21844
using System;
using System.Linq;

namespace AtCoder
{
    class Abc160C
    {
        public static void Main()
        {
            var kn = Console.ReadLine().Split(' ').Select(s => int.Parse(s));
            int k = kn.First();
            int n = kn.Last();

            var a = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();

            int max = a[0] + k - a[n - 1];

            for (int i = 0; i < n - 1; i++)
            {
                var d = a[i + 1] - a[i];
                if (max < d)
                    max = d;
            }
            Console.WriteLine(k - max);
        }
    }
}


Measured memory_bytes: 34780
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  ll a, b, k;
  cin >> a >> b >> k;
  if(k > a ) {
    k -= a, a = 0;
    if( k > b ) b = 0; else b -= k; 
  }
  else {
    a -= k;
  }
  cout << a << " " << b ;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
int n,cnt[1000010],k,ans;
vector<int> G[1000010];
const int MOD=1000000007;
void DFS(int x,int fa,int can){
	bool flag=false;
	if(can>=k-1)can--;
	int nex=can;
	for(int i=0;i<G[x].size();i++){
		int t=G[x][i];
		if(t==fa)continue;
		if(flag)nex--;
		cnt[t]=nex;
		DFS(t,x,can);
		flag=true;
	}
}
signed main(){
	scanf("%lld %lld",&n,&k);
	for(int i=1;i<=n-1;i++){
		int a,b;
		scanf("%lld %lld",&a,&b);
		G[a].push_back(b);
		G[b].push_back(a);
	}
	cnt[1]=k;
	DFS(1,0,k);
	ans=1;
	for(int i=1;i<=n;i++)ans*=cnt[i],ans%=MOD;
	cout<<ans;
	return 0;
}

Measured memory_bytes: 33792
#include<bits/stdc++.h>
#define int long long
#define ii pair<int,int>
#define fi first
#define se second
using namespace std;

int h,w,n;
vector<ii> cor;
map<ii,int> num;
int arr[10];

main() {
	cin>>h>>w>>n;
	memset(arr,0,sizeof(arr));
	while(n--) {
		int a,b;	cin>>a>>b;
		for(int k = 0 ; k <= 2 ; k++) {
			for(int j = 0 ; j <= 2 ; j++) {
				if(3<=a+k && a+k<=h && 3<=b+j && b+j<=w) {
					if(!num.count(ii(a+k,b+j))) {
						num[ii(a+k,b+j)]=1;
						arr[num[ii(a+k,b+j)]]++;
					}
					else {
						arr[num[ii(a+k,b+j)]]-=1;
						arr[num[ii(a+k,b+j)]+1]++;
						num[ii(a+k,b+j)]++;
					}
				}
			}
		}
	}
	arr[0] = (h-2)*(w-2);
	for(int i=1;i<=9;i++) arr[0] -= arr[i];
	for(int i=0;i<=9;i++) cout<<arr[i]<<endl;
}

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

using namespace std;

#ifdef NeverBeRed
#include "debug.h"
#else
#define debug(...) 9715
#endif
typedef long long ll;
typedef long double ld;
typedef complex<ll> point;
#define F first
#define S second



int main()
{
	#ifdef TurnRed
		//freopen("a.in", "r", stdin);
		//freopen("a.out", "w", stdout);
	#endif

	ios_base::sync_with_stdio(0), cin.tie(0);

	int n;
	cin >> n;
	vector<int> a(n);
	for (int i = 0, x; i < n; ++i)
	{
		cin >> x;
		a[x-1] = i+1;
	}
	for (auto &i : a)
		cout << i << " \n"[&i==&a.back()];

	return 0;
}


Measured memory_bytes: 1280
#include<iostream>
#include<string>
#include<cmath>
using namespace std;

int main(){
    long long n;
         cin>>n;
    	long long sum=n/11*2;
    	n%=11;
    	if(n>=7&&n<=10)
		sum+=2;
    	if(n>=1&&n<=6)
		sum+=1;

       

        cout<<sum<<endl;
	
	return 0;
}

Measured memory_bytes: 256
N = int(input())
a_list = list(map(int,input().split()))

left = []
left_cnt = 0
left.append(left_cnt)

for a in a_list:
    left_cnt += a
    left.append(left_cnt)

from collections import Counter
c = Counter(left)

result = 0
for _, cnt in c.items():
    if cnt >= 2:
        result += cnt*(cnt-1)/2

print(int(result))

Measured memory_bytes: 112512
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
template<class T, class U> inline bool chmax(T& a,U b) { if (a < b) { a = b; return 1; } return 0; }
template<class T, class U> inline bool chmin(T& a,U b) { if (a > b) { a = b; return 1; } return 0; }
const int MOD = 1e9+7;
const int MAX = 400400;
template<int mod> struct ModInt {
    int x;
    ModInt() : x(0) {}
    ModInt(long long y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}
    ModInt &operator+=(const ModInt &p) { if((x += p.x) >= mod) x -= mod; return *this; }
    ModInt &operator-=(const ModInt &p) { if((x += mod-p.x) >= mod) x -= mod; return *this; }
    ModInt &operator*=(const ModInt &p) { x = (int)(1LL*x*p.x%mod); return *this; }
    ModInt &operator/=(const ModInt &p) { *this *= p.inverse(); return *this; }
    ModInt operator-() const { return ModInt(-x); }
    ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }
    ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }
    ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }
    ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }
    bool operator==(const ModInt &p) const { return x == p.x; }
    bool operator!=(const ModInt &p) const { return x != p.x; }
    ModInt inverse() const{
        int a = x, b = mod, u = 1, v = 0, t;
        while(b > 0) { t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); }
        return ModInt(u);
    }
    ModInt pow(int e){
        long long a = 1, p = x;
        while(e > 0) {
            if(e%2 == 0) {p = (p*p) % mod; e /= 2;}
            else {a = (a*p) % mod; e--;}
        }
        return ModInt(a);
    }
    friend ostream &operator<<(ostream &os, const ModInt<mod> &p) {
        return os << p.x;
    }
    friend istream &operator>>(istream &is, ModInt<mod> &a) {
        long long x;
        is >> x;
        a = ModInt<mod>(x);
        return (is);
    }
};

struct Combination {
    vector<ModInt<MOD>> fact;
    Combination(int n) : fact(n+1) {
        fact[0] = 1;
        for (int i = 1; i <= n; i++) {
            fact[i] = (fact[i-1] * i);
        }
    }
    ModInt<MOD> operator() (int n, int r) {
        if (r < 0 || r > n) return 0;
        return fact[n]/(fact[n-r]*fact[r]);
    }
};

ModInt<MOD> ncr(int n, int r) {
    if (r < 0 || r > n) return 0;
    ModInt<MOD> ret = 1;
    for (int i = n; i > n-r; i--) ret *= i;
    for (int i = 2; i < r; i++) ret /= i;
    return ret;
}

int main() {
    using mint = ModInt<MOD>;
    Combination com(MAX);
    int n, k;
    cin >> n >> k;
    
    auto cnt = [&](int i) -> mint {
        mint ret = com(n, i);
        ret *= com(n-1, i);
        return ret;
    };
    
    int lim = min(k, n-1);
    mint ans = com(n+n-1, n);
    for (int i = k+1; i < n; i++) {
        ans -= cnt(i);
    }
    
    cout << ans << endl;
    return 0;
}

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

int main()
{
    ios_base::sync_with_stdio(false); cin.tie(0);
    int a,b;
    while(cin >> a >> b)
        cout << (a * b % 2 == 0? "Even" : "Odd") << '\n';
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef DEBBY
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
      *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

#define ll long long
#define rep(i,a,b) for(int i=int(a); i<=int(b); i++)
#define sz(v)  (int)(v).size()
#define all(v) (v).begin(), (v).end()
#define pi pair<int,int>
#define vi vector<int>
#define vpi vector<pi>
#define fs first
#define sd second
#define pb push_back

void solve(){
      int m,n,x;
      cin >> n >> m >> x;
      vector<vector<int>> books; vector<int> costs(n);
      for(int i=0; i<n; i++){
            cin >> costs[i];
            books.push_back(vector<int>(m));
            rep(j,0,m-1)
                  cin >> books[i][j];
      }
      int ans = 1e7;
      for(int it=1; it<=(1 << n); it++){
            int sum_cost = 0;
            int els = it;
            int b = 0;
            vector<int> learn(m, 0);
            while(b<n){
                  if(els & (1 << b)){
                        sum_cost += costs[b];
                        for(int i=0; i<m; i++){
                              learn[i] += books[b][i];
                        }
                  }
                  b++;
            }
            debug() << imie(learn);
            bool notpassed = false;
            for(int l: learn){
                  if(l<x){
                        notpassed = true;
                        break;
                  }
            }
            if(!notpassed){
                  ans = min(ans, sum_cost);
            }
      }
      if(ans == 1e7)
            cout << -1;
      else
            cout << ans;
} 

int main(){
      ios_base::sync_with_stdio(false);
      cin.tie(NULL);
      solve();
      return 0;
}
      





Measured memory_bytes: 3664
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

#define MOD 1000000007
#define MOD2 998244353
#define int long long
//#define PI 3.14159265358979

#define rep(i, n) for (int i = 0; i < (int)(n); i++)

using namespace std;

template < typename T >
ostream &operator<<(ostream &os, const vector< T > &A) {
	for (int i = 0; i < A.size(); i++)
		os << A[i] << " ";
	os << endl;
	return os;
}
template <>
ostream &operator<<(ostream &os, const vector< vector< int > > &A) {
	int N = A.size();
	int M;
	if (N > 0)
		M = A[0].size();
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < M; j++)
			os << A[i][j] << " ";
		os << endl;
	}
	return os;
}

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

struct edge {
	int from, to, d, c;
	edge(int _from = 0, int _to = 0, int _d = 0, int _c = 0) {
		from = _from;
		to = _to;
		d = _d;
		c = _c;
	}
	bool operator<(const edge &rhs) const {
		return (d == rhs.d) ? (c < rhs.c) : (d < rhs.d);
	}
};
struct aabb {
	int x1, y1, x2, y2;
	aabb(int x1, int y1, int x2, int y2) : x1(x1), y1(y1), x2(x2), y2(y2) {}
};

typedef vector< edge > edges;
typedef vector< edges > graph;
struct flow {
	int to, cap, rev, cost;
	flow(int to = 0, int cap = 0, int rev = 0, int cost = 0) : to(to), cap(cap), rev(rev), cost(cost) {}
};
typedef vector< vector< flow > > flows;

const int di[4] = {0, -1, 0, 1};
const int dj[4] = {-1, 0, 1, 0};
const int ci[5] = {0, 0, -1, 0, 1};
const int cj[5] = {0, -1, 0, 1, 0};
const ll LINF = LLONG_MAX / 2;
const int INF = INT_MAX / 2;
const double PI = acos(-1);

int pow2(int n) { return 1 << n; }
template < typename T, typename U >
bool chmin(T &x, const U &y) {
	if (x > y) {
		x = y;
		return true;
	}
	return false;
}
template < typename T, typename U >
bool chmax(T &x, const U &y) {
	if (x < y) {
		x = y;
		return true;
	}
	return false;
}

struct initializer {
	initializer() {
		cout << fixed << setprecision(20);
	}
};
initializer _____;

int N, M, K, T, Q, H, W;
signed main() {
	cin >> N;
	M = 1 << N;
	vector< int > S(M);
	rep(i, M) cin >> S[i];
	multiset< int > s;
	rep(i, M) s.insert(S[i]);
	priority_queue< int > q1, q2;
	q1.push(*(s.rbegin()));
	s.erase(q1.top());
	string ans = "Yes";
	rep(k, N) {
		while (!q1.empty()) {
			int p = q1.top();
			q1.pop();
			q2.push(p);
			auto it = s.lower_bound(p);
			if (it == s.begin()) {
				ans = "No";
				break;
			}
			it--;
			q2.push(*it);
			s.erase(it);
		}
		if (ans == "No")
			break;
		swap(q1, q2);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 17772
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>

#include <algorithm>

using namespace std;
#define REP(i, n) for (int i = 0; i < (n); ++i)
typedef long long ll;
const ll INF = 1ll << 60;

ll MOD = 1e9 + 7;

vector<int> to[200005];
vector<int> ans;

void dfs(int v, int p = -1)
{
    for (int u : to[v])
    {
        if (u == p)
            continue;
        ans[u] += ans[v];
        dfs(u, v);
    }
}

int main()
{

    int n, q;
    cin >> n;
    cin >> q;
    vector<int> query(q);

    REP(i, n - 1)
    {
        int s, t;
        cin >> s;
        cin >> t;
        --s, --t;
        to[s].push_back(t);
        to[t].push_back(s);
    }
    ans.resize(n);
    REP(i, q)
    {
        int s, v;
        cin >> s;
        cin >> v;
        --s;
        ans[s] += v;
    }

    dfs(0);
    REP(i, n)
    {
        cout << ans[i] << endl;
    }
    return 0;
}

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

public class Main {
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int a = sc.nextInt();
        int k[] = new int[n];
        int all = 0,min = Integer.MAX_VALUE;
        for (int i = 0;i < n;++i){
            k[i] = sc.nextInt();
            all += k[i];
            if(min > k[i])min = k[i];
        }

        System.out.println(n + (a - all) / min);
    }
}

Measured memory_bytes: 21972
// khodaya khodet komak kon
#include <bits/stdc++.h>
#define pb push_back
#define ers erase
#define ins insert
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define debug(x)  cerr << #x << " = " << x << endl
#define kill(x) return cout << x, 0;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#pragma GCC optimize ("Ofast")
using namespace std;

typedef long long ll;
typedef long double ld;
typedef string str;
typedef pair<ll, ll> pll;
typedef vector<ll> vl;
typedef vector<pll> vpl;

const ld Pi = 3.14159265359;
const ll MOD = 1000 * 1000 * 1000 + 7;
const ll N = 2e5 + 10;
const ll INF = 1e18;
const ll LOG = 20;
ll n ,k;



int main(){
	IOS;
	cin >> n >> k;
	if (k <= n / 2 + (n % 2)) kill("YES");
	kill("NO");
	
	
	
	
	
	
	
	return 0;
}






/*
     ,---,           ___                 ,--,
    '  .' \        ,--.'|_             ,--.'|                             ,--,
   /  ;    '.      |  | :,'            |  | :                           ,--.'|    ,---.        ,---,
  :  :       \     :  : ' :            :  : '                 .--.--.   |  |,    '   ,'\   ,-+-. /  |
  :  |   /\   \  .;__,'  /    ,--.--.  |  ' |     ,--.--.    /  /    '  `--'_   /   /   | ,--.'|'   |
  |  :  ' ;.   : |  |   |    /       \ '  | |    /       \  |  :  /`./  ,' ,'| .   ; ,. :|   |  ,"' |
  |  |  ;/  \   \:__,'| :   .--.  .-. ||  | :   .--.  .-. | |  :  ;_    '  | | '   | |: :|   | /  | |
  '  :  | \  \ ,'  '  : |__  \__\/: . .'  : |__  \__\/: . .  \  \    `. |  | : '   | .; :|   | |  | |
  |  |  '  '--'    |  | '.'| ," .--.; ||  | '.'| ," .--.; |   `----.   \'  : |_|   :    ||   | |  |/
  |  :  :          ;  :    ;/  /  ,.  |;  :    ;/  /  ,.  |  /  /`--'  /|  | '.'\   \  / |   | |--'
  |  | ,'          |  ,   /;  :   .'   \  ,   /;  :   .'   \'--'.     / ;  :    ;`----'  |   |/
  `--''             ---`-' |  ,     .-./---`-' |  ,     .-./  `--'---'  |  ,   /         '---'
                            `--`---'            `--`---'                 ---`-'
*/




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

int main(){
    string S;
    cin >> S;
    int N = S.size();
    string keyence = "keyence";
    for (int i = 0; i < 7; i++) {
        if (S.substr(0, i) + S.substr(N-7+i, 7-i) == keyence) {
            cout << "YES" << endl;
            return 0;
        }
    }
    cout << "NO" << endl;
    return 0;
}

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

struct UnionFind{
    int num;
    vector<int> par,rank;
    UnionFind(int n):num(n),par(n),rank(n,1){
        iota(par.begin(),par.end(),0);
    }
    int root(int x){
        if (par[x]==x) return x;
        return par[x]=root(par[x]);
    }
    bool merge(int x, int y){
        x=root(x),y=root(y);
        if (x==y) return false;
        if (rank[x]<rank[y]) swap(x,y);
        par[y]=x;
        rank[x]+=rank[y];
        --num;
        return true;
    }
    bool same(int x, int y){
        return root(x)==root(y);
    }
    int size(int x){
        return rank[root(x)];
    }
    int count(){
        return num;
    }
};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N,M; cin >> N >> M;
    UnionFind uf(N+M);
    for (int i=0;i<N;++i){
        int K; cin >> K;
        for (;K--;){
            int L; cin >> L;
            uf.merge(i,L-1+N);
        }
    }
    int p=uf.root(0),ok=1;
    for (int i=1;i<N;++i)
        if (uf.root(i)!=p) ok=0;
    cout << (ok?"YES":"NO") << '\n';
}

Measured memory_bytes: 1792