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

public class Main {
    static Scanner sc = new Scanner(System.in);
    public static void main(String[] args) {
        int n = Integer.parseInt(sc.next());
        Map<String, Integer> counts = new HashMap<>();
        int maxCount = 0;
        for(int i = 0; i < n; ++i) {
            String k = sc.next();
            int t = counts.getOrDefault(k, 0);
            counts.put(k, t + 1);
            maxCount = Math.max(maxCount, t + 1);
        }
        
        List<String> sl = new ArrayList<>();
        for(Map.Entry<String, Integer> entry : counts.entrySet()) {
            if(entry.getValue() == maxCount) {
                sl.add(entry.getKey());
            }
        }
        
        Collections.sort(sl);
        for(String s : sl) {
            System.out.println(s);
        }
    }
}


Measured memory_bytes: 82320
#include<stdio.h>

int main(void){
  int N,i,j,k;
  int num[101]={0};

  scanf("%d",&N);
  for(i=0;i<N;i++){
    scanf("%d",&k);
    num[k]++;
  }

  for(i=0;num[i]==0;i++);
  if(num[i]>2){
    puts("Impossible");
    return 0;
  }

  k=i;

  for(i++;num[i]!=0;i++){
    if(num[i]==1){
      puts("Impossible");
      return 0;
    }
  }

  for(j=i+1;j<N;j++){
    if(num[j]!=0){
      puts("Impossible");
      return 0;
    }
  }

  if(i-1>k*2-(num[k]-1)){
    puts("Impossible");
  }else{
    puts("Possible");
  }
  return 0;
}


Measured memory_bytes: 128
from  collections import Counter
N = int(input())
D = list(map(int,input().split()))
M = int(input())
T = list(map(int,input().split()))

D.sort()
#T.sort()
TC = Counter(D)
D =T
#print(TC)
index_a =0
flag=True
for d in D:
    if TC[d]>0:
        TC[d]-=1
    else:
        print("NO")
        exit(0)


if flag:
    print("YES")
else:
    print("NO")

Measured memory_bytes: 41700
#include <bits/stdc++.h>
using namespace std;
#define pi acos(-1.0)
#define pb push_back
#define mp make_pair
#define ll long long
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define testcase ll T; cin >> T; for (ll tc = 1; tc <= T; tc++)
#define M 1000000007
#define MM 998244353
#define eps 1e-8
#define eq(x,y) (fabs((x)-(y)) < eps)
#define r2 1.41421356237
ll powmod(ll a,ll b,ll mod) {ll res=1;a%=mod;assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}

int pp=0,ans=0;
bool vis[200005]={};
vector<int>v[200005];

void dfs(int p) {
	vis[p]=1;
	ans++;
	for(auto x:v[p]) { if(!vis[x]) { dfs(x); } }
}

int main()
{
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  //testcase {
  int n,m;
  cin>>n>>m;
  while(m--) {
  	int a,b;
  	cin>>a>>b;
  	a--; b--;
  	v[a].pb(b);
  	v[b].pb(a);
  }
  for(int i=0;i<n;i++) {
  	ans=0;
  	if(!vis[i]) { dfs(i); pp=max(pp,ans); }
  }
  cout<<pp;
  //}  
  return 0;
}

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

using ll = long long;
using VI = vector<ll>;
using VVI = vector<VI>;
using P = pair<ll, ll>;

int main() {
  ll n, a;
  ll tmp = 1;
  double tmp2 = 1;

  cin >> n;

  for (int i = 0; i < n; i++) {
    cin >> a;
    tmp *= a;
    tmp2 = tmp2 * (double)a;
  }

  if (tmp2 > 1e18L || tmp > (ll)1e18L)
    cout << -1 << endl;
  else
    cout << tmp << endl;

  return 0;
}


Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
 
#define int             long long
#define ld              long double
#define fi              first
#define se              second
#define pb              push_back
#define mp              make_pair
#define mt              make_tuple
#define fo(i,n)         for(i=0; i<n; i++)
#define fo1(i,n)        for(i=1; i<=n; i++)
#define Fo(i,k,n)       for(i=k; k<=n?i<=n:i>=n; k<=n?i++:i--)
#define all(x)          x.begin(), x.end()
#define rall(x)         x.rbegin(), x.rend()
#define sortall(x)      sort(all(x))
#define sortrall(x)     sort(rall(x))
#define clr(x)          memset(x, 0, sizeof(x))
#define tr(it, a)       for(auto it = a.begin(); it != a.end(); it++)
#define pii             pair<int, int>
#define mk(arr,n,type)  type *arr = new type[n];
#define vi              vector<int>
#define si              set<int>
#define usi             unordered_set<int>
#define mii             map<int, int>
#define umii            unordered_map<int, int>
#define pqmx            priority_queue<int>
#define pqmn            priority_queue<int, vi, greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define trailzrobits(x) __builtin_ctzll(x)
#define leadzrobits(x)  __builtin_clzll(x)
#define paritybits(x)   __builtin_parityll(x)
#define gcd             __gcd
#define lcm(x, y)       (x * y) / gcd(x, y)
#define mod             1000000007
#define endl            '\n'
#define PI              3.1415926535897932384626
#define inf             1e18
#define sp(x,y)         fixed<<setprecision(y)<<x
void __print(int32_t x) {cout<<x;}
void __print(int x) {cout<<x;}
void __print(ld x) {cout<<x;}
void __print(double x){cout<<x;}
void __print(float x){cout<<x;}
void __print(bool x) {cout<<(x?"true":"false");}
void __print(char x){cout <<'\''<<x<<'\'';}
void __print(const char *x){cout <<'\"' <<x<<'\"';}
void __print(const string &x) {cout<<'\"'<<x<<'\"';}
template<typename T,typename V>     void __print(const pair<T,V> &x) {cout<<'{';__print(x.first);cout<<',';__print(x.second);cout<<'}';}
template<typename T>                void __print(const T &x) {int f = 0; cout << '{'; for (auto &i: x) cout << (f++ ? "," : ""), __print(i); cout << "}";}void _print() {cout << "]\n";}
template <typename T,typename... V> void _print(T t, V... v) {__print(t);if(sizeof...(v))cout<<", ";_print(v...);}
#ifndef ONLINE_JUDGE
#define dbg(x...) cout<<"["<<#x<<"]=[";_print(x)
#else 
#define dbg(x...)
#endif
int power(int base, int exp){ int res = 1; base %= mod; while(exp > 0){ if(exp & 1) res = (res * base) % mod; base = (base * base) % mod; exp = exp >> 1; } return res; }
int inv(int x){ return power(x, mod - 2) % mod; }
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++




