akhauriyash/Code-Regression huggingface dataset:
# 入力値を数値で返す
def gets_i()
  gets.chomp.to_i
end

# 空白区切の入力値を数値の配列で返す
def gets_i_list()
  gets.chomp.split(" ").map(&:to_i)
end

N = gets_i
K = gets_i
x_list = gets_i_list

total = 0
x_list.each do |x|
  total += [(x - 0).abs * 2, (x - K).abs * 2].min
end

puts total


Measured memory_bytes: 1788
import java.util.*;

public class Main {

	public static void main (String[] args)  {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		char[] arrS = sc.next().toCharArray();
		char[] arrT = sc.next().toCharArray();
		long x = lcm(n, m);
		int nn = (int)(x / n);
		int mm = (int)(x / m);
		for (int i = 0; i * mm < n && i * nn < m; i++) {
			if (arrS[i * mm] != arrT[i * nn]) {
				System.out.println(-1);
				return;
			}
		}
		System.out.println(x);
	}
	static long lcm(long x, long y) {
		return x / gcd(x, y) * y ;
	}
	
	static long gcd(long x, long y) {
		if (x % y == 0) {
			return y;
		}
		return gcd(y, x % y);
	}
}


Measured memory_bytes: 27268
#include <iostream>
#include <cstdio>
#define N 100005
using namespace std;

typedef long long ll;
ll n, s1, s2, t, s, k, num, cnt, h, a[N], ans[N];
int main()
{
	ll i, j;
//	freopen ("input.txt", "r", stdin);
	cin >> n;
	if (n == 1) {
		cout << "YES" << endl;
		return 0;
	}
	for (i = 0; i < n; i++) {
		scanf ("%lld", &a[i]);
		s += a[i];
	}
	t = n * (n + 1) / 2;
	if (s % t > 0) {
		cout << "NO" << endl;
		return 0;
	}
	k = s / t;
	num = k - (a[0] - a[n - 1]);
	if (num < 0 || num % n > 0) {
		cout << "NO" << endl;
		return 0;
	}
	ans[0] = num / n;
	cnt = num / n;
	for (i = 0; i < n - 1; i++) {
		num = k - (a[i + 1] - a[i]);
		if (num < 0 ||num % n > 0) {
			cout << "NO" << endl;
			return 0;
		}
		ans[i + 1] = num / n;
		cnt += num / n;
	}
	if (cnt != k) {
		cout << "NO" << endl;
		return 0;
	}
	j = 1;
	for (i = 0; i <n; i++) {
		h += ans[i] * j;
		if (j == 1) j = n;
		else j--;
	}
	if (h != a[0]) {
			cout << "NO" << endl;
			return 0;
	}
	for (i = 1; i < n; i++) {
		h += k;
		h -= ans[i] * n;
		if (h != a[i]) {
				cout << "NO" << endl;
				return 0;
		}
	}
	cout << "YES" << endl;
    return 0;
}


Measured memory_bytes: 1920
def solve(s) :
    f = 0
    b = len(s)-1
    ans = 0
    while True :
        if abs(f-b) <= 1 and s[f] == s[b]:
            return ans
        elif s[f] != s[b] :
            if s[f] == 'x' :
                f += 1
                ans += 1
            elif s[b] == 'x' :
                b -= 1
                ans += 1
            else :
                return -1
        else :
            f += 1
            b -= 1

def main() :
    s = input()
    print(solve(s))

main()

Measured memory_bytes: 3316
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc=new Scanner(System.in);
    String a=sc.next();
    String b=sc.next();
    if(a.equals(b.substring(0,a.length())))
       System.out.println("Yes");
     else System.out.println("No");
  }
}

Measured memory_bytes: 26916
import java.lang.*

fun main(args: Array<String>) {
    val (N, A) = readLine()!!.split(" ").map(String::toInt)
    println(ret(Math.min(N,A).toString(),Math.max(N,A)))
}

fun ret(str : String,m : Int) : Int{
    var ans = ""
    for(i in 0 until m){
        ans += str
    }
    return ans.toInt()
}

Measured memory_bytes: 36004
S = input()
S = S[::-1]
snipetts = [s[::-1] for s in ['dream', 'dreamer', 'erase', 'eraser']]

found = True
index = 0
while found:
    found = False
    for s in snipetts:
        if S[index:index+len(s)] == s:
            index += len(s)
            found = True
            break

if index == len(S):
    print('YES')
else:
    print('NO')

Measured memory_bytes: 3188
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int trans1(char c)
{
	if(c=='.')return 0;return 1;
}
int xx[4]={0,0,-1,1};
int yy[4]={-1,1,0,0};//上下左右
int cnt[305][305][4][305];
int sumx[305][305][4][305];
int n,m;
int Z[305][305];
void init()
{
	register int i,j,k;
	memset(cnt,0,sizeof(cnt));
	for(i=1;i<=n;i++)
	{
		for(j=1;j<=m;j++)
		{
			for(k=1;k<i;k++)
				cnt[i][j][0][k]=cnt[i-1][j][0][k-1];
			cnt[i][j][0][0]=Z[i][j];
		}
	}//up

	
	for(i=n;i>=1;i--)
	{
		for(j=1;j<=m;j++)
		{
			for(k=1;k<n-i+1;k++)
				cnt[i][j][1][k]=cnt[i+1][j][1][k-1];
			cnt[i][j][1][0]=Z[i][j];
		}
	}//down

	for(j=1;j<=m;j++)
	{
		for(i=1;i<=n;i++)
		{
			for(k=1;k<j;k++)
				cnt[i][j][2][k]=cnt[i][j-1][2][k-1];
			cnt[i][j][2][0]=Z[i][j];
		}
	}

	for(j=m;j>=1;j--)
	{
		for(i=1;i<=n;i++)
		{
			for(k=1;k<m-j+1;k++)
				cnt[i][j][3][k]=cnt[i][j+1][3][k-1];
			cnt[i][j][3][0]=Z[i][j];
		}
	}

}

int n1,m1;

int minlen(int nx,int ny)
{
//	return min(min(min(nx-1,ny-1),n-nx),m-ny);
	return min(n,m);
}

