akhauriyash/Code-Regression huggingface dataset:
//#include "IntMod.h"
//typedef IntMod<1000000007> MInt;

//#include "Union_Find.h"

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <algorithm>
#include <functional>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
//#include <unordered_set>
//#include <unordered_map>
#include <iomanip>
#include <sstream>

using namespace std;
#define REP(i,a,n) for(int i = a; i < n; ++i)
#define REPM(i,n,a) for(int i = n - 1; i >= a; --i)
#define EPS 0.0001
#define INF 0x3FFFFFFF
#define INFLL 0x3FFFFFFF3FFFFFFF
#define INFD 1.0e+308
typedef long long LL;
typedef unsigned long long ULL;

class SplitStream {
	typedef basic_ostream<char, char_traits<char> > BaseOst;
	std::ostream& ost_m;
	bool line_is_empty_m;
public:
	SplitStream(std::ostream& ost);
	template <typename T>
	SplitStream& operator<<(T right);
	SplitStream& operator<<(BaseOst& (*right)(BaseOst&));
};
SplitStream::SplitStream(std::ostream& ost) : ost_m(ost), line_is_empty_m(true) {}
template <typename T>
SplitStream& SplitStream::operator<<(T right) {
	if (!line_is_empty_m) ost_m << ' ';
	line_is_empty_m = false;
	ost_m << right;
	return *this;
}
/* std::endl のみ */
SplitStream& SplitStream::operator<<(BaseOst& (*right)(BaseOst&)) {
	ost_m << '\n';
	ost_m.flush();
	line_is_empty_m = true;
	return *this;
}
SplitStream Scout(cout);

template <typename T, int Begin, int End>
class OffsetArray {
	T arr_m[End - Begin];
public:
	OffsetArray();

	T& operator[](int index);
	T operator[](int index) const;
};
template<typename T, int Begin, int End>
OffsetArray<T, Begin, End>::OffsetArray() : arr_m() {}
template<typename T, int Begin, int End>
T& OffsetArray<T, Begin, End>::operator[](int index) {
	return arr_m[index - Begin];
}
template<typename T, int Begin, int End>
T OffsetArray<T, Begin, End>::operator[](int index) const {
	return arr_m[index - Begin];
}

LL N, X[500], A[250000];
priority_queue<pair<int, int> > QL;
priority_queue<pair<int, int> > QR;

int solve() {
	cin >> N;
	fill(A, A + N * N, -1);
	REP(i, 0, N) {
		cin >> X[i];
		--X[i];
	}
	REP(i, 0, N) {
		A[X[i]] = i;
		REP(k, 0, i) QL.push(make_pair(-(X[i] - 1), i));
		REP(k, 0, N - i - 1) QR.push(make_pair(X[i] + 1, i));
	}
	REP(i, 0, N * N) {
		if (A[i] == -1) {
			if (QL.empty()) break;
			auto p = QL.top(); QL.pop();
			if (i > -(p.first)) return -1;
			A[i] = p.second;
		}
	}
	REPM(i, N * N, 0) {
		if (A[i] == -1) {
			if (QR.empty()) break;
			auto p = QR.top(); QR.pop();
			if (i < p.first) return -1;
			A[i] = p.second;
		}
	}
	return 0;
}
int main() {
	if (solve() == 0) {
		cout << "Yes" << endl;
		REP(i, 0, N*N) {
			cout << A[i] + 1 << (i == N*N - 1 ? '\n' : ' ');
		}
	} else {
		cout << "No" << endl;
	}
	return 0;
}


Measured memory_bytes: 5236
import java.util.*;


public class Main {
	
	Scanner cin = new Scanner(System.in);
	
	public static void main(String[] args) {
		new Main().run(); 
	}
	
	public void run() {		
		
		/*input*/
		String str = cin.next();
		
		
		/*start
		 * search law*/
		
		int n = str.length();
		boolean twoHeadEqual  = str.charAt(0) == str.charAt(n-1);
		
		if (twoHeadEqual) {
			
			if (n % 2 == 0) {
				System.out.println("First");
			} else {
				System.out.println("Second");
			}
		} else {
			if (n % 2 == 0) {
				System.out.println("Second");
			} else {
				System.out.println("First");
			}
		}
		
		/*finish*/
		
	}
}



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

using namespace __gnu_pbds;
using namespace std;

#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
// order_of_key (val): returns the no. of values less than val
// find_by_order (k): returns the kth largest element.(0-based)

#define ll long long int
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define pi pair<ll,ll>
#define md (ll)(1e9+7)
#define all(X) X.begin(),X.end()

// for pair comparison function(ascending order) use return (i1.ff < i2.ff);

/* string operations :
   str.substr (x,y) : returns a substring str[x],str[x+1],...str[x+y-1]
   str.substr (x) : returns a substring str[x],... end of string
   str.find(qtr) : returns the first occurenece of qtr in str */

const int M=1e6+6;

ll pwr(ll a,ll n,ll m)
{
	ll p=1;
	while(n>0)
	{
		if(n%2==1)
			p=(p*a)%m;
		a=(a*a)%m;
		n=n/2;
	}
	return p;
}

double p,sum = 0.0,dp[M],tmp[M];

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

	ll n,i,j;

	cin >> n;
	dp[0] = 1.0;

	for(i=1;i<=n;++i)
	{
		cin >> p;
		for(j=1;j<=i;++j)
			tmp[j] = (dp[j]*(1.0-p)+dp[j-1]*p);
		for(j=1;j<=i;++j)
		{
			dp[j] = tmp[j];
			// cout << "in proc : " << j << " " << tmp[j] << "\n";
		}
		dp[0] *= (1.0-p);
	}

	for(i=n;i>=1 && 2*i>n;i--)
	{
		sum += dp[i];
		// cout << i << " " << dp[i] << "\n";
	}

	cout << setprecision(12) << sum << "\n";
	return 0;
}

	


Measured memory_bytes: 2304
//大文字->小文字 tolower(),逆はtoupper()
//int a = stoi(c); 文字列をintへ
//途中の出力をそのまま残さない
//数値計算 個数以外はdouble
//map<キー,値> p は辞書。p[キー] = 値
//絶対値 abs()
//入力は空白で切れる
//大文字判定 isupper(文字) 小文字判定 islower(文字)
#include <bits/stdc++.h>
#define rep(i,N) for(int i = 0; i < N;i++)
#define ALL(a) (a).begin(),(a).end()
#define ll long long int
using namespace std;

// Nの桁数
ll dig(ll N) {
	ll dig = 0;
	while (N) {
		dig++;
		N /= 10;
	}
	return dig;
}
// x,yの最大公約数
ll gcd(ll x, ll y) {
	ll r;
	while (x%y) {
		r = x % y;
		x = y;
		y = r;
	}
	return y;
}

