akhauriyash/Code-Regression huggingface dataset:
// execute g++ main.cpp -std=c++14 -I C:\Users\naoya\Desktop\code\Atcoder
#include<bits/stdc++.h>
//#include<atcoder/all>
typedef long long ll;
typedef long double ld;
using namespace std;
//using namespace atcoder;

using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

#define REP(i, l, n) for(int i=(l), i##_len=(n); i<i##_len; ++i)
#define ALL(x) (x).begin(),(x).end()
#define pb push_back

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;}

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;}


char alpha[26] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};

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

int main(){
    int h, w; cin >> h >> w;
    vector<string> lis(h);
    vector<vector<vector<int> > > dp(h, vector<vector<int> >(w, vector<int>(4, 0)));
    REP(i, 0, h){cin >> lis[i];}
    REP(i, 0, h){
        int count = 0;
        REP(l, 0, w){
            if(lis[i][l] == '.'){
                count++;
                dp[i][l][0] = count;
            }else{
                count = 0;
            }
        }
    }
    REP(i, 0, h){
        int count = 0;
        for(int l = w-1; l >= 0; l--){
            if(lis[i][l] == '.'){
                count++;
                dp[i][l][1] = count;
            }else{
                count = 0;
            }
        }
    }
    REP(i, 0, w){
        int count = 0;
        REP(l, 0, h){
            if(lis[l][i] == '.'){
                count++;
                dp[l][i][2] = count;
            }else{
                count = 0;
            }
        }
    }
    REP(i, 0, w){
        int count = 0;
        for(int l = h-1; l >= 0; l--){
            if(lis[l][i] == '.'){
                count++;
                dp[l][i][3] = count;
            }else{
                count = 0;
            }
        }
    }
    int ans = 0;
    REP(i, 0, h){
        REP(l, 0, w){
            int mid = 0;
            REP(j, 0, 4){
                mid += dp[i][l][j];
            }
            chmax(ans, mid - 3);
        }
    }
    cout << ans << endl;
}

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

int cal(int x,int y,int op){
	if(op==0)return x+y;
	else if(op==1)return x-y;
	else return x*y;
	}

int main(){
	int a,b,c,d;
	while(cin>>a>>b>>c>>d){
		if(a==0&&b==0&&c==0&&d==0)break;
		
		vector<int>k;
		
		k.push_back(a);
		k.push_back(b);
		k.push_back(c);
		k.push_back(d);
		sort(k.begin(),k.end());
		
		string o[3]={" + "," - "," * "};
		int flg=1;
		
		do{
			for(int i=0;i<3;i++){//op1
				for(int j=0;j<3;j++){//op2
					for(int l=0;l<3;l++){//op3
						int e=cal(cal(cal(k[0],k[1],i),k[2],j),k[3],l);
						int f=cal(cal(k[0],k[1],i),cal(k[2],k[3],l),j);
						int g=cal(cal(k[0],cal(k[1],k[2],j),i),k[3],l);
						int h=cal(k[0],cal(cal(k[1],k[2],j),k[3],l),i);
						int m=cal(k[0],cal(k[1],cal(k[2],k[3],l),j),i);
						
						if(e==10){
							cout<<"((("<<k[0]<<o[i]<<k[1]<<")"<<o[j]<<k[2]<<')'<<o[l]<<k[3]<<')'<<endl;
							flg=0;
							goto FINLOOP;
							}
						else if(f==10){
							cout<<"(("<<k[0]<<o[i]<<k[1]<<')'<<o[j]<<'('<<k[2]<<o[l]<<k[3]<<"))"<<endl;
							flg=0;
							goto FINLOOP;
							}
						else if(g==10){
							cout<<"(("<<k[0]<<o[i]<<'('<<k[1]<<o[j]<<k[2]<<"))"<<o[l]<<k[3]<<')'<<endl;
							flg=0;
							goto FINLOOP;
							}
						else if(h==10){
							cout<<"("<<k[0]<<o[i]<<"(("<<k[1]<<o[j]<<k[2]<<")"<<o[l]<<k[3]<<"))"<<endl;
							flg=0;
							goto FINLOOP;
							}
						else if(m==10){
							cout<<"("<<k[0]<<o[i]<<"("<<k[1]<<o[j]<<"("<<k[2]<<o[l]<<k[3]<<")))"<<endl;
							flg=0;
							goto FINLOOP;
							}				
						}
					}
				}
			}while(next_permutation(k.begin(),k.end()));
			
			FINLOOP:;
			if(flg==1)cout<<"0"<<endl;
		}
		return 0;
	}

Measured memory_bytes: 3148
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
#include<bitset>
#include<stack>
#include<memory>
using namespace std;
using namespace std::chrono;
typedef long long int llint;
typedef double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
/*cout<<fixed<<setprecision(20);cin.tie(0);ios::sync_with_stdio(false);*/
const llint mod=998244353;
const llint big=2.19e15+1;
const long double pai=3.141592653589793238462643383279502884197;
const long double eps=1e-15;
template <class T,class U>bool mineq(T& a,U b){if(a>b){a=b;return true;}return false;}
template <class T,class U>bool maxeq(T& a,U b){if(a<b){a=b;return true;}return false;}
llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);}
llint lcm(llint a,llint b){if(a==0){return b;}return a/gcd(a,b)*b;}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());}
template<class T>llint LBI(vector<T>&ar,T in){return lower_bound(ar.begin(),ar.end(),in)-ar.begin();}
template<class T>llint UBI(vector<T>&ar,T in){return upper_bound(ar.begin(),ar.end(),in)-ar.begin();}
int main(void){
	llint A;cin>>A;
	int i,n=1;
	while(n*(n+1)/2<A){n++;}
	//n個の ( と )
	for(i=0;i<2*n;i++){
		if(i<=n&&i!=A-n*(n-1)/2){cout<<')';}
		else{cout<<'(';}
	}
	cout<<endl;
	return 0;
}


Measured memory_bytes: 3088
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <sstream>
#include <string>
#define _repargs(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _repargs(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define inf 2000000007
#define mp make_pair
#define pb push_back
typedef long long ll;
using namespace std;
template <typename T>
inline void output(T a, int p = 0) {
    if(p) cout << fixed << setprecision(p)  << a << "\n";
    else cout << a << "\n";
}
// end of template

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    // source code
    
    ll N;
    cin >> N;
    vector<ll> A(N);
    ll one = N * (N + 1) / 2;
    ll sum = 0;
    rep(i, N) cin >> A[i], sum += A[i];
    
    if(sum % one > 0) {
        output("NO");
        return 0;
    }
    
    
    ll cnt = sum / one;
