akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)

template<int MOD>
struct ModInt {
  ll x;
  ModInt():x(0){}
  ModInt(ll x):x((x%MOD+MOD)%MOD){}
  int getMod() { return MOD; }
  ModInt operator-() const { return ModInt(0) - *this;}
  ModInt& operator+=(const ModInt& a){ if((x+=a.x)>=MOD) x-=MOD; return *this;}
  ModInt& operator-=(const ModInt& a){ if((x+=MOD-a.x)>=MOD) x-=MOD; return *this;}
  ModInt& operator*=(const ModInt& a){ (x*=a.x)%=MOD; return *this;}
  ModInt operator+(const ModInt& a)const{ return ModInt(*this) += a;}
  ModInt operator-(const ModInt& a)const{ return ModInt(*this) -= a;}
  ModInt operator*(const ModInt& a)const{ return ModInt(*this) *= a;}
  bool operator<(const ModInt& a)const{ return x < a.x;}
  bool operator==(const ModInt& a)const{ return x == a.x;}
  ModInt pow(ll t) const {
    if (!t) return 1;
    ModInt a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
  friend istream & operator >> (istream & in, ModInt & v) {
    ll x;
    in >> x;
    v.x = x;
    return in;
  }
  friend ostream & operator << (ostream & out, ModInt<MOD> const & v) {
    out << v.x;
    return out;
  }
};
const int MOD = 1000000007;
using mint = ModInt<MOD>;

int main() {
  ll n,k; cin >> n >> k;
  vector<mint> dp(k+1, 0); // dp[i] := gcd(A) = iとなる数列の数

  mint ans(0);
  // i := gcd(A)
  for (int i=k; i>=1; i--) {
    dp[i] = mint(k/i).pow(n);
    for (int j=i*2; j<=k; j+=i) {
      dp[i] -= dp[j];
    }
    ans += dp[i] * i;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 4056
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define All(v) (v).begin(),(v).end()
int dy[8] = {-1,0,1,0,-1,1,1,-1};
int dx[8] = {0,1,0,-1,1,1,-1,-1};
const int mod = 1000000007;
const int inf = mod*mod;
const int d5 = 100100;
signed main(){
    int n,m;
    cin>>n;
    vector<int> a(n);
    for(int i=0;i<n;i++)cin>>a[i];
    cin>>m;
    vector<int> b(m);
    for(int i=0;i<m;i++)cin>>b[i];
    sort(All(a));
    int cnt=0;
    for(int i=0;i<m;i++){
        int low=-1;
        int high=n;
        while(abs(high-low)>1){
            int mid=(high+low)/2;
            if(a[mid]>b[i])high=mid;
            else low=mid;
        }
        if(a[high]==b[i]||a[low]==b[i])cnt++;
    }
    cout<<cnt<<endl;
}


Measured memory_bytes: 3896
#include "bits/stdc++.h"
using namespace std;
void InsertionSort(int N, vector<int>& A) {
	for (int i = 1; i < N; i++) {
		if (A.at(i - 1) > A.at(i)) {
			int tmp = A.at(i);
			int j = i - 1;
			while (j >= 0) {
				if (A.at(j) <= tmp) break;
				A.at(j + 1) = A.at(j);
				j--;
			}
			A.at(j) = tmp;
		}
		for (int k = 0; k < N; k++) {
			cout << A.at(k);
			if (k != N - 1) cout << ' ';
		}
		cout << endl;
	}
}
long long GCD(long long A, long long B) {
	if (B == 0) return A;
	else return GCD(B, A % B);
}
bool Prime_Num(long long N) {
	for (long long i = 2; i <= sqrt(N); i++) {
		if (N % i == 0) {
			return false;
		}
	}
	return true;
}
int main() {
	long long N; cin >> N;
	long long M;
	long long ans = 0;
	for (long long i = 0; i < N; i++) {
		cin >> M;
		if (Prime_Num(M)) ans++;
	}
	cout << ans << endl;
}


Measured memory_bytes: 3092
#include <bits/stdc++.h>
using namespace std;
int main(){
  long long n,ans=0,x;
  cin >> n;
  long long a[n];
  for(int i=0;i<n;i++){
  	cin >> a[i];	
  	if(a[i]==i+1&&x!=i-1){
  		ans++;
  		x=i;
  	}
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1024
import sys

# お約束
args = None
INF = float("inf")
MOD = int(1e9 + 7)
def int1(n):
    return int(n) - 1
def parse(*params):
    if len(params) == 1:
        return params[0](next(args))
    return tuple(p(v) for p, v in zip(params, next(args).split()))
def debug(*v):
    if __debug__:
        print(*v, file=sys.stderr)

# エントリーポイント
def main():
    N = parse(int)
    H = [0] + list(map(int, next(args).split()))

    c = 0
    debug(H)
    for h in range(100):
        for n in range(1, N + 1):
            if H[n - 1] - h <= 0 and 0 < H[n] - h:
                c += 1
    print(c)

if __name__ == '__main__':
    args = iter(sys.stdin.read().split("\n"))
    main()


Measured memory_bytes: 3064
import java.util.*;
public class Main{
    static Scanner kbd = new Scanner(System.in);
    public static void main(String[] args){
	while(kbd.hasNext()){
	    int a = kbd.nextInt();
	    int b = kbd.nextInt();
	    if(!(a==0 && b==0)) solve(a, b);
	}
    }

    static void solve(int a, int b){
	String[] n = {"A", "B", "C", "D", "E"};
	long[] m = new long[5];
	m[0] = a+b;
	int i;
	int max = 0;
	for(i=1; i<n.length; i++){
	    a = kbd.nextInt();
	    b = kbd.nextInt();
	    m[i] = a+b;
	    if(m[i] > m[max])  max = i;
	}
	System.out.println(n[max]+" "+m[max]);
    }
}

Measured memory_bytes: 21144
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <bitset>
#include <cassert>
using namespace std;
typedef long long ll;

int main() {
	ll n; cin >> n;
	vector<ll> a(5);
	for (int i = 0; i < 5; i++) cin >> a[i];
	ll mi = 1e18; int idx = 0;
	for (int i = 0; i < 5; i++) {
		if (a[i] <= mi) {
			mi = a[i];
			idx = i;
		}
	}
	cout << (n + a[idx] - 1) / a[idx] + 4 << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
const int inf = 1e9 + 7;
const ll INF = 1e18;
#define abs(x) (x >= 0 ? x : -(x))
#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
template<typename T> T pow(T a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
const int mod = 1000000007;
ll modpow(ll a, int b) { return b ? modpow(a * a % mod, b / 2) * (b % 2 ? a : 1) % mod : 1; }
template<class T> ostream& operator<<(ostream& os, const vector<T>& vec) { for (auto &vi: vec) os << vi << " "; return os; }
template<class T, class U> ostream& operator<<(ostream& os, const pair<T, U>& p) { os << p.F << " " << p.S; return os; }
template<class T> inline void add(T &a, int b) { a += b; if (a >= mod) a -= mod; }



void solve();

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

    int T;
    // cin >> T;
    T = 1;

    while (T--) {
        solve();
    }
}

void solve() {
  string s, t;
  cin >> s >> t;
  int n = sz(s);

  // -1
  set<char> st;
  rep(i, sz(s)) st.insert(s[i]);
  rep(i, sz(t)) {
    if (!st.count(t[i])) {
      cout << -1 << endl;
      return;
    }
  }

  s += s;
  vector<vector<int> > v(26);
  rep(i, sz(s)) {
    v[s[i] - 'a'].eb(i);
  }
  // rep(i, 26) cout << (char)(i + 'a') << "  " << v[i] << endl;
  ll ans = 0;
  int it = -1;
  rep(i, sz(t)) {
    int it2 = ub(v[t[i] - 'a'], it);
    it2 = v[t[i] - 'a'][it2];

    ans += it2 - it;
    it = it2;
    it %= n;
  }

  cout << ans << endl;
}


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

const int N = 1e5 + 5;

#define int long long

int n , a[N] , Min[N] , Max[N];

main(void) {
    cin >> n;
    for(int i = 1;i <= n;++ i) {
	cin >> a[i];
    }
    Min[n] = Max[n] = 2;
    if(2 % a[n] != 0) {
	puts("-1"); return 0;
    }
    for(int i = n - 1;i >= 1;-- i) {
        int L = Min[i + 1] , R = Max[i + 1] + a[i + 1] - 1;
	L = L / a[i] + (L % a[i] != 0); R = R / a[i];
	if(L > R) {
	    puts("-1"); return 0;
	}
	Min[i] = L * a[i]; Max[i] = R * a[i];
    }
    cout << Min[1] <<" " << Max[1] + a[1] - 1 << endl;
}


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

long long n, a[ 100010 ];
long long Sum[ 100010 ], l, r;
long long Ans;
long long Tree[ 200010 ];

long long Lowbit( long long x ) { return x & -x; }

void Add( long long x ) {
    while( x <= 200001 ) {
        ++Tree[ x ];
        x += Lowbit( x );
    }
    return;
}

long long Query( long long x ) {
    long long ans = 0;
    while( x ) {
        ans += Tree[ x ];
        x -= Lowbit( x );
    }
    return ans;
}

int main() {
    scanf( "%lld", &n );
    Ans = n * ( n + 1 ) / 4 + 1;
    for( long long i = 1; i <= n; ++i ) scanf( "%lld", &a[ i ] );
    l = 0; r = 1e9 + 1;
    while( l < r ) {
        long long mid = l + r >> 1;
        for( long long i = 1; i <= n; ++i ) 
            if( a[ i ] > mid ) Sum[ i ] = -1; else Sum[ i ] = 1;
        Sum[ 0 ] = 0;
        for( long long i = 1; i <= n; ++i ) Sum[ i ] += Sum[ i - 1 ];
        for( long long i = 0; i <= n; ++i ) Sum[ i ] += 100001;
        memset( Tree, 0, sizeof( Tree ) );
        Add( Sum[ 0 ] );
        long long Cnt = 0;
        for( long long i = 1; i <= n; ++i ) {
            Cnt += Query( Sum[ i ] - 1 );
//            printf( "%lld %lld\n", i, Cnt );
            Add( Sum[ i ] );
        }
        if( Cnt >= Ans ) r = mid; else l = mid + 1;
//        printf( "%lld %lld\n", mid, Cnt );
    }
    printf( "%lld\n", l );
    return 0;
}

Measured memory_bytes: 3328
#include <stdio.h>
#include <string.h>

int main(){
	char str[101];
	int k;
	
	scanf("%d\n%s",&k, str);
	int len = strlen(str);
	
	if(len<=k){
		printf("%s\n", str);
	}
	else{
		for(int i=0;i <k; i++){
			printf("%c",str[i]);
		}
		printf("...\n");
	}
		
	return 0;}

Measured memory_bytes: 1612
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define REP(i, n) for (int i = 0; i < n; ++i)
#define range(i,a,b) ((a)<=(i) && (i)<(b))
#define debug(x) cout << #x << ' ' << '=' << ' ' << (x) << endl;
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
typedef long long ll;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;
typedef vector<ll> vec;
typedef vector<P> pvec;
typedef vector<vector<ll>> vvec;
typedef vector<vector<P>> pvvec;
typedef priority_queue<ll> PQI;
typedef priority_queue<P> PQP;
typedef priority_queue<ll,vector<ll>,greater<ll>> PQIG;
typedef priority_queue<P,vector<P>,greater<P>> PQPG;
const vector<int> dx = {0, -1, 0, 1, 1, 1, -1, -1};
const vector<int> dy = {1, 0, -1, 0, 1, -1, 1, -1};
constexpr int MOD = (1000000007);
// const int MOD = (998244353);
// const int INF = (1 << 30); // 1073741824
const int INF = (1LL << 60); // 1152921504606846976
const double EPS = (1 >> 30);
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return 1;} return 0;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return 1;} return 0;}
template< typename T1, typename T2 > istream &operator>>(istream &is, pair< T1, T2 > &p) { is >> p.first >> p.second; return is; }
int nmax=200000; // 2*(10^5)
vvec g(nmax);



signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(15);
    //---------------------------------------------
    
    int a,b,c;
    cin>>a>>b>>c;
    swap(a,b);
    swap(a,c);
    cout<<a<<" "<<b<<" "<<c<<endl;
    
}

Measured memory_bytes: 4992
#include <iostream>
#include <array>
#include <vector>
#include <map>
#include <utility>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <string>
#include <limits.h>
#include <algorithm>

using namespace std;



#define M 1 << 17


int p[M][11];
int d[M];
int c[M];
int v[M];
int n,m,q,i,j,k,a,b;

vector<int> G[M];

void dfs(int island, int length, int color){
    //塗られていたら無理
    if (length>=0 && !p[island][length]) {
        p[island][length] = color;
        for (int i = 0; i < G[island].size(); i++) {
            dfs(G[island][i], length-1, color);
        }
    }
}

int main(){
    cin >> n >> m;
    for (int i = 0; i < m; i++) {
        cin >> a>> b;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    cin >> q;
    for (j = 0; j < q; j++) {
        cin >> v[j] >> d[j] >> c[j];
    }
    //反対から塗る
    for (; q--; ) {
        int length = d[q] + 1;
        for (; length--; ) {
            dfs(v[q], length, c[q]);
        }
    }
    for (int k = 1; k < n+1; k++) {
        cout << p[k][0] << endl;
    }
    return 0;
}


Measured memory_bytes: 14328
#include<bits/stdc++.h>
#define ll long long
const double PI= 3.141592653589793238;
using namespace std;
void solve()
{
	int n,m;
	cin>>n>>m;
	int x;
	int sum=0;
	for(int i=0;i<m;i++)
	{
		cin>>x;sum+=x;
	}
	if(sum>n)
	cout<<-1;
	else
	cout<<n-sum;
}
int main()
{
	//int t;cin>>t;
	//while(t--)
	solve();
}


Measured memory_bytes: 3636
/*
confirm 0LL and 1LL
confirm cornercases such as 0
confirm times of cin < 10^6
*/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
using Pld = pair<ld, ld>;
using Vec = vector<ll>;
using VecP = vector<P>;
using VecB = vector<bool>;
using VecC = vector<char>;
using VecD = vector<ld>;
using VecS = vector<string>;
using Graph = vector<VecP>;
template <typename T>
using Vec1 = vector<T>;
template <typename T>
using Vec2 = vector<Vec1<T> >;
#define REP(i, m, n) for(ll (i) = (m); (i) < (n); ++(i))
#define REPN(i, m, n) for(ll (i) = (m); (i) <= (n); ++(i))
#define REPR(i, m, n) for(ll (i) = (m)-1; (i) >= (n); --(i))
#define REPNR(i, m, n) for(ll (i) = (m); (i) >= (n); --(i))
#define rep(i, n) REP(i, 0, n)
#define repn(i, n) REPN(i, 1, n)
#define repr(i, n) REPR(i, n, 0)
#define repnr(i, n) REPNR(i, n, 1)
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define fs first
#define sc second
template <typename T>
bool chmax(T &a, const T b){if(a < b){a = b; return true;} return false;}
template <typename T>
bool chmin(T &a, const T b){if(a > b){a = b; return true;} return false;}
template <typename T>
ll pow2(const T n){return (1LL << n);}
template <typename T>
void cosp(const T n){cout << n << ' ';}
void co(void){cout << '\n';}
template <typename T>
void co(const T n){cout << n << '\n';}
template <typename T1, typename T2>
void co(pair<T1, T2> p){cout << p.fs << ' ' << p.sc << '\n';}
template <typename T>
void co(const Vec1<T> &v){for(T i : v) cosp(i); co();}
template <typename T>
void co(initializer_list<T> v){for(T i : v) cosp(i); co();}
template <typename T>
void ce(const T n){cerr << n << endl;}
void sonic(){ios::sync_with_stdio(false); cin.tie(0);}
void setp(const ll n){cout << fixed << setprecision(n);}
constexpr int INF = 1e9+1;
constexpr ll LINF = 1e18+1;
constexpr ll MOD = 1e9+7;
//constexpr ll MOD = 998244353;
constexpr ld EPS = 1e-11;
const ld PI = acos(-1);

int main(void){
	string s;
	cin >> s;
	rep(i, s.size()){
		if(s[i] == '7'){
			puts("Yes");
			return 0;
		}
	}

	puts("No");
	return 0;
}


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

int main()
{
  int hold, con1, con2, remain;
  remain = 0;

  cin >> hold >> con1 >> con2 ;
  remain = con2 - (hold - con1);

  if((hold-con1) > con2)
  {
    cout << 0 << endl;
  }

  else
  cout << remain << endl;
}


Measured memory_bytes: 3572
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i < n; i ++)
#define rep1(i, n) for (int i=1; i <= n; i ++)
#define _min(x, y) x = min(x, y)
#define _max(x, y) x = max(x, y)
using namespace std;

const int LENGTH = 100005;

int main() {
  vector<int> l(LENGTH, 0), r(LENGTH, 0);
  string S;
  cin >> S;
  int r_cnt = 0;
  int l_cnt = 0;
  char prev = 'a';
  int l_idx = 0;

  rep(i, S.length()) {
    char c = S[i];
    if (c == 'R') {
      if (prev != c && i != 0) {
        r_cnt = 0;

        int half_l_cnt = l_cnt / 2;
        l[l_idx] = half_l_cnt + (l_cnt % 2 == 0 ? 0 : 1);
        l[l_idx - 1] = half_l_cnt;
      }
      r_cnt += 1;
    } else if (c == 'L') {
      if (prev != c){
        l_cnt = 0;
        l_idx = i;

        int half_r_cnt = r_cnt / 2;
        r[i - 1] = half_r_cnt + (r_cnt % 2 == 0 ? 0 : 1);
        r[i] = half_r_cnt;
      }
      l_cnt += 1;
    }
    prev = c;
  }
  int half_l_cnt = l_cnt / 2;
  l[l_idx] = half_l_cnt + (l_cnt % 2 == 0 ? 0 : 1);
  l[l_idx - 1] = half_l_cnt;

  rep(i, S.length() - 1) {
    cout << l[i] + r[i] << " ";
  }
  int last_idx = S.length() - 1;
  cout << l[last_idx] + r[last_idx] << endl;


  return 0;
}


Measured memory_bytes: 1408
import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline

a, b,k = map(int, input().split())
taka=1
for i in range(k):
    if taka==1:
        if a%2==1:
            a-=1
        b = b+a//2
        a = a//2
        taka = 0
    else:
        if b%2==1:
            b-=1
        a = a+b//2
        b = b//2
        taka = 1

print(a,b)

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

int main(){
  int N;
  cin >> N;
  int X = 55555;
  vector<int> sosu(0);
  for(int i=2; i<X; i++){
    bool flag = true;
    for(int j=2; j*j<=i; j++){
      if(i %j == 0){
        flag = false;
      }
    }
    if(flag && i %5 == 1){
      sosu.push_back(i);
    }
  }
  
  for(int i=0; i<N; i++){
    cout << sosu.at(i) << endl;
  }     
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void){
  int a,b,c,d;
  scanf("%d%d%d%d",&a,&b,&c,&d);
  if (a==1||b==1||c==1||d==1){
    if (a==9||b==9||c==9||d==9){
      if (a==7||b==7||c==7||d==7){
        if (a==4||b==4||c==4||d==4){
          printf("YES\n");
          return 0;
        }
      }
    }
  }
  printf("NO\n");
  return 0;
}

Measured memory_bytes: 128
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <bitset>

using namespace std;
using ll = long long int;

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

  ll prev_t = 0;
  ll prev_x = 0;
  ll prev_y = 0;
  bool ok = true;

  for (ll i = 0; i < N; i++)
  {
    ll ti, xi, yi;
    cin >> ti >> xi >> yi;

    ll walk = ti - prev_t;
    ll dist = abs(xi - prev_x) + abs(yi - prev_y);
    if (walk < dist) {
      ok = false;
    }
    if ((walk - dist) % 2 == 1) {
      ok = false;
    }

    prev_t = ti;
    prev_x = xi;
    prev_y = yi;
  }
  cout << (ok ? "Yes" : "No") << endl;
    
}

Measured memory_bytes: 3524
// AUTHOR : Kishan Srivastav
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
#define in freopen("input.txt", "r", stdin)
#define out freopen("output.txt", "w", stdout)
#define ios ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
ll gcd(ll a,ll b){ if(b==0) return a;    return gcd(b,a%b);}
ll lcm(ll a,ll b) { return (a/gcd(a,b)*b);}

int main() {
	ios
#ifndef ONLINE_JUDGE
	in;
	out;
#endif
	ll a,b,c,d;
	cin>>a>>b>>c>>d;
	
	ll x=lcm(c,d);
	ll ans=(b/c-(a-1)/c)+(b/d-(a-1)/d)-(b/x-(a-1)/x);
	cout<<b-a+1-ans<<endl;
}

Measured memory_bytes: 3600
#include<bits/stdc++.h>
#include<unordered_map>
using namespace std;
const int N=1000100,P=1e9+9;
#define X first
#define Y second
int a[18],b[18],c[18],dp[N];
unordered_map<int,int>f,sz;
int main()
{
	memset(dp,-1,sizeof(dp));
	int n,m,ans=0;
	scanf("%d%d",&n,&m);
	dp[0]=1;
	for(int i=1;i<=n;i++)dp[i]=1ll*(3*i-1)*(3*i-2)/2%P*dp[i-1]%P;
	for(int i=0;i<m;i++)scanf("%d%d%d",&a[i],&b[i],&c[i]);
	for(int i=0;i<(1<<m);i++)
	{
		int coef=1,res=1,cnt[4]={};
		bool ff=0;f.clear();sz.clear();
		for(int j=0;j<m;j++)
		{
			if(i&(1<<j))
			{
				if(c[j])coef*=-1;
				if(!f.count(a[j]))f[a[j]]=a[j],sz[a[j]]=1;
				if(!f.count(b[j]))f[b[j]]=b[j],sz[b[j]]=1;
				if(f[a[j]]!=f[b[j]])
				{
					if(sz[f[a[j]]]+sz[f[b[j]]]>3)ff=1;
					else if(sz[f[a[j]]]<sz[f[b[j]]])f[a[j]]=f[b[j]],sz[f[b[j]]]++;
					else f[b[j]]=f[a[j]],sz[f[a[j]]]++;
				}
			}
			else if(!c[j]) coef=0;
		}
		if(!ff)
		{
			for(auto it=f.begin();it!=f.end();++it)if(it->X==it->Y)cnt[sz[it->X]]++;
			cnt[1]=3*n-2*cnt[2]-3*cnt[3];
			for(int i=0;i<cnt[2];i++){res=1LL*res*cnt[1]%P;cnt[1]--;}
			res=1LL*res*dp[cnt[1]/3]%P;
		}
		else res=0;
		ans=(ans+1ll*res*(P+coef))%P;
	}
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 7136
#include"bits/stdc++.h"

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

int main() {
	int n,t,x,y,dist;
	int bt, bx, by;
	bt = by = bx = 0;
	bool  ans = true;
	cin >> n;
	rep(i, n) {
		cin >> t >> x >> y;
		dist = max(bx, x) - min(bx, x) + max(by, y) - min(by, y);
		if (t - bt < dist || (t - bt) % 2 != dist % 2)ans = false;
		bt = t, bx = x, by = y;
	}
	if (ans) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n,ans;
string s[305];
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>n;
	for(int i=0;i<n;i++)cin>>s[i];
	for(int B=0;B<n;B++){
		bool frog=true;
		for(int i=0;i<n;i++)for(int j=0;j<i;j++)frog&=(s[(i+B)%n][j]==s[(j+B)%n][i]);
		ans+=frog;
	}
	cout<<ans*n<<endl;
	return 0;
}

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

using namespace std;

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#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);i>=(b);i--)
#define RREP(i, n) RFOR(i, n, 0)
#define MFOR(i, m) for(auto i=(m).begin();i!=(m).end();i++)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((int)(x).size())

typedef long long int ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;

const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1 << 30;

int main () {
  cin.tie(0);
  cout << setprecision(10);

  int l, k; cin >> l >> k;

  // 長さiで上の色がcのときの個数
  vector<vector<ll>> dp(l+k+1);
  REP(i, l+k+1) {
    dp[i].resize(2);
  }

  // 初期化
  dp[1][0] = 1;
  dp[k][0] = 1;

  // 遷移
  REP(i, l+1) {
    dp[i+1][0] += dp[i][1];
    dp[i+k][0] += dp[i][1];
    dp[i+1][1] += dp[i][0];
  }

  ll ans = 0;
  REP(i, l+1) {
    ans += dp[i][0];
  }
  cout << ans << endl;

}



Measured memory_bytes: 3116
import numpy as np
from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson
from scipy.sparse import csr_matrix

n, x, y = map(int, input().split())
ma = [[0]*n for _ in range(n)]
for i in range(n-1):
    ma[i][i+1] = 1
    ma[i+1][i] = 1

ma[x-1][y-1] = 1
ma[y-1][x-1] = 1
a = csr_matrix(ma)
b = dijkstra(a, directed=False).astype(int)
ans = np.bincount(b.ravel(), minlength=n) // 2
print(*ans[1:], sep='\n')

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

int main()
{
	int H, W;
	cin >> H >> W;
	while (H != 0 && W != 0)
	{
		for (int i = 0; i < W; i++)
		{
			cout << "#";
		}
		cout << endl;
		for (int i = 0; i < (H - 2); i++)

		{
			cout << "#";
			for (int j = 0; j < (W - 2); j++)
			{
				cout << ".";
			}
			cout << "#";
			cout << endl;

		}
		
		for (int i = 0; i < W; i++)
		{
			cout << "#";
		}
		cout << endl;
		cout << endl;
		cin >> H >> W;
	}
	return 0;
}


Measured memory_bytes: 3068
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < int(n); i++)
using namespace std;
using ll = long long;
const int INF = (1<<30)-1;
const long long LINF = (1LL<<62)-1;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int h, w, k;
  cin >> h >> w >> k;
  vector<vector<ll>> grid(h, vector<ll>(w));
  rep(i, k) {
    int x, y, v;
    cin >> x >> y >> v;
    --x, --y;
    grid[x][y] = v;
  }
  vector<vector<vector<ll>>> dp(h, vector<vector<ll>>(w, vector<ll>(4)));
  if (grid[0][0])
    dp[0][0][1] = grid[0][0];
  rep(i, h) rep(j, w) rep(k, 4) {
    if (i+1 < h) {
      chmax(dp[i+1][j][0], dp[i][j][k]);
      if (grid[i+1][j])
        chmax(dp[i+1][j][1], dp[i][j][k]+grid[i+1][j]);
    }
    if (j+1 < w) {
      chmax(dp[i][j+1][k], dp[i][j][k]);
      if (grid[i][j+1] && k < 3)
        chmax(dp[i][j+1][k+1], dp[i][j][k]+grid[i][j+1]);
    }
  }
  ll ans = 0;
  rep(i, 4)
    chmax(ans, dp[h-1][w-1][i]);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 706028
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <iomanip>
using namespace std;
#define int long long

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