int main() {
	int N; cin >> N;
	int ans = 0;
	for (int i = 1; i <= N; i++) {
		if (i % 2 == 0)continue;
		int cnt = 0;
		for (int j = 1; j <= i; j++) {
			if (i%j == 0)cnt++;
		}
		if (cnt == 8) {
			ans++;
		}
	}

	cout << ans << endl;
}

Measured memory_bytes: 256
n,q=map(int, input().split())
queue=[]
for _ in range(n):
    name,time=map(str, input().split())
    queue.insert(0, {"name":name, "time":int(time)})

T=0
while queue != []:
    process=queue.pop()
    if process["time"] <= q:
        T+=process["time"]
        print(process["name"], T, sep=" ")
    else :
        process["time"]-=q
        queue.insert(0, process)
        T+=q


Measured memory_bytes: 20952
#include <iostream>
#include <stdio.h>
#include <algorithm>
using namespace std;
int n, m;

int G[30][30];
int main() {

    for(int i=0; i<30; ++i) for(int j=0; j<30; ++j) G[i][j]=1e9;
    cin >> n >> m;
    for(int i=0; i<m; ++i){
        int a, b, c, d;
        scanf("%d,%d,%d,%d", &a, &b, &c, &d);
        a--; b--;
        G[a][b] = c;
        G[b][a] = d;
    }
    int s,g,V,P;
    scanf("%d,%d,%d,%d", &s, &g, &V, &P);
    for(int k=0; k<n; ++k){
        for(int i=0; i<n; ++i){
            for(int j=0; j<n; ++j){
                G[i][j] = min(G[i][j], G[i][k]+ G[k][j]);
            }
        }
    }

    s--;
    g--;
    cout << V - P - (G[s][g] + G[g][s]) << endl;

    return 0;
}


Measured memory_bytes: 3156
n=gets.to_i
x=[];y=[];z=[]
kai=0
n.times{|i|x[i],y[i],z[i]=gets.split.map &:to_i;kai=i if z[i]>0}
for i in 0..100
  for j in 0..100
    ans=1
    h=z[kai]+(i-x[kai]).abs+(j-y[kai]).abs
    n.times{|g|
      if z[g] != [h-(i-x[g]).abs-(j-y[g]).abs,0].max
        ans=0
      end
    }
    break if ans==1
  end
  break if ans==1
end
puts [i,j,h]*' '


Measured memory_bytes: 14324
r, c = map(int, input().split())
list_gyouretsu = []
list_last_gyou = []
for i in range(r):
  list_gyou = list(map(int, input().split()))
  list_gyouretsu.append(list_gyou)
  list_gyouretsu[-1].append(sum(list_gyou))
for j in range(c+1):
  sum = 0
  for k in range(r):
    sum += list_gyouretsu[k][j]
  list_last_gyou.append(sum)
list_gyouretsu.append(list_last_gyou)
for l in range(r+1):
  print(" ".join(map(str, list_gyouretsu[l])))


Measured memory_bytes: 5696
// https://ynucpc.github.io/blog/2018/04/15/cp_vscode/
// http://www.atmarkit.co.jp/ait/articles/1509/08/news019.html

#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define rep1(i,n) for(ll i=1;i<=(ll)(n);i++)
#define rep3(i,n,m) for(ll i=(n);i<(ll)(m);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << (x) << endl
// #define max(a, b) ((a) > (b) ? (a) : (b))
// #define min(a, b) ((a) < (b) ? (a) : (b)) 
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
	return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
	o<<"{";
	for(const T& v:vc) o<<v<<",";
	o<<"}";
	return o;
}
using ll = long long;
template<class T> using V = vector<T>;
template<class T> using VV = vector<vector<T>>;
int stoi (string s, int tmp=10){
	istringstream stm(s);
	int res;
	stm >> res;
	return res;
}
double stod(string s, int tmp=10){
	istringstream stm(s);
	double res;
	stm >> res;
	return res;
}


// 配列の総和
// greater


ll dp[101][101010]={};

int main(){	
	// ll A;
    // cin >> A;
	// cout << "hello" << endl;
	// cout << stoi("14") << endl;
	// cout << max({1,3}) << endl;
	ll N, W, V = 1000;
	cin >> N >> W;
	rep(i, N+1)rep1(j, 101009)dp[i][j]=1ll<<60;
	dp[0][0]=0;
	rep1(i, N){
		ll w, v;
		cin >> w >> v;
		rep1(j, V*N){
			dp[i][j] = dp[i-1][j];
			if (j>=v) chmin(dp[i][j], dp[i-1][j-v]+w);
		}
	}
	ll ans=N*V+1;
	while (1){
		if (dp[N][ans] <= W)break;
		ans--;
	}

	cout << ans << endl;

}








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

#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <algorithm>

#include <bits/stdc++.h>
#include <cmath>
#include <limits>

using namespace std;

