akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define INF 1e9
using namespace std;

#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ALL(a)  (a).begin(),(a).end()

template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}
typedef long long ll;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}

/**
 * 固定長キュークラス
 */
template <typename T>
class FixedQueue
{
public:

    typedef typename std::deque<T>::iterator iterator;
    typedef typename std::deque<T>::const_iterator const_iterator;

    //! サイズ指定コンストラクタ
    FixedQueue(size_t size)
    {
        que.resize(size);
    }

    //! 後ろに要素を追加
    void push_back(const T&& t)
    {
        que.pop_front();
        que.push_back(t);
    }

    void push_back(const T& t)
    {
        que.pop_front();
        que.push_back(t);
    }

    //! 前に要素を追加
    void push_front(const T&& t)
    {
        que.pop_back();
        que.push_front(t);
    }

    void push_front(const T& t)
    {
        que.pop_back();
        que.push_front(t);
    }



    iterator begin() { return que.begin(); }
    const_iterator begin() const { return que.begin(); }

    iterator end() { return que.end(); }
    const_iterator end() const { return que.end(); }

private:

    std::deque < T > que;       //!< データが格納されているコンテナ
};

void solve() {
    int N;
    cin >> N;
    // val,amount
    map<int,int> mp;
    REP(i,N) {
        int a;
        cin >> a;
        if (mp.count(a) == 0) mp[a] =0;
        mp[a]++;
    }

    int cnt=0;
    // mapは内部で昇順ソート
    FixedQueue<int> q(2);
    for(auto const& itr: mp) {
        if (itr.second > 1) {
            q.push_back(itr.first);
            cnt++;
        }
        if (itr.second > 3) {
            q.push_back(itr.first);
            cnt++;
        }
    }

    if (cnt < 2) {
        cout << 0 << endl;
        exit(0);
    }

    ll ans = 1;
    for(auto const& it: q) {
        ans*=it;
    }
    cout << ans << endl;


}

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


Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define REP(i,x,n) for(int i = (x); i < (n); ++i)
#define ll long long
#define P pair<ll,ll>
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()

const ll mod = 1e9+7;
const ll INF = 1e18;
const double pi = acos(-1);
//const ll mod = 998244353;

ll lcm(ll a, ll b){
    return a / __gcd(a, b) * b;
}

int main(void)
{
    ll n, k;
    cin >> n >> k;
    vector<ll> a(n), s, ord(n+1,-1);
    rep(i,n) cin >> a[i];
    ll c = 1, l = 0;
    {
        ll v = 1; //1スタートなのでordのサイズはn+1
        while(ord[v] == -1){ //未訪問なら続行
            ord[v] = s.size();
            s.push_back(v);
            v = a[v-1];
        }
        c = s.size() - ord[v];
        l = ord[v];
    }
    if(k < l) cout << s[k] << endl;
    else{
        k -= l;
        k %= c;
        cout << s[l+k] << endl;
    }
    return 0;
}

Measured memory_bytes: 8480
fun main() {
    var n = readLine()!!.toInt()
    var a = readLine()!!.split(" ").map { it.toInt() }

    var q = readLine()!!.toInt()
    var l = Array(q){0}
    var d = Array(100010){0}

    var s = 0L
    for(i in 0 until n) {
        s += a[i]
        d[a[i]]++
    }

    for(i in 0 until q) {
        var (b, c) = readLine()!!.split(" ").map{it.toInt()}

        l[i] = c - b

        s += l[i] * d[b]
        println(s)

        d[c] += d[b]
        d[b] = 0
    }
}

Measured memory_bytes: 70608
#include <bits/stdc++.h>
using namespace std;
 
int main() {
	int H,W;
	cin >> H >> W;
	vector<string> A(H);
	for (int i = 0; i<H; i++){
		cin >> A.at(i);
	}
	
	for (int i = 0; i<W+2; i++){
		cout << '#';
	}
	cout << endl;
	
	for (int i = 0; i<H;i++){
		cout << '#' << A.at(i) << '#' << endl;
	}
		
	for (int i = 0; i<W+2; i++){
		cout << '#';
	}
	cout << endl;	
	
}

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

using namespace std;

