akhauriyash/Code-Regression huggingface dataset:
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		String S;
		int Q;
		int T;
		int F;
		String J;
		int flag = 0;
		int i;
		Scanner sc = new Scanner(System.in);
		S = sc.next();
		Q = Integer.parseInt(sc.next());
		Deque<String> deque = new ArrayDeque<String>();
		deque.addLast(S);
		for (i = 0; i < Q; i++) {
			T = Integer.parseInt(sc.next());
			if (T == 1) {
				if (flag == 0)
					flag = 1;
				else
					flag = 0;
			} else {
				F = Integer.parseInt(sc.next());
				J = sc.next();
				if (F == 1) {
					if (flag == 0)
						deque.addFirst(J);
					else
						deque.addLast(J);
				} else {
					if (flag == 0)
						deque.addLast(J);
					else
						deque.addFirst(J);
				}
			}
		}
		StringBuilder strBuf = new StringBuilder();
		while (deque.size() > 0) {
			strBuf.append(deque.removeFirst());
		}
		if (flag == 0)
			System.out.println(strBuf);
		else
			System.out.println(strBuf.reverse());
		sc.close();
	}
}

Measured memory_bytes: 100852
N,M = map(int, input().split())
field =[]
field.append(list("."*(M+2)))
for i in range(N):
    t = list("."+input()+".")
    field.append(t)
field.append(list("."*(M+2)))
res = 1
def dfs(x,y):
    r = 0 #周りの”.”の数を数える
    #field[x][y] = "."
    
    for dx in range(-1,2):
        for dy in range(-1,2):
            if abs(dx+dy) ==1: #ここがなかったら周り８マス探す
                nx = x + dx
                ny = y + dy
                if field[nx][ny]==".":
                    r+=1
    if r==4: return 0
    else: return 1
                    
        
                
for i in range(0,N+2):
    for j in range(0,M+2):
        if field[i][j] == "#":
            res = res *dfs(i,j)
            
if res:print("Yes")
else:print("No")

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

LR = [list(map(int,input().split())) for _ in range(M)]

L=0
R=N
for l,r in LR:
    if L<l:
        L=l
    if R>r:
        R=r
    #print(str(L)+str(R))

if R-L+1<0:
    print(0)
else:
    
    print(str(R-L+1))


Measured memory_bytes: 27336
//atcoder clange
#include <stdio.h>

int main(void){
 
    int N,L;
  
  	scanf("%d", &N);
  	scanf("%d", &L);
  
  int num[N];
  int i=0;
  for(i=0;i<N;i++){
   num[i] = L +i; 
  }
  
  int j,k;
  int sum = 0;
    int ans[N];
  for(i=0;i<N;i++){
	sum = sum + num[i];
    ans[i] = 0;
  }
  int ansl = 0;
  int ansm = 0;
  int ans2 = 0;
  if(L >= 0){
		if(L == 0){
    	 printf("%d",sum);
     	 return 0;
    	}else {
          ansl = sum - num[0];
          printf("%d", ansl);
          return 0;
        }
    }else if(L < 0){
    if(N <= abs(L)){
		ansm = sum - num[N-1];
   		printf("%d",ansm);
    	return 0;
    }else if(N > abs(L)){
		printf("%d",sum);
      return 0;
    }
  }
    
 
  
  
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <array>
#include <cassert>
#include <utility>
#include <vector>

constexpr int mod = 1'000'000'007;

int main(void){
    std::cin.tie(nullptr); std::ios_base::sync_with_stdio(false); 
    std::cout << std::fixed << std::setprecision(16);
    int n; std::cin >> n;
    std::vector<std::vector<int>> edge(n);
    for(int i = 1; i < n; ++i){
        int u, v; std::cin >> u >> v; --u; --v;
        edge[u].push_back(v); edge[v].push_back(u);
    }
    std::vector<int> bc(n, -1), wc(n, -1);
    const std::function<std::pair<int, int>(int)> dfs = [&](int v){
        if(bc[v] != -1) return std::pair<int, int>(0, 1);

        bc[v] = 1; wc[v] = 1;
        for(const int nv : edge[v]){
            const auto r = dfs(nv);
            bc[v] = static_cast<long long int>(bc[v]) * r.second % mod;
            wc[v] = static_cast<long long int>(wc[v]) * (r.first + r.second) % mod;
        }
        return std::pair<int, int>(bc[v], wc[v]);
    };
    const auto res = dfs(0);
    std::cout << (res.first + res.second) % mod << '\n';
    return 0;
}

Measured memory_bytes: 14948
//
// Created by yamunaku on 2019/12/29.
//

#include <bits/stdc++.h>

using namespace std;

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repl(i, l, r) for(int i = (l); i < (r); i++)
#define per(i, n) for(int i = ((n)-1); i >= 0; i--)
#define perl(i, l, r) for(int i = ((r)-1); i >= (l); i--)
#define all(x) (x).begin(),(x).end()
#define MOD9 998244353
#define MOD1 1000000007
#define IINF 1000000000
#define LINF 1000000000000000000
#define SP <<" "<<
#define CYES cout<<"Yes"<<endl
#define CNO cout<<"No"<<endl
#define CFS cin.tie(0);ios::sync_with_stdio(false)
#define CST(x) cout<<fixed<<setprecision(x)

using ll = long long;
using ld = long double;
using vi = vector<int>;
using mti = vector<vector<int>>;
using vl = vector<ll>;
using mtl = vector<vector<ll>>;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
template<typename T>
using heap = priority_queue<T, vector<T>, function<bool(const T, const T)>>;

int main(){
    // CFS;
    cout << "square1001" << endl;
    return 0;
}


Measured memory_bytes: 3092
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
#define rep1(i, n) for(int i=1; i<=n; i++)
#define repr(i, n) for(int i=n-1; i>=0; i--)
#define repr1(i, n) for(int i=n; i>=1; i--)
#define all(v) v.begin(),v.end()
using ll = long long;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = 1e9+7;
const double EPS = 1e-10;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main() {
    ll n, k; cin >> n >> k;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];

    vector<ll> an, ap;
    rep(i, n) {
        if (a[i] < 0) an.push_back(a[i]);
        if (a[i] > 0) ap.push_back(a[i]);
    }
    sort(all(an)); sort(all(ap));

    ll nn = an.size();
    ll np = ap.size();
    ll nz = n - nn - np;
    ll neg = nn * np;
    ll pos = nn * (nn - 1) / 2 + np * (np - 1) / 2;
    ll zer = nz * (nz - 1) / 2 + nz * (nn + np);

    if (k <= neg) { // K番目の数は負
        ll l = -2e18, r = -1;
        while (r - l > 1) {
            ll mid = (r + l) / 2;
            ll sum = 0;
            rep(i, (int)ap.size()) {
                sum += upper_bound(all(an), (mid - ap[i] + 1)/ap[i]) - an.begin();
            }
            if (sum >= k) r = mid;
            else l = mid;
        }
        cout << r << endl;
    } else if (k <= neg + zer) {
        cout << 0 << endl;
    } else { // k番目の数は正
        k -= neg + zer;
        rep(i, (int)(an.size())) an[i] = -an[i];
        sort(all(an));

        ll l = -1, r = 2e18;
        while (r - l > 1) {
            ll mid = (r + l) / 2;
            ll sum = 0;
            rep(i, (int)an.size()) {
                ll d = upper_bound(all(an), mid/an[i]) - an.begin();
                if (i < d) d--;
                sum += d;
            }
            rep(i, (int)ap.size()) {
                ll d = upper_bound(all(ap), mid/ap[i]) - ap.begin();
                if (i < d) d--;
                sum += d;
            }
            sum /= 2;
            if (sum >= k) r = mid;
            else l = mid;
        }
        cout << r << endl;
    }
}


