akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

int main()
{
    int N,M,A,B;
    cin >> N >> M;
    vector<int> H(N),D(N);
    for ( int i = 0; i < N; ++i)
    {
        cin >> H.at(i);
    }
    for ( int i = 0; i < M; ++i)
    {
        cin >> A >> B;
        A = A - 1;
        B = B - 1;
        if (H.at(A) < H.at(B) )
            D.at(A) = 1;
        else if(H.at(A) > H.at(B))
            D.at(B) = 1;
        else if ( H.at(A) == H.at(B))
        {
            D.at(A) = 1;
            D.at(B) = 1;
        }

    }
    int count = 0;
    for ( int i = 0; i < N; ++i)
    {
        if ( D.at(i) == 0 )
            count++;
    }
    cout << count << endl;
}


Measured memory_bytes: 4024
#include <bits/stdc++.h>
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define in(x,y,h,w) x >= 0 && x < h && y >= 0 && y < w
using namespace std;

#define int long long
//typedef    long long          ll;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      P;
 
const int INF=1e+9;
const double EPS=1e-9;
const int MOD=1000000007;
 
const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};

signed main(){
	int n,t[102],v[102],sum = 0,tmp = 0;
	double ans = 0,lim[50000];
	cin >> n;
	for(int i = 0;i < n;i++){
		cin >> t[i];
		sum += t[i];
	}
	for(int i = 0;i < n;i++) cin >> v[i];
	for(int i = 0;i <= sum * 2;i++) lim[i] = (double)min(i,sum * 2 - i) / 2.0;
	for(int i = 0;i < n;i++){
		for(int j = tmp * 2;j >= 0;j--) lim[j] = min(lim[j],(double)v[i] + (double)(tmp * 2 - j) / 2.0);
		for(int j = tmp * 2;j <= (tmp + t[i]) * 2;j++)  lim[j] = min((double)v[i],lim[j]);
		tmp += t[i];
		for(int j = tmp * 2;j <= sum * 2;j++) lim[j] = min(lim[j],(double)v[i] + (double)(j - tmp * 2) / 2.0);
	}
	for(int i = 0;i < sum * 2;i++) ans += (lim[i] + lim[i + 1]) * 0.25;
	printf("%.9lf\n",ans);
	return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <iomanip>
#include <ios> 
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>
#include <map>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)

using namespace std;
typedef long long int lli;
const int MAX=1e5+4;

int main(){
	string S,T;
	cin>>S>>T;
	int l=S.size();
	
	bool anst=true;
	rep(i,26){
		char x='a'+i;
		char s='X';
		rep(j,l)if(T[j]==x){
			if(s=='X'){
				s=S[j];
			}
			else{
				if(s!=S[j]){
					anst=false;
					break;
				}
			}
		}
		if(!anst)break;
	}
  	bool anss=true;
  	rep(i,26){
		char x='a'+i;
		char s='X';
		rep(j,l)if(S[j]==x){
			if(s=='X'){
				s=T[j];
			}
			else{
				if(s!=T[j]){
					anss=false;
					break;
				}
			}
		}
		if(!anss)break;
	}
  
	if(anst&&anss)cout<<"Yes";
	else cout<<"No";
}

Measured memory_bytes: 776
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <queue>
#include <map>
using namespace std;
typedef long long ll;
const int INF = 1<<30; 
const int MOD = 1e9 + 7;
const int dy[] = {1, 0, -1, 0};
const int dx[] = {0, 1, 0, -1};
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a, b, c;
    cin >> a >> b >> c;
    cout << a * b / 2 << endl;
    return 0;
}



Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strconv"
)

const mod = 998244353
const facNum = 300001

var ans = 0
var N, M, Q int
var a []int
var b []int
var c []int
var d []int

func main() {
	sc := newScanner(os.Stdin)
	N, M, Q = sc.i(), sc.i(), sc.i()
	a = make([]int, Q)
	b = make([]int, Q)
	c = make([]int, Q)
	d = make([]int, Q)
	for i := 0; i < Q; i++ {
		a[i], b[i], c[i], d[i] = sc.i(), sc.i(), sc.i(), sc.i()
	}
	dfs([]int{1})
	fmt.Println(ans)
}

func dfs(A []int) {
	if len(A) == N+1 {
		now := 0
		for i := 0; i < Q; i++ {
			if A[b[i]]-A[a[i]] == c[i] {
				now += d[i]
			}
		}
		ans = max(ans, now)
		return
	}
	A = append(A, A[len(A)-1])
	for A[len(A)-1] <= M {
		dfs(A)
		A[len(A)-1] += 1
	}
}

// fmt.Println("Yes")
// fmt.Println("No")

// I/O
type scanner struct {
	sc *bufio.Scanner
}

func newScanner(input io.Reader) *scanner {
	sc := bufio.NewScanner(input)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &scanner{sc}
}

func (s *scanner) s() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *scanner) i() int {
	i, e := strconv.Atoi(s.s())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *scanner) f() float64 {
	f, e := strconv.ParseFloat(s.s(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *scanner) bs() []byte {
	return []byte(s.s())
}

func (s *scanner) is(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.i()
	}
	return res
}

func (s *scanner) fs(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.f()
	}
	return res
}

//const factorial = new
func Pow(a, n int) int {
	ans := 1
	for n > 0 {
		if (n & 1) == 1 {
			ans = ans * a % mod
		}
		a = a * a % mod
		n = n >> 1
	}
	return ans
}