int main(int argc, char* argv[]){
	cin.tie(0);
	ios::sync_with_stdio(false);

	int N, M;
	vector<int> L, R;
	cin >> N >> M;

	for(int i=1; i<=M; i++){
		int l, r;
		cin >> l >> r;
		L.push_back(l);
		R.push_back(r);
	}

	sort(L.begin(), L.end());
	sort(R.begin(), R.end());

	int lmax = L[L.size()-1];
	int rmin = R[0];
	int ans = max(rmin - lmax + 1, 0);
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 1276
# coding: utf-8

import sys
import math
import collections
import itertools
INF = 10 ** 10
MOD = 10 ** 9 + 7
def input() : return sys.stdin.readline().strip()
def gcd(x, y) : return y if x % y == 0 else gcd(y, x % y)
def lcm(x, y) : return (x * y) // gcd(x, y)
def I() : return int(input())
def LI() : return [int(x) for x in input().split()]
def RI(N) : return [int(input()) for _ in range(N)]
def LRI(N) : return [[int(x) for x in input().split()] for _ in range(N)]

L = I()
print((L / 3)**3)


Measured memory_bytes: 38384
#include<bits/stdc++.h>
#define REP(i,n) for(ll i=0;i<(n);i++)
#define INF 1e9
#define MOD 1000000007
#define All(x) (x).begin(),(x).end()
#define Cout(x) cout << (x) << endl
typedef long long ll;
using namespace std;

int main(void){
  int N;
  cin>>N;
  vector<int> P(N);
  REP(i,N)cin>>P[i];
  int p_min=INF,ans=0;
  REP(i,N){
    if(p_min>P[i])ans++;
    p_min=min(p_min,P[i]);
  }
  cout<<ans<<endl;
}








Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb(a) push_back(a)
ll MAX=1e18;
ll solve()
{
    ll n;
    cin>>n;
    vector<ll>num(n);
    bool zero=false;
    for(ll i=0;i<n;i++)
    {
        cin>>num[i];
        if(num[i]==0) return 0;
    }
    ll res=1;
    for(auto x:num)
    {
        if(x <= MAX/res)
        res*=x;
        else return -1;
    }
    return res;
}
// ll solve2()
// {
//     ll a,b;
//     cin>>a>>b;
//     ll ans=a*b;
//     return ans;
// }
int main() {
    cout<<solve()<<"\n";
	return 0;
}

Measured memory_bytes: 4040
#include <bits/stdc++.h>
using namespace std;
#define int long long   // <-----!!!!!!!!!!!!!!!!!!!

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(a)-1;i>=b;i--)
#define chmin(a,b) (a)=min((a),(b));
#define chmax(a,b) (a)=max((a),(b));
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define printV(v) cerr<<(#v)<<":";for(auto(x):(v)){cerr<<" "<<(x);}cerr<<endl;
#define printVS(vs) cerr<<(#vs)<<":"<<endl;for(auto(s):(vs)){cerr<<(s)<< endl;}
#define printVV(vv) cerr<<(#vv)<<":"<<endl;for(auto(v):(vv)){for(auto(x):(v)){cerr<<" "<<(x);}cerr<<endl;}
#define printP(p) cerr<<(#p)<<(p).first<<" "<<(p).second<<endl;
#define printVP(vp) cerr<<(#vp)<<":"<<endl;for(auto(p):(vp)){cerr<<(p).first<<" "<<(p).second<<endl;}

inline void output(){ cerr << endl; }
template<typename First, typename... Rest>
inline void output(const First& first, const Rest&... rest) {
    cerr << first << " "; output(rest...);
}

using ll = long long;
using Pii = pair<int, int>;
using TUPLE = tuple<int, int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
const int inf = 1ll << 60;
const int mod = 1e9 + 7;
using Graph = vector<vector<int>>;

int n, m0, m;
vector<Pii> vp0, vp;

void trans() {
    int dx = vp[0].first - vp0[0].first;
    int dy = vp[0].second - vp0[0].second;
    for (auto& p : vp0) {
        p = Pii(p.first + dx, p.second + dy);
    }
}


void rot() {
    for (auto& p : vp0) {
        p = Pii(p.second, -p.first);
    }
}

bool check() {
    rep(k, 4) {
        trans();
        if (vp0 == vp) return true;
        reverse(all(vp0));
        trans();
        if (vp0 == vp) return true;
        rot();
    }
    return false;
}

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

    int n;
    while (cin >> n, n) {
        cin >> m0;
        vp0.clear();
        vp0.resize(m0);
        rep(i, m0) cin >> vp0[i].first >> vp0[i].second;

        rep(i, n) {
            cin >> m;
            vp.clear();
            vp.resize(m);
            rep(i, m) cin >> vp[i].first >> vp[i].second;
            if (check()) cout << i + 1 << endl;
        }
        cout << "+++++" << endl;
    }
}

Measured memory_bytes: 3176
#include <stdio.h>
#include <stdlib.h>

int a_max,b_max,total;
int timelist[20001];

int qsort_comp(const void* x,const void* y) {
	int* a=(int*)x;
	int* b=(int*)y;
	if(*a>*b)return 1;
	if(*a<*b)return -1;
	return 0;
}

int main(void) {
	int i;
	int r_max;
	while(1) {
		scanf("%d%d",&a_max,&b_max);
		if(a_max==0 && b_max==0)break;
		timelist[0]=0;
		for(i=0;i<a_max;i++)scanf("%d",&timelist[i+1]);
		for(i=0;i<b_max;i++)scanf("%d",&timelist[a_max+i+1]);
		total=a_max+b_max+1;
		qsort(timelist,total,sizeof(int),qsort_comp);
		for(i=1,r_max=0;i<total;i++) {
			if(timelist[i]-timelist[i-1]>r_max) {
				r_max=timelist[i]-timelist[i-1];
			}
		}
		printf("%d\n",r_max);
	}
	return 0;
}

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

int main() {
  double A,B,H,M;
  cin>>A>>B>>H>>M;
  cout << fixed << setprecision(13);
  cout<<sqrt(A*A+B*B-2*A*B*cos(acos(-1)*11*(H*60+M)/360))<<endl;
}

Measured memory_bytes: 4228
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt();
		int d=sc.nextInt();
		int c=sc.nextInt();
		int eat=0;
		for(int i=0;i<n;i++) {
			int Ai=sc.nextInt();
			for(int j=0;j<d;j++) {
				int e=j*Ai+1;
				if(e<=d) {
					eat++;
				}else {
					continue;
				}
			}
		}
		int answer=eat + c;
		System.out.println(answer);
	}
}

Measured memory_bytes: 23636
import java.util.Scanner;

public class Main {
	public static void main(String args[]) {
		Scanner scan = new Scanner(System.in);

		int n = scan.nextInt();
		int k = scan.nextInt();
		
		for(int i=0; i<Math.pow(2, n); i++) {
			int[] array = new int[n];
			int count = 0;
			int tmp = i;
			
			for(int j=0; tmp>0; j++) {
				if(tmp % 2 == 1) {
					array[j] = 1;
					count++;
				}
				tmp /= 2;
			}
			
			if(count == k) {
				System.out.print(i + ":");
				for(int j=0; j<n; j++) {
					if(array[j] == 1) System.out.print(" " + j);
				}
				System.out.println();
			}
		}
		
	}
}


Measured memory_bytes: 73392
#include<bits/stdc++.h>
	using namespace std;
	#define xxx ios::sync_with_stdio(),cin.tie(0),cout.tie(0)
	#define rep(i,n) for(int i=0;i<n;i++)
	#define int long long
	int bp(int a, int b, int m) {
   		a %= m;
   		int res = 1;
    	while (b > 0) {
        	if (b & 1)
            	res = res * a % m;
       		a = a * a % m;
       	 	b >>= 1;
 	    }
    return res;
	}
	int max(int a, int b){
		return (a>b)?a:b;	
	}
	int csb( int n) 
{ 
    int count = 0; 
    while (n) { 
        count += n & 1; 
        n >>= 1; 
    } 
    return count; 
} 
	int solve(int x){
		int r=0;
		while(x>0){
			int t=csb(x);
			x%=t;
			r++;
		}
		return r;
	}

	signed main(){
		int test=1;
		//cin>>test;
		while(test--){
			int n;
			cin>>n;
			int x=1;
			if(n==0) {cout<<"No"<<endl;break;}
			while(true){
				if(x>9) {cout<<"No"<<endl;break;}
				if(n%x==0) {
					int t=n/x;
					if(t<=9){ cout<<"Yes"<<endl; break;}
					
				}
				x++;
			}		
		}
		return 0;
	}

Measured memory_bytes: 3560
<?php
        $x;
        $y;
        $a=fgets(STDIN);
        list($c, $d) = sscanf($a, "%d %d");
        //echo $c . "aaaaa " . $d;
        $x=$c*$d;
        $y=2*($c+$d);
        echo $x.' '.$y;
        ?>

