akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

int const N = 1234567;

int was[N], g[N], ng[N], p[N], cycle[N];

vector<int> edges[N];

int dfs(int v, int bad) {
  if (g[v] >= 0) return g[v];
  for (int to : edges[v]) {
    if (to == bad) continue;
    dfs(to, bad);
  }
  int children = (int) edges[v].size();
  for (int i = 0; i <= children; i++) was[i] = false;
  for (int to : edges[v]) {
    if (to == bad) continue;
    int got = dfs(to, bad);
    if (got <= children) was[got] = true;
  }
  int i = 0;
  while (was[i]) ++i;
  g[v] = i;
  return i;
}

int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", p + i);
    --p[i];
    edges[p[i]].push_back(i);
    g[i] = -1;
  }
  int v = 0;
  for (int i = 0; i < n; i++) v = p[v];
  int cc = 0;
  int start = v;
  while (true) {
    cycle[cc++] = v;
    v = p[v];
    if (start == v) break;
  }
  dfs(cycle[0], cycle[cc - 1]);
  int gv = g[cycle[0]];
  for (int i = 0; i < n; i++) ng[i] = g[i];
  for (int value = gv; value <= gv + 1; value++) {
    for (int i = 0; i < n; i++) g[i] = ng[i];
    g[cycle[0]] = value;
    for (int i = 0; i < cc; i++) {
      int v = cycle[i];
      if (g[v] < 0) dfs(v, -1);
    }
    int last = cycle[cc - 1];
    if (value == gv && g[last] == gv) {
      continue;
    }
    if (value == gv + 1 && g[last] != gv) continue;
    puts("POSSIBLE");
    return 0;
  }
  puts("IMPOSSIBLE");
}


Measured memory_bytes: 46464
#include <bits/stdc++.h>
using namespace std; 
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ll long long
long long min(long long x,long long y){return (x<y ? x:y);}
long long max(long long x,long long y){return (x>y ? x:y);}
#define ld long double
int stoi(string s) {return atoi(s.c_str());}
int keta(ll x){ if(x<10){return 1;} else{return keta(x/10) + 1;}}

int main(){
  int n;
  int seki = 1;
  int wa = 0;
  REP(i,4){
    cin >> n;
    seki *= n;
    wa += n;
  }
  bool r = ( (seki==9*4*7) && (wa==1+9+7+4) );
  cout << (r? "YES\n":"NO\n");
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int INF = 1000000;
int main(){
  while (1){
    int n;
    cin >> n;
    if (n == 0){
      break;
    }
    vector<int> p(n), t(n);
    for (int i = 0; i < n; i++){
      cin >> p[i] >> t[i];
    }
    vector<vector<pair<int, int>>> E(n * 4 + 2);
    for (int i = 0; i < n - 1; i++){
      int d = abs(p[i + 1] - p[i]);
      int dt = t[i + 1] - t[i];
      for (int j = 0; j < 3; j++){
        if (d * (j + 1) <= dt){
          E[i * 4 + j].push_back(make_pair(d, (i + 1) * 4 + j + 1));
        }
      }
      for (int j = 0; j < 4; j++){
        if (p[i] * (j + 1) + p[i + 1] <= dt){
          E[i * 4 + j].push_back(make_pair(p[i] + p[i + 1], (i + 1) * 4 + 1));
        }
      }
    }
    if (p[0] <= t[0]){
      E[n * 4].push_back(make_pair(p[0], 1));
    }
    for (int j = 0; j < 4; j++){
      E[(n - 1) * 4 + j].push_back(make_pair(p[n - 1], n * 4 + 1));
    }
    vector<int> d(n * 4 + 2, INF);
    priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> pq;
    pq.push(make_pair(0, n * 4));
    while (!pq.empty()){
      int c = pq.top().first;
      int v = pq.top().second;
      pq.pop();
      if (d[v] == INF){
        d[v] = c;
        for (auto P : E[v]){
          int w = P.second;
          if (d[w] == INF){
            pq.push(make_pair(c + P.first, w));
          }
        }
      }
    }
    if (d[n * 4 + 1] == INF){
      int ans = 0;
      for (int i = 0; i < n; i++){
        for (int j = 0; j < 4; j++){
          if (d[i * 4 + j] != INF){
            ans = i + 1;
          }
        }
      }
      cout << "NG" << ' ' << ans + 1 << endl;
    } else {
      cout << "OK" << ' ' << d[n * 4 + 1] << endl;
    }
  }
}


Measured memory_bytes: 3084
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>
#include<iomanip>
using namespace std;


int main() {
	map<int, int> mp;
	long long int a, b = 0, num[200005], sum[200005] = {}, n, cou = 0, res = 0, memo,min=10000;
	string str,str2,str3;
	cin >> str2;

	n = str2.length();
	a = n;
	for (int i = 0; i < 26; i++) {
			str = str2;
			a = n;
			for (int j = 0; j < n; j++) {

				cou = 0;
				for (int k = 0; k < a; k++) {

					if (str[k] == ('a' + i)) {
						cou++;
					}
					if (cou == a) {
						if (min > j) { min = j; break; }
					}
				}
				a--;
				str3 = str;
				for (int k = 0; k < a; k++) {
					if (str[k] == i + 'a') {
						str3[k] = i + 'a';
					}
					else if (str[k + 1] == i + 'a') {
						str3[k] = i + 'a';
					}
				}
				str = str3;

			}
	}
	cout << min;
}


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

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

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

int main() {
	string s;
	cin>>s;
	bool c=false;
	if(s.at(0)==s.at(1)){
		if((s.at(2)==s.at(3))&&(s.at(0)!=s.at(2))){
			c=true;
		}
	}else if(s.at(0)==s.at(2)){
		if((s.at(1)==s.at(3))&&(s.at(0)!=s.at(1))){
			c=true;
		}
	}else if(s.at(0)==s.at(3)){
		if((s.at(1)==s.at(2))&&(s.at(0)!=s.at(1))){
			c=true;
		}
	}
	if(c){
		cout<<"Yes"<<endl;
	}else{
		cout<<"No"<<endl;
	}
	return 0;
}

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

signed main() {
  int N;
  cin >> N;
  
  vector<int> L(N);
  for( int i = 0; i < N; i++ ) cin >> L.at(i);
  sort(L.begin(), L.end());
  
  int Ckosu;
  int ans = 0;
  for( int i = 0; i < N; i++ ){ //A
    for( int j = i+1; j < N; j++ ){ //B
      //CはB以上A+B未満
      Ckosu = lower_bound(L.begin(), L.end(), L.at(i)+L.at(j)) - L.begin();
      ans += max(Ckosu - j-1, 0LL);
    }
  }
  cout << ans << endl;
  
}


Measured memory_bytes: 256
import java.io.*;
import java.util.*;

public class Main{

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

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());

		Set<String> set = new TreeSet<String>();

		for(int i = 0; i < n; i++){
			String[] coms = br.readLine().split(" ");
			if(coms[0].equals("insert")){
				set.add(coms[1]);
			}else if(coms[0].equals("find")){
				System.out.printf("%s\n",set.contains(coms[1])? "yes" : "no");
			
			}
		}
	}
}