const int N = 1e6 + 6, M = N;
int i, j;

void solve(){
    
    int a; ld b; cin>>a>>b;
    int c=b;
    int d=a*c;
    ld e=b-c;
    ld f=a*e;
    int g=d+f;
    cout<<g<<endl;
    
    
    
    
}




int32_t main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    
    int t = 1;
    // cin >> t;
    while(t--)
        solve();
    return 0;
}

Measured memory_bytes: 3736
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
inline ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
inline ll lcm(ll a, ll b) { return a / gcd(a, b)*b; }
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T>& V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> >& Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T>& mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }
template<typename T>vector<T> make_v(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>auto make_v(size_t a,Ts... ts){return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type fill_v(T &t,const V &v){t=v;}
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type fill_v(T &t,const V &v){for(auto &e:t) fill_v(e,v);}
/*
 <url:>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */

// nの約数を列挙する
vector<ll> getdivisor(ll n){
    vector<ll> res;
    for(ll i = 1; i*i <= n;i++){
        if(n%i == 0) {
            res.push_back(i);
            if(n/i != i) res.push_back(n/i);
        }
    }
    sort(res.begin(),res.end());
    return res;
}
template<class Type>
Type solve(Type res = Type()){
    res = 1;
    
    int N; ll K; cin >> N >> K;
    vector<ll> A(N); for(auto& in:A) cin >> in;
    sort(A.begin(),A.end());
    auto divisors = getdivisor(accumulate(A.begin(),A.end(),0LL));
    
    vector<ll> cusum1(N+1),cusum2(N+1);
    for(auto d:divisors){
        auto B = A;
        for(auto& v:B) v%=d;
        
        sort(B.begin(),B.end());
        
        for(int i = 0 ; i < N;i++){
            cusum1[i+1] = cusum1[i] + B[i];
        }
        for(int i = N-1; i >= 0; i--){
            cusum2[i] = cusum2[i+1] + (d-B[i]);
        }
        
        for(int i = 0; i <= N;i++){
            if(max(cusum1[i],cusum2[i]) > K) continue;
            ll diff = abs(cusum1[i] - cusum2[i]);
            if(diff%d == 0){
                res = d;
                break;
            }
        }
    }

    return res;
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    // solve(0);
    cout << fixed << setprecision(15) << solve<ll>() << endl;
    return 0;
}


Measured memory_bytes: 256
/**
 * Dont raise your voice, improve your argument.
 * --Desmond Tutu
 */

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

#define DEBUG
#ifndef DEBUG
#define endl "\n"
#define log(args...)
#else
#define log(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); logf(_it, args); }
void logf(istream_iterator<string> it) {
}
template<typename T, typename ... Args>
void logf(istream_iterator<string> it, T a, Args ... args) {
	cout << *it << " = " << a << endl;
	logf(++it, args...);
}
#endif

#define forn(i,k,n) for(ll i=(k); i<(n); i++)

const double PI = acos(-1);
typedef long long ll;
#define fori(n) for(ll i=0; i<(n); i++)

#define cins(s) string s; cin>>s;
#define cini(i) int i; cin>>i;
#define cinll(l) ll l; cin>>l;
#define cind(d) double d; cin>>d;
#define cinai(a, n) vi a(n); fori(n) { cin>>a[i]; }
#define cinall(a, n) vll a(n); fori(n) { cin>>a[i]; }
#define cinas(s, n) vs s(n); fori(n) { cin>>s[i]; }
#define cinad(a, n) vd a(n); fori(n) { cin>>a[i]; }

typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef vector<double> vd;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<string> vs;
typedef vector<ll> vll;

void solve() {
	cini(a);
	cini(b);
	string sa(b, (char) '0' + a);
	string sb(a, (char) '0' + b);

	if (a < b)
		cout << sa << endl;
	else
		cout << sb << endl;
}

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



Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>

using namespace std;
struct Node
{
    int r,s;
}a[100005];
bool cmp(Node x,Node y)
{
    return (x.s<y.s)||(x.s==y.s&&x.r<y.r);
}

int main()
{
    int n,m;
    int ans=0,q=0;
    scanf("%d %d",&n,&m);
    for(int i=1;i<=m;i++)
    {
        scanf("%d %d",&a[i].r,&a[i].s);
    }
    sort(a+1,a+1+m,cmp);
    for(int i=1;i<=m;i++)
    {
        if(a[i].r<q&&a[i].s>=q)
            continue;
        else
        {
            q=a[i].s;
            ans++;
        }
    }
    printf("%d",ans);
    return 0;
}

Measured memory_bytes: 1024
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class Main {
	public static void main(String[] args){
		FastScanner sc = new FastScanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int sum = 0;
		int count = 0;
		for (int i=1;i<n+1;i++) {
			sum += sc.nextInt();
			if (sum > m) {
				count = i;
				break;
			}

		}

		if (count == 0) {
			System.out.println(n + 1);
		} else {
			System.out.println(count);
		}


	}

}

class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;

    public FastScanner(InputStream in) {
        reader = new BufferedReader(new InputStreamReader(in));
        tokenizer = null;
    }

    public String next() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

    public String nextLine() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                return reader.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }

        return tokenizer.nextToken("\n");
    }

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

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

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

    public int[] nextIntArray(int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++)
            a[i] = nextInt();
        return a;
    }

    public long[] nextLongArray(int n) {
        long[] a = new long[n];
        for (int i = 0; i < n; i++)
            a[i] = nextLong();
        return a;
    }
}

Measured memory_bytes: 21204
/*
for (int i = 0; i < N; ++i){}

// 各桁の和を計算する関数
int findSumOfDigits(int n) {
  int sum = 0;
  while (n > 0) { // n が 0 になるまで
    sum += n % 10;
    n /= 10;
  }
  return sum;
}

sort(a, a + N, greater<int>());  // a[0:N] を大きい順にソート

int num[110] = {0};  // バケット
for (int i = 0; i < N; ++i) {
    num[d[i]]++;  // d[i] が 1 個増える
}

map<string, int> mp; // 連想配列 map<キー型, 値型> オブジェクト名
for (int i = 0; i < N; ++i) {
    auto itr = mp.find(s[i]);        // s[i] が設定されているか？
    if(itr != mp.end() ) {
         mp[s[i]] += 1;
    }
    else {
         mp[s[i]] += 1 ;
    }
}
stack<int> s;	//intをデータとするスタックを用意
s.push(1);		//{} -> {1}
printf("%d\n", s.top());	// 3
s.pop();

queue<int> que;	//intをデータとするキューを用意
que.push(1);		//{} -> {1}
printf("%d\n", que.front());	// 1
que.pop();
*/
#include <iostream>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <bitset>

