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

using namespace std;

const long long MOD = 1000000007;

long long factorial(long long n) {
    long long ret = 1;
    for (long long i = 2; i <= n; ++i) {
        ret *= i;
        ret %= MOD;
    }
    return ret;
}

long long modPow(long long n, long long p) {
    if (p == 0) {
        return 1;
    }
    else if (p % 2 == 0) {
        long long x = modPow(n, p / 2);
        return x * x % MOD;
    }
    else {
        long long x = modPow(n, p / 2);
        return ((x * x % MOD) * n) % MOD;
    }
}

void Main() {
    long long X, Y;
    cin >> X >> Y;

    if ((X + Y) % 3 != 0) {
        cout << 0 << endl;
        return;
    }
    long long generation = (X + Y) / 3;
    if (!(generation <= X && X <= 2 * generation && generation <= Y && Y <= 2 * generation)) {
        cout << 0 << endl;
        return;
    }

    // gen C (X - gen)
    // = gen! / ((X - gen)! * (2 * gen - X)!
    long long fgen = factorial(generation);
    long long fXmgen = factorial(X - generation);
    long long f2genmX = factorial(2 * generation - X);

    long long ans = fgen * modPow(fXmgen, MOD - 2);
    ans %= MOD;
    ans *= modPow(f2genmX, MOD - 2);
    ans %= MOD;
    cout << ans << endl;
}

