akhauriyash/Code-Regression huggingface dataset:
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

struct Circle {
    x: f64,
    y: f64,
    radius: f64,
}

impl Circle {
    fn included(&self, x: f64, y: f64) -> bool {
        (self.x - x).hypot(self.y - y) <= self.radius + 0.00000001
    }
}

fn main() {
    let n = read::<usize>();
    let mut points = vec![];
    for i in 0..n {
        let v = read_vec::<f64>();
        points.push((v[0], v[1]));
    }

    let mut ans = 100000.0;
    for i in 0..n {
        for j in i + 1..n {
            let cx = (points[i].0 + points[j].0) / 2.0;
            let cy = (points[i].1 + points[j].1) / 2.0;
            let mut rad = 0.0;
            for &(px, py) in points.iter() {
                rad = max(Total(rad), Total((cx - px).hypot(cy - py))).0;
            }
            ans = min(Total(ans), Total(rad)).0;
        }
    }

    for i in 0..n {
        for j in i + 1..n {
            'k: for k in j + 1..n {
                let ex = (points[i].0 + points[j].0) / 2.0;
                let ey = (points[i].1 + points[j].1) / 2.0;
                let fx = (points[k].0 + points[j].0) / 2.0;
                let fy = (points[k].1 + points[j].1) / 2.0;
                let a = (points[j].1 - points[i].1).atan2(points[j].0 - points[i].0)
                    + std::f64::consts::PI * 0.5;
                let b = (points[k].1 - points[j].1).atan2(points[k].0 - points[j].0)
                    + std::f64::consts::PI * 0.5;
                let tana = a.tan();
                let tanb = b.tan();

                let cx = (ey - fy - ex * tana + fx * tanb) / (tanb - tana);
                let cy = ey - (ex - cx) * tana;
                let rad = (points[i].1 - cy).hypot(points[i].0 - cx);
                let circle = Circle {
                    x: cx,
                    y: cy,
                    radius: rad,
                };
                for &(px, py) in points.iter() {
                    if !circle.included(px, py) {
                        continue 'k;
                    }
                }
                ans = min(Total(ans), Total(rad)).0;
            }
        }
    }

    println!("{}", ans);
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

#[derive(PartialEq, PartialOrd)]
pub struct Total<T>(pub T);

impl<T: PartialEq> Eq for Total<T> {}

impl<T: PartialOrd> Ord for Total<T> {
    fn cmp(&self, other: &Total<T>) -> std::cmp::Ordering {
        self.0.partial_cmp(&other.0).unwrap()
    }
}


Measured memory_bytes: 4476
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int H,W,h,w;cin >> H >> W >> h >> w;
	if(H%h==0 && W%w==0) cout << "No" << endl;
	else if(h<=2 || w<=2){
		cout << "Yes" << endl;
		rep(i,H){
			rep(j,W){
				if((i+1)%h==0 && (j+1)%w==0){
					if(j!=0) cout << " " << -(h*w-1)*H*W;
					else cout << -(h*w-1)*H*W;
				}
				else{
					if(j!=0) cout << " " << H*W-1;
					else cout << H*W-1;
				}
			}
			cout << endl;
		}
	}
	else{
		cout << "Yes" << endl;
		rep(i,H){
			rep(j,W){
				if((i+1)%h==0 && (j+1)%w==0){
					if(j!=0) cout << " " << -h*w;
					else cout << -h*w;
				}
				else{
					if(j!=0) cout << " " << 1;
					else cout << 1;
				}
			}
			cout << endl;
		}
	}
}


Measured memory_bytes: 2048
from collections import Counter

n, m = map(int, input().split())
A = [int(i) for i in input().split()]

A[0] %= m
for i in range(n - 1):
    A[i + 1] += A[i]
    A[i + 1] %= m
    
C = Counter(A)
ans = 0

for k, v in C.items():
    if k == 0:
        ans += v
    if v >= 2:
        ans += v * (v - 1) // 2
        
print(ans)

Measured memory_bytes: 14636
[n,a,b,c,d] = [int(i)-1 for i in input().split()]
s = input()
if c < b:
    if "##" in s[a:c+1] or "##" in s[b:d+1]:
        print("No")
    else:
        print("Yes")
elif d < c :
    if "##" not in s[a:c+1]and "..." in s[b-1:d+2]:
        print("Yes")
    else:
        print("No")
else:
    if "##" not in s[b:d+1]:
        if "##" not in s[a:c+1]:
            print("Yes")
        else:
            print("No")
    else:
        print("No")


Measured memory_bytes: 40816
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<iomanip>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
#define LINF (long long)4e18

using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;




int main(){
    int N,K; cin >> N >> K;
    vector<int> V(N);
    rep(i,N) cin >> V[i];
    int ans = 0;
    for(int i = 0; i <= min(N,K); i++){
      for(int j = 0; i+j <= min(N,K); j++){
        vector<int> now;
        int sum = 0;
        rep(k,i){
          now.push_back(V[k]);
          sum += V[k];
        }
        rep(k,j){
          now.push_back(V[N-1-k]);
          sum += V[N-1-k];
        }
        sort(now.begin(),now.end());
        rep(k,min(K-i-j,(int)now.size())){
          if(now[k] < 0) sum -= now[k];
        }
        
        ans = max(ans,sum);
      }
    }
    cout << ans << endl;

}
 


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

using namespace std;

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

	vector<int> v(n - 1);
	for (int i = 0; i < n - 1; i++) {
		cin >> v[i];
	}

	long long sum = v[0];
	for (int i = 0; i < n - 2; i++) {
		if (v[i] < v[i + 1]) {
			sum += v[i];
		}
		else {
			sum += v[i + 1];
		}
	}
	cout << sum + v[n - 2] << endl;

	return 0;
}

Measured memory_bytes: 256
# coding: utf-8

w = int(raw_input())
n = int(raw_input())

yoko = []
for i in range(n):
	data = map(int, raw_input().split(","))
	yoko.append(data)

ans = []
for i in range(1,w+1):
	ans.append(0)

for num in range(1,w+1):
#	deb.printdebug1(num, debug)
	direction = num
	for c in yoko:
		if c[0] == direction:
#			deb.printdebug2(direction, debug)
#			deb.printdebug2(c[1], debug)
			direction = c[1]
		elif c[1] == direction:
#			deb.printdebug2(direction, debug)
#			deb.printdebug2(c[1], debug)
			direction = c[0]
	ans[direction-1] = num

for i in ans:
	print(i)

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

/* constant */

#define MAX_L	(10)
#define MAX_H	(32)

/* typedef */

typedef int nums_t[MAX_L];
typedef int hb_t[MAX_H];