func Gcd(a, b int) int {
	if a < b {
		return Gcd(b, a)
	}
	for b != 0 {
		a, b = b, a%b
	}
	return a
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func combination(n, k int, fac, ifac []int) int {
	if n < k || n < 0 {
		return 0
	}
	if k == 0 {
		return 1
	}
	//while n != 0
	ans := ifac[k] * ifac[n-k] % mod
	return ans * fac[n] % mod
}

// 階乗: factorial
// コンビネーションを計算する際に前もって計算しておく
// fac[k] => k! (mod M)
// ifac[k] => k!^(M-2) (mod M)
// n: ex. 2 * 10^5 => 200001
// fac, ifac := factorial()
func factorial() (fac []int, ifac []int) {
	fac = make([]int, facNum)
	fac[0] = 1
	ifac = make([]int, facNum)
	ifac[0] = 1
	for i := 1; i < facNum; i++ {
		fac[i] = fac[i-1] * i % mod
		ifac[i] = ifac[i-1] * Pow(i, mod-2) % mod
	}
	return
}


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

void dfs(int k, vector<int> &a, vector<int> &b){
  if(2 * k > n){
    b[k-1] = a[k-1];
    return;
  }
  int d = n / k;
  int g = k * d;
  int num = 0;
  while(g > k){
    num += b[g-1];
    g -= k;
  }
  if(a[k-1] == num % 2){
    b[k - 1] = 0;
  }else{
    b[k - 1] = 1;
  }
  return;
}

int main() {
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  vector<int> b(n);
  vector<int> ans;
  int ans_count = 0;
  for (int i = n - 1; i >= 0; i--){
    dfs(i + 1, a, b);
  }
  int d = 0;
  rep(i, n){
    if (b[i] > 0){
      ans.push_back(i + 1);
    }
    //if(b[i] % 2 != a[i]){
    //  cout << -1 << endl;
    //  return 0;
    //}
  }
  sort(ans.begin(), ans.end());
  if(ans.size() == 0){
    cout << 0 << endl;
  }else {
    cout << ans.size() << endl;
    rep(i,ans.size()){
      cout << ans[i] << (i == ans.size() - 1 ? "\n" : " ");
    }
  }
}

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define cinf(n,x) for(int i=0;i<(n);i++) cin >> x[i];
typedef long long int ll;
using namespace std;

int main(){
	ll h,w; cin >>h >>w;
	if(h%3 ==0 || w%3 ==0){
		cout << 0 << endl;
		return 0;
	}
	ll ans=1000000000;
	ans=min({ans,h,w});
	for(int i=0;i<h;i++){
		ll cnt=w*(i+1);
		ll cnt1=(h-i-1)*(w/2);
		ll cnt2=(h-i-1)*((w+1)/2);
		ans=min(ans,max({cnt,cnt1,cnt2})-min({cnt,cnt1,cnt2}));
	}
	for(int i=0;i<w;i++){
		ll cnt=h*(i+1);
		ll cnt1=(w-i-1)*(h/2);
		ll cnt2=(w-i-1)*((h+1)/2);
		ans=min(ans,max({cnt,cnt1,cnt2})-min({cnt,cnt1,cnt2}));
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;

int main()
{
	int n, c;
	string key[] = {"", ".,!? ", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz"};
	string input;
	char p;
	
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> input;
		c = 0;
		p = '0';
		for (int j = 0; j < input.size(); j++) {
			if (input[j] == '0' && p != '0') {
				cout << key[p - '0'][(c - 1) % key[p - '0'].size()];
				c = 0;
			} else if (input[j] == p) {
				c++;
			} else {
				c = 1;
			}
			p = input[j];
		}
		cout << endl;
	}
	
	return 0;
}

Measured memory_bytes: 1212
H, W = gets.split(' ').map(&:to_i) 
ARR = Array.new(H) { Array.new(gets.chomp.split('')) }

def dfs(i, j)
  ret = 0
  [i-1, i, i+1].each do |row|
    [j-1, j, j+1].each do |col|
      next if row == i && col == j
      if row > -1 && row < H && col > -1 && col < W
        ret += 1 if ARR[row][col] == '#'
      end
    end
  end
  ret
end

output = Marshal.load(Marshal.dump(ARR))
ARR.each_with_index do |row, i|
  row.each_with_index do |item, j|
    output[i][j] = dfs(i, j) if item == '.'
  end 
end

output.each { |r| puts r.join }


Measured memory_bytes: 2300
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long long hp,atk;
  cin >> hp >> atk;
  
  long long last_hp;
  int counter = 0;
  while (true){
    last_hp = hp - atk;
    counter++;
    if(last_hp <= 0){
      break;
    }
    hp = last_hp;
  }
  cout << counter << endl;
}

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

int main() {
    cin.tie(0)->sync_with_stdio(false);

    int ans = 0;
    REP(i, 5) {
        int tmp;
        cin >> tmp;
        if (tmp == 0) ans = i + 1;
    }
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 3604
import sys
input = sys.stdin.readline

N, A, B = map(int, input().split())
h = [int(input()) for _ in range(N)]
h.sort(reverse=True)
left = 0
right = 10**10
while left < right:
    mid = (left + right) // 2
    remaining = mid
    ok = True
    for health in h:
        x = (health-B*mid+A-B-1) // (A-B)
        remaining -= x
        if remaining < 0:
            ok = False
            break
    if ok:
        right = mid
    else:
        left = mid + 1
print(right)


Measured memory_bytes: 7508
#pragma GCC optimize("O3")
#include<bits/stdc++.h>
#include<map>
#include<iostream>
#include <cstring>
#include <iomanip>
#include <algorithm>
#define forr(i,a,b) for(int i=a;i<=b;i++)
#define F first
#define S second
#define input ios_base::sync_with_stdio(0);cin.tie(0);

const double PI  = acos(-1.0);
using namespace std;
//typedef pair<double,double>pdd;
typedef long long  ll;
typedef pair<ll, ll>pii;
//typedef complex<double> point;
//int x[8]={1,0,0,-1,-1,-1,1,1};
//int y[8]={0,1,-1,0,-1,1,-1,1};
//char rv[4]={'D','R','L','U'};
const double EPS = 1e-9;
const int N = 100000 + 9;
int n,mem[N],a[N];

int dp(int i=1)
{
    if(i == n)return 0;
    if(i > n) return 1e9+9;
    if(mem[i] != -1) return mem[i];

    int c1 = abs(a[i] - a[i+1]) + dp(i+1);
    int c2 = abs(a[i] - a[i+2]) + dp(i+2);
    return mem[i] = min(c1,c2);
}

 int main()
{
//freopen("calc.in","r",stdin);
//freopen("calc.out","w",stdout);
//__builtin_popcount()
input
        cin>>n;
        forr(i,1,n)cin>>a[i];

        memset(mem,-1,sizeof mem);
        cout<<dp()<<endl;





return 0;
}


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

#define MOD 1000000007
#define rep(i, n) for(ll i=0; i < (n); i++)
#define rrep(i, n) for(ll i=(n)-1; i >=0; i--)
#define ALL(v) v.begin(),v.end()
#define rALL(v) v.rbegin(),v.rend()
#define FOR(i, j, k) for(ll i=j;i<k;i++)
#define debug_print(var) cerr << #var << "=" << var <<endl;
#define DUMP(i, v)for(ll i=0;i<v.size();i++)cerr<<v[i]<<" "
#define fi first
#define se second

using namespace std;
typedef long long int ll;
typedef vector<ll> llvec;
typedef vector<double> dvec;
typedef pair<ll, ll> P;
typedef long double ld;
struct edge{ll x, c;};

ll mod(ll a, ll mod){
  ll res = a%mod;
  if(res<0)res=res + mod;
  return res;
}

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

ll modinv(ll a, ll mod){
  ll b=mod, u=1, v=0;
  while(b){
    ll t=a/b;
    a-=t*b; swap(a, b);
    u-=t*v; swap(u, v);
  }
  u%=mod;
  if(u<0)u+=mod;
  return u;
}

ll gcd(ll a, ll b){
  ll r = a%b;
  if(r==0) return b;
  else return gcd(b, a%b);
}

bool is_prime(ll n){
  ll i = 2;
  if(n==1)return false;
  if(n==2)return true;
  bool res = true;
  while(i*i <n){
    if(n%i==0){
      res = false;
    }
    i = i+1;
  }

  //if(i==1)res = false;
  if(n%i==0)res=false;
  return res;
}
/**************************************
** A main function starts from here  **
***************************************/
int main(){
  ll N, M;
  cin >> N >> M;
  ll t = (N-M) * 100 + M * 1900;
  cout << t * (1<<M);

  return 0;
}


Measured memory_bytes: 3596
#include<bits/stdc++.h>// Logic%2==0 //
#define CASE(t)                 printf("Case %d: ",t)
#define gcd(a,b)                __gcd(a,b)
#define lcm(a,b)                ((a)*(b))/gcd(a,b)
#define PI                      2*acos(0.0)
#define ll                      long long int
//MD.JAHIR RAYHAN  , 11th batch CSE ,ID : 11908028 , Comilla University (2018-2019) :
//Email : rayhanlabib7@gmail.com, Phone : 01637809651.
using namespace std;
int main()
{
    ll a,b,c,x,y,z,m,k,l,r,i,n;

cin>>n;
c=1;
while(n>1)
{
    n/=2;
    c++;
}
x=pow(2,c)-1;
cout<<x<<endl;


return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
string a;
int k,n;
long long dp[102][2][100000];
long long solve(int pos,int tight,int cnt){
	if(cnt>k) return 0;
	if(n==pos) return (cnt==k)?1:0;
	if(dp[pos][tight][cnt]!=-1)	return dp[pos][tight][cnt];
	long long ret=0;
	for(int i=0;i<10;i++){
		if(tight&&i>a[pos]-'0') break;
		int nxt_cnt=cnt+(i>0);
		int nxt_tight=tight&&i==(a[pos]-'0');
		ret+=solve(pos+1,nxt_tight,nxt_cnt);
	}
	return dp[pos][tight][cnt]=ret;
}

int main()
{
	cin>>a>>k;
	n=a.size();
	memset(dp,-1,sizeof(dp));
	cout<<solve(0,1,0);
}

Measured memory_bytes: 159616
#include <bits/stdc++.h>
using i64 = long long;

int main() {
    int x;
    std::cin >> x;

    for (int y = 1; y <= 100000; y++) {
        int min = y * 100, max = y * 105;
        if (min <= x && x <= max) {
            std::cout << 1 << std::endl;
            return 0;
        }
    }

    std::cout << 0 << std::endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
  int m,f,b;
  cin >> m >> f >> b;
  if(m >= b){
      cout << 0 << endl;
  }
  else if(m+f >= b){
      cout << b-m << endl;
  }
  else{
      cout << "NA" << endl;
  }
}


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

using namespace std;
using ll = long long;
using ld = long double;

int main () {
	ll n, x, m;
	cin >> n >> x >> m;
	set<ll> st;
	vector<ll> seq;
	ll repeat;
	while (true) {
		seq.push_back(x);
		st.insert(x);
		x = (x * x) % m;
		if (st.count(x)) {
			repeat = x;
			break;
		}
	}

	ll sol = 0;
	int i = 0;

	while (i < (int) seq.size() && seq[i] != repeat && n > 0) {
		sol += seq[i];
		i++;
		n--;
	}

	vector<ll> cycle, pref = {0};

	for (int j = i; j < (int) seq.size(); j++) {
		cycle.push_back(seq[j]);
		pref.push_back(seq[j]);
		pref.back() += pref[(int) pref.size() - 2];
	}

	sol += pref.back() * (n / (int) cycle.size());
	sol += pref[n % (int) cycle.size()];

	cout << sol << '\n';
}


Measured memory_bytes: 7124
n, m = gets.split(" ").map(&:to_i)
b = Array.new(m){gets.split(" ").map(&:to_i)}
1001.times do |i|
  if i == 1000
    puts -1
    break
  end
  s = i.to_s
  next if s.size != n
  flag = true
  b.each do |p|
    flag = false if s[p[0]-1].to_i != p[1]
  end
  if flag
    puts i
    break
  end
end

Measured memory_bytes: 1788
let () =
  let xs = Scanf.scanf "%d" (fun n -> Array.init n (fun _ -> Scanf.scanf " %d" (fun x -> x))) in
  let total = Array.fold_left (+) 0 xs in
  Scanf.scanf " %d" (fun m -> Array.init m (fun _ -> Scanf.scanf " %d %d" (fun p u -> (p, u))))
  |> Array.iter (fun (p, u) -> Printf.printf "%d\n" (total + (u-xs.(p-1))))


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

#define int long long

#define ii pair<int,int>
#define fi first
#define sc second
#define lwb lower_bound
#define upb upper_bound
#define uset unordered_set
#define umap unordered_map
#define all(x) (x).begin(),(x).end()

int chmin(int &a, int b) { if (a > b) { a = b; return 1; } return 0; }
int chmax(int &a, int b) { if (a < b) { a = b; return 1; } return 0; }

signed main() {
#ifdef _DEBUG
  // freopen("in" , "r", stdin );
  // freopen("out", "w", stdout);
#endif
  ios::sync_with_stdio(0); cin.tie(0);
  int n; cin >> n;
  int ans = 0;
  map<int, int> m;
  for (int i = 0; i < n; i++) {
    int t; cin >> t;
    ans += m[i - t];
    m[i + t]++;
  }
  cout << ans << '\n';
}


Measured memory_bytes: 26400
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define printYes() cout << "Yes" << endl;
#define printNo() cout << "No" << endl;
#define printVector(v) rep(i, v.size()) cout << v[i] << endl;

int main()
{
  string SA, SB, SC;
  cin >> SA >> SB >> SC;
  reverse(SA.begin(), SA.end());
  reverse(SB.begin(), SB.end());
  reverse(SC.begin(), SC.end());

  string ans;
  char turn = 'a';
  while (true)
  {
    if (turn == 'a')
    {
      if (SA.size() == 0)
      {
        ans = "A";
        break;
      }

      turn = SA.back();
      SA.pop_back();
    }
    else if (turn == 'b')
    {
      if (SB.size() == 0)
      {
        ans = "B";
        break;
      }

      turn = SB.back();
      SB.pop_back();
    }
    else if (turn == 'c')
    {
      if (SC.size() == 0)
      {
        ans = "C";
        break;
      }

      turn = SC.back();
      SC.pop_back();
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  ll n,i,ans=0;
  cin>>n;
  
  vector<ll> ret;
  
  for(ll i=1 ; i*i+i<n ; i++){
    if((n-i)%i==0){
     ans+=(n-i)/i;
    }
  }
   cout<<ans<<endl;
}

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

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

    int n;
    cin >> n;
    vector<pair<int, int>> R(n), B(n);
    REP(i, n) cin >> R[i].second >> R[i].first;
    REP(i, n) cin >> B[i].first >> B[i].second;
    sort(R.begin(), R.end(), greater<pair<int, int>>());
    sort(B.begin(), B.end());

    vector<bool> F(n, true); 
    REP(i, n){
        REP(j, n){
            if(F[j] and R[j].second < B[i].first and R[j].first < B[i].second){
                F[j] = false;
                break;
            }
        }
    }

    cout << count(F.begin(), F.end(), false) << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
using namespace std;
#define LOCAL  1
#define UPLOAD 2
unsigned gcd(unsigned a, unsigned b) {
  if(a < b) return gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}
template <class T = long long> T input(){T x;cin >> x;return x;}
template <class T> void output(T x){cout << x << endl;}
#define debug(x) cerr << #x<< ": " << x<< '\n';

#define ll long long

int main()
{
#if ENVIRONMENT == LOCAL
    std::ifstream in("input.txt");
    std::cin.rdbuf(in.rdbuf());
#endif
  ll N = input();
  
  int count = 0;
  for(int i=1;i<=N;i++){
    if(i % 2 == 1)count++;
  }

  output((float)count/N);

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, a, b) for(ll i=(a); i<(b); i++)
#define PER(i, a, b) for(ll i=(a); i>=(b); i--)
#define rep(i, n) REP(i, 0, n)
#define per(i, n) PER(i, n, 0)
#define ALL(a)  (a).begin(),(a).end()
const ll INF = 1e18+18;
const ll MAX = 200000;
const ll MOD = 1000000007;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define YES(n) cout << ((n) ? "YES" : "NO") << endl;



int main(){
  ll N;
  cin>>N;
  vector<ll> L(N);
  rep(i, N){
    cin>>L[i];
  }
  ll Ans=0;
  rep(i, N){
    for(ll j=i+1; j<N; j++){
      for(ll k=j+1; k<N; k++){
        if(L[i]+L[j]>L[k]&&L[j]+L[k]>L[i]&&L[k]+L[i]>L[j]){
          if(L[i]==L[j]||L[j]==L[k]||L[k]==L[i])continue;
          Ans++;
          //cout<<i<<" "<<j<<" "<<k<<endl;
          //cout<<L[i]<<" "<<L[j]<<" "<<L[k]<<endl;
        }

      }
    }
  }
  cout<<Ans<<endl;
}

Measured memory_bytes: 3632
import java.util.*;
 
public class Main {
	
    public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
    	String N = sc.next();
    	boolean hi = true;
    	for (int i = 0; i < N.length(); i++) {
    		if ((i%2 == 0 && N.charAt(i) != 'h') || (i%2 == 1 && N.charAt(i) != 'i')) {
    			hi = false;
    		} 
    	}
    	System.out.println(hi && N.length()%2 ==0 ? "Yes" : "No");
    }
}

Measured memory_bytes: 21844
#include <iostream>
#include <iomanip>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <sstream>
 
using namespace std;

vector<string> vec_splitter(string s) {
  s += ',';
  vector<string> res;
  while(!s.empty()) {
    res.push_back(s.substr(0, s.find(',')));
    s = s.substr(s.find(',') + 1);
  }
  return res;
}
void debug_out(
vector<string> __attribute__ ((unused)) args,
__attribute__ ((unused)) int idx,
__attribute__ ((unused)) int LINE_NUM) { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
  if(idx > 0) cerr << ", "; else cerr << "Line(" << LINE_NUM << ") ";
  stringstream ss; ss << H;
  cerr << args[idx] << " = " << ss.str();
  debug_out(args, idx + 1, LINE_NUM, T...);
}

#ifndef ONLINE_JUDGE
#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
#else
#define debug(...) 42
#endif
 
#define MOD 1000000007
#define A first
#define B second
#define all(x) (x).begin(), (x).end

typedef long long ll;
 
inline int mulmd(ll a, ll b){
  ll ret = (a * b) % MOD;
  return (int) ret;
}
 
inline int power(ll x, ll y, int m){
  ll res = 1;
  x = x % m;
  while(y > 0){
    if(y & 1){
      res = mulmd(res, x);
    }
    y = y >> 1;
    x = mulmd(x, x);
  }
  return (int) res;
}
 
inline int submd(ll a, ll b){
  ll ret = (a - b);
  if(ret < 0) ret += MOD;
  return (int) ret;
}
 
inline int addmd(ll a, ll b){
  ll ret = (a + b) % MOD;
  return (int) ret;
}
 
inline int invPow(ll a){
  return power(a, MOD - 2, MOD);
}
 
inline int divmd(ll a, ll b){
  ll ret = mulmd(a, invPow(b));
  return (int) ret;
}
 
const int N = 1e5 + 5;

int arr[N];

void solve(){
  string s, t;
  cin >> s >> t;
  int cnt = 0;
  for(int i = 0; i < s.size(); i++){
    if(s[i] != t[i]) cnt++;
  }
  cout << cnt;
}

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t;
  t = 1;
  //cin >> t;
  while(t--){
    solve();
  }
}



Measured memory_bytes: 3736
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < (n); ++i)
#define FOR(i, m, n) for(ll i = m; i < (n); i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
using vi = vector<int>;
using vii = vector<vi>;
using pii = pair<int, int>; 
using vl = vector<ll>;
using vll = vector<vl>;
using pll = pair<ll, ll>;

int main() {
    ll N;
    cin >> N;
    vl a(N);
    rep(i, N){
        cin >> a[i];
    }
    ll ari = 0, bob = 0;
    ll t = 1;
    rep(i, N){
        ll maxi = 0;
        ll id = 0;
        rep(j, N){
            if(a[j] > maxi){
                maxi = a[j];
                id = j;
            }
        }
        if(t == 1){
            ari += maxi;
            t = 0;
        }else{
            bob += maxi;
            t = 1;
        }
        a[id] = 0;
    }
    cout << ari-bob;
}

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

// #define int long long
#define rep(i, n) for (long long i = (long long)(0); i < (long long)(n); ++i)
#define reps(i, n) for (long long i = (long long)(1); i <= (long long)(n); ++i)
#define rrep(i, n) for (long long i = ((long long)(n)-1); i >= 0; i--)
#define rreps(i, n) for (long long i = ((long long)(n)); i > 0; i--)
#define irep(i, m, n) for (long long i = (long long)(m); i < (long long)(n); ++i)
#define ireps(i, m, n) for (long long i = (long long)(m); i <= (long long)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) long long(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

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

const ll INF = 1e9;
const ll MOD = 1e9+7;
const ll LINF = 1e18;

ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

ll ngcd(vector<ll> a) {
  ll res = a[0];
  for(ll i=1; i<a.size() && res!=1; i++) res = gcd(a[i], res);
  return res;
}
ll nlcm(vector<ll> a){
  ll res = a[0];
  for(ll i=1; i<a.size(); i++) res = lcm(a[i], res);
  return res;
}
bool is_prime(ll n) {
  if(n < 2) return false;
  for (ll i = 2; i * i <= n; i++) if (n % i == 0) return false;
  return true;
}
ll digsum(ll n) {
  ll res=0;
  while(n) res += n%10, n /= 10;
  return res;
}
ll digcnt(ll n){
  ll res=0;
  while(n) res++, n /= 10;
  return res;
}
vector<ll> divisor(ll n) {
  vector<ll> res;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      res.push_back(i);
      if (i != n / i) res.push_back(n / i);
    }
  }
  sort(res.begin(), res.end());
  return res;
}
map<ll, ll> prime_factor(ll n) {
  map<ll, ll> res;
  for (ll i = 2; i * i <= n; i++) {
    while (n % i == 0) ++res[i], n /= i;
  }
  if (n != 1) res[n] = 1;
  return res;
}

signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  ll n,k; cin>>n>>k;
  vll a(n); ll sum=0;
  rep(i,n){
    cin>>a[i];
    sum+=a[i];
  }
  ll ans=1;
  auto v=divisor(sum);
  for(auto e: v){
    vll b(n);
    ll p=0;
    rep(i,n){
      b[i]=a[i]%e;
      p+=e-b[i];
    }
    vsort(b);
    ll m=0;
    rep(i,n){
      m+=b[i];
      p-=e-b[i];
      if(m==p){
        if(p<=k){
          chmax(ans,e);
        }
        if(m>p) break;
      }
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl;
#define DEBUG_MAT(v) cerr<<#v<<endl;for(int i=0;i<v.size();i++){for(int j=0;j<v[i].size();j++) {cerr<<v[i][j]<<" ";}cerr<<endl;}
typedef long long ll;
#define int ll
 
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); }
template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); }
template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
#define X first
#define Y second
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(int)(n);i>0;i--)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(),c.end()
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 UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
const ll inf = 1000000001;
const ll INF = (ll)1e18 + 1;
const long double pi = 3.1415926535897932384626433832795028841971L;
#define Sp(p) cout<<setprecision(25)<< fixed<<p<<endl;
//int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
//int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
vi dx = {1, 0, -1, 0}, dy = {0, 1, 0, -1};
vi dx2 = { 1,1,0,-1,-1,-1,0,1 }, dy2 = { 0,1,1,1,0,-1,-1,-1 };
#define fio() cin.tie(0); ios::sync_with_stdio(false);
const ll MOD = 1000000007;
//const ll MOD = 998244353;
// #define mp make_pair
//#define endl '\n'

