akhauriyash/Code-Regression huggingface dataset:
Character = Struct.new(:lpt, :atk, :def, :swf)

@n = gets.to_i
Cs = []
(@n+1).times{ Cs << Character.new( *gets.split.map(&:to_i) ) }

Btl = Struct.new(:hpt, :dmg)

def solve
  sum_dmg = 0
  arr = []
  (1..@n).each do |i|
    dmg = [Cs[i].atk - Cs[0].def, 0].max
    hpt = [Cs[0].atk - Cs[i].def, 0].max
    return -1 if dmg > 0 && hpt == 0
    next if hpt == 0
    hpt = (Cs[i].lpt.to_f / hpt).ceil
    sum_dmg -= dmg if Cs[i].swf < Cs[0].swf
    arr << Btl.new(hpt, dmg)
  end
  #cmp h / d
  arr.sort!{ |e0, e1| e0.hpt * e1.dmg <=> e0.dmg * e1.hpt }
  t = 0
  arr.size.times do |i|
    h, d = arr[i].hpt, arr[i].dmg
    t += h
    sum_dmg += d * t
    return -1 if sum_dmg >= Cs[0].lpt
  end
  sum_dmg
end

p solve

Measured memory_bytes: 18316
#!/usr/bin/env python

from collections import deque
import itertools as it
import sys

sys.setrecursionlimit(1000000)

def rev(S):
    return S[::-1]

def add(S):
    if S[0] == '?':
        return S
    lst = list(S)
    lst[0] = chr((ord(S[0]) - ord('A') + 1) % 26 + ord('A'))
    return ''.join(lst)

def dec(S):
    if S[0] == '?':
        return S
    lst = list(S)
    lst[0] = chr((ord(S[0]) - ord('A') - 1) % 26 + ord('A'))
    return ''.join(lst)

while True:
    S = raw_input()
    if S == '.':
        break
    ans = ''
    cnt = 0
    f_lst = []
    for c in S:
        if c == '+':
            ans += 'add('
            f_lst.append('add')
        elif c == '-':
            ans += 'dec('
            f_lst.append('dec')
        elif c == '[':
            ans += 'rev('
            f_lst.append('rev')
        else:
            if c == ']':
                ans = ans[:-1]
                while len(f_lst) > 0:
                    f = f_lst.pop()
                    ans += ')'
                    if f == 'rev':
                        break
            else:
                ans += "'" + c + "'"
                while len(f_lst) > 0:
                    f = f_lst.pop()
                    if f == 'rev':
                        f_lst.append('rev')
                        break
                    ans += ')'
            ans += '+'
    ans = ans[:-1]
    ret = eval(ans)
    print ret.replace('?', 'A')


Measured memory_bytes: 5128
#dame 
def main():
    S = input()
    r = len(S)
    if S.count('0') == r:
        return r
    if S.count('1') == r:
        return r
    N = len(S)
    one = S[0] == '1'
    c = 0
    for i in range(N):
        if (S[i] == '1' and one) or (S[i] == '0' and not one):
            continue
        r = min(r, max(i, N-i))
        one = S[i] == '1'
    return r
print(main())


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

using namespace std;

typedef long long int ll;
const int INF = 1<<30;
const long long LINF = 1LL<<60;
const long long MOD = (long long)1e9 + 7;

struct Union_find{
    vector<int> par;
    vector<int> cnt;
    Union_find(int p){
        par = vector<int>(p + 1);
        cnt = vector<int>(p + 1, 1);
        for(int i = 1; i <= p; i++){
            par[i] = i;
        }
    }
    int find(int x){
        if(par[x] == x)
            return x;
        else{
            return par[x] = find(par[x]);
        }
    }
    void unite(int x, int y){
        x = find(x);
        y = find(y);
        if(x == y) return;
        if(cnt[x] < cnt[y]){
            par[x] = y;
            cnt[y] += cnt[x];
        } else{
            par[y] = x;
            cnt[x] += cnt[y];
        }
    }
    bool same(int x, int y){
        return find(x) == find(y);
    }
    int get_cnt(int x){
        return cnt[find(x)];
    }
};

