akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<cstring>
using namespace std;
int main()
{
	long long N;
	scanf("%lld",&N);
	for(long long h=1;h<=3500;++h)
		for(long long n=1;n<=3500;++n)
		{
			long long fm=N*h*n;
			long long fz=4*h*n-N*n-N*h;
			if(fz==0)
				continue;
			long long w=(fm/fz);
			if(fm%fz==0&&w>=1)
			{
				printf("%lld %lld %lld",h,n,w);
				return 0;
			}
		} 
}


Measured memory_bytes: 128
s = list(str(input()))
a = int(s[0]+s[1])
b = int(s[2]+s[3])
if 0 < a < 13:
    if 0 < b < 13:
        print("AMBIGUOUS")
    else:
        print("MMYY")

else:
    if 0 < b < 13:
        print("YYMM")
    else:
        print("NA")


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

int main(){
    int kosuto[100000];
    int n,m;
    cin >> n >> m;
    int koin[m];
    for(int i = 0;i < m;i++){
    cin >> koin[i];
    kosuto[koin[i]] = 1;
    }
    int flag = 1;
    while(flag){
        for(int i = 0;i < n;i++){
            for(int j = 0;j < m;j++){
                if(kosuto[i] > 0 ){
                    if(kosuto[i + koin[j]] == 0){
                        kosuto[i + koin[j]] = kosuto[i] + 1;
                    }
                    else{
                        kosuto[i + koin[j]] = min(kosuto[i + koin[j]],kosuto[i] + 1);
                        if(i + koin[j] == n){
                            flag = 0;
                        }
                    }
                }
            }
        }
    }
    cout << kosuto[n] << endl;
    return 0;
}

Measured memory_bytes: 1400
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ll long long
#define lld long double
#define ALL(x) x.begin(), x.end()
#ifdef DEBUG
#define line() cerr << "[" << __LINE__ << "] ";
#define dump(i) cerr << #i ": " << i << " ";
#define dumpl(i) cerr << #i ": " << i << endl;
#else
#define line(i)
#define dump(i)
#define dumpl(i)
#endif
using namespace std;
int head(int n)
{
    while (n > 9)
    {
        n /= 10;
    }
    return n;
}

int main(int argc, char const *argv[])
{
    int n;
    cin >> n;
    int c[10][10];
    rep(i, 10) rep(j, 10) c[i][j] = 0;
    rep(i, 1, n + 1)
    {
        c[head(i)][i % 10]++;
    }
    ll ans = 0;
    rep(i, 10) rep(j, 10)
    {
        ans += c[i][j] * c[j][i];
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long n,a,b,sm;
int main()
{
	cin>>n>>a>>b;
	long long h=n/(a+b),g=n%(a+b);
	sm+=(h*a);
	if(g>a)
	{
		sm+=a;
	}
	else
	{
		sm+=g;
	}
	cout<<sm;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define INF 1000000010
#define EPS 1e-9
#define fst first
#define scd second

#define debug(x) cout<<x<<endl;
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define lp(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
#define int long long
#define endl "\n"


signed main(){
  cin.tie(0);	
  ios::sync_with_stdio(false);
  int n;
  string s;
  cin>>n>>s;
  int a[26]={0};
  rep(i,n){
    a[s[i]-'a']++;
  }
  int ans=1;
  rep(i,26){
    ans*=(a[i]+1);
    ans%=MOD;
  }
  cout<<ans-1<<endl;

  return 0;
}

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

Measured memory_bytes: 128
package main

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

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		log.Fatal(e)
	}
	return i
}

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

func asub(a, b int) int {
	if a > b {
		return a - b
	}
	return b - a
}
func main() {
	sc.Split(bufio.ScanWords)

	k := getInt()
	a := getInt()
	b := getInt()
	b = (b / k) * k
	if b >=a {
		out("OK")
	} else {
		out("NG")
	}
}


Measured memory_bytes: 1816
#include<stdio.h>
#include<math.h>
#define N 10000

int isprime(int);

int main(){
  int i,j;
  int n;
  int number[N];
  int result=0;

  scanf("%d",&n);
  
  for(i=0;i<n;i++){
    scanf("%d",&number[i]);
  }
  
  for(i=0;i<n;i++){
    if(isprime(number[i])==1){
      result++;
    }  
  }
  
  printf("%d\n",result);
  
  return 0;
}

int isprime(int x){
  int i;

  if(x==2){
    return 1;
  }

  if(x<2||x%2==0){
    return 0;
  }

  i=3;
  while(i<=sqrt(x)){
    if(x%i==0){
      return 0;
    }
    i+=2;
  }

  return 1;
}

Measured memory_bytes: 632
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<map>
#include<cstring>
using namespace std;
const int MAXN=5e5+5;
const int M=MAXN*100;
int n,q,tot;
int a[MAXN];
int T[MAXN*4],lson[M],rson[M],c[M];

int build(int l,int r)
{
    int root=tot++;
    c[root]=0;
    if(l!=r)
    {
        int mid=(l+r)>>1;
        lson[root]=build(l,mid);
        rson[root]=build(mid+1,r);
    }
    return root;
}

int update(int root,int pos,int val)
{
    int newroot=tot++,tmp=newroot;
    c[newroot]=c[root]+val;
    int l=1,r=n;
    while(l<r)
    {
        int mid=(l+r)>>1;
        if(pos<=mid)
        {
            lson[newroot]=tot++;
            rson[newroot]=rson[root];
            newroot=lson[newroot];
            root=lson[root];
            r=mid;
        }else
        {
            rson[newroot]=tot++;
            lson[newroot]=lson[root];
            newroot=rson[newroot];
            root=rson[root];
            l=mid+1;
        }
        c[newroot]=c[root]+val;
    }
    return tmp;
}

int query(int root,int pos)
{
    int ret=0;
    int l=1,r=n;
    while(pos<r)
    {
        int mid=(l+r)>>1;
        if(pos<=mid)
        {
            r=mid;
            root=lson[root];
        }else
        {
            ret+=c[lson[root]];
            root=rson[root];
            l=mid+1;
        }
    }
    return ret+c[root];
}

int main()
{
	cin>>n>>q;
        tot=0;
        for(int i=1;i<=n;i++)
            scanf("%d",&a[i]);
        T[n+1]=build(1,n);
        map<int,int> mp;
        for(int i=n;i>=1;i--)
        {
            if(mp.find(a[i])==mp.end())
            {
                T[i]=update(T[i+1],i,1);
            }else
            {
                int tmp=update(T[i+1],mp[a[i]],-1);
                T[i]=update(tmp,i,1);
            }
            mp[a[i]]=i;
        }
        while(q--)
        {
            int l,r;
            scanf("%d%d",&l,&r);
            printf("%d\n",query(T[l],r));
        }

    return 0;
}


Measured memory_bytes: 253000
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; 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 ll long long
#define pb(a) push_back(a)

ll mod = 1e09 + 7;

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

  ll n, k;
  cin >> n >> k;
  ll a[n], b[n];
  map<ll, ll> mp;

  REP(i, n){
    cin >> a[i] >> b[i];
    mp[a[i]] += b[i];
  }

  ll cnt = 0;

  REP(i, mp.size()){
    cnt += mp[i];
    if(k <= cnt){
      cout << i << endl;
      return 0;
    }
  }

}


Measured memory_bytes: 8064
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int x,a,b,c,d;
  cin >>x>>a>>b;
  c=x-a;
  d=x-b;
  if(c<0)c*=-1;
  if(d<0)d*=-1;
 
  if(c>=d)cout<<"B"<<endl;
  if(c<d)cout<<"A"<<endl;
}