Measured memory_bytes: 258756
#include <iostream>
#include <numeric>
#include <stdio.h>
#include <iomanip>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;
using ll = long long;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
int Max(long long(a), long long(b), long long(c)) {
	return max(max(a,b), c);
}
int Min(long long(a), long long(b), long long(c)) {
	return min(min(a, b), c);
}

int cnt(ll N) {
	int digits = 0;

	while (N > 0) {
		N /= 10;
		digits++;
	}

	return digits;
}



int main() {
	ll N,M;
	cin >>N>>M;
	if (N % 2 == 1) {
		rep(i, M) {
			cout << i + 1 <<" "<< N - i << endl;
		}
	}
	else if (N %4== 0) {
		rep(i, N / 4) {
			if (i < M) {
				cout << i + 1 << " " << N - i << endl;
			}
		}
		for (ll i = N / 4; i < M; i++) {
			cout << i + 2 << " " << N - i << endl;
		}
	}
	else{ 
		rep(i, (N-2) / 4) {
			if (i < M) {
			cout << i + 1 << " " << N - i << endl;
			}
		}
		for (ll i = (N-2) / 4; i < M; i++) {
			cout << i + 2 << " " << N - i << endl;
		}
	}
	}

	
	
	

	


Measured memory_bytes: 3636
#include<cstring>
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
 
int main(){
    long long int d, t, s;
    cin >> d >> t >> s;
    if (t*s >= d) printf("Yes");
    else printf("No");
    return 0;
}

Measured memory_bytes: 3660
#include <iostream>
#include <cstdio>
using namespace std;
int main(void)
{
    int w, n;
    cin >> w >> n;
    int m[w];
    for (int i = 0; i < w; i++)
    {
        m[i] = i;
    }
    for (int i = 0; i < n; i++)
    {
        int a, b;
        scanf("%d,%d", &a, &b);
        int t = m[a - 1];
        m[a - 1] = m[b - 1];
        m[b - 1] = t;
    }
    for (int i = 0; i < w; i++)
    {
        cout << m[i] + 1 << endl;
    }
    return 0;
}



Measured memory_bytes: 3152
#include <iostream>
#include <algorithm>

using namespace std;

int main() {
  int in[5];
  cin >> in[0] >> in[1] >> in[2] >> in[3] >> in[4];
  sort(in, in + 5, greater<int>());
  for (int i = 0; i < 5; i++) {
    if (i < 4)
      cout << in[i] << " ";
    else
      cout << in[i] << endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <cmath>
#include <climits>
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include <string>
#include <stack>
#include <algorithm>
#include <map>
#include <numeric>
#include <set>
using namespace std;
// scanf
#pragma warning(disable: 4996)
// v:vector  type:型  order:greater or less
#define _sort(v,type,order) do { sort(v.begin(),v.end(),order<type>()); } while(0)
// vector 要素の総和算出
// v:vector  default_value:初期値
#define _sum(v,default_value) accumulate(v.begin(),v.end(),default_value )
// vector 最大値( return ite )
#define _max_element(v) max_element(v.begin(),v.end())
// vector 最大値が格納されている要素値
#define _max_element_number(v) distance(v.begin(),max_element(v.begin(),v.end()))

//set<uint32_t> member;	// 重複するデータを保持する事はできない member.insert(2) member.insert(2) ⇒ member.count(2)は1
//multiset<uint32_t> v;	// 重複するデータも保持する事はできる   member.insert(2) member.insert(2) ⇒ member.count(2)は2

// 丸め
#define _round(v) round(v)
// 2乗 / 3乗
#define _square(v) pow(v,2)
#define _cube(v)   pow(v,3)
// 大小判定
#define _max(x,y) max(x,y)-
#define _min(x,y) min(x,y)
// string ⇒ int
#define _stringtoi(s) stoi(s)
// double 平方根
#define _sqrt(x) sqrt(x)
// double 引数 x 以上で最小の整数値 ex) 3.30303 ⇒ 4
#define _ceil(x) ceil(x)
// 指定された要素以上の値が現れる最初の位置のイテレータを取得する
#define _lower_bound(v,min) lower_bound(v.begin(), v.end(), min)
// 指定された要素より大きい値が現れる最初の位置のイテレータを取得する
#define _upper_bound(v,min) upper_bound(v.begin(), v.end(), min)

// 順列 n個の数が与えられる
// 0,1,2,...,n-1
// 全ての並べ方を1行ごとに出力する
// ex 0 1 2 / 0 2 1 / 1 0 2 / 1 2 0 / 2 0 1 / 2 1 0
#define _next_permutation(v) do {   \
	for (auto num : v) {            \
		printf("%d ", num);         \
	}                               \
	printf("\n");                   \
} while (next_permutation(v.begin(), v.end()))

// 絶対値
static int32_t _abs(const int32_t x) { return  (x > 0 ? x : -x); }
// 最大公約数
static int gcd(int a, int b)
{
	if (a < b) {
		a ^= b;
		b ^= a;
		a ^= b;
	}
	return b ? gcd(b, a % b) : a;
}
// 最小公倍数
static int lcm(int a, int b) { return a * b / gcd(a, b); }
// 多次元 std::vector 生成
template<class T>
vector<T> make_vec(size_t a) { return vector<T>(a); }
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts) { return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...)); }
// ex) auto dp = make_vec<uint64_t>(SIZE + 1, 2, 2);



// 169 C
// https://atcoder.jp/contests/abc169/tasks/abc169_c
int main()
{
	uint64_t a;
	double _b;
	uint32_t b;
	cin >> a >> _b;

	b = _round(_b * 100);

	printf("%llu\n", a*b / 100);
	return 0;
}


