akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
vector<int> keta(ll N){//各桁の数をもつ配列を返す
    vector<int> k;
    while(N>0){
        int r = N%10;
        N = N/10;
        k.push_back(r);
    }
    return k;
}
/*bool keta9(ll N){//Nの最上位以外の各桁が全て９かどうか
    vector<int> k;
    
    while(N>10){
        int r = N%10;
        N = N/10;
        if(r != 9) return false;
    }
    return true;
}*/
int main() {
  ll N;
  cin >> N;
  string S;
  S = to_string(N);
  bool flag = true;//Nがc999999..99型の数かどうか
  for(int i = 1;i<S.size();i++){
      if(S[i] != '9'){
          flag = false;
          break;
      }
  }
  if(flag){
      ll ans = int(S[0]-'1') + 1 + 9*(S.size()-1);
      cout << ans << endl;
      return 0;
  }
else{
 vector<int> k = keta(N);
 /*for(int i = 0;i<k.size();i++){
     cout << k[i] <<endl;
 }*/
  k[k.size()-1] -= 1;
 for(int i = 0;i<k.size()-1;i++){
     k[i] = 9;
 }
 ll sum = 0;
  
 for(int i = 0;i<k.size();i++){
     sum += k[i];
 }
 cout << sum <<endl;
}
}

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

using namespace std;

using ll = long long int;
using ld = long double;

using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vvvl = vector<vvl>;
using vd = vector<double>;
using vvd = vector<vd>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vs = vector<string>;

const int INF = (1 << 30) - 1;
const ll INF64 = ((ll)1 << 62) - 1;
const double PI = 3.1415926535897932384626433832795;

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

int gcd(int x, int y) { return y ? gcd(y, x % y) : x; }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
int lcm(int x, int y) { return x / gcd(x, y) * y; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }

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

	string s;
	cin >> s;

	string res = "";
	int n = s.size() - 8;
	for (int i = 0; i < n; i++) {
		res += s[i];
	}
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
#define rep(i, a, n) for (ll i = (a); i < (n); i++)
#define debug(x) cerr << #x << ": " << x << endl;
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;}

int main() {
    string s;
    cin >> s;
    deque<char> dq;
    ll ans = 0;
    for (auto c : s) {
        if (!dq.empty() && dq.back() != c) {
            dq.pop_back();
            ans += 2;
        }
        else dq.push_back(c);
    }
    cout << ans << endl;
}

Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <map>

#define reps(i,s,n) for(int (i) = (s); (i) < (n); (i)++)
#define rep(i,n) reps(i,0,n)
using namespace std;
using ll = long long;

int main(){
    int n;
    cin >> n;
    vector<int> p(n);
    rep(i,n) cin >> p[i];
    int m = p[0]; 
    int ans = 1;
    reps(i,1,n){
        if(m > p[i]){
            m = p[i];
            ans++;
        }
    }

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

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
struct Edge {
    int to;     // 辺の行き先
    int weight; // 辺の重み
    Edge(int t, int w) : to(t), weight(w) { }
};
using Graph = vector<vector<Edge>>;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reprep(i,j,h,w) rep(i,h)rep(j,w)
#define rrep(i,m, n) for(int i = m; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define aall(x,n) (x).begin(),(x).begin()+(n)
#define VEC(type,name,n) std::vector<type> name(n);rep(i,n)std::cin >> name[i];
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define sum accumulate
#define keta fixed<<setprecision
#define vvector(name,typ,m,n,a)vector<vector<typ> > name(m,vector<typ> (n,a))
#define vvvector(name,t,l,m,n,a) vector<vector<vector<t> > > name(l, vector<vector<t> >(m, vector<int>(n,a)));
typedef long long ll;
const int INF = 2000000000;
const long INF64 = 1000000000000000ll;
const ll MOD = 1000000007LL;
typedef unsigned int uint;
int main(){
  int a,b;
  std::cin >> a>>b;
  std::cout << 6-a-b << std::endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ALL(c) (c).begin(),(c).end()
#define EACH(i,c) for(auto i=(c).begin();i!=(c).end();++i)
using namespace std;
#define int long long

const string YES = "YES";
const string NO = "NO";

void solve(long long N, std::vector<long long> p){
    for(int i = 0; i < N; ++i) for(int j = 0; j < N; ++j) {
        vector<int> q = p;
        swap(q[i], q[j]);
        bool f = true;
        for(int k = 0; k < N; ++k) {
            f = f && q[k] == (k + 1);
        }
        if (f) {
            cout << YES << endl;
            return;
        }
    }
    cout << NO << endl;
}

signed main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> p(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&p[i]);
    }
    solve(N, std::move(p));
    return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
  long W, H, x, y;
  cin >> W >> H >> x >> y;
  double area = static_cast<double>(W * H);
  bool half = 2 * x == W && 2 * y == H;
  cout << (area / 2.0) << " " << (half ? 1 : 0) << endl;
  
  return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;


namespace Test1 {

    


    class ClassMain {

       
        public static void Main(String[] args) {
            string line;
            while ((line = Console.ReadLine()) != null) {
                int[] ints = line.Split(' ').Select(int.Parse).ToArray();
                int n = ints[0];
                if(n==0){break;}
                int m = ints[1];
                int[] sugoroku = new int[n + 1];
                for (int i = 1; i <= n; i++) {
                    int masu = int.Parse(Console.ReadLine());
                    sugoroku[i] = masu;
                }
                int cnt = 0;
                int currentPosi = 1;
                for (int i = 0; i < m; i++) {
                    cnt++;
                    int me = int.Parse(Console.ReadLine());
                    currentPosi += me;
                    if (currentPosi >= n) { break; }
                    currentPosi += sugoroku[currentPosi];
                    if (currentPosi >= n) { break; }
                }
                for (int i = 0; i < m - cnt; i++) {
                    Console.ReadLine();
                }
                Console.WriteLine(cnt);
            }
        }

        
    }



    
}

Measured memory_bytes: 6024
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)
#define N 100000
typedef long long ll;
#define ALL(v) (v).begin(),(v).end()
#define SZ(x) int(x.size())
#define OUT(a) cout<<(a)<<endl
typedef pair<int,int> P;
#define INF 1000000000
const int MAX = 1000000;
const int MOD = 1000000007;