//    output(cnt);
    A.pb(A[0]);
    
    ll ok = 0;
    rep(i, N){
        ll sub = A[i + 1] - A[i];
//        output(cnt - sub);
        if(sub > cnt || (cnt - sub) % N != 0) {
            output("NO");
            return 0;
        }
        
        ok += (cnt - sub) / N;
    }
    
//    cout <<  "ok " <<  ok << endl;
    if(ok == cnt) {
        output("YES");
    }
    else{
        output("NO");
    }
    
    
    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
typedef long long int ll;
using namespace std;
int main(){
	ios_base::sync_with_stdio(false);  
	cin.tie(NULL);
	string s1 = "CODEFESTIVAL2016";
	string s; cin>>s;
	int count=0;
	int n = s.length();
	for(int i=0;i<n;i++){
		if(s[i]!=s1[i]){
			count++;
		}
	}
	cout<<count<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;

const int inf = 99999999;
const ll linf = 999999999999999999;
const double pi = acos(-1);
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};

#define p_queue(i) priority_queue<i> 
#define rp_queue(i) priority_queue<i, vector<i>, greater<i>> 
#define P(p) cout<<(p)<<endl
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define mod(i) ((i)%(ll)(1e9 + 7))
#define divm(a,b) (mod(a * modpow((ll)b,(ll)(1e9+5))))
#define rsort(a,b,c) sort(a, b, greater<c>())
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v) sort(v.end(), v.begin());
#define ft first
#define sd second
#define pb push_back
#define it insert
#define sz(x) ((int)(x).size())
#define lb(a,n,k) (lower_bound(a,a+n,k) - a) 
#define vlb(a,k)  (lower_bound(a.begin(),a.end(),k) - a.begin())
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return

ll modpow(ll i,ll j){ ll tmp=1; while(j){ if(j%2)tmp=mod(tmp*i);i=mod(i*i);j/=2;}return tmp;}
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; }

///////////////////////////////////////////////////////////////////////////

int main(){
	int n;
	map<int,int> m;
	cin >> n;
	int a[1005] = {};

	rep(i,0,n){
	    cin >> a[i];
        
        if(a[i] >= 3200)m[0]++;
        else if(a[i] >= 2800)m[1]++;
        else if(a[i] >= 2400)m[2]++;
        else if(a[i] >= 2000)m[3]++;
        else if(a[i] >= 1600)m[4]++;
        else if(a[i] >= 1200)m[5]++;
        else if(a[i] >= 800)m[6]++;
        else if(a[i] >= 400)m[7]++;
        else m[8]++;
    }

    int cnt = sz(m);
    if(m[0] > 0){
        cnt--;
        int ma = cnt+m[0];
        //if(ma > 9)ma = 9;
        if(cnt <= 0)cnt = 1;
        cout << cnt << " " << ma << endl;
    }else{
        cout << cnt << " " << cnt << endl;
    }
 
   
	return  0;
}

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

#define rep(i,n) for(long long i=0; i<(long long)(n);i++)
#define rep2(i,s,n) for(long long i=(s); i<(long long)(n);i++)

typedef long long ll;

const ll inf = 1e18+7;
const ll mod = 1e9+7;

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

    ll ans=n/11*2;

    if(n%11>0&&n%11<=6){
        ans++;
    }
    else if(n%11>6&&n%11<=10){
        ans+=2;
    }

    cout<<ans<<endl;
}



Measured memory_bytes: 256
#include<iostream>
using namespace std;
typedef long long ll;
int main(void)
{
    ll n,m;
    cin >> n >> m;
    if(n>=2 && m>=2) cout << (n-2)*(m-2);
    else if(n==1 && m==1) cout << '1';
    else if(n==1) cout << m-2;
    else cout << n-2;
    return 0;
}


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

class dice{
public:
	int d[6], tmp[6];
	dice(int n[6]){
		for (int i = 0; i < 6; i++){
			d[i] = n[i];
		}
	}
	void throwdice(char c){
		for (int i = 0; i < 6; i++){
			tmp[i] = d[i];
		}
		if (c == 'N'){
			d[0] = tmp[1];
			d[1] = tmp[5];
			d[2] = tmp[2];
			d[3] = tmp[3];
			d[4] = tmp[0];
			d[5] = tmp[4];
		}
		else if (c == 'E'){
			d[0] = tmp[3];
			d[1] = tmp[1];
			d[2] = tmp[0];
			d[3] = tmp[5];
			d[4] = tmp[4];
			d[5] = tmp[2];
		}
		else if (c == 'W'){
			d[0] = tmp[2];
			d[1] = tmp[1];
			d[2] = tmp[5];
			d[3] = tmp[0];
			d[4] = tmp[4];
			d[5] = tmp[3];
		}
		else if (c == 'S'){
			d[0] = tmp[4];
			d[1] = tmp[0];
			d[2] = tmp[2];
			d[3] = tmp[3];
			d[4] = tmp[5];
			d[5] = tmp[1];
		}
		else if (c == 'R'){
			d[0] = tmp[0];
			d[1] = tmp[3];
			d[2] = tmp[1];
			d[3] = tmp[4];
			d[4] = tmp[2];
			d[5] = tmp[5];
		}
	}
};
int main()
{
	int q;
	int n[6];
	for (int i = 0; i < 6; i++){
		cin >> n[i];
	}
	dice dice1(n);
	cin >> q;
	for (int i = 0; i < q; i++){
		bool upsame = false;
		int up, front;
		cin >> up >> front;
		for (int i = 0; i < 4; i++){
			dice1.throwdice('S');
			if (dice1.d[0] == up){
				upsame = true;
				break;
			}
		}
		if (!upsame){
			while (true){
				dice1.throwdice('W');
				if(dice1.d[0] == up){
					break;
				}
			}
		}

		for (int i = 0; i < 4; i++){
			dice1.throwdice('R');
			if (dice1.d[1] == front){
				break;
			}
		}
		cout << dice1.d[2] << endl;
	}

	return 0;
}

Measured memory_bytes: 1160
n = int(input())
b = list(map(int, input().split()))
a = [0] * (n + 1)
for i in range(1, n + 1):
    a[i] = b[i - 1]


ball = [0] * (n + 1)
ans = []