Measured memory_bytes: 15328
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <functional>
using namespace std;

typedef long long ll;

int sum[2][103];

int main() {
	int n; cin >> n;
	int a[2][103];
	for (int i = 0; i < 2; ++i) {
		for (int j = 0; j < n; ++j) {
			cin >> a[i][j];
		}
	}

	sum[0][0] = a[0][0];
	for (int i = 1; i < n; ++i) {
		sum[0][i] = sum[0][i - 1] + a[0][i];
	}
	sum[1][n - 1] = a[1][n - 1];
	for (int i = n - 2; i >= 0; --i) {
		sum[1][i] = sum[1][i + 1] + a[1][i];
	}
	int ans = 0;
	for (int i = 0; i < n; ++i) ans = max(ans, sum[0][i] + sum[1][i]);
	cout << ans << endl;
	return 0;
}

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

const int MAX_N = 8e3 + 10 , offset = 8e3 ;

std::bitset<MAX_N << 1> f[MAX_N] ;

char op[MAX_N] ;
int len , init[2] , cnt[2] , to[2] , num[2][MAX_N] ;

bool work(int ty) {
	for (int i = 0 ; i <= cnt[ty] ; ++i) f[i].reset() ;

	f[0][init[ty] + offset] = 1 ;
	for (int i = 1 ; i <= cnt[ty] ; ++i)
		f[i] = (f[i - 1] >> num[ty][i]) | (f[i - 1] << num[ty][i]) ;

	return f[cnt[ty]][to[ty] + offset] == 1 ;
}

int main() {
	scanf("%s" , op) ;
	len = strlen(op) ;
	scanf("%d %d" , &to[0] , &to[1]) ;

	///

	cnt[0] = cnt[1] = 0 ;
	init[0] = init[1] = 0 ;
	int i = 0 ;
	for (; i < len && op[i] != 'T' ; ++i , ++init[0]) ;

	int ty = 1 ;
	for (++i ; i < len ; ty ^= 1) {
		int p = i ;
		for (; p < len && op[p] != 'T' ; ++p) ;

		if (p > i) num[ty][++cnt[ty]] = p - i ;
		i = p + 1 ;
	}

	bool ans = work(0) & work(1) ;
	if (ans) printf("Yes\n") ;
	else printf("No\n") ;

	return 0 ;
}

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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
string char_to_string(char val) {
  return string(1, val);
}
int char_to_int(char val) {
  return val - '0';
}
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;
}
int vector_finder(std::vector<ll> vec, int number) {
  auto itr = std::find(vec.begin(), vec.end(), number);
  size_t index = std::distance( vec.begin(), itr );
  if (index != vec.size()) { // 発見できたとき
    return 1;
  }
  else { // 発見できなかったとき
    return 0;
  }
}

