akhauriyash/Code-Regression huggingface dataset:
/*
Author: Sagar Gupta
E mail: sagar.june97p@gmail.com
*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define newline ("\n")
#define deb(n) cerr << #n << " = " << (n) << '\n'
#define FOR(i, n) for (int(i) = 0; (i) < n; (i)++)
#define PI (3.141592653589)
#define ordered_set tree<int, null_type, std::less<int>, rb_tree_tag, tree_order_statistics_node_update>

#define MOD 1000000007

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

    // Pikachu, I choose you
    vector<int> adj[5];
    for (int i = 0; i < 3; i++)
    {
        int u, v;
        cin >> u >> v;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    for (int i = 1; i < 5; i++)
        if (adj[i].size() > 2)
        {
            cout << "NO";
            return 0;
        }
    cout << "YES";
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <stdlib.h>
#include <vector>
#include <climits>
#include <math.h>
#include <map>
#include <set>
#include <stack>
#include <iomanip>
#include <stdio.h>
using namespace std; 
#define Endl '\n'
int main()
{
    int k;
    cin>>k;
    string s;
    cin>>s;
    if (s.size()<=k)
    {
        cout<<s;
    }
    else
    {
        for (int i = 0; i < k; ++i)
        {
            cout<<s[i];
        }
        cout<<"...";
    }
}

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

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repp(i, l, r) for(int i = (l); i < (r); i++)
#define per(i, n) for(int i = ((n)-1); i >= 0; i--)
#define perr(i, l, r) for(int i = ((r)-1); i >= (l); i--)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define IINF 1000000000
#define LINF 1000000000000000000
#define SP <<" "<<
#define CYES cout<<"Yes"<<endl
#define CNO cout<<"No"<<endl
#define CFS cin.tie(0);ios::sync_with_stdio(false)

typedef long long LL;
typedef long double LD;

int main(){
  while(1){
    int n,p;
    cin >> n >> p;
    if(n==-1) return 0;
    vector<bool> hurui(200000,true);
    hurui[0]=hurui[1]=false;
    repp(i,2,200000){
      if(hurui[i]){
        for(int j=i+i;j<200000;j+=i) hurui[j]=false;
      }
    }
    vector<int> prime;
    repp(i,n+1,200000){
      if(hurui[i]) prime.push_back(i);
      if(prime.size()>=100) break;
    }
    vector<int> sum;
    rep(i,100){
      repp(j,i,100){
        sum.push_back(prime[i]+prime[j]);
      }
    }
    sort(all(sum));
    cout << sum[p-1] << endl;
  }
  return 0;
}



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

using namespace std;

int main(void)
{
	string s;
	cin >> s;

	cout << ((s[0]==s[1] && s[1]==s[2]) ? "Yes" : ((s[1]==s[2] && s[2]==s[3]) ? "Yes" : "No" )) << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long int ll;
using namespace std;
ll a[200005], b[200005];
ll n, m, k;

void solve()
{
    cin >> n >> m >> k;
    ll asum = 0, bsum = 0;
    for(int i = 1; i<=n; i++)
    {
        int c;
        cin >> c;
        asum += c;
        a[i] = asum;
    }
    for(int i = 1; i<=m; i++)
    {
        int c;
        cin >> c;
        bsum += c;
        b[i] = bsum;
    }
    ll total = 0;
    for(ll i=0; i<=n; i++)
    {
        ll other = k-a[i];
        if(other<0)
            continue;
        int l=lower_bound(b, b+m, other)-begin(b);
        if(l>m || b[l]>other)
            --l;
        total=max(total, i+l);
    }
    cout <<total;
}


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


Measured memory_bytes: 6708
N,K=input().split()
N,K=[int(N),int(K)]
A=list(map(int,input().split()))
F=list(map(int,input().split()))

A=sorted(A)
F=sorted(F,reverse=True)

goal_max=10**12+1
goal_min=0-1

while(goal_max-goal_min!=1):
   goal=(goal_max+goal_min)//2
   counter=0

   for i in range(N):
      counter+=max(0,A[i]-goal//F[i])

   if(counter<=K):
      goal_max=goal

   else:
      goal_min=goal
      
print(goal_max)

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

int main()
{
	int a[6] = { 0 }, q = 0, b1 = 0, b2= 0, c[24] = { 0 };

	for (int i = 0; i < 6; i++)
		cin >> a[i];

	cin >> q;

	for (int i = 0; i < q; i++) {
		cin >> b1 >> b2;

		if(b1 == a[0]){
			if (b2 == a[1])
				c[i] = a[2];
			else if (b2 == a[2])
				c[i] = a[4];
			else if (b2 == a[3])
				c[i] = a[1];
			else if (b2 == a[4])
				c[i] = a[3];
		}
		else if(b1 == a[1]) {
			if (b2 == a[0])
				c[i] = a[3];
			else if (b2 == a[2])
				c[i] = a[0];
			else if (b2 == a[3])
				c[i] = a[5];
			else if (b2 == a[5])
				c[i] = a[2];
		}
		else if (b1 == a[2]) {
			if (b2 == a[0])
				c[i] = a[1];
			else if (b2 == a[1])
				c[i] = a[5];
			else if (b2 == a[4])
				c[i] = a[0];
			else if (b2 == a[5])
				c[i] = a[4];
		}
		else if (b1 == a[3]) {
			if (b2 == a[0])
				c[i] = a[4];
			else if (b2 == a[1])
				c[i] = a[0];
			else if (b2 == a[4])
				c[i] = a[5];
			else if (b2 == a[5])
				c[i] = a[1];
		}
		else if (b1 == a[4]) {
			if (b2 == a[0])
				c[i] = a[2];
			else if (b2 == a[2])
				c[i] = a[5];
			else if (b2 == a[3])
				c[i] = a[0];
			else if (b2 == a[5])
				c[i] = a[3];
		}
		else if (b1 == a[5]) {
			if (b2 == a[1])
				c[i] = a[3];
			else if (b2 == a[2])
				c[i] = a[1];
			else if (b2 == a[3])
				c[i] = a[4];
			else if (b2 == a[4])
				c[i] = a[2];
		}
	}

	for(int i = 0; i < q; i++)
		cout << c[i] << endl;

    return 0;
}

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


#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)

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


#define WANT 753

//C++14 (GCC 5.4.1)
int main() {
    string S;
    cin >>S;

    //-----------------------------------
    int ans=999,N=S.size()-2;
    rep(i,N){
        int get=(S[i]-'0')*100+(S[i+1]-'0')*10+(S[i+2]-'0');
        //数字文字を数字に変換するいい感じの表記
        chmin(ans,abs(get-WANT));
    }


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

Measured memory_bytes: 256
from heapq import *
l = list()
r = list()
q = int(input())
sb = 0
sr = 0
sl = 0
f = 0
for _ in range(q):
  t = list(map(int, input().split()))
  if t[0] == 1:
    f ^= 1
    _, a, b = t
    sb += b
    if f:
      c = heappushpop(r, a)
      sr += a - c
      heappush(l, -c)
      sl += c
    else:
      c = -heappushpop(l, -a)
      sl += a - c
      heappush(r, c)
      sr += c   
  else:
    print(-l[0], l[0]*(len(r)-len(l)) + sr - sl + sb)

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

int main () {
  string s;
  char c1 = '0';
  char c2 = '0';
  int i1 = 0;
  int i2 = 0;
  cin >> s;
  for (char c : s) {
    if (c1 == '0')
	  c1 = c;
    else if (c != c1 && c2 == '0')
      c2 = c;
    if (c == c1)
      i1++;
    else if (c == c2)
      i2++;
    else {
      cout << "No" << endl;
      return 0;
    }
    if (i1 > 2 || i2 > 2) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  return 0;
}

Measured memory_bytes: 256
#include <assert.h>
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
 
using ll = long long;
using P = std::pair<ll, ll>;
 
#define rep(i, a, b) for (ll(i) = (a); i < (b); i++)
#define all(i) i.begin(), i.end()
#define debug(i) std::cerr << "debug " << i << std::endl
 
template <typename T1, typename T2>
std::ostream& operator<<(std::ostream& os, std::pair<T1, T2> pa) {
  return os << pa.first << " " << pa.second;
}
 
template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
  for (int i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  return os;
}
 
template<typename T1,typename T2>
inline bool chmax(T1& a,T2 b){return a<b && (a=b,true);}
 
template<typename T1,typename T2>
inline bool chmin(T1& a,T2 b){return a>b && (a=b,true);}
 
ll pow_mod(ll a, ll b, ll mod=-1) {
  if ((a == 0)||(mod!=-1&&a%mod==0)) {
    return 0;
  }
 
  ll x = 1;
 
  while (b > 0) {
    if (b & 1) {
      x = (mod!=-1)?(x * a) % mod:x*a;
    }
    a = (mod!=-1)?(a * a) % mod:a*a;
    b >>= 1;
  }
  return x;
}
 
// const ll MOD = 998244353;
const ll MOD = 1e9 + 7;
 
int main() {
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);

  ll n,m;
  std::cin>>n>>m;

  std::vector<std::vector<ll>> graph(n);

  rep(i,0,m){
    ll a,b;
    std::cin>>a>>b;
    a--;b--;
    graph[a].push_back(b);
    graph[b].push_back(a);
  }

  std::vector<ll> color(n,-1);

  std::stack<ll> que;

  color[0]=0;
  que.push(0);

  while(!que.empty()){
    ll now=que.top();que.pop();
    for(ll next:graph[now]){
      if(color[next]==-1){
        color[next]=color[now]^1;
        que.push(next);
      }else{
        if(color[next]==color[now]){
          std::cout<<n*(n-1)/2-m<<"\n";
          return 0;
        }
      }
    }
  }

  ll black=0;
  rep(i,0,n)if(color[i]==0)black++;

  std::cout<<black*(n-black)-m<<"\n";

  return 0;
}

Measured memory_bytes: 7168
A, B, C = map(int, input().split())

limit = A * B

i = 0
while True:
  val = B*i + C 
  if val == 0:
    continue

  if val > limit:
    print("NO")
    exit()

  if val % A == 0:
    print("YES")
    exit()

  i += 1


Measured memory_bytes: 2940
n = list(map(int,input()))
cnt = 0
b = tuple(n)
c = b

for i in n:
    cnt += 1
    if i == 9:
        continue
    else:
        if cnt == len(n):
            cnt -= 1
            n[cnt-1] -= 1
            break
        else:
            if i == 0:
                n[cnt-2] -= 1
                cnt -= 1
                break
            else:
                n[cnt-1] -= 1
                break

for i in range(cnt,len(n)):
    n[i] = 9

if len(n) == 1:
    n = b

if sum(n) >= sum(b):
    print(sum(n))
else:
    print(sum(b))

Measured memory_bytes: 3064
import java.util.*;
import java.io.PrintWriter;
import static java.lang.Integer.*;
import static java.lang.Long.*;
import static java.lang.Math.*;
import static java.lang.System.*;

public class Main {
	public static final int MOD = 1000000007;
	public static void main(String[] args) {
		int i,j;
		Scanner sc = new Scanner(in);
		HashSet<String> set = new HashSet<>();
		set.add(sc.next());
		set.add(sc.next());
		set.add(sc.next());
		sc.close();
		out.println(set.size()==2?"Yes":"No");
	}
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
#ifndef ONLINE_JUDGE
#define dbg(x...) do{cout << "\033[32;1m" << #x << "->" ; err(x);} while(0)
void err(){cout << "\033[39;0m" << endl;}
template<template<typename...> class T,typename t,typename... A>
void err(T<t> a,A... x){for (auto v:a) cout << v << ' '; err(x...);}
template<typename T,typename... A>
void err(T a,A... x){cout << a << ' '; err(x...);}
#else
#define dbg(...)
#endif
const int mod=1e9+7;
const int INF=0x3f3f3f3f;
ll quick(ll a,ll b)
{
	ll ret=1;
	while(b)
	{
		if(b&1)
			ret=ret*a%mod;
		a=a*a%mod;
		b>>=1;
	}
	return ret;
}
ll inv(ll a){return quick(a,mod-2);}
const int maxn=407;
ll sum[maxn][maxn];
int a[maxn],b[maxn];
ll dp[maxn][maxn];
int main()
{
	int n,c;
	scanf("%d%d",&n,&c);
	for(int i=1;i<=n;i++) scanf("%d",&a[i]);
	for(int i=1;i<=n;i++) scanf("%d",&b[i]);
	for(int i=1;i<=n;i++)
	{
		for(int j=0;j<=c;j++)
		{
			for(int k=a[i];k<=b[i];k++)
				sum[i][j]=(sum[i][j]+quick(k,j))%mod;
		}
	}
	dp[0][0]=1;
	for(int i=1;i<=n;i++)
	{
		for(int j=0;j<=c;j++)
		{
			for(int k=0;k<=j;k++)
			{
				dp[i][j]=(dp[i][j]+dp[i-1][k]*sum[i][j-k]%mod)%mod;
			}
		}
	}
	printf("%lld\n",dp[n][c]);
}


Measured memory_bytes: 2816
##input##
N = int(input())
num = input().split()
max_num =max(num)
temp = []
##

##for i in range(int(max_num)):
for i in range(100):
  sum = 0
  for a in num:
    out = (i - int(a))** 2
    sum += out
  temp.append(sum)

min_temp=min(temp)
print(min_temp)

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

int main() {
   int N;
   cin >> N;
   long long X[N],Y[N];
   for (int i=0; i<N; i++) {
       int x,y;
       cin >> x >> y;
       X[i]=x+y;Y[i]=x-y;
   }
   sort(X,X+N);sort(Y,Y+N);
   cout << max(X[N-1]-X[0],Y[N-1]-Y[0]) << endl;
}

Measured memory_bytes: 6752
/*
Hey there stalker....

█▀▀▄░░░░░░░░░░░▄▀▀█
░█░░░▀▄░▄▄▄▄▄░▄▀░░░█
░░▀▄░░░▀░░░░░▀░░░▄▀
░░░░▌░▄▄░░░▄▄░▐▀▀
░░░▐░░█▄░░░▄█░░▌▄▄▀▀▀▀█
░░░▌▄▄▀▀░▄░▀▀▄▄▐░░░░░░█
▄▀▀▐▀▀░▄▄▄▄▄░▀▀▌▄▄▄░░░█
█░░░▀▄░█░░░█░▄▀░░░░█▀▀▀
░▀▄░░▀░░▀▀▀░░▀░░░▄█▀
░░░█░░░░░░░░░░░▄▀▄░▀▄
░░░█░░░░░░░░░▄▀█░░█░░█
░░░█░░░░░░░░░░░█▄█░░▄▀
░░░█░░░░░░░░░░░████▀
░░░▀▄▄▀▀▄▄▀▀▄▄▄█▀

Like what you see?
*/
#include <bits/stdc++.h>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
using namespace std;
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define pii         pair<ll ,ll>
#define vi          vector<ll>
#define present(container, element) (container.find(element) != container.end()) /* For set n maps */
#define cpresent(container, element) (find(all(container),element) != container.end()) /* For vectors */
#define all(a)      (a).begin(),(a).end()
#define invect(data,n,commands) for(int i = 0;i<n;i++){int tmp;cin>>tmp;data.pb(tmp);commands}
#define inset(data,n,commands) for(int i = 0;i<n;i++){int tmp;cin>>tmp;data.I(tmp);commands}
#define F           first
#define S           second
#define I           insert
#define sz(x)       (ll)x.size()
#define rep(i,a,b)    for(ll  i=a;i<b;i++)
#define repr(i,a,b) for(ll  i=a;i>b;i--)
#define trav(a, x) 	for(auto& a : x)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define lcase(a) (char)tolower(a)
#define ll long long int
#define lld long double
#define endl "\n"
#define PI 3.14159265358979323844
#define MOD 1000000007
#define max(a, b) (a < b ? b : a)
#define min(a, b) ((a > b) ? b : a)
#define mod 1e9 + 7
const int N = 1e5 + 5;
/*	For Debugging	*/
#define DEBUG 		cerr<<"\n>>>I'm Here<<<\n"<<endl;
#define display(x) trav(a,x) cout<<a<<" ";cout<<endl;
#define what_is(x)  cerr << #x << " is " << x << endl;
int a[1 << 18];string s[1 << 18];
int f[1<< 18],penalty[1 << 18];
int main()
{
   IOS

    int TESTS=1;
    //cin >> TESTS;
    while (TESTS--)
    {
    	int n,m;

    	cin>> n >> m;
    	for(int i=1;i<=m;i++)
		{
			cin>> a[i]>> s[i];
		if(s[i]=="AC")
			{
				f[a[i]]=1;
			}
			else if(f[a[i]]==0)
			{
				penalty[a[i]]++;
			}

		}
		ll sum1=0,sum2=0;
		for(int i=1;i<=n;i++)
		{
			sum1+=f[i];
			if(f[i]==1)
			{

				sum2+=penalty[i];
			}

		}
		cout<< sum1 <<" "<< sum2 << endl;




    }
    return 0;
}


