akhauriyash/Code-Regression huggingface dataset:
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#ifdef __GXX_EXPERIMENTAL_CXX0X__
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#ifdef __GXX_EXPERIMENTAL_CXX0X__
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif
 size_t strlen(const char *s);
#define rep(i,n) for(long long int i=0;i<n;i++)
#define sz(x) ((int)(x).size())

using namespace std;
struct ToUpper {
    char operator()(char c) { return toupper(c); }
};
struct ToLower {
    char operator()(char c) { return tolower(c); }
};
const int N=200010;
const int P=1000000007;
using ll = long long;

//絶対値
int ze(int a, int b){
	if(a>b){
		return a-b;
	}else{
		return b-a;
	}
}
//小さい方
long long int min(long long int a,long long int b){
	if(a>b){
		return b;
	}else{
		return a;
	}
}
//大きい方
long long int max(long long int a,long long int b){
	if(a>b){
		return a;
	}else{
		return b;
	}
}
// a^n mod 
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

// a^{-1} mod 
long long modinv(long long a, long long mod) {
    return modpow(a, mod - 2, mod);
}

//mod掛け算
long long mt(long long a, long long b, long long mod){
	return (a*b)%mod;
}

//メモ

/*
	memset(b, '\0', sizeof(b));
初期化*/

/*
	char s[N];
	strlen(s)
*/

/*
	if(  <  )puts("Yes");
	else puts("No");
*/

/*文字列比較
if(strcmp(name[i],s)==0)
*/

/*
	graph[a].push_back(b);//graph[a][i番目に入れた]==b
	graph[j].size()	//forで回すときとか

*/

/*添字1がa個、2がb個
  vector<vector<ll>> map(a,vector<ll>(b));
*/

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



	cout<<a+a*a+a*a*a        <<endl;


}



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

using namespace std;

int main() {
  vector<int> first{1, 2, 3, 4, 5, 6, 7, 8, 9};
  vector<int> second{1, 2, 3, 4, 5, 6, 7, 8, 9};

  int N;

  cin >> N;

  if (81 < N) {
    goto NO;
  } else {
    for (auto &f : first) {
      for (auto &s : second) {
        if (N == f * s) {
          goto YES;
        }
      }
    }
    goto NO;
  }
YES:
  cout << "Yes" << endl;
  return 0;
NO:
  cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
	int a,b,c,d,e,f,sum;
	scanf("%d %d %d %d %d %d",&a,&b,&c,&d,&e,&f);
	sum=a+b*5+c*10+d*50+e*100+f*500;
	if(sum>=1000){
		printf("1\n");
	}
	else{
		printf("0\n");
	}
	return 0;
}



Measured memory_bytes: 2148
#include <cstdio>
#include <algorithm>

using namespace std;

const long long INF = 2e12;

