akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

using ll = long long;

const ll MOD = 1000000007;

ll modpow(ll x, ll n, ll mod = MOD) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * x % mod;
        x = x * x % mod;
        n >>= 1;
    }
    return res;
}

ll f[100005], fi[100005];

ll comb(int r, int c) {
    if (r < c) return 0;
    return f[r] * fi[c] % MOD * fi[r - c] % MOD;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<ll> a(n), sum(n, 0);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }

    f[0] = 1;
    for (int i = 1; i <= n; i++) {
        f[i] = f[i - 1] * i % MOD;
    }
    fi[n] = modpow(f[n], MOD - 2);
    for (int i = n; i > 0; i--) {
        fi[i - 1] = fi[i] * i % MOD;
    }

    for (int i = 1; i < n; i++) {
        sum[i] = f[n] * fi[i + 1] % MOD * f[i] % MOD;
        (sum[i] += sum[i - 1]) %= MOD;
    }

    ll ans = 0;
    for (int i = 0; i < n; i++) {
        (ans += a[i] * f[n] % MOD) %= MOD;
        (ans += a[i] * sum[i] % MOD) %= MOD;
        (ans += a[i] * sum[n - 1 - i] % MOD) %= MOD;
    }
    cout << ans << endl;
    return 0;
}

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

int main(){
	int k, n;
	cin >> k >> n;
	
	vector<int> a(n);
	rep(i, n) cin >> a.at(i);
	
	vector<int> gap(n);
	rep(i, n) {
		if (i == n - 1) {
			gap.at(i) = k + a.at(0) - a.at(n-1);
		} else {
			gap.at(i) = a.at(i+1) - a.at(i);
		}
     // cout << gap.at(i) << endl;
	}
	
	int max = 0;
	rep(i, n) {
		if (gap.at(i) > max) {
			max = gap.at(i);
		}
	}
	
	cout << k - max << endl;
}

Measured memory_bytes: 1792
while 1:
    try:
        s=raw_input()
        n=len(s)
        ns=""
        i=0
        while i<=n-1:
            if s[i]=="@" and i!=n-2:
                ns+=int(s[i+1])*s[i+2]
                i+=3
            else:
                ns+=s[i]
                i+=1
        print(ns)
    except:
        break

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

