akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define llu unsigned long long 
#define ll long long 
ll read() { ll  x; if (scanf("%lld", &x) == -1)exit(0); return x; }
#define vi vector<int>
#define vb vector<bool>
const long long INF = 5e18;

#define LOCAL_JUDGE
void c_p_c()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifdef LOCAL_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}

const int N = 505;
bool killed[N][N];
int n;
int memo[N][N] = { 0 };
int dist[N][N] = { 0 };

int dx[4] = { -1, 1, 0, 0 };
int dy[4] = { 0, 0, -1, 1 };
vector<pair<int, int>> nei[N][N];

int main() {
   // c_p_c();
    n = read();
    for (auto row = 0; row < n; row++) {
        for (auto col = 0; col < n; col++) {
            dist[row][col] = 1 + min({ row, n - 1 - row, col , n - 1 - col });
        }
    }

    for (int row = 0; row < n; ++row) {
        for (int col = 0; col < n; ++col) {
            for (int dir = 0; dir < 4; ++dir) {
                int r2 = row + dx[dir];
                int c2 = col + dy[dir];
                if (0 <= r2 && 0 <= c2 && r2 < n && c2 < n) {
                    nei[row][col].emplace_back(r2, c2);
                }
            }
        }
    }

    long long answer = 0;
    for (auto turn = 1; turn <= n * n; turn++) {
        int who = read();
        who--;
        int row = who / n;
        int col = who % n;
        answer += dist[row][col] - 1;
        dist[row][col]--;
        killed[row][col] = true;
        vector<pair<int, int>> q;
        q.emplace_back(row, col);
        for (int i = 0; i < (int)q.size(); i++) {
            pair<int, int> a = q[i];
            for (const pair<int, int>& b : nei[a.first][a.second]) {
                int maybe = dist[a.first][a.second];
                if (!killed[b.first][b.second])
                    maybe++;
                if (dist[b.first][b.second] > maybe) {
                    dist[b.first][b.second] = maybe;
                    q.push_back(b);
                }
            }
        }
    }

    cout << answer << endl;
    return 0;
}



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

typedef struct _node {
  struct _node *left, *right;
  int key;
} node;

node *root = NULL;

node *deleteMin(node **p) {
  node *x;

  while((*p)->left != NULL)
    p = &(*p)->left;

  x = *p;
  *p = NULL;

  return x;
}

void delete(node **p) {
  node *x, *y;
  x = *p;

  if((*p)->left == NULL && (*p)->right == NULL) {
    *p = NULL;
  } else if((*p)->left == NULL) {
    *p = (*p)->right;
  } else if((*p)->right == NULL) {
    *p = (*p)->left;
  } else {
    y = deleteMin(&(*p)->right);
    y->right = (*p)->right;
    y->left = (*p)->left;
    *p = y;
  }

  free(x);
}

node **find(int key) {
  node **x;
  x = &root;

  while((*x) != NULL && (*x)->key != key) {
    if(key < (*x)->key)
      x = &(*x)->left;
    else if(key > (*x)->key)
      x = &(*x)->right;
  }

  return x;
}

void insert(int key) {
  node *new, **x;

  x = &root;
  while(*x != NULL) {
    if(key < (*x)->key)
      x = &(*x)->left;
    else if(key > (*x)->key)
      x = &(*x)->right;
  }

  new = (node *)malloc(sizeof(node));
  new->left = NULL;
  new->right = NULL;
  new->key = key;
  *x = new;

  return;
}

void inorder(node *current) {
  if(current == NULL)
    return;

  inorder(current->left);
  printf(" %d", current->key);
  inorder(current->right);
}

void preorder(node *current) {
  if(current == NULL)
    return;

  printf(" %d", current->key);
  preorder(current->left);
  preorder(current->right);
}

void print() {
  inorder(root);
  printf("\n");

  preorder(root);
  printf("\n");
}

int main() {
  int i, n, key;
  char command[20];

  scanf("%d", &n);
  for(i = 0;i < n;i++) {
    scanf("%s", command);
    switch(command[0]) {
      case 'i':
        scanf("%d", &key);
        insert(key);
        break;
      case 'p':
        print();
        break;
      case 'f':
        scanf("%d", &key);
        *(find(key)) != NULL ? printf("yes\n") : printf("no\n");
        break;
      case 'd':
        scanf("%d", &key);
        delete(find(key));
        break;
    }
  }

  return 0;
}



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

#define fs first
#define se second
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define pb emplace_back

using pii = pair<int, int>;
using vi = vector<int>;
using lint = long long;

const int inf = 1001001001;
const lint linf = 1001001001001001001ll;
const int mod = 1e9 + 7;
const int dx[]{0, 1, 0, -1, -1, -1, 1, 1}, dy[]{1, 0, -1, 0, -1, 1, -1, 1};

template<typename T> inline bool chmin(T &a, T b) { if (a > b) { a = b; } return a > b; }
template<typename T> inline bool chmax(T &a, T b) { if (a < b) { a = b; } return a < b; }
template<typename T> inline void print(const T &x, string s = "\n") { cout << x << s; }
template<typename T> inline void print(const vector<T> &v, string s = " ") 
{ rep(i, v.size()) cout << v[i] << (i + 1 == v.size() ? "\n" : s); }
inline bool inside(int y, int x, int H, int W) { return 0 <= y && y < H && 0 <= x && x < W; }
inline lint in() { lint x; std::cin>>x; return x; }

vector<lint> h;
int n;
int a, b, d;

bool f(lint m) {
	lint cnt = 0;
	rep(i, n) {
		lint H = h[i] - m * b;
		if (H <= 0) continue;
		cnt += (H + d - 1) / d;
	}

	return cnt <= m;
}

int main() {
	cin >> n >> a >> b;
	d = a - b;

	lint mazai = 0;
	rep(i, n) { h.pb(in()); chmax(mazai, h[i]); }

	lint l = 0, r = mazai / b + 1000;
	while (r - l > 1) {
		lint m = (l + r) / 2;
		if (f(m)) {
			r = m;
		} else {
			l = m;
		}
	}

	if (f(l)) {
		r = l;
	} else {
		l = r;
	}

	cout << l << endl;
}


Measured memory_bytes: 1400
#include <iostream>
#include <vector>
#include <string>
#include <stdlib.h>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <climits>
#include <iomanip>
#include <deque>

