akhauriyash/Code-Regression huggingface dataset:
import java.io.InputStream;
import java.io.PrintStream;
import java.util.Scanner;

public class Main {
	InputStream in = System.in;
	PrintStream out = System.out;

	public void _main(String[] args) {
		Scanner sc = new Scanner(in);

		int N = sc.nextInt();
		long[] A = new long[N];
		for(int i=0;i<N;i++) {
			A[i] = sc.nextLong();
		}

		sc.close();


		long mod = 1000000007;

		int[][] bitCntSum = new int[N+1][63]; // iより前のbitの立ってる数

		for(int i=1;i<=N;i++) {
			long n = A[i-1];

			for(int j=0;j<63;j++) {
				bitCntSum[i][j] = (int)(bitCntSum[i-1][j] + ((n>>j)&1));
			}
		}

		long ans = 0;

		for(int j=0;j<63;j++) {
			// bitごとにみる
			for(int i=0;i<N;i++) {
				long c;
				if((A[i]>>j &0x1) == 1) {
					// 1なら、それより右の0の数を数える
					c = (N-i) - (bitCntSum[N][j] - bitCntSum[i][j]);
				}else {
					// 0なら、それより右の1の数を数える
					c = bitCntSum[N][j] - bitCntSum[i][j];
				}
				ans += (c%mod) * ((1L<<j)%mod);
				ans %= mod;
			}
		}

		ans %= mod;

		out.println(ans);

	}

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


Measured memory_bytes: 131188
fun main() = Thread(null, ::abc173b, "(^o^)", 128 * 1024 * 1024).apply { start() }.join()

@OptIn(ExperimentalStdlibApi::class)
fun abc173b() {
    val n = readLine()!!.toInt()
    val sList = Array(n) { readLine()!! }

    val grouped = sList.groupBy { it }.mapValues { it.value.size }

    val answer = listOf("AC", "WA", "TLE", "RE").map { it to (grouped[it] ?: 0) }
        .joinToString(System.lineSeparator()) { "${it.first} x ${it.second}" }

    println(answer)
}


Measured memory_bytes: 63108
#include <stdio.h>


int main(void)
{
	char num[1001];
	int i, sum;

	while(scanf("%s", num)!=EOF && num[0]!='0'){
		sum = 0;

		for(i=0;num[i]!='\0';i++){
			sum += num[i] - '0';
		}

		printf("%d\n", sum);
	}

	return 0;
}

Measured memory_bytes: 536
#![allow(
    non_snake_case,
    unused_variables,
    unused_assignments,
    unused_mut,
    dead_code
)]
//use permutohedron::LexicalPermutation as _;
use proconio::{fastout, input};
//use proconio::marker::Chars;
//use proconio::marker::Usize1;
//use std::collections::HashSet;
//use std::collections::HashMap;
//use std::collections::BTreeMap;
//use std::cmp::*;
//use std::num;

#[fastout]
fn main() {
    input! {
        N:usize
    }
    let mut f = vec![1usize; N + 1];
    let mut ans = 1;
    for i in 2..N + 1 {
        let mut j = i;
        while j <= N {
            f[j] += 1;
            j += i;
        }
        ans += i * f[i];
    }
    println!("{}", ans);
}


Measured memory_bytes: 80132
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.*;


public class Main {

    int N,M;
    Pair[] pairs;

    private class Pair  {
        int n,p,y;
        public Pair(int n,int p,int y) {
            this.n = n;
            this.p = p;
            this.y = y;
        }
    }

    private void solve() {
        N = nextInt();
        M = nextInt();

        pairs = new Pair[M];
        for(int i = 0;i < M;i++) {
            int P = nextInt();
            int Y = nextInt();

            pairs[i] = new Pair(i, P, Y);
        }

        Arrays.sort(pairs, (p1, p2) -> {
            if (p1.p == p2.p) {
                return p1.y - p2.y;
            }

            return p1.p - p2.p;
        });

        int[] seq = new int[N + 1];
        String[] ans = new String[M];
        for(int i = 0;i < M;i++) {
            seq[pairs[i].p]++;

            ans[pairs[i].n] = String.format("%06d%06d", pairs[i].p, seq[pairs[i].p]);
        }

        for(int i = 0;i < M;i++) {
            out.println(ans[i]);
        }
    }

    public static void main(String[] args) {
        out.flush();
        new Main().solve();
        out.close();
    }

    /* Input */
    private static final InputStream in = System.in;
    private static final PrintWriter out = new PrintWriter(System.out);
    private final byte[] buffer = new byte[4096];
    private int p = 0;
    private int buflen = 0;

    private boolean hasNextByte() {
        if (p < buflen)
            return true;
        p = 0;
        try {
            buflen = in.read(buffer);
        } catch (IOException e) {
            e.printStackTrace();
        }
        if (buflen <= 0)
            return false;
        return true;
    }

    public boolean hasNext() {
        while (hasNextByte() && !isPrint(buffer[p])) {
            p++;
        }
        return hasNextByte();
    }

    private boolean isPrint(int ch) {
        if (ch >= '!' && ch <= '~')
            return true;
        return false;
    }

    private int nextByte() {
        if (!hasNextByte())
            return -1;
        return buffer[p++];
    }

    public String next() {
        if (!hasNext())
            throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = -1;
        while (isPrint((b = nextByte()))) {
            sb.appendCodePoint(b);
        }
        return sb.toString();
    }

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

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

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


Measured memory_bytes: 115124
N = int(input())
T, A = map(int, input().split())
Hs = list(map(int, input().split()))
diff = 100000000
ans = 0
for i in range(N):
    tmp = abs(A - T + Hs[i] * 0.006)
    if diff > tmp: 
        diff = tmp
        ans = i+1

print(ans)

Measured memory_bytes: 3060
def Main(N, K, d, A):
    se = set()
    for a in A:
        se.update(a)
    return N - len(se)
        
def main():
    N, K = map(int, input().split())
    d = []
    A = []
    for i in range(K):
        d.append(int(input()))
        A.append(list(map(int, input().split())))
    print(Main(N, K, d, A))

if __name__ == '__main__':
    main()

Measured memory_bytes: 9208
import java.util.Scanner;

public class Main{
  public static void main(String[] args){
    Scanner scanner = new Scanner(System.in);
    int A = scanner.nextInt();
    int B = scanner.nextInt();
    int C = scanner.nextInt();
    int D = scanner.nextInt();
    
    System.out.println(cal(A,D) >= cal(C,B) ? "Yes" : "No");
  }
  
