akhauriyash/Code-Regression huggingface dataset:
import java.util.*;

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

		int swordMaxPoint = 0;
		int swordPoint;
		int[] throwPoints = new int[swordNum];
		for(int i = 0; i < swordNum; i++) {
			swordPoint = sc.nextInt();
			swordMaxPoint = swordMaxPoint > swordPoint ? swordMaxPoint : swordPoint;
			throwPoints[i] = sc.nextInt();
		}
		Arrays.sort(throwPoints);
		int ans = 0;
		for(int i = swordNum-1; i >= 0; i--) {
			if(throwPoints[i] <= swordMaxPoint) {
				ans += Math.ceil((double)hitPoint / swordMaxPoint);
				hitPoint = 0;
				break;
			}
			hitPoint -= throwPoints[i];
			ans++;
			if(hitPoint <= 0) break;
		}
		if(hitPoint > 0) ans += Math.ceil((double)hitPoint / swordMaxPoint);

		System.out.println(ans);
	}
}


Measured memory_bytes: 67244
import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) {
        FastScanner scanner = new FastScanner();
        PrintWriter out = new PrintWriter(System.out,false);
        char[] s = scanner.next().toCharArray();
        char[] t = scanner.next().toCharArray();
        int n = s.length;
        int m = t.length;
        int[][] next = new int[n][26];
        for(int i= 0; i < 26; i++) {
            next[n-1][i] = -1;
            if (i == s[n-1]-'a') next[n-1][i] = n-1;
        }
        for(int i = n-2; i >= 0; i--) {
            for(int j = 0; j < 26; j++) {
                next[i][j] = next[i+1][j];
                if (s[i]-'a' == j) next[i][j] = i;
            }
        }
        long ans = 0;
        int cur = 0;
        for(int i = 0; i < m; i++) {
            int c = t[i]-'a';
            if (next[0][c] == -1) {
                System.out.println(-1);
                return;
            }
            if (next[cur][c] != -1) {
                ans += next[cur][c] - cur + 1;
                cur = next[cur][c] + 1;
            }
            else {
                ans += n - cur;
                ans += next[0][c] + 1;
                cur = next[0][c] + 1;
            }
            if (cur == n) cur = 0;
        }
        out.println(ans);
        out.flush();
    }
    
    public static class FastScanner {
        BufferedReader br;
        StringTokenizer st;
        
        public FastScanner(Reader in) {
            br = new BufferedReader(in);
        }
        
        public FastScanner() {
            this(new InputStreamReader(System.in));
        }
        
        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }
        
        int nextInt() {
            return Integer.parseInt(next());
        }
        
        long nextLong() {
            return Long.parseLong(next());
        }
        
        double nextDouble() {
            return Double.parseDouble(next());
        }
        
        String readNextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
}


Measured memory_bytes: 39124
import java.util.Scanner;
 
class Main{
  public static void main(String[] arg){
    int r, c;

    Scanner in = new Scanner(System.in);

    r = in.nextInt();
    c = in.nextInt();

    int [][] output = new int[r+1][c+1];

    for(int i=0; i<output.length-1; i++){
        in.nextLine();
        for(int j=0; j<output[0].length-1; j++){
            output[i][j] = in.nextInt();
        }
    }

    for(int i=0; i<output.length; i++)
        output[i][output[0].length-1] = 0;

    for(int i=0; i<output[0].length-1; i++)
        output[output.length-1][i] = 0;

    for(int i=0; i<output.length-1; i++){
        for(int j=0; j<output[0].length-1; j++){
            output[i][output[0].length-1] += output[i][j];
            output[output.length-1][j] += output[i][j];
        }
    }

    for(int i=0; i<output[0].length-1; i++)
        output[output.length-1][output[0].length-1] += output[output.length-1][i];

    for(int i=0,j; i<output.length; i++){
        for(j=0; j<output[0].length-1; j++){
            System.out.print(output[i][j] + " ");
        }
        System.out.print(output[i][j]);
        System.out.println();
    }

  }
}

Measured memory_bytes: 46456
/*
　　　∫ ∫ ∫
　　　ノヽ
　　（＿　 ）
　（＿　　　 ）
（＿＿＿＿＿＿ ）
　ヽ(´･ω･)ﾉ　
　　 |　 /
　　 UU
*/
#pragma region macro
#include <bits/stdc++.h>
typedef long long int64;
using namespace std;
using P = pair<int64, int64>;
typedef vector<int> vi;
const int MOD = (int)1e9 + 7;
const int64 INF = 1LL << 62;
const int inf = 1<<30;
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; }
#define REP(i, n) for (int i = 0; i < (n); i++)
#define FOR(i,s,n) for (int i = s; i < (n); i++)
#define ALL(obj) (obj).begin(), (obj).end() //コンテナじゃないと使えない!!
#define debug(x) cerr << #x << ": " << x << "\n";
#define mp make_pair
#define bn '\n'
template <typename T>
ostream& operator<<(ostream& os, const vector<T> &V){
    int N = V.size();
    REP(i,N){
        os << V[i];
        if (i!=N-1) os << " ";
    }
    os << "\n";
    return os;
}
template <typename T,typename S>
ostream& operator<<(ostream& os, pair<T,S> const&P){
    os << "(";
    os << P.first;
    os << " , ";
    os << P.second;
    os << ")";
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, set<T> &S){
    auto it=S.begin();
    while(it!=S.end()){
        os << *it;
        os << " ";
        it++;
    }
    os << "\n";
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, deque<T> &q){
    for(auto it=q.begin();it<q.end();it++){
        os<<*it;
        os<<" ";
    }
    os<<endl;
    return os;
}
template <typename T,typename S>
ostream& operator<<(ostream& os, map<T,S> const&M){
    for(auto e:M){
        os<<e;
    }
    os<<endl;
    return os;
}
vector<pair<int,int>> dxdy = {mp(0,1),mp(1,0),mp(-1,0),mp(0,-1)};
#pragma endregion
//fixed<<setprecision(10)<<ans<<endl;



int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<vector<int64>> DP(N+3,vector<int64>(3,-INF)); //飛ばした回数
    DP[0][0] = 0;
    DP[1][0] = 0;
    DP[2][1] = 0;
    vector<int64> A(N);
    REP(i,N) cin >> A[i];

    REP(i,N){
        int idx = i + 3;
        REP(j,3){
            chmax(DP[idx][j], DP[idx-2][j] + A[i]);
            // if(j) chmax(DP[idx][j], DP[idx-3][j-1] +  A[i]);
            if(j) chmax(DP[idx][j], DP[idx-1][j-1]);
        }
    }

    auto ans = DP.back()[1 + (N&1)];
    cout << ans << endl;
}