Measured memory_bytes: 3824
#ifdef _WIN32
#include "stdc++.h"
#else
#include <bits/stdc++.h>
#endif

// 継承可能な型
template <class Type>
struct IN : Type
{
	IN()
	{
		std::cin >> *this;
	}
};

// 継承不可能な型
template <class Type>
struct IN_
{
	Type val;

	IN_()
	{
		std::cin >> val;
	}

	operator Type&()
	{
		return val;
	}

	IN_<Type>& operator=(const Type& _value)
	{
		val = _value;
		return *this;
	}
};

template <class Char, class Type>
std::basic_ostream<Char>& operator <<(std::basic_ostream<Char>& os, const IN_<Type>& value)
{
	return os << value.val;
}

template <class Char, class Type>
std::basic_istream<Char>& operator >>(std::basic_istream<Char>& is, IN_<Type>& value)
{
	return is >> value.val;
}

template <class Type>
void OUT(const Type& value)
{
	std::cout << value << std::endl;
}

template <class Type, class ... Args>
void OUT(const Type& value, const Args& ... args)
{
	std::cout << value << ' ';
	OUT(args...);
}

void YES()
{
	OUT("YES");
}
void NO()
{
	OUT("NO");
}
void YESNO(const bool cond)
{
	OUT(cond ? "YES" : "NO");
}

void Yes()
{
	OUT("Yes");
}
void No()
{
	OUT("No");
}
void YesNo(const bool cond)
{
	OUT(cond ? "Yes" : "No");
}

using ll = long long;
using inll = IN_<ll>;
using vll = std::vector<ll>;
using setll = std::set<ll>;
using msetll = std::multiset<ll>;
using instr = IN<std::string>;

// 階乗を計算 O(N) (N=10^7 で O(10^7))
ll factorial(ll n)
{
	for (ll i = n - 1; i > 1; --i)
		n *= i;
	return n;
}

// nCrを計算 O(N) (N=10^7 で O(10^7))
ll ncr(const ll n, ll r)
{
	if (r * 2 > n) r = n - r;

	ll dividend = 1, divisor = 1;

	for (ll i = 1; i <= r; ++i) {
		dividend *= n - i + 1;
		divisor *= i;
	}

	return dividend / divisor;
}

// 素数判定 O(sqrt(N)) (N=10^7 で O(10^3))
bool isprime(const ll num)
{
    if (num < 2) return false;
    if (num == 2) return true;
    if (num % 2 == 0) return false;

    double sqrtNum = sqrt(num);
    for (ll i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0) return false;
    }

    return true;
}

// 各桁の和を計算 O(logN) (N=10^7 で O(7))
ll digsum(ll n)
{
	ll sum = 0;
	while(n != 0){
		sum += n % 10;
		n /= 10;
	}
	return sum;
}

#define FOR(i, m, n) for (ll (i) = (m); (i) < (n); ++(i))
#define REP(i, n) for (ll (i) = 0; (i) < (n); ++(i))
#define REPR(i, n) for (ll (i) = (n); (i) >= 0; --(i))
#define ITRREP(it, v) for (auto (it) = (v).begin(); (it) != (v).end(); ++(it))
#define ITRREPR(it, v) for (auto (it) = (v).rbegin(); (it) != (v).rend(); ++(it))
#define DIVUP(a, b) (((a) + (b) - 1) / (b))

void Main();

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

	Main();

#ifdef _DEBUG
	system("pause");
#endif

	return 0;
}

using namespace std;

//////////////////////////////

void Main()
{
	inll n;

	REP(i, 26)
	{
		REP(j, 15)
		{
			if (i * 4 + j * 7 == n) return Yes();
		}
	}
	
	return No();
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL)
#define li long int
#define ll long long int
#define vec(x) vector<x> 
#define st(x) set<x> 
#define mpp(x,y) map<x,y>
#define qq(x) queue<x>
#define pqq(x) priority_queue<x> 
#define pi(x,y) pair<x,y>
#define forf(i,x,y) for(ll i=x;i<y;i++)
#define forl(i,x) for(ll i=x-1;i>=0;i--)
#define rev(x) reverse(x.begin(),x.end())
#define mem(x,a) memset(x,a,sizeof(x))
#define mod 1000000007
#define nxt_per(x) next_permutation(x.begin(),x.end())
#define pb push_back
#define pob pop_back
#define pp push
#define po pop
#define ub upper_bound
#define lb lower_bound
#define mp make_pair
#define vp(x,y) vec(pi(x,y) )
#define vv(x) vector<vector<x> >
#define all(x) x.begin(),x.end()

using namespace std;

int main()
{
	fastio;
	/*#ifndef ONLINE_JUDGE
    	freopen("input.txt","r",stdin);
    	freopen("output.txt","w",stdout);
	#endif*/
	
	string ss;
	cin>>ss;
	ll k;
	cin>>k;
	if(k==1)
	{	cout<<ss[0];
		return 0;
	}
	st(int) s;
	int f=200;
	forf(i,0,ss.size())
	{	if(ss[i]!='1')
			s.insert(i+1);
	}
	if(!s.empty())
		f=*s.begin();
	if(k<f)
		cout<<1;
	else
		cout<<ss[f-1];
	return 0;
}

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

int main() {
  int H, W;
  cin >> H >> W;

  // ここにプログラムを追記
  string S1, S2 = "";
  int cnt=0;
  
  for(int i=0; i<H; i++) {
    cin >> S1;
    S2 += S1;
  }
  
  for(int i=0; i<H; i++) {
    for(int j=0; j<W; j++) {
      if(j!=0 && S2.at(j + i*W - 1)=='#') {
        cnt++;
      }
      if(j!=W-1 && S2.at(j + i*W + 1)=='#') {
        cnt++;
      }
      if(j!=0 && i!=H-1 && S2.at(j + i*W + W-1)=='#') {
        cnt++;
      }
      if(i!=H-1 && S2.at(j + i*W + W)=='#') {
        cnt++;
      }
      if(j!=W-1 && i!=H-1 && S2.at(j + i*W + W+1)=='#') {
        cnt++;
      }
      if(j!=0 && i!=0 && S2.at(j + i*W - W-1)=='#') {
        cnt++;
      }
      if(i!=0 && S2.at(j + i*W - W)=='#') {
        cnt++;
      }
      if(j!=W-1 && i!=0 && S2.at(j + i*W - W+1)=='#') {
        cnt++;
      }
      
      if(S2.at(j + i*W)=='.') {
        S2.at(j + i*W) = '0' + cnt;
      }
      cnt = 0;
    }
  }
  
  for(int i=0; i<H; i++) {
    for(int j=0; j<W; j++) {
      cout << S2.at(j + i*W);
    }
    cout << endl;
  }
}

