akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define show(x) cout << #x << " = " << (x) << endl;
using namespace std;
using ll = long long;
using pii = pair<int,int>;
int n;
double dp[301][301][301];
double dfs(int a, int b, int c){
    if(dp[a][b][c]!=-1)return dp[a][b][c];
    double res =0;
    double aa = (double) a/(a+b+c);
    double bb = (double) b/(a+b+c);
    double cc = (double) c/(a+b+c);
    if(a)res += aa*dfs(a-1,b,c);
    if(b)res += bb*dfs(a+1,b-1,c);
    if(c)res += cc*dfs(a,b+1,c-1);
    dp[a][b][c] = res+(double)n/(a+b+c);
//    cerr << a << " " << b << " " << c << endl;
//    show(dp[a][b][c]);
    return dp[a][b][c];
}
int main(){
    cin >> n;
    int a[4] = {};
    rep(i,n){
        int x;
        cin >> x;
        a[x]++;
    }
    rep(i,n+1)rep(j,n+1)rep(k,n+1)dp[i][j][k] = -1;
    dp[0][0][0] = 0;
    printf("%.10lf\n", dfs(a[1],a[2],a[3]));
}

Measured memory_bytes: 213376
#include <iostream>
using namespace std;
void reverse(int b[],int n){
	int temp[n];
	
	for (int i=0;i<n;i++){
		
	}
}
int main() {
	int n,input,count=0;
	cin>>n;
	int b[n],c[n];
	for (int i=0;i<n;i++){
		cin>>b[i];
	}
	for (int i=n-1;i>=(!(n%2));i-=2){
		c[count]=b[i];
		count++;
	}
	for (int i=((n%2));i<n-1;i+=2){
		c[count]=b[i];
		count++;
	}
	for (int i=0;i<n;i++){
		b[i]=c[i];
	}
	for (int i=0;i<n;i++){
		cout<<b[i]<<" ";
	}
	return 0;
}

Measured memory_bytes: 3712
import java.util.*;
import java.lang.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int q = sc.nextInt();
		long[] s = new long[a];
		long[] t = new long[b];
		long[] x = new long[q];
		for (int i = 0; i < a; i++) {
			s[i] = sc.nextLong();
		}
		for (int i = 0; i < b; i++) {
			t[i] = sc.nextLong();
		}
		for (int i = 0; i < q; i++) {
			x[i] = sc.nextLong();
		}
		for (int i = 0; i < q; i++) {
			long ws;
			long es;
			long wt;
			long et;
			if (s[0] > x[i]) {
				ws = -100000000000l;
				es = s[0];
			} else if (s[a - 1] < x[i]) {
				ws = s[a - 1];
				es = 100000000000l;
			} else {
				int ok = 0;
				int ng = a - 1;
				while (Math.abs(ok - ng) > 1) {
					int mid = (ok + ng) / 2;
					if (s[mid] < x[i]) {
						ok = mid;
					} else {
						ng = mid;
					}
				}
				ws = s[ok];
				es = s[ok + 1];
			}
			if (t[0] > x[i]) {
				wt = -100000000000l;
				et = t[0];
			} else if (t[b - 1] < x[i]) {
				wt = t[b - 1];
				et = 100000000000l;
			} else {
				int ok = 0;
				int ng = b - 1;
				while (Math.abs(ok - ng) > 1) {
					int mid = (ok + ng) / 2;
					if (t[mid] < x[i]) {
						ok = mid;
					} else {
						ng = mid;
					}
				}
				wt = t[ok];
				et = t[ok + 1];
			}
			long min = 1000000000000000000l;
			long[] ss = {ws, es};
			long[] tt = {wt, et};
			for (long S: ss) {
				for (long T: tt) {
					long d1 = Math.abs(S - x[i]) + Math.abs(T - S);
					long d2 = Math.abs(T - x[i]) + Math.abs(S - T);
					min = Math.min(min, Math.min(d1, d2));
				}
			}
			System.out.println(min);
		}
	}
}

Measured memory_bytes: 110920
using System;
using System.Collections.Generic;

enum occupant
{
build, floor, room, number
}

class Program
 {


     
     static void Main(string[] args)
     {
         String nyuryoku;
         string[] data = new string[2];
         string[] data1;
         int row, column;
         int[,] matrix;
         int[] vector,result;


         nyuryoku = Console.ReadLine();
         data = nyuryoku.Split(' ');
         row = int.Parse(data[0]);
         column = int.Parse(data[1]);
         
         vector = new int[column];
         matrix = new int[row, column];
         data1 = new string[column];
         result = new int[row];

         for (int i = 0 ; i < row ; i++)
         {
             nyuryoku = Console.ReadLine();
             data1 = nyuryoku.Split(' ');
             for (int j = 0; j < column; j++)
                 matrix[i, j] = int.Parse(data1[j]);
         }
         for (int i = 0; i < column; i++)
         {
             nyuryoku = Console.ReadLine();
             vector[i] = int.Parse(nyuryoku);

         }
         for (int i = 0; i < row; i++)
         {
             for (int j = 0; j < column; j++)
             {
                 result[i] = result[i] + matrix[i, j] * vector[j];
             }
         }

         for (int i = 0; i < row; i++)
             Console.WriteLine("{0}", result[i]);

      }
 }



Measured memory_bytes: 18040
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<iomanip>
using namespace std;

int main(){
    int n,x;
    cin>>n>>x;
    int ans=1;
    int lx=0;
    int l[n];
    for(int i=0;i<n;i++){
        cin>>l[i];
        lx+=l[i];
        if(lx>x)break;
        else ans++;
    }
    cout<<ans<<endl;
    return 0;
}

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

int64_t nx(int n){
  int64_t x = 0;
  for(int i=1; i<=n; i++){
    x += i;
  }
  return x;
}

int main(){
  string S;
  cin >> S;
  int w_cnt = 0;
  int64_t w_num = 0;
  for(int i=0; i<S.size(); i++){
    if(S.at(i) == 'W'){
      w_cnt++;
      w_num += i;
    }
  }
  
  if(w_cnt == S.size() || w_cnt == 0){
    cout << 0 << endl;
  }
  else{
    cout << w_num - nx(w_cnt-1) << endl;
  }
}

Measured memory_bytes: 640
N = int(input())
ans = ""
v = 0
i = 0
while N != 0:
    if N % 2**(i+1) == 2**i:
        N -= (-2)**i
        ans += "1"
    else:
        ans += "0"
    i += 1