Measured memory_bytes: 15860
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <map>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i=0;i < (int)(n);i++)

int main(){
  ll n;
  cin >> n;
  ll ans = 0;
  rep(i,n){
    ans += ll(i+1)*(n/ll(i+1))*(1 + (n/ll(i+1)))/2;  
  }
  cout << ans << endl;

}


Measured memory_bytes: 3628
import sys
IS = lambda: sys.stdin.readline().rstrip()
II = lambda: int(IS())
MII = lambda: list(map(int, IS().split()))
def main():
    n, m = MII()
    ab = sorted([(MII()) for _ in range(m)], key=lambda x: x[1])
    pre = -1
    cnt = 0
    for a, b in ab:
        a -= 1; b-= 1
        if a>=pre: cnt+=1; pre=b
    print(cnt)


if __name__ == '__main__':
    main()


Measured memory_bytes: 29932
#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>

using namespace std;

int main(int argc, char const* argv[])
{
    int c;
    while ((c = getchar()) != EOF) {
        if('a' <= c && c <= 'z'){
            putchar(c + ('A' - 'a'));
        }else{
            putchar(c);
        }
    }
    return 0;
}

Measured memory_bytes: 892
#include<iostream>
#include <string>
using namespace std;
string S,T,ans;
int N;
int k;
int main(){
  cin>>N;
  cin>>S;
  cin>>T;
  k=0;
  for(int n=0;n<N;n++){
    ans=ans+S[n];
    k++;
    ans=ans+T[n];
    k++;
  }
  
  cout<<ans<<endl;
    
  }
  

Measured memory_bytes: 256
N = gets.to_i
H = gets.split.map(&:to_i)

max = 0

0.upto(N - 1) do |i|
  if H[i] < max - 1
    puts 'No'
    exit
  end
  max = max < H[i] ? H[i] : max
end

puts 'Yes'

Measured memory_bytes: 8580
import java.util.*;

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

    boolean flg = true;

    List<Integer> result = new ArrayList<Integer>();

    List<Integer> list = new ArrayList<Integer>();
    List<String> op = new ArrayList<String>();
    while(flg) {
      for(int i = 0; i < 3; i++) {
        if (i == 1) {
          String str = sc.next();
          op.add(str);
          char[] c = str.toCharArray();
          if (str == null || c[0] == '?') {
            flg = false;
          }
        } else {
          int num = sc.nextInt();
          list.add(num);
        }
      }
    }
    sc.close();

    for(int j = 0; j < op.size(); j++) {
      switch(op.get(j)) {
        case "+":
          int ans = list.get(0) + list.get(1);
          result.add(ans);
          list.subList(0, 2).clear();
          // op.remove(0);
          break;
        case "-":
          int ans1 = list.get(0) - list.get(1);
          result.add(ans1);
          list.subList(0, 2).clear();
          // op.remove(0);
          break;
        case "*":
          int ans2 = list.get(0) * list.get(1);
          result.add(ans2);
          list.subList(0, 2).clear();
          // op.remove(0);
          break;
        case "/":
          int ans3 = list.get(0) / list.get(1);
          result.add(ans3);
          list.subList(0, 2).clear();
          // op.remove(0);
          break;
        case "?":
          break;
      }
    }

    for(int k = 0; k < result.size(); k++) {
      System.out.println(result.get(k));
    }
  }
}


Measured memory_bytes: 26224
#include <iostream>
#include <fstream>
#include <string>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <utility>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <unordered_map>
#define int long long
using namespace std;
using P = pair<int, int>;
using ll = long long;
using prique = priority_queue<int>;
const int MOD = 1000000007;
signed main(){
    int n,k;
    cin>>n>>k;
    int a[2000];
    for(int i=0;i<n;i++)cin>>a[i];
    int s=k*(k+1)/2%MOD;
    int ans=0;
    for(int i=0;i<n;i++){
        int cnta=0;
        int cntal=0;
        for(int j=0;j<n;j++){
            if(i==j)continue;
            else if(j<i){
                if(a[j]<a[i]){
                    cnta++;
                    cntal++;
                }
            }else{
            if(a[j]<a[i]){
                    cntal++;
                }
            }
        }
        ans+=cntal*s%MOD-cnta*k;
        if(ans<0)ans+=MOD;
        ans%=MOD;
    }
    if(ans<0)ans+=MOD;
    cout<<ans<<endl;
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5;
int a[maxn], b[maxn];
int main(){
    int n;
    cin >> n;
    for(int i = 1; i <= n; i ++) cin >> a[i];
    for(int i = 1; i <= n; i ++) cin >> b[n + 1 - i];
    //reverse(b + 1, b + n + 1);
    int ok = 0;
    for(int i = 1; i <= n; i ++){
        if(a[i] != b[i]) continue;
        int f = 0;
        for(int j = 1; j <= n; j ++){
            if(a[i] != b[j] && a[j] != b[i]){
                f = 1;
                swap(b[i], b[j]);
                break;
            }
        }
        if(!f){
            ok=1;
            break;
        }
    }
    if(ok==1){
        cout << "No" << endl;
    }else{
		cout << "Yes" << endl;
		for(int i = 1; i <= n; i ++){
			if(i != 1)cout << " ";
			cout << b[i];
		}
    	cout << endl;
	}
    return 0;
}


Measured memory_bytes: 5172
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 = new int[n];
for(int i=0;i<a.length;i++){
a[i] = sc.nextInt();
}
for(int j=n-1;j>0;j--){
System.out.printf("%d ",a[j]);
}
System.out.printf("%d\n",a[0]);
sc.close();
}
}


Measured memory_bytes: 26636
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

import numpy as np

N,K,*A = map(int,read().split())

MOD = 10**9 + 7

"""
・次々と(1+x+...+x^a)をかけていく
・(1-x^{a+1})をかけたあと(1-x)^{-1}をかける
"""

dp = np.zeros(K+10,np.int64)
dp[0] = 1
for a in A:
    dp[(a+1):] -= dp[:-(a+1)].copy()
    dp %= MOD

for _ in range(N):
    np.cumsum(dp,out=dp); dp %= MOD

answer = dp[K]
print(answer)

Measured memory_bytes: 14740
#include <bits/stdint-intn.h>
#include<cstdint>
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<deque>
#include<stack>
#include<iterator>
#include<stack>
#include<cctype>
#include<climits>
#include<string>
#include<bitset>
#include<cfloat>
#include<iomanip>
#include<numeric>
#include<utility>
#include<initializer_list>


