akhauriyash/Code-Regression huggingface dataset:
#include <functional>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;
const ll MOD = 1000000007LL;

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

    ll t1, t2, a1, a2, b1, b2;
    cin >> t1 >> t2 >> a1 >> a2 >> b1 >> b2;

    ll c1 = b1 - a1;
    ll c2 = b2 - a2;

    ll diff = t1 * c1 + t2 * c2;

    if (diff == 0) {
        cout << "infinity\n";
    } else if (diff > 0) {
        if (c1 > 0) {
            cout << 0 << '\n';
        } else {
            if (t1 * (-c1) % diff == 0) {
                cout << t1 * (-c1) / diff * 2 << '\n';
            } else {
                cout << t1 * (-c1) / diff * 2 + 1 << '\n';
            }
        }
    } else {
        if (c1 < 0) {
            cout << 0 << '\n';
        } else {
            if (t1 * c1 % (-diff) == 0) {
                cout << t1 * c1 / (-diff) * 2 << '\n';
            } else {
                cout << t1 * c1 / (-diff) * 2 + 1 << '\n';
            }
        }
    }

    return 0;
}

Measured memory_bytes: 256
def yymm(s):
    mm = int(s[2:])
    if mm == 0 or mm > 12:
        return False
    return True


def mmyy(s):
    mm = int(s[:2])
    if mm == 0 or mm > 12:
        return False
    return True


S = input()
if yymm(S) and mmyy(S):
    print('AMBIGUOUS')
elif not yymm(S) and mmyy(S):
    print('MMYY')
elif yymm(S) and not mmyy(S):
    print('YYMM')
else:
    print('NA')


Measured memory_bytes: 3064
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
 
using namespace std;
 
int main(){
  int t[1123],n[1123],m[1123],s[1123],N,M,r,i,j,k;
  int stud[1269];
  while(1){
    cin>>N>>M;
    // cout<<N<<","<<M<<endl;
    if(N==0 && M==0)
      break;
    cin>>r;
    for(i=0;i<r;i++){
      cin>>t[i]>>n[i]>>m[i]>>s[i];
    }
    int q,ts,te,mm,re=0;
    cin>>q;
    for(i=0;i<q;i++){
      re=0;
      cin>>ts>>te>>mm;
      fill(stud,(stud+1269),0);
      for(j=0;j<r;j++)
    if(m[j]==mm)stud[t[j]]+=(s[j]?1:-1);
      for(j=0;j<=1260;j++){
    stud[j+1]+=stud[j];
    re+=(stud[j]>0)&&(ts<=j)&&(j<te);
      }
      cout<<re<<endl;
    }
   }
  return 0;
}
    

Measured memory_bytes: 3064
#include<stdio.h>

int main(){
	int w,h;
	int x,y;
	while(1){
		scanf("%d %d",&h,&w);
		if(w==0 && h==0)
			break;
		for(y=0;y<h;y++){
			for(x=0;x<w;x++)
				if((y%2)?x%2:!(x%2))
					printf("#");
				else
					printf(".");
			printf("\n");
		}
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 572
#include <bits/stdc++.h>
#define INF 1e18
#define int long long
#define Rep(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) Rep(i, 0, n)
#define all(a) (a).begin(), (a).end()
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;
const int mod = 1000000007;

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

    int n, m, c;
    cin >> n >> m >> c;
    int a[30][30], b[30];
    rep(i, m) cin >> b[i];
    rep(i, n) rep(j, m) cin >> a[i][j];
    int ans = 0;
    rep(i, n)
    {
        int sum = c;
        rep(j, m) sum += a[i][j] * b[j];
        if (sum > 0)
            ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
int isprime(int);
int main(){
  int n,a[10000],x=0,i;

  scanf("%d",&n);

  for(i = 0; i < n; i++){
    scanf("%d",&a[i]);
  }

  for(i = 0; i < n; i++){
    if(isprime(a[i])==1)x++;
  }
  printf("%d\n",x);

  return 0;
}


int isprime(int x){
  int i;
   if(x == 2) return 1;
   if(x < 2 || x%2 == 0) return 0;
   for(i = 3; i <= sqrt(x); i += 2){
      if(x%i == 0) return 0;
    }
    
    return 1;
}



Measured memory_bytes: 2036
#include <bits/stdc++.h>
#define f first
#define s second
#define fore(i,a,b) for(int i = (a), ThxMK = (b); i < ThxMK; ++i)
#define pb push_back
#define all(s) begin(s), end(s)
#define _ ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define sz(s) int(s.size())
#define ENDL '\n'
using namespace std;
typedef long double ld;
typedef long long lli;
typedef pair<lli,lli> ii;
typedef vector<int> vi;
typedef vector<lli> vl;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
#define deb(x) cout << #x": " << (x) << endl;

const int N = 1e4+5;
const int INF = 1e9;
const lli MOD = 1e9+7;


vi primes(1,2);
vector<vector<ld>>nk;
void sieve(){
	vi m(N+1,0);
	for(int i = 4; i<N; i+=2)m[i]=1;
	for(int i = 3; i*i<=N; i+=2)if(!m[i])for(int j = i*i; j<N; j+=i)m[j]=1;
	for(int i = 3; i<N; i+=2)if(!m[i])primes.pb(i);
}

void pascal(){
	nk =vector<vector<ld>>(N,vector<ld>(N,0.0));
	fore(i,0,N)nk[i][0]=nk[i][i]=1.0;
	fore(i,1,N)fore(j,1,i)nk[i][j]=nk[i-1][j-1]+nk[i-1][j];
}

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

lli lcm(lli a, lli b){
	if(a<b)swap(a,b);
	lli c = gcd(a,b);
	a/=c;
	return a*b;
}

int popcount(lli x) { return __builtin_popcountll(x); }

lli poww(lli a, lli b){
	lli res =1;
	while(b){
		if(b&1) res = res * a;
		a = a*a;
		b/=2;
	}
	return res;
}

lli powm(lli a, lli b){
	lli res =1;
	while(b){
		if(b&1) res = (res * a)%MOD;
		a = (a*a)%MOD;
		b/=2;
	}
	return res;
}

bool isPrime(lli x){
	if(x==1)return 0;
	for(auto i:primes){
		if(i*i>x)return 1;
		if(x%i==0)return 0;
	}
	return 1;
}

lli SUM(lli a, lli b, lli mod=MOD){
	return (a+b+mod)%mod;
}
lli PROD(lli a, lli b, lli mod=MOD){
	a%=mod; b%=mod;
	return a*b % mod;
}
int dx[4]={-1,0,0,1}, dy[4]={0,1,-1,0};

// ---- コーディングはここから！ ('-')7
struct S{
	lli w,s,v;
	bool operator < (const S &n)const{
		return ii{w+s,v}<ii{n.w+n.s,n.v};
	}
};
void solve(){
	int n; cin>>n;
	vector<S>v(n); for(auto &[a,b,c]:v)cin>>a>>b>>c;
	sort(all(v));
	// for(auto &[a,b,c]:v)cout<<a<<b<<c<<ENDL;
	vvl dp(n,vl(N,-1));
	auto f=[&](auto f, int u, lli sum)->lli{
		if(u==n or sum>=N)return 0;
		if(dp[u][sum]!=-1)return dp[u][sum];
		lli res = f(f,u+1,sum);
		if(v[u].s>=sum)res = max(res, f(f,u+1,sum+v[u].w)+v[u].v);
		return dp[u][sum]=res;
	};
	cout<<f(f,0,0)<<ENDL;

}

int main(){_
	//int t; cin>>t; fore(tt,0,t)
	solve();
}


Measured memory_bytes: 81580
#include <iostream>
    #include <vector>
    #include <string>
    #include <algorithm>
    #include<set>
    #include <unordered_map> 
    #include <cmath>
    using namespace std;
   #define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main(void){

    cin.tie(0);
    ios::sync_with_stdio(false);

    int n,m;

    int ans_ = n;

    cin >> n >> m;

    vector<int> vec;
    vector<bool> YOI;

    int inp;
    rep(i,n){
        cin >> inp;
        vec.push_back(inp);
        YOI.push_back(true);
    }

    int a,b;
    rep(i,m){
        cin >> a >> b;
        //cout << a << ":" << b << endl;

        if(vec[a-1]==vec[b-1]){
            YOI[b-1]=false;
            YOI[a-1]=false;
        }else if(vec[a-1]>vec[b-1]){
            YOI[b-1]=false;
            //cout << "DAME" <<b << endl;
        }else{
            YOI[a-1]=false;
            //cout << "DAME" <<a << endl;
        }
    }

    int ans = 0;
    rep(i,n){
        if(YOI[i]==true){
            ans++;
        }
    }

    cout << ans;




    return 0;
}

Measured memory_bytes: 3792
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl; 
#define INF 1000000000
#define mod 1000000007
typedef long long ll;
const ll LINF = 1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
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; }

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

    //木を端から構築することを考えたら，最大値は2個以上必要
    //最大値をAmaxとすし，最小値をAminとする
    //Amax~Amin+1までは連続で2個以上ないといけない
    //Aminは1個か2個しかありえない．
    //Aminが2個-> Amax=2*Amin-1ならok
    //Aminが1個-> Amax=2*Aminならok
    //ウニの時だけはAminは1個じゃないといけない
    
    string P="Possible",I="Impossible";
    int n;cin>>n;
    vector<int> a(n);
    map<int,int> cnt;
    rep(i,n){
        cin>>a[i];
        cnt[a[i]]++;
    }
    int Amax=*max_element(ALL(a));
    int Amin=*min_element(ALL(a));
    if(n==2){
        if(a[0]==1&&a[1]==1) cout<<P<<endl;
        else cout<<I<<endl;
        return 0;
    }
    //ウニ選別作業
    if(Amin==1){
        if(Amax==2&&cnt[2]==n-1){
            cout<<P<<endl;
        }else{
            cout<<I<<endl;
        }
        return 0;
    }

    if(cnt[Amin]==1){
        bool f=true;
        for(int i=Amin+1;i<=Amax;i++){
            if(cnt[i]<2) f=false;
        }
        if(f&&Amax==2*Amin){
            cout<<P<<endl;
        }
        else{
            cout<<I<<endl;
        }
    }
    else if(cnt[Amin]==2){
        bool f=true;
        for(int i=Amin+1;i<=Amax;i++){
            if(cnt[i]<2) f=false;
        }
        if(f&&Amax==2*Amin-1){
            cout<<P<<endl;
        }
        else{
            cout<<I<<endl;
        }
    }
    else{
        cout<<I<<endl;
    }
    return 0;
}