if len(ans) == 0:
    ans = "0"
print(ans[::-1])


Measured memory_bytes: 3060
#include<iostream>
#include<algorithm>
#include<math.h>
#include<queue>
#include<vector>
#include<climits>
#include<map>
#include<string>
#include<functional>
#include<iomanip>
#include<deque>
#include<random>
#include<set>
#include<bitset>
#include<cassert>

using namespace std;
typedef long long ll;
typedef double lldo;
#define mp make_pair
#define pub push_back
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
ll gcd(ll a, ll b) { if (a % b == 0) { return b; } else  return gcd(b, a % b); }
ll lcm(ll a, ll b) { if (a == 0) { return b; }return a / gcd(a, b) * b; }
template<class T>ll LBI(vector<T>& ar, T in) { return lower_bound(ar.begin(), ar.end(), in) - ar.begin(); }
template<class T>ll UBI(vector<T>& ar, T in) { return upper_bound(ar.begin(), ar.end(), in) - ar.begin(); }

ll n, white = 0, ans = 0;
string c;

int main() {
	cin >> n;
	cin >> c;
	rep(i, sz(c)) {
		if (c[i] == 'W')white++;
	}
	rep(i, white) {
		if (c[n - i - 1] == 'R')ans++;
	}
	cout << ans << endl;
	return 0;
}

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

const int INF = 1e9+5;

int main() {

    int n, k;
    cin >> n >> k;

    vector<int> h(n);
    for (int& x: h)
        scanf("%d", &x);

    vector<long long> dp(n, INF);
    dp[0] = 0;

    for (int i=0; i<n; i++) {
        for (int j=i+1; j <= i+k; j++) {
            if (j < n) {
                dp[j] = min(dp[j], dp[i] + abs(h[i] - h[j]));
            }
        }
    }

    printf("%d\n", dp[n-1]);
}

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

int main() {
    int A, B, C, D;
    cin >> A >> B >> C >> D;
	while(true){
		C -= B;
		if (C <= 0){
			cout << "Yes" << endl;
			break;
		}
		A -= D;
		if (A <= 0){
			cout << "No" << endl;
			break;
		}
	}
	return 0;
}

Measured memory_bytes: 3576
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define SORT(a) sort(a.begin(), a.end())
#define REVERSE(a) reverse(a.begin(), a.end())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define int long long
#define INF 1000000000000000000
using namespace std;

typedef vector<int> vec;
typedef vector<vec> mat;
typedef pair<int, int> Pii;

#define ANS(f) if(f) cout << "YES" << endl; else cout << "NO" << endl;

template<typename T>
void readv(vector<T> &a){ REP(i, a.size()) cin >> a[i]; }
void readi(vector<int> &a){ REP(i, a.size()){cin >> a[i]; a[i]--;} }



