akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<algorithm>
using namespace std;

#define ll long long 

#define file_io 0

ll i,t,j;
ll n,nt,a[200005],c;
ll dp[200005],mx,q[200005],l,r;

//dp[j]-dp[k] / (h[j]-h[k]) < (h[i]-h[k]+h[i]-h[j])
double m(ll j, ll k) {
	return (1.0*(dp[j]-dp[k])/(a[j]-a[k])+a[k]+a[j]);
}

int main(){
	if (file_io){
		freopen(".in","r",stdin);
		freopen(".out","w",stdout);
	}
	
	scanf("%lld%lld",&n,&c);
	for (i=1; i<=n; ++i){
		scanf("%lld",&a[i]);
	}
	
	l=1,r=0;
	q[++r]=1;

	for (i=2; i<=n; ++i) {
		//property 2: pop useless front - at least two elements
		while (r-l>=1 && m(q[l],q[l+1]) < a[i]+a[i]) ++l;

		//peak of the moutain
		if (r>=l) {
			j=q[l];
			dp[i]=dp[j]+(a[i]-a[j])*(a[i]-a[j])+c;
		}

		//because y[i] is monotone, strictly decreasing
		
		//property 2: pop useless back, j<k<l
		//bt(k,l) is true, l is better than k
		//bt(j,k) is false, j may be better than k

		while (r-l>=1 && m(q[r-1],q[r]) > m(q[r],i)) --r;
		q[++r]=i;
	}

	printf("%lld\n",dp[n]);
	
	return 0;
}
/*
dp[i]=min(dp[j])+(h[j]-h[i])^2+C

k is better than j
	dp[j]+(h[i]-h[j])^2+C > dp[k]+(h[i]-h[k])^2+C
	dp[j]-dp[k] > (h[i]-h[k])^2 - (h[i]-h[j])^2
	dp[j]-dp[k] > (h[i]-h[k]+h[i]-h[j])(h[i]-h[k]-h[i]+h[j])
	
	dp[j]-dp[k] / (h[j]-h[k]) < (h[i]-h[k]+h[i]-h[j])
*/

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

#define M 1046527
#define L 14

char H[M][L]; /* Hash Table */

int getChar(char ch){
  if ( ch == 'A') return 1;
  else if ( ch == 'C') return 2;
  else if ( ch == 'G') return 3;
  else if ( ch == 'T') return 4;
}

/* convert a string into an integer value */
long long getKey(char str[]){
  long long sum = 0, p = 1, i;
  for ( i = 0; i < strlen(str); i++ ){
    sum += p*(getChar(str[i]));
    p *= 5;
  }
  return sum;
}

int h1(int key){ return key%M; }
int h2(int key){ return 1+(key%(M-1)); }

int find(char str[]){
  long long key,i,h;
  key=getKey(str);
  for(i=0;;i++){
    h=(h1(key)+i*h2(key))%M;
    if(strcmp(H[h],str)==0)return 1;
    else if(strlen(H[h])==0)return 0;
  }
  return 0;
}
   

int insert(char str[]){
  long long key,i,h;
  key=getKey(str);
  for(i=0;;i++){
    h=(h1(key)+i*h2(key))%M;
    if(strcmp(H[h],str)==0)return 1;
    else if(strlen(H[h])==0){
      strcpy(H[h],str);
      return 0;
    }
  }
  return 0;

}

int main(){
    int i, n, h;
    char str[L], com[9];
    for ( i = 0; i < M; i++ ) H[i][0] = '\0';
    
    scanf("%d", &n);
    
    for ( i = 0; i < n; i++ ){
	scanf("%s %s", com, str);
	
	if ( com[0] == 'i' ){
	    insert(str);
	} else {
	    if (find(str)){
		printf("yes\n");
	    } else {
		printf("no\n");
	    }
	}
    }

    return 0;
}

Measured memory_bytes: 14916
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll MOD = 1'000'000'007;
const ld PI = acos(-1);  
const ld EPS = 0.0000000001;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define REP(i, n) for(ll i=0; i<(ll)(n); i++)
#define REPD(i, n) for(ll i=n-1; 0<=i; i--)
#define FOR(i, a, b) for(ll i=a; i<(ll)(b); i++)
#define FORD(i, a, b) for(ll i=a; (ll)(b)<=i; i--)
#define ALL(x) x.begin(), x.end()
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int main(){
    ll n, k;    cin >> n >> k;
    vector<ll> key(10, true);
    REP(i, k){
        ll x;   cin >> x;
        key[x] = false;
    }
    FOR(i, n, 1'000'000){
        ll tmp=i;
        bool flag=true;
        while(0<tmp && flag){
            if(!key[tmp%10]) flag = false;
            tmp /= 10;
        }
        if(!flag) continue;
        cout << i << endl;
        return 0;
    }
}


Measured memory_bytes: 3624
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/* 
 * File:   main.c
 * Author: kundaikwangwari
 *
 * Created on July 23, 2019, 2:00 PM
 */

#include <stdio.h>
#include <stdlib.h>
#define NIL -1

/*
 * 
 */


int main(int argc, char** argv) {

    int V,k,n,edge;
    scanf("%d",&n);
    int table[n+1][n+1];
    for(int i = 1; i < n + 1; i++){
        for(int a = 1; a < n + 1; a++)table[i][a] = NIL;

}
    
    for(int i = 0; i < n; i++){
        
        scanf("%d%d",&V,&k);
        //printf("V %d edges %d\n",V,edge);
        for(int a = 0; a < k; a++){
            scanf("%d",&edge);
            table[V][edge] = 1;
           // printf("table(%d)(%d) has value %d \n",V,edge,table[V][edge]);
        }

    }
    

    for(int i = 1; i < n + 1; i++){
        for(int a = 1; a < n + 1; a++){
            if(table[i][a] == NIL)printf("0");
            else printf("%d",table[i][a]);
            if(a < n)printf(" ");
        }
        printf("\n");
    }

    return (0);
}




Measured memory_bytes: 2112
#include<bits/stdc++.h>
#define pb push_back
#define ll long long
#define ull unsigned long long
#define ii pair<int,int>
#define iii pair <int,ii>
#define iil pair<ll,ll>
#define iiil pair<ll,iil>
#define max3(a,b,c) max(a, max(b,c))
#define min3(a,b,c) min(a, min(b,c))
#define s(v) sort(v.begin(),v.end())
#define pf printf
#define sf scanf
#define MIN INT_MIN
#define MAX INT_MAX
#define accepted 0
using namespace std;
//long long int factorial(long long int n){if (n == 0)return 1;return n * factorial(n - 1);}
//
//bool prime[n];
//vector<int> v;
//void sieve(){
//    prime[0]=prime[1]=1;
//    for(int i=2;i*i<=n;i++){
//        if(prime[i]==0){
//            for(ll j = i*i;j<=n;j+=i){
//                prime[j]=true;
//            }
//        }
//    }
//    for(int i=2;i<=n;i++){
//        if(prime[i]==0)v.push_back(i);
//    }
//}
//
//bool ispalindrome(string s){
//
//    for(int i=0,j=s.size()-1;i<s.size();i++,j--){
//        if(s[i]!=s[j])
//            return false;
//    }
//    return true;
//}