    int n; cin >> n;
    vector<int> a(n);
    for(int i = 0;i < n;i ++) cin >> a.at(i);

    vector<pair<int,int> > b(n);
    for(int i = 0;i < n;i ++){
        b.at(i).first = a.at(i);
        b.at(i).second = i+1;
    }

    sort(b.begin(),b.end());
    for(int i = 0;i < n;i ++){
        cout << b.at(i).second << " ";
    }
    cout << endl;
}

Measured memory_bytes: 5516
/*
神题
合法的矩形中每个2*2的子矩形黑点个数必为偶数
以此转化原图，找出所有极大子矩形，统计答案
*/
#include<cstdio>
#include<cstring>
#include<algorithm>
#define N 2010
using namespace std;
int n, m, m1[N][N], map[N][N], sum, ans, L[N][N], R[N][N], h[N][N];
char S[N];
int main(){
	scanf("%d%d", &n, &m);
	for(int i=1; i<=n; i++){
		scanf("%s", S+1);
		for(int j=1; j<=m; j++)m1[i][j]=S[j]=='#'?1:0;
	}
	for(int i=1; i<=n-1; i++)
		for(int j=1; j<=m-1; j++){
			sum=m1[i][j]+m1[i][j+1]+m1[i+1][j]+m1[i+1][j+1];
			map[i][j]=sum&1?0:1;
		}
	ans=max(n, m);
	for(int i=1; i<=n-1; i++){
		L[i][0]=0;
		for(int j=1; j<=m-1; j++)L[i][j]=map[i][j]?L[i][j-1]:j;
		R[i][m]=m;
		for(int j=m-1; j; j--)R[i][j]=map[i][j]?R[i][j+1]:j;
	}
	for(int i=1; i<=m-1; i++){L[0][i]=0; R[0][i]=m; h[0][i]=0;}
	for(int i=1; i<=n-1; i++)
		for(int j=1; j<=m-1; j++){
			if(!map[i][j]){L[i][j]=0; R[i][j]=m; h[i][j]=0; continue;}
			h[i][j]=h[i-1][j]+1; L[i][j]=max(L[i-1][j], L[i][j]); R[i][j]=min(R[i-1][j], R[i][j]);
			ans=max(ans, (R[i][j]-L[i][j])*(h[i][j]+1));
		}
	printf("%d", ans);
	return 0;
}

