akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<cassert>
#define PB push_back
#define MP make_pair
#define sz(v) (in((v).size()))
#define forn(i,n) for(in i=0;i<(n);++i)
#define forv(i,v) forn(i,sz(v))
#define fors(i,s) for(auto i=(s).begin();i!=(s).end();++i)
#define all(v) (v).begin(),(v).end()
using namespace std;
typedef long long in;
typedef vector<in> VI;
typedef vector<VI> VVI;
in n,a;
in pw(in x, in b){
  in r=1;
  forn(z,b){
    if(r>n/x)
      return n+1;
    r*=x;
  }
  return r;
}
int main(){
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin>>n>>a;
  if(n==1){
    cout<<1<<endl;
    return 0;
  }
  in bst=n;
  for(in cd=1;cd<=40;++cd){
    in mn=1;
    in mx=n+2;
    in md;
    while(mx-mn>1){
      md=(mx+mn)/2;
      if(pw(md,cd+1)<n)
	mn=md;
      else
	mx=md;
    }
    in ta,tb;
    for(in ss=0;ss<=cd+1;++ss){
      ta=pw(mx-1,ss);
      tb=pw(mx,cd+1-ss);
      if(ta>n/tb || ta*tb>=n)
	bst=min(bst,mx*(cd+1-ss)+(mx-1)*ss+cd*a);
    }
  }
  cout<<bst<<endl;
  return 0;
}


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

#define int long long
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; }