Measured memory_bytes: 256
import java.util.*;

class Main
{
    //I don't want to make here.
    public static int hight=0;
    public static int node=0;
    public static int degree=0, depth=0;

    //Tree class
    static class Tree
    {
	int id;
	Tree parent = null;
	Tree left = null;
	Tree right = null;

	public void setId(int n)
	{
	    id = n;
	}

	public void setParent(Tree p)
	{
	    parent = p;
	}

	public void setDegree(Tree l, Tree r)
	{
	    left=l;
	    right=r;
	}

    }

    public static void main(String args[])
    {
	Tree[] t = new Tree[1000];
	Tree tree = new Tree();
	int n;
	int id, left, right;

	Scanner read = new Scanner(System.in);
	int length;
	int idFlag, leftFlag, rightFlag;
	int i, j, k;

	//initialization
	for(i=0; i<1000; i++)t[i] = new Tree();

	//make tree
	n = read.nextInt();
	t[0].id=-1;

	length=0;
	for(i=0; i<n; i++)
	    {
		id = read.nextInt();
		left = read.nextInt();
		right = read.nextInt();

		//find id, left and right
		idFlag=-1;
		leftFlag=-1;
		rightFlag=-1;
		for(j=0; j<length; j++)
		    {
			if(t[j].id==id)idFlag=j;
			if(t[j].id==left && t[j].id!=-1)leftFlag=j;
			if(t[j].id==right && t[j].id!=-1)rightFlag=j;

			if(idFlag!=-1 && leftFlag!=-1 && rightFlag!=-1)break;
		    }

		//if it cannot find id, make node
		if(idFlag==-1){
		    t[length].setId(id);
		    idFlag=length;
		    length++;
		}
		if(leftFlag==-1){
		    t[length].setId(left);
		    leftFlag=length;
		    length++;
		}
		if(rightFlag==-1){
		    t[length].setId(right);
		    rightFlag=length;
		    length++;
		}

		//set parent
		t[leftFlag].setParent(t[idFlag]);
		t[rightFlag].setParent(t[idFlag]);
		
		//set degree
		t[idFlag].setDegree(t[leftFlag], t[rightFlag]);
	    }

	//print
	//for(i=1; i<length; i++)if(t[i].id!=-1)System.out.println(t[i].id+" "+t[i].parent.id+" ");//+t[i].left.id+" "+t[i].right.id);
	for(i=0; i<length; i++)if(t[i].parent==null)break;
	System.out.println("Preorder");
	preorder(t[i]);
	System.out.println("");

	System.out.println("Inorder");
	inorder(t[i]);
	System.out.println("");

	System.out.println("Postorder");
	postorder(t[i]);
	System.out.println("");
    }


    //method
    static void preorder(Tree t)
    {
	if(t.id!=-1)
	    {
		System.out.print(" "+t.id);
		preorder(t.left);
		preorder(t.right);
	    }
    }

    static void inorder(Tree t)
    {
	if(t.id!=-1)
	    {
		inorder(t.left);
		System.out.print(" "+t.id);
		inorder(t.right);
	    }
    }
    
    static void postorder(Tree t)
    {
	if(t.id!=-1)
	    {
		postorder(t.left);
		postorder(t.right);
		System.out.print(" "+t.id);
	    }
    }
}

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

typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<P,ll> PLL;
typedef pair<P,P> PP;
typedef vector<ll> VECLL;
typedef vector<P> VECP;
typedef priority_queue<P,VECP,greater<P> > PQP;
typedef priority_queue<ll, VECLL, greater<ll> > PQll;

#define rep(i,a,n) for(ll i = a;i < n;i++)   
#define rrep(i,a,n) for(ll i = n; i >= a;i--)
#define index_check(i,n) if(i > n-1 || i < 0) continue; 
#define LINF (ll)1e18
#define INF (int)1e9
#define fs first
#define sc second

const ll MOD = 1e9+7;

ll mod_pow(ll a, ll x, ll n){
    ll res = 1,index = 0;
    ll pow_list[30] = {};
    ll temp = x;
    pow_list[0] = a;

    while(temp){
        if(temp % 2) res = (res * pow_list[index]) % n; 

        pow_list[index+1] = (pow_list[index] * pow_list[index]) % n;
        index++;
        temp /= 2;
    }

    return res;
}


int main(){
    ll n,m;
    cin >> n >> m;
    cout << mod_pow(n,m,(ll)1e9+7) << endl;
    return 0;
}



Measured memory_bytes: 3104
' Imports System.Collections.Generic
' Imports System.Text.RegularExpressions

Class Main
    Public Shared Sub Main()
        Dim N As Integer
        N = Console.ReadLine()
        Dim S, T As String
        Dim arr() As String
        arr = Split(Console.ReadLine())
        S = arr(0) : T = arr(1)
        Dim ans As String = String.Empty
        For i As Integer = 0 To N - 1
            ans = ans & S(i) & T(i)
        Next
        Console.WriteLine(ans)
        Return
    End Sub