int main(){
    int a,b,c;
        cin>>a>>b>>c;
        if(a==b && b!=c)cout<< "Yes" <<endl;
        else if(a==c && a!=b)cout<< "Yes" <<endl;
        else if(b==c && b!=a)cout<< "Yes" <<endl;
        else cout<< "No" <<endl;



    return accepted;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <climits>
#include <cmath>
#include <utility>
#include <string>
#include <cstring>
#include <functional>

using namespace std;

const int maxn = 100002;

int n, m, u[maxn], v[maxn], fa[maxn];
long long ans[maxn];

int getfa(int x) {
	if (fa[x] < 0)
		return x;

	fa[x] = getfa(fa[x]);
	return fa[x];
}

int main() {

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	cin >> n >> m;
	for (int i = 0; i < m; ++i)
		cin >> u[i] >> v[i];

	memset(fa, -1, sizeof(fa));

	ans[m-1] = (long long)n * (n-1) / 2;
	for (int i = m-2; i >= 0; --i) {
		int x = getfa(u[i+1]), y = getfa(v[i+1]);

		if (x == y)
			ans[i] = ans[i+1];
		else {
			ans[i] = ans[i+1] - (long long)fa[x] * fa[y];

			fa[x] += fa[y];
			fa[y] = x;
		}
	}

	for (int i = 0; i < m; ++i)
		cout << ans[i] << endl;

	return 0;
}

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

using namespace std;

int main() {
    int n, k; cin >> n >> k;
    vector<int> h(n);
    for (int i = 0; i < n; i++) cin >> h[i];
    sort(h.begin(), h.end());
    int i = 0, j = k - 1;
    int ans = h[j] - h[i];

    while (j < n) {
        ans = min(ans, h[j] - h[i]);
        i++, j++;
    }

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

Measured memory_bytes: 640
#include<bits/stdc++.h>
    using namespace std;
    #define int long long 
    #define pb push_back
    #define pii pair<int,int>
    #define mp make_pair
    #define F first
    #define S second
    #define ld long double
    int const M=1e6+10,inf=1e9+10,mod=1e9+7;
    int fact[M],ans[M];
    int pw(int x,int y)
    {
    	if(y==0)return 1;
    	int tmp=pw(x,y/2);
    	if(y%2==0)return (tmp*tmp)%mod;
    	return ((tmp*tmp)%mod*x)%mod;
    }
    int C(int n,int r)
    {
    	int tmp=fact[r]*fact[n-r];
    	tmp%=mod;
    	tmp=pw(tmp,mod-2);
    	tmp*=fact[n];
    	tmp%=mod;
    	return tmp;
    }
    int say(int n,int r)
    {
    	int tmp=n-r;
    	if(tmp==0 && r==0)return 1;
    	if(tmp<r || r==0)return 0;
    	return C(tmp-1,r-1);
    }
    int32_t main()
    {
    	int n;
    	cin>>n;
    	fact[0]=1;
    	//cout<<C(5,2)<<" "<<pw(2,4)<<endl;
    	for(int i=1;i<=n;i++)
    	{
    		fact[i]=fact[i-1]*i;
    		fact[i]%=mod;
    	}
    	int all=0;
		if(n==3)return cout<<4,0;
    	for(int i=1;i<=n-1;i++)
    	{
    		if(n-i-1<0)continue;
    		int res=n-i;
    		if(n-2>=res)
    			ans[i]=say(n-2,res);
    		ans[i]*=(res*2)%mod;
    		ans[i]%=mod;
    		if(n-2>=res-1){
    			ans[i]+=say(n-2,res-1)*res;
    			ans[i]%=mod;
    		}
    		if(n-3>=res)
    		{
    			int hlp=say(n-3,res-1)*2;
    			hlp*=res;
    			hlp%=mod;
    			ans[i]+=hlp;
    			ans[i]%=mod;
    		}
    		int tmp=1;
    		tmp%=mod;
    		tmp*=fact[i-1];
    		tmp%=mod;
    		tmp*=fact[n-i-1];
    		tmp%=mod;
    		tmp*=i;
    		tmp%=mod;
    		tmp*=ans[i];
    		tmp%=mod;
    	//	cout<<i<<" "<<res<<" "<<tmp<<" "<<ans[i]<<endl;
    		all+=tmp;
    		all%=mod;
    	}
    	cout<<all;
    }

Measured memory_bytes: 15872
import java.util.Scanner;
import java.util.Arrays;
import java.util.ArrayList;
import java.util.List;

public class Main {
    public static Scanner sc = new Scanner(System.in);
    public static int[] taro;
    public static int[] hana;
    public static long res;
    public static int at;
    public static int ah;
    public static void main(String[] args) throws Exception {
        while (sc.hasNext()) {
            int n = sc.nextInt();
            int m = sc.nextInt();
            if (n == 0 && m == 0) break;
            taro = new int[n];
            hana = new int[m];
            res = Integer.MAX_VALUE;
            at = 0;
            ah = 0;
            for (int i = 0; i < n; i++) {
                taro[i] = sc.nextInt();
            }
            for (int i = 0; i < m; i++) {
                hana[i] = sc.nextInt();
            }
            
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < m; j++) {
                    int t = taro[i];
                    taro[i] = hana[j];
                    hana[j] = t;
                    if (sum(taro) == sum(hana)) {
                        int tmp = taro[i] + hana[j];
                        if (tmp < res) {
                            at = hana[j];
                            ah = taro[i];
                            res = tmp;
                        }
                    }
                    t = taro[i];
                    taro[i] = hana[j];
                    hana[j] = t;
                }
            }
            if (res == Integer.MAX_VALUE) {
                System.out.println("-1");
            } else {
                System.out.println(at + " " + ah);
            }
        }
    }
    
    public static long sum(int[] ary) {
        long sum = 0;
        for (int i = 0; i < ary.length; i++) {
            sum += ary[i];
        }
        return sum;
    }
}

Measured memory_bytes: 30040
x, k, d = map(int, input().split())
x = abs(x)
if x > k*d:
    print(x-k*d)
    exit()