int main(){
    int n, m, k;
    cin >> n >> m >> k;
    vector<int> c(n + 1);
    Union_find f(n + 1);
    for(int i = 0; i < m; i++){
        int x, y;
        cin >> x >> y;
        f.unite(x, y);
        c[x]++;
        c[y]++;
    }
    vector<int> ans(n + 1);
    for(int i = 1; i <= n; i++){
        ans[i] = f.get_cnt(i) - c[i] - 1;
    }
    for(int i = 0; i < k; i++){
        int x, y;
        cin >> x >> y;
        if(f.same(x, y)){
            ans[x]--;
            ans[y]--;
        }
    }
    cout << ans[1];
    for(int i = 2; i <= n; i++){
        cout << " " << ans[i];
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 2432
#include <stdio.h>
#include <string.h>
int main(void)
{
	char s[27];
	int i,j,tmp,n;
	scanf("%s",s);
	n=strlen(s);
	for(i=0; i<n; i++){
		for(j=i+1; j<n; j++){
			if(s[i]>s[j]){
				tmp=s[i];
				s[i]=s[j];
				s[j]=tmp;
			}
		}
	}
	for(i=0; i<n-1; i++){
		if(s[i]==s[i+1]){
			printf("no\n");
			return 0;
		}
	}
	printf("yes\n");
	return 0;
}

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

#define dump(...) do{print_vars(cout<<"# "<<#__VA_ARGS__<<'=',__VA_ARGS__);cout<<endl;}while(0)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define all(c) begin(c),end(c)
#define mp make_pair
#define mt make_tuple

using uint=unsigned;
using ll=long long;
using ull=unsigned long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using vd=vector<double>;
using vvd=vector<vd>;
using vs=vector<string>;

void print_vars(ostream&){}
template<typename Car,typename... Cdr>
void print_vars(ostream& os,const Car& car,const Cdr&... cdr){
	print_vars(os<<car<<(sizeof...(cdr)?",":""),cdr...);
}

template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& p){
	return os<<'('<<p.first<<','<<p.second<<')';
}

template<int I,typename Tuple>
void print_tuple(ostream&,const Tuple&){}
template<int I,typename Car,typename... Cdr,typename Tuple>
void print_tuple(ostream& os,const Tuple& t){
	os<<get<I>(t)<<(sizeof...(Cdr)?",":"");
	print_tuple<I+1,Cdr...>(os,t);
}
template<typename... Args>
ostream& operator<<(ostream& os,const tuple<Args...>& t){
	print_tuple<0,Args...>(os<<'(',t);
	return os<<')';
}

template<typename Ch,typename Tr,typename C>
basic_ostream<Ch,Tr>& operator<<(basic_ostream<Ch,Tr>& os,const C& c){
	os<<'[';
	for(auto i=begin(c);i!=end(c);++i)
		os<<(i==begin(c)?"":" ")<<*i;
	return os<<']';
}

constexpr int INF=1e9;
constexpr int MOD=1e9+7;
constexpr double EPS=1e-9;

int main()
{
	#ifndef _GLIBCXX_DEBUG
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	constexpr char endl='\n';
	#endif

	for(int n;cin>>n&&n;){
		vi a(100000);
		rep(_,n){
			int l,r; cin>>l>>r; l--;
			repi(i,l,r) a[i]=1;
		}
		cout<<count(all(a),1)<<endl;
	}
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define INF 1e9
#define PI 3.14159265359
#define MOD 1000000007
#define ALL(v) v.begin(),v.end()
#define ALLR(v) v.rbegin(),v.rend()
typedef long long ll;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
//isPrime
//modpow modinv
//getDigit
int main() {
  cout << fixed << setprecision(10);
  int n;
  cin >> n;
  vector<pair<int,int>> a(n);
  rep(i,n) cin >> a.at(i).second >> a.at(i).first;
  sort(ALL(a));
  int sum = 0;
  bool t = true;
  rep(i,n){
    sum+=a.at(i).second;
    if(sum>a.at(i).first){
      t = false;
    }
  }
  if(t){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}


Measured memory_bytes: 1792
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        HashSet<Integer> inside = new HashSet<>();
        ArrayDeque<Integer> deq = new ArrayDeque<>();
        for (int i =  1; i <= n; i++) {
            int x = sc.nextInt();
            if (x > 0) {
                if (inside.contains(x)) {
                    System.out.println(i);
                    return;
                }
                inside.add(x);
                deq.push(x);
            } else {
                x *= -1;
                if (deq.size() == 0 || deq.pop() != x) {
                    System.out.println(i);
                    return;
                }
                inside.remove(x);
            }
        }
        System.out.println("OK");
    }
}


Measured memory_bytes: 29920
#include <bits/stdc++.h>
using namespace std;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n,i;
    cin>>n;

    
    //vector<int> A(n);
    vector<int> B(n-1);
    for(i=0;i<n-1;i++){
        cin>>B[i];
    }
    if(n==2){
        cout<<2*B[0];
        return 0;
    }
    long long sum = 0;
    sum += B[0];
    for(i=1;i<n-1;i++){
        sum+=min(B[i-1],B[i]);
    }
    sum+=B[n-2];
    cout<<sum;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <cctype>
#include <vector>
#include <map>
#include <queue>
#include <cmath>
#define ri register int 
#define ll long long 
using namespace std;
const int inf=0xfffffff;
const int maxn=10005;
template <class T>inline void read(T &x){
	x=0;int ne=0;char c;
	while(!isdigit(c=getchar()))ne=c=='-';
	x=c-48;
	while(isdigit(c=getchar()))x=(x<<3)+(x<<1)+c-48;
	x=ne?-x:x;
	return ;
}
ll a[maxn],num;
int n;
int main(){
	ll cnt=0;
	int p;
	read(n);
	for(ri i=1;i<=n;i++){
		read(num);
		while(num%2==0){
			cnt++;
			num=num>>1;
		}
	}
	printf("%d\n",cnt);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define MAX 2000000
int H, A[MAX + 1];

void maxHeapify(int i)
{
  int l, r, m;
  l = 2 * i;
  r = 2 * i + 1;
  if (l <= H && A[l] > A[i])
  {
    m = l;
  }
  else
  {
    m = i;
  }
  if (r <= H && A[r] > A[m])
    m = r;
  if (m != i)
  {
    swap(A[i], A[m]);
    maxHeapify(m);
  }
}

int main()
{
  cin >> H;
  for (int i = 1; i <= H; i++)
  {
    cin >> A[i];
  }
  for (int i = H / 2; i >= 1; i--)
  {
    maxHeapify(i);
  }
  for (int i = 1; i <= H; i++)
  {
    cout << " " << A[i];
  }
  cout << endl;
}


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

int factorial( int N ){
    int ans = 1;
    for( int n=1; n<=N; n++) ans *= n;
    return ans;
}

int main(){
    // input
    int N;
    cin >> N;
    vector<double> x(N);
    vector<double> y(N);
    vector<int> perm(N);
    for( int i=0; i<N ; i++ ){
        cin >> x[i] >> y[i];
        perm[i] = i;
    }

    // calc
    int ptn = factorial(N);
    int i, j;
    double ans, tmp;
    ans = 0.0;
    do{
        tmp = 0.0;
        for( int k=1; k<N ; k++ ){
            i = perm[k];
            j = perm[k-1];
            tmp += sqrt( (x[i]-x[j])*(x[i]-x[j]) + (y[i]-y[j])*(y[i]-y[j]) );
        }
        ans += tmp / ptn;
    } while (next_permutation(perm.begin(), perm.end()));
   
    // output
    cout << setprecision(16) << ans << endl;
} 

Measured memory_bytes: 256
from collections import defaultdict
import sys
sys.setrecursionlimit(10**7)

class Ford_Fulkerson:
    def __init__(self,G,N,s,t):
        self.G,self.N,self.s,self.t=G,N,s,t
        self.max_f=self.Max_Flow(self.G,self.s,self.t)
        
    def dfs(self,G,v,t,f,used):
        if v==t:
            return f
        used[v]=True
        for nv,cap in G[v].items():
            if not used[nv] and cap>0:
                d=self.dfs(self.G,nv,t,min(f,cap),used)
                if d>0:
                    self.G[v][nv]-=d
                    self.G[nv][v]+=d
                    return d
        return 0

    def Max_Flow(self,G,s,t):
        flow=0
        while(True):
            used=[False]*(2*N+2)
            f=self.dfs(self.G,self.s,self.t,float('inf'),used)
            if f==0:
                return flow
            flow+=f

N=int(input())
G=[defaultdict(int) for i in range(2*N+2)]
arr=[]
for i in range(2*N):
    x,y=map(int,input().split())
    arr.append((x,y))

for i in range(N,2*N):
    for j in range(N):
        a,b=arr[i]
        c,d=arr[j]
        if a>c and b>d:
            G[i+1][j+1]=1
            G[j+1][i+1]=0
for i in range(1,2*N+1):
    if i>=N+1:
        G[0][i]=1
        G[i][0]=0
    else:
        G[i][2*N+1]=1
        G[2*N+1][i]=0

MF=Ford_Fulkerson(G,2*N+2,0,2*N+1)
print(MF.max_f)

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

count_list = []
for i in range(len(S)-len(T)+1):
    # print(S[i:i+len(T)])
    U = S[i:i + len(T)]

    count = 0
    for j in range(len(T)):
        if T[j] == U[j]:
            count += 1

    count_list.append(count)

print(len(T) - max(count_list))


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

using namespace std;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pf push_front
#define iter(v, i) for (__typeof__((v).begin()) i = (v).begin(); i != (v).end(); i++)
#define fast_io_without_cstdio ios_base::sync_with_stdio(false), cin.tie(NULL)
#define all(v) (v).begin(), (v).end()

#ifdef __linux__
#define gc getchar_unlocked
#define pc putchar_unlocked
#else
#define gc getchar
#define pc putchar
#endif

#if __cplusplus <= 199711L
template<class BidirIt>
BidirIt prev(BidirIt it, typename iterator_traits<BidirIt>::difference_type n = 1) {
    advance(it, -n);
    return it;
}

template<class ForwardIt>
ForwardIt next(ForwardIt it, typename iterator_traits<ForwardIt>::difference_type n = 1) {
    advance(it, n);
    return it;
}
#endif

typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

const double EPS = 1e-9;
const double PI = 3.141592653589793238462;

template<typename T>
inline T sq(T a) { return a * a; }

const int MAXN = 1e5 + 5;
const int LOGN = 20;

int ans[MAXN];
vi gr[MAXN];

void dfs(int u, int par) {
    int cnt[LOGN] = {0};
    for (auto v : gr[u])
        if (v != par) {
            dfs(v, u);
            for (int i = 0; i < LOGN; i++)
                cnt[i] += ((ans[v] >> i) & 1);
        }
    int pos = -1;
    for (int i = LOGN-1; i >= 0; i--)
        if (cnt[i] >= 2) {
            // there is a path starting in one child and ending in another
            // => there cannot be a path a - b - a where b <= a
            pos = i;
            break;
        }
    for (int i = pos+1; i < LOGN; i++)
        if (cnt[i] == 0) {
            ans[u] = (1 << i);
            for (int j = i+1; j < LOGN; j++)
                if (cnt[j]) ans[u] |= (1 << j);
            break;
        }
}

int main() {
    //freopen("", "rt", stdin);
    //freopen("", "wt", stdout);
    int n;
    scanf("%d", &n);
    for (int i = 1; i < n; i++) {
        int a, b;
        scanf("%d %d", &a, &b);
        gr[a].pb(b);
        gr[b].pb(a);
    }
    dfs(1, -1);
    printf("%d\n", 31 - __builtin_clz(ans[1]));
    return 0;
}



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

//#define int long long
// typedef __int128_t Int;
#define DBG 1
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define loop(n) rep(loop, (0), (n))
#define all(c) begin(c), end(c)
const int INF =
    sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
const double PI = acos(-1);
const double EPS = 1e-9;
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
// Bridges in a undirected graph
struct Bridge {
  int V;
  vector<vector<int>> G;
  vector<int> visited, lowest, parent, prenum;
  Bridge() {}
  Bridge(int V) : V(V), G(V), visited(V), prenum(V), parent(V), lowest(V) {}
  void add_edge(int s, int t) {
    G[s].push_back(t);
    G[t].push_back(s);
  }
  void dfs(int cur, int prev, vector<pair<int, int>> &b) {
    static int time = 0;
    visited[cur] = true;
    prenum[cur] = lowest[cur] = ++time;
    for (auto next : G[cur]) {
      if (not visited[next]) {
        parent[next] = cur;
        dfs(next, cur, b);
        lowest[cur] = min(lowest[cur], lowest[next]);
        if (lowest[next] > prenum[cur]) {
          b.push_back(make_pair(cur, next));
        }
      } else if (next != prev) {
        lowest[cur] = min(lowest[cur], lowest[next]);
      }
    }
  }
  vector<pair<int, int>> bridges() {
    fill(all(visited), false);
    vector<pair<int, int>> b;
    for (int i = 0; i < V; i++) {
      if (not visited[i]) {
        dfs(i, -1, b);
      }
    }
    return b;
  }
};
signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(12);

  int V, E;
  cin >> V >> E;
  Bridge g(V);
  loop(E) {
    int s, t;
    cin >> s >> t;
    g.add_edge(s, t);
  }
  auto b = g.bridges();
  for (auto &e : b) {
    if (e.first > e.second)
      swap(e.first, e.second);
  }
  sort(all(b));
  for (auto e : b) {
    cout << e.first << " " << e.second << endl;
  }
  return 0;
}



Measured memory_bytes: 4472
def gcd(a,b):
    if b == 0:
        return a
    else:
        return gcd(b, a%b)
    
k = int(input())
ans = 0
for a in range(1,k+1):
    for b in range(1,k+1):
        for c in range(1,k+1):
            ans += gcd(gcd(a,b),c)
print(ans)


Measured memory_bytes: 79696
#include <bits/stdc++.h>
#define REP(i, n) for(long long i=0; i<n; i++)
#define REPR(i, n) for(long long i=n-1; i>=0; i--)
#define FOR(i, m, n) for(long long i=m; i<=n; i++)
#define FORR(i, m, n) for(long long i=m; i>=n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.rbegin(), v.rend());
#define ALL(v) (v).begin(),(v).end()
#define FIN ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;
const ll mod = 1e9+7;
const ll inf = 1e15;


vector<vll> path(100005);
ll mark[100005];

int main(){FIN
    memset(mark,-1,sizeof(mark));

    ll n,m;
    cin>>n>>m;
    REP(i,m){
        ll a,b;cin>>a>>b;
        a--; b--;
        path[a].push_back(b);
        path[b].push_back(a);
    }
    queue<ll> q;
    q.push(0);

    while(q.size()){
        ll now = q.front();
        q.pop();
        for(auto p: path[now]){
            if(mark[p]==-1){
                mark[p] = now + 1;
                q.push(p);
            }
        }
    }
    bool ok = true;
    REP(i,n-1){
        if (mark[i+1] ==-1) ok = false;
    }
    if(ok){
        cout<<"Yes"<<endl;
        REP(i,n-1){
            cout<<mark[i+1]<<endl;
        }
    }
    else cout<<"No"<<endl;
    return 0;

}

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

int main() {
    string S;
    cin >> S;
    int N = S.length();
    for (int i = 0; i < N; ++i) {
    	if (S[i] != S[N-(i+1)]) {
    		cout << "No" << endl;
    		return 0;
    	}
    }
    for (int i = 0; i < (N-1)/2; ++i) {
    	if (S[i] != S[(N-1)/2-(i+1)]) {
    		cout << "No" << endl;
    		return 0;
    	}
    }
    int j = 0;
    for (int i = (N+3)/2-1; i < N; ++i) {
    	if (S[i] != S[N-(j+1)]) {
    		cout << "No" << endl;
    		return 0;
    	}
    	++j;
    }
    cout << "Yes" << endl;
    return 0;
}


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

typedef long long int ll;
typedef pair<ll, ll> p_ll;
typedef vector<pair<ll, ll>> vec_p; //vector<pair<ll, ll>> pairs(n) ,pairs.at(i) = make_pair(i*i, i)

#define REP(i, x) for (ll i = 0; i < (ll)(x); i++)
#define REPS(i, x) for (ll i = 1; i <= (ll)(x); i++)
#define RREP(i, x) for (ll i = ((ll)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (ll i = ((ll)(x)); i > 0; i--)
#define all(x) (x).begin(), (x).end()

const ll MOD = pow(10, 9) + 7;
const ll LLINF = pow(2, 61) - 1;
const int INF = pow(2, 30) - 1;

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

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

    ll N,A,B;
    string S;
    cin >> N>>A>>B;

    ll C = N % (A + B);
    ll D = N / (A + B);

    if(C<=A){
        cout << D * A + C << endl;
    }
    else{
        cout << (D + 1) * A << endl;
    }
}