Measured memory_bytes: 78976
#include <iostream>
#include <cmath>

#define N_MAX 100000

using namespace std;

int main(){
    int N;
    int A[N_MAX];
    int sum = 0;
    int diff;
    
    cin >> N;
    for(int i = 0; i < N; i++){
        cin >> A[i];
    }
    sum += abs(A[0]);
    for(int i = 1; i < N; i++){
        sum += abs(A[i] - A[i-1]);
    }
    
    sum += abs(A[N-1]);
    
    diff = abs(A[0]) + abs(A[1] - A[0]) -  abs(A[1]);
    cout << sum - diff << endl;
    for(int i = 1; i < N-1; i++){
        diff = abs(A[i] - A[i-1]) + abs(A[i+1] - A[i]) -  abs(A[i+1] - A[i-1]);
        cout << sum - diff << endl;
    }
    diff = abs(A[N-1] - A[N-2]) + abs(A[N-1]) -  abs(A[N-2]);
    cout << sum - diff << endl;
}

Measured memory_bytes: 1664
#include <iostream>
#include <string>
#include <algorithm>
#include <map>
#include <vector>
#include <tuple>

using namespace std;

int main()
{
 int n;
 cin >> n;
 if(n >= 1200){
     cout << "ARC" << endl;
 }else{
     cout << "ABC" << endl;
 }
}

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