typedef struct _hint_t {
  nums_t tri;
  int hi, bi;
} hint_t;

/* global variables */

static int h, l;
static int count;
static nums_t ans, used, ds;
static hint_t hints[MAX_H];

/* subroutines */

void print_hint(hint_t *htpt) {
  int i;
  for (i = 0; i < l; i++) printf("%d", htpt->tri[i]);
  printf(", hi=%d, bi=%d\n", htpt->hi, htpt->bi);
}

int count_rec(int k, hb_t hits, hb_t blows) {
  int d, i, j, skip;
  hb_t hits0, blows0;
  hint_t *htpt;

  if (k >= l) {
    for (i = 0, htpt = hints; i < h; i++, htpt++)
      if (htpt->hi != hits[i] || htpt->bi != blows[i]) return;

    count++;
    bcopy(ds, ans, sizeof(nums_t));
    return;
  }

  /*printf("k = %d\n", k);*/

  for (d = 0; d <= 9; d++) {
    if (used[d]) continue;

    skip = 0;
    bcopy(hits, hits0, sizeof(hb_t));
    bcopy(blows, blows0, sizeof(hb_t));

    for (i = 0, htpt = hints; i < h; i++, htpt++) {
      if (htpt->tri[k] == d) {
        hits0[i]++;
        if (hits0[i] > htpt->hi) {
          skip = 1;
          break;
	}
      }
      else {
	for (j = 0; j < l; j++)
	  if (htpt->tri[j] == d) break;
	if (j < l) {
	  blows0[i]++;
	  if (blows0[i] > htpt->bi) {
	    skip = 1;
	    break;
	  }
	}
      }
    }
    if (skip) continue;

    used[d] = 1;
    ds[k] = d;

    count_rec(k + 1, hits0, blows0);
    
    used[d] = 0;

    if (count > 1) return;
  }
}

/* main */

int main(int argc, char **argv) {
  int i, j, k;
  hb_t hits, blows;
  hint_t *htpt;
  char line[64];

  for (;;) {
    scanf("%d %d", &l, &h);
    if ((l | h) == 0) break;

    for (i = 0, htpt = hints; i < h; i++, htpt++) {
      scanf("%s", line);
      for (j = 0; j < l; j++)
	htpt->tri[j] = line[j] - '0';
      scanf("%d", &(htpt->hi));
      scanf("%d", &(htpt->bi));
      /*print_hint(htpt);*/
    }

    count = 0;
    bzero(used, sizeof(nums_t));
    bzero(hits, sizeof(hb_t));
    bzero(blows, sizeof(hb_t));

    count_rec(0, hits, blows);
    /*printf("count = %d\n", count);*/

    if (count != 1)
      puts("NO");
    else {
      for (i = 0; i < l; i++) printf("%d", ans[i]);
      putchar('\n');
    }
  }

  return 0;
}

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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = ((int)(n)-1); i >= 0; i--)
#define all(x) (x).begin(),(x).end()

using namespace std;
using ll = long long;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> P;
 
const int INF = 1e9;
//const ll INF = 1e18;
const double EPS = 1e-10;
const int MOD = 1e9+7;
const double PI = acos(-1.0);

int main()
{
	int a,b,x;
	cin >> a >> b >> x;
	cout << (a > x || a+b < x ? "NO" : "YES") << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <list>
#include <queue>
using namespace std;

int inf = (1 << 30);
int mod = 1e9 + 7;
int64_t inf64 = (1LL << 60);

template <typename T>
T gcd(T a, T b) {
    if(b == 0) return a;
    else return gcd(b, a % b);
}

template <typename T>
T lcm(T a, T b) {
    T g = gcd(a, b);
    return a / g * b;
}

bool check(vector<int> a, int index, int key){
    if(a[index] >= key) return true;
    else return false;
}

int lower_bound(vector<int> a, int key){
    int left = -1, right = a.size();
    while(right - left > 1){
        int mid = left + (left + right) / 2;
        if(check(a, mid, key)) right = mid;
        else left = mid;
    }
    return right;
}

int main(){

    int N;
    cin >> N;

    cout << (800 * N) - 200 * (N / 15) << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define ld long double
#define mk make_pair
#define fi first
#define se second
#define vll vector<ll>
#define pii pair<ll,ll>
#define vvll vector< vector<ll> >
#define pb push_back
#define sz(v) (v).size()
#define inf 1e18
#define md 1000000007
#define all(v) (v).begin(),(v).end()
#define rep(i,a,b) for(ll i=a;i<b;++i)
#define tel(a){cout<<a<<"\n";}
#define tell(a,b){cout<<a<<" | "<<b<<"\n";}
#define telll(a,b,c){cout<<a<<" | "<<b<<" | "<<c<<"\n";}
#define teln(v,n){cout<<"v- ";rep(i,0,n)cout<<v[i]<<" ";cout<<"\n";}
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define tihs if(fopen("inp.txt","r"))freopen("inp.txt", "r", stdin),freopen("out.txt", "w", stdout);
using namespace std;
#define TRACE
 
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif
 

#define M 410

ll dp[M][M];
ll n,a[M],p[M];
ll find(ll i,ll j){
	if(i==0) return p[j];
	return p[j]-p[i-1];
}
ll f(ll i,ll j){
	if(i>j) return inf;
	if(i==j) return 0;
	if(dp[i][j]!=-1) return dp[i][j];
	ll ans = inf, sum = find(i,j);
	rep(k,i,j) ans = min(ans,f(i,k)+f(k+1,j)+sum);
	return dp[i][j]=ans;
}
int main(){
	IOS;
	tihs;
	memset(dp,-1,sizeof(dp));
	cin>>n;
	rep(i,0,n)cin>>a[i];
	p[0]=a[0];
	rep(i,1,n)p[i]=p[i-1]+a[i];
	ll ans=f(0,n-1);
	cout<<ans;
	return 0;
}

Measured memory_bytes: 1664
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {

        Scanner scan =new Scanner(System.in);

        int N =scan.nextInt();

        Map<String,Integer> map=new HashMap<>();

      int i=0;


while(i<N){
   map.put(scan.next(),1);

    i=i+1;

}

System.out.println(map.size());


    }
}

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

int main(void) {
    /*
    double a, b, c;
    scanf("%lf%lf%lf", &a, &b, &c);
    */
    long long a, b, c;
    scanf("%lld%lld%lld", &a, &b, &c);
    if (a*a+b*b+c*c-2*a*b-2*b*c-2*c*a>0 && c>=a+b) printf("Yes");
    else printf("No");
}


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

const int N = 3e5;

int n;
int a[N],h[N],x[N],y[N],g[N];
int ans;

void upd(int x)
{
    int nx = h[x];
    if(!g[x]) nx++;
    if(x-n>=1) if(h[x-n]>nx) h[x-n] = nx,upd(x-n);
    if(x+n<=n*n) if(h[x+n]>nx) h[x+n] = nx,upd(x+n);
    if(x%n!=1) if(h[x-1]>nx) h[x-1] = nx,upd(x-1);
    if(x%n!=0) if(h[x+1]>nx) h[x+1] = nx,upd(x+1);
}

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

    cin >> n;
    for(int i = 1;i <= n;i++) for(int j = 1;j <= n;j++) x[(i-1)*n+j] = i,y[(i-1)*n+j] = j;
    for(int i = 1;i <= n*n;i++) cin >> a[i],h[i] = min(min(n-x[i],x[i]-1),min(n-y[i],y[i]-1));
    for(int i = 1;i <= n*n;i++)
    {
        int x = a[i];
        ans+=h[x];
        g[x] = true;
        upd(x);
    }
    cout << ans;
}


