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

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

        int h = sc.nextInt();
        int w = sc.nextInt();
        sc.nextLine();

        char s[][] = new char[h+2][w+2];
        for (int i = 1; i <= h; i++) {
            String line = sc.nextLine();
            for (int j = 1; j <= w; j++) {
                s[i][j] = line.charAt(j-1);
            }
        }

        for (int i = 1; i <= h; i++) {
            for (int j = 1; j <= w; j++) {
                int count = 0;
                if (s[i][j] == '#') {
                    System.out.print('#');
                    continue;
                }

                if (s[i-1][j-1] == '#') count++;
                if (s[i][j-1] == '#') count++;
                if (s[i+1][j-1] == '#') count++;
                if (s[i-1][j] == '#') count++;
                if (s[i+1][j] == '#') count++;
                if (s[i-1][j+1] == '#') count++;
                if (s[i][j+1] == '#') count++;
                if (s[i+1][j+1] == '#') count++;
                System.out.print(count);
            }
            System.out.println();
        }
    }
}


Measured memory_bytes: 23252
#include <algorithm>
#include <cmath>
#include <vector>
#include <functional>
#include <cstdlib>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <ctype.h>
#include <climits>
#include <queue>
using namespace std;
typedef long long ll;
#define REP(i, n) for(ll i = 0; i < (ll)(n); ++i)
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 k,s;
	cin >> k >> s;
	
	ll ans=0;
	for(int x=0; x<=k; ++x){
		for(int y=0; y<=k; ++y){
			if(s-(x+y)>=0 && s-(x+y)<=k) ans++; 
		}
	}
	
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 3636
# coding: utf-8

class Mission:
  def __init__(self):
    self.field = [[0]*21 for i in range(21)]
    self.x = 10
    self.y = 10

  def get_gem(self, x, y):
    self.field[x][y] = 0

  def put_gem(self, x, y):
    self.field[x][y] = 1

  def move_x(self, step, sign=1):
    for i in range(1,step+1): self.get_gem(self.x+(i*sign), self.y)
    self.x += step * sign

  def move_y(self, step, sign=1):
    for j in range(1,step+1): self.get_gem(self.x, self.y+(j*sign))
    self.y += step * sign

  def command(self, direction, step):
    if direction == 'N': self.move_y(step)
    elif direction == 'E': self.move_x(step)
    elif direction == 'S': self.move_y(step, -1)
    elif direction == 'W': self.move_x(step, -1)

def main():
  while True:
    n_gems = input()
    if n_gems == 0: break

    m = Mission()
    for i in range(n_gems):
      x, y = map(int, raw_input().split(' '))
      m.put_gem(x, y)

    n_commands = input()
    for i in range(n_commands):
      direction, step = raw_input().split(' ')
      m.command(direction, int(step))

    if m.field == [[0]*21 for i in range(21)]: print 'Yes'
    else: print 'No'

if __name__ == '__main__':
  main()

Measured memory_bytes: 4308
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int main()
{
  int N; cin >> N;
  vector<int> a(N);
  for(int i = 0;i < N;++i) {
    cin >> a[i];
  }
  int mn = a[0]; 
  int mx = a[0];
  for(int i = 0; i < N; ++i){
    if(mn > a[i]) mn = a[i];
    if(mx < a[i]) mx = a[i];
  }
  cout << mx - mn << endl;
}

Measured memory_bytes: 256
import numpy as np

N, K = map(int, input().split())
h = np.array(list(map(int, input().split())))

# dp = np.array([-1 for _ in range(N)])
dp = np.zeros(N, dtype=int)

dp[0] = 0

for i in range(1, N):
    start = max(0, i-K)
    dp[i] = min(dp[start: i] + np.abs(h[i] - h[start: i]))

print(dp[-1])


Measured memory_bytes: 22892
n = gets.chomp.to_i
kazu = n ** 0.5
meyasu = kazu.ceil
ans = Float::INFINITY
meyasu.downto(1) do |i|
    amari = n % i
    j = n / i
    if amari == 0 
        goukei = i + j
        ans = [ans,goukei].min
    end 

end
puts ans - 2

Measured memory_bytes: 14768
-- Try AtCoder
-- author: Leonardone @ NEETSDKASU

main = print . solve . map read . words =<< getLine

solve [a, b, c] = ans where
    f x y z = x * y * (z - div z 2) - x * y * (div z 2)
    ans = minimum [f a b c, f b c a, f c a b]

Measured memory_bytes: 508
use std::io::Read;

fn read<T: std::str::FromStr>() -> T {
    let stdin = std::io::stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n: usize = read();
    let s: Vec<char> = read::<String>().chars().collect();

    let mut pre_c = ' ';

    let mut res = 0;
    for i in 0..n {
        if i == 0 {
            res += 1;
            pre_c = s[i];
            continue;
        }

        if s[i] == pre_c {
            continue;
        } else {
            res += 1;
            pre_c = s[i];
        }
    }

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


Measured memory_bytes: 4352
n,m = gets.split(" ").map(&:to_i)

conditions = m.times.map { gets.split(" ").map(&:to_i) }

#p conditions
# ary[n]はn桁目の数字、ary[0]は存在可能性
ary = (n+1).times.map { nil }
ary[0] = true

conditions.each do |s,c|
    if ary[s] && ary[s]!=c
        ary[0] = false
        break
    else
        ary[s] = c
    end
end

#p ary
# num builder
num_s = ""

if n==1
    # 1桁の場合
    if ary[0]
        if ary[1]
            num_s = ary[1].to_s
        else
            num_s = "0"
        end
    end
else
    # 2桁以上の場合
    if ary[0]
        if ary[1] == 0
            # 先頭が0にはなりえない
            ary[0] = false
        else 
            1.upto(n) do |i|
                if ary[i]
                    num_s << ary[i].to_s 
                else
                    if i==1
                        num_s << "1"
                    else
                        num_s << "0"
                    end
                end
            end
        end
    end
end

if ary[0]
    puts num_s
else
    puts -1
end


Measured memory_bytes: 1788
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.StreamTokenizer;
import java.util.Arrays;

public class Main {
    public static StreamTokenizer in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));

    public static int nextInt() {
        try {
            in.nextToken();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return (int) in.nval;
    }

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        int x = nextInt(), y = nextInt(), a = nextInt(), b = nextInt(), c = nextInt(), cnt1 = 0, cnt2 = 0, cnt3 = 0;
        int n = a + b + c;
        long ans = 0;
        M6 m[] = new M6[n];
        for (int i = 0; i < a; i++) {
            m[i] = new M6(nextInt(), 1);
        }
        for (int i = a; i < a + b; i++) {
            m[i] = new M6(nextInt(), 2);
        }
        for (int i = a + b; i < n; i++) {
            m[i] = new M6(nextInt(), 3);
        }
        Arrays.sort(m);
        for (int i = n - 1; i >= 0; i--) {
            int k = m[i].i;
            if (k == 3) {
                cnt3++;
                ans += m[i].v;
            } else if (k == 1 && cnt1 < x) {
                cnt1++;
                ans += m[i].v;
            } else if (k == 2 && cnt2 < y) {
                cnt2++;
                ans += m[i].v;
            }
            if (cnt3 + cnt2 + cnt1 == x + y)
                break;
        }
        System.out.println(ans);
    }

}

