akhauriyash/Code-Regression huggingface dataset:
N, D = map(int, input().split())
coordinates = []
c_append = coordinates.append
count = 0

for _ in range(N):
    X = list(map(int, input().split()))
    c_append(X)

for i in range(N-1):
    for j in range(i+1, N):
        distance = 0
        tmp1 = coordinates[i]
        tmp2 = coordinates[j]
        for k in range(D):
            distance += (tmp1[k] - tmp2[k]) ** 2
        distance = distance ** (1/2)
        if distance == int(distance):
            count += 1

print(count)


Measured memory_bytes: 62456
import java.io.*;

class Main{
    public static void main(String[] args) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String str = br.readLine();
        int a = Integer.parseInt(str);
        str = br.readLine();
        int b = Integer.parseInt(str);
        str = br.readLine();
        int c = Integer.parseInt(str);
        str = br.readLine();
        int d = Integer.parseInt(str);
        str = br.readLine();
        int e = Integer.parseInt(str);
        str = br.readLine();
        int k = Integer.parseInt(str);
        if (e-a>k){
            System.out.println(":(");
        } else {
            System.out.println("Yay!");
        }
    }
}

Measured memory_bytes: 22868
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define ios ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
const int MOD = 1e9 + 7;
#define rep(i, n) for (int i = 0; i < int(n); ++i)

//-------------------ここから回答する-----------------------

void solve(void)
{
    int n;
    cin >> n;
    ll ans = n;
    while (--n > 0)
    {
        ans *= n;
        ans %= MOD;
    }
    cout << ans << endl;
}
int main(void)
{
    solve();
}


Measured memory_bytes: 3652
N = int(input())
H =list(map(int,input().split()))

ans=0
i=0

while(i<N-1):
    temp=0
    while(H[i]>=H[i+1]):
        temp+=1
        i+=1
        if(i==N-1):
            break
    ans = max(ans,temp)
    i+=1

print(ans)
    

Measured memory_bytes: 14224
n, l = map(int, input().split())

# N 個のりんごがあって、それ一つ一つの味はL + i - 1 で表される（i = 1,2,...,n）
total = n * (l + l + n - 1) // 2

# ひとつめのりんごの味はL, N個目のりんごの味はL+N-1
first, last = l, l + n - 1
# 1. 美味しいりんごだけで作る場合、もっともおいしくないりんごなら食べてもいい
if first >= 0:
  taste = total - first
# 2. まずいりんごが混ざっている時、全体が美味しければまずいものを、全体がまずければ美味しいものを食べるべき
elif first < 0 and last >= 0: 
  taste = total - 0
#  if total == 0:
#    taste = total - 0
#  elif total < 0:
#    taste = total - last
#  else:
#    taste = total - first
# 3. まずいりんごだけで作る場合、もっともまずくないりんごを食べたほうがいい
else:
  taste = total - last  

print(taste)
#print('taste is ' + str(taste))
#print('total is ' + str(total))
#print('apple is ' + str(total - taste))

Measured memory_bytes: 3060
import java.util.Scanner;
public class Main {

    public static void main(String[] args)
    {
        Scanner in = new Scanner(System.in);
        int x = in.nextInt();
        int y = in.nextInt();
        int z = in.nextInt();

        if (x == y && x!=z || y == z && y!=x || x == z && x!=y)
        {
            System.out.println("Yes");
        }
        else
        {
            System.out.println("No");
        }
    }
}


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

using namespace std;
int main(){
    int n, m;
    cin >> n >> m;
    int max_state = 1 << n;
    vector<int> prices (m, 0);
    vector<int> keys (m, 0);
    vector<vector<int>> corr (n, vector<int> {});
    for(int i = 0; i < m; i ++)
    {
        int price, nums;
        cin >> price >> nums;
        prices[i] = price;
        for(int j = 0; j < nums; j ++)
        {
            int bit;
            cin >> bit;
            keys[i] += (1 << (bit-1));
            corr[bit-1].push_back(i);
        }
    }
    vector<int> dp (max_state, 0x3f3f3f3f);
    dp[0] = 0;
    for(int state = 0; state < max_state - 1; state ++)
    {
        int x = 0;
        for(int i = 0; i < n; i ++)
        {
            if(!(state >> i & 1))
            {
                x = i;
                break;
            }
        }
        if(corr[x].size() == 0)
        {
            cout << -1 << endl;
            return 0;
        }
        for(int key: corr[x]){
            dp[state|keys[key]] = min(dp[state|keys[key]], dp[state] + prices[key]);
        }
    }
    cout << dp[max_state - 1] << endl;
    return 0;
}

Measured memory_bytes: 384
<?php

fscanf(STDIN, '%s', $str_a);
fscanf(STDIN, '%s', $str_b);

$a = str_split($str_a);
$b = str_split($str_b);

if(($a[0]==$b[2])&&($a[1]==$b[1])&&($a[2]==$b[0])){
    echo 'YES';
}else{
    echo 'NO';
}


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

int main()
{
    int n;
    cin >> n;
    if(n <= 111) cout << 111 << endl;
    else if(n <= 222) cout << 222 << endl;
    else if(n <= 333) cout << 333 << endl;
    else if(n <= 444) cout << 444 << endl;
    else if(n <= 555) cout << 555 << endl;
    else if(n <= 666) cout << 666 << endl;
    else if(n <= 777) cout << 777 << endl;
    else if(n <= 888) cout << 888 << endl;
    else if(n <= 999) cout << 999 << endl;
    return 0;
}

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

int main(void){
    ll N;
    cin>>N;
    
    ll minv=100000000000;
    
    vector<ll> A(N);
    for(int i=0;i<N;i++){
        cin>>A[i];
        minv=min(minv,A[i]);
    }
    
    

    while(minv>1){
        ll MIN = minv;
        
        for(int i=0;i<N;i++){
            
            if(A[i]%MIN !=0 && MIN > A[i]%MIN){
                MIN=A[i]%MIN;
                
            }
            
        }
        
        if(MIN==minv)break;
        minv=MIN;
    }
    
    
    
    cout<<minv<<endl;
}

Measured memory_bytes: 1024
#!/usr/bin/env python
# coding: utf-8

