akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define meow(args...) fprintf(stderr, args)
inline bool cmin(auto &a, const auto &b) {return b<a?(a=b, true):false;}
inline bool cmax(auto &a, const auto &b) {return a<b?(a=b, true):false;}
template<class Type> Type read() {
	Type a;
	bool b;
	unsigned char c;
	while(c=getchar()-48, (c>9)&(c!=253));
	for(a=(b=c==253)?0:c; (c=getchar()-48)<=9; a=a*10+c);
	return b?-a:a;
}
auto rd=read<int>;
typedef unsigned u32;
typedef long long s64;
typedef unsigned long long u64;
const u32 P=1e9+7;
u32 &inc(u32 &a, u32 b) {return (a+=b)<P?a:(a-=P);}
u32 &dec(u32 &a, u32 b) {return (a-=b)&0x80000000?(a+=P):a;}
u32 sum(u32 a, u32 b) {return inc(a, b);}
u32 dif(u32 a, u32 b) {return dec(a, b);}
u64 power(u64 a, int b) {
	u64 ans=1;
	for(; b; a=a*a%P, b/=2) if(b&1) ans=ans*a%P;
	return ans;
}

const int T=65555;
int a[16];
u32 fac[T], ifac[T], f[T];
u64 arr(int n, int r) {return n<0||r<0||r>n?0:(u64)fac[n]*ifac[n-r]%P;}
int main() {
	int n=rd(), m=rd(), tot=1<<n;
	u32 ans=0;
	std::generate(a, a+m, rd);
	fac[0]=1;
	for(int i=1; i<=tot; ++i) fac[i]=(u64)fac[i-1]*i%P;
	ifac[tot]=power(fac[tot], P-2);
	for(int i=tot; i--; ) ifac[i]=ifac[i+1]*(i+1llu)%P;
	f[0]=1;
	for(int i=m; i--; )
		for(int j=tot; j--; )
			for(int t=j; t; t&=t-1) {
				int k=t&-t;
				f[j]=(f[j]+arr(tot-a[i]-j+k, k-1)*(P-f[j-k])%P*k)%P;
			}
	for(int i=0; i<tot; ++i) ans=(ans+(u64)fac[tot-i-1]*f[i])%P;
	std::cout<<(u64)ans*tot%P<<std::endl;
	return 0;
}


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

int main(){
  int i,n;
  int p,d1,d2,d;
  int max,maxnum;

  while(1){
    cin >> n;
    if(!n)break;

    max = 0;
    for(i=0;i<n;i++){
      cin >> p >> d1 >> d2;
      d = d1 + d2;
      if(max<d){
	max = d;
	maxnum = p;
      }
    }
    cout << maxnum << " " << max << endl;
  }
}

Measured memory_bytes: 864
#include <stdio.h>
int main(void){
    int h,w,i,j;
    char gomi;
    scanf("%d %d",&h,&w);
    char data[h][w];
    scanf("%c",&gomi);
    for(i=0;i<h;i++){
        for(j=0;j<w;j++){
            scanf("%c",&data[i][j]);
            if(j==w-1){
                scanf("%c",&gomi);
            }
        }
    }
    for(i=0;i<w+2;i++){
        printf("#");
    }
    printf("\n");
    for(i=0;i<h;i++){
        for(j=0;j<w;j++){
            if(j==0){
                printf("#");
            }
            printf("%c",data[i][j]);
            if(j==w-1){
                printf("#\n");
            }
        }
    }
    for(i=0;i<w+2;i++){
        printf("#");
    }
    return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
#define fo(i,a,b) for((i)=(a);i<=(b);i++)
#define rfo(i,a,b) for((i)=(a);i>=(b);i--)
#define inrange(x,y,z) (((x)>=(y))&&((x)<=(z)))
#define ALL(vec) ((vec).begin(),(vec).end())
#define SOR(vec) sort(ALL(vec))
#define UNI(vec) (vec).erase(unique(ALL(vec)),(vec).end())
using namespace std;
int n,eu,ev;
long long tot,block;
vector<int> ga[200100];
int main(){
	#ifdef FILIN
		#ifndef DavidDesktop
			freopen(FILIN,"r",stdin);
			freopen(FILOUT,"w",stdout);
		#endif
	#endif
	ios::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>n;
	for(int i=2;i<=n;i++){
		cin>>eu>>ev;
		ga[eu].push_back(ev);
		ga[ev].push_back(eu);
	}
	for(int i=1;i<=n;i++){
		block++;
		for(int j:ga[i])
			if(j<i) block--;
		tot+=block;
	}
	block=tot;
	for(int i=1;i<n;i++){
		block-=(long long)(n-i+1);
		for(int j:ga[i])
			if(j>i) block+=(long long)(n-j+1);
		tot+=block;
	}
	cout<<tot<<endl;
	return 0;
}


Measured memory_bytes: 14952
using System;
using System.Collections.Generic;
using System.Linq;

namespace PaizaTest
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            //var sumList = new int[n + 1];

            // (x - p)^2 分体力を消費する
            // 累積和の計算を行う
            var nList = Console.ReadLine().Split(' ').Select(int.Parse).ToList();
            var maxDistance = nList.Max();
            int maxPower = int.MaxValue;
            //int maxIndex = 0;

            for (int i = 1; i <= maxDistance; i++)
            {
                var meetingIndex = i;
                var currentPower = 0;
                for (int j = 0; j < nList.Count; j++)
                {
                    currentPower += (nList[j] - meetingIndex) * (nList[j] - meetingIndex);
                }

                if (maxPower > currentPower)
                {
                    maxPower = currentPower;
                    //maxIndex = i;
                }
            }

            Console.WriteLine(maxPower);
            //Console.WriteLine($"index: {maxIndex}");
        }
    }
}


Measured memory_bytes: 13396
# include "algorithm"
# include "iostream"
# include "cstdio"

using namespace std;

const int maxm=1e2+10;

int A[maxm];