  private static int cal(int a,int b){
    int i;
    for(i = 0;a - b > 0;i++){
      a = a - b;
    }
    return i;
  }
}

Measured memory_bytes: 27080
#include<iostream>

using namespace std;

int main()
{
	int A,B,C,D;
	int time[101];
	int ans = 0;

	cin >> A >> B >> C >> D;

	for(int i=0;i<101;i++)
	{
		time[i] = 0;
	}

	for(int i=A;i<B;i++)
	{
		time[i]++;
	}

	for(int i=C;i<D;i++)
	{
		time[i]++;
	}

	for(int i=0;i<101;i++)
	{
		if(time[i] == 2)
		{
			ans++;
		}
	}

	cout << ans << endl;

	return 0;
}

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

int main(){
    int n;cin>>n;
    int l=-1;
    for(int i=1;i<=n;++i){
        int h;cin>>h;
        if(h-1>=l){
            l=h-1;
        }else if(h>=l){
            l=h;
        }else{
            printf("No");
            return 0;
        }
    }
    printf("Yes");
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(c) (c).begin(), (c).end()
#define pb push_back
#define eb emplace_back
const long long INF = 1LL<<60; // 仮想的な無限大の値;
using namespace std;
using ll = long long;
using P  = pair<int, int>;
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; }

int main()
{
    //二分木
    int N;
    cin >> N;
    vector<ll> A(N);
    rep(i, N) cin >> A[i];
    // sort(A.begin(), A.end());
    // reverse(A.begin(), A.end());
    sort(A.rbegin(), A.rend());//リバースイテレータ
    ll ans = 0;
    int t = N-1;
    rep(i, N)
    {
        int lim = 2;
        if(i == 0) lim = 1;
        rep(j, lim)
        {
            if(t > 0)
            {
                ans += A[i];
                t--;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4844
#include<bits/stdc++.h>
#define pb push_back
using namespace std;
typedef long long ll;
struct edge{int to;ll cost;};
typedef pair<ll,int> P;
const ll INF=1000000000000LL;
const ll MOD=1000000007LL;
const ll MAX=100010;
int main(){
	int a[10];
	for(int i=0;i<10;i++){
		cin>>a[i];
	}
	sort(a,a+10,greater<int>());
	cout<<a[0]<<endl;
	cout<<a[1]<<endl;
	cout<<a[2]<<endl;
	return 0;
}



Measured memory_bytes: 3036
#include <iostream>
#include <climits>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
 
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

#define MOD 1000000007LL

int main()
{
  ll x;

  cin >> x;

  if (x>=30) {
    printf("Yes\n");
  } else {
    printf("No\n");
  }

  return 0;
}


Measured memory_bytes: 3632
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <functional>
#include <ccomplex>
#include <unordered_map>
#include <cstring>
#include <iostream>
#include <numeric>
#include <sstream>
#include <set>
#include <tuple>
#include <iomanip>
#include <bitset>
#include <map>

using namespace std;
#define MAX 1LL << 60

typedef long long ll;
typedef unsigned long long ull;

#define rep(i, s, e) for(ll i = s; i < e; i++)
#define repR(i, s, e) for(ll i = s; i > e; i--)
#define reft0(i, j) setfill('0') << setw(i) << j

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

int main(){
	int cnt = 0;
	rep(i, 0, 3){
		char tmp;
		cin >> tmp;
		if (tmp == 'o') cnt++;
	}

	cout << 700 + 100 * cnt << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void)
{
   long long a,b;
   long long max = 0;
   long long min = 0;
   long long sum = 0;
   long long i;
   
   scanf("%lld", &a);
   
   for(i=1;i<=a;i++){
      scanf("%lld", &b);
   	
   	if(i==1){
   		min = b;
   		max = b;
   	}
      
      if(min>b){
         min = b;}
      if(max<b){
         max = b;    }
      
      sum += b;
   }
   
   printf("%lld %lld %lld\n", min,max,sum);
   
   return 0;
}


Measured memory_bytes: 2092
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N=15;
int x[N],y[N],p[N],mix[1<<N][N],miy[1<<N][N];
LL ans[N+5];
int main(){
	int n,s;scanf("%d",&n),s=(1<<n);
	for(int i=0;i<n;i++)scanf("%d%d%d",x+i,y+i,p+i);
	for(int i=0;i<s;i++){
		for(int j=0;j<n;j++){
			mix[i][j]=abs(x[j]),miy[i][j]=abs(y[j]);
			for(int k=0;k<n;k++)if(i&(1<<k))
				mix[i][j]=min(mix[i][j],abs(x[j]-x[k])),miy[i][j]=min(miy[i][j],abs(y[j]-y[k]));
		}
	}
	LL w,w1;memset(ans,0x1f,sizeof(ans));
	for(int i=0,j=0;i<s;i++,j=i){
		do{
			w1=w=0;
			for(int k=0;k<n;k++)if(i&(1<<k))w++;
				else w1+=1ll*min(mix[j][k],miy[i^j][k])*p[k];
			ans[w]=min(ans[w],w1);
			j=(j-1)&i;
		}while(i!=j);
	}
	for(int i=0;i<=n;i++)printf("%lld\n",ans[i]);
	return 0;
} 

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

using namespace std;

typedef long long ll;

template<typename T>
void _dump(const char* s, T&& head)
{
  cerr << s << "=" << head << endl;
}

template<typename T, typename... Args>
void _dump(const char* s, T&& head, Args&&... tail)
{
  while (*s != ',')
    cerr << *s++;
  cerr << "=" << head << ",";
  _dump(s + 1, tail...);
}

template<typename T>
void _dumpv(const char* s, T&& v)
{
  cerr << *s << "=";
  for (auto it = v.begin(); it != v.end(); it++) {
    cerr << *it << " ";
  }
  cerr << endl;
}

#define dump(...) _dump(#__VA_ARGS__, __VA_ARGS__)
#define dumpv(...) _dumpv(#__VA_ARGS__, __VA_ARGS__)
// #define dump(...)
// #define dumpv(...)

const ll MOD = 1000000007;

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  // freopen("template.1", "r", stdin);

  int N, K;
  cin >> N >> K;
  cout << (K == 1 ? 0 : N - K) << endl;
  return 0;
}


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

//.define
// #define FILE_IN_OUT
#define RET(_x)    return cout << (_x) << '\n', 0;
#define all(_obj)  (_obj).begin(), (_obj).end()
#define loop(_n)   for (int i = 0; i < (_n); ++i)
#define sz(_obj)   static_cast<int>((_obj).size())
#ifdef SHJ_LOCAL
#define debug(_x)  std::cerr << (#_x) << " = " << (_x) << '\n' << std::flush;
#else
#define debug(_x)  {}
#endif
#define endl "\n"
template<typename P, typename Q>
P CeilDiv(P _dividend, Q _divider) {
    return static_cast<P>((_dividend - 1LL + _divider) / _divider);
}
template<typename Tp>
inline void outarr(Tp _begin, Tp _end, const char* _delim = " ") {
    for (Tp current = _begin; current != _end; ++current) {
        std::cout << *current << _delim;
    }
    std::cout << '\n';
}

//.constant
using ll  = long long;
using pii = std::pair<int, int>;
constexpr int INF = 0x3f3f3f3f;
constexpr int MOD = static_cast<const int>(1e9 + 7);

//.data

//.code
int main() {
#ifdef FILE_IN_OUT
    std::ifstream cin ("input.txt",  std::ios::in);
    std::ofstream cout("output.txt", std::ios::out);
#else
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);
#endif

    int n;
    cin >> n;
    map<pii, int> cnt;
    loop(n) {
        double x;
        cin >> x;
        ll val = llround(x * 1e9);
        int two = -9;
        while (val % 2 == 0) {
            val >>= 1;
            ++two;
        }
        int five = -9;
        while (val % 5 == 0) {
            val /= 5;
            ++five;
        }
        ++cnt[{two, five}];
    }
    ll ans = 0;
    for (auto [tf1, k1] : cnt) {
        for (auto [tf2, k2] : cnt) {
            if (tf1.first + tf2.first >= 0 && tf1.second + tf2.second >= 0) {
                if (tf1 == tf2) {
                    ans += 1LL * k1 * (k2 - 1);
                } else {
                    ans += 1LL * k1 * k2;
                }
            }
        }
    }
    cout << ans / 2 << endl;

#ifdef FILE_IN_OUT
    cin.close();
    cout.close();
#endif
    return 0;
}

Measured memory_bytes: 3700
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		while(true){
			int H=sc.nextInt();
			int W=sc.nextInt();
			if(H==0 && W==0){
				break;
			}
			for(int i=1;i<=H;i++){
				for(int j=1;j<=W;j++){
					if(i%2==1){
						if(j%2==1){
							System.out.print("#");
						}else{
							System.out.print(".");
						}
					}else{
						if(j%2==1){
							System.out.print(".");
						}else{
							System.out.print("#");
						}
					}
					if(j==W){
						System.out.println();
					}
				}
				if(i==H){
					System.out.println();
				}
			}
		}
	}

}



Measured memory_bytes: 37084
sx, sy, tx, ty = map(int, input().split())
dx, dy = tx-sx, ty-sy
print(dy*'U'+dx*'R' + dy*'D'+dx*'L' + 'L'+(dy+1)*'U'+(dx+1)*'R'+'D' + 'R'+(dy+1)*'D'+(dx+1)*'L'+'U')

Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <cmath>
#include <queue>
#include <deque>
#include <set>
#include <iomanip>
#include <utility>
#define ll long long
#define ld long double
using namespace std;

ll K;

void memo(vector<vector<int>> &v, vector<ll> &u, int key){
    int cnt=0;
    for(int i=0; i<v[key].size(); ++i){
        if(u[v[key][i]]<0){
            ++cnt;
            if(key==1){
                u[v[key][i]]=max(K-cnt, (ll) 0);
            }else{
                u[v[key][i]]=max(K-cnt-1, (ll) 0);
            }
            memo(v, u, v[key][i]);
        }
    }
}

int main() {
	ll N;
	cin >> N >> K;
	vector<vector<int>> g(N+1);
	for(int i=1; i<N; ++i){
	    int a, b;
	    cin >> a >> b;
	    g[a].push_back(b);
	    g[b].push_back(a);
	}
	vector<ll> comb(N+1, -1);
	comb[1]=K;
	memo(g, comb, 1);
	ll ans=1, mod=1000000007;
	for(int i=1; i<=N; ++i) ans=(ans*comb[i])%mod;
	cout << ans << endl;
	return 0;
}


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

int main() {
    int n;
    int count=0;
    cin >> n;
    int a[n];
    int b[n];
    int c[n-1];
    for (int i = 0; i < n; i++) cin >> a[i];
    for (int i = 0; i < n; i++) cin >> b[i];
    for (int i = 0; i < (n-1); i++) cin >> c[i];

    for (int i = 0; i < n; i++){
        count+=b[i];
    }
    for (int i = 0; i < n-1; i++)
    {
        if (a[i]==(a[i+1]-1))
        {
            count+=c[a[i]-1];
        }
    }
    cout << count << endl;
}

Measured memory_bytes: 256
N = int(input())
a = list(map(int, input().split()))
ave1 = int(sum(a)/N+0.5)
ave2 = ave1-1
ave3 = ave1+1
ans1, ans2, ans3 = 0, 0, 0
for i in range(N):
    ans1 += (ave1 - a[i])**2
    ans2 += (ave2 - a[i])**2
    ans3 += (ave3 - a[i])**2

print(min(ans1, ans2, ans3))

Measured memory_bytes: 3064
def lscan; gets.split.map(&:to_i); end

a,v = lscan
b,w = lscan
t = gets.to_i

if v <= w
  puts 'NO'
else
  d = (b-a).abs
  u = v - w
  if (d.to_r/u) <= t
    puts 'YES'
  else
    puts 'NO'
  end
end

Measured memory_bytes: 14376
#include <iostream>
#include <fstream>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <numeric>
#include <queue>
using namespace std;
 
#define LOCAL  1
#define UPLOAD 2
 
#define ll long long
const long long INF = 1LL << 60;
 
template <class T = long long> T input(){T x;cin >> x;return x;}
template <class T> void output(T x){cout << x << endl;}
#define debug(x) cerr << #x<< ": " << x<< '\n';
#define debugBit(x,n) cerr << #x<< ": " << std::bitset<n>(x) << '\n';
#define REP(i,M) for(int i=0;i<M;i++)
 
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;}
ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
 
