akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <algorithm>
#include <vector>
using namespace std;

class Node {
 public:
  int location;
  int p, l, r;
  Node() {}

};

class Point {
 public:
  int id, x, y;
  Point() {}
  Point(int id, int x, int y) :
    id(id),
    x(x),
    y(y) {}
  bool operator < (const Point &p) const {
    return id < p.id;
  }

  void print() {
    printf("%d\n", id);
  }
};

static const int MAX = 1000000;
static const int NIL = -1;

int N;
Point P[MAX];
Node T[MAX];
int np;

bool lessX(const Point &p1,
           const Point &p2) {
  return p1.x < p2.x;
}
bool lessY(const Point &p1,
           const Point &p2) {
  return p1.y < p2.y;
}

int makeKDTree(int l, int r, int depth) {
  if (!(l < r)) return NIL;
  int mid = (l+r) / 2;
  int t = np++;
  if (depth%2 == 0) {
    sort(P + l, P + r, lessX);
  } else {
    sort(P + l, P + r, lessY);
  }
  T[t].location = mid;
  T[t].l = makeKDTree(l, mid, depth + 1);
  T[t].r = makeKDTree(mid + 1, r, depth + 1);

  return t;
}

void find(int v,
          int sx, int tx,
          int sy, int ty,
          int depth, vector<Point> &ans) {
  int x = P[T[v].location].x;
  int y = P[T[v].location].y;

  if (sx <= x && x <= tx && sy <= y && y <= ty) {
    ans.push_back(P[T[v].location]);
  }

  if (depth%2 == 0) {
    if (T[v].l != NIL) {
      if (sx <= x) find(T[v].l, sx, tx, sy, ty, depth+1, ans);
    }
    if (T[v].r != NIL) {
      if (x <= tx) find(T[v].r, sx, tx, sy, ty, depth+1, ans);
    }
  } else {
    if (T[v].l != NIL) {
      if (sy <= y) find(T[v].l, sx, tx, sy, ty, depth+1, ans);
    }
    if (T[v].r != NIL) {
      if (y <= ty) find(T[v].r, sx, tx, sy, ty, depth+1, ans);
    }
  }
}

int main() {
  int x, y;
  scanf("%d", &N);
  for (int i = 0; i < N; i++) {
    scanf("%d %d", &x, &y);
    P[i] = Point(i, x, y);
    T[i].l = T[i].r = T[i].p = NIL;
  }
  np = 0;
  int root = makeKDTree(0, N, 0);

  int q;
  scanf("%d", &q);
  int sx, tx, sy, ty;
  vector<Point> ans;
  for (int i = 0; i < q; i++) {
    scanf("%d %d %d %d", &sx, &tx, &sy, &ty);
    ans.clear();
    find(root, sx, tx, sy, ty, 0, ans);
    sort(ans.begin(), ans.end());
    for (int j = 0; j < ans.size(); j++) {
      ans[j].print();
    }
    printf("\n");
  }
  return 0;
}



Measured memory_bytes: 15868
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <numeric>
#include <string>
#include <vector>

using namespace std;

void A_Next_Alphabet(void) {

	char C;
	cin >> C;
	cout << char(C + 1) << flush;
	return;
}

void B_Achieve_the_Goal(void) {

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

	vector<int> A(N - 1);
	for (int& it : A) cin >> it;

	int re = M * N - accumulate(A.begin(), A.end(), 0);
	
	if (re < 0)			cout << 0 << flush;
	else if (re > K)	cout << -1 << flush;
	else				cout << re << flush;
	return;
}

void C_Welome_to_AtCoder(void) {

	int N, M;
	cin >> N >> M;

	struct Problem {
		bool correct = false;
		int penalty = 0;
	};
	vector<struct Problem> problem(N);
	for (int loop = 0; loop < M; loop++) {
		int p;
		string S;
		cin >> p >> S;

		if (S.compare("AC") == 0) problem[p - 1].correct = true;
		else if (!problem[p - 1].correct) problem[p - 1].penalty++;	
	}

	int corSum = 0;
	int penSum = 0;
	for (struct Problem it :problem) {
		if (it.correct) {
			corSum++;
			penSum += it.penalty;
		}
	}
	cout << corSum << " " << penSum << flush;
	return;
}

int main(void) {

	//A_Next_Alphabet();
	//B_Achieve_the_Goal();
	C_Welome_to_AtCoder();
	return 0;
}


Measured memory_bytes: 1024
import java.util.*;
public class Main{
  static class NCK{
    int max;
    int mod;
    long[] fac;
    long[] finv;
    long[] inv;
    NCK(){
      this(510000,1000000007);
    }
    NCK(int max,int mod){
      this.max=max;
      this.mod=mod;
      pre(max,mod);
    }
    void pre(int nmax,int nmod){
      fac = new long[nmax];
      finv = new long[nmax];
      inv = new long[nmax];
      fac[0]=fac[1]=1;
      finv[0]=finv[1]=1;
      inv[1]=1;
      for(int i=2;i<nmax;i++){
        fac[i]=fac[i-1]*i%nmod;
        inv[i]=nmod-inv[nmod%i]*(nmod/i)%nmod;
        finv[i]=finv[i-1]*inv[i]%nmod;
      }
    }
    long nCk(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;
    }
  }
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n=sc.nextInt();
    int k=sc.nextInt();
    int mod=1_000_000_007;
    NCK nck=new NCK(n+3,mod);
    for(int i=1;i<=k;i++){
      long ans=nck.nCk(n-k+1,i)*nck.nCk(k-1,i-1);
      System.out.println(ans%mod);
    }
  }
}



Measured memory_bytes: 22356
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;

namespace AtTest.ABC_152
{
    class D
    {
        static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(OpenStandardOutput()) { AutoFlush = false };
            SetOut(sw);

            Method(args);

            Out.Flush();
        }

        static void Method(string[] args)
        {
            int n = ReadInt();
            var dict = new Dictionary<int, long>();
            for(int i = 1; i <= n; i++)
            {
                int tail = i % 10;
                int tmp = i;
                while (tmp >= 10) tmp /= 10;
                int head = tmp;
                int val = head * 10 + tail;
                if (dict.ContainsKey(val))
                {
                    dict[val]++;
                }
                else
                {
                    dict.Add(val, 1);
                }
            }
            long res = 0;
            for (int i = 1; i <= 9; i++)
            {
                for(int j = 1; j <= 9; j++)
                {
                    int a = i * 10 + j;
                    int b = j * 10 + i;
                    if (dict.ContainsKey(a) && dict.ContainsKey(b))
                    {
                        res += dict[a] * dict[b];
                    }
                }
            }
            WriteLine(res);
        }

