akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int MOD = 1000000007;
struct edge {int to,costa,costb;};

signed main() {
int n,m;
string s;
cin>>n>>s;
bool a[10]={},b[100]={},c[1000]={};
for(int i=0;i<n;i++){
m=s[i]-'0';
   
    for(int i=0;i<100;i++)if(b[i])c[i*10+m]=true;
     for(int i=0;i<10;i++)if(a[i])b[i*10+m]=true;
         a[m]=true;
}
int ans=0;
for(int i=0;i<1000;i++)if(c[i])ans++;
cout<<ans;

return 0;


}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <map>
#include <set>

#define FOR(idx, begin, end) for(int idx = (int)(begin); idx < (int)(end); ++idx)
#define DBG(x) cerr << #x << ": " << x << "\n"

using namespace std;
typedef long long lint;
const int MOD = 1000000007;


int main() {

	cin.tie(0);
	
	string S;
	cin >> S;
	
	vector<char> output;

	FOR(i,0,S.length()){
		if (S[i] == 'B') { if(!output.empty())output.erase(output.end()-1,output.end()); }
		else { output.emplace_back(S[i]); }
	}

	for (auto elem : output) cout << elem;

	return 0;
}

Measured memory_bytes: 256
def isCLKWISE(ph):
    a = ph[-1][0] - ph[-3][0]
    d = - ph[-3][1] + ph[-2][1]
    c = ph[-2][0] - ph[-3][0]
    b = - ph[-3][1] + ph[-1][1] 
    crs = a*d - b*c
    if crs < 0 : return False
    else : return True
     
def ConvexHullScan(P):
    P = sorted(P)
    phU = [P[0],P[1]]
    for p in P[2:]:
        phU.append(p)
        while(True):
            if isCLKWISE(phU) : break
            else :
                del phU[-2]
                if len(phU) == 2 : break
    phL = [P[-1],P[-2]]
    for p in P[-3::-1]:
        phL.append(p)
        while(True):
            if isCLKWISE(phL) : break
            else :
                del phL[-2]
                if len(phL) == 2 : break
    ph = phU + phL[1:-1]
    return ph
 
n = int(input())
P = []
for i in range(n):
    P.append([int(x) for x in input().split()])
     
Q = ConvexHullScan(P)
Q.reverse()
print(len(Q))
idx = min([[x[1][1],x[1][0],x[0]] for x in enumerate(Q)])[2]
R = Q[idx:] + Q[:idx]
for r in R:
    print(r[0],r[1])

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


int main()
{
 	char B;
	cin >> B;
	if (B == 'A'){
      cout << 'T' << endl;
    }
	if (B == 'T'){
      cout << 'A' << endl;
    }
  	if (B == 'G'){
      cout << 'C' << endl;
    }
	if (B == 'C'){
      cout << 'G' << endl;
    }

  
	return 0;
}

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

#define ll long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define uniqueV(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define debug3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define debugB(value, size) cerr<<#value<<": "<<bitset<size>(value) << endl;
#define line() cerr << "---------------" << endl;

const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, -1, 1};
const double PI = 3.14159265358979323846;

template<typename T>
void printA(vector<T> &printArray, char between = ' ') {
   int paSize = printArray.size();
   for (int i = 0; i < paSize; i++) { cerr << printArray[i] << between;}
   if (between != '\n') {cerr << endl;}
}

// ------------------------------------------------------------------------------------------

int N;
int F[111][11];
int P[111][11];