int main(){
	register int i,Ans=0;
	for(i=1;i<=5;i++){
		scanf("%d",A+i);
		Ans+=A[i];
		A[i]=(10-A[i]%10)%10;
	}
	sort(A+1,A+6);
	for(i=1;i<5;i++){
		Ans+=A[i];
	}
	cout<<Ans;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define fi first;
#define se second;
int main(){
  ll N,K;
 cin>>N>>K;
 if(K%2==0){
     ll a=N/K;
     ll b=(N+K/2)/K;
     cout<<a*a*a+b*b*b<<endl;
 }
 else{
     ll a=N/K;
 cout<<a*a*a<<endl;
}
}

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

using namespace std;

using ll = long long;

constexpr char newl = '\n';

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

    int x;
    cin >> x;
    cout << 1 - x << newl;

    return 0;
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
#define _MACRO(_1, _2, _3, NAME, ...) NAME
#define _repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define _rep(i,n) _repl(i,0,n)
#define rep(...) _MACRO(__VA_ARGS__, _repl, _rep)(__VA_ARGS__)
#define pb push_back
#define all(x) begin(x),end(x)
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#ifdef LOCAL
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
void _dbg(string){cerr<<endl;}
template<class H,class... T> void _dbg(string s,H h,T... t){int l=s.find(',');cerr<<s.substr(0,l)<<" = "<<h<<", ";_dbg(s.substr(l+1),t...);}
template<class T,class U> ostream& operator<<(ostream &o, const pair<T,U> &p){o<<"("<<p.first<<","<<p.second<<")";return o;}
template<class T> ostream& operator<<(ostream &o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}
#else
#define dbg(...) {}
#endif

class SCC {
private:
  vector<vector<int>> &G;
  vector<vector<int>> &rG;
  vector<bool> used;
  vector<int> vs;
  int n;
  void dfs(int v){
    used[v] = true;
    for(auto to : G[v]) if(!used[to]) dfs(to);
    vs.pb(v);
  }
  void rdfs(int v, int k){
    used[v] = true;
    cmp[v] = k;
    groups.back().pb(v);
    for(auto to : rG[v]) if(!used[to]) rdfs(to, k);
  }
public:
  vector<int> cmp; //頂点iが属するSCCのID
  vector<vector<int>> groups; // SCCのトポロジカル順i番目に属する頂点番号群
  int gc = 0; // group count
  SCC(vector<vector<int>> &g, vector<vector<int>> &r) : G(g), rG(r){
    n = G.size();
    used = vector<bool>(n, false);
    cmp.resize(n);
    rep(i,n) if(!used[i]) dfs(i);
    fill(all(used), false);
    for(int i=vs.size()-1; i>=0; i--) if(!used[vs[i]]){
      groups.pb(vector<int>());
      rdfs(vs[i], gc++);
    }
  }
  inline bool same(int i, int j){ return cmp[i]==cmp[j]; }
  inline int operator[](int i){ return cmp[i]; }
};

int main(){
  int n;
  cin>>n;
  map<pair<int,int>, int> num;
  rep(i,n) rep(j,i) {
    int x = num.size();
    num[{j,i}] = x;
  }

  vector<vector<int>> to(num.size());
  vector<vector<int>> from(num.size());

  rep(i,n){
    vector<int> tmp;
    rep(j,n-1){
      int k; cin>>k;
      k--;
      tmp.pb(num[{min(i,k), max(i,k)}]);
    }
    rep(j,n-2) {
      to[tmp[j]].pb(tmp[j+1]);
      from[tmp[j+1]].pb(tmp[j]);
    }
  }

  SCC scc(to, from);

  for(auto &v : scc.groups) if(v.size() > 1) {
    cout << -1 << endl;
    return 0;
  }

  vector<int> nxt;
  vector<int> d(num.size());
  rep(i,num.size()) {
    d[i] = from[i].size();
    if(d[i]==0) nxt.pb(i);
  }

  int ans = 0;
  int visited = n * (n-1) / 2;
  while(visited > 0) {
    ans++;
    vector<int> tmp;
    assert(nxt.size() > 0);
    for(auto v : nxt) {
      visited--;
      for(auto i : to[v]) {
        d[i]--;
        if(d[i]==0) tmp.pb(i);
      }
    }
    swap(tmp, nxt);
  }

  cout << ans << endl;

  return 0;
}


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

int main(){

  int n, maxv=-1000000000, minv;

  cin>>n;
  for(int i=0;i<n;i++){
    int x;
    cin>>x;
    if(!i) minv=x;
    else{
      maxv=max(maxv, x-minv);
      minv=min(minv, x);
    }
  }

  cout<<maxv<<endl;

  return 0;
}



Measured memory_bytes: 3116
#include <bits/stdc++.h>
using namespace std;
  
int main(){
  int n, temp;
  cin>>n;
  int arr[n];
  for(int i=0;i<n;i++){
    cin>>temp;
    arr[i]=temp;
  }
  int dp[n];
  dp[0]=0;
  dp[1]=abs(arr[1]-arr[0]);
  for(int i=2;i<n;i++){
  	dp[i]=min(dp[i-1]+abs(arr[i]-arr[i-1]),dp[i-2]+abs(arr[i]-arr[i-2]));
  }
  cout<<dp[n-1]<<endl;
}


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

int main(){
    int n;
    cin >> n;
    
  if(n==3 ||n==5 ||n==7)cout << "YES" << endl;
  else cout << "NO" << endl;
    
    return 0;
}

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

using namespace std;

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

#define REP(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, a, b) for(int i=(a); i<(b); ++i)
#define FORR(i, a, b) for(int i=(b)-1; i>=(a); --i)

#define DEBUG(x) cout<<#x<<": "<<x<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";REP(i, v.size())cout<<' '<<v[i];cout<<'\n'
#define ALL(a) (a).begin(), (a).end()

#define CHMIN(a, b) a=min((a), (b))
#define CHMAX(a, b) a=max((a), (b))

const ll MOD=1000000007ll;
// const ll MOD=998244353ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

const double EPS=1e-11;
#define EQ0(x) (abs((x))<EPS)
#define EQ(a, b) (abs((a)-(b))<EPS)

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	double a[114], sum=0;
	cin>>n;
	REP(i, n){
		cin>>a[i];
		sum+=a[i];
	}
	sum/=n;
	int ans=0;
	double tmp=1e9;
	REP(i, n){
		if(tmp>(abs(sum-a[i]))){
			tmp=abs(sum-a[i]);
			ans=i;
		}
	}
	cout<<ans<<'\n';
	return 0;
}


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

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

#define FOR(i, n, m) for (ll(i) = (m); (i) < (n); ++(i))
#define REP(i, n) FOR(i, n, 0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

ll N;
ll A[100005];
bool U[100005];

