akhauriyash/Code-Regression huggingface dataset:
import itertools
import math

n = int(input())
p = tuple(map(int, input().split()))
q = tuple(map(int, input().split()))

arr = [i for i in itertools.permutations([i for i in range(1, n+1)])]

a = arr.index(p)
b = arr.index(q)
print(abs(a-b))


Measured memory_bytes: 13852
#include "bits/stdc++.h"
    #define REP(i, n) for(int i = 0; i < int(n); i++)
    #define FOR(i,n,m) for(int i = int(n); i < int(m); i++)
    using namespace std;
    typedef long long ll;
    const int MOD = 1e9 + 7;
    const int INF = 1e9 + 6;
    const ll LLINF = 1e18 + 1;
     
    int main() {
        int n, t; cin >> n >> t;
        vector<pair<int,int>> p(n);
        REP(i, n) cin >> p[i].first >> p[i].second;
        sort(p.begin(), p.end());
        // dp[i][j] : iまででj以内に食べるときの最大値
        vector < vector < ll >> dp(n + 1, vector<ll>(t + 1,0));
        REP(i, n) {
            REP(j, t+1) {
                dp[i + 1][j] = dp[i][j];
                if (j - p[i].first >= 0) dp[i + 1][j] = max(dp[i+1][j],dp[i][j - p[i].first] + p[i].second);
            }
        }
        ll ans = 0;
        REP(i, n) {
            REP(j, t) {
                ans = max({ans, dp[i][j] + p[i].second,dp[i + 1][j]});
            }
        }
        cout << ans << endl;
        return 0;
    }


Measured memory_bytes: 70784
#include<iostream>
#include<tuple>
#include<vector>
#include<queue>
#include<set>
#include<algorithm>
using namespace std;

#define INF ((int)(1e9))
#define MAX 110000

int n, k, a[MAX], q;

int main(){
	cin>>n;
	
	for(int i = 0; i < n; i++){
		cin>>a[i];
	}
	
	cin>>q;
	
	for(int i = 0; i < q; i++){
		cin>>k;
		cout<<lower_bound(a,a+n,k)-a<<" "<<upper_bound(a,a+n,k)-a<<endl;
	}
	
	return 0;
}


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

using namespace std;

