akhauriyash/Code-Regression huggingface dataset:
#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;

vpll G[100100];
ll dist[100100];

// 葉から計算
void dfs1(ll v, ll p){
  for(auto &np: G[v]){
    if(np.first==p) continue;
    dfs1(np.first,v);
    chmax(dist[v],dist[np.first]+np.second);
  }
}

// 根から計算
ll dfs2(ll v, ll parent, ll p){
  vector<pii> child;
  child.emplace_back(0,-1); // 番兵(頂点が1個の場合)
  for(auto &np: G[v]){
    if(np.first==p) child.emplace_back(parent+np.second,np.first);
    else child.emplace_back(dist[np.first]+np.second,np.first);
  }
  sort(child.rbegin(),child.rend());
  ll res=child[0].first+child[1].first;
  for(auto &np: G[v]){
    if(np.first==p) continue;
    // 子に下る際、parent(pからの最遠距離)は基本的にchild[0].firstとなるが、これがその子の部分木の方向への距離ならば2番目の距離を渡す必要がある
    // 例えば1直線に連なる3つのノードからなる木を左から探索する場合を考えると、2番目のノードに移る際に最遠距離を渡してしまうと2番目のノードで重複して距離をカウントしてしまう
    chmax(res, dfs2(np.first, child[child[0].second==np.first].first, v));
  }
  return res;
}

signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  
  ll n; cin>>n;
  rep(i,n-1){
    ll a,b,w; cin>>a>>b>>w;
    G[a].emplace_back(b,w);
    G[b].emplace_back(a,w);
  }
  
  dfs1(n/2,-1);
  cout<<dfs2(n/2,0,-1)<<endl;
  
}


Measured memory_bytes: 20256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<list>
#include<queue>
#include<deque>
#include<stack>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 1000;
const int MAX_M = 1000;

const long long MOD = 1000000007;

/* typedef */

typedef vector<int> vi;
typedef set<int> si;
typedef long long ll;

/* global variables */

int n, m, nsc;
int scc[MAX_N];
vi nbrs[MAX_N], rnbrs[MAX_N];
si srnbrs[MAX_N];
bool used[MAX_N], roots[MAX_N];
stack<int> st;
ll dp[MAX_N][2];

/* subroutines */

void dfs0(int u) {
  used[u] = true;
  vi& nbru = nbrs[u];
  for (vi::iterator vit = nbru.begin(); vit != nbru.end(); vit++)
    if (! used[*vit]) dfs0(*vit);
  st.push(u);
}

void dfs1(int u) {
  used[u] = true;
  scc[u] = nsc;
  vi& rnbru = rnbrs[u];
  for (vi::iterator vit = rnbru.begin(); vit != rnbru.end(); vit++)
    if (! used[*vit]) dfs1(*vit);
}

void dfs2(int u) {
  dp[u][0] = dp[u][1] = 1;
  si& srnbr = srnbrs[u];

  for (si::iterator vit = srnbr.begin(); vit != srnbr.end(); vit++) {
    int v = *vit;
    roots[v] = false;
    if (dp[v][0] < 0) dfs2(v);

    dp[u][0] = (dp[u][0] * (dp[v][0] + dp[v][1])) % MOD;
    dp[u][1] = (dp[u][1] * dp[v][1]) % MOD;
  }
}

/* main */

int main() {
  cin >> n >> m;

  for (int i = 0; i < m; i++) {
    int s, d;
    cin >> s >> d;
    s--, d--;
    nbrs[s].push_back(d);
    rnbrs[d].push_back(s);
  }

  memset(used, false, sizeof(used));
  
  for (int u = 0; u < n; u++)
    if (! used[u]) dfs0(u);

  memset(used, false, sizeof(used));
  nsc = 0;

  while (! st.empty()) {
    int u = st.top(); st.pop();
    if (! used[u]) {
      dfs1(u);
      nsc++;
    }
  }
  //cout << nsc << endl;
  //for (int i = 0; i < n; i++) printf("%d ", scc[i]); putchar ('\n');

  for (int u = 0; u < n; u++) {
    si& srnbr = srnbrs[scc[u]];
    vi& rnbru = rnbrs[u];
    for (vi::iterator vit = rnbru.begin(); vit != rnbru.end(); vit++) {
      int v = scc[*vit];
      if (v != scc[u]) srnbr.insert(v);
    }
  }

  for (int u = 0; false && u < nsc; u++) {
    printf("srnbrs[%d]:", u);
    for (si::iterator vit = srnbrs[u].begin(); vit != srnbrs[u].end(); vit++)
      printf(" %d", *vit);
    putchar('\n');
  }

    memset(roots, true, sizeof(roots));
  memset(dp, -1, sizeof(dp));

  for (int u = 0; u < nsc; u++)
    if (dp[u][0] < 0) dfs2(u);

  ll d = 1;
  for (int u = 0; u < nsc; u++) {
    //printf("dp[%d] = %lld,%lld\n", u, dp[u][0], dp[u][1]);
    if (roots[u]) d = (d * (dp[u][0] + dp[u][1])) % MOD;
  }

  cout << d << endl;
  
  return 0;
}

Measured memory_bytes: 1428
#include<bits/stdc++.h>
 using namespace std;
#define INF 1000000
#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
int n,k;
int a[8001];
bool used[8001];
int R[4001];
int L[4001];

#define MAX_N 8010
int dp[MAX_N];
int solve(int x){
    fill(dp,dp+n+1,INF);
    for(int i=L[x]+1;i<R[x];i++){
        int b=a[i];
        if(L[x]>b)b+=n;
        if(R[x]<b){
           *lower_bound(dp,dp+n,b)=b;
        }
    }
    return (lower_bound(dp,dp+n,INF)-dp);
}
/*
int solve(int x){
    fill(dp,dp+n,INF);
    for(int i=R[x]+1;i<L[x]+n;i++){
        int b=a[i%n];
        if(b<R[x]&&b>L[x]){
           *lower_bound(dp,dp+n,b)=b;
        }
    }
    return (lower_bound(dp,dp+n,INF)-dp);
}*/