using namespace std;

int main()
{
  int64_t L;

  cin >> L;

  cout << fixed << setprecision(8)
       << pow(L, 3) / 27.0 << endl;

  return 0;
}


Measured memory_bytes: 256
MOD = 10**9+7

class Combination:
    def __init__(self, n_max=10**6, mod=10**9+7):
        # self._n_max = n_max
        self._fac, self._finv, self._inv = [0]*n_max, [0]*n_max, [0]*n_max
        self._fac[0], self._fac[1] = 1, 1
        self._finv[0], self._finv[1] = 1, 1
        self._inv[1] = 1
        for i in range(2, n_max):
            self._fac[i] = self._fac[i - 1] * i % MOD
            self._inv[i] = MOD - self._inv[MOD%i] * (MOD // i) % MOD
            self._finv[i] = self._finv[i - 1] * self._inv[i] % MOD
    def com(self, n, r):
        if n < r: return 0
        if n < 0 or r < 0: return 0
        return self._fac[n] * (self._finv[r] * self._finv[n - r] % MOD) % MOD



def main():
    comb = Combination(10**5+10, MOD)
    n = int(input())
    al = list(map(int, input().split()))
    same_num = 0
    aset = set()
    for a in al:
        if a in aset: 
            same_num = a
            break
        else:
            aset.add(a)
    
    l,r = -1,-1
    for i, a in enumerate(al):
        if a == same_num:
            if l == -1: l = i
            else: r = i

    l = l
    r = (n+1)-r-1

    # l_coms = [0]*(l+1)
    # r_coms = [0]*(r+1)

    # for i in range(l+1):
    #     l_coms[i] = comb.com(l,i)
    # for i in range(r+1):
    #     r_coms[i] = comb.com(r,i)

    for k in range(1,n+2):
        all_cnt = comb.com(n+1,k)
        ng_cnt = comb.com(l+r,k-1)
        ans = all_cnt-ng_cnt
        ans %= MOD
        print(ans)

    # l_cnts = [0]*(l+1)
    # r_cnts = [0]*(r+1)
    # for 


if __name__ == "__main__":
    main()

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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

signed main(){
	int a,b;
	cin>>a>>b;
	if((a+b)&1)cout<<"IMPOSSIBLE"<<endl;
	else cout<<(a+b)/2<<endl;
	return 0;
}

Measured memory_bytes: 256
import java.math.BigInteger;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main
{
	public static void main(String[] args)
	{


        // Mapの宣言
        Map<Integer, String> mMap = new HashMap<Integer, String>();

		Scanner sc = new Scanner(System.in);
		int x = sc.nextInt();
		int y = sc.nextInt();
		int na = sc.nextInt();
		int nb = sc.nextInt();
		int nc = sc.nextInt();

		Integer[] a = new Integer[na];
		Integer[] b = new Integer[nb];
		Integer[] c = new Integer[nc+x+y];

		for (int i=0; i<na; i++) {
			a[i]=new Integer(sc.nextInt());
		}
		for (int i=0; i<nb; i++) {
			b[i]=new Integer(sc.nextInt());
		}
		for (int i=0; i<nc; i++) {
			c[i]=new Integer(sc.nextInt());
		}
		sc.close();

		Arrays.sort(a, Collections.reverseOrder());
		Arrays.sort(b, Collections.reverseOrder());

		for (int i=0; i<x; i++) {
			c[i+nc]=a[i];
		}

		for (int i=0; i<y; i++) {
			c[i+nc+x]=b[i];
		}

		Arrays.sort(c, Collections.reverseOrder());

        BigInteger ans = BigInteger.ZERO;
        for (int i = 0; i<x+y; i++) {
        	ans = ans.add(BigInteger.valueOf((Integer)c[i]));
       	}
		System.out.println(ans.toString());
	}
}


Measured memory_bytes: 101388
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <map>
#include <list>
#include <iterator>
#include <queue>
#include <stack>
#include <deque>
#include <sstream>
#include <algorithm>
#include <numeric>
#include <string>
#include <cmath>
#include <complex>
#include <functional>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <cstdlib>
#include <cctype>

#define REP(i,m,n) for(int i=m;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define rp(i,c) rep(i,(int)c.size())
#define fr(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define mp make_pair
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define rall(u) (u).rbegin(),(u).rend()
#define dbg(x) cerr<<#x<<" = "<<(x)<<endl
#define v_delete(a,b) (a).erase(remove((a).begin(), (a).end(), b), (a).end())
#define v_unique(a) (a).erase(unique((a).begin(), (a).end()), (a).end())
#define VV(T) vector<vector< T > >
#define init(a,b) memset((a), (b), sizeof((a)))
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
const int inf=1<<28;
const double INF=1e10,EPS=1e-9;


template<class T>int SIZE(T a){return a.size();}
template<class T>string IntToString(T num){string res;stringstream ss;ss<<num;return ss.str();}
template<class T>T StringToInt(string str){T res=0;for(int i=0;i<SIZE(str);i++)res=(res*10+str[i]-'0');return res;}
template<class T>T gcd(T a,T b){if(b==0)return a;return gcd(b,a%b);}
template<class T>T lcm(T a,T b){return a/gcd(a,b)*b;}

template <class T> void input(T& a, int n) { for (int i = 0; i < n; ++i) cin >> a[i]; }
template <class T> void input(T* a, int n) { for (int i = 0; i < n; ++i) cin >> a[i]; }
typedef pair<int,int> pii;

inline bool IN(int x, int y, int w, int h)
{
    return 0 <= x && x < w && 0 <= y && y < h;
}


int main()
{
	int l[5];
	rep(i,5){
		cin >> l[i];
	}
	sort(l,l+5,greater<int>());
	rep(i,4){
		cout << l[i] << " ";
	}
	cout << l[4] << endl;

}

Measured memory_bytes: 1176
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            var q = Array.ConvertAll(Console.ReadLine().Split(), int.Parse).ToList();

            //軽油
            int tmp = q[2];

            q.Sort();

            //経由地店が中央にあるか　
            if (tmp == q[1])
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }

        }
        
    }
}


Measured memory_bytes: 11220
<?php
/*
    Problem URL : http://abc051.contest.atcoder.jp/tasks/abc051_b

    Score  :
    Result :
    Time   : ms
    Memory : KB
 */

