akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
ll MOD = 1e9+7;

#define vec     vector<int>
#define vecll   vector<ll>
#define vec2    vector<vector<int>>
#define vec2ll  vector<vector<ll>>
#define vpair   vector<pair<int, int>>
#define vpairll vector<pair<ll, ll>>
#define vecst   vector<string>
#define vecb    vector<bool>

#define rep(i,n)         for(ll i=(ll)0; i<(ll)n; i++)
#define REP(i,m,n)       for(ll i=(ll)m; i<(ll)n; i++)
#define arr(var, n)      vec var(n); rep(i,n){cin >> var[i];}
#define arrll(var, n)    vecll var(n); rep(i,n){cin >> var[i];}
#define arrst(var, n)    vecst var(n); rep(i,n){cin >> var[i];}
#define all(var)         (var).begin(), (var).end()
#define sortall(var)     sort(all(var))
#define uniqueall(v)     v.erase(unique(v.begin(), v.end()), v.end());
#define f_sum(var)       accumulate(all(var), 0)
#define f_sumll(var)     accumulate(all(var), 0LL)
#define chmin(v1, v2)    v1 = min(v1, v2)
#define chmax(v1, v2)    v1 = max(v1, v2)
#define mpair(v1, v2)    make_pair(v1, v2)
#define pb(var)          push_back(var)
#define prt(var)         cout << var << "\n"
#define prtd(n, var)     cout << fixed << setprecision(n) << var << "\n"
#define prtfill(n, var)  cout << setw(n) << setfill('0') << var;
#define prt2(v1, v2)     cout << v1 << " " << v2 << "\n"
#define prt3(v1, v2, v3) cout << v1 << " " << v2 << " " << v3 << "\n"
#define prtall(v)        rep(i,v.size()){cout<<v[i]<<(i!=v.size()-1?" ":"\n");}
void prtok(bool ok){prt((ok ? "Yes" : "No"));}
//----------------------------------------------------------------
#define bitrep(i, n)     for(ll i=0; i<(ll) (1<<n); i++)
#define bis(i, j)        i & (1<<j)

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

  if(s.size()==1){
    prt(s);
    return 0;
  }
  ll ans=0;
  ll n=s.size()-1;
  bitrep(i, n){
    ll tmp=s[0]-'0';
    rep(j,n){
      if(bis(i,j)){
        ans+=tmp;
        tmp=s[j+1]-'0';
      } else {
        tmp=tmp*10+(s[j+1]-'0');
      }
      if(j==n-1) ans+=tmp;
    }
  }

  prt(ans);


}


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

#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC targett("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

using namespace std;
#define fast ios::sync_with_stdio(0);cin.tie(0);
#define endl        '\n'
#define ll          long long int
#define pb          push_back
#define sz(x)       (int)(x).size()
const ll mod = 1e9 + 7;

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


ll powm(ll a, ll b) {
	ll res = 1;
	while (b) {
		if (b & 1)
			res = (res * 1LL * a) % mod;
		b >>= 1LL;
		a = (a * 1LL * a) % mod;
	}
	return res;
}

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

int n;
ll a[100];
ll dp[100];

int main() {
	fast
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
	}

	dp[1] = 1000;

	for (int i = 2; i <= n; i++) {
		dp[i] = dp[i - 1];
		for (int j = 1; j < i; j++) {
			dp[i] = max(dp[i] , dp[j] + ((dp[j] / a[j]) * (a[i] - a[j])));
		}
	}
	cout << dp[n] << endl;

	return 0;

}





Measured memory_bytes: 3608
#include<bits/stdc++.h>
using namespace std;
int main() {
   cin.tie(0);
   ios::sync_with_stdio(false);
   int n, k;
   cin >> n >> k;
   vector<int> vc;
   for(int i = 0;i < n;i++) {
       int x;
       cin >> x;
       vc.push_back(x);
   }
   int count = 0;
   for(int i = 0;i < n;i++) {
       int len = min(abs(vc[i]), abs(vc[i]-k));
       count+=len*2;
   }
   cout << count << endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace B
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] str = Console.ReadLine().Split(' ');
            int N = int.Parse(str[0]);
            int T = int.Parse(str[1]);

            int mincost = 10000;

            for (int i = 0; i < N; i++)
            {
                string[] str2 = Console.ReadLine().Split(' ');
                int c = int.Parse(str2[0]);
                int t = int.Parse(str2[1]);

                if (t <= T && c < mincost)
                {
                    mincost = c;
                }
            }

            if (mincost == 10000)
            {
                Console.WriteLine("TLE");
            }
            else
            {
                Console.WriteLine(mincost);
            }
        }
    }
}


Measured memory_bytes: 11092
import java.util.Scanner
import java.io.PrintWriter

object Main {
  def main(args: Array[String]): Unit = {
    val sc = new Scanner(System.in)
    val pw = new PrintWriter(System.out)

    val n = sc.nextInt()
    val s = sc.next()
    if (n % 2 == 1) {
      pw.println("No")
    } else {
      if (s.substring(0, n / 2) == s.substring(n / 2)) {
        pw.println("Yes")
      } else {
        pw.println("No")
      }
    }

    pw.flush()
  }
}

Measured memory_bytes: 25536
#include <bits/stdc++.h>
using namespace std;
int main(){
    int a,b,c;
    cin >>a>>b>>c;
    if((a == 5 && b == 5 && c == 7) ||
    (a == 5 && b == 7 && c ==5) || (a == 7 && b == 5 && c ==5)){
        cout << "YES" << endl;
    }
    else cout << "NO" <<endl;
}

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