using namespace std;

// #define for(i,a,b) for (int i=(a);i<(b);++i)
typedef long long ll;
typedef pair<ll,ll> P;
#define REP(i,n) for(long long i = 0; i < (long long)(n); i++)
#define pb push_back // vectorに要素追加
#define INF (ll)1e18
// int 
// // 各桁の和を計算する関数
// int findSumOfDigits(int n) {
//   int amari = 0;
//   int keta = 0;
//   while (n > 0) { // n が 0 になるまで
//     amari += n % 2;
//     if (keta%2==0)
//     n /= 10;
//   }
//   return sum;
// }

float calc_abs(float x){
	if (x<0) return -x;
	else return x;
}

int main() {
	// 入力
	ll N;
	cin >> N;
	ll a[N];
	for (ll i = 0; i < N; ++i) cin >> a[i];
 
	// 解法
	float mean = 0;
	
	REP(i,N){
		mean += (float)a[i];
	}
	mean = mean /N;
	// cout << mean << endl;
	
	float a_abs[N];
	float min_abs = 100000000000;
	ll ans = INF;
	REP(i,N){
		a_abs[i] = calc_abs(a[i]-mean);
		// cout << a_abs[i] << endl;
		if (a_abs[i]<min_abs){
			min_abs = a_abs[i];
			ans = i;
		}
	}
	cout << ans;
}


Measured memory_bytes: 256
S = list(input())
L = len(S)

for i in range(0, 1 << L-1):
    f = S[0]
    ans = int(S[0])
    for j in range(L-1):
        if (i >> j) & 1:
            f += "+"
            f += S[j+1]
            ans += int(S[j+1])
        else:
            f += "-"
            f += S[j+1]
            ans -= int(S[j+1])
    if ans == 7:
        print(f, "=7", sep="")
        exit()

Measured memory_bytes: 3064
#include<iostream>
#include<vector>
using namespace std;
int main() {
	int point_number;
	cin >> point_number;
	vector<vector<int>>v(point_number);
	for (int i = 0;i < point_number;i++) {
		int point_name;
		cin >> point_name;
		v[i].push_back(point_name);
		int adj_point_number;
		cin >> adj_point_number;
		v[i].push_back(adj_point_number);
		for (int j = 0;j < adj_point_number;j++) {
			int adj_point_name;
			cin >> adj_point_name;
			v[i].push_back(adj_point_name);

		}

	}
	vector<vector<int>>ans(point_number, vector<int>(point_number));
	for (int i = 0;i < point_number;i++) {
		for (int j = 0;j < v[i][1];j++) {
			ans[v[i][0] - 1][v[i][j + 2] - 1] = 1;

		}


	}
	for (int i = 0;i < point_number;i++) {
		for (int j = 0;j < point_number;j++) {
			if (j == 0) {
				cout << ans[i][j];
			}
			else {
				cout << " " << ans[i][j] ;
			}
			
		}
		cout << endl;
	}
}

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

signed main()
{
  cout << fixed << setprecision(20);
  cin.tie(0);
  ios::sync_with_stdio(false);

  int a, b, h, m;
  cin >> a >> b >> h >> m;

  ld l = (6.0 * m);
  ld s = 30.0 * h + 0.5 * m;
  ld angle = min({abs(l - s), abs(s - l), (360 - l) + s, (360 - s) + l});
  ld rad = angle * M_PI / 180.0;

  cout << sqrt(a*a + b*b - 2*a*b*cos(rad)) << '\n';

  return (0);
}


Measured memory_bytes: 4104
import bisect

n = int(input())
arr = list(map(int,input().split()))

arr.sort()
ans = 0
for i in range(n):
    for j in range(i+1,n):
        a,b = arr[i],arr[j]

        cmin = abs(a-b)
        cmax = a+b

        l = bisect.bisect_left(arr,cmin+1,lo=j+1)
        r = bisect.bisect_right(arr,cmax-1,lo=j+1)
        # print(cmin,l,cmax,r)
        if r-l > 0:
            ans += r-l

print(ans)


Measured memory_bytes: 74860
n,k = map(int,input().split())
a = [int(input()) for s in range(n)]
pmax = sum(a)
pmin = pmax//k-1

def check(ptest):
    tk = 1
    p = 0
    global a,k,n
    i = 0
    while i < n:
        p += a[i]
        if p <= ptest:
            i += 1
        else:
            tk += 1
            p = 0
        if tk > k:
            return False
    return True

while (pmax-pmin) > 1:
    pmid = (pmax+pmin)//2
    if check(pmid):
        pmax = pmid
    else:
        pmin = pmid
print(pmax)




Measured memory_bytes: 9560
#include <iostream>
#include <queue>
#include <string>

using namespace std;

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

int main() {

  string s, t;
  cin >> s >> t;
  int n = s.size();
  rep(i, n) {
    s.push_back(s[0]);
    s.erase(s.begin());
    if (s == t) {
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
struct node{
  int key;
  struct node *parent;
  struct node *right;
  struct node *left;
};
typedef struct node *Node;
Node T;
#define NIL NULL;
void Insert(int);
void Preorder(Node);
void Inorder(Node);
int main()
{
  int n,i,key;
  char S[7];

  scanf("%d",&n);

  for(i=0;i<n;i++){
    scanf("%s",S);
    if(S[0]=='i'){
      scanf("%d",&key);
      Insert(key);
    }
    else{
      Inorder(T);
      printf("\n");
      Preorder(T);
      printf("\n");

    }
  }
  return 0;
}

void Insert(int key)
{
  Node y,x,z;
  y=NIL;
  x=T;
  z=malloc(sizeof(struct node));
  z->key=key;
  z->left=NIL;
  z->right=NIL;
  while(x!=NULL){
    y=x;
    if( z->key < x->key )x=x->left;
    else x=x->right;
  }
  z->parent=y;
  if(y==NULL){
    T=z;
  }
  else if(z->key<y->key){
      y->left=z;
  }
  else{
    y->right=z;
  }
}

void Preorder(Node T)
{
  printf(" %d",T->key);
  if(T->left!=NULL){
    Preorder(T->left);
  }
  if(T->right!=NULL){
    Preorder(T->right);
  }

}
void Inorder(Node T)
{
  if(T->left!=NULL && T->right!=NULL){
    Inorder(T->left);
    printf(" %d",T->key);
    Inorder(T->right);

  }
  if(T->left!=NULL && T->right==NULL){
   Inorder(T->left);
     printf(" %d",T->key);
  }

  if(T->right!=NULL && T->left==NULL){
  printf(" %d",T->key);
 Inorder(T->right);

  }
  if(T->left==NULL && T->right==NULL)printf(" %d",T->key);

}



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

int main() {
  int x, a, b;
  cin >> x >> a >> b;
  if (a>=b) {
    cout << "delicious";
  }
  else if (b <= a + x) {
    cout << "safe";
  }
  else {
    cout << "dangerous";
  }
  cout << endl;
}


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

namespace A
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());

            var output = 0;
            var maxCount = -1;
            foreach (var i in Enumerable.Range(1, N))
            {
                var ii = i;
                var count = 0;
                while (ii % 2 == 0)
                {
                    ii = ii / 2;
                    count++;
                }

                if (maxCount < count)
                {
                    maxCount = count;
                    output = i;
                }
            }

            Console.WriteLine(output);
        }
    }
}