signed main(){
	int n, k;
	cin >> n >> k;

	int a[100010];
	int idx = 0;
	for(int i = 0;i < n;i++){
		cin >> a[i];
		if(a[i] == 1) idx = i;
	}

	int ans = INT_MAX;
	for(int l = idx-k+1;l <= idx;l++){
		int r = l+k-1;
		if(0 <= l && r <= n-1){
			int tmp = (l+(k-1)-1)/(k-1);
			int rr = n-r-1;
			tmp += (rr+(k-1)-1)/(k-1);
			chmin(ans, tmp+1);
		}
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 1024
import sys
N,M=map(int,input().split())
data=[[0]*(N+1) for i in range(N+1)]
for i in range(M):
    A,B=map(int,input().split())
    data[A][B]=1
    data[B][A]=1
for i in range(1,N+1):
    data[i][i]=1
lst=[-1]*(N+1)
ddd=[]
for i in range(1,N+1):
    if lst[i]!=-1:
        continue
    else:
        lst[i]=0
        que=[i]
        count=[1,0]
        while que:
            h=[]
            for u in que:
                for j in range(1,N+1):
                    if data[u][j]==1:
                        continue
                    else:
                        if lst[j]==-1:
                            lst[j]=lst[u]^1
                            count[lst[j]]+=1
                            h.append(j)
                        elif lst[j]^lst[u]==0:
                            print(-1)
                            sys.exit()
            que=h
        ddd.append(count)
dp=[0]*(N+1)
dp[0]=1
for u in ddd:
    v=u[0]
    h=[0]*(N+1)
    for i in range(v,N+1):
        if dp[i-v]==1:
            h[i]=1
    v=u[1]
    for i in range(v,N+1):
        if dp[i-v]==1:
            h[i]=1
    dp=h
ans=0
for i in range(N+1):
    if dp[i]==1:
        if abs(N-2*ans)>abs(N-2*i):
            ans=i
qqq=N-ans
if qqq==0 or ans==0:
    print(N*(N-1)//2)
else:
    print(ans*(ans-1)//2+qqq*(qqq-1)//2)

Measured memory_bytes: 51672
#include<bits/stdc++.h>
using namespace std;
#define debug(x) cout<<#x<<' '<<x<<endl
#define read(x)  freopen("input.txt","r",stdin);
#define iter(x)  x.begin(),x.end()
#define int long long
#define ull unsigned int
#define endl '\n'
#define inf INT_MAX
#define mod 1000000007
map<int,int>m;
int n,d,a,b,c;
int solve(int n)
{
    if(n==0)
        return 0;
    if(n==1)
        return d;
    if(m.find(n)!=m.end())
        return m[n];
        int res=1e18;
      if(res/d>n) res=n*d;

    res=min(res,(n%2)*d+a+solve(n/2));
    if(n%2!=0)
    res=min(res,(2-(n%2))*d+a+solve(n/2+1));
    res=min(res,(n%3)*d+b+solve(n/3));
    if(n%3!=0)
    res=min(res,(3-(n%3))*d+b+solve(n/3+1));
    res=min(res,(n%5)*d+c+solve(n/5));
    if(n%5!=0)
    res=min(res,(5-(n%5))*d+c+solve(n/5+1));
    m[n]=res;
    return res;



}
main()
{
    //ios_base::sync_with_stdio(false);
    //cin.tie(NULL);
    //cout.tie(NULL);
    int t;
    cin>>t;
    while(t--)
    {
        m.clear();
        cin>>n>>a>>b>>c>>d;
        cout<<solve(n)<<endl;

    }


}


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

typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pair<int, int> > vii;
#define rrep(i, m, n) for(int (i)=(m); (i)<(n);  (i)++)
#define erep(i, m, n) for(int (i)=(m); (i)<=(n); (i)++)
#define  rep(i, n)    for(int (i)=0; (i)<(n);  (i)++)
#define rrev(i, m, n) for(int (i)=(n)-1; (i)>=(m); (i)--)
#define erev(i, m, n) for(int (i)=(n); (i)>=(m); (i)--)
#define  rev(i, n)    for(int (i)=(n)-1; (i)>=0; (i)--)
#define vrep(i, c)    for(__typeof((c).begin())i=(c).begin(); i!=(c).end(); i++)
#define  ALL(v)       (v).begin(), (v).end()
#define pb            push_back
#define mp            make_pair
template<class T, class S> inline bool minup(T& m, const S x){ return m>(T)x ? (m=(T)x, true) : false; }
template<class T, class S> inline bool maxup(T& m, const S x){ return m<(T)x ? (m=(T)x, true) : false; }

static const int    INF = 1000000000;
static const ll     MOD = 1000000007LL;
static const double EPS = 1E-10;

double a1x, a2x, a1y, a2y;
double b1x, b2x, b1y, b2y;

int main(int argc, char *argv[])
{
  while(cin >> a1x >> a1y >> a2x >> a2y >> b1x >> b1y >> b2x >> b2y){
    if(a1x > b2x || a2y < b1y || a2x < b1x || a1y > b2y) cout << "NO" << endl;
    else cout << "YES" << endl;
  }

  return 0;
}

Measured memory_bytes: 1228
#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define REP(i,a,b) for (int i = a; i <b; i++)
typedef long long ll;
#define int ll
typedef vector<int> vi;
typedef vector<long long> vl;
typedef pair<int,int> pi;
#define trace(x) cout<<#x<<"="<<x<<"\n";
#define sz(x) (int)(x.size())
#define mod 1000000007

template < typename F, typename S >
ostream& operator << ( ostream& os, const pair< F, S > & p ) {
    return os << "(" << p.first << ", " << p.second << ")";
}

template < typename T >
ostream &operator << ( ostream & os, const vector< T > &v ) {
    os << "{";
    typename vector< T > :: const_iterator it;
    for( it = v.begin(); it != v.end(); it++ ) {
        if( it != v.begin() ) os << ", ";
        os << *it;
    }
    return os << "}";
}

template < typename T >
ostream &operator << ( ostream & os, const set< T > &v ) {
    os << "[";
    typename set< T > :: const_iterator it;
    for ( it = v.begin(); it != v.end(); it++ ) {
        if( it != v.begin() ) os << ", ";
        os << *it;
    }
    return os << "]";
}

template < typename F, typename S >
ostream &operator << ( ostream & os, const map< F, S > &v ) {
    os << "[";
    typename map< F , S >::const_iterator it;
    for( it = v.begin(); it != v.end(); it++ ) {
        if( it != v.begin() ) os << ", ";
        os << it -> first << " = " << it -> second ;
    }
    return os << "]";
}

#define deb(x) cerr << #x << " = " << x << endl;



int32_t main(){
    ios::sync_with_stdio(false);
    int n;
    cin>>n;
    vector<pair<int, int> > a(n);
    set<pair<int, int> >S;
    REP(i,0,n){
        cin>>a[i].F;
        a[i].S=i+1;
        S.insert(a[i]);
    }
    while(S.size()!=0){
        auto g=*(S.begin());
        S.erase(S.begin());
        cout<<g.S<<" ";
    }
    cout<<"\n";
    




    return 0;
}

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

using namespace std;
#define X first
#define Y second
#define pb push_back
typedef double db;
typedef long long ll;
typedef pair<int,int> P;
const int MAXN=101;
char s[MAXN][MAXN];
int n,m,x,y;
short dp[MAXN][MAXN][MAXN][MAXN];
short line[MAXN][MAXN],col[MAXN][MAXN];
void upd(short &a,short b){a=max(a,b);}

int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)
	{
		scanf("%s",s[i]+1);
		for(int j=1;j<=m;j++)
		{
			if(s[i][j]=='E') x=i,y=j;
			line[i][j]=line[i][j-1]+(s[i][j]=='o');
			col[i][j]=col[i-1][j]+(s[i][j]=='o');
		}
	}
	
	short res=0;
	dp[0][0][0][0]=0;
	for(int u=0;u<x;u++) for(int d=0;d<=n-x;d++)
		for(int l=0;l<y;l++) for(int r=0;r<=m-y;r++)
		{
			if(!(u+d<max(x,n-x+1)&&l+r<max(y,m-y+1))) continue;	
			short &cur=dp[u][d][l][r];res=max(res,cur);
			int L=max(r+1,y-l),R=min(y+r,m-l),D=min(x+d,n-u),U=max(x-u,d+1);
			if(u+1+d<x) upd(dp[u+1][d][l][r],cur+line[x-u-1][R]-line[x-u-1][L-1]);
			if(d+1+u<=n-x) upd(dp[u][d+1][l][r],cur+line[x+d+1][R]-line[x+d+1][L-1]);
			if(l+1+r<y) upd(dp[u][d][l+1][r],cur+col[D][y-l-1]-col[U-1][y-l-1]);
			if(r+1+l<=m-y) upd(dp[u][d][l][r+1],cur+col[D][y+r+1]-col[U-1][y+r+1]);
		}
	printf("%d",res);
	return 0;
}

Measured memory_bytes: 198912
#include <bits/stdc++.h>
#define rep(i,a,b) for(ll i=ll(a);i<ll(b);i++)
#define irep(i,a,b) for(ll i=ll(a);i>=ll(b);i--)
#define pb push_back
#define mp make_pair
#define pll pair<ll,ll>
#define endl "\n"
using ll=long long;
using ld=long double;
using namespace std;
const ll mod= 1e9+7;
const ll INF = 1LL<<40;
ll GCD(ll a, ll b) { return b ? GCD(b, a%b) : a; }
ll a[11000];
int main(){
  ll n,k,ans=0;
  cin>>n>>k;
  if(n>=10)cout<<k;
  else cout<<k+(10-n)*100;
}

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


int main() {
  int N;
  cin >> N;
  long long count = 0;
  //iはAに相当
  for(int i = 1; i<=N-1;i++)
  {
    count += (N-1)/i;
  }
  cout << count << endl;
  
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, j, n) for (ll i = j; i < n; i++)
#define all(x) (x).begin(),(x).end()
#define INF (1000000000)
#define MOD (1000000007)
#define MAX (110)
#define pii pair<int, int>

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

class XY{
public:
  ll x, y;
  XY() {x = y = 0;}
  XY(ll u, ll v) {x = u; y = v;}
};

template<typename T1, typename T2>
void chmin(T1 &a, T2 b) {if(a > b) a = b;}
template<typename T1, typename T2>
void chmax(T1 &a, T2 b) {if(a < b) a = b;}

template<typename T1, typename T2>
T1 mypow(T1 a, T2 n){
  if(n == 0) return 1;
  if(n == 1) return a;
  if(n % 2) return a * mypow(a, n - 1);
  T1 tmp = mypow(a, n / 2);
  return tmp * tmp;
}

template<typename T>
int BS(vector<T> V, int left, int right, T key){
  int mid = (left + right) / 2;
  if(V[mid] <= key) left = mid;
  else right = mid;
  if(right - mid == 1) return left;
  else return BS(V, left, right, key);
}

bool isPrime(int n){
  if(n == 1) return false;
  rep(i, 2, min((int)(pow(n, 0.5) + 1), n)){
    if(n % i == 0) return false;
  }
  return true;
}

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

void Main() {
  string S; cin >> S;
  ll res = 0;
  ll cnt = 0;
  rep(i, 0, S.size()){
    if(S[i] == 'W'){
      res += i - cnt;
      cnt++;
    }
  }
  cout << res << endl;
}

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

int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << std::fixed << std::setprecision(15);

  Main();
}


Measured memory_bytes: 720
//Love and Freedom.
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<map>
#define N 200010 
#define ll long long
#define inf 20021225
using namespace std;
int read()
{
	int s=0,t=1; char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')	t=-1; ch=getchar();}
	while(ch>='0' && ch<='9')	s=s*10+ch-'0',ch=getchar();
	return s*t;
}
ll a[N]; int n;
map<pair<int,int>,int> mp;
int main()
{
	n=read(); double d;
	for(int i=1;i<=n;i++)
	{
		scanf("%lf",&d); (d*=1000000000); a[i]=d+0.5;
		int c2=0,c5=0;
		while(a[i]%2==0)	c2++,a[i]/=2;
		while(a[i]%5==0)	c5++,a[i]/=5;
		int n2=9,n5=9;
		mp[make_pair(c2-n2,c5-n5)]++;
	}
	ll ans1=0,ans=0;
	for(int c2=-9;c2<=60;c2++)	for(int c5=-9;c5<=20;c5++)	for(int cc2=max(-9,-c2);cc2<=60;cc2++)	for(int cc5=max(-9,-c5);cc5<=20;cc5++)
		if(make_pair(c2,c5)==make_pair(cc2,cc5))	ans+=(1ll*mp[make_pair(c2,c5)]*mp[make_pair(c2,c5)]-mp[make_pair(c2,c5)])>>1;
		else	ans1+=1ll*mp[make_pair(c2,c5)]*mp[make_pair(cc2,cc5)];
	printf("%lld\n",ans+(ans1>>1));
	return 0;
}

Measured memory_bytes: 4980
#include <stdio.h>
int main()
{
	int num[4] = { 0,-1,-1,-1 };
	int N, M, s, c;
	scanf("%d %d", &N, &M);
	for (int i = 1;i <= M;i++)
	{
		scanf("%d %d", &s, &c);
		if (num[s] == -1 || num[s] == c)
			num[s] = c;
		else
		{
			printf("-1");
			return 0;
		}
	}
	if (num[1] == 0)
	{	
		if (N > 1)
		{
			printf("-1");
			return 0;
		}
	}
	if (num[1] == -1)
	{
		if (N > 1)
			num[1] = 1;
	}
	for (int i = 1;i <= N;i++)
	{
		if (num[i] == -1)
			num[i] = 0;
		printf("%d", num[i]);
	}
	return 0;
}

Measured memory_bytes: 128
#include <cstdio>

int main(){
    int n;
    scanf("%d",&n);
    bool array[4][13];
    for(int i = 0;i < 4;i++){
        for(int j = 0;j < 13;j++){
        array[i][j] = false;
        }
    }
    for(int i = 0;i < n;i++){
        char a;
        scanf("\n%c",&a);
        int x;
        scanf("%d",&x);
        if(a == 'S'){
            array[0][x - 1] = true;}
        else if(a == 'H'){
            array[1][x - 1] = true;}
        else if(a == 'C'){
            array[2][x - 1] = true;}
        else if(a == 'D'){
            array[3][x - 1] = true;}
    }
        char (Llor[4]) = {'S','H','C','D'};
        for(int i = 0;i < 4;i++){
            for(int j = 0;j < 13;j++)
            if(!array[i][j]){
                printf("%c %d\n",Llor[i],j + 1);
            }
        }
    return 0;
    }


Measured memory_bytes: 2716
import java.util.Scanner;

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

        int N = sc.nextInt();

        System.out.println(solve(N) ? "Yes" : "No");

        sc.close();
    }

    static boolean solve(int N) {
        String s = String.valueOf(N);

        return s.charAt(1) == s.charAt(2) && (s.charAt(0) == s.charAt(1) || s.charAt(2) == s.charAt(3));
    }
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rep1(i,n) for(int i=1;i<=(int)n;i++)
#define sp(n) cout << fixed << setprecision(n)
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; }
typedef long long ll;
using namespace std;
int main(void){
    int n;cin>>n;
    vector<ll> a(n+1,0);
    rep(i,n+1) cin>>a[i];
    vector<ll> b(n+3,1);
    ll maxi=1;
    rep(i,n+1){
        maxi-=a[i];
        if((maxi==0&&i!=n)||maxi<0){
            cout<<-1<<endl;
            return 0;
        }
        if(maxi*2<=1e+18)maxi*=2;
        b[i+1]=maxi;
    }
    
    ll tmp=-1,res=0;
    rep(i,n+1){
        if(i==0){
            tmp=a[n];
            if(tmp>b[n]){
                cout<<-1<<endl;
                return 0;
            }
            res+=tmp;
            //cout<<i<<" "<<tmp<<endl;
            continue;
        }
        if(tmp>b[n-i]*2){
            cout<<-1<<endl;
            return 0;
        }else if(tmp+a[n-i]>=b[n-i]){
            tmp=b[n-i];
        }else{
            tmp+=a[n-i];
        }
        res+=tmp;
        //cout<<i<<" "<<tmp<<endl;
    }
    cout<<res<<endl;
    return 0;
}