bool is_prime(int n) {
	for (int i = 2; i*i <= n; i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}

int main() {
	int a, d, n;
	while (cin >> a >> d >> n, a) {
		int p = 0;
		for (int i = a;; i += d) {
			if (is_prime(i))p++;
			if (p == n) {
				cout << i << endl;
				break;
			}
		}
	}
}

Measured memory_bytes: 3080
#include <iostream>
using namespace std;
int main(void){
    long N,T,i,c,t,ans,temp;
    temp=1000;
    ans=1000;
    cin >> N >> T;
    for (i=0;i<N;i++){
        cin >> c >> t;
        if (T>=t){
        if (ans>=c) {
            ans=c;
            temp=t;
        }
        }
    }
    if (temp==1000)
    cout << "TLE" <<endl;
    else cout << ans << endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#include <sys/timeb.h>
#include <fstream>

using namespace std;

#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define replrev(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define reprev(i,n) replrev(i,0,n)
#define repi(itr,ds) for(auto itr = ds.begin(); itr != ds.end(); ++itr)
#define mp make_pair
#define INF 2000000000
#define INFL 2000000000000000000LL
#define MOD 1000000007
#define PI 3.1415926536
#define RMAX 4294967295
typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<double> vd;
typedef vector<P> vP;
typedef vector<vector<int> > vvi;
typedef vector<vector<ll> > vvll;
typedef vector<vector<char> > vvc;
typedef vector<vector<P> > vvP;
typedef priority_queue<int, vector<int>, greater<int> > pqli;
typedef priority_queue<P, vector<P>, greater<P> > pqlP;
typedef pair<int, pair<int, int> > Edge;

int N, M;
vvi G;
vi col;

// 奇数長の閉路が見つかったらfalse
bool dfs(int s, int ncol) {
	col[s] = ncol;
	bool ret = true;
	rep(i, G[s].size()) {
		if (col[G[s][i]] != 0) {
			if (col[G[s][i]] == ncol) {
				ret = false;
			}
			continue;
		}
		if (!dfs(G[s][i], -ncol)) {
			ret = false;
		}
	}
	return ret;
}

int main() {
	cin >> N >> M;
	G = vvi(N);
	col = vi(N, 0);
	rep(i, M) {
		int u, v;
		cin >> u >> v;
		u--;
		v--;
		G[u].push_back(v);
		G[v].push_back(u);
	}

	ll odd = 0, even = 0, isol = 0;

	rep(i, N) {
		if (G[i].size() == 0) {
			isol++;
			continue;
		}
		if (col[i] == 0) {
			if (dfs(i, 1))even++;
			else odd++;
		}
	}
	ll ans = (odd + even)*(odd + even) + even * even + 2 * (N - isol) * isol + isol * isol;

	//cout << odd << ',' << even << ',' << isol << endl;

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 9984
#include<bits/stdc++.h>
using namespace std;
#define ll long  
#define pb push_back 
#define mod 1e9+7
 
int main(){
      ios_base::sync_with_stdio(0) ; cin.tie(0) ; cout.tie(0);    
       ll n;
            cin>>n;
      set<long>s;
  for(ll i=0; i<n; i++)
  {  ll k;
      cin>>k;
     s.insert(k);
   
  }
     if((ll)s.size()==n)
        cout<<"YES"<<endl;
  else
      cout<<"NO"<<endl;
  
  
    }


Measured memory_bytes: 9600
#include <iostream>
#include <string>
#include <vector>
using namespace  std;
typedef long long lint;
#define REP(i, n) for(long long (i)=0; (i)<(n); ++i)
const lint MOD = (lint)1e9 + 7;
signed main(){
    string S; cin >> S;
    int n = S.size();
    vector<vector<lint> > DP(n+1, vector<lint>(4, 0));
    DP[n][3] = 1;
    REP(i, 3) DP[n][i] = 0;
    for(int j=3; j>=0; j--){
        for(int i=n-1; i>=0; --i){
            int m1, m2; //m1 reffers to case to select S[i]
            m1 = (S[i]=='?' || S[i]==(char)('A'+j)? 1 : 0); 
            m2 = (S[i]=='?' ? 3 : 1);
            if(j==3) DP[i][j] = (m2 * DP[i+1][j])%MOD;
            else DP[i][j] = ((m1 * DP[i+1][j+1])%MOD + (m2 * DP[i+1][j])%MOD)%MOD;
        }
    }
    cout << DP[0][0] << endl;
    return 0;
}

Measured memory_bytes: 7424
#include<iostream>
#include<vector>

using namespace std;




int main(){

    int N,M;
    cin >> N >> M;

    int ans;

    if(N>=2 && M>=2){
        ans = N*(N-1)/2+M*(M-1)/2;
    }
    if(N>=2 && M<2){
        ans = N*(N-1)/2;
    }
    if(N<2 && M>=2){
        ans = M*(M-1)/2;
    }
    if(N<2 && M<2){
        ans = 0;
    }

    cout << ans << endl;



}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define uint ungigned
#define db double
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pli pair<ll,int>
#define vi vector<int>
#define vpi vector<pii >
#define IT iterator
 
#define PB push_back
#define MK make_pair
#define LB lower_bound
#define UB upper_bound
#define y1 wzpakking
#define fi first
#define se second
#define BG begin
#define ED end
 
#define For(i,j,k) for (int i=(int)(j);i<=(int)(k);i++)
#define Rep(i,j,k) for (int i=(int)(j);i>=(int)(k);i--)
#define UPD(x,y) (((x)+=(y))>=mo?(x)-=mo:233)
#define CLR(a,v) memset(a,v,sizeof(a))
#define CPY(a,b) memcpy(a,b,sizeof(a))
#define sqr(x) (1ll*x*x)
 
#define LS3 k*2,l,mid
#define RS3 k*2+1,mid+1,r
#define LS5 k*2,l,mid,x,y
#define RS5 k*2+1,mid+1,r,x,y
#define GET pushdown(k);int mid=(l+r)/2
#define INF (1ll<<60)
using namespace std;
const int mo=1000000007;
int power(int x,int y){
	int s=1;
	for (;y;y/=2,x=1ll*x*x%mo)
		if (y&1) s=1ll*s*x%mo;
	return s;
}
int calc(int y){
	return 1ll*(power(10,y)-1)*power(9,mo-2)%mo;
}
int n,Q,v[35];
int f[33333][10];
pii q[35];
int main(){
	scanf("%d%d",&n,&Q);
	For(i,1,Q){
		int x,y;
		scanf("%d%d",&x,&y);
		q[i]=pii(x-1,i);
		q[i+Q]=pii(y,i);
	}
	sort(q+1,q+2*Q+1);
	For(i,1,2*Q-1) v[i]=calc(q[i+1].fi-q[i].fi);
	f[0][0]=1;
	For(i,0,(1<<Q)-1){
		for (int to=1;to<1<<Q;){
			if (to^(i&to)){
				to+=to^(i&to);
				continue;
			}
			int val=1;
			For(j,1,2*Q-1){
				int s1=0,s2=0;
				if (to&(1<<(q[j].se-1))) s1=2;
				else if (i&(1<<(q[j].se-1))) s1=1;
				if (to&(1<<(q[j+1].se-1))) s2=2;
				else if (i&(1<<(q[j+1].se-1))) s2=1;
				if (s1+s2==4) val=1ll*val*(v[j]+1)%mo;
				else if (s1+s2==3) val=1ll*val*v[j]%mo;
			}
			For(j,0,8)
				f[i][j+1]=(f[i][j+1]+1ll*val*f[i-to][j])%mo;
			++to;
		}
		For(j,0,8)
			f[i][j+1]=(f[i][j+1]+f[i][j])%mo;
	}
	int ans=1ll*f[(1<<Q)-1][9]*power(9,mo-2)%mo;
	int cnt=n-q[2*Q].fi+q[1].fi;
	printf("%d\n",1ll*ans*power(10,cnt)%mo);
}

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

int main(){
  string S;
  long long K;
  cin >> K;
  cin >> S;
  if(S.size() <= K){
    cout<< S <<endl;
  }
  else if(S.size() > K){
    for(long long i=0; i<K; i++){
      cout<< S.at(i);
      if(i==K-1){
        cout << "..."<<endl;
      }
    
    }
  }
}

Measured memory_bytes: 3628
import java.util.Scanner;

class Main {
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);

        int d = sc.nextInt();
        int n = sc.nextInt();

        if(n == 100){
            n++;
        }

        System.out.println((int)Math.pow(100, d) * n);
    }
}

Measured memory_bytes: 21844
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1000005), 1000005)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func getNextUint64(scanner *bufio.Scanner) uint64 {
	i, _ := strconv.ParseUint(getNextString(scanner), 10, 64)
	return i
}