Measured memory_bytes: 11220
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;

ll gcd(ll x, ll y) {
    if(y == 0) {
        return x;
    }
    return gcd(y, x%y);
}

ll lcm(ll x, ll y) {
    ll g = gcd(x, y);
    return x / g * y;
}

ll a, b, c, d;

ll f(ll n) {

    if(n == 0) {
        return 0;
    }

    ll x = n/c;
    ll y = n/d;
    ll z = n/lcm(c, d);

    return n - (x + y - z);
}

int main() {
    
    cin >> a >> b >> c >> d;

    cout << f(b) - f(a-1) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main( ) {
    //freopen("A.01.inp","r",stdin);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int a,b;
    char op;
    cin >> a >> op >> b;
    int g = a-b;
    int ret = a+b;
    if (op=='-') ret = a-b;
    cout << ret << endl;
    return 0;
}

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

for i in range(N):
  if A[i] % 2 == 0:
    if A[i] % 3 != 0 and A[i] % 5 != 0:
      print('DENIED')
      break
    elif i != N-1:
      continue
    else:
      print('APPROVED')
      break
  elif i != N-1:
    continue
  else:
    print('APPROVED')
    break

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

using namespace std;

const int backet = 333;

int N, Q;
vector< int > g[100000];
int in[100000], out[100000], ptr;

int sz[(100000 + backet - 1) / backet][10];
int convert[(100000 + backet - 1) / backet][10];
int data[100000];

void tour(int idx, int par = -1)
{
  in[idx] = ptr++;
  for(int &to : g[idx]) if(to != par) tour(to, idx);
  out[idx] = ptr;
}

void push(int k)
{
  for(int i = k * backet; i < min(N, (k + 1) * backet); i++) {
    data[i] = convert[k][data[i]];
  }
  for(int i = 0; i < 10; i++) {
    convert[k][i] = i;
    sz[k][i] = 0;
  }
  for(int i = k * backet; i < min(N, (k + 1) * backet); i++) {
    sz[k][data[i]]++;
  }
}

int main()
{
  cin >> N >> Q;
  for(int i = 1; i < N; i++) {
    int U, V;
    cin >> U >> V;
    g[U].push_back(V);
    g[V].push_back(U);
  }
  tour(0);

  int all = (N + backet - 1) / backet;
  for(int i = 0; i < all; i++) {
    sz[i][0] += min(N, (i + 1) * backet) - i * backet;
    for(int j = 0; j < 10; j++) convert[i][j] = j;
  }

  while(Q--) {
    int t, s, x, y;
    cin >> t >> s >> x >> y;

    int a = in[s], b = out[s];

    if(t == 1) {
      int sum = 0;
      for(int i = 0; i < all; i++) {
        int l = i * backet, r = min(N, (i + 1) * backet);
        if(a >= r || b <= l) continue;
        if(a <= l && r <= b) {
          for(int k = 0; k < 10; k++) {
            if(x <= convert[i][k] && convert[i][k] <= y) sum += sz[i][k];
          }
        } else {
          push(i);
          for(int j = max(a, l); j < min(b, r); j++) {
            if(x <= data[j] && data[j] <= y) sum++;
          }
        }
      }
      cout << sum << endl;
    } else {
      for(int i = 0; i < all; i++) {
        int l = i * backet, r = min(N, (i + 1) * backet);
        if(a >= r || b <= l) continue;
        if(a <= l && r <= b) {
          for(int k = 0; k < 10; k++) {
            if(convert[i][k] == x) convert[i][k] = y;
          }
        } else {
          push(i);
          for(int j = max(a, l); j < min(b, r); j++) {
            if(data[j] == x) {
              data[j] = y;
              --sz[i][x];
              ++sz[i][y];
            }
          }
        }
      }
    }
  }
}

Measured memory_bytes: 14072
#include<iostream>
#include<vector>
#include<string>
#include<bitset>

using namespace std;

int main() {
	int h, w, k;
	cin >> h >> w >> k;
	vector<vector<char>> data(h, vector<char>(w));
	for (int i = 0; i < h; i++) 
		for (int j = 0; j < w ; j++)
			cin >> data[i][j];

	int number_answer = 0;
	for (int i = 0; i < (1 << h + w); i++) {
		int number_black = 0;
		for (int x = 0; x < w; x++)
			for (int y = 0; y < h; y++)
				if ((((i >> x) & 1) == 0) && (((i >> (y + w)) & 1) == 0) && (data[y][x] == '#'))
					number_black++;
	//	cout << number_black <<" i="<<i<< endl; 確認用
		if (number_black == k)
			number_answer++;
	}
	cout << number_answer << endl;

	return 0;
}

Measured memory_bytes: 3568
#include <stdio.h>

int main(void)
{
	int x, i;

	for( i = 1;  ; i++){
		scanf("%d", &x);
		if (x == 0) {
			break;
		}
		printf("Case %d: %d\n", i, x);
			
	}
	
	
	return 0;
}


Measured memory_bytes: 2568
n,k = map(int, input().split())
l = [0] + list(map(int, input().split()))
a = list()
for i in range(n):
  l[i+1] += l[i]
a = [l[j]-l[i] for i in range(n) for j in range(i+1,n+1)]
x = 0
for i in range(40,-1,-1):
  t = 2**i 
  if sum(map(lambda y:((y&(t+x)) == t+x),a)) >= k:
    x += t
print(x)

Measured memory_bytes: 66940
N = int(input())
A = input().split()
A_i = [int(i) for i in A]

A_even = [i for i in A_i if i % 2 == 0]

flag = 0
for even in A_even:
  if even % 3 != 0 and even % 5 != 0:
    flag = 1

if flag == 1:
  print("DENIED")
else:
  print("APPROVED")


Measured memory_bytes: 3060
//Author: xiaowuga
#include <bits/stdc++.h>
using namespace std;
#define inf 0x3f3f3f3f
#define MAX INT_MAX
#define mem(s,ch) memset(s,ch,sizeof(s))
const long long N=100000; 
const long long mod=1e9+7; 
typedef long long LL;
typedef int II;
typedef unsigned long long ull;
#define nc cout<<"nc"<<endl
#define endl "\n"
int main() {
	ios::sync_with_stdio(false);cin.tie(0);
    int n,m;
    cin>>n>>m;
    char a[100][100];
    int b[100][100];
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            cin>>a[i][j]; 
        }
    }
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            int ct=0;
            if(a[i-1][j-1]=='#') ct++;
            if(a[i-1][j]=='#') ct++;
            if(a[i-1][j+1]=='#') ct++;
            if(a[i][j-1]=='#') ct++;
            if(a[i][j+1]=='#') ct++;
            if(a[i+1][j-1]=='#') ct++;
            if(a[i+1][j]=='#') ct++;
            if(a[i+1][j+1]=='#') ct++;
            b[i][j]=ct;
        } 
    }
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            if(a[i][j]=='#') cout<<"#";
            else cout<<b[i][j];
        }
        cout<<endl;
    }
	return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    string s,t;
    cin>>s;
    cin>>t;
    int count=INT_MAX;
    int m=s.length();
    int n=t.length();
    for(int i=0;i<=m-n;i++){
        int temp=0;
        int j=i;
        int k=0;
        while(k<n){
            if(s[j]!=t[k]){
                temp++;
            }
            j++;
            k++;
        }
        count=min(count,temp);
    }
    
    cout<<count<<endl;
    return 0;
    
}

