akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using static System.Math;
using System.Linq;
using System.Text;

class DandA {
    static void Main(string[] args) {
        int n = ReadLineInt();
        string s = ReadLineStr();
        if (n % 2 == 0) {
            if (s.Substring(0, n / 2) == s.Substring(n / 2, n / 2)) {
                Console.WriteLine("Yes");
            } else {
                Console.WriteLine("No");
            }
        } else {
            Console.WriteLine("No");
        }
    }

    static string[] ary = new string[] {"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"};
  
    static private string ReadLineStr() {return Console.ReadLine();}
    static private int ReadLineInt() {return int.Parse(Console.ReadLine());}
    static private string[] ReadLineStrArray() {return Console.ReadLine().Trim().Split();}
    static private int[] ReadLineIntArray() {return Console.ReadLine().Trim().Split().Select(a => int.Parse(a)).ToArray();}
    static private long[] ReadLineLongArray() {return Console.ReadLine().Trim().Split().Select(a => long.Parse(a)).ToArray();}
    static private string[][] ReadMLineStrArray(int arg) { return new int[arg].Select(_ => Console.ReadLine().Split()).ToArray();}
    static private int[][] ReadMLineIntArray(int arg) { return new int[arg].Select(_ => Console.ReadLine().Split().Select(int.Parse).ToArray()).ToArray();}

    static private bool IsPrime(int num) {
        if (num < 2) return false;
        if (num == 2) return true;
        else if (num % 2 == 0) return false;
        double sqrtNum = Math.Sqrt(num);
        for (int i = 3; i <= sqrtNum; i += 2) {
            if (num % i == 0) return false;
        }
        return true;
    }
}


Measured memory_bytes: 13140
from sys import stdin
def make_divisors(n):
    mod0 = set()
    mod1 = set()
    for i in range(1, int(n**0.5)+1):
        if n%i==0:
            mod0.add(i)
            mod0.add(n/i)
        if (n-1)%i==0:
            mod1.add(i)
            mod1.add((n-1)/i)

    return mod0,mod1

N=list(map(int,(stdin.readline().strip().split())))
num=N[0]
K=0
mod0,mod1=(make_divisors(num))
mod0.remove(1)
mod1.remove(1)
for i in mod0:
    num = N[0]
    while(num % i == 0):
        num/=i

    if num%i==1:
        K+=1
K+=len(mod1)
print(K)


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

#define PI 3.14159265
  

int main() 
{
    int n;
    cin>>n;
    string s;
    cin>>s;
    int l=s.length();
    if(l<=n)
    cout<<s;
    else
    cout<<s.substr(0,n)+"...";
}

/*1.000000000
2.414213562
127.321336469



*/

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

int X[2], Y[2], Z[2], W[2];
int x, y, z, w;

void calc(){
  x = X[0] * X[1] + (Y[0] * Y[1] * -1) + (Z[0] * Z[1] * -1) + (W[0] * W[1] * -1);
  y = X[0] * Y[1] + Y[0] * X[1] + Z[0] * W[1] + (W[0] * Z[1] * -1);
  z = X[0] * Z[1] + (Y[0] * W[1] * -1) + Z[0] * X[1] + W[0] * Y[1];
  w = X[0] * W[1] + Y[0] * Z[1] + (Z[0] * Y[1] * -1) + W[0] * X[1];
}

int main() {
  int T;
  while(cin >>T && T != 0){
    REP(t, T){
      cin >>X[0] >>Y[0] >>Z[0] >>W[0];
      cin >>X[1] >>Y[1] >>Z[1] >>W[1];
      calc();
      printf("%d %d %d %d\n", x, y, z, w);
    }
  }
  return 0;
}

Measured memory_bytes: 1144
import java.util.Scanner;
import java.util.Stack;

class Main {

    public static void main(String[] args) {
        new Main().compute();
    }

    void compute() {
        Scanner sc = new Scanner(System.in);
        String S = sc.next();
        int max = 0;
        for (int i = 1; i < S.length() / 2; i++) {
            if (S.substring(0, i).equals(S.substring(i, 2 * i))) {
                max = 2 * i;
            }
        }
        System.out.println(max);
    }
}


Measured memory_bytes: 23508
import itertools
N, M, Q = map(int, input().split())
par = []
for _ in range(Q):
    par.append([int(x) for x in input().split()])

ans = 0
for A in itertools.combinations_with_replacement(range(M), N):
#     print(A)
    temp = 0
    for i in range(Q):
        if A[par[i][1]-1] - A[par[i][0]-1] == par[i][2]:
            temp += par[i][3]
    ans = max(ans, temp)
print(ans)

Measured memory_bytes: 9148
/////////////////////////////////////////////template 1
#include <bits/stdc++.h>
#define MOD 1000000007
//for(int i=0; i<n; ++i)
using namespace std;
#define all(c) c.begin(), c.end()
#define watch(x) cout << (#x) << " is " << (x) << endl
#define ll long long

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n, k;
    cin >> n >> k;
    vector<int> h(n), dp(n, INT_MAX);
    for (int i = 0; i < n; ++i)
        cin >> h[i];
    dp[0] = 0;
    for (int i = 1; i < n; ++i)
        for (int j = max(0, i - k); j < i; ++j)
            dp[i] = min(dp[i], dp[j] + abs(h[i] - h[j]));
    cout << dp[n - 1] << endl;
    return 0;
}

Measured memory_bytes: 1024
package main

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

var sc = bufio.NewScanner(os.Stdin)

func scanText() string {
	sc.Scan()
	return sc.Text()
}

func scanInt() int {
	sc.Scan()
	a, err := strconv.Atoi(sc.Text())
	if err != nil {
		fmt.Println(err)
	}
	return a
}

func scanInt64() int64 {
	sc.Scan()
	a, err := strconv.Atoi(sc.Text())
	if err != nil {
		fmt.Println(err)
	}
	return int64(a)
}

func scanFloat() float64 {
	sc.Scan()
	a, err := strconv.ParseFloat(sc.Text(), 64)
	if err != nil {
		fmt.Println(err)
	}
	return a
}

func scanTextSlice(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = scanText()
	}
	return a
}

func scanSlice(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = scanInt()
	}
	return a
}

func scanFloatSlice(n int) []float64 {
	a := make([]float64, n)
	for i := 0; i < n; i++ {
		a[i] = scanFloat()
	}
	return a
}

func scanInt64Slice(n int64) []int64 {
	a := make([]int64, n)
	for i := int64(0); i < n; i++ {
		a[i] = scanInt64()
	}
	return a
}

// var sc = bufio.NewScanner(os.Stdin)