int main() {
  int H, N; cin >> H >> N;
  vector<int> A(N), B(N); REP(i, N) cin >> A[i] >> B[i];
  const int INF = pow(10, 9) + 7; vector<int> dp(H * H + H, INF);
  dp[0] = 0;
  REP(i, H + 1) {
    REP(k, N) {
      dp[i + A[k]] = min(dp[i] + B[k], dp[i + A[k]]);
    }
  }
  ll ans = pow(10, 9) + 7;
  for(int i = H; i < H * H + H; ++i) {
    if(dp[i] != INF) {
      if(ans > dp[i]) ans = dp[i];
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 393944
#include<stdio.h>
#include<stdlib.h>
 
#define N 101
#define BLACK 200
#define WHITE 201
#define GRAY 202
void DFS();
void DFS_Visit(int );
int t =0,num = 0;
int d[N],f[N],color[N],num4[N][N];
 
 
int main(){
  int i,j,num2,num3,num5,flag;
  scanf("%d",&num);
  
  for(i=1;i<=num;i++){
    for(j=1;j<=num;j++){
      num4[i][j] = 0;
    }
  }
  
   for(i=1;i<=num;i++){
     scanf("%d",&num5);
     scanf("%d",&num2);
     if(num2 == 0)continue; 
     else{
       for(j=0;j<num2;j++){
     scanf("%d",&num3);
     num4[i][num3] = 1; 
       }
     }   
   }
 
   DFS();
   for(i=1;i<=num;i++){
     printf("%d %d %d\n",i,d[i],f[i]);
   }
    
    
   return 0;
}
void DFS(){
  int i;
  for(i=1;i<=num;i++){
    color[i]=WHITE;
  }
  t = 0;
   
  for(i=1;i<=num;i++){
    if(color[i]==WHITE){
      DFS_Visit(i);
    }
  }
   
}
 
void DFS_Visit(int u){
  int v,j;
  color[u] = GRAY;
  t += 1;
  d[u] = t;
  for(j=1;j<=num;j++){
    if(color[j] == WHITE && num4[u][j] == 1)DFS_Visit(j);
  }
  color[u] = BLACK;
  t++;
  f[u] = t;
   
}

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

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

using namespace std;


int main(){
	
	int n;
	long long int input, median1, median2;
	vector<long long int> x, sorted;
	
	scanf("%d", &n);
	REP(i,n){
		scanf("%lld", &input);
		x.push_back(input);
		sorted.push_back(input);
	}
	
	sort(sorted.begin(), sorted.end() );
	
	median1 = sorted[n/2-1];
	median2 = sorted[n/2];
	
	REP(i,n){
		if (x[i]<=median1) printf("%lld\n", median2);
		else printf("%lld\n", median1);
	}
	
	return 0;
	
}


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

const int mod = 1e9 + 7;

int exp(int x, int n) {
    int ret = 1;
    while(n) {
        if(n & 1) ret = 1LL * ret * x % mod;
        x = 1LL * x * x % mod;
        n >>= 1;
    }
    return ret;
}
int inv(int x) {
    return exp(x, mod - 2);
}
int comb(int n, int k) {
    if(n < k) return 0;
    int ret = 1;
    for(int i = 0; i < k; i++) {
        ret = 1LL * ret * (n - i) % mod;
        ret = 1LL * ret * inv(i + 1) % mod;
    }
    return ret;
}

int H, W, K;

int main() {
    cin >> H >> W >> K;

    int fact = 1;
    for(int i = 0; i < K; i++) fact = 1LL * fact * (H + W - i) % mod;

    int tmp = 1LL * fact * comb(K, 2) % mod * inv(comb(H + W, 2)) % mod;
    tmp += 1LL * fact * comb(K, 3) % mod * inv(comb(H + W, 3)) % mod * (H + W - 2) % mod * inv(3) % mod;
    tmp %= mod;

    int ans = 1LL * H * W % mod * tmp % mod;

    tmp = 1LL * fact * comb(K, 1) % mod * inv(comb(H + W, 1)) % mod;
    tmp += 1LL * fact * comb(K, 2) % mod * inv(comb(H + W, 2)) % mod * (H + W - 1) % mod * inv(2) % mod;
    tmp %= mod;
    ans += 1LL * tmp * (H + W) % mod;
    ans %= mod;

    tmp = 1LL * fact * comb(K, 1) % mod * inv(comb(H + W, 1)) % mod * (H + W) % mod;
    ans += tmp;
    ans %= mod;

    cout << ans;
}


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

int main() {
  int n, l;
  cin >> n >> l;
  vector<string> s(n);
  for (int i = 0; i < n; i++) {
    cin >> s.at(i);
  }
  
  sort(s.begin(), s.end());
  
  for (int i = 0; i < n; i++) {
    if (i == n - 1) {
      cout << s.at(i) << endl;
      break;
    }
    cout << s.at(i);
  }
}


Measured memory_bytes: 3644
#include<iostream>
#include<cstdio>
#include<cstring>
typedef long long ll;
using namespace std;
int main()
{
	char s[1000];
	int a, b;
	cin >> a >> b;
	cin >> s;
	int len = strlen(s);
	if(len != a+b+1){
		cout << "No" << endl;
		return 0;		
	}
	if(s[a] != '-'){
		cout << "No" << endl;
		return 0;
	}
	for(int i = 0; i < a; i++){
		if(s[i] >= '0' && s[i] <= '9') ;
		else{
			cout << "No" << endl;
			return 0;
		}
	}
	for(int i = a+1; i < len; i++){
		if(s[i] >= '0' && s[i] <= '9') ;
		else{
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	return 0;
} 

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

string divide[4] = {"dream", "dreamer", "erase", "eraser"};

int main() {
    string S;
    cin >> S;

    reverse(S.begin(), S.end());
    for (int i=0; i<4; ++i) reverse(divide[i].begin(), divide[i].end());

    bool can = true;
    for(int i=0; i<S.size();) {
        bool can2 = false;
        for(int j=0; j<4; ++j){
            string d = divide[j];
            if(S.substr(i, d.size())==d) {
                can2 = true;
                i += d.size();
            }
        }
        if(!can2) {
            can = false;
            break;
        }
    }

    if(can) cout << "YES" << endl;
    else cout << "NO" << endl;

}

Measured memory_bytes: 512
#include<bits/stdc++.h>
#define ll long long
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<pii>
#define vll vector<pll>
#define all(v) v.begin(),v.end()
#define mem(v,x) memset(v,x,sizeof(v))
#define N 100005

using namespace std;

ll mod = 1e9+7;
ll power(ll a,ll b){
    ll res = 1;
    while(b){
        if(b&1){
            res = (res*a)%mod;
        }
        a = (a*a)%mod;
        b >>= 1;
    }
    return res;
}
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(NULL);
    int n,k;
    cin>>n>>k;
    ll ans[k+1];
    ans[k] = 1;
    ll res = k;
    for(int i=k-1;i>0;i--){
        int x = k/i;
        ll val = power(x,n);
        for(int j=2*i;j<=k;j+=i){
            val = (val-ans[j]+mod)%mod;
        }
        ans[i] = val;
        res = (res + val*i)%mod;
    }
    cout<<res;
	return 0;
}


Measured memory_bytes: 4296
#include<bits/stdc++.h>
# define PI           3.14159265358979323846  /* pi */

using namespace std;

int main()
{

    long n, m, x;
    cin >> n >> m >> x;
    long fans = 1e9;
    vector<vector<long>> a(n, vector<long>(m));
    vector<long> c(n);
    for (long i = 0; i < n; i++)
    {
        cin >> c[i];
        for (long j = 0; j < m; j++)
            cin >> a[i][j];
    }
    for (long ss = 0; ss < 1<<n; ss++)
    {
        vector<long> this_sum(m, 0);
        long cost = 0;
        for (long i = 0; i < n; i++){
            // this bit set => included in this subset
            if ((ss&(1<<i)) != 0) {
                cost += c[i];
                // add the gains
                for (int j = 0; j < m; j++)
                    this_sum[j] += a[i][j];
            }
        }
        // check if all > x
        bool ag = true;
        for (auto p: this_sum)
            if (p < x){
                ag = false;
                break;
            }
        if (ag)
            fans = min(fans, cost);
    }
    if (fans == 1e9)
        fans = -1;

    cout << fans;
    return 0;
}


Measured memory_bytes: 3596
#include<iostream>
using namespace std;
int main()
{
  string s;
  cin>>s;
  int t=0,maxv=0;
  for(int i=0;i<s.size();i++)
  {
    if(s[i]=='A' || s[i]=='C' || s[i]=='G' || s[i]=='T')
      t++;
    else
    {
      if(t>maxv)
        maxv=t;
      t=0;
    }
  }
  if(t>maxv)
        maxv=t;
  cout<<maxv;
}

Measured memory_bytes: 256
import java.util.*;


public class Main{
	public static void main(String args[]){
        
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        int q = sc.nextInt();
        int[] array = new int[n];
        Arrays.fill(array, k-q);

        for(int i = 0; i < q; i++){
            int stack = sc.nextInt();
            array[stack-1] += 1;
        }

        for(int j = 0; j < n; j++){
            if(array[j] < 1){
                System.out.println("No");
            }else{
                System.out.println("Yes");
            }
        }
    }
}

Measured memory_bytes: 59216
/*dismint|jjc*/
#include <bits/stdc++.h>
using namespace std;
#define forl(V, S, E) for(int V = S; V < E; V++)
#define ford(V, S, E) for(int V = S; V >= E; V--)
#define fore(E, X) for(auto &E:X)
#define println(X) cout << X << endl
#define printe(X) for(auto &E:X) cout << E << " "; cout << endl
typedef unordered_map<int, unordered_set<int>> graph;
typedef long long ll;

int n, k;
int costs[100001], dp[100001];

int main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	cin >> n >> k; forl(i, 0, n) cin >> costs[i];
	forl(i, 0, 100001) dp[i] = INT_MAX;
	dp[0] = 0;
	forl(i, 0, n) {
		forl(j, 1, k+1) {
			dp[i+j] = min(dp[i+j], dp[i]+abs(costs[i]-costs[i+j]));
		}
	}
	println(dp[n-1]);
}


Measured memory_bytes: 1024
//
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define ote(x) cout<<(x)<<endl

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

	ll s = sqrt(N);
	// cout<<"N "<<N<<"\n";
	// cout<<"sqrt(N) "<<s<<"\n";

	ll ans = log10(N)+1;
	// cout<<"len "<<ans<<"\n";//
	// ote("--------");//

	for(ll a=1; a<=s; a++){
		ll b = N/a;
		if(a*b==N){
			// cout<<a<<","<<b<<"\n";
			ll la = log10(a)+1;
			ll lb = log10(b)+1;
			ans = min(ans, max(la, lb));
		}
	}

	// ote("--------");//
	ote(ans);
}

Measured memory_bytes: 512
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int k = sc.nextInt();
        int n = sc.nextInt();
        int[] a = new int[n];
        int[] diff = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
        }
        for (int j = 1; j < n; j++) {
            diff[j - 1] = a[j] - a[j - 1];
        }
        diff[n - 1] = k - a[n - 1] + a[0];
        Arrays.sort(diff);
        System.out.println(k - diff[n - 1]);
    }
}