Measured memory_bytes: 4848
#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
#include <random>
#include <cmath>
#include <iomanip>
#include <climits>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <deque>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <unordered_map>
#include <bitset>
#include <sstream>

typedef  long long ll;
#define mop 1000000007
using namespace std;

int point[100001] = {};
int main() {
    

    ll n,k;
    cin >> n >> k;
    ll r,s,p;
    cin >> r >> s >> p;
    string t;
    cin >> t;
    ll ans = 0;
    for(ll i=0;i<k;i++){
        if(t[i] == 'r'){
            ans += p;
        }else if(t[i] == 's'){
            ans += r;
        }else{
            ans += s;
        }
        point[i] = 1;
    }
    for(ll i=k;i<n;i++){
        if(t[i] == t[i-k] and point[i-k] != 0){
            continue;
        }else{
            if(t[i] == 'r'){
                ans += p;
            }else if(t[i] == 's'){
                ans += r;
            }else{
                ans += s;
            }
        }
        point[i] = 1;
    }
    cout << ans << endl;
}

Measured memory_bytes: 896
for n in range(int(input())):
  A = [int(i) for i in input().split()]
  B = [0]
  C = [0]
  for a in A:
    if a > B[-1] and a > C[-1]:
      if a - B[-1] <= a - C[-1]:
        B.append(a)
      else:
        C.append(a)
    elif a > B[-1] and a < C[-1]:
      B.append(a)
    elif a > C[-1]:
      C.append(a)
    else:
      print("NO")
      break
  if len(B) + len(C) == 12:
    print("YES")