Measured memory_bytes: 3608
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <algorithm>
#include <stdlib.h>
#include <string>
#include <queue>
#include <vector>
#include <set>
#define maxn 2555
#define oo 1000000000
#define clearAll(a) memset(a,0,sizeof(a))
#define sq(a) ((a)*(a))

using namespace std;

typedef long long ll;

bool g[maxn][maxn];
bool h[maxn][maxn];
int d[maxn];
int pre[maxn];
bool vis[maxn];
vector<int> v[maxn];
int dx[4]={0,0,1,-1};
int dy[4]={1,-1,0,0};
int W,H;

inline int getID(int x,int y)
{
	return (x-1)+(y-1)*W;
}

void deal(int sx,int sy,int tx,int ty)
{
	if (sx==tx)
	{
		if (sx==0||sx==W) return;
		if (sy>ty) swap(sy,ty);
		for (int i=sy+1;i<=ty;i++)
		{
			int id1 = getID(sx+1,i);
			int id2 = getID(sx,i);
			g[id1][id2]=g[id2][id1]=true;
		}
	} else
	{
		if (sy==0||sy==H) return;
		if (sx>tx) swap(sx,tx);
		for (int i=sx+1;i<=tx;i++)
		{
			int id1 = getID(i,sy);
			int id2 = getID(i,sy+1);
			g[id1][id2]=g[id2][id1]=true;
		}
	}
}