int main()
{
#if ENVIRONMENT == LOCAL
    std::ifstream in("input.txt");
    std::cin.rdbuf(in.rdbuf());
#endif

  vector<vector<ll>> A;
  vector<vector<bool>> ret;
  
  for(int i=0;i<3;i++){
    vector<ll> temp;
    for(int j=0;j<3;j++){
      temp.push_back(input());
    }
    A.push_back(temp);
  }

  ret = {
    {false,false,false},{false,false,false},{false,false,false}
  };

  ll N = input();
  for(int i=0;i<N;i++){
    ll a = input();
    for(int j=0;j<3;j++){
      for(int k=0;k<3;k++){
        if(A[j][k] == a){
          ret[j][k] = true;
        }
      }
    }
  }

  for(int i=0;i<3;i++){
    if(ret[i][0] && ret[i][1] && ret[i][2]){
      output("Yes");
      return 0;
    }
    if(ret[0][i] && ret[1][i] && ret[2][i]){
      output("Yes");
      return 0;
    }
    
  }
  if(ret[0][0] && ret[1][1] && ret[2][2]){
    output("Yes");
    return 0;
  }
  if(ret[0][2] && ret[1][1] && ret[2][0]){
    output("Yes");
    return 0;
  }

  output("No");
  
  return 0;
}