Measured memory_bytes: 380
#include<stdio.h>
#include<iostream>
#include<math.h>
#include<algorithm>
#include<string.h>
#include<queue>
#include<set>
#include<string>
#include<sstream>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;

ll Pow_mod(ll a, ll b, ll c){
    ll ans = 1;
    a %= c;
    while (b){
        if (b & 1) ans = (ans * a) % c;
        a = (a * a) % c;
        b >>= 1;
    }
    return (ans % c);
}

ll Pow(ll a, ll b){
    ll ans = 1;
    while (b){
        if (b & 1) ans *= a;
        a *= a;
        b >>= 1;
    }
    return ans;
}

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

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

const int N = 1e5 + 10;

int n, tmp;
ll ans;
int a[N], b[N];

int main(){
    scanf("%lld", &n);
    for (int i = 1; i <= n + 1; i ++ ) scanf("%d", &a[i]);
    for (int i = 1; i <= n; i ++ ) scanf("%d", &b[i]);
    for (int i = 1; i <= n; i ++ ){
        tmp = min(b[i], a[i]);
        ans += tmp;
        a[i] -= tmp;
        b[i] -= tmp;
        tmp = min(b[i], a[i + 1]);
        ans += tmp;
        a[i + 1] -= tmp;
        b[i] -= tmp;
    }
    printf("%lld\n", ans);
    return 0;
}


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

using ll = long long;

int main() {
    int N, Q;
    string S;
    cin >> N >> S >> Q;
    vector<int> k(Q);
    rep(i, Q) cin >> k[i];
    rep(i, Q) {
        ll ans = 0;
        vector<ll> D(N + 1, 0), M(N + 1, 0), DM(N + 1, 0);
        rep(j, N) {
            D[j + 1] = D[j];
            M[j + 1] = M[j];
            DM[j + 1] = DM[j];
            if (S[j] == 'D') D[j + 1]++;
            if (j >= k[i] && S[j - k[i]] == 'D') {
                D[j + 1]--;
                DM[j + 1] -= M[j + 1];
            }
            if (S[j] == 'M') {
                M[j + 1]++;
                DM[j + 1] += D[j + 1];
            }
            if (j >= k[i] && S[j - k[i]] == 'M') M[j + 1]--;
            if (S[j] == 'C') ans += DM[j + 1];
            //cout << "j=" << j << " D=" << D[j + 1] << " M=" << M[j + 1] << " DM=" << DM[j + 1] << "\n";
        }
        cout << ans << "\n";
    }
}

Measured memory_bytes: 26704
// includes {{{
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<tuple>
#include<cmath>
#include<random>
#include<cassert>
#include<bitset>
#include<cstdlib>
// #include<deque>
// #include<multiset>
// #include<cstring>
// #include<bits/stdc++.h>
// }}}
using namespace std;
using ll = long long;

int g[][2] = {
  {1, 2},
  {-1, 3},
  {1, -1},
  {4, 5},
  {5, 2},
  {2, 1},
};

int main() {
  std::ios::sync_with_stdio(false), std::cin.tie(0);
  string s;
  while(1) {
    cin >> s;
    if(s == "#") break;
    int now = 0;
    for(auto c : s) {
      now = g[now][c-'0'];
      if(now == -1) break;
    }
    if(now == 5) cout << "Yes" << "\n";
    else cout << "No" << "\n";
  }
  return 0;
}