signed main() {
    fio();
    ll n;
    cin >> n;
    ll sum = n * (n + 1) / 2;
    ll m = 3;
    ll t = n / m;
    sum -= t * (t + 1) / 2 * 3;
    m = 5;
    t = n / m;
    sum -= t * (t + 1) / 2 * 5;
    m = 15;
    t = n / m;
    sum += t * (t + 1) / 2 * 15;
    cout << sum << endl;
}

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

using namespace std;

int main()
{
    ios_base::sync_with_stdio(0);
    int n, m;
    cin >> n >> m;
    vector<string> a(n);
    vector<string> b(n);
    for (int i = 0; i < n; ++i)
        cin >> a[i];
    for (int i = 0; i < m; ++i)
        cin >> b[i];
    bool jest = false;
    for (int i = 0; i < n; ++i)
    {
        for (int j = 0; j < n; ++j)
        {
            if (i + m - 1 < n && j + m - 1 < n)
            {
                bool db = true;
                for (int k = 0; k < m; ++k)
                    for (int l = 0; l < m; ++l)
                        if (a[i + k][j + l] != b[k][l])
                            db = false;
                if (db)
                    jest = true;
            }
        }
    }
    if (jest)
        cout << "Yes";
    else
        cout << "No";
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <vector>
#include <utility>
#include <string>
#include <algorithm>
#include <cmath>
#include <queue>
#include <cstring>
 
typedef long long ll;

#define rep(i,n) for(ll i = 0; i < n; i++)
 
using namespace std;
 
const ll INF = ll(1e18)+1;
const double PI=3.14159265358979323846;

vector<vector<char> > G(55,vector<char>(55));
vector<vector<int> > D(55,vector<int>(55,-1));
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,1,-1};