func main() {
	sc.Split(bufio.ScanWords)

	n := scanInt()
	// arr := make([]float64, 0)
	p := scanSlice(n)
	q := scanSlice(n)

	memo := make([]int, 0)
	for i := 1; i <= n; i++ {
		memo = append(memo, i)
	}

	m := n - 1
	partial := factorial(m)

	pNum := int64(1)

	for i := 0; i < n-1; i++ {
		num := p[i]
		index := binarySearch(memo, num)
		memo = deleteNumOfArray(memo, index)
		pNum += partial * int64(index)
		partial /= int64(m)
		m--
		// fmt.Println("memo: ", memo)
		// fmt.Println("pNum: ", pNum)

	}

	// fmt.Println("------------------------")

	memo = make([]int, 0)
	for i := 1; i <= n; i++ {
		memo = append(memo, i)
	}
	// fmt.Println(memo)

	m = n - 1
	partial = factorial(m)

	qNum := int64(1)

	for i := 0; i < n-1; i++ {
		num := q[i]
		index := binarySearch(memo, num)
		memo = deleteNumOfArray(memo, index)
		qNum += partial * int64(index)
		partial /= int64(m)
		m--
	}
	ans := pNum - qNum
	if ans < 0 {
		ans *= -1
	}
	fmt.Println(ans)

}

func binarySearch(arr []int, number int) int {
	// fmt.Println("number: %s", number)

	l := -1
	r := len(arr)
	index := 0
	for {
		mid := l + (r-l)/2
		tmp := arr[mid]
		// fmt.Println("number: %s", number)
		// fmt.Println("tmp: %s", tmp)
		// fmt.Println("mid: %s , left : %s , right : %s", mid, l, r)

		if r-l <= 1 || tmp == number {
			index = mid
			break
		} else if tmp < number {
			l = mid
		} else {
			r = mid
		}
	}
	return index
}

func factorial(n int) int64 {
	sum := int64(1)
	for i := 2; i <= n; i++ {
		sum *= int64(i)
	}
	return sum
}

func deleteNumOfArray(arr []int, position int) []int {
	left := arr[:position]
	r := arr[position+1:]
	appendArr := append(left, r...)
	return appendArr
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define pb push_back
using namespace std;

int n,m,cnt;

vector<int>a[1000];

int main() {
	scanf("%d",&n);
	
	for(int i=1;i*(i-1)<=2*n;i++) if(i*(i-1)==n*2) m=i;
	
	if(!m) {
		puts("No");return 0;
	}
	
	puts("Yes");printf("%d\n",m);
	
	for(int i=1;i<=m;i++) for(int j=i+1;j<=m;j++) cnt++,a[i].pb(cnt),a[j].pb(cnt);
	
	for(int i=1;i<=m;i++) {
		printf("%d ",a[i].size());
		for(int j=0;j<a[i].size();j++) printf("%d ",a[i][j]);puts("");
	}
	
	return 0;
}


Measured memory_bytes: 2304
#include<iostream>
#include<string>
#include<map>
#include<tuple>
#include<vector>
#include<set>

using namespace std;

struct edge{
  int v,f;
};

map<string,int> m;
vector<edge> G[2000];

int num(string s){
  if(!m.count(s)){
    auto n=m.size();
    m[s]=n;
    G[n].clear();
  }
  return m[s];
}

tuple<int,int> input(){
  string s;
  cin>>s;
  int h=s.find('-');
  int x=num(s.substr(0,h));
  int y=num(s.substr(h+1));
  return make_tuple(x,y);
}

bool dfs(int x,int y,int f,set<int> &s){
  if(x==y)return f;
  if(!s.insert(x).second)return false;
  for(auto e:G[x]){
    if(dfs(e.v,y,f^e.f,s))return true;
  }
  return false;
}

int main(){
  for(int N;cin>>N,N;){
    m.clear();
    bool d[200][200]={};
    for(int i=0;i<N;i++){
      int x,y;
      tie(x,y)=input();
      G[y].push_back({x,1});
      d[y][x]=true;
    }
    for(int i=0;i<200;i++){
      for(int j=0;j<i;j++){
	bool s=false,df=false;
	for(int k=0;k<200;k++){
	  s|=d[i][k]&&d[j][k]||d[k][i]&&d[k][j];
	  df|=d[i][k]&&d[k][j]||d[j][k]&&d[k][i];
	}
	if(s&&!df){
	  G[j].push_back({i,0});
	  G[i].push_back({j,0});
	}
      }
    }
    cout<<m.size()<<endl;
    int M;
    cin>>M;
    while(M--){
      int x,y;
      tie(x,y)=input();
      set<int> s;
      cout<<(dfs(y,x,0,s)?"YES":"NO")<<endl;
    }
  }
}

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

vector<int> g[200005];
vector<int> ans(200005);

void dfs(int a, int p = -1) {
	for (auto& c : g[a]) {
		if (c == p) continue;
		ans[c] += ans[a];
		dfs(c, a);
	}
}

int main() {
	int n, q;
	cin >> n >> q;
	rep(i, n - 1) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		g[a].emplace_back(b);
		g[b].emplace_back(a);
	}
	rep(i, q) {
		int p, x;
		cin >> p >> x;
		p--;
		ans[p] += x;
	}
	dfs(0);
	rep(i, n) cout << ans[i] << (i == n - 1 ? "\n" : " ");
	return 0;
}


Measured memory_bytes: 23424
N, M = list(map(int, input().split()))

aisle_dict = {i+1:[] for i in range(N)}
direction = {1:0}

for i in range(M):
    A, B = list(map(int, input().split()))
    aisle_dict[A].append(B)
    aisle_dict[B].append(A)
    
def calc_next(current_rooms):
    all_next_rooms = []
    for current_room in current_rooms:
        next_rooms = aisle_dict[current_room]
        for room in next_rooms:
            if room not in direction:
                direction[room] = current_room
                all_next_rooms.append(room)
    return all_next_rooms
    
rooms = [1]
while len(direction) < N:
    rooms = calc_next(rooms)

print("Yes")
for i in range(2, N+1):
    print(direction[i])

Measured memory_bytes: 50380
def solve():
    N, A, B = [int(i) for i in input().split()]
    ans = 0
    for i in range(1, N + 1):
        s = sum([int(x) for x in str(i)])
        if A <= s <= B:
            ans += i
    print(ans)


if __name__ == "__main__":
    solve()

Measured memory_bytes: 73964
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        B solver = new B();
        solver.solve(1, in, out);
        out.close();
    }

    static class B {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            // 入力
            String S = in.next();

            int s_a = Integer.parseInt(S.substring(0, 2));
            int s_b = Integer.parseInt(S.substring(2, 4));
            if (s_a >= 1 && s_a <= 12) {
                if (s_b >= 1 && s_b <= 12) {
                    out.println("AMBIGUOUS");
                } else {
                    out.println("MMYY");
                }
            } else {
                if (s_b >= 1 && s_b <= 12) {
                    out.println("YYMM");
                } else {
                    out.println("NA");
                }
            }
            // 出力

        }

    }
}