Measured memory_bytes: 5596
/**********************************************
 * author : deepak nayan
 * file   : e:/Solutions/atcoder/abc130_a.cpp
 * time   : Sat May  2 00:44:27 2020
 * quest  : A - Rounding
 *********************************************/
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>

using namespace std;

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int x, a;
  cin >> x >> a;
  cout << (x < a ? 0 : 10) << "\n";
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAX = 510000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

int main(){
  COMinit();
  ll n,k; cin >> n >> k;
  //ll MOD = 1000000007
  vector<ll> A(n);
  for(ll i=0; i<n; i++){
    cin >> A.at(i);
  }
  vector<ll> fact(n+1);

  ll ans = 0;
  sort(A.begin(),A.end());
  if(k==1){
    cout << 0 << endl;
    return 0;
  }
  for(ll i=k-1; i<n; i++){
    
    ans += A.at(i)*COM(i,k-1)%MOD;
  }
  for(ll i=k-1; i<n; i++){
    
    ans -= A.at(n-i-1)*COM(i,k-1)%MOD;
  }
  ans = ans%MOD;   
  cout << ans << endl;
}

Measured memory_bytes: 13824
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rep1(i,n) for(int i=1;i<=(int)n;i++)
#define sp(n) cout << fixed << setprecision(n)
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; }
typedef long long ll;
using namespace std;
int main(void){
    ll n,k;cin>>n>>k;
    vector<ll> a(n);
    rep(i,n)cin>>a[i];
    sort(a.begin(),a.end());
    ll right=1e9,left=0;
    while(right-left>1){
        ll mid=left+(right-left)/2;
        ll tot=0;
        rep(i,n){
            tot+=(a[i]-1)/mid;
        }
        if(tot<=k)right=mid;
        else left=mid;
        //cout<<right<<" "<<left<<endl;
    }
    //cout<<left<<endl;
    cout<<right<<endl;
}

Measured memory_bytes: 4844
import java.util.Scanner;

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

        while(true) {
            int a = sc.nextInt();
            char op = sc.next().charAt(0);
            int b = sc.nextInt();

            if(op == '?') {
                break;
            } else if(op == '+') {
                System.out.println(a+b);
            } else if(op == '-') {
                System.out.println(a-b);
            } else if(op == '*') {
                System.out.println(a*b);
            } else {
                System.out.println(a/b);
            }
        }
        sc.close();
    }
}



Measured memory_bytes: 26388
#include <bits/stdc++.h>
#define REP(i, n) for (long long i = 0; i < (long long)n; i++)
#define _GLIBCXX_DEBUG
using namespace std;
using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using Vecl = vector<ll>;
using Graph = vector<vector<int>>;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  ll ans = 0;
  cin >> N;
  vector<string> str(N);
  REP(i, N) {
    cin >> str.at(i);
    sort(str.at(i).begin(), str.at(i).end());
  }
  sort(str.begin(), str.end());
  ll tmp = 1;
  for (int j = 1; j < N; j++) {
    if (str.at(j) == str.at(j - 1))
      tmp++;
    else {
      ans += (tmp * (tmp - 1)) / 2;
      tmp = 1;
    }
  }
  ans += (tmp * (tmp - 1)) / 2;

  cout << ans << endl;
}

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

#define rep( i, n, m ) for(int i = ( n ); i < ( m ); i++)
#define rep_d( i, n, m ) for(int i = ( n ) - 1; i >= ( m ); i--)
#define sort_asc( X ) sort(( X ).begin(), ( X ).end())
#define sort_desc( X ) sort(( X ).begin(), ( X ).end(), greater <>())
#define endl "\n"

template <class T> bool chmax( T& a, T b );
template <class T> bool chmin( T& a, T b );
int* eratosthenes( int N );
bool bit_search( int pattern, int N );
void initialize( void );

const ll INF = 1LL << 60;
const int k_mod = 1e9 + 7;
template <typename T, typename K> struct P {
	T a; K b;
};
typedef struct {
	vector <int> to;
	int cost;
} edge;

int main( void ){
	// initialize();
	int N;
	cin >> N;
	vector<int> vec(N);
	rep(i,0,N) cin >> vec[i];
	int a = 0;
	rep(i,1,N){
		a^=vec[i];
	}
	cout << a << " ";
	rep(i,1,N){
		a^=vec[i-1];
		a^=vec[i];
		cout << a << " ";
	}
	cout << endl;

}

template <class T> bool chmax( T& a, T b ) {
	if (a < b){
		a = b; return true;
	}
	return false;
}
template <class T> bool chmin( T& a, T b ) {
	if (a > b){
		a = b; return true;
	}
	return false;
}
int* eratosthenes( int N ){
	int* prime_array = new int[ N + 1 ];
	int lim = N;
	prime_array[ 0 ] = 0;
	prime_array[ 1 ] = 0;
	rep( i, 2, N + 1 ){
		prime_array[ i ] = 1;
	}
	rep( i, 2, lim ){
		if (prime_array[ i ] == 0)
			continue;
		lim = N / i;
		for(int j = i * 2; j < N + 1; j += i){
			prime_array[ j ] = 0;
		}
	}
	return prime_array;
}
bool bit_search( int pattern, int N ){
	int cnt = 0;
	rep( bit, 0, N ){
		if (pattern & ( 1 << bit )){
			cnt++;
		}
	}
	return true;
}
void initialize( void ){
	cout << fixed << setprecision( 10 );
}