long long getans1()
{
	register int i,j,k;
	long long sumz=0;
	for(i=1;i<=n;i++)for(j=1;j<=m;j++)
	{
		for(k=1;k<=minlen(i,j);k++)
		{
			int sum=0;
			for(int l=0;l<4;l++)
				sum+=cnt[i][j][l][k];//,printf("%d %d %d %d val:%lld\n",i,j,k,l,cnt[i][j][l][k]);
			if(sum==3)sumz++;
			if(sum==4)sumz+=4;
		}
	}
	return sumz;
}

void initc()
{
	register int i,j,k;
	for(i=1;i<=n;i++)for(j=1;j<=m;j++)
	{
		for(k=1;k<=minlen(i,j);k++)
			sumx[i][j][0][k]=sumx[i-1][j][0][k-1]+cnt[i][j][2][k];//从左侧转移过来
		sumx[i][j][0][0]=Z[i][j];
//		for(k=0;k<=minlen(i,j);k++)
//			printf("%d %d %d val:%d\n",i,j,k,sumx[i][j][0][k]);
	}
	
	for(i=1;i<=n;i++)for(j=m;j>=1;j--)
	{
		for(k=1;k<=minlen(i,j);k++)
			sumx[i][j][1][k]=sumx[i-1][j][1][k-1]+cnt[i][j][3][k];
		sumx[i][j][1][0]=Z[i][j];
	}

	for(i=n;i>=1;i--)for(j=1;j<=m;j++)
	{
		for(k=1;k<=minlen(i,j);k++)
			sumx[i][j][2][k]=sumx[i+1][j][2][k-1]+cnt[i][j][2][k];
		sumx[i][j][2][0]=Z[i][j];
	}

	for(i=n;i>=1;i--)for(j=m;j>=1;j--)
	{
		for(k=1;k<=minlen(i,j);k++)
			sumx[i][j][3][k]=sumx[i+1][j][3][k-1]+cnt[i][j][3][k];
		sumx[i][j][3][0]=Z[i][j];
	}
}

long long getans2()
{
	register int i,j,k;
	long long sum=0;
	initc();
	for(i=1;i<=n;i++)for(j=1;j<=m;j++)
	{
		for(k=1;k<=minlen(i,j);k++)
		{
			sum+=1ll*(sumx[i][j][0][k]-cnt[i][j][0][k]-cnt[i][j][2][k])*cnt[i][j][3][k]*cnt[i][j][1][k];
			sum+=1ll*(sumx[i][j][1][k]-cnt[i][j][0][k]-cnt[i][j][3][k])*cnt[i][j][2][k]*cnt[i][j][1][k];
			sum+=1ll*(sumx[i][j][2][k]-cnt[i][j][1][k]-cnt[i][j][2][k])*cnt[i][j][3][k]*cnt[i][j][0][k];
			sum+=1ll*(sumx[i][j][3][k]-cnt[i][j][1][k]-cnt[i][j][3][k])*cnt[i][j][2][k]*cnt[i][j][0][k];
		}
	}
	return sum;
}

char str[1005];
int main()
{
	int i,j;
	scanf("%d%d",&n,&m);
	n1=n/2,m1=m/2;
	for(i=1;i<=n;i++)
	{
		scanf("%s",str);
		for(j=0;j<m;j++)
			Z[i][j+1]=trans1(str[j]);
	}
	init();
	long long ans=0;
	ans=getans1();
	printf("%lld\n",ans+getans2());
	return 0;
}


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

using namespace std;

int main()
{
	string S;
	cin >> S;

	bool easy = true;

	for (int i = 0; (size_t)i < S.size(); i++) {
		if ((i % 2 == 0 && S[i] == 'L') || (i % 2 == 1 && S[i] == 'R')) {
			easy = false;
		}
	}

	if (easy) {
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}

	return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;
int main(int argc, char *argv[]) {
	int a,b;
	cin >> a >> b;
	if((a > 0 && b > 0) || a==b){
		cout << "Positive" << endl;
	}else if (a == 0 || b == 0 || (a<0 && b>0) || (b<0 && a>0)){
		cout << "Zero" << endl;
	}else{
		if ((b*-1 - a*-1) %2 == 0) cout << "Negative" << endl;
		else cout << "Positive" << endl;
	}
	return 0;
}

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

using namespace std;

int main(void) {
	int H, W;
	cin >> H >> W;
	vector<vector<int>> ans(H, vector<int>(W, 0));
	vector<string> S(H);
	for (int i = 0; i < H; i++) cin >> S[i];
	for (int y = 0; y < H; y++) {
		for (int x = 0; x < W; x++) {
			for (int dy = -1; dy <= 1; dy++) {
				for (int dx = -1; dx <= 1; dx++) {
					if (dx == 0 && dy == 0) continue;
					int yy = y + dy;
					int xx = x + dx;
					if (yy < 0 || yy >= H) continue;
					if (xx < 0 || xx >= W) continue;
					if (S[yy][xx] == '#') ans[y][x]++;
				}
			}
		}
	}

	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			if (S[i][j] == '#') cout << "#";
			else cout << ans[i][j];
		}
		cout << endl;
	}
	system("pause");
	return 0;
}

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

#define all(x) (x).begin(),(x).end()
#define init() \
  ios::sync_with_stdio(false); \
  cin.tie(0)

using namespace std;

using ll = long long;
using ull = unsigned long long;

template<typename M, typename N>
constexpr common_type_t<M, N> gcd(M a, N b) {
  return a == 0 ? b
    : b == 0 ? a
    : gcd(b, a % b);
}

template <typename M, typename N>
constexpr common_type_t<M, N> lcm(M a, N b) {
  return a * b / gcd(a, b);
}

class Point {
  public:
    int t;
    int x;
    int y;

    Point(int t, int x, int y): t(t), x(x), y(y) {}

    int dist(const Point& other) const {
      int dx = abs(this->x - other.x);
      int dy = abs(this->y - other.y);
      return dx + dy;
    }

    bool reachable(const Point& other) const {
      int dt = abs(this->t - other.t);
      int dist = this->dist(other);
      if (dt < dist) {
        return false;
      }
      if (dt % 2 == dist % 2) {
        return true;
      }
      return false;
    }
};

int main() {
  init();

  int n;
  cin >> n;
  Point p1 = Point(0, 0, 0);
  bool ok = true;
  for (int i = 0; i < n; i++) {
    int t, x, y;
    cin >> t >> x >> y;
    Point p2 = Point(t, x, y);
    if (!p1.reachable(p2)) {
      ok = false;
    }
  }

  if (ok) {
    cout << "Yes" << '\n';
  } else {
    cout << "No" << '\n';
  }
  return 0;
}


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

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

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

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

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