Measured memory_bytes: 25172
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<stdio.h>
#include<queue>
#include <climits>
#include <map>
#include <set>
const long long mod = 1e9 + 7;
const int INF = 1 << 20;
using namespace std;
typedef long long ll;
typedef pair<int,int> P;


int main()
{
    while(true){
        int n; cin >> n;
        if(n == 0) break;
        int w,h; cin >> w >> h;
        int f[h][w];
        for(int i = 0; i < h; i++){
            for(int j = 0; j < w; j++){
                f[i][j] = 0;
            }
        }
        for(int i = 0; i < n; i++){
            int x,y; cin >> x >> y;
            f[y-1][x-1] = 1;
        }
        int s,t; cin >> s >> t;
        int ans = 0;
        for(int i = 0; i < h-t+1;i++){
            for(int j = 0; j < w-s+1; j++){
                int tmp = 0;
                for(int k = 0; k < t; k++){
                    for(int l = 0; l < s; l++){
                        if(f[i+k][j+l] == 1){
                            tmp++;
                        }
                    }
                }
                ans = max(ans,tmp);
            }
        }
        cout << ans << endl;
    }
}


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

typedef vector<int> vi;
typedef pair<int, int> pi;

const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;

#define pb push_back
#define mp make_pair

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REP2(i, b, e) for (int i = (b); i <= (int)(e); i++)
#define DEBUG(x) cout << #x << ": " << (x) << endl
#define DEBUGA(a) cout << #a << ": "; for (const auto& v: (a)) cout << v << endl

signed main() {
    int N;
    cin >> N;
    vi v(N);
    REP(i, N) cin >> v[i];

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

    double ans = (v[0] + v[1]) / 2.0;
    REP2(i, 2, N-1) {
        ans = (ans + v[i]) / 2.0;
    }

    cout << setprecision(10) << ans << endl;

    return 0;
}


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

#define rep(i, n) rep2(i, 0, n)
#define rep2(i, m, n) for(int i = m; i < (int)(n); ++i)
#define pb(e) push_back(e)

typedef long long ll;

string str, pre, suf;

char c(char ch)
{
    char table1[] = "(){}[]", table2[] = ")(}{][";
    rep(i, 6) if(ch == table1[i]) return table2[i];
    return ' ';
}

int f(int l, int r)
{
    if(l == pre.size() || r == suf.size())
        return 0;
    char ch = c(pre[l]);
    string::size_type pos = suf.find(ch, r);
    if(pos == string::npos) return f(l + 1, r);
    return max(f(l + 1, r), f(l + 1, pos + 1) + 1);
}

int main()
{
    cin >> str;
    rep(i, str.size()) if(str[i] == 'i') {
        pre = str.substr(0, i);
        suf = str.substr(i + 3);
        break;
    }
    reverse(suf.begin(), suf.end());
    cout << 2 * f(0, 0) + 3 << endl;
}

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

using namespace std;
using llong = long long;
using ldbl = long double;
using lpair = pair<llong, llong>;

#define ALL(x) x.begin(), x.end()

constexpr llong mod = 1e9+7;
constexpr llong inf = mod * mod;

struct node {
  int h;
  int w;
  int k;
  int m;
  int d;

  node() = default;
  node(int h, int w, int k, int m, int d):
    h(h),
    w(w),
    k(k),
    m(m),
    d(d)
  {}

  bool operator<(const node &ri) const {
    return m == ri.m ?
      k > ri.k :
      m < ri.m;
  }
  bool operator>(const node &ri) const {
    return m == ri.m ?
      k < ri.k :
      m > ri.m;
  }
};

constexpr array<llong, 9> nw = {0, 1, 0, -1, -1, 1, 1, -1, 0};
constexpr array<llong, 9> nh = {1, 0, -1, 0, 1, 1, -1, -1, 0};
int H, W, K;
vector<string> area;
lpair start, goal;

llong dijkstra() {
  vector<vector<vector<node>>> dis(H + 1, vector<vector<node>>(W + 1, vector<node>(4, node(-1, -1, 0, mod, -1))));
  priority_queue<node, vector<node>, greater<node>> que;

  node s(start.first, start.second, 0, 0, 0);
  dis[start.first][start.second][0] = s;
  que.push(s);
  while (que.size()) {
    node now = que.top();
    que.pop();

    if (dis[now.h][now.w][now.d] < now) continue;
    // cerr << now.h << " " << now.w << " "<< now.k << " " << now.m << " " << now.d << endl;
    for (int i = 0; i < 4; ++i) {
      node next(now.h + nh[i], now.w + nw[i], 0, now.m, i);
      if (next.h <= 0 || next.w <= 0 || next.h > H || next.w > W) continue;
      if (area[next.h - 1][next.w - 1] == '@') continue;
      if (now.d == i) {
        next.k = now.k - 1;
        if (next.k < 0) {
          next.k = K - 1;
          next.m++;
        }
        // cerr << next.h << " " << next.w << " " << next.k << " " << next.m << " " << next.d << endl;
      }
      else {
        next.k = K - 1;
        next.m++;
      }

      if (dis[next.h][next.w][next.d] > next) {
        dis[next.h][next.w][next.d] = next;
        que.push(next);
      }
    }
  }

  int ret = mod;
  for (int i = 0; i < 4; ++i) {
    if (dis[goal.first][goal.second][i].m < mod) {
      ret = min(ret, dis[goal.first][goal.second][i].m);
    }
  }
  if (ret == mod) {
    ret = -1;
  }

  return ret;
}


int main() {
  cin >> H >> W >> K;
  cin >> start.first >> start.second >> goal.first >> goal.second;
  area.resize(H);
  for (auto &in: area) {
    cin >> in;
  }

  cout << dijkstra() << endl;

  return 0;
}

Measured memory_bytes: 355884
#include <bits/stdc++.h>
using namespace std;
 
pair<int,int> root (int x, vector<int> &g, int t) {
  if (x == g.at(x)) {
    return pair<int,int>(x,t);
  }
  else {
    pair<int,int>  k = root(g.at(x),g,t+1);
    g.at(x) = k.first;
    return k;
  }
}
 
void connect(int a, int b, vector<int> &g) {
  pair<int,int> m = root(a,g,0);
  pair<int,int> n = root(b,g,0);  
  if (m.first != n.first) {
    if (m.second > n.second) {
      g.at(n.first) = m.first;   
    }
    else {
      g.at(m.first) = n.first;      
    }
  } 
  return;
}
 
int main() {
  
  int N, M;
  cin >> N >> M;
  
  vector<int> G(N);
  for (int i = 0; i < N; i++) {
    G.at(i) = i;
  }
  
  int A, B;
  
  for (int i = 0; i < M; i++) {
    cin >> A >> B;
    connect(A-1,B-1,G);
  }
  
  vector<int> G2(N,0);
  for (int i = 0; i < N; i++) {
    G2.at(root(i,G,0).first)++;
  }
  
  int X = 0;
  for (int i = 0; i < N; i++) {
    X = max(X,G2.at(i));
  }
  
  cout << X << endl;
  
  return 0;
}

