akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
int main(void){
    
    string s;
    int n;
    
    cin >> s;
    
    n = s.size();
    
    for(int i=1; i<=n; i++){
        
        if(i-1<n-1&&s.at(i-1)!=s.at(n-i)){
            
            cout << "No" << endl;
            return 0;
            
        }
        
        if(i-1<(n-1)/2-i&&s.at(i-1)!=s.at((n-1)/2-i)){
            
            cout << "No" << endl;
            return 0;
            
        }
        
        if((n+3)/2+i-2<n-i&&s.at((n+3)/2+i-2)!=s.at(n-i)){
            
            cout << "No" << endl;
            return 0;
            
        }
        
    }
    
    cout << "Yes" << endl;
    
    return 0;
    
}

Measured memory_bytes: 256
import java.util.*

fun main(args: Array<String>) {
  val sc = Scanner(System.`in`)
  val n = sc.nextInt()
  val m = sc.nextInt()
  val x = sc.nextInt()
  val a = (1..m).map { sc.nextInt() }

  println(abc094b(n, m, x, a))
}

private fun abc094b(n: Int, m: Int, x: Int, a: List<Int>): Int {
  val first = a.filter { it < x }.count()
  val second = a.filter { it > x }.count()

  return Math.min(first, second)
}


Measured memory_bytes: 31380
x = input()

if int(x[0:2]) <= 12 and int(x[0:2])>0:
  a = True
else:
  a = False
      
if int(x[2:4]) <= 12 and int(x[2:4])>0:
  b = True
else:
  b = False
  
if(a and b):
  print("AMBIGUOUS")
  
elif( not a and b):
  print("YYMM")
  
elif( a and not b):
  print("MMYY")
  
else:
  print("NA")

Measured memory_bytes: 3064
N, K = map(int, input().split())
P = list(map(int, input().split()))
C = list(map(int, input().split()))

seen = []
roots = []
candidates = []

for i in range(N):
    if i+1 in seen:
        continue
    root = [i+1]
    seen.append(i+1)
    to = P[i]
    while(root[0] != to):
        root.append(to)
        seen.append(to)
        to = P[to-1]
    roots.append(root)