int main(){
	int r;
    cin>>r;
    OUT(r*r);
	return 0;
}

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

signed main(){
       int n;
       cin >> n;
       int a,b,s[n],ball;
       
       ball=0;
       for(int i=0;i<n;i++){
           cin >>a>>b;
           s[i]=a+b;
           ball+=b;
       }
       sort(s,s+n,greater<int>());
       int ans=0;
       for(int i=0;i<n;i+=2){
           ans+=s[i];
       }
       cout << ans-ball;
    return 0;
}

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

int main(){
    ll a,b;
    cin>>a>>b;
    ll sum;
    ll presum;

    for(ll i=0;i<1e5;++i){
        sum=i*8/100;
        presum=i*10/100;
        if(sum==a and presum==b){
            cout<<i<<endl;
            return 0;
        }
    }
    cout<<-1<<endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<climits>
#include<iostream>
#include<sstream>
#include<utility>
#include<map>
#include<vector>
#include<queue>
#include<algorithm>
#include<set>
#include<stack>
#include<functional>
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
int N;
vector<ll>a,b;


int main()
{
	cin>>N;
	for(int i=0;i<N;i++)
	{
		ll x;
		cin>>x;
		a.push_back(x);
	}
	for(int i=0;i<N;i++)
	{
		ll x;
		cin>>x;
		b.push_back(x);
	}
	sort(a.begin(),a.end());
	sort(b.begin(),b.end());
	ll res=0;
	for(int i=0;i<=28;i++)
	{
		ll x=1LL<<i;
		vector<ll>aa,bb;
		for(int j=0;j<N;j++)
		{
			aa.push_back(a[j]%(x<<1));
			bb.push_back(b[j]%(x<<1));
		}
		sort(aa.begin(),aa.end(),greater<ll>());
		sort(bb.begin(),bb.end());

		ll c1=0,c2=0,c3=0,c4=0;
		ll cc=0;
		for(int j=0;j<N;j++)
		{
			while(c1<N&&bb[c1]<1*x-aa[j])c1++;
			while(c2<N&&bb[c2]<2*x-aa[j])c2++;
			while(c3<N&&bb[c3]<3*x-aa[j])c3++;
			while(c4<N&&bb[c4]<4*x-aa[j])c4++;
			cc+=c4-c3+c2-c1;
		}
		res|=(cc%2)<<i;
	}
	cout<<res<<endl;
}


Measured memory_bytes: 8404
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AOJHelloWorld1
{
    class Program
    {
        static void Main(string[] args)
        {
            for (int i = 1; i > 0; i++)
            {
                string[] str = Console.ReadLine().Split(' ');
                int a = int.Parse(str[0]);
                int b = int.Parse(str[2]);
                string op = str[1];

                if (op == "+")
                {
                    Console.WriteLine(a + b);
                }
                else if (op == "-")
                {
                    Console.WriteLine(a - b);
                }
                else if (op == "*")
                {
                    Console.WriteLine(a * b);
                }
                else if (op == "/")
                {
                    Console.WriteLine(a / b);
                }
                else { break; }
            }        
        }
    }
}




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

using namespace std;

int main()
{
    int n;
    cin >>n;
    int h[n];
    for(int i=0;i<n;i++){
        cin >> h[i];
    }
    bool flg=true;
    for(int i=0;i<(n-1);i++){
        if(h[n-1-i]<h[n-2-i]){
            h[n-i-2]--;
        }
        if(h[n-1-i]<h[n-2-i])flg=false;
    }
    if(flg)puts("Yes");
    else puts("No");
    return 0;
}


Measured memory_bytes: 640
// READ & UNDERSTAND
// ll, int overflow, array bounds, memset(0)
// special cases (n=1?), n+1 (1-index)
// do smth instead of nothing & stay organized
// WRITE STUFF DOWN

#include <bits/stdc++.h>

using namespace std;

#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end() 
#define MOD 1000000007

typedef long long ll;
typedef pair <int, int> ii;
typedef pair <ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef long double ld;

ll INF=LLONG_MAX;

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    //freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
	char a,b;
	cin >> a >> b;
	if(a==b)cout << '=';
	else if(a>b)cout << '>';
	else cout << '<';
}	


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

int main()
{
  int h, m, s;

  cin >> s;
  m = s / 60;
  s %= 60;
  h = m / 60;
  m %= 60;
  cout << h << ":" << m << ":" << s << endl;

  return 0;
}


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

int main(){
  int a,b,c;
 cin >> a >> b >> c;
 if(a<b){
   if(a < c && c < b){
     cout << "Yes";
   }else{
     cout << "No";
   }
 }else if(a > b){
   if(b < c && c < a){
     cout << "Yes";
   }else{
     cout << "No";
   }
 }
return 0;
}



Measured memory_bytes: 256
n=int(input())
t,a=map(int,input().split())
h=list(map(int,input().split()))
m=100000
ans=0
for i in range(n):
  if abs((t-h[i]*0.006)-a) < m:
    m=abs((t-h[i]*0.006)-a)
    ans=i+1
print(ans)


Measured memory_bytes: 3060
#include <stdio.h>
#include <math.h>
#define inf 1000000007
typedef long long ll;

ll fact(ll n) {
	ll m;
	if (n == 0) return 1;
	n = n%inf;
	m = fact(n - 1)%inf;
	return ((n * (m)) % inf);
}
int main() {
	ll n, m;
	scanf("%lld %lld", &n, &m);
	if (fabs(n - m) > 1) { printf("0"); }
	else if (fabs(n - m) == 1){	printf("%lld", (fact(n) * fact(m))%inf);}
	else { printf("%lld", (2 * fact(n) * fact(n))%inf); }
	return 0;
}