End Class


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

int main() {
    int n;
    cin >> n;
    vector<int> x(n);
    rep(i,n) {
        cin >> x[i];
    }
    double ave = accumulate(x.begin(), x.end(), 0.) / n;
    int iave = ave + 0.5;
    int ans = 0;
    for (auto& v : x) {
        ans += (v - iave) * (v - iave);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repr(i, a, b) for(int i = a; i >= b; i--)
#define int long long
#define all(a) a.begin(), a.end()
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e18;

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    rep(i, 0, n){
        cin >> a[i];
    }
    int m = n + (n - 1) * k;
    int cnt = 0;
    bool f = true;
    vector<P> d; 
    vector<int> c;
    rep(i, 0, n){
        if(a[i] >= k + 1) continue;
        int tmp = k + 1 - a[i];
        if(a[i] < k / 2 + 1) f = false;
        cnt += tmp;
        d.push_back({tmp, i});
    }
    if(cnt > k) f = false;
    
    rep(i, 0, n){
        int tmp = 0;
        while(a[i] > k / 2 + 1 && cnt < k && (tmp + 1) <= (k + 1) / 2){
            a[i]--;
            cnt++;
            tmp++;
        }
        if(tmp) d.push_back({tmp, i});
    }
    sort(d.rbegin(), d.rend());
    rep(i, 0, d.size()){
        rep(j, 0, d[i].first){
            c.push_back(d[i].second);
        }
    }
    assert(cnt >= k);
    vector<int> cc = c;
    rep(i, 0, c.size()){
        if(i % 2 == 0) cc[i] = c[i / 2];
        else cc[i] = c[(c.size() + 1) / 2 + i / 2];
    }
    rep(i, 0, cc.size() - 1){
        if(cc[i] == cc[i + 1]) f = false;
    }
    if(!f){
        cout << -1 << endl;
        return 0;
    }
    vector<int> ans;
    int now = 0, pre = -1;
    rep(i, 0, k){
        rep(j, 0, n){
            if(j != cc[i] && j != pre){
                ans.push_back(j);
            }
        }
        ans.push_back(cc[i]);
        pre = cc[i];
    }
    rep(i, 0, n){
        if(i != pre){
            ans.push_back(i);
        }
    }
    cout << m << endl;
    for(int ii = 0; ii < ans.size(); ii++){
        if(ii) cout << ' ';
        cout << ans[ii] + 1;
    }
    cout << endl;
}

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

using namespace std;

//FILE *fi=freopen("1.txt","r",stdin);

int n,w,a[101],b[101];
long long d[101][100001];

void nhap()
{
    scanf("%d %d",&n,&w);
    for (int i=1;i<=n;++i)
    {
        scanf("%d %d",&a[i],&b[i]);
    }
}

void process()
{
    for (int j=1;j<=w;++j)
    {
        for (int i=1;i<=n;++i)
        {
            d[i][j]=d[i-1][j];
            if (j>=a[i])
            {
                d[i][j]=max(d[i][j],d[i-1][j-a[i]]+b[i]);
            }
        }
    }
    cout<<d[n][w];
}

int main()
{
    nhap();
    process();
    return 0;
}


Measured memory_bytes: 78336
#include <iostream>

int main() {
  int64_t a, b, n;
  std::cin >> a >> b >> n;
  int64_t x = n < b ? n : b - 1;
  int64_t ans = (a * x / b) - a * (x / b);
  std::cout << ans << std::endl;
  return 0;
}


Measured memory_bytes: 3640
n,k = map(int, input().split())
x = list(map(int, input().split()))

ans = float("inf")
for i in range(n-k+1):
  # 0の位置から移動し、i〜i+kまでのろうそくに火をつけた場合の移動時間について左右で確認し、最小を求める
  l = abs(x[i]) + abs(x[i]-x[i+k-1])
  r = abs(x[i+k-1]) + abs(x[i] - x[i+k-1])
  ans = min(ans, l, r)
print(ans)

Measured memory_bytes: 19992
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
#define rep(i, n) for (int i = 0, i##_len = (int)(n); i < i##_len; i++)
int main() {
    Int n, k, s;
    cin >> n >> k >> s;
    rep(i, k) {
        printf("%lld", s);
        if (i < n - 1) printf(" ");
    }
    for (Int i = k; i < n; i++) {
        if (s == 1000000000) {
            printf("%lld", s - 1);
        } else {
            printf("%lld", s + 1);
        }
        if (i < n - 1) printf(" ");
    }
    puts("");
}


Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
int main () {
	int n;
	cin >> n;
	string s;
	cin >> s;
	vector<int> v[10];
	for (int i = 0; i < n; i++) {
		v[s[i] - '0'].push_back(i);
	}
	int ans = 0;
	for (int i = 0; i < 1000; i++) {
		string ss = to_string(i);
		ss = string(3-ss.length(), '0') + ss;
		int k = 0;
		int inf = n+n;
		for (auto c: ss) {
			auto o = lower_bound(v[c-'0'].begin(), v[c-'0'].end(), k);
			if (o == v[c-'0'].end()) {
				k = inf;
				break;
			}
			k = (*o) + 1;
		}
		if (k != inf) ans++;
	}
	cout << ans << endl;
}

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

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    
    int n;
    cin >> n;
    vector<int> arr(n);
    for (int i = 0; i != n; ++i)
        cin >> arr[i];
    sort(arr.begin(), arr.end());
    
    if (n > 2)
    {
        vector<pair<int, int>> ans;
        int j = 1;
        while (j < n - 1 && arr[j] < 0)
        {
            ans.push_back({arr[n - 1], arr[j]});
            arr[n - 1] -= arr[j];
            ++j;
        }
        for (int i = j; i < n - 1; ++i)
        {
            ans.push_back({arr[0], arr[i]});
            arr[0] -= arr[i];
        }
        ans.push_back({arr[n - 1], arr[0]});
        cout << arr[n - 1] - arr[0] << '\n';
        for (auto x : ans)
            cout << x.first << ' ' << x.second << '\n';
    }
    else
    {
        cout << arr[1] - arr[0] << '\n';
        cout << arr[1] << ' ' << arr[0] << '\n';
    }
    
    return 0;
}

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