Measured memory_bytes: 23644
#include<bits/stdc++.h>
#define For(i,l,r) for(int i = (l),i##end = (r);i <= i##end;i++)
#define Fordown(i,r,l) for(int i = (r),i##end = (l);i >= i##end;i--)
#define debug(x) cout << #x << " = " << x << endl

using namespace std;

typedef long long ll;

template <typename T> inline bool chkmin(T &x,T y) { return y < x ? x = y,1 : 0; }
template <typename T> inline bool chkmax(T &x,T y) { return x < y ? x = y,1 : 0; }

const int INF = 0x3f3f3f3f;
const int N = 1e5 + 10;

int to[N << 1],nex[N << 1],beg[N],dis[N],deg[N],vis[N],f[N],cnt[N];
int ansl[N],ansr[N];
int e;

inline int read() {
	int x = 0,flag = 1;
	char ch = getchar();
	while(!isdigit(ch) && ch != '-')ch = getchar();
	if(ch == '-')flag = -1,ch = getchar();
	while(isdigit(ch))x = (x << 3) + (x << 1) + (ch - '0'),ch = getchar();
	return x * flag;
}

inline void add(int x,int y) {
	to[++e] = y,nex[e] = beg[x],beg[x] = e;
}

inline void dfs(int x,int fa) {
	f[x] = fa;
	for(int i = beg[x];i;i = nex[i]) {
		if(to[i] == fa) continue;
		dis[to[i]] = dis[x] + 1;
		dfs(to[i],x);
	}
}

int main() {
	int n = read();
	For(i,1,n - 1) {
		int x = read(),y = read();
		add(x,y),add(y,x);
		deg[x]++,deg[y]++;
	}
	dfs(1,0);
	int Max = 0,id = 1;
	For(i,1,n) if(chkmax(Max,dis[i])) id = i;
	dis[id] = f[id] = Max = 0,dfs(id,0);
	For(i,1,n) if(chkmax(Max,dis[i])) id = i;
	for(int pos = id;pos;pos = f[pos]) vis[pos] = true;
	bool flag = true;int cur = 0;
	for(int pos = id;pos;pos = f[pos]) {
		cur++;
		for(int j = beg[pos];j;j = nex[j]) {
			if(vis[to[j]]) continue;
			if(deg[to[j]] != 1) {
				flag = false;
				break;
			}
			cnt[cur]++;
		}
		if(!flag) break;
	}
	if(!flag) return puts("-1"),0;
	int Sum = 0;
	For(i,1,cur) {
		For(j,1,cnt[i]) ansl[Sum + j] = Sum + j + 1;
		ansl[Sum + cnt[i] + 1] = Sum + 1;
		Sum += cnt[i] + 1;
	}
	Sum = 0;
	Fordown(i,cur,1) {
		For(j,1,cnt[i]) ansr[Sum + j] = Sum + j + 1;
		ansr[Sum + cnt[i] + 1] = Sum + 1;
		Sum += cnt[i] + 1;
	}
	flag = false;
	For(i,1,n) {
		if(ansl[i] < ansr[i]) {
			flag = true;
			break;
		}
		if(ansl[i] > ansr[i]) break;
	}
	if(flag) For(i,1,n) printf("%d%c",ansl[i],i == iend ? '\n' : ' ');
	else For(i,1,n) printf("%d%c",ansr[i],i == iend ? '\n' : ' ');
	return 0;
}

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

long long dp[1005][1005];
char mat[1005][1005];

const long long mod = 1e9 + 7;


int main()
{
    int n,m;
    scanf("%d %d",&n,&m);
    for(int i = 1; i <= n; i++)
    {
        scanf("%s",mat[i] + 1);
    }

    dp[1][1] = 1;
    for(int i = 1; i <= n; i++)
    {
        for(int j = 1; j <= m ; j++)
        {
            if(mat[i][j] == '.')
            {
                dp[i][j] += ( dp[i-1][j] + dp[i][j-1]) % mod;
                dp[i][j] %= mod;
            }
        }
    }
    printf("%lld\n",dp[n][m]);
    return 0;
}

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

int main() {
    long long n;
    cin >> n;
    vector<long long> a(n);
    for (long long i = 0; i < n;i++)
        cin >> a.at(i);

    long long min_a = INT_MAX, max_a = -INT_MAX, sum_a = 0;
    for (long long i = 0; i < n;i++){
        min_a = min(min_a, a.at(i));
        max_a = max(max_a, a.at(i));
        sum_a += a.at(i);
    }

    cout << min_a << " " << max_a << " " << sum_a << endl;
}


Measured memory_bytes: 3172
import java.util.*;
class Main{
    static long n;
    static List<Long> list;
    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);
        list = new ArrayList<>();
        n = scanner.nextLong();
        dfs("3");
        dfs("5");
        dfs("7");
        int count = 0;
        for(int i = 0; i < list.size(); i++){
            String cur = String.valueOf(list.get(i));
            if(cur.contains("3") && cur.contains("5") && cur.contains("7")){
                count++;
            }
        }
        System.out.println(count);
    }
    public static void dfs(String s){
        if(Long.parseLong(s) <= n){
            list.add(Long.parseLong(s));
            String[] target = {"3", "5", "7"};
            for(int i = 0; i < target.length; i++){
                String newS = s + target[i];
                dfs(newS);
            }
        }
    }
}

Measured memory_bytes: 44152
/*
 * 2399.cc: Save Your Privacy!
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<bitset>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 100;

typedef long long ll;

const int INF = 1 << 30;
const ll LINF = 1LL << 60;

/* typedef */

typedef vector<int> vi;
typedef queue<int> qi;
typedef pair<int,int> pii;
typedef bitset<MAX_N> bsn;

/* global variables */