string solve()
{
    sort(A, A + N);
    ll s = -1;
    ll t = -1;
    REP(i, N - 1)
    {
        ll x = A[N - 1] ^ A[i];
        ll ok = i, ng = N - 1;
        while (abs(ok - ng) > 1)
        {
            ll mid = (ok + ng) / 2;
            if (A[mid] <= x)
                ok = mid;
            else
                ng = mid;
        }
        if (ok == i || A[ok] != x)
            continue;
        s = i;
        t = ok;
        break;
    }
    if (s < 0 || t < 0)
        return "No";

    U[N - 1] = U[s] = U[t] = true;
    vector<ll> v;
    v.push_back(A[N - 1]);
    v.push_back(A[s]);
    v.push_back(A[t]);

    while (v.size() < N)
    {
        ll num = v.size();
        ll x = v[num - 1] ^ v[num - 2];
        int low = lower_bound(A, A + N, x) - A;
        int upp = upper_bound(A, A + N, x) - A;
        ll ok = low, ng = upp;
        while (abs(ok - ng) > 1)
        {
            ll mid = (ok + ng) / 2;
            if (!U[mid])
                ok = mid;
            else
                ng = mid;
        }
        int index = ok;
        if (x != A[index]||U[index])
            return "No";
        v.push_back(A[index]);
        U[index] = true;
    }

    if ((v[0] ^ v[1]) != v[N - 1])
        return "No";
    return "Yes";
}

int main()
{
    cin >> N;
    REP(i, N)
    {
        cin >> A[i];
    }

    cout << solve() << endl;
    return 0;
}


Measured memory_bytes: 2296
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;

ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

int main(){
	int n; cin>>n;
	cout<<n*n*n<<endl;
}

Measured memory_bytes: 256
ar = list(input())
l = len(ar)
if l < 5:
    print('NO')
else:
    while True:
        if l == 0:
            print("YES")
            exit()
        if "".join(ar[l-5:l]) == 'dream' or "".join(ar[l-5:l]) == 'erase':
            l -= 5
        elif "".join(ar[l-6:l]) == 'eraser':
            l -= 6
        elif "".join(ar[l-7:l]) == 'dreamer':
            l -= 7
        else:
            print("NO")
            exit()


Measured memory_bytes: 3956
from sys import stdin


def main():
    input = lambda: stdin.readline()[:-1]
    K = int(input())

    n = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
    print(n[K-1])


main()


Measured memory_bytes: 3060
#include "bits/stdc++.h"
using namespace std ;


int a[100005] , b[100005] ;

int main(){
	int N ;
	cin >> N ;
	for( int i= 0 ; i < N ; i++ ){
		cin >> a[i];
	}
	if( N == 1) {
		puts("0");
		return 0 ;
	}
	for( int i= N-2 ; i >=0 ; i-- ){

		if( a[i] >= a[i+1] ) b[i] = b[i+1] + 1 ;
		else  b[i] = 0 ;
	}
	int ans = 0 ;
	for( int i = 0 ; i < N ; i++ ){
		// cout << b[i] << endl ;
		ans = max(ans,b[i]);
	}
	cout << ans << endl ;
	return 0 ;
}

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

struct dsu {
  public:
    dsu() : _n(0) {}
    dsu(int n) : _n(n), parent_or_size(n, -1) {}

    int merge(int a, int b) {
        assert(0 <= a && a < _n);
        assert(0 <= b && b < _n);
        int x = leader(a), y = leader(b);
        if (x == y) return x;
        if (-parent_or_size[x] < -parent_or_size[y]) std::swap(x, y);
        parent_or_size[x] += parent_or_size[y];
        parent_or_size[y] = x;
        return x;
    }

    bool same(int a, int b) {
        assert(0 <= a && a < _n);
        assert(0 <= b && b < _n);
        return leader(a) == leader(b);
    }

    int leader(int a) {
        assert(0 <= a && a < _n);
        if (parent_or_size[a] < 0) return a;
        return parent_or_size[a] = leader(parent_or_size[a]);
    }

    int size(int a) {
        assert(0 <= a && a < _n);
        return -parent_or_size[leader(a)];
    }

    std::vector<std::vector<int>> groups() {
        std::vector<int> leader_buf(_n), group_size(_n);
        for (int i = 0; i < _n; i++) {
            leader_buf[i] = leader(i);
            group_size[leader_buf[i]]++;
        }
        std::vector<std::vector<int>> result(_n);
        for (int i = 0; i < _n; i++) {
            result[i].reserve(group_size[i]);
        }
        for (int i = 0; i < _n; i++) {
            result[leader_buf[i]].push_back(i);
        }
        result.erase(
            std::remove_if(result.begin(), result.end(),
                           [&](const std::vector<int>& v) { return v.empty(); }),
            result.end());
        return result;
    }

  private:
    int _n;
    // root node: -1 * component size
    // otherwise: parent
    std::vector<int> parent_or_size;
};

int main() {
    int N, M;
    cin >> N >> M;
    int A[M], B[M];
    dsu ds(N);
    for (int i = 0; i < M; i++) {
        cin >> A[i] >> B[i];
        A[i]--;
        B[i]--;
        ds.merge(A[i], B[i]);
    }
    int n = ds.groups().size();
    cout << n - 1<< "\n";
    return 0;
}

Measured memory_bytes: 8980
import java.util.TreeMap

fun main(args: Array<String>) {
    val (n, k) = readLine()!!.split(' ').map(String::toLong)
    val tm = TreeMap<Int, Long>()
    repeat(n.toInt()) {
        val (a, b) = readLine()!!.split(' ').map(String::toInt)
        val qty = tm[a]
        tm[a] = if (qty == null) b.toLong() else qty + b
    }
    var i = 0L
    for ((a, b) in tm) {
        i += b
        if (k <= i) {
            println(a)
            break
        }
    }
}


Measured memory_bytes: 60268
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

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

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

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

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

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

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

// use std::io::{stdout, Write, BufWriter};
use std::cmp::min;

fn main() {
    input! {
        a_size: usize,
        b_size: usize,
        m: usize,
        refg: [i32; a_size],
        mw: [i32; b_size],
        disc: [(usize, usize, i32); m],
    }

    let mut ans = *(refg.iter().min().unwrap()) + *(mw.iter().min().unwrap());

    for (x, y, c) in disc {
        ans = min(ans , *(refg.get(x - 1).unwrap()) + *(mw.get(y - 1).unwrap()) - c)
    }

    println!("{}", ans);
}


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

using namespace std;

#define MMAX 1000
#define NMAX 1000
#define JOI_J 0
#define JOI_O 1
#define JOI_I 2

int M,N;
string emb[MMAX];
string mon[2];
int changec[3][MMAX][NMAX];