Measured memory_bytes: 12940
/*
　　こんにちは。あたしはｶｳｶﾞｰﾙ。
　　RedcoderになるためAtCoderを巡る旅をしてます。

　　　 　＿_
　　　 ヽ|＿_|ノ　　　　ﾓｫ
　　　　||‘‐‘||ﾚ　　_)_, ―‐ 、
　　　　/(Ｙ (ヽ＿ /・ ヽ　　   ￣ヽ
　　　　∠ ＿ ゝ　 ｀^ヽ ﾉ.::::_(ノヽ
　　　　 _/ヽ　 　　  /ヽ￣￣￣/ヽ
*/

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define dump(x) cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl

#define rep(i, n) REP(i, 0, n)                  // 0, 1, ..., n-1
#define REP(i, x, n) for(int i = x; i < n; i++) // x, x + 1, ..., n-1
#define FOREACH(x, a) for(auto &(x) : (a))

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()

#define COUT(x) cout << (x) << endl

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 = 1e18;

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

    int N, K;
    cin >> N >> K;
    vector<int> a(N);
    rep(i, N) cin >> a[i];

    vector<ll> v(N + 1, 0);
    rep(i, N) v[i + 1] = v[i] + a[i];
    vector<ll> w(N + 1, 0);
    rep(i, N) w[i + 1] = w[i] + max(a[i], 0);

    ll ans = -INF;
    for(int i = 0; i + K <= N; i++) {
        ll tmp = w[N];
        tmp += max(v[i + K] - v[i], 0LL);
        tmp -= w[i + K] - w[i];
        ans = max(ans, tmp);
    }
    COUT(ans);
}


