akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstdio>
#include<queue>
#include<vector>
#include<string.h>
#include<algorithm>
#include <cmath>
#include<map>

using namespace std;

long long i,j,k,n,m,N,M,ans,a,b,X[200001]={0};



int main()
{
  cin>>N;
  
  vector<long long> L(N+1),R(N+1);
  //map<long long ,long long> L,R;
  
  
  for(i=1;i<=N;i++)
  {
    cin>>j;
    L[i]=i-j;
    R[i]=i+j;
  }
  sort(L.begin(),L.end());
  sort(R.begin(),R.end());
  ans=0;
  
  i=1;
  j=1;
  while(i<=N && j<=N)
  {
    if(L[i]<R[j])
    {
      i++;
    }
    else if(L[i]>R[j])
    {
      j++;
    }
    else
    {
      
      for(n=i+1;n<=N;n++)
      {
        if(L[i]==L[n])
        {
          continue;
        }
        else
        {
          break;
        }
      }
      
      for(m=j+1;m<=N;m++)
      {
        if(R[j]==R[m])
        {
          continue;
        }
        else
        {
          break;
        }
      }
      
      ans+=(n-i)*(m-j);
      i=n;
      j=m;
      
    }
      
    
  }
  
  
  
  cout<<ans;
  
  
}

Measured memory_bytes: 6348
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <stack>
#include <set>
#include <queue>
#include <iomanip>
#include <math.h>

using namespace std;

long long mod = 1000000007;

long long binpow(long long x, long long k)
{
    if (k == 0)
    {
        return 1LL;
    }
    long long temp = binpow(x, k / 2);
    if (k % 2 == 1)
    {
        return (((temp * temp) % mod) * x) % mod;
    }
    else
    {
        return (temp * temp) % mod;
    }
}

long long modular_inverse(long long x)
{
    return binpow(x, mod - 2);
}

long long binomial(long long n, long long k)
{
    long long rez = 1;
    for (long long i = n - k + 1; i <= n; i++)
    {
        rez *= i;
        rez %= mod;
    }
    long long temp = 1;
    for (long long i = 1; i <= k; i++)
    {
        temp *= i;
        temp %= mod;
    }
    rez *= modular_inverse(temp);
    rez %= mod;
    return rez;
}

int main()
{
    vector<vector<int> > a(3, vector<int>(3));
    vector<vector<bool> > checked(3, vector<bool>(3, false));
    for (int i = 0; i < 3; i++)
    {
        for (int j = 0; j < 3; j++)
        {
            cin >> a[i][j];
        }
    }
    int n;
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        int b;
        cin >> b;
        for (int j = 0; j < 3; j++)
        {
            for (int k = 0; k < 3; k++)
            {
                if (a[j][k] == b)
                {
                    checked[j][k] = true;
                }
            }
        }
    }
    for (int i = 0; i < 3; i++)
    {
        if (checked[i][0] && checked[i][1] && checked[i][2])
        {
            cout << "Yes\n";
            return 0;
        }
        else if (checked[0][i] && checked[1][i] && checked[2][i])
        {
            cout << "Yes\n";
            return 0;
        }
    }
    if (checked[0][0] && checked[1][1] && checked[2][2])
    {
        cout << "Yes\n";
        return 0;
    }
    else if (checked[0][2] && checked[1][1] && checked[2][0])
    {
        cout << "Yes\n";
        return 0;
    }
    cout << "No\n";
    return 0;
}


Measured memory_bytes: 256
h, w = map(int, input().split())
sw = [list(input()) for _ in range(h)]

result = [[10**5 for i in range(w)] for j in range(h)]
result[0][0] = 0
for i in range(h):
    for j in range(w):
        if j > 0:
            result[i][j] = result[i][j-1]+(sw[i][j-1]!=sw[i][j])
        if i > 0:
            result[i][j] = min(result[i][j], result[i-1][j]+(sw[i-1][j]!=sw[i][j]))


if sw[0][0]=="#":
    print(1+result[h-1][w-1]//2)
else:
    print(result[h-1][w-1]//2+(sw[0][0]!=sw[h-1][w-1]))

Measured memory_bytes: 3188
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long int ll;
int main()
{
    ll a[200009],b[200009];
    int n,m;
    cin>>n>>m;
    ll k;
    cin>>k;
    for(int i=1;i<=n;i++) cin>>a[i];
    for(int i=1;i<=m;i++) cin>>b[i];
    a[0]=0;
    b[0]=0;
    for(int i=1;i<=n;i++) a[i]=a[i]+a[i-1];
    for(int i=1;i<=m;i++) b[i]=b[i]+b[i-1];
    ll ans=0;
    for(ll i=0;i<=n;i++)
    {
       if(k>=a[i]) ans= max(ans, (ll)(i+(upper_bound(b+1,b+m+1,k-a[i])-b)-1));
    }
    cout<<ans;
}


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

using namespace std;
using ll = long long;
using pi = pair<int, int>;
using vi = vector<int>;

const ll linf = 1LL << 62;
const int inf = 99999999;
const int dx[4] = { 1,0,-1,0 };
const int dy[4] = { 0,1,0,-1 };
const ll atcoder = 1e9 + 7;

#define Endl endl
#define mp make_pair
#define all(v) v.begin(),v.end()
#define pb push_back
#define pr(x) cout << x << endl
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
#define rep(i,n) for(int i= 0;i<n;i++)
#define FOR(i,a,b) for(int i = a;i<b;i++)

template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T &val) {
	std::fill((T*)array, (T*)(array + N), val);
}

ll gcd(ll a, ll b) {//最大公約数
	if (a < b)swap(a, b);
	if (a%b == 0)return b;
	else gcd(b, a%b);
}

ll lcm(ll a, ll b) {//最小公倍数
	if (a < b)swap(a, b);
	return (a / gcd(a, b))*b;
}

int main() {

	string s;
	cin >> s;
	bool flag = false;


	rep(i, s.length()) {
		if (s[i] == 'C') {
			FOR(j, i, s.length())
				if (s[j] == 'F')flag = true;
		}
	}

	flag ? pr("Yes") : pr("No");

	//system("pause");
	return 0;
}



Measured memory_bytes: 256
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

public class Main {
	private static FastScanner sc = new FastScanner();

	public static void main(String[] args) {
		int n = sc.nextInt();
		
		int[] C = new int[10001];
		int[] A = new int[n+1];
		for(int i=1; i<=n; i++) {
			A[i] = sc.nextInt();
			C[A[i]]++;
		}
		
		for(int i=1; i<C.length; i++) {
			C[i] = C[i] + C[i-1];
		}
		
		int[] B = new int[n+1];
		for(int j=n; j>=1; j--) {
			B[C[A[j]]] = A[j];
			C[A[j]]--;
		}
		
		StringBuilder ans = new StringBuilder();
		for(int i=1; i<=n; i++) {
			if(i != 1) {
				ans.append(" ");
			}
			ans.append(B[i]);
		}
		System.out.println(ans);
	}
	
	static class FastScanner {
	    private final InputStream in = System.in;
	    private final byte[] buffer = new byte[1024];
	    private int ptr = 0;
	    private int buflen = 0;
	    private boolean hasNextByte() {
	        if (ptr < buflen) {
	            return true;
	        }else{
	            ptr = 0;
	            try {
	                buflen = in.read(buffer);
	            } catch (IOException e) {
	                e.printStackTrace();
	            }
	            if (buflen <= 0) {
	                return false;
	            }
	        }
	        return true;
	    }
	    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
	    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
	    private void skipUnprintable() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;}
	    public boolean hasNext() { skipUnprintable(); return hasNextByte();}
	    public String next() {
	        if (!hasNext()) throw new NoSuchElementException();
	        StringBuilder sb = new StringBuilder();
	        int b = readByte();
	        while(isPrintableChar(b)) {
	            sb.appendCodePoint(b);
	            b = readByte();
	        }
	        return sb.toString();
	    }
	    public long nextLong() {
	        return Long.parseLong(next());
	    }
	    public int nextInt(){
	    	return Integer.parseInt(next());
	    }
	}

}

