akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:1024000000,1024000000")
#define mem(a,b) memset((a),(b),sizeof(a))
#define MP make_pair
#define pb push_back
#define fi first
#define se second
#define sz(x) x.size()
#define all(x) x.begin(),x.end()
using namespace std;
#define _GLIBCXX_PERMIT_BACKWARD_HASH
#include <ext/hash_map>
using namespace __gnu_cxx;
struct str_hash{size_t operator()(const string& str)const{return __stl_hash_string(str.c_str());}};
typedef long long ll;
typedef unsigned long long ull;
#define PII pair<int,int>
#define PLL pair<ll,ll>
#define PDD pair<double,double>
const int INF=0x3f3f3f3f;
const ll LLINF=0x3f3f3f3f3f3f3f3f;
const double PI=acos(-1.0);
const double eps=1e-6;
const int MAX=5e5+10;
const ll mod=1e9+7;
int main()
{
	ll x,y,ans;
	while(~scanf("%lld%lld",&x,&y))
	{
		ans=0;
		y/=x;
		while(y)
		{
			ans++;
			y>>=1;
		}
		printf("%lld\n",ans);
	}
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <utility>
#include <numeric>

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9) + 7;

int main(void) {
	int n, k;
	cin >> n >> k;
	
	int ans = 0;
	for(int i = 0; i < n; ++i) {
		int h;
		cin >> h;
		
		if( k <= h ) ans++;
	}
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 256
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
#[allow(unused_imports)]
use std::cmp::{min, max};
use std::io::{Write, BufWriter};
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    ($($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)*}
    };
}

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)*}
    };
}

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, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

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

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

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

fn solve() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($($format:tt)*) => (write!(out,$($format)*).unwrap());
    }
    input!{
        n:usize, a:i64, b: i64,
        x: [i64; n],
    }
    let mut ans : i64 = 0;
    for i in 1..n{
        let dist = (x[i] - x[i - 1]);
        ans += min(b, dist * a);
    }
    println!("{}", ans);
}
fn main() {
    // In order to avoid potential stack overflow, spawn a new thread.
    let stack_size = 104_857_600; // 100 MB
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}

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

using namespace std;


const int N = 1e5 + 10;


int id[N], n;


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

Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define m 1000005
bool mark[m+1];
void prime(){
    memset(mark,1,sizeof(mark));
    for(int i=2;i*i<=m;i++){
        if(mark[i]==1){
            for(int j=i*i;j<=m;j+=i){
                mark[j]=0;
            }
        }
    }
}
int main() {
    prime();
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
  	ll n;
  	while(cin>>n){
        while(!mark[n])n++;
        cout<<n<<endl;
  	}

    return 0;
}


Measured memory_bytes: 1280
#include <stdio.h>
#include <string.h>
#define LEN 100005

typedef struct pp{
    char name[100];
    int t;
}P;

P Q[LEN];
int head,tail,n;

void enqueue(P u){
    Q[tail]=u;
    tail=(tail+1)%LEN;
}

P dequeue(){
    P r=Q[head];
    head=(head+1)%LEN;
    return r;
}

int min(int a,int b){
    return (a<b?a:b);
}

int main(void){
    int q,i;
    int elap=0, c;
    P u;
    
    scanf("%d %d",&n,&q);
    
    for(i=1;i<=n;i++){
        scanf("%s %d",Q[i].name,&Q[i].t);
        //printf("%s %d\n",Q[i].name,Q[i].t);
    }
    
    head=1;
    tail=n+1;
    
    while(head!=tail){
        u=dequeue();
        c=min(q,u.t);
        elap+=c;
        u.t-=c;
        if(u.t>0){
            enqueue(u);
        }else{
            printf("%s %d\n",u.name,elap);
        }
    }
}



Measured memory_bytes: 11880
c = gets.chomp.to_s

if c.size == 2 && c == 'hi'
  puts 'Yes'
elsif c.size == 4 && c == 'hihi'
  puts 'Yes'
elsif c.size == 6 && c == 'hihihi'
  puts 'Yes'
elsif c.size == 8 && c == 'hihihihi'
  puts 'Yes'
elsif c.size == 10 && c == 'hihihihihi'
  puts 'Yes'
else
  puts 'No'
end


Measured memory_bytes: 1788
#include <iostream>
using namespace std;
int main(){
    int a[5];
    for(int i=0;i<5;i++){
        cin>>a[i];
    }
    int x=a[0];
    int y=a[3];
    if(a[1]<x)x=a[1];
    if(a[2]<x)x=a[2];
    if(a[4]<y)y=a[4];
    cout<<x+y-50<<endl;
}

Measured memory_bytes: 3092
#include <bits/stdc++.h>
#define endl '\n'
#define ll long long
using namespace std;


void lok(){
}

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int a,b,c,d,m;
	cin>>a>>b>>c>>d>>m;
	int mino;
	if(a>c){
		mino=(24-a)*60+c*60-b+d;
	}
	else if(a==c){
		if(b==d){
			cout<<'0'<<endl;
			return 0;
		}
		else if (b<d){
			mino=d-b;
		}
		else if(d>b){
			mino=24*60-d+b;
		}
	}
	else{
		mino=(c-a)*60+d-b;
	}
	cout<<mino-m<<endl;
	return 0;
}


Measured memory_bytes: 3652
/*
Program Wall
Written by "Vaibhav" aka 'ZodiacBestro'
In 2017
*/

#include <bits/stdc++.h>

using namespace std;

#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define sz(x) ((int)x.size())
#define eps 1e-9
#define fast_cin ios_base::sync_with_stdio(false)
#define rep(i,n) for (int (i) = 0; (i) < n; ++(i))

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

const ll MOD = 1e9+7;
const ll MAXN = 1e6+5;

ll dp[MAXN],dp1[MAXN];
int c[10][10];