# In[11]:


N = int(input())
A = list(map(int, input().split()))


# In[12]:


even_list = [x for x in A if x%2 == 0]
ans = 3**len(A) - 2**(len(even_list))
print(ans)


# In[ ]:






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

int main()
{
    int n,re,flag;
    while(cin>>n)
    {
        flag=0;
        while(n!=0)
        {
            re=n%10;
            if(re==7)
            {
                flag=1;
                break;
            }
            n=n/10;
        }
        if(flag==1)
            cout<<"Yes";
        else
            cout<<"No";
    }
}


Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
	ll n,k;
	cin>>n>>k;
	ll a[n];
	ll t=0;
for(ll i=0;i<n;i++){
	cin>>a[i];
	if(a[i]>=k){
		t++;
	}
}

cout<<t;
	
	return 0;
}

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

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

#define FOR(k,m,n) for(ll (k)=(m);(k)<(n);(k)++)
#define REP(i,n) FOR((i),0,(n))
#define WAITING(str) int str;std::cin>>str;
#define DEBUGING(str) cout<< #str << " " str<<endl

constexpr int INF = (1 << 30);
constexpr ll INFL = (1ll << 60);
constexpr ll MOD = 1000000007;// 10^9+7


int main()
{
	ll N, K;
	cin >> N >> K;
	if (N == 1) {
		cout << 1 << endl;
		return 0;
	}

	ll len = sqrt(N);
	ll rlen = (len*len == N ? len - 1 : len);
	vector<ll> normal(len + 1, 1);
	normal[0] = 0;
	vector<ll> dup(len + 1, 0);
	FOR(i, 1, rlen) dup[i] = N / i - N / (i + 1);
	dup[rlen] = N / rlen - len;
	vector<ll> inv = dup;

	vector<ll> nbit(len + 1), rbit(len + 1);
	REP(i, K - 1) {
		fill(nbit.begin(), nbit.end(), 0);
		fill(rbit.begin(), rbit.end(), 0);

		FOR(i, 1, len + 1) {
			(nbit[len] += normal[i]) %= MOD;
			(rbit[i] += normal[i]) %= MOD;
		}
		FOR(i, 1, rlen + 1) {
			(nbit[i] += inv[i]) %= MOD;
		}
		REP(i, rlen)(rbit[i + 1] += rbit[i]) %= MOD;
		for (int i = len; i > 1; i--)(nbit[i - 1] += nbit[i]) %= MOD;

		FOR(i, 1, len + 1)normal[i] = nbit[i];
		FOR(i, 1, rlen + 1)inv[i] = rbit[i] * dup[i];
	}

	ll res = accumulate(normal.begin(), normal.end(), 0ll) + accumulate(inv.begin(), inv.end(), 0ll);
	res %= MOD;
	cout << res << endl;
	return 0;
}


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

// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP1_3_B

int main() {
	int i = 1;
	int x;
	while (cin >> x) {
		if (x == 0) break;
		cout << "Case " << i << ": " << x << endl;
		i++;
	}
}

Measured memory_bytes: 1160
n = int(input())
d, x = map(int, input().split())
a = [int(input()) for i in range(n)]
ans = x + n
for i in range(n):
    for z in range(1, d):
        if a[i] * z + 1<= d:
            ans += 1
        else:
            break
print(ans)

Measured memory_bytes: 3060
import bisect

def grade(score, breakpoints=[400, 800, 1200, 1600, 2000, 2400, 2800, 3200],
          grades='abcdefghx'):
    i = bisect.bisect(breakpoints, score)
    return grades[i]

N = int(input())
a = list(map(int, input().split()))
grades = [grade(score) for score in a]

normal = [i for i in grades if i != 'x']
ans_max = len(set(normal)) + grades.count('x')
if len(normal) == 0:
    ans_min = 1
else:
    ans_min = len(set(normal))
print(ans_min, ans_max)


Measured memory_bytes: 3188
#accepted

import sys

HW = list(map(int,input().split()))
N = int(input())
a = list(map(int,input().split()))

now_n = 0

for y in range(HW[0]):
	n_array = []
	for x in range(HW[1]):
		if a[now_n] > 0:
			n_array.append(now_n+1)
			a[now_n] -= 1
		else:
			now_n += 1
			n_array.append(now_n+1)
			a[now_n] -= 1
	if y%2 == 1:
		n_array.reverse()
	for pi in n_array:
		sys.stdout.write(str(pi) + " ")
	sys.stdout.write("\n")


Measured memory_bytes: 3504
N = int(input())
A = [[int(i) for i in input().split()]for i in range(N)]
dp = [[0, 0, 0] for i in range(N)]
dp[0] = A[0]

for i in range(1, N):
    dp[i][0] = A[i][0] + max(dp[i - 1][1], dp[i - 1][2])
    dp[i][1] = A[i][1] + max(dp[i - 1][0], dp[i - 1][2])
    dp[i][2] = A[i][2] + max(dp[i - 1][0], dp[i - 1][1])
    
print(max(dp[-1]))

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


 
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
 
    int K; cin >> K;
    int A, B; cin >> A >> B;
    while (A <= B) {
        if (A%K==0) {
            cout << "OK" << endl;
            return 0;
        }
        A++;
    }

    cout << "NG" << endl;
    
    return 0;
}

Measured memory_bytes: 3644
#include <iostream>
#include <string>

using namespace std;

