akhauriyash/Code-Regression huggingface dataset:
from collections import Counter
n = int(input())
a = Counter(map(int, input().split()))
MAX = 1000000 + 9
dp = [True] * MAX
for num in a:
    for i in range(num*2, MAX, num):
        dp[i] = False
ans = 0
for num in a:
    if dp[num] and a[num] == 1:
        ans += 1
print(ans)


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

int main() {
  int N;
  cin >> N;
  vector<int> vec(N);
  for(int i = 0;i < N ;i++){
    cin >> vec.at(i);
  }
  sort(vec.begin(),vec.end());
  reverse(vec.begin(),vec.end());
  int A = 0,B = 0;
  for(int i =0;i<N ; i++){
    if(i % 2 == 0){
      A += vec.at(i);
    }else{
      B += vec.at(i);
    }
  }
  cout << A - B << endl;
}
      

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

long dp[105][100005];

int main() {
  long N, W;
  cin >> N >> W;
  vector<long> w(N), v(N);
  for (int i = 0; i < N; i++) cin >> w[i] >> v[i];
  for (int i = 0; i < N; i++) {
    for (int j = 0; j <= W; j++) {
      if (j-w[i] < 0) dp[i+1][j] = dp[i][j];
      else dp[i+1][j] = max(dp[i][j], dp[i][j-w[i]] + v[i]);
    }
  }
  cout << dp[N][W] << endl;
}

Measured memory_bytes: 79360
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    int N, X; cin >> N >> X;
    int bound = 0,ans = 0; 
    while( bound <= X && ans != N + 1){
        ans++;
        int l; cin >> l;
        bound += l;
    }
 
 
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
using namespace std;
typedef long long int ll;
const int MAXN=1001;
int n,place;
int fa[MAXN],opt[MAXN],tot=0;
ll arr[MAXN],dp[MAXN],ans=-1e9-1;
bool flag=true;
int main(){
	ios::sync_with_stdio(false);
	cin>>n;
	for(int i=1;i<=n;++i){
		cin>>arr[i];
		dp[i]=arr[i];
		if(arr[i]>0) flag=false;
	}
		for(int i=1;i<=n;++i)
		for(int j=1;j<i;++j)
			if(((i-j)&1)==0){
				if(dp[j]+arr[i]>dp[i]){
					dp[i]=dp[j]+arr[i];
					fa[i]=j;
				}
			}
	for(int i=1;i<=n;++i){
		if(dp[i]>ans){
			ans=dp[i];
			place=i;
		}
	}
	for(int i=n;i>place;--i) opt[++tot]=i;
	while(fa[place]!=0){
		int Next=fa[place];
		int mid=(Next+place)>>1;
		for(int i=mid;i>Next;--i) opt[++tot]=i;
		place=fa[place];
	}
	for(int i=1;i<place;++i) opt[++tot]=1;
	cout<<ans<<endl<<tot<<endl;
	for(int i=1;i<=tot;++i) cout<<opt[i]<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<map>
#include<cstring>
#include<string>
#include<vector>
#include<queue>
#include<cmath>
#include<iomanip>
using namespace std;
const int maxn =1e5+4;
const int inf=1e9;
typedef long long ll;
const ll mod=998244353;
int main(){
	int n;
	int a[200];
	while(cin>>n){
		int ans=inf;
		int i,j;
		for(i=1;i<=n;i++)
			scanf("%d",&a[i]);
		sort(a+1,a+1+n);
		int tmp;
		for(i=a[1];i<=a[n];i++){
			tmp=0;
			for(j=1;j<=n;j++)
				tmp+=(a[j]-i)*(a[j]-i);
			ans=min(ans,tmp);
		}
		cout<<ans<<endl;
	}
}

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

using namespace std;
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))
#define endl "\n"
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {os << "["; for (const auto &v : vec) {os << v << ","; } os << "]"; return os;}
template <typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &p) {os << "(" << p.first << ", " << p.second << ")"; return os;}

ll f(ll x, ll c, ll d) {
    ll na = x / c;
    ll nb = x / d;
    ll nc = x / (c / __gcd(c, d) * d);
    return x - (na + nb - nc);
}

void solve() {
    ll A, B, C, D;
    cin >> A >> B >> C >> D;
    cout << f(B, C, D) - f(A - 1, C, D) << endl;
}

int main() {
    #ifdef LOCAL_ENV
    cin.exceptions(ios::failbit);
    #endif
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    
    solve();
}

Measured memory_bytes: 256
#include<stdio.h>
#define MAX 100
static const int INFTY = (1<<21);
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;

int n, M[MAX][MAX];

int prim()
{
  int u,minv;
  int d[MAX],p[MAX],color[MAX];
  int i,v,sum=0;
 
  for(i=0;i<n;i++)
    {
      d[i]=INFTY;
      p[i]=-1;
      color[i]=WHITE;
    }
  d[0]=0;
  
  while(1)
    {
      minv=INFTY;
      u=-1;
      for(i=0;i<n;i++)
	{
	  if(minv>d[i] && color[i] != BLACK)
	    {
	      u=i;
	      minv =d[i];
	    }
	}

      if(u==-1) break;
      color[u]=BLACK;

      for(v=0;v<n;v++)
	{
	  if(color[v]!=BLACK && M[u][v]!=INFTY)
	    {
	      if(d[v]>M[u][v])
		{
		  d[v]=M[u][v];
		  p[v]=u;
		  color[v]=GRAY;
		}
	    }
	}
    }

  for(i=0;i<n;i++)
    {
      if(p[i]!=-1) sum+= M[i][p[i]];
    }

  return sum;
}


int main()
{
  int i,j,e;

  scanf("%d",&n);
  for(i=0;i<n;i++)
    {
      for(j=0;j<n;j++)
	{
	  scanf("%d",&e);
	  M[i][j]=(e==-1)?INFTY:e;
	}
    }

  printf("%d\n",prim());

  return 0;
}

      



Measured memory_bytes: 2108
// 今日はお盆前の最終出社日です
// いい加減寝ろ

#include <bits/stdc++.h>
#define mod 1000000007
#define INF LLONG_MAX
#define ll long long
#define ln cout<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
using namespace std;
ll dx[4]={1,0,-1,0};
ll dy[4]={0,1,0,-1};