else:
    k = k - (x//d)
    x = x - (x//d)*d
    if k % 2 == 0:
        print(x)
    else:
        print(abs(x-d))

Measured memory_bytes: 9168
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>

#define fr(i,b,e) for(int i=(b); i<(e); ++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long int li;
typedef long long ll;

const int mod= 1000000007;    

int chk(vector<int>& a){
    int n=a.size();
    fr(i,0,n){
        cout << a.at(i);
    }
    cout << endl;
}


int gcd(int a,int b){ //a>b
    int tmp=a%b;
    a=b;
    b=tmp;
    if(b!=0){
        return gcd(a,b);
    }else{
        return a;
    }
}

ll power(ll a,ll n){
    if(n==1){
        return a;
    }
    else if(n&1==1){
        --n;
        return power(a,n)*a;
    }else{
        n=n>>1;
        return power(a,n)*power(a,n);
    }
}

ll mod_power(ll a,ll n, ll p){
    if(n==1){
        return a%p;
    }
    else if(n&1==1){
        --n;
        return (mod_power(a,n,p)*a)%p;
    }else{
        n=n>>1;
        return (mod_power(a,n,p)*mod_power(a,n,p))%p;
    }
}

ll mod_inv_fermat(ll a,ll p){  // inv of a in mod p
    ll n=p-2;
    return mod_power(a,n,p);
}

ll egcd(ll a, ll p, ll &x, ll &y) {
    /*
        ax+pm=1を再帰的に解いてxをaの逆元として求める。
        入力としてa<pを仮定。
    */
    if (a == 0) {
        x = 0;
        y = 1;
        return p;
    }
    ll d = egcd(p%a, a, y, x); // 再帰的に解く
    // 再帰で求まったx,y,a,pを用いて、逆元を計算
    x -= p/a * y; //　今までの処理を呼び出している関数の引数を計算
    return d;
}

ll mod_inv(ll a,ll p){  // inv of a in mod p
    ll x,y;
    egcd(a,p,x,y);
    return (x%p+p)%p;
}

int mod_combination(int n, int a, int p){
    int m = min(a,n-a);
    int c = 0;
    ll up = 1;
    ll down = 1;
    while(c != m){
        up = ((n-c)*up) % p;
        ++c;
        down =(down*c) % p;
    }
    return (up*mod_inv(down,p))%p;
}


int main(void){
    int n,m;
    cin >> n >> m;
    bool check=false;
    if(n==1){
        if(m==0){
            cout << "0" << endl;
        }else{
            string out(n,'a');
            vector<short int> s(m);
            vector<char> c(m);

            for(int i=0; i<m; ++i){
                cin >> s.at(i) >> c.at(i);
            }

            for(int i=0; i<m; ++i){
                if(out.at(0)=='a' || out.at(0)==c.at(i)){
                    out.at(0)=c.at(i);
                }else{
                    check=true;
                    break;
                }
            }
            
            if(check){
                cout << "-1" << endl;
            }else{
                cout << out << endl;
            }
        }
    }else{
        string out(n,'a');
        vector<short int> s(m);
        vector<char> c(m);
        for(int i=0; i<m; ++i){
            cin >> s.at(i) >> c.at(i);
        }

        for(int i=0; i<m; ++i){
            if(out.at(s.at(i)-1)=='a' || out.at(s.at(i)-1)==c.at(i)){
                out.at(s.at(i)-1)=c.at(i);
            }else{
                check=true;
                break;
            }
        }

        if(out.at(0)=='0') check=true;

        replace(out.begin(),out.end(),'a','0');

        if(out.at(0)=='0') out.at(0)='1';

        if(check){
            cout << "-1" << endl;
        }else{
            cout << out << endl;
        }
    }
}


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

int main() {
    int n; 
    cin >> n;  // データセットの数
    while(n--){
        int balls[10] = {0};
        for(int i = 0; i < 10; i++) cin >> balls[i]; // 各データセットの入力

        bool isYES = true;  // 玉10個を振り分けられるかどうか
        int topB = 0, topC = 0;  // 筒B及び筒Cの最上部の玉の値
        for(int i = 0; i < 10; i++){
            if (topB < balls[i]){
                topB = balls[i];
            } else if (topC < balls[i]) {
                topC = balls[i];
            } else {
                isYES = false;
                break;
            }
        }
        cout << (isYES ? "YES" : "NO") << endl;
    }
}



Measured memory_bytes: 2988
#include<bits/stdc++.h>
#define fast ios::sync_with_stdio(false), cin.tie(0);
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define endl '\n'

using namespace std;

main()
{
    fast;
    int n,m,c,i,j;
    cin>>n>>m>>c;
    int b[m];
    for (i=0;i<m;i++)
        cin>>b[i];
    int ans=0;
    for (i=0;i<n;i++)
    {
        int a,sum=c;
        for (j=0;j<m;j++)
        {
            cin>>a;
            sum+=a*b[j];
        }
        if (sum>0)
            ans++;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
while True:
    n=int(input())
    a=[]
    if n==0:
        break
    else:
        for i in range(n):
            a.append(int(input()))
    k=sorted(a)
    del k[0]
    del k[n-2]
    s=sum(k)
    print(int(s/(n-2)))
    


Measured memory_bytes: 5596
#include <iostream>
#include <string>
using namespace std;
int main() {
	string L,R;int left,right,i,j,N;cin>>N;while (N--) {cin>>L>>R;left=L.length(),right=R.length();
		if (left>=right) {if (left>80) {cout<<"overflow"<<endl;continue;}R.resize(left);for (i=right-1,j=left-1;i>=0;i--,j--) R[j]=R[i];right=left;for (;j>=0;R[j--]='0');
		} else {if (right>80) {cout<<"overflow"<<endl;continue;}L.resize(right);for (i=right-1,j=left-1;j>=0;i--,j--) L[i]=L[j];left=right;for (;i>=0;L[i--]='0');}
		L[left]=0;for (i=left-1,j=0;i>=0;i--) {L[i]+=R[i]+j-48;if (L[i]>'9') j=1,L[i]-=10; else j=0;}i=L.length()+j;if (i>80) cout<<"overflow"<<endl; else {if (j) cout<<"1";cout<<L<<endl;}} return 0;}

Measured memory_bytes: 0
import java.util.*;
public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		long N = sc.nextLong();
		long M = sc.nextLong();
		if(N != 1 && M != 1) {
			System.out.println(N * M - N * 2 - M * 2 + 4);
		} else if(N != 1 || M != 1){
			System.out.println(Math.max(N, M) - 2);
		} else {
			System.out.println(1);
		}
	}
}


Measured memory_bytes: 23252
#include<cstdio>
#include<iostream>
#include<vector>
#include<map>
#include<queue>
#include<algorithm>
#include<deque>
#include<cmath>
#include<set>
#include<cstring>
#include<string.h>
using namespace std;
typedef long long ll;
const int inf = 0x3f3f3f3f;
//----------------
#define int long long
//----------------
inline int read()
{
    int x = 0, f = 1;char ch = getchar();
    while (ch < '0' || ch > '9'){if (ch == '-')f = -1;ch = getchar();}
    while (ch >= '0' && ch <= '9'){x = (x << 1) + (x << 3) + (ch ^ 48);ch = getchar();}
    return x * f;
}
#define sdf(x) x=read()
#define For(i, a, b) for (int i = (a); i <= (b); i++)
#define FFor(i, a, b) for (int i = (a); i >= (b); i--)
#define me(a, b) memset(a, b, sizeof(a))
#define mid ((l + ((r - l)/2)))
#define random(a, b) ((a) + rand() % ((b) - (a) + 1))
#define bg1(x) cout<<(#x)<<":"<<(x)<<" "<<endl
#define bg2(x,y) cout<<(#x)<<":"<<(x)<<" "<<(#y)<<":"<<(y)<<" "<<endl
#define bg3(x,y,z) cout<<(#x)<<":"<<(x)<<" "<<(#y)<<":"<<(y)<<" "<<(#z)<<":"<<(z)<<" "<<endl
#define bg4(x,y,z,w) cout<<(#x)<<":"<<(x)<<" "<<(#y)<<":"<<(y)<<" "<<(#z)<<":"<<(z)<<" "<<(#w)<<":"<<(w)<<" "<<endl
#define bg5(x,y,z,w,k) cout<<(#x)<<":"<<(x)<<" "<<(#y)<<":"<<(y)<<" "<<(#z)<<":"<<(z)<<" "<<(#w)<<":"<<(w)<<" "<<(#k)<<":"<<(k)<<" "<<endl
#define call(x) cout<<x<<":"
#define lll cout<<"\n------\n"
int die = 0;
#define Die die++;if(die>100000){cout<<"dead!!!";exit(0);}
#define mk make_pair
#define pb push_back
const double eps = 1e-8;
// srand((unsigned)time(NULL));
const int mod = 1e9 + 7;
const int N = 1e6 + 5;

char s[N];

void sol1(){
    int x=(s[1]-'0')*10+(s[2]-'0');
    int y=(s[3]-'0')*10+(s[4]-'0');
    bool f1,f2;
    f1=f2=0;
    if(x>=1&&x<=12)f1=1;
    if(y>=1&&y<=12)f2=1;
    if(f1&&f2)cout<<"AMBIGUOUS";
    else if(f1)cout<<"MMYY";
    else if(f2)cout<<"YYMM";
    else cout<<"NA";
}

void rd(){
    scanf("%s",s+1);
    sol1();
}

signed main()
{

    rd();
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<int(n);++i)
typedef long long ll;
vector<int> get_acum(string s, char c){
    vector<int> acum = {0};
    rep(i,s.size()){
        acum.push_back(acum.back() + (s[i] == c));
    }
    return acum;
}

int main(void){
    int n;
    string s;
    cin >> n >> s;
    vector<int> acum[3];
    acum[0] = get_acum(s, 'R');
    acum[1] = get_acum(s, 'B');
    acum[2] = get_acum(s, 'G');
    map<char,int> mp = {{'R', 0}, {'B', 1}, {'G', 2}};
    ll sum = 0;
    rep(j,n)rep(i,j){
        if (s[i] == s[j]) continue;
        int c = 3 - mp[s[i]] - mp[s[j]];
        sum += acum[c][n] - acum[c][j];
        int k = j+(j-i);
        if (k < n && mp[s[k]] == c) sum--;
    }
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 3672
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main(){
	char a,b,c,d,e,f;
	cin>>a>>b>>c>>d>>e>>f;
	if(a==f && b==e && c==d ){
		cout<<"YES"<<endl;
		
	}
	
	else cout<<"NO"<<endl;
	
}

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

using i64=int64_t;

#define rep(i,x,y) for(i64 i=i64(x),i##_max_for_repmacro=i64(y); i<i##_max_for_repmacro; ++i)
#define debug(x) #x << "=" << (x)
 
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif
 
const int inf=1.01e9;
const i64 inf64=4.01e18;
const double eps=1e-9;
 
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
    os << "[";
    for (const auto &v : vec) {
        os << v << ",";
    }
    os << "]";
    return os;
}

void solve(){
    i64 K;
    cin >> K;

    const i64 N=50,x=K/N;
    vector<i64> a(N);
    rep(i,0,N) a[i]=i+x;
    rep(i,0,K%N){
        a[i]+=N;
        rep(j,0,N){
            if(i==j) continue;
            --a[j];
        }
    }

    cout << N << endl;
    rep(i,0,N){
        cout << a[i];
        if(i==N-1) cout << endl;
        else cout << " ";
    }
}

int main(){
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    solve();
    return 0;
}


Measured memory_bytes: 256
using System;
        using System.Linq;
        using System.Collections.Generic;
        using static System.Math;

        public class Program
        {
            public static void Main(string[] args)
            {
            int count = int.Parse(Console.ReadLine());
            int num = int.Parse(Console.ReadLine());
            int answer = 1;

            for (int i = 0; i < count; i++)
            {
                int a = answer * 2;
                int b = answer + num;
                answer = a < b ? a : b;
            }

            Console.WriteLine(answer);
            }
        }

Measured memory_bytes: 13140
// Problem : L - Deque dp on partial games
// Contest : AtCoder - Educational DP Contest
// URL : https://atcoder.jp/contests/dp/tasks/dp_l
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include "bits/stdc++.h"
using namespace std;
 #define int               long long
#define nl                "\n"
#define pb                push_back
#define mp                make_pair
#define ppb               pop_back
#define pf                push_front
#define ppf               pop_front
#define all(x)            (x).begin(),(x).end()
#define uniq(v)           (v).erase(unique(all(v)),(v).end())
#define sz(x)             (int)((x).size())
#define f                 first
#define s                 second
#define pii               pair<int,int>
#define rep(i,a,b)        for(int i=a;i<b;i++)
#define mem1(a)           memset(a,-1,sizeof(a))
#define mem0(a)           memset(a,0,sizeof(a))
#define ppc               __builtin_popcount
#define ppcll             __builtin_popcountll
#define fast_io           ios_base::sync_with_stdio(false);cin.tie(NULL);
 
const long long INF=1e18;
const int32_t M=1e9+7;
const int32_t MM=998244353;

 
 int dp[3000][3000][2];
 //dp[L][R][P] l,r for segments left both inclusive , pth player turn
 //p=0 first,p=1 second;



void solve(){
	int n,sum=0;
	cin>>n;
	vector<int>v(n);
	for(int& a:v){cin>>a;sum+=a;}
	//cout<<sum<<nl;
     //base case
     rep(i,0,n)
    { dp[i][i][0]=v[i];
     dp[i][i][1]=0;}
     //transition state
     rep(rminusl,1,n)
       for(int l=0;l+rminusl<n;l++)
        {
        	int r=l+rminusl;
        	dp[l][r][0]=max(v[l]+dp[l+1][r][1],
        	                v[r]+dp[l][r-1][1]);
        	dp[l][r][1]=min(dp[l+1][r][0],
        	                dp[l][r-1][0]);
        	                

        }
       
     //ans
     
     int x=dp[0][n-1][0];
    // cout<<x<<nl;
	 cout<<(2*x)-sum;

}	


signed main(){
	fast_io
   
	#ifdef SIEVE
		sieve();
	#endif
	#ifdef NCR
		init();
	#endif
	int t=1;
	//cin>>t;
	while(t--) solve();
	return 0;
}


Measured memory_bytes: 85400
#include <bits/stdc++.h>
#define rep(i,a,b) for(ll i=ll(a);i<ll(b);i++)
#define irep(i,a,b) for(ll i=ll(a);i>=ll(b);i--)
#define pb push_back
#define mp make_pair
#define pll pair<ll,ll>
#define endl "\n"
using ll=long long;
using ld=long double;
using namespace std;
ll mod= 1e9+7;
ll GCD(ll a, ll b) { return b ? GCD(b, a%b) : a; }

ll a[210000];
ll b[210000];
main(){
    ll n,ans=0;
    cin>>n;
    rep(i,1,n+1)cin>>a[i];
    irep(i,n,1){
      ll tmp=0;
      for(ll j=i+i;j<=n;j+=i){
        if(b[j]==1)tmp++;
      }
      if(tmp%2!=a[i]){b[i]=1;ans++;}
    }
    cout<<ans<<endl;
    rep(i,1,n+1){
      if(b[i]==1)cout<<i<<endl;
    }
}

Measured memory_bytes: 3968
K, S = map(int, input().split())
count = 0
for i in range(K + 1):
    if 0 <= S - i < K:
        count += S - i + 1
    elif K <= S - i <= 2 * K:
        count += 2 * K - S + i + 1
    else:
        continue
print(count)

Measured memory_bytes: 3060
#include <cstdio>
#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <tuple>
#include <assert.h>
#include <deque>
#include <bitset>
#include <iomanip>
#include <limits>
#include <chrono>
#include <random>
#include <array>
#include <unordered_map>
#include <functional>
#include <complex>
#include <numeric>
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; }

constexpr long long MAX = 5100000;
constexpr long long INF = 1LL << 60;
constexpr int inf = 1 << 28;
constexpr long long mod = 1000000007LL;
//constexpr long long mod = 998244353LL;

using namespace std;
typedef unsigned long long ull;
typedef long long ll;


bool check(int x, vector<int>& a) {
	int n = a.size();
	int i = 0;
	for (; i < n; i++) {
		if (x % a[i] == 0) {
			return i % 2 == 0;
		}
	}
	return (n % 2 == 0);

}
void solve() {
	int n, l, r; scanf("%d %d %d", &n, &l, &r); if (n == 0 and l == 0 and r == 0) exit(0);
	vector<int> a(n); for (int i = 0; i < n; i++) scanf("%d", &a[i]);
	int res = 0;
	for (int i = l; i <= r; i++) res += check(i, a);
	printf("%d\n", res);
}

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

	int kkt = 89;
	while (kkt) {
		solve();
	}
	return 0;
}