Measured memory_bytes: 3120
#include<iostream>
#include<sstream>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<algorithm>
#include<numeric>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>

#define rep(i,n) for(int i=0;i<n;i++)
#define all(c) (c).begin(),(c).end()
#define mp make_pair
#define pb push_back
#define rp(i,c) rep(i,(c).size())
#define fr(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define dbg(x) cerr<<#x<<" = "<<(x)<<endl

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
const int inf=1<<28;
const double INF=1e12,EPS=1e-9;

int dx[]={-1,0,1,1,1,0,-1,-1},dy[]={-1,-1,-1,0,1,1,1,0};
int h;
char in[1000][82];
int Y[5],X[5],n;
map<int,int> M;

void dfs(int y,int x,int pd)
{
	in[y][x]=' ';
	int ny=y+dy[pd],nx=x+dx[pd];
	if(ny<0||nx<0||ny>=h||!in[ny][nx]||in[ny][nx]!='*')
	{
		Y[n]=y; X[n]=x; n++;
		rep(d,7)
		{
			pd=pd+1&7;
			ny=y+dy[pd],nx=x+dx[pd];
			if(ny<0||nx<0||ny>=h||!in[ny][nx])continue;
			if(in[ny][nx]=='*')goto FOUND;
		}
		return; FOUND:;
	}
	dfs(ny,nx,pd);
}
int main()
{
	bool f=1;
	while(scanf("%d",&h),h)
	{
		if(!f)puts("----------"); else f=0;
		
		M.clear(); getchar();
		rep(i,h)fgets(in[i],81,stdin),in[i][strlen(in[i])-1]=0;
		
		rep(i,h)for(int j=0;in[i][j];j++)if(in[i][j]=='*')
		{
			n=1; Y[0]=i; X[0]=j;
			dfs(i,j,3);
			M[(Y[3]-Y[0]+1)*(X[1]-X[0]+X[2]-X[3]+2)/2]++;
		}
		fr(i,M)printf("%d %d\n",i->first,i->second);
	}
	return 0;
}

Measured memory_bytes: 0
#include <algorithm>
#include <cassert>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

namespace atcoder {
namespace {
bool check() {
  string line;
  cin >> line;
  assert(line.size() == 4);
  const auto a = line[0];

  const auto count_a = count_if(line.begin(), line.end(), [a](const auto x) { return x == a; });
  if (count_a != 2) return false;

  const auto b = line[1] != a ? line[1] : line[2];
  if (b == a) return false;
  const auto count_b = count_if(line.begin(), line.end(), [b](const auto x) { return x == b; });
  return (count_b == 2) ? true : false;
}
} // namespace
} // namespace atcoder

int main() {
  using namespace atcoder;
  cout << (check() ? "Yes" : "No");
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
//BEGIN CUT HERE
struct BiconectedGraph{
  typedef pair<int,int> P;
  int n;
  vector<vector<int> > G,C,T;
  vector<int> ord,low,belong;
  vector<P> B;
  BiconectedGraph(){}
  BiconectedGraph(int sz):n(sz),G(sz),C(sz),T(sz){}
  
  void add_edge(int u,int v){
    G[u].push_back(v);
    G[v].push_back(u);
  }

  void input(int m,int offset){
    int a,b;
    for(int i=0;i<m;i++){
      cin>>a>>b;
      add_edge(a+offset,b+offset);
    }
  }
  
  bool is_bridge(int u,int v){
    if(ord[u]>ord[v]) swap(u,v);
    return ord[u]<low[v];
  }
  
  void dfs(int u,int p,int &k){
    ord[u]=low[u]=k;
    ++k;
    for(int v:G[u]){
      if(v==p) continue;
      if(ord[v]>=0){
	low[u]=min(low[u],ord[v]);
      }else{
	dfs(v,u,k);
	low[u]=min(low[u],low[v]);
      }
      if(is_bridge(u,v)) B.push_back(P(u,v));
    }
  }
  
  void fill_component(int c,int u){
    C[c].push_back(u);
    belong[u]=c;
    for(int v:G[u]){
      if(belong[v]>=0||is_bridge(u,v)) continue;
      fill_component(c,v);
    }
  }
  
  void add_component(int u,int &k){
    if(belong[u]>=0) return;
    fill_component(k++,u);
  }
  
  int build(){
    int k=0;
    ord.resize(n);
    low.resize(n);
    belong.resize(n);
    fill(ord.begin(),ord.end(),-1);
    fill(belong.begin(),belong.end(),-1);
    for(int u=0;u<n;u++){
      if(ord[u]>=0) continue;
      dfs(u,-1,k);
    }
    k=0;
    for(int i=0;i<(int)B.size();i++){
      add_component(B[i].first,k);
      add_component(B[i].second,k);
    }
    for(int u=0;u<n;u++) add_component(u,k);
    for(int i=0;i<(int)B.size();i++){
      int u=belong[B[i].first],v=belong[B[i].second];
      T[u].push_back(v);
      T[v].push_back(u);
    }
    return k;
  }
};
//END CUT HERE

signed main(){
  int v,e;
  cin>>v>>e;
  BiconectedGraph bcc(v);
  bcc.input(e,0);
  bcc.build();
  typedef pair<int,int> P;
  vector<P> B=bcc.B;
  for(P &p:B) if(p.first>p.second) swap(p.first,p.second);
  sort(B.begin(),B.end());
  for(P p:B) cout<<p.first<<" "<<p.second<<endl;
  return 0;
}

/*
  verified on 2017/10/21
  http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=GRL_3_B&lang=jp
*/

Measured memory_bytes: 5616
#k = int(input())
#s = input()
#a, b = map(int, input().split())
#s, t = map(str, input().split())
#l = list(map(int, input().split()))


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

ans = 0
last = -1
for i in range(n):
    ans += b[a[i] -1]
    if (last + 1 == a[i]):
        ans += c[a[i] -2]
    last = a[i]
print(ans)


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

//#define int long long
#define DBG 1
#define dump(o) if(DBG){cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) if(DBG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define each(it,c) for(auto it=(c).begin();it!=(c).end();it++)
#define all(c) c.begin(),c.end()
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9 + 7);
const double EPS = 1e-10;
void print_v(vector<vector<int>>aaa) {
	cout << endl;
	rep(i, 0, aaa.size()) {
		rep(j, 0, aaa.size()) {
			cout << aaa[i][j] << (j == aaa[i].size() - 1 ? '\n' : ' ');
		}
	}
}
int ans(0);
vector<string>v, g;
int h, w, n, cheese(1), bfs_cnt(0);
vector<vector<int>>s;
int bfs(int x, int y) {
	bfs_cnt = 0;
	queue<pair<int, int>>Q;
	Q.push(make_pair(x, y));
	s[x][y] = bfs_cnt++;
	while (!Q.empty()) {
		auto p = Q.front(); Q.pop();
		int a = p.first, b = p.second;
		if (a < 0 || h <= a || b < 0 || w <= b)continue;
		if (v[a][b] == 'X')continue;
		if (v[a][b] == '0' + cheese)return s[a][b];

		v[a][b] = 'X';
		if (a - 1 >= 0) {
			if (s[a - 1][b] == -1)s[a - 1][b] = s[a][b] + 1;
			Q.push(make_pair(a - 1, b));
		}
		if (a + 1 < h) {
			if (s[a + 1][b] == -1)s[a + 1][b] = s[a][b] + 1;
			Q.push(make_pair(a + 1, b));
		}
		if (b - 1 >= 0) {
			if (s[a][b - 1] == -1)s[a][b - 1] = s[a][b] + 1;
			Q.push(make_pair(a, b - 1));
		}
		if (b + 1 < w) {
			if (s[a][b + 1] == -1)s[a][b + 1] = s[a][b] + 1;
			Q.push(make_pair(a, b + 1));
		}
		
	}

}