func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}

func main() {
	fp := os.Stdin
	wfp := os.Stdout
	cnt := 0

	if os.Getenv("MASPY") == "ますピ" {
		fp, _ = os.Open(os.Getenv("BEET_THE_HARMONY_OF_PERFECT"))
		cnt = 1
	}
	if os.Getenv("MASPYPY") == "ますピッピ" {
		wfp, _ = os.Create(os.Getenv("NGTKANA_IS_GENIUS10"))
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(wfp)
	solve(scanner, writer)
	for i := 0; i < cnt; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
	writer.Flush()
}

func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	n := getNextInt(scanner)
	h := getNextInt(scanner)
	w := getNextInt(scanner)

	ans := 0
	for i := 0; i < n; i++ {
		a := getNextInt(scanner)
		b := getNextInt(scanner)
		if h > a {
			continue
		}
		if w > b {
			continue
		}
		ans++
	}

	fmt.Fprintln(writer, ans)
}


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

using namespace std;

int main() {
	int D;
	cin >> D;

	if (D == 25) {
		cout << "Christmas" << endl;
	}
	else if (D == 24) {
		cout << "Christmas Eve" << endl;
	}
	else if (D == 23) {
		cout << "Christmas Eve Eve" << endl;
	}
	else if (D == 22) {
		cout << "Christmas Eve Eve Eve" << endl;
	}
}

