akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

void bubble(vector<pair<char, int>> &suit, int n) {
  	int i=0;
    while(i<n*n) {
        for(int j=n-1; j>=1; j--) {
            if(suit.at(j-1).second>suit.at(j).second) swap(suit.at(j-1), suit.at(j));
        }
      	i++;
    }
    for(int i=0; i<n; i++) {
        cout<<suit.at(i).first<<suit.at(i).second;
        i==n-1? cout<<endl: cout<<' ';
    }
  	//安定判別
  	cout<<"Stable"<<endl;
}

void selection(vector<pair<char, int>> &suit, int n) {
    
    for(int i=0; i<n; i++) {
        int minj=i;
        for(int j=i; j<n; j++) {
            if(suit.at(j).second<suit.at(minj).second) minj=j;
        }
        swap(suit.at(i), suit.at(minj));
    }
    for(int i=0; i<n; i++) {
        cout<<suit.at(i).first<<suit.at(i).second;
        i==n-1? cout<<endl: cout<<' ';
    }  	
}

int main() {
    int n;  cin>>n;
    vector<pair<char, int>> bubb(n);
    vector<pair<char, int>> sele(n);
    for(int i=0; i<n; i++) cin>>sele.at(i).first>>sele.at(i).second;
    for(int i=0; i<n; i++) bubb.at(i)=sele.at(i);
    bubble(bubb, n);
    selection(sele, n);

    bool flag=true;
    for(int i=0; i<n; i++) {
        if(bubb.at(i)!=sele.at(i)) flag=false;
    }

    flag? cout<<"Stable"<<endl: cout<<"Not stable"<<endl;
}


Measured memory_bytes: 3100
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
//const int INF = 1e8;
using namespace std;

bool canUseVer(int v, int ver, vector<long long>& c, bool u[20][20]){
	rep(i,c.size()){
		if(u[c[i]][ver]) return false;
	}
	return true;
}

bool f;
int st;
vector<long long> dfs(vector<long long> c, int v, int n, bool u[20][20]){
	if(n == c.size()){
		return c;
	}

	vector<long long> res;
	int s = c.empty() ? 0 : c.back() + 1;
	s = f and s == 0 ? st : s;
	range(i,s,v){
		if(canUseVer(v, i, c, u)){
			c.emplace_back(i);
			res = dfs(c, v, n, u);
			if(res.size() == n) return res;
			c.pop_back();
		}
	}
	return vector<long long>();
}

bool search(bool u[20][20], int v, int n){
	vector<long long> tmp;
	vector<long long> c = dfs(tmp, v, n, u);
	if(c.size() == n){
		for(auto i : c){
			//cout << i << ' ' ;
			for(auto j : c){
				u[i][j] = u[j][i] = true;
			}
		}
		//cout << endl;
		return true;
	}
	return false;
}

bool C(int v, vector<long long>& a){
	bool u[20][20] = {{0}};
	rep(i,a.size()){
		f = true;
		st = i / 2;
		if(not search(u, v, a[i])){
			return false;
		}
	}
	return true;
}

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

	long long ans = 0;
	vector<long long> a(n);
	rep(i,n){
		cin >> a[i];
		ans += max<long long>(a[i] - 4L, 0L);
		a[i] -= max<long long>(a[i] - 4L, 0L);
	}
	sort(all(a),greater<long long>());

	int right = 20, left = 1;
	rep(i,10){
		int mid = (right + left) / 2;
		if(C(mid, a)) right = mid;
		else left = mid;
	}
	C(10,a);
	cout << ans + right << endl;
}



Measured memory_bytes: 3160
#include <bits/stdc++.h>
using namespace std;
#define ul unsigned long long
#define ll long long
#define ld long double


int main()
{
  ll n;
  cin >>n;

  ll a[100];
  for (ll i = 0; i < n; i++)
  {
    cin>>a[i];
  }
  for (ll k = 0; k < n - 1; k++)
  {
    cout << a[k] << " ";
  }
  cout << a[n - 1] << endl;

  ll v,j;
  for (ll i = 1; i < n; i++)
  {
    v=a[i];
    j=i-1;
    while (j>=0&&a[j]>v) {
      a[j+1]=a[j];
      j--;
    }
    a[j+1]=v;

    for (ll k = 0; k < n-1; k++)
    {
      cout<<a[k]<<" ";
    }
    cout<<a[n-1]<<endl;

  }
  

  return 0;
}



Measured memory_bytes: 3116
n = int( raw_input( ) )
dic = set()
for i in range( n ):
	cmd, word = raw_input( ).split( " " )
	if "insert" == cmd:
		dic.add( word )
	elif "find" == cmd:
		if word in dic:
			print( "yes" )
		else:
			print( "no" )

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

using namespace std;
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
#define REP(i,n) for(ll i = 0;i < (ll)n;i++)
#define REPD(i,n) for(ll i = (ll)n - 1;i >= 0;i--)
#define ALL(x) (x).begin(),(x).end()
#define FILLl(n,first_dimension_size,value) fill((ll*)n,(ll*)(n+first_dimension_size),value)
#define FILL(n,first_dimension_size,value) fill((int*)n,(int*)(n+first_dimension_size),value)
#define INF (1 << 30)
#define MOD 1000000007
//int dy[4] = {-1,0,0,1};
//int dx[4] = {0,1,-1,0};



int main(){

  int a,b;
  cin >> a >> b;
  if(a*b%2)cout << "Odd" << endl;
  else cout << "Even" << endl;






  

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define pb emplace_back
#define pob pop_back
#define ff first
#define ss second
typedef long long int ll;
#define vll vector<ll>
#define vpll vector<pair<ll,ll>>
#define vvll vector<vector<ll>>
#define vcc vector<char>
#define vss vector<string>
#define bs binary_search
#define lb lower_bound
#define ub upper_bound
#define test ll t; cin>>t; while(t--)
main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,i,j;
    cin>>n;
    vll h(n);
    for(i=0;i<n;i++)
    cin>>h[i];
    vll dp(n);
    dp[0]=0;
    dp[1]=abs(h[1]-h[0]);
    for(i=2;i<n;i++)
    dp[i]=min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]));
    cout<<dp[n-1];
}

Measured memory_bytes: 1792
N=int(input())
S=input()
R=S.count("R")
G=S.count("G")
B=S.count("B")


count=R*G*B
for i in range(0,N-2):
    for j in range(i+1,N-1):
        k=j+(j-i)
        if k>=N:
            break
        if S[i]!=S[j] and S[j]!=S[k] and S[k]!=S[i]:
            count=count-1

print(count)

