akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
using namespace std;
bool search(int a[],int n,int len){
	int first=0;
	int last=len-1;
	int center=(first+last)/2;
	bool check=false;
	while(1){
//		cout<<"check="<<check<<" "<<endl;
//			cout<<n<<" "<<first<<" "<<center<<" "<<last<<" "<<a[first]<<" "<<a[center]<<" "<<a[last]<<endl;
		if(a[first]==n||a[last]==n||a[center]==n){
			check=true;
			break;
		}
		else if(first>last){
			break;
		}
		else if(n>a[center]){
			first=center+1;
			center=(first+last)/2;
		}
		else if(n<a[center]){
			last=center-1;
			center=(first+last)/2;
		}
	}
//	cout<<"check="<<check<<" "<<endl;
	return check;
}
int main(void){
	cin.tie(0);ios::sync_with_stdio(false);
	int i,n,q,ans=0;
	cin>>n;
	int s[n];
	for(i=0;i<n;i++)cin>>s[i];
	cin>>q;
	int t[q];
	for(i=0;i<q;i++)cin>>t[i];
	sort(s,s+n);
	sort(t,t+q);
	for(i=0;i<q;i++){
		if(search(s,t[i],n))ans++;
	}
	cout<<ans<<endl;
	
	return 0;
}


Measured memory_bytes: 3768
import math
a,b,c = map(int,input().split())

s = a*b*math.sin(math.radians(c))*0.5

line = a**2 + b**2 - 2*a*b*math.cos(math.radians(c))
l = a + b + math.sqrt(line)

h = (2*s)/a

print(s)
print(l)
print(h)


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