bsn ps[MAX_N];

/* subroutines */

/* main */

int main() {
  for (;;) {
    int n;
    cin >> n;
    if (n == 0) break;

    for (int i = 0; i < n; i++) ps[i].reset();

    for (int i = 0; i < n; i++) {
      int m;
      cin >> m;
      for (int j = 0; j < m; j++) {
	int pj;
	cin >> pj;
	pj--;
	ps[i].set(pj);
      }
      //printf("ps[%d]=", i); cout << ps[i].to_string() << endl;
    }

    bsn bls(0);
    int k;
    cin >> k;
    for (int i = 0; i < k; i++) {
      int li;
      cin >> li;
      li--;
      bls.set(li);
    }
    //cout << "bls=" << bls.to_string() << endl;

    int an = 0, ai = -1;
    
    for (int i = 0; i < n; i++)
      if ((bls & ps[i]) == bls) an++, ai = i;

    printf("%d\n", (an == 1) ? ai + 1 : -1);
  }

  return 0;
}

Measured memory_bytes: 1144
/*****Enigma_27*****/
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define mp          make_pair
#define pll         pair<ll,ll>
#define vll          vector<ll>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (int)x.size()
#define hell        1000000007
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define ios        	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
ll n,i,j,k,l,ans=0,m,flag=0;
string s[105];
map<char,ll> mm;
int main()
{   ios
    cin>>n>>m;
    for(i=0;i<n;i++) cin>>s[i];
    for(i=0;i<n;i++)
    {
        for(j=0;j<m;j++) mm[s[i][j]]++;
    }
    priority_queue<ll> pq;
    for(auto i:mm) pq.push(i.second);
    ll f=((m-m%2)*(n-n%2))/4;
    ll t=((m%2)*n)/2+((n%2)*m)/2;
    ll o=(m%2)*(n%2);
    while(!pq.empty())
    {
        ll k=pq.top();
        pq.pop();
        if(f&&k>=4) f--,k-=4;
        else if(t&&k>=2) t--,k-=2;
        else if(o)  o--,k--;
        else break;
        if(k) pq.push(k);
    }
    if(f||t||o) cout<<"No\n";
    else cout<<"Yes\n";
	return 0;
}


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

using namespace std;