#define repi(i,start,end)for(int64_t (i)=(start);(i)<(end);++(i))
#define rep(i,end) repi((i),0,(end))
#define rfor(x, v) for(auto& (x) : (v))
#define iterate(itr, v) for(auto (itr)=(v).begin();(itr)!=(v).end();++(itr))
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define vin(v) rep(i,(v).size()) cin >> (v)[i];
#define vpin(v) rep(i,(v).size()) cin >> (v)[i].first >> (v)[i].second

using namespace std;
using Int = int64_t;
using pint = pair<Int, Int>;
using vint = vector<Int>;
using vvint = vector<vint>;
using vpint = vector<pint>;
using vstr = vector<string>;

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; }
template<class T>void put_double(T a){if(cout.precision()!=12)cout<<setprecision(12);cout<<a<<"\n";}
template<class T>void println(T a){cout << a << "\n";}
template<class T>void put_line(T &v){iterate(itr,v){cout<<*itr<<((itr==--v.end())?"\n":" ");}}
// auto [x, y] = make_tuple(3, 4); => let (x, y) = (3, 4);

int main(void) {
    Int n, m; cin >> n >> m;
    vint h(n); vin(h);

    vvint t(n);
    rep(i, m) {
        Int x, y; cin >> x >> y;
        x--; y--;
        t[x].push_back(h[y]);
        t[y].push_back(h[x]);
    }

    Int ans = 0;
    rep(i, n) {
        if(t[i].size() == 0)  {
            ans++;
            continue;
        }
        sort(all(t[i]));
        if(h[i] > t[i].back()) ans++;
    }
    println(ans);
    return 0;
}


Measured memory_bytes: 9804
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <map>
#include <vector>
using namespace std;
typedef long long LL;

LL f[2055][2055] = {0};
LL n,m;

void solve(LL x,LL y,LL d){
	if(d == 0){
		f[x][y] = 1;
		return;
	}
	solve(x,y,d - 1);
	solve(x + (1LL << d),y,d - 1);
	solve(x,y + (1LL << d),d - 1);
	solve(x + (1LL << d),y + (1LL << d),d - 1);
	f[x + (1LL << d) - 1][y + (1LL << d) - 1] = 1;
}

int main(){
	cin >> n >> m;
	solve(1,1,10);
	for(LL i = 1;i < (1LL << n);i ++){
		for(LL j = 1;j < (1LL << m);j ++){
			cout << f[i][j];
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 34176
#include <cassert>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <numeric>
#include <algorithm>

using namespace std;
using lint = long long;
constexpr int MOD = 1000000007, INF = 1010101010;
constexpr lint LINF = 1LL << 60;

#ifdef _DEBUG
#include "../../library/library/debug_template.cpp"
#define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__)
#else 
#define DMP(...) ((void)0)
#endif

struct init {
	init() {
		cin.tie(nullptr); ios::sync_with_stdio(false);
		cout << fixed << setprecision(10);
	}
} init_;

int main() {

	int N, Q;
	string S;
	cin >> N >> S >> Q;

	vector<set<int>> idx(26);
	for (int i = 0; i < N; i++) {
		idx[S[i] - 'a'].emplace(i);
	}

	for (int i = 0; i < Q; i++) {
		int q;
		cin >> q;
		if (q == 1) {
			int j;
			char c;
			cin >> j >> c;
			j--;
			idx[S[j] - 'a'].erase(j);
			S[j] = c;
			idx[c - 'a'].emplace(j);
		}
		else {
			int l, r;
			cin >> l >> r;
			l--, r--;
			int cnt = 0;
			for (int i = 0; i < 26; i++) {
				cnt += idx[i].upper_bound(r) != idx[i].lower_bound(l);
			}
			cout << cnt << "\n";
		}
	}

	return 0;
}



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

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;

const double PI = acos(-1);
#define MOD 1000000007

#define PB push_back
#define F first
#define S second
#define all(a) (a).begin(), (a).end()
#define sz(x) (ll)x.size()
#define el <<'\n'

#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*(b/gcd(a,b)))
#define sqr(a) ((a) * (a))

#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define file() freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
main()
{
    //optimize();
    double n,c,d;
    cin>>n;
    c=n/3;
    d=pow(c,3);
    printf("%.12lf\n",d);
}










Measured memory_bytes: 256
#include <iostream>
using namespace std;
int n,a[10000],b[10000];
long long x,A,B;
int main(){
    cin>>n;
    for(int i=0;i<n;i++)cin>>a[i];
    for(int i=0;i<n;i++){
        cin>>b[i];
        x+=b[i]-a[i];
        if(a[i]<b[i])A+=(b[i]-a[i]+1)/2;
        if(a[i]>b[i])B+=(a[i]-b[i]);
    }
    if(x>=A&&x>=B) cout<<"Yes";
    else cout<<"No";
    return 0;
}

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

int main()
{
  int n,m;

  cin >> n;
  
  m=n/10;

  n-=m*10;
  if(n==2 || n==4 || n==5 || n==7 || n==9)cout << "hon\n";
  else if(n==3)cout << "bon\n";
  else cout << "pon\n";

  return 0;
}

Measured memory_bytes: 3636
using System;
using System.Collections.Generic;
using System.Collections;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.IO;
using System.Reflection;
using static System.Math;
using System.Numerics;
static class Program{
	const int mod=(int)1e9+7;
	static List<int>[] li;
	static bool[] b;
	static int[] low,ord;
	static int ans=0;
	static void Main(){
		Sc sc=new Sc();
		int[] s=sc.Ia;
		int n=s[0],m=s[1];
		li=new List<int>[n+1];
		b=new bool[n+1];
		low=new int[n+1];
		ord=new int[n+1];
		for(int i=1;i<=n;i++){li[i]=new List<int>();}
		for(int i=0;i<m;i++){
			int[] e=sc.Ia;
			li[e[0]].Add(e[1]);
			li[e[1]].Add(e[0]);
		}
		Fu(1,0,-1);
		Console.WriteLine("{0}",ans);
	}
	static void Fu(int a,int g,int p){
		b[a]=true;
		ord[a]=g;
		low[a]=g;
		for(int i=0;i<li[a].Count;i++){
			if(!b[li[a][i]]){
				Fu(li[a][i],g+1,a);
				if(low[li[a][i]]==ord[li[a][i]]){ans++;}
			}
			if(li[a][i]!=p){low[a]=Min(low[li[a][i]],low[a]);}
		}
	}
}

public class Sc{
	public int I{get{return int.Parse(Console.ReadLine());}}
	public long L{get{return long.Parse(Console.ReadLine());}}
	public double D{get{return double.Parse(Console.ReadLine());}}
	public string S{get{return Console.ReadLine();}}
	public int[] Ia{get{return Array.ConvertAll(Console.ReadLine().Split(),int.Parse);}}
	public long[] La{get{return Array.ConvertAll(Console.ReadLine().Split(),long.Parse);}}
	public double[] Da{get{return Array.ConvertAll(Console.ReadLine().Split(),double.Parse);}}
	public string[] Sa{get{return Console.ReadLine().Split();}}
	public object[] Oa{get{return Console.ReadLine().Split();}}
	public int[] Ia2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),int.Parse);}}
	public int[] Ia3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),int.Parse);}
	public int[] Ia3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),int.Parse);}
	public long[] La2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),long.Parse);}}
	public long[] La3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),long.Parse);}
	public long[] La3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),long.Parse);}
	public T[] Arr<T>(int n,Func<T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f();}return a;}
	public T[] Arr<T>(int n,Func<int,T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i);}return a;}
	public T[] Arr<T>(int n,Func<string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(Console.ReadLine().Split());}return a;}
	public T[] Arr<T>(int n,Func<int,string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i,Console.ReadLine().Split());}return a;}
}