Measured memory_bytes: 256
using System;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            string input = Console.ReadLine();
            string[] inputA = input.Split();
            int[] inputi = new int[2];
            inputi[0] = int.Parse(inputA[0]);
            inputi[1] = int.Parse(inputA[1]);
            int n, n2;
            if (inputi[0] > inputi[1])
            {
                n = inputi[0] % inputi[1];
                n2 = inputi[1];
            }
            else if (inputi[0] < inputi[1])
            {
                n = inputi[1] % inputi[0];
                n2 = inputi[0];
            }
            else
            { 
                n = inputi[0];
                n2 = inputi[1];
            }
            int gcd = 0;
            for (int i = 1; i <= n; i++)
            {
                if (n % i == 0 && n2 % i == 0)
                    gcd = i;
            }
            Console.WriteLine(gcd);
            Console.ReadLine();

            //string sN = Console.ReadLine();
            //int N = int.Parse(sN);
            //string st = Console.ReadLine();
            //string[] ast = st.Split();
            //int[] A = new int[ast.Length];
            //for (int n = 0; n < N; n++)
            //{
            //    A[n] = int.Parse(ast[n]);

            //}
            //int key;
            //int j;
            //for (int i = 0; i < A.Length; i++)
            //{
            //    if (i != 0)
            //    {
            //        key = A[i];
            //        /* insert A[i] into the sorted sequence A[0,...,j-1] */
            //        j = i - 1;
            //        while (j >= 0 && A[j] > key)
            //        {
            //            A[j + 1] = A[j];
            //            j--;
            //        }
            //        A[j + 1] = key;
            //    }

            //    string output = "";

            //    for (int ii = 0; ii < A.Length; ii++)
            //    {

            //        output += A[ii] + " ";
            //    }
            //    output = output.TrimEnd(' ');
            //    Console.WriteLine(output);

            //}
            //Console.ReadLine();
        }
    }
}

Measured memory_bytes: 7628
import java.util.*


private val readString: ()->String = {readLine()!!}
private val readInt: ()->Int = { readLine()!!.toInt() }
private val readLong: ()->Long = { readLine()!!.toLong() }
private val readListInt: ()->List<Int> = { readLine()!!.split(' ').map(String::toInt) }
private val readListLong: ()->List<Long> = { readLine()!!.split(' ').map(String::toLong) }
private val errPrintln: (String)->Unit = { msg -> System.err.println(msg) }


internal class Position(var x: Int, var y: Int)

fun solveA(G: Array<String>): Int {
    val H = G.size
    val W = G[0].length
    val INF = Int.MAX_VALUE / 2
    val step = Array(H) { IntArray(W) }
    val starts: ArrayList<Position> = ArrayList<Position>()
    for (i in 0 until H) {
        for (j in 0 until W) {
            step[i][j] = INF
            if (G[i][j] == '#') {
                starts.add(Position(i, j))
            }
        }
    }
    val dx = intArrayOf(0, 1, 0, -1)
    val dy = intArrayOf(1, 0, -1, 0)
    val que: ArrayDeque<Position> = ArrayDeque<Position>()
    for (i in starts.indices) {
        que.addLast(starts[i])
        step[starts[i].x][starts[i].y] = 0
    }
    var res = 0
    while (!que.isEmpty()) {
        val pos: Position = que.removeFirst()
        val x: Int = pos.x
        val y: Int = pos.y
        for (i in dx.indices) {
            val nx = x + dx[i]
            val ny = y + dy[i]
            if (nx < 0 || H <= nx || ny < 0 || W <= ny) {
                continue
            }
            if (step[nx][ny] > step[x][y] + 1) {
                step[nx][ny] = step[x][y] + 1
                que.addLast(Position(nx, ny))
                res = Math.max(res, step[nx][ny])
            }
        }
    }
    return res
}