int main() {

	char S[1234] = { '\0' };
	int str_long, x = 0, y = 0, n = -1, w = -1, s = -1, e = -1;
	int flag = -1;

	scanf("%s", &S);
	str_long = strlen(S);

	for (int i = 0; i < str_long - 1; i++) {
		switch (S[i]) {
		case 'N':
			y++;
			n = 1;
			break;

		case 'W':
			x--;
			w = 1;
			break;

		case 'S':
			y--;
			s = 1;
			break;

		case 'E':
			x++;
			e = 1;
			break;
		}
	}

	switch (S[str_long - 1]) {
	case 'N':
		n = 1;
		break;

	case 'W':
		w = 1;
		break;

	case 'S':
		s = 1;
		break;

	case 'E':
		e = 1;
		break;
	}

	/*if (x == 0 && y < 0) {
		if (S[str_long-1] == 'N') {
			flag = true;
		}
	}

	if (x == 0 && y > 0) {
		if (S[str_long-1] == 'S') {
			flag = true;
		}
	}

	if (x < 0 && y == 0) {
		if (S[str_long-1] == 'E') {
			flag = true;
		}
	}

	if (x > 0 && y == 0) {
		if (S[str_long-1] == 'W') {
			flag = true;
		}
	}*/

	if (x == 0) {
		if (n == 1 && s == 1) {
			flag = 1;
		}
	}

	if (y == 0) {
		if (w == 1 && e == 1) {
			flag = 1;
		}
	}

	if (flag == 1) { printf("Yes"); }
	if (flag == -1) { printf("No"); }

	// printf("\n%d %d", x, y);

	return 0;
}

Measured memory_bytes: 128
n, k = map(int, input().split())
a = list(map(int, input().split()))
now = 1
chk = [0] * n
flg = True
count = 0
if k < 10 ** 7:
    for i in range(k):
        now = a[now - 1]
else:
    while flg:
        count += 1
        now = a[now - 1]
        if chk[now - 1] == 0 and now != 1:
            chk[now - 1] = count
        else:
            flg = False
            if (k - count) != 0 and (count - chk[now - 1]) != 0:
                rem = (k - count) % (count - chk[now - 1])
            else:
                rem = 0
    else:
        for i in range(rem):
            now = a[now - 1]
            count += 1
print(now)


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

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define shandom_ruffle random_shuffle

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy


int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    ll n;
    cin >> n;
    ll a[n];
    int x = 0;
    ll mn = INF;
    ll sum = 0;
    F0R(i,n){
      cin >> a[i];
      if(abs(a[i]) < mn) mn = abs(a[i]);
      if(a[i] < 0) x^=1;
      sum += abs(a[i]);
    }
    if(x == 0) cout << sum << endl;
    else cout << sum - 2*mn << endl;
    return 0;
}

// read the question correctly (ll vs int)
// template by super1 derived from bqi343


Measured memory_bytes: 1024
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import java.util.NoSuchElementException;