int main() {
   cin >> N;
   rep (i, N) {
      rep (j, 10) {
         cin >> F[i][j];
      }
   }
   rep (i, N) {
      rep (j, 11) {
         cin >> P[i][j];
      }
   }

   ll ans = -1e15;
   for (int mask = 1; mask < (1<<10); mask++) {
      ll sum = 0;
      for (int i = 0; i < N; i++) {
         int cnt = 0;
         for (int j = 0; j < 10; j++) {
            if (((mask>>j)&1) && F[i][j]) cnt++;
            // if ((mask>>j) && F[j][j])cnt++;
         }
         sum += P[i][cnt];
      }
      ans = max(ans, sum);
   }
   cout << ans << endl;

   return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define f first
#define s second
#define Fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define fo(a,b,c) for(int i=a;i<b;i+=c)  
typedef pair<ll , pair<ll, ll> > pi;
int pow(int x,int y){
    int res=1;
    while(y){
        if(y&1) res*=x;
        y>>=1;
        x*=x;
    }
    return res;
}   
struct Compare {
    constexpr bool operator()(pi const & a,
                              pi const & b) const noexcept
    { return a.first < b.first || (a.first == b.first && a.second.first > b.second.first); }
 
};
void prefix_function( string s,ll arr[] )
{
     long long border=0; arr[0]=0;
    for(long long i=1;i<s.size();i++)
    {
      while(border>0 && s[i]!=s[border])
        border=arr[border-1];
     
     if(s[i]==s[border])
         border++;
      else
       border=0;
      
      arr[i]=border;
    }
}
ll mod=998244353;
ll add( ll a , ll b)
{
    return (((a%mod)+(b%mod))%mod);
}
ll mul(ll a,ll b)
{
  return (((a%mod)*(b%mod))%mod);
}
//send mod-2 for a^-1 if mod is a prime number
ll binpow(ll a, ll b) {
    ll res = 1;
    while (b) {
        if (b & 1) res = mul(res, a);
        a = mul(a, a);
        b >>= 1;
    }
    return res;
}
ll dsu_arr[100000];
ll dsu_sz[100000];
void dsu(ll n)
{
    for(ll i=0;i<=n;i++)
    {
        dsu_arr[i]=i;
        dsu_sz[i]=1;
    }
}
ll find(ll x)
{
     ll root=x;
    while (root!=dsu_arr[root])
    {
        root=dsu_arr[root];
    }
    while(x!=dsu_arr[x])
    {
        dsu_arr[x]=root;
        x=dsu_arr[x];
    }
    return root;
}
ll merge(ll x,ll y)
{
    ll root1=find(x);
    ll root2=find(y);
    
    if(root1==root2)
    return 0ll;
 
    if(dsu_sz[x]>dsu_sz[y]){
    dsu_arr[root2]=root1;
    dsu_sz[x]+=dsu_sz[y];
    }
    else
    {
         dsu_sz[y]+=dsu_sz[x];
        dsu_arr[root1]=root2;
    }
    return 1ll;
}


int main()
{
    ll ans;
for(ll i=0;i<5;i++ )
{
    ll k;
    cin>>k;
    if(k==0)
    ans=i+1;
}

cout<<ans<<endl;
}



   
      
    
        



Measured memory_bytes: 3576
#include <iostream>
#include <string>
#include <cstdlib>
#include <vector>
#include <array>
#include <map>
#include <algorithm>
#include <queue>
#include <stack>
#include <cmath>

using namespace std;
typedef long long int ll;

int main(int argc, char const *argv[])
{
	vector<ll> v(5);
	for(int i = 0; i < 5;i++)
	{
		cin >> v[i];
	}
	ll k;
	cin >> k;
	ll ans = 0;	
	for(ll i = 0; i < 5 - 1; i++)
	{
		for(ll j = i; j < 5; j++)
		{
			if(v[j] - v[i] > k){
				cout << ":(" << endl;
				exit(0);
			}
		}
		
	}
	
	cout << "Yay!" << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main(void){
	char str[1001],buf[1001],bufr[1000],p[1001],command[10];
	int q,a,b,i,j;

	scanf("%s %d",str,&q);
	for(j=0;j<q;j++){
		scanf("%s %d %d",command,&a,&b);
		if(strcmp(command,"print")==0){
			for(i=0;i<1001;i++) buf[i]=NULL;
			strncpy(buf,str+a,b-a+1);
			printf("%s\n",buf);
		}
		else if(strcmp(command,"reverse")==0){
			for(i=0;i<1001;i++) buf[i]=NULL;
			strncpy(buf,str,a);
			for(i=0;i<1000;i++) bufr[i]=NULL;
			for(i=0;i<=b-a;i++) bufr[i]=str[b-i];
			strcat(buf,bufr);
			strcat(buf,str+b+1);
			strcpy(str,buf);
		}
		else if(strcmp(command,"replace")==0){
			scanf("%s",p);
			for(i=a;i<=b;i++) str[i]=p[i-a];
		}
	}
	return 0;
}

Measured memory_bytes: 612
#include <algorithm>
#include <bitset>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stdio.h>
#include <string>
#include <vector>

#define rep(i,n) for (int i = 0; i < (n); ++i)
#define M_PI 3.14159265358979
#define deg_to_rad(deg) (((deg)/360)*2*M_PI)
#define rad_to_deg(rad) (((rad)/2/M_PI)*360)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using LP = pair<ll, ll>;
const double PI = 3.1415926535897932;

/* a と b の最大公約数を返す関数 */
long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}


int main()
{
	int A, B;
	cin >> A >> B;

	int ans = A - B * 2;
	ans = max(ans, 0);

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


Measured memory_bytes: 3556
#include <iostream>
#include <fstream>
#include <string> 
#include <cmath>  
#include <cstdlib>
#include <ctime>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <set>
#include <functional>

using namespace std;
using ll = long long;

#define FOR(i, m, n) for(int i = (m);i < (n);i++)
#define REP(i,n) for(int i = 0; i < int(n); i++)
#define VI vector<int>
#define VVI vector<vector<int>>
#define VVVI vector<vector<vector<int>>>
#define VL vector<ll>
#define PAIR pair<int,int>
#define MP make_pair
#define VP vector<pair<int,int>>
#define VS vector<string>
#define PQUE priority_queue<int> //5,5,4,3,3,2,...
#define REPQUE priority_queue<int, vector<int>, greater<int>> //1,1,2,3,4,4,5,...
#define SUM(obj) accumulate((obj).begin(), (obj).end(), 0)
#define SORT(obj) sort((obj).begin(), (obj).end()) // 1,2,3,4,5...
#define RESORT(obj) sort((obj).begin(), (obj).end(), greater<int>()) // 5,4,3,2,1...
#define UB(obj,n) upper_bound((obj).begin(), (obj).end(), n) //itr > n
#define LB(obj,n) lower_bound((obj).begin(), (obj).end(), n) //itr>= n

const ll MOD = (ll)1e9 + 7;

int main() {
	int N, K;
	cin >> N >> K;
	VI x(N);
	REP(i, N)cin >> x[i];
	int c = 0;
	REP(i, N) c += 2 * min(x[i], K - x[i]);
	cout << c << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>
#include <set>
#include <functional>
#include <iomanip>

using namespace std;

//#define DEBUG_ //!!$BDs=P;~$K%3%a%s%H%"%&%H(B!!
#ifdef DEBUG_
#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
#define dump(x)  ;
#endif

#define equals(a,b) (fabs((a)-(b)) < EPS)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back

//#define int long long

typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

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; }

    template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

template <typename T>
void print_array(const T &ary, int size){
    REP(i,size){
        cout << ary[i] << " ";
    }
    cout << endl;
}

const int mod = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;
const double EPS = (1e-10);
const long double PI = 3.14159265358979323846264338327950288419716939937510582097494459230781640628620899;
int dx[] = {0,0,-1,1};
int dy[] = {-1,1,0,0};


signed main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(12);

    int T; cin >> T;
    REP(_,T){
        int N; cin >> N;
        LL ans = 0;
        vector<VL> red(N), blue(N+1);
        REP(i,N){
            LL k,l,r; cin >> k >> l >> r;
            if(l >= r){
                k--;
                red[k].eb(l-r);
                ans += r;
            }else{
                blue[k].eb(r-l);
                ans += l;
            }

        }

        dump(ans)

        priority_queue<LL, VL, greater<LL>> pq1,pq2;
        REP(i,N){
            for(LL x : red[i]){
                pq1.push(x);
                ans += x;
            }
            while(SZ(pq1) > (i+1)){
                ans -= pq1.top();
                pq1.pop();
            }
        }
        dump(ans)

        for(int i = N-1; i >= 0; i--){
            for(LL x : blue[i]){
                pq2.push(x);
                ans += x;
            }
            while(SZ(pq2) > N - i){
                ans -= pq2.top();
                pq2.pop();
            }
        }

        cout << ans << endl;


    }


}

Measured memory_bytes: 19664
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const long long MOD=1000000007;
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
const int mmax=1000009;

int main(void){
    int n;
    string s;
    cin>>n>>s;
    vector<int> left(26),right(26);
    rep(i,n) left[s[i]-'a']++;
    int ans=0;
    rep(i,n){
        left[s[i]-'a']--;
        right[s[i]-'a']++;
        int temp=0;
        rep(j,26) if(left[j]>0 && right[j]>0) temp++;
        chmax(ans,temp);
    }
    cout<<ans<<endl;
    return 0;
}


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

using namespace std;

#define pb push_back
#define pp pop_back
#define f first
#define s second
#define sz(a) (int)((a).size())
#define NoType ios_base::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL)
#define mp make_pair

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair < int, int > pi;

const int mod = (int)1e9 + 7;
const int MAXN = 1e5+12;

int h1,m1,h2,m2,k;

int main() {

    NoType;

    cin >> h1 >> m1 >> h2 >> m2 >> k;

    int ans = 0;

    ans = h2 - h1;
    ans *= 60;
    if (m2 >= m1) ans += (m2 - m1);
    else ans -= m1, ans += m2;

    ans -= k;
    cout << ans;

return 0;
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
#define ll long long
#define PB push_back
#define MP make_pair
#define PI pair<int , int>
#define REP(i, n) for(int i=0;i<(int)(n);++i)
#define FOR(i,l,h) for(int i=(int)(l);i<=(int)(h);++i)
#define FORD(i,h,l) for(int i=(int)(h);i>=(int)(l);--i)

//#define max(a,b) a>b?a:b
//#define min(a,b) a>b?b:a

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

#define dump(x)  cerr << #x << " = " << (x) << endl
#define ALL(t) (t).begin(),(t).end()

using namespace std;

#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}

int sum() { return 0; }

template<typename T, typename... Args>
T sum(T a, Args... args) { return a + sum(args...); }

/*
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

	string s;cin>>s;
	ll sum = 0;
	for (int i = 0; i < s.size(); ++i)
	{
		sum += (s[i] - '0');
	}
	if(sum % 9 == 0) cout<<"Yes\n";
	else cout<<"No\n";
    return 0;
}
*/


int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	int n;std::cin >> n;
	std::vector<int> v(n);
	REP(i,n)cin>>v[i];
	int prev= v[0];
	ll sum =0;
	for (int i = 1; i < n; ++i)
	{
		if(v[i] < v[i-1]){
			sum += (v[i-1] - v[i]);
			v[i] = v[i-1];
		}
	}
	std::cout << sum << "\n";
	return 0;
}


Measured memory_bytes: 3988
import java.util.*;
public class Main {
    public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
    	int n=sc.nextInt();
    	int m;
    	int reg=0;
        for(int i=0;i<n;i++){
        	m=sc.nextInt();
        	if(m==2||m==3){
        		reg++;
        	}
        	for(int j=2;j*j<m;j++){
        		if(m%j==0){
        			break;
        		}else if((j+1)*(j+1)>m){
        			reg++;
        		}
        	}
        }
        System.out.println(reg);

    }
}


