akhauriyash/Code-Regression huggingface dataset:
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {

    private static Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {

        int n = sc.nextInt();

        int[] v = new int[n];
        int[] c = new int[n];

        for (int i=0; i < n; i++)
            v[i] = sc.nextInt();
        for (int i=0; i < n; i++)
            c[i] = sc.nextInt();

        List<Integer> d = new ArrayList<>();

        for (int i=0; i < n; i++)
            d.add(v[i] - c[i]);

        Collections.sort(d, (o1, o2) -> o2 - o1);

        int max = 0;

        for (int i=0; i < d.size(); i++) {
            if (d.get(i) > 0)
                max += d.get(i);
            else
                break;
        }

        System.out.println(max);

    }

}


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

int main() {
  string S;
  cin>>S;
  for(int i=0;i<8;i++){
    string ans;
    ans+=S.at(0);
    int sum=S.at(0)-'0';
    for(int j=0;j<3;j++){
      if(i>>j&1){
        sum+=S.at(j+1)-'0';
        ans+="+";
        ans+=S.at(j+1);
      }
      else{
        sum-=S.at(j+1)-'0';
        ans+="-";
        ans+=S.at(j+1);
      }
    }
    if(sum==7){
        cout<<ans<<"=7"<< endl;
        return 0;
      
    }
  }
} 

Measured memory_bytes: 3588
from collections import defaultdict
from heapq import heappush, heappop, heapify
from sys import stdin
def sp(G,R,V):
    d = {}
    q = [(0, R)]
    heapify(q)
    seen = set()
    while q:
        (cost, v) = heappop(q)
        if v not in seen:
            seen.add(v)
            d[v] = cost
            for (next, c) in G[v].items():
                heappush(q, (cost + c, next))
    return d

V, E, R = [int(x) for x in stdin.readline().split()]
G = defaultdict(dict)
for case in range(E):
    s, t, w = [int(x) for x in stdin.readline().split()]
    G[s][t] = w
d = sp(G, R, V)
for k in range(V):
    if k not in d:
        print("INF")
    else:
        print(d[k])

Measured memory_bytes: 129156
#include<stdio.h>
#include<stdlib.h>

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

Node treeMinimum(Node x){
  while(x->left!=NIL) x=x->left;
  return x;

}

//Node treeMaximum(Node x){


//}

Node treeSearch(Node u, int k){
  Node a;
  if(u->key==k) a=u;
  else if(u->key > k){
    if(u->left!=NIL) a=treeSearch(u->left,k);
    else a=NIL;
  }else if(u->key < k){
    if(u->right!=NIL) a=treeSearch(u->right,k);
    else a=NIL;
  }
  return a;
}

Node treeSuccessor(Node x){
  Node y,z;
  if(x->right!=NIL){
    z=treeMinimum(x->right);
    return z;
  }
  y=x->parent;
  while(y!=NIL && y->right==x){
    x=y;
    y=y->parent;
  }
  return y;
}

void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y
  if(z->left==NIL ||z->right==NIL) y=z;
  else y=treeSuccessor(z);
  
  if(y->left!=NIL) x=y->left;
  else x=y->right;
  
  if(x!=NIL)  x->parent=y->parent;

  if(y->parent==NIL)  root=x;
  else if(y==y->parent->left)  y->parent->left=x;
  else  y->parent->right=x;

  if(y!=z)  z->key=y->key;
}

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;
  
  while(x!=NIL){
    y=x;
    if(z->key < x->key) x=x->left;
    else x=x->right;
  }
  z->parent=y;

  if(y==NIL) root=z;
  else if(z->key < y->key) y->left=z;
  else y->right=z;
}

void inorder(Node u){
  if(u->left!=NIL) inorder(u->left);
  printf(" %d",u->key);
  if(u->right!=NIL) inorder(u->right);
}
void preorder(Node u){
  printf(" %d",u->key);
  if(u->left!=NIL) preorder(u->left);
  if(u->right!=NIL) preorder(u->right);
}


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
      } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
  }

  return 0;
}



Measured memory_bytes: 20476
use std::io::prelude::*;
use std::io::stdin;
use std::str::FromStr;

fn main() {
    let n: usize = read();
    let mut v = vec![];

    for _ in 0..n {
        let a: usize = read();
        let xy: Vec<(usize, usize)> = (0..a).map(|_| (read(), read())).collect();
        v.push(xy);
    }

    let mut max_i = 0;
    'outer: for bit in (0..1 << n).rev() {
        let mut tmp = vec![];
        let mut v1 = vec![0; n];
        for i in 0..n {
            if bit & (1 << i) > 0 {
                tmp.push(&v[i]);
                v1[i] = 1;
            }
        }

        let len = tmp.len();
        for xy in tmp {
            for &(x, y) in xy {
                if v1[x - 1] != y {
                    continue 'outer;
                }
            }
        }
        max_i = std::cmp::max(max_i, len);
    }
    println!("{}", max_i);
}

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|b| b.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(k,i,n) for(ll i=k;i<n;++i)
const ll M = 1e9+7;

vector<ll> fac(3001); //n!(mod M)
vector<ll> ifac(3001); //k!^{M-2} (mod M)
//a,bの範囲的にこれだけ配列を用意していけば十分

ll mpow(ll x, ll n){ //x^n(mod M) ←普通にpow(x,n)では溢れてしまうため，随時mod計算
    ll ans = 1;
    while(n != 0){
        if(n&1) ans = ans*x % M;
        x = x*x % M;
        n = n >> 1;
    }
    return ans;
}

ll comb(ll a, ll b){ //aCbをmod計算
    if(a == 0 && b == 0)return 1;
    if(a < b || a < 0)return 0;
    ll tmp = ifac[a-b]* ifac[b] % M;
    return tmp * fac[a] % M;
}

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

    fac[0] = 1;
    ifac[0] = 1;
    for(ll i = 0; i<3000; i++){
        fac[i+1] = fac[i]*(i+1) % M; // n!(mod M)
        ifac[i+1] = ifac[i]*mpow(i+1, M-2) % M; // k!^{M-2} (mod M) ←累乗にmpowを採用
    }
    rep(0,i,k){
        cout<<comb(n-k+1,i+1)*comb(k-1,i)%M<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.lang.*;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String x = sc.next();
        String y = sc.next();
        if (x.compareTo(y) > 0){
            System.out.println(">");
        }else if(x.compareTo(y) == 0){
            System.out.println("=");
        }else{
            System.out.println("<");
        }
        System.out.println();
        sc.close();
    }
}