int main(){
  int H, W, cntd = 0;
  cin >> H >> W;
  rep(i,H) rep(j,W){
    cin >> G[i][j];
    if(G[i][j] == '.') cntd++;
  }

  int sy = 0, sx = 0, gy = H-1, gx = W-1;
  D[sy][sx] = 1;
  queue<pair<int,int> > q;
  q.push(make_pair(sy,sx));

  while(!q.empty()){
    pair<int,int> p = q.front();
    q.pop();
    rep(i,4){
      int y = p.first + dy[i];
      int x = p.second + dx[i];
      if(y<0 || H<=y || x<0 || W<=x || D[y][x]!=-1 || G[y][x] == '#')
	continue;
      D[y][x] = D[p.first][p.second] + 1;
      q.push(make_pair(y,x));
    }
  }

  if(D[gy][gx] != -1) cout << cntd - D[gy][gx] << endl;
  else cout << -1 << endl;
}


Measured memory_bytes: 256
# coding: utf-8
# Your code here!


import math
X, K, D = list(map(int, input().split()))
flag = 0

step = math.floor(abs(X)/D)
if abs(abs(X) - D *step) < abs(abs(X)-D * (step + 1)):
    step += 1
    flag = 1

if step > K:
    print(abs(abs(X) - D * K))