Measured memory_bytes: 6804
/*
    Ujjawal Pabreja [cuber_coder]
*/
#include <bits/stdc++.h> 
#include <functional> 
using namespace std;
#define speed_cubing    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define ll              long long
#define ld              long double
#define rep(i,a)        for(ll i = 0 ; i < a ; i++)
#define repe(i,a,b)     for(ll i = a ; i < b ; i++)
#define bac(i,a)        for(ll i = a ; i >= 0 ; i--)
#define bace(i,a,b)     for(ll i = a ; i >= b ; i--)
#define pb              push_back
#define in              insert
#define ff              first
#define ss              second
#define setbit(x)       __builtin_popcountll(x)
#define init(c,a)       memset(c,a,sizeof(c))
#define all(c)          c.begin(),c.end()
#define sz(c)           (ll)c.size()
#define lb              lower_bound
#define ub              upper_bound
#define maxe            *max_element
#define mine            *min_element
#define rev             reverse
#define Y				"YES"
#define N 				"NO"
#define endl            "\n"
#define debug(x)        cout << #x << " : " << x << endl;
const ll inf = 1e18;  
const ll mod = 1e9 + 7;
const ll MOD = 998244353;
const ll MAX = 2e5 + 1;

inline ll add(ll a,ll b) {return ((a % mod) + (b % mod)) % mod;}
inline ll sub(ll a,ll b) {return ((a % mod) - (b % mod) + mod) % mod;}
inline ll mul(ll a,ll b) {return ((a % mod) * (b % mod)) % mod;}
ll pwr(ll x,ll n){
    if(n == 0){
        return 1;
    }
    if(n&1){
        return mul(x, pwr(mul(x, x), (n - 1) / 2));
    } else {
        return pwr(mul(x, x), n / 2);
    }
}
ll modInv(ll n){ 
    return pwr(n, mod - 2); 
}
ll gcd(ll a,ll b) {
    if(b == 0) {
        return a;
    }
    return gcd(b, a % b);
}
// ====== Useful functions end ======
 
// ====== Global Variables begin ======

// ====== Global Variables end ======
void speed_solve(){
    ll n;
    cin >> n;
    ll a[n];
    rep(i,n) cin >> a[i];
    ll suf[n];
    bac(i,n - 1){
        suf[i] = (i == n - 1 ? a[i] : add(suf[i + 1], a[i]));
    }
    ll ans = 0;
    rep(i,n - 1){
        ll cur = mul(a[i], suf[i + 1]);
        ans = add(ans, cur);
    }
    cout << ans;
}

int main(){
    // #ifndef ONLINE_JUDGE
    //     freopen("input.txt", "r", stdin);
    //     freopen("output.txt", "w", stdout);
    // #endif
    speed_cubing;
    ll test_cases = 1;
    // cin >> test_cases;
    rep(i,test_cases){
        // cout << "Case #" << i + 1 << ": ";
        speed_solve();
    }
    return 0;
}

Measured memory_bytes: 6764
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int a = sc.nextInt();
		int b = sc.nextInt();
		if (a <= 8 && b <= 8) {
			System.out.println("Yay!");
		}else{
			System.out.println(":(");
		}
	}

}

Measured memory_bytes: 20948
#include<iostream>
#include<vector>
#include<functional>
#include<algorithm>
#include<cmath>


using namespace std;
int main()
{
	int n;
	cin>>n;
	int* dp=new int [n];
	int k;
	cin>>k;
	vector<int> cost;
	int t;
	for(int i=0;i<n;i++)
	{
		cin>>t;
		cost.push_back(t);
	}
	dp[0]=0;
	for(int i=1;i<n;i++)
	{
		for(int j=1;j<=k&&i-j>=0;j++)
		{
			if(j==1)
				dp[i]=dp[i-j]+abs(cost[i]-cost[i-j]);
			dp[i]=min(dp[i],dp[i-j]+abs(cost[i]-cost[i-j]));
		}
	}
	cout<<dp[n-1]<<endl;
	return 0;
}

Measured memory_bytes: 1144
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <map>
#define eps 0.0000000001
#define maxn 2000009
#define DEUG 1
#include<stack>
#define inf 0x3f3f3f3f
#define mod 1000000007
#define ll long long
using namespace std;
int d[maxn],n,m;