int bfs_start() {
	vector<pair<int, int>>point(n + 1);
	rep(i, 0, h) {
		rep(j, 0, w) {
			if (g[i][j] == 'S')point[0] = make_pair(i, j);
			else if (isdigit(g[i][j])) {
				point[g[i][j] - '0'] = make_pair(i, j);
			}
		}
	}

	rep(i, 0, n) {
		s = vector<vector<int>>(h, vector<int>(w, -1));
		v = g;
		ans += bfs(point[i].first, point[i].second);
		cheese++;
	}
	return ans;
}

signed main() {
	cin >> h >> w >> n;
	rep(i, 0, h) {
		string s; cin >> s;
		g.push_back(s);
	}

	cout << bfs_start() << endl;


	return 0;
}

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

#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y

#define ASSERT(expr...) assert((expr))

using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;

using f32 = float;
using f64 = double;

constexpr i64 INF = 1'010'000'000'000'000'017LL;

constexpr i64 MOD = 1'000'000'007LL;

constexpr f64 EPS = 1e-12;

constexpr f64 PI = 3.14159265358979323846;

#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)

#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }

template<typename T, size_t N>
i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); }

template<typename T, typename U, typename Comp=less<>>
bool chmax(T& xmax, const U& x, Comp comp={}) {
    if(comp(xmax, x)) {
        xmax = x;
        return true;
    }
    return false;
}

template<typename T, typename U, typename Comp=less<>>
bool chmin(T& xmin, const U& x, Comp comp={}) {
    if(comp(x, xmin)) {
        xmin = x;
        return true;
    }
    return false;
}

struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;



void solve() {
    int N; cin >> N;
    string S; cin >> S;

    if (N % 2 != 0) {
        cout << "No"; 
        return;
    } else {
        for (int i = 0; i < N/2; ++i) {
            if (S.at(i) != S.at(i+N/2)) {
                cout << "No"; 
                return;
            }
        }
    }

    cout << "Yes";
    // cout << ans << "\n";
}

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


Measured memory_bytes: 256
import sys
read = sys.stdin.buffer.read
input = sys.stdin.readline
input = sys.stdin.buffer.readline


#sys.setrecursionlimit(10**9)
#from functools import lru_cache

def RD(): return sys.stdin.read()
def II(): return int(input())
def MI(): return map(int,input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int,input().split()))
def LF(): return list(map(float,input().split()))
def TI(): return tuple(map(int,input().split()))
# rstrip().decode('utf-8')

#import numpy as np
from itertools import combinations

def main():
	n=II()
	s=input().decode()


	def check(a,b,c):
		A=[None]*(n+1)
		A[0]=a
		A[1]=b
		A[n-1]=c
		A[n]=a

		for i in range(1,n):
			if (s[i]=="o" and A[i]=="S") or (s[i]=="x" and A[i]=="W"):
				if A[i+1]==None:
					A[i+1]=A[i-1]
				else:
					if A[i+1]!=A[i-1]:
						return
			#if (s[i]=="o" and A[i]=="W") or (s[i]=="x" and A[i]=="S"):
			else:
				if A[i+1]==None:
					if A[i-1]=="S":
						A[i+1]="W"
					else:
						A[i+1]="S"
				else:
					if A[i+1]==A[i-1]:
						return

		print(*A[:-1],sep="")
		exit(0)

	if s[0]=="o":
		check("S","S","S")
		check("S","W","W")
		check("W","W","S")
		check("W","S","W")

	else:
		check("S","S","W")
		check("S","W","S")
		check("W","S","S")
		check("W","W","W")

	print(-1)













if __name__ == "__main__":
	main()


Measured memory_bytes: 9696
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int N;
    cin >> N;
    vector<int> vec(N);
    for (int i = 0; i < N; ++i) cin >> vec[i];
    sort(vec.begin(), vec.end());
 
    int ans = 0;
 
    for (int i = 0; i < N; ++i) {
        for (int j = 0; j < i; ++j) {
            for (int k = 0; k < j; ++k) {
                if (vec[k] != vec[j] and vec[i] != vec[j] and
                    vec[k] + vec[j] > vec[i]) {
                    ans++;
                }
            }
        }
    }
 
    cout << ans << endl;
 
    return 0;
}

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

using namespace std;

int main() {

    string s; cin >> s;
    
    string tmp1 = s, tmp2 = s;

    for (int i=0; i<(int)s.size(); i++) {
        if (i%2==0) tmp1[i] = '1', tmp2[i] = '0';
        if (i%2==1) tmp2[i] = '1', tmp1[i] = '0';
    }

    int c1 = 0, c2 = 0;
    for (int i=0; i<(int)s.size(); i++) {
        if (s[i]!=tmp1[i]) c1 += 1;
        if (s[i]!=tmp2[i]) c2 += 1;
    }

    cout << min(c1, c2) << "\n";

    return 0;
}

Measured memory_bytes: 512
/*
   Author: Shivam Shukla
*/
#include<bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vpii;
typedef vector<pair<ll,ll> > vpll;
 
const int MOD=1e9+7;
const int MAX=1e5+5;
const double PI= acos(-1.0);
const long double EPS=1e-10;
const int64_t INF=1e18+10;
 
#define fastio() ios_base::sync_with_stdio(false);cin.tie(0), cout.tie(0)
#define trace(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define vi vector<int>
#define vl vector<ll>
#define vs vector<str>
#define vc(x) vector<x>
#define mapll map<ll,ll>
#define mapib map<int,bool>
#define mapiv map<int,vector>
#define mapsi map<string,int>
#define rep(i,j,k) for(ll i=j;i<k;i++)
#define down(i,j,k) for(ll i=j;i>=k;i--)
#define repa(i,n) for(ll i=0;i<n;i++)
#define dowa(i,n) for(ll i=n;i>=0;i--)
#define reps(i,j,k,s) for(ll i=j;i<k;i+=s)
#define downs(i,j,k,s) for(ll i=j;i>=k;i-=s)
#define trv(i,x) for(auto i:x)
#define pb push_back
#define eb emplace_back
#define sz(x) (int)x.size()
#define ff first
#define ss second
#define str string 
#define dub double
#define pqmax priority_queue<ll>
#define pqmin priority_queue<ll,vl,greater<ll> >
 
