akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <math.h>
#include <cmath>
#include <limits.h>
#include <map>
#include <unordered_map>
#include <set>
#include <queue>
#include <algorithm>
#include <functional>
#include <stdio.h>
using namespace std;

long long MOD = 1000000007;


// int main() {
    
//     int N;
//     cin >> N;
//     vector<int> A(N);
//     for ( int i = 0; i < N; i++ ) {
//         cin >> A[i];
//     }

//     long long ans = 0;
//     for ( int i = 0; i < N; i++ ) {
//     for ( int j = i+1; j < N; j++ ) {
//         int s = 0;
//         int x = 0;
//         int o = 0;
//         bool b = false;
//         for ( int k = i; k <= j; k++ ) {
//             s += A[k];
//             if ( o & A[k] ) { b = true; }
//             o |= A[k];
//             x ^= A[k];
//         }
//         if ( ( s == x ) && b ) { cout << "aaa" << endl; }
//         if ( s == x ) { ans++; }
//     }
//     }
//     cout << ans << endl;

//     return 0;
// }


int main() {
    
    int N;
    cin >> N;
    vector<int> A(N);
    vector<int> X(20,-1);
    
    for ( int i = 0; i < N; i++ ) {
        cin >> A[i];
    }

    long long ans = 0; 
    
    int a = 0;
    for ( int i = 0; i < N; i++ ) {
        int z = -1;
        for ( int j = 0; j < 20; j++ ) {
            if ( (1<<j)&A[i] ) {
                z = max( z, X[j] );
                X[j] = i;
            }
        }
        if ( i-a <= z ) {
            a = i-z;
            ans += i-z;
        }
        else {
            a++;
            ans += a;
        }
    }
    cout << ans << endl;


    return 0;
}

Measured memory_bytes: 1024
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;
import std.bigint;
import std.ascii;


void main()
{
  auto n = readln.chomp.to!int;
  auto res = int.max;
  foreach (a; 1..n) {
    auto b = n - a;
    int sum;
    while (a) {
      sum += a % 10;
      a /= 10;
    }
    while (b) {
      sum += b % 10;
      b /= 10;
    }

    res = min(sum, res);
  }
  res.writeln;
}


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