else:
    if (step%2 + K%2) %2 == 0:
        print(abs(abs(X)-D * step))
    else:
        if flag == 0:
            print(abs(abs(X)-D * (step + 1)))
        else:
            print(abs(abs(X) - D *(step-1)))

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

using namespace std;
vector<vector<int>> adj;
vector<int> color;

void dfs(int u) {
    for (int v : adj[u]) {
        if (color[v] == -1) {
            color[v] = 1 - color[u];
            dfs(v);
        }
    }
}

int main() {
    int n;
    cin >> n;
    adj.assign(n + 1, {});
    color.assign(n + 1, -1);
    for (int i = 0; i < n - 1; ++i) {
        int u, v;
        cin >> u >> v;
        adj[u].emplace_back(v);
        adj[v].emplace_back(u);
    }
    color[1] = 0;
    dfs(1);
    vector<int> cnt(2);
    for (int i = 1; i <= n; ++i)
        cnt[color[i]]++;
    int one = n / 3 + (n % 3 >= 1);
    int two = n / 3 + (n % 3 >= 2);
    vector<int> ans(n + 1);
    int min_color = cnt[0] < cnt[1] ? 0 : 1;
    if (cnt[min_color] < two) {
        int a = 3;
        for (int i = 1; i <= n; ++i)
            if (color[i] == min_color) {
                ans[i] = a;
                a += 3;
            }
        int b = 1, c = 2;
        for (int i = 1; i <= n; ++i) {
            if (ans[i] == 0) {
                if (a <= n) {
                    ans[i] = a;
                    a += 3;
                } else if (b <= n) {
                    ans[i] = b;
                    b += 3;
                } else {
                    ans[i] = c;
                    c += 3;
                }
            }
        }
    } else {
        int a = 3, b = 1, c = 2;
        for (int i = 1; i <= n; ++i) {
            if (color[i] == 0 && b <= n) {
                ans[i] = b;
                b += 3;
            } else if (color[i] == 1 && c <= n) {
                ans[i] = c;
                c += 3;
            } else {
                ans[i] = a;
                a += 3;
            }
        }
    }
    for (int i = 1; i <= n; ++i)
        cout << ans[i] << " ";
}