int main(void)
{
	int n, a, b;
	cin >> n >> a >> b;
	a = a * n;
	if (a > b)
	{
		cout << b << endl;
	}
	else
	{
		cout << a << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#define all(v)              ((v).begin()), ((v).end())
#define allr(v)             ((v).rbegin()), ((v).rend())
#define MP                  make_pair
#define PI                  3.14159265359
#define SZ(v)				(int)v.size()
#define ull                 unsigned long long
#define ll                  long long
#define LD					long double
#define vi                  vector<int>
#define vl                  vector<ll>
#define vs                  vector<string>
#define vp                  vector<pair<int,int>>
#define OO                  (int)2e9
using namespace std;
const ll MOD = (int)1e9 + 7;
int dx[] = { 1,-1,0,0,1,-1,1,-1 };
int dy[] = { 0,0,-1,1,1,-1,-1,1 };
const int MAX = (int)1e5 + 10;
using namespace std;

/*void Ka8eeM()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	ios::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);
}*/
ll n, y;
int main()
{
	//Ka8eeM();
	cin >> n >> y;
	for (ll i = 0;i <= n;i++)
	{
		for (ll j = 0;j <= n;j++)
		{
			ll k = n - (i + j);
			if (k < 0)
				continue;
			if (i * 10000 + j * 5000 + k * 1000 == y)
			{
				cout << i << " " << j << " " << k << endl;
				return 0;
			}
		}
	}
	cout << "-1 -1 -1\n";
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <bits/stdc++.h>
#include <array>

#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;

using namespace std;

#define rad_to_deg(rad) (((rad)/2.0/M_PI)*360)
int main(int argc, const char * argv[]) {
    // source code
    long a, b ,x;
    cin >> a >> b >> x;
    if (x >= a * a * b / 2) {
        cout << setprecision(10) <<   rad_to_deg(atan(2.0 * (b * a * a -x ) / a / a / a)); 
    } else {
        cout << setprecision(10) <<  rad_to_deg(atan( b * b * a / 2.0 / x));
    }
    return 0;
}

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

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

    ll cnt=0;

    for(int i=0;i<3;i++){
        if(S[i]==T[i]){
            cnt++;
        }
    }
    cout << cnt << endl;

  return 0;
}

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

using namespace std;
//knapsack problem
long long max(long long a,long long b){
    return a>b?a:b;
}

const int Nmax = 100001;
vector< vector<long long> > knap_sack(Nmax);
void KnapSack(vector< pair<int,long long> > &table, int N){
    //initialize
    for(int i=0;i<Nmax;i++){
        knap_sack[i] = vector<long long>(N);
        for(int j=0;j<N;j++){
            
            if(i<table[j].first) knap_sack[i][j] = 0;
            else{
                knap_sack[i][j] = table[j].second + (j>0?knap_sack[i-table[j].first][j-1]:0);
            }
            if(j>0) knap_sack[i][j] = max(knap_sack[i][j],knap_sack[i][j-1]);
            
        }
    }
}

int main(){
    //driving code for knapsack
    int n,cos;cin>>n>>cos;
    vector< pair<int,long long> > table(n);
    for(int i=0;i<n;i++){
        cin >> table[i].first >> table[i].second;
    }
    KnapSack(table,n);
        cout << knap_sack[cos][n-1] << endl;
        return 0;
        }

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

// 整数xが回文数かを判定する
bool isKaibun(int x) {
  string s = to_string(x);
  int len = s.size();
  for (int i = 0; i < len; i++) {
    if (s[i] != s[len - 1 - i]) {
      return false;
    }
  }
  return true;
}

int main() {
  int A, B, num = 0;
  cin >> A >> B;
  // ここにプログラムを追記
  for (int i = A; i <= B; i++) {
    if (isKaibun(i)) {
      num++;
    }
  }

  cout << num << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <cmath>
#include <utility>
#include <map>
#include <unordered_map>
#define rep(i,n) for(int i=0;i<n;++i)
using namespace std;
typedef long long int ll;

int main() {
  string S;
  cin>>S;
  
  int N=S.size();
  
  string T=S;
  reverse(T.begin(),T.end());
  string X=S.substr(0,(N-1)/2);
  string Y=X;
  reverse(Y.begin(),Y.end());
  
  string A=S.substr((N+1)/2,(N-1)/2);
  string B=A;
  reverse(B.begin(),B.end());
  
  if(S==T && X==Y && A==B)
    cout<<"Yes"<<endl;
  else
    cout<<"No"<<endl;
  
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <cmath>

using namespace std;
#define REP(i,n) for(int i = 0; i < (int)(n); i++)
#define IREP(i, n) for(int i = (int)(n) - 1; i >= 0; i--)
#define MOD (1000 * 1000 * 1000 + 7)

typedef long long ll;

typedef pair<int, int> pint;

int main() {
    int n;
    cin >> n;
    int sum = 0;
    int v[n];
    REP(i, n) cin >> v[i];
    int c[n];
    REP(i, n) cin >> c[i];
    REP(i, n) if(v[i] > c[i]) sum += v[i] - c[i];
    cout << sum;
    return 0;
}


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

int main() {
	int n;
	cin >> n;
	cout << n * n * n << endl;
}


Measured memory_bytes: 256
from collections import Counter

N = int(input())
a = list(map(int,input().split()))
da = Counter(a)


if 0 in da and da[0]==N:
  print('Yes')
elif N%3!=0:
  print('No')
elif len(da)==2 and 0 in da and da[0]==N/3:
  print('Yes')
elif len(da)==3:
  x, y, z = da.keys()
  if (x^y==z) and da[x]==N/3 and da[y]==N/3:
    print('Yes')
  else:
    print('No')
else:
  print('No')

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

using namespace std;

#define REP(i,n) for(ll (i) = 0;(i) < (n);i++)
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define ALL(v) b.begin(),v.end()
#define SHOW1d(v, n) {REP(WW,n)cerr<<v[WW]<<" ";cerr<<endl;}
#define SHOW2d(v,WW,HH) {REP(W_,WW){REP(H_,HH)cerr<<v[W_][H_]<<" ";cerr<<endl;}cerr<<endl;}
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 1000000007

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

ll dp[222222];
ll mp[222222];
char c[222222];
vector<vector<ll>> v(4444444);

void mod_add(ll &a, ll b){
  a += b;
  //a %= MOD;
}

void v_push(ll i, ll a){
  v[i+222222].PB(a);
}

void v_pop(int i){
  v[i+222222].pop_back();
}

ll v_get(int i){
  return v[i+222222].back();
}

ll v_size(int i){
  return v[i+222222].size();
}

ll cal_func(int pla, int high){
  //cout << "cal_func " << pla << " " << high << endl;
  if(v_size(high) == 0)return dp[pla] = 0;
  ll ret = 1;
  ll tmp = v_get(high);
  //cout << "cal_func " << tmp << endl;
  if(tmp > 0 && c[tmp - 1] == ')')mod_add(ret, dp[tmp-1]);
  return dp[pla] = ret;
}

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

  string str;cin >> str;
  ll now_high = 0;
  ll length = 0;
  ll ans = 0;
  REP(i, str.size()){
    if(str[i] == '('){
      v_push(now_high, length);
      c[length] = '(';
      now_high++;

      length++;
    }
    else if(str[i] == ')'){
      now_high--;
      c[length] = ')';
      mod_add(ans, cal_func(length, now_high));

      length++;
    }
    else {
      length--;
      if(c[length] == ')'){
        now_high++;
        mod_add(ans, -dp[length]);
      }
      else{
        now_high--;
        v_pop(now_high);
      }
      c[length] = ' ';
      dp[length] = 0;
    }

    cout << ans << "\n";
    //SHOW1d(dp, 10);
    //SHOW1d(c, 20);
  }

  return 0;
}



Measured memory_bytes: 113816
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
typedef unsigned long long int ulli;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int,int> pii;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define YN(x) cout<<(bool x?"Yes":"No")<<endl;
#define out(s) cout<<s<<endl;
#define pb push_back;
#define sp " ";
void vout(vector<int> v){
    for(int i=0;i<v.size();i++)
    cout<<v.at(i)<<endl;
}
int main(){
    string num;
    int ans=0;
    cin>>num;
    reverse(num.begin(),num.end());
    vi sum(2020,0);
    lli t=1,tot=0;
    rep(i,num.size()){
        sum.at(tot)++;
        int y=num.at(i)-'0';
        t%=2019;
        y*=t;
        tot+=y%2019;
        tot%=2019;
        ans+=sum.at(tot);
        t*=10;
    }
    cout<<ans;
}

Measured memory_bytes: 3724
#include <iostream>

using namespace std;

int n, k, p;

int main() {
	cin >> n >> k;
  	int P[n];
  	long long sum = 0;
  	for (int i = 0;  i < n; i++) {
    	cin >> p;
      	P[i] = p;
      	if (i < k) sum += p;
    }
  	//cout << sum << endl;
  	int l = 0;
  	int r = k;
  	long long maxSum = sum;
  	for (int i = 0; i < n-k; i++) {
    	sum = sum-P[i]+P[i+k];
      	if (sum > maxSum) {
        	maxSum = sum;
          	l = i+1;
          	r = i+k+1;
        }
    }
  	// cout << maxSum << " " << l << " " << r << endl;
  	long double ans = 0;
  	for (int i = l; i < r; i++) {
    	if (P[i] % 2 == 1) {
    		ans += P[i] / 2 + 1;
    	} else {
        	ans += P[i] / 2 + 0.5;
        }
    }
	printf("%.9Lf", ans);
	return 0;
}




Measured memory_bytes: 3980
#include <stdio.h>

int main(){

 char X[3];

    scanf("%s",&X);

    if(X[0]=='7'){


        printf("Yes\n");

    }
    
    else if(X[1]=='7'){


        printf("Yes\n");

    }
    else if(X[2]=='7'){


        printf("Yes\n");

    }
    
    else{

       printf("No\n");

    }



return 0;

}



Measured memory_bytes: 1632
input()
ls = []
from numpy import cumsum
for i in input():
    if i == 'W':
        ls.append(1)
    else:
        ls.append(0)
a = cumsum(ls)
ans = (len(a)-1)-(a[-1]-a[0])
for i in range(1,len(a)):
    ans = min(ans,(len(a)-(i+1))-(a[-1]-a[i])+a[i-1])
print(ans)

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

int main(){
	int n;
	long min = 100000000;
	long max = -100000000;
	long long sum=0;
	long x;

	cin >> n;
	for(int i=0; i<n; i++){
		cin >> x;
		if(max < x) max = x;
		if(min > x) min = x;
		sum += x;
	}

	cout << min << " " << max << " " << sum << endl;

	return 0;
}

Measured memory_bytes: 3112
#include<bits/stdc++.h>
using namespace std;
#define REP(i,st,ed) for(register int i=st,i##end=ed;i<=i##end;++i)
#define DREP(i,st,ed) for(register int i=st,i##end=ed;i>=i##end;--i)
typedef long long ll;
template<typename T>inline bool chkmin(T &x,T y){return (y<x)?(x=y,1):0;}
template<typename T>inline bool chkmax(T &x,T y){return (y>x)?(x=y,1):0;}
inline int read(){
	int x;
	char c;
	int f=1;
	while((c=getchar())!='-' && (c>'9' || c<'0'));
	if(c=='-') f=-1,c=getchar();
	x=c^'0';
	while((c=getchar())>='0' && c<='9') x=(x<<1)+(x<<3)+(c^'0');
	return x*f;
}
inline ll readll(){
	ll x;
	char c;
	int f=1;
	while((c=getchar())!='-' && (c>'9' || c<'0'));
	if(c=='-') f=-1,c=getchar();
	x=c^'0';
	while((c=getchar())>='0' && c<='9') x=(x<<1ll)+(x<<3ll)+(c^'0');
	return x*f;
}
const int maxn=2e5+10,inf=0x3f3f3f3f;
int Begin[maxn],Next[maxn<<1],to[maxn<<1],e;
inline void add_edge(int x,int y){
	to[++e]=y;
	Next[e]=Begin[x];
	Begin[x]=e;
}
int Md[maxn],g[maxn],Md1[maxn],g1[maxn];
int sz[maxn],Up[maxn],Down[maxn];
char s[maxn];
void dfs1(int x,int ff){
	Md1[x]=inf,sz[x]=(s[x]=='1');
	for(int i=Begin[x];i;i=Next[i]) if(to[i]!=ff){
		dfs1(to[i],x),sz[x]+=sz[to[i]];
		chkmax(Md[x],Md[to[i]]+1);
		if(sz[to[i]]) chkmin(Md1[x],Md[to[i]]+1);
	}
	if(s[x]=='1') chkmin(Md1[x],Md[x]);
}
void dfs2(int x,int ff){
	int Max=0,Sec=0;
	Up[x]=max(g[x],Md[x])-1;
	Down[x]=min(Md1[x],sz[x]==sz[1]?inf:g[x]);
	if(s[x]=='1') Down[x]=0;
	chkmin(Up[x],Md[x]+1);
	for(int i=Begin[x];i;i=Next[i]) if(to[i]!=ff){
		if(Md[to[i]]+1>Max) Sec=Max,Max=Md[to[i]]+1;
		else chkmax(Sec,Md[to[i]]+1);
	}
	for(int i=Begin[x];i;i=Next[i]) if(to[i]!=ff){
		g[to[i]]=g[x];
		if(Md[to[i]]+1==Max) chkmax(g[to[i]],Sec);
		else chkmax(g[to[i]],Max);
		++g[to[i]];
		chkmin(Up[x],g[to[i]]);
	}
	for(int i=Begin[x];i;i=Next[i]) if(to[i]!=ff) dfs2(to[i],x);
}
int main(){
	int n=read();
	REP(i,1,n-1){
		int x=read(),y=read();
		add_edge(x,y),add_edge(y,x);
	}
	scanf("%s",s+1);
	ll ans=0;
	REP(i,1,n) ans|=(s[i]=='1');
	dfs1(1,0),g1[1]=inf;
	dfs2(1,0);
	REP(i,1,n) if(Down[i]<=Up[i]) ans+=Up[i]-Down[i]+1;
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 16896
import java.util.*;

class Main{
	
	public static void main(String args[]){

		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();

		long arr[] = new long[N];
		long p[] = new long[N];
		HashMap<Long,Integer> mods = new HashMap<>();

		for(int n=0;n<N;n++){
			arr[n] = sc.nextLong();
			if(n==0) p[n] = arr[n];
			else p[n] = p[n-1] + arr[n];
		}


		long ans = 0;

		mods.put((long)0,1);

		for(int n=0;n<N;n++){

			if(mods.containsKey(p[n]%M)){
				mods.put(p[n]%M,mods.get(p[n]%M)+1);
			}
			else
				mods.put(p[n]%M,1);
		}

		for(Long key : mods.keySet()){
			long v = mods.get(key);
			ans += v*(v-1)/2;
		}

		System.out.println(ans);
	}
}

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


#define fast_IO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl '\n'
typedef long long int lli;
typedef long long ll;
typedef long double ld;


signed main(){
    fast_IO;
    int t=1;
    //cin>>t;
    while(t--){
        int x,n;
        cin>>x>>n;
        int a[n];
        vector<int> unused;
        for(int i=0;i<n;i++){
            cin>>a[i];
        }
        for(int i=-100;i<201;i++){
            int f=0;
            for(int j=0;j<n;j++){
                if(i==a[j]){
                    f=1;
                    break;
                }
            }
            if(!f)
                unused.push_back(i);
        }
        int mini=1000;
        int p=-1;
        for(auto i: unused){
            if(abs(i-x)<mini){
                mini=abs(i-x);
                p=i;
            }
        }
        cout<<p<<endl;
    }   
    return 0;
}


Measured memory_bytes: 3576
function Main(input) {
  // 入力解析
  input = input.split("\n").map((v) => v.split(" "));
  // 使うのこれだけだから input に代入
  input = input[0][0];
  // 結果
  console.log(input.slice(-1) === "s" ? `${input}es` : `${input}s`);
}
// 魔法の呪文
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 29648
def hoge(a)
    res = []
    i = 1
    while i * i <= a
        if a % i == 0
            res.push(i)
            if i * i != a
                res.push(a / i)
            end
        end
        i += 1
    end
    res.sort!
    return res
end

a, b, k = gets.split.map(&:to_i)
v = hoge(a)
vv = hoge(b)
vvv = v & vv
p vvv[-k]



Measured memory_bytes: 1788
n,m=map(int,input().split())

def factorize(n):
    fct=[]
    b,e=2,0
    while b*b<=n:
        while n%b==0:
            n=n//b
            e=e+1
        if e>0:
            fct.append((b,e))
        b,e=b+1,0
    if n>1:
        fct.append((n,1))
    return fct

l=factorize(m)
mod=10**9+7
ans=1

def inv(x):
    return pow(x, mod - 2, mod)
 
cms = 10**5 + 100
cm = [0] * cms
 
def comb_init():
    cm[0] = 1
    for i in range(1, cms):
        cm[i] = cm[i-1] * i % mod
 
def c(a, b):
    return (cm[a] * inv(cm[a-b]) % mod) * inv(cm[b]) % mod

mod=10**9+7
comb_init()

for i,j in l:
    ans*=c(j+n-1,j)
    ans=ans%mod

print(ans)

Measured memory_bytes: 6900
import sys

sys.setrecursionlimit(10000000)
input=sys.stdin.readline

n = int(input())
a = list(map(int,input().split()))

def gcd(a, b):
    return a if b == 0 else gcd(b, a%b)

def lcm(a, b):
    return a // gcd(a, b) * b

mod = 10**9+7

x=a[0]

for i in a[1:]:
    x=lcm(x,i)
ans=0
for i in range(n):
    ans+= x//a[i]

print(ans%mod)


Measured memory_bytes: 4084
#include <iostream>
using namespace std;
int main(){
    int N,M;
    cin >>N >>M;
    int city[50]={};
    for(int i=0; i < M; i++){
        int a,b;
        cin>>a>>b;
        city[a-1]++;
        city[b-1]++;
    }
    for(int i=0; i < N; i++){
        cout<<city[i]<<endl;
    }
    
}

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

int main(int argc, char const *argv[])
{
	int a,b;
	cin >> a >> b;
	if(a*b%2==0){
		cout << "Even" << endl;
	}else{
		cout << "Odd" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstring>
using namespace std;
#define MAXN 1100
int n,w;
long long ans=0;
long long v[MAXN];
long long val[MAXN];
long long f[10000000];
int main()
{
	cin>>n>>w;
    memset(f,0x3f,sizeof f);
    for(int i=1;i<=n;i++) cin>>v[i]>>val[i];
    f[0]=0;
    for(int i=1;i<=n;i++)
    {
        for(int j=100000;j>=val[i];j--)
        {
        	f[j]=min(f[j],f[j-val[i]]+v[i]);
        }
    }
    for(long long i=1;i<=100000;i++)
    {
    	if(f[i]<=w) ans=max(ans,i);
    }
    cout<<ans;
	return 0;
}

Measured memory_bytes: 78336
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using pint = pair<int,int>;
ll mod = 1000000007,mod2 = 998244353;

void chmin(long long &a, long long b) { if (a > b) a = b; }
void chmax(long long &a, long long b) { if (a < b) a = b; }
const long long INF = 1LL<<60;
int gcd(int a,int b){
    if(b == 0) return a;
    else return gcd(b,a%b);
}

//重みある時
using Edge = pair<int,int>;
using Graph = vector<vector<Edge> >;

int main() {
    int n;
    cin >> n;
    vector<int> t(n),x(n),y(n);
    for (int i = 0; i < n; ++i) {
        cin >> t[i] >> x[i] >> y[i];
    }

    if(n == 1){
        if(t[0] >= (x[0]+y[0])){
            cout << "Yes" << endl;
            return 0;
        }else{
            cout << "No" << endl;
            return 0;
        }
    }

    bool ok = 1;
    for (int i = 0; i < n-1; ++i) {
        if(((t[i+1]-t[i]) %2 != abs(x[i+1]+y[i+1]-x[i]-y[i]) %2) || ((t[i+1]-t[i]) < abs(x[i+1]+y[i+1]-x[i]-y[i])))ok = 0;
    }
    if(ok) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 1408
//! ----------------------------------------------
//! Framework <https://github.com/vain0x/procon>
//!
//! See the bottom of file for solution.
//! ----------------------------------------------

#![allow(unused_imports)]
#![allow(non_snake_case)]

use std::cell::RefCell;
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::fmt::{Debug, Display, Formatter, Write as FmtWrite};
use std::io::{stderr, stdin, BufRead, Write};
use std::mem::{replace, swap};
use std::ops::*;
use std::rc::Rc;

/// Print values to standard error if debug mode.
#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), stderr());
            writeln!(err, "\x1B[33m{}\x1B[0m = {:?}", e, $e).unwrap()
        })*
    };
}

/// Read from standard input and parse each word.
/// - `read!(T, U, ..)` parses a line as a tuple of words.
/// - `read![[T]]` parses a line as an array of words.
/// - `read![..; N]` parses `N` lines, using `read!(..)` repeatedly.
#[allow(unused_macros)]
macro_rules! read {
    ([$t:ty] ; $n:expr) =>
        ((0..$n).map(|_| read!([$t])).collect::<Vec<_>>());
    ($($t:ty),+ ; $n:expr) =>
        ((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>());
    ([$t:ty]) =>
        (rl().split_whitespace().map(|w| w.parse().unwrap()).collect::<Vec<$t>>());
    ($($t:ty),*) => {{
        let buf = rl();
        let mut w = buf.split_whitespace();
        ($(w.next().unwrap().parse::<$t>().unwrap()),*)
    }};
}

/// Read a line from standard input.
#[allow(dead_code)]
fn rl() -> String {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();

    #[allow(deprecated)]
    buf.trim_right().to_owned()
}

// -----------------------------------------------
// Solution
// -----------------------------------------------

fn main() {
    let N = read!(usize);
    let A = read![i64; N];

    let mut B = A.clone();
    B.sort();

    for i in 0..N {
        let m = if A[i] == B[N - 1] { B[N - 2] } else { B[N - 1] };
        println!("{}", m)
    }
}


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

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

int N;
int A[202000], B[202000];
ll dp[4040][4040];
ll yes[4040][4040];
ll mo=1000000007;
ll ret=0;

ll combi(ll N_, ll C_) {
	const int NUM_=400001;
	static ll fact[NUM_+1],factr[NUM_+1],inv[NUM_+1];
	if (fact[0]==0) {
		inv[1]=fact[0]=factr[0]=1;
		for (int i=2;i<=NUM_;++i) inv[i] = inv[mo % i] * (mo - mo / i) % mo;
		for (int i=1;i<=NUM_;++i) fact[i]=fact[i-1]*i%mo, factr[i]=factr[i-1]*inv[i]%mo;
	}
	if(C_<0 || C_>N_) return 0;
	return factr[C_]*fact[N_]%mo*factr[N_-C_]%mo;
}
ll hcomb(int P_,int Q_) { return (P_==0&&Q_==0)?1:combi(P_+Q_-1,Q_);}

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N;
	FOR(i,N) {
		cin>>A[i]>>B[i];
		dp[2010-A[i]][2010-B[i]]++;
		yes[2010+A[i]][2010+B[i]]++;
	}
	FOR(x,4020) FOR(y,4020) {
		if(yes[x][y]) (ret += yes[x][y]*dp[x][y])%=mo;
		dp[x+1][y] += dp[x][y];
		if(dp[x+1][y]>=mo) dp[x+1][y]-=mo;
		dp[x][y+1] += dp[x][y];
		if(dp[x][y+1]>=mo) dp[x][y+1]-=mo;
	}
	
	FOR(i,N) {
		ret -= combi(2*(A[i]+B[i]),2*A[i]);
		if(ret<0) ret+=mo;
	}
	cout<<ret*((mo+1)/2)%mo<<endl;
	
}


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


Measured memory_bytes: 176768
import sys
sys.setrecursionlimit(10 ** 9)

N, M, K = map(int, input().split())

Friend = [[] for i in range(N)]
for _ in range(M):
  A, B = map(int, input().split())
  Friend[A-1].append(B-1)
  Friend[B-1].append(A-1)

Block = [set() for i in range(N)]
for _ in range(K):
  C, D = map(int, input().split())
  Block[C-1].add(D-1)
  Block[D-1].add(C-1)


def dfs(x):
    if seen[x] == 0:
        R[cnt].add(x)
        seen[x]=1
        for i in Friend[x]:
            dfs(i)

seen = [0]*N
cnt  = 0
R    = []
for i in range(N):
    if seen[i] == 0:
        R.append(set())
        dfs(i)
        cnt += 1

seq = [0]*N

for r in R:
    lr = len(r)
    for j in r:
        seq[j] = lr - len(Friend[j]) - len(r&Block[j]) - 1

print(*seq)

Measured memory_bytes: 83704
#include <bits/stdc++.h>
#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define ALL(v) v.begin(), v.end()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define INTXT std::ifstream in ("input.txt"); std::cin.rdbuf(in.rdbuf());
#define INF 1e9

using namespace std;
typedef long long ll;
static const ll MOD = 1000000007LL;

int gcd(unsigned a, unsigned b) {
  while(1) {
    if(a < b) swap(a, b);
    if(!b) break;
    a %= b;
  }
  return a;
}

signed main() {
  IOS
  int n;
  cin >> n;

  vector<int> nums(n);
  REP(i, n){
    cin >> nums.at(i);
  }
  
  vector<int> gcd_frm_top(n);
  gcd_frm_top.at(0) = nums.at(0);
  REPS(i, n - 1){
    // cout << gcd_frm_top.at(i - 1) << " " << nums.at(i) << endl;
    gcd_frm_top.at(i) = gcd(gcd_frm_top.at(i - 1), nums.at(i));
  }

  vector<int> gcd_frm_end(n);
  gcd_frm_end.at(n - 1) = nums.at(n - 1);
  RREP(i, n - 1){
    gcd_frm_end.at(i) = gcd(gcd_frm_end.at(i + 1), nums.at(i));
  }

  // REP(i, n){
  //   cout << i << " " << gcd_frm_top.at(i) << " " << gcd_frm_end.at(i) << endl;
  // }

  int ans = max(gcd_frm_end.at(1), gcd_frm_top.at(n - 2));
  for(int i = 0; i < n - 2; i++){
    // cout << gcd(gcd_frm_end.at(i + 2), gcd_frm_top.at(i)) << endl;
    ans = max(ans, gcd(gcd_frm_end.at(i + 2), gcd_frm_top.at(i)));
  }
  cout << ans << endl;

}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> l_l;
const int INF=1001001000;
const int mINF=-1001001000;
const ll LINF=1010010010010010000;
int main(){
    int n,m;cin >> n >> m;
    vector<ll> x(n),y(n),z(n);
    for(int i=0;i<n;i++) cin >> x[i] >> y[i] >> z[i];
    ll mx=-LINF;
    for(int bit=0;bit<(1<<3);bit++){
        vector<ll> xx=x;
        vector<ll> yy=y;
        vector<ll> zz=z;
        for(int i=0;i<3;i++){
            if((bit>>0)&1){
                for(int i=0;i<n;i++){
                    xx[i]=-x[i];
                }
            }
            if((bit>>1)&1){
                for(int i=0;i<n;i++){
                    yy[i]=-y[i];
                }
            }
            if((bit>>2)&1){
                for(int i=0;i<n;i++){
                    zz[i]=-z[i];
                }
            }
        }
        vector<ll> xyz(n);
        for(int i=0;i<n;i++) xyz[i]=xx[i]+yy[i]+zz[i];
        sort(xyz.rbegin(),xyz.rend());
        ll sum=0;
        for(int i=0;i<m;i++){
            sum+=xyz[i];
        }
        mx=max(mx,sum);
        //cout << sum << endl;
    }
    cout << mx << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

typedef struct {
	double x;
	double y;
} POINT;

int contains(POINT *p0, POINT *p1, POINT *p2, POINT *q);

int main()
{
	POINT p0, p1, p2, q;
	while (scanf("%lf %lf %lf %lf %lf %lf %lf %lf",
				&p0.x, &p0.y, &p1.x, &p1.y, &p2.x, &p2.y, &q.x, &q.y) != -1) {
		if (contains(&p0, &p1, &p2, &q)) {
			printf("YES\n");
		} else {
			printf("NO\n");
		}
	}
	return 0;
}

int contains(POINT *p0, POINT *p1, POINT *p2, POINT *q)
{
	double x1, y1, x2, y2, xq, yq;
	double s, t;
	x1 = p1->x - p0->x;
	y1 = p1->y - p0->y;
	x2 = p2->x - p0->x;
	y2 = p2->y - p0->y;
	xq = q->x - p0->x;
	yq = q->y - p0->y;

	s = (y2 * xq - x2 * yq) / (x1 * y2 - x2 * y1);
	t = (-y1 * xq + x1 * yq) / (x1 * y2 - x2 * y1);

	return s >= 0.0 && t >= 0.0 && s + t < 1.0;

}

Measured memory_bytes: 612
# include <bits/stdc++.h>
# define sz(x) (int)((x).size())
# define F first
# define S second
# define pb push_back
# define ub upper_bound
# define lb lower_bound
# define all(x) x.begin(), x.end()
# define pqueue priority_queue
# define mset multiset
# define umap unordered_map
# define Speed() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
# define rep(i,n) for(int i=0;i<n;++i)
# define forn(i,n) for(int i=1;i<=n;++i)
# define lr(i,l,r) for(int i=l;(l>r?i>=r:i<=r);(l>r?--i:++i))

using namespace std;

template<class T> void umin(T &a, T b) { a = min(a, b); }
template<class T> void umax(T &a, T b) { a = max(a, b); }

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

const int mod = 1e9+7;
const int N = 1e5+5;
int n,a[N],pref[N],suf[N];
void solve(){
	cin>>n;
	forn(i,n)cin>>a[i];
	int g=0;
	forn(i,n){
		g=__gcd(a[i],g);
		pref[i]=g;
	}
	g=0;
	for(int i=n;i>=1;--i){
		g=__gcd(g,a[i]);
		suf[i]=g;
	}
	int ans=0;
	forn(i,n){
		umax(ans,__gcd(pref[i-1],suf[i+1]));
	}
	cout<<ans;


}

int main(){
	Speed();
	int T=1; 
	//cin>>T;	
	while(T--)
		solve();
	return 0;
}

Measured memory_bytes: 4716