int main(){

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

	cin>>mon[0];
	cin>>mon[1];

	int c=0;

	for(int i=0;i<M;i++){
		for(int j=0;j<N;j++){
			for(int k=0;k<3;k++){
				changec[k][i][j]=0;
			}
		}
	}

	for(int i=0;i<M-1;i++){
		for(int j=0;j<N-1;j++){
			bool f=true;
			int fc=0;
			int fi=0,fj=0,fm=0;
			for(int k=0;k<2;k++){
				for(int l=0;l<2;l++){
					if(emb[i+k][j+l]!=mon[k][l]){
						f=false,fc++,fi=i+k,fj=j+l;
						if(mon[k][l]=='J') fm=JOI_J;
						if(mon[k][l]=='O') fm=JOI_O;
						if(mon[k][l]=='I') fm=JOI_I;
					}
				}
			}
			if(f){
				c++;
				for(int k=0;k<2;k++){
					for(int l=0;l<2;l++){
						for(int m=0;m<3;m++){
							if(!(m==JOI_J&&emb[i+k][j+l]=='J'||m==JOI_O&&emb[i+k][j+l]=='O'||m==JOI_I&&emb[i+k][j+l]=='I')) changec[m][i+k][j+l]--;
						}
					}
				}
			}
			else{
				if(fc==1){
					changec[fm][fi][fj]++;
				}
			}
		}
	}

	

	int max=-1;
	for(int i=0;i<M;i++){
		for(int j=0;j<N;j++){
			for(int k=0;k<3;k++){
				if(max<changec[k][i][j]) max=changec[k][i][j];
			}
		}
	}

	if(max>=1) c+=max;
	cout<<c<<endl;
}

Measured memory_bytes: 13972
// 2013/06/22 Tazoe

#include <iostream>
using namespace std;

void setD(int D[6], int t, int f)
{
	D[0] = t;
	D[1] = f;
	D[5] = 7-t;
	D[3] = 7-f;

	if((D[0]==3&&D[1]==5) || (D[1]==3&&D[5]==5) || (D[5]==3&&D[3]==5) || (D[3]==3&&D[0]==5))  D[2] = 1;
else	if((D[0]==3&&D[1]==1) || (D[1]==3&&D[5]==1) || (D[5]==3&&D[3]==1) || (D[3]==3&&D[0]==1))  D[2] = 2;
else	if((D[0]==5&&D[1]==1) || (D[1]==5&&D[5]==1) || (D[5]==5&&D[3]==1) || (D[3]==5&&D[0]==1))  D[2] = 3;
else	if((D[0]==1&&D[1]==5) || (D[1]==1&&D[5]==5) || (D[5]==1&&D[3]==5) || (D[3]==1&&D[0]==5))  D[2] = 4;
else	if((D[0]==1&&D[1]==3) || (D[1]==1&&D[5]==3) || (D[5]==1&&D[3]==3) || (D[3]==1&&D[0]==3))  D[2] = 5;
else	if((D[0]==5&&D[1]==3) || (D[1]==5&&D[5]==3) || (D[5]==5&&D[3]==3) || (D[3]==5&&D[0]==3))  D[2] = 6;

	D[4] = 7-D[2];
}

int searchD(int D[6], int n)
{
	for(int i=0; i<6; i++){
		if(D[i]==n){
			return i;
		}
	}

	return -1;
}


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

		if(n==0)
			break;

		int F[200][200][2];
		for(int y=0; y<200; y++){
			for(int x=0; x<200; x++){
				F[y][x][0] = 0;
				F[y][x][1] = 0;
			}
		}

		for(int i=0; i<n; i++){
			int t, f;
			cin >> t >> f;

			int D[6];
			setD(D, t, f);
/*
			for(int j=0; j<6; j++){
				cout << D[j] << ' ';
			}
			cout << endl;
*/
			int Y = 100;
			int X = 100;
			int Z = F[100][100][1];

			bool flg = true;
			while(flg){
				flg = false;

				for(int j=6; j>=4; j--){
					switch(searchD(D, j)){
					case 0:
					case 5:
						break;
					case 1:
						if(F[Y+1][X][1]<Z){
							Y++;
							Z = F[Y][X][1];
							setD(D, D[3], D[0]);
							flg = true;
						}
						break;
					case 2:
						if(F[Y][X+1][1]<Z){
							X++;
							Z = F[Y][X][1];
							setD(D, D[4], D[1]);
							flg = true;
						}
						break;
					case 3:
						if(F[Y-1][X][1]<Z){
							Y--;
							Z = F[Y][X][1];
							setD(D, D[1], D[5]);
							flg = true;
						}
						break;
					case 4:
						if(F[Y][X-1][1]<Z){
							X--;
							Z = F[Y][X][1];
							setD(D, D[2], D[1]);
							flg = true;
						}
						break;
					default:
						break;
					}

					if(flg)
						break;
				}
			}

			F[Y][X][0] = D[0];
			F[Y][X][1]++;

//			cout << Y << ' ' << X << ' ' << F[Y][X][0] << ' ' << F[Y][X][1] << endl;
		}

		int C[7];
		for(int i=0; i<7; i++){
			C[i] = 0;
		}

		for(int y=0; y<200; y++){
			for(int x=0; x<200; x++){
				C[F[y][x][0]]++;
			}
		}

		cout << C[1] << ' ' << C[2] << ' ' << C[3] << ' ' << C[4] << ' ' << C[5] << ' ' << C[6] << endl;
	}

	return 0;
}

Measured memory_bytes: 1472
#include <bits/stdc++.h>
#define int long long
#define rep(i, a, n) for(int (i) = (int)(a);(i) < (int)(n);++(i))
#define repe(i, a, n) for(int (i) = (int)(a);(i) <= (int)(n);++(i))
#define repif(i, a, x) for(int (i) = (int)(a);(x);++(i))
#define repr(i, a, n) for(int (i) = ((int)(a)-1);(i) >= (int)(n);--(i))
#define reper(i, a, n) for(int (i) = (int)(a);(i) >= (int)(n);--(i))
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define SIZE(x) ((int)(x).size())
#define ALL(x) (x).begin(), (x).end()
#define RNG(x, a, n) &((x)[a]), &((x)[n])
#define ADD(a, b) ((((a+MOD)%MOD)+((b+MOD)%MOD))%MOD)
#define MUL(a, b) ((((a)%MOD)*((b)%MOD))%MOD)
#define CEIL(x) ((int)ceil(((double)x)))
#define POW(x, y) ((int)pow(x, y))
#define UNIQUE(x) (x).erase(unique(ALL((x))), (x).end())
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define yes cout << "yes" << endl;
#define no cout << "no" << endl;
#define fcout cout << fixed << setprecision(10)
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define PI (acos(-1))
#define EPS (1e-10)
#define INF LLONG_MAX
#define MOD 1000000007
using namespace std;
using VI = vector<int>;
using PII = pair<int, int>;
using VPII = vector<PII>;
using Complex = complex<double>;


int N, X;
int x[100010];