//main code

int main(int argc, char const* argv[])
{
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    int ans = 0;
    for (int i = a; i < b; i++) {
        if (i >= c && i< d) {
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {
	private final static String NEG = "NO\n";
	private final static String AFF = "YES\n";

	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in),1024);
		int number = Integer.parseInt(br.readLine());
		int sides[] = new int[3];
		StringTokenizer tknz;
		StringBuilder builder = new StringBuilder();

		for (; 0 < number; number--) {
			tknz = new StringTokenizer(br.readLine());
			for (int i = 0; i < 3; i++) {
				sides[i] = Integer.parseInt(tknz.nextToken());
			}
			Arrays.sort(sides);
			if (sides[0] * sides[1] * sides[2] % 60 != 0) {
				builder.append(NEG);
			} else if (Math.pow(sides[0], 2) + Math.pow(sides[1], 2) != Math.pow(sides[2], 2)) {
				builder.append(NEG);
			} else {
				builder.append(AFF);
			}
		}
		System.out.print(builder);
	}
}

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

int main() {
  int n;
  cin >> n;
  bool flag = false;
  if(n / 10 == 9) flag = true;
  else if(n % 10 == 9) flag = true;
  
  if(flag) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 3584
#include <stdio.h>
#include <string.h>
char x[110];
int main()
{
	scanf("%s",x+1);
	int ans = 0, c =0;
	for(int i=1;i<=strlen(x+1);i++)
	{
		if(x[i]=='S') c = 0;
		else c++;
		ans = ans>c?ans:c;
	}
	printf("%d",ans);
}

Measured memory_bytes: 1724
#include <bits/stdc++.h>
#define fup(i,a,b) for(int i=a;i<=b;++i)
#define fdw(i,a,b) for(int i=a;i>=b;--i)
#define sync ios::sync_with_stdio(false);cin.tie(0)
#define cl(a) memset(a,0,sizeof(a))
#define gcd __gcd
#define fi first
#define se second
#define pb push_back
#pragma GCC optimize(2)
using namespace std;
typedef long long ll;
//ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
//ll ksm(ll a,ll b,ll mod){ll res=1;a%=mod;for(;b;b>>=1){if(b&1) res=res*a%mod;a=a*a%mod;}return res;}
//ll oula(ll n){ ll res=n;for(ll i=2;i*i<=n;i++){if(n%i==0){ res=res-res/i;while(n%i==0) n/=i;}}if(n>1) res=res-res/n;return res;}
//bool MRT(ll x){if(x==2)return true;fup(i,1,50){ll now=rand()%(x-2)+2;if(ksm(now,x-1,x)!=1)return false;}return true;}
//void shai(int n)fup(i,2,n){if(isprime[i]){v.push_back(i);for(int j=2*i;j<=10000;j+=i)isprime[j]=0;}}//"埃氏筛筛选素数"
const int mod=998244353;
const int inf=0x3f3f3f3f;
const double eps=1e-7;
const int N=1e3+10;
int main()
{
    
    sync;
    ll a,b,ans;
    cin>>a>>b;
    if(a==1||b==1)
        return cout<<1<<endl,0;
    if((a*b)%2==1)
        ans=(a*b)/2+1;
    else ans=(a*b)/2;
    cout<<ans<<endl;
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <numeric>
#include <cstdint>
#include <iomanip>
using ll = long long;

const int INF = 1145141919;

int main(){
    ll h, w; std::cin >> h >> w;
    std::vector<std::vector<int>> s(h, std::vector<int>(w,0));
    for(int i=0; i<h; ++i){
        std::string b; std::cin >> b;
        for(int j=0; j<w; ++j){
            if(b[j]=='#') s[i][j]=-INF;
        }
    }

    for(int i=0; i<h; ++i){
        for(int j=0; j<w; ++j){
            if(s[i][j]<0){
                if(i+1<h  && j+1<w ) ++s[i+1][j+1];
                if(i+1<h           ) ++s[i+1][j  ];
                if(i+1<h  && j-1>-1) ++s[i+1][j-1];
                if(          j+1<w ) ++s[i  ][j+1];
                if(          j-1>-1) ++s[i  ][j-1];
                if(i-1>-1 && j+1<w ) ++s[i-1][j+1];
                if(i-1>-1          ) ++s[i-1][j  ];
                if(i-1>-1 && j-1>-1) ++s[i-1][j-1];
            }
        }
    }

    for(int i=0; i<h; ++i){
        for(int j=0; j<w; ++j){
            if(s[i][j]<0){
                std::cout << "#";
            }else{
                std::cout << s[i][j];
            }
        }
        std::cout << "\n";
    }

    return 0;
}


Measured memory_bytes: 256
#include <cmath>
#include <iostream>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <bitset>
#include <algorithm>
#include <functional>
#include <utility>
#include <iomanip>

#define int long long int
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )

using namespace std;

typedef pair<int, int> P;

const int INF = 1e15;
const int MOD = 1e9+7;

template <typename T>
using vector2 = vector<vector<T>>;
template <typename T>
vector2<T> initVec2(size_t n0, size_t n1, T e = T()){
    return vector2<T>(n0, vector<T>(n1, e));
}

template <typename T>
using vector3 = vector<vector<vector<T>>>;
template <typename T>
vector3<T> initVec3(size_t n0, size_t n1, size_t n2, T e = T()){
    return vector3<T>(n0, vector2<T>(n1, vector<T>(n2, e)));
}

int gcd(int a, int b){
    if(a < b){
        swap(a, b);
    }
    int r = a % b;
    while(r != 0){
        a = b;
        b = r;
        r = a % b;
    }
    return b;
}

vector<int> prime(int n){
    vector<int> t;
    vector<bool> x(n+1, true);
    t.push_back(2);

    int i;
    for(i = 3; i * i <= n; i += 2){
        if(!x[i]){
            continue;
        }
        t.push_back(i);
        for(int j = i; j <= n; j += i){
            x[j] = false;
        }
    }
    for(; i <= n; i += 2){
        if(x[i]){
            t.push_back(i);
        }
    }
    return t;
}

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

    int a, b;
    cin >> a >> b;

    int r = gcd(a, b);
    vector<int> p = prime(1000000);

    int ans = 1;
    rep(i, SZ(p)){
        if(r % p[i]){
            continue;
        }
        ans++;
        while(r % p[i] == 0){
            r /= p[i];
        }
    }

    if(r != 1){
        ans++;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1528
#include <bits/stdc++.h>
#define fi first
#define se second
#define inf (int)1e8
using namespace std;

struct data {
  int p;
  int c;
};

bool operator<(const data &l, const data &r) {
  if(l.c != r.c) return l.c > r.c;
  return l.p > r.p;
}

int n, x;
vector<int> dp;
vector<pair<int, int>> v;
priority_queue<data> pq;

bool ch(data nextp) {
  return nextp.p >= 0 && nextp.p < dp.size();
}
int solve();

int main() {
  cin >> n >> x;
  v.resize(n);
  dp.assign(4 * 100000 + 100, inf);
  for(int i = 0; i < n; ++i) cin >> v[i].fi >> v[i].se;
  cout << solve() << endl;
  return 0;
}

int solve() {
  x += 100050;
  pq.push({100050, 0});
  dp[100050] = 0;
  while(!pq.empty()) {
    data now = pq.top();
    pq.pop();
    for(int i = 0; i < n; ++i) {
      data nextp = now;
      nextp.p += v[i].fi;
      nextp.c += v[i].se;
      if(ch(nextp) && dp[nextp.p] > nextp.c) {
        dp[nextp.p] = nextp.c;
        pq.push(nextp);
      }
      nextp.p -= v[i].fi * 2;
      if(ch(nextp) && dp[nextp.p] > nextp.c) {
        dp[nextp.p] = nextp.c;
        pq.push(nextp);
      }
    }
  }
  if(dp[x] == inf)
    return -1;
  else
    return dp[x];
}


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

typedef long long ll;

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

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

int main() {
    ll N,M;
    cin >> N >> M;
    
    ll ans;
    if ( N == 1 ) {
        if ( M == 1 ){
            ans = 1;
        } else {
            ans = M - 2;
        }
    } else if ( M == 1 ){
        ans = N - 2;
    } else {
        ans = ( N-2 ) * ( M-2 );
    }
    
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 3628
import java.util.Scanner;

public class Main {

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

        String AB = String.valueOf(a) + String.valueOf(b);
        double ab = Double.parseDouble(AB);

        //平方数を求める
        int square =(int) Math.sqrt(ab);

        //2乗して元の数に戻るか確認
        int conf = square * square;

        String judge = (int)ab == conf ? "Yes" : "No";
        System.out.println(judge);
    }

}

Measured memory_bytes: 21844
while True:
    N = int(input())
    if N == 0:
        quit()
    k = []
    for i in range(N):
        temp = [int(i) for i in input().split()]
        if temp[0] != 0:
            k.append(temp[1:])
        else:
            k.append([])
    o = [int(i) for i in input().split()][1:]
    ans = []
    for i in range(N):
        if all(j in k[i] for j in o):
            ans.append(i)
    if len(ans) != 1:
        print(-1)
    else:
        print(ans[0]+1)


Measured memory_bytes: 5668
#include <algorithm>
#include <cmath>
#include <complex>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
#include <functional>
#include <cstring>
#include <regex>
#include <random>
#include <cassert>
#include <stack>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, s, n) for (int i = (s); i < (int)(n); i++)
#define revrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define revrepr(i, s, n) for (int i = (n) - 1; i >= s; i--)
#define debug(x) cerr << #x << ": " << x << "\n"
#define popcnt(x) __builtin_popcount(x)

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

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

template<class T>
istream& operator >>(istream &is, vector<T> &v) {
    for (int i = 0; i < (int)v.size(); i++) cin >> v.at(i);
    return is;
}

template<class T, class U>
ostream& operator <<(ostream &os, pair<T, U> p) {
    cout << '(' << p.first << ", " << p.second << ')';
    return os;
}

template<class T>
void print(const vector<T> &v, const string &delimiter) { rep(i, v.size()) cout << (0 < i ? delimiter : "") << v.at(i); cout << endl; }

template<class T>
void print(const vector<vector<T>> &vv, const string &delimiter) { for (const auto &v: vv) print(v, delimiter); }

struct Query {
    int num, x;
};
bool operator <(const Query &a, const Query &b) { return a.x < b.x; }

int main() {
    int n;
    cin >> n;
    vector<Query> qs(n);
    vector<int> num(n * n, -1);
    rep(i, n) {
        int x;
        cin >> x;
        x--;
        qs[i] = Query{i, x};
        num[x] = i;
    }
    sort(qs.begin(), qs.end());
    
    int ptr = 0;
    queue<int> que;
    vector<int> a(n * n, -1);
    vector<int> cnt(n);
    rep(i, n * n) {
        if (num[i] != -1) {
            a[i] = num[i];
            cnt[num[i]]++;
            if (cnt[num[i]] != num[i] + 1) {
                cout << "No" << endl;
                return 0;
            }
            rep(c, n - num[i] - 1) que.push(num[i]);
            continue;
        }
        
        while (ptr < n && (cnt[qs[ptr].num] == qs[ptr].num || qs[ptr].x < i)) ptr++;
        if (ptr < n) {
            a[i] = qs[ptr].num;
            cnt[qs[ptr].num]++;
        }
        else {
            if (que.empty()) {
                cout << "No" << endl;
                return 0;
            }
            a[i] = que.front(); que.pop();
        }
    }
    
    cout << "Yes" << endl;
    rep(i, n * n) cout << a[i] + 1 << " ";
    cout << endl;
}

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

int main() {
  string S,T;
  cin>>S>>T;
  vector<int> A[26];
  rep(i,0,S.size()) A[(int)S[i]-97].push_back(i);
  int ans=0;
  int cur=0;
  if(A[(int)T[0]-97].size()==0) ans=-1;
  rep(i,0,T.size()-1){
    if(A[(int)T[i+1]-97].size()==0 || A[(int)T[i]-97].size()==0){
      ans=-1;
      break;
    }
    if(T[i+1]!=T[i]){
      int a=A[(int)T[i]-97][cur];
      auto it=upper_bound(A[(int)T[i+1]-97].begin(),A[(int)T[i+1]-97].end(),a);
      int index=it-A[(int)T[i+1]-97].begin();
      if(index==A[(int)T[i+1]-97].size()){
        ans++;
        cur=0;
      }
      else{
        cur=index;
      }
    }
    else{
      if(cur!=A[(int)T[i]-97].size()-1) cur++;
      else{
        cur=0;
        ans++;
      }
    }
  }
  if(ans==-1) cout<<-1<<endl;
  else{
    ll p=ans*S.size()+A[(int)T[T.size()-1]-97][cur]+1;
    cout<<p<<endl;
  }
}


Measured memory_bytes: 1216
def e_this_message_will_self_destruct_in_5s():
    N = int(input())
    A = [int(i) for i in input().split()]

    add = [j + a for j, a in enumerate(A, 1)]
    diff = sorted([k - a for k, a in enumerate(A, 1)])

    from bisect import bisect_left as bleft
    return sum([bleft(diff, p + 1) - bleft(diff, p) for p in add])

print(e_this_message_will_self_destruct_in_5s())

Measured memory_bytes: 37196
def is_integer_num(n):
    if isinstance(n, int):
        return True
    if isinstance(n, float):
        return n.is_integer()
    return False

n, d = map(int, input().split())
input = [list(map(int, input().split())) for i in range(n)]
count = 0

for i in range(n):
    for j in range(i+1, n):
        ans = 0
        for k in range(d):
            ans += (input[i][k] - input[j][k])**2
        ans = ans**(1/2)
        if is_integer_num(ans):
            count += 1
print(count)


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

using namespace std;
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
constexpr int MOD = 1000000007;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
constexpr int dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
constexpr int dy[] = {0, -1, 0, 1, 1, -1, -1, 1};

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){os << "["; for (const auto &v : vec) {os << v << ","; } os << "]"; return os; }

void solve() {
  ll H, W, N;
  cin >> H >> W >> N;
  map<pair<ll,ll>, ll> cnt;
  for (int q = 0; q < N; q++) {
    ll a, b;
    cin >> a >> b;
    a--, b--;
    for(int i = -1; i <= 1; i++) {
      for(int j = -1; j <= 1; j++) {
        if (a + i < 0 || a + i >= H || b + j < 0 || b + j >= W) continue;
        cnt[{a + i, b + j}]++;
      }
    }
  }
  ll ans[10] = {0};
  for(auto &&e : cnt) {
    ll y = e.first.first, x = e.first.second;
    if (x == 0 || x == W - 1 || y == 0 || y == H - 1) continue;
    ans[e.second]++;
  }
  ll sum = 0;
  for (int i = 1; i < 10; i++) {
    sum += ans[i];
  }
  cout << (H - 2) * (W - 2) - sum << endl;
  for (int i = 1; i < 10; i++) {
    cout << ans[i] << endl;
  }
}

int main() {
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);
  cout.setf(ios::fixed);
  cout.precision(16);
  solve();
  return 0;
}