Measured memory_bytes: 22612
#include <bits/stdc++.h>
#define ll long long

using namespace std;

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int bingo[3][3], n;
    bool called[3][3] = { {0, 0, 0}, {0, 0, 0}, {0, 0, 0} };
    cin >> bingo[0][0] >> bingo[0][1] >> bingo[0][2] >> bingo[1][0] >> bingo[1][1] >> bingo[1][2] >> bingo[2][0] >> bingo[2][1] >> bingo[2][2] >> n;
    for (int i = 0; i < n; i++) {
        int no;
        cin >> no;
        for (int j = 0; j < 3; j++) {
            for (int k = 0; k < 3; k++) {
                if (bingo[j][k] == no) {
                    called[j][k] = true;
                }
            }
        }
    }
    if (called[0][0] + called[0][1] + called[0][2] == 3 || called[1][0] + called[1][1] + called[1][2] == 3 || called[2][0] + called[2][1] + called[2][2] == 3 ||
        called[0][0] + called[1][0] + called[2][0] == 3 || called[0][1] + called[1][1] + called[2][1] == 3 || called[0][2] + called[1][2] + called[2][2] == 3 ||
        called[0][0] + called[1][1] + called[2][2] == 3 || called[0][2] + called[1][1] + called[2][0] == 3) {
            cout << "Yes";
        } else {
            cout << "No";
        }
}


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

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REPl(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define REPRl(i, n) for(ll i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < (int)n; i++)
#define FORl(i, m, n) for(ll i = m; i < (ll)n; i++)
#define ALL(v) v.begin(), v.end()
ll gcd(ll a,ll b) {
  return b? gcd(b,a%b): a;  
}
ll lcm(ll a,ll b) {
  return a*b/gcd(a,b);
}
bool isLowerCase(char c){
  return (c>='a'&&c<='z');
}
int main() {
  int a,b;cin>>a>>b;
  int d=b-a;
  int h=d*(d+1)/2;
  int ans=h-b;
  cout<<ans<<endl;
}


Measured memory_bytes: 256
using System;
class Program
{
    static void Main()
    {
        int[] input = new int[10];
        for (int i = 0; i < input.Length; i++)
        {
            input[i] = int.Parse(Console.ReadLine());
        }
        Array.Sort(input);
        Array.Reverse(input);
        for (int i = 0; i < 3; i++)
        {
            Console.WriteLine(input[i]);
        }
        Console.ReadLine();
    }
}

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

const int N = 1e5 + 5;

int n;
int a[N];

int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", a + i);
  }
  sort(a + 1, a + n + 1, greater<int>());
  int j = n;
  for (int i = 1; i <= n; i++) {
    if (a[i] < i) {
      j = i - 1;
      break;
    }
  }
  int gou = a[j] - j, gor = 0, h = j;
  while (j < n && a[j + 1] == h)
    j++, gor++;
  puts(((gor & 1) || (gou & 1)) ? ("First") : ("Second"));
  return 0;
}


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

#define ll long long
#define pb push_back
#define mp make_pair
int main() 
{
	 ios_base::sync_with_stdio(false);
     cin.tie(NULL);
     ll int n,k;
      cin>>n>>k;
     ll ans=min(n%k,abs(n%k-k));
     cout<<ans<<"\n";
      
}

Measured memory_bytes: 3660
#include<iostream>
#include <bits/stdc++.h>
#include<stdio.h>
#include <stdlib.h>
#include<string>
#include<queue>
#include<algorithm>
#include<math.h>
#include<map>
using namespace std;