Measured memory_bytes: 61480
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //これつけるとA[N]でもいいらしい
//for文のマクロ
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define mp(a,b) make_pair(a,b)
#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を出力する
const int MOD=1000000007;
//エラトステネスの篩による素数列挙 O(NloglogN)
int main(){
    int n;
    cin>>n;
    int64_t sum=0;
    //map<int,int> fk;
    vector<int64_t> fk(n+1);
    for(int i=1;i<=n;i++){//xがiで割れるならiはxの約数
        for(int j=1;j*i<=n;j++){
            fk[i*j]+=1;
        }
    }
    for(int k=1;k<=n;k++){
        //cout<<k<<":"<<fk[k]<<endl;
        sum += k*fk[k];
    }
    cout<<sum<<endl;
}

Measured memory_bytes: 81400
#include<algorithm>
#include<iostream>
#include<cstdio>
#include<string>
char s2[1000];
using namespace std;
int main()
{
    string s1;
    cin>>s1;
    int cnt=0;
    for(int i=0;i<s1.size();i++)
    {
        if(s1[i]=='0'||s1[i]=='1')
            s2[cnt++]=s1[i];
       if(s1[i]=='B')
       {
           if(cnt>0)
            cnt--;
       }
    }
     for(int i=0;i<cnt;i++)
        cout<<s2[i];
     cout<<endl;
    return 0;
}


Measured memory_bytes: 256
N, Y = gets.split.map(&:to_i)
(N + 1).times do |i|
    (N + 1 - i).times do |j|
        if (10000 * i + 5000 * j + 1000 * (N - i - j) == Y)
            puts [i, j, N - i - j].join(" ")
            exit
        end
    end
end
puts [-1, -1, -1].join(" ")
        

Measured memory_bytes: 1916
#include <stdio.h>
#include <iostream>
#include <math.h>
using namespace std;

int main() {
	double a[2];
	int i;

	for (i = 0; i <= 1; i++) {
		cin >> a[i];
	}

	double x = ceil((a[0] + a[1] )/ 2);

	cout << x;

		return 0;
	}


Measured memory_bytes: 256
import fractions
N = int(input())
A=[int(i) for i in input().split()]
B=[]
L = [0]
R = [0]
for i in range(N):
    L.append(fractions.gcd(A[i],L[i]))
    R.append(fractions.gcd(A[N-i-1],R[i]))
for i in range(N):
    B.append(fractions.gcd(L[i],R[N-i-1]))
print(max(B))

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

namespace multiset
{

class multiset
{
  private:
    std::vector<int> tree;
    int MSB;

    void add(int i, int x)
    {
        for (; i < tree.size(); i += i & -i) {
            tree[i] += x;
        }
    }

    int sum(int i)
    {
        int res = 0;
        for (; i > 0; i -= i & -i) {
            res += tree[i];
        }
        return res;
    }

    int bisect(int w)
    {
        int i = 0;
        for (int k = MSB; k > 0; k /= 2) {
            if (i + k < tree.size() && tree[i + k] < w) {
                w -= tree[i + k];
                i += k;
            }
        }
        return i + 1;
    }

    uint32_t get_MSB(uint32_t x) { return 0x80000000 >> __builtin_clz(x); }

  public:
    multiset(int N) : tree(N + 1), MSB(get_MSB(N)) {}
    void insert(int x) { add(x, 1); }
    void erase(int x) { add(x, -1); }
    int lower_bound(int x)
    {
        int s = sum(x);
        return (s == 0) ? 0 : bisect(s);
    }

    size_t size() { return sum(tree.size() - 1); }
};

} // namespace multiset

struct FastIO {
    FastIO()
    {
        std::ios_base::sync_with_stdio(false);
        std::cin.tie(nullptr);
    }
} fastio;

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

    std::vector<int> A(N);
    for (auto &&a : A) {
        std::cin >> a;
    }

    std::vector<int> B = A;
    std::sort(begin(B), end(B));
    B.erase(std::unique(begin(B), end(B)), end(B));

    std::transform(begin(A), end(A), begin(A), [&](int val) -> int {
        return std::lower_bound(begin(B), end(B), val) - begin(B) + 1;
    });

    multiset::multiset ms(B.size());
    for (auto a : A) {
        auto i = ms.lower_bound(a - 1);
        if (i != 0) {
            ms.erase(i);
        }
        ms.insert(a);
    }

    std::cout << ms.size() << '\n';
}


Measured memory_bytes: 1536
#include<cstdio>
#include<algorithm>
using namespace std;
#define mod int(1e9+7)
const int MAXN=int(2e3+5);
typedef long long LL;
LL n;
LL k;
LL A[MAXN];
int main()
{
    LL Ans=0;
    scanf("%lld%lld",&n,&k);
    for(LL i=1;i<=n;i++)
        scanf("%lld",&A[i]);
    for(LL i=1;i<=n-1;i++)
        for(LL j=i+1;j<=n;j++) {
            if(A[i]>A[j])
                Ans=(Ans+(k+1)*k/2%mod)%mod;
            if(A[i]<A[j])
                Ans=(Ans+(k-1)*k/2%mod)%mod;
        }
    printf("%lld",Ans);
}


Measured memory_bytes: 128
from collections import Counter

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

arr.sort()
c = Counter(arr)

if N % 3 == 0:
    if len(c) == 3:
        x1, x2 = c.most_common()[0]
        y1, y2 = c.most_common()[1]
        z1, z2 = c.most_common()[2]
        if x2 == y2 == z2 and x1 ^ y1 == z1:
            print("Yes")
            exit()
    elif len(c) == 2:
        x1, x2 = c.most_common()[0]
        y1, y2 = c.most_common()[1]
        if x2 == 2 * y2 and y1 == 0:
            print("Yes")
            exit()

if N % 2 == 0:
    if len(c) == 2:
        x1, x2 = c.most_common()[0]
        y1, y2 = c.most_common()[1]
        if x2 == y2 and y1 == 0:
            print("Yes")
            exit()

if len(c) == 1:
    x1, x2 = c.most_common()[0]
    if x1 == 0:
        print("Yes")
        exit()

print("No")


Measured memory_bytes: 14468
#include<bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define repk(i,k,n) for (ll i = k; i < (ll)(n); ++i)
#define MAX 500000001000000000
#define MOD 1000000007
typedef long long  ll;

using namespace std;