Measured memory_bytes: 13396
import queue
import sys
imput = sys.stdin.readline

n,m = map(int,input().split()) 

conne = [[] for _ in range(n+1)]
dist = [99999]*(n+1)
par = [0] * (n+1)

for i in range(m):
    a,b = map(int,input().split()) 
    conne[a].append(b)
    conne[b].append(a)
    
q=queue.Queue()
dist[1] = 0
q.put((1,0))

while not q.empty():
    
    x,d = q.get()
    
    for i in conne[x]:
        if dist[i]==99999:
            q.put((i,d+1))
            par[i] = x
            dist[i] = d+1


print("Yes")    

for i in par[2:]:
    print(i)



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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define sf scanf
#define pf printf
#define pb push_back
#define mp make_pair
#define PI ( acos(-1.0) )
#define mod 1000000007LL
#define maxn 500005
#define IN freopen("C.in","r",stdin)
#define OUT freopen("output.txt","w",stdout)
#define FOR(i,a,b) for(i=a ; i<=b ; i++)
#define DBG pf("Hi\n")
#define INF 1000000000
#define i64 long long int
#define eps (1e-8)
#define xx first
#define yy second
#define ln 17
#define off 2

using namespace __gnu_pbds;
using namespace std ;

typedef tree< i64, null_type, less<i64>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef pair<i64, i64> pii;

int a[2][105] ;

int main()
{
    int i , j , k , l , m , n ;

    scanf("%d",&n) ;

    for(i=1 ; i<=2 ; i++)
    {
        for(j=1 ; j<=n ; j++) scanf("%d",&a[i][j]) ;

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

    int ans = -1 ;

    for(i=1 ; i<=n ; i++)
    {
        ans = max(ans, a[1][i]+a[2][n]-a[2][i-1] ) ;
    }

    cout<<ans<<endl ;

    return 0 ;
}


Measured memory_bytes: 256
#!/usr/bin/env python3


import collections


class UnitDict(dict):

    def __init__(self, iterable=None, wrapper=lambda x: x):
        super().__init__(self)
        self.wrapper = wrapper
        if iterable is not None:
            self.update(iterable)

    def __missing__(self, key):
        self[key] = self.wrapper(key)
        return self[key]


class DisjointSetDataStructure(object):

    def __init__(self, nodes=None):
        self.par = UnitDict(wrapper=lambda x: x)
        self.rank = collections.defaultdict(int)
        self.groups = UnitDict(wrapper=lambda x: {x})
        if nodes is not None:
            for node in nodes:
                _, _, _ = self.par[node], self.rank[node], self.groups[node]
        
    def root(self, node):
        if self.par[node] == node:
            return node
        else:
            r = self.root(self.par[node])
            self.par[node] = r
            return r
    
    def in_the_same_set(self, node1, node2):
        return self.root(node1) == self.root(node2)
    
    def elements_of_group(self, node):
        return self.groups[self.root(node)]
 
    def unite(self, node1, node2):
        x = self.root(node1)
        y = self.root(node2)
        if x != y:
            if self.rank[x] < self.rank[y]:
                x, y = y, x
            self.par[y] = x
            self.groups[x].update(self.groups[y])
            self.groups[y].clear()
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1


def main():
    _, q = [int(z) for z in input().split()]
    d = DisjointSetDataStructure()
    for _ in range(q):
        # string, not int!
        c, x, y = input().split()
        if c == "0":
            d.unite(x, y)
        else:
            print(int(d.in_the_same_set(x, y)))


if __name__ == "__main__":
    main()


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

const long long INF = 1LL << 60;
int MOD = 1000000007;
double PI = 3.14159265358979323846;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

typedef long long ll;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define For(i,s,n) for (int i=s;i<(int)(n);i++)
#define vi vector<int>
#define vii vector< vector<int> >
#define vs vector<string>
#define All(c) (c).begin(), (c).end()
#define Print(x) cout<<(x)<<"\n"
#define Sort(c) sort(c.begin(), c.end())


//D

int N;

int main() {

	cin >> N;
	int k = 1;
	while (k * (k - 1) / 2 < N) k++;
	if (k * (k - 1) / 2 != N) {
		cout << "No" << endl;
		return 0;
	}

	vii A(k);
	int s = 1;
	rep(i, k) {
		for (int j = i + 1; j < k; j++) {
			A[i].push_back(s);
			A[j].push_back(s);
			s++;
		}
	}

	cout << "Yes" << endl;
	cout << k << endl;
	rep(i, k) {
		cout << k - 1 << ' ';
		rep(j, k - 1) {
			cout << A[i][j] << ' ';
		}
		cout << endl;
	}

}


Measured memory_bytes: 2304
#include <bits/stdc++.h>
#define PI 3.14159265358979323846
#define MAXINF (1e18L)
#define INF (1e9L)
#define EPS (1e-9)
#define MOD ((ll)(1e9+7))
#define REP(i, n) for(int i=0;i<int(n);++i)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define ALL(v) v.begin(),v.end()
#define FIND(v,x) (binary_search(ALL(v),(x)))
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v));reverse(ALL(v))
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define YES(n) cout<<((n)?"YES":"NO")<<endl
#define pb push_back
#define fi first
#define se second
using namespace std;
template<class A>void pr(A a){cout << (a) << endl;}
template<class A,class B>void pr(A a,B b){cout << a << " "  ;pr(b);}
template<class A,class B,class C>void pr(A a,B b,C c){cout << a << " " ;pr(b,c);}
template<class A,class B,class C,class D>void pr(A a,B b,C c,D d){cout << a << " " ;pr(b,c,d);}
template<class T> void pr_vec(vector<T> &v, char ep=' '){int n=v.size();REP(ni,n){cout<<v[ni];if(ni!=n-1)cout<<ep;}cout<<endl;};
template<class T> inline bool chmin(T& a, T b){return a>b ? a=b, true : false;}
template<class T> inline bool chmax(T& a, T b){return a<b ? a=b, true : false;}
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;