int main()
{
	int n,k,h[100000];
	cin>>n>>k;
	for(int i=0;i<n;i++) cin>>h[i];
	
	sort(h,h+n);
	int minv=1000000000;
	for(int i=0;i+k<=n;i++) minv=min(minv,h[i+k-1]-h[i]);
	
	cout<<minv<<endl;
	return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main(){
  map<string,int> p;
  int n;
  cin>>n;
  for(int i=0;i<n;i++){
    string s;
    cin>>s;
    p[s]++;
  }
  int m;
  cin>>m;
  for(int i=0;i<m;i++){
    string t;
    cin>>t;
    p[t]--;
  }
  int a=0;
  for(auto x:p)
    a=max(a,x.second);
  cout<<a<<endl;
}

Measured memory_bytes: 3612
#include <iostream>
using namespace std;
int main(void){
    long long n;
    double ans = 0, rate = 380000;
    cin >> n;
    for(int i=0;i<n;i++){
        double x;
        string u;
        cin >> x >> u;
        if(u == "JPY") ans += x;
        else ans += (x*rate);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
/*
 ╔═══╦═══╦═══╗
 ║╔═╗║╔══╩╗╔╗║
 ║║░║║╚══╗║║║║
 ║║░║║╔══╝║║║║
 ║╚═╝║╚══╦╝╚╝║
 ╚══╗╠═══╩═══╝
 ░░░╚╝░░░░░░░░
 */

#include <bits/stdc++.h>
#define ll					long long
#define debug(x)			{ cerr << #x << " = " << x << endl; }
#define MOD					1000000007
#define MAX					1e9
#define MIN                 -1e9
#define vi					vector<int>
#define vii					vector<vi>
#define max(x,y)			(x>y)?x:y
#define mid(s,e)			(s+(e-s)/2)

using namespace std;

int main() {
	ios::sync_with_stdio(false);
 	cin.tie(0);
	int n,a,b;
	cin>>n>>a>>b;
	cout<<min(a*n, b);
	return 0;
}



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

int main(){

    int n;
    cin >>n;
    int a[n][3];
    for (int i=0;i<n;i++){
        for (int j=0;j<3;j++){
            cin >>a[i][j];
        }
    }
    int dp[n][3];
    dp[0][0]=a[0][0];
    dp[0][1]=a[0][1];
    dp[0][2]=a[0][2];
    for (int i=1;i<n;i++){
        dp[i][0]=max(dp[i-1][1],dp[i-1][2])+a[i][0];
        dp[i][1]=max(dp[i-1][0],dp[i-1][2])+a[i][1];
        dp[i][2]=max(dp[i-1][1],dp[i-1][0])+a[i][2];
    }
    cout <<max(max(dp[n-1][0],dp[n-1][1]),dp[n-1][2]);
    return 0;
}


Measured memory_bytes: 2560
#include <iostream>
#include <stdio.h>
#include <map>
#include <algorithm>
using namespace  std;

int main()
{
    int x,y;
    scanf("%d%d",&x,&y);
    for (int i=0;i<=x;++i){
        if ( (i*2+(x-i)*4) ==  y){
            printf("Yes");
            return 0;
        }
    }
    printf("No");
}

Measured memory_bytes: 3728
#include <algorithm>
#include <bitset>
#include <cassert>
#include <deque>
#include <fstream>
#include <iostream>
#include <map>
#include <math.h>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stdio.h>
#include <string>
#include <vector>

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

using namespace std;

namespace Dump {
#define dump(...) Dump::print(#__VA_ARGS__, __VA_ARGS__)
static std::vector<string> dumpKey;
static string dumpKeyBuf;

void print() { cerr << endl; }
template <class Head, class... Tail> void print(Head &&head, Tail &&... tail) {
  if (dumpKey.empty()) {
    dumpKeyBuf = head;
    dumpKeyBuf.erase(std::remove_if(dumpKeyBuf.begin(), dumpKeyBuf.end(),
                                    [](char c) { return c == ' '; }),
                     dumpKeyBuf.end());

    std::istringstream stream(dumpKeyBuf);
    string field;
    while (std::getline(stream, field, ','))
      dumpKey.push_back(field);

    reverse(dumpKey.begin(), dumpKey.end());
  } else {
    cerr << dumpKey.back() << ":" << head << "  ";
    dumpKey.pop_back();
  }
  Dump::print(std::move(tail)...);
}
}

typedef long long ll;
typedef unsigned long long ull;

typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<long long> vll;
typedef vector<unsigned long long> vull;
typedef pair<int, int> pii; // p.first p.second

// ll n = to_T<ll>("114514")
template <class T> T to_T(const string &s) {
  istringstream is(s);
  T res;
  is >> res;
  return res;
}
template <class T> string to_s(const T &a) {
  ostringstream os;
  os << a;
  return os.str();
}

void solve(long long N, vector<long long> D, long long M, vector<long long> T) {
  map<int, int> mm;

  REP(i, N) { mm[D[i]] = mm[D[i]] + 1; }

  REP(i, M) {
    if (mm[T[i]] == 0) {
      cout << "NO" << endl;
      return;
    }
    mm[T[i]] = mm[T[i]] - 1;
  }
  cout << "YES" << endl;
}

int main() {
  ios::sync_with_stdio(false);
  long long M;
  long long N;
  cin >> N;
  vector<long long> D(N - 1 + 1);
  for (int i = 0; i <= N - 1; i++) {
    cin >> D[i];
  }
  cin >> M;
  vector<long long> T(M - 1 + 1);
  for (int i = 0; i <= M - 1; i++) {
    cin >> T[i];
  }
  solve(N, D, M, T);
  return 0;
}


Measured memory_bytes: 15960
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <regex>
#include <numeric>

using namespace std;


/*--- Macro ---*/
#define rep(i, n) for(int i=0; i<(int)n; i++)
#define rep1(i, n) for(int i=1; i<(int)n; i++)
#define mp make_pair
#define pb push_back


/*---  Type ---*/
typedef long long ll;


/*--- Constants ---*/
template <typename T> const T INF = numeric_limits<T>::max() / 10;
const int MOD = (int)1e9 + 7;

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

// 8-direction
int dy8[] = {0,  1,  1,  1,  0, -1, -1, -1};
int dx8[] = {1,  1,  0, -1, -1, -1,  0,  1};

// Floating
const double EPS = 1e-11;
#define EQ0(x) (abs(x) < EPS)
#define EQ(x, y) (abs(a-b) < EPS)

int n, m;
vector<string> a, b;

bool judge(int x, int y) {
  rep(i, m) {
    rep(j, m) {
      if(a[i+x][j+y] != b[i][j]) {
        return false;
      }
    }
  }
  return true;
}

int main() {
  cin >> n >> m;
  a.resize(n);
  b.resize(m);
  rep(i, n) cin >> a[i];
  rep(i, m) cin >> b[i];

  bool ans = false;
  rep(i, n-m+1) {
    rep(j, n-m+1) {
      if(judge(i, j)) {
        ans = true;
      }
    }
  }

  cout << (ans ? "Yes" : "No") << endl;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
    int N; cin >> N;
    int flag =0;
    for (int i=1;i<10;i++){
        for (int j=1;j<10;j++){
            if (i*j==N) flag = 1;
    }
    }
    if (flag) cout << "Yes" <<"\n";
    else cout << "No" << "\n";
}

Measured memory_bytes: 256
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use itertools::Itertools;
use num_traits::clamp;
use ordered_float::OrderedFloat;
use proconio::{input, marker::*, fastout};
use superslice::*;

fn main() {
    input! {
        x: i128, k: i128, d: i128
    }

    let x = x.abs();
    let ans = if x >= d * k {
        x - k * d
    } else {
        let q = x / d;
        if (k - q) % 2 == 0 {
            x % d
        } else {
            d - x % d
        }
    };
    println!("{}", ans);
}


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

int main() {
	
	     ios_base::sync_with_stdio(false); 
    cin.tie(NULL); 
	  
	   long long n,i,j,k,count=0,ans=0;
	   cin>>n;
	   double x;
	   x=double(n)/double(3);
	   cout<< fixed << setprecision(6) <<x*x*x;
	return 0;
}

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

using namespace std;

vector<char> tag[2];
vector< vector<int> > e[2];

struct Node {
	unsigned char a, b, score;
};
bool operator <(const Node& node1, const Node& node2) {
	return node1.score < node2.score;
}

int v[100][100];

void PushQ(priority_queue<Node>& Q, int a, int b, int score) {
	if (tag[0][a] == tag[1][b]) ++score;
	if (score <= v[a][b]) return;
	v[a][b] = score;

	Q.push({(unsigned char)a, (unsigned char)b, (unsigned char)score});
}
int main() {
	fill(&v[0][0], &v[0][0]+100*100, -1);

	for (int t = 0; t < 2; ++t) {
		int N, M; cin >> N >> M;
		tag[t].resize(N);
		for (int i = 0; i < N; ++i) {
			cin >> tag[t][i];
		}
		e[t].resize(N);
		for (int i = 0; i < M; ++i) {
			int a, b; cin >> a >> b; --a, --b;
			e[t][a].push_back(b);
		}
	}

	priority_queue<Node> Q;
	for (int a = 0; a < tag[0].size(); ++a) for (int b = 0; b < tag[1].size(); ++b) {
		PushQ(Q, a, b, 0);
	}

	while ( !Q.empty() ) {
		Node node = Q.top(); Q.pop();
		int a = (int)node.a, b = (int)node.b;
		int score = (int)node.score;

		if (score < v[a][b]) continue;
		if (score > 100) {
			cout << -1 << endl;
			return 0;
		}

		if (tag[0][a] != tag[1][b]) {
			for (int i = 0; i < e[0][a].size(); ++i) {
				PushQ(Q, e[0][a][i], b, score);
			}
			for (int i = 0; i < e[1][b].size(); ++i) {
				PushQ(Q, a, e[1][b][i], score);
			}
		}
		for (int i = 0; i < e[0][a].size(); ++i) {
			for (int j = 0; j < e[1][b].size(); ++j) {
				PushQ(Q, e[0][a][i], e[1][b][j], score);
			}
		}
	}
	int ans = 0;
	for (int a = 0; a < tag[0].size(); ++a) for (int b = 0; b < tag[1].size(); ++b) {
		ans = max(ans, v[a][b]);
	}
	cout << ans << endl;
}

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

typedef long long ll;
using ll = long long;

bool between(ll x, ll y1, ll y2){
    if(y1 > y2) swap(y1, y2);
    // y1++; y2--;
    // if(!(y1 <= y2)) return false;

    if(x % 3 == 1){
        if(y2 - y1 > 3) return true;
        for(ll y=y1;y<=y2;y++) if(y % 3 == 1) return true;
    }

    return false;
}

ll get_extra(ll x1, ll y1, ll x2, ll y2) {
    ll ans = 0;
    ll three = 1;
    for (int i = 0; i < 35; ++i) {
        if(x1 / three == x2 / three && between(x1 / three, y1 / three, y2 / three)) {
            ll tmp = min(min(x1 % three, x2 % three) + 1, three - max(x1 % three, x2 % three));
            ans = max(ans, tmp);
        }
        three *= 3;
    }

    return ans;
}

ll get_dist(ll x1, ll y1, ll x2, ll y2){
    return abs(x1 - x2) + abs(y1 - y2) + 2 * max(get_extra(x1, y1, x2, y2), get_extra(y1, x1, y2, x2));
}

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

    while (Q--) {
        long long a;
        long long b;
        long long c;
        long long d;

        cin >> a >> b >> c >> d;
        cout << get_dist(a-1, b-1, c-1, d-1) << endl;
    }

    return 0;
}

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

#define debug(x) cout<<#x<<": "<<x<<endl
#define rep(i,n) for (int i=0;i<(n);i++)
#define FOR(i,a,b) for (int i=(a);i<=(b);i++)
#define all(a) (a).begin(),(a).end()
using namespace std;
typedef vector<int> VI;
typedef vector<vector<int>> VVI;
typedef long long ll;


void solve(){
#ifdef _WIN32
	istream &cin = ifstream("input.txt");
#endif

	vector<ll> v(3);

	rep(i, 3) cin >> v[i];

	if (v[0] % 2 == 0 || v[1] % 2 == 0 || v[2] % 2 == 0) cout << 0 << endl;
	else{
		sort(all(v));
		ll ans = v[1] * v[0];
		cout << ans << endl;
	}
}


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


	solve();
	system("PAUSE");
	return 0;
}

Measured memory_bytes: 504
#include <bits/stdc++.h>
typedef long long int LL;
typedef unsigned long long int ULL;
using namespace std;

// 插入此處

struct Pos {
    int i, v;
} a[200005];
int b[200005];
int ans[200005];

int main() {
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++) {
        a[i].i = i;
        cin >> a[i].v;
    }
    sort(a + 1, a + n + 1, [](Pos x, Pos y) {
        return x.v < y.v;
    });
    for (int i = 1; i <= n; i++) {
        cin >> b[i];
    }
    sort(b + 1, b + n + 1, [](int x, int y) { return x > y; });
    vector<int> v;
    int dup;
    for (int i = 1; i <= n; i++) {
        if (a[i].v == b[i]) {
            dup = b[i];
            v.push_back(i);
        }
    }
    int len = v.size();
    if (v.size() > 0) {
        int i = 1;
        int cur = v[0];
        while (len && b[i] != dup && a[i].v != dup) {
            swap(b[i], b[cur]);
            i++;
            cur++;
            len--;
        }
        i = n;
        while (len && b[i] != dup && a[i].v != dup) {
            swap(b[i], b[cur]);
            i--;
            cur++;
            len--;
        }
    }
    if (len == 0) {
        puts("Yes");
        for (int i = 1; i <= n; i++) {
            ans[a[i].i] = b[i];
        }
        for (int i = 1; i <= n; i++) {
            printf("%d ", ans[i]);
        }
        puts("");
    } else {
        puts("No");
    }
}


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

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)

