akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
//import java.util.stream.Collectors;

public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		System.out.println(sc.next().charAt(0) + "" +  sc.next().charAt(1) + "" +  sc.next().charAt(2));
	}
}


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

bool d[101],dd[101];	//true = 使った。

int ans = 0;
int n;
vector<int> G[101];



int dfs(int from, int now)
{

	for(int i = 0; i < G[from].size(); i++){
		if(!d[G[from][i]]){
			d[G[from][i]] = true;
			if(G[from].size() > 2)
				dd[G[from][i]] = true;
			ans = max(ans,dfs(G[from][i], now+1));
			d[G[from][i]] = false;
		}
	}

	return now;
}

int main(void)
{

	ans = 0;

	while(cin >> n,n){
ans = 0;
		int from,to;

		for(int i = 0; i < 101; i++)
			d[i] = dd[i] = false;

		for(int i = 0; i < n; i++){
			cin >> from >> to;
			G[from].push_back(to);
			G[to].push_back(from);
		}

		for(int i = 0; i <= n; i++){
			if(!dd[i]){
				dfs(i, 1);
			}
		}

		for(int i = 0; i < 101; i++)
			while(G[i].size())
				G[i].pop_back();

		cout << ans-1 << endl;

	}
	return 0;
}

Measured memory_bytes: 1216
#include<iostream>
using namespace std;
int main()
{
	string s;
	long k;
	cin>>s>>k;
	k--;
	if(s[0]=='1')
	{
		for(int i=0;;i++)
		{
			if(s[i]!='1')
			{
				if(i-1<k)cout<<s[i]<<endl;
				else cout<<1<<endl;
				return 0;
			}
		}
	}
	cout<<s[0]<<endl;
	return 0;
}

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

using namespace std;

typedef long long ll;
typedef vector<ll> vl;
typedef long double ld;
typedef vector<ld> vd;
typedef bool bl;
typedef vector<bl> vb;
typedef unordered_map<ll,unordered_map<ll,ll>> graph;

const ll e5 = 1 << 20;
const ll mod = 1000000007;
const ll e3 = 1 << 13;
const ll INF = 1ll << 60;

string s;

int main(){
  cin >> s;
  ll k = 15;
  k -= s.size();
  ll a = 0;
  for(ll i = 0;i < s.size();i++){
    if(s[i] == 'o') a++;
  }
  if(a+k >= 8) cout << "YES" << endl;
  else cout << "NO" << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>


using namespace std;


struct Node {
	int key;
	Node *parent, *left, *right;
};

Node *root, *NIL;

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

	z = new Node;
	z->key = k;
	z->left = NIL;
	z->right = NIL;

	while (x != NIL) {
		y = x;
		if (z->key < x->key) {
			x = x->left;
		}
		else {
			x = x->right;
		}
	}

	z->parent = y;

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

}

bool find(int key)
{
	Node *x = root;

	while (x != NIL ) {

		if (key < x->key) {
			x = x->left;
		}
		else if(key > x->key){
			x = x->right;
		}
		else {
			return true;
		}
	}

	return false;
}

void inorder(Node *u) {
	if (u == NIL) {
		return;
	}

	inorder(u->left);
	cout << " " <<u->key;
	inorder(u->right);
}


void preorder(Node *u) {
	if (u == NIL) {
		return;
	}

	cout << " " << u->key;
	preorder(u->left);
	preorder(u->right);
}


int main(void)
{
	int n;
	string command;
	int key;

	cin >> n;

	for (int i = 0; i < n; i++) {
		cin >> command;

		if (command == "insert") {
			cin >> key;
			insert(key);
		}
		else if (command == "print") {
			inorder(root);
			cout << endl;
			preorder(root);
			cout << endl;

		}
		else if (command == "find") {
			cin >> key;
			cout << ((find(key)) ? "yes" : "no" )<< endl;
		}

	}

	return 0;

}

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

#define ll long long
#define vl vector<ll>
#define vvl vector<vector<ll>> //vvl data(10, vector<ll>(10);
#define fo(i,a,b) for(ll i=a; i<b; i++)

int main(){
    int a, b, c, d, e;
    cin >> a >> b >> c >> d >> e;

    if(a == 0)
        cout << 1 << endl;
    else if(b == 0)
        cout << 2 << endl;
    else if(c == 0)
        cout << 3 << endl;
    else if(d == 0)
        cout << 4 << endl;
    else
        cout << 5 << endl;
    
}

/*
　 ◇　　　　 ミ ◇
　◇◇　 /￣|　 ◇◇
◇◇＼　 L＿| ◇◇
　　彡Ｏ(・＿・)/
　 　　ヽ Ｐ`Ｏ
　　 ／彡#_|ミ＼
　　　 </LL凵>
　　　　∪ ∪
pass system test !!
*/

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=(n)-1;i>=0;i--)
#define VSORT(v) sort(v.begin(), v.end())
#define DVSORT(v) sort(v.begin(), v.end(),greater<int>())
#define SORT(v, n) sort(v, v+n)
#define DSORT(v,n) sort(v, v+n,greater<int>())
#define vi vector<int>
#define pb push_back
#define P pair<int,int>


template <class T> void chmin(T&a, const T&b) { a = min(a,b); }
template <class T> void chmax(T&a, const T&b) { a = max(a,b); }

const double EPS =1e-9;
const long INF =2147483647;//32bit 2*1e+9
const long MOD =1e+9+7;
#define PI 3.14159265258979

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

int main(void){
	map<char,int> mp;
	string S;
	cin>>S;

	REP(i,(int)S.length()) mp[S[i]]++;

	for(auto itr=mp.begin();itr!=mp.end();itr++){
		if(itr->second%2!=0){
			puts("No");
			return 0;
		}
	}
	puts("Yes");
	return 0; 
}



Measured memory_bytes: 256
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.Scanner;

class Main {
	public static void main(String args[]) {
		Scanner scanner = new Scanner(System.in);
		int num = scanner.nextInt();		//要素数
		int[][] time = new int[num + 1][num + 1];
		
		for(int i = 0; i < num; i ++ ){		//要素数分処理
			time = make_array(time, num, scanner);
		}
		
		DepthFirstSearch(time,num);
		
		scanner.close();
	}