Measured memory_bytes: 256
N=int(input())
S=[0]*N
for i in range (N):
    S[i]=input()

#S.sort()


result={}
for i in range (0,len(S)):
    item = S[i]
    if item in result:
        result[item] = result[item]+1
    else:
        result[item] = 1

max_v = max(result.values())

keys = [k for k, v in result.items() if v == max_v]

keys.sort()
s_n = '\n'.join(keys)
print(s_n)

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

using namespace std;
const int MAX_H = 50, MAX_W = 51;
const int INF = 10000;

char area[MAX_H][MAX_W];
int H, W, d[MAX_H][MAX_W];
typedef pair<int, int> P;

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

bool judge(int y, int x)
{
  if(y >= 0 && y < H && x >= 0 && x < W && d[y][x] == INF && area[y][x] != '#')
    return true;
  else 
    return false;
}

int bfs()
{
  queue<P> que;
  
  for(int i = 0; i < H; i++){
    for(int j = 0; j < W; j++){
      d[i][j] = INF;
    }
  }

  que.push(P(0, 0));
  d[0][0] = 0;

  while(que.size()){
    P p = que.front(); que.pop();
    if(p.first == H && p.second == W){
      break;
     }

    for(int i = 0; i < 4; i++){
      int ny = p.first + dy[i], nx = p.second + dx[i];
      if(judge(ny, nx)){
        que.push(P(ny, nx));
        d[ny][nx] = d[p.first][p.second] + 1;
      }
    }
  }

  return d[H - 1][W - 1];

}

