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

public class Main {

	public double search(int[] r){
		sort(r, true);
		double sum1 = 0;
		for(int i = 0; i < r.length; i++){
			sum1 += dist(r[i], r[(i+1)%r.length]);
		}
		double min = 1000000000;
		for(int i = 0; i < r.length; i++){
			min = Math.min(min, sum1 - dist(r[i], r[(i+1)%r.length]) + r[i] + r[(i+1)%r.length]);
		}
		sort(r, false);
		double sum2 = r[0] + r[r.length-1];
		for(int i = 0; i < r.length-1; i++){
			sum2 += dist(r[i], r[i+1]);
		}
		for(int i = 0; i < r.length; i++){
			min = Math.min(min, sum1 - dist(r[i], r[(i+1)%r.length]) + r[i] + r[(i+1)%r.length]);
		}
		return Math.min(sum1, sum2);
	}
	public void sort(int[] r, boolean start){
		boolean flag = start;
		for(int i = 0; i < r.length; i++){
			int key = i;
			for(int j = i; j < r.length; j++){
				if( flag ){
					if( r[j] > r[key] ){
						key = j;
					}
				} else {
					if( r[j] < r[key] ){
						key = j;
					}
				}
			}
			int temp = r[key];
			r[key] = r[i];
			r[i] = temp;
			flag = (flag) ? false : true;
		}
	}
	public double dist(int x, int y){
		return 2*Math.sqrt(x*y);
	}
	public void solve() throws IOException{
		while( stdIn.hasNext() ){
			String[] s = stdIn.nextLine().split(" ");
			int m = Integer.parseInt(s[0]);
			int[] r = new int[s.length-1];
			for(int i = 0; i < r.length; i++){
				r[i] = Integer.parseInt(s[i+1]);
			}
			double sum = search(r);
		//	System.out.println(sum);
			if( sum > m ){
				System.out.println("NA");
			} else {
				System.out.println("OK");
			}
		}
	}			
	public static void main (String args[]) throws IOException{
		new Main().run();
	}
	
	Scanner stdIn;
	PrintWriter writer;
	
	public void run() throws IOException{
		stdIn = null;
		try{
			stdIn = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
			writer = new PrintWriter(System.out);
			solve();
			stdIn.close();
			writer.close();
		} catch (Exception e){
			e.printStackTrace();
			System.exit(1);
		}
	}	
}

Measured memory_bytes: 11000
#include<stdio.h>
int main(void)
{
	int a[7],b[7],i;
	for(i=0;i<7;i++){
		a[i]=0;
		b[i]=0;
		scanf("%d %d",&a[i],&b[i]);
		printf("%d\n",a[i]-b[i]);
	}
	return 0;
}

Measured memory_bytes: 600
program ABC168_A
  read(*,*)N
  M=mod(N,10)
  if(M==3)  write(*,*)'bon'
  if(M==0 .or. M==1 .or. M==6 .or. M==8) write(*,*)'pon'
  if(M==2 .or. M==4 .or. M==5 .or. M==7 .or. M==9) write(*,*)'hon'
end program ABC168_A


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

using namespace std;

void failed() {
  cout << "NA" << endl;
}
 
int main() {
   
  int Q1, B, C1, C2, Q2;
   
  while(cin >> Q1 >> B >> C1 >> C2 >> Q2) {
    if(Q1 == 0) break;
    int AizuCh = min(B/C1, Q2);
    int NCh = 0;
    for(;;) {
      if(AizuCh <= 0) { failed(); break; }
      NCh = (B - AizuCh*C1)/C2;
      if(AizuCh + NCh >= Q1) {
        cout << AizuCh << ' ' << NCh << endl; break;
      }
      else AizuCh --;
    }
  }
   
  return 0;
}

Measured memory_bytes: 1160
fun main(args: Array<String>) {
    val (n, m) = readLine()!!.split(" ").map(String::toInt)
    var s = "0".repeat(n).toCharArray()

    val list = mutableListOf<Pair<Int, Int>>()
    repeat(m) {
        val (si, ci) = readLine()!!.split(" ").map(String::toInt)
        list.add(si to ci)
    }

    for (i in 0..999) {
        val num = i.toString()
        if (num.length != n) {
            continue
        }

        var flg = true
        for ((s, c) in list) {
            if (num[s - 1] != c.toString()[0]) {
                flg = false
            }
        }
        if (flg) {
            println(i)
            return
        }
    }
    println("-1")
}





Measured memory_bytes: 38024
import numpy as np
def main():
    printl = lambda l: [print(x) for x in l]
    H, W = list(map(int, input().split()))
    A = np.array([[1 if i == '.' else 0 for i in input()] for _ in range(H)])
    L = np.zeros((H, W), dtype = np.int)
    R = np.zeros((H, W), dtype = np.int)
    U = np.zeros((H, W), dtype = np.int)
    D = np.zeros((H, W), dtype = np.int)
    L[:, 0] = A[:, 0]
    for w in range(1, W):
        L[:, w] = (L[:, w - 1] + 1) * A[:, w]
    R[:, W - 1] = A[:, W - 1]
    for w in range(W - 2, -1, -1):
        R[:, w] = (R[:, w + 1] + 1) * A[:, w]
    U[0, :] = A[0, :]
    for h in range(1, H):
        U[h, :] = (U[h - 1, :] + 1) * A[h, :]
    D[H - 1, :] = A[H - 1, :]
    for h in range(H - 2, -1, -1):
        D[h, :] = (D[h + 1, :] + 1) * A[h, :]
    print(np.max(L + R + U + D - 3))

if __name__ == '__main__':
    main()