int gcd(int a, int b){
	return a%b ? gcd(b, a%b) : b;
}


signed main(){
    cin >> N >> X;
    rep(i, 0, N) cin >> x[i], x[i] = abs(x[i]-X);

    int ans = x[0];
    rep(i, 1, N) ans = gcd(ans, x[i]);

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1024
package main

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

func getNextLine(scanner *bufio.Reader) string {
	var buffer string
	for {
		line, isPrefix, _ := scanner.ReadLine()
		buffer += string(line)
		if isPrefix == false {
			break
		}
	}
	return buffer
}

func getIntList(scanner *bufio.Reader) []int {
	list := strings.Split(getNextLine(scanner), " ")
	l := len(list)
	result := make([]int, l)
	for i := 0; i < l; i++ {
		result[i], _ = strconv.Atoi(list[i])
	}
	return result
}

func main() {
	fp := os.Stdin
	if len(os.Args) > 1 {
		fp, _ = os.Open(os.Args[1])
	}

	scanner := bufio.NewReader(fp)

	ab := getIntList(scanner)
	a := ab[0]
	b := ab[1]
	sum := 0
	if a > b {
		sum += a
		a--
	} else {
		sum += b
		b--
	}
	if a > b {
		sum += a
		a--
	} else {
		sum += b
		b--
	}
	fmt.Println(sum)
}


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

using namespace std;

typedef long long ll;

void getlis(int here, int parent, vector<vector<int>>& g, vector<ll>& value, vector<ll>& lis, vector<int>& ret){
    
    ll a = value[here];

    bool last = false;
    bool duplicate = false;
    int idx = 0;
    ll before = 0;
    if(lis.size() == 0 || lis.back() < a){
        last = true;
        lis.push_back(a);
    }
    else{
        idx = distance(lis.begin(), lower_bound(lis.begin(), lis.end(), a));
        if(lis[idx] == a){
            duplicate = true;
        }
        else{
            before = lis[idx];
            lis[idx] = a;
        }
    }

    ret[here] = lis.size();

    for(int i = 0 ; i < g[here].size(); ++i){
        int there = g[here][i];
        if(there == parent){
            continue;
        }
        getlis(there, here, g, value, lis, ret);
    }

    if(last){
        lis.pop_back();
    }
    else if(duplicate == false){
        lis[idx] = before;
    }

    return;

}


int main (){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll N;
    cin >> N;
    vector<ll> value(N+1);
    for(int i = 1 ; i < N+1 ; ++i){
        cin >> value[i];
    }
    vector<vector<int>> g(N+1);
    for(int i = 0 ; i < N-1 ; ++i){
        int a, b;
        cin >> a >> b;
        g[a].push_back(b);
        g[b].push_back(a);
    }

    vector<int> ret(N+1);
    vector<ll> lis;
    
    getlis(1, -1, g, value, lis, ret);

    for(int i = 1; i < N+1; ++i){
        cout << ret[i] << endl;
    }

    return 0;
}

Measured memory_bytes: 39484
#include<bits/stdc++.h>
#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll long long
#define inf 2000000000
#define infLL 2000000000000000000
#define MAX 200005
#define sf(a) scanf("%d", &a)
#define sfl(a) scanf("%lld", &a)
#define pf(a) printf("%d\n", a)
#define pfl(a) printf("%lld\n", a)
#define Case(t) printf("Case %d: ", t)
#define pii pair<int, int>
#define MOD 1000000007

#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args)
{
    cerr << *it << " = " << a << endl;
    err(++it, args...);
}

clock_t t_Start;
void Start()
{
    t_Start = clock();
}
void End()
{
    double Time = (double)(clock()-t_Start)/CLOCKS_PER_SEC;
    error(Time);
}

typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>orderedSet;

vector<int>edge[MAX];
ll dp[2][MAX];

int dfs(int u, int p = -1)
{
    dp[0][u] = dp[1][u] = 1;
    for(auto v : edge[u])
    {
        if(v==p)
            continue;
        dfs(v, u);
        dp[1][u] = (dp[1][u] * dp[0][v])%MOD; ///if parent is black then child must be white
        dp[0][u] = (dp[0][u] * (dp[0][v]+dp[1][v])%MOD)%MOD; ///if parent is white then child can be white or black
    }
}

int main()
{
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    //Start();

    int n;
    cin>>n;
    for(int i = 0; i < n-1; i++)
    {
        int u, v;
        cin>>u>>v;
        edge[u].push_back(v);
        edge[v].push_back(u);
    }
    dfs(1);
    cout<<(dp[0][1]+dp[1][1])%MOD<<endl;

    //End();
    return 0;
}


Measured memory_bytes: 17408
from collections import deque

que=deque([1,2,3,4,5,6,7,8,9])
lunlun=deque([])
while len(lunlun)<10**5:
    p=que.popleft()
    lunlun.append(p)
    if p%10!=0:
        que.append(p*10+(p%10-1))
    que.append(p*10+(p%10))
    if p%10!=9:
        que.append(p*10+(p%10+1))

k=int(input())
print(lunlun[k-1])

Measured memory_bytes: 43376
#include <stdio.h>
#include <string.h>
int main()
{
    char a[50]={0},b[50]={0};
    int result=0,i,j,count;
    scanf("%s",a);
    scanf("%s",b);
    for(i=strlen(a)-strlen(b)+1;i>=0;i--)
    {
       count=0;
       for (j=i;j<strlen(b)+i;j++)
       {
           if (a[j]==b[j-i]||a[j]=='?')
           {
               count++;
           }
       }
       if (count==strlen(b))
       {
           for (j=i;j<strlen(b)+i;j++)
           {
               a[j]=b[j-i];
           }
           for (j=0;j<strlen(a);j++)
           {
               if (a[j]=='?') a[j]='a';
           }
           printf("%s\n",a);
           return 0;
       }
    }
    if(i<0){
        printf("UNRESTORABLE\n");
    }
    return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
#include<algorithm>
#include<math.h>
#include<string>
#include<iostream>
#include<vector>
#include<cstdlib>
#include<stdio.h>
#include<cmath>
#include<limits>
#include<iomanip>

using namespace std;

template <class T> using V = vector<T>;

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 long long INF = 1LL << 60;

using ll = long long;
using db = long double;
using st = string;
using ch = char;
using bl = bool;
using vll = V<ll>;
using vpll =V<pair<ll,ll>>;
using vst = V<st>;
using vdb = V<db>;
using vch = V<ch>;
using vbl = V<bl>;
using graph = V<V<int>>;
using pq = priority_queue<ll>;



#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define rFOR(i,a,b) for(ll i=(a);i>=(b);i--)
#define oFOR(i,a,b) for(ll i=(a);i<(b);i+=2)
#define bgn begin()
#define en end()
#define SORT(a) sort((a).bgn,(a).en)
#define REV(a) reverse((a).bgn,(a).en)
#define M(a,b) max(a,b)
#define rM(a,b) min(a,b)
#define fi first
#define se second
#define sz size()
#define gcd(a,b) __gcd(a,b)
#define co(a) cout<<a<<endl;
#define pb(a) push_back(a);



ll Sum(ll n) {
ll m=0;
  while(n){
    m+=n%10;
    n/=10;
  }
  return m;
}



const int MAX = 510000;
const int MOD = 1000000007;
 
long long fac[MAX], finv[MAX], inv[MAX];
 
void Comuse() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}


#define comuse Comuse()

ll combi(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

ll perm(int n,int k){
    if(n < k) return 0;
    if(n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] % MOD) % MOD;
}


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


vll div(ll n){
  vll ret;
  for(ll i=1;i*i<=n;i++){
    if(n%i==0){
      ret.push_back(i);
      if(i*i!=n){
        ret.push_back(n/i);
      }
    }
  }
  SORT(ret);
  return (ret);
}

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

    a=a*a%mod;
    
    n>>=1;
  }

  return ans;
}