Measured memory_bytes: 17920
#include<iostream>
#include<math.h>
#include<iomanip>

using namespace std;

int main() {
    float n,k;
    cin >> n >> k;
    float res = 0;
    for(int i=1; i <n+1; i++) {
        if (i >= k) res += 1.0;
        else res += pow(0.50, ceil(log2(k/i)));
    }
    cout << fixed;
    cout << setprecision(10) << res * 1.0/n << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define REPL(i,m,n) for(ll i=(ll)(m); i<(ll)(n); i++)
#define repl(i,n) REPL(i,0,n)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
int main() {
  int N, T;
  cin >> N >> T;
  vector<int> A(N), B(N), idx(N);
  rep(i, N) {
    cin >> A[i] >> B[i];
    idx[i] = i;
  }
  sort(all(idx), [&](int i, int j) {
      return A[i] < A[j];
    });
  vector<vector<ll> > dp(T+1, vector<ll>(N+1));
  rep(t, T) {
    rep(i, N) {
      ll a = A[idx[i]];
      ll b = B[idx[i]];
      dp[t][i+1] = max(dp[t][i], dp[t][i+1]);
      if(t+a<=T) dp[t+a][i+1] = max(dp[t][i]+b, dp[t+a][i+1]);
      else       dp[T][i+1] = max(dp[t][i]+b, dp[T][i+1]);
    }
  }
  ll ans = 0;
  rep(i, N+1) ans = max(dp[T][i], ans);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 70784
s=gets.chomp
start = s.size
while !s.empty?
  if s.size.odd?
    s.slice!(-1)
    next
  else
    if s.size == start
      s.slice!(-1)
      next
    end
    
    if s[0..(s.size-1)/2] == s[(s.size-1)/2+1..s.size-1]
      puts s.size
      break
    end
    s.slice!(-1)
  end
end

Measured memory_bytes: 1788
#include <bits/stdc++.h>
#include <numeric>
using namespace std;
using Graph = vector<vector<int>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const long long X=1000000000+7;

int main() {
  int n;
  cin>>n;
  bool ans=true;
  if(n%10!=7){
    n/=10;
    if(n%10!=7){
      n/=10;
      if(n%10!=7)
        ans=false;
    }
  }
  if(ans) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}


Measured memory_bytes: 3616
#include<bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
const double eps = 1e-8;
const int NINF = 0xc0c0c0c0;
const int INF  = 0x3f3f3f3f;
const ll  mod  = 1e9 + 7;
const ll  N = 2e5 + 5;

int n;
string s;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>n>>s;
	int R=n-1;
	int cnt=0;
	for(int L=0;L<R;L++,R--){
		while(s[L]!='W' && L<R) L++;
		while(s[R]!='R' && L<R) R--;
		if(s[L]!='W'||s[R]!='R') break;
		cnt++;
	}
	cout<<cnt<<'\n';
	return 0;
}

Measured memory_bytes: 3752
#include<bits/stdc++.h>
 
using namespace std;
 
#define ll long long 
#define ld long double
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mkp make_pair
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define ff first
#define ss second
#define endl "\n"
#define MOD 1000000007
#define MOD1 998244353
#define inf 1e18
 
ll GCD(ll x,ll y){if(y==0)return x;return GCD(y,x%y);}
ll LCM(ll x,ll y){return (x*y)/(GCD(x,y));}
ll LOGK(ll x,ll k){if(x>=k)return 1+LOGK(x/k,k);return 0;}
ll MPOW( ll a, ll b, ll m) { if(b==0) return 1; ll x=MPOW(a,b/2,m); x=(x*x)%m; if(b%2==1) x=(x*a)%m; return x;}
ll MINV(ll a,ll m) {return MPOW(a,m-2,m);}
 
class pnc{
  ll FACT_MAX,MODU;
  vector<ll> fact;
public:
  pnc( ll n, ll m) { FACT_MAX = n; fact.resize(FACT_MAX); MODU = m; MFACT_INIT(MODU);}
  void MFACT_INIT( ll m) { fact[0]=1; for(ll i=1;i<FACT_MAX;++i) fact[i]=(i*fact[i-1])%MODU;}
  ll MFACT( ll n) { return fact[n];}
  ll PERM( ll n, ll r) { return (fact[n]*::MINV(fact[n-r],MODU))%MODU;}
  ll COMB( ll n , ll r) { return (PERM(n,r)*::MINV(fact[r],MODU))%MODU;}
};
 
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);    
 
    ll test=1;
    // cin>>test;
    while(test--)
    {
        ll n;
        cin>>n;

        ll ar[n];
        
        ll txor=0;

        for(ll i=0;i<n;i++)
        {
            cin>>ar[i];
        }

        if(n%2==0)
        {
            for(ll i=0;i<n;i++)
            {
                txor^=ar[i];
            }

            for(ll i=0;i<n;i++)
            cout<<(txor^ar[i])<<' ';
        }
        else
        {
            for(ll i=0;i<n-1;i++)
            {
                txor^=ar[i];
            }

            for(ll i=0;i<n-1;i++)
            cout<<(txor^ar[i])<<' ';
            cout<<0;
        }
        

    }
}