int main() {
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 3612
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main(void){
    string S, T;
    cin >> S >> T;

    set<char> sts, stt;
    for(int i = 0; i < S.length(); i++){
        sts.insert(S[i]);
    }
    for(int i = 0; i < T.length(); i++){
        stt.insert(T[i]);
    }

    if(stt != sts){
        cout << "No" << endl;
        return 0;
    }

    bool isRotate = false;
    for(int j = 0; j < S.length(); j++){

        if(S == T){
            isRotate = true;
        }

        char head = S.front();
        S.erase(0,1);
        S.push_back(head);

    }

    if(isRotate) cout << "Yes" << endl;
    else  cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 256
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <queue>
#include <utility>
#include <vector>
using namespace std;

const int MAX_LEN = 6;
const int MAX_N = 40;
const int LIMIT = MAX_LEN * MAX_N;
const string INF(LIMIT, 'z');

struct edge {
	int to;
	string cost;
	edge(int t, const string& c):to(t), cost(c){}
};

bool to_goal[MAX_N];
vector<vector<edge> > es;

string dijkstra(int s, int g) {
	typedef pair<string, int> P;
	const int n = es.size();
	vector<vector<string> > dist(n, vector<string>(LIMIT + MAX_LEN + 1, INF));
	dist[s][0] = "";
	priority_queue<P, vector<P>, greater<P> > que;
	que.push(make_pair("", s));

	while(!que.empty()) {
		const string spell = que.top().first;
		const int v = que.top().second, len = spell.size();
		que.pop();

		if(!to_goal[v] || dist[v][len] != spell)
			continue;

		if(len > LIMIT)
			return "NO";

		if(v == g)
			return spell;

		for(int i = 0; i < es[v].size(); ++i) {
			const edge& e = es[v][i];
			const string next_spell = spell + e.cost;
			const int next_len = next_spell.size();
			if(dist[e.to][next_len] > next_spell) {
				dist[e.to][next_len] = next_spell;
				que.push(make_pair(next_spell, e.to));
			}
		}
	}

	return "NO";
}

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

	for(int n, a, s, g; cin >> n >> a >> s >> g, n;) {
		es.clear();
		es.resize(n);
		for(int i = 0; i < a; ++i) {
			int x, y;
			string lab;
			cin >> x >> y >> lab;
			es[x].push_back(edge(y, lab));
		}

		memset(to_goal, false, sizeof(to_goal));
		to_goal[g] = true;
		for(int i = 0; i < n; ++i)
			for(int j = 0; j < n; ++j)
				for(int k = 0; k < (int)es[j].size(); ++k)
					if(to_goal[es[j][k].to])
						to_goal[j] = true;

		cout << dijkstra(s, g) << endl;
	}

	return EXIT_SUCCESS;
}

Measured memory_bytes: 5416
while True :
    n = int(input())
    if n == 0 :
        break
    
    S = 1
    for i in range(n) :
        S *= (i+1)
    
    ans = 0
    while True :
        if S % 10 != 0 :
            break
        else :
            S = S // 10
            ans += 1
    print(ans)


Measured memory_bytes: 5624
import java.util.Scanner;
class Main
{
  public static void main(String args[])
  {
    Scanner sc=new Scanner(System.in);
    int a,b,c;
    a=sc.nextInt();
    b=sc.nextInt();
    c=sc.nextInt();
    System.out.println(c+" "+a+" "+b);
  }
};


Measured memory_bytes: 21844
#include <iostream>

using namespace std;

int main()
{
    int a;
    int b;
    cin>>a;
    cin>>b;
    if(a<b) cout<<"a < b"<<endl;
    else
        if(a>b) cout<<"a > b"<<endl;
    else
        if(a==b) cout<<"a == b"<<endl;
    return 0;
}




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

typedef long long ll;
typedef pair<int,int> P;
typedef map<int,int> M;
typedef vector<int> V;
typedef queue<int> Q;
typedef pair<long,long> PLL;
typedef map<long,long> MLL;
typedef vector<long long> VLL;
typedef vector<pair<int,int>> VP;
typedef vector<vector<int>> VV;
#define INF (int)(1e9+1)
#define MAXX (int)1.1529215e+18
#define inf 999999
#define EPS (1e-7)
#define MOD (ll)(1e9+7)
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define REP(i,n) for(int i=1;i<=(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n-1);i>=0;i--)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define ALL(a)  a.begin(),a.end()
#define RALL(a) a.begin(),a.end(),greater<int>()
#define PRALL(a) a.begin(),a.end(),greater<pair<int,int>>()
#define ROT(a) a.begin(),a.begin()+1,a.end()
#define RROT(a) a.begin(),a.end()-1,a.end()
#define PB push_back
#define MP make_pair
#define PI acos(-1.0)
//printf("myco\n");//for debug
/*--------------------------------------------*/
int main(){
    int n,d;cin>>n>>d;
    int ans=ceil(n/(double)(2*d+1));
    cout<<ans<<endl;
}


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

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

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

int main(void) {
    LL A, B, C, K;
    cin >> A >> B >> C >> K;
    
    LL ans = 0;
    if (K <= A) {
        ans = K;
    } else if (K <= A + B) {
        ans = A;
    } else {
        ans = A - (K - (A + B));
    }

    cout << ans << endl;
}


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

# define C continue;
# define R return

# define D double
# define I insert
# define ll long long
# define ld long double

# define ull unsigned long long
# define ui unsigned int

# define pb push_back
# define pf push_front

# define vi vector < int >
# define vc vector < char >
# define vs vector < string >
# define vb vector < bool >
# define vd vector < D >
# define vll vector < ll >
# define vull vector < ull >
# define vld vector < ld >
# define PQ priority_queue

# define vvi vector < vector < int > >
# define vvb vector < vector < bool > >
# define vvc vector < vector < char > >
# define vvs vector < vs >
# define vvll vector < vector < ll > >
# define vvd vector < vector < D > >
# define vvld vector < vector < ld > >

# define all(v) (v).begin() , (v).end()
# define allrev(v) (v).rbegin() , (v).rend()
# define allcomp(v) v.begin() , v.end() , comp
# define allrevcomp(v) v.rbegin() , v.rend() , comp

# define pii pair < int , int >
# define pll pair < ll , ll >
# define pld pair < ld , ld >
# define pDD pair < D , D >

# define vpld vector < pld >
# define vpii vector < pii >
# define vpll vector < pll >
# define vpDD vector < pDD >

# define vvpii vector < vector < pii > >
# define F first
# define S second
# define mp make_pair

# define dist(a,b,p,q) sqrt((p-a)*(p-a) + (q-b)*(q-b))

# define pp(n) printf("%.10Lf",n);
# define line cout<<"\n";
# define fast ios_base::sync_with_stdio(false) ; cin.tie(0) ; cout.tie(0);

string vow = "aeiou";
int month[] = {-1, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

const int dxhorse[] = {-2, -2, -1, -1, 1, 1, 2, 2};
const int dyhorse[] = {1, -1, 2, -2, 2, -2, 1, -1};

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

const ld pie = 3.1415926535897932384626 ;
const ll mod = 1e9 + 7 ;

/// Tip : If a and b are positive integers ; we may say - ceil (a/b) = 1 + floor ( (a-1)/b ) .

void solve ( int test_case )
{
    int n ;
    cin >> n ;

    int r ; cin >> r ;

    if ( n >= 10 )
    {
        cout << r ;
        line ; R ;
    }

    int ans = r + 100 * ( 10 - n ) ;
    cout << ans ; line ;
}

int main()
{
    int t = 1;
    // cin >> t;

    for ( int i=1 ; i <= t ; i ++ ) solve ( i ) ;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const ll mod = 1000000007;
const int INF = 1001001001;
const ll LINF = 1001001001001001001;

int main(){
    ld n; cin >> n;
    ld hen = n/3.0;
    ld ans = hen*hen*hen;
    cout <<setprecision(15) <<  ans << endl;    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;

#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(ll i=(n)-1;i>=0;i--)
#define range(i,a,n) for(ll i=(a);i<(n);i++)

#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI 3.1415926535897932384

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

template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S acm(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
void YN(bool b){cout<<(b?"YES":"NO")<<"\n";}
void Yn(bool b){cout<<(b?"Yes":"No")<<"\n";}
void yn(bool b){cout<<(b?"yes":"no")<<"\n";}
int sgn(const double&r){return (r>EPS)-(r<-EPS);} // a>0  : sgn(a)>0
int sgn(const double&a,const double&b){return sgn(a-b);} // b<=c : sgn(b,c)<=0

ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s;a=0;} return os;}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n;
	cin>>n;
	set<string> st;
	rep(i,n){
		string s;
		cin>>s;
		st.insert(s);
	}
	cout<<st.size()<<endl;
}


Measured memory_bytes: 19188
#include <bits/stdc++.h>
#define rep(i, n) for (lli i = 0; i < (n); i++)
#define rrep(i, n) for (lli i = (n)-1; i >= 0; i--)
using namespace std;
using lli = long long int;
void YESNO(bool), YesNo(bool);
template <class T1, class T2>
bool chmin(T1 &l, const T2 &r);
template <class T1, class T2>
bool chmax(T1 &l, const T2 &r);
void dfs(int u, int p, int depth, vector<lli> &dist, const vector<vector<int>> &e)
{
  dist[u] = depth;
  for (auto s : e[u])
  {
    if (s == p)
      continue;
    dfs(s, u, depth + 1, dist, e);
  }
}
vector<lli> dist(vector<vector<int>> &e, int u)
{
  int N = e.size();
  vector<lli> v(N, -1);
  dfs(u, -1, 0, v, e);
  return v;
}
void solve(long long N, long long u, long long v, std::vector<long long> A,
           std::vector<long long> B)
{
  vector<vector<int>> e(N);
  u--, v--;
  rep(i, N - 1) A[i]--, B[i]--;
  rep(i, N - 1) e[A[i]].push_back(B[i]), e[B[i]].push_back(A[i]);
  auto u_dist = dist(e, u);
  auto v_dist = dist(e, v);
  vector<bool> ok(N);
  //  rep(i, N) cout << u_dist[i] << " " << v_dist[i] << endl;
  rep(i, N) ok[i] = u_dist[i] < v_dist[i];

  vector<vector<int>> e_sub(N);
  rep(i, N - 1) if (ok[A[i]] && ok[B[i]]) e_sub[A[i]].push_back(B[i]), e_sub[B[i]].push_back(A[i]);
  auto u_sub_dist = dist(e_sub, u);
  lli ans = 0;
  lli dst = 0;
  lli cnt = 0;
  rep(i, N)
  {
    if (u_sub_dist[i] >= 0)
    {
      cnt++;
    }
  }
  cerr << cnt << endl;
  if (cnt == 1)
  {
    // 1 or 0
    cout << (e[u][0] == v ? 0 : 1) << endl;
    return;
  }
  rep(i, N)
  {
    // cerr << "#"
    //      << " " << i << " " << v_dist[i] << endl;
    if (u_sub_dist[i] >= 0)
    {
      chmax(ans, v_dist[i] - 1);
      // v_dist[i]に死ぬ
      // v_dist[i]-1で死ぬか?
      // u_dist[i]についてu_dist[i]+1,+3,+5では一つ前にいる
    }
  }
  cout << ans << endl;
}

signed main()
{
  long long N;
  scanf("%lld", &N);
  long long u;
  scanf("%lld", &u);
  long long v;
  scanf("%lld", &v);
  std::vector<long long> A(N - 1);
  std::vector<long long> B(N - 1);
  for (int i = 0; i < N - 1; i++)
  {
    scanf("%lld", &A[i]);
    scanf("%lld", &B[i]);
  }
  solve(N, u, v, std::move(A), std::move(B));
  return 0;
}

// -- lib
void YESNO(bool b) { cout << (b ? "YES" : "NO") << endl; }
void YesNo(bool b) { cout << (b ? "Yes" : "No") << endl; }

template <class T1, class T2>
bool chmin(T1 &l, const T2 &r)
{
  return (l > r) ? (l = r, true) : false;
}

template <class T1, class T2>
bool chmax(T1 &l, const T2 &r)
{
  return (l < r) ? (l = r, true) : false;
}


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

using namespace std;

#define LL long long
#define Re register
#define U unsigned
#define forn(i,a,b) for(Re int i = a;i <= b;++i)
#define nfor(i,a,b) for(Re int i = a;i >= b;--i)
#define CLR(i,a) memset(i,a,sizeof(i))
#define BR printf("--------------------\n")
#define pb push_back
#define Rep(i,a,b) for(int i=a;i<=b;i++)
#define DEBUG(x) std::cerr << #x << '=' << x << std::endl
const double PI=atan(1.)*4.;
const int maxn=1e6+5;
const int inf = 0x3f3f3f3f;
const int mod=1e9+7;
const double e=2.71828182845904523536;
int dir[4][2]={1,0,0,1,-1,0,0,-1};
int a[maxn];
int main()
{
	ios::sync_with_stdio(false);
    cin.tie(0);
   	cout.tie(0);
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }
    int ans=0;
    for(int i=1;i<=n-2;i++)
    {
        if(a[i]>min(a[i-1],a[i+1])&&a[i]<max(a[i-1],a[i+1]))
            ans++;
    }
    cout<<ans;
	return 0;
}


Measured memory_bytes: 256
# Fast IO (only use in integer input)

import os,io
input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline

# Fenwick Tree to Calculate Sum

N,Q = map(int,input().split())

MaxLength = N
FenwickTree = []

CurLen = MaxLength
while CurLen != 0:
    FenwickTree.append([0] * CurLen)
    CurLen //= 2

Depth = len(FenwickTree)

def addElem(n,index): # add n to an element in index
    for j in range(Depth):
        if index < len(FenwickTree[j]):
            FenwickTree[j][index] += n
        index //= 2

def firstNSum(n): # Return the sum of the first n elements (0 to n-1)
    nCpy = n
    summ = 0
    depthCur = 0
    while nCpy != 0:
        if nCpy % 2 != 0:
            summ += FenwickTree[depthCur][nCpy - 1]
        nCpy //= 2
        depthCur += 1
    return summ

c = list(map(int,input().split()))
firstLocColor = [-1] * N
ans = [-1] * Q
queries = []
for i in range(Q):
    l,r = map(int,input().split())
    queries.append((l,r,i))
queries.sort(key = lambda x: x[1])
queryIndex = 0
for i in range(N):
    # Update the Fenwick tree to count ith element
    if firstLocColor[c[i] - 1] == -1:
        addElem(1,i)
        firstLocColor[c[i] - 1] = i
    else:
        addElem(-1,firstLocColor[c[i] - 1])
        addElem(1,i)
        firstLocColor[c[i] - 1] = i
    
    # get query
    while queryIndex < Q and queries[queryIndex][1] - 1 <= i:
        if queries[queryIndex][1] - 1 == i:
            ans[queries[queryIndex][2]] = firstNSum(queries[queryIndex][1]) - firstNSum(queries[queryIndex][0] - 1)
        queryIndex += 1

for elem in ans:
    print(elem)

Measured memory_bytes: 193472
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder.Abc
{
    public class QuestionA
    {
        public static void Main(string[] args)
        {
            // 整数配列の入力
            var inputLongArray = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();

            if(inputLongArray[1] % inputLongArray[0] == 0) {
                Console.WriteLine(inputLongArray[0] + inputLongArray[1]);
            } else {
                Console.WriteLine(inputLongArray[1] - inputLongArray[0]);

            }

        }
    }
}

Measured memory_bytes: 13268
import collections
n=int(input())
s=[]
for i in range(n):
  S=input()
  s.append(S)
d=collections.Counter(s)
e=list(d.items())
e.sort(key=lambda x:-x[1])
lst=[]
for i in range(len(e)):
  if e[i][1]==e[0][1]:
    lst.append(e[i][0])
  else:
    break
lst.sort()
for j in range(len(lst)):
  print(lst[j])




Measured memory_bytes: 47636
#include <iostream>
#include <cstdio>
#include <queue>
#define REP(i,n) for(int i=0; i<(int)(n); i++)

typedef long long ll;

using namespace std;

vector<int> times[50][50];

char g[50][60];
int w,h,m;
int tx[1000];
int ty[1000];

int cont[50][50];
int on[50][50];
int off[50][50];

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

bool move(int x1, int y1, int x2, int y2, int t, int px = -1, int py = -1){
  if(x1 == x2 && y1 == y2){
    if(times[y1][x1].empty() || times[y1][x1].back() != t)
      times[y1][x1].push_back(t);
    return true;
  }

  REP(i,4){
    int xx = x1 + dx[i];
    int yy = y1 + dy[i];

    if(xx <  0) continue;
    if(yy <  0) continue;
    if(xx >= w) continue;
    if(yy >= h) continue;
    if(xx == px && yy == py) continue;
    if(g[yy][xx] == '#') continue;

    if(move(xx, yy, x2, y2, t + 1, x1, y1)){
      if(times[y1][x1].empty() || times[y1][x1].back() != t)
	times[y1][x1].push_back(t);
      return true;
    }
  }

  return false;
}

int main(){
  scanf("%d%d%d", &h, &w, &m);
  REP(i,h) scanf("%s", g[i]);
  REP(i,h) REP(j,w) scanf("%d", &cont[i][j]);
  REP(i,h) REP(j,w) scanf("%d", &on[i][j]);
  REP(i,h) REP(j,w) scanf("%d", &off[i][j]);

  REP(i,m) scanf("%d%d", ty+i, tx+i);

  times[ty[0]][tx[0]].push_back(0);
  REP(i,m - 1){
    move(tx[i], ty[i], tx[i+1], ty[i+1], times[ty[i]][tx[i]].back());
  }

  ll ans = 0;

  REP(i,h) REP(j,w){
    int n = times[i][j].size();
    if(n != 0) ans += on[i][j] + off[i][j];

    REP(k, n - 1){
      int duration = times[i][j][k+1] - times[i][j][k];
      ans += min(duration * cont[i][j], on[i][j] + off[i][j]);
    }
  }

  cout << ans << endl;

  return 0;
}

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

using namespace std;
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
#define REP(i,n) for(ll i = 0;i < (ll)n;i++)
#define REPD(i,n) for(ll i = (ll)n - 1;i >= 0;i--)
#define ALL(x) (x).begin(),(x).end()
#define FILLl(n,first_dimension_size,value) fill((ll*)n,(ll*)(n+first_dimension_size),value)
#define FILL(n,first_dimension_size,value) fill((int*)n,(int*)(n+first_dimension_size),value)
#define INF (1 << 29)
#define MOD 1000000007
//int dx[4] = {1,0,0,-1};
//int dy[4] = {0,1,-1,0};




int main(){
  
  int n;
  cin >> n;
  vector<int> v(n),w;
  REP(i,n)cin >> v[i];
  w = v;
  sort(ALL(w));
  int lm = w[(n-2)/2],rm = w[n/2];
  for(int i = 0;i < n;i++){
    if(v[i] <= lm)cout << rm << endl;
    else cout << lm << endl;
  }




  


  return 0;
}


Measured memory_bytes: 3712
eval"_,*A="+gets.split*?,
s=*$<
q=[]
f=->i{s[i]&.chop&.bytes{|x|A[x-65]>0&&(q<<(y=s[i].sum-x-10).chr;A[x-65]-=1;A[y-65]+=1;f[i+1];A[x-65]+=1;A[y-65]-=1;q.pop)}||puts(:Yes,q)+exit}
f[0]
puts :No

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

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

int main(){
// experiment
/*
	bool win[50][50][50]={};
	int n=30;
	rep(i,n) rep(j,n) rep(k,n) {
		if(i>0 && !win[i-1][j][k]) win[i][j][k]=true;
		if(j>0 && !win[i][j-1][k]) win[i][j][k]=true;
		if(k>0 && !win[i][j][k-1]) win[i][j][k]=true;
		if(i>0 && j>0 && !win[i-1][j-1][k]) win[i][j][k]=true;
		if(i>0 && k>0 && !win[i-1][j][k-1]) win[i][j][k]=true;
		if(j>0 && k>0 && !win[i][j-1][k-1]) win[i][j][k]=true;
		if(i>0 && j>0 && k>0 && !win[i-1][j-1][k-1]) win[i][j][k]=true;
	}
*/

	int n; scanf("%d",&n);
	bool win=false;
	rep(i,n){ int a; scanf("%d",&a); win|=(a%2==1); }
	puts(win?"first":"second");

	return 0;
}


Measured memory_bytes: 256
// AOJ 0622: Walking in JOI Kingdom
// 2017.10.29 bal4u@uu

#include <stdio.h>
#include <stdlib.h>

#define MIN(a,b) ((a)<=(b)?(a):(b))
#define MAX(a,b) ((a)>=(b)?(a):(b))

#define EAST 0		// dir
#define WEST 1
typedef struct { long long a, t; char dir; } T;
T tbl[100010];

char buf[105], *p;
int getint()
{
	int n = 0;
	while (*p >= '0') n = (n<<3) + (n<<1) + (*p++ & 0xf);
	return n;
}

long long getlonglong()
{
	long long n = 0;
	while (*p >= '0') n = (n<<3) + (n<<1) + (*p++ & 0xf);
	return n;
}

int main()
{
	int n, q, i, j;
	long long t, x, ans;

	fgets(p=buf, 100, stdin);
	n = getint(), p++, t = getlonglong(), p++, q = getint();
	x = 1LL << 62, tbl[0].a = -x, tbl[0].dir = EAST;
	for (i = 1; i <= n; i++) {
		fgets(p=buf, 100, stdin);
		if (*p == '-') p++, tbl[i].a = -getlonglong();
		else                tbl[i].a =  getlonglong();
		p++, tbl[i].dir = (*p == '2');
	}
	tbl[i].a = 1LL << 62, tbl[i].dir = WEST;

	for (i = 0; i <= n; i++) {
		if (tbl[i].dir == EAST && tbl[i+1].dir == WEST) {
			x = (tbl[i].a + tbl[i+1].a) >> 1;
			for (j = i; j >= 0; j--) {
				if (tbl[j].dir == EAST) tbl[j].t = x;
				else break;
			}
			for (j = i+1; j <= n+1; j++) {
				if (tbl[j].dir == WEST) tbl[j].t = x;
				else break;
			}
		}
	}

	while (q--) {
		fgets(p=buf, 30, stdin);
		x = getlonglong();
		if (tbl[x].dir == EAST) ans = MIN(tbl[x].a + t, tbl[x].t);
		else                    ans = MAX(tbl[x].a - t, tbl[x].t);
		printf("%lld\n", ans);
	}
	return 0;
}

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

int main() {
	cin.tie(0)->sync_with_stdio(false);

	ll a, b, c, d; cin >> a >> b >> c >> d;
	ll res = LONG_MIN;
	res = max(res, a * c);
	res = max(res, a * d);
	res = max(res, b * c);
	res = max(res, b * d);
	cout << res << '\n';
	return 0;
}

Measured memory_bytes: 3648
import java.util.Scanner;

public class Main
{
    public static void main(String[] args)
    {
        Scanner cin = new Scanner(System.in);
        int n = Integer.parseInt(cin.next());
        int[] array = new int [n];
        cin.nextLine();
        for (int i = 0; i < n; i++)
        {
            array[i] = cin.nextInt();
        }

        int cnt = selectionSort(array, n);
        for (int i = 0; i < n; i++)
        {
            System.out.print(array[i]);
            if (i != n - 1)
            {
                System.out.print(" ");
            }
        }
        System.out.println();
        System.out.println(cnt);
    }

    // Return count
    public static int selectionSort(int[] A, int N)
    {
        int minj;

        int cnt = 0;
        for (int i = 0; i < N; i++)
        {
            minj = i;
            for (int j = i; j < N; j++)
            {
                if (A[j] < A[minj])
                {
                    minj = j;
                }
            }
            int tmp = A[i];
            A[i] = A[minj];
            A[minj] = tmp;
            if (i != minj)
                cnt++;
        }

        return cnt;
    }
}

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

#define max_n 3001
#define INF 1e15

int main(){
    ll mod=1e9+7;
    ll n,k;
    cin>>n>>k;
    vector<ll> a(n);
    rep(i,n)cin>>a[i];

    vector<vector<ll>> dp(n+1,vector<ll>(k+1,0));
    vector<ll> sum(k+1,0);
    
    rep(i,n+1)dp[i][0]=1;
    rep(i,n){
        sum[0]=dp[i][0];
        rep2(1,j,k+1){
            sum[j]=(sum[j-1]+dp[i][j])%mod;
        }
        /*
        rep2(1,j,k+1){
            dp[i+1][j]=(((j-a[i]>0)?sum[j]-sum[j-a[i]]:sum[j])+mod)%mod;
        }
        */
       rep2(1,j,k+1){
           
            dp[i+1][j]=(dp[i][j]+dp[i+1][j-1])%mod;
            if(j - a[i] - 1 >= 0){
               dp[i+1][j]=(dp[i+1][j]+mod-dp[i][j-a[i]-1])%mod;
            }
            
        }
              
    }
  /*
    rep(i,n+1){
        rep(j,k+1){
            cout<<dp[i][j]<<" ";
        }cout<<endl;
    }
    */
    cout<<dp[n][k]<<endl;
    

    return 0;
}

Measured memory_bytes: 80256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
typedef long long ll;

using namespace std;

class Edge
{
	public:
	ll cap;
	int next;
	int rev;

	Edge(int n,ll c,int r)
	{
		next=n;
		cap=c;
		rev=r;
	}
};

vector<Edge> g[202];
bool used[202];

//増加パスをdfsで探す
//now...現在の頂点
//goal...目標の頂点
//nowflow...現在の流量
ll dfs(int now,int goal,ll nowflow)
{
	if(now==goal)
		return nowflow; //goalまで到達できればとりあえず流せている
	used[now]=true;
	for(int i=0;i<g[now].size();i++)
	{
		Edge &e = g[now][i];
		//使われていないかつ流せる頂点を探す
		if(!used[e.next] && e.cap>0)
		{
			ll d = dfs(e.next,goal,min(nowflow,e.cap)); //流せる限り流したシミュレーションを行う
			if(d>0)
			{
				e.cap -= d; //流せていたら流量の分容量を差し引く
				g[e.next][e.rev].cap+=d;
				return d;
			}
		}
	}
	return 0;
}

//辺と逆辺を張る
int adde(int from,int to, int cap)
{
	g[from].push_back(Edge(to,cap,g[to].size()));
	g[to].push_back(Edge(from,0,g[from].size()-1));//逆辺
	return 0;
}

int main()
{
	int n;
	pair<int,int> r[100];
	ll ans=0;
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>r[i].first>>r[i].second;
	}
	//ここからグラフ作る
	//s->赤->青->tの順番で流すことを考える
	//s...0
	//t...2*n
	for(int i=0;i<n;i++)
	{
		adde(0,i+1,1);
		adde(n+1+i,2*n+1,1);
	}
	sort(r,r+n);
	for(int i=0;i<n;i++)
	{
		//青い点の入力
		int x,y;
		cin>>x>>y;
		for(int j=0;j<n;j++)
		{
			if(x>r[j].first && y>r[j].second)
			{
				adde(j+1,n+1+i,1);
			}
			if(x<r[j].first)
				break;
		}
	}
	while(1)
	{
		fill(used,used+202,false);
		ll f = dfs(0,2*n+1,9999999999999999);
		if(f==0)
			break;
		ans+=f;
	}
	cout<<ans<<endl;
	return 0;
}

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