int main(){
    cin>>n>>k;
    REP(i,8001){
        used[i]=false;
    }
    REP(i,n){
        cin>>a[i];
        a[i]--;
    }
    
    int c=0;
    REP(i,n){
        if(used[i]==true)continue;
        used[i]=true;
        used[a[i]]=true;
        L[c]=i;
        R[c]=a[i];
        c++;
    }
    
    int ans=0;
    REP(i,n/2){
        //????????§???????¢????????????????
        ans=max(ans,solve(i));
    }
    ans=min(n/2,ans+k+1);
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3212
n,k = map(int,input().split())
a = list(map(int,input().split()))

a.sort(reverse=True)
dp = [False] * (k)
dp[0] = True
min_n = 10**10
for i in a:
    for j in range(k-1,-1,-1):
        if(dp[j]):
            if(j+i >= k):
                min_n = i
            else:
                dp[j+i] = True

ans = 0
for i in a:
    ans += (i < min_n)

print(ans)

Measured memory_bytes: 71912
macro_rules ! input { ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; input_inner ! { iter , $ ( $ r ) * } } ; ( $ ( $ r : tt ) * ) => { let s = { use std :: io :: Read ; let mut s = String :: new ( ) ; std :: io :: stdin ( ) . read_to_string ( & mut s ) . unwrap ( ) ; s } ; let mut iter = s . split_whitespace ( ) ; input_inner ! { iter , $ ( $ r ) * } } ; }
macro_rules ! input_inner { ( $ iter : expr ) => { } ; ( $ iter : expr , ) => { } ; ( $ iter : expr , mut $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let mut $ var = read_value ! ( $ iter , $ t ) ; input_inner ! { $ iter $ ( $ r ) * } } ; ( $ iter : expr , mut $ var : ident $ ( $ r : tt ) * ) => { let mut $ var = $ iter . next ( ) . unwrap ( ) . parse ::< usize > ( ) . unwrap ( ) ; input_inner ! { $ iter $ ( $ r ) * } } ; ( $ iter : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ iter , $ t ) ; input_inner ! { $ iter $ ( $ r ) * } } ; ( $ iter : expr , $ var : ident $ ( $ r : tt ) * ) => { let $ var = $ iter . next ( ) . unwrap ( ) . parse ::< usize > ( ) . unwrap ( ) ; input_inner ! { $ iter $ ( $ r ) * } } ; }
macro_rules ! read_value { ( $ iter : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ iter , $ t ) ) ,* ) } ; ( $ iter : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ iter , $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ iter : expr , chars ) => { read_value ! ( $ iter , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ iter : expr , usize1 ) => { read_value ! ( $ iter , usize ) - 1 } ; ( $ iter : expr , $ t : ty ) => { $ iter . next ( ) . unwrap ( ) . parse ::<$ t > ( ) . unwrap ( ) } ; }
use std::collections::VecDeque;
#[derive(Debug)]
struct DirectedAcyclicGraph {
    graph: Vec<Vec<usize>>,
    cost: Vec<Option<usize>>,
}
impl DirectedAcyclicGraph {
    fn new(n: usize) -> DirectedAcyclicGraph {
        DirectedAcyclicGraph {
            graph: vec![vec![]; n],
            cost: vec![None; n],
        }
    }
    fn add_edge(&mut self, u: usize, v: usize) {
        self.graph[u].push(v)
    }
    fn bfs(&mut self, s: usize, t: usize) -> Option<usize> {
        self.cost = vec![None; self.graph.len()];
        let mut deq = VecDeque::new();
        self.cost[s] = Some(0);
        deq.push_back(s);
        while let Some(u) = deq.pop_front() {
            if u == t {
                return self.cost[u];
            }
            let d = self.cost[u].unwrap();
            for &v in &self.graph[u] {
                if self.cost[v].is_none() {
                    self.cost[v] = Some(d + 1);
                    deq.push_back(v);
                }
            }
        }
        None
    }
}
fn main() {
    input! { n, m, uv: [(usize1, usize1); m], s: usize1, t: usize1 };
    let mut dag = DirectedAcyclicGraph::new(3 * n);
    for &(u, v) in &uv {
        dag.add_edge(u, v + n);
        dag.add_edge(u + n, v + n * 2);
        dag.add_edge(u + n * 2, v);
    }
    println!("{}", dag.bfs(s, t).map(|x| x as isize / 3).unwrap_or(-1));
}


Measured memory_bytes: 37116
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const ll mod = 1000000007;
//const ll mod = 998244353;
const int inf = 1e9 + 10;
const ll INF = 1e18;
const ld EPS = 1e-10;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
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; }