#define INF 100000000
#define MOD 1000000007
#define writeln(n) cout<<n<<endl
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;
//vector<tuple<long long, long long, long long>>vec;

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

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

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

const int inf=100000000;


int main()
{
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    int n; cin>>n;
    llong Z,W; cin>>Z>>W;
    vector<llong> a(n,0);
    REP(i,n) cin>>a[i];
    if(n==1) cout<<abs(a[0]-W)<<endl;
    else cout<<max(abs(a[n-1]-W),abs(a[n-1]-a[n-2]))<<endl;
}

Measured memory_bytes: 892
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<cstdio>
#include<sstream>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double EPS=1e-8;
const int inf=1e9;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
int main(){
	int n,m;
	vector<string>out;
	cin>>n>>m;
	int N=n+m;
	rep(i,1<<min(8,N)){
		int c=0;
		string s="";
		rep(j,min(8,N)){
			if(i&(1<<j)){
				c++;
				s+="A";
			}else s+="B";
		}
		if(c!=(N<9?n:min(4,n)))continue;
		if(N<9){
			if(n==5&&s[s.size()-1]=='B')continue;
			if(m==5&&s[s.size()-1]=='A')continue;
		}
		int t,h=1;
		if((t=s.find("AAAAA"))!=string::npos&&t!=min(4,m))h=0;
		else if((t=s.find("BBBBB"))!=string::npos&&t!=min(4,n))h=0;
		if(h){
			int t=n-4,tt=m-4;
			if(t==2)s+="AA";
			else if(tt==2)s+="BB";
			else if(tt==1&&t==1){
				out.pb(s+"BA");
				s+="AB";
			}else if(t==1&&tt==0)s+="A";
			else if(tt==1&&t==0)s+="B";
			out.pb(s);
		}
	}
	sort(all(out));
	rep(i,out.size())cout<<out[i]<<endl;
//	cout<<out.size()<<endl;
}

Measured memory_bytes: 1224
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Scanner;
import java.util.Set;

//Name the Crossing
public class Main{

	class R{
		int id, col;
		Set<Integer> adj, eq;
		boolean visit;
		public R(int id) {
			this.id = id;
			col = -1;
			eq = new HashSet<Integer>();
			adj = new HashSet<Integer>();
		}
		void color(int c){
			if(visit)return;
			col = c;
			visit = true;
			for(int v:adj)rs[v].color(c%2==0?(c+1):(c-1));
		}
		boolean reach(int g){
			if(id==g)return true;
			if(visit)return false;
			visit = true;
			for(int v:eq)if(rs[v].reach(g))return true;
			return false;
		}
	}
	
	int ID;
	Map<String, R> ref;
	Set<String> streets;
	String[] names;
	R get(String s){
		if(ref.containsKey(s))return ref.get(s);
		R res = new R(ID);
		names[ID] = s;
		rs[ID++] = res;
		ref.put(s, res);
		return res;
	}
	R[] rs;
	
	void reset(){
		for(int i=0;i<ID;i++)rs[i].visit = false;
	}
	
	void run(){
		Scanner sc = new Scanner(System.in);
		for(;;){
			int n = sc.nextInt();
			if(n==0)break;
			ID = 0;
			ref = new HashMap<String, R>();
			rs = new R[200];
			names = new String[200];
			streets = new HashSet<String>();
			while(n--!=0){
				String t = sc.next();
				streets.add(t);
				String s[] = t.split("-");
				R a = get(s[0]), b = get(s[1]);
				a.adj.add(b.id); b.adj.add(a.id);
				b.eq.add(a.id);
			}
			int col = 0;
			for(int i=0;i<ID;i++){
				if(rs[i].visit)continue;
				rs[i].color(col);
				col+=2;
			}
			int N =	ID;
			for(int i=0;i<N;i++)for(int j=i+1;j<N;j++){
				boolean C, D, E;
				C = false;
				D = E = true;
				for(int k=0;k<N;k++){
					if(k==i||k==j)continue;
					if(rs[i].adj.contains(k)&&rs[j].adj.contains(k))C = true;
					if(streets.contains(names[k]+"-"+names[i])&&streets.contains(names[j]+"-"+names[k]))D = false;
					if(streets.contains(names[i]+"-"+names[k])&&streets.contains(names[k]+"-"+names[j]))E = false;
				}
				if(C&&D&&E){
					R a = get(names[i]), b = get(names[j]);
					a.eq.add(b.id); b.eq.add(a.id);
				}
			}
			System.out.println(N);
			int m = sc.nextInt();
			while(m--!=0){
				String[] t = sc.next().split("-");
				R a = get(t[0]), b = get(t[1]);
				if(a.col==b.col||Math.abs(a.col-b.col)>=2||a.col==-1||b.col==-1){
					System.out.println("NO"); continue;
				}
				reset();
				System.out.println(b.reach(a.id)?"YES":"NO");
			}
		}
	}
	