class M6 implements Comparable<M6> {
    int v;

    int i;

    public M6(int v, int i) {
        super();
        this.v = v;
        this.i = i;
    }

    @Override
    public int compareTo(M6 o) {
        // TODO Auto-generated method stub
        return this.v - o.v;
    }

}


Measured memory_bytes: 35644
from collections import deque

N, M = map(int, input().split())

a = deque()
b = deque()
for i in range(1, int(M ** (1 / 2)) + 1):
    if M % i == 0:
        a.appendleft(i)
        b.append(M // i)

b.extend(a)

for i in b:
    m = M // i
    if m >= N:
        print(i)
        break


Measured memory_bytes: 9576
#include <bits/stdc++.h>
#define REP(i, a, b) for (long long i = a; i <= b; ++i)
#define ll long long
#define N 100010
using namespace std;

ll n, k, q, a[N];

inline ll read(){
	ll s = 0, w = 1;
	char ch = getchar();
	while (ch < '0' || ch > '9'){
		if (ch == '-') w *= -1;
		ch = getchar();
	}
	while (ch >= '0' && ch <= '9'){
		s = s * 10 + ch - '0';
		ch = getchar();
	}
	return s * w;
}

inline void work(){
	n = read(), k = read(), q = read();
	REP(i, 1, n) a[i] = k;
	REP(i, 1, q){
		ll x = read();
		a[x]++;
	}
	REP(i, 1, n){
		if (a[i] - q > 0) puts("Yes");
		else puts("No");
	}
}

int main(){
	work();
	return 0;
}

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

int main()
{
 	long long n;
  	cin >> n;
  	
  	pair<long long, long long> mxplus, mnplus, mxsub, mnsub;
  	long long mx1 = -1e18 - 1;
  	long long mn1 = 1e18 + 1;
  	long long mx2 = -1e18 - 1;
  	long long mn2 = 1e18 + 1;
  	
  	for(long long i = 0; i < n; i++)
    {
      	long long x, y;
      	cin >> x >> y;
      
      	if(x + y > mx1)
        {
         	mx1 = x + y;
          	mxplus.first = x;
          	mxplus.second = y;
        }
      	
      	if(x + y < mn1)
        {
         	mn1 = x + y;
          	mnplus.first = x;
          	mnplus.second = y;
        }
      
      	if(x - y > mx2)
        {
         	mx2 = x - y;
          	mxsub.first = x;
          	mxsub.second = y;
        }
      
      	if(x - y < mn2)
        {
         	mn2 = x - y;
          	mnsub.first = x;
          	mnsub.second = y;
        }
    }
  	
  	long long dis1 = abs(mxplus.first - mnplus.first) + abs(mxplus.second - mnplus.second);
  	long long dis2 = abs(mxsub.first - mnsub.first) + abs(mxsub.second - mnsub.second);
  	
  	cout << max(dis1, dis2);
}

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

using namespace std;

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

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

    int max = 0;
    for(int i = 0; i < N; i++) {
        for(int j = 0; j < N; j++) {
            if(i == j) continue;

            if(abs(A[i] - A[j]) > max) {
                max = abs(A[i] - A[j]);
            }
        }
    }

    cout << max << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
 #define int long long

#define all(X) (X).begin(), (X).end()
#define reset(X) memset(X, 0, sizeof(X))
#define mp(a, b) make_pair(a, b)
#define pb push_back
#define endl '\n'
#define fi first
#define se second


using namespace __gnu_pbds;
using namespace std;
const int mod=1e9+7;
 // const int mod=998244353;
 // const int mod=1e9+9;
const int INF=4e18+10;
// const int INF=4e18+10;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T>
using ordered_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define read(n) int n; cin>>n;
#define readv(x, n) vector<int> x(n); for(auto &i:x) cin>>i;


typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int, int> pii;

template<typename T1,typename T2>
void set_min(T1& a, T2 b)
{
    a=min(a, (T1)b);
}


int multiply(int a, int b, int in_mod){return (a*b)%in_mod;}
int mult_identity(int a){return 1;}


auto power(auto a, int b, int in_mod)
{
    auto prod=mult_identity(a);
    auto mult=a%in_mod;
    while(b!=0)
    {
        if(b%2)
        {
            prod=multiply(prod,mult, in_mod);

        }
        mult=multiply(mult, mult,in_mod);
        b/=2;
    }
    return prod;
}
int mod_inv(int q, int in_mod)
{

    return power(q, in_mod-2,in_mod);
}


void solve()
{
    vector<bool> usable(500, true);
    int x;
    cin>>x;
    int n;
    cin>>n;
    readv(p,n);
    int offset=+250;
    for(auto i:p)
        usable[i+offset]=false;

    pair<int,int> mn={INF, INF};
    for(int i=0;i<=500;i++)
    {
        int real = (i-offset);
        if(usable[i] == true)
        {
            mn= min(mn, {abs(x-real), real});
        }
    }
    cout<<mn.second<<endl;


}

signed main()

{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
#ifndef ONLINE_JUDGE
    if (fopen("INPUT.txt", "r"))
    {
        freopen("INPUT.txt", "r", stdin);
        freopen("OUTPUT.txt", "w", stdout);
    }
#endif
    auto clk = clock();
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    // -------------------------------------Code starts here---------------------------------------------------------------------

    int t = 1;
    // cin>>t;

    for (int test = 1; test <= t; test++)
    {
        // cout<<"Case #"<<test<<": ";
        // cout<<endl;
        solve();
        // cout<<endl;
    }

    // -------------------------------------Code ends here------------------------------------------------------------------

    clk = clock() - clk;
    // cerr << fixed << setprecision(6) << "Time: " << ((long double)clk) / CLOCKS_PER_SEC << "\n";
    return 0;
}


Measured memory_bytes: 3676
#include <cstdio>
#include <string>
#include <iostream>
#include <cmath>
#include <vector>
#include <stack>
#include <algorithm>


using namespace std;
typedef long long LL;

int main(void) {

	int D = 0, N = 0, cnt = 0, result = 0;
	cin >> D >> N;

	if (N == 100)
		N = 101;

	for (int i = 1; cnt != N; i++) {
		if (D == 0) {
			cnt++;
			result = i;
		}
		else if (D == 1) {
			cnt++;
			result = i * 100;
		}
		else if (D == 2) {
			cnt++;
			result = i * 10000;
		}
	}

	cout << result << endl;

	return 0;
}


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

#define REP(i, m, n) for (int i = (m); i < (int)(n); i++)
#define REPS(i, m, n) for (int i = (m); i <= (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define reps(i, n) for (int i = 0; i <= (int)(n); i++)
#define rrep(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define rreps(i, x) for (int i = (int)(x); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
#define fi first
#define se second
typedef long long ll;
typedef pair<int, int> P;
const int inf = INT_MAX;
const ll INF = 1LL << 60;
const ll mod = 1e9 + 7;
const double EPS = 1e-10;
const double PI = acos(-1.0);
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; }
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val) { fill( (T*)array, (T*)(array+N), val ); }
template <class T1, class T2, class Pred = std::less<T2> >
struct sort_pair_second {
    bool operator()(const std::pair<T1,T2>&left, const std::pair<T1,T2>&right) {
        Pred p;
        return p(left.second, right.second);
    }
};

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

    int N; cin >> N;
    vector<ll> A(N), B(N);
    rep(i, N) cin >> A[i] >> B[i];
    sort(all(A));
    sort(all(B));
    ll mi, ma;
    if (N % 2) {
      mi = A[N/2];
      ma = B[N/2];
    } else {
      mi = A[N/2-1] + A[N/2];
      ma = B[N/2-1] + B[N/2];
    }
    cout << ma - mi + 1 << endl;
    return 0;
}

