akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;

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

	vector<vector<int>> ans(h, vector<int>(w, 0));
	if (s[0][0] == '#') ans[0][0]++;
	rep(i, h)rep(j, w) {
		if (i == 0 && j == 0) { continue; }
		else if (i == 0) {
			if (s[i][j] == '.') ans[i][j] = ans[i][j - 1];
			else {
				if (s[i][j - 1] == '.') ans[i][j] = ans[i][j - 1] + 1;
				else ans[i][j] = ans[i][j - 1];
			}
		}
		else if (j == 0) {
			if (s[i][j] == '.') ans[i][j] = ans[i - 1][j];
			else {
				if (s[i - 1][j] == '.') ans[i][j] = ans[i - 1][j] + 1;
				else ans[i][j] = ans[i - 1][j];
			}
		}
		else {
			if (s[i][j] == '.') ans[i][j] = min(ans[i - 1][j], ans[i][j - 1]);
			else {
				/*int x = ans[i][j - 1] + (s[i][j - 1] == '.');
				int y = ans[i - 1][j] + (s[i - 1][j] == '.');*/
				int x = ans[i][j - 1];
				if (s[i][j - 1] == '.') x++;
				int y = ans[i - 1][j];
				if (s[i - 1][j] == '.') y++;
				ans[i][j] = min(x, y);
			}
		}

	}
	
	cout << ans[h-1][w-1] << endl;

}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Map;
import java.util.Scanner;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

/**
 * AtCoder Beginner Contest 1xx
 *
 * https://atcoder.jp/contests/abc1xx/tasks/abc1xx_c
 */
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        Map<String, Long> map = IntStream.range(0, n)
                .mapToObj(m -> {
                    sc.nextLine();
                    char[] chars = sc.next().toCharArray();
                    Arrays.sort(chars);
                    return new String(chars);
                })
                .collect(Collectors.groupingBy(m -> m, Collectors.counting()));
        System.out.println(map.values().stream().map(m -> m * (m-1)/2).mapToLong(m -> m).sum());
    }
}


Measured memory_bytes: 140304
import numpy as np
# -*- coding: utf-8 -*-
"""
Created on Wed Apr 25 12:48:25 2018

@author: tsumura
"""

        
ab = [int(x) for x in input().split()]

m = len(str(ab[1]))

ans= ab[0] * 10 ** m  + ab[1]

m2 = np.sqrt(ans)

if m2 % 2 == 0 or m2 % 2 == 1:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 21024
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
int n;
int a[1005];
int main()
{
    cin >> n;
    for(int i=0;i<n;i++){
        cin >> a[i];
    }
    sort(a,a+n);
    int ans = 0;
    for(int i=0;i<n;i++)
        for(int j=i+1;j<n;j++)
    for(int k=j+1;k<n;k++){
        if(a[i]+a[j]>a[k]&&a[k]-a[j]<a[i]&&a[i]!=a[j]&&a[j]!=a[k]){
            ans++;
        }
    }
    cout << ans <<endl;
    return 0;
}


Measured memory_bytes: 3592
S = input()


for i in range(2**3):
    formula = ""

    for j in range(3):
        formula += S[j]
        if (i >> j) & 1:
            formula += "+"
        else:
            formula += "-"
    formula += S[-1]

    if eval(formula) == 7:
        print(formula + "=7")
        break

Measured memory_bytes: 2940
import sys
from collections import Counter
from collections import deque
import heapq
import math
import fractions
import bisect
import itertools
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))

n=int(input())
p=lmp()
ans=0
for i in range(n-2):
    if sorted(list((p[i],p[i+1],p[i+2])))[1]==p[i+1]:
        ans+=1
print(ans)

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