int main()
{
	fast_cin; cin.tie(NULL); cin.tie(NULL);
	int h,w; cin >> h >> w;
	rep(i,10){
		rep(j,10){
			cin >> c[i][j];
		}
	}
	rep(k,10) rep(i,10) rep(j,10) {
		if (c[i][j] > c[i][k] + c[k][j])
		{
			c[i][j] = c[i][k] + c[k][j];
		}
	}
	/*cout << "Now our all pairs shortest path matrix is \n";
	rep(i,10){
		rep(j,10){
			cout << c[i][j] << " ";
		}
		cout << endl;
	}*/
	int a, ans = 0;
	rep(i,h){
		rep(j,w){
			cin >> a;
			if (a >= 0)
			{
				ans += c[a][1];
			}
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
typedef long long ll;
typedef pair<int, int> P;
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
struct Edge {
  ll to;
  ll cost;
};
int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  ll sum = 0;
  unordered_map<int, ll> mp{};
  REP(i, N) {
    cin >> A[i];
    sum += A[i];
    mp[A[i]]++;
  }
  int Q;
  cin >> Q;
  REP(i, Q) {
    ll B, C;
    cin >> B >> C;
    ll bnum = mp[B] * B;
    ll cnum = mp[B] * C;
    mp[C] += mp[B];
    mp[B] = 0;
    sum += cnum - bnum;
    cout << sum << endl;
  }

}

Measured memory_bytes: 7324
#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N;
string S;

int dp[2][2020202];

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>S;
	reverse(ALL(S));
	S+=string(1000005,'0');
	
	dp[0][0]=0;
	dp[1][0]=1<<30;
	
	FOR(i,1000005) {
		
		dp[0][i+1]=min(dp[0][i]+S[i]-'0',dp[1][i]+(S[i]-'0'+1));
		dp[1][i+1]=min(dp[0][i]+10-(S[i]-'0'),dp[1][i]+10-(S[i]-'0'+1));
	}
	
	cout<<dp[0][1000004]<<endl;
	
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 13684
#include<bits/stdc++.h>
using namespace std;
int main(){
int N,L,sum=0;
cin>>N>>L;
int a[N],s[N];
for(int i=0;i<N;i++){
    a[i]=L+(i+1)-1;
    sum+=a[i];
}
for(int i=0;i<N;i++){
    s[i]=sum-(L+(i+1)-1);
}
vector<pair<int,int>> r(N);
for(int i=0;i<N;i++){
    r[i].first=abs(s[i]-sum);
    r[i].second=s[i];
}
sort(r.begin(),r.end());
cout<<r[0].second;
return 0;
}

Measured memory_bytes: 256
A,B,C,D = map(int, input().split())

if B<=C:
  ans = 0
elif D<=A:
  ans = 0
  
elif A<=C and D<=B: 
  ans = D-C
elif A>=C and D>=B:
  ans = B-A

elif A<=C and B>=C and B<=D:
  ans = B-C
else:
  ans = D-A
print(ans)

Measured memory_bytes: 38384
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;

const ll INF64 = 1LL << 60;
const int INF32 = 1 << 29;
const int MOD =   1000000007;


struct UnionFind {
    vector<int> par;

    UnionFind(int n) : par(n, -1) { }
    void init(int n) { par.assign(n, -1); }

    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }

    bool issame(int x, int y) {
        return root(x) == root(y);
    }

    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y); // merge technique
        par[x] += par[y];
        par[y] = x;
        return true;
    }

    int size(int x) {
        return -par[root(x)];
    }
};


int main()
{
#ifdef MYLOCAL
    ifstream in("input.txt");
    cin.rdbuf(in.rdbuf());
#endif
    int N, K; cin >> N >> K;
    int maxnum = (N - 1)*(N - 2) / 2;
    if (maxnum < K){
        cout << -1 << endl;
        return 0;
    }

    // 1-indexed star-graph
    vector<P> res;
    for (int i = 1; i <= N-1; ++i) {
        res.push_back({i, N});
    }

    int rem = maxnum - K;
    int ci = 1, cj = 2;
    for (int _ = 0; _ < rem; ++_) {
        res.push_back({ci, cj});
        ++cj;
        if (cj == N) {
            ++ci;
            cj = ci + 1;
        }
    }

    cout << res.size() << endl;
    for (auto p : res){
        cout << p.first << " " << p.second << endl;
    }
    return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <set>
#include <map>
#include <iomanip>
#include <string>
#include <bitset>
#include <cassert>
using namespace std;

int main()
{
	long long n, m, k;
	cin >> n >>  m >> k;
	vector<vector<long long>> vec(n + 2, vector<long long>(m + 2));
	for (long long i = 0; i < k; i++) {
		long long a, b, v;
		cin >> a >> b >> v;
		vec[a][b] = v;
	}
	vector<vector<vector<long long>>> dp(n + 2, vector<vector<long long>>(m + 2,vector<long long>(4)));
	
	

	dp[1][1][1] = vec[1][1];
	for (long long i = 1; i <= n; i++) {
		for (long long j = 1; j <= m; j++) {
			dp[i][j][0] = max({dp[i-1][j][0],dp[i][j-1][0],dp[i][j][0],dp[i-1][j][1],dp[i - 1][j][2],dp[i - 1][j][3] });
			dp[i][j][1] = max({dp[i][j][1],dp[i-1][j][0]+vec[i][j],dp[i - 1][j][1] + vec[i][j],dp[i - 1][j][2] + vec[i][j],dp[i - 1][j][3] + vec[i][j],
				dp[i][j-1][1],dp[i][j-1][0]+vec[i][j]});
			dp[i][j][2] = max({dp[i][j][2],dp[i][j-1][1]+vec[i][j],dp[i][j-1][2]});
			dp[i][j][3] = max({ dp[i][j][3],dp[i][j - 1][2] + vec[i][j],dp[i][j - 1][3] });
		}
		
	
	}
	cout << max({ dp[n][m][0],dp[n][m][1],dp[n][m][2],dp[n][m][3] });
	
	
}


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

// @@ !! LIM()

int main(int argc, char *argv[]) {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << setprecision(20);

  ll N, M; cin >> N >> M;
  vector<bool> used(M);
  using Tuple = tuple<ll, ll, ll>;
  vector<vector<Tuple>> nbr(N);
  for (ll i = 0; i < M; i++) {
    ll a, b, c; cin >> a >> b >> c; a--; b--;
    nbr.at(a).emplace_back(c, b, i);
    nbr.at(b).emplace_back(c, a, i);
  }
  ll big = 1000 * 1000;
  for (ll i = 0; i < N; i++) {
    priority_queue<Tuple, vector<Tuple>, greater<Tuple>> pq;
    vector<ll> dist(N, big);
    pq.emplace(0, i, -1);
    dist.at(i) = 0;
    while(!pq.empty()) {
      ll j, c, k; tie(c, j, k) = pq.top(); pq.pop();
      if (dist.at(j) < c) continue;
      if (k >= 0) used.at(k) = true;
      for (Tuple t : nbr.at(j)) {
	ll j1, c1, k1; tie(c1, j1, k1) = t;
	if (dist.at(j1) < dist.at(j) + c1) continue;
	dist.at(j1) = dist.at(j) + c1;
	pq.emplace(dist.at(j) + c1, j1, k1);
      }
    }
  }
  ll cnt = 0;
  for (ll i = 0; i < M; i++) if (!used.at(i)) cnt++;
  cout << cnt << endl;

  return 0;
}



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

ll mod = 1000000007;

struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};

struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
};


int main() {
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  sort(a.begin(), a.end());

  combination c(n+5);

  mint ans = 0;
  rep(ri,2) {
    rep(i,n) {
      mint now = c(i,k-1);
      if (ri == 1) now = -now;
      ans += now*a[i];
    }
    reverse(a.begin(), a.end());
  }

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


Measured memory_bytes: 5104
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

int n;
vector<pair<ll,ll>> a;

int main(void)
{
	cin>>n;
	int max=0;
	unordered_set<ll> flag;
	for (int i = 0; i < n; i++) {
		int x;
		cin>>x;
		a.push_back({x,i+1});
		if(max<x){
			max=x;
			flag.insert(i+1);
		}
	}		
	a.push_back({0,0});
	flag.insert(0);
	unordered_map<ll,ll> ret;
	sort(a.begin(),a.end());
	int len=a.size();
	for(ll i=len-1,last=a.back().first,lastflag=-1,tmp=0;i>=0;i--){
		tmp+=(last-a[i].first)*(len-1-i);
		if(flag.count(a[i].second)){
			ret[lastflag]=tmp;
			tmp=0;
			lastflag=a[i].second;
		}
		last=a[i].first;
	}
	for(int i=1;i<=n;i++){
		cout<<ret[i]<<endl;
	}
	return 0;
}


Measured memory_bytes: 10772
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
#define fst first
#define snd second

/* clang-format off */
template <class T, size_t D> struct _vec { using type = vector<typename _vec<T, D - 1>::type>; };
template <class T> struct _vec<T, 0> { using type = T; };
template <class T, size_t D> using vec = typename _vec<T, D>::type;
template <class T> vector<T> make_v(size_t size, const T& init) { return vector<T>(size, init); }
template <class... Ts> auto make_v(size_t size, Ts... rest) { return vector<decltype(make_v(rest...))>(size, make_v(rest...)); }
template <class T> inline void chmin(T &a, const T& b) { if (b < a) a = b; }
template <class T> inline void chmax(T &a, const T& b) { if (b > a) a = b; }
/* clang-format on */

int main() {
#ifdef DEBUG
  ifstream cin("in.txt");
#endif
  int N, M;
  while (cin >> N >> M) {
    vector<int> A(N);
    for (int& x : A) cin >> x;
    vector<int> plus, minus;
    ll res = 0;
    for (int i = 0; i < N; i++) {
      res += abs(A[i] - i);
      if (A[i] >= i) {
        plus.push_back(A[i]);
        minus.push_back(i);
      } else {
        plus.push_back(i);
        minus.push_back(A[i]);
      }
    }
    sort(plus.begin(), plus.end());
    sort(minus.rbegin(), minus.rend());
    for (int i = 0; i < M; i++) {
      if (minus[i] <= plus[i]) break;
      res += 2 * (minus[i] - plus[i]);
    }
    cout << res << endl;
  }
  return 0;
}



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

int main() {
	int n;cin>>n;
for(int i=0;i<100;i++){
	for(int j=0;j<100;j++){
		if(4*i+7*j==n){
			cout<<"Yes"<<endl;
			return 0;
		}
	}
}
cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
inline int read(){
	char ch=getchar();int o=0,f=1;
	while(ch<'0'||ch>'9'){
		if(ch=='-') f=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9') o=(o<<3)+(o<<1)+(ch^48),ch=getchar();
	return f*o;
}
int n,m,a[20000],b,c;
inline bool cmp(int a,int b){
	return a<b;
}
int main(){
	n=read();
	for(register int i=1;i<=n;i++) a[i]=read();
	sort(a+1,a+n+1,cmp);
	for(register int i=1;i<n;i++){
		for(register int j=i+1;j<=n;j++){
			int xx=a[i]+a[j];
			int tmp=lower_bound(a+1,a+n+1,xx)-a;
			tmp--;
			m+=max(0,tmp-j);
		}
	}
	cout<<m<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <cstdio>
#include <vector>
#include <set>
#include <cassert>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <sstream>
#include <functional>
#include <iomanip>
//#include <windows.h>  //Should be deleted when using AtCoder&POJ
using namespace std;

#define ll long long
#define pii pair<int,int>
/**==Info==
*Program:4
*Problem:Symmetric Grid
*Date:2018-4-21
*Algorithm:kawatea's Solution
*Stats:Unknown*/

bool debug=false;

int n,m;
string s[15];
string ss[15];
int a[15],b[15];

void dfs2(int pos,bool mid){
	if(pos==m){
		puts("YES");
		exit(0);
	}
	if(b[pos]!=-1){
		dfs2(pos+1,mid);
		return;
	}
	for(int i=pos+1;i<m;i++){
		if(b[i]!=-1){
			continue;
		}
		int j;
		for(j=0;j<n;j++){
			if(s[j][pos]!=s[a[j]][i]) break;
		}
		
		
		if(j==n){
			b[pos]=i;
			b[i]=pos;
			dfs2(pos+1,mid);
			b[pos]=-1;
			b[i]=-1;
		}
	}
	
	if(!mid){
		int j;
		for(j=0;j<n;j++){
			if(s[j][pos]!=s[a[j]][pos]) break;
		}
		
		if(j==n){
			b[pos]=pos;
			dfs2(pos+1,true);
			b[pos]=-1;
		}
	}
}

void dfs(int pos,bool mid){
	if(pos==n){
		dfs2(0,!m%2);
		return;
	}
	if(a[pos]!=-1){
		dfs(pos+1,mid);
		return;
	}
	for(int i=pos+1;i<n;i++){
		if(a[i]!=-1){
			continue;
		}
		if(ss[i]!=ss[pos]){
			continue;
		}
		
		a[i]=pos;
		a[pos]=i;
		
		dfs(pos+1,mid);
		
		a[pos]=-1;
		a[i]=-1;
	}
	
	if(!mid){
		a[pos]=pos;
		dfs(pos+1,true);
		a[pos]=-1;
	}
}

int main(int argc,char* argv[]){
	scanf("%d%d",&n,&m);
	for(int i=0;i<n;i++){
		cin>>s[i];
		ss[i]=s[i];
		sort(ss[i].begin(),ss[i].end());
	}
	
	memset(a,-1,sizeof(a));
	memset(b,-1,sizeof(b));
	
	dfs(0,!n%2);
	
	while(clock()<=1900){
	}
	puts("NO");
	
	//Atcoder is just a fuck
	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
int main(int argc, char const* argv[]) {
    int n, t;
    cin >> n >> t;
    int minC = 10000;
    for (int i = 0; i < n; ++i) {
        int ci, ti;
        cin >> ci >> ti;
        if (ti <= t && ci < minC) {
            minC = ci;
        }
    }
    if (minC == 10000) {
        cout << "TLE" << endl;
    } else {
        cout << minC << endl;
    }
    return 0;
}


Measured memory_bytes: 256
import std.stdio;
import std.string;
import core.stdc.stdlib;

enum vocab = ["dream", "dreamer", "erase", "eraser"];

void solve(string s) {
    if (s == "") {
        writeln("YES");
        exit(0);
    }

    foreach (v; vocab) {
        if (s.startsWith(v)) {
            solve(s[v.length .. $]);
        }
    }
}

void main() {
    string s;
    readf("%s\n", &s);
    solve(s);
    writeln("NO");
}

Measured memory_bytes: 2812
#include <stdio.h>

int main() {

  int i, j, r, c;
  int mat[101][101];

  scanf("%d %d", &r, &c);
  for (i = 0; i < r; i++){
    for (j = 0; j < c; j++){
      scanf("%d", &mat[i][j]);
    }
  }

  for (i = 0; i <= r; i++){
    mat[i][c] = 0;
  }
  for (j = 0; j <= c; j++){
    mat[r][j] = 0;
  }

  for (i = 0; i < r; i++){
    for (j = 0; j < c; j++){
      mat[i][c] += mat[i][j];
      mat[r][j] += mat[i][j];
      mat[r][c] += mat[i][j];
    }
  }
    for (i = 0; i <= r; i++){
    for (j = 0; j <= c; j++){
      printf("%d", mat[i][j]);
      if (j < c) printf(" ");
    }
    printf("\n");
  }

  return 0;

}

Measured memory_bytes: 640
#include <stdio.h>

void setValue( int value[], int size );
void swap( int* a, int* b );
void showValue( int value[], int size );

int main( void )
{
	int value[30];
	int list[2];
	int trash;
	int listSize;
	int valueSize;
	int i;
	
	scanf( "%d", &valueSize );
	setValue( value, valueSize );
	
	scanf( "%d", &listSize );
	
	for( i = 0; i < listSize; i++ )
	{
		scanf( "%d", &list[0] );
		scanf( "%c", &trash );
		scanf( "%d", &list[1] );
		swap( &value[ list[0] - 1 ], &value[ list[1] - 1 ] );
	}
	
	showValue( value, valueSize );
	
	return (0);
}

void setValue( int value[], int size )
{
	int i;
	
	for( i = 0; i < size; i++ )
	{
		value[i] = i + 1;
	}
}

void swap( int* a, int* b )
{
	int buf;
	
	buf = *a;
	*a = *b;
	*b = buf;
}

void showValue( int value[], int size )
{
	int i;
	for( i = 0; i < size; i++ )
	{
		printf( "%d\n", value[i] );
	}
}

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

struct Node{
	int key;
	Node *parent,*left,*right;
};

void insert(int key);
Node *find(Node *x,int key);
void inorder(Node *u);
void preorder(Node *u);
void deleteNode(int key);
Node *getSuccessor(Node *z);
Node *getMinimum(Node *z);

Node *root,*NIL;

int main(){
	int n; cin>>n;
	string command; int key;
	for(int i=0;i<n;i++){
		cin>>command;
		if(command=="insert"){
			cin>>key;
			insert(key);
		}else if(command=="find"){
			cin>>key;
			Node *z = find(root,key);
			if(z==NIL){
				cout<<"no"<<endl;
			}else{
				cout<<"yes"<<endl;
			}
		}else if(command=="print"){
			inorder(root);
			cout<<endl;
			preorder(root);
			cout<<endl;
		}else if(command=="delete"){
			cin>>key;
			deleteNode(key);
		}
	}
	
	cin.get(); cin.get();
}

void insert(int key){
	Node *x,*y,*z;
	y = NIL; x = root;
	z = (Node *)malloc(sizeof(Node));
	z->key = key; z->left = z->right = NIL;

	while(x!=NIL){
		y = x;
		if(z->key<x->key) x = x->left;
		else x = x->right;
	}

	z->parent = y;

	if(y==NIL)
		root = z;
	else{
		if(y->key>z->key)
			y->left = z;
		else
			y->right = z;
	}
}

Node* find(Node *x,int key){
	while(x!=NIL&&x->key!=key){
		if(x->key>key) x = x->left;
		else x = x->right;
	}
	return x;
}

void inorder(Node *u){
	if(u==NIL) return ;
	
	inorder(u->left);
	cout<<" "<<u->key;
	inorder(u->right);
}

void preorder(Node *u){
	if(u==NIL) return ;

	cout<<" "<<u->key;
	preorder(u->left);
	preorder(u->right);
}

void deleteNode(int key){
	Node *x,*y,*z;
	z = find(root,key);
	if(z->left==NIL || z->right==NIL){
		y = z;
	}else{
		y = getSuccessor(z);
	}

	if(y->left!=NIL){
		x = y->left;
	}else{
		x = y->right;
	}

	if(x!=NIL) x->parent = y->parent;

	if(y->parent==NIL){
		root = x;
	}else{
		if(y->parent->left==y){
			y->parent->left = x;
		}else{
			y->parent->right = x;
		}
	}

	if(z!=y){
		z->key = y->key;
	}
	free(y);
}

Node *getSuccessor(Node *z){
	if(z->right!=NIL) return getMinimum(z->right);

	Node *y = z->parent;
	while(y!=NIL && z==y->right){
		z = y;
		y = y->parent;
	}
	return y;
}

Node *getMinimum(Node *z){
	while(z->left!=NIL){
		z = z->left;
	}
	return z;
}

Measured memory_bytes: 21848
import sys
N,A,B,C,D=map(int,input().split())
A,B,C,D=A-1,B-1,C-1,D-1
S=input()
if C<D:
    for i in range(B,D-1):
        if S[i:i+2]=='##':
            print('No')
            sys.exit()
    for i in range(A,C-1):
        if S[i:i+2]=='##':
            print('No')
            sys.exit()
    print('Yes')
    sys.exit()
for i in range(B,D-1):
    if S[i:i+2]=='##':
        print('No')
        sys.exit()
for i in range(A,C-1):
    if S[i:i+2]=='##':
        print('No')
        sys.exit()
for i in range(B,D+1):
    if S[i-1:i+2]=='...':
        print('Yes')
        sys.exit()
print('No')

Measured memory_bytes: 40048
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
int main(){
  ll H,W;
  cin>>H>>W;
  vector<vector<char>> A(W+1, vector<char>(H+1,'x'));
  vector<vector<ll>> B(W, vector<ll>(H,1e6));
  for(int j=0; j<H; j++){
    for(int i=0; i<W; i++){
      char z;
      cin>>z;
      A[i][j]=z;
    }
  }
  //ue
  ll tmp=0;
  if(A[0][0]=='#')
    tmp++;
  B[0][0]=tmp;
  for(int i=1; i<W; i++){
    if(A[i][0]=='#' &&A[i-1][0]=='.')
      tmp++;
    B[i][0]=tmp;
  }
  //hidari
  tmp=B[0][0];
  for(int j=1; j<H; j++){
    if(A[0][j]=='#' &&A[0][j-1]=='.')
      tmp++;
    B[0][j]=tmp;
  }
  for(int j=1; j<H; j++){
    for(int i=1; i<W; i++){
      ll up,left;
      if(A[i][j]==A[i][j-1] || A[i][j]=='.')
        up=B[i][j-1];
      else if(A[i][j]!=A[i][j-1])
        up=B[i][j-1]+1;
      if(A[i][j]==A[i-1][j] || A[i][j]=='.')
        left=B[i-1][j];
      else if(A[i][j]!=A[i-1][j])
        left=B[i-1][j]+1;
      B[i][j]=min(up,left);
    }
  }
  cout<<B[W-1][H-1]<<endl;
}

Measured memory_bytes: 384
//package AtCoder.C114;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {

    static InputStream inputStream = System.in;
    static OutputStream outputStream = System.out;
    static InputReader in = new InputReader(inputStream);
    static PrintWriter out = new PrintWriter(outputStream);

    public static void main(String[] args) {
        int x = in.NI();
        if (x==3 || x==5 || x==7)
            out.println("YES");
        else
            out.println("NO");
        out.close();
    }


    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int NI() {
            return Integer.parseInt(next());
        }

        public long NL() {
            return Long.parseLong(next());
        }

    }


}


Measured memory_bytes: 21076
import java.util.*;

import static java.lang.Math.*;

class Main {
    final Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {
        new Main().run();
    }

    private void run() {
        int x = sc.nextInt();
        int y = sc.nextInt();

        for (int i = 0; i <= x; i++) {
            if (i * 2 + (x - i) * 4 == y) {
                System.out.println("Yes");
                return;
            }
        }
        System.out.println("No");
    }
}


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

using namespace std;

using ll = long long;
using ld = long double;

const double PI = 3.1415926535897932384626433832795;

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

int gcd(int x, int y) { return y ? gcd(y, x % y) : abs(x); }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : abs(x); }
int lcm(int x, int y) { return x / gcd(x, y) * y; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }

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

	int n;
	cin >> n;

	vector<pair<pair<string, int>, int>> vec(n);
	for (int i = 0; i < n; i++) {
		string s;
		int p;

		cin >> s >> p;
		vec[i] = make_pair(make_pair(s, -p), i + 1);
	}

	sort(begin(vec), end(vec));

	for (auto v : vec) {
		cout << v.second << endl;
	}
	return 0;
}


Measured memory_bytes: 256
import Data.List
import qualified Data.Set as Set
import qualified Data.ByteString.Char8 as BC
import Data.Maybe

type Set = Set.Set Int

toTuple [a, b] = (a, b)

readIntsLines :: IO [(Int, Int)]
readIntsLines = map (toTuple . map (fst . fromJust . BC.readInt) . BC.words) . BC.lines <$> BC.getContents

solve :: [(Int, Int)] -> Int -> Set -> Bool
solve [] _ _ = False
solve ((a, b):xs) n s
  | a == 1 = solve xs n $ Set.insert b s
  | b == n = Set.member a s || solve xs n s
  | otherwise = solve xs n s

main :: IO ()
main = do
  [n, m] <- map read . words <$> getLine
  ls <- sortOn fst <$> readIntsLines
  putStrLn $ if solve ls n Set.empty then "POSSIBLE" else "IMPOSSIBLE"

Measured memory_bytes: 82428
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int MAXN = 1e6+69;
const int mod = 1e9+7;
int m,n;
int t;
int x,y,z;
struct vl{
	int x,y;
	bool operator<(vl t)const {
		if(x==t.x)return y<t.y;
		return x<t.x;
	}
};
int a[MAXN];
signed main(){																																																																																						ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	string s;
	cin>>n>>s;
	for(int i=0;i<s.length();i++){
		cout<<char('A'+(s[i]-'A'+n)%26);
	}
	


	
}  

Measured memory_bytes: 3600
#include<stdio.h>
#include<stdlib.h>
#define NIL NULL
struct node{
  int key;
  struct node *right,*left,*parent;
};
typedef struct node * Node;
Node root;


void insert(int k){
  Node y=NIL;
  Node x=root;
  Node z;
  z=malloc(sizeof(struct node));
  z->key=k;
  z->left=NIL;
  z->right=NIL;

  while(x!=NIL){
    y=x;
    if(z->key < x->key){
      x=x->left;
    }
    else{
      x=x->right;
    }
  }
  z->parent=y;
  if(y==NIL){
    root=z;
  }
  else{
    if(z->key < y->key){
      y->left=z;
    }
    else{
      y->right=z;
    }
  }
}

void inorder(Node u){
  if(u==NIL)return;
  inorder(u->left);
  printf(" %d",u->key);
  inorder(u->right);
}
void preorder(Node u){
  if(u==NIL)return;
  printf(" %d",u->key);
  preorder(u->left);
  preorder(u->right);
}

int main(){
    int n, i, x;
    char com[20];
    scanf("%d", &n);
    for (i=0;i<n;i++)
      {
	scanf("%s", &com);
	if (com[0]=='i')
	  {
	    scanf("%d", &x);
	    insert(x);
	  }
	else if (com[0]=='p')
	  {
	    inorder(root);
	    printf("\n");
	    preorder(root);
	    printf("\n");
	  }
      }
    return 0;
  }

Measured memory_bytes: 24040
#include<cstdio> 
#include<algorithm>
#include<cstring>
#include<cmath>
#include<map>
using namespace std;
#define fo(i,j,k) for(i=j;i<=k;i++)
#define fd(i,j,k) for(i=j;i>=k;i--)
#define cmax(a,b) (a=(a>b)?a:b)
#define cmin(a,b) (a=(a<b)?a:b)
typedef long long ll;
typedef double db;
const int N=2e5+5;
int n,m,x,y,i,ans;
int tt,b[N],nxt[N],fst[N];
void cr(int x,int y)
{
	tt++;
	b[tt]=y;
	nxt[tt]=fst[x];
	fst[x]=tt;
}
int tr[N*4],tag[N*4];
void dw(int x,int s)
{
	if (s)
	{
		tag[x*2]+=tag[x];
		tag[x*2+1]+=tag[x];
	}
	tr[x]+=tag[x];
	tag[x]=0;
}
void change(int x,int l,int r,int i,int j,int v)
{
	if (l==i&&r==j)
	{
		tag[x]+=v;
		dw(x,l!=r);
	}else
	{
		int m=l+r>>1;
		dw(x*2,l!=m);
		dw(x*2+1,m+1!=r);
		if (i<=m) change(x*2,l,m,i,min(m,j),v);
		if (m<j)  change(x*2+1,m+1,r,max(i,m+1),j,v);
		tr[x]=max(tr[x*2],tr[x*2+1]);
	}
}
int get(int x,int l,int r,int i,int j)
{
	if (l==i&&r==j) return tr[x];
	int m=l+r>>1,ret=0;
	dw(x*2,l!=m);
	dw(x*2+1,m+1!=r);
	if (i<=m) ret=max(ret,get(x*2,l,m,i,min(m,j)));
	if (m<j)  ret=max(ret,get(x*2+1,m+1,r,max(i,m+1),j));
	return ret;
}
void make(int x,int l,int r)
{
	if (l==r) 
		tr[x]=-m+l;else
	{
		int m=l+r>>1;
		make(x*2,l,m);
		make(x*2+1,m+1,r);
		tr[x]=max(tr[x*2],tr[x*2+1]);
	}
}
int main()
{
	scanf("%d %d",&n,&m);
	fo(i,1,n)
	{
		scanf("%d %d",&x,&y);
		cr(x,y);
	}
	ans=n-m;
	m++;
	make(1,0,m);// special shit
	fo(i,0,m-1)
	{
		for(int p=fst[i];p;p=nxt[p])
			change(1,0,m,i+1,b[p],1);
		ans=max(ans,get(1,0,m,i+2,m)-i);
	}
	cmax(ans,0);
	printf("%d\n",ans);
}

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

using namespace std;

#define ff first
#define ss second

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pi;
typedef pair<long long, long long> pl;

const int MOD = 1e9 + 7;
const ll INF = 1e18;
const double EPS = 1e-6;
const int MAX_N = 1e5 + 5;

namespace modOp {
    int add(int a, int b, int mod = MOD) { return (a + b) % mod; }
    int sub(int a, int b, int mod = MOD) { return (a - b + mod) % mod; }
    int mul(int a, int b, int mod = MOD) { return (ll)a * b % mod; }
}
using namespace modOp;

int N;
vector<int> adjList[MAX_N];

//{current node is black, current node is white}
pl dfs(int u, int p) {
	int allWhite = 1;
	int black = 0;
	for (int v: adjList[u]) {
		if (v != p) {
			pl res = dfs(v, u);
			black = add(mul(allWhite, res.ff), mul(black, res.ff +  res.ss));
			allWhite = mul(allWhite, res.ss);
		}
	}
	return {allWhite, add(allWhite, black)};
}

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);
	
	cin >> N;
	for (int i = 0; i < N - 1; ++i) {
		int u, v; cin >> u >> v;
		adjList[u].push_back(v);
		adjList[v].push_back(u);
	}
	
	pl ans = dfs(1, -1);
	cout << add(ans.ff, ans.ss) << '\n';

	return 0;
}

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