Measured memory_bytes: 6360
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define reps(i,o,n) for(int i=o;i<n;++i)
#define eb emplace_back
#define pb push_back
#define X first
#define Y second
#define all(X) X.begin(), X.end()

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef tuple<int,int,int,int> T;


struct UF{
  vector<int> data;
  UF(int size):data(size,-1){}
  bool unite(int x,int y){
    x=root(x); y=root(y);
    if(x!=y){
      if(data[y]<data[x]) swap(x,y);
      data[x]+=data[y]; data[y]=x;
    }
    return x!=y;
  }
  bool findSet(int x,int y){return root(x)==root(y);}
  int root(int x){return data[x]<0?x:data[x]=root(data[x]);}
  int size(int x){return -data[root(x)];}
};

int main(){
  ios_base::sync_with_stdio(0);
  cout<<fixed<<setprecision(10);
  int n,m;
  cin>>n>>m;
  vector<T> es;
  rep(i,m){
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    es.eb(a,b,c,d);
  }
  if(n-1==m){
    cout<<0<<endl;
    return 0;
  }
  double l=0,r=1e11;
  rep(_,90){
    double m=(l+r)/2;
    sort(all(es),[&](const T &a,const T &b){return m*get<2>(a)-get<3>(a)<m*get<2>(b)-get<3>(b);});
    UF uf(n);
    int a,b,c,d;
    double sum=0;
    for(auto t:es){
      tie(a,b,c,d)=t;
      if(!uf.unite(a,b)) sum+=c*m-d;
    }
    ///cout<<m<<","<<sum<<endl;
    if(sum>0) r=m;
    else l=m;
  }
  cout<<l<<endl;
  return 0;
}

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

using namespace std;

int main()
{
    int n;
    cin>>n;
    int niza[n];
    int dp[n];

    for(int i=0; i<n; i++)
    {
        cin>>niza[i];
    }
    dp[0]=0;
    dp[1]=abs(niza[1]-niza[0]);
    for(int i=2; i<n; i++)
    {
        dp[i]=min(dp[i-1]+abs(niza[i]-niza[i-1]),dp[i-2]+abs(niza[i]-niza[i-2]));
    }
    cout<<dp[n-1]<<endl;
    return 0;
}


Measured memory_bytes: 1024
import sys
import re
import math
import collections
import decimal
import bisect
import itertools
import fractions
import functools
import copy
import heapq
import decimal
import statistics
import queue

# import numpy as np

sys.setrecursionlimit(10 ** 9)
INF = 10 ** 16
MOD = 10 ** 9 + 7
# MOD = 998244353

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===

def main():
    n, t = ns()
    d = [na() for _ in range(n)]
    d.sort()

    dp = [-1 for _ in range(t + 3000 + 1)]
    dp[0] = 0

    for a, b in d:
        for i in range(t - 1, -1, -1):
            if dp[i] >= 0:
                dp[i + a] = max(dp[i + a], dp[i] + b)

    print(max(dp))


if __name__ == '__main__':
    main()


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