int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(25);

  ll a, b, c, k;
  cin >> a >> b >> c >> k;

  cout << (k % 2 == 0 ? a - b : b - a) << '\n';



  
  return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int ans = b / a;
        if(ans > c){
            ans = c;
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 23636
#include<stdio.h>
int head[262144],last[524288],to[524288],cnt=0;
void add(int u,int v)
{
	cnt++;
	last[cnt]=head[u];
	head[u]=cnt;
	to[cnt]=v;
}
int val0[262144],val1[262144],dp0[262144],dp1[262144],dp[262144];
void dfs(int u,int f)
{
	val0[u]=val0[f];
	val1[u]=val1[f];
	if(u>val0[u])
	{
		val1[u]=val0[u];
		val0[u]=u;
	}
	dp0[u]=1;
	dp1[u]=1;
	for(int i=head[u];i;i=last[i])
	{
		int v=to[i];
		if(v==f)
		{
			continue;
		}
		dfs(v,u);
		if(v<val0[u])
		{
			dp0[u]+=dp0[v];
		}
		if(v<val1[u])
		{
			dp1[u]+=dp1[v];
		}
	}
}
void dfs2(int u,int f)
{
	if(u==1)
	{
		dp[u]=0;
	}
	else if(val0[u]==u)
	{
		dp[u]=dp[f]+dp1[u];
	}
	else if(val0[f]==f&&u>val1[f])
	{
		dp[u]=dp[f]+dp0[u];
	}
	else if(val0[f]==f)
	{
		dp[u]=dp[f]+dp0[u]-dp1[u];
	}
	else
	{
		dp[u]=dp[f];
	}
	for(int i=head[u];i;i=last[i])
	{
		int v=to[i];
		if(v==f)
		{
			continue;
		}
		dfs2(v,u);
	}
}
int main()
{
	int n;
	scanf("%d",&n);
	for(int i=1;i<n;i++)
	{
		int u,v;
		scanf("%d%d",&u,&v);
		add(u,v);
		add(v,u);
	}
	dfs(1,0);
	dfs2(1,0);
	for(int i=2;i<=n;i++)
	{
		printf("%d",dp[i]);
		if(i==n)
		{
			putchar('\n');
		}
		else
		{
			putchar(' ');
		}
	}
	return 0;
}

Measured memory_bytes: 20608
#include <iostream>
#include <vector>
#include <iomanip>
#include <cmath>
#include <algorithm>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
template<class T> inline void chmin(T& a, T b) {if (a>b) a=b; }
template<class T> inline void chmax(T& a, T b) {if (a<b) a=b; }
inline void print() { cout << endl; }
template <class Head, class... Tail> inline void print(Head&& head, Tail&&... tail) {cout << head; if (sizeof...(tail) != 0) cout << " "; print(forward<Tail>(tail)...);}
template <class T> inline void print(vector<T>& vec) { for (auto& a : vec) {cout << a; if (&a != &vec.back()) cout << " "; } cout << endl;}
template <class T> inline void print(vector<vector<T>>& df) { for (auto& vec : df) { print(vec); }}
typedef long long ll;
const ll LINF = 1e18;
const int INF = 1e9;


int main() { 
    int N, K, Q; cin >> N >> K >> Q;
    // print(K, Q);
    vector<int> A(N);
    vector<int> P(N);
    REP(i, N) {P[i] = K-Q;}

    // print(P);
    REP(i, Q) {
        int a; cin >> a;
        // cin >> A[i];
        // print("====A[i]", A[i]);
        // print("before", P[A[i-1]]);
        P[a-1] += 1;
        // print("after", P[A[i-1]]);
    }
    // print(A);
    // print(P);

    REP(i, N) {
        // print("i+1=", i+1, "P[i]=", P[i]);
        if(P[i]>0) {
            print("Yes");
        } else {
            print("No");
        }
    }
    
    return 0;
}

Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
#define SZ(v) ((int)(v).size())
#define zero(v) memset(v,0,sizeof(v))
#define rep(i,n) for(int i=0;i<(n);i++)
#define foreach(it,c) for(__typeof(c.begin()) it=c.begin();it!=c.end();it++)
#define all(v) (v).begin(),(v).end()
template<typename T>inline bool chkmin(T &a,const T &b){return a>b?a=b,1:0;}
template<typename T>inline bool chkmax(T &a,const T &b){return a<b?a=b,1:0;}
typedef long long ll;
typedef unsigned uint;
const int INF=0x3f3f3f3f;
const double EPS=1e-10;
typedef pair<int,int>P;
int inline in(){int x=0,c;for(;(uint)((c=getchar())-'0')>=10;)
{if(c=='-')return -in();if(!~c)throw ~0;}do{x=(x<<3)+(x<<1)+(c-'0');}
while((uint)((c=getchar())-'0')<10);return x;}
int n,k,c;
const int Maxn=2e5+5;
char s[Maxn];
int lwork[Maxn],rwork[Maxn];
int main(){
	scanf("%d%d%d%s",&n,&k,&c,s+1);
	for(int i=1;i<=n;i++){
		int add=(s[i]=='o');
		lwork[i]=max(lwork[i-1],add);
		if(i-c-1>=1){
			chkmax(lwork[i],lwork[i-c-1]+add);
		}
	}
	for(int i=n;i>=1;i--){
		int add=(s[i]=='o');
		rwork[i]=max(rwork[i+1],add);
		if(i+c+1<=n){
			chkmax(rwork[i],rwork[i+c+1]+add);
		}
	}
//	for(int i=1;i<=n;i++)printf("%d ",lwork[i]);printf("\n");
//	for(int i=1;i<=n;i++)printf("%d ",rwork[i]);printf("\n");
	for(int i=1;i<=n;i++){
		int works=lwork[i-1]+rwork[i+1];
		if(works<k){
			printf("%d\n",i);
		}
	}
	return 0;
}

Measured memory_bytes: 3200
#include <stdio.h>

int main(void){
    int strs[4] = {'S','H','C','D'};
    int data[4][13] = {0};
    int n,i,j,x;
    char c;
    scanf("%d",&n);
    for(i = 0;i<=n;i++){
        scanf("%c %d\n",&c,&x);
        switch(c){
            case 'S':
                data[0][x-1] = 1;
                break;
            case 'H':
                data[1][x-1] = 1;
                break;
            case 'C':
                data[2][x-1] = 1;
                break;
            case 'D':
                data[3][x-1] = 1;
                break;
        }
    }
    for(i = 0;i<4;i++){
        for(j = 0;j<13;j++){
            if(data[i][j] == 0){
                printf("%c %d\n",strs[i],j+1);
            }
        }
    }
    return 0;
}

Measured memory_bytes: 600
from functools import cmp_to_key
import heapq

N,M = map(int,input().split())
AB = []
for i in range(N):
    A,B = map(int,input().split())
    AB.append((A,B))
AB.sort()
sum = 0
D = 0
li = []
i = 0
heapq.heapify(li)
for D in range(1,M+1):
    while(True):
        if i >= N:
            break
        if AB[i][0] <= D:
            heapq.heappush(li,-AB[i][1])
            i = i + 1
        else:
            break
    if len(li) > 0:
        sum = sum - heapq.heappop(li)

print(sum)

Measured memory_bytes: 21136
import sys
sys.setrecursionlimit(10**6) #再帰関数の上限
import math
from copy import copy, deepcopy
from operator import itemgetter
from bisect import bisect_left, bisect, bisect_right#2分探索
#bisect_left(l,x), bisect(l,x)#aはソート済みである必要あり。aの中からx未満の要素数を返す。rightだと以下
from collections import deque 
#deque(l), pop(), append(x), popleft(), appendleft(x)
##listでqueの代用をするとO(N)の計算量がかかってしまうので注意
from collections import Counter#文字列を個数カウント辞書に、
#S=Counter(l),S.most_common(x),S.keys(),S.values(),S.items()
from itertools import accumulate#累積和
#list(accumulate(l))
from heapq import heapify,heappop,heappush
#heapify(q),heappush(q,a),heappop(q) #q=heapify(q)としないこと、返り値はNone
#import fractions#古いatcoderコンテストの場合GCDなどはここからimportする


def input(): return sys.stdin.readline()[:-1]
def printl(li): print(*li, sep="\n")
def argsort(s, return_sorted=False): 
    inds=sorted(range(len(s)), key=lambda k: s[k])
    if return_sorted: return inds, [s[i] for i in inds]
    return inds
def alp2num(c,cap=False): return ord(c)-97 if not cap else ord(c)-65
def num2alp(i,cap=False): return chr(i+97) if not cap else chr(i+65)

def main():
    mod = 10**9+7
    #w.sort(key=itemgetter(1),reversed=True)  #二個目の要素で降順並び替え

    #N = int(input())
    N, K = map(int, input().split())
    H = tuple(map(int, input().split())) #1行ベクトル
    #L = tuple(int(input()) for i in range(N)) #改行ベクトル
    #S = tuple(tuple(map(int, input().split())) for i in range(N)) #改行行列
    inf=10**10
    dp=[inf]*N
    dp[0]=0
    for i in range(N):
        for k in range(1,min(K+1,N-i)):
            dp[i+k]=min(dp[i+k],dp[i]+abs(H[i]-H[i+k]))

    print(dp[N-1])



if __name__ == "__main__":
    main()

Measured memory_bytes: 56432
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<math.h>
#define lol(i,n) for(int i=0;i<n;i++)
#define mod 1000000007
#define Max(a,b) a=max(a,b);
#define P acos(-1.0)
typedef long long ll;

using namespace std;
double x[110],y[110];
int main(){
    int n;cin>>n;
    lol(i,n)cin>>x[i]>>y[i];
    lol(i,n){
	vector<double> v;v.clear();
	lol(j,n){
	    if(i==j)continue;
	    double cur=atan2(y[j]-y[i],x[j]-x[i]);
	    v.push_back(cur);
	    v.push_back(cur+2*P);
	}
	sort(v.begin(),v.end());
	double ans=0;
	lol(j,n-1)Max(ans,P+v[j]-v[j+n-2]);
	printf("%.9f\n",ans/(P*2.0));
    }
    return 0;
}


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

int main(){
    string s;
    cin >> s;
    string s_re = s;
    reverse(s_re.begin(), s_re.end());

    long long n = s.size();
    string s1 = s.substr(0, (n-1)/2);
    string s2 = s.substr((n+1)/2);

    string s1_re = s1;
    string s2_re = s2;
    reverse(s1_re.begin(), s1_re.end());
    reverse(s2_re.begin(), s2_re.end());

    if(s == s_re and s1 == s1_re and s2 == s2_re) printf("Yes\n");
    else printf("No\n");

    return 0;
}

Measured memory_bytes: 3600
N =int(input())
S = input()
i = 1
W = [0 for i in range(N)] #位置iを含む左側で西を向く人の数
E = [0 for i in range(N)] #位置iを含む左側で東を向く人の数
# 位置iを含まない右側で西を向く人の数はW[N-1]-W[i]
if S[0] == "W":
    W[0] = 1
else:
    E[0] = 1
while i < N:
    if S[i] == "W":
        W[i] = W[i-1]+1
        E[i] = E[i-1]
    else:
        E[i] = E[i-1]+1
        W[i] = W[i-1]
    i += 1
ans = 300001
for i in range(N):
    #位置iの人をリーダーにする
    if i != 0:
        temp = W[i-1]+E[N-1]-E[i]
    else:
        temp = E[N-1]-E[0]
    if temp < ans:
        ans = temp
print(str(ans))

Measured memory_bytes: 17812
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rrep(i,n) for(ll i = 1; i <= (n); ++i)
#define drep(i,n) for(ll i = (n)-1; i >= 0; --i)
#define all(v) v.begin(),v.end()
#define len(x) (ll)(x).length()
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define pb push_back
#define sz(x) (ll)(x).size()
#define v(T) vector<T>
#define vv(T) vector<vector<T>>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
ll gcd(ll a,ll b){if(a%b==0){return b;}else{return(gcd(b,a%b));}}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
const int INF=1e9;
const ll MX = 1e18;
const int MOD=INF+7;
const int di[] = {-1,0,1,0};
const int dj[] = {0,-1,0,1};
const double PI=acos(-1);

int main() {
  char c;
  cin>>c;
  printf("%c",(c+1));
}

Measured memory_bytes: 3596
#include <iostream>
#include<vector>
#include<stdio.h>
#include <algorithm>
#include <functional>

#define FOR(i,n) for(int i=0;i<n;i++)
#define SORT(v,n) std::sort(&v[0],&v[n])
#define INF 999999999
#define mod 1000000007

using namespace std;

int main(){

	int N,M;

	cin >> N >> M ;

	vector<string> A(N);
	vector<string> B(M);

	FOR(i,N){
		cin >> A.at(i);
	}
	FOR(i,M){
		cin >> B.at(i);
	}
	bool x=false;
	FOR(i,N-M+1){//tate
		//cout << "in";
		FOR(j,N-M+1){//yoko
			x=true;
			FOR(k,M){//tate
				FOR(l,M){//yoko
					if(A.at(i+k).at(j+l)!=B.at(k).at(l)){
						//cout << i << ","<<j << ","<<k << ","<<l << "," ;
						x=false;
					}
				}
			}
			if(x){
				cout << "Yes" <<endl;
				return 0;
			}
		}
	}
	cout << "No" << endl;
	return 0;

}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <cstring>
#define rep(i, N) for (int i = 0; i < (int)N; i++)
using namespace std;
typedef long long ll;
const ll LLINF = 9223372036854775807;
const int MOD = 1000000007;

int main() {
  int N; cin >> N;
  string result;
  if (N<=999) result = "ABC";
  else result = "ABD";
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <map>
#include <set>
#include <vector>
#include <iostream>
#include <algorithm>
#include <string>
#include <iomanip>

using namespace std;

int squares[101];

int main() {
    cout.setf(ios::fixed, ios::floatfield);
    cout.setf(ios::showpoint);
    cout.precision(12);
    ios::sync_with_stdio(false);

    int N, M, X;
    cin >> N >> M >> X;
    --N;
    --X;
    for(int i = 0; i < M; ++i) {
        int v;
        cin >> v;
        --v;
        squares[v] = 1;
    }
    int cost1 = 0;
    for(int i = 0; i < X; ++i) {
        if(squares[i] == 1) ++cost1;
    }
    int cost2 = 0;
    for(int i = X; i < N; ++i) {
        if(squares[i] == 1) ++cost2;
    }
    cout << min(cost1, cost2) << endl;

    return 0;
}


Measured memory_bytes: 256
// ========================================================================================================
// Library
// ========================================================================================================
#define _CRT_SECURE_NO_WARNINGS

#include <bits/stdc++.h>
using namespace std;

// competitive macro
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b) - 1; i >= (a); i--)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i ,n) for (int i = (n) - 1; i >= 0; i--)
#define LL long long
#define ULL unsigned long long