Measured memory_bytes: 11052
#include "bits/stdc++.h"
// Begin Header {{{
#define all(x)          (x).begin(), (x).end()
#define rep(i, n)       for (i64 i = 0, i##_limit = (n); i < i##_limit; ++i)
#define reps(i, s, t)   for (i64 i = (s), i##_limit = (t); i <= i##_limit; ++i)
#define repr(i, s, t)   for (i64 i = (s), i##_limit = (t); i >= i##_limit; --i)
#define var(Type, ...)  Type __VA_ARGS__; input(__VA_ARGS__)
#ifndef DBG
#define trace(...)
#endif
using namespace std;
using i64 = int_fast64_t;
using pii = pair<i64, i64>;
template <class T, class U> inline bool chmax(T &a, const U &b) { return b > a && (a = b, true); }
template <class T, class U> inline bool chmin(T &a, const U &b) { return b < a && (a = b, true); }
inline i64  sigma(i64 n)            { return (n * (n + 1) >> 1); }
inline i64  updiv(i64 a, i64 b)     { return (a + b - 1) / b; }
inline i64  sqr(i64 n)              { return n * n; }
inline string to_string(char c)     { return string(1, c); }
constexpr int INF  = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;

template <class T>
inline vector<T> make_v(const T &initValue, size_t sz) {
    return vector<T>(sz, initValue);
}
template <class T, class... Args>
inline auto make_v(const T &initValue, size_t sz, Args... args) {
    return vector<decltype(make_v<T>(initValue, args...))>(sz, make_v<T>(initValue, args...));
}

inline void input() {}
template <class Head, class... Tail>
inline void input(Head &head, Tail&... tail) { cin >> head; input(tail...); }

inline void print() { cout << "\n"; }
template <class Head, class... Tail>
inline void print(Head &&head, Tail&&... tail) {
    cout << head;
    if (sizeof...(tail)) cout << ' ';
    print(forward<Tail>(tail)...);
}

template <class T>
inline ostream& operator<< (ostream &out, const vector<T> &vec) {
    static constexpr const char *delim[] = { " ", "" };
    for (const auto &e : vec) out << e << delim[&e == &vec.back()];
    return out;
}

template <typename Func>
struct FixPoint : Func {
    inline constexpr FixPoint(Func &&f) noexcept : Func(forward<Func>(f)) {}

    template <typename... Args>
    inline decltype(auto) operator()(Args &&... args) const {
        return Func::operator()(*this, forward<Args>(args)...);
    }
};

template< typename Func >
inline decltype(auto) makeFixPoint(Func &&f) {
    return FixPoint< Func >{forward< Func >(f)};
}
// }}} End Header

constexpr int MOD = 998244353;


inline int64_t modpow(int64_t value, int64_t p) {
    int64_t ret = 1;
    int64_t v = value;
    for (; p > 0; p >>= 1) {
        if (p & 1) (ret *= v) %= MOD;
        (v *= v) %= MOD;
    }
    return ret;
}

signed main()
{
    ios::sync_with_stdio(false); cin.tie(nullptr);

    var(int, N);

    vector<int> d(N);
    vector<i64> cnt(N + 2);

    rep(i, N) {
        input(d[i]);
        cnt[d[i]] += 1;
    }

    int last = N + 1;
    while(cnt[last] == 0) --last;

    trace(last);
    trace(cnt);


    if (cnt[0] != 1 || d[0] != 0) {
        print(0);
    } else {
        i64 ans = 1;
        reps(i, 1, last) {
            (ans *= modpow(cnt[i-1], cnt[i])) %= MOD;
        }
        print(ans);
    }


    return 0;
}


Measured memory_bytes: 1408
#include <iostream>
#include <vector>
#include <deque>

struct BFS
{
  size_t N;
  size_t M;
  std::vector<std::vector<size_t>> Graph;
  std::vector<size_t> dist;
  std::vector<std::vector<size_t>> distMap;
  std::deque<size_t> que;
  std::vector<size_t> arrow;

  BFS()
  {
    std::cin>>N;
    std::cin>>M;

    Graph.assign(N,std::vector<size_t>());
    for(size_t i=0;i!=M;i++)
    {
      size_t j1,j2;
      std::cin>>j1>>j2;
      j1--;
      j2--;
      Graph[j1].push_back(j2);
      Graph[j2].push_back(j1);
    }

    dist.assign(N,-1);
    distMap.assign(N,std::vector<size_t>());
    arrow.assign(N,-1);
  }

  void find(size_t pos)
  {
    dist[pos]=0;
    distMap[dist[pos]].push_back(pos);
    que.push_back(pos);

    while(que.empty()==false)
    {
      pos=que.front();
      que.pop_front();

      for(size_t i=0;i!=Graph[pos].size();i++)
      {
        size_t nextPos=Graph[pos][i];

        if(dist[nextPos]!=-1)
          continue;

        dist[nextPos]=dist[pos]+1;
        distMap[dist[nextPos]].push_back(nextPos);
        que.push_back(nextPos);
        arrow[nextPos]=pos;
      }
    }
  }
};

int main()
{  
  BFS f;
  f.find(0);

  for(size_t i=1;i!=f.arrow.size();i++)
  {
    if(f.arrow[i]==-1)
    {
      std::cout<<"No"<<std::endl;
      return 0;
    }
  }

  std::cout<<"Yes\n";
  for(size_t i=1;i!=f.arrow.size();i++)
  {
    std::cout<<f.arrow[i]+1<<"\n";
  }
  std::cout<<std::endl;
  
  return 0;
}

Measured memory_bytes: 17024
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int A = sc.nextInt();
		int B = sc.nextInt();
		int T = sc.nextInt();

		int count = T/A ;
		int sum = 0 ;
		for(int i = 0 ; i < count ; i ++) {
			sum += B ;
		}

		// 出力
		System.out.println(sum);

	}

}


Measured memory_bytes: 21716
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int L = sc.nextInt();
    String S[] = new String[N];
    for(int i=0;i<N;i++){
      S[i]=sc.next();
    }
    Arrays.sort(S);
    for(int i=0;i<N;i++){
      System.out.print(S[i]);
    }
  }
  

  
}

Measured memory_bytes: 21844
from collections import Counter


def inpl(): return list(map(int, input().split()))

N, K = inpl()
A = inpl()
C = Counter(A)
C = list(sorted(C.items(), key=lambda x: x[1]))

ans = 0
for i in range(len(C) - K):
    ans += C[i][1]
print(ans)

Measured memory_bytes: 39352
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<string>
#include<vector>
#include<stack>
#include<bitset>
#include<cstdlib>
#include<cmath>
#include<set>
#include<list>
#include<deque>
#include<map>
#include<queue>
using namespace std;
typedef long long ll;
const double PI = acos(-1.0);
const double eps = 1e-6;
const int INF = 0x3f3f3f3f;