int main() {
  int a, b, c; cin >> a >> b >> c;
  string out = "No";
  if(a == b){
    if(a == c){
      out = "No";
    }else{
      out = "Yes";
    }
  }else if(b == c){
    out = "Yes";
  }else if(a == c){
    out = "Yes";
  }
  cout << out;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
struct ios_accelerate { ios_accelerate() { ios::sync_with_stdio(false); cin.tie(nullptr); } } CALL;

#define REP(i, n) for(auto (i) = (n)*0; (i) < (n); (i)++)
#define RNG(i, a, b) for(auto (i) = (a); (i) < (b); (i)++)
#define RBF(i, v) for(auto& (i) : (v))
#define ALL(x) (x).begin(), (x).end()

using LL = long long;
using UL = unsigned long;
using ULL = unsigned long long;
template<typename T> using V = vector<T>;
template<typename T> using VV = vector<vector<T>>;
template<typename T> using P = pair<T, T>;

const double PI = 3.141592653589793;
const int MOD = 1000000007;
const LL INF64 = static_cast<LL>(1e18) + 2;
const int INF = static_cast<int>(1e9) + 2;

template<typename T> inline void upsort(vector<T>& x) { sort(x.begin(), x.end()); }
template<typename T> inline void downsort(vector<T>& x) { sort(x.begin(), x.end(), greater<T>()); }
template<typename T> inline void col(T x) { cout << x << '\n'; }
template<> inline void col(double x) { cout << fixed << setprecision(12) << x << '\n'; }

signed main() {
	int a, b;
	cin >> a >> b;

	string sa(""), sb("");
	REP(i, a) {
		sa += '0' + b;
	}
	REP(i, b) {
		sb += '0' + a;
	}

	col(min(sa, sb));

	return 0;
}


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

int main(void){
  int A,B,C,D,E,F;
  cin>>A>>B>>C>>D>>E>>F;
  int score=A+B+C+D;
  score-=min(min(A,B),min(C,D));
  score+=max(E,F);
  cout<<score<<endl;
  return 0;
}



Measured memory_bytes: 3120
#include<bits/stdc++.h>
#define MAXN 3010010
#define Max 25
using namespace std;
 
int arr[MAXN];
int BitCount[Max];

int main()
{	
		   // freopen("in.txt" , "r" , stdin);
	       int N;
	       cin >> N;
	       for(int i = 1 ; i <= N ; i++) cin >> arr[i];
	       long long Ans = 0;
	   	   int l = 1;
	   	   for(int r = 1 ; r <= N ; r++) {
	   	   	
	   	   		for(int i = 0 ; i < 22 ; i++) {
	   	   			if(arr[r] & (1 << i)) {
	   	   				BitCount[i]++;
	   	   			}
	   	   		}

	   	   		while(true) {
	   	   			bool flag = 0;
	   	   			for(int i = 0 ; i < 22 ; i++) {
	   	   				if(BitCount[i] > 1) {
	   	   					flag = 1;
	   	   					for(int i = 0 ; i < 22 ; i++) {
	   	   						if(arr[l] & (1 << i)) BitCount[i]--;
	   	   					}
	   	   					l++;
	   	   				}
					}
					if(!flag) break;
				}
				Ans += r - l + 1;
	   	   }
	   	   cout << Ans << endl;
}

Measured memory_bytes: 1024
#include <vector>
#include <bitset>
#include <map>
#include <queue>
#include <climits>
#include <algorithm>
#include <iostream>
#include <cmath>
#include <cfloat>
using namespace std;

const double INF = DBL_MAX / 2;
const double EPS = 1.0e-10;

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

	vector<int> p(n), t(n), v(n);
	for(int i=0; i<n; ++i)
		cin >> p[i] >> t[i] >> v[i];

	vector<vector<double> > time(n, vector<double>(m+2, INF));
	vector<vector<double> > prob(n, vector<double>(m+1, 0.0)), sumProb(n, vector<double>(m+2, 0.0));
	for(int i=0; i<n; ++i){
		double comb = 1.0;
		for(int j=m; j>=0; --j){
			time[i][j] = l / (double) v[i] + j * t[i];
			prob[i][j] = comb * pow(p[i]/100.0, j) * pow(1.0-p[i]/100.0, m-j);
			sumProb[i][j] = sumProb[i][j+1] + prob[i][j];
			comb *= j;
			comb /= m-j+1;
		}
	}

	for(int i=0; i<n; ++i){
		double ret = 0.0;
		for(int j=0; j<=m; ++j){
			double tmp = prob[i][j];
			for(int k=0; k<n; ++k){
				if(i == k)
					continue;
				int left = 0;
				int right = m+1;
				while(left < right){
					int middle = (left + right) / 2;
					if(time[i][j] < time[k][middle] - EPS){
						right = middle;
					}else{
						left = middle + 1;
					}
				}
				if(time[i][j] < time[k][left] - EPS)
					tmp *= sumProb[k][left];
				else
					tmp *= 0.0;
			}
			ret += tmp;
		}
		printf("%.10f\n", ret);
	}

	return 0;
}

Measured memory_bytes: 0
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<cmath>
#include<queue>
#include<stack>
#include<list>

#define endl "\n"
using namespace std;
using ll = long long;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define REP(i, n) for(int i = 0; i < n; i++)

int main(){
    ll n;
    cin>>n;
    string s;
    ll ex[26] = {};
    map<string,ll> memo;
    ll var = 0;
    for(int i=0;i<n;i++){
        cin>>s;
        if(s[0]=='M'||s[0]=='A'||s[0]=='R'||s[0]=='C'||s[0]=='H'){
            if(memo[s]!=0) continue;
            memo[s]++;
            ex[s[0]-'A']++;
            if(ex[s[0] - 'A'] == 0) var++;
        }
    }
    ll ans = 0;
    for(int i=0;i<24;i++){
        for(int j=i+1;j<25;j++){
            for(int k=j+1;k<26;k++){
                ans += ex[i]*ex[j]*ex[k];
            }
        }
    }
    // for(int i=0;i<26;i++) cout<<ex[i]<<endl;
    cout<<ans<<endl;
}

Measured memory_bytes: 11136
#include<iostream>
#include<vector>
using namespace std;
int N;
int c[2<<17];
vector<int>G[2<<17];
int cnt[2<<17];
long ans[2<<17];
int dfs(int u,int p)
{
	int ret=1;
	int sto=cnt[c[u]];
	int pre=sto;
	for(int v:G[u])if(v!=p)
	{
		int t=dfs(v,u);
		ret+=t;
		long k=t-(cnt[c[u]]-sto);
		ans[c[u]]-=k*(k+1)/2;
		sto=cnt[c[u]];
	}
	cnt[c[u]]=pre+ret;
	return ret;
}
main()
{
	cin>>N;
	for(int i=0;i<N;i++)
	{
		cin>>c[i];
		c[i]--;
	}
	for(int i=1;i<N;i++)
	{
		int u,v;cin>>u>>v;u--,v--;
		G[u].push_back(v);
		G[v].push_back(u);
	}
	dfs(0,-1);
	for(int i=0;i<N;i++)
	{
		ans[i]+=(long)N*(N+1)/2;
		long k=N-cnt[i];
		ans[i]-=k*(k+1)/2;
		cout<<ans[i]<<endl;
	}
}

Measured memory_bytes: 34592
#include <stdio.h>
int main(void)
{
    int a, b, c;
    scanf("%d", &a);
    scanf("%d", &b);
    scanf("%d", &c);
    if (a >= b && b >= c ) printf("%d %d %d\n", c, b, a);
    else if ( a >= c && c >= b ) printf("%d %d %d\n", b, c, a);
    else if ( b >= a && a >= c ) printf("%d %d %d\n", c, a, b);
    else if ( b >= c && c >= a ) printf("%d %d %d\n", a, c, b);
    else if ( c >= a && a >= b ) printf("%d %d %d\n", b, a, c);
    else printf("%d %d %d\n", a, b, c);
    return 0;
}