Measured memory_bytes: 3328
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		String[] phrases = {scanner.next(), scanner.next(), scanner.next()};

		Arrays.sort(phrases);
		if(("5".equals(phrases[0]) && "5".equals(phrases[1]))
									&& "7".equals(phrases[2])) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}
	}
}


Measured memory_bytes: 23764
#include <iostream>
#include <math.h>
using namespace std;


int main(void){

    int n, i, j;


    while(1){

        int count=0;
        int judge=0;

        cin >> n ;
        if(n == 0)break;


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

            judge = 0;

            for(j = 2; j <= sqrt(i); j++){

                // 素数ではないときjudgeに1を入れる。
                if(i%j == 0){
                    judge = 1;
                    break;
                }

            }

            if(judge == 0){
                count++;
            }

        }

        cout << count <<endl;

    }



    return 0;   


}

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

#define ll long long

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

    int n, d;
    cin >> n >> d;

    vector<int> arr[n+1];

    int c;
    for (int i = 1; i<=n; i++){
        for (int j = 1; j<=d; j++){
            cin >> c;
            arr[i].push_back(c);
        }
    }


    float mul = 0;
    int ans = 0;
    for (int i = 2; i<=n; i++){
        for (int j = 1; j<i; j++){
            mul = 0;
            for (int z = 0; z<d; z++){
                mul += pow(arr[i][z] - arr[j][z], 2);
            }
            mul = sqrt(mul);
            if (floor(mul) == mul){
                ans++;
            }
        }
    }

    cout << ans << endl;

    return 0;
}



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

using namespace std;

char s[2];
void query(long long x) { printf("? %lld\n",x); fflush(stdout); scanf("%s",s); }

void work(int MAX) {
	long long l = MAX, r = MAX * 10 - 1, mid, res = r;
	while(l <= r) {
		mid = l + r >> 1;
		query(mid * 10);
		if(s[0] == 'Y') {
			if(mid < res) res = mid;
			r = mid - 1;
		} else {
			l = mid + 1;
		}
	}
	printf("! %lld\n", res);
}

int main() {
	query(1e9);
	if(s[0] == 'Y') {
		int cur = 1e9;
		for(int i = 9; i; --i, cur /= 10) {
			query(cur - 1);
			if(s[0] == 'N') break;
		}
		printf("! %d\n", cur);
		return 0;
	}
	for(int cur = 1000000000, bit = 10; true; cur /= 10, --bit) {
		query(cur);
		if(s[0] == 'Y') {
			work(cur);
			break;
		}
	}
	return 0;
}

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

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

fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}

fn main() {
    let i : Vec<i64> = read_vec();
    let x = i[0];
    let y = i[1];
    let ans = run(x,y,0);
    println!("{}",ans);
}

fn run(x:i64,y:i64,count:i64) -> i64{
    if x > y {
        count
    } else {
        run(x * 2,y,count + 1)
    }
}

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

int main(){
  int k;
  int a,b;
  cin >> k >> a >> b ;
  for(int i=a; i<=b; i++){
    if(i%k == 0){
      cout << "OK" << endl;
      return 0;
    }
  }
  cout << "NG" << endl;
}


Measured memory_bytes: 3620
#include<bits/stdc++.h>
#define ll long long
#define MOD 1000000007
#define FOR(i, a, b) for(int i=a; i<b; i++)
#define REP(i, n) for(int i=0; i<n; i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using namespace std;

int N;
ll W, w[110], v[110];
ll dp[110][100100] = {0};

int main() {
    cin >> N >> W;
    REP(i, N) cin >> w[i] >> v[i];

    for (int i=0; i<N; i++) {
        for (int sum_w=0; sum_w <= W; sum_w++) {
            // i番目の品物を選ぶ場合
            if (sum_w - w[i] >= 0) {
                chmax(dp[i+1][sum_w], dp[i][sum_w - w[i]] + v[i]);
            }
            // 選ばない場合
            chmax(dp[i+1][sum_w], dp[i][sum_w]);
        }
    }
    cout << dp[N][W] << endl;
}


Measured memory_bytes: 79360
import static java.lang.Math.*;
import static java.util.Arrays.*;
import java.util.*;

import java.io.*;

public class Main {
	
	void solve() {
		int T = sc.nextInt();
		for (; T--> 0;) {
			int N = sc.nextInt();
			int D = sc.nextInt();
			solve2(N,D);
		}
	}
	
	void solve2(int N, int D) {
		int ans = 0;
		for (int i = 1; i < N; i++) {
			int x = D;
			int y = (127 ^ x);
//			tr(x, y);
			ans += 127;
			D = y;
		}
		ans += D;
		out.println(ans);
	}
	
	static void tr(Object... os) { System.err.println(deepToString(os)); }
	static void tr(int[][] as) { for (int[] a : as) tr(a); }

	void print(int[] a) {
		if (a.length > 0) out.print(a[0]);
		for (int i = 1; i < a.length; i++) out.print(" " + a[i]);
		out.println();
	}

	public static void main(String[] args) throws Exception {
		new Main().run();
	}

	MyScanner sc = null;
	PrintWriter out = null;
	public void run() throws Exception {
		sc = new MyScanner(System.in);
		out = new PrintWriter(System.out);
		for (;sc.hasNext();) {
			solve();
			out.flush();
		}
		out.close();
	}

	class MyScanner {
		String line;
		BufferedReader reader;
		StringTokenizer tokenizer;