fun main(args: Array<String>) {
    val (H, W) = readListInt()
    val A = Array<String>(H){""}
    for (i in 0 until H) {
        A[i] = readString()
    }

    val ans = solveA(A)

    println(ans)
}


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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
string char_to_string(char val) {
  return string(1, val);
}
int char_to_int(char val) {
  return val - '0';
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

int N, M, Q;
vector<int> a, b, c, d;
ll ans = 0;

void dfs(vector<int> &A) {
  // 終了条件
  if(A.size() == N) {
    ll tmp = 0;
    REP(i, Q) {
      if(A[b[i] - 1] - A[a[i] - 1] == c[i]) {
        tmp += d[i];
      }
    }
    if(ans < tmp) {
      ans = tmp;
    }
    return;
  }

  // 再帰
  int first;
  if(A.empty()) {
    first = 1;
  } else {
    first = A[A.size() - 1];
  }
  for(int i = first; i <= M; ++i) {
    A.push_back(i);
    dfs(A);
    A.pop_back();
  }
}

int main() {
  cin >> N >> M >> Q;
  a.resize(Q); b.resize(Q); c.resize(Q); d.resize(Q);
  REP(i, Q) cin >> a[i] >> b[i] >> c[i] >> d[i];
  vector<int> A;
  dfs(A);
  cout << ans << endl;
}

Measured memory_bytes: 3628
N = int(input())
A = [int(i) for i in input().split()]
c = 0
for i in range(0,N):
    minj = i
    for j in range(i, N):
        if A[j] < A[minj]:
            minj = j
    A[i], A[minj] = A[minj], A[i]
    if i != minj:
        c += 1
print(" ".join(map(str, A)))
print(c)


Measured memory_bytes: 5604
#include<bits/stdc++.h>
using namespace std;
#define ll long long
typedef pair<ll,ll> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
#define M 1000000007
#define all(a) (a).begin(),(a).end()
#define rep(i,n) reps(i,0,n)
#define reps(i,m,n) for(int i=(m);i<(n);i++)
int main(){
  double a,b,c,d;cin>>a>>b>>c;
  if(c==0.0)d=(b-1.0)/a;
  else d=2.0*(b-1.0)*(a-c)/(a*a);
  cout<<fixed<<setprecision(18)<<d;
}

Measured memory_bytes: 256
n,m,c=gets.split.map(&:to_i)
b=gets.split.map(&:to_i)
a=Array.new(m)

sum=0
ans=0
n.times do |i|
    sum=0
    a=gets.split.map(&:to_i)
    m.times do |j|
        sum+=a[j]*b[j]
    end
    if sum > -c
        ans+=1
    end
end
puts ans


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

using ll = long long;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = (n-1); i >= 0; i--)
#define all(n) n.begin(), n.end()
#define print(n) cout << n << endl
ll mods = 1000000007;

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    //print(fixed << setprecision(10));
    
    int k;
    string s;
    cin >> k >> s;

    if(s.size() <= k) print(s);
    else print(s.substr(0,k) << "...");

    return 0;
}

Measured memory_bytes: 3652
/// How many numbers x are there in the range a to b, where the digit d occurs exactly k times in x?
//https://github.com/flash7even/Programming-Contest/blob/master/Code%20Repository/Dynamic%20Programming/Digit%20DP/Digit-DP.cpp
#include <bits/stdc++.h>
using namespace std;
#define int long long
vector<int> num;
int a, b, d, k;
int DP[120][120][2];
/// DP[p][c][f] = Number of valid numbers <= b from this state
/// p = current position from left side (zero based)
/// c = number of times we have placed the digit d so far
/// f = the number we are building has already become smaller than b? [0 = no, 1 = yes]

int call(int pos, int cnt, int f){
    if(cnt > k) return 0;

    if(pos == num.size()){
        if(cnt == k) return 1;
        return 0;
    }

    if(DP[pos][cnt][f] != -1) return DP[pos][cnt][f];
    int res = 0;

    int LMT;

    if(f == 0){
        /// Digits we placed so far matches with the prefix of b
        /// So if we place any digit > num[pos] in the current position, then the number will become greater than b
        LMT = num[pos];
    } else {
        /// The number has already become smaller than b. We can place any digit now.
        LMT = 9;
    }

    /// Try to place all the valid digits such that the number doesn't exceed b
    for(int dgt = 0; dgt<=LMT; dgt++){
        int nf = f;
        int ncnt = cnt;
        if(f == 0 && dgt < LMT) nf = 1; /// The number is getting smaller at this position
        if(dgt == d) ncnt++;
        if(ncnt <= k) res += call(pos+1, ncnt, nf);
    }

    return DP[pos][cnt][f] = res;
}


signed main () {

    string s;
    cin >> s;
    cin >> k;
    k = s.size()-k;
    for(int i=0;i<s.size();i++){
      num.push_back(s[i]%48);
    }
    // cin >> a >> b >> d >> k;
    d = 0;
    memset(DP, -1, sizeof(DP));
    int res = call(0, 0, 0);
    // int res = call(0,0,0);
    if(k==1)res--;
    cout << res << endl;

    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; ++i)
#define REPP(i, n) for(int i = 1; i <= n; ++i)
#define REPR(i, n) for(int i = n-1; i >= 0; --i)
#define FOR(i, m, n) for(int i = m; i < n; ++i)
#define ALL(v) v.begin(), v.end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1000000007;
const ll INF = 1000000000;

template<typename T1,typename T2> inline void chmin(T1 &a,T2 b) {if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b) {if(a<b) a=b;}