ll ans, cnt;

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

	ll N;
	cin >> N;


	repk(i,1,N+1) {
		if (i % 3 == 0 || i % 5 == 0) {
			continue;
		}
		else {
			ans += i;
		}
	}

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


Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define log(x) cout<<x<<endl
#define pb push_back
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
typedef long long lint;
using namespace std;
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; }
const long long INF = 1LL << 60;

int gcd(lint x, lint y){
  return y==0 ? x:gcd(y,x % y);
}

int digsum(int n) {
  int res = 0;
  while(n > 0) {
    res += n%10;
    n /= 10;
  }
  return res;
}

int dignum(int n) {
  int res = 0;
  while(n > 0) {
    res++;
    n /= 10;
  }
  return res;
}

int stringcount(string s, char c) {
  return count(s.cbegin(), s.cend(), c);
}

int lcm(lint x, lint y){
  return x/ gcd(x, y) * y;
}

int combi(int n, int r){
  int num = 1;
  for(int i = 1; i <= r; i++){
    num = num * (n - i + 1) / i;
  }
  return num;
}

int main(){
  int n;
  lint num=1000000000;
  cin>>n;
  int h[100010];
  int dp[100010];
  rep(i,n){
    cin>>h[i];
    dp[i]=num;
  }
  dp[0]=0;
  for(int i=1;i<n;++i){
    chmin(dp[i],dp[i-1]+abs(h[i]-h[i-1]));
    if(i>1) chmin(dp[i],dp[i-2]+abs(h[i]-h[i-2]));
  }
  cout<<dp[n-1];
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
 
int main() {
	cin.tie(0);
    ios::sync_with_stdio(false);

    int N;
    cin >> N;

    string ans = "";

    int re = -1;

    if(N == 0) {
        cout << 0 << endl;
        return 0;
    }

    while(N != 0) {
        if(N % 2) {
            N += re;
            ans += "1";
        } else {
            ans += "0";
        }

        //cerr << N << endl;
        if(abs(N) != 1) N /= 2;
        re = -re;
    }

    reverse(ans.begin(), ans.end());

    cout << ans << endl;
}

Measured memory_bytes: 256
N = int(input())
B = list(map(int, input().split()))

if N == 2:
  print(2 * B[0])
  exit()

A = []
A.append(B[0])
A.append(B[N-2])

for i in range(N-2):
  A.append(min(B[i], B[i+1]))

print(sum(A))

Measured memory_bytes: 3064
#include<iostream>
#include<string>
#include<map>
#include<string.h>
#include<vector>
#include<set>
#include<stdio.h>
#include<math.h>
//#include<algothm>
#include<queue>
typedef long long ll;
typedef long double ld;
using namespace std;
int dp[110],l,add;
int main()
{
	int n,d,x,a[110];
	cin>>n>>d>>x;
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
		int m;
		if(d%a[i]==0) m=d/a[i];
		else 	m=d/a[i]+1;
	  dp[l+1]=m;
		l++;
	}
	for(int j=1;j<=l;j++)
	{
		add+=dp[j];
	}
	add+=x;
	cout<<add;
	system("pause");
  return 0;
}

Measured memory_bytes: 504
#!/usr/bin/env python3
import sys

YES = "Yes"  # type: str
NO = "No"  # type: str


def solve(N: int):
    for x in str(N):
        if x =="7":
            print(YES)
            return
    print(NO)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    solve(N)

if __name__ == '__main__':
    main()


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

int main() {
  int A, B, C;
  cin >> A >> B >> C;
  vector<int> vec = {A, B, C};
  sort(vec.begin(), vec.end());
  reverse(vec.begin(), vec.end());
  
  	cout << vec.at(0) * 10 + vec.at(1) + vec.at(2) << endl;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void){

  int N;
  scanf("%d",&N);
  int i, p[N], count=0;
  for(i=1;i<=N;i++){
  scanf("%d",&p[i]);
}
  for(i=1;i<=N;i++){
    if(p[i]!=i){
	count+=1;
    }
  }
  if(count==0||count==2){
    printf("YES");
  }else{
    printf("NO");
  }

      return 0;
}