public class Main {
	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		double T = sc.nextDouble();
		double X = sc.nextDouble();
		System.out.println(T/X);
	}
}

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;

    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        } else {
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }

    private int readByte() {
        if (hasNextByte())
            return buffer[ptr++];
        else
            return -1;
    }

    private static boolean isPrintableChar(int c) {
        return 33 <= c && c <= 126;
    }

    public boolean hasNext() {
        while (hasNextByte() && !isPrintableChar(buffer[ptr]))
            ptr++;
        return hasNextByte();
    }

    public String next() {
        if (!hasNext())
            throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while (isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    public long nextLong() {
        if (!hasNext())
            throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while (true) {
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            } else if (b == -1 || !isPrintableChar(b)) {
                return minus ? -n : n;
            } else {
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }

    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
            throw new NumberFormatException();
        return (int) nl;
    }

    public double nextDouble() {
        return Double.parseDouble(next());
    }
}

Measured memory_bytes: 22864
using System;
using System.Linq;

class Program
{
    static void Main()
    {
        var na = Array.ConvertAll(Console.ReadLine().Split(), long.Parse);
        var inp = Array.ConvertAll(Console.ReadLine().Split(), long.Parse);
        inp = new long[1] {0}.Concat(inp).ToArray();
        var dp = new long[na[0] + 1, na[0] + 1, (na[0] + 1) * 50 + 1];
        long ans = 0;
        for (int k = 1; k <= na[0]; k++)
        {
            for (int x = 1; x <= k; x++)
            {
                if (x == 1) dp[k, x, inp[k]] = 1;
                for (int s = 0; s <= na[0] * 50; s++)
                {
                    dp[k, x, s] += dp[k - 1, x, s];
                    dp[k, x, s + inp[k]] += dp[k - 1, x - 1, s];
                }
            }
        }
        for (int i = 1; i <= na[0]; i++) ans += dp[na[0], i, i * na[1]];
        Console.WriteLine(ans);
    }
}


Measured memory_bytes: 64224
s = input()

acgt_len = 0
max_len = 0

ACGT = ['A', 'C', 'G', 'T']

for i in range(len(s)):
    if s[i] in ACGT:
        acgt_len += 1
    else:
        max_len = max(acgt_len, max_len)
        acgt_len = 0

print(max(acgt_len, max_len))

Measured memory_bytes: 3060
#include<stdio.h>
int main(void){
    int a,b;
    scanf("%d%d",&a,&b);
    if(a<=b){
        for(int i=0;i<b;i++){
            printf("%d",a);
        }
    }
    else{
        for(int i=0;i<a;i++){
            printf("%d",b);
        }
    }
    printf("\n");
    return 0;
}

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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
typedef long long ll;

int main(){
  int n, m;
  cin >> n >> m;

  //vector<pair<int, int>> a;
  vector<vector<int>> tuuro(n, vector<int>(0));
  rep(i, m){
    int a, b;
    cin >> a >> b;
    a--;
    tuuro.at(a).push_back(b);
    a++;
    b--;
    tuuro.at(b).push_back(a);
  }

  vector<int> sirube(n, -1);
  sirube.at(0) = 0;

  queue<int> que;
  que.push(0);

  int now = 0;
  int last = 0;

  while(que.size()){
    now = que.front();
    que.pop();
    for(int i=0; i<tuuro.at(now).size(); i++){
      int tugi = tuuro.at(now).at(i)-1;
      if(tugi!=last&&sirube.at(tugi)==-1){
        sirube.at(tugi) = now+1;
        que.push(tugi);
      }
    }
  }

  int ans=1;

  rep(i, n){
    if(sirube.at(i)==-1) ans=0;
  }

  if(ans){
    cout << "Yes" << endl;
    for(int i=1; i<n; i++){
      cout << sirube.at(i) << endl;
    }
  }else{
    cout << "No";
  }

  
}


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

using namespace std;

int main(){
    int n, m;
    scanf("%d %d", &n, &m);
    long int x[n], y[n], z[n];
    for(int i = 0; i < n; i++){
        scanf("%ld %ld %ld", &x[i], &y[i], &z[i]);
    }
    long int max = 0;
    for(int i = -1; i < 2; i += 2){
        for(int j = -1; j < 2; j += 2){
            for(int k = -1; k < 2; k += 2){
                long int a[n];
                for(int l = 0; l < n; l++){
                    a[l] = x[l] * i + y[l] * j + z[l] * k;
                    // printf("%d ", a[l]);
                }
                // puts("");

                sort(a, a + n);
                long int c = 0;
                for(int l = n - 1; l > n - m - 1; l--){
                    c += a[l];
                    // printf("%d ", a[l]);
                }
                // puts("");
                if (c >= max) max = c;
            }
        }
    }
    printf("%ld\n", max);
}

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

int n, a[52];

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

	long double las = a[0];
	for (int i=1; i<n; ++i)
		las = (las+a[i])*0.5;

	printf("%.7Lf\n", las);

	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ



	        Scanner sc = new Scanner(System.in);
	        int[] a = new int[7];
	        for (int i = 1; i < 7; i++) {
	            a[i] = sc.nextInt();
	        }

	        char[] b = sc.next().toCharArray();
	        for (int i = 0; i < b.length; i++) {
	            if (b[i] == 'N') {
	                a[0] = a[1];
	                a[1] = a[2];
	                a[2] = a[6];
	                a[6] = a[5];
	                a[5] = a[0];

	            } else if (b[i] == 'S') {
	            	a[0] = a[1];
	                a[1] = a[5];
	                a[5] = a[6];
	                a[6] = a[2];
	                a[2] = a[0];

	            } else if (b[i] == 'E') {
	            	a[0] = a[1];
	                a[1] = a[4];
	                a[4] = a[6];
	                a[6] = a[3];
	                a[3] = a[0];

	            } else {
	            	a[0] = a[1];
	                a[1] = a[3];
	                a[3] = a[6];
	                a[6] = a[4];
	                a[4] = a[0];
	               ;
	            }
	        }
	        System.out.println(a[1]);

	}



}

//途中



Measured memory_bytes: 26368
#include<bits/stdc++.h>
#include<boost/multiprecision/cpp_int.hpp>
using namespace std;
using namespace boost::multiprecision;
#define BEGIN ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define END return EXIT_SUCCESS
#define rep(I,N) for(auto I=0;I<(N);++I)
#define up(I,A,B) for(auto I=(A);I<=(B);++I)
#define dw(I,A,B) for(auto I=(A);I>=(B);--I)
#define all(C) (C).begin(),(C).end()
#define rall(C) (C).rbegin(),(C).rend()
#define ft first
#define sd second
#define mp make_pair
#define mt make_tuple
#define pf push_front
#define pb push_back
#define pt pop_front
#define pk pop_back
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define rs resize
template<class T> T count_bit(T p){
  if(typeid(p)==typeid(int))return __builtin_popcount(p);
  else if(typeid(p)==typeid(long))return __builtin_popcountl(p);
  else return __builtin_popcountll(p);
}
template<class T>inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;}
template<class T>inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;}
template<class T>inline void                                      in(T &p){cin>>p;}
template<class T1,class T2>inline void                            in(T1 &p1,T2 &p2){cin>>p1>>p2;}
template<class T1,class T2,class T3>inline void                   in(T1 &p1,T2 &p2,T3 &p3){cin>>p1>>p2>>p3;}
template<class T1,class T2,class T3,class T4>inline void          in(T1 &p1,T2 &p2,T3 &p3,T4 &p4){cin>>p1>>p2>>p3>>p4;}
template<class T1,class T2,class T3,class T4,class T5>inline void in(T1 &p1,T2 &p2,T3 &p3,T4 &p4,T5 &p5){cin>>p1>>p2>>p3>>p4>>p5;}
template<class T>inline void                                      ins(T &p){for_each(all(p),in<decltype(p[0])>);}
template<class T>inline void                             out(T p){cout<<p<<endl;}
template<class T1,class T2>inline void                   out(T1 p1,T2 p2){cout<<p1<<" "<<p2<<endl;}
template<class T1,class T2,class T3>inline void          out(T1 p1,T2 p2,T3 p3){cout<<p1<<" "<<p2<<" "<<p3<<endl;}
template<class T1,class T2,class T3,class T4>inline void out(T1 p1,T2 p2,T3 p3,T4 p4){cout<<p1<<" "<<p2<<" "<<p3<<" "<<p4<<endl;}
inline                                              void out(double p){printf("%.10f\n",p);}
template<class T>inline                             void outs(T p){for_each(all(p),out<decltype(p[0])>);}