		public MyScanner(InputStream stream) {
			reader = new BufferedReader(new InputStreamReader(stream));
			tokenizer = null;
		}
		public void eat() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					line = reader.readLine();
					if (line == null) {
						tokenizer = null;
						return;
					}
					tokenizer = new StringTokenizer(line);
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
		}
		public String next() {
			eat();
			return tokenizer.nextToken();
		}
		public String nextLine() {
			try {
				return reader.readLine();
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		public boolean hasNext() {
			eat();
			return (tokenizer != null && tokenizer.hasMoreElements());
		}
		public int nextInt() {
			return Integer.parseInt(next());
		}
		public long nextLong() {
			return Long.parseLong(next());
		}
		public double nextDouble() {
			return Double.parseDouble(next());
		}
		public int[] nextIntArray(int n) {
			int[] a = new int[n];
			for (int i = 0; i < n; i++) a[i] = nextInt();
			return a;
		}
	}
}

Measured memory_bytes: 9552
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int inf = 1e9;
const ll INF = 1e18;
const double pi = 3.14159265358979323846;
#define rep(i, n) for (int i = 0; i < n; i++)
using Graph = vector<vector<int>>;
using pint = pair<int, int>;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int dxx[8] = {1, 1, 1, 0, 0, -1, -1, -1}, dyy[8] = {-1, 0, 1, -1, 1, -1, 0, 1};

int main() {
    int n, m;
    cin >> n >> m;
    Graph g (n);
    vector<int> chk (n, 0);
    rep (i, m) {
        int x, y;
        cin >> x >> y;
        g[--x].push_back (--y);
        chk[y]++;
    }
    queue<int> q;
    rep (i, n) if (chk[i] == 0) q.push (i);

    int dp[n] = {};
    while (!q.empty()) {
        int now = q.front();
        q.pop();
        for (auto next : g[now]) {
            if (!chk[next]) continue;
            chk[next]--;
            if (!chk[next]) {
                q.push (next);
                dp[next] = dp[now] + 1;
            }
        }
    }
    int ans = 0;
    rep (i, n) ans = max (ans, dp[i]);
    cout << ans << "\n";
}

Measured memory_bytes: 6528
import java.util.Scanner;

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

        // 入力(a b c d)
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int d = sc.nextInt();

        int s1 = a * b;
        int s2 = c * d;
        System.out.println((s1 >= s2) ? s1 : s2);
        sc.close();
    }
}

Measured memory_bytes: 35724
#include<bits/stdc++.h>
#define int long long
#define mod 1000000007
using namespace std;
int n,f[1000005]={1},s[1000005]={1},ans=0;
signed main(){
	scanf("%lld",&n);
	if(n==1)return puts("1"),0;
	for(int i=1;i<n;i++){
		f[i]=f[i-1]+(i>=3?s[i-3]:0);
		s[i]=s[i-1]+f[i];
		f[i]%=mod;
		s[i]%=mod;
		//cout<<f[i]<<endl;
		if(i<n-1)ans+=((n-1)*(n-1)%mod+min(i+2,n-1))*f[i],ans%=mod;
	}
	printf("%lld\n",(ans+n*f[n-1]%mod+(n-1)*(n-1)+1+(n>2))%mod);
}

Measured memory_bytes: 15872
#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <utility>
using namespace std;
using ll = long long;
 
int main() {
	int n;
	cin >> n;
	vector <int> a(n);
	for(int i=0;i<n;i++) cin >> a[i];
	int count =0;
	for(int i=0;i<n;i++) {
		if (a[i] != i+1) {
			count++;
		}
	}
	if (count <=2) {
		cout << "YES" << endl;
	} else {
		cout << "NO" << endl;
	}
	return 0;
}


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

typedef long long ll;

#define vi std::vector<int>
#define vl std::vector<ll>
#define in(x, a, b) a <= x && x <= b;
#define tern(b, o1, o2) b ? o1 : o2
#define floop(n) for(int i = 0; i < n; ++i)
#define print(x) std::cout << x << std::endl;

const ll INF = 1e18;