signed main(){

    int N; cin >> N;
    string S; cin >> S;
    int Q; cin >> Q;
    vec k(Q); readv(k);

    REP(q, Q){
        int ans = 0;
        int D = 0, M = 0, DM = 0;
        REP(i, N){
            if(i >= k[q]){
                if(S[i - k[q]] == 'D'){
                    D--;
                    DM -= M;
                }else if(S[i - k[q]] == 'M') M--;
            }
            if(S[i] == 'D') D++;
            else if(S[i] == 'M'){
                M++;
                DM += D;
            }
            else if(S[i] == 'C') ans += DM; 
        }

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

Measured memory_bytes: 1412
#include<bits/stdc++.h>
using namespace std;
int x,y;
int m[1009][1009];
char a[1009][1009];
int main()
{
    for(int i=0; i<1009; i++)
    {
        for(int j=0; j<1009; j++)
        {
            m[i][j]=0;
        }
    }

    cin>>x>>y;

    for(int i=0; i<x; i++)
    {
        for(int j=0; j<y; j++)
        {
            cin>>a[i][j];
        }
    }
    for(int i=0; i<x; i++)
    {
        if(a[i][0]=='.')
            m[i][0]=1;
        else
            break;
    }
    for(int i=0; i<y; i++)
    {
        if(a[0][i]=='.')
            m[0][i]=1;
        else
            break;
    }

    for(int i=1; i<x; i++)
    {
        for(int j=1; j<y; j++)
        {
            if(a[i][j]=='.')
                m[i][j]=(m[i-1][j]+m[i][j-1])%1000000007;
        }
    }
    cout<<m[x-1][y-1]<<endl;

}

Measured memory_bytes: 5248
#include <bits/stdc++.h> 
#define FOR(i,a,b) for(int i=(a);i<=(b);++i) 
#define RFOR(i,a,b) for(int i=(a);i>=(b);--i) 
#define REP(i,n) for(int i=0;i<(n);++i)
#define RREP(i,n) for(int i=(n);i>0;--i)
#define CI cin>> 
#define CO cout<<
#define EN <<endl 
#define all(x) (x).begin(),(x).end() 
#define asn ans
using namespace std;
template <typename T> istream& operator >> (istream& is, vector<T>& vec) { for (T& x : vec) is >> x; 	return is; }
using ll = long long;

int main(){
	int a; CI a;
	ll ans = 0;
	ll b = 0;
	vector<ll> v(a);
	REP(i, a){
		int tmp; CI tmp;
		v[i] = tmp - (i + 1);
	}

	sort(all(v));

	if (a % 2==1){
		b = v[(a - 1) / 2];
	}
	else{
		b = (v[(a / 2) - 1] + v[a / 2]) / 2;
	}


	REP(i, a){
		ans += abs(v[i] - b);
	}

	CO ans EN;

	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long cc;
typedef pair <int, int> pii;
#define X first
#define Y second
#define pb push_back
const int N = 1000006, md = 1000000000 + 7;
int n, m;
int f[N];
int main() {
    //freopen("input.inp", "r", stdin);
    //freopen("output.out", "w", stdout);
    //freopen("BOYGIRL.inp", "r", stdin);
    //freopen("BOYGIRL.out", "w", stdout);
    ios_base  :: sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    cin >> n >> m;
    if (abs(n - m) > 1) {
        cout << 0;
        return 0;
    }
    f[1] = 1;
    for (int i = 2; i <= max(n, m); i++)
        f[i] = (1ll * f[i - 1] * i) % md;
    int res = (1ll * f[n] * f[m]) % md;
    if (n == m)
        res= (2ll * res) % md;
    cout << res;
    return 0;
}


Measured memory_bytes: 640
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1000000009LL;
constexpr long long LINF = 1000100010001000100LL;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define rept(i, j, n) for(int i=(j); i<(n); i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }


int main() { 
    string s; cin >> s;
    int a = 0, b = 0;
    for(char c: s){
        if(c=='0')a++;
        else b++;
    }
    cout << min(a, b)*2 << ln;
}

Measured memory_bytes: 512
#include<iostream>
#define N 10000
using namespace std;

int father[N+1];
int n,q;

int findp(int i){
    while(father[i]!=i){
        i=father[i];
    }
    return i;
}

void mergep(int a,int b){
    int fa=findp(a);
    int fb=findp(b);
    father[fb]=fa;
}

int main(){
    cin>>n>>q;
    int k,a,b;
    for(int i=0;i<n;i++){
        father[i]=i;
    }
    for(int i=0;i<q;i++){
        cin>>k>>a>>b;
        if(k==0){
            mergep(a,b);
        }else if(k==1){
            cout<<(findp(a)==findp(b))<<endl;
        }
    }
}



Measured memory_bytes: 3136
#include <iostream>
#include <map>

using namespace std;

int main() {
    int N, T;
    cin >> N;
    cin >> T;
    int key;
    int val;
    map<int, int> mp;
    for(int i = 0; i < N; i++) {
        cin >> key;
        cin >> val;
        mp[key] = val;
    }
    for(auto x : mp) {
        if (x.second > T) {
            continue;
        }
        cout << x.first << endl;
        return 0;
    }
    cout << "TLE" << endl;

    return 0;
}

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

int main(void)
{
	char in[1001];
	int freq[26];
	int p;
	int s;
	int i;
	int base;
	
	scanf("%s", &in);
	
	if (strlen(in) < 8){
		printf("%s\n", in);
		return (0);
	}
	
	memset(freq, 0, sizeof(freq));
	base = 0;
	for (p = 0; in[p] != '\0'; p++){
		freq[in[p] - 'A']++;
		if (freq['A' - 'A'] == 2 &&
			freq['I' - 'A'] == 1 &&
			freq['D' - 'A'] == 1 &&
			freq['U' - 'A'] == 1 &&
			freq['N' - 'A'] == 2 &&
			freq['Y' - 'A'] == 1){

			
			printf("AIZUNYAN");
			
			memset(freq, 0, sizeof(freq));
			base = p + 1;
//printf("[base=%d]", base);
		}
		else {
//printf("*");
			if (p - 7 >= base){
				freq[in[p - 7] - 'A']--;
				printf("%c", in[p - 7]);
//				printf("<%d-%d=%d %c>", p, base, p - 8, in[p - 8]);
			}
		}
	}
	s = 0;
	for (i = 0; i < 26; i++){
//printf("[%c %d]", i + 'A', freq[i]);
		s += freq[i];
	}
//printf("<%d>", s);
	printf("%s\n", &in[strlen(in) - s]);
	
	return (0);
}

Measured memory_bytes: 540
using System;

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

            for (int i = 0; i < N; i++)
            {
                input = Console.ReadLine();
                string[] num = input.Split(' ');
                Circle A = new Circle(num[0], num[1], num[2]);
                Circle B = new Circle(num[3], num[4], num[5]);
                output = A.Cross(B);
                Console.WriteLine(output);
            }

        }
    }

    public struct Circle
    {
        decimal X, Y, R;

        public Circle (string k, string l, string m)
        {
            this.X = decimal.Parse(k);
            this.Y = decimal.Parse(l);
            this.R = decimal.Parse(m);
        }

        public int Cross (Circle A)
        {
            int z;
            decimal dis = (A.X -this.X) * (A.X - this.X) + (A.Y - this.Y) * (A.Y - this.Y);
            if (A.R > this.R)
            {
                if (dis > A.R * A.R + 2 * A.R * this.R + this.R * this.R)
                {
                    z = 0;
                } else if (dis < A.R * A.R - 2 * A.R * this.R + this.R * this.R)
                {
                    z = -2;
                } else
                {
                    z = 1;
                }
            } else if (A.R < this.R)
            {
                if (dis > A.R * A.R + 2 * A.R * this.R + this.R * this.R)
                {
                    z = 0;
                }
                else if (dis < A.R * A.R - 2 * A.R * this.R + this.R * this.R)
                {
                    z = 2;
                }
                else
                {
                    z = 1;
                }
            } else
            {
                if (dis > A.R * A.R + 2 * A.R * this.R + this.R * this.R)
                {
                    z = 0;
                }
                else 
                {
                    z = 1;
                }
            }
            return z; 
        }
    }
}

Measured memory_bytes: 9452
N = int(input())

S = [int(input()) for _ in range(N)]

S_sum = sum(S)

if S_sum %10 !=0:
    print(S_sum)
    exit()
max_val = 0

for val in S:
    if val %10 !=0:
        max_val = max(max_val,S_sum-val)

print(max_val)

Measured memory_bytes: 3060
#include<cstdio>
#include<cstdlib>
#include<string>
#include<iostream>
using namespace std;

struct Node {
	int key;
	Node *right, *parent, *left;
};

Node *root, *NIL;

Node * find(Node *u, int k) {
	while (u != NIL && k != u->key) {
		if (k < u -> key) {
			u = u->left;
		}
		else u = u->right;
	}
	return u;
}

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

	z = (Node *)malloc(sizeof(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)return;
	inorder(u->left);
	printf(" %d", u->key);
	inorder(u->right);
}

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

int main() {
	int n, i, x;
	string com;

	scanf("%d", &n);

	for (i = 0; i < n; i++) {
		cin >> com;
		if (com[0] == 'f') {
			scanf("%d", &x);
			Node *t = find(root, x);
			if (t != NIL)printf("yes\n");
			else printf("no\n");
		}
		else if (com == "insert") {
			scanf("%d", &x);
			insert(x);
		}
		else if (com == "print") {
			inorder(root);
			printf("\n");
			preorder(root);
			printf("\n");
		}
	}

	return 0;
}


Measured memory_bytes: 22072
s = input()


def valid(s):
    if s[0] != 'A':
        return False
    if 'C' not in s[2:len(s)-1] or s[2:len(s)-1].find('C') != s[2:len(s)-1].rfind('C'):
        return False

    _s = s[1:].replace('C', "")
    if not _s.islower():
        return False
    return True


if valid(s):
    print("AC")
else:
    print("WA")

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