int main(){
	int n;
	cin >> n;
	vector<string> w(n);
	rep(i,n) cin >> w[i];
	for(int i = 0;i < n-1;i++){
		for(int j = i+1;j < n;j++){
			if(w[i] == w[j]){
				cout << "No" << endl;
				return 0;
			}
		}
	}
	rep(i,n-1){
		int ilen = w[i].size()-1;
		if(w[i][ilen] != w[i+1][0]){
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

 long long n , v[200005]={} , a[200005]={} , s=0,aux;
int main()
{

    cin>>n;

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

    for(int i=1;i<=200000;i++) s+=v[i]*(v[i]-1)/2;

    for(int i=1;i<=n;i++){

        int x=a[i];

        aux=s-(v[x]*(v[x]-1)/2)+((v[x]-1)*(v[x]-2)/2);
        cout<<aux<<endl;
    }

        return 0;
}


Measured memory_bytes: 5116
n= int(input())
apart_table=[[[0]*10 for i in range(0,3)] for k in range(0,4)]

for l in range(0,n):
    apart_id,floor,room,human=map(int,input().split())
    apart_table[apart_id-1][floor-1][room-1]+=human

count=0
for m in range(0,4):
    if count!=0:
        print('#'*20)
    count+=1

    for n in range(0,3):
        for o in range(0,10):
            print(" {}".format(apart_table[m][n][o]),end='')
        print()


Measured memory_bytes: 5628
import math

K = int(input())

gcd = []

for a in range(1,K+1,1):
    for b in range(1,K+1,1):
        for c in range(1,K+1,1):
            partial = math.gcd(a, b)
            ans = math.gcd(partial, c)
            gcd.append(ans)

print(sum(gcd))

Measured memory_bytes: 205824
//#include<bits/stdc++.h>
#include<set>
#include<map>
#include<list>
#include<iomanip>
#include<cmath>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<complex>
#include<sstream>
#include<iostream>
#include<fstream>
#include<algorithm>
#include<numeric>
#include<utility>
#include<functional>
#include<stdio.h>
#include<assert.h>
#include<memory.h>
#include<bitset>
#include<stdio.h>
#include <cstdio>
#include <cstring>
#include <string>


using namespace std;

#define ld long double
#define ll long long
#define ff first
#define ss second
#define sz(a) (int)a.size()
#define mem(a, b) memset((a), (b), sizeof(a))
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define pii pair<int ,int >
#define pll pair<ll ,ll >
#define mp make_pair
#define vi vector<int >
#define vii vector<pii>
#define vvi vector < vi >
#define vll vector < ll >
#define vllll vector < pll >
#define vvll vector < vll >
#define forn(i,n) for(int i=0;i<(n);i++)
#define fori(i,s,e) for(int i=s,i<n;i++)
#define qi  queue <int >
#define qll  queue <ll >
#define in_r(x,y,n,m) (x>=0 && x<n && y>=0 && y<m)
#define maxn 1000009


void fast(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
}

const ll MOD = 1e9 + 7;
const double EPS = (1e-8);
const int OO = (int) 1e9 + 7;
const ll OOO = (ll) 1e15 + 7;
double const PI = 3.1415926535897932384626433832795;
const int mxn = 200009;
char c1, c2, c3, c4;
string s, s1, s2, s3;
ll   n, m, k, t, q, a, b, c, d, e, x, y, z; ll sol = 0;






int main(){
	fast();
	
	cin >> s; n = sz(s);
	x = s[n-1]-'0';
	if (x == 2 || x == 4 || x == 5 || x == 7 || x == 9) cout << "hon";
	else if (x == 3) cout << "bon";
	else cout << "pon";



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


Measured memory_bytes: 3640
# ABC138D - Ki
import sys

input = sys.stdin.readline
sys.setrecursionlimit(4 * 10 ** 5)


def dfs(v: int, p: int) -> None:
    x = cnt[v]
    for u in T[v]:
        if u != p:  # p: parent -> skip
            cnt[u] += x  # cumulative sum
            dfs(u, v)


def main():
    # Ai (A[i][0]) may be not a parent of Bi (A[i][1])
    global T, cnt
    N, Q = tuple(map(int, input().split()))  # vertices and queues
    E = tuple(tuple(map(int, input().split())) for _ in range(N - 1))
    P = tuple(tuple(map(int, input().split())) for _ in range(Q))
    T = [[] for _ in range(N + 1)]  # tree, N+1: 1-idx
    for a, b in E:
        T[a] += [b]
        T[b] += [a]
    cnt = [0] * (N + 1)
    for p, x in P:
        cnt[p] += x  # increase vertex p by x
    dfs(1, -1)
    print(*cnt[1:])


if __name__ == "__main__":
    main()

Measured memory_bytes: 265724
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define m1(x) memset(x,-1,sizeof(x))
const int INF = 1e9 + 1;
const ll MOD = 1e9 + 7;
const double PI = 3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799;

ll x;
ll lis[2001];

int main(){
  cin >> x;
  for(int i = -1000; i <= 1000;i++){
    lis[i+1000] = pow(i, 5);
  }
  bool flag = false;
  for(int i = 2000; i >=0; i--){
    for(int j = 2000; j >= 0; j--){
      ll p = lis[i], q = lis[j];
      if(p - q == x){
        cout << i-1000 << " " << j-1000 <<endl;
        flag = true;
        break;
      }
    }
    if(flag) break;
  }
  //cout << lis[182] - lis[116]<<endl;
}
  

Measured memory_bytes: 4052
def main():
  n = int(input())
  
  dp = [0]*(n+1)
  dp[0] = 1
  mod = pow(10, 9) + 7
  for i in range(3, n+1):
    dp[i] = dp[i-1] + dp[i-3]
    dp[i] %= mod
  
  print(dp[n])

if __name__ == "__main__":
  main()

Measured memory_bytes: 9108
#include<bits/stdc++.h>
#define ll long long
using namespace std; 
int n;
stack<int> st;
int main(){
	cin >> n;
	int val;
	for(int i=1;i<=n;++i){
		cin >> val;
		if(val == st.size()+1){
			st.push(val);
		}
	}
	int ans = n - st.size();
	if(ans == n)	ans = -1;
	cout << ans ;
	return 0;
}

Measured memory_bytes: 1024
import sys
import os
import bisect, collections, copy, itertools, math, string
def I(): return int(input())
def S(): return input()
def LI(): return list(map(int, input().split()))
def LS(): return list(input().split())

def solve():
	NM= LI()
	N = NM[0]
	M = NM[1]

	A = LI()

	_sum = 0
	for a in A:
		_sum += a

	x = _sum/(4* M)
	for a in A:
		if a >= x:
			M -= 1

	if M <= 0:
		print('Yes')
	else:
		print('No')

if __name__ == '__main__':
	solve()


Measured memory_bytes: 3888
#include<iostream>
#include<stdio.h>
using namespace std;
int main() {

	char ch;

	while (1) {
		scanf("%c", &ch);


		if ('a' <= ch && ch <= 'z') {
			int a = (int)ch - 32;
			printf("%c", a);
		}else if ('A' <= ch && ch <= 'Z') {
			int a = (int)ch + 32;
			printf("%c", a);
		}else{
			cout << ch;
		}
		if (ch == '\n')break;


	}
	return 0;

}



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

#define pb push_back
#define FIO {ios::sync_with_stdio(0); cin.tie(nullptr); cout.tie(nullptr);}
#define testCases int testCases = 0; cin>>testCases; while(testCases--)
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef long double ld;

// int NumberOfConnectedComponents(vector<vector<int>> graph){
//     cout<<"This is who I am..."<<endl;
//     int numberOfNodes = graph.size();
//     int visitedNode[numberOfNodes] = {0};
//     int startIndex = 0, counter = 1;
//     while(true){
//         cout<<"This is where I might get stuck..."<<endl;
//         deque <int> nodeList;
//         nodeList.push_back(startIndex);
//         while(!nodeList.empty()){
//             int n = nodeList.front();
//             visitedNode[n] = counter;
//             nodeList.pop_front();
//             for(int i=0; i<graph[n].size(); ++i){
//                 nodeList.push_back(graph[n][i]);
//             }
//         }
//         bool complete = true;
//         for(int i=0; i<numberOfNodes; ++i){
//             if(visitedNode[i]==0){
//                 complete = false;
//                 break;
//             }
//         }
//         if(!complete) counter++;
//         else return counter;   
//     }
// }

int main(){
    FIO
    // testCases{

    // }
    string S; cin>>S;
    bool valid = true;
    for(int i=0; i<S.length(); i+=2){
        if(S[i]!='h' || S[i+1]!='i'){
            valid = false;
            break; 
        }
    }
    if(valid) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

//0 -> 1 | 2 |
//1 -> 0 |
//2 -> 0 |
//3 -> |

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<algorithm>
#include<vector>
using namespace std;
string s;
#define rep2(x,from,to) for(int x=from;x<to;x++)
#define rep(x,to) rep2(x,0,to)
string t;

int m,d;
int d1,d10;
int ans;
int main()
{
    cin>>m>>d;
    //cin>>m>>d;
    rep2(i,1,d+1)
    {
        d1=i%10;
        d10=i/10;
        if(d1>=2&&d10>=2&&d1*d10<=m)ans++;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
from heapq import *

N=int(input())
X=list(map(int,input().split()))
h=[]
for i in X:
    heappush(h,i)
for i in range(N//2-1):
    heappop(h)
a = heappop(h)
b = heappop(h)
for i in X:
    print(a if i >= b else b)


Measured memory_bytes: 103252
#include <stdio.h>
#include <string.h>
int main(void)
{
  char s[12], t[12], u[12];
  int a, b;
  scanf("%s%s",s,t);
  scanf("%d%d", &a,&b);
  scanf("%s",u);
  if(strcmp(s,u)==0) {
    a--;
  } else {
    b--;
  }
  printf("%d %d\n", a, b);
}


Measured memory_bytes: 1736
#include<stdio.h>
int main(void){
	int x,y;
	for(;;){
		scanf("%d %d",&x,&y);
		if(x==0&&y==0){
			break;
		}
		if(x<y){
			printf("%d %d\n",x,y);
		}else{
			printf("%d %d\n",y,x);
		}
	}
	return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
using namespace std;
int main() {
int k,s,count;
cin>>k>>s;
count=0;
for(int x=0;x<=k;x++){
  for(int y=0;y<=k;y++){
      if(s>=x+y && k+x+y>=s)count++;
      }
      }
cout<<count<<endl;
return 0;
}
 

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

using namespace std;
int main(){
    string to_be_changed;
    string refer;

    cin >> to_be_changed;
    cin >> refer;

    int count = 0, i;

    for(i = 0; i < refer.size(); i++){
        if(refer[i] != to_be_changed[i]){
            count = count + 1;
        }
    }

    printf("%d", count);
}


Measured memory_bytes: 3932
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#define rep(i, n) for(i = 0; i < n; i++)
using namespace std;
typedef pair<int, int> P;

int h, w; char s, t;
string art[50];
vector<int> et[26];

P toPos(char a) {
	int i, j;
	rep(i, h) rep(j, w) if (art[i][j] == a) return P(i, j);
	return P(-1, -1);
}

bool isConnect(char a, char b) {
	P posA = toPos(a); int yA = posA.first; int xA = posA.second;
	P posB = toPos(b); int yB = posB.first; int xB = posB.second;
	int i;
	
	if (yA == -1 || yB == -1) return false;
	if (yA == yB) {
		int y = yA;
		if (xA > xB) swap(xA, xB);
		if (art[y][xA + 1] != 'o') return false;
		if (art[y][xB - 1] != 'o') return false;
		for (i = xA + 2; i <= xB - 2; i++) {
			if (art[y][i] != '-') return false;
		}
		return true;
	}
	if (xA == xB) {
		int x = xA;
		if (yA > yB) swap(yA, yB);
		if (art[yA + 1][x] != 'o') return false;
		if (art[yB - 1][x] != 'o') return false;
		for (i = yA + 2; i <= yB - 2; i++) {
			if (art[i][x] != '|') return false;
		}
		return true;
	}
	return false;
}

int main() {
	int i, j, k;
	
	cin >> h >> w >> s >> t;
	for (i = 0; i < h; i++) cin >> art[i];
	
	for (i = 0; i < 26; i++) {
		for (j = i + 1; j < 26; j++) {
			if (isConnect('A' + i, 'A' + j)) {
				et[i].push_back(j);
				et[j].push_back(i);
			}
		}
	}
	
	int dist[26][26], INF = 114514;
	rep(i, 26) rep(j, 26) dist[i][j] = INF;
	rep(i, 26) dist[i][i] = 0;
	rep(i, 26) rep(j, et[i].size()) dist[i][et[i][j]] = 1;
	rep(k, 26) rep(i, 26) rep(j, 26) dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
	cout << dist[s - 'A'][t - 'A'] << endl;
	return 0;
}


Measured memory_bytes: 3208
import sys
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
read = sys.stdin.buffer.read
sys.setrecursionlimit(10 ** 7)


X = int(readline().rstrip())

money = 100
answer = 0
while True:
    answer += 1
    money = int(money * 1.01)
    if money >= X:
        break
print(answer)

Measured memory_bytes: 9240
#include<iostream>
#include<map>
#include<algorithm>
using namespace std;
map<pair<int,int>,int>mp;
int r[1000009],c[1000009];
pair<int,int>r1[1000009],c1[1000009];
bool cmp( pair <int ,int > x , pair<int,int >y){
         return x.second>y.second;
}

int main(){
    int n,m,s;
    cin>>n>>m>>s;
    for(int i=1;i<=s;i++){
        int x,y;
        cin>>x>>y;
        r[x]++;
        c[y]++;
        mp[make_pair(x,y)]=1;
    }
    for(int i=1;i<=n;i++){
        r1[i]=make_pair(i,r[i]);
        
    }
    for(int i=1;i<=m;i++)
    c1[i]=make_pair(i,c[i]);
    sort(r1+1,r1+1+n,cmp);
    sort(c1+1,c1+m+1,cmp);
    for(int i=1;r1[i].second==r1[1].second;i++){
        for(int j=1;c1[j].second==c1[1].second;j++){
            if(!mp[make_pair(r1[i].first,c1[j].first)]){
                cout<<r1[1].second+c1[1].second;
                system("pause");
                return 0;
            }
        }
    }
    
        cout<<r1[1].second+c1[1].second-1;
    
    system("pause");
}


Measured memory_bytes: 29452
#include <stdio.h>


int main() {

    int x, y, z;
    scanf("%d %d %d", &x, &y, &z);

    int cnt = 0;
    if (x - y - z * 2 >= 0) {
        cnt++;
        int nokori = x - y - z * 2;
        cnt += nokori / (y + z);

    }

    printf("%d", cnt);
    return 0;
}


Measured memory_bytes: 1708
#include <iostream>
#include <string>
#include <algorithm>
#include <ctime>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cassert>
#include <bitset>
#include <list>
#include <cstdio>
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <math.h>
#include <cmath>
#include <tuple>
#include <cassert>
#include <array>
#include <iomanip>

using namespace std;
using pii = pair<int, int>;
using ti = tuple<int, int, int>;

const double eps=1e-14;
const int mod = 1e9 + 7;
const int inf = ((1<<30));
const long long linf = (1LL<<60);

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    int n = s.size();
    vector<int> a(n+1);
    for(int i=0; i<n; i++)
    {
        if(s[i] == '<') a[i+1] = max(a[i+1], a[i]+1);
    }
    for(int i=n-1; i>=0; i--)
    {
        if(s[i] == '>') a[i] = max(a[i], a[i+1]+1);
    }
    long long ans = 0;
    for(int i=0; i<=n; i++) ans += a[i];
    cout << ans << endl;
    return 0;
}



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

using namespace std;
using ll = long long;
using pii = pair<int, int>;

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  int dp[31] = {};
  dp[0] = dp[1] = 1;
  dp[2] = 2;
  for (int i = 3; i <= 30; i++) {
    for (int j = i - 3; j < i; j++) {
      dp[i] += dp[j];
    }
  }
  int n;
  while (cin >> n, n) {
    cout << dp[n] / (10 * 365) + 1 << endl;
  }

  return 0;
}


Measured memory_bytes: 3128
"""
A
"""
import sys

S=list(input())
N=len(S)
if N%2==1:
    print("No")
    sys.exit()
for i in range(N):
    if i%2==0 and S[i]=="h":
        continue
    elif i%2==1 and S[i]=="i":
        continue
    else:
        print("No")
        sys.exit()
print("Yes")
        

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

int main(){
  int n,k;
  cin >> n >> k;
  string s;
  cin >> s;
  int i;
  int zero=1,one=1,c=-1,d=0,e=0;
  int kata[100000][2] = {0};
  for (i = 0;i < n-1;i++){
    if(s[i] == '0' && s[i+1] == '0'){
      zero++;
    }else if(s[i] == '1' && s[i+1] == '1'){
      one++;
    }else if(s[i] == '1' && s[i+1] == '0'){
           c++;
      kata[c][0] = 1;
      kata[c][1] = one;
      one = 1;
 
      d++;
    }else if(s[i] == '0' && s[i+1] == '1'){
           c++;
      kata[c][0] = 0;
      kata[c][1] = zero;
      zero = 1;
      e++;
    }
  }
  if(s[n-1] == '1'){
    kata[c+1][0]=1;
    kata[c+1][1] = one;
  }else{
        kata[c+1][0]=0;
    kata[c+1][1] = zero;
  }
  if(d < k-1 || e < k){
    cout << n << endl;
    return 0;
  }
  int x=0,y = 0,z=0,j =0,f =0;
  for (i = 0;i < n;i++){
    if(kata[i][1] ==0){
      break;
    }
    x += kata[i][1];
    if(kata[i][0] == 0){
      y++;
    }else{
      z++;
    }
    while(y > k && z > k-1){
      x -= kata[j][1];
      if(kata[j][0] == 0){
        y--;
      }else{
        z--;
      }
      j++;
    }
    if(x > f)f = x;
  }
  cout << f << endl;
}

Measured memory_bytes: 1280
#include"bits/stdc++.h"
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define eb emplace_back

using ll = long long;
using vll = vector<ll>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using P = pair<int, int>;
using Pll = pair<ll, ll>;

vvi to;
vi visited;

void dfs(int v){
    visited[v] = 1;
    for(auto u : to[v]){
        if(visited[u] == 1)continue;
        dfs(u);
    }    
    return;
}

void Main() {
    // ABC126 - E - 1 or 2 // 
    int n, m; cin >> n >> m;
    to.resize(n);
    visited.resize(n, -1);
    
    rep(i, m){
        int a, b, z;
        cin >> a >> b >> z;
        a--; b--;
        to[a].pb(b); to[b].pb(a);
    }
    
    int cnt = 0;
    rep(i, n){
        if(visited[i] == -1){
            dfs(i);
            cnt++;
        }
    }    
    cout << cnt << endl;
	return;
}

int main() {
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
	return 0;
}

Measured memory_bytes: 9216
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

int main(){

  int k,n;

  cin >> n >> k;

  vector<int> l(n);
  
  for(int i=0;i<n;i++)cin >> l[i];

  sort(l.begin(),l.end());
  
  //for(int i=0;i<n;i++)cout << l[i] << endl;
  
  int sum=0;
  // cout << sum << endl;
  for(int i=0;i<k;i++) sum+=l[n-i-1];
  
  cout << sum << endl;
  
  return 0;
}


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

using namespace std;

#define FOR(i, n) for(int i = 0; i < (int) n; i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define PB push_back
#define F first
#define S second

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

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

	int n; cin >> n;
	vi v(n); FOR(i, n) cin >> v[i];

	map<int, int> cnt;
	FOR(i, n) cnt[v[i]]++;

	ll ans = 0;
	for(int i = 0; i < n; i++){
		int div = 0;
		for(int j = 1; j*j <= v[i]; j++){
			if(v[i]%j == 0){
				div += cnt[j];
				if(j*j != v[i]){
					div += cnt[v[i]/j];
				}
			}
		}
		div--;
		if(div == 0) ans++;
	}

	cout << ans << '\n';

	return 0;
}


Measured memory_bytes: 32904
#define _USE_MATH_DEFINES
#include<iostream>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<string>
#include<set>
#include<map>
#include<stdbool.h>
#include<math.h>
#include<sstream>
#include<math.h>
#include<vector>
#include<functional>
#include<queue>
#include<utility>
#include<bitset>
typedef long long ll;
#define N (1000000000+7)
#define INF 1e16
using namespace std;
typedef pair<ll, ll> P;
ll dp[100010][2];

int main(void) {
	string s;
	for (int i = 0;i < 100010;i++)
		for (int j = 0;j < 2;j++)dp[i][j] = -1;
	cin >> s;
	int i = 1;
	dp[1][0] = 2;
	dp[1][1] = 1;
	for (int i = 1;i < s.length();i++) {
		ll d = s[i] - '0';
		dp[i + 1][0] = dp[i][0] * (d ? 2 : 1) % N;
		dp[i + 1][1] = dp[i][1] * 3 % N;
		dp[i + 1][1] = (dp[i + 1][1] + dp[i][0] * (d ? 1 : 0)) % N;
	}
	cout << (dp[s.length()][0] + dp[s.length()][1])%N << endl;
	return 0;
}

Measured memory_bytes: 2176
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <climits>
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

#define INF INT_MAX/3
#define REP(i,n) for(int i=0;i<n;i++)

int main(){
	int a,b,c;
	cin>>a>>b>>c;
	
	int ab,ac,bc;
	ab = a+b;
	ac = a+c;
	bc = b+c;
	
	if(ab == c || ac == b || bc == a){
		cout<<"Yes"<<endl;
	}
	else{
		cout<<"No"<<endl;
	}


	return 0;
}


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

int main() {
  int A, B;
  int count = 0;
  cin >> A >> B;
  for(int i = A; i <= B; ++i){
    int s = i%10;
    int v = i/10000%10;
    int u = i/10%10;
    int w = i/1000%10;
    if(s==v && u == w) ++count;
  }
  cout << count << endl;
}

Measured memory_bytes: 256
def slove():
    import sys
    input = sys.stdin.readline
    n = int(input().rstrip('\n'))
    s = str(input().rstrip('\n'))
    t = str(input().rstrip('\n'))
    l = n * 2
    for i in range(n):
        if s[-i-1:] == t[:i+1]:
            l = n * 2 - (i + 1)
    print(l)


if __name__ == '__main__':
    slove()


Measured memory_bytes: 38384
def Multiplication_2():
    N = int(input())
    An = list(map(int,input().split()))

    if 0 in An:
        return 0
    
    over = 10 ** 18

    ans = 1
    
    for i in An:
        ans *= i
        if ans > over:
            return -1
        #print(ans)
    
    return ans

print(Multiplication_2())

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

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

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

#define ll long long
#define rep(i,x,y) for(int i=x;i<y;i++)
#define rel(i,x,y) for(int i=x-1;i>=y;i--)
#define all(x) x.begin(),x.end()

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    int n; cin >> n;
    vector<ll> a(n);
    rep(i,0,n) cin >> a[i];
    ll l[n],r[n]; //累積gcd 
    l[0] = a[0];
    r[n-1] = a[n-1];
    rep(i,1,n) l[i] = gcd(l[i-1],a[i]);
    rel(i,n-1,0) r[i] = gcd(r[i+1],a[i]);
    ll ma = max(l[n-2],r[1]);
    rep(i,0,n-2){
        ma = max(ma,gcd(l[i],r[i+2]));
    }
    cout << ma << endl;
}


Measured memory_bytes: 2560
#include<bits/stdc++.h>
#define ll long long int
#define mp make_pair
#define pb push_back
#define ff first 
#define ss second
#define mod 1000000007
#define lim 100005
#define nfs_mw ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;

int m;
vector<int> gr[lim];
ll dp[lim] = {}, dp2[lim] = {};

void dfs(int u, int pa){
	dp[u] = 1;
	for(int v:gr[u]) if(v!=pa){
		dfs(v,u);
		dp[u] = (dp[u]*dp[v])%m;
	}
	dp[u] = (dp[u] + 1)%m;
}

void dfs2(int u, int pa, ll val = 1)
{
	dp2[u] = val;
	int i,chz;
	vector<int> ch;
	for(int v:gr[u]) if(v!=pa){
		ch.pb(v);
		dp2[u] = (dp2[u]*dp[v])%m;
	}
	chz = ch.size();
	ll left[chz] = {}, right = val; left[0] = 1;
	for(i=0; i<chz-1; i++) left[i+1] = (left[i]*dp[ch[i]])%m;
	for(i=chz-1; i>=0; i--){
		dfs2(ch[i], u, (((left[i]*right)%m)+1)%m);
		right = (right*dp[ch[i]])%m;
	}
}

int main()
{
	int i,j,n,u,v,ans = 0;
	cin>>n>>m;
	
	for(i=1; i<n; i++){
		cin>>u>>v;
		gr[u].pb(v);
		gr[v].pb(u);
	}
	
	dfs(1,0);
	dfs2(1,0);

	for(i=1; i<=n; i++) cout<<dp2[i]<<"\n";
}

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

namespace AIZU {
	class Program {
		static int cin() { return cin(-1); }
		static int cin(int D) {
			string s = Console.ReadLine();
			if (string.IsNullOrEmpty(s))
				return D;
			return int.Parse(s);
		}
		static int[] cins(char spliter) {
			string s = Console.ReadLine();
			if (string.IsNullOrEmpty(s))
				return new int[] { };
			string[] ss = s.Split(spliter);
			int[] Res = new int[ss.Length];
			for (int i = 0; i < ss.Length; i++)
				Res[i] = int.Parse(ss[i]);
			return Res;
		}
		static void print(object j) { Console.WriteLine(j.ToString()); }
		static void print(string j) { Console.WriteLine(j); }

		static void Main(string[] args) {
			var ManPoint = new int[100];
			var Points = new List<int>();
			int[] I;
			while (true) {
				I = cins(',');
				if (I[0] == 0 && I[1] == 0)
					break;
				ManPoint[I[0] - 1] = I[1];
				if (!Points.Contains(I[1]))
					Points.Add(I[1]);
			}
			var table = Points.OrderByDescending(i=>i).ToList();
			int h,res;
			while (true) {
				h = cin();
				if (h == -1)
					break;
				res = table.IndexOf(ManPoint[h-1])+1;
				print(res);
			}
		}

		static bool Palindrome(string s) {
			return s==new string(s.Reverse().ToArray());
		}
	}
}

Measured memory_bytes: 10052
# include "bits/stdc++.h"
using namespace std;
using LL = long long;
using ULL = unsigned long long;
const double PI = acos(-1);
template<class T>constexpr T INF() { return ::std::numeric_limits<T>::max(); }
template<class T>constexpr T HINF() { return INF<T>() / 2; }
template <typename T_char>T_char TL(T_char cX) { return tolower(cX); };
template <typename T_char>T_char TU(T_char cX) { return toupper(cX); };
typedef pair<LL, LL> pii;
const int vy[] = { -1, -1, -1, 0, 1, 1, 1, 0 }, vx[] = { -1, 0, 1, 1, 1, 0, -1, -1 };
const int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
int popcnt(unsigned long long n) { int cnt = 0; for (int i = 0; i < 64; i++)if ((n >> i) & 1)cnt++; return cnt; }
int d_sum(LL n) { int ret = 0; while (n > 0) { ret += n % 10; n /= 10; }return ret; }
int d_cnt(LL n) { int ret = 0; while (n > 0) { ret++; n /= 10; }return ret; }
LL gcd(LL a, LL b) { if (b == 0)return a; return gcd(b, a%b); };
LL lcm(LL a, LL b) { LL g = gcd(a, b); return a / g*b; };
# define ALL(qpqpq)           (qpqpq).begin(),(qpqpq).end()
# define UNIQUE(wpwpw)        sort(ALL((wpwpw)));(wpwpw).erase(unique(ALL((wpwpw))),(wpwpw).end())
# define LOWER(epepe)         transform(ALL((epepe)),(epepe).begin(),TL<char>)
# define UPPER(rprpr)         transform(ALL((rprpr)),(rprpr).begin(),TU<char>)
# define FOR(i,tptpt,ypypy)   for(LL i=(tptpt);i<(ypypy);i++)
# define REP(i,upupu)         FOR(i,0,upupu)
# define INIT                 std::ios::sync_with_stdio(false);std::cin.tie(0)

int N, W;
LL w[101], v[101];
LL dp[101010];

int main(){
    INIT;
    cin >> N >> W;
    REP(i, 101010)dp[i] = -HINF<LL>();
    dp[0] = 0;
    REP(i, N){
        cin >> w[i] >> v[i];
        for(int j = W; j >= w[i];j--){
            dp[j] = max(dp[j], dp[j - w[i]] + v[i]);
        }
    }
    LL ans = -1;
    REP(i, W + 1){
        ans = max(ans, dp[i]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 1024
class Tree():
    def __init__(self):
        self.parent = -1
        self.depth = 0
        self.child = []


n = int(input())
tree = [Tree() for i in range(n)]

for i in range(n):
    cmd = list(map(int, input().split()))
    node = tree[cmd[0]]
    node.child.extend(cmd[2:])
    for j in cmd[2:]:
        tree[j].parent = cmd[0]

for j in tree:
    d, p = 0, j.parent
    while p != -1:
        d += 1
        p = tree[p].parent
    j.depth = d

for count in range(n):
    j = tree[count]

    if j.parent == -1:
        state = "root"
    elif j.child:
        state = "internal node"
    else:
        state = "leaf"

    print("node {}: parent = {}".format(count, j.parent), "depth = {}".format(
        j.depth), state, "[{}]".format(", ".join(map(str, j.child))), sep=", ")



Measured memory_bytes: 40416
#include <bits/stdc++.h>
using namespace std;
#define INCANT cin.tie(0), cout.tie(0), ios::sync_with_stdio(0), cout << fixed << setprecision(20);
#define int long long
#define double long double
const int INF = 1e18, MOD = 998244353;

vector<int> fact;

void modinit(int n) {
    fact.push_back(1);
    int now = 1;
    for (int i = 1; i <= n; i++) {
        now *= i;
        now %= MOD;
        fact.push_back(now);
    }
}

int modpow(int x, int n) {
    return n == 0 ? 1 : modpow(x * x % MOD, n / 2) * (n % 2 ? x : 1) % MOD;
}

int modcomb(int n, int r) {
    if (n < r) return 0;
    return fact[n] * modpow(fact[n - r], MOD - 2) % MOD * modpow(fact[r], MOD - 2) % MOD;
}

signed main() {
    int n, m, k;
    cin>>n>>m>>k;
    int res = 0;
    modinit(222222);
    for (int i = 0; i <= k; i++) {
        res += m * modcomb(n - 1, i) % MOD * modpow(m - 1, n - i - 1) % MOD;
        res %= MOD;
    }
    cout<<res<<endl;
}

Measured memory_bytes: 5324
#include<iostream>
#include<cstdio>
#include<iomanip>
using namespace std;
double a[200001],s[200001],ans=-1e9;
int main()
{
	int n,k;
	cin>>n>>k;
	for(int i=1;i<=n;i++)
	{
		scanf("%lf",&a[i]);
		a[i]=(1+a[i])/2;
		s[i]=s[i-1]+a[i];
	}
	for(int i=0;i<=n-k;i++)
	{
		ans=ans>s[i+k]-s[i]?ans:s[i+k]-s[i];
	}
	cout<<fixed<<setprecision(15)<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3328
H, W, K = map(int, input().split())
mod = 1000000007

dp = [[0 for _ in range(W)] for _ in range(H+1)]
dp[0][0] = 1

for h in range(H):
  cnt = 0
  while cnt < (1<<(W-1)):
    if '11' not in format(cnt, 'b'):
      for w in range(W):
        if w>0 and (cnt>>(w-1)) & 1:
          dp[h+1][w-1] += dp[h][w]
        elif w<W-1 and (cnt>>w) & 1:
          dp[h+1][w+1] += dp[h][w]
        else:
          dp[h+1][w] += dp[h][w]
    cnt += 1

print(dp[-1][K-1] % mod)


Measured memory_bytes: 3188
//ｺｯwwｺｯwwｺｹｯwwwｺｯwwｺｹｯwwwｺｹｯｺｯwwwｺｯwwｺｯwwｺｹｯwwwｺｯwwｺｹｯwwwｺｹｯｺｯwwwｺｹｰｰｰｰｯ!!!wwwwwｺｯwwｺｯwwｺｹｯwwwｺｯwwｺｹｯwwwｺｹｯｺｯwwwｺｯwwｺｯwwｺｹｯwwwｺｯwwwｺｹｯwwwｺｹｯｺｯwwwｺｹｰｰｰｰｯ!!!wwwwwｺｹｯｺｯｯｺｰｰｰｰ!!!!!!wwwwwwwwwww
import java.util.*;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        if(a + b >= 10){
            System.out.println("error");
        }else{
            System.out.println(a + b);
        }
    }
}

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

int main()
{
	int h[10];
	for (int i = 0; i < 10; ++i) cin >> h[i];
	sort(h, h+10, greater<int>());
	
	cout << h[0] << endl << h[1] << endl << h[2] << endl;
	
	return 0;
	
}

Measured memory_bytes: 0
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);


		int N = sc.nextInt();
		
		ArrayList<Integer> a = new ArrayList<Integer>();
		
		for(int i = 0 ; i< N ; i++) {
			
			a.add(sc.nextInt());
			
		}
		
		ArrayList<Integer> b = (ArrayList<Integer>)a.clone();
		
		
		Collections.sort(b, Collections.reverseOrder());
		
		for(int i = 0; i< N ; i++) {
			
			if(a.get(i) == b.get(0)){
				System.out.println(b.get(1));
			} else {
				System.out.println(b.get(0));
			}	
		}
		

	}

}

Measured memory_bytes: 102568
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<int,int> P;
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; }
const LL mod=1000000007;
const LL LINF=1LL<<60;
const int INF=1<<30;
int dx[]={1,0,1,-1,1,-1,-1,0};
int dy[]={0,1,1,-1,-1,1,0,-1};




int main(){
    int a,b;cin >> a >> b;
    cout << (a==b?"Yes":"No") << endl;
    return 0;
}


Measured memory_bytes: 256
import itertools
import math
import fractions
import functools
import copy
n, k = map(int, input().split())

sum = 0
for i in range(1,n+1):
    score = i
    count = 0
    while score < k:
        score *= 2
        count += 1
    sum += (1/n) * (1/2) ** count

print(sum)


Measured memory_bytes: 65388
#include <iostream>

using namespace std;

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

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

    while(n > 0){
        if(n - i >= 0){
            cout << i << '\n';
            n -= i;
        }
        i--;
    }
}

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

using namespace std;

#define mp make_pair
#define pb push_back
#define fi first
#define se second

typedef int def; //default parameter for loops

#define fori(a) for(def i=0; i<(a); i++)
#define fori1(a) for(def i=1; i<=(a); i++)
#define fori_(a) for(def i=(a)-1; i>=0; i--)
#define fori1_(a) for(def i=(a); i>0; i--)
#define forii(a, b) for(def i=(a); i<(b); i++)
#define forii_(a, b) for(def i=(b)-1; i>=(a); i--)

#define forj(a) for(def j=0; j<(a); j++)
#define forj1(a) for(def j=1; j<=(a); j++)
#define forj_(a) for(def j=(a)-1; j>=0; j--)
#define forj1_(a) for(def j=(a); j>0; j--)
#define forjj(a, b) for(def j=(a); j<(b); j++)
#define forjj_(a, b) for(def j=(b)-1; j>=(a); j--)

#define fork(a) for(def k=0; k<(a); k++)
#define fork1(a) for(def k=1; k<=(a); k++)
#define fork_(a) for(def k=(a)-1; k>=0; k--)
#define fork1_(a) for(def k=(a); k>0; k--)
#define forkk(a, b) for(def k=(a); k<(b); k++)
#define forkk_(a, b) for(def k=(b)-1; k>=(a); k--)

#define forl(a) for(def l=0; l<(a); l++)
#define forl1(a) for(def l=1; l<=(a); l++)
#define forl_(a) for(def l=(a)-1; l>=0; l--)
#define forl1_(a) for(def l=(a); l>0; l--)
#define forll(a, b) for(def l=(a); l<(b); l++)
#define forll_(a, b) for(def l=(b)-1; l>=(a); l--)

#define forg(a) for(def g=0; g<(a); g++)
#define forg1(a) for(def g=1; g<=(a); g++)
#define forg_(a) for(def g=(a)-1; g>=0; g--)
#define forg1_(a) for(def g=(a); g>0; g--)
#define forgg(a, b) for(def g=(a); g<(b); g++)
#define forgg_(a, b) for(def g=(b)-1; g>=(a); g--)

#define forf(a) for(def f=0; f<(a); f++)
#define forf1(a) for(def f=1; f<=(a); f++)
#define forf_(a) for(def f=(a)-1; f>=0; f--)
#define forf1_(a) for(def f=(a); f>0; f--)
#define forff(a, b) for(def f=(a); f<(b); f++)
#define forff_(a, b) for(def f=(b)-1; f>=(a); f--)

#define forh(a) for(def h=0; h<(a); h++)
#define forh1(a) for(def h=1; h<=(a); h++)
#define forh_(a) for(def h=(a)-1; h>=0; h--)
#define forh1_(a) for(def h=(a); h>0; h--)
#define forhh(a, b) for(def h=(a); h<(b); h++)
#define forhh_(a, b) for(def h=(b)-1; h>=(a); h--)

#define fastIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define endl '\n'

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;

template <typename T>
std::ostream& operator<< (std::ostream& out, const std::vector<T>& v) {
  if ( !v.empty() ) {
    std::copy (v.begin(), v.end(), std::ostream_iterator<T>(out, " "));
  }
  return out;
}
template <typename T>
std::ostream& operator<< (std::ostream& out, const std::set<T>& v) {
  if ( !v.empty() ) {
    std::copy (v.begin(), v.end(), std::ostream_iterator<T>(out, " "));
  }
  return out;
}

const int N = 1e5+10;
const ll M = 1e9+7;

bool isDiv(int x){
	int d = 0;
	fori1(x)d+=x%i==0;
	return d==8;
}

int main(){
	fastIO;
	int n;
	cin>>n;
	int ans = 0;
	for(int i=1; i<=n; i+=2){
		ans+=isDiv(i);
	}
	cout<<ans;
}


Measured memory_bytes: 256
import math
rad=0
x=0
y=0
while True:
    try:
        r,c=map(int,raw_input().split(','))
    except EOFError:
        break
    
    x+=math.cos(rad)*r
    y+=math.sin(rad)*r
    rad+=c*math.pi/180
    
print int(y)
print int(x)

Measured memory_bytes: 4416
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = int(A); I < int(B); ++I)
#define FORR(I,A,B) for(ll I = int((B)-1); I >= int(A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //xi>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //xi>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd(ll a,ll b){if(a<b)swap(a,b);if(a%b==0)return b;return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}//saisyo kobaisu
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=1e18+7;
const ll MOD=1e9+7;

vector<ll> yakusu(ll x){
	vector<ll> ans;
	if(x==1){return {1};}
	ll p=x;
	ans.push_back(1);
	for(ll i=2;i*i<=x;i++){
		ll j=0,l=1;
		while(p%i==0){
			p /= i;
			j++;
		}
		vector<ll> s=ans;
		for(ll k=0;k<j;k++){
			l*=i;
			for(auto y:ans){
				s.push_back(y*l);
			}
		}
		ans = s;
	}
	if(p!=1){
		vector<ll> s=ans;
		for(auto x:ans){
			s.push_back(x*p);
		}
		ans = s;
	}
	sort(ans.begin(),ans.end());
	return ans;
}

int main(){
	ll N,ans=0;
	cin >> N;
	vector<ll> a(N);
	FOR(i,0,N)cin>>a[i];
	FOR(i,0,2){
		for(auto x:yakusu(a[i])){
			ll k = 0;
			FOR(j,0,N){
				if(a[j]%x==0)k++;
			}
			if(k>=N-1){
				ans = max(ans,x);
			}
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 1024
/*
ID: thanhvq1
LANG: C++14
PROB: namenum
*/

#pragma GCC optimize ("O2")
#include<bits/stdc++.h>
#include<unistd.h>
using namespace std;

// defines
#define int long long
typedef long long ll;
#define double long double
#define vec vector
#define vi vector<int>
#define vvi vector<vector<int>>
#define FZ(n) memset((n),0,sizeof())
#define FMO(n) memset((n),-1,sizeof(n))
#define unset unordered_set
#define ii pair<int, int>
#define vii vector<ii>
#define F first;
#define S second
#define mp make_pair
#define PB push_back
#define ALL(x) begin(x),end(x)
#define SZ(x) ((int)(x).size())
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define FORE(i, a, b) for(int i = (a); i <= (b); i++)
#define FORD(i, a, b) for(int i = (a); i >= (b); i--)
#define bitcount(n) __builtin_popcountll(n)
#define reset(x, y) memset(x, y, sizeof(x))
#define uni(x) (x).erase(unique(all(x)), (x).end());
#define BUG(x) cerr << #x << " = " << (x) << endl
#define chkmin(a, b) a = min(a, b)
#define chkmax(a, b) a = max(a, b)
#define max3(a, b, c) max(a, b) > max(b, c) ? max(a, b) : max(b, c)
#define min3(a, b, c) min(a, b) < min(b, c) ? min(a, b) : min(b, c)

//permanent constants
const long long ZERO = 0LL;
const long long INF64 = 1e18;
const int INF32 = 1e9;
const int MOD = 998244353; //1e9 + 7;  const ll MOD2 = (ll)MOD * (ll)MOD;
const double PI = 2.0*acos(0.0); //acos(-1.0L);
const double EPS = static_cast<double>(1e-10);
const int day[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int dx[4] = {0, 1, 0, -1}; const int dy[4] = {1, 0, -1, 0};
//const ll INF = (ll)(1e18 + 239);
const int BIG = (int)(1e9 + 239);

//random
mt19937 rnd(239); //(chrono::high_resolution_clock::now().time_since_epoch().count());

void FILEIO() {  freopen("in.txt", "r", stdin);  freopen("out.txt", "w", stdout); }
//void FILEIO() {  freopen("namenum.in", "r", stdin);  freopen("namenum.out", "w", stdout); }
void input() {   }

void solve() {
	int n; cin >> n;
	vi a(n), b; FOR(i, 0, n) cin >> a[i];
	b = a; sort(ALL(a));
	FOR(i, 0, n) {
		if(b[i]==a[n-1]) cout << a[n-2] << endl;
		else cout << a[n-1] << endl;
	}

}

signed main() {
  ios_base::sync_with_stdio(false); cin.tie();
//  FILEIO();
//auto beginProgram = chrono::steady_clock::now();

//  int test = 0;
//  string s; getline(cin, s); int t = stoi(s);
//  while(t--)
  {
//	  cout << "Case " << ++test << ": ";
	  solve();
  }

  //auto endProgram = chrono::steady_clock::now();

  return 0;
}


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

#define  ll  long long
#define  pii pair<int,int>
#define  pll pair<ll , ll>
#define  debug cout << "this far" << endl;
#define  For(i, n) for(int i = 0; i < (n); ++i)
#define  lsb(x) ((x) & (-x))
#define  PI acos(-1)
#define  line cout << endl;
#define  getbit(n, i) (((n) & (1LL << (i))) != 0)
#define  resetbit(n, i) ((n) & (~(1LL << (i))))
#define  setbit(n, i) ((n) | (1LL << (i)))
#define  togglebit(n, i) ((n) ^ (1LL << (i)))
#define  gap " "
using namespace std;
const int N = 1e6;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int  n ;  cin >> n ;
    int a[n] ;
    for(int i = 0 ; i  < n;  ++i) cin >> a[i];
    int cr_max = 0 ;
    ll ans = 0 ;
    for(int i = 0 ; i < n ; ++i) {
        if(a[i] < cr_max ) {
            ans += (cr_max - a[i]) ;
        }
        cr_max = max(cr_max , a[i]) ;
    }
    cout << ans;

}

Measured memory_bytes: 4400
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
typedef unsigned long long int ulli;
typedef long double ld;
#define vec(s) vector

#define vvec(s) vector<vector
>
typedef vector<lli> vi;
typedef vector<vi> vvi;
typedef pair<lli, lli> pii;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define Yes(x) cout<<(x?"Yes":"No")<<endl;
#define YES(x) cout<<(x?"YES":"NO")<<endl;
#define out(s) cout<<s<<endl;
#define pb(s) push_back(s);
#define sp " " 
#define INF 10000000000
#define LINF 9000000000000000000
#define all(s) s.begin(),s.end()
void vout(vi v) {
    for (lli i=0;i<v.size();i++)
        cout<<v.at(i)<<endl;
}
int main() {
    cout << std::fixed << std::setprecision(10);
    map<string, vec(pii)> rec;
    lli n;
    cin>>n;
    rep(i, n) {
        string p;
        lli q;
        cin>>p>>q;
        if (!rec.count(p)) {
            vec(pii) r={ pii(q,i) };
            rec[p]=r;
        }
        else {
            rec[p].push_back(pii(q,i));
        }
    }
    for (auto v:rec) {
        sort(all(v.second));
        reverse(all(v.second));
            rep(i, v.second.size()) {
                out(v.second[i].second+1);
        }
    }
}

Measured memory_bytes: 3728
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
using namespace std;

int main() {
    int n, m, x, y, i, j;
    cin >> n >> m >> x >> y;
    int dataX[n];
    int dataY[m];
    for (i = 0; i < n; i++) {
        cin >> dataX[i];
    }
    for (i = 0; i < m; i++) {
        cin >> dataY[i];
    }
    int checkFlag = 0;
    for (j = x + 1; j <= y; j++) {
        for (i = 0; i < n; i++) {
            if (dataX[i] < j) {
                checkFlag++;
                // cout << "dataX[" << i << "] = " << dataX[i] << endl;
                // cout << "j = " << j << endl;
            }
        }
        for (i = 0; i < m; i++) {
            if (dataY[i] >= j) {
                checkFlag++;
                // cout << "dataY[" << i << "] = " << dataY[i] << endl;
                // cout << "j = " << j << endl;
            }
        }
        //cout << "checkFlag = " << checkFlag << endl;
        if (checkFlag == (n + m)) {
            cout << "No War" << endl;
            return 0;
        }
        checkFlag = 0;
    }
    cout << "War" << endl;    
    return 0;
}

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

//define gcd and lcm (using 64bit)
ll gcd(ll a,ll b){
    if (a < b) {
        //^はxor(bitwise operator)。以下三行でswap(a,b)を行っている。
        a ^= b;
        b ^= a;
        a ^= b;
    }
    //only when b==0,this program finds that b means false and returns a.
    return b ? gcd(b, a % b) : a;
}

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


int n;

void dfs(string s, char t){
    if(s.size()==n){
        cout<<s<<endl;
        return;
    }
    for(char i='a'; i<=t+1; ++i){
        string u=s;
        u+=i;
        dfs(u,max(t,i));
    }
}

int main(){
    cin>>n;
    dfs("a",'a');
    return 0;
}

Measured memory_bytes: 1536
#include <stdio.h>

int main(void)
{
  int h,w,k;
  int ans = 0;
  scanf("%d %d %d",&h,&w,&k);
  
  char c[h][w];
  for(int i=0; i<h; i++)
      scanf("%s",c[i]);
  
  for(int a=0; a < (1 << h); a++){
    for(int b=0; b < (1 << w); b++){
      int black = 0;
      for(int i=0; i<h; i++){
        for(int j=0; j<w; j++){
          if(((a >> i) & 1) && ((b >> j) & 1) && (c[i][j] == '#'))
            black++;
        }
      }
      if(black == k)
        ans++;
    }
  }
  printf("%d\n",ans);
  
  return 0;
} 

Measured memory_bytes: 1712
n, m = map(int, input().split())
A = list(map(int, input().split()))

all_vote = sum(A)

cnt = 0

for a in A:
    #if a >= all_vote / (4*m):
    if a * 4 * m >= all_vote:   #小数になる可能性をなくした
        cnt += 1
if cnt >= m:
    print('Yes')
else:
    print('No')

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

#define range 100005
#define mod 1000000007
#define eps 1e18
#define PI 3.14159265358979323846
#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define ALL(V) V.begin(), V.end()
#define _ <<" "<<

using namespace std;

typedef long long ll;
typedef vector <int> vi;
typedef vector<vi> vvi;
typedef pair <int, int> ii;
typedef pair<int, pair<int,int> > iii;
typedef vector<ii> vii;
typedef vector<iii> viii;

int dp[200000];

int main(int argc, char const *argv[])
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	//freopen("test.txt","r",stdin);
	int n;
	cin>>n;
	int a[n];
	for(int i=0;i<n;i++)
		cin>>a[i];
	dp[1] = fabs(a[1] - a[0]);
	for(int i=2;i<n;i++)
		dp[i] = min(dp[i-1] + fabs(a[i] - a[i-1]),dp[i-2] + fabs(a[i] - a[i-2]));
	cout<<dp[n-1];
	return 0;
}

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

typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
using namespace std;

//ループマクロ
#define FOR(i , a , b)  for(int i = (a) ; i < (b) ; i++)
#define REP(i , n)      for(int i = 0 ; i < n ; i++)
#define REPR(i , n)     for(int i = n ; 0 <= i ; i--)

//入出力
#define SCOUT(x) cout << (x) << " "
#define VECCIN(x) for(auto& ele : (x) ) cin >> ele
#define CEVCOUT(x) for(auto& ele : (x) ) cout << ele << " "; cout << endl;

//その他
#define ALL(obj) (obj).begin() , (obj).end() 
#define P pair<int , int>
#define V vector<int>
#define M map<int,int>
#define S set<int>
#define PQ priority_queue<int>
#define PQG priority_queue<int , V , greater<int>>

const long double PI = (acos(-1));
int main(void){

  long double a, b, x;  cin >> a >> b >> x;

  long double ans;
  if(x < (a*a*b) / 2.0 ){
    ans = PI / 2 - atan( (2 * x) / (a*b*b) );
  }else{
    ans = atan( 2*(a*a*b - x) / (a*a*a) );
  }

  ans = ans * 180 / PI;
  printf("%.7lf\n", (double)ans);
  
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <iomanip>
#include <cmath>
#include <cstdlib>
#include <map>
#include <utility>
#include <numeric>
#define ll long long
#define REP(i, x) for(int (i) = 0; (i) < (x); (i) ++)
#define pi 3.1415926535
const int MOD = 1000000007;
using namespace std;

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

Measured memory_bytes: 256