akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <utility>
#include <memory.h>
#include <algorithm>
#include <cassert>
#include <bitset>

#define forn(i, n) for (int i = 0; i < int(n); ++i)
#define ford(i, n) for (int i = int(n) - 1; i >= 0; --i)
#define all(c) (c).begin(), (c).end()
#define sz(c) int((c).size())
#define mp(x, y) make_pair(x, y)
#define pb(x) push_back(x)
#define fst first
#define snd second

using namespace std;

using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vi>;
using ull = unsigned long long;

#define FNAME "a"

#ifdef LOCAL
#define eprintf(args...) fprintf(stderr, args), fflush(stderr);
#else
#define eprintf(args...) ;
#endif

int n;
vi a;
vi b;

bool read() {
    if  (!(cin >> n)) {
        return 0;
    }
    a.resize(n);
    b.resize(n);
    forn(i, n) {
        cin >> a[i];
    }
    forn(i, n) {
        cin >> b[i];
    }
    return 1;
}

const int MAX = 50;

bool bit(ull mask, int i) {
    return (mask >> i) & 1;
}

bool can(int from, int to, ull mask) {
    bitset<MAX + 1> dp;
    dp[from] = 1;
    for (int k = MAX; k >= 1; --k) {
        if  (!bit(mask, k)) {
            continue;
        }
        for (int val = MAX; val >= to; --val) {
            if  (dp[val]) {
                dp[val % k] = 1;
            }
        }
    }
    return dp[to];
}

bool can(ull mask) {
    forn(i, n) {
        if  (!can(a[i], b[i], mask)) {
            return 0;
        }
    }
    return 1;
}

ull go(ull have) {
    if  (can(have)) {
        return have;
    }
    forn(i, MAX + 1) {
        assert(!bit(have, i));

        ull cand = have;
        forn(j, i + 1) {
            cand ^= 1ull << j;
        }
        if  (can(cand)) {
            have ^= 1ull << i;
            return go(have);
        }
    }
    return -1;
}

void solve() {
    ull ans = go(1ull << (MAX + 1));

    if  (ans == -1) {
        cout << -1 << endl;
        return;
    }

    ull cost = 0;
    for (int k = 1; k <= MAX; ++k) {
        if  (bit(ans, k)) {
            cost += 1ull << k;
        }
    }

    cout << cost << endl;
}

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

#ifdef LOCAL
    freopen(FNAME ".in", "r", stdin);
    freopen(FNAME ".out", "w", stdout);
#endif

    while (read()) {
        solve();
    }

    return 0;
}


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

using i8  = int8_t;   /* -128 ~ 127 */
using u8  = uint8_t;  /* 0 ~ 255 */
using i16 = int16_t;  /* -32,768 ~ 32,767 */
using u16 = uint16_t; /* 0 ~ 65,535 */
using i32 = int32_t;  /* -2,147,483,648 ~ 2,147,483,647 */
using u32 = uint32_t; /* 0 ~ 4,294,967,295 */
using i64 = int64_t;  /* -9,223,372,036,854,775,808 ~ 9,223,372,036,854,775,807 */
using u64 = uint64_t; /* 0 ~ 18,446,744,073,709,551,615 */
using f32 = float;    /* (-3.4 * 10^38) ~ (3.4 * 10^38) */
using f64 = double;   /* (-1.7 * 10^308) ~ (1.7 * 10^308) */
using f80 = __float80;
template <class T> using Vec = vector<T>;
constexpr i64 INF = 1010000000000000017;
constexpr i64 MOD = 1e9 + 7;
constexpr f64 EPS = 1e-12;
constexpr f64 PI = 3.14159265358979323846;
#define ALL(v) v.begin(), v.end()
#define YN(a, b, c) ((c)? a : b)
#define GCD(a, b) __gcd(a, b) /* 最大公約数 */
#define LCM(a, b) (i64)(a / (f64)__gcd(a, b) * b) /* 最小公倍数 */

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

void Main() {
    i64 N, X;
    cin >> N >> X;
    Vec<i64> x;
    x.push_back(X);
    for (i64 i = 0; i < N; i++) {
        i64 t; cin >> t;
        x.push_back(t);
    }
    sort(ALL(x));
    i64 max_v = x[1] - x[0];
    for (i64 i = 1; i < x.size() - 1; i++) {
        max_v = GCD(max_v, x[i + 1] - x[i]);
    }
    cout << max_v << endl;
}


Measured memory_bytes: 4276
import java.util.*;

public class Main {
	public static void main(String[] args) throws Exception{
		Scanner scn = new Scanner(System.in);
		int n = scn.nextInt();
      	int m = scn.nextInt();
		int[][] a = new int[n][2];
		for(int i=0; i<n; i++){
          for(int j=0; j<2; j++){
			a[i][j] = scn.nextInt();
          }
		}
      	int[][] c = new int[m][2];
		for(int i=0; i<m; i++){
          for(int j=0; j<2; j++){
			c[i][j] = scn.nextInt();
          }
		}
      	for(int i=0; i<n; i++) {
    		int min = Integer.MAX_VALUE;
    		int min2 = 0;
    		for(int j=0; j<m; j++) {
      			int x =  Math.abs(a[i][0]-c[j][0])+Math.abs(a[i][1]-c[j][1]);
      			if(x<min) {
        			min = x;
        			min2 = j;
      			}
    		}
    		System.out.println(min2 + 1);
        }
	}
}


Measured memory_bytes: 35984
#include<iostream>
#include<string>
#include<math.h>
using namespace std;

int main() {
	char S[20];
	string T;
	string p;
	string Q;
	double m;
	int a = 0;
	int A = 0;
	int b = 0;
	int B = 0;
	int c = 0;
	int C = 0;
	int q, w, z;
	int n = 0;
	int x = 0;
	int y = 0;
	int ans = 0;
	int X[100] = { 0 };
	cin >> x;
	if (x == 3 || x == 5 || x == 7) {
		cout << "YES";
	}
	else {
		cout << "NO";
	}
}

Measured memory_bytes: 256
// #pragma GCC target("avx")  // CPU 処理並列化
// #pragma GCC optimize("O3")  // CPU 処理並列化
// #pragma GCC optimize("unroll-loops")  // 条件処理の呼び出しを減らす
// #define BEGIN_STACK_EXTEND(size) void * stack_extend_memory_ = malloc(size);void * stack_extend_origin_memory_;char * stack_extend_dummy_memory_ = (char*)alloca((1+(int)(((long long)stack_extend_memory_)&127))*16);*stack_extend_dummy_memory_ = 0;asm volatile("mov %%rsp, %%rbx\nmov %%rax, %%rsp":"=b"(stack_extend_origin_memory_):"a"((char*)stack_extend_memory_+(size)-1024));
// #define END_STACK_EXTEND asm volatile("mov %%rax, %%rsp"::"a"(stack_extend_origin_memory_));free(stack_extend_memory_);