Measured memory_bytes: 163144
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = (s); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) for(int i = (n); i >= 0; i--)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << '\n';
#define CFYN(n) cout << ( (n) ? "YES":"NO") << '\n';
#define OUT(n) cout << (n) << '\n';
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;

int main(void)
{
    IOS
    auto ketawa = [](const int x) {
        int ret = 0;
        string s = to_string(x);
        for (auto c:s) ret += c - '0';
        return ret;
    };

    int N; cin >> N;
    int ans = 1<<30;
    FOR(i,1,N/2+1) ans = min(ans,ketawa(i)+ketawa(N-i));

    cout << ans << '\n';

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
static const int LENGTH_MAX = 100;

void print_array(int array[], int size) {
  for (int i = 0; i < size; i++) {
    printf("%d", array[i]);

    if (i != size -1) {
      printf(" ");
    }
  }

  printf("\n");
}

void swap(int* val1, int* val2) {
  int tmp = *val1;
  *val1 = *val2;
  *val2 = tmp;
}

int main() {
  int array[LENGTH_MAX];
  int size;

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

  print_array(array, size);
  for(int i = 1; i < size; i++) {
    for(int j = i; j > 0; j--) {
      if (array[j - 1] <= array[j]) {
        break;
      }

      swap(&array[j -1], &array[j]);
    }

    print_array(array, size);
  }
}



Measured memory_bytes: 2748
#include<iostream>
#include<cmath>
#include<string>
using namespace std;

int main() {
   string s;
   long long int k;
   cin >> s >> k;
/*
   for (int i = 0; i < s.size(); i++) {
      cout << std::stoi(s[i]) << endl;
      // k -= std::pow(temp, 5e15);
   }
*/

   for (int i = 0; i < s.size(); i++) {
      if (s[i] == '1') {
         k -= 1;
         if (k == 0) {
            cout << s[i] << endl;
            break;
         }
      }
      else { 
         cout << s[i] << endl;
         break;
      }
   }
/*
   if (s[0] == '1') {
      if (k == 1) cout << s[0] << endl;
      else cout << s[1] << endl;
   } else cout << s[0] << endl;
*/
   return 0;

}


Measured memory_bytes: 256
program Half_and_Half
    implicit none
    integer(4):: a,b,c
    integer(4):: x,y
    
    read*, a,b,c,x,y

    print*, min(x,y) * min(a+b, 2*c) + min(max((x-y)*a,(y-x)*b), abs(x-y)*2*c)

end program Half_and_Half

Measured memory_bytes: 384
#include<iostream>
#include<algorithm>
#include<map>
#include<vector>

using namespace std;

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

	sort(a,a + n);
	int t1 = a[n-1];
	int t2 = a[0];
	for(int i = 0; i < n-1; i++) {
		if(abs((t1+1) / 2 - a[i]) < abs((t1+1) / 2 - t2)) {
			t2 = a[i];
		}
	}
	if(t1 < t2) {
		int tmp = t1;
		t1 = t2;
		t2 = tmp;
	}
	cout << t1 << " " << t2 << endl;
	

	

	
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define uli unsigned long long int
#define INF 999999999999999999
#define rep(i,m,n) for(lli i = m;i < n;i++)
#define rrep(i,m,n) for(lli i=m-1;i>=n;i--)
#define pb(n) push_back(n)
#define UE(N) N.erase(unique(N.begin(),N.end()),N.end());
#define Sort(n) sort(n.begin(), n.end())
#define Rev(n) reverse(n.begin(),n.end())
#define Out(S) cout << S << endl
#define NeOut(S) cout << S
#define HpOut(S) cout << setprecision(25) << S << endl
#define Vec(K,L,N,S) vector<L> K(N,S)
#define DV(K,L,N,M,S) vector<vector<L>> K(N,vector<L>(M,S))
#define TV(K,L,N,M,R,S) vector<vector<vector<L>>> K(N,vector<vector<L>>(M,vector<L>(R,S)))
#define pint pair<lli,lli>
#define paf(L,R) pair<L,R>
#define mod 1000000007
#define MAX 5100000
#define ALL(a)  a.begin(),a.end()
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  lli A,B,C,D,E,F,N,M,K,L,X,Y,Z,H,W,sum=0,num=0,flag=0;string S,T;
  cin >> N >> M;
  //Scc-S*1+C*2orC*4
  if(2*N>M)Out(M/2);
  else{
    M-=2*N;
    Out(N+M/4);
  }
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
N = int, input()
num = str(N[1])
char_list = list(num)
sum = 0
for i in range(len(char_list)):
    sum += int(char_list[i])

if int(N[1]) % sum == 0:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 2940
a,b = gets,gets
dp = Array.new(a.size){Array.new(b.size,0)}
(a.size).times { |i| dp[i][0]=i }
(b.size).times { |i| dp[0][i]=i }
(a.size-1).times { |i|
	(b.size-1).times{ |j|
		dp[i+1][j+1] = (a[i]==b[j]?dp[i][j]:[dp[i][j],dp[i+1][j],dp[i][j+1]].min+1)
	}
}
puts dp[a.size-1][b.size-1]

Measured memory_bytes: 16604
#include <iostream>
#include <fstream>
#include <typeinfo>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <iomanip>
#include <cctype>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<25;
const double pi=acos(-1);
const double eps=1e-8;
const vi emp;

int n;

int main(){
	cin>>n;
	int s;
	ll sum=0;
	for(int i=0;i<n;i++){
		cin>>s;
		sum+=s;
	}
	cout<<sum/n<<endl;
}

Measured memory_bytes: 1156
#include <iostream>
#include "bits/stdc++.h"
using namespace std;
#define print(x) cout<<x<<endl;
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define REP(i,a) for(ll i=0;i<a;i++)
#define jkl ll debug = 0;
#define RREP(i,a) for(ll i=a-1;i>=0;i--)
#define rrep(i,a,b) for(ll i=a-1;i>=b;i--)
#define printall(n,array) {for(ll i=0;i<n;i++){cout<<array[i]<<" ";}cout<<endl;}
#define U() cout<<endl;
#define mp make_pair
typedef long long ll;
typedef pair<ll, ll> Pi;
typedef pair<ll, Pi> V;
typedef vector<ll> VE;
const ll mod = 1e9 + 7; //10^9+7

int main(){
    int n, a, b;
    int p[102];
    int lea=0, beab=0, gtb=0;
    cin >> n;
    cin >> a >> b;
    REP(i, n)cin >> p[i];
    REP(i, n){
        if(p[i] <= a)lea++;
        else if(p[i] > a && p[i] <= b)beab++;
        else if(p[i] > b)gtb++;
    }
    int ans = min(min(lea, beab), gtb);
    print(ans);
}

Measured memory_bytes: 256
r, c = map(int, input().strip().split())

maze = [["#"] * (c + 2)] + [list("#" + input().strip() + "#") for _ in range(r)] + [["#"] * (c + 2)]

points = sum(row.count(".") for row in maze)

def BFS_maze(maze, start_pos, goal_pos, symbol_wall):
    sr, sc = start_pos
    maze[sr][sc] = symbol_wall
    queue = [(sr, sc)]

    gr, gc = goal_pos
    maze[gr][gc] = "g"

    depth = 0
    nextqueue = []

    while queue:
        depth += 1
        for pos in queue:
            posr, posc = pos
            for r, c in zip([1, -1, 0, 0], [0, 0, 1, -1]):
                nextr = posr + r
                nextc = posc + c
                terrein = maze[nextr][nextc]
                if terrein == "g":
                    return depth
                elif terrein == symbol_wall:
                    continue
                else:
                    maze[nextr][nextc] = symbol_wall
                    nextqueue.append((nextr, nextc))
        queue = nextqueue[:]
        nextqueue.clear()
    return -1

path_length = BFS_maze(maze, (1, 1), (r, c), "#")
print(-1 if path_length == -1 else points - path_length - 1)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define MOD 1000000007
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
using P = pair<int,int>;

int main()
{
  int N;
  cin >> N;
  vector<int> A(N);
  REP(i, N) cin >> A[i];
  
  sort(ALL(A));
  int MIN = INF;
  FOR(i,A[0],A[N-1]+1){
    int sum = 0;
    REP(j,N){
      sum+=(i-A[j])*(i-A[j]);
    }
    MIN = min(MIN,sum);
  }

  cout << MIN << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); i++)