inline void solve(void){
  long a,b;
  in(a,b);
  if((a+b)%2==0)out((a+b)/2);
  else out("IMPOSSIBLE");
}
int main(int argc,char**argv){
  BEGIN;
  solve();
  END;
}


Measured memory_bytes: 256
import sys
lines = [s.rstrip("\n") for s in sys.stdin.readlines()]
n = int(lines.pop(0))
v_list = [int(num) for num in lines.pop(0).split(" ")]
c_list = [int(num) for num in lines.pop(0).split(" ")]
ans = 0
for v, c in zip(v_list, c_list):
    if v > c:
        ans += (v - c)
print(ans)


Measured memory_bytes: 9076
#include<iostream>
#include<set>
#include <bitset>
#include<queue>
#include<vector>
#include<map>
#include<stack>
#include <cstdio>
#include<algorithm>
#include <sstream>
#include<string.h>
#include <cmath>
#include <iomanip>
#include <string>
#include<list>
#include <limits>
#include <numeric>
#include <type_traits>
#define int long long
#define ll long long
#define mod  1000000007
#define MOD  1000000007
#define inf 1e17
#define rep(i,j,n) for(int i=j;i<n;i++)
#define P pair<int,int>
#define ps push_back
#define all(x) x.begin(),x.end()
double pi = 3.141592653589793;
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
//ここから始めよう
signed main(){
    int n;cin>>n;
    vector<vector<int>> v;
    rep(i,0,n){
        int a,b;cin>>a>>b;
        v.ps({a+b,a,b});
    }
    sort(all(v));
    reverse(all(v));
    int ans=0;
    rep(i,0,n){
        if(i%2==0)ans+=v[i][1];
        else ans-=v[i][2];
    }cout<<ans<<endl;return 0;
}

Measured memory_bytes: 6836
#include <iostream>
#include <iomanip>
#include <map>
typedef long long ll;
using namespace std;
const ll INF = 1e9;
const ll MOD = 1e9 + 7;
#define repi(i, n, init) for (ll i = init; i < (n); i++)

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

    map<int, int> mp;
    int ans = 0;

    repi(i, n, 0)
    {
        int a;
        cin >> a;
        mp[a]++;
        if (mp[a] % 2 == 0)
            ans --;
        else ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4864
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder.Abc
{
    class A_165_WeLoveGolf
    {
        // https://atcoder.jp/contests/abc165/tasks/abc165_a

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

            // 整数の入力
            int K = int.Parse(Console.ReadLine());

            // 整数配列の入力
            var array = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();
            int A = array[0];
            int B = array[1];

            for (int i = A; i < B + 1; i++)
            {
                if (i % K == 0)
                {
                    Console.WriteLine("OK");
                    break;
                }
                else if (i == B)
                {
                    Console.WriteLine("NG");
                }
            }
                Console.Out.Flush();

        }
    }
}


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

int n, a[10010][10010], z;
bool vis[10010], flag;
bool ok() {
  for (int i = 1; i <= n; ++i)
    if (a[i][0] != n) return 0;
  return 1;
}

int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= n - 1; ++j) cin >> a[i][j];
    a[i][0] = 1;
  }
  while (1) {
    if (ok()) {
      cout << z << '\n';
      return 0;
    }
    flag = 0;
    z++;
    memset(vis, 0, sizeof vis);
    for (int i = 1; i <= n; ++i) {
      if (vis[i] || a[i][0] == n) continue;
      int x = a[i][a[i][0]];
      if (a[x][a[x][0]] == i && !vis[i] && !vis[x]) {
        ++a[i][0];
        ++a[x][0];
        vis[i] = vis[x] = 1;
        flag = 1;
      }
    }
    if (!flag) {
      cout << -1 << '\n';
      return 0;
    }
  }
  return 0;
}


Measured memory_bytes: 39552
#include<bits/stdc++.h>
using namespace std;
#define speed ios_base::sync_with_stdio(false) , cin.tie(NULL) , cout.tie(NULL);

int main()
{
    speed;

    int n,l;
    cin>>n>>l;

    vector<string>v(n);
    string s,ans;

    for(int i=0;i<n;i++) cin>>v[i];

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

    for(int i=0;i<n;i++) ans+=v[i];

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

Measured memory_bytes: 3656
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repI(i, d, n) for (int i = (d); i < (n); ++i)
#define reps1(i, n) for (int i = 1; i < (n); ++i)
using namespace std;
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; }

using ll = long long;
using P = pair<int, int>;
using Pl = pair<ll, ll>;
using M = map<int, int>;
ll const INF = 1ll<<61;
double pi = 3.141592653589793238;