int main()
{
	char b;
	cin >> b;
	if(b == 'A')
		cout << "T" << endl;
	else if(b == 'T')
		cout << "A" << endl;
	else if(b == 'C')
		cout << "G" << endl;
	else
		cout << "C" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 1000000007
#define MOD 1000000007
#define EPS 1e-10
#define MAX_N 100100
#define MAX_M 100100

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;
typedef pair<P, char> PC;
typedef pair<ll, string> PLS;

int n;
string s;

int main(){
	int ans = 0;
	cin >> n >> s;
	REP(i, n){
		string t;
		cin >> t;
		REP(j, t.size()){
			bool f = 0;
			if (t[j] == s[0]){
				FOR(k, j + 1, t.size()){
					if (j + (k - j)*(s.size() - 1) >= t.size())break;
					if (t[k] == s[1]){
						int cnt = 2, wid = k - j;
						for (int l = k + wid; l < t.size(); l += wid){
							if (s[cnt] != t[l])break;
							if (cnt == s.size() - 1){
								f = 1;
								ans++;
								break;
							}
							cnt++;
						}
					}
					if (f)break;
				}
			}
			if (f)break;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 3156
n=int(input())
x=[-1]*(10**7+5)
x[0]=0
x[1]=1
i=2

x=[-1]*(10**7+5) #2以上の自然数に対して最小の素因数を表す
x[0]=0
x[1]=1
i=2
prime=[]
while i<=10**7+1:

    if x[i]==-1:
        x[i]=i
        prime.append(i)

    for j in prime:
        if i*j>10**7+1 or j>x[i]:break
        x[j*i]=j
    i+=1

def f(k):
    if k==1:
        return 1

    z=[]
    p=x[k]
    m=1
    ans=1
    while k>=2:
        k=k//p
        if p==x[k]:
            m+=1
        else:
            z.append(m)
            m=1
            p=x[k]

    for i in range(len(z)):
        ans*=z[i]+1
    return ans
s=0
for i in range(1,n+1):
    s+=i*f(i)
print(s)


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

int main() {
	char a, b, c, d;
	cin >> a >> b >> c >> d;

	for (int i = 0; i < 2; i++) {
		for (int j = 0; j < 2; j++) {
			for (int k = 0; k < 2; k++) {
				int x = a - '0';
				int y = b - '0';
				int z = c - '0';
				int w = d - '0';

				if (x + (i ? y : -y) + (j ? z : -z) + (k ? w : -w) == 7) {
					cout << x << (i ? "+" : "-") << y << (j ? "+" : "-") << z << (k ? "+" : "-") << w << "=7" << endl;
					return 0;
				}
			}
		}
	}

	return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<list>
#include<map>
#include<algorithm>

using namespace std;

void trace(vector<int> v)
{
    for (int i = 0; i < v.size(); i++) {
        if (i != 0) {
            cout << " ";
        }
        cout << v[i];
    }
    cout << endl;

}

void insertionSort(vector<int>& v)
{
    for (int i = 1; i < v.size(); i++) {
        int vi = v[i];
        int j = i - 1;
        while (j >= 0 && v[j] > vi) {
            v[j + 1] = v[j];
            j--;
        }
        v[j + 1] = vi;

        trace(v);
    }
}

int main()
{
    int n;
    cin >> n;
    
    vector<int> v;
    for (int i = 0; i < n; i++) {
        int vi;
        cin >> vi;
        v.push_back(vi);
    }

    trace(v);
    insertionSort(v);

    return 0;
}



Measured memory_bytes: 3164
#include<iostream>
#include<vector>
#include<string>
#include <algorithm>
#include <queue>
#include <climits>
#include<cmath>
#include <sstream>
#include <iomanip>

const int64_t cc = pow( 10, 9 ) + 7;

int main()
{
   int64_t a,b,c,d;
   std::cin>> a;
   std::cin>> b;

   std::string str;
   std::cin>> str;

   std::vector< int64_t > list;
   std::vector< int64_t > zero_list;

   char s = str[0];
   c = 0;

   for( int i = 0; i < str.size(); i++ )
   {
       if( s != str[i] )
       {
           if( s == '1' )
           {
               list.push_back( c );
           }
           else
           {
               list.push_back( c * -1 );
               zero_list.push_back( list.size() - 1 );
           }

           c = 0;
           s = str[i];
       }

       c += 1;
   }

   if( s == '1' )
   {
       list.push_back( c );
   }
   else
   {
       list.push_back( c * -1 );
       zero_list.push_back( list.size() - 1 );
   }

   int64_t start = 0;
   int64_t finish = 0;
   int64_t answer = 0;

   if( !zero_list.empty()
       && b < zero_list.size() )
   {
       for( int i = 0; i <= zero_list.size() - b; i++ )
       {
           int instance = 0;

           if( i + b >= zero_list.size() )
           {
               finish = list.size() - 1;
           }
           else
           {
               finish = zero_list[i+b] - 1;
           }
           //std::cout<< start << " " << finish <<"\n";

           for( int r = start; r <= finish; r++ )
           {               
               instance += abs( list[r] );
           }

           if( answer < instance )
           {
               answer = instance;
           }

           start = zero_list[i] + 1;
       }
   }
   else
   {
       answer = str.size();
   }

   std::cout<< answer;
}


Measured memory_bytes: 2036
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
#define fst first
#define snd second

/* clang-format off */
template <class T, size_t D> struct _vec { using type = vector<typename _vec<T, D - 1>::type>; };
template <class T> struct _vec<T, 0> { using type = T; };
template <class T, size_t D> using vec = typename _vec<T, D>::type;
template <class T> vector<T> make_v(size_t size, const T& init) { return vector<T>(size, init); }
template <class... Ts> auto make_v(size_t size, Ts... rest) { return vector<decltype(make_v(rest...))>(size, make_v(rest...)); }
/* clang-format on */

int main() {
  int N, K;
  while (cin >> N >> K) {
    vector<int> a(N);
    for (int i = 0; i < N; i++) cin >> a[i];
    vector<int> dp(K + 1, 0);
    dp[0] = 1;
    for (int i = 1; i <= K; i++) {
      dp[i] = 1;
      for (int j = 0; j < N; j++) {
        if (i - a[j] >= 0) {
          dp[i] &= 1 - dp[i - a[j]];
        }
      }
    }
    cout << (dp[K] == 0 ? "First" : "Second") << endl;
  }
  return 0;
}


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

// #define int long long
#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) int(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const ll INF = 1e15;
const int MOD = 1e9+7;
const ll LINF = 1e18;

ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

ll ngcd(vector<ll> a) {
  ll res = a[0];
  for(ll i=1; i<a.size() && res!=1; i++) res = gcd(a[i], res);
  return res;
}
ll nlcm(vector<ll> a){
  ll res = a[0];
  for(ll i=1; i<a.size(); i++) res = lcm(a[i], res);
  return res;
}
bool is_prime(ll n) {
  if(n < 2) return false;
  for (ll i = 2; i * i <= n; i++) if (n % i == 0) return false;
  return true;
}
ll digsum(ll n) {
  ll res=0;
  while(n) res += n%10, n /= 10;
  return res;
}
ll digcnt(ll n){
  ll res=0;
  while(n) res++, n /= 10;
  return res;
}
vector<ll> divisor(ll n) {
  vector<ll> res;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      res.push_back(i);
      if (i != n / i) res.push_back(n / i);
    }
  }
  return res;
}

signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  ll a,b,h; cin>>a>>b>>h;
  cout<<(a+b)*h/2<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>

#define SIZE_OF_STRING	1200	//??\?????????????????????

int main(void)
{
	int loop;
	char string_array[SIZE_OF_STRING];

	fgets(string_array, SIZE_OF_STRING, stdin);

	//?°?????????¨??§???????????\????????????
	for(loop = 0; string_array[loop] != '\0'; loop++){
		
		if( ('A' <= string_array[loop]) && (string_array[loop] <= 'Z')){

			//??§???????????´??????????°????????????????
			string_array[loop] = string_array[loop] + ( 'a' - 'A' );

		}else if(('a' <= string_array[loop]) && (string_array[loop] <= 'z')){

			//?°????????????´???????????§???????????????
			string_array[loop] = string_array[loop] - ( 'a' - 'A' );

		}else{
			//do nothing
		}

	}

	printf("%s", string_array);

	return 0;
}

Measured memory_bytes: 524
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    while(cin>>n,n){
        int num[n],ans;
        for(int i=0;i<n;i++)cin>>num[i];
        cin>>ans;
        int serch,kawa[2]={0,n-1};
        for(int i=1;kawa[1]>=kawa[0];i++){
            serch=(kawa[0]+kawa[1])/2;
            if(num[serch]>ans)kawa[1]=serch-1;
            else if(num[serch]<ans)kawa[0]=serch+1;
            if(num[serch]==ans||kawa[0]>kawa[1]){
                cout<<i<<endl;
                break;
            }
        }
    }
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
unsigned long long int func(unsigned long long int w[], unsigned long long int v[], unsigned long long int W, unsigned long long int n)
{
    unsigned long long int k[n+1][W+1];
    for(int i=0; i<=n; i++)
    {
        for(int j=0; j<=W; j++)
        {
            if(i==0  ||  j==0)
            {
                k[i][j]=0;
            }
            else if(w[i-1]<=j)
            {
                k[i][j] = max(k[i-1][j],  k[i-1][j-w[i-1]]+v[i-1]);
            }
            else
            {
                k[i][j] = k[i-1][j];
            }
        }
    }
    return k[n][W];
}

int main()
{
    unsigned long long int n, W;
    cin>>n>>W;
    unsigned long long int w[n];
    unsigned long long int v[n];
    for(int i=0; i<n; i++)
    {
        cin>>w[i];
        cin>>v[i];
    }
    cout<<func(w, v, W, n);
    return 0;
}



Measured memory_bytes: 79104
#include <iostream>
using namespace std;
int main(void){
   int n,i;
   cin>>n;
   int kazu[n];
   for(i=1;i<=n;i++){cin>>kazu[i];}
   for(i=n;i>=1;i--){if(i>=2){cout<<kazu[i]<<" ";}else if(i==1){cout<<kazu[i]<<endl;}
   }
    return 0;
}



Measured memory_bytes: 3104
import numpy as np

n = int(input())
lst = []
for _ in range(n):
  lst.append(int(input()))
max_idx = np.argmax(lst)
max_ = lst[max_idx]
lst[max_idx] = 0
next_max_ = max(lst)

for i in range(len(lst)):
  if i == max_idx:
    print(next_max_)
  else:
    print(max_)

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

int main(){
  string S;
  cin >> S;
  vector<int>Ans(S.size());
  for(int i=0;i<S.size();++i){
    if('A' ==S[i] || 'C'==S[i] || 'G'==S[i] || 'T'==S[i]){
      if(i==0){
        Ans[i]=1;
      }
      else{
        Ans[i]=Ans[i-1]+1;
      }
    }
    else{
      Ans[i]=0;
    }
  }
  int ans=0;
  for(int i=0;i<S.size();++i){
    ans = max(ans,Ans[i]);
  }
  cout << ans << endl;
}


Measured memory_bytes: 3632
#include <iostream>
#include <algorithm>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#include <vector>
#include <string>
#include <iomanip>
#define faster       ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define f(i,a,b) for(ll i=a;i<b;i++)
#define r(i,a,b) for(ll i=a;i>b;i--)
using namespace std;
typedef long long ll;
typedef long double ld;


int main() {

ll n; cin>>n;
vector<ll> v(n);

f(i,0,n){
  cin>>v[i];
}

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

if(v[0]==1){
  if(v[1]==1){
    cout << "0" << endl;
    return 0;
  }else{
    cout << "1" << endl;
    return 0;
  }
}

map<ll,ll> mp;

f(i,0,n){
  mp[v[i]]-=10000000;
}

f(i,0,n-1){
  ll a=v[i];
  for(ll j=2*a; j<=v[n-1]; j=j+a){
    mp[j]+=1;
  }
}

ll ans=0;

f(i,0,n){
  if(mp[v[i]]==-10000000){
    ans+=1;
  }
}

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


Measured memory_bytes: 65732
#include<iostream>
using namespace std;
int main(){
        int w,h,n;
        cin>>w>>h>>n;
        int Y[3][100];
        for(int i=0;i<n;i++){
                cin>>Y[0][i]>>Y[1][i]>>Y[2][i];
        }
        int num[2][101]={0};
        for(int i=0;i<n;i++){
                if(Y[2][i]==1){
                        for(int j=0;j<Y[0][i];j++){
                                num[0][j]++;
                        }
                }
                if(Y[2][i]==2){
                        for(int j=Y[0][i]+1;j<=w;j++){
                                num[0][j]++;
                        }
                }
                if(Y[2][i]==3){
                        for(int j=0;j<Y[1][i];j++){
                                num[1][j]++;
                        }
                }
                if(Y[2][i]==4){
                        for(int j=Y[1][i]+1;j<=h;j++){
                                num[1][j]++;
                        }
                }
        }
        int a=0,b=0;
        for(int i=0;i<=w;i++){
                if(num[0][i]==0){
                        a++;
                }
        }
        for(int i=0;i<=h;i++){
                if(num[1][i]==0){
                        b++;
                }
        }
        int x=a-1;
        int y=b-1;
        if(x<0){
                x=0;
        }
        if(y<0){
                y=0;
        }
        cout<<x*y;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long  ll ;
typedef double db;
const double pi = 3.141592654;
#define pb         push_back
#define forab(i,a,b)       for(int i=(a);i<=(b);i++)
#define CIN	ios_base::sync_with_stdio(0); cin.tie(0)
#define pcase(z,x)     printf("Case %ld: %lld\n",z,x)
#define nw	 "\n"
#define mod 1000000007

ll e[100000000];
int main(void)
{
	CIN;
	ll tc,l,k=0,sum=0,x=0,y,z=0,m=1,n=0,ans=0,cnt=0;
	map<ll,bool>mp;
	string s;
	cin>>n>>k;
	for(ll i=1;i<=k;i++){
		cin>>x>>s;
		if(s=="AC"){
			if(!mp[x])sum++,cnt+=e[x],mp[x]=1;
		}
		
		else e[x]++;

	}
	
	cout<<sum<<" "<<cnt;

}

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

int main(){
  long long n, a;
  cin >> n;
  long double s = sqrt(n);
  for(long long  i = floor(s); i > 0 ; i--){
    if(n % i == 0){
      a = n/i;
//      cout << a << endl;
      break;
    }
  }
  for(int i = 10; i >= 0; i--){
    if(a / pow(10, i) >= 1){
      cout << i+1 << endl;;
      break;
    }
  }
}


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

const int INF = 1 << 30;

int a[110];

int main(){
	int n;
	scanf("%d", &n);
	int sum = 0;
	for(int i = 0; i < n; i++) {
		scanf("%d", a + i);
		sum += a[i];
	}
	if(sum % 10 != 0) {
		printf("%d\n", sum);
	}else{
		int x = INF;
		for(int i = 0; i < n; i++)
			if(a[i] % 10 != 0) x = min(x, a[i]);
		if(x == INF) printf("0\n");
		else printf("%d\n", sum - x);
	}
}


Measured memory_bytes: 256
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
    int n,i,change=0,j;
    char s[110];
    cin>>n;
    cin>>s;
    if(n%2==1)
    {
        cout<<"No"<<endl;
    }
    else
    {
        for(i=0,j=n/2;i<n/2,j<n;i++,j++)
        {
            if(s[i]!=s[j])
            {
                change=1;
            }
        }
        if(change==1)
        {
            cout<<"No"<<endl;
        }
        else if(change==0)
        {
            cout<<"Yes"<<endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3636
#include <regex>
#include "bits/stdc++.h"
#define FOR(i, s, e) for (int i = int(s); i < int(e); ++i)
#define REP(i, e) FOR(i, 0, e)
#define INF (INT_MAX / 2)
#define LINF (LLONG_MAX / 2)
#define EPS (1.0e-8)
#define mkpr make_pair
const int MGN = 10;
const int ARY_SZ_MAX = (int)1e7;
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vvi = vector<vi>;
using vc = vector<char>; using vvc = vector<vc>;
using vb = vector<bool>; using vvb = vector<vb>;
using vl = vector<ll>; using vvl = vector<vl>;
using vd = vector<double>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>; using psl = pair<string, ll>;


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


    int N, K; cin >> N >> K;
    
    double ans = 0.0;
    int cnt = 0;
    FOR(i, 1, N+1) {  // サイコロの出た目
        int scr = i;  // 現在のスコア
        double p = 1.0;  // 現在のスコアとなる確率
        if (K <= scr) {  // 最初から勝っていたら
          ans += p / N;
          continue;
        }

        // n 回コインを投げて勝ち続けると得点は
        // scr * 2^n
        // 勝ちとなるのは 
        // scr * 2^n >= K
        int n = ceil(log2(((double)K) / scr));
        cerr << n << endl;
        ans += pow(0.5, n) / N;
    }    

    printf("%.12lf\n", ans);


  return 0;
}

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

int main(void){
  int n,x,ans;
  while(1){
    ans = 0;
    cin >> n >> x;
    if(n==0 && x==0) break;
    for(int i=1; i<=n-2; i++){
      if(i > x-2) break;
      for(int j=i+1; j<=n-1; j++){
        if( (i+j) > x-1) break;
        for(int k=j+1; k<=n; k++){
          if( (i+j+k) > x) break;
          int sum = 0;
          sum = i+j+k;
          if(sum==x){
            //printf("DBG : i=%d j=%d k=%d\n", i,j,k);
            ans++;
          }
        }
      }
    }
    printf("%d\n", ans);
  }
  return 0;
}



Measured memory_bytes: 3208
S = gets.chomp              # 文字列。chompを付けないと改行文字がついてくる
S.freeze
wk = S.split("")

if wk[2].gsub(" ", "") == wk[3].gsub(" ", "") && wk[4].gsub(" ", "") == wk[5].gsub(" ", "") then
  puts "Yes"
else
  puts "No"
end

Measured memory_bytes: 1788
// by adiforluls
#pragma GCC optimize ("-O2")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define FAST            ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define ll              long long
#define ld              long double
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define mii             map<int,int>
#define vi              vector<int>
#define vll             vector<long long>
#define all(a)          (a).begin(),(a).end()
#define clz(a)          __builtin_clz(a) // count leading zeroes
#define ctz(a)          __builtin_ctz(a) // count trailing zeroes
#define popc(a)         __builtin_popcount(a) // count set bits (for ints only diff for ll)
#define lul             1000000007
#define rep(i,a,b)      for(int i=a;i<b;i++)
#define rfor(i,a,b)     for(int i=a; i>=b; i--)
#define debug(x)        cerr << #x << " = " << x << endl;
#define F               first
#define S               second
#define mod             998244353 
#define pll             pair<ll,ll>
#define endl            '\n'
#define deci(n)         cout<<fixed<<setprecision(n)
#define ordered_set     tree<pll, null_type,less<pll>, rb_tree_tag,tree_order_statistics_node_update>
// order_of_key(k)
// find_by_order(k)
const ld PI = acos(-1.0);
const int INF = 0x3f3f3f3f;

ll n,k;
void solve()
{
    cin>>n>>k;
    vll a(n),f(n);
    rep(i,0,n) cin>>a[i];
    rep(i,0,n) cin>>f[i];
    sort(all(a));
    sort(f.rbegin(), f.rend());
    ll ans = 0;
    ll l = 0, r = 1e18;
    while(l<=r)
    {
        ll t = l + (r-l)/2;
        ll cnt = k;
        rep(i,0,n)
        {
            if(t>=a[i]*f[i]) continue;
            cnt-=(a[i]-t/f[i]);
            if(cnt<0) break;
        }
        if(cnt<0) l = t+1;
        else{
            ans = t;
            r = t-1;
        } 
    }
    cout<<ans;
}
int main()
{   
    FAST;
   //  #ifndef ONLINE_JUDGE
     // freopen("input.txt", "r", stdin);
     // freopen("output.txt", "w", stdout);
   //  #endif
    int t; t=1;  //cin>>t;
    while(t--){
       solve();
    }
    return 0;
}

Measured memory_bytes: 3328
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <stdio.h>
#include <cmath>
#include <cctype>

using namespace std;

int main()
{
    string s, p;
    bool f = false;
    int index;
    cin >> s >> p;

    for (int i = 0; i < s.size(); i++)
    {
        for (int j = 0; j < p.size(); j++)
        {
            int n = i + j;
            if (n >= s.size())
            {
                n -= s.size();
            }
            if (s[n] != p[j])
            {
                f = false;
                break;
            }
            f = true;
        }
        if (f)
        {
            cout << "Yes" << endl;
            return 0;
        }
    }

    cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 3212
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        char[] s = sc.next().toCharArray();
        int min = Integer.MAX_VALUE;
        int x;
        for(int i=0;i+2<s.length;i++){
            x = 100*(s[i]-'0')+10*(s[i+1]-'0')+s[i+2]-'0';
            min = Math.min(Math.abs(x-753),min);
        }
        System.out.println(min);
    }
}

Measured memory_bytes: 21844
//おまじない
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#define INF 1e9+7
#define roop(i,m,n) for(int i=m;i<n;i++)
#define mroop(i,m,n) for(int i=m;i<n;i--)
#define NO cout<<"NO"<<endl;
#define YES cout << "YES"<<endl;
#define No cout << "No"<<endl;
#define Yes cout << "Yes"<<endl;
using namespace std;
typedef long long int ll;


//(int)'a'は97 (int)'A'は65
//おまじない



int main() {

	char a[51][51], b[51][51];
	char st;
	int n, m;
	cin >> n >> m;

	roop(i, 0, n) {
		roop(j, 0, n) {
			cin >> a[i][j];
		}
	}

	roop(i, 0, m) {
		roop(j, 0, m) {
			cin >> b[i][j];
		}
	}
	st = b[0][0];

	roop(i, 0, n - m + 1) {
		roop(j, 0, n - m + 1) {
			if (a[i][j] == st) {
				roop(k, 0, m) {
					roop(l, 0, m) {
						if (b[k][l] != a[i + k][j + l]) {
							goto A;
						}
						if (k == m - 1 && l == m - 1 && b[k][l] == a[i + k][j + i]) {
							Yes;
							return 0;
						}
					}
				} A: continue;
			}
		}
	}

	No;


	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#define LL long long
using namespace std;
const LL Maxn = 300010;
const LL Mod = 998244353;
LL a[Maxn], n, K;
LL b[Maxn], c[Maxn], cl, pos[Maxn], pi[Maxn], len[Maxn];
bool v[Maxn];
LL jc[Maxn], inv[Maxn];
LL t[Maxn];
LL _max(LL x, LL y) { return x > y ? x : y; }
int main() {
	LL i, j, k;
	scanf("%lld", &n);
	jc[0] = 1;
	for(i = 1; i <= n; i++) jc[i] = jc[i-1]*i%Mod;
	inv[0] = inv[1] = 1;
	for(i = 2; i <= n; i++) inv[i] = inv[Mod%i]*(Mod-Mod/i)%Mod;
	for(i = 2; i <= n; i++) inv[i] = inv[i-1]*inv[i]%Mod;
	for(i = 0; i < n; i++) scanf("%lld", &a[i]);
	for(i = 0; i < n; i++){
		if(a[i] != a[(i+n-1)%n]){
			if(v[a[i]] == true){ printf("0\n"); return 0; }
			v[a[i]] = true;
		}
	}
	for(i = 0; i < n; i++){
		if(a[i] != a[(i+n-1)%n]){
			if(a[i] == 1) break;
		}
	}
	for(j = 0; j < n; j++) b[j] = a[(i+j)%n];
	K = 0;
	while(b[K] == 1) K++;
	if(K == n){ printf("%lld\n", jc[n]); return 0; }
	c[++cl] = 1; pi[cl] = 0;
	t[1] = 1;
	for(i = K; i < n; i++){
		c[++cl] = b[i]; pi[cl] = i;
		t[b[i]] = cl;
		j = i;
		while(b[i] == b[j]) j++;
		if(j-i > K){ printf("0\n"); return 0; }
		i = j-1;
	}
	LL ans = 1;
	pos[1] = 0;
	for(i = 2; i <= cl; i++){
		if(c[i-1] > c[i]){
			if(c[i%cl+1] > c[i]){
				if(pi[i] != (pi[i%cl+1]+n-K)%n){ printf("0\n"); return 0; }
			}
			pos[i] = pi[i];
		} else {
			if(c[i%cl+1] > c[i]){
				pos[i] = (pi[i%cl+1]+n-K)%n;
				if(pos[i] <= pos[i-1]){ printf("0\n"); return 0; }
			} else {
				pos[i] = -1;
				LL l = _max(pos[i-1]+1, (pi[i%cl+1]+n-K)%n), r = pi[i];
				ans = ans*(r-l+1)%Mod;
			}
		}
	}
	LL sy = 0;
	for(i = n; i >= 1; i--){
		if(t[i] == 0){ sy++; continue; }
		LL x = t[i];
		LL frt = x-1 <= 0 ? x+cl-1 : x-1;
		LL p = 0;
		if(pos[x] == -1) p = (pos[x%cl+1]+n-pos[frt]-2)%n;
		else if(c[frt] < c[x]) p = (pos[x]+n-pos[frt]-1)%n;
		else if(c[x%cl+1] < c[x]) p = (pos[x%cl+1]+n-pos[x]-1)%n;
		if(p > sy){ printf("0\n"); return 0; }
		ans = ans*jc[sy]%Mod*inv[sy-p]%Mod;
		sy -= p;
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 21504
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define irep(i, n) for (int i = n; i >= 0; i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1 << 30;
 
int main() {
	int n;
	string s;
	cin >> n >> s;
	int cnt = 0;
	rep(i, 1000) {
		int c[3] = {i/100, (i%100)/10, i%10};
		int f = 0;
		rep(i, n) {
			if (s[i] == '0'+c[f]) f++;
			if (f == 3) {cnt++; break;}
		}
	}

	cout << cnt << endl;
	return 0;
}

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

using namespace std;

#define MAXN 112345
#define ll long long
#define db(x) cerr << #x << " = " << x << endl;
#define B 1
#define W 0

set<int> G[MAXN];
int N;
int vis[MAXN][2];
ll dp[MAXN][2];
const int MOD = 1e9 + 7;

void dfs(int u, int p)
{
	G[u].erase(p);
	for (auto v : G[u])
		dfs(v, u);
}

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

void add(ll &a, ll b)
{
	a = (a + b) % MOD;
}

ll solve(int node, int last_color)
{
	
	if (G[node].empty())
	{
		return last_color == W ? 2:1;
	}

	ll res = 0;
	
	if (vis[node][last_color])
	{
		return dp[node][last_color];
	}
	vis[node][last_color] = 1;
	
	// PAINT BLACK	
	ll pos = 1;
	if (last_color == W)
	{
		for (auto v : G[node])
		{
			ll sub = solve(v, B);
			mul(pos, sub);
		}
		add(res, pos);
	}
	
	// PAINT WHITE
	pos = 1;
	for (auto v : G[node])
	{
		ll sub = solve(v, W);
		mul(pos, sub);
	}
	add(res, pos);
	
	dp[node][last_color] = res;
	return res;
}

int main()
{
	scanf("%d", &N);
	int u, v;
	for (int i = 0; i < N - 1; i++)
	{
		scanf("%d%d", &u, &v);
		G[u].insert(v);
		G[v].insert(u);
	}
	
	dfs(1, 1);
	
	printf("%lld\n", solve(1, W));
}


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

using namespace std;

//State
//dp[i][k]: The number of ways of coloring the subtree rooted
// at i can be colored with i being colored white(k=0) or i being colored black(k=1)

//Initialization
//For all nodes i with no children(leaf nodes) dp[i][0] = 1 and dp[i][1]=1

//Transitions: If root is white the children can be ehite or black but if root is black children must be white
//dp[parent][0] = max(dp[child1][0],dp[child1][1]) + max(dp[child2][0],dp[child2][1]) + max(dp[child3][0],dp[child3][1])
//dp[parent][1] = dp[child1][0] + dp[child2][0] +dp[child3][0]

//Order of Evaluation
//DFS

//Answer
//dp[root][0]+dp[root][1] Sum this over all connected components

//Time Complexity: O(N)

const long long mod = 1e9+7;
long long dp[100005][2] = {0};
long long visited[100005] = {false};
vector<vector<long long>> adjList(100005, vector<long long>(0));
long long N;

void dfs(long long node, long long parent){
	vector<long long> children = adjList[node];
	long long numChild = children.size();
	if(numChild==0 || (numChild==1 && children[0]==parent)){
		dp[node][0] = 1;
		dp[node][1] = 1;
		return;
	}
	long long temp1 = 1;
	long long temp2 = 1;
	for(long long child: children){
		if(child != parent){
			dfs(child, node);
			temp1 = ((temp1 % mod)*((dp[child][0] + dp[child][1]) % mod)) % mod;
			temp2 = (temp2*dp[child][0]) % mod;
		}
	}
	dp[node][0] = temp1;
	dp[node][1] = temp2;
}

int main(){
	cin >> N;
	long long x, y;
	for(long long i=1; i<N; i++){
		cin >> x >> y;
		x = x-1;
		y = y-1;
		adjList[x].push_back(y);
		adjList[y].push_back(x);
	}

	long long root = 0;
	dfs(root, -1);
	cout << (dp[root][0]+dp[root][1]) % mod << endl;
}












Measured memory_bytes: 19904
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        D solver = new D();
        solver.solve(1, in, out);
        out.close();
    }

    static class D {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int N = in.nextInt();
            long sum = 0;
            for (int i = 1; i < N; i++) {
                sum += i;
            }
            out.println(sum);
        }

    }
}



Measured memory_bytes: 21332
//23/12/2019
#include<bits/stdc++.h>

using namespace std;

#define debug printf("Debug\n");
#define ll long long
#define ull unsigned long long

#define pi acos(-1.0)
#define mod 1000000007

#define p_b(x) push_back(x)
#define m_p(x) make_pair(x,y)

#define _fastio  ios_base:: sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define in_fre  freopen("in.txt", "r", stdin);
#define out_fre freopen("out.txt", "w", stdout);

struct Node{
    ll val,pos;
};
vector<ll>v;

ll a[200005];

int main(){
    _fastio
    ll n;
    cin>>n;
    for(ll i=1;i<=n;i++){
        cin>>a[i];
    }

    ll ans=0;
    ll last=0;
    ll found=0;

    for(ll i=1;i<=n;i++){
        if(a[i]==found+1){
            ans+=(i-last-1);
            last=i;
            found++;
        }
    }
    if(found==0) cout<<-1<<endl;
    else {
        if(last!=n) ans+=(n-last);
        cout<<ans<<endl;
    }

    return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main(){
long long int n;
cin >> n;
long long int a,ans=0;
vector <long long int> v;
for(int i=0;i<n;i++) {
  cin >> a;
  if(a%2==0) v.push_back(a);
}
if(v.size()==0) cout << 0<<endl;
else{
for(int i=0;i<v.size();i++){
  while(1){
    if(v[i]%2!=0) break;
    v[i]/=2;
    ans++;
  }
}
cout <<ans <<endl;
}
}


Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <queue>
#include <sstream>
#include <algorithm>
#include <bitset>
#include <limits>
#include <map>
#include <set>
#include <iomanip>
#include <cmath>

using namespace std;

typedef long long int ll;
typedef std::numeric_limits<double> dbl;
const long long int LL_INF=1LL<<60;

vector<string> split(const string& input, char delimiter)
{
    stringstream stream(input);
    
    string field;
    vector<string> result;
    while (getline(stream, field, delimiter)) {
        result.push_back(field);
    }
    return result;
}

//#define DEBUG

ll A, B, M, N, D, K, L, Q, W, H, T, X, Y, S;

int main()
{
    N = 1;
    while (true) {
        cin >> N >> M;
        if (N == 0 && M == 0) break;
    vector<ll> hs(N+1), ws(M+1);
    for (int i = 1; i <= N; ++i) cin >> hs[i];
    for (int i = 1; i <= M; ++i) cin >> ws[i];
    
    for (int i = 1; i < N+1; ++i)
        hs[i] += hs[i-1];
    for (int j = 1; j < M+1; ++j)
        ws[j] += ws[j-1];
    
    vector<ll> hExist(1500*1000+1);
    vector<ll> wExist(1500*1000+1);
    for (int i = 0; i <= N; ++i) {
        for (int j = 0; j <= N; ++j) {
            //cout << hs[j] - hs[i] << endl;
            hExist[abs(hs[j] - hs[i])]++;
        }
    }
    for (int i = 0; i <= M; ++i) {
        for (int j = 0; j <= M; ++j) {
            //cout << abs(ws[j] - ws[i]) << endl;
            wExist[abs(ws[j] - ws[i])]++;
        }
    }

    ll cnt = 0;
    for (int i = 1; i < hExist.size(); ++i) {
        //cerr << i << " " << hExist[i] << " " << wExist[i] << endl;
        if (hExist[i] && wExist[i])
            cnt += hExist[i] * wExist[i];
    }

        cout << cnt/4 << endl;
}

    return 0;
}


Measured memory_bytes: 26256
#include<bits/stdc++.h>
using namespace std;
long long a,b,c,d,i,e,f,g,n,m,k,l,A[200005],dp[200005][22],maxx;
int main() {
           cin>>a>>b;
           if(a>b) cout<<"safe";
           else cout<<"unsafe";
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define mp make_pair
#define eb emplace_back
#define pb push_back
#define fi first
#define se second
#define bit(n) (1 << n)
using namespace std;
using cd = complex <double>;
 
typedef pair <int, int> pii;
typedef vector <int> vi;
typedef vector <pair <int, int> > vii;
typedef map <int, int> mii;
 
const int Inf = 1000000000;
const int mod = 1000000007;//998244353;
const double Pi = acos(-1);

void Fastio()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
}	

int n, k, s;

void Solve()
{
	cin >> n >> k >> s;
	if(s == 1000000000)
	{
		for(int i = 1; i <= k; i++)
		{
			cout << s << " ";
		}
		for(int i = k + 1; i <= n; i++)
		{
			cout << 1 << " ";
		}
		return;
	}
	for(int i = 1; i <= k; i++)
	{
		cout << s << " ";
	}
	for(int i = k + 1; i <= n; i++)
	{
		cout << s + 1 << " ";
	}
}
 
int main()
{
	Fastio();
	Solve();
}

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

int main(int argc, char const *argv[])
{
    ios_base::sync_with_stdio(false);
    
    int n, w;
    cin >> n >> w;
    vector<pair<int, int> > value_weights (n, pair<int, int> (0, 0));
    for (int i = 0; i < n; i++)
        cin >> value_weights[i].first >> value_weights[i].second;
    vector<int> memoization (w+1, -1);
    memoization[0] = 0;
    for (int i = 0; i <= w; i++)
    {
        for (int j = 0; j < n; j++)
        {
            if (i - value_weights[j].second >= 0)
                memoization[i] = max(memoization[i], memoization[i-value_weights[j].second] + value_weights[j].first);
        }
    }
    cout << *max_element(memoization.begin(), memoization.end()) << endl;
    return 0;
}



Measured memory_bytes: 3204
#ifdef _DEBUG
#include "../../library/library/debug_template.cpp"
#define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__)
#else
#define DMP(...) ((void)0)
#endif

#include <cassert>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <numeric>
#include <algorithm>

using namespace std;
using lint = long long;
constexpr int MOD = 1000000007, INF = 1010101010;
constexpr lint LINF = 1LL << 60;

struct init {
	init() {
		cin.tie(nullptr); ios::sync_with_stdio(false);
		cout << fixed << setprecision(10);
	}
} init_;

class UnionFind {
private:
	vector<int> data;
public:
	UnionFind(int size) : data(size, -1) { }
	int root(int x) { return data[x] < 0 ? x : data[x] = root(data[x]); }
	bool is_same(int x, int y) { return root(x) == root(y); }
	int size(int x) { return -data[root(x)]; }

	bool unify(int x, int y) {
		x = root(x); y = root(y);
		if (x != y) {
			if (data[y] < data[x]) swap(x, y);
			data[x] += data[y]; data[y] = x;
			return true;
		}
		return false;
	}
};

template<class T>
inline bool chmax(T& a, const T b) { return a < b && (a = b, true); }

int main() {

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

	UnionFind uf(N);
	for (int i = 0; i < M; i++) {
		int a, b;
		cin >> a >> b;
		a--, b--;
		uf.unify(a, b);
	}

	int ans = 0;
	for (int i = 0; i < N; i++) {
		chmax(ans, uf.size(i));
	}

	cout << ans << "\n";

	return 0;
}


Measured memory_bytes: 3984
#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int H,W;
ll K;
string S[1010];
ll mo=1000000007;

void rot() {
	int y,x;
	string T[1010];
	FOR(y,H) FOR(x,W) T[x] += S[y][x];
	FOR(x,1000) S[x]=T[x];
	swap(H,W);
}

const int MAT=2;
ll G[MAT][MAT],G2[MAT][MAT];
void powmat(ll p,int n,ll a[MAT][MAT],ll r[MAT][MAT]) {
	int i,x,y,z;
	ll a2[MAT][MAT];
	FOR(x,n) FOR(y,n) a2[x][y]=a[x][y];
	FOR(x,n) FOR(y,n) r[x][y]=0;
	FOR(i,n) r[i][i]=1;
	while(p) {
		ll h[MAT][MAT];
		if(p%2) {
			FOR(x,n) FOR(y,n) h[x][y]=0;
			FOR(x,n) FOR(z,n) FOR(y,n) h[x][y] += (r[x][z]*a2[z][y]) % mo;
			FOR(x,n) FOR(y,n) r[x][y]=h[x][y]%mo;
		}
		FOR(x,n) FOR(y,n) h[x][y]=0;
		FOR(x,n) FOR(z,n) FOR(y,n) h[x][y] += (a2[x][z]*a2[z][y]) % mo;
		FOR(x,n) FOR(y,n) a2[x][y]=h[x][y]%mo;
		p>>=1;
	}
}

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>H>>W>>K;
	
	FOR(y,H) cin>>S[y];
	int a=0,b=0;
	FOR(y,H) if(S[y][0]=='#' && S[y][W-1]=='#') a++;
	FOR(x,W) if(S[0][x]=='#' && S[H-1][x]=='#') b++;
	if(a&&b) return _P("1\n");
	if(b) rot(), a=b;
	
	FOR(y,H) {
		FOR(x,W) {
			if(S[y][x]=='#') G[0][0]++;
			if(x>0 && a && S[y][x]=='#' && S[y][x-1]=='#') G[0][1]--;
		}
		if(S[y][0]=='#' && S[y][W-1]=='#') G[1][1]++;
	}
	
	G[0][1] += mo;
	
	powmat(K-1,2,G,G2);
	cout<<(G2[0][0] + G2[0][1])%mo<<endl;
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n';
	FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	solve(); return 0;
}


Measured memory_bytes: 2432
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import math
a, b, h, m = map(int, input().split())
x = abs(30 * h + m / 2 - 6 * m)
if x <= 180:
    d = math.sqrt(a**2 + b**2 - 2 * a * b * math.cos(math.radians(x)))
else:
    x = 360 - x
    d = math.sqrt(a**2 + b**2 - 2 * a * b * math.cos(math.radians(x)))
print(d)

Measured memory_bytes: 9500
#include<bits/stdc++.h>
using namespace std;
typedef double db;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pw(x) (1ll << (x))
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define rep(i,l,r) for(int i=(l);i<(r);++i)
#define per(i,l,r) for(int i=(r)-1;i>=(l);--i)
#define dd(x) cout << #x << " = " << x << ", "
#define de(x) cout << #x << " = " << x << endl

//-----
const int N = 2e3 + 7;
int n, pos[2][N], c[2][N][N], dp[N][N];
int main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
  cin >> n;
  rep(i, 1, n << 1 | 1) {
		char op; int id; cin >> op >> id;
		pos[op == 'B'][id] = i;
	}
	rep(_, 0, 2) {
		rep(i, 1, n + 1) rep(j, 1, i) c[_][i][0] += pos[_][i] < pos[_][j];
		rep(i, 1, n + 1) rep(j, 1, n + 1) c[_][i][j] = c[_][i][j - 1] + (pos[_][i] < pos[_ ^ 1][j]);
	}
	rep(i, 1, n + 1) {
		dp[i][0] = dp[i - 1][0] + c[0][i][0];
		dp[0][i] = dp[0][i - 1] + c[1][i][0];
	}
	rep(i, 1, n + 1) rep(j, 1, n + 1) dp[i][j] = min(dp[i - 1][j] + c[0][i][j], dp[i][j - 1] + c[1][j][i]);
	cout << dp[n][n];
	return 0;
}

Measured memory_bytes: 47488
#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define rep(i,n) for (int i=0;i<(int)(n);i++)
#define codefor int test;scanf("%d",&test);while(test--)
#define yn(ans) if(ans)printf("Yes\n");else printf("No\n")
#define YN(ans) if(ans)printf("YES\n");else printf("NO\n")
#define umap unordered_map
#define uset unordered_set
using namespace std;
using ll = long long;
const int MOD=1000000007;
//入力系
void scan(int& a){scanf("%d",&a);}
void scan(long long& a){scanf("%lld",&a);}
template<class T> void scan(T& a){cin>>a;}
template<class T> void scan(vector<T>& vec){for(auto&& it:vec)scan(it);}
void in(){}
template <class Head, class... Tail> void in(Head& head, Tail&... tail){scan(head);in(tail...);}
//出力系
void print(const int& a){printf("%d",a);}
void print(const long long& a){printf("%lld",a);}
void print(const double& a){printf("%.15lf",a);}
template<class T> void print(const T& a){cout<<a;}
template<class T> void print(const vector<T>& vec){if(vec.empty())return;print(vec[0]);for(auto it=vec.begin();++it!= vec.end();){putchar(' ');print(*it);}}
void out(){putchar('\n');}
template<class T> void out(const T& t){print(t);putchar('\n');}
template <class Head, class... Tail> void out(const Head& head,const Tail&... tail){print(head);putchar(' ');out(tail...);}
//デバッグ系
template<class T> void dprint(const T& a){cerr<<a;}
template<class T> void dprint(const vector<T>& vec){if(vec.empty())return;cerr<<vec[0];for(auto it=vec.begin();++it!= vec.end();){cerr<<" "<<*it;}}
void debug(){cerr<<endl;}
template<class T> void debug(const T& t){dprint(t);cerr<<endl;}
template <class Head, class... Tail> void debug(const Head& head, const Tail&... tail){dprint(head);cerr<<" ";debug(tail...);}

int main(){
    long long int n,k;
    in(n,k);
    vector<ll> a(n);
    in(a);
    ll ans=0;
    for(int i=0;i<n-1;i++){
        for(int j=i+1;j<n;j++){
            if(a[i]>a[j])ans++;
        }
    }
    ll ans2=ans*k;
    ans=0;
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            if(a[i]>a[j])ans++;
        }
    }
    ans2+=(ll)ans*((k*(k-1)/2)%MOD);
    ans2%=MOD;
    out(ans2);
}


Measured memory_bytes: 3804
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i = (a); i <= (b); i++)
#define rng(a) a.begin(), a.end()
#define ina(n,a) cin >> n; for(int i = 1; i <= n; i++) cin >> a[i]
#define sz(x) (int)(x).size()
#define se second
#define fi first
#define prev            coyhhhhhhyoc    
#define next          sdNNNmNNNNNNNmds  
#define y0           hNNNNy_yNNNNNN_sNh
#define y1          mNNNNNdtdNNNNNNtsNNm
#define yn          mNNNNNNNNy___smNNNms
#define tm            oooooosyysooooot 
#define read               tyhyt        
#define rank              ytmNmo         
#define index              yyy
#define pb push_back
#define pcnt __builtin_popcountll
#define rrep(i,a,b) for(int i = (b); i >= (a); i--)
#define rall(x,a) for(auto x : a)
#define MOD 1000000007
#define endl "\n"
typedef long long ll;
using namespace std;

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    int ans = n + 1 >> 1;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;
class P
{
    static void Main()
    {
        Console.ReadLine();
        Dictionary<int, int> dict = new Dictionary<int, int>();
        int[] d = Console.ReadLine().Split().Select(int.Parse).ToArray();
        for (int i = 0; i < d.Length; i++)
        {
            if (dict.ContainsKey(d[i])) dict[d[i]]++;
            else dict.Add(d[i],1);
        }
        Console.ReadLine();
        int[] t = Console.ReadLine().Split().Select(int.Parse).ToArray();
        for (int i = 0; i < t.Length; i++)
        {
            if(!dict.ContainsKey(t[i]) || --dict[t[i]] < 0)
            {
                Console.WriteLine("NO");
                return;
            }
        }
        Console.WriteLine("YES");
    }
}

Measured memory_bytes: 50256
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S; cin >> S;
    rep(i, 4) cout << S[i];
    cout << " ";
    rep(i, 8) cout << S[i + 4];
    cout << endl;

    return 0;
}


Measured memory_bytes: 256