int main()
{
	int n, i, sum = 0;
	int l[100000], r[100000];

	scanf("%d", &n);

	for (i = 0; i < n; i++){
		scanf("%d %d", &l[i], &r[i]);
		sum += r[i] - l[i] + 1;
	}

	printf("%d", sum);

	return 0;
}

Measured memory_bytes: 128
S = input()
N = len(S)
cnt = [0 for i in range(N)]
even = 1
odd = 0
prev = 'R'
now = ''
flag1 = 0
flag2 = 0

for i in range(1,N):
    now = S[i]
    if prev != now:
        if prev == 'R':
            flag1 = i-1
            flag2 = i
        else:
            if flag1 % 2 == 0:
                cnt[flag1] = even
                cnt[flag2] = odd
            else:
                cnt[flag2] = even
                cnt[flag1] = odd
            odd = 0
            even = 0
    if i % 2 == 0:
        even += 1
    else:
        odd += 1
    prev = now

if flag1 % 2 == 0:
    cnt[flag1] = even
    cnt[flag2] = odd
else:
    cnt[flag2] = even
    cnt[flag1] = odd

print(' '.join([str(a) for a in cnt]))

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

#define int long long
#define INT int
#define MOD 1000000007

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define all(i) (i).begin(), (i).end()
#define rall(i) (i).begin(), (i).end(), greater<int>()
#define elif else if
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define fst first
#define sec second
template <typename T>
void print(T x)
{
    std::cout << x << '\n';
}
typedef long long ll;
const long long INF = 1LL << 60;