#define RREP(i, s, n) for (int i = s; i < (n); i++)
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.rbegin(), a.rend()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using namespace std;
using ll = long long;
typedef pair<int, int> pint;
typedef pair<ll, ll> pll;
const ll MOD = 1000000007;
const ll INF = MOD * MOD;
const int inf = (1<<29);

int main() {

    int n, m;
    cin >> n >> m;
    vector<int> a(m);
    REP(i, m) cin >> a[i];
    
    int sum = 0;
    REP(i, m) sum += a[i];

    if (sum > n) {
        cout << -1 << endl;
        
    } else {
        cout << n - sum << endl;
        
    }


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

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

using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    char a,b;cin>>a>>b;
    if (a=='H'){
        cout<<b;
    }else {
        if (b=='H'){
            cout<<a;
        }else cout<<'H';
    }
    return 0;
}

Measured memory_bytes: 256
/*
    -ensure correct output format
    -ensure printing required output
    -reread the problem statement
  */

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll>pll;
typedef pair<ll,pair<ll,ll>>plll;
#define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL));
#define vll(v) v.begin(),v.end()
#define all(x) x.rbegin(),x.rend()
#define min3(a, b, c)   min(a, min(b, c))
#define max3(a, b, c)   max(a, max(b, c))
#define F first
#define S second
#define in  freopen("input.txt", "r", stdin)
#define out  freopen("output.txt", "w", stdout)
#define minheap int,vector<int>,greater<int>
#define pb push_back
#define eb emplace_back
#define ischar(x)  (('a' <= x && x <= 'z') || ('A' <= x && x <= 'Z'))
#define isvowel(ch) ((ch=='a'||ch=='e'||ch=='i'||ch=='o'||ch=='u')||(ch=='A'|| ch=='E' || ch=='I'|| ch=='O'|| ch=='U'))
#define bug cout<<"BUG"<<endl;
const int Max = 2e6 + 10;
const int Mod = 1e9 + 7;
const double PI  =3.141592653589793238463;
bool compare(const pair<ll,ll> &a, const pair<ll,ll> &b)
{
    return (a.first > b.first);
}
ll lcm(ll a,ll b)
{
    if(a==0 || b==0)return 0;

    return a/__gcd(a,b)*b;
}