        private static string Read() { return ReadLine(); }
        private static char[] ReadChars() { return Array.ConvertAll(Read().Split(), a => a[0]); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


Measured memory_bytes: 13272
// 
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <stack>
#include <queue>
#include <iomanip>
#include <set>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;

int main()
{
    ll n, m, k;
    cin >> n >> m >> k;
    vector<ll> a(n), asum(n+1), b(m), bsum(m+1);
    for (ll i = 0; i < n; ++i) cin >> a[i];
    for (ll i = 0; i < m; ++i) cin >> b[i];
    asum[0] = 0, bsum[0] = 0;
    for (int i = 1; i <= n; ++i)
    {
        asum[i] = asum[i - 1] + a[i - 1];
    }
    for (int i = 1; i <= m; ++i)
    {
        bsum[i] = bsum[i - 1] + b[i - 1];
    }

    ll ans = 0, jmax = m;

    for (ll i = 0; i <= n; ++i)
    {
        if (asum[i] > k) break;
        for (ll j = jmax; j >= 0; --j)
        {
            if (asum[i] + bsum[j] <= k)
            {
                ans = (max)(ans, i + j);
                jmax = j;
                break;
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 9520
#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
using str = string;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
const double PI = 3.141592653589793238;
const ll mod = 1000000007;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define REP(i, m, n) for (int i = m; i < (int)n; i++)
#define all(a) (a).begin(), (a).end()
#define allg(a) (a).begin(), (a).end(), greator<>()
#define d20 std::setprecision(20)
#define veci vector<int>
#define vecll vector<long long int>
#define vecb vector<bool>
#define vecd vector<double>
template <typename T>
T lcm(T a, T b)
{
	return a / __gcd(a, b) * b;
}

int main()
{
	str s, t;
	cin >> s >> t;
	int ans = 0;
	rep(i, s.size())
	{
		if (s[i] != t[i])
		{
			ans++;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3856
#include <cstdio>
#include <cmath>
#include <cstring>
#include <iostream>
#include <sstream>

#include <string>
#include <vector>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <deque>
#include <algorithm>
#include <random>
using namespace std;


int main(int argc, char *argv[]) {
    long long int n, k;
    cin >> n >> k;
    vector<long long int> v1, v2;
    for (int i = 0; i < n; i++) {
        long long int a;
        cin >> a;
        v1.push_back(a);
    }
    for (int i = 0; i < n; i++) {
        long long int f;
        cin >> f;
        v2.push_back(f);
    }

    sort(v1.begin(), v1.end());
    sort(v2.begin(), v2.end());
    reverse(v2.begin(), v2.end());
    
    long long int l = 0, h = 1;
    for (int i = 0; i < n; i++) {
        h = max(h, v1[i] * v2[i]);
    }
    while (l < h) {
        // cout << l << " " << h << endl;
        long long int m = (l + h) / 2;
        long long int kk = 0;
        for (int i = 0; i < n; i++) {
            if (v1[i] * v2[i] <= m)
                continue;
            kk += (v1[i] * v2[i] - m) / v2[i] + ((v1[i] * v2[i] - m) % v2[i] > 0 ? 1 : 0);
        }
        if (kk <= k) {
            h = m;
        }
        else if (kk > k) {
            l = m + 1;
        }
    }
    cout << l << endl;
}




Measured memory_bytes: 5360
#include <iostream>
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>

using namespace std;
#define REP(i,n) FOR(i,0,n)
#define FOR(i,a,b) for(long long i=(a),i##Len_=(b);i<i##Len_;i++)
typedef long long ll;
static const ll MOD = 1000000007;
static const ll INF = 1000000000000000000LL;



int main()
{
    ll N;

    cin >> N;

    ll a[N];

    ll array[512345];

    ll left = 212345;
    ll right = left + 1;
    REP(i,N)
    {
        cin >> a[i];
    }

    REP(i,N)
    {
        if(i % 2 == (N-1)%2)
        {
            array[left--] = a[i];
        }
        else
        {
            array[right++] = a[i];
        }
    }

    for(ll i = left+1; i< right; ++i)
    {
        cout << array[i] << " ";
    }
}



Measured memory_bytes: 6400
// C++ program to find if a number is divisible by 
// 9 or not 
#include<bits/stdc++.h> 
using namespace std; 
  
// Function to find that number divisible by 9 or not 
int check(string str) 
{ 
    // Compute sum of digits 
    int n = str.length(); 
    int digitSum = 0; 
    for (int i=0; i<n; i++) 
        digitSum += (str[i]-'0'); 
  
    // Check if sum of digits is divisible by 9. 
    return (digitSum % 9 == 0); 
} 
  
// Driver code 
int main() 
{ 
  	string str;
    cin>>str; 
    check(str)?  cout << "Yes" : cout << "No "; 
    return 0; 
} 

Measured memory_bytes: 3848
import sys
sys.setrecursionlimit(10**6)
INF = 10 ** 9
N ,M = map(int,input().split())

G = [[] for i in range(N+1)]

for _ in range(M):
    l, r, d = map(int, input().split())
    G[l].append((r, d))
    G[r].append((l, -d))

dp = [INF] * (N+1)

def dfs(l):
    for r, d in G[l]:
        if dp[r] == INF:
            dp[r] = dp[l] + d
            if not dfs(r):
                return False
        elif dp[r] != dp[l] + d:
            return False
    return True

for i in range(1, N+1):
    if dp[i] == INF:
        dp[i] = 0
        if not dfs(i):
            print('No')
            exit()

print('Yes')


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

using namespace std;

typedef long long ll;

int main() {
#ifndef ONLINE_JUDGE
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n, l;
    cin >> n >> l;
    vector <string> s(n);
    for(int i = 0; i < n; i++){
        cin >> s[i];
    }
    sort(s.begin(), s.end());
    string ans = "";
    for(int i = 0; i < n; i++){
        ans += s[i];
    }
    cout << ans << "\n";
    return 0;
}


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

vector<vector<int>> is_connected;
vector<int> node_sum;
int n,q;

void add_to_child(int node,int parent){
	for(int i=0;i<(int)is_connected[node].size();i++){
		int tar = is_connected[node][i];
		if(tar == parent){continue;}
		node_sum[tar] += node_sum[node];
		add_to_child(tar,node);
	}
}
int main(){
	cin >> n >> q;
	is_connected.resize(n);
	node_sum.resize(n);
	for(int i=0;i<n;i++) node_sum[i] = 0;
	int a,b;
	for(int i=0;i<n-1;i++){
		//cin >> a >> b;
		scanf("%d %d",&a,&b);
		is_connected[a-1].push_back(b-1);
		is_connected[b-1].push_back(a-1);
	}
	for(int i=0;i<q;i++){
		cin >> a >> b;
		node_sum[a-1] += b;
	}
	add_to_child(0,-1);
	for(int i=0;i<n;i++){
		cout << node_sum[i] << " ";
	}
	cout << endl;
	return 0;
}


Measured memory_bytes: 23552
#include <bits/stdc++.h>//Carefully Crafted by hetp111
using namespace std;
#define int long long
#define double long double
#define all(v) (v).begin(),(v).end()
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int,int>
#define vii vector<pii>
#define MOD (1000000007)
//#define MOD (998244353)
#define PI acos(-1)
#define eps (1e-8)
#define INF (1e18)
#define FASTER ios_base::sync_with_stdio(0);cin.tie(0)
template<class A,class B>ostream&operator<<(ostream&out,const pair<A,B>&a){return out<<"("<<a.first<<","<<a.second<<")";}
template<class A>ostream&operator<<(ostream&out,const vector<A>&a){for(const A &it:a)out<<it<<" ";return out;}
template<class A,class B>istream&operator>>(istream&in,pair<A,B>&a){return in>>a.first>>a.second;}
template<class A>istream&operator>>(istream&in,vector<A>&a){for(A &i:a)in>>i;return in;}
//ifstream cinn("input.txt");ofstream coutt("output.txt");


signed main(){
    FASTER;
    int n;cin>>n;
    string s;cin>>s;
    for(char &c:s){
        if(c=='R')c='A';
        else if(c=='G')c='B';
        else if(c=='B')c='C';
    }
    vi v[3];
    for(int i=0;i<n;i++)v[s[i]-'A'].push_back(i);
    
    int ans=0;
    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            if(s[i]==s[j])continue;
            
            int dusra=3-(s[i]-'A'+s[j]-'A');// 0 1, 2 1, 0 2 
            
            auto up=v[dusra].end();
            auto dw=upper_bound(all(v[dusra]),j);
            
            ans+=up-dw;
            ans-=binary_search(dw,up,j+(j-i));
            
        }
    }
    cout<<ans;
}






Measured memory_bytes: 3680
#include<iostream>
#include<cstring>
#include<vector>
#include<queue>
using namespace std;

const int NMax = 100000 + 10;

int N;

int main() {

    cin>>N;
    int total = N*800,nr=(N/15),backM=nr*200;
    cout<<total-backM;

    return 0;
}





Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int w = sc.nextInt();
		int a = sc.nextInt();
		int b = sc.nextInt();
		int res = 0;
		if ( (a+w) < b ) res = b-(a+w);
		if ( (b+w)<a ) res = a-(b+w);
		
		System.out.println(res);
	}
}


Measured memory_bytes: 23636
eval"N,A,B,K="+`tr ' ' ,`
f=s=1,*(1..N).map{s=s*_1%M=998244353}
p (0..N).sum{|a|b=(K-A*a)/B
b>N||A*a+B*b!=K||b<0?0:s*s*(f[a]*f[b]*f[~a]*f[~b]).pow(M-2,M)}%M

Measured memory_bytes: 47692
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define DUMP(x)  cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for(ll i = m; i < n; i++)
#define IFOR(i, m, n) for(ll i = n - 1; i >= m; i-- )
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define FOREACH(x,a) for(auto& (x) : (a) )
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) ll(x.size())

int main(){
  vector<string> s(3);
  ll N; cin >> N;
  REP(i,3) cin >> s[i];
  ll ans = 0;
  REP(i,N){
    set<char> st;
    REP(j,3) st.insert(s[j][i]);
    ans += SZ(st)-1;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
while True:
    R=str(input())
    if R=='0':
        break
    r=list(R)
    a=0
    b=0
    for i in range(len(r)-1):
        if r[i+1]=='A':
            a+=1
        else:
            b+=1
    if a>b:
        print(a+1,b)
    else:
        print(a,b+1)


Measured memory_bytes: 5556
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n, k, res;
	cin>>n>>k;
	res = 0;
	vector<int> vec(n, 0);
	for(int i = 0; i < n; ++i)cin>>vec[i];
	sort(vec.begin(), vec.end());
	for(int i = 0; i < n; ++i){
		if(k - vec[i] >= 0){
			k -= vec[i];
			res++;
		}
		else{
			k = 0;
		}
	}
	if(k > 0 && res > 0){
		res--;
	} 
	cout<<res<<endl;
	return 0;
}

Measured memory_bytes: 384
def main():
    from collections import Counter
    import sys
    input = sys.stdin.readline
    n=int(input())
    s=[]
    for _ in [0]*n:
        s.append(input().rstrip())
    c = Counter(s)
    ans=[]
    max_vote = max(c.values())
    for i,j in c.items():
        if j == max_vote:
            ans.append(i)
    print("\n".join(sorted(ans)))
main()

Measured memory_bytes: 35980
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define INF 1000000010
#define EPS 1e-9
#define fst first
#define scd second

#define debug(x) cout<<x<<endl;
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define lp(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
#define int long long
#define endl "\n"


signed main(){
  cin.tie(0);	
  //ios::sync_with_stdio(false);
  while(1){
    int h,w;
    cin>>w>>h;
    if(h==0 && w==0) break;
    char c[h][w];
    rep(i,h){
      rep(j,w){
	cin>>c[i][j];
      }
    }
    string dp[h][w];
    rep(i,h){
      rep(j,w){
	dp[i][j]="0";
      }
    }
    string ans="0";
    rep(i,h){
      rep(j,w){
	if(i>0){
	  if(isdigit(c[i-1][j]) && isdigit( c[i][j])){
	    string t=dp[i-1][j]+c[i][j];
	    if(t.size() > dp[i][j].size() ) dp[i][j]=t;
	    else if(t.size() == dp[i][j].size() ){
	      rep(k,t.size() ){
		if(t[k]>dp[i][j][k]){dp[i][j]=t;break;}
		else if(t[k]<dp[i][j][k]) break;
	      }
	    }
	  }
	}
	
	if(j>0){
	  if(isdigit(c[i][j-1] )&& isdigit( c[i][j])){
	    string t=dp[i][j-1]+c[i][j];
	    if(t.size() > dp[i][j].size() ) dp[i][j]=t;
	    else if(t.size() == dp[i][j].size() ){
	      rep(k,t.size() ){
		if(t[k]>dp[i][j][k]){dp[i][j]=t;break;}
		else if(t[k]<dp[i][j][k]) break;
	      }
	    }
	  }
	}
	if(isdigit(c[i][j])){
	  string tt={c[i][j]};
	  if(dp[i][j].size() == tt.size() && dp[i][j]<tt) dp[i][j]=tt;
	  if(ans.size() < dp[i][j].size() ) ans=dp[i][j];
	  else if(ans.size() == dp[i][j].size() ){
	    rep(k,ans.size() ){
	      if(ans[k]<dp[i][j][k]){ans=dp[i][j];break;}
	      else if(ans[k]>dp[i][j][k]) break;
	    }
	  }
	}
	while(dp[i][j][0]=='0' && dp[i][j].size() > 0){
	  dp[i][j]=dp[i][j].substr(1);
	}
      }
      
    }
    /*rep(i,h){
      rep(j,w){
	cout<<dp[i][j]<<"    ";
      }
      cout<<endl;
      }*/
    
    cout<<ans<<endl;
  }

  return 0;
}



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

int main() {
    int A, B;
    cin >> A >> B;
    double xa, xb;
    xa = A * 100 / 8.0;
    xb = B * 100 / 10.0;
    double ans = 0;
    if (xa > xb)
        ans = (double)xa;
    else
        ans = (double)xb;

    if ((int)((int)ans * 0.08) != A || (int)((int)ans * 0.1) != B) {
        if ((int)(((int)ans + 1) * 0.08) == A && (int)(((int)ans + 1) * 0.1) == B) {
            cout << (int)ans + 1 << endl;
        } else
            cout << -1 << endl;
    } else
        cout << (int)ans << endl;
    return 0;
}

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

int	main()
{
	int	A, B, M;
	int	*a, *b, min, numa, numb;
	int	x, y, c, sum;

	scanf("%d %d %d\n", &A, &B, &M);
	a = (int *)malloc(sizeof(int) * (A + 1));
	b = (int *)malloc(sizeof(int) * (B + 1));
	min = 10001;
	for (int i = 0; i < A; i++)
	{
		scanf("%d ", &a[i]);
		if (a[i] < min)
		{
			min = a[i];
			numa = i;
		}
	}
	min = 10001;
	for (int i = 0; i < B; i++)
	{
		scanf("%d ", &b[i]);
		if (b[i] < min)
		{
			min = b[i];
			numb = i;
		}
	}
	min = a[numa] + b[numb];
	for (int i = 0; i < M; i++)
	{
		scanf("%d %d %d", &x, &y, &c);
		sum = a[x - 1] + b[y - 1] - c;
		if (sum < min)
			min = sum;
	}
	printf("%d\n", min);
	return (0);
}

Measured memory_bytes: 1024
n=int(input())
#tempt

A=map(int,input().split())
MOD=1000000007
ans = 1
cnt = [3 if i == 0 else 0 for i in range(n + 1)]

for a in A:
    ans = ans * cnt[a] % MOD
    if ans == 0:
        break
    cnt[a] -= 1
    cnt[a + 1] += 1

print(ans)

Measured memory_bytes: 11196
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.util.*;

public class Main {

    int[] inputArray;

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

    void run() {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int K = sc.nextInt();
        inputArray = new int[N];

        for(int i=0; i<N; i++){
            inputArray[i] = sc.nextInt();
        }

        int sum = 0;

        for(int i=0; i<N; i++){
            int num = inputArray[i];
            int ans = Math.min(Math.abs(num-K)*2, Math.abs(num-0)*2);

            sum += ans;
        }

        System.out.println(sum);
    }

}

Measured memory_bytes: 21844
#include <iostream>

using namespace std;

int main(void) {
	int N;
	cin >> N;
	int mp = 0;
	int sum = 0;
	for (int i = 0; i < N; ++i) {
		int p;
		cin >> p;
		mp = max(p,mp);
		sum += p;
	}
	cout << sum-(mp/2) << endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<cmath>
#include<algorithm>
#include<string>
#include <utility>

using namespace std;


int main() {

	int x, r, D;
	cin >> r >> D >> x;

	for (auto i = 0; i < 10; i++) {
		x = r * x - D;
		cout << x << endl;
	}



	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <fstream>
#include <vector>
#include <cstdio>
#include <cmath>
#include <queue>
#include <stack>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <list>
#include <bitset>

using namespace std;
typedef long long ll;

// #define DEBUG

class Unionfind
{
    vector<int> p;

public:
    Unionfind(int n);
    int find(int x);
    void unite(int x, int y);
    bool match(int x, int y);
};

Unionfind::Unionfind(int n)
{
    for (int i = 0; i < n; i++)
    {
        p.push_back(i);
    }
}

int Unionfind::find(int x)
{
    while (p[x] != x)
    {
        p[x] = p[p[x]];
        x = p[x];
    }
    return x;
}

bool Unionfind::match(int x, int y)
{
    return (find(x) == find(y)) ? true : false;
}

void Unionfind::unite(int x, int y)
{
    x = Unionfind::find(x);
    y = Unionfind::find(y);
    if (x != y)
    {
        p[x] = y;
    }
}

int main()
{
#ifdef DEBUG
    cout << "DEBUG MODE" << endl;
    ifstream in("input.txt"); //for debug
    cin.rdbuf(in.rdbuf());    //for debug
#endif
    int n, m, x;
    set<int> a, b, c, d, e;

    cin >> n;
    for (int i = 0; i < n; i++)
    {
        cin >> x;
        a.insert(x);
    }
    cin >> m;
    for (int i = 0; i < m; i++)
    {
        cin >> x;
        b.insert(x);
    }

    for (auto itr = a.begin(); itr != a.end(); itr++)
    {
        c.insert(*itr);
    }

    for (auto itr = b.begin(); itr != b.end(); itr++)
    {
        c.insert(*itr);
    }

    for (auto itr = a.begin(); itr != a.end(); itr++)
    {
        auto itr2 = b.find(*itr);
        if (itr2 != b.end())
            d.insert(*itr);
    }

    for (auto itr = c.begin(); itr != c.end(); itr++)
    {
        auto itr2 = d.find(*itr);
        if (itr2 == d.end())
            e.insert(*itr);
    }

    for (auto itr = e.begin(); itr != e.end(); itr++)
    {
        cout << *itr << endl;
    }

    return 0;
}

// getline(cin,s);
// a = strtok(s, ",");  ","で分解
// for (int i = 0; i < n; i++)


Measured memory_bytes: 59348
// Always check for base cases
            // Check for overflows and out of index
            // Do something instead of sitting idle
            #include<bits/stdc++.h>
            #define ll long long
            #define f   first
            #define s   second
            #define pb          push_back
            #define mod        1000000007
            #define mod1       1000000009
            #define hell        998244353
            #define inf         1000000000000000000LL
            #define pi          3.14159265358979323
            //#define N           100005 
            const int N=200005;
            using namespace std;
            ll n,k,sum,q,res,m,val,ans;
            ll x,y;
            double p;
            ll xx[]={1,0,-1,0};
            ll yy[]={0,1,0,-1};
            void solve()    
            {   
                string s;
                cin>>s;
                n=s.size();
                ll ans=0;
                for(int i=0;i<n;i++) ans+=(s[i]-'0');
                if(ans%9==0) cout<<"Yes\n";
            else cout<<"No\n";


            }
            int main()  
            {   ios_base::sync_with_stdio(false);
                cin.tie(0);cout.tie(0);
                ll t=1;  
                //cin>>t;
                 for(ll i=1;i<=t;i++)
                    solve();
                

            }            


Measured memory_bytes: 3764
#include<bits/stdc++.h>                          
using namespace std;
int n,ans;
string s;             
int main(){
    cin>>n>>s;
    for(int i=0;i<n-2;i++)
        if(s[i]=='A'&&s[i+1]=='B'&&s[i+2]=='C') ans++;
    cout<<ans;
	return 0;
}

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

B = [0]*(N+1)
for i in range(N):
    B[A[i]] += 1
B.sort(reverse = True)
cnt = 0
for i in range(K):
     cnt += B[i]
print(N - cnt)


Measured memory_bytes: 32316
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath> //abs();
using namespace std;

int main(void)
{
    long long int a,b,c,d,i,j,k,n,x[10];
    string s;
    char C[5];

    cin >> a >> b >> c;

    if(b-a==c-b) cout << "YES"; 
    else cout << "NO";

    return 0;
}


Measured memory_bytes: 256
//Author- VMAX


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_multiset tree<long long , null_type,less_equal<long long >, rb_tree_tag,tree_order_statistics_node_update>
#define ordered_set tree<long long , null_type,less<long long >, rb_tree_tag,tree_order_statistics_node_update>
using namespace std;
#define ll long long int
#define YES cout<<"YES"<<"\n";
#define NO cout<<"NO"<<"\n";
#define ld     long double 
#define yes cout<<"yes"<<"\n";
#define no cout<<"no"<<"\n";
#define No cout<<"No"<<"\n";
#define Yes cout<<"Yes"<<"\n";
#define f(i,a) for(i=0;i<a;i++)
#define fo(i,a) for(i=1;i<=a;i++)
#define fa(i,a) for(auto i:a)
#define r(i,a) for(auto i=a.rbegin();i!=a.rend();i++)
#define en cout<<"\n";
#define ull unsigned long long int
#define o(x) cout<<x<<"\n";
#define o1(x) cout<<x<<" ";
#define pb push_back
#define F first
#define in insert
#define mp make_pair
#define S second
#define pre(n) cout<<fixed<<setprecision(n);
#define      gcd(a,b)    __gcd(a,b)
#define bs            binary_search
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define test ll t;cin>>t;while(t-->0)
const ll Mod = 998244353;
#define mod 1000000007
#define pi 3.14159265358979323846
#define all(x) x.begin(),x.end()
#define re return 0;
// *#######################################################################################*

/*
bool isp(ll n)
{
    ll i;
    for(i=2;i*i<=n;i++)
    {
        if(n%i==0)
        {
            return false;
        }
        
    }
}
  */
  ll powerm(ll x, unsigned ll y, ll p)  
{  
    ll res = 1;    
  
    x = x % p; 
   
    if (x == 0) return 0;
  
    while (y > 0)  
    {  
        if (y & 1)  
            res = (res*x) % p;  
   
        y = y>>1; // y = y/2  
        x = (x*x) % p;  
    }  
    return res;  
}
  long long lcm(long long a, long long b){//最小公倍数を求める
   return a * b / gcd(a, b);
}
//ll ss[2][(1<<22)+10];
       int main()
       
       {
        fast
    
         
       ll n;
       cin>>n;
       ll a[n],i;
       f(i,n)
       {
           cin>>a[i];
       }
    ll c=0;
    sort(a,a+n);
    ll z=a[n/2],z1=a[n/2-1];
    z1++;
    
    o(z-z1+1)
    
        
       
          re
}


Measured memory_bytes: 4412
#include <bits/stdc++.h>
using namespace std;
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef pair<int, int> Pint;
typedef pair<int64_t, int64_t> Pll;

int main() {
    int N, M;
    cin >> N >> M;
    
    if (500 * N >= M) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }

}



Measured memory_bytes: 256
H, W, K = map(int, input().split(' '))
ls, rst = [], 0
for i in range(H):
    ls.append(input())

for i in range(1 << H):
    for j in range(1 << W):
        cnt = 0
        for s in range(H):
            if i >> s & 1:
                continue
            for t in range(W):
                if j >> t & 1:
                    continue
                if ls[s][t] == '#':
                    cnt += 1
        if cnt == K:
            rst += 1
print(rst)

Measured memory_bytes: 9152
#include <bits/stdc++.h>
#define rep(a,n) for (ll a = 0; a < (n); ++a)
using namespace std;
typedef long long ll;
using ll = long long;
typedef pair<ll,ll> P;
typedef pair<P,ll> PP;
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; }
const ll INF = 1e18;

ll n;
vector<ll>a;

ll dp[2020][2020];

vector<ll>id;

ll rec(ll i,ll j){
    if(dp[i][j]>=0)return dp[i][j];
    ll res = 0;
    ll move = n+i-j;
    if(i>0){
        ll l = rec(i-1,j);
        l += a[id[move-1]]*abs(id[move-1]-(i-1));
        chmax(res,l);
    }
    if(j<n){
        ll r = rec(i,j+1);
        r += a[id[move-1]]*abs(id[move-1]-j);
        chmax(res,r);
    }
    return dp[i][j]=res;
}

int main(){
    cin >> n;
    a.resize(n);
    vector<P>vec(n);
    rep(i,n){
        cin>>a[i];
        vec[i]={a[i],i};
    }
    sort(vec.rbegin(),vec.rend());
    id.resize(n);
    rep(i,n){
        id[i]=vec[i].second;//i番目に大きい要素が左から何番目か
    }
    ll ans = 0;
    rep(i,2020)rep(j,2020)dp[i][j]=-1;


    rep(i,n+1){
        chmax(ans,rec(i,i));
    }

    cout << ans << endl;



    return 0;
}

Measured memory_bytes: 35656
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
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 EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
const ll mod = 1000003;
ll inv[1000010];
ll FactorialInv[1000010];
ll Factorial[1000010];
ll beki(ll a, ll b){
    if(b == 0){
        return 1;
    }
    ll ans = beki(a, b / 2);
    ans = ans * ans % mod;
    if(b % 2 == 1){
        ans = ans * a % mod;
    }
    return ans;
}
void init_combination(){
    inv[1] = 1;
    FactorialInv[1] = 1;
    Factorial[1] = 1;
    Factorial[0] = 1;
    FactorialInv[0] = 1;
    inv[0] = 1;
    for(int i = 2; i < 1000010; i++){
        inv[i] = beki(i, mod - 2);
        Factorial[i] = Factorial[i - 1] * i % mod;
        FactorialInv[i] = FactorialInv[i - 1] * inv[i] % mod;
    }
}
ll combination(ll a, ll b){
    if((a == b) || (b == 0)){
        return 1;
    }
    ll ans = Factorial[a] * FactorialInv[b] % mod;
    ans = ans * FactorialInv[a - b] % mod;
    return ans;
}
ll product[1000100];

int main() {
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
    init_combination();
    product[0] = 1;
    for(ll i = 1; i <= mod; i++) {
        product[i] = product[i-1] * i % mod;
        //cerr << i << " " << product[i] << " " << inv[product[i]];
        //cerr << " " << product[i] * inv[product[i]] % mod << endl;
    }
    ll Q;
    cin >> Q;
    while(Q--) {
        ll x, d, n;
        cin >> x >> d >> n;
        if(x == 0) {
            cout << 0 << endl;
            continue;
        }
        if(d == 0) {
            cout << beki(x, n) << endl;
            continue;
        }
        ll ans = beki(d, n);
        ll start = x * inv[d] % mod;
        //cerr << start << endl;
        if(start + n - 1 >= mod) {
            cout << 0 << endl;
            continue;
        }
        cout << (ans * product[start + n - 1] % mod) * inv[product[start-1]] % mod << endl;
    }
    return 0;
}


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

using namespace std;

const int inf = 1000000000;

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

	int n;
	cin >> n;

	int m = 1 << n;

	vector<int> a;
	a.resize(m);

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

	vector<int> dp_1;
	dp_1.resize(m);
	iota(dp_1.begin(), dp_1.end(), 0);

	vector<int> dp_2;
	dp_2.assign(m, -1);

	for(int S = 0; S < m; ++S) {
		for(int i = 0; i < n; ++i) {
			if((S >> i & 1) == 0) {
				if(dp_1[S] != dp_1[S ^ (1 << i)]) {
					if(a[dp_1[S]] >= a[dp_1[S ^ (1 << i)]]) {
						dp_2[S ^ (1 << i)] = dp_1[S ^ (1 << i)];
						dp_1[S ^ (1 << i)] = dp_1[S];
					} else if(dp_2[S ^ (1 << i)] == -1 || a[dp_1[S]] > a[dp_2[S ^ (1 << i)]]) {
						dp_2[S ^ (1 << i)] = dp_1[S];
					}
				}
			}
		}
	}

	int ans = -inf;

	for(int i = 1; i < m; ++i) {
		ans = max(ans, a[dp_1[i]] + a[dp_2[i]]);
		cout << ans << '\n';
	}

	return 0;
}

Measured memory_bytes: 6144
import java.io.*;
import java.math.BigDecimal;
import java.util.*;


public class Main {
	public static void main(String[] args) {	
		Scanner sc = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		while(true) {
			int m = sc.nextInt();
			int n = sc.nextInt();
			if(m == 0 && n == 0) break;
			int[] b = new int[m];
			int[] r = new int[n];
			for(int i = 0; i < m; i++) {
				b[i] = sc.nextInt();
			}
			for(int i = 0; i < n; i++) {
				r[i] = sc.nextInt();
			}
			MaximumFlow mf = new MaximumFlow(m+n+2,m+n,m+n+1);
			for(int i = 0; i < m; i++) {
				mf.addEdge(m+n, i, 1);
			}
			for(int i = m; i < m + n; i++) {
				mf.addEdge(i, m+n+1, 1);
			}
			for(int i = 0; i < m; i++) {
				for(int j = 0; j < n; j++) {
					boolean ok = gcd(b[i],r[j])==1?false:true;
					if(ok) {
						mf.addEdge(i, m + j, 1);
					}
				}
			}
			int ans = mf.fordFulkerson();
			System.out.println(ans);
		}
		
	}
	static int gcd(int a, int b) {
		if(a < b) return gcd(b,a);
		if(b == 0) return a;
		return gcd(b,a%b);
	}
	
}
class MaximumFlow {
	public static final int INF = 100000000;

	int V;
	int source;
	int sink;

	java.util.ArrayList<Edge>[] graph;
	boolean[] used;

	@SuppressWarnings("unchecked")
	public MaximumFlow(int V, int source, int sink) {
		this.V = V;
		this.source = source;
		this.sink = sink;
		graph = new java.util.ArrayList[V];
		for (int i = 0; i < V; i++) {
			graph[i] = new java.util.ArrayList<Edge>();
		}
		used = new boolean[V];
	}

	public void addEdge(int from, int to, int cap) {
		graph[from].add(new Edge(to, cap, graph[to].size()));
		graph[to].add(new Edge(from, 0, graph[from].size() - 1));
	}

	public int fordFulkerson() {
		int flow = 0;
		while (true) {
			java.util.Arrays.fill(used, false);
			int f = dfsFF(source, sink, INF);
			if (f == 0) {
				break;
			}
			flow += f;
		}
		return flow;
	}

	private int dfsFF(int from, int to, int flow) {
		if (from == to) {
			return flow;
		}
		used[from] = true;

		for (Edge edge : graph[from]) {
			if (used[edge.to] || edge.cap <= 0) {
				continue;
			}
			int d = dfsFF(edge.to, to, Math.min(flow, edge.cap));
			if (d > 0) {
				edge.cap -= d;
				graph[edge.to].get(edge.rev).cap += d;
				return d;
			}
		}
		return 0;
	}

	class Edge {
		int to;
		int cap;
		int rev;

		public Edge(int to, int cap, int rev) {
			this.to = to;
			this.cap = cap;
			this.rev = rev;
		}
	}

}

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

using namespace std;

int n, m;
int l[300100], r[300100];
vector<int> chan[100100];
vector<int> part[100100];
int now[100100];

int main() {
    int i, j, k;

    scanf("%d%d",&n,&m);
    for (i=0;i<n;i++) {
        scanf("%d%d",&l[i],&r[i]);
        l[i]--;
        part[l[i]].push_back(r[i]);
        part[r[i]].push_back(l[i]);
    }
    for (i=1;i<=m;i++) {
        for (j=1;j*j<=i;j++) chan[j].push_back(i);
        int cur;
        for (;;) {
            cur = i/j;
            chan[j].push_back(i);
            if (!cur) break;
            j = i/cur+1;
        }
    }
    for (i=0;i<=m;i++) now[i] = i;
    printf("%d\n",n);
    int res = n;
    for (i=2;i<=m;i++) {
        for (j=0;j<chan[i].size();j++) {
            for (k=0;k<part[chan[i][j]].size();k++) {
                if (now[part[chan[i][j]][k]]==now[chan[i][j]]&&now[part[chan[i][j]][k]]!=chan[i][j]/i) res++;
                else if (now[part[chan[i][j]][k]]!=now[chan[i][j]]&&now[part[chan[i][j]][k]]==chan[i][j]/i) res--;
            }
            now[chan[i][j]] = chan[i][j]/i;
        }
        printf("%d\n",res);
    }

    return 0;
}


Measured memory_bytes: 197448
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N=200005;
int read(){
	int x=0,f=1;
	char ch=getchar();
	while (!isdigit(ch)&&ch!='-')
		ch=getchar();
	if (ch=='-')
		f=-1,ch=getchar();
	while (isdigit(ch))
		x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
	return x*f;
}
int n,Len,T;
int x[N],w[N],res[N];
vector <int> v1,v2;
int s1,s2;
bool check(int x){
	int L,R;
	if (!w[0])
		L=(x-1)>>1,R=x>>1;
	else
		L=x>>1,R=(x-1)>>1;
	LL tot=1LL*(L/s1)*Len+v1[L%s1]
		  +1LL*(R/s2)*Len+v2[R%s2];
	return tot<=(T<<1);
}
int main(){
	n=read(),Len=read(),T=read();
	v1.clear();
	v2.clear();
	for (int i=0;i<n;i++){
		x[i]=read(),w[i]=read()&1;
		if (w[i])
			res[i]=(x[i]+T)%Len;
		else
			res[i]=((x[i]-T)%Len+Len)%Len;
		if (!w[i])
			v2.push_back(x[i]-x[0]);
		else
			v1.push_back((x[0]-x[i]+Len)%Len);
	}
	if (v1.empty()||v2.empty()){
		for (int i=0;i<n;i++)
			printf("%d\n",res[i]);
		return 0;
	}
	sort(res,res+n);
	sort(v1.begin(),v1.end());
	s1=v1.size(),s2=v2.size();
	int L=1,R=T<<1,ans=0;
	while (L<=R){
		int mid=(L+R)>>1;
		if (check(mid))
			L=mid+1,ans=mid;
		else
			R=mid-1;
	}
	int p0;
	if (ans==0)
		p0=w[0]?(x[0]+T)%Len:(x[0]+Len-T)%Len;
	else {
		if (!w[0])
			L=(ans-1)>>1,R=ans>>1;
		else
			L=ans>>1,R=(ans-1)>>1;
		int tot=L/s1*Len+v1[L%s1]+R/s2*Len+v2[R%s2];
		T=(T<<1)-tot;
		LL p=(R/s2*Len+v2[R%s2])-(L/s1*Len+v1[L%s1]);
		if (w[0]^(ans&1))
			p+=T;
		else
			p-=T;
		p/=2;
		p0=((p+x[0])%Len+Len)%Len;
	}
	int p=lower_bound(res,res+n,p0)-res;
	if (w[0]^(ans&1)){
		if (n>2&&res[(p+1)%n]==res[p])
			p++;
	}
	else
		if (n>2&&res[(p+n-1)%n]==res[p])
			p--;
	for (int i=0;i<n;i++)
		printf("%d\n",res[(p+i)%n]);
	return 0;
}

Measured memory_bytes: 2892
#include <stdio.h>

int linearSearch(int*, int, int);

int main()
{
  int n, q, S[10000+1], T, C=0;
  int i;

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

  scanf("%d",&q);
  for(i=0;i<q;i++){
    scanf("%d",&T);
    if( linearSearch(S, n ,T) ) C++;
  }

  printf("%d\n",C);
  return 0;
}

int linearSearch(int S[], int n, int T)
{
  int i=0;
  S[n]=T;
  while(S[i] != T) i++;
  return i != n;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


#define NUM 100

struct Point{
	Point(double arg_x,double arg_y){
		x = arg_x;
		y = arg_y;
	}

	Point(){
		x = y = 0.0;
	}

	Point operator + (Point p){ return Point(x+p.x,y+p.y); }
	Point operator - (Point p){ return Point(x-p.x,y-p.y);}
	Point operator * (double a){ return Point(a*x,a*y); }
	Point operator / (double a){ return Point(x/a,y/a); }

	double abs(){ return sqrt(norm()); }
	double norm(){ return x*x + y*y; }

	bool operator<(const Point &p) const{
		return x != p.x? x < p.x: y < p.y;
	}

	bool operator == (const Point &p) const{
		return fabs(x-p.x) < EPS && fabs(y-p.y) < EPS;
	}

	double x,y;
};

int N;
Point point[NUM],current;
double speed[NUM];
const double R = 0.98;

double calc_dist(Point a,Point b){
	return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}

void func(){

	for(int i = 0; i < N; i++){
		scanf("%lf %lf %lf",&point[i].x,&point[i].y,&speed[i]);
	}

	current.x = 0;
	current.y = 0;

	int max_index;
	double max_time,tmp_time;

	for(double value = 10; value > EPS; value *= R){

		max_time = 0;

		for(int i = 0; i < N; i++){

			tmp_time = calc_dist(current,point[i])/speed[i];

			if(max_time < tmp_time){
				max_time = tmp_time;
				max_index = i;
			}
		}

		current = current+((point[max_index]-current)/calc_dist(point[max_index],current)*value);
	}

	double ans = 0;
	for(int i = 0; i < N; i++){
		ans = max(ans,calc_dist(current,point[i])/speed[i]);
	}

	printf("%.10lf\n",ans);
}

int main(){

	while(true){
		scanf("%d",&N);
		if(N == 0)break;

		func();
	}
	return 0;
}



Measured memory_bytes: 3156
function main(input) {
  	const total = parseInt(input.split('\n')[0], 10)
	let a = 1
    let num = 0
	
	while(a < total) {
		let b = 1
		while(a * b < total) {
		    num++
		    b++
	  	}
		a++
	}

	console.log(num)
}

main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 32140
def binarySearch(A, key):
    left = 0
    right = len(A)
    while left < right:
        mid = (left + right) // 2
        if A[mid] == key:
            return mid
        elif key < A[mid]:
            right = mid
        else:
            left = mid + 1
    return -1

if __name__=='__main__':
    n=int(input())
    S=list(map(int,input().split()))
    q=int(input())
    T=list(map(int,input().split()))
    cnt = 0
    print(sum(map(lambda t: binarySearch(S,t) >= 0, T)))

Measured memory_bytes: 18852
fn main() {
    let kx = read_vec::<i32>();
    let k = kx[0];
    let x = kx[1];
    let mi;
    let ma;
    if x - (k - 1) < -1000000 {
        mi = -1000000;
    } else {
        mi = x - (k - 1);
    }
    if x + (k - 1) > 1000000 {
        ma = 1000000;
    } else {
        ma = x + (k - 1);
    }

    for i in mi..ma+1 {
        print!("{} ", i);
    }
    println!("");
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().split_whitespace().map(|e| e.parse().ok().unwrap()).collect()
}


Measured memory_bytes: 4352
/*BISMILLAH
THE WHITE WOLF
NO DREAM IS TOO BIG AND NO DREAMER IS TOO SMALL*/

#include<bits/stdc++.h>
using namespace std;

#define io ios_base::sync_with_stdio(false)
#define ll long long
#define ull unsigned long long
#define vi vector<int>
#define vll vector<long long>
#define pb push_back
#define mod  10000007
#define pii pair<int, int>
#define PI 2*acos(0.0)
#define forn(i, n) for(int i = 0; i < n; i++)


int main()
{
    io;
    string s, w;
    cin>>s>>w;
    int sl = s.size(), wl = w.size();
    int dp[sl+1][wl+1];
    for(int i = 0; i<= sl; i++) dp[i][0] = 0;
    for(int j = 0; j<= wl; j++) dp[0][j] = 0;
    for(int i = 1; i<= sl; i++)
    {
        for(int j = 1; j<= wl; j++)
        {
            if(s[i-1] == w[j-1])
                dp[i][j] = 1 + dp[i-1][j-1];
            else
                dp[i][j] = max(dp[i-1][j] , dp[i][j-1]);
        }
    }
    string com = "";
    int i = sl-1, j = wl -1;
    while(i >= 0 && j >= 0)
    {
        if(s[i] == w[j])
        {
            com += s[i];
            i--;
            j--;
        }
        else if(dp[i][j+1] > dp[i+1][j])
            i--;
        else
            j--;
    }
    reverse(com.begin(), com.end());
    cout<<com;
    return 0;
}


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

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

  long long h; cin >> h;
  if(h < 2){
    cout << 1 << '\n';
    return 0;
  }
  long long cnt = 0;
  long long ans = 2;
  while(h != 1){
    h /= 2;
    if(cnt == 0){
      cnt = 2;
      continue;
    }
    cnt = cnt * 2;
    ans += cnt;
  }

  cout << ans+1 << endl;
  
  return 0;
}


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

int main() {
  while (1) {
    // m 中間
    // f 期末
    // r 再試験
    int m, f, r;
    cin >> m >> f >> r;

    if (m == -1 && f == -1 && r == -1) { break; }

    // 中間、期末のいずれかを欠席
    if (m == -1 || f == -1) {
      cout << "F" << endl;
    } else {
      int sum = 0;
      sum += (m >= 0 ? m : 0);
      sum += (f >= 0 ? f : 0);

      if (sum >= 80) {
        cout << "A" << endl;
      } else if (sum >= 65) {
        cout << "B" << endl;
      } else if (sum >= 50) {
        cout << "C" << endl;
      } else if (sum >= 30) {
        cout << (r >= 50 ? "C" : "D") << endl;
      } else {
        cout << "F" << endl;
      }
    }
  }
  return 0;
}



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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  int t=1;
 // cin >> t;
   while (t--) {
    int n;
    cin>>n;
    if(n>=30)
    cout<<"Yes"<<endl;
    else
    cout<<"No"<<endl;
   }
    
  return 0;
}

Measured memory_bytes: 3592
M,K=map(int,input().split())
if (1<<M)<=K or (K==1 and M==1):
  print(-1)
  exit()
if M==1:
  print('0 0 1 1')
  exit()
X=[]
for i in range(1<<M):
  if i!=K:
    X.append(i)
X.append(K)
for i in range((1<<M)-1,-1,-1):
  if i!=K:
    X.append(i)
X.append(K)
print(*X)

Measured memory_bytes: 101244
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
struct pac{
  int t;
  int o;
  int m;
  bool operator<(const pac& right)const{
    return t==right.t ? o<right.o:t < right.t ;
  }
};
int main(){
  while(1){
    int n,x;
    cin >> n >> x;
    if(n==0&&x==0)break;
    vector<pac> p(x);
    vector<int> v(n+1,0);
    int c=1;
    v[1]=1;
    for(int i=0;i<x;i++){
      cin >> p[i].t >> p[i].o >> p[i].m;
    }
    sort(p.begin(),p.end());
    for(int i=0;i<x;i++){
      if(v[p[i].o]==1){if(v[p[i].m]==0)c++;v[p[i].m]=1;
	}
    }
    cout << c<< endl; 
  }
  return 0;

}

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

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rept(i,n) for(int (i)=0;(i)<=(int)(n);(i)++)
#define reps(i,s,n) for(int (i)=(s);(i)<(int)(n);(i)++)
#define repst(i,s,n) for(int (i)=(s);(i)<=(int)(n);(i)++)
#define repr(i,n) for(int (i)=(n);(i)>=0;(i)--)
#define each(itr,v) for(auto (itr):(v))
#define all(c) c.begin(),c.end()
#define pb push_back
#define fi first
#define se second
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define ln << "\n"
#define show(x) cout << #x << " = " << x ln
#define dbg(x) cout<<#x"="<<x ln

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

const int inf = (int)1e9;
const ll linf = (ll)1e18;
const int mod = (int)(1e9+7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};

// ⊂ニニニニニニニニニニニニニ( ^ω^)ニニニニニニニニニニニニニ⊃

int main() {
	cin.tie(0);
	ios::sync_with_stdio(0);
	
	int n, c;
	cin >> n >> c;
	int imo[c][200010]={{}};
	rep(i,n) {
		int s, t, ch;
		cin >> s >> t >> ch;
		imo[ch-1][s*2-1]++, imo[ch-1][t*2]--;
	}
	
	int ans = 0;
	rep(i,200005) {
		int cnt = 0;
		rep(j,c) {
			imo[j][i+1] += imo[j][i];
			if (imo[j][i]>0) cnt++;
		}
		chmax(ans, cnt);
	}
	cout << ans ln;
}

Measured memory_bytes: 23680