signed main()
{

    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n)
    {
        cin >> a[i];
    }
    int ans = 1000;
    int buy_m;
    int buy_c;
    vector<int> b = a;

    rep1(i, n)
    {
        b[i] = a[i] - a[i - 1];
    }

    bool sellable;

    if (b[1] > 0)
    {
        sellable = true;
        buy_c = ans / a[0];
        buy_m = a[0] * buy_c;
        ans -= buy_m;
    }
    else
    {
        sellable = false;
    }
    int i = 1;
    while (i < n)
    {
        if (sellable)
        {
            while (b[i] >= 0)
            {
                i++;
                if (i >= n)
                {
                    ans += buy_c * a[i - 1];
                    print(ans);
                    return 0;
                }
            }

            ans += buy_c * a[i - 1];
            buy_c = 0;
            buy_m = 0;
            sellable = false;
        }
        else
        {
            while (b[i] <= 0)
            {
                i++;
                if (i >= n)
                {
                    print(ans);
                    return 0;
                }
            }
            buy_c = ans / a[i - 1];
            buy_m = a[i - 1] * buy_c;
            ans -= buy_m;
            sellable = true;
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3568
#include <bits/stdc++.h>
 
using namespace std;
int n,m;
int nx = pow(10,5)+10;
vector<vector<int>> g(nx+1);
vector<int>dp(nx+2,0);
vector<int> vis(nx+2);
void dfs(int s){
    vis[s] = 1;
    for(int x : g[s]){
        if(vis[x]==0){
            dfs(x);
        }
        dp[s] = max(dp[s] , dp[x]+1);
    }
    
}
int main() {
    cin>>n>>m;
    int u,v;
    for(int i=0;i<m;i++){
        cin>>u>>v;
        g[u].push_back(v);
    }
    for(int i=1;i<=n;i++){
        if(vis[i]==0){
            dfs(i);
        }
    }
    int mx=0;
    for(int i=1;i<=n;i++){
        mx = max(mx,dp[i]);
    }
    cout<<mx;
    return 0;
    
}

Measured memory_bytes: 8576
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e5+5,mod=998244353;
int n,m,k;
ll f[N],invf[N],p[N];
ll C(int n,int m)
{
    return f[n]*invf[n-m]%mod*invf[m]%mod;
}
int main()
{
    scanf("%d%d%d",&n,&m,&k);
    p[0]=f[0]=f[1]=invf[0]=invf[1]=1;
    p[1]=m-1;
    for(int i=2;i<N;i++) p[i]=p[i-1]*(m-1)%mod,f[i]=f[i-1]*i%mod,invf[i]=(mod-mod/i)*invf[mod%i]%mod;
    for(int i=2;i<N;i++) invf[i]=invf[i]*invf[i-1]%mod;
    ll ans=0;
    for(int i=0;i<=k;i++)
        ans=(ans+C(n-1,i)*m%mod*p[n-1-i])%mod;
    printf("%lld\n",ans);
}


Measured memory_bytes: 8512
// #include<iostream>
// #include<vector>
// #include<algorithm>
// #include<map>
// #include<cstring>
// #include<math.h>
// #include<bitset>
// #include<queue>
// #include<set>
// #include<iomanip>
// #include<math.h>
// #include<assert.h>
// #include<string>
// #include<cstdlib>
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr ll INF = 1LL << 40;
const double INFD = 1e100;
const ll mod = 1000000007;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
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;
}
// ----------------------------------------------------------------------------

int main(){
  int N;
  cin >> N;
  vector<int> s(N);
  int sum=0;
  for(int i=0; i<N; i++){
    cin >> s[i];
    sum += s[i];
  }
  sort(s.begin(),s.end());
  if(sum%10){
    cout << sum << endl;
    return 0;
  }
  for(int i=0; i<N; i++){
    if((sum-s[i])%10){
      cout << sum-s[i] << endl;
      return 0;
    }
  }
  cout << 0 << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstring>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>
#include <fstream>

using namespace std;

#define REP(i, n) for(ll i = 0;i < n;i++)
#define REPR(i, n) for(ll i = n;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define FORR(i, m, n) for(ll i = m;i >= n;i--)
#define REPO(i, n) for(ll i = 1;i <= n;i++)
#define ll long long
#define INF (ll)1 << 60
#define MINF (-1 * INF)
#define ALL(n) n.begin(),n.end()
#define MOD 1000000007
#define P pair<ll, ll>

ll n;
int main() {
	cin >> n;
	if (n % 2 == 1) {
		cout << 0 << endl;
		return 0;
	}
	
	ll ans = 0, now = 1, t = 10;
	while (n >= t) {
		ans += n / t;
		t *= 5;
	}
	cout << ans << endl;
}



Measured memory_bytes: 256
import numpy as np
import itertools
import statistics
import math

n = int(input())
l = [list(map(int, input().split())) for i in range(n)]

arr = np.array(l)

arr1 = arr[:,:1].tolist()
arr2 = arr[:,1:].tolist()

l1 = list(itertools.chain.from_iterable(arr1))
l2 = list(itertools.chain.from_iterable(arr2))

a = statistics.median(l1)
b = statistics.median(l2)

if n%2 ==1:
    print(b-a+1)
else:
    print(int((b-a)//0.5) + 1)

Measured memory_bytes: 119372
// dfmt off
T lread(T=long)(){return readln.chomp.to!T;}T[] lreads(T=long)(long n){return iota(n).map!((_)=>lread!T).array;}
T[] aryread(T=long)(){return readln.split.to!(T[]);}void arywrite(T)(T a){a.map!text.join(' ').writeln;}
void scan(L...)(ref L A){auto l=readln.split;foreach(i,T;L){A[i]=l[i].to!T;}}alias sread=()=>readln.chomp();
void dprint(L...)(lazy L A){debug{auto l=new string[](L.length);static foreach(i,a;A)l[i]=a.text;arywrite(l);}}
static immutable MOD=10^^9+7;alias PQueue(T,alias l="b<a")=BinaryHeap!(Array!T,l);import std;
// dfmt on

void main()
{
    long R, G, B, N;
    scan(R, G, B, N);
    long ans;

    foreach (r; 0 .. N*2)
        foreach (g; 0 .. N*2)
        {
            long remain = N - R * r - G * g;
            if (remain < 0)
                continue;
            if (remain % B == 0)
                ans++;
        }
    writeln(ans);
}


Measured memory_bytes: 3680
#define D(x) cout << #x " = " << x << endl
#define DD(x, y) cout << "(" #x ", " #y ") = (" << x << ", " << y << ")" << endl
#define DDD(x, y, z) cout << "(" #x ", " #y ", " #z ") = (" << x << ", " << y << ", " << z << ")" << endl
#define DV(v) for (auto __macro_vi : v){ cout << __macro_vi << " ";} cout << endl;
#define DA(a, n) for (int __macro_i = 0; __macro_i < n; ++__macro_i) { cout << a[__macro_i] << " "; } cout << endl;
#define REP(i, n) for (int i = 0; i < n; ++i)
#define ALL(v) (v).begin(), (v).end()
#include<iostream>
#include<vector>
#include<cassert>
#include<cmath>

using namespace std;
using ll = long long;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> a(n);
    REP(i, n) {cin >> a[i]; a[i] -= i + 1; }
    sort(a.begin(), a.end());
    int med = a[a.size() / 2];
    ll ans = 0;
    REP(i, n) {ans += abs(a[i] - med);}
    cout << ans << endl;
}


Measured memory_bytes: 1024
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <numeric>
#include <queue>
#include <stack>
#include <map> 
#include <set>
#include <string>
#include <functional>
#include <list>
#include <random>
#include <time.h>
#include <iomanip>
#include <assert.h>
#include <numeric>
#define int long long
#define ll long long
#define double long double
#define mod 1000000007
#define MAXN (int)1e+5 * 2+1
#define LL_MAX 9223372036854775807	//ない環境用
#define LL_HALFMAX 9223372036854775807 / 2	//ない環境用
#define MIN -(9223372036854775807 / 2)
#define INF 9223372036854775807 / 2
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define mp make_pair


using namespace std;

std::mt19937 mt((int)time(0));

int dx[4] = { 0, 1, 0, -1 }; // x軸方向への変位
int dy[4] = { 1, 0, -1, 0 }; // y軸方向への変位

using Weight = int;
using Flow = int;
struct Edge {
	int src, dst;
	Weight weight;
	Flow cap;
	Edge() : src(0), dst(0), weight(0) {}
	Edge(int s, int d, Weight w) : src(s), dst(d), weight(w) {}
};
using Edges = std::vector<Edge>;
using Graph = std::vector<Edges>;
using Array = std::vector<Weight>;
using Matrix = std::vector<Array>;

void add_edge(Graph &g, int a, int b, Weight w = 1) {
	g[a].emplace_back(a, b, w);
	g[b].emplace_back(b, a, w);
}
void add_arc(Graph &g, int a, int b, Weight w = 1) { g[a].emplace_back(a, b, w); }

struct uf_tree {
	std::vector<int> parent;
	int __size;
	uf_tree(int size_) : parent(size_, -1), __size(size_) {}
	void unite(int x, int y) {
		if ((x = find(x)) != (y = find(y))) {
			if (parent[y] < parent[x]) std::swap(x, y);
			parent[x] += parent[y];
			parent[y] = x;
			__size--;
		}
	}
	bool is_same(int x, int y) { return find(x) == find(y); }
	int find(int x) { return parent[x] < 0 ? x : parent[x] = find(parent[x]); }
	int size(int x) { return -parent[find(x)]; }
	int size() { return __size; }
};



//!!!問題をちゃんと読む!!!
//!!!問題をちゃんと読め!!!
//!!!問題は読みましたか？!!!

char s1[3], s2[3];
signed main() {
	string s;
	cin >> s;

	s1[0] = s[0];
	s1[1] = s[1];
	s2[0] = s[2];
	s2[1] = s[3];

	int first, second;
	first = atoi(s1);
	second = atoi(s2);

	bool firstY, firstM, secondY, secondM;

	if (first > 0 && first <= 12) {
		firstM = true;
		firstY = true;
	}
	else {
		firstM = false;
		firstY = true;
	}
	if (second > 0 && second <= 12) {
		secondM = true;
		secondY = true;
	}
	else {
		secondM = false;
		secondY = true;
	}

	if (firstM && firstY && secondM && secondY) {
		cout << "AMBIGUOUS\n";
	}
	else if (firstM && secondY) {
		cout << "MMYY\n";
	}
	else if (firstY && secondM) {
		cout << "YYMM\n";
	}
	else {
		cout << "NA\n";
	}

	return 0;
}

Measured memory_bytes: 256
package main

import "fmt"

var repeatedComb [][]int

func main() {
	var n, m, q int

	fmt.Scan(&n)
	fmt.Scan(&m)
	fmt.Scan(&q)

	a := make([]int, q, q)
	b := make([]int, q, q)
	c := make([]int, q, q)
	d := make([]int, q, q)

	for i := 0; i < q; i++ {
		fmt.Scan(&a[i])
		a[i]--
		fmt.Scan(&b[i])
		b[i]--
		fmt.Scan(&c[i])
		fmt.Scan(&d[i])
	}

	dfs([]int{}, n, m)

	answer := 0
	l := len(repeatedComb)
	for i := 0; i < l; i++ {
		ar := repeatedComb[i]
		sum := 0
		for j := 0; j < q; j++ {
			if ar[b[j]]-ar[a[j]] == c[j] {
				sum += d[j]
			}
		}
		if sum > answer {
			answer = sum
		}
	}

	fmt.Println(answer)
}

func dfs(a []int, n int, m int) {
	l := len(a)
	if l == n {
		repeatedComb = append(repeatedComb, a)
	} else {
		var k int
		if l == 0 {
			k = 1
		} else {
			k = a[l-1]
		}

		for i := k; i <= m; i++ {
			a2 := make([]int, l)
			copy(a2, a)
			a2 = append(a2, i)

			dfs(a2, n, m)
		}
	}
}


Measured memory_bytes: 30436
//
//  main.c
//  ITP1_2_D
//
//  Created by k16031kk on 2018/05/17.
//  Copyright © 2018年 AIT. All rights reserved.
//

#include <stdio.h>

int main(int argc, const char * argv[]) {
    // insert code here...
    int W,H,x,y,r;
    scanf("%d %d %d %d %d",&W, &H, &x, &y, &r);
    int f=0;
    
    if(x+r>W)f=1;
    if(y+r>H)f=1;
    if(r>x)f=1;
    if(r>y)f=1;
    if(f==0)printf("Yes\n");
    else printf("No\n");
    
    return 0;
}



Measured memory_bytes: 2104
#!/usr/bin/env python
N = int(input())
A = [0]*N
for i in range(N):
    A[i] = int(input())
A_sort = sorted(A, reverse=True)
for i in range(N):
        if A[i] == A_sort[0]:
            print(A_sort[1])
        else:
            print(A_sort[0])

Measured memory_bytes: 14076
#include <algorithm>
#include <array>
#include <cstddef>
#include <cstdint>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <vector>

using namespace std;

int main()
{
    int n;
    cin >> n;
    set<int> ds;
    for (int i = 0; i < n; i++)
    {
        int d;
        cin >> d;
        ds.insert(d);
    }
    cout << ds.size() << endl;
}


Measured memory_bytes: 256
import sys

def solve():
    n, q = map(int, sys.stdin.readline().split())
    uf = UnionFind(n)
    ans = []

    for lp in range(q):
        c, x, y = map(int, sys.stdin.readline().split())

        if c == 0:
            uf.unite(x, y)
        else:
            ans.append(1 if uf.is_same(x, y) else 0)

    print(*ans, sep='\n')


class UnionFind:

    def __init__(self, n):
        self.ds = [i for i in range(n)]
        self.root = [i for i in range(n)]
        self.rank = [0] * n

    def find_root(self, x):
        if x != self.root[x]:
            self.root[x] = self.find_root(self.root[x])

        return self.root[x]

    def is_same(self, x, y):
        return self.find_root(x) == self.find_root(y)

    def unite(self, x, y):
        p = self.find_root(x)
        q = self.find_root(y)

        if p == q:
            return None

        if self.rank[p] < self.rank[q]:
            self.root[p] = q
        elif self.rank[q] < self.rank[p]:
            self.root[q] = p
        else:
            self.root[q] = p
            self.rank[p] += 1

def debug(x, table):
    for name, val in table.items():
        if x is val:
            print('DEBUG:{} -> {}'.format(name, val), file=sys.stderr)
            return None

if __name__ == '__main__':
    solve()

Measured memory_bytes: 10436
#include <iostream>
#include <string>
#include <cstdio>

using namespace std;

int N;
char S[4001];

int main(){
  cin >> N >> S;
  long long int R=0,G=0,B=0;
  long long int ans;
  for (int i=0; i<N; i++)
    switch(S[i]) {
    case 'R': R++;break;
    case 'G': G++;break;
    case 'B': B++;break;
    }
  ans = R * G * B;
  for (int i=0; i<N; i++) {
    for (int j=i+1; j<N; j++) {
      int k = j + (j-i);
      if (k >= N) break;
      if (S[i] != S[j] && S[j] != S[k] && S[i] != S[k])
        ans--;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3644
S=input()
lens=len(S)
S=int(S, 2)
a=[]
b=[]

def popcnt0(n):
	global lens
	c = 0
	for i in range(lens):
		c += (n >> i) & 1
	return c

for i in range(lens):
	if i%2==0:
		a.append('0')
		b.append('1')
	if i%2==1:
		a.append('1')
		b.append('0')
aa=''.join(a)
bb=''.join(b)
aaa=int(aa,2)
bbb=int(bb,2)
c=S^aaa
d=S^bbb

print(min(popcnt0(c),popcnt0(d)))






Measured memory_bytes: 4904
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

ll p[100100];

int main(void){
	int n,q,a,i;
	ll k;
	cin >> n >> k >> q;
	k -= q;
	for(i=0; i<q; ++i){
		cin >> a; --a;
		++p[a];
	}
	for(i=0; i<n; ++i){
		p[i] += k;
		cout << ((p[i]>0ll)?"Yes":"No") << endl;
	}
	return 0;
}


Measured memory_bytes: 1408
#include <iostream>
#include <cmath>
using namespace std;
int main(void){
    string S, T;
    cin >> S >> T;
    if(S[0]==T[2]&&S[1]==T[1]&&S[2]==T[0]){
        cout << "YES";
    }else{
        cout << "NO";
    }
}


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

    typedef long long int ll;

    #define MOD (ll)(1e9+7)
    #define endl "\n"
    #define pb push_back
    #define TEST_CASES  ll t;cin>>t;while(t--)
    #define forn(i,a,n) for (int i = a; i < n; ++i)
    #define f first
    #define s second
    #define all(x) x.begin(), x.end()
    
    ll powD(ll x,ll y){
      ll res = 1;
      while(y > 0){
        if(y & 1)
          res = (res*x)%MOD;
        x = (x*x)%MOD;
        y = y>>1;
      }
      return res;
    }

    int main()
    {
      ios_base::sync_with_stdio(false);
      cin.tie(NULL);
      int n;
      cin>>n;
      int q = n/1000 + (n%1000 != 0);
      int ans = 1000*q-n;
      cout<<ans<<endl;
    } 
    

Measured memory_bytes: 3656
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp> 
//#include <ext/pb_ds/tree_policy.hpp>
//#include <functional> // for less
//using namespace __gnu_pbds;
using namespace std;
typedef long long  L;
typedef pair<L, L> pii;
#define max_(x, y) (((x) > (y)) ? (x) : (y))
#define min_(x, y) (((x) < (y)) ? (x) : (y))
#define ___ ios_base::sync_with_stdio(false);cin.tie(NULL);
#define Mx 2000001
#define inf 1e17
const L MOD = 1e9+7;
const double pi = 2 * acos (0.0);

/*------------------------------Graph Moves----------------------------*/
//const int fx[]={+1,-1,+0,+0};
//const int fy[]={+0,+0,+1,-1};
//const int fx[]={+0,+0,+1,-1,-1,+1,-1,+1};   // Kings Move
//const int fy[]={-1,+1,+0,+0,+1,+1,-1,-1};  // Kings Move
//const int fx[]={-2, -2, -1, -1,  1,  1,  2,  2};  // Knights Move
//const int fy[]={-1,  1, -2,  2, -2,  2, -1,  1}; // Knights Move
/*---------------------------------------------------------------------*/


//typedef tree<L,null_type,less<L>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

L a,b,a1,a2,a3,b1,b2,b3,c,c1,c2,c3,d,d1,d2,d3,d4,d5,e1,e2,e3,f,h,k,l,n,m,m1,m2,n1,n2,o,p1,p2,p3,p4,
q1,q2,q3,q4,r,s,t,x,y,z,sum,mn,flg,flg1,flg2,id1,id2,id3,lim,cost,ans;

L A[Mx];
struct info{
    L F,S;
    info(L _F,L _S){
        F=_F;
        S=_S;
    }
};

struct compare{
  bool operator()(const info& lf, const info& rt){
      return lf.F < rt.F;
  }
};
priority_queue<info,vector<info>,compare>Pq;
void solve(){
    sort(A,A+n,greater<L>() );
    ans=A[0];

    Pq.push(info(A[1],A[0]));
    for(L i=2;i<n;i++){
        a=Pq.top().F;
        b=Pq.top().S;
        if(i!=2){
            Pq.pop();
        }
        ans+=a;

        Pq.push(info(A[i],a));
        Pq.push(info(A[i],b));
    }
    printf("%lld\n",ans);
}
int main()
{
    scanf("%lld",&n);
    for(L i=0;i<n;i++){
        scanf("%lld",&A[i]);
    }
    solve();
    return 0;
}
/// empty() lld I64d push_back() top() pop() insert() upper_bound() lower_bound() memset() max() min() scanf continue


Measured memory_bytes: 8992
#include<bits/stdc++.h>
#include <math.h>
#include <algorithm>
#include <functional>
#include<iostream>
#include <string>
using namespace std;
typedef long long ll;
#define pb pushback
#define fr(i,n) for(int i=0;i<n;i++)
#define fro(i,j,n) for(int i=j;i<n;i++)
#define ifr(i,n) for(int i=n-1;i>=0;i--)


int main() {
    int n;
	cin >> n;
    int b[n];
    int ans=0;
    fr(i,n-1){
      cin>>b[i];
    }
    ans+=b[0];
    fr(i,n-2){
      ans+=min(b[i],b[i+1]);
    }
    ans+=b[n-2];
      cout << ans << endl;
}

Measured memory_bytes: 256