int main(){
	int r,g,b;
	cin >> r >> g >> b;
	int num = (r * 10 + g) * 10 + b;
	string s =  num % 4 == 0 ? "YES" : "NO";
	cout << s << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
//#define DEBUG
#define REP(i, nn ) for(int i = 0 ; i < (int) nn; i++)
#define deb(x) std::cerr << #x << " " << x << endl;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
template<typename... T>
void read(T& ... a){
    ((cin >> a),...);
}
template<typename... T>
void write(T... a){
    ((cout << a << "\n"),...);
}

template<typename... T>
void write_space(T... a){
    ((cout << a << " "),...);
}
constexpr int mxW = 1e5;
constexpr int mxN = 100;
ll dp[mxN][mxW];
void solve(){
    int n, W;
    read(n, W);
    vector<pair<ll,ll>> item(n);
    REP(i,n){
        ll w, v;
        cin >> w >> v;
        item[i] = {w,v};
    }
    //sort(item.begin(), item.end());
    for(int k = item[0].first; k <= W; k++){
        dp[0][k] = item[0].second;
    }
    for(int i = 1; i < n ; i++){
        for(int k = 0 ; k <= W ; k++){
            if( item[i].first > k){
                dp[i][k] = max(dp[i][k], dp[i-1][k]);
            }else{
                dp[i][k] = max(dp[i - 1][k], dp[i-1][k - item[i].first] + item[i].second);
            }
        }
        // deb(i);
        // deb(dp[i][W]);
    }
    cout << dp[n-1][W] << endl;
}

int main()
{
    //making data IO Fast
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(NULL);
    /****************************/
    solve();
    return 0;
}



Measured memory_bytes: 81684
/*
   AUTHOR :- Gaurang_Kothiya
   
   Quote:-" Great things never come from comfort zones."                                                                                                                
*/
 
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>  
#include <ext/pb_ds/tree_policy.hpp> 
#include <functional>
 
using namespace std;
using namespace __gnu_pbds;  

typedef tree<int, null_type, less<int>, rb_tree_tag,tree_order_statistics_node_update> data_set; 
#define speed ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long  
#define ld long double
#define f(i,x,n) for(ll i=x;i<=n;i++)
#define fe(x,v)   for(auto &x :v)
#define nf(i,x,n) for(ll i=n;i>=x;i--)
#define all(a)   a.begin(),a.end()
#define b_s(a,b)   binary_search( all(a),b)
#define lb(v,n)  lower_bound(all(v) ,n )
#define ub(v,n)  upper_bound( all(v) , n)
#define gcd(a,b) __gcd(a,b)
#define pub push_back
#define pob pop_back
#define puf push_front
#define pof pop_front
#define B begin()
#define E end()
#define acc(v, x) accumulate(all(v), x)
#define p(a,b) pair<a,b>
#define F first
#define S second
#define sz size()
#define v(x) vector<x>
#define m(a,b) map<a,b>
#define u_m(a,b) unordered_map<a,b>
#define mm(a,b) multimap<a,b>
#define s(a) set<a>
#define us(a) unordered_set<a>
#define ms(a) multiset<a>
#define maxy __LONG_LONG_MAX__
#define miny INT_MIN
#define PI 3.14159265358979323846
#define MOD 1000000007



void solver()
{
	string s;
	cin>>s;
	deque<char> d;
	f(i,0,s.length()-1) d.pub(s[i]);
	
	ll q;
	cin>>q;
	bool clock=true;
	
	while(q--)
	{
		ll x;
		cin>>x;
		if(x==1)
		{
			clock= !clock;
		}
		else
		{
			ll y;
			char z;
			cin>>y>>z;
			
			if(clock==true)
			{
				if(y==1) d.puf(z);
				else d.pub(z);
			}
			else
			{
				if(y==1) d.pub(z);
				else d.puf(z);
			}			
		}
	}
	if(!clock) reverse(all(d));
	fe(x,d)cout<<x;
	
}

signed main() 
{
	speed	
		
	ll q=1;	
	//cin>>q;	
	
	while(q--)	
	solver();	
	
	//cout << "\n\n"<<"Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " seconds.\n";
	return 0;
}

 
 

Measured memory_bytes: 976
#include <stdio.h>
#include <list>
using namespace std;

class Node {
public:
	int parentsCount = 0;
	list<int> children;

	int setParents = 0;
	int trueParent = 0;
	int trueDepth = 0;
	
	void setDepth(int parent, int depth) {
		if (trueDepth < depth) {
			trueDepth = depth;
			trueParent = parent;
		}
		setParents++;
	}

	int getDepth() {
		if (parentsCount > setParents) {
			return -1;
		}
		return trueDepth;
	}
};

int getRoot(Node* nodes, int size) {
	for (int i=1; i<size; i++) {
		if (nodes[i].parentsCount == 0) {
			return i;
		}
	}
	return -1;
}

int main(void) {
	Node* nodes = NULL;
	int N, M, a, b;
	scanf("%d%d", &N, &M);
	nodes = new Node[N+1];

	for (int i=0; i<N+M-1; i++) {
		scanf("%d%d", &a, &b);
		nodes[b].parentsCount++;
		nodes[a].children.push_front(b);
	}

	list<int> list;
	list.push_front(getRoot(nodes, N+1));

	while (list.size() > 0) {
		int target = list.front();
		list.pop_front();
		int depth = nodes[target].getDepth();
		
		for (const int x : nodes[target].children) {
			nodes[x].setDepth(target, depth+1);
			if (nodes[x].getDepth() != -1 && nodes[x].children.size() > 0) {
				list.push_front(x);
			}
		}

	}

	for (int i=1; i<N+1; i++) {
		printf("%d\n", nodes[i].trueParent);
	}

}


Measured memory_bytes: 7808
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <string>
#include <cmath>
#include <complex>
#include <map>
using namespace std;

#define rep(i,n) for(int i=0;i<int(n);++i)
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define EPS 1e-8
#define F first
#define S second

static const double PI=6*asin(0.5);
typedef pair<double,double> P;
typedef complex<double> CP;
typedef long long ll;

string s;
int a[1100]={0},b[1100]={0};


int main(){
	while(getline(cin,s),s.size()!=0){
		int t1=0;
		rep(i,s.size()){
			if(s[i]==','){
				break;
			}
			else{
				t1*=10;
				t1+=s[i]-'0';
				//cout<<t1<<endl;
			}
		}
		//cout<<t1<<endl;
		a[t1]++;
	}
	while(getline(cin,s)){
		int t1=0;
		rep(i,s.size()){
			if(s[i]==','){
				break;
			}
			else{
				t1*=10;
				t1+=s[i]-'0';
			}
		}
		b[t1]++;
	}
	
	
	rep(i,1100){
		if(a[i]&&b[i]){
			cout<<i<<" "<<a[i]+b[i]<<endl;
		}
	}
	
	return 0;
}

Measured memory_bytes: 1180
// Copyright 2020 yaito3014
#include <bits/stdc++.h>

int main() {
  using namespace std;
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  auto gcd = [](auto&& f) {
    return [&](auto&&... args) {
      return f(f, std::forward<decltype(args)>(args)...);
    };
  }([](auto&& self, int a, int b) -> int {
    return b ? self(self, b, a % b) : a;
  });
  int N, K;
  cin >> N >> K;
  vector<int> A(N);
  for (auto& e : A) cin >> e;
  int g = 0;
  for (auto& e : A) g = gcd(g, e);
  int m = *max_element(cbegin(A), cend(A));
  cout << (g == gcd(K, g) && K <= m ? "POSSIBLE" : "IMPOSSIBLE") << endl;
}


Measured memory_bytes: 640
n = int(input())
S = [list(input()) for _ in range(2)]
mod = 1000000007
if S[0][0]==S[1][0]:
    ans = 3
    i = 1
    typ = '2x1'
else:
    ans = 6
    i = 2
    typ = '2x2'
while i<n:
    if S[0][i]==S[1][i]:
        if typ=='2x1':
            ans *= 2
        typ = '2x1'
        i += 1
    else:
        if typ=='2x1':
            ans *= 2
        else:
            ans *= 3
        typ = '2x2'
        i += 2
    ans %= mod
print(ans)

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

int main() {
	int n,m; cin>>n>>m;
	bool flag = false;
	int i=0;
	bool pass = n==0 || m==0;
	for(i=0; i<1e9 && !pass; i++){
		if(abs(n-i) == abs(m-i)){
			flag =true;
			break;
		}
	}
	if(flag)cout<<i<<endl;
	else cout<<"IMPOSSIBLE"<<endl;
	return 0;
}

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

int main()
{
  int n; cin >> n;
  vector<int> a(n);
  rep(i, n) {
    cin >> a[i];
    a[i]--;
  }
  int ans = 0;
  rep(i, n) {
    int to = a[i];
    if (i == a[to]) ans++;
  }
  cout << ans/2 << endl;

  return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001;

int N;
vi A;
map<pi,int> m;

int get(int x, int y) {
    if (m.count({x,y})) return m[{x,y}];
    if (A[x] <= y) return 2;
    if (get(x+1,y) == 2) return m[{x,y}] = (A[x]+1-y)&1;
    return m[{x,y}] = !(get(x+1,y) && get(x,y+1));
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> N; A.resize(N);
    F0R(i,N) cin >> A[i];
    sort(A.rbegin(),A.rend());
    A.pb(0);
    
    int cur = 0;
    while (A[cur+1] > cur+1) cur ++;
    if (get(cur,cur)) cout << "First";
    else cout << "Second";
    /*F0Rd(i,N) {
        F0R(j,8) cout << get(i,j);
        cout << "\n";
    }*/
}

// read the question correctly (is y a vowel? what are the exact constraints?)
// look out for SPECIAL CASES (n=1?) and overflow (ll vs int?) ARRAY OUT OF BOUNDSS

Measured memory_bytes: 16248
n,m = map(int,input().split())
d = [0 for i in range(n+1)]
for i in range(m):
    a,b = map(int,input().split())
    d[a] = 1-d[a]
    d[b] = 1-d[b]

if sum(d) == 0:
    print("YES")
else:
    print("NO")

Measured memory_bytes: 3888
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.next());
        String SList = sc.next();
        String r = "";
        for (char s:
             SList.toCharArray()) {
            s += N;
            if ('Z' < s) s -= 26;
            r += (char)(s);
        }
        System.out.println(r);
    }
}