Measured memory_bytes: 4052
import math
m, n = [int(i) for i in input().split()]
mod = 1000000007
m = m % mod
a = n
ans = 1
while a != 0:
    p = m
    b = math.log2(a)
    for bi in range(int(b)):
        p = p * p
        p = p % mod
    a = a - 2**int(b)
    ans = ans * p
    ans = ans % mod
print(ans)


Measured memory_bytes: 5684
#include<bits/stdc++.h>
using namespace std;
int a[1005];
bool cmp(int a,int b){
    return a>b;
}
int main(){
    int n;
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>a[i];
    }
    sort(a+1,a+n+1,cmp);
    int ans=0,res=0;
    for(int i=1;i<=n;i++){
        if(i%2){
            ans+=a[i];
        }else {
            res+=a[i];
        }
    }
    cout<<ans-res<<endl;
    return 0;
}


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


int main(void)
{
	int a, b;
	cin >> a>> b;

	int sum = a + b;
	int min = a - b;
	int ka = a * b;

	if (sum >= min && sum >= ka)
		cout << sum << endl;
	else if (min >= sum && min >= ka)
		cout << min << endl;
	else
		cout << ka << endl;


}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<string> vs;
typedef complex<double> pnt;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<pii, pii> pp;
typedef double ld;
typedef long double lld;
#define INF 0x3f3f3f3f // for int
#define LL_INF 0x3f3f3f3f3f3f3f3f // for ll
#define gl(x) getline(cin, (x))
#define sz(x) (int)(x.size())
#define af(x) x.begin(), x.end()
#define ms(x, y) memset(x, y, sizeof(x))
#define mpp make_pair
#define pb push_back
#define AUT auto
//coordinate compression:sort(val.begin(), val.end());
//		val.resize(unique(val.begin(), val.end()) - val.begin());
#define nl '\n'
typedef unsigned long long ull;
const int MOD = 1e9 + 7;
const lld pi = 3.14159265358979323846;

//remember to remove ios stuff if i use scanf

//printf("%05lld\n", x); --> print last 5 digits including 0's
//printf("%02d:%02d", h, m); --> time
ll gcd(ll a, ll b){return b == 0 ? a : gcd(b, a % b);}
ll lcm(ll a, ll b){return a*b/gcd(a,b);}
ll pwmd(ll b, ll exp) {
    ll ret = 1;
    while (exp > 0) {
        if (exp % 2 == 1) ret = (ret * b) % MOD;
        exp /= 2;
        b = (b * b) % MOD;
    }
    return ret;
}
//void RotateArr(int X) {
//    for (int n=0; n<X; n++) {
//        for (int i=0; i<N/2; i++) {
//            for (int j=0; j<N; j++) {
//                swap(a[i][j], a[N-i-1][j]);
//            }
//        }
//        for (int i=0; i<N; i++) {
//            for (int j=i+1; j<N; j++) {
//                swap(a[i][j], a[j][i]);
//            }
//        }
//    }
//}

/*
 * string input;
 *
 * stringstream ss(input);
 *- if the input contains '\n', separate lines with: string line; while (getline(ss, line))
 * - clear() to clear the stream
 * - >> : read smth from stringstream object ie. while (s >> word)
 */

struct pair_hash { //megabrain --> for unordered_set<pair<ll, ll>>
    //initialize the set with unordered_set<pair<ll, ll>, pair_hash>st
    inline std::size_t operator()(const std::pair<ll,ll> & v) const {
        return v.first*31+v.second;
    }
};
/* for dijkstra:
 * bool operator < (const E &other) const {
        return this->w > other.w;
    }
 */

int n, x, t;

void solve(int tc) {

    cin >> n >> x >> t;
    int ans = t * (int)(n / x);
    if (n % x != 0) ans += t;
    cout << ans <<nl;

}

//you should really read the stuff at the bottom

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);

    int tc = 1; //cin >> tc;
    for (int t = 0; t < tc; t++) solve(t);

    return 0;
}

/* stuff you should look for
	* int overflow, array bounds
	* special cases (n=1?)
	* do smth instead of nothing and stay organized
	* WRITE STUFF DOWN
	* DON'T GET STUCK ON ONE APPROACH
// Did you read the bounds?
// Did you make typos?
// Are there edge cases (N=1?)
// Are array sizes proper (scaled by proper constant, for example 2* for koosaga tree)
// Integer overflow?
// DS reset properly between test cases?
// Is using long longs causing TLE?
// Are you using floating points?
*/

Measured memory_bytes: 3632
a = list(map(int, input().split()))
b = a[:]
c = a[:]

def aa(a):
    total = a[1]
    i6 = min(a[0],a[3],a[4])
    a[0] -= i6
    a[3] -= i6
    a[4] -= i6
    total += i6 * 3
    total += a[0]//2*2
    total += a[3]//2 *2
    total += a[4]//2 *2
    return total

def bb(a):
    total = a[1]
    if a[0] > 0 and a[3]%2 ==  a[4]%2 == 1:
        a[0] -= 1
        a[3] -= 1
        a[4] -= 1
        total += 3
    total += a[0]//2 * 2
    total += a[3]//2 * 2
    total += a[4]//2 * 2
    return total

def cc(a):
    total = a[1]
    if (a[0]%2 == a[3]%2 == 1 and a[4]>0) or (a[0]%2 == a[4]%2 == 1 and a[3]>0) or(a[4]%2 == a[3]%2 == 1 and a[0]>0):
        total += 3
        a[0] -= 1
        a[3] -= 1
        a[4] -= 1
    total += a[0]//2 * 2
    total += a[3]//2 * 2
    total += a[4]//2 * 2
    if a[0]%2 == a[3]%2 ==  a[4]%2 == 1:
        a[0] -= 1
        a[3] -= 1
        a[4] -= 1
        total += 3
    return total
print(max(aa(a),bb(b), cc(c)))

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

int main() {
  int n;cin>>n;
  int m=1;
  if (n==1||n==2||n==4){   cout<<4;return 0;}
  else 
  {
  while(n!=4) {
    m++;
    if (n%2==0) n /= 2;
    else n = n * 3 + 1;
  }
  }
  cout<<m+3<<endl;
  return 0;
}