int main() {
  ll n;
  string s, t;
  cin >> n;
  cin >> s >> t;
  string ans = "";
  rep(i, n) {
    ans += s[i];
    ans += t[i];
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
def binom(n,r):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n-r] % p

def power(n,r):
    res = 1
    for i in range(r):
        res *= n
        res %= p
    return res

n,m,k = list(map(int, input().split()))

p = 998244353

fact = [1, 1]
factinv = [1, 1]
inv = [0, 1]
 
for i in range(2, n + 1):
    fact.append((fact[-1] * i) % p)
    inv.append((-inv[p % i] * (p // i)) % p)
    factinv.append((factinv[-1] * inv[-1]) % p)

num = 0

pw = (m-1)**(n-k-1) % p

for i in range(k+1):
    num += m * pw * binom(n-1, k - i)
    num %= p
    pw *= m-1
    pw %= p

print(num)

Measured memory_bytes: 34504
//package com.karancp;

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.*;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.io.InputStream;


 class Main {
    public static void main(String args[])
    {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader z = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        task solver =new task();
        solver.solve(z,out);
        out.close();
    }

    static class task
    {

        static long gcd(long a,long b)
        {
            if(b==0)return a;
            else return gcd(b,a%b);
        }
        static long lcm(long a,long b)
        {
            long pp=a*b;
            long bb=gcd(a,b);
            long res =pp/bb;
            return res;
        }
        static int max(int a,int b)
        {
            return Math.max(a,b);
        }
        static int min(int a,int b)
        {
            return Math.min(a,b);
        }





        public static void solve(InputReader z, PrintWriter out) {
          String s=z.next();
          String a="";a+=s.charAt(0);a+=s.charAt(1);
          String b="";
          b+=s.charAt(2);b+=s.charAt(3);
          //out.println(a+" "+b);
          int aa=Integer.valueOf(a);
          int bb=Integer.valueOf(b);
          if(aa==0&&bb==0)
          {
              out.println("NA");
          }
          else if(aa==0)
          {
              if(bb<=12)
              {
                  out.println("YYMM");
              }
              else
              {
                  out.println("NA");
              }
          }
          else if(bb==0)
          {
              if(aa<=12)
              {
                  out.print("MMYY");
              }
              else out.println("NA");
          }
          else if(aa>12&&bb<=12)
          {
              out.println("YYMM");
          }
          else if(aa<=12&&bb<=12)
          {
              out.println("AMBIGUOUS");
          }
          else if(aa<=12&&bb>12)
          {
              out.println("MMYY");
          }
          else
          {
              out.println("NA");
          }
        }
    }
    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }
        public long nextLong() {
            return Long.parseLong(next());
        }

    }



}

Measured memory_bytes: 23124
import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) throws IOException{
        BufferedReader f = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
        int k = Integer.parseInt(f.readLine());
        long sum = 0;
        for(int i = 1; i <= k; i++){
            for(int j = 1; j <= k; j++){
                for(int jj = 1; jj <= k; jj++){
                    sum+=gcd(gcd(i, j), jj);
                }
            }
        }
        out.println(sum);
        out.close();
    }

    public static long gcd(long a, long b){
        while(b != 0){
            long t = b;
            b = a%b;
            a = t;
        }
        return a;
    }
}


Measured memory_bytes: 32812
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int N = sc.nextInt();
		int[] a = new int[N];
		for(int i=0; i<N; i++)
			a[i] = sc.nextInt();
		Arrays.sort(a);
		
		int ai = a[N-1];
		int aj = a[0];
		for(int i=1; i<N-1; i++) {
			if(Math.min(a[i], ai-a[i]) > Math.min(aj, ai-aj))
				aj = a[i];
		}
		System.out.println(ai + " " + aj);
		sc.close();
	}
}


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

using namespace std;

int main()
{
    int N;
    cin>>N;
    int arr[N];
    int ans = 0;
    for(int i=0; i<N; i++){
        cin>>arr[i];
    }
    int current = 1;
    for(int i=1; i<N; i++){
        if(arr[i] == arr[i-1]){
            current += 1;
        }
        else{
            ans += current/2;
            current = 1;
        }
    }
    ans += current/2;
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
using namespace std;
#define MOD 1000000007
#define INF (1<<29)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long Int;
typedef pair<Int, Int> P;


Int res;



Int mod_pow(Int x, Int a, Int m = MOD){
  if(a == 0)return 1;
  Int res = mod_pow(x, a / 2, m);
  res = res * res % m;
  if(a % 2)res *= x;
  return res % m;
}

Int inv(Int x, Int m = MOD){
  return mod_pow(x, m-2, m);
}

Int cnt1(Int x, Int y){
  return ((mod_pow(10, x) - mod_pow(10, x-1)) % MOD  + 1 - y) % MOD;
}

Int keta(Int x){
  if(x < 10)return 1;
  if(x < 100)return 2;
  if(x < 1000)return 3;
  if(x < 10000)return 4;
  if(x < 100000)return 5;
  if(x < 1000000)return 6;
  if(x < 10000000)return 7;
  if(x < 100000000)return 8;
  return 9;
}

Int s;
int main(){
  cin >> s;
  int cnt = 0;
  int r = 1;
  for(int l = 1;l < 100000000;l++){
    while(cnt < s){
      cnt += keta(r++);
    }
    if(cnt == s)res++;
    cnt -= keta(l);
  }
  for(int i = 1;i*i <= s;i++){
    if(s % i)continue;
    int j = s / i;
    if(i >= 9)res += cnt1(i, j);
    if(j > i && j >= 9)res += cnt1(j, i);
  }
  for(int i = 1;i <= s / 9;i++){
    if(s % i)res++;
    res %= MOD;
  }
  if(res < 0)res += MOD;
  cout << res << endl;
  
  return 0;
}

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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}


int nextInt() { int x; scanf("%d", &x); return x;}

const int MAX_N = 212345;
ll A[MAX_N];
int N;

ll f(int b) {
  ll res = 0;
  REP(i, N) {
    res += abs(A[i] - (b+i+1));
  }
  return res;
}

ll search() {
  ll lo = 0;
  ll hi = 1LL << 60;
  while (hi - lo >= 3) {
    ll l = (lo * 2 + hi) / 3;
    ll r = (lo + hi * 2) / 3;
    if (f(l) > f(r)) lo = l; else hi = r; // min: > , max: <
  }
  ll minVal = f(lo);
  for (ll i = lo + 1; i <= hi; i++)
    minVal = min(minVal, f(i));
  return minVal;
}

int main2() {
  N = nextInt();
  REP(i, N) A[i] = nextInt();
  ll ans = search();
  cout << ans << endl;
  return 0;
}

int main() {
  for (;!cin.eof();cin>>ws)
    main2();
  return 0;
}


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

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