Measured memory_bytes: 56576
n = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))

counter = 0
for i in range(n):
  power = B[-i-1]
  counter += min(power,A[-i-1])
  power -= min(power,A[-i-1])
  counter += min(power,A[-i-2])
  A[-i-2] = max(0, A[-i-2]-power)
print(counter)

Measured memory_bytes: 19116
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var Arr=(input.trim()).split("\n");
while(true){
   var n=Arr.shift()-0;
   if(n==0)break;
   var S=[];
   for(var i=0;i<=n;i++)S[i]=0;
   for(var i=0;i<n;i++){
      var arr=(Arr.shift()).split(" ").map(Number);
      var s=arr.reduce(function(a,b){return a+b;});
      arr.push(s);
      arr.forEach(function(v,i){S[i]+=v;});
      arr.forEach(function(v,i){arr[i]=("    "+v).slice(-5)});
      console.log(arr.join(""));
   }
   S.forEach(function(v,i){S[i]=("    "+v).slice(-5)});
   console.log(S.join(""));
}

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

int N, M;

bool check_string(string S){
    int l = S.length();
    if(l % 2 == 0){
        int h = l / 2, c = 0;;
        while(h - c - 1 >= 0){
            if(S[h - c - 1] != S[h + c]) return false;
            c++;
        }
    }else{
        int h = l / 2, c = 0;
        while(h - c >= 0){
            if(S[h - c] != S[h + c]) return false;
            c++;
        }
    }

    return true;
}
int main(){
    string S;
    cin >> S;
    bool flag = false;
    int length = S.length();

    if(check_string(S) && check_string(S.substr(0, (length - 1) / 2))
        && check_string(S.substr((length + 1) / 2, (length - 1) / 2)))
        flag = true;
    
    if(flag) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

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

using namespace std;
using llong = long long;
using ldbl = long double;
using lpair = pair<llong, llong>;

#define ALL(x) x.begin(), x.end()

constexpr llong mod = 1e9+7;
constexpr llong inf = mod * mod;

int main() {
  llong N;
  cin >> N;

  for (llong i = 1; i <= N; ++i) {
    llong cnt = 0;
    for (llong x = 1; x <= 1000; x++) {
      for (llong y = 1; y <= 1000; y++) {
        if (x*x + y*y + x*y > i) {
          break;
        }

        llong d = (x + y) * (x + y) - 4 * (x*x + y*y + x*y - i);
        llong sqrt_d = sqrtl(d);
        if (sqrt_d * sqrt_d == d && sqrt_d - (x + y) > 0 && (sqrt_d - (x + y)) % 2 == 0) {
          cnt++;
        }
      }
    }

    cout << cnt << endl;
  }

  return 0;
}

Measured memory_bytes: 3536
//package may2020;

import java.util.*;
import java.lang.*;
import java.math.*;
import java.io.*;

public class Main {

	public static void main(String[] args) throws IOException {
		// TODO Auto-generated method stub
			FastReader scn = new FastReader();
			OutputStream out = new BufferedOutputStream ( System.out );
			int n =scn.nextInt();
			int[] cnt = new int[4];
			
			for(int i = 0;i<n;i++) {
				int sv=scn.nextInt();
				cnt[sv]++;
			}
			int max =305;
			double[][][] p= new double[max][max][max],ev = new double[max][max][max];
			p[cnt[1]][cnt[2]][cnt[3]]=1;
			for(int c = n;c>=0;c--) {
				for(int b = n;b>=0;b--) {
					for(int a = n;a>=0;a--) {
						if(a==0&&b==0&&c==0) {
							continue;
						}
						if(a+b+c>n)
							continue;
						double p_wasted = ((double)n-(a+b+c))/n;
						
						double ev_wasted = (p_wasted/(1-p_wasted))+1;
						ev[a][b][c] += ev_wasted*p[a][b][c]; 
						if(a!=0) {
							double p_go = (double)a/(a+b+c);
							p[a-1][b][c] += p[a][b][c]*p_go;
							ev[a-1][b][c] += ev[a][b][c]*p_go;
							
						}
						if(b!=0) {
							double p_go = (double)b/(a+b+c);
							p[a+1][b-1][c] += p[a][b][c]*p_go;
							ev[a+1][b-1][c]+=ev[a][b][c]*p_go;
						}
						if(c!=0) {
							double p_go = (double)c/(a+b+c);
							p[a][b+1][c-1] += p[a][b][c]*p_go;
							ev[a][b+1][c-1]+=ev[a][b][c]*p_go;
						}
						
					}
				}
			}
			out.write((ev[0][0][0]+"\n").getBytes());
			out.close();
	}

	static class FastReader 
    { 
        BufferedReader br; 
        StringTokenizer st; 
  
        public FastReader() 
        { 
            br = new BufferedReader(new
                     InputStreamReader(System.in)); 
        } 
  
        String next() 
        { 
            while (st == null || !st.hasMoreElements()) 
            { 
                try
                { 
                    st = new StringTokenizer(br.readLine()); 
                } 
                catch (IOException  e) 
                { 
                    e.printStackTrace(); 
                } 
            } 
            return st.nextToken(); 
        } 
  
        int nextInt() 
        { 
            return Integer.parseInt(next()); 
        } 
  
        long nextLong() 
        { 
            return Long.parseLong(next()); 
        } 
  
        double nextDouble() 
        { 
            return Double.parseDouble(next()); 
        } 
  
        String nextLine() 
        { 
            String str = ""; 
            try
            { 
                str = br.readLine(); 
            } 
            catch (IOException e) 
            { 
                e.printStackTrace(); 
            } 
            return str; 
        } 
    }

}


Measured memory_bytes: 724068
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <math.h>
#include <cmath>
#include <limits.h>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <functional>
#include <stdio.h>
using namespace std;

long long MOD = 1000000007;

int main() {
    
    long long ans = 0;
    vector<long long> V;
    int N;
    cin >> N;
    for ( int i = 0; i < N; i++ ) {
        long long a;
        cin >> a;
        V.push_back(a);
    }
    
    sort( V.begin(), V.end() );
    
    int count = 1;
    
    for ( int i = 1; i < N; i++ ) {
        
        if ( V[i] == V[i-1] ) {
            count++;
        }
        else {
            ans += count%2 ? 1 : 0;
            count = 1;
        }
        
    }
    
    ans += count%2 ? 1 : 0;
    
    
    cout << ans << endl;
    
    return 0;
}

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

int main(){
    int N;
    cin >> N ;
    int ans=0;
    for(int i=0;i<100;i++){
        if(1000*i>=N) {
            ans=1000*i-N;
            break;}
        }
    
    cout << ans << endl;
    }



Measured memory_bytes: 3528
#include<iostream>
#include<cctype>
#include<stdio.h>
using namespace std;
int main(){
	char ch;
	while (1){
		scanf("%c", &ch);
		if (isupper(ch)){
			ch=tolower(ch);
			
		}
		else if (islower(ch)){
			ch=toupper(ch);
		}
		cout << ch;

			
		
		if (ch == '\n')break;
	}

	return 0;
}

Measured memory_bytes: 3100
#include <iostream>
using namespace std;
 
int main(){

    int n;
    int *h; // 配列用ポインタ
    int i, j; // ループ用変数
    bool upflg;
    int dif;

	cin >> n;
    
    h = new int[n]; // 配列の動的確保

    for(i=0; i<n; i++){
        cin >> h[i];
    }
    // ここまで読み込み

    // n = 1の時は必ずyes
    if(n == 1){
        cout << "Yes" << endl;
        return 0;
    }

    upflg = false;

    for(i=1; i<n; i++){

        dif = h[i] - h[i-1];

        // 一つ前の数字が2以上大きい場合
        if(dif < -1){
            cout << "No" << endl;
            return 0;
        }

        // 一つ前の数字が1だけ大きい場合
        if(dif == -1){
            // upflgがすでにture(=もう一つ前の数字もだけ大きかった)
            if(upflg == true){
                cout << "No" << endl;
                return 0;
            }
            else
                upflg = true;
        }

        // 同値の場合、何もしない

        // 一つ前の数字より大きい場合
        if(dif > 0)
            upflg = false;
    }

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

Measured memory_bytes: 640
/*** author: yuji9511 ***/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> lpair;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define print2(x,y) cout << (x) << " " << (y) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " \n"[i==n-1];};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    double v[55];
    rep(i,0,N) cin >> v[i];
    sort(v, v+N);
    double ans = 0.0;
    priority_queue<double, vector<double>, greater<double> > pq;
    rep(i,0,N) pq.push(v[i]);
    while(not pq.empty()){
        if(pq.size() == 1){
            ans = pq.top();
            cout << setprecision(10) << ans << endl;
            return 0;
        }else{
            double l1 = pq.top();
            pq.pop();
            double l2 = pq.top();
            pq.pop();
            double v = (l1 + l2) / 2.0;
            pq.push(v);
        }
    }



}

