akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
int n,m;
string f[15];

bool forbid[15][15][15][15];

bool rec(int mask,vector<P>mch,bool ok){
    int yet = -1;
    for(int i=0;i<n;i++){
        if(!((mask>>i)&1)){
            yet = i; break;
        }
    }
    if(yet != -1){
        vector<int>zan;
        for(int i=yet+1;i<n;i++){
            if(!((mask>>i)&1)){
                zan.pb(i);
            }
        }
        for(int i=0;i<zan.size();i++){
            int newmask = mask+(1<<yet)+(1<<zan[i]);
            mch.pb(mp(yet,zan[i]));
            if(rec(newmask,mch,ok)) return true;
            mch.pop_back();
        }
        if(ok){
            int newmask = mask+(1<<yet);
            mch.pb(mp(yet,yet));
            if(rec(newmask,mch,false)) return true;
        }
        return false;
    }
    else{
        bool bad[15][15]={};
        for(int i=0;i<mch.size();i++){
            int a = mch[i].fi,b = mch[i].sc;
            for(int c=0;c<m;c++) for(int d=0;d<m;d++) bad[c][d] |= forbid[a][b][c][d];
        }
        bool okk[(1<<12)]={};
        okk[0] = true;
        for(int i=0;i<(1<<m);i++){
            if(okk[i] == false) continue;
            for(int j=0;j<m;j++){
                for(int k=0;k<m;k++){
                    if( ((i>>j)&1) || ((i>>k)&1) ) continue;
                    if(bad[j][k]) continue;
                    if(__builtin_popcount(i) != m-1 && j==k) continue;
                    okk[i | (1<<j) | (1<<k)] = true;
                }
            }
        }
        return okk[(1<<m)-1];
    }
}
int main(){
    cin>>n>>m;
    rep(i,n){
        cin>>f[i];
    }
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            for(int a=0;a<m;a++){
                for(int b=0;b<m;b++){
                    if(f[i][a] == f[j][b] && f[i][b] == f[j][a]);
                    else{
                        forbid[i][j][a][b] = true;
                    }
                }
            }
        }
    }
    bool flag = rec(0,vector<P>(),n%2);
    puts(flag?"YES":"NO");
}


Measured memory_bytes: 256
// Original: https://github.com/tanakh/competitive-rs
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::BTreeMap;

fn main() {
    input!(n: usize, mut ps: [usize1; n]);

    let mut cnt = 0;
    for l in 0..n - 1 {
        if ps[l] == l {
            let tmp = ps[l];
            ps[l] = ps[l + 1];
            ps[l + 1] = tmp;
            cnt += 1;
        }
    }
    if ps[n - 1] == n - 1 {
        cnt += 1;
    }
    println!("{}", cnt);
}


Measured memory_bytes: 4352
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <string>

using namespace std;

int main()
{
    int n, a[101];
    int ans = 0;

    cin >> n;

    for (int i = 0; i < n; i++) {
        cin >> a[i];
        ans += a[i];
    }

    sort(a, a+n);
    if (ans%10) {
        cout << ans << endl;
    }
    else {
        for (int i = 0; i < n; i++) {
            if (a[i]%10) {
                ans -= a[i];
                break;
            }
        }
        if (!(ans%10)) {
            cout << 0 << endl;
        }
        else {
            cout << ans << endl;
        }
    }
}


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

int N;
int A[200010];
int dp[200010];
int INF = 1001001001;
int MAX = 0;

int main()
{
    scanf("%d",&N);
    for(int i = 0; i < N; i++)scanf("%d",A + i);

    for(int i = 0; i <= N; i++)dp[i] = -INF;

    for(int i = 0; i < N; i++)
    {
        int now = A[i];
        dp[now] = max(1,dp[now - 1] + 1);
        MAX = max(MAX,dp[now]);
    }

    printf("%d\n",N - MAX);
    return 0;
}


Measured memory_bytes: 1792
k, a, b = map(int, input().split())
if (a + 2 >= b):
  print(k + 1)
else:
  bisc = a
  k -= a - 1
  bisc += (b - a) * (k // 2)
  if (k % 2):
    bisc += 1
  print(bisc)

Measured memory_bytes: 2940
import math
a, b, h, m = map(int, input().split())
h = h*30 + m*0.5
m = m*6
rad = abs(h-m)
if rad > 180:
        rad = 360-rad
c2 = a*a + b*b - 2*a*b*math.cos(math.radians(rad))
#print(rad)
print(math.sqrt(c2))

Measured memory_bytes: 9452
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
    REP(i,v.size()){if(i)os<<" ";os<<v[i];}return os;}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
    REP(i,v.size()){if(i)os<<endl;os<<v[i];}return os;}

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

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

vector< vector<int> > Graph;
vector< int > value;