	public static void output(int[] find,int[] ans, int num){
	   //出力
	   StringBuilder sb = new StringBuilder("");
	   for (int i = 0; i < num; i++) {
		  sb.append( i + 1 ).append(" ").append( find[i] )
		  		.append(" ").append( ans[i] ).append( "\n" );
	   }
		System.out.print(sb);
	}
	
	public static void DepthFirstSearch(int[][] exetime, int num){
		Deque<Integer> deq = new ArrayDeque<Integer>();
		int[] find = new int[num + 1];			//格納用配列
		int[] ans = new int[num + 1];
		int time = 0;
		
		for (int k = 0; k < num; k ++ ) {
			if (find[k] != 0){
				continue;
			}
			 
			deq.push(k);
			
			while(!deq.isEmpty()) {
				int top = deq.peek();
				if (find[top] == 0){
					find[top] = ++time;
				}
				
				int j;
				for (j = 0; j < num; j++) {
					if (exetime[top][j] == 1 && find[j] == 0) {
						deq.push(j);
						find[j] = ++time;
						break;
					}
				}
				if ( j == num ) {
					deq.pop();
					ans[top] = ++time;
				}
			}
		}

		output(find,ans, num);					//出力呼び
	}
	
	public static int[][] make_array(int[][] array,int num, Scanner scanner){
		int off = scanner.nextInt();		//いらないけど仕方ない
		int ver_num = scanner.nextInt();	//頂点数
		
		//頂点の分その場所を1にしていく
		for(int j = 0; j < ver_num; j ++ ){
			array[off - 1][scanner.nextInt() - 1] = 1;
		}
		return array;
	}
}


Measured memory_bytes: 27680
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0;i < (n);i++)
#define all(v) v.begin(),v.end()
#define dec(x) cout << fixed << setprecision(x);
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using vvl = vector<vl>;


int main(){
  ll n,k; cin >> n >> k; ll d = 0; 
  /*while(true){
    if(n <= abs(n-k)){
      cout << n << endl;
      break;
    }
    else{
      n = abs(n-k);
    }
  }*/
  n = n % k;
  cout << min(n,abs(n-k)) << endl;
}

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

int main(void) {

    int N, K;
    cin >> N >> K;
    int cnt = 0; 
    while(N > 0) {
        N /= K;    
        cnt++;
    }

    cout << cnt << endl;

    return 0;

}



Measured memory_bytes: 256
use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {
        n: usize,
        a_vec: [i64; n],
    };
    let mut ans: i64 = n as i64 / 2 + n as i64 % 2;
    ans -= a_vec
        .iter()
        .step_by(2)
        .fold(0, |acc, a| if a % 2 == 0 { acc + 1 } else { acc });
    println!("{}", ans);
}


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

using namespace std;