Measured memory_bytes: 2084
import sys
sys.setrecursionlimit(10**7) #再帰関数の上限,10**5以上の場合python
import math
from copy import copy, deepcopy
from copy import deepcopy as dcp
from operator import itemgetter
from bisect import bisect_left, bisect, bisect_right#2分探索
#bisect_left(l,x), bisect(l,x)#aはソート済みである必要あり。aの中からx未満の要素数を返す。rightだと以下
from collections import deque
#deque(l), pop(), append(x), popleft(), appendleft(x)
##listでqueの代用をするとO(N)の計算量がかかってしまうので注意
from collections import Counter#文字列を個数カウント辞書に、
#S=Counter(l),S.most_common(x),S.keys(),S.values(),S.items()
from itertools import accumulate,combinations,permutations#累積和
#list(accumulate(l))
from heapq import heapify,heappop,heappush
#heapify(q),heappush(q,a),heappop(q) #q=heapify(q)としないこと、返り値はNone
#import fractions#古いatcoderコンテストの場合GCDなどはここからimportする
from functools import lru_cache#pypyでもうごく
#@lru_cache(maxsize = None)#maxsizeは保存するデータ数の最大値、2**nが最も高効率
from decimal import Decimal

def input(): 
    x=sys.stdin.readline()
    return x[:-1] if x[-1]=="\n" else x
def printl(li): _=print(*li, sep="\n") if li else None
def argsort(s, return_sorted=False): 
    inds=sorted(range(len(s)), key=lambda k: s[k])
    if return_sorted: return inds, [s[i] for i in inds]
    return inds
def alp2num(c,cap=False): return ord(c)-97 if not cap else ord(c)-65
def num2alp(i,cap=False): return chr(i+97) if not cap else chr(i+65)
def matmat(A,B):
    K,N,M=len(B),len(A),len(B[0])
    return [[sum([(A[i][k]*B[k][j]) for k in range(K)]) for j in range(M)] for i in range(N)]
def matvec(M,v):
    N,size=len(v),len(M)
    return [sum([M[i][j]*v[j] for j in range(N)]) for i in range(size)]
def T(M):
    n,m=len(M),len(M[0])
    return [[M[j][i] for j in range(n)] for i in range(m)]
def main():
    mod = 1000000007
    #w.sort(key=itemgetter(1),reversed=True)  #二個目の要素で降順並び替え

    #N = int(input())
    H,N = map(int, input().split())
    A = tuple(map(int, input().split())) #1行ベクトル
    #L = tuple(int(input()) for i in range(N)) #改行ベクトル
    #S = tuple(tuple(map(int, input().split())) for i in range(N)) #改行行列

    if sum(A)>=H:
        print('Yes')
    else:
        print('No')




if __name__ == "__main__":
    main()

Measured memory_bytes: 21652
n ,y = map(int,input().split())
list = [-1,-1,-1]
for i in range(n+1):
    for j in range(n+1 - i):
        if (j *10000 + i * 5000 + (n-i-j)* 1000) == y:
                list = [i,j,(n-i-j)]
                break
      
        
    if (j *10000 + i * 5000 + (n-i-j)* 1000) == y:
        break

print(list[1],list[0],list[2])    

Measured memory_bytes: 9152
// フェルマーの小定理
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

const (
	m = 1000000007
)

func mpow(x, y int) int {
	result := 1
	for y != 0 {
		if y&1 == 1 {
			result *= x
			result %= m
		}
		x *= x
		x %= m
		y >>= 1
	}
	return result
}

var (
	fac []int
)

func mcomb(n, k int) int {
	if n == 0 && k == 0 {
		return 1
	}
	if n < k || k < 0 {
		return 0
	}
	return (fac[n] * mpow(fac[n-k], m-2) % m) * mpow(fac[k], m-2) % m
}

func main() {
	N := readInt()
	K := readInt()
	A := make([]int, N)
	for i := 0; i < N; i++ {
		A[i] = readInt()
	}

	fac = make([]int, N+1)
	fac[0] = 1
	for i := 0; i < N; i++ {
		fac[i+1] = fac[i] * (i + 1) % m
	}

	sort.Sort(sort.Reverse(sort.IntSlice(A)))
	maxX := 0
	for i := 0; i < N-K+1; i++ {
		maxX += A[i] * mcomb(N-(i+1), K-1)
		maxX %= m
	}

	sort.Ints(A)
	minX := 0
	for i := 0; i < N-K+1; i++ {
		minX += A[i] * mcomb(N-(i+1), K-1)
		minX %= m
	}

	maxX += m
	maxX %= m

	minX += m
	minX %= m

	fmt.Println((maxX - minX + m) % m)
}

const (
	ioBufferSize = 1 * 1024 * 1024 // 1 MB
)

var stdinScanner = func() *bufio.Scanner {
	result := bufio.NewScanner(os.Stdin)
	result.Buffer(make([]byte, ioBufferSize), ioBufferSize)
	result.Split(bufio.ScanWords)
	return result
}()

func readString() string {
	stdinScanner.Scan()
	return stdinScanner.Text()
}

func readInt() int {
	result, err := strconv.Atoi(readString())
	if err != nil {
		panic(err)
	}
	return result
}


Measured memory_bytes: 6216
#include<iostream>
using namespace std;
int main() {
	int n, p;
	while (cin >> n >> p, n, p) {
		int k[60] = {};
		int w = p, now = 0;
		while (true) {
			if (w) {
				k[now]++; w--;
				if ((!w)&&k[now] == p) {
					cout << now << endl;
					goto end;
				}
			}
			else if (!w) {
				w = k[now];
				k[now] = 0;
			}
			now++;
			if (now == n)now = 0;
		}
	end:;
	}
}

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

using namespace std;

long long int acum = 0;
int n;

int main()
{

    cin >> n;

    for (int i = 1; i <= n; i++)
    {
        if ((i % 3 != 0) && (i % 5 != 0))
        {
            
            acum += i;
        }
            
    }

    cout << acum << endl;



    return 0;
}