int main(int argc, const char * argv[]) {
    
  

    cin.tie(0);
    ios::sync_with_stdio(false);
   
    
    int n,t; cin >> n >> t;
    vector<pair<int, int>> CT;
    for (int i = 0; i < n; i++) {
        int cost,time; cin >> cost >> time;
        CT.push_back(make_pair(cost, time));
    }
    
    int ans = 9999999;
    for (int i = 0; i < n; i++) {
        if(CT[i].second <= t) ans = min(ans,CT[i].first);
    }
     
    if(ans > 100000) cout << "TLE" << endl;
    else cout << ans << endl;
    
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int main()
{
	int n;
	int w[105];
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>w[i];
	}
	int cnt=9999;
	for(int i=0;i<n;i++)
	{
		int ans1=0,ans2=0;
		for(int j=0;j<=i;j++){
			ans1+=w[j];
		}
		for(int k=i+1;k<n;k++){
			ans2+=w[k];
		}
		if(ans1>=ans2){
			if(ans1-ans2<cnt){
				cnt=ans1-ans2;
			}
		}else{
			if(ans2-ans1<cnt){
				cnt=ans2-ans1;
			}
		}
	}
	cout<<cnt;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll>pi;
const int MAXN=100005;
const int MOD=1000000007;

#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define DEC(i,a,b) for(int i=(a);i>=(b);i--)
#define fst first
#define snd second
#define pb push_back
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(),(v).end()
#define db(x) cerr<<#x<<" = "<<x<<"\n"
#define LOW(v,x) (lower_bound(all(v),(x))-(v).begin())
#define UP(v,x) (upper_bound(all(v),(x))-(v).begin())

main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int A, B; cin>>A>>B;
	FOR(i,1,2000){
		if (i*8/100==A && i*10/100==B){
			cout<<i;
			exit(0);
		}
	}
	cout<<-1;
	exit(0);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
vector <ll> v[100004];
ll dp[100004][2];
ll m=1e9+7;
void dfs (ll i,ll j)
{
	for (ll k=0;k<v[i].size();k++)
	{
		ll temp=v[i][k];
		if (temp!=j)
		{
			dfs(temp,i);
			dp[i][0]=((dp[temp][0]%m+dp[temp][1]%m)*dp[i][0]%m)%m;
			dp[i][1]=(dp[temp][0]%m*dp[i][1]%m)%m;
		}
	}
}
int main()
{
	ll n;
	cin>>n;
	for (ll i=0;i<n-1;i++)
	{
		ll a,b;
		cin>>a>>b;
		v[a].push_back(b);
		v[b].push_back(a);
	}
	dp[1][0]=1;
	dp[1][1]=1;
	for (ll i=2;i<=n;i++)
		dp[i][0]=dp[i][1]=1;
	dfs(1,-1);
	cout<<(dp[1][0]%m+dp[1][1]%m)%m;
}

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

using namespace std;

#define sp << " " <<

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n,dp=0;
    cin >> n;
    string d,p,s;
    cin >> d >> p >> s;
    for(int i=0;i<n;i++)
    {
        if(d[i]==p[i]&&p[i]==s[i])
            dp+=0;
        else if(d[i]==p[i]||p[i]==s[i]||d[i]==s[i])
            dp+=1;
        else
            dp+=2;
    }
    cout << dp;
    return 0;
}


Measured memory_bytes: 256
a,b,c,d = map(int, input().split())
if a < 0 and b < 0 and c < 0: 
  print(a*c)
elif a < 0 and b < 0 and c >= 0 and d >= 0:
  print(b*c)
elif a < 0 and b >= 0 and c < 0 and d < 0:
  print(a*c)
elif a < 0 and b >= 0 and c < 0 and d >= 0:
  print(max(a*c, b*d))
elif a < 0 and b >= 0 and c >= 0 and d >= 0:
  print(b*d)
elif a >= 0 and b >= 0 and c < 0 and d < 0:
  print(a*d)
else:
  print(b*d)

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

using namespace std;

typedef long long int ll;
typedef pair<int,int> ii;

const int N = 3e2 + 5;

int n,m,a[N][N],l[N],cnt[N];
bool used[N];

inline void relax() {
  for (int i = 1 ; i <= n ; i++)
    while(l[i] <= m && used[a[i][l[i]]])
      l[i]++;
}

inline bool is_gg() {
  for (int i = 1 ; i <= n ; i++)
    if (l[i] > m)
      return true;
  return false;
}

bool check(int x) {
  // cerr << x << endl;
  // cerr << "helal" << endl;
  memset(used,0,sizeof used);
  for (int i = 1 ; i <= n ; i++)
    l[i] = 1;
  int adim = 0;
  while(true) {
    relax();
    if (is_gg())
      break;
    memset(cnt,0,sizeof cnt);
    // cerr << "Adim : " << adim << endl;
    // for (int i = 1 ; i <= n ; i++)
      // cerr << i << " " << a[i][l[i]] << endl;
    // getchar();
    for (int i = 1 ; i <= n ; i++)
      cnt[a[i][l[i]]]++;
    bool ok = true;
    for (int i = 1 ; i <= m ; i++)
      if (cnt[i] > x) {
        // cerr << " anaskm " << i << " " << cnt[i] << endl;
        ok = false;
        used[i] = true;
        break;
      }
    if (ok == true)
      return true;
  }
  return false;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL); cout.tie(NULL);
  cin >> n >> m;
  for (int i = 1 ; i <= n ; i++)
    for (int j = 1 ; j <= m ; j++)
      cin >> a[i][j];
  int l = 0,r = n;
  while(l < r) {
    int mid = (l + r - 1);
    if (check(mid))
      r = mid;
    else
      l = mid + 1;
  }
  cout << r << endl;;
}

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

//UnionFind
//0-indexed
//#include <vector>
struct union_find {
  std::vector<long long> parent;
  std::vector<long long> sizes;
  long long num_of_trees;

  //コンストラクタ
  union_find(long long n) {
    for (long long i = 0; i < n; i++) {
      parent.push_back(i);
      sizes.push_back(1);
    }
    num_of_trees = n;
  }

  //頂点nの根
  long long root_of(long long n) {
    if (parent[n] == n) return n;
    return parent[n] = root_of(parent[n]); //パス圧縮
  }

  //頂点nを含む木の頂点数(自身含む)
  long long size_of(long long n) {return sizes[root_of(n)];}

  //頂点a, bが間接的に繋がっているか判定
  bool is_united(long long a, long long b) {return (root_of(a) == root_of(b));}

  //頂点aを含むグラフに頂点bを含むグラフを結合
  void unite(long long a, long long b) {
    if (is_united(a, b)) return;
    num_of_trees--;
    if (size_of(a) < size_of(b)) std::swap(a, b); //マージテク
    sizes[root_of(a)] += size_of(b);
    parent[root_of(b)] = root_of(a);
  }
};

int main() {
  long long n, m, k;
  std::cin >> n >> m >> k;

  union_find uf(n);

  std::vector<std::vector<long long>> nx(n, std::vector<long long>(0));
  for (long long i = 0; i < m; i++) {
    long long a, b;
    std::cin >> a >> b;
    nx[a - 1].push_back(b - 1);
    nx[b - 1].push_back(a - 1);
    uf.unite(a - 1, b - 1);
  }

  std::vector<long long> bl(n, 0);
  for (long long i = 0; i < k; i++) {
    long long c, d;
    std::cin >> c >> d;
    if (uf.is_united(c - 1, d - 1)) {
      bl[c - 1]++;
      bl[d - 1]++;
    }
  }

  for (long long i = 0; i < n - 1; i++) std::cout << uf.size_of(i) - 1 - nx[i].size() - bl[i] << " ";
  std::cout << uf.size_of(n - 1) - 1 - nx[n - 1].size() - bl[n - 1] << std::endl;
}