Measured memory_bytes: 256
n=int(input())
s=input()
def f(x,y):
  ret=x+y
  for i in range(2,n):
    if s[i-1]=="o" and ret[-1]=="S":
      ret+=ret[-2]
    elif s[i-1]=="o" and ret[-1]=="W":
      if ret[-2]=="S":
        ret+="W"
      else:
        ret+="S"
    elif s[i-1]=="x" and ret[-1]=="S":
      if ret[-2]=="S":
        ret+="W"
      else:
        ret+="S"
    elif s[i-1]=="x" and ret[-1]=="W":
      ret+=ret[-2]
  return ret
def chk(A):
  B=[A[-2],A[-1],A[0],A[1]]
  ret=True
  if s[-1]=="o":
    if B[1]=="S":
      if B[0]!=B[2]:
        ret=False
    else:
      if B[0]==B[2]:
        ret=False
  else:
    if B[1]=="S":
      if B[0]==B[2]:
        ret=False
    else:
      if B[0]!=B[2]:
        ret=False
  if s[0]=="o":
    if B[2]=="S":
      if B[1]!=B[3]:
        ret=False
    else:
      if B[1]==B[3]:
        ret=False
  else:
    if B[2]=="S":
      if B[1]==B[3]:
        ret=False
    else:
      if B[1]!=B[3]:
        ret=False
  return ret