void Solve();


const int MAX_N = 131072;
//segment tree 
int NN;
int seg[MAX_N*2-1];
void seguse(){
  for(int i=0;i<2*NN-1;i++){
    seg[i]=INT_MAX;
  }
}

signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<setprecision(20)<<fixed;
  Solve();
}


/****************************************\
| Thank you for viewing my code:)        |
| Written by RedSpica a.k.a. RanseMirage |
| Twitter:@asakaakasaka                  | 
\****************************************/
//segtreeの葉の先頭の添え字はn-1
void Solve(){
  //vll segtree(524287);
  //ll N=262144;
  ll n;
    cin>>n;
  st s,t;
    cin>>s>>t;
  FOR(i,0,2*n){
    if(i%2==0){
      cout<<s[i/2];
    }
    else{
      cout<<t[i/2];
    }
  }
  cout<<"\n";
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define ull unsigned long long
#define pb push_back
#define pf push_front
#define endl "\n"
#define fast_in_out ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

const int mod=1e7+9;

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

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

int power(int a , int b , int c)
{
    if(a==0) return 0;
    if(b==0) return 1;

    int res=1;
    a=a%c;
    while(b>0)
    {
        if(b&1)
        {
            res=(res*a)%c;
        }
        a=(a*a)%c;
        b>>=1;
    }
    return res;
}

int32_t main()
{

    fast_in_out;

    int t=1;
    //cin>>t;
    while(t--)
    {
		int n;
  	cin>>n;
  int a[n],b[n];
  bool flag=false;
  int c=0;
  for(int i=0;i<n;i++)
  {
      cin>>a[i]>>b[i];
      if(a[i]==b[i])
            c++;
        else
            c=0;

      if(c>=3 && flag==false)
      {
          flag=true;

      }
  }
  if(flag==false)
    cout<<"No";
  else
    cout<<"Yes";
    }

    return 0;
}


Measured memory_bytes: 3644
import math
import collections
N=int(input())
B=list(map(int,input().split()))
cnt=0
for i in range(N):
 if i==0:
  cnt=cnt+B[0]
 elif  i==N-1:
  cnt=cnt+B[N-2]
 else:
  cnt=cnt+min(B[i-1],B[i])
print(cnt)

Measured memory_bytes: 38256
#include <iostream>
#include <math.h>

void printRect(int w, int h) {
    for (int y=0; y<h; y++) {
        
        for (int x=0; x<w; x++) {
            printf("#") ;
        }
        printf("\n");
    }
    printf("\n") ;
}

int main(int argc, const char * argv[]) {
    
    while (1) {
        int h, w;
        std::cin >> h >> w ;
        if(h==0&&w==0) break ;
        printRect(w, h);
    }
    
    return 0 ;
}



Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <climits>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <string>
#include <list>
#include <ctime>
#include <complex>
#include <bitset>
#include <tuple>

#define ff first
#define ss second

using namespace std;
using pii=pair<int,int>;
using ll=long long;

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

    int n;
    cin>>n;
    map<string,int> m;
    for(int i=0; i<n; i++){
        string s;
        cin>>s;
        auto ret=m.insert({s,1});
        if(!ret.second) ret.first->second+=1;
    }
    vector<string> answer;
    int maxcnt=0;
    for(auto it=m.begin(); it!=m.end(); it++){
        if(maxcnt<it->second){
            maxcnt=it->second;
            answer.clear();
            answer.push_back(it->first);
        }
        else if(maxcnt==it->second) answer.push_back(it->first);
    }
    for(string &s : answer){
        cout<<s<<"\n";
    }
    return 0;
}


Measured memory_bytes: 25584
n = int(input())
array = list(input())
array.sort()
length = len(array)
if(length%2==0):
    if(array[int(length/2)-1]=='B'):
        print("No")
    else:
        print("Yes")
else:
    if(array[int(length/2)]=='B'):
        print("No")
    else:
        print("Yes")

Measured memory_bytes: 3060
n = int(input())
dlist = list(map(int,input().split()))

import itertools

kumiawaselist = list(range(0,n))
kumiawaselist = list(itertools.combinations(kumiawaselist,2))
ans = 0
for i in range(0,len(kumiawaselist)):
    ans += dlist[kumiawaselist[i][0]] * dlist[kumiawaselist[i][1]]

print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep_range(i, s, e) for (int i = (s); i < (int)(e); i++)
#define rep_rev(i, s, e) for (int i = (s)-1; i >= (int)(e); i--)
#define sort_vec(v) sort((v).begin(),(v).end())
typedef int64_t lint;
// lint mod = 998244353;
// lint mod = 1000000007;
template< typename T1, typename T2 >
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 >
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

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

