akhauriyash/Code-Regression huggingface dataset:
//file_name:ABC55_B.cpp
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>inline ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
const int MX = 200005;

    // int scan
    /*
    int x;
    scanf("%d",&x);
    int y;
    scanf("%d",&y);
    int z;
    scanf("%d",&z);

    // matrix scan
    /*
    ll a[n] = {};
    rep(i,n){
        scanf("%lld",&a[i]);
    }
    */

    // string scan
    /*
    string s;
    cin >> s;
    */


int main() {
    int n;
    scanf("%d",&n);


    ll ans = 1;

    srep(i,1,n+1){
        ans *= i;
        ans %= 1000000007;
    }

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



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

using namespace std;

int main(){
    string s, t;
    cin >> s >> t;
    if((s == t.substr(0, s.size())) && (s.size()+1 == t.size())){
        cout << "Yes\n";
    }else{
        cout << "No\n";
    }
    return 0;
}

Measured memory_bytes: 3628
# AOJ 1172: Chebyshev's Theorem
# Python3 2018.7.14 bal4u

from bisect import bisect_left

MAX = 250000
SQRT = 500     # sqrt(MAX)

f = [True]*MAX
prime = [2]
def sieve():
#	for i in range(2, MAX, 2): f[i] = False
	for i in range(3, SQRT, 2):
		if f[i]:
			for j in range(i*i, MAX, i): f[j] = False
	for i in range(3, MAX, 2):
		if f[i]: prime.append(i)
			
sieve()
while True:
	n = int(input())
	if n == 0: break
	if n == 1: print(1)
	else:
		a = bisect_left(prime, n<<1)
		if prime[a] != n<<1: a -= 1
		print(a-bisect_left(prime, n+1, 0, a)+1)



Measured memory_bytes: 8392
#include <iostream>                                                             

using namespace std;

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


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

int main(){
  char ch;
  int cnt[26]={};

  while(cin>>ch){
    ch=tolower(ch);
    if(isalpha(ch)){
      cnt[ch-'a']++;
    }
  }

  for(int i=0;i<26;i++){
    printf("%c : %d\n",i+'a',cnt[i]);
  }
  return 0;
}


Measured memory_bytes: 3228
n=int(input())
c,f=0,0
while(n>0):
  a,b=map(int,input().split())
  if(a==b):
    c+=1
  else:
    c=0
  if(c>=3):
    f=1
    break
  n-=1
if(f==1 or c>=3):
  print("Yes")
else:
  print("No")

Measured memory_bytes: 9176
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
char ans[105][105];

void init()
{
	rep(i,105)
	{
		rep(j,105)
		{
			ans[i][j] = '.';
		}
	}
}

int main()
{
	int A,B;
	cin >> A >> B;
	swap(A,B);
	init();
	int tempi = 0, tempj = 0;
	while(A > 0)
	{
		ans[tempi][tempj] = '#';
		A--;
		if (tempj == 98)
		{
			tempi += 2;
			tempj = 0;
		}
		else
		{
			tempj += 2;
		}
	}
	if (tempj == 0)
	{
		tempi -= 2;
		tempj = 98;
	}
	else
	{
		tempj -= 2;
	}
	ans[tempi][tempj] = '.';
	tempi++;
	ans[tempi][tempj] = '#';
	tempi++;
	for (int i = tempi; i < 100; ++i)
	{
		rep(j,100)
		{
			ans[i][j] = '#';
		}
	}
	tempi++;
	B--;
	tempj = 0;
	while(B > 0)
	{
		ans[tempi][tempj] = '.';
		B--;
		if (tempj == 98)
		{
			tempi += 2;
			tempj = 0;
		}
		else
		{
			tempj += 2;
		}
	}

	cout << "100 100" << endl;
	rep(i,100)
	{
		rep(j,100)
		{
			cout << ans[i][j];
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;

#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--)
#define repa(i,n) for (auto& i: n)

template<class T> inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
void init() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(15);}

#ifdef DEBUG
template <class T, class N> void verr(const T& a, const N& n) { rep(i, n) cerr << a[i] << " "; cerr << "\n" << flush; }
ll dbgt = 1; void err() { cerr << "passed " << dbgt++ << "\n" << flush; }
template<class H, class... T> void err(H&& h,T&&... t){ cerr<< h << (sizeof...(t)?" ":"\n") << flush; if(sizeof...(t)>0) err(forward<T>(t)...); }
#endif

const ll INF = 4e18;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
//--------------------------------------------------------------------------------//

int main() {
    init();
    ll N, base = 1e9, digit = 9;
    cin >> N;
    vl A;
    rep(_, N) {
        string S, s, t;
        bool iss = false;
        cin >> S;
        rep(i, S.size()) {
            if (S[i] == '.') iss = true;
            else if (iss) {
                t += S[i];
            } else {
                s += S[i];
            }
        }
        repa(c, t) s += c;
        rep(_, digit - t.size()) s += '0';
        A.eb(stoll(s));
    }

    vvc<ll> cnt(21, vl(21));
    rep(i, N) {
        ll c2 = 0, c5 = 0, tv = A[i];
        while (tv % 2 == 0) c2++, tv /= 2;
        while (tv % 5 == 0) c5++, tv /= 5;
        chmin(c2, 18ll), chmin(c5, 18ll);
        cnt[c2][c5]++;
    }

    ll ans = 0;
    rep(i, 19) rep(j, 19) repe(k, 19 - i - 1, 19) repe(l, 19 - j - 1, 19) {
        if (i == k and j == l) {
            ans += cnt[i][j] * (cnt[i][j] - 1);
        } else {
            ans += cnt[i][j] * cnt[k][l];
        }
    }
    ans /= 2;
    cout << ans << endl;
}

Measured memory_bytes: 5312
#include <iostream>
#include <vector>
#include <queue>

using namespace std;

int main() {
    int N;
    cin >> N;
    vector<vector<int> > E(N+1);
    for(int n=1; n<N; n++) {
        int a, b;
        cin >> a >> b;
        E[a].push_back(b);
        E[b].push_back(a);
    }
    
    vector<int> fdis(N+1, -1);
    vector<int> sdis(N+1, -1);
    fdis[1]=0;
    sdis[N]=0;
    
    queue<int> que;
    que.push(1);
    while(!que.empty()) {
        int cur=que.front(); que.pop();
        
        for(int i=0; i<E[cur].size(); i++) {
            if(fdis[E[cur][i]]!=-1) continue;
            fdis[E[cur][i]] = fdis[cur]+1;
            que.push(E[cur][i]);
        }
    }
    que.push(N);
    while(!que.empty()) {
        int cur=que.front(); que.pop();
        
        for(int i=0; i<E[cur].size(); i++) {
            if(sdis[E[cur][i]]!=-1) continue;
            sdis[E[cur][i]] = sdis[cur]+1;
            que.push(E[cur][i]);
        }
    }
    
    int ans=0;
    for(int n=1; n<=N; n++) {
        if(sdis[n]<fdis[n]) {
            ans++;
        }
    }
    if(N-ans<=ans) {
        cout << "Snuke" << endl;
    } else {
        cout << "Fennec" << endl;
    }


    return 0;
    
}

Measured memory_bytes: 6528
#include <bits/stdc++.h>
#define rep(i, start, end) for (long long i = start; i < end; ++i)
#define repreverse(i, start, end) for (long long i = start; i >= end; --i)
#define all(x) (x).begin(), (x).end()
#define len(x) ((long long)(x).size())
#define lcm(a, b) ((a) / __gcd((a), (b)) * (b))
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vllvll = vector<vll>;
using pll = pair<ll, ll>;
template<class T>void print1d(T x,ll n=-1){if(n==-1)n=x.size();rep(i,0,n){cout<<x[i]<<' ';}cout<<'\n';}
template<class T>void print2d(T x,ll r=-1,ll c=-1){if(r==-1)r=x.size();if(c==-1)c=x[0].size();rep(i,0,r)print1d(x[i],c);}
template<class T, class U>bool haskey(T mp, U key) { return mp.find(key) != mp.end(); }
template<class T, class U>bool isin(T el, U container) { return find(all(container), el) != container.end(); }
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
template<class T>bool even(T n) { return ! (n & 1); }
template<class T>bool odd(T n) { return n & 1; }
template<class T>ld deg2rad(T deg) { return M_PI * deg / 180.0; }
template<class T>ld rad2deg(T rad) { return 180.0 * rad / M_PI; }
ll intpow(ll a,ll n){ll p=1;while(n){if(n&1)p*=a;a*=a;n>>=1;}return p;}
const long double pi = M_PI;
const long long big = 1LL << 50;
const long long inf = 1LL << 60;
const long long mod = 1e9 + 7;



int main()
{
        ll N;
        cin >> N;
        vll s(N);
        rep(i, 0, N) cin >> s[i];

        sort(all(s));

        ll sm = accumulate(all(s), 0LL);
        if (sm % 10 != 0) {
                cout << sm << endl;
                return 0;
        }
        rep(i, 1, 101) {
                if ((sm - i) % 10 != 0 and isin(i, s)) {
                        cout << sm-i << endl;
                        return 0;
                }
        }
        cout << 0 << endl;
}

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

using namespace std;
using ll =long long;
using vi = vector<int>; 
using vvi = vector<vi>; 
using vl = vector<ll>; 
using vvl = vector<vl>; 
using vs = vector<string>;
using vvs = vector<vs>; 
using vc = vector<char>;
using vvc = vector<vc>; 
using vb = vector<bool>;
using vvb = vector<vb>; 

#define rep(i,n) ;for( int i =0; i < n ; i ++)
#define all(a) a.begin(),a.end()
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define f(i,a,b) for(int i=a;i<b;i++)
#define pri(a)  printf("%.14lf\n",a);
#define MOD 1000000007
bool is_int_lround(double x){
  return std::lround(x)==x;
}
ll keta(ll x){
  int n=0;
  while(x>0){
    x /=10 ;
    n ++;
  }
  return n;
}

ll conbi(int n,int m){
  
  cin>>n>>m;
  vector<ll> a(100);
  a[0] =1;
  for(int i=0;i<14;i++){
    a[i+1]=a[i]*(i+1);
  }
  return a[n] /(a[m] *a[n-m]);
}

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
int main(){
  ll n,a,b;cin>>n>>a>>b;
  
  ll bunboa=1,bunsia=1;
  for(ll i=1;i<=min(a,n-a);i++){
    bunboa *=i;
    bunboa %=MOD;
  }
  
  for(ll i=max(a,n-a)+1;i<=n;i++){
    bunsia *=i;
    bunsia %=MOD;
  }
  ll bunsib=1,bunbob=1;
  for(ll i=1;i<=min(b,n-b);i++){
    bunbob *=i;
    bunbob %=MOD;
  }
  
  for(ll i=max(b,n-b)+1;i<=n;i++){
    bunsib *=i;
    bunsib %=MOD;
  }
  ll ans1 =bunsia* modpow(bunboa,MOD-2,MOD)%MOD;
  ll ans2 =bunsib* modpow(bunbob,MOD-2,MOD)%MOD;
  
  ll ans=modpow(2,n,MOD)-1;
  ll res =ans-ans1-ans2;
 
  while(res<0) {
    res +=MOD;
  }
    cout<< res<<endl;
  

}
  


Measured memory_bytes: 256
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
using LL = long long;
const LL LINF = 1e18;
const double EPS = 1e-10;
using namespace std;
#define COUT(v) cout<<(v)<<endl
#define CIN(n)  int(n);cin >> (n)
#define LCIN(n) LL(n);cin >> (n)
#define SCIN(n) string(n);cin >> (n)
#define YES(n) cout<<((n)? "YES" : "NO")<<endl
#define Yes(n) cout<<((n)? "Yes" : "No")<<endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) <<endl

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

#define FOREACH(x,a) for(auto& (x) : (a) )

#define ALL(obj) (obj).begin(),(obj).end()

#define P pair<int,int>
#define I vector<int>
#define pb(v) push_back(v)
#define V vector
#define rt return
#define rmsame(a) sort(ALL(a)),a.erase(unique(ALL(a)), a.end())
#define ENDL cout<<endl
#define MAXE(a,b) a=max(a,b)
#define MINE(a,b) a=min(a,b)

typedef string::const_iterator State;
class PalseError {};
class Edge{
public:
    int from,to,value;
    Edge(LL a,LL b,LL c){
        from = a;
        to = b;
        value = c;
    }
    Edge(LL a,LL b){
        from = a;
        to = b;
    }
};
LL gcd(LL a,LL b){
    if(b == 0)return a;
    return gcd(b, a % b);
}
int main(){
    LL N, K;
    cin >> N >> K;
    LL ins = 1;
    LL ma = 0;
    for(int a = 0;a < N;a++){
        LCIN(b);
        ma = max(ma,b);
        if(a != 0)ins = gcd(ins,b);
        else ins = b;
    }
   // cout<<K<<" "<<ma<<" "<<ins<<endl;
    POSSIBLE(ma >= K && !(K % ins));
    return 0;
}


Measured memory_bytes: 256
n = int(input())
last = ""
flg = 0
li = []
for i in range(n):
    s = input()
    str = list(s)  # 一文字ずつ格納
    if last == "":
        last = str[-1]
        li.append(s)
        continue

    if str[0] != last or s in li:
        flg = 1

    last = str[-1]
    li.append(s)


if flg == 0:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 3064
#include <iostream>

using namespace std;

int am[303];
char fin[103][103];

int main() {

    ios::sync_with_stdio(false);

    int n,m;
    cin >> n >> m;
    char x;

    for(int i = 1; i <= n; i++) {
        for(int j = 1; j <= m; j++) {
            cin >> x;
            am[x]++;
        }
    }

    bool has1 = (n%2);
    bool has2 = (m%2);
    int pnt = 'a';

    for(int i = 1; i <= n/2; i++) {
        for(int j = 1; j <= m/2; j++) {

            if(pnt > 'z') {
                cout << "No";
                return 0;
            }

            if(am[pnt] >= 4) {

                am[pnt] -= 4;
                fin[i][j] = pnt;
                fin[n-i+1][j] = pnt;
                fin[i][m-j+1] = pnt;
                fin[n-i+1][m-j+1] = pnt;

            } else {

                j--;
                pnt++;

            }

        }
    }

    if(has1) {
        pnt = 'a';
        for(int j = 1; j <= m/2; j++) {
            if(pnt > 'z') {
                cout << "No";
                return 0;
            }
            if(am[pnt] >= 2) {
                am[pnt] -= 2;
                fin[n/2+1][j] = pnt;
                fin[n/2+1][m-j+1] = pnt;
            } else {
                j--;
                pnt++;
            }
        }
    }

    if(has2) {
        pnt = 'a';
        for(int i = 1; i <= n/2; i++) {
            if(pnt > 'z') {
                cout << "No";
                return 0;
            }
            if(am[pnt] >= 2) {
                am[pnt] -= 2;
                fin[i][m/2+1] = pnt;
                fin[n-i+1][m/2+1] = pnt;
            } else {
                i--;
                pnt++;
            }
        }
    }

    if(has1 && has2) {

        for(pnt = 'a'; pnt <= 'z'; pnt++) {
            if(am[pnt] != 0)
                break;
        }

        fin[n/2+1][m/2+1] = pnt;
        am[pnt]--;

    }

    cout << "Yes" << '\n';

    /*for(int i = 1; i <= n; i++) {
        for(int j = 1; j <= m; j++)
            cout << fin[i][j];
        cout << '\n';
    }*/

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include <stdio.h>

using namespace std;

int max_of_array(int n[], int len){
  int i, ans;
  ans = n[0];
  for (i=1;i<len; i++) {
    if (ans < n[i]) ans = n[i];
  }
  return ans;
}

int main(){
  int N;
  cin >> N;
  int a[3][N+1];
  for(int i=1;i<N+1;i++){
    cin >> a[1][i];
  }
  for(int j=1;j<N+1;j++){
    cin >> a[2][j];
  }
  int c[N+1];
  c[0]=0;
  for(int k=1;k<N+1;k++){
    c[k] = 0;
    for(int l=1;l<N+1;l++){
    if(k>l){
      c[k]+=a[1][l];
    }
    else if(k==l){c[k]+=(a[1][l]+a[2][l]);}
    else{c[k]+=a[2][l];}
    }
  }
  cout << max_of_array(c,N+1) << endl;
  return 0;
}


Measured memory_bytes: 256
//include
//------------------------------------------
#include <iostream>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
using namespace std;

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

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//debug
//-------------------------------------------
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

vector<string> island(12);

void dfs(int i, int j) {
    island[i][j] = '0';

    if (i < 11 && island[i + 1][j] == '1') {
        dfs(i + 1, j);
    }
    if (j < 11 && island[i][j + 1] == '1') {
        dfs(i, j + 1);
    }
    if (j > 0 && island[i][j - 1] == '1') {
        dfs(i, j - 1);
    }
    if (i > 0 && island[i - 1][j] == '1') {
        dfs(i - 1, j);
    }

    return;
}

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

    while(1) {
        REP(i, 12) {
            if (!(cin >> island[i])) {
                return 0;
            }
        }

        int cnt = 0;
        REP(i, 12) REP(j, 12) {
            if (island[i][j] == '1') {
                dfs(i, j);
                cnt++;
            }
        }
        cout << cnt << endl;
    }

    return 0;
}

Measured memory_bytes: 3204
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (k); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) begin(a),end(a)
#define MS(m,v) memset(m,v,sizeof(m))
#define D10  fixed<<setprecision(10)
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> P;
typedef complex<double> Point;
typedef long long ll;
const int INF = 114514810;
const int MOD = 1000000007;
const double EPS = 1e-10;
const double PI = acos(-1.0);
struct edge
{
	int from, to, cost;
	bool operator < (const edge& e) const { return cost < e.cost; }
	bool operator >(const edge& e) const { return cost > e.cost; }
};
///*************************************************************************************///
///*************************************************************************************///
///*************************************************************************************///

int m, n;
int book[105];

bool check(int bre)
{
	int cnt = 0;
	int tmp = 0;
	REP(i, n)
	{
		if (cnt > m || book[i]>bre) return false;
		if (tmp + book[i] > bre)
		{
			cnt++;
			tmp = book[i];
		}
		else
		{
			tmp += book[i];
		}
	}
	return cnt < m;
}

int main()
{
	while (cin >> m >> n, m)
	{
		REP(i, n) cin >> book[i];
		int lb = 0; int ub = 2000000;
		while (ub - lb > 1)
		{
			int mid = (ub + lb) / 2;
			if (check(mid)) ub = mid;
			else lb = mid;
		}
		cout << ub << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <stdio.h>
using namespace std;


int num[1000];
int len = 0;
int N ;
int M ;

int main(void){
    // Your code here!
    
    string s;
    int i = 0;
    
    cin >> N;
    cin >> M;
    
    int sum = 0;
    while(cin>>s){
      //  cout << s << endl;
        num[len] = stoi(s);
        sum += num[len];
        len += 1;
    }
    //cout << len << endl;
    
    float thres = 1.0 / (4.0 * M);
    int count = 0;
    for (int i = 0; i < N; i++) {
        if ((float)num[i] >= sum * thres) {
            count++;
        }
    }
    
    if (count >= M) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ft first
#define sc second
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define pt(sth) cout << sth << "\n"
#define chmax(a, b) {if(a<b) a=b;}
#define chmin(a, b) {if(a>b) a=b;}
#define moC(a, s, b) (a)=((a)s(b)+MOD)%MOD
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
static const ll INF=1e18;
static const ll MAX=1e5+7;
static const ll MOD=1e9+7;
ll max(ll a, ll b) {return a>b?a:b;}
ll min(ll a, ll b) {return a<b?a:b;}

ll moP(ll x, ll n) {
  ll res=1;
  while(n>0) {
    if(n&1) moC(res, *, x);
    moC(x, *, x);
    n>>=1;
  }
  return res;
}

int main(void) {
  ll N;
  cin >> N;
  ll i;
  ll Nfa=1;
  ll s[MAX]={};
  
  for(i=1; i<=N; i++) moC(Nfa, *, i);
  
  for(i=1; i<=N; i++) {
    s[i]=(s[i-1]+moP(i, MOD-2))%MOD; // 1/i の累積和
  }
  
  ll ans=0;
  for(i=1; i<=N; i++) {
    ll a;
    cin >> a;
    moC(ans, +, (s[i]+s[N-i+1]-s[1]+MOD)*Nfa%MOD*a%MOD);
  }
  
  pt(ans);
}












Measured memory_bytes: 1024
import sys
def S(): return sys.stdin.readline().rstrip()
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())
INF = 1000000000000

x = LI()

for i in range(5):
    if(x[i] == 0):
        print(i+1)
        break

Measured memory_bytes: 9184
# TLEするので、自前で用意せずに、ライブラリ使おう
# https://juppy.hatenablog.com/entry/2019/02/24/ABC119_-D_Lazy_Faith-_Python_%E7%AB%B6%E6%8A%80%E3%83%97%E3%83%AD%E3%82%B0%E3%83%A9%E3%83%9F%E3%83%B3%E3%82%B0_Atcoder

import bisect
A, B, Q = map(int, input().split())
S = sorted([int(input()) for i in range(A)])
T = sorted([int(input()) for i in range(B)])
X = [int(input()) for i in range(Q)]

s_size = A
t_size = B
inf = 99999999999999

for x in X:
  s_index = bisect.bisect_left(S, x)
  s_left = S[s_index - 1] if s_index > 0 else None
  s_right = S[s_index] if s_index < s_size else None
  t_index = bisect.bisect_left(T, x)
  t_left = T[t_index - 1] if t_index > 0 else None
  t_right = T[t_index] if t_index < t_size else None

  ans = inf

  sl = [s_left, s_right]
  tl = [t_left, t_right]

  for s in sl:
    if not s: continue
    c1 = abs(x - s)
    for t in tl:
      if not t: continue
      ans = min(ans, c1 + abs(s-t))


  for t in tl:
    if not t: continue
    c1 = abs(x - t)
    for s in sl:
      if not s: continue
      ans = min(ans, c1 + abs(s-t))

  print(ans)




Measured memory_bytes: 16160
#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;

int main(){
  string s, t; cin >> s >> t;
  int N = s.size(), M = t.size();
  vector<vector<int> > dp(N + 1, vector<int> (M + 1, INF));
  for(int i = 0; i <= N; i++) dp[i][0] = i;
  for(int i = 0; i <= M; i++) dp[0][i] = i;
  for(int i = 1; i <= N; i++){
    for(int j = 1; j <= M; j++){
      dp[i][j] = min(dp[i - 1][j] + 1, dp[i][j - 1] + 1);
      dp[i][j] = min(dp[i][j], dp[i - 1][j - 1] + (s[i - 1] != t[j - 1]));
    }
  }
  cout << dp[N][M] << endl;
}
  


Measured memory_bytes: 6924
#include <iostream>

using namespace std;

int main() {
    int n,m;
    cin >> n >> m;

    int a[n][m];
    int b[m];

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            int in;
            cin >> in;
            a[i][j] = in;
        }
    }

    for (int i = 0; i < m; i++) {
        int in;
        cin >> in;
        b[i] = in;
    }

    for (int i = 0; i < n; i++) {
        int res = 0;
        for (int j = 0; j < m; j++) {
            res += a[i][j] * b[j];
        }
        cout << res << endl;
    }
    return 0;
}

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

using namespace std;

int main(){
	int n,a,b;
	cin >> n >> a >>b;
	string s;
	cin >> s;
	for(int unsigned i=0;i<s.size();i++){
		if(s[i] == 'a'){
			if(a+b > 0){
				cout << "Yes" << endl;
				if(a>0) a--;
				else if(b>0) b--;
			} else {
				cout << "No" << endl;
			}
		} else if(s[i] == 'b'){
			if(b > 0){
				cout << "Yes" << endl;
			} else {
				cout << "No" << endl;
			}
			if(b>0) b--;
		} else {
			cout << "No" << endl;
		}
	}
	
	return 0;
}

Measured memory_bytes: 896
#include <stdio.h>

int main()
{
   int n;
   scanf("%d", &n);

   int p[n];
   for (int i = 0; i < n; i++)
      scanf("%d", &p[i]);

   int count = 0;
   int q[3] = {0};

   for (int i = 0; i < n-2; i++) {
      q[0] = p[i];
      q[1] = p[i+1];
      q[2] = p[i+2];

      if ((q[0] < q[1] && q[1] < q[2]) || (q[2] < q[1] && q[1] < q[0]))
         count++;
   }

   printf("%d\n", count);
   return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <cstring>
#include <queue>
#include <algorithm>
#include <stdio.h>
#include <map>
using namespace std;

int main()
{
    int t;
    cin>>t;
    if(t>=30)
    {
        cout<<"Yes"<<endl;
    }
    else
    {
        cout<<"No"<<endl;
    }
    return 0;
}



Measured memory_bytes: 3568
from collections import deque

N , M = map(int, input().split())
friends = [list() for _ in range(N+1)]
for _ in range(M):
    h1, h2 = map(int, input().split())
    friends[h1].append(h2)
    friends[h2].append(h1)

f_group = [0]*(N+1)
q = deque()
cnt = 0
mem_num_max = 0
while cnt < N:
    for i in range(N):
        mem_num = 0
        if f_group[i] == 0:
            q.append(i)
            f_group[i] = i
            cnt += 1
            mem_num += 1

        while len(q):
            now = q.popleft()

            for h in friends[now]:
                if f_group[h] == 0:
                    f_group[h] = f_group[now]
                    q.append(h)
                    cnt += 1
                    mem_num += 1
        
        mem_num_max = max(mem_num_max, mem_num)

print(mem_num_max)

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

int N, M;
string S;
vi va, vb;

int a, b, c;
void input() {
  cin >> a >> b >> c;
  cout << (((a <= c && c <= b) || (a >= c && c >= b)) ? "Yes" : "No") << endl;
  ;
  ;
}
void solve() {
  ;
  ;
}
signed main() {
  input();
  solve();
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <limits>
#include <algorithm>
#include <functional>

#include <vector>

using namespace std;

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

	int N, K;
	cin >> N >> K;

	vector<bool> digit_list(10, false);

	for (int i = 0; i < K; i++)
	{
		int d;
		cin >> d;
		digit_list[d] = true;
	}

	int val = N;
	while (true)
	{
		string nstr = to_string(val);

		bool check = true;
		for (int i = 0; i < nstr.size(); i++)
		{
			for (int j = 0; j < digit_list.size(); j++)
			{
				if (digit_list[j] && (nstr[i] - '0') == j)
				{
					check = false;
					break;
				}
			}

			if (!check) break;
		}

		if (check)
		{
			cout << val;
			break;
		}

		val++;
	}
	
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>


int main(){
	int x, y, a, b, c;
	scanf("%i %i", &x, &y);
	a=x+y;
	b=x+(x-1);
	c=y+(y-1);
	if(a>=b&&a>=c)
		printf("%i\n", a);
	else if(b>=c)
		printf("%i\n", b);
	else
		printf("%i\n", c);
}

Measured memory_bytes: 128
/*
 * Author : Andrew J
*/
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
using ll = long long;
using ii = pair <ll , ll>;
void in(ll &x);
const ll N = 1e4 + 10;
const ll M = 1e9 + 7;
char s[N];
ll n, d;
ll dp[N][105][2];

ll ctoi(char x) {
  return x - '0';
}

ll add(ll a , ll b) {
  return ((a % M) + (b % M)) % M;
}

ll subs(ll a , ll b) {
  return (((a % M) - (b % M)) + 2 * M) % M;
}

ll f(ll cur , ll modulo , bool isFree) {
  if (cur >= n) return modulo == 0;
  ll &sol = dp[cur][modulo][isFree];
  if (sol != -1) return sol;
  sol = 0;
  if (!isFree) {
    for (ll i = 0 ; i < ctoi(s[cur]) ; i++) {
      sol = add(sol , f(cur + 1 , (modulo + i) % d , 1));
    }
    sol = add(sol , f(cur + 1 , (modulo + ctoi(s[cur])) % d , 0));
  } else {
    for (ll i = 0 ; i < 10 ; i++) {
      sol = add(sol , f(cur + 1 , (modulo + i) % d , 1));
    }
  }
  return sol;
}

int main() {
  scanf("%s" , s);
  n = strlen(s);
  scanf("%d" , &d);
  memset (dp , -1 , sizeof dp);
  ll sol = 0;
  for (ll i = 0 ; i < ctoi(s[0]) ; i++) {
    sol = add(sol , f(1 , (i % d) , 1));
  }
  sol = add(sol , f(1 , ctoi(s[0]) % d , 0));
  printf("%lld\n" , subs(sol , 1));
  return 0;
}

void in(ll &x){
	bool neg = false;
	register ll c;
	x = 0;
	c = getchar();
	if(c == '-'){
		neg = true;
		c = getchar();
	}
	for (; c > 47 && c < 58; c = getchar())
	x = (x << 1) + (x << 3) + c - 48;
	if (neg) x *= -1;
}


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

#define watch(x) cerr << (#x) << ": " << (x) << endl


int32_t main() {

    int p, q, r; cin >> p >> q >> r;
    int ans = p+q+r - max(p, max(q, r));
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int MX = 1e5;
int main(){
  vector<int> x(5);
  for (int i=0; i<5; i++) cin >> x[i];
  for (int i=0; i<5; i++){
    if (x[i]==0){
      cout << i+1 << endl;
      return 0;
    }
  }
}

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

using namespace std;

using int64 = long long;

struct INFTY {
  const int64 infll = (1LL << 62) - 1;
  const int inf = (1 << 30) - 1;

  operator int64() { return infll; }

  operator int() { return inf; }
} inf;

struct IoSetup {
  IoSetup() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    cerr << fixed << setprecision(10);
  }
} iosetup;

template< typename T >
ostream &operator<<(ostream &os, const vector< T > &v) {
  for(int i = 0; i < (int) v.size(); i++) {
    os << v[i] << (i + 1 != v.size() ? " " : "");
  }
  return os;
}

template< typename T >
istream &operator>>(istream &is, vector< T > &v) {
  for(T &in : v) is >> in;
  return is;
}

template< typename T1, typename T2 >
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }

template< typename T1, typename T2 >
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

template< typename T = int64 >
vector< T > make_v(size_t a) {
  return vector< T >(a);
}

template< typename T, typename... Ts >
auto make_v(size_t a, Ts... ts) {
  return vector< decltype(make_v< T >(ts...)) >(a, make_v< T >(ts...));
}

template< typename T, typename V >
typename enable_if< is_class< T >::value == 0 >::type fill_v(T &t, const V &v) {
  t = v;
}

template< typename T, typename V >
typename enable_if< is_class< T >::value != 0 >::type fill_v(T &t, const V &v) {
  for(auto &e : t) fill_v(e, v);
}

int main() {
  int N, K;
  cin >> N >> K;
  if(K == 1 || K == 2 * N - 1) {
    cout << "No" << endl;
    return 0;
  }
  cout << "Yes" << endl;
  if(N == 2) {
    cout << "1 2 3" << endl;
    return 0;
  }

  vector< int > ans(2 * N - 1, -1);
  if(K != 2) {
    ans[N - 2] = K - 1;
    ans[N - 1] = K;
    ans[N] = K + 1;
    ans[N + 1] = K - 2;
  } else {
    ans[N - 2] = K + 1;
    ans[N - 1] = K;
    ans[N] = K - 1;
    ans[N + 1] = K + 2;
  }

  vector< int > used(2 * N);
  for(auto &p : ans) if(~p) used[p] = true;
  int now = 1;
  for(auto &p : ans) {
    if(~p) continue;
    while(used[now]) ++now;
    used[now] = true;
    p = now;
  }
  for(auto &p : ans) cout << p << endl;
}


Measured memory_bytes: 3072
// 全然わからないので解説PDFを読む
//
// * すべての整数は1から初めて+1 or *10の操作で到達できる
// * +1すると桁和は1増え、*10すると桁和は変わらない
// までは理解できたのだが、mod Kする操作が理解できなかった
//
// 以下のように考えてなんとなく理解できた
//
// K = 7の場合を考える。
// もし7の倍数のいずれかが1, 10, 100, 1000, ... のどれかになれば答は最小の1になる。
// しかし、上記数列のmod 7を調べると1, 3, 2, 6, 4, 5, 1, ...の
// ループになりそうなことがわかる
// つまり残念ながら答が1になることはない。
//
// しかし、上記のループの中に"6"がある。これは1000に相当する。
// ここに+1すると1001で、mod 7は0になる。答は1にはなりえないので、
// 答は2である。
//
// 上の考察からもう少し飛躍させると、解答PDFのようなグラフになる。
//
// もし回答として桁和が最小になる数を答える必要がある場合は、
// グラフの0の辺をたどるたびに*10, 1の辺をたどるたびに+1すればよい


#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>


using namespace std;
typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;

#define REP(i,n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i,a,b) for(int i = (a); i < (int)(b); ++i)
#define ALL(c) (c).begin(), (c).end()
#define SIZE(v) ((int)v.size())

#define pb push_back
#define mp make_pair
#define mt make_tuple

int main(void)
{
    cin.sync_with_stdio(false);
    int K;
    cin >> K;

    // 01-BFS
    deque<int> dq;
    vector<int> best(K, 1e9);
    vector<char> seen(K);
    dq.push_back(1);
    best[1] = 1;
    while (!dq.empty()) {
        int v = dq.front(); dq.pop_front();

        // *10に相当
        int v2 = (v * 10) % K;
        if (best[v2] > best[v]) {
            best[v2] = best[v];
            dq.push_front(v2);
        }

        // +1に相当
        int v3 = (v + 1) % K;
        if (best[v3] > best[v] + 1) {
            best[v3] = best[v] + 1;
            dq.push_back(v3);
        }
    }

    cout << best[0] << endl;
    return 0;
}


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

int main()
{
	int N,i,j,tmp=0,len[110];
	cin >> N;
	string W[101];
	for(i=0; i<N; i++){
		cin >> W[i];
	}
	bool ans = true;
	for(i=0; i<N; i++){
		for(int j=0; j<i; j++){
			if(W[i] == W[j])
			ans = false;
		}
	}
	for(i=0; i<N-1; i++){
		if(W[i][W[i].length()-1] != W[i+1][0])
		ans = false;
	}
	if(ans)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
			
	return 0;
}


Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;

pub fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

use std::cmp::min;

fn main() {
    let a: i64 = read();
    let b: i64 = read();
    let c: i64 = read();

    for i in 0..b {
        let ai = a * i;
        if ai % b == c {
            println!("YES");
            return;
        }
    }
    println!("NO")
}


Measured memory_bytes: 4352
import itertools

n,m = map(int,input().split())

a = [list(sorted(map(int, input().split()))) for i in range(m)]
a.sort()

cnt = 0

for i in itertools.permutations(range(2, n +1), (n-1)):
    li = [1] + list(i)
    if sum(list(sorted(edge)) in a for edge in zip(li, li[1:])) == n-1:
        cnt += 1
    
print(cnt)
    

Measured memory_bytes: 3064
#include<iostream>
//#include<cmath>
//#include <algorithm>
//#include<vector>
//typedef long long int ll;
#define fr(x,y) for(int x=0;x<y;x++)


using namespace std;

int main() {
	int n, k, c;
	cin >> n >> k >> c;
	string s;
	cin >> s;
	bool* start = new bool[n], * end = new bool[n];
	int count = 0;
	fr(i, n) {
		start[i] = end[i] = false;
	}
	fr(i, n)
	{
		//cout << "i is " << i << endl;
		if (s[i] == 'x' ) continue;
		//cout << "enter" << endl;
		count++;
		start[i] = true;
		i = i + c;
		if (count > k) return 0;

	}
	count = 0;
	for (int i = n - 1; i >= 0; i--) {

		if (s[i] == 'x' ) continue;
		end[i] = true;
		count++;
		i = i - c;
		if (count > k) return 0;
	}
	fr(i, n)
	{
		//cout << start[i] << " " << end[i] << endl;
		if (end[i] == true && start[i] == true)
			cout << i + 1 << endl;
	}
}



Measured memory_bytes: 2180
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;

int main()
{
  int n, m, sum = 0, max = 0;
  string s[102], t[102];

  cin >> n;
  for(int i = 0; i < n; i++)
    cin >> s[i];
  cin >> m;
  for(int i= 0; i< m;i++)
    cin >> t[i];

  for(int i = 0; i < n; i++){
    sum = 0;
    for(int k=0; k < n; k++){
      if(s[i] == s[k])
        sum++;
    }
    for(int j = 0; j < m; j++){
      if(s[i] == t[j])
        sum--;
    }
    if(max < sum)
      max = sum;

  }

  cout << max << endl;

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<queue>
#include<vector>
#include<tuple>
#include<functional>

using namespace std;
typedef tuple<int, int, int, int> T4i;
typedef long long ll;

struct pos {
	int x, y;
	pos(int a, int b) { x = a, y = b; }
};

int W, H;
int field[30][30];
ll d[30][30][4];
ll c[4];//問題文と添え字が一つずれてることに注意

//v[i][j]: iの向きのときの動き方の増分
pos v[4][4] = {
	{pos(0, 1), pos(1, 0), pos(0, -1), pos(-1, 0)},
	{pos(1, 0), pos(0, -1), pos(-1, 0), pos(0, 1)},
	{pos(0, -1), pos(-1, 0), pos(0, 1), pos(1, 0)},
	{pos(-1, 0), pos(0, 1), pos(1, 0), pos(0, -1)}
};

int vdirect[4][4] = {
	{0, 1, 2, 3},
	{1, 2, 3, 0},
	{2, 3, 0, 1},
	{3, 0, 1, 2}
};
//0: 右向き 1: 下向き 2:左向き  3: 上向き 

void djkstra() {
	priority_queue<T4i, vector<T4i>, greater<T4i>> pq;

	//queueの中身は　コスト、座標、向いてる方向
	//始まりは、(0, 0)で向きは右向き　つまり0
	d[0][0][0] = 0;
	pq.push(make_tuple(0, 0, 0, 0));

	while (pq.size()) {

		auto now = pq.top(); pq.pop();
		pos nowp = pos(get<1>(now), get<2>(now));
		int nowd = get<3>(now);
		if (d[nowp.x][nowp.y][nowd] < get<0>(now))continue;

		for (int i = 0; i < 4; i++) {
			//ここから４種類の行き方をそれぞれエッジとして試す
			ll cost = 0;
			if (i == field[nowp.x][nowp.y])cost = 0;
			else cost = c[i];

			pos nextp = pos(nowp.x + v[nowd][i].x, nowp.y + v[nowd][i].y);
			
			//範囲外になってないかをチェック
			if (nextp.x < 0 || nextp.y < 0 || nextp.x >= H || nextp.y >= W)continue;

			//ゴール判定
			if (nextp.x == H - 1 && nextp.y == W - 1) {
				d[nextp.x][nextp.y][0] = min(d[nextp.x][nextp.y][0], d[nowp.x][nowp.y][nowd] + cost);
			}

			//行先処理
			if (d[nextp.x][nextp.y][vdirect[nowd][i]] > d[nowp.x][nowp.y][nowd] + cost) {
				d[nextp.x][nextp.y][vdirect[nowd][i]] = d[nowp.x][nowp.y][nowd] + cost;
				pq.push(make_tuple(d[nextp.x][nextp.y][vdirect[nowd][i]], 
					nextp.x, nextp.y, 
					vdirect[nowd][i]));
			}

		}

	}

}

int main() {

	while (1) {
		cin >> W >> H;

		for (int i = 0; i < 30; i++)
			for (int j = 0; j < 30; j++)
				for(int k = 0; k < 4; k++)
					d[i][j][k] = 999999999;
		
		if (W + H == 0)break;
		
		for (int i = 0; i < H; i++) {
			for (int j = 0; j < W; j++) {
				cin >> field[i][j];
			}
		}
		cin >> c[0] >> c[1] >> c[2] >> c[3];
		
		djkstra();
	
		//d[H - 1][W - 1]だけは、Stop確実なのでここだけ例外措置でStraightのところに答えを置く。
		cout << d[H - 1][W - 1][0] << endl;
	
	}
	
	return 0;
}


Measured memory_bytes: 3176
def gcd(a, b):
    return a if b == 0 else gcd(b, a % b)

def solve(a, b, c, d):
    if a < b or d < b:
        return False
    if b < c:
        return True

    g = gcd(b, d)
    return (b + a % g - g) <= c

T, *L = map(int, open(0).read().split())

for t in zip(*[iter(L)] * 4):
    if solve(*t):
        print("Yes")
    else:
        print("No")


Measured memory_bytes: 3188
import java.io.BufferedReader;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.ListIterator;
import java.util.Map.Entry;
import java.util.PriorityQueue;
import java.util.Scanner;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;

import javax.swing.text.Segment;

public class Main {
	
	public static final long INF = Long.MAX_VALUE / 2 - 1;
	public static long gcd(long a, long b){
		return b == 0 ? a : gcd(b, a % b);
	}
	public static long lcm(long a, long b){
		return a / gcd(a, b) * b;
	}
	
	public static void main(String[] args) throws IOException {
		try(Scanner sc = new Scanner(System.in)){
			final long N = sc.nextLong();
			
			for(long h = 1; h <= 3500; h++){
				for(long w = 1; w <= 3500; w++){
					final long denom = N * w * h;
					final long nom = 4 * (w * h) - N * (w + h);
					
					if(nom <= 0){ continue; }
					final long gcd = gcd(nom, denom);
					
					if(nom / gcd == 1){
						System.out.println(h + " " + w + " " + (denom / gcd));
						return;
					}
				}
			}
		}
	}
	
	public static class Scanner implements Closeable {
		private BufferedReader br;
		private StringTokenizer tok;
 
		public Scanner(InputStream is) throws IOException {
			br = new BufferedReader(new InputStreamReader(is));
		}
 
		private void getLine() throws IOException {
			while (!hasNext()) {
				tok = new StringTokenizer(br.readLine());
			}
		}
 
		private boolean hasNext() {
			return tok != null && tok.hasMoreTokens();
		}
 
		public String next() throws IOException {
			getLine();
			return tok.nextToken();
		}
 
		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}
 
		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}
 
		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}
		
		public int[] nextIntArray(int n) throws IOException {
			final int[] ret = new int[n];
			for(int i = 0; i < n; i++){
				ret[i] = this.nextInt();
			}
			return ret;
		}
		
		public long[] nextLongArray(int n) throws IOException {
			final long[] ret = new long[n];
			for(int i = 0; i < n; i++){
				ret[i] = this.nextLong();
			}
			return ret;
		}
 
		public void close() throws IOException {
			br.close();
		}
	}
}

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


int main(){
	int A, B;
	cin >> A >> B;
	if(A<=8&&B<=8) cout <<"Yay!" << endl;
	else cout << ":(" << endl;
}












Measured memory_bytes: 3628
#include<stdio.h>
int main(void){
	
	int N; scanf("%d",&N);
	
	int count,i,j,answer = 0;
	for(j = 1;j <= N;j = j+2){
		
		count = 0;
		
		for(i = 1;i <= j;i++){
			
			if(j %i == 0){
				count ++;
			}
			
		}
			
		if(count == 8){
			answer ++;
		}
		
	}
	printf("%d",answer);

}		

Measured memory_bytes: 128
#include <stdio.h>

int n, ans;

int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i += 2) {
    int sigma = 0;
    for (int j = 1; j <= i; j += 2) {
      if (i % j == 0) ++sigma;
    }
    ans += (sigma == 8);
  }
  printf("%d\n", ans);
  return 0;
}