int main()
{
    int n, a, b;
    cin >> n >> a >> b;
    if (n == 1)
    {
        if (a == b)
            cout << 1 << endl;
        else
            cout << 0 << endl;
    }
    else
    {
        if (a > b)
            cout << 0 << endl;
        else
        {
            long long minn = b + (long long) (n - 1) * a;
            long long maxx = a + (long long) (n - 1) * b;
            cout << maxx - minn + 1 << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
n = int(input())
w = list(map(int, input().split()))

total = sum(w)

cumsum = list()
cumsum.append(w[0])

for i in range(1, n):
    cumsum.append(cumsum[i - 1] + w[i])


ans = float('inf')
for s1 in cumsum:
    s2 = total - s1
    ans = min(ans, abs(s1 - s2))

print(ans)

Measured memory_bytes: 3064
#include<stdio.h>
#include<queue>
#include<algorithm>
#include<vector>
using namespace std;
vector<pair<int,int> > g[100];
int mat[100][100];
int v[2][100];
int ijk[2][100];
int main(){
	int a,b;
	while(scanf("%d%d",&a,&b),a){
		for(int i=0;i<a;i++){
			g[i].clear();
			for(int j=0;j<a;j++)mat[i][j]=999999;
		//	mat[i][i]=0;
			v[0][i]=v[1][i]=0;ijk[0][i]=ijk[1][i]=999999999;
		}
		for(int i=0;i<b;i++){
			int c,d,e;
			scanf("%d%d%d",&c,&d,&e);
			c--;d--;
			g[c].push_back(make_pair(d,e));
			g[d].push_back(make_pair(c,e));
			mat[c][d]=mat[d][c]=0;
		}
		ijk[0][0]=0;
		priority_queue<pair<int,pair<int,int> > > Q;
		Q.push(make_pair(0,make_pair(0,0)));
		while(Q.size()){
			int cost=-Q.top().first;
			int at=Q.top().second.first;
			int type=Q.top().second.second;
			Q.pop();
			if(v[type][at])continue;
			v[type][at]=1;
			
			for(int i=0;i<g[at].size();i++){
				if(!v[type][g[at][i].first]&&ijk[type][at]+g[at][i].second<ijk[type][g[at][i].first]){
					ijk[type][g[at][i].first]=ijk[type][at]+g[at][i].second;
					Q.push(make_pair(-cost-g[at][i].second,make_pair(g[at][i].first,type)));
				}
			}
			if(type==0){
				for(int i=0;i<a;i++)
					for(int j=0;j<a;j++)
						if(i!=at&&j!=at&&mat[at][i]==0&&mat[i][j]==0&&ijk[1][j]>ijk[0][at]){
							ijk[1][j]=ijk[0][at];
							Q.push(make_pair(-cost,make_pair(j,1)));
						}
			}
		}
		printf("%d\n",min(ijk[1][a-1],ijk[0][a-1]));
	}
}

Measured memory_bytes: 1088
using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;

class Program
{
    void solve()
    {
        int n = int.Parse(Console.ReadLine());
        int[] min = new int[26];

        for (int i = 0; i < 26; ++i)
        {
            min[i] = 100;
        }

        for (int i = 0; i < n; ++i)
        {
            string str = Console.ReadLine();
            int[] cnt = new int[26];

            for (int j = 0; j < str.Length; ++j)
            {
                cnt[str[j] - 'a']++;
            }
            for (int j = 0; j < 26; ++j)
            {
                if (cnt[j] < min[j])
                {
                    min[j] = cnt[j];
                }
            }
        }
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < 26; ++i)
        {
            sb.Append((char)('a' + (char)i), min[i]);
        }
        Console.WriteLine(sb.ToString());
    }
    public static int Main()
    {
        bool loop = false;
#if ES_DEBUG
        loop = true;
#endif
        do
        {
            new Program().solve();
        } while (loop);
        return 0;
    }
}


Measured memory_bytes: 13140
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <string>
#include <cmath>
#include <set>
#include <stack>
#include <queue>
#include <numeric>
#include <deque>
#include <cstring>
#include <iterator>
#include <map>
#include <cstdlib>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <complex>
#include <bitset>
#include <chrono>
#include <random>
#include <assert.h>

using namespace std;

#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define eb emplace_back
#define el '\n'
typedef  long long  ll;
typedef  unsigned long long  ull;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef vector<ll> vll;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<pll> vpll;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<string> vs;

ll inf=(ll)2e18;
const int mod=1000000007;
//const int mod=998244353;

int n,m;



int main()
{   ios_base::sync_with_stdio(false);cin.tie(NULL);
    int q,t,k,u,v;
    ll x,a,b,c,d,y,l,p;
    cin >> a >> b >> n;
    c=0;
    for(int i=a; i<=b; i++){
        c+=(i%n==0);
    }
    cout << c << el;
    
    return 0;
}


Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
int main () {
    long long N, M;
    cin >> N >> M;
    long long ans = 1, p = 1000000007;
    for (int i = 1; i <= N; i++) {
        ans *= i;
        ans %= p;
    }
    for (int i = 1; i <= M; i++) {
        ans *= i;
        ans %= p;
    }
    if (abs(N-M) == 1) {
    }
    else if (N == M) {
        ans *= 2;
        ans %= p;
    }
    else {
        ans = 0;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
// Working program with FastReader
import java.io.BufferedReader; 

import java.io.IOException; 
import java.io.InputStreamReader; 
import java.util.Scanner; 
import java.util.StringTokenizer;
import java.lang.*;
public class Main
{ 
	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; 
		} 
	} 

	long gcd(long a, long b) {
		if(b==0) {
			return a;
		}
		return gcd(b,a%b);
	}
	public static void main(String[] args) {
		FastReader ob = new FastReader();
		int arr[] = new int[100];
		arr[ob.nextInt()]++;
		arr[ob.nextInt()]++;
		arr[ob.nextInt()]++;
		if(arr[5]==2 && arr[7]==1) {
			System.out.println("YES");
		}
		else {
			System.out.println("NO");
		}
	}

} 


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

int main(){
    string str,str2,str3;
    ll N;
    cin >> N;
    cin >> str;
    if(N%2==1) puts("No");
    else{
        for(ll i=0;i<N/2;i++){
            if(str[i]!=str[i+(N/2)]){
                puts("No");
                return 0;
            }
        }
        puts("Yes");
        
    }
    

    return 0;
}

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

bool isKaibun(string);

int main() {
  string s;
  cin >> s;
  int n = s.size();
  string s_head = "", s_tail = "";

  for (int i = 0; i < (n-1) / 2; i++) {
    s_head += s[i];
    s_tail += s[1 + i + (n-1)/2];
  }

  //cout << s_head << endl << s_tail << endl;
  if (isKaibun(s) && isKaibun(s_head) && isKaibun(s_tail)) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

bool isKaibun(string str) {
  string substr = str;
  reverse(substr.begin(), substr.end());
  return (str == substr);
}

Measured memory_bytes: 256
a = []
b = []

for i in range(3):
    a.append(list(map(int, input().split())))

n = int(input())

for i in range(n):
    b.append(int(input()))

# yoko
for i in range(3):
    yoko = set(a[i])
    if yoko <= set(b):
        print("Yes")
        exit()

# tate
for i in range(3):
    tate = set([a[0][i], a[1][i], a[2][i]])
    if tate <= set(b):
        print("Yes")
        exit()

# naname
naname1 = {a[0][0], a[1][1], a[2][2]}
naname2 = {a[0][2], a[1][1], a[2][0]}

if naname1 <= set(b):
    print("Yes")
    exit()
elif naname2 <= set(b):
    print("Yes")
    exit()
else:
    print("No")

Measured memory_bytes: 3064
#include<stdio.h>
#include<string.h>
 
 
typedef struct  {
    int first;
    int second;
    int third;
    int forth;
    int fifth;
    int sixth;
} Dice;
 
int main() {
    Dice one;
    int q, i;
 
    scanf("%d ", &one.first);
    scanf("%d ", &one.second);
    scanf("%d ", &one.third);
    scanf("%d ", &one.forth);
    scanf("%d ", &one.fifth);
    scanf("%d", &one.sixth);
 
    scanf("%d\n", &q);
 
    for(i = 0; i < q; ++i) {
        int a[2];
        scanf("%d %d", &a[0], &a[1]);
         
        if(a[0] == one.first){
            if(a[1] == one.second) printf("%d\n", one.third);
            if(a[1] == one.third) printf("%d\n", one.fifth);
            if(a[1] == one.forth) printf("%d\n", one.second);
            if(a[1] == one.fifth) printf("%d\n", one.forth);
        }
        if(a[0] == one.second){
            if(a[1] == one.first) printf("%d\n", one.forth);
            if(a[1] == one.third) printf("%d\n", one.first);
            if(a[1] == one.forth) printf("%d\n", one.sixth);
            if(a[1] == one.sixth) printf("%d\n", one.third);
        }
        if(a[0] == one.third){
            if(a[1] == one.second) printf("%d\n", one.sixth);
            if(a[1] == one.first) printf("%d\n", one.second);
            if(a[1] == one.sixth) printf("%d\n", one.fifth);
            if(a[1] == one.fifth) printf("%d\n", one.first);
        }
        if(a[0] == one.forth){
            if(a[1] == one.second) printf("%d\n", one.first);
            if(a[1] == one.sixth) printf("%d\n", one.second);
            if(a[1] == one.first) printf("%d\n", one.fifth);
            if(a[1] == one.fifth) printf("%d\n", one.sixth);
        }
        if(a[0] == one.fifth){
            if(a[1] == one.first) printf("%d\n", one.third);
            if(a[1] == one.third) printf("%d\n", one.sixth);
            if(a[1] == one.forth) printf("%d\n", one.first);
            if(a[1] == one.sixth) printf("%d\n", one.forth);
        }
         if(a[0] == one.sixth){
            if(a[1] == one.second) printf("%d\n", one.forth);
            if(a[1] == one.third) printf("%d\n", one.second);
            if(a[1] == one.forth) printf("%d\n", one.fifth);
            if(a[1] == one.fifth) printf("%d\n", one.third);
        }
    }
    return 0;
}


Measured memory_bytes: 2076
#include <iostream>

using namespace std;

int main() {
  int h, n;
  cin >> h >> n;
  int sum = 0;
  while (n--) {
    int a;
    cin >> a;
    sum += a;
  }

  cout << (sum >= h ? "Yes" : "No") << endl;

  return 0;
}


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

int main ()
{
    int n;
    cin >> n;
    long a[n];
    rep(i, n) cin >> a[i];

    long minA = 0;
    long sumA = 0;

    for (int i = 0; i < n; i++) {
        sumA += a[i];
        if (i % 2 == 0) {
            if (sumA <= 0) {
                minA += abs(sumA) + 1;
                sumA += abs(sumA) + 1;
            }
        }
        else {
            if (sumA >= 0) {
                minA += abs(sumA) + 1;
                sumA -= abs(sumA) + 1;
            }
        }
    }

    long minB = 0;
    long sumB = 0;
    for (int i = 0; i < n; i++) {
        sumB += a[i];
        if ((i+1) % 2 == 0) {
            if (sumB <= 0) {
                minB += abs(sumB) + 1;
                sumB += abs(sumB) + 1;
            }
        }
        else {
            if (sumB >= 0) {
                minB += abs(sumB) + 1;
                sumB -= abs(sumB) + 1;
            }
        }
    }

    cout << min(minA, minB) << endl;
    return 0;
}

Measured memory_bytes: 1024
A = int(input())
B = int(input())
C = int(input())
X = int(input())

ans = 0

for i in range(A+1):
    for j in range(B+1):
        for k in range(C+1):
            if 500*i+100*j+50*k == X:
                ans += 1
print(ans)

Measured memory_bytes: 9032
import java.util.Scanner;

public class Main{
  public static void main(String[] args){
    Scanner sc=new Scanner(System.in);
    final int A=sc.nextInt();
    String   op=sc.next();
    final int B=sc.nextInt();
    if(op.equals("+")){
      System.out.println(A+B);
    }else{
      System.out.println(A-B);
    }
  }
}

Measured memory_bytes: 22868
#include <iostream>

using namespace std;

void solve()
{

	char field[3][3];
	while(cin >> field[0][0])
	{
		if(field[0][0] == '0')
		{
			break;
		}
		cin >> field[0][1] >> field[0][2];
		for(int i = 1; i < 3; ++i)
		{
			for(int j = 0; j < 3; ++j)
			{
				cin >> field[i][j];
			}
		}
		bool flag = false;
		for(int i = 0; i < 3; ++i)
		{
			if(field[i][0] == 'b' && field[i][1] == 'b' && field[i][2] == 'b' ||
			   field[0][i] == 'b' && field[1][i] == 'b' && field[2][i] == 'b')
			{
				cout << 'b' << endl;
				flag = true;
				break;
			}
			else if(field[i][0] == 'w' && field[i][1] == 'w' && field[i][2] == 'w' ||
					field[0][i] == 'w' && field[1][i] == 'w' && field[2][i] == 'w')
			{
				cout << 'w' << endl;
				flag = true;
				break;
			}
		}
		if(!flag)
		{
			if(field[0][0] == 'b' && field[1][1] == 'b' && field[2][2] == 'b' ||
			   field[0][2] == 'b' && field[1][1] == 'b' && field[2][0] == 'b')
			{
				cout << 'b' << endl;
				flag = true;
			}
			else if(field[0][0] == 'w' && field[1][1] == 'w' && field[2][2] == 'w' ||
				    field[0][2] == 'w' && field[1][1] == 'w' && field[2][0] == 'w')
			{
				cout << 'w' << endl;
				flag = true;
			}
		}
		if(!flag)
		{
			cout << "NA" << endl;
		}
	}
}

int main()
{
	solve();
	return(0);
}

Measured memory_bytes: 1132
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cstdint>
#include <cassert>
#include <random>

using namespace std;
using i64 = int64_t;
using i32 = int32_t;
template<class T, class U> void init_n(vector<T>& v, size_t n, U x) 
{ v = vector<T>(n, x); }
template<class T> void init_n(vector<T>& v, size_t n) { init_n(v, n, T()); }
template<class T> void read_n(vector<T>& v, size_t n, size_t o = 0) 
{ v = vector<T>(n+o); for (size_t i=o; i<n+o; ++i) cin >> v[i]; }
template<class T> void read_n(T a[], size_t n, size_t o = 0)
{ for (size_t i=o; i<n+o; ++i) cin >> a[i]; }
template<class T> T iabs(const T& x) { return max(x, -x); }
// #define abs gabs

int main() {
    int n, k;
    cin >> n >> k;
    vector<int> c(n + 1);
    for (int i = 0; i < n; ++i) {
        int x;
        cin >> x;
        c[x]++;
    }

    sort(begin(c), end(c));
    int ans = 0;
    for (int i = 1; i <= n - k; ++i) {
        ans += c[i];
    }

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

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define endl "\n"
#define speed() ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define sz(x) (int)(x).size()
#define _USE_MATH_DEFINES
using namespace std;
typedef long long int lli;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

int main() {
    speed();
    int N; cin >> N;
    int B[N-1];
    rep(i, 0, N-1) cin >> B[i];
    int A[N];
    A[0] = B[0], A[N-1] = B[N-2];
    rep(i, 1, N-1) A[i] = min(B[i-1], B[i]);
    int ans = 0;
    rep(i, 0, N) ans += A[i];
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(long i = 0; i < n; i++)
#define erep(i, n) for(long i = 1; i <= n; i++)
const long MOD = 1000000007;
#define all(a) a.begin(), a.end()
#define show(ans)  cout << ans << endl;

const int INF = 1e8;
typedef pair<int, int> P;

char maze[50][51];
int N, M;
int sx, sy; int gx, gy;
int d[50][51];
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

int bfs(){
    queue<P> que;
    rep(i, N){
        rep(j, M) d[i][j] = INF;
    }
    que.push(P(sx, sy));
    d[sx][sy] = 0;
    
    while(que.size()){
        P p = que.front(); que.pop();
        if(p.first == gx && p.second == gy) break;
        
        rep(i, 4){
            int nx = p.first + dx[i], ny = p.second + dy[i];

            if(0<=nx && nx<N && 0<=ny && ny<M && maze[nx][ny] != '#' && 
            d[nx][ny] == INF){
                que.push(P(nx, ny));
                d[nx][ny] = d[p.first][p.second] + 1;
            }
        }
    }
    return d[gx][gy];
}

int main() {
cin >> N >> M;
sx = 1; sy = 1; gx = N; gy = M;
sx--; sy--; gx--; gy--;
rep(i, N){
    rep(j, M){
        cin >> maze[i][j];
    }
}
int ans = bfs();
if(ans == INF) {
  show(-1);
  return 0;
}
long cnt = 0;
rep(i, N){
  rep(j, M){
    if(maze[i][j] == '.') cnt++;
  }
}

show(cnt - ans - 1);
// show(ans);
  return 0;
 
}



Measured memory_bytes: 256
#include <stdio.h> 

 
 int main(){ 
     int h, w; 
     int i, j; 
     while(1){ 
         scanf("%d %d ", &h, &w); 
         if(h==0&&w==0)break; 
         for(i=0;i<h;i++){ 
             for(j=0;j<w;j++){ 
                 if((i%2==0&&j%2==0)||(i%2==1&&j%2==1)){ 
                     printf("#"); 
                 }else{ 
                     printf("."); 
                 } 
             } 
             printf("\n"); 
         } 
         printf("\n"); 
     } 
 
 
     return 0; 
 } 



Measured memory_bytes: 2144
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long long N,A,B;
  cin >> N >> A >> B;
  long long div = N / (A+B);
  long long par = N % (A+B);
  
  if(par >= A) cout << div*A + A << endl;
  else cout << div*A + par << endl;
}

Measured memory_bytes: 3636
#include <cstring>
#include <cstdio>
#define rg register
using namespace std;
typedef long long ll;
const int maxn=200010,mod=1e9+7,INF=0x3f3f3f3f;
template <typename Tp> inline int getmin(Tp &x,Tp y){return y<x?x=y,1:0;}
template <typename Tp> inline int getmax(Tp &x,Tp y){return y>x?x=y,1:0;}
template <typename Tp> inline void read(Tp &x)
{
    x=0;int f=0;char ch=getchar();
    while(ch!='-'&&(ch<'0'||ch>'9')) ch=getchar();
    if(ch=='-') f=1,ch=getchar();
    while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
    if(f) x=-x;
}
struct data{int v,nxt;}edge[maxn*10];
int n,p,tot,ans,x,y,p1,p2,mn1,mn2,c[maxn],w[maxn],mn[maxn],mp[maxn];
int vis[maxn],cnt[maxn],fac[maxn],inv[maxn],head[maxn];
inline void insert(int u,int v)
{
	edge[++p]=(data){v,head[u]};head[u]=p;
	edge[++p]=(data){u,head[v]};head[v]=p;
}
int power(int x,int y)
{
	int res=1;
	for(;y;y>>=1,x=(ll)x*x%mod)
	  if(y&1)
	    res=(ll)res*x%mod;
	return res;
}
void input()
{
	mn1=mn2=INF;
	memset(mn,0x3f,sizeof(mn));
	read(n);read(x);read(y);
	for(rg int i=1;i<=n;i++)
	{
		read(c[i]);read(w[i]);
		if(getmin(mn[c[i]],w[i])) mp[c[i]]=i;
		if(getmin(mn1,w[i])) p1=i;
	}
	for(rg int i=1;i<=n;i++)
	  if(i^c[p1]&&getmin(mn2,mn[i]))
	    p2=mp[i];
	for(rg int i=1;i<=n;i++)
	  if(i!=mp[c[i]]&&w[i]+mn[c[i]]<=x)
	    insert(i,mp[c[i]]);
	if(mn1+mn2<=y) insert(p1,p2);
	for(rg int i=1;i<=n;i++)
	{
		if(c[i]^c[p1]&&w[i]+mn1<=y) insert(i,p1);
		if(mn2<INF&&c[i]^c[p2]&&w[i]+mn2<=y) insert(i,p2);
	}
}
inline int C(int n,int m){return m>n?0:(ll)fac[n]*inv[m]%mod*inv[n-m]%mod;}
void dfs(int x)
{
	if(vis[x]) return ;
	vis[x]=1;++cnt[c[x]];++tot;
	for(int i=head[x];i;i=edge[i].nxt)
	  dfs(edge[i].v);
}
int main()
{
	input();fac[0]=1;
	for(rg int i=1;i<=n;i++) fac[i]=(ll)fac[i-1]*i%mod;
	inv[n]=power(fac[n],mod-2);
	for(rg int i=n-1;~i;i--) inv[i]=(ll)inv[i+1]*(i+1)%mod;
	dfs(p1);ans=1;
	for(rg int i=1;i<=n;i++)
	{
		ans=(ll)ans*C(tot,cnt[i])%mod;
		tot-=cnt[i];
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 14464
#include<cstdio>
int a,b,k;
bool c[1000000000];
int main()
{
	scanf("%d%d%d",&a,&b,&k);
	int t=k;
	for(int i=a;i<=b&&t--;i++)
		c[i]=1;
	for(int i=b;i>=a&&k--;i--)
		c[i]=1;
	for(int i=a;i<=b;i++)
		if(c[i])
			printf("%d\n",i);
	return 0;
}

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

int main() {
  int n; cin >> n;
  vector<int> vec(n);
    for (int i = 0; i < n; i++) {
    cin >> vec.at(i);
  }
  sort(vec.begin(), vec.end());
  reverse(vec.begin(), vec.end());
  int a = vec.at(0);
  int ans=0;
  for (int i = 1; i < n; i++) {
    ans += vec.at(i);
  }
  if (ans>a) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String []args) {
	Scanner in = new Scanner(System.in);
	for(int i = 0;;i++) {
		int x = in.nextInt();
		int y = in.nextInt();
		if(x==0&&y==0) break;
		if(x<y) System.out.println(x+" "+y);
		else System.out.println(y+" "+x);
	}
	in.close();
	}
}


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

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

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

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

int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  int n, k;
  cin >> n >> k;
  combination comb1(n - k + 1);
  combination comb2(k - 1);
  for(int i = 1; i <= k; ++i){
    mint ans = comb1(n - k + 1, i) * comb2(k - 1, i - 1);
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 256
N = int(input())
T,X,Y = 0,0,0
for n in range(N):
    t,x,y = map(int,input().split())
    if (x-X)+(y-Y) <= t-T and ((t-T)-(x-X)-(y-Y))%2 == 0:
        X = x
        Y = y
        T = t
        continue
    else:
        print('No')
        exit()
print('Yes')


Measured memory_bytes: 3060
import java.util.Scanner;
public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        long N = sc.nextLong();
        long K = sc.nextLong();
        
        
        long ab = N;
        ab = N % K;
       // System.out.print(ab);
        
        long min = Math.abs(ab - K);
        if(min > ab){
            min = ab;
        }
        
        System.out.print(min);
    }
}

Measured memory_bytes: 23764
#include<iostream>
#include<deque>
using namespace std;
int main() {
	long n;
	cin >> n;
	deque <long long> x;
	for (long i = 0; i < n; i++)
	{
		int y;
		cin >> y;
		if (y == 0)
		{
			int n;
			cin >> n;
			long long m;
			cin >> m;
			if (n == 0)
				x.push_front(m);
			else
				x.push_back(m);
		}
		else if (y == 1)
		{
			long p;
			cin >> p;
			cout << x[p] << endl;
		}
		else if (y == 2)
		{
			int n;
			cin >> n;
			if (n == 0)
				x.pop_front();
			else
				x.pop_back();
		}
	}
	x.clear();
	return 0;
}


Measured memory_bytes: 5956
n, w = map(int, input().split())
a = [[int(i) for i in input().split(" ")] for j in range(n)]
dp = [[0]*(w+1) for i in range(n+1)]
for i in range(1, n+1):
    w_, v_ = a[i-1]
    for j in range(1, w+1):
        if j < w_:
            dp[i][j] = dp[i-1][j]
        else:
            dp[i][j] = max(dp[i-1][j-w_]+v_, dp[i-1][j])
print(dp[n][w])
    

Measured memory_bytes: 119916
N, x = map(int, input().split())
array = list(map(int, input().split()))

array.sort()
s = sum(array)

if s < x:
    print(N-1)
elif s == x:
    print(N)
else:
    a = 0
    for i in range (N):
        a += array[i]
        if a > x:
            print(i)
            break

Measured memory_bytes: 3064
#include <iostream>
using namespace std;
void ABC150(void);
void ABC151(void);
void ABC152(void);
void ABC153(void);
void ABC154(void);
void ABC155(void);
void ABC156(void);
void ABC157(void);
void ABC158(void);
void ABC159(void);

int main(void){
    ABC152();
}

void ABC152(){
    int n,m;
    cin>>n>>m;
    if(m==n)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include <vector>
#include <algorithm>
#include <string>

using namespace std;
using ll = long long;

struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

int main(){
    int n,m,x,y;
    cin >> n >> m;
    UnionFind tree(n+1);
    vector<int> p(n+1);
    for(int i=1;i<=n;i++){
        cin >> p[i];
    }
    for(int i=0;i<m;i++){
        cin >> x >> y;
        tree.unite(x,y);
    }
    int ans = 0;
    for(int i=1;i<=n;i++){
        if(tree.same(p[i],i)==1)   ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
using Pld = pair<ld, ld>;
using Vec = vector<ll>;
using VecP = vector<P>;
using VecB = vector<bool>;
using VecC = vector<char>;
using VecD = vector<ld>;
using VecS = vector<string>;
template <class T>
using Vec2 = vector<vector<T>>;
#define REP(i, m, n) for(ll i = (m); i < (n); ++i)
#define REPN(i, m, n) for(ll i = (m); i <= (n); ++i)
#define REPR(i, m, n) for(ll i = (m)-1; i >= (n); --i)
#define REPNR(i, m, n) for(ll i = (m); i >= (n); --i)
#define rep(i, n) REP(i, 0, n)
#define repn(i, n) REPN(i, 1, n)
#define repr(i, n) REPR(i, n, 0)
#define repnr(i, n) REPNR(i, n, 1)
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define fs first
#define sc second
template <class T1, class T2>
bool chmax(T1 &a, const T2 b){if(a < b){a = b; return true;} return false;}
template <class T1, class T2>
bool chmin(T1 &a, const T2 b){if(a > b){a = b; return true;} return false;}
ll pow2(const int n){return (1LL << n);}
void co() { cout << endl; }
template <class Head, class... Tail>
void co(Head&& head, Tail&&... tail) {
    cout << head << ' ';
    co(forward<Tail>(tail)...);
}
void ce() { cerr << endl; }
template <class Head, class... Tail>
void ce(Head&& head, Tail&&... tail) {
    cerr << head << ' ';
    ce(forward<Tail>(tail)...);
}
void sonic(){ios::sync_with_stdio(false); cin.tie(0);}
void setp(const int n){cout << fixed << setprecision(n);}
constexpr int INF = 1e9+1;
constexpr ll LINF = 1e18L+1;
constexpr ll MOD = 1e9L+7;
constexpr ll MOD_N = 998244353;
constexpr ld EPS = 1e-11;
const double PI = acos(-1);

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

    ll ans = LINF;
    rep(i, s.size() - t.size() + 1){
        ll cnt = 0;
        rep(j, t.size()){
            if (s[i + j] != t[j]) cnt++;
        }
        chmin(ans, cnt);
    }
    co(ans);

    return 0;
}


Measured memory_bytes: 3632
#include <algorithm>
#include <iostream>
#include <string>
#include <random>
#include <cassert>
#include <cstring>
#include <chrono>

using namespace std;

typedef long long ll;


int main()
{
  int n;
  cin >> n;
  vector<ll> a(n), s(n);
  for (int i = 0; i < n; ++i) cin >> a[i];
  s[0] = a[0];
  for (int i = 1; i < n; ++i) s[i] = s[i - 1] + a[i];

  ll result = s[n - 1];
  for (int i = 0; i < n; ++i) {
    ll l = s[i];
    ll r = s[n - 1] - s[i];
    result = min<ll>(result, abs(l - r));
  }
  cout << result << endl;
  return 0;
}


Measured memory_bytes: 3328
#include <iostream>

using namespace std;

int main()
{
int a,b,c;
cin>>a>>b>>c;
if(a==b&&a!=c){cout<<"Yes";}
else if(a==c&&a!=b){cout<<"Yes";}
else if(b==c&&b!=a){cout<<"Yes";}
else {cout<<"No";}

        return 0;
}


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

ans = S.count('E')
w = 0
e = S.count('E')
for i in range(N):
    if S[i-1] == 'W' and i != 0:
        w += 1
    if S[i] == 'E':
        e -= 1
    if w + e < ans:
        ans = w + e
print(ans)

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

int main() {
    int a,b,c,f=0;
    cin >>a>>b>>c;
    
    for (int x=a;x<=b;x++){
        if (c%x==0)f++;
    }
    cout<<f<<endl;
    
    
                

        
    return 0;        
         
}

Measured memory_bytes: 1164
n, m, l = map(int, input().split())
a = []
b = []

for i in range(n):
    a.append(list(map(int, input().split())))

for i in range(m):
    b.append(list(map(int, input().split())))

for i in range(n):
    ans_matrix = []
    for j in range(l):
        num = 0
        for k in range(m):
            num += a[i][k] * b[k][j]
        ans_matrix.append(num)
    print(' '.join(list(map(str, ans_matrix))))



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

int main() {
	int N; cin >> N;
	vector<int> a(N);
	for (int i = 0; i < N; i++)
	{
		cin >> a[i];
	}
	int K = 1,cnt=0;
	for (int i = 0; i < N; i++)
	{
		if (a[i] == K) {
			K++;
		}
		else cnt++;
	}
	if (cnt == N)cout << "-1";
	else cout << cnt;
	cout << endl;
}


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

int main() {
  int n;
  cin >> n;
  if(n < 10) cout << n << endl;
  else if(9 < n && n < 100) cout << 9 << endl;
  else if(n < 1000) cout << n - 90 << endl;
  else if(n < 10000) cout << 909 << endl;
  else if(n < 100000) cout << n - 9090 << endl;
  else cout << 90909 << endl;
}

Measured memory_bytes: 3604
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var arr = input.trim().split("\n");
while (true) {
   if (arr[0] == "0 0") break;
   var nm = arr.shift().split(" ").map(Number);
   var n = nm[0];
   var m = nm[1];
   var max = [];
   for (var i = 0; i < m; i++) max[i] = 0;
   for (var i = 0; i < n; i++) {
      var dv = arr.shift().split(" ").map(Number);
      var d = dv[0] - 1;
      var v = dv[1];
      if (max[d] < v) max[d] = v;
   }
   var sum = 0;
   for (var i = 0; i < m; i++) sum += max[i];
   console.log(sum);
}

Measured memory_bytes: 17896
import numpy as np
from scipy.sparse.csgraph import dijkstra

my_input = lambda : map(int, input().split(" "))

N, M = my_input()
dist = 100 * 1000 * (np.ones([N, N]) - np.eye(N)).astype(int)

edges = []
for i in range(M):
    a, b, c = my_input()
    dist[a-1][b-1] = c
    dist[b-1][a-1] = c
    edges.append((a, b, c))

dist = dijkstra(dist, directed=False)
print(len([e for e in edges if e[2] != dist[e[0]-1][e[1]-1]]))

Measured memory_bytes: 14316
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <iomanip>
#include <vector>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <map>
#include <queue>
#define rep(i,n) for (int i=0;i<(n);i++)

using namespace std;

void print(vector<int> v) {
	for_each(v.begin(), v.end(), [](int x) {
		cout << x << " ";
		});
	cout << endl;
}

int main() {
	int n;
	cin >> n;
	vector<int> p(n);
	vector<int> q(n);
	for (int i = 0;i < n;i++) {
		cin >> p[i];
	}

	for (int i = 0;i < n;i++) {
		cin >> q[i];
	}

	vector<int> v(n);
	for (int i = 0;i < n;i++) {
		v[i] = i + 1;
	}

	int pn = 0, qn = 0;
	int count = 0;
	do {
		count++;
		if (v == p) {
			pn = count;
		}
		if (v == q) {
			qn = count;
		}
	} while (next_permutation(v.begin(), v.end()));
	
	cout << abs(pn - qn) << endl;
	return 0;
}


//BBBBBBBBBBBBBBBBBB
//int main() {
//	int n;
//	string s;
//	cin >> n >> s;
//
//	int ans = 0;
//	for (int i = 0;i < n - 2;i++) {
//		if (s[i] == 'A' && s[i + 1] == 'B' && s[i + 2] == 'C')ans++;
//	}
//
//	cout << ans << endl;
//
//	return 0;
//}

//AAAAAAAAAAAAAAAAA
//int main() {
//	int k, x;
//	cin >> k >> x;
//
//	if (k * 500 >= x) cout << "Yes" << endl;
//	else cout << "No" << endl;
//
//	return 0;
//}


Measured memory_bytes: 3572
import java.util.*;

public class Main {
	char[][] map;
	boolean[][] visit;
	int cnt;
	boolean flag;
	
	void drop(){
		for(int i=0;i<6;i++){
			char[] temp = new char[12];
			Arrays.fill(temp, '.');
			int k = 0;
			for(int j=0;j<12;j++){
				if(map[j][i]!='.'){
					temp[k] = map[j][i];
					k++;
				}
			}
			for(int j=0;j<12;j++) map[j][i] = temp[j];
		}
	}
	
	void func(){
		LinkedList<Integer> x = new LinkedList<Integer>();
		LinkedList<Integer> y = new LinkedList<Integer>();
		LinkedList<Integer> sx = new LinkedList<Integer>();
		LinkedList<Integer> sy = new LinkedList<Integer>();		
		int cnt, p, q;
		
		for(int z=0;;z++){
			flag = false;
			visit = new boolean[12][6];
			for(int i=0;i<12;i++){
				for(int j=0;j<6;j++){
					if(map[i][j]=='R' || map[i][j]=='G' || map[i][j]=='B' || map[i][j]=='Y' || map[i][j]=='P'){
						
						x.offer(j);
						y.offer(i);
						cnt = 0;
						while(x.size()!=0){
							p = x.poll();
							q = y.poll();
							sx.offer(p);
							sy.offer(q);
							visit[q][p] = true;
							cnt++;
							
							if(p-1>=0 && visit[q][p-1]==false && map[q][p-1]==map[i][j]){
								x.offer(p-1);
								y.offer(q);
							}
							if(p+1<6 && visit[q][p+1]==false && map[q][p+1]==map[i][j]){
								x.offer(p+1);
								y.offer(q);
							}
							if(q-1>=0 && visit[q-1][p]==false && map[q-1][p]==map[i][j]){
								x.offer(p);
								y.offer(q-1);
							}
							if(q+1<12 && visit[q+1][p]==false && map[q+1][p]==map[i][j]){
								x.offer(p);
								y.offer(q+1);
							}
						}
						if(cnt>=4){
							flag = true;
							while(sx.size()!=0){
								p = sx.poll();
								q = sy.poll();
								map[q][p] = '.';
								if(p-1>=0 && map[q][p-1]=='O') map[q][p-1] = '.';
								if(p+1<6 && map[q][p+1]=='O') map[q][p+1] = '.';
								if(q-1>=0 && map[q-1][p]=='O') map[q-1][p] = '.';
								if(q+1<12 && map[q+1][p]=='O') map[q+1][p] = '.';
							}
						}else{
							sx.clear();
							sy.clear();
						}
						
					}
				}
			}
			if(flag==false){
				System.out.println(z);
				break;
			}else{
				drop();
			}
		}
	}
	
	void solve(){
		Scanner sc = new Scanner(System.in);
		
		int T = sc.nextInt();
		for(int t=0;t<T;t++){
			map = new char[12][6];
			for(int i=11;i>=0;i--) map[i] = sc.next().toCharArray();
			func();
		}
	}
	
	public static void main(String[] args) {
		new Main().solve();
	}	
}

Measured memory_bytes: 46144
N, K = [int(i) for i in input().split()]
h = sorted([int(input()) for _ in range(N)])

ans = float("inf")
for i, h_i in enumerate(h):
    if i + K - 1 == N:
        break
    ans = min(ans, h[i + K - 1] - h_i)
print(ans)

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

const int MAX_N = 1000005;
const int MAX = 2000000000;
int N;
int heights[MAX_N];
int mem[MAX_N];

int dp(int stone) {
  if (stone == N) return 0;
  if (stone > N) return MAX;
  if (mem[stone] != -1) return mem[stone];

  int best = MAX;
  if (stone + 1 <= N) best = std::min(best,
    dp(stone + 1) + std::abs(heights[stone] - heights[stone+1]));
 if (stone + 2 <= N) best = std::min(best,
    dp(stone + 2) + std::abs(heights[stone] - heights[stone+2]));
  mem[stone] = best;
  return best;
}

int main() {
  memset(mem, -1, sizeof(mem));
  scanf("%d", &N);
  for (int i = 0; i < N; ++i) {
    scanf("%d", heights + i + 1);
  }

  printf("%d\n", dp(1));
}


Measured memory_bytes: 12756
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define lint long long
using namespace std;
int readint() {
	char c = getchar_unlocked();
	int ans = 0;
	while ('0' <= c && c <= '9') {
		ans = ans * 10 + c - '0';
		c = getchar_unlocked();
	}
	return ans;
}
lint readlint() {
	char c = getchar_unlocked();
	lint ans = 0;
	while ('0' <= c && c <= '9') {
		ans = ans * 10 + c - '0';
		c = getchar_unlocked();
	}
	return ans;
}
char ch[1024];
void writeint(int x) {
	int ptr = 0;
	while (x) {
		ch[ptr++] = (x % 10) + '0';
		x /= 10;
	}
	while (ptr) {
		putchar_unlocked(ch[--ptr]);
	}
	putchar_unlocked(' ');
}
int q;
constexpr int mod=1000000007;
lint x,y,a,n,m;
constexpr lint f[]={0,1,1,2,3,5,8,13,21,34,55,89,144,233,377,610,987,1597,2584,4181,6765,10946,17711,28657,46368,75025,121393,196418,317811,514229,832040,1346269,2178309,3524578,5702887,9227465,14930352,24157817,39088169,63245986,102334155,165580141,267914296,433494437,701408733,1134903170,1836311903,2971215073,4807526976,7778742049,12586269025,20365011074,32951280099,53316291173,86267571272,139583862445,225851433717,365435296162,591286729879,956722026041,1548008755920,2504730781961,4052739537881,6557470319842,10610209857723,17167680177565,27777890035288,44945570212853,72723460248141,117669030460994,190392490709135,308061521170129,498454011879264,806515533049393,1304969544928657,2111485077978050,3416454622906707,5527939700884757,8944394323791464,14472334024676221,23416728348467685,37889062373143906,61305790721611591,99194853094755497,160500643816367088,259695496911122585,420196140727489673,679891637638612258,1100087778366101931};
int main(){
	q=readint();
	rep(i,q){
		x=readlint();y=readlint();
		if(x>y)swap(x,y);
		if(y<=2){
			writeint(1);writeint(y==1?1:x==1?2:4);
			continue;
		}
		rep(j,99){
			if(x<f[j]||y<f[j+1]){
				a=(x==1?2:1);
				rep(k,j-2){
					n=f[j-1]+f[j-3-k]*f[k+2],m=f[j]+f[j-2-k]*f[k+2];
					if(n<=x&&m<=y)a+=(y-m)/n+1;
				}
				if(f[j]<=x){
					a++;
					rep(k,j-2)a+=(x-f[j])/(f[j-2-k]*f[k+2]);
				}
				writeint(j-2);writeint(a%mod);
				break;
			}
		}
	}
}

Measured memory_bytes: 4252
import java.util.*;

public class Main {
	
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		int start = 0;
		int end = 0;
		for (int i = 0; i < s.length(); i++) {
			if (s.charAt(i) == 'A') {
				start = i;
				break;
			}
		}
		for (int i = s.length() - 1; i >= 0; i--) {
			if (s.charAt(i) == 'Z') {
				end = i;
				break;
			}
		}
		System.out.println(end - start + 1);
	}
}


Measured memory_bytes: 26908