Measured memory_bytes: 41092
import java.util.*;
import java.io.*;
import java.lang.*;

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

        if (b <= a)
            System.out.println("delicious");
        else if ((b-a) <= x)
            System.out.println("safe");
        else
            System.out.println("dangerous");

    }
}


Measured memory_bytes: 35324
#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  set<char> set_s;
  for(int i = 0;i < s.size();i++) {
    set_s.insert(s.at(i));
  }
  if(s.size() == set_s.size()) {
    cout << "yes" << endl;
  }else {
    cout << "no" << endl;
  }
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/stack:16777216")
#include <string>
#include <vector>
#include <map>
#include <list>
#include <iterator>
#include <cassert>
#include <set>
#include <queue>
#include <iostream>
#include <sstream>
#include <stack>
#include <deque>
#include <cmath>
#include <memory.h>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <algorithm>
#include <utility>
#include <time.h>
#include <complex>
using namespace std;
 
#define FOR(i, a, b) for(int i=(a);i<(b);i++)
#define RFOR(i, b, a) for(int i=(b)-1;i>=(a);--i)
#define FILL(A,value) memset(A,value,sizeof(A))
 
#define ALL(V) V.begin(), V.end()
#define SZ(V) (int)V.size()
#define PB push_back
#define MP make_pair
#define Pi 3.14159265358979
#define x0 ikjnrmthklmnt
#define y0 lkrjhkltr
#define y1 ewrgrg
 
typedef long long Int;
typedef unsigned long long UInt;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef pair<Int, Int> PLL;
typedef pair<double, double> PDD;
typedef complex<double> base;
 
const int INF = 1000000000;
const int MAX = 120000;
const int MAX2 = 50007;
const int ADD = 1000000;
const int MAXD = 256;
const int BASE = 1000000000;
const int MOD = 1000000007;

int n;
int x[MAX], y[MAX], w[MAX];
map<PII, int> M;
int q[3][3];

int main()
{
	//freopen("in.txt", "r", stdin);
	//freopen("distance.in",  "r", stdin);
	//freopen("distance.out", "w", stdout);
	//freopen("out.txt" , "w" , stdout);
	
	cin >> n;
	FOR (i,0,n)
	{
		scanf("%d%d%d", x+i, y+i, w+i);
		M[MP(x[i], y[i])] = w[i];
	}
	int ans = 0;
	FOR (i,0,n)
	{
		FOR (dx,-1,2)
		FOR (dy,-1,2)
		{
			q[dx+1][dy+1] = M[MP(x[i]+dx,y[i]+dy)];
		}
		FOR(i1,0,2)
		FOR(i2,0,2)
		ans = max(ans, q[i1][i2] + q[i1][i2+1] + q[i1+1][i2] + q[i1+1][i2+1]);
	}
	cout << ans << " / 1" << endl;
	return 0;
}