int main()
{
    //freopen("d:\\in.txt","r",stdin);
    scanf("%d%d",&n,&m);
    for(int i=1;i<=m;i++)
    {
        int a,b;
        scanf("%d%d",&a,&b);
        d[a]++;
        d[b]++;
    }
    bool f=false;
    for(int i=1;i<=n;i++)
        if(d[i]%2)
            f=true;
    if(f)
        printf("NO\n");
    else
        printf("YES\n");
    return 0;
}


Measured memory_bytes: 640
inputST = input()
STlist = inputST.split(" ")
s = STlist[0]
t = STlist[1]

inputAB = input()
ABlist = inputAB.split(" ")
a = int(ABlist[0])
b = int(ABlist[1])

u = input()

if u == s:
    print(a-1, b)
elif u == t:
    print(a, b-1)

Measured memory_bytes: 3064
using System.Linq;
using static System.Console;

namespace AOJ
{
    public class BubbleSort
    {
        public static void Main(string[] args)
        {
            int N = int.Parse(ReadLine());
            int[] A = ReadLine().Split().Select(int.Parse).ToArray();

            int cnt = DoBubbleSort(A, N);
            Write("\n");
            WriteLine(cnt);
        }

        public static int DoBubbleSort(int[] A, int N)
        {
            int cnt = 0;
            bool flag = true;
            while (flag)
            {
                flag = false;
                for (int j = N - 1; j > 0 ; j--)
                {
                    if (A[j - 1] > A[j])
                    {
                        int tmp = A[j];
                        A[j] = A[j - 1];
                        A[j - 1] = tmp;
                        flag = true;
                        cnt++;
                    }
                }
            }

            for (int i = 0; i < N; i++)
            {
               Write(A[i]);
               if (N != 1 && i != (N - 1))
               {
                   Write(" ");
               }
            }
            return cnt;
        }
    }
    
}


Measured memory_bytes: 18300
# include <deque>
# include <stdio.h>
# include <string.h>
# include <iostream>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

const int M = 1e6 + 10;
const int mod = 1e9 + 7;

int n;

deque < pair <int, int> > que;
bool vis[M];

int main() {
  cin >> n;
  que.push_back( make_pair(1, 1) );
  while(!que.empty()) {
    pair <int, int> top = que.front();
    que.pop_front();
    if(vis[top.first]) continue;
    if(top.first == 0) {
      cout << top.second << endl;
      return 0;
    }
    vis[top.first] = 1;
    que.push_back( make_pair((top.first + 1) % n, top.second + 1) );
    que.push_front( make_pair((top.first * 10) % n, top.second)); 
  }
  return 0;
}




Measured memory_bytes: 1152
def examA():
    S = {0:"pon",1:"pon",2:"hon",3:"bon",4:"hon",5:"hon",6:"pon",7:"hon",8:"pon",9:"hon"}
    N = SI()
    ans = S[int(N[-1])]
    print(ans)
    return

def examB():
    K = I()
    S = SI()
    N = len(S)
    if N<=K:
        ans = S
    else:
        ans = S[:K]+"..."
    print(ans)
    return

def examC():
    A, B, H, M = LI()
    a = abs(H*30 - M*5.5)
    deg = min(360-a,a)*math.pi/180
    #print(deg)
    ans = (A**2 + B**2 - 2*A*B*math.cos(deg))**(0.5)
    print(ans)
    return

def examD():

    N, M = LI()
    V = [[]for _ in range(N)]
    for _ in range(M):
        a, b = LI()
        a -= 1; b -= 1
        V[a].append(b)
        V[b].append(a)

    ans = [-1]*N

    def bfs(n, e, fordfs):
        # 点の数、スタートの点、有向グラフ
        W = [-1] * n
        # 各点の状態量、最短距離とか,見たかどうかとか
        W[e] = 0
        que = deque()
        que.append(e)
        while que:
            now = que.popleft()
            nowW = W[now]
            for ne in fordfs[now]:
                if W[ne] == -1:
                    W[ne] = now
                    que.append(ne)
        return W
    ans = bfs(N,0,V)
    for a in ans:
        if a==-1:
            print("No")
            return
    print("Yes")
    for v in ans[1:]:
        print(v+1)
    return

def examE():
    ans = 0
    print(ans)
    return

def examF():
    ans = 0
    print(ans)
    return

import sys,bisect,itertools,heapq,math,random
from copy import deepcopy
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
def I(): return int(input())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet,_ep
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
_ep = 10**(-12)
alphabet = [chr(ord('a') + i) for i in range(26)]

sys.setrecursionlimit(10**7)

if __name__ == '__main__':
    examD()

"""
142
12 9 1445 0 1
asd dfg hj o o
aidn
"""