int main()
{
    int N, K, i, min=1001, p, res=0;
    std::cin >> N >> K;
    vi price(1000, 0);

    for(i = 0; i < N; ++i)
    {
        std::cin >> p;
        if(p < min)
            min = p;
        
        price[p-1]++;
    }

    for(i = min; i < 1001; ++i)
    {
        if(price[i-1] == 0)
            continue;
        
        while(price[i-1] > 0 && K > 0)
        {
            K--;
            res += i;
            price[i-1]--;
        }

        if(K == 0)
        {
            print(res);
            break;
        }
    }

    return 0;
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
//#include<iostream>
//#include<cstdio>
//#include<stdlib.h>
//#include<string.h>
//#include<algorithm>
using namespace std;
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define READ freopen("in.txt","r",stdin)
#define WRITE freopen("out.txt","w",stdout);
#define pb push_back
#define mem(arr,val) memset(arr,val,sizeof(arr))
#define sf(x) scanf("%d",&x)
#define sf2(x,y) scanf("%d %d",&x,&y)
#define sf3(x,y,z) scanf("%d %d %d",&x,&y,&z)
#define sl(x) scanf("%lld",&x)
#define sl2(x,y) scanf("%lld %lld",&x,&y)

#define sl3(x,y,z) scanf("%lld %lld %lld",&x,&y,&z)
#define sd(x) scanf("%lf",&x);
#define pLL pair<long long,long long>
#define pDB pair<double,double>
#define ff first
#define sn second
#define PRINT_CASE  printf("Case %d: ",tc++)
#define PRINT_CASENL  printf("Case %d:\n",tc++)
//#define mx 100005
#define lnd tree[ind<<1]
#define rnd tree[(ind<<1)+1]
#define cnd tree[ind]
#define lndp b,(b+e)>>1,(ind<<1)
#define rndp ((b+e)>>1)+1,e,(ind<<1)+1
#define IN(a,x,y) (a>=x && a<=y)
#define popcountL __builtin_popcountll
#define popcount __builtin_popcount
/// int other=mask^((1<<n)-1);
typedef long long ll;
typedef long long int lln;
typedef pair<int,int> pii;
ll INF=1<<28;
//typedef long long lld;
const double PI=acos(-1.0);
//int fx[]={1,-1,0,0}; //direction array
//int fy[]={0,0,1,-1};
int dir[4][2]={1,0,-1,0,0,-1,0,1};
int knight[8][2]={1,2,1,-2,2,1,2,-1,-1,2,-1,-2,-2,1,-2,-1};
const long double EPS=1e-7;
//#define INF 10000

struct compare
{
  bool operator()(const pair<int,pii>& l, const pair<int,pii>& r)
  {
      if(l.ff==r.ff)
      {
          return l.sn.ff>r.sn.ff;
      }
      return l.ff<r.ff;
  }
};
// bool operator<(pair<int,pii> l, pair<int,pii> r)
//  {
//      if(l.ff==r.ff)
//      {
//          cout<<"ok "<<endl;
//          return l.sn.ff<r.sn.ff;
//      }
//      return l.ff>r.ff;
//  }

/////////////////////////////////////template sesh/////////////////////////////////////////////////////

///code goes from here
const int mx=300015;
///
int mod=1e9+7;
ll arr[mx];
int main()
{
//    SPEED;
    int t,tc=1;
    t=1;
    while(t--)
    {
        int n;
        sf(n);
        for(int i=0;i<n;i++)
        {
            sl(arr[i]);
        }
        ll sum=0;
        ll ans=0;
        for(int i=n-1;i>=0;i--)
        {
            ans+=((sum*arr[i])%mod);
            ans%=mod;
            sum+=arr[i];
            sum%=mod;
        }

        cout<<ans<<endl;

    }



    return 0;
}



Measured memory_bytes: 5208
#include <bits/stdc++.h>
//#pragma GCC optimize ("Ofast")

using namespace std;
#define ms(x,a) memset(x,a,sizeof x)
typedef long long ll;
typedef pair<int,int> pii;
const int mod=1e9+7,seed=131,MAXN=2e5+1;

ll a[MAXN],b[MAXN];

int main(){
    cin.tie(0)->sync_with_stdio(0);
    int n,m; ll k; cin >> n >> m >> k;
    for (int i=1;i<=n;++i) cin >> a[i];
    for (int i=1;i<=m;++i) cin >> b[i];
    ll ta=0,tb=0,pb=0,ans=0;
    for (int i=1;i<=m;++i){
        if (tb+b[i]<=k) tb+=b[i], pb++;
        else break;
    }
    ans=pb;
    for (int i=1;i<=n;++i){
        ta+=a[i]; if (ta>k) break;
        while (ta+tb>k){
            tb-=b[pb]; pb--;
        }
        ans=max(ans,i+pb);
    }   
    cout << ans << '\n';
}

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

use text_io::*;
use proconio::*;
use std::collections::*;
use std::process::exit;
use std::cmp::*;
use itertools::Itertools;

fn main() {
    let a: usize = read!();
    let b: String = read!();
    let b = b.chars().collect_vec();
    let mut sum:usize = 0;
    let mut ans:usize = 0;
    let mut c:usize = 0;
    let mut d:usize = 0;
    for i in 0..b.len() {
        for j in 0..i {
            if b[i]==b[j] {
               c=1;
            }
        }
        for j in i+1..b.len() {
            if b[i]==b[j] {
               d=1;
            }
        }
        sum=sum-c+d;
        c=0;
        d=0;
        if ans<sum {
            ans=sum;
        }
    }
    println!("{}",ans)
}

Measured memory_bytes: 2164
n,w = map(int,input().split())

dp = [[0]*(w+1) for _ in range(n+1)]

for i in range(1,n+1):
    weight,value = map(int,input().split())
    for j in range(w+1):
        if j < weight:
            dp[i][j] = dp[i-1][j]
        else:
            dp[i][j] = max(dp[i-1][j],dp[i-1][j-weight]+value)

print(dp[-1][-1])

Measured memory_bytes: 119916
import java.io.*;

public class Main {
	public static void main(String[] args) throws Exception {
		int[] p = new int[101];int m=1;
		BufferedReader bf =new BufferedReader(new InputStreamReader(System.in));
		String t;
		for(int i=0;i<=100;i++)p[i]=0;
		while((t=bf.readLine())!=null)p[Integer.parseInt(t)]++;
		for(int i=1;i<=100;i++)if(p[m]<p[i])m=i;
		m=p[m];for(int i=1;i<=100;i++)if(p[i]==m)System.out.println(i);
	}
}

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

#define fi first
#define se second

const int N = 100100;

using namespace std;

int n, m;
int a[N];

int main()
{
        ios_base::sync_with_stdio(0);

        //freopen("input.txt", "r", stdin);
        //freopen("output.txt", "w", stdout);

        cin >> n >> m;
        long long res = 0;
        for(int i = 1; i <= n; i++){
                cin >> a[i];
                int s = a[i] + a[i - 1];
                res += max(0, s - m);
                s = min(s, m);
                a[i] = s - a[i - 1];
        }
        cout << res << "\n";
}


Measured memory_bytes: 640
// #include "testlib.h"
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define endl '\n'
#define Endl '\n'
#define fi first
#define ii pair<ll,ll>
#define se second
#define double long double
#define mod 1000000007
#define popcount __builtin_popcountll
const double PI = acos(-1.0);
using namespace std;
#define MXN 3005
int n;
int cnt[66];
ll m[66];
int main(){
    m[0] = 1;
    for(int i=1;i<=60;i++){
        m[i] = 2 * m[i-1];
        m[i]%=mod;
    }
    cin>>n;
    for(int i=0;i<n;i++){
        ll x;
        scanf("%lld", &x);
        for(int j=0;j<60;j++){
            if(x&(1ll<<j))cnt[j]++;
        }
    }
    ll amid = 0;
    for(int i=0;i<60;i++){
        ll _1 = cnt[i];
        ll _0 = n-cnt[i];
        ll x = m[i];
        amid+=((_1*_0)%mod*x);
        amid%=mod;
    }
    cout<<amid<<endl;
}


Measured memory_bytes: 256
// AOJ 3127 Gag
// 2020.1.14 bal4u

#include <stdio.h>

typedef long long ll;

#define gc() getchar_unlocked()

int in() {   // 非負整数の入力
	int n = 0, c = gc();
	do n = 10 * n + (c & 0xf); while ((c = gc()) >= '0');
	return n;
}

int main()
{
	int N; ll s;
	
	N = in();
	s = -(ll)N*(N+1)/2;
	while (N--) s += in();
	printf("%lld\n", s);
	return 0;
}



Measured memory_bytes: 2112
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#include <cassert>
#include <fstream>

using namespace std;

int main() {
    
    int n, a, b, c;
    cin >> n >> a >> b >> c;
    
    int cost = 1e9;
    int na, nb, nc;
    
    vector<int> l(n);
    
    for (int i = 0; i < n; ++i)
    {
        cin >> l[i];
    }
    
    for (int i = 0; i < (1 << n); ++i)
    {
        int used = 0;
        int a_count = 0;
        na = 0;
        for (int j = 0; j < n; ++j)
        {
            if ((i >> j) & 1)
            {
                na += l[j];
                a_count += 10;
            }
        }
        
        for (int j = 0; j < (1 << n); ++j)
        {
            used = i;
            nb = 0;
            int b_count = 0;
            
            bool cbf = 0;
            for (int k = 0; k < n; ++k)
            {
                if ((j >> k) & 1)
                {
                    if (((used >> k) & 1))
                    {
                        cbf = 1;
                        break;
                    }
                    nb += l[k];
                    b_count += 10;
                }
            }
            
            if (cbf)
            {
                continue;
            }
            
            for (int k = 0; k < (1 << n); ++k)
            {
                used = i | j;
                nc = 0;
                int c_count = 0;
                bool ccf = 0;
                
                for (int m = 0; m < n; ++m)
                {
                    if ((k >> m) & 1)
                    {
                        if (((used >> m) & 1))
                        {
                            ccf = 1;
                            break;
                        }
                        nc += l[m];
                        c_count += 10;
                    }
                }
                
                if (ccf)
                {
                    continue;
                }
                
                
                if (a_count < 10 || b_count < 10 || c_count < 10)
                {
                    continue;
                }
                
                cost = min(cost, (abs(a - na) + abs(b - nb) + abs(c - nc) + a_count + b_count + c_count - 30));
                
            }
        }
        
    }
    
    cout << cost << endl;
        
    
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstdio>
#include <functional>
#include <algorithm>
#include <vector>
#include <stack>
#include <cmath>
#include <climits>
#include <bitset>
#include <array>
using namespace std;
typedef long long ll;

int V, Mod;
vector<vector<int>*> *es;
vector<int> *par;
vector<ll> *dp0, *dp1;

void dfs1(int u, int p)
{
	par->at(u) = p;
	if (p >= 0) es->at(u)->erase(find(es->at(u)->begin(), es->at(u)->end(), p));
	for (auto v : *(es->at(u))) dfs1(v, u);
}
ll dfs2(int u)
{
	dp0->at(u) = 1L;
	for (auto v : *(es->at(u))) dp0->at(u) = dp0->at(u) * (dfs2(v) + 1) % Mod;
	return dp0->at(u);
}
void dfs3(int u)
{
	auto W = es->at(u)->size();
	auto x = new vector<ll>(W + 1, 1); // x[i] = t[0]*...*t[i-1], x[i+1]=x[i]*t[i]
	auto y = new vector<ll>(W + 1, 1); // y[i] = t[i]*...*t[W-1], y[i]=y[i+1]*t[i]
	for (int i = 0; i < W; i++) x->at(i + 1) = x->at(i) * (dp0->at(es->at(u)->at(i)) + 1) % Mod;
	for (int i = W - 1; i >= 0; i--) y->at(i) = y->at(i + 1) * (dp0->at(es->at(u)->at(i)) + 1) % Mod;
	for (int i = 0; i < W; i++) dp1->at(es->at(u)->at(i)) = (dp1->at(u) + 1) * x->at(i) % Mod * y->at(i + 1) % Mod;
	for (int v : *(es->at(u))) dfs3(v);
}

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> V >> Mod;
	es = new vector<vector<int>*>();
	par = new vector<int>(V, 0);
	dp0 = new vector<ll>(V, 0);
	dp1 = new vector<ll>(V, 0);
	for (size_t i = 0; i < V; i++) es->push_back(new vector<int>());
	for (size_t i = 0; i < V - 1; i++)
	{
		int x, y; cin >> x >> y;
		es->at(x - 1)->push_back(y - 1);
		es->at(y - 1)->push_back(x - 1);
	}
	dfs1(0, -1);
	dfs2(0);
	dfs3(0);
	for (size_t u = 0; u < V; u++) cout << dp0->at(u) * (dp1->at(u) + 1) % Mod << endl;
    return 0;
}


Measured memory_bytes: 30324
#include <iostream>
#include<string>
using namespace std;
int main(){
   int A,B;
   cin>>A>>B;
   int sum=0;
    if(A>B){
        sum=2*A-1;
        
    }
    else if(A<B){
        sum=2*B-1;
    }
    else {
        sum=A+B;
    }
    cout<<sum<<endl;
}

Measured memory_bytes: 256
import bisect
n=int(input())
a=[int(i) for i in input().split()]
a.sort()
ans=[]
x=bisect.bisect_left(a, 0)
m=a[:x]
p=a[x:]

if n==2 and len(p)==2:
    print(p[1]-p[0])
    print(p[1],p[0])
    
    exit()
if m==[]:
    m+=[p[0]-p[-1]]
    ans+=[[p[0],p[-1]]]
    del p[0]
    del p[-1]

if p==[]:
    p+=[m[-1]-m[0]]
    ans+=[[m[-1],m[0]]]
    del m[-1]
    del m[0]

while len(p)!=1:

    m+=[m[0]-p[0]]
    ans+=[[m[0],p[0]]]
    del p[0]
    del m[0]
cnt=p[0]
for i in m:
    ans+=[[cnt,i]]
    cnt-=i
print(cnt)
for i,j in ans:print(i,j)


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

using namespace std;

int main(void) {
  int n, ans = 0, tmp = 0; cin >> n;
  
  int bf, af; cin >> af;
  for (int i = 0; i < n-1; i++) {
    bf = af; cin >> af;
    if (bf < af) {
      ans = max(tmp, ans);
      tmp = 0;
    } else {
      tmp++;
    }
  } 
  ans = max(tmp, ans);

  cout << ans << endl;

  return 0;
}

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

int main()
{
  string s,t;
  cin>>s>>t;
  int n=s.size();
  int m=t.size();
  if(n>m)
  {
    string temp=s;
    s=t;
    t=temp;
    int sw=n;
    n=m;
    m=sw;
  }
  vector<vector<int>>dp(n+1,vector<int>(m+1,0));
  for(int i=1;i<=n;i++)
  {
    for(int j=1;j<=m;j++)
    {
      if(s[i-1]==t[j-1])
        dp[i][j]=dp[i-1][j-1]+1;
      else
          dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
    }
  }
  string ans="";
  int i=n,j=m;
  while(i>0&&j>0)
  {
    if(s[i-1]==t[j-1])
    {
      ans=s[i-1]+ans;
      i--;
      j--;
    }
    else
    {
      if(dp[i-1][j]>dp[i][j-1])
        i--;
      else
        j--;
    }
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 38848
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v).begin(), (v).end()
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define DEBUG
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }
template<class T>void show(vector<T>v){for (int i = 0; i < v.size(); i++){cerr<<v[i]<<" ";}cerr<<"\n";}
typedef long long ll;

struct UnionFind
{
    vector<int> par;
   
    UnionFind(int n) : par(n,-1){}
    void init(int n) { par.assign(n,-1);}
 
    int root(int x){
        if(par[x]<0) return x;
        return par[x]=root(par[x]);
    }
 
    bool issame(int x, int y){
        return root(x)==root(y);
    }
    bool merge(int x, int y){
        x=root(x);
        y=root(y);
        if(x==y) return false;
        if(par[x]>par[y])swap(x,y);
        par[x]+=par[y];
        par[y]=x; //大きさが正になるよ
        return true;
    }
    int size(int x){
        return -par[root(x)];
    }
};


int x[100010],y[100010];
bool flag[100010];
map<int,int>mp;
int main(){

    int n,m;
    cin>>n>>m;

    for (int i = 0; i < n; i++)
    {
        mp[i]++;
    }
    for (int i = 0; i < m; i++)
    {
        cin>>x[i]>>y[i];
        x[i]--;
        y[i]--;
    }
   flag[0]=true;
   for (int i = 0; i < m; i++)
   {    
       if(flag[x[i]])flag[y[i]]=true;
       mp[x[i]]--;
       mp[y[i]]++;
       if(!mp[x[i]]) flag[x[i]]=false;
       

   }
   int cnt=0;
   for (int i = 0; i < n; i++)
   {
       if(flag[i]&&mp[i])cnt++;
   }
   
   cout<<cnt<<endl;
   
   
    
    return 0;
}

Measured memory_bytes: 5760
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn min (a: &i64, b: &i64)-> i64{
    if *a <= 0i64 {*b}
    else if *b <= 0i64  {*a}
    else if *a < *b {*a}
    else {*b}
}

fn abs (a: &i64, b: &i64) -> i64{
    if *a - *b <= 0 {*b - *a} else {*a - *b}
}

fn main(){
    input!{
        n: usize,
        l: [u64; n]
    }
    let mut ls = l.clone();
    ls.sort();
    let mut count = 0u64;
    for i in 0..n-2 {
        for j in i+1..n-1{
            for k in (j+1..n).rev(){
                if ls[i] + ls[j] > ls[k] {
                    count += k as u64 - j as u64;
                    break
                }
            }
        }
    }
    print!("{}", count);
}


Measured memory_bytes: 4352
#include <cstdio>
#include <algorithm>
#include <vector>
#include <numeric>

using namespace std;

int h, w;
char grid[116][116];
int level[116][116];
char trace[1000000];

void color(char ch, int n, int m, int l, vector<pair<int,int>> &v) {
    if (grid[n][m] && grid[n][m] != ch) {
        v.push_back({n, m});
        return;
    }
    if (grid[n][m] != ch || level[n][m] <= l) {
        return;
    }
    level[n][m] = min(level[n][m], l);
    trace[level[n][m]] = ch;
    color(ch, n+1, m, l, v);
    // color(ch, n-1, m, l, v);
    color(ch, n, m+1, l, v);
    // color(ch, n, m-1, l, v);
}

int bfs() {
    vector<pair<int,int>> qu;
    int cur_l = 1;
    color(grid[1][1], 1, 1, cur_l, qu);
    while (1) {
        cur_l++;
        vector<pair<int,int>> nqu;
        for (auto cur : qu) {
            int n = cur.first;
            int m = cur.second;
            color(grid[n][m], n, m, cur_l, nqu);
        }
        if (qu.empty()) {
            return level[h][w];
        }
        qu = nqu;
    }
}

int main() {
    //freopen("A.in", "r", stdin);
    while (scanf("%d%d", &h, &w) == 2) {
        fill(&grid[0][0], &grid[110][0], 0);
        fill(&level[0][0], &level[110][0], 0x3f3f3f3f);
        fill(begin(trace), end(trace), 0);
        for (int i = 1; i <= h; i++) {
            scanf("%s", &grid[i][1]);
        }
        bfs();
        int ans = 0;
        for (int i = 1; i <= level[h][w]; i++) {
            ans += trace[i] == '#';
        }
        printf("%d\n", ans);
    }
    return 0;
}

/*
...#.#
...#.#
###.##
...#.#
*/

Measured memory_bytes: 1280
#include <stdio.h>
int main(){
    int n,i,kin=100000;
    scanf("%d",&n);
    for(i=0;i<n;i++){
        kin*=1.05;
        if(kin%1000!=0){
            kin=kin-(kin%1000)+1000;
        }
    }
    printf("%d\n",kin);
    return 0;
}

Measured memory_bytes: 592
/*Shivam Bhalla */
/* f2016941@pilani.bits-pilani.ac.in */



#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cctype>
#include <algorithm>
#include <map>
#include <vector>
#include <list>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <iostream>
#include <string>
#include <cmath>
#include <cassert>
#include <bits/stdc++.h>
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL)
using namespace std;
long long maxv = 1e9;