Measured memory_bytes: 58684
def warshall_floyd(v_count: int, matrix: list) -> list:
    """ ワーシャルフロイド
    v_count: 頂点数
    matrix: 隣接行列(到達不能はfloat("inf"))
    """
    for i in range(v_count):
        for j, c2 in enumerate(row[i] for row in matrix):
            for k, (c1, c3) in enumerate(zip(matrix[j], matrix[i])):
                if c1 > c2+c3:
                    matrix[j][k] = c2+c3
    return matrix


h, w = map(int, input().split())
c = [list(map(int, input().split())) for _ in range(10)]
warshall_floyd(10, c)
ans = 0
for _ in range(h):
    for x in list(map(int, input().split())):
        if x >= 0:
            ans += c[x][1]
print(ans)


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

#define fa(x,v) for(auto x:v)
#define f(i,a,b) for(ll i=(ll)a;i<=(ll)b;i++)
#define rf(i,a,b) for(ll i=(ll)a;i>=(ll)b;i--)
#define spc " "
#define endl '\n'
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define len(s) (ll)int(s.length())
#define sz(v) (ll)int(v.size())
#define MOD 1000000007

void Fast_IO() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    #ifndef ONLINE_JUDGE
    freopen("input.in","r",stdin);
    freopen("output.out","w",stdout);
    freopen("debug.out","w",stderr);
    #endif
} 

// Code Here

int main()
{
    // Fast_IO();
    ll a,b; cin>>a>>b;
    if(a > b) swap(a,b);
    if(a == 1 && b == 2) cout<<3;
    else if(a == 1 && b == 3) cout<<2;
    else cout<<1;
    return 0;
}

Measured memory_bytes: 256
n,k=map(int,input().split())
p=list(map(int,input().split()))
c=list(map(int,input().split()))
for i in range(n):
    p[i]-=1
ans=max(c)
for i in range(n):
    f=i
    r=0
    l=[]
    while True:
        f=p[f]
        l.append(c[f])
        r+=c[f]
        if f==i:
            break
    t=0
    for j in range(len(l)):
        t+=l[j]
        ret=t
        if r>0:
            e=(k-j-1)//len(l)
            ret+=r*e
        ans=max(ans,ret)
print(ans)


Measured memory_bytes: 77164
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		String a = sc.next();
		boolean flg = true;
		for(int i = 0; i < a.length(); i++){
			if(i%2==0){
				if(a.substring(i, i+1).equals("L")){
					flg = false;
				}
			}
			else{
				if(a.substring(i, i+1).equals("R")){
					flg = false;
				}
			}
		}
		if(flg){
			System.out.print("Yes");
		}
		else{
			System.out.print("No");
		}

	}

}

Measured memory_bytes: 22996
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (int i = j; i < (int)(n); i++)
#define _GLIBCXX_DEBUG
#define n_p(v) next_permutation(v.begin(),v.end())
#define to_ll(b) stoll(b)
#define MOD 1000000007
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; }
//name[i][j]-> vvl name(i,vl(j))
//map<int,int>mp
//余りを切り上げる =>  (a + b - 1) / b 

signed main(){
	int n,k,x,y; cin>>n>>k>>x>>y;
	int ans=0;
	rep(i,0,n){
		if(i<k) ans+=x;
		else ans+=y;
	}
	cout<<ans;
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define ll long long
using ull = unsigned long long;
using namespace std;
const int INF = 1e10;
const int MOD = 1e9 + 7;
#define dump(x)                             \
    if (dbg) {                              \
        cerr << #x << " = " << (x) << endl; \
    }
#define overload4(_1, _2, _3, _4, name, ...) name
#define FOR1(n) for (ll i = 0; i < (n); ++i)
#define FOR2(i, n) for (ll i = 0; i < (n); ++i)
#define FOR3(i, a, b) for (ll i = (a); i < (b); ++i)
#define FOR4(i, a, b, c) for (ll i = (a); i < (b); i += (c))
#define FOR(...) overload4(__VA_ARGS__, FOR4, FOR3, FOR2, FOR1)(__VA_ARGS__)
#define FORR(i, a, b) for (int i = (a); i <= (b); ++i)
template <class T>
bool chmin(T& a, const T& b) {
    if (a > b) {
        a = b;
        return 1;
    } else
        return 0;
}
template <class T>
bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return 1;
    } else
        return 0;
}
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(), (v).end()
#define SZ(x) ((int)(x).size())
#define P pair<int, int>
#define V vector<int>
//#define S set<int>
#define itn int
bool dbg = false;

int N, X[200];


void solve() {
    cin >> N;
    FOR(N)
        cin >> X[i];
    int ans = INF;
    FOR(p, 1, 101) {
        itn tmp = 0;
        FOR(N)
        tmp += (X[i] - p) * (X[i] - p);
        chmin(ans, tmp);
    }
    cout << ans << endl;
}

signed main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    solve();
    return 0;
}


Measured memory_bytes: 256
from collections import deque


n = 0
m = 0
M = None
color = None


def main():
    global n, m, M, color
    n, m = map(int, input().split(' '))

    M = [[] for _ in range(n)]
    color = [-1 for _ in range(n)]

    for _ in range(m):
        a, b = map(int, input().split(' '))
        M[a].append(b)
        M[b].append(a)

    num = 1
    for u in range(n):
        if color[u] == -1:
            dfs(u, num)
            num += 1

    k = int(input())
    for _ in range(k):
        a, b = map(int, input().split(' '))
        if color[a] == color[b]:
            print('yes')
        else:
            print('no')


def dfs(r, c):
    stack = deque()
    stack.append(r)
    color[r] = c
    while len(stack) > 0:
        u = stack.pop()
        for i in range(len(M[u])):
            v = M[u][i]
            if color[v] == -1:
                color[v] = c
                stack.append(v)


if __name__ == '__main__':
    main()



Measured memory_bytes: 23552
#include "bits/stdc++.h"
using namespace std;
 
#define int long long

template <typename A, typename B>
string to_string(pair<A, B> p);

string to_string(const string&);

string to_string(const char* s);

string to_string(bool b);

template <typename A>
string to_string(A v);

template <typename A, typename B>
string to_string(pair<A, B> p);

void debug_out(); 

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T);

vector<string> vec_splitter(string s);
void debug_var(
vector<string> __attribute__ ((unused)) args,
__attribute__ ((unused)) int idx, 
__attribute__ ((unused)) int LINE_NUM) { cerr << endl; } 