Measured memory_bytes: 3620
#include <iostream>
using namespace std;
const int maxn = 1e5;
int h[maxn];
int dp[maxn];
int N, K;

int main(int argc, char const *argv[])
{
    cin >> N >> K;
    for(int i = 0 ; i<N ; i++){
        cin >> h[i];
    }
    dp[0] = 0;
    for(int i = 1 ; i<N ; i++){
        int minx = 0x3f3f3f3f;
        for(int j = 1 ; j<=K ; j++){
            if(i - j < 0) continue;
            minx = min(minx, dp[i - j] + abs(h[i-j] - h[i]));
        }
        dp[i] = minx;
    }
    cout << dp[N-1] << endl;
}

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

int main() {
  ll a, b, n; cin >> a >> b >> n;
  cout << a * min(n, b-1) / b << endl;
  return 0;
}

Measured memory_bytes: 3624
#include <cstdio>
#include <vector>
#include <stack>
#include <iostream>
#include <string>
#include <tuple>
#include <random>
#include <map>
#include <queue>
#include <set>
#include <complex>
#include <algorithm>
#include <cassert>
 
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;

int main(){
	ll N, K;
	cin >> N >> K;
	map<P, ll> mp;
	ll ans =0;
	ll zero = 0;
	for(int i=0;i<N;i++){
		ll A,B;
		cin >> A >> B;
		if(A==0)
			zero+=B;
		else{
			if(mp.find(P(A,B))==mp.end())
				mp[P(A,B)] = 1;
			else
				mp[P(A,B)]++;
		}
	}
	for(ll i=31; i>=0; i--){
		ll k=(ll)1<<i;
		if((K & k) != 0){
			ll sum = 0;
			for(auto ite = mp.begin(); ite!=mp.end(); ite++){
				if((k & ite->first.first) == 0)
					sum += ite->first.second * ite->second;
			}
			ans = max(ans, zero + sum);
		}else{
			for(auto ite = mp.begin(); ite!=mp.end(); ite++){
				if((k & ite->first.first) != 0)
					ite->second = 0;
			}
		}
	}
	ll sum = 0;
	for(auto ite = mp.begin(); ite!=mp.end(); ite++){
		sum += ite->first.second * ite->second;
	}
	cout << max(ans, zero+sum) << endl;
	return 0;
}

Measured memory_bytes: 7552
# 入力
N,Y = gets.chomp.split(" ").map(&:to_i)
# Y円になる組み合わせを考える
_10000yen = -1
_5000yen = -1
_1000yen = -1

for a in 0..N do
   for b in 0..N - a do
       c = N - (a + b)
       if (10000 * a + 5000 * b + 1000 * c == Y) && (a + b + c == N)
           _10000yen = a
           _5000yen = b
           _1000yen = c
       end
   end
end

puts "#{_10000yen} #{_5000yen} #{_1000yen}"

Measured memory_bytes: 1788
#include <iostream>
#include <string>

using namespace std;
     
int main()
{
  int A,B,T;
  
  cin >> A >> B >> T;

  int N =0;
  for( int t=1; t< T+0.5; t ++ ) {
    if( t % A == 0 ) {
      N += B;
    }
  }

  cout << N << endl;

  return 0;
}


Measured memory_bytes: 256
#include<algorithm>
#include<cassert>
#include<cmath>
#include<cstdio>
#include<iostream>
#include<map>
#include<numeric>
#include<stack>
#include<string>
#include<deque>
#include<queue>
#include<vector>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const ll INF = 1e18;
const ll mod = 1e9+7;
const double PI = acos(-1);  // PI = 3.141593...

int trucks(vector<int>& v, int p) {
    // pを載せられるトラックの台数
	int w = 0, k = 1;
	rep(i, v.size()){
		if (w + v[i] <= p){
			w += v[i];
		} else {
			w = v[i];
			++k;
		}
	}
	return k;
}
int main(){
	int n, k;
	cin >> n >> k;
	vector<int> w(n);
	int max = 0;
    int sum = 0;
	rep(i, n) {
		cin >> w[i];
		if (max < w[i]) {
			max = w[i];
		}
		sum += w[i];
	}

	while (max != sum){
		int mid = (max + sum) / 2;
		if (trucks(w, mid) > k){
            // 最大積載重量が低い
			max = mid + 1;
		} else {
            // 最大積載重量が高い
			sum = mid;
		}
	}
	cout << max << endl;
	return 0;
}