void input(ll ara[],ll n)
{
    for(ll i=0; i<n; i++)cin>>ara[i];
}
void print(ll ara[],ll n)
{
    for(ll i=0; i<n; i++)
        cout<<ara[i]<<" ";
    cout<<endl;
}


char ara[1002][1002];

ll dis[1002][1002];

ll r[]= {1,0,0,-1};

ll c[]= {0,1,-1,0};

int main()
{

    fastread();

    ll i,j,n,m,p,a,sum=0,k,t,b,d,cnt=0,l;

    bool flag=false;

    string str;


    cin>>n>>m;

    pll s,e;

    cin>>s.F>>s.S>>e.F>>e.S;

    for(i=1; i<=n; i++)
    {
        for(j=1; j<=m; j++)
        {
            cin>>ara[i][j];

            dis[i][j]=1e9;
        }
    }

   priority_queue<plll, vector<plll>,greater<plll> > q;


    q.push({0,{s.F,s.S}});
    dis[s.F][s.S]=0;


    while(!q.empty())
    {
        auto ps=q.top();

        auto u=ps.S;

        d=dis[u.F][u.S];

        q.pop();

        if(u.F==e.F && u.S==e.S)continue;


        for(ll p=0; p<4; p++)
        {
            i=u.F+r[p];
            j=u.S+c[p];

            if(i>0 && j>0 && i<=n && j<=m && ara[i][j]=='.' && d<dis[i][j])
            {
                dis[i][j]=d;
                q.push({d,{i,j}});
            }

        }


        for(i=u.F-2; i<=u.F+2; i++)
        {
            for(j=u.S-2; j<=u.S+2; j++)
            {
                if(i==u.F && j==u.S)continue;

                if(i>0 && j>0 && i<=n && j<=m && ara[i][j]=='.' && d+1<dis[i][j])
                {
                    dis[i][j]=d+1;
                    q.push({d+1,{i,j}});
                }
            }
        }
    }

    if(dis[e.F][e.S]==1e9)dis[e.F][e.S]=-1;

    cout<<dis[e.F][e.S]<<endl;
}



Measured memory_bytes: 12604
from collections import Counter
mod = 1000000007


def inverse(a):
    return pow(a, mod - 2, mod)


def usearch(x, a):
    lft = 0
    rgt = len(a) + 1
    while rgt - lft > 1:
        mid = (rgt + lft) // 2
        if a[mid] <= x:
            lft = mid
        else:
            rgt = mid
    return lft


def main():
    n = int(input())
    s =input()
    frac = [1] * (n+1)
    for i in range(n):
        frac[i+1] = frac[i] * (i+1) % mod
    cnt = [0, 1]
    f = 0
    a = [0] * (2* n)
    a[-1] = 1
    for i in range(2*n-1):
        a[i] = f
        if s[i] == s[i+1]:
            f ^= 1

    ans = 1
    tmp = 0
    for i in range(2*n):
        if a[i] == 0:
            tmp += 1
        else:
            ans *= tmp
            ans %= mod
            tmp -= 1

    if len([i for i in a if i == 0]) == n and s[0] == s[-1] == 'B':
        print(ans * frac[n] % mod)
    else:
        print(0)

main()


Measured memory_bytes: 55776
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#pragma comment(linker, "/STACK:16777216")
#pragma warning( disable : 6031)
#include <climits>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <iostream>
#include <map>
#include <stack>
#include <set>
#include <queue>
#include <numeric>
#include <algorithm>
#include <utility>
#include <bitset>
#include <cmath>
#include <sstream>
#include <functional>
#include <iomanip>
#include <limits>

#define all(a) (a).begin(),(a).end()
#define sz(a) (int)(a).size()
#define eps (1e-9)
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector< vi > vvi;
typedef vector<double> vd;
typedef vector< vd > vvd;
typedef vector< string > vs;
typedef pair< int, int > pii;
typedef vector< pii > vpii;
typedef tuple<int, int, int> tiii;
const long long inf = 1e12;



int main()
{
#ifdef LOCAL_MACHINE
	freopen("input.txt", "rt", stdin);
	freopen("output.txt", "wt", stdout);
#endif
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); cout << setprecision(18) << fixed;
	const long long mod = 1e9 + 7;
	int n, k;
	cin >> n >> k;
	vector<vector<long long>> bc(n + 1, vector<ll>(k + 1));
	for (int i = 0; i <= n; i++)
		for (int j = 0; j <= min(i, k); j++)
		{
			if (j == 0 || j == i)
				bc[i][j] = 1;
			else
				bc[i][j] = (bc[i - 1][j - 1] + bc[i - 1][j]) %mod;
		}
	for (int i = 1; i <= k; i++)
	{
		cout << bc[n - k + 1][i] * bc[k - 1][i - 1] % mod << endl;
	}

	return 0;
}

Measured memory_bytes: 31616
import math
import os
import sys
from collections import Counter
from functools import reduce

from operator import mul

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7

N, M = list(map(int, sys.stdin.readline().split()))


def get_factors(n):
    """
    素因数分解
    :param int n:
    :rtype: list of int
    """
    if n <= 1:
        return []

    ret = []
    while n > 2 and n % 2 == 0:
        ret.append(2)
        n //= 2
    i = 3
    while i <= math.sqrt(n):
        if n % i == 0:
            ret.append(i)
            n //= i
        else:
            i += 2
    ret.append(n)
    return ret


def ncr(n, r, mod=None):
    """
    scipy.misc.comb または scipy.special.comb と同じ
    組み合わせの数 nCr
    :param int n:
    :param int r:
    :param int mod: 3 以上の素数であること
    :rtype: int
    """
    if n < r:
        return 0
    r = min(n - r, r)
    if r == 0:
        return 1
    return reduce(mul, range(n, n - r, -1)) // reduce(mul, range(r, 0, -1))


factors = get_factors(M)

ans = 1
for c in Counter(factors).values():
    # N 個の箱から重複ありで c 個選ぶ
    ans = ans * ncr(N + c - 1, c) % MOD
print(ans)


Measured memory_bytes: 3808
s = input()
t = input()
 
ans = 0
 