lint app() {
  int h,w;
  cin>>h>>w;

  int ch,cw,dh,dw;
  cin>>ch>>cw;
  cin>>dh>>dw;
  ch--;cw--;dh--;dw--;

  vector<vector<bool>> s(h,vector<bool>(w));
  rep(i,h){
    string str;
    cin>>str;
    rep(j,w) s[i][j]=(str[j]=='.');
  }

  vector<vector<int>> dep(h,vector<int>(w,2e9));

  using state=pair<int,pair<int,int>>;
  priority_queue<state,vector<state>,greater<state>> que;
  que.emplace(0,make_pair(ch,cw));
  while(!que.empty()){
    auto u=que.top(); que.pop();
    auto us=u.second;
    int udep=u.first;
    int ui=us.first;
    int uj=us.second;
    if(udep>dep[ui][uj]) continue;

    rep(t,4){
      int vi=ui+dx[t];
      int vj=uj+dy[t];
      if(vi<0||vi>=h||vj<0||vj>w) continue;
      if(s[vi][vj]) if(chmin(dep[vi][vj],udep)) que.emplace(udep,make_pair(vi,vj));
    }
    rep_range(vi,ui-2,ui+3) rep_range(vj,uj-2,uj+3){
      if(vi<0||vi>=h||vj<0||vj>w) continue;
      if(s[vi][vj]) if(chmin(dep[vi][vj],udep+1)) que.emplace(udep+1,make_pair(vi,vj));
    }
  }

  int ans=dep[dh][dw];
  if(ans==2e9) return -1;
  return ans;
}

int main(){cout<<app()<<endl;return 0;}


Measured memory_bytes: 7676
#include <stdio.h>

#define MAX 2000000

void insert( char* queue, int k );
int extractMax( char* queue );
void swap( int x, int y );
int GetMaxindex( int x, int y );

int S[MAX] = {};
int index = 0;


int extractMax( char* queue )
{
    int i = 1;
    int maxIndex = 0;
    int left = 0;
    int right = 0;
    int maxElement = S[1];
    S[1] = S[index];
    index--;
    
    while((i * 2) <= index)
    {
        left = i * 2;
        right = left + 1;
        maxIndex = ( right <= index ) ? GetMaxindex( left, right ) : left;
         
        if( GetMaxindex( maxIndex, i ) == maxIndex )
        {
            swap( maxIndex, i );
            i = maxIndex;
        }
        else
        {
            break;
        }
    }
    return maxElement;
}

void swap( int x, int y )
{
    int temp = S[x];
     
    S[x] = S[y];
    S[y] = temp;
}

int GetMaxindex( int x, int y )
{
    return ( S[x] > S[y] ) ? x : y ;
}

void insert( char* queue, int k )
{
    int leaf = 0;
    int node = 0;
    index++;
    S[index] = k;
    leaf = index;
    node = leaf / 2;
    
    while( (S[leaf] > S[node]) && leaf > 1 )
    {
        swap( leaf, node );
        leaf = node;
        node = leaf / 2;
    }
}

int main()
{
    char com[10];
    int k = 0;
    
    while(1)
    {
        scanf("%s",com);
        if(com[0] == 'e')
        {
            if(com[1] == 'x')   printf("%d\n",extractMax(&S[0]));
            else    break;
        }
        else if(com[0] == 'i')
        {
            scanf("%d",&k);
            insert(&S[0],k);
        }
    }
    return 0;
}



Measured memory_bytes: 5648
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>

using ll = long long;

using namespace std;


string s[100010], ans;

bool exec(int i, int &a, int &b, char A, char B, string AB, string AC, string BC) {
    if (a < 0 || b < 0 || (a == 0 && b == 0)) {
        cout << "No" << '\n';
        return false;
    } 
    else if (a == 0) a++, b--, ans+=A;
    else if (b == 0) a--, b++, ans+=B;
    else if (s[i+1] == AC) a++, b--, ans+=A;
    else if (s[i+1] == BC) a--, b++, ans+=B;
    else if (a > b) a--, b++, ans+=B;
    else a++, b--, ans+=A;
    return true;
}

int main() {
    int n, a, b, c;
    cin >> n >> a >> b >> c;
    for (int i=0; i<n; i++) cin >> s[i];
    for (int i=0; i<n-1; i++) {
        if (s[i] == "AB") {
            if (!exec(i, a, b, 'A', 'B', "AB", "AC", "BC")) return 0;
        }
        if (s[i] == "AC") {
            if (!exec(i, a, c, 'A', 'C', "AC", "AB", "BC")) return 0;
        }
        if (s[i] == "BC") {
            if (!exec(i, b, c, 'B', 'C', "BC", "AB", "AC")) return 0;
        }
    }
    if (a >= 0 && b >= 0 && c >= 0) {
        bool yes = false;
        if (s[n-1] == "AB" && a + b > 0) {
            yes = true;
            ans += (a < b ? "A" : "B");
        }
        else if (s[n-1] == "AC" && a + c > 0) {
            yes = true;
            ans += (a < c ? "A" : "C");
        }
        else if(s[n-1] == "BC" && c + b > 0) {
            yes = true;
            ans += (c < b ? "C" : "B");
        }
        if (yes) {
            cout << "Yes" << '\n';
            for (auto &ai:ans) cout << ai << '\n';
            return 0;
        }
    }
    cout << "No" << '\n';
    return 0;
}

Measured memory_bytes: 6880
#include <bits/stdc++.h>
using namespace std;
int pre[105][105];

int main()
{
  int n,m,k;
  scanf("%d%d%d",&n,&m,&k);
  n++;
  for(int i=0;i<n;i++){
    for(int j=0;j<m;j++){
      scanf("%d",&pre[i][j]);
    }
  }
  int cnt = 0;
  for(int i=1;i<n;i++){
    int ans = 0;
    for(int j=0;j<m;j++){
      ans += pre[0][j] * pre[i][j];
    }
    if(ans + k > 0) cnt ++;
  }
  cout<<cnt<<endl;
  return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int cnt[100001];

int main(){
    int n, m;
    cin >> n >> m;
    for(int i = 0; i < m; ++i){
        int a, b;
        cin >> a >> b;
        --a;
        --b;
        ++cnt[a];
        ++cnt[b];
    }
    
    for(int i = 0; i < n; ++i){
        if(cnt[i] % 2 != 0){
            cout << "NO\n";
            return 0;
        }
    }
    cout << "YES\n";
}

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

int main() {
  int N1, N2, N3, N4;
  cin >> N1 >> N2 >> N3 >> N4;

  vector<int> N = {N1, N2, N3, N4};

  int ans = 0;
  for (int i = 0; i < 4; i++) {
    if (N.at(i) == 1)
      N.at(i) *= 1000;
    else if (N.at(i) == 9)
      N.at(i) *= 100;
    else if (N.at(i) == 7)
      N.at(i) *= 10;
    ans += N.at(i);
  }

  if (ans == 1974)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
}

Measured memory_bytes: 384
#include<stdio.h>
int main()
{
    long long h,m;
char s;
    scanf("%lld %c %lld",&h,&s,&m);
    if(s=='+')
    {
        printf("%lld\n",h+m);
    }
    else
    {
         printf("%lld\n",h-m);
    }
    return 0;
}

Measured memory_bytes: 128
s = gets.chomp.split("")
t = gets.chomp.split("")
tlen = t.length
slen = s.length
min = 10000
(slen-tlen+1).times do |i|
  cnt = 0
  tlen.times do |j|
    if s[i+j] != t[j]
      cnt += 1
    end
  end
  min = [cnt,min].min
end
puts min

Measured memory_bytes: 14340
#include<iostream>
#include<cstdio>
using namespace std;
int main(){
	long n,s=0,min=0,max=0,a;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a;
		if(i==0){min=a;max=a;}
		s+=a;
		if(min>a)min=a;
		if(max<a)max=a;
	}
	cout<<min<<" "<<max<<" "<<s<<endl;
    return 0;
}