template<typename t> t lcm(t a, t b) {return (a*b)/__gcd(a,b);}
template<typename t> t gcd(t a, t b) {return __gcd(a,b);}
template<typename t> t mul_mod(t a, t b, t m){t res=((a%m)*(b%m)%m); return res;}
template<typename t> t add_mod(t a, t b, t m){t res=((a%m)+(b%m))%m; return res;}
template<typename t> t pow_mod(t a,t b,t m) {t res=1;while(b){if(b&1) res=mul_mod(res,a,m);a=mul_mod(a,a,m), b>>=1;} return res%m;}
template<typename t> vc(t) num_vec(t num) {t res; while (num) res.pb(num%10), num/=10; return res;}
template<typename t> t vec_num(t vec) {t res=0; ll mul=1; repa(i,sz(vec)) res=vec[i]*mul, mul*=10; return res;}
 

int32_t main(int argc,char** argv){
	fastio();
	auto tstart= clock();
 

    double r; cin >> r;
    cout << (2.0 * PI * r) << endl;  
  
    cerr<<setprecision(2)<<fixed<<"Time elapsed: "<<(double)(clock() - tstart)/CLOCKS_PER_SEC<<endl; 
    return 0; 
}

Measured memory_bytes: 3804
n = int(input())

def num2alpha(num):
    if num<=26:
        return chr(64+num)
    elif num%26==0:
        return num2alpha(num//26-1)+chr(90)
    else:
        return num2alpha(num//26)+chr(64+num%26)


X = num2alpha(n)
print(X.swapcase())

Measured memory_bytes: 9184
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<cmath>
#include<iomanip>
#include<map>
#include<cstring>

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define vi vector<int>
#define vivi vector<vi>
const int INF = int(1e9);
typedef long long int ll;
/* -- template -- */

const ll MOD = 1e9 + 7;

ll modpow(int a, int b){//return a^b
    if(b == 0)return 1;
    while(b > 1){
        a = a * 2 % MOD;
        --b;
    }
    return a;
}

int main(){
    int N; cin >> N;
    int A[N]; rep(i, N)cin >> A[i];
    //2^N/2
    sort(A, A + N);
    bool flg = true;
    for(int i =((A[0] == 0) ? 1 : 0); i < N - 1; i += 2){
        if(A[i] != A[i + 1])flg = false;
    }
    if(flg){
        cout << modpow(2, N / 2) << endl;
    }else{
        cout << 0 << endl;
    }
}


Measured memory_bytes: 768
#include <iostream>

using namespace std;

int main() {
	int n;
	cin >> n;
	
	int ans[n][3], a[n], b[n], c[n];
	
	for (int i = 0;i < n;i++) { cin >> a[i] >> b[i] >> c[i]; }

	ans[0][0] = a[0]; ans[0][1] = b[0]; ans[0][2] = c[0];

	for (int i = 1;i < n;i++) {
		ans[i][0] = max(ans[i - 1][1], ans[i - 1][2]) + a[i];
		ans[i][1] = max(ans[i - 1][0], ans[i - 1][2]) + b[i];
		ans[i][2] = max(ans[i - 1][0], ans[i - 1][1]) + c[i]; 
	}

	cout << max(ans[n - 1][0], max(ans[n - 1][1], ans[n - 1][2]));
}

Measured memory_bytes: 2560
import std.algorithm;
import std.array;
import std.ascii;
import std.bigint;
import std.complex;
import std.container;
import std.conv;
import std.functional;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

auto readInts() {
	return array(map!(to!int)(readln().strip().split()));
}
auto readInt() {
	return readInts()[0];
}
auto readLongs() {
	return array(map!(to!long)(readln().strip().split()));
}
auto readLong() {
	return readLongs()[0];
}

void readlnTo(T...)(ref T t) {
    auto s = readln().split();
    assert(s.length == t.length);
    foreach(ref ti; t) {
        ti = s[0].to!(typeof(ti));
        s = s[1..$];
    }
}

class UnionFindTree {
public:
    this(size_t n) {
        parent = iota(n).array();
        rank = new size_t[](n);
    }
    size_t find(size_t n) {
        if(n == parent[n]) {
            return n;
        } else {
            parent[n] = find(parent[n]);
            return parent[n];
        }
    }
    void unite(size_t n, size_t m) {
        auto p1 = find(n);
        auto p2 = find(m);
        if(n == m) {
            return;
        }
        if(rank[p1] < rank[p2]) {
            swap(p1, p2);
        }
        if(rank[p1] == rank[p2]) {
            ++rank[p1];
        }
        parent[p2] = p1;
    }
private:
    size_t[] parent;
    size_t[] rank;
}
unittest {
    auto uft = new UnionFindTree(10);
    foreach(i; iota(10)) {
        assert(uft.find(i) == i);
    }
    foreach(i; iota(10).filter!(a => a%3 == 0).drop(1)) {
        uft.unite(i, i-3);
    }
    foreach(i; iota(10).filter!(a => a%3 == 0)) {
        assert(uft.find(0) == uft.find(i));
    }
    foreach(i; iota(10).filter!(a => a%3 != 0)) {
        assert(uft.find(0) != uft.find(i));
    }
}

const real eps = 1e-10;

const long p = 1_000_000_000 + 7;

void main(){
    auto s = readln().chomp();
    writeln(s[0..$-8]);
}



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


int main()
{
  int L, N, W[100] = {};
  cin >> L >> N;
  for(int i = 0; i < N; i++) {
    int x, w;
    cin >> x >> w;
    W[x + 50] += w;
  }

  vector< pair< int, int > > ret;
  for(int i = -L; i < 0; i++) {
    int P = W[50 + i];
    int Q = W[50 - i];
    int R = max(W[50 + i], W[50 - i]);
    for(int j = W[50 + i]; j < R; j++) {
      ret.push_back({i, 1});
    }
    for(int j = W[50 - i]; j < R; j++) {
      ret.push_back({-i, 1});
    }
  }
  cout << ret.size() << endl;
  for(auto k : ret) {
    cout << k.first << " " << k.second << endl;
  }
}

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

#include <iostream>
using namespace std;
int main() {
  string s, t;
  cin >> s >> t;
  int64_t ans = 0;
  for (int i = 0; i < s.size(); ++i) {
    if (s[i] != t[i]) ans++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3856
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return true;
    }
    return false;
}
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}
const long long INF = 1LL << 60;

int main()
{
    int a;
    cin >> a;
    cout << a + a * a + a * a * a << endl;
    return 0;
}


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

#define INF 1000000007
#define ll long long
#define F first
#define S second
#define pii pair<ll int,ll int>
#define pb push_back
#define ppb pop_back
#define vi vector<ll int>

int p[200005];
int size[200005];

void initialize(int n){
	for(int i=0;i<=n;i++){
		p[i] = i;
		size[i] = 1;
	}
}

int root(int x){
	while(x != p[x]){
		p[x] = p[p[x]];
		x = p[x];
	}
	return x;
}

void sunion(int x,int y){
	int rx = root(x);
	int ry = root(y);
	if(size[rx] < size[ry]){
		p[rx] = p[ry];
		size[ry] += size[rx];
	}
	else{
		p[ry] = p[rx];
		size[rx] += size[ry];
	}
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int t=1;
	//cin >> t;
	while(t--){
		int n,m,k;
		cin >> n >> m >> k;
		int a,b;
		initialize(n);
		int A[m][2];
		for(int i=0;i<m;i++){
			cin >> a >> b;
			sunion(a,b);
			// for(int i=1;i<=n;i++) cout << root(i) << " ";
			// cout << endl;
			A[i][0] = a;
			A[i][1] = b;
		}
		//set <int> B[n+1];

		vector <int> comp[n+1];
		for(int i=1;i<=n;i++){
			comp[root(i)].pb(i);
		}
		int cand[n+1] = {0};
		for(int i=1;i<=n;i++){
			//if(!comp[i].empty()){
				cand[i] = comp[root(i)].size()-1;
			//}
			//cand[i] = size[root(i)] - 1;
		}
		// for(int i=1;i<=n;i++) cout << cand[i] << " ";
		// cout << endl;
		int c,d;
		for(int i=0;i<k;i++){
			cin >> c >> d;
			//B[c].insert(d);
			//B[d].insert(c);
			if(root(c) == root(d)){
				cand[c]--;
				cand[d]--;
			}
		}
		for(int i=0;i<m;i++){
			cand[A[i][0]]--;
			cand[A[i][1]]--;
		}
		for(int i=1;i<=n;i++) cout << cand[i] << " ";
		cout << endl;
	}
	return 0;
}


Measured memory_bytes: 7808
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <queue>
#include <stack>
#include <string>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#define rep(i, n) for(int i = 0; i < n; i ++)
#define ALL(T) T.begin(), T.end()
#define mp make_pair
#define pb push_back
#define MEMSET(v, h) memset((v), h, sizeof(v))

using namespace std;

typedef pair<int, int> pii;
typedef long long ll;
typedef vector<int> vi;
typedef vector<string> vs;

const int INF = 1 << 24;






int main(void){
	bool is_prime[123456*2+1];
	for (int i=0; i<=123456*2;i++)is_prime[i]=true;
	is_prime[0]=is_prime[1]=false;
	for (int i=2; i<=123456*2;i++)
			if( is_prime[i])
				for(int j=2*i;j<=123456*2;j+=i) is_prime[j]=false;
	int n, count;
	while(1){
		count=0;
		scanf("%d",&n);
		if(!n)
			break;
		for(int i=n+1;i<=2*n;i++)
			if(is_prime[i])
				count++;
		printf("%d\n",count);
	}

    
    return 0;
}

Measured memory_bytes: 1428
#include<iostream>
#include<queue>

using namespace std;
static const int N=100;
static const int INFTY=(1<<21);

int n,M[N][N];
int d[N];

void bfs(int s){
  queue<int>q;
  q.push(s);
  for(int i=0;i<n;i++)d[i]=INFTY;
  d[s]=0;
  int u;
  while(!q.empty()){
    u=q.front();q.pop();
    for(int v=0;v<n;v++){
      if(M[u][v]==0)continue;
      if(d[v]!=INFTY)continue;
      d[v]=d[u]+1;
      q.push(v);
    }
  }
  for(int i=0;i<n;i++){
    cout<<i+1<<" "<<( (d[i]==INFTY) ? (-1):d[i] ) << endl;
  }
}
int main(){
  int u,k,v;
  cin>>n;
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++)M[i][j]=0;
  }
  for(int i=0;i<n;i++){
    cin>>u>>k;
    u--;
    for(int j=0;j<k;j++){
      cin>>v;
      v--;
      M[u][v]=1;
    }
  }
  bfs(0);
  return 0;
}