void fastIOS()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
}
// ========================================================================================================
// ========================================================================================================

int main()
{
	fastIOS();

	int n,k; cin >> n >> k;
    int h[n];
    REP(i,n)
    {
        cin >> h[i];
    }
    
    LL cnt = 0;
    if(k<n)
    {
        sort(h,h+n);
        REP(i,n-k)
        {
            cnt += h[i];
        }
    }
    
    cout << cnt << endl;
    
    return 0;
}

Measured memory_bytes: 1024
package main

import (
  "fmt"
  "math"
  "sort"
)

func main() {
  var n, m int
  fmt.Scan(&n, &m)
  x := make([]int, m)
  for i := 0; i < m; i++ {
    fmt.Scan(&x[i])
  }

  if n >= m {
    fmt.Println(0)
    return
  }

  sort.Ints(x)
  diff := make([]int, m-1)
  for i := 0; i < m-1; i++ {
    diff[i] = x[i+1] - x[i]
  }
  for i := 0; i < m-1; i++ {
    diff[i] = int(math.Abs(float64(diff[i])))
  }
  sort.Ints(diff)

  ans := x[len(x)-1] - x[0]
  for _, v := range diff[m-(n-1)-1:] {
    ans -= v
  }
  fmt.Println(ans)
}

Measured memory_bytes: 5504
using Yorukatsu035.Questions;
using Yorukatsu035.Extensions;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace Yorukatsu035.Questions
{
    /// <summary>
    /// ABC106 C
    /// </summary>
    public class QuestionB : AtCoderQuestionBase
    {
        public override IEnumerable<object> Solve(TextReader inputStream)
        {
            var s = inputStream.ReadLine();
            var k = inputStream.ReadLong();

            for (int i = 0; i < k; i++)
            {
                if (s[i] != '1' || i == k - 1)
                {
                    yield return s[i];
                    yield break;
                }
            }
        }
    }
}