int K;

bool dfs(int red, int green, int blue, int k){
    if(red < green && green < blue) return true;
    if(k == K) return false;

    return (dfs(red*2, green, blue, k+1) || dfs(red, green*2, blue, k+1) || dfs(red, green, blue*2, k+1));
}

int main(void)
{
    int a,b,c;
    cin >> a >> b >> c;
    cin >> K;
    
    Yes(dfs(a,b,c,0));
}

Measured memory_bytes: 3628
#include <set>
#include <ctime>
#include <cstdio>
#include <string>
#include <cstdlib>
#include <iostream>
using namespace std;
set<string> s; string t1, t2;
int main() {
	srand((unsigned)time(NULL));
	s.insert("aaaaaaaaaa"); cout << "?aaaaaaaaaa" << endl;
	while(true) {
		cin >> t1;
		if(s.find(t1) != s.end() || t1[0] != 'a' || t1.size() > 2) {
			cout << "!OUT" << endl; break;
		}
		s.insert(t1);
		t2 = t1.substr(t1.size() - 1, 1);
		for(int i = 0; i < 8; i++) t2 += rand() % 26 + 97;
		t2 += 'a';
		cout << "?" << t2 << endl;
		s.insert(t2);
	}
	return 0;
}

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

int main() {
    int N, x; cin >> N >> x;
    vector<int> a(N);
    rep(i, 0, N) cin >> a[i];
 
    sort(a.begin(),a.end());
    ll cnt = 0;
    rep(i, 0, N){
        x -= a[i];
        if(x < 0) break;
        cnt++;
    }
    if(x > 0) cnt--;
    cout << cnt << endl;
 
    return 0;
}

Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split()))
box=[0]*n
for i in range(n):
  baisu=n//(n-i)
  if baisu==1:
    box[n-i-1]=a[n-i-1]
  else:
    cnt=0
    for j in range(2,baisu+1):
      cnt+=box[(n-i)*j-1]
    if cnt%2!=a[n-i-1]:
      box[n-i-1]=1
print(sum(box))
if sum(box)!=0:
  for i in range(n):
    if box[i]==1:
      print(i+1,end=' ')


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

using namespace std;

int main()
{
    int n;
    scanf("%i", &n);
    vector<long long> cnt(n+1);
    vector<int> arr(n);
    for (auto &x : arr)
    {
        scanf("%i", &x);
        cnt[x]++;
    }
    long long s = 0;
    for (auto &x : cnt)
        s += x * (x - 1) / 2;
    for (auto &x : arr)
    {
        long long c = s - cnt[x] * (cnt[x] - 1) / 2;
        c += (cnt[x] - 1) * (cnt[x] - 2) / 2;
        printf("%lli\n", c);
    }
}


Measured memory_bytes: 4992
#include <iostream>
#include <string>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <list>
#include <iomanip>
#include <vector>
#include <functional>
#include <algorithm>
#include <cstdio>
#include <random>
#include <ctime>
#include <cstdlib>
#include <unordered_map>
#include <string.h>
#include <iostream>

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(begin, i, end) for (int i = begin; i < (int)(end); i++)
#define all(v) v.begin(), v.end()
const int MOD = 1000000007;

int main()
{
    int N, M;
    cin >> N >> M;
    vector<int> H(N);
    rep(0, i, N)
    {
        cin >> H.at(i);
    }
    vector<vector<int>> path(N);
    rep(0, i, M)
    {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        path.at(a).push_back(b);
        path.at(b).push_back(a);
    }
    int ans = 0;
    vector<int> flag(N, 0);
    rep(0, i, N)
    {
        if (flag.at(i))
        {
            continue;
        }
        int f = 1;
        for (auto p : path.at(i))
        {
            if (H.at(i) <= H.at(p))
            {
                f = 0;
                flag.at(i) = 1;
                break;
            }
        }
        if (f)
        {
            ans++;
            for (auto p : path.at(i))
            {
                flag.at(p) = 1;
            }
        }
    }

    cout << ans << endl;
}

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

using vb = std::vector<bool>;
using pii = std::pair<int, int>;
std::vector<vb> s, visited;

pii dfs(int, int, bool);

int dir[4][2]{{1, 0}, {-1, 0}, {0, 1}, {0, -1}};

int main()
{
	int h, w;
	scanf("%d%d", &h, &w);
	s.resize(h + 2, vb(w + 2));
	visited.resize(h + 2, vb(w + 2));
	for (int i{1}; i <= h; i++)
		for (int j{1}; j <= w; j++)
		{
			char tmp;
			scanf(" %c", &tmp);
			s[i][j] = tmp == '#';
		}
	for (int r{}; r <= h + 1; r++)
		visited[r][0] = visited[r][w + 1] = true;
	for (int c{}; c <= w + 1; c++)
		visited[0][c] = visited[h + 1][c] = true;
	long long count{};
	for (int i{1}; i <= h; i++)
		for (int j{1}; j <= w; j++)
		{
			auto tmp{dfs(i, j, s[i][j])};
			count += (long long)tmp.first * tmp.second;
		}
	printf("%lld\n", count);
	
	return 0;
}

pii dfs(int r, int c, bool black)
{
	if (visited[r][c] || s[r][c] != black) return pii();
	visited[r][c] = true;
	pii ret;
	if (black)
		ret.first = 1;
	else
		ret.second = 1;
	for (int i{}; i < 4; i++)
	{
		auto tmp{dfs(r + dir[i][0], c + dir[i][1], !black)};
		ret.first += tmp.first;
		ret.second += tmp.second;
	}
	return ret;
}

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

#define ull unsigned long long
#define ul unsigned long
#define ll long long
#define size_t long long
// sort(&a[0], &a[4], [](auto& x, auto& y){return x[0] < y[0];});
//accumulate(&arr2[n], &arr2[m-1], 0);
using namespace std;

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

  int N,L; std::cin >> N >> L;

  if(L >= 0){
    std::cout << L*(N-1)+N*(N-1)/2 << '\n';
  }else{
    std::cout << (L-1)*(N-1) + N*(N+1)/2 - min(N,1-L) << '\n';
  }


  return 0;
}