int main(){
  int N;
  int k=0;
  int a[50];
  
  cin >> N;
  for(int i=0;i<N;i++){
    cin >> a[i];
    if(a[i] != i+1) k++;
  }
  
  if(k==0||k==2) cout << "YES";
  else cout << "NO";
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
char s[100010];
int n;
int main(){
    scanf("%s",s+1);
    n=strlen(s+1);
    if(s[1]!='1'||s[n]!='0'){
        puts("-1");
        return 0;
    }
    for(int i=1;i<n;++i){
        if(s[n-i]!=s[i]){
            puts("-1");
            return 0;
        }
    }
    for(int i=2,rt=1;i<=n;++i){
        printf("%d %d\n",rt,i);
        if(s[i-1]=='1')rt=i;
    }
    return 0;
}

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

#define v short
const char nl = '\n';
#define loop(i, n) for (v i = 0; i < n; i++)

int main () {
    ios_base::sync_with_stdio(false);

    v n, c = 0;
    cin >> n;
    v a[n];
    loop (i, n) {
        cin >> a[i];
        if (i % 2 == 0 && a[i] % 2 == 1) {
            c++;
        }
    }
    cout << c << nl;
    
    return 0;
} 

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

namespace GRL4_B
{
    class Program
    {
        const int MAX = 10000;
        static int v, e;
        static int[] indeg = new int[MAX];
        static List<int>[] L = Enumerable.Range(0, MAX).Select(n => new List<int>()).ToArray();
        static bool[] color = new bool[MAX];
        static Queue<int> Q = new Queue<int>(); 
        static void Main(string[] args)
        {
            var t = scan;
            v = t[0];
            e = t[1];
            for (int i = 0; i < e; i++)
            {
                var k = scan;
                L[k[0]].Add(k[1]);
                indeg[k[1]]++;
            }

            for (int i = 0; i < v; i++)
            {
                if (indeg[i] == 0 && !color[i]) bfs(i);
            }
        }
        static void bfs(int s)
        {
            Q.Enqueue(s);
            color[s] = true;
            while (Q.Any())
            {
                Console.WriteLine(Q.Peek());
                int u = Q.Dequeue();

                foreach (var v in L[u])
                {
                    indeg[v]--;
                    if(indeg[v]==0&&!color[v])
                    {
                        color[v] = true;
                        Q.Enqueue(v);
                    }
                }
            }
        }
        static int[] scan { get { return Array.ConvertAll(Console.ReadLine().Split(), int.Parse); } }
    }
}

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

int main(){
  int n,i,j,sum=0,ans;
  string s;
  cin>>n>>s;
  
  for(i=1;i<n;i++){
    sum+=(s[i]=='E');
  }
  ans=sum;
  for(i=1;i<n;i++){
    sum+=(s[i-1]=='W');
    sum-=(s[i]=='E');
    ans=min(ans,sum);
  }
  cout<<ans<<endl;
}

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

int main(){
  std::string jpy = "JPY", btc = "BTC";
  int n;
  std::string t_u;
  double t_x;
  double ret = 0;
  double bit1 = 380000.0;

  std::cin >> n;
  for(int i = 0; i <n ; i++){
     std::cin >> t_x >> t_u;
     if(t_u == btc) t_x  = t_x * bit1;
     ret += t_x;
  }

  printf("%lf\n", ret);
  return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = (int)(a); i <= (int)(n); ++i)
#define rrep(i, a, n) for (int i = (int)(a); i >= (int)(n); --i)
#define debug(x) cerr << #x << " = " << x << "\n"
#define debugv(x) \
  rep(f, 0, (x.size() - 1)) cerr << x[f] << (f == (x.size() - 1) ? "\n" : " ")
#define all(x) x.begin(), x.end()
#define int long long
using namespace std;
typedef pair<int, int> pii;
typedef vector<int> vi;
const int MX = 1e5 + 5, INF = 5 << 28, MOD = 1e9 + 7;

int a, b, x;

void input() { cin >> a >> b >> x; }
void solve() {
  auto f = [&](int n) {
    int res = 0;
    if (n == 0) return 1LL;
    if (n < 0) return 0LL;
    res = n / x + 1;
    return res;
  };

  cout << f(b) - f(a - 1) << endl;
}
signed main() {
  input();
  solve();
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<iostream>
#include<algorithm>
using namespace std;
int hui(int n)
{
	int k=0;	int m,h=0;
	while(n>0)
	{
		m=n%10;
		n=n/10;
		h=h*10+m; 
	}
	return h;
}
int main()
{
	int a,b;
	scanf("%d%d",&a,&b);
	int h=0;
	for(int i=a;i<=b;i++)
	{
		int b=hui(i);
		if(b==i)
		h++;
	}
	printf("%d\n",h);
	return 0;
}

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

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

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

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

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

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

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

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

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

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

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

#[allow(dead_code)]
fn chmin<T>(x: &mut T, y: T) -> bool
where
    T: PartialOrd + Copy,
{
    *x > y && {
        *x = y;
        true
    }
}

#[allow(dead_code)]
fn chmax<T>(x: &mut T, y: T) -> bool
where
    T: PartialOrd + Copy,
{
    *x < y && {
        *x = y;
        true
    }
}

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

fn main() {
    input! {
        n:usize,
        a:[usize;n]
    }

    // 最大値を除くなら2番目の最大値を、それ以外は最大値を出力
    let mut ass = a.clone();
    ass.sort();
    let nax = ass[n - 1];
    let nax2 = ass[n - 2];
    for i in 0..n {
        if a[i] == nax {
            println!("{}", nax2);
        } else {
            println!("{}", nax);
        }
    }
}


Measured memory_bytes: 9724
//{
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double lf;
typedef pair<ll,ll> ii;
#define REP(i,n) for(ll i=0;i<n;i++)
#define REP1(i,n) for(ll i=1;i<=n;i++)
#define FILL(i,n) memset(i,n,sizeof i)
#define X first
#define Y second
#define SZ(_a) (int)_a.size()
#define ALL(_a) _a.begin(),_a.end()
#define pb push_back
#ifdef brian
#define debug(...) do{\
    fprintf(stderr,"%s - %d (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
    _do(__VA_ARGS__);\
}while(0)
template<typename T>void _do(T &&_x){cerr<<_x<<endl;}
template<typename T,typename ...S> void _do(T &&_x,S &&..._t){cerr<<_x<<" ,";_do(_t...);}
template<typename _a,typename _b> ostream& operator << (ostream &_s,const pair<_a,_b> &_p){return _s<<"("<<_p.X<<","<<_p.Y<<")";}
template<typename It> ostream& _OUTC(ostream &_s,It _ita,It _itb)
{
    _s<<"{";
    for(It _it=_ita;_it!=_itb;_it++)
    {
        _s<<(_it==_ita?"":",")<<*_it;
    }
    _s<<"}";
    return _s;
}
template<typename _a> ostream &operator << (ostream &_s,vector<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,set<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a,typename _b> ostream &operator << (ostream &_s,map<_a,_b> &_c){return _OUTC(_s,ALL(_c));}
template<typename _t> void pary(_t _a,_t _b){_OUTC(cerr,_a,_b);cerr<<endl;}
#define IOS()
#else
#define debug(...)
#define pary(...)
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0);
#endif // brian
//}


const ll MAXn=1e5+5,MAXlg=__lg(MAXn)+2;
const ll MOD=1000000007;
const ll INF=ll(1e15);

ll d[MAXn];

vector<ll> dt;

int main()
{
    IOS();
    ll n;
    cin>>n;
    REP(i,n)cin>>d[i];
    sort(d,d+n);
    if(n % 2 == 0)
    {
        ll tt = 0;
        REP1(i,n)
        {
            if(i < n / 2)tt -= 2 * d[i-1];
            else if(i == n/2)tt -= d[i-1];
            else if(i == n/2+1)tt += d[i-1];
            else tt += 2 * d[i-1];
        }
        cout<<tt<<endl;
    }
    else{
        ll tt1 = 0,tt2 = 0;
        REP(i,n)
        {
            if(i < n / 2 - 1)tt1 -= 2 * d[i];
            else if(i < n / 2 + 1)tt1 -= d[i];
            else tt1 += 2 * d[i];
        }
        REP(i,n)
        {
            if(i < n / 2)tt2 -= 2 * d[i];
            else if(i <= n / 2 + 1)tt2 += d[i];
            else tt2 += 2 * d[i];
        }
        cout<<max(tt1,tt2)<<endl;
    }
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define rep(i, c) for(int i=0; i < (int)c; i++)
const int inf = 1000000000;

int main() {
  int N;
  cin >> N;
  vector<int> X(N);
  rep(i, N) cin >> X[i];
  int L = X[0], R = X[0];
  rep(i, N) {
    L = min(L, X[i]);
    R = max(R, X[i]);
  }
  int ans = inf;
  for(int i = L; i <= R; i++){
    int cost = 0;
    rep(j, N) cost += (X[j]-i) * (X[j]-i);
    ans = min(ans, cost);
  }
  cout << ans <<endl;
  return 0;
}

Measured memory_bytes: 3580
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <string>
#include <cctype>
#include <stack>
#include <queue>
#include <vector>
#include <cstdlib>
#include <list>

using namespace std;

int main(void) {

	int a, b, c;
	int maxv;

	cin >> a >> b >> c;

	if (a > b && a > c)
		maxv = a;
	else if (b > a && b > c)
		maxv = b;
	else maxv = c;


	if (maxv == a && maxv == b + c)
		cout << "Yes" << endl;
	else if (maxv == b && maxv == a + c)
		cout << "Yes" << endl;
	else if (maxv == c && maxv == a + b)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;

	return 0;
}


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

// template {{{  0 
// using {{{ 1
using ll = long long int;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vii = vector<pii>;
using vll = vector<pll>;
// }}} 1
// definition {{{ 1
// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x,y) scanf("%d%d", &x, &y)
#define Scd3(x,y,z) scanf("%d%d%d", &x, &y, &z)
#define Scll(x) scanf("%lld", &x)
#define Scll2(x,y) scanf("%lld%lld", &x, &y)
#define Scll3(x,y,z) scanf("%lld%lld%lld", &x, &y, &z)
#define Scc(c) scanf("%c", &c);
#define Scs(s) scanf("%s", s);
#define Scstr(s) scanf("%s", &s);
// }}} 2
// constants {{{ 2
#define EPS (1e-7)
#define INF (2e9)
#define PI (acos(-1))
// }}} 2
// systems {{{ 2
#define Repe(x,y,z) for(ll x = z; x < y; x++)
#define Rep(x,y) Repe(x,y,0)
#define RRepe(x,y,z) for(ll x = y-z-1; x >= 0; x--)
#define RRep(x,y) RRepe(x,y,0)
// }}} 2
// output {{{ 2
#define YesNo(a) (a)?printf("Yes\n"):printf("No\n")
#define YESNO(a) (a)?printf("YES\n"):printf("NO\n")
// }}} 2
// }}} 1
// input {{{ 1
// }}} 1
// }}} 0

int main() {

    char s[12311];
    Scs(s);
    if( s[1] == 'R' ) s[1] = 'B'; else s[1] = 'R';
    printf ("%s\n", s );

    return 0;
}



Measured memory_bytes: 3668
#include <cassert>
#include <array>
#include <algorithm>
#include <iostream>
#include <complex>
#include <tuple>
#include <vector>
using namespace std;

const double EPS = 1e-10;
template<class T>
bool eq(const T& a, const T& b) {return abs(a - b) < EPS;}

typedef complex<double> point;
double cross(const point& a, const point& b) {
	return imag(conj(a)*b);
}
double dot(const point& a, const point& b) {
	return real(conj(a)*b);
}
int ccw(point a, point b, point c) {
	b -= a; c -= a;
	if (cross(b, c) > 0)   return +1;  // counter clockwise
	if (cross(b, c) < 0)   return -1;  // clockwise
	if (dot(b, c) < 0)     return +2;  // c--a--b on line
	if (norm(b) < norm(c)) return -2;  // a--b--c on line
	return 0;  // a--c--b on line or a----bc
}

typedef array<point, 2> line;
bool intersectSS(const line& s, const line& t) {
	return ccw(s[0],s[1],t[0])*ccw(s[0],s[1],t[1]) <= 0 &&
			ccw(t[0],t[1],s[0])*ccw(t[0],t[1],s[1]) <= 0;
}
point crosspoint(const line& l, const line& m) {
	double A = cross(l[1] - l[0], m[1] - m[0]);
	double B = cross(l[1] - l[0], l[1] - m[0]);
	if (eq(A, 0.) && eq(B, 0.)) return m[0]; // same line
	if (eq(A, 0.)) assert(false); // !!!PRECONDITION NOT SATISFIED!!!
	return m[0] + B / A * (m[1] - m[0]);
}

line read_line() {
	line res;
	for (auto& p : res) {
		int x, y;
		cin >> x >> y;
		p = point(x, y);
	}
	return res;
}

int solve() {
	line new_road = read_line();
	int n;
	cin >> n;
	typedef tuple<point, bool, bool> pinfo;
	vector<pinfo> points;
	for (int i = 0; i < n; i++) {
		line l = read_line();
		bool own, ground;
		cin >> own >> ground;
		if (intersectSS(new_road, l)) {
			points.emplace_back(crosspoint(new_road, l), own, ground);
		}
	}
//	cout << points.size() << endl;
	sort(points.begin(), points.end(), [&new_road](const pinfo& a, const pinfo& b) {
		return abs(get<0>(a) - new_road[0]) < abs(get<0>(b) - new_road[0]);
	});
	if (points.empty()) return 0;
	bool cur = get<1>(points[0]) ? get<2>(points[0]) : !get<2>(points[0]);
	int cnt = 0;
	for (int i = 1; i < points.size(); i++) {
		if ((get<1>(points[i]) && cur != get<2>(points[i])) ||
			(!get<1>(points[i]) && cur == get<2>(points[i]))) {
			cur = !cur;
			cnt++;
//			cout << i << endl;
		}
	}
	return cnt;
}

int main() {
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cout << solve() << endl;
	}
	return 0;
}

Measured memory_bytes: 1224
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1000000007;
#define INF 1LL<<30
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()

int main(){
    string s,t;
    cin>>s>>t;
    int n=s.size();
    int ans=0;
    rep(i,n){
        if(s[i]!=t[i]) ans++;
    }

    cout<<ans<<endl;
}


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

#define endl '\n'

int const N = 100010;
string s[N];
int n;
char ans[N];

bool solve(long long i, long long a, long long b, long long c){
    if (a < 0 || b < 0 || c < 0) return false;
    if (i == n) return true;
    if (s[i] == "AB"){
        ans[i] = 'A';
        if (solve(i+1, a+1, b-1, c)) return 1;
        ans[i] = 'B';
        return solve(i+1, a-1, b+1, c);
    } else if (s[i] == "AC"){
        ans[i] = 'A';
        if (solve(i+1, a+1, b, c-1)) return 1;
        ans[i] = 'C';
        return solve(i+1, a-1, b, c+1);
    }
    ans[i] = 'B';
    if (solve(i+1, a, b+1, c-1)) return 1;
    ans[i] = 'C';
    return solve(i+1, a, b-1, c+1);
}

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

    long long a,b,c; cin >> n >> a >> b >> c;
    for (int i=0; i<n; i++) cin >> s[i];
    if (solve(0, a,b,c)){
        cout << "Yes\n";
        for (int i=0; i<n; i++) cout << ans[i] << endl;
    } else cout << "No\n";
}

Measured memory_bytes: 12988
#include <iostream>
#include<sstream>
#include<string>
#include<vector>
#include <cmath>
#include <limits>
#include <queue>
#include<algorithm>
#include<cstring>
#include <cstdlib>
#include <cstdio>
#include <set>
#include <iomanip>
#include <map>
#include <stack>
#include <memory>
#include <numeric>
#include <type_traits>
 
using namespace std;
 
#define rep(i,n) for (int (i)=0;(i)<(n);i++)


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


int main(){
    int n;
    cin >> n;
    long long res;
    long long a[n];
    cin >> a[0] >> a[1];
    res = gcd(a[0],a[1]);
    rep(i,n-2){
        cin >> a[i+2];
        res = gcd(res,a[i+2]);
    }
    cout << res << endl;

    

    
    return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<queue>
#include<stack>
#include<set>
#include<cmath>
#include<iomanip>
#include<functional>
using namespace std;

int INF = 1e9 + 7;

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

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

	ll MIN = 1e12;
	for (ll i = 1; i <= sqrt(n); i++) {
		ll sum = 0;

		if (n % i == 0) {
			ll m = (n / i);
			while (m > 0) {
				m /= 10;
				sum++;
			}

			MIN = min(sum, MIN);
		}
	}
	cout << MIN << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;

const ll MOD = 1e9 + 7;
ll dp[10005][100][2];

int main(){
  string s;
  cin >> s;
  int N = s.size();
  int D;
  cin >> D;

  dp[0][0][0] = 1;
  for(int i = 0; i < N; i++){
    int num = s[i] - '0';
    for(int j = 0; j < D; j++){
      dp[i + 1][(j + num) % D][0] = dp[i][j][0];
    }
    for(int j = 0; j < D; j++){
      for(int k = 0; k < num; k++){
        dp[i + 1][(j + k) % D][1] += dp[i][j][0];
      }
      for(int k = 0; k < 10; k++){
        dp[i + 1][(j + k) % D][1] += dp[i][j][1];
      }
      dp[i + 1][j][0] %= MOD;
      dp[i + 1][j][1] %= MOD;
    }
  }

  /*for(int i = 0; i <= N; i++){
    for(int j = 0; j < D; j++){
      cout << dp[i][j][0] << " ";
    }
    cout << endl;
    for(int j = 0; j < D; j++){
      cout << dp[i][j][1] << " ";
    }
    cout << endl;

  }*/

  cout << (dp[N][0][0] + dp[N][0][1] - 1) % MOD << endl;
  return 0;
}

Measured memory_bytes: 15872
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,m;
  cin >> n >> m;
  vector<int> c(n);
  for(int i=0;i<m;i++){
    int a,b;
    cin >> a >> b;
    c[a-1]++;
    c[b-1]++;
  }
  bool can=true;
  for(int i=0;i<n;i++){
    if(c[i]%2==1){
      can=false;
      break;
    }
  }
  if(can){
    cout << "YES" << endl;
  }
  else{
    cout << "NO" << endl;
  }
}

Measured memory_bytes: 640
while 1:
    co=[0 for i in range(40)]
    r,n=map(int,input().split())
    if r==n==0:
        break
    for i in range(n):
        a,b,h=map(int,input().split())
        a+=20
        b+=20
        for j in range(a,b):
            co[j]=max(co[j],h)
    r_list=[]
    for i in range(r):
        r_list.append((r**2-i**2)**0.5+500)
    r_list=[-9999 for j in range(20-r)]+r_list[::-1]+r_list+[-9999 for j in range(20-r)]
    for i in range(40):
        if co[i]<r_list[i]:
            tmp=r_list[i]
            r_list=list(map(lambda x:x-(tmp-co[i]),r_list))
    print(r_list[20])


Measured memory_bytes: 5680
#include <bits/stdc++.h>
#define ll long long int
#define booga cout << "booga" << endl
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
using namespace std;

void testcase(){

}

int main(int argc, char** argv){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n,cnt{0};
	cin >> n;
	for(int i{0};i < n;i++){
		int term;
		cin >> term;
		if(term != i+1)
			cnt++;
	}
	if(cnt > 2){
		cout << "NO \n";
	}
	else{
		cout << "YES\n";	
	}
	return 0;
}



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


int main(){
	string n;
	cin >> n;
	
	int sum = 0;
	for (int i = 0; i<n.size(); i++){
		sum += int(n[i])-48;
		sum %= 9;
	}

	if (sum == 0){
		cout << "Yes";
	}else{
		cout << "No";
	}

	return 0;
}


Measured memory_bytes: 3724
N, X = gets.chomp.split(" ").map(&:to_i)

def calc(n, d)
  return 1 if n == 0
  return 0 if d == 1
  wk = 2 ** (n+1) - 1
  return 2**n if d == wk
  return 2**(n+1) - 1 if d == 2 * wk - 1
  if wk < d then
    2**n + calc(n-1, d-wk)
  else
    calc(n-1, d-1)
  end
end

puts calc(N, X)


Measured memory_bytes: 1788
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
#define PI 3.14159265359
#define INF 1000100100
#define all(x) (x).begin(),(x).end()
typedef long long ll;
#define P pair<ll, ll>
#define PP pair<P,P>
using namespace std;

int main(){
    int x,y,z,k; cin >> x >> y >> z >> k;
    vector<ll> a(x),b(y),c(z);
    rep(i,x) cin >> a[i];
    rep(i,y) cin >> b[i];
    rep(i,z) cin >> c[i];
    sort(all(a));
    reverse(all(a));
    sort(all(b));
    reverse(all(b));
    sort(all(c));
    reverse(all(c));
    vector<pair<P,int> > check;
    priority_queue<PP> q;
    q.push(PP(P(a[0]+b[0]+c[0],0),P(0,0)));
    while(k){
        ll de=q.top().first.first;
        int aid=q.top().first.second;
        int bid=q.top().second.first;
        int cid=q.top().second.second;
        q.pop();
        bool exi=false;
        rep(i,check.size()){
            if(check[i].first.first==aid && check[i].first.second==bid && check[i].second==cid){
                exi=true;
                break;
            }
        }
        if(exi) continue;
        pair<P,int> g = make_pair(P(aid,bid),cid);
        check.push_back(g);
        cout << de << endl;
        if(aid!=x-1) q.push(PP(P(a[aid+1]+b[bid]+c[cid],aid+1),P(bid,cid)));
        if(bid!=y-1) q.push(PP(P(a[aid]+b[bid+1]+c[cid],aid),P(bid+1,cid)));
        if(cid!=z-1) q.push(PP(P(a[aid]+b[bid]+c[cid+1],aid),P(bid,cid+1)));
        k--;
    }
return 0;
}


Measured memory_bytes: 768
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

public class Main {

      public static void main(String[] args) {

            Scanner sc = new Scanner(System.in);
            int n = sc.nextInt();
            boolean[] isZorome = new boolean[n];
            for (int i = 0;i<n;i++){
                  int d_1 = sc.nextInt();
                  int d_2 = sc.nextInt();
                  isZorome[i] = (d_1 == d_2);
            }
            String ans = "No";
            for (int i = 0;i<n-2;i++){
                  boolean sanren = isZorome[i] && isZorome[i+1] && isZorome[i+2];
                  if (sanren){
                        ans = "Yes";
                  }
            }
            System.out.println(ans);
      }



}



Measured memory_bytes: 36104
lista = []
contador = 0
entrou = 0
nVezes = int(input())
linha = input()
lista = linha.split()
for aux in range(len(lista)):
    for aux2 in range(aux,-1,-1):
        if int(lista[aux]) < int(lista[aux2]):
            entrou = 1
    if entrou == 0:
        contador += 1
    entrou = 0
print(contador)

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

int main () {
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  if(a*b >= c*d){
    cout<<a*b<<endl;
  }
  else{
    cout<<c*d<<endl;
  }
  return 0;
}

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

string a="ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ";
int main(){
  int n;
  string s;
  cin >> n;
  cin >> s;
  for(int i=0;i<s.size();i++){
    for(int j=0;j<26;j++){
      if(s[i]==a[j]){
        s[i]=a[j+n];
        break;
      }
    }
  }
  cout << s << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(obj)   (obj).begin(),(obj).end()

#define debug(var)  do{std::cout << __LINE__ << "> " << #var << ": ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

using namespace std;
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;

void Main() {
	int N; cin >> N;
	vi A(N);
	vvi bit(N, vi(32, 0));
	REP(i, N) {
		cin >> A[i];
		int _a = A[i];
		int idx = 0;
		while (_a) {
			bit[i][idx] = _a % 2;
			_a /= 2;
			++idx;
		}
	}
	// debug(bit);

	REP(i, 32) {
		int sum = 0;
		REP(j, N) {
			sum += bit[j][i];
		}
		if (sum % 2 == 0) continue;

		REP(j, N) {
			bit[j][i] = (bit[j][i] + 1) % 2;
		}
	}

	REP(i, N) {
		ll res = 0ll;
		ll bi = 1;
		REP(j, 32) {
			res += bit[i][j] * bi;
			bi *= 2;
		}
		cout << res;
		if (i == N - 1) {
			cout << endl;
		} else {
			cout << " ";
		}
	}
}

int main() {
    cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
}


Measured memory_bytes: 36684
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1000000000LL;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

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

int main() {
  int h , w;
  cin >> h >> w;
  char grid[h+2][w+2];
  fill(grid[0], grid[h+2], ' ');
  for(int i = 1; i <= h; i++){
    string s; cin >> s;
    for(int j = 1; j <= w; j++){
      grid[i][j] = s[j-1];
    }
  }
  int res[h+2][w+2];
  fill(res[0], res[h+2], 0);
  for(int i = 1; i <= h; i++){
    for(int j = 1; j <= w; j++){
      if(grid[i][j] == '#'){
        res[i][j] = -1;
      } else {
        int cnt = 0;
        rep(k, 8){
          int y = i + dy[k];
          int x = j + dx[k];
          if(grid[y][x] == '#') cnt++;
        }
        res[i][j] = cnt;
      }
    }
  }
   for(int i = 1; i <= h; i++){
    for(int j = 1; j <= w; j++){
      if(res[i][j] == -1) cout << '#';
      else cout << res[i][j];
    }
    cout << ln;
  } 
  
}
  


Measured memory_bytes: 256
#include <stdio.h>

int main()
{
	int h = 1, w = 1, i, j;
	while(1)
	{
		scanf("%d %d", &h, &w);
		if(h == 0 && w == 0)
			break;
		for(j = 1; j <= h; j++)
		{
			for(i = 1; i <= w; i++)
			{
				if(j==1||j==h||i==1||i==w)
				printf("#");
				else
				printf(".");
			}
			printf("\n");
		}
		printf("\n"); 
	}
	return 0;
}


Measured memory_bytes: 2576
def fact(n):
    mmm = 1
    for i in range(1,n+1):
        mmm *= i
    return mmm

N = int(input())
city = []
for i in range(N):
    x,y = map(int,input().split())
    city.append([x,y])

ans = 0
for i in range(N-1):
    for j in range(i+1,N):
        dist = ((city[i][0]-city[j][0])**2 + (city[i][1]-city[j][1])**2)**0.5
        ans += dist*(2*fact(N-1))

print(ans / fact(N))

Measured memory_bytes: 3188
/*---------------------------------

 @Author:   Dicer
 @DateTime: 2019-05-15 19:53:54

---------------------------------*/

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
inline ll qpow(ll a,ll b,ll mod){ll res=1;while(b){if(b&1)res = (res*a)%mod;a=(a*a)%mod;b>>=1;}return res;}
const double eps = 1e-8;
const int INF = 0x3f3f3f3f;
const int mod = 1e9+7;
const int MAXN = 2e5 + 7;

int main(int argc, char const *argv[])
{
	int H, W, h, w;
	cin >> H >> W >> h >> w;
	cout << H*W-(h*W+w*(H-h)) << endl;	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;

struct UnionFind {
  const int n;
  V<> t; // root ? -sz : par
  UnionFind(int n) : n(n), t(n, -1) {}
  int find(int v) { return t[v] < 0 ? v : t[v] = find(t[v]); }
  void unite(int u, int v) {
    if ((u = find(u)) == (v = find(v))) return;
    if (-t[u] < -t[v]) swap(u, v);
    t[u] += t[v];
    t[v] = u;
  }
  bool same(int u, int v) { return find(u) == find(v); }
  int size(int v) { return -t[find(v)]; }
};

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  while (true) {
    int w, h; cin >> w >> h;
    if (!w) break;
    V<string> s(h);
    for (int y = h - 1; y >= 0; --y) cin >> s[y];
    UnionFind uf(w * h);
    auto _ = [&](int x, int y) -> int { return x * h + y; };
    for (int x = 0; x < w; ++x) for (int y = 0; y < h; ++y) if (s[y][x] != '.') {
      if (x + 1 < w and s[y][x] == s[y][x + 1]) uf.unite(_(x, y), _(x + 1, y));
      if (y + 1 < h and s[y][x] == s[y + 1][x]) uf.unite(_(x, y), _(x, y + 1));
    }
    V<> p;
    for (int x = 0; x < w; ++x) for (int y = 0; y < h; ++y) if (s[y][x] != '.') {
      p.push_back(uf.find(_(x, y)));
    }
    sort(begin(p), end(p));
    p.erase(unique(begin(p), end(p)), end(p));
    auto zip = [&](int e) -> int { return lower_bound(begin(p), end(p), e) - begin(p); };
    VV<> a(w, V<>(h, -1));
    for (int x = 0; x < w; ++x) for (int y = 0; y < h; ++y) if (s[y][x] != '.') {
      a[x][y] = zip(uf.find(_(x, y)));
    }
    int n = p.size();
    VV<> ch(n);
    for (int x = 0; x < w; ++x) for (int y = 0; y + 1 < h; ++y) if (a[x][y] >= 0 and a[x][y + 1] >= 0 and a[x][y] != a[x][y + 1]) {
      ch[a[x][y]].push_back(a[x][y + 1]);
    }
    for (auto&& v : ch) {
      sort(begin(v), end(v));
      v.erase(unique(begin(v), end(v)), end(v));
    }
    [&] {
      for (int i = 0; i < n; ++i) {
        set<int> se;
        auto dfs = [&](const auto& dfs, int i) -> void {
          se.insert(i);
          for (int j : ch[i]) dfs(dfs, j);
        };
        dfs(dfs, i);
        double g = 0;
        int c = 0, l = w, r = 0;
        for (int x = 0; x < w; ++x) for (int y = 0; y < h; ++y) if (se.count(a[x][y])) {
          g += x + 0.5;
          ++c;
          if (a[x][y] == i) {
            if (y and (a[x][y - 1] == a[x][y] or a[x][y - 1] == -1)) continue;
            l = min(l, x);
            r = max(r, x + 1);
          }
        }
        g /= c;
        if (g < l + 1e-10 or r - 1e-10 < g) {
          cout << "UNSTABLE" << '\n';
          return;
        }
      }
      cout << "STABLE" << '\n';
    }();
  }
}


Measured memory_bytes: 3112
n = int(input())
lst = []
for i in range(n):
    x,l = map(int,input().split())
    if x-l < 0:
        # [右端の位置,左端の位置]
        lst.append([x+l,0])
    else:
        lst.append([x+l,x-l])
lst.sort()


# [[6, 0], [7, 1], [12, 6], [105, 95]]

# 最初のロボットの選択
now = lst[0][0]
cnt = 1
idx = 1


for i in range(idx,n):
    if now <= lst[i][1]:
        now = lst[i][0]
        cnt += 1
        idx = i + 1
print(cnt)

Measured memory_bytes: 24488
/*
ID:dyx_6661
TASK:
LANG:
*/
#include<cstdio>
#include<cstring>
#include<cmath>
#include<queue>
#include<stack>
#include<algorithm>
#include<deque>
#include<set>
#include<map>
#include<vector>
#include<iostream>
using namespace std;
typedef long long int ll;
typedef double db;
typedef string str;
typedef pair<int,int> pa;
typedef vector<int> vec;

int n;
char s[20];

int main(){
//  freopen(".in","r",stdin);
//  freopen(".out","w",stdout);
    scanf("%d",&n);scanf("%s",s);
    if(n>=3200) printf("%s",s);
    else printf("red");
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#define rep(i, n) for(i = 0; i < n; i++)
using namespace std;

int n;
int m;
int x, y;
int t[9][9];

bool check(int y) {
	int x, cnt = 0;
	rep(x, n) {
		cnt += t[y][x];
	}
	return cnt == 0;
}

void printT() {
	int i, j;
	rep(i, n) {
		rep(j, n) {
			cout << t[i][j] << " ";
		}
		cout << endl;
	}
}

int dfs(int y, int x) {
	//cout << y << ", " << x << endl;
	//printT();
	
	if (y == n) {
		return 1;
	}
	if (x == n) {
		if (!check(y)) return 0;
		return dfs(y + 1, 0);
	}
	if (y == x) {
		return dfs(y, x + 1);
	}
	
	if (t[y][x] != 0) {
		return dfs(y, x + 1);
	}
	
	t[y][x] = 1;
	t[x][y] = -1;
	int res1 = dfs(y, x + 1);
	
	t[y][x] = -1;
	t[x][y] = 1;
	int res2 = dfs(y, x + 1);
	
	t[y][x] = 0;
	t[x][y] = 0;
	return res1 + res2;
}

int main() {
	int i, j;
	
	while (cin >> n) {
		if (!n) break;
		
		rep(i, n) rep(j, n) t[i][j] = 0;
		
		cin >> m;
		rep(i, m) {
			cin >> x >> y;
			x--; y--;
			t[x][y] = 1;
			t[y][x] = -1;
		}
		int res = dfs(0, 0);
		cout << res << endl;
	}
	return 0;
}


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

#define endl '\n'
#define LL long long
#define MP make_pair
#define REP(i, n) for(int i = 0; i < n; ++i)
#define REPR(i, n) for(int i = n - 1; i >= 0; --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 EB emplace_back
#define ST first
#define ND second
#define S size()
#define RS resize

using VI = vector<int>;
using VVI = vector<VI>;
using PI = pair<int, int>;
using VPI = vector<PI>;
using VVPI = vector<VPI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;

int main()
{ 
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    string s, t;
    cin >> s >> t;
    int s1 = s.S, s2 = t.S;
    int dp[s1][s2];
    REP(i, s2)
    {
        if (s[0] == t[i])
        {
            FOR(j, i, s2)
                dp[0][j] = 1;
            break;
        }
        else
            dp[0][i] = 0;
        }
    REP(i, s1)
    {
        if (s[i] == t[0])
        {
            FOR(j, i, s1)
                dp[j][0] = 1;
            break;
        }
        else
            dp[i][0] = 0;
    }
    FOR(i, 1, s1)
        FOR(j, 1, s2)
        {
            if (s[i] != t[j])
                dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
            else
            {
                int a = max(dp[i - 1][j], dp[i][j - 1]);
                dp[i][j] = max(a, dp[i - 1][j - 1] + 1);
            }
        }
    int i = s1 - 1, j = s2 - 1;
    vector<char> podciag;
    while (i >= 0 && j >= 0)
    {
            while (i > 0 && dp[i - 1][j] == dp[i][j])
                i--;
            while (j > 0 && dp[i][j - 1] == dp[i][j])
                j--;
            podciag.EB(s[i]);
                i--;
                j--;
    }
    REPR(k, dp[s1 - 1][s2 - 1])
        cout << podciag[k];
    if (int(podciag.S) == 0)
        cout << ' ';
}

Measured memory_bytes: 35456
#include <iostream>
#include <algorithm>
#include <set>
#include <string>
#include <vector>
#include <cmath>

int main(void){
    int a,b,c,d;
    std::cin >> a >> b >> c >> d;

    if(a+b > c+d){
        std::cout << "Left";
    }
    else if(a+b == c+d){
        std::cout << "Balanced";
    }
    else{
        std::cout << "Right";
    }
    return 0;

}



Measured memory_bytes: 256
#ifdef LOCAL
#define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define reps(i,a,b) for(int i=a;i<b;++i)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
using namespace std;
using ll = long long;
using P = pair<int, int>;
template<typename T> inline bool chmax(T &a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T> inline bool chmin(T &a,T b){if(b<a){a=b;return 1;}return 0;}
template<typename T> vector<T> make_vec(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_vec(size_t a,Ts... ts){return vector<decltype(make_vec<T>(ts...))>(a,make_vec<T>(ts...));}
template<typename T,typename U,typename... V>
typename enable_if<is_same<T,U>::value>::type fill_v(U &u,const V... v){u=U(v...);}
template<typename T,typename U,typename... V>
typename enable_if<!is_same<T,U>::value>::type fill_v(U &u,const V... v){for(auto &e:u)fill_v<T>(e,v...);}

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

    int n, t;
    cin >> n >> t;
    vector<P> ab(n);
    rep(i, n) {
        int a, b;
        cin >> a >> b;
        ab[i] = make_pair(a, b);
    }
    sort(all(ab));
    auto dp = make_vec<int>(n+1, t);
    rep(i, n) {
        int a = ab[i].fi, b = ab[i].se;
        rep(j, t) {
            chmax(dp[i+1][j], dp[i][j]);
            if (j != 0) chmax(dp[i+1][j], dp[i+1][j-1]);
            if (j+a < t) chmax(dp[i+1][j+a], dp[i][j] + b);
        }
    }
    int ans = 0;
    rep(i, n) {
        chmax(ans, dp[i][t-1] + ab[i].se);
    }
    cout << ans << endl;
}


Measured memory_bytes: 35584
a, b = input().split()
A = int(a)
Bn,Bs = map(int, b.split('.'))

C1 = A * Bn

abs = str(A * Bs)
if A * Bs > 99:
    C2 = int(abs[:-2])
else:
    C2 = 0
print(C1+C2)


Measured memory_bytes: 9136
from collections import deque
N = int(input())
S = [list(map(int, input().strip())) for _ in range(N)]
G = [[] for _ in range(N)]
for i in range(N):
    for j in range(N):
        if S[i][j] == 1:
            G[i].append(j)

#Bipartie Graph
def is_bibarate(G):
    vst = [False] * N
    que = deque([0])
    color = [0] * N
    color[0] = 1
    while len(que):
        p = que.popleft()
        for q in list(G[p]):
            if color[q] == 0:
                color[q] = - color[p]
                que.append(q)
            elif color[q] == color[p]:
                return False
            
    return True
                

        
#Warshal Floyd        
d = [[float('inf')] * N for _ in range(N)]
for i in range(N):
    for j in range(N):
        if i == j:
            d[i][j] = 0
        elif S[i][j] == 1:
            d[i][j] = 1
            
for k in range(N):
    for i in range(N):
        for j in range(N):
            d[i][j] = min(d[i][j],d[i][k] + d[k][j])

wf_ans = max([max(r) for r in d]) + 1

if is_bibarate(G):
    print(wf_ans)
else:
    print(-1)

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

typedef long long LL;
const int N = 205;

string s;
int t, n, a[N];
LL f[N][11][5], ans;

int main() {
	cin>>s>>t;
	n = s.size();
	for(int i = 1; i <= n; i++)
	   a[i] = s[i - 1] - '0';
	if(n == 1) {
		if(a[1] && t == 1) cout<<a[1]<<endl;
		else cout<<0<<endl;
		return 0;
	}
	f[1][0][0] = 1;
	for(int i = 1; i <= 9; i++)
	   f[1][i][1] = 1;
	for(int i = 2; i <= n; i++)
	   for(int j = 0; j <= 9; j++)
	      for(int k = 0; k <= 9; k++) {
	      	int cnt = (j != 0) + (k != 0);
	      	for(int p = cnt; p <= t; p++)
	      	   f[i][j][p] += f[i - 1][k][p - (j != 0)];
	      }
	for(int i = 1; i < n; i++)
	   for(int j = 1; j <= 9; j++)
	      ans += f[i][j][t];
	for(int i = 1; i < a[1]; i++)
	   ans += f[n][i][t];
	int res = t - 1;
	for(int i = 2; i <= n; i++) {
		if(res == -1) break;
		if(res != 0)
		for(int j = 0; j < a[i]; j++)
		   ans += f[n - i + 1][j][res];
		else if (a[i] != 0)
		   ans += f[n - i + 1][0][res];
		if(i == n) {
			if(res == 0 && a[i] == 0) ans += f[1][a[i]][res];
			if(res == 1 && a[i] != 0) ans += f[1][a[i]][res];
		} 
		if(a[i]) res--;
	}
	cout<<ans<<endl;
}


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
using llint = long long;
using vint = vector<int>;

int main () {
    int n, a, b; cin >> n >> a >> b;
    if (n * a < b) cout << n * a << endl;
    else cout << b << endl;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)
#define ALL(x) x.begin(), x.end()
#define INF (1001000000)
#define SZ(a) int((a).size())
#define EACH(i,c) for(auto i:c)
#define EXIST(cs,v) (find(ALL(cs),(v))!=cs.end())
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())
#define UNIQ(c) (c).erase(unique((c).begin(),(c).end()), (c).end());
#define P(p) cout<<(p)<<endl;

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

    int n;
    cin >> n;
    map<int, int> odd, even;
    FOR(i, 1, n+1) {
        int input;
        cin >> input;
        if (i % 2 == 0 ) {
            even[input] += 1;
        }
        else {
            odd[input] += 1;
        }
    }

    // odd
    int odd_max = 0;
    int odd_second = 0;
    int odd_max_key = 0;
    int odd_second_key = 0;
    EACH(x, odd) {
        if (odd_max <= x.second) {
            odd_second = odd_max;
            odd_second_key = odd_max_key;
            odd_max_key = x.first;
            odd_max = x.second;
        }
    }
    EACH(x, odd) {
        if (odd_second <= x.second && x.first != odd_max_key) {
            odd_second_key = x.first;
            odd_second = x.second;
        }
    }

    // even
    int even_max = 0;
    int even_max_key = 0;
    int even_second = 0;
    int even_second_key = 0;
    EACH(x, even) {
        if (even_max <= x.second) {
            even_second = even_max;
            even_second_key = even_max_key;
            even_max_key = x.first;
            even_max = x.second;
        }
    }
    EACH(x, even) {
        if (even_second <= x.second && x.first != even_max_key) {
            even_second_key = x.first;
            even_second = x.second;
        }
    }

    // if the keys are the same.
    // use the second highest.
    int ans = 0;
    if (odd_max_key == even_max_key) {
        ans = min(n - odd_max - even_second, n - odd_second - even_max);
    }
    else {
        ans = n - even_max - odd_max;
    }
    P(ans);

    return 0;
}


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

int main(void){
    int s,w;
    scanf("%d",&s);
    if(1>s || s>100){
        while(1>s || s>100){
            scanf("%d",&s);
        }
    }
    scanf("%d",&w);
    if(1>w || w>100){
        while(1>w || w>100){
            scanf("%d",&w);
        }
    }
    if(s>w){
        printf("safe\n");
    }else{
        printf("unsafe\n");
    }
}


Measured memory_bytes: 1628
#include<bits/stdc++.h>
using namespace std;
const int N=3e5+10;
const int mod=1e9+7;
typedef vector<int> vi;
#define pb push_back

int prd[N],iprd[N],inv[N],n,col[N],m,p[N],val[N],sum,ans,f[N][2];
bool vis[N];

void access(int x,bool op) {
	while(x) vis[x]=op,x>>=1;
}

void dfs(int u,int c) {
	if(u>m) {
		col[p[u]]=c;
		val[p[u]]=1ll*prd[p[u]]*prd[u]%mod;
		access(p[u],1);
		return;
	}
	dfs(u<<1,c);
	dfs(u<<1|1,c);
}

void clear(int u) {
	if(u>m) {
		access(p[u],0);
		return;
	}
	clear(u<<1);
	clear(u<<1|1);
}

void dfs2(int u) {
	f[u][0]=f[u][1]=0;
	if(!vis[u]) return;
	if(u>m) {
		f[u][col[u]]=val[u];
		return;
	}
	dfs2(u<<1);
	dfs2(u<<1|1);
	int tmp=(1ll*f[u<<1][0]*f[u<<1|1][1]+1ll*f[u<<1][1]*f[u<<1|1][0])%mod;
	sum=(sum+1ll*tmp*iprd[u]%mod*iprd[u>>1])%mod;
	f[u][0]=(f[u<<1][0]+f[u<<1|1][0])%mod;
	f[u][1]=(f[u<<1][1]+f[u<<1|1][1])%mod;
}

int main() {
	ios::sync_with_stdio(0);cin.tie(0);
	cin>>n;n=(1<<n)-1;m=n/2;
	for(int i=m+1;i<=n;i++) cin>>p[i],p[i]+=m;
	inv[1]=1;for(int i=2;i<=n;i++) inv[i]=1ll*(mod-mod/i)*inv[mod%i]%mod;
	prd[0]=iprd[0]=1;
	for(int i=1;i<=n;i++) {
		prd[i]=1ll*prd[i>>1]*i%mod;
		iprd[i]=1ll*iprd[i>>1]*inv[i]%mod;
	}
	for(int i=1;i<=m;i++) {
		dfs(i<<1,0);
		dfs(i<<1|1,1);
		sum=0;dfs2(1);
		ans=(ans+1ll*sum*iprd[i]%mod*iprd[i>>1])%mod;
		clear(i);
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 10556
// Last Change: 04/07/2019 17:31:47.
#include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;
using ll = long long;

namespace NS {
void LoopUntilZeroInpput() {
  int hogegegege = 0;
  while (cin >> hogegegege && hogegegege != 0) {
  }
}
} // namespace NS

int main() {
  ll N, M, Q;
  cin >> N >> M >> Q;

  vector<vector<ll>> station(N + 1, vector<ll>(N + 1, 0));
  ll l, r;
  for (ll i = 0; i < M; ++i) {
    cin >> l >> r;
    ++station[l][r];
  }

  //直接stationで計算してもいい。その場合station[i][j]+=station[i-1][j]...
  vector<vector<ll>> cumSum(N + 1, vector<ll>(N + 1, 0));
  for (ll i = 1; i < N + 1; ++i) {
    for (ll j = 1; j < N + 1; ++j) {
      cumSum[i][j] = cumSum[i - 1][j] + cumSum[i][j - 1] - cumSum[i - 1][j - 1]
                     + station[i][j];
    }
  }

  for (ll i = 0; i < Q; ++i) {
    cin >> l >> r;
    ll ans = cumSum[r][r] - cumSum[r][l - 1] - cumSum[l - 1][r]
             + cumSum[l - 1][l - 1];
    cout << ans << endl;
  }

  //NS::LoopUntilZeroInpput();
}


Measured memory_bytes: 4864
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>

#include <map>

#define Min(a,b) ((a)<(b)?(a):(b))
#define Max(a,b) ((a)>(b)?(a):(b))
#define Mabs(a,b) ((a)>(b)?(a)-(b):(b)-(a))
#define Abs(a) (a)>0?(a):(-(a))
template <typename QvQ> inline QvQ Min2(QvQ a,QvQ b){if(a<b) return a;return b;}
template <typename QvQ> inline QvQ Max2(QvQ a,QvQ b){if(a>b) return a;return b;}
template <typename QvQ> inline QvQ Abs2(QvQ a){if(a>0) return a;return -a;}

#define n1kw 10000000
#define inf 0x7f7f7f7f
#define dinf 0x3f3f3f3f
#define llinf 0x7f7f7f7f7f7f7f7f
#define lldinf 0x3f3f3f3f3f3f3f3f

#define ll long long
#define rei register int
#define inv inline void
#define inb inline bool
#define ini inline int

#define bl putchar(' ')
#define ed putchar('\n')
#define test std::cout<<"this:"
#define card system("pause")

#define read2(a,b) read(a),read(b)
#define write2(a,b) write(a),bl,write(b)
#define read3(a,b,c) read(a),read(b),read(c)
#define write3(a,b,c) write(a),bl,write(b),bl,write(c)

//char buf[1<<23],*p1=buf,*p2=buf,obuf[1<<23],*O=obuf;
//#define getchar() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)

template <typename QvQ>inv read(QvQ &x)
{
	x=0;int f=1;
	char c=getchar();
	for(;c<'0'||c>'9';c=getchar()) if(c=='-') f=-1;
	for(;c>='0'&&c<='9';c=getchar()) x=(x<<1)+(x<<3)+(c^48);
	x=x*f;
}
template <typename QvQ>inv write(QvQ x)
{
	if(x<0) x=-x,putchar('-');
	if(x>9) write(x/10);
	putchar(x%10+48);
}
using namespace std;
#define MAXN 100005
#define MAXM 200005
int n;
char a[MAXN][11];
map <string,int> vis;
int main()
{
	read(n); ll ans=0;
	for(rei i=1;i<=n;++i) cin>>a[i];
	for(rei i=1;i<=n;++i)
	{
		sort(a[i],a[i]+10);
		ans+=vis[a[i]]++;
	}
	write(ans);
	return 0;
}

Measured memory_bytes: 12288