int W,H,N;
int X,Y,A;
int dp[101][101];

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>W>>H>>N;
	while(N--) {
		cin>>X>>Y>>A;
		if(A==1) {
			FOR(y,H) FOR(x,X) dp[y][x]=1;
		}
		if(A==2) {
			FOR(y,H) for(x=X;x<W;x++) dp[y][x]=1;
		}
		if(A==3) {
			FOR(x,W) FOR(y,Y) dp[y][x]=1;
		}
		if(A==4) {
			FOR(x,W) for(y=Y;y<H;y++) dp[y][x]=1;
		}
	}
	int ret=0;
	FOR(x,W) FOR(y,H) ret+=1-dp[y][x];
	cout<<ret<<endl;
	
}


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


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
const int INF=1145141919,MOD=1e9+7;
const long long LINF=8931145141919364364,LMOD=998244353;
// const int dx[]={1,0,-1,0,1,1,-1,-1},dy[]={0,-1,0,1,1,-1,-1,1};

int 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
x,y=list(map(int, input().split()))
z=[0]*x
for i in range(y):
	a,b=list(map(str, input().split()))
	a=int(a)
	if b=='AC' and z[a-1]<10**6:
		z[a-1]=z[a-1]+10**6
	if b=='WA' and z[a-1]<10**6:
		z[a-1]=z[a-1]+1
for i in range(x):
	if z[i]//(10**6)==0:
		z[i]=0
ansa=str(sum(z)//(10**6))
ansb=str(sum(z)%(10**6))
print(ansa+' '+ansb)

Measured memory_bytes: 6980
double x[100][100],y[100][100],r,z;
main(n,m,i,j,k){for(;scanf("%d%d",&n,&m),m;printf("%.2f\n",r)){
memset(x,0,sizeof(x));
for(i=0;i<n;i++)for(j=0;j<n;j++)scanf("%lf",y[i]+j);
for(j=0;j<n;j++)x[0][j]=1;
for(i=1;i<m;i++)for(j=0;j<n;j++)for(k=0;k<n;k++)if(x[i][j]<(z=x[i-1][k]*y[k][j]))x[i][j]=z;
for(r=j=0;j<n;j++)r=r<x[m-1][j]?x[m-1][j]:r;
}exit(0);}

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

typedef long long ll;

#define rep(i, a, n) for (ll i = a; i < (ll)n; ++i)
#define INF 10e9
#define MOD 1000000000 + 7
#define MAX 51000
#define all(x) (x).begin(), (x).end()
#define MX(x) *max_element(all(x))
#define MN(x) *min_element(all(x))

using namespace std;

int main(void)
{
    ll n;
    cin >> n;
    vector<ll> v(n);
    rep(i, 0, n) cin >> v[i];
    int x = 0;
    if (n % 2 == 1)
        x = 1;
    for (int i = n - 1; i >= 0; i -= 2)
        cout
            << v[i] << " ";
    for (int i = x; i < n; i += 2)
        cout << v[i] << " ";
    cout << endl;
}

Measured memory_bytes: 4772
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n,m,r,l,a,maxL=0,minR=100100; cin>>n>>m;
  for(int i=0;i<m;i++){
    cin>>l>>r;
    maxL=max(l,maxL),minR=min(r,minR);
  }
  a=minR-maxL+1;
  cout<<(a<0?0:a);
}