Measured memory_bytes: 2176
fn run() {
    let n: usize = {
        let mut s = String::new();
        std::io::stdin().read_line(&mut s).unwrap();
        s.trim().parse().unwrap()
    };
    let mut dp = vec![9 * n; n];
    dp[1] = 1;
    let mut deq = std::collections::VecDeque::new();
    deq.push_front((1, 1));
    while let Some((v, d)) = deq.pop_front() {
        if d > dp[v] {
            continue;
        }
        let u = 10 * v % n;
        if d < dp[u] {
            dp[u] = d;
            deq.push_front((u, d));
        }
        let u = (v + 1) % n;
        if d  + 1 < dp[u] {
            dp[u] = d + 1;
            deq.push_back((u, d + 1));
        }
    }
    println!("{}", dp[0]);
}

fn main() {
    run();
}


Measured memory_bytes: 6396
#include<bits/stdc++.h>
using namespace std;
#define all(a)  (a).begin(),(a).end()
typedef long long ll;
const ll mod=1000000007;
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)

int main() {
  int n;cin >> n;
  vector<int> a(n,-1);
  int cnt = 0;
  for(int i=0;i<n;++i){
    int t; cin >>t;
    a[i] = t-1;
    if(a[t-1] == i){
      ++cnt;
    }
  }
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 640
#include <stdio.h>

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

    if (n == 1) {
        printf("%d\n", m);
        return 0;
    }

    int gcd = 1;
    for (int i = 2; m / i >= n; i += 1) {
        if (m % i == 0) {
            gcd = i;
        }
    }

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


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const ll MOD = 1000000007;

int main(){
    vector<int> nums(5);
    for(int i=0;i<3;i++){
        cin >> nums[i];
    }

    for(int t=0;t<10000000;t++){
        for(int i=0;i<3;i++){
            if(nums[i] % 2 == 1){
                cout << t << endl;
                return 0;
            }
        }
        nums[3] = nums[0];
        nums[4] = nums[1];
        vector<int> nums_next(5);
        for(int i=0;i<3;i++){
            nums_next[i] = nums[i+1] / 2 + nums[i+2] / 2;
        }
        nums = nums_next;
    }
    cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 256
def main():
    n, *p = map(int, open(0).read().split())
    res = []
    tmp = False
    for i, j in enumerate(p, 1):
        if i == j:
            tmp = not tmp
            res.append(tmp)
        else:
            tmp = False

    ans = sum(res)
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 13940
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <cmath>
#include <cstring>
#define rep(i,n) for(int i=0;i<n;i++)
using ll =long long;
using namespace std;


int main() {
	int n, p;
	cin >> n >> p;
	string s;
	cin >> s;
	if (10 % p == 0) {
		ll ans = 0;
		rep(r, n) {
			if ((s[r] - '0') % p == 0) {
				ans +=r + 1;
			}
		}
		cout << ans << endl;
		return 0;
	}
	
	vector<int> d(n + 1);
	int ten = 1;
	for (int i = n - 1; i >= 0; --i) {
		int a = (s[i] - '0') * ten % p;
		d[i] = (d[i+1] + a) % p;
		ten *= 10;
		ten %= p;
	}

	vector<int>cnt(p);
	ll ans = 0;
	for (int i = n; i >=0; --i) {
		ans += cnt[d[i]];
		cnt[d[i]]++;
	}
	cout << ans << endl;
	return 0;

}

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

int main() {
	int N;
	cin>>N;
	for(int i=1; i<=9; i++){
		for(int j=1; j<=9; j++){
			if(i*j==N){
				cout<<"Yes"<<endl;
				return 0;
			}
		}
	}
	cout<<"No"<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
#define ld long double
#define pb push_back
#define all(x) x.begin(),x.end()
#define ff first
#define ss second
#define mod 1000000007
#define dbg if(debug)
using namespace std;
const bool debug = 0;

string s;
int d;
int dp[10005][100][2];

int solve(int i,int r,bool lt){
	if(i==s.length())
		return (r==0);
	int &ans = dp[i][r][lt];
	if(ans!=-1)
		return ans;
	ans = 0;
	if(lt){
		int x = 0;
		for(;x<s[i]-'0';++x){
			ans = (ans + solve(i+1,(r+x)%d,0))%mod;
		}
		ans = (ans + solve(i+1,(r+x)%d,1))%mod;
	}
	else{
		int x = 0;
		for(;x<10;++x){
			ans = (ans + solve(i+1,(r+x)%d,0))%mod;
		}
	}
	// cout<<i<<" : "<<lt<<" ::"<<ans<<'\n';
	return ans;
}

int main(){
	ios_base::sync_with_stdio(false); 
	cin.tie(NULL);cout.tie(NULL);
	
	cin>>s>>d;
	memset(dp,-1,sizeof dp);

	cout<<(mod+solve(0,0,1)-1)%mod;

	// cerr<< '\n' << "Time elapsed :" << clock() * 1000.0 / CLOCKS_PER_SEC << " ms\n" ;
	return 0;
}

Measured memory_bytes: 8960
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class Program
{
    static void Main(string[] args)
    {
            System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
            sw.Start();

            // 入力
            string sS = Console.ReadLine().Trim();
            int iN = int.Parse(sS);
            List<int> lstsS = new List<int>();
            for (int i = 0; i < iN; i++)
            {
                lstsS.Add(int.Parse(Console.ReadLine().Trim()));
            }
            //// debug
            //int iN = 100000;                                  // 10万件で検証
            //List<int> lstsS = new List<int>();
            //for (int i = 1; i <= iN; i++)
            //{
            //    lstsS.Add(i);
            //}

            // 解析
            lstsS.Sort();                                       // 昇順
            int iOut = 0;                                       // 存在奇数数
            int iBak = lstsS[0];                                // 比較元
            int iDup = 0;                                       // 重複数
            for (int i = 1; i < lstsS.Count; i++)
            {
                if (lstsS[i] == iBak) { iDup += 1; }
                else
                {
                    if (iDup % 2 == 0) { iOut += 1; }           // 存在奇数のみ加算
                    iDup = 0;
                    iBak = lstsS[i];
                }
            }
            if (iDup % 2 == 0) { iOut += 1; }                   // 存在奇数のみ加算

            //出力
            Console.WriteLine("{0}", iOut.ToString().Trim());

            sw.Stop();
#if DEBUG
            Console.WriteLine();
            Console.WriteLine("{0}", sw.Elapsed.ToString());
            Console.WriteLine("続行するには何かキーを押してください．．．");
            Console.ReadKey();
#endif
    }
}


Measured memory_bytes: 17452
S = input()
x,y = map(int,input().split())

if 'T' not in S:
    print('Yes' if x==len(S) and y==0 else 'No')
    exit()

sp = S.split('T')
x -= len(sp[0])

v_moves = []
h_moves = []
for i,s in enumerate(sp[1:]):
    if not s: continue
    if i%2==0:
        v_moves.append(len(s))
    else:
        h_moves.append(len(s))

if not h_moves:
    if x != 0:
        print('No')
        exit()
else:
    hs = set([0])
    for h in h_moves:
        tmp = set()
        for h2 in hs:
            tmp.add(h2 + h)
            tmp.add(h2 - h)
        hs = tmp
    if x not in hs:
        print('No')
        exit()

if not v_moves:
    if y != 0:
        print('No')
        exit()
else:
    vs = set([0])
    for v in v_moves:
        tmp = set()
        for v2 in vs:
            tmp.add(v2 + v)
            tmp.add(v2 - v)
        vs = tmp
    if y not in vs:
        print('No')
        exit()

print('Yes')


Measured memory_bytes: 3816
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define INF 1e9
// #define MOD 1e9+7

vector<vector<ll> > dp;
vector<vector<int> > arr;
int MOD = 1e9+7;
int main(){
	int m,n;cin>>m>>n;
	dp.resize(m+1,vector<ll>(n+1,0));
	arr.resize(m,vector<int>(n,0));
	for(int i=0;i<m;i++){
		string a;
		cin>>a;
		for(int j=0;j<n;j++){
			if(a[j]=='.') arr[i][j]=1;
		}
	}
	dp[m-1][n-1] = 1;
	for(int i=m-1;i>=0;i--){
		for(int j=n-1;j>=0;j--){
			if(arr[i][j]==0||(i==m-1&&j==n-1)) continue;
			dp[i][j] = dp[i+1][j]%MOD + dp[i][j+1]%MOD; 
		}
	}
	cout<<(dp[0][0]%MOD)<<endl;
}


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

using namespace std;

long long int N , T , L , B;

vector<vector<long double>>M;
vector<bool>Ls , Bs;

void saiki(long long int turn)
{
	for(long long int i = 0; i < N; i++)
	{
		for(long long int j = 1; j <= 6; j++)
		{
			long long int now = N - abs(i + j - N);
			if(Ls[now])
			{
				M[turn + 2][now] += M[turn][i] * 6L;
			} else if(Bs[now])
			{
				M[turn + 1][0] += M[turn][i];
			} else
			{
				M[turn + 1][now] += M[turn][i];
			}
		}
	}
	M[turn + 1][N] += M[turn][N] * 6L;
	if(turn < T)
	{
		saiki(turn + 1);
	}
}

int main()
{
	while(cin >> N >> T >> L >> B , N || T || L || B)
	{
		M.resize(T + 4);
		for(long long int i = 0; i < T + 4; i++)
		{
			M[i].resize(N + 1);
		}
		M[0][0] = 1L;
		Ls.resize(N + 1);
		Bs.resize(N + 1);
		for(size_t i = 0; i < L; i++)
		{
			long long int X;
			cin >> X;
			Ls[X] = true;
		}
		for(size_t i = 0; i < B; i++)
		{
			long long int Y;
			cin >> Y;
			Bs[Y] = true;
		}

		saiki(0);
		cout << fixed << setprecision(20) << M[T][N] * 1.L / powl(6L , T) << endl;

		M.clear();
		Ls.clear();
		Bs.clear();
	}
}

Measured memory_bytes: 1420
#include<bits/stdc++.h>
#define gc getchar
#define rint register int
#define rep(i,u,z) for(rint i=u;i<=z;++i)
#define reb(i,u,z) for(rint i=u;i>=z;--i)
#define inf 0x7fffffff

using namespace std;
typedef long long ll;

int n;
int cnts[110],ans,cur,big3[110],big5[110],big15[110],big25[110];
bool picked[110];
bool not_prime[1100];

inline int readint(){
	int rt=0,sign=1;
	char ch=gc();
	while(ch<'0'||ch>'9'){
		if(ch=='-')sign=-1;
	    ch=gc();
	}
	while(ch>='0'&&ch<='9'){
		rt=(rt<<3)+(rt<<1)+(ch&15);
		ch=gc();
	}
	return rt*sign;
}
inline void primit(){
	rep(i,2,n){
		if(!not_prime[i]){
			rep(j,2,n/i)not_prime[i*j]=true;
		}
	}
}
inline void dfs(int crt,int req1,int req2){
	if(crt>2){
		++cur;
		return;
	}
	if(crt==1){
		if(req1==3)rep(i,1,big3[0]){
			if(picked[big3[i]])continue;
			picked[big3[i]]=true;
			dfs(crt+1,req1,req2);
			picked[big3[i]]=false;
		}
		else if(req1==5)rep(i,1,big5[0]){
			if(picked[big5[i]])continue;
			picked[big5[i]]=true;
			dfs(crt+1,req1,req2);
			picked[big5[i]]=false;
		}
	}
	else{
		if(req2==25)rep(i,1,big25[0]){
			if(picked[big25[i]])continue;
			picked[big25[i]]=true;
			dfs(crt+1,req1,req2);
			picked[big25[i]]=false;
		}
		else if(req2==15)rep(i,1,big15[0]){
			if(picked[big15[i]])continue;
			picked[big15[i]]=true;
			dfs(crt+1,req1,req2);
			picked[big15[i]]=false;
		}
	}
}
inline void dfs(int crt){
	if(crt>3){
		++cur;
		return;
	}
	if(crt==1)rep(i,1,big3[0]){
		if(picked[big3[i]])continue;
		picked[big3[i]]=true;
		dfs(crt+1);
		picked[big3[i]]=false;
	}
	else rep(i,1,big5[0]){
		if(picked[big5[i]])continue;
		picked[big5[i]]=true;
		dfs(crt+1);
		picked[big5[i]]=false;
	}
}
int main(){
	n=readint();
	primit();
	rint sqr,emm;
	rep(i,2,n){
		emm=i;
		rep(j,2,i){
			while(emm%j==0)emm/=j,++cnts[j];
		}
	}
	rep(i,2,n){
		if(!not_prime[i]){
			if(cnts[i]>1){
				big3[++big3[0]]=i;
				if(cnts[i]>3){
					big5[++big5[0]]=i;
					if(cnts[i]>13){
						big15[++big15[0]]=i;
						if(cnts[i]>23){
							big25[++big25[0]]=i;
							if(cnts[i]>73)++ans;
						}
					}
				}
			}
		}
	}
	dfs(1,3,25);
	dfs(1,5,15);
	ans+=cur;
	cur=0;
	dfs(1);
	ans+=cur/2;
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 256
Scanf.scanf "%d" (fun n ->
    let a = Array.init n (fun _ -> Scanf.scanf " %d" (fun a -> a)) in

    let rec loop i acc =
        let calc i = Array.fold_left (fun acc v -> acc + (v - i) * (v - i)) 0 a in
        if i > 100 then acc else loop (i + 1) (min acc (calc i))
    in
    loop (-100) max_int |> Printf.printf "%d\n"
)

Measured memory_bytes: 3800
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <string>
#include <cmath>
#include <map>
#include <tuple>
#include <queue>
#include <stack>
#include <iomanip>

#define MOD (1000000007)
using namespace std;

typedef long long ll;

typedef tuple<ll, ll> tup; 


int main() {

    ll A, B, N;
    cin >> A >> B >> N;

    ll x =  min(B-1, N);

    cout << floor(A*x/B) - A*floor(x/B) << endl;


    return 0;
}


Measured memory_bytes: 3676
import java.util.ArrayList;
import java.util.Scanner;

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

		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int count = 0;

		ArrayList<Integer> num = new ArrayList<Integer>();

		for(int i = a; i <= b; i++) {
			num.add(i);
		}
		for(int loop : num) {
			if(c % loop == 0) {
				count++;
			}
		}
		System.out.println(count);
	}
}



Measured memory_bytes: 26972
<?php
fscanf(STDIN, "%d %d", $N, $Q);
fscanf(STDIN, "%s", $S);
$ans = [];
$sum = array_pad(array(), $N, 0);
for ($i = 1; $i < $N; $i++) {
    $sum[$i] = $sum[$i - 1] + ($S[$i - 1] . $S[$i] === 'AC');
}
for ($i = 0; $i < $Q; $i++) {
    fscanf(STDIN, "%d %d", $l, $r);
    $ans[] = $sum[$r - 1] - $sum[$l - 1];
}
echo implode(PHP_EOL, $ans);


Measured memory_bytes: 15476
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
using ll = long long;
const ll INF = ll(1e18) + 1;
typedef pair<int,int> P;// pair型は２つの値の組を表せる

int main(){
    int N,R; cin >> N >> R;
    if (N>=10){
        cout << R << endl;
        return 0;
    }
    else{
        cout << R+(10-N)*100;
        return 0;
    }
}


Measured memory_bytes: 256
N = int(input()) #目的
H =[int(i) for i in input().split()]

flug = 0
for index in range(1,N):
  if int(H[index]- H[index - 1]) < -1 :
    print("No")
    flug = 1
    break
  else:
    if int(H[index] < H[index - 1]):
      H[index] = H[index-1]
   # print(H[index])
    continue
if flug == 0:
  print("Yes")

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

using namespace std;
typedef long long ll;
#define rep(i, s, e) for (int(i) = (s); (i) <= (e); ++(i))
#define all(x) x.begin(),x.end()


int main()
{
    int n;cin>>n;
    vector<int> h(n);
    rep(i,0,n-1)cin>>h[i];
    vector<int> dp(100100, 1001001001);
    dp[0] = 0;
    rep(i,0,n-1){
        dp[i+1]=min(dp[i+1], dp[i]+abs(h[i]-h[i+1]));
        dp[i+2]=min(dp[i+2], dp[i]+abs(h[i]-h[i+2]));
    }
    cout<<dp[n-1]<<endl;
}


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

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

	int five_hundred_yen = 0;
	int five_yen = 0;

	five_hundred_yen = x / 500;
	x %= 500;
	five_yen = x / 5;

	cout << five_hundred_yen * 1000 + five_yen * 5 << endl;
}


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

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)n; ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cout<<*i<<" "; cout<<endl; }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
struct edge{
  int to, cap, rev;
  edge(){}
  edge(int to, int cap, int rev):
    to(to), cap(cap), rev(rev) {}
};
typedef vector<edge> edges;
int gcd(int m,int n){
  return (m%n)?gcd(n, m%n):n;
}
void add_edge(vector<edges>& g, int from, int to, int cap){
  g[from].push_back(edge(to, cap, g[to].size()));
  g[to].push_back(edge(from, 0, g[from].size()-1));
}
bool used[1002];
int dfs(vector<edges>& g, int u, int end, int f){
  if(u == end) return f;
  used[u] = true;
  REP(i,g[u].size()){
    edge& e = g[u][i];
    if(used[e.to] || e.cap <= 0) continue;
    int t = dfs(g, e.to, end, min(f,e.cap));
    if(t > 0){
      e.cap -= t;
      g[e.to][e.rev].cap += t;
      return t;
    }
  }
  return 0;
}
int maxflow(vector<edges>& g, int s, int e){
  int res = 0;
  while(true){
    memset(used, 0, sizeof(used));
    int f = dfs(g, s, e, 1);
    if(f == 0) return res;
    else res += f;
  }
  return -1;
}