int insert_sort(int aiNum[], int iLen)
{
    for (int i = 1; i < iLen; i++)
    {
        int iVal = aiNum[i];
        int j = i - 1;
        while ((j >= 0) && (aiNum[j] > iVal))
        {
            aiNum[j + 1] = aiNum[j];
            j--;
        }
        aiNum[j + 1] = iVal;
    }
    
    for (int i = 0; i < iLen; i++)
    {
        if (i > 0)
        {
            cout << " ";
        }
        
        cout << aiNum[i];
    }
    
    cout << endl;
    
    return 0;
}

int main()
{
    int aiNum[3];
    
    for (int i = 0; i < 3; i++)
    {
        cin >> aiNum[i];
    }
    
    insert_sort(aiNum, 3);
    
    return 0;
}



Measured memory_bytes: 3092
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define all(a) a.begin(),a.end()
#define P pair<int,int>
#define F first
#define S second
#define mod 1000000007
#define INF 9000000000000000000
signed main(void){
    int n,k;cin>>n>>k;
    string s;cin>>s;
    int ans=0;
    rep(i,n-1){
        if(s[i]=='R'&&s[i+1]=='R')ans++;
    }
    rep(i,n-1){
        if(s[n-i-1]=='L'&&s[n-i-2]=='L')ans++;
    }
    cout<<min(n-1,ans+2*k)<<endl;
}

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