#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
#include<numeric>
#include<unordered_set>
#include<unordered_map>
#include<complex>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const double EPS=1e-11;
const double INF=1e+10;
const double PI=acos(-1.0);
const int C_SIZE = 11100000;
const int UF_SIZE = 3100000;
namespace{
	long long fact[C_SIZE];
	long long finv[C_SIZE];
	long long inv[C_SIZE];
	inline long long Comb(int a,int b){
	 	if(a<b||b<0)return 0;
	 	return fact[a]*finv[b]%mod*finv[a-b]%mod;
	}
	void init_C(int n){
		fact[0]=finv[0]=inv[1]=1;
		for(int i=2;i<n;i++){
			inv[i]=(mod-(mod/i)*inv[mod%i]%mod)%mod;
		}
		for(int i=1;i<n;i++){
			fact[i]=fact[i-1]*i%mod;
			finv[i]=finv[i-1]*inv[i]%mod;
		}
	}
	long long pw(long long a,long long b){
		if(a<0LL)return 0;
		if(b<0LL)return 0;
		long long ret=1;
		while(b){
			if(b%2)ret=ret*a%mod;
			a=a*a%mod;
			b/=2;
		}
		return ret;
	}
	long long pw_mod(long long a,long long b,long long M){
		if(a<0LL)return 0;
		if(b<0LL)return 0;
		long long ret=1;
		while(b){
			if(b%2)ret=ret*a%M;
			a=a*a%M;
			b/=2;
		}
		return ret;
	}
	int pw_mod_int(int a,int b,int M){
		if(a<0)return 0;
		if(b<0)return 0;
		int ret=1;
		while(b){
			if(b%2)ret=(long long)ret*a%M;
			a=(long long)a*a%M;
			b/=2;
		}
		return ret;
	}
	int ABS(int a){return max(a,-a);}
	long long ABS(long long a){return max(a,-a);}
	double ABS(double a){return max(a,-a);}
	int sig(double r) { return (r < -EPS) ? -1 : (r > +EPS) ? +1 : 0; }
	int UF[UF_SIZE];
	void init_UF(int n){
		for(int i=0;i<n;i++)UF[i]=-1;
	}
	int FIND(int a){
		if(UF[a]<0)return a;
		return UF[a]=FIND(UF[a]);
	}
	void UNION(int a,int b){
		a=FIND(a);b=FIND(b);if(a==b)return;
		if(UF[a]>UF[b])swap(a,b);
		UF[a]+=UF[b];UF[b]=a;
	}
}
// ここから編集しろ

int main(){
	int a,b,c,d;scanf("%d%d%d%d",&a,&b,&c,&d);
	while(a>=b){
		b*=2;d--;
	}
	while(b>=c){
		c*=2;d--;
	}
	if(d<0)printf("No\n");
	else printf("Yes\n");
}

Measured memory_bytes: 1628
n = int(input())
xy_li = [list(map(int,input().split())) for _ in range(n)]
from itertools import permutations
import math
def distance(a,b):
    return math.sqrt((a[0]-b[0])**2+(a[1]-b[1])**2)
ans = 0
cnt = 0
i_li = [i for i in range(n)]
for x in permutations(i_li,n):
    cnt += 1
    for i in range(n-1):
        ans += distance(xy_li[x[i]],xy_li[x[i+1]])
        
print(ans/cnt)

Measured memory_bytes: 3064
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
#define ROF(i,a,b) for(ll i=a;i>=b;i--)
#define per(i,a) ROF(i,a,0)
#define pb push_back
using namespace std;
using ll=long long;
using ld=long double;
using ch=char;
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<P> vP;
typedef vector<ch> vc;
typedef vector<vc> vvc;
const ll MOD=1000000007;
const ll MOD2=998244353;
const ld PI=acos(-1);
const ll INF=1e18;
struct edge{ll to,cost;};
struct edge2{ll from,to,cost;};