#define mod 1000000007
int add(int x,int y){
	return (x+=y)<mod?x:x-mod;
}
int mul(int x,int y){
	return (int)((long long int)x*y%mod);
}

#define ran 111111
struct Node{
	bool val;
	int sum;
	void setzero(){
		val = true;
		sum = 0;
	}
	void set_single_val(int x){
		val = false;
		sum = x;
	}
};
void merge(Node&res,const Node&A,const Node&B){
	res.sum = add(A.sum,B.sum);
}

struct segTree{
	Node seg[ran*4];
	void push(int i,int s,int e){
		bool&tmp = seg[i].val;
		if(tmp){
			seg[i*2].setzero();
			seg[i*2+1].setzero();
			tmp = false;
		}
	}
	void setzero(int i,int s,int e,int l,int r){
		if(s == l && e == r){
			seg[i].setzero();
			return;
		}
		push(i,s,e);
		int m = (s+e)/2;
		if(r <= m)setzero(i*2,s,m,l,r);else
		if(l > m)setzero(i*2+1,m+1,e,l,r);else{
			setzero(i*2,s,m,l,m);
			setzero(i*2+1,m+1,e,m+1,r);
		}
		merge(seg[i],seg[i*2],seg[i*2+1]);
	}
	void set_single_val(int i,int s,int e,int x,int y){
		if(s == x && e == x){
			seg[i].set_single_val(y);
			return;
		}
		push(i,s,e);
		int m=(s+e)/2;
		if(x <= m)set_single_val(i*2,s,m,x,y);else
			set_single_val(i*2+1,m+1,e,x,y);
		merge(seg[i],seg[i*2],seg[i*2+1]);
	}
	int query(int i,int s,int e,int l,int r){
		if(s==l && e==r)
			return seg[i].sum;
		push(i,s,e);
		int m = (s+e)/2;
		if(r<=m)return query(i*2,s,m,l,r);else
		if(l>m)return query(i*2+1,m+1,e,l,r);else{
			return add(query(i*2,s,m,l,m),query(i*2+1,m+1,e,m+1,r));
		}
	}
};
segTree setA,setB;

int n;
long long int A,B;
long long int a[ran];
int main(){
	cin >> n >> A >> B;
	for(int i=1; i<=n; i++)
		cin >> a[i];

	setA.set_single_val(1,0,n,0,1);
	setB.set_single_val(1,0,n,0,1);
	for(int i=2; i<=n; i++){
		setA.set_single_val(1,0,n,i-1,
				setB.query(1,0,n,0,min(i-2,
					(int)(upper_bound(a+1,a+i,a[i] - A) - a - 1)
						)));
		setB.set_single_val(1,0,n,i-1,
				setA.query(1,0,n,0,min(i-2,
					(int)(upper_bound(a+1,a+i,a[i] - B) - a - 1)
						)));
		if(a[i] - a[i-1] < A){
			setA.setzero(1,0,n,0,i-2);
		}
		if(a[i] - a[i-1] < B){
			setB.setzero(1,0,n,0,i-2);
		}
	}
	printf("%d\n",add(setA.query(1,0,n,0,n-1),setB.query(1,0,n,0,n-1)));
	return 0;
}


Measured memory_bytes: 6652
#include<bits/stdc++.h>
using namespace std;
#define db long double
#define ys operator
int n,ct1,ct2,ct;
struct node{
	db x,y;
	int bh;
	node(db _x = 0.0,db _y = 0.0){
		x = _x;
		y = _y;
		bh = 0;
	}
	void r(int i){
		double _x,_y;
		scanf("%lf%lf",&_x,&_y);
		x = _x;
		y = _y;
		bh = i;
	}
}a[100010];
int d[100010],e[100010],f[100010];
node ys + (node q,node w){
	return node(q.x + w.x,q.y + w.y);
} 
node ys - (node q,node w){
	return node(q.x - w.x,q.y - w.y);
} 
node ys * (db q,node w){
	return node(q * w.x,q * w.y);
} 
db cj(node q,node w){
	return q.x * w.y - q.y * w.x;
}
bool ys < (node q,node w){
	return q.x < w.x ? 1 : q.x > w.x ? 0 : q.y < w.y;
}
#define pi acos(-1)
db len(node q){
	return sqrtl(q.x * q.x + q.y * q.y);
}
db as[100010];
db dj(node q,node w){
	return q.x * w.x + q.y * w.y;
}
int main(){
	//cout<<acos(-0.5);
	int i,j,k;
	scanf("%d",&n);
	for(i = 1;i <= n;++i) a[i].r(i);
	sort(a + 1,a + n + 1);
	for(i = 1;i <= n;++i){
		while(ct1 > 1 && cj(a[d[ct1]] - a[i],a[d[ct1]] - a[d[ct1 - 1]]) >= 0) --ct1;
		d[++ct1] = i;
	} 
	for(i = n;i;--i){
		while(ct2 > 1 && cj(a[e[ct2]] - a[i],a[e[ct2]] - a[e[ct2 - 1]]) >= 0) --ct2;
		e[++ct2] = i;
	}
	for(i = 1;i <= ct1;++i) f[++ct] = d[i];
	for(i = 2;i <= ct2;++i) f[++ct] = e[i];
	f[++ct] = f[2];
	//for(i = 2;i < ct;++i) cout<<a[f[i]].x<<" "<<a[f[i]].y<<endl;
	for(i = 2;i < ct;++i){
		//cout<<a[f[i]].x<<" "<<a[f[i]].y<<" ";
		node p1 = a[f[i]] - a[f[i - 1]],p2 = a[f[i]] - a[f[i + 1]];
		db jiao = dj(p1,p2) / len(p1) / len(p2) > 1 ? 0 : dj(p1,p2) / len(p1) / len(p2) < -1 ? pi : acos(dj(p1,p2) / len(p1) / len(p2));
		//cout<<fabs(cj(p1,p2)) / len(p1) / len(p2)<<" "<<jiao<<endl;
		as[a[f[i]].bh] = (pi - jiao) / 2 / pi;
		//cout<<as[f[i]]<<endl;
	}
	for(i = 1;i <= n;++i) printf("%.10lf\n",(double)as[i]);
	return 0;
}

Measured memory_bytes: 5632
def inpl(): return [int(i) for i in input().split()]

