akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

int n,m;
vvi g,rg;
vd a,b;

int main(){
	cin>>n>>m;
	g=rg=vvi(n);
	a=b=vd(n);
	for(int i=0;i<m;i++){
		int u,v;
		cin>>u>>v;
		u--;v--;
		g[u].push_back(v);
		rg[v].push_back(u);
	}
	a[0]=1;
	fill(b.begin(),b.end()-1,1);
	for(int i=1;i<n;i++) for(auto v:rg[i]) a[i]+=a[v]/(double)g[v].size();
	for(int i=n-2;i>=0;i--) for(auto v:g[i]) b[i]+=b[v]/(double)g[i].size();
	double res=b[0];
	for(int i=0;i<n-1;i++) if(g[i].size()>1){
		double sum=0;
		int S=g[i].size();
		vd c;
		for(auto v:g[i]) c.push_back(b[v]);
		sort(c.begin(),c.end());
		for(int j=0;j<S-1;j++) sum+=c[j];
		double sa=(sum+c[S-1])/S-sum/(S-1);
		res=min(res,b[0]-sa*a[i]);
	}
	cout<<syosu(9)<<res<<endl;
}

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

toUP = [[0] * w for _ in range(h)]
for i in range(w):
  cnt = 0
  for j in range(h):
    if S[j][i] == ".":
      cnt += 1
      toUP[j][i] = cnt
    else:
      cnt = 0

toDOWN = [[0] * w for _ in range(h)]
for i in range(w):
  cnt = 0
  for j in range(h - 1, -1, -1):
    if S[j][i] == ".":
      cnt += 1
      toDOWN[j][i] = cnt
    else:
      cnt = 0

toLEFT = [[0] * w for _ in range(h)]
for i in range(h):
  cnt = 0
  for j in range(w):
    if S[i][j] == ".":
      cnt += 1
      toLEFT[i][j] = cnt
    else:
      cnt = 0
    
toRIGHT = [[0] * w for _ in range(h)]
for i in range(h):
  cnt = 0
  for j in range(w - 1, -1, -1):
    if S[i][j] == ".":
      cnt += 1
      toRIGHT[i][j] = cnt
    else:
      cnt = 0

ans = 0
for i in range(h):
  for j in range(w):
    if S[i][j] == ".":
      ans = max(ans, toUP[i][j] + toDOWN[i][j] + toLEFT[i][j] + toRIGHT[i][j] - 3)
print(ans)


Measured memory_bytes: 359392
#include <bits/stdc++.h>
#define DEBUG if(0)
#define lli long long int
#define ldouble long double
using namespace std;

const int maxA = 100 + 1;
struct Pos { int i, j; };
Pos pos[maxA];
bool marked[3][3];

bool won()
{
  for (int i = 0; i < 3; i ++)
  {
    int s1 = 0, s2 = 0;
    for (int j = 0; j < 3; j ++)
      s1 += marked[i][j], s2 += marked[j][i];
    if (s1 == 3 || s2 == 3) return true;
  }
  int s1 = 0, s2 = 0;
  for (int i = 0; i < 3; i ++)
    s1 += marked[i][i], s2 += marked[i][2 - i];
  return s1 == 3 || s2 == 3;
}

int main()
{
  memset(pos, -1, sizeof(pos));
  for (int i = 0; i < 3; i ++)
    for (int j = 0; j < 3; j ++)
    {
      int a; scanf("%d", &a);
      pos[a] = {i, j};
    }

  int n; scanf("%d", &n);
  while (n --)
  {
    int b; scanf("%d", &b);
    if (pos[b].i != -1)
      marked[pos[b].i][pos[b].j] = true;
  }
  printf("%s\n", won() ? "Yes" : "No");

  return 0;
}

Measured memory_bytes: 256
/**
 * Author: Behradm
 * Created: 14-04-2020 11:57:32
**/
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef vector<int> vi;

#define F first
#define S second
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define LOCAL

#ifdef LOCAL
	#define debugi(x) cerr << "{" << #x << "}: " << (x) << '\n'
	#define debug(v, begin, end) cerr << "{ | "; for(auto i = begin; i < end; i++){cerr << #v << "[" << i << "]: " << v[i] << " | ";} cerr << " }\n"
	#define debugp(a, b) cerr << "\n{ " << a << " " << b << " }\n"
#else
	#define debugi(x) 42
	#define debug(v, begin, end) 42
	#define debugp(a, b) 42 
#endif

int32_t main()
{
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cout.precision(6);
	cout << fixed;
	string s;
	cin >> s;
	for(int i = 0; i < sz(s); i++){
		if(s[i] == '7'){
			cout << "Yes\n";
			return 0;
		}
	}

	cout << "No\n";
	return 0;
}



Measured memory_bytes: 3644
n, m = map(int, input().split())
result = 1
for i in range(int(m**0.5), 0, -1):
    if m % i == 0:
        j = m // i
        if i >= n:
            result = max(result, j)
        elif j >= n:
            result = max(result, i)
print(result)


Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <cstdio>
using namespace std;

struct Rec{
	int area;
	int circumference;
};

Rec rectangle(int a, int b){
	int area = a * b;
	int circumference = 2 * (a + b);
	Rec foo = {area, circumference};
	return foo;
}

int main(){
	int width, height;
	int area, circumference;
	cin >> width >> height;
	Rec ans = rectangle(width, height);
	cout << ans.area << ' ' << ans.circumference << endl;
	return 0;
}



Measured memory_bytes: 3080
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <iomanip>
using ll = long long;
using uint = unsigned int;
using graph = std::vector<std::vector<ll>>;
using wGraph = std::vector<std::vector<std::pair<ll,ll>>>;
#define rep(i,n) for (int i=0; i < int(n); i++)