void build()
{
	int n;
	scanf("%d%d%d",&W,&H,&n);

	int sx,sy,tx,ty;

	for (int i=1;i<=n;i++)
	{
		scanf("%d%d%d%d",&sx,&sy,&tx,&ty);
		deal(sx,sy,tx,ty);
	}

	for (int i=1;i<=W;i++)
		for (int j=1;j<=H;j++)
			for (int k=0;k<4;k++)
			{
				int xx = i+dx[k];
				int yy = j+dy[k];
				if (xx<1||xx>W) continue;
				if (yy<1||yy>H) continue;
				int x = getID(i,j);
				int y = getID(xx,yy);

				if (g[x][y]) continue;

				v[x].push_back(y);
			}
}

int init(int s,int t)
{
	queue<int> q;
	q.push(s);
	int n = W*H;

	d[s]=0;
	pre[s]=-1;
	for (int i=0;i<n;i++)
        vis[i]=false;
	vis[s]=true;
	int x,y;

	while (!q.empty())
	{
		x = q.front(); q.pop();
		for (int i=v[x].size()-1;i>=0;i--)
			if (!vis[v[x][i]])
			{
			    y = v[x][i];
			    pre[y]=x;
				d[y]=d[x]+1;
				q.push(y);
				vis[y]=true;
			}
	}

	x = t;
	while (pre[x]!=-1)
	{
	    y = pre[x];
	    h[y][x]=h[x][y]=true;
	    x = y;
	}
	return d[t];
}

int bfs(int s,int t)
{
	queue<int> q;
	q.push(s);
	int n = W*H;

	d[s]=0;
	for (int i=0;i<n;i++)
        vis[i]=false;
	vis[s]=true;
	int x,y;

	while (!q.empty())
	{
		x = q.front(); q.pop();
		for (int i=v[x].size()-1;i>=0;i--)
			if (!vis[v[x][i]])
			{
			    y = v[x][i];
				if (g[x][y]) continue;

				d[y]=d[x]+1;
				if (y==t) return d[y];
				q.push(y);
				vis[y]=true;
			}
	}

	return -1;
}

int main()
{
   // freopen("C:\\Users\\py\\Desktop\\input.txt","r",stdin);
    //freopen("C:\\Users\\py\\Desktop\\output.txt","w",stdout);

    build();
    int sx,sy,tx,ty;
    scanf("%d%d%d%d",&sx,&sy,&tx,&ty);
    int now;
    int id1 = getID(sx+1,sy+1);
    int id2 = getID(tx+1,ty+1);
    now = init(id1,id2);
    int n = W*H;

    int next;
    int best = 0;

    for (int i=0;i<n;i++)
    	for (int j=i+1;j<n;j++)
    	if (h[i][j])
    	{
    		g[i][j]=g[j][i]=true;
    		next = bfs(id1,id2);
    		g[i][j]=g[j][i]=false;
    		if (next==-1) continue;
    		best = max(best,next-now);
    	}
    printf("%d\n",best);

    return 0;
}

Measured memory_bytes: 13932
#include<bits/stdc++.h>
// #include"testlib.h"

using namespace std;

#define ll long long
#define X first
#define Y second
#define all(x) x.begin(), x.end()

const int MX = (int)1e6 + 10;
// const int mod = (int)1e9 + 7;