#ifdef ONLINE_JUDGE
#define freopen \
  if (0) freopen
#define cerr \
  if (0) cerr
#endif

#define fi first
#define se second

#define pb push_back
#define pp pop_back
#define mp make_pair

#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)

#define sqr(a) ((a)*1ll * (a))
#define sz(a) (int)a.size()
#define len(a) (int)a.length()
#define all(a) a.begin(), a.end()
#define nl '\n'

using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef pair<int, int> pi;

const int inf = (int)1e9 + 7;
const int mod = (int)1e9 + 7;
const ll linf = (ll)1e18 + 7;

map< pi, bool > visited;

void solve() {
  int n, m;
  int p, q, c;
  cin >> n >> m;
  
  map< pi, vector< pair< int, pi > > > g;
  rep(i, 1, m) {
    cin >> p >> q >> c;
    g[mp(p, c)].pb(mp(0, mp(q, c)));
    g[mp(q, c)].pb(mp(0, mp(p, c)));
    g[mp(p, c)].pb(mp(0, mp(q, -1)));
    g[mp(q, c)].pb(mp(0, mp(p, -1)));
    g[mp(p, -1)].pb(mp(1, mp(q, c)));
    g[mp(q, -1)].pb(mp(1, mp(p, c)));
  }

  vector<int> d(n + 1, inf);
  priority_queue< pair< int, pi >, vector< pair< int, pi > >, greater< pair< int, pi > > > queue;
  d[1] = 0;
  queue.push(mp(0, mp(1, -1)));
  while (!queue.empty()) {
    pair< int, pi > cur = queue.top();
    queue.pop();
    int cost = cur.first;
    int v = cur.second.first;
    int prev_c = cur.second.second;
    if (visited[mp(v, prev_c)]) continue;
    visited[mp(v, prev_c)] = true;
    for (auto next : g[mp(v, prev_c)]) {
      int new_cost = next.first;
      int to = next.second.first;
      int new_c = next.second.second;
      if (visited[mp(to, new_c)]) continue;
      queue.push(mp(cost + new_cost, mp(to, new_c)));
      d[to] = min(d[to], cost + new_cost);
    }
  }

  if (d[n] == inf) {
    cout << -1;
  } else {
    cout << d[n];
  }
}

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

  freopen(".in", "r", stdin);

  solve();

  return 0;
}


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

#define lld long long
#define pi pair<int,int>
#define pl pair<lld,lld>
#define mem0(x) memset(x,0,sizeof(x))
#define fillnum(x,n) fill(begin(x),end(x),n)
#define asort(x) sort(x.begin(),x.end())
#define dsort(x,t) sort(x.begin(),x.end(),greater<t>())

int main() {
    int N,R;
    cin >> N >> R;
    if (N >= 10) {
        cout << R << endl;        
    } else {
        cout << R + 100*(10-N) << endl;
    }
}

Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#define INIT(a) memset(a,0,sizeof(a))
using namespace std;

int main(){
  int n,r;
  int x1[10010],y1[10010],x2[10010],y2[10010];
  int imos[10010];

  while(cin >> n >> r,n){
    for(int i=0;i<n;i++)cin >> x1[i] >> y1[i] >> x2[i] >> y2[i];

    int area = 0;
    for(int i=0;i<=10000;i++){
      INIT(imos);
      for(int j=0;j<n;j++){
	if(x1[j]<=i && i<x2[j]){
	  imos[y1[j]]++; imos[y2[j]]--;
	}
      }
      for(int i=0;i<10000;i++)imos[i+1] += imos[i];
      for(int i=0;i<=10000;i++){
	if(imos[i])area++;
      }
    }

    cout << area << endl;

    if(r==2){
      int len = 0;
      for(int t=0;t<2;t++){
	for(int i=0;i<=10000;i++){
	  INIT(imos);
	  for(int j=0;j<n;j++){
	    if(x1[j]<=i && i<x2[j]){
	      imos[y1[j]]++; imos[y2[j]]--;
	    }
	  }
	  for(int i=0;i<10000;i++)imos[i+1] += imos[i];
	  for(int i=0;i<=10000;i++){
	    if(imos[i]){
	      if(i==0 || imos[i-1]==0)len++;
	      if(i==10000 || imos[i+1]==0)len++;
	    }
	  }
	}
	for(int i=0;i<n;i++){
	  swap(x1[i],y1[i]);
	  swap(x2[i],y2[i]);
	}
      }
      cout << len << endl;
    }
  }
}
      
  

Measured memory_bytes: 1364
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define vi vector<int>
#define pb push_back
#define INF 999999999
//#define INF (1LL<<59)

int main(){
	int n,m,a;
	while(cin>>n>>m>>a&&(n||m||a)){
		vector<pair<int,pii>> vp;
		rep(i,m){
			int h,p,q;
			cin>>h>>p>>q;
			vp.pb(make_pair(h,pii(p,q)));
		}
	
		sort(vp.rbegin(),vp.rend());
	
		for(auto e:vp){
			int l=e.second.first;
			int r=e.second.second;
		
			if(l==a)a = r;
			else if(r==a)a=l;
		}
		cout<<a<<endl;
	}
}

Measured memory_bytes: 3052
//xenowitz -- Jai Shree Ram
#include<bits/stdc++.h>
using namespace std;

#define fori(i,a,b) for (long int i = a; i <= b ; ++i)
#define ford(i,a,b) for(long int i = a;i >= b ; --i)
#define mk make_pair
#define mod 1000000007
#define pb push_back
#define eb emplace_back
#define vec vector<long long int>
#define ll long long
#define rnd mt19937_64 rng(chrono::high_resolution_clock::now().time_since_epoch().count())
#define pi pair<long long int,long long int>
#define sc second
#define fs first
#define stf shrink_to_fit

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  string s;
  cin >> s;

  int n = s.length();
  if (s[n-1] == 's') {
      cout << s << "es" << endl;
  } else {
      cout << s << "s" << endl;
  }
  return 0;
}


Measured memory_bytes: 3660
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
using ld = long double;
const ll ATCODER_AMARI = 1000000007; //10^9 + 7
const ll INF = 10000000000000;

//階乗関数　ATCODER_AMARIに注意
ll factorial(ll k){
  ll sum = 1;
  for(int i = 1 ; i < k + 1; i++) {
    sum *= i;
    //sum = sum % ATCODER_AMARI;
  }
  return sum;
}