for root in roots:
    length = len(root)
    eachMoveBests = [None] * length
    for i in range(length):
        score = 0
        to = P[root[i]-1]
        for j in range(len(root)):
            score += C[to-1]
            to = P[to-1]
            if eachMoveBests[j] == None or score > eachMoveBests[j]:
                eachMoveBests[j] = score
    # 周回スコア
    aroundScore = eachMoveBests[len(eachMoveBests)-1]
    if length < K and aroundScore > 0:
        for i in range(len(eachMoveBests)):
            if K-i-1 % length == 0:
                candidates.append(aroundScore * ((K-i-1) // length))
            else:
                candidates.append(aroundScore * ((K-i-1) // length) + eachMoveBests[i])
    else:
        candidates.append(max(eachMoveBests[:K]))

print(max(candidates))


Measured memory_bytes: 74452
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<set>
#include<queue>
#include<stack>
#include<bitset>
#include<functional>
#include<map>
using namespace std;
int p = 1000000007;
#define int long long
#define vel vector<long long>
#define vvel vector<vel>
#define rep(i,n) for(long long i=0;i<n;i++)
#define sor(v) sort(v.begin(),v.end())
#define mmax(a,b) a=max(a,b)
#define mmin(a,b) a=min(a,b)
#define mkp make_pair
#define pin pair<int,int>
#define qin pair<pin,int>
#define V vector
#define Endl endl
#define veb vector<bool>
#define sq(a) (a)*(a)
#define rev(s) reverse(s.begin(),s.end())
#define end_pr(s) cout << s <<endl;return 0
#define itn int
#define bs bitset<5001>

int kai_size = 1000001;
vel kai(kai_size, 1);
vel ink(kai_size, 1);
vel dist;
int sz(pin x) { return x.first*x.second; }
void make(int c, int pot, int d, vel &col, vel &max_use,vvel &way) {
	if (max_use[pot] < d) {
		if (col[pot] == 0) { col[pot] = c; }
		max_use[pot] = d;
		for (auto x : way[pot]) {
			make(c, x, d - 1, col, max_use, way);
		}
	}
}
signed main() {
	int n; cin >> n;
	cout << 3 * n*n << endl;
	return 0;
}

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

long long int n;
long long int a, b;
long long int res = 0;

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

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

public class Main {

    public static void main(String[] args) throws Exception {

        InputStreamReader is = new InputStreamReader(System.in);
        BufferedReader reader = new BufferedReader(is);

        List<String> mylist = new ArrayList<>();

        // 標準入力からの値を変数strinputに代入
        String strinput = reader.readLine();

        while (strinput != null) {

            mylist.add(strinput);
            strinput = reader.readLine();

        }
        String arr01[] = mylist.get(0).split(" ");

        int h = Integer.valueOf(arr01[0]);
        int w = Integer.valueOf(arr01[1]);

        //2次元配列を定義
        int arr_data[][] = new int[h + 2][w + 2];

        for (int i = 0; i < 2 + h; i++) {
            if (i == 0 || i == h + 1) {
                for (int j = 0; j < w + 2; j++) {
                    arr_data[i][j] = 0;
                }
            } else {

                String s = mylist.get(i);

                for (int j = 0; j < w; j++) {
                    String stemp = s.substring(j, j + 1);
                    if (stemp.equals("#")) {
                        arr_data[i][j + 1] = 1;
                    } else {
                        arr_data[i][j + 1] = 0;
                    }
                }
            }
        }

        for (int i = 1; i < h + 1; i++) {
            // System.out.println(Arrays.toString(arr_data[i]));
            for (int j = 1; j < w + 1; j++) {
                if (arr_data[i][j] == 1) {
                    System.out.print("#");
                } else {
                    //System.out.println(".");

                    int cnt = 0;
                    cnt += arr_data[i - 1][j - 1];
                    cnt += arr_data[i - 1][j];
                    cnt += arr_data[i - 1][j + 1];
                    cnt += arr_data[i][j - 1];
                    cnt += arr_data[i][j];
                    cnt += arr_data[i][j + 1];
                    cnt += arr_data[i + 1][j - 1];
                    cnt += arr_data[i + 1][j];
                    cnt += arr_data[i + 1][j + 1];
                    System.out.print(cnt);
                }

            }
            System.out.println();
        }
    }

}


Measured memory_bytes: 22740
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;

namespace AtCoderTemplate
{
    class Program
    {
        static void Main (string[] args)
        {
            string[] str;
            str = Console.ReadLine ().Split (' ');

            long N = long.Parse (str[0]);
            long A = long.Parse (str[1]);
            long B = long.Parse (str[2]);

            long tmp = 0;
            if (N % (A + B) <= A)
            {
                tmp = N % (A + B);
            }
            else
            {
                tmp = A;
            }
            Console.WriteLine (N / (A + B) * A + tmp);
        }
        class MyLibrary
        {
            public static int GCD (int a, int b)
            {
                if (a % b == 0) return b;
                return GCD (b, a % b);
            }
        }
    }
}

Measured memory_bytes: 27552
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while (true) {
			int r = sc.nextInt();
			if (r == 0) {
				sc.close();
				break;
			}

			int n = sc.nextInt();

			int[] xl = new int[n];
			int[] xr = new int[n];
			int[] h = new int[n];
			for (int i = 0; i < n; i++) {
				xl[i] = sc.nextInt();
				xr[i] = sc.nextInt();
				h[i] = sc.nextInt();
			}

			int[] cover = new int[2 * r];
			for (int i = 0; i < n; i++) {
				int ll = Math.max(0, xl[i] + r);
				int rr = Math.min(r * 2, Math.max(0, xr[i] + r));

				for (int j = ll; j < rr; j++) {
					cover[j] = Math.max(cover[j], h[i]);
				}
			}

			double ans = 100000.0;
			for (int i = 0; i < cover.length; i++) {
				int x = Math.abs(r - i);
				int xx = Math.abs(r - i - 1);
				double t1 = cover[i] - r * Math.sin(Math.acos((double) x / r));
				double t2 = cover[i] - r * Math.sin(Math.acos((double) xx / r));
				ans = Math.min(ans, Math.min(t1 + r, t2 + r));
			}

			System.out.println(String.format("%.4f", ans));
		}
	}
}

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

int A[100];
int dp[100][400];

void chmax(int &A, int B) {
  A = max(A, B);
}

int main() {
  int T; scanf("%d", &T);
  while(T--) {
    memset(dp, -1, sizeof(dp));

    int N; scanf("%d", &N);
    for(int i=0; i<N; i++) {
      scanf("%d", &A[i]);
    }

    if(N == 1 || N == 2) {
      printf("%d\n", A[N-1]);
    }
    else {
      dp[1][ A[0] ] = A[1];

      for(int i=1; i<N-1; i++) {
        for(int j=0; j<400; j++) {
          if(dp[i][j] < 0) continue;
          
          chmax(dp[i+1][ dp[i][j] ], A[i+1]);
          if(dp[i][j] > 0) chmax(dp[i+1][ dp[i][j] - 1 ], A[i+1] + j);
        }
      }

      int ans = 0;
      for(int i=0; i<400; i++) chmax(ans, dp[N-1][i]);
      printf("%d\n", ans);
    }
  }
  return 0;
}



Measured memory_bytes: 2868
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        final int N = sc.nextInt();
        int[][] l = new int[2][N];
        int ans = 0;
        for(int i = 0;i < N;i++)    l[0][i] = sc.nextInt();
        for(int i = 0;i < N;i++){
            l[1][i] = sc.nextInt();
            ans += l[1][i];
        }
        ans += l[0][0];
        int a = ans;
        for(int i = 1;i < N;i++){
            a = a-l[1][i-1]+l[0][i];
            ans = Math.max(ans, a);
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 21844
#include<cstdio>
#include<vector>
#include<queue>
#include<algorithm>
using namespace std;

int main(){
  while(true){
    int n,m;
    scanf("%d %d",&n,&m);
    if(n == 0 && m == 0) return 0;
    int a[n][m];
    for(int i = 0;i < n;i++){
      for(int j = 0;j < m;j++){
        scanf("%d",&a[i][j]);
      }
    }
    pair<int,int> p[100];
    for(int i = 0;i < m;i++){
      p[i].first = 0;
      p[i].second = m - i;
      for(int j = 0;j < n;j++){
        if(a[j][i]) p[i].first++;
      }
    }
    sort(p,p+m);
    for(int i = m - 1;i > 0;i--) printf("%d ",m - p[i].second + 1);
    printf("%d\n",m - p[0].second + 1);
  }
}

Measured memory_bytes: 2984
from heapq import heappop, heappush
N, M = map(int, input().split())
V = [[] for _ in range(N)]
for i in range(1,N):
    V[i].append((i-1, 0))
for _ in range(M):
    l, r, c = map(int, input().split())
    V[l-1].append((r-1, c))
INF = float('inf')

q = [(0, 0)]
d = [INF] * N
d[0] = 0

while q:
    _, u = heappop(q)
    for v, c in V[u]:
        if d[v] > d[u] + c:
            d[v] = d[u] + c
            heappush(q, (d[v], v))

print(d[-1] if d[-1] != INF else -1)


Measured memory_bytes: 80416
#include "bits/stdc++.h"
using namespace std;

const int N = 1e5 + 5;
int in[N];

int main() {
    int n;
    scanf("%d", &n);
    for (int i = 0; i < n; ++i) {
        int x; cin >> x;
        in[x]++;
    }

    int best = 0;
    for(int i = 1; i < N - 2; ++i) {
        best = max(best, in[i] + in[i - 1] + in[i + 1]);
    }
    cout << best << endl;
}

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

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            B();
        }

        static void B()
        {
            var s = ReadInt();
            var list = new List<int>();

            list.Add(-1);
            list.Add(s);

            Func<int, int> func = n =>
            {
                if (n % 2 == 0)
                    return n / 2;
                return 3 * n + 1;
            };

            for (int i = 2; i <= 1000010; i++)
            {
                var a = func(list[i - 1]);
                if (list.Contains(a))
                {
                    Console.WriteLine(i);
                    return;
                }
                list.Add(a);
            }
        }

        static IEnumerable<int> Range(int start, int stop)
        {
            if (start < 0 || stop < 0 || start > stop || (start <= 0 && stop <= 0))
                return new List<int>();

            return Enumerable.Range(start, stop - start);
        }

        static bool IsDigit(string str)
        {
            var i = 0;
            return int.TryParse(str, out i);
        }

        static int DigitsSum(long num)
        {
            return num.ToString().Select(x => x.ToString()).Sum(int.Parse);
        }

        static int[] ToIntArray(string str)
        {
            return str.Select(x => x.ToString()).Select(int.Parse).ToArray();
        }

        static string Read() => Console.ReadLine();
        static int ReadInt() => int.Parse(Read());
        static long ReadLong() => long.Parse(Read());

        static List<string> ReadSplit() => Read().Split().ToList();
        static List<int> ReadSplitInt() => Read().Split().Select(int.Parse).ToList();

        static void Print(object value) => Console.Write(value.ToString());
        static void Println(object value) => Console.WriteLine(value.ToString());

        static string Join<T>(IEnumerable<T> list) => string.Join("", list);
    }

    public static class MyExtensions
    {
        public static string Slice(this string str, int start = 0, int stop = 0)
        {
            if (start > str.Length || stop > str.Length || start < 0 || stop < 0)
                return "";

            if (stop == 0) stop = str.Length;
            return str.Substring(start, stop - start);
        }
    }
}