/*

型を使いたいように合わせる！！！！！！！！！！！！！！！！！！！！！！！！！！！！

*/
bool comp(pair<ll, ll> a, pair<ll , ll> b) {
    // 基本はfirstで比較
    if(a.first != b.first){
         return a.first < b.first; // 昇順
        //return a.first > b.first; // 降順
    }

    // それ以外はsecondで比較
    if(a.second != b.second){
        return a.second > b.second;
    }else{
        // どちらも同じ
        return true;
    }
}
int main() {
    cin.tie(0);
   	ios::sync_with_stdio(false);
    ll a,b,c,d,maxi=0,f=0,mini=INF,sum=0;
    ll n;
    ll k;
    cin>>n>>a>>d;
    vector<pair<ll,ll>> p(n);
        //vector<pair<ll,ll>> pa(n);
    map<ll,ll> m;
    rep(i,n){
        cin>>c>>b;
        p[i]=make_pair(c,b);
    }
    sort(all(p),comp);
    //lastexplosionが範囲に入っていた時のダメージが入っている
    ll lastd=0;
    //lastexplosionの影響範囲が入っている
    ll lastx=-1;
    ll bombs=0;
    ll lastfirst=0;
    deque<pair<ll,ll>> dq;
    rep(i,n){
        while(!dq.empty()&&dq.front().first<p[i].first){
            bombs-=dq.front().second;
            dq.pop_front();
        }
        //if(lastd>=p[i].second) continue;
        if(!dq.empty()&&dq.front().first>=p[i].first&&bombs*d>=p[i].second) continue;
        //まえの爆発の影響範囲内の時
        if(!dq.empty()&&dq.front().first>=p[i].first){
            //cout<<"hanni nai";
            ll lastbomb=bombs;
            bombs+=(p[i].second-bombs*d)/d;
            if(((p[i].second-bombs*d)%d)!=0) bombs++;
            sum+=bombs-lastbomb;
            pair <ll,ll> pa;
            pa=make_pair(p[i].first+a*2,bombs-lastbomb);
            dq.push_back(pa);
        }else{
        //まえの爆発の影響範囲外の時
            ll lastbomb=bombs;
            bombs+=(p[i].second)/d;
            if((p[i].second%d)!=0) bombs++;
            sum+=bombs-lastbomb;
            pair <ll,ll> pa;

            pa=make_pair(p[i].first+a*2,bombs-lastbomb);
            dq.push_back(pa);
        }
        //cout<<i<<" "<<sum<<endl;
        //while(i<n-1&&p[i].first==p[i+1].first) i++;
        //lastx=p[i].first+a*2;
        
    }
    cout<<sum<<endl;


    return 0;
}


Measured memory_bytes: 7940
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(x) x.begin(), x.end()
#define mod 1000000007
typedef long long ll;