int main() {
  int N;
  cin>>N;
  int maxi=INT_MIN;
  int indexi;
  int indexii;
  int maxii=INT_MIN;
  int A;
  for(int i=0;i<N;i++){
    cin>>A;
    if(A>=maxi){
      maxii=maxi;
      indexii=indexi;
      maxi=A;
      indexi=i;
    }
    else if(A>=maxii){
      maxii=A;
      indexii=i;
    }
  }
  for(int i=0;i<N;i++){
    if(i==indexi)
      cout<<maxii<<"\n";
    else
      cout<<maxi<<"\n";
  }
  return 0;
}


Measured memory_bytes: 1664
import pdb

n = int(raw_input())
count = 0
for x in xrange(n):
  target = int(raw_input())
  # pdb.set_trace()
  if target == 2:
    count += 1
  elif target < 3 or not target & 1:
    continue
  else:
    if pow(2, target - 1, target) == 1:
      count += 1

print count

Measured memory_bytes: 6868
#include<bits/stdc++.h>
using namespace std;
#ifndef ONLINE_JUDGE
#define dbg(x...) do { cout << "\033[32;1m " << #x << " -> "; err(x); } while (0)
void err() { cout << "\033[39;0m" << endl; }
template<template<typename...> class T, typename t, typename... A>
void err(T<t> a, A... x) { for (auto v: a) cout << v << ' '; err(x...); }
template<typename T, typename... A>
void err(T a, A... x) { cout << a << ' '; err(x...); }
#else
#define dbg(...)
#endif
typedef long long ll;
typedef pair<int,int> pi;
typedef vector<int> vi;
template<class T> using vc=vector<T>;
template<class T> using vvc=vc<vc<T>>;
template<class T> void mkuni(vector<T>&v)
{
    sort(v.begin(),v.end());
    v.erase(unique(v.begin(),v.end()),v.end());
}
template<class T>
void print(T x,int suc=1)
{
    cout<<x;
    if(suc==1) cout<<'\n';
    else cout<<' ';
}
template<class T>
void print(const vector<T>&v,int suc=1)
{
    for(int i=0;i<v.size();i++)
    print(v[i],i==(int)(v.size())-1?suc:2);
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin>>n;
    deque<int> q;
    bool f=0;
    for(int i=0,tmp;i<n;i++)
    {
        cin>>tmp;
        f^=1;
        if(i&1) q.push_back(tmp);
        else q.push_front(tmp);
    }
    vi ans;
    while(!q.empty())
    {
        ans.push_back(q.front());
        q.pop_front();
    }
    if(!f)
        reverse(ans.begin(),ans.end());
    print(ans);
}