template <typename T>
bool chmax(T &a, const T& b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

template <typename T>
bool chmin(T &a, const T& b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    vl x(n);
    rep(i,n){
        cin >> x[i];
    }
    vl y;
    y=x;
    sort(x.begin(),x.end());
    ll big=x[n/2],small=x[n/2-1];
    rep(i,n){
        if(big<=y[i]){
            cout << small << endl;
        }
        else{
            cout << big << endl;
        }
    }
}

Measured memory_bytes: 6344
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
void Say(bool say, string a = "Yes", string b = "No"){cout << (say ? a : b) << endl;};

int main(){

    ll N;
    cin >> N;
    double sum = 0;
    for(ll i = 1; i <= N; i++){
        double a;
        cin >> a;
        sum += 1 / a;
    }
    printf("%.9f\n", 1 / sum);

    return 0;
}

Measured memory_bytes: 256
a = input()
v = 0
h = 0
if a.count('W') >=1:
  if a.count('E') ==0:
    print('No')
    exit()
if a.count('E') >=1:
  if a.count('W') ==0:
    print('No')
    exit()
if a.count('N')>= 1:
  if a.count('S') ==0:
    print('No')
    exit()
if a.count('S')>= 1:
  if a.count('N')==0:
    print('No')
    exit()
print('Yes')


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define printInt(a) printf("%d\n", a)
#define scanInt(a) scanf("%d", &a)
using namespace std;

int main() {
    int a, b;
    scanf("%d %d", &a, &b);
    printInt(a*b);
    return 0;
}


Measured memory_bytes: 3780
#ifdef _MSC_VER
#include <__msvc_all_public_headers.hpp>
#undef min
#undef max
#else
#define NDEBUG
#include <bits/stdc++.h>
#endif

using namespace std;
using large = long long;

static int N;
static array<vector<int>, 200'005> Pos;

static int solve() {
    int xmax = -1;
    int pos = 0;
    for (int x = 1; x <= N; ++x) {
        auto itr = upper_bound(Pos[x].begin(), Pos[x].end(), pos);
        if (itr == Pos[x].end())
            break;
        xmax = x;
        pos = *itr;
    }
    return (xmax < 0 ? -1 : N - xmax);
}

int main() {
    cin >> N;
    for (int i = 1; i <= N; ++i) {
        int Ai;
        cin >> Ai;
        Pos[Ai].push_back(i);
    }

    cout << solve() << endl;
    return 0;
}


Measured memory_bytes: 14536
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#include <functional>
#include <numeric>
#include <iomanip>
#define fi first
#define se second
#define fcout(n) cout<<fixed<<setprecision((n))
#define cinl(str) getline(cin,(str))
using namespace std;
bool value(int y,int x,int R,int C){return 0<=y&&y<R&&0<=x&&x<C;}
typedef pair<int,int> pii;
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long > vll;
typedef vector< vi > vvi;
double pie=acos(-1);
int INF=1000000007;
int dx[4] = { 0,-1,0,1 };
int dy[4] = { -1,0,1,0 };


int main() {
	int n,m,p;
	int x[105];
	long long ans=0;
	while(true){
		cin>>n>>m>>p;
		if(n+m+p==0) return 0;
		ans=0;
		//cout<<ans<<" "<<n<<" "<<m<<" "<<" "<<p<<endl;
		for(int i=0;i<n;i++){
			cin>>x[i];
			ans+=x[i]*100;
		}
		for(int i=0;i<n;i++){
			if(i+1==m){
				if(x[i]!=0){
					ans=ans/100;
					ans=ans*(100-p);
					ans=ans/x[i];
					break;
				}
				else{
					ans=0;
					break;
				}
			}
		}
		cout<<ans<<endl;


	}
}

Measured memory_bytes: 2976
#include<bits/stdc++.h>
using namespace std;
#define mx 1000000000000000000
#define ll long long int
ll len(ll a)
{
    ll count=0 ,i;
    while(a!=0)
    {
        a/=10;
        count++;
    }
    return count;
}
int main()
{
   string s,t,b;
  // char s[210],t[210],b[210];
   ll i,j,count=0,lens,lent;
   cin>> s >> t;
   //if(s.size()>=t.size()-1)

       b = t.substr(0,t.size()-1);
   //}
  // cout << b << endl;
   for(i=0;i<=b.size();i++)
   {
       if(s[i]==b[i])
        count=0;
       else
       {
           count = 1;
           break;
       }
   }
   if(count==0)
    cout << "Yes" << endl;
   else
    cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 3604
import java.util.*;
public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.next());
        double[] listx = new double[N];
        double[] listy = new double[N];
        for (int i = 0; i<N; i++){
            listx[i] = Double.parseDouble(sc.next());
            listy[i] = Double.parseDouble(sc.next());
        }
        int numLine = 0;
        if((N-1)%2==0){
            numLine = (N)*(N-1)/2;
        }else{
            numLine = (N)*(N-1)/2+N/2;
        }

        double[] dist = new double[numLine];
        int count = 0;
        double distance = 0.0;
        for(int i = 0; i<N; i++){
            for(int j = i+1; j<N;j++){
                dist[count] = Math.sqrt(Math.pow(listx[i]-listx[j],2)+Math.pow(listy[i]-listy[j],2));
                distance += dist[count];
                count ++;
            }
        }
        System.out.println(distance*2/N);
    }
}


Measured memory_bytes: 22996
#include <iostream>
#include <vector>
#include <unordered_set>
#include <algorithm>

using namespace std;

template <int base>
int digit_sum(int n)
{
	int sum = 0;
	while (n > 0) {
		sum += n % base;
		n /= base;
	}
	return sum;
}

using ivec = vector<int>;

ivec read_int_args()
{
	int N;
	cin >> N;
	ivec v(N);
	for (auto& e : v) {
		cin >> e;
	}
	return v;
}

int compar(const void * b, const void* a)
{
	return (*(int*)a - *(int*)b );
}

int main()
{
	int N, M;
	cin >> N >> M;
	ivec A(N + M + 1);
	for (auto& e : A) {
		cin >> e;
	}

	auto begin = A.begin();
	auto end = begin;
	advance(end, N);
	make_heap(begin, end);
	
	for (int i = 0; i < M; i++) {
		*begin /= 2;
		pop_heap(begin, end);
		push_heap(begin, end);
	}
	size_t sum = 0;
	for (auto it = begin; it != end; it++) {
		sum += *it;
	}

	cout << sum << endl;

	return 0;
}


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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>bool chmin(T&a,const T&b){return a>b?(a=b,1):0;}
template<class T>bool chmax(T&a,const T&b){return a<b?(a=b,1):0;}


int nextInt() { int x; scanf("%d", &x); return x;}

int N;
bool query(ll n) {
  // return (n <= N) == (to_string(n) <= to_string(N));
  cout << "? " << n << endl;
  string res;
  cin >> res;
  return res[0] == 'Y';
}

bool answer(ll n) {
  cout << "! " << n << endl;
  // if (n != N) {cout << "wrong answer : N=" << N << " n=" << n << endl;}
  // return n == N;
  return true;
}

int main2() {

  ll lo = 10000000000LL;
  ll hi = 100000000000LL;
  while (hi - lo > 1) {
    ll mid = (hi + lo) / 2;
    if (query(mid)) {
      hi = mid;
    } else {
      lo = mid;
    }
  }
  ll n = hi;
  for (;;) {
    if (query(n - 1)) {
      break;
    }
    n /= 10;
  }
  if (n == 10000000001) {
    n = 9;
    for (;;) {
      if (query(n)) break;
      n = n * 10 + 9;
    }
    n = (n + 1) / 10;
  }
  answer(n);
  return 0;
}

int main() {
  // for (int i = 1; i <= 20000; i++) {
    // N = i;
    // main2();
  // }
  main2();
  return 0;
}