Measured memory_bytes: 3116
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n,a; cin>>n;
  for(int i=0;i<n;i++){
    cin>>a;
    if(a%2==0&&(a%6!=0&&a%10!=0)){
      cout<<"DENIED"<<endl;
      exit(0);
    }
  }
  cout<<"APPROVED"<<endl;
}

Measured memory_bytes: 256
def solve():
        
    N = int(input())
    A = [(a, i+1) for i, a in enumerate(map(int, input().split()))]

    A.sort(reverse=True)
    INF = float('inf')
    dp = [[-INF] * (N+1) for _ in range(N+1)]
    dp[0][0] = 0

    for s in range(1, N+1):
        for l in range(s+1):
            r = s - l
            dp[l][r] = max(dp[l-1][r] + A[s-1][0] * abs(A[s-1][1]-l), dp[l][r-1] + A[s-1][0] * abs(N-r+1-A[s-1][1]))

    ans = 0
    for m in range(N):
        if dp[m][N-m] > ans:
            ans = dp[m][N-m]

    print(ans)
solve()

Measured memory_bytes: 136172
N, K = map(int,input().split())
x=[int(i) for i in input().split()]
m=9999999999
for i in range(0,N-K+1):
    if x[i+K-1]<=0:
        if -x[i]<m:
            m=-x[i]
    elif x[i]>=0:
        if x[i+K-1]<m:
            m=x[i+K-1]
    elif x[i+K-1]>-x[i]:
        if -2*x[i]+x[i+K-1]<m:
            m=-2*x[i]+x[i+K-1]
    else:
        if 2*x[i+K-1]-x[i]<m:
            m=2*x[i+K-1]-x[i]
print(m)


Measured memory_bytes: 14480
N = int(input())
AB = [list(map(int,input().split())) for _ in range(N)]

AB = sorted(AB, key=lambda x: x[1])
time=0
for i in range(N):
    time += AB[i][0]
    if time>AB[i][1]:
        print('No')
        exit()
print('Yes')

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

#define ll long long
#define ar array

int n, ans;
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> n;
	for(int x = 1; x <= n; x++)
	{
		for(int y = 1; y <= n; y++)
		{
			for(int z = 1; z <= n; z++)
			{
				ans += __gcd((__gcd(x, y)), z);
			}
		}
	}
	cout << ans;
}


Measured memory_bytes: 3580
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
using ull=unsigned long long int;
using P=pair<ll,ll>;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
const ll mod=1000000007;
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
int main(){
string s;
cin>>s;
int n=s.size();
 int l=0;
for(int i=0;i<n;i++){
  if(s[i]=='(')l++;
  else if(s[i]==')')l--;
  else{
    cout<<l<<"\n";
    return 0;
  }
}
}


Measured memory_bytes: 3248
#include "bits/stdc++.h"
using namespace std;

//#define int long long
#define DBG 1
#define dump(o) if(DBG){cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) if(DBG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define each(it,c) for(auto it=(c).begin();it!=(c).end();it++)
#define all(c) c.begin(),c.end()
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9 + 7);

signed main() {
	for (int n; cin >> n&&n;) {
		vector<string> w(n); rep(i, 0, n) { cin >> w[i]; }
		rep(i, 0, n) {
			int a[5] = { 5,7,5,7,7 };
			int idx = 0;
			rep(j, i, n) {
				a[idx] -= w[j].size();
				if (a[idx] == 0) {
					if (idx == 4) {
						cout << i + 1 << endl;
						i = INF;
						break;
					}
					idx++;
				}
				if (a[idx] < 0)break;
			}
		}
	}
	return 0;
}

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

using namespace std;

typedef long long lo;
typedef pair< lo,lo > PII;

#define fi first
#define se second
#define mp make_pair
#define int long long
#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 = 100000000000000000;
const lo KOK = 100000;
const lo LOG = 30;
const lo li = 200005;
const lo mod = 1000000007;

int n,m,b[li],a[li],k,flag,t,dp[li];
int cev;
string s;
vector<int> v;

main(void){
	scanf("%lld %lld",&n,&k);
	FOR scanf("%lld",&a[i]);
	FOR dp[i]=inf;
	dp[1]=0;
	FOR{
		for(int j=1;j<=k;j++){
			dp[i+j]=min(dp[i+j],dp[i]+abs(a[i+j]-a[i]));
		}
	}
	printf("%lld\n",dp[n]);
	return 0;
}


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

using namespace std;

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

  int ap = 0;
  int zp = s.size() - 1;
  while(s[ap] != 'A') ap++;
  while(s[zp] != 'Z') zp--;
  cout << (zp - ap + 1) << endl;

  return 0;
}


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

#define rep(i, a, n)  for(ll i=a; i<n; i++)
#define per(i, a, n)  for(ll i=n-1; i>=a; i--)
#define fill0(n)  setfill('0') << right << setw(n)
#define all(x)  (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define LONGMAX 1e18
#define INTMAX 1000000000

using namespace std;
typedef long long ll;
typedef pair<ll ,ll> P;
const ll mod = 1e9+7;
const long double EPS = 0.0000000001;

int n, w;
int main(){
	cin >> n >> w;
	vector<int> weight(n), value(n);
	for(int i = 0; i < n; i++)cin >> weight[i] >> value[i];
	ll dp[n+1][w+1];
	for(int i = 0; i < n+1; i++){
		for(int j = 0; j < w+1; j++){
			dp[i][j] = 0;
		}
	}
	for(int i = 0; i < n; i++){
		for(int j = 0; j < w+1; j++){
			if(j - weight[i] >= 0){
				ll tmp = dp[i][j - weight[i]] + value[i];
				dp[i+1][j] = max(tmp, dp[i][j]);
			}else {
				dp[i+1][j] = dp[i][j];
			}
		}
	}
	cout << dp[n][w] << endl;

}

Measured memory_bytes: 79104