Measured memory_bytes: 256
import java.io.*;
import java.util.Scanner;


public class Main {

	private static Scanner sc;
	private static Printer pr;

	private static void solve() {
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();

		pr.println(Math.min(c, b / a));
	}

	// ---------------------------------------------------
	public static void main(String[] args) {
		sc = new Scanner(System.in);
		pr = new Printer(System.out);
			
		solve();
			
		pr.close();
		sc.close();
	}

	static class Printer extends PrintWriter {
		Printer(OutputStream out) {
			super(out);
		}
	}
}


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

long long int temp_max(long long int n) {
	return (n == 0) ? 0 : 9 + 10 * temp_max(n / 10);
}
long long int max_digit(long long int n) {
	return (n < 10) ? 1 : 10 * max_digit(n / 10);
}
long long int sum_digit(long long int n) {
	return (n == 0) ? 0 : n % 10 + sum_digit(n / 10);
}
int main() {
	long long int n;
	std::cin >> n;
	auto temp = temp_max(n);
	auto digit = max_digit(n);
	while (n < temp) {
		temp -= digit;
	}
	std::cout << sum_digit(temp) << std::endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define U [100005]={}
typedef long long L;using namespace std;map<L,L> path U;L P U,E U,Z U,H U,C U,A U,O U,X U,B U,k,n,a,b,c,p,r;char s U;
L D(L a){Z[a]=1;for(map<L,L>::iterator I=path[a].begin();I!=path[a].end();I++){L d=I->first;if(d-P[a]){P[d]=a;E[d]=E[a]+1;C[d]=I->second;D(d);Z[a]+=Z[d];!H[a]|Z[H[a]]<Z[d]?H[a]=d:0;}}}
L G(L a){r=A[a]+A[P[a]]+C[a];return r%k?r:0;}
L M(L i){return i?B[i]+M(i-(i&-i)):0;}
L S(L i,L x){for(x=G(x)-M(i+1)+M(i++);i<100005;B[i]+=x,i+=i&-i);}
main(){for(cin>>n>>k;p<n-1;p++)cin>>a>>b>>c,path[a][b]=path[b][a]=c;
       for(D(c=p=0);p<n;p++)if(!p|H[P[p]]-p)for(a=p;!c|a;a=H[a])X[a]=p,S(O[a]=c++,H[a]);
       for(cin>>a;cin>>s>>a>>b;)if(*s&2){
           for(c=0;p=X[a],n=X[b],p-n;a=P[p])E[p]<E[n]?swap(p,n),swap(a,b),0:0,c+=M(O[a])-M(O[p])+G(p);cout<<c+abs(M(O[a])-M(O[b]))<<endl;}
       else A[a]+=b,S(O[a],H[a]),a?S(O[a]-1,a):0;}

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

int main()
{
	
	double n,k;
	cin>>n>>k;
	for(int i=0;i<n;i++)
	{
	 int x;
	 cin>>x;
	 }
	int ans=0;
	int a=k-1;
	n-=k;
	ans+=ceil(n/a);
	cout<<++ans<<endl;
 return 0;
 }

Measured memory_bytes: 384
import math
def make_prime_list_2(num):
    if num < 2:
        return []

    # 0のものは素数じゃないとする
    prime_list = [i for i in range(num + 1)]
    prime_list[1] = 0 # 1は素数ではない
    num_sqrt = math.sqrt(num)

    for prime in prime_list:
        if prime == 0:
            continue
        if prime > num_sqrt:
            break

        for non_prime in range(2 * prime, num, prime):
            prime_list[non_prime] = 0

    return [prime for prime in prime_list if prime != 0]

def prime_factorization_2(num):
    if num <= 1:
        return False
    else:
        num_sqrt = math.floor(math.sqrt(num))
        prime_list = make_prime_list_2(num_sqrt)

        dict_counter = {}
        for prime in prime_list:
            while num % prime == 0:
                if prime in dict_counter:
                    dict_counter[prime] += 1
                else:
                    dict_counter[prime] = 1
                num //= prime
        if num != 1:
            if num in dict_counter:
                dict_counter[num] += 1
            else:
                dict_counter[num] = 1

        return dict_counter

def search_divisor_num_1(num):
    if num < 0:
        return None
    elif num == 1:
        return 1
    else:
        num_sqrt = math.floor(math.sqrt(num))
        prime_list = make_prime_list_2(num_sqrt)

        divisor_num = 1
        for prime in prime_list:
            count = 1
            while num % prime == 0:
                num //= prime
                count += 1
            divisor_num *= count

        if num != 1:
            divisor_num *= 2

        return divisor_num

n = int(input())
a = 0
for i in range(1,n+1,2):
    if search_divisor_num_1(i)==8:
        a +=1
print(a)

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

int main(){
    long long n,T;

    cin >> n >> T;
    long long t[n],ans(0);

    for(long long i=0;i<n;i++)
        cin >> t[i];

    if(n==1){
        cout << T << endl;
        return 0;
    }
    if(n==2){
        if((t[1]-t[0])<T){
            cout << T+t[1]-t[0] << endl;
            return 0;
        }else{
            cout << T*2 << endl;
            return 0;
        }
    }

    for(long long i=0;i<n;i++){
        if((t[i+1]-t[i])<T){
            ans = ans+t[i+1]-t[i];
        }else{
            ans = ans + T;
        }
    }

    cout << ans << endl;

    return 0;
}

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

typedef long long ll;
using namespace std;
ll MOD = 1000000007;

int main() {
  ll H, W, K;
  cin >> H >> W >> K;
  // dp[i][j]
  // i列目について、0からスタートしてj番目に到達するパスの数
  vector<vector<ll>> dp(H + 1, vector<ll>(W, 0));
  dp[0][0] = 1;  // 1(インデックスは0)からスタートする
  for (ll i = 0; i < H; i++) {
    for (ll j = 0; j < W; j++) {
      // stepがiのときの線の入れ方を考える
      // step (i+1)のパスの数を計算する(配るDP)

      // それぞれの区間で線を入れる、入れないの2通り
      for (ll bit = 0; bit < (1<<(W-1)); bit++) {
        ll ok = true;
        // 連続して同じ高さの棒が引かれているか
        for (ll k = 0; k < (W-1); k++) {
          if (bit & (1 << k) && (bit & (1 << (k+1)))) {
            ok = false;
            break;
          }
        }

        if (ok == false) continue;

        // stepがiでj = 1を考える
        // j(=1)bit目が立っているとき
        // 次のstepの総数
        // i:   | | |
        // i+1: | |-|
        //      0 1 2
        if (bit & (1 << j)) {
          dp[i + 1][j + 1] += dp[i][j];
          dp[i + 1][j + 1] %= MOD;
        }
        // stepがiでj = 1を考える
        // j-1(=0)bit目が立っているとき
        // 次のstepの総数
        // i:   | | |
        // i+1: |-| |
        //      0 1 2
        else if ((j - 1 >= 0) && bit & (1 << (j - 1))) {
          dp[i + 1][j - 1] += dp[i][j];
          dp[i + 1][j - 1] %= MOD;
        } else {
          dp[i + 1][j] += dp[i][j];
          dp[i + 1][j] %= MOD;
        }
      }
    }
  }

  // for (ll i = 0; i <= H; i++) {
  //   for (ll j = 0; j <= W; j++) {
  //     cout << dp[i][j] << " ";
  //   }
  //   cout << endl;
  // }
  // cout << endl;

  cout << dp[H][K - 1] % MOD << endl;

  return 0;
}

Measured memory_bytes: 256
import sys,collections as cl,bisect as bs,copy
sys.setrecursionlimit(100000)
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist 小数はfloat
    return list(map(float,input().split()))
def m(): #複数文字
    return map(int,input().split())
def onem(): #Nとかの取得
    return int(input())
def s(x): #圧縮
    a = []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): #listをスペースごとに分ける
    return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
    return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False