Measured memory_bytes: 3560
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
//FILE *fi = freopen("1.txt", "r", stdin);
//FILE *fo = freopen("1", "w", stdout);
int n;
int a[101];
bool T(int a, int b, int c)
{
    return a < b + c && a > abs(b - c);
}
bool check(int a, int b, int c)
{
    return T(a, b, c) && T(b, c, a) && T(a, c, b) && T(c, a, b);
}
int main()
{
    cin >> n;
    int ans = 0;
    for (int i = 1; i <= n; i++)
    {
        cin >> a[i];
    }
    for (int i = 1; i <= n; i++)
    {
        for (int j = 1; j < i; j++)
        {
            for (int k = 1; k < j; k++)
            {
                if (a[i] != a[j] && a[i] != a[k] && a[j] != a[k] && check(a[i], a[j], a[k]))
                    ans++;
            }
        }
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 3632
import Data.List
import Data.Array.IArray

main :: IO ()
main = do
    [d,n] <- map read . words <$> getLine :: IO [Int]
    let arr = listArray (0,n-1) [ i | i <- [1..], f i == d ] :: Array Int Int
    print $ arr!(n-1)
  where
    f x | x `rem` 100 /= 0 = 0
        | otherwise = 1 + f (x `div` 100)


Measured memory_bytes: 508
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
#include<unordered_map>
#include<fstream>
#include<list>
#include<functional>
#include<bitset>
#include<complex>
#include<tuple>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pi;
typedef pair<double,double> pd;
typedef pair<double,ll> pdl;
#define F first
#define S second
const ll E=1e18+7;
const ll MOD=1000000007;

vector<ll> & T(vector<ll> &ret,vector<ll> A,vector<ll> B){
    for(int i=0;i<B.size();i++){
        ret[i]=A[B[i]];
    }
    return ret;
}



int main(){
    ll n;
    cin>>n;
    vector<ll> x(n);
    for(auto &i:x){cin>>i;}
    ll m,k;
    cin>>m>>k;
    vector<ll> A(m);
    for(auto &i:A){cin>>i;}
    vector<ll> a(n-1);
    vector<ll> ans(n-1);
    for(int i=0;i+1<n;i++){ans[i]=a[i]=i;}
    for(int i=0;i<m;i++){
        A[i]--;
        swap(a[A[i]-1],a[A[i]]);
    }
    while(k>0){
        if(k&1){T(ans,ans,a);}
        T(a,a,a);
        k>>=1;
    }
    vector<ll> dp(n,x[0]);
    for(int i=0;i<n-1;i++){
        dp[i+1]=dp[i]+x[ans[i]+1]-x[ans[i]];
    }
    for(int i=0;i<n;i++){
        cout<<dp[i]<<endl;
    }
    
    
    return 0;
}


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

int main(){
    int l, r; 
    cin >> l >> r;
    int d;
    cin >> d;
    int cnt = 0;
    for(int i = l; i <= r; i++){
        if(i % d == 0) cnt++;
    }
    cout << cnt << endl;
}

Measured memory_bytes: 3600
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef string str;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector <pii> vpii;
typedef vector <pll> vpll;
typedef map <str,int> mapsi;
typedef map <str,int> :: iterator mapsitr;
typedef map <int , int> mint;
typedef map <ll , ll> mll;
typedef set <int> si;
typedef set <ll> sll;
typedef si :: iterator sitr;
typedef si :: reverse_iterator rsitr;
typedef sll :: iterator sltr;
typedef sll :: reverse_iterator rsltr;
#define mset multiset
typedef mset <int> msi;
typedef mset <ll> msll;
typedef msi :: iterator msitr;
typedef msi :: reverse_iterator msritr;
typedef msll :: iterator msltr;
typedef msll :: reverse_iterator mslritr;
#define mp make_pair
#define pb push_back
#define pob pop_back
#define fi first
#define se second
#define fs first.second
#define ss second.second
#define ff first.first
#define sf second.first
#define newl '\n'
char to_upper (char x){
    if( 97 <= int(x) && int(x) <= 126)return char(x-32);
    else if( 65 <= int(x) && int(x) <= 90)return x;
}
char to_lower (char x){
    if( 97 <= int(x) && int(x) <= 126)return x;
    else if( 65 <= int(x) && int(x) <= 90)return char(x+32);
}
int numerize (char x){
    if(48 <= int(x) && int(x) <= 57)return int(x-'0');
    else if( 97 <= int(x) && int(x) <= 126)return int(x-96);
    else if( 65 <= int(x) && int(x) <= 90)return int(x-64);
}
//void IO(){
//	#ifndef ONLINE_JUDGE
//	    freopen("input.txt", "r", stdin);
//	    freopen("output.txt", "w", stdout);
//	#endif
//}
// end of Template

int n,c,ans;
int trans[5][40],d[40][40];
vi v[4];
void solve (){
    for(int i=1;i<=c;i++){
        for(int j=1;j<=c;j++){
            if(j==i)continue;
            else{
                for(int k=1;k<=c;k++){
                    if(k==i || k==j){continue;}
                    else{
                        int res = 0;
                        res = trans[0][i] + trans[1][j] + trans[2][k];
                        ans = min(ans,res);

                    }
                }
            }
        }
    }

}
int main(){
	//IO();
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin>>n>>c;
    for(int i=1;i<=c;i++){
        for(int j=1;j<=c;j++){
            cin>>d[i][j];
        }
    }
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            int temp;
            cin>>temp;
            v[(i+j)%3].pb(temp);
        }
    }
    for(int i=0;i<3;i++){
        for(int color = 1; color <= c; color++){
            for(int j=0;j<v[i].size();j++){
                trans[i][color] += d[v[i][j]][color];
            }
        }
    }
    ans = INT_MAX;
    solve();
    cout<<ans<<newl;
}