	public static void main(String[] args) {
		new Main().run();
	}
}

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

int main()
{
    int N;
    std::vector<int> a = {1, 2, 4, 6, 16, 12, 64, 24, 36, 48, 1024, 60};
    std::cin >> N;
    std::cout << a[N - 1] << std::endl;
    return 0;
}

Measured memory_bytes: 3100
import sys
input = lambda: sys.stdin.readline().rstrip()

n, m = map(int, input().split())

B = []
B_append = B.append
for _ in range(m):
    a, b = map(int, input().split())
    B_append((b, a))

B.sort()
ans = 1
tmp = B[0][0]
for upper, lower in B[1:]:
  if lower >= tmp:
      tmp = upper
      ans += 1

print(ans)

Measured memory_bytes: 17384
#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, t;
    cin >> s >> t;

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

    string u;
    cin >> u;
    if(s==u){
        a--;
    }else{
        b--;
    }

    cout << a << " " << b << endl;

    return 0;
}

Measured memory_bytes: 256
import sys
import bisect
input = sys.stdin.readline

class Bisect(object):
    def bisect_max(self, reva, func,M):
        ok = 0 # exist
        ng = 4*(10**5) # not exist
        while abs(ok-ng) > 1:
            cnt = (ok + ng) // 2
            if func(cnt,reva,M):
                ok = cnt
            else:
                ng = cnt
        return ok

def solve1(tgt,reva,M):
    res=0
    n = len(reva)
    for i in range(n):
        tmp = bisect.bisect_left(reva,tgt-reva[i])
        tmp = n - tmp
        res += tmp
    if M <= res:
        return True
    else:
        return False

N,M = map(int,input().split())
a = list(map(int,input().split()))
a.sort(reverse=True)
reva = a[::-1]
bs = Bisect()
Kmax = (bs.bisect_max(reva,solve1,M))

r=[0]
for i in range(N):
    r.append(r[i]+a[i])

res = 0
cnt = 0
t = 0
for i in range(N):
    tmp = bisect.bisect_left(reva,Kmax-reva[N-i-1])
    tmp2 = bisect.bisect_right(reva,Kmax-reva[N-i-1])
    if tmp!=tmp2:
        t = 1
    tmp = N - tmp
    cnt += tmp
    res += tmp*a[i]+r[tmp]
if t==1:
    res -= (cnt-M)*Kmax
print(res)


Measured memory_bytes: 59664
a=[input() for i in range(2)]
a1=[int(i) for i in a[0].split()]
a2=int(a[1])

count=0

while a1[1]<=a1[0]:
	a1[1]=a1[1]*2
	count+=1

while a1[2]<=a1[1]:
	a1[2]=a1[2]*2
	count+=1

if count<=a2:
	print("Yes")
else:
	print("No")


Measured memory_bytes: 9156
#include<iostream>
using namespace std;
int main() {
	int n;
	while (cin >> n&&n != 0) {
		int a, b=-1;
		for (int i = 0; i < n; i++) {
			int c, d, e;
			cin >> c >> d >> e;
			d += e;
			if (d > b) {
				a = c;
				b = d;
			}
		}
		cout << a << " " << b << endl;
	}
}

Measured memory_bytes: 3096
def fibonacci(n)
  if n.zero? || n == 1
    return $F[n] = 1
  end
  if $F[n]
    return $F[n]
  end
  return $F[n] = fibonacci(n - 2) + fibonacci(n - 1)
end

$F = Array.new(50, nil)
n = gets.to_i
puts fibonacci(n)


Measured memory_bytes: 6860
#include <iostream>

using namespace std;

string a, b;

int main() {
	cin >> a >> b;
	for (int i = 0; i < a.length() + b.length(); ++i) {
		cout << ((i + 1) & 1 ? a[i >> 1] : b[i >> 1]);
	}
	cout << 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>

using namespace std;
using namespace __gnu_pbds;

using u128 = __uint128_t;

#define int long long
#define idxSet tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>
#define atIdx find_by_order
#define idxOf order_of_key
#define MOD 1000000007
#define MAX 200005
#define endl '\n'

#define v(type) vector<type>
#define p(type1, type2) pair<type1 , type2>
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

int dp[MAX];

void solve() {
    int n;
    cin >> n;
    vi a(n);
    for(int i = 0 ; i< n ; i++)
        cin>>a[i];
    int cnt = 0;
    cnt += a[0] / 2;
    a[0] = a[0] % 2;
    for (int i = 1; i < n; i++) {
        if(a[i] == 0)
            continue;
        if(a[i-1] != 0){
            cnt++;
            a[i] --;
        }
        cnt += a[i] / 2;
        a[i] = a[i] % 2 ;
    }
    cout<<cnt<<endl;

}

int32_t main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int t = 1;
    //cin>>t;
    while (t--)
        solve();
    return 0;
}

Measured memory_bytes: 3996
//  Author: Tanuj Johal
//  It's a show time, Enjoy your everyday.

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define ll          long long
#define fio         ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb          push_back
#define vi          vector<ll>
#define pp          push_pop
#define pll         pair<ll,ll>
#define in          insert
#define ini(a,n)    memset(a,n,sizeof(a))
#define ff          first
#define ss          second
#define inf         1e18
#define all(p)      p.begin(), p.end()
#define que_max     priority_queue <int>
#define que_min     priority_queue <int, vi, greater<int>>
#define print(a)    for(auto i:a){cout<<i<<" ";}
#define print1(a)   for(auto i:a){cout<<i.ff<<" "<<i.ss<<endl;}
#define run_time cout << "\nTIME = " << clock() - tt << endl; tt = clock();

typedef tree<pll, null_type, less<pll>, rb_tree_tag, tree_order_statistics_node_update> Set;
unordered_map<ll,set<ll>> g;
unordered_map<ll,ll> vis;
ll tt;
const ll mod = 1e9+7;