Measured memory_bytes: 13140
//#define _GLIBCXX_DEBUG//TLEの原因になるので注意！！！！！！！！！！！
#include<cmath>
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
vector<int> arr;
stack<int> st;
queue<int> qu;
queue<pair<int,int> > qu2;
priority_queue<int> pq;
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define rep2(i,n) for(int i=1; i<=(int)(n); i++)
#define mins(x,y) x=min(x,y)
#define maxs(x,y) x=max(x,y)
typedef set<int> set_t;
typedef set<string> set_g;
typedef complex<double> xy_t;
static const int NIL = -1;
static const int INF = 1000000007;
#define mp make_pair
#define sz(x) int(x.xise())
#define mod 1000000007
#define reps(i,s,n) for(int i = s; i < n; i++)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
deque<int> deq;
#define fi first
#define se second
//#define int long long

//cerrはコメントアウトしなくても通る//ただしTLEを引き起こすことがある

ll N,M,H,W,K,Q,A,B;
string S;
//const ll MOD = 998244353;
const ll MOD = (1e+9) + 7;
//const ll INF = 1LL << 60;
//typedef pair<ll,ll> P;
typedef pair<int, int> P;
bool chmx(int &a, int b) {
	if (b > a) {
		a = b;
		return true;
	}
	return false;
}

bool chmn(int &a, int b) {
	if (b < a) {
		a = b;
		return true;
	}
	return false;
}

int c[10][1005];

int main(){
	int h,w,k;
	cin >> h>>w>>k;
	int ans=INF;
	string s[h];
	rep(i,h){
		cin >> s[i];
	}
	rep(div,1<<(h-1)){
		int g=0;//グループ数
		vector<int> id(h);
		rep(i,h){
			id[i]=g;
			if(div>>i&1==1)g++;
		}
		g++;

		rep(i,g)rep(j,w)c[i][j]=0;
		rep(i,h)rep(j,w)c[id[i]][j]+=(s[i][j]-'0');

		int num=g-1;
		vector<int> now(g);
		auto add=[&](int j){
			rep(i,g) now[i]+=c[i][j];
			rep(i,g) if(now[i]>k)return 0;
			return 1;
		};
		rep(j,w){
			if(!add(j)){
				num++;
				now=vector<int>(g);
				if(!add(j)){
					num=INF;
					break;
				}
			}
		}
		chmn(ans,num);
	}
	cout<<ans<<endl;
    return 0;
}



Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <cfloat>

using std::cerr;
using std::cin;
using std::cout;
using std::endl;

int main(void){
  cout << std::fixed << std::setprecision(16);
  cin.tie(0);
  std::ios::sync_with_stdio(false);

  int n,k,q;
  cin>>n>>k>>q;
  int count[100001]={};
  for(int i=0;i<q;i++){
    int tmp;
    cin>>tmp;
    count[tmp]++;
  }
  for(int i=1;i<=n;i++){
    if(k-q+count[i]>=1){
      cout<<"Yes"<<endl;
    }else{
      cout<<"No"<<endl;
    }
  }





  return 0;
}


Measured memory_bytes: 1024
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define E "\n"

using namespace std;
const long long MOD = (long long)1e9 + 7;

int n, k, a[200009], b[200009];

int main()
{
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n >> k;
	for (int i = 0; i < n; i++) cin >> a[i];
	for (int i = 0; i < k; i++) {
		bool ok = true;
		for (int i = 0; i < n; i++) {
			if (a[i] < n) ok = false;
		}
		if (ok) break;
		memset(b, 0, sizeof(int) * (n + 1));
		for (int i = 0; i < n; i++) {
			b[max(0, i - a[i])]++;
			b[min(n, i + a[i] + 1)]--;
		}
		int cur = 0;
		for (int i = 0; i < n; i++) {
			cur += b[i];
			a[i] = cur;
		}
	}
	for (int i = 0; i < n; i++) cout << a[i] << " ";
	cout << E;
	//system("pause");
	return 0;
}

Measured memory_bytes: 5204
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; --i)
#define whole(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
using P = pair<int, int>;
#define debug(var) cerr << "[" << #var << "] " << var << endl
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
const ll mod = 1000000007;
const int dx[] = {-1,0,1,0};
const int dy[] = {0,-1,0,1};