int main() {
  string s;

  cin >> s;

  rep(i,s.size()) {
    cout << 'x';
  }

  cout << endl;
}



Measured memory_bytes: 3616
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;

public class Main {

    /**
     * @param args
     */
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        while(true){
            int w=sc.nextInt();
            int h=sc.nextInt();
            if(w+h==0)break;
            int[][] a = new int[h][w];
            for (int i = 0; i < a.length; i++) {
                String s = sc.next();
                for (int j = 0; j < a[i].length; j++) {
                    a[i][j]=s.charAt(j);
                }
            }
            int bs = 0,ws=0;
            for (int i = 0; i < a.length; i++) {
                for (int j = 0; j < a[i].length; j++) {
                    if(a[i][j]!='.')continue;
                    int[] res = rec(a,i,j);
                    if(res[1]==1){
                        bs+=res[0];
                    } else if(res[1]==2){
                        ws+=res[0];                        
                    }
                }
            }
            System.out.println(bs+" "+ws);
        }
    }
    static int[] v1 = {0,0,1,-1};
    static int[] v2 = {1,-1,0,0};
    static int[] rec(int[][] a,int h,int w){
        int[] res = new int[2];
        Queue<int[]>q = new LinkedList<int[]>();
        a[h][w]=-1;
        q.add(new int[]{h,w});
        while(!q.isEmpty()){
            int y = q.peek()[0];
            int x = q.poll()[1];
            res[0]++;
            for (int i = 0; i < v1.length; i++) {
                int yy = y + v1[i];
                int xx = x + v2[i];
                try {
                    a[yy][xx]*=1;
                } catch (Exception e) {
                    continue;
                }
                if(a[yy][xx]=='B'){
                    res[1]|=1;
                } else if(a[yy][xx]=='W'){
                    res[1]|=2;
                } else if(a[yy][xx]==-1){
                    continue;
                } else {
                    a[yy][xx]=-1;
                    q.add(new int[]{yy,xx});
                }
            }
        }
        return res;
    }
}

Measured memory_bytes: 28156
using System;
using System.Collections.Generic;
using System.Linq;

class D
{
	static void Main()
	{
		var h = Console.ReadLine().Split().Select(int.Parse).ToArray();
		var a = Console.ReadLine().Split().Select(double.Parse).ToArray();

		var q = PQ<double>.Create(a, true);
		for (var i = 0; i < h[1]; i++) q.Push(q.Pop() / 2);
		Console.WriteLine(q.Sum(x => (long)x));
	}
}

class PQ<T> : List<T>
{
	public static PQ<T> Create(T[] vs = null, bool desc = false)
	{
		var c = Comparer<T>.Default;
		return desc ?
			new PQ<T>(vs, (x, y) => c.Compare(y, x)) :
			new PQ<T>(vs, c.Compare);
	}

	Comparison<T> c;
	public T First => this[0];

	PQ(T[] vs, Comparison<T> _c)
	{
		c = _c;
		if (vs != null) foreach (var v in vs) Push(v);
	}

	void Swap(int i, int j) { var o = this[i]; this[i] = this[j]; this[j] = o; }
	void UpHeap(int i) { for (int j; i > 0 && c(this[j = (i - 1) / 2], this[i]) > 0; Swap(i, i = j)) ; }
	void DownHeap(int i)
	{
		for (int j; (j = 2 * i + 1) < Count;)
		{
			if (j + 1 < Count && c(this[j], this[j + 1]) > 0) j++;
			if (c(this[i], this[j]) > 0) Swap(i, i = j); else break;
		}
	}

	public void Push(T v)
	{
		Add(v);
		UpHeap(Count - 1);
	}
	public T Pop()
	{
		var r = this[0];
		this[0] = this[Count - 1];
		RemoveAt(Count - 1);
		DownHeap(0);
		return r;
	}
}


Measured memory_bytes: 34268
//omajinai c++
#include <iostream>
#include<cmath>
#include<vector>
#include <algorithm>
#include <limits>
#include <numeric>
#include <type_traits>
#include <map>
#include <string>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
constexpr auto mod = 1000000007;
using namespace std;
int main() {
	int n, m;
	cin >> n >> m;
	vector<int> s(m);
	vector<int> c(m);
	rep(i, m) {
		cin >> s[i] >> c[i];
	}
	vector<int > ans(n);
	rep(i, n) {
		ans[i] = -1;
	}

	int f = 0;//0 ok 1 ng
	
	rep(i, m) {
		if (ans[s[i]-1] == -1) {
			ans[s[i]-1] = c[i];
		}
		else if (ans[s[i]-1] != c[i]) {
			f = 1;
			break;
		}
	}
	if (n!=1&&ans[0] == 0) {
		f = 1;
	}

	if (f == 1) {
		cout << -1;

	}
	
	else if(n!=1){
		rep(i, n) {
			if (ans[i] == -1 && i != 0) {
				cout << 0;
			}
			else if (ans[i] == -1 && i == 0) {
				cout << 1;
			}
			else {
				cout << ans[i];
			}
		}
	}
	else {
		if (ans[0] == -1) {
			cout << 0;

		}
		else {
			cout << ans[0];

		}
	}
}





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

#define ll long long

using namespace std;

const int N = (int)400 + 7;
const int mod = (int)1e9 + 7;

ll dp[N][N];
ll dp1[N][N];
int a[N];
int n;

ll go(int l, int r) {
	ll &res = dp[l][r];
	if (res != -1) return res;
	res = 0;
	if (l == r) {
		return res = a[l];
	}
	dp1[l][r] = 1e18;
	for (int i = l; i < r; i++) {
		if ((go(l, i) + go(i + 1, r)) + dp1[l][i] + dp1[i + 1][r] < dp1[l][r]) {
			res = go(l, i) + go(i + 1, r);
			dp1[l][r] = res + dp1[l][i] + dp1[i + 1][r];
		}
	}
	return res;
}

main() {
	memset(dp, -1, sizeof dp);
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) {
		scanf("%d", &a[i]);
	}
	go(1, n);
	cout << dp1[1][n];
}