int main(){
  int m,n;
  while(cin>>m>>n,m||n){
    vector<int> v1(m);
    vector<int> v2(n);
    REP(i,m)cin>>v1[i];
    REP(i,n)cin>>v2[i];
    const int start = m + n;
    const int end = m + n + 1;;
    vector<edges> graph(end + 1);
    REP(i,m)add_edge(graph, start, i, 1);
    REP(i,n)add_edge(graph, m + i, end, 1);
    REP(i,m)REP(j,n)if(gcd(v1[i],v2[j])!=1){
      add_edge(graph, i, m + j, 1);
    }
    cout<<maxflow(graph,start,end)<<endl;
  }
  return 0;
}

Measured memory_bytes: 5292
#encoding:utf-8 No.0075 2014.10.8
student = []
while gets
  student.push $_.chomp.split(/,/).map{|item| item.to_f}
end

judge = 0
student.length.times do |i|
  if student[i][1]/(student[i][2]**2) >= 25.0
    puts student[i][0].to_i
    judge += 1
  end
end

if judge == 0
  puts "該当なし"
end

Measured memory_bytes: 6128
S = input()
T = input()
num = 0
S = sorted(S)
T = sorted(T,reverse=True)
while num < min(len(S),len(T)):
    if  S[num] < T[num]:
        print('Yes')
        break
    elif S[num] > T[num]:
        print('No')
        break
    num += 1