Measured memory_bytes: 9452
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <bits/stdc++.h>
#include<queue>
#include <numeric>
#include<stdio.h>
using namespace std;
 
//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
 
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}
 template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
 
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define fore(i,a) for(auto &i:a)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
 
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
 
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
 

LL gcd(LL a, LL b){
    if(b == 0) return a;
    return gcd(b,a%b);
}

LL lcm(LL a, LL b){
    LL g = gcd(a,b);
    return a/g *b;
}

int main(){
    int N,X;
    cin >> N >> X;
    int L[N];
    REP(i,N) cin >> L[i];
    int num=1;
    int sum=0;
    for(int i=0;i<N;++i){
        sum+=L[i];
        if(sum<=X){
            ++num;
        }
        else{
            break;
        }
    }
    cout << num;
    }

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cmath>

int main()
{
    const double Pi = 3.14159265359;

    int a, b, h, m;
    std::cin >> a >> b >> h >> m;
    double rad_h = (h + m / 60.0) / 12.0 * Pi * 2 + Pi / 2;
    double rad_m = m / 60.0 * Pi * 2 + Pi / 2;
    double rx = std::cos(rad_h) * a - std::cos(rad_m) * b;
    double ry = std::sin(rad_h) * a - std::sin(rad_m) * b;
    std::cout << std::fixed << std::setprecision(15) << std::sqrt(rx * rx + ry * ry) << std::endl;
}


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

#define LL long long
#define LD long double
#define SC(t,x) static_cast<t>(x)
#define AR(t) vector < t >
#define PII pair < int, int >
#define PLL pair < LL, LL >
#define PIL pair < int, LL >
#define PLI pair < LL, int >
#define MP make_pair
#define PB push_back
#define PF push_front
#define POB pop_back
#define POF pop_front
#define PRF first
#define PRS second
#define INIT(ar,val) memset ( ar, val, sizeof ( ar ) )
#define lp(loop,start,end) for ( int loop = start; loop < end; ++loop )
#define lpd(loop,start,end) for ( int loop = start; loop > end; --loop )
#define lpi(loop,start,end) for ( int loop = start; loop <= end; ++loop )
#define lpdi(loop,start,end) for ( int loop = start; loop >= end; --loop )
#define qmax(a,b) (((a)>(b))?(a):(b))
#define qmin(a,b) (((a)<(b))?(a):(b))
#define qabs(a) (((a)>=0)?(a):(-(a)))

const int INF = 0x3fffffff;
const int SINF = 0x7fffffff;
const long long LINF = 0x3fffffffffffffff;
const long long SLINF = 0x7fffffffffffffff;
const int MAXN = 1e9;
const int MAXL = 10;

void init ();
void input ();
void work ();

bool query ( LL x );
void find ( LL x );



int main()
{
	init();
	input();
	work();
}



void init ()
{
	// Init Everything Here

	ios::sync_with_stdio ( false );
}

void input ()
{
	// input method
}

void work ()
{
	// main work

	int len = -1;
	LL bs = 1;
	lp ( i, 0, MAXL ){
		if ( !query ( bs ) ){
			len = i - 1;
			break;
		}
		bs *= 10;
	}
	if ( len == -1 ){
		bs = 10;
		lp ( i, 0, MAXL ){
			if ( query ( bs - 1 ) ){
				len = i;
				break;
			}
			bs *= 10;
		}
	}

	if ( len == MAXL - 1 ) find ( MAXN );

	int l = 1, r, mid;
	lp ( i, 0, len ) l *= 10;
	r = l * 10 - 1;
	while ( l < r ){
		mid = ( l + r ) >> 1;
		if ( query ( 1LL * mid * MAXN ) ) r = mid;
		else l = mid + 1;
	}

	find ( l );
}



bool query ( LL x )
{
	printf ( "? %lld\n", x );
	fflush ( stdout );
	char in[5];
	scanf ( "%s", in );
	return ( in[0] == 'Y' );
}

void find ( LL x )
{
	printf ( "! %lld\n", x );
	fflush ( stdout );
	exit ( 0 );
}

Measured memory_bytes: 660
#include<stdio.h>
int main(){
    int n,k;
    scanf("%d",&n);
    scanf("%d",&k);
    int x=1;
    for(int i=0;i<n;i++){
        if(x*2<x+k){
            x*=2;
        }
        else if(x*2>x+k){
            x+=k;
        }
        else{
            x*=2;
        }
    }
    printf("%d",x);
    puts("");
    return 0;
}

Measured memory_bytes: 3232
//Author:- S_Aditya
//Date created:- 24 February 2019

#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
using namespace std;
//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
#define ll long long 
#define scn(n) scanf("%d",&n)
#define lscn(n) scanf("%lld",&n)
#define lpri(n) printf("%lld",n)
#define pri(n) printf("%d",n)
#define pln() printf("\n")
#define priln(n) printf("%d\n",n)
#define lpriln(n) printf("%lld\n",n)
#define rep(i,init,n) for(int i=init;i<n;i++)
#define pb push_back     
#define mp make_pair
#define F first
#define S second
#define gcd __gcd
#define inf INT_MAX
#define ninf INT_MIN
const ll mod=1e9+7;         
const int N=22;

//mask represents a subset of women,e.g:- 010010 represents that the 2nd and 5th women are paired.

//dp[i][mask] tells the total no. of possible pairings considering the first i men
//with a subset of size i of women represented by mask.

//Answer will be dp[n][(1<<n)-1] as we have to pair all n men with all n women.
int dp[N][1<<21]; 

int can[N][N]; //can[i][j] is 1 if ith man is permitted to pair up with the jth woman,otherwise 0.

void add_self(int &a,int b)
{
    a+=b;
    
    if(a>=mod)
    a-=mod;
}