Measured memory_bytes: 9184
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
#define int long long
int gcd(int a,int b){
    if(a>b){swap(a,b);}
    if(a==0){return b;}
    else{return gcd(b%a,a);}
}

int ord2(int n){
    int ret =0;
    while(n%2==0){
        n/=2;
        ret++;
    }
    return ret;
}
signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n,m,ans=0,L=1,ord,d;
    cin>>n>>m;
    vector<int>a(n);
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    ord=ord2(a[0]);
    d=(1<<ord);
    for(int i=0;i<n;i++){
        if((a[i]/d)%2==0){cout<<0<<endl;return 0;}
        a[i]/=d;
        int tmp =(L/gcd(L,a[i]))*a[i];
        if(tmp<0||L>tmp){cout<<0<<endl;return 0;}
        else{L = tmp;}
    }
    L*=d/2;
    if((L>m)||(L<=0)){cout<<0;return 0;}
    cout<<(m+L)/(2*L)<<endl;
    return 0;
}


Measured memory_bytes: 1024
object Main extends App {
	val input: Seq[Array[Char]] = io.Source.stdin.getLines.toSeq.tail.map(' ' +: _.toArray :+ ' ')
	val wall = input.head.map(_ => 'w')
	val walled: Array[Array[Char]] = (wall +: input :+ wall).toArray

	private def func(x: Int, y: Int): Char =
		if (walled(x)(y) == '#') '#' else Seq(
			walled(x - 1)(y - 1),
			walled(x - 1)(y),
			walled(x - 1)(y + 1),
			walled(x)(y - 1),
			walled(x)(y + 1),
			walled(x + 1)(y - 1),
			walled(x + 1)(y),
			walled(x + 1)(y + 1)).count(_ == '#').toString.head

	(1 until walled.length - 1).foreach { l =>
		(1 until walled(0).length - 1).foreach { e =>
			walled(l)(e) = func(l, e)
		}
	}

	(1 until walled.length - 1).foreach { l =>
		println((1 until walled(0).length - 1).map(e => walled(l)(e)).mkString(""))
	}
}


Measured memory_bytes: 28804
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
#define rrep(i,n) for(int i=n-1; i>=0; i--)

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef long double lb;

const int INF=1<<27;
const int MOD=(int)1e9+7;

int main(void)
{
    int a, b, c;
    int n, y;
    cin >> n >> y;
    if(y < n || (y%1000 != 0)){
        cout << "-1 -1 -1" << endl;
        return 0;
    }

    a = 0;
    while(y/1000 - n - 9*a >= 0){
        if((y/1000 - n - 9*a) % 4 == 0){
            b = (y/1000 - n - 9*a) / 4;
            c = n - a - b;
            if(c >= 0){
                cout << a << ' ' << b << ' ' << c << endl;
                return 0;
            }
        }
        a++;
    }

    cout << "-1 -1 -1" << endl;

    return 0;
}



Measured memory_bytes: 256
from itertools import accumulate


def solve(h, w, lim, choco):
    acc = [[0] + list(accumulate(int(c == '1') for c in s)) for s in choco]
    acc = list(zip(*acc))
    acc = [[0] + list(accumulate(s)) for s in acc]
    acc = list(zip(*acc))
    # print(*acc, sep='\n')

    ans = 10 ** 9
    # i:j  h方向の分割
    # k:l  w方向の分割
    for bit in range(1 << (h - 1)):
        k = 1
        tmp = 0
        while k < w:
            # print(bin(bit), k)
            i = 0
            l = w + 1
            sp = bit | 1 << (h - 1)
            while sp:
                b = sp & -sp
                sp ^= b
                j = b.bit_length()
                lt = k
                while lt <= w and acc[j][lt] - acc[j][k - 1] - acc[i][lt] + acc[i][k - 1] <= lim:
                    lt += 1
                if lt == k:
                    break
                l = min(l, lt)
                # print('i,j,k,l', i, j, k, l, lt)
                i = j
            else:
                k = l
                if k <= w:
                    tmp += 1
                continue
            break
        else:
            # print(tmp, bin(bit).count('1'))
            ans = min(ans, tmp + bin(bit).count('1'))
    return ans


h, w, k = map(int, input().split())
choco = [input() for _ in range(h)]
print(solve(h, w, k, choco))


Measured memory_bytes: 3956
#include <bits/stdc++.h>
using namespace std;
inline void read (int &x) {
    char ch = getchar(); int f = 0; x = 0;
    while (!isdigit(ch)) { if (ch == '-') f = 1; ch = getchar(); }
    while (isdigit(ch)) x = x * 10 + ch - 48, ch = getchar(); if (f) x = -x;
} char ch[1234];
signed main() {
    scanf ("%s", ch + 1);
    int n = strlen (ch + 1), na = (n - 1) / 2, nb = (n + 3) / 2;
    for (int i = 1; i <= n; ++i)
        if (ch[i] != ch[n - i + 1]) return puts ("No"), 0;
    for (int i = 1; i <= na; ++i)
        if (ch[i] != ch[na - i + 1]) return puts ("No"), 0;
    for (int i = nb; i <= n; ++i)
        if (ch[i] != ch[n - i + nb]) return puts ("No"), 0;
    return puts ("Yes"), 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
typedef long long ll;
const long long INF = 1LL << 60;
int main()
{
    int N;
    string S;
    cin >> N >> S;

    int l = 0, now = 0;
    rep(i, N) {
        if (S[i] == '(') now++;
        else now--;
        if (now < 0) {
            l++;
            now = 0;
        }
    }

    string tmp = "";
    rep(i, l) {
        tmp += "(";
    }
    tmp += S;
    S = tmp;
    rep(i, now) {
        S += ")";
    }

    cout << S << endl;

    return 0;
}

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

void solve(std::string s) {
  for (int i = 0; i < s.size() - 1; i++) {
    if (s[i] == s[i + 1]) {
      cout << i + 1 << " " << i + 2 << endl;
      return;
    }
  }
  for (int i = 0; i < s.size() - 2; i++) {
    if (s[i] == s[i + 2]) {
      cout << i + 1 << " " << i + 3 << endl;
      return;
    }
  }
  cout << -1 << " " << -1 << endl;
}

// Generated by 1.1.5 https://github.com/kyuridenamida/atcoder-tools  (tips: You
// use the default template now. You can remove this line by using your custom
// template)
int main() {
  std::string s;
  std::cin >> s;
  solve(s);
  return 0;
}


Measured memory_bytes: 512
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 9)
MOD = 10 ** 9 + 7

from collections import defaultdict

N = int(input())

S = [list(input()) for _ in range(N)]