if num == len(T):
    print('No')
elif num == len(S):
    print('Yes')

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <map>
#include <algorithm>

using namespace std;

int main() {
    map<char, string> mp;
    string pa,pb,pc;
    
    cin >> pa;
    cin >> pb;
    cin >> pc;
    
    mp['a'] = pa;
    mp['b'] = pb;
    mp['c'] = pc;
    
    char turn = 'a';
    char next;
    string answer;
    
    while(true){
        if(mp[turn].empty()){
            answer = turn;
            break;
        }else{
            next = mp[turn][0];
            mp[turn].erase(mp[turn].begin());
            turn = next;
        }
    }
    
    transform(answer.begin(), answer.end(), answer.begin(), ::toupper);
    
    cout << answer << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
long double pi = 2 * acos(0.0);
const ll mod = 1e9 + 7;

void solve() {
    ll n;
    cin >> n;
    if(n >= 30) cout << "Yes\n";
    else cout << "No\n";
}       

int main() {
    ios_base :: sync_with_stdio(false); 
    cin.tie(nullptr);   
    ll t = 1;
    //cin >> t;
    while(t--) {
        solve();
    }
    return 0;
}


Measured memory_bytes: 3636
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
#include<iomanip>
#include<list>
#include<deque>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define DEB2(X) cout<<X<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define DEB2(X) {}
#define END {}
#endif
typedef long long ll;
#define int ll
#define uset unordered_set
#define umap unordered_map
//typedef std::pair<int,int> P;
struct edge{int to,cost;};
const int INF=100000000000000000;
const int INF2=9223372036854775807;
const int MOD=1000000007;
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define min(X,Y) (((int)(X)<(int)(Y))?(X):(Y))
#define max(X,Y) (((int)(X)>(int)(Y))?(X):(Y))
#define NP(X,Y) next_permutation(X,Y)
#define setdouble(X,Y) cout<<fixed<<setprecision(X)<<Y
int ceil2(int a,int b){if(a%b==0){return a/b;}else{return a/b+1;}}
int pow2(int a,int b){int r=1;for(int i=1;i<=b;i++){r*=a;}return r;}
int Log2(int a){int t=0;while(1){if(a==0||a==1){break;}a/=2;t++;}return t;}

int A,B,M;
int a[100010],b[100010],x[100010],y[100010],c[100010];

signed main(){
	cin>>A>>B>>M;
	int m=INF;
	int m2=INF,m3=INF;
	REP(i,A){
		cin>>a[i];
		m2=min(m2,a[i]);
	}
	REP(i,B){
		cin>>b[i];
		m3=min(m3,b[i]);
	}
	m=m2+m3;
	REP(i,M){
		cin>>x[i]>>y[i]>>c[i];
		x[i]--,y[i]--;
		m=min(m,a[x[i]]+b[y[i]]-c[i]);
	}
	cout<<m<<endl;
	
	return 0;
}


Measured memory_bytes: 4096
#include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <vector>

const int MOD = 1e9 + 7;
const int iINF = 2147483647 / 2;
const long long int llINF = 9223372036854775807 / 2;

using namespace std;
using ll = long long int;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vvvl = vector<vector<vector<ll>>>;

typedef pair<ll, ll> pll;
bool paircomp(const pll &a, const pll &b) {
  if (a.first == b.first)
    return a.second < b.second;
  return a.first < b.first;
}

#define REP(i, n) for (ll i = 0; i < (n); i++)
#define RREP(i, n) for (ll i = (n)-1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define AUTO(i, m) for (auto &i : m)
#define ALL(a) (a).begin(), (a).end()
#define MAX(vec) *std::max_element(vec.begin(), vec.end())
#define MIN(vec) *std::min_element(vec.begin(), vec.end())
#define ARGMAX(vec)                                                            \
  std::distance(vec.begin(), std::max_element(vec.begin(), vec.end()))
#define ARGMIN(vec)                                                            \
  std::distance(vec.begin(), std::min_element(vec.begin(), vec.end()))
#define REV(T) greater<T>()
#define PQ(T) priority_queue<T, vector<T>, greater<T>>
#define VVL(a, b, c) vector<vector<ll>>(a, vector<ll>(b, c))
#define VVVL(a, b, c, d)                                                       \
  vector<vector<vector<ll>>>(a, vector<vector<ll>>(b, vector<ll>(c, d)))
#define SP(a) setprecision(a)
#define SQRT(a) sqrt((long double)(a))
#define DPOW(a, b) pow((long double)(a), (long double)(b))
#define UNIQUE(vec)                                                            \
  do {                                                                         \
    sort(ALL((vec)));                                                          \
    (vec).erase(std::unique(ALL((vec))), (vec).end());                         \
  } while (0)

ll POW(ll n, ll m) {
  if (m == 0) {
    return 1;
  } else if (m % 2 == 0) {
    ll tmp = POW(n, m / 2);
    return (tmp * tmp);
  } else {
    return (n * POW(n, m - 1));
  }
}

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

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll N;
  cin >> N;
  vvl A = VVL(N, N, 0);
  vl DP(POW(2, N), 0);
  REP(i, N) {
    REP(j, N) { cin >> A[i][j]; }
  }

  vl COUNT(POW(2, N), 0);
  REP(k, POW(2, N)) {
    ll po = k;
    while (po > 0) {
      if (po % 2 == 1)
        COUNT[k]++;
      po /= 2;
    }
    // cout << COUNT[k] << endl;
  }

  DP[0] = 1;
  REP(i, N) {
    vl DP2 = DP;
    REP(j, POW(2, N)) {
      if (COUNT[j] != i + 1)
        continue;
      REP(k, N) {
        if (A[i][k] == 0 || (j >> k) == 0)
          continue;
        DP2[j] += DP[j - (1 << k)];
        DP2[j] %= MOD;
      }
    }
    DP = DP2;
  }
  cout << DP[POW(2, N) - 1] << endl;
  return 0;
}