Measured memory_bytes: 256
n=int(input())
mojilist=[]
for i in range(n):
	tmps=sorted(input())
	mojilist.append("".join(tmps))

mojilist.sort()
tmp=""
count=1
sum=0
for moji in mojilist:
	if moji == tmp:
		count += 1
	else:
		sum += count*(count-1)//2
		count=1
		tmp=moji

sum += count*(count-1)//2
print(sum)




Measured memory_bytes: 16512
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <map>
#include <queue>

static const int INF = 1000000007;
using ll = long long;
using u32 = unsigned;
using namespace std;

int main() {
    string a, b;
    cin >> a >> b;
    int k = stoi((a+b));
    for (int i = 0; i*i <= k; ++i) {
        if(k == i*i){
            cout << "Yes" << "\n";
            return 0;
        }
    }
    cout << "No" << "\n";
    return 0;
}


Measured memory_bytes: 256
import datetime
H1,M1,H2,M2,K = map(int,input().split())

#d1 = datetime.datetime(hour=H1, minute=M1)
#d2 = datetime.datetime(hour=H2, minute=M2)

#d1 = datetime.datetime(year=2020, month=5, day=30, hour=H1, minute=M1, second=0, microsecond=0)
#d2 = datetime.datetime(year=2020, month=5, day=30, hour=H2, minute=M2, second=0, microsecond=0)

d1 = datetime.datetime(year=2020, month=5, day=30, hour=H1, minute=M1)
d2 = datetime.datetime(year=2020, month=5, day=30, hour=H2, minute=M2)

#print(d2-d1)

min = d2 - d1

#print(min)
#print(type(min))
#print(min.seconds)
print(min.seconds // 60 - K)
#h = (H2 - H1)*60
#m = (M2 - M1)


Measured memory_bytes: 9440
import java.util.*;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] p = {2, 3, 5, 7, 11, 13, 17, 19, 23 ,29, 31, 37, 41, 43, 47};
		int[] num = new int[15];
		int c2 = 0;
		int c4 = 0;
		int c14 = 0;
		int c24 = 0;
		int c74 = 0;
		for(int i=0; i<15; i++){
			int t = n;
			while(t>0){
				t /= p[i];
				num[i] += t;
			}
			if(num[i]>=2){
				c2++;
			}
			if(num[i]>=4){
				c4++;
			}
			if(num[i]>=14){
				c14++;
			}
			if(num[i]>=24){
				c24++;
			}
			if(num[i]>=74){
				c74++;
			}
		}
		int ans = 0;
		if(c74>=1){
			ans += 1;
		}
		if(c14>=1 && c4>=2){
			ans += c14 * (c4-1);
		}
		if(c24>=1 && c2>=2){
			ans += c24 * (c2-1);
		}
		if(c4>=2 && c2>=3){
			ans += (c4*(c4-1))/2 * (c2-2);
		}
		System.out.println(ans);
	}
}

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

using namespace std;


#define PI 3.14159265
#define int long long



main(){


	int a, b, k; cin >> a >> b >> k;

	cout << max(a - k, 0LL) << " " << min(b, max(a + b - k, 0LL)) << endl;
	
	
	return 0;
}

Measured memory_bytes: 256
n, q = map(int, input().split())
s = input()

t = [0] * (n+1)

for i in range(n):
  if s[i:i+2] == "AC":
    t[i+1] = t[i] + 1
  else:
    t[i+1] = t[i]

for i in range(q):
  l, r = map(int, input().split())
  l = l-1
  r = r-1
  print(t[r] - t[l])

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

using namespace std;
typedef int64_t ll;
typedef uint64_t ull;
typedef long double ld;

#define x first
#define y second

ld dist(pair<int, int> a, pair<int, int> b) {
	ld xd = a.x - b.x;
	ld yd = a.y - b.y;
	return sqrt(xd*xd + yd*yd);
}

int main() {
#ifdef cute
	freopen("in", "r", stdin);
#endif
	ios::sync_with_stdio(false);
	cin.tie(NULL);

	int n;
	cin >> n;
	pair<int, int> p[n];
	for(int i = 0; i < n; i++)
		cin >> p[i].x >> p[i].y;

	ld res = 0;
	for(int i = 0; i < n; i++) {
		for(int j = i+1; j < n; j++)
			res += dist(p[i], p[j])*2.0/(ld)n;
	}
	cout << setprecision(10) << fixed << res;



#ifdef cute
	cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << " ms.\n";
#endif
}

// g++ o .cpp -O2 -std=c++11 -D cute -Wall -Wno-unused-result



Measured memory_bytes: 256
def main():
    n = int(input())

    if n % 10 in (2, 4, 5, 7, 9):
        print('hon')
    elif n % 10 in (0, 1, 6, 8):
        print('pon')
    else:
        print('bon')

if __name__ == '__main__':
    main()


Measured memory_bytes: 9196
#include <stdio.h>
#include <string.h>

int main(){
int max;
int i,i1,i2,i3;
int q1,q2,q3,q4;
int p[4][3][10]={{{0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0}},{{0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0}},{{0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0}},{{0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0}}};
scanf("%d\n", &max);

for(i = 0;i < max;i++){
scanf("%d %d %d %d", &q1, &q2, &q3, &q4);
p[q1-1][q2-1][q3-1] += q4;
}
for(i1 = 0;i1 < 4; i1++){
for(i2 = 0;i2 < 3; i2++){
for(i3 = 0;i3 < 10;i3++){
printf(" %d",p[i1][i2][i3]);
}
printf("\n");
}
if(i1<3){
printf("####################\n");
}
}
return 0;
}

Measured memory_bytes: 612
#include<bits/stdc++.h>
using namespace std;
int a[100002],n,h[100002];
int fun(int x)
{
  if(x==n-1)
  {
    return 0;
  }
  if(x>=n)
  {
    return 1000000;
  }
  if(h[x]!=-1)
  {
    return h[x];
  }
  return(h[x]=min(fun(x+1)+abs(a[x+1]-a[x]),fun(x+2)+abs(a[x+2]-a[x])));
}
int main()
{
  cin>>n;
  memset(h,-1,sizeof(h));
  memset(a,0,sizeof(a));
  for(int i=0;i<n;i++)
  {
    cin>>a[i];
  }
  int c;
  c=fun(0);
  cout<<c;
  return 0;
}