for i in range(N):
    S[i].sort()

S.sort()
ans = 0
count = 1
for i in range(1, N):
    if S[i - 1] == S[i]:
        count += 1
    else:
        ans += count * (count - 1) // 2
        count = 1

ans += count * (count - 1) // 2
print (ans)

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

using namespace std;

int main(){
    int num[32]={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};
    int n;
    cin>>n;
    cout<<num[n-1]<<endl;

    return 0;
}

Measured memory_bytes: 256
// abc122_a
#include "iostream"
using namespace std;

int main(int argc, char *argv[])
{
  char b;
  cin >> b;
  if(b == 'A') cout << 'T' << endl;
  else if(b == 'T') cout << 'A' << endl;
  else if(b == 'G') cout << 'C' << endl;
  else cout << 'G' << endl;
  return 0;
}


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

int cnt[2010];

int main()
{
    int n,x,y;
    cin >>n>>x>>y;
    if(x>y)swap(x,y);
    int i,j;
    for(i=1;i<n;i++){
        for(j=i+1;j<=n;j++){
            int d;
            if(x>=i){
                if(y<=j)d=j-i-(y-x)+1;
                else d=x-i+min(j-x,1+y-j);
            }
            else {
                if(y<=i)d=j-i;
                else if(y<=j)d=min(j-i,i-x+1+j-y);
                else d=min(j-i,i-x+1+y-j);
            }
            cnt[d]++;
        }
    }
    for(i=1;i<=n-1;i++){
        cout << cnt[i] << endl ;
    }


    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include<map>
#include<list>
#include<cctype>
#include<climits>
#include<bitset>
#include<stack>

using namespace std;

typedef long long ll;

#define int long long

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

int W, H, N, X[100000], Y[100000];
int X_[100000], Y_[100000];

int Calculate(int x, int y)
{
	int res = 0;
	int ma = 0;
	for (int i = 0; i < N; i++)
	{
		ma = max(ma, abs(x - X[i]) + abs(y - Y[i]));
		res += 2 * (abs(x - X[i]) + abs(y - Y[i]));
	}
	return res - ma;
}

signed main()
{
	cin >> W >> H >> N;
	for (int i = 0; i < N; i++)
	{
		cin >> X[i] >> Y[i];
		X_[i] = X[i]; Y_[i] = Y[i];
	}
	sort(X_, X_ + N);
	sort(Y_, Y_ + N);
	int idX = (N - 1) / 2, idY = (N - 1) / 2;
	int ansX, ansY, mi = LLONG_MAX / 2;
	for (int i = 0; i < 2; i++)
	{
		for (int j = 0; j < 2; j++)
		{
			int cost = Calculate(X_[idX + dx[i]], Y_[idY + dy[j]]);
			if (mi > cost)
			{
				mi = cost;
				ansX = X_[idX + dx[i]]; ansY = Y_[idY + dy[j]];
			}
		}
	}
	printf("%lld\n%lld %lld\n", mi, ansX, ansY);
	return 0;
}

Measured memory_bytes: 4292
s = int(input())

def func(x):
    if x % 2 == 0:
        return x//2
    else:
        return 3 * x + 1

a = [s]
for i in range(1000000):
    value = func(a[i])
    if value in a:
        print(i+2)
        break
    a.append(func(a[i]))




Measured memory_bytes: 2940
import collections
n = int(input())
a = list(map(int, input().split()))
ans = 0
dd = collections.defaultdict(int)
for i in range(n):
    dd[str(a[i])] += 1
for i in range(1, 10 ** 5 - 1):
    tmp = dd[str(i - 1)] + dd[str(i)] + dd[str(i + 1)]
    ans = max(ans, tmp)
print(ans)

Measured memory_bytes: 23000
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"

int main(void) {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    
    int n, Count = 0, Max = 0;
    cin >> n;
    for (int i = 0, x; i < n; i++) {
        cin >> x;
        if (Max <= x)
            Count++, Max = x;
    }
    cout << Count << endl;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int arr1[60][60] ;

int main()
{
    int n , m ;
    cin>>n>>m ;
    char arr[n+5][m+5] ;
    for(int i = 1 ; i <= n ; ++i)
    {
        for(int j = 1 ; j <= m ; ++j)
        {
            cin>>arr[i][j] ;
            if(arr[i][j] != '#')
                continue;
            arr1[i+1][j]++ , arr1[i-1][j]++ , arr1[i][j+1]++ , arr1[i][j-1]++ , arr1[i+1][j+1]++ , arr1[i+1][j-1]++ , arr1[i-1][j+1]++ , arr1[i-1][j-1]++;
        }
    }
    for(int i = 1 ; i <= n ; ++i)
    {
        for(int j = 1 ; j <= m ; ++j)
        {
            if(arr[i][j] == '#')
                cout<<arr[i][j];
            else
                cout<<arr1[i][j];
        }
        cout<<"\n";
    }
    return 0 ;
}


Measured memory_bytes: 256
/* ＵＴＦ－８ */
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <array>
#include <queue>
#include <stack>
#include <algorithm>
#include <tuple>
#include <numeric>
#include <type_traits>
#include <limits>

#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>

#define USE_COLORED 1

#ifdef USE_COLORED
static const char stdout_pre[]  = "\033[1m"; // bold black
static const char stderr_pre[]  = "\033[31;1m"; // bold red
static const char stdxxx_post[] = "\033[m";

// 当然ながら GCC(g++)/libstdc++ 依存
#include <ext/stdio_filebuf.h>
using stdio_filebuf = __gnu_cxx::stdio_filebuf<char>;
class colored_stdio_filebuf : public stdio_filebuf {
private:
	const char* const pre_;
	const char* const post_;

public:
	colored_stdio_filebuf(FILE* fp, const char* pre, const char* post) : stdio_filebuf(fp, std::ios_base::out), pre_(pre), post_(post)
	{
	}

protected:
	std::streamsize xsputn(const char* s, std::streamsize count) override
	{
		stdio_filebuf::xsputn(pre_, strlen(pre_));
		auto ret = stdio_filebuf::xsputn(s, count);
		stdio_filebuf::xsputn(post_, strlen(post_));
		return ret;
	}
};
#endif

int main()
{
#ifdef USE_COLORED
	if (getenv("DEBUG")) {
		std::cout.rdbuf(new colored_stdio_filebuf(stdout, stdout_pre, stdxxx_post));
		std::cerr.rdbuf(new colored_stdio_filebuf(stderr, stderr_pre, stdxxx_post));
	} else
#endif
	{
		int fd = open("/dev/null", O_WRONLY);
		dup2(fd, 2);
		close(fd);
	}
	
	std::string s, t;
	std::cin >> s >> t;
	std::sort(s.begin(), s.end());
	std::sort(t.begin(), t.end(), std::greater<char>());
	if (s < t) {
		std::cout << "Yes\n";
	} else {
		std::cout << "No\n";
	}
}


Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <numeric>
#include <set>
#include <unordered_set>
#include <queue>
#include <boost/math/constants/constants.hpp>
#include <boost/math/common_factor_rt.hpp>

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

int main() {
  string S;
  cin >> S;
  vector<char> v;
  int l = S.length();
  rep(i, l) v.push_back(S[i]);
  ll Q;
  cin >> Q;
  ll T;
  ll Tcount = 0;
  int F;
  char C;
  
  rep(i, Q){
    cin >> T;
    if(T==1){
      Tcount += 1;
    }else{
      cin >> F >> C;
      if((F+Tcount)%2==1){
        v.insert(v.begin(), C);
      }else{
        v.push_back(C);
      }
    }
    //cout << v[0] << v[1] << v[2] << endl;
  }
    
  if(Tcount%2==0){
    for(auto itr = v.begin(); itr != v.end(); ++itr) {
      cout << *itr;
    }
  }else{
    for(auto itr = v.end()-1; itr != v.begin()-1; --itr) {
      cout << *itr;
    }
  }
    
}

Measured memory_bytes: 1148
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>
#include <cmath>
#include <stack>
#include <map>
using namespace std;



int main(){
    string s ;
    cin >> s ;
    bool N = 0 ;
    bool S = 0 ;
    bool W = 0 ;
    bool E = 0 ;
    for (int i = 0; i < s.size(); i++)
    {
        if (s.at(i) == 'N')
        {
            N = 1 ;
        }else if (s.at(i) == 'S')
        {
            S = 1 ;
        }else if (s.at(i) == 'W')
        {
            W = 1 ;
        }else if (s.at(i) == 'E')
        {
            E = 1 ;
        }
        
    }
    if (!(N^S)&!(W^E))
    {
        cout << "Yes" ;
    }else
    {
        cout << "No" ;
    }
    cout << endl ;
    
    
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-

n = int(raw_input())
#print n

while True:
    try:
        a = map(int, raw_input().split())
        #print a
        a.sort(reverse=True)
        #print a

        b, c, d = a
        if (b * b) == ((c * c) + (d * d)):
            print 'YES'
        else:
            print 'NO'
    except EOFError:
        break;

Measured memory_bytes: 6404
def main():
    N = int(input())
    A = list(map(int, input().split()))
    Q = int(input())
    opeList = []

    for _ in range(Q):
        b, c = map(int, input().split())

        opeList.append([b, c])
    
    bucket = [0] * (10**5 + 1)
    sumA = sum(A)

    for num in A:
        bucket[num] += 1
    
    for ope in opeList:
        tmp = bucket[ope[0]]
        bucket[ope[0]] = 0
        bucket[ope[1]] += tmp
        sumA = sumA - ope[0] * tmp + ope[1] * tmp
        print(sumA)

if __name__ == '__main__':
    main()

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

N = int(input())
s = list(input())

def decide_i_plus_one(p, c, res):
  if c == 'S':
    if res == 'o':
      return p
    else:
      if p == 'S': return 'W'
      else:        return 'S'
  else:
    if res == 'o':
      if p == 'S': return 'W'
      else:        return 'S'
    else:
      return p

def valid(animals):
  # -2, -1, 0 のバリデーション
  if decide_i_plus_one(animals[-2], animals[-1], s[-1]) != animals[0]:
    return 0
  # -1, 0, 1 のバリデーション
  if decide_i_plus_one(animals[1], animals[0], s[0]) != animals[-1]:
    return 0

  # 0, 1, 2 のバリデーションは必要なし
  return 1

possible_pairs = [('S','S'), ('S','W'), ('W','S'), ('W','W')]
for (fst,snd) in possible_pairs:
  animals = []
  animals.append(fst)
  animals.append(snd)

  pi,ci = 0,1

  while 1:
    if ci == N-1:
      if valid(animals):
        print("".join(animals))
        exit(0)
      else:
        break

    n = decide_i_plus_one(animals[pi], animals[ci], s[ci])

    animals.append(n)
    pi += 1
    ci += 1

print("-1")

Measured memory_bytes: 4888
#include<bits/stdc++.h>
using namespace std;
int main(void){
    long long int n=0;
    cin>>n;
    long long int i,j,k;
    for(i=1;i<=3500;i++){
        for(j=1;j<=i;j++){
            long long int l=4*i*j-n*i-n*j;
            if(l<=0)continue;
            k=(int)((n*i*j)/l);
            if(4*i*j*k == n*(i*j+j*k+k*i)){
                goto ESCAPE;
            }
        }
    }
ESCAPE:
    cout<<i<<' '<<j<<' '<<k<<endl;
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;
using static AtCoderTemplate.MyLibrary;

namespace AtCoderTemplate
{
    class Program
    {
        static void Main (string[] args)
        {
            string[] str;
            str = Console.ReadLine ().Split (' ');

            int N = int.Parse (str[0]);
            long D = int.Parse (str[1]);

            int ans = 0;
            for (int i = 0; i < N; i++)
            {
                str = Console.ReadLine ().Split (' ');
                long X = int.Parse (str[0]);
                long Y = int.Parse (str[1]);

                if (X * X + Y * Y <= D * D) ans++;
            }

            Console.WriteLine (ans);

        }
    }

    class MyLibrary
    {
        public static int GCD (int a, int b)
        {
            if (a % b == 0) return b;
            return GCD (b, a % b);
        }
    }
}

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

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

	string s;
	cin >> s;

	string ans = "";
	for(auto i : s) {
		if(i == 'P')
			ans += i;
		else
			ans += 'D';
	}
	cout << ans << "\n";
}

Measured memory_bytes: 3896
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; (i) < (int)(n); ++(i))
#define REP3(i, m, n) for (int i = (m); (i) < (int)(n); ++(i))
#define REP_R(i, n) for (int i = (int)(n)-1; (i) >= 0; --(i))
#define REP3R(i, m, n) for (int i = (int)(n)-1; (i) >= (int)(m); --(i))
#define ALL(x) ::std::begin(x), ::std::end(x)
using namespace std;

int solve(int64_t K) {
  int64_t a = 7 % K;
  REP3(i, 1, K + 1) {
    if (a == 0)
      return i;
    a = (a * 10 + 7) % K;
  }
  return -1;
}

// generated by online-judge-template-generator v4.4.0
// (https://github.com/kmyk/online-judge-template-generator)
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  constexpr char endl = '\n';
  int64_t K;
  cin >> K;
  auto ans = solve(K);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define stoi stoll
using pii=pair<int,int>;
using vi = vector<int>;
using vvi = vector<vi>;
#define all(c) begin(c),end(c)
#define rall(c) rbegin(c),rend(c)
#define fore(x,c) for(auto &&x:c)
#define rep(i,a,n) for(int i=a,i##len=(int)(n);i<i##len;++i)
#define rrep(i, a, n) for(int i=(int)(n-1);i>=a;--i)
#define sz(c) ((int)c.size())
#define contains(c,x) (c.find(x)!=end(c))
#define inseg(l,x,r) ((l)<=(x)&&(x)<(r))
#define dump(...)
#define pb push_back
#define _ 0
const signed INF_=1001001001; const long long INF=1001001001001001001LL;
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) {
    for (auto i = begin(v); i != end(v); i++) os<<*i<<(i==end(v)-1?"":" ");return os;}
template<class T> istream& operator>>(istream &is,vector<T> &v) {
    for (auto i = begin(v); i != end(v); i++) is>>*i;return is;}
template<class T,class U> istream& operator>>(istream &is, pair<T,U> &p) {
    is>>p.first>>p.second;return is;}
template<class T, class U> bool chmax(T &a,const U &b){return a<b?a=b,1:0;}
template<class T, class U> bool chmin(T &a,const U &b){return a>b?a=b,1:0;}
template <class T> void psum(T& c) {partial_sum(begin(c), end(c), begin(c));}
template<class T> using heap=priority_queue<T,vector<T>,greater<T>>;
struct before_main_function {
    before_main_function() {
        cin.tie(nullptr); ios::sync_with_stdio(0);
        cout << setprecision(15) << fixed;
        // #define endl "\n"
    }
} before_main_function;
//------------------8<------------------------------------8<--------------------

signed main() {
    int N;
    cin >> N;
    map<string, int> cnt;
    int ans = 0;
    rep(i, 0, N) {
        string s;
        cin >>s;
        sort(all(s));
        ans += cnt[s];
        cnt[s]++;
    }
    cout << ans << endl;
    return (0^_^0);
}



Measured memory_bytes: 11264
//#define NDEBUG
#include <cstddef>
#include <cstdint>
#include <vector>

using i8 = ::std::int_least8_t;
using i32 = ::std::int_least32_t;
using i64 = ::std::int_least64_t;
using u8 = ::std::uint_least8_t;
using u32 = ::std::uint_least32_t;
using u64 = ::std::uint_least64_t;
using isize = ::std::ptrdiff_t;
using usize = ::std::size_t;

template <class T = usize> class rep {
	const T f, l;

public:
	class itr {
		friend rep;
		T i;
		constexpr itr(T x) noexcept : i(x) {}

	public:
		void operator++() noexcept { ++i; }
		constexpr T operator*() const noexcept { return i; }
		constexpr bool operator!=(const itr x) const noexcept { return i != x.i; }
	};
	constexpr rep(const T first, const T last) noexcept : f(first), l(last) {}
	constexpr itr begin() const noexcept { return itr(f); }
	constexpr itr end() const noexcept { return itr(l); }
};
template <class T = usize> class revrep {
	const T f, l;

public:
	class itr {
		friend revrep;
		T i;
		constexpr itr(T x) noexcept : i(x) {}

	public:
		void operator++() noexcept { --i; }
		constexpr T operator*() const noexcept { return i; }
		constexpr bool operator!=(const itr x) const noexcept { return i != x.i; }
	};
	constexpr revrep(const T first, const T last) noexcept : f(first), l(last) {}
	constexpr itr begin() const noexcept { return itr(l - 1); }
	constexpr itr end() const noexcept { return itr(f - 1); }
};
template <class T> bool amax(T &a, const T &b) {
	return a <= b ? (a = b, 1) : 0;
}
template <class T> bool amin(T &a, const T &b) {
	return b <= a ? (a = b, 1) : 0;
}
template <class T> bool asmax(T &a, const T &b) {
	return b <= a ? 0 : (a = b, 1);
}
template <class T> bool asmin(T &a, const T &b) {
	return a <= b ? 0 : (a = b, 1);
}
template <class T> using vec_alias = ::std::vector<T>;
template <class T> auto md_vec(usize n, const T &value) {
	return ::std::vector<T>(n, value);
}
template <class... Args> auto md_vec(usize n, Args... args) {
	return ::std::vector<decltype(md_vec(args...))>(n, md_vec(args...));
}
template <class T> const T &as_const(const T &v) noexcept { return v; }
template <class T> constexpr T difference(const T &a, const T &b) {
	return a <= b ? b - a : a - b;
}

#include <algorithm>
#include <iostream>
#include <utility>
#include <string>
#include <numeric>
#include <stack>

int main() {
	usize n, m;
	::std::cin >> n >> m;
	auto g = md_vec(n, 0, usize());
	::std::vector<usize> deg(n, 0);
	for (const auto i : rep<>(0, n - 1 + m)) {
		usize a, b;
		::std::cin >> a >> b;
		--a;
		--b;
		g[a].push_back(b);
		++deg[b];
	}
	::std::stack<usize> st;
	for (const auto i : rep<>(0, n)) {
		if (deg[i] == 0) {
			st.push(i);
		}
	}
	::std::vector<usize> topol;
	while (!st.empty()) {
		const auto v = st.top();
		st.pop();
		topol.push_back(v);
		for (const auto e : g[v]) {
			--deg[e];
			if (deg[e] == 0) {
				st.push(e);
			}
		}
	}
	::std::vector<usize> ans(n, 0), dist(n, 0);
	for (const auto v : topol) {
		for (const auto e : g[v]) {
			if (asmax<usize>(dist[e], dist[v] + 1)) {
				ans[e] = v + 1;
			}
		}
	}
	for (const auto e : ans) {
		::std::cout << e << ::std::endl;
	}
	return 0;
}


Measured memory_bytes: 9588
#include <bits/stdc++.h>
using namespace std; 
using ll = long long;
signed main() { 
	cin.tie(0);
	cin.sync_with_stdio();
	int n; 
	cin>>n;
	set<int> s;
	for(int i = 0; i < n; i++){
		int a;
		cin>>a;
		s.insert(a);
	}
	if(s.size() == n){
		cout<<"YES";
	}else{
		cout<<"NO";
	}
}


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

#define ll long long
#define endl "\n"
#define FAST ios_base::sync_with_stdio(false); cin.tie(NULL);


void solve()
{
	ll n,sum=0;
	cin>>n;
	ll a[n];
	for(ll i=0;i<n;i++) 
	{
		cin>>a[i];
	}
	sort(a,a+n);
	sum=a[n-1];
	ll tt=n-2;
	for(ll i=n-2;i>=0;i--)
	{
		if(tt==0) break;
		if(tt>1)
		{
			sum+=2*a[i];
			tt-=2;	
		}
		else
		{
			sum+=a[i];
			tt--;
		}
		if(tt==0) break;
	}
	cout<<sum;
}

int main()
{
	FAST
	ll t=1;
	//cin>>t;
	for(ll i=0;i<t;i++) solve();
	return 0;
}

Measured memory_bytes: 5144
import std.stdio, std.string, std.conv;

enum N = 110000;
enum M = 10000;
immutable hurui = {
    bool[N + 1] table;
    table[] = true;
    table[0 .. 2] = false;
    for(int i = 2; i * i <= N; ++i)
    {
        if(table[i])
        {
            for(int j = 2; i * j <= N; j++)
            {
                table[i * j] = false;
            }
        }
    }
    return table;
}();

immutable res = {
    int[M + 1] table;
    int sum, index;
    for(int i = 1; i <= N && index < M; ++i)
    {
        if(hurui[i]) table[++index] = (sum += i);
    }
    return table;
}();

void main()
{
    while(true)
    {
        int n = readln.chomp.to!int;
        if(!n) break;
        res[n].writeln;
    }
}

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

#ifdef _DEBUG
#define debug(x) cout<<#x<<": "<<x<<endl
#else
#define debug(x)
#endif

using namespace std;

struct UnionFind {
  vector<int> data;
  UnionFind(int size) : data(size, -1) { }
  bool unionSet(int x, int y) {
    x = root(x); y = root(y);
    if (x != y) {
      if (data[y] < data[x]) swap(x, y);
      data[x] += data[y]; data[y] = x;
    }
    return x != y;
  }
  bool findSet(int x, int y) {
    return root(x) == root(y);
  }
  int root(int x) {
    return data[x] < 0 ? x : data[x] = root(data[x]);
  }
  int size(int x) {
    return -data[root(x)];
  }
};

int main() {
    int N, M, K;
    cin >> N >> M >> K;
    // (is_friend, id)*
    vector<set<int>> f_graph(N), b_graph(N);
    for (int i = 0; i < M; ++i) {
        int A, B;
        cin >> A >> B;
        --A, --B;
        f_graph[A].insert(B);
        f_graph[B].insert(A);
    }
    for (int i = 0; i < K; ++i) {
        int A, B;
        cin >> A >> B;
        --A, --B;
        b_graph[A].insert(B);
    }

    vector<int> parent(N, -1);

    for (int i = 0; i < N; ++i) {
        if (parent[i] == -1) {
            queue<int> Q;
            Q.push(i);
            while (!Q.empty()) {
                int cur = Q.front(); Q.pop();
                if (parent[cur] != -1) { continue; }
                // cout << "Visits " << cur << endl;
                parent[cur] = i;
                for (auto j : f_graph[cur]) {
                    if (parent[j] != -1) { continue; }
                    Q.push(j);
                }
            }
            // cout << "End" << endl;
        }
    }

    // for (int i = 0; i < N; ++i) {
    //     cout << parent[i] << " ";
    // }
    // cout << endl;

    UnionFind uf(N);
    for (int i = 0; i < N; ++i) {
        uf.unionSet(i, parent[i]);
    }
    vector<int> nb_in_cc(N);
    for (int i = 0; i < N; ++i) {
        for (auto j : b_graph[i]) {
            if (uf.findSet(i, j) && f_graph[i].count(j) == 0) {
                nb_in_cc[i]++;
                nb_in_cc[j]++;
            }
        }
    }
    // for (int i = 0; i < N; ++i) {
    //     cout << i << ":" << endl;
    //     cout << uf.size(i) << endl;
    //     cout << f_graph[i].size() << endl;
    //     cout << nb_in_cc[i] << endl;
    // }
    for (int i = 0; i < N; ++i) {
        cout << (int)uf.size(i) - 1 - (int)f_graph[i].size() - (int)nb_in_cc[i] << " ";
    }
    cout << endl;
}

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

void read(int &x) {
    x=0;int f=1;char ch=getchar();
    for(;!isdigit(ch);ch=getchar()) if(ch=='-') f=-f;
    for(;isdigit(ch);ch=getchar()) x=x*10+ch-'0';x*=f;
}

void print(int x) {
    if(x<0) putchar('-'),x=-x;
    if(!x) return ;print(x/10),putchar(x%10+48);
}
void write(int x) {if(!x) putchar('0');else print(x);putchar('\n');}

#define lf double
#define ll long long 

#define pii pair<int,int >
#define vec vector<int >

#define pb push_back
#define mp make_pair
#define fr first
#define sc second

#define data asd09123jdf02i3h

#define FOR(i,l,r) for(int i=l,i##_r=r;i<=i##_r;i++)

const int maxn = 1e6+10;
const int inf = 1e9;
const lf eps = 1e-8;
const int mod = 1e9+7;

int a,b,n;
int sta[maxn],top,ans[maxn];

int query(int x,int y) {
    printf("? %d %d\n",x-1,y-1);fflush(stdout);
    char s[3];scanf("%s",s+1);
    return s[1]=='Y';
}

int main() {
    read(a),read(b),n=a+b;
    if(b>=a) return puts("Impossible"),0;
    for(int i=1;i<=n;i++)
        if(!top) sta[++top]=i;
        else if(query(sta[top],i)) sta[++top]=i;
        else top--;
    for(int i=1;i<=n;i++) ans[i]=query(sta[top],i);
    printf("! ");
    for(int i=1;i<=n;i++) printf("%d",ans[i]);puts("");
    return 0;
}


Measured memory_bytes: 2772
// D - Not Divisible

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// const int INF = 2147483647;
// const ll INF = 9223372036854775807;
// const ll MOD = 1e9 + 7;

vector<int> enum_divisor(int n) {
	vector<int> result;
	for(int i=1; i*i <= n; i++){
		if(n % i == 0){
			result.push_back(i);
			if(i*i != n) result.push_back(n / i);
		}
	}

	return result;
}

int A[200000];
unordered_map<int, int> cnt;

int main() {
	int N;
	cin >> N;

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

	int ans = 0;

	for (int i=0; i<N; i++) {
		if (cnt[A[i]] >= 2) {
			continue;
		}

		bool no_div = true;

		if (A[i] == 1) {
			ans++;
			continue;
		}

		for(int k=1; k*k <= A[i]; k++){
			if(A[i] % k == 0) {
				int d1 = k;
				int d2 = A[i] / k;

				if (cnt[d1] > 0 || (d2 != A[i] && cnt[d2] > 0)) {
					no_div = false;
					break;
				}
			}
		}

		if (no_div) ans++;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 32516
#include<set>
#include<map>
#include<cmath>
// #include<ctime>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<string>
#include<vector>
#include<cstring>
#include<iostream>
#include<algorithm>
#define INF 0x3f3f3f3f
#define eps 1e-8
#define re register
#define LL long long
// #define MOD 1000000007ll
#define MAXN 3005
using namespace std;
struct Edge{
	int to,nex;
	Edge(){}
	Edge(int a,int b){
		to=a,nex=b;
	}
}e[MAXN<<1];
LL n,cnt,hd[MAXN],a[MAXN];
LL rd(){
	LL x=0,tp=1;char c;
	c=getchar();
	while(c<'0' || c>'9'){if(c=='-')tp=-1;c=getchar();}
	while(c>='0' && c<='9'){
		x=x*10+c-'0';
		c=getchar();
	}
	return x*tp;
}
void adde(int x,int y){
	e[++cnt]=Edge(y,hd[x]);
	hd[x]=cnt;
}
bool dfs(int now,int fa){
	for(int i=hd[now];i;i=e[i].nex){
		if(e[i].to!=fa && a[e[i].to]<a[now] && !dfs(e[i].to,now)){
			return 1;
		}
	}
	return 0;
}
int main(){
	// freopen("testdata.in","r",stdin);
	// freopen("sb.out","w",stdout);
	LL x,y;
	n=rd();
	for(int i=1;i<=n;i++){
		a[i]=rd();
	}
	for(int i=1;i<n;i++){
		x=rd(),y=rd();
		adde(x,y);
		adde(y,x);
	}
	for(int i=1;i<=n;i++){
		if(dfs(i,i)){
			printf("%d ",i);
		}
	}
	printf("\n");
	// printf("%.2lf\n",(double)clock()/CLOCKS_PER_SEC);
	return 0;
}


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

int main(){
	int64_t A,B,C,K;
  	cin >> A >> B >> C >> K;
  	int64_t ans=0;
  	if(A >= K){cout << K << endl;}
  	else{
    	ans+=A;
      	K-=A;
      	if(B >= K){cout << ans << endl;}
      	else{
        	K-=B;
          	cout << ans - K << endl;
        }
    }
  
}


Measured memory_bytes: 3568
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <utility>
#include <tuple>
#include <cctype>
#define INF 0x3f3f3f3f
#define MOD 1000000007
#define PI 4*atan(1.0)
typedef long long ll;
typedef long double ld;
using namespace std;
int dx[4]={0,0,-1,1};
int dy[4]={-1,1,0,0};
const int SIZE=100050;
//int arr[SIZE]={};
//ここまでテンプレ
int main(){
	int A,B;
	cin>>A>>B;
	if(A%3==0 || B%3==0 || (A+B)%3==0)
		cout<<"Possible"<<endl;
	else
		cout<<"Impossible"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for(int64_t i=0;i<(n);i++)
#define ALL(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define REV(c) reverse((c).begin(),(c).end())
#define YES cout << "YES" << endl;
#define NO cout << "NO" << endl;
#define Yes cout << "Yes" << endl;
#define No cout << "No" << endl;
#define VIN(n,v) for(int64_t i=0;i<(n);i++){cin >> (v).at(i);}

using namespace std;
typedef int64_t I;
typedef pair<I,I> P;
typedef vector<I> V;

I MOD = pow(10,9)+7;

// 最大公約数
I gcd(I a, I b) {
  return b != 0 ? gcd(b, a % b) : a;
}

// 最小公倍数
I lcm(I a, I b) {
  return a * b / gcd(a, b);
}

int ctoi(char c){
  return c - '0';
}

int main(){
  I n;
  cin >> n;
  V h(n);
  VIN(n,h);
  I t = 0;
  REP(i,n){
    if (t < h.at(i)){
      t = h.at(i);
    }else if (t - 1 >  h.at(i)){
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  return 0;
}



Measured memory_bytes: 1024
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def enum_primes(n):
    flag_num = (n + 1) // 2
    prime_flag = [True] * flag_num

    for num in range(3, int(n ** 0.5) + 1, 2):
        idx = (num - 1) // 2 - 1
        if prime_flag[idx]:
            for j in range(idx + num, flag_num, num):
                prime_flag[j] = False

    primes = [2]
    temp = [(i + 1) * 2 + 1 for i in range(flag_num) if prime_flag[i]]
    primes.extend(temp)

    return primes


def main():
    N = int(readline())
    A = list(map(int, readline().split()))
    primes = enum_primes(10 ** 6 + 1)

    def judge():
        seq = [False] * (10 ** 6 + 1)
        A.sort()

        for x in A:
            if x == 1:
                continue
            if seq[x]:
                return False
            seq[x] = True

        for prime in primes:
            cnt = 0
            for i in range(prime, 10 ** 6 + 1, prime):
                if seq[i]:
                    cnt += 1
            if cnt > 1:
                return False
        return True

    if judge():
        print("pairwise coprime")
    else:
        from math import gcd
        cur = A[0]
        for x in A[1:]:
            cur = gcd(cur, x)

        if cur == 1:
            print("setwise coprime")
        else:
            print("not coprime")


if __name__ == '__main__':
    main()


Measured memory_bytes: 202788
import java.util.*;
public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int H[] = new int[N];
		int max = 0;
		int ans = 0;
		for(int i = 0; i < N; i++) {
			H[i] = sc.nextInt();
			if(max <= H[i]) {
				max = H[i];
				ans++;
			}
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 21844
import sys
sys.setrecursionlimit(10**6)
s=list(input())
t=list(input())

tsr=list(t)+list(s)
while len(tsr)<2*len(t)+len(s):
  tsr+=s
#print(tsr)

#Z[i]: 文字列Sと各S[i:]の最長共通接頭辞の長さ
def z_alg(S):
  NN=len(S)
  Z=[NN]+[0]*(NN-1)
  i,j=1,0
  while i<NN:
    while i+j<NN and S[j]==S[i+j]:
      j+=1
    if not j:
      i+=1
      continue
    Z[i]=j
    k=1
    while NN-i>k and k<j-Z[k]:
      Z[i+k]=Z[k]
      k+=1
    i+=k
    j-=k
  return Z

zlist=z_alg(tsr)
#print(zlist)

match_list=[]
for i in range(len(s)):
  match_list.append(zlist[i+len(t)]>=len(t))
#print(match_list)

path=[-1]*len(s)
for i in range(len(s)):
  if match_list[i]:
    path[i]=(i+len(t))%len(s)
#print(path)

dist=[-1]*len(s)
for i in range(len(s)):
  if dist[i]!=-1:
    continue
    
  d=0
  offset=0
  stack=[i]
  ii=i
  while path[ii]!=-1:
    if d>len(s):
      print(-1)
      sys.exit(0)
    elif dist[ii]!=-1:
      offset=dist[ii]
      break    
    ii=path[ii]
    stack.append(ii)
    d+=1
  
  cnt=0
  while stack:
    p=stack.pop()
    dist[p]=offset+cnt
    cnt+=1
    
#print(dist)
print(max(dist))

Measured memory_bytes: 169700
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<double,int> P;

int n;
double x[1005],y[1005],r[1005];
double cost[1005][1005];
double dp[1005];
int main(void){
	scanf("%lf%lf%lf%lf",&x[0],&y[0],&x[1],&y[1]);
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%lf%lf%lf",&x[i+2],&y[i+2],&r[i+2]);
	}
	n+=2;
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			double dis=(x[i]-x[j])*(x[i]-x[j]);
			dis+=(y[i]-y[j])*(y[i]-y[j]);
			dis=sqrt(dis);
			if(dis<=r[i]+r[j]){
				dis=0.0;
			}else{
				dis-=r[i]+r[j];
			}
			cost[i][j]=dis;
		}
	}
	for(int i=0;i<n;i++){
		dp[i]=1e18;
	}
	dp[0]=0;
	priority_queue<P,vector<P>,greater<P> > que;
	que.push(P(0.0,0));
	while(que.size()){
		P p=que.top();
		que.pop();
		if(p.first>dp[p.second])continue;
		for(int j=0;j<n;j++){
			if(p.second==j)continue;
			double nc=p.first+cost[p.second][j];
			if(dp[j]>nc){
				dp[j]=nc;
				que.push(P(nc,j));
			}
		}
	}
	printf("%.10f\n",dp[1]);
	return 0;
}

Measured memory_bytes: 12784
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
constexpr ll mod=1000000007;

int N,K;
ll A[100001],res;

ll pw(ll x,int y){
	ll a=1;
	while(y){
		if(y&1)a=a*x%mod;
		x=x*x%mod;
		y/=2;
	}
	return a;
}

int main(){
	cin>>N>>K;
	for(int i=K;i>=1;i--){
		A[i]=pw(K/i,N);
		for(int j=i+i;j<=K;j+=i){
			A[i]=(A[i]+mod-A[j])%mod;
		}
		res+=A[i]*i;
		res%=mod;
	}
	cout<<res<<endl;
}


Measured memory_bytes: 4372
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.stream.Stream;

public class Main {
  public static void main(String[] args) throws Exception {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
    String s = br.readLine();
    String[] sa = s.split(" ");
    int n = Integer.parseInt(sa[0]);
    int y = Integer.parseInt(sa[1]);
    int yukichi = -1;
    int ichiyou = -1;
    int hideyo = -1;
    for (int a = 0; a <= n; a++) {
      for (int b = 0; b <= n -a; b++) {
        int c = n - a - b;
        int total = 10000*a + 5000*b + 1000*c;
        if (total == y) {
          yukichi = a;
          ichiyou = b;
          hideyo = c;
        }
      }
    }
    out.println(yukichi + " " + ichiyou + " " + hideyo);
    out.close();
  }
}

Measured memory_bytes: 37284
def n0():return int(input())
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(input()) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]

a,b,c,k=n1()
if k<=a:
    print(k)
elif k<=a+b:
    print(a)
else:
    print(a-(k-(a+b)))

Measured memory_bytes: 9200
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

def main():
    N,K=map(int,input().split())
    A=list(map(int,input().split()))
    SUM=sum(A)
    l=[]
    for i in range(1,int(SUM**0.5)+1):
        if SUM%i==0:
            l.append(i)
            l.append(SUM//i)
    ans=0
    for x in l:
        B=[A[i]%x for i in range(N)]
        B.sort()
        S_m=[0]*(N+1)
        S_p=[0]*(N+1)
        for i in range(N):
            S_m[i+1]=S_m[i]+B[i]
            S_p[i+1]=S_p[i]+x-B[i]
        for i in range(N+1):
            if max(S_m[i],S_p[N]-S_p[i])<=K:
                ans=max(ans,x)
                break
    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 42348
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
 
#define inp 20
#define check exit(0)
#define nl cout<<endl;
#define mod 1000000007 
#define ll long long int
#define trace(x) cerr<<#x<<" : "<<x<<endl;
#define deb(v) for(int i=0;i<v.size();i++) {cout<<v[i]; (i==v.size()-1) ? cout<<"\n":cout<<" "; }
#define jaldi ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ordered_set tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update>
 
using namespace __gnu_pbds;
using namespace std;
 
// Errichto ... ;)

void md(ll &a)
{
    a%=mod;
}
void add_self(int& a, int b) {
    a += b;
    if(a >= mod) {
        a -= mod;
    }
}
void sub_self(int& a, int b) {
    a -= b;
    if(a < 0) {
        a += mod;
    }
}

int main()
{
    jaldi

    int n,k;
    cin>>n>>k;
    vector<int> dp(k+1,0);
    dp[0]=1;

    for(int child=1;child<=n;child++)
    {
        int upto;
        cin>>upto;

        vector<int> tmp(k+2,0);
        for(int ubho=k;ubho>=0;ubho--)
        {
            int toadd=dp[ubho];
            int l=ubho+1;
            int r=ubho+min(upto,k-ubho);
            if(l<=r)
            {
                add_self(tmp[l],toadd);
                sub_self(tmp[r+1],toadd);
            }
        }
        int ps=0;
        for(int i=0;i<=k;i++)
        {
            ps+=tmp[i];
            ps%=mod;
            dp[i]+=ps;
            dp[i]%=mod;
            // add_self(ps,tmp[i]);
            // add_self(dp[i],ps);
        }
    }
    cout<<dp[k];

    return 0;
}

Measured memory_bytes: 4044
#include <iostream>
#include <algorithm>
#include <set>

int main() {
	std::set<long long> s;
	long long N;
	std::cin >> N;
	for (int i = 0; i < N; i++) {
		auto a = 0LL;
		std::cin >> a;
		if (!s.insert(a).second) {
			std::cout << "NO" << std::endl;
			return 0;
		}
	}
	std::cout << "YES" << std::endl;
	return 0;
}


Measured memory_bytes: 9600