for i in range(n, 0, -1):
    s = 0
    j = i * 2
    while j <= n:
        s += ball[j]
        j += i

    if s % 2 != a[i]:
        ball[i] += 1
        ans.append(i)

print(len(ans))
for e in ans:
    print(e)


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

#define LEN 100005

typedef struct {
	string name;
	int t;
}P;

P Q[LEN];
int head, tail, n;

void enqueue(P x) {
	Q[tail] = x;
	tail = (tail + 1) % LEN;
}

P dequeue() {
	P x = Q[head];
	head = (head + 1) % LEN;
	return x;
}

int min(int a, int b) {
	return a < b ? a : b;
}

int main()
{
	int elaps = 0, c, q;
	P u;
	cin >> n >> q;

	for( int i = 1; i <= n; i++ ) {
		cin >> Q[i].name >> Q[i].t;
	}
	head = 1; tail = n + 1;

	while(head != tail) {
		u = dequeue();
		c = min(q, u.t);
		elaps += c;
		u.t -= c;
		if(u.t > 0) enqueue(u);
		else cout << u.name << " " << elaps << endl;
	}

	return 0;
}


Measured memory_bytes: 7052
fun main(args: Array<String>) = p24()

fun p24() {
    data class Vertex(val index: Int, val neighbor: List<Int>, var visitedTime: Int = -1, var completeTime: Int = -1) {
        override fun toString(): String = "${index + 1} $visitedTime $completeTime"
    }

    val n = readLine()!!.toInt()
    val vertexes = Array(n) {
        val line = readLine()!!.split(' ').map { it.toInt() }
        Vertex(line.first() - 1, line.drop(2).map { it - 1 })
    }

    var currTime = 1

    fun dfs(index: Int) {
        val vertex = vertexes[index]
        if (vertex.visitedTime != -1) return
        vertex.visitedTime = currTime++
        vertex.neighbor.forEach { dfs(it) }
        vertex.completeTime = currTime++
    }

    (0 until n).forEach { dfs(it) }

    val answer = vertexes.joinToString(System.lineSeparator())

    println(answer)
}



Measured memory_bytes: 32176
/* Author - thiolhub */

#include <bits/stdc++.h>

using namespace std;

#define ll              long long int
#define ld              long double
#define db              double
#define pi              3.1415926535897932384626
#define PI              acos(-1.0)
#define endl            "\n"
#define mod             1000000007
#define mk              make_pair
#define pb              push_back
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define ps(x,y)         fixed<<setprecision(y)<<x
#define w(t)            ll t; cin>>t; while(t--)
#define sc(a)	        scanf("%lld",&a);
#define pr(a)	        printf("%lld\n",a)
#define f(i,a,n)		for(ll i=a;i<n;i++)
#define m(a)		    memset(a,0,sizeof(a))
#define FastIO          ios_base::sync_with_stdio(0);cin.tie(0),cout.tie(0)



int main(){ FastIO;

ll n,w,i,j;cin>>n>>w;
ll val[n],wt[n];
for(i=0;i<n;i++) cin>>wt[i]>>val[i];
ll dp[n+1][w+1];
memset(dp,0,sizeof(dp));
for(i=0;i<=n;i++)
{
	for(j=0;j<=w;j++)
	{
		if(i==0 || j==0) dp[i][j]=0;
		else if(wt[i-1]>j) dp[i][j]=dp[i-1][j];
		else dp[i][j]=max(dp[i-1][j-wt[i-1]]+val[i-1],dp[i-1][j]);
	}
}
cout<<dp[n][w];

return 0;
}


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

int main() {
  int A, B;
  cin >> A >> B;
  
  int a_01 = A / 10000;
  int a_02 = A / 1000 - a_01 * 10;
  int a_03 = A / 100 - a_01 * 100 - a_02 * 10;
  
  int b_01 = B / 10000;
  int b_02 = B / 1000 - b_01 * 10;
  int b_03 = B / 100 - b_01 * 100 - b_02 * 10;
  
  int head = 0, tail = 0;
  
  if (A <= (a_01 * 10000 + a_02 * 1000 + a_03 * 100
            + a_02 * 10 + a_01)){
    head = 1;
  }
  
  if (B >= (b_01 * 10000 + b_02 * 1000 + b_03 * 100
            + b_02 * 10 + b_01)){
    tail = 1;
  }
  
  int sum;
  
  if ((b_01 - a_01) >= 1){
    sum = (b_01 - a_01 - 1) * 100
      + ((9 - a_02) + b_02) * 10
      + ((9 - a_03) + b_03)
      + head + tail;
  }else{
    if ((b_02 - a_02) >= 1){
       sum = (b_02 - a_02 -1) * 10
         + ((9 - a_03) + b_03)
         + head + tail;
    }else{
      if ((b_03 - a_03) >= 1){
        sum = (b_03 - a_03 -1) + head + tail;
      }else{
        if (head == 1 && tail == 1){
          sum = 1;
        }else{
          sum = 0;
        }
      }
    }
  }
      
  cout << sum << endl;
}


Measured memory_bytes: 3564
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define F first
#define S second
ll mod=998244353;

int main(){
    std::ios::sync_with_stdio(false);
    int n;
    cin>>n;
    int m=n-1;
    int ar[n][m];
    for(int i=0;i<n;i++)for(int j=0;j<n-1;j++)cin>>ar[i][j];
    int in[n]={0};
    int ans=0,game=(n*(n-1))/2,prev=game,fl=0;
    //cout<<endl;
    while(game){
        int vis[n]={0};
        for(int i=0;i<n;i++){
            if(in[i]==n-1)continue;
            int in1=ar[i][in[i]];
            in1--;
            if(in[in1]==n-1)continue;
            //cout<<i<<" "<<ar[i][in[i]]<<" "<<ar[in1][in[in1]]<<endl;
            if(i+1==ar[in1][in[in1]]&&(vis[i]==0&&vis[in1]==0)){
                game--;
                in[i]++;
                in[in1]++;
                vis[i]=1;
                vis[in1]=1;
            }
        }
        ans++;
        if(game==prev){
            fl=1;
            break;
        }
        prev=game;
        //cout<<endl;
    }
    if(fl==1)cout<<-1;
    else cout<<ans;

    return 0;
}



Measured memory_bytes: 4224
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define vtpl(x,y,z) vector<tuple<x,y,z>>
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
} 
 