Measured memory_bytes: 49408
N = int(input())
B = list(map(int,input().split()))

A = []
A.append(B[0])

for i in range(N-1):
    if i != 0:
        A.append(min(B[i-1],B[i]))
    if i == N-2:
        A.append(B[i])
print(sum(A))


Measured memory_bytes: 2940
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
int dx[4]={1,0,-1,0} , dy[4]={0,1,0,-1} ;

struct edge{int to;int cap;int rev;};
struct Dinic{
private:
    int n;
    vector<vector<edge>> v;
    vector<int> dist,iter;
public:
    Dinic(int sz):n(sz),v(sz),dist(sz),iter(sz){}
    
    void addedge(int from,int to,int cap){
        int x=v[to].size(),y=v[from].size();
        v[from].push_back({to,cap,x});
        v[to].push_back({from,0,y});
    }
    
    void bfs(int s){
        fill(dist.begin(),dist.end(),-1);
        queue<int> q;
        dist[s]=0;
        q.push(s);
        while(q.size()){
            int x=q.front();q.pop();
            rep(i,v[x].size()){
                edge &e=v[x][i];
                if(e.cap>0&&dist[e.to]<0){
                    dist[e.to]=dist[x]+1;
                    q.push(e.to);
                }
            }
        }
    }
    