Measured memory_bytes: 3232
#include <iostream>
#include <stdlib.h>
#include <iomanip>

int main(void) {
  int a, b;
  int div_i, mod;
  double div_f;

  int cout_precision = 5;
  char deli = ' ';

  std::cin >> a >> b;

  div_i = a / b;
  mod = a % b;
  div_f = a / (double)b;

  std::cout << std::fixed << std::setprecision(cout_precision)
    << div_i << deli << mod << deli << div_f << std::endl;

  return 0;
}



Measured memory_bytes: 3208
#include"iostream"
#include"cmath"
#include"vector"
#include"algorithm"
#include"list"
#include"set"
#include"unordered_set"
#include"map"
#include"unordered_map"
#include"string"
#include"cstring"
#include"iomanip"
using namespace std;
typedef long long ll;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;cin>>n;
    int min10=1e7,sum=0;
    for(int i=0;i<n;++i)
    {
        int s;cin>>s;
        sum+=s;
        if(s%10!=0)
            min10=min(min10,s);
    }
    if(sum%10!=0)
    {
        cout<<sum<<'\n';
    }
    else if(min10!=0&&min10!=1e7)
    {
        cout<<sum-min10<<'\n';
    }
    else cout<<"0\n";
}

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

string s, t;

int main(){

    cin >> s >> t;

    int cnt = 0;
    for (int i=0; i<3; i++){
        if(s.at(i) == t.at(i)){
            cnt++;
        }
    }

    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
n,m = map(int,input().split())
a = []
b = []
for _ in range(n):
    a1,b1 = map(int,input().split())
    a.append(a1)
    b.append(b1)
c = sorted(zip(a,b))
ans = 0
for i in range(n):
    if m > c[i][1]:
        ans += c[i][0]*c[i][1]
        m -= c[i][1]
    else:
        ans += c[i][0]*m
        break
print(ans)

Measured memory_bytes: 18644
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner stdIn = new Scanner(System.in);
		
		String s1 = stdIn.next();
		String s2 = stdIn.next();
		
		if(s1.charAt(0) == s2.charAt(2) && s1.charAt(1) == s2.charAt(1) && s1.charAt(2) == s2.charAt(0))
		{
			System.out.println("YES");
		}
		else
		{
			System.out.println("NO");
		}
		

	}

}