R, C, N = inpl()
loopx = {0: [], R: []}
loopy = {0: [], C: []}
for i in range(N):
    x1, y1, x2, y2 = inpl() 
    if (x1 in (0,R) or y1 in (0,C))\
    and (x2 in (0,R) or y2 in (0,C)):
        if x1 in (0,R):
            loopx[x1].append((y1,i))
        elif y1 in (0,C):
            loopy[y1].append((x1,i))
        if x2 in (0,R):
            loopx[x2].append((y2,i))
        elif y2 in (0,C):
            loopy[y2].append((x2,i))
loop = [j for i, j in sorted(loopy[0])] +\
[j for i, j in sorted(loopx[R])] +\
[j for i, j in sorted(loopy[C])][::-1] +\
[j for i, j in sorted(loopx[0])][::-1]
stack = []
for i in loop:
    if not stack:
        stack.append(i)
        continue
    if stack[-1] == i:
        stack.pop()
    else:
        stack.append(i)
if not stack:
    print('YES')
else:
    print('NO')

Measured memory_bytes: 30584
#define _CRT_SECURE_NO_WARNINGS
#define _SCL_SECURE_NO_WARNINGS
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <utility>
#include <algorithm>
#include <functional>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
#include <sstream>
#include <bitset>
#include <limits>
#include <numeric>
#include <valarray>
#include <fstream>

using namespace std;
typedef unsigned int uint;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<LL, LL> PP;
#define REP(i, a, n) for(LL i = (a), i##_max = (n); i < i##_max; ++i)
#define REM(i, a, n) for(LL i = (LL)(n) - 1, i##min = (a); i >= i##min; --i)
#define ALL(arr) (arr).begin(), (arr).end()
#define FLOAT fixed << setprecision(16)
#define SPEEDUP {cin.tie(NULL); ios::sync_with_stdio(false);}
const int INF = 0x3FFFFFFF;
const LL INFLL = 0x3FFFFFFF3FFFFFFF;
const double INFD = 1.0e+308;
const string INFSTR = "\x7f";
const double EPS = 1.0e-9;

void YesNo(bool b) { cout << (b ? "Yes" : "No") << endl; }
void YESNO(bool b) { cout << (b ? "YES" : "NO") << endl; }
template <class T, class U>
istream& operator>>(istream& ist, pair<T, U>& right) { return ist >> right.first >> right.second; }
template <class T, class U>
ostream& operator<<(ostream& ost, const pair<T, U>& right) { return ost << right.first << ' ' << right.second; }
template <class T, class TCompatible, size_t N>
void Fill(T(&dest)[N], const TCompatible& val) { fill(dest, dest + N, val); }
template <class T, class TCompatible, size_t M, size_t N>
void Fill(T(&dest)[M][N], const TCompatible& val) { for (int i = 0; i < M; ++i) Fill(dest[i], val); }
template<class T>
T Compare(T left, T right) { return left > right ? 1 : (left < right ? -1 : 0); }
istream& Ignore(istream& ist) { string s; ist >> s; return ist; }
bool Inside(int i, int j, int h, int w) { return i >= 0 && i < h && j >= 0 && j < w; }
template <class T>
T Next() { T buf; cin >> buf; return buf; }

#ifdef ONLY_MY_ENVIR
#include "IntMod.h"
#include "UnionFind.h"
#include "Graph.h"
#include "Range.h"
#include "Global.h"
#include "FlowSolver.h"
#include "Tree.h"
#include "SuffixArray.h"
#include "Matrix.h"
#include "SegmentTree.h"
#include "SegmentTree2D.h"
#include "BIT.h"
#include "Rational.h"
#include "Position.h"
#include "Factorization.h"
#include "Math.h"
#endif

#ifdef __GNUC__
typedef __int128 LLL;
istream& operator>> (istream& ist, __int128& val) { LL tmp;  ist >> tmp; val = tmp; return ist; }
ostream& operator<< (ostream& ost, __int128 val) { LL tmp = val; ost << tmp; return ost; }
#endif

#if 1234567891
#include <array>
#include <random>
#include <unordered_set>
#include <unordered_map>
template<typename T>
using PriorityQ = priority_queue<T, vector<T>, greater<T> >;
// template <class T>
// auto Is(const T& value) { return [value](const auto& comparand) -> bool { return comparand == value; }; }
#endif

int C[4];

bool sub() {
	REP(i, 0, 4) {
		if (C[i] == 3) return false;
	}
	return true;
}

int main() {
	REP(i, 0, 6) {
		int a;
		cin >> a;
		--a;
		C[a]++;
	}

	YESNO(sub());
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    string a,b,c;
    cin >>a>>b>>c;
    for(int i=0;i<a.size();i++){
    for(int j=0;j<b.size();j++){
    for(int z=0;z<c.size();z++){
     (a[i])=  (a[i])-'a'+'A';
     (b[j])=  (b[j]) -'a'+'A';
     (c[z])=  (c[z]) -'a'+'A';
    cout <<a[i] ;cout << b[j];cout << c[z]; return 0;}
    }
}
}

Measured memory_bytes: 764
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <numeric>
#include <set>
#include <unordered_set>
#include <queue>
#include <cmath>
 
using namespace std;
#define ll long long
#define rep(i, n) for(int i = 0;i < n;i++)
#define FOR(i, n, m) for(int i=n; i<m; ++i)

using Graph = vector<vector<int>>;

// 深さ優先探索
vector<bool> seen;
void dfs(const Graph &G, int v) {
    seen[v] = true; // v を訪問済にする

    // v から行ける各頂点 next_v について
    for (auto next_v : G[v]) { 
        if (seen[next_v]) continue; // next_v が探索済だったらスルー
        dfs(G, next_v); // 再帰的に探索
    }
}

bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return false;
        }
    }

    // 素数である
    return true;
}

int main() {
  ll N, K, sum;
  cin >> N >> K;
  ll p[2000];
  rep(i,N) cin >> p[i];
  
  sort(p, p+N);
  
  sum = 0;
  
  rep(i,K){
    sum+=p[i];
  }
  
  cout << sum << endl;

  
}

Measured memory_bytes: 3660
#include<iostream>
#include<string>
#include<cstdio>

using namespace std;