Measured memory_bytes: 5228
#pragma GCC optimize("Ofast", "unroll-loops")

#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define ld long double

int R, C, K;
ll dp[3001][3001][5];
int item[3000][3000];

void input(void){
	cin >> R >> C >> K;
	for (int i = 0; i < K; ++i){
		int r, c, v;
		cin >> r >> c >> v;
		--r, --c;
		item[r][c] = v;
	}
}

void do_dp(void){
	dp[0][0][1] = item[0][0];
	for (int i = 0; i < R; ++i){
		for (int j = 0; j < C; ++j){
			for (int g = 0; g <= 3; ++g){
				// 右へ、回収
				dp[i][j + 1][g + 1] = max(dp[i][j + 1][g + 1], dp[i][j][g] + item[i][j + 1]);
				// 右へ、回収しない
				dp[i][j + 1][g] = max(dp[i][j + 1][g], dp[i][j][g]);
				// 下へ、回収
				dp[i + 1][j][1] = max(dp[i + 1][j][1], dp[i][j][g] + item[i + 1][j]);
				// 下へ、回収しない
				dp[i + 1][j][0] = max(dp[i + 1][j][0], dp[i][j][g]);
			}
		}
	}
	// show dp
	/*
	for (int g = 0; g < 4; ++g){
		cout << g << endl;
		for (int i = 0; i < R; ++i){
			for (int j = 0; j < C; ++j)
				cout << dp[i][j][g] << " ";
			cout << endl;
		}
	}
	*/
}

int main(void){
	input(); do_dp();
	ll res = max({
		dp[R - 1][C - 1][0],
		dp[R - 1][C - 1][1],
		dp[R - 1][C - 1][2],
		dp[R - 1][C - 1][3]
	});
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 390516
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <deque>
#include <stack>

using namespace std;

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

	int n, m;
	string s[110], t[110];
	cin >> n;
	for (int i = 0; i < n; i++)  cin >> s[i];
	cin >> m;
	for (int i = 0; i < m; i++)  cin >> t[i];

	int maxv = 0;
	for (int i = 0; i < n; i++) {
		int con = 0;
		for (int j = 0; j < n; j++) {
			if (s[i] == s[j])  con++;
		}
		for (int k = 0; k < m; k++) {
			if (s[i] == t[k])  con--;
		}
		maxv = max(maxv, con);
	}

	cout << maxv << endl;
}

Measured memory_bytes: 256
import math

def quot(p, q):
  return p // q + (p % q != 0)

n = int(input())
ratio = [list(map(int, input().split())) for i in range(n)]

k = 1
for i in range(n-1):
  k1 = quot(ratio[i][0] * k , ratio[i+1][0])
  k2 = quot(ratio[i][1] * k , ratio[i+1][1])
  k = max(k1, k2)

print(sum(ratio[n-1]) * k)

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

int main() {
    int n;
    int k;
    cin >> n >> k;
    int* score = new int[n];
    for (int i = 0; i < n; i++) {
        cin >> score[i];
    }
    for (int i = 0; i < n-k; i++) {
        if (score[i]<score[k+i]) {
            cout << "Yes" << endl;
        }
        else {
            cout << "No" << endl;
        }
    }
    delete[] score;
    return 0;
}

Measured memory_bytes: 4004
#include<bits/stdc++.h>
#include<algorithm>
using namespace std;
#define ll long long 
int ctoi(char c) {return c-'0';}/*char to int*/
int gcd(ll a,ll b){return b?gcd(b,a%b):a;}/*MAX*/
int lcm(ll a,ll b){return a*b/gcd(a,b);}/*MIN*/
bool primecheck(ll n){/*sosuu*/if(n < 2) return false;else{for(int i = 2; i * i <= n; i++){if(n % i == 0) return false;}return true;}}
string  reverserange(string s,ll a,ll b){reverse(s.begin()+a-1,s.begin()+b); return s;}
int  main(){
ll n;
cin >> n;
vector<ll>a(5);
ll che = -1;
for(int i=0;i<5;i++){
    cin >> a.at(i);
    ll aa = n/a.at(i);
    if(n%a.at(i)!=0&&n>a.at(i))aa++;
    if(n<=a.at(i))aa++;
    che =max(che,aa);
    a.at(i)=aa;
}
ll ans;
for(int i=0;i<5;i++){
    if(che==a.at(i)){//kokomadeni kakaru ataihosii
    if(i==0){
        ans = che+4;
        cout << ans << endl;
        break;
    }
    else{
        ans=che+i + 4-i;
        cout << ans << endl;
        break;
    }
    }
}
}





Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
int main() {
	int d; cin >> d;
	bool ok = (d % 10 == 7) || (d / 10 % 10 == 7) || (d / 100 == 7);
	ok ? puts("Yes") : puts("No");
	return 0;
} 