int main() {
  int a, b, c, x, y;
  int i;
  scanf("%d %d %d %d %d", &a, &b, &c, &x, &y);
  long long ans = INF;
  for (i = 0; i <= max(x, y); i++) {
    long long ans_now = max(0, (x-i))*a + max(0, (y-i))*b + 2*i*c;
    ans = min(ans_now, ans);
  }
  printf("%lld", ans);
  return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include<cstdlib>
#include<queue>
#include<set>
#include<vector>
#include<string>
#include<algorithm>
#include<stack>
#include<map>
#include<deque>
#include<cstdio>
using namespace std;
#define rep(i,a) for(int i=0;i<a;i++)
#define mp make_pair
#define pb push_back
//#define ll __int64
#define ll long long
#define P pair<ll,ll>

int k;
deque<P>bfs;
bool v[200000];

int main(){
	cin>>k;
	bfs.push_back(mp(1,1));

	rep(i,1000000000){
		P tmp=bfs.front();
		bfs.pop_front();
		//cout<<tmp.first<<" "<<tmp.second<<endl;
		if(v[tmp.second])continue;
		v[tmp.second]=1;
		bfs.push_back(mp(tmp.first+1,(tmp.second+1%k)));
		bfs.push_front(mp(tmp.first,(tmp.second*10)%k));

		if(tmp.second%k==0){
				cout<<tmp.first<<endl;
				return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 2048
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using Map = map<string,ll>;
using vl = vector<ll>;
using vvp = vector<vector<P>>;


ll INF=100000000;

//d[i]は1からiまでの距離
vector<ll> d(100008,INF);

void dfs(ll x,vvp &next){
    for(ll i=0;i<next[x].size();i++){
        if(d[next[x][i].first]==INF){
            d[next[x][i].first]=d[x]+next[x][i].second;
            dfs(next[x][i].first,next);
        }
    ;}
}

int main(){
    ll N;
    cin >> N;
    vector<ll> u(N-1,0);
    vector<ll> v(N-1,0);
    vector<ll> w(N-1,0);
    for(ll i=0;i<N-1;i++){
        cin>>u[i]>>v[i]>>w[i]
    ;}
    vector<vector<P>> next(N+1, vector<P>(0));
    for(ll i=0;i<N-1;i++){
        next[u[i]].emplace_back(P(v[i],w[i]));
        next[v[i]].emplace_back(P(u[i],w[i]));
    ;}
    d[1]=0;
    dfs(1,next);
    for(ll i=0;i<N;i++){
        if(d[i+1]%2==1)cout<<0<<endl;
        else cout<<1<<endl;
    ;}

    return 0;
}


Measured memory_bytes: 12288
#include <algorithm>
#include <cstring>
#include <iostream>
#include <vector>
#include <cmath>
#include <math.h>
#include <stdio.h>
#include <iomanip>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <string>
#define rep(i,n) for (int i = 0; i < (n); ++i)

using namespace std;
const int MOD = 1000000007;


typedef long long int ll; 
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;

void floatOutPutSetup(){
    cout << fixed;
    cout << setprecision(10);
}

int main(){
    ll a,b,k;
    cin >> a >> b >> k;
    cout << max(ll(0),a-k)<< " ";
    cout << max(ll(0), min(a+b-k,b) );


    return 0;
}

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


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
inline int read(){
    int x=0,f=0;char ch=getchar();
    while(!isdigit(ch))f|=ch=='-',ch=getchar();
    while(isdigit(ch))x=x*10+(ch^48),ch=getchar();
    return f?-x:x;
}
inline void Yeah(){puts("Yes");exit(0);}
int main(){ 
    int n=read(),m=read(),k=read();
    for(int i=1;i<=n;++i){
        int kk=(k-i*m),a=n-i-i;
        if(!kk || a && (kk>>31&1)==(a>>31&1) && kk%a==0 && kk/a<=m)Yeah();
    }
    puts("No");
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int N;
  cin >> N;
  int X=0, Y=0;
  
  for(int i=0; i<N; i++){
    int H;
    cin >> H;
    
    if(H<Y)
      continue;
    
    X++;
    Y=H;
  }
  
  cout << X << endl;
}


Measured memory_bytes: 384
import collections
import sys

readline = sys.stdin.buffer.readline


def main():
    N = int(readline())
    A = list(map(int, readline().split()))
    B = list(range(1, N + 1))

    C = collections.defaultdict(int)
    for a, b, in zip(A, B):
        a, b = min(a, b), max(a, b)
        C[(a, b)] += 1

    D = collections.Counter(C.values())
    print(D[2])


main()


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

int main(void){
  int H, W;
  int **a;
  cin >> H >> W;
  a = new int*[H];
  for (int i = 0; i < H;i++){
    a[i] = new int[W];
  }
  for (int y = 0; y < H;y++){
    for (int x = 0; x < W;x++){
      char c;
      cin >> c;
      if(c=='.'){
        a[y][x] = 0;
      }else if(c=='#'){
        a[y][x] = 1;
      }
    }
  }

  vector<int> passH, passW;
  
  // 縦探索
  for (int y = 0; y < H;y++){
    bool flag = true;

    for (int x = 0; x < W;x++){
      if(a[y][x]==1){
        flag = false;
      }
    }

    if(flag==true){
      passH.push_back(y);
    }
  }

  // 横探索
  for (int x = 0; x < W; x ++){
    bool flag = true;

    for (int y = 0; y < H; y++){
      if (a[y][x] == 1){
        flag = false;
      }
    }

    if (flag == true){
      passW.push_back(x);
    }
  }



  // 無視する行以外を出力する
  for (int y = 0; y < H;y++){
    bool passY = false;
    
    for(auto index : passH){
      if(y==index){
        passY = true;
        break;
      }
    }

    if(passY==true){
      continue;
    }

    for (int x = 0; x < W;x++){
      bool passX = false;

      for(auto index : passW){
        if(x==index){
          passX = true;
          break;
        }
      }

      if(passX==true){
        continue;
      }

      cout << (a[y][x] == 0 ? '.' : '#');
    }
    cout << endl;
  }
}


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

int main() {
  int r;
  cin >> r;
  cout << r*r << endl;
}


Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	S := getStdin()
	T := getStdin()

	flag := true
	for i := 0; i < len(S); i++ {
		if S[i] != T[i] {
			flag = false
			break
		}
	}

	if flag {
		fmt.Printf("Yes\n")
	} else {
		fmt.Printf("No\n")
	}
}

func getStdin() string {
	sc.Scan()
	return sc.Text()
}
func getStdinInt() int {
	str := getStdin()
	rtn, _ := strconv.Atoi(str)
	return rtn
}
func getStdinIntArr() []int {
	str := getStdin()
	list := strings.Split(str, " ")
	rtn := make([]int, len(list))
	for idx, val := range list {
		rtn[idx], _ = strconv.Atoi(val)
	}
	return rtn
}


Measured memory_bytes: 1756
#include <bits/stdc++.h>
using namespace std;
string s;
long long rec(long long idx,long long out,long long val)
{
	if(idx==s.size())
		return (out*(val==0));
	return (rec(idx+1,out,val*10+s[idx]-'0')+rec(idx+1,out+val*10+s[idx]-'0',0));
}
int main()
{
	cin>>s;
	cout<<rec(0,0,0)<<"\n";
 	return 0;
}


Measured memory_bytes: 256
def main():
	s = input()
	ans = ["-1", "-1"]
	for i in range(len(s)-1):
		if s[i] == s[i+1]:
			ans = [str(i+1), str(i+2)]
			break
		if i == len(s)-2:
			break
		if s[i] == s[i+2]:
			ans = [str(i+1), str(i+3)]
			break
	print(" ".join(ans))


if __name__ == '__main__':
	main()

Measured memory_bytes: 3188
#include<bits/stdc++.h>
    #define F first
    #define S second
    using ll = long long;
    const ll mod = 1000000007;
    const ll infi = 1000000000000000;
    const ll md = 998244353;
    using namespace std;
    using vl = vector<ll>;
    using pll =  pair<ll,ll>;
     

    int main() {
        int ans=0;
        string s;
        cin>>s;
        string a[s.size()][2];
        int dp[s.size()][2]={0};
        if(s.size()==1){
            cout<<1;
            return 0;
        }
        a[0][1]="";
        for(int i=0;i<s.size();i++){
           a[i][0] = s[i];
           if(i!=0) {a[i][1] = (s[i-1]);a[i][1]+=s[i];}
        }
        dp[0][0] =1;
        dp[1][1] = 1;
        for(int i=1;i<s.size();i++){
            if(i>1)dp[i][1]=max(dp[i-2][0]+1,dp[i][1]);
            dp[i][0]=max(dp[i-1][1]+1,dp[i][0]);
            if(a[i][0]!=a[i-1][0]) dp[i][0]=max(dp[i-1][0]+1,dp[i][0]);
            if(i>1) {if(a[i][1]!=a[i-2][1]) dp[i][1]=max(dp[i-2][1]+1,dp[i][1]);}
        }
        cout<<max(dp[s.size()-1][0],dp[s.size()-1][1]);
        return 0;
    } 

Measured memory_bytes: 23940
#include <iostream>
#include <tuple>
#include <utility>
#include <algorithm>
#include <vector>
using namespace std;

int main () { 
  int n, c;
  cin >> n >> c;
  vector<tuple<int, int, int> > all;
  int s, ss, sss;
  for (int i = 0; i < n; i++) {
    cin >> s >> ss >> sss;
    all.push_back(make_tuple(s, ss, sss));    
  }  
  sort(all.begin(), all.end());
  /*
  for (int i = 0; i < n; i++) {
    cout << get<0>(all[i]) << " " << get<1>(all[i]) << " " << get<2>(all[i]) << endl;  
  }
  */
  vector<pair<int, int> > ans;
  ans.push_back(make_pair(0, 0));
  int ch, t;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < ans.size(); j++) {
      ch = ans[j].first;
      t  = ans[j].second;
      if (ch == get<2>(all[i])) {
        if (t <= get<0>(all[i])) {
          ans[j].second = get<1>(all[i]);
          break;  
        }  
      }     
      else {
        if ((float) (t + 0.5) <= (float) get<0>(all[i])) {
          ans[j].first = get<2>(all[i]);
          ans[j].second = get<1>(all[i]);
          break;    
        }  
      } 
      if (j == ans.size() - 1) {
        ans.push_back(make_pair(get<2>(all[i]), get<1>(all[i]) ));
        break;  
      }
    }  
  }
  cout << ans.size() << endl;
}

Measured memory_bytes: 1912
def bubbleSort(A, N):
    swap_count = 0
    flag = True
    while flag:
        flag = False
        for j in range(N-1, 0, -1):
            if A[j] < A[j-1]:
                A[j], A[j-1] = A[j-1], A[j]
                flag = True
                swap_count += 1
    return swap_count

n = int(input())
A = list(map(int, input().split()))
count = bubbleSort(A,n)
print(*A)
print(count)

Measured memory_bytes: 7760
#include<bits/stdc++.h>
using namespace std;
typedef long long l;
l o=0,ans=1;
bool ok=0,w[5000005];
int main()
{
	l n,k;
	cin>>n>>k;
	if(n==1)
	{
		cout<<k<<endl;
		return 0;
	}
	for(int i=2;ok==0;i++)
	{
		if(i*i>k)
			break;
		if(w[i]==1)
			continue;
		o=1;
		for(int c=0;c<n;c++)
		{
			o=o*i;
			if(o>k)
			{
				ok=1;
				break;
			}
		}
		if(k%o==0)
			ans=i;
		else
			for(l d=i;d<5000005;d+=i)
				w[d]=1;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 5120
total_card = []
for flower in 'SHCD':
    for num in range(1, 14):
        total_card.append((flower, num))

current_card = []
k = int(raw_input())
for i in range(k):
    f, v = map(str, raw_input().split())
    t = (f, int(v))
    current_card.append(t)


loss_card = []
for tu in total_card:
    if tu not in current_card:
        loss_card.append(tu)

for tu in loss_card:
    print tu[0] + ' ' + str(tu[1])

Measured memory_bytes: 6424
import           Control.Monad
import           Control.Monad.ST
import qualified Data.Array                  as A
import qualified Data.Array.Unboxed          as AU
import qualified Data.ByteString.Char8       as BS
import           Data.Char
import           Data.List
import           Data.Maybe
import           Data.Ord
import           Data.Time
import qualified Data.Vector                 as V
import qualified Data.Vector.Mutable         as VM
import qualified Data.Vector.Unboxed         as VU
import qualified Data.Vector.Unboxed.Mutable as VUM

readIntegers :: IO [Integer]
readIntegers = map (fst . fromJust . BS.readInteger) . BS.words <$> BS.getLine

readIntegerLists :: Int -> IO [[Integer]]
readIntegerLists n =
  replicateM n (map (fst . fromJust . BS.readInteger) . BS.words <$> BS.getLine)

readInts :: IO [Int]
readInts = map (fst . fromJust . BS.readInt) . BS.words <$> BS.getLine

readIntLists :: Int -> IO [[Int]]
readIntLists n =
  replicateM n (map (fst . fromJust . BS.readInt) . BS.words <$> BS.getLine)

readStrings :: IO [String]
readStrings = map BS.unpack . BS.words <$> BS.getLine

readStringLists :: Int -> IO [[String]]
readStringLists n = replicateM n (map BS.unpack . BS.words <$> BS.getLine)

toPair :: [a] -> (a, a)
toPair [x, y] = (x, y)

main :: IO ()
main = do
  [a, b, c] <- readInts
  print $ min (b `div` a) c


Measured memory_bytes: 380
def solve(b):
    u = []
    lenu = []
    p = ''
    for i in range(len(b)):
        if (b[i]=='A')or(b[i]=='T')or(b[i]=='G')or(b[i]=='C'):
            p += b[i]
        else:
            u.append(p)
            lenu.append(len(p))
            p=p.replace(p,'')
    u.append(p)
    lenu.append(len(p))
    
    
    
    # print(u,lenu)

    print(max(lenu))


 
 
def main():
    b = input()
    solve(b)
 
 
if __name__ == '__main__':
    main()

Measured memory_bytes: 3188
#include<bits/stdc++.h> 
using namespace std;
#define debug1(x) cout<<#x<<" "<<x<<endl;
#define debug2(x,y) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<endl;
#define debug3(x,y,z) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<" "<<#z<<" "<<z<<endl;
#define pii pair<ll,ll>
#define vi vector<int>
#define vii vector<pii>
#define pb push_back
#define mp make_pair
# define ll long long int
int dp[3007][3007];
int n1,n2;
int lcs(char s1[],int i,char s2[],int j)
{
	if(dp[i][j]!=-1)
		return dp[i][j];
	if(n1==i || n2==j)
		return dp[i][j]=0;
	if(s1[i]==s2[j])
		return dp[i][j]=1+lcs(s1,i+1,s2,j+1);
	return dp[i][j]=max(lcs(s1,i+1,s2,j),lcs(s1,i,s2,j+1));
}
int main() 
{ 
  char X[3005]; 
  char Y[3005];
  cin>>X;
  cin>>Y; 
  
  n1 = strlen(X); 
  n2 = strlen(Y); 
  int i,j;
  for(i=0;i<3007;i++)
  	for(j=0;j<3007;j++)
  		dp[i][j]=-1;
 int p=lcs( X, 0,Y,  0 ) ; 
   i=0;
   j=0;
  char lcsa[100000];
  int k=0;
  while(i<n1 && j<n2)
  {
  	if(X[i]==Y[j])
  		{
  			lcsa[k++]=X[i];
  			i++,j++;
  		}
  	else if(dp[i+1][j]>dp[i][j+1])
  		i++;
  	else
  		j++;
  }
  printf("%s",lcsa);
  return 0; 
} 

Measured memory_bytes: 35968
from collections import defaultdict

n = int(input())
a = list(map(int, input().split()))
lInfo = defaultdict(int)
rInfo = defaultdict(int)
cnt = 0

for i in range(n):
    lInfo[a[i]+i] += 1
    rInfo[i-a[i]] += 1

for k in lInfo.keys():
    cnt += lInfo[k] * rInfo[k]
print(cnt)

Measured memory_bytes: 73792
#include <cstdio>
#include <vector>
#include <queue>
using namespace std;
const int MAXN = 1e4 + 7, INF = 5e5 + 7;
int d[MAXN];
struct node {
	int id, dist;
	node(int id, int dist) :id(id), dist(dist) {}
	bool operator < (const node &rhs) const {
		return dist > rhs.dist;
	}
};
vector<pair<int, int> > G[MAXN];
priority_queue<node> nodes;
int main() {
    int n;
    scanf("%d", &n);
    for (int i = 1; i < n; i++) {
    	d[i] = INF;
	}
    for (int i = 0; i < n; i++) {
    	int u, k;
    	scanf("%d%d", &u, &k);
    	for (int j = 0; j < k; j++) {
    		int v, c;
    		scanf("%d%d", &v, &c);
    		G[u].push_back(make_pair(v, c));
		}
	}
	nodes.push(node(0, 0));
	while (!nodes.empty()) {
		node tmp = nodes.top();
		nodes.pop();
		if (tmp.dist > d[tmp.id]) continue;
		int cnt = G[tmp.id].size();
		for (int i = 0; i < cnt; i++) {
			if (d[G[tmp.id][i].first] > d[tmp.id] + G[tmp.id][i].second) {
				d[G[tmp.id][i].first] = d[tmp.id] + G[tmp.id][i].second;
				nodes.push(node(G[tmp.id][i].first, d[G[tmp.id][i].first]));
			}
		}
	}
	for (int i = 0; i < n; i++) {
		printf("%d %d\n", i, d[i]);
	}
	return 0;
}


Measured memory_bytes: 2952
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl; 
#define INF 1000000000
#define mod 1000000007
typedef long long ll;
const ll LINF = 1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
//答え0~12しかないから決め打てないかやってみる

int n;
vector<int> d;
int main(){
    cin>>n;
    d.resize(n);
    rep(i,n){
        cin>>d[i];
    }
    sort(ALL(d));
    int cnt[30]={};
    cnt[0]++;
    for(auto x:d){
        cnt[x]++;
    }
    // for(auto x:cnt){
    //     if(x>2){
    //         cout<<0<<endl;return 0;
    //     }
    // }
    for(int ans=12;ans>0;ans--){
        multiset<int> tim;
        tim.insert(0);
        tim.insert(24);
        for(int i=0;i<n;i++){
            auto ite=tim.lower_bound(d[i]+1);
            if(ite==tim.begin()){
                cout<<0<<endl;return 0;
            }
            ite--;
            if(d[i]-*ite<ans){
                tim.insert(24-d[i]);
            }
            else{
                tim.insert(d[i]);
            }
        }
        bool f=true;
        for(auto it=tim.begin();it!=tim.end();it++){
            auto x=*it;
            auto nit=it;nit++;
            if(nit==tim.end()) break;
            auto y=*nit;
            if(abs(x-y)<ans){
                f=false;break;
            }
        }
        if(f){
            cout<<ans<<endl;
            return 0;
        }
    }
    cout<<0<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	long long a[3];
	for(int i=0;i<3;i++)
	{
		cin>>a[i];
	}
	sort(a,a+3);
	if(a[2]%2==0)
	{
		cout<<"0";
	}
	else
	{
		long long ans=a[0]*a[1];
		cout<<ans;
	}
}

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

typedef long long LL;

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ALL(x) (x).begin(),(x).end()
const int IINF = 1e9;
const LL LINF = 1e18;
const LL mod = 1e9+7;

int main() {
    map<string, int> m;
    m["SUN"] = 7;
    m["MON"] = 6;
    m["TUE"] = 5;
    m["WED"] = 4;
    m["THU"] = 3;
    m["FRI"] = 2;
    m["SAT"] = 1;
    string s;
    cin >> s;
    cout << m[s] << endl;
    return 0;
}



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

long long solve()
{
    long long N;
    cin>>N;
    long long last = 1;
    long long root = sqrt(N)+2;
    // cout<<root<<endl;
    for(long long i=root; i>1; i--){
        if(N%i==0){
            last = i;
            break;
        }
    }
    // cout<<last<<endl;
    return last+N/last-2;
}
int main()
{
    // freopen("sample_input.txt", "r", stdin);
    // freopen("sample_output.txt", "w", stdout);
    // seive();
    // int test;
    // cin>>test;
    // for(int t=1; t<=test; t++)
        cout << solve() << endl;
    
}


Measured memory_bytes: 256
#define    ll           long long
#define    dd           double
#define    mp           make_pair
#define    pb           push_back
#define    se           second
#define    fi           first
#define    mod          1000000007
#define    sob(v)       v.begin(),v.end()
#define    sobr(v)      v.rbegin(),v.rend()
#define    fr(i,a,b)    for(int i=a;i<=b;++i)
#define    frr(i,a,b)   for(int i=a;i>=b;--i)
#define    pi           acos(-1.00)
#define    check        cout<<"*"<<endl
#define    ffix(x)      cout<<fixed<<setprecision(x)
#define    fast         ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)

#include<bits/stdc++.h>
using namespace std;

typedef vector<int> vi;
typedef map<int,int> mii;
typedef pair<int,int> pii;
typedef pair<int,vi> pp;

int dr[4]= {0,0,-1,1};
int dc[4]= {-1,1,0,0};

const int N=100;

ll binpow(ll a,ll b)
{
    ll res=1*1LL;
    a%=mod;
    while(b>0)
    {
        if(b&1)res=(res*a)%mod;
        a=(a*a)%mod;
        b>>=1;
    }
    return res;
}
int main()
{
    char ch;
    cin>>ch;
    if(ch>='A' && ch<='Z')cout<<'A'<<endl;
    else cout<<'a'<<endl;
}


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

int main(){
    string s,t;
    cin>>s;
    cin>>t;
    int cnt=0,ans=INT_MAX;
    for(int i=0; i<=s.size()-t.size(); i++){
        cnt=0;
        for(int j=0,p=i; j<t.size(); j++,p++){
            if(t[j]!=s[p])
            cnt++;
        }
        ans=min(cnt,ans);
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 3628
#include <stdio.h>
#define MAX 100
#define inf 1000000000
#define NIL -1
#define WHITE 0
#define BLACK 1
#define GRAY 2

int n,A[MAX][MAX];

int prim(){
  int i,u,mincost;
  int d[MAX],p[MAX],color[MAX];
  
  for(i=0;i<n;i++){
    d[i]=inf;
    p[i]=NIL;
    color[i]=WHITE;
  }

  d[0]=0;

  while(1){
    mincost=inf;
    for(i=0;i<n;i++){
      if(color[i]!=BLACK && d[i]<mincost){
	mincost=d[i];
	u=i;
      }
    }
    if(mincost==inf) break;

    color[u]=BLACK;

    for(i=0;i<n;i++){
      if(color[i]!=BLACK && A[u][i] != inf){
	if(d[i]>A[u][i]){
	  d[i]=A[u][i];
	  p[i]=u;
	  color[i]=GRAY;
	}
      }
    }
  }
  int sum=0;
  for(i=0;i<n;i++){
    if(p[i]!=-1) sum+=A[i][p[i]];
  }
  return sum;
}

  
  

int main(){
  int i,j,e; //nは頂点、Aは辺の重み
 

  scanf("%d",&n);

  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      scanf("%d",&e);
      if(e==-1) A[i][j]=inf;
      else A[i][j]=e;
      
    }
  }

  
  printf("%d\n",prim());

  return 0;
}


  



Measured memory_bytes: 2048
object Main extends App {
  val scan = new java.util.Scanner(System.in)
  val n, m = scan.next().toInt
  val ps = (1 to n).toList.map(i => (i,scan.next().toInt))
  
  val unionFind = Array.fill(n+1)(0)
  for (i <- 0 to n) unionFind(i) = i
  for (_ <- 1 to m) {
    val x, y = scan.next().toInt
    union(x, y)
  }

  var cnt = 0
  for ((i,p) <- ps)
    cnt += (if (find(i) == find(p)) {1} else {0})

  println(cnt)

  def find(i: Int): Int = {
    if (unionFind(i) == i) i
    else {
      val r = find(unionFind(i))
      unionFind(i) = r
      r
    }
  }

  def union(i: Int, l: Int): Unit = {
    val iRoot = find(i)
    val lRoot = find(l)
    unionFind(iRoot) = math.min(iRoot, lRoot)
    unionFind(lRoot) = math.min(iRoot, lRoot)
  }
}

Measured memory_bytes: 79368
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<cstring>
using namespace std;

char **data;
char done[20];
int donen;
int h,w;

int r(char);
int inc(char);
void sear(char,int*,int*,int*,int*);

int main(){
	int n;
	int i,j;
	char s[100];
	char *ps;
	int size;
	int error;
	fgets(s,sizeof(s),stdin);
	size=atoi(s);
	for(n=0;n<size;n++){
		fgets(s,sizeof(s),stdin);
		ps=strtok(s," ");
		h=atoi(ps);
		ps=strtok(NULL," ");
		w=atoi(ps);

		data=new char*[h];
		for(i=0;i<h;i++){
			data[i]=new char[w];
			fgets(s,sizeof(s),stdin);
			memcpy(data[i],s,w);
		}
		//memset(done,0,sizeof(done));
		donen=0;
		error=0;
		for(i=0;i<h;i++){
			for(j=0;j<w;j++){
				if(data[i][j]!='.' && data[i][j]!=' '){
					if(r(data[i][j])==1){
						error=1;
						break;
					}
				}
			}
			if(error==1) break;
		}
		if(error==0) cout<<"SAFE"<<endl;
		else cout<<"SUSPICIOUS"<<endl;
		for(i=0;i<h;i++) delete [] data[i];
		delete [] data;
	}
	return 0;
}

int r(char c){
	int i,j;
	int x1,x2,y1,y2;
	sear(c,&x1,&y1,&x2,&y2);
	for(i=y1;i<=y2;i++){
		for(j=x1;j<=x2;j++){
			if(data[i][j]=='.') return 1;
			else if(inc(data[i][j])==1) return 1;
		}
	}
	done[donen++]=c;
	for(i=y1;i<=y2;i++){
		for(j=x1;j<=x2;j++){
			if(data[i][j]!=c &&data[i][j]!=' '){
				if(r(data[i][j])==1) return 1;
			}
		}
	}
	for(i=y1;i<=y2;i++){
		for(j=x1;j<=x2;j++){
			if(data[i][j]==c) data[i][j]=' ';
		}
	}
	return 0;
}

int inc(char c){
	for(int i=0;i<donen;i++) if(done[i]==c) return 1;
	return 0;
}

void sear(char c,int *x1,int *y1,int *x2,int *y2){
	int i,j;
	*x1=*x2=*y1=*y2=-1;
	for(i=0;i<h;i++){
		for(j=0;j<w;j++){
			if(data[i][j]==c){
				*y1=i;
				break;
			}
		}
		if(*y1!=-1) break;
	}
	for(i=h-1;i>=0;i--){
		for(j=0;j<w;j++){
			if(data[i][j]==c){
				*y2=i;
				break;
			}
		}
		if(*y2!=-1) break;
	}
	for(i=0;i<w;i++){
		for(j=0;j<h;j++){
			if(data[j][i]==c){
				*x1=i;
				break;
			}
		}
		if(*x1!=-1) break;
	}
	for(i=w-1;i>=0;i--){
		for(j=0;j<h;j++){
			if(data[j][i]==c){
				*x2=i;
				break;
			}
		}
		if(*x2!=-1) break;
	}
	return;
}

Measured memory_bytes: 0
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define int long long
using namespace std;
signed main() {
	string A, B, C;
	cin >> A >> B >> C;

	cout << "A" << B[0] << "C" << endl;
}

Measured memory_bytes: 3600
#include <stdio.h>
    #include <stdlib.h>
 
    int main(void){
      int a,b,n,p,q;
     
      if( scanf("%d%d%d",&n,&a,&b) < 3 ){
        return -1;
     }   
     
     if(a<b) {
                 if(a+b <= n){
                 q=0;
                 }
                 else{       
                 q=b+a-n;
                }            
                 p=a;             
         } 
     else{
                 if(a+b <= n){
                 q = 0;
                 }
                 else{
                 q=a+b-n;
              }
                 p=b;
         }
     if(a==b){
                if(b==n){
                        q=a;
                        p=b;
                  }
      }
     
     printf("%d %d\n",p,abs(q));
     
     return 0;
    }

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    int K; cin >> K;

    int chk = K%10;
    if(chk != 1 && chk != 3 && chk != 7 && chk != 9){
        cout << -1 << endl;
        return 0;
    }

    int ans = 1;
    int seven = 7;

    while(seven%K != 0){
        seven %= K;
        seven *= 10;
        seven += 7;
        ans++;
    }

    cout << ans << endl;

}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define ss second
#define ff first
#define all(x) x.begin(), x.end()
 
using namespace std;
using ll = long long;
using pii = pair<ll, ll>;
 
const int oo = 1e9 + 7;
const int mod = 1e9 + 7, maxn = 1e7+1;
const long double PI = acos(-1);


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

    ll n, ans = 0, x;
    cin >> n;

    for (int i=1; i<=n; i++){
        x = n/i;
        ans += i * (x*(x+1))/2;
    }

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

Measured memory_bytes: 3644
#include <algorithm>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
using ll = long long;
using P = pair<int, int>;
const ll INF = 1001001001;

int main() {
  int n;
  cin >> n;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];
  sort(a.begin(), a.end());

  ll res = a[0];

  rep(i, n) {
    if (a[i] % res != 0 && res > a[i] % res) {
      res = a[i] % res;
      i = -1;
    }
  }

  cout << res;
  return 0;
}


Measured memory_bytes: 4048
#include <bits/stdc++.h>
#define DUMP(x)  cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define IFOR(i, m, n) for(int i = n - 1; i >= m; i-- )
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define FOREACH(x,a) for(auto& (x) : (a) )
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
const ll INF = 1LL << 60;
const int MOD = 1000000007;
/* テンプレートここまで */

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

  string s, t;
  cin >> s;
  cin >> t;

  IFOR(i,1,N+1){
    if(s.substr(N-i) == t.substr(0, i)){
      cout << 2*N - i << endl;
      return 0;
    }
  }

  cout << 2*N << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MAX = 500000;
const ll INF = 1LL<<60;
typedef struct Node { ll num; char c; } node;
ll cnt;

void merge(vector<node> &seq, ll left, ll mid, ll right) {
    ll n1 = mid - left;
    ll n2 = right - mid;
    vector<node> seq_left(n1), seq_right(n2);
    for(ll i = 0; i < n1; i++) seq_left.at(i) = seq.at(left+i);
    for(ll i = 0; i < n2; i++) seq_right.at(i) = seq.at(mid+i);
    node infinite; infinite.num = INF;
    seq_left.push_back(infinite); seq_right.push_back(infinite);
    ll i = 0, j = 0;
    for( ll k = left; k < right; k++ ) {
        cnt++;
        if( seq_left.at(i).num <= seq_right.at(j).num) {
            seq.at(k) = seq_left.at(i++);
        } else {
            seq.at(k) = seq_right.at(j++);
        }
    }
}

void merge_sort(vector<node> &seq, ll left, ll right) {
    if( left + 1 < right) {
        ll mid = (left + right) / 2;
        merge_sort(seq, left, mid);
        merge_sort(seq, mid, right);
        merge(seq, left, mid, right);
    }
}

ll partition(vector<node> &seq, ll p, ll right) {
    node x = seq.at(right);
    ll i = p - 1;
    for( ll j = p; j < right; j++) {
        if( seq.at(j).num <= x.num) {
            i++;
            node temp = seq.at(i); seq.at(i) = seq.at(j); seq.at(j) = temp;
            // swap(seq.at(i), seq.at(j));
        }
    }
    node temp = seq.at(i+1); seq.at(i+1) = seq.at(right); seq.at(right) = temp; 
    // swap(seq.at(i+1), seq.at(right));

    return i + 1;
}

void quick_sort(vector<node> &seq, ll p, ll r) {
    if(p < r) {
        ll q = partition(seq, p, r);
        quick_sort(seq, p, q-1);
        quick_sort(seq, q+1, r);
    }
}

void quicksort(vector<node> &seq, ll n) {
    quick_sort(seq, 0, n-1);
}

signed main() {
    ll n; scanf("%lld", &n); 
    vector<node> seq(n);
    // for( ll i = 0; i < n; i++ ) scanf("%c %lld", &seq.at(i).c, &seq.at(i).num);
    for( ll i = 0; i < n; i++ ) cin >> seq.at(i).c >> seq.at(i).num;

    // for (ll j = 0; j < n-1; j++)
    // { printf("%c %lld\n", seq.at(j).c, seq.at(j).num); }
    // printf("%c %lld\n", seq.at(n-1).c, seq.at(n-1).num);

    vector<node> sorted_merge(n); sorted_merge = seq; merge_sort(sorted_merge, 0, n);
    vector<node> sorted_quick(n); sorted_quick = seq; quicksort(sorted_quick,n);
    bool flg = true;
    for (ll i = 0; i < n; i++) {
        if( sorted_quick.at(i).c != sorted_merge.at(i).c ) {
            flg = false; break;
        } 
    }
    if(flg) printf("Stable\n");
    else printf("Not stable\n");
    for (ll j = 0; j < n-1; j++)
    // { cout << sorted_quick.at(j).c << ' ' << sorted_quick.at(j).num << endl; }
    // cout << sorted_quick.at(n-1).c << ' ' << sorted_quick.at(n-1).num << endl;
    { printf("%c %lld\n", sorted_quick.at(j).c, sorted_quick.at(j).num); }
    printf("%c %lld\n", sorted_quick.at(n-1).c, sorted_quick.at(n-1).num);
    // cout << endl;
    // for (ll j = 0; j < n-1; j++)
    // { printf("%c %lld\n", sorted_merge.at(j).c, sorted_merge.at(j).num); }
    // printf("%c %lld\n", sorted_merge.at(n-1).c, sorted_merge.at(n-1).num);
    return 0;
}




Measured memory_bytes: 9168
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
#define rep(i, begin, n) for (int i = begin; i < n; i++)
#define repe(i, begin, n) for (int i = begin; i <= n; i++)
#define repr(i, begin, n) for (int i = begin; i > begin - n; i--)
#define repre(i, begin, end) for (int i = begin; i >= end; i--)

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 int inf = 1000000007;
const int MOD = 1000000007;
const long long INF = 1000000000000000007;

// -------------------------------------------------------

int H, W;
int a[600][600];

int main()
{
    cin >> H >> W;
    repe(i, 1, H)
    {
        repe(j, 1, W)
        {
            cin >> a[i][j];
        }
    }

    int N = 0;
    ostringstream ans;
    repe(i, 1, H)
    {
        if (i % 2 == 1)
        {
            repe(j, 1, W - 1)
            {
                if (a[i][j] % 2 == 1)
                {
                    a[i][j + 1]++;
                    N++;
                    ans << i << " " << j << " " << i << " " << j + 1 << endl;
                }
            }
            if (i != H && a[i][W] % 2 == 1)
            {
                a[i + 1][W]++;
                N++;
                ans << i << " " << W << " " << i + 1 << " " << W << endl;
            }
        }
        else
        {
            for (int j = W; j >= 2; j--)
            {
                if (a[i][j] % 2 == 1)
                {
                    a[i][j - 1]++;
                    N++;
                    ans << i << " " << j << " " << i << " " << j - 1 << endl;
                }
            }
            if (i != H && a[i][1] % 2 == 1)
            {
                a[i + 1][1]++;
                N++;
                ans << i << " " << 1 << " " << i + 1 << " " << 1 << endl;
            }
        }
    }
    cout << N << endl;
    cout << ans.str();
}


Measured memory_bytes: 7172
// clang-format off
#include <bits/stdc++.h>

#define mp make_pair
#define fst first
#define snd second
#define forn(i,n) for (int i = 0; i < int(n); i++)
#define forn1(i,n) for (int i = 1; i <= int(n); i++)
#define popcnt __builtin_popcount
#define ffs __builtin_ffs
#define ctz __builtin_ctz
#define clz __builtin_clz
#define all(a) (a).begin(), (a).end()
 
using namespace std;

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pli = pair<ll,int>;
using pil = pair<int,ll>;
using pll = pair<ll,ll>;
template <typename T> using vec = vector<T>;
using vi = vec<int>;
using vl = vec<ll>;
template <typename T> using que = queue<T>;
template <typename T> using deq = deque<T>;

template <typename T> T id(T b) {return b;};
template <typename T> void chmax(T &x, T y) {if (x < y) x = y;}
template <typename T> void chmin(T &x, T y) {if (x > y) x = y;}
template <typename S, typename K> bool contains(S &s, K k) { return s.find(k) != s.end(); }
void fastio() { ios_base::sync_with_stdio(false); cin.tie(nullptr); }
constexpr ll TEN(int n) { if (n == 0) return 1LL; else return 10LL*TEN(n-1); }
// clang-format on

int main() {
    fastio();

    ll x;
    cin >> x;

    ll z = 100;
    int y = 1;
    while (true) {
        z = z + 0.01L * z;
        if (z >= x) {
            cout << y << endl;
            return 0;
        }
        y++;
    }

    return 0;
}

Measured memory_bytes: 3652
//config = {input: 'tmp', newline: '\r\n'}; // win
config = {input: '/dev/stdin', newline: '\n'}; //linux

line = require('fs').readFileSync(config.input, 'ascii').trim();

geo = [0];
j = 0;
for (i in line) {
  if (line[i] === '\\') geo.push(--j);
  else if (line[i] === '/') geo.push(++j);
  else geo.push(j);
}

lv = []; // level of water surface
j = 0;
for (i in geo) {
  j = Math.max(j, geo[i]);
  lv.push(j);
}
j = geo[geo.length - 1];
for (i = geo.length - 1; i >= 0; i--) {
  j = Math.max(j, geo[i]);
  if (lv[i] > j) lv[i] = j;
}

segment = [];
prev = false;
for (i = 0; i < lv.length; i++) {
  cur = (lv[i] > geo[i]);
  if (!prev && cur) min = i;
  if (prev && !cur) segment.push([min, i - 1]);
  prev = cur;
}

res = segment.map(function (segment) {
  var max = segment[1];
  var sum = 0;
  for (var j = segment[0] - 1; j <= max; j++)
    sum += (lv[j] - (geo[j] + geo[j+1]) / 2);
  return sum;
});

console.log(res.reduce(function(p, c) { return p + c; }, 0));
if (res.length !== 0) console.log('%d %s', res.length, res.join(' '));
else console.log(0);

Measured memory_bytes: 19260
#include <algorithm>  
#include <iostream>  
#include <sstream>  
#include <string>  
#include <cstring>
#include <vector>  
#include <queue>  
#include <set>  
#include <map>  
#include <cstdio>  
#include <cstdlib>  
#include <cctype>  
#include <cmath>  
#include <list>  
#include <cassert>
#include <ctime>
#include <climits>
using namespace std;  

#define PB push_back  
#define MP make_pair  
#define SZ(v) ((int)(v).size())  
#define FOR(i,a,b) for(int i=(a);i<(b);++i)  
#define REP(i,n) FOR(i,0,n)  
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)  
#define REPE(i,n) FORE(i,0,n)  
#define FORSZ(i,a,v) FOR(i,a,SZ(v))  
#define REPSZ(i,v) REP(i,SZ(v))  
typedef long long ll;
typedef unsigned long long ull;
ll gcd(ll a,ll b) { return b==0?a:gcd(b,a%b); }