Measured memory_bytes: 3132
#include <bits/stdc++.h>
using namespace std;
#ifdef _IS_LOCAL //
#define dout cout
#define debug() if (true)
#define dvout(v) vout(v)
#else
#define dout   \
	if (false) \
	cout
#define debug() if (false)
#define dvout(v) if(false);
#endif //
#define next asdnext
#define prev asdprev
#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define vrep(i, v) for (auto &i : v)
#define all(x) (x).begin(), (x).end()
#define vout(v)           \
	for (auto &i : v)     \
	{                     \
		cout << i << " "; \
	}                     \
	cout << "\n"; //配列出力
#define vin(v)        \
	for (auto &i : v) \
		cin >> i; //配列入力
#define vecin(v,n)	\
	vec(v,n);		\
	vin(v);
#define vec(v, n) vector<int> v(n, 0);
#define mod (int)(1e9+7)
typedef long long ll;
typedef unsigned long long ull;



void Main()
{
	int N;
	cin>>N;
	vec(H,N);
	vin(H);

	vector<int> ans(0, 0);
	int cnt = 0;
	rep(i,N-1){
		if(H[i] >= H[i+1]){
			cnt++;
		}
		else{
			ans.push_back(cnt);
			cnt = 0;
		}
	}

	ans.push_back(cnt);

	sort(all(ans));
	cout<<ans[ans.size()-1]<<endl;
}

int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << std::fixed << std::setprecision(15);
	Main();
	return 0;
}

Measured memory_bytes: 1276
import java.io.PrintWriter;
import java.util.Scanner;

public class Main {
    static private Scanner scan = new Scanner(System.in);
    public static void main(String args[]) {
        int int1 = Integer.parseInt(scan.next());
        int int2 = Integer.parseInt(scan.next());
        int int3 = Integer.parseInt(scan.next());
//        String temp_str1 = "";
//        String temp_str2 = "";
        int temp_int1 = 0;
//        String str1 = scan.next();
//        String str2 = scan.next();
//        String str3 = scan.next();
        int ans_int = 0;
        String ans = "";
//        double ans_dob = 0;
        if((int1*100+int2*10+int3)%4 == 0){
            ans = "YES";
        }else{
            ans = "NO";
        }
        PrintWriter out = new PrintWriter(System.out);
        out.println(ans);
        out.flush();
        scan.close();
    }
}


Measured memory_bytes: 21844
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cmath>
#include <algorithm>
#include <utility>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const double EPS = 1e-9;


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

  int a,b,c,d;
  cin>>a>>b>>c>>d;
  if(abs(a - c) <= d || abs(a - b) <= d && abs(b - c) <= d) cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;
}


Measured memory_bytes: 256
import scala.io.StdIn.readLine
import scala.collection.mutable.HashMap

object Main extends App {
  val m = HashMap.empty[Int,Int]
  val m2 = HashMap.empty[Int,Int]
  Iterator.continually(readLine).takeWhile(_!="").foreach { s =>
    val n = s.split(",").map(_.toInt)
    if(m contains n(0)) m(n(0)) += 1 else m += (n(0) -> 1)
  }

  Iterator.continually(readLine).takeWhile(_!=null).foreach { s =>
    val n = s.split(",").map(_.toInt)
    if(m contains n(0)) {
      if(m2 contains n(0)) m2(n(0)) += 1 else m2 += (n(0) -> (m(n(0)) + 1))
    }
  }
  m2.toSeq.sorted.foreach { case (x,y) => println(x + " " + y) }
}

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

int main()
{
    int n,x,sum=0;
    cin>>n>>x;
    int a[n];
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }
    sort(a,a+n);
    int ans=0;
    for(int i=0;i<n;i++)
    {
        if(sum+a[i]<=x&&i<n-1)
            {
                ++ans;
                sum+=a[i];
            }
        else if(sum+a[i]<=x && i==n-1)
        {
            if(sum+a[i]==x)
                ++ans;
        }
        else
           break;

    }
    cout<<ans;
    return 0;
}



Measured memory_bytes: 3588
s=str(input())
if s=="SUN":
  print(7)
elif s=="MON":
  print(6)
elif s=="TUE":
  print(5)
elif s=="WED":
  print(4)
elif s=="THU":
  print(3)
elif s=="FRI":
  print(2)
elif s=="SAT":
  print(1)

Measured memory_bytes: 3060
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<map>
#include<queue>
#include<stack>
#include<list>
#include<set>
#include<cstring>
#include<string>
using namespace std;
int a[205];
int main(){
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	int n;
	scanf("%d",&n);
	for(int i=1;i<=2*n;i++){
		scanf("%d",&a[i]);
	}
	sort(a+1,a+1+2*n);
	int ans=0;
	for(int i=1;i<=2*n;i+=2){
		ans+=a[i];
	}
	printf("%d\n",ans);
	return 0;
}


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

 
int main() {
  int a,b,c,d,k,i,j,ans=0;
  cin >> a >> b >> c >> k;
  if(a<k){
    ans+=a;
    k-=a;
  }else{
    ans=k;
    k=0;
  }
  if(b<k){
    k-=b;
  }else{
    k=0;
  }
  ans-=k;
  cout << ans << endl;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ld long double
#define ll long long
#define P pair<int,int>
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<n;i++)
#define all(v) v.begin(),v.end()
#define pb push_back
#define eb emplace_back
template<class T>void chmax(T &a,T b){if(a<b)a=b;}
template<class T>void chmin(T &a,T b){if(a>b)a=b;}
constexpr int INF=1000000000000000000;
constexpr int mod=1000000007;
constexpr double eps=1e-8;
const double pi=acos(-1);
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
int Random(int mi,int ma){
    random_device rnd;
    mt19937 mt(rnd());//32bit
    //[mi,ma]
    uniform_int_distribution<int>engine(mi,ma);
    return engine(mt);
}
int gcd(int a,int b){
    if(b==0)return a;
    return gcd(b,a%b);
}
int lcm(int a,int b){
    return a/gcd(a,b)*b;
}
bool prime(int a){
    if(a==1)return false;
    for(int i=2;i*i<=a;i++){
        if(a%i==0)return false;
    }
    return true;
}
int modpow(int a,int b){
    if(b==0)return 1;
    if(b%2)return modpow(a,b-1)*a%mod;
    int memo=modpow(a,b/2);
    return memo*memo%mod;
}
vector<int>kaijo,invkaijo;
void init_fact(int n){
    kaijo.resize(n+1);
    invkaijo.resize(n+1);
    kaijo[0]=1;
    for(int i=1;i<=n;i++){
        kaijo[i]=kaijo[i-1]*i;
        kaijo[i]%=mod;
    }
    rep(i,n+1)invkaijo[i]=modpow(kaijo[i],mod-2);
}
int comb(int a,int b){
    if(a<b)return 0;
    if(a<0||b<0)return 0;
    return kaijo[a]*modpow(kaijo[a-b],mod-2)%mod*modpow(kaijo[b],mod-2)%mod;
}
int inv(int x){
    x=modpow(x,mod-2);
    return x;
}
struct BIT{
    int n,beki=1;
    vector<int>bit;
    BIT(int x){
        bit.resize(x+1,0);
        n=x;
        while(beki*2<=n)beki*=2;
    }
    int sum(int i){
        int res=0;
        while(i>0){
            res+=bit[i];
            i-=i&-i;
        }
        return res;
    }
    void add(int i,int x){
        while(i<=n){
            bit[i]+=x;
            i+=i&-i;
        }
    }
    int lowerbound(int w){
        if(w<=0)return 0;
        int x=0;
        for(int k=beki;k>0;k>>=1){
            if(x+k<=n&&bit[x+k]<w){
                w-=bit[x+k];
                x+=k;
            }
        }
        return x+1;
    }
};
void solve(){
    int n,m,cnt;
    cin>>n>>m;
    vector<P>v[100010];
    BIT bit(m);
    rep(i,n){
        int l,r;
        cin>>l>>r;
        v[r-l+1].pb({l,r});
    }
    cnt=n;
    for(int d=1;d<=m;d++){
        int ans=cnt;
        for(int i=d;i<=m;i+=d){
            ans+=bit.sum(i);
        }
        cout<<ans<<endl;
        for(P p:v[d]){
            bit.add(p.fi,1);
            bit.add(p.se+1,-1);
        }
        cnt-=v[d].size();
    }
}
signed main(){
    cin.tie(0);ios::sync_with_stdio(false);
    //int t;cin>>t;while(t--)
    solve();
    return 0;
}