template <typename Head, typename... Tail>
void debug_var(vector<string>, int, int, Head, Tail...);

#ifndef ONLINE_JUDGE
#define var(...) debug_var(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
#define stl(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define var(x...)
#define stl(...) 
#endif

const int mod = 1e9 + 7;
const int N = 1e6 + 5; 

void solve() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; ++i) {
    int x;
    cin >> x;
    n -= x;
  }
  if (n < 0) n = -1;
  cout << n << '\n';
}

signed main() {
  ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
  // int T = 1; cin >> T; for (int i = 1; i <= T; ++i)
  solve();
  return 0;
}

string to_string(const string& s) {
  return '"' + s + '"';
}

string to_string(const char* s) {
  return to_string((string) s);
}

string to_string(bool b) {
  return (b ? "T" : "F");
}

template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}

template <typename Head, typename... Tail>
void debug_var(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
  if(idx > 0) cerr << ", "; else cerr << "Line(" << LINE_NUM << "): ";
  stringstream ss; ss << H;
  cerr << args[idx] << " = " << ss.str();
  debug_var(args, idx + 1, LINE_NUM, T...);
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}

vector<string> vec_splitter(string s) {
  s += ',';
  vector<string> res;
  while(!s.empty()) {
    res.push_back(s.substr(0, s.find(',')));
    s = s.substr(s.find(',') + 1);
  }
  return res;
}

Measured memory_bytes: 3664
import java.util.Scanner;

public class Main {
	
    public static void main(String[] args){
        
    Scanner sc = new Scanner(System.in);
    String S = sc.next();
    char[]ss = S.toCharArray();

    int cou = 0;
    for(int i=0; i<3; i++) {
	   if(ss[i]=='1') {
		   cou++;
	   }
    }
	System.out.println(cou);
      }
}


Measured memory_bytes: 35512
def choose(n, r, mod)
  return 0 if not (0 <= r and r <= n)
  return 1 if r == 0 or r == n
  fact(n, mod) * inverse(fact(r, mod) * fact(n-r, mod) % mod, mod) % mod
end
@fact = [1]
def fact(n, mod)
  if n > @fact.size then
    f = @fact[-1]
    (@fact.size+1..n).each{|i|
      f = (f * i) % mod
      @fact << f
    }
  end
  @fact[n-1]
end
def inverse(x, mod)
  pow(x, mod-2, mod)
end
def pow(x, n, mod)
  ans = 1
  while n > 0
    ans = ans * x % mod if n.odd?
    x = x * x % mod
    n >>= 1
  end
  ans
end

N, M, K = gets.chomp.split(" ").map(&:to_i)
MOD = 998244353

ans, wk = [0, 1]
(1..N).each{|n|
  wk = (n == 1 ? M : wk * (M-1) % MOD)
  if N - n <= K then
    ans = (ans + wk * choose(N-1, N-n, MOD)) % MOD
  end
}

puts ans


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

using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, n) for (int i = 1; i <= (n); i++)
#define all(x) (x).begin(), (x).end()
#define rv(s) reverse((s).begin(), (s).end())
#define pii pair<int, int>
#define int int64_t
#define re(s) reverse((s).begin(), (s).end())
#define setout(n, x) setw(n) << setfill(x)
#define Fixed fixed << setprecision(10);
const long long mod = 1e9 + 7;

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

   vector<int> x;
   vector<int> y;
   int n, a, b;
   cin >> n;

   rep(i, n * 2)
   {
      cin >> a;
      y.push_back(a);
   }

   rep(i, n)
   {
      x.push_back(i + 1);
   }

   int j = 1;
   bool as = false, az = false;
   do
   {
      rep(i, n)
      {
         if (x[i] != y[i])
            break;
         if (i == (n - 1))
         {
            a = j;
            as = true;
         }
      }

      rep(i, n)
      {
         if (x[i] != y[(n + i)])
            break;
         if (i == (n - 1))
         {
            b = j;
            az = true;
         }
      }

      if (as && az)
      {
         cout << abs(a - b) << '\n';
         return 0;
      }
      ++j;

   } while (next_permutation(x.begin(), x.end()));
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
int main() {
    string X;
    cin >> X;
    int scount=0;
    int count=0;
    for(char c : X){
        if(c == 'S') scount++;
        else{
            if(scount){
                count+=2;
                scount--;
            }
        }
    }
    cout << X.length()-count << endl;

    return 0;
} 

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

int main()
{
  int n, ans=0;
  cin>>n;
  for(int i=1; i<=n; i++)
  {
  	string s = to_string(i);
    if(s.length()%2==1)
      ans++;
  }
  cout<<ans<<endl;
  
  return 0;
}

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

int main() {
  int N;
  cin >> N;
  
  vector<int> vec(N);
  for (int i=0; i<N; i++){
    cin >> vec.at(i);
  }
  
  vector<int> DP(N);
  DP.at(0) = 0;
  DP.at(1) = DP.at(0) + abs(vec.at(1)-vec.at(0));
  
  for (int i=0; i<N-2; i++){
    int DP1 = DP.at(i) + abs(vec.at(i)-vec.at(i+2));
    int DP2 = DP.at(i+1) + abs(vec.at(i+1)-vec.at(i+2));
    DP.at(i+2) = min(DP1,DP2);
  }
  cout << DP.at(N-1) << endl;
}

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

#include <cstring>
#include <set>
#include <map>
#include <queue>
#include <utility>

using namespace std;

typedef long long LL;

#define dump(c) { for (auto it = c.begin(); it != c.end(); ++it) if (it == c.begin()) cout << *it; else cout << ' ' << *it; cout << endl; } 
#define rep(i,n) for (int i = 0; i < (n); ++i)

const int MOD = 1000000007;

int main()
{
    int N, M;
    cin >> N >> M;

    int l = 1;
    int r = N;
    rep(i, M) {
        int L, R;
        cin >> L >> R;
        l = max(l, L);
        r = min(r, R);
    }

    cout << max(0, r-l+1) << endl;

    return 0;
}


Measured memory_bytes: 384
#include <iostream>

using namespace std;

const int MAX_INDEX = 100005;
const int INF = 1001001001;