int main(){
    int n, m, k;
    cin >> n >> m >> k;
    vector<ll> a(n);
    vector<ll> b(m);
    rep(i, n) cin >> a[i];
    rep(i, m) cin >> b[i];
    ll t = 0;
    rep(i, m) t += b[i];
    int ans = 0;
    int index = m-1;
    rep(i, n+1) {
        while (index>=0 && t>k) {
            t -= b[index];
            index--;
        }
        if (t>k) continue;
        chmax(ans, i+index+1);
        if (i==n) break;
        t += a[i];
    }
    
    
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 6428
#include <cstdio>
#include <map>
#include <iostream>
#include <cstring>
using namespace std;
int n,x,m;
char a[500];
int flag1=-1,flag2=-1;
int main()
{
	scanf("%s",a);
	int len=strlen(a);
	for(int i=0;i<len;i++)
	{
		if(a[i]=='C'&&flag1==-1)
			flag1=i;
		if(a[i]=='F'&&flag1!=-1)
			flag2=1;
	}
	if(flag1!=-1&&flag2!=-1)
		printf("Yes");
	else
		printf("No");
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <string.h>
#include <math.h>
#include <cmath>
#include <tuple>
#include <vector>
#include <bitset>
#include <stack>
#include <iomanip>
#include <set>
#include <queue>
#include <map>

typedef long long ll;
typedef unsigned long long ull;
#define mk make_pair
#define mkt make_tuple

using namespace std;
const int N = 300005;
const ll MOD = 1e9 + 7;
const int M = 61;
int arr[N];

ll gcd(ll a, ll b) {
    while (b) {
        a %= b;
        swap(a, b);
    }
    return a;
}

ll lcm(ll a, ll b) {
    return (a / gcd(a, b)) * b;
}

int main()
{
    int n; ll m; cin >> n >> m;
    ll lc = 1; bool isValid = true;
    for (int i = 0; i < n; i++) {
        cin >> arr[i]; arr[i] /= 2;
        if (i == 0) lc = arr[i];
        else lc = lcm(lc, arr[i]);
        if (lc > m) isValid = false;
    }
    for (int i = 0; i < n; i++)
        if ((lc / arr[i]) % 2 == 0)
            isValid = false;

    if (isValid) {
        ll val = (m / lc) / 2 + (m / lc) % 2;
        cout << val;
    }
    else cout << 0;
}



Measured memory_bytes: 640
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
#define N 1333
inline int read(){
	int x=0,f=1;
	char c=getchar();
	while(c<'0'||c>'9'){
		if(c=='-')f=-1;
		c=getchar();
	}
	while(c>='0'&&c<='9'){
		x=(x<<1)+(x<<3)+c-'0';
		c=getchar();
	}
	return x*f;
}
int a[N][N],n,m;
void Copy(int x,int y,int len){
	for(int i=1;i<=len;++i){
		for(int j=1;j<=len;++j){
			a[i+x][j+y]=a[i][j];
		}
	}
}
void dfs(int n){
	if(n==1)return (void)(a[1][1]=1);
	dfs(n>>1);
	Copy(0,(n>>1)+1,n>>1);
	Copy((n>>1)+1,0,n>>1);
	Copy((n>>1)+1,(n>>1)+1,n>>1);
	a[(n>>1)+1][(n>>1)+1]=1;
}
int main(){
	n=read(),m=read();
	dfs((1<<max(n,m))-1);
	for(int i=1;i<=(1<<n)-1;++i){
		for(int j=1;j<=(1<<m)-1;++j){
			putchar(a[i][j]+'0');
		}
		putchar('\n');
	}
	return 0;
}



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

using namespace std;


typedef long long ll;
ll mod=1e9+0LL;
ll MOD=1e18+0LL;
double pi=acos(-1);


int main()
{
    int cs=1;
    //scanf("%d",&cs);
    while(cs--)
    {
        int n,i;
        cin>>n;
        int a[n],b[n];
        for(i=0;i<n;i++)
        {
            cin>>a[i]>>b[i];
        }
        sort(a,a+n);
        sort(b,b+n);
        ll p,q;
        if(n%2)
        {
            p=a[n/2];
            q=b[n/2];
        }else{
            p=(a[n/2]+a[(n/2)-1]);
            q=(b[n/2]+b[(n/2)-1]);
        }
        cout<<(ll)(q-p+1);
    }
}


Measured memory_bytes: 5192
import itertools
N = int(input())
P = list(map(int,input().split()))
Q = list(map(int,input().split()))

lst = itertools.permutations(range(1,N+1))

for i, L in enumerate(lst):
    #print(i,L)
    if L == tuple(P):
        a = i + 1
    if L == tuple(Q):
        b = i + 1

print(abs(a-b))


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

#define rep(i,a,b) for(int i=a;i<b;i++)
#define int long long
const int inf = 100100100100100;
const int mod = 1000000007;



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

    int n,q;
    cin >> n >> q;

    rep(i,0,q){
        int a,b;
        cin >> a >> b;

        if(n==1){
            cout << min(a,b) << endl;
            continue;
        }
        while(a != b){
            if( a > b ){
                a = (a+n-2)/n;
            }else{
                b = (b+n-2)/n;
            }
        }

        if(a == 0) cout << 1 << endl;
        else cout << a << endl;

    }

}

Measured memory_bytes: 1280
#include<bits/stdc++.h>
using namespace std;
#define PI 3.141592653589793238
int main(){
	long double a,b,h,m;
	
	cin>>a>>b>>h>>m;
	long double q=(h*30)+(0.5*m)-(m*6);
	long double param, result;
    param = q;
    result = cos ( param * PI / 180.0 );
	long double w=pow(a,2)+pow(b,2)-(2*a*b*result);
	cout<< std::setprecision(20)<<pow(w,0.5); 
	
	return 0;
	
}

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

using namespace std;

struct Point {
	int x, y;
	Point(int x=0, int y=0) : x(x), y(y) {}
	bool operator==(const Point &o) const {
		return (x == o.x && y == o.y);
	}
	Point operator-(const Point &o) const {
		return Point(x-o.x, y-o.y);
	}
};

struct Line {
	vector<Point> vertices;
	Line() {}
	Line(vector<Point> v) : vertices(v) {}
};

bool is_same(Line a, Line b) {
	Point diff = a.vertices[0];
	for (int i = 0; i < a.vertices.size(); i++) {
		a.vertices[i] = a.vertices[i] - diff;
	}
	diff = b.vertices[0];
	for (int i = 0; i < b.vertices.size(); i++) {
		b.vertices[i] = b.vertices[i] - diff;
	}

	Line r[4]; // bを回転
	r[0] = b;
	r[1].vertices.push_back(Point(0,0));
	r[2].vertices.push_back(Point(0,0));
	r[3].vertices.push_back(Point(0,0));
	for (int i = 1; i < b.vertices.size(); i++) {
		r[1].vertices.push_back(Point(b.vertices[i].y, -b.vertices[i].x));
		r[2].vertices.push_back(Point(-b.vertices[i].x, -b.vertices[i].y));
		r[3].vertices.push_back(Point(-b.vertices[i].y, b.vertices[i].x));
	}

	for (int i = 0; i < 4; i++) {
		if (a.vertices == r[i].vertices) {
			return true;
		}
	}

	return false;
}
	
int main() {
	int n, m;
	while (cin >> n, n) {
		vector<Line> lines;
		for (int i = 0; i <= n; i++) {
			cin >> m;
			Line l;
			for (int j = 0; j < m; j++) {
				Point p;
				cin >> p.x >> p.y;
				l.vertices.push_back(p);
			}
			lines.push_back(l);
		}

		Line fl = lines[0];
		Line rfl = lines[0]; reverse(rfl.vertices.begin(), rfl.vertices.end());
//		for (int i = 0; i < fl.vertices.size(); i++) {
//			cout << fl.vertices[i].x << ' ' << fl.vertices[i].y << endl;
//		}
//		cout << endl;
//		for (int i = 0; i < rfl.vertices.size(); i++) {
//			cout << rfl.vertices[i].x << ' ' << rfl.vertices[i].y << endl;
//		}
			
		vector<int> same;

		for (int i = 1; i <= n; i++) {
			if (is_same(fl, lines[i])) {
				same.push_back(i);
			}
			else if (is_same(rfl, lines[i])) {
				same.push_back(i);
			}
		}

		for (int i = 0; i < same.size(); i++) {
			cout << same[i] << endl;
		}

		cout << "+++++" << endl;
	}
	return 0;
}

Measured memory_bytes: 1232
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <string>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <cctype>

using namespace std;

#define ll long long

void solve() {
    int n;
    scanf("%d", &n);
    if (n) printf("0\n");
    else printf("1\n");
    return ;
}

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


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

template <typename T>
T binary_search(function<bool(T)> func, T include, T exclude)
{
  while (abs(exclude - include) > 1)
  {
    auto middle = (include + exclude) / 2;
    (func(middle) ? include : exclude) = middle;
  }
  return include;
}

long long N, A[200000], B[200000];
int main()
{
  cin >> N;
  for(int i = 0; i < N; i++)
  {
    cin >> A[i];
    A[i + N] = B[i] = B[i + N] = A[i];
  }
  for(int i = 1; i < N * 2; i++)
    B[i] += B[i - 1];
  auto f = [&](long long v)
  {
    for(int i = 0; i < N; i++)
    {
      auto it = lower_bound(B + i, B + N * 2, v + B[i]);
      if(it == B + N * 2)
        continue;
      auto it2 = lower_bound(it, B + N * 2, v + *it);
      if(it2 == B + N * 2)
        continue;
      if(B[i + N] - *it2 >= v)
        return true;
    }
    return false;
  };
  cout << binary_search<long long>(f, 0, B[N]) << endl;
}

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

int main(){
  ll N,l,r;
  cin>>N;
  ll X[N],A[N];
  for(ll i=0;i<N;i++){
    cin>>X[i];
    A[i]=X[i];
  }
  sort(A,A+N);
  l=A[N/2-1];
  r=A[N/2];
  for(ll i=0;i<N;i++){
    if(X[i]<=l) cout<<r<<endl;
    else cout<<l<<endl;
  }
}



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

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

// ABC131-A

int main() {

    string S;
    cin >> S;

    for(int i=0; i<3; i++){
        if(S[i]==S[i+1]){
            cout << "Bad" << endl;
            return 0;
        }
    }
    
    cout << "Good" << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <cassert>
using namespace std;
using ll = long long;
const int INF = 1<<30;
const int MOD = 1e9 + 7;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    int n, k; cin >> n >> k;
    double ans = 0.0;
    double s = 1.0 / n;
    for(int i = 1; i <= n; i++)
    {
        ll score = i;
        double p = 1;
        while(true)
        {
            if(score >= k) break;
            score *= 2;
            p *= 0.5;
        }
        ans += s * p;
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String [] args){
        Scanner sc =new Scanner(System.in);
        int N = sc.nextInt();
        int [] t = new int[N+11];
        int [] x = new int[N+1];
        int [] y = new int[N+1];
        t[0] =x[0] =y[0] =0;
        for (int i=1;i<=N;i++){
            t[i] = sc.nextInt();
            x[i] = sc.nextInt();
            y[i] = sc.nextInt();
        }
        boolean flag =true;
        for (int i=0;i<N;i++){
            int dt = t[i+1] - t[i];
            int dist =Math.abs(x[i+1]-x[i]) + Math.abs(y[i+1] -y[i]);
            if (dist>dt){
                flag =false;
                break;
            }else{
                if (dist%2 != dt%2){
                    flag =false;
                    break;
                }
            }
        }
        if (flag){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
    }
}

Measured memory_bytes: 94244
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		@SuppressWarnings("resource")
		Scanner sc = new Scanner(System.in);
		
		String str = sc.nextLine();
		String[] wds = str.split("[,. ]");
		
		boolean hasFirst = false;
		
			for (String wd : wds) {
				if (wd.length() < 7 && wd.length() > 2) {
						if (!hasFirst) {
								System.out.print(wd);
								hasFirst = true;
						} else {
								System.out.printf(" %s" ,wd);
						}
				}
			}
			
		System.out.println();
		
	}
}