Measured memory_bytes: 1520
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<cmath>
using namespace std;
#define ll long long
const int MAXN=15;
const int MAXS=(1<<MAXN);
const int MOD=1000000007;
int n,m,S,tot=1;
int f[MAXS+5],cnt[MAXS+5],to[MAXN+10];
int main()
{
	scanf("%d%d",&n,&m);S=(1<<n)-1;
	for(int i=0,u,v;i<m;++i)
	{
		scanf("%d%d",&u,&v);
		to[--u]^=(1<<(--v));
		tot=(tot+tot)%MOD;
	}
	for(int j=0;j<n;++j)for(int i=S;~i;--i)cnt[i]+=((i>>j)&1);
	f[0]=1;
	for(int i=0,la,x,y,w;i<S;++i)
	{
		la=S^i;if((i&3)&&(i&3)!=3)continue;
		for(int j=la;j;j=(j-1)&la)
		{
			x=i^j;if((x&3)&&(x&3)!=3)continue;
			y=S^x;w=f[i];
			for(int o=0;o<n;++o)
				if((y>>o)&1)w=(ll)w*((1<<cnt[j&to[o]])-1)%MOD;
				else if((j>>o)&1)w=((ll)w<<cnt[y&to[o]])%MOD;
			f[x]=(f[x]+w)%MOD;
		}
	}
	printf("%d",(tot+MOD-f[S])%MOD);
	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>  // ver1.8
#define int long long
#define ALL(v) (v).begin(),(v).end()
#define Vi vector<int>
#define pb push_back
#define mp make_pair
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repeq(i,a,b) for(int i=a;i<=b;i++)
#define repr(i,a,b) for(int i=a;i>b;i--)
#define repreq(i,a,b) for(int i=a;i>=b;i--)
#define leng(n) (int)(log10(n)+1)
#define INF 9000000000000000000  //  9.0 * 10^18
#define MOD 1000000007  //  10^9 + 7
#define PAI 3.14159265358979
using namespace std;

int gcd(int a,int b){return b?gcd(b,a%b):a;}  //  最大公約数gcd
int lcm(int a,int b){return a/gcd(a,b)*b;}  //  最小公倍数lcm

signed main() {
  cout << fixed << setprecision(14);
  int n,m;
  cin >> n >> m;
  Vi a(0);
  rep(i,0,n) a.pb(i+1);
  vector<pair<int,int>> line(m);
  int qw,er;
  rep(i,0,m){
    cin >> qw >> er;
    line[i] = mp(qw,er);
  }
  int ans = 0;
  bool ok1 = false;
  bool ok2 = false;
  do {
    if(a[0]!=1) break;
    ok2=false;
    
    rep(i,0,n-1){
      ok1=false;
      rep(j,0,m){
        if(mp(a[i],a[i+1])==line[j]) ok1 = true;
        if(mp(a[i+1],a[i])==line[j]) ok1 = true;
      }
      if(!ok1) break;
      if(i==n-2) ok2=true;
    }
    
    if(ok2) ans++;
  } while (next_permutation(ALL(a)));
  
  cout << ans << endl;
  
  return 0;
}


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

using namespace std;

#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl

typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); }
template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); }
template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
#define X first
#define Y second
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(n);i>0;i--)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(),c.end()
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 (a>b) { a = b; return 1; } return 0; }
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
const ll inf = 1000000001;
const ll INF = 1e18;
const ll MOD = 1000000007;
//const ll MOD = 998244353;
const double pi = 3.14159265358979323846;
#define Sp(p) cout<<setprecision(15)<< fixed<<p<<endl;
int dx[4] = { 1,0, -1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
#define fio() cin.tie(0); ios::sync_with_stdio(false);
//#define mp make_pair

int main() {
  ll n, k;
  cin >> n >> k;
  vii G(n);
  rep (i, n) {
    rep (j, n) {
      int t;
      cin >> t;
      if (t) {
        G[i].push_back(j);
      }
    }
  }
  int m = 61;
  vector<vll> dp1(m, vll(n, vl(n)));
  rep (i, n) {
    rep (j, G[i].size()) {
      dp1[0][i][G[i][j]] = 1;
    }
  }
  rep (i, m - 1) {
    rep (u, n) {
      rep (v, n) {
        rep (k, n) {
          dp1[i + 1][u][v] += (dp1[i][u][k] * dp1[i][k][v]) % MOD;
          dp1[i + 1][u][v] %= MOD;
        }
      }
    }
  }
  /*
  rep (i, m) {
    rep (j, n) {
      rep (k, n) {
        cout << dp1[i][j][k] << " ";
      }
      cout << endl;
    }
    cout << endl;
  }
  //*/
  vll dp2(m + 1, vl(n));
  rep (i, n) {
    dp2[0][i] = 1;
  }
  rep (i, m) {
    ll mask = 1LL << i;
    if ((k & mask) == 0) {
      rep (u, n) {
        dp2[i + 1][u] = dp2[i][u];
      }
    }
    else {
      rep (u, n) {
        rep (v, n) {
          dp2[i + 1][v] += (dp2[i][u] * dp1[i][u][v]) % MOD;
          dp2[i + 1][v] %= MOD;
        }
      }
    }
  }
  ll ans = 0;
  rep (i, n) {
    ans = (ans + dp2[m][i]) % MOD;
  }
  cout << ans << endl;
}


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

#define F first
#define S second
#define PB push_back
#define MP make_pair
#define REP(i,a,b) for (int i = a; i <= b; i++)
#define debug(i) cout << i << endl;
#define debugarr(a) for(auto i : a) cout << i << " ";

#define ll long long
#define vi vector<int>
#define vll vector<ll>
#define pi pair<int,int>
#define pll pair<ll, ll>
#define vpi vector<pi>

using namespace std;

int main() {
    ios_base::sync_with_stdio(false);

    string s;
    cin >> s;

    if(s == "SUN") cout << 7 << endl;
    else if(s == "MON") cout << 6 << endl;
    else if(s == "TUE") cout << 5 << endl;
    else if(s == "WED") cout << 4 << endl;
    else if(s == "THU") cout << 3 << endl;
    else if(s == "FRI") cout << 2 << endl;
    else cout <<1 << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    char s;
    cin >> s;
    if(s=='A'){
        cout << "T" << endl;
    } else if(s=='T'){
        cout << "A" << endl;
    } else if(s=='G'){
        cout << "C" << endl;
    } else if(s=='C'){
        cout << "G" << endl;
    } 
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define INF 100000000
#define EPS 1e-10
#define MOD 1000000007
using namespace std;
typedef pair<int,int> P;

int n, m;
int s[100], t[100];

int main(){
	while(cin >> n >> m){
		if(n == 0 && m == 0) break;
		int S = 0, T = 0;
		rep(i,n){
			cin >> s[i];
			S += s[i];
		}
		rep(i,m){
			cin >> t[i];
			T += t[i];
		}
		int ok = INF;
		int x, y;
		rep(i,n) rep(j,m){
			if(S+t[j]*2==T+s[i]*2 && s[i]+t[j] < ok){
				x = s[i];
				y = t[j];
				ok = s[i]+t[j];
			}
		}
		if(ok == INF) cout << "-1" << endl;
		else cout <<  x << " " << y << endl;
	}
}

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

int main()
{
	int a, b, c, sred;
	cin >> a >> b >> c;
	if((b-a)%2 == 0) sred = (b-a)/2;
	else sred = (b-a)/2+1;

	if(c > sred){
		for(int i=a; i<=b; i++){
			cout << i << endl;
		}
	}

	else if(c <= sred){
		for(int i=a; i<=a+c-1; i++){
			cout << i << endl;
		}
		for(int i=b-c+1; i<=b; i++){
			cout << i << endl;
		}
	}

    return 0;
}


Measured memory_bytes: 256
N = int(input())
S = list(input())

count = len([s for s in S[1:] if s == "E"])
min_count = count
for i in range(1, N):
    if S[i - 1] == "W":
        count += 1
    if S[i] == "E":
        count -= 1
    min_count = min(min_count, count)
print(min_count)


Measured memory_bytes: 10360