int main() {
    char str[100000+1];
    scanf("%s", str);

    deque<char> deq;

    for(size_t i = 0; i < strlen(str); i++) {
        deq.push_back(str[i]);
    }

    int q_count;
    scanf("%d", &q_count);

    bool inversed = false;

    for(int i = 0; i < q_count; i++) {
        int type;
        scanf("%d", &type);
        if(type == 1) {
            inversed = !inversed;
        }else {
            int f;
            char c;
            scanf("%d %c", &f, &c);

            if(f == 1) {
                if(inversed) {
                    deq.push_back(c);
                }else {
                    deq.push_front(c);
                }
            }else {
                if(inversed) {
                    deq.push_front(c);
                }else {
                    deq.push_back(c);
                }

            }
        }
    }

    while(!deq.empty()) {
        if(inversed) {
            printf("%c", deq.back());
            deq.pop_back();
        }else {
            printf("%c", deq.front());
            deq.pop_front();
        }
    }
    printf("\n");
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
#define VI vector<int>
#define VVI vector<vector<int>>
#define REP(i, n) for (int i = 0; i < (n); i++)
#define MOD 1000000007
#define INF 1e9
#define All(x) (x).begin(), (x).end()
typedef long long ll;
using namespace std;

int main() {
  int n, m, x;
  cin >> n >> m >> x;
  int cnt = 0;
  for (int i = 0; i < m; i++) {
    int a;
    cin >> a;
    if (a < x) cnt++;
  }
  int ans = min(cnt, m - cnt);
  cout << ans << endl;
  return 0;
}


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

int main(){
	/*intput*/
	int n;	cin >> n;
	vector<double>a(n);
	for(int i = 0; i < n; i++){
		cin >> a[i]; 
	}
	/*calculaiton*/
	double sum = 0;
	for(int i = 0; i < n; i++){
		sum += 1/a[i];
	}
	/*output*/
	cout << 1/sum << endl;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {

    public static void main(String[] args) {
        // write your code here
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        HashMap<Character, Integer> map = new HashMap<>();
        for (int i = 0; i < s.length() ; i++) {
            char key = s.charAt(i);
            Integer v = map.get(key);
            map.put(key, v == null ? 1 : ++v);
        }
        int ans = Integer.MAX_VALUE;
        for (int i = 0; i < s.length(); i++) {
            int count = 0;
            char v = s.charAt(i);
            String t = s;
            while (true) {
                boolean isOK = true;
                StringBuilder builder = new StringBuilder();
                for (int j = 0; j < t.length() - 1; j++) {
                    if (t.charAt(j) != v) {
                        isOK = false;
                    }
                    if (t.charAt(j + 1) == v) {
                        builder.append(v);
                    } else {
                        builder.append(t.charAt(j));
                    }
                }
                if (isOK) {
                    if (t.charAt(t.length() - 1) != v) {
                        count++;
                    }
                    ans = Math.min(count, ans);
                    break;
                }
                t = builder.toString();
                count++;
            }
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 25336
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<numeric>
#include<map>
#include<iostream>
using namespace std;
#define rep(i,n) for(int i = 0;i<((int)(n));i++)
#define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(int i = ((int)(b));i>=((int)(a));i--)
typedef long long ll;
typedef pair<ll, ll> mp;

ll N,ans=1,last=0,MOD=1e9+7;
string S1,S2;

int main(void){
	cin>>N>>S1>>S2;
	rep(i,N){
		if(S1[i]==S2[i]){//縦
			if(last==0){
				ans=ans*3%MOD;
			}else if(last==1){
				ans=ans*2%MOD;
			}else if(last==2){
			}
			last = 1;
		}else{//横
			if(last==0){
				ans=ans*6%MOD;
			}else if(last==1){
				ans=ans*2%MOD;
			}else if(last==2){
				ans=ans*3%MOD;
			}
			last = 2;
			i++;
		}
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 256
s = input()

e = ["dream", "dreamer", "erase", "eraser"]

while True:
    flag = False
    for _e in e:
        if s[-len(_e):] == _e or s == _e:
            s = s[:len(s)-len(_e)]
            flag = True
    else:
        if flag:
            continue

        break

print("YES" if len(s) == 0 else "NO")


Measured memory_bytes: 3188
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#define N 1234560
int main(void){
    int p[N]={0};
    p[0]=1; p[1]=1;
    for(int i=2;i<=sqrt(N);i++){
        if(p[i]==0){
            for(int j=2*i;j<N;j+=i)
                p[j]=1;
        }
    }
    while(1){
        int a,d,n;
        scanf("%d%d%d",&a,&d,&n);
        if(a+d+n==0) break;
        int cnt=0;
        for(int i=0;;i+=d){
            if(!p[a+i]){
                cnt++;
                if(cnt==n){
                    printf("%d\n",a+i);
                    break;
                }
            }
        }
    }
}




Measured memory_bytes: 6520
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define repi(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define repdi(i,a,b) for(ll i=(a)-1;i>=(b);--i)
#define repd(i,a) repdi(i,a,0)
#define itr(it,a) for( auto it = (a).begin(); it != (a).end(); ++it )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()

using ll = long long;
using P = std::pair<ll, ll>;

constexpr ll INF = 1ll<<60;

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

template<class S, class T>
std::ostream& operator<< ( std::ostream& out, const std::pair<S,T>& a )
{ std::cout << '(' << a.first << ", " << a.second << ')'; return out; }

template<class T>
std::ostream &operator<< ( std::ostream& out, const std::vector<T>& a )
{ std::cout << '['; rep( i, a.size() ){ std::cout << a[i]; if( i != a.size()-1 ) std::cout << ", "; } std::cout << ']'; return out; }

ll N, M;
ll H[100010], ans;
std::vector<ll> G[100010];

int main()
{
  std::cin >> N >> M;

  rep( i, N )
    std::cin >> H[i];

  rep( i, M )
  {
    ll A, B;
    std::cin >> A >> B;
    --A; --B;
    G[A].emplace_back( B );
    G[B].emplace_back( A );
  }

  rep( i, N )
  {
    for( auto u : G[i] )
    {
      if( H[u] >= H[i] )
        goto end;
    }

    ++ans;
end:;
  }

  std::cout << ans << std::endl;

  return 0;
}

Measured memory_bytes: 9820
n = gets.chomp.to_i
alist = gets.chomp.split.collect{ |item| item.to_i}
result = 0
nexttype = 1
option = false
last = alist.pop
blist = []
alist.each do |num|
  result += num.abs
  if (num < 0 && nexttype == 1)
    nexttype = -1
  elsif  (num > 0 && nexttype == 1)
    nexttype = 1
  elsif  (num < 0 && nexttype == -1)
    nexttype = 1
  elsif  (num > 0 && nexttype == -1)
    nexttype = -1
  end
  if num == 0
    option = true
  end
  blist.push(num.abs)
end
result += last.abs
alist.push(last)
blist.push(last.abs)
min = blist.min
if (((nexttype * last) < 0) && (option == false))
  result -= min*2
end
puts result

Measured memory_bytes: 10636
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<string.h>
#include<math.h>
using namespace std;

int syc(long i,long Min,long Max){
	if(Min <= i && i <= Max){
		return 1;
	}else{
		exit(1);
		//return 0;
	}
}

int main(){
	int n;
	cin >> n;
	syc(n,1,100);
	int a[n];
	int max=0,sum=0;
	
	for(int i=0;i<n;i++){
		cin >> a[i];
		sum+=a[i];
		if(i==0){
			max=a[i];
		}else{
			if(a[i]>max)max=a[i];
		}		
	}

	if((sum-max) > max){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<set>
#define rep(i, start, end) for (int i = (int)start; i < (int)end; ++i)
#define rrep(i, start, end) for (int i = (int)start - 1; i >= (int)end; --i)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
template<typename T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return 0;}
template<typename T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return 0;}

using P = pair<int, int>;

const int INF = 1 << 30;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int H, W;
    cin >> H >> W;
    vector<int> A(H), B(H);
    rep(i, 0, H) {
        cin >> A[i] >> B[i];
        --A[i];
    }
    set<P> path;
    multiset<int> dist;
    rep(i, 0, W) {
        path.emplace(i, i);
        dist.insert(0);
    }
    rep(i, 0, H) {
        vector<P> buf;
        for (auto itr = path.lower_bound(P(A[i], 0)); itr != path.end() && (*itr).first < B[i]; ++itr) {
            buf.push_back(*itr);
        }
        int max_start = -INF;
        P max_path;
        for (auto& p : buf) {
            path.erase(p);
            dist.erase(dist.find(p.first - p.second));
            if (chmax(max_start, p.second)) {
                max_path = p;
            }
        }
        if (max_start > -INF) {
            path.emplace(B[i], max_path.second);
            dist.insert(B[i] == W ? INF : B[i] - max_path.second);
        }
        cout << (*dist.begin() == INF ? -1 : *dist.begin() + i + 1) << endl;
    }
    return 0;
}

Measured memory_bytes: 23504
import sys
 
 
def run():
    q = []
 
    for line in sys.stdin:
        if line.startswith("i"):
            v = int(line[7:])
            q.append(v)
            i = len(q) - 1
            while i > 0:
                p = (i-1) // 2
                vp = q[p]
                if vp < v:
                    q[p], q[i] = v, vp
                    i = p
                else:
                    break
        elif line.startswith("ex"):
 
            size = len(q) - 1
            if size < 0:
                raise ValueError('get from empty queue')
 
            v = q[0]
            last = q.pop()
            if size > 0:
                q[0] = last
                i = 0
                while i < size // 2:
                    top, vt = i, last
                    left = (i+1) * 2 - 1
                    right = (i+1) * 2
                    if left < size:
                        vl = q[left]
                        if vl > vt:
                            top, vt = left, vl
                    if right < size:
                        vr = q[right]
                        if vr > vt:
                            top, vt = right, vr
 
                    if top > i:
                        q[top], q[i] = last, vt
                        i = top
                    else:
                        break
            print(v)
        elif line.startswith("end"):
            break
        else:
            ValueError("invalid command")
 
 
if __name__ == '__main__':
    run()


Measured memory_bytes: 44692
import sys
from collections import deque
from copy import copy

N,K = list(map(int, input().split()))
V = deque(list(map(int, input().split())))

max_value = 0

def calc_max_value(V, K, k, l, r):
    store = deque([])
    for i in range(l):
        if len(V)>0:
            store.append(V.popleft())
            continue
        else:
            break
    for i in range(r):
        if len(V)>0:
            store.append(V.pop())
            continue
        else:
            break
    store = deque(sorted(store))
    for i in range(K-l-r):
        if len(store)>0:
            e = store.popleft()
            if e < 0:
                continue
            else:
                store.appendleft(e)
                break
        else:
            break
    max_value = sum(store)
    return max_value

    
for k in range(min(K+1,N+1)):
    for l in range(k+1):
        for r in range(k+1-l):
            max_value = max(max_value, calc_max_value(copy(V), K, k, l, r))

print(max_value)


Measured memory_bytes: 46684
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); ++i)
using namespace std;
typedef long long ll;
const int INF = 1001001001;

int main() {
    string T;

    cin >> T;

    rep(i,T.size()) {
        if (T[i] == '?') {
            if(T[i-1] == 'P') {
                T[i] = 'D';
            } else if(T[i+1] == '?') {
                T[i] = 'P';
            } else if(T[i+1] == 'D') {
                T[i] = 'P';
            } else {
                T[i] = 'D';
            }
        }
    }

    cout << T << endl;

    return 0;
    
}

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

int main() {
    int n, l;
    cin >> n >> l;
    vector<string> s(n);
    rep(i, n) cin >> s.at(i);
    sort(s.begin(), s.end());
    rep(i, n) cout << s.at(i);
    return 0;
}

Measured memory_bytes: 256
import sys
def input():
	return sys.stdin.readline()[:-1]

class BellmanFord():
	def __init__(self, adj, start):
		self.adj = adj
		self.start = start
		self.size = len(adj)
		self.dist = [10**30 for _ in range(self.size)]
		self.dist[self.start] = 0

	def solve(self):
		for _ in range(self.size-1):
			for x in range(self.size):
				for y, w in self.adj[x]:
					if self.dist[y] > self.dist[x] + w:
						self.dist[y] = self.dist[x] + w
		return

	#負閉路のせいでgoalへの距離が-infになるか
	def NegativeCycleToGoal(self, goal):
		res = self.dist[goal]
		for x in range(self.size):
			for y, w in self.adj[x]:
				if self.dist[y] > self.dist[x] + w:
					self.dist[y] = self.dist[x] + w
		if res != self.dist[goal]:
			return True
		else:
			return False

	def GetDistance(self, goal):
		return self.dist[goal]

n, m = map(int, input().split())
adj = [[] for _ in range(n)]
for _ in range(m):
	a, b, c = map(int, input().split())
	adj[a-1].append((b-1, -c))

bf = BellmanFord(adj, 0)
bf.solve()
if bf.NegativeCycleToGoal(n-1):
	print("inf")
else:
	print(-bf.GetDistance(n-1))

Measured memory_bytes: 3444
n = int(input())
# one - index
a = [0] + list(map(int,input().split())) + [0]
temp = 0
for i in range(n+1):
    temp += abs(a[i+1] - a[i])
for i in range(1,n+1):
    ans = temp + abs(a[i-1] - a[i+1]) - abs(a[i-1] - a[i]) - abs(a[i] - a[i+1])
    print(ans)


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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}
int N, M;
string s;
vector<int32> G[212345];
vector<int32> cnt;
bool visited[212345][2] = {};

bool ok(int32 v, int32 now){
	if(cnt[v] >> now & 1) return 1;
	cnt[v] |= 1 << now;
	REP(i, G[v].size()){
		if(visited[G[v][i]][now^1]) continue;
		if((s[G[v][i]] == s[v]) ^ (now == 1)){
			if(ok(G[v][i], now^1))
				return 1;
		}
	}
	visited[v][now] = 1;
	cnt[v] ^= 1 << now;
	return 0;
}

int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> N >> M;
	cnt.resize(N, 0);
	cin >> s;
	REP(i, M){
		int32 a, b;
		cin >> a >> b; a--; b--;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	REP(i, N){
		if(ok(i, 0)){
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;
}


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

class _Class
{
	void _()
	{
		var S = _Ss()[0];
		var c = new char[]{ 'C','F'};
		var x = 0;
		for (int i=0;i<S.Length;i++)
		{
			if (S[i] == c[x]) {
				x += 1;
				if (x==2) {
					Console.WriteLine("Yes");
					return;
				}

			}
		}

		Console.WriteLine("No");

	}

	static void Main(string[] args)
  {
    new _Class()._();
  }

  #region

  string _S()
  {
    return Console.ReadLine();
  }

  string[] _Ss()
  {
    return Console.ReadLine().Split();
  }

  int[] _N(int n)
  {
    var x = new int[n];
    for (var i = 0; i < n; i++)
    {
      x[i] = int.Parse(Console.ReadLine());
    }
    return x;
  }

  int[] _Ns()
  {
    var ss = Console.ReadLine().Split();

    var x = new int[ss.Length];
    for (var i = 0; i < ss.Length; i++)
      x[i] = int.Parse(ss[i]);

    return x;
  }
  #endregion
}


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

int h[100000], dp[100000];

int main() {
  ios::sync_with_stdio(0); cin.tie(0);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) cin >> h[i];
  fill_n(dp, n, 2e9);
  dp[0] = 0;
  for (int i = 0; i < n; i++) {
    if (i+1 < n)
      dp[i+1] = min(dp[i+1], dp[i]+abs(h[i+1]-h[i]));
    if (i+2 < n)
      dp[i+2] = min(dp[i+2], dp[i]+abs(h[i+2]-h[i]));
  }
  cout << dp[n-1] << endl;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
// #define ll long long int
#define int long long int
#define N 10000005
#define MOD 1000003

int fact[N], inv[N], finv[N];

int mexp(int a, int b)
{
	int res = 1;
	while(b)
	{
		if(b & 1)
			res = res * a % MOD;
		b >>=1;
		a = a * a % MOD;
	}
	return res;
}

void make()
{
	fact[0] = fact[1] = 1;
	inv[1] = 1;
	finv[1] = finv[0] = 1;
	for (int i = 2; i <= N; ++i)
	{
		fact[i] = fact[i - 1] * i % MOD;
		inv[i] = MOD - (MOD/i) * inv[MOD % i] % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

int32_t main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);

	make();
	int q;
	int x, d, n;

	cin >> q;

	while(q--)
	{
		cin >> x >> d >> n;
		if(d == 0)
		{
			cout << mexp(x, n) << "\n";
		}
		else
		{
			int k = x * inv[d] % MOD;
			// cout << "k : " << k << '\n';
			int ans;
			if(k + n - 1 >= MOD)
				ans = 0;
			else
			{
				ans = fact[k + n - 1] * finv[k - 1] % MOD;
				ans = ans * mexp(d, n) % MOD;
			}
			cout << ans << "\n";
		}
	}
	return 0;
}	

Measured memory_bytes: 235264
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;
int main() {
	cin.tie(0); ios::sync_with_stdio(false);
	int N; cin >> N;
	string kanban; cin >> kanban;
	int ans = 0;
	for (int n = 0; n < N;n++) {
		string str; cin >> str;
		bool flag = false;
		for (int i = 0; i < str.size();i++) {
			if (str[i] != kanban[0])continue;
			for (int j = i + 1; j < str.size();j++) {
				if (str[j] != kanban[1]) continue;

				int at = j;
				int dif = j - i;
				bool f = true;
				at += dif;
				for (int k = 2; k < kanban.size();k++) {
					if (at >= str.size()) { f = false; break; }
					if (kanban[k] != str[at]) { f = false; break; }
					at += dif;
				}
				if (f) {
					ans++;
					flag = true;
					break;
				}
			}
			if (flag)break;
		}
	}

	cout << ans << endl;
}

Measured memory_bytes: 3208
#include<cstdio>
const int N=600005;
int n,m,v[N],t,x=0;char c[N];
int main()
{
	scanf("%d%d%s",&n,&m,c+1),t=1;
	for(int i=1;i<=n;++i)v[i]=c[i]=='A';
	for(int i=1;i<=2*n&&i<=m;++i)if(v[t]^x)v[t]^=1;else ++t,x^=1,v[t+n-1]=x^1;
	if(m<=2*n)for(int i=t;i<=t+n-1;++i)printf("%c",v[i]^x?'A':'B');
	else{printf("%c",v[t]^x^((n&1)&(m-2*n&1))?'A':'B');for(int i=t+1;i<=t+n-1;++i)printf("%c",v[i]^x?'A':'B');}
	return 0;
}

Measured memory_bytes: 3812
#include<bits/stdc++.h>
#define mod (long)(1e9 + 7)
using namespace std;

long dp[21][(1<<21)];

long solve(int curr, int mask, int a[][21], int n) {
	// cout<< curr <<" " << mask <<"\n";
	if(curr == n) return 1;
	if(dp[curr][mask] != -1) return dp[curr][mask];
	long res = 0;
	for(int i = 0; i < n; ++i) {
		// cout<<a[curr][i]<<"->"<<((mask>>i)&1)<<"\t";
		if(a[curr][i] && ((mask>>i)&1) == 0) {
			res = (res + solve(curr + 1, mask | (1<<i), a, n))%mod;
		} 
	}
	// cout<<"*";
	return dp[curr][mask] = res;
}

int main() {
	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
	int n;
	cin >> n;
	int a[n][21];
	for(int i = 0; i < n; ++i) {
		for(int j = 0; j < n; ++j) {
			cin >> a[i][j];
		}
	}
	memset(dp, -1, sizeof dp);
	cout<<solve(0, 0, a, n);
	return 0;
}

Measured memory_bytes: 347604
#pragma region template 2.4
#include <bits/stdc++.h>
using namespace std;
template <typename T>
using pq_asc = priority_queue<T, vector<T>, greater<T>>;
typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll, ll> ii;
typedef vector<ii> vii;
typedef vector<string> vs;
#define REP(i, n) for (ll i = 0; i < (n); ++i)
#define REP1(i, n) for (ll i = 1; i <= (n); ++i)
#define FOR(i, a) for (auto &i : a)
#define CH(f, x, y) x = f(x, y)
#define IN(T, x) \
    T x;         \
    cin >> x;
#define AIN(T, a, n) \
    vector<T> a(n);  \
    FOR(i, a)        \
    cin >> i;
#define A2IN(T1, a, T2, b, n) \
    vector<T1> a(n);          \
    vector<T2> b(n);          \
    REP(i, n)                 \
    cin >> a[i] >> b[i];
#define OUT(x) cout << (x) << endl;
#define FOUT(x) cout << fixed << setprecision(15) << (x) << endl;
#define ALL(a) (a).begin(), (a).end()
#define SORT(a) sort(ALL(a))
#define RSORT(a) \
    SORT(a);     \
    reverse(ALL(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define DUMPA(a)          \
    cout << #a << " = {"; \
    JOUT(ALL(a), ", ", cout) << "}" << endl;

template <typename T>
ostream &JOUT(T s, T e, string sep = " ", ostream &os = cout)
{
    if (s != e)
    {
        os << *s;
        ++s;
    }
    while (s != e)
    {
        os << sep << *s;
        ++s;
    }
    return os;
}

ostream &YES(bool cond, string yes = "Yes", string no = "No", ostream &os = cout)
{
    if (cond)
    {
        os << yes << endl;
    }
    else
    {
        os << no << endl;
    }
    return os;
}

template <typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p)
{
    os << '(' << p.first << ", " << p.second << ')';
    return os;
}

template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v)
{
    os << '[';
    JOUT(ALL(v), ", ", os) << ']';
    return os;
}

const ll INF = 1e18;
const ll MOD = 1e9 + 7;
#pragma endregion template

int main()
{
    IN(ll, R);
    OUT(2 * M_PI * R);
}

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

#define FOR(i, j, k) for(int i = j; i < k; i++)
#define REP(i, j) FOR(i, 0, j)
#define fst first
#define snd second
#define pb push_back
#define eb emplace_back
#define all(obj) (obj).begin(), (obj).end()
#define rall(obj) (obj).rbegin(), (obj).rend()
typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;

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

template <typename T> istream &operator>>(istream &is, vector<T> &vec) {
    for(T &x : vec) {
        is >> x;
    }
    return is;
}

int main() {

    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(10);
    cout << fixed;

    int n;
    cin >> n;
    vi a(n);
    cin >> a;

    vi b(n);
    for(int i = n; i > 0; i--) {
        for(int j = i * 2; j <= n; j += i) {
            b[i - 1] ^= b[j - 1];
        }
        b[i - 1] ^= a[i - 1];
    }

    vi c;
    REP(i, n) {
        if(b[i] > 0) {
            c.push_back(i + 1);
        }
    }

    cout << c.size() << endl;
    REP(i, c.size()) { cout << c[i] << " "; }
    cout << endl;

    return 0;
}


Measured memory_bytes: 3192
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws FileNotFoundException {
		new Main().run();
	}

	class Edge implements Comparable<Edge> {
		int[] id;
		int cost;

		public Edge(int id1_, int id2_, int cost_) {
			id = new int[] { id1_, id2_ };
			cost = cost_;
		}

		@Override
		public int compareTo(Edge o) {
			return Integer.compare(cost, o.cost);
		}
	}

	int NIL = Integer.MAX_VALUE;

	void run() {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		DJSet ds = new DJSet(n);
		int[][][] lis = new int[2][n][];
		for (int i = 0; i < n; ++i) {
			int x = sc.nextInt();
			int y = sc.nextInt();
			lis[0][i] = new int[] { x, i };
			lis[1][i] = new int[] { y, i };
		}
		int[][] ref = new int[2][n];
		Arrays.sort(lis[0], new Comparator<int[]>() {
			@Override
			public int compare(int[] o1, int[] o2) {
				return Integer.compare(o1[0], o2[0]);
			}
		});
		Arrays.sort(lis[1], new Comparator<int[]>() {
			@Override
			public int compare(int[] o1, int[] o2) {
				return Integer.compare(o1[0], o2[0]);
			}
		});
		for (int t = 0; t < 2; ++t) {
			for (int i = 0; i < n; ++i) {
				ref[t][lis[t][i][1]] = i;
			}
		}
		PriorityQueue<Edge> pq = new PriorityQueue<>();
		for (int t = 0; t < 2; ++t) {
			for (int i = 0; i + 1 < n; ++i) {
				pq.add(new Edge(lis[t][i][1], lis[t][i + 1][1], lis[t][i + 1][0] - lis[t][i][0]));
			}
		}

		long ans = 0;
		while (!pq.isEmpty()) {
			Edge e = pq.poll();
			if (ds.equiv(e.id[0], e.id[1])) {
				continue;
			}
			ans += e.cost;
			ds.setUnion(e.id[0], e.id[1]);
		}
		System.out.println(ans);
	}

	class List {
		int n;
		int[] arr;
		int[] ne;
		int[] pre;

		public List(int n_) {
			n = n_;
			arr = new int[n];
			ne = new int[n];
			pre = new int[n];
			Arrays.fill(ne, NIL);
			Arrays.fill(pre, NIL);
			for (int i = 0; i < n; ++i) {
				arr[i] = i;
			}
			for (int i = 0; i < n; ++i) {
				if (i - 1 >= 0) {
					pre[i] = i - 1;
				}
				if (i + 1 < n) {
					ne[i] = i + 1;
				}
			}
		}

		boolean del(int idx) {
			if (!exist(idx)) {
				return false;
			}
			arr[idx] = NIL;
			if (pre[idx] != NIL && exist(pre[idx])) {
				ne[pre[idx]] = ne[idx];
			}
			if (ne[idx] != NIL && exist(ne[idx])) {
				pre[ne[idx]] = pre[idx];
			}
			pre[idx] = NIL;
			ne[idx] = NIL;
			return true;
		}

		boolean exist(int idx) {
			return arr[idx] == NIL;
		}
	}

	class DJSet {
		int n;
		int[] upper;

		public DJSet(int n_) {
			n = n_;
			upper = new int[n];
			Arrays.fill(upper, -1);
		}

		boolean equiv(int x, int y) {
			return root(x) == root(y);
		}

		int root(int x) {
			return upper[x] < 0 ? x : (upper[x] = root(upper[x]));
		}

		void setUnion(int x, int y) {
			x = root(x);
			y = root(y);
			if (x != y) {
				if (upper[x] < upper[y]) {
					int tmp = x;
					x = y;
					y = tmp;
				}
				upper[y] += upper[x];
				upper[x] = y;
			}
		}
	}

	void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}
}

Measured memory_bytes: 99452
#include <iostream>
#include <vector>
#include <string>
#include <bitset>
#include <cmath>
#include <iomanip>
#include <stack>
#include <set>
#include <queue>
#include <algorithm>
#include <deque>
using namespace std;

#define INF 1e18
#define int long long
#define MAX 1000000010

signed main() {
    int n, m; cin >> n >> m;
    vector<int> a(n), b(m), c(m);
    for(int i = 0; i < n; i++) {
        cin >> a[i];
    }
    for(int i = 0; i < m; i++) {
        cin >> b[i] >> c[i];
    }

    priority_queue<pair<int, int>> q;
    for(int i = 0; i < n; i++) {
        q.push(make_pair(a[i], 1));
    }
    for(int i = 0; i < m; i++) {
        q.push(make_pair(c[i], b[i]));
    }

    int ans = 0;
    for(int i = 0; i < n; i++) {
        auto p = q.top();
        q.pop();
        ans += p.first;
        if(p.second > 1) {
            p.second--;
            q.push(p);
        }
    }

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


Measured memory_bytes: 8176
//#include<bits/stdc++.h>
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <cstring>
#include <algorithm>
using namespace std;
/*#define fast ios_base::sync_with_stdio(0); cin.tie(0)*/
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
const double pi = acos(-1);
typedef long long ll;
int main()
{
	//fast;
	
	ll a,b,c,x;
	cin>>a>>b>>c;
	cout<<(a-b)%c<<endl;
}

Measured memory_bytes: 3616
#define _USE_MATH_DEFINES
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <clocale>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i, s, n) for(int i = (s), i##_len=(n); i < i##_len; ++i)
#define FORS(i, s, n) for(int i = (s), i##_len=(n); i <= i##_len; ++i)
#define VFOR(i, s, n) for(int i = (s); i < (n); ++i)
#define VFORS(i, s, n) for(int i = (s); i <= (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) FORS(i, 0, n)
#define VREP(i, n) VFOR(i, 0, n)
#define VREPS(i, n) VFORS(i, 0, n)
#define RFOR(i, s, n) for(int i = (s), i##_len=(n); i >= i##_len; --i)
#define RFORS(i, s, n) for(int i = (s), i##_len=(n); i > i##_len; --i)
#define RREP(i, n) RFOR(i, n, 0)
#define RREPS(i, n) RFORS(i, n, 0)
#define ALL(v) (v).begin(), (v).end()
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v), greater<decltype(v[0])>())
#define SZ(x) ((int)(x).size())
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define MT make_tuple
#define BIT(n) (1LL<<(n))
#define UNIQUE(v) v.erase(unique(ALL(v)), v.end())

using ld = long double;
using ll = long long;
using ui = unsigned int;
using ull = unsigned long long;
using Pi_i = pair<int, int>;
using Pll_ll = pair<ll, ll>;
using VB = vector<bool>;
using VC = vector<char>;
using VD = vector<double>;
using VI = vector<int>;
using VLL = vector<ll>;
using VS = vector<string>;
using VSH = vector<short>;
using VULL = vector<ull>;

const int MOD = 1000000007;
const int INF = 1000000000;
const int NIL = -1;
const double EPS = 1E-10;

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


int main(){
    VI cnt(4, 0);
    REP(i, 3){
        int a, b; cin >> a >> b;
        --a; --b;
        ++cnt[a]; ++cnt[b];
    }
    REP(i, 4){
        if(cnt[i] == 3){
        cout << "NO" << endl;
        return 0;
        }
    }
    cout << "YES" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <cmath>
#include <iostream>
#include <numeric>
#include <queue>
#include <unordered_map>
#include <vector>

const int mod = 1e9 + 7;
const int kmax = 510000;

long long fact[kmax], fact_inv[kmax], inv[kmax];

int gcd(int a, int b)
{
    if (!b) {
        return a;
    }

    return gcd(b, a % b);
}

void init_comb()
{
    fact[0] = fact[1] = 1;
    fact_inv[0] = fact_inv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < kmax; i++) {
        fact[i] = fact[i - 1] * i % mod;
        inv[i] = mod - inv[mod % i] * (mod / i) % mod;
        fact_inv[i] = fact_inv[i - 1] * inv[i] % mod;
    }
}

long long comb(int n, int r)
{
    if (n < r) {
        return 0;
    }

    if (n < 0 || r < 0) {
        return 0;
    }

    return fact[n] * (fact_inv[r] * fact_inv[n - r] % mod) % mod;
}

template <typename T, T N>
class UnionFind {
    T parent_[N];
    T rank_[N];
    T size_[N];

public:
    UnionFind();
    T Root(T idx);
    bool IsSame(T x, T y);
    void Unite(T x, T y);
    T GetSize(T idx);
};

template <typename T, T N>
UnionFind<T, N>::UnionFind()
{
    for (T i = 0; i < N; i++) {
        parent_[i] = i;
        rank_[i] = 0;
        size_[i] = 1;
    }
}

template <typename T, T N>
T UnionFind<T, N>::Root(T idx)
{
    return parent_[idx] == idx ? idx : parent_[idx] = Root(parent_[idx]);
}

template <typename T, T N>
bool UnionFind<T, N>::IsSame(T x, T y)
{
    return Root(x) == Root(y);
}

template <typename T, T N>
void UnionFind<T, N>::Unite(T x, T y)
{
    x = Root(x);
    y = Root(y);
    if (x == y) {
        return;
    }

    if (rank_[x] < rank_[y]) {
        parent_[x] = y;
        size_[y] += size_[x];
    } else {
        parent_[y] = x;
        size_[x] += size_[y];
        if (rank_[x] == rank_[y]) {
            rank_[x]++;
        }
    }
}

template <typename T, T N>
T UnionFind<T, N>::GetSize(T idx)
{
    return size_[Root(idx)];
}

int main(void)
{
    long long a, b;
    std::cin >> a >> b;

    auto XorValue = [](long long x) -> long long {
        switch (x % 4) {
        case 0:
            return x;
        case 1:
            return 1;
        case 2:
            return x + 1;
        case 3:
            return 0;
        }
    };

    std::cout << (XorValue(std::max(a - 1, 0LL)) ^ XorValue(b)) << std::endl;
}


Measured memory_bytes: 256
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
int n,a,ans;
vector<int> v;
int main(void){
    cin>>n;
    v.push_back(-1);
    for(int i=0;i<n;i++){
        cin>>a;
        int itr=lower_bound(v.begin(),v.end(),a)-v.begin();
        ans=max(ans,itr);
        if(itr==v.size())v.push_back(a);
        else v[itr]=a;
    }
    cout<<ans<<endl;
}



Measured memory_bytes: 3416
#include <iostream>
#include <string>
#include <sstream>

using namespace std;

int main() {
  int n;
  string str;

  int sum = 0;
  int item_cnt = 0;
  int line_cnt = 0;

  while (getline(cin, str, ',')) {
    int a = atoi(str.c_str());
    getline(cin, str);
    int b = atoi(str.c_str());

    sum += a * b;
    item_cnt += b;
    ++line_cnt;
  }

  cout << int(sum) << endl;
  cout << int(double(item_cnt)/line_cnt+0.5) << endl;
}


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


#define ll          long long
#define uint        unsigned int 
#define ld          long double
#define SAM         ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define FOR(i,a,b)  for(ll i=a;i<b;++i)
#define RFOR(i,a,b) for(int i=a;i>b;--i)
#define mod         1000000007
#define mxn         200005
#define pb          push_back
#define pii         pair<int,int>
#define f           first
#define s           second
#define sz(x)       (int)x.size()
#define all(x)      x.begin(),x.end()

using namespace std;

/*mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int power(int a,int n)
{
    a %= mod;
    if(n == 1) return a;
    if(n == 0) return 1;
    if(n%2) return (a*(power((a*a)%mod,n/2)%mod))%mod;           //n is odd
    return power((a*a)%mod,n/2)%mod;                             //n is even
}

const int inf = (int) 1e18;

int inverse(int x)
{
    return power(x,mod-2)%mod;     //Fermat's little theorem
}*/

int main()
{
    SAM;
    string a;
    cin>>a;
    ll sum=0;
    ll temp=a.length();
    FOR(i,0,temp)
    {
        sum+=a[i]-'0';
    }
    
    if(sum%9==0)
        cout<<"Yes";
    else
        cout<<"No";
        
    
    return 0;
}




Measured memory_bytes: 3724
#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
using namespace std;

int main(){
    ll sx, sy, tx, ty;
    cin>>sx>>sy>>tx>>ty;

    for(ll i=0;i<ty-sy;++i){
        cout<<'U';
    }
    for(ll i=0;i<tx-sx;++i){
        cout<<'R';
    }
    for(ll i=0;i<ty-sy;++i){
        cout<<'D';
    }
    for(ll i=0;i<tx-sx;++i){
        cout<<'L';
    }

    cout<<'L';
    for(ll i=0;i<ty-sy+1;++i){
        cout<<'U';
    }
    for(ll i=0;i<tx-sx+1;++i){
        cout<<'R';
    }
    cout<<'D'<<'R';
    for(ll i=0;i<ty-sy+1;++i){
        cout<<'D';
    }
    for(ll i=0;i<tx-sx+1;++i){
        cout<<'L';
    }
    cout<<'U';
    cout<<endl;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		int n,m,l;
		Scanner scan = new Scanner(System.in);
		n=scan.nextInt();
		m=scan.nextInt();
		l=scan.nextInt();
		int[][] A = new int[n][m];
		int[][] B = new int[m][l];
		long[][] C = new long[n][l];
		
		for(int i=0;i<n;i++)
			for(int j=0;j<m;j++)
				A[i][j]=scan.nextInt();
		
		for(int i=0;i<m;i++)
			for(int j=0;j<l;j++)
				B[i][j]=scan.nextInt();
		
		for(int i=0;i<n;i++)
			for(int j=0;j<l;j++)
				C[i][j]=0;
		
		for(int i=0;i<n;i++){
			for(int j=0;j<l;j++){
				long temp = 0;
				for(int k=0;k<m;k++){
					temp += A[i][k] * B[k][j];
				}
				C[i][j]=temp;
			}
		}
		
		for(int i=0;i<n;i++){
			for(int j=0;j<l-1;j++){
				System.out.print(C[i][j] + " ");
			}
			System.out.println(C[i][l-1]);
		}
	}
}


Measured memory_bytes: 52876
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, n, s) for (int i = (s); i < (n); i++)
#define MOD 1000000007
typedef long long int ll;
using namespace std;
using Graph = vector<vector<int>>;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<int> A(N), B(N), C(N - 1);
    rep(i, N) cin >> A[i];
    rep(i, N) cin >> B[i];
    rep(i, N - 1) cin >> C[i];
    int before = -1;
    int ans = 0;
    for (auto a : A)
    {
        ans += B[a - 1];
        if (a - before == 1)
        {
            ans += C[before - 1];
        }
        before = a;
    }
    cout << ans << endl;
   // system("pause");
    return 0;
}