Measured memory_bytes: 26344
function Main(input) {
  s=input.split(" ")[0];
  c=input.split(" ")[1];
  if(c>=s*2){
  c=c-2*s;
  a=s;
  s=0;
  b=Math.floor(c/4);
  }else{
  a=0;b=Math.floor(c/2);}
 
console.log(Number(a)+Number(b));
}
 
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 21064
import Control.Monad
import Data.Function
import Data.Char
import Data.List
import Text.Read
import Text.ParserCombinators.ReadPrec

import Data.Array

newtype Pair a b = Pair { getPair :: (a, b) }

instance (Read a, Read b) => Read (Pair a b) where
  readPrec = Pair `dot` (,) <$> readPrec <* get <*> readPrec

instance (Show a, Show b) => Show (Pair a b) where
  show (Pair (a, b)) = show a ++ " " ++ show b

readPair :: IO (Int, Int)
readPair = getPair <$> readLn

infixr 8 `dot`
dot :: (c -> d) -> (a -> b -> c) -> a -> b -> d
dot = ((.).(.))

main :: IO ()
main = do
  n <- readLn
  ls <- listArray (1, n) . map read . words <$> getLine
  print $ solve n ls

solve :: Int -> Array Int Int -> Int
solve n ls = 
  length [ (i, j, k) 
         | i <- [1..n], j <- [i+1..n], k <- [j+1..n] 
         , let [a,b,c] = sort [ls!i, ls!j, ls!k]
         , a < b && b < c
         , a + b > c
         ]


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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(a)     (a).begin(),(a).end()
#define VI         vector<int>
#define MOD 1000000007