int main() {
    int l, r, d;
    cin >> l >> r >> d;
    int cnt = 0;
    for(int i=l; i<=r; i++){
        if(i % d == 0) cnt++;
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 3636
main(n,m,c,i){
  scanf("%d%d",&n,&m);
  for(i=0;i<2*n;i++)a[i]=i+1;
  for(;m;m--){
    scanf("%d",&c);
    if(!c)
      for(i=0;i<2*n;i++)
        b[2*i]=a[i],b[2*i+1]=a[n+i];
    else{
      for(i=0;i<c;i++)
        b[2*n-c+i]=a[i];
      for(;i<2*n;i++)
        b[i-c]=a[i];
    }
    strcpy(a,b);
  }
  for(i=0;i<2*n;i++)printf("%u\n",a[i]&0xff);
  return 0;
}

Measured memory_bytes: 0
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
int main(void){
	int r,g,b,sum;
	cin>>r>>g>>b;
	sum+=r*100+g*10+b;
	if(sum%4==0) cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
	return 0;
}

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

using namespace std;

int main(){
    int n;
    int x;
    cin >> n >> x;
    vector<int> v(n);
    for (int i = 0;i < n;i++){
        cin >> v[i];
    }
    sort(v.begin(),v.end());
    int a = 0;
    for(int i = 0;i<n;i++){
        x -= v[i];
        if(x >= 0){
            a++;
        }
        else{
            break;
        }
    }
    if(x > 0) a--;
    cout << a << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define pi M_PI
#define EPS 1e-6
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int main() {
    int n, w, d;
    while (cin >> n >> w >> d && w){
        vector<P> cake;
        cake.push_back(make_pair(w, d));
        while (n--){
            int p, s;
            cin >> p >> s;
            p--;
            int x = cake[p].first, y = cake[p].second;
            cake.erase(cake.begin()+p);
            P a, b;
            s %= x + y;
            if (s < x){
                a.first = s;
                a.second = y;
                b.first = x-s;
                b.second = y;
            }else{
                s -= x;
                a.first = x;
                a.second = s;
                b.first = x;
                b.second = y-s;
            }
            if (a.first * a.second < b.first * b.second){
                cake.push_back(a);
                cake.push_back(b);
            }else{
                cake.push_back(b);
                cake.push_back(a);
            }
        }
        VI area(cake.size());
        REP(i,cake.size()) area[i] = cake[i].first * cake[i].second;
        sort(area.begin(), area.end());
        REP(i,area.size()){
            if (i > 0) cout << " ";
            cout << area[i];
        }
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 3164
#include "bits/stdc++.h"
#define LF '\n'
#define ALL(x) x.begin(), x.end()
#define iostreamBooster() do{ cin.tie(nullptr); ios_base::sync_with_stdio(false); }while(0)
using namespace std;
typedef int64_t i64;
typedef pair<int,int> pii;
template<class A, class B>inline bool chmax(A &a, const B &b){return b>a ? a=b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return b<a ? a=b,1 : 0;}
constexpr int INF = 0x3f3f3f3f;
template<class Itr> void dump(Itr begin, Itr end) { for (;begin != end; ++begin) clog << *begin << LF; }

int H, W;
int mat[1500][1500];


signed main()
{
  iostreamBooster();
  cin >> H >> W;
  for (int i = 1; i <= H; ++i) {
    for(int j = 1; j <= W; ++j) {
      cin >> mat[i][j];
      mat[i][j] = 1 - mat[i][j];
    }
  }

  int ans = 0;
  for (int i = 1; i <= H; i++) {
    for (int j = 1; j <= W; j++) {
      if (mat[i][j]) {
        mat[i][j] = 1 + min({mat[i][j-1], mat[i-1][j], mat[i-1][j-1]});
      }
      chmax(ans, mat[i][j]);
    }
  }

  cout << ans*ans << endl;

  return 0;
}




Measured memory_bytes: 11372
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <cassert>
#include <complex>
#include <queue>
#include <bitset>
using namespace std;
using ll = long long;
const int INF = 1<<30;
const int MOD = (int)1e9 + 7;
const int MAX_N = 25;
#define debug(x) cout << #x << ": " << x << endl
template<typename T>
ostream &operator<<(ostream &os, const vector<T> &v) { for(int i = 0; i < (int) v.size(); i++) os << v[i] << (i + 1 != v.size() ? " " : ""); return os; }

const double EPS = 1e-8;
const double PI = acos(-1);
inline bool equals(double a, double b) { return abs(b - a) < EPS; }

using Point = complex<double>;
struct Circle
{
    Point p; double r; int color;
    Circle() = default;
    Circle(Point p, double r, int color) : p(p), r(r), color(color) {}
};

bool check(Circle c1, Circle c2)
{
    if(c1.r < c2.r) swap(c1, c2);
    double d = abs(c1.p - c2.p);
    if(c1.r + c2.r < d or equals(c1.r + c2.r, d)) return false;
    return true;
}

vector<Circle> cir;
vector<int> pale, dp;

int dfs(int bit)
{
    if(dp[bit]) return dp[bit];
    int res = 0;
    for(int i = 0; i < cir.size(); i++)
    {
        if(bit & (1<<i)) continue;
        if((bit & pale[i]) != pale[i]) continue;
        for(int j = i + 1; j < cir.size(); j++)
        {
            if(bit & (1<<j)) continue;
            if(cir[i].color != cir[j].color or check(cir[i], cir[j])) continue;
            if((bit & pale[j]) != pale[j]) continue;
            int tmp = bit;
            tmp |= (1<<i);
            tmp |= (1<<j);
            res = max(res, dfs(tmp) + 2);
        }
    }
    //debug(bitset<8>(bit));
    return dp[bit] = res;
}
signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    while(cin >> N, N)
    {
        pale.resize(N, 0);
        dp.resize(1<<N, 0);
        for(int i = 0; i < N; i++)
        {
            int x, y, r, c; cin >> x >> y >> r >> c;
            Circle tmp = Circle(Point(x, y), r, c);
            for(int j = 0; j < cir.size(); j++)
            {
                if(check(tmp, cir[j])) pale[i] |= 1<<j;
            }
            cir.push_back(tmp);
        }
        cout << dfs(0) << endl;
        cir.clear();
        pale.clear();
        dp.clear();
    }
    return 0;
}




Measured memory_bytes: 68408
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define ll long long
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
ll int gcd (ll int a,ll int b) { return b ? gcd (b, a % b) : a; }

ll int mod = 1e9+7;

int main()
{
	ll int n,m;
	cin>>n>>m;
	int a[n][m];
	for (int i = 0; i < n; ++i)
	{
		for(int j=0;j<m;j++)
		{
			char x; cin>>x;
			if(x=='.')
				a[i][j]=1;
			else
				a[i][j]=-1;
		}
	}
	if(a[0][0]==-1)
		return 0;
	int dp[n][m];
	memset(dp,0,sizeof(dp));
	for (int i = 0; i < n; ++i)
	{
		if(a[i][0]!=-1)
			dp[i][0]=1;
		else
			break;
	}
	for (int i = 0; i < m; ++i)
	{
		if(a[0][i]!=-1)
			dp[0][i]=1;
		else
			break;
	}
	for(int i=1;i<n;i++)
	{
		for(int j=1;j<m;j++)
		{
			if(a[i][j-1]!=-1)
				dp[i][j]+=dp[i][j-1];
			if(a[i-1][j]!=-1)
				dp[i][j]+=dp[i-1][j];
			dp[i][j] = dp[i][j] % mod ;
		}
	}
	cout<<dp[n-1][m-1]<<"\n";
}

Measured memory_bytes: 11396
#include <bits/stdc++.h>
using namespace std;
int main(){
  int A,B,C,D,ab,cd;
  cin >> A >> B >> C >> D;
  ab = A+B;
  cd = C+D;
  if (ab > cd){
    cout << "Left" << endl;
  }else if (ab == cd){
    cout << "Balanced" << endl;
  }else if (ab < cd){
    cout << "Right" << endl;
  }
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void){
  int i;
  int c;
  char prime[60000];
  int n;

  prime[0] = 0;
  prime[1] = 0;
  prime[2] = 1;

  for(i=3;i<60000;i+=2)prime[i] = 1;
  for(i=4;i<60000;i+=2)prime[i] = 0;

  c = 3;
  while(c<250){
    for(i=c+2;i<60000;i+=2){
      if(i%c==0)prime[i] = 0;
    }
    while(!prime[++c]);
  }

  while(scanf("%d",&n)!=EOF){
    c=0;
    while(!prime[n+(--c)]);
    printf("%d ",n+c);
    c=0;
    while(!prime[n+(++c)]);
    printf("%d\n",n+c);
  }

  return 0;
}

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

int main() {
    int n;
    cin >> n;
    map<int, int> mp;
    rep(i,n) {
        int a;
        cin >> a;
        mp[a]++;
    }
    ll ans = 0;
    for(auto x : mp){
        if(x.first==x.second) continue;
        if(x.second > x.first) ans+=x.second-x.first;
        else ans += x.second;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 7960
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
using namespace std;
#define Ma_PI 3.141592653589793
#define eps 0.00000001
#define LONG_INF 3000000000000000000
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define MOD 998244353
#define REP(i,n) for(long long i = 0;i < n;++i)    
#define seg_size 524288
double dot(complex<double> a, complex<double> b) {
	return a.real() * b.real() + a.imag() * b.imag();
}
double gyaku_dot(complex<double> a, complex<double> b) {
	return a.real() * b.imag() - a.imag() * b.real();
}
double leng(complex<double> a) {
	return sqrt(a.real() * a.real() + a.imag() * a.imag());
}
double angles(complex<double> a, complex<double> b) {
	double cosine = dot(a, b) / (leng(a) * leng(b));
	double sine = gyaku_dot(a, b) / (leng(a) * leng(b));
	double kaku = acos(cosine);
	if (sine <= 0) {
		kaku = 2 * Ma_PI - kaku;
	}
	return kaku;
}
vector<int> convex_hull(vector<complex<double>> a) {
	vector<int> ans;
	double now_minnest = a[0].real();
	int now_itr = 0;
	REP(i, a.size()) {
		if (now_minnest > a[i].real()) {
			now_minnest = a[i].real();
			now_itr = i;
		}
	}
	ans.push_back(now_itr);
	complex<double> ba(0, 1);
	while (true) {
		int now_go = 0;
		double now_min = 0;
		int starter = ans[ans.size() - 1];
		for (int i = 0; i < a.size(); ++i) {
			if (i != starter) {
				double goa = angles(ba, a[i] - a[starter]);
				if (goa > now_min) {
					now_min = goa;
					now_go = i;
				}
			}
		}
		if (now_go == ans[0]) break;
		ans.push_back(now_go);
		ba = complex<double>(a[now_go] - a[starter]);
	}
	return ans;
}
long long gcd(long long a, long long b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
int main() {
	string s;
	cin >> s;
	int geko = 0;
	REP(i, s.length()) {
		if (s[i] == 'A') {
			geko = i;
			break;
		}
	}
	for (int i = s.length() - 1; i >= 0; --i) {
		if (s[i] == 'Z') {
			cout << i - geko + 1 << endl;
			return 0;
		}
	}
}


Measured memory_bytes: 832
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bits/stdc++.h>
#include<cmath>
#include<bitset>
#include<cstdio>
using namespace std;

int main(){
  long long int W,H,x,y;
  cin>>W>>H>>x>>y;
  
  int a=0;
  if(x*2==W && y*2==H) a=1;
  
  long double ans=1;
  cout<<fixed<<setprecision(9)<<ans*W*H/2;
  cout<<" "<<a<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
ll dp[100005][3];
int main()
{
    ll n,i,j,k;
    cin>>n;
    ll a[n],b[n],c[n];
    for(i=0;i<n;i++)
    {
        cin>>a[i]>>b[i]>>c[i];
    }
    dp[0][0]=a[0];
    dp[0][1]=b[0];
    dp[0][2]=c[0];
    for(i=1;i<n;i++)
    {
        dp[i][0]=a[i]+max(dp[i-1][1],dp[i-1][2]);
        dp[i][1]=b[i]+max(dp[i-1][0],dp[i-1][2]);
        dp[i][2]=c[i]+max(dp[i-1][0],dp[i-1][1]);
    }
    cout<<max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]));
    return 0;
}

Measured memory_bytes: 4864
from collections import deque
h, w = map(int, input().split())
s = []
ans = 0
si, sj = 0, 0

for i in range(h):
    s.append(input())

for x in range(h):
    for y in range(w):
        # print('x, y:', x, y)
        if s[x][y] == '#':
            continue
        q = deque()
        q.append((0, (x, y)))
        done = set()
        done.add(str(x) + ':' + str(y))
        temp = 0

        while q:
            dis, tup = q.popleft()
            i, j = tup[0], tup[1]
            temp = max(temp, dis)

            # Right
            if j < w - 1 and s[i][j + 1] == '.':
                if str(i) + ':' + str(j + 1) not in done:
                    done.add(str(i) + ':' + str(j + 1))
                    q.append((dis + 1, (i, j + 1)))

            # Left
            if j > 0 and s[i][j - 1] == '.':
                if str(i) + ':' + str(j - 1) not in done:
                    done.add(str(i) + ':' + str(j - 1))
                    q.append((dis + 1, (i, j - 1)))

            # Up
            if i > 0 and s[i - 1][j] == '.':
                if str(i - 1) + ':' + str(j) not in done:
                    done.add(str(i - 1) + ':' + str(j))
                    q.append((dis + 1, (i - 1, j)))

            # Down
            if i < h - 1 and s[i + 1][j] == '.':
                if str(i + 1) + ':' + str(j) not in done:
                    done.add(str(i + 1) + ':' + str(j))
                    q.append((dis + 1, (i + 1, j)))

        if temp > ans:
            # print('\nUpdate:', x, y)
            # print('temp, ans:', temp, ans)
            ans = temp
            si, sj = x, y

        # ans = max(ans, temp)

print(ans)

Measured memory_bytes: 98796
#include <bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c,d,e;
  cin >> a >> b >> c >> d >> e;
  int sub[5]={};
  sub[0]=a/10*10+(a%10>0)*10-a;
  a=a/10*10+(a%10>0)*10;
  sub[1]=b/10*10+(b%10>0)*10-b;
  b=b/10*10+(b%10>0)*10;
  sub[2]=c/10*10+(c%10>0)*10-c;
  c=c/10*10+(c%10>0)*10;
  sub[3]=d/10*10+(d%10>0)*10-d;
  d=d/10*10+(d%10>0)*10;
  sub[4]=e/10*10+(e%10>0)*10-e;
  e=e/10*10+(e%10>0)*10;
  sort(sub,sub+5);
  cout << a+b+c+d+e-sub[4] << endl;
  return 0;
}


Measured memory_bytes: 256
import math

N = int(input())

d = {}

def primeFactor(n):
    for i in range(2, int(math.sqrt(n)) + 1):
        while n % i == 0:
            d[i] += 1
            n = n // i
    if n != 1:
        if n in d.keys():
            d[n] += 1
        else:
            d[n] = 1
    #return d

ans = 1
mod = 10**9 + 7

for i in range(1, N + 1):
    primeFactor(i)

for v in d.values():
    ans *= (v + 1) 
    ans %= mod

print(ans)


Measured memory_bytes: 3064
def main():
    n = int(input())
    h = list(map(int, input().split()))

    res = [0]*n
    k = 0
    for i in range(1,n):
        if h[i-1] >= h[i]:
            res[k] += 1
        else:
            k += 1
    print(max(res))

if __name__ == '__main__':
    main()


Measured memory_bytes: 63984
#include<set>
#include<map>
#include<cmath>
#include<queue>
#include<bitset>
#include<string>
#include<cstdio>
#include<cctype>
#include<cassert>
#include<cstdlib>
#include<cstring>
#include<sstream>
#include<iostream>
#include<algorithm>

#define For(i,x,y) for (int i=x;i<y;i++)
#define pb push_back
#define mp make_pair
#define fi first
#define se second

#define dprintf(...) fprintf(stderr,__VA_ARGS__)
using namespace std;

int IN(){
	int c,f,x;
	while (!isdigit(c=getchar())&&c!='-');c=='-'?(f=1,x=0):(f=0,x=c-'0');
	while (isdigit(c=getchar())) x=(x<<1)+(x<<3)+c-'0';return !f?x:-x;
}

typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> Vi;

const int N=1e5+19;

struct Point{
	int x,y,id;
	bool operator < (const Point &B) const {return x<B.x||x==B.x&&y<B.y;}
} A[N],B[N];
int S[N],fa[N];
int m,n,a,b,d,x,y;
ll res;

int getf(int x){
	return fa[x]==x?x:fa[x]=getf(fa[x]);
}
void Union(int x,int y){
	x=getf(x),y=getf(y);
	if (x!=y) fa[x]=y;
}
void Build(){
	memset(S,0,sizeof(S));
	sort(A+1,A+n+1);
	For(i,1,n+1){
		int l,r;
		l=lower_bound(A+1,A+n+1,(Point){A[i].x-d,A[i].y-d})-A;
		r=upper_bound(A+1,A+n+1,(Point){A[i].x-d,A[i].y+d})-A-1;
		if (l<=r){
			Union(A[i].id,A[l].id);
			S[l]++;S[r]--;
		}
	}
	For(i,1,n+1){
		S[i]+=S[i-1];
		if (S[i]) Union(A[i].id,A[i+1].id);
	}
}
void Calc(int f){
	sort(B+1,B+m+1);
	For(i,1,m+1){
		int l,r;
		l=lower_bound(B+1,B+m+1,(Point){B[i].x-d,B[i].y-(d-f)})-B;
		r=upper_bound(B+1,B+m+1,(Point){B[i].x-d,B[i].y+(d-f)})-B-1;
		res+=max(r-l+1,0);
	}
}

int main(){
	n=IN(),a=IN(),b=IN();
	For(i,1,n+1){
		fa[i]=i;
		x=IN(),y=IN();
		A[i]=(Point){x+y,x-y,i};
	}
	d=max(abs(A[a].x-A[b].x),abs(A[a].y-A[b].y));
	Build();
	For(i,1,n+1) swap(A[i].x,A[i].y);
	Build();
	For(i,1,n+1){
		if (getf(A[i].id)==getf(a)) B[++m]=A[i];
	}
	Calc(0);
	For(i,1,m+1) swap(B[i].x,B[i].y);
	Calc(1);
	cout<<res<<endl;
}

Measured memory_bytes: 4096
#include <stdio.h>
#include <string.h>
int A[20000001];
char b[20],c[20];
int C(char x) {
  if(x=='A') return 1;
  if(x=='C') return 2;
  if(x=='G') return 3;
  return 4;
}
int search(int k, int x, int y, int t) {
  if(k==strlen(c)) {
    if(!t) A[x]=1;
    return A[x];
  }
  return search(k+1,x+C(c[k])*y,y*4,t);
}

int main() {
  int n;
  scanf("%d",&n);
  while(n--) {
    scanf("%s %s",b,c);
    if(b[0]=='i') search(0,0,1,0);
    else {
      if(search(0,0,1,1)) printf("yes\n");
      else printf("no\n");
    }
  }
  return 0;
}



Measured memory_bytes: 7108
N=int(input())
D={}

for x in range(1,101):
    for y in range(1,101):
        for z in range(1,101):
            A=x*x+y*y+z*z+x*y+y*z+z*x
            if A not in D:
                D[A]=1
            else:
                D[A]+=1
for i in range(1,N+1):
    if i not in D:
        print(0)
    else:
        print(D[i])

Measured memory_bytes: 72372
# include <bits/stdc++.h>
using namespace std;
# define FOR(i, a, b) for (int i = a; i <= b; ++i)
# define FDR(i, a, b) for (int i = a; i >= b; --i)
# define push_back pb
# define make_pair mp
# define lch p<<1, l, mid
# define rch p<<1|1, mid + 1, r
# define mem(a, b) memset(a, b, sizeof(a))
# define first fi
# define second se
# define MOD 1000000007
# define INF 1000000000
typedef long long i64;
typedef vector<int> VI;
typedef pair<int, int> PII;
const int N = 200005;

int a[N], sum[N];
struct Node{int x, cnt;}node[N];
int pos;

int main ()
{
    int n;
    scanf("%d", &n);
    FOR(i, 1, n) scanf("%d", a + i);
    node[++pos] = Node{a[1], 1};
    sum[pos] = 1;
    FOR(i, 2, n) {
        if (a[i] == a[i - 1] && a[i] == 0) ++node[pos].cnt, ++sum[pos];
        else {
            node[++pos] = Node{a[i], 1};
            sum[pos] = sum[pos - 1] + 1;
        }
    }
    i64 ans = 0;
    FOR(i, 1, pos) {
        int r = i - 1, now = 0;
        while (r < pos && (now & node[r + 1].x) == 0) {
            now |= node[r + 1].x;
            ++r;
        }
        int x = node[i].cnt, y = sum[r] - sum[i - 1];
        ans += (i64)(2 * y - x + 1) * x / 2;
    }
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 3328
// In god we trust
 
#include <bits/stdc++.h>
#include <chrono>
#include <algorithm>
#include <signal.h>
#include <thread>
#include <pthread.h>
#include <omp.h>
 
#define pb push_back
#define fi first
#define se second
#define Vi vector<int>
#define Vb vector<bool>
#define Pi pair<int, int>
#define MP make_pair
#define MT make_tuple
#define Q queue
#define Qi Q<int>
#define INF 1000000000 
#define LINF 1000000000000000000
#define int long long
#define _USE_MATH_DEFINES
using namespace std;
using namespace std::chrono;

unordered_map<int, int> factor(int n){
  int cnt = 0;
  unordered_map<int, int> m;
  int nn = n;
  while (!(nn & 1))
    cnt++, nn /= 2;
  if(cnt)
    m[2] = cnt;
  for (int i = 3; i <= sqrt(n); i++){
    cnt = 0;
    while(nn % i == 0)
      nn /= i, cnt++;
    if (cnt)
      m[i] = cnt;
  }
  if (nn > 2)
    m[nn] = 1;
  
  return m;
}
const int MAXN = 1000100;
int spf[MAXN];

set<int> sieve_factor(int n){
  set<int> s;
  while(n != 1)
    s.insert(spf[n]), n /= spf[n];
  return s;
}

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

  int n;
  cin >> n;
  int a[n];

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

  for (int i = 2; i < MAXN; i++)
    spf[i] = i;

  for (int i = 2; i < MAXN; i++)
    if (spf[i] == i)
      for (int j = i * i; j < MAXN; j += i)
	if (spf[j] == j)
	  spf[j] = i;
  
  int gcd = __gcd(a[0], a[1]);

  for (int i = 2; i < n; i++)
    gcd = __gcd(gcd, a[i]);

  if (gcd == 1){
    set<int> factors;
    bool could = true;
    for (int i = 0; i < n; i++)
      for (auto item: sieve_factor(a[i]))
	if (factors.find(item) != factors.end()){
	  could = false;
	  break;
	}else
	  factors.insert(item);
    if (could)
      cout << "pairwise coprime" << endl;
    else
      cout << "setwise coprime" << endl;
  }else{
    cout << "not coprime" << endl;
  }
  
}


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

int main() {
  long long int x, y, a, b, c;
  cin >> x >> y>>a>>b>>c;
  priority_queue<long long int> aa;
  priority_queue<long long int> bb;
  priority_queue<long long int> cc;
  long long int sum=0;
  for (int i = 0; i<a;i++) {
    int s;
    cin >> s;
    aa.push(s);
  }
  for (int i = 0; i<b;i++) {
    int s;
    cin >> s;
    bb.push(s);
  }
  priority_queue<long long int> abc;
  for (int i = 0; i < x; i++) {
    abc.push(aa.top());
    aa.pop();
  }
  for (int i = 0; i < y; i++) {
    abc.push(bb.top());
    bb.pop();
  }
  for (int i = 0; i<c;i++) {
    int s;
    cin >> s;
    abc.push(s);
  }
  for (int i = 0; i < x+y; i++) {
    sum += abc.top();
    abc.pop();
  }
  printf("%lld\n", sum);
}

Measured memory_bytes: 7920
h, w = list(map(int, input().split()))
s = [input() for _ in range(h)]

adj = [(1, 0), (0, 1), (-1, 0), (0, -1)]
non_adj = 0
for y in range(h):
    for x in range(w):
        if s[y][x] == '.':
            continue
        n_adj = 0
        for dx, dy in adj:
            i, j = y+dy, x+dx
            if i < 0 or i >= h or j < 0 or j >= w:
                continue
            if s[i][j] == '#':
                n_adj += 1
        if n_adj == 0:
            non_adj += 1
# print(non_adj)
if non_adj == 0:
    print('Yes')
else:
    print('No')

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


int main(){
	int x, y;
	cin >> x >> y;
	bool ans = false;
	rep(i,x+1){
		if(i*2+(x-i)*4==y) ans = true;
	}
	if(ans) cout << "Yes" << endl;
	else    cout << "No"  << endl;
}








Measured memory_bytes: 3612
//#include<bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <algorithm>
#include <utility>
#include <climits>
#define REP(i, n) for(int i = 0; i < n; ++i)
#define FOR(i, a, b) for(int i = a; i < b; ++i)
#define F first
#define S second
#define OUT(x) cout << x << "\n"
using namespace std;
using point = pair< int,int >;
using ll = long long;

int main() {
    int t, n;

    while (~scanf("%d", &t)) {
        if (t == 0) break;
        scanf("%d", &n);
        int cnt = 0;
        int s, f;

        REP (i, n) {
            scanf("%d%d", &s, &f);
            cnt += f - s;
        }

        if (cnt >= t) OUT("OK");
        else OUT(t - cnt);
    }

    return 0;
}




Measured memory_bytes: 3152
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    char a[200];
    scanf("%d%s",&n,a);
    int len=strlen(a);
    if(strlen(a)%2)
        printf("No");
    else
    {
        int flag=0;
        for(int i=0;i<=len/2-1;i++)
            if(a[i]!=a[i+len/2])
            {
                flag=1;
                break;
            }
            if(flag)
                printf("No");
            else
                printf("Yes");
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define EM 100000000
using namespace std;
using LL = long long;
using P = pair<LL, LL>;
LL LINF = 1e18;
int INF = 1e9;
using vint = vector<int>;
using vLL = vector<LL>;

vector<vector<int>> G(200010);
vector<int> c(200010, 0), used(200010, 0);
void dfs(int s, int cnt){
    if(used[s]) return;
    used[s] = 1;
    c[s] += cnt;
    for(auto v : G[s]){
        dfs(v, c[s]);
    }
}
int main(){
    int N, Q;
    cin >> N >> Q;
    for(int i = 0; i < N-1;i++){
        int a, b;
        cin >> a >> b;
        G[a-1].push_back(b-1);
        G[b-1].push_back(a-1);
    }
    for(int i = 0;i < Q;i++){
        int p, x;
        cin >> p >> x;
        c[p-1] += x;
    }
    dfs(0, 0);
    for(int i = 0;i < N;i++)    cout << c[i] << endl;
}

Measured memory_bytes: 21120
#include <algorithm>
#include <bits/stdc++.h>
#include <cstdlib>  
#include <cmath>
using namespace std;

int main(){
    int n;
    cin >> n;
    vector<int>a(n+10);
    vector<int>b(n+10);
    vector<int>c(n+10);
    for(int i = 0; i < n; i++){
      cin >> a.at(i);
    }
    for(int i = 0; i < n; i++){
      cin >> b.at(i);
    }
    for(int i = 0; i < n-1; i++){
      cin >> c.at(i);
    }
  
  
    int ans = 0;
    for(int i = 0; i<n; i++){
      ans += b.at(a.at(i) - 1);
      if( a.at(i+1) == a.at(i)+1 ){
        ans += c.at(a.at(i) -1);
      }
    }
    cout << ans << endl;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
typedef pair<int,int> P;
typedef pair<P,int> P2;

int main() {
  int n,m;
  while(cin >> n >> m && n) {
    vector<P2> a;
    a.push_back(P2(P(0,0),-1));
    a.push_back(P2(P(n,n),-1));
    while(m--) {
      char c;
      int x,y;
      cin >> c;
      if(c=='s') {
        cin >> x >> y;
        int z=-1;
        for(int i=0; i<a.size()-1; i++) {
          if(a[i+1].F.F-a[i].F.S>=y) {
            z=a[i].F.S;
            a.push_back(P2(P(z,z+y),x));
            sort(a.begin(),a.end());
            break;
          }
        }
        if(z!=-1) cout << z << endl;
        else cout << "impossible" << endl;
      } else {
        cin >> x;
        for(int i=0; i<a.size(); i++) {
          if(a[i].S==x) a.erase(a.begin()+i);
        }
      }
    }
    cout << "END" << endl;
  }
  return 0;
}


Measured memory_bytes: 1200
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		//		new Main().solveA();
		new Main().solveB();
		// new Main().solveC();
		// new Main().solveD();
	}

	private void solveA() {
		Scanner scanner = null;
		int numA = 0;
		int numB = 0;

		try {
			scanner = new Scanner(System.in);
			numA = scanner.nextInt();
			numB = scanner.nextInt();

			System.out.println((numA - 1) * (numB - 1));

			System.out.println("");

		} finally {
			if (scanner != null) {
				scanner.close();
			}
		}
	}

	private void solveB() {
		Scanner scanner = null;
		int numN = 0;

		try {
			scanner = new Scanner(System.in);
			numN = scanner.nextInt();

			int count = 0;
			for (int i = 1; i <= numN; i++) {
				if (i % 2 == 0) {
					continue;
				}
				int wk = i;
				Map<Integer, Integer> wkMap = new HashMap<Integer, Integer>();
				for (int j = 2; j < i;) {
					if (wk % j == 0) {
						wk /= j;
						wkMap.put(j, wkMap.get(j) == null ? 1 : wkMap.get(j) + 1);
					} else {
						j++;
					}
				}
				int wkRes = 1;
				for (Integer val1 : wkMap.values()) {
					wkRes *= (val1 + 1);
				}
				if (wkRes == 8) {
					count++;
				}
			}

			System.out.println(count);

		} finally {
			if (scanner != null) {
				scanner.close();
			}
		}
	}

	private void solveC() {
		Scanner scanner = null;
		int numN = 0;
		int numK = 0;
		int numS = 0;

		try {
			scanner = new Scanner(System.in);
			numN = scanner.nextInt();

			System.out.println("");

		} finally {
			if (scanner != null) {
				scanner.close();
			}
		}
	}

	private void solveD() {
		Scanner scanner = null;
		int numN = 0;
		int numK = 0;
		int numS = 0;

		try {
			scanner = new Scanner(System.in);
			numN = scanner.nextInt();

			System.out.println("");

		} finally {
			if (scanner != null) {
				scanner.close();
			}
		}
	}
}

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

using namespace std;

int main() {
  int N;
  cin >> N;
  vector<int> a(N);
  for_each(begin(a), end(a), [](auto &e) {
    cin >> e;
  });

  int two = 0, four = 0;
  for (int i = 0; i < N; i++) {
    if (a[i] % 4 == 0) {
      four++;
      two++;
    } else if (a[i] % 2 == 0) {
      two++;
    }
  }

  const int dame = N - two;
  if (dame > four) {
    if (dame - four == 1 && four == two) {
      cout << "Yes" << endl;
    } else {
      cout << "No" << endl;
    }
    return 0;
  }

  cout << "Yes" << endl;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define vi vector<int>
#define vll vector<ll>
#define vvi vector < vi >
#define pii pair<int,int>
#define pll pair<long long, long long>
#define vpll vector < pair<long long,long long> >
#define fill(a,val)  memset(a,val, sizeof (a))
#define sort_unique(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define all(cont) cont.begin(), cont.end()
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define MAX   1e9
#define MIN  -1e9
typedef map<int,int> mpi;
typedef set<int> seti;
typedef multiset<int> mseti;
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define rep(i, n)    for(long long int i = 0; i < (n); ++i)
#define repA(i, a, n)  for(int i = a; i <= (n); ++i)
#define repD(i, a, n)  for(int i = a; i >= (n); --i)
#define trav(a, x) for(auto& a : x)
struct Interval {int start, end;};
bool compare(pll i1, pll i2) {return (i1.s < i2.s);}
int main()
{
    ll n,k;
    cin>>n>>k;
    long double sum=0;
    repA(i,1,n)
    {
        ll t=i;
        ll power=0;
        while(t<k)
        {
           power++;
           t=2*t;
        }
        sum+=(1.0/n)*(1.0/((pow(2,power))));
    }
    cout<<fixed<<setprecision(15)<<sum;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <cmath>
#include <utility>

using namespace std;


int main(void){
    int n,d;
    cin >> n >> d;
    int x[n][d];
    for(int i = 0; i < n; i++)
        for(int j = 0; j < d; j++)
            cin >> x[i][j];

    int count = 0;
    for(int i = 0; i < n; i++){
        
        for(int j = i+1; j < n; j++){
            double dist = 0;
            for(int k = 0; k < d; k++){
                dist += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
            }
            dist = sqrt(dist);
            //cout << i << " " <<j<<" " <<dist <<endl;
            if(dist - (int)(dist) == 0)
                count++;
        }
    }
    cout << count << endl;
    
    return 0;

}

Measured memory_bytes: 256
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

template <typename T>
void print(T x) {
    cout << x << endl;
}

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REVFOR(i, m, n) for (int i = (n - 1); i >= (m); --i)
#define REP(i, n) FOR(i, 0, n)
#define REVREP(i, n) REVFOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    
    int N;
    cin >> N;

    vi p(N);
    REP(i, N) cin >> p[i];

    vi q = p;
    sort(ALL(q));

    REP(i, N) REP(j, N) {
        vi r = p;
        swap(r[i], r[j]);
        bool f = true;
        REP(k, N) f &= q[k] == r[k];

        if (f) {
            print("YES");
            return 0;
        }
    }

    print("NO");
    
}


Measured memory_bytes: 3612
from operator import itemgetter


n, k = map(int,input().split())
info = [list(map(int, input().split())) for i in range(n)]

info = sorted(info, key = itemgetter(1), reverse = True)

selected = info[0:k]
selected_only = []
selected_chohuku = []
unselected_only = []
memo = {}
for t, d in selected:
    if t not in memo:
        memo[t] = 1
        selected_only.append(d)
    else:
        selected_chohuku.append(d)

cnt_type = len(memo)
for t, d in info[k:]:
    if t not in memo:
        memo[t] = 1
        unselected_only.append(d)


sum_select = sum(selected_chohuku) + sum(selected_only) 
ans = cnt_type*cnt_type + sum_select

unselected_only = unselected_only[::-1]
for i in range(min(len(selected_chohuku), len(unselected_only))):
    cnt_type += 1
    sum_select += unselected_only[-1]
    sum_select -= selected_chohuku[-1]
    del unselected_only[-1]
    del selected_chohuku[-1]
    tmp = cnt_type*cnt_type + sum_select
    ans = max(ans, tmp)
print(ans)

  

Measured memory_bytes: 78808
#include <iostream>
#include <vector>
#include <sstream>

using namespace std;

int main(){
  int N,M;
  cin >> N >> M;
  vector <int> l(M+1, 0);
  string in;  
  getline(cin, in);
  for( int i=0;i<N;i++ )
    {
      int K;
      int A;
      cin >> K;
      for( int j=0;j<K;j++ )
	{
	  cin >> A;
	  l[A]++;
	}
    }
  int out = 0;
  for( int i=1;i<M+1;i++ )
    {
      if(l[i] == N)
	out++;
    }
  cout << out << endl;
}


Measured memory_bytes: 256
import kotlin.math.max

fun main() {
    val (n, m, k) = readLine()!!.split(' ').map { it.toInt() }
    val a = readLine()!!.split(' ').map { it.toInt() }
    val b = readLine()!!.split(' ').map { it.toInt() }

    val sa = LongArray(n + 1)
    for (i in 0 until n) {
        sa[i + 1] = sa[i] + a[i]
    }
    val sb = LongArray(m + 1)
    for (i in 0 until m) {
        sb[i + 1] = sb[i] + b[i]
    }

    var ans = 0
    var j = m
    for (i in 0..n) {
        if (sa[i] > k) break
        while (sb[j] > k - sa[i]) {
            j--
        }
        ans = max(ans, i + j)
    }

    println(ans)
}

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

using namespace std;

#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define REV(i,n) for(ll (i) = (n) - 1;(i) >= 0;--i)
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {REP(WW,n)cerr << v[WW] << ' ';cerr << endl << endl;}
#define SHOW2d(v,WW,HH) {REP(W_,WW){REP(H_,HH)cerr << v[W_][H_] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 1000000007
#define fastcin() cin.tie(0);ios::sync_with_stdio(false)

typedef long long ll;
typedef pair<double,ll> P;


int main(){
	
	int n;cin >> n;
	cout << (n / 2) * ((n + 1) / 2) << endl;
	
	return 0;
}


Measured memory_bytes: 256
object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val s = sc.next()
  if (s == "RRR") {
    println(3)
  } else if (s.count(_ == 'R') == 2 && s(1) == 'R') {
    println(2)
  } else if (s.contains('R')) {
    println(1)
  } else {
    println(0)
  }
}


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

int main() {
  string s;
  cin >> s;
  char s1, s2, s3;
  s1 = s[0];
  s2 = s[1];
  s3 = s[2];
  if (s1==s2 && s2 == s3) cout << "No" << endl;
  else cout << "Yes" << endl;
  return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {
    static PrintWriter out;

    public static void main(String[] args) throws IOException {
        out = new PrintWriter(new OutputStreamWriter(System.out));
        CF_Reader in = new CF_Reader();

        long X = in.longNext();

        double A = 100;
        int years = 0;
        while (A < X) {
            A = (long) A * 1.01;
            years += 1;
        }
        out.println(years);

        out.close();
    }

    static class CF_Reader {
        BufferedReader br;
        StringTokenizer st;

        public CF_Reader() throws IOException {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() throws IOException {
            while (st == null || !st.hasMoreTokens())
                st = new StringTokenizer(br.readLine().trim());
            return st.nextToken();
        }

        long longNext() throws IOException {
            return Long.parseLong(next());
        }

        int intNext() throws IOException {
            return Integer.parseInt(next());
        }

        double doubleNext() throws IOException {
            return Double.parseDouble(next());
        }

        char charNext() throws IOException {
            return next().charAt(0);
        }

        public int[] nextIntArray(final int n) throws IOException {
            final int[] a = new int[n];
            for (int i = 0; i < n; i++)
                a[i] = intNext();
            return a;
        }

        public long[] nextLongArray(final int n) throws IOException {
            final long[] a = new long[n];
            for (int i = 0; i < n; i++)
                a[i] = longNext();
            return a;
        }

        String line() throws IOException {
            return br.readLine().trim();
        }
    }
}


Measured memory_bytes: 25424
#include<cstdio>
#include<iostream>
#include<vector>
#include<queue>
typedef long long ll;
const ll MAXN=1e5+10;
using namespace std;
//全局变量 
int ans[4]={0},vis[MAXN]; 
vector<int> ver[MAXN];

//函数
void bfs(int x,int y){
	vis[x]=1;//第一个点1访问 
	vis[y]=2;//最后一个点2访问
	queue<int> q;//队列
	q.push(x);
	q.push(y);
	while(!q.empty()){//当队列不空时进行广度优先搜索 
		int pos=q.front();//下一个要访问的点 
		q.pop();
		ans[vis[pos]]++;//为什么在这里加？ 
		for(int i=0;i<ver[pos].size();i++){
			if(vis[ver[pos][i]])	
				continue;
			vis[ver[pos][i]]=vis[pos];
			q.push(ver[pos][i]);
		} 
	} 
}
//主函数 
int main(){
	int n,x,y;
	scanf("%d",&n);
	for(int i=1;i<=n-1;i++){
		scanf("%d %d",&x,&y);
		ver[x].push_back(y);//邻接表 
		ver[y].push_back(x);
	}
	bfs(1,n);//广度优先搜索 
	if(ans[1]>ans[2]){
		printf("Fennec");
	}
	else {
		printf("Snuke");
	}
	return 0;
}

Measured memory_bytes: 6272