for i in range(len(s) - len(t) + 1):
  count = 0
  for j in range(len(t)):
    if s[i + j] == t[j]:
      count += 1
 
  if ans <= count:
    ans = count
print(len(t) - ans)

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

using namespace std;

vector<long int> a;
long int x,y;
long int sum;
long long int n;

int main(){
  long int temp;

  cin >> n;
  for( int i = 0; i < n; ++i){
    cin >> temp;
    a.push_back(temp);
  }
  sum = 0;
  for( auto i : a){
    sum += i;
  }
  x = 0;
  y = 0;
  long int min = 1000000000000000;
  for( int i = 0;  i < n-1; ++i){
    x += a[i];
    y = sum - x;
    if( min > labs(y-x) ){
      min = labs(y-x);
    }
  }
  cout << min << endl;
  
}


Measured memory_bytes: 2420
n = int(input())
f = list()
def dfs(k, a):
  if not k:
    f.append(a)
    return
  if not a:
    for i in range(10):
      dfs(k-1, i)
    return 
  t = a % 10
  dfs(k-1, a*10 + t)
  if t: dfs(k-1, a*10 + t - 1)
  if t < 9: dfs(k-1, a*10 + t + 1)
  return

dfs(11, 0)
f.sort()
print(f[n])

Measured memory_bytes: 28800
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#define int long long
using namespace std;
signed main() {
	vector<int>v;
	int n; cin >> n;
	for (int i = 0; i < n; i++) {
		int a, b;
		cin >> a;
		if (a == 0) {
			cin >> b;
			v.push_back(b);
		}
		else if (a == 1) {
			cin >> b;
			cout << v[b] << endl;
		}
		else {
			v.pop_back();
		}
	}
	return 0;
}


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

using namespace std;

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

#define F first
#define S second
#define PB push_back
#define MK make_pair
#define REP(i, a, b) for (int i=a; i < b; i++)


bool sort_by(pi c, pi d){
	return c.S < d.S;
}

int main() {
	int n, ans, tmp;
	
	cin >> n >> ans;
	REP(i, 1, n){
		cin >> tmp;
		ans = __gcd(ans, tmp);
	}
	cout << ans;

}


Measured memory_bytes: 256
s = input()

def check(s):
  if len(s) == 1 or len(s) == 0:
    return True
  if s[0]!=s[-1]:
    return False
  return check(s[1:-1])

mid = len(s)//2

if check(s) and check(s[0:mid]) and check(s[mid+1:]):
  print("Yes")
else:
  print("No")


Measured memory_bytes: 2940
import java.util.*;
import java.io.*; 
import java.text.*;
//Solution Credits: Taranpreet Singh
public class Main{
    //SOLUTION BEGIN
    void solve(int TC) throws Exception{
        int n = ni();
        for(int i = 111; i<= 999; i+=111)if(i>=n){
            pn(i);break;
        }
    }
    //SOLUTION ENDS
    long mod = (int)1000000001, IINF = (long)1e14;
    final int MAX = (int)1e6+1, INF = (int)1e14, root = 3;
    DecimalFormat df = new DecimalFormat("0.00000000000");
    double PI = 3.141592653589793238462643383279502884197169399375105820974944, eps = 1e-8;
    static boolean multipleTC = false, memory = true;
    FastReader in;PrintWriter out;
    void run() throws Exception{
        in = new FastReader();
        out = new PrintWriter(System.out);
        int T = (multipleTC)?ni():1;
        //Solution Credits: Taranpreet Singh
        for(int i = 1; i<= T; i++)solve(i);
        out.flush();
        out.close();
    }
    public static void main(String[] args) throws Exception{
        if(memory)new Thread(null, new Runnable() {public void run(){try{new Main().run();}catch(Exception e){e.printStackTrace();}}}, "1", 1 << 28).start();
        else new Main().run();
    }
    long gcd(long a, long b){return (b==0)?a:gcd(b,a%b);}
    int gcd(int a, int b){return (b==0)?a:gcd(b,a%b);}
    int bit(long n){return (n==0)?0:(1+bit(n&(n-1)));}
    void p(Object o){out.print(o);}
    void pn(Object o){out.println(o);}
    void pni(Object o){out.println(o);out.flush();}
    String n(){return in.next();}
    String nln(){return in.nextLine();}
    int ni(){return Integer.parseInt(in.next());}
    long nl(){return Long.parseLong(in.next());}
    double nd(){return Double.parseDouble(in.next());}

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

        public FastReader(String s) throws Exception{
            br = new BufferedReader(new FileReader(s));
        }

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

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

Measured memory_bytes: 25172
#include <stdio.h>

int abs(int a, int b){
  return a>b? a-b: b-a;
}

int main(void){
  int a[3];
  int sum[6];
  int i;
  int tmp = 200000;

  scanf("%d",&a[0]);
  scanf("%d",&a[1]);
  scanf("%d",&a[2]);

  /*
  012
  021
  102
  120
  201
  210
  */
  sum[0] = abs(a[0], a[1]) + abs(a[1], a[2]);
  sum[1] = abs(a[0], a[2]) + abs(a[2], a[1]);
  sum[2] = abs(a[1], a[0]) + abs(a[0], a[2]);
  sum[3] = abs(a[1], a[2]) + abs(a[2], a[0]);
  sum[4] = abs(a[2], a[0]) + abs(a[0], a[1]);
  sum[5] = abs(a[2], a[1]) + abs(a[1], a[0]);
  for(i=0; i<6; i++){
    if(tmp > sum[i]) tmp = sum[i];
  }
  printf("%d\n", tmp);
}

Measured memory_bytes: 128
def main():
    (l, r) = list(map(int, input().split()))

    ans = 2020
    for i in range(l, min(r + 1, l + 2019)):
        for j in range(i + 1, min(r + 1, i + 2020)):
            mod = i * j % 2019
            if mod <= ans:
                ans = mod