    int dfs(int x,int t,int f){
        if(x==t)return f;
        for(int& i=iter[x];i<(int)v[x].size();++i){
            edge& e=v[x][i];
            if(e.cap>0&&dist[x]<dist[e.to]){
                int d=dfs(e.to,t,min(f,e.cap));
                if(d>0){
                    e.cap-=d;
                    v[e.to][e.rev].cap+=d;
                    return d;
                }
            }
        }
        return 0;
    }

    int max_flow(int s,int t){
        int flow=0;
        while(1){
            bfs(s);
            if(dist[t]<0)return flow;
            fill(iter.begin(),iter.end(),0);
            int f;
            while((f=dfs(s,t,(1LL<<31)-1))>0)flow+=f;
        }
    }
};

int main(){
    int h,w;
    cin>>h>>w;
    Dinic dn(h+w+2);
    string s[h];
    rep(i,h){
        cin>>s[i];
        rep(j,w){
            if(s[i][j]=='S'){
                dn.addedge(h+w, i, inf);
                dn.addedge(h+w, h+j, inf);
            }
            if(s[i][j]=='T'){
                dn.addedge(i,h+w+1, inf);
                dn.addedge(h+j,h+w+1, inf);
            }
            if(s[i][j]=='o'){
                dn.addedge(i, h+j, 1);
                dn.addedge(h+j, i, 1);
            }
        }
    }
    int ans=dn.max_flow(h+w, h+w+1);
    cout<<(ans>=inf?-1:ans)<<endl;
   return 0;
}


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

int main() {
  int N;
  cin >> N;
  vector<int> H(N);
  
  for(int i = 0; i < N; i++){
    cin >> H.at(i);
  }
  int max = 0;
  string str = "Yes";
  for(int i = 0; i < N; i++){
    if (max - 1 > H.at(i)) {
      str = "No";
    }
    if (max < H.at(i)) {
      max = H.at(i);
    }
  }
  
  cout << str;
}