Measured memory_bytes: 256
n = int(input())
A = list(map(int, input().split()))

#import fractions
import math
from functools import reduce

def gcd(*numbers):
    #return reduce(fractions.gcd, numbers)
    return reduce(math.gcd, numbers)

def gcd_list(numbers):
    #return reduce(fractions.gcd, numbers)
    return reduce(math.gcd, numbers)

print(gcd_list(A))


Measured memory_bytes: 85184
#include<bits/stdc++.h>
using namespace std;
//define
#define int long long
#define rep(x,y) for(int i=x;i<y;i++)
#define REP(x,y) for(int j=x;j<y;j++)
#define Rep(x,y) for(int k=x;k<y;k++)
#define str string
#define vint vector<int>
#define vvint vector<vector<int>>
#define vc vector<char>
#define vvc vector<vector<char>>
#define vool vector<bool>
#define vtr vector<str>
#define vvtr vector<vector<str>>
#define pb() push_back()
#define elif else if
#define all(x) x.begin(),x.end()
//function
int shizuku(int,int);
//UnionFind
struct UnionFind{
  vint par;
  UnionFind(int N):par(N){
    rep(0,N)par[i]=i;
  }
  int root(int x){
    if(par[x]==x)return x;
    return par[x]=root(par[x]);
  }
  void unite(int x,int y){
    int rx=root(x);
    int ry=root(y);
    if(rx==ry)return;
    par[rx]=ry;
  }
  bool same(int x,int y){
    return root(x)==root(y);
  }
};