ll power(ll x,ll y,ll p){ll r=1;x=x%p;while(y>0){if(y&1)r=(r*x)%p;y=y>>1;x=(x*x)%p;}return r;}
const ll N = 2e5 + 10;
ll dx[4]={-1, +1, 0, 0};
ll dy[4]={0, 0, +1, -1};
bool imp = false;


void solve()
{

    ll n;cin >> n;
    string  s;
    cin >> s;
    ll w = 0;
    for(ll i=0;i<n;i++){
        if(s[i] == 'W')
            w++;
    }
    ll e = n-w;

    ll ans = min(e, w);
    ll c = 0;
    ll i = 0;
    ll j = n-1;

    while(i < j){
        if(s[i] == 'W' and s[j] == 'R'){
            i++;
            j--;
            c++;
        }
        if(s[i] != 'W')
            i++;
        if(s[j] != 'R')
            j--;
    }

    cout << min(ans, c ) << endl;
}

int main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
#endif
    fio
//    precompute();

    int t=1;
    if(imp) cin>>t;
    tt = clock();
    while(t--)
    {
        // cout<<"Case #"<<tc<<": ";
        g.clear();
        vis.clear();
        solve();
        // tc++;
    }
//    run_time;

}

Measured memory_bytes: 3804
import java.io.*;

class Main{
  public static void main(String[] args) throws IOException{
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    String str = br.readLine();
    int i = 0;
    int count = 0;
    for(i=0; i< str.length(); i++){
      if(str.charAt(i) == 'x'){
        count++;
      }
    }
    if(count > 7){
      System.out.println("NO");
    }else{
      System.out.println("YES");
    }
  }
}



Measured memory_bytes: 21844
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)


def main():
    n = int(input())
    csf = [list(map(int, input().split())) for _ in range(n-1)]
    arr = []
    for i in range(len(csf)):
        arr.append(csf[i:])

    for x in arr:
        ans = x[0][0] + x[0][1]
        for c, s, f in x[1:]:
            if ans > s:
                if ans % f == 0:
                    ans += c
                else:
                    ans += c + f - ans % f
            else:
                ans = c + s
        print(ans)
    print(0)


if __name__ == '__main__':
    main()


Measured memory_bytes: 41584
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <queue>
#include <utility>
#include <map>
#include <bitset>
#include <numeric>
#define ll long long
using namespace std;
using p = pair<ll, ll>;
ll dx[8]={ 0, 1, 0,-1, 1, 1,-1,-1}; // x軸方向への変位
ll dy[8]={ 1, 0,-1, 0, 1,-1, 1,-1}; // y軸方向への変位