int main(){
	int a,b,c;
	cin>>a>>b>>c;
	if(a*b*c == 175){
		printf("YES\n");
		return 0;
	}
	printf("NO\n");
	return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class MainClass
{
	public static void Main(string[] args)
	{
		int n = int.Parse(Console.ReadLine());
		SortedDictionary<string,List<Val>> m = new SortedDictionary<string,List<Val>>();
		for(int i = 0; i < n; i ++)
		{
			string[] k = Console.ReadLine().Split(' ');
			string s = k[0];
			int p = int.Parse(k[1]);
			if(!m.ContainsKey(s))
			m.Add(s,new List<Val>());
			m[s].Add(new Val(){Name=s,Point=p,Index=i+1});
		}
		foreach(string key in m.Keys)
		{
			List<Val> a = m[key];
			a.Sort ((k,b) => { return b.Point - k.Point; });
			for(int i = 0; i < a.Count; i++)
			{
				Console.WriteLine(a[i].Index);
			}
		}
	}


	public static int Clamp(int val, int max, int min = 0)
	{
		return Math.Min(max, Math.Max(min, val));
	}

	
}

public class Val
{
	public string Name{get;set;}
	public int Point{get;set;}
	public int Index{get;set;}
}


Measured memory_bytes: 11860
import java.util.*;

public class Main {

    public static void main(String[] args) {
        // write your code here
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        HashMap<Integer, Integer> map = new HashMap<>();
        for (int i = 0; i < n; i++) {
            int v = sc.nextInt();
            Integer saved = map.get(v);
            map.put(v, saved == null ? 1 : ++saved);
        }
        int m  = sc.nextInt();
        for (int i = 0; i < m; i++) {
            int need = sc.nextInt();
            Integer saved = map.get(need);
            if (saved == null || saved == 0) {
                System.out.println("NO");
                return;
            }
            map.put(need, --saved);
        }
        System.out.println("YES");
    }
}

Measured memory_bytes: 135748
#include<bits/stdc++.h>
using namespace std;
typedef  long long ll;
using vll=vector<ll>;
using vi=vector<int>;

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;}

//pow(llpow,modpow)
template<class T> ll llpow(ll x,T n){ll ans=1;if(x==0)ans=0;while(n){if(n&1)ans*=x;x*=x;n>>=1;}return ans;}
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;}
//最大公約数
template<class T> inline T gcd(T x,T y){if(y==0)return x; else {return gcd(y,x%y);}}
//最小公倍数
template<class T> inline T lcm(T x,T y){return x/gcd(x,y)*y;}
//逆元
long long modinv(long long a, long long m) {long long b = m, u = 1, v = 0;while (b) {long long t = a / b;a -= t * b; swap(a, b);u -= t * v; swap(u, v);}u %= m;if (u < 0) u += m;return u;}

#define rep(i,n) for(ll i=0;i<(ll)n;i++)
#define rep2(i, begin_i, end_i) for (ll i = (ll)begin_i; i < (ll)end_i; i++)

long long INF = 1LL<<60;

string s;int K;
int comb(int n,int k){
    if(k<0||n<k)return 0;

    if(k==1)return n;
    else if(k==2)return n*(n-1)/2;
    else return n*(n-1)*(n-2)/6;
}

int solve(bool smaller,int i,int k){
    int n=s.size();
    if(i==n){
        if(k==0)return 1;
        else return 0;
    }
    if(k==0)return 1;

    if(smaller){
        return comb((n-i),k)*pow(9,k);
    }
    else{
        int v=s.at(i)-'0';
        if(v==0){
            return solve(false,i+1,k);
        }
        else {
        int aida,zero,pitta;
        aida=solve(true,i+1,k-1)*(v-1);
        zero=solve(true,i+1,k);
        pitta=solve(false,i+1,k-1);
        return aida+zero+pitta;
        }
    }
}
int main( ){
    cin>>s>>K;
    ll ans=0;
    ans=solve(false,0,K);
    cout<<ans<<endl;
    return 0;
}




Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <iomanip> // cout<<setprecision(n)
#include <functional> // std::function<void(int)>
using namespace std;
#define All(v) (v).begin(),(v).end()
const long long mod = 1000000007;
const long long inf = mod*mod;
const double EPS=1e-10;
const double INF=1e+10;
const double PI=acos(-1.0);
signed main(){
    string s;
    cin>>s;
    s += 'R';
    int l = s.size();
    int rcnt = 0, lcnt = 0;
    int p = 0, q = 0;
    int dp[1000000];
    for (int i = 0; i < l;i++){
        dp[i] = 0;
    }
    for (int i = 0; i < l; i++){
        if (s[i] == 'R'){
            rcnt++;
        }
        else{
            lcnt++;
        }
        if(s[i]=='R'&&s[i+1]=='L'){
            p = i;
            q = i + 1;
        }
        if (s[i] == 'L' && s[i + 1] == 'R')
        {
            dp[p] = (lcnt + rcnt) / 2;
            dp[q] = (lcnt + rcnt) / 2;
            if (abs(lcnt - rcnt) % 2 == 1 && rcnt > lcnt && rcnt % 2 == 0)
                dp[q]++;
            if (abs(lcnt - rcnt) % 2 == 1 && rcnt > lcnt && rcnt % 2 == 1)
                dp[p]++;
            if (abs(lcnt - rcnt) % 2 == 1 && rcnt < lcnt && lcnt % 2 == 1)
                dp[q]++;
            if (abs(lcnt - rcnt) % 2 == 1 && rcnt < lcnt && lcnt % 2 == 0)
                dp[p]++;
            lcnt = 0;
            rcnt = 0;
        }
    }
    for (int i = 0; i < l - 1;i++){
        cout << dp[i]<<' ';
    }
    cout << endl;
}

Measured memory_bytes: 3072
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define INF 1000000007
//0=48,A=65,a=97