Measured memory_bytes: 35700
#include<bits/stdc++.h>
#define ll long long
#define pii_ pair<int,int>
#define mp_ make_pair
#define pb push_back
#define fi first
#define se second
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define show1(a) cout<<#a<<" = "<<a<<endl
#define show2(a,b) cout<<#a<<" = "<<a<<"; "<<#b<<" = "<<b<<endl
using namespace std;
const ll INF = 1LL<<60;
const int inf = 1<<30;
const int maxn = 2e5+5;
inline void fastio() {ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);}



int main()
{
    fastio();
    int x;cin>>x;
    if(x>=1800) cout<<1<<endl;
    else if(x>=1600) cout<<2<<endl;
    else if(x>=1400) cout<<3<<endl;
    else if(x>=1200) cout<<4<<endl;
    else if(x>=1000) cout<<5<<endl;
    else if(x>=800) cout<<6<<endl;
    else if(x>=600) cout<<7<<endl;
    else if(x>=400) cout<<8<<endl;
    return 0;
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
int a,b,c;
int n;
int o;
bool abc(int x){
	a=x/100;
	b=x%100/10;
	c=x%10;
	if(a==b&&b==c){
		return true;
	}
	return false;
}
int atcoder(int a){
	for(int i=111;i<=999;i+=111){
		if(n<i){
			return i;
		}
	}
}
int main(){
	cin>>n;
	if(abc(n)){
		cout<<n;
	}
	else{
		o=atcoder(n);
		cout<<o;
	}
	
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<limits.h>
#include<cmath>
#include<queue>
#include<stack>

#include<stdio.h>
#include<stdlib.h>

#define rep(i,n) for(ll i = 0; i < (ll)n; i++)
#define swap(a,b) a^=b;b^=a;a^=b;
#define chmax(a,b) {if(a < b) a = b;}
#define chmin(a,b) {if(a > b) a = b;}

using namespace std;
typedef long long ll;
const ll INF = 1LL << 60;

int main(void) {
	cin.tie(0);
	ios::sync_with_stdio(false);
	//Program Start	

	int N, M;
	cin >> N >> M;

	cout << (N * (N - 1)) / 2 + (M * (M - 1)) / 2 << endl;


EndPoint:;

	//Program End
#ifndef DEBUG
	system("pause");
#endif // !DEBUG

	return 0;
}




Measured memory_bytes: 3160
#include <stdio.h>
int main(void){
    int C1,C2,C3,a[10],i,ok;
    while(scanf("%d %d %d",&C1,&C2,&C3)!=EOF){
        for(i=0;i<10;i++)a[i]=1;
        a[C1-1]=0;a[C2-1]=0;a[C3-1]=0;ok=0;
        for(i=1;i+C1+C2<21;i++)if(a[i-1])ok++;
        if(ok>3)printf("YES\n"); else printf("NO\n");
    }
    return 0;
}

Measured memory_bytes: 580
n, m, x, y = map(int, input().split())
xn = [int(i) for i in input().split()]
ym = [int(i) for i in input().split()]
if max(xn) >= y:
    print("War")
elif min(ym) <= x:
    print("War")
elif max(xn) >= min(ym):
    print("War")
else:
    print("No War")

Measured memory_bytes: 3060
//#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<set>
#include<map>

/*
#include<boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/rational.hpp>
namespace mp = boost::multiprecision;
using Real = mp::number<mp::cpp_dec_float<1024>>;
using Bint = mp::cpp_int;
*/

using namespace std;

#define int long long
#define REP(i,s,e) for((i)=(s);(i)<(e);(i)++)
#define RREP(i,s,e) for((i)=((s)-1);(i)>=(e);(i)--)
#define FOR(i,n) for((i)=(0);(i)<(n);(i)++)
#define RFOR(i,n) for((i)=((n)-1);(i)>=(0);(i)--)
#define MOD 1000000007

//https://drken1215.hatenablog.com/entry/2020/03/02/022900
struct UnionFind {
    vector<int> par;

    UnionFind(int n) : par(n, -1) { }

    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }

    bool issame(int x, int y) {
        return root(x) == root(y);
    }

    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y); // merge technique
        par[x] += par[y];
        par[y] = x;
        return true;
    }

    int size(int x) {
        return -par[root(x)];
    }
};