Measured memory_bytes: 3612
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main(){
	bool flag = true;
	int n,i,win,draw,lose,point[10];
	string str[10];
	while(cin >> n && n){
		for(i=0;i<n;i++){
			cin >> str[i] >> win >> lose >> draw;
			point[i] = (win*3)+(draw*1);
		}
		if(flag == false) cout << "\n";
		for(i=0;i<n-1;i++){
			for(int j=n-1;i<j;j--){
				if(point[j-1] < point[j]){
					swap(str[j-1],str[j]);
					swap(point[j-1],point[j]);
				}
			}
		}
		for(i=0;i<n;i++){
			cout << str[i] << "," << point[i] << endl;
		}
		flag = false;
	}
	return 0;
}

Measured memory_bytes: 0
package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	sc.Split(bufio.ScanWords)
	a := nextInt()
	b := nextInt()

	num := 0
	port := 1

	for i := 0; i < 100; i++ {
		if port < b {
			port += (a - 1)
			num++
		}
	}
	fmt.Println(num)
}


Measured memory_bytes: 640
n, m = map(int, input().split())

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

A = [0] * n
for i in range(m):
    a, b = map(int, input().split())
    if L[a - 1] == L[b - 1]:
        A[b - 1] = 1
        A[a - 1] = 1
    elif L[a-1] > L[b-1]:
        A[b - 1] = 1
    else:
        A[a - 1] = 1
print(A.count(0))

Measured memory_bytes: 84964
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        try (Scanner in = new Scanner(System.in)) {
            String a = in.next();
            String b = in.next();
            String c = in.next();

            String[] Sabc = new String[] { a, b, c, };
            int[] index = new int[3];
            int current = 0;
            for (;;) {
                if (index[current] >= Sabc[current].length()) {
                    System.out.println((char) ('A' + current));
                    return;
                }
                current = Sabc[current].charAt(index[current]++) - 'a';
            }
        }
    }
}


Measured memory_bytes: 26752
import java.util.Arrays;
import java.util.Scanner;

public class Main {

    void run() {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int w = sc.nextInt();
        int[] wArr = new int[n];
        int[] vArr = new int[n];

        for (int i = 0 ; i < n; i ++) {
            wArr[i] = sc.nextInt();
            vArr[i] = sc.nextInt();
        }

        long[][] dp = new long[n + 1][w + 1];
        // dp[i][j] ... i番目までの荷物をつかって、重さがjを超えないような最大の価値

        for (int i = 0; i < n; i ++) {
            for (int j = 0; j <= w; j++) {
                if (wArr[i] <= j) {
                    dp[i + 1][j] = Math.max(dp[i][j], dp[i][j - wArr[i]] + vArr[i]);
                } else {
                    dp[i + 1][j] = dp[i][j];
                }
            }
        }
//        debug(dp);
        System.out.println(dp[n][w]);
    }


    void debug(Object... os) {
        System.err.println(Arrays.deepToString(os));
    }

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


Measured memory_bytes: 126288
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;
using ll = long long int;
using int64 = long long int;
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const int INF = 1LL << 29;
const ll LONGINF = 1LL << 60;
const ll MOD = 1000000007LL;
 
int main() {
    int N; cin >> N;
    ll ans = 0;
    for(int i=1; i<=N; i++) {
        if(i % 3 == 0) continue;
        if(i % 5 == 0) continue;
        ans += i;
    }
    cout << ans << endl;
    return 0;
}


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

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define lcm( a, b ) (a)/__gcd((a),(b))*(b)
#define endl '\n'

using namespace std;

typedef long long LL;
typedef pair< int, int > P;
typedef pair< LL, LL > LP;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1000000007;
static const int SIZE = 200005;

const int dx[] = {0, -1, 1, 0};
const int dy[] = {-1, 0, 0, 1};

LL fac[SIZE], finv[SIZE], inv[SIZE];
void combInit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for( int i = 2; i < SIZE; ++i ) {
        fac[i] = (fac[i - 1] * i) % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = (finv[i - 1] * inv[i]) % MOD;

    }
}

LL comb(int n, int k) {
    if( n < k ) return 0;
    if( n < 0 || k < 0 ) return 0;
    return (fac[n] * (finv[k] * finv[n - k] % MOD)) % MOD;

}

vector< int > Div( int n ) {
    vector< int > ret;
    for( int i = 1; i * i <= n; ++i ) {
        if( n % i == 0 ) {
            ret.pb( i );

            if( i * i != n ) ret.pb( n / i );
        }
    }
    sort( all( ret ) );
    return ret;
}

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

    int n, l;
    cin >> n >> l;
    vector< string > v;
    for( int i = 0; i < n; ++i ) {
        string s;
        cin >> s;
        v.pb(s);

    }
    sort(all(v));
    for( int i = 0; i < n; ++i ) cout << v[i];
    cout << endl;

    return 0;
}



Measured memory_bytes: 256
from math import gcd
N, M = map(int, input().split())
A = list(map(int, input().split()))
lcm = 1
for a in A:
    lcm = lcm * a // gcd(lcm, a)
    if lcm > M*2:
        print(0)
        exit()
for a in A:
    if lcm // a % 2 == 0:
        print(0)
        exit()
ans = M // (lcm//2) - M // lcm
print(ans)


Measured memory_bytes: 20244
#include <cstddef>
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <vector>
#include <array>
#include <list>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <bitset>
#include <valarray>
#include <utility>
#include <tuple>
#include <cmath>
#include <memory>
#include <random>
#include <fstream>
#include <locale>
#include <regex>
#include <complex>

using ll = long long;
using ull = unsigned long long;
using ld = long double;

//vector
template <class T>
using vec = std::vector<T>;

template <class T>
using vvec = vec<vec<T>>;

constexpr std::size_t operator""_sz(ull n) { return std::size_t(n); }

template <class T>
constexpr bool in(T min, T max, T t)
{
    return t >= min && t <= max;
}

template <class T>
constexpr bool nin(T min, T max, T t)
{
    return !in(min, max, t);
}

template <class T>
void ninDebug(T min, T max, T t)
{
    using namespace std;
    if (nin(min, max, t))
    {
        cout << "ERROR" << endl;
    }
}

int main()
{
    using namespace std;
    // cerr.rdbuf(nullptr);

    string s, p;
    cin >> s >> p;

    s += s;

    bool ans = false;

    for (int i = 0; i <= s.size(); ++i)
    {
        if (s.substr(i, p.size()) == p)
            ans = true;
    }
    
    if (ans)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;


    return 0;
}