const int MAXN=21;
const int MOD=1000000007;
void inc(int &a,int b) { if((a+=b)>=MOD) a-=MOD; }

int n;
int a[MAXN][MAXN];

int dp[MAXN+1][1<<MAXN];

int solve() {
	memset(dp,0,sizeof(dp)); dp[0][0]=1;
	REP(i,n) REP(mask,1<<n) if(dp[i][mask]!=0) {
		REP(k,n) if((mask&(1<<k))==0&&a[i][k]==1) inc(dp[i+1][mask^(1<<k)],dp[i][mask]);
	}
	return dp[n][(1<<n)-1];
}

void run() {
	scanf("%d",&n);
	REP(i,n) REP(j,n) scanf("%d",&a[i][j]);
	printf("%d\n",solve());
}

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


Measured memory_bytes: 180480
#include<cstdio>
#include<cmath>
#include<climits>
#include<algorithm>
#include<sstream>
#include<iostream>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<unordered_set>
#include<unordered_map>
#include<set>
#include<map>
#include<list>

using namespace std;

#define in(s) cin >> s
#define out(s) cout << s << endl
#define rep(i,n) for(int i=0; i<n; i++)
#define rept(i,a,b) for(int i=a; i<b; i++)
#define ll long long
#define MOD 1000000007