if chk(f("S","S")):
  print(f("S","S"))
elif chk(f("S","W")):
  print(f("S","W"))
elif chk(f("W","S")):
  print(f("W","S"))
elif chk(f("W","W")):
  print(f("W","W"))
else:
  print(-1)

Measured memory_bytes: 3572
#![allow(unused_imports)]

use proconio::{input, fastout};
use proconio::marker::*;
use im_rc::HashMap;

#[fastout]
fn main() {
    input! {
    n: usize
    }
    if n == 1 {
        println!("0");
        return;
    }
    let mut l = vec![];
    let mut t = 2;
    let mut k = n.clone();
    while t * t <= n {
        while k % t == 0 {
            l.push(t);
            k /= t;
        }
        t += 1;
    }
    if k != 1 {
        l.push(k);
    }
    let mut ans = 0;
    let m = l.len();
    let mut i = 0;
    let mut d = 0;
    while i < m {
        if i != 0 && l[i] != l[i - 1] {
            d = 0;
        }
        if i + d < m && l[i] == l[i + d] {
            ans += 1;
            i += d;
            d += 1;
        }
        i += 1;
    }
    println!("{}", ans);
}



Measured memory_bytes: 2160
/***********************
*  Author: xuziyuan    * 
***********************/

#include <bits/stdc++.h>

