akhauriyash/Code-Regression huggingface dataset:
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
input = sys.stdin.readline
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
    return list(map(int,input().split()))
def m(): #複数文字
    return map(int,input().split())
def onem(): #Nとかの取得
    return int(input())
def s(x): #圧縮
    a = []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): #listをスペースごとに分ける
    return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
    return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False
"""
def nibu(x,n,r):
    ll = 0
    rr = r
    while True:
        mid = (ll+rr)//2

    if rr == mid:
        return ll
    if (ここに評価入れる):
        rr = mid
    else:
        ll = mid+1
"""

mod = 10**9+7 #出力の制限
N = 10**5 * 2
def cmb(n, r):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod
def p(n,r):
    if ( r<0 or r>n ):
        return 0
    return g1[n] * g2[n-r] % mod

g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )
# a = cmb(n,r)

import fractions
from functools import reduce
def gcd(*numbers):
    return reduce(fractions.gcd, numbers)

def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)
def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

k,q = m()

d = l()


for i in range(q):
    n,x,mm = m()
    co = 0

    po = []
    for j in range(k):
        po.append(d[j] % mm if d[j] % mm > 0 else mm)

    """
    for j in range(k):
        if po[j] == 0:
            ccc = ((n-1)//k)
            if (n-1)%k >= j:
                ccc += 1
            co += ccc
    """
    pp = sum(po) * ((n-1)//k)
    pp += x
    for j in range((n-1)%k):
        pp += po[j]
    
    co += (pp//mm) - (x//mm)
    
    print((n-co-1))






Measured memory_bytes: 90756
using System.Linq;
using System;

public class hello
{
    public static void Main()
    {
        var n = int.Parse(Console.ReadLine().Trim());
        var arr = new long[n];
        string[] line = Console.ReadLine().Trim().Split(' ');
        for (int i = 0; i < n; i++) arr[i] = int.Parse(line[i]);
        Console.WriteLine("{0} {1} {2}", arr.Min(), arr.Max(), arr.Sum());

    }
}


Measured memory_bytes: 20356
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(n) begin(n), end(n)
using ll = long long;
using namespace std;

int main(){
	string s;
	cin >> s;
	set<char> st;
	rep(i, s.size()){
		char c = s[i];
		st.insert(c);
	}
	if((st.count('E') == 1 ^ st.count('W')) || (st.count('N') == 1 ^ st.count('S') == 1)){
		cout << "No" << endl;
	}else{
		cout << "Yes" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <vector>
#include <algorithm>
#include <tuple>
#include <utility>
#include <cstring>
#include <iostream>
#include <cstdio>
using namespace std;
using ll = long long int;
using Graph = vector< vector<int> >;

/*
void chmax(ll &A, const ll B) {
  A = max(A, B);
}
*/

ll N, K, dp[100010][2][2], sz[100010];

void dfs(Graph &G, int cur, int par=-1) {
  sz[cur] = 1;
  for(auto to : G[cur]) {
    if(to == par) continue;
    dfs(G, to, cur);
    sz[cur] += sz[to];
  }
}

int solve(Graph &G, int cur, int f1, int f2, int par=-1) {
  if(dp[cur][f1][f2] >= -1) return dp[cur][f1][f2];

  ll val = -1;
  if(f1 == 0) {
    if(f2 == 0) {
      val = 0;
      for(auto to : G[cur]) {
        if(to == par) continue;
        val += (sz[to] >= K);
      }
    }

    if(f2 == 1) {
      for(auto to : G[cur]) {
        if(to == par) continue;
        ll tmp = solve(G, to, 0, 1, cur);
        if(tmp >= 0) val = max(val, tmp);

        tmp = solve(G, to, 1, 1, cur);
        if(tmp >= 0) {
          tmp += (N - sz[to]) >= K;
          val = max(val, tmp);
        }
      }
    }

    return dp[cur][f1][f2] = val;
  }
  if(f1 == 1) {
    int M = G[cur].size();
    vector<ll> dpcur(3, -1);
    dpcur[0] = 0;
    for(size_t i=0; i<G[cur].size(); i++) {
      int to = G[cur][i];
      if(to == par) continue;
      
      vector<ll> dpnxt(3, -1);
      for(int j=0; j<=2; j++) {
        if(dpcur[j] < 0) continue;
        
        // take
        if(j < 2) {
          ll tmp = solve(G, to, 1, 0, cur);
          if(tmp >= 0) {
            dpnxt[j+1] = max(dpnxt[j+1], dpcur[j] + tmp);
          }
        }

        // do not take
        dpnxt[j] = max(dpnxt[j], dpcur[j] + (sz[to] >= K));
      }
      swap(dpcur, dpnxt);
    }

    if(f2 == 0) {
      return dp[cur][f1][f2] = (val = max(dpcur[0], dpcur[1]));
    }
    if(f2 == 1) {
      return dp[cur][f1][f2] = (val = max(dpcur[1], dpcur[2]));
    }
  }
}

int main() {
  cin >> N >> K;

  Graph G(N);
  for(int i=0; i<N-1; i++) {
    int u, v; cin >> u >> v;
    u--; v--;
    G[u].push_back(v);
    G[v].push_back(u);
  }

  fill(dp[0][0], dp[N+1][0], -2);
  dfs(G, 0);
  cout << max(solve(G, 0, 0, 1), solve(G, 0, 1, 1)) << endl;

  /*
  for(int i=0; i<N; i++) {
    for(int f1=0; f1<2; f1++) {
      for(int f2=0; f2<2; f2++) {
        fprintf(stderr, "dp[%d][%d][%d] = %lld\n", i, f1, f2, dp[i][f1][f2]);
      }
    }
  }
  */
  return 0;
}


Measured memory_bytes: 23396
import sys
N = int(input())
A = []
for i in range(N):
    A.append(int(input()))

Ans = 0
if A[0]>0:
    print(-1)
else:
    for i in range(N-1):
        d = A[N-1-i]-A[N-2-i]
        if d>1:
            print(-1)
            sys.exit()
        elif d<=0:
            Ans += A[N-1-i]
        elif d==1:
            Ans += 1
    print(Ans)
    


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


int main()
{
    int n,T,i,j,k,n2,l;
    char str[100];
    int ck=0;
    cin>>n;
    cin>>str;
    if(n%2==0){
        k=(n/2);
        l=k-1;
        for(i=0;i<=l;i++){
            if(str[i]!=str[k]){
                ck=1;
                break;
            }
            k++;
        }
        if(ck){
            cout<<"No"<<endl;
        }
        else{
            cout<<"Yes"<<endl;
        }
    }
    else{
        cout<<"No"<<endl;
    }


    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <climits>

using namespace std;

int main() {
    int n;
    cin >> n;
    vector<int> v(n), dp(n);
    for (int i = 0; i < n; ++i)cin >> v[i];
    if (n == 1) {
        printf("0\n");
    } else {
        dp[0] = 0;
        dp[1] = abs(v[1] - v[0]);
        dp[2] = min(dp[0] + abs(v[2] - v[0]), dp[1] + abs(v[2] - v[1]));
        for (int i = 3; i < n; ++i)
            dp[i] = min(dp[i - 2] + abs(v[i] - v[i - 2]), dp[i - 1] + abs(v[i] - v[i - 1]));
        printf("%d\n", dp[n - 1]);
    }
}

Measured memory_bytes: 1024
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.IO.Compression;
using System.Linq;
using System.Text;

namespace Atcoder
{
    class Program
    {
        private const long COMDIV = 1000000007;
        static void Main(string[] args)
        {
            var SW = Console.ReadLine().Split().Select(int.Parse).ToArray();
            Console.WriteLine(SW[0] <= SW[1] ? "unsafe" : "safe");
        }
    }
}

Measured memory_bytes: 28076
#include <cstdio>
#define S_MAX 1000000

bool binarySearch(int S[], int s, int e, int t) {
    if (e < s) return false;
    int half = (s + e) / 2;
    int half_value = S[half];
    if (half_value == t) {
        return true;
    }
    else if (half_value < t) {
        return binarySearch(S, half + 1, e, t);
    }
    else if (t < half_value) {
        return binarySearch(S, s, half - 1, t);
    }
    return false;
}

int main()
{
    int n;
    scanf("%d", &n);
    int S[S_MAX];
    for (int i=0; i<n; i++) scanf("%d", &S[i]);

    int q;
    scanf("%d", &q);
    int count = 0;
    for (int j=0; j<q; j++) {
        int t;
        scanf("%d", &t);
        if (S[n-1] < t) continue;
        if (t < S[0]) continue;
        if (binarySearch(S, 0, n-1, t)) count++;
    }

    printf("%d\n", count);

    return 0;
}

Measured memory_bytes: 3124
#include <iostream>
#include <string.h>
using namespace std;

int main() {
  int N;
  int count = 0;
  string S;

  cin >> N;
  cin >> S;

  for (int i = 0; i < N; i++) {
    if (S.substr(i, 3) == "ABC") {
      count++;
    }
  }

  cout << count;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define pq priority_queue
using namespace std;
const ll INF=(ll)1e9;
const ll MOD=(ll)1e9+7;
const ll MAX=510000;
vector<int> dx={1,0,-1,0},dy={0,1,0,-1};
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; }

bool com(pair<ll,ll> a,pair<ll,ll> b){
    if(a.second!=b.second) return a.second>b.second;
    else return a.first>b.first;
}

int main(){
    ll N,b=0,cnt=0;
    cin>>N;
    pair<ll,ll> A[N],B[N];
    bool f[N];
    for(ll i=0;i<N;i++) cin>>A[i].first>>A[i].second;
    for(ll i=0;i<N;i++){
        cin>>B[i].first>>B[i].second;
        f[i]=false;
    }
    sort(A,A+N,com);
    sort(B,B+N);

    for(ll i=0;i<N;i++){
        for(ll j=0;j<N;j++){
            if(A[j].first<B[i].first&&A[j].second<B[i].second&&!f[j]){
                cnt++;
                f[j]=true;
                break;
            }
        }
    }
    cout<<cnt<<endl;
}


Measured memory_bytes: 256
fun main(args: Array<String>) {
    abc000X()
}

fun abc000X() {
    val s = readLine()!!
    var max = 0
    var count = 0
    s.forEach {
        if (it == 'A' || it == 'C' || it == 'G' || it == 'T') {
            count++
            max = count.coerceAtLeast(max)
        } else {
            count = 0
        }
    }
    println(max)
}

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

using namespace std;

int counter[26];

int main() {
	bool end = false;
	while (!end) {
		string str;
		getline(cin, str);
		if (str.size() == 0)
			break;
		for (int i = 0; i < str.size(); i++) {
			char charactor = str.at(i);
			if ('A' <= charactor && charactor <= 'Z')
				charactor += 32;
			if ('a' <= charactor && charactor <= 'z')
				counter[charactor - 'a']++;
		}
		str = "";
	}
	for (int i = 0; i < 26; i++)
		cout << (char)(i + 'a') << " : " << counter[i] << endl;
	return 0;
}

Measured memory_bytes: 1176
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>

using namespace std;

int main()
{
    int N;
    int Nums_A[1000];
    string RetVal = "APPROVED";

    cin >> N;

    for (int loop = 0; loop < N; loop++) {
        cin >> Nums_A[loop];
    }

    for (int loop = 0; loop < N; loop++) {
        if (Nums_A[loop] % 2 == 0 && (Nums_A[loop] % 5 != 0 && Nums_A[loop] % 3 != 0)) {
            RetVal = "DENIED";
            break;
        }
    }

    cout << RetVal;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <string.h>
#include <cstdio>
#include <tuple>
#include <numeric>
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define CST(x) cout<<fixed<<setprecision(x)//小数点以下の桁数指定
#define ct(a) cout<<a<<endl
static const double pi = 3.141592653589793;
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const ll INF = 1e9 + 7;
const ll mod = 1e9 + 7;


int K;
string S;

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

	cin >> K;
	cin >> S;
	if (S.length() <= K)cout << S << endl;
	else {
		cout << S.substr(0, K);
		cout << "..." << endl;
	}


	return 0;
}

Measured memory_bytes: 3656
#include <cstdio>
#include <algorithm>
#include <vector>
using namespace std;
typedef long long ll;
const int MAXN=220000;
const ll INF=1E18;
int n, m, a[MAXN];
struct Edge
{
	int to, val;
	Edge(int v, int w): to(v), val(w) {}
};
vector<Edge> g[MAXN];
struct DSU
{
	int f[MAXN];
	void init()
	{
		for (int i=1; i<=n; i++) f[i]=i;
	}
	int getf(int x)
	{
		if (x==f[x]) return x;
		return f[x]=getf(f[x]);
	}
	bool merge(int u, int v)
	{
		int x=getf(u), y=getf(v);
		if (x==y) return 0;
		f[x]=y; return 1;
	}
} dsu;
typedef pair<ll, int> pli;
pli dp1[MAXN], dp2[MAXN], p[MAXN];
void dfs1(int u, int f)
{
	for (Edge e:g[u])
	{
		int v=e.to;
		if (v!=f)
		{
			dfs1(v, u);
			dp1[u]=min(dp1[u],
			make_pair(dp1[v].first+e.val, dp1[v].second));
		}
	}
}
void dfs2(int u, int f)
{
	for (Edge e:g[u])
	{
		int v=e.to;
		if (v!=f)
		{
			dp1[v]=min(dp1[v],
			make_pair(dp1[u].first+e.val, dp1[u].second));
			dfs2(v, u);
		}
	}
	for (Edge e:g[u])
	{
		int v=e.to;
		if (v!=f)
		{
			dp2[u]=min(dp2[u], dsu.f[dp1[v].second]!=dsu.f[dp1[u].second]?
			make_pair(dp1[v].first+e.val, dp1[v].second):
			make_pair(dp2[v].first+e.val, dp2[v].second));
		}
	}
}
void dfs3(int u, int f)
{
	for (Edge e:g[u])
	{
		int v=e.to;
		if (v!=f)
		{
			dp2[v]=min(dp2[v], dsu.f[dp1[u].second]!=dsu.f[dp1[v].second]?
			make_pair(dp1[u].first+e.val, dp1[u].second):
			make_pair(dp2[u].first+e.val, dp2[u].second));
			dfs3(v, u);
		}
	}
}
int main()
{
//	freopen("AT3611.in", "r", stdin);
//	freopen("AT3611.out", "w", stdout);
	scanf("%d", &n);
	for (int i=1; i<=n; i++) scanf("%d", &a[i]);
	for (int i=1; i<n; i++)
	{
		int u, v, w;
		scanf("%d%d%d", &u, &v, &w);
		g[u].push_back(Edge(v, w));
		g[v].push_back(Edge(u, w));
	}
	dsu.init();
	int cnt=0; ll ans=0;
	while (cnt<n-1)
	{
		for (int i=1; i<=n; i++)
		{
			dp1[i]=make_pair(a[i], i);
			dp2[i]=make_pair(INF, 0);
		}
		dfs1(1, 0); dfs2(1, 0); dfs3(1, 0);
		for (int i=1; i<=n; i++)
		{
			p[i]=dsu.f[dp1[i].second]!=dsu.f[i]?dp1[i]:dp2[i];
			p[i].first+=a[i];
		}
		for (int i=1; i<=n; i++) p[dsu.f[i]]=min(p[dsu.f[i]], p[i]);
		for (int i=1; i<=n; i++)
		{
			pli t=p[dsu.getf(i)];
			if (t.first<INF&&dsu.merge(i, t.second)) cnt++, ans+=t.first;
		}
		for (int i=1; i<=n; i++) dsu.getf(i);
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 42368
// https://atcoder.jp/contests/abc177/tasks/abc177_c
#include <bits/stdc++.h>
// #include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
// using cpp_dec = boost::multiprecision::cpp_dec_float_50;
using cpp_int = boost::multiprecision::cpp_int;

using namespace std;
#define int long long
#define REP(i, n) FOR(i, 0, n)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define CEIL(a, b) ((a - 1) / b + 1)
const int MOD = 1e9 + 7;

// 参考
// https://atcoder.jp/contests/abc177/submissions/16384020
void solve() {
    int N;
    cin >> N;
    cpp_int x = 0, y = 0;
    REP(i, N) {
        cpp_int t;
        cin >> t;
        x += t;
        y += t * t;
    }
    // (A + B + C)^2 = A^2 + B^2 + C^2 + 2*AB + 2*AC + 2*BC
    // 2*AB + 2*AC + 2*BC = (A + B + C)^2 - (A^2 + B^2 + C^2)
    // AB + AC + BC = ((A + B + C)^2 - (A^2 + B^2 + C^2)) / 2
    // = (x^2 - y) / 2
    cout << (x * x - y) / 2 % MOD << endl;
}

signed main() {
    cin.tie(nullptr)->sync_with_stdio(false);
    solve();
}


Measured memory_bytes: 3704
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ll unsigned long long
#define lld long double
#ifdef DEBUG
#define line() cout << "[" << __LINE__ << "] ";
#define dump(i) cout << #i ": " << i << " ";
#define dumpl(i) cout << #i ": " << i << endl;
#else
#define line(i)
#define dump(i)
#define dumpl(i)
#endif
using namespace std;
ll cmb[51][51];

int main(int argc, char const *argv[])
{
    rep(i, 51)
    {
        cmb[i][0] = 1;
        rep(j, 1, i + 1)
        {
            cmb[i][j] = cmb[i - 1][j - 1] + cmb[i - 1][j];
        }
    }
    int n, a, b;
    cin >> n >> a >> b;
    ll v[n];
    rep(i, n) cin >> v[i];
    sort(v, v + n, greater<ll>());
    rep(i, n) dumpl(v[i]);

    ll target = 0;
    rep(i, a) target += v[i];
    cout << fixed << ((lld)target) / a << endl;
    if (v[0] != v[a - 1])
    {
        int x = 0, y = 0;
        rep(i, n)
        {
            if (v[i] == v[a])
                x++;
        }

        rep(i, a)
        {
            if (v[i] == v[a])
                y++;
        }
        cout << cmb[x][y] << endl;
    }
    else
    {
        ll ans = 0, x = 0;
        rep(i, n) if (v[i] == v[0]) x++;
        rep(i, a, b + 1)
        {
            ans += cmb[x][i];
        }
        cout << ans << endl;
    }
    return 0;
}


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

int main() {
  string str;
  vector<string> v;
  vector<string>::iterator it_old;
  int l_max = 0;
  int c_max = 0;
  string l_str;
  string c_str;
  int count = 0;

  while (cin >> str) v.push_back(str);
  sort(v.begin(), v.end());
  it_old = v.begin();
  for (vector<string>::iterator it = v.begin(); it != v.end(); it++) {
    if (it->size() > l_max) {
      l_max = it->size();
      l_str = *it;
    }
    if (it != v.begin() && *it_old == *it) {
      count++;
      if (count > c_max) {
        c_max = count;
        c_str = *it;
      }
    }
    else {
      count = 0;
      it_old = it;
    }
  }
  cout << c_str << " " << l_str << endl;
}

Measured memory_bytes: 1208
#include <iostream>
#include <algorithm>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#include <vector>
#include <string>
using namespace std;

#pragma GCC optimize("O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//(UNCOMMENT WHEN HAVING LOTS OF RECURSIONS)
#pragma comment(linker, "/stack:200000000")
//(UNCOMMENT WHEN TRYING TO BRUTEFORCE WITH A LOT OF LOOPS)
#pragma GCC optimize("unroll-loops")

#define DEBUG(x) cout << ">> " << #x << ": " << x << endl;
#define _ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define f first
#define s second

const int MOD = 1000000007;
typedef long long ll;
typedef long double ld;

void setIO(string s) {
  ios_base::sync_with_stdio(0); cin.tie(0);
  freopen((s+".in").c_str(),"r",stdin);
  freopen((s+".out").c_str(),"w",stdout);
}

int main() { _
  string n; cin >> n;
  for (char c : n) {
    if (c == '7') {
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 3628
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
//#define int long long  ←保留
#define _CRT_SECURE_NO_WARNINGS
#define rep(i, n) for (int i = 0; i < n; i++)
#define _GLIBCXX_DEBUG
const int MOD = 1e9 + 7;
const int INF = 1e18 + 9;
constexpr long double pi = 3.141592653589793238462643383279; //円周率
/*---------------------便利な関数--------------------------------------*/
int fact(int i) {       //階乗
    if (i == 0) return 1;
    return (fact(i - 1)) * i;
}

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

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

int keta(int n) {        //桁数を求める
    if (n == 0) return 1;
    int count = 0;
    while (n != 0) {
        n /= 10;
        count++;
    }
    return count;
}

int ketasum(int n) {    //各桁の和
    int sum = 0;
    while (n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
/*-------------ここまで---------------------------------------------*/

//C++(GCC9.2.1)

/*signed*/int main() {
    int s, w;
    cin >> s >> w;
    if (w >= s) cout << "unsafe" << endl;
    else cout << "safe" << endl;
    return 0;
}

Measured memory_bytes: 3516
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pb push_back
#define mp make_pair

string s;

void solve()
{
	for(int i=1;i<4;++i){
		if(s[i]==s[i-1]){
			cout << "Bad\n";
			return;
		}
	}
	cout << "Good\n";
}

int main()
{
	ios::sync_with_stdio(false);
	cin >> s;
	solve();
	return 0;
}

Measured memory_bytes: 256
import java.io.PrintWriter

fun main() {
    val pw = PrintWriter(System.out)

    val (s, w) = readInputLine().split(" ").map { it.toInt() }

    if (w >= s) {
        pw.println("unsafe")
    } else {
        pw.println("safe")
    }

    pw.flush()
}

fun readInputLine(): String {
    return readLine()!!
}


Measured memory_bytes: 36452
#include<bits/stdc++.h>
using namespace std;
constexpr int64_t mod=1e9+7;

// a^n%mod
template<class T=int64_t>
T bin_pow(T a,T n,T mod=1e9+7){
    T ans=1;
    while(n>0){
        if(n&1) ans=ans*a%mod;
        a=a*a%mod;
        n>>=1;
    }
    return ans%mod;
}

//a^(-1)(mod)=a^(mod-2)
template<class T=int64_t>
T inv_mod(T a,T mod=1e9+7){
  return bin_pow(a,mod-2);
}

//a!%mod
template<class T=int64_t>
T fact(T a,T mod=1e9+7){
    T ans=1;
    for(int i=2;i<=a;++i){
        ans=ans*i%mod;
    }
    return ans;
}

//nCr%mod
template<class T=int64_t>
T comb(T n,T r,T mod=1e9+7){
    return fact(n)*inv_mod(fact(r)*fact(n-r)%mod)%mod;
}
template<class T=int64_t>
T nCk(T n,T k,T mod=1e9+7)
{
  int64_t ans=1;
  for (int64_t i = 0; i < k; ++i)
  {
    ans*=(n-i);
    ans%=mod;
  }
  for (int64_t i = 1; i <= k; ++i)
  {
    ans*=inv_mod(i);
    ans%=mod;
  }
  return ans%mod;
}
int main()
{
  int64_t n,a,b;
  cin>>n>>a>>b;
  int64_t ans=bin_pow((int64_t)2,n)-1;
  ans-=nCk(n,a);
  ans%=mod;
  ans-=nCk(n,b);
  ans%=mod;
  cout<<(ans+mod)%mod;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(n);i++)
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
const ll INF=1e18;
const int MOD=1e9+7;
const double pi=acos(-1);


int main(){
  ll h,w,a,b;
  cin >> h >> w >> a >> b;
  rep(i,b){
    rep(j,w){
      if(j<a){
        cout <<0;
      }
      else cout<<1;
    }
    cout<<endl;
  }
  rep(i,h-b){
    rep(j,w){
      if(j<a){
        cout <<1;
      }
      else cout<<0;
    }
    cout<<endl;
  }
    
}


Measured memory_bytes: 1280
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define is(a, b) a == b
#define len(v) ll(v.size())

const ll mod=1e9+7;

//vector書き出し
template <class T>
void cout_vec(const vector<T> &vec1){
  rep(i,len(vec1)){
    cout<<vec1[i]<<' ';
  }
  cout<<'\n';
}

struct edge{
    ll to,cost;
};

ll n,q,k;
ll INF=1e15;
vector<edge> g[100010];
vector<ll> d(100010);

void dijkstra(ll x){
    rep(i,len(d)){
        d[i]=INF;
    }
    priority_queue<P,vector<P>,greater<P>> que;
    d[x]=0;
    que.push(P(0,x));
    while(!que.empty()){
        P p=que.top();
        que.pop();
        ll v=p.second;
        if(d[v]<p.first){
            continue;
        }
        rep(i,len(g[v])){
            edge e=g[v][i];
            if(d[e.to]>d[v]+e.cost){
                d[e.to]=d[v]+e.cost;
                que.push(P(d[e.to],e.to));
            }
        }
    }
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin>>n;
    rep(i,n-1){
        ll a,b,c;
        cin>>a>>b>>c;
        g[a].push_back({b,c});
        g[b].push_back({a,c});
    }
    cin>>q>>k;
    dijkstra(k);//kから各頂点までの最短距離
    /*
    cout<<k<<'\n';
    rep(i,n+1){
        cout<<d[i]<<'\n';
    }
    */
    rep(i,q){
        ll x,y;
        cin>>x>>y;
        cout<<d[x]+d[y]<<'\n';
    }
}

Measured memory_bytes: 9984
#include <iostream>
using namespace std;
int main(void){
    int H, M, S;
    cin >> S;
    M = S / 60;
    S = S % 60;
    H = M / 60;
    M = M % 60;
    cout << H << ":" << M << ":" << S << endl;
    return 0;
}



Measured memory_bytes: 3116
X, N = map(int, input().split(' '))
if N == 0:
    print(X)
else:
    P_ls = list(map(int, input().split(' ')))
    diff, rst = -1, 0
    for i in range(101, -1, -1):
        if i not in P_ls:
            if diff == -1:
                diff = abs(X - i)
                rst = i
            else:
                diff = min(diff, abs(X - i))
                if diff == abs(X - i):
                    rst = i
    print(rst)

Measured memory_bytes: 9128
#include<bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i= (a); i < (b); ++i)
typedef long long ll;
typedef pair<int,int> P;
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
int main() { int n, m;
  cin >> n >> m;
  cout << (n - 1) * (m - 1) << endl;
}

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

int main(){
      int n;cin >> n;
      string s;cin >> s;
      int ans = INT_MIN;
      if(n == 2 && s[0] != s[1])return cout << 0, 0;
      else if(n == 2) return cout << 1, 0;
      for(int i = 1;i < n - 1;i++){
            set<char> s1;
            set<char> s2;
            set<char> s3;
            for(int j = 0;j < n;j++){
                  if(j < i)s1.insert(s[j]);
                  else{
                        if(s1.count(s[j]) != 0 && s3.count(s[j]) == 0){
                              s2.insert(s[j]);
                              s3.insert(s[j]);
                        }
                  }
            }
            ans = max(ans, (int)s2.size());
      }
      cout << ans;
}

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

using namespace std;

bool sorter(pair<string, pair<int, int>>a, pair<string, pair<int, int>>b)
{
    if (a.first==b.first)
        return a.second.first>b.second.first;
    return lexicographical_compare(a.first.begin(), a.first.end(), b.first.begin(), b.first.end());
}

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

    int a;
    cin>>a;
    pair<string, pair<int, int>> book[a];

    for (int i=0;i<a;i++)
    {
        string b;
        int c;
        cin>>b>>c;
        book[i] = {b, {c, i+1}};
    }

    sort(book, book+a, sorter);
    for (int i=0;i<a;i++)
        cout<<book[i].second.second<<endl;




}



Measured memory_bytes: 256
#include<stdio.h>

int main()
{
  int A,B,C,D,E;
  scanf("%d",&A);
  scanf("%d",&B);
  scanf("%d",&C);
  scanf("%d",&D);
  scanf("%d",&E);
  
  int a,b,c,d,e;
  int min=0;
  int i=0;
  a = A%10;
  b = B%10;
  c = C%10;
  d = D%10;
  e = E%10;
  
  if(a!=0){
  min=a;
  if(b<min & b!=0) min=b;
  if(c<min & c!=0) min=c;
  if(d<min & d!=0) min=d;
  if(e<min & e!=0) min=e;
  }
  if(b!=0){
  min=b;
  if(c<min & c!=0) min=c;
  if(d<min & d!=0) min=d;
  if(e<min & e!=0) min=e;
  if(a<min & a!=0) min=a;
  }  
  if(c!=0){
  min=c;
  if(d<min & d!=0) min=d;
  if(e<min & e!=0) min=e;
  if(a<min & a!=0) min=a;
  if(b<min & b!=0) min=b;
  }
  if(d!=0){
  min=d;
  if(e<min & e!=0) min=e;
  if(a<min & a!=0) min=a;
  if(b<min & b!=0) min=b;
  if(c<min & c!=0) min=c;
  }
  if(e!=0){
  min=e;
  if(a<min & a!=0) min=a;
  if(b<min & b!=0) min=b;
  if(c<min & c!=0) min=c;
  if(d<min & d!=0) min=d;
  }
  
  if(a==0) i++;
  if(b==0) i++;
  if(c==0) i++;
  if(d==0) i++;
  if(e==0) i++;
  
  if(min==a & a!=0){ printf("%d",B+C+D+E-(b+c+d+e)+40-10*i+A);
            }else if(min==b & b!=0){printf("%d",A+C+D+E-(a+c+d+e)+40-10*i+B);
            }else if(min==c & c!=0){printf("%d",A+B+D+E-(a+b+d+e)+40-10*i+C);
            }else if(min==d & d!=0){printf("%d",A+B+C+E-(a+b+c+e)+40-10*i+D);
            }else if(min==e & e!=0){printf("%d",A+B+C+D-(a+b+c+d)+40-10*i+E);
   }else if(min==0){printf("%d",A+B+C+D+E);
        }
  
  return 0;
  
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define pii pair <int, int>
#define fi first
#define sc second
#define ALL(x) x.begin(), x.end()
#define RALL(X) x.begin(), x.end()
#define FOR(i, n, k) for(i=0; i<n; i+=k)
#define FO(i, n, k) for(i=1; i<=n; i+=k)
#define CLEAR(a, b) memset(a, b, sizeof(a))
#define N 100005
#define mid ((l+r)/2)
#define dbg(x) (cerr << #x << " : " << x << endl)
#define endl "\n"
#define MOD 100000009

using namespace std;

typedef long long int lli;

int main(){
	ios_base::sync_with_stdio(false);
	int n, k, ans=0;
	cin >> n >> k;

	string s;
	cin >> s;

	char last = s[0];
	int cnt = 1;

	for(int i=1; i<n; i++){
		if(s[i] != last){
			cnt++;
			last = s[i];
		}

		if(s[i] == s[i-1]) ans++;
	}

	if(k >= cnt/2){
		ans = n-1;
	}else{
		ans += 2*k;
	}

	cout << ans;

	return 0;
}

Measured memory_bytes: 512
#include <iostream>

using namespace std;

int main(){
  int i;
  long long A,B,C,K;
  cin >> A >> B >> C >> K;
  if (A-B <-1000000000000000000 || A-B > 1000000000000000000) {
    cout << "Unfair" << endl;
    return 0;
  }
  if (K%2==0) {
    cout << A-B << endl;
  } else {
    cout << B-A << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <algorithm>

const int MAXN = 5e5 + 5;

template<typename _T>
void read( _T &x )
{
	x = 0;char s = getchar();int f = 1;
	while( s > '9' || s < '0' ){if( s == '-' ) f = -1; s = getchar();}
	while( s >= '0' && s <= '9' ){x = ( x << 3 ) + ( x << 1 ) + ( s - '0' ), s = getchar();}
	x *= f;
}

template<typename _T>
void write( _T x )
{
	if( x < 0 ){ putchar( '-' ); x = ( ~ x ) + 1; }
	if( 9 < x ){ write( x / 10 ); }
	putchar( x % 10 + '0' );
}

char S[MAXN];
int nxt1[MAXN], nxt2[MAXN];
int N;

void calc( int *ret )
{
	ret[1] = 0;
	for( int i = 2, j = ret[1] ; i <= N ; i ++ )
	{
		while( j && S[i] ^ S[j + 1] ) j = ret[j];
		if( S[j + 1] == S[i] ) j ++;
		ret[i] = j;
	}
}

bool chkPre( const int p ) { return nxt1[p] && p % ( p - nxt1[p] ) == 0; }
bool chkSuf( const int p ) { return nxt2[p] && p % ( p - nxt2[p] ) == 0; }
bool chk( const int p ) { return chkPre( p ) == 0 && chkSuf( N - p ) == 0; }

int main()
{
	scanf( "%s", S + 1 );
	N = strlen( S + 1 );
	calc( nxt1 ), std :: reverse( S + 1, S + 1 + N ), calc( nxt2 );
	if( nxt1[N] && N % ( N - nxt1[N] ) == 0 )
	{
		if( nxt1[N] == N - 1 ) { printf( "%d\n%d\n", N, 1 ); return 0; }
		puts( "2" ); int ans = 0;
		for( int i = 1 ; i < N ; i ++ ) 
			ans += chk( i );
		write( ans ), putchar( '\n' );
	}
	else puts( "1\n1" );
	return 0;
}

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


int main(){
  long long n;
  string s="";
  cin >>n;


  while(n>0){
    n-=1;
    s+=char(n%26 +97);
    n/=26;
    }
   reverse(s.begin(),s.end()) ;
   cout << s << endl;
}


Measured memory_bytes: 3588
# 回文かどうかを調べる関数
def is_palindrome(s: str) -> bool:
    return s[:len(s)//2] == "".join(list(reversed(s[-1*(len(s)//2):])))


a, b = [int(i) for i in input().split()]
print([is_palindrome(str(n)) for n in range(a, b+1)].count(True))

Measured memory_bytes: 3864
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma comment(linker, "/STACK:1024000000,1024000000")

#include "bits/stdc++.h"
using namespace std;

#define pb push_back
#define F first
#define S second

#define f(i,a,b)  for(int i = a; i < b; i++)
// #define endl '\n'

using ll = long long;
using db = long double;
using ii = pair<int, int>;

const int N = 1.5e5, LG = 17, MOD = 1e9+7;
const int SQ = 390;
const long double EPS = 1e-7;
int dp[405][405];
int A[405], B[405], n, C;
int VAL[405][405];
int SUM[405][405];
int solve(int idx, int cnt){
  if(idx == n)
    return !cnt;
  int &ret = dp[idx][cnt];
  if(~ret)
    return ret;
  ret = 0;
  f(pwr,0,cnt+1){
    int x = SUM[pwr][B[idx]]-SUM[pwr][A[idx]-1];
    if(x<0)x+=MOD;
    ret+=x*1ll*solve(idx+1,cnt-pwr)%MOD;
    if(ret>=MOD)ret-=MOD;
  }
  return ret;
}
int32_t main(){
#ifdef ONLINE_JUDGE
  ios_base::sync_with_stdio(0);
  cin.tie(0);
#endif // ONLINE_JUDGE

  f(i,1,405){
    VAL[i][0] = 1;
    f(j,1,405)VAL[i][j] = 1ll * i * VAL[i][j-1] % MOD;
  }
  
  f(pwr,0,405){
    f(j,1,405){
      SUM[pwr][j] = SUM[pwr][j-1] + VAL[j][pwr];
      if(SUM[pwr][j] >= MOD)SUM[pwr][j] -= MOD;
    }
  }
  memset(dp,-1,sizeof dp);
  cin >> n >> C;
  f(i,0,n)cin>>A[i];
  f(i,0,n)cin>>B[i];
  cout<<solve(0,C)<<'\n';
  return 0;
}


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

typedef long long ll; // -9,223,372,036,854,775,808 から 9,223,372,036,854,775,807

template <class T> using vec = std::vector<T>;
template <class T> using vec2 = vec<vec<T>>;
template <class T> using vec3 = vec<vec<vec<T>>>;

#define DEBUG

void solve(long long A, long long B, long long C, long long K){
    ll pts = 0;
    ll rem = K;
    if(A > rem){
        pts += rem;
        rem = 0;
    }else{
        rem -= A;
        pts += A;
    }

    if(B > rem){
        rem = 0;
    }else{
        rem -= B;
    }

    pts -= rem;

    cout << pts << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    long long C;
    scanf("%lld",&C);
    long long K;
    scanf("%lld",&K);
    solve(A, B, C, K);
    return 0;
}


Measured memory_bytes: 3760
#include<iostream>
#include<deque>
#include<vector>
#include<string>
#include<stdio.h>
#include<stdlib.h>
using namespace std;

#define SIZEOF(x) (sizeof x) / (sizeof x[0])



int main(){
    long long l ,r;
    cin >> l >> r;
    long min=2018;
    

    if((l - r)*(l-r) >= 2019*2019){
        cout<<0;
        return 0;
    }
    while (l >= 2019){
        l -= 2019;
    }
    while (r>2019){
        r-=2019;
    }
    if(l > r){
        r+= 2019;
    }
    if(l<=2019&&2019<=r)min = 0;
    else{
        for(long k = l;k<r;k++){
            for(long j = k+1;j<r+1;j++){
                if((j*k)%2019 < min)min = (j*k)%2019;
            }
        }
    }
    cout << min;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
#include <sstream>
#include <istream>

using namespace std;

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

int main(){
	int a,b,k;

	cin >> a >> b >> k;
	int m = min(a,b);
	for(;m>=1;m--){
		if(a%m==0 && b%m==0) k--;
		if(k==0) break;
	} 
	cout << m << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <unordered_set>
#include <vector>
#include <list>
#include <utility>

using namespace std;

void dfs(const vector<unordered_set<int> > &adj, const int v_id,
    vector<int> &clique_id, int &size_c1, int &size_c2){

    // cout << v_id << endl;

    for (const int &neighbor : adj[v_id]){
        if (clique_id[neighbor] != 0){
            if (clique_id[v_id] == clique_id[neighbor]){
                cout << "-1" << endl;
                exit(0);
            }   
        }
        else{
            if (clique_id[v_id] == 1){
                clique_id[neighbor] = 2;
                ++size_c2;
            }
            else {  // clique_id[v_id] == 2
                clique_id[neighbor] = 1;
                ++size_c1;
            }
            dfs(adj, neighbor, clique_id, size_c1, size_c2);
        }
    }        
}


// returns number of edges in a complete undirected graph
int num_edges(int v){
    return v * (v - 1) / 2;
}


int main()
{
    int N, M;
    cin >> N >> M;
    
    // O(N^2)
    vector<unordered_set<int> > adj;
    for (int i = 0; i < N; ++i){
        unordered_set<int> adj_set;
        for (int j = 0; j < N; ++j){
            if (i != j){
                adj_set.insert(j);                
            }
        }
        adj.emplace_back(adj_set);
    }

    // O(M) -> O(N^2)
    int v1, v2;
    for (int i = 0; i < M; ++i){
        cin >> v1 >> v2;
        adj[v1 - 1].erase(v2 - 1);
        adj[v2 - 1].erase(v1 - 1);
    }

    // O(N + M) -> O(N^2) in this question 
    vector<int> clique_id(N, 0);
    int size_c1 = 0, size_c2 = 0;
    list<pair<int, int> > clique_sizes;
    for (int i = 0; i < N; ++i){
        if (clique_id[i] == 0){
            clique_id[i] = 1;
            ++size_c1;
            
            dfs(adj, i, clique_id, size_c1, size_c2);
            
            clique_sizes.emplace_back(make_pair(size_c1, size_c2));
            size_c1 = 0;
            size_c2 = 0;
        }
    }
    
    // clique_sizes <= N/2 -> O(N^2)
    vector<bool> possible(N + 1, false);
    possible[0] = true;  // considering 0 cliques, the size of S can only be 0
    for (const auto &p : clique_sizes){
        vector<bool> possible_tmp(N + 1, false);
        for (int i = 0; i <= N; ++i){
            if (possible[i]){
                possible_tmp[i + p.first] = true;
                possible_tmp[i + p.second] = true;
            }
        }
        possible = move(possible_tmp);
    }
    
    for (int i = N / 2; i <= N; ++i){
        if (possible[i]){
            cout << num_edges(N - i) + num_edges(i) << endl;
            break;
        }
    }
    
    return 0;
}


Measured memory_bytes: 20096
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <cassert>
#include <cstdarg>
#include <sys/time.h>
#include <fstream>
//#include "cout.h"

using namespace std;

#define SZ(x) ((int)x.size())
#define MSET(x,a) memset(x, a, (int)sizeof(x))
#define PB push_back
#define VI vector < int >
#define PII pair < int, int >
#define LL long long
#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(), (v).end()
#define FIT(it,v) for (__typeof((v).begin()) it = (v).begin(); it != (v).end(); it++)
#define OUT(A) cout << #A << " = "<< (A) << endl
#define OUT2(A, B) cout << "(" << #A << ", " << #B << ") = (" << (A) << ", "<< (B) << ")" << endl
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }

#define present(c, e) ((c).find((e)) != (c).end())
#define cpresent(c, e) (find(ALL(c), (e)) != (c).end())


void solve() {
  int a, b;
  cin >> a >> b;
  if (a >= 13) {
    cout << b << endl;
  } else if (a >= 6) {
    cout << b/2 << endl;
  } else {
    cout << 0 << endl;
  }
}

int main() {
	solve();
	return 0;
}


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

bool went[50 + 10][50 + 10][50 + 10][50 + 10] = { 0 };

int map[50 + 10][50 + 10]/* = { 0 }*/;

int gx[] = { 1,0,-1,0,-1,0,1,0 };
int gy[] = { 0,1,0,-1,0,-1,0,1 };

struct ST
{
	int tx, ty;
	int kx, ky;
	int tim=0;
};

bool ChekNow(ST);


ST GoMap(ST, int);

void test(ST ex, int h, int w)
{
	int i, j;
	cout << endl;
	for (i = 1; i <= h; i++)
	{
		for (j = 1; j <= w; j++)
		{
			if ((i == ex.ky && j == ex.kx) || (i == ex.ty && j == ex.tx))
				cout << "*";
			else cout << map[i][j];
		}
		cout << endl;
	}
	cout << ex.tim << endl;
}


int main()
{
	ST now,tmp;

	queue <ST> nx;


	int w, h;
	int tsx, tsy;
	int ksx, ksy;

	bool flg;
	int i, j;

	while (cin >> w >> h, w != 0 && h != 0)
	{
		flg = true;

		cin >> tsx >> tsy;
		cin >> ksx >> ksy;
		
		for (i = 1; i <= h; i++)
		{
			map[i][0] = map[i][w + 1] = 1;

			for (j = 1; j <= w; j++)
			{
				cin >> map[i][j];
			}
		}

		for (i = 0; i <= w + 1; i++)
		{
			map[0][i] = 1;
			map[h + 1][i] = 1;
		}


		now.tx = tsx;
		now.ty = tsy;
		now.kx = ksx;
		now.ky = ksy;
		now.tim = 0;

		nx.push(now);

		while (!nx.empty()  && now.tim<100)
		{
			now = nx.front();
			nx.pop();

			/*
			if (now.tim >= 100)
			{
				break;
			}
			*/


			//if (ChekNow(now))
			//{
			//	continue;
			//}
			//went[now.tx][now.ty][now.kx][now.ky] = true;


			//test(now, h, w);


			if (now.tx == now.kx && now.ty == now.ky)
			{
				cout << now.tim << endl;

				flg = false;

				break;
			}

			for (i = 0; i < 4; i++)
			{
				//tmp=GoMap(now, i);


				tmp = now;

				if (map[now.ty + gy[i]][now.tx + gx[i]] == 0)
				{
					tmp.ty += gy[i];
					tmp.tx += gx[i];
				}
				if (map[now.ky + gy[i + 4]][now.kx + gx[i + 4]] == 0)
				{
					tmp.ky += gy[i + 4];
					tmp.kx += gx[i + 4];
				}


				if (!ChekNow(tmp))
				{
					tmp.tim++;

					went[tmp.tx][tmp.ty][tmp.kx][tmp.ky] = true;

					nx.push(tmp);
				}
			}
		}

		if (flg)
		{
			cout << "NA\n";
		}

		while (!nx.empty())
		{
			nx.pop();
		}


		memset(went, 0, sizeof(went));
	}
	return 0;
}


bool ChekNow (ST ex)
{
	return went[ex.tx][ex.ty][ex.kx][ex.ky];
}


ST GoMap(ST ex, int i)
{
	if (map[ex.ty + gy[i]][ex.tx + gx[i]] == 0)
	{
		ex.ty += gy[i];
		ex.tx += gx[i];
	}
	if (map[ex.ky + gy[i + 4]][ex.kx + gx[i + 4]] == 0)
	{
		ex.ky += gy[i + 4];
		ex.kx += gx[i + 4];
	}


	return ex;
}

Measured memory_bytes: 15840
#include <bits/stdc++.h>
#include <vector>
#include <string>
using namespace std;
#define FL(i,a,b) for(long int i = a;i<b;i++)
typedef vector<int> vi;

const int  INF = 1e9 + 5;

int main(){
    long int n;
    cin>>n;
    int arr[n];
    FL(i,0,n){
        cin>>arr[i];
    }
    int cost[n] = {INF};
    cost[0] = 0;
    cost[1] = abs(arr[1]-arr[0]);
    for(long int i = 2;i<n;i++){
        cost[i] = min(cost[i-2]+abs(arr[i]-arr[i-2]),cost[i-1]+abs(arr[i]-arr[i-1]));
    }
    cout<<cost[n-1];
    
    
}






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

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

int main()
{
    int N;
    cin >> N;
    vector<vector<int>> A(2, vector<int>(N));

    for (int i = 0; i < 2; i++) {
        for (int j = 0; j < N; j++) {
            cin >> A.at(i).at(j);
        }
    }

    int max = 0;
    for (int change = 0; change < N; change++) {
        int sum = 0;
        for (int i = 0; i <= change; i++) {
            sum += A.at(0).at(i);
        }
        for (int i = change; i < N; i++) {
            sum += A.at(1).at(i);
        }
        if (sum >= max) {
            max = sum;
        }
    }

    cout << max << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using vc = vector<char>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define debug(x) cerr << #x << ": " << x << endl;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

int main() {
    string s;
    cin >> s;
    if(s[2] == s[3] && s[4] == s[5]) cout << "Yes" << endl;
    else cout << "No" << endl;
}


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

#include<cmath>

struct Q {
	int x;
	int y;
};

int map[10002][10002] = { 0 };

int xm[] = { 1, -1, 0, 0, -1, 1 };
int ym[] = { 1, -1, -1, 1, 0, 0 };

int main() {
	int w, h, n;
	int cnt = 0;
	Q tage;
	cin >> w >> h >> n >> tage.x >> tage.y;
	Q q; q.x = tage.x; q.y = tage.y;
	for (int i = 1; i < n; ++i) {
		cin >> tage.x >> tage.y;
		while (!(q.x == tage.x && q.y == tage.y)) {
			if (q.x < tage.x && q.y < tage.y) {
				cnt++;
				q.x++; q.y++;
			}
			else if (q.x > tage.x && q.y > tage.y) {
				cnt++;
				q.x--; q.y--;
			}
			else {
				if (q.x != tage.x) {
					cnt += abs(q.x - tage.x);
					q.x = tage.x;
				}
				if (q.y != tage.y) {
					cnt += abs(q.y - tage.y);
					q.y = tage.y;
				}
			}
		}
	}

	cout << cnt << endl;

	return 0;
}

Measured memory_bytes: 3080
#include <bits/stdc++.h>
#define FIO ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);

using namespace std;

int main() {
  /**
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
  **/
	FIO
	int n; cin >> n;
	vector<string> words;
	for (int i = 0; i < n; i++) {
		string str; cin >> str;
		words.push_back(str);
	}
	vector<string> w = words;
	if (true) {
		sort(words.begin(), words.end());
		for (int i = 0; i < n-1; i++) {
			if (words[i] == words[i+1]) {
				cout << "No" << "\n";
				exit(0);
			}
		}
	}
	string lw = w[0];
    bool ans = true;
	for (int i = 1; i < n; i++) {
		if ((lw != w[i]) && (w[i][0] == lw[lw.size()-1]))
			lw = w[i];
		else {
			ans = false;
			break;
		}
	}
	(ans) ? cout << "Yes" << "\n" : cout << "No" << "\n";
	return 0;
}

Measured memory_bytes: 3640
// finish date: 2018/07/22
#include <bits/stdc++.h>

using namespace std;

#define FOR(i, a, b) for(int (i)=a;(i)<(b);(i)++)
#define rep(i, n)  FOR(i,0,n)
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>> vvvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<double> vd;
typedef vector<vector<double>> vvd;
typedef vector<vector<vector<double>>> vvvd;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<string> vs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, pair<int, int>> plii;
const int bigmod = 1000000007;
const int INF = 1050000000;
const long long INFll = 100000000000000000;


int main() {
    int N;
    cin >> N;
    vi A(N);
    ll sum = 0;
    rep(i, N) {
        cin >> A[i];
        sum += A[i];
    }
    if (sum % ((ll) N * (1 + N) / 2) != 0) {
        cout << "NO" << endl;
        return 0;
    }
    int K = (int) (sum / ((ll) N * (1 + N) / 2));

    vi d(N);
    rep(i, N) {
        d[i] = A[(i + 1) % N] - A[i] - K;
        if (d[i] > 0 || d[i] % N != 0) {
            cout << "NO" << endl;
            return 0;
        }
    }
    cout<<"YES"<<endl;

    return 0;
}



Measured memory_bytes: 1024
def modinv(a,m):
    return pow(a,m-2,m)

import copy

S = input()
N = len(S)
dp = [[[0,0], [0,0,0], [0,0,0,0]] for i in range(N+1)]
mod = 10**9 + 7

for i in range(N):
    dp[i+1] = copy.deepcopy(dp[i])
    if S[i] == 'A':
        dp[i+1][0][0] += 1

    elif S[i] == 'B':
        for j in range(2):
            dp[i+1][1][j] = (dp[i+1][1][j] + dp[i][0][j])%mod

    elif S[i] == 'C':
        for j in range(3):
            dp[i+1][2][j] = (dp[i+1][2][j] + dp[i][1][j])%mod

    else:
        dp[i+1][0][1] += 1
        for j in range(2):
            dp[i+1][1][j+1] = (dp[i+1][1][j+1] + dp[i][0][j])%mod
        for j in range(3):
            dp[i+1][2][j+1] = (dp[i+1][2][j+1] + dp[i][1][j])%mod

Q = S.count('?')

inv3 = modinv(3,mod)
inv9 = inv3*inv3%mod
inv27 = inv9*inv3%mod
threeQ = pow(3,Q,mod)

ans = threeQ * (dp[N][2][0] + dp[N][2][1]*inv3 + dp[N][2][2]*inv9 + dp[N][2][3]*inv27) % mod
print(ans)

Measured memory_bytes: 59416