int main(){
    ll n,k,l,r;cin >> n >> k >> l >> r;
    vl v(n);rep(i,n)cin >> v[i];
    vvl x(k+1),y(k+1);
    rep(bit,1<<(n/2)){
        ll ret=0,sum=0;
        rep(i,n/2){
            if(bit&(1<<i)){
                sum+=v[i],ret++;
            }
        }
        if(ret>k)continue;
        x[ret].pb(sum);
    }
    rev(all(v));
    rep(bit,1<<(n-n/2)){
        ll ret=0,sum=0;
        rep(i,n-n/2){
            if(bit&(1<<i)){
                sum+=v[i],ret++;
            }
        }
        if(ret>k)continue;
        y[ret].pb(sum);
    }
    rep(i,k+1)sort(all(x[i]));
    rep(i,k+1)sort(all(y[i]));
    ll ans=0;
    rep(i,k+1){
        for(auto p:x[i]){
            if(p>r)continue;
            ans+=upper_bound(all(y[k-i]),r-p)-lower_bound(all(y[k-i]),l-p);
        }
    }
    cout << ans <<endl;
}


Measured memory_bytes: 23324
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;

long long n, m;

bool judge(long long k) {
    long long x = n;
    while(x % k == 0) {
        x /= k;
    }
    if(x % k == 1) return 1;
    return 0;
}

int main() {
    scanf("%lld", &n);
    if(n == 2) {
        printf("1\n");
        return 0;
    }
    m = n - 1;
    long long cnt = 0;
    for(long long i = 2; i * i <= m; i++) {
        if(i * i == m) cnt++;
        else if(m % i == 0) cnt += 2;
    }
    cnt += 2;
    for(long long i = 2; i * i <= n; i++) {
        if(m % i == 0) continue;
        if(i * i == n) {
            cnt += judge(i);
        }
        else if(n % i == 0) {
            cnt += judge(n / i);
            cnt += judge(i);
        }
    }
    printf("%lld\n", cnt);

    return 0;
}


Measured memory_bytes: 128
import java.util.*;
import java.lang.*;
import java.io.*;
public class Main
{
	public static void main (String[] args) throws java.lang.Exception
	{
		Scanner scn = new Scanner(System.in);
		int n = scn.nextInt();
		int maxWeight = scn.nextInt();
		int[][] itemvaw = new int[n+1][2];
		
		for(int i=1;i<=n;i++){
		    itemvaw[i][0] = scn.nextInt();
		    itemvaw[i][1] = scn.nextInt();
		}
		long[][] memo = new long[n+1][maxWeight+1];
		System.out.println(knapsack_memoized(1,itemvaw,maxWeight,memo));
	}
	
	public static long knapsack_memoized(int cii, int[][] itemvaw, int capacityLeft, long[][] memo) {
		if (cii == itemvaw.length)return 0;
		if (capacityLeft == 0)return 0;
		if (memo[cii][capacityLeft] != 0)return memo[cii][capacityLeft];
		long o1 = capacityLeft - itemvaw[cii][0] >= 0 ?
		         itemvaw[cii][1] + knapsack_memoized(cii + 1, itemvaw, capacityLeft - itemvaw[cii][0], memo) : Integer.MIN_VALUE;
		long o2 = knapsack_memoized(cii + 1, itemvaw, capacityLeft, memo);
		return memo[cii][capacityLeft] = Math.max(o1, o2);
	}
}


Measured memory_bytes: 140960
#include <iostream>

using namespace std;