Measured memory_bytes: 147748
import java.io.*;
import java.util.*;

public class Main{
    static class FastReader{
        BufferedReader br;
        StringTokenizer st;
        public FastReader(){br = new BufferedReader(new InputStreamReader(System.in));}
        public FastReader(String fileName) throws FileNotFoundException{br = new BufferedReader(new FileReader(fileName));}
        String next(){while (st == null || !st.hasMoreElements()){try{st = new StringTokenizer(br.readLine());}catch (IOException  e){e.printStackTrace();}}return st.nextToken();}
        int nextInt(){return Integer.parseInt(next());}
        long nextLong(){return Long.parseLong(next());}
        double nextDouble(){return Double.parseDouble(next());}
        char[][] readCharArray(int n,int m) {
            String str;
            char[][] arr = new char[n][m];
            for(int i=0;i<n;i++) {
                str=nextLine();
                for(int j=0;j<n;j++) {
                    arr[i][j]=str.charAt(j);
                }
            }
            return arr;
        }
        char[][] readCharArray(int n){
            return readCharArray(n,n);
        }
        int[] readArray(int n){int[] a=new int[n];for (int i=0; i<n; i++) a[i]=nextInt();return a;}
        long[] readLongArray(int n){long[] a=new long[n];for (int i=0; i<n; i++) a[i]=nextLong();return a;}
        String nextLine(){String str = "";try{str = br.readLine();}catch (IOException e){e.printStackTrace();}return str;}
    }
    static void printArray(int[] arr){
        for(int x:arr){
            System.out.print(x+" ");
        }
        System.out.println();
    }
    static final Random random=new Random();
    static void ruffleSort(int[] a) {
        int n=a.length;//shuffle, then sort
        for (int i=0; i<n; i++) {
            int oi=random.nextInt(n), temp=a[oi];
            a[oi]=a[i]; a[i]=temp;
        }
        Arrays.sort(a);
    }
    public static void main(String[] args) throws NumberFormatException, IOException {
        FastReader st = new FastReader();
        int n = st.nextInt();
        int d1,d2,count=0;
        boolean test=true;
        while(n-- > 0) {
        	d1 = st.nextInt();d2 = st.nextInt();
        	if(d1==d2) {
        		count++;
        		if(count==3) {
        			System.out.println("Yes");
        			test=false;
        			break;
        		}
        	}
        	else {
        		count=0;
        	}
        }
        if(test) System.out.println("No");
    }
}

Measured memory_bytes: 25600
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