Measured memory_bytes: 3224
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.PriorityQueue;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] sa = br.readLine().split(" ");
		int n = Integer.parseInt(sa[0]);
		int m = Integer.parseInt(sa[1]);
		int s = Integer.parseInt(sa[2]) - 1;
		int t = Integer.parseInt(sa[3]) - 1;
		List<List<Hen>> list1 = new ArrayList<>(n);
		List<List<Hen>> list2 = new ArrayList<>(n);
		for (int i = 0; i < n; i++) {
			list1.add(new ArrayList<>());
			list2.add(new ArrayList<>());
		}
		for (int i = 0; i < m; i++) {
			sa = br.readLine().split(" ");
			int u = Integer.parseInt(sa[0]) - 1;
			int v = Integer.parseInt(sa[1]) - 1;
			int a = Integer.parseInt(sa[2]);
			int b = Integer.parseInt(sa[3]);

			list1.get(u).add(new Hen(v, a));
			list1.get(v).add(new Hen(u, a));
			list2.get(u).add(new Hen(v, b));
			list2.get(v).add(new Hen(u, b));
		}
		br.close();

		long[] d1 = new long[n];
		Arrays.fill(d1, Long.MAX_VALUE);
		d1[s] = 0;
		PriorityQueue<Node> que = new PriorityQueue<Node>();
		Node first = new Node(s, 0);
		que.add(first);

		while (!que.isEmpty()) {
			Node cur = que.poll();
			for (Hen hen : list1.get(cur.v)) {
				long alt = d1[cur.v] + hen.c;
				if (d1[hen.v] > alt) {
					d1[hen.v] = alt;
					Node next = new Node(hen.v, alt);
					que.add(next);
				}
			}
		}

		long[] d2 = new long[n];
		Arrays.fill(d2, Long.MAX_VALUE);
		d2[t] = 0;
		que = new PriorityQueue<Node>();
		first = new Node(t, 0);
		que.add(first);

		while (!que.isEmpty()) {
			Node cur = que.poll();
			for (Hen hen : list2.get(cur.v)) {
				long alt = d2[cur.v] + hen.c;
				if (d2[hen.v] > alt) {
					d2[hen.v] = alt;
					Node next = new Node(hen.v, alt);
					que.add(next);
				}
			}
		}

		PrintWriter pw = new PrintWriter(System.out);
		long[] min = new long[n];
		Arrays.fill(min, Long.MAX_VALUE);
		min[n - 1] = d1[n - 1] + d2[n - 1];
		for (int i = n - 2; i >= 0; i--) {
			min[i] = Math.min(min[i + 1], d1[i] + d2[i]);
		}
		for (int i = 0; i < n; i++) {
			pw.println(1_000_000_000_000_000L - min[i]);
		}
		pw.flush();
		pw.close();
	}

	static class Hen {
		int v, c;

		public Hen (int v, int c) {
			this.v = v;
			this.c = c;
		}
	}

	static class Node implements Comparable<Node> {
		int v;
		long d;

		public Node (int v, long d) {
			this.v = v;
			this.d = d;
		}

		public int compareTo(Node o) {
			if (d > o.d) {
				return 1;
			} else if (d == o.d) {
				return 0;
			} else {
				return -1;
			}
		}
	}
}


Measured memory_bytes: 94832
#include <bits/stdc++.h>
#define ll long long
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
using namespace std;
int main()
{
    string s;
    cin >> s;
    ll t = 0, n = s.size(), ans = 0;

    rep(i, n)
    {

        if (s[i] == 'B')
        {
            t++;
        }
        else
        {
            ans += t;
        }
    }
    cout << ans << endl;
    return 0;
}

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

int main() {
  long a, b, c, d;
  cin >> a >> b >> c >> d;
  vector<long> N= {a * c, a * d, b * c, b * d};
  sort(N.begin(), N.end());

  cout << N[3] << endl;
  return 0;
}

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

int main()
{
	int D, N;

	cin >> D >> N;

	for (int i = 1, c = 0; i <= 10000000; i++) {
		if (D == 0) {
			if (i % 100 != 0)c++;
		}
		else if (D == 1) {
			if (i % 100 == 0&&i%10000!=0)
				c++;
		}
		else if (D == 2) {
			if (i % 10000 == 0&&i%1000000!=0)
				c++;
		}

		if (c == N) {
			cout << i << endl;
			break;
		}
	}

	return 0;
}

Measured memory_bytes: 256
import itertools
import numpy as np
N,M,X = (int(x) for x in input().split())
S = []
C = []
l = []
ans = 10000000
for i in range(N):
  l.append(i)
for i in range(N):
  s = [int(x) for x in input().split()]
  S.append(s)
npS = np.array(S)
#print(npS)
for i in range(1,N+1):
  if i == 1:
    continue
  C =  list(itertools.combinations(l,i)) + C
#print(C)
for i in C:
  wa = np.zeros(M+1)
  #print("#",wa,S)
  for j in range(len(i)):
   # print(j,wa)
    wa = wa + S[i[j]]
  #print(i,wa)
  cnt = 0
 # print(len(wa))
  for k in range(0,len(wa)):
    if k == 0:
      continue
    if wa[k] >= X:
      cnt += 1
   # print(cnt,(ans > wa[0]))
    if cnt == M and ans > wa[0]:
      ans = wa[0]
for i in range(N):
  cnt = 0
  for j in range(M+1):
    if j == 0:
      continue
    if S[i][j] >= X:
      cnt += 1
    if cnt == M and ans > S[i][0]:
      ans = S[i][0]
if ans == 10000000:
  print(-1)
else:
  print(int(ans))

Measured memory_bytes: 27624
#include <memory.h>

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <utility>
#include <vector>

using namespace std;

#define mod 1000000007

int gcd(int m, int n) {
	if (n == 0) return m;
	return gcd(n, m % n);
}