Measured memory_bytes: 3960
s = input()
l = len(s)
s1 = s[:l//2]
s2 = s[l//2+1:]
l1 = len(s1)
l2 = len(s2)
#print(s1)
#print(s2)
ans = "Yes"
for i in range(l//2):
 #   print(s[i:i+1],s[l-1-i:l-i])
    if s[i:i+1] != s[l-1-i:l-i]:
        ans = "No"
"""
for i in range(l//4+1):
    print(s[i:i+1],s[(l-1)//2-1-i:(l-1)//2-i],i,i+1,(l-1)//2-1-i,(l-1)//2-i)
    if s[i:i+1] != s[(l-1)//2-1-i:(l-1)//2-i]:
        ans = "No"
for i in range(l//4+1):
    print(s[(l+3)//2+i-1:(l+3)//2+i],s[l-1-i:l-i],(l+3)//2+i-1,(l+3)//2+i,l-1-i,l-i)
    if s[(l+3)//2+i-1:(l+3)//2+i] != s[l-1-i:l-i]:
        ans = "No"
"""
for i in range(l1//2):
   # print(s1[i:i+1],s1[l1-1-i:l1-i])
    if s1[i:i+1] != s1[l1-1-i:l1-i]:
        ans = "No"
for i in range(l2//2):
 #   print(s2[i:i+1],s2[l1-1-i:l1-i])
    if s2[i:i+1] != s2[l1-1-i:l1-i]:
        ans = "No"
print(ans)

Measured memory_bytes: 3064
//             بسم الثالوث الاقدس

#include<iostream>	
#include<algorithm>
#include<cstdio>
#include<sstream>
#include<cmath>
#include<climits>
#include<string>
#include<iomanip>
#include<vector>
#include<map>
using namespace std;
//********************************************************************************************
//******************************************************************************************** 
/*
jesus help me.......
*/
typedef long long lld;
typedef char c;

				
bool prime(int x)
{
	if (x == 1)
		return false;
	else if (x == 2)
		return true;
	for (int i = 2; i*i <= x; i++)
	{
		if (x%i == 0)
			return false;

	}
	return true;
}
void fun2(int t)
{
	if (t == 1)
	{
		cout << "*";
		return;
	}
	cout << "*";
	return fun2(t - 1);
}

void fun(int s)
{
	map<int, int>asd;
	map<int, int>::iterator ir;
	ir = asd.begin();
	ir->first;
	if (s)
	{
		cout << s % 10 << endl;
		fun(s / 10);
		
	}
}
long long numb(long long i){
	if ( i == 2 || i == 1)
		return 1;
	else{
		long long n = i, z = 0;
		while (n>1){
			if (i%n == 0){
				z++;
			}
			n--;
		}
		return z;
	}

}

/*
jesus help me.......
jesus help me.......
jesus help me.......
*/

int main()
{
	std::ios_base::sync_with_stdio(0);
	cin.tie(NULL); cout.tie(NULL);
	
	int n;
	cin >> n;
	long long l = 2,m=1,t;
	if (n == 1)
	{
		cout << 1 << endl;
		return 0;
	}
		for (int i = 2; i <= n; i++)
		{
			t = l + m;
			l = m;
			m = t;
		}
		cout << t << endl;
	


	//system("pause");
	return 0;
}
/*
jesus help me.......
jesus help me.......
jesus help me.......
*/

Measured memory_bytes: 256