int main(void) {
    ll n, q;
    cin >> n >> q;
    vector<vector<ll>> g(n+1);
    vector<ll> w(n+1, 0);
    for(ll i = 0; i < n-1; i++){
        ll a, b;
        cin >> a >> b;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    for(ll i = 0; i < q; i++){
        ll a, b;
        cin >> a >> b;
        w[a] += b;
    }
    vector<ll> d(n+1, -1);
    queue<ll> que;
    que.push(1);
    d[1] = w[1];
    while(!que.empty()){
        ll v = que.front();
        que.pop();
        for(ll nv : g[v]){
            if(d[nv]!=-1) continue;
            d[nv] = d[v]+w[nv];
            que.push(nv);
        }
    }
    for(ll i = 1; i <= n; i++)
        cout << d[i] << endl;
    return 0;
}


Measured memory_bytes: 19440
#include <iostream>
#include<queue>
#include<stack>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
#include<cstring>
#include<string>
#include<cassert>
#include<cmath>
#include<climits>
#include<iomanip>
#include<bitset>
#include<unordered_map>

using namespace std;

#define MOD 998244353
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define rep(i,j,n) for(ll (i)=(j);(i)<(n);(i)++)
#define FOR(i,c) for(decltype((c).begin())i=(c).begin();i!=(c).end();++i)
#define ll long long
#define ull unsigned long long
#define all(hoge) (hoge).begin(),(hoge).end()
typedef pair<ll, ll> P;
const long long INF = 1LL << 60;
typedef vector<ll> Array;
typedef vector<Array> Matrix;


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

//グラフ関連
struct Edge {//グラフ
	ll to, cap, rev;
	Edge(ll _to, ll _cap, ll _rev) {
		to = _to; cap = _cap; rev = _rev;
	}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

void add_edge(Graph& G, ll from, ll to, ll cap, bool revFlag, ll revCap) {
	G[from].push_back(Edge(to, cap, (ll)G[to].size()));
	if (revFlag)G[to].push_back(Edge(from, revCap, (ll)G[from].size() - 1));
}


//nCr,nPr,modの逆元
class Combination {
public:
	Array fact;//n！
	Array inv;//n!の逆元
	ll mod;
	Combination(ll n, ll _mod) {
		mod = _mod;
		fact.resize(n + 1);
		fact[0] = 1;
		REP(i, n) {
			fact[i + 1] = (fact[i] * (i + 1LL)) % mod;
		}
		inv.resize(n + 1);
		inv[n] = mod_inv(fact[n]);
		for (int i = n; i > 0; i--) {
			inv[i - 1] = inv[i] * i % mod;
		}
	}
	//modの逆元
	ll mod_inv(ll x) {
		ll n = mod - 2;
		ll res = 1LL;
		while (n > 0) {
			if (n & 1) res = res * x % mod;
			x = x * x % mod;
			n >>= 1;
		}
		return res;
	}
	ll nCr(ll n, ll r) {
		return ((fact[n] * inv[r] % mod) * inv[n - r]) % mod;
	}
	ll nPr(ll n, ll r) {
		return (fact[n] * inv[n - r]) % mod;
	}
	ll nHr(ll n, ll r) {
		//重複組み合わせ：n種類のものからr個取り出す組み合わせ
		return nCr(r + n - 1, r);
	}
};


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

	ll n;
	cin >> n;
	vector<string> s(n);
	REP(i, n) cin >> s[i];

	map<ll, ll> mp;
	REP(i,s[0].size()) {
		mp[s[0][i]]++;
	}

	for (int j = 1; j < n; j++) {
		map<ll, ll> mp2;
		REP(i, s[j].size()) {
			mp2[s[j][i]]++;
		}
		auto it = mp.begin();
		while(it!=mp.end()) {
			if (mp2.find(it->first)==mp2.end()) {
				it=mp.erase(it);
			}
			else {
				it->second = min(it->second, mp2[it->first]);
				it++;
			}
		}
	}

	for (auto i : mp) {
		while (i.second--) {
			cout << (char)i.first;
		}
	}
	cout << endl;

	return 0;
}

Measured memory_bytes: 256
/*input
12345678 87654321 12345678 87654321
123456789
*/
#include <bits/stdc++.h>
using namespace std;
const long long md=1e9+7;
long long n;

int main(){
	#ifdef ONLINE_JUDGE
	ios_base::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	#endif
	long long q,m,k,h,ans=0,sum=0,a,b,c,d;
	cin>>a>>b>>c>>d>>k;
	if(b>2*a) b=2*a;
	if(c>2*b) c=2*b;
	if(d>2*c) d=2*c;
	if(k%2==1){
		cout<<c+(k-1)/2*d;
	}
	else cout<<k/2*d;
}

Measured memory_bytes: 256
N,C = map(int, input().split())
# D[i][j]: 色iから色jに塗り替える場合のコスト
D = [[int(i) for i in input().split()] for _ in range(C)]

cnt = [[0] * C for _ in range(3)]
for i in range(1, N + 1):
    line = [int(i) for i in input().split()]
    for j, c in enumerate(line, start=1):
        cnt[(i + j) % 3][c - 1] += 1

ans = float("inf")
for i in range(C):
    for j in range(C):
        if i == j: continue
        for k in range(C):
            if i == k or j == k: continue
            cost = 0
            for x in range(C):
                cost += D[x][i] * cnt[0][x]
                cost += D[x][j] * cnt[1][x]
                cost += D[x][k] * cnt[2][x]
            
            ans = min(ans, cost)

print(ans)

Measured memory_bytes: 3064
package main

import (
  "bufio"
  "os"
  "strconv"
  "fmt"
)

var reader = bufio.NewReaderSize(os.Stdin, 1000000)
var writer = bufio.NewWriter(os.Stdout)
func NextLine() string {
  var line, buffer []byte
  var isPrefix bool = true
  var err error
  for isPrefix {
    line, isPrefix, err = reader.ReadLine()
    if err != nil { panic(err) }
    buffer = append(buffer, line...)
  }
  return string(buffer)
}
func NextInt() int {
  var n int
  n, _ = strconv.Atoi(NextLine())
  return n
}
func Write(s interface{}) {
  fmt.Fprintln(writer, s)
}
func Output() {
  _ = writer.Flush()
}

const p = 1000000007

func main() {
  N := NextInt()
  S := NextLine()
  DP := make([][]int, 2 * N)
  for i := range DP {
    DP[i] = make([]int, 2)
  }
  DP[0] = []int{1, 0}
  pat := 1
  for i := 1; i < 2 * N; i++ {
    if S[i] == 'W' {
      if DP[i - 1][0] % 2 == 0 {
        DP[i][0] = DP[i - 1][0] - 1
        DP[i][1] = DP[i - 1][1] + 1
        pat = pat * DP[i - 1][0] % p
      } else {
        DP[i][0] = DP[i - 1][0] + 1
        DP[i][1] = DP[i - 1][1]
      }
    } else {
      if DP[i - 1][0] % 2 == 0 {
        DP[i][0] = DP[i - 1][0] + 1
        DP[i][1] = DP[i - 1][1]
      } else {
        DP[i][0] = DP[i - 1][0] - 1
        DP[i][1] = DP[i - 1][1] + 1
        pat = pat * DP[i - 1][0] % p
      }
    }
  }
  if DP[2 * N - 1][0] != 0 || DP[2 * N - 1][1] != N {
    Write(0)
  } else {
    factorial := 1
    for i := N; i > 0; i-- {
      factorial = factorial * i % p
    }
    Write(pat * factorial % p)
  }
  Output()
}

Measured memory_bytes: 9088
from collections import deque

N, M = map(int, input().split())
l = [[] for i in range(N)]

for i in range(M):
  a,b=map(int,input().split())
  l[a-1].append(b-1)
  l[b-1].append(a-1)

ans = [-1] * (N)

que = deque([0])

while que:
    now = que.popleft()
    for i in l[now]:
        if ans[i] == -1:
            ans[i] = now
            que.append(i)



if(min(ans) == -1):
    print("No")


print("{} ".format('Yes'))
for i in range(1,N):
    print("{} ".format(ans[i] + 1))


Measured memory_bytes: 34220
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, x, n) for (int i = x; i < (n); i++)
#define all(n) begin(n), end(n)
struct cww
{
    cww()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
} star;
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
typedef vector<int> vint;
typedef vector<char> vchar;
typedef vector<vector<int>> vvint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef unsigned long long ull;
#define vcin(a)                          \
    for (int i = 0; i < (a).size(); i++) \
        cin >> (a)[i];

int main()
{
    ll N, A;
    cin >> N >> A;
    vll x(N + 1);
    ll sum = 0, ans = 0;
    rep(i, N)
    {
        cin >> x[i + 1];
        sum += x[i + 1];
    }
    vector<vvll> dp(N + 1, vvll(N + 1, vll(sum + 1)));
    //   ll DP[51][51][2501];
    dp[1][1][x[1]] = 1;
    rep2(i, 1, N + 1)
    {
        dp[i][0][0] = 1;
    }
    rep2(i, 1, N)
    {
        rep2(j, 1, N + 1)
        {
            rep2(k, 0, sum + 1)
            {
                if (k >= x[i + 1])
                    dp[i + 1][j][k] = dp[i][j][k] + dp[i][j - 1][k - x[i + 1]];
                else
                {
                    dp[i + 1][j][k] = dp[i][j][k];
                }
            }
        }
    }
    for (int j = 1; j * A <= sum and j <= N; j++)
    {
        ans += dp[N][j][j * A];
    }

    /*
    rep2(i, 1, N + 1)
    {
        rep2(j, 1, N + 1)
        {
            rep(k, sum + 1)
            {
                DP[i][j][k] = 0;
            }
        }
    }
    DP[1][1][x[1]] = 1;
    rep2(i, 1, N + 1)
    {
        DP[i][0][0] = 1;
    }
    rep2(i, 1, N)
    {
        rep2(j, 1, N + 1)
        {
            rep2(k, 0, sum + 1)
            {
                if (k >= x[i + 1])
                    DP[i + 1][j][k] = DP[i][j][k] + DP[i][j - 1][k - x[i + 1]];
                else
                {
                    DP[i + 1][j][k] = DP[i][j][k];
                }
            }
        }
    }
    for (int j = 1; j * A <= sum and j <= N; j++)
    {
        ans += DP[N][j][j * A];
    }
    */
    cout << ans;
    return 0;
}

Measured memory_bytes: 52224
# 入力が10**5とかになったときに100ms程度早い
import sys
read = sys.stdin.readline