Measured memory_bytes: 2816
#include "bits/stdc++.h"
#define MAXN 100009
#define INF 1000000007
#define mp(x,y) make_pair(x,y)
#define all(v) v.begin(),v.end()
#define pb(x) push_back(x)
#define wr cout<<"----------------"<<endl;
#define ppb() pop_back()
#define tr(ii,c) for(__typeof((c).begin()) ii=(c).begin();ii!=(c).end();ii++)
#define ff first
#define ss second
#define my_little_dodge 46
#define debug(x)  cerr<< #x <<" = "<< x<<endl;
using namespace std;

typedef long long ll;
typedef pair<int,int> PII;
template<class T>bool umin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T>bool umax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
int F[MAXN],inv[MAXN],vis[MAXN];
int mod(ll x){
	while(x<0)
		x+=INF;
	return (x%INF);
}
int Fe(int x,int y){
	if(!y)
		return 1;
	int h=Fe(x,y/2);
	h=mod(h*1LL*h);
	if(y&1)
		h=mod(h*1LL*x);
	return h;	
}	
int C(int x,int y){
	if(x<y)
		return 0;
	return mod(F[x]*1LL*mod(inv[y]*1LL*inv[x-y]));
}
int main(){
	//~ #ifndef ONLINE_JUDGE
    //~ freopen("file.in", "r", stdin);
	//~ #endif	
	F[0]=inv[0]=1;
	for(int i=1;i<MAXN;i++){
		F[i]=mod(F[i-1]*1LL*i);
		inv[i]=Fe(F[i],INF-2);
	}
	int n,one,two;
	scanf("%d",&n);
	for(int i=1;i<=n+1;i++){
		int x;
		scanf("%d",&x);
		if(vis[x])
			one=vis[x]-1,two=n+1-i;
		vis[x]=i;	
	}
	for(int i=1;i<=n+1;i++)
		printf("%d\n",mod(C(n+1,i)-C(one+two,i-1)));
	return 0;
}


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

int gcd(int x, int y) {
    if(x < y) swap(x,y);
    while(y>0) {
        int r = x % y;
        x = y;
        y = r;
    }
    return x;
}

int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    for(int i=0; i<N; ++i) cin >> A[i];
    sort(A.begin(), A.end());

    int res = gcd(A[0], A[1]);
    for(int i=2; i<N; ++i) {
        res = min(res, gcd(A[0], A[i]));
    }
    cout << res << endl;
}

Measured memory_bytes: 640
#include<iostream>
#include<vector>
#include<cmath>
#include<iomanip>
using namespace std;

int main(){
  int n, r, diff = 20;
  while(std::cin >> r >> n, r){
    vector<int> hl(50, 0), hr(50, 0);
    for (int i = 0; i < n; i++) {
      int xl, xr, h;
      std::cin >> xl >> xr >> h;
      for (int j = xl; j < xr; j++) {
        hr[j + diff] = max(hr[j + diff], h);
      }
      for (int j = xl + 1; j <= xr; j++) {
        hl[j + diff] = max(hl[j + diff], h);
      }
    }
    double ans = 1e9;
    for (int i = -r + 1; i < r; ++i) {
      ans = min(ans, min(hr[i + diff], hl[i + diff]) +
                r - sqrt(r*r - i*i));
    }
    std::cout << setprecision(12) << fixed << ans << std::endl;
  }
  return 0;
}

Measured memory_bytes: 1268
import java.util.HashMap;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		final char[] alp = "abcdefghijklmnopqrstuvwxyz".toCharArray();

		String S = sc.next();
		char[] input = S.toCharArray();

		HashMap<Character, Integer> abcMap = new HashMap<Character, Integer>();
		for (char c : alp) {
			abcMap.put(c, 0);
		}

		for (char c : input) {
			int value = abcMap.get(c);
			abcMap.put(c, ++value);
		}
		for (char c : abcMap.keySet()) {
			if (abcMap.get(c) == 0) {
				System.out.print(c);
				return;
			}
		}
		System.out.print("None");

	}
}


Measured memory_bytes: 25556
d,n = map(int, input().split())

if d ==0:
    if n!=100:
        print(n)
    else:
        print(101)

elif d ==1:
    if n!=100:
        print(100*n)
    else:
        print(10100)

else:
    if n!=100:
        print(10000*n)
    else:
        print(1010000)

Measured memory_bytes: 9168
#include <iostream>
#include <vector>
constexpr int P = 998244353 , V = 1000000000000000000 % P, INV2 = (P + 1) / 2;
int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    int n;
    std::cin >> n;
    std::vector<int> f{1};
    auto work = [&]() {
        std::vector<std::vector<int>> e(n);
        std::vector<int> c(n);
        int m;
        std::cin >> m;
        for (int i = 0; i < m; ++i) {
            int u, v;
            std::cin >> u >> v;
            --u;
            --v;
            if (u > v)
                std::swap(u, v);
            e[u].push_back(v);
        }
        for (int i = n - 1; i >= 0; --i) {
            std::vector<bool> vis(e[i].size() + 1);
            for (int v : e[i])
                if (c[v] <= int(e[i].size()))
                    vis[c[v]] = true;
            while (vis[c[i]])
                ++c[i];
        }
        std::vector<int> g;
        for (int i = 0, j = V; i < n; ++i, j = 1ll * j * V % P) {
            if (c[i] >= int(g.size()))
                g.resize(c[i] + 1);
            g[c[i]] = (g[c[i]] + j) % P;
        }
        std::vector<int> h;
        for (int i = 0; i < int(f.size()); ++i) {
            for (int j = 0; j < int(g.size()); ++j) {
                if ((i ^ j) >= int(h.size()))
                    h.resize((i ^ j) + 1);
                h[i ^ j] = (h[i ^ j] + 1ll * f[i] * g[j]) % P;
            }
        }
        f = h;
    };
    work();
    work();
    work();
    std::cout << f[0] << "\n";
    return 0;
}

Measured memory_bytes: 4816
#include <algorithm>
#include <bitset>
#include <complex>
#include <cstdio>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)n; ++i)
#define FOR(i, a, b) for(int i = a; i < (int)b; ++i)

typedef long long ll;

const int Inf = 1e9;
const double EPS = 1e-9;

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

int lcm(int a, int b) {
    return a * b / gcd(a, b);
}