signed main(){
    int D,G,N,M,X,count=0,count2=0;
    double d;
    int C='A'-'a';
    char op;
    str S,T;
    cin>>N>>X;
  	if(N==0&&X==100)cout<<101<<endl;
    elif(N==0)cout<<X<<endl;
    elif(N==1&&X==100)cout<<X*100+100<<endl;
    elif(N==2&&X==100)cout<<X*10000+10000<<endl;
  	elif(N==1)cout<<X*100<<endl;
  	elif(N==2)cout<<X*10000<<endl;
}


Measured memory_bytes: 256
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a


def lcm(a, b):
    return a * b // gcd(a, b)


def power(n,p):
    cnt = 0
    while n%p == 0:
        cnt += 1
        n //= p
    return cnt


N, M = map(int, input().split())
A = [int(x)//2 for x in input().split()]

for i in range(1,N):
    if power(A[i],2) != power(A[i-1], 2):
        print(0)
        exit()

g = A[0]
for i in range(1, N):
    g = lcm(g, A[i])

print((M + g)//(2*g))

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

int main() {

    int N;
    cin >> N;
 
    int hen[3];
    while (N --> 0) {
        cin >> hen[0] >> hen[1] >> hen[2];
        sort(hen, hen + 3);
        
        if (hen[2] * hen[2] == hen[0] * hen[0] + hen[1] * hen[1]) {
            cout << "YES" << endl;
        } else {
            cout << "NO" << endl;
        }
    }
    

    return 0;
}

Measured memory_bytes: 0
import itertools
import math
import sys
import heapq
from collections import Counter
from collections import deque
from fractions import gcd
from functools import reduce

sys.setrecursionlimit(4100000)
INF = 1 << 60
MOD = 10 ** 9 + 7

# ここから書き始める
# x = int(input())
# ans = (x // 500) * 1000
# x %= 500
# ans += (x // 5) * 5
# print(ans)


k, n = map(int, input().split())
a = list(map(int, input().split()))
max_gap = 0
start = 0
for i in range(n):
    if i == 0:
        if k - a[-1] + a[0] > max_gap:
            start = i
            max_gap = k - a[-1] + a[0]
    elif a[i] - a[i - 1] > max_gap:
        start = i
        max_gap = a[i] - a[i - 1]
# print("max_gap =", max_gap)
# print("start =", start)
ans = k - max_gap
print(ans)


Measured memory_bytes: 27724
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define invrepr(i,a,b) for(int i=b-1;i>=a;i--)
#define invrep(i,n) invrepr(i,0,n)
#define repitr(itr,a) for(auto itr=a.begin();itr!=a.end();++itr)
#define P pair<int,ll>
const ll MOD=998244353;
const int INF=1e9;
const double PI=acos(-1);


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

    int a,b,c;
    cin >> a >> b >> c;
    swap(a,b);
    swap(a,c);
    cout << a << ' ' << b << ' ' << c << endl; 

    return 0; 
}


Measured memory_bytes: 3592
import Control.Applicative ((<$>), (<*>), (<*), (*>), (<$))
import Control.Monad
import Data.List

main :: IO ()
main = do
  n <- getl toInt
  solve <$> replicateM n (getl $ toTpl . wrds toInt) >>= print

toTpl :: [Int] -> (Int,Int)
toTpl [x,y] = (x,y)

solve :: [(Int,Int)] -> Int
solve xs = g $ foldl f (head xs) (tail xs)
  where
    f :: (Int,Int) -> (Int, Int) -> (Int,Int)
    f (x,y) (t,a)
      | x <= t && y <= a = (t,a)
      | otherwise = (b * t, b * a)
      where
        b = max (if x `mod` t == 0 then x `div` t else x `div` t + 1) (if y `mod` a == 0 then y `div` a else y `div` a + 1)
    g (x,y) = x + y

toInt :: String -> Int
toInt = read

wrds :: (String -> a) -> String -> [a]
wrds f = map f . words

getl :: (String -> a) -> IO a
getl f = f <$> getLine


Measured memory_bytes: 1532
#include <bits/stdc++.h>
#define SIZE 5005
using namespace std;
typedef long long int ll;

int main(){
    ios::sync_with_stdio(false);
    priority_queue<int,vector<int>, greater<> > q;
    priority_queue<int,vector<int>, less<> > p;
    int n;
    cin>>n;
    char s[200005];
    cin>>s;
    for(int i=0;i<n;i++){
        if(s[i]=='W'){
            q.push(i+1);
        }else{
            p.push(i+1);
        }
    }
    int ans=0;
    if(q.empty()||p.empty()){
        printf("0\n");
        return 0;
    }
    while(q.top()<p.top()){
        int tmp1=q.top();
        q.pop();
        int tmp2=p.top();
        p.pop();
        q.push(tmp2);
        p.push(tmp1);
        ans++;
    }
    printf("%d\n",ans);
}

Measured memory_bytes: 4732
/*.....Bismillahir Rahmanir Rahim.....*/
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <unordered_map>
#include <queue>
#define   mod  998244353
#define   int  long long 
#define   ld long double
#define   pb push_back
#define   sz(x)  (int)x.size()
#define   ff first
#define   ss second
#define   pii  pair<int,int> 
#define   pb  push_back
#define   eb  emplace_back
#define   lcm(a,b)  (a*b)/gcd(a,b)
using namespace std;

const int inf=10000000;
signed main(){
	int n,m;
	cin>>n>>m;
	int a[1000],b[1000],c[1000],dist[1000][1000];	
	for(int i=0;i<m;++i){
		cin>>a[i]>>b[i]>>c[i];
		a[i]--,b[i]--;
	}
	for(int i=0;i<n;++i){
		for(int j=0;j<n;++j){
			if(i==j) dist[i][j]=0;
			else dist[i][j]=inf;
		}
	}
	for(int i=0;i<m;++i){
		dist[a[i]][b[i]]=min(dist[a[i]][b[i]],c[i]);			dist[b[i]][a[i]]=min(dist[b[i]][a[i]],c[i]);
	}
	for(int k=0;k<n;++k){
		for(int i=0;i<n;++i){
			for(int j=0;j<n;++j){
				dist[i][j]=min(dist[i][j],dist[i][k]+dist[k][j]);
			}
		}
	}
	int ans=m;
	for(int i=0;i<m;++i){
		bool shortest=false;
		for(int j=0;j<n;++j)
			if(dist[j][a[i]]+c[i]==dist[j][b[i]])
				shortest=true;										if(shortest==true){
				ans--;
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 2816
N = int(input())
items = []

for i in range(N):
    item = input()
    items.append(item)    
items.sort()
cnt = 0
before = ""
for index,item in enumerate(items):
    if index == 0:
        cnt += 1    
    elif before != item:
        cnt += 1
    before = item
print(cnt)

Measured memory_bytes: 23816
#include <bits/stdc++.h>
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define ff first
#define ss second
#define sf scanf
#define pf printf
#define MAX 200002
#define INF 100000000000000
#define EXP 1e-6
#define endl '\n'
#define all(v) v.begin(), v.end()
#define FOR(i, a, b, c) for( int i = a; i < b; i+=c )
#define rep(i, a) for( int i = 0; i < a; i++ )
#define fastio ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);

typedef long long ll;
const int maxn = 2e5 + 10;
const ll MOD = 1e9 + 7;

using namespace std;

typedef pair <int, int> ii;
typedef pair <int, ii> trie;
typedef vector <int> vi;
typedef vector <ii> vii;
typedef vector <vii> vvii;
typedef vector <vi> vvi;
typedef vector <bool> vb;
typedef vector <trie> vtrie;
typedef bitset <maxn> bs;

int main()
{
	fastio

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

    int dp[s.length() + 2][t.length() + 2];
    memset( dp, 0, sizeof(dp) );

    s = '#' + s;
    t = '#' + t;

    for( int i = 1; i <= s.length()-1; i++ ){
    	for( int j = 1; j <= t.length()-1; j++ ){
    		if( s[i] == t[j] )
    			dp[i][j] = 1 + dp[i-1][j-1];
    		else dp[i][j] = max( dp[i][j-1], dp[i-1][j] );
    	}
    }

    int i = s.length()-1, j = t.length()-1;
    string ans = "";
    while( i != 0 && j != 0 ) {
    	if( max(dp[i][j-1], dp[i-1][j]) < dp[i][j] ) ans += t[j], i--, j--;
    	else{
    		if( dp[i][j-1] > dp[i-1][j] ) j--;
    		else i--;
    	}
    }
    reverse(all(ans));
    cout << ans << endl;
   // cout << dp[s.length()-1][t.length()-1] << endl;
    
	return 0;

}

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

int main(){
  int N;
  cin >> N;
  vector<double>x(N);
  vector<double>y(N);
  vector<vector<double>>z(N,vector<double>(N,0));
  for(int i=0;i<N;i++){
    cin >> x[i] >> y[i];
  }
  int count=1;
  double ans=0;
  for(int i=1;i<N;i++){
    count*=i;
  }
  for(int i=0;i<N;i++){
    for(int j=0;j<N;j++){
      if(i==j){
        continue;
      }
      z[i][j]=sqrt((x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]));
      ans+=z[i][j]*count;
    }
  }
  cout << std::fixed << std::setprecision(15) << ans/count/N << endl;
}

Measured memory_bytes: 3784