Measured memory_bytes: 253824
def resolve():
    N,K = map(int,input().split())
    A = list(map(int,input().split()))
    F= list(map(int,input().split()))

    A.sort()
    F.sort(reverse = True)
    AF  = list(zip(A,F))

    if sum(A)<=K:
        print(0)
        return
    l = 0
    r = max([i*j for i,j in AF])
    center =0
    while l < r-1:

        center = (l+r)//2
        score =sum([max(0,a-center//f) for a,f in AF])
        
        if score > K:
            l = center
        else:
            r = center

    print(r)





if __name__ == "__main__":
    resolve()

Measured memory_bytes: 139740
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <functional>
#include <ctime>
#include <cmath>
#include <limits>
#include <numeric>
#include <type_traits>
#include <iomanip>
#include <float.h>
#include <math.h>
using namespace std;
using ll = long long;
unsigned euclidean_gcd(unsigned a, unsigned b) {
    if (a < b) return euclidean_gcd(b, a);
    unsigned r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}

ll ll_gcd(ll a, ll b) {
    if (a < b) return ll_gcd(b, a);
    ll r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}

class UnionFind {
public:
    vector <ll> par;
    vector <ll> siz;
    UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL) {
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
    void init(ll sz_) {
        par.resize(sz_);
        siz.assign(sz_, 1LL);
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
    ll root(ll x) {
        while (par[x] != x) {
            x = par[x] = par[par[x]];
        }
        return x;
    }
    bool merge(ll x, ll y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        if (siz[x] < siz[y]) swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

    bool issame(ll x, ll y) {
        return root(x) == root(y);
    }

    ll size(ll x) {
        return siz[root(x)];
    }
};

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

long long modinv(long long a, long long mod) {
    return modpow(a, mod - 2, mod);
}

int main() {
    ll x,y,z,kk;
    cin >> x >> y >> z >> kk;
    vector<ll> xx(x);
    vector<ll> yy(y);
    vector<ll> zz(z);
    for (int i = 0; i < x; i++) {
       cin >> xx[i];
    }
    for (int i = 0; i < y; i++) {
       cin >> yy[i];
    }
    for (int i = 0; i < z; i++) {
       cin >> zz[i];
    }
    sort(xx.begin(), xx.end());
    reverse(xx.begin(), xx.end());
    sort(yy.begin(), yy.end());
    reverse(yy.begin(), yy.end());
    sort(zz.begin(), zz.end());
    reverse(zz.begin(), zz.end());
    vector<ll> ans(1000000);
    ll now = 0;
    for (int i = 0; i < x; i++) {
        for (int j = 0; j < y; j++) {
            for (int k = 0; k < z; k++) {
                if ((i+1) * (j+1) * (k+1) > kk)break;
                ans[now] = xx[i] + yy[j] + zz[k];
                now++;
            }
        }
    }
    sort(ans.begin(), ans.end());
    reverse(ans.begin(), ans.end());
    for (int i = 0; i < kk; i++) {
        cout << ans[i] << endl;
    }
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(a) (a).begin(), (a).end()
#define INF (int)1e8
#define EPS 1e-9

using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;

int main() {
  int K, S;
  cin >> K >> S;

  int res = 0;
  rep(i, K + 1) rep(j, K + 1) {
    int z = S - i - j;
    if (0 <= z && z <= K) res++;
  }

  cout << res << endl;
}

Measured memory_bytes: 384
base_list = list()
i = 0
while i < 3000:
    input_a = input("")
    term = input_a.split(' ')
    a = int(term[0])
    b = int(term[1])
    if(a == 0 and b == 0):
        break
    else:
        subset_list = [a, b]
        subset_list.sort()
        base_list.append(subset_list)

    i += 1

for bl in base_list:
    print("{} {}".format(bl[0], bl[1]))



Measured memory_bytes: 6024
n,k=map(int,input().strip().split())
s=input().strip()
l=r=0
c=0
while r<n and s[r]=='1': r+=1
while c<k:
 while r<n and s[r]=='0':r+=1
 while r<n and s[r]=='1':r+=1
 if r==n:print(n);exit()
 c+=1
ans=r-l
while r<n:
 while l<n and s[l]=='1':l+=1
 while l<n and s[l]=='0':l+=1 
 while r<n and s[r]=='0':r+=1
 while r<n and s[r]=='1':r+=1
 ans=max(ans,r-l)
print(ans)

 



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

int main() {
  int x, y;
  cin >> x >> y;

  vector<int> A={1,3,5,7,8,10,12};
  vector<int> B={4,6,9,11};
  
  if(x==2 || y==2){
    cout << "No" <<endl;
    return 0;
  }

  if(find(A.begin(), A.end(), x)==find(A.begin(), A.end(), y)){
    cout << "Yes" << endl;
  }
  else if(find(B.begin(), B.end(), x)==find(B.begin(), B.end(), y)){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
return 0;  
}

Measured memory_bytes: 256
using namespace std;
#include<iostream>
#include<bits/stdc++.h>
#include<algorithm>
#define w(x) int x;cin>>x;while(x--)

#define FIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)

#define ll long long

void abc()
{
	FIO;
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}

int mod = 1000000007;
vector<vector<ll>> dp;
vector<int> v;
vector<int> w;


ll go( int i, int sum) {



	if (i == v.size() ) return 0;
	if (dp[i][sum] != -1) return dp[i][sum];

	ll x = 0;

	if (sum - w[i] >= 0) {
		x = max(x, v[i] + go(i + 1, sum - w[i]));
	}
	x = max(x, go(i + 1, sum));


	return dp[i][sum] = x;


}



int main()
{
	abc();


	int n, s;
	cin >> n >> s ;
	v.resize(n);
	w.resize(n);

	dp.resize(n, vector<ll>(s + 1, -1));

	for (int i = 0; i < n; i++) cin >> w[i] >> v[i];

	cout << go(0, s) << endl;


}

Measured memory_bytes: 82272
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <cmath>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <iostream>
#include <climits>
#include <cfloat>


using namespace std;


int main()
{
	double a;
	while (scanf("%lf\n", &a) != EOF)
	{
		double arr[10];
		arr[0] = a;
		for (int i = 1; i < 10; ++i)
			arr[i] = (i&1) ? arr[i-1] * 2 : arr[i-1] / 3;
		double s = 0;
		for (int i = 0; i < 10; ++i)
			s += arr[i];
		printf("%.8f\n", s);
	}

	return 0;
}

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

int main(){
    long long N, ans=0, l=1e9, r=-1e9, sum;
    cin >> N;
    vector<int> a(N);
    for(int i=0; i<N; i++){
	cin >> a[i];
	a[i] -= (i+1);
    }
    sort(a.begin(), a.end());
    long long mid = N%2==0 ? (a[N/2-1]+a[N/2])/2: a[N/2];
    
    for(int i=0; i<N; i++){
	ans += abs(a[i]-mid);
    }

    cout << ans << endl;
    
}



Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {
	static int N;
	static int X;
	static int T;
	public static void main(String args[]) {
		try(Scanner sc = new Scanner(System.in)){
			N = Integer.parseInt(sc.next());
			X = Integer.parseInt(sc.next());
			T = Integer.parseInt(sc.next());
		}
		int count=0;
		for(int i=0;N>X*i;i++) {
			count++;
		}
		if(count==0) {
			System.out.println(1);
		}else {			
			System.out.println(count*T);
		}
	}
}

Measured memory_bytes: 35572
//pragma
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>

#define YOU using
#define DONT namespace
#define SAY std

YOU DONT SAY;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ll,int> pli;
typedef pair<int,ll> pil;
typedef vector<int> vi;
typedef vector<pii> vii;
typedef vector<pll> vll;

#define REPP(i,a,b,d) for(int i=a;i<=b;i+=d)
#define REP(i,a,b) REPP(i,a,b,1)
#define REVV(i,a,b,d) for(int i=a;i>=b;i-=d)
#define REV(i,a,b) REVV(i,a,b,1)

#define FOR(i,a) for(int i=0; i<a; i++)
#define FORD(i,a) for(int i=(int)a-1; i>=0; i--)

#define pb push_back
#define F first
#define S second

const int OO = 1e9;
const ll INF = 1e18;

const int irand(int lo,int hi){
	return ((double)rand()/(RAND_MAX + 1.0)) * (hi-lo+1) + lo;
}

const ll lrand(ll lo,ll hi){
	return ((double)rand()/(RAND_MAX + 1.0)) * (hi-lo+1) + lo;
}

#define getc getchar
template<typename T>
T getnum(){
	int sign = 1;
	T ret = 0;
	char c;

	do{
		c = getc();
	}while(c == ' ' || c == '\n');
	if(c == '-')sign = -1;
	else ret = c-'0';
	while(1){
		c = getc();
		if(c < '0' || c > '9')break;
		ret = 10*ret + c-'0';
	}
	return sign * ret;
}

inline void ini(int& x){
	x = getnum<int>();
}

inline void scani(int& x){
	scanf("%d",&x);
}

//end of macro

int n;
map<int,int>mep;
    
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    #define endl '\n'
    cout.setf(ios::fixed);
    cout.setf(ios::showpoint);
    cout.precision(10);
    
    cin>>n;
    REP(i,1,n){
    	int x;
    	cin>>x;
    	mep[x]++;
    	mep[x+1]++;
    	mep[x-1]++;
	}
	
	int best = 0;
	for(auto x : mep){
		best = max(best, x.S);
	}
	cout << best << endl;
    
    return 0;
}

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

#define rep(i,a,n) for(int i=a;i<n;i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

// Debug Vector
template <typename T>
std::ostream &operator<<(std::ostream &out, const std::vector<T> &v){
    if(!v.empty()) {
        out << '[';
        std::copy(v.begin(), v.end(), std::ostream_iterator<T>(out, ", "));
        out << "\b\b]";
    }
    return out;
}

template <typename T1, typename T2>
std::ostream &operator<<(std::ostream &out, const std::pair<T1, T2> &p) {
    out << "[" << p.first << ", " << p.second << "]";
    return out;
}
//---------


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
////    CLion Standard Input for DEBUG
////    --------------------------------------------------------------------------
//    ifstream in("./in.txt");
//    cin.rdbuf(in.rdbuf());
////    --------------------------------------------------------------------------

    int n;
    cin >> n;
    vector<int> as(n);
    for(auto &a : as) cin >> --a;

    int now = 0;
    int cnt = 0;

    while(1){
        if(now == 1){
            break;
        }
        if(cnt >= n){
            cnt = -1;
            break;
        }
        cnt++;
        now = as[now] - 1;
    }

    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define sqr(x) ((x)*(x))
#define mp make_pair
#define uint unsigned
#define PI pair<int,int>
inline char gc(){
    static char buf[100000],*p1=buf,*p2=buf;
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
#define gc getchar
inline int read(){
	int x = 0; char ch = gc(); bool positive = 1;
	for (; !isdigit(ch); ch = gc())	if (ch == '-')	positive = 0;
	for (; isdigit(ch); ch = gc())	x = x * 10 + ch - '0';
	return positive ? x : -x;
}
inline void write(int a){
    if(a<0){
    	a=-a; putchar('-');
	}
    if(a>=10)write(a/10);
    putchar('0'+a%10);
}
inline void writeln(int a){
    if(a<0){
    	a=-a; putchar('-');
	}
	write(a); puts("");
}
inline int rnd(int x){
	return rand()%x;
}
inline ull rnd(){
	return ((ull)rand()<<30^rand())<<4|rand()%4;
}
const int M=205,N=5005;
int n,m,g[M][N],a[M][N];
ll de[N],sum[N],ans;
inline int ggg(int id,int pos,int x){
	if(a[id][pos]>x)return pos;
	return ggg(id,g[id][pos],x);
}
int main(){
	n=read(); m=read();
	for(int i=2;i<=n;i++)sum[i]=sum[i-1]+read();
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++)a[j][i]=read(); 
	}
	for(int i=1;i<=m;i++){
		a[i][0]=a[i][n+1]=2e9; 
		for(int j=n;j;j--)g[i][j]=ggg(i,j+1,a[i][j]);
	}
	for(int i=n;i;i--){
		for(int j=1;j<=m;j++){
			de[i+1]-=a[j][i+1];
			for(int k=i+1;a[j][k]<=a[j][i];k=g[j][k]){
				de[g[j][k]]-=a[j][g[j][k]]-a[j][k]; 
			}
			de[i]+=a[j][i]; de[g[j][i]]+=a[j][g[j][i]]-a[j][i];
		}
		ll dq=0;
		for(int j=i;j<=n;j++){
			dq+=de[j];
			ans=max(ans,dq-(sum[j]-sum[i]));
			//cout<<i<<" "<<j<<" "<<dq<<endl;
		}
	}
	cout<<ans<<endl;
}

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

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

Node treeMinimum(Node x)
{
    while (x->left != NIL) x = x->left;
    return x;
}

Node treeMaximum(Node x)
{
    while (x->right != NIL) x = x->right;
    return x;
}

Node treeSearch(Node x, int k)
{
    if (x == NIL || k == x->key) return x;
    if (k < x->key) return treeSearch(x->left, k);
    else return treeSearch(x->right, k);
}

Node treeSuccessor(Node x)
{
    if (x->right != NIL) return treeMinimum(x->right);
    Node y = x->parent;
    while (y != NIL && x == y->right)
    {
        x = y;
        y = y->parent;
    }
    return y;
}

//void treeDelete(Node z){
//  Node y; // node to be deleted
//  Node x; // child of y
//
//
//
//}

void insert(int k){
    Node y = NIL;
    Node x = root;
    Node z;

    z = malloc(sizeof(struct node));
    z->key = k;
    z->left = NIL;
    z->right = NIL;
  
    while (x != NIL)
    {
        y = x;
        if (z->key < x->key) x = x->left;
        else x = x->right;
    }
    
    z->parent = y;
    
    if (y == NIL) root = z;
    else if (z->key < y->key) y->left = z;
    else y->right = z;
}

void inorder(Node u)
{
    if (u != NIL)
    {
        inorder(u->left);
        printf(" %d", u->key);
        inorder(u->right);
    }
}
void preorder(Node u)
{
    if (u != NIL) 
    {
        printf(" %d", u->key);
        preorder(u->left);
        preorder(u->right);
    }
}


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");}
//    } else if ( com[0] == 'd' ){
//      scanf("%d", &x);
//      treeDelete(treeSearch(root, x));
//    }
  }

  return EXIT_SUCCESS;
}


Measured memory_bytes: 25140
#include <iostream>
#include <vector>

using namespace std;

int main(void)
{
    vector<int> v;
    int n;

    cin >> n; v.push_back(n);
    cin >> n; v.push_back(n);
    cin >> n; v.push_back(n);

    sort(v.begin(), v.end());

    cout << v[2] * 10 + v[1] + v[0] << endl;

    return 0;
}


Measured memory_bytes: 256
from collections import Counter
n = int(input())
ans = []
cnt = 0
for i in range(n):
    s = input()
    l = list(s)
    l.sort()
    ans.append("".join(l))
c = Counter(ans)


for i in c.values():
    cnt += i*(i-1)//2

print(cnt)

Measured memory_bytes: 19824
#include <stdio.h>

int main(void)
{
    int N;

    scanf("%d",&N);

    if(N%10 == 7){
        printf("Yes\n");
    } else {
        N/=10;
        if(N%10 == 7){
            printf("Yes\n");
        } else {
            N/=10;
            if(N == 7){
                printf("Yes\n");
            } else {
                printf("No\n");
            }
        }
    } 

    return 0;
}

Measured memory_bytes: 1664
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
using namespace std;

int w, h, n;

int x, y, a;

int area[101][101];
int leftx, lefty, rightx, righty;

int main() {
    ios_base::sync_with_stdio(false);
    
    cin >> w >> h >> n;
    
    rightx = w;
    righty = h;
    
    for (int i = 0; i < n; i++) {
        cin >> x >> y >> a;
    
        if (a == 1) {
            //left paint
            if (leftx < x)
                leftx = x;
        } else if (a == 2) {
            //right paint
            if (x <= rightx)
                rightx = x;
            
        } else if (a == 3) {
            if (lefty < y)
                lefty = y;
            
        } else {
            if (y <= righty)
                righty = y;
        }
    
    }
    //cout << leftx << ":" << lefty << endl;
    //cout << rightx << ":" << righty << endl;
    int ans = 0;
    if (((righty - lefty) > 0) and ((rightx -leftx) > 0))
        ans = (righty - lefty) * (rightx - leftx);
    
    if (ans <= 0)
        cout <<  0 << endl;
    else
        cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<algorithm>
#include<iostream>
#include<queue>
#include<map>
#include<cmath>
#include<set>
#include<stack>
#define ll long long
#define pb push_back
#define max(x,y) ((x)>(y)?(x):(y))
#define min(x,y) ((x)>(y)?(y):(x))
#define cls(name,x) memset(name,x,sizeof(name))
using namespace std;
const int inf=1e9+10;
const int maxn=1e6+10;
const int maxm=20;
const int mod=1e9+7;
const double pi=acos(-1.0);
int n;
int num[maxn];
int main()
{
    //freopen("in.txt","r",stdin);
    while(~scanf("%d",&n))
    {
        int minnum=inf,maxnum=0;
        for(int i=0;i<n;i++)
        {
            scanf("%d",&num[i]);
            minnum=min(minnum,num[i]);
            maxnum=max(maxnum,num[i]);
        }
        if(!(minnum+1==maxnum||minnum==maxnum))
        {
            printf("No\n");
            continue;
        }
        int color=maxnum;
        int maxc=0;
        for(int i=0;i<n;i++)
        {
            if(maxnum-1==num[i])
                color--;
            else maxc++;
        }
        if(minnum+1==maxnum)
        {
            if(maxc>=color*2&&color>=1)
                printf("Yes\n");
            else printf("No\n");
        }
        else
        {
            if(maxc>=color*2||maxc==color+1)
                printf("Yes\n");
            else printf("No\n");
        }
    }
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define maxn 200001
#define maxa 1000005
#define MOD 1000000007
#define INF 1000000000000000000

using namespace std;

#define ll long long
#define pii pair<ll, ll>
#define piii pair<pii, ll>
#define ft first
#define sd second

void fast(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
}

ll power(ll a, ll b = MOD-2){
    if(b == 0) return 1;
    ll r = power(a, b/2);
    r = (r*r)%MOD;
    if(b%2 == 1) r = (r*a)%MOD;
    return r;
}

vector<ll> vec[55];
ll par[55], dep[55], X[21], Y[21], lca[21], n, m, dp[1<<21];

void  dfs(ll u, ll p){
    par[u] = p;
    dep[u] = dep[p]+1;
    for(auto x: vec[u]){
        if(p != x){
            dfs(x, u);
        }
    }
}

void solve(){

    cin >> n;

    for(ll i = 0; i < n-1; i++){
        ll x, y; cin >> x >> y;
        vec[x].push_back(y);
        vec[y].push_back(x);
        //mp[{x, y}] = mp[{y, x}] = 1;
    }
    dfs(1, 1);

    cin >> m;
    for(ll i = 0; i < m; i++){
        cin >> X[i] >> Y[i];
        ll x = X[i], y = Y[i];
        if(dep[x] > dep[y]) swap(x, y);
        while(dep[y] != dep[x]){
             y = par[y]; //mp[{y, par[y]}] = 1;
        }
        if(y != x){
            while(x!=y){
                y = par[y]; x = par[x]; //mp[{y, par[y]}] = 1; mp[{x, par[x]}] = 1;
            }
        }
        lca[i] = x;
    }
    ll ans = (1ll<<(n-1));
    for(ll i = 1; i < (1ll<<m); i++){
        ll c = 0, f = 0;
        ll vis[n+1];
        memset(vis, 0, sizeof(vis));
        for(ll j = 0; j < m; j++){
            if(i&(1ll<<j)){
                f++;
                ll x = X[j], y = Y[j], l = lca[j];
                while(x != l){
                    if(!vis[x]){c++; vis[x] = 1;}x = par[x];
                }
                while(y != l){
                    if(!vis[y]){c++; vis[y] = 1;}y = par[y];

                }
            }
        } //cout << (1<<(n-1-c)) << "  " << c << endl;
        if(f%2 == 0) ans += (1ll<<(n-1-c));
        else ans -= (1ll<<(n-1-c));
    }
    cout << ans;
}

int main()
{
    fast();
    ll t = 1;
    //cin >> t;
    while(t--){
        solve();
    }
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringBuilder sb = new StringBuilder();

		int N = Integer.parseInt(br.readLine());
		for (int i = 0; i < N; i++) {
			int x, y, b, p;
			int regular, discount;
			StringTokenizer st = new StringTokenizer(br.readLine());
			x = Integer.parseInt(st.nextToken());
			y = Integer.parseInt(st.nextToken());
			b = Integer.parseInt(st.nextToken());
			p = Integer.parseInt(st.nextToken());
			regular = x * b + y * p;
			discount = (x * (b > 5 ? b : 5) + y * (p > 2 ? p : 2)) * 4 / 5;
			sb.append(regular < discount ? regular : discount).append('\n');
		}
		System.out.print(sb.toString());
	}
}

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

int main() {
  long n, a, b;
  cin >> n >> a >> b;
  if ((b - a) % 2 == 1) {
    cout << min(n - b, a - 1) + (b - a) / 2 + 1 << endl;
  } else {
    cout << (b - a) / 2 << endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
const long long INF = 9999999999999999;
using ll = long long;
int main(){
  ll X;
  cin>>X;
  ll ans = 0;
  ll p = 100;
  while(1){
    p *= 1.01;
    ans++;
    if(p>= X){
      break;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3636
#include<iostream>
#include<string>
using namespace std;
#define rep(i, n) for ( int i = 0; i < (int)n; i++ )
#define MAX 250

bool compute(string str1, string str2){
  bool V1[MAX][MAX], V2[MAX][MAX];
  int ldy1, ldx1, rty1, rtx1;
  int dy[6] = {1, 1, 0, -1, -1, 0};
  int dx[6] = {0, -1, -1, 0, 1, 1};
  if ( str1.size() != str2.size() ) return false;
  int n = (int)str1.size()*2+2;
  rep(y, n) rep(x, n) V1[y][x] = false;

  int py = n/2;
  int px = n/2;
  V1[py][px] = true;
  ldy1 = rty1 = py;
  ldx1 = rtx1 = px;
  rep(i, str1.size()){
    int r = (str1[i]-'a')%6;
    py += dy[r];
    px += dx[r];
    V1[py][px] = true;
    ldy1 = min(ldy1, py);
    ldx1 = min(ldx1, px);
    rty1 = max(rty1, py);
    rtx1 = max(rtx1, px);
  }

  rep(d, 6){
    int ldy2, ldx2, rty2, rtx2;
    py = n/2;
    px = n/2;
    ldy2 = rty2 = py;
    ldx2 = rtx2 = px;
    rep(y, n) rep(x, n) V2[y][x] = false;
    V2[py][px] = true;
    rep(i, str2.size()){
      int r = (str2[i]-'a'+d)%6;
      py += dy[r];
      px += dx[r];
      V2[py][px] = true;
      ldy2 = min(ldy2, py);
      ldx2 = min(ldx2, px);
      rty2 = max(rty2, py);
      rtx2 = max(rtx2, px);
    }
    if ( !(rty1-ldy1 == rty2-ldy2 && rtx1-ldx1 == rtx2-ldx2 ) ) continue;
    int h = rty1-ldy1+1;
    int w = rtx1-ldx1+1;
    bool same = true;
    rep(y, h) rep(x, w){
      if ( V1[y+ldy1][x+ldx1] != V2[y+ldy2][x+ldx2] ) {same = false; break;}
    }
    if ( same ) return true;
  }
  return false;
}

main(){
  int tcase; cin >> tcase;
  string str1, str2, kasu;
  getline(cin, kasu);
  rep(t, tcase) {
    getline(cin, str1);
    getline(cin, str2);
    if (compute(str1, str2) ) cout << "true" << endl;
    else cout << "false" << endl;
    getline(cin, kasu);
  }
}

Measured memory_bytes: 1028
#include <bits/stdc++.h>  
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#define forn(i,a,b)        for( i = a ; i < b  ; i++ )
#define debug(x)           cout << #x << " " << x << " -- "
#define I__O               ios::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define ll                 long long  
#define p(x)               cout << x << "\n" ; 
#define MOD                100000007
#define pi                 pair<int,int>
#define vi                 vector <int>
#define pb                 push_back
#define vp                 vector <pair<ll,ll>>
#define endl               cout << "\n"
#define mi                 map <int,int> 
#define f1                 first 
#define s1                 second    
#define in                 insert
#define all(x)             (x).begin(),(x).end() 
/* 
  date | time : 3/22/2020 9:57:02 AM 
*/    
using namespace std ; 
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set ; 
const int N = 2e5+7;
bool ok(string S){
	// cout << S << ' ' ; 
	int N = S.size();
	int i = 0 ; 
	while( i < N/2){
		if(S[i] != S[N-i-1])
			return false ;
		i++;  
	}
	return true ; 		 
}  
int tests(){
	double d ;  
	cin >> d ; 
	d /= 3.00 ; 
	d = d*d*d ;
	printf("%0.15f\n",d) ;  
	return 0; 
} 
int main(){
    I__O ;          
    int cases = 1 ; 
    // cin >> cases ; 
    for(int i = 1 ; i <= cases ; i++ ){
      // cout << "Case #" << i << ": " ;  	
      tests(); 
    }
    return 0 ; 
}


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

namespace Abc138
{
    public class QuestionC
    {
        public static void Main(string[] args)
        {
            // 整数の入力
            int n = int.Parse(Console.ReadLine());

            // スペース区切りの整数の入力
            string[] input = Console.ReadLine().Split(' ');
            var hs = input.Select(i => long.Parse(i));

            int result = 0;
            int currentCount = 0;
            long currentH = 0;
            foreach(var h in hs)
            {
                if(currentH < h)
                {
                    currentCount = 0;
                }
                else
                {
                    currentCount++;
                    if(currentCount > result)
                    {
                        result = currentCount;
                    }
                }
                currentH = h;
            }

            Console.WriteLine(result);
        }
    }
}


Measured memory_bytes: 28892
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;

typedef long long ll;
typedef map<ll, ll> M;
typedef pair<ll, ll> P;

#define REP(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define SIZE(x) ((ll)(x).size())

int main() {
  ll x;
  cin >> x;
  if (x == 0) cout << 1 << endl;
  else cout << 0 << endl;
  return 0;
}


Measured memory_bytes: 3644
#include<stdio.h>

int parent(int i){
  return i/2;
}

int left(int i){
  return 2*i;
}

int right(int i){
  return 2*i+1;
}

int main(){
  
  int i, h, a[250+1];
  scanf("%d", &h);
  for(i=1; i<=h; i++) scanf("%d", &a[i]);
  for(i=1; i<=h; i++){
    printf("node %d: key = %d, ", i, a[i]);
    if(parent(i) >= 1) printf("parent key = %d, ", a[parent(i)]);
    if(left(i) <= h) printf("left key = %d, ", a[left(i)]);
    if(right(i) <= h) printf("right key = %d, ", a[right(i)]);
    printf("\n");
  }
  return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
#define rep(i,n) for (int (i) = 0; (i) < (n); (i)++)
using namespace std;
typedef long long ll;
// Welcome to my source code!

int main() {
    int n, q, time; cin >> n >> q;
    string name;
    queue<pair<string, int>> que;

    rep(i,n) {
        cin >> name >> time;
        que.push(make_pair(name, time));
    }

    pair<string, int> t;
    int x, elaps = 0;

    while (!que.empty()) {
        t = que.front(); que.pop();
        x = min(t.second, q);
        t.second -= x;
        elaps += x;
        if (t.second > 0) {
            que.push(t);
        } else {
            cout << t.first << ' ' << elaps << endl;
        }
    }
}


Measured memory_bytes: 6284
import java.util.Scanner

fun main(args: Array<String>){
    val scanner = Scanner(System.`in`)
    val sa = scanner.next()
    val sb = scanner.next()
    val sc = scanner.next()
    val a = Integer.parseInt(sa)
    val b = Integer.parseInt(sb)
    val c = Integer.parseInt(sc)
    val d = b + c
    if (a >= d){
        println(0)
    } else {
        println(d - a)
    }
}

Measured memory_bytes: 31392
#include <iostream>
#include <cstring>
#include <map>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <set>
#include <vector>
#include <queue>
#include <list>
#include <numeric>

using namespace std;
typedef long long ll;

/*迷路
const int INF = 50;

typedef pair<int,int> P;
char field[52][52];
int d[51][51];
int r,c;
int sx,sy;
int gx,gy;

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

int bfs(){
    queue<P> que;
    for(int i=0;i<r;i++){
        for(int j=0;j<c;j++){
            d[i+1][j+1] = INF;
        }
    }
    que.push(P(sy,sx));
    d[sy][sx]=0;
while(que.size()){
    P p=que.front();
    que.pop();
    if(p.second==gx&&p.first==gy) break;
    for(int i=0;i<4;i++){
        int nx=p.second+dx[i];
        int ny=p.first+dy[i];

        if(1<=nx&&nx<=c&&1<=ny&&ny<=r&&field[ny][nx]!='#'&&d[ny][nx]==INF){
            que.push(P(ny,nx));
            d[ny][nx] = d[p.first][p.second] + 1;
        }
    }
}
return d[gy][gx];
}
*/
int main(){
  int n,k;
  cin>>n>>k;
  int h[n];
  for(int i = 0; i<n;i++){
    cin>>h[i];
  }
  ll min = 1000000000;
  sort(h,h+n);

  for(int i = 0; i<=n-k;i++){
    if(h[i+k-1]-h[i]<min){
      min = h[i+k-1]-h[i];
    }
  }
  cout<<min<<endl;
  return 0;
}


Measured memory_bytes: 640
using System;
using System.Linq;
class S
{
static void Main()
{
int []a=Console.ReadLine().Split().Select(int.Parse).ToArray();
Array.Sort(a);
if(a[0]==5&&a[1]==5&&a[2]==7){
Console.WriteLine("YES");}
else{Console.WriteLine("NO");}
}
}

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

long long int n,r[4010],g[4010],b[4010],i,ans,j;
string s;

signed main()
{
    ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	cin>>n>>s;
	r[0]=0;b[0]=0;g[0]=0;
	for (i=1;i<n+1;i++)
	{
		r[i]=r[i-1];
		g[i]=g[i-1];
		b[i]=b[i-1];
		if (s[i-1]=='R') r[i]++;
		if (s[i-1]=='G') g[i]++;
		if (s[i-1]=='B') b[i]++;
	}
	ans=0;
	for (i=2;i<n;i++) for (j=i+1;j<n+1;j++) if (s[i-1]!=s[j-1])
	{
		if ((s[i-1]=='R' && s[j-1]=='G') || (s[i-1]=='G' && s[j-1]=='R'))
		{
			ans=ans+b[i-1];
			if (2*i-j>0) if (s[2*i-j-1]=='B') ans--;
		}
		if ((s[i-1]=='G' && s[j-1]=='B') || (s[i-1]=='B' && s[j-1]=='G'))
		{
			ans=ans+r[i-1];
			if (2*i-j>0) if (s[2*i-j-1]=='R') ans--;
		}
		if ((s[i-1]=='R' && s[j-1]=='B') || (s[i-1]=='B' && s[j-1]=='R'))
		{
			ans=ans+g[i-1];
			if (2*i-j>0) if (s[2*i-j-1]=='G') ans--;
		}
	}
	cout<<ans;
}


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

int main(void)
{
	char str1[1024];
	char str2[1024];
	char temp[1024];
	int l1, l2;
	int n;
	int i;
	int diff;
	
	scanf("%d", &n);
	while (n-- != 0){
		scanf("%s", str1);
		scanf("%s", str2);
		
		l1 = strlen(str1);
		l2 = strlen(str2);
		
		if (l2 > l1){
			strcpy(temp, str1);
			strcpy(str1, str2);
			strcpy(str2, temp);
			
			l1 += l2;
			l2 = l1 - l2;
			l1 -= l2;
		}
		
		strcpy(temp, str2);
		memset(str2, '0', sizeof(str2));
		strcpy(&str2[l1 - l2 + 1], temp);
		
		strcpy(temp, str1);
		memset(str1, '0', sizeof(str1));
		strcpy(&str1[1], temp);
		
		memset(temp, '0', sizeof(temp));
		temp[l1 + 1] = '\0';
		diff = 0;
		
		for (i = l1; i >= 0; i--){
			temp[i] = str1[i] + str2[i] - '0' + diff;
			if (!(temp[i] >= '0' && temp[i] <= '9')){
				temp[i] -= 10;
				diff = 1;
			}
			else {
				diff = 0;
			}
		}
		if (temp[0] == '0'){
			strcpy(temp, &temp[1]);
		}
		if (strlen(temp) > 80){
			printf("overflow\n");
		}
		else {
			printf("%s\n", temp);
		}
	}
	
	return (0);
}

Measured memory_bytes: 0
import math
p=10**9+7
temp=list(map(int,input().split(" ")))
a,b=temp

if abs(a-b)>1:
  print(0)

elif a==b:
  print(math.factorial(a)*math.factorial(b)*2%p)
else:
  print(math.factorial(a)*math.factorial(b)%p)

Measured memory_bytes: 5184
#include <iostream>
#include <vector>
#include <string>
#include <stdio.h>
#include<limits.h>
#include<algorithm>


#define MOD 1000000007

using namespace std;

long long int modpow(long long int a, long long int n) {
	if (n == 0)return 1;
	if (n == 1)return (a % MOD);

	long long int hanbun = n / 2;
	long long int amari = n % 2;

	long long int ans = (a * a) % MOD;
	ans = modpow(ans, hanbun);

	if (amari == 1)ans *= a;

	ans %= MOD;

	return ans;

}

long long int gcd(long long int a, long long int b) {
	if (a < b) {
		long long int tmp = a;
		a = b;
		b = tmp;
	}

	long long int amari = a % b;

	if (amari == 0)return b;

	return gcd(b, amari);
}

long long int lcm(long long int a, long long int b) {
	long long int ans = (a * b) % MOD;
	long long int wari = modpow(gcd(a, b), MOD - 2);
	ans = (ans * wari) % MOD;
	return ans;
}

long long int factElement[10000] = { 0 };

long long int factrial(int n) {

	if (factElement[n] != 0)return factElement[n];

	if (n == 0) {
		factElement[0] = 1;
		return factElement[n];
	}

	long long int ans = n * factrial(n - 1);
	factElement[n] = ans;
	return factElement[n];

}

int main()
{

	int n;
	cin >> n;

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


	bool ans = true;
	for (int i = 0; i < n; i++) {
		if (a[i] % 2 == 0) {
			if (a[i] % 3 != 0 && a[i] % 5 != 0) {
				ans = false;
				break;
			}
			



		}
	}

	if(ans){
		cout << "APPROVED" << endl;
	}
	else {
		cout << "DENIED" << endl;
	}




	return 0;



}



Measured memory_bytes: 256
import sys
import math
MAX_INT = int(10e15)
MIN_INT = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

def tami(n, cnt):
  aoki_visited[n] = True
  aoki[n] = cnt
  for x in edge[n]:
    if aoki_visited[x] == False:
      tami(x, cnt+1)

def tami2(n, cnt):
  choku_visited[n] = True
  if cnt <= aoki[n]:
    choku[n] = cnt
    for x in edge[n]:
      if choku_visited[x] == False:
        tami2(x, cnt+1)

N, u, v = IL()
ab = [IL() for _ in range(N-1)]

aoki = [0]*(N+1)
aoki_visited = [False]*(N+1)
choku = [0]*(N+1)
choku_visited = [False]*(N+1)

edge = [[] for _ in range(N+1)]
for a,b in ab:
  edge[a].append(b)
  edge[b].append(a)

ans = 0
aoki[v] = MAX_INT
tami(v, 0)
tami2(u, 0)
#print(aoki)
#print(choku)

for i in range(N+1):
  if choku[i] == 0 and i != u:
    continue
  if aoki[i] > choku[i]:
    ans = max(ans, aoki[i] - 1)

print(ans)


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

// #define int ll
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using si = set<int>;
using ii = pair<int, int>;
using vii = vector<ii>;

#define fastio    ios::sync_with_stdio(0); cin.tie(0)
#define rep(i, n) for (int i = 0; i < n; i++)
#define dotc()    int tcs; if (cin >> tcs) rep(tc, tcs)
#define sz(x)     (int)x.size()
#define eb        emplace_back
#define pb        push_back
#define mp        make_pair
#define all(x)    x.begin(), x.end()
#define rall(x)   x.rbegin(), x.rend()
#define fi        first
#define se        second

int inf(0x3fffffff);
int mod(1000000007);
double pi(acos(-1.0));

int32_t main() {
  fastio;
#ifdef LOCAL
  freopen("io\\in.txt", "r", stdin);
  freopen("io\\out.txt", "w", stdout);
#endif

  ll n;
  cin >> n;

  int cnt = 0;
  for (int i = 2; 1ll * i * i <= n; i++) {
    int c = 0;
    while (n % i == 0) {
      c++;
      n /= i;
    }

    for (int j = 1; c - j >= 0; j++) cnt++, c -= j;
  }
  if (n != 1) cnt++;
  cout << cnt;

  return 0;
}


Measured memory_bytes: 3668
#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
const int pds=998244353;
const int N=1000086;
int q1[N+5],q2[N+5];
int Pow(int a,int b)
{
    int ans=1;
    for(;b;b>>=1,a=1ll*a*a%pds)
        if(b&1) ans=1ll*ans*a%pds;
    return ans;
}
void Init()
{
    q1[0]=1;
    for(int i=1;i<=N;i++)
        q1[i]=1ll*q1[i-1]*i%pds;
    q2[N]=Pow(q1[N],pds-2);
    for(int i=N-1;i>=0;i--)
        q2[i]=1ll*q2[i+1]*(i+1)%pds;
}
int C(const int &n,const int &m){return 1ll*q1[n]*q2[m]%pds*q2[n-m]%pds;}
int invC(const int &n,const int &m){return 1ll*q2[n]*q1[m]%pds*q1[n-m]%pds;}
int main()
{
    int n,m;Init();
    cin>>n>>m;
    int t=min(n,m),ans=0;
    for(int i=1;i<=t;i++)
    {
    	ans=(ans+1ll*C(2*i,i)*C(n+m-2*i,n-i))%pds;
    }
    ans=1ll*ans*invC(n+m,n)%pds*q2[2]%pds;
    cout<<(ans+max(n,m))%pds;
    return 0;
}

Measured memory_bytes: 8064
import java.util.Scanner;

public class Main {
 
	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		String s = input.next();
		long[] dp = new long[2019]; //stores remainder from 0-2018
		int cur = Integer.parseInt(s.substring(s.length()-1,s.length()));
		dp[cur]++;
		dp[0]=1;
		long cnt = 0;
		long pow_10 = 10;
		long div = 2019;
		//(2019 does not share any divisors with 10 (the base), 
		//therefore storing remainder trick works.
		for (int i = s.length()-2; i >= 0; i--) {
			long digit = Long.parseLong(s.substring(i,i+1));
			cur+=digit*pow_10;
			pow_10*=10;
			pow_10%=div;
			cur%=div;
			dp[cur]++;
		}
		for (int i = 0; i < 2019; i++) {
			cnt+=(dp[i])*(dp[i]-1)/2;
		}
		System.out.println(cnt);
	}
}

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

int n, k;
double p[202020];

int main()
{
    cin >> n >> k;
    rep(i, n)
    {
        cin >> p[i];
        p[i] = (p[i] + 1) / 2;
    }

    double sum = 0;
    rep(i, k) sum += p[i];
    double res = sum;
    for (int i = k; i < n; i++)
    {
        sum += p[i] - p[i - k];
        res = max(res, sum);
    }
    cout << setprecision(10) << res << endl;
    
    return 0;
}

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

int main()
{
  vector<vector<int> > p(2, vector<int>(10));
  for (int i = 0; i < 2; ++i) {
    for (int j = 0; j < 10; ++j)
      cin >> p[i][j];
  }
  sort(p[0].begin(), p[0].end(), greater<int>());
  sort(p[1].begin(), p[1].end(), greater<int>());
  cout << p[0][0]+p[0][1]+p[0][2] << " " << p[1][0]+p[1][1]+p[1][2] << endl;
  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using pll = pair<ll, ll>;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define rrep(i, m, n) for(ll i = m; i > n; i--)
#define Rep(i, m, n) for(ll i = m; i < n; i++)
#define all(vec) vec.begin(), vec.end()
#define lmax(x, y) max<ll>(x, y)
#define lmin(x, y) min<ll>(x, y)
#define tmax(x, y, z) lmax((x), lmax((y), (z)))
#define tmin(x, y, z) lmin((x), lmin((y), (z)))
#define MINUS(a) memset(a, 0xff, sizeof(a))
#define ZERO(a) memset(a, 0, sizeof(a))
const ll INF = 1LL << 60;
const ll MM = 1000000000; const ll MOD = MM + 7; const ll MMM=9223372036854775807;//2^63 -1
#define ADD(a,b) a = (a + ll(b)) % MOD
#define MUL(a,b) a = (a * ll(b)) % MOD
ll GCD(ll x, ll y){ if(y == 0) return x; else return GCD(y, x % y);}
ll LCM(ll x, ll y){ return x / GCD(x, y) * y;}
template<class T> inline bool chmin(T& a, T b){ if(a > b){ a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b){ if(a < b){ a = b; return true;} return false;}
template<typename A, size_t N, typename T> void FILL(A (&array)[N], const T &val){ fill( (T*)array, (T*)(array+N), val );}
// struct edge{ ll from, to, cost; };
// struct edge{ ll to, cost; };
// using Graph = vector<vector<ll>>;  // 重み無し
// using Graph = vector<edge>;  // 辺
// using Graph = vector<vector<edge>>;  // 重み付き
ll dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
ll ddx[8] = {1, 1, 0, -1, -1, -1, 0, 1}, ddy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
//cout << fixed << setprecision(10);
// priority_queue<ll, vector<ll>, greater<ll>> pq;


int main(){
    ll n, m, sum = 0; cin >> n;
    vector<ll> t(n);
    rep(i, n) cin >> t[i], sum += t[i];
    cin >> m;
    rep(i, m){
        ll p, x; cin >> p >> x;
        cout << sum - t[p-1] + x << endl;;
    }
}


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

using namespace std;

int main(void){
  int N;
  string S;
  cin >> N >> S;
  for(int i = 0; i < S.length(); i++){
    int n = S[i] - 'A';
    n += N;
    n %= 26;
    cout << (char)(n + 'A');
  }
  cout << endl;
  return 0;
}


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

// #define int long long // intで書いたけど心配なときにlong longに変換する
struct Fast {Fast(){std::cin.tie(0);ios::sync_with_stdio(false);}} fast;

/* short */
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define Fi first
#define Se second
#define ALL(v) begin(v), end(v)
#define RALL(v) rbegin(v), rend(v)
#define X real()
#define Y imag()

/* REPmacro */
#define REPS(i, a, n) for (ll i = (a); i < (ll)(n); ++i)
#define REP(i, n) REPS(i, 0, n)
#define RREP(i, n) REPS(i, 1, n + 1)
#define DEPS(i, a, n) for (ll i = (a); i >= (ll)(n); --i)
#define DEP(i, n) DEPS(i, n, 0)
#define EACH(i, n) for (auto&& i : n)

/* debug */
#define debug(x) cerr << x << " " << "(L:" << __LINE__ << ")" << '\n';

/* alias */
using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using pii = pair<int, int>;
using D = double;
using P = complex<D>;
using vs = vector<string>;
template <typename T> using PQ = priority_queue<T>;
template <typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

/* const */
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7;
const D EPS = 1e-9;
const int dx[] = {0, 1, 0, -1, 1, -1, 1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};

/* func */
inline bool inside(int y, int x, int H, int W) {return y >= 0 && x >= 0 && y < H && x < W;}
inline int in() {int x; cin >> x; return x;}
inline ll IN() {ll x; cin >> x; return x;}
inline vs split(const string& t, char c) {vs v; stringstream s(t); string b; while(getline(s, b, c)) v.eb(b); return v;}
template <typename T> inline bool chmin(T& a, const T& b) {if (a > b) a = b; return a > b;}
template <typename T> inline bool chmax(T& a, const T& b) {if (a < b) a = b; return a < b;}
template <typename T, typename S> inline void print(const pair<T, S>& p) {cout << p.first << " " << p.second << endl;}
template <typename T> inline void print(const T& x) {cout << x << endl;}
template <typename T, typename S> inline void print(const vector<pair<T, S>>& v) {for (auto&& p : v) print(p);}
template <typename T> inline void print(const vector<T>& v, string s = " ") {REP(i, v.size()) cout << v[i] << (i != (ll)v.size() - 1 ? s : "\n");}


signed main() {
    //my-code
    int R; cin >> R;
    cout << fixed;
    cout << setprecision(12) << 2*R*1.0*3.1415926535 << endl;

    return 0;
}

// https://github.com/kurokoji/.cpp-Template/wiki テンプレートについて
// http://www.creativ.xyz/dump-cpp-652 dump()について
// https://gist.github.com/rigibun/7905920 色々

Measured memory_bytes: 3804