namespace Yorukatsu035
{
    class Program
    {
        static void Main(string[] args)
        {
            IAtCoderQuestion question = new QuestionB();    // 問題に合わせて書き換え
            var answers = question.Solve(Console.In);
            foreach (var answer in answers)
            {
                Console.WriteLine(answer);
            }
        }
    }
}

#region Base Classes

namespace Yorukatsu035.Questions
{

    public interface IAtCoderQuestion
    {
        IEnumerable<object> Solve(string input);
        IEnumerable<object> Solve(TextReader inputStream);
    }

    public abstract class AtCoderQuestionBase : IAtCoderQuestion
    {
        public IEnumerable<object> Solve(string input)
        {
            var stream = new MemoryStream(Encoding.Unicode.GetBytes(input));
            var reader = new StreamReader(stream, Encoding.Unicode);

            return Solve(reader);
        }

        public abstract IEnumerable<object> Solve(TextReader inputStream);
    }

}

#endregion

#region Extensions

namespace Yorukatsu035.Extensions
{
    internal static class TextReaderExtensions
    {
        internal static int ReadInt(this TextReader reader) => int.Parse(ReadString(reader));
        internal static long ReadLong(this TextReader reader) => long.Parse(ReadString(reader));
        internal static double ReadDouble(this TextReader reader) => double.Parse(ReadString(reader));
        internal static string ReadString(this TextReader reader) => reader.ReadLine();

        internal static int[] ReadIntArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(int.Parse).ToArray();
        internal static long[] ReadLongArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(long.Parse).ToArray();
        internal static double[] ReadDoubleArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(double.Parse).ToArray();
        internal static string[] ReadStringArray(this TextReader reader, char separator = ' ') => reader.ReadLine().Split(separator);
    }
}

#endregion

Measured memory_bytes: 13140
const int LG = 21;
const int FN = 400005;
const long long MOD = 1e9 + 7;
const long long INF = 1e9;
const long long INFLL = 1e18;

#include <bits/stdc++.h>

using namespace std;
#define int long long
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;

#define forn(i, n) for (int (i) = 0; (i) != (n); (i)++)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define fi first
#define se second
#define re return
#define pb push_back
#define uniq(x) sort(all(x)); (x).resize(unique(all(x)) - (x).begin())

#ifdef LOCAL
#define dbg(x) cerr << __LINE__ << " " << #x << " " << x << endl
#define ln cerr << __LINE__ << endl
#else
#define dbg(x) void(0)
#define ln void(0)
#endif // LOCAL

int cx[4] = {-1, 0, 1, 0};
int cy[4] = {0, -1, 0, 1};
string Yes[2] = {"No", "Yes"};
string YES[2] = {"NO", "YES"};

ll inq(ll x, ll y)
{
    if (!y) re 1 % MOD;
    ll l = inq(x, y / 2);
    if (y % 2) re l * l % MOD * x % MOD;
    re l * l % MOD;
}

ll rev(ll x)
{
    return inq(x, MOD - 2);
}

bool __precomputed_combinatorics = 0;
vector<ll> __fact, __ufact, __rev;

void __precompute_combinatorics()
{
    __precomputed_combinatorics = 1;
    __fact.resize(FN);
    __ufact.resize(FN);
    __rev.resize(FN);
    __rev[1] = 1;
    for (int i = 2; i < FN; i++) __rev[i] = MOD - __rev[MOD % i] * (MOD / i) % MOD;
    __fact[0] = 1, __ufact[0] = 1;
    for (int i = 1; i < FN; i++) __fact[i] = __fact[i - 1] * i % MOD, __ufact[i] = __ufact[i - 1] * __rev[i] % MOD;
}

ll fact(int x)
{
    if (!__precomputed_combinatorics) __precompute_combinatorics();
    return __fact[x];
}

ll cnk(int n, int k)
{
    if (k < 0 || k > n) return 0;
    if (!__precomputed_combinatorics) __precompute_combinatorics();
    return __fact[n] * __ufact[n - k] % MOD * __ufact[k] % MOD;
}

int Root(int x, vector<int> &root)
{
    if (x == root[x]) return x;
    return root[x] = Root(root[x], root);
}

void Merge(int v, int u, vector<int> &root, vector<int> &sz)
{
    v = Root(v, root), u = Root(u, root);
    if (v == u) return;
    if (sz[v] < sz[u])
    {
        sz[u] += sz[v];
        root[v] = u;
    }
    else
    {
        sz[v] += sz[u];
        root[u] = v;
    }
}

int ok(int x, int n)
{
    return 0 <= x && x < n;
}

void bfs(int v, vi &dist, vector<vi> &graph)
{
    fill(all(dist), -1);
    dist[v] = 0;
    vi q = {v};
    for (int i = 0; i < q.size(); i++)
    {
        for (auto u : graph[q[i]])
        {
            if (dist[u] == -1)
            {
                dist[u] = dist[q[i]] + 1;
                q.push_back(u);
            }
        }
    }
}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n, a;
    cin >> n >> a;
    cout << Yes[n % 500 <= a];
}

/* Note:
Check constants at the beginning of the code.
    N is set to 4e5 but be careful in problems with large constant factor.
    Setting N in every problem is more effective.
Check corner cases.
    N = 1
No def int long long for now.
Add something here.
*/


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define rep1(i,n) for(int i = 1; i <= n; i++)
#define co(x) cout << x <<endl
#define cs(x) cout << x <<" "
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
using namespace std;
ll mod = 1e9 + 7;