int main()                  
{
    int n;
    
    scn(n);
    
    rep(i,0,n)
    {
        rep(j,0,n)
        scn(can[i][j]);
    }
    
    dp[0][0]=1; //1 way to match no men with no women
    
    for(int i=1;i<=n;i++)
    {
        for(int mask=0;mask<(1<<n);mask++)
        {
            int set_bits=__builtin_popcount(mask);
            
            //check if no. of women in this candidate subset 
            //is equal to i(i.e the no of men to match) or not.
            if(set_bits!=i) 
            continue;
            
            //ith men should be compatible to pair with jth women
            //and jth women should be a part of the current candidate subset
            //represented by mask.
            for(int j=0;j<n;j++)
            if(can[i-1][j] and mask&(1<<j))
            {
                int temp_mask=mask^(1<<j);
                
                add_self(dp[i][mask],dp[i-1][temp_mask]);
            }
        }
    }
    
    ll ans=dp[n][(1<<n)-1];
    
    printf("%lld ",ans);
} 


Measured memory_bytes: 162048
e=Hash.new [];n=gets.to_i;(n-1).times{|i|a,b=gets.split;e[a]+=[i];e[b]+=[i]};a=[0]*(n-1);(1..n).map{|w|u={};e[v=w.to_s].map{|j|u[a[j]]=1};t=1;e[v].map{|j|1>a[j]&&(t+=1until u[t].nil?;a[j]=t;t+=1)}};p a.max;$><<a*"\n"

Measured memory_bytes: 187912
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <array>
#include <queue>
#include <map>
#include <set>
#include <sstream>
#include <stdio.h>
#include <cstdio>
#include <cstring>

using namespace std;

#define Rep(i,a,b) for(int i = a; i < b; i++)
#define rep(i,b) Rep(i,0,b)
#define rrep(i,a) for(int i = a; i >= 0; i--)
#define allof(a) (a).begin(), (a).end()

typedef long long ll;
const int inf = 1e9 + 7;
const ll infll = 1ll << 60ll;
const ll mod = 1e9 + 7;
// 0~3までは右左下上 4~7までは斜め
constexpr int dx[] = { 1, 0, -1, 0, 1, 1, -1, -1 };
constexpr int dy[] = { 0, -1, 0, 1, 1, -1, -1, 1 };

/*
// 最大公約数
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}

// 最小公倍数
ll lcm(ll a, ll b) {
	return a * b / gcd(a, b);
}*/

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

	ll a, b, c, x, y;
	cin >> a >> b >> c >> x >> y;

	ll ans = 0;

	if (a + b >= 2 * c) {
		while (x > 0 && y > 0) {
			x--;
			y--;
			ans += 2 * c;
		}
		if (x > 0) {
			if (a < 2 * c) {
				ans += x * a;
			}
			else {
				ans += x * 2 * c;
			}
		}
		else if(y > 0) {
			if (b < 2 * c) {
				ans += y * b;
			}
			else {
				ans += y * 2 * c;
			}
		}
	}
	else {
		ll tx = x;
		ll ty = y;
		if (tx > 0) {
			if (a < 2 * c) {
				ans += tx * a;
			}
			else {
				ans += tx * 2 * c;
				ty -= tx;
			}
		}
		if (ty > 0) {
			if (b < 2 * c) {
				ans += ty * b;
			}
			else {
				ans += ty * 2 * c;
			}
		}

		ll tmp = 0;

		if (y > 0) {
			if (b < 2 * c) {
				tmp += y * b;
			}
			else {
				tmp += y * 2 * c;
				x -= y;
			}
		}
		if (x > 0) {
			if (a < 2 * c) {
				tmp += x * a;
			}
			else {
				tmp += x * 2 * c;
				y -= x;
			}
		}

		ans = min(ans, tmp);
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
N = int(input())
P = list(map(int, input().split()))

dp = [[min(i, N - i - 1, j, N - j - 1) for j in range(N)] for i in range(N)]

presence = [[1 for j in range(N)] for i in range(N)]

ans = 0
for i in range(len(P)):
    P[i] -= 1
    x, y = divmod(P[i], N)
    ans += dp[x][y]
    presence[x][y] = 0

    Q = [(x, y)]
    while Q:
        x, y = Q.pop()
        new_value = dp[x][y] + presence[x][y]
        if 1 <= x and dp[x - 1][y] > new_value:
            dp[x - 1][y] = new_value
            Q.append((x - 1, y))
        if x < N - 1 and dp[x + 1][y] > new_value:
            dp[x + 1][y] = new_value
            Q.append((x + 1, y))
        if 1 <= y and dp[x][y - 1] > new_value:
            dp[x][y - 1] = new_value
            Q.append((x, y - 1))
        if y < N - 1 and dp[x][y + 1] > new_value:
            dp[x][y + 1] = new_value
            Q.append((x, y + 1))


print(ans)

Measured memory_bytes: 154660
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner stdIn=new Scanner(System.in);
		int N=stdIn.nextInt();
		int z=0;
		if(N/100==9)
			z=100;
		else
			z=900;
		if((N%100)/10==9)
			z+=10;
		else
			z+=90;
		if(((N%100)%10)==9)
			z+=1;
		else
			z+=9;
		System.out.println(z);
	}
}


Measured memory_bytes: 21844
#include<iostream>
#include<vector>
#include<string>
using namespace std;
// #define MAX 1000003
class Dictionary{
    const int MAX = 1000003;
    vector<int> D;
    int get_key(char c) {
        if (c == 'A') return 1;
        if (c == 'C') return 2;
        if (c == 'G') return 3;
        return 4;
    }
    int keta(int N) {
        int ret = 1;
        for (int i = 0; i < N; i++) {
            ret *= 5;
        }
        return ret;
    }
    int make_key(string s){
        int key = 0;
        for (int i = 0; i < s.size(); i++) {
            key += get_key(s[i]) * keta(i);
        }
        return key;
    }
    int hash1(int key){
        return key % MAX;
    }
    int hash2(int key){
        return 1 + (key % (MAX - 1));
    }
public:
    Dictionary(){
        D.resize(MAX);
        for (auto& d : D) d = 0;
    }
    void insert(string s){
        int key = make_key(s);
        int h = hash1(key);
        while (D[h]) h = (h + hash2(key)) % MAX;
        D[h] = key;
    }
    bool find(string s){
        int key = make_key(s);
        int h = hash1(key);
        while (D[h]) {
            if (key == D[h]) return true;
            h = (h + hash2(key)) % MAX;
        }
        return false;
    }
};