struct UnionFind {
    vector<int> par, size;
    UnionFind(int n) : par(n), size(n,1) {
        for(int i = 0; i < n; ++i) par[i] = i;
    }
    void Union(int x, int y) {
        x = Find(x), y = Find(y);
        if(x == y) return;
        if(size[x] < size[y]) swap(x,y);
        size[x] += size[y];
        par[y] = x;
    }
    int Find(int x) {
        if(par[x]==x) return x;
        else return par[x] = Find(par[x]);
    }
    bool Same(int x, int y) {
        return Find(x) == Find(y);
    }
    int Size(int x) {
        return size[Find(x)];
    }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,m; cin >> n >> m;
    vector<int> p(n);
    REP(i,n) {
        cin >> p[i]; -- p[i];
    }
    UnionFind uf(n);
    REP(i,m) {
        int x,y; cin >> x >> y; --x, --y;
        uf.Union(x,y);
    }
    int ans = 0;
    REP(i,n) {
        if(uf.Same(uf.par[i],p[i])) ++ ans;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
 
int main() {
	string S,T;
  cin >> S >> T ;
  
  int flag = 0;
  
  for(int i = 0 ; i < S.size() ; i++){
  	if(S.at(i) != T.at(i)){
    	flag = 1;
    }
  }
  if(flag==1){
  	cout << "No" << endl;
  }else{
  	cout << "Yes" << endl;
  }
}

Measured memory_bytes: 3632
// Why am I so dumb? :c
#include <bits/stdc++.h>

#define pb push_back
#define mp make_pair

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

#define fi first
#define se second

using namespace std;

typedef long long ll;

int arr[200005];

int n, ans;

void solve() {                   
	scanf("%d", &n);

    for (int i = 1, x; i <= n; ++i) {
    	scanf("%d", &x);
    	arr[x] = i;
    }

    for (int l = 1, r; l <= n; l = r) {
		r = l + 1;

	    while (r <= n && arr[r] > arr[r - 1]) {
	    	++r;
	    }

	    ans = max(ans, r - l);
    }

    printf("%d\n", n - ans);
}

int main() {    
    int tt = 1;

    while (tt--) {
        solve();
    }

    return 0;
}

Measured memory_bytes: 1024
n = gets.to_i
tasks = n.times.map { gets.strip.split.map(&:to_i) }.sort_by(&:last)

time = 0
flag = true
tasks.each do |duration, limit|
  time += duration
  if time > limit
    flag = false
    break
  end
end

puts(flag ? "Yes" : "No")


Measured memory_bytes: 34688
#include<cstdio>
#include<iostream>
#include<algorithm>

using namespace std;

const int N = 1000005;

int n;
char s[N];
int t[N];

int main()
{
	scanf("%d",&n);
	scanf("%s",s+1);
	for(int i=1;i<=n;i++) s[i]--;
	
	int sum=0,c=0;
	t[0]=t[1]=0;
	for(int i=2;i<=n;i++)
		if(i&1) t[i]=0;
		else t[i]=t[i/2]+1;
	for(int i=1;i<=n;i++){
		if(i>1) c+=t[n-i+1]-t[i-1];
		if(s[i]=='1' && c==0) sum^=1;
	}
	if(sum==1) { printf("1\n"); return 0; }
	
	for(int i=1;i<=n;i++)
		if(s[i]=='1') { printf("0\n"); return 0; }
	
	sum=0; c=0;
	for(int i=1;i<=n;i++){
		if(i>1) c+=t[n-i+1]-t[i-1];
		if(s[i]=='2' && c==0) sum^=1;
	}
	if(sum==1) printf("2\n");
	else printf("0\n");
	
	return 0;
}

Measured memory_bytes: 5120
#include<bits/stdc++.h>
using namespace std;
int main()
{
  vector<int> antena(5);
  int k;
  int count=0;
  for(int i=0; i<antena.size(); i++){
    cin >> antena.at(i);
  }
  cin >> k;
  for(int i=0; i<antena.size(); i++){
    for(int j=0; j<antena.size(); j++){
      if((antena.at(i)-antena.at(j))>k){
        count++;
      }
    }
  }
  if(count==0)
    cout << "Yay!" << endl;
  else
    cout << ":(" << endl;
}

 
        

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

int main(){
	int i,cnt,flag;
	char str[101];

	cnt = 0;

	while(scanf("%s",str) != EOF){
		flag = 1;
		for(i = 0;i < (strlen(str)/2);i++){
			if(str[i] != str[strlen(str)-i-1]){
				flag = 0;
				break;
			}
		}

		if(flag){
			cnt++;
		}
	}

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

	return 0;
}

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

using namespace std;
using ll =long long;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef pair<int,int> PII;
#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cerr << #x << " = " << (x) << endl;
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; }
using P = pair<int,int>;
//Write From this Line

const int inf = 1e9;
vector<vector<int>> dp(1010, vector<int> (10010,inf));
int main()
{
	int h, n;
	cin >> h >> n;
	vector<int> a(n), b(n);
	rep(i,n) cin >> a[i] >> b[i];


	rep(i,n+1) dp[i][0] = 0;
	For(i,1,n+1){
		int atk = a[i-1], mp = b[i-1];
		rep(j,h+1){
			dp[i][j] = min(dp[i][max(0,j-atk)]+mp, dp[i-1][j]);
		}
	}
	cout << dp[n][h] << endl;
}


Measured memory_bytes: 39936
r,c=map(int,input().split())
d=c
f=0
a=[];
h=0
for i in range(r):
    a.append(list(map(int,input().split())))
for i in range(r):
    for j in range(c):
        f=a[i][j]+f
        print(a[i][j],end=" ")
    print(f)
    f=0
for i in range(c):
    for j in range(r):
        f=a[j][i]+f
    print(f,end=" ")
    h=f+h
    f=0
    if (i==c-1):
        if (j==r-1):
            f=h
            print(f,end="")
print()


Measured memory_bytes: 6216
import math
N = int(input())
XY = [list(map(int, input().split())) for n  in range(N)]

f = math.factorial(N)
a = N * (N - 1) // 2


sumd = 0
for n in range(N - 1):
    for m in range(n, N):
        sumd += ((XY[n][0] - XY[m][0]) ** 2 + (XY[n][1] - XY[m][1]) ** 2) ** 0.5

print (sumd   / N * 2)


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

using namespace std;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
#define watch(a) { cout << #a << " = " << a << endl; }
template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); }
template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); }
template<class T> void operator>> (istream& ist, vector<T>& vs) { for(auto& e: vs) cin >> e; }

typedef long long ll;
int const inf = 1<<29;

int N;
int a[100010];
int b[100010];

int main() {
  cin >> N;
  rep(i, N) cin >> a[i] >> b[i];
  int64_t plus = 0;
  rep(i, N) {
    int k = N - i - 1;
    int poipoipoi_po_poipoipo_pi_ = b[k] - (a[k] + plus) % b[k];
    if (poipoipoi_po_poipoipo_pi_ < b[k]) {
      plus += poipoipoi_po_poipoipo_pi_;
    }
  }
  cout << plus << "\n";
}


Measured memory_bytes: 1024
#include<cstdio>
#include<iostream>
#include<cstring>
#include<bitset>
#define mp(a,b) make_pair(a,b)
using namespace std;
bitset<10010> can[2010];
pair<int,int> vis[2][10010];
char s[2010][20010],ans[1000010];
int len[2010],n,k,cnt,ncnt;
int main()
{
	scanf("%d%d",&n,&k);
	for (int i=1;i<=n;i++) scanf("%s",s[i]),len[i]=strlen(s[i]);
	can[n+1][0]=1;
	for (int i=n;i>=1;i--)
		can[i]=can[i+1]|(can[i+1]<<len[i]);
	for (int i=1;i<=n;i++)
		if (can[i+1][k-len[i]]) vis[0][++cnt]=mp(i,0);
	int ii=0;
	for (int i=0;i<k;i++)
	{
		char minc='z';
		for (int j=1;j<=cnt;j++) minc=min(minc,s[vis[ii][j].first][vis[ii][j].second]);
		ans[i]=minc;
		int minid=n+1;
		ncnt=0;
		for (int j=1;j<=cnt;j++)
		{
			int nid=vis[ii][j].first,nlen=vis[ii][j].second;
			if (s[nid][nlen]!=minc) continue;
			if (nlen+1==len[nid]) minid=min(minid,nid);
			else vis[ii^1][++ncnt]=mp(nid,nlen+1);
		}
		for (int j=minid+1;j<=n;j++)
			if (k-len[j]-i-1>=0&&can[j+1][k-len[j]-i-1]) vis[ii^1][++ncnt]=mp(j,0);
		ii^=1;
		cnt=ncnt;
	}
	printf("%s",ans);
}