Measured memory_bytes: 12180
#include<bits/stdc++.h>
using namespace std;
int n,s,a[3200];
long long dp[3200][3200],result,MOD=998244353;
int main(){
	ios::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>n>>s;
	for(int i=1;i<=n;i++)
		cin>>a[i];
	dp[0][0]=1;
	for(int i=1;i<=n;i++){
		for(int j=0;j<=s;j++) dp[i][j]=(dp[i-1][j]*2LL)%MOD;
		for(int j=s;j>=a[i];j--){
			dp[i][j]=(dp[i][j]+dp[i-1][j-a[i]])%MOD;
		}
	}
	cout<<dp[n][s]<<endl;
	return 0;
}


Measured memory_bytes: 78676
def main():
    S = list(input())
    for i in range(1, len(S)-1):
        sub_str = S[:len(S)-i]
        if len(sub_str) % 2 == 1:
            continue
        elif sub_str[:int(len(sub_str)/2)] == sub_str[int(len(sub_str)/2):]:
            print(len(sub_str))
            break

if __name__ == '__main__':
    main()


Measured memory_bytes: 38384
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <cmath>

constexpr double EPS = (1e-10);
constexpr double INF = 252521;
#define equals(a, b) (fabs(a - b) < EPS)

std::vector<int> par, rnk;

void init(int n)
{
    par.resize(n); rnk.resize(n);
    for (int i = 0; i < n; i++) {
        par[i] = i;
        rnk[i] = 0;
    }
}

int find(int x)
{
    if (par[x] == x) {
        return x;
    }
    return par[x] = find(par[x]);
}

void unite(int x, int y)
{
    x = find(x);
    y = find(y);

    if (x == y) return;

    if (rnk[x] < rnk[y]) {
        par[x] = y;
    } else {
        par[y] = x;
        if (rnk[x] == rnk[y]) {
            rnk[x]++;
        }
    }
}

bool same(int x, int y)
{
    return (find(x) == find(y));
}

struct Edge {
    int u, v;
    double w;

    Edge() {}
    Edge(int u, int v, double w) :
        u{u}, v{v}, w{w} {}
};

struct Data {
    int u, v;
    double c, t;

    Data() {}
    Data(int u, int v, double c, double t) :
        u{u}, v{v}, c{c}, t{t} {}
};

int N, M;
std::vector<Data> d;
std::vector<Edge> es;

double kruskal()
{
    sort(es.begin(), es.end(), [](const Edge& e1, const Edge& e2) {
            return e1.w > e2.w;
    });
    
    init(N); 
    double tw = 0;
    for (Edge& e : es) {
        if (!same(e.u, e.v)) {
            unite(e.u, e.v);                       
        } else {
            tw += e.w;
        }
    }    
    return tw;
}

bool c(double x)
{
    for (int i = 0; i < M; i++) {
        es[i].u = d[i].u;
        es[i].v = d[i].v;
        es[i].w = d[i].t - x * d[i].c;
    }
    return kruskal() >= 0;
}

double solve()
{
    double lb = 0, ub = INF;
    for (int i = 0; i < 50; i++) {
        double mid = (lb + ub) / 2;
        if (c(mid)) {
            lb = mid;
        } else {
            ub = mid;
        }
    }
    return ub;
}

int main()
{
    scanf("%d %d", &N, &M);
    d.resize(M); es.resize(M);
    
    for (int i = 0; i < M; i++) {
        scanf("%d %d %lf %lf", &d[i].u, &d[i].v, &d[i].c, &d[i].t);
    }
    
    auto res = solve();
    printf("%.15f\n", (equals(res, INF) ? 0 : res));
    return 0;
}

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

def solve():
    S = readline().rstrip()

    c= S.count('R')
    if c == 1:
        print(1)
    elif c == 0:
        print(0)
    elif c== 2:
        if S[1] == 'S':
            print(1)
        else:
            print(2)
    else:
        print(3)

solve()

Measured memory_bytes: 61712
#include <stdio.h>

void init( int point[101] )
{
        for ( int i = 0 ; i < 101 ; i++ ) {
                point[i] = 0;
        }
}

int isOdd( int point[101] )
{
        int odd = 0;
        for ( int i = 1 ; i < 101 ; i++ ) {
                if ( point[i] % 2 == 1 ) {
                        odd++;
                }
        }

        if ( odd == 2 && point[1]%2 ==1 && point[2]%2 == 1 ) {
                return 1;
        } else {
                return 0;
        }
}