const int mod = 1000000007;
//const int mod = 998244353;
struct mint {
  ll x;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint nCk(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
  mint nHk(int n, int k) {
    if (n == 0 && k == 0) return 1; 
    if (n <= 0 || k < 0) return 0;
    return nCk(n + k - 1, k); 
  }
} comb(2001000);

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int k;
  string s;
  cin >> k >> s;
  int n = s.size();
  mint ans = 0;
  REP(rest, k+1){
    int inj = k - rest;
    ans += (comb.nHk(n, inj) * mint(25).pow(inj) * mint(26).pow(rest));
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 35520
a, b, k = map(int, input().split())
# print(f"{a} {b} {k}")

# l = []
# for i in range(a, b + 1):
#     l.append(i)
# print(l)

# l_small = set()
# for i in range(a, a + k):
#     l_small.add(i)
# print(l_small)

# l_large = set()
# for i in range(b, b - k, -1):
#     l_large.add(i)
# print(l_large)

# l = [i for i in range(a, b + 1)]
# print(l)

l_ans = set()

count = 1
for i in range(a, b + 1):
    if count <= k:
        l_ans.add(i)
    else:
        break
    count += 1

count = 1
for i in range(b, a - 1, -1):
    if count <= k:
        l_ans.add(i)
    else:
        break
    count += 1

for num in sorted(l_ans):
    print(num)

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

ll inf=1ll<<60;

int main()
{
	//freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
	ios_base::sync_with_stdio(false); cin.tie(0);
	ll n,t,a[200000],i,ans=0;
	cin>>n>>t;
	for (i=0;i<n;i++){
		cin>>a[i];
	}
	for (i=1;i<n;i++){
		if (a[i]-a[i-1]<=t){
			ans+=a[i]-a[i-1];
		}
		else {
			ans+=t;
		}
	}
	cout<<ans+t;
	return 0;
}

Measured memory_bytes: 1792
N=int(input())
A=[int(i) for i in input().split()]
A_abs=list(map(abs,A))
c=0
for i in A:
    if i<0:
        c+=1
if c%2==0:
    print(sum(A_abs))
else:
    print(sum(A_abs)-2*min(A_abs))

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

int N;

int main(){
  while(cin>>N&&N){

    int a=1,b=2,sum=1,ans=0;

    while(1){

      if(a==b)break;

      if(sum==N){
	if(a+1!=b)ans++;
	sum-=a;
	a++;
      }else if(sum<N){
	sum+=b;
	b++;
      }else if(sum>N){
	sum-=a;
	a++;
      }
      
    }
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b,n;
  cin>>a>>b>>n;
  if(a<b){
    int c=a;
    a=b;
    b=c;
  }
  if(n%a==0)
    cout<<n/a<<endl;
  else
    cout<<n/a+1<<endl;
}


Measured memory_bytes: 256
while True:
    n, x = map(int, input().split())
    if not n and not x:
        break

    ans = 0
    for i in range(1, n - 1):
        for j in range(i + 1, n):
            for k in range(j + 1, n + 1):
                if i + j + k == x:
                    ans += 1
    print(ans)



Measured memory_bytes: 5596
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); ++i)
#define REP(i,n) for(int i=1;i<=(n);++i)
#define pa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};
#define pb push_back

using ll = long long;
using namespace std;
using pint = pair<int,int>;
using pll = pair<ll,ll>;
const int INFint = 2e9+1;
const ll INFll = 2e18+1;
ll MOD=1e9+7;

ll gcd(ll a, ll b) { return __gcd(a,b); } //最大公約数
ll lcm(ll a, ll b) { return a/gcd(a,b)*b; } //最大公倍数

// aのn乗をMODで割りながら計算する
ll modpow(ll a, ll n) {
  long long res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % MOD;
    a = a * a % MOD;
    n >>= 1; // right shift
  }
  return res;
}

// MODを法としたaの逆元を計算する
ll modinv(ll a) {
  return modpow(a, MOD - 2);
}

int main(){
  int N,A[200000],cnt[200001] = {0};
  cin>>N;
  rep(i,N){
    cin>>A[i];
    cnt[A[i]]++;
  }
  ll sum(0);
  for(int i(0);i<=200000;i++){
    sum += (ll)cnt[i]*(cnt[i]-1)/2;
  }
  rep(i,N){
    int a = cnt[A[i]];
    cout << sum - (a-1) << endl;
  }
  return 0;
}



Measured memory_bytes: 4096
import java.util.*;
public class Main{
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int d = sc.nextInt();
    int w = 2*d+1;
    int ans = (n+(w-1))/w;
    System.out.println(ans);
  }
}


Measured memory_bytes: 21716
#include<iostream>
#include<string>
using namespace std;
char A[5];
int a[5];
int sum;
string str;
int main(){
  for(int i=0; i<4; ++i){
    cin >> A[i];
    a[i] = A[i] - '0';
  }
  
  for(int bit=0; bit < (1 << 3); ++bit){
    sum =a[0];
    str ="";
    str.push_back(A[0]);
    for(int i=0; i <3; ++i){
      if (bit & (1 <<i)){
        sum +=a[i+1];
        str += "+";
        str.push_back(A[i+1]);
      }
      else {
        sum -= a[i+1];
        str +="-";
        str.push_back(A[i+1]);
      }
    }
    if (sum ==7) break;
  }
  str += "=7";
  cout << str << endl;
  return 0;
}

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

#define int long long
const int N = 1000005;
const int a[40] = {0,1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};

signed main() {
    int n;
    cin>>n;
    cout<<a[n];
}

Measured memory_bytes: 256
import sys
import heapq
input = sys.stdin.readline
N, M = map(int, input().split())
graph = [[] for _ in range(3*N)]
for _ in range(M):
  u, v = map(lambda x:int(x)-1, input().split())
  graph[3*u+0] += [[3*v+1, 1]]
  graph[3*u+1] += [[3*v+2, 1]]
  graph[3*u+2] += [[3*v+0, 1]]

def dijkstra(s):
  dist = [float('inf')]*(3*N)
  dist[s] = 0
  num = [0]*(3*N)
  num[s] = 1
  q = [[0, s]]
  heapq.heapify(q)
  while q:
    c, u = heapq.heappop(q)
    if dist[u] < c:
      continue
    for v, weight in graph[u]:
      if dist[v] > dist[u] + weight:
        dist[v] = dist[u] + weight
        num[v] = num[u]
        heapq.heappush(q, [dist[v], v])
      elif dist[v] == dist[u] + weight:
        num[v] += num[u]
  return dist, num