int bubbleSort(int A[],int N){
	int sw =0;
	bool flag = 1;
	for(int i=0;flag;i++){
		flag =0;
		for(int j=N-1;j>=i+1;j--){
			if(A[j]<A[j-1]){
				swap(A[j],A[j-1]);
				flag = 1;
				sw++;
			}
		}
	}
	return sw;
}

int main(){
	int A[100],N,sw;
	scanf("%d",&N);
	for(int i=0;i<N;i++){
		scanf("%d",&A[i]);
	}
	sw = bubbleSort(A,N);
	
	for(int i=0;i<N;i++){
		if(i) printf(" ");
		printf("%d",A[i]);
	}
	printf("\n");
	printf("%d\n",sw);
	
	return 0;
}




Measured memory_bytes: 3216
a = int(input())
b = int(input())
c = 0
if a == 1:
  if b == 2:
    c = 3
  else:
    c = 2
elif a == 2:
  if b == 1:
    c = 3
  else:
    c = 1
elif a == 3:
  if b == 1:
    c = 2
  else:
    c = 1
print(c)

Measured memory_bytes: 2940
#include<iostream>
#include<stdio.h>

using namespace std;

int main(){
	int n;
	int max = 1;
	int a[101];
	cin >> n;
	a[n + 1] = { 0 };
	for (int i = 1; i <= n; i++){
		cin >> a[i];
	}
	for (int j = 1; j <= n; j++){
		if (a[j] == 1){
			for (int k = 1; k <= n+1; k++){
				if (a[j+k] == 0){
					if (max < k+1){
						max = k+1;
					}
					break;
				}
			}
		}
		
	}
	cout << max << endl;
	return 0;
}


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

int main()
{
  int n,k;
  double p[200005];
  cin>>n>>k;
int flag=1;
double ans=0.0;
p[0]=0;
  for(int i=1;i<=n;i++)
  {
      scanf("%lf",&p[i]);
      p[i]=p[i]*(p[i]+1)/(2*p[i]);
      if(i>1) p[i]+=p[i-1];
  }
 for(int i=1;i<=n-k+1;i++){
 ans=max(ans,p[i+k-1]-p[i-1]);
 }
 printf("%.12f",ans);
    return 0;
}


Measured memory_bytes: 1792
import sys
input = sys.stdin.readline

wea = list(input())
if wea[0] == "R":
  if wea[1] == "R":
    if wea[2] == "R":
      print(3)
    elif wea[2] == "S":
      print(2)
  elif wea[1] == "S":
    print(1)
elif wea[0] == "S":
  if wea[1] == "R":
    if wea[2] == "R":
      print(2)
    elif wea[2] == "S":
      print(1)
  elif wea[1] == "S":
    if wea[2] == "R":
      print(1)
    elif wea[2] == "S":
      print(0)

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

using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

constexpr int I_INF = numeric_limits<int>::max();
constexpr ll L_INF = numeric_limits<ll>::max();

//==================================

template <typename _Ty>
class UnionFind {
private:
    vector<_Ty> par;
    vector<_Ty> sz;

public:
    UnionFind(_Ty N) : par(N), sz(N, 1) {
        for (_Ty i = 0; i < N; ++i) par[i] = i;
    }
    _Ty root(_Ty x) {
        return par[x] == x ? x : par[x] = root(par[x]);
    }
    bool same(_Ty x, _Ty y) {
        return root(x) == root(y);
    }
    void unite(_Ty x, _Ty y) {
        x = root(x);
        y = root(y);
        if (x == y) return;
        if (sz[x] < sz[y]) swap(x, y);
        par[y] = x;
        sz[x] += sz[y];
    }
    _Ty size(_Ty x) {
        return sz[root(x)];
    }
};

int N, M;
using Graph = vector<Vi>;
Graph g;

int main() {
#ifdef FASTIO
    cin.tie(0), cout.tie(0);
    ios::sync_with_stdio(false);
#endif
#ifdef FILEINPUT
    ifstream ifs("./in_out/input.txt");
    cin.rdbuf(ifs.rdbuf());
#endif

    cin >> N >> M;
    g.resize(N);
    vector<Pii> edges(M);
    for (int i = 0; i < M; i++) {
        int a, b;
        cin >> a >> b;
        --a, --b;
        edges[i] = make_pair(a, b);
        g[a].emplace_back(b);
        g[b].emplace_back(a);
    }

    ll ans = 0;
    for (int i = 0; i < M; i++) {
        int a, b;
        tie(a, b) = edges[i];
        UnionFind<int> uf(N);
        for (int j = 0; j < N; j++) {
            for (const auto& to : g[j]) {
                if ((a == j && b == to) || (b == j && a == to)) continue;
                uf.unite(j, to);
            }
        }
        if (uf.size(0) != N) ++ans;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
from math import sqrt,cos,atan2

class Ufo:
	def __init__(self,px,py,d,vd,ui):
		self.pd=sqrt(px**2+py**2)
		self.px=float(px)
		self.py=float(py)
		self.ex=self.px/self.pd
		self.ey=self.py/self.pd
		self.d=float(d)
		self.vd=float(vd)
		self.vx=-self.vd*self.ex
		self.vy=-self.vd*self.ey
		self.i=ui
	def move(self):
		self.pd -= self.vd
		self.px += self.vx
		self.py += self.vy



while True:
	R,ul=tuple(map(int,raw_input().split()))
	if(R==0 and ul==0): break
	us=[]
	for ui in xrange(ul):
		px,py,d,vd = tuple(map(int,raw_input().split()))
		u = Ufo(px,py,d,vd,ui)
		us.append(u)

	re=0
	while True:
		for u in us: u.move()
		us.sort(key=lambda u: u.pd)

		for u in us[:]:
			if u.pd<=R:
				re+=1
				us.remove(u)
				#print u.i, "due to invade"
				continue
			else:
				break
		if len(us)==0: break

		neu=us.pop(0)
		#print "focus",neu.i
		#print neu.i,"due to hit"

		for u in us[:]:
			d = u.pd*abs(neu.ex*u.ey-neu.ey*u.ex)	#u kara laser ni orosita suisen no nagasa
			if d<u.d:
				#if u.pd*cos(atan2(u.ey,u.ex)-atan2(neu.ey,neu.ex)) + sqrt(u.d**2-d**2) > R:
				if u.pd*(neu.ex*u.ex+neu.ey*u.ey)+sqrt(u.d**2-d**2) > R: #nazeka kore ja dame
					us.remove(u)
					#print u.i, "due to hit"
		if len(us)==0: break

	print re

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    vector<int> v1, v2;
    int n, m;
    while(cin) {
        cin >> n >> m;
        v1.push_back(n);
        v2.push_back(m);
    }
    
    for(int i=0; i+1<v1.size(); i++) {
        int count = 0;
        int num = v1[i] + v2[i];
        while(num > 0) {
            num /= 10;
            count++;
        }
        cout << count << endl;
    }
    return 0;
}

Measured memory_bytes: 1216
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <set>
#include <map>
#include <unordered_map>
#include <queue>
using namespace std;
#define Fio                           \
    ios_base::sync_with_stdio(false); \
    cin.tie(nullptr);                 \
    cout.tie(nullptr)
#define f(i, n) for (long long int i = 0; i < n; i++)
#define ll long long int
#define fo(i, a, b) for (long long int i = a; i <= b; i++)
#define w(t)  \
    int t;    \
    cin >> t; \
    while (t--)
#define vi vector<int>
#define vl vector<long long int>
#define vvi vector<vector<int>>
#define vvl vector<vector<long long int>>
#define mii map<int, int>
#define umii unordered_map<int, int>
#define newl cout<<"\n"
#define pb push_back
#define mp make_pair
#define fi first
#define se second
const ll inf = 1e9 + 7;
const ll modc = 998244353;
#define MAX 100002

ll maxi(ll a,ll b){
	if(a>=b)return a;
	return b;
}

ll mini(ll a,ll b){
	if(a>=b)return b;
	return a;
}


int main(){
	Fio;
	ll n;
	cin>>n;
	ll H[n+1];
	fo(i,1,n)cin>>H[i];
	ll dp[n+1] = {0};
	dp[2] = abs(H[2]-H[1]);
	fo(i,3,n){
		dp[i] = mini(dp[i-1]+abs(H[i]-H[i-1]),dp[i-2]+abs(H[i]-H[i-2]));
	}
	cout<<dp[n];

	return 0;
}

Measured memory_bytes: 5212
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
using namespace std;
int main() {
    int N; cin >> N;
    int f = 1.0;
    while(true) {
        double M = sqrt(N), x = 0.0, y = 0.0;
        x = modf(M, &y);
        if (x == 0) {
            printf("%d\n", N);
            return 0;
        }
        else N--;
    }
}


Measured memory_bytes: 3704
#include <stdio.h>
int main(void) {
    int c;
 
    while (1) {
        c = getchar();
        if (c == EOF)
            break;
        if ('A' <= c && c <= 'Z')
            putchar(c + 0x20);
        else if ('a' <= c && c <= 'z')
            putchar(c - 0x20);
        else
            putchar(c);
    }
    return 0;
}


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

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,sum=0,i,min,max;
    cin>>n;
    ll a[n-1];
    for(i=0;i<n-1;i++){
        
        cin>>a[i];
    }
    for(i=0;i<n-2;i++)
    {
        if(a[i]>a[i+1]){
            sum+=a[i+1];
        }
        else
        sum+=a[i];
    }
    sum+=a[0]+a[n-2];
    cout<<sum;
  return 0;
    
}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
 