int bitCount(long bits) {
    bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
    bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
    bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f);
    bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff);
    return (bits & 0x0000ffff) + (bits >>16 & 0x0000ffff);
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m;
    int maxi = 0;
    cin >> n;
    map<string, int> p;
    rep(i, n) {
      string s;  cin >> s;
      p[s]++;
    }
    cin >> m;
    rep(i, m) {
      string s;  cin >> s;
      p[s]--;
    }
    for (auto itr = p.begin(); itr != p.end(); itr++) {
      maxi = max(maxi, itr->second);
    }

    cout << maxi << '\n';
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <algorithm>
#include <queue>
#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define INF 99999999
using namespace std;

typedef int Weight;
struct Edge {
  int src, dst;
  Weight weight;
  Edge(int src, int dst, Weight weight) :
    src(src), dst(dst), weight(weight) { }
};
bool operator < (const Edge &e, const Edge &f) {
  return e.weight != f.weight ? e.weight > f.weight : // !!INVERSE!!
    e.src != f.src ? e.src < f.src : e.dst < f.dst;
}
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
typedef vector<Weight> Array;
typedef vector<Array> Matrix;

typedef pair<Weight, int> Result;
Result visit(int p, int v, const Graph &g) {
  Result r(0, v);
  FOR(e, g[v]) if (e->dst != p) {
    Result t = visit(v, e->dst, g);
    t.first += e->weight;
    if (r.first < t.first) r = t;
  }
  return r;
}
Weight diameter(const Graph &g) {
  Result r = visit(-1, 0, g);
  Result t = visit(-1, r.second, g);
  return t.first; // (r.second, t.second) is farthest pair
}

int main(){
	int i,V,E,s,t,e;
	//for(scanf("%d",&T);T;putchar(--T?' ':'\n')){
		scanf("%d",&V);
		Graph g(V);
		for(;V>1;V--)scanf("%d%d%d",&s,&t,&e),g[s].push_back(Edge(s,t,e)),g[t].push_back(Edge(t,s,e));
		printf("%d\n",diameter(g));
	//}
}

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

int main() {
  using graph= vector<vector<int>>;

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

  graph G(N, vector<int>(N));
  for(int i=0; i<M; i++){
    int x,y;
    cin >> x >> y;
    x--; y--; // 1-indexed -> 0-indexed

    G.at(x).at(y)= 1;
    G.at(y).at(x)= 1;
  }

  vector<int> path;
  for(int i=0; i<N; i++){
    path.push_back(i);
  }

  int cnt= 0;
  do{
    bool connected= true;
    for(int i=0; i<N-1; i++){
      if( G.at(path.at(i)).at(path.at(i+1))==0 ){
        connected= false;
        break;
      }
    }
    if(connected) cnt++;
  } while( next_permutation(path.begin()+1, path.end()) );

  cout << cnt << endl;
}

Measured memory_bytes: 256
import heapq

def main():
    N = int(input())
    a = list(map(int, input().split()))

    left = [0] * (3 * N)
    right = [0] * (3 * N)

    tmp = 0
    q = []
    for i in range(N):
        heapq.heappush(q, a[i])
        tmp += a[i]
    left[N-1] = tmp
    for i in range(N, 2*N):
        heapq.heappush(q, a[i])
        left[i] = left[i-1] + a[i] - heapq.heappop(q)
    
    tmp = 0
    q = []
    for i in range(N*3-1, N*2-1, -1):
        heapq.heappush(q, -a[i])
        tmp += a[i]
    right[2*N] = tmp
    for i in range(2*N-1, N-1, -1):
        heapq.heappush(q, -a[i])
        right[i] = right[i+1] + a[i] + heapq.heappop(q)
    
    ans = left[N-1] - right[N]
    for i in range(N, 2*N):
        ans = max(ans, left[i]-right[i+1])
    print(ans)

if __name__ == "__main__":
    main()