n = onem()

a = l()

dp = [[0 for i in range(n+1)]for j in range(n+1)]
dp[0][0] = 1

for i in range(n):
    for j in range(0,n+1):
        if j == 0:
            dp[i+1][0] = dp[i][0]*(1-a[i])
        elif j == n:
            dp[i+1][-1] = dp[i][-2]*a[i]
        else:
            dp[i+1][j] = dp[i][j-1]*a[i] + dp[i][j]*(1-a[i])
    

print(sum(dp[-1][(n+1)//2:]))





Measured memory_bytes: 259720
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef string str;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector <pii> vpii;
typedef vector <pll> vpll;
typedef map <str,int> mapsi;
typedef map <str,int> :: iterator mapsitr;
typedef set <int> si;
typedef set <int> :: iterator sitr;
typedef set <ll> :: iterator sltr;
#define mset multiset
typedef mset <int> msi;
typedef mset <ll> msll;
typedef mset <int> :: iterator msitr;
typedef mset <ll> :: iterator msltr;
#define mp make_pair
#define pb push_back
#define pob pop_back
#define fi first
#define se second
#define fs first.second
#define ss second.second
#define ff first.first
#define sf second.first
int k,f;
int main(){
    cin>>k;
    for(int i=1;i<=k;i++){
        for(int j=i+1;j<=k;j+=2){
            f++;
        }
    }
    cout<<f<<endl;
}


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

using i64 = long long;
using P = pair<i64, i64>;

#define overload3(_1, _2, _3, name, ...) name
#define rep1(i, n) for(i64 i = 0LL; i < (n); ++i)
#define rep2(i, a, b) for(i64 i = (a); i < (b); ++i)
#define rep(...) overload3(__VA_ARGS__, rep2, rep1)(__VA_ARGS__)
#define all(v) v.begin(), v.end()

struct IoSetup {
    IoSetup() {
        // cin.tie(nullptr);
        // ios::sync_with_stdio(false);
        cout << fixed << setprecision(10);
        cerr << fixed << setprecision(10);
    }
} iosetup;

vector< vector< int64_t > > get_combination(int N)
{
  vector< vector< int64_t > > mat(N + 1, vector< int64_t >(N + 1));
  for(int i = 0; i <= N; i++) {
    for(int j = 0; j <= i; j++) {
      if(j == 0 || j == i) mat[i][j] = 1;
      else mat[i][j] = mat[i - 1][j - 1] + mat[i - 1][j];
    }
  }
  return (mat);
}

using int64 = long long;

int64 mod_pow(int64 x, int64 n)
{
  int64 ret = 1;
  while(n > 0) {
    if(n & 1) (ret *= x);
    (x *= x);
    n >>= 1;
  }
  return ret;
}


int main(){
    i64 n, p;
    cin >> n >> p;
    vector<i64> a(n);
    rep(i, n) cin >> a[i];
    i64 d = 0, b = 0;
    rep(i, n){
        if(a[i] % 2 == 1) d++;
        else b++;
    }
    auto comb = get_combination(n);
    i64 ans;
    if(p == 1){
        ans = 0;
        for(int i = 1; i <= d; i += 2) ans += comb[d][i];
        ans *= mod_pow(2, b);
    }else{
        ans = 0;
        for(int i = 0; i <= d; i += 2) ans += comb[d][i];
        ans *= mod_pow(2, b);
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**6)
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

n = ni()
p = na()
ans = 0

for i in range(n-1):
    j = i+1
    if j == p[i]:
        p[i],p[i+1] = p[i+1],p[i]
        ans += 1
if p[-1] == n:
    ans += 1
print(ans)

Measured memory_bytes: 14388
#include <stdio.h>


int main(void){
  float D;
  float T;
  float S;
  
    
 scanf("%f",&D);
   

   
  scanf("%f",&T);
   

   
  scanf("%f",&S);
   

  
  if(D/S <= T){
  printf("Yes");
  }
  else if(D/S >= T){
      printf("No");
  }
  
  
  return 0;
   
};

Measured memory_bytes: 1748
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

using namespace std;
typedef long long  ll;
typedef long double ld;
typedef pair<ll,ll> pp;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> super_set;
typedef tree<ll,null_type,less_equal<ll>,rb_tree_tag,tree_order_statistics_node_update> multi_set;
#define x1 dfds
#define y1 dsfdsfe
#define pb push_back
#define forn(i,n) for(ll i = 1;i<=n;++i)
#define fi first
#define sc second
#define endl '\n'
#define po(x) (1ll<<x)
const ll DIM = 800+7;
const ll INF = 1e8;


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

    ll a,b,c;
    cin>>a>>b>>c;
    cout<<c<<' '<<a<<' '<<b<<endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.io.*;
import java.math.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int maxi = 0;
        int maxv = 0;
        int seci = 0;
        int secv = 0;
        for(int i = 0; i < n; i++){
            int v = sc.nextInt();
            if(v > maxv){
                secv = maxv;
                seci = maxi;
                maxv = v;
                maxi = i;
            }else if(v > secv){
                secv = v;
                seci = i;
            }
        }
        for(int i = 0; i < n; i++){
            if(i == maxi){
                System.out.println(secv);
            }else{
                System.out.println(maxv);
            }
        }
    }
}



Measured memory_bytes: 84200
#include<bits/stdc++.h>
#include<algorithm>
using namespace std;
#define ll long long
#define ff first
#define ss second
#define pb(x) push_back(x)

typedef pair<ll,ll> pp;
int lcm(int a, int b)
{
    int lar = max(a, b);
    int small = min(a, b);
    for (int i = lar; ; i += lar) {
        if (i % small == 0)
            return i;
    }
}

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

bool sortbysec(const pair<ll,ll> &a, const pair<ll,ll> &b) {
    return (a.second < b.second);
}

ll power(ll x, unsigned ll y, ll p){
    ll res = 1;
    x = x % p;
    if (x == 0) return 0;
    while (y > 0){
        if (y & 1)
            res = (res*x) % p;
        y = y>>1;
        x = (x*x) % p;
    }
    return res;
}

ll lis( ll arr[], ll n )
{
    ll lis[n];
   
    lis[0] = 1;
  
    /* Compute optimized LIS values in bottom up manner */
    for (ll i = 1; i < n; i++)
    {
        lis[i] = 1;
        for (ll j = 0; j < i; j++ )
            if ( arr[i] > arr[j] && lis[i] < lis[j] + 1)
                lis[i] = lis[j] + 1;
    }
  
    // Return maximum value in lis[]
    return *max_element(lis, lis+n);
}

void solve(){
    ll s, w;
    cin >> s >> w;
    if(w >= s)
      cout << "unsafe\n";
    else
      cout << "safe\n";
}

int main()
{
    //ll t; cin >> t; while(t--)
        solve();
}


Measured memory_bytes: 3632
N = int(input())

a_dict = {}

for i in range(1, N+1):
	a_dict[i] = int(input())

answer = 0
now_point = 1

for i in range(N):
	now_point = a_dict[now_point]
	answer += 1
	if now_point == 2:
		print(answer)
		break

if now_point != 2:
	print(-1)

Measured memory_bytes: 17892
import sys
import heapq
import re
from itertools import permutations
from bisect import bisect_left, bisect_right
from collections import Counter, deque
from fractions import gcd
from math import factorial, sqrt
from functools import lru_cache, reduce
INF = 1 << 60
mod = 1000000007
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline

# UnionFind
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

# ダイクストラ
def dijkstra_heap(s, edge, n):
    #始点sから各頂点への最短距離
    d = [10**20] * n
    used = [True] * n #True:未確定
    d[s] = 0
    used[s] = False
    edgelist = []
    for a,b in edge[s]:
        heapq.heappush(edgelist,a*(10**6)+b)
    while len(edgelist):
        minedge = heapq.heappop(edgelist)
        #まだ使われてない頂点の中から最小の距離のものを探す
        if not used[minedge%(10**6)]:
            continue
        v = minedge%(10**6)
        d[v] = minedge//(10**6)
        used[v] = False
        for e in edge[v]:
            if used[e[1]]:
                heapq.heappush(edgelist,(e[0]+d[v])*(10**6)+e[1])
    return d

# 素因数分解
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

# 2数の最小公倍数
def lcm(x, y):
    return (x * y) // gcd(x, y)

# リストの要素の最小公倍数
def lcm_list(numbers):
    return reduce(lcm, numbers, 1)

# リストの要素の最大公約数
def gcd_list(numbers):
    return reduce(gcd, numbers)

# ここから書き始める
a, b, c = map(int, input().split())
if a % 2 == 0 and a == b == c:
    print(-1)
else:
    ans = 0
    while True:
        if a % 2 == 1 or b % 2 == 1 or c % 2 == 1:
            break
        copy_a = a
        copy_b = b
        copy_c = c
        a = copy_b // 2 + copy_c // 2
        b = copy_a // 2 + copy_c // 2
        c = copy_a // 2 + copy_b // 2
        ans += 1
    print(ans)

Measured memory_bytes: 5180
#include<stdio.h>
int main(){
  int a,s;
  scanf("%d%d",&a,&s);
  int sum=0;
  for(int i=0;i<2;i++){
    if(a>s){
      sum+=a;
      a--;
    }
    else{
      sum+=s;
      s--;
    }
  }
  printf("%d\n",sum);
}

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

using namespace std;

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

int n,a[100001],d[200001],k;

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

void process()
{
    d[1]=0;
    for (int i=1;i<=n;++i)
    {
        for (int j=1;j<=k;++j)
            d[i+j]=min(d[i+j],d[i]+abs(a[j+i]-a[i]));
    }
    cout<<d[n];
}

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


Measured memory_bytes: 1024
object Main extends App {
    val in = io.Source.stdin.getLines.map(_.trim.split(" ").map(_.toInt))
    val n = in.next.head
    val t = (0 to n-1).toArray
    val d = in.toSeq
    val es = (for (i <- (0 to n-2); j <- (i+1 to n-1) if d(i)(j) != -1) yield (i, j, d(i)(j))).sortBy(_._3)
    var cost = 0

    def find(m: Int): Int = if(t(m) == m) m else {t(m) = find(t(m)); t(m)}
 
    def unite(x: Int, y: Int) = {
        val _x = find(x)
        val _y = find(y)
        if(_x != _y) t(_x) = _y
    }
 
    es.foreach(e => if (find(e._1) != find(e._2)) {unite(e._1, e._2); cost += e._3})
    println(cost)
}

Measured memory_bytes: 48608