#define IMIN INT_MIN;
#define IMAX INT_MAX;


int main(){
    int H, W;
    in(H); in(W);
    vector<vector<int>> s(H, vector<int> (W));
    char tmp;
    int cnt = 0;
    rep(i, H) rep(j, W) { in(tmp); s[i][j] = (tmp == '.')? INT_MAX : -1; if(tmp == '#') cnt++; }
    s[0][0] = 1;

    //rep(i, H) {
    //    rep(j, W) cout << s[i][j] << '\t';
    //    cout << endl;
    //}

    queue<pair<int, int>> Q;
    int x, y;
    Q.push(make_pair(0, 0));
    while (!Q.empty()) {
        x = Q.front().first;
        y = Q.front().second;
        if (x > 0 && s[x-1][y] != -1 && s[x-1][y] > s[x][y] + 1) {
            s[x-1][y] = s[x][y] + 1;
            Q.push(make_pair(x-1, y));
        }
        if (y > 0 && s[x][y-1] != -1 && s[x][y-1] > s[x][y] + 1) {
            s[x][y-1] = s[x][y] + 1;
            Q.push(make_pair(x, y-1));
        }
        if (x < H-1 && s[x+1][y] != -1 && s[x+1][y] > s[x][y] + 1) {
            s[x+1][y] = s[x][y] + 1;
            Q.push(make_pair(x+1, y));
        }
        if (y < W-1 && s[x][y+1] != -1 && s[x][y+1] > s[x][y] + 1) {
            s[x][y+1] = s[x][y] + 1;
            Q.push(make_pair(x, y+1));
        }
        Q.pop();
    }
    //rep(i, H) {
    //    rep(j, W) cout << s[i][j] << '\t';
    //    cout << endl;
    //}

    if (s[H-1][W-1] == INT_MAX) out(-1);
    else out(H*W - cnt - s[H-1][W-1]);
	return 0;
}


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