Measured memory_bytes: 103456
#include<bits/stdc++.h>
using namespace std;
int main(){
  	int X;
	cin >> X;
	if(X == 3 || X==5 || X==7){
    	cout << "YES" <<endl;
    }
  	else{
    	cout << "NO" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
using namespace std;
int main(){
    int N, K;
    cin >> N >> K;
    vector<long long> V(N);
    for(int i = 0; i < N; i++) cin >> V[i];
    long long ans = 0;
    if(N <= K){
        for(int i = 0; i < N; i++){
            if(V[i] >= 0) ans += V[i];
        }
        cout << ans << endl;
        return 0;
    }
    for(int x = 0; x <= K; x++){
    for(int i = 0; i <= x; i++){
        int s = i, t = x - i;
        for(int j = 0; j <= s; j++){
            priority_queue<int, vector<int>, greater<int>> q;
            long long res = 0;
            for(int k = 0; k < s - j; k++){
                q.push(V[k]);
            }
            for(int k = 0; k < j && !q.empty(); k++) q.pop();
            int si = q.size();
            for(int l = 0; l < si; l++){
                res += q.top();
                q.pop();
            }
            for(int k = 0; k <= t; k++){
                priority_queue<int, vector<int>, greater<int>> q1;
                long long res2 = res;
                for(int l = 0; l < t - k; l++){
                    q1.push(V[N - 1 - l]);
                }
                for(int l = 0; l < k && !q1.empty(); l++) q1.pop();
                int sie = q1.size();
                for(int l = 0; l < sie; l++){
                    res2 += q1.top();
                    q1.pop();
                }
                ans = max(ans, res2);
            }
        }
    }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
  let mut b = String::new();
  std::io::stdin().read_line(&mut b).ok();
  b.split_whitespace()
    .map(|x| x.parse().ok().unwrap())
    .collect()
}

fn main() {
  let v: Vec<usize> = read_vec();
  let (n, m) = (v[0], v[1]);

  let mut stairs: Vec<usize> = vec![1; n + 1];
  for _ in 0..m {
    let i: usize = read_vec()[0];
    stairs[i] = 0;
  }

  for i in 2..n + 1 {
    stairs[i] = stairs[i] * (stairs[i - 2] + stairs[i - 1]) % 1_000_000_007;
  }
  println!("{}", stairs[n]);
}


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

using namespace std;
typedef long long int ll;
typedef pair<int, int> ii;
#define DEBUG freopen("in.txt", "r", stdin);

struct fastio {
    fastio() {
        ios::sync_with_stdio(false);
        cout << setprecision(10) << fixed;
        cin.tie(0);
    }
};

fastio _fast_io;

const int N = 1e5 + 5;
int n, m, k, ans;

int a, b, c, d;
int main() {
    cin >> a >> b >> c >> d;
    if (abs(a - c) <= d || (abs(a - b) <= d && abs(b - c) <= d)) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 3648
#include <iostream>

int main(void){
	int k, a, b, m = 0;
	std::cin >> k;
	std::cin >> a >> b;
	
	m = b / k * k;
	
	if(a <= m){	
		puts("OK");
		return 0;
	}
	puts("NG");
	return 0;
}


Measured memory_bytes: 3616
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

typedef struct _Node {
  int key;
  struct _Node *next, *prev;
} Node;

Node *nil;

Node* listSearch(int key) {
  Node *cur = nil->next;
  while(cur != nil && cur->key != key) {
    cur = cur->next;
  }
  return cur;
}

void init(void) {
  nil = (Node *)malloc(sizeof(Node));
  nil->next = nil;
  nil->prev = nil;
}

void printList(void) {
  Node *cur = nil->next;
  int isf = 0;
  while(1) {
    if(cur == nil) break;
    if(isf++>0) printf(" ");
    printf("%d",cur->key);
    cur = cur->next;
  }
  printf("\n");
}

void deleteNode(Node *t) {
  if(t==nil) return;
  t->prev->next = t->next;
  t->next->prev = t->prev;
  free(t);
}

void deleteFirst(void) {
  deleteNode(nil->next);
}

void deleteLast(void) {
  deleteNode(nil->prev);
}

void deleteKey(int key) {
  deleteNode(listSearch(key));
}

void insert(int key) {
  Node *x = (Node *)malloc(sizeof(Node));
  x->key = key;
  x->next = nil->next;
  nil->next->prev = x;
  nil->next = x;
  x->prev = nil;
}

int main(void) {
  int key, n, i;
  int size = 0;
  int np = 0, nd = 0;
  char com[20];
  scanf("%d", &n);
  init();
  for(i=0;i<n;i++) {
    scanf("%s%d",com, &key);
    if (com[0] == 'i') {
      insert(key);
      np++;
      size++;
    } else if(com[0] == 'd') {
      if(strlen(com) > 6) {
        if(com[6] == 'F')
          deleteFirst();
        else if(com[6] == 'L')
          deleteLast();
      } else {
        deleteKey(key);
        nd++;
      }
      size--;
    }
  }
  printList();
  return 0;
}


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

stack<int> sta;
int main(){
    char s[100];
    int a,b;

    while(scanf("%s",s)!=EOF){
        if(s[0]=='+'){
            a = sta.top();
            sta.pop();
            b = sta.top();
            sta.pop();
            sta.push(a+b);
        }else if(s[0]=='-'){
            a = sta.top();
            sta.pop();
            b = sta.top();
            sta.pop();
            sta.push(b-a);
        }else if(s[0]=='*'){
            a = sta.top();
            sta.pop();
            b = sta.top();
            sta.pop();
            sta.push(a*b);
        }else{
            a = atoi(s);
            sta.push(a);
        }
    }
    
    cout << sta.top() << endl;
}


Measured memory_bytes: 3240
#include<bits/stdc++.h>
using namespace std;
const long long mod=1e9+7;
long long mod_pow(long long a,long long n)
{
    if(n==0)
        return 1;
    long long p=mod_pow(a,n/2);
    long long a1=(p*p)%mod;
    if(n%2)
        return a*a1;
    else return a1;
}

int main()
{
    double a,b;
    cin>>a>>b;
    long long c=ceil((b-1)/(a-1));
    cout<<c;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n, m;
  cin >> n >> m;
  int L = 1;
  int R = n;
  for (int i = 0; i < m; i++){
    int l, r;
    cin >> l >> r;
    if (L < l)
      L = l;
    if (R > r)
      R = r;
  }
  if (R < L)
    cout << 0 << endl;
  else
    cout << R-L+1 << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long mod = 1e9 + 7;
vector<long long>fact(2e6 + 20);
long long bigmod(long long a, long long p){
    if(p == 0){
        return 1;
    }
    long long ans = bigmod(a, p/2);
    ans = (ans * ans) % mod;
    if(p % 2 == 1){
        ans = (ans * a) % mod;
    }
    return ans;
}
long long nCr(long long n, long long m){
    long long cur = (fact[m] * fact[n - m]) % mod;
    cur = bigmod(cur, mod - 2);
    cur = (cur * fact[n]) % mod;
    return cur;
}
int main(){
    fact[0] = 1;
    for(long long i = 1; i <= 2000000; i++){
        fact[i] = (fact[i - 1] * i) % mod;
    }
    long long k;
    string s;
    cin >> k >> s;
    long long n = s.size();
    long long ans = bigmod(26, n + k);
    long long cur = 0;
    for(int i = 0; i < n; i++){
        long long cur2 = (nCr(n + k, i) * bigmod(25, n + k - i)) % mod;
        cur = (cur + cur2) % mod;
    }
    cout << (ans - cur + 2 * mod) % mod;
    return 0;
}

Measured memory_bytes: 20944
n = int(input())
s = sorted([input() for i in range(n)])
s_ = sorted(list(set(s)))
if len(s_) != n:
    s.append(0)
    co = [1] + [0 for i in range(len(s_)-1)]
    ind = 0
    for i in range(1, n):
        if s[i-1] == s[i]:
            co[ind] += 1
        else:
            ind += 1
            co[ind] += 1
    ma = max(co)
    arg = [i for i in range(len(s_)) if co[i]==ma]
    ans = [s_[i] for i in arg]
    print("\n".join(sorted(ans)))
    
else:
    print("\n".join(s))

Measured memory_bytes: 29608
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int H,W;
  cin >> H >> W;
  
  for(int i = 0; i<W+2; i++){
    cout << "#";
  }
  cout << endl;
  
  for(int j = 0; j < H; j++){
  	vector<char> date(W);
    
  	for(int i = 0; i < W+2; i++){
      if(i == 0 || i == W+1){
        cout << "#";
      }
      else{
        cin >> date.at(i-1);
        cout << date.at(i-1);
      }
    }
    cout << endl;
    
  }
  
   for(int i = 0; i<W+2; i++){
    cout << "#";
  }
  cout << endl;
  
}

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

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

vector<int> divisor(int n){
    vector<int>ret;
    for(int i=2;i*i<=n;i++){
        if(n%i==0){
            ret.push_back(i);
            if(i*i!=n){ret.push_back(n/i);}
        }
    }
    return ret;
}

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n,ans=0;
    cin>>n;
    map<int,int>fac_1 = pf(n-1);
    int c_1 = 1;
    for(auto i:fac_1){
        c_1*=(i.second+1);
    }
    c_1--;
    ans+=c_1;
    ans++;//Nのぶん
    vector<int>div = divisor(n);
    for(int i=0;i<(int)div.size();i++){
        if(div[i]*div[i]>n){continue;}
        else if(div[i]*div[i]==n){ans++;}
        else{
            int tmp = n;
            while(tmp%div[i]==0){tmp/=div[i];}
            if(tmp%div[i]==1){ans++;}
            }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 384
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {

    private static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

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

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }

    public static void main(final String[] args) throws IOException {
        FastReader in = new FastReader();
        PrintWriter out = new PrintWriter(System.out, true);

        String s = in.nextLine();
        String t = in.nextLine();

        int correct = 0;
        for (int i = 0; i < 3; i++) {
            if (s.charAt(i) == t.charAt(i)) {
                correct++;
            }
        }
        out.println(correct);
    }
}


Measured memory_bytes: 22996
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define all(x) x.begin(),x.end()
#define cmin(a,b) (a>b?a=b:a)
#define cmax(a,b) (a<b?a=b:a)
#define mem(a,k) memset(a,k,sizeof(a))
#define lop(i,s,t) for(int i=s;i<(t);++i)
#define rep(i,s,t) for(int i=s;i<=(t);++i)
#define dec(i,s,t) for(int i=s;i>=(t);--i)
#define fore(i,v) for(int i=g[v],d=es[i].d;i;i=es[i].nxt,d=es[i].d)
using namespace std;

#define Pr(f,...) //fprintf(stderr,f,##__VA_ARGS__),fflush(stderr)

typedef long long ll;

template<typename T>
void read(T &x){
	x=0; 
	char c;
	for(c=getchar();!isdigit(c);c=getchar()); 
	for(;isdigit(c);c=getchar())x=x*10+c-'0'; 
}

const int N=2e5+50,P = 998244353;


int mul(int a,int b){ return 1ll*a*b%P; }
int add(int a,int b){ a+=b; return a>=P?a-P:a; }
int sub(int a,int b){ a-=b; return a<0?a+P:a; }
int gcd(int a,int b){ return !b?a:gcd(b,a%b); }
void upd(int &a,int b){ a=add(a,b); }
int powMod(int x, int k) {
	int res = 1;
	for (;k;k >>= 1, x = mul(x, x)) if (k & 1) res = mul(res, x); 
	return res;
}
int inv(int x) { return powMod(x, P - 2); } 
int frac(int a,int b){ return mul(a, inv(b)); }

int ans,n,z,fac[N];
char s[N],ss[N]; 
vector<int> R,G,B;
int main(int argc,char *argv[]){
#ifdef CURIOUSCAT
	freopen("d.in", "r", stdin); 
#endif
	read(n),z=3*n; 
	
	fac[0]=1;rep(i,1,n)fac[i]=mul(fac[i-1],i);
	scanf("%s",s+1);
	rep(i,1,z){
		if(s[i]=='R')R.pb(i);
		if(s[i]=='G')G.pb(i);
		if(s[i]=='B')B.pb(i);
	}
	sort(all(R)),sort(all(G)),sort(all(B));
	lop(i,0,n){
		int a[3];a[0]=R[i],a[1]=G[i],a[2]=B[i];
		sort(a,a+3);
		ss[a[0]]='L';
		ss[a[1]]='M';
		ss[a[2]]='R';
	}
	int cl=0,clm=0,ans=1;
//printf("ss=%s\n",ss+1);
	rep(i,1,n*3){
		char c=ss[i];
		
		Pr("c=%c\n",c);
		Pr("fk\n");
		if(c=='L')++cl;
		if(c=='M'){
			ans=mul(ans,cl);
			Pr("ans=%d\n",ans);
			--cl,++clm;
		}
		if(c=='R'){
			ans=mul(ans,clm);
			Pr("ans=%d\n",ans);
			--clm;
		}
	}
	printf("%d\n", mul(ans,fac[n]));
	return 0;
}

Measured memory_bytes: 2424
def ToSet(S):
    set_S = set()
    for s in S:
        set_S.add(s)
    return set_S

def main():
    n = int(input())
    s = input()

    m = 0
    for i in range(1, n):
        set1 = ToSet(s[0:i])
        set2 = ToSet(s[i:])
        l = len(set1 & set2)
        if m < l: 
            m = l
    print(m)

if __name__ == "__main__":
    main()

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

ll n,m,r;
ll memo[8];
ll dist[222][222];

int main(){
    cin >> n >> m >> r;
    for(ll i=0;i<r;i++) cin >> memo[i];
    sort(memo,memo+r);
    for(ll i=1;i<=n;i++){
        for(ll j=1;j<=n;j++){
            if(i!=j) dist[i][j]=1e9;
        }
    }
    for(ll i=0;i<m;i++){
        ll a,b,c;
        cin >> a >> b >> c;
        dist[a][b]=c;
        dist[b][a]=c;
    }
    for(ll i=1;i<=n;i++){
        for(ll j=1;j<=n;j++){
            for(ll k=1;k<=n;k++){
                dist[j][k]=min(dist[j][k],dist[j][i]+dist[i][k]);
            }
        }
    }
    ll res=1e9;
    do{
        ll count=0;
        for(ll i=0;i<r-1;i++){
            count+=dist[memo[i]][memo[i+1]];
        }
        res=min(res,count);
    } while(next_permutation(memo,memo+r));
    cout << res << endl;
}  


Measured memory_bytes: 3904
nk = list(map(int, input().split()))
n = nk[0]
k = nk[1]

if k > (n - 1) * (n - 2) // 2:
    print(-1)
else:
    number = n - 1 + (n - 1) * (n - 2) // 2 - k
    print(number)
    for i in range(n - 1):
        print(1, i + 2)
    u = 2
    v = 2
    for i in range(number - (n - 1)):
        if v == n:
            u = u + 1
            v = u + 1
        else:
            v = v + 1
        print(u, v)

Measured memory_bytes: 3608
#include <bits/stdc++.h>
#define rep(i,n) for (int i =0; i< (n);i++);
#define pie 3.141592653589793
using namespace std;
typedef long long ll;
int main() {
  int r;
  cin >> r;
  int awnser = r*r;
  cout << awnser << endl;
			}	
  

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<set>
#include<cstdio>
#define MAXA 100000
#define MAX 20000000000
#define s(i) scanf("%d", &(i))
#define p(i) printf("%d", (i))
#define ps() printf(" ")
#define rer(i,j,k) for((i)=(j);(i)<(k);++(i))
#define ret(i,j,k) for((i)=(j);(i)>(k);--(i))
using namespace std;
struct{
	string str;
	int Count = 0;
}M[101],N[101];
int main(){
	int i, j, n, m;
	cin >> n;
	rer(i,0,n){
		cin >> N[i].str;
	}
	rer(i,0,n){
		rer(j,0,n){
			if(N[i].str==N[j].str){
				N[i].Count++;
			} 
		}
	}
	cin >> m;
	rer(i,0,m){
		cin >> M[i].str;
	}
	rer(i,0,m){
		rer(j,0,m){
			if(M[i].str==M[j].str){
				M[i].Count++;
			} 
		}
	}
	rer(i,0,n){
		rer(j,0,m){
			if(N[i].str==M[j].str){
				N[i].Count -= M[j].Count;
				break;
			}
		}
	}
	int max = 0;
	rer(i,0,n){
		if(N[i].Count > max){
			max = N[i].Count;
		}
	}
	cout << max << endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<deque>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#include<functional>
#include<unordered_set>
#include<iomanip>
#include<cassert>
#include<regex>
#include<bitset>
#include<complex>
#include<chrono>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(),x.end()
using ll=long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;

ll gcd(ll n, ll m) {
	ll tmp;
	while (m!=0) {
		tmp = n % m;
		n = m;
		m = tmp;
	}
	return n;
}

ll lcm(ll n, ll m) {
	return abs(n * m) / gcd(n, m);//gl=xy
}
 
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
 
using namespace std;

//ここから


void solve(){
  int n;
  cin>>n;
  vector<int>a(n);
  rep(i,n)cin>>a[i];
  sort(a.rbegin(),a.rend());
  int x=0,y=0;
  rep(i,n){
    if(i%2==0)x+=a[i];
    else y+=a[i];
  }
  cout<<x-y;
}

int main(){
	ios::sync_with_stdio(false);
  cin.tie(0);
	cout<<fixed<<setprecision(15);
  solve();
	return 0;
}


Measured memory_bytes: 256
takahp, takaatk, aokihp, aokiatk = map(int, input().split())

def attack(hp, atk):
  hp -= atk
  if hp <= 0:
    return True

while True:
  if attack(aokihp, takaatk):
    print("Yes")
    break
  else:
    aokihp -= takaatk
  if attack(takahp, aokiatk):
    print("No")
    break
  else:
    takahp -= aokiatk

Measured memory_bytes: 9192
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;

class Program {
    static void Main (string[] args) {
        int N = int.Parse (Console.ReadLine ());

        long[] xdash = new long[N];
        long[] ydash = new long[N];
        long[] x = new long[N];
        long[] y = new long[N];
        long[] xindex = new long[N];
        long[] yindex = new long[N];

        for (int i = 0; i < N; i++) {
            var strtmp = Console.ReadLine ().Split (' ');
            xdash[i] = long.Parse (strtmp[0]);
            ydash[i] = long.Parse (strtmp[1]);
            x[i] = xdash[i] + ydash[i];
            y[i] = xdash[i] - ydash[i];
            xindex[i] = i;
            yindex[i] = i;
        }

        QuickSortS2B (x, xindex);
        QuickSortS2B (y, yindex);

        long xdiff = x[N - 1] - x[0];
        long ydiff = y[N - 1] - y[0];
        long ans = 0;
        if (xdiff > ydiff) {
            long orig_xdash1 = xdash[xindex[N - 1]];
            long orig_xdash2 = xdash[xindex[0]];
            long orig_ydash1 = ydash[xindex[N - 1]];
            long orig_ydash2 = ydash[xindex[0]];
            ans = Math.Abs (orig_xdash1 - orig_xdash2) + Math.Abs (orig_ydash1 - orig_ydash2);
        } else {
            long orig_xdash1 = xdash[yindex[N - 1]];
            long orig_xdash2 = xdash[yindex[0]];
            long orig_ydash1 = ydash[yindex[N - 1]];
            long orig_ydash2 = ydash[yindex[0]];
            ans = Math.Abs (orig_xdash1 - orig_xdash2) + Math.Abs (orig_ydash1 - orig_ydash2);
        }
        Console.WriteLine (ans);
    }

    static void QuickSortS2B (long[] a, long[] index) {
        QuickSortS2B (a, index, 0, a.Length - 1);
    }

    static void QuickSortS2B (long[] a, long[] index, int left, int right) {
        if (left < right) {
            int i = left;
            int j = right;
            long tmp;
            long pivot = med3 (a[i], a[i + (j - i) / 2], a[j]);
            while (true) {
                while (a[i] < pivot) i++;
                while (pivot < a[j]) j--;
                if (i >= j) break;
                tmp = a[i];
                a[i] = a[j];
                a[j] = tmp;
                tmp = index[i];
                index[i] = index[j];
                index[j] = tmp;
                i++;
                j--;
            }
            QuickSortS2B (a, index, left, i - 1);
            QuickSortS2B (a, index, j + 1, right);
        }
    }

    static long med3 (long x, long y, long z) {
        if (x < y) {
            if (y < z) {
                return y;
            } else if (z < x) {
                return x;
            } else {
                return z;
            }
        } else {
            if (z < y) {
                return y;
            } else if (x < z) {
                return x;
            } else {
                return z;
            }
        }
    }
}

//dotnet run --project test

Measured memory_bytes: 49928
#include<stdio.h>



int main()
{
    int a,b;
    int i;
    int flag1=0,flag2=0;
    int q[7]={1,3,5,7,8,10,12};
    int p[4]={4,6,9,11};
    int m[1]={2};
    scanf("%d%d",&a,&b);
    for(i=0;i<7;i++){
    if(q[i]==a)
        flag1=1;
    if(b==q[i])
        flag2=1;
    }
    for(i=0;i<4;i++){
    if(p[i]==a)
        flag1=2;
    if(b==p[i])
        flag2=2;
    }
    for(i=0;i<1;i++){
    if(m[i]==a)
        flag1=3;
    if(b==m[i])
        flag2=3;
    }
    if(flag1==flag2)
        printf("Yes");
    else
        printf("No");
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i <= n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
 
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;

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

    ll n;
    cin >> n;
    vll a(n), b(n);
    REP(i, n){
        cin >> a[i] >> b[i];
    }
    ll res = 0, p = 0, q, r;
    REPR(i, n){
        q = a[i] + p;
        if(q % b[i] == 0) continue;
        r = b[i] * (q / b[i] + 1) - q;
        res += r;
        p += r;
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 1792
#include "bits/stdc++.h"
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define BUGAVOID(x) x
#define rep(...) BUGAVOID(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define sz(c) (int)(c.size())
#define all(c) c.begin(),c.end()
#define mp make_pair
#define write(x) cout<<(x)<<"\n"
using namespace std; typedef long long ll;
typedef vector<int> vi; typedef vector<ll> vll; template<class T, class U>using vp = vector<pair<T, U>>;
template<class T>using vv = vector<vector<T>>; template<class T, class U>using vvp = vv<pair<T, U>>;
template<class T>vv<T> vvec(size_t n, size_t m, T v) { return vv<T>(n, vector<T>(m, v)); }
template<class T>bool chmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
template<class T>bool chmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
constexpr int INF = 1 << 28, MAX = 1e5 + 5, MOD = 1e9 + 7;
constexpr ll LINF = 1ll << 60; constexpr double EPS = 1e-6;
constexpr int dy[4] = { 0,1,0,-1 }, dx[4] = { 1,0,-1,0 };
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); }; }aaaa;

string S;

int main() {
    cin >> S;
    int N = S.size();

    // white start
    int wscnt = 0;
    rep(i, N) {
        if (i % 2 != S[i] - '0') wscnt++;
    }

    // black start
    int bscnt = 0;
    rep(i, N) {
        if (i % 2 == S[i] - '0') bscnt++;
    }

    write(min(wscnt, bscnt));
}

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

int main() {
    int n;
    vector<int> p(200100);

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

    int min = p[0];
    int count = 1;
    for (int i = 1; i < n; i++) {
        if (p[i] <= min) {
            count++;
            min = p[i];
        }
    }
    cout << count << endl;

    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define ALL(v) (v).begin(), (v).end()
using ll = long long;
constexpr int INF = 1e9;
constexpr long long LINF = 1e18;
constexpr long long MOD = 1e9 + 7;

signed main() {
    int n;
    ll k;
    cin >> n >> k;
    ll a[n];
    rep(i, n) {
        cin >> a[i];
    }
    auto isOK = [&](int l) {
        int cnt = 0;
        rep(i, n) {
            cnt += (a[i] - 1) / l;
        }
        return cnt <= k;
    };
    int ng = 0, ok = INF;
    while (abs(ok - ng) > 1){
        int mid = (ok + ng) / 2;
        if (isOK(mid)) {
            ok = mid;
        }else {
            ng = mid;
        }
    }
    cout << ok << endl;
    return 0;
}

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

int main() {
  int n;
  char f[110], s[110];
  scanf("%d", &n);
  while (n--) {
    scanf("%s%s", f, s);
    int fp = strlen(f);
    int sp = strlen(s);
    if (fp > 80 || sp > 80) {
      puts("overflow");
      continue;
    }
    int c = 0, p = 0, ans[90];
    while (fp > 0 || sp > 0) {
      int a = 0, b = 0;
      if (fp > 0) a = f[--fp] - '0';
      if (sp > 0) b = s[--sp] - '0';
      ans[p++] = (a + b + c) % 10;
      c = (a + b + c) / 10;
    }
    if (c) ans[p] = c;
    else --p;
    if (p >= 80) {
      puts("overflow");
      continue;
    }
    for (; p >= 0; --p) {
      printf("%d", ans[p]);
    }
    puts("");
  }
}


Measured memory_bytes: 2576
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;

ll pw[10];
bool can[12][12];
int h, w;
vector<string> s;
bool rec(vector<ll> l, vector<ll> r, int bit, int depth = 0){
	if(bit == 0){
		int b = (1 << w) - 1;
		rep(i, w / 2){
			rep(j, w) if(b >> j & 1) rep(k, j) if(b >> k & 1){
				if(l[j] == r[k] && l[k] == r[j]){
					b -= 1 << j | 1 << k;
					goto NEXT;
				}
			}
			NEXT:;
		}
		if(__builtin_popcount(b) != w % 2) return 0;
		rep(i, w) if(b >> i & 1) if(l[i] != r[i]) return 0;
		return 1;
	}
	
	if(__builtin_popcount(bit) == 1){
		rep(i, h) if(bit >> i & 1){
			rep(k, w){
				l[k] += pw[depth] * (s[i][k] - 'a');
				r[k] += pw[depth] * (s[i][k] - 'a');
			}
			if(rec(l, r, 0)) return 1;
			rep(k, w){
				l[k] -= pw[depth] * (s[i][k] - 'a');
				r[k] -= pw[depth] * (s[i][k] - 'a');
			}
			return 0;
		}
	}
	
	rep(i, h) if(bit >> i & 1){
		for(int j = i + 1; j < h; j++) if(bit >> j & 1) if(can[i][j]){
			rep(k, w){
				l[k] += pw[depth] * (s[i][k] - 'a');
				r[k] += pw[depth] * (s[j][k] - 'a');
			}
			if(rec(l, r, bit ^ 1 << i ^ 1 << j, depth + 1)) return 1;
			rep(k, w){
				l[k] -= pw[depth] * (s[i][k] - 'a');
				r[k] -= pw[depth] * (s[j][k] - 'a');
			}
		}
	}
		return 0;
}
int main(){
	pw[0] = 1; rep(i, 9) pw[i + 1] = pw[i] * 29;
	cin >> h >> w;
	s.resize(h);
	rep(i, h) cin >> s[i];
	rep(i, h) rep(j, i){
		string a = s[i], b = s[j];
		sort(all(a)); sort(all(b));
		if(a == b) can[i][j] = can[j][i] = 1;
	}
	vector<ll> l(w), r(w);
	cout << (rec(l, r, (1 << h) - 1) ? "YES" : "NO") << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int maxlen=1005;
const int INF=0x3f3f3f3f;
char s[maxlen],t[maxlen];
int main()
{
    scanf("%s",s);
    scanf("%s",t);
    int slen=(int)strlen(s),tlen=(int)strlen(t);
    int ans=INF;
    for(int i=0;i+tlen<=slen;i++)
    {
        int cur=0;
        for(int j=0;j<tlen;j++)
            cur+=(s[i+j]!=t[j]);
        ans=min(ans,cur);
    }
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 3824
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
#define allR(v) v.rbegin(), v.rend()
#define PRINT(v) for (auto x : (v)) cout <<x <<" " ; cout <<endl;
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
typedef pair<int,int> Pi;
const ll MOD = 1000000007;
const ll INF = 10000000000000000;
const int inf = 1001001001;
vector<int> x4 = {0, 1, 0, -1}, x8 = {0, 1, 1, 1, 0, -1, -1, -1};
vector<int> y4 = {1, 0, -1, 0}, y8 = {1, 1, 0, -1, -1, -1, 0, 1};
template<class T> inline bool chmin(T& a, T b){if (a>b){a = b; return true;}return false;}
template<class T> inline bool chmax(T& a, T b){if (a<b){a = b; return true;}return false;}
template<class T> inline T powerM(T a,T b){if (b==0) return 1;
T tmp = powerM(a,b/2); if (b%2==0) return tmp*tmp%MOD; else return tmp*tmp%MOD*a%MOD; }
template<class T> inline T power(T a,T b,T m=numeric_limits<T>::max()){ if (b==0) return 1;
  T tmp = power(a,b/2,m); if (b%2==0) return tmp*tmp%m; else return tmp*tmp%m*a%m; }
template<class T> inline T gcd(T a, T b){if (b==0) return a; return gcd(b, a%b);}
template<class T> inline T lcm(T a, T b){return a / gcd(a,b) * b;}
// ax+by=gcd(a,b)を解く
template<class T> inline T extgcd(T a,T b,T &x,T &y){if (b==0){x=1; y=0; return a;} T d=extgcd(b,a%b,y,x); y -= a/b*x; return d;}
void hey(){ cout <<"hey" <<endl; }

template<class T> struct edge { int to; T cost;};


int main() {
  int H,W; cin >>H >>W;
  vector<string> field(H); rep(i, H) cin >>field[i];
  int i,j; i=j=0;
  field[i][j] = '.';
  while (true){
    if (j+1<W && field[i][j+1]=='#'){
      j++;
      field[i][j] = '.';
    }else if (i+1<H && field[i+1][j]=='#'){
      i++;
      field[i][j] = '.';
    }else{
      break;
    }
  }
  string res = "Impossible";
  if (i!=H-1 || j!=W-1){ cout <<res <<endl; return 0;}
  for (int i=0; i<H; i++){
    for (int j=0; j<W; j++){
      if (field[i][j] == '#'){ cout <<res <<endl; return 0;}
    }
  }
  cout <<"Possible" <<endl;
}


Measured memory_bytes: 256