int main(){
    int n;
    cin >> n;
    Dictionary d;
    for (int i = 0; i < n; i++) {
        string command;
        string content;
        cin >> command >> content;
        if (command == "insert") {
            d.insert(content);
            continue;
        }
        cout << (d.find(content) ? "yes" : "no") << endl;
    }
    return 0;
}

Measured memory_bytes: 6800
#include <stdio.h>

#define MAX 1000

int main() {
  int i,j,k,v;
  int N;
  int A[MAX];

  scanf("%d",&N);
  if(N < 0 || 100 < N){
    return 0;
  }
  for(i = 0; i < N; i++){
    scanf("%d",&A[i]);
  }
  for(i = 0; i < N; i++){
    v = A[i];
    j = i-1;

    while(j>=0 && A[j] > v){
      A[j+1] = A[j];
      j--;
      //printf("%d ",A[j]);                                                     
    }
    A[j+1] = v;
    for(k = 0; k < N; k++){
      if(k){
	printf(" ");
      }
      printf("%d",A[k]);
    }
    printf("\n");
  }
  //printf("\n");                                                               
  for(i = 0; i < N; i++){
    //printf("%d ",A[i]);                                                       
  }
  //printf("\n");                                                               

  return 0;
}

Measured memory_bytes: 608
#include<iostream>
using namespace std;
int main(){
	int n;
	cin >> n;
	int a = 1;
	int b = 1;
	for(int i=1; i<n;++i){
		int t = b;
		b = a + b;
		a = t;
	}
	cout << b << std::endl;
}

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

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

    int ans=0;
    for(int i=1 ; i<=n ; i++){
        int count=0;
        for(int j=1 ; j<=i ; j++){
            if(i%j == 0)
                count++;
        }
        if(i%2 == 1 && count == 8)
            ans++;
    }

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

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

using namespace std;
typedef int64_t ll;
typedef uint64_t ull;
typedef long double ld;

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

	int n;
	cin >> n;
	vector<int> b(n-1);
	for(int i = 0; i < n-1; i++) cin >> b[i];

	vector<int> a(n, INT_MAX);
	for(int i = 0; i < n-1; i++) {
		a[i] = min(a[i], b[i]);
		a[i+1] = min(a[i+1], b[i]);
	}
	
	cout << accumulate(a.begin(), a.end(), 0);

	cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << " ms.\n";
}

// g++ o .cpp -O2 -std=c++11 -D cute -Wall -Wno-unused-result



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<LL,LL> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a,T b){return b?gcd(b,a%b):a;}
const LL mod=998244353;
const LL LINF=1LL<<62;
const int INF=1<<30;
int dx[]={1,0,-1,0,-1,1,1,-1};
int dy[]={0,1,0,-1,-1,-1,1,1};



int main(){
    int n;cin >> n;
    vector<LL> a(n),b(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i] >> b[i];
    }
    sort(ALL(a));
    sort(ALL(b));
    if(n%2 == 1){
        cout << (b[n/2] - a[n/2] + 1) << endl;
    }
    else{
        LL la = a[(n - 1) / 2], ra = a[n / 2];
        LL lb = b[(n - 1) / 2], rb = b[n / 2];
        LL ans = (rb + lb) - (ra + la);
        cout << ans + 1 << endl;
    }
    return 0;
}


Measured memory_bytes: 6424
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <numeric>
#include <iomanip>

#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
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; }

#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;
struct INIT { INIT(){
  cin.tie(0); ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
}}INIT;


signed main() {
  string s;
  cin >> s;

  int a = stoi(s.substr(0, 2));
  int b = stoi(s.substr(2, 4));

  if(0 < a && a <= 12 && 0 < b && b <= 12) cout << "AMBIGUOUS" << "\n";
  else if((a == 0 && b == 0) || (min(a, b) == 0 && max(a, b) > 12) || min(a, b) > 12) cout << "NA" << "\n";
  else if(a == 0 || a > 12) cout << "YYMM" << "\n";
  else cout << "MMYY" << "\n";

  return 0;
}


Measured memory_bytes: 3620
#include <iostream>
#include <vector>
#include <queue>

using lli = long long int;
using Vint = std::vector<int>;
using Wint = std::vector<Vint>;

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

int main(void){
    lli n, k; scanf("%lld%lld", &n, &k);
    int MX = -1;
    Vint A(n); REP(i, n){
        scanf("%d", &A[i]);
        if(MX < A[i]) MX = A[i];
    }
    Wint Indexes(MX + 1, Vint(0)); // インデックスを表すデータ構造
    REP(i, n) Indexes[A[i]].push_back(i);
    Vint ComeLoop(n, -1); // すでに訪れたかを表すデータ(初めてついた時点でのループの回数)
    Vint Nxt_Index(n, -1); // 次のの場所をさす : x -> x の位置をさす
    FOReq(val, 1, MX) if(Indexes[val].size() != 0){
        int sz = Indexes[val].size();
        REP(i, sz - 1) Nxt_Index[Indexes[val][i]] = Indexes[val][i+1];
        Nxt_Index[Indexes[val][sz-1]] = Indexes[val][0];
    }
    int idx = 0; lli b = 0; int Loop = 0;
    while(true){
        if(ComeLoop[idx] != -1) break;
        ComeLoop[idx] = Loop;
        int nxt_idx = Nxt_Index[idx];
        int cost = (nxt_idx > idx) ? nxt_idx - idx : (n - idx) + nxt_idx;
        b += cost + 1;
        if(nxt_idx <= idx) Loop++;
        if(nxt_idx == n-1) Loop++;
        idx = (nxt_idx + 1) % n;
    }

    lli M = n * k;
    int v;
    if(M < b) v = 0;
    else{
        M -= b; v = idx;
        
        int LOOP = Loop - ComeLoop[idx];
        M %= (LOOP * n);
    }
    while(true){
        int v2 = Nxt_Index[v];
        int cost = (v2 > v) ? v2 - v : (n - v) + v2; cost++;
        if(cost > M) break;
        M -= cost;
        v = (v2 + 1) % n;
    }
    int buffor = M;

    std::queue<int> RES;
    while(buffor > 0){
        int v2 = Nxt_Index[v];
        int dist = (v2 > v) ? v2 - v : (n - v) + v2; dist++;
        if(dist <= buffor){
            buffor -= dist;
            v = (v2 + 1) % n;
        }
        else{
            RES.push(A[v]); buffor--;
            (v += 1) %= n;
        }
    }
    while(not RES.empty()){
        printf("%d", RES.front()); RES.pop();
        putchar(RES.empty() ? '\n' : ' ');
    }
    return 0;
}