using ll = long long int;
using P = pair<int,int>;

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

const ll INF=(ll)1e19;
//const int INF=(1<<30);

int main(){
  int a,b,t;
  cin >> a >> b >> t;
  cout << t/a*b << endl;
}



Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Text.RegularExpressions;
using System.Globalization;

namespace test
{
    class Program
    {
        static void Main(string[] args)
        {
            String S = Console.ReadLine();
            int ans = 0;

            for (int i = 1; i < S.Count(); i++)
            {
                if ((S.Count() - i )% 2 == 0)
                {
                    int Length = ((S.Count() - i) / 2) -1;
                    if (S.Substring(0, Length) == S.Substring(Length + 1, Length))
                    {
                        ans = S.Count() - i;
                        break;
                    }
                }
            }
            Console.WriteLine(ans);
        }
    }
}


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

long long func(long long H) {
  if (H == 1) return 1;
  else {
    return 2 * func(H/2) + 1;
  }
}

int main(void) {
  long long H;
  
  cin >> H;
  
  cout << func(H) << endl;
  
  return 0;
}

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

using namespace std;
using ll = long long;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.precision(10);
  cout << fixed;
  int n, k;
  cin >> n >> k;
  vector<double> ar(n);
  for(auto &x: ar) cin >> x;
  double res = 0;
  double sum = 0;
  for(int i = 0; i < k; ++i) {
    sum += ((ar[i] * (ar[i] + 1)) / 2) / ar[i];
  }
  res = sum;
  for(int i = k; i < n; ++i) {
    sum -= ((ar[i - k] * (ar[i - k] + 1)) / 2) / ar[i - k];
    sum += ((ar[i] * (ar[i] + 1)) / 2) / ar[i];
    res = max(res, sum);
  }
  cout << res << '\n';
  return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <vector>

using namespace std;

int main() {
  int N;
  int x;
  int i, tmp;
  int *a;
  
 
  cin >> N >> x;

  a = new int[N]; 
  
  for(i=0;i<N;i++){
    cin >> a[i]; 
  }

  sort(a,a+N);

  tmp=0;
  for(i=0;i<N;i++){
    tmp += a[i];
    if(tmp>x) break;       
  }

  if(tmp < x) i--; 
  cout << i <<endl;
  
  return 0;
}


Measured memory_bytes: 256
N, K = map(int, input().split())
ans = 0

#全てあまり0のパターン
x = N // K#あまりが0であるものの数
ans += x ** 3

#全てあまりが等しく、それがK/2に等しいパターン
if K % 2 == 0:
  y = (N - K //2) // K + 1#あまりがK/2であるものの数
  ans += y ** 3
  
print(ans)

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

struct Doubling {
    int sz, n;
    vector<vector<int>> table;
    Doubling(int n, long long ma = 1LL << 62) : sz(0), n(n) {
        while ((1LL << sz) < ma) ++sz;    // 64 - __builtin_clzll(ma)
        table.assign(sz, vector<int>(n, -1));
    }
    void set_next(int i, int x) { table[0][i] = x; }
    void build() {
        for (int k = 0; k < sz - 1; k++) for (int i = 0; i < n; i++) {
            if (~table[k][i]) table[k + 1][i] = table[k][table[k][i]];
        }
    }
    int query(int i, long long t) {
        for (int k = sz - 1; k >= 0; k--) {
            if (t >> k & 1) i = table[k][i];
        }
        return i;
    }
    long long lower_bound(int s, int t) {
        long long ret = s != t;
        if (s > t) swap(s, t);
        for (int k = sz - 1; k >= 0; k--) {
            if (table[k][s] < t) ret += 1LL << k, s = table[k][s];
        }
        return ret;
    }
};

int main() {
    int n; cin >> n;
    vector<int> x(n);
    for (int &xi: x) cin >> xi;
    int l; cin >> l;
    Doubling dbl(n);
    int nxt = 0;
    for (int i = 0; i < n; i++) {
        while (nxt + 1 < n && x[nxt + 1] - x[i] <= l) nxt++;
        dbl.set_next(i, nxt);
    }
    dbl.build();
    int q; cin >> q;
    while (q--) {
        int a, b; cin >> a >> b; a--, b--;
        cout << dbl.lower_bound(a, b) << endl;
    }
    return 0;
}

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

int linearSearch(int * ,int, int);

int main(){

  int i,count=0;
  int insertNumber1,insertNumber2,*S,*T;

  scanf("%d",&insertNumber1);
  S=(int *) malloc(sizeof(int)*insertNumber1);
  for(i=0;i<insertNumber1;i++) scanf("%d",&S[i]);
  scanf("%d",&insertNumber2);
  T= (int *) malloc(sizeof(int)*insertNumber2);
  for(i=0;i<insertNumber2;i++) {
    scanf("%d",&T[i]);
  }

  for(i=0;i<insertNumber2;i++) {
    count+=linearSearch(S,T[i],insertNumber1);
  }

  printf("%d\n",count);

  return 0;
}
int linearSearch(int *S,int key,int insertNumber){

  int i=0;
  S[insertNumber]=key;
  while(S[i]!=key){
    i++;
    if(i==insertNumber) return 0;
  }

  return 1;
}

Measured memory_bytes: 632
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int m = sc.nextInt();
    int[] mList = new int[m];
    for (int i = 0; i < n; i++) {
      int k = sc.nextInt();
        for (int j = 0; j < k; j++) {
          int a = sc.nextInt();
          mList[a - 1]++;
        }
    }
    int count = 0;
    for (int mm : mList) {
      if (mm == n) {
        count++;
      }
    }
    System.out.print(count);
  }
}

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

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	double cnt=0;
	vector<double>v(3);
	for(int i=0;i<3;i++)cin>>v.at(i);
	sort(v.begin(),v.end(),greater<double>());
	cnt+=v.at(0)-v.at(1);
	v.at(2)+=cnt;
	cnt+=(v.at(0)-v.at(2))/2;
	if(fmod((v.at(0)-v.at(2)),2)!=0){
		cnt+=2;
	}
	cout<<floor(cnt)<<endl;
}


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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;