#define mod 1e9+7
#define ll long long int
#define epsilon 1e-7

struct hoge
{
    char ss[51];
};
int compare_int(const void *a, const void *b){
	struct hoge *A = (struct hoge *)a;
	struct hoge *B = (struct hoge *)b;
	int sc = strcmp(A->ss,B->ss);
	return sc;
}

int safe(char s, char t){
    if(s!='?' && s!=t)return 0;
    return 1;
}

int main(void){
    char s[51], t[51];
    scanf("%s %s", &s, &t);
    int ls = 0;
    int lt = 0;
    while(1){
        ls++;
        if(s[ls]=='\0')break;
    }
    while(1){
        lt++;
        if(t[lt]=='\0')break;
    }
    int mem[50];
    mem[0] = -1;
    int j = 0;
    for(int i = 0;i <= ls-lt;i++){
        if(safe(s[i],t[0])){
            int k = 1;
            while(k < lt){
                if(safe(s[i + k], t[k]))k++;
                else break;
            }
            if(k == lt){
                mem[j] = i;
                j++;
            }
        }
    }
    if(mem[0] == -1)printf("UNRESTORABLE");
    else{
        struct hoge pr[j];
        for(int i = 0;i < j;i++){
            for(int k = 0;k < ls;k++){
                if(k == mem[i]){
                    for(int h = 0;h < lt;h++){
                        pr[i].ss[k+h] = t[h];
                    }
                    k += lt - 1;
                }else if(s[k] == '?'){
                    pr[i].ss[k] = 'a';
                }else{
                    pr[i].ss[k] = s[k];
                }
            }
        }
        qsort(pr, j, sizeof(struct hoge), compare_int);
        for(int i = 0;i < ls;i++){
            printf("%c", pr[0].ss[i]);
        }
        //printf("\n");
    }
    return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <math.h>
#include <queue>

using namespace std;
typedef long long ll;
static const double EPS = 1e-9;
static const double PI = acos(-1.0);

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define FOREQ(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define DEC(i, s) for (int i = (s); i >= 0; i--)

#define SIZE(v) (int)((v).size())
#define MEMSET(v, h) memset((v), h, sizeof(v))
#define FIND(m, w) ((m).find(w) != (m).end())

struct Node {
  int x;
  int y;
  int dir;
  int cost;
  Node(int x, int y, int d, int c) : x(x), y(y), dir(d), cost(c) {;}
  bool operator<(const Node &rhs) const { return cost > rhs.cost; }
};

int w, h;
int field[40][40];
int dirc[4];
bool visit[4][40][40];
const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };

int main() {
  while (scanf("%d %d", &w, &h), w|h) {
    MEMSET(visit, 0);
    REP(y, h) REP(x, w) {
      scanf("%d", &field[y][x]);
    }
    REP(i, 4) {
      scanf("%d", &dirc[i]); 
    }
    priority_queue<Node> que;
    que.push(Node(0, 0, 0, 0));
    while (!que.empty()) {
      Node node = que.top();
      que.pop();
      if (visit[node.dir][node.y][node.x]) { continue; }
      visit[node.dir][node.y][node.x] = true;
      if (node.x == w - 1 && node.y == h - 1) {
        printf("%d\n", node.cost);
        break;
      }
      FOR(i, 0, 4) {
        int nd = (node.dir + i) % 4;
        int nc = node.cost;
        if (field[node.y][node.x] != i) {
          nc += dirc[i];
        }
        int nx = node.x + dx[nd];
        int ny = node.y + dy[nd];
        if (nx < 0 || nx >= w || ny < 0 || ny >= h || visit[nd][ny][nx]) { continue; }
        que.push(Node(nx, ny, nd, nc));
      }
    }
  }
}

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

using namespace std;

int main()
{
	int n,x;
	cin >> n >> x;
	int m[1000];
	int all = 0;
	int min = 100000;
	for (int i = 0; i < n; i++)
	{
		cin >> m[i];
		all += m[i];
		if(min > m[i])
		{
			min = m[i];
		}
	}

	all = x - all;
	for(all; min <= all; all -= min)
	{
		n++;
	}
	printf("%d\n", n);
	return 0;
}

Measured memory_bytes: 256
/*
このコード、と～おれ!
Be accepted!
∧＿∧　
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
 　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
		  　　　　　　　　　　(¸.·´ (¸.·'* ☆
					*/

#include <stdio.h>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstring>
#include <vector>
#include <numeric>
#include <iostream>
#include <random>
#include <map>
#include <unordered_map>
#include <queue>
#include <regex>

#pragma GCC optimize("Ofast")
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define rep1(i, n) for(int i = 1; i <= (n); ++i)
#define rep2(i, n) for(int i = 2; i < (n); ++i)
#define repr(i, n) for(int i = n; i >= 0; --i)
#define reprm(i, n) for(int i = n - 1; i >= 0; --i)
#define printynl(a) printf(a ? "yes\n" : "no\n")
#define printyn(a) printf(a ? "Yes\n" : "No\n")
#define printYN(a) printf(a ? "YES\n" : "NO\n")
#define printin(a) printf(a ? "possible\n" : "inposible\n")
#define printdb(a) printf("%.50lf\n", a)//少数出力
#define printdbd(a) printf("%.16lf\n", a)//少数出力(桁少なめ)
#define prints(s) printf("%s\n", s.c_str())//string出力
#define all(x) (x).begin(), (x).end()
#define allsum(a, b, c) ((a + b) * c / 2)//等差数列の和、初項,末項,項数
#define pb push_back
#define priq priority_queue
#define rpriq priq<int, vector<int>, greater<int>>
#define deg_to_rad(deg) (((deg)/360.0)*2.0*PI)
#define rad_to_deg(rad) (((rad)/2.0/PI)*360.0)
#define Please return
#define AC 0

using ll = long long;

constexpr int INF = 1073741823;
constexpr int MINF = -1073741823;
constexpr ll LINF = ll(4661686018427387903);
constexpr ll MOD = 1000000007;
const double PI = acos(-1);

using namespace std;

void scans(string& str) {
	char c;
	str = "";
	scanf("%c", &c);
	if (c == '\n')scanf("%c", &c);//最初の改行対策
	while (c != '\n' && c != -1) {
		str += c;
		scanf("%c", &c);
	}
}

void scanc(char& str) {
	char c;
	scanf("%c", &c);
	if (c == -1)return;
	while (c == '\n') {
		scanf("%c", &c);
	}
	str = c;
}

double acot(double x) {
	return PI / 2 - atan(x);
}

/*-----------------------------------------ここからコード-----------------------------------------*/


int main() {
	
	string s;
	scans(s);
	printyn(s.find("a") != string::npos && s.find("b") != string::npos && s.find("c") != string::npos);
	
	Please AC;
}


Measured memory_bytes: 760
//Sani buyuk Osman Pasa Plevneden cikmam diyor.
//FatihSultanMehmedHan
//Abdulhamid Han
//Bismillahirrahmanirrahim
//█▀█─█──█──█▀█─█─█
//█▄█─█──█──█▄█─█▄█
//█─█─█▄─█▄─█─█─█─█
 
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
 
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long int lo;
typedef pair< int,int > PII;
 
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define FOR for(int i=1;i<=n;i++)
#define mid ((start+end)/2)
#define ort ((bas+son)/2)
 
const lo MAX = -1000000000000000000;
const lo MIN = 1000000000000000000;
const lo inf = 1000000000;
const lo KOK = 100000;
const lo LOG = 30;
const lo li = 500005;
const lo mod = 1000000007;
 
lo n,m,b[li],a[li],k,flag,t,at;
lo cev;
string s;
vector<lo> v;

int main(void){
	scanf("%lld %lld",&n,&m);
	for(int i=m*2+1;i<=n;i+=m*2+1){
		cev++;
		at=i;
	}
	if(at!=n)cev++;
	printf("%lld\n",cev);
	return 0;
}


Measured memory_bytes: 256
s,h,c,d = [[0 for i in range(13)] for j in range(4)]
n = int(input())
for i in range(n):
    m,num = [i for i in input().split()]
    if(m == 'S'):
        s[int(num) - 1] += 1
    if(m == 'H'):
        h[int(num) - 1] += 1
    if(m == 'C'):
        c[int(num) - 1] += 1
    if(m == 'D'):
        d[int(num) - 1] += 1
for i in range(13):
    x1 = s[i]
    if(x1 == 0):
        print('S',i + 1)
for i in range(13):
    x2 = h[i]
    if(x2 == 0):
        print('H',i + 1)
for i in range(13):
    x3 = c[i]
    if(x3 == 0):
        print('C',i + 1)
for i in range(13):
    x4 = d[i]
    if(x4 == 0):
        print('D',i + 1)

Measured memory_bytes: 7772
#pragma region template 2.4
#include <bits/stdc++.h>
using namespace std;
template <typename T>
using pq_asc = priority_queue<T, vector<T>, greater<T>>;
typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll, ll> ii;
typedef vector<ii> vii;
typedef vector<string> vs;
#define REP(i, n) for (ll i = 0; i < (n); ++i)
#define REP1(i, n) for (ll i = 1; i <= (n); ++i)
#define FOR(i, a) for (auto &i : a)
#define CH(f, x, y) x = f(x, y)
#define IN(T, x) \
    T x;         \
    cin >> x;
#define AIN(T, a, n) \
    vector<T> a(n);  \
    FOR(i, a)        \
    cin >> i;
#define A2IN(T1, a, T2, b, n) \
    vector<T1> a(n);          \
    vector<T2> b(n);          \
    REP(i, n)                 \
    cin >> a[i] >> b[i];
#define OUT(x) cout << (x) << endl;
#define FOUT(x) cout << fixed << setprecision(15) << (x) << endl;
#define ALL(a) (a).begin(), (a).end()
#define SORT(a) sort(ALL(a))
#define RSORT(a) \
    SORT(a);     \
    reverse(ALL(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define DUMPA(a)          \
    cout << #a << " = {"; \
    JOUT(ALL(a), ", ", cout) << "}" << endl;

template <typename T>
ostream &JOUT(T s, T e, string sep = " ", ostream &os = cout)
{
    if (s != e)
    {
        os << *s;
        ++s;
    }
    while (s != e)
    {
        os << sep << *s;
        ++s;
    }
    return os;
}

ostream &YES(bool cond, string yes = "Yes", string no = "No", ostream &os = cout)
{
    if (cond)
    {
        os << yes << endl;
    }
    else
    {
        os << no << endl;
    }
    return os;
}

template <typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p)
{
    os << '(' << p.first << ", " << p.second << ')';
    return os;
}

template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v)
{
    os << '[';
    JOUT(ALL(v), ", ", os) << ']';
    return os;
}

const ll INF = 1e18;
const ll MOD = 1e9 + 7;
#pragma endregion template

int main()
{
    IN(ll, N);
    A2IN(ll, T, ll, A, N);
    ll t = 0;
    ll a = 0;
    REP(i, N)
    {
        ll r = 1;
        if (T[i] < t)
        {
            CH(max, r, (t + T[i] - 1) / T[i]);
        }
        if (A[i] < a)
        {
            CH(max, r, (a + A[i] - 1) / A[i]);
        }
        t = r * T[i];
        a = r * A[i];
    }
    OUT(t + a);
}

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

using namespace std;

#define mz 1000000007

char s[8005];
queue <int> q[2];
bool dp[2][2][16015];

int main()
{
    bool ff[2]={};
    int f=-1;
    int l,now=0;
    int sx,sy=0,nx,ny;
    scanf("%s",s);
    l=strlen(s);
    for(int i=0;i<=l;i++)
    {
        if(s[i]=='F')
            now++;
        else
        {
            if(f==-1)
            {
                sx=now;
                f=1;
                now=0;
            }
            else
            {
                q[f].push(now);
                f=!f;
                now=0;
            }
        }
    }
    scanf("%d%d",&nx,&ny);
    dp[0][0][sx+8005]=1;
    dp[1][0][sy+8005]=1;
    for(int i=0;i<2;i++)
    {
        while(!q[i].empty())
        {
            now=q[i].front();
            q[i].pop();
            memset(dp[i][!ff[i]],0,sizeof(dp[i][!ff[i]]));
            for(int j=0;j<16005;j++)
            {
                if(dp[i][ff[i]][j])
                {
                    dp[i][!ff[i]][j+now]=1;
                    dp[i][!ff[i]][j-now]=1;
                }
            }
            ff[i]=!ff[i];
        }
    }
    if(dp[0][ff[0]][nx+8005] && dp[1][ff[1]][ny+8005])
        printf("Yes\n");
    else
        printf("No\n");
    return 0;
}


Measured memory_bytes: 384
S = input()

flag = 1
c_count = 0
if S[0] == 'A':
  for i in range(1,len(S)):
    if 2 <= i <= len(S)-2:
      if S[i] == 'C':
        c_count += 1
    else:
      if S[i].islower() == False:
        flag = 0
else:
  flag = 0
if c_count == 1 and flag == 1:
  print('AC')
else:
  print('WA')

Measured memory_bytes: 9044
#include <stdio.h>

int main(void) {
	int H, W;
	while (scanf("%d%d", &H, &W) == 2 && (H|W) != 0) {
		int i, j;
		for (i = 0; i < H; i++) {
			for (j = 0; j < W; j++) putchar((i + j) % 2 == 0 ? '#' : '.');
			putchar('\n');
		}
		putchar('\n');
	}
	return 0;
}



Measured memory_bytes: 2116
#include<stdio.h>

int main(void)
{
	
	int a, b, c, x;
	
    scanf("%d %d %d",&a, &b, &c);
    
    if(a > b){
    	x = a;
    	a = b;
    	b = x;
    };
    
    
    if(b > c){
    	x = c;
    	c = b;
    	b = x;
    };
    
    
    if(a > b){
    	x = a;
    	a = b;
    	b = x;
    };
    
    printf("%d %d %d\n", a, b, c);
    
    return 0;
}

Measured memory_bytes: 596