Measured memory_bytes: 596
def factorization(n):
    arr = []
    temp = n
    if n<2:
        return []
    for i in range(2, int(n**0.5)+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
                arr.append(i**cnt)
    if temp!=1:
        arr.append(temp)

    if arr==[]:
        arr.append(n)
    return arr

N = int(input())
arry = factorization(N)
ans = 0
for a in sorted(arry):
    if N%a==0:
        N //= a
        ans += 1
    if N<=1:
        break
print(ans)

Measured memory_bytes: 9480
import java.util.ArrayList;
import java.util.Collections;
import java.util.PriorityQueue;
import java.util.Scanner;

class Main{
	public static void main(String[] args) {
		ArrayList <PriorityQueue<Integer>> queues = new ArrayList <PriorityQueue<Integer>>();  //PriorityQueueのArrayListを生成
		try (Scanner sc = new Scanner (System.in)){
			int n = sc.nextInt();
			for (int i=0; i<n; i++) {
				queues.add(new PriorityQueue<Integer>(Collections.reverseOrder()));

			}
			int times = sc.nextInt();
			for (int i=0; i<times; i++) {
				int query = sc.nextInt();
				int que = sc.nextInt();
				switch (query) {
				//insert(t,x)
				case 0:
					int x = sc.nextInt();
					queues.get(que).add(x);
					break;
				case 1:
					if (queues.get(que).size() != 0) {
						System.out.println(queues.get(que).peek());
					}
					break;
				case 2:
					if (queues.get(que).size() != 0) {
						queues.get(que).poll();
					}
					break;

				}
			}
		}
	}
}



Measured memory_bytes: 168332
#include <iostream> // cin, cout, cerr
#include <algorithm> // minmax, sort, swap
#include <numeric> // iota
#include <cstdio> // printf, scanf
#include <string> // string, stoi, to_string
#include <vector> // vector
#include <queue> // queue, priority_queue
#include <deque> // deque
#include <map> // key-value pairs sorted by keys
#include <set> // set
#include <iomanip> // cout<<setprecision(n)
#include <functional> // function<void(int)>
#include <cmath>
#include <cassert>
#include <bitset>

#ifdef DEBUG
#include "debug.hpp"
#else
#define debug(...)
#endif

#define int long long // at least int64 > 9*10^18
#define EL '\n'
#define rep(i,n) for(int i = 0; i < (n); i++)
#define print(i) std::cout << (i) << '\n'
#define all(v) (v).begin(), (v).end()
using Graph = std::vector<std::vector<int> >;
const int INF = 1e17;
/* libraries */

signed main() {
	int n;
	std::cin >> n;
	std::vector<int> a(n);
	rep(i,n) std::cin >> a[i];
	// hope n*sqrt(n) will work
	int sn=1;
	{
		while(sn*sn<=n) sn++;
	}
	std::vector<std::vector<int> > dp(n,std::vector<int>(sn,0));
	for(int j=1;j<sn;j++) {
		for(int i=0;i<n;i+=j) {
			dp[i][j]=(i-j>=0) ? dp[i-j][j] : (int)0;
			dp[i][j]+=a[i]+a[n-i-1];
		}
	}
	debug(dp);
	int max=0;
	for(int i=2;i<n-1;i++) {
		int x=n-i-1;
		for(int xx=1;xx*xx<=x;xx++) {
			if(x%xx) continue;
			if(!(x>=i && (x-i)%xx==0) && xx<i) {
				max=std::max(max,dp[x][xx]);
			}
			int yy=x/xx;
			if(!(x>=i && (x-i)%yy==0) && yy<i) {
				int sum=0;
				for(int l=0;l<=x;l+=yy) sum+=a[l]+a[n-l-1];
				max=std::max(max,sum);
			}
		}
	}
	print(max);
	return 0;
}


Measured memory_bytes: 251904
inp = list(map(int,input().split()))
q = inp[0] #0.25
h = inp[1] #0.5
s = inp[2] #1
d = inp[3] #2
n = int(input())
q *= 4
h *= 2
num = min(q,h,s) 
if n >= 2:
    N = n // 2
    total = min(2*num*N, d*N) + num*(n % 2)
else:
    total = n * num
print(total)


Measured memory_bytes: 3060
def read_int():
    return int(input())

def read_int_map():
    return map(int,input().split(' '))

def read_int_list():
    return list(map(int,input().split(' ')))

def read_s_list_loop(n):
    return [input() for _ in range(n)]

N,M = read_int_map()
Hn = read_int_list()
tree_list = [[] for i in range(N)]
for _ in range(M):
    A,B = read_int_map()
    A -= 1
    B -= 1
    tree_list[A].append(B)
    tree_list[B].append(A)
ans = 0
for i in range(len(tree_list)):
    depend = tree_list[i]
    base_high = Hn[i]
    flag = True
    for i2 in depend:
        compare_high = Hn[i2]
        if base_high <= compare_high:
            flag = False
            break
    if flag:
        ans += 1
print(ans)

Measured memory_bytes: 91924
#include <bits/stdc++.h>
#include <ext/rope>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define ll long long
//#define int long long
#define pb push_back
#define x first
#define ld long double
#define y second
#define mk(a,b) make_pair(a,b)
#define rr return 0
#define sqr(a) ((a)*(a))
#define all(a) a.begin(),a.end()

using namespace std;
using namespace __gnu_cxx;
using namespace __gnu_pbds;
template<class value, class cmp = less<value> >
using ordered_set = tree<value, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
template<class value, class cmp = less_equal<value> >
using ordered_multiset = tree<value, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
template<class key, class value, class cmp = less<key> >
using ordered_map = tree<key, value, cmp, rb_tree_tag, tree_order_statistics_node_update>;

/// find_by_order()
/// order_of_key()
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
inline int randll(int l = INT_MIN, int r = INT_MAX) {
    return uniform_int_distribution<int>(l, r)(rng);
}
map <int, map <int, int> > cnt;
main()
{
    ios::sync_with_stdio(0);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int h, w, n;
    cin >> h >> w >> n;
    vector <ll> ans (10);
    vector <pair<int, int> > a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i].x >> a[i].y;
        for (int j = 0; j <= 2; j++) {
            for (int k = 0; k <= 2; k++) {
                if (a[i].x - j > 0 && a[i].y - k > 0 && a[i].x - j + 2 <= h && a[i].y - k + 2 <= w) ++cnt[a[i].x - j][a[i].y - k];
            }
        }
    }
    for (auto &i : cnt) {
        for (auto &j : i.y) {
            ++ans[j.y];
        }
    }
    ll sum = (h - 2ll) * (w - 2ll);
    for (int i = 1; i < 10; i++) sum -= ans[i];
    ans[0] = sum;
    for (int i = 0; i < 10; i++) cout << ans[i] << '\n';
}


Measured memory_bytes: 71296
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v).begin(), (v).end()
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define DEBUG
#define int long long
#define INF 1e9
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }
template<class T>void show(vector<T>v){for (int i = 0; i < v.size(); i++){cerr<<v[i]<<" ";}cerr<<"\n";}
typedef long long ll;