int door[20][20],sw[20][20],light[20],check[40000][20],prev[40000][20][2],q[500000][4];
int N,M,SET,GOAL,FR,TO,EXIT;
char stp[500000][40];

/*
Code - RoomNo --Steps --Prev
*/

int mark(int code,int now,int from){
	if(check[code][now]!=SET){
		check[code][now]=SET;
		prev[code][now][0]=q[FR][0];
		prev[code][now][1]=q[FR][1];
		q[TO][0]=code;
		q[TO][1]=now;
		q[TO][2]=q[FR][2]+1;
		q[TO][3]=from;
		TO++;
		if(now==N){
			EXIT=1;
			if(code==GOAL)return 1;
		}
	}
	return 0;
}

int search(int code,int now,int from){
	int i;

	for(i=0;i<N;i++){
		if( (code>>i & 1) && (door[now][i+1]==SET) ){
			if(mark(code,i+1,0))return 1;
		}
	}

	for(i=from-1;i<N;i++){
		if(now!=(i+1) && (sw[now][i+1])==SET ){
			if(mark(code^(1<<i),now,i+2))return 1;
		}
	}

	return 0;
}

void write(int code,int now,int pcode,int pre){
	if(now != pre){
		sprintf(stp[TO],"Move to room %d.\n",now);
	}
	else{
		int i;
		for(i=N-1;i>=0;i--){
			if( (code>>i) != (pcode>>i) ){
				sprintf(stp[TO],"Switch %s room %d.\n",(code>>i&1)?"on":"off",i+1);
				return;
			}
		}
	}
}
 
int main(){
    int i,j,k,x,y,code;
 
    while(scanf("%d %d",&N,&M)*(N+M)){
		SET++;

		GOAL=1<<N-1;

		for(i=0;i<M;i++){
			scanf("%d %d",&x,&y);
			door[x][y]=SET;
			door[y][x]=SET;
		}

		for(i=1;i<=N;i++){
			scanf("%d",&light[i]);
		}

		for(i=1;i<=N;i++){
			for(scanf("%d",&k);k>0;k--){
				scanf("%d",&x);
				sw[i][x]=SET;
				//if(i==x)fprintf(stderr,"??\n");
			}
		}

		code=0;
		
		for(i=N;i>0;i--){
			code=code*2+light[i];
		}

		q[0][0]=code;q[0][1]=1;q[0][2]=0;q[0][3]=1;
		FR=0;TO=1;EXIT=0;

		while(FR<TO){
			if(search(q[FR][0],q[FR][1],q[FR][3])){EXIT=2;break;}
			FR++;
		}

		if(EXIT==2){
			printf("You can go home in %d steps.\n",q[TO-1][2]);
			code=q[TO-1][0];x=q[TO-1][1];FR=q[TO-1][2];
			for(TO=FR-1;TO>=0;TO--){
				y=prev[code][x][1];
				i=prev[code][x][0];
				write(code,x,i,y);
				x=y;code=i;
			}
			for(TO=0;TO<FR;TO++){
				printf("%s",stp[TO]);
				//fprintf(stderr,"%s",stp[TO]);
			}

		}
		else if(EXIT==1)printf("You can not switch off all lights.\n");
		else printf("Help me!\n");
    }
  
    return 0;
}

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



int main(){
  int a,b,c,x;
  cin >> a >> b >> c >> x;
  int res = 0;
  for(int i=0;i<=a;i++){
    for(int j=0;j<=b;j++){
      for(int k=0;k<=c;k++){
        int total = 500*i + 100*j + 50*k;
        if(total==x) res++;
      }
    }
  }
  cout << res << endl;
}


Measured memory_bytes: 256
n,m = gets.chomp.split(' ').map(&:to_i)
arr = gets.chomp.split(' ').map(&:to_i)
ans = Array.new(n,1)
m.times do
  a,b = gets.chomp.split(' ').map(&:to_i)
  if arr[a-1] < arr[b-1]
    ans[a-1] = 0
  elsif arr[b-1] < arr[a-1]
    ans[b-1] = 0
  else
    ans[a-1] = 0
    ans[b-1] = 0
  end