def read_ints():
    return list(map(int, read().split()))


def read_a_int():
    return int(read())


def read_matrix(H):
    '''
    H is number of rows
    '''
    return [list(map(int, read().split())) for _ in range(H)]


def read_map(H):
    '''
    H is number of rows
    文字列で与えられた盤面を読み取る用
    '''
    return [read()[:-1] for _ in range(H)]


def read_col(H, n_cols):
    '''
    H is number of rows
    n_cols is number of cols

    A列、B列が与えられるようなとき
    '''
    ret = [[] for _ in range(n_cols)]
    for _ in range(H):
        tmp = list(map(int, read().split()))
        for col in range(n_cols):
            ret[col].append(tmp[col])

    return ret


H = read_a_int()
W = read_a_int()
N = read_a_int()

print(min(N // H + 1 if N % H else N // H, N // W + 1 if N % W else N // W))


Measured memory_bytes: 3064
X1,Y1,X2,Y2 = map(int,input().split())
a = X2 - X1
b = Y2 - Y1
X3 = X2 - b
Y3 = Y2 + a
X4 = X1 - b
Y4 = Y1 + a
print(X3,end=' ') 
print(Y3,end=' ')
print(X4,end=' ')
print(Y4)

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

using namespace std;
long int c = 1000000007;
vector<long int> power2(1000001);
int main(){

int n;
cin>>n;
int i=1;
int ans=0;
while(i<=n){
  int k;
  cin>>k;
  if(i%2==1 && k%2==1)
    ans+=1;
  i++;
}
cout<<ans;
}
/*
// Sample code to perform I/O:

cin >> name;                            // Reading input from STDIN
cout << "Hi, " << name << ".\n";        // Writing output to STDOUT

// Warning: Printing unwanted or ill-formatted data to output will cause the test cases to fail
*/

// Write your code here


Measured memory_bytes: 11024
#include <iostream>
#include <fstream>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <unordered_set>
#include <bitset>
#include <limits>
#include <algorithm>

#define MOD_BIG 1000000007
#define MOD_BIG2 998244353
using std::string;
using std::cin;
using std::cout;
using std::cerr;
using std::endl;
using ll = long long;
using pint = std::pair<int, int>;
using pll = std::pair<ll, ll>;
using std::vector;

#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)

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



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

int main() {
    
    int N;
    cin >> N;
    vector<pll> B(N);
    REP(i, N) {
        ll x, y;
        cin >> x >> y;
        B[i] = pll(x, y);
    }
    std::sort(B.begin(), B.end());
    std::set<pll> s;
    FOR(i, 0, N) FOR(j, i+1, N) {
        ll dx = B[j].first - B[i].first;
        ll dy = B[j].second - B[i].second;
        s.insert(pll(dx, dy));
    }
    int ans = N;
    while(!s.empty()) {
        int cnt = 0;
        ll mx, my;
        mx = (*s.begin()).first;
        my = (*s.begin()).second;
        s.erase(s.begin());
        FOR(i, 0, N) {
            FOR(j, i+1, N) {
                ll dx = B[j].first - B[i].first;
                ll dy = B[j].second - B[i].second;
                if (dx == mx && dy == my) cnt++;
                if (dx > mx) break;
            }
        }
        ans = std::min(ans, N-cnt);
        //cerr << N - cnt << endl;
    }
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 384
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {
	private static final FastIn in = new FastIn();
	private static final PrintWriter out = new PrintWriter(System.out);
	public static void main(String[] args) {
		Solver sol = new Solver();
		sol.solve();
		out.close();
	}
	
	private static final class Solver {
		public void solve() {
			int x = in.nextInt();
			out.println(x == 0 ? 1 : 0);
		}
	}
	
	private static final class FastIn {
		private BufferedReader br;
		private StringTokenizer st;
		public FastIn() {
			br = new BufferedReader(new InputStreamReader(System.in), 1 << 20);
			st = null;
		}
		
		public String next() {
			while (st == null || !st.hasMoreTokens()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return st.nextToken();
		}
		
		public int nextInt() {
			return Integer.parseInt(next());
		}
	}
}

Measured memory_bytes: 34644
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	a, _ := strconv.Atoi(next())
	return a
}

func main() {
	buf := make([]byte, 1024*1024)
	sc.Buffer(buf, bufio.MaxScanTokenSize)
	sc.Split(bufio.ScanWords)

	n := nextInt()
	a := make([]int, n)

	for i := 0; i < n; i++ {
		a[i] = nextInt()
	}

	b := make([]int, n)
	copy(b, a)

	sort.Slice(b, func(i, j int) bool { return b[j] < b[i] })

	for i := 0; i < n; i++ {
		if a[i] == b[0] {
			fmt.Println(b[1])
		} else {
			fmt.Println(b[0])
		}
	}
}


Measured memory_bytes: 8124
n=int(input())
s=input()
ans=0
for i in range(1,n):
    count=0
    str1=set(s[:i])
    str2=s[i:]
    for j in range(len(str1)):
        str3=(str1.pop()) in str2
        if str3==True:
            count+=1
    if ans<count:
        ans=count
print(ans)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ok() puts(ok?"Yes":"No");
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef set<int> si;
typedef map<string, int> msi;
typedef greater<int> gt;
typedef priority_queue<int, vector<int>, gt> minq;
typedef long long ll;
typedef pair<ll,ll> pll;
const ll LINF = 1e18L + 1;
const int INF = 1e9 + 1;
//clang++ -std=c++11 -stdlib=libc++ 

int main() {
  ll n,k; cin >> n>>k;
  vector<ll>  a(n); 
  rep(i,n) {
    cin >> a[i];
    a[i]--;
  }
  vb visited(n, false);
  ll start = -1;
  ll now = 0;
  while (!visited[now]) {
    k--;
    visited[now] = true; 
    now = a[now];
    if (k==0) {
      cout << now + 1 << endl;
      return 0;
    }
  }
  start = now;
  ll len = 2;
  now = a[now];
  while (a[now] != start) {
    len++; 
    now = a[now];
  }
  k %= len;
  now = start;
  rep(i, k) {
    now = a[now];
  }
  cout << now + 1 << endl;
  return 0;
}

Measured memory_bytes: 4844
h, w = map(int ,input().split())
s = [list(input()) for _ in range(h)]
check = [[0] * w for _ in range(h)]
move = [[1, 0], [-1, 0], [0, 1], [0, -1]]
ans = 0

for i in range(h):
    for j in range(w):
        if check[i][j] == 1:
            continue
        black, white = 0, 0 

        stack = [[i, j]]
        check[i][j] = 1
        if s[i][j] == '#':
            black += 1
        else:
            white += 1

        while len(stack) > 0:
            x, y = stack.pop()
            tmp = s[x][y]
            for dx, dy in move:
                nx, ny = x + dx, y + dy
                if 0 <= nx < h and 0 <= ny < w and tmp != s[nx][ny] and check[nx][ny] == 0:
                    stack.append([nx, ny])
                    check[nx][ny] = 1
                    if s[nx][ny] == '#':
                        black += 1
                    else:
                        white += 1

        ans += black * white

print(ans)

# %%


Measured memory_bytes: 60252
#include <algorithm>
#include <vector>

template<typename T>
struct FlowGraph {
private:
  struct edge {
    const int from, to;
    T cap;
    const int r_idx;
    const bool is_rev;
    edge(int f, int t, T c, int i, bool is_rev) :
      from(f), to(t), cap(c), r_idx(i), is_rev(is_rev) {}
  };

  std::vector<std::vector<edge>> G;

  T dfs(int v, int sink, T min_cap, std::vector<bool>& visited){
    visited[v] = true;
    if(v == sink) return min_cap;
    for(auto& e : G[v]){
      if(e.cap == T()) continue;
      if(visited[e.to]) continue;
      T min_cap_ = std::min(min_cap,e.cap);
      T flowed = dfs(e.to,sink,min_cap_, visited);
      if(flowed == T()) continue;
      e.cap -= flowed;
      G[e.to][e.r_idx].cap += flowed;
      return flowed;
    }
    return T();
  }
  
public:
  FlowGraph(size_t n) : G(n) {}
  void add_edge(int from, int to, T cap){
    int i = G[to].size(), i_ = G[from].size();
    G[from].emplace_back(from,to,cap,i,false);
    G[to].emplace_back(to,from,T(),i_,true);//reverse edge
  }
  T max_flow(int from, int to){
    T ret = 0, INF = 1e9;
    while(true){
      std::vector<bool> visited(G.size());
      T f = dfs(from,to,INF,visited);
      if(f == T()) break;
      ret += f;
    }
    return ret;
  }
  std::vector<edge> flowed_edge(){
    std::vector<edge> ret;
    for(auto v : G){
      for(auto e : v){
        if(e.is_rev) continue;
        if(!G[e.to][e.r_idx].cap) continue;
        ret.emplace_back(e.from,e.to,G[e.to][e.r_idx].cap,e.r_idx,false);
      }
    }
    return ret;
  }
};

#include <iostream>
#include <vector>
using namespace std;

int main(){
  int N, M;
  cin >> N >> M;
  vector<string> S(N);
  for(int i = 0; i < N; ++i){
    cin >> S[i];
  }
  FlowGraph<int> G(N*M+2);
  int source = N*M, sink = source+1;
  for(int i = 0; i < N; ++i){
    for(int j = 0; j < M; ++j){
      if(S[i][j] == '#') continue;
      int v = i*M+j;
      if((i+j)%2){
        G.add_edge(source,v,1);
        if(i > 0 and S[i-1][j] != '#')
          G.add_edge(v,v-M,1);
        if(i < N-1 and S[i+1][j] != '#')
          G.add_edge(v,v+M,1);
        if(j > 0 and S[i][j-1] != '#')
          G.add_edge(v,v-1,1);
        if(j < M-1 and S[i][j+1] != '#')
          G.add_edge(v,v+1,1);
      }else{
        G.add_edge(v,sink,1);
      }
    }
  }
  cout << G.max_flow(source,sink) << '\n';
  auto flowed_edge = G.flowed_edge();
  int d[] = {M,-M,1,-1};
  string s = "v^><";
  for(auto e : flowed_edge){
    if(e.from == source) continue;
    if(e.to == sink) continue;
    for(int i = 0; i < 4; ++i){
      if(e.from+d[i] != e.to)
        continue;
      S[e.from/M][e.from%M] = s[i];
      S[e.to/M][e.to%M] = s[i^1];
      break;
    }
  }
  for(auto e : S)
    cout << e << '\n';
}


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

const int mod = 1e9 + 7;

ll modpow(ll a, ll n, ll mod) {
	ll res = 1;
	while(n > 0) {
		if (n & 1) res = res * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}

int main() {
	int m, n;
	cin >> m >> n;
	cout << modpow(m, n, mod) << endl;
	return 0;
}


Measured memory_bytes: 3104
a, b, c, k = map(int, input().split())

left = 0
if k > a:
   ans = a
   left = k - a
else:
   print(k)
   exit()

if left > 0:
   if left > b:
      left = left - b
   else:
      print(ans)
      exit()

if left > 0:
   if left < c:
      print(ans - left)
   else:
      print(ans - c)


Measured memory_bytes: 9184
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//INSERT ABOVE HERE
signed main(){
  int n;
  cin>>n;
  vector<vector<int> > G(n);
  for(int i=1;i<n;i++){
    int x,y;
    cin>>x>>y;
    x--;y--;
    G[x].emplace_back(y);
    G[y].emplace_back(x);
  }
  
  vector<int> mx(n,0);
  function<void(int, int, int)> dfs1=
    [&](int v,int p,int d){
      chmax(mx[v],d);
      for(int u:G[v]){
        if(u==p) continue;
        dfs1(u,v,max(v,mx[v]));
      }      
    };
  dfs1(0,-1,0);
  
  vector<unordered_map<int, int> > dp(n);
  function<int(int, int, int)> dfs4=
    [&](int v,int p,int d){
      if(dp[v].count(d)) return dp[v][d];
      int &res=dp[v][d];
      res=v<d;
      for(int u:G[v]){
        if(u==p||u>d) continue;
        res+=dfs4(u,v,d);
      }
      return res;
    };
  
  vector<int> ans(n,0);
  function<void(int, int)> dfs2=
    [&](int v,int p){      
      for(int u:G[v]){
        if(u==p) continue;
        dfs2(u,v);
      }
      if(p<0) return;
      ans[v]=1+dfs4(v,p,mx[v]);
      if(mx[v]>v) ans[v]-=1+(v<mx[p]?dfs4(v,p,mx[p]):0);      
    };
  dfs2(0,-1);
  
  function<void(int, int)> dfs3=
    [&](int v,int p){
      for(int u:G[v]){
        if(u==p) continue;
        ans[u]+=ans[v];
        dfs3(u,v);
      }
    };
  dfs3(0,-1);

  for(int i=1;i<n;i++){
    if(i>1) cout<<" ";
    cout<<ans[i];
  }
  cout<<endl;
  return 0;
}


Measured memory_bytes: 56320