Measured memory_bytes: 128
/*
　　　　 ∧＿∧　にっぽんちゃちゃちゃ
　／＼（　・∀・）／ヽ
（ ●　と　　　つ　● ）　にっぽんちゃちゃちゃ
　＼/⊂、 ノ　　＼ノ
　　　　　し'
*/
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define repone(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define Rep(j,n) for(int j=0;j<(int)(n);++j)
#define Repone(j,n) for(int j=1;j<(int)(n);++j)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define int long long
#define MOD 1000000007
#define INF 9223372036854775807


signed main()
{
  string xyz ="";
int x=0,y=0,z=0,w=0,i=0,j=0,n=0;
std::vector<int> v;
std::cin >> w;
rep(i,w){
  std::cin >> x>>y>>z;
  if(x>y&&x>z&&x*x==y*y+z*z){
      std::cout << "YES" << '\n';


  }else if(y>x&&y>z&&y*y==x*x+z*z){

      std::cout << "YES" << '\n';

  }else if(z>x&&z>y&&z*z==x*x+y*y){
      std::cout << "YES" << '\n';

  }else{
    std::cout << "NO" << '\n';
  }
}
}



Measured memory_bytes: 2956
#include<iostream>
using namespace std;
int main(void){
  int minpas=3000,minju=3000,pas,ju;
  for(int i=0;i< 3;i++){
    cin >> pas;
    minpas = (minpas > pas)?pas:minpas;
  }for(int i=0;i<2;i++){
    cin >> ju;
    minju = (minju > ju)?ju:minju;
  }int synthetic=0;
  synthetic = minju+minpas -50;
  cout << synthetic << endl;
}

Measured memory_bytes: 1160
#include <iostream>
#include <bits/stdc++.h>
#include <time.h>
#include <sys/timeb.h>
#include <cstdio>
#include <sys/time.h>

using namespace std;
#define ll long long
#define uint unsigned int
#define ulong unsigned long long int

int main(){
	
	string s;
	cin >> s;
	for(auto& c : s) {
		if(c == '1'){
			c = '9';
		} else if(c == '9'){
			c = '1';
		}
	} 
	cout << s << endl;
	
	
	
	
	
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define Fast_IO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
int n,m,x;
int ans=INT_MAX;
int flag=0;
int dp[1000000];
void recur(int mask,vector<vector<int>> &algo,vector<int> &cost,int curr,vector<int> &stack){
    if(dp[mask]) return;
    vector<int> check (m,0);
    if(stack==check){
        ans=min(ans,curr);
        flag=1;
    }
    for (int i = 0; i < n; i++)
    {
        // cout<<(mask&(1<<i))<<" "<<(1<<i)<<"\n";
        if((mask&(1<<i))==0){
            vector<int> cp (m,0);
            // cout<<"fff"<<"\n";
            for(int j=0;j<m;j++){
                cp[j]=stack[j];
                stack[j]=max(0,stack[j]-algo[i][j]);
            }
            recur(mask|(1<<i),algo,cost,curr+cost[i],stack);
            stack=cp;
        }
    }
    dp[mask]=1;
}
int main()
{
    memset(dp,0,sizeof(dp));
    cin>>n>>m>>x;
    vector<int> cost (n,0);
    vector<vector<int>> algo (n,vector<int>(m,0));
    vector<int> z (m,x);
    for (int i = 0; i < n; i++)
    {
        cin>>cost[i];
        for (int j = 0; j < m; j++)
        {
            cin>>algo[i][j];
        }
    }
    recur(0,algo,cost,0,z);
    if(flag)
    cout<<ans<<"\n";
    else
    cout<<-1<<"\n";
}



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

int main()
{
	ll n,m;
	cin >> n >> m;
	ll ans = 0;
	for(ll i = 1;i*i<=m;i++)
	{
		if(m%i==0)
		{
			if(i*n<=m&&(m-i*n)%i==0)ans = max(ans,i);
			
			if((m/i)*n<=m&&(m-(m/i)*n)%(m/i)==0)ans = max(ans,m/i);
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#define _USE_MATH_DEFINES
#include <math.h>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
    long n;
    scanf("%ld", &n);
    long iMin = 2000000000;
    long iSum = 0;
    bool bSame = true;
    for(long i = 0; i < n; i++){
        long a,b;
        scanf("%ld %ld", &a, &b);
        iSum += a;
        if(a > b){
            bSame = false;
            iMin = min(iMin, b);
        }
    }
    if(bSame){
        printf("0");
    } else {
        printf("%ld", iSum - iMin);
    }
    return 0;
}


Measured memory_bytes: 3220
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define reps(i, n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
#define rrep(i, n) for(int i=((int)(n)-1); i>=0; --i)
#define rreps(i, n) for(int i=((int)(n)); i>0; --i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((int)(x).size())
#define pl(s) cout << (s) << "\n";
#define pls(...) {bool space = false; for(auto i : __VA_ARGS__) (cout << (space?" ":"") << i), space = true; cout << "\n";}
#define plexit(s) {cout << (s) << "\n"; exit(0);}
#define yes(s) cout << ((s)?"Yes":"No") << "\n";
template<typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using ll = long long; using ull = unsigned long long; using ld = long double;
template<typename T = int> using V = vector<T>; template<typename T = int> using P = pair<T, T>;
using Vi = V<int>; using Vl = V<ll>; using Vd = V<ld>; using VVi = V<Vi>; using VVl = V<Vl>; using Pi = P<int>; using Pl = P<ll>; using Pd = P<ld>;
constexpr ll MOD = 1000000007; constexpr int INF = (1 << 30) - 1; constexpr ll INFL = 1LL << 60; constexpr ld EPS = 1e-12; constexpr ld PI = 3.141592653589793238462643383279;

int main(void) {
  int a, b; cin >> a >> b;
  int c = 1;
  int ans = 0;
  while(1) {
    if (c >= b) break;
    c += a - 1;
    ++ans;
  }
  pl(ans)
  return 0;
}


Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin >> n;
	int a[10][10][11]={0};
	for(int i=0;i<n;i++){
		int b,f,r,v;
		cin>>b>>f>>r>>v;
		a[b][f][r]+=v;
		if(a[b][f][r]<0) a[b][f][r]=0;
	}
	for(int i=1;i<=4;i++){
		for(int j=1;j<=3;j++){
			for(int k=1;k<=10;k++){
				cout<<" "<<a[i][j][k];
			}
			cout<<"\n";
		}
		if(i!=4){ 
			for(int j=0;j<20;j++) cout<<"#";
			cout<<"\n";
		}
	}
	return 0;
}

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

#define ALL(x) (x).begin(), (x).end()

int main()
{

    string s;
    cin >> s;

    sort(ALL(s));
    if (s[0] == s[1] && s[1] != s[2] && s[2] == s[3])
        cout << "Yes" << "\n";
        else
        cout << "No" << "\n";

    return 0;
}

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

using namespace std;

#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define fin(ans) cout << (ans) << endl;
#define blank(ans) cout << (ans) << " ";
#define mp(p, q) make_pair(p, q)
#define mt(p, q, r) make_tuple(p, q.r)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()

typedef long long ll;
typedef long long lli;
typedef unsigned long long ull;
typedef long double ld;
typedef string str;

typedef vector<ll> vll;

const ld PI = acos(-1.0);
const ll MAX = 9000000000000000000;
const ll MIN = -9000000000000000000;
const ld DMAX = 4500;
const ld DMIN = -4500;
const ll MOD = 1000000007;

struct Cube
{
    ll f[6];
    //0 top
    //1 left
    //2 right
    //3 bottom
    //4 front
    //5 back
};

//実行部
void Main()
{
    Cube saikoro;
    rep(i, 6)
    cin >> saikoro.f[i];
    str s;
    cin >> s;
    rep(i, s.size())
    {
      if(s[i] == 'S')
      {
          ll tmp = saikoro.f[0];
          saikoro.f[0] = saikoro.f[4];
          saikoro.f[4] = saikoro.f[5];
          saikoro.f[5] = saikoro.f[1];
          saikoro.f[1] = tmp;
      }
      else if(s[i] == 'N')
      {
          ll tmp = saikoro.f[0];
          saikoro.f[0] = saikoro.f[1];
          saikoro.f[1] = saikoro.f[5];
          saikoro.f[5] = saikoro.f[4];
          saikoro.f[4] = tmp;
      }
      else if(s[i] == 'W')
      {
          ll tmp = saikoro.f[0];
          saikoro.f[0] = saikoro.f[2];
          saikoro.f[2] = saikoro.f[5];
          saikoro.f[5] = saikoro.f[3];
          saikoro.f[3] = tmp;
      }
      else
      {
          ll tmp = saikoro.f[0];
          saikoro.f[0] = saikoro.f[3];
          saikoro.f[3] = saikoro.f[5];
          saikoro.f[5] = saikoro.f[2];
          saikoro.f[2] = tmp;
      }
    }
    fin(saikoro.f[0])
}

//前処理
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20); //高精度少数表示
    Main();
    return 0;
}



Measured memory_bytes: 3220
package main

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

var sc = bufio.NewScanner(os.Stdin)

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

func nextFloat64() float64 {
	sc.Scan()
	i, e := strconv.ParseFloat(sc.Text(), 64)
	if e != nil {
		panic(e)
	}
	return i
}

func nextString() string {
	sc.Scan()
	return sc.Text()
}

func main() {
	sc.Split(bufio.ScanWords)
	n := nextInt()
	if n == 1 {
		fmt.Println(0)
	} else {
		fmt.Println(1)
	}
}


Measured memory_bytes: 1772