Measured memory_bytes: 3580
A = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
h, w = gets.split.map(&:to_i)
s = h.times.map { gets.chomp.split }
row = nil
col = nil
h.times do |i|
  w.times do |j|
    if s[i][j] == "snuke"
      row = i
      col = j
      break
    end
  end
  break if !row.nil?
end
puts "#{A[col]}#{row + 1}"


Measured memory_bytes: 1788
#include<bits/stdc++.h>
int main(){
	int baris, kolom;
	int sum, totalSum=0;
	int ang[105][105];
	scanf("%d %d", &baris, &kolom);
	
	for(int i = 0; i < baris+1; i++){
        for(int j = 0; j < kolom+1; j++){
            ang[i][j] = 0;
        }
    }
	for(int i=0; i<baris; i++){
		for(int j=0; j<kolom; j++){
			scanf("%d", &ang[i][j]);
		}
	}
	for(int i=0; i<baris; i++){
		sum=0;
		for(int j=0; j<kolom; j++){
			sum += ang[i][j];
			ang[baris][j] += ang[i][j];
		}
		ang[i][kolom] = sum;
		totalSum += sum;
	}
	ang[baris][kolom] = totalSum;
	for(int i=0; i<=baris; i++){
		for(int j=0; j<kolom; j++){
			printf("%d ", ang[i][j]);
		}
		printf("%d\n", ang[i][kolom]);
	}
}


Measured memory_bytes: 3232
def sub(m, line, row, a, b):
    one_ans = "T"
    for j in range(1, m):
        a_match = a[line + j][row : row + m]
        #print(a_match)
        if b[j] == a_match:
            one_ans += "T"
        else:
            one_ans += "F"
    return (one_ans)

def resolve_mine(): #quote
    n, m = map(int, input().split())
    
    a = list()
    for i in range(n):
        line = input()
        a.append(line)
    
    b = list()
    for i in range(m):
        line = input()
        b.append(line)
    
    ans = list()
    for a_line in range(n - m + 1):
        count = a[a_line].count(b[0])
        #print(f"count is {count}, a_line is {a_line}")
        
        if count == 1:
            line, row = a_line, a[a_line].find(b[0])
            one_ans = sub(m, line, row, a, b)
            ans.append(one_ans)
        elif count > 1:
            line = a_line
            formar_row = -1
            for counter in range(count):
                formar_row = a[a_line].find(b[0], formar_row + 1)
                row = formar_row
                one_ans = sub(m, line, row, a, b)
                ans.append(one_ans)

    #print(ans)
    result = "No"
    for an in ans:
        if "T" * m == an:
            result = "Yes"
            break

    print(result)

resolve_mine()

Measured memory_bytes: 3064
N = int(input())
h = list(map(int ,input().split(" ")))
flag = 0
h.append(0)
ct = 0
while sum(h):
    for i in range(len(h)):
        if h[i]:
            h[i] = h[i] - 1
            flag = 1
        else:
            if flag:
                ct += 1
                flag = 0
print(ct)


Measured memory_bytes: 3060
def m():
    N = int(input())
    S = input()

    left = 0
    right = 0
    t = 0
    for c in list(S):
        if c == '(':
            t += 1
        if c == ')':
            if t > 0:
                t -= 1
            else:
                left += 1
    right = t
    print('(' * left + S + right * ')')


m()


Measured memory_bytes: 38384
n=int(input())
p=len(list(str(n)))
s=[3,5,7]
l=0
for i in range(2,p+1):
    for j in range(l,l+3**i):
        s+=[s[j]*10+3,s[j]*10+5,s[j]*10+7]
    else:
        l+=3**i
s=s[12:]
c=0
for i in range(len(s)):
    if s[i]<=n:
        if len(set(list(str(s[i]))))==3:
            c+=1
print(c)

Measured memory_bytes: 7696
//?????????????????????????¨???????pair???????????¨???????????????????????£????????§31-179573????????????????????????????????????????????????????????????init(n)???????????????????????¨????°????????????????30?????????????????????????????£??????
#include<iostream>
#include<utility>
#include<vector>
#include<algorithm>
using namespace std;

int P[10010];
void init(int N){
  for (int i=0;i<=N;i++) P[i]=i;
}

int root(int a){
  if(P[a]==a) return a;
  return(P[a] = root(P[a]));
}

bool is_same_set(int a,int b){
  return root(a) == root(b);
}
void unite(int a,int b){
  P[root(a)] = root(b);
}

int main(){
  int n;
  cin>>n;
  init(n);
  int A[101][101];
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      cin >> A[i][j];
    }
  }
  int cost[10010],src[10010],dst[10010];
  int M=0;
  for(int r=0;r<n;r++){
    for(int c=r+1;c<n;c++){
      if(A[r][c]>-1){
	cost[M]=A[r][c];
	src[M]=r;
	dst[M]=c;
	M+=1;
      }
    }
  }
  pair<int,int> edges[10010];
  for(int i=0;i<M;i++){
    edges[i] =make_pair(cost[i],i);
  }

  sort(edges,edges+M);
  int s=0;
  for(int i=0;i<M;i++){
    int k= edges[i].second;
    int p=src[k];
    int q=dst[k];
    if(is_same_set(p,q)) {
      continue;
    }
    unite(p,q);
    s+=edges[i].first;
  }
  cout << s<<endl;
}

Measured memory_bytes: 3184
#include <fcntl.h>
#include <unistd.h>
#include <sys/mman.h>
#include <string.h>
#include <stdio.h>