fscanf(STDIN, "%d %d", $K, $S);

for ($i = 0; $i <= $K; $i++) {
    $rest = $S - $i;
    if (0 <= $rest && $rest <= $K + $K) {
        $ans += min($rest, $K + $K - $rest) + 1;
    }
}

echo $ans . PHP_EOL;


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

int string_compar(const void *a, const void *b)
{
    return(strcmp(*(char**)a, *(char**)b));
}

int main()
{
  long n = 0;
  int k = 0;
  long dig = 1;
  int cnt = 0;

  scanf("%d %d", &n,&k);
  while(n/dig > 0)
  {
    dig = dig * k;
    cnt++;
  }

  printf("%d", cnt);

  //qsort((void*)ary, n, sizeof(char*), string_compar);

    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD=1000000007;
const int N_MAX=2010;
ll fact[N_MAX],factinv[N_MAX];

/*階乗
ll fact(int n){
  if(n==0){return 1;}
  return fact((n-1)%MOD)*n%MOD;
}
毎回の出力が一つだけならメモ化しなくていいので先に階乗を計算する
*/

//繰り返し2乗法
ll power(ll a,ll b){
  ll res=1;
  while(b>0){
    if(b&1) res=res*a%MOD;
    a=a*a%MOD;
		b>>=1;
	}
  return res;
}
//二項係数
ll comb(ll n, ll r){
	ll res;
	if(n<0||r<0||n<r){res=0;}
	else{res=(fact[n]*factinv[r])%MOD*factinv[n-r]%MOD;}
	return res;
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n,k;
	cin>>n>>k;//Binの分子
	fact[0]=1;
        // 階乗の計算
	for(int i=1;i<=n;i++){fact[i]=fact[i-1]*i%MOD;}
	factinv[n]=power(fact[n], MOD-2);
        // 逆元の計算
	for(int i=n-1; i>=0; --i){factinv[i]=factinv[i+1]*(i+1)%MOD;}
  for(int i=1;i<=k;i++){
    cout<<comb(n-k+1,i)*comb(k-1,i-1)%MOD<<endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
typedef long long ll;
#define ALL(v) v.begin(), v.end()
#define vmax(v) *max_element(ALL(v))
#define vmin(v) *min_element(ALL(v))
#define chmax(x, a) x = max(x, a)
#define chmin(x, a) x = min(x, a)

int main() {
    int L, R, d; cin >> L >> R >> d;
    cout << R/d - (L-1)/d << endl;
}


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

int main(){
  int n;
  cin>>n;
  vector<int> s(n);
  int ans=0;
  rep(i,n) {
    cin>>s[i];
    ans+=s[i];
  }
  sort(s.begin(),s.end());
  if(ans%10==0){
    rep(i,n){
      if(s[i]%10!=0){
        ans-=s[i];
        break;
      }
    }
  }
  if(ans%10==0)cout<<0<<endl;
  else cout<<ans<<endl;
}

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

template<typename T, typename Q>
istream &operator>>(istream &is, pair<T, Q> &p) {
	return is >> p.first >> p.second;
}

template<typename T>
istream &operator>>(istream &is, vector<T> &v) {
	for (auto &x : v) is >> x;
	return is;
}

template<typename T, typename Q>
ostream &operator<<(ostream &os, pair<T, Q> p) {
	return os << "(" << p.first << ", " << p.second << ")";
}

template<typename T>
ostream &operator<<(ostream &os, vector<T> v) {
	os << "[";
	for (auto it = v.begin(); it != v.end(); it++)
		os << (it == v.begin() ? "" : ", ") << *it;
	return os << "]";
}

template<typename T, typename Q>
ostream &operator<<(ostream &os, map<T, Q> m) {
	os << "[";
	for (auto it = m.begin(); it != m.end(); it++) 
		os << (it == m.begin() ? "" : ", ") << *it;
	return os;
}
#define imie(...) " [" << #__VA_ARGS__": " << (__VA_ARGS__) << "] "

int main() {
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	string s; cin >> s;
	for (int i = 0; i < s.size() - 1; i++) {
		if (s[i] == s[i + 1]) {
			cout << "Bad\n";
			return 0;
		}
	}
	cout << "Good\n";
}


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

int main()
{
    int N, K;
    cin >> N >> K;
    pair<int, int> a[N];
    for (int i = 0; i < N; i++)
    {
        cin >> a[i].second >> a[i].first;
    }
    sort(a, a + N);
    reverse(a, a + N);

    stack<int> s;
    long long x = 0;
    long long sum = 0;
    bool used[100000 + 1] = {};
    for (int i = 0; i < K; i++)
    {
        sum += a[i].first;
        if (!used[a[i].second])
        {
            x++;
            used[a[i].second] = true;
        }
        else
        {
            s.push(a[i].first);
        }
    }
    long long ans = sum + x * x;

    for (int i = K; i < N; ++i)
    {
        if (x >= K)
        {
            break;
        }
        if (!used[a[i].second])
        {
            x++;
            used[a[i].second] = true;
            long long minimum = s.top();
            s.pop();
            sum -= minimum;
            sum += a[i].first;
            ans = max(ans, sum + x * x);
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 1280
#include<bits/stdc++.h>
 
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("-funroll-loops")
#pragma GCC target("avx,sse4")
 
#define mms(a,n) memset(a,0,sizeof((a)[0])*(n))
#define mmp(a,b,n) memcpy(a,b,sizeof((b)[0])*(n))
#define lowbit(x) ((x)&-(x))
#define pb push_back
#define fi first
#define se second
#define debug(...) fprintf(stderr,__VA_ARGS__)
#define fo(i,l,r) for(register int i=l,_lim_=r;i<=_lim_;i++)
#define fd(i,r,l) for(register int i=r,_lim_=l;i>=_lim_;i--)
#define fos(i,l,r,d) for(register int i=l,_lim_=r;i<=r;i+=d)
#define fol(i,l,r) for(register ll i=l,_lim_=r;i<=_lim_;i++)
#define fdl(i,r,l) for(register ll i=r,_lim_=l;i>=_lim_;i--)
#define fosl(i,l,r,d) for(register ll i=l,_lim_=r;i<=r;i+=d)
#define Clear(a) memset(a,0,sizeof(a))
#define Copy(a,b) memcpy(a,b,sizeof(b))
#define ALL(v) v.begin(),v.end()
#define SZ(v) ((int)v.size())
#define sqr(x) ((x)*(x))
#define GCD __gcd

using namespace std;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ldb;
typedef double db;
typedef pair<int,int> pi;
typedef vector<int> VI;
typedef vector<VI> VII;

namespace io{
	const int L=(1<<21)+1;
	char ibuf[L],*iS,*iT,obuf[L],*oS=obuf,*oT=obuf+L-1,c,st[55];int f,tp;
	#ifdef whzzt
		#define gc()getchar()
	#else
		#define gc()(iS==iT?(iT=(iS=ibuf)+fread(ibuf,1,L,stdin),(iS==iT?EOF:*iS++)):*iS++)
	#endif
	inline void flush(){fwrite(obuf,1,oS-obuf,stdout);oS=obuf;}
	inline void putc(char x){*oS++=x;if(oS==oT)flush();}
	template<class I>
	inline void gi(I&x){
		for(f=1,c=gc();c<'0'||c>'9';c=gc())if(c=='-')f=-1;
		for(x=0;c<='9'&&c>='0';c=gc())x=x*10+(c&15);x*=f;
	}
	template<class I>
	inline void print(I x){
		if(!x)putc('0');if(x<0)putc('-'),x=-x;
		while(x)st[++tp]=x%10+'0',x/=10;
		while(tp)putc(st[tp--]);
	}
	inline void gs(char*s,int&l){
		for(c=gc();c<'a'||c>'z';c=gc());
		for(l=0;c<='z'&&c>='a';c=gc())s[l++]=c;
	}
	inline void ps(const char*s){
		fo(i,0,strlen(s)-1)putc(s[i]);
	}
};
using io::putc;
using io::gi;
using io::gs;
using io::ps;
using io::print;

const int N=305,M=26;

char s[N];
int n,k,dp[N][N][N];
bool vi[N][N][N];

inline void upd(int&x,int y){x>y?:x=y;}
int dfs(int a,int l,int r){
	if(a<0)return -N;
	if(l>=r)return l==r;
	if(a*2>=r-l)return r-l+1;
	if(vi[a][l][r])return dp[a][l][r];
	vi[a][l][r]=true;
	int&ret=dp[a][l][r];
	upd(ret,dfs(a-(s[l]!=s[r]),l+1,r-1)+(l<r)+1);
	upd(ret,dfs(a,l+1,r));upd(ret,dfs(a,l,r-1));
	return ret;
}

int main(){
	scanf("%s",s+1);
	n=strlen(s+1);
	scanf("%d",&k);
	printf("%d\n",dfs(k,1,n));
	return 0;
}

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

int main() {
	ll N;
	cin >> N;
	if (N < 30)
		cout << "No";
	else
		cout << "Yes";
}

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

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

	int n;
	cin >> n;
	ll total = 0;
	for (int i = 1; i <= n; ++i) {
		if (i%3 == 0 || i%5 == 0) continue;
		total += i;
	}
	cout << total << endl;
}

Measured memory_bytes: 3652
open System.Linq
let read conv = stdin.ReadLine() |> conv
let reads n =
    let mutable acc = System.Collections.Generic.List<int>()
    for i = 1 to n do
        acc.Add (stdin.ReadLine() |> int)
    acc

let n = read int
let ls = reads n
let ms = ls.OrderBy(fun x -> x).ToList()
for i = 0 to (n-1) do
    printfn "%d" (if ls.[i] = ms.[n-1] then ms.[n-2] else ms.[n-1])


Measured memory_bytes: 23604
N, M = map(int, raw_input().split())
G = {v: set() for v in range(N+1)}
for i in range(M):
    a, b = map(int, raw_input().split())
    G[a].add(b)
    G[b].add(a)
ok = False
for v in range(N+1):
    if (1 in G[v]) and (N in G[v]):
        ok = True
        break
print "POSSIBLE" if ok else "IMPOSSIBLE"

Measured memory_bytes: 91672
import java.util.*;
class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String S = sc.next();
    String S1 = S.substring(0,1);
    String S2 = S.substring(1,2);
    String S3 = S.substring(2,3);
    String S4 = S.substring(3,4);
    if(S1.equals(S2) || S2.equals(S3) || S3.equals(S4)){
      System.out.println("Bad");
    }else{
      System.out.println("Good");
    }
  }
}

Measured memory_bytes: 21844
g=proc{gets.split.map &:to_i};n, m = g.call;z = n + 1;states = [];z.times { states << [] };w = [];
m.times do
  p, y = g.call;states[p] << y;w << [p, y];
end
hash = {}
z.times do |i|
  states[i].sort.each_with_index do |y, i|
    hash[y] = i + 1
  end
end
w.each do |v|
  p, y = v
  puts format('%06d%06d', p, hash[y])
end

Measured memory_bytes: 34920
/*
ID: anonymo14
TASK: wormhole
LANG: C++                 
*/
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<pair<int,int>> vpii;

#define F first
#define S second
#define PU push
#define PUF push_front
#define PUB push_back
#define PO pop
#define POF pop_front
#define POB pop_back

#define REP(i,a,b) for(int i=a; i<=b; i++)

#define MOD 1000000007

void solve(int test_case) {
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	cout<<max(a*b,c*d);
}

int main() {
	
	////// FILE BASED IO////
	//freopen("wormhole.in", "r", stdin);
	//freopen("wormhole.out", "w", stdout);
	///////////////
	
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t=1;
	//cin>>t;
	REP(i,1,t) {
		solve(i);
	}
	return 0;
}	


Measured memory_bytes: 3616
#include <bits/stdc++.h>
#define FOR(i, k, n) for(int i = (k); i < (n); i++)
#define FORe(i, k, n) for(int i = (k); i <= (n); i++)
#define FORr(i, k, n) for(int i = (k)-1; i > (n); i--)
#define FORre(i, k, n) for(int i = (k)-1; i >= (n); i--)
#define REP(i, n) FOR(i, 0, n)
#define REPr(i, n) FORre(i, n, 0)
#define ALL(x) (x).begin(), (x).end()
#define ALLr(x) (x).rbegin(), (x).rend()
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;
using ll = long long;

const int INF = 1001001001;

vector<int> l(8);
int N, A, B, C;
int f(int i, int a, int b, int c){
  if(i == N){
    if(!a || !b || !c) return INF;
    return abs(A-a)+abs(B-b)+abs(C-c);
  }

  int ans = f(i+1, a, b, c);
  chmin(ans, f(i+1, a+l[i], b, c) + (a ? 10 : 0));
  chmin(ans, f(i+1, a, b+l[i], c) + (b ? 10 : 0));
  chmin(ans, f(i+1, a, b, c+l[i]) + (c ? 10 : 0));

  return ans;
}

int main(void){
  cin >> N >> A >> B >> C;
  l.resize(N);
  REP(i, N) cin >> l[i];
  cout << f(0, 0, 0, 0) << endl;
  return 0;
}

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


int main(void){
	int n;
	string s;
	cin >> n;
	if(n==0){
		cout << 0 << endl;
	}
	while(true){
		if(n == 0)break;
		if(n%2!=0){
			--n;
			s = "1" + s;
		}else{
			s = "0" + s;
		}
		n /= -2;
	}
	cout << s << endl;
	return 0;
}

Measured memory_bytes: 888
#include<bits/stdc++.h>
#define fast ios::sync_with_stdio(false), cin.tie(0);
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define endl '\n'

using namespace std;

main()
{
    fast;
    double l;
    cin>>l;
    double ans=(l*l*l)/27.0;
    cout<<setprecision(12);
    cout<<fixed;
    cout<<ans<<endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#include<cmath>
using namespace std;
#define int long long int
#define pb push_back
#define ub upper_bound
#define lb lower_bound
#define mp make_pair
#define pii pair<int,int>
#define piii pair< int,pair<int,int> >
#define F first
#define S second
#define all(a) a.begin(),a.end()
#define endl '\n'
#define boost ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define file freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define N 2005
#define mod 1000000007
#define inf 1e17
#define pf push_front
#define pob pop_back
#define pof pop_front
#define debug1(x) cout<<#x<<" "<<x<<endl;
#define debug2(x,y) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<endl;
#define debug3(x,y,z) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<" "<<#z<<" "<<z<<endl;

int32_t main()
{
   // boost
    int t=1;
    //cin>>t;
    while(t--)
    {
        int n,k;
        cin>>n>>k;
        int a[n];
        for(int i=0;i<n;i++)
        cin>>a[i];
        int dp[n+1];
        for(int i=0;i<n+1;i++)
        {
            dp[i]=1e18;
        }
        dp[0]=0;
        dp[1]=abs(a[1]-a[0]);
        if(n>2)
        {
        for(int i=2;i<n;i++)
        {
            for(int j=1;j<=k&&i-j>=0;j++)
            {
                dp[i]=min(dp[i],abs(a[i]-a[i-j])+dp[i-j]);
               // debug1(abs(a[i]-a[i-j])+dp[i-j]);
            }
           // cout<<endl;
        }
        }
        //for(int i=0;i<n;i++)
        cout<<dp[n-1]<<" ";
        //cout<<endl;
            }


    

}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<P,int> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=998244353;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

const int M=26;
ll n;

int main(){
	cin>>n;
	ll m=1,s=M,t=M;
	while(n>s){
		t*=M;
		s+=t;
		m++;
	}
	n-=1+s-t;
	t/=M;
	for(int i=0;i<m;i++){
		cout<<(char)('a'+n/t%M);
		t/=M;
	}
	cout<<endl;
}

Measured memory_bytes: 3648
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"

using namespace std;

const long long int MOD = 1000000007;


long long int N, M, K, H, W, L, R;

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

	cin >> N;
	vector<long long int>v(N);
	for (int i = 0; i < N; i++) {
		cin >> v[i];
	}
	if (v[0]) {
		cout << -1 << endl;
		return 0;
	}
	int zero = 0;
	for (int i = 0; i < N; i++) {
		if (!v[i]) {
			zero = i;
		}
		if (v[i] + zero - i > 0) {
			cout << -1 << endl;
			return 0;
		}
	}
	for (int i = 1; i < N; i++) {
		if (v[i] - v[i - 1] > 1) {
			cout << -1 << endl;
			return 0;
		}
	}
	int index = MOD;
	long long int ans = 0;
	for (int i = N - 1; i > 0; i--) {
		if (i - v[i] < index) {
			ans += v[i];
			index = i - v[i];
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 1792
using System;
using System.Linq;
using System.Threading.Tasks;
using System.Collections.Generic;

static class Program
{
  static void Main()
  {
    int inputVal = int.Parse(Console.ReadLine());
    List<string> lines = new List<string>();
    for (int i = 0; i < inputVal; i++)
    {
      lines.Add(Console.ReadLine());
    }
    var restrants = lines.Select((line, idx) =>
    {
      var words = line.Split(' ');
      return new { Idx = idx + 1, City = words[0], Value = int.Parse(words[1]) };
    });
    var result = restrants
      .OrderByDescending(x => x.Value)
      .GroupBy(x => x.City)
      .OrderBy(x => x.Key)
      .SelectMany(x => x);
    foreach (var item in result)
    {
      Console.WriteLine(item.Idx);
    }
  }
}

Measured memory_bytes: 13920
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	  public static void main(String[] args)throws IOException{
		    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		    String inputValue = br.readLine();
		    String[] inputArray = inputValue.split(" ");

		    int a = Integer.valueOf(inputArray[0]);
		    int b = Integer.valueOf(inputArray[1]);

		    System.out.println(a * b + " " + 2*(a+b));
		  }

}

Measured memory_bytes: 24068
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned int uint;
typedef unsigned char uchar;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;

#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();i++)
#define RFOR(i,c) for(__typeof((c).rbegin())i=(c).rbegin();i!=(c).rend();i++)
#define ALL(container) (container).begin(), (container).end()
#define RALL(container) (container).rbegin(), (container).rend()
#define SZ(container) ((int)container.size())
#define mp(a,b) make_pair(a, b)
#define pb push_back
#define eb emplace_back
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define __builtin_popcount __builtin_popcountll

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; }
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
    os<<"["; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"]"; return os;
}
template<class T> ostream& operator<<(ostream &os, const set<T> &t) {
    os<<"{"; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"}"; return os;
}
template<class S, class T> ostream& operator<<(ostream &os, const map<S, T> &t) {
    os<<"{"; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"}"; return os;
}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<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> 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);}

const int INF = 1<<28;
const double EPS = 1e-8;
const int MOD = 1000000007;


int T, n, m;

int main(int argc, char *argv[]){
    ios::sync_with_stdio(false);
    string s;
    while(cin >> s >> m){
        for(int i = 0;i < s.size(); i += m) cout << s[i];
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 256
def main():
    runrun = {1: [1, 2, 3, 4, 5, 6, 7, 8, 9]}
    for i in range(2, 13):
        r = []
        for v in runrun[i-1]:
            num = v % 10
            for j in range(max(0, num-1), min(10, num+2)):
                r.append(v*10+j)
        runrun[i] = r

    mrunrun = []
    for _, v in runrun.items():
        mrunrun.extend(v)
    mrunrun.sort()
    k = int(input())
    print(mrunrun[k-1])


if __name__ == '__main__':
    main()


Measured memory_bytes: 138464
//666yuchen
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<string>
#include<cstdlib>
using namespace std;
string a;
int z,y;
int main()
{
  cin>>a;
  for(int i=0;i<a.size();i++)if(a[i]=='A'){z=i;break;}
  for(int i=a.size()-1;i>=0;i--)if(a[i]=='Z'){y=i;break;}
  cout<<y-z+1;
  return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <algorithm>
#include <unordered_map>
#include <numeric>

#define rep(i, a, b) for (ll i = a; i < b; i++)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> pll;
typedef unordered_map<string, ll> u_map;

// input
void input() {}
template <class Head, class... Tail>
void input(Head &&a, Tail &&... b)
{
    cin >> a;
    input(forward<Tail>(b)...);
}

template <class V>
void input(vector<V> &v)
{
    for_each(v.begin(), v.end(), [](auto &i) { input(i); });
}

// output
template <class V>
void output(vector<V> &v)
{
    for_each(v.begin(), v.end(), [](auto &x) { cout << x << " "; });
    cout << endl;
}

// math functions
ll mpow(ll a, ll n, ll p)
{
    ll x = 1;
    while (n > 0)
    {
        if (n & 1)
        {
            x = a * x % p;
        }
        a = a * a % p;
        n >>= 1;
    }

    return x;
}

ll mfact(ll n, ll p)
{
    ll res = 1;
    for (ll i = 2; i <= n; i++)
    {
        res = res * i % p;
    }
    return res;
}

ll mcomb(ll n, ll r, ll p)
{
    if (n == 0 && r == 0)
    {
        return 1;
    }
    if (n < r || n < 0 || r < 0)
    {
        return 0;
    }

    ll a = mfact(n, p);
    ll b = mfact(n - r, p);
    ll c = mfact(r, p);
    return (((a * mpow(b, p - 2, p)) % p) * mpow(c, p - 2, p)) % p;
}

ll gcd(ll a, ll b)
{
    if (a < b)
    {
        a ^= b;
        b ^= a;
        a ^= b;
    }
    return b ? gcd(b, a % b) : a;
}

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

int main()
{
    int N, M;
    input(N, M);

    vector<int> a(N, 0);
    int sum = 0;
    rep(i, 0, N)
    {
        input(a[i]);
        sum += a[i];
    }

    int cnt = 0;
    rep(i, 0, N)
    {
        cnt += 4 * M * a[i] >= sum;
    }

    cout << (cnt >= M ? "Yes" : "No") << endl;

    return 0;
}

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

using namespace std ;

long long a [ 200001 ] , c , d , e , f , g , h , k , l , m , n ;

int mn = 1e9 ;

int mx = -1e9 , x ;

int main ()
{
    for ( int i = 1 ; i <= 3 ; ++ i ){
        cin >> x ;
        mn = min ( x , mn ) ;
        mx = max ( x , mx ) ;
    }
    cout << mx - mn ;
}
    

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int p = 0; int q = 0;
		int[] usedp = new int[n];
		for (int i = 0; i < n; i++) usedp[i] = 0;
		int[] usedq = new int[n];
		for (int i = 0; i < n; i++) usedq[i] = 0;
		for (int i = 0; i < n-1; i++) {
			int a = sc.nextInt();
			int b = 0;
			for (int j = 0; j < a-1; j++) {
				if(usedp[j] == 0) b++;
			}
			p += b*fact(n-i-1);
			usedp[a-1] = 1;
		}
		sc.next();
		for (int i = 0; i < n-1; i++) {
			int a = sc.nextInt();
			int b = 0;
			for (int j = 0; j < a-1; j++) {
				if(usedq[j] == 0) b++;
			}
			q += b*fact(n-i-1);
			usedq[a-1] = 1;
		}
		System.out.println(Math.abs(p-q));
	}
	private static int fact(int n) {
	    int a = 1;
		while(n != 0) {
			a = a*n;
			n = n-1;
		}
		return a;
	}
}

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

int main(){
    int N;
    cin >> N;
    for(int i=0; i<N; ++i){
        int gx, gy;
        cin >> gx >> gy;
        
        // ?§???????????????????????????????????????£?¨????0??§???????????????????????????
        // ???????????????????§????????????¨????????¨??????
        // ????????????????????\????????´??? = 0
        // ??????????????\???????????´??? = 1
        // ??????????????\???????????´??? = 2
        // ??????????????????????????\???????????´??? = 3 (=1+2)
        int movable[16][16]={};
        
        for(int i=0; i<=gx; ++i){
            movable[i][0] += 1;
        }
        for(int j=0; j<=gy; ++j){
            movable[0][j] += 2;
        }
        
        int M;
        cin >> M;
        for(int i=0; i<M; ++i){
            int x1,y1,x2,y2;
            cin >> x1 >> y1 >> x2 >> y2;
            if(x1 == x2){
                movable[x1][max(y1,y2)] += 1;
            } else {
                movable[max(x1,x2)][y1] += 2;
            }
        }
        
        int route[16][16] = {};
        for(int i=0; i<=gx; ++i){
            for(int j=0; j<=gy; ++j){
                switch(movable[i][j]){
                    case 0:
                        route[i][j] = route[i-1][j] + route[i][j-1];
                        break;
                    case 1:
                        route[i][j] = route[i-1][j];
                        break;
                    case 2:
                        route[i][j] = route[i][j-1];
                        break;
                    case 3:
                        if(i == 0 && j == 0){
                            route[0][0] = 1;
                            // ?????????????????????????????????
                        } else {
                            route[i][j] = 0;
                        }
                        break;
                    default:
                        cout << movable[i][j] << endl;
                }
            }
        }
        if(route[gx][gy] != 0){
            cout << route[gx][gy] << endl;
        } else {
            cout << "Miserable Hokusai!" << endl;
        }
    }
}

Measured memory_bytes: 3088
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll inf = 1e9;
#define Fast    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define sz      300005

string s,p;

int main(){
    Fast;
    int a,b,c, i,j,k, n,m,t, cs=1;

    cin>>s>>p;
    for(i=0; i<s.size(); i++){
        if(s[i]!=p[i]){
            cout<<"No"<<endl;
            return 0;
        }
    }
    cout<<"Yes"<<endl;



    return 0;
}



Measured memory_bytes: 3604
#include<cstdio>
int main()
{
	int n,ans=0;
	scanf("%d",&n);
	int a[110];
	for(int i=1;i<=n;i++)
	{
	scanf("%d",&a[i]);
	ans+=a[i];
}
	int m;
	scanf("%d",&m);
	int b[110],c[110],num[110];
	for(int i=1;i<=m;i++)
	{
		num[i]=ans;
		scanf("%d%d",&b[i],&c[i]);
		int e=a[b[i]]-c[i];
		num[i]-=e;
	}
	for(int i=1;i<=m;i++)
	printf("%d\n",num[i]);
	return 0;
	}

Measured memory_bytes: 128
s=list(input())
q=0
if s[1]=="R":
    q=1
    if s[0]=="R":
        q+=1
    if s[2]=="R":
        q+=1
else:
    if s[0]=="S" and s[2]=="S":
        q=0
    else:
        q=1
print(q)

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

long long monster(long long x){
  if(x==1)
    return 1;
  else
    return 1+2*monster(x/2);
}
int main(){
  long long h;
  cin >> h;
  cout << monster(h) << endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
 
int main(void){
    int N,X,T,x;
    scanf("%d %d %d",&N,&X,&T);
    x = N / X * T;
    int k = 0;
    k = N - N /X * X ;
    if(k == 0){
        printf("%d\n",x);
        return 0;
    }
    
    if(k == 0 || k <= X){
        k = T;
        printf("%d\n",x + k);
    }
    
 
}

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

int main() {
  ll N;
  cin>>N;
  ll count=0;
  map<int,int> M;
  rep(i,N){
    int a;
    cin>>a;
    M[a]++;
  }
  for (auto p : M) {
  auto v = p.second;
if(v%2==1){
  count++;
}
}
cout<<count<<endl;
}

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

const double eps = 1e-9;

bool same(double a, double b) { return a == b; }

struct P {
    double x, y;
    P() : x(0), y(0) {}
    P(double x, double y) : x(x), y(y) {}
    P operator + (P b) { return P(x + b.x, y + b.y); }
    P operator - (P b) { return P(x - b.x, y - b.y); }
    P operator * (double b) { return P(x * b, y * b); }
    P operator / (double b) { return P(x / b, y / b); }
    double operator * (P b) { return x * b.x + y * b.y; }
    double operator ^ (P b) { return x * b.y - y * b.x; }
    double abs() { return hypot(x, y); }
    P unit() { return *this / abs(); }
};

struct L{
    // ax + by + c = 0
    double a, b ,c, o;
    P pa, pb;
    L() : a(0), b(0), c(0), o(0), pa(), pb() {}
    L(P pa, P pb) : a(pa.y - pb.y), b(pb.x - pa.x), c(pa ^ pb), o(atan2(-a, b)), pa(pa), pb(pb) {}
    P project(P p) { return pa + (pb - pa).unit() * ((pb - pa) * (p - pa) / (pb - pa).abs()); }
    P reflect(P p) { return p + (project(p) - p) * 2; }
    double get_ratio(P p) { return (p - pa) * (pb - pa) / ((pb - pa).abs() * (pb - pa).abs()); }
    bool inside(P p) {
        double z = get_ratio(p);
        return z >= 0 && z <= 1;
    }
};

bool parallel(L x, L y) { return same(x.a * y.b, x.b * y.a); }

P intersect(L x, L y) { return P(-x.b * y.c + x.c * y.b, x.a * y.c - x.c * y.a) / (-x.a * y.b + x.b * y.a); }

int main() {
    int q; cin >> q; while (q--) {
        P p[4]; 
        for (int i = 0; i < 4; ++i) cin >> p[i].x >> p[i].y;
        L l1(p[0], p[1]), l2(p[2], p[3]);
        double ans = 1e12;
        auto update = [&] (P &p, L &l) {
            P z = l.project(p);
            if (l.inside(z)) ans = min(ans, (p - z).abs());
            ans = min({ans, (p - l.pa).abs(), (p - l.pb).abs()});
        };
        if (parallel(l1, l2)) {
            if ((p[2] - l1.project(p[2])).abs() < eps) {
                if (l1.inside(p[2]) || l1.inside(p[3]) || l2.inside(p[0]) || l2.inside(p[1])) ans = 0;
                else ans = min({ans, (p[0] - p[2]).abs(), (p[0] - p[3]).abs(), (p[1] - p[2]).abs(), (p[1] - p[3]).abs()});
            } else {
                update(p[2], l1);
                update(p[3], l1);
                update(p[0], l2);
                update(p[1], l2);
            }
        } else {
            P z = intersect(l1, l2);
            if (l1.inside(z) && l2.inside(z)) ans = 0;
            else {
                update(p[2], l1);
                update(p[3], l1);
                update(p[0], l2);
                update(p[1], l2);
            }
        }
        cout << fixed << setprecision(12) << ans << endl;
    }
}



Measured memory_bytes: 3532
#include <iostream>
#include <algorithm>
#include <cctype>

using namespace std;

#define loop(i,a,b) for(int i=(a);i<int(b);i++)
#define rep(i,b) loop(i,0,b)

int W,H;
string c[70];

bool comp(string const& a, string const& b){
    if(a.size() != b.size()) return a.size() < b.size();
    rep(i,a.size())if(a[i]!=b[i])return a[i] < b[i];
    return false;
}

string dp[70][70];

string rec(int x, int y){
    if(dp[y][x]!="@") return dp[y][x];
    string& res = dp[y][x] = c[y][x];
    if(y!=H-1 && isdigit(c[y+1][x])) res=max(res, c[y][x] + rec(x,y+1), comp);
    if(x!=W-1 && isdigit(c[y][x+1])) res=max(res, c[y][x] + rec(x+1,y), comp);
    return res;
}

int main(){
    while(cin>>W>>H && W|H){
        rep(i,H)cin>>c[i];
        rep(i,H)rep(j,W)dp[i][j]="@";
        string ans = "0";
        rep(i,H)rep(j,W)if(isdigit(c[i][j]) && c[i][j]!='0')ans=max(ans,rec(j,i), comp);
        cout<<ans<<endl;
    }
}

Measured memory_bytes: 1416
#include <iostream>

int main() {
    int a, b;
    int ans = 0;
    std::cin >> a >> b;
    if (a > b) {
        ans += a;
        --a;
    } else {
        ans += b;
        --b;
    }
    std::cout << ans + std::max(a,  b) << '\n';
    return 0;
}

Measured memory_bytes: 256
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define int long long
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001ll
#define fcout cout << fixed << setprecision(10)

using namespace std;

int dp[105][100005];

int MAXV = 100000;

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    int N, W;
    cin >> N >> W;

    vector<int> w(N), v(N);
    REP(i, N) cin >> w[i] >> v[i];

    FOR(i, 0, N) FOR(j, 0, MAXV) dp[i][j] = INF;

    dp[0][0] = 0;
    REP(i, N) {
        FOR(j, 0, MAXV) {
            dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]);
            if (j + v[i] <= MAXV) {
                dp[i + 1][j + v[i]] = min(dp[i][j + v[i]], dp[i][j] + w[i]);
            }
        }
    }

    int ans = 0;
    FOR(j, 0, MAXV) {
        if (dp[N][j] <= W)
        {
            ans = j;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 80128
#include <bits/stdc++.h>
#include <cstdio>
#define fastio {ios_base::sync_with_stdio(false); cin.tie(NULL);}
#define nln cout << '\n'
#define ll long long int
#define INF (ll)1e+12
#define MAX 300100
#define mp(i, j) make_pair(i, j)
#define here cout  << "here";nln;
#define mul(a, b, mod) (((a % mod) * (b % mod)) % mod)
#define add(a, b, mod) (((a % mod) + (b % mod)) % mod)
#define inf 100000
#define M 1000000000LL

using namespace std;

ll a[100100];

int main()
{
    ll n, i, ans = 0;

    cin >> n;

    for(i = 0; i < n; i++)cin >> a[i];

    for(i = 0; i < n; i++){
        if(a[i]&1){
            ans += a[i]/2;
            a[i] = 1;
        }
        else if(a[i]){
            ans += (a[i]/2)-1;
            a[i] = 2;
        }
    }

    for(i = 0; i < n-1; i++){
        if(a[i] == 1){
            if(a[i+1]){
                ans++;
                a[i]--;
                a[i+1]--;
            }
        }
    }

    for(i = 0; i< n; i++)if(a[i] == 2LL)ans++;

    cout << ans << endl;
}


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

using namespace std;

typedef long long ll;

int main() {
	int N; cin >> N;
	
	ll num = 3;
	int ans = 1;
	while (num < N) {
		num *= 3;
		ans++;
	}
	
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 1160
import java.util.*;
/*
import java.util.HashMap;
import java.util.Set;
import java.util.Scanner;
*/

class Graph<T> {

	private HashMap<T, Set<T> > graph;

	public Graph() {
		this.graph = new HashMap<T, Set<T> >();
	}

	public void addNode(T node) {
		if (! this.graph.containsKey(node)) {
			this.graph.put(node, new HashSet<T>());
		}
	}

	public void addEdge(T src, T dest) {
		this.graph.get(src).add(dest);
	}

	public Set<T> getEdges(T node) {
		return this.graph.get(node);
	}

	public Set<T> getNodes() {
		return this.graph.keySet();
	}

	private boolean has_cycle(T node, Set<T> active, Set<T> seen) {

		if (seen.contains(node)) {
			return false;
		}
		seen.add(node);
		active.add(node);
		for (T next_node : this.getEdges(node)) {
			if (active.contains(next_node) || this.has_cycle(next_node, active, seen)) {
				return true;
			}
		}
		active.remove(node);
		return false;
	}

	public Set<T> find_cycle(T start_node) {

		Set<T> seen = new HashSet<T>();
		Set<T> active = new HashSet<T>();

		this.has_cycle(start_node, active, seen);
		return active;

	}

	/*
	static class Node {

		int num;


		Node(int num) {
			this.num = num;
		}

	}
	
	static class Edge {

		Node src;
		Node dest;

		Edge(Node src, Node dest) {
			this.src = src; 
			this.dest = dest; 
		}

	}
	*/


}

public class Main {


	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);
		Graph<Integer> graph = new Graph<Integer>();

		int v = scan.nextInt();
		int e = scan.nextInt();
		for (int i = 0; i < e; i++) {
			int s = scan.nextInt();
			int t = scan.nextInt();

			graph.addNode(s);
			graph.addNode(t);
			graph.addEdge(s, t);
		}

		for (int n : graph.getNodes()) {
			if (graph.find_cycle(n).size() > 0) {
				System.out.println("1");
				return;
			}
		}
		System.out.println("0");
	}

}



Measured memory_bytes: 33092
import sys
input=sys.stdin.readline
import fractions

def main():
    N = int(input())
    A = list(map(int, input().split()))

    L = [0]*(N+1)
    R = [0]*(N+1)
    for i in range(1,N):
        L[i+1] = fractions.gcd(L[i],A[i-1])
    for i in range(N-1,-1,-1):
        R[i] = fractions.gcd(R[i+1],A[i])
    ma = 1
    for i in range(0,N+1):
        ma = max(ma, fractions.gcd(L[i], R[i]))
    print(ma)
    
if __name__ == '__main__':
    main()


Measured memory_bytes: 16168