int upper_bound(int* array, int value, int size)
{
    int l = 0, r = size;
    while(l < r)
    {
        int mid = (l + r) / 2;
        if(array[mid] > value)
        {
            r = mid;
        }
        else{
            l = mid + 1;
        }
    }
    return r;
}

int lower_bound(int* array, int value, int size)
{
    int l = 0, r = size;
    while(l < r)
    {
        int mid = (l + r) / 2;
        if(array[mid] >= value)
        {
            r = mid;
        }
        else{
            l = mid + 1;
        }
    }
    return r;
}


int main()
{
    int array[MAX_INDEX], dp[MAX_INDEX];
    int n, u, ans = -1;
    cin >> n;
    for(int i=0;i<n;++i){
        cin >> array[i];
        dp[i] = INF;
    }

    for(int i=0;i<n;++i)
    {
        u = lower_bound(dp, array[i], n);
        dp[u] = array[i];
        ans = max(ans, u + 1);
    }
    cout << ans << endl;
}



Measured memory_bytes: 3848
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
typedef long long ll;

int main(){
  ios_base::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
  int n; cin >> n;
  map<string, int> m;
  m["AC"] = 0;
  m["WA"] = 1;
  m["TLE"] = 2;
  m["RE"] = 3;
  vector<int> d(4);
  for(int i = 0; i < n; i ++){
    string s; cin >> s;
    d[m[s]] ++;
  }
  vector<string> s = {"AC", "WA", "TLE", "RE"};
  for(int i = 0; i < 4; i ++){
    cout << s[i] << " x " << d[i] << endl;
  }
}


Measured memory_bytes: 3684
#include<cstdio>
#include<functional>
#include<algorithm>
#define MM	2100000000
using namespace std;
int main(void)
{
	int n,a[100],i,j,sum,mn,x;
	scanf("%d",&n);
	for(i=0;i<n;i++)	scanf("%d",&a[i]);
	mn=MM;
	for(i=-100;i<=100;i++)	{
		x=0;
		for(j=0;j<n;j++)	{
			x+=(i-a[j])*(i-a[j]);
		}
		mn=min(mn,x);
	}
	printf("%d\n",mn);
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <string>
#include <queue>
#include <tuple>
#include <cmath>
#include <bitset>
#include <cctype>
#include <set>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
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; }
template<typename T>
vector<T> table(int n, T v) { return vector<T>(n, v); }

template <class... Args>
auto table(int n, Args... args) {
    auto val = table(args...);
    return vector<decltype(val)>(n, move(val));
}
const ll INF = (1ll<<31)-1;
const ll MOD = 1000000007;
typedef pair<ll,ll> P;
const ll MAX = 200005;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,a;
    cin >> n >> a;
    n %= 500;
    if (n <= a) PRINT("Yes");
    else PRINT("No");
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
//#pragma GCC optimization ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
using namespace std;
#define pb emplace_back
#define int long long
#define endl "\n"
#define pii pair<int,int> 
#define ff first
#define ss second
#define mii map<int,int>
#define si set<int>
#define sti stack<int>
#define qi queue<int>
#define vi vector<int>
#define pq priority_queue<int>
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const int M=998244353;

int32_t main(){
	int p,q,r;
	cin>>p>>q>>r;
	cout<<min(r+p,min(p+q,q+r));
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b;
	cin>>a>>b;
	if(b!=100) cout<<b*pow(100,a);
	else if(a==2&&b==100) cout<<10<<10000;
	else cout<<101*pow(100,a);
	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N; cin >> N;
	vector<int> A(N); rep(i, 0, N) {
		cin >> A[i];
	}
	int sum = accumulate(all(A), 0LL);
	int p = N*(N + 1) / 2;
	if (sum%p != 0) {
		cout << "NO" << endl;
		return 0;
	}
	int k = sum / p;
	dump(k);
	vector<int> B(N), C(N);
	rep(i, 0, N) {
		B[i] = A[(i + 1) % N] - A[i];
	}
	dump(B);
	rep(i, 0, N) {
		if (B[i] > 0)continue;
		if ((k - B[i]) % N != 0) {
			cout << "NO" << endl;
			return 0;
		}
		C[i] = (k - B[i]) / N;
	}
	int sumc = accumulate(all(C), 0LL);
	dump(sumc);
	if (sumc != k) {
		cout << "NO" << endl;
		return 0;
	}
	cout << "YES" << endl;
	return 0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int k; cin >> k;
    int a[1000001];
    a[1] = 7%k;
    for (int i = 2; i <= k; ++i){a[i] = (a[i-1]*10 + 7)%k;}
    for(int i=1;i<=k;i++){
        if(a[i]==0){
            printf("%d\n",i);
            return 0;
        }
    }
    printf("-1\n");
}

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

typedef long long ll;

#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define file() freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define tt int t; cin>>t; while(t--)
#define nl cout<<"\n";
#define sp cout<<" ";
#define rep(i, a, b) for(long long i=a; i<b; i++)

const int INF = 1e9 + 7;
const int MOD = 1e9 + 7;
double PI = 4*atan(1);

int main()
{
    optimize();

    int n, k;

    cin>> n>> k;

    int p[n];

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


sort(p, p+n);
int cost= 0;

for(int i=0; i<k; i++)
    cost+= p[i];

cout<< cost;
nl;

return 0;
}




Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
const int N=200005;
int a[N],n,x,ans;
int main(){
	scanf("%d",&n);
	for (int i=1;i<=n;i++){
		scanf("%d",&x);
		a[x]=a[x-1]+1;
		ans=max(ans,a[x]);
	}
	printf("%d\n",n-ans);
}


Measured memory_bytes: 1024
//g++ -std=gnu++14 a.cpp

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iostream>
#include <istream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <tuple>
#include <iomanip>
#include <random>
#include <math.h>
#include <stdio.h>

using namespace std;

#define ll long long
#define rep(i, n) for(ll i = 0; i < (n); i++)
ll MOD = 1e9 + 7;
int INF = 1 << 30;
ll INFL = 1LL << 60;
ll MODP = 998244353;