    print(ans)

if __name__ == "__main__":
    main()


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

// template {{{  0 
// using {{{ 1
using ll = long long int;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vii = vector<pii>;
using vll = vector<pll>;
// }}} 1
// definition {{{ 1
// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x,y) scanf("%d%d", &x, &y)
#define Scd3(x,y,z) scanf("%d%d%d", &x, &y, &z)
#define Scll(x) scanf("%lld", &x)
#define Scll2(x,y) scanf("%lld%lld", &x, &y)
#define Scll3(x,y,z) scanf("%lld%lld%lld", &x, &y, &z)
#define Scc(c) scanf("%c", &c);
#define Scs(s) scanf("%s", s);
#define Scstr(s) scanf("%s", &s);
// }}} 2
// constants {{{ 2
#define EPS (1e-7)
#define INF (2e9)
#define PI (acos(-1))
// }}} 2
// systems {{{ 2
#define Repe(x,y,z) for(ll x = z; x < y; x++)
#define Rep(x,y) Repe(x,y,0)
#define RRepe(x,y,z) for(ll x = y-z-1; x >= 0; x--)
#define RRep(x,y) RRepe(x,y,0)
// }}} 2
// output {{{ 2
#define YesNo(a) (a)?printf("Yes\n"):printf("No\n")
#define YESNO(a) (a)?printf("YES\n"):printf("NO\n")
// }}} 2
// }}} 1
// input {{{ 1
// }}} 1
// }}} 0

int main() {

    int N;
    Scd(N);
    vii a(N);

    Rep(i,N){
        Scd2(a[i].first,a[i].second);
        a[i].first -= a[i].second;
        a[i].second =-a[i].second;
    }

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

    ll ans = 0;
    Rep(i,N){
        a[i].second =-a[i].second;
        if( a[i].first < 0 ) ans += a[i].second;
    }

    ll buy = 0;
    ll ign = INF;
    if( ans > 0 )
    Rep(i,N){
        if( a[i].first >= 0 ){
            buy += a[i].second;
            if( a[i].first > 0 )
            if( a[i].second < ign ){
                ign = a[i].second;
            }
        }
    }
    else ign= 0;

    printf ("%lld\n", ans + buy - ign );

    return 0;
}

/*
 *
 * 2
 * 101 102 // -1
 * 003 002 // +1
 *
 * 000 001 // -1
 * 003 002 // +1
 *
 * 000 000
 * 002 002
 * ans = 102
 *
 */



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

#define REPI(i, n) for(int i = 0; i < n; i++)
#define REPJ(j, n) for(int j = 0; j < n; j++)

using namespace std;

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

    int n, l; cin >> n >> l;
    string s[n];
    REPI(i, n){
        cin >> s[i];
    }

    sort(s, s + n);
    REPI(i, n){
        cout << s[i];
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int h, w;
  cin >> h >> w;
  vector<string> s(h);
  for (int i = 0; i < h; i++) {
    cin >> s[i];
  }
  vector<vector<int>> f(h, vector<int>(w));
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (i + j == 0) {
        f[0][0] = (s[0][0] == '#');
      } else {
        f[i][j] = (int) 1e9;
        if (i > 0) f[i][j] = min(f[i][j], f[i - 1][j] + (s[i - 1][j] == '.' && s[i][j] == '#'));
        if (j > 0) f[i][j] = min(f[i][j], f[i][j - 1] + (s[i][j - 1] == '.' && s[i][j] == '#'));
      }
    }
  }
  cout << f[h - 1][w - 1] << '\n';
  return 0;
}

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

struct Image {
	bool f;
	int len[10];
	int com[10];
};

int main()
{
	int n, m, tm, x, y, d, px, py, pd, j;
	Image images[51];

	while (cin >> n , n) {
		for (int i = 0; i <= n; i++) {
			cin >> tm;
			if (i == 0) m = tm;
			else {
				if (tm == m) images[i].f = true;
				else {
					images[i].f = false;
					for (j = 0; j < tm; j++) cin >> x >> y;
					continue;
				}
			} 
			for (j = 0; j < m; j++) {
				cin >> x >> y;
				if (j != 0) {
					d = (x == px ? y - py : x - px);
					images[i].len[j - 1] = abs(d);
					if (j == 1) {
						images[i].com[j - 1] = 0;
					} else if (x == px) {
						images[i].com[j - 1] = (pd * d > 0 ? 1 : -1);
					} else {
						images[i].com[j - 1] = (pd * d > 0 ? -1 : 1);
					}
				}
				px = x;
				py = y;
				pd = d;
			}
			images[i].com[j - 1] = 0;
		}
		m--;
		for (int i = 1; i <= n; i++) {
			if (!images[i].f) continue;
			
			for (j = 0; j < m; j++) {
				if (images[0].len[j] != images[i].len[j] ||
				 images[0].com[j] != images[i].com[j]) break;
			}
			if (j == m) {
				cout << i << endl;
				continue;
			}
			
			for (j = 0; j < m; j++) {
				if (images[0].len[j] != images[i].len[m - 1 - j] ||
				 images[0].com[j] != -images[i].com[m - j]) break;
			}
			if (j == m) {
				cout << i << endl;
				continue;
			}
		}
		cout << "+++++" << endl;
	}
	
	return 0;
}

Measured memory_bytes: 1160
#include <vector> 
#include <list> 
 #include <map>
 #include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//debug
#define dump(x)  cerr << #x << '=' << (x) << endl;
#define debug(x) cerr << #x << '=' << (x) << '('<<'L' << __LINE__ << ')' << ' ' << __FILE__ << endl;

int main(){
 
    int n;
    LL a0=2,a1=1;
    cin>>n;
    n-=1;
    REP(i,n){
        LL s=a1;
        a1=a0+a1;
        a0=s;
    }

    cout<<a1<<endl;



}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using datas=pair<ll,ll>;
using ddatas=pair<double,double>;
using tdata=pair<ll,datas>;
using vec=vector<ll>;
using mat=vector<vec>;
using pvec=vector<datas>;
using pmat=vector<pvec>;
#define For(i,a,b) for(i=a;i<(ll)b;i++)
#define bFor(i,a,b) for(i=a;i>=(ll)b;i--)
#define rep(i,N) For(i,0,N)
#define rep1(i,N) For(i,1,N)
#define brep(i,N) bFor(i,N-1,0)
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define vsort(v) sort(all(v))
#define vrsort(v) sort(allr(v))
#define endl "\n"
#define pb push_back
#define output(v) do{bool f=0;for(auto outi:v){cout<<(f?" ":"")<<outi;f=1;}cout<<endl;}while(0)
const ll mod=1000000007;
const ll inf=1LL<<60;
const double PI = acos(-1);
const double eps = 1e-9;
template<class T> inline bool chmax(T& a,T b){bool x=a<b;if(x)a=b;return x;} 
template<class T> inline bool chmin(T& a,T b){bool x=a>b;if(x)a=b;return x;} 