int main() {
  string s, t;
  cin >> s >> t;
  int slen = s.size();
  int tlen = t.size();
  int ans = 1000;
  for (int i = 0; i <= slen - tlen; i++) {
    int c = 0;
    for (int j = 0; j < tlen; j++) {
      if (s[i + j] != t[j]) {
        c++;
      }
    }
    if (c < ans) {
      ans = c;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3196
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
#define endl "\n"
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();
// freopen("input.txt", "r", stdin);
// T = A or A+1
// T_any = shortest_T + 2*n
// A_any = shortest_A;

// maximize T_any
// minimize A_any

int main() {
    int n, u, v, a, b;
    cin >> n >> u >> v;
    unordered_map<int, vector<int>> e;
    for(int i = 0 ; i < n-1; i++) {
        cin >> a >> b;
        e[a].push_back(b);
        e[b].push_back(a);
    }
    auto bfs = [&] (int st) -> vector<int> {
        vector<int> dis(n+1, -1);
        vector<int> dq = {st};
        dis[st] = 0;
        int step = 1;
        while(!dq.empty()) {
            vector<int> new_dq;
            for(int node: dq) {
                for(int neibor: e[node]) {
                    if (dis[neibor] == -1) {
                        dis[neibor] = step;
                        new_dq.push_back(neibor);
                    }
                }
            }
            dq.swap(new_dq);
            step += 1;
        }
        return dis;
    };
    auto taka = bfs(u);
    auto aoki = bfs(v);
    int ans = 0;
    for(int i = 1; i <= n; i++) {
       if (taka[i] <= aoki[i]) {
           ans = max(ans, aoki[i]-1);
           /*
           if ((taka[i] + aoki[i]) % 2 == 1) {
               int cand = taka[i];
               ans = max(ans, cand); 
           }*/
       } 
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 10148
#include <cstdio>
#include <iostream>
using namespace std;
int N, t;
int main(){
    scanf("%d", &N);
    for(int i = 0, x = 0; i < N; ++i){
        scanf("%d", &x);
        if(x&1) ++t;
    }
    if(t&1) printf("NO\n");
    else printf("YES\n");
}


Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
from bisect import bisect_left
INF = float("inf")


def solve(N: int, H: "List[int]"):
    mc = 0
    counter = 0
    for i in range(1, N):
        if H[i-1] >= H[i]:
            counter += 1
        else:
            if counter > mc:
                mc = counter
            counter = 0
    if counter > mc:
        mc = counter
    print(mc)
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    H = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, H)


if __name__ == '__main__':
    main()


Measured memory_bytes: 15356
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cstring>
#include<map>
using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(n) rep(i,n)

#define MAX 1000

typedef pair<string, vector<int> > pp;

int main()
{
    string s;
    int n;
    vector<pp> ind;
    vector<int> emp;

    while(cin >> s >> n)
    {
        bool found = false;
        REP(ind.size() )if(ind[i].first == s){ ind[i].second.push_back(n); found = true; break; }
        if(found)continue;

        ind.push_back(pp(s,emp));
        ind[ind.size() - 1].second.push_back(n);
    }
    sort(ind.begin(), ind.end());


    REP(ind.size())
    {
        sort(ind[i].second.begin(), ind[i].second.end());
        cout << ind[i].first << endl;
        rep(j, ind[i].second.size())
        {
            cout << ind[i].second[j] ;
            if(j == ind[i].second.size() - 1) break;
            cout << " " ;
        }

        cout << endl ;
    }
    return 0;
}

Measured memory_bytes: 0
import java.util.Scanner;
public class Main{
	static void swap(int[] a, int idx1, int idx2) {
        int t = a[idx1];
        a[idx1] = a[idx2];
        a[idx2] = t;
    }
    static void quickSort(int[] a, int left, int right) {
        int pl = left;
        int pr = right;
        int x = a[(pl + pr) / 2];
 
        do {
            while (a[pl] < x) {
                pl++;
            }
            while (a[pr] > x) {
                pr--;
            }
            if (pl <= pr) {
                swap(a, pl++, pr--);
            }
        } while (pl <= pr);
 
        if (left < pr) {
            quickSort(a, left, pr);
        }
        if (pl < right) {
            quickSort(a, pl, right);
        }
    }
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int[] hill=new int[10];
		for(int i=0;i<10;i++){
			hill[i]=scan.nextInt();
		}	
		quickSort(hill,0,9);
		System.out.println(hill[9]);
		System.out.println(hill[8]);
		System.out.println(hill[7]);
	}
}

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

#define INF (1<<30)
#define MAX_N 100
#define MAX_V 100

int N, W;
int v[MAX_N];
int w[MAX_N];

int dp[MAX_N * MAX_V + 1];

int main()
{
	cin >> N >> W;
	for( int i = 0; i < N; i++ ) {
		cin >> v[i] >> w[i];
	}

	for( int j = 0; j <= N * MAX_V; j++ ) {
		dp[j] = INF;
	}
	dp[0] = 0;
	for( int i = 0; i < N; i++ ) {
		for( int j = N * MAX_V; j >= 0; j-- ) {
			if( j >= v[i] ) {
				dp[j] = min( dp[j], dp[j - v[i]] + w[i] );
			}
		}
	}
	int ans;
	for( int j = 0; j <= N * MAX_V; j++ ) {
		if( dp[j] <= W ) {
			ans = j;
		}
	}

	cout << ans << endl;

	return 0;
}



Measured memory_bytes: 3176
#include<bits/stdc++.h>
using namespace std;
int gcd(int a,int b){
if(a==0)
{
    return b;
}
return gcd(b%a,a);
}
int main()
{
    int n,k,c,ans=0,a[10001],cnt=0;
    cin>>k;
    for(int i=1;i<=k;i++)
    {
        for(int j=1;j<=k;j++)
        {
        for(int l=1;l<=k;l++)
        {
        ans+=gcd(gcd(i,j),l);
    }
}
}
cout<<ans<<"\n";
}


Measured memory_bytes: 3584
#include <stdio.h>
#include <assert.h>
#include <fstream>
#include <iostream>
#include <algorithm>
#include <array>
#include <vector>
#include <queue>
#include <set>
#include <cmath>
#include <unordered_map>
//#include <unordered_set>
//#include <boost/container/static_vector.hpp>
//#include <boost/unordered_set.hpp>
//#include <boost/unordered_map.hpp>
//#include <unistd.h>
 
const int MAX_N = 1010;
const int MAX_M = 2020;
int N, M;
long long a[MAX_M], b[MAX_M], c[MAX_M];

long long score[MAX_N];
bool can_goal[MAX_N];

const long long INF = (long long)1000000000 * 3000;
 
int main(int argc, char **argv) {
    std::cin >> N >> M;

    for (int i = 1; i <= M; i++) {
        std::cin >> a[i] >> b[i] >> c[i];
    }

    for (int i = 1; i <= N; i++) {
        score[i] = -INF;
        can_goal[i] = false;
    }

    can_goal[N] = true;
    score[1] = 0;

    for (int j = 1; j <= N; j++) {
        for (int i = 1; i <= M; i++) {
            if (can_goal[b[i]]) {
                can_goal[a[i]] = true;
            }
        }
    }

    for (int j = 1; j <= N; j++) {
        for (int i = 1; i <= M; i++) {
            if (score[a[i]] != -INF && can_goal[b[i]] && score[b[i]] < score[a[i]] + c[i]) {
                score[b[i]] = score[a[i]] + c[i];
                if (j == N) {
                    std::cout << "inf" << std::endl;
                    return 0;
                }
            }
        }
    }
    
    std::cout << score[N] << std::endl;

    return 0;
}

Measured memory_bytes: 256
s = int(input())
mod = 10 ** 9 + 7

fact = [1] * s
inv = [1] * s
invf = [1] * s
for i in range(2, s):
  fact[i] = fact[i-1] * i % mod
  inv[i] = -(mod // i) * inv[mod % i] % mod
  invf[i] = invf[i-1] * inv[i] % mod

count = 0
rest = s
for n in range(1, s // 3 + 1):
  rest -= 3
  count = (count + fact[rest + n - 1] * invf[rest] * invf[n - 1]) % mod
print(count)

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


int main() {
	int N;
	map<char, long long> m;
	char I[] = "MARCH";
	long long ans = 0;

	cin >> N;
	for (int i = 0; i < N; i++) {
		string str;
		cin >> str;
		m[str[0]]++;
	}

	for (int i = 0; i < 5; i++) {
		for (int j = i + 1; j < 5; j++) {
			for (int k = j + 1; k < 5; k++) {
				ans += m[I[i]] * m[I[j]] * m[I[k]];
			}
		}
	}

	cout << ans << endl;

	return 0;
}

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

int main() {
  int r,g,b;
  cin >> r >> g >> b;
  int c;
  c=r*100+g*10+b;
  if(c % 4 ==0)
    cout << "YES" << endl;
  else
    cout << "NO" <<endl;
      
}

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

int main(){
    int k, n;
    cin >>k >>n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >>a.at(i);
    }

    //"dis" is longest range of houses
    int dis = a.at(0);
    if (n == 2) {
        if (a.at(1) - a.at(0) > dis){
            dis = a.at(1) - a.at(0);
        }
        if (k - a.at(1) + a.at(0) > dis){
            dis = k - a.at(1) + a.at(0);
        }
    }
    else{
        if (dis < a.at(1) - a.at(0))
        {
            dis = a.at(1) - a.at(0);
        }
        for (int i = 2; i < n; i++)
        {
            if (dis < a.at(i) - a.at(i - 1))
            {
                dis = a.at(i) - a.at(i - 1);
            }
        }

        if (dis < (k - a.at(n - 1)) + a.at(0))
        {
            dis = (k - a.at(n - 1)) + a.at(0);
        }
    }


    cout << k - dis <<endl;
}

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

int main(){

  int n, ans = 0, flag;
  cin >> n;
  int h[n];
  for (int i = 0; i < n; i++) {
    cin >> h[i];
  }

  reverse(h, h + n);

  for (int i = 0; i < n; i++) {
    flag = 1;
    for (int j = i; j < n; j++) {
      if(h[i] < h[j]) flag = 0;
    }
    if(flag == 1) ans += 1;
  }

  cout << ans << endl;

}


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

int main(){
    int A, B;
    cin >> A >> B;
    if (A == B) {
        cout << A + B << endl;
    }else if(A > B){
        cout << A + A - 1 << endl;
    }else{
        cout << B + B - 1 << endl;
    }
}




Measured memory_bytes: 256
<?php
      fscanf(STDIN, "%d", $n);
    while ($a = fgets(STDIN)){
    $a = str_replace(PHP_EOL, '', $a);
    $s = explode(" ", $a);
     $value_count = array_count_values($s);
       $max = max($value_count); // 最大の出現回数を取得する
        if ($max == 1) {
            echo "YES";
        }else {
            echo "NO";
        }
    }
    ?>

Measured memory_bytes: 68964
#include <iostream>
#include <string>
#include <sstream>
#include <queue>
#include <map>
 
using namespace std;
 
int const N = 8;
int const pow_10[N] = { 10000000, 1000000, 100000, 10000, 1000, 100, 10, 1 };
class card
{
    static int const Offset = 1;
 
public:
    template<typename T>
    card( T const& t )
    {
        for( int y=0; y<2; ++y ) {
            for( int x=0; x<N/2; ++x ) {
                num_[y][x] = t[y*N/2+x] + Offset;
                if ( num_[y][x] == Offset ) {
                    x0_ = x;
                    y0_ = y;
                }
            }
        }
    }
 
public:
    card make_moved( int const dir ) const
    {
        card ret( *this );
 
        switch( dir )
        {
        case 0:
            ret.to_up();
            break;
        case 1:
            ret.to_right();
            break;
        case 2:
            ret.to_down();
            break;
        case 3:
            ret.to_left();
            break;
        }
 
        return ret;
    }
 
public:
    operator long long int() const
    {
        long long int  p = 0;
        static bool pp = false;
 
        for( int y=0; y<2; ++y ) {
            for( int x=0; x<N/2; ++x ) {
                p += num_[y][x] * pow_10[y*N/2+x];
            }
        }
 
        return p;
    }
     
    bool operator==( card const& rhs ) const
    {
        return static_cast<long long int>( *this ) == static_cast<long long int>( rhs );
    }
 
    bool operator<( card const& rhs ) const
    {
        return static_cast<long long int>( *this ) < static_cast<long long int>( rhs );
    }
 
private:
    void to_down()
    {
        if ( y0_ == 0 ) {
            swap( num_[y0_][x0_], num_[y0_+1][x0_] );
            ++y0_;
        }
    }
 
    void to_up()
    {
        if ( y0_ == 1 ) {
            swap( num_[y0_][x0_], num_[y0_-1][x0_] );
            --y0_;
        }
    }
 
    void to_right()
    {
        if ( x0_ != N/2-1 ) {
            swap( num_[y0_][x0_], num_[y0_][x0_+1] );
            ++x0_;
        }
    }
 
    void to_left()
    {
        if ( x0_ != 0 ) {
            swap( num_[y0_][x0_], num_[y0_][x0_-1] );
            --x0_;
        }
    }
 
private:
    int num_[2][4];
    int x0_, y0_;
};
 
 
int main()
{
    int const start[N] = {0, 1, 2, 3, 4, 5, 6, 7 };
    int const goal[N]  = {7, 6, 5, 4, 3, 2, 1, 0 };
 
    map<card, bool> memo;
    map<card, int> costs;
    queue<pair<int, card> > q;
    q.push( make_pair( 0, card( start ) ) );
 
    // loop
    while( !q.empty() ) {
        int const cost = q.front().first;
        card const c = q.front().second;
        q.pop();
 
        if ( memo[c] ) continue;
        memo[c] = true;
        costs[c] = cost;
 
        for( int i=0; i<4; ++i ) {
            card const nc = c.make_moved( i );
            if ( nc == c ) continue;
            q.push( make_pair( cost + 1, nc ) );
        }
    }
 
 
    for(int r=0; r<1000; ++r ) { 
        int nn[N];
        for( int i=0; i<N; ++i ) {
            cin >> nn[i];
            if ( cin.eof() ) return 0;
        }
        card const f( nn );
 
        cout << costs.at( f ) << endl;
    }
}

Measured memory_bytes: 5088
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> P;
typedef vector<vector<int>> Matrix;
static const int INF = 2000000000;

int main(){
  auto f = [&](int x){
    int res = 0;
    while (x){
      res += x % 10;
      x /= 10;
    }
    return res;
  };

  int n;
  cin >> n;
  if (n % f(n)) cout << "No\n";
  else cout << "Yes\n";
}



Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <utility>
#define mod 1000000007
using namespace std;
typedef long long ll;
inline int getint(){
  char c; int res = 0, sig = 1;
  for(c = getchar();c < '0' || c > '9';c = getchar()) if(c == '-') sig = -1;
  for(;c >= '0' && c <= '9';c = getchar()) res = res * 10 + (c - '0');
  return res * sig;
}
const char s[] = "ACGT";
int n,f[105][4][4][4];//0...3: A,C,G,T
bool legal(int a,int b,int c,int d){
  if(b == 0 && c == 2 && d == 1) return false;
  if(b == 0 && c == 1 && d == 2) return false;
  if(b == 2 && c == 0 && d == 1) return false;
  if(a == 0 && c == 2 && d == 1) return false;
  if(a == 0 && b == 2 && d == 1) return false;
  return true;
}
int main(){
  n = getint();
  for(int i = 0;i < 4;i++){
    for(int j = 0;j < 4;j++){
      for(int k = 0;k < 4;k++){
        if(legal(2535,i,j,k)) f[3][i][j][k] = 1;
      }
    }
  }
  for(int w = 3;w < n;w++){
    for(int i = 0;i < 4;i++){
      for(int j = 0;j < 4;j++){
        for(int k = 0;k < 4;k++){
          for(int l = 0;l < 4;l++){
            if(legal(i,j,k,l)) (f[w + 1][j][k][l] += f[w][i][j][k]) %= mod;
          }
        }
      }
    }
    
//    for(int j = 0;j < 4;j++){
//      for(int k = 0;k < 4;k++){
//        cout << w + 1 << " " << s[j] << " " << s[k] << ": " << f[w + 1][j][k] << endl;
//      }
//      system("pause");
//    }
    
  }
  
  int ans = 0;
  for(int i = 0;i < 4;i++){
    for(int j = 0;j < 4;j++){
      for(int k = 0;k < 4;k++){
        (ans += f[n][i][j][k]) %= mod;
      }
    }
  }
  printf("%d\n",ans);
  return 0;
}


Measured memory_bytes: 256
def cut(d, w, s):
    s %= d + w
    sq = []
    if 0 < s < w:
        sq = [(d, s), (d, w - s)]
    elif w < s < w + d:
        s -= w
        sq = [(s, w), (d - s, w)]
    else:
        assert(False)
    p1, p2 = sq
    if p1[0] * p1[1] > p2[0] * p2[1]:
        p1, p2 = p2, p1
    return [p1, p2]


while True:
    N, W, D = map(int, input().split())
    if not (N | W | D):
        break
    square = [(D, W)]
    for _ in range(N):
        p, s = map(int, input().split())
        d, w = square.pop(p - 1)
        square.extend(cut(d, w, s))
    print(*sorted(d * w for d, w in square))

Measured memory_bytes: 7632
h, w, k = map(int, input().split())
ccc = [input() for _ in range(h)]
ans = 0
for bit_h in range(2 ** h):
    for bit_w in range(2 ** w):
        cnt = 0
        for hi in range(h):
            for wi in range(w):
                if (bit_h >> hi) & 1 == 0 and (bit_w >> wi) & 1 == 0:
                    if ccc[hi][wi] == '#':
                        cnt += 1
        if cnt == k:
            ans += 1
print(ans)

Measured memory_bytes: 9204
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#include <bits/stdc++.h>
#include <iterator>
#include <algorithm>
#include <queue>
#include <set>
#include <bitset>
#include <vector>
#include <map>



#define IOS                    ios::sync_with_stdio();cin.tie(0);
#define tc()                int tc;scanf("%d",&tc);while(tc--)
#define endl                "\n"
#define FLOAT_COM(a,b)      if(abs(a-b)==1e-9)
#define VI                  vector<int>
#define VLL                 vector<long long>
#define PB                  push_back
#define MP                  make_pair



using namespace std;

int i,j,k,l,temp;

void shomoy(){
    #ifndef ONLINE_JUDGE
        cerr<<"\nTime  :"<<1.0*clock()/CLOCKS_PER_SEC<<"  s\n";
    #endif

}

bool isprime(int n){
    int f;
    for(f=2;f*f<=n;f++){
        if(n%f==0)
            return false;
    }
    return true;
}


                      /*Driver Code Startes Here*/
int main(){IOS

    int n;
    scanf("%d",&n);
    if(n>=30){
        printf("Yes\n");
    }
    else{
        printf("No\n");
    }
    

    

shomoy();
return 0;
}

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

#define fast ios_base::sync_with_stdio; cin.tie(0); cout.tie(0)
#define ll          long long
#define ull         unsigned long long
#define pb          push_back
#define pii         pair<int,int>
#define pll         pair<long,long>
#define vi          vector<int>
#define vll         vector<ll>
#define vii         vector<pii>
#define Mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define rall(a)      (a).rbegin(),(a).rend()
#define ff           first
#define ss           second
#define sz(x)       (int)x.size()
//#define endl        '\n'
#define mod        1000000007
//#define mod        998244353
#define rep(i,a,b)  for(int i=a;i<b;i++)
#define rem(i,a,b)  for(int i=a;i>b;i--)
#define mp(a,b)     make_pair(a,b)
#define INF         numeric_limits<ll>::max();
#define NINF        numeric_limits<ll>::min();
#define vvi(a,b,name)    vector<vector<int>> name(a,vector<int>(b,-1))
const long double pi=3.14159265359;

inline ll add(ll a, ll b, ll m)
{
    if ((a + b) >= m)
        return (a + b) % m;
    return a + b;
}

inline ll mul(ll a, ll b, ll m)
{
    if ((a * b) < m)
        return a * b;
    return (a * b) % m;
}

ll power(ll x, ll y, ll m)
{
    ll res = 1;
    x = x % m;
    if (x == 0)
        return 0;
    while (y > 0)
    {
        if (y & 1)
            res = (res * x) % m;
        y = y >> 1;
        x = (x * x) % m;
    }
    return res;
}

ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}

int h,w,k;
int ans=0;
vector<string> v;

void fun(vector<int> &r,int i){
    if(i>=h+w){

        int co=0;
        rep(p,0,h){
            rep(q,0,w){
                if(r[p]||r[h+q]){
                    continue;
                }
                if(v[p][q]=='#'){
                    co++;
                }
            }
        }
        if(co==k){
            ans++;
        }
        return;
    }
    /*for(int p=i;p<h;p++){
        r[p]=1;
        for(int q=j;q<w;q++){
            c[q]=1;
            fun(r,c,p+1,q+1);
            c[q]=0;
        }
        r[p]=0;
        for(int q=j;q<w;q++){
            c[q]=1;
            fun(r,c,p+1,q+1);
            c[q]=0;
            fun(r,c,p+1,q+1);
        }
    }*/

    r[i]=1;
    fun(r,i+1);
    r[i]=0;
    fun(r,i+1);
}

int main()
{fast;
 #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
 #endif
 int t=1,n;
 //cin>>t;
 while(t--)
 {
  cin>>h>>w>>k;
  v.resize(h);
  rep(i,0,h){
    cin>>v[i];
  }
  vector<int> r(h+w);
  fun(r,0);
  cout<<ans<<endl;
 }
 return 0;
}


Measured memory_bytes: 3612
#define _USE_MATH_DEFINES
#include<stdio.h>
#include<string>
#include<iostream>
#include<cctype>
#include<cstdio>
#include<vector>
#include<stack>
#include <algorithm>
#include<math.h>
#include<set>
#include<map>
#include<iomanip>

//#include<bits/stdc++.h>



using namespace std;




int main() {
	
	int n;
	cin>>n;
	vector<vector<int>>t(n,vector<int>(0));
	for(int i=0;i<n;i++){
		int x,r;cin>>r>>x;
		for(int j=0;j<x;j++){
			int w;cin>>w;w--;t[i].push_back(w);
			//t[w].push_back(i);
		}
		sort(t[i].begin(),t[i].end());
	}/*
	for(int i=0;i<n;i++){
		sort(t[i].begin(),t[i].end());
		for(int j=0;j<t[i].size();j++)cout<<t[i][j];
		cout<<endl;
	}
	*/
	stack<int>S;
	bool F[105]={};
	S.push(0);
	int p=1;
	F[0]=1;
	vector<int>G(n),H(n);
	int g=1;
	G[0]=1;
	
	while(S.size()||p<n){
		g++;
		if(!S.size()){
			
			for(int i=1;i<n;i++)
				if(!F[i]){
					F[i]=1;
					S.push(i);
					G[i]=g;
					p++;
					break;
				}
			//	cout<<t[S.top()].size();
			//break;
				

		}
		else{
		
		//cout<<p;
		int v=S.top();
		int a=-1;
		for(int i=0;i<t[v].size();i++){
			if(!F[t[v][i]]){
				a=t[v][i];break;
			}
			//if(v==2)cout<<t[v][i]<<"&"<<F[i];
		}
		//cout<<a;
		//if(v==2&&a==-1)break;
		if(a==-1){
			H[S.top()]=g;
			S.pop();
			
			
		}
		else{
			//cout<<"%"<<a<<endl;
			F[a]=1;
			G[a]=g;
			S.push(a);
			p++;
		}
		}
	}
	/*for(int i=0;i<t[S.top()].size();i++)
		cout<<t[S.top()][i];
	cout<<"#"<<t[S.top()][1];
	*/
	for(int i=0;i<n;i++){
		cout<<i+1<<" "<<G[i]<<" "<<H[i]<<endl;
	}
	

	
	return 0;
}


	

Measured memory_bytes: 3148
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Linq;

namespace contest_Csharp
{
    class Program
    {
        

        static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            var vals = Console.ReadLine().Split(' ')
                .Select(x => int.Parse(x)).ToList();

            var A = vals[0];
            var B = vals[1];
            
            



            Console.WriteLine(A*B);
            Console.Out.Flush();

        }



    }

}


Measured memory_bytes: 28308
#include <iostream>

using namespace std;

int main(void) {
  int H,W;
  while(cin >> H >> W && H && W) {
    for(int i = 0; i < H; i++) {
      for(int j = 0; j < W; j++) {
        if(i % 2 == 0 && j % 2 == 0)
          cout << "#";
        else if(i % 2 == 1 && j % 2 == 0)
          cout << ".";
        else if(i % 2 == 0 && j % 2 == 1)
          cout << ".";
        else
          cout << "#";
      }
      cout << endl;
    }
    cout << endl;
  }
  return 0;
}

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

int main() {
  string s;
  string t;
  int count=0;
  bool result=false;
  
  cin>>s>>t;
  
  s=s+s;

  for(int i=0;i<t.size();i++){
    for(int j=0;j<t.size();j++){
      if(s.at(i+j)==t.at(j))count++;
    }
    if(count==t.size())result=true;
    count=0;
  }
 
  if(result)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}


Measured memory_bytes: 256
"use strict"
function main(arg) {
    var data = arg.trim().split("\n")[1].split(" ").map(Number)
    data = data.sort((a,b) => a - b)
    var ans = 'YES'
    for (var i = 1; i < data.length; i++) {
        if (data[i - 1] === data[i]) {
            ans = 'NO'
            break
        }
    }
    console.log(ans)
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 34472
#!/usr/bin/env python3
def main():
    from collections import deque

    H, W = map(int, input().split())
    S = []
    num_path = 0
    for _ in range(H):
        s = input()
        num_path += s.count('.')
        S.append(s)

    move = ((0, 1), (0, -1), (1, 0), (-1, 0))
    distance = [[1] * W for _ in range(H)]
    queue = deque([(0, 0)])
    while queue:
        y, x = queue.popleft()
        if y == H - 1 and x == W - 1:
            break
        for dy, dx in move:
            ny = y + dy
            nx = x + dx
            if (1
                    and 0 <= ny < H
                    and 0 <= nx < W
                    and distance[ny][nx] == 1
                    and S[ny][nx] == '.'):
                queue.append((ny, nx))
                distance[ny][nx] = distance[y][x] + 1
    if distance[H - 1][W - 1] == 1:
        print(-1)
    else:
        print(num_path - distance[H - 1][W - 1])


if __name__ == '__main__':
    main()


Measured memory_bytes: 9440
#include <bits/stdc++.h>
#define ll long long
using namespace std;
vector<pair<int,int>> p(200010);

int main() {
    int n,k,hoge, ans = 0;
    cin >> n >> k;
    for(int i=0;i<n;i++){
        p[i].first = 0;
        p[i].second = i;
    }
    for(int i=0;i<n;i++){
        cin >> hoge;
        p[hoge].first++;
    }
    sort(p.begin(), p.end());
    reverse(p.begin(), p.end());
    for(int i = k ; i < 200010 ; i++){
        ans += p[i].first;
    }
    cout << ans << endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define ll long long int
#define MOD 1000000007
#define INF 1e18
#define PI 3.14159265358979

using namespace std;

int main(void){
  int a, b, c;
  string s;

  cin >> a >> b;
  
  if (a <= 10)
    cout << b + 100 * (10 - a) << endl;
  else
    cout << b << endl;



  return 0;
}


Measured memory_bytes: 256
import re

S = input()
T = input()

flag = False
for i in range(len(S) - len(T), -1, -1):
    pattern = S[i:i+len(T)].replace('?', '.')
    m = re.search(pattern, T)
    if m:
        # result = re.sub(pattern, T, S)
        result = S[:i] + T + S[i+len(T):]
        flag = True
        break

if flag > 0 :
    output = result.replace('?', 'a')
    
else :
    output = 'UNRESTORABLE'
    
print(output)


Measured memory_bytes: 9820