signed main(){
    int n,m,k;
    cin >> n >> m >> k;
    for (int i = 0; i <= n; i++)
    {
        for (int j = 0; j <= m; j++)
        {
            int x=i;
            int y=n-i;
            int z=j;
            int w=m-j;
            if(x*z+y*w==k) {
                cout<<"Yes"<<endl;
                return 0;
            }
        }
    }
    cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <algorithm>
using namespace std;
int main(){
  int N,V,P;
  long long M;
  cin>>N>>M>>V>>P;
  long long A[100000],emp[100000];
  for(int i=0;i<N;i++) cin>>A[i];
  sort(A,A+N);
  emp[N-P]=0;
  for(int i=N-P-1;i>=0;i--){
    emp[i]=A[N-P]-A[i];
    emp[i]+=emp[i+1];
  }
  int answer=P;
  for(int i=0;i<N-P;i++){
    if(A[N-P]-A[i]<=M){
      long long a=A[i]+M;
      long long vote=(V-P-i)*M;
      if(emp[i+1]+(N-P-i)*(a-A[N-P])>=vote){
        answer=N-i;
        break;
      }
    }
  }
  cout<<answer<<endl;
  
  return 0;
}

Measured memory_bytes: 4680
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int x,y,a,b,c;cin>>x>>y>>a>>b>>c;
	int t1[a];for(int &i:t1) cin>>i; sort(t1,t1+a,greater<int>());
	int t2[b];for(int &i:t2) cin>>i; sort(t2,t2+b,greater<int>());
	int t3[c];for(int &i:t3) cin>>i; sort(t3,t3+c,greater<int>());
	vector<int> v;
	for(int i=0;i<x;i++) v.push_back(t1[i]);
	for(int i=0;i<y;i++) v.push_back(t2[i]);
	for(int i=0;i<c;i++) v.push_back(t3[i]);
	sort(v.begin(),v.end(),greater<int>());
	cout<<accumulate(v.begin(),v.begin()+x+y,0LL);
	return 0;
}

Measured memory_bytes: 3572
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,m;
  cin >> n >> m;
  int i;
  vector<int> ans(m+1);
  for(i=0;i<n;i++){
    int k;
    cin >> k;
    vector<int> vec(k);
    for(int j=0;j<k;j++){
       cin >> vec.at(j);
      ans.at(vec.at(j))++;
    }
  }
  int b=0;
  for(i=1;i<m+1;i++){
    if(ans.at(i)==n){
      b++;
    }
  }
  cout << b;
}

Measured memory_bytes: 256
n = gets.to_i
a,b = gets.split.map(&:to_i)
pt = gets.split.map(&:to_i)
list=[[],[],[]]
pt.each do |v|
  if v <= a
    list[0] << v
  elsif v <= b
    list[1] << v
  else
    list[2] << v
  end
end
cnt = []
list.each do |arr|
  cnt << arr.length
end
p cnt.min

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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define fore(i,x,n) for(int i=x;i<n;i++)
#define all(a) a.begin(),a.end()
#define pb push_back
#define ordenar(a) sort(all(a))
typedef long long ll;
typedef vector<int> vi;

string a;
set<char> b;

int main(){
    IOS

    cin>>a;

    for(auto it : a){
        b.insert(it);
    }

    if(b.size() == 2) cout<<"Yes";
    else cout<<"No";

    return 0;
}

Measured memory_bytes: 3632
using System;
using System.Collections.Generic;
using System.Collections;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.IO;
using System.Reflection;
using static System.Math;
using System.Numerics;
static class Program{
	const int mod=(int)1e9+7;
	const double eps=1e-11;
	static void Main(){
		Sc sc=new Sc();
		var s=sc.Ia;
		for(int i = 0;i<=s[0];i++) {
			if(i*2+(s[0]-i)*4==s[1]){
				Console.WriteLine("Yes");
				return;
			}
		}
		Console.WriteLine("No");
	}
}
public class Sc{
	public int I{get{return int.Parse(Console.ReadLine());}}
	public long L{get{return long.Parse(Console.ReadLine());}}
	public double D{get{return double.Parse(Console.ReadLine());}}
	public string S{get{return Console.ReadLine();}}
	public int[] Ia{get{return Array.ConvertAll(Console.ReadLine().Split(),int.Parse);}}
	public long[] La{get{return Array.ConvertAll(Console.ReadLine().Split(),long.Parse);}}
	public double[] Da{get{return Array.ConvertAll(Console.ReadLine().Split(),double.Parse);}}
	public string[] Sa{get{return Console.ReadLine().Split();}}
	public object[] Oa{get{return Console.ReadLine().Split();}}
	public int[] Ia2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),int.Parse);}}
	public int[] Ia3(string a,string b){return Array.ConvertAll((a+Console.ReadLine()+b).Split(),int.Parse);}
	public long[] La2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),long.Parse);}}
	public long[] La3(string a,string b){return Array.ConvertAll((a+Console.ReadLine()+b).Split(),long.Parse);}
	public double[] Da2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),double.Parse);}}
	public double[] Da3(string a,string b){return Array.ConvertAll((a+Console.ReadLine()+b).Split(),double.Parse);}
	public T[] Arr<T>(int n,Func<T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f();}return a;}
	public T[] Arr<T>(int n,Func<int,T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i);}return a;}
	public T[] Arr<T>(int n,Func<string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(Console.ReadLine().Split());}return a;}
	public T[] Arr<T>(int n,Func<int,string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i,Console.ReadLine().Split());}return a;}
}

Measured memory_bytes: 27552
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int mod=1e9+7;
const int N=1e6+5;
int ksm(int b,int n){
	int res=1;
	while(n){
		if(n&1) res=res*b%mod;
		b=b*b%mod; n>>=1;
	}
	return res;
}
void add(int &x,int y){
	x=(x+y)%mod;
}
int fac[N],sum,f[N],s[N];
void init(int n){
	fac[0]=1;
	for(int i=1;i<=n;++i)
		fac[i]=fac[i-1]*i%mod,
		add(sum,fac[i]);
}
signed main(){
	int n,H,D;
	cin>>n>>H>>D;
	init(n);f[0]=1;s[0]=1;
	for(int i=1;i<=H;++i){
		f[i]=(s[i-1]+mod-((i-D>=1)?s[i-D-1]:0))%mod*sum%mod;
		s[i]=(s[i-1]+f[i])%mod;
	//	cout<<f[i]<<" "<<s[i]<<endl;
	}
	int ans=f[H]*fac[n]%mod*ksm(sum,mod-2)%mod;
	cout<<ans;
	return 0;
}

Measured memory_bytes: 27056
#include<iostream>
#include<cmath>
#include<iomanip>
#include<cstdio>
using namespace std;

double distance(double a, double b, double c, double d){
    double dx = c - a;
    double dy = d - b;
    double dis = std::pow(dx*dx + dy*dy, 0.5);
    return dis;
}