int main()
{
	int n, m;
	cin >> n >> m;
	vector<vector<bool>> init(n, vector<bool>(n, false));
	vector<int>a(m), b(m);
	rep(i, m)
	{
		cin >> a[i] >> b[i];
		a[i]--; b[i]--;
		init[a[i]][b[i]] = true;
		init[b[i]][a[i]] = true;
	}
	int ans = 0;
	rep(i, m)
	{
		auto dp = init;
		dp[a[i]][b[i]] = false;
		dp[b[i]][a[i]] = false;
		rep(k, n)rep(x, n)rep(y, n)if (dp[x][k] && dp[k][y])dp[x][y] = true;
		rep(j, n)
		{
			bool flag = false;
			rep(k, n)
			{
				if (!dp[j][k])
				{
					ans++;
					flag = true;
					break;
				}
			}
			if (flag)break;
		}
	}
	co(ans);
	return 0;
}


Measured memory_bytes: 256
using System;
class Solution
{
   static void Main(string[] args)
   {
      long result = 0;
      long N = long.Parse(Console.ReadLine());
      for(long a = 1; a * (a + 1) < N; a++)
      {
         if((N-a) % a == 0) result += (N-a) / a;
      }
     
      Console.WriteLine("{0}", result);
   }
}


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

using namespace std;

#define MP make_pair
#define PB push_back
#define f first
#define s second

typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef vector<int> vi;

//int dr1[] = {-1, 0, 1, 0};
//int dc1[] = {0, 1, 0, -1};
//int dr3[] = {0, 1, 2, 3, 2, 1, 0, -1, -2, -3, -2, -1, -1, 1, 0, 0};
//int dc3[] = {3, 2, 1, 0, -1, -2, -3, -2, -1, 0, 1, 2, 0, 0, -1, 1};
const int MOD = 1000000007;
const int INF = 1000000007;

ll modx(ll a)
{
    return (a%MOD+MOD)%MOD;
}

ll times(ll a, ll b)
{
    return modx(modx(a)*modx(b));
}

ll add(ll a, ll b)
{
    return modx(modx(a)+modx(b));
}

ll sub(ll a, ll b)
{
    return modx(MOD+modx(a)-modx(b));
}

ll fastExp(ll base, ll exp)
{
    if(exp == 0LL)
    {
        return 1LL;
    }

    if(exp%2==0)
    {
        return fastExp(times(base, base), exp/2);
    }
    else
    {
        return times(base, fastExp(times(base, base), exp/2));
    }
}


const int MAXN = (int)2e5+1;
ll N, c[MAXN];


int main()
{
    //freopen("input.in","r",stdin);
    //freopen("output.out","w",stdout);
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> N;
    ll ans = fastExp(2, 2*N-2);
    ll t = 0;
    for(int i=1; i<=N; i++)
    {
        cin >> c[i];
    }
    sort(c+1, c+N+1);
    for(int i=1; i<=N; i++)
    {
         t = add(t, times(c[i], N-i+2));
    }
    cout << times(ans, t);
    return 0;
}


Measured memory_bytes: 1792
a,z,i,j,d[9999][9];main(k){scanf("%d ",&a);d[a][2]=1;for(i=a;a=getchar()%4-1,i--;)for(j=8;j--;z+=d[0][j])for(k=8;k--;)d[i][j]+=j&k&&j>>a&1?d[i+1][k]%10007:0;a=!printf("%d\n",z%10007);}

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

const int MAXN = 2e5 + 10;

int n, a[MAXN], sum;

int main() {
    scanf("%d", &n);
    for (int i = 1, x; i <= n; ++i) {
        scanf("%d", &a[i]); sum ^= a[i];
    }
    for (int i = 1; i <= n; ++i) printf("%d ", sum ^ a[i]);
    return 0;
}

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

int main(){
    int n;
    string s,t;
    cin>>n>>s>>t;
    int ans=0;
    for(int i=0;i<n;i++){
        int cnt=0;
        for(int j=0;j<n-i;j++){
            if(s[i+j]!=t[j]) break;
            cnt++; 
        }
        ans=max(ans,cnt);
    }
    cout<<n*2-ans<<endl;
}

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

constexpr int MAX = 1e9;
 
int main() {
	int n, m, x;
	cin >> n >> m >> x;

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

	int ans = MAX;
	int l = 1 << n;
	for (int mask = 0; mask < l; ++mask) {
		vector<int> u(m, 0);
		int cost = 0;
		for (int i = 0; i < n; ++i) {
			if ((mask >> i) & 1) {
				cost += c[i];
				for (int j = 0; j < m; ++j) {
					u[j] += a[i][j];
				}
			}
		}

		bool ok = true;
		for (int i = 0; i < m; ++i) {
			if (u[i] < x) {
				ok = false;
				break;
			}
		}

		if (ok && cost < ans) {
			ans = cost;
		}
	}

	if (ans == MAX) {
		cout << -1;
	} else {
		cout << ans;
	}
	
	return 0;
}

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

long long N, W;
long long weight[100005], value[100005];

long long A[100002][102];

int main() {
  cin >> N >> W;

  for (int i = 0; i < N; i++) {
    cin >> weight[i] >> value[i];
  }

  for (int i = 0; i < 100002; i++) {
    A[i][0] = 0;
  }

  for (int i = 0; i < 102; i++) {
    A[0][i] = 0;
  }

  for (int w = 1; w <= W; w++) {
    for (int item = 0; item < N; item++) {

      if (weight[item] > w) {
        A[w][item] = A[w][item - 1];
      }

      else {
        A[w][item] = max((value[item] + A[w - weight[item]][item - 1]), A[w][item - 1]);
      }

    }
  }

  cout << A[W][N - 1] << "\n";

  return 0;
}

Measured memory_bytes: 80128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include <boost/multiprecision/cpp_ll.hpp>
//typedef boost::multiprecision::cpp_ll ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
string alp="abcdefghijklmnopqrstuvwxyz";
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);

struct Node{
    bool seen[3];
    vector<ll> to;
};

int main(){
    ll n,m;cin>>n>>m;
    ll v,u;
    Node node[n+1];
    rep(i,1,n){
        rep(j,0,2){
            node[i].seen[j]=false;
        }
    }
    rep(i,0,m-1){
        cin>>v>>u;
        node[v].to.pb(u);
        //node[u].to.pb(v);
    }
    queue<pair<ll,ll>> q;
    ll s,t;cin>>s>>t;
    q.push(make_pair(0,s));
    while(q.size()>0){
        ll flag=q.front().first;
        ll x=q.front().second;
        q.pop();
        if(flag%3==0 && x==t){
            cout<<flag/3<<endl;
        }
        if(node[x].to.size()!=0){
        rep(j,0,node[x].to.size()-1){
            if(node[node[x].to[j]].seen[(flag+1)%3]){
                continue;
            }
            node[node[x].to[j]].seen[(flag+1)%3]=true;
            q.push(make_pair(flag+1,node[x].to[j]));
        }
        }
    }
    if(node[t].seen[0]){
        
    }else{
        cout<<-1<<endl;
    }
    
    return 0;
}