using namespace std;
ll MOD7 = 1000000007;
ll MOD9 = 1000000009;
vector<ll> InputVec(ll N){
    vector<ll> A(N);
    for (int i = 0; i < N; ++i) {
        cin >> A[i];
    }
    return A;
}
void OutputVec(vector<ll> A){
    for (int i = 0; i < A.size(); ++i) {
        cout << A[i] << ",";
    }
    cout << endl;
}
vector<vector<ll>> InputVec2d(ll H,ll W){
    vector<vector<ll>> A(H);
    for (int yi = 0; yi < H; ++yi) {
        A[yi] = vector<ll>(W);
    }
    for (int yi = 0; yi < H; ++yi) {
        for (int xi = 0; xi < W; ++xi) {
            cin >> A[yi][xi];
        }
    }
    return A;
}
vector<vector<char>> InputVec2dStr(ll H,ll W){
    vector<vector<char>> A(H);
    for (int yi = 0; yi < H; ++yi) {
        A[yi] = vector<char>(W);
    }
    for (int yi = 0; yi < H; ++yi) {
        string S;
        cin >> S;
        for (int xi = 0; xi < W; ++xi) {
            A[yi][xi] = S[xi];
        }
    }
    return A;
}
void OutputVec2d(vector<vector<ll>> A){
    for (int yi = 0; yi < A.size(); ++yi) {
        for (int xi = 0; xi < A[yi].size(); ++xi) {
            cout << A[yi][xi] << ",";
        }
        cout << endl;
    }
}
graph InputGraph(ll N,ll M){
    graph G(N);
    for (int i = 0; i < M; ++i) {
        ll a,b;
        cin >> a >> b;
        a--;b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    return G;
}
graph InputDGraph(ll N,ll M){
    graph G(N);
    for (int i = 0; i < M; ++i) {
        ll a,b;
        cin >> a >> b;
        a--;b--;
        G[a].push_back(b);
    }
    return G;
}
void OutputGraph(graph G){
    for (int i = 0; i < G.size(); ++i) {
        cout << i << ":";
        for (int j = 0; j < G[i].size(); ++j) {
            cout << G[i][j]<< ",";
        }
        cout << endl;
    }
}
void OutputAnswerBool(bool b,bool isUpperCase = false){
    if(b){
        if(isUpperCase){
            cout << "YES" << endl;
        }else{
            cout << "Yes" << endl;
        }
    }else{
        if(isUpperCase){
            cout << "NO" << endl;
        }else{
            cout << "No" << endl;
        }
    }
}
int main() {
    ll N;
    cin >> N;
    vector<ll> A(N-1);
    for (int i = 0; i < N-1; ++i) {
        cin >> A[i];
    }
    vector<ll> b(N);
    for (int i = 0; i < N-1; ++i) {
        b[A[i]-1]++;
    }
    for (int i = 0; i < N; ++i) {
        cout << b[i] << endl;
    }
}


Measured memory_bytes: 6432
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A, N, mod;
  cin >> N >> A;
  mod = N % 500;
  
  if (mod <= A) {
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }    
}

Measured memory_bytes: 256
/* Author : Aaryan Srivastava ^__^ */ 
#include <bits/stdc++.h>
#include <random>
#include <chrono>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
#define pb push_back
#define popb pop_back
#define mt make_tuple 
#define eb emplace_back
#define mp make_pair
#define ff first
#define ss second 
#define ull unsigned long long  
#define pii pair<int, int>
#define piii pair<int,pii>
#define beg begin
#define rep(i,n) for(int (i) = 0 ; i < (n) ; i++)
#define repA(i,x,y) for(int i = (x) ; i <= (y) ; i++)
#define repD(i,x,y) for(int i = (x) ; i >= (y) ; i--)
#define all(c) (c).begin(),(c).end()
#define fill(a,val) memset(a,val,sizeof(a))
#define Randomize mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define int ll
using ll = long long;
const int N = 3*1e5 +5 ;
const int mod = 1e9 + 7 ;
const int inf = 1e18 ;
const int SZ = 101 ;
const double eps = 1e-9 ;
using namespace __gnu_pbds;
using namespace std;
using ordered_set =  tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ;

#ifdef AaryanS
#define mycout cout
#define mycerr cerr 
#endif

#ifndef AaryanS
#define mycout if(false) cout
#define mycerr if(false) cerr
#endif