Measured memory_bytes: 2560
def main():
    H, W, K = map(int, input().split())
    mapping = [input() for _ in range(H)]

    count = 0
    ans = []
    is_find_first_ichigo = False
    tmp = ""
    num = 0
    for i, line in enumerate(mapping):
        if "#" in line:
            num += 1
            is_find_first_ichigo = True
            first_ichigo = True
            tmp = []
            for c in line:
                if c == ".":
                    tmp.append(str(num))
                else:
                    if first_ichigo:
                        tmp.append(str(num))
                        first_ichigo = False
                    else:
                        num += 1
                        tmp.append(str(num))
            for _ in range(count):
                ans.append(tmp)
            count = 0
            ans.append(tmp)
        else:
            if is_find_first_ichigo:
                ans.append(tmp)
            else:
                count += 1

    for line in ans:
        print(" ".join(line))


if __name__ == "__main__":
    main()


Measured memory_bytes: 9332
#include <stdio.h>

int main(void)
{
	char s[11], t[11];
	int i, j = 0;
	
	scanf("%s", s);
	
	for(i = 0; s[i] != '\0'; i++) {
		if(s[i] != 'B') {
			t[j++] = s[i];
		}
		else if(j >0) {
			j--;
		}
	}
	t[j] = '\0';
	printf("%s", t);
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include<iomanip>
#include <string>
#include<vector>
#include<algorithm>
#include<utility>
#include<queue>
#include<math.h>
#include<stack>
#include<set>
#include<map>
#define INF long long int(1e18+1)
#define rep(i,n,m) for(int i=n;i<m;i++)

using namespace std;

int main() 
{
	int n;
	cin >> n;
	vector<long long int>a(n);
	rep(i, 0, n)cin >> a[i];
	sort(a.begin(), a.end());
	long long int ans = 0;
	reverse(a.begin(), a.end());
	ans = a[0];
	rep(i, 1, n / 2)ans += 2 * a[i];
	if (n % 2)ans += a[(n - 1) / 2];
	cout << ans << endl;
}


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

using namespace std;
typedef long long ll;
typedef pair<ll, ll> p_ll;

template<class T>
void debug(T itr1, T itr2) { auto now = itr1; while(now<itr2) { cout << *now << " "; now++; } cout << endl; }
#define repr(i,from,to) for (ll i=(ll)from; i<(ll)to; i++)
#define all(vec) vec.begin(), vec.end()
#define rep(i,N) repr(i,0,N)
#define per(i,N) for (int i=(int)N-1; i>=0; i--)

const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,30)-1;

vector<ll> fac;
void c_fac(int x=pow(10,6)+10) { fac.resize(x,true); rep(i,x) fac[i] = i ? (fac[i-1]*i)%MOD : 1; }
ll inv(ll a, ll m=MOD) { ll b = m, x = 1, y = 0; while (b!=0) { int d = a/b; a -= b*d; swap(a,b); x -= y*d; swap(x,y); } return (x+m)%m; }
ll nck(ll n, ll k) { return fac[n]*inv(fac[k]*fac[n-k]%MOD)%MOD; }
ll gcd(ll a, ll b) { if (a<b) swap(a,b); return b==0 ? a : gcd(b, a%b); }
ll lcm(ll a, ll b) { return a/gcd(a,b)*b; }


int main() {
  ll N, D; cin >> N >> D;
  ll d[N]; rep(i,N) cin >> d[i];
  ll Q; cin >> Q;
  ll q[Q]; rep(i,Q) { cin >> q[i]; q[i]--; }

  ll pos[N+1] = {}; rep(i,N+1) pos[i] = i==0 ? D : min(pos[i-1],abs(pos[i-1]-d[i-1]));
  ll out[N+1] = {}; per(i,N+1) out[i] = i==N ? 1 : out[i+1]*2>d[i] ? out[i+1]+d[i] : out[i+1];
  // debug(pos,pos+(N+1)); debug(out,out+(N+1));

  rep(i,Q) {
    string result = pos[q[i]]>=out[q[i]+1] ? "YES" : "NO";
    cout << result << endl;
  }
  return 0;
}

Measured memory_bytes: 19160
#include <stdio.h>
#include <math.h>

int main(){

	int n, i;
	int x[100], y[100];
	double d1, d2, d3, d4;

	scanf( "%d", &n );


	for( i=0; i<n; i++ ) scanf( "%d", &x[i] );
	for( i=0; i<n; i++ ) scanf( "%d", &y[i] );


	d1 = 0;
	for( i=0; i<n; i++ ) d1 += fabs( (double)x[i]-(double)y[i] );
	printf( "%f\n", d1 );

	d2 = 0;
	for( i=0; i<n; i++ ) d2 += pow( fabs((double)x[i]-(double)y[i]), 2 );
	printf( "%f\n", sqrt(d2) );	

	d3 = 0;
	for( i=0; i<n; i++ ) d3 += pow( fabs((double)x[i]-(double)y[i]), 3 );
	printf( "%f\n", cbrt(d3) );

	d4 = 0;
	for( i=0; i<n; i++ ) d4 = fmax(d4, abs(x[i]-y[i]));
	printf( "%f\n", d4 );

	return 0;

}

Measured memory_bytes: 712
#include <cmath>
#include <cstdio>
using namespace std;
int main(){
	int f[9] = {1, 1, 2, 6, 24, 120, 720, 5040, 40320};
	int n;
	scanf("%d", &n);
	int m = 2 * f[n - 1];
	int x[n], y[n];
	for (int i = 0; i < n; i++){
		scanf("%d %d", &x[i], &y[i]);
	}
	double sum = 0;
	for (int i = 0; i < n; i++){
		for (int j = i + 1; j < n; j++){
			double len = sqrt((x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j]));
			sum += len * m;
		}
	}
	printf("%.12lf\n", sum / f[n]);
}

Measured memory_bytes: 128
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<int,pii> pip;
typedef vector<pip>vip;
const double PI=acos(-1);
const double EPS=1e-7;
const int inf=1e8;
const ll INF=1e16;
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};
int main(){
	int n;
	cin>>n;
	vi in(3*n);
	rep(i,3*n)cin>>in[i];
	sort(all(in));
	ll out=0;
	rep(i,n)out+=in[3*n-(i+1)*2];
	cout<<out<<endl;
}









Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define N 1000005
typedef long long ll;
const ll LLINF=1ll<<60;
const int mx=1e6+7;
// int n;
//vector<int> a(mx),b(mx);
// vector<int> g[mx];
// int deg[mx];
// vector<int> adj[mx];
//vector<int> ans;
//---dfs--
//bool visited[mx];
//vector<ll> val(mx,0);

// void dfs(int s,int e,int c1,int c2){
// 	if(a[s]^c1!=b[s]) {ans.push_back(s), c1^=1;}
// 	for(auto u:adj[s]){
// 		if(u!=e){
// 			dfs(u,s,c2,c1);
// 		}
// 	}
// }
//---dfs---