int main()
{
  int tmp, count = 0;
  cin >> H >> W;
  for(int i = 0; i < H; i++){
    for(int j = 0; j < W; j++){
      cin >> area[i][j];
      if(area[i][j] == '#') count++;
    }
  }

  tmp = bfs();

  if(tmp != INF) cout << H * W - 1 - tmp - count << endl;
  else cout << -1 << endl;

  return 0;
}




























Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<pair<int, int> > vpii;
typedef pair<int, int> pii;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
#define INF 1000000000
#define MOD 998244353
#define EPSILON 0.00001
#define f first
#define s second
#define pb push_back
#define mp make_pair

#define FOR(i, a, b) for (int i=(a); i<=(signed)(b); i++)
#define F0R(i, a) for (int i=0; i<(signed)(a); i++)
#define RFOR(i, a, b) for (int i=(a); i >= b; i--)

#define MN 200005
int n;
string s;

ll modExp(ll b, ll ex){
    ll prod = 1;
    while(ex > 0){
        if(ex % 2 == 0){
            b = (b * b) % MOD;
            ex /= 2;
        } else{
            prod = (prod*b) % MOD;
            ex--;
        }
    }
    
    return prod;
}

vi facs[MN];
void sieve(){
    FOR(i, 1, MN-1){
        for(int j=i*2; j<MN; j+=i){
            facs[j].pb(i);
        }
    }
}
ll cnts[MN];

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

    sieve();

    cin >> n >> s;

    ll ans = 0;
    
    RFOR(i, n, 1){ //i = # blocks
        if((i % 2 == 0) || (n % i != 0)) continue;
        ll cnt = 0;
        int sz = n/i;
        F0R(j, sz){
            if(s[j] == '1') cnt += modExp(2, sz-j-1);
            cnt %= MOD;
        }
        bool ok = true;
        bool gd = false;
        FOR(j, 1, i-1){
            FOR(k, sz*j, sz*(j+1)-1){
                //cout << "doing " << j << " " << k << " " << s[k] << "\n";
                if(j%2==0){
                    if(s[k] < s[k%sz]) ok = false;
                    if(s[k] > s[k%sz]) gd = true;
                } else{
                    if(s[k] < ('1'+'0'-s[k%sz])) ok = false;
                    if(s[k] > ('1'+'0'-s[k%sz])) gd = true;
                }
                if(!ok) break;
                if(gd) break;
            }
            if(!ok) break;
            if(gd) break;
        }
        if(ok) ++cnt;
        //else cout << "hmm\n";

        for(auto u : facs[sz]){
            cnt = cnt - cnts[u];
            cnt = (cnt+MOD)%MOD;
        }
        cnts[sz] = cnt;
        //cout << i << " " << cnt << "\n";
        ans += (sz*2*cnt)%MOD;
        ans %= MOD;
    }

    cout << ans << "\n";
    
    return 0;
}


Measured memory_bytes: 22096
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <fstream>
#include <cstdlib>
#include <ctime>
#include <string>
#include <cstring>
#include <fstream>
#include <random>
#include <tuple>
#include <climits>
#include <unordered_map>

using namespace std;

//int X[100000], Y[100000];
//
//void solve() {
//    int P, Q, x, y;
//    char d;
//    cin>>P>>Q;
//    memset(X, 0, sizeof(X));
//    memset(Y, 0, sizeof(Y));
//    for (int i=0; i<P; i++) {
//        cin>>x>>y>>d;
//        if (d == 'N') for (int j= y+1; j<=Q; j++) Y[j]++;
//        if (d == 'S') for (int j= 0; j<y; j++) Y[j]++;
//        if (d == 'E') for (int j= x+1; x<=Q; j++) X[j]++;
//        if (d == 'W') for (int j= 0; j<x; j++) X[j]++;
//    }
//    int ans = 0;
//    for (int i=0; i<=Q; i++) {
//        if (X[i])
//    }
//
//}



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

    int n, k;
    cin>>n>>k;
    cout<<n-k+1<<endl;

//    int T;
//    cin>>T;
//    for (int t=1; t<=T; t++) {
//        cout<<"Case #"<<t<<": ";
//        solve();
//    }
    return 0;
}

Measured memory_bytes: 256
from collections import defaultdict
from itertools import permutations

n, c = map(int, input().split())
d = [list(map(int, input().split())) for _ in range(c)]
cmat = [list(map(int, input().split())) for _ in range(n)]

dcnt = [defaultdict(int) for _ in range(3)]
for i, ci in enumerate(cmat, 1):
    for j, cij in enumerate(ci, 1):
        mod = (i + j) % 3
        dcnt[mod][cij - 1] += 1

ans = 10 ** 9
for color in permutations(range(c), 3):
    tmp = 0
    for ci, cnt in zip(color, dcnt):
        tmp += sum(d[k][ci] * cnt[k] for k in cnt)
    ans = min(ans, tmp)
print(ans)