void solve()
{
	int n,a,b ;
	cin >> n >> a >> b ;
	cout << min(a*n,b);
}   

     
int32_t main(int32_t argc, char *argv[])
{
    double t1 = clock() ;
    ios::sync_with_stdio(0);    
    cin.tie(0); cout.tie(0);
    int TC = 1, t = 0;
    //cin >> TC ;
    while(t++ < TC)
    {
        //cout << "Case #" << t << ": " ;
        solve();
        //cout << endl ;
    }
    mycerr << "Time : " << 1000 *(clock() - t1)/CLOCKS_PER_SEC << " ms\n" ;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <algorithm>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#define N 110
#define pb push_back
#define fi first
#define se second
#define si size()
#define ll long long
#define mp make_pair
#define iter ::iterator
#define all(v) v.begin(), v.end()
#define READ(f) freopen (f, "r", stdin)
#define WRITE(f) freopen (f, "w", stdout)
#define pp pop_back
#define mapiter map<int, int>::iterator
#define pii pair<int, int>
#define forn(i, n) for(ll i = 0; i < n; ++i)
#define forn1(i, n) for(int i = 1; i <= n; ++i)
#define forr(i, n) for(int i = n - 1; i >= 0; --i)
#define forr1(i, n)	for(int i = n; i >= 1; --i)
#define barnarnar ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define PI 3.141592653589793238462643383279502884L
#define elif else if
#define lld long double
#define r0 return 0
#define EPS 1e-7
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 

const int inf = 1e9 + 1;
const ll modw = 1e9 + 9;
  
using namespace std;
using namespace __gnu_pbds;

int gcd(int a_a, int b_b)
{
	return b_b?gcd(b_b,a_a%b_b):a_a;
}



int main()
{
    barnarnar
	int x, y;
	cin >> x >> y;
	if(x * 2 <= y && y <= 4 * x && y % 2 == 0)	cout << "Yes";
	else	cout << "No";
    return 0;
}
/*
1
1
FMMMMFFFFFMM 1
*/



Measured memory_bytes: 3636
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;

template<int MOD>
class ModInt{
public:
    ModInt():value(0){}
    ModInt(long long val):value((int)(val<0?MOD+val%MOD:val%MOD)){ }

    ModInt& operator+=(ModInt that){
        value = value+that.value;
        if(value>=MOD)value-=MOD;
        return *this;
    }
    ModInt& operator-=(ModInt that){
        value -= that.value;
        if(value<0)value+=MOD;
        return *this;
    }
    ModInt& operator*=(ModInt that){
        value = (int)((long long)value * that.value % MOD);
        return *this;
    }
    ModInt &operator/=(ModInt that){
        return *this *= that.inverse();
    }
    ModInt operator+(ModInt that) const{
        return ModInt(*this)+=that;
    }
    ModInt operator-(ModInt that) const{
        return ModInt(*this)-=that;
    }
    ModInt operator*(ModInt that) const{
        return ModInt(*this)*=that;
    }
    ModInt operator/(ModInt that) const {
        return ModInt(*this) /= that;
    }
    ModInt pow(long long k) const{
        if(value == 0)return 0;
        ModInt n = *this, res = 1;
        while(k){
            if(k & 1)res *= n;
            n *= n;
            k >>= 1;
        }
        return res;
    }
    ModInt inverse() const {
        long long a = value, b = MOD, u = 1, v = 0;
        while(b) {
            long long t = a / b;
            a -= t * b;
            swap(a, b);
            u -= t * v;
            swap(u, v);
        }
        return ModInt(u);
    }
    int toi() const{ return value; }

private:
    int value;
};
typedef ModInt<924844033> mint;
ostream& operator<<(ostream& os, const mint& x){
    os << x.toi();
    return os;
}

mint dp[4000][2001][2][2], DP[2001][2001];

int main(){
    int N, K;
    cin >> N >> K;
    DP[0][0] = 1;
    rep(ii, K){
        dp[ii][0][0][0] = 1;
        int L = 0;
        for(int i = ii; i < N; i += K){
            if(dp[i][0][0][0].toi() == 0)assert(0);
            rep(j, N + 1)rep(pp, 2)rep(p, 2){
                mint x = dp[i][j][pp][p];
                if(x.toi() == 0)continue;
                if(!pp && i-K>=0)dp[i + K][j + 1][p][0] += x;
                if(i+K<N)dp[i + K][j + 1][p][1] += x;
                dp[i + K][j][p][0] += x;
            }
            L = i + K;
        }
        
        rep(i, N + 1){
            mint x;
            rep(j, 2)rep(k, 2)x += dp[L][i][j][k];
            if(x.toi())for(int j = 0; i + j <= N; ++j){
                DP[ii + 1][i + j] += x*DP[ii][j];
            }
        }
    }

    vector<mint> fa(N + 1);
    fa[0] = 1;
    rep(i, N)fa[i + 1] = fa[i] * (i + 1);
    mint ans;
    rep(i,N+1)ans += fa[N - i] * DP[K][i] * (i%2?-1:1);
    cout << ans << endl;
}

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

using namespace std;

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

    vector<int> cnt(100010);
    long long sum = 0;
    for(int i=0;i<n;i++){
        int a;
        cin >>a;
        cnt[a]++;
        sum += a;
    }

    int q, b, c;

    cin >>q;
    while(q--){
        cin >>b>>c;

        sum += (c-b) * cnt[b];
        cnt[c] += cnt[b];
        cnt[b] = 0;

        cout << sum << "\n";
    }

}


Measured memory_bytes: 3752
import java.util.Scanner;

public class Main{
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int c = sc.nextInt();
    int ans = c - (a - b);
    if(ans < 0) ans = 0;
    System.out.println(ans);
  }
}

Measured memory_bytes: 23636
/*
ID: anonymo14
TASK: wormhole
LANG: C++                 
*/
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<pair<int,int>> vpii;

#define F first
#define S second
#define PU push
#define PUF push_front
#define PUB push_back
#define PO pop
#define POF pop_front
#define POB pop_back

#define REP(i,a,b) for(int i=a; i<=b; i++)

#define MOD 1000000007

void solve(int test_case) {
	int n;
	cin>>n;
	n*=3;
	ll sum = 0;
	int req = n/3;
	int end = 2*n/3;
	vector<int> arr(n);
	for(int &i:arr)cin>>i;
	sort(arr.rbegin(),arr.rend());
	for(int i=1;i<2*n/3;i+=2) {
			sum+=arr[i];
	}
	cout<<sum;
}

int main() {
	
	////// FILE BASED IO////
	//freopen("wormhole.in", "r", stdin);
	//freopen("wormhole.out", "w", stdout);
	///////////////
	
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t=1;
	//cin>>t;
	REP(i,1,t) {
		solve(i);
	}
	return 0;
}	


Measured memory_bytes: 4436
#include <iostream>

using namespace std;

int main() {
  long long int m, n;
  cin >> m >> n;

  long long int res = 1;
  while(n > 0) {
    if(n & 1) {
      res *= m;
    }
    res %= 1000000007;
    m *= m;
    m %= 1000000007;
    n >>= 1;
  }

  cout << res << endl;

  return 0;
}



Measured memory_bytes: 3120
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

#define MOD 1000000007
#define MOD2 998244353
#define int long long
#define double long double
#define EPS 1e-9
//#define PI 3.14159265358979

#define rep(i, n) for (int i = 0; i < (int)(n); i++)

using namespace std;

template < typename T >
ostream &operator<<(ostream &os, const vector< T > &A) {
	for (int i = 0; i < A.size(); i++)
		os << A[i] << " ";
	os << endl;
	return os;
}
template <>
ostream &operator<<(ostream &os, const vector< vector< int > > &A) {
	int N = A.size();
	int M;
	if (N > 0)
		M = A[0].size();
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < M; j++)
			os << A[i][j] << " ";
		os << endl;
	}
	return os;
}

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