#define rt0 return 0
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define replet(c) for(char c='a';c<='z';c++) 
#define LL long long
#define pii pair <int,int>
#define pb push_back
#define fi first
#define se second
#define mpr make_pair
#define sqr(a) ((a)*(a))

using namespace std;

const LL MOD=1e9+7;

int n,k;

int main()
{
	cin>>n>>k;
	if(k==1) cout<<0<<endl;
	else cout<<n-k<<endl;
	rt0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <algorithm>
#include <iomanip>

const int mod=1e9+7;
using LL=long long;
using std::cout;using std::endl;using std::cin;
using std::vector;using std::string;using std::set;using std::multiset;
using std::pair;using std::map;
using std::min;using std::max;
using std::make_pair;
std::ostream& operator<<(std::ostream& os,std::map<int,int>& obj){for(std::map<int,int>::iterator itr=obj.begin();itr!=obj.end();itr++){os<<itr->first<<"^"<<itr->second<<" ";}return os;}
std::ostream& operator<<(std::ostream& os,std::vector<std::map<int,int>>& obj){for(auto itr=obj.begin();itr!=obj.end();itr++){os<<*itr<<std::endl;}return os;}
std::ostream& operator<<(std::ostream& os,std::vector<int>& obj){for(auto itr=obj.begin();itr!=obj.end();itr++){os<<*itr<<endl;}return os;}

namespace ndifix{
template<class T>void sort(T &v){std::sort(v.begin(),v.end());}
template<class T>void rsort(T &v){std::sort(v.rbegin(),v.rend());}

}

int main(){
  std::cout<<std::setprecision(10);
  
  double h,w,x,y;cin>>w>>h>>x>>y;
  
  cout<<w*h/2.0<<" ";
  if(2*x==w && 2*y==h)cout<<1<<endl;
  else cout<<0<<endl;
  
}


Measured memory_bytes: 256
/*
	B - Shift only
*/
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;

double EPS = 1e-10;

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define int(x) int x; cin >> x;
#define lint(x) long long x; cin >> x;
#define vint(v,n) vector<int> v(n); REP(i,n) cin >> v[i];
#define vlint(v,n) vector<lint> v(n); REP(i,n) cin >> v[i];
#define double(x) double x; cin >> x[i];
#define vdouble(v,n) vector<double> v(n); REP(i,n) cin >> v[i];
#define string(x) string x; cin >> x;

int main()
{
	int(N);
	vint(A,N);
	int result = 0;
	bool flag = true;
	
	REP(i, N)
	{
		if (A[i] % 2 != 0)
			flag = false;
	}

	while (flag)
	{
		result++;
		REP(i, N)
		{
			A[i] /= 2;
			if (A[i] % 2 != 0)
				flag = false;
		}
	}

	cout << result << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  vector<int>a(n);
  for(int i=0;i<n;i++){
    cin>>a.at(i);
  }
  int pre=-999;
  for(int i=0;i<n;i++){
    if(pre<=a.at(i)-1){
      pre=a.at(i)-1;
    }
    else if(pre<=a.at(i)){
      pre=a.at(i);
    }
    else{
      cout<<"No"<<endl;
      return 0;
    }
  }
  cout<<"Yes"<<endl;
  return 0;
}


Measured memory_bytes: 3708
#include<iostream>
#include<sstream>
#include<vector>
#include<algorithm>
#include<string>
#include<stdexcept>
#include<stdio.h>
#include<queue>
#include <cmath>
#include<bits/stdc++.h>
//for(int i=0;i<n;i++)
#define cinf(n,x) for(int i=0;i<n;i++) cin >> x[i];
#define pi pair<int,int> 
using namespace std;
using ll = long long;
int main(){
    int n; cin >> n;
    int a[n]; 
    int ma[n+1],mb[n+1];
    ma[-1]=0;mb[n]=0;
    for(int i=0;i<n;i++){
        cin >> a[i]; 
        ma[i]=max(ma[i-1],a[i]);
        //左からMAX
    }
    for(int i=n-1;i>=0;i--){
        mb[i]=max(mb[i+1],a[i]);
        //右からMAX
    }
    for(int i=0;i<n;i++){
        cout << max(ma[i-1],mb[i+1]) << endl;
    }
    return 0;
}




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

int main() {
	int X;
	cin >> X;
	while (1) {
		int flag = 0, i;
		for (i = 2; i * i <= X; i++) {
			if (X % i == 0) flag = 1;
		}
		if (flag == 0) break;
		X++;
	}
	cout << X << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;

const int dx[4] = {-1, 0, 0, 1};
const int dy[4] = {0, -1, 1, 0};

// Self settings
// clang-format off
#define MAX_N 100000
#define REP(i, N) for (int i = 0; i < (int)(N); ++i)
#define SLN(i,N) (i == N-1 ? "\n" : " ")
ll fact(ll n) { ll res = 1; for(ll i=2;i<=n;++i) res = res * i; return res;}
ll nCr(ll n, ll r) {return (fact(n)/fact(n-r)*fact(r)) ;}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
const ll MOD = 1e9+7;
const ll INF = 1LL << 60;
const int inf = 1 << 30;
// clang-format on

char a, b;

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> a >> b;

  bool aa = a == 'H';
  bool bb = b == 'H';
  bool ans = true;

  if (aa) ans = !ans;
  if (bb) ans = !ans;

  cout << (ans ? 'H' : 'D') << endl;

  return 0;
}


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

using namespace std;

int main(){
    int n, k;
    cin >> n >> k;
    
    long long int trees[n];
    for(int i = 0; i < n; i++){
        cin >> trees[i];
    }
    sort(trees, trees+n);
    long long int ans = 0;
    for(int i = 0; i < n - k + 1; i++){
        if(i == 0){
            ans = trees[i + k - 1] - trees[i];
        }else{
            if(ans >= trees[i + k - 1] - trees[i]){
                ans = trees[i + k - 1] - trees[i];
            }
        }
    }
    cout << ans;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i=0; i<(n); i++)
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
int main(){
    ll q,h,s,d; cin>>q>>h>>s>>d;
    ll n; cin>>n;
    ll res=q*4*n;
    chmin(res, h*2*n);
    chmin(res, s*n);
    if(n%2==0) chmin(res, d*n/2);
    else{
        chmin(res, d*(n/2)+4*q);
        chmin(res, d*(n/2)+2*h);
        chmin(res, d*(n/2)+s);
    }
    cout<<res<<endl;
    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define EPS (1e-7)
#define INF (1e9)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
const double PI = acos(-1);
const ll MOD = 1000000007;
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;
}
///////////////////////////////////////////////////////////////


int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
	int N; cin >> N;
	vector<int> a(N);
	rep(i,N) cin >> a[i];

	int p = INF;
	int k = 0;
	rep(i,N) if (chmin(p,a[i])) k = i;

	cout << k+1 << endl;
}