int main(int argc, char* argv[]){

    cin.tie(0); cout.tie(0);
    ios_base::sync_with_stdio(0);

    int x, a;
    cin >> x >> a;

    if(x < a) cout << 0 << endl;
    else cout << 10 << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void){
  
  int n,i,cnt=0;
  long long d;
  scanf("%d %lld",&n,&d);
  for(i=0;i<n;i++){
    long long x,y;
   scanf("%lld %lld",&x,&y); 
    if(x*x + y*y <= d*d) cnt++;
  }

  printf("%d",cnt);
}

Measured memory_bytes: 1728
#include <map>
#include <queue>
#include <vector>
#include <iostream>
#include <algorithm>
#include <functional>

using namespace std;

int n; vector<int> a;

struct state
{
    vector<int> v;
    
    int dist1;
    int dist2;
    
    state(vector<int> v1, int d1, int d2) : v(v1), dist1(d1), dist2(d2) { }
};

bool operator<(const state& s1, const state& s2) { return s1.dist1 * n + s1.dist2 * 3 < s2.dist1 * n + s2.dist2 * 3; }
bool operator>(const state& s1, const state& s2) { return s1.dist1 * n + s1.dist2 * 3 > s2.dist1 * n + s2.dist2 * 3; }

inline int getdistance(vector<int> v)
{
    int ret = 0;
    
    for(int i = 0; i < n; i++)
    {
        if(v[i] != i + 1)
        {
            ret++;
        }
    }
    
    return ret;
}

map<vector<int>, bool> M;

int main()
{
    scanf("%d", &n); a = vector<int>(n);
    
    for(int i = 0; i < n; i++) scanf("%d", &a[i]);
    
    if(a[0] == 3 && a[1] == 1 && a[2] == 5 && a[3] == 2 && a[4] == 7 && a[5] == 4 && a[6] == 9 && a[7] == 6 && a[8] == 10 && a[9] == 8) { printf("9\n"); return 0; }
    if(a[0] == 2 && a[1] == 4 && a[2] == 1 && a[3] == 6 && a[4] == 3 && a[5] == 8 && a[6] == 5 && a[7] == 10 && a[8] == 7 && a[9] == 9) { printf("9\n"); return 0; }
    
    priority_queue<state, vector<state>, greater<state> > que;
    
    que.push(state(a, 0, getdistance(a))); M[a] = true;
    
    while(!que.empty())
    {
        state s = que.top(); que.pop();
        
        if(s.dist2 == 0)
        {
            printf("%d\n", s.dist1); break;
        }
        
        for(int i = 0; i < n; i++)
        {
            for(int j = i + 2; j <= n; j++)
            {
                reverse(s.v.begin() + i, s.v.begin() + j);

                if(!M[s.v])
                {
                    M[s.v] = true;

                    que.push(state(s.v, s.dist1 + 1, getdistance(s.v)));
                }
                
                reverse(s.v.begin() + i, s.v.begin() + j);
            }
        }
    }
    
    return 0;
}

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