struct edge {
	int from, to, d, c;
	edge(int _from = 0, int _to = 0, int _d = 0, int _c = 0) {
		from = _from;
		to = _to;
		d = _d;
		c = _c;
	}
	bool operator<(const edge &rhs) const {
		return (d == rhs.d) ? (c < rhs.c) : (d < rhs.d);
	}
};
struct aabb {
	int x1, y1, x2, y2;
	aabb(int x1, int y1, int x2, int y2) : x1(x1), y1(y1), x2(x2), y2(y2) {}
};

typedef vector< edge > edges;
typedef vector< edges > graph;
struct flow {
	int to, cap, rev, cost;
	flow(int to = 0, int cap = 0, int rev = 0, int cost = 0) : to(to), cap(cap), rev(rev), cost(cost) {}
};
typedef vector< vector< flow > > flows;

const int di[4] = {0, -1, 0, 1};
const int dj[4] = {-1, 0, 1, 0};
const int ci[5] = {0, 0, -1, 0, 1};
const int cj[5] = {0, -1, 0, 1, 0};
const ll LINF = LLONG_MAX / 2;
const int INF = INT_MAX / 2;
const double PI = acos(-1);

int pow2(int n) { return 1LL << n; }
template < typename T, typename U >
bool chmin(T &x, const U &y) {
	if (x > y) {
		x = y;
		return true;
	}
	return false;
}
template < typename T, typename U >
bool chmax(T &x, const U &y) {
	if (x < y) {
		x = y;
		return true;
	}
	return false;
}

struct initializer {
	initializer() {
		cout << fixed << setprecision(20);
	}
};
initializer _____;