const char solve_[] = { 0x6a, 0x00, 0x48, 0x89, 0xf8, 0x48, 0x01, 0xc0, 0x48, 0x01, 0xc0, 0x48, 0x01, 0xf0, 0x50, 0x56, 0x41, 0x58, 0x49, 0x83, 0xf8, 0x00, 0x74, 0x50, 0x41, 0x59, 0x4c, 0x89, 0xc9, 0x4c, 0x29, 0xc1, 0x48, 0x83, 0xf9, 0x04, 0x76, 0xea, 0x4d, 0x89, 0xc2, 0x4d, 0x89, 0xcb, 0x41, 0x8b, 0x00, 0x49, 0x83, 0xc2, 0x04, 0x41, 0x0f, 0xbe, 0x0a, 0x39, 0xc1, 0x73, 0xf4, 0x49, 0x83, 0xeb, 0x04, 0x41, 0x0f, 0xbe, 0x13, 0x39, 0xc2, 0x72, 0xf4, 0x4d, 0x39, 0xd3, 0x76, 0x08, 0x41, 0x89, 0x0b, 0x41, 0x89, 0x12, 0xeb, 0xdb, 0x41, 0x89, 0x10, 0x41, 0x89, 0x03, 0x41, 0x53, 0x41, 0x50, 0x49, 0x83, 0xc3, 0x04, 0x41, 0x51, 0x41, 0x53, 0xeb, 0xa8, 0x48, 0x31, 0xc0, 0x48, 0x31, 0xc9, 0x48, 0x31, 0xd2, 0x48, 0x39, 0xcf, 0x0f, 0x84, 0x00, 0x00, 0x00, 0x00, 0x48, 0x83, 0xfa, 0x00, 0x74, 0x09, 0x48, 0x2b, 0x04, 0x8e, 0x48, 0xff, 0xca, 0xeb, 0x07, 0x48, 0x03, 0x04, 0x8e, 0x48, 0xff, 0xc2, 0x48, 0xff, 0xc1, 0x48, 0x39, 0xcf, 0x77, 0xd9, 0xc3 };

int main(void){
	int fd = open("/dev/zero", O_RDONLY);
	int (*solve)(int, int *) = mmap(NULL, sizeof solve_, PROT_WRITE | PROT_EXEC, MAP_PRIVATE, fd, 0);
	memcpy(solve, solve_, sizeof solve_);

	int n, a[123];
	scanf("%d", &n);
	for(int i = 0; i < n; ++i) scanf("%d", a + i);
	printf("%d\n", solve(n, a));

	close(fd);
	munmap(solve, sizeof solve_);
	return 0;
}


Measured memory_bytes: 384
#include <iostream>

using namespace std;

int main(void){
  int n, k, an[101] = {0}, d, a, i, j, count = 0;
  cin >> n >> k;
  for(i = 0; i < k; i++){
    cin >> a;
    for(j = 0; j < a; j++){
      cin >> d;
      an[d]++;
    }
  }
  for(i = 1; i <= n; i++){
    if(an[i] == 0){
      count++;
    }
  }
  cout << count << endl;
  return 0;
}
  

Measured memory_bytes: 3580
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>

long max2(long a,long b){
    return a>=b?a:b;
}

int main(void){
    long n,i,a=0,max=0;
    scanf("%ld",&n);
    long h[n];
    for(i=0;i<n;i++){
        scanf("%ld",&h[i]);
    }
    for(i=0;i<n;i++){
        if(h[i]>=h[i+1]){
            a++;
        }else{
            max=max2(a,max);
            a=0;
        }
    }
    printf("%ld\n",max);
    return 0;
}


Measured memory_bytes: 896
//#pragma GCC optimize ("O3")
//#pragma GCC target ("sse4")
//#pragma comment(linker, "/stack:200000000")
#include <bits/stdc++.h>

using namespace std;
typedef vector <int> vi;
typedef long long ll;
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;

#define MP make_pair
#define PB push_back
#define EB emplace_back
#define F first
#define S second
#define LB lower_bound
#define UB upper_bound

#define SZ(x) (int)x.size()
#define ALL(x) begin(x), end(x)
#define RALL(x) rbegin(x), rend(x)
#define RSZ resize
#define INS insert
#define REP(i,a,b) for (int i = (a); i <= (b); i++)
#define PER(i,a,b) for (int i = (b); i >= (a); i--)
#define TRAV(a,x) for (auto& a : x)

int nxt(){int x;cin>>x;return x;}
ll nxtll(){ll x;cin>>x;return x;}


signed main() {
    ios_base::sync_with_stdio(0);cin.tie(0);
    int a=nxt(),b=nxt();
    if(a<=9&&b<=9)cout<<a*b;
    else cout<<-1;
}


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

using namespace std;
int main(){
  int n;
  vector <int> p;
  int count = 0;
  cin >>n;
  for(int i = 0; i < n; i++){
    int x;
    cin >>x;
    p.push_back(x);
  }
  for(int i = 0;i < n-2;i++){
    if(p[i]<p[i+1] && p[i+1]<p[i+2] ||p[i]>p[i+1] && p[i+1]>p[i+2])count++;
  }
  cout <<count <<endl;
}


Measured memory_bytes: 384
import java.util.Arrays;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        try (Scanner scanner = new Scanner(System.in)) {
            int N = scanner.nextInt();
            int[] A = new int[N];
            for (int i = 0; i < N; i++) {
                A[i] = scanner.nextInt();
            }
            bubbleSort(A, N);
            System.out.println(Arrays.stream(A).mapToObj(a -> "" + a)
                    .reduce((a, b) -> a + " " + b).get());
            System.out.println(count);
        }
    }

    static int count = 0;
    public static void bubbleSort(int[] A, int N) {
        count = 0;
        boolean flag = true;
        while (flag) {
            flag = false;
            for (int j = N - 1; j >= 1; j--) {
                if (A[j] < A[j - 1]) {
                    int tmp = A[j];
                    A[j] = A[j - 1];
                    A[j - 1] = tmp;
                    flag = true;
                    count++;
                }
            }
        }
    }
}

Measured memory_bytes: 32372
#define rep(i,a,b) for (int i = (a); i < (b); i++)
#define _USE_MATH_DEFINES
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <math.h>
#include <complex>
#include <cassert>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> p;
typedef complex<double> com;
const int mod = 1e9 + 7;
const int MOD = 998244353;
const ll INF = 1e18;