int main() {
	int n, k, l[50];
	cin >> n >> k;
	for (int i = 0; i < n; i++) cin >> l[i];
	sort(l, l + n);

	int ans = 0;
	for (int j = 0; j < k; j++)
	{
		ans += l[n - j - 1];
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
using namespace std;
#define REP(i, j) for(int i = 0; i < (int)(j); ++i)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
typedef pair<int, int> P;
const int H = 4;
const int W = 8;
const int INF = 1e9 + 7;

int ans = INF;
map< vector< vector<int> >, int> M;

bool check(vector< vector<int> > &v){
  REP(i, H) REP(j, W - 1) if(v[i][j] != 10 * (i + 1) + j + 1) return false;
  return true;
}

P searchP(vector< vector<int> > &v, int y, int x){
  P res;
  REP(i, H) REP(j, W) if(v[i][j] == v[y][x] + 1) res = P(i, j);
  return res;
}

void dfs(int t, vector< vector<int> > &v){
  if(check(v)){ ans = min(t, ans); return ; }
  if(t >= ans || (M.find(v) != M.end() && M[v] <= t)) return ;
  M[v] = t;
  REP(i, H){
    FOR(j, 1, W){
      if(v[i][j] != 0) continue;
      P p = searchP(v, i, j - 1);
      swap(v[i][j], v[p.first][p.second]);
      dfs(t + 1, v);
      swap(v[i][j], v[p.first][p.second]);
    }
  }
}

int main() {
  int T; cin >>T;
  REP(t, T){
    ans = INF;
    M = map< vector< vector<int> >, int>();
    vector< vector<int> > v(H, vector<int>(W, 0));
    REP(i, H){
      FOR(j, 1, W){
        cin >>v[i][j];
        if(v[i][j] % 10 == 1) swap(v[i][j], v[v[i][j] / 10 - 1][0]);
      }
    }
    dfs(0, v);
    cout <<(ans == INF ? -1 : ans) <<endl;
  }
  return 0;
}

Measured memory_bytes: 31948
t = [[int(j) for j in input().split()] for i in range(3)]
l = sum(t, [])
N = int(input())
for _ in range(N):
    i = int(input())
    for j in range(9):
        if i == l[j]:
            l[j] = 0
a, b, c, d, e, f, g, h, i = l
if (a == 0 and d == 0 and g == 0) \
or (b == 0 and e == 0 and h == 0) \
or (c == 0 and f == 0 and i == 0) \
or (a == 0 and b == 0 and c == 0) \
or (d == 0 and e == 0 and f == 0) \
or (g == 0 and h == 0 and i == 0) \
or (a == 0 and e == 0 and i == 0) \
or (c == 0 and e == 0 and g == 0):
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3316
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import string
import heapq
from _collections import defaultdict
from functools import lru_cache

class Scanner():
    def int():
        return int(sys.stdin.readline().rstrip())
    def string():
        return sys.stdin.readline().rstrip()
    def map_int():
        return [int(x) for x in Scanner.string().split()]
    def string_list(n):
        return [input() for i in range(n)]
    def int_list_list(n):
        return [Scanner.mapInt() for i in range(n)]
    def int_cols_list(n):
        return [int(input()) for i in range(n)]
        
class Math():
    def gcd(a,b):
        if b == 0:
            return a
        return Math.gcd(b,a % b)
    def lcm(a,b):
        return (a * b) // Math.gcd(a,b)
    def roundUp(a,b):
        return -(-a // b)
    def toUpperMultiple(a,x):
        return Math.roundUp(a,x) * x
    def toLowerMultiple(a,x):
        return (a // x) * x
    def nearPow2(n):
        if n <= 0:
            return 0
        if n & (n - 1) == 0:
            return n
        ret = 1
        while(n > 0):
            ret <<= 1
            n >>= 1
        return ret
    def isPrime(n):
        if n < 2:
            return False
        if n == 2:
            return True
        if n % 2 == 0:
            return False
        d = int(n ** 0.5) + 1
        for i in range(3,d + 1,2):
            if n % i == 0:
                return False
        return True

MOD = int(1e09) + 7

def main():
    N,T = Scanner.map_int()
    A = Scanner.map_int()

    ans = 0
    prev = 0
    for i in range(N):
        ans += T
        ans -= max(0,prev - A[i])
        prev = A[i] + T
    print(ans)
    return

if __name__ == "__main__":
    main()


Measured memory_bytes: 81528
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e5 + 7;

#include <math.h>
#define PI 3.14159265358979323846264338327950L


int main() {
    int n, m, x;
    cin >> n >> m >> x;
    vector<vector<int>> a(n, vector<int>(m));
    vector<int> c(n);
    for (int i = 0; i < n; i++) {
        cin >> c[i];
        for (int j = 0; j < m; j++)cin >> a[i][j];
    }
    int ans = 12345678;
    int all = 1 << n;
    for (int mask = 0; mask < all; mask++) {
        vector<int> line(m, 0);
        int price = 0;
        for (int i = 0; i < n; i++) {
            if (mask & (1 << i)) {
                price += c[i];
                for (int j = 0; j < m; j++) line[j] += a[i][j];
            }
        }
        bool ok = true;
        for (int i = 0; i < m; i++) {
            if (line[i] < x) ok = false;
        }
        if (ok) ans = min(ans, price);
    }
    

    cout << (ans == 12345678 ? -1 : ans) << endl;

    return 0;
}

Measured memory_bytes: 3532
import java.util.Scanner;
public class Main {
	public static void main(String[] args) throws Exception{
		Scanner scan=new Scanner(System.in);
		int a=scan.nextInt();
		int b=scan.nextInt();
		String str[]=new String[a];
	for(int i=0;i!=a;i++) {
		str[i]=scan.next();
	}
	for(int i=0;i!=a;i++) {
		System.out.println(str[i]);
		System.out.println(str[i]);
	}
	}
}

Measured memory_bytes: 23636
from collections import deque
n = int(input())
s = input()
d = deque(s)

stack = []
for c in s:
  #抜き出したもの(c)が左括弧だった場合
  if c == "(":
    stack.append(c)
    
  #抜き出したもの(c)が右括弧だった場合
  else:
    #stackがなかった場合
    if not stack:
      d.appendleft('(')
      
    #stackがあった場合
    else:
      #末尾をstackから削除する
      stack.pop()

#まだstackが残っていたらそれは左かっこなので、その数だけ ")" を足す
while stack:
  stack.pop()
  d.append(')')
  
print("".join(list(d)))




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

main() {
    int A,B,C,D; cin >> A >> B >> C >> D;
    cout << min(A,B)+min(C,D) << endl;

    return 0;
}

Measured memory_bytes: 256