akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string.h>
using namespace std;
int n;
char s[111],t[111];
int main(){
    cin>>n;
    cin>>s>>t;
    for(int i=0;i<=n;i++){
        if(strncmp(s+i,t,n-i)==0){
            cout<<n+i;
            return 0;
        }
    }
}

Measured memory_bytes: 256
N=int(input())
arr=list(map(int,input().split()))
print(' '.join(map(str,arr)))
for key in range(1,len(arr)):
    temp=arr[key]
    i=key-1
    while i>=0 and arr[i]>temp:
        arr[i+1]=arr[i]
        i-=1
    arr[i+1]=temp
    print(*arr)

Measured memory_bytes: 5980
#include<iostream>
#include<cmath>
using namespace std;
int main() {
	int n;
	cin >> n;
	int i, j, k, ch, a[101][3] = { 0 };
	for (i = 0; i < n; i++) {
		cin >> a[i][0] >> a[i][1] >> a[i][2];
	}
	int f = 0;
	while (a[f][2] == 0)
		f++;
	for (int i = 0; i <= 100; i++) {
		for (int j = 0; j <= 100; j++) {
			int h = abs(i - a[f][0]) + abs(j - a[f][1]) + a[f][2];
			int flag = 0;
			for (int k = 0; k < n; k++) {
				int ch = h - abs(i - a[k][0]) - abs(j - a[k][1]);
				if (ch < 0)
					ch = 0;
				if (ch != a[k][2]) {
					flag = 1;
					break;
				}
			}
			if (flag == 0) {
				cout << i << ' ' << j << ' ' << h << endl;
				return 0;
			}
		}
	}
}


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

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


int main(){
	cin>>n;
	a.resize(n);	sum.resize(n);

	for(int i=0;i<n;i++)cin>>a[i];
	sort(a.begin(), a.end());
	for(int i=0;i<n;i++)sum[i]=a[i];

	for(int i=1;i<n;i++)sum[i]+=sum[i-1];
	
	int ans=1;
	for(int i=n-2;i>=0;i--){
		if(sum[i]*2>=a[i+1])ans++;
		else break;
	}

	cout<<ans<<endl;

	return 0;
}


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

typedef long long ll; 

int main(){
    int n; cin>>n; 
    ll a[n+1]; 
    for(int i=1;i<=n;i++) { cin>>a[i]; }
    a[0]=0; 
    for(int i=1;i<=n;i++) { a[i]+=a[i-1]; }
    map<ll,int> m;
    for(int i=0;i<=n;i++) m[a[i]]++; 
    ll ans=0; 
    for(pair<ll,int> p:m){
        ll v=p.second;
        //if(p.first!=0)  v--; 
        ans+=(v)*(v-1)/2;
    }
    cout<<ans<<endl; 
	return 0; 
}


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

int main(){
  bool p[1000000];
  int num[1000000];
  int c,n;

  for(int i=0;i<1000000;i+=2)p[i] = false;
  for(int i=1;i<1000000;i+=2)p[i] = true;
  p[1] = false;
  p[2] = true;

  c = 3;
  while(c < 1000){
    for(int i=3*c;i<1000000;i+=2*c)p[i] = false;
    do{c+=2;}while(!p[c]);
  }

  c = 0;
  for(int i=0;i<1000000;i++){
    if(p[i])c++;
    num[i] = c;
  }

  while(cin >> n)cout << num[n] << endl;
}

Measured memory_bytes: 0
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>

using namespace std;

//typedef
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<LL, LL> PLL;

//conversion
inline LL toLong(string s) {LL 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;}

//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) LL((a).size())
#define EACH(i,c) for(auto 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(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define UNTIL(p) while(!(p))

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

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

#define PUTS(x) cout << (x) << endl;

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin>>s;
    deque<char> deq(SZ(s));
    REP(i,SZ(s)){
        deq[i] = s[i];
    }
    LL q;
    cin>>q;
    bool rev = false;
    REP(i,q){
        LL t;
        cin>>t;
        if(t == 1){
            rev = !rev;
        }
        else{
            LL f;
            char c;
            cin>>f>>c;
            if(f == 1 && rev){
                deq.push_back(c);
            }
            if(f == 1 && !rev){
                deq.push_front(c);
            }
            if(f == 2 && rev){
                deq.push_front(c);
            }
            if(f == 2 && !rev){
                deq.push_back(c);
            }
        }
    }

    if(rev){
        reverse(ALL(deq));
    }
    REP(i,deq.size()){
        cout<<deq[i];
    }
    PUTS("");
}

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

#define FOR(i,l,r) for(int i = int(l);i < int(r);i++)
template<typename T> bool chmax(T& a,const T& b){ return a < b ? (a = b,true) : false; }
template<typename T> bool chmin(T& a,const T& b){ return b < a ? (a = b,true) : false; }
typedef long long ll;

int A,B,C;

int main()
{
	cin >> A >> B >> C;
	cout << (A ^ B ^ C) << endl;

	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <string>
#include <cstring>
#include <queue>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <map>
#include <numeric>
#include <functional>
#include <cmath>
#include <cassert>
#include <string>
#include <iostream>

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
const ll MOD = 1000000007;
const int mod = 1000000007;
ll INF = 1LL << 60;

template <typename T>
istream &operator>>(istream &is, vector<T> &vec)
{
   for (auto &v : vec)
      is >> v;
   return is;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &vec)
{
   os << "[";
   for (auto v : vec)
      os << v << ",";
   os << "]";
   return os;
}
template <typename T>
ostream &operator<<(ostream &os, const deque<T> &vec)
{
   os << "deq[";
   for (auto v : vec)
      os << v << ",";
   os << "]";
   return os;
}
template <typename T>
ostream &operator<<(ostream &os, const set<T> &vec)
{
   os << "{";
   for (auto v : vec)
      os << v << ",";
   os << "}";
   return os;
}
template <typename T>
ostream &operator<<(ostream &os, const unordered_set<T> &vec)
{
   os << "{";
   for (auto v : vec)
      os << v << ",";
   os << "}";
   return os;
}
template <typename T>
ostream &operator<<(ostream &os, const multiset<T> &vec)
{
   os << "{";
   for (auto v : vec)
      os << v << ",";
   os << "}";
   return os;
}
template <typename T>
ostream &operator<<(ostream &os, const unordered_multiset<T> &vec)
{
   os << "{";
   for (auto v : vec)
      os << v << ",";
   os << "}";
   return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &pa)
{
   os << "(" << pa.first << "," << pa.second << ")";
   return os;
}
template <typename TK, typename TV>
ostream &operator<<(ostream &os, const map<TK, TV> &mp)
{
   os << "{";
   for (auto v : mp)
      os << v.first << "=>" << v.second << ",";
   os << "}";
   return os;
}
template <typename TK, typename TV>
ostream &operator<<(ostream &os, const unordered_map<TK, TV> &mp)
{
   os << "{";
   for (auto v : mp)
      os << v.first << "=>" << v.second << ",";
   os << "}";
   return os;
};
#define dbg(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ") " << __FILE__ << endl;
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val)
{
   fill((T *)array, (T *)(array + N), val);
}

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