end
puts ans.sum

Measured memory_bytes: 23412
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();
bool check(int a, int b, int c) {
    return a == b && b == c;
}
bool consist(vector<vector<int>>& A) {
    if (!check(A[0][1]-A[0][0], A[1][1]-A[1][0], A[2][1]-A[2][0]))
        return false;
    if (!check(A[0][2]-A[0][1], A[1][2]-A[1][1], A[2][2]-A[2][1]))
        return false;
    if (!check(A[1][0]-A[0][0], A[1][1]-A[0][1], A[1][2]-A[0][2]))
        return false;
    if (!check(A[2][0]-A[1][0], A[2][1]-A[1][1], A[2][2]-A[1][2]))
        return false;
    return true;
}
int main() {
    vector<vector<int>> A(3, vector<int>(3, 0));
    for(int i = 0; i < 3; i++) {
        for(int j = 0; j < 3; j++) {
            cin >> A[i][j];
        }
    }
    if (consist(A) == true)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;

    return 0;
}




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

class Dice {
public:
    static int rollingface[][4];
    static int sideface[][4];
    int face[6];

    Dice(string &face_data);
    // ~Dice();
    void roll(const char &op);
    int top();
    int front_face(int top, int right);
    void print_faces();
    bool operator==(const Dice& other);
};

int Dice::rollingface[][4] = {
    {0, 2, 5, 3},
    {0, 4, 5, 1},
    {0, 1, 5, 4},
    {0, 3, 5, 2},
};

int Dice::sideface[][4] = {
    {1, 3, 4, 2},
    {0, 2, 5, 3},
    {0, 4, 5, 1},
    {0, 1, 5, 4},
    {0, 3, 5, 2},
    {1, 2, 4, 3},
};

Dice::Dice(string &face_data) {
    istringstream strm;
    strm.str(face_data);
    for (int i = 0; i < 6; i++) {
        strm >> face[i];
    }
}

void Dice::roll(const char &op) {
    int *fseq;
    switch (op) {
        case 'E': fseq = Dice::rollingface[0]; break;
        case 'N': fseq = Dice::rollingface[1]; break;
        case 'S': fseq = Dice::rollingface[2]; break;
        case 'W': fseq = Dice::rollingface[3]; break;
        default: break;
    }
    int t, p = face[fseq[3]];
    for (int i = 0; i < 4; i++) {
        t = face[fseq[i]];
        face[fseq[i]] = p;
        p = t;
    }
}

int Dice::front_face(int top, int right) {
    int i;
    for (i = 0; i < 6; i++) {
        if (face[i] == top) break;
    }
    int *fseq = Dice::sideface[i];
    for (i = 0; i < 4; i++) {
        if (face[fseq[i]] == right) return face[fseq[(i-1+4)%4]];
    }
    return -1;
}

void Dice::print_faces() {
    cout << "face:" << endl;
    cout << "   " << face[4] << endl;
    cout << face[3] << " " << face[0] << " " << face[2] << endl;
    cout << "   " << face[1] << endl;
    cout << "   " << face[5] << endl;
    cout << endl;
}

bool Dice::operator==(const Dice& other) {
    int i;
    for (i = 0; i < 6; i++) {
        if (other.face[i] == face[0]) {
            if (other.face[5-i] != face[5]) continue;
            int *f = Dice::sideface[0], *of = Dice::sideface[i];
            for (int j = 0; j < 4; j++) {
                if (face[f[0]] == other.face[of[j]]) {
                    for (int k = 1; k < 4; k++) {
                        if (face[f[k]] != other.face[of[(j+k)%4]]) goto NOT_MATCH;
                    }
                    break;
                }
            }
            return true;
            NOT_MATCH:;
        }
    }
    return false;
}

int Dice::top() {
    return face[0];
}

int main() {
    string buf;
    Dice *d1, *d2;

    getline(cin, buf);
    d1 = new Dice(buf);
    getline(cin, buf);
    d2 = new Dice(buf);
    cout << (*d1 == *d2 ? "Yes": "No") << endl;

    return 0;
}

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

struct Card {char suit, value; };

void BubbleSort(struct Card c[], int n){
    Card a;
    for(int i = 0; i < n; i++){
        for(int j = n-1; j > i; j--){
            if(c[j].value < c[j-1].value){
                a = c[j];
                c[j] = c[j-1];
                c[j-1] = a;
            }
        }
    }
}

void SelectionSort(struct Card c[], int n){
    Card a;
    int minj;
    for(int i = 0; i < n; i++){
        minj = i;
        for(int j = i; j < n; j++){
            if(c[j].value < c[minj].value)
                minj = j;
        }
            a = c[i];
            c[i] = c[minj];
            c[minj] = a;
    }
}

int main(void){
    int n, count = 0;
    Card c1[50], c2[50];
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> c1[i].suit >> c1[i].value;
        c2[i] = c1[i];
    }
    BubbleSort(c1, n);
    SelectionSort(c2, n);
    
    for(int i = 0; i < n; i++){
        if(i == n-1)
        cout << c1[i].suit << c1[i].value << endl;
        else
        cout << c1[i].suit << c1[i].value << " ";
    }
    cout << "Stable" << endl;
    
    for(int i = 0; i < n; i++){
        if(i == n-1)
        cout << c2[i].suit << c2[i].value << endl;
        else
        cout << c2[i].suit << c2[i].value << " ";
        if(c1[i].suit != c2[i].suit)  count++;
    }
    if(count > 0)    
        cout << "Not stable" << endl;
    else    cout << "Stable" << endl;
    
    
    return 0;
}


Measured memory_bytes: 3084
#include "bits/stdc++.h"

#define MOD 1000000007
#define rep(i, n) for(ll i=0; i < (n); i++)
#define ALL(v) v.begin(),v.end()
#define DUMP(i, v)for(ll i=0;i<v.size();i++)cout<<v[i]<<" "

using namespace std;
typedef long long int ll;
typedef vector<ll> llvec;
typedef vector<double> dvec;
typedef pair<int, int> P;
struct Edge{ll from, to, cost;};

ll mod(ll a, ll mod){
  ll res = a%mod;
  if(res<0)res=res + mod;
  return res;
}

ll modpow(ll a, ll n, ll mod){
  ll res=1;
  while(n>0){
    if(n&1) res=res*a%mod;
    a=a*a%mod;
    n>>=1;
  }
  return res;
}

ll modinv(ll a, ll mod){
  return modpow(a, mod-2, mod);
}

bool is_prime(ll n){
  ll i = 2;
  if(n==1)return false;
  if(n==2)return true;
  bool res = true;
  while(i*i <n){
    if(n%i==0){
      res = false;
    }
    i = i+1;
  }

  //if(i==1)res = false;
  if(n%i==0)res=false;
  return res;
}