int main(){
	int N,ans=0;
	int A[100001]={};
	cin>>N;
	for(int i=0;i<N;i++){
		int a;
		cin>>a;
		A[a]++;
	}
	for(int i=1;i<=99999;i++){
		if(ans<A[i-1]+A[i]+A[i+1]){
			ans=A[i-1]+A[i]+A[i+1];
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 640
from functools import reduce
from fractions import gcd
import math
import bisect
import itertools
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
INF = float("inf")


def main():
    K = int(input())
    A, B = map(int, input().split())
    for i in range(A, B+1):
        if i % K == 0:
            print("OK")
            return
    print("NG")
        


if __name__ == '__main__':
    main()

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

int main(){
    ll a, b, m; cin >> a >> b >> m;
    vector<ll> alis(a+1, 0), blis(b+1, 0);
    ll amin = 1e8, bmin = 1e8;
    for(int i = 0; i < a; i++){
        cin >> alis[i+1];
        amin = min(amin, alis[i+1]);
    }
    for(int i = 0; i < b; i++){
        cin >> blis[i+1];
        bmin  = min(bmin, blis[i+1]);
    }
    vector<vector<ll> > lis(m, vector<ll>(3, 0));
    ll sum = amin + bmin;
    for(int i = 0; i < m; i++){
        ll x, y, z; cin >> x >> y >> z;
        sum = min(sum, alis[x] + blis[y] - z);
    }
    cout << sum << endl;
}

Measured memory_bytes: 7296
#include <iostream>
using namespace std;
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n,x;
    while (cin>>n>>x, n||x) {
        int c = 0;
        for (int i=1; i<=n; ++i) {
            for (int j=i+1; j<=n; ++j) {
                for (int k=j+1; k<=n; ++k) {
                    if (i+j+k == x) {
                        c ++;
                    }
                }
            }
        }
        cout << c << "\n";
    }

    return 0;
}

Measured memory_bytes: 1196
import java.io.*;
import java.util.NoSuchElementException;

public class Main {

    public static void main(String[] args) {
        FastScanner fs = new FastScanner();
        int a1 = fs.nextInt();
        int a2 = fs.nextInt();
        int a3 = fs.nextInt();
        System.out.println( ( a1 + a2 + a3 >= 22 ) ? "bust" : "win");
    }

    static 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: 22868
#include <iostream>
#include <stdio.h>
using namespace std;
int n,k;
double ans=0.0;
int main(){
    cin>>n>>k;
    for(int d=1;d<=n;d++){
        int x=1;
        while(d*x<k)x*=2;
        ans+=(1.0/(n*x));
    }
    printf("%.10f\n",ans);
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include<string>
#include<cstring>
#include <cstdio>
#include<utility>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<bitset>
#include<queue>
#include<stack>
#include<set>
#include <limits>
#include <climits>
#include <numeric>
#include<cassert>
#include<cctype>
#include<iterator>
using namespace std;
typedef long long ll;
typedef vector<ll>VI;
typedef vector<bool>VB;
typedef pair<ll,ll>P;
typedef pair<double,double>P_D;
#define VV(T) vector<vector<T>>
#define PI 3.1415926535897932384626433832795
#define rep(i, n) for (ll i = 0; i < (ll)n; i++)
#define reprev(i, n) for (ll i = (ll)n - 1; i >= 0; i--)
#define bitrep(bit,A) for(int bit=A; ;bit=(bit-1)&A)
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) (ll)((a).size())
#define c_max(a, b) (((ll)a)>((ll)b)?(a):(b))
#define c_min(a,b) (((ll)a)<((ll)b)?(a):(b))
#define chmax(x,a) x=c_max(x,a)
#define chmin(x,a) x=c_min(x,a)
#define vmax(v) *max_element(ALL(v))
#define vmin(v) *min_element(ALL(v))
#define SORT(c) stable_sort(ALL(c))
#define $(x) {cout<<#x<<" = " <<(x)<<endl;}
#define fi first
#define se second
#define MAX 100100//5
#define MAX2 200100
#define MAX_6 1001001//6
#define MAX_7 10010010//7
#define SENTINEL 2000000000//9
#define NIL -1
#define MOD 1000000007
#define INF 1<<30
#define INFTY 1000000000000000001LL
#define MAX_INT INT_MAX
#define Endl '\n'
#define greater greater<int>()

int main(){
    ll n,k;cin>>n>>k;
    ll score[3];rep(i,3)cin>>score[i];
    string T;cin>>T;
    vector<vector<int>> table(k);
    ll ans=0;
    for(int i=0;i<n;i++){
        if(T[i]=='r')table[i%k].push_back(2);
        if(T[i]=='s')table[i%k].push_back(0);
        if(T[i]=='p')table[i%k].push_back(1);
    }
    for(int i=0;i<k;i++)table[i].push_back(-1);
    for(int i=0;i<k;i++){
        int row=0;
        for(int j=0;j<(int)table[i].size()-1;j++){
            if(table[i][j]==table[i][j+1]){
                if(row%2==0){
                    ans+=score[table[i][j]];
                    row+=1;
                }
                else row+=1;
            }
            else if(row%2==0){
                ans+=score[table[i][j]];
                row=0;
            }
            else row+=1;
        }
    }
    cout<<ans<<endl;
    
}


Measured memory_bytes: 5120
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define N 100000
typedef long long ll;
#define all(v) (v).begin(),(v).end()
int main(){
	int n;
	cin>>n;
	vector<double> vn(n);
	rep(i,n){
		cin>>vn.at(i);
	}
	sort(all(vn));
	int z=0;
	while(z<n-1){
		vn.at(z+1)=(double)(vn.at(z)+vn.at(z+1))/2;
		vn.at(z)=0;
		sort(all(vn));
		z++;
	}
	printf("%.8lf\n",vn.at(n-1));
	return 0;
}

Measured memory_bytes: 256
#include "iostream"
#include <algorithm>
#include <stdlib.h>
#include <string>
#include <cctype>
#include <stack>
#include <vector>
#include <list>
#include <queue>
using namespace std;
using ll=long long;
#define mod  1000000007

int main(int argc, char const *argv[]) {
  int x,y;
  std::cin >> x >> y;
  bool ans=false;
  if(x==y) ans=true;
  else if((x==4 || x==6 || x==9 || x==11) && (y==4 || y==6 || y==9 || y==11)) ans=true;
  else if((x==1 || x==3 || x==5 || x==7 || x==8 || x==10 || x==12) && (y==1 || y==3 || y==5 || y==7 || y==8 || y==10 || y==12)) ans=true;

  if(ans) printf("Yes");
  else printf("No");
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
 
public class Main {
    public static void main(String[] args) {
        try(Scanner sc = new Scanner(System.in)){
            while(sc.hasNext()) {
                int n = sc.nextInt();
                int q = sc.nextInt();
                if(n+q == 0)break;
                
                int[][] date = new int[n+1][101];
                int[] quo = new int[101];
                for(int i=0;i<=100;i++) {
                	quo[i] = 0;
                }
                
                int limit = 0;
                for(int i=1;i<=n;i++) {
                	 int m = sc.nextInt();
                	 if(m==0)continue;
                	 for(int j=1;j<=m;j++) {
                		 int in = sc.nextInt();
                		 if(limit<in)
                			 limit = in;
                		 date[i][j] = in;
                		 quo[in]++;
                	 }
                }
                
                int max = 0;
                int near = 0;
                for(int i=1;i<=limit;i++) {
                	if(quo[i]==n) {
                		near = i;
                		break;
                	}
                	if(quo[i]>max) {
                			 max = quo[i];
                			 near = i;
                	}
                }
                if(quo[near] < q)
                	System.out.println(0);
                else
                	System.out.println(near);
            }
        }
    }
}


Measured memory_bytes: 68820
import itertools

n, m, x = map(int, input().split())
data = []
for _ in range(n):
  data.append( list(map(int, input().split())) )

ans_list_ = []

origin_list = data
for i, _ in enumerate(origin_list, 1):     
  for j in itertools.combinations(origin_list, r=i):  # rには1、2、3と渡される
    # print(list(j))

    # 合計値リスト
    each_point_list_ = [0] * m
    for j_ in j:
      for m_ in range(m):
        each_point_list_[m_] += j_[m_+1]

    # X判定
    flag_ = True
    for epl in each_point_list_:
      if epl < x:
        flag_ = False
    
    if flag_:
      # 金額の計算
      price_ = 0
      for j_ in j:
        price_ += j_[0]
      
      ans_list_.append( price_ )

    # print(*each_point_list_)

if len(ans_list_) == 0:
  print(-1)
else:
  print(min(ans_list_))



Measured memory_bytes: 9272
N,M = (int(x) for x in input().split())

c_arr = [[0]*N for _ in range(8)]

for i in range(N):
    x,y,z = (int(x) for x in input().split())
    c_arr[0][i] = x+y+z
    c_arr[1][i] = x+y-z
    c_arr[2][i] = x-y+z
    c_arr[3][i] = x-y-z
    c_arr[4][i] =-x+y+z
    c_arr[5][i] =-x+y-z
    c_arr[6][i] =-x-y+z
    c_arr[7][i] =-x-y-z

ans = 0
for i in range(8):
    ans = max(ans, sum(sorted(c_arr[i], reverse=True)[:M]))

print(ans)



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

vector<int> e[100];
int n,m;

int main() {

    cin >> n >> m;

    for(int i=0; i<m; i++){
        int a,b;
        cin >> a >> b;
        e[a].push_back(b);
        e[b].push_back(a);
    }

    vector<int> start;
    start.push_back(1);

    pair<vector<int>,int> now = make_pair(start,1);

    queue<pair<vector<int>,int>> q;

    q.push(now);

    int ans = 0;

    while(!q.empty()){

        now = q.front();
        q.pop();

        if(now.first.size() == n){
            ans++;
            continue;
        }

        for(int i=0; i<e[now.second].size(); i++){
            pair<vector<int>,int> tmp = now;
            bool flag = true;
            for(int j=0; j<tmp.first.size(); j++){
                if(e[now.second][i] == tmp.first[j]){
                    flag = false;
                    break;
                }
            }

            if(flag){
                tmp.first.push_back(e[now.second][i]);
                tmp.second = e[now.second][i];
                q.push(tmp);
            }

        }

    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,a,b) for(int i=(a),_end_=(b);i<=_end_;i++)
#define DREP(i,a,b) for(int i=(a),_end_=(b);i>=_end_;i--)
#define EREP(i,u) for(int i=start[u];i;i=e[i].next)
#define fi first
#define se second
#define mkr(a,b) make_pair(a,b)
#define SZ(A) ((int)A.size())
template<class T>inline void chkmin(T &a,T b){ if(a>b)a=b;}
template<class T>inline void chkmax(T &a,T b){ if(a<b)a=b;}
inline int read()
{
	int s=0,f=1;char ch=getchar();
	while(!isdigit(ch) && ch!='-')ch=getchar();
	if(ch=='-')ch=getchar(),f=-1;
	while(isdigit(ch))s=s*10+ch-'0',ch=getchar();
	return ~f?s:-s;
}

const int maxn=3e3+20;

char str[maxn<<1];
int s[maxn<<1];
int a[maxn],b[maxn];
int n;

bitset<3020>f[maxn];

inline void init()
{
	n=read();
	int an=0,bn=0;
	scanf("%s",str+1);
	REP(i,1,2*n)
	{
		if(str[i]=='a')a[++an]=i,s[i]=an;
		else b[++bn]=i,s[i]=bn+n;
	}
}

inline string GetString(bitset<3020>f)
{
	static int vis[6020];
	memset(vis,0,sizeof(int)*(2*n+1));
	REP(i,1,n)if(f[i])vis[a[i]]=1,vis[b[i]]=1;
	string S;
	REP(i,1,2*n)if(vis[i])S+=str[i];
	return S;
}

inline int ID(int x){ return s[x]>n?s[x]-n:s[x];}

inline void doing()
{
	DREP(i,n,1)
	{
		f[i]=f[i+1];
		bitset<3020>tmp;
		tmp.set(i);
		if(a[i]<b[i])
		{
			//tmp|=f[i+b[i]-a[i]];
			int far=i;
			REP(j,a[i]+1,b[i]-1)chkmax(far,ID(j));
			tmp|=f[far+1];
		}else {
			int far=a[i];
			//REP(j,b[i]+1,far)
			for(int j=b[i]+1;j<=far;j++)
				if(ID(j)>i && s[j]>n)tmp.set(s[j]-n),chkmax(far,a[s[j]-n]);
			int to=far+1;
			if(to<=2*n)
			{
				to=s[to]>n?s[to]-n:s[to];
				tmp|=f[to];
			}
		}
		string A=GetString(f[i]),B=GetString(tmp);
		f[i]=A>B?f[i]:tmp;
	}
	string s=GetString(f[1]);
	cout<<s<<endl;
	
}

int main()
{
	init();
	doing();
	return 0;
}


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

int main(){
    int N;  cin >> N;
    string sl, sr;
    cout << 0 << endl;  cin >> sl;
    if(sl == "Vacant"){
        cout << 0 << endl;
        return 0;
    }
    cout << N-1 << endl;  cin >> sr;
    if(sr == "Vacant"){
        cout << N-1 << endl;
        return 0;
    }

    int left = 0, right = N - 1;
    while(true){
        int mid = (left + right)/2;
        string s;
        cout << mid << endl;  cin >> s;
        if(s == "Vacant"){
            cout << mid << endl;
            return 0;
        }

        if(((mid - left + 1)%2 == 0 && sl == s) || ((mid - left + 1)%2 == 1 && sl != s)){
            right = mid;
            sr = s;
        }else{
            left = mid;
            sl = s;
        }
    }
}

Measured memory_bytes: 852
#include<cstdio>
#include<iostream>
#include<cstring>
#define in inline
#define re register
using namespace std;
in long long read(){
	re long long t=0;
	re char v=getchar();
	while(v<'0'||v>'9')v=getchar();
	while(v>='0'&&v<='9'){
		t=(t<<3)+(t<<1)+(v^48);
		v=getchar();
	}
	return t;
}const long long M=1e9+7;  
inline long long ksm(re long long p,re long long b){
    long long ans=1;
    while(b){
        if(b&1){
          ans*=p;
            ans%=M;
        }
        p*=p;
        p%=M;
        b>>=1;
    }
    return ans;
}

long long cnt[62];
long long ans,n;
int main(){
	n=read();
	for(re long long i=1;i<=n;++i){
		long long num=0;
		long long tmp=read();
		while(num<=61){
			if(tmp&1)++cnt[num],ans=(ans+ksm(2,num)*(i-cnt[num]))%M;
			else ans=(ans+ksm(2,num)*cnt[num])%M;
			tmp>>=1;
			++num;
			
		}
	}
	printf("%lld",ans%M);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int n, a;
int nums[200001];
 
int main() {
	cin >> n;
	for(int i = 0; i < n - 1; i++){
	    cin >> a;
	    nums[a]++;
	}
	
	for(int i = 1; i <= n; i++){
	    cout << nums[i] << '\n';
	}
	return 0;
}

Measured memory_bytes: 4372
import itertools
from collections import deque,Counter
import bisect
import heapq

def IN(): return int(input())
def sIN(): return input()
def MAP(): return map(int,input().split())
def LMAP(): return list(map(int,input().split()))
def TATE(n): return [input() for i in range(n)]
MOD = 10**9 + 7

x,n = map(int,input().split())
if  n == 0:
  print(x)
  exit()
p = list(map(int,input().split()))

if x not in p:
  print(x)
  exit()
for i in range(1,5555555):
  a = x-i
  b = x+i
  if a not in p and b not in p:
    print(a)
    exit()
  if a not in p and b  in p:
    print(x-i)
    exit()
  if b not in p and a in p:
    print(x+i)
    exit()
  

Measured memory_bytes: 9424
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string A, B, C;
    cin >> A >> B >> C;
    int a = 0, b = 0, c = 0;
    char state = 'a';
    while(true) {
        //dump(state);
        //dump(a); dump(b); dump(c);
        if(state == 'a') {
            if (a == A.length()) {
                cout << "A" << endl; 
                return 0;
            }
            state = A[a++];
        } else if (state == 'b') {
            if (b == B.length()) {
                cout << "B" << endl; 
                return 0;
            }
            state = B[b++];
        } else if (state == 'c') {
            if (c == C.length()) {
                cout << "C" << endl; 
                return 0;
            }
            state = C[c++];
        }
        
    }

    return 0;
}


Measured memory_bytes: 256
import scala.annotation.tailrec
import scala.collection.mutable
import scala.io.StdIn._
object Main extends App {
  val n = readInt()
  val num = readLine.trim.split(' ').map(_.toInt)
  println{
    if (num.forall{i ⇒ (i % 2 == 1) || (i % 3 == 0) || (i % 5 == 0)}) "APPROVED" else "DENIED"
  }
}


Measured memory_bytes: 27304
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please

int G[100001];
pair<int, int> E[200001];
int P[100002];
int dfs(int A) {
	if (G[A] == 0) {
		int g = 0;
		G[A] = -1;
		for (int i = P[A]; i < P[A + 1]; i++) {
			g ^= dfs(E[i].second);
		}
		return G[A] = g + 1;
	}
	return 0;
}

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


	int N;
	cin >> N;
	for (int i = 0; i < N + N - 2; i += 2) {
		int x, y;
		cin >> x >> y;
		E[i] = mp(x, y);
		E[i + 1] = mp(y, x);
	}
	sort(E, E + N + N - 2);
	int k = 0;
	rep(i, N + N - 2) {
		if (k != E[i].first) {
			k++;
			P[k] = i;
		}
	}
	P[N + 1] = N + N - 2;

	dfs(1);

	if (G[1] - 1) co("Alice");
	else co("Bob");

	Would you please return 0;
}

Measured memory_bytes: 7296
#include <iostream>

using namespace std;

int main()
{
    int a,b,c,maxn;
    cin>>a>>b>>c;
    maxn=max(a, b);
    maxn=max(maxn, c);
    if(maxn==a)
    {
        cout<<b+c;
    }
    else if(maxn==b)
    {
        cout<<a+c;
    }
    else
    {
        cout<<a+b;
    }
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;

int main()
{
    using vi = vector<int>;
    using vvi = vector<vi>;
    using vvvi = vector<vvi>;

    string S;
    cin >> S;

    int parity = 1;
    bool good = true;
    for(char s : S)
    {
        if(parity == 1) // 奇数文字目
        {
            if(!(s == 'R' || s == 'U' || s == 'D'))
            {
                good = false;
                break;
            }
            parity = 0;
        }
        else // 偶数文字目
        {
            if(!(s == 'L' || s == 'U' || s == 'D'))
            {
                good = false;
                break;
            }
            parity = 1;
        }
    }
    cout << (good ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <math.h>
#include <cmath>
#include<cctype>
#include<string>
#include<set>
#include<iomanip>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include<bitset>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility> 
using namespace std;
using ll = long long;
using R = double;
using Data = pair < ll, vector <ll>>;
template<typename T>using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
const ll MOD = 1e9 + 7;
const ll inf = 1LL << 60;
struct edge { ll from; ll to; ll cost; };
typedef pair<ll, ll>pll;
#define all(x) (x).begin(),(x).end()
#define rep(i,m,n) for(ll i = m;i < n;++i)
#define pb push_back
#define fore(i,a) for(auto &i:a)
#define rrep(i,m,n) for(ll i = m;i >= n;--i)
#define INF INT_MAX/2

int main() {
	ll W, H, x, y;
	cin >> W >> H >> x >> y;

	int fl;
	if (W%2 == 0 && H%2 == 0 && x == W / 2 && y == H / 2) {
		fl = 1;
	}
	else {
		fl = 0;
	}
	W = (double)W;
	H = (double)H;
	double S = W * H;
	printf("%.20f", S / 2.0);
	cout << " " << fl << endl;

	return 0;
}


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

int main()
{
	int n;
	cin >> n;
	int T[100000+521],X[100000+521],Y[100000+521];
	for(int i = 1;i <= n;i++)
	{
		cin >> T[i] >> X[i] >> Y[i];
	}
	for(int i = 1;i <= n;i++)
	{
		if(T[i]<X[i]+Y[i])
		{
			cout << "No";
			break;
		}
		if(T[i]>X[i]+Y[i]&&(X[i]+Y[i])%2!=T[i]%2)
		{
			cout << "No";
			break;
		}
		if(i==n)
			cout <<"Yes";
	}
	
	
	return 0;
}

Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int a,b,c;
  cin>>a>>b>>c;
  if(a==b || b==c || c==a)
  {if(a==b && b==c)
  {cout<<"No";}
  else
    cout<<"Yes";
  }
  else 
    cout<<"No";
  return 0;
}

Measured memory_bytes: 256
'use strict'

function Main(input) {
  const A = Number(input.split(" ")[0])
  const B = Number(input.split(" ")[1])

  const add = A + B
  const diff = A - B
  const cross = A * B

  console.log(Math.max(add, diff, cross))

}
Main(require("fs").readFileSync("/dev/stdin", "utf8").trim())

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

double p[10];
double q[10];

double tsa, tsb, tss1, tss2;

double ilep[10];
double ileq[10];

double check(double v)
{
	double ret=0.0;
	for (int i=1; i<=6; i++)
		ilep[i]=p[i]*v;
	for (int i=1; i<=6; i++)
		ileq[i]=q[i]*(1.0-v);
	for (int i=1; i<=6; i++)
		ret+=max(ilep[i], ileq[i]);
	return ret;
}

int main()
{
	for (int i=1; i<=6; i++)
	{
		int p1;
		scanf("%d", &p1);
		p[i]=p1/100.0;
	}
	for (int i=1; i<=6; i++)
	{
		int p1;
		scanf("%d", &p1);
		q[i]=p1/100.0;
	}
	tsa=0.0;
	tsb=1.0;
	for (int h=1; h<=60 && tsa<tsb; h++)
	{
		tss1=(2.0*tsa+tsb)/3.0;
		tss2=(tsa+2.0*tsb)/3.0;
		if (check(tss1)<check(tss2))
			tsb=tss2;
		else
			tsa=tss1;
	}
	printf("%.11lf\n", check(tsa));
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<math.h>
#include<algorithm>
using namespace std;

int main() {
  int n, cnt;
  cin >> n;
  cnt = 0;
  for(int i = 0; i < n; i++){
    int x;
    cin >> x;
    int max = (int)sqrt(x);
    if (x == 2 || x == 3){
      cnt += 1;
      continue;
    }
    for(int j = 2; j <= max; j++){
      if (x % j == 0) break;
      if (j == max){
    cnt += 1;
      }
    }
  }
  cout << cnt << endl;
  return 0;
}



Measured memory_bytes: 3068
#include <iostream>
#include <cmath>
#define INF 1e+9
using namespace std;
 
int main(){
	int n,m,a[50],b[50],c[50],d[50];
	cin >> n >> m;
	for(int i = 0;i < n;i++){
		cin >> a[i] >> b[i];
	}
	for(int i = 0;i < m;i++) cin >> c[i] >> d[i];
	for(int i = 0;i < n;i++){
		int mi = INF,mii;
		for(int j = 0;j < m;j++){
			int e = abs(a[i] - c[j]) + abs(b[i] - d[j]);
			if(mi > e){
				mi = e;
				mii = j + 1;
			}
		}
		cout << mii << endl;
	}
	return 0;
}

Measured memory_bytes: 256
N = int(input())
number = list(map(int,input().split()))
count = 0
if not 1 in number:
    print(-1)
else:
    nownumber = 1
    nowindex = 0
    for i in range(N):
        if number[i]  == nownumber:
            count += 1
            nownumber += 1
        else:
            pass
    print(N-count)

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

#define ll long long
#define ull unsigned long long
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(a,b) for(int a=0;a<(b);++a)
#define REP1(i,n) for(int i=1;i<=(n);++i)
#define debug(x) cerr<<#x<<": "<<x<<'\n'
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair
#define INF (1<<29)
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

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

template<class T=int>
T in(){T x;cin>>x;return (x);}
template<class T>
void print(T& x){cout<<x<<'\n';}

const int MOD =(int)1e9+7;
const int MAX =510000;
ll fac[MAX],finv[MAX],inv[MAX];
void COMint(){
    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;
    for(int i=2;i<MAX;i++){
        fac[i]=fac[i-1]*i%MOD;
        inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
        finv[i]=finv[i-1]*inv[i]%MOD;
    }
}
ll COM(int n,int k){
    if(n<k) return 0;
    if(n<0||k<0)return 0;
    return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}
ll gcd(ll a,ll b){
    if(b==0)return a;
    if(a>b){
        swap(a,b);
    }
    return gcd(a,b%a);
}
ll lcm(ll a,ll b){
    ll g;g=gcd(a,b);
    return a*b/g;
}
bool compare_by_b(pair<int, int> a, pair<int, int> b) {
    if(a.second != b.second){
        return a.second < b.second;
    }else{
        return a.first < b.first;
    }
}

bool compare_by_a(pair<int, int> a, pair<int, int> b) {
    if(a.first != b.first){
        return a.first < b.first;
    }else{
        return a.second < b.second;
    }
}

vector<int>vec[8];
bool visited[8];
int dfs(int now,bool){

}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    string S=in<string>();
    string T=in<string>();
    int ans;ans=0;
    REP(i,3){
        if(S[i]==T[i])ans++;
    }
    print(ans);
    return 0;
}


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

bool pairSort( pair<long,long> &a, pair<long,long> &b ) {
		return (a.second < b.second);
}

int main()
{
	int n;
	cin >> n;
	vector< pair<long, long>> works( n );

	for( int i = 0; i < n; i++ )
	{
		cin >> works[i].first >> works[i].second;
	}

	sort( works.begin(), works.end(), pairSort );

	long long time = 0;
	for( int i = 0; i < n; i++ )
	{
		time += works[i].first;
		if( time > works[i].second )
		{
			cout << "No" << endl;
			return 0;
		}
	}

	cout << "Yes" << endl;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int , int> i_i;
typedef vector<ll> vel;
typedef vector<int> vei;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> ve_vel;
typedef vector<vector<int>> ve_vei;
typedef vector<vector<char>> ve_vec;
typedef vector<vector<bool>> ve_veb;
typedef vector<vector<string>> ve_ves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define fs first
#define sc second
#define pub push_back
#define puf push_front
#define pob pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
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; }

map< int64_t, int > prime_factor(int64_t n) {
  map< int64_t, int > ret;
  for(int64_t i = 2; i * i <= n; i++) {
    while(n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if(n != 1) ret[n] = 1;
  return ret;
}

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

  ll ans = 1;
  ll temp;
  vel num(N,1);
  rep1(i,N+1){
      for(auto p : prime_factor(i)) {
        while(p.second--) num[p.fs-1]++;
    }
  }
  rep(i,N) {
      ans *= num[i];
      if(ans > mod) ans %= mod;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
loop {
    e = gets.to_i
    break if e == 0
    m = e
    loop.with_index { |_, z|
        break if(z**3 > e)
        y = Math.sqrt(e - z**3).to_i
        m = [m, e+y+z-y**2-z**3].min
    }
    puts m
}

Measured memory_bytes: 6128
import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        String[] c;
        c = new String[3];
        for(int i=0;i<c.length;i++)
        {
            c[i]=scan.next();
            System.out.print(c[i].charAt(i)); 
        }
        System.out.println("");
    }
}

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

using namespace std;

typedef long long lint;

lint rez;

int a[309][309];
int b[309][309];
int gasit[309][309];

int n;

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

    int i, j;
    for(i = 1; i <= n; i ++)
    {
        for(j = 1; j <= n; j ++)
        {
            scanf("%d", &a[i][j]);
        }
    }
    int k;

    for(k = 1; k <= n; k ++)
    {
        for(i = 1; i <= n; i ++)
        {
            for(j = 1; j <= n; j ++)
            {
                if(i != j && i != k && j != k)
                if(a[i][k] + a[k][j] == a[i][j])
                {
                    gasit[i][j] = 1;
                }
            }
        }
    }

    for(i = 1; i <= n; i ++)
    {
        for(j = 1; j <= n; j ++)
        {
            if(i != j)
            {
                if(gasit[i][j] == 0)
                {
                    gasit[i][j] = 2, rez += 1LL * a[i][j];

                    b[i][j] = a[i][j];
                }

                else
                    b[i][j] = 1000000001;
            }
        }
    }

    for(k = 1; k <= n; k ++)
    {
        for(i = 1; i <= n; i ++)
        {
            for(j = 1; j <= n; j ++)
            {
                if(i != j)
                if(b[i][k] + b[j][k] < b[i][j])
                {
                    b[i][j] = b[i][k] + b[j][k];
                }
            }
        }
    }

    for(i = 1; i <= n; i ++)
    {
        for(j = 1; j <= n; j ++)
        {
            if(b[i][j] != a[i][j])
            {
               // printf("DIFERA %d %d  %d %d", i, j, b[i][j], a[i][j]);
                printf("-1\n");

                return 0;
            }
        }
    }

    printf("%lld\n", rez / 2);

    return 0;
}


Measured memory_bytes: 1408
def main():
    import sys
    def input(): return sys.stdin.readline().rstrip()
    n = int(input())
    lx = []
    rx = []
    for i in range(n):
        a = 0
        cnt = 0
        for j in input():
            if j == '(':
                cnt += 1
            else:
                cnt -= 1
            a = min(a, cnt)
        
        if cnt >= 0:
            lx.append((a, cnt))
        else:
            rx.append((a, cnt))
    lx.sort(key= lambda x: -x[0]) # -aの昇順
    rx.sort(key= lambda x: x[0]-x[1]) # -bの昇順(bの降順)
    total = 0
    check = True
    for x,cnt in (lx+rx):
        if total + x < 0:
            check = False
            break
        total += cnt
    if total == 0 and check:
        print('Yes')
    else:
        print("No")
    




if __name__ == '__main__':
    main()

Measured memory_bytes: 91744
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Scanner;
import java.util.Set;

public class Main {
    private static int n;
    private static List<List<Integer>> edge;

    private static int root(Set<Integer> set, int from, int i) {
        if(i == n - 1) return 1;

        int res = 0;
        for(int to : edge.get(from)) {
            if(!set.contains(to)) {
                Set<Integer> nset = new HashSet<>();
                for(int j : set) {
                    nset.add(j);
                }
                nset.add(to);
                res += root(nset, to, i + 1);
            }
        }
        return res;
    }

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

        n = sc.nextInt();
        int m = sc.nextInt();
        edge = new ArrayList<>();
        for(int i = 0; i < n; i++) {
            edge.add(new ArrayList<>());
        }
        for(int i = 0; i < m; i++) {
            int a = sc.nextInt() - 1;
            int b = sc.nextInt() - 1;
            edge.get(a).add(b);
            edge.get(b).add(a);
        }

        Set<Integer> set = new HashSet<>();
        set.add(0);
        System.out.println(root(set, 0, 0));

        sc.close();
    }
}

Measured memory_bytes: 29396
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i < (n+1); ++i)
const double PI  =3.141592653589793238463;
using namespace std;
using ll = long long;
const ll INF = +10010010000;
typedef pair<int,int> P;
const int mod = 1e9+7;

struct mint{
    ll x;
    mint(ll x=0):x((x%mod+mod)%mod){}
    mint& operator+=(const mint a){
        (x+=a.x)%=mod;
        return *this;
    }
    mint& operator-=(const mint a){
        (x-=mod-a.x)%=mod;
        return *this;
    }
    mint& operator*=(const mint a){
        (x *= a.x)%= mod;
        return *this;
    }
    mint operator+(const mint a)const{
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint a)const{
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint a)const{
        mint res(*this);
        return res*=a;
    }
    mint pow(ll t) const {
      if(!t)return 1;
      mint a = pow(t>>1);
      a*=a;
      if(t%1)a*=*this;
      return a;
    }

    // for prime mod
    mint inv() const {
      return pow(mod-2);
    }
    mint& operator/=(const mint a){
      return (*this) *= a.inv();
    }
    mint operator/(const mint a)const{
      mint res(*this);
      return res/=a;
    }
};

struct combination{
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1){
    fact[0] = 1;
    for(int i = 1; i<n;++i)fact[i] = fact[i-1] * i;
    ifact[n] = fact[n].inv();
    for(int i = n; i>=1;--i) ifact[i-1] = ifact[i] * i;
  }
  mint operator()(int n, int k){
    if(k<0 || k>n)return 0;
    return fact[n] * ifact[k] + ifact[n-k]; 
  }
};

int main(){
    int n,k;
    cin >> n >> k;
    ll ans=0;
    if(k%2==1){
        int cnt = 0;
        rrep(i,n){
            if(i%k==0)cnt++;
        }
        ans = pow(cnt,3);
    }else{
        int cnt1 = 0;
        int cnt2 = 0;
        rrep(i,n){
            if(i%k==0)cnt1++;
            else if(i%k==k/2)cnt2++;
        }
        ans = pow(cnt2,3) + pow(cnt1,3);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>

#define mod 1000000007
using namespace std;

long long dp[3010][3010],a[3010],l[3010],r[3010],mx;
int main(){
	string s;
	pair<int,int> p[3010],q[3010];
	int i,j,n,m,x,y;
	cin >> n >> m >> s;
	j = 0;
	cin >> l[0] >> r[0];
	mx = r[0];
	for(i=1;i<m;i++){
		cin >> l[i] >> r[i];
		if(l[i]==l[i-1]){
			mx = max(mx,r[i]);
		}else{
			q[j] = make_pair(l[i-1],mx);
			mx = r[i];
			j++;
		}
	}
	q[j] = make_pair(l[m-1],mx);
	int k = 0;
	p[0] = q[0];
	for(i=1;i<=j;i++){
		if(q[i].second>p[k].second){
			k++;
			p[k] = q[i];
		}
	}
	
	/*for(i=0;i<=k;i++){
		cout << p[i].first << " " << p[i].second << endl;
	}*/
	p[k+1] = make_pair(3010,3010);
	k = 0;
	a[0] = 0;
	for(i=0;i<n;i++){
		if(s[i]=='1'){
			k++;
		}
		a[i+1] = k;
	}
	
	for(i=0;i<=n;i++){
		for(j=0;j<=n;j++){
			dp[i][j] = 0;
		}
	}
	
	k = 0;
	dp[0][0] = 1;
	for(i=1;i<=n;i++){
		if(p[k].first==i){
			k++;
		}
		//cout << i << " " << k << endl;
		for(j=0;j<i;j++){
			if(k==0 || (i<p[k].first && i>p[k-1].second)){
				if(i==22){
					//cout << i << endl;
				}
				if(s[i-1]=='1'){
					dp[i][j+1] += dp[i-1][j];
					dp[i][j+1] %= mod;
				}else{
					dp[i][j] += dp[i-1][j];
					dp[i][j+1] %= mod;
				}
			}else{// k>=1 && p[mx-1].first<=i<=p[mx-1].second
				dp[i][j+1] += dp[i-1][j];
				dp[i][j+1] %= mod;
				if(a[p[k-1].second]<j+1 || a[p[k-1].second]-(p[k-1].second-i)>j+1){
					//cout << i << " "<< j << endl;
					dp[i][j+1] = 0;
				}
				dp[i][j] += dp[i-1][j];
				dp[i][j] %= mod;
				if(a[p[k-1].second]<j || a[p[k-1].second]-(p[k-1].second-i)>j){
					//cout <<" " << i << " " << j << endl;
					dp[i][j] = 0;
				}
			}
		}
	}
	/*for(i=0;i<=n;i++){
		cout << a[i] << " " ;
	}
	cout << endl;
	cout << "  " ;
	for(i=0;i<=n;i++){
		cout << i << " " ;
	}
	cout << endl;
	for(i=0;i<=n;i++){
		cout << i << " " ;
		for(j=0;j<=n;j++){
			cout << dp[i][j] << " ";
		}
		cout << endl;
	}*/
	
	cout << dp[n][a[n]] << endl;
}

/*
22 15
1010011100010100100000
2 7
4 6
5 8
8 9
10 12
11 13
11 14
12 14
12 17
12 14
13 17
15 16
16 21
17 21
18 20
*/
	

Measured memory_bytes: 71040
#include<stdio.h>
#include<stdlib.h>
int parent(int);
int left(int);
int right(int);
void maxHeapify(int*, int);
void buildMaxHeap(int*);
int n;
int main(){
  int *T, i;
  scanf("%d",&n);
  T = (int*)malloc(sizeof(int) * (n+1));
  for(i=1; i<=n; i++) scanf("%d",&T[i]);
  buildMaxHeap(T);
  for(i=1; i<=n; i++) printf(" %d",T[i]);
  printf("\n");
  return 0;
}
int parent(int n){
  return n/2;
}
int left(int n){
  return 2*n;
}
int right(int n){
  return 2*n+1;
}
void maxHeapify(int *A, int i){
  int l=left(i), r=right(i), largest, temp;
  if(l <= n && A[l] > A[i]) largest = l;
  else largest = i;
  if(r <= n && A[r] > A[largest]) largest = r;
  if(largest != i){
    temp = A[i];
    A[i] = A[largest];
    A[largest] = temp;
    maxHeapify(A,largest);
  }
}
void buildMaxHeap(int *A){
  int i;
  for(i=n/2; i>0; i--) maxHeapify(A,i);
}

Measured memory_bytes: 2556