Measured memory_bytes: 15616
#include <iostream>
#include <string>

int main()
{
    std::string N;
    std::cin >> N;

    int sum = 0;
    for(int i = 0; i < N.size(); i++)
    {
        char now = N[i];
        sum += atoi(&now);
        
    }
    std::string ans;
    if( sum % 9 == 0)
    {
        ans = "Yes";
    }
    else
    {
        ans = "No";
    }

    std::cout << ans << std::endl;
    

    return 0;
}

Measured memory_bytes: 3740
#AGC030 A- Poisonous Cookies
a,b,c = [int(i) for i in input().split()]
if a+b>=c:
    print(b+c)
else:#毒入りのほうが多い→毒入りは薬＋１枚食べられる
    print(a+2*b+1)


Measured memory_bytes: 2940
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
)

func main() {
	r := bufio.NewReader(os.Stdin)
	var s string
	var k int
	fmt.Fscan(r, &s)
	fmt.Fscan(r, &k)

	mp := make(map[string]bool)
	var ss []string
	for i := 1; i <= k; i++ {
		for j := 0; i+j <= len(s); j++ {
			tmpS := s[j : i+j]
			if mp[tmpS] == false {
				ss = append(ss, tmpS)
				mp[tmpS] = true
			}
		}
	}

	sort.Strings(ss)

	fmt.Println(ss[k-1])
}

// Union-Find
type unionFind struct {
	d []int
}

func newUnionFind(n int) *unionFind {
	uf := new(unionFind)
	uf.d = make([]int, n)
	for i := 0; i < n; i++ {
		uf.d[i] = -1
	}
	return uf
}

func (uf *unionFind) find(x int) int {
	if uf.d[x] < 0 {
		return x
	}
	uf.d[x] = uf.find(uf.d[x])
	return uf.d[x]
}

func (uf *unionFind) unite(x, y int) bool {
	rootX := uf.find(x)
	rootY := uf.find(y)
	if rootX == rootY {
		return false
	}

	if uf.d[rootX] < uf.d[rootY] {
		uf.d[rootX] += uf.d[rootY]
		uf.d[rootY] = rootX
	} else {
		uf.d[rootY] += uf.d[rootX]
		uf.d[rootX] = rootY
	}

	return true
}

func (uf *unionFind) same(x, y int) bool {
	return uf.find(x) == uf.find(y)
}

func (uf *unionFind) size(x int) int {
	return -uf.d[uf.find(x)]
}

// mod combination
func modpow(a, n, mod int) int {
	res := 1
	for n > 0 {
		if n%2 != 0 {
			res = res * a % mod
		}
		a = a * a % mod
		n = n / 2
	}
	return res
}

func modcomb(n, a, mod int) int {
	x := 1
	y := 1
	for i := 0; i < a; i++ {
		x = x * (n - i)
		x %= mod
		y = y * (i + 1)
		y %= mod
	}
	return x * modpow(y, mod-2, mod) % mod
}

func modfactorial(n, mod int) int {
	result := 1
	for i := 1; i <= n; i++ {
		result = (result * i) % mod
	}
	return result
}

// Utility

func min(x, y int) int {
	if x < y {
		return x
	}
	return y
}

func max(x, y int) int {
	if x > y {
		return x
	}
	return y
}

func abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

func primeFactor(x int) map[int]int {
	res := make(map[int]int)
	for i := 2; i*i <= x; i++ {
		for x%i == 0 {
			res[i]++
			x = x / i
		}
	}
	if x != 1 {
		res[x] = 1
	}
	return res
}

func divisor(x int) []int {
	res := make([]int, 0)
	for i := 1; i*i <= x; i++ {
		if x%i == 0 {
			res = append(res, i)
			if i != x/i {
				res = append(res, x/i)
			}
		}
	}
	return res
}

func gcd(x, y int) int {
	if y == 0 {
		return x
	}
	return gcd(y, x%y)
}

func lcm(x, y int) int {
	return x / gcd(x, y) * y
}

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

// Queue ...
type Queue []int

// pop ...
func (q *Queue) empty() bool {
	return len(*q) == 0
}

// push ...
func (q *Queue) push(i int) {
	*q = append(*q, i)
}

// pop ...
func (q *Queue) pop() (int, bool) {
	if q.empty() {
		return 0, false
	} else {
		res := (*q)[0]
		*q = (*q)[1:]
		return res, true
	}
}

// Stack ...
type Stack []int

// pop ...
func (s *Stack) empty() bool {
	return len(*s) == 0
}

// push ...
func (s *Stack) push(i int) {
	*s = append(*s, i)
}

// pop ...
func (s *Stack) pop() (int, bool) {
	if s.empty() {
		return 0, false
	} else {
		index := len(*s) - 1
		res := (*s)[index]
		*s = (*s)[:index]
		return res, true
	}
}


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

int n,k;
long long T[100000];

int P(long long p)
{
	int i=0,j;
	long long s;
	for(j=0;j<=k-1;j++)
	{
		s=0;
		while(s+T[i]<=p)
		{
			s+=T[i];
			i++;
			if(i==n) return n;
		}
	}
	return i;
}