int main() {
	int k;
	cin >> k;
	long long int ans = 0;
	for (int i = 1; i <= k; i++) {
		for (int j = 1; j <= k; j++) {
			for (int l = 1; l <= k; l++) {
				ans += gcd(i, gcd(j, l));
			}
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 3636
n,k = map(int,input().split())
a = list(map(int,input().split()))
kosu = [0]*n
kaburi = []

for i in range(n):
    kosu[a[i]-1] += 1

for j in range(n):
    if kosu[j] != 0:
        kaburi.append(kosu[j])

kaburi.sort()
print(sum(kaburi[:len(kaburi)-k]))

Measured memory_bytes: 32276
from collections import deque

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

e = [[] for i in range(n)]
for i in range(m):
    f, t = map(int,input().split())
    f -= 1
    t -= 1
    e[f].append(t)
    e[t].append(f)

INF = 10**9
dist = [INF] * n
dist[0] = 0
d = deque()
d.append([0, 0])

while d:
    f, c = d.pop()
    if c >= 2:
        break
    for t in e[f]:
        if c + 1 < dist[t]:
            dist[t] = c + 1
            d.appendleft([t, c+1])
print('POSSIBLE') if dist[n-1] <= 2 else print('IMPOSSIBLE')

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

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

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()

int n;
int ans[200010];

int main() {
	cin >> n;
	vector<pii> vec(n);

	rep(i, n) {
		int x;
		cin >> x;
		vec[i] = mp(x, i);
	}

	sort(ALL(vec));

	rep(i, n) {
		if (i < n/2) {
			ans[vec[i].se] = vec[n/2].fi;
		} else {
			ans[vec[i].se] = vec[n/2-1].fi;
		}
	}

	rep(i, n) {
		printf("%d\n", ans[i]);
	}

	return 0;
}

Measured memory_bytes: 4480
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <stack>
#include <queue>
#include <array>
#include <algorithm>
#include <utility>
#include <numeric>


using namespace std;


template <class ...Args>
void Input(Args &...args)
{
	(cin >> ... >> args);
}

template <class T>
void InputArray(std::size_t size, T &t)
{
	t.resize(size);
	for (auto &e : t) {
		cin >> e;
	}
}

template <class ...Args>
void InputArray(std::size_t size, Args &...args)
{
	(InputArray(size, args), ...);
}

template <class ...Args>
void InputVerticalArray(std::size_t size, Args &...args)
{
	(args.resize(size), ...);
	for (int i = 0; i < size; i++) {
		((cin >> args[i]), ...);
	}
}

template <class ...Args>
void Output(const Args &...args)
{
	((cout << args << ' '), ...) << endl;
}

template <class ...Args>
void OutputVertical(const Args &...args)
{
	((cout << args << endl), ...);
}

template <class T>
void OutputArray(const T &t)
{
	for (const auto &e : t) {
		cout << e << ' ';
	}
	cout << endl;
}

template <class ...Args>
void OutputArray(const Args &...args)
{
	(OutputArray(args), ...);
}

template <class ...Args>
void OutputVerticalArray(const Args &...args)
{
	for (int i = 0; i < min({ args.size()... }); i++) {
		((cout << args[i] << ' '), ...) << endl;
	}
}


#define inp(type, ...) \
	type __VA_ARGS__; \
	Input(__VA_ARGS__)

#define inpa(type, size, ...) \
	type __VA_ARGS__; \
	InputArray((size), __VA_ARGS__)

#define inpva(type, size, ...) \
	type __VA_ARGS__; \
	InputVerticalArray((size), __VA_ARGS__)

#define otp(...) \
	Output(__VA_ARGS__)

#define otpv(...) \
	OutputVertical(__VA_ARGS__)

#define otpa(...) \
	OutputArray(__VA_ARGS__)

#define otpva(...) \
	OutputVerticalArray(__VA_ARGS__)

#define rep(counter, range) \
	for (int (counter) = 0; (counter) < (range); (counter)++)

#define repi(range) \
	rep(i, range)

#define rrep(counter, range) \
	for (int (counter) = (range) - 1; (counter) >= 0; (counter)--)

#define rrepi(range) \
	rrep(i, range)

#define repc(element, container) \
	for (auto &(element) : (container))

#define repe(container) \
	repc(e, container)

#define all(container) \
	(container).begin(), (container).end()

#ifdef __CCR__
#	define dlog(x) clog << #x " = " << x << endl
#else
#	define dlog(x)
#endif



vector<int> factor(1000001);

void InitFactor()
{
	for (int i = 2; i <= 1000000; i++) {
		if (factor[i] == 0) factor[i] = i;
		for (int j = i + i; j <= 1000000; j += i) {
			factor[j] = i;
		}
	}
}


int main()
{
	inp(int, n);
	inpa(vector<int>, n, a);
	
	InitFactor();
	map<int, int> cnt;
	int fc;
	fc = a[0];
	for (int i = 1; i < n; i++) {
		fc = gcd(fc, a[i]);
	}
	bool setwise = fc == 1;
	repe(a) {
		while (e > 1) {
			fc = factor[e];
			do {
				e /= fc;
			} while (e % fc == 0);
			cnt[fc]++;
			if (cnt[fc] > 1) {
				otp(setwise ? "setwise coprime" : "not coprime");
				return 0;
			}
		}
	}
	otp("pairwise coprime");
	return 0;
}


Measured memory_bytes: 11164
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
typedef vector<int> vec1;
typedef vector<string> vec2;
typedef vector<double> vec3;

int main() {

  int n, m;
  cin >> n >> m;
  vec1 a(n);
  int c = 0;
  int A = 2;
  for(int i = 0; i < n; i++) {
    a.at(i) = A;
    A = A + 2;
    c++;
  }
  int B = 1;
  for(int i = 0; i < m; i++) {
    a.push_back(B);
    B = B + 2;
  }
  int ans = 0;
  sort(a.begin(),a.end());
  for(int i = 0; i < n+m; i++) {
    for(int j = i+1; j < n+m; j++) {
      if((a.at(i) + a.at(j)) % 2 == 0) {
        ans++;
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val x = sc.nextInt()
    val y = sc.nextInt()
    val a = sc.nextInt()
    val b = sc.nextInt()
    val c = sc.nextInt()

    val redArr = LongArray(a)
    repeat(a) {
        val red = sc.nextLong()
        redArr[it] = red
    }
    val sortedRedArr = redArr.sortedArrayDescending().take(x).toLongArray()

    val greenArr = LongArray(b)
    repeat(b) {
        val green = sc.nextLong()
        greenArr[it] = green
    }
    val sortedGreenArr = greenArr.sortedArrayDescending().take(y).toLongArray()

    val nonArr = LongArray(c)
    repeat(c) {
        val non = sc.nextLong()
        nonArr[it] = non
    }

    val sorted = (sortedRedArr + sortedGreenArr + nonArr).sortedArrayDescending()

    var answer = 0L
    repeat(x + y) {
        answer += sorted[it]
    }
    println(answer)


}


Measured memory_bytes: 112676