int main(){
    double x1, y1, x2, y2;
    std::cin >> x1 >> y1 >> x2 >> y2;
    
    double ans = distance(x1, y1, x2, y2);
    printf("%lf\n", ans);
}


Measured memory_bytes: 3388
class PQueue
  def initialize(data = [], &cmp)
    @data = [nil] + data.sort(&cmp)
    @cmp = cmp
  end
  def size; @data.size - 1; end
  def empty?; @data.size == 1; end
  def peek; empty? ? nil : @data[1]; end

  def push(el)
    j = @data.size
    @data << el
    while j > 1
      break if @cmp.call(@data[j / 2], @data[j]) < 0
      
      @data[j] = @data[j / 2]
      @data[j / 2] = el
      j /= 2
    end
    self
  end
  alias_method :<<, :push
  
  def shift
    return nil if empty?
    return @data.pop if size == 1
    
    el = @data[1]
    tail = @data.pop
    
    @data[1] = tail
    j = 1
    while 2 * j < @data.size
      i = 2 * j
      i += 1 if i + 1 < @data.size && @cmp.call(@data[i + 1], @data[i]) < 0

      break if @cmp.call(@data[j], @data[i]) < 0
      
      @data[j] = @data[i]
      @data[i] = tail
      j = i
    end
    return el
  end
end
# dp[s][c] : 駅sをコインc枚以上もって、出発するときの最小時間
# dp[v][j] = min{ dp[u][j + a] + b } (j >= 0)
def min(a,b); a < b ? a : b; end
INF = Float::INFINITY

N,M,S = gets.split.map(&:to_i)
dp = Array.new(N + 1){ Array.new(2520, INF) }

E = Array.new(M)
V = Array.new(N + 1)

M.times do |i|
  E[i] = gets.split.map(&:to_i)
end
(1 .. N).each do |i|
  V[i] = gets.split.map(&:to_i)
end

G = Array.new(N + 1){ [] }
E.each do |(u, v, a, b)|
  G[u] << [v, a, b]
  G[v] << [u, a, b]
end

q = PQueue.new{|a,b| [a[0],-a[1]] <=> [b[0],-b[1]] }
q << [0, min(S, 2500), 1]

until q.empty?
  t,w,v = q.shift
  c,d = V[v]

  next if t >= dp[v][w]
  w.downto(0) do |w_|
    if dp[v][w_] > t
      dp[v][w_] = t 
    else
      break
    end
  end
  
  G[v].each do |u,a,b|
    q << [t + b, w - a, u] if w >= a && dp[u][w - a] > t + b
  end
  q << [t + d, min(w + c, 2500), v] if dp[v][min(w + c, 2500)] > t + d
end
puts (2 .. N).map{|i| dp[i][0] }


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

typedef long long ll;
#define repd(i,a,b) for (ll i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)

ll mod=1e9+7;

using namespace std;


ll inputValue(){
	ll a;
	cin >> a;
	return a;
};

void inputArray(int * p, ll a){
	rep(i, a){
		cin >> p[i];
	}
};

template<typename T>
void inputVector(vector<T>& p, ll a){
	rep(i, a){
		T input;
		cin >> input;
		p.emplace_back(input);
	}
}


template <typename T>
void output(T a) {
    cout << a << "\n";
}

bool is_odd(ll n)
{
        ll digit=0;
        while(n!=0){
            n /= 10;
            digit++;
        }
    return digit%2;
}