/**************************************
** A main function starts from here  **
***************************************/
int main(){
  ll N;cin>>N;
  llvec A(N, 0);
  rep(i, N)cin >> A[i];
  sort(ALL(A), [](ll a, ll b){return a>b;});
  long double ans = 0;
  rep(i, N){
    ans += 1.00/A[i];
  }
  cout << 1.0/ans;
  
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n)  for(int i = 0; i < n; i++)
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.rbegin(), cont.rend()
#define unique(a)  (a).erase(unique((a).begin(), (a).end()),(a).end())
#define fastio          ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define PB push_back
#define endl "\n"
#define mod 1000000007
typedef long long LL;
typedef long double LD;
typedef vector<int> VI;
inline LL add(LL x, LL y) { x += y; if (x >= mod) x -= mod; return x; }
inline LL moduloMultiplication(LL x, LL y) {
	return (x%mod * 1LL * y%mod) %

		mod;
}
inline LL power(LL a, LL b) {
	LL x = 1 % mod;
	while (b) {
		if (b & 1) x = moduloMultiplication(x, a);
		a = moduloMultiplication(a, a);
		b >>= 1;
	}
	return x % mod;
}

inline LL inv(LL a) { return power(a, mod - 2) % mod; }
LL gcd(LL a, LL b)
{
	if (!a)
		return b % mod;
	return gcd(b%a, a) % mod;
}

LL binomialCoeff(LL n, LL k)
{
	LL res = 1;

	// Since C(n, k) = C(n, n-k)  
	if (k > n - k)
		k = n - k;

	// Calculate value of  
	// [n * (n-1) *---* (n-k+1)] / [k * (k-1) *----* 1]  
	for (LL i = 0; i < k; ++i)
	{
		//res *= (n - i);
		res = moduloMultiplication(res, n - i);
		res %= mod;
		res = moduloMultiplication(res, inv(i + 1));
		res %= mod;
	//	res /= (i + 1);
	}

	return res;
}
int main()
{
	LL n, a, b;
	cin >> n >> a >> b;
	LL f = power(2, n);
	f %= mod;
	f = add(f, -1);
	f %= mod;
	f = add(f, -binomialCoeff(n, a));
	f = (f + mod) % mod;
	f %= mod;
	f = add(f, -binomialCoeff(n, b));
	f %= mod;
	cout << (f+mod)%mod << endl;

	
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, z, n) for(int i = z; i < n; i++)
#define all(v) v.begin(), v.end()
typedef long long ll;
//const int INF = 1<<29;
//const int MODINF = 1000000007;
using namespace std;

int main(){
    string S;
    cin >> S;
    set<char> s;
    rep(i, 0, S.size()){
        if (s.count(S.at(i))){
            cout << "no" << endl;
            return 0;
        }
        else{
            s.insert(S.at(i));
        }
    }
    cout << "yes" << endl;
}

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

robot=[]
for _ in range(N):
    x,l=map(int,input().split())
    robot.append((x+l,x-l))
robot.sort()

tmp=-10**10
ans=0
for i in range(N):
    end,start=robot[i]
    if tmp<=start:
        tmp=end
        ans+=1
print(ans)




Measured memory_bytes: 16988
N, U, V = map(int, input().split())
G = [set() for _ in range(N+1)]
for _ in range(N-1):
    a, b = map(int, input().split())
    G[a].add(b)
    G[b].add(a)

stack = [V]
path = []
vs = set([V])
G2 = [set() for _ in range(N+1)]
depth = [0] * (N+1)
while stack:
    v = stack.pop()
    if v > 0:
        path.append(v)
        if v == U:
            tmp = len(path)//2
#            print(path)
            ss = path[-tmp]
        for u in G[v]:
            if u in vs:
                continue
            depth[u] = depth[v] + 1
            G2[v].add(u)
            vs.add(u)
            stack += [-v, u]
    else:
        path.pop()

stack = [ss]
vs = set([ss])
while stack:
    v = stack.pop()
    for u in G2[v]:
        if u in vs:
            continue
        vs.add(u)
        stack.append(u)
#print(vs, depth)
x = 0
for v in vs:
    x = max(depth[v], x)
print(x-1)


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

int head[100005], tot, n, m, q, v[100005], d[100005], c[100005], ou[100005], maxd[100005];
struct edge {
	int to, nxt;
} G[300005];

inline void add(int u, int v) {
	tot++;
	G[tot].to = v;
	G[tot].nxt = head[u];
	head[u] = tot;
}

void dfs(int un, int ds, int c) {
	if(maxd[un] >= ds) return;
	if(!ou[un]) ou[un] = c;
	if(!ds) return;
	maxd[un] = ds;
	for (int i = head[un]; i; i = G[i].nxt) dfs(G[i].to, ds - 1, c);
}

int main() {
	scanf ("%d %d", &n, &m);
	int u, vd;
	for (int i = 1; i <= m; i++) {
		scanf ("%d %d", &u, &vd);
		add(u, vd); add(vd, u);
	}
	memset (maxd, -1, sizeof (maxd));
	scanf ("%d", &q);
	for (int i = 1; i <= q; i++) scanf ("%d %d %d", &v[i], &d[i], &c[i]);
	for (int i = q; i >= 1; i--) dfs(v[i], d[i], c[i]);
	for (int i = 1; i <= n; i++) printf ("%d\n", ou[i]);
	return 0;
}

Measured memory_bytes: 4864
def getN():
    return int(input())


def getNM():
    return map(int, input().split())


def getList():
    return list(map(int, input().split()))


from collections import defaultdict, deque
from sys import exit
import math
import copy
from bisect import bisect_left, bisect_right
from heapq import *
import sys

# sys.setrecursionlimit(1000000)
INF = 10 ** 17
MOD = 1000000007

from fractions import *


def inverse(f):
    # return Fraction(f.denominator,f.numerator)
    return 1 / f


def combmod(n, k, mod=MOD):
    ret = 1
    for i in range(n - k + 1, n + 1):
        ret *= i
        ret %= mod

    for i in range(1, k + 1):
        ret *= pow(i, mod - 2, mod)
        ret %= mod

    return ret


def bunsu(n):
    ret = []
    for i in range(2, int(math.sqrt(n)) + 1):
        if n % i == 0:
            tmp = 0
            while (True):
                if n % i == 0:
                    tmp += 1
                    n //= i
                else:
                    break
            ret.append((i, tmp))

    ret.append((n, 1))
    return ret

MOD = 998244353
def solve():
    n, k = getList()
    nums = getList()
    dp = [0 for i in range(k+1)]
    dp[0] = 1
    for i, num in enumerate(nums):
        new = [0 for i in range(k+1)]
        for j, d in enumerate(dp):
            new[j] += d * 2
            if (j + num) <= k:
                new[j+num] += d

        dp = [ne%MOD for ne in new]
    print(dp[-1])

def main():
    # n = getN()
    # for _ in range(n):
    solve()


if __name__ == "__main__":
    solve()

Measured memory_bytes: 83204