signed main(){
    int N,M;
    cin>>N>>M;
    UnionFind uf(N+1);
    for(int i=0;i<M;i++){
        int A,B;
        cin>>A>>B;
        uf.merge(A,B);
    }

    int ans=0;
    for(int i=1;i<=N;i++){
        ans=max(uf.size(i),ans);
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 4408
iN,iM=$stdin.gets.split.map(&:to_i)
  iA=[]
  iN.times do
    iA<<$stdin.gets.split.map(&:to_i)
  end
  iB=[]
  iM.times do
    iB<<$stdin.gets.to_i
  end
  iN.times do |i|
    ans=[]
    iB.each_with_index do |n,j|
      ans << iA[i][j]*n
    end
    puts ans.sum
  end


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

using namespace std;

int main(){

  while(true){
    int M,T,P,R;
    cin>>M>>T>>P>>R;
    if(!M and !T and !P and !R)break;

    vector< vector<bool> > is_ac(T,vector<bool>(P,false));
    vector< vector<int> > wa_num(T,vector<int>(P,0));
    vector< pair< pair<int,int> ,int > > point(T);

    for(int i=0;i<T;i++){
      point[i].second=i+1;
    }
    
    for(int i=0;i<R;i++){
      int m,t,p,j;
      cin>>m>>t>>p>>j;
      //cout<<m<<" "<<t<<" "<<p<<" "<<j<<endl;
      t--;
      p--;
      if(j==0){
        is_ac[t][p]=true;
        point[t].first.first++;
        point[t].first.second+=m*(-1);
      }
      else{
        wa_num[t][p]++;
      }
    }

    for(int i=0;i<T;i++){
      for(int j=0;j<P;j++){
        if(is_ac[i][j]){
          point[i].first.second-=wa_num[i][j]*20;
        }
      }
    }
    
    sort(point.begin(),point.end());
    reverse(point.begin(), point.end());


    for(int i=0;i<T;i++){
      if(i>0){
       if(point[i].first==point[i-1].first)printf("=");
       else printf(",");
      }
      printf("%d",point[i].second);
    }
    puts("");
  }
  
}

Measured memory_bytes: 1204
#include<bits/stdc++.h>
using namespace std;
char s[10];
double a[1005];
int  main(){
	double n,m;
	double sum=0;
	cin>>n>>m;
	for(int i=1;i<=n;++i){
		cin>>a[i];
		sum+=a[i];
	}
	double av=sum*(1.0/(4.0*m));
	int cnt=0;
	for(int i=1;i<=n;++i){
		if(a[i]>=av)cnt++;
	}
	if(cnt>=m)puts("Yes");
	else puts("No");
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main()
{
  char S[5];
  scanf("%s",&S);
  if (S[0] == S[3] && S[1] == S[2] && S[0] != S[1] || S[0] == S[2] && S[1] == S[3] && S[0] != S[1] || S[0] != S[2] && S[0] == S[1] && S[2] == S[3])
    printf("Yes");
  else
    printf("No");
}

Measured memory_bytes: 128
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
typedef pair<ld, ld> LDP;
const int mn = 1 << 17;
ll dp[mn],x[mn];
int n, nn; ll dat[2][2*mn-1];
void init() {
	nn = 1;
	while (nn < n)nn *= 2;
	rep(i, 2 * nn - 1)dat[0][i] = dat[1][i] = INF;
}
void update(int id, int k, ll a) {
	k += nn - 1;
	dat[id][k] = a;
	while (k > 0) {
		k = (k - 1) / 2;
		dat[id][k] = min(dat[id][k * 2 + 1], dat[id][k * 2 + 2]);
	}
}
ll query(int id,int a, int b, int k, int l, int r) {
	if (r <= a || b <= l)return INF;
	if (a <= l && r <= b)return dat[id][k];
	else {
		ll vl = query(id, a, b, k * 2 + 1, l, (l + r) / 2);
		ll vr = query(id, a, b, k * 2 + 2, (l + r) / 2, r);
		return min(vl, vr);
	}
}
int main() {
	cin >> n; n++;
	init();
	ll e, t; cin >> t >> e;
	rep(i, n-1) {
		cin >> x[i];
	}
	x[n-1] = t;
	fill(dp, dp + n + 2, INF);
	dp[0] = x[0];
	update(0, 0, 0);
	update(1, 0, -2*x[0]);
	rep1(i, n-1) {
		int loc = lower_bound(x, x + n, x[i-1] - e / 2) - x;
		ll mi1 = query(1, 0, loc, 0, 0, nn) + x[i] + 2*x[i - 1];
		ll mi2 = query(0, loc, i, 0, 0, nn) + e + x[i];
		dp[i] = min(mi1, mi2);
		update(0, i, dp[i] - x[i]);
		update(1, i, dp[i] - 3 * x[i]);
	}
	cout << dp[n-1] << endl;
	return 0;
}


Measured memory_bytes: 6400
import sys
from itertools import product

input = sys.stdin.readline


def calc_prime_factors(n, count=False):
    """Trial division"""
    factors = []
    # factor: 2
    while n % 2 == 0:
        factors.append(2)
        n //= 2
    # factor: 3, 5, 7, 11, ...
    f = 3
    root_n = int(n ** 0.5) + 1
    while f <= root_n:
        if n % f == 0:
            factors.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        factors.append(n)
    return factors


def main():
    N = int(input())

    factors = calc_prime_factors(N)
    factors = list(set(factors))
    ans = N
    for comb in product(range(2), repeat=len(factors)):
        div = 1
        cnt = 0
        for i, c in enumerate(comb):
            if c == 1:
                cnt += 1
                div *= factors[i]
        if cnt == 0:
            continue
        coeff = -1 if cnt % 2 == 1 else 1
        ans += coeff * (N // div)

    print(ans)


if __name__ == "__main__":
    main()



Measured memory_bytes: 5684
import java.util.*;
public class Main {
	public static void main(String [] args){
		Scanner sc = new Scanner(System.in);
		int x = 0;
		int y = 0;
		int x1 = 0;
		int y1 = 0;
		int N = sc.nextInt();
		int[] t = {0,0};
		int a = 0;
		Boolean hantei = null;
		for(int i=0;i<N;i++){
			t[0]  = t[1];
			t[1] = sc.nextInt();
			x1 = sc.nextInt();
			y1 = sc.nextInt();
			a = ((t[1]-t[0])-(Math.abs(x1-x)+Math.abs(y1-y)));
			if(a>=0 && a%2==0){
				hantei = true;
			}else{
				hantei = false;
				break;
			}
			x = x1;
			y = y1;
		}
		if(hantei){
			System.out.println("Yes");
		}else{
			System.out.println("No");
		}
	}
}

Measured memory_bytes: 84716
#include<bits/stdc++.h>
#include<iostream>
using namespace std;
typedef long long int ll; 

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

	ll sum=0;
	for(ll i=1;i<=n;i++)
	{
		ll a,b,c;
		a = i%3==0 && i%5==0;
			// cout << "FizzBuzz ";
		b = i%3==0 && i%5!=0;
			// cout << "Fizz ";
		c = i%3!=0 && i%5==0;
			// cout << "Buzz ";
		if(a==0 && b==0 && c==0)
		{
			// cout << i << " ";
			sum+=i;
		}
	}
	cout << sum << endl;

	return 0;
}

Measured memory_bytes: 3616
#include  <iostream>
using namespace std;
int main() {
  int h,s=0;
  cin>>h;
  while(cin>>h){
    if(h>s){
      s=h;
    }else if(h<s-1){
      cout << "No";
      return 0;
    }
  }
  cout << "Yes";
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long 
#define inf 1e17
#define f(i,a,b) for(ll i=a;i<b;i++)
//ll m = 1e9+7;
using namespace std;
//cout<<setprecision(9)<<m/(1<<q);
//__builtin_popcount();
//next_permutation(abc.begin(), abc.end());
//(string(n, abc[0]);
//str.find(s);
//ll a[1000001];
ll umin(ll a,ll b)
{
  if(a<b)
    return a;return b;
}
/*string toBinary(ll n)
{
    string r;
    while(n!=0) {r=(n%2==0 ?"0":"1")+r; n/=2;}
    return r;
}*/
int main()
{
	ll n;cin >> n;
	ll a[n];ll b[n];
	for(ll i=0;i<n;i++)cin >> a[i],b[i]=a[i];
		sort(a,a+n);
	ll ans =0;
	for(ll i=0;i<n;i++)
	{
		if(a[i]!=b[i])
			ans++;
	}
	if(ans ==0 or ans ==2)
		cout << "YES\n";
	else
		cout << "NO\n";
	return 0;
}

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

using namespace std;

#define MAX_H 10
#define MAX_W 10
#define MAX 13*12+10
#define F first
#define S second
typedef pair<int,int> pii;
typedef pair<pii,int> Ink;

int mat[MAX_H][MAX_W];
const int size[] = {5,9,13};

const int dx[3][13] = {
    {-1,0,0,1,0},
    {-1,-1,-1,0,0,0,1,1,1},
    {-2,-1,-1,-1,0,0,0,0,0,1,1,1,2}
};

const int dy[3][13] = {
    {0,-1,0,0,1},
    {-1,0,1,-1,0,1,-1,0,1},
    {0,-1,0,1,-2,-1,0,1,2,-1,0,1,0}
};

inline bool inField(int x,int y){
    return (0 <= x && x < MAX_W &&
            0 <= y && y < MAX_H);
}

inline bool check(int x,int y,int s){
    for(int i = 0 ; i < size[s] ; i++){
        int nx = x + dx[s][i];
        int ny = y + dy[s][i];
        if(!inField(nx,ny)) return 0;
        if(mat[ny][nx] == 0) return 0;
    }
    return 1;
}

inline void removeBlur(int x,int y,int s,bool plus){
    for(int i = 0 ; i < size[s] ; i++){
        int nx = x + dx[s][i];
        int ny = y + dy[s][i];
        mat[ny][nx] = mat[ny][nx] + (plus ? +1 : -1);
    }
}

vector<Ink> v;
bool ok[MAX];

void solve(int x,int y,int rem,int n){
    if(n == 0){
        if(rem == 0) throw 0;
        return;
    }
    if(!ok[rem]) return;
    if(rem < n*5 || rem > n*13) return;
    for(; y < MAX_H-1 ; y++){
        for(; x < MAX_W-1 ; x++){
            if(mat[y][x] == 0) continue;
            for(int i = 2 ; i >= 0 ; i--){
                if(check(x,y,i)){
                    removeBlur(x,y,i,0);
                    v.push_back(Ink(pii(x,y),i+1));
                    solve(x,y,rem-size[i],n-1);
                    removeBlur(x,y,i,1);
                    v.pop_back();
                }
            }
        }
        x = 1;
    }
}

void init(){
    memset(ok,0,sizeof(ok));
    ok[0] = 1;
    for(int i = 0 ; i < MAX ; i++){
        if(!ok[i]) continue;
        for(int j = 0 ; j < 3 ; j++){
            if(i+size[j] < MAX){
                ok[i+size[j]] = 1;
            }
        }
    }
}

int main(){
    int n,cnt = 0;
    init();
    cin >> n;
    for(int i = 0 ; i < 10 ; i++){
        for(int j = 0 ; j < 10 ; j++){
            cin >> mat[i][j];
            cnt += mat[i][j];
        }
    }
    try{
        solve(1,1,cnt,n);
    }catch(...){}
    for(int i = 0 ; i < (int)v.size() ; i++){
        cout << v[i].F.F << " " << v[i].F.S << " " << v[i].S << endl;
    }
    return 0;
}

Measured memory_bytes: 1264
#include <stdio.h>
#define N 101
#define WHITE 0
#define GRAY 1
#define BLACK 2

int V,time,color[N],G[N][N],d[N],f[N];
void DFS(void);
void DFS_Visit(int);

main(){
  int i,j,k,l;
  int Adj[N];
  scanf("%d",&V);
  for(i=1;i <= V;i++) {
    for(j=1;j <= V;j++){
      G[i][j] = WHITE;
    }
  }
  
  for(i=1;i <= V;i++){
    scanf("%d%d",&k,&l);
    for(j=1;j <= l;j++){
      scanf("%d",&Adj[j]);
      G[k][Adj[j]] = GRAY;
    }
  }
  
  DFS();
  for(i=1;i<=V;i++){
    printf("%d %d %d\n",i,d[i],f[i]);
  }
  return 0;
}


void DFS(){
  int u;
  for(u=1;u <= V;u++){
    color[u] = WHITE;
    time = 0;
  }
  for(u=1;u <= V;u++){
    if(color[u] == WHITE){
      DFS_Visit(u);
    }
  }
}

void DFS_Visit(int u){
  int v;
  color[u] = GRAY; // White vertex u has just been discovered
  d[u] = ++time;
  for(v=1;v<= V ;v++){ // Explore edge (u,v)
    if(color[v] == WHITE && G[u][v] == GRAY){
      DFS_Visit(v);
    }
  }
  color[u] = BLACK; // Blacken u; it is finished
  f[u] = ++time;
  
}

Measured memory_bytes: 636
import java.util.Scanner;

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

        int N = sc.nextInt();
        int T = sc.nextInt();
        int[] A = new int[N];
        for (int i = 0; i < A.length; ++i) {
            A[i] = sc.nextInt();
        }

        System.out.println(solve(A, T));

        sc.close();
    }

    static int solve(int[] A, int T) {
        int maxDiff = 0;
        int count = 0;
        int min = Integer.MAX_VALUE;
        for (int ai : A) {
            int diff = ai - min;
            if (diff > maxDiff) {
                maxDiff = diff;
                count = 1;
            } else if (diff == maxDiff) {
                ++count;
            }

            min = Math.min(min, ai);
        }

        return count;
    }
}

Measured memory_bytes: 50228
#include<bits/stdc++.h>
using namespace std;
#define int long long
int unx(){int x=0,n=0; char c=getchar(); for(;!isdigit(c);c=getchar()) n=(c=='-'); for(;isdigit(c);c=getchar())x=x*10+c-'0'; return (n)?-x:x;}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int rnd(int l,int r){}
#define in unx()
#define fasty ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define forinc(a,b,c) for(int a=b, _c=c; a<=_c; ++a)
#define fordec(a,b,c) for(int a=b, _c=c; a>=_c; --a)
#define forv(a,b) for(auto &a:b)
#define ii pair<int,int>
#define fi first
#define se second
#define pb push_back
#define all(a) a.begin(),a.end()
#define reset(f, x) memset(f, x, sizeof(f))
#define mt make_tuple
#define bit(x,i) (x>>(i-1)&1ll)
#define onbit(x,i) (x|(1ll<<(i-1)))
#define offbit(x,i) (x&~(1ll<<(i-1)))

const int N=2e5+5;
int n,a[N],dp[N],x[N],ma,f[N];
vector<int> ad[N],e;

void dfs(int u,int par){
  int pre=ma;
  f[u]=lower_bound(x+1,x+ma+1,a[u])-x;
  if(f[u]>ma) ma++;
  int pf=x[f[u]];
  x[f[u]]=a[u]; dp[u]=ma;
  forv(v,ad[u]) if(v!=par) dfs(v,u);
  x[f[u]]=pf;
  ma=pre;
}

main(){
  fasty;

  forinc(i,1,n=in) a[i]=in, e.pb(a[i]);
  forinc(i,2,n){
    int u=in, v=in;
    ad[u].pb(v); ad[v].pb(u);
  }

  sort(all(e)); e.erase(unique(all(e)), end(e));
  forinc(i,1,n) a[i]=lower_bound(all(e), a[i])-begin(e)+1;

  dfs(1,-1);

  forinc(i,1,n) cout<<dp[i]<<'\n';
}


Measured memory_bytes: 34744
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
int main(int argc, char *argv[])
{
	char sh[55],str[10]="FESTIVAL";
	scanf("%s",sh);
	int l=strlen(sh);
	sh[l-8]='\0';
	printf("%s\n",sh);
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
    int n;
    scanf("%d", &n);
    int d[n];
    int i,j,sum=0;
    for(i=0;i<n;i++){
        scanf("%d",&d[i]);
    }
    for(i=0;i<n;i++){
        for(j=i+1;j<n;j++){
            sum += d[i]*d[j];
        }
    }printf("%d\n",sum);
    return 0;
}


Measured memory_bytes: 128
"""Boot-camp-for-Beginners_Easy009_B_Collecting-Balls-(Easy-Version)_28-August-2020.py"""

N = int(input())
K = int(input())
x = list(map(int, input().split()))

s = 0
for i in range(N):
    if x[i] < K/2:
        s += 2*x[i]
    else:
        s += 2*(K-x[i])
print(s)


Measured memory_bytes: 9064
#include <iostream>
#include <string>
#include <vector>
#include <climits>
#include <algorithm>
#include <set>
#include <unordered_map>
#include <queue>
#include <iomanip>

using namespace std;
int N;
int mod = 1000000007;

int main() {
  cin >> N;
  string s1, s2;
  cin >> s1 >> s2;

  long ans = 1;
  bool tate = false;
  for (int i=0; i<N; i++) {
    if (i==0) {
      if (s1.at(i) == s2.at(i)) {
        ans*=3;
        tate = true;
      } else {
        ans*=6;
        tate = false;
        i++;
      }
    } else {
      if (s1.at(i) == s2.at(i)) {
        if (tate) {
          ans*=2;
          ans%=mod;
        }
        tate = true;
      } else {
        if (tate) {
          ans*=2;
          ans%=mod;
        } else {
          ans*=3;
          ans%=mod;
        }
        tate = false;
        i++;
      }
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
import collections
import itertools as it
import math
#import numpy as np
 
#  = input()
x  = int(input())
#  = map(int, input().split())
#  = list(map(int, input().split()))
#  = [int(input()) for i in range(N)]
#
# c = collections.Counter()

n11 = (x // 11)
rest = x - n11 * 11
rest6 = int(bool(rest % 6))
rest5 = int(bool(rest // 6 % 5))
#print(n11, rest, rest6, rest5)
print(n11 * 2 + rest6 + rest5)


Measured memory_bytes: 3316
import fractions
y = int(input())
x = list(map(int, input().split()))
list=[0]

for i in range(len(x)):
  if x[i]== list[-1]+1:
    list.append(x[i])

if len(list)==1:
  print(-1)
else:
  print(len(x)-(len(list)-1))
  

Measured memory_bytes: 28128