Measured memory_bytes: 6528
N = gets.to_i

array0 = []
N.times{||
	array0 << gets.strip.split(//).collect{|c| c.to_sym}
}

$array = []
array0.each{|line|
	$array << line * 2
}
array0.each{|line|
	$array << line * 2
}

$array_t = $array.transpose

def check(x)
	N.times{|i|
		a = $array[i]
		at = $array_t[i + x]
		(i...N).each{|j|
			if a[j + x] != at[j]
				return false
			end
		}
	}
	return true
end

sum = 0
N.times{|x|
	if check(x)
		sum += N
	end
}
puts sum


Measured memory_bytes: 10772
package main

import(
    "fmt"
    "sort"
    "strings"
)



func main() {
    var n int
    fmt.Scan(&n)
    a := make([]int, n)
    for i:=0;i<n;i++{
        fmt.Scan(&a[i])
    }
    sort.Ints(a)
    fmt.Println(a[n/2]-a[n/2-1])
}





// Pairsort
type Pair struct {
    first,second int64
}

type By func(p1, p2 *Pair) bool

func (by By) Sort(pairs []Pair) {
    ps := &pairSorter{
            pairs : pairs,
            by: by,
    }
    sort.Sort(ps)
}

type pairSorter struct {
    pairs []Pair
    by func(p1, p2 *Pair) bool
}

func (s *pairSorter) Len() int {
    return len(s.pairs)
}

func (s *pairSorter) Swap(i, j int) {
    s.pairs[i], s.pairs[j] = s.pairs[j], s.pairs[i]
}

func (s *pairSorter) Less(i, j int) bool {
    return s.by(&s.pairs[i], &s.pairs[j])
}

func first (p1, p2 *Pair) bool {
        return p1.first < p2.first
}

func second (p1, p2 *Pair) bool {
        return p1.second < p2.second
}
// end



func abs32(a int) int {
    if a<0{
        return -a
    }
    return a
}

func abs64(a int64) int64 {
    if a<0{
        return -a
    }
    return a
}

func min32(a, b int) int {
    if a >= b {
        return b
    }
    return a
}

func max32(a, b int) int {
    if a >= b {
        return a
    }
    return b
}

func min64(a, b int64) int64 {
    if a >= b {
        return b
    }
    return a
}

func max64(a, b int64) int64 {
    if a >= b {
        return a
    }
    return b
}

func gcd(a, b int64) int64 {
    if a % b == 0 {
        return b
    } else {
        return gcd(b, a%b)
    }
}

func lcm(a, b int64) int64 {
    return a / gcd(a, b) * b
}

func scanNums(len int) (nums []int){
    var num int
    for i:=0; i<len; i++{
        fmt.Scan(&num)
        nums = append(nums,num)
    }
    return
}

func scanNums64(len int) (nums []int64){
    var num int64
    for i:=0; i<len; i++{
        fmt.Scan(&num)
        nums = append(nums,num)
    }
    return
}

func scanString(len int) (str []string){
    var s string
    for i:=0; i<len; i++{
        fmt.Scan(&s)
        str = append(str,s)
    }
    return
}

func makeTwoNums(n,m int) ([][]int){
    Nums := make([][]int, n)
    for i:=0; i<n; i++{
        Nums[i] = make([]int, m)
    }
    return Nums
}

func sortString(s string) string{
    t := strings.Split(s, "")
    sort.Strings(t)
    return strings.Join(t, "")
}

func reverseString(s string) string{
    t := []rune(s)
    for i,j := 0, len(s)-1 ; i < j ; i, j = i+1, j-1 {
        t[i], t[j] = t[j], t[i]
    }
    return string(t)
}

func stringRev(s []byte,l int,r int) []byte{
    for i:=0;i<(r-l+1)/2;i++{
        s[l-1+i], s[r-1-i] = s[r-1-i], s[l-1+i]
    }
    return s
}

func inside(h,w,H,W int) bool{
    if h>=0 && h<H && w>=0 && w<W{
        return true
    }
    return false
}



Measured memory_bytes: 5504
use std::io;
fn main() {
    let mut buft = String::new();
    // io::stdin().read_line(&mut bufs).unwrap();
    io::stdin().read_line(&mut buft).unwrap();
    let ab :Vec<i32> = buft.trim().split_whitespace().map(|x| x.parse::<i32>().unwrap()).collect();
    // println!("{} {}", a, b);
    let mut tot = 1;
    let mut ans = 0;
    while tot < ab[1] {
        tot = tot - 1 + ab[0];
        ans += 1;
    }
    println!("{}", ans);
}


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

typedef long long ll;
const ll INF = 100100100100;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int a, b, q;
    cin >> a >> b >> q;
    vector<ll> s(a+2), t(b+2);
    // 番兵みたいな要素
    s[0] = -2 * INF, s[a + 1] = 2 * INF;
    t[0] = -2 * INF, t[b + 1] = 2 * INF;
    for(int i = 1; i <= a; ++i){
        cin >> s[i];
    }
    for(int i = 1; i <= b; ++i){
        cin >> t[i];
    }
    for(int i = 0; i < q; ++i){
        ll x;
        cin >> x;
        int s_id = lower_bound(s.begin(), s.end(), x) - s.begin();
        int t_id = lower_bound(t.begin(), t.end(), x) - t.begin();
        ll res = INF;
        ll x1 = s[s_id] - x;
        ll x2 = x - s[s_id - 1];
        ll y1 = t[t_id] - x;
        ll y2 = x - t[t_id - 1];
        cerr << x1 << " " << x2 << " " << y1 << " " << y2 << " ";
        res = min(res, max(x1, y1));
        res = min(res, max(x2, y2));
        res = min({res, 2 * x1 + y2, x1 + 2 * y2});
        res = min({res, 2 * x2 + y1, x2 + 2 * y1});
        cout << res << endl;
    }
}

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

double dp[8][8];
int x[8], y[8];

double distance(int i, int j)
{
    if(dp[i][j] == -1)
    {
        dp[i][j] = sqrt(pow(x[i]-x[j],2.0)+pow(y[i]-y[j],2.0));
    }
    else
    {
        return dp[i][j];
    }
}