Measured memory_bytes: 3084
#include<iostream>
using namespace std;
int main() {
	int n, a[2][210], b[2][210] = {};
	cin >> n;
	for (int i = 0; i < 2; i++) {
		cin >> a[i][0];
		b[i][0] = a[i][0];
		for (int j = 1; j < n; j++) {
			cin >> a[i][j];
			b[i][j] = b[i][j - 1] + a[i][j];
		}
	}
	int ans = -1;
	for (int i = 0; i < n; i++) {
		if (ans < b[0][i] + b[1][n - 1] - b[1][i] + a[1][i])ans = b[0][i] + b[1][n - 1] - b[1][i] + a[1][i];
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
n, m = map(int, input().split())
h = list(map(int, input().split()))
a, b = [0] * m, [0] * m
data = [[] for _ in range(n)]
for i in range(m):
    a[i], b[i] = map(int, input().split())
    data[a[i] - 1].append(b[i] - 1)
    data[b[i] - 1].append(a[i] - 1)
ans = 0
for i in range(n):
    flag = True
    for x in data[i]:
        if h[i] <= h[x]:
            flag = False
            break
    if flag:
        ans += 1
print(ans)

Measured memory_bytes: 37260
fun main(args: Array<String>) = IO().println {
    var n = int()
    var cnt = 0
    while (n > 0) {
        if (n % 10 == 2) cnt++
        n /= 10
    }
    cnt
}

// region template
operator fun Int.iterator() = 0.until(this).iterator()

class IO {
    val printable = 33..126
    val buffer = ByteArray(1024)
    var ptr = 0
    var buflen = 0
    val out = java.io.PrintWriter(System.out)
    fun hasNextByte(): Boolean = if (ptr < buflen) true else {
        ptr = 0
        buflen = System.`in`.read(buffer)
        buflen > 0
    }

    fun readByte(): Byte = if (hasNextByte()) buffer[ptr++] else -1
    fun hasNext(): Boolean {
        while (hasNextByte() && buffer[ptr] !in printable) ptr++
        return hasNextByte()
    }

    fun string(): String {
        if (!hasNext()) throw java.util.NoSuchElementException()
        val sb = StringBuilder()
        var b = readByte()
        while (b in printable) {
            sb.appendCodePoint(b.toInt())
            b = readByte()
        }
        return sb.toString()
    }

    fun long(): Long {
        if (!hasNext()) throw java.util.NoSuchElementException()
        var n = 0L
        var minus = false
        var b = readByte()
        if (b == '-'.toByte()) {
            minus = true
            b = readByte()
        }
        if (b !in '0'.toByte()..'9'.toByte()) {
            throw NumberFormatException()
        }
        while (true) {
            if (b in '0'.toByte()..'9'.toByte()) {
                n *= 10
                n += b - '0'.toByte()
            } else if (b == (-1).toByte() || b !in printable) {
                return if (minus) -n else n
            } else {
                throw NumberFormatException()
            }
            b = readByte()
        }
    }

    fun int(): Int {
        val nl = long()
        if (nl !in Integer.MIN_VALUE..Integer.MAX_VALUE) throw NumberFormatException()
        return nl.toInt()
    }

    fun double(): Double = string().toDouble()
    fun print(obj: Any) = out.print(obj)
    fun print(i: Int) = out.print(i)
    fun print(l: Long) = out.print(l)
    fun println(obj: Any) = out.println(obj)
    fun println(i: Int) = out.println(i)
    fun println(l: Long) = out.println(l)
    inline fun exec(block: IO.() -> Unit) {
        block()
        out.flush()
    }

    inline fun println(block: IO.() -> Any) {
        println(block())
        out.flush()
    }
}
// endregion

Measured memory_bytes: 31272
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1145141919810893364
#define PI 3.141592653589
typedef pair<int,int> PP;
typedef long long ll;
#define int ll
#define setdouble setprecision
#define REP(i,n) for(int i=0;i<(n);++i)
#define OREP(i,n) for(int i=1;i<=(n);++i)
#define RREP(i,n) for(int i=(n)-1;i>=0;--i)
#define GOODBYE do { cout << -1 << endl; return 0; } while (false)
#define MM <<" "<<
#define Endl endl

int BE(int b,int e){
    int r=1;
    while(e){
        if(e&1){
            r=(r*b)%MOD;
        }
        b=(b*b)%MOD;
        e >>=1;
    }
    return r;
}

signed main(void){
    int N,M,K;
    cin >> N >> M >> K;
    int C=1,Ans=0;
    int c=1;
    for(int i=0;i<K-2;i++){
        C=(C*(N*M-2-i))%MOD;
        c=(c*(i+1))%MOD;
    }
    C=(C*BE(c,MOD-2))%MOD;
    int X=0,Y=0;
    for(int d=1;d<=N-1;d++){
        c=(M*M)%MOD;
        c=(c*d)%MOD;
        c=(c*(N-d))%MOD;
        X=(X+c)%MOD;
    }
    for(int d=1;d<=M-1;d++){
        c=(N*N)%MOD;
        c=(c*d)%MOD;
        c=(c*(M-d))%MOD;
        Y=(Y+c)%MOD;
    }
    Ans=(X+Y)%MOD;
    Ans=(Ans*C)%MOD;
    cout << Ans << endl;
  return 0;
}



Measured memory_bytes: 256
S=input()
Sf=int(S[:2])
Sb=int(S[2:])
if 1<=Sf<=12:
  if 1<=Sb<=12:
    print('AMBIGUOUS')
  else:
    print('MMYY')
else:
  if 1<=Sb<=12:
    print('YYMM')
  else:
    print('NA')

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

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

const int max_n = 50;
ll a[max_n+1], p[max_n+1];

ll rec(ll n, ll x){
	if(n == 0) return 1;
	if(x == 1) return 0;
	if(1 < x && x < a[n-1] + 2) return rec(n-1, x-1);
	if(x == a[n-1] + 2) return p[n-1] + 1;
	if(a[n-1] + 2 < x && x < a[n]) {
		return p[n-1] + 1 + rec(n-1, x - a[n-1] - 2);
	}
	return p[n];
}

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

	ll n, x;
	cin >> n >> x;

	a[0] = 1;
	p[0] = 1;

	rep(i, n){
		a[i+1] = 2 * a[i] + 3;
		p[i+1] = 2 * p[i] + 1;
	}

	cout << rec(n, x) << endl;
}


Measured memory_bytes: 256
;; C - Tax Increase

(defun solve (a b)
  "floor(x * 0.08) == a, floor(x * 0.1) == b である x.
   1 <= a <= b <= 100"
  (loop for x from 1 to (/ 100 8/100)
        when (and (= a (floor (* x 8/100)))
                  (= b (floor (* x 1/10))))
        do (return x) end
        finally (return -1)))

(let ((a (read))
      (b (read)))
  (princ (solve a b)))


Measured memory_bytes: 28128
#include <stdio.h>
int main (){

int H,W,s,s2,s3,dr[1000]={0},dr2[1000]={0},c=0,c2=0;

while (1){
	scanf ("%d %d",&H,&W);
	if (H==0&&W==0) break;
	dr[c]=H;
	dr2[c]=W;
	c++;
	
}


for (s=0;s<c;s++){
	
	for (s2=0;s2<dr[c2];s2++){
		for (s3=0;s3<dr2[c2];s3++){
			if (s3==dr2[c2]-1){
				printf ("#\n");
			}
			else {
				printf ("#");
			}
		}
	}
	c2++;
	printf ("\n");
}


return 0;
}

Measured memory_bytes: 1768
#include <bits/stdc++.h>
#define ll long long int
#define mod_ceil(a, b) (a % b) ? a / b + 1 : a / b
using namespace std;

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

    ll x, n;
    cin >> x >> n;
    vector<ll> A(n);
    unordered_set<ll> U;
    for (auto &it : A)
    {
        cin >> it;
        U.insert(it);
    }
    for (ll i = 0;; i++)
    {
        if (U.find(x - i) == U.end())
        {
            cout << x - i << endl;
            return 0;
        }
        else if (U.find(x + i) == U.end())
        {
            cout << x + i << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 3592
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

def identity(x):
    return x

def mapv(f,s):
    return list(map(f,s))

def readln():
    _res = mapv(int,str(input()).split(' '))
    return _res

def seq(n,f=(lambda x: 0)):
    return [f(i) for i in range(0,n)]

n,c,k = readln()
t = [0 for i in range(0,n)]
for i in range(0,n):
    t[i] = int(input())
t = sorted(t)
ans,left = 0,0
while left < n:
    right = left
    while right < n and right - left < c and t[right] - t[left] <= k :
        right = right + 1
    ans = ans + 1
    left = right
print(ans)


Measured memory_bytes: 8292
// https://atcoder.jp/contests/abl/tasks/abl_e
#include <atcoder/all>
// https://betrue12.hateblo.jp/entry/2020/09/27/013719
#include <bits/stdc++.h>
using namespace std;
using mint = atcoder::modint998244353;
struct S {
    mint val, unit;
};
using F = int;
const F ID = -1;

// 区間取得をどのような演算で行うかを定義します。通常のセグメント木と同じ
S op(S a, S b) { return {a.val + b.val, a.unit + b.unit}; }
// op(a, e) = op(e, a) = a を満たす。通常のセグメント木と同じ
S e() { return {0, 0}; }
// 操作 f を各ノードが持つ data の値 x に対して作用
S mapping(F f, S x) {
    if (f != ID)
        x.val = f * x.unit;
    return x;
}
// 既にこれまでの操作を溜めている lazy に対して、さらに新しい操作を追加
F composition(F f, F g) { return (f == ID ? g : f); }
// mapping(id, a) = a を満たす
F id() { return ID; }

void solve() {
    int N, Q;
    cin >> N >> Q;
    vector<S> init(N);
    mint pow10 = 1;
    for (int i = N - 1; i >= 0; i--) {
        init[i] = {pow10, pow10};
        pow10 *= 10;
    }
    atcoder::lazy_segtree<S, op, e, F, mapping, composition, id> seg(init);
    while (Q--) {
        int l, r, d;
        cin >> l >> r >> d;
        // 0-based indexのため-1
        seg.apply(l - 1, r, d);
        // 構造体Sのvalとmodintのval()
        cout << seg.all_prod().val.val() << "\n";
    }
}

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


Measured memory_bytes: 10156
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
import itertools as it
ac_a=list(it.accumulate(a))
ac_b=list(it.accumulate(b))
sum_b=sum(b)
ans=0
for i in range(n):
    if i>0:
        tmp=ac_a[i]+sum_b-ac_b[i-1]
    elif i==0:
        tmp=a[0]+sum_b
    ans=max(tmp,ans)
print(ans)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
int main(){
    int k;
    cin >> k;
    int a,b;
    cin >> a >> b;
    if(k>a && k>b)
        cout<<"NG";
    else
    {
        bool check=false;
        for(int i=a;i<=b;i++)
        {
            if(i%k==0)
            {
                check=true;
                break;
            }
        }
        if(check)
            cout<<"OK";
        else
            cout<<"NG";
    }
}

Measured memory_bytes: 3624
s = input()
count = 0
tmp = 0
for i in range(len(s)):
    if s[i] == "A" or s[i] == "C" or s[i] == "G" or s[i] == "T":
        tmp += 1
    else:    
        tmp = 0
    count = max(tmp,count)
print(count)

Measured memory_bytes: 9104
#include <iostream>
#include<stdio.h>
#include<algorithm>
#include<string.h>
//#define ll long long
//#define maxn -99999
using namespace std;
int a[200005];
int book[200005];
//bool cmp(int x,int y)
//{
//	return x>y;
//}
 //int ll=999999999,rr=-999999999;
int main()
{
   int n,m;
   int l,r,t;
  
   scanf("%d %d",&n,&m); 
   t=m;
   memset(book,0,sizeof(book));
   while(t--)
   {
   	 scanf("%d %d",&l,&r);
   	for(int i=l;i<=r;i++)
   	{
   		book[i]++;
	   }
//	   ll=min(ll,l);
//	   rr=max(rr,r);
	   
   }
   //sort(book,book+n,cmp);
   int ans=0;
   for(int i=1;i<=n;i++)
   {
   	 if(book[i]==m)
   	 ans++;
   	 //cout<<book[i]<<endl;
   }
   printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 3968
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)n; i++)
#define REPvec(itr, mp) for (auto itr = mp.begin(); itr != mp.end(); itr++)
#define all(x) x.begin(), x.end()
#define MOD 1000000007  // 1e9+7
using namespace std;
typedef long long int ll;
typedef vector<int> vecint;
typedef vector<ll> vecll;
typedef vector<double> vecd;
typedef vector<string> vecstr;
typedef vector<char> vecchar;
typedef vector<bool> vecbool;
typedef vector<vector<bool>> vec2bool;
typedef vector<vector<int>> vec2int;
typedef vector<vector<double>> vec2d;
typedef pair<int, int> P;
////////////////////////////////////////////////
void init() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}
////////////////////////////////////////////////
int main() {
  init();
  int n, k;
  cin >> n >> k;
  string s;
  cin >> s;
  vecint rec;
  REP(i, n) {
    int cnt = 1;
    while (i < n - 1 && s[i] == s[i + 1]) {
      i++;
      cnt++;
    }
    rec.push_back(cnt);
  }
  int init = 0;
  for (auto &e : rec) {
    // cout << e << endl;
    init += e - 1;
  }
  int m = rec.size();
  if (m % 2 == 0) {
    if (k < m / 2 - 1) {
      cout << init + 2 * k << endl;
    } else if (k == m / 2 - 1) {
      cout << n - 2 << endl;
    } else {
      cout << n - 1 << endl;
    }
  } else {
    if (k < m / 2) {
      cout << init + 2 * k << endl;
    } else {
      cout << n - 1 << endl;
    }
  }
}


Measured memory_bytes: 972
while True:
    try:
        p, q = map(int, input().split())
        ans = ""
        r_list = [p]
        while True:
            p *= 10
            a, b = divmod(p,q)
            ans += str(a)
            if b == 0:
                print(ans)
                break
            elif b in r_list:
                print(ans)
                print(" "*r_list.index(b) + "^"*(len(r_list) - r_list.index(b)))
                break
            r_list.append(b)
            p -= a*q
    except:
        break



Measured memory_bytes: 5608
# print(list(__import__('string').ascii_lowercase))

alp = list(__import__('string').ascii_lowercase)

d = {}

for i in alp:
	d[i] = d.get(i, 0) + 0

# print(d)

s = ''

while True:
    try:
        # listA=list(map(int,input().split()))
        s += input()
        #listA<-[1,2,2,3,1]
        #ここに逐次処理を書けばいいと思う。
    except:
        break;

for i in range(len(s)):
	c = s[i].lower()
	if c in alp:
		d[c] = d.get(c, 0) + 1

# print(d)

for k,v in d.items():
	print(k,':',v)


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

using namespace std;

typedef long long ll;
typedef vector<ll> vll;

#define pb push_back
#define mp make_pair

#define mod 1000000007

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define vin(v, n) for (int i = 0; i < (int)(n); i++) cin >> (v)[i];

ll power(ll a, ll b) {
	ll result = 1;
	while (b > 0) {
		if (b % 2 == 1) result = (result * a) % mod;
		a = (a * a) % mod;
		b /= 2;
	}

	return result;
}

ll inverse(ll n) {
	return power(n, mod - 2);
}

vector<ll> facts(1e6 + 5, 1);

void precompute() {
	for (ll i = 1; i <= 1e6; i++) {
		facts[i] = ((i % mod) * facts[i - 1]) % mod;
	}
}

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

	precompute();

	ll h, w, a, b;

	cin >> h >> w >> a >> b;

	ll s = 0;
	for (ll i = 0; i <= h - a - 1; i++) {
		ll t1 = (facts[b+i-1] * inverse(facts[i]) % mod * inverse(facts[b - 1]) % mod) % mod;
		ll t2 = (facts[h+w-b-2-i] * inverse(facts[h-1-i]) % mod * inverse(facts[w-b-1]) % mod) % mod;

		ll t = (t1 * t2) % mod;
		s = (s + (t % mod)) % mod;
	}
	cout << s << endl;
	
}


Measured memory_bytes: 8064
a = int(input())
b = int(input())
c = int(input())
x = int(input())

ans = 0
for i in range(0, a+1):
    for j in range(0, b+1):
        for k in range(0, c+1):
            if 500*i + 100*j + 50*k == x:
                ans += 1

print(ans)


Measured memory_bytes: 3060