int n, m;
vector<int> pathes[100200];
int q;
int a[100200], b[100200], v[100200], d[100200], c[100200];
int colors[100200];
int painted[100020];

void paint(int from, int distance, int color){
    if(distance <= painted[from]){
        return;
    }
    painted[from] = distance;
    if(colors[from] == 0){
        colors[from] = color;
    }
    if(distance == 0){
        return;
    }
    for(int i = 0; i < pathes[from].size(); i++){
        paint(pathes[from][i], distance - 1, color);
    }
    return;
}
int main() {
    //cout.precision(10);
    cin >> n >> m;
    for(int i = 1; i <= m; i++){
        cin >> a[i] >> b[i];
        pathes[a[i]].push_back(b[i]);
        pathes[b[i]].push_back(a[i]);
    }
    for(int i = 1; i <= n; i++){
        colors[i] = 0;
        painted[i] = -1;
    }
    cin >> q;
    for(int i = q; i >= 1; i--){
        cin >> v[i] >> d[i] >> c[i];
    }
    for(int i = 1; i <= q; i++){
        paint(v[i],  d[i], c[i]);
    }
    for(int i = 1; i <= n; i++){
        cout << colors[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 9208
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<vector>
#include<set>
#include<queue>
#include<iostream>
#include<map>
#include<cstring>
#define INF 0x3f3f3f3f
#define eps 1e-10
using namespace std;
set<int> groupc;
int n,m,root[200005],sizex[200005],a,b,ans;
int find(int x){
    if(root[x]==x)
        return x;
    return root[x]=find(root[x]);
}
bool same(int x,int y){
    return find(x)==find(y);
}
void merge(int x,int y){
    x=find(x);
    y=find(y);
    if(sizex[x]<sizex[y])
        swap(x,y);
    sizex[x]+=sizex[y];
    root[y]=x;
}
int main(){
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++){
        root[i]=i;
        sizex[i]=1;
    }
    for(int i=1;i<=m;i++){
        scanf("%d%d",&a,&b);
        if(!same(a,b))
            merge(a,b);
    }
    for(int i=1;i<=n;i++){
        groupc.insert(find(i));
    }
    for(auto e:groupc){
        ans=max(sizex[e],ans);
    }
    printf("%d",ans);
}

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

void printArray(int A[], int N)
{
    for (int i = 0; i < N; i++) {
        cout << A[i];
        if (i != N - 1) {
            cout << ' ';
        }
    }
    cout << endl;
}
int main() {
    int N, M, a, b;
    int C[100000] = {};
    cin >> N >> M;
    for (int i = 0; i < M; i++) {
        cin >> a >> b;
        C[a - 1]++;
        C[b - 1]++;
    }
    for (int i = 0; i < N; i++) {
        if (C[i] % 2 == 1) {
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;
    return 0;
}


Measured memory_bytes: 640
N = int(input())
numMap = {}
answer = 0
def StartEnd(x):
    start = str(x)[0]
    end = str(x)[-1]
    return start, end

for i in range(1, N+1):
    # print('numMap:', numMap)
    pair = StartEnd(i)
    if pair in numMap:
        numMap[pair] += 1
    else:
        numMap[pair] = 1

for i in range(1, N+1):
    key = StartEnd(i)
    rev = key[::-1]
    # print('rev:', rev)
    if rev in numMap:
        answer += numMap[rev]
    
print(answer)    



Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
vector<int> e[200010];

pair<int, int> tddfs(int v, int par = -1) {
  pair<int, int> ret = {0, v};
  for (auto &x : e[v]) {
    if (x == par) continue;
    auto r = tddfs(x, v);
    ret = max(ret,  {1+r.first, r.second});
  }
  return ret;
}

int main() {
    int n; cin >> n;
    for (int i = 0; i < n-1; i++) {
        int u, v; cin >> u >> v;
        u--; v--;
        e[u].emplace_back(v);
        e[v].emplace_back(u);
    }
    auto c = tddfs(0);
    auto w = tddfs(c.second);
    if (w.first%3 == 1) cout << "Second" << endl;
    else cout << "First" << endl;
    return 0;
}

Measured memory_bytes: 23680
//#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 rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
const int INF = 100010001;
const ll LINF = (ll)INF*INF*10;

void exi() {cout << "No" << endl;}

int main() {
    int n;
    cin >> n;
    ll a[3];
    cin >> a[0] >> a[1] >> a[2];
    vs s(n);
    rep(i, n) {
        cin >> s[i];
        rep(j, 2) {
            s[i][j] -= 'A';
        }
    }

    if(!a[s[0][0]] and !a[s[0][1]]) {
        exi();
        return 0;
    }
    vi ans;
    if(a[0] + a[1] + a[2] == 1) {
        rep(i, n) {
            if(a[s[i][0]] == 0 and a[s[i][1]] == 0) {
                exi();
                return 0;
            }
            if(a[s[i][0]]) {
                a[s[i][0]] = 0;
                a[s[i][1]] = 1;
                ans.push_back(s[i][1]);
            } else {
                a[s[i][1]] = 0;
                a[s[i][0]] = 1;
                ans.push_back(s[i][0]);
            }
        }
    } else {
        rep(i, n) {
            if(!a[s[i][0]]) {
                a[s[i][0]]++;
                a[s[i][1]]--;
                ans.push_back(s[i][0]);
            } else if(!a[s[i][1]]) {
                a[s[i][0]]--;
                a[s[i][1]]++;
                ans.push_back(s[i][1]);
            } else {
                if(i != n-1) {
                    if(s[i+1][0] == s[i][0] or s[i+1][1] == s[i][0]) {
                        a[s[i][0]]++;
                        a[s[i][1]]--;
                        ans.push_back(s[i][0]);
                    } else {
                        a[s[i][0]]--;
                        a[s[i][1]]++;
                        ans.push_back(s[i][1]);
                    }
                } else {
                    ans.push_back(s[i][0]);
                }
            }
        }
    }
    cout << "Yes" << endl;
    rep(i, n) {
        cout << char(ans[i]+'A') << endl;
    }
}

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

#define long long long int
using namespace std;

// @author: pashka

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

    int n, m;
    cin >> n >> m;
    vector<vector<bool>> a(n + 2, vector<bool>(m + 2));
    for (int i = 0; i < n; i++) {
        string s;
        cin >> s;
        for (int j = 0; j < m; j++) {
            if (s[j] == '.') {
                a[i + 1][j + 1] = true;
            }
        }
    }

    int res = 0;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            if (!a[i + 1][j + 1]) continue;
            vector<vector<int>> d
                    (n, vector<int>(m, INT_MAX));
            d[i][j] = 0;
            vector<pair<int, int>> q;
            q.emplace_back(i, j);
            for (int k = 0; k < q.size(); k++) {
                auto p = q[k];
                int x = p.first;
                int y = p.second;

                res = max(res, d[x][y]);

                vector<int> dx = {-1, 0, 0, 1};
                vector<int> dy = {0, -1, 1, 0};
                for (int dir = 0; dir < 4; dir++) {
                    int xx = x + dx[dir];
                    int yy = y + dy[dir];
                    if (a[xx + 1][yy + 1] &&
                        d[xx][yy] == INT_MAX) {
                        d[xx][yy] = d[x][y] + 1;
                        q.emplace_back(xx, yy);
                    }
                }
            }
        }
    }

    cout << res << "\n";


    return 0;
}

Measured memory_bytes: 256
import java.util.*;
    public class Main {
    	public static void main(String[] args) {
    		Scanner sc = new Scanner(System.in);
    		long x = Long.parseLong(sc.next());
    		long a = x/11;
    		long b = x%11;
    		if(b == 0)
    			System.out.println(String.valueOf(a*2));
    		else if(b <= 6)
    			System.out.println(String.valueOf(a*2 + 1));
    		else
    			System.out.println(String.valueOf(a*2 + 2));
    	}
    }

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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit32(x) (1 << (x))
#define bit64(x) (1ll << (x))
#define sz(v) ((int) v.size())

using namespace std;

using i64 = long long;
using f80 = long double;
using vi32 = vector<int>;
using vi64 = vector<i64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << endl; exit(0); }
inline void no() { cout << "No" << endl; exit(0); }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> inline void amax(T &x, T y) { x = max(x, y); }
template <typename T> inline void amin(T &x, T y) { x = min(x, y); }
template <typename T> inline T exp(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { each(x, v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }

i64 dp[200001][3][2];

void solve() {
  int n;
  cin >> n;
  vi32 a(n);
  cin >> a;
  repc(i, n) rep(j, 3) rep(k, 2) {
    dp[i][j][k] = -1e18;
  }
  dp[0][1][0] = 0;
  rep(i, n) rep(j, 3) rep(k, 2) rep(l, 2) {
    if (dp[i][j][k] == -1e18) continue;
    if (k == 1 && l == 1) {
      continue;
    }
    if (i & 1) {
      if (l == 0) {
        if (j == 0) continue;
        amax(dp[i + 1][j - 1][0], dp[i][j][k]);
      } else {
        amax(dp[i + 1][j][1], dp[i][j][k] + a[i]);
      }
    } else {
      if (l == 0) {
        amax(dp[i + 1][j][0], dp[i][j][k]);
      } else {
        if (j == 2) continue;
        amax(dp[i + 1][j + 1][1], dp[i][j][k] + a[i]);
      }
    }
  }
  i64 ans = -1e18;
  rep(k, 2) amax(ans, dp[n][1][k]);
  cout << ans << endl;
}

Measured memory_bytes: 13484
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <iterator>
#include <cmath>
#include <deque> 

using namespace std;


int a, b, t;

int main()
{
	scanf("%d%d%d", &a, &b, &t);
	
	int times = t / a;
	int count = times * b;
	printf("%d\n", count);
	

	return 0;
}



Measured memory_bytes: 128
#include <list>
#include <cstdio>

int main()
{
	int n, v;

	char c[12];

	std::list<int> l;

	scanf("%d", &n);

	for (int i = 0; i < n; i++)
	{
		scanf("%s", c);

		if (c[0] == 'i')
		{
			scanf("%d", &v);

			l.push_front(v);
		}
		else if (c[6] == 'F')
		{
			l.pop_front();
		}
		else if (c[6] == 'L')
		{
			l.pop_back();
		}
		else
		{
			scanf("%d", &v);

			std::list<int>::iterator it = l.begin();

			std::list<int>::iterator end_it = l.end();

			while (it != end_it)
			{
				if (*it == v)
				{
					l.erase(it); break;
				}

				it++;
			}
		}
	}

	std::list<int>::iterator it = l.begin();

	std::list<int>::iterator end_it = l.end();

	printf("%d", *it);

	while (++it != end_it)
	{
		printf(" %d", *it);
	}

	printf("\n");

	return 0;
}

Measured memory_bytes: 33920