Measured memory_bytes: 41344
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <queue>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
constexpr int MOD = 1000000007;
constexpr int INF = 1e18;

using namespace std;


signed main() {
  vector<char> s(3);
  vector<char> t(3);

  REP(i, 3) cin >> s[i];
  REP(i, 3) cin >> t[i];

  int ans = 0;
  REP(i, 3) if(s[i] == t[i]) ans++;

  cout << ans << endl;
  

  return 0;
}

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

const int N = 1010;

int n;
int indegree[N * N];
vector<int> g[N * N];

int toint(int x, int y) {
  if (x > y)
    swap(x, y);
  return n * x + y;
}

pair<int, int> demap(int x) {
  return {x / n, x % n};
}

int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    int last;
    scanf("%d", &last);
    last--;
    for (int j = 0; j < n - 2; j++) {
      int cur;
      scanf("%d", &cur);
      cur--;
      g[toint(i, last)].push_back(toint(i, cur));
      indegree[toint(i, cur)]++;
      last = cur;
    }
  }

  int proc = 0, ans = 0;
  vector<int> cur_set;
  for (int i = 0; i < n * (n - 1); i++)
    if (!indegree[i] && demap(i).first < demap(i).second)
      cur_set.push_back(i);

  while ((int) cur_set.size() > 0) {
    ans++;
    proc += (int) cur_set.size();
    vector<int> nxt;
    for (int u : cur_set)
      for (int v : g[u]) {
        indegree[v]--;
        if (!indegree[v])
          nxt.push_back(v);
      }
    cur_set = nxt;
  }

  printf("%d\n", (proc == n * (n - 1) / 2 ? ans : -1));
  return 0;
}

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

using namespace std;

typedef long long ll;

const int INF = 1000000000;

int main()
{
  int N; scanf("%d", &N);
  int ans = 1;
  for (int i = 2; i <= N; ++i) {
    for (int val = i; val * i <= N; ) {
      val *= i;
      ans = max(ans, val);
    }
  }
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<math.h>
#include<stdlib.h>
#include<string>
#include<iostream>
#include<set>
#include<map>
#include<deque>
using namespace std;
typedef long long ll;
typedef pair<ll, ll>pii;
typedef pair<pii, ll>pi3;
ll mod = 1000000007;
int main()
{
	int a, b, c;
	cin >> a >> b >> c;
	int r;
	if (a == b)r = c;
	else if (b == c)r = a;
	else r = b;
	//printf("%c%c%c\n", a[0]+'A'-'a',b[0]+'A'-'a',c[0]+'A'-'a');
	cout << r << endl;
	//printf((a == 'a' || a == 'i' || a == 'u'||a=='e'||a=='o') ? "vowel\n" : "consonant\n");
}

Measured memory_bytes: 256
import math

def f(d):
  theta = d * math.pi /180
  if a * math.tan(theta) <= b:
    return a*a*b - a*a*a*math.tan(theta)/2
  else:
    return a*b*b/(2*math.tan(theta))

a, b, x = map(int, input().split())
l, r = 0.0, 90.0
for i in range(1000):
  m = (l+r)/2
  if f(m) <= x: r = m
  else: l = m
print('{0:.10f}'.format(l))

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

int main(){
  
  int n,i,j,s;
  
  cin >>n ;
 
  int num[n];
 
  for(s = 0;s < n;s++){
  cin >>num[s] ;
  }

  for( i = n-1; i>0;i--){
    cout <<num[i] <<" " ;
    
  }
  cout <<num[0] <<"\n" ;
  
  return 0;
}

Measured memory_bytes: 1164
#include <bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin >> s;
    if(s[0] == s[1] && s[1] == s[2])
    {
        cout << "Yes";
        return 0;
    }
    if(s[1] == s[2] && s[3] == s[2])
    {
        cout << "Yes";
        return 0;
    }
    cout << "No";
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996) 
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
//const long long MOD = 998244353;

using namespace std;

void solve()
{
    int a,b,c;
    scanf("%d%d%d", &a, &b, &c);
    if((a==b && b!=c)||(b==c && c!=a)||(c==a && c!=b)) {
        printf("Yes\n");
    }
    else {
        printf("No\n");
    }

    
    return;
}

int main(int argc, char* argv[])
{
#if 1
    solve();
#else
    int T; scanf("%d", &T);
    while(T--) {
        solve();
    }
#endif
    return 0;
}


Measured memory_bytes: 128
import java.util.Scanner

object Main {
  def main(args: Array[String]): Unit = {
    val sc = new Scanner(System.in)
    val n, x = sc.nextInt()
    val kids = List.fill(n)(sc.nextLong()).sorted.scan(0L)((a, b) => a + b)
    val sum = kids(n)
    val a = kids.takeWhile(_ <= x).length

    if (sum == x) println(n)
    else
      a match {
        case 1L                     => println(0)
        case m if kids(m - 1) == x => println(m - 1)
        case m if m == kids.length => println(m - 2)
        case m                     => println(m - 1)
      }
  }
}


Measured memory_bytes: 27448
#include<bits/stdc++.h>
using namespace std;
const int lim=1120;
int N,K;

vector<int>prime;

int dp[200][2000][20];

int main(){
    bool f[2000];
    fill_n(f,2000,true);
    f[0]=f[1]=false;

    for(int i=2;i<=lim;i++){
        if(!f[i])continue;
        prime.push_back(i);
        for(int j=i+i;j<=lim;j+=i)f[j]=false;
    }
    fill_n(**dp,200*2000*20,0);
    dp[0][0][0]=1;

    for(int i=0;i<prime.size();i++){
        for(int j=0;j<=lim;j++){
            for(int k=0;k<=14;k++){
                int to=j+prime[i];
                dp[i+1][j][k]+=dp[i][j][k];
                if(to>lim)continue;
                dp[i+1][to][k+1]+=dp[i][j][k];

            }
        }
    }
    while(cin>>N>>K,N||K){
        cout<<dp[(int)prime.size()][N][K]<<endl;
    }
    return 0;
}

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