Measured memory_bytes: 640
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cassert>
#include<vector>
#define ll long long
using namespace std;
inline int read(){
	int re=0,flag=1;char ch=getchar();
	while(ch>'9'||ch<'0'){
		if(ch=='-') flag=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9') re=(re<<1)+(re<<3)+ch-'0',ch=getchar();
	return re*flag;
}
char ss[100010];
int n,a[100010];
vector<int>s;
vector<int>e[100010]; 
int main(){
	int i;
	scanf("%s",ss);n=strlen(ss);
	for(i=0;i<n;i++) a[i+1]=(ss[i]=='1');
	for(i=1;i<n;i++){
		if(!a[i]) continue;
		if(!a[n-i]){
			puts("-1");return 0;
		}
		if(i<=n-i) s.push_back(i);
	}
	if(a[1]!=1||a[n]==1){
		puts("-1");return 0;
	}
	int top=1,cnt=1;
	for(i=1;i<s.size();i++){
		int num=s[i]-s[i-1]-1;
		cnt++;e[cnt].push_back(top);top=cnt;
		while(num) cnt++,e[top].push_back(cnt),num--;
	}
	cnt++;e[cnt].push_back(top);top=cnt;
	while((++cnt)<=n) e[top].push_back(cnt);
	for(i=1;i<=n;i++){
		for(auto u:e[i]){
			printf("%d %d\n",i,u);
		}
	}
}

Measured memory_bytes: 6268
#include<iostream>

#include<queue>

#include<string.h>

using namespace std;

priority_queue<string,vector<string>,greater<string> >q;
int main()
{
    int n,m;
    cin>>n>>m;
    for(int i=0;i<n;i++)
    {
        string ch;
        cin>>ch;
        q.push(ch);
    }
    for(int i=0;i<n;i++)
    {
        string b=q.top();
        cout<<b;
        q.pop();
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N, M, L[100000], R[100000], X, Y;
  cin >> N >> M >> L[1] >> R[1];
  
  if(M>1){
  for(int i=2; i<(M+1); i++){
    cin >> L[i] >> R[i];
    X=max(L[i-1], L[i]);
    Y=min(R[i-1], R[i]);
    L[i]=X;
    R[i]=Y;
  }
  if(Y<X){
    cout << 0 << endl;
  }
    if(Y>X || Y==X){
      cout << Y-X+1 << endl;
    }
  }
  
  if(M==1){
    cout << R[1]-L[1]+1 << endl;
  }
}


Measured memory_bytes: 1024
// #include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<cstdlib>
#include<algorithm>
#define pb emplace_back
#define LOCAL
  
using namespace std;
  
const int inf = 0x3f3f3f3f;
const int maxn = 1e5+5;
typedef long long ll;
typedef pair<int,int> Pii;
 
template <typename T>inline void read(T& t){
    char c=getchar();t=0;
    int f=1;
    while(!isdigit(c)){
       if(c=='-')f=-1;
        c=getchar();
    }
    while(isdigit(c))t=t*10+c-48,c=getchar();
    t=f*t;
}
  
template <typename T,typename... Args> inline void read(T& t,Args&... args){
    read(t);read(args...);
}

int r,c,k;
int mps[3005][3005];
ll dp[3005][3005][5];
  
int main(){
    int t=1;
    // read(t);
    while(t--){
        read(r,c,k);
        for(int i=1;i<=k;i++){
            int x,y,z;
            read(x,y,z);
            mps[x][y]=z;
        }
        for(int i=1;i<=r;i++){
            for(int j=1;j<=c;j++){
                if(!mps[i][j]){
                    for(int k=0;k<4;k++){
                        dp[i][j][k]=max(dp[i][j][k],dp[i][j-1][k]);
                        dp[i][j][0]=max(dp[i][j][0],dp[i-1][j][k]);
                    }
                }else{
                    for(int k=1;k<4;k++){
                        dp[i][j][k]=max(max(dp[i][j][k],dp[i][j-1][k]),dp[i][j-1][k-1]+mps[i][j]);
                    }
                    for(int k=0;k<4;k++){
                        dp[i][j][0]=max(dp[i][j][0],dp[i-1][j][k]);
                        dp[i][j][1]=max(dp[i][j][1],dp[i-1][j][k]+mps[i][j]);
                    }
                }
            }
        }
        ll ans=0;
        for(int i=0;i<4;i++){
            ans=max(ans,dp[r][c][i]);
        }
        printf("%lld\n",ans);
    }
    return 0;
}

Measured memory_bytes: 390328
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)
#define VL vector<ll>
#define VS vector<string>
#define VB vector<bool>
#define VP vector<pair<ll,ll>>
#define VVL vector<vector<ll>>
#define VVP vector<vector<pair<ll,ll>>>
#define PL pair<ll,ll>
#define ALL(v) (v).begin(), (v).end()
ll d1[4] = {1, -1, 0, 0};
ll d2[4] = {0, 0, 1, -1};

int main(){
    string s, t;
    cin >> s >> t;
    ll ans = 0;
    rep(i, 0, s.size()){
        if(s[i] != t[i]) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3856
#include<bits/stdc++.h>
const int mo=1000000007;
const int N=200005;
using namespace std;
struct edge{
	int to,next;
}e[N*4];
int tot,head[N];
int a[N],b[N],mx[N];
int n,nx,ny,mx1,mx2,inv[N];
int q[N],qn,cnt,g[N],ans;
int Min(int x,int y){
	return b[x]<b[y]?x:y;
}
void merge(int x,int y){
	e[++tot]=(edge){y,head[x]};
	head[x]=tot;
	e[++tot]=(edge){x,head[y]};
	head[y]=tot;
}
void dfs(int x){
	cnt++;
	ans=1ll*ans*cnt%mo;
	if (!(g[a[x]]++)) q[++qn]=a[x];
	a[x]=0;
	for (int i=head[x];i;i=e[i].next)
		if (a[e[i].to]) dfs(e[i].to);
}
int main(){
	scanf("%d%d%d",&n,&nx,&ny);
	b[0]=1e9+1;
	for (int i=1;i<=n;i++){
		scanf("%d%d",&a[i],&b[i]);
		mx[a[i]]=Min(mx[a[i]],i);
	}
	for (int i=1;i<=n;i++)
		if (b[mx[i]]<b[mx1]) mx2=mx1,mx1=mx[i];
		else if (b[mx[i]]<b[mx2]) mx2=mx[i];
	for (int i=1;i<=n;i++){
		if (i!=mx[a[i]]&&b[i]+b[mx[a[i]]]<=nx)
			merge(i,mx[a[i]]);
		if (a[i]==a[mx1]){
			if (b[i]+b[mx2]<=ny)
				merge(i,mx2);
		}
		else
			if (b[i]+b[mx1]<=ny)
				merge(i,mx1);
	}
	inv[0]=inv[1]=1;
	for (int i=2;i<=n;i++)
		inv[i]=1ll*(mo-mo/i)*inv[mo%i]%mo;
	for (int i=1;i<=n;i++)
		inv[i]=1ll*inv[i-1]*inv[i]%mo;
	ans=1;
	for (int i=1;i<=n;i++)
		if (a[i]){
			qn=cnt=0;
			dfs(i);
			for (int j=1;j<=qn;j++)
				ans=1ll*ans*inv[g[q[j]]]%mo,g[q[j]]=0;
		}
	printf("%d",ans);
}

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

int n,m,sum,a[105],cnt;

int main(){

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

    cin>>n>>m;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        sum+=a[i];
    }
    for(int i=1;i<=n;i++){
        cnt+=4*m*a[i]>=sum;
    }
    cout<<(cnt>=m?"Yes":"No")<<endl;

    return 0;
}

Measured memory_bytes: 256