int main() {
    int n,k;cin >> n >> k;
    vector<int> a(n);for(int i=0;i<n;i++) cin >> a[i];
    
    int z=lower_bound(a.begin(),a.end(),0)-a.begin();//zero_indexed
    int plus=min(k,n-z);//まず0以上のろうそくを付ける
    int minus=k-plus;//まず最初に付けなくてはならない0未満のろうそくの数
    int first=z-minus,end=z+plus-1;//最初の先頭,最後

    int ans=INF;
    
    while(first>=0 && end >= z-1){
        int sum=2*min(abs(a[first]),abs(a[end])) + max(abs(a[first]),abs(a[end]));
        if(first==z || end==z-1) sum = max(abs(a[first]),abs(a[end]));
        ans = min(sum,ans);
        first--,end--;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3764
using namespace std;
#include <bits/stdc++.h>
#define rep(i, s) for (int i = 0; i < s; ++i)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define all(v) (v.begin(), v.end())
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define VEC(a, n) vector<int>a(n)
#define PQ(a) priority_queue<int>a
#define PQmin(a) priority_queue< int, :vector<int>, greater<int> >a
#define PAIR pair<int, int>
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
#define EPS (1e-7)
#define INF (1e10)
#define PI (acos(-1))
const ll mod = 1000000007;
bool f(string s){
  bool ans=true;
  rep(i,s.size()/2){
    if(s[i]!=s[s.size()/2+i]){
      ans=false;
      break;
    }
  }
  return ans;
}

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int A,B;
  cin>>A>>B;
  if(A==B)
    cout<<"Yes"<<endl;
  else
    cout<<"No"<<endl;
}


Measured memory_bytes: 256
import java.util.Collections;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		try (Scanner sc = new Scanner(System.in)) {
			int N = sc.nextInt();
			int M = sc.nextInt();
			PriorityQueue<Integer> pq = new PriorityQueue<>(Collections.reverseOrder());
			for (int i = 0; i < N; i++) {
				pq.add(sc.nextInt());
			}
			for (int i = 0; i < M; i++) {
				int top = pq.poll();
				pq.add(top / 2);
			}
			long sum = 0;
			for (int i = 0; i < N; i++) {
				sum += pq.poll();
			}
			System.out.print(sum);
		}
	}
}


Measured memory_bytes: 62540
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;

class Program
{
    static void Main(string[] args)
    {
        var NK = ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
        var (N, K) = (NK[0], NK[1]);

        var mCombination = new ModCombination(2001);

        for (int i = 0; i < K; i++)
        {
            var r = N - K;
            var rFree = r - i;

            if(rFree < 0)
            {
                WriteLine(0);
                continue;
            }

            var rInsert = i + 1;
            var rCombination = mCombination.Combination(rFree + rInsert, rInsert);

            var b = K;
            var bFree = (i == 0) ? 0 : b - (i + 1);
            var bInsert = i;
            var bCombination = mCombination.Combination(bFree + bInsert, bInsert);

            var ans = rCombination * bCombination;

            WriteLine(ans);
        }
    }
}

class ModCombination
{
    private ModInt[] fact, ifact;
    public int MaxN { get; }

    public ModCombination(int maxN)
    {
        if (maxN < 0 || ModInt.Mod <= maxN)
            throw new ArgumentException();

        MaxN = maxN;

        fact = new ModInt[maxN + 1];
        ifact = new ModInt[maxN + 1];

        fact[0] = new ModInt(1);
        for (int i = 1; i <= maxN; ++i)
            fact[i] = fact[i - 1] * new ModInt(i);

        ifact[maxN] = ModInt.Inv(fact[maxN]);
        for (int i = maxN; i >= 1; --i)
            ifact[i - 1] = ifact[i] * new ModInt(i);
    }

    public ModInt Combination(int n, int k)
    {
        if ((n < 0 || MaxN < n) || (k < 0 || n < k))
            throw new ArgumentException();

        return fact[n] * ifact[k] * ifact[n - k];
    }
}

struct ModInt
{
    public const int Mod = 1000000007;

    public long X { get; }

    public ModInt(long x = 0) => X = (x % Mod + Mod) % Mod;

    public static ModInt operator +(ModInt mint) => mint;
    public static ModInt operator -(ModInt mint) => new ModInt(-mint.X);
    public static ModInt operator +(ModInt mint1, ModInt mint2) => new ModInt(mint1.X + mint2.X);
    public static ModInt operator -(ModInt mint1, ModInt mint2) => new ModInt(mint1.X - mint2.X);
    public static ModInt operator *(ModInt mint1, ModInt mint2) => new ModInt(mint1.X * mint2.X);
    public static ModInt operator /(ModInt mint1, ModInt mint2) => mint1 * Inv(mint2);

    public static ModInt Pow(ModInt mint, long t)
    {
        if (t == 0)
            return new ModInt(1);

        var a = Pow(mint, t >> 1);
        a *= a;

        if (t % 2 == 1)
            a *= mint;

        return a;
    }

    public static ModInt Inv(ModInt mint) => Pow(mint, Mod - 2);

    public override string ToString() => X.ToString();
}


Measured memory_bytes: 28216
X,K,D=map(int, input().split())

if 0<abs(X)<K*D:
  a=X//D
  K-=a
  if K%2==0:
    ans=X-D*a
  else:
    ans=X-D*(a+1)

else:
  ans=abs(X)-K*D
    
print(abs(ans))

Measured memory_bytes: 9184
#include<iostream>
#include<algorithm>
#include<cmath>

using namespace std;