int main()
{
        int point[101];
        int a, b;

        init( point );
        while ( scanf( "%d %d", &a, &b ) != EOF ) {
                if ( a == 0 && b == 0 ) {
                        if ( isOdd( point ) == 1 ) {
                                printf( "OK\n" );
                        } else {
                                printf( "NG\n" );
                        }

                        init( point );
                } else {
                        point[a]++;
                        point[b]++;
                }
        }

        return 0;
}



Measured memory_bytes: 2056
#include<bits/stdc++.h>
using namespace std;
int pw[(1<<16)+3];
void pre(){
	for(int i=0;i<16;i++) pw[1<<i]=i;
}
int pos(int val){
	val=val&(-val);
	if((val>>16)==0) return pw[val];
	else return 16+pw[val>>16];
}
int n,tot;
vector<int> v[35];
int main(){
	scanf("%d",&n);pre();
	for(int i=1,t;i<=n;i++){
		scanf("%d",&t);
		tot^=t;v[pos(t)].push_back(t);
	}
	int ans=0;
	for(int i=30;i>=0;i--){
		if((tot>>i)&1){
			if(v[i].size()==0) return puts("-1"),0;
			int t=v[i][0]-1;tot=tot^(t+1)^t;
			ans++;
		}
	}
	cout<<ans<<endl;
	return 0;
}

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

int pos = 0;
vector<int> ans;

void reconstruction(vector<int> &pre, vector<int> &in, int left, int right)
{
    // cout << "left = " << left << ", right = " << right << endl;
    if (left >= right)
    {
        return;
    }

    int next_root = pre[pos++];
    auto ite = find(in.begin(), in.end(), next_root);
    if (ite == in.end())
    {
        return;
    }
    int next_root_idx = ite - in.begin();

    reconstruction(pre, in, left, next_root_idx);
    reconstruction(pre, in, next_root_idx + 1, right);

    // cout << next_root << endl;
    ans.push_back(next_root);
}

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

    vector<int> pre_order(n);
    vector<int> in_order(n);
    for (int i = 0; i < n; i++)
    {
        cin >> pre_order[i];
    }
    for (int i = 0; i < n; i++)
    {
        cin >> in_order[i];
    }

    reconstruction(pre_order, in_order, 0, n);

    for (int i = 0; i < n; i++)
    {
        cout << ans[i];
        if (i < n - 1)
        {
            cout << " ";
        }
    }
    cout << endl;

    return 0;
}


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

int main() {
  std::ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int N,X;
  cin>>N>>X;
  int m[N];
  int total=X;
  int ans=N;
  for (int i=0; i<N; i++) {
    cin>>m[i];
    total-=m[i];
  }
  sort(m,m+N);
  while (total>=m[0]) {
    total-=m[0];
    ans++;
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define MAX 100000
vector<int> G[MAX];
int id[MAX],pa[MAX],dp[MAX],used[MAX];
void dfs(int v,int d){
  dp[v]=d;
  for(int i=0;i<(int)G[v].size();i++){
    dfs(G[v][i],d+1);
    pa[G[v][i]]=v;
  }
}
signed main(){
  int n;
  cin>>n;
  for(int i=0,k;i<n;i++){
    cin>>id[i]>>k;
    G[id[i]].resize(k);
    for(int j=0;j<k;j++){
      cin>>G[id[i]][j];
      used[G[id[i]][j]]=1;
    }
  }
  memset(pa,-1,sizeof(pa));
  for(int i=0;i<n;i++){
    if(!used[i]) dfs(i,0);
  }
  for(int i=0;i<n;i++){
    cout<<"node "<<i<<": parent = "<<pa[i]<<", depth = "<<dp[i];
    if(pa[i]<0) cout<<", root, [";
    else if(!G[i].size()) cout<<", leaf, [";
    else cout<<", internal node, [";
    for(int j=0;j<(int)G[i].size();j++){
      if(j) cout<<", ";
      cout<<G[i][j];
    }
    cout<<"]"<<endl;
  }
  return 0;
}

Measured memory_bytes: 9472
#include<stdio.h>
int main()
{
	int A[10000], B[500], n, q, count = 0;
	scanf("%d", &n);
	for(int i = 0; i < n; i++) 
		scanf("%d", &A[i]);
	scanf("%d", &q);
	for(int i = 0; i < q; i++)
		scanf("%d", &B[i]);
	for(int i = 0; i < q; i++)
	{
		for(int j = 0; j < n; j++)
		{
			if(A[j] == B[i])
			{
				count++;
				break;
			}
				
		}
	}
	printf("%d\n", count);
		return 0;
}



Measured memory_bytes: 2764
#define M 100
char m[M][M],s[M][M][M],r[M],*z;
cmp(char *p,char *q){
	for(;*p=='0';p++);for(;*q=='0';q++);
	return (z=strlen(p)-strlen(q))?z:strcmp(p,q);
}
main(w,h,i,j,k,l){
	for(;scanf("%d%d",&w,&h),w;puts(z)){
		for(memset(s,0,sizeof(s)),memset(r,0,sizeof(r)),j=1;j<=h;j++)scanf("%s",m[j]+1);
		for(i=1;i<=w;i++)for(j=1;j<=h;j++){
			if(!isdigit(m[j][i]))continue;
			if(cmp(s[j][i-1],s[j-1][i])>0)strcpy(s[j][i],s[j][i-1]),s[j][i][strlen(s[j][i])]=m[j][i];
			else strcpy(s[j][i],s[j-1][i]),s[j][i][strlen(s[j][i])]=m[j][i];
			if(cmp(s[j][i],r)>0)strcpy(r,s[j][i]);
		}
		for(z=r;*z=='0';z++);
	}
return 0;}

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

uint32_t div_ceil(uint32_t a, uint32_t b) {
  return (a % b == 0) ? a / b : a / b + 1;
}

int main() {
  uint32_t T_HP = 0, T_ATT = 0, A_HP = 0, A_ATT = 0;
  std::cin >> T_HP >> T_ATT >> A_HP >> A_ATT;

  std::cout << (div_ceil(T_HP, A_ATT) >= div_ceil(A_HP, T_ATT) ? "Yes" : "No")
            << std::endl;

  return 0;
}

Measured memory_bytes: 3596
N,M = map(int,input().split())
SC = []
for _ in range(M):
    SC.append([int(i) for i in input().split()])
for n in range(1000):
    if len(str(n)) != N:
        continue
    else:
        flg = True
        for sc in SC:
            if str(n)[sc[0]-1] == str(sc[1]):
                pass
            else:
                flg = False
                break
        if flg:
            break
        else:
            continue
print(n) if flg else print(-1)

Measured memory_bytes: 38384