Measured memory_bytes: 77316
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
    int h, w, n;
    cin >> h >> w >> n;

    vector<pair<int, int>> rc(n);

    for (int i = 0; i < n; i++) {
        cin >> rc[i].first >> rc[i].second;
        rc[i].first--;
        rc[i].second--;
    }

    rc.emplace_back(h - 1, w - 1);
    n++;

    sort(rc.begin(), rc.end());

    using i64 = long long;

    const i64 mod = 1000000000 + 7;

    vector<i64> inv(h + w + 1);
    vector<i64> fact(h + w + 1);
    vector<i64> fact_inv(h + w + 1);

    for (i64 i = 1; i < h + w + 1; i++) {
        inv[i] = (i == 1) ? 1 : (mod - (mod / i) * inv[mod % i] % mod);
    }

    fact[0] = 1;
    fact_inv[0] = 1;

    for(int i = 1; i < h + w + 1; ++i) {
        fact[i] = fact[i - 1] * i % mod;
        fact_inv[i] = fact_inv[i - 1] * inv[i] % mod;
    }

    auto comb = [&](int n, int k) {
        if (n < 0 || k < 0) {
            return i64(0);
        }

        if (n < k) {
            return i64(0);
        }

        return fact[n] * fact_inv[n - k] % mod * fact_inv[k] % mod;
    };

    auto f = [&](int x, int y) {
        return comb(x + y, y);
    };

    vector<i64> dp(n);

    for (int i = 0; i < n; i++) {
        dp[i] = f(rc[i].first, rc[i].second);

        for (int j = 0; j < i; j++) {

            if (rc[i].second >= rc[j].second) {
               dp[i] = (dp[i] - dp[j] * f(rc[i].first - rc[j].first, rc[i].second - rc[j].second) % mod + mod) % mod;
            }
        }
    }

    cout << dp[n - 1] << endl;
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
#define arep(a,i,n) for(ll i=(a);i<(n);i++)
#define rep(i,n) for(ll i=0;i<(n);i++)
#define cinf(x,n) for(ll i=0;i<(n);i++)cin>>x[i];
#define coutf(x,n) for(ll i=0;i<(n);i++)cout<<x[i]<<endl;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

using namespace std;

string a[51];
string b[51];

int main(){
	int n,m;
	cin >> n >> m;
	rep(i,n)cin>>a[i];
	rep(i,m)cin>>b[i];
	rep(i,n-m+1){
		rep(j,n-m+1){
			rep(k,m){
				if(a[i+k].substr(j,m)!=b[k])break;
				else if(k==m-1){
					cout << "Yes" << endl;
					return 0;
				}
			}
		}
	}
	cout << "No" << endl;
}

Measured memory_bytes: 3544
#define ENABLE_DEBUG 1
// Kana's kitchen {{{
#include<bits/stdc++.h>
#define ALL(v) std::begin(v),std::end(v)
#define LOOP(k) for(i64 ngtkana_is_a_genius=0; ngtkana_is_a_genius<(i64)k; ngtkana_is_a_genius++)

using i32 = std::int_least32_t;
using i64 = std::int_least64_t;
using u32 = std::uint_least32_t;
using u64 = std::uint_least64_t;
using usize = std::size_t;

template <class T, class U> using pair = std::pair<U, T>;
template <class T> using diag_pair = std::pair<T, T>;
template <class... Args> using tuple = std::tuple<Args...>;
template <class T> using vec = std::vector<T>;
template <class T> using numr = std::numeric_limits<T>;

#ifdef NGTKANA
#include<debug.hpp>
#else
#define DEBUG(...)(void)0
#endif
/*}}}*/

int main(){
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    std::cout << std::setprecision(15) << std::fixed;

    std::string s;
    std::cin >> s;
    vec<usize> ckd(26);
    for (char c: s) ckd.at(c-'a')=true;
    usize i=0;
    for (; i<26 && ckd.at(i); i++);
    std::cout << (i==26 ? "None" : std::string(1,'a'+i)) << '\n';
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll mod=1e9+7;
int main(void){
    string K;
    int D;
    cin>>K>>D;
    int n=K.size();
    ll dp[10001][2][100]={};//dp[上から何桁目まで決めたか][未満フラグ][各桁の和をDで割った余り]
    dp[0][0][0]=1;//初期条件
    for(int i=0;i<n;i++){
        int a=K[i]-'0';
        for(int j=0;j<D;j++){
            for(int x=0;x<10;x++){
                dp[i+1][1][(j+x)%D]+=dp[i][1][j];//i桁目までの段階でK未満確定→(i+1)桁目までの段階でK未満確定
                if(x==a){
                    dp[i+1][0][(j+x)%D]+=dp[i][0][j];//i桁目まで一致→(i+1)桁目まで一致
                }
                else if(x<a){
                    dp[i+1][1][(j+x)%D]+=dp[i][0][j];//i桁目まで一致→(i+1)桁目の段階でK未満確定
                }
                dp[i+1][0][(j+x)%D]%=mod;
                dp[i+1][1][(j+x)%D]%=mod;
            }
        }
    }
    cout<<(dp[n][0][0]+dp[n][1][0]-1+mod)%mod<<endl;//dpでは「0」も数えられているのでそれを引く
}

Measured memory_bytes: 16000
//In the name of the Almighty

   #include <bits/stdc++.h>
using namespace std;
#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int main( )
{

  optimize();

   string s;
   cin>>s;
   int sum=0;
   for (int i=0; i<s.size(); i++)
   {
       int x= s[i]-48;
       sum=sum+x;
   }
  if (sum%9==0) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
       return 0;
}



Measured memory_bytes: 3676
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <functional>

using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define VI vector<int>
#define debug(x) cout<<#x<<": "<<x<<endl
#define DEBUG(x) cout<<#x<<": "<<x<<endl
int N;
vector <long long > A,B,C,AB,BC;





int main()
{

	cin >> N;

	A.resize(N);
	B.resize(N);
	C.resize(N);
	AB.resize(N);
	BC.resize(N);


	REP(i,N){
		cin >> A[i];
	}
	REP(i,N){
		cin >> B[i];
	}
	REP(i,N){
		cin >> C[i];
	}

	sort(A.begin(),A.end());
	sort(B.begin(),B.end());
	sort(C.begin(),C.end());

	int num=0;
	REP(i,N){
		while(B[i]>=C[num]){
			num++;
		}
		if(num>N-1)
			break;
		BC[i]=N-num;
	}
	long long sum = 0;
	REP(i,N){
		sum += BC[i];
	}
	REP(i,N){
		long long temp = BC[i];
		BC[i] = sum;
		sum -= temp;
		while(i != N-1 && B[i]==B[i+1]){
			BC[i+1] = BC[i];
			i++;
			sum -= temp;
		}
	}

	num = 0;
	REP(i,N){
		while(A[i]>=B[num]){
			num++;
		}
		if(N-1<num)
			break;
		AB[i]=BC[num];
	}

	long long ans=0;
	REP(i,N){
		ans += AB[i];
	}
	cout << ans;
}

Measured memory_bytes: 4224