int main(){
  int N, K, p=1 , ans=1;
  cin >> N >> K;
  for (int i = 0; i < N; i++){
    if (p < K){
      ans += p;
    }
    else{
      ans += K;
    }
    p *= 2;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ls rt<<1
#define rs rt<<1|1
using namespace std;

typedef long long ll;
const int p=1e8+7;


int ans;
int mp[3000][4][4];
string s[4];
void solve(int op1,int op2,int op3)
{
    for(int i=0; i<=s[op1].size(); i++)
    {
        if(!mp[i][op1][op2]) continue;
        for(int j=0; j<=s[op2].size(); j++)
        {
            if(mp[j][op2][op3])
            {
                if(i+j>=s[op1].size()||mp[i+j][op1][op3])
                {
                    int now=max(i+j+s[op3].size(),max(i+s[op2].size(),s[op1].size()));
                    ans=min(now,ans);
                }
            }
        }
        for(int j=s[op2].size();j<s[op1].size();j++)
        {
             if(i+j>=s[op1].size()||mp[i+j][op1][op3])
                {
                    int now=max(i+j+s[op3].size(),max(i+s[op2].size(),s[op1].size()));
                    ans=min(now,ans);
                }
        }
    }
}
int main()
{
    cin>>s[1]>>s[2]>>s[3];
    ans=s[1].size()+s[2].size()+s[3].size();
    for(int i=1; i<=3; i++)
    {
        for(int j=1; j<=3; j++)
        {
            if(i==j)
                continue;
            for(int k=0; k<=s[i].size(); k++)
            {
                mp[k][i][j]=1;
                for(int m=k,l=0; m<s[i].size()&&l<s[j].size(); m++,l++)
                {
                    if(s[i][m]==s[j][l]||s[i][m]=='?'||s[j][l]=='?')
                        continue;
                    mp[k][i][j]=0;
                    break;
                }
            }
        }
    }
    solve(1,2,3);
    solve(1,3,2);
    solve(3,1,2);
    solve(3,2,1);
    solve(2,1,3);
    solve(2,3,1);
    cout<<ans<<endl;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
#define to edge[i].v
#define mp make_pair
#define rint register int
#define debug(x) cerr<<#x<<"="<<x<<endl
#define fgx cerr<<"-------------"<<endl
#define pb push_back
#define N 1000000
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
int t,head[N],fa[N],son[N],del[N],c[N],dep[N];
struct Edge{int v,next;Edge(int _v=0,int _n=0):v(_v),next(_n){}}edge[N];
inline void add(int x,int y){edge[++t]=Edge(y,head[x]);head[x]=t;}
struct Q
{	int x,y,p,id; vector<int> go[2];
	Q(int _x=0,int _y=0,int _id=0):x(_x),y(_y),id(_id){p=0;go[0].clear();go[1].clear();}
}q[N];
void dfs(int x,int la=0)
{	fa[x]=la; dep[x]=dep[la]+1;
	for(rint i=head[x];i;i=edge[i].next) if(to!=la) dfs(to,x),son[x]++;
}
vector<Q*> cur;
void Add(int x,int y)
{	if(dep[x]<dep[y]) swap(x,y);
	for(;dep[x]!=dep[y];x=fa[x]) c[x]++;
	for(;x!=y;x=fa[x],y=fa[y]) c[x]++,c[y]++;
}
int main()
{//	freopen("a.in","r",stdin);
//	freopen("a.txt","w",stdout);
	int n,m,tot=0,x,y,sum=0; cin>>n>>m; tot=m;
	for(rint i=1;i<n;i++) scanf("%d%d",&x,&y),add(x,y),add(y,x);
	dfs(1);
	for(rint i=1;i<=m;i++) scanf("%d%d",&q[i].x,&q[i].y),Add(q[i].x,q[i].y),q[i].id=i;
	for(rint i=1;i<=n;i++) sum+=min(2,c[i]);
	cout<<sum<<endl;
	for(rint i=1;i<=n;i++)
	if(!son[i])
	{//	debug(i);
		son[fa[i]]--; son[i]=1e9;
		for(rint j=1;j<=tot;j++)
		{	if(!del[j]&&(q[j].x==i&&q[j].y==i)) del[j]=1;
			if(!del[j]&&(q[j].x==i||q[j].y==i)) cur.pb(&q[j]);
		}
		for(rint j=0;j<cur.size();j++) if(cur[j]->y==i)
		swap(cur[j]->x,cur[j]->y),cur[j]->p^=1,swap(cur[j]->go[0],cur[j]->go[1]);
//		for(rint j=0;j<cur.size();j++) debug(cur[j]->id);
	//	debug(cur.size());
		i=0; if(cur.size()==0) continue;
		if(cur.size()==1)
		for(rint j=0;j<cur.size();j++)
		{	del[cur[j]->id]=1,++tot,q[tot]=Q(fa[cur[j]->x],cur[j]->y,tot);
			q[tot].p=cur[j]->p; q[tot].go[0].push_back(cur[j]->id);
		//	debug(q[tot].p);
		}
		else
		{	for(rint j=0;j<cur.size();j+=2)
			if(j+1<cur.size())
			{	del[cur[j]->id]=del[cur[j+1]->id]=1;
		//		cerr<<cur[j].id<<" "<<cur[j+1].id<<endl;
				++tot,q[tot]=Q(cur[j]->y,cur[j+1]->y,tot);
				q[tot].go[1].pb(cur[j]->id),q[tot].go[0].pb(cur[j+1]->id);
			}
			else
			{	del[cur[j]->id]=1,++tot,q[tot]=Q(fa[cur[j]->x],cur[j]->y,tot);
				q[tot].p=cur[j]->p; q[tot].go[0].push_back(cur[j]->id);
			}
		}
		cur.clear();
	//	fgx;for(rint j=1;j<=tot;j++)if(!del[j])cerr<<q[j].x<<" "<<q[j].y<<" "<<q[j].p<<endl;fgx; 
	}
	for(rint i=tot;i>m;i--)
	{	for(rint j=0;j<q[i].go[0].size();j++) q[q[i].go[0][j]].p=q[i].p;
		for(rint j=0;j<q[i].go[1].size();j++) q[q[i].go[1][j]].p=q[i].p^1;
	}
//	debug(q[1].p);debug(q[1].x);debug(q[1].y);
	for(rint i=1;i<=m;i++)
	if(!q[i].p) printf("%d %d\n",q[i].x,q[i].y);
	else printf("%d %d\n",q[i].y,q[i].x);
	return 0;
}


Measured memory_bytes: 82432
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pli = pair<ll, int>;
using Graph = vector<vector<bool>>;
const int MOD = 1e9 + 7;

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

    int N, K;
    cin >> N >> K;
    vector<pii> xy(N);
    for (int i = 0; i < N; ++i)
        cin >> xy[i].first >> xy[i].second;
    sort(xy.begin(), xy.end());

    ll ans = LLONG_MAX;
    for (int l = 0; l < N; ++l) {
        for (int t = l; t < N; ++t) {
            for (int b = l; b < N; ++b) {
                if (xy[t].second < xy[b].second)
                    continue;
                int cnt = 0, minr = INT_MAX;
                for (int r = l; r < N; ++r) {
                    if (xy[r].second >= xy[b].second && xy[r].second <= xy[t].second)
                        cnt++;
                    minr = xy[r].first;
                    if (cnt >= K)
                        break;
                }
                if (cnt >= K)
                    ans = min(ans, (ll)(minr - xy[l].first) * (xy[t].second - xy[b].second));
            }
        }
    }

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


Measured memory_bytes: 256
import sys
from copy import deepcopy
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり


N,x = MI()
A = LI()
B = deepcopy(A)
A += A

ans = sum(B)
for k in range(1,N+1):  # 魔法を k 回唱える
    for i in range(N):
        B[i] = min(B[i],A[N+i-k])
    ans = min(ans,sum(B)+k*x)

print(ans)


Measured memory_bytes: 69416
#include<stdio.h>
#define N -2000000001

int main(){
  int i,n;
  int A[251];

  scanf("%d",&n);
  for(i=0;i<=n;i++){
    A[i]=N;
  }


  for(i=1;i<=n;i++){
    scanf("%d",&A[i]);}

  for(i=1;i<=n;i++){
    printf("node %d: key = %d, ",i,A[i] );

    if(A[i/2]!=N){
      printf("parent key = %d, ",A[i/2] );}

    if(i*2<=n&&A[i*2]!=N){
      printf("left key = %d, ",A[i*2] );}

    if(i*2+1<=n&&A[i*2+1]!=N){
      printf("right key = %d, ",A[i*2+1] );}

    printf("\n");
  }
  return 0;
}

Measured memory_bytes: 600
import sys
input = sys.stdin.readline

def divisors(n):
    i = 1
    table = set()
    while i * i <= n:
        if not n % i:
            table.add(i)
            table.add(n//i)
        i += 1
    table = list(table)
    return table

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

D = divisors(A[0]) + divisors(A[1])
D.sort(reverse=True)
for d in D:
    cnt = 0
    for a in A:
        if a%d:
            cnt += 1
    if cnt <= 1:
        print(d)
        exit()



Measured memory_bytes: 84768
#include <iostream>
#include <string>
#include <functional>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <math.h>
#include <iomanip>
#include <map>

using namespace std;
using ll = long long;

int main()
{
	string s;
	cin >> s;
	int cnt = 0;
	for (char c : s)
	{
		if (c == 'x')
			cnt++;
	}

	if (cnt <= 7)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define FOR(i,a,b) for (register int i=(a);i<=(b);i++)
#define For(i,a,b) for (register int i=(a);i>=(b);i--)
#define mem(i,j) memset(i,j,sizeof(i))
#define pb push_back
using namespace std;
typedef long long ll;
int a,b,c;
int read()
{
	int x=0,f=1;
	char c=getchar();
	while (c<'0'||c>'9') {if (c=='-') f=-1;c=getchar();}
	while (c>='0'&&c<='9') {x=(x<<1)+(x<<3)+c-'0';c=getchar();}
	return f*x;
}
int main()
{
	a=read(),b=read(),c=read();
	c-=min(c,a-b);
	printf("%d\n",c);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define eb emplace_back
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}
int const INF = 1001001001;
ll const MOD = 1000000007;


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

int N;
cin >> N;
vi a(N);
rep(i,N) cin >> a[i];
sort(all(a),greater<int>());

int A=0,B=0;

rep(i,N) {
    if(i%2 == 0) A += a[i];
    else B += a[i];
}

cout << A-B << endl;

return 0;
}

Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <iostream>
#include <fstream>

#include "bits/stdc++.h"

#define REP(i,x,y) for(int i=(x);i<(y);i++)
#define RREP(i,x,y) for(int i=(y)-1;i>=(x);i--)
#define all(x) (x).begin(),(x).end()
//#define int long long

using namespace std;

// conversion
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

#define dump(x)  cerr << #x << " = " << (x) << endl
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl

typedef long long ll;

const ll MOD = 1e9 + 7;

class ERemOfSumIsNum {
public:
	void solve(std::istream& in, std::ostream& out) {
	    ll N, K;
	    in >> N >> K;
	    vector<ll> A(N);
	    REP(i,0,N) in >> A[i];

	    unordered_map<ll, vector<ll>> cnt; // key: (a - b) % K, value: vector<index>
	    ll sum = 0;
	    cnt[1].push_back(-1);
	    REP(i,0, N) {
	        sum += A[i];
	        ll key = (sum%K - i%K + K) % K;
	        cnt[key].push_back(i);
	    }
	    ll answer = 0;
	    for (auto& p : cnt) {
	        auto& indices = p.second;
	        if (indices.size() == 1) continue;
	        sort(all(indices));
	        REP(i,0,indices.size()) {
	            ll length = distance(indices.begin(), lower_bound(all(indices), indices[i]+K)) - i;
	            answer += length - 1;
	        }
	    }
	    out << answer << "\n";
	}
};


signed main() {
	ERemOfSumIsNum solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 19400
#include<bits/stdc++.h>
using namespace std;
 
typedef long long ll;
#define rep(i,a,b) for (int i = a; i < b; i++)
#define repn(i,a,b) for (int i = a; i >=b ;i--)
#define MOD 1000000007
int arr[200010]; 
void solve(){
   int n,tmp;cin>>n;
   rep(i,1,n){
       cin>>tmp;
       arr[tmp]++;
   }
   rep(i,1,n+1)cout<<arr[i]<<"\n";

 
 
return ;
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
   int t=1;
   //cin>>t;
   rep(i,0,t){
     solve();
  }
return 0;
}

Measured memory_bytes: 4292
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main() { 
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  ll n,a,b,sum=0;
  cin>>n;
  while(n--) { 
    cin>>a>>b;
    sum+=(b-a)+1;
    }
  cout<<sum<<endl;
  
  return 0;
}


Measured memory_bytes: 3604
import java.util.Scanner;

public class Main {

	public static final int BIG_NUM = 2000000000;
	public static final int MOD = 1000000007;

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		int W = sc.nextInt();

		int dp[] = new int[W+1];
		for(int i = 0; i < dp.length; i++){
			dp[i] = -1;
		}
		dp[0] = 0;

		int value,weight;

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

			value = sc.nextInt();
			weight = sc.nextInt();

			for(int i = 0; i+weight <= W; i++){
				if(dp[i] == -1)continue;
				dp[i+weight] = Math.max(dp[i+weight],dp[i]+value);
			}
		}

		int ans = 0;
		for(int i = 1; i <= W; i++){
			ans = Math.max(ans, dp[i]);
		}

		System.out.println(ans);
	}
}



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

#define rep(i, N) for (int i = 0; i < (N); i++)
#define all(a) (a).begin(), (a).end()
#define pb push_back

using ll = long long;
using i_i = tuple<int, int>;

ll MOD = 1e9 + 7;

ll F[1000];
ll C[1000][1000];
ll dp[100001];

int main() {
    F[0] = 1;
    for (int x = 1; x < 1000; x++)
        F[x] = F[x - 1] * x % MOD;
    rep(x, 1000) {
        C[x][0] = 1;
        for (int y = 1; y <= x; y++)
            C[x][y] = (C[x - 1][y - 1] + C[x - 1][y]) % MOD;
    }
    int N, X;
    cin >> N >> X;
    vector<int> a(N);
    rep(i, N) cin >> a[i];
    sort(all(a));
    ll ans = 0;
    int n = 0;
    rep(i, N) if (a[i] > X) n++;
    dp[X] = C[N][n] * F[n] % MOD;
    for (int x = X; x >= 0; x--) {
        int n = 0;
        rep(i, N) if (a[i] <= x) n++;
        if (n == 0) {
            ans = (ans + dp[x] * x) % MOD;
            continue;
        }
        rep(i, n) {
            int y = x % a[i];
            int m = upper_bound(all(a), y) - a.begin();
            dp[y] = (dp[y] + dp[x] * C[n - 1][n - 1 - m] % MOD * F[n - 1 - m]) % MOD;
        }
    }
    cout << ans << endl;
}


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

#define x first
#define y second
#define ndl '\n'
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define up_b upper_bound
#define low_b lower_bound
#define sz(x) (int)x.size()
#define bit __builtin_popcount
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()

using namespace std;
using namespace __gnu_pbds;

template<typename T> using indexed_set = tree <T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<int, ull> piu;
typedef vector<vector<int>> matrix;

const ll INF = 1e18 + 123;
const ld EPS = 1e-9;
const int inf = 1e9 + 123;
const int MOD = 1e9 + 7;
const int N = 3e3 + 13;
const int M = 1e6 + 123;
const double pi = acos(-1.0);
const int dx[] = {0, 0, 1, -1};
const int dy[] = {1, -1, 0, 0};

int dp[N][N];

int main(){
    #ifdef KAZAKH
        freopen("input.txt", "r", stdin);
    #endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n, m;
    string s, t;
    cin >> s >> t;
    n = sz(s);
    m = sz(t);
    for (int i = 1; i <= n; i++){
        for (int j = 1; j <= m; j++){
            if (s[i-1] == t[j-1]){
                dp[i][j] = dp[i-1][j-1]+1;
            }
            else{
                dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
            }
        }
    }
    string ans = "";
    while (n && m){
        if (s[n-1] == t[m-1]){
            ans += s[n-1];
            n--;
            m--;
        }
        else if (dp[n][m] == dp[n-1][m]) n--;
        else m--;
    }
    reverse(all(ans));
    cout << ans;
    return 0;
}


Measured memory_bytes: 35584
n = int(input())
h = list(map(int, input().split()))
res = [0] * n

res[1] = abs(h[1] - h[0])
for i in range(2, n):
    res[i] = min(res[i-2] + abs(h[i] - h[i-2]),
                 res[i-1] + abs(h[i] - h[i-1]))

print(res[-1])


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

using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod= int(1e9)+7;
using P = pair<ll,ll>;
using ld=long double;

int main(){
    ll r;cin>>r;
    cout <<r*r<<endl;
    return 0;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**7)

readline = sys.stdin.buffer.readline
def readstr():return readline().rstrip().decode()
def readstrs():return list(readline().decode().split())
def readint():return int(readline())
def readints():return list(map(int,readline().split()))
def printrows(x):print('\n'.join(map(str,x)))
def printline(x):print(' '.join(map(str,x)))

import math

n = readint()
a = readints()

flag = 0

node = [1]
for i in range(n):
    if a[i]>node[-1]:
        flag = 1
        break
    else:
        node.append((node[-1]-a[i])*2)

if a[-1]>node[-1]:
    flag = 1

if flag:
    print(-1)
    exit()

node[n] = a[n]

for i in range(n-1,-1,-1):
    if node[i]>a[i]+node[i+1]:
        node[i] = a[i] + node[i+1]
    else:
        break
print(sum(node))

Measured memory_bytes: 708816
#include<vector>
#include<list>
#include<algorithm>
#include<iostream>
#include<string>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;
int main(){
  int i;
  int ln,jsm,ism;
  string s;
  while(cin>>s){
    ln=s.length();
    jsm=0;
    ism=0;
    for(i=0;i<ln-1;i++){
      if(s[i+1]=='O'&&s[i+2]=='I'){
	if(s[i]=='J')
	  jsm++;
	else if(s[i]=='I')
	  ism++;
      }
    }
    cout<<jsm<<endl<<ism<<endl;
  }
  return 0;
}

Measured memory_bytes: 0
# 二項係数を"やるだけ"にしてくれるライブラリ
MAX = 310000
MOD = 998244353
factrial = [0]*MAX
inverse = [0]*MAX
factrial_inverse = [0]*MAX


# テーブルを作る前処理
def COMinit():
    global factrial, inverse, factrial_inverse
    factrial[0] = 1
    factrial[1] = 1
    inverse[1] = 1
    factrial_inverse[0] = 1
    factrial_inverse[1] = 1
    for i in range(2, MAX):
        factrial[i] = factrial[i-1] * i % MOD
        inverse[i] = MOD - inverse[MOD % i] * (MOD//i) % MOD
        factrial_inverse[i] = factrial_inverse[i-1] * inverse[i] % MOD


# 二項係数計算
def COM(n, k):
    global factrial, inverse, factrial_inverse
    if n < k:
        return 0
    if n < 0 or k < 0:
        return 0
    return factrial[n] * (factrial_inverse[k] * factrial_inverse[n-k] % MOD) % MOD


# 前処理完了
COMinit()
N, A, B, K = map(int, input().split())
ans = 0
for a in range(N+1):
    # 整数bが存在するならansに加算する
    if (K - A*a) % B == 0:
        b = (K - A*a) // B
        ans += COM(N, a) * COM(N, b) % MOD

print(ans % MOD)


Measured memory_bytes: 41768
#include<iostream>
#include<vector>
#include<algorithm>
#include<complex>
#include<string>
#include<string.h>
using namespace std;
typedef long long int llint;
#define rep(i,n) for(int i=0;i<n;i++)

int main() {
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	a += b;
	c += d;
	if (a < c) {
		cout << "Right" << endl;
	}
	if (a == c) {
		cout << "Balanced" << endl;
	}
	if (a > c) {
		cout << "Left" << endl;
	}
	return 0;
}

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

void bubble(int*a,char*c,int n);
void selection(int*a,char*c,int n);

int main(){
	int n;
	cin>>n;
	char suit[n],bs[n];
	int num[n],bn[n],j;
	char dou[9][4];//各数字のスーツの順番を記録
	memset(dou,'n',sizeof(dou));
	for(int i=0;i<n;i++){
		cin>>suit[i]>>num[i];
		for(j=0;dou[num[i]-1][j]!='n';j++);
		dou[num[i]-1][j]=suit[i];
		bs[i]=suit[i];
		bn[i]=num[i];
	}
	
	bubble(bn,bs,n);//バブルソート
	cout<<bs[0]<<bn[0];
	for(int i=1;i<n;i++){
		cout<<' '<<bs[i]<<bn[i];
	}
	cout<<endl;
	cout<<"Stable"<<endl;
	
	selection(num,suit,n);
	cout<<suit[0]<<num[0];
	for(int i=1;i<n;i++){
		cout<<' '<<suit[i]<<num[i];
	}
	cout<<endl;
	for(int i=1;i<n;i++){//安定か判別
		if(bs[i]!=suit[i]){
			cout<<"Not stable"<<endl;
			goto No;
		}
	}
	cout<<"Stable"<<endl;
	No:
	return 0;
}

void bubble(int*a,char*c,int n){
	for(int i=0;i<n;i++){
		for(int j=n-1;j>i;j--){
			if(a[j]<a[j-1]){
				int temp=a[j]; a[j]=a[j-1]; a[j-1]=temp;
				char cop=c[j]; c[j]=c[j-1]; c[j-1]=cop;
			}
		}
	}
}

void selection(int*a,char*c,int n){
	for(int i=0;i<n;i++){
		int min=i;
		for(int j=i;j<n;j++){
			if(a[min]>a[j]) min=j;
		}
		if(min!=i){
			int temp=a[i]; a[i]=a[min]; a[min]=temp;
			char cop=c[i]; c[i]=c[min]; c[min]=cop;
		}
	}
}

Measured memory_bytes: 1164
import java.util.*;

class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    Set<String> prizeTypes = new HashSet<>();
    for (int i = 0; i < N; i++) {
      prizeTypes.add(sc.next()); 
    }
    System.out.println(prizeTypes.size());
  }
}


Measured memory_bytes: 77996
package main

import (
    "fmt"
    "sort"
)

type As [][]int

func (a As) Len() int {
    return len(a)
}

func (a As) Swap(i, j int) {
    a[i], a[j] = a[j], a[i]
}

func (a As) Less(i, j int) bool {
    return a[i][1] < a[j][1]
}

func main() {
    var n int
    fmt.Scan(&n)
    ps := make([][]int, n)
    pc := make([]int, n)
    for i := 0; i < n-1; i++ {
        var a, b int
        fmt.Scan(&a, &b)
        a--
        b--
        ps[a] = append(ps[a], b)
        ps[b] = append(ps[b], a)
        pc[a]++
        pc[b]++
    }

    cs := make([]int, n)
    for i := 0; i < n; i++ {
        fmt.Scan(&cs[i])
    }
    sort.Sort(sort.IntSlice(cs))

    var dsum int
    ds := make([]int, n)

    var cnt int
    for cnt < n-1 {
        pcs := make(As, 0, n-cnt)
        for i, v := range pc {
            if v > 0 {
                pcs = append(pcs, []int{i, v})
            }
        }
        sort.Sort(pcs)
        val := pcs[0][1]
        for i := 0; pcs[i][1] == val && cnt < n-1; i++ {
            idx := pcs[i][0]
            ds[idx] = cs[cnt]
            dsum += cs[cnt]
            cnt++
            for _, v := range ps[idx] {
                pc[idx]--
                pc[v]--
                if pc[v] == 0 {
                    ds[v] = cs[cnt]
                    cnt++
                }
            }
        }
    }

    fmt.Println(dsum)
    for i := range ds {
        if i == len(ds)-1 {
            fmt.Println(ds[i])
        } else {
            fmt.Printf("%d ", ds[i])
        }
    }
}


Measured memory_bytes: 5632
#include <stdio.h>

int number(char c[1]){
    switch(c[0]){
    case 'A':
        return 0;
    case 'B':
        return 1;
    case 'C':
        return 2;
    }
    return 3;
}

int main(void){
    int cup[3] = {0};
    char c[3], c1[1], c2[1];
    int tmp;
    int i;
    cup[0] = 1;
    c[0] = 'A';
    c[1] = 'B';
    c[2] = 'C';

    while(scanf("%c,%c", c1, c2) != EOF){
        tmp = cup[number(c1)];
        cup[number(c1)] = cup[number(c2)];
        cup[number(c2)] = tmp;
    }

    for(i = 0; i < 3; i++){
        if(cup[i] == 1){
            printf("%c\n", c[i]);
            break;
        }
    }

    return 0;
}

Measured memory_bytes: 544
/*░░░░░░░▄▄▄▀▀▀▄▄███▄
░░░░░▄▀▀░░░░░░░▐░▀██▌
░░░▄▀░░░░▄▄███░▌▀▀░▀█
░░▄█░░▄▀▀▒▒▒▒▒▄▐░░░░█▌
░▐█▀▄▀▄▄▄▄▀▀▀▀▌░░░░░▐█▄
░▌▄▄▀▀░░░░░░░░▌░░░░▄███████▄
░░░░░░░░░░░░░▐░░░░▐███████████▄
░░░░░le░░░░░░░▐░░░░▐█████████████▄
░░░░toucan░░░░░░▀▄░░░▐██████████████▄
░░░░░░has░░░░░░░░▀▄▄████████████████▄
░░░░░arrived░░░░░░░░░░░░█▀██████*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const int MAXN = 200 * 1000 + 7;
char s[MAXN];
int main()
{
#ifdef LOCAL
	freopen("input.txt", "r", stdin);
#endif
	scanf("%s", s);
	int n = strlen(s);
	vector<char> st;
	for (int i = 0; i < n; i++)
	{
		if (s[i] == 'T' && !st.empty() && st.back() == 'S')
		{
			st.pop_back();
		}
		else
		{
			st.push_back(s[i]);
		}
	}
	printf("%d\n", (int)st.size());
}


Measured memory_bytes: 1148
import sys
input = sys.stdin.readline

N = int(input())
A = [int(v) for v in input().split()]
B = [int(v) for v in input().split()]
s = [0] * (N + 1)

for i in range(N):
    if A[i] <= B[i]:
        s[i] += A[i]
        B[i] -= A[i]
        A[i] = 0
    else:
        s[i] += B[i]
        A[i] -= B[i]
        B[i] = 0
        
    if A[i + 1] <= B[i]:
        s[i + 1] += A[i + 1]
        B[i] -= A[i + 1]
        A[i + 1] = 0
    else:
        s[i + 1] += B[i]
        A[i + 1] -= B[i]
        B[i] = 0
        
print(sum(s))


Measured memory_bytes: 19376
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
const char* solve() {
    int N, A[3][3];
    vector<vector<bool>> f(3, vector<bool>(3, false));
    for (auto& v : A) for (auto& i : v) cin >> i;
    cin >> N;
    vector<int> B(N);
    for (auto& x : B) {
        cin >> x;
        for (int i = 0; i < 3; i++) for (int j = 0; j < 3; j++) if (A[i][j] == x) {
            f[i][j] = true;
        }
    }
    for (int i = 0; i < 3; i++) {
        if (all_of(f[i].begin(), f[i].end(), [](bool x) { return x; })) return "Yes";
        int cnt = 0;
        for (int j = 0; j < 3; j++) {
            if (f[j][i]) cnt++;
        }
        if (cnt == 3) return "Yes";
    }
    int cnt1 = 0, cnt2 = 0;
    for (int i = 0; i < 3; i++) {
        if (f[i][i]) cnt1++;
        if (f[i][2 - i]) cnt2++;
    }
    if (cnt1 == 3) return "Yes";
    if (cnt2 == 3) return "Yes";
    return "No";
}
int main() {
    cout << solve() << endl;
}

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

int main() {
  int n, k; cin >> n >> k;
  vector<int> snk(n);
  for (int i = 0; i < k; i++) {
    int d; cin >> d;
    for (int i = 0; i < d; i++) {
      int a; cin >> a;
      snk.at(~-a)++;
    }
  }
  int ans = 0;
  for (auto e : snk) ans += e == 0;
  cout << ans << endl;
}

Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define lef(x) (x<<1)
#define rig(x) (lef(x)+1)
#define int long long
const ll MOD=1e9+7LL;
const int N=100100;

int32_t main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    ll x,y,tot=0;
    cin>>x>>y;
    if(x==1 && y==1)
    	tot=400000;
    if(x<4)
    {
	    x=4-x;
	    tot+=(x)*100000;
    }

    if(y<4)
    {
	    y=4-y;
	    tot+=(y)*100000;
    }
    cout<<tot<<"\n";
    return 0;   
}

Measured memory_bytes: 256
#include <stdio.h>
#define PI 3.14159265358979

int main(void)
{
    double r, area, circum;

    scanf("%lf", &r);

    area = r * r * PI;
    circum = 2 * r * PI;

    printf("%lf %lf\n", area, circum);

    return 0;
}


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

#define rep(i, a, b) for (int i = a; i < (int)(b); ++i)
#define rrep(i, a, b) for (int i = b - 1; i >= (int)(a); --i)

using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;

constexpr int MOD = 1000000007;

int bfs(vvi& g, int i) {
    queue<int> q;
    vi dp(g.size(), INT_MAX);
    vector<bool> seen(g.size(), false);
    int maxv = 0;

    q.push(i);
    dp[i] = 0;
    seen[i] = true;

    while (!q.empty()) {
        int v = q.front();
        q.pop();

        for (auto u: g[v]) {
            if (!seen[u]) {
                dp[u] = dp[v] + 1;
                q.push(u);
                seen[u] = true;
                maxv = max(maxv, dp[u]);
            }
        }
    }
    return maxv;
}

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

    int h, w;
    cin >> h >> w;

    vvi maze(h, vi(w, 0));
    map<int, int> m_to_v;
    int v_num = 0;

    rep(i, 0, h) {
        rep(j, 0, w) {
            char c;
            cin >> c;
            if (c == '.') {
                maze[i][j] = 1;
                m_to_v[i * w + j] = v_num++;
            }
        }
    }

    vvi g(v_num);
    rep(i, 0, h) {
        rep(j, 0, w) {
            if (maze[i][j] == 0) { continue; }
            int curr_node = m_to_v[i * w + j];
            if (i < h - 1 && maze[i + 1][j] == 1) {
                int next_node = m_to_v[(i + 1) * w + j];
                g[curr_node].push_back(next_node);
            }
            if (i > 0 && maze[i - 1][j] == 1) {
                int next_node = m_to_v[(i - 1) * w + j];
                g[curr_node].push_back(next_node);
            }
            if (j < w - 1 && maze[i][j + 1] == 1) {
                int next_node = m_to_v[i * w + j + 1];
                g[curr_node].push_back(next_node);
            }
            if (j > 0 && maze[i][j - 1] == 1) {
                int next_node = m_to_v[i * w + j - 1];
                g[curr_node].push_back(next_node);
            }
        }
    }
    int ans = 0;
    rep(i, 0, v_num) {
        ans = max(ans, bfs(g, i));
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc *bufio.Scanner = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	val, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return val
}

func nextLine() string {
	sc.Scan()
	return sc.Text()
}
func main() {
	sc.Split(bufio.ScanWords)
	//
	H, W := nextInt(), nextInt()
	G := make([]string, H)
	for i := range G {
		G[i] = nextLine()
	}
	res := make([][]byte, 2*H)
	for i := 0; i < 2*H; i++ {
		res[i] = make([]byte, W)
		for j := 0; j < W; j++ {
			res[i][j] = G[(i)/2][j]
		}
	}
	for i := range res {
		fmt.Println(string(res[i]))
	}
}


Measured memory_bytes: 768
q=int(input())

#prime table
prime=[0 for i in range(10**5+5)]
for i in range(2,10**5+5):
  j=1
  if not prime[i]:
    while j*i<=10**5+4:
      prime[j*i]=i
      j+=1

like2017=[0 for i in range(10**5+5)]
for i in range(3,10**5+5,2):
  j=(i+1)//2
  if i==prime[i] and j==prime[j]:
    like2017[i]=1

like2017sum=[0 for i in range(10**5+5)]
for i in range(10**5+4):
  like2017sum[i+1]=like2017sum[i]+like2017[i+1]
#print(like2017[0:54])
#print(like2017sum[0:80])
for i in range(q):
  l,r=map(int,input().split())
  if like2017[l]==1:
    alpha=1
  else:
    alpha=0
  print(like2017sum[r]-like2017sum[l]+alpha)


Measured memory_bytes: 85636
#include <iostream>
#include <fstream>
#include <string>
#include <cmath>
#include <vector>
#include <algorithm>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <cctype>
#include <bits/stdc++.h>
#include <queue>

using namespace std;
// for loop
#define F(i, L, R) for(long i = L; i < R; i++)
#define FE(i, L, R) for(long i = L; i <= R; i++)
// for (reversed)
#define FR(i, L, R) for(long i = L; i > R; i--)
#define FRE(i, L, R) for(long i = L; i >= R; i--)

// data types
#define Int long
#define ul unsigned long
#define ll long long
#define ull unsigned long long
#define ui unsigned int
#define us unsigned shoft

// vectors
typedef vector<int> vi;
typedef vector<long> vl;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
#define ALL(c) (c).begin(),(c).end()
#define last(vec) vec.size()-1
#define lastEle(vec) vec[last(vec)]
#define pb push_back
#define InputV(a, n) F(i,0,n){long l; cin >> l; a.pb(l);}

// debug
#define DBG(vari) cerr<<#vari<<" = "<<(vari)<<endl;
#define printA(a, L, R) FE(i, L, R) cout << a[i] << (i==R?'\n':' ')
#define printAF(a, L) printA(a, 0, L-1)
#define printV(a) printA(a, 0, a.size()-1)

// utils
#define char2int(c) (c-'0')
#define bit(x, i) (x&(1<<i))
#define space ' '
#define PI 3.14159265358979323

#define TST 0
int main() {
#if TST==1
    ifstream in ("input.txt");
    cin.rdbuf(in.rdbuf());
#endif
    map<string, bool> m;
    int n;
    cin >> n;
    string str;
    F(i, 0, n){
        cin >> str;
        m[str] = true;
    }
    cout << m.size() << endl;
#if TST==1
#endif
}


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

string abacus(int x){
  string res;
  if(x<5)res += "* =";
  else res += " *=";

  if(x%5 == 0)res += " ****";
  if(x%5 == 1)res += "* ***";
  if(x%5 == 2)res += "** **";
  if(x%5 == 3)res += "*** *";
  if(x%5 == 4)res += "**** ";
  return res;
}
int main(){
  int x;
  bool f = false;

  while(cin>>x){
    if(f)cout << endl;
    f = true;
    string ans[5];
    for(int i=4;i>=0;i--){
      ans[i] = abacus(x%10);
      x /= 10;
    }
 
    for(int i=0;i<8;i++){
      for(int j=0;j<5;j++)cout << ans[j][i];
      cout << endl;
    }
  }
}

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

using namespace std;


int main() {
    int base[2];
    for (int i = 0; i < 2; ++i) {
        scanf("%d", &base[i]);
    }

    vector<pair<long, long> > input(base[0]);
    for (int j = 0; j < base[0]; ++j) {
        cin >> input[j].first >> input[j].second;
    }

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

//    for (int k = 0; k < base[0]; ++k) {
//        cout << input[k].first << " " << input[k].second << "\n";
//    }

    long ans = 0;
    int requried = base[1];
    for (int k = 0; k < base[0]; ++k) {
        if (input[k].second >= requried) {
            ans += input[k].first * requried;
            cout << ans;
            return 0;
        } else {
            ans += input[k].first * input[k].second;
            requried -= input[k].second;
        }
    }

}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std ;
long long int   input[102][2];

int main()
{
  int n,w;
  cin>>n>>w ;
   int r=w+2 ;
   int c=n+2 ;
   long long  int *arr[r]; 
   for (int i=0; i<r; i++) 
      arr[i] = (long long int *)malloc(c * sizeof(long long int)); 
   
  for(int i=0;i<w+2 ;i++)
   {
     for(int j=0;j<n+2 ;j++)
     {
       arr[i][j]=0;
     }
   }

  for(int i=0;i<w+2 ;i++)
   {
     arr[i][0] =0;
   }

  for(int i=0;i<n+2 ;i++)
   {
     arr[0][i] =0;
   }
   for(int i=1;i<=n;i++)
   cin>>input[i][0]>>input[i][1]  ;
 
  
  
     for(int j=1;j<n+1 ;j++)
     {
       for(int i=1;i<w+1 ;i++)
     {
        if(i-input[j][0]>=0 )
            arr[i][j]=arr[i-input[j][0]][j-1]+input[j][1] ;

        arr[i][j]=max(arr[i][j] ,arr[i][j-1]) ;     
       
     }
   }


   cout<<arr[w][n]<<endl;;


  return 0;
}











Measured memory_bytes: 82304
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
const long long MOD = 1e18 ;
const long long INF = 1e18;
const int INT_INF   = 1e9 + 8;
int GCD(int a, int b){return b == 0 ? a : GCD(b, a % b);}
long long fast_exp(long long base, long long exp, long long mod = MOD, long long tot = 1) {
    for(;exp > 0; exp >>= 1, base = base * base % mod) if((exp & 1) == 1) tot = tot * base % mod;
    return tot;
}
long long slow_mult(long long base, long long exp, long long mod = MOD, long long tot = 0) {
    for(;exp > 0; exp >>= 1, base = base * 2 % mod) if((exp & 1) == 1) tot = (tot + base) % mod;
    return tot;
}
struct chash {
    static uint64_t splitmix64(uint64_t x) {x += 0x8e3779b97f4a7c15; x = (x ^ (x >> 30)) * 0xbf54876d1ce4e5b9; x = (x ^ (x >> 27)) * 0x94d049bb133111eb; return x ^ (x >> 31);}
    size_t operator()(uint64_t x) const { static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count(); return splitmix64(x + FIXED_RANDOM);}
    size_t operator()(pair<uint64_t,uint64_t> x) const { static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count(); return splitmix64(x.first + FIXED_RANDOM)^(splitmix64(x.second + FIXED_RANDOM) >> 1);}
};

long long arr[200005], psa[200005];

int main(){

    cin.sync_with_stdio(0); cin.tie(0); cout.tie(0);

    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    int n, k; cin >> n >> k;

    for(int i = 0; i < n; ++i){
        cin >> arr[i];
        arr[i] %= k;
        psa[i + 1] = (arr[i] + psa[i] - 1 + k) % k;
    }

    map<long long, int> freq;

    long long ans = 0;

    for(int i = 0; i <= n; ++i){
        if(k <= i) --freq[psa[i - k]];
        if(freq.count(psa[i]) == 1) ans += freq[psa[i]];
        ++freq[psa[i]];
    }

    cout << ans;

    return 0;

}


Measured memory_bytes: 15872
#!/usr/bin/env python
import math

n = int(input())
p = [int(i) for i in input().split()]

r = []

for i in range(1, n + 1):
	if i != p[i - 1]:
		r.append(p[i - 1])

if len(r) <= 2:
	print("YES")
else:
	print("NO")


Measured memory_bytes: 3060
#include<bits/stdc++.h>
typedef long long ll;
#define INF 100000000
#define MOD 100000007
int dx[4]={1,0,-1,0},dy[4]={0,-1,0,1};
using namespace std;
int main(void){
int n;
cin>>n;
int v[n],c[n];
for(int i=0;i<n;i++){
   cin>>v[i];
}
for(int i=0;i<n;i++){
   cin>>c[i];
}
int ans=0;
for(int i=0;i<n;i++){
   if(v[i]-c[i]>0){
      ans+=v[i]-c[i];
   }
}
cout<<ans<<endl;
   return 0;    
}

Measured memory_bytes: 256
import math

x = input()
x = x.split()
n = int(x[0])
d = int(x[1])


ans = 0
points = []

for i in range(n):
  x = input()
  x = x.split()
  points.append(x)

for i in range(len(points)):
  for j in range(i+1,len(points)):
    dis = 0
    for k in range(d):
      sa = int(points[i][k])-int(points[j][k])
      dis += sa*sa
    
    disf = math.sqrt(dis)
    if disf.is_integer() == True:
      ans += 1

      
print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using  namespace  std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define faster  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define sq(x)   (x)*(x)
#define PI      acos(-1.0)
#define all(x) x.begin(),x.end()
#define nl      '\n'
typedef long long int ll;
typedef unsigned long long int  llu;

int main()
{
	faster
	ll n;
	cin>>n;
	ll a[n],sum=0,i;
	for(i=0;i<n;i++)
	{
		cin>>a[i];
	}
	for(i=0;i<n-1;i++)
	{
		if(a[i]>a[i+1])
		{
			sum+=a[i]-a[i+1];
			a[i+1]=a[i];
		}
	}
	cout<<sum<<nl;
	return 0;
}

Measured memory_bytes: 5172
from itertools import combinations, product
n=int(input())
s=[["a" for _ in range(n)] for _ in range(n)]
for i in range(n):
  s[i]=list(input())

res=0
for a in range(n):
  for i,j in combinations(range(n),2):
    if(s[(i+a)%n][j%n]!=s[(j+a)%n][i%n]):
      break
  else:
    res+=1

print(res*n)


Measured memory_bytes: 46812
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define REPS(i,n) FOR(i,1,n+1)
#define RFOR(i,l,r) for(long long i=(l);i>=(r);--i)
#define RREP(i,n) RFOR(i,N-1,0)
#define RREPS(i,n) RFOR(i,N,1)
#define int long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
const int INF=1e18;
const int MOD=1e9+7;

signed main(){
    string S;cin>>S;
    int N=S.size();
    int sc=0;
    int ans=N;
    REP(i,N){
        if(S[i]=='S')sc++;
        else{
            if(sc>0){
                sc--;
                ans-=2;
            }
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3704
import sys
from collections import Counter
Input = sys.stdin.readline

n = int(Input())
v = list(map(int, Input().split()))
mi = float("inf")
count1 = 0
count2 = 0

v1 = v[0::2]
v1_count = Counter(v1)
v1_count = v1_count.most_common()
count1 += len(v1) - v1_count[0][1]

v2 = v[1::2]
v2_count = Counter(v2)
v2_count = v2_count.most_common()
count2 += len(v2) - v2_count[0][1]

if v1_count[0][0] != v2_count[0][0]:
    mi = count1 + count2
else:
    lv2 = len(v2)
    for k, i in v2_count[1:]:
        result = count1 + lv2 - i
        if mi > result:
            mi = result
    else:
        if mi > count1 + lv2:
            mi = count1 + lv2

    lv1 = len(v1)
    for k, i in v1_count[1:]:
        result = count2 + lv1 - i
        if mi > result:
            mi = result
    else:
        if mi > count2 + lv1:
            mi = count2 + lv1

print(mi)

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

using namespace std;

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

int main(){
    string s;
    cin>>s;
  	int n=s.size();

    long dp1[100002],dp2[100002];
    
    dp1[0]=1;//0,0で確定
    dp2[0]=2;//0,1 と 1,0
    
    rep(k,n){
        if(k==0) continue;

        if(s[k]=='0'){
            //確定していたほうから1,1以外の3,わからないほうからはない
            dp1[k]=(dp1[k-1]*3)%mod;
            //まだわからないのは0,0のときのみ
            dp2[k]=dp2[k-1];
        }else if(s[k]=='1'){
            //わからないほうから0,0の場合がくる
            dp1[k]=((dp1[k-1]*3)%mod+dp2[k-1])%mod;
            //わからない
            dp2[k]=(dp2[k-1]*2)%mod;
        }
    }
	printf("%ld",(dp1[n-1]+dp2[n-1])%mod);
}


Measured memory_bytes: 2048
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastScanner in = new FastScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskA {
        public void solve(int testNumber, FastScanner in, PrintWriter out) {
            out.println((in.nextInt() + in.nextInt()) % 24);
        }

    }

    static class FastScanner {
        private InputStream in;
        private byte[] buffer = new byte[1024];
        private int bufPointer;
        private int bufLength;

        public FastScanner(InputStream in) {
            this.in = in;
        }

        private int readByte() {
            if (bufPointer >= bufLength) {
                if (bufLength == -1)
                    throw new InputMismatchException();

                bufPointer = 0;
                try {
                    bufLength = in.read(buffer);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }

                if (bufLength <= 0)
                    return -1;
            }
            return buffer[bufPointer++];
        }

        private static boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public long nextLong() {
            long n = 0;

            int b = readByte();
            while (isSpaceChar(b))
                b = readByte();

            boolean minus = (b == '-');
            if (minus)
                b = readByte();

            while (b >= '0' && b <= '9') {
                n *= 10;
                n += b - '0';
                b = readByte();
            }

            if (!isSpaceChar(b))
                throw new NumberFormatException();

            return minus ? -n : n;
        }

        public int nextInt() {
            long n = nextLong();

            if (n < Integer.MIN_VALUE || n > Integer.MAX_VALUE)
                throw new NumberFormatException();

            return (int) n;
        }

    }
}



Measured memory_bytes: 21588
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <math.h>

using namespace std;

int main(void){
    int s;
    cin >> s;
    int cp[1000010];
    int cnt = 0;
    int num = s;
    while(!cp[num]){
        cnt++;
        cp[num]=1;
        
        if(num % 2 == 1){
            num = 3 * num + 1;
        } else {
            num = num / 2;
        }
    }
    cout << cnt + 1 << endl;  
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int H,W,i,j;
  while(1){
    scanf("%d%d",&H,&W);
    if(H==0&&W==0){
      break;
    }
      for(i=0;i<H;i++){
        for(j=0;j<W;j++){
          printf("#");
        }
        printf("\n");
    }
      printf("\n");
  }
  return 0;
}

Measured memory_bytes: 2680
import sys
import math

input = sys.stdin.readline


def main():
    N, M = [int(x) for x in input().split()]

    MOD = 10 ** 9 + 7

    if abs(M - N) >= 2:
        print(0)
        return

    d = math.factorial(N)
    m = math.factorial(M)
    if N == M:
        d *= 2
    print(d * m % MOD)



    
    

if __name__ == '__main__':
    main()



Measured memory_bytes: 5184
#include<stdio.h>
int main()
{
	int a;
	int b;
	int c;
	int d;
	scanf("%d",&a);
	d = a / 3600;
	c = a / 60 - d * 60;
	b = a - d * 3600 - c * 60;
	printf("%d:%d:%d\n",d,c,b);
	return 0;
}

Measured memory_bytes: 1020
package main

import (
	"fmt"
	"strings"
)

func main() {
	var n int
	var x string
	fmt.Scan(&n, &x)

	pc := strings.Count(x, "1")
	pc0 := pc - 1
	pc1 := pc + 1
	v1 := 0
	v0 := 0
	for i := 0; i < n; i++ {
		if x[i] == '0' {
			continue
		}
		k := n - i - 1
		if pc0 > 0 {
			v0 += powMod(2, k, pc0)
			v0 %= pc0
		}
		v1 += powMod(2, k, pc1)
		v1 %= pc1
	}

	for i := 0; i < n; i++ {
		k := n - i - 1
		a := 0
		if x[i] == '0' {
			a = (v1 + powMod(2, k, pc1)) % pc1
		} else {
			if pc0 == 0 {
				fmt.Println(0)
				continue
			}
			a = (v0 - powMod(2, k, pc0))
			a = (a + pc0) % pc0
		}

		cnt := 1
		for a > 0 {
			a = f(a)
			cnt++
		}
		fmt.Println(cnt)
	}
}

func f(n int) int {
	p := popcount(n)
	return n % p
}

func popcount(n int) int {
	cnt := 0
	for n > 0 {
		if n&1 == 1 {
			cnt++
		}
		n >>= 1
	}
	return cnt
}

func powMod(n, k, m int) int {
	if k == 0 {
		return 1
	} else if k%2 == 1 {
		return powMod(n, k-1, m) * n % m
	} else {
		t := powMod(n, k/2, m)
		return t * t % m
	}
}


Measured memory_bytes: 4908