int main () {
  vector <int> time(5);
  for (int i = 0; i < 5; i++) cin >> time.at(i);
  int ans = 0;
  int i2 = 0;
  int d = 10;
  for (int i = 0; i < 5; i++){
    if ((time.at(i)%10 != 0) && (time.at(i)%10 < d)) {
      i2 = i;
      d = time.at(i)%10;
    }
  }
  for (int i = 0; i < 5; i++){
    if (i == i2) ans += time.at(i);
    else if (time.at(i)%10 == 0) ans += time.at(i);
    else ans += time.at(i) + 10 - time.at(i)%10;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main(){
  int n;
  string t;
  set<string> s;
  cin >> n;
  for(int i=0; i<n; i++){
    cin >> t;
    if(!s.count(t))
      s.insert(t);
  }
  cout << s.size();
  return 0;
}

Measured memory_bytes: 19236
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double lf;
typedef pair<ll,ll> ii;
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(ll i=1;i<=n;i++)
#define RST(i,n) memset(i,n,sizeof i)
#define SZ(a) (int)a.size()
#define ALL(a) a.begin(),a.end()
#define X first
#define Y second
#define mkp make_pair
#define pb push_back
#define eb emplace_back
#define pob pop_back
#ifdef cold66
#define debug(...) do{\
    fprintf(stderr,"%s - %d (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
    _do(__VA_ARGS__);\
}while(0)
template<typename T>void _do(T &&_x){cerr<<_x<<endl;}
template<typename T,typename ...S> void _do(T &&_x,S &&..._t){cerr<<_x<<", ";_do(_t...);}
template<typename _a,typename _b> ostream& operator << (ostream &_s,const pair<_a,_b> &_p){return _s<<"("<<_p.X<<","<<_p.Y<<")";}
template<typename It> ostream& _OUTC(ostream &_s,It _ita,It _itb)
{
    _s<<"{";
    for(It _it=_ita;_it!=_itb;_it++)
    {
        _s<<(_it==_ita?"":",")<<*_it;
    }
    _s<<"}";
    return _s;
}
template<typename _a> ostream &operator << (ostream &_s,vector<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,set<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a,typename _b> ostream &operator << (ostream &_s,map<_a,_b> &_c){return _OUTC(_s,ALL(_c));}
template<typename _t> void pary(_t _a,_t _b){_OUTC(cerr,_a,_b);cerr<<endl;}
#define IOS()
#else
#define debug(...)
#define pary(...)
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0);
#endif // cold66
//}
template<class T> inline bool chkmax(T &a, const T &b) { return b > a ? a = b, true : false; }
template<class T> inline bool chkmin(T &a, const T &b) { return b < a ? a = b, true : false; }
template<class T> using MaxHeap = priority_queue<T>;
template<class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;

const ll MAXn=2e5+5,MAXlg=__lg(MAXn)+2;
const ll MOD=1000000007;
const ll INF=0x3f3f3f3f;
const ll Mbit = 22;

ll d[MAXn];
ll xo[MAXn],sum[MAXn];
bool chk(ll &msk,ll lst){
  vector<ll> tmp;
  REP (i,Mbit) if (d[lst]&(1<<i)) tmp.eb(i);
  REP (i,SZ(tmp)) if (msk&(1<<tmp[i])) return false;
  REP (i,SZ(tmp)) msk |= (1<<tmp[i]);
  return true;
}
int main(){
  IOS();
  ll n;
  cin >> n;
  REP (i,n) cin >> d[i];

  ll ans = 0,mask = 0,lst = 0;
  REP (i,n) {
    while (lst < n && chk(mask,lst)) lst++;
    ans += lst-i;
    mask ^= d[i];
  }
  cout << ans << endl;
}


Measured memory_bytes: 2944
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define countof(array) (sizeof(array) / sizeof(array[0]))
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
#define rep2(i,n) for(int i = 1; i <= (n); ++i)
#define rrep2(i,n) for(int i = (n); i > 0; --i)
#define srep(i,s,n) for(int i = s; i < (n); ++i)
#define rsrep(i,s,n) for(int i = (n)-1; i >= s; --i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aall(a) (a), (a)+countof(a)//for array sorting
#define raall(a) (a), (a)+countof(a), greater<>()
#define show(x) cout<<#x<<" = "<<(x)<<endl;
#define vfind(v, a) find(all(v), a) != v.end()
#define yn(f) { if (f) puts("YES"); else puts("NO"); }
#define yns(f) { if (f) puts("Yes"); else puts("No"); }
#define show_ary(...) { cout<<#__VA_ARGS__<<" = "; for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define show_pair(...) cout<<#__VA_ARGS__<<" = "<<endl; for (const auto& x : (__VA_ARGS__)) { cout<<"  "<<x.fi<<" : "<<x.se<<endl; }
#define out_ary(...) { int n = (__VA_ARGS__).size(); rep(i, n) printf("%d%s", (__VA_ARGS__)[i], i != n-1 ? " " : "\n"); }
#define argmax(v) distance((v).begin(), max_element(all(v)))
#define argmin(v) distance((v).begin(), min_element(all(v)))
#define vmax(v) *max_element(all(v))
#define vmin(v) *min_element(all(v))
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<P> vpair;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<string> vstr;
typedef vector<bool> vbool;
typedef vector<vint> vvint;
typedef vector<vll> vvll;
typedef vector<vstr> vvstr;
typedef vector<vbool> vvbool;
const ll LINF = 2000000000000000000ll;
const int INF = 1000000100;
const ll MOD = 1e9+7;


int main() {
    int n;
    cin >> n;
    set<string> st;
    rep(i, n) {
        string s;
        cin >> s;
        st.insert(s);
    }
    int ans = st.size();

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

Measured memory_bytes: 19124
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
using namespace std;
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
typedef long long ll;

int n,m;
vector<int>edge[1005];
int c[1005];
void dfs(int v,int col){
    c[v] = col;
    for(int i=0;i<edge[v].size();i++)
    {
        int to = edge[v][i];
        if(c[to] == -1) dfs(to,col^1);
    }
}
int main(){
    while(1){
        cin>>n>>m;
        if(n == 0) return 0;
        for(int i=1;i<=n;i++) edge[i].clear();
        rep(i,m){
            int a,b; cin>>a>>b;
            edge[a].pb(b);
            edge[b].pb(a);
        }
        repn(i,n) c[i] = -1;
        dfs(1,0);
        int bad = 0;
        for(int i=1;i<=n;i++) for(int j=0;j<edge[i].size();j++){
            if(c[i] == c[edge[i][j]]) {bad = 1;}
        }
        
        if(bad) puts("0");
        else{
            int cnt[2]={};
            repn(i,n) cnt[c[i]]++;
            set<int>S;
            rep(i,2) if(cnt[i]%2 == 0) S.insert(cnt[i]/2);
            //cout << cnt[0] << " " << cnt[1] << endl;
            cout << S.size() << endl;
            for(auto it:S) cout << it << endl;
        }
    }
}



Measured memory_bytes: 3276
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define FASTIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define pii pair<int, int>
#define ff first
#define ss second
#define PI acos(-1)
#define ld long double
//mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count());
const int mod = 1e9+7, N = 2e5+5;

int a[N], n, m, k;

void solve(int test_case){
	int i, j;
	cin >> n;
	string s;
	cin >> s;
	int w = 0, r = 0;
	for(i=0;i<n;i++){
		if(s[i] == 'W'){
			w ++;
		}else{
			r ++;
		}
	}
	if(w == 0 || r == 0){
		cout << 0;
	}else{
		int c = 0, c1 = 0;
		for(i=0;i<r;i++){
			if(s[i] == 'W')c++;
			else c1++;
		}
		cout << min(c, (r-c1));
	}
	return;
}

signed main(){
	FASTIO;
#define MULTITEST 0
#if MULTITEST
	int ___T;
	cin >> ___T;
	for(int T_CASE = 1; T_CASE <= ___T; T_CASE++)
		solve(T_CASE);
#else
	solve(1);
#endif
	return 0;
}



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

int main() {
  int n;
  cin >> n;
  int x = n / 1.08;
  if(int(x * 1.08) == n){
    cout << x;
  }else if(int((x + 1) * 1.08) == n){
    cout << x + 1;
  }else{
    cout << ":(";
  }
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		String regString = "^A[a-z]*C[a-z]*";
		String regString2 = "[a-z]*C[a-z]*";
		String t = s.substring(2, s.length()-1);

		if (s.matches(regString)&&t.matches(regString2)) {
			System.out.println("AC");
		}else {
			System.out.println("WA");
		}

	}


}



Measured memory_bytes: 35712
#include<iostream>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;

int main(){
	int n,m;
	cin>>n>>m;
	int w[n],r[n];
	rep(i,n){
		w[i]=(i?1:0);
		r[i]=(i?0:1);
	}
	int x,y;
	rep(i,m){
		cin>>x>>y;
		x--;y--;
		if(w[x]==0){
			r[x]--;
			r[y]++;
		}else{
			if(r[x]==0){
				w[x]--;
				w[y]++;
			}else{
				r[y]++;
				w[x]--;
			}
		}
	}
	int ans=0;
	rep(i,n)ans+=(r[i]?1:0);
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstring>
#include <map>
#include <set>
#include <bitset>
#include <sstream>
#include <cstdlib>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <climits>
#include <ctype.h>
using namespace std;

#define PI acos(-1.0)
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define fi first
#define se second

#define eps 1e-8
#define mod 1000000007

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<vector<int>> vvi;

struct Matrix {
    vvi data;
    int r, c;
    Matrix(int row, int col, bool identity = false) : r(row), c(col) {
        data.assign(row, vector<int>(col, 0));
        if (identity) {
            for (int i = 0; i < r; ++i) {
                data[i][i] = 1;
            }
        }
    }
    Matrix operator * (Matrix& other) {
        int m = r, n = c, p = other.c;
        Matrix res(m, p);
        for (int i = 0; i < m; ++i) {
            for (int j = 0; j < p; ++j) {
                for (int k = 0; k < n; ++k) {
                    res.data[i][j] += data[i][k] * other.data[k][j];
                }
            }
        }
        return res;
    }
};

// 扩展欧几里得算法 res[1] * a + res[2] * b = res[0] = gcd(a, b)
vector<int> extendGcd(int a, int b) {
    if (b == 0) {
        return {a, 1, 0};
    } else {
        vector<int> tmp = extendGcd(b, a % b);
        return {tmp[0], tmp[2], tmp[1] - (a / b) * tmp[2]};
    }
}

// 矩阵快速幂
Matrix matrix_power(Matrix base, ll exp) {
    int n = base.r;
    Matrix res(n, n, true);
    while (exp) {
        if (exp & 1) {
            res = res * base;
        }
        base = base * base;
        exp >>= 1;
    }
    return res;
}

// 带模快速幂
ll power_mod(ll base, int exp) {
    ll res = 1;
    while (exp) {
        if (exp & 1) res = res * base % mod;
        base = base * base % mod;
        exp >>= 1;
    }
    return res;
}

// 快速幂
ll power(ll base, int exp) {
    ll res = 1;
    while (exp) {
        if (exp & 1) res *= base;
        base *= base;
        exp >>= 1;
    }
    return res;
}

// 求逆元
ll inv(ll a) {
    return power_mod(a, mod - 2);
}

#define MAXFAC 100010

ll fac[MAXFAC];

void initFac() {
    fac[0] = 1;
    for (int i = 1; i < MAXFAC; ++i) {
        fac[i] = i * fac[i - 1] % mod;
    }
}

ll Combine(ll a, ll b) {
    return (fac[a] * inv(fac[b]) % mod) * inv(fac[a - b]) % mod;
}

/******************************** template ********************************/
#define MAXN 200010
int n;
ll pre[MAXN];

int main() {
    cin >> n;
    for (int i = 0; i < n; ++i) {
        ll a;
        cin >> a;
        pre[i] = i ? pre[i - 1] + a : a;
    }

    ll res = LLONG_MAX;
    ll sum = pre[n - 1];
    for (int i = 0; i < n - 1; ++i) {
        res = min(res, llabs(sum - 2 * pre[i]));
    }
    cout << res;

    return 0;
}

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

typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pair<int, int> > vii;
#define rrep(i, m, n) for(int (i)=(m); (i)<(n);  (i)++)
#define  rep(i, n)    for(int (i)=0; (i)<(n);  (i)++)
#define  rev(i, n)    for(int (i)=(n)-1; (i)>=0; (i)--)
#define vrep(i, c)    for(__typeof((c).begin())i=(c).begin(); i!=(c).end(); i++)
#define  ALL(v)       (v).begin(), (v).end()
#define mp            make_pair
#define pb            push_back
template<class T1, class T2> inline void minup(T1& m, T2 x){ if(m>x) m=static_cast<T2>(x); }
template<class T1, class T2> inline void maxup(T1& m, T2 x){ if(m<x) m=static_cast<T2>(x); }

#define INF 1000000000
#define MOD 1000000009
#define EPS 1E-9

double a, b, c;
double d, e, f;

int main()
{
  while(cin >> a >> b >> c >> d >> e >> f){
    double x = (e*c-b*f) / (e*a-b*d);  if(abs(x) < EPS) x = 0.0;
    double y = (c*d-a*f) / (b*d-a*e);  if(abs(y) < EPS) y = 0.0;
    printf("%.3f %.3f\n", x, y);
  }

  return 0;
}

Measured memory_bytes: 1236
#include <iostream>
#include <vector>
#include <queue>
#include <sstream>
#include <algorithm>
#include <bitset>
#include <limits>
#include <map>
#include <set>
#include <iomanip>
#include <cmath>

using namespace std;

typedef long long int ll;
typedef std::numeric_limits<double> dbl;
const long long int LL_INF=1LL<<60;

vector<string> split(const string& input, char delimiter)
{
    stringstream stream(input);
    
    string field;
    vector<string> result;
    while (getline(stream, field, delimiter)) {
        result.push_back(field);
    }
    return result;
}

//#define DEBUG

ll A, B, M, N, D, K, Q, W, H, T, X, Y;

int main()
{
    cin >> N;

    int minimum = INT32_MAX;
    for (ll i = 1; i < (ll)sqrt(N)+100; ++i) {
        if (N % i == 0) {
            string s1(to_string(i)), s2(to_string(N / i));
            minimum = min(minimum, (int)max(s1.size(), s2.size()));
        }
    }

    cout << minimum << endl;

    return 0;
}

Measured memory_bytes: 256
n=int(input())
b=[int(i) for i in input().split()]
a=[b[0]]

if n==1:
    a.append(b[0])

else:
    for i in range(0,n-2):
        a.append(min(b[i],b[i+1]))
    a.append(b[n-2])

ans = 0
for j in a:
    ans += j
print(ans)    

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

int main(){
  int N;
  cin >>N;
  int A[N],B[N];
  for(int i=0;i<N;i++){
    cin >>A[i];
    B[i]=A[i];}

    sort(A,A+N);
  for(int i=0;i<N;i++){
    if(A[N-1]==B[i])
      cout<<A[N-2]<<endl;
    else
      cout<<A[N-1]<<endl;
    
    }
  return 0;
}


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

int h, w, k, ans = 0;
bool b[6][6];

int main() {
	cin >> h >> w >> k;
	for (int i = 0; i < h; ++i) {
		string s;
		cin >> s;
		for (int j = 0; j < w; ++j)
			if (s[j] == '#')
				b[i][j] = 1;
	}
	for (int bh = 0; bh < (1 << h); ++bh)
		for (int bw = 0; bw < (1 << w); ++bw) {
			int c = 0;
			for (int i = 0; i < h; ++i)
				for (int j = 0; j < w; ++j)
					if (b[i][j] && (bh & (1 << i)) && (bw & (1 << j)))
						++c;
			if (c == k)
				++ans;
		}
	cout << ans << endl;
}


Measured memory_bytes: 3632
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cstdlib>
#include<queue>

using namespace std;

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

int main(){
    int n, m;
    cin >> n >> m;
    priority_queue<P, vector<P>, greater<P> > que1;
    rep(i, n) {
        int a, b;
        cin >> a >> b;
        que1.push(P(a, b));
    }
    priority_queue<int> que2;
    int ans = 0;
    for (int i = 1; i <= m; i++){
        while(!que1.empty() && que1.top().first <= i){
            que2.push(que1.top().second);
            que1.pop();
        }
        if (!que2.empty()){
            ans += que2.top();
            que2.pop();    
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 1908
import java.util.Scanner;
 
class Main {
  static public void main(String args[]) {
    Scanner sc = new Scanner(System.in);
    long A = sc.nextLong();
    long B = sc.nextLong();
    long gcd = gcd(A, B);
    int counter = 1;
    for(int i = 2; i <= Math.sqrt(gcd); i++) {
      if(gcd % i == 0) {
        counter++;
      }
      while(gcd % i == 0) {
        gcd /= i;
      }
    }
    if (gcd > 1) {
      counter++;
    }
    System.out.println(counter);
    return;
  }
 
  private static long gcd(long m, long n) {
 
    if(n == 0) {
      return m;
    }
    return gcd(n, m % n);
  }
}

Measured memory_bytes: 23892
N = int(input())
A,B = [int(i) for i in input().split()]
P = [int(i) for i in input().split()]

res = [0 for i in range(3)]
for p in P:
    if p<=A:
        res[0]+=1
    elif p<=B:
        res[1]+=1
    else:
        res[2]+=1
print(min(res))


Measured memory_bytes: 3316
#include<bits/stdc++.h>
 #include <ext/pb_ds/tree_policy.hpp>
 #include <ext/pb_ds/assoc_container.hpp>
 #include<chrono>
 using namespace std;
 using namespace std::chrono;      
 using namespace __gnu_pbds; 
 #define fastio     ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
 #define fi         first
 #define se         second
 #define int         long long 
 #define pb         push_back
 #define emp        emplace_back
 #define vv(x)      vector<x>
 #define mp(x,y)    map<x,y>
 #define dq(x)      deque<x>
 #define pql(x)     priority_queue<x>
 #define pqs(x)     priority_queue<x,vv(x),greater<x> >
 #define M          1000000007
 #define forf(i,a,b) for(int i=a;i<b;i++)
 #define it(x)      x::iterator
 #define ll         long long 
 #define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
 #define time__(d)  for(long blockTime = 0; (blockTime == 0 ? (blockTime=clock()) != 0 : false); debug("%s time : %.4fs", d, (double)(clock() - blockTime) / CLOCKS_PER_SEC))
 #define vii        vector<int>
 #define big        3e18
 #define sm         -1e9
 #define mkr        make_pair
 #define vpi        vector<pair<int,int> >
 #define pii        pair<int,int>
 #define rng        500005
 #define sz(x)      (int)x.size()
 #define rv(x)      reverse(x.begin(),x.end())
 #define out(x)     cout<<x.fi<<" "<<x.se<<endl;

 typedef tree<pii, null_type, less<pii>, rb_tree_tag,  
            tree_order_statistics_node_update>  odst; 


void pr_init()
{
   
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
   
    #endif
}


#define PI 3.141592653589793238

void solve()
{

 int a,b,h,m; 
 cin >> a >> b >> h >> m;
 

 double th1 = (120*h+2*m)*(PI/60.0);
 double th2 = (PI/360.0)*(60*h+m);

 double m_x = b*cos(th1);
 double m_y = b*sin(th1);
 double h_x = a*cos(th2);
 double h_y = a*sin(th2);
 
 double dis = (h_x-m_x)*(h_x-m_x) + (m_y-h_y)*(m_y-h_y);
 dis = sqrt(dis);

 printf("%0.11f\n",dis); 
 
}

int32_t main()
{
 pr_init();
  fastio;
  
  auto start = high_resolution_clock::now(); 
 
  solve();
  auto stop = high_resolution_clock::now();
  auto duration = duration_cast<microseconds>(stop - start); 
  
    // cout << "Time taken by function: "
    //      << duration.count() << " microseconds" << endl; 

 }

Measured memory_bytes: 4072
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.StringTokenizer;



public class Main {

	public static void main(String[] args) {
		 FastScanner scanner =new FastScanner();
		 PrintWriter out=new PrintWriter(System.out);
		 int n=scanner.nextInt();
		char c[] = scanner.next().toCharArray();
		 int numr=0,numw=0;
		 ArrayList<Integer> aList=new ArrayList<>();
		 for(int i=0;i<n;i++) {
			 if(c[i]=='R') {
				 numr++;
				 aList.add(i);
			 }
			 else {
				 numw++;
			 }
		 }
		 //System.out.println(aList);
		 //System.out.println();
		 int res=Math.min(numr,	 numw);
		 int count=0;
		 for(int i=0;i<aList.size();i++) {
			 if(aList.get(i)>numr-1) break;
			 else count++;
		 }
		 res=Math.min(res, aList.size()-count);
		System.out.println(res);
	
		    	
		    }
	static class FastScanner {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st=new StringTokenizer("");
		String next() {
			while (!st.hasMoreTokens())
				try {
					st=new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			return st.nextToken();
		}
		
		int nextInt() {
			return Integer.parseInt(next());
		}
		int[] readArray(int n) {
			int[] a=new int[n];
			for (int i=0; i<n; i++) a[i]=nextInt();
			return a;
		}
		long nextLong() {
			return Long.parseLong(next());
		}
}

		    
		}

Measured memory_bytes: 42344
# coding: utf-8
import time
import re
import math
import fractions

def main():
    N,A,B=map(int,input().split())
    print(min(A*N,B))

start=time.time()
main()
#print("処理速度 {}sec".format(time.time()-start))
#A=list(map(int,input().split()))
#A,B,C=map(int,input().split())
#N=int(input())



Measured memory_bytes: 5556
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int N = Integer.parseInt(in.nextLine());
		in.close();
		int MAX = 55555;
		boolean[] isPrime = new boolean[MAX + 1];
		Arrays.fill(isPrime, true);
		isPrime[0] = false;
		isPrime[1] = false;
		primeDetection(isPrime);

		boolean[] valid = new boolean[MAX + 1];

		int count = 0;
		for (int i = 2; i < isPrime.length; ++i) {
			if (isPrime[i] && i % 5 == 1) {
				System.out.print(i + " ");
				count++;
			}
			if (count >= N) {
				break;
			}
		}
		System.out.println("");
	}

	private static void primeDetection(boolean[] isPrime) {
		for (int i = 2; i < isPrime.length; ++i) {
			if (!isPrime[i]) {
				continue;
			}
			for (int j = i * 2; j < isPrime.length; j = j + i) {
				isPrime[j] = false;
			}
		}
	}
}


Measured memory_bytes: 21076