Measured memory_bytes: 38148
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<map>
#include<stack>
#include<cmath>
using namespace std;
int main() {
	int n, k,ans=0,originally=1;
	cin >> n >> k;
	for (int i = 1; i <= n; i++) {
		ans = min(originally * 2, originally + k);
      originally=min(originally*2,originally+k);
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<cstdio>
using namespace std;

int main() {
	int a;
	while (scanf("%d", &a), a) {
		int s = 0;
		bool x = false;
		for (int b = 0; b < a; b++) {
			int c;
			scanf("%d", &c);
			if (c)s++;
			if (c > 1)x = true;
		}
		if (!x)puts("NA");
		else printf("%d\n", s+1);
	}
}

Measured memory_bytes: 3184
#include<iostream>
#include<cstdio>
#include<cstring>
inline void check_max(int a,int &b){if(a>b)b=a;}
typedef long long ll;
const int N=100100;
int a[N],b[N];
int n,m;
ll sum;
bool check()
{
	if(sum%((ll)n*(n+1)/2))return 0;
	sum/=(ll)n*(n+1)/2;
	
	int cnt=0;
	for(int i=1;i<=n;i++)
		if((m-b[i])%n)return 0;
		else cnt+=(m-b[i])/n;
	return cnt==m && cnt<=sum && ((sum-cnt)%n==0);
}
int main()
{
	scanf("%d",&n),sum=0;
	for(int i=1;i<=n;i++)scanf("%d",a+i),sum+=a[i];
	m=b[1]=a[1]-a[n];
	for(int i=2;i<=n;i++)check_max(b[i]=a[i]-a[i-1],m);
	printf("%s\n",check()?"YES":"NO");
	return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define f(i,a,b) for(int i(a);i<b;i++)
#define rep(i,n) for(int i(0);i<n;i++)
#define fast  ios_base::sync_with_stdio(0); cin.tie(0);
#define pres(x) cout<<fixed; cout<<setprecision(x);
#define open freopen("input.txt","r",stdin) ; freopen("output.txt","w",stdout);
#define watch(x) cout<<(#x)<<" is "<<x<<"\n";
#define out(x) cout<<x<<"\n";
#define mod 1000000007

int32_t main(){
	
	fast;
	//open;

	int n,x;
	cin>>n;
	int a[n] , b[n];
	rep(i,n){
		cin>>x;
		a[i] = x; b[i] = x;
	}
	sort(a,a+n);
	rep(i,n){
		if(b[i] == a[n-1])cout<<a[n-2]<<"\n";
		else cout<<a[n-1]<<"\n";
	}


	return 0;
}

Measured memory_bytes: 4736
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string s;
    cin >> s;
    if (s[2]==s[3]&&s[4]==s[5])
    {
    	cout << "Yes\n";
    }
    else
    {
    	cout << "No\n";
    }
    return 0;
}

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

//repetition
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

//container util
#define all(x) (x).begin(),(x).end()

//typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;


//conversion
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}


ll H,W;
string board[410];
ll m[410][410];

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

void dfs(int y, int x, ll mark){
  m[y][x] = mark;
  rep(dir,4){
    int nx = x + dx[dir];
    int ny = y + dy[dir];

    if(nx >= 0 && nx < W  &&
       ny >= 0 && ny < H  &&
      m[ny][nx] == -1     && board[y][x] != board[ny][nx]){
      dfs(ny,nx,mark);
    }
  }
  return;
}

int main(){
  //input
  cin >> H >> W;
  rep(i,H) cin >> board[i];

  //初期化
  rep(i,H)rep(j,W) m[i][j] = -1;
  ll cnt = 0;

  //どのグループに属するか深さ優先探索
  rep(i,H)rep(j,W){
    if(m[i][j] == -1){
      dfs(i,j,cnt);
      cnt++;
    }
  }

  // グループごとの要素数を把握
  vector< pair<ll,ll> > p(cnt+2,make_pair(0,0));
  rep(i,H)rep(j,W){
    if(board[i][j] == '#')      p[m[i][j]].second++;
    else if(board[i][j] == '.') p[m[i][j]].first++;
  }

  // グループの黒要素  * 白要素を答えに加算
  ll  ans = 0;
  rep(i,p.size()){
    ans += p[i].first * p[i].second;
  }


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


Measured memory_bytes: 21760
#include <bits/stdc++.h>
using namespace std;
#define int long long
using ll=long long;
using vi=vector<int>;
using vl=vector<long long>;
using pii=pair<int,int>;
using pll=pair<long long,long long>;
#define ITR(i,c) for(auto i=begin(c);i!=end(c);++i)
#define FORE(x,c) for(auto &x:c)
#define REPF(i,a,n) for(int i=a,i##_len=(int)(n);i<i##_len;++i)
#define REP(i,n) REPF(i,0,n)
#define REPR(i,n) for(int i=(int)(n);i>=0;--i)
#define ALL(c) begin(c),end(c)
#define RALL(c) rbegin(c),rend(c)   // c++14
#define SZ(c) ((int)c.size())
#define EXIST(c,x) (c.find(x)!=end(c))
#define OUTOFRANGE(y,x,h,w) (y<0||x<0||y>=h||x>=w)
#define dump(...)
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
#define INF (1001001001)
#define INFLL (1001001001001001001ll)
template<class T> ostream& operator << (ostream &os,const vector<T> &v) {
    ITR(i,v) os << *i << (i==end(v)-1 ? "" : "\n"); return os; }
template<class T> istream& operator >> (istream &is,vector<T> &v) {
    ITR(i,v) is >> * i; return is; }
template<class T> istream& operator >> (istream &is, pair<T,T> &p) {
        is >> p.first >> p.second; return is; }
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}
//------------------------------------------------------------------------------
struct before_main_function {
    before_main_function() {
        #ifdef int
            #undef INF
            #define INF INFLL
            #define stoi stoll
        #endif
        cin.tie(0);ios::sync_with_stdio(false);
        cout<<setprecision(15)<<fixed;
    }
} before_main_function;
//------------------------------------------------------------------------------

signed main() {
    int N;
    cin>>N;
    vi a(N*3);
    cin>>a;
    sort(ALL(a));
    int sum=0;
    REPF(i,N,3*N) sum+=a[i],i++;
    cout<<sum<<endl;
    return 0;
}


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



int main(){
	string s, t;
	cin >> s >> t;
	t.pop_back();
	if (s == t) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 3600
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

int main(void){
	int a,b,c;
	cin >> a >> b >> c;
	cout << (a+b+c-max(a,max(b,c))) << endl;
	return 0;
}


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

int main() {
  string S;
  int cnt=0;
  cin >> S;
  
  if(S.at(0) == 'o') cnt++;
  if(S.at(1) == 'o') cnt++;
  if(S.at(2) == 'o') cnt++;
  
  cout << 700 + cnt*100 << endl;

  return 0;
}

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

using namespace std;

const int N = 200000 + 77;
int n , A , a[N];
char S[N];
int main() {
   scanf("%d %s" , & n , S + 1);
   for(int i = 1;i <= n;++ i)
      a[i] = a[i - 1] + (S[i] == '.');
   A = min(a[n] , n - a[n]);
   for(int i = 1;i <= n;++ i)
      A = min(A , i - a[i] + (a[n] - a[i]));
   printf("%d\n" , A);
   return 0;
}


Measured memory_bytes: 1280
#include<iostream>
using namespace std;
int main(){
    int H,W,i,x,t;
    i=0;
    x=0;
    t=0;
    string a="";
    string b="";
    while(1){
        cin>>H>>W;
        if(H==0&&W==0) break;
        while(x<W){
            a+="#";
            x+=1;
        }
        while(t<W-2){
            b+=".";
            t+=1;
        }
        while(i<H){
            if(i==0|| i==H-1) cout<<a<<endl;
            else cout<<"#"<<b<<"#"<<endl;
            i+=1;
        }
        cout<<endl;
        t=0;
        x=0;
        i=0;
        a="";
        b="";
    }
}




Measured memory_bytes: 3188
#include<stdio.h>
#include<vector>
#include<string>
#include<array>
#include <utility>
#include <algorithm>
#include <map> // pair
#include <iostream>
using namespace std;

int main(){
    int n;
    scanf("%d", &n);

    char s[n+5];
    for (int i= 0; i < n+1; i++) scanf("%c", &s[i]);

    //printf("%c", s[0]);
    //cout << s[0];

    int judge = (n/2) + 1;
    int count = 0;
    bool res = false;

    for (int i = 1; i < n+1; i++){
        //cout << s[i] << endl;
        if(s[i] == 'R'){
            count++;
        }
        if(count == judge){
            res = true;
            break;
        }
    }

    if(res) printf("Yes");
    else printf("No");
}

Measured memory_bytes: 256