void startupcpp(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(15);
}

double distance(ddatas& x,ddatas& y){
  double a=x.first-y.first,b=x.second-y.second;
  return sqrt(a*a+b*b);
}

ll modinv(ll a) {
  ll b=mod,u=1,v=0,t;
  while(b){
    t=a/b;
    a-=t*b; swap(a,b);
    u-=t*v; swap(u,v);
  }
  return (u+mod)%mod;
}

ll moddevide(ll a,ll b){return (a*modinv(b))%mod;}

vec modncrlistp,modncrlistm;

ll modncr(ll n,ll r){
  ll i,size=modncrlistp.size();
  if(size<=n){
    modncrlistp.resize(n+1);
    modncrlistm.resize(n+1);
    if(!size){
      modncrlistp[0]=modncrlistm[0]=1;
      size++;
    }
    For(i,size,n+1){
      modncrlistp[i]=modncrlistp[i-1]*i%mod;
      modncrlistm[i]=modinv(modncrlistp[i]);
    }
  }
  return modncrlistp[n]*modncrlistm[r]%mod*modncrlistm[n-r]%mod;
}

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

ll gcd(ll a,ll b){if(!b)return a;return (a%b==0)?b:gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

ll countdigits(ll n){
  ll ans=0;
  while(n){n/=10;ans++;}
  return ans;
}

ll sumdigits(ll n){
  ll ans=0;
  while(n){ans+=n%10;n/=10;}
  return ans;
}
void judgement(int a){
  if(a){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
  if(a){
    cout<<"YES"<<endl;
  }else{
    cout<<"NO"<<endl;
  }
}

int main(){
  startupcpp();
  ll i,N;
  vec v(3);
  rep(i,3)cin>>v[i];
  vrsort(v);
  cout<<v[0]*10+v[1]+v[2]<<endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<queue>
#include<string>
#include<stack>
#include<cstdio>
#include<algorithm>
using namespace std;

int main(void)
{
  int a[10]={};
  int i=0;
  int j=0;

  for(i=0;i<10;i++)
    cin>>a[i];

  sort(a,a+10);

  cout<<a[9]<<endl<<a[8]<<endl<<a[7]<<endl;

}

Measured memory_bytes: 1176
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
#define rep1(i,n) for (int i = 1; i <= (n); i++)
#define repf(i,a,b) for (int i = (a); i < (b); i++)
#define repi(i,a,b) for (int i = (a); i <= (b); i++)
#define repr(i,a,b) for (int i = (a); i >= (b); i--)
#define all(x) (x).begin(),(x).end()
#define debug(x)  cout << #x << " = " << (x) << endl;
using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using vc = vector<char>;
using vvc = vector<vc>;
using vs = vector<string>;
using tiii = tuple<int, int, int>;

int main() {
  ll L, R;
  cin >> L >> R;
  
  R = min(R,L+4038);
  int ans = 2018;
  for (ll i = L; i <= R; i++) {
    for (ll j = i+1; j <= R; j++) {
      int x = i*j%2019;
      ans = min(ans, x);
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int a = scanner.nextInt();
		int b = scanner.nextInt();

		if(a*b % 2 == 1) {
			System.out.println("Odd");
		}else {
			System.out.println("Even");
		}
	}

}

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

int main(){
int m1,d1,m2,d2; cin >> m1 >> d1 >> m2 >> d2;
int ans=0;
if(m1!=m2) ans++;
cout << ans << endl;

return 0;
}


Measured memory_bytes: 256
import random

class Dice():
    def __init__(self):
        self.face = [i for i in range(6)]
        self.memo = [i for i in range(6)]

    def setface(self,initface):
        for i in range(6):
            self.face[i] = initface[i]

    def roll(self,direction):
        for i in range(6):
            self.memo[i] = self.face[i]
        index = {'E':(3,1,0,5,4,2),'N':(1,5,2,3,0,4),'S':(4,0,2,3,5,1),'W':(2,1,5,0,4,3)}
        for i in range(6):
            self.face[i] = self.memo[index[direction][i]]

    def top(self):
        return self.face[0]

n = int(input())
dice1 = Dice()
dice1.setface(list(map(int,input().split())))
flag = 0
for d in range(n-1):
    dicei = Dice()
    dicei.setface(list(map(int,input().split())))
    for i in range(1000):
        dicei.roll(['E','N','S','W'][random.randint(0,3)])
        for j in range(6):
            if dice1.face[j]!=dicei.face[j]:
                break
        else:
            if not flag:print('No' )
            flag = 1
            break
if not flag:
    print('Yes')


Measured memory_bytes: 8200
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <cmath>
#include <list>
#include <cassert>

using namespace std;

#define y1 roman_kaban
#define rank oryshych_konb
#define ull unsigned long long
const int mod = int(1e9) + 7;
const long long infLL = 2e18;
const int MX = 200105;


int main()
{
    //init();
    //cerr << delta << endl;
    //freopen("/Users/ozzy/Documents/in.txt","r", stdin);
    ios_base::sync_with_stdio(false);
    long long n;
    cin >> n;
    long long ans = n / 11;
    ans *= 2;
    n %= 11;
    if(n > 6) ans += 2; else
    if(n) ans++;
    cout << ans  << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,x;
	cin>>n>>x;
	int a[n];
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	int ans=0,mi=1000000000;
	for(int i=0;i<n;i++){
		x=x-a[i];
		ans++;
		mi=min(mi,a[i]);
	}
	ans=ans+x/mi;
	cout<<ans;
}

Measured memory_bytes: 256
def main():
    v,e,r=map(int,input().split())
    ans=[float('inf') for _ in range(v)]
    E = [tuple(map(int,input().split())) for _ in range(e)]
    ans[r]=0
    for i in range(v):
        update=False
        for s,t,c in E:
            if ans[t]>ans[s]+c:
                ans[t]=ans[s]+c
                update=True
        if not update:
            break
    for i in ans:
        if i==float('inf'):
            print("INF")
        else:
            print(i)
            
    
if __name__ == '__main__':
    main()


Measured memory_bytes: 96852
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main{
    public static int lis_dp(int[] num, int n){
        int[] length = new int[n];
        if (n == 1){
            return 1;
        }

        length[0] = 1;
        int maxLen = 1;
        for(int i = 1; i < n; i++){
            length[i] = 1;
            for(int j = 0; j < i; j++){
                if (num[i] > num[j]){
                    if (length[j] + 1 > length[i]){
                        length[i] = length[j] + 1;
                    }
                }
            }
            if (length[i] > maxLen)
                maxLen = length[i];
        }
        return maxLen;
    }
    public  static int bsearch(int target, int[] num, int n){
        int left = 0, right = n - 1;
        while(left <= right){
            int mid = (left + right) / 2;
            if (num[mid] > target){
                right = mid - 1;
            }else if(num[mid] < target){
                left = mid + 1;
            }else{
                return mid;
            }
        }
        return -left;
    }
    public static int lis_log(int[] num, int n){
        int[] b = new int[n];
        int bLen = 0;
        for(int i = 0; i < n; i++){
            int bIndex = bsearch(num[i], b, bLen);
            if (bIndex <= 0){
                if (-bIndex < bLen){
                    if(b[-bIndex] > num[i]){
                        b[-bIndex] = num[i];
                    }
                }else if(-bIndex == bLen){
                    b[bLen++] = num[i];
                }else{
                    // should not get here
                }
            }
        }
        return bLen;
    }
    public static void main(String[] args){
        int[] num = new int[100010];
        Scanner s = new Scanner(System.in);

        int n = 0;
        while(s.hasNext()){
            n = s.nextInt();
            int i = 0;
            while(s.hasNext()) {
                num[i++] = s.nextInt();
            }
        }
        int result = lis_log(num, n);
        System.out.println(result);
    }
}


Measured memory_bytes: 69424
#include<cstdio>

int a[2],sum;
char c,ct[2];

int main()
{
	do{
		c=getchar();
		if(ct[0]=='\000'||ct[0]==c)a[0]++,ct[0]=c;
		else if(ct[1]=='\000'||ct[1]==c)a[1]++,ct[1]=c;
		else if(c!='\n'){
			printf("No");
			return 0;
		}
	}while(c!='\n');
	if(a[0]==2&&a[1]==2)
		printf("Yes");
	else
		printf("No");
	return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
const int MAX=1e6;
int father[MAX],v[MAX],flag,t;
int find(int x)
{
    if(father[x]==x)return x;
    t=find(father[x]);
    v[x]+=v[father[x]];
    father[x]=t;
    return father[x];
}
void work(int x,int y,int w)
{
    int p=find(x),q=find(y);
    if(p!=q)
    {
        father[p]=q;
        v[p]=v[y]-v[x]-w;
    }
    else if(v[y]-v[x]!=w)flag=1;
}
int main()
{
    int w,n,m;
    memset(v,0,sizeof(v));
    flag=0;
    scanf("%d%d",&n,&m);
    for(int i=0; i<=n; i++)father[i]=i;
    for(int i=1; i<=m; i++)
    {
        int x,y,z;
        scanf("%d%d%d",&x,&y,&z);
        work(x,y,z);
    }
    if(flag)printf("No\n");
    else printf("Yes\n");
    return 0;
}


Measured memory_bytes: 6528
n, a, b, c, d = map(int,input().split())
s = input()
s = "." + s

def aa():
    for i in range(a, c):
        if s[i:i+2] == "##":
            return "No"
    for i in range(b, d):
        if s[i:i+2] == "##":
            return "No"
    if c > d:
        for i in range(b-1, d):
            if s[i:i+3] == "...":
                return "Yes"
        return "No"
    else:
        return "Yes"

print(aa())


Measured memory_bytes: 40816
#pragma region template
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const long long MOD = 1e9 + 7, MAX = 1e18, larg = 1e5, INF = -1e9;
long long A, B, C, D, E, F, G, H, I, J, K, L, N, M, O, P, Q, R, S, T, U, V, W, x, y, z;
long long max_value = INF, max_index = -1;
long long min_value = MAX, min_index = -1;
typedef long long ll;
typedef pair<ll, ll> Pa;

int main() {
	cin >> A >> B;
	ll curr = A;
	int cnt = 0;
	while(curr <= B){
		curr*=2;
		cnt++;
	}
	cout << cnt;
}

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

const int MAXN = 1e5 + 100 ; 
int l = 0 , r ; 
string s[MAXN] ; 

int main()
{
	cin >> r ; 

	cout << l << endl ; 
	cin >> s[l] ; 
	if(s[l] == "Vacant")
		return 0 ;  
	while(true)
	{
		int pos = (l+r)/2 ; 
		cout << pos << endl ; 
		cin >> s[pos] ; 
		if(s[pos] == "Vacant")
			return 0  ;
		if(s[pos] == s[l])
		{
			if((pos-l) %2 == 0)
				l = pos ; 
			else
				r = pos ; 
		}
		else
		{
			
			if((pos-l) %2 == 0)
				r = pos ; 
			else
				l = pos ; 
		}
		
	}
	
}

Measured memory_bytes: 1620
N = int(input())
L = [list(map(int,input().split())) for i in range(N)]

L = sorted(L, key=lambda x: x[1])

calc = 0

for i in range(len(L)) :
    A,B = L[i]
    calc += A
    if calc > B :
        ans = "No"
        break
else :
    ans = "Yes"

print(ans)


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

int main() {
  int N;
  cin >> N;
  int A[110];
  for (auto i = 0; i < N; i++) {
    cin >> A[i];
  }
  int ans = 0;
  for (auto i = 0; i < N; i++) {
    int minj = i;
    for (auto j = i; j < N; j++) {
      if (A[j] < A[minj]) {
        minj = j;
      }
    }
    if (i != minj) {
      swap(A[i], A[minj]);
      ans++;
    }
  }
  for (auto i = 0; i < N; i++) {
    cout << A[i];
    if (i != N-1) {
      cout << " ";
    } else {
      cout << endl;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3124