int N, M, K, T, Q, H, W;
signed main() {
	cin >> N >> M;
	vector< int > H(N);
	rep(i, N) cin >> H[i];
	vector< vector< int > > G(N);
	rep(i, M) {
		int a, b;
		cin >> a >> b;
		--a;
		--b;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	int ans = 0;
	rep(i, N) {
		int f = 1;
		for (auto j : G[i]) {
			if (H[j] >= H[i])
				f = 0;
		}
		ans += f;
	}
	cout << ans << endl;
	return 0;
}

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

int mincost( int *arr , int *dp , int n , int i , int k  ){
  if(i==0){
      dp[0] = 0 ;
      return 0 ;
  }
  if(i==1){
      dp[1] = max(arr[1] - arr[0] , arr[0] -arr[1]) ;
      return dp[1] ;
  }

  if( dp[i]!= -1){
      return dp[i] ;
  }
  int y ;
  int ans = INT_MAX ;
  for( int j= 1 ; j<=k ; j++){
      if(i-j>=0){
       y = mincost( arr , dp , n , i-j , k) + max( arr[i] - arr[i-j] , arr[i-j] - arr[i]) ;
      }
      else{
         break ;
      }
   ans = min( ans , y) ;
  }
  return dp[i] = ans  ;
}


int main() {
    int n, k ;
    cin>> n>>k;
    int arr[n] ;
    for( int i = 0 ;i< n ; i++){
        cin>>arr[i] ;
    }
      int dp[n] ;
    for( int i = 0 ;i< n ; i++){
        dp[i] = -1 ;
    }
  
    cout<<mincost( arr , dp , n , n-1 , k)<<endl ;

    return 0 ;
}


Measured memory_bytes: 10368
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ll  long long
#define FASTINOUT ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const int N=200009;
int main()
{
    FASTINOUT;
    ll a;
    cin>>a;
    cout<<a+a*a+a*a*a<<endl;
    return 0;
}


Measured memory_bytes: 3648
# 計算量 O(NC) = O(3 * 10 ** 6)
import sys
input = sys.stdin.readline
import numpy as np

N, C = map(int, input().split())

# 入力
lst = [[0] * (10 ** 5 + 10) for _ in range(C + 1)]
# lst_max = [[1] * (10 ** 5 + 10) for _ in range(C + 1)]

# lst = [[0] * (10) for _ in range(C + 1)]
# lst_max = [[1] * (10) for _ in range(C + 1)]

for _ in range(N):
    s, t, c = map(int, input().split())
    lst[c][s] += 1
    lst[c][t + 1] -= 1

lst = np.array(lst)
np.cumsum(lst, axis = 1, out = lst)
np.minimum(lst, 1, out = lst)
np.cumsum(lst, axis = 0, out = lst)

print (np.max(lst[-1]))

Measured memory_bytes: 60964
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
 
int main() {
    int N, T, A;
    cin >> N >> T >> A;
    vector<int> vec(N);
    vector<double> sa(N);
    double minsa = 100000.0;
    for(int i=0; i<N; i++){
        cin >> vec.at(i);
        sa.at(i) = max(T-vec.at(i)*0.006-A, A-T+vec.at(i)*0.006);
        minsa = min(minsa, sa.at(i));
    }
    for(int i=0; i<N; i++){
        if(minsa == sa.at(i)){
            cout << i+1 << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define t(...) GET_MACRO(__VA_ARGS__,t6,t5, t4, t3, t2, t1)(__VA_ARGS__)
#define _ cerr<<"here"<<endl;
#define __ {ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);}

using namespace std;


bool check(int n,int i)
{
  if((n|i)==n)
  return true;
  else return false;
}

int main()
{
  __;
  int n;
  cin >> n;
  string s;
  cin >> s;
  vector<int> v;
  for(int i=0;i<n;i++)
  {
    if(check(n-1,i)) 
    {
      v.push_back(i);
      continue;
    }
  }

  set<char> se;
  bool zero = false;
  for(int i=0;i<s.size();i++) 
  {
    if(s[i] == '1') zero = true;
    s[i]--;
    se.insert(s[i]);
  }

  int x = 0;
  if(se.size() == 3)
  {
    for(int i=0;i<v.size();i++)
    {
      if(s[v[i]] == '1') x ^= 1;
      // t(s[v[i]],v[i],x);
    }
  }
  else if(se.size() == 2)
  {
    for(int i=0;i<v.size();i++)
    {
      if(s[v[i]] != '0') x ^= s[v[i]]-'0';
    }
    if(!zero) 
    {
      cout << 1 << endl;
      return 0;
    }
  }
  else 
  {
    if(s.size() == 1) cout << (char)(s[0]+1) << endl;
    else cout << 0 << endl;
    return 0;
  }

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


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

int main(){
	int x, n; cin>>x>>n;
	set<int> st; 
	int t;
	for(int i=0;i<n;i++) cin>>t, st.insert(t);
	int i=x, j=x;
	int ans;
	while(true){
		if(st.find(i)==st.end()){
			 ans = i; break;
		}
		if(st.find(j)==st.end()){
			 ans = j; break;
		}
		i--; j++;
	}
	cout<<ans;
	return 0;
}



Measured memory_bytes: 3636
#include <stdio.h>
#include <string.h>

int main(){
    char S[11];
    char T[strlen(S)+1];
    int j=0;
    scanf("%s\n",S);
    scanf("%s",T);
    for (int i=1; i<=strlen(S); i++) {
        if (S[i-1]!=T[i-1]) {
            j++;
        }
    }
    if (j==0 && strlen(S)!=strlen(T)) {
        printf("Yes\n");
    }
    if (j>0 || strlen(S)==strlen(T)) {
        printf("No\n");
    }
}


Measured memory_bytes: 2032
def rotation(string):
    result = string[-1]
    for i in range(len(string)-1):
        result += string[i]
    return result

S = input()
T = input()

flag = False
for i in range(len(S)):
    S = rotation(S)
    if T == S:
        flag = True
        break

if flag:
    print("Yes")
else:
    print("No")

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

using ll = int64_t;
#define int ll

#define FOR(i, a, b) for (int i = int(a); i < int(b); i++)
#define REP(i, b) FOR(i, 0, b)
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define ALL(x) x.begin(), x.end()

using pi = pair<int, int>;
using vi = vector<int>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  REP(i, (int)v.size()) {
    if (i)
      os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}

ll read() {
  ll i;
  scanf("%" SCNd64, &i);
  return i;
}

void printSpace() { printf(" "); }

void printEoln() { printf("\n"); }

void print(ll x, int suc = 1) {
  printf("%" PRId64, x);
  if (suc == 1)
    printEoln();
  if (suc == 2)
    printSpace();
}

string readString() {
  static char buf[3341000];
  scanf("%s", buf);
  return string(buf);
}

char *readCharArray() {
  static char buf[3341000];
  static int bufUsed = 0;
  char *ret = buf + bufUsed;
  scanf("%s", ret);
  bufUsed += strlen(ret) + 1;
  return ret;
}

template <class T, class U> void chmax(T &a, U b) {
  if (a < b)
    a = b;
}

template <class T, class U> void chmin(T &a, U b) {
  if (b < a)
    a = b;
}

template <class T> T Sq(const T &t) { return t * t; }

const int mod = 1e9 + 7;

signed main() {
  int x, a, b;
  std::cin >> x >> a >> b;
  print((x - a) % b);
}


Measured memory_bytes: 256
#k = int(input())
#s = input()
#a, b = map(int, input().split())
#s, t = map(str, input().split())
#l = list(map(int, input().split()))
#l = [list(map(int,input().split())) for i in range(n)]
#a = [list(input()) for _ in range(n)]
#a = [int(input()) for _ in range(n)]

n = int(input())
d,x = map(int, input().split())
a = [int(input()) for _ in range(n)]

ans = 0
for i in range(n):
    if (d % a[i] == 0):
        ans += d // a[i]
    else:
        ans += d // a[i] + 1
print(ans + x)





Measured memory_bytes: 9108
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		int N = scan.nextInt();
		int[] suretuP = new int[N];
		int[] suretuQ = new int[N];

		ArrayList<Integer> integer1 = new ArrayList<>();
		ArrayList<Integer> integer2 = new ArrayList<>();

		for(int i=0;i<N;i++) {

			suretuP[i] = scan.nextInt();
		}

		for(int i=0;i<N;i++) {
			suretuQ[i] = scan.nextInt();
		}


		for(int i=1;i<=N;i++) {
			integer1.add(i);
		}

		int countP = 0;

		for(int i=0;i<N-1;i++) {
			countP += integer1.indexOf(suretuP[i])*fact(N-i-1);
			integer1.remove((Integer)suretuP[i]);
			Collections.sort(integer1);
		}

		for(int i=1;i<=N;i++) {
			integer2.add(i);
		}
		int countQ = 0;

		for(int i=0;i<N-1;i++) {
			countQ += integer2.indexOf(suretuQ[i])*fact(N-i-1);
			integer2.remove((Integer)suretuQ[i]);
			Collections.sort(integer2);
		}

		System.out.println(Math.abs(countP-countQ));
		scan.close();

	}

	public static int fact(int num) {

		int i=1;
		for(int j=1;j<=num;j++) {
			i *= j;
		}
		return i;
	}

}


Measured memory_bytes: 21844
#include<iostream>
#include <vector>
#include <math.h>
using namespace std;
 
int main()
{
    long long N;
    cin >> N;
  
    long long rest = 0;
    for (long long i = 1; i <= N; ++i) {
        rest += i-1;
    }
  
    cout << rest << endl;
    return 0;
}
 

Measured memory_bytes: 256
// --------------------<optimizations>--------------------
#pragma GCC optimize("O3")

//(UNCOMMENT WHEN HAVING LOTS OF RECURSIONS)\
#pragma comment(linker, "/stack:200000000")
//(UNCOMMENT WHEN TRYING TO BRUTEFORCE WITH A LOT OF LOOPS)\
#pragma GCC optimize("unroll-loops")

// -------------------</optimizations>--------------------
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pii pair<int,int>
#define pb push_back
#define pf push_front
#define cases int t;cin>>t;while(t--)
#define N 100003
#define M 103
#define inf LLONG_MAX
//int mod=1e9+7;
//int mod=998244353;

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

    int a,b,c,d,e,k;
    cin>>a>>b>>c>>d>>e>>k;
    if(e-a>k)
        cout<<":(";
    else
        cout<<"Yay!";



    return 0;
}


Measured memory_bytes: 764
#include <bits/stdc++.h>
using namespace std;;
#define ll long long
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define INF 1<<30
#define LINF 1LL<<62
#define all(x) (x).begin(), (x).end()
#define mp make_pair
#define pb push_back
const int MOD = 1000000007;
 
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll N,W; cin >> N >> W;
  vector<ll> w(N), v(N);
  REP(i,N){
      cin >> w[i] >> v[i];
  }
  ll d[N][100005];
  REP(i,N){
      REP(j,100005){
          d[i][j] = LINF;
      }
  }
  d[0][0] = 0;
  d[0][v[0]] = w[0];
  REP(i,N-1){
      REP(j,100005){
          if(d[i][j]!=LINF){
              d[i+1][j] = min(d[i][j], d[i+1][j]);
              d[i+1][j+v[i+1]] = min(d[i+1][j+v[i+1]], d[i][j] + w[i+1]);
          }
      }
  }
  ll ans = 0;
  REP(j,100005){
      if(d[N-1][j]<=W){
          ans = j;
      }
  }
  cout << ans << endl;

}

Measured memory_bytes: 78336
#include<bits/stdc++.h>
#include<iostream>
#include<cmath>
#include<string>
#include<set>
using namespace std;
#define rep(i, a, n) for (int i = a; i < n; i++)
typedef long long ll;
#define big 1000000007
#define all(a) sort((a).begin(),(a).end()) //ソートのマクロ
#define Re(a) reverse((a).begin(),(a).end())
#define YN(a) if(a){cout<<"Yes"<<endl;}else cout<<"No"<<endl;//条件によってYes、Noを出力する
int main(){
    int x;
    cin>>x;
    YN(x>=30);
}

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

#define rp(i, k, n) for (int i = k; i < n; i++)
typedef long long ll;
typedef double ld;



template<class T>inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>inline bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll INF = 1ll << 60;
const ll MOD = 1e9 + 7ll;
const double PI=3.14159265358979323846;

int main() {
    int N;
    cin >> N;
    vector< vector <int> > dis(20, vector<int>(20));
    for(int i = 1; i <= N; i++) {
        int matsubi = i % 10;
        int sentou = i;
        while(sentou >= 10) sentou /= 10;
        dis[sentou][matsubi] += 1;
    }
    int res = 0;
    for(int i = 1; i <= 9; i++) {
        for(int j = 1; j <= 9; j++) {
            res += dis[i][j] * dis[j][i];
        }
    }
    cout << res << endl;
    return 0;
}

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

using namespace std;

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

    int N, X;
    cin >> N >> X;
    int cnt = 1;
    for (int i = 0, cur = 0; i < N; ++i) {
        int L;
        cin >> L;
        cur += L;
        cnt += (cur <= X);
    }
    cout << cnt << "\n";

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const long long INF = 1LL << 60;
const int mod = 1e9 + 7;

int main()
{
    long long a, b, c, k;
    cin >> a >> b >> c >> k;
    long long ans = k;
    if (k > a)
    {
        ans -= (k - a);
        if ((k - a) > b)
        {
            ans -= (k - a - b);
        }
    }

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

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
typedef long long llong;
const int inf = 1 << 20;
const int mod = 1e9 + 7;

int main() {
   int h, w;
   cin >> h >> w;
   vector<vector<char>> s(h, vector<char>(w));
   rep(i, h) rep(j, w) cin >> s[i][j];

   vector<vector<int>> row(h, vector<int>(w));
   rep(i, h) {
      rep(j, w) {
         if (s[i][j] == '#') continue;
         if (row[i][j]) continue;
         int l = 0;
         for (int k = j; k < w; k++) {
            if (s[i][k] == '#') break;
            l++;
         }
         for (int k = j; k < j + l; k++) {
            row[i][k] = l;
         }
      }
   }
   vector<vector<int>> col(h, vector<int>(w));
   rep(j, w) {
      rep(i, h) {
         if (s[i][j] == '#') continue;
         if (col[i][j]) continue;
         int l = 0;
         for (int k = i; k < h; k++) {
            if (s[k][j] == '#') break;
            l++;
         }
         for (int k = i; k < i + l; k++) {
            col[k][j] = l;
         }
      }
   }
   int ans = 0;
   rep(i, h) rep(j, w) ans = max(ans, col[i][j] + row[i][j] - 1);
   cout << ans << endl;
   return 0;
}

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

#pragma region Macro
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define SORT(v) sort(v.begin(), v.end())
#define pb(a) push_back(a)
#define eb(a) emplace_back(a)
#define vi vector<int>
#define vvi vector<vector<int>>
#define chmax(x,y) (x = max(x,y))
#define chmin(x,y) (x = min(x,y))

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#pragma endregion

const int MAX = 510000;
const int MOD = 998244353;

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

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

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

void solve(){
	#define int ll
	// ここに処理を記述
	// コンパイル時はエイリアス「gpp」--> c++17でコンパイル
	int n,m,k;
	cin >> n >> m >> k;

	int ans = 0;
	COMinit();

	ll color = m;
	for(int i = n-1; i >= 0; --i){
		ll col_pattern = color;
		col_pattern *= COM(n-1,i);
		col_pattern %= MOD;
		// cout << col_pattern << endl;
		if(i <= k){
			ans += col_pattern;
			ans %= MOD;
		}
		color *= m-1;
		color %= MOD;
	}

	cout << ans << endl;
}

signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	
	solve();
	return 0;
}

Measured memory_bytes: 15552
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 1000000000000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;



int main(){

	int table[3];
	int maximum = -1;

	for(int i = 0; i < 3; i++){

		scanf("%d",&table[i]);
		maximum = max(maximum,table[i]);
	}

	int ans = 0;
	for(int i = 0; i < 3; i++){

		int add = (maximum-table[i])/2;
		ans += add;
		table[i] += 2*add;
	}

	int count = 0;
	for(int i = 0; i < 3; i++){

		if(table[i] != maximum){

			count++;
		}
	}

	if(count == 1){

		ans += 2;

	}else if(count == 2){

		ans++;
	}

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

	return 0;
}


Measured memory_bytes: 3824
def examD():
    N = I()
    A = LI(); A.sort()
    ans = [max(A)]
    ansC = ans[0]/2
    lower = 0; upper = N-2
    while(upper-lower>1):
        now = (lower+upper)//2
        if A[now]>ansC:
            upper = now
        elif A[now]<ansC:
            lower = now
        else:
            ans.append(int(ansC))
            break
    if len(ans)==1:
        if abs(A[upper]-ansC)-abs(A[lower]-ansC)<0:
            now = upper
        else:
            now = lower
        ans.append(A[int(now)])
    print(" ".join(map(str,ans)))


import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

examD()


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

//Trigonometric function.
//Drawing.
int main(){
	double PI=acos(-1);
	
	double a,b,x;
	cin>>a>>b>>x;
	
	x/=a;
	double ans;
	if(x>a*b/2){
		double tmp=a*b-x;
		double h=tmp*2/a;
		ans=180*(atan(h/a)/PI);
	}else{
		double h=x*2/b;
		ans=180*(atan(b/h)/PI);
	}
	
	printf("%.10f\n",ans);
}


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

int main(){ 
  int n;
  cin >> n;
  vector<vector<int>> cnt(10,vector<int>(10,0));
  ll res = 0;
  for (int i = 1; i <= n; i++) {
    string now = to_string(i);
    cnt[now.front() - '0'][now.back() -'0']++;
  }
  for (int i = 1; i < 10; i++) {
    for (int j = 1; j < 10; j++) res += cnt[i][j] * cnt[j][i];
  }
  cout << res << endl;
  return 0;
} 

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

int main() {
  string s; cin >> s;
  if (s.length() % 2) {
    cout << "No" << endl;
    return 0;
  }
  int tmp = 0;
  while (tmp + 1 < s.length()) {
    if (s[tmp] == 'h' && s[tmp+1] == 'i') {
      tmp += 2;
    }
    else {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}


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

using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define ll long long int
#define INF 1000000007
#define llINF 1000000000000000007
#define v(i) vector<i>
#define vv(i) vector<vector<i>>
// cin.eof() 入力個数の問題
// int num = atoi(string.c_str()); 文字列の整数変換

int main() {
ll a,b;
cin>>a>>b;
if((a<0&&b>0)||(a==0||b==0)){
    cout<<"Zero"<<endl;
}
else if(a>0&&b>0){
    cout<<"Positive"<<endl;
}else
{
    ll count = - a - b + 1;
    if(count % 2 == 0){
         cout<<"Positive"<<endl;
    }else
    {
        cout<<"Negative"<<endl;
    }
    
}


    return 0;
}


Measured memory_bytes: 3576
n, m = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(m)]

from collections import defaultdict
graph = defaultdict(list)
for i in range(m):
    a = ab[i][0] - 1
    b = ab[i][1] - 1
    graph[a].append(b)
    graph[b].append(a)

ans = 0
import itertools
for orders in itertools.permutations(list(range(n))):
    if orders[0] != 0:
        continue

    # check
    f = True
    for j in range(len(orders) - 1):
        if orders[j+1] not in graph[orders[j]]:
            f = False
    if f:
        ans += 1
        # print(orders)

print(ans)


Measured memory_bytes: 3436
#include<cstdio>
#include<algorithm>
using namespace std;

struct BIT{
  long long int a;
  int num;
};

struct BUG{
  int a, b, pos;
};

bool acomp(const BUG& x, const BUG& y){
  return x.a < y.a;
}

bool bcomp(const BUG& x, const BUG& y){
  return x.b > y.b;

}

BIT bit[1 << 20];
BUG bug[1 << 20];

int n, nbin = 1, ans = 0, up, down;

void addbit(int x){
  int pos = bug[x].pos;
  while(pos <= nbin){
    bit[pos].a += bug[x].a;
    bit[pos].num++;
    pos += pos & -pos;
  }
}

int able(int pos, int limit){
  long long int asum = 0;
  long long int num = 0;
  while(pos != 0){
    asum += bit[pos].a;
    num += bit[pos].num;
    pos -= pos & -pos;
  }
  if(limit * num >= asum)return num;
  else return -1;
}

int main(){
  scanf("%d" , &n);
  while(n > nbin)nbin <<= 2;
  for(int i = 0;i < n;i++){
    scanf("%d%d", &bug[i].a, &bug[i].b);
    bug[i].pos = 0;
    bit[i].a = 0;
    bit[i].num = 0;
  }
  sort(bug, bug + n, acomp);
  for(int i = 1;i <= n;i++){
    bug[i - 1].pos = i;
  }
  sort(bug, bug + n, bcomp);
  
  for(int i = 0;i < n;i++){
    addbit(i);
    up = nbin;
    down = 1;
    while(up - down > 1){
      int mid = (up + down) / 2;
      int tmp = able(mid, bug[i].b);
      if(tmp == -1)
	up = mid;
      else
	down = mid;
    }
    ans = max(ans, able(down, bug[i].b));
  }
  printf("%d\n", ans);
}

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

using namespace std;

typedef vector<int> vi;

int main(){
  int N;
  cin >> N;
  vi A(N);
  vi B(N);

  for(int i=0;i<N;i++){
    int t;
    cin >> t;
    A.at(i) = t;
    B.at(i) = t;
  }

  sort(A.begin(), A.end());

  int counter=0;
  for(int i=0;i<N;i++){
    if(A.at(i)!=B.at(i))  counter++;
  }

  if(counter==2 || counter==0)  cout << "YES" << endl;
  else  cout << "NO" << endl;

}



Measured memory_bytes: 256
parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function euc(a,m)
	b = m
	x = 1
	u = 0
	while b>0
		q = div(a,b)
		tmp = u
		u = x-q*u
		x = tmp
		tmp = b
		b = a-q*b
		a = tmp
	end
	x<0?x+abs(m):x
end

function main()
	mod = 10^9+7
	n = readline() |> parseInt
	x = readline() |> split |> parseMap
	fact = zeros(Int,n-1)
	fact[1] = 1
	for i in 2:n-1
		fact[i]=fact[i-1]*i%mod
	end
	a = zeros(Int,n-1)
	a[1]=fact[n-1]
	for i in 2:n-1
		a[i]=(a[i-1]*euc(i,mod)%mod)*(i-1)%mod
	end
	b = zeros(Int,n-1)
	b[1] = a[1]
	for i in 2:n-1
		b[i]=(b[i-1]+a[i])%mod
	end
	s = 0
	for i in 1:n-1
		s = (s+(x[i+1]-x[i])*b[i]%mod)%mod
	end
	println(s)
end

main()

Measured memory_bytes: 120588
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

using namespace std;
using ll = long long;

template<typename T>
using vec2 = vector<vector<T>>;
template<typename T>
using vec3 = vec2<vector<T>>;
template<typename T>
using vec4 = vec3<vector<T>>;
template<typename T>
using vec5 = vec4<vector<T>>;
template<typename T>
using vec6 = vec5<vector<T>>;



int main(){
    string S,T;cin>>S>>T;
    int ans = S.size();
    for(int i = 0;i < S.size() - T.size()+1;i++){
        int res = 0;
        for(int j = 0;j < T.size();j++){
            if(S[i+j] != T[j])res++;
        }
        ans = min(ans,res);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3612
#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 str;
    cin >> str;
    int n = 0;
    int w = 0;
    int s = 0;
    int e = 0;
    for(char c : str){
        if(c == 'N') n = 1;
        if(c == 'W') w = 1;
        if(c == 'S') s = 1;
        if(c == 'E') e = 1;
    }
    if((n+s)%2 == 0 && (w+e)%2 == 0) {
        cout << "Yes" << endl;
    }
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3572
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

int main() {
	char c;

	std::cin >> c;

	if (c == 'A') {
		std::cout << "T" << std::endl;
	}
	else if (c == 'C') {
		std::cout << "G" << std::endl;
	}
	else if (c == 'T') {
		std::cout << "A" << std::endl;
	}
	else {
		std::cout << "C" << std::endl;
	}
}

Measured memory_bytes: 256
#include<stdio.h>
#include<bits/stdc++.h>
int main()
{
  int n;
  scanf("%d",&n);
  int f=0;
  if(n%2==0)
    f=0;
  else
    f=1;
  if(f==1)
    printf("%d",(n/2)+1);
  else
    printf("%d",n/2);
}

Measured memory_bytes: 256
from collections import deque

H, W = map(int, input().split())
Ch, Cw = map(int, input().split())
Dh, Dw = map(int, input().split())

grid = []
for i in range(H):
    grid.append(input().rstrip())

d = deque()
d.append((Ch-1, Cw-1, 0))

memo = [[[False] * W for _ in range(H)] for _ in range(2)]
memo[0][Ch-1][Cw-1] = True

searched = [[False] * W for _ in range(H)]

ans = -1

while d:
    h, w, c = d.popleft()

    if searched[h][w]:
        continue

    searched[h][w] = True

    if h == Dh-1 and w == Dw-1:
        ans = c
        break

    for i, j in [(0, 1), (0, -1), (1, 0), (-1, 0)]:
        if 0 <= h+i < H and 0 <= w+j < W:
            if grid[h+i][w+j] == '.':
                if not memo[0][h+i][w+j] and not searched[h+i][w+j]:
                    memo[0][h+i][w+j] = True
                    d.appendleft((h+i, w+j, c))

    for i in range(-2, 3):
        for j in range(-2, 3):
            if 0 <= h+i < H and 0 <= w+j < W:
                if grid[h+i][w+j] == '.':
                    if not memo[0][h+i][w+j] and not memo[1][h+i][w+j] and not searched[h+i][w+j]:
                        memo[1][h+i][w+j] = True
                        d.append((h+i, w+j, c+1))

print(ans)


Measured memory_bytes: 116624
mod = 10**9 + 7
def main():
    N,K = map(int,input().split())
    ans = 0
    S = [0]
    for i in range(1,N+4):
        S.append( S[-1] + i )
    for k in range(K,N + 1):
        ans = (ans + (S[N] - S[N - k]) - S[k - 1] + 1)%mod
    print((ans+1)%mod)
    return

if __name__ == "__main__":
    main()

Measured memory_bytes: 19296
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

int main(void) {
	int N, M;
	char buffer[128];
	char *ch;

	fgets(buffer, sizeof(buffer), stdin);
	ch = strtok(buffer, " ");
	N = atoi(ch);
	ch = strtok(NULL, " ");
	M = atoi(ch);

	if(N == M) {
		printf("Yes\n");
	} else {
		printf("No\n");
	}


	return 0;
}


Measured memory_bytes: 128
import java.util.*;
public class Main{

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt(), T = sc.nextInt();
		int c[] = new int[N];
		int t[] = new int[N];
		for(int i = 0; i<N; i++) {
			c[i]=sc.nextInt();
			t[i]=sc.nextInt();
		}
		int mincost = 10000;
		boolean ok = false;
		for(int i = 0; i<N; i++) {
			if(t[i]<=T) {
				if(c[i]<mincost)mincost = c[i];
				ok = true;
			}
		}
		if(ok)System.out.println(mincost);
		else System.out.println("TLE");
		sc.close();

	}
}

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

using namespace std;

using ll = long long;
using ull = unsigned long long;

int main(int argc, char const *argv[]) {
	int n;
	std::cin >> n;
	std::vector<int> v(n);
	std::vector<int> c(n);
	for (size_t i = 0; i < v.size(); i++) {
		std::cin >> v[i];
	}
	for (size_t i = 0; i < c.size(); i++) {
		std::cin >> c[i];
	}

	int ans = 0;
	for (size_t i = 0; i < v.size(); i++) {
		ans = ans + max(0, v[i]-c[i]);
	}

	std::cout << ans << '\n';
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <numeric>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep2(i, a, n) for (int i = (a); i < (n); ++i)
using namespace std;
using ll = long long;
using uint = unsigned int;
const ll mod = (ll)1e9 + 7;

int main() {
  int n;
  cin >> n;
  n %= 1000;
  if (n != 0) n = 1000 - n;
  cout << n << endl;
  return 0;
}


Measured memory_bytes: 3676