int main(void)
{
    int n;
    for (int i = 0; i < 8; i++)
    {
        for (int j = 0; j < 8; j++)
        {
            dp[i][j] = -1;
        }
    }
    double sum = 0.0;
    int sum_perm = 0;
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        cin >> x[i] >> y[i];
    }

    vector<int> v(n);
    iota(v.begin(), v.end(), 1);
    do
    {
        for (int i = 1; i < n; i++)
        {
            sum += distance(v[i-1]-1, v[i]-1);
        }
        sum_perm++;
    } while (next_permutation(v.begin(), v.end()));
    printf("%.10lf\n", sum/sum_perm);
}

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

using int64 = long long;

int main() {
  int64 n;
  cin >> n;
  string ret;
  for (; n; n /= -2) {
    if (n & 1) {
      --n;
      ret.push_back('1');
    } else {
      ret.push_back('0');
    }
  }
  if (ret.size() == 0)
    ret = "0";
  reverse(ret.begin(), ret.end());
  cout << ret << "\n";
  return 0;
}


Measured memory_bytes: 256
s = int(input())
an = []
an.append(s)
n = s
while an.count(4) != 2:
    if n % 2 == 0:
        n /= 2
        an.append(int(n))
    else:
        n = 3 * n + 1
        an.append(int(n))
if an.index(1) == 0 or an.index(2) == 0:
    print(4)
else:
    print(an.index(4) + 4)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int x,v=1,c=0;
    for(int i=0;i<n;i++)
    {
        cin>>x;
        if(x!=v)
            c++;
        else v++;
    }
    if(c==n)c=-1;
    cout<<c<<endl;
    return 0;
}




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

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl




typedef long long ll;
const ll mod = 1e9+7;
const int maxn = 1e6 + 5;



string s;
int k;

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);  cout.tie(0);
    cin>>s;
    int n=s.length();
    cin>>k;
    vector<string> v;
    for (int i=0; i<n; i++) {
	for (int j=1; j<=min(6,n) && i+j<=n; j++) {
	    v.push_back(s.substr(i,j));
	}
    }
    sort(v.begin(),v.end());
    v.erase(unique(v.begin(),v.end()),v.end());
    cout<<v[k-1]<<endl;


  

    return 0;
}


Measured memory_bytes: 1916
#include<bits/stdc++.h>
using namespace std;
int main() {
	int N,T,A;
  cin>>N>>T>>A;
  vector<int> h(N);
  int c,d,m=100000000;
  for(int i=0;i<N;i++){
    
    cin>>c;
    h.at(i)=(T*1000-c*6)-A*1000;
    if(h.at(i)<0){
      h.at(i)=-1*h.at(i);
    }
    if(h.at(i)<m){
      m=h.at(i);
      d=i+1;
  }
  }
  cout<<d;
}

Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split()))

cnt=[0]*((10**6)+1)
for elem in a:
    cnt[elem]+=1

unique=[]

for i in range(10**6+1):
    if cnt[i]==1:
        unique.append(i)

cnt=[0]*((10**6)+1)
a=list(set(a))

for elem in a:
    for i in range(elem*2,10**6+1,elem):
        cnt[i]=1

ans=0

for elem in unique:
    if cnt[elem]==0:
        ans+=1
        
print(ans)

Measured memory_bytes: 143396
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner std = new Scanner(System.in);
        int n = std.nextInt();
        PriorityQueue<Integer> pq = new PriorityQueue<>();
        for (int i = 0; i < n; i++) {
            pq.add(std.nextInt());
        }

        Integer first = pq.poll();
        double ans = first;
        while (!pq.isEmpty()) {
            Integer value = pq.poll();
            ans += value;
            ans /= 2.0;
        }

        System.out.println(ans);
    }
}


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

char *reverse(char *s) {

	int i;
	char answer[strlen(s)];
	int length = strlen(s);

	memset(answer,'\0',sizeof(char));

	for(i=0;i<=strlen(s)-1;i++)
		answer[i]=s[strlen(s)-1-i];

	strcpy(s,answer);
	s[length] = '\0';
	return s;
}

int main() {

	int m;
	char c[74];
	char s1[74],s2[74];
	char temp1[74],temp2[74];
	char s1_rev[74],s2_rev[74];
	char A[600][74];
	int a,i,j,k,l,x;
	int A_max;
	int answer;
	int length;

	scanf("%d\n",&m);

	//???????????????????????§?¨????????§?
	for(a=0;a<m;a++) {

		answer=0; //??????;
		fgets(c,sizeof(c),stdin);
		c[strlen(c)-1]='\0';
		length = strlen(c);

		for(i=0;i<600;i++)
			for(j=0;j<73;j++)
				A[i][j]='\0';

		//???????????????
		for(j=1;j<strlen(c);j++) {
			for(x=1;x<=8;x++){
				memset(s1,'\0',sizeof(char));
				memset(s2,'\0',sizeof(char));
				memset(temp1,'\0',sizeof(char));
				memset(temp2,'\0',sizeof(char));
				memset(s1_rev,'\0',sizeof(char));
				memset(s2_rev,'\0',sizeof(char));

				strncpy(s1,c,j);
				strncpy(s2,c+j,strlen(c)-j+1);
				s1[j]='\0';
				s2[strlen(c)-j+1]='\0';
				strcpy(temp1,s1);
				strcpy(temp2,s2);
				strcpy(s1_rev,reverse(temp1));
				strcpy(s2_rev,reverse(temp2));

				switch(x) {
				case 1:
					//s1,s2????????????(c)
					strcpy(A[8*(j-1)],c);
					break;
				case 2:
					//s1???????????¢
					strcpy(A[8*(j-1)+1],strcat(s1_rev,s2));
					break;
				case 3:
					//s2???????????¢
					strcpy(A[8*(j-1)+2],strcat(s1,s2_rev));
					break;
				case 4:
					//s1,s2???????????¢
					strcpy(A[8*(j-1)+3],strcat(s1_rev,s2_rev));
					break;
					//????????????s1,s2?????¢
				case 5:
					//s1.s2????????????
					strcpy(A[8*(j-1)+4], strcat(s2,s1));
					break;
					//s1???????????¢
				case 6:
					strcpy(A[8*(j-1)+5],strcat(s2_rev,s1));
					break;
					//s2???????????¢
				case 7:
					strcpy(A[8*(j-1)+6],strcat(s2,s1_rev));
					break;
				case 8:
					//s1,s2???????????¢
					strcpy(A[8*(j-1)+7],strcat(s2_rev,s1_rev));
					break;
				}
			}
		}
		A_max=8*(strlen(c)-1);

		for(k=0;k<A_max;k++) {
			if(k==0)
				answer++;
			else {
				for(l=0;l<k;l++) {
					if(!strcmp(A[l],A[k]))
						break;
					else if(l==k-1) {
						answer++;
					}
				}
			}

		}
		printf("%d\n",answer);
	}

	return 0;
}

Measured memory_bytes: 1748