//---primes---
// const int N = 1e7 + 10;

// bool prime[N];
 
// int spf[N];
 
// void calc(){
// 	for(int i = 2; i<1e4; i++){
// 		if(prime[i])
// 			continue;
// 		spf[i] = i;
// 		for(int j = i * i; j < N; j += i){
// 			prime[j] = 1;
// 			spf[j] = i;
// 		}
// 	}
// 	for(int i = 2; i < N; i++)
// 		if(!spf[i])
// 			spf[i] = i;
// }

// vector<pair<int,int>> getp(int x){
// 	int curr=x;
// 	vector<pair<int,int>> ans;
// 	while(curr>1){
// 		int a=spf[curr];
// 		int count=0;
// 		while(curr%a==0){ curr/=a; count++;}
// 		ans.push_back(make_pair(a,count));
// 	}
// 	return ans;
// }

// bool ispr(int n) {
// 	if(n==1) return false;
//     for (int i=2;i*i<=n;++i){
//         if(n%i==0){
//             return false;
//         }
//     }
//     return true;
// }
//---primes---

//---segment_tree---
// int upd(int t,int val,int l,int r,int y, int z){
// 	if(y<l||y>r) return tr[val];
// 	if(l==r) return tr[val]=z;
// 	int s=(l+r)/2;
// 	upd(t^1,2*val+1,l,s,y,z);
// 	upd(t^1,2*val+2,s+1,r,y,z);
// 	if(t) tr[val]=tr[2*val+1]|tr[2*val+2];
// 	else tr[val]=tr[2*val+1]^tr[2*val+2];
// 	return tr[val];
// }
//int query(){}
//---segment_tree---

int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);cout<<setprecision(25);
	int T=1;
	//cin>>T;
	while(T--){
		int n;
		cin>>n;
		vector<ll> a(n);
		for(int i=0;i<n;i++) cin>>a[i];
		vector<ll> pref(n,0);
		pref[0]=a[0];
		for(int i=1;i<n;i++){
			pref[i]=pref[i-1]+a[i];
			pref[i]%=MOD;
		}
		ll sum=0;
		for(int i=0;i<n-1;i++){
			sum+=1ll*(a[i]%MOD)*((pref[n-1]-pref[i]+MOD))%MOD;
			if(sum>MOD) sum-=MOD;
		}
		cout<<sum<<"\n";
 	}
}


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

#define rep(i,n) for(i = 0;i < n;++i)
#define all(v) v.begin(), v.end()
using ll = long long;

int main()
{
    ll i,j;
    ll x;
    cin >> x;
    ll tmp = x%100;
    ll spare = (x - tmp)/100;
    ll cnt = 0;
    cnt += tmp/5;
    tmp %= 5;
    if(tmp != 0) ++cnt;
    if(spare >= cnt) cout << 1 << endl;
    else cout << 0 << endl;

    return 0;
}

Measured memory_bytes: 3620
n,m = map(int,input().split())
arr = list(map(int,input().split()))

arr.sort(reverse=True)
sum_arr = sum(arr)
flag = True

b = sum_arr/(4*m)
for i in range(m):
    if arr[i] < b:
        flag = False
        break
if flag:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 3060
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <math.h>
#include <malloc.h>

#define char_max 200000

int Pow(int n, int m);
int Max(int N[], int n);
int Min(int N[], int n);
int Sum(int N[], int n);





int main()
{
	int sunuke = 0;
	int ans = 0;

	scanf("%d", &sunuke);
	
	for (int i = 0; sunuke != 0; i++) {
		if (sunuke % 10 == 1) {
			ans += 9 * Pow(10, i);
		}
		else if (sunuke % 10 == 9) {
			ans += 1 * Pow(10, i);
		}
		sunuke = sunuke / 10;
	}

	printf("%d", ans);


	return 0;
}

int Pow(int n, int m) {
	int ret = 1;

	for (int i = 0; i < m; i++) {
		ret *= n;
	}

	return ret;
}

int Max(int N[], int n) {
	int max = N[0];

	for (int i = 0; i < n; i++) {
		max = max < N[i] ? N[i]: max;
	}

	return max;
}

int Min(int N[], int n) {
	int min = N[0];

	for (int i = 0; i < n; i++) {
		min = min > N[i] ? N[i] : min;
	}

	return min;
}

int Sum(int N[], int n) {
	int sum = 0;

	for (int i = 0; i < n; i++) {
		sum += N[i];
	}

	return sum;
}

Measured memory_bytes: 128
N,K = map(int,input().split())
A = list(map(int,input().split()))
def divisor_all(n): # 約数全列挙
    l = [1,n]
    for i in range(2,int(pow(n,1/2))+1):
        if n % i == 0:
            if i == n//i:
                l.append(i)
            else:
                l.append(i)
                l.append(n//i)
    l.sort(reverse=True)
    return l # list
D = divisor_all(sum(A))
def accumulater1D(A): # B:list[int]
    B = [0]*len(A)
    B[0] = A[0]
    for i in range(1,len(B)):
        B[i] = B[i-1]+A[i]
    return B # Aの1次元累積和
import bisect
ans = 0

for d in D:
    R = [A[i]%d for i in range(N) if A[i]%d!=0]
    nr = len(R)
    
    R.sort()
    if len(R)==0:
        ans = d
        break
    LR = accumulater1D(R)
    RR = list(reversed(accumulater1D([d-R[nr-1-i] for i in range(nr)])))
    
    for i in range(nr-1):
        if LR[i]==RR[i+1]:
            if LR[i]<=K:
                ans = d
                break
    if ans != 0:
        break
print(ans)





Measured memory_bytes: 3188
#include <stdio.h>
int main(){
  int n,m,x,i,j,r=0,s=0,a[100];
  scanf("%d%d%d",&n,&m,&x);
  for(i=0;i<m;i++)scanf("%d",&a[i]);
  for(i=x;i<=n;i++)for(j=0;j<m;j++)if(i==a[j])r++;
  for(i=0;i<=x;i++)for(j=0;j<m;j++)if(i==a[j])s++;
  printf("%d",r>s?s:r);
  return 0;
}

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

using namespace std;

const int MAX_N = 100;

int n, l;

string s[MAX_N + 1];

bool comp(string &a, string &b) {
    return a + b < b + a;
}

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

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

    sort(s + 1, s + n + 1, comp);

    for (int i = 1; i <= n; i++) {
        cout << s[i];
    }
    cout << '\n';

    return 0;
}


Measured memory_bytes: 256