int main()
{
	int i;
	long long left=0;
	long long right;
	long long mid;
	int v;
	
	cin >> n;
	cin >> k;
	right=10000*n;
	for(i=0;i<=n-1;i++) cin >> T[i];
	while(right-left>1)
	{
		mid=(right+left)/2;
		v=P(mid);
		if(v>=n) right=mid;
		else left=mid;
	}
	cout << right << endl;
	return 0;
}

Measured memory_bytes: 3884
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;

public class Main {

    public static void main(String[] args) {

        InputStreamReader isr = new InputStreamReader(System.in);
        BufferedReader br = new BufferedReader(isr);

        String str1 = null;


        PrintWriter out = new PrintWriter(System.out);
        try {
            str1 = br.readLine();

            int intCnt1 = 0;
            int intCnt2 = 0;

        	boolean bIsWhite = true;
            for (int i=0 ; i < str1.length() ; i++) {

            	if (str1.charAt(i) == (bIsWhite ? '0' : '1')) {
            		intCnt1++;
            	} else {
            		intCnt2++;
            	}
            	bIsWhite = !bIsWhite;
            }


            System.out.println(intCnt1 < intCnt2 ? intCnt1 : intCnt2 );


        } catch (IOException e) {

        }


    }
}

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

const int MaxN = 100000;
int S[ MaxN + 10 ];

int main()
{
int i;
int N;
int M;
int A;
long long x;
long long iCnt;
int iSum;

	scanf( "%d %d", &N, &M );

	iSum = 0;
	iCnt = 0;
	for( i = 1; i <= N; i++ )
	{
		scanf( "%d", &A );

		iSum += A;
		iSum %= M;
		S[ i ] = iSum;
	}

	sort( S, S + ( N + 1 ) );

	x = 0;
	for( i = 1; i <= N; i++ )
	{
		if( S[ i - 1 ] == S[ i ] )
			x++;
		else
		{
			iCnt += ( x + 1 ) * x / 2;
			x = 0;
		}
	}

	if( x > 0 ) iCnt += ( x + 1 ) * x / 2;

	printf( "%lld\n", iCnt );

	return 0;
}






Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int n,k;
vector<int> G[2010];
int a[2010], b[2010];
bool used[2010];
int dfs(int nd, int d) {
    int ans = (d > k / 2);
    for (int i = 0; i < G[nd].size(); i++) {
        if (used[G[nd][i]]) continue;
        used[G[nd][i]] = 1;
        ans += dfs(G[nd][i], d+1);
    }
    return ans;
}
 