struct Unionfind {
  vector<int> d;
  Unionfind(int n): d(n,-1) {} //dを初期化
  int find(int x){
    if(d[x] < 0)return x;
    return find(d[x]);
  }
  bool unite(int x,int y){
    x = find(x);
    y = find(y);
    if(x == y)return false;
    if(d[x] > d[y]) swap(x,y);//小さい方を大きい方にくっつける
    d[x] += d[y];
    d[y] = x;
    return true;
  }
  bool same(int x,int y) { return find(x) == find(y);}
  int size(int x) { return -d[find(x)];}
};


int main(){
  int N,M;
  cin >> N >> M;
  Unionfind uf(N);
  rep(i,M){
    int a,b;
    cin >> a >> b;
    a--;
    b--;
    uf.unite(a,b);
  }
  int ans = 0;
  rep(i,N){
    if(ans < uf.size(i))ans = uf.size(i);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3980
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string S;
  cin >> S;
  int N = S.size();
  vector<int>count(3);
  for (int i = 0; i < N; i++) {
    if (S.at(i) == 'a'){
      count.at(0)++;
    }
    else if (S.at(i) == 'b'){
      count.at(1)++;
    }
    else if (S.at(i) == 'c'){
      count.at(2)++;
    }
  }
  sort(count.begin(), count.end());
  int M = count.at(0);
  for (int i = 0; i < 3; i++) {
    count.at(i) -= M;
  }
  
  if (count.at(1) == 0 || count.at(1) == 1){
    if (count.at(2) == 0 || count.at(2) == 1){
      cout << "YES" << endl;
      return 0;
    }
  }
  cout << "NO" << endl;
}
    
  
  
    
 

Measured memory_bytes: 3732
#define DEB
#include<bits/stdc++.h>
#define REP(i,m) for(int i=0;i<(m);++i)
#define REPN(i,m,in) for(int i=(in);i<(m);++i)
#define ALL(t) (t).begin(),(t).end()
#define CLR(a) memset((a),0,sizeof(a))
#define pb push_back
#define mp make_pair
#define fr first
#define sc second

using namespace std;


#ifdef DEB
#define dump(x)  cerr << #x << " = " << (x) << endl
#define prl cerr<<"called:"<< __LINE__<<endl
#define dumpR(x) cerr<<"\x1b[31m"<<#x<<" = " <<(x)<<"\x1b[39m"<<endl
#define dumpY(x) cerr<<"\x1b[33m"<<#x<<" = " <<(x)<<"\x1b[39m"<<endl
#define dumpG(x) cerr<<"\x1b[32m"<<#x<<" = " <<(x)<<"\x1b[39m"<<endl
template<class T> void debug(T a,T b){ for(;a!=b;++a) cerr<<*a<<' ';cerr<<endl;}
#else
#define dump(x) ;
#define dumpR(x) ;
#define dumpY(x) ;
#define dumpG(x) ;
#define prl ;
template<class T> void debug(T a,T b){ ;}
#endif

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

typedef long long int lint;
typedef pair<int,int> pi;

namespace std{
  template<class S,class T>
  ostream &operator <<(ostream& out,const pair<S,T>& a){
    out<<'('<<a.fr<<','<<a.sc<<')';
    return out;
  }
}

const int INF=5e8;

typedef long long Int;

typedef vector<int> vi;
vi col[405];
int n;

vi getmini(vi c){
  vector<int> mini(4,INF);
  REP(k,4){
    vector<int> tmp=c;
    rotate(tmp.begin(),tmp.begin()+k,tmp.end());
    chmin(mini,tmp);
  }
  return mini;
}
Int dp[405][16];
int coef[405];
int rotn(vi mini){
  if(mini[0]==mini[1] && mini[1]==mini[2] && mini[2]==mini[3]) return 4;
  else if(mini[0]==mini[2] && mini[1]==mini[3]) return 2;
  return 1;
}
int main(){
  cin>>n;
  REP(i,n){
    vector<int> c(4),mini;
    REP(j,4) cin>>c[j];
    mini=getmini(c);

    col[i]=mini;
  }



  Int res=0;
  REP(i,n) REP(j,i) REP(d,4){
    int back[4];
    REP(k,4) back[k]=col[j][3-k];
    rotate(back,back+d,back+4);

    map<vi,pi> cnt;
    lint tmpn=1;
    REP(k,4){
      vi tmp(4),mini;
      tmp[0]=back[k];
      tmp[1]=back[(k+1)%4];
      tmp[2]=col[i][(1+k)%4];
      tmp[3]=col[i][k];
      mini=getmini(tmp);
      cnt[mini].fr++;
      tmpn*=rotn(mini);
    }
    int match[4]={0};
    int coef2[4]={0};

    REP(k,i) if(k!=j && cnt.count(col[k])){
      ++cnt[col[k]].sc;
    }
    for(auto e:cnt){
      lint tmp2=1;
      REP(j,e.sc.fr) tmp2=tmp2*(e.sc.sc-j);
      tmpn*=tmp2;
    }
    res+=tmpn;
  }
  cout<<res<<endl;
  return 0;
}





Measured memory_bytes: 384
#include <stdio.h>
#include <algorithm>
using namespace std;
int N, S, T[50]; bool dp[51][834][1251];
int main() {
	scanf("%d", &N);
	for (int i = 0; i < N; i++) scanf("%d", &T[i]), S += T[i];
	dp[0][0][0] = true;
	for (int i = 1; i <= N; i++) {
		for (int j = 0; j <= S / 3; j++) {
			for (int k = 0; k <= S / 2; k++) {
				dp[i][j][k] = dp[i - 1][j][k];
				if (j - T[i - 1] >= 0) dp[i][j][k] |= dp[i - 1][j - T[i - 1]][k];
				if (k - T[i - 1] >= 0) dp[i][j][k] |= dp[i - 1][j][k - T[i - 1]];
			}
		}
	}
	int ret = 999999999;
	for (int i = 0; i <= S / 3; i++) {
		for (int j = 0; j <= S / 2; j++) {
			if (dp[N][i][j]) {
				ret = min(ret, max({ i, j, S - i - j }));
			}
		}
	}
	printf("%d\n", ret);
	return 0;
}

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

int main() {
  int N,M;
  cin >> N >> M;
  vector<long long> H(N);
  for (int i = 0; i < N; i++) {
    cin >> H.at(i);
  }
  vector<vector<long long>> A(M,vector<long long>(2));
  for (int i = 0; i < M; i++) {
    for (int j = 0; j < 2; j++) {
      cin >> A.at(i).at(j);
    }
  }
  vector<long long> B(2*M);
  for (int i = 0; i < 2*M; i++) {
    B.at(i) = -1;
  }
  int s = 0;
  for (int i = 0; i < M; i++) {
    if (H.at(A.at(i).at(0)-1) < H.at(A.at(i).at(1)-1)) {
      B.at(i) = A.at(i).at(0)-1;
    }
    else if (H.at(A.at(i).at(0)-1) == H.at(A.at(i).at(1)-1)) {
      B.at(i) = A.at(i).at(0)-1;
      B.at(2*M-1-s) = A.at(i).at(1)-1;
      s++;
    }
    else {
      B.at(i) = A.at(i).at(1)-1;
    }
  }
  for  (long long x: B) {
    if (x == -1) {
      continue;
    }
    else {
    H.at(x) = 0;
    }
  }
  int ans = 0;
  for (long long x: H) {
    if (x != 0) {
      ans++;
    }
  }
  cout << ans <<endl;
}


Measured memory_bytes: 11192
#include <iostream>
#include <vector>

int root(int x,std::vector<int>& par);
void Unite(int x,int y,std::vector<int>& par,std::vector<int>& rank);
bool isSameSet(int x,int y,std::vector<int> par);
int max(int a,int b);
int main() {
    int M,N;
    std::cin >> N >> M;
    std::vector<int> P(N+1);
    std::vector<int> par(N+1);
    std::vector<int> rank(N+1,1);
    for(int i=1;i<N+1;i++){
        par[i] = i;
    }
    for(int i=1;i<N+1;i++){
        std::cin >> P[i];
    }
    for(int i=0;i<M;i++){
        int x,y;
        std::cin >> x >> y;
        Unite(x,y,par,rank);
    }
    int ans=0;
    for(int i=1;i<N+1;i++){
        if(isSameSet(P[i],i,par)){
            ans++;
        }
    }
    std::cout << ans;
    return 0;
}

int root(int x,std::vector<int>& par){
    if(par[x] == x)
        return x;
    else{
        int rx = root(par[x],par);
        par[x] = rx;
        return rx;
    }

}

void Unite(int x,int y,std::vector<int>& par,std::vector<int>& rank){
    int rx = root(x,par);
    int ry = root(y,par);
    if(rx == ry)
        return;
    if(rank[rx] <= rank[ry]) {
        par[rx] = ry;
        rank[ry] = max(rank[rx]+1,rank[ry]);
    }
    else{
        par[ry] = rx;
        rank[rx] = max(rank[ry]+1,rank[rx]);
    }
    return;
}

bool isSameSet(int x,int y,std::vector<int> par){
    int rx = root(x,par);
    int ry = root(y,par);
    return rx == ry;
}

int max(int a,int b){
    if(a>b){
        return a;
    }else{
        return b;
    }
}

Measured memory_bytes: 4848
n = int(input())
t,a = map(float,input().split())
list = input().split()
list = map(float,list)
alist = []
count = 0
for h in list:
	count += 1
	temp = a - (t - (h*0.006))
	#print(temp)
	alist.append(abs(temp))

x = min(alist)
#print(x,'min')
answer = alist.index(x)

print(answer + 1,end='')

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

int main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    int n;
    cin >> n;
    int v[n];
    int count[1005];
    memset( count, 0, sizeof count );
    for( int i = 0; i < n; i++ ) {
        cin >> v[i];
    }
    sort( v, v+n );
    long long ans = 0;
    for( int i = 0; i < n; i++) {
        for( int j = i+1; j < n; j++ ) {
            int mmax = v[i]+v[j]-1;
            int mmin = max( v[i]-v[j]+1, v[j]-v[i]+1 );
            ans += upper_bound( v, v+i, mmax) - lower_bound( v, v+i, mmin );
        }
    }
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 256
s = input()
t = input()

if len(s) < len(t):
    print('UNRESTORABLE')
    exit()
ansl = []


for i in range(len(s)-len(t)+1):
    flag = True
    for j in range(len(t)):
        if s[i+j] == t[j] or s[i+j] == '?':
            continue
        else:
            flag = False
    if flag:
        ans = s[:i]+t+s[i+len(t):]
        ans = ans.replace('?', 'a')
        ansl.append(ans)

if len(ansl) == 0:
    print('UNRESTORABLE')
else:
    ansl.sort()
    print(ansl[0])


Measured memory_bytes: 38256
#include <bits/stdc++.h>
#define fastIO (cin.tie(0), cout.tie(0), ios::sync_with_stdio(false))
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define precise(i) fixed << setprecision(i)
using lint = long;
using llint = long long;
using namespace std;

void drawRect(int H, int W) {
    // top
    rep(qi, W) cout << "#";
    cout << endl;

    rep(h, H - 2) {
        rep(w, W) {
            if (w == 0)
                cout << "#";
            else if (w == W - 1)
                cout << "#";
            else
                cout << ".";
        }
        cout << endl;
    }

    // bottom
    rep(qi, W) cout << "#";
    cout << endl;
}

int main() {
    fastIO;
    int H, W;
    while (cin >> H >> W) {
        if (H == 0 && W == 0)
            break;

        drawRect(H, W);
        cout << endl;
    }
}



Measured memory_bytes: 3136
from collections import deque

n = int(input())
C = [input() for i in range(n)]

A = deque([])
for c in C:
	if c == 'deleteFirst':
		A.popleft()
	elif c == 'deleteLast':
		A.pop()
	elif 'delete' in c:
		q = int(c[7:])
		if q in A:
			A.remove(q)
	elif 'insert' in c:
		q = int(c[7:])
		A.appendleft(q)

print(' '.join(map(str, A)))


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

N = int(input())
ans = [0]*(N)

for x in range(1, 101):
    for y in range(1, 101):
        for z in range(1, 101):
            m = x**2 + y**2 + z**2 + x*y + y*z + z*x
            if m <= N:
                ans[m-1] += 1

print(*ans, sep="\n")

Measured memory_bytes: 68616