int main() {
  string a,b;
  cin>>a>>b;
  
  if (a.at(0)==b.at(2) and a.at(1)==b.at(1) and a.at(2)==b.at(0)){
    cout<<"YES"<<endl;
  }
  else {
    cout<<"NO"<<endl;
  }
  
}

  













Measured memory_bytes: 256
from sys import stdin

def main():
    n = int(stdin.readline().strip())
    l = list(map(int,stdin.readline().split()))
    ar = [-1 for _ in range(n)]
    ar[0] = l[0]
    ans = 1
    for i in range(1,n):
        if(l[i] <= ar[i-1]):
            ans+=1
            ar[i] = l[i]
        else:
            ar[i] = ar[i-1]
    print(ans)
        
main()


Measured memory_bytes: 24596
use std::cmp::min;
use std::io::prelude::*;
use std::io::stdin;
use std::str::FromStr;

fn main() {
    let a: i32 = read();
    let b: i32 = read();
    let c: i32 = read();
    println!("{}", min(b / a, c));
}

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|b| b.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}


Measured memory_bytes: 4352
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#include <math.h>
#include<bitset>
#include<stdio.h>
#include<iomanip>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)

bool isOK(int a[],int index,int key){
    if(a[index] >= key){
        return true;
    }else{
        return false;
    }
}

int binary_search(int a[],int n,int key){
    int left = -1;
    int right = n;

    while(right-left>1){
        int mid = left + (right - left)/2;
        if(isOK(a,mid,key)){
            right = mid;
        }else{
            left = mid;
        }
    }
    return right;
}



int main(void){
    long long x;
    cin >> x;
    vector<long long> buf(10000);
    int i =1;

    buf.at(0) = 100;

    while(1){
        buf.at(i) = buf.at(i-1)*0.01 + buf.at(i-1);
        if(buf.at(i)>=x){
            cout << i << endl;
            break;
        }
        i++;
    } 
    return 0;
}

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

using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
#define all(x) x.begin(), x.end()

template <typename T1, typename T2> inline void chkmin(T1 &x, const T2 & y) {if (x > y) x = y;}
template <typename T1, typename T2> inline void chkmax(T1 &x, const T2 & y) {if (x < y) x = y;}

const int MAXN = 1e5 + 10;
int n, m;
vector<int> g[MAXN];

void read() {
	cin >> n >> m;
	for (int i = 0; i < m; i++) {
		int u, v;
		cin >> u >> v;
		u--;
		v--;
		g[u].push_back(v);
		g[v].push_back(u);
	}
}

int dist[MAXN];
int par[MAXN];

void bfs() {
	fill(dist, dist + n, -1);
	dist[0] = 0;
	queue<int> q;
	q.push(0);
	while (!q.empty()) {
		int v = q.front();
		q.pop();
		for (auto i : g[v]) {
			if (dist[i] != -1) continue;
			q.push(i);
			dist[i] = dist[v] + 1;
			par[i] = v;
		}
	}
}

void no() {
	cout << "No\n";
	exit(0);
}


void run() {
	bfs();
	for (int i = 0; i < n; i++) {
		if (dist[i] == -1) {
			no();
		}
	}
}

void write() {
	cout << "Yes\n";
	for (int i = 1; i < n; i++) {
		cout << par[i] + 1 << "\n";
	}
}

signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	read();
	run();
	write();
	return 0;
}

Measured memory_bytes: 10956
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,k,a[100001];
    scanf("%d%d",&n,&k);
    for(int i=1;i<=n;i++) scanf("%d",&a[i]);
    sort(a+1,a+1+n);
    int ans=1e9;
    for(int i=1;i<=n;i++)
        if(i+k-1<=n) ans=min(ans,a[i+k-1]-a[i]);
    else break;
    printf("%d\n",ans);
}


Measured memory_bytes: 640
#include<iostream>
using namespace std;
int main(){
    int tate,yoko,x,y;
    while(1){
        cin >> tate >> yoko;
        if(tate==0 && yoko==0) break;
        for(x=0;x<tate;x+=1){
            for(y=0;y<yoko;y+=1){
                cout << "#";
            }
            y=0;
            cout << endl;
        }
        x=0;
        cout << endl;
    }
    return 0;
}


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

using namespace std;

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

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

ll A[10005];
ll M[105][105];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll H, W, N;
    cin >> H >> W >> N;
    REP(i, N) {
        cin >> A[i];
    }

    ll index = 0;
    pll g(0, 0);
    while (g.first < H) {
        M[g.first][g.second] = index + 1;
        if (--A[index] <= 0)
            index++;

        if (g.first % 2 == 0)
            g.second++;
        else
            g.second--;

        if (g.second < 0) {
            g.first++;
            g.second = 0;
        }
        else if (g.second >= W) {
            g.first++;
            g.second = W - 1;
        }
    }

    REP(i, H) {
        REP(j, W) {
            cout << M[i][j] << " ";
        }
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int main(){
	string s;
	cin>>s;
	int cnt = 0;
	if(s[0]=='R'){
		if(s[1]=='R'){
			if(s[2]=='R'){
				cnt = 3;
			}
			else{
				cnt = 2;
			}
		}else{
			cnt = 1;
		}
	}else if(s[1]=='R'){
		if(s[2]=='R'){
				cnt = 2;
		}
		else{
			cnt = 1;
		}
	}else if(s[2]=='R'){
		cnt = 1;
	}else{
		cnt = 0;
	}
	
	
	cout<<cnt;
	return 0;
}

Measured memory_bytes: 3588
#include <iostream>

using namespace std;

int main() {
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		int x, y, w, h;
		cin >> x >> y >> w >> h;
		int neko;
		cin >> neko;
		int counter = 0;
		for (int j = 0; j < neko; j++) {
			int nx, ny;
			cin >> nx >> ny;
			if (x <= nx && nx <= x+w && y <= ny && ny <= y+h) {
				counter++;
			}
		}
		cout << counter << endl;
	}
	return 0;
}

Measured memory_bytes: 1160