int main() {
    cin >> n >> k;
    for (int i = 0; i < n - 1; i++) {
        cin >> a[i] >> b[i];
        a[i]--;
        b[i]--;
        G[a[i]].push_back(b[i]);
        G[b[i]].push_back(a[i]);
    }
    int ans = n;
    if (k&1) {
        for (int i = 0; i < n - 1; i++) {
            memset(used,0,sizeof(used));
            used[a[i]] = 1;
            used[b[i]] = 1;
            ans = min(ans, dfs(a[i], 0) + dfs(b[i], 0));
        }
    } else {
        for (int i = 0; i < n; i++) {
            memset(used,0,sizeof(used));
            used[i] = 1;
            ans = min(ans, dfs(i,0));
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3732
#include <iostream>
#include <vector>
#include <limits.h>
using namespace std;
using ll=long long;

int main(){
    const ll INF=LLONG_MAX/2;
    int n;
    cin>>n;
    vector<int> a(n);
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    ll ret=0;
    if(n%2==0){
        vector<vector<vector<ll>>> dp(n,vector<vector<ll>>(2,vector<ll>(2,-INF)));
        dp[0][0][0]=0;
        dp[0][1][1]=a[0];
        for(int i=1;i<n;i++){
            if(i%2==0){
                dp[i][0][0]=max(dp[i-1][0][1],dp[i-1][1][1]);
                dp[i][0][1]=-INF;
                dp[i][1][0]=-INF;
                dp[i][1][1]=dp[i-1][0][1]+a[i];
            }else{
                dp[i][0][0]=-INF;
                dp[i][0][1]=dp[i-1][1][1];
                dp[i][1][0]=-INF;
                dp[i][1][1]=dp[i-1][0][0]+a[i];
            }
        }
        ret=max(dp[n-1][0][1],dp[n-1][1][1]);
    }else{
        vector<vector<vector<ll>>> dp(n,vector<vector<ll>>(2,vector<ll>(2,-INF)));
        dp[0][0][0]=0;
        dp[0][1][1]=a[0];
        for(int i=1;i<n;i++){
            if(i%2==0){
                dp[i][0][0]=max(dp[i-1][0][1],dp[i-1][1][1]);
                dp[i][0][1]=-INF;
                dp[i][1][0]=dp[i-1][0][0]+a[i];
                dp[i][1][1]=dp[i-1][0][1]+a[i];
            }else{
                dp[i][0][0]=max(dp[i-1][0][0],dp[i-1][1][0]);
                dp[i][0][1]=max(dp[i-1][0][1],dp[i-1][1][1]);
                dp[i][1][0]=-INF;
                dp[i][1][1]=dp[i-1][0][0]+a[i];
            }
        }
        ret=max(dp[n-1][0][0],dp[n-1][1][0]);
    }
    cout<<ret<<endl;
}


Measured memory_bytes: 33568
#import numpy as np
import sys
input = sys.stdin.readline


def main():
    h, n = map(int, input().split())
    # A = []
    # B = []
    # for _ in range(n):
    #     A.append(a)
    #     B.append(b)
        
    m = 2 * 10**4 + 10
    dp = [float("inf")] * (h+1)
    dp[0] = 0
    # for a, b in zip(A, B):
    #     dp[a] = b
    for _ in range(n):
        a, b = map(int, input().split())
        for i in range(h):
            # for a, b in zip(A, B):
            if i + a < m :
                j = min(i+a, h)
                if dp[j] > 0:
                    dp[j] = min(dp[j], dp[i] + b)
                else:
                    dp[j] = dp[i] + b
    k = h
    # print(dp[:20])
    # while (flag):
    #     if dp[k] > 0:
    #         ans = dp[k]
    #         flag = 0
    #     k += 1
    # d = np.array(dp[k:])
    # print(np.min(d[d.nonzero()]))
    print(dp[h])
    
    
main()


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

constexpr int INF = numeric_limits<int>::max() / 4;

#define REP(i, stop) FOR(i, 0, stop)
#define FOR(i, start, stop) for (int i = start, i##_len = stop; i < i##_len; ++i)

signed main() {
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	int N;
	cin >> N;
	vector<string> S(N);
	REP(i, N) cin >> S[i];
	vector<vector<int>> d(N, vector<int>(N));
	REP(i, N) REP(j, N) {
		d[i][j] = i == j ? 0 : S[i][j] == '1' ? 1 : INF;
	}
	REP(k, N) REP(i, N) REP(j, N) {
		int *ij = &d[i][j];
		int *ik = &d[i][k];
		int *kj = &d[k][j];
		if (*ik == INF) continue;
		if (*kj == INF) continue;
		if (*ij == INF) {
			*ij = *ik + *kj;
		} else {
			if ((*ij + *ik + *kj) & 1 == 1) {
				cout << -1 << endl;
				return 0;
			}
			if (*ij > *ik + *kj) {
				*ij = *ik + *kj;
			}
		}
	}
	int ans = 0;
	REP(i, N) REP(j, N) {
		if (d[i][j] != INF)
			ans = max(ans, d[i][j]);
	}
	cout << ans + 1 << endl;
}


Measured memory_bytes: 512
// n<10^5
// o(nlogn);

#include <cstdio>
#include <iostream>
using namespace std;

int n, a[200005];

inline bool check(const int &k) {
  if ((a[n - 1] <= k && a[n] <= k) || (a[n] <= k && a[n + 1] <= k))
    return 1;
  if ((a[n - 1] > k && a[n] > k) || (a[n] > k && a[n + 1] > k))
    return 0;
  for (int i = 1; i < n - 1; i++) {
    if ((a[n + i] <= k && a[n + i + 1] <= k) ||
        (a[n - i] <= k && a[n - i - 1] <= k))
      return 1;
    if ((a[n + i] > k && a[n + i + 1] > k) ||
        (a[n - i] > k && a[n - i - 1] > k))
      return 0;
  }
  return a[1] <= k;
}

int main() {
  scanf("%d", &n);
  for (int i = 1; i < n << 1; i++)
    scanf("%d", a + i);
  int l = 1, r = (n << 1) - 1;
  while (l < r) {
    int mid = l + r >> 1;
    if (check(mid))
      r = mid;
    else
      l = mid + 1;
  }
  printf("%d", r);
}


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

int main(){
    int n, k;
    cin >> n >> k;
    int a[n] = {0};
    for(int i=0; i<n; i++) cin >> a[i];
    
    int v[n] = {0};
    int i=0;
    
    for(int i=0; i<n; i++)
    {
        v[a[i]-1]++;
    }
    
    sort(v, v + n, greater<int>());
    int ans = 0;
    
    for(int i=k; i<n; i++)
    {
        ans += v[i];
    }
    cout << ans << endl;
    return 0;
}

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

#define int long long
#define rep(i, l, r) for (int i = (int)(l); i < (int)(r); i++)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)x.size())
template <class T> bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

using vi = vector<int>;
using vvi = vector<vi>;
using P = pair<int, int>;

/*
 */

signed main(){
  int n, k, p[3];
  string s;
  cin >> n >> k;
  rep(i, 0, 3) cin >> p[i];
  cin >> s;

  vi win(n);
  rep(i, 0, n){
    if(s[i] == 'r') win[i] = 2;
    if(s[i] == 's') win[i] = 0;
    if(s[i] == 'p') win[i] = 1;
  }

  vi memo(n, -1);
  int ans = 0;
  rep(i, 0, n){
    if(i >= k and win[i] == memo[i-k]){
    }else{
      ans += p[win[i]];
      memo[i] = win[i];
    }
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 2048
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <complex>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <bitset>
#include <ctime>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cassert>
#include <cstddef>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <sstream>
#include <fstream>

using namespace std;
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define RREP(i, a) for(int (i) = (a) - 1; (i) >= 0; (i)--)
#define FORR(i, a, b) for(int (i) = (a) - 1; (i) >= (b); (i)--)
#define DEBUG(C) cerr << #C << " = " << C << endl;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<LL>;
using VVL = vector<VL>;
using VD = vector<double>;
using VVD = vector<VD>;
using PII = pair<int, int>;
using PDD = pair<double, double>;
using PLL = pair<LL, LL>;
using VPII = vector<PII>;
template<typename T> using VT = vector<T>;
#define ALL(a) begin((a)), end((a))
#define RALL(a) rbegin((a)), rend((a))
#define SORT(a) sort(ALL((a)))
#define RSORT(a) sort(RALL((a)))
#define REVERSE(a) reverse(ALL((a)))
#define MP make_pair
#define FORE(a, b) for (auto &&a : (b))
#define FIND(s, e) ((s).find(e) != (s).end())
#define EB emplace_back
template<typename T> inline bool chmax(T &a, T b){if (a < b){a = b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if (a > b){a = b;return true;}return false;}

const int INF = 1e9;
const int MOD = INF + 7;
const LL LLINF = 1e18;

int calc(int i) {
    int ret = 0;
    while (i) {
        ret += i % 10;
        i /= 10;
    }
    return ret;
}

int main(void) {
    int n;
    cin >> n;
    int ans = INF;
    FOR(i, 1, n) {
        chmin(ans, calc(i) + calc(n - i));
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<cassert>
#include<math.h>
#include<complex>
#include<algorithm>
#include<utility>
#include<queue>
#include<string.h>
#include<string>
#include<set>
#include<map>
#include<unordered_map>
#include<functional>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll INF=2e18;
const ll MOD=1e9+7;

ll R;
double PI=3.14159265;
int main(){
    cin>>R;
    cout<<2*R*PI<<endl;


    return 0;
}

Measured memory_bytes: 3784