Measured memory_bytes: 128
S = int(input())

mod = 10 ** 9 + 7

X = [1] * S

for i in range(1, S):
  X[i] = X[i - 1] * i % mod

ans = 0

for i in range(1, S // 3 + 1):
  ans += X[S - 2 * i - 1] * pow(X[i - 1] * X[S - 3 * i] % mod, mod - 2, mod) % mod
  ans %= mod

print(ans)

Measured memory_bytes: 63732
#include <bits/stdc++.h>
using namespace std;
const int maxn=112345;
int n,m,x[maxn];
long long K;
vector<int> perm;
int main()
{
    scanf("%d",&n);
    for (int i=0;i<n;++i) scanf("%d",&x[i]);
    scanf("%d%lld",&m,&K);
    for (int i=0;i<n-1;++i) perm.push_back(i);
    for (int i=0;i<m;++i) {
        int t;scanf("%d",&t);
        swap(perm[t-1],perm[t-2]);
    }
    vector<int> ret(n-1);
    for (int i=0;i<n-1;++i) ret[i]=i;
    while (K) {
        if (K&1) {
            vector<int> nxt(n-1);
            for (int i=0;i<n-1;++i)
                nxt[i]=ret[perm[i]];
            for (int i=0;i<n-1;++i)
                ret[i]=nxt[i];
        }
        K>>=1;
        vector<int> nxt(n-1);
        for (int i=0;i<n-1;++i)
            nxt[i]=perm[perm[i]];
        for (int i=0;i<n-1;++i)
            perm[i]=nxt[i];
    }
    for (int i=0;i<n-1;++i) perm[i]=ret[i];
    long long now=x[0];
    printf("%lld\n",now);
    for (int i=0;i<n-1;++i) {
        now+=x[perm[i]+1]-x[perm[i]];
        printf("%lld\n",now);
    }
    return 0;
}


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

using namespace std;

int main(){
	int h,w; cin >> h >> w;
	string s = "snuke";
	for(int i = 1; i <= h; ++i)
		for(char j = 'A'; j < 'A'+w; ++j){
			string str; cin >> str;
			if(str == s){
				cout << j << i << endl;
				return 0;
			}
		}
	

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <vector>

using namespace std;
string str;

vector<string> split(string s, char token) {
    stringstream iss(s);
    string word;
    vector<string> vs;
    while (getline(iss, word, token)) {
        vs.push_back(word);
    }
    return vs;
}

int main() {
    getline(cin, str);
    vector<string> v = split(str, ' ');
    stack<int> s;
    for (int i = 0; i < v.size(); i++) {
        if (isdigit(v[i][0])) {
            int val = 0;
            for (int j = 0; j < v[i].size(); j++) {
                val = val * 10 + (v[i][j] - 48);
            }
            s.push(val);
        } else {
            int a = s.top();
            s.pop();
            int b = s.top();
            s.pop();
            if (v[i][0] == '+') {
                s.push(a + b);
            } else if (v[i][0] == '-') {
                s.push(b - a);
            } else {
                s.push(a * b);
            }
        }
    }
    cout << s.top() << endl;
}


Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n; ll m; cin >> n >> m;
  vector<ll> A(n), sum(n+1);
  rep(i, n) {
    cin >> A[i];
    sum[i+1] = sum[i] + A[i];
  }
  map<ll, ll> rem;
  rep(i, n+1) rem[sum[i]%m]++;
  ll ans = 0;
  for(auto ele: rem) {
    ans += ele.second * (ele.second-1) / 2;
  }
  cout << ans << "\n";
  return 0;
}


Measured memory_bytes: 8596
import math
from math import gcd,pi,sqrt
INF = float("inf")

import sys
sys.setrecursionlimit(10**6)
import itertools
from collections import Counter,deque
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]

def main():
    n,k = i_map()

    R = [0]*k
    for i in range(1,n+1):
        R[i%k] += 1

    ans = 0
    for a in range(k):
        b = (k-a)%k
        if 2*b%k == 0: # b==cとしてbを2倍
            ans += R[a] * R[b] * R[b]

    print(ans)

if __name__=="__main__":
    main()


Measured memory_bytes: 10796