int main(int argc, const char * argv[]) {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
	// source code
    ll n;
    cin >> n;

    ll cnt=0;
    ll tmp;
    
    while(n)
    {
        if(is_odd(n))
        {
            ++cnt;
        }
            --n;
               
    }

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


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define vlli vector<ll>
#define vi vector<int>
#define vs vector<string>
#define vplli vector< pair< ll,ll> >
#define plli pair< ll,ll >
#define vps vector< pair< string, string> >
#define vpi vector< pair< int, int> >
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define fast ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define forn(i,a,n) for(ll i=a;i<n;i++)
#define forr(i,n,a) for(ll i=n-1;i>=a;i--)
#define scan(arr,a,n) for(ll i=(a);i<(n);i++)cin>>(arr)[i];
#define print(arr,a,n) for(ll i=(a);i<(n);i++)cout<<(arr)[i]<<" ";

const ll inf = 1e18;

ll add(ll x, ll y) {ll res = x + y; return (res >= mod ? res - mod : res);}
ll mul(ll x, ll y) {ll res = x * y; return (res >= mod ? res % mod : res);}
ll sub(ll x, ll y) {ll res = x - y; return (res < 0 ? res + mod : res);}
ll power(ll x, ll y) {ll res = 1; x %= mod; while (y) {if (y & 1)res = mul(res, x); y >>= 1; x = mul(x, x);} return res;}
ll mod_inv(ll x) {return power(x, mod - 2);}


int main(){
    fast;
    #ifndef ONLINE_JUDGE
    freopen("input1.txt","r",stdin);
    freopen("output1.txt","w",stdout);
    #endif
    ld d, t, s;
    cin>>d>>t>>s;
    if(d/s > t){
        cout<<"No"<<endl;
    } else {
        cout<<"Yes"<<endl;
    }
}

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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

#define ld long double
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

/* Some Libraries */

//-------------------------------------------------

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int h,w; cin>>h>>w;
    vector<string> f(h);
    rep(i,h) cin>>f[i];
    int idx=0;
    while(idx<h){
        bool flg=true;
        rep(j,w)if(f[idx][j]=='#'){
            flg = false;
        }
        if (flg){
            f.erase(f.begin()+idx);
            h--;
        }else{
            idx++;
        }
    }
    idx = 0;
    while(idx<w){
        bool flg=true;
        rep(i,h)if(f[i][idx]=='#'){
            flg = false;
        }
        if (flg){
            rep(i,h) f[i].erase(f[i].begin()+idx);
            w--;
        }else{
            idx++;
        }
    }
    rep(i,h){
        rep(j,w) cout<<f[i][j];
        cout<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
class Adjmat
  
  def initialize(n=0, inf=9876543210)
    @n = n
    @inf = inf
    @mat = Array.new(n){ Array.new(n, inf ) }.each_with_index{|s,i| s[i] = 0 }
  end
  
  def add_edge(s,t,d=1)
    @mat[s][t] = d
    @mat[t][s] = d
  end
  
  def add_directed_edge(s,t,d=1)
    @mat[s][t] = d
  end
  
  def floyd_warshall!
    @n.times do |k|
      @n.times do |i|
        @n.times do |j|
          l = @mat[i][k]
          r = @mat[k][j]
          next if l == @inf || r == @inf
          nd = l + r
          @mat[i][j] = nd if @mat[i][j] > nd
        end
      end
    end
    @mat
  end
  
  def floyd_warshall
    res = @mat
    @n.times do |k|
      @n.times do |i|
        @n.times do |j|
          l = res[i][k]
          r = res[k][j]
          next if l == @inf || r == @inf
          res[i][j] = l + r if res[i][j] > l + r
        end
      end
    end
    res
  end
  
  def negative_cycle?
    @n.times{ |i| return true if @mat[i][i] < 0}
    false
  end
  
  def out
    @n.times do |i|
      @n.times do |j|
        print @mat[i][j] == @inf ? "INF" : @mat[i][j]
        print j != @n-1 ? " " : "\n"
      end
    end
  end
end

n, m = gets.to_s.split.map{|t| t.to_i }

a = Adjmat.new(n)

edges = Array.new(m){ gets.to_s.split.map{|t| t.to_i } }

edges.each do |e|
  s = e[0] - 1
  t = e[1] - 1
  c = e[2]
  a.add_edge(s,t,c)
end

a = a.floyd_warshall

ans = 0
edges.each do |e|
  s = e[0] - 1
  t = e[1] - 1
  c = e[2]
  ok = true
  n.times do |i|
    n.times do |j|
      if a[i][j] == a[i][s] + c + a[t][j]
        ok = false
        break
      end
    end
  end
  ans += 1 if ok
end

puts ans

Measured memory_bytes: 2172
#include <algorithm>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <set>
#include <string>
#include <vector>
#define rep(i, x, n) for(int i = x; i < n; i++)
using namespace std;
const long long INF = 1LL << 60;
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;
}
const int MOD = 1000000007;
int rui(int a, int b) {
    if(b == 0) {
        return 1;
    }
    return rui(a, b - 1) * a;
}
int main() {
    long long H, W;
    cin >> H >> W;
    if(H == 1 || W == 1) {
        cout << 1 << endl;
        return 0;
    }
    if(H % 2 == 0) {
        cout << H / 2 * W << endl;
    } else {
        if(W % 2 == 0) {
            cout << W / 2 * H << endl;
        } else {
            cout << ((H - 1) / 2 * W) + W / 2 + 1 << endl;
        }
    }
}

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

int main() {
	int counter = 0;
	int ans = 0;
	bool rain = false;
	string S;
	cin >> S;

	for(int i = 0;i < S.size();++i) {
		if(i != 0) {
			if(S.at(i) == 'R' && S.at(i - 1) == 'R')
				counter++;
		}

		if(S.at(i) == 'S') {
			ans = max(ans,counter);
			counter = 0;
		}

		ans = max(ans,counter);
		if(S.at(i) == 'R') rain = true;
	}
		if(rain)
			ans++;
		cout << ans << endl;

}


Measured memory_bytes: 3616
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <algorithm>
#include <cstdlib>
int n,m;
int a[10005],ans;
using namespace std;
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;i++)
	{
		scanf("%d",&a[i]);
		ans+=a[i];
	}
	if(ans<=n)
	{
		cout<<(n-ans);
	}
	else
	{
		cout<<"-1";
	}
	return 0;
}

Measured memory_bytes: 3840
class Fixnum
  def / o
    fdiv(o).to_i
  end
end
ps = {'+' => 1, '-' => 1, '*' => 2, '/' => 2}
gets.to_i
  .times
  .lazy
  .map{ gets.chomp }
  .map {|s| s.scan(/([+\-*\/()]|\d+)/).flatten }
  .map {|tokens|
    ops = []
    tokens.each_with_object([]) {|t, rpn|
      case t
      when /\d+/
        rpn << t
      when '('
        ops << t
      when ')'
        op = nil
        rpn << op until (op = ops.pop) == '('
      else
        p = ps[t]
        rpn << ops.pop until p > (ps[ops.last] || 0)
        ops << t
      end
    }.push(*ops.reverse)
  }
  .map {|rpn|
    rpn.reduce([]) {|s, t|
      case t
      when /\d+/
        s << t.to_i
      else
        r = s.pop
        l = s.pop
        s << l.send(t, r)
        s
      end
    }.first
  }
  .each(&method(:puts))

Measured memory_bytes: 6144
#include<stdio.h>
#include<string.h>
#include <stdlib.h>

int main(){
    int N,n;
    char S[10000],z='Z';
    
    scanf("%d %s",&N,S);
    for (int i=0; S[i]!='\0'; i++) {
        if (S[i]+N>'Z') {
            n='Z'-S[i];
            printf("%c",'A'+N-n-1);
        }
        else{
            printf("%c",S[i]+N);
        }
    }
    printf("\n");
    return 0;
}


Measured memory_bytes: 128
#include<stdio.h>
#include<stdio.h>

int main(void)
{
  int a,b,k,n;
  scanf("%d",&k);
  scanf("%d%d",&a,&b);
  n=k;
  while(n<=b)
    {
      if(n>=a && n<=b)
	{
	  printf("OK\n");
	  return 0;
	}
      n += k;
    }
  printf("NG\n");

  return 0;
}


Measured memory_bytes: 1664
/* Dynamic Programming implementation of LCS problem */
#include<bits/stdc++.h> 
using namespace std; 
vector<int>ar[100001];
vector<int>vis;
vector<int>dp;
void dfs(int v)
{
    vis[v]=1;
    for(int c:ar[v])
    {
        if(vis[c]==0)
        {
            dfs(c);
        }
        dp[v]=max(dp[v],1+dp[c]);
    }
}
int main()
{
    int n,m,i,a,b;
    cin>>n>>m;
    for(i=0;i<m;i++)
    {
        cin>>a>>b;
        ar[a].push_back(b);
    }
    vis.resize(n+1);
    dp.resize(n+1);
    for(i=0;i<n+1;i++)
    {
        vis[i]=0;
        dp[i]=0;
    }
    for(i=1;i<=n;i++)
    {
        if(vis[i]==0)
        {
            dfs(i);
        }
    }
    cout<<*max_element(dp.begin(),dp.end());
}

Measured memory_bytes: 11240
#include <bits/stdc++.h>
#define REP(i, s, n) for (int i = s; i < n; i++)
#define ALL(a) a.begin(), a.end()
#define MOD 1000000007
using namespace std;
typedef long long ll;