S, T = map(lambda x:int(x)-1, input().split())
dist, _ = dijkstra(3*S)

if dist[3*T] == float('inf'):
  print(-1)
else:
  print(dist[3*T]//3)

Measured memory_bytes: 124324
#include <iostream>
#include <algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<iomanip>
#define sqr(x) (x)*(x)
using namespace std;
long long n,m,ned,i,j,fa[1005],dis[1005],x,y,mod=1e9+7,par[1005],vis[1005],dep[1005];
long long qp(long long x,long long y)
{
	if (y==0) return 1;
	if (y==1) return x;
	long long z=qp(x,y/2);
	z=z*z%mod;
	if (y&1) z=z*x%mod;
	return z;
}
int find(int x)
{
	if (fa[x]==x)
	{
		return x;
	}
	return fa[x]=find(fa[x]);
}
struct ii
{
	long long x,y,z,ty;
}bi[2005];
void init()
{
	long long i;
	for (i=1;i<=n;i++) fa[i]=i;
}
long long span()
{
	init();
	long long i,ans=0,s=0,ans2,t;
	for (i=1;i<=m;i++)
	{
		if (find(bi[i].x)!=find(bi[i].y))
		{
			/*if (s+bi[i].ty>=n-1) continue;
			s+=bi[i].ty;*/
			fa[find(bi[i].x)]=find(bi[i].y);
			bi[i].ty=1;
			ans+=bi[i].z;
		}
	}
	return ans;
}
bool cmp(ii x,ii y)
{
	return x.z*2+x.ty<y.z*2+y.ty;
}
void dfs(int x)
{
	int i;
	if (vis[x]) return;
	vis[x]=1;
	for (i=1;i<=m;i++)
	{
		if (!bi[i].ty) continue;
		if (bi[i].x==x||bi[i].y==x)
		{
			int y=(bi[i].x^bi[i].y^x);
			if (!vis[y])
			{
				par[y]=x;
				dis[y]=bi[i].z;
				dep[y]=dep[x]+1;
				dfs(y);
			}
		}
	}
}
long long getmin(int x,int y)
{
	if (dep[x]>dep[y]) swap(y,x);
	int i;
	long long ans=0;
	while (dep[x]<dep[y])
	{
		ans=max(ans,dis[y]);
		y=par[y];
	}
	while (x!=y)
	{
		ans=max(ans,dis[x]);
		x=par[x];
		ans=max(ans,dis[y]);
		y=par[y];
	}
	return ans;
}
int main()
{
	ios_base::sync_with_stdio(0);
	cin>>n>>m>>ned;
	for (i=1;i<=m;i++)
	{
		cin>>bi[i].x>>bi[i].y>>bi[i].z;
	}
	sort(bi+1,bi+m+1,cmp);
	long long mst=span(),ok=0;
	if (mst>ned)
	{
		cout<<0;
		return 0;
	}
	if (mst==ned) ok=1;
	dfs(1);
	int cnt1=0,cnt2=0;
	for (i=1;i<=m;i++)
	{
		long long t=mst-getmin(bi[i].x,bi[i].y)+bi[i].z;
		if (t<ned) cnt1++;
		if (t==ned) cnt2++;
	}
	if (!cnt2)
	{
		cout<<0;
		return 0;
	}
	if (ok) cout<<((qp(2,m)-2*qp(2,m-cnt2)%mod)%mod+mod)%mod;
	else cout<<qp(2,m-cnt1-cnt2)*2*(qp(2,cnt2)-1)%mod;
	return 0;
}

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

namespace ClassLibrary1
{
    public class ListNode
    {
        public int val;
        public ListNode next;
        public ListNode(int x) { val = x; }
    }


    public class Class1
    {
        static Dictionary<Tuple<long, long>, long> dic = new Dictionary<Tuple<long, long>, long>();


        static void Main(string[] args)
        {

            var aa = ReadLongArr();
            var bb = ReadLongArr();
            var T = ReadString();

            var N = aa[0];
            var K = aa[1];

            var R = bb[0];
            var S = bb[1];
            var P = bb[2];

            long res = 0;

            var tc = T.ToCharArray();
            var tt = new char[tc.Length];

            for(long i=0; i<tc.Length; i++)
            {
                if ((i>=K) && tc[i] == tt[i-K])
                {
                    tt[i] = '*';
                    continue;
                }

                tt[i] = tc[i];
                if (tc[i] == 'r')
                {
                    res += P;
                }
                else if (tc[i] == 's')
                {
                    res += R;
                }
                else if (tc[i] == 'p')
                {
                    res += S;
                }
            }


            Console.WriteLine(res);


        }


        class BitArr
        {
            public bool[] bitArr = new bool[64];

            public BitArr(long l)
            {
                var ll = l;
                for(int i=0; i<64; i++)
                {
                    bitArr[i] = (ll % 2) == 1;
                    ll = ll / 2;
                }
            }
        }

        public static int Digit(long num)
        {
            // Mathf.Log10(0)はNegativeInfinityを返すため、別途処理する。
            return (num == 0) ? 1 : ((int)Math.Log10(num) + 1);
        }

        public static long nCm(long n, long m, long mod)
        {
            if (m == 0) return 1;
            if (n == 0) return 0;
            var a = n * nCm(n - 1, m - 1, mod) / m;
            return a % mod;
            //return a % 1000000007;
        }

        private static string ReadString()
        {
            return Console.ReadLine();
        }
        private static string[] ReadStringArr()
        {
            return Console.ReadLine().Split(' ');
        }
        private static long ReadLong()
        {
            return long.Parse(Console.ReadLine());
        }
        private static long[] ReadLongArr()
        {
            string[] s = ReadStringArr();
            long[] l = new long[s.Length];
            for(int i=0; i<l.Length; i++)
            {
                l[i] = long.Parse(s[i]);
            }

            return l;
        }
    }

}


Measured memory_bytes: 13248
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("O3")
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define EPS (1e-9)
#define INF (1e17)
#define PI (acos(-1))
//const double PI = acos(-1);
//const double EPS = 1e-15;
//long long INF=(long long)1E17;
#define i_7 (long long)(1e9+7)
//#define i_7 998'244'353
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
long long po(long a, long b){
    if(b==0){
        return 1;
    }
    
    long long z = po(a,b/2);
    z = mod(z*z);
    if(b%2!=0){
        z = mod(a*z);
    }
    return z;
}
 
bool prime_(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=std::sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}
 
long long gcd_(long long a, long long b){
  if(a<b){
    std::swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd_(b,a%b);
  }
}
 
long long lcm_(long long x, long long y){
  return (x/gcd_(x,y))*y;
}
 
//using namespace std;
//using namespace boost::multiprecision;
//using namespace __gnu_pbds;

int main(){
  using namespace std;
  int n;
  cin>>n;
  int A[n][n - 1];
  REP(i, n) REP(j, n - 1) cin>>A[i][j];
  
  stack<int> a[n];
  REP(i, n) for(int j = n - 2; j >= 0; j--) a[i].push(A[i][j] - 1);
  
  typedef pair<int, int> P;
  vector<P> battles; //現時点で実行可能な試合たち
  auto add_battle = [&a](int i, vector<P>& next_battles) -> void {
    if(a[i].empty()) return;
    int j = a[i].top();
    if(a[j].top() == i){
      if(i < j){
        next_battles.push_back(P(i, j));
      }else{
        next_battles.push_back(P(j, i));
      }
    }
    return;
  };
  REP(i, n) add_battle(i, battles);
  sort(ALL(battles)); battles.erase(unique(ALL(battles)), battles.end());
  
  int days = 0;
  while(!battles.empty()){
    days++;
    for(auto& battle: battles){
      int i = battle.first, j = battle.second;
      a[i].pop(); a[j].pop();
    }
    vector<P> next_battles;
    for(auto& battle: battles){
      int i = battle.first, j = battle.second;
      add_battle(i, next_battles);
      add_battle(j, next_battles);
    }
    swap(battles, next_battles);
    sort(ALL(battles)); battles.erase(unique(ALL(battles)), battles.end());
  }
  
  REP(i, n){
    if(!a[i].empty()){
      cout << -1 << endl;
      return 0;
    }
  }
  cout << days << endl;
    
  return 0;
}


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

using namespace std;

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define MOD 1000000007
#define NUM 2520
#define INF (1LL<<60)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)

lli bitCnt(lli now){
	lli cnt=0;
	while(now>0){
		cnt += (now%2);
		now/=2;
	}
	return cnt;
}

signed main(){

	lli n,k;
	cin>>n>>k;

	vector<lli> a(n);
	REP(i,0,n)cin>>a[i];

	vector<lli> amaxh(n+1);
	amaxh[0]=0;
	REP(i,0,n)amaxh[i+1] = max(a[i],amaxh[i]);
	lli ans = INF;

	for(lli b=0;b<(1LL<<(n));b++){
		if(__builtin_popcount(b) != k) continue;
		if(DEBUG)cout<<"b="<<b<<endl;
		lli nowh=0,tmp=0;
		REP(i,0,n){
			if(DEBUG)cout<<"i="<<i<<endl;
			if((b&(1LL<<i))==0)continue;
			nowh=max(nowh,amaxh[i]);
			if(nowh>=a[i]){
				tmp += nowh-a[i]+1;
				nowh++;
			}
			else{
				nowh = a[i];
			}
		}
		ans = min(ans,tmp);
	}
	cout<<ans<<endl;


	return 0;
}

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

using namespace std;


int main() {
    int k, n;
    cin >> k >> n;
    int min = 99999999;
    vector<int> a(n, 0);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    int mx = 0;
    int total = 0;
    for (int i = 0; i < n-1; i++) {
        mx = max(mx, abs(a[i] - a[i+1]));
        total += abs(a[i] - a[i + 1]);
    }
    total += a[0] - 0;
    total += k - a[n - 1];
    mx = max(mx, (k - a[n - 1]) + a[0] - 0);
    total -= mx;
    cout << total;
    return 0;
}

Measured memory_bytes: 1152
// Problem : D - Chat in a Circle
// Contest : AtCoder - AtCoder Beginner Contest 173
// URL : https://atcoder.jp/contests/abc173/tasks/abc173_d
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
#define DEBUG fprintf(stderr, "Passing [%s] line %d\n", __FUNCTION__, __LINE__)
#define File(x) freopen(x".in","r",stdin); freopen(x".out","w",stdout)

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef pair <int, int> PII;
typedef pair <int, PII> PIII;

inline int gi()
{
    int f = 1, x = 0; char c = getchar();
    while (c < '0' || c > '9') {if (c == '-') f = -1; c = getchar();}
    while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
    return f * x;
}

inline LL gl()
{
    LL f = 1, x = 0; char c = getchar();
    while (c < '0' || c > '9') {if (c == '-') f = -1; c = getchar();}
    while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
    return f * x;
}

const int INF = 0x3f3f3f3f, N = 200003, M = N << 1;

int n, m;
int a[N];

int main()
{
    //File("");
    n = gi();
    for (int i = 1; i <= n; i+=1) a[i] = gi();
    sort(a + 1, a + 1 + n); reverse(a + 1, a + 1 + n);
    LL ans = a[1], cnt = 2;
    for (int i = 2; i <= n; i+=1)
    {
    	if (cnt < n) ans += a[i], ++cnt;
    	if (cnt < n) ans += a[i], ++cnt;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4344
using System;
using System.Linq;
public class Aprob {
    public static void Main() {
        int n = int.Parse(Console.ReadLine());
        long outp = 1;
        for (int i = 1; i <= n; i++) {
            outp *= i;
            outp %= (long)(Math.Pow(10, 9) + 7);
        }
        Console.WriteLine(outp);
    }
}

Measured memory_bytes: 13140
#pragma GCC optimize("O3")
    #pragma comment(linker, "/stack:200000000")
    #pragma GCC optimize("unroll-loops")
     
    #include <algorithm>
    #include <bitset>
    #include <cassert>
    #include <chrono>
    #include <cmath>
    #include <complex>
    #include <cstdio>
    #include <cstdlib>
    #include <cstring>
    #include <ctime>
    #include <deque>
    #include <functional>
    #include <iomanip>
    #include <iostream>
    #include <iterator>
    #include <limits>
    #include <climits>
    #include <list>
    #include <map>
    #include <numeric>
    #include <queue>
    #include <random>
    #include <ratio>
    #include <set>
    #include <sstream>
    #include <stack>
    #include <string>
    #include <unordered_map>
    #include <unordered_set>
    #include <utility>
    #include <vector>
    using namespace std;
     
    typedef long long ll;
    typedef long double LD;
    #define int ll
    #define double LD
    #define pb push_back
    #define mp make_pair
    #define REP(i,n) for (int i = 0; i < n; i++)
    #define loop(i,n) for (int i = 0; i < n; i++)
    #define FOR(i,a,b) for (int i = a; i < b; i++)
    #define REPD(i,n) for (int i = n-1; i >= 0; i--)
    #define FORD(i,a,b) for (int i = a; i >= b; i--)
    #define remax(a,b) a = max(a,b)
    #define remin(a,b) a = min(a,b)
    #define mem(a, b) memset(a, b, sizeof a)
    #define append push_back
    #define all(v) v.begin(),v.end()
    #define F first
    #define S second
    #define print(x) cout << (x) << endl
    #define PRECISION(x) cout << fixed << setprecision(x)
    #define FAST_IO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
     
    const double PI=acos(-1);
    const int MOD = 1000000007;
    const int FMOD = 998244353;
    const double eps = 1e-9;
     
    mt19937 RNG(chrono::steady_clock::now().time_since_epoch().count()); 
  
  	int find(int i,int *parent)
  	{
  		if(parent[i]==i)
  		return i;
  		else
  		return parent[i]=find(parent[i],parent);
	}

	signed main()
	{
		int n,m,k;
		cin>>n>>m>>k;
		int connected[n+1],parent[n+1],size[n+1];
		vector<int> v[n+1];
		FOR(i,1,n+1)
		{
			connected[i]=0;
			parent[i]=i;
			size[i]=1;
		}
		loop(i,m)
		{
			int x,y;
			cin>>x>>y;
			v[x].push_back(y);
			v[y].push_back(x);
			connected[x]++;
			connected[y]++;
			x=find(x,parent);
			y=find(y,parent);
			if(x!=y)
			{
				parent[y]=x;
				size[x]+=size[y];
			}
		}
		loop(i,k)
		{
			int x,y;
			cin>>x>>y;
			if(find(x,parent)==find(y,parent))
			{
				connected[x]++;
				connected[y]++;
			}
		}
		FOR(i,1,n+1)
		{
			cout<<size[find(i,parent)]-connected[i]-1<<" ";
		}
	}

Measured memory_bytes: 10624
#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

int main(){
    int N;
    string S;

    cin >> N >> S;

    vector<int> w(N,0),b(N,0);

    if(S[0] == '#')b[0] = 1;
    if(S[N-1] == '.') w[N-1] = 1;

    for(int i = 1;i < N;i++){
        b[i] = b[i-1];
        if(S[i] == '#') b[i]++;
    }

    for(int i = N -2;i >= 0;i--){
        w[i] = w[i + 1];
        if(S[i] == '.') w[i]++;
    }

    int ans = 1000000;
    for(int i = 0;i < N-1;i++){
        ans = min(ans,b[i] + w[i + 1]);
    }

    //すべて白
    int black = 0,white = 0;
    for(int i = 0;i < N;i++){
        if(S[i] == '#')black++;
        else white++;
    }

    ans = min(ans,black);
    ans = min(ans,white);

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 2180
import sys
input = sys.stdin.buffer.readline


n = int(input())
a = list(map(int,input().split()))
a.sort()

MAX = 10**6+1

used = [False]*MAX


res = 0

for i in range(n):
    if used[a[i]]:
        continue
    if i+1 == n or a[i+1] != a[i]:
        res += 1
    for j in range(a[i],MAX,a[i]):
        used[j] = True

print(res)


Measured memory_bytes: 95708
//Radhe Radhe
#include<bits/stdc++.h>
#define godspeed  ios_base:: sync_with_stdio(false); cin.tie(0); cout.tie(0);

#define ll long long
#define ld long double
#define fi first
#define se second
#define mp make_pair
#define rep1(i,a,b)    for(ll i=a; i<=b; i++)
#define repVect(i,n)    for(ll i=0; i<sum.size(); i++)
#define fixed cout.setf(ios::fixed);
#define Precise cout.precision(7);
#define yes cout<<"Yes"<<'\n';
#define no cout<<"No"<<'\n';
using namespace std;

int main()
{
    godspeed
    ll  t,i,x,j,k,n,a,b,c,d,alp[26]={0};
    string s;
    cin>>s;
    for(i=0;s[i];i++)
    {
    x=s[i]-'a';
    alp[x]=1;
    }
    for(i=0;i<26;i++)
    {
        if(alp[i]==0){
            char c='a'+i;
       return cout<<c<<endl,0;
        }
    }
     cout<<"None"<<endl;

    return 0;
}





Measured memory_bytes: 3736
#pragma GCC optimize(2)
#include <iostream>
#include <cstring>
#include <stdio.h>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <queue>
#define all(v) (v).begin(),(v).end()
#define rep(x,y) for(ull i = (x);i<=(y);i++)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
const int maxn = 1e6+10;
int dir[8][2] = {-1,0,1,0,0,1,0,-1,-1,-1,-1,1,1,-1,1,1};
int dir2[4][2] = {0,1,1,0,0,-1,-1,0};
const ll eps = -3000;

int N,M;
priority_queue<int> q;
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);

    cin>>N>>M;
    int tmp;
    rep(1,N){
        cin>>tmp;
        q.push(tmp);
    }
    while(M--){
        int x = q.top();q.pop();
        x/=2;
        q.push(x);
    }
    ll res = 0;
    while(!q.empty()){
        res += q.top();
        q.pop();
    }
    cout<<res;
    return 0;
}

Measured memory_bytes: 892