Measured memory_bytes: 3356
#include<cstdio>
int main(){
    int n;
    scanf("%d",&n);
    if(n>27)printf("Yes");
    else{
        bool a[28];
        for(int i=0;i<28;i++)a[i]=false;
        for(int i=0;i<28;i+=7){
            for(int j=0;i+j<28;j+=4)a[i+j]=true;
        }
        if(a[n])printf("Yes");
        else printf("No");
    }
    return 0;
}

Measured memory_bytes: 128
#include <stdio.h>

#if 1
#define gc() getchar_unlocked()
#define pc(c) putchar_unlocked(c)
#else
#define gc() getchar()
#define pc(c) putchar(c)
#endif
int in()
{
	int n = 0, c = gc();
	do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');
	return n;
}

char buf[20];
void mypr(int n)
{
	int i;
	if (!n) { pc('0'); return; }
	i = 0; while (n) buf[i++] = n%10 + '0', n/=10;
	while (i--) pc(buf[i]); 
}

typedef struct { char c; int a; int id; } DATA;

int partition(DATA *a, int lo, int hi)
{
	int i, j;
	int key;
	DATA t;
	
	key = a[hi].a, i = lo-1;
	for (j = lo; j < hi; j++) {
		if (a[j].a <= key) i++, t = a[i], a[i] = a[j], a[j] = t;
	}
	t = a[++i], a[i] = a[hi], a[hi] = t;
	return i;
}

void quick_sort(DATA *a, int lo, int hi)
{
	int mi;

	if (lo < hi) {
		mi = partition(a, lo, hi);
		quick_sort(a, lo, mi-1);
		quick_sort(a, mi+1, hi);
	}
}

DATA a[100002];

int main()
{
	int N, i, f;

	N = in();
	for (i = 0; i < N; i++) {
		a[i].c = gc(), gc();
		a[i].a = in(), a[i].id = i;
	}
	quick_sort(a, 0, N-1);
	f = 0; for (i = 1; i < N; i++) {
		if (a[i-1].a == a[i].a && a[i-1].id > a[i].id) { f = 1; break; }
	}
	puts(f? "Not stable": "Stable");
	for (i = 0; i < N; i++) {
		pc(a[i].c), pc(' '), mypr(a[i].a), pc('\n');
	}
	return 0;
}



Measured memory_bytes: 2708
#include <cassert>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <numeric>
#include <algorithm>

using namespace std;
using lint = long long;
constexpr int MOD = 1000000007, INF = 1010101010;
constexpr lint LINF = 1LL << 60;

template <class T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
	for (const auto &e : vec) os << e << (&e == &vec.back() ? "\n" : " ");
	return os;
}

#ifdef _DEBUG
template <class T>
void dump(const char* str, T &&h) { cerr << str << " = " << h << "\n"; };
template <class Head, class... Tail>
void dump(const char* str, Head &&h, Tail &&... t) {
	while (*str != ',') cerr << *str++; cerr << " = " << h << "\n";
	dump(str + (*(str + 1) == ' ' ? 2 : 1), t...);
}
#define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__)
#else 
#define DMP(...) ((void)0)
#endif

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

int main() {

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

	int N, M;
	cin >> N >> M;

	vector<vector<int>> d(N, vector<int>(N, INF));
	for (int i = 0; i < M; i++) {
		int a, b;
		cin >> a >> b;
		a--, b--;
		d[a][b] = 1;
	}
	DMP(d);

	for (int k = 0; k < N; k++) {
		for (int i = 0; i < N; i++) {
			for (int j = 0; j < N; j++) {
				if (d[i][k] == INF || d[k][j] == INF) continue;
				d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
			}
		}
	}
	DMP(d);

	int mincyc = INF;
	vector<int> ans;
	for (int i = 0; i < N; i++) chmin(mincyc, d[i][i]);
	if (mincyc == INF) cout << -1 << "\n";
	else {

		for (int i = 0; i < N; i++) {
			if (d[i][i] == mincyc) {
				bool ok = true;
				for (const auto &e : ans) if (mincyc != d[e][i] + d[i][e]) ok = false;
				if (ok) ans.emplace_back(i);
			}
			if (ans.size() == mincyc) break;
		}

		cout << ans.size() << "\n";
		for (const auto &e : ans) cout << e + 1 << "\n";
	}

	return 0;
}

Measured memory_bytes: 6272