int main() {
    int W, H, N; cin >> W >> H >> N;
    int x0 = 0, y0 = 0, x1 = W, y1 = H;
    REP(i, 0, N) {
        int x, y, a; cin >> x >> y >> a;
        if (a == 1) x0 = max(x0, x);
        if (a == 2) x1 = min(x1, x);
        if (a == 3) y0 = max(y0, y);
        if (a == 4) y1 = min(y1, y);
    }

    if (y1 - y0 < 0 || x1 - x0 < 0) cout << 0 << endl;
    else cout << (y1 - y0) * (x1 - x0) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define ll long long
#define ld long double
#define all(a) (a).begin(),(a).end()
#define mk make_pair
int main(){
  ll a,b,c,k;
  cin>>a>>b>>c>>k;
 if(k<a) cout<<k<<endl;
 else if(a<=k&&k<=a+b) cout<<a<<endl;
 else if(a+b<k)  cout<<a-(k-a-b)<<endl;
return 0;
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++) 
#define all(x) (x).begin(), (x).end()
typedef long long ll;
using namespace std;

int main() {
	int N,K;
  string S;
	cin >> N >> K;
  cin >> S;
  S[K-1] = S[K-1] + 32;
  cout << S << endl;
}

Measured memory_bytes: 256
n, x = map(int, input().split())
a, p = [1], [1]
for i in range(n):
    a.append(a[i] * 2 + 3)
    p.append(p[i] * 2 + 1)

def f(n, x):
    if n == 0:
        return 0 if x <= 0 else 1
    elif x <= 1 + a[n - 1]:
        return f(n - 1, x - 1)
    else:
        return p[n - 1] + 1 + f(n - 1, x - 2 - a[n - 1])
print(f(n, x))


Measured memory_bytes: 3064
#include <algorithm>
    #include <bitset>
    #include <cctype>
    #include <cmath>
    #include <cstdio>
    #include <cstring>
    #include <deque>
    #include <fstream>
    #include <functional>
    #include <iostream>
    #include <limits>
    #include <map>
    #include <numeric>
    #include <queue>
    #include <set>
    #include <vector>
    using namespace std;
    using ll = long long;
    #define fst first
    #define snd second
     
    /* clang-format off */
    template <class T, size_t D> struct _vec { using type = vector<typename _vec<T, D - 1>::type>; };
    template <class T> struct _vec<T, 0> { using type = T; };
    template <class T, size_t D> using vec = typename _vec<T, D>::type;
    template <class T> vector<T> make_v(size_t size, const T& init) { return vector<T>(size, init); }
    template <class... Ts> auto make_v(size_t size, Ts... rest) { return vector<decltype(make_v(rest...))>(size, make_v(rest...)); }
    /* clang-format on */
     
    int N;
    vector<ll> A;
     
    ll dp[200010][20];
     
    int lg(ll A, int x, ll B) {
      for (int i = 0; i < x; i++) A *= 4;
      double dB = B;
      // A*4^x <= B*4^y
      for (int y = 0;; y++) {
        if (dB > A + 100 || A <= B) {
          return y;
        }
        dB *= 4;
        B *= 4;
      }
    }
     
    ll solve(int i, int x) {
      if (i == N - 1) return 0;
      if (x > 15) {
        return solve(i, 15) + (ll)(N - i - 1) * (x % 15);
      }
      ll& res = dp[i][x];
      if (res != -1) return res;
      int y = lg(A[i], x, A[i + 1]);
      return res = y + solve(i + 1, y);
    }
     
    int main() {
      while (cin >> N) {
        A.resize(N);
        for (int i = 0; i < N; i++) cin >> A[i];
        vector<ll> costA(N + 1, 0);
        {
          memset(dp, -1, sizeof(dp));
          for (int i = 0; i < N; i++) costA[i] = solve(i, 0) * 2;
        }
        vector<ll> costB(N + 1, 0);
        {
          reverse(A.begin(), A.end());
          memset(dp, -1, sizeof(dp));
          for (int i = 0; i < N; i++) costB[i] = solve(i, 0) * 2;
        }
        reverse(costB.begin(), costB.end());
        ll res = 1ll << 60;
        for (int i = 0; i <= N; i++) {
          ll cost = i + costA[i] + costB[i];
          res = min(res, cost);
        }
        cout << res << endl;
      }
      return 0;
    }

Measured memory_bytes: 54912
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		double a = sc.nextDouble();
		double b = sc.nextDouble();
		double x = sc.nextDouble();
		sc.close();
		if (x <= a * a * b / 2.0) {
			System.out.println(90.0 - Math.toDegrees(Math.atan((2.0 * x) / (a * b * b))));
		} else {
			System.out.println(Math.toDegrees(Math.atan((2.0 * (a * a * b - x)) / (a * a * a))));
		}
	}

	public static int[] arrayInt(Scanner sc, int n) {
		int[] array = new int[n];
		for (int i = 0; i < n; i++) {
			array[i] = sc.nextInt();
		}
		return array;
	}

	public static long[] arrayLong(Scanner sc, int n) {
		long[] array = new long[n];
		for (int i = 0; i < n; i++) {
			array[i] = sc.nextLong();
		}
		return array;
	}

	public static double[] arrayDouble(Scanner sc, int n) {
		double[] array = new double[n];
		for (int i = 0; i < n; i++) {
			array[i] = sc.nextDouble();
		}
		return array;
	}
}


Measured memory_bytes: 24660
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
  
int D,G;
int p[10],c[10];  
int dp[1001];

int main() {
  cin >> D >> G;
  for (int i = 0; i < D; i++) {cin >> p[i] >> c[i];}
  
  for(int i=0; i<D; i++){		//mondai
    for(int k=1000; k>=1;k--){
      for(int j=1;j<=p[i]&&j<=k;j++){	//tokukazu                
        dp[k]=max(dp[k],dp[k-j]+(i+1)*100*j+(j==p[i]?c[i]:0));   //max tensu vs mondaisuu         
      }        
    }  
  }
    
  for(int i=0;i<=1000;i++){        
    if(dp[i]>=G){            
      cout<<i<<endl;           
      break;       
    }    
  }
}


Measured memory_bytes: 256
N, M = map(int, input().split())
a_li = [input() for i in range(N)]
b_li = [input() for i in range(M)]

for i in range(N - M + 1):
    for j in range(N - M + 1) :
        for k in range(M) :
            if a_li[i + k][j : j + M] != b_li[k] :
                break
            if k == M - 1:
                print("Yes")
                exit()
print("No")


Measured memory_bytes: 3060