ll a[202020];
int solve()
{
   ll n;
   cin >> n;
   ll ans = 1;
   map<ll, ll> m;
   for(int i=2; i <= n; i++){
      for (auto p:prime_factor(i)){
         m[p.first] += p.second;
      }
   }
   for(int i=2; i <= n; i++){
      ans = (ans * (m[i] + 1)) % MOD;
   }
   cout << ans << endl;
   return 0;
}

int main()
{
   //cout.precision(10)
   ios::sync_with_stdio(false);
   cin.tie(0);

   solve();
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
using namespace std;
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(a) a.begin(),a.end()
#define rall(c) (c).rbegin(),(c).rend()
#define mp make_pair
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef long double ld;
const ll inf=1e9+7;
const ll mod=1e9+7;
int main(){
    string s,t;cin>>s>>t;
    vector<ll>last(26,-1);
    ll n=s.size();
    string q=s+s;
    vector<vector<ll> >a(n*2,vector<ll> (26));
    for(int i=n*2-1;i>=0;i--){
        rep(j,26){
            a[i][j]=last[j];
        }
        ll c=q[i]-'a';
        last[c]=i;
    }
    ll ans=0;
    ll now=0;
    if(a[0][t[0]-'a']==-1){
        cout<<-1<<endl;
        return 0;
    }
    if(s[0]==t[0]){
        now=0;
        ans+=1;
    }else{
        ans+=a[0][t[0]-'a']+1;
        now=(a[0][t[0]-'a'])%n;
    }
    //cout<<ans<<' '<<now<<endl;
    rep(i,t.size()-1){
        if(a[now][t[i+1]-'a']>=0){
            ans+=a[now][t[i+1]-'a']-now;
            now=(a[now][t[i+1]-'a'])%n;
        }else{
            ans=-1;
            break;
        }
        //cout<<ans<<' '<<now<<endl;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 49152
class UnionFind():
    # 作りたい要素数nで初期化
    # 使用するインスタンス変数の初期化
    def __init__(self, n):
        self.n = n
        # root[x]<0ならそのノードが根かつその値が木の要素数
        # rootノードでその木の要素数を記録する
        self.root = [-1]*(n+1)
        # 木をくっつける時にアンバランスにならないように調整する
        self.rnk = [0]*(n+1)

    # ノードxのrootノードを見つける
    def Find_Root(self, x):
        if(self.root[x] < 0):
            return x
        else:
            # ここで代入しておくことで、後の繰り返しを避ける
            self.root[x] = self.Find_Root(self.root[x])
            return self.root[x]
    # 木の併合、入力は併合したい各ノード
    def Unite(self, x, y):
        # 入力ノードのrootノードを見つける
        x = self.Find_Root(x)
        y = self.Find_Root(y)
        # すでに同じ木に属していた場合
        if(x == y):
            return 
        # 違う木に属していた場合rnkを見てくっつける方を決める
        elif(self.rnk[x] > self.rnk[y]):
            self.root[x] += self.root[y]
            self.root[y] = x

        else:
            self.root[y] += self.root[x]
            self.root[x] = y
            # rnkが同じ（深さに差がない場合）は1増やす
            if(self.rnk[x] == self.rnk[y]):
                self.rnk[y] += 1
    # xとyが同じグループに属するか判断
    def isSameGroup(self, x, y):
        return self.Find_Root(x) == self.Find_Root(y)

    # ノードxが属する木のサイズを返す
    def Count(self, x):
        return -self.root[self.Find_Root(x)]

def main():
    n,m = map(int,input().split())
    p = [int(x) for x in input().split()]
    uni = UnionFind(n)
    for i in range(m):
        a,b = map(int,input().split())
        uni.Unite(a,b)
    cnt = 0
    for i,p_ in enumerate(p):
        if uni.isSameGroup(i+1,p_):
            cnt += 1
    print(cnt)




if __name__ == "__main__":
    main()

Measured memory_bytes: 95596
package main

import "fmt"

func main() {
	var s string
	fmt.Scan(&s)

	flag := 0
	max := 0
	for i := range s {
		if s[i] == 'A' || s[i] == 'C' || s[i] == 'G' || s[i] == 'T' {
			flag++
			if max < flag {
				max = flag
			}
			continue
		}
		flag = 0
	}
	fmt.Println(max)
}


Measured memory_bytes: 512
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define F first
#define S second
#define int long long
#define ll long long
//#define int  unsigned long long
#define pb push_back
//#define double long double

using namespace std;
using namespace __gnu_pbds;
typedef  tree< int , null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int N = 210000;
const int K = 100000;
const int mod = 1e9 + 7;
vector <int> g[N];
int sz[N], pt[N];
int ans, n;
void dfs(int v, int p = -1){
    sz[v] = 1;
    for (auto u: g[v]){
        if (u == p) continue;
        dfs(u, v);
        ans += pt[sz[u]];
        sz[v] += sz[u];
    }
    ans = (ans + (p != -1) * pt[n - sz[v]] - (int)g[v].size() + 1 + mod + pt[n - 1]) % mod;
}
int binpow(int x, int y){
    int res = 1;
    while(y){
        if (y % 2){
            res = res * x % mod;
        }
        x = x * x % mod;
        y /= 2;
    }
    return res;
}
main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    cin >> n;
    pt[0] = 1;
    for (int i = 1; i <= n; i++) pt[i] = 2 * pt[i - 1] % mod;
    for (int i = 1; i < n; i++){
        int u, v;
        cin >> u >> v;
        g[u].pb(v);
        g[v].pb(u);
    }
    dfs(1);
    cout << (n - ans * binpow(binpow(2, n), mod - 2) % mod + mod) % mod;
}


Measured memory_bytes: 29252
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
#include <stack>
#include <set>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define INF (int)(1123456789)
#define LINF (long long int)(112345678901234567)
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
#define all(v) v.begin(), v.end()

const int N = 1234567;

ll mpow(ll a, ll b){
	if(b==0) return 1;
	else if(b%2==0){ll memo = mpow(a,b/2); return memo*memo%MOD;}
	else return mpow(a,b-1) * a % MOD;
}
ll gcd(ll a, ll b){
	if(b==0) return a;
	else return gcd(b, a%b);
}
vector<ll> kaijo_memo;
ll kaijo(ll n){
	if(kaijo_memo.size() > n) return kaijo_memo[n];
	if(kaijo_memo.size() == 0) kaijo_memo.push_back(1);
	while(kaijo_memo.size() <= n) kaijo_memo.push_back(kaijo_memo[kaijo_memo.size()-1] * kaijo_memo.size() % MOD);
	return kaijo_memo[n];
}
ll nCr(ll n, ll r){
	if(n < r || r < 0) return 0;
	ll ret = 1;
	ret *= kaijo(n); ret %= MOD;
	ret *= mpow(kaijo(r), MOD-2); ret %= MOD;
	ret *= mpow(kaijo(n-r), MOD-2); ret %= MOD;
	return ret;
}

int main(void){
	int n,p;
	cin>>n;
	int ans,memo;
	ans = 0;memo = 0;
	rep(i,n){
		cin>>p;
		ans += p;
		memo = max(memo, p);
	}
	ans -= memo/2;
	cout<<ans<<endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cassert>
#include <algorithm>
#include <functional>
#include <cmath>
#include <cfenv>
using ll = unsigned long long;
using namespace std;

int main(){
    vector<int> vec(4);
    for(int i=0;i<3;i++){
        int a,b;cin >> a >> b;
        a--;b--;
        vec[a]++;
        vec[b]++;
    }
    int c=0;
    for(int i=0;i<4;i++){
        if(vec[i]%2==1){
            c++;
            
        }
        if(c>=3){
            cout<<"NO"<<endl;
            return 0;
        }
    }
    cout<<"YES"<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define MOD 1000000007
#define INF 1e18
#define PI 3.14159265358979

using namespace std;

ll gcd(ll a, ll b);
ll power(ll n, ll k);
ll inv(ll n);
ll genfact(ll n, ll k);
ll fact(ll n);
ll nck(ll n, ll k);

int main(void){
  int a, b, c, d, e;
  cin >> a >> b >> c >> d;
  cout << min(a, b) + min(c, d) << endl;

  return 0;
}

ll gcd(ll a, ll b){
  if (a < b)
    return gcd(b, a);
  if (b == 0)
    return a;
  else
    return gcd(b, a % b);
}

ll power(ll n, ll k){
  ll res = 1;
  while(k > 0){
    if (k & 1) 
      res = res * n % MOD;
    n = n * n % MOD;
    k >>= 1;
  }
  return res;
}

ll genfact(ll n, ll k){

  ll res = 1;
  while (k >= 0){
    res = (res * (n - k)) % MOD;
    k--;
  }

  return res;
}

ll inv(ll n){
  return power(n, MOD - 2);
}

ll fact(ll n){
  return genfact(n, n - 1);
}

ll nck(ll n, ll k){
  if (k == 0)
    return 1;
  if (n <= 0)
    return 0;

  return ((genfact(n, k) % MOD) * inv(fact(k))) % MOD;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <functional>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <deque>
#include <ctime>
  
using namespace std;
  
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define pb push_back
#define mp make_pair
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second
#define println(X) cout<<X<<endl;
#define DBG(X) cout<<#X<<" : "<<X<<endl;
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const int INF = 1e9;
const ll LINF = 1e18;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;
const double PI = acos(-1);

int main(){
	int n, m;
	cin>>n>>m;
	vi a(n + 1);
	rep(i, n) cin>>a[i + 1];
	for(int k = 1; k <= m; k++){
		for(int i = 1; i < n; i++){
			if(a[i] % k > a[i+1] % k) swap(a[i], a[i + 1]);
		}
	}
	rep(i, n) cout<<a[i  +1]<<endl;
 }

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

int main(void){
  double maxv = -1,minv=(int)1e5;
  double v;
  while(cin>>v){
    if(v>maxv)maxv = v;
    else if(v<minv)minv = v;
  }
  cout<<maxv-minv<<endl;
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll gcd(ll a, ll b) {
    if (b == 0) return a;

    return gcd(b, a % b);
}

ll lcm(ll a,ll b) {
    return a * b / gcd(a, b);
}
int main(void){
    // Your code here!
    ll A,B;
    cin>>A>>B;
    cout<<lcm(A,B)<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <ctime>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <cassert>
#include <unordered_map>
#include <bitset>
#include <unordered_set>

using namespace std;

#define pb push_back
#define pp pop_back
#define f first
#define s second
#define mp make_pair
#define sz(a) (int)((a).size())
#ifdef _WIN32
#  define I64 "%I64d"
#else
#  define I64 "%lld"
#endif
#define fname "."

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

const int inf = (int)1e9 + 123;
const ll infl = (ll)1e18 + 123;
const double eps = 1e-9;

const int MAX_N = (int)1e5 + 5;
const int mod = (int)1e9 + 7;

int main() {
#ifdef DEBUG
    freopen("input.txt", "r", stdin);
#endif
    int n;
    scanf("%d", &n);
    deque < int > q;
    bool tp = 0;
    for (int i = 1, x; i <= n; i++) {
        scanf("%d", &x);
        if (!tp)
            q.push_back(x);
        else
            q.push_front(x);
        tp ^= 1;
    }
    if (tp)
        reverse(q.begin(), q.end());
    for (auto i : q)
        printf("%d ", i);
    return 0;
}


Measured memory_bytes: 2944
a,b,c,d=map(int,input().split())
if a<c:
    if c<=b<=d:
        print(b-c)
    elif b<c:
        print(0)
    elif d<b:
        print(d-c)
if a>=c:
    if a<=d<=b:
        print(d-a)
    elif d<a:
        print(0)
    elif d>b:
        print(b-a)




Measured memory_bytes: 3060
#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <climits>
#include <cmath>
#include <complex>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <iomanip>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <cstdint>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
#define MP make_pair
#define PB push_back
#define inf 1000000007
#define mod 1000000007
#define rep(i,n) for(int i = 0; i < (int)(n); ++i)
#define all(x) (x).begin(),(x).end()

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}
 
template<class T> inline bool chmax(T &a, T b){
    if(a<b){
        a = b;
        return true;
    }
    return false;
}

template<class T> inline bool chmin(T &a, T b){
    if(a>b){
        a = b;
        return true;
    }
    return false;
}

vector<int> inv(vector<int>&a){
    vector<int>b(a.size());
    rep(i,a.size()){
        b[a[i]] = i;
    }
    return b;
}

vector<int> mul(vector<int>&a,vector<int>&b){
    int n = a.size();
    vector<int> res(n);
    vector<int> ib = inv(b);
    rep(i,n){
        res[ib[i]] = a[i];
    }
    return res;
}
vector<int> calc(vector<int>a,int k){

    if(k==0){
        int n = a.size();
        vector<int> res(n);
        rep(i,n){
            res[i] = i;
        }
        return res;
    }
    if(k==1){
        return a;
    }
    if(k%2==0){
        vector<int> tmp = calc(a,k/2);
        return mul(tmp,tmp);
    }else{
        vector<int> tmp = calc(a,k/2);
        tmp = mul(tmp,tmp);
        return mul(a,tmp);
    }
}
int main(){
    int n,k;
    cin >> n >> k;
    vector<int>p(n),q(n);
    rep(i,n){
        cin >> p[i];
        p[i]--;
    }
    rep(i,n){
        cin >> q[i];
        q[i]--;
    }
    k--;
    int c = k/6;
    int d = k%6;
    vector<int> a,b;
    if(d==0){
        b = p;
    }else if(d==1){
        b = q;
    }else if(d==2){
        vector<int> tmp = inv(p);
        b = mul(q,tmp);
    }else if(d==3){ 
        b = inv(p);
    }else if(d==4){
        b = inv(q);
    }else if(d==5){
        vector<int> tmp = inv(q);
        b = mul(tmp,p);
    }
    vector<int> ip,iq;
    ip = inv(p);
    iq = inv(q);
    a = mul(q,ip);
    a = mul(a,iq);
    a = mul(a,p);
    a = calc(a,c);
    if(d >= 3){
        a = mul(a,q);
        a = mul(a,ip);
    }
    vector<int> ia = inv(a);
    vector<int> T = mul(a,b);
    vector<int>res = mul(T,ia);
    rep(i,n){
        cout << res[i]+1 << " ";
    }
    cout << endl;
    
    return 0;
}

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

using namespace std;

int main()
{
    int count[1000];
    int x[10];
    int y[10][10];
    int N;
    string S;
    int ans;
    int i, j, k;
    int idx;
    cin >> N;
    cin >> S;
    for(i = 0; i < 1000; i++) {
        count[i] = 0;
    }
    for(i = 0; i < 10; i++) {
        for(j = 0; j < 10; j++) {
            y[i][j] = 0;
        }
        x[i] = 0;
    }
    ans = 0;
    for(i = 0; i < S.length()-2; i++) {
        if(x[S[i]-'0'] == 1) {
            continue;
        }
        for(j = i+1; j < S.length()-1; j++) {
            if(y[S[i]-'0'][S[j]-'0'] == 1) {
                continue;
            }
            for(k = j+1; k < S.length(); k++) {
                idx = (S[i]-'0')*100 + (S[j]-'0')*10 + (S[k]-'0');
                if(count[idx] == 0) {
                    count[idx] = 1;
                    ans += 1;
                }
            }
            y[S[i]-'0'][S[j]-'0'] = 1;
        }
        x[S[i]-'0'] = 1;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <stack>
#include <string>
#include <algorithm> 
#include <set>
#include <sstream>
#include <bit>
#include <time.h>
#include <bitset>
#include <iomanip>
#include <queue>
typedef long long int ll;
using namespace std;

int main()
{
	ll MOD = pow(10, 9) + 7;
	int N; cin >> N;
	ll num1=1, num2=1, num3=1;
	ll ans;
	for (int i = 0; i < N; i++) {
		num1 *= 10;
		num1 = num1 % MOD;
		num2 *= 9;
		num2 = num2 % MOD;
		num3 *= 8;
		num3 = num3 % MOD;
	}
	ans = num1 - 2 * num2 + num3 + 3 * MOD;
	ans = ans % MOD;
	cout << ans << endl;
}

Measured memory_bytes: 3192
package main

import (
    "fmt"
    "sort"
)

func main(){
    var H, N int
    fmt.Scan(&H, &N)

    A := make([]int, N)

    for i:=0; i<N; i++{
        fmt.Scan(&A[i])
    }

    sort.Sort(sort.Reverse(sort.IntSlice(A)))

    for i:=0; i<N; i++{
        H -= A[i]
        if H<=0{
            break
        }
    }

    if H<=0{
        fmt.Println("Yes")
    }else{
        fmt.Println("No")
    }
    
    
}


Measured memory_bytes: 5504
//https://mrsrz.github.io/2020/03/13/ARC083E/
#include<cstdio>
#include<bitset>
#include<vector>
#include<cstdlib>
using namespace std;
const int N=1145;
int n,fa[N],X[N],a[N];
vector<int>G[N];
bitset<5001>b;
void dfs(int now){
    int sum=0;
    for(int to:G[now])dfs(to),sum+=a[to];
    b.reset();
    b.set(0);
    for(int to:G[now])b=(b<<X[to])|(b<<(a[to]-X[to]));
    int x=-1;
    for(int i=X[now];i>=0&&x==-1;--i)if(b.test(i))x=i;
    if(x==-1)exit(puts("IMPOSSIBLE")*0);
    a[now]=sum+X[now]-x;
}
int main(){
    scanf("%d",&n);
    for(int i=2;i<=n;++i)
        scanf("%d",fa+i),G[fa[i]].push_back(i);
    for(int i=1;i<=n;++i)scanf("%d",X+i);
    dfs(1);
    puts("POSSIBLE");
    return 0;
}

Measured memory_bytes: 1408
N=int(input())
li=[]
for i in range(N):
  a,b=input().split()
  b=str(100-int(b)).zfill(3)
  li.append(a+b)
lis = sorted(li)

for i in range(len(li)):
  for j in range(len(li)):
    if lis[i] == li[j]:
      print(j+1)

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

#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define loop(i,a,b) for(ll i=a;i<b;i++)
#define test() ll t;cin>>t;for(ll test = 1;test<=t;test++)
#define f first
#define s second
#define pb push_back
#define ins insert
#define nl cout<<"\n"
#define P 1000000007
#define N 100005
#define MOD(x) ((x%P)+P)%P
#define show(x) cout<<x<<" "
#define vec(v) loop(i,0,v.size()) show(v[i]); nl

int main()
{
	fastio();
	

	ll n,k;
	cin>>n>>k;

	ll mn = INT_MAX;
	ll dp[k+1] = {};

	ll arr[n];
	loop(i,0,n)
	{
		cin>>arr[i];
		mn = min(arr[i],mn);
	}

	loop(i,mn,k+1)
	{
		loop(j,0,n)
		{
			if(arr[j]>i)
				continue;

			if(dp[i-arr[j]]==0)
				dp[i] = 1;
		}
	}

	if(dp[k]==1)
		cout<<"First";
	else
		cout<<"Second";

	//cerr << "\nTime elapsed : " << 1000 * clock() / CLOCKS_PER_SEC << " ms\n";
	return 0;
}

Measured memory_bytes: 1024
using System;

namespace test
{
    class program
    {
        static void Main()
        {
            while (true)
            {
                string[] str = Console.ReadLine().Split(' ');
                int x = int.Parse(str[0]);
                int y = int.Parse(str[1]);
                if (x == 0 && y == 0) break;
                if (x > y) { int temp = x; x = y; y = temp; }
                Console.WriteLine(x + " " + y);
            }
        }
    }
}

Measured memory_bytes: 9300
#include<iostream>
using namespace std;
int N;
int sum,m=2e9;
main()
{
  cin>>N;
  for(int i=0;i<N;i++)
  {
    int A;cin>>A;sum+=A;
    if(A%10&&A<m)m=A;
  }
  cout<<(sum%10?sum:sum<m?0:sum-m)<<endl;
}

Measured memory_bytes: 256
N,K = map(int,input().split())
V = list(map(int,input().split()))
Vrev = V[::-1]
ans = 0
for a in range(N+1):
    for b in range(min(K-a,N-a)+1):
        VV = V[:a] + Vrev[:b]
        VV.sort(reverse=True)
        for k in range(min(K-a-b,len(VV))):
            if VV[-1] < 0:
                VV.pop()
        ans = max(sum(VV),ans)
print(ans)


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

using namespace std;

int main(){
  string S;
  cin >> S;
  int ans = 0;
  int tmp = 0;
  for (int i=0; i<3; i++){
    if (S[i] == 'R') tmp++;
    else {
      ans = max(ans, tmp);
      tmp = 0;
    }
  }
  ans = max(ans, tmp);
  cout << ans << "\n";
  return 0;
}

Measured memory_bytes: 3624
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <vector>

using namespace std;

int main() {
    string s, t;

    cin >> s >> t;

    reverse(t.begin(), t.end());

    if (s == t) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
h,w = map(int, input().split())
r=[[0 for i in range(h+2)] for j in range(w+2)]
for i in range(0,h):
  s=input()
  for j in range(0,w):
    if s[j]=='#':
      r[j+1][i+1]=-1
      for y in range(-1,2):
        for x in range(-1,2):
          if x==0 and y==0:
            continue
          elif r[j+1+x][i+1+y]!=-1:
            r[j+1+x][i+1+y]+=1
for i in range(0,h):
  mz=""
  for j in range(0,w):
    if r[j+1][i+1]==-1:
      mz=mz+'#'
    else:
      mz=mz+str(r[j+1][i+1])
  print(mz)
    
    


Measured memory_bytes: 3064
#include<cstdio>
#include<cmath>
#include<climits>
#include<algorithm>
#include<sstream>
#include<iostream>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<unordered_set>
#include<unordered_map>
#include<set>
#include<map>
#include<list>

using namespace std;

#define in(s) cin >> s
#define out(s) cout << s << endl
#define rep(i,n) for(int i=0; i<n; i++)
#define rept(i,a,b) for(int i=a; i<b; i++)
#define ll long long
#define MOD 1000000007

#define IMIN INT_MIN;
#define IMAX INT_MAX;

bool isPalindrome(const string &s) {
    stack<char> q;
    string ans;
    if (s.size() % 2 == 1) ans = s.substr(0, (s.size()-1)/2) + s.substr((s.size()+1)/2, (s.size()-1)/2);
    else ans = s;
    int N = ans.size();
    rep(i, N/2) {
        q.push(ans[i]);
        //out("push " << ans[i]);
    }
    rept(i, N/2, ans.size()) {
        //out("check " << ans[i]);
        if (q.top() != ans[i]) return false;
        q.pop();
    }
    return true;
}

int main(){
    //out(isPalindrome("akasaka"));
    //out(isPalindrome("prdrp"));
    //out(isPalindrome("abbalabba"));
    //out(isPalindrome("lassal"));
    string S;
    in(S);
    //out(S.substr(0, (S.size()-1)/2));
    //out(S.substr((S.size()+1)/2, (S.size()-1)/2));
    if (isPalindrome(S) &&
            isPalindrome(S.substr(0, (S.size()-1)/2)) &&
            isPalindrome(S.substr((S.size()+1)/2, (S.size()-1)/2)))
        out("Yes");
    else out("No");


	return 0;
}


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

#define PI 3.14159265359
#define rep(i,a,n) for(int i=a;i<(int)n;++i)
#define SZ(x) ((int)(x).size())	//size() unsigned -> int
#define descsort(a) sort(a.begin(),a.end(),std::greater<int>())
using namespace std;
typedef long long ll;
const ll INF = 1e9 + 7;

int main(void)
{
    ll a,b,c;
    cin>>a>>b>>c;
    if(a%2==0 || b%2==0 || c%2==0)cout<<0<<endl;
    else cout<<min({a*b,b*c,c*a})<<endl;
    return 0;
}

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

typedef long long ll;

const int maxn = 1e5 + 10;
int x[maxn], pos[maxn], w[maxn];
int l, p, s, t, n, m;
ll exc;

inline int read()
{
    int w = 0, t = 1; char ch = getchar();
    while (ch > '9' || ch < '0') {if (ch == '-') t = - 1; ch = getchar();}
    while (ch >= '0' && ch <= '9') { w = (w << 3) + (w << 1) + (ch ^ 48); ch = getchar();}
    return w * t;
}

int main()
{
    n = read(), l = read(), t = read();
    for( int i = 1; i <= n; i++)
        x[i] = read(),
        w[i] = read();
    for(int i = 1; i <= n; i++)
    {
        if (w[i] == 2) w[i] = -1;
        p = x[i] + w[i] * t;
        if (p > 0)
            (exc += p / l) %= n;
        else if (p < 0)
            (exc += (p + 1) / l - 1) %= n;
        pos[i] = (p % l + l) % l;
    }
    std::sort(pos + 1, pos + n + 1);
    exc = (exc + n) % n; 
    exc ++;
    for(int i = exc; i <= n; i++)
        printf("%d\n", pos[i]);
    for(int i = 1; i < exc; i++) printf("%d\n", pos[i]);
}


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

using namespace std;

int main()
{
    //system("chcp 65001");

    int A,B;
    cin >> A >> B;
    int i;

    for (i = 1;i <= 3;i++)
    {
        if((A * B * i) % 2 == 1)
        {
            cout << "Yes";
            goto end;
        }
    }

    cout << "No";
    end:

    //cout << N;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<string>
#include<vector>
#include<algorithm>
#include<utility>
#include<tuple>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<numeric>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>

using namespace std;

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

#define BIL ((ll)1e9)
#define MOD ((ll)1e9+7)
#define INF (1LL<<60)           //1LL<<63でオーバーフロー
#define inf (1<<29)             //1<<29でオーバーフロー

int main(int argc,char* argv[]){
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(20);

    int n;
    string s;
    cin >> n >> s;

    int maxval=0;
    for(int i=1;i<n;i++){
        string x=s.substr(0,i),y=s.substr(i);
        vector<bool> alph(26,false);
        for(int j=0;j<x.size();j++){
            char c=x[j];
            alph[c-'a']=true;
        }
        int val=0;
        for(int j=0;j<y.size();j++){
            char c=y[j];
            if(alph[c-'a']){
                val++;
                alph[c-'a']=false;
            }
        }
        maxval=max(maxval,val);
        if(maxval==26)break;
    }

    cout << maxval << endl;

    return 0;
}


Measured memory_bytes: 3624
#include<iostream>
#include<math.h>
using namespace std;
#define l long long
#define pb push_back
void frooty()
{
	float a,b,c,d;
	cin>>a>>b>>c>>d;
	int x=ceil(c/b);
	int y=ceil(a/d);
	if(y<x)
		cout<<"No"<<"\n";
	else
		cout<<"Yes"<<"\n";
}
int main()
{
	l t=1;
	//cin>>t;
	while(t--)
	{
		frooty();
	}
}

Measured memory_bytes: 3720
N = int(input())
A = list(map(int, input().split()))
cost = float('Inf')
check = 0

for m in range(min(A), max(A)+1):
    check = 0
    for a in range(len(A)):
        check += (A[a] - m) ** 2
    cost = min(cost, check)
print(cost)


Measured memory_bytes: 3060
X,K,D = map(int,input().split())
if K*D<=abs(X):
    print(abs(X)-K*D)
elif (K-(abs(X)//D))%2==0:
    print(abs(X)%D)
elif (K-(abs(X)//D))%2==1:
    print(-(abs(X)%D-D))

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

int main(){
    int n;cin>>n;
    int a[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    int c=0;
    for(int i=0;i<n;i++){
        if(a[i]!=i+1) c++;
    }
    if(c==2||c==0) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
}


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

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

using namespace std;

const int INF=1<<29;

string s;
int dp[1000002][2];

int dfs(int i,bool ge){
	if(i==s.length()) return ge?0:INF;

	if(dp[i][ge]!=-1) return dp[i][ge];

	int res=INF,a=s[i]-'0';
	if(ge){
		rep(d,10){
			res=min(res,dfs(i+1,d>=a)+d+(10+d-a)%10);
		}
	}
	else{
		for(int d=1;d<10;d++){
			res=min(res,dfs(i+1,d>a)+d+(10+(d-1)-a)%10);
		}
		res=min(res,dfs(i+1,false)+(9-a));
	}
	return dp[i][ge]=res;
}

int main(){
	memset(dp,-1,sizeof dp);

	cin>>s;
	reverse(s.begin(),s.end());
	s+="0";

	printf("%d\n",dfs(0,true));

	return 0;
}


Measured memory_bytes: 87428
#include  <stdio.h>
#include  <math.h>
int prime(int x)
{ 
	int temp,i,k;  
	temp=(int)(sqrt(x));  
	for(i=2;i<=temp;++i)      
	if(x%i==0)    
	{ k=0; 
		break; 
	}      
	if(i>temp)      
	k=1;
	return k;    
	}
int main(){        
	int x;    
	int i,n,count=0;  
	scanf("%d",&n);  
	for(i=0;i<n;i++)   {        
	scanf("%d",&x);         
	if(prime(x))  
	count++;   
	}    
	printf("%d\n",count);
	return 0;
}


Measured memory_bytes: 2052
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,int> P;
typedef pair<P,int> T;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define LLINF 1000000000000000ll
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define all(x) (x).begin(),(x).end()
#define sq(x) ((x)*(x))
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repn(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++)
#define EQ(a,b) (abs((a)-(b))<eps)
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;}
int X,Y,Z,K;
ll A[1010],B[1010],C[1010];
int main(){
	cin >> X >> Y >> Z >> K;
	for(int i=0;i<X;i++){
		cin >> A[i];
	}
	for(int i=0;i<Y;i++){
		cin >> B[i];
	}
	for(int i=0;i<Z;i++){
		cin >> C[i];
	}	
	sort(A,A+X);
	sort(B,B+Y);
	sort(C,C+Z);
	vector<ll> vec;
	for(int i=0;i<X;i++){
		for(int j=0;j<Y;j++){
			vec.pb(A[i]+B[j]);
		}
	}
	sort(all(vec),greater<ll>());
	vector<ll> ans;
	for(int i=0;i<min((int)vec.size(),(int)K);i++){
		for(int k=0;k<Z;k++){
			ans.pb(vec[i]+C[k]);
			//cout << vec[i] << ' ' << C[k] << endl;
		}
	}
	sort(all(ans),greater<ll>());
	for(int i=0;i<K;i++){
		cout << ans[i] << endl;
	}
	return 0;
}



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

#define REP( i, n )     for( int (i) = 0; (i) < (n); (i)++ )
#define ALL( a )        (a).begin(), (a).end()

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

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

const int INF = 1e9;
const ll LINF = 1e18;
const int MOD = 1e9 + 7;

int main(){
    int a, b; cin >> a >> b;
    int t = 0;
    REP( i, b - a ){
        t += i + 1;
    }

    cout << t - b << endl;
}


Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;
use std::collections::*;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char) 
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}



fn main() {
    let a: isize = read();
    let b: isize = read();
    let c = a-2*b;
    if c>0 {
        println!("{}", c);
    }
    else {
        println!("0");
    }
}

Measured memory_bytes: 2128
S = input()
T = input()

Skey = sorted(set(S),key=S.index)
Tkey = sorted(set(T),key=T.index)

for idx,i in enumerate(Skey):
  S = S.replace(i,str(idx))
for idx,i in enumerate(Tkey):
  T = T.replace(i,str(idx))

if S==T:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 3932
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define np next_permutation
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define pi acos(-1.0)
const ll INF = 1LL<<61;
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
ll jou(ll N, ll P){if(P==0) return 1;
  if(P%2==0){ll t = jou(N, P/2);return t*t % mod;
  }return (N * jou(N, P-1)) % mod;}  //jou(n,mod-2)で逆元
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'大文字'+=32;    で小文字に
//  cout << fixed << setprecision (20);   小数点以下2０桁まで
//実行時間制約2秒では２×10^8回くらいまで計算できる



int main() {
  int n,m;
  cin >> n >> m;

  vector<ll> p(n,0);
  rep(i,2*m){
    int x;
    cin>>x;
    p[x-1]++;
  }

  rep(i,n){
    if(p[i]%2==1){
      cout << "NO" << endl;
      return 0;
    }
  }

  cout << "YES" << endl;
}


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

using namespace std;


void solve() {
    int n; cin >> n;
    vector<int> a(n), indeg(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        a[i]--;
        indeg[a[i]]++;
    }
    if (n == 2) {
        cout << -1; return;
    }
    set<int> bucket;
    set<pair<int,int>> lookup;
    for (int i = 0; i < n; i++) {
        bucket.insert(i);
        lookup.insert({indeg[i], i});
    }
    vector<int> p(n);
    vector<bool> trk(n);
    const int L = 3; 
    for (int i = 0; i < n-L; i++) {
        auto it = --lookup.end();
        int cnt,z;
        tie(cnt,z) = *it;
        for (int x: bucket) {
            if (i == 0 || a[p[i-1]] != x) {
                if (z == x || cnt - (i && a[p[i-1]]==z) < n-i-1) {
                    p[i] = x;
                    break;
                }
            }
        }
        if (i > 0) {
            int x = a[p[i-1]];
            if (!trk[x]) {
                lookup.erase({indeg[x],x});
                lookup.insert({--indeg[x], x});
            }
        }
        trk[p[i]] = true;
        bucket.erase(p[i]);
        lookup.erase({indeg[p[i]], p[i]});
    }

    for (int i = max(0, n-L); i < n; i++) {
        p[i] = *bucket.begin();
        bucket.erase(p[i]);
    }
    do {
        bool yes = true;
        for (int i = max(1, n-L); i < n; i++) {
            if (a[p[i-1]] == p[i]) yes = false;
        }
        if (yes) {
            for (int x: p) cout << x+1 << ' ';
            return;
        }
    } while (next_permutation(p.begin(), p.end()));
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    cout << endl;
}


Measured memory_bytes: 11392
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools
import time,random

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
mod2 = 998244353
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def pe(s): return print(str(s), file=sys.stderr)
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)


def main():
    n,a,b = LI()
    if a % 2 == b % 2:
        return abs(a-b) // 2
    t = a + (b-a) // 2
    c = n - b + 1
    d = n - a + 1
    u = c + (d-c) // 2

    return min(t,u)


print(main())





Measured memory_bytes: 5464
#include<iostream>
#include<iomanip>
using namespace std;
 
 int main(){
	 int a,b;
	 char op;
	 while(1){
		 cin>>a>>op>>b;
		 if(op == '?') break;
		 
		 switch(op){
			 case '+':
			 cout<<a+b<<endl;
			 break;
			 
			 case '-':
			 cout<<a-b<<endl;
			 break;
			 
			 case '*':
			 cout<<a*b<<endl;
			 break;
			 
			 case '/':
			 cout<<a/b<<endl;
			 break;
		}
	}
		return 0;
}			 
			 



Measured memory_bytes: 3076
#include <cstdio>

const int maxn = 1e5 + 10;

char s[maxn];
int ans[maxn];

int main()
{
	int N;
	scanf("%d", &N);
	scanf("%s", s);
	bool flag = false;
	for (int i = 0; i < 2 && !flag; ++i)
		for (int j = 0; j < 2 && !flag; ++j)
		{
			ans[0] = i;
			ans[1] = j;
			for (int k = 2; k < N; ++k)
			{
				int t = s[k - 1] == 'x';
				t ^= ans[k - 1] ^ ans[k - 2];
				ans[k] = t;
			}
			if (ans[N - 2] ^ ans[N - 1] ^ ans[0] != (s[N - 1] == 'x'))
				continue;
			if (ans[N - 1] ^ ans[0] ^ ans[1] != (s[0] == 'x'))
				continue;
			for (int k = 0; k < N; ++k)
				putchar(ans[k] ? 'W' : 'S');
			puts("");
			flag = true;
		}
	if (!flag)
		puts("-1");
	return 0;
}


Measured memory_bytes: 768
using System;
using System.Linq;
using System.Collections.Generic;
using System.Numerics;
namespace Sample
{
  class Sample
  {
    static void Main(string[] args)
    {
     string N=Console.ReadLine();
      int len=N.Length;
      int sum=0;
      for(int i=0;i<len;i++){
       sum+=int.Parse(N.Substring(i,1)); 
      }
      if((sum%9)==0){
        Console.WriteLine("Yes");
      }else{
        Console.WriteLine("No");
      }
    }
    
  }

}


Measured memory_bytes: 32812
#include<stdio.h>
int main( )
{
	int a,b,c;
	scanf("%d %d %d",&a,&b,&c);
	if(a < b && b < c)
	{
		printf("Yes\n");
	}
	else 
	{
	    printf("No\n");	
	}	
    return 0;
}



Measured memory_bytes: 2080
#include<bits/stdc++.h>
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int a,b,c,k;
    cin>>a>>b>>c>>k;
    if(a >= k)
    {
        cout<<k<<endl;
    }
    else if(a+b >= k)
    {
        cout<<a<<endl;
    }
    else
    {
        cout<<(a-(k-a-b))<<endl;
    }
}



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

using namespace std;
int main()
{
	string a,b;
	cin>>a>>b;
	reverse(a.begin(),a.end());
	if(a==b)
	{
		cout<<"YES";
	}
	else
	{
		cout<<"NO";
	}
	return 0;	
} 

Measured memory_bytes: 256
ls = []
n = 0
while 1:
    ls1 = list(map(int,input().split()))
    #print(ls1)
    if ls1[0] == 0 and ls1[1] == 0:
        break
    else:
        ls1.sort()
        ls.append(list(ls1))
        #print(ls)
        ls1.clear()
        #print(ls1)
#print(len(ls))
#print(ls)
for i in range(len(ls)):
    print(ls[i][0],ls[i][1])



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

ll roundup(ll a, ll b){
    return (a + (b - 1)) / b;
}
 
int main(){
    ll H, W;
    cin >> H >> W;

    if(H == 1 || W == 1)
        cout << 1 << endl;
    else
        cout << roundup(H*W, 2) << endl;

}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<stdlib.h>
#include<time.h>
#include<math.h>
#include<string.h>
#include<algorithm>
#include<queue>
using namespace std;
char s[200050];

int main(void){
 int ans=0;
 long long int B_total=0;
 long long int before=0;
 long long int after=0;
 long long int sum=0;
 cin>>s;
 for(int i=0; i<strlen(s);++i){
  if(s[i]=='B'){
   before+=i;
   after+=(strlen(s)-B_total-1);
   B_total++;
  }
 }
 sum=after-before; 
 
 printf("%lld",sum);
 return 0;
}


Measured memory_bytes: 384
#include<iostream>
using namespace std;
long a,b,c,s,r;
main(){
  cin>>a>>b>>c;
  while(a%2==0&&b%2==0&&c%2==0&&r<50){
    r++;
    s=a+b+c;
    a=(s-a)/2;
    b=(s-b)/2;
    c=(s-c)/2;
  }
  cout<<(r==50?-1:r);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ios ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long
#define bit(x,j) ((x>>j)&1)
using namespace std;
// bitset<8>set1(p);
// __builtin_popcountll(x);
// bitset<100> b("1010");
ll int mod=1e9+7;//998244353;
int mul(ll int x, ll int y)
{
    return (x * 1ll * y) % mod;
}

int add(int x, int y)
{
    x += y;
    while(x >= mod) x -= mod;
    while(x < 0) x += mod;
    return x;
}

long long power(long long a, long long b,ll m) {
    a %= m;
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = mul(res,a);
        a = mul(a,a);
        b >>= 1;
    }
    return res%m;
    }


  ll int binomial(ll int n, ll int k) 
{ 
    ll int C[k+1]; 
    memset(C, 0, sizeof(C)); 
  
    C[0] = 1;  // nC0 is 1 
  
    for (ll int i = 1; i <= n; i++) 
    { 
        // Compute next row of pascal triangle using 
        // the previous row 
        for (int j = min(i, k); j > 0; j--) 
            C[j] = C[j]+C[j-1]; 
    } 
    return C[k]; 
} 
  vector<int> pr;
  bool prime[10000000];
void Sieve(ll int n) 
{ 
    memset(prime, true, sizeof(prime)); 
    prime[1]=false;
  
    for (int p=2; p*p<=n; p++) 
    { 
        if (prime[p] == true) 
        { 
            pr.push_back(p);
            for (int i=p*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    } 
}
 


//It reurns Fn,Fn+1
pair<int, int> fib (int n) {
    if (n == 0)
        return {0, 1};

    auto p = fib(n >> 1);
    int c = p.first * (2 * p.second - p.first);
    int d = p.first * p.first + p.second * p.second;
    if (n & 1)
        return {d, c + d};
    else
        return {c, d};
}
int sum(int n)  
{  
    if (n == 0)  
    return 0;  
    return (n % 10 + sum(n / 10));  
}  
ll int factorial(ll int n,ll int m) 
{ 
    ll int fact = 1; 
    for(int i=2;i<=n;i++) { 
        fact = (fact * i)%m; 
    } 
    return fact%m; 
} 

int reduce(int x, int y) 
{ 
    int d; 
    d = __gcd(x, y); 
  
    x = x / d; 
    y = y / d; 
    return x; 
} 


int main() {
  ios;
  ll int n;
  cin>>n;
  ll int a[n];
  for(int i=0;i<n;i++)
  {
      cin>>a[i];
  }
  ll int l=0;
  for(int i=1;i<n;i++)
  {
      l+=max(a[i-1]-a[i],0ll);
      if(a[i]<a[i-1])
      a[i]=a[i-1];
  }
  cout<<l<<endl;
}


Measured memory_bytes: 5192