Measured memory_bytes: 3632
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <bitset>
#include <string>
#include <cmath>
#include <complex>
#include <numeric>
#include <cassert>

#include <vector>
#include <array>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <utility>

#define int64 long long
#define uint64 unsigned long long
using namespace std;

int main()
{
	long double ll;
	cin >> ll;
	ll /= 3.0;
	ll *= ll * ll;
	cout << fixed << setprecision(15);
	cout << ll << endl;
	return 0;
}


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

typedef int_fast32_t int32;
typedef int_fast64_t int64;

const int32 inf = 1e9+7;
const int32 MOD = 1000000007;
const int64 llinf = 1e18;

#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE\n" : "IMPOSSIBLE\n"  )
#define ANS(n) cout << (n) << "\n"
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define all(obj) (obj).begin(),(obj).end()
#define rall(obj) (obj).rbegin(),(obj).rend()
#define fi first
#define se second
#define pb(a) push_back(a)
typedef pair<int32,int32> pii;
typedef pair<int64,int64> pll;

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

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int32 x,n;
  cin >> x >> n;
  set<int32> p;
  REP(i,n){
    int32 pi;
    cin >> pi;
    p.insert(pi);
  }
  REP(d,200){
    if(p.count(x-d) == 0){
      ANS(x-d);
      return 0;
    }
    if(p.count(x+d) == 0){
      ANS(x+d);
      return 0;
    }
  }
  return 0;
}

Measured memory_bytes: 3660
import sys
n = [int(line) for line in sys.stdin]

prime = [0, 0] + [1] * (max(n) - 1)

for i in range(len(prime)):
    if prime[i]:
        for j in range(2 * i, len(prime), i):
            prime[j] = 0

for i in range(1, len(prime)):
    prime[i] += prime[i - 1]

for ni in n:
    print(prime[ni])

Measured memory_bytes: 46472
package main

import (
	"bufio"
	"fmt"
	"log"
	"math"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)
var buff []byte

func init() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(buff, bufio.MaxScanTokenSize*1024)
	log.SetFlags(log.Lshortfile)
}

var memo map[int]int

var A, B, C, D int

func solve(N int) int {
	if N == 0 {
		return 0
	}
	if N == 1 {
		return D
	}
	if v, ok := memo[N]; ok {
		// log.Println(N, v, ok)
		return v
	}
	l2 := (N / 2) * 2
	r2 := ((N + 1) / 2) * 2
	l3 := (N / 3) * 3
	r3 := ((N + 2) / 3) * 3
	l5 := (N / 5) * 5
	r5 := ((N + 4) / 5) * 5
	res := int(1e18)
	if N < res/D {
		res = N * D
	}
	res = min(res, abs(l2-N)*D+A+solve(l2/2))
	res = min(res, abs(r2-N)*D+A+solve(r2/2))
	res = min(res, abs(l3-N)*D+B+solve(l3/3))
	res = min(res, abs(r3-N)*D+B+solve(r3/3))
	res = min(res, abs(l5-N)*D+C+solve(l5/5))
	res = min(res, abs(r5-N)*D+C+solve(r5/5))
	memo[N] = res
	return res
}

func main() {
	T := nextInt()
	for i := 0; i < T; i++ {
		memo = map[int]int{}
		N := nextInt()
		A = nextInt()
		B = nextInt()
		C = nextInt()
		D = nextInt()
		fmt.Println(solve(N))
	}
}

func nextString() string {
	sc.Scan()
	return sc.Text()
}

func nextFloat64() float64 {
	sc.Scan()
	f, err := strconv.ParseFloat(sc.Text(), 64)
	if err != nil {
		panic(err)
	}
	return f
}

func nextInt() int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return i
}

func nextInts(n int) (r []int) {
	r = make([]int, n)
	for i := 0; i < n; i++ {
		r[i] = nextInt()
	}
	return r
}

var dy = []int{0, 1, 0, -1}
var dx = []int{1, 0, -1, 0}
var MAX = math.MaxInt32

func pow(a, b int) int {
	return int(math.Pow(float64(a), float64(b)))
}

func lcm(a, b int) int {
	return a * b / gcd(a, b)
}
func gcd(a, b int) int {
	if a < b {
		a, b = b, a
	}
	for b != 0 {
		a, b = b, a%b
	}
	return a
}
func max(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r < a[i] {
			r = a[i]
		}
	}
	return r
}
func min(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r > a[i] {
			r = a[i]
		}
	}
	return r
}
func sum(a []int) (r int) {
	for i := range a {
		r += a[i]
	}
	return r
}
func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

type Pair struct {
	a, b int
}

type Pairs []Pair

func (p Pairs) Len() int {
	return len(p)
}
func (p Pairs) Swap(i, j int) {
	p[i], p[j] = p[j], p[i]
}

func (p Pairs) Less(i, j int) bool {
	if p[i].a == p[j].a {
		return p[i].b < p[j].b
	}
	return p[i].a < p[j].a
}


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

int main() {
    int N, M; cin >> N >> M;
    vector<vector<int>> G(N);
    for(int i = 0; i < M; ++i) {
        int a, b; cin >> a >> b;
        a--, b--;
        G[a].emplace_back(b);
        G[b].emplace_back(a);
    }
    auto dfs = [&](auto &&dfs, int cur, int pre, int S) -> int {
        if(S == (1 << N) - 1) return 1;
        int res = 0;
        for(auto &to : G[cur]) {
            if(pre == to) continue;
            if(S & (1 << to)) continue;
            res += dfs(dfs, to, cur, S | (1 << to));
        }
        return res;
    };
    cout << dfs(dfs, 0, 0, 1) << '\n';
    return 0;
}


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

int main() {
  int H, W;
  cin >> H >> W;
  vector<vector<char>> a(H, vector<char>(W));
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) cin >> a.at(i).at(j);
  }
  vector<int> row(H), column(W);
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (a.at(i).at(j) == '.') {
        row.at(i)++;
        column.at(j)++;
      }
    }
  }
  for (int i = 0; i < H; i++) {
    if (row.at(i) == W) continue;
    for (int j = 0; j < W; j++) {
      if (column.at(j) != H) cout << a.at(i).at(j);
    }
    cout << endl;
  }
}

Measured memory_bytes: 256