int main(void){
	std::ios_base::sync_with_stdio();
	int t,y,n;
	int data[3];
	double ja;
	int nn;
	int iri;

	while(cin>>t>>y>>n){
		if(t==0&&y==0&&n==0) break;
		data[0]=t,data[1]=y,data[2]=n;
		sort(data,data+3);
		ja=sqrt((data[1]*data[1])+(data[0]*data[0]));
		cin>>nn;
		for(int i=0;i<nn;i++){
			cin>>iri;
			if(2*iri>ja) cout<<"OK"<<endl;
			else cout<<"NA"<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1172
#include "bits/stdc++.h"

using namespace std;
typedef long long int ll;
typedef pair<ll, ll > pi;  
typedef pair<pair<ll, ll >, ll > pii;  
vector<ll > vec;
vector<vector<ll > > vec2;
ll MOD = 1000000007;
ll INF = 11451419194545;


int main() 
{ 

    ll N;
    cin >> N;
    vector<pi > C(N);

    for(ll i = 0; i < N; i++){
        ll c, r; cin >> c >> r;
        C[i].first = c;
        C[i].second = r;
    }
    
    sort(C.begin(), C.end());

    vector<pi > CC(N);
    for(ll i = 0; i < N; i++){
        CC[i].first  = C[i].first + C[i].second;
        CC[i].second = C[i].first - C[i].second;
    }

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

    ll ans = 0;
    ll mn = -INF; 
    for(ll i = 0; i < N; i++){
        if(mn <= CC[i].second){
            mn = CC[i].first;
            ans++;
        }
    }
    
    cout << ans << endl;
    return 0; 
} 

Measured memory_bytes: 3328
#include<bits/stdc++.h>
#define ll long long
#define inf 1000000000
#define infll 1000000000000000000ll
#define vi vector<int>
#define vll vector<ll>
#define pb push_back
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pdd pair<double,double>
#define mpr make_pair
#define fi first
#define se second
#define pq priority_queue<int>
#define pqll priority_queue<ll>
#define up(x,y) (x<(y)?x=(y):0)
#define dn(x,y) (x>(y)?x=(y):0)
#define ad(x,y) (x=(x+(y))%mod)
using namespace std;

int read(){
	int x=0; char ch=getchar(); bool flag=0;
	while (ch<'0' || ch>'9'){ if (ch=='-') flag=1; ch=getchar(); }
	while (ch>='0' && ch<='9'){ x=x*10+ch-'0'; ch=getchar(); }
	return flag?-x:x;
}
ll readll(){
	ll x=0; char ch=getchar(); bool flag=0;
	while (ch<'0' || ch>'9'){ if (ch=='-') flag=1; ch=getchar(); }
	while (ch>='0' && ch<='9'){ x=x*10+ch-'0'; ch=getchar(); }
	return flag?-x:x;
}
int main(){
	ll n,m;
	scanf("%lld%lld",&n,&m);
	int i; ll m0=m,ans=1;
	for (i=2; (ll)i*i<=m0; i++) if (!(m%i)){
		int tmp=0;
		for (; !(m%i); m/=i) tmp++;
		for (tmp/=n; tmp; tmp--) ans*=i;
	}
	if (m && n==1) ans*=m;
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
import sys

YES = "Yes"  # type: str
NO = "No"  # type: str


def solve(H: int, N: int, A: "List[int]"):
    if H <= sum(A):
        print(YES)
    else:
        print(NO)


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    H = int(next(tokens))  # type: int
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(H, N, A)

if __name__ == '__main__':
    main()


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

int main() {
  vector<int> v(3);
  v.at(0)=1;
  v.at(1)=2;
  v.at(2)=3;
 int A , B;
  cin >> A >> B ;
  if ((A == 1)||(B==1)){
    v.at(0)=0;
  }
   if ((A == 2)||(B==2)){
    v.at(1)=0;
   }
  if ((A == 3)||(B==3)){
    v.at(2)=0;
  }
  cout << v.at(0)+ v.at(2)+ v.at(1);
    
  
}


Measured memory_bytes: 256
#include <stdio.h>

int s;

int pattern_search(int now, int add, int n)
{
	int pattern = 0;
	int i;
	
	if (n == 0){
		if (now == s) return (1);
		return (0);
	}
	
	if (n > 0 && now >= s) return (0);
	
	for (i = add + 1; i <= 9; i++){
		if (now + i <= s) pattern += pattern_search(now + i, i, n - 1);
	}
	
	return (pattern);
}

int main(void)
{
	int n;
	int i;
	int ans;
	
	while (1){
		scanf("%d %d", &n, &s);
		
		if (n == 0 && s == 0){
			break;
		}
		
		for (i = 0, ans = 0; i <= 8; i++){
			ans += pattern_search(i, i, n - 1);
		}
		
		printf("%d\n", ans);
	}
	
	return (0);
}

Measured memory_bytes: 0
/*DavitMarg*/
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <cstring>
#include <map>
#include <set>
#include <queue>
#include <iomanip>
#include <stack>
#include <cassert>
#include <iterator>
#include <ctype.h>
#include <fstream>
#include <unordered_map>
#define mod 1000000007ll
#define LL long long
#define LD long double
#define MP make_pair
#define PB push_back
#define all(v) v.begin(),v.end()
using namespace std;
int n;
LL w, v,W,dp[200005],ans;
int main()
{
	cin >> n >> W;
	for (int i = 0; i <= 200000; i++)
		dp[i] = mod * mod;
	dp[0] = 0;
	while (n--)
	{
		cin >> w >> v;
		for (int j = 100000; j >= 0; j--)
			dp[j + v] = min(dp[j + v], dp[j] + w);
	}

	for (int i = 0; i <= 200000; i++)
		if (dp[i] <= W)
			ans = max(ans,(LL)i);
	cout << ans << endl;
	return 0;
}

/*



*/

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
 
#define 	pi 				      3.14159265358979
#define 	mod 			      1000000007
#define 	ll  			      long long
#define 	rep(i, a, b) 	  for(ll i = a ; i < b ; i++)
#define   repn(i, a, b)   for(ll i = a ; i > b ; i--)
#define 	mod1 			      1000003
#define   mod2            998244353
#define   inf             2e18
#define 	hi   			      "hello"
#define 	nl 				      "\n"
#define 	ws 				      " "
#define 	ff 				      first
#define 	ss 				      second
#define 	pb 				      push_back
#define 	MP				      make_pair
#define 	B 				      begin()
#define   RB              rbegin()
#define 	E 				      end()
#define   UB              upper_bound
#define   LB              lower_bound
#define   present(k, m)   (m.find(k)!=m.end())?1:0
#define 	all(v) 			    v.begin(), v.end()
#define 	reset(a, val) 	memset(a, val, sizeof(a))
#define   pll             pair<ll, ll>
#define   vll             vector<ll>
#define   vpll            vector<pll>
#define 	vs 				      vector<string>
#define   vc              vector<char>
#define   sqr(a)          ((a)*(a))
#define 	print1(a) 		  for(auto i : a)cout<<i<<" ";cout<<"\n"
#define 	print2(a) 		  for(auto i : a)cout<<i;cout<<"\n"
#define 	print3(a) 		for(auto i : a)cout<<i<<nl;
#define 	boost 			ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)

// ostringstream str1;
// str1 << n;
// string tmp = str1.str();
bool sortbysec(const pair<int, int> &a, const pair<int, int> &b) { return (a.second < b.second); }
 
bool compare(const pair<string, int>&a, const pair<string, int>&b){ return a.second<b.second; }
 
double logn(double n, double r) { return (n > r - 1) ? 1 + logn(n / r, r) : 0; }
 
vll pwx(10);
void cal(ll x){ pwx[0] = 1; rep(i, 1, 10)pwx[i] = x*pwx[i-1]; }
 
/* ################################################################ */

#define space 200005

void solve() {
    ll a, b, c, d;
    cin >> a >> b >> c >> d;

    cout << max({b*d,a*c,b*c,a*d}) << nl;
}

int main(){
    boost;
    // cal(3);

    // // For getting input from input.txt file 
    // freopen("alchemy_input.txt", "r", stdin); 
  
    // // Printing the Output to output.txt file 
    // freopen("output.txt", "w", stdout);

    int t = 1, k = 1;
    // cin>>t;
    while(t--){
        // cout<<"Case #"<<k<<": ";
        solve();
        k++;
    }
}


Measured memory_bytes: 3588