int main() {
	int n,k; cin >> n >> k;
	ll ans = 0;
	rep(i, k + 1, n + 1) {
		ans += (ll)(n / i) * (i-k);
		ans += max(0, (n % i) - (k == 0 ? 1 : k)+1);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
X = int(input())
K = int(input())
R = [int(x) for x in reversed(input().split())]
for i in range(0,K-1): R[i] -= R[i+1]
Q = int(input())

aM = X
M = X
am = 0
m = 0
now = 0
sign = -1
timer = R.pop()

def Go(time):
    global aM,M,am,m
    if sign==1:
        if m+time>X:
            m = X
            M = X
            aM = am
        elif M+time>X:
            m += time
            M = X
            aM = am + M - m
        else:
            m += time
            M += time
    else:
        if M-time<0:
            m = 0
            M = 0
            am = aM
        elif m-time<0:
            m = 0
            M -= time
            am = aM + m - M
        else:
            m -= time
            M -= time

for i in range(Q):
    t,a = [int(x) for x in input().split()]
    t -= now
    now += t
    
    while t>=timer:
        Go(timer)
        t -= timer
        if R:
            timer = R.pop()
        else:
            timer = float("inf")
        sign *= -1
    
    Go(t)
    timer -= t
    
    if a<am:
        print(m)
    elif a>aM:
        print(M)
    else:
        print(m+a-am)

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

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


#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))

int dx4[4] = {1,0,-1,0}, dy4[4] = {0,1,0,-1};


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

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N,K;
string S;
vector<pair<int,int>> C;
ll SS[101010];

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>K>>S;
	FORR(s,S) {
		if(C.empty()||C.back().first!=s) C.push_back({s,0});
		C.back().second++;
	}
	ll ma=0;
	FOR(i,C.size()) {
		SS[i+1]=SS[i]+C[i].second;
		int tar;
		if(C[i].first=='0') {
			tar=max(0,i+1-(2*K));
		}
		else {
			tar=max(0,i+1-(2*K+1));
		}
		ma=max(ma,SS[i+1]-SS[tar]);
		
	}
	cout<<ma<<endl;
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 2116
#include <iostream>
#include <vector>
// #include<list>
#include <algorithm>

using namespace std;
#define l long long
#define vi vector<int>
#define vvi vector<vector<int>>
#define rep(i,n) for (i = 0; i < n; i++) 
#define REP(i,k,n) for (i = k; i <= n; i++) 
#define REPR(i,k,n) for (i = k; i >= n; i--) 

bool hi(string s)
{
  for(int i=0;i<s.length();i++)
  {
    if(s[i]=='h' && s[i+1]=='i')
    {
      i++;
    }
    else
    	return false;
  }
  return true;
}

int  main(int arg,char** argc)
{
    ios_base::sync_with_stdio(false);
    string s;
  cin>>s;
  	if(hi(s))
      cout<<"Yes";
     else
       cout<<"No";
    return 0;
}


Measured memory_bytes: 256
import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, core.stdc.stdlib;

immutable int INF = 1 << 29;

void main() {
    auto X = readln.chomp.to!long;

    long[] F;
    for (long i = 1; i * i <= X; ++i) {
        if (X % i == 0) {
            F ~= i;
            if (i * i != X) {
                F ~= X / i;
            }
        }
    }

    foreach (f; F) for (long a = f, b = 0; a^^5-b^^5 <= X; ++a, ++b) {
        if (a^^5 - b^^5 == X) {
            writeln(a, " ", b);
            return;
        }
    }

    foreach (f; F) for (long a = f-1, b = -1; a >= 0; --a, --b) {
        if (a^^5 - b^^5 == X) {
            writeln(a, " ", b);
            return;
        }
    }
}


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

typedef long long ll;
using namespace std;

const int mod = 1000000007;

struct mint {
    ll x; // typedef long long ll;
    mint(ll x = 0) : x((x % mod + mod) % mod) {}

    mint operator-() const { return mint(-x); }

    mint &operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }

    mint &operator-=(const mint a) {
        if ((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }

    mint &operator*=(const mint a) {
        (x *= a.x) %= mod;
        return *this;
    }

    mint operator+(const mint a) const {
        mint res(*this);
        return res += a;
    }

    mint operator-(const mint a) const {
        mint res(*this);
        return res -= a;
    }

    mint operator*(const mint a) const {
        mint res(*this);
        return res *= a;
    }

    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const {
        return pow(mod - 2);
    }

    mint &operator/=(const mint a) {
        return (*this) *= a.inv();
    }

    mint operator/(const mint a) const {
        mint res(*this);
        return res /= a;
    }
};

struct combination {
    vector<mint> fact, ifact;

    combination(int n) : fact(n + 1), ifact(n + 1) {
        assert(n < mod);
        fact[0] = 1;
        for (int i = 1; i <= n; ++i) fact[i] = fact[i - 1] * i;
        ifact[n] = fact[n].inv();
        for (int i = n; i >= 1; --i) ifact[i - 1] = ifact[i] * i;
    }

    mint operator()(int n, int k) {
        if (k < 0 || k > n) return 0;
        return fact[n] * ifact[k] * ifact[n - k];
    }
};

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

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

    if (k == 1) {
        cout << 0;
        return 0;
    }

    sort(a.begin(), a.end());
    mint max_sum = 0;
    auto c = combination(n);
    for (int i = 0; i < n; ++i) {
        mint maxv = a[i];
        max_sum += c(i, k - 1) * maxv;
    }

    sort(a.begin(), a.end(), greater<>());
    mint min_sum = 0;
    for (int i = 0; i < n; ++i) {
        mint minv = a[i];
        min_sum += c(i, k - 1) * minv;
    }

    mint ans = max_sum - min_sum;
    cout << ans.x;

    return 0;
}


Measured memory_bytes: 2176
//libraries
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>

//namespace
using namespace std;
using namespace __gnu_pbds;

//typedef
typedef tree<long long,null_type,less<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef tree<long long,null_type,greater<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set1;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<long,long> pll;

//define
#define inp(X) cin>>X;
#define inp_long(X) long long X; cin>>X;
#define inp_arr(A,N) long long A[N]; for(long long int i=0;i<N;i++) {cin>>A[i];}
#define sz(A) A.size()
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define endl '\n'
#define vect(A) vector<long long> A;
#define inp_vect(A,N); vect(A);for(long long i=0;i<N;i++){long long q; cin>>q; A.push_back(q);}
#define forin(i,a,b) for(long long i=a;i<=b;i++)
#define forde(i,a,b) for(long long i=a;i>=b;i--)
#define fio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

const long long inf=(long long)1e18;
const long long mod=(long long)(1e9+7);

ll power(ll x, ll y, ll p) 
{ 
    ll res = 1;
    x = x % p;
    while (y > 0) 
    {
        if (y & 1) 
            res = (res*x) % p; 
        y = y>>1;
        x = (x*x) % p; 
    } 
    return res; 
} 
ll modInverse(ll a,ll p)
{
   return power(a,p-2,p);
}
ll gcd(ll a, ll b) 
{ 
    if (a == 0) 
        return b; 
    return gcd(b % a, a); 
}
int main()
{
    // #ifndef ONLINE_JUDGE
    //    freopen ("input.txt" , "r" , stdin);
	// 	// freopen ("OUTPUT.txt" , "w" , stdout);
	// #endif
    fio;
    ll testcase=1;
    //cin>>testcase;
    while(testcase--)
    {
        string s;
        cin>>s;
        ll e=0;
        for(char c:s)
        {
            if(c=='7')
            {
                e++;
                break;
            }
        }
        if(e)
        {
            cout<<"Yes";
        }
        else
        cout<<"No";
        cout<<endl;
    }
    return 0;
}

Measured memory_bytes: 3660
# -*- coding: utf-8 -*-
import math
n = int(input())
color = list(input())

i = 0
j = n-1
count = 0

while(i<j):
  found1 = 0
  found2 = 0
  for k in range(n-1-i):
    if color[i+k] == 'W':
      i = i+k
      found1 = 1
      break
  for k in range(j):
    if color[j-k] == 'R':
      j = j-k
      found2 = 1
      break

  if found1*found2 == 0:
    break
  elif i>j:
    break
  else:
    count += 1
    i+=1
    j-=1
      

print(count)

Measured memory_bytes: 10776
n = int(input())
c_l = list(map(int, input().split()))
p_l = [0]*n
ans = 0
is_prev_correct = True
while True:
  for i in range(n):
    if c_l[i] == p_l[i]:
      is_prev_correct = True
    elif is_prev_correct:
      p_l[i] += 1
      ans += 1
      is_prev_correct = False
    else:
      p_l[i] += 1
  is_prev_correct = True
  if p_l == c_l:
    break
print(ans)

Measured memory_bytes: 3064
import java.util.*;
import static java.lang.System.*;

class Main {
  public static final int MOD = 1000000007;
  public static final int INF = 1000000000;
  public static void main(String[] args) {
    Scanner sc = new Scanner(in);
    int N = sc.nextInt();
    int Y = sc.nextInt();
    int x,y,z;
    int tmp;
    String ans = "-1 -1 -1";
    boolean check = true;
    for(x=0; x<=N; x++){
      if(check == false) break;
      for(y=0; y<=N-x; y++){
        z = N-x-y;
        tmp = 10000*x + 5000*y + 1000*z;
        if(tmp == Y){
          ans = x + " " + y + " " + z;
          check = false;
          break;
        }
      }
    }
    out.println(ans);
  }

  public static int gcd(int a, int b){
    if(b == 0) return a;
    return gcd(b, a%b);
  }
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int deg(ll a){
    int deg=1;
    while(a){
        a/=26;
        deg++;
    }
    return deg;
}

int main(void){
    ll N;
    cin >> N;
    vector<char> S;
    while(N>0){
        if(N%26==0){ S.push_back('z');N-=26;}
        else S.push_back('`'+N%26);
        N/=26;
    }
    reverse(S.begin(),S.end());
    for(char c:S){
        cout << c;
    }
}

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

int main(void){
    int h, a;
    cin >> h >> a;
    if (h % a != 0)
        cout << h/a + 1 << endl;
    else
        cout << h/a << endl;
}

Measured memory_bytes: 256
#include <algorithm>  // sort, 二分探索(lower_bound)など
#include <cmath>      // pow, logなど
#include <complex>    // 複素数
#include <deque>      // 両端アクセスのキュー
#include <iostream>   // 入出力
#include <iterator>
#include <map>
#include <numeric>  // iota(整数列の生成), gcd, lcm
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>  // 順序保持しないmap
#include <unordered_set>  // 順序保持しないset
#include <utility>        // pair
#include <vector>

#define REP(i, n) for (int i = (0); i < (n); ++i)
#define REPR(i, n) for (int i = (n - 1); i >= (0); --i)
#define ALL(container) (container).begin(), (container).end()
#define MAX(x) *max_element(ALL(x))  // 最大値を求める
#define MIN(x) *min_element(ALL(x))  // 最小値を求める

using namespace std;
typedef long long ll;

constexpr int INF = 1e9;
constexpr int MOD = 1000000007;

int main() {
  size_t a;
  cin >> a;
  cout << a + a * a + a * a * a << endl;
  return 0;
}


Measured memory_bytes: 3560
x_1, y_1, x_2, y_2 = gets.chomp.split(" ").map(&:to_i)

dx = x_2 - x_1
dy = y_2 - y_1

x_3 = x_2 - dy
y_3 = y_2 + dx
x_4 = x_1 - dy
y_4 = y_1 + dx

puts x_3.to_s + " " + y_3.to_s + " " + x_4.to_s + " " + y_4.to_s

Measured memory_bytes: 1788
/*
    Problem 16
    https://atcoder.jp/contests/abc150/tasks/abc150_c
*/
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cmath>
#include <iomanip>
#include <queue>
#include <list>
#include <set>
#include <stack>
#include <cctype>
#include <cmath>
#include <bitset>

using namespace std;
/* typedef */
typedef long long ll;
/* constant */
/* global variables */
/* function */
/* main */
int main(){
    int N;
    cin >> N;
    vector<int> A(N), B(N), v(N);
    for (int i = 0; i < N; i++) cin >> A[i];
    for (int i = 0; i < N; i++) cin >> B[i];
    iota(v.begin(), v.end(), 1);
    int indA, indB;
    int cnt = 0;
    do {
        if (A == v) indA = cnt;
        if (B == v) indB = cnt;
        cnt++;
    } while (next_permutation(v.begin(), v.end()));

    cout << abs(indA - indB) << '\n';
}


Measured memory_bytes: 256
data_list = [[["0" for i in range(10)] for j in range(3)] for x in range(4)]
number = int(input())

for x in range(number):

    b ,f ,r, v =(int(i) for i in input().split())
    data = data_list[b -1] [f -1][r -1]
    point =int(data) + v
    data_list[b -1] [f -1][r -1] = str(point)
for n in range(4):
    for y in range(3):
        
        for l in range(10):
            print(' ' + data_list[n][y][l], end="")
        print()
    if n < 3:
       
        print('#' * 20)    


Measured memory_bytes: 5624
#pragma GCC optimize("O3")
#pragma GCC target("sse4.1")
#ifdef LOCAL
#define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define fst first
#define snd second
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define ford(i, n) for (int i = ((int)(n) - 1); i >= 0; --i)
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef pair<int, int> pii;
typedef vector<pii> vii;
#define sz(c) (int)(c).size()
#define all(c) (c).begin(), (c).end()

#ifdef LOCAL
#define eprintf(args...) fprintf(stderr, args), fflush(stderr);
#else
#define eprintf(args...) ;
#endif

void solve (int n)
{
    vll a(n);
    forn (i, n)
        cin >> a[i];

    vll sum(n + 1);
    partial_sum(all(a), sum.begin() + 1);
    sort(all(sum));

    ll ans = 0;
    for (int i = 0; i < sz(sum); )
    {
        int j = i;
        while (j < sz(sum) && sum[i] == sum[j])
            j++;

        ll len = j - i;
        ans += len * (len - 1) / 2;
        i = j;
    }

    cout << ans << endl;
    return;
}

int32_t main()
{
#ifdef LOCAL
    freopen("input.txt", "rt", stdin);
    freopen("output.txt", "w", stdout);
#endif // ONLINE_JUDGE

    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int n;
    while (cin >> n)
        solve(n);
}


Measured memory_bytes: 3456
n=list(map(int,input().split()))#k=n[0],x=n[1]
#print(n)
b = [n[1]]
for i in range(1, n[0]):
    b.append(n[1] + i)
    b.append(n[1] - i)
b=sorted(b)
#print(b)
for i in b:
    print(i,end=" ")

Measured memory_bytes: 3060
import Data.List
import Data.Ord

main = interact $ unlines . map (show . infected_computer) . read' . lines
 where
  read' ("0 0":_) = []
  read' (nm:xs) = map (map read . words) ms : read' xs'
   where
    [_,m] = map read (words nm)
    (ms,xs') = splitAt m xs

infected_computer = length . foldl' infect [1] . sortBy (comparing head)
 where infect acc [_,s,d] = if elem s acc && notElem d acc then d:acc else acc

Measured memory_bytes: 48112
import sys

N = int(input())

x = [0 for i in range(N)]
y = [0 for i in range(N)]
h = [0 for i in range(N)]

for i in range(N):
    x[i], y[i], h[i] = map(int, input().split())

# N = 4

# x = [2,2,1,3]
# y = [3,1,2,2]
# h = [5,5,5,5]

def dif(x,y,a,b):
    ans = int(abs(x-a) + abs(y-b))
    return(ans)


for i in range(N):
    if h[i] != 0:
        xt, yt, ht = x[i], y[i], h[i]
        break


for i in range(101):
    for j in range(101): # 頂点に関する全探索

        collect = True
        top = ht + dif(i, j, xt, yt)

        for k in range(N):
            h_predict = max(0, top - dif(x[k], y[k], i, j))

            if h[k] != h_predict:
                collect = False
                break

        if collect:
            print(i,j,top)
            sys.exit()



Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main() {
	char a[1000001];
	scanf("%s",a);
	if(a[0]==a[strlen(a)-1]) {
		if((strlen(a))%2==1) cout<<"Second"<<endl;
		else cout<<"First"<<endl;
	} else {
		if((strlen(a))%2==1) cout<<"First"<<endl;
		else cout<<"Second"<<endl;
	}
	return 0;
}

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

main() {
  int N;
  char x;
  cin >> N;
  for(int i=0; i<N; i++){
    cin >> x;
    if(x == 'Y'){
      cout << "Four" << endl;
      break;
    }
    else if(i == N-1){
      cout << "Three" << endl;
    }
  }  
}


Measured memory_bytes: 256
def examA():
    def calc_L(x1,y1,x2,y2):
        return ((x2-x1)**2 + (y2-y1)**2)**0.5
    N = I()
    X = [LI()for _ in range(N)]
    ans = 0
    for x in itertools.permutations(X):
        cur = 0
        for i in range(1,N):
            cur += calc_L(x[i-1][0],x[i-1][1],x[i][0],x[i][1])
        #print(x,cur)
        ans += cur
    for i in range(1,N+1):
        ans /= i
    print(ans)
    return

def examB():
    def judge(n):
        sn = 0
        for i in n:
            sn += int(i)
        if int(n)%sn==0:
            return "Yes"
        return "No"
    N = SI()
    ans = judge(N)
    print(ans)
    return

def examC():
    N, K = LI()
    P = LI()
    ans = 0
    S = [0]*(N+1)
    for i in range(N):
        S[i+1] = S[i]+(P[i]+1)/2
    for i in range(N-K+1):
        cur = S[i+K] - S[i]
        if cur>ans:
            ans = cur
    print(ans)
    return

def examD():
    def bfs(n,V,s,W):
        visited = [False]*n
        que = deque()
        que.append(s)
        while(que):
            now = que.pop()
            visited[now] = True
            for ne in V[now]:
                if visited[ne]:
                    continue
                W[ne] += W[now]
                que.append(ne)
        return W
    N, Q = LI()
    V = [[]for _ in range(N)]
    for _ in range(N-1):
        a, b = LI()
        a -= 1; b -= 1
        V[a].append(b)
        V[b].append(a)
    W = [0] * N
    for _ in range(Q):
        p, x = LI()
        W[p-1] += x
    ans = bfs(N,V,0,W)
    print(" ".join(map(str,ans)))
    return

def examE():
    def bfs(n,edges,s):
        L = [inf]*n
        que = deque()
        que.append(s)
        L[s] = 0
        while(que):
            now = que.popleft()
            for ne in edges[now]:
                if L[ne]>L[now]+1:
                    L[ne] = L[now]+1
                    que.append(ne)
        return L
    N = I()
    V = [[]for _ in range(N)]
    for _ in range(N-1):
        a, b = LI()
        a -= 1; b -= 1
        V[a].append(b)
        V[b].append(a)
    F = bfs(N,V,0)
    S = bfs(N,V,N-1)
    f = 0; s = 0
    for i in range(N):
        if F[i]>S[i]:
            s += 1
        else:
            f += 1
    if f>s:
        print("Fennec")
    else:
        print("Snuke")
    return

def examF():
    ans = 0
    print(ans)
    return

import sys,bisect,itertools,heapq,math,random
from copy import deepcopy
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet,_ep
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
_ep = 10**(-12)
alphabet = [chr(ord('a') + i) for i in range(26)]

sys.setrecursionlimit(10**6)

if __name__ == '__main__':
    examE()

"""

"""

Measured memory_bytes: 36240