akhauriyash/Code-Regression huggingface dataset:
import           Control.Applicative
import           Control.Monad
import qualified Data.ByteString.Char8 as B

import           Data.Sequence         (Seq (..), ViewL (..), ViewR (..), (<|),
                                        (><), (|>))
import qualified Data.Sequence         as S

read' :: B.ByteString -> Int
read' bs | Just (n, _) <- B.readInt bs = n

merge :: Seq Int -> Seq Int -> (Seq Int, Int)
merge xs ys
    | S.null xs = (ys, 0)
    | S.null ys = (xs, 0)
    | a :< as <- S.viewl xs
    , b :< bs <- S.viewl ys =
        if a <= b
            then (S.singleton a, 0) <:> merge as ys
            else (S.singleton b, S.length xs) <:> merge xs bs

(<:>) :: (Seq Int, Int) -> (Seq Int, Int) -> (Seq Int, Int)
(xs, m) <:> (ys, n) = (xs >< ys, m + n)

mergeSort :: Seq Int -> (Seq Int, Int)
mergeSort xs
    | S.length xs == 1 = (xs, 0)
    | otherwise        = let (as, i) = mergeSort ls
                             (bs, j) = mergeSort rs
                             (cs, k) = merge as bs
                          in (cs, i + j + k)
  where
    mid = S.length xs `div` 2
    (ls, rs) = S.splitAt mid xs

main :: IO ()
main = do
    B.getLine
    xs <- S.fromList . fmap read' . B.words <$> B.getLine
    let (_, n) = mergeSort xs
    print n



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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
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;
}
int ctoi(char c) {
  if (c >= '0' && c <= '9') {
    return c - '0';
  }
  return 0;
}
int64_t factorial(int64_t n) {
  if (n == 1) {
    return 1;
  }
  int64_t ans = factorial(n-1);
  return ans*n;
}

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  vector <int> v = {abs(a-b), abs(b-c), abs(c-a)};
  sort(v.begin(), v.end());
  cout << v.at(0)+v.at(1) << endl;
}

Measured memory_bytes: 256
import sys
import re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
import math
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

K = INT()
S = input()

if len(S) <= K:
    print(S)
else:
    print(S[:K] + '...')


Measured memory_bytes: 10620
#include <fstream>
#include <iostream>
#include <cmath>
#include <vector>
#include <queue>
#include <utility>
#include <algorithm>
using namespace std;

int main() {
  // ifstream cin("../test.txt");
  char a[20][20];
  for (int i = 0; i < 20; i++) {
    for (int j = 0; j < 20; j++) {
      a[i][j] = '0';
    }
  }
  char c;

  vector<string> shape(7);
  shape[0] = "1100110000000000";
  shape[1] = "1000100010001000";
  shape[2] = "1111000000000000";
  shape[3] = "1000100000000000";
  shape[4] = "1100011000000000";
  shape[5] = "1000110001000000";
  shape[6] = "1100100000000000";

  while (cin >> c) {
    a[0][0] = c;
    for (int i = 1; i < 8; i++) {
      cin >> c;
      a[0][i] = c;
    }
    for (int i = 1; i < 8; i++) {
      for (int j = 0; j < 8; j++) {
        cin >> c;
        a[i][j] = c;
      }
    }

    // for (int i = 0; i < 8; i++) {
    //   for (int j = 0; j < 8; j++) {
    //     cout << a[i][j];
    //   }
    //   cout << endl;
    // }


    int h,w;
    for (int i = 0; i < 64; i++) {
      if (a[i/8][i%8] == '1') {
        h = i / 8;
        w = i % 8;
        break;
      }
    }

    // cout << h << " " << w << endl;

    for (int s = 0; s < 7; s++) {
      bool flag = true;
      for (int i = 0; i < 4; i++) {
        for (int j = 0; j < 4; j++) {
          if (shape[s][4 * i + j] != a[h + i][w + j])
            flag = false;
        }
      }

      if (flag) {
        cout << (char)('A' + s) << endl;
        break;
      }
    }

  }
}

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


using namespace std;

int main() {
  int N, M, C;
  cin >> N >> M >>C;
  vector<int> B(M);
  for (int i=0; i<M; i++){
    cin >> B[i];
  }
  int cnt = 0;
  for (int i=0; i<N; i++){
    int a;
    int sum=0;
    for (int j=0; j<M; j++){
      cin >> a;
      sum += a * B[j];
    }
    if (sum+C>0){
      cnt++;
    }
  }
  cout << cnt << endl;
}


Measured memory_bytes: 256
//HEADER FILES//
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <iomanip>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <bitset>
#include <cstdio>
#include <limits>
#include <vector>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <fstream>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <unordered_map>
#include <map>
#include <unordered_set>
#include <set>

//#########################################################################//
//MACROS
#define fastio                        \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);
#define stringinput(s) \
    string s;          \
    cin >> s;
#define lc cout << "\n";
#define testcase \
    int t;       \
    cin >> t;    \
    while (t--)
#define umap unordered_map
#define testcasei \
    inti t;       \
    cin >> t;     \
    while (t--)
#define notestcase \
    inti t = 1;    \
    while (t--)
#define input(n) \
    int n;       \
    cin >> n;
#define inputi(n) \
    inti n;       \
    cin >> n;
#define inputl(n) \
    li n;         \
    cin >> n;
#define display(a, n)         \
    {                         \
        int zzzz = n;         \
        for (auto x : a)      \
        {                     \
            cout << x << " "; \
            if (!(--zzzz))    \
                break;        \
        }                     \
        lc                    \
    }
#define pb push_back
#define pause \
    int zzz;  \
    cin >> zzz;
#define arrayinput(a) \
    for (auto &x : a) \
        cin >> x;
#define floop(i, n) for (__typeof(n) i = 0; i < n; ++i)
#define foop(i, start, end) for (__typeof(end) i = start; i < end; ++i)
#define display2d(a, m, n)          \
    for (int i = 0; i < m; ++i)     \
    {                               \
        for (int j = 0; j < n; ++j) \
            cout << a[i][j] << " "; \
        lc                          \
    }                               \
    lc

#define here(n)                  \
    cout << "here(" << n << ")"; \
    lc
#define debugHere(n)                   \
    cout << #n << " is (" << n << ")"; \
    lc
#define MOD 1000000007
#define bb begin()
#define ee end()
//#########################################################################//
using namespace std;
typedef unsigned long long int inti;
typedef long long int intl;
struct trio
{
    intl a, b, c;
};
struct duo
{
    inti l, r;
};
//######################################//
//          SOLUTION STARTS              //
//               HERE                    //
//###################################### //
int main()
{
    fastio
        notestcase
    {
        inti a;
        cin>>a;
        cout<<a+(a*a)+(a*a*a);
    }
}

Measured memory_bytes: 3192
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <cmath>
#include <iomanip>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cassert>
#include <cstring>
#include <climits>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define mp make_pair
#define fi first
#define se second
#define pb push_back

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;

constexpr ll INF = 1e18;
constexpr ll MOD = 1e9 + 7;
constexpr double PI = 3.14159265358979323846;
constexpr int di[] = {0, 0, 1, -1};
constexpr int dj[] = {1, -1, 0, 0};

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

    int n, l[11];

    cin >> n;

    REP(i, n)
    cin >> l[i];

    bool res = true;

    REP(i, n)
    {
        int a = 0;
        REP(j, n)
        {
            if (i == j)
                continue;
            a += l[j];
        }

        if (l[i] >= a)
            res = false;
    }

    cout << (res ? "Yes" : "No") << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <iomanip>

#define REP(i,n) for(int i=0;i<n;++i)
#define RREP(i,n) for(int i=n-1;i>=0;--i)
#define FOR(i,m,n) for(int i=m;i<n;++i)
#define RFOR(i,m,n) for(int i=m-1;i>=n;--i)
#define ALL(v) v.begin(),v.end()
#define PB(a) push_back(a)
#define INF 1000000001
#define MOD 1000000007

using namespace std;


int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, w, h, s, t;
	while (1) {
		cin >> n;
		if (!n) break;
		cin >> w >> h;
		vector<int> e(h, 0);
		vector<vector<int> > v(w, e);
		REP(i, n) {
			int x, y;
			cin >> x >> y;
			v[x - 1][y - 1] = 1;
		}
		int cmax = -INF;
		cin >> s >> t;
		REP(i, w - s + 1) {
			REP(j, h - t + 1) {
				int cnt = 0;
				REP(k, s) {
					REP(l, t) {
						cnt += v[i + k][j + l];
					}
				}
				cmax = max(cmax, cnt);
			}
		}
		cout << cmax << endl;
	}
	return 0;
}

Measured memory_bytes: 3188
while True:
    H, W = map(int, input().split())

    if H != 0 and W != 0:
        for h in range(H):
            for w in range(W):
                if h%2 == 0:
                    if w%2 == 0:
                        print("#", end = "")
                    else:
                        print(".", end = "")
                else:
                    if w%2 == 0:
                        print(".", end = "")
                    else:
                        print("#", end = "")
            print("")
        print("")
    else:
        break


Measured memory_bytes: 7012
package main

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

var (
	reader io.Reader = os.Stdin
	writer io.Writer = os.Stdout
)

func main() {
	reader = os.Stdin
	writer = os.Stdout
	run()
}

func run() {
	nums := readIntsFromStdin()[0]
	W, H, x, y, r := nums[0], nums[1], nums[2], nums[3], nums[4]
	var result string

	if x < r || y < r || x > W-r || y > H-r {
		result = "No"
	} else {
		result = "Yes"
	}

	fmt.Fprintln(writer, result)
}

// readIntsFromStdin parses lines of inputs into 2D int array.
func readIntsFromStdin() [][]int {
	out := [][]int{}
	scanner := bufio.NewScanner(reader)

	for scanner.Scan() {
		var ints []int

		for _, s := range strings.Split(scanner.Text(), " ") {
			i, err := strconv.Atoi(s)

			if err != nil {
				fmt.Fprintln(os.Stderr, "Failed to parse string into int.", err)
				os.Exit(1)
			}

			ints = append(ints, i)
		}

		out = append(out, ints)
	}

	return out
}



Measured memory_bytes: 1104
//header{{{
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
//#include<boost/multiprecision/cpp_int.hpp>
//#include<boost/math/common_factor_rt.hpp>
  
using namespace std;
//using namespace boost::multiprecision;  
//using namespace boost::math;

#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define all(x) (x).begin(),(x).end()
#define Fixed fixed << setprecision(12)
#define int int64_t
using pii = pair<int,int>;
constexpr int INF  = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int mod = 1e9+7; 
constexpr int MOD = 998244353;

template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }

template <class T> using min_heap = priority_queue<T,vector<T>,greater<T> >;
template <class T> using max_heap = priority_queue<T>;
template <class A, class B> using umap = unordered_map<A,B>;
  
inline int square(int a){ return a * a;}
inline int updiv(int a,int b){ return (a + b - 1) / b; }

constexpr int dx[] = {1,0,-1,0,1,1,-1,-1};
constexpr int dy[] = {0,-1,0,1,1,-1,-1,1};
//}}}

//UnionFind{{{
struct UnionFind {
    vector< int > data;
 
    UnionFind(int sz) {
        data.assign(sz, -1);
    }
 
    bool unite(int x, int y) {
        x = find(x), y = find(y);
        if(x == y) return (false);
        if(data[x] > data[y]) swap(x, y);
        data[x] += data[y];
        data[y] = x;
        return (true);
    }
 
    int find(int k) {
        if(data[k] < 0) return (k);
        return (data[k] = find(data[k]));
    }
 
    int size(int k) {
        return (-data[find(k)]);
    }

    bool same(int x, int y) {
        return (find(x) == find(y));
    }
};
//}}}

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

    int n;
    cin >> n;

    vector<int> a(n);
    vector<int> cnt(1e5+1);

    int sum = 0;

    rep(i,n){
        cin >> a[i];
        cnt[a[i]]++;
        sum += a[i];
    }

    int q;
    cin >> q;

    rep(i,q){
        int b, c;
        cin >> b >> c;
        sum -= b * cnt[b];
        sum += c * cnt[b];
        cnt[c] += cnt[b];
        cnt[b] = 0;
        cout << sum << '\n';
    }


    return 0;
}



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

int main(){
    int n; cin >> n;
    vector<int> a;
    map<int, int> mp;
    for(int i=0; i<n; i++){
        int tmp; cin >> tmp;
        a.push_back(tmp);
        if(mp.count(tmp))
            mp[tmp]++;
        else
            mp[tmp] = 1;
    }

    bool flg=false;

    if(mp.size()==1){
        if(mp.count(0)) 
            flg = true;
    }else if(mp.size()==2){
        int b[2];
        int d[2];
        int c = 0;
        for (auto i : mp)
		{
			b[c] = i.second;
			d[c] = i.first;
			++c;
		}
 
		sort(b, b + 2);
		sort(d, d+ 2);
		if (n % 3 == 0)
		{
			if (mp[d[1]] == mp[d[0]] * 2 && d[0] == 0) flg = true;
		}
    }else if(mp.size()==3){
        int b[3];
        int d[3];
        int c = 0;
        for(auto i : mp){
            b[c] = i.second;
            d[c] = i.first;
            c++;
        }
        sort(b, b+3);
        if(n%3==0 && ((d[0]^d[1])==d[2]) && ((d[0]^d[2])==d[1]) && ((d[1]^d[2])==d[0])){
            if(b[0] == b[1] && b[1] == b[2] && b[0] == b[2]) flg = true;
        }
    }

    cout <<  (flg ? "Yes" : "No") << endl;
    return 0;
}

Measured memory_bytes: 7216
#include <bits/stdc++.h>
 
#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
 
#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=(int)(a)-1;i>=(int)(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)
 
#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define bit(n) (1LL<<(n))
 
// #define DEBUG
 
#ifdef DEBUG
    #define dump(...) fprintf(stderr, __VA_ARGS__)
#else
    #define dump(...)
#endif
 
template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}
 
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
 
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int inf = INT_MAX;
const ll INF = LLONG_MAX;
const ll MOD = 1000000007LL;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
 
ll extgcd(ll a,ll b,ll& x,ll& y){x=1,y=0;ll g=a;if(b!=0) g=extgcd(b,a%b,y,x),y-=a/b*x;return g;}
ll ADD(const ll &a, const ll &b, const ll mod=MOD) { return (a+b)%mod;}
ll SUB(const ll &a, const ll &b, const ll mod=MOD) { return (a-b+mod)%mod;}
ll MUL(const ll &a, const ll &b, const ll mod=MOD) { return (1LL*a*b)%mod;}
ll DIV(const ll &a, const ll &b, const ll mod=MOD) {ll x,y; extgcd(b,mod,x,y);return MUL(a,(x+mod)%mod,mod);}
 
int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n; cin >> n;
    vi a(n); for(auto& e : a) cin >> e;

    vi L(n); L[0] = a[0]; rep(i, 1, n) L[i] = __gcd(L[i-1], a[i]);
    vi R(n); R[0] = a[n-1]; rep(i, 1, n) R[i] = __gcd(R[i-1], a[n-1-i]);

    int res = 1;
    rep(i, n){
        int cur;
        if(i == 0) cur = R[n-2];
        else if(i == n-1) cur = L[n-2];
        else cur = __gcd(L[i-1], R[n-2-i]);

        chmax(res, cur);
    }

    cout << res << endl;

    return 0;
}


Measured memory_bytes: 1408
#include<bits/stdc++.h>
#include<set>
using namespace std;
int n,m;
set<int>q;
int dis(int x1,int y1,int x2,int y2)
{
    return abs(x1-x2)+abs(y1-y2);
}
int a1[10000],b1[100000],a2[10000],b2[100000];
int main()
{
    cin>>n>>m;
    for(int i=1;i<=n;i++)
    {
        cin>>a1[i]>>b1[i];
    }
    for(int i=1;i<=m;i++)
    {
        cin>>a2[i]>>b2[i];
    }
    for(int i=1;i<=n;i++)
    {
        int pos;
        int Max=(1<<31)-1;
        for(int j=1;j<=m;j++)
        {
            int ans=dis(a1[i],b1[i],a2[j],b2[j]);
            //cout<<ans<<endl;
            if(ans<Max)
            {
                pos=j;
               // cout<<pos<<endl;
                Max=ans;
            }
        }
        cout<<pos<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
using System;
class P
{
  static void Main()
  {
    int N = int.Parse(Console.ReadLine());
    int sum = 0;
    int maxValue = 0;
    for (int i = 0; i < N; i++) {
      int v = int.Parse(Console.ReadLine());
      sum += v;
      maxValue = Math.Max(maxValue, v);
    }
    Console.WriteLine(sum-(maxValue/2));
  }
}


Measured memory_bytes: 13140
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
int dx[] = {0,1,0,-1};
int dy[] = {-1,0,1,0};
int main(){
  int N,n,d;
  while(cin >> N , N){
    P p[201];
    int ax=0,ay=0,ix=0,iy=0;
    p[0] = P(0,0);
    for(int i=1;i<N;i++){
      cin >> n >> d;
      p[i] = P(p[n].first+dx[d],p[n].second+dy[d]);
      ax = max(ax,p[i].first);
      ay = max(ay,p[i].second);
      ix = min(ix,p[i].first);
      iy = min(iy,p[i].second);
    }
    cout << ay - iy + 1 << " " << ax - ix + 1 << endl;
  }
}

Measured memory_bytes: 1160
import math

a,b=map(int,input().split())

n=math.gcd(a,b)

cnt=1

f=2
d=n
while f*f<=n:
    if d%f==0:
        cnt+=1
        while d%f==0:
            d=d//f
    f+=1
if d!=1:
    cnt+=1

print(cnt)

Measured memory_bytes: 9192
#include <iostream>
#include <string>
#include <vector>
#include <cstring>
#include <climits>
#include <algorithm>
#include <map>

using namespace std;

#define x first
#define y second

int getArea(int x1, int y1, int x2, int y2, int x3, int y3) {
    return abs((x1-x2)*(y3-y2)-(x3-x2)*(y1-y2));
}

int main() {
    int n;
    while (cin >> n, n) {
        map<int, bool> has;

        vector<pair<int,int> > co(n);
        for (int i=0; i<n; ++i) {
            cin >> co[i].x >> co[i].y;
            has[co[i].x+10000*co[i].y] = true;
        }
        sort(co.begin(), co.end());

        int area = 0;
        for (int i=0; i<(int)co.size(); ++i) {
            for (int j=i+1; j<(int)co.size(); ++j) {
                int dx, dy, x3, y3, x4, y4;
                dx = co[j].x - co[i].x;
                dy = co[j].y - co[i].y;
                x3 = co[j].x - dy;
                y3 = co[j].y + dx;
                x4 = co[i].x - dy;
                y4 = co[i].y + dx;
                if (has.count(x3+10000*y3) && has.count(x4+10000*y4)) {
                    area = max(area, getArea(co[i].x, co[i].y, co[j].x, co[j].y, x3, y3));
                }
            }
        }
        cout << area << endl;
    }
    return 0;
}

Measured memory_bytes: 1356
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
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 int INF=1001001001;
vector<pair<int64_t,int64_t>>pppp(int64_t x){
  vector<pair<int64_t,int64_t>>p;
  for(int64_t i=2;i*i<=x;i++){
    int cnt=0;
    if(x%i==0){
    while(x%i==0){cnt++;x/=i;}
    p.push_back(make_pair(i,cnt));
    }
  }
  if(x!=1){p.push_back(make_pair(x,1));}
  return p;
}

int main() {
  int N;
  cin>>N;
  vector<int>D(N);
  map<int,int>a;
  for(int i=0;i<N;i++){cin>>D[i];a[D[i]]++;}
  int M;
  cin>>M;
  vector<int>T(M);
  map<int,int>b;
  for(int i=0;i<M;i++){cin>>T[i];b[T[i]]++;}
  if(N<M){cout<<"NO"<<endl;return 0;}
  for(auto s:b){
    int x=s.first;
    int y=s.second;
    if(y>a[x]){cout<<"NO"<<endl;return 0;}
  }
  cout<<"YES"<<endl;

  return 0;
}

Measured memory_bytes: 20608
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define int long long
using namespace std;
typedef vector<int>   vint;
typedef pair<int,int> pint;

signed main()
{
    int K,S; cin>>K>>S;

    int ans=0;
    REP(x,K+1) REP(y,K+1){
        int z=S-(x+y);
        if(0<=z and z<=K) ans++;
    }
    cout<<ans<<endl;

}


Measured memory_bytes: 256
import sys
def S(): return sys.stdin.readline().rstrip()
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())

import itertools
import math

n = I()
p = LI()
q = LI()
nums = range(1,n+1)

count = 0
for lis in itertools.permutations(nums,n):
    pflg = True
    qflg = True
    for i in range(n):
        if(p[i] != lis[i]):
            pflg = False
        if(q[i] != lis[i]):
            qflg = False
    if(pflg):
        a = count
    if(qflg):
        b = count
    count += 1

print(abs(b-a))

Measured memory_bytes: 3064
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int y[10000000], n, maxv; vector<int>a;
int main() {
	while (cin >> n) {
		y[n]++;
	}
	for (int i = 0; i < 10000000; i++) {
		maxv = max(maxv, y[i]);
	}
	for (int i = 0; i < 10000000; i++) {
		if (y[i] == maxv) { cout << i << endl; }
	}
}

Measured memory_bytes: 38024
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
using Graph = vector<vector<pair<int, bool> > >;

int main() {
  int N;
  cin >> N;
  Graph A(N);
  for (int i = 0; i < N; i++) {
    int a;
    cin >> a;
    for (int j = 0; j < a; j++) {
      int x;
      bool y;
      cin >> x >> y;
      A[i].push_back(make_pair(x - 1, y));
    }
  }

  int ans = 0;
  // ビットが立ってる時正直者
  for (int mask = 0; mask < (1 << N); mask++) {
    // 矛盾があるかないか
    bool OK = true;
    for (int i = 0; i < N; i++) {
      // i人目を正直者とした場合を考える（不親切なら発言内容はどうでもいい）
      if ((1 << i) & mask) {
        for (pair<int, bool> P : A[i]) {
          if (((1 << P.first) & mask) > 0 && P.second == 0) OK = false;
          if (((1 << P.first) & mask) == 0 && P.second == 1) OK = false;
        }
      } else
        continue;
    }

    if (OK) {
      // maskを2進数に、向きは反対になっているがこれでもOKのはず
      string bits = "";
      for (int i = 0; i < N; i++) {
        if ((1 << i) & mask)
          bits += '1';
        else
          bits += '0';
      }
      int sum = count(bits.begin(), bits.end(), '1');
      ans = max(sum, ans);
    }
  }

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

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include <queue>

using namespace std;
using ll = long long;


int main() {
	int N, K, Q;
	cin >> N >> K >> Q;
	vector<int> p(N, 0);

	for (int i = 0; i < Q; ++i) {
		int A;
		cin >> A;
		p[A - 1]++;
	}

	for (int i = 0; i < N; ++i) {
		if (K > (Q - p[i])) {
			cout << "Yes" << endl;
		}
		else {
			cout << "No" << endl;
		}
	}
	return 0;
}


Measured memory_bytes: 3796
#include <bits/stdc++.h>
using namespace std;
#define ALL(a) (a).begin(), (a).end()
#define FOR(i, s, n) for (int i = (s); i < (n); i++)
#define rep(i, n) FOR(i, 0, n)
#define repi(i, n) FOR(i, 1, n + 1)
#define pp(v) cout << #v "=" << (v) << endl;
#define ppa(v) cout << "----\n"; rep(i,v.size()) cout << #v << "[" << i << "] = " << v[i] << endl;
#define div_ceil(a,b) ((a) + ((b) - 1)) / (b)

int main() {
  int a,b; cin>>a>>b;
  bool ans = a*b&1==1;
  cout << (ans ? "Yes" : "No") << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <queue>
#include <map>
using namespace std;
typedef long long ll;
const int INF = 1<<30; 
const int MOD = 1e9 + 7;
const int dy[] = {1, 0, -1, 0};
const int dx[] = {0, 1, 0, -1};
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int H, W; cin >> H >> W;
    int h, w; cin >> h >> w;
    int S = H * W;
    S -= h * w;
    S -= (H - h) * w;
    S -= h * (W - w);
    cout << S << endl;
    return 0;
}



Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int x = scan.nextInt();
		int t = scan.nextInt();
		int a;

		if(n % x ==0) {
			a = n / x;
		}else {
			a = n / x + 1;
		}
		System.out.println(a * t);
	}
}


Measured memory_bytes: 35620
//From Naruto to Hokage
//#include <RJ>
#include<bits/stdc++.h>
using namespace std;

#define ll          long long
#define pb          push_back
#define endl        '\n'
#define mii         map<ll,ll>
#define pii         pair<ll,ll>
#define vi          vector<ll>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll)x.size()
#define hell        1000000007
#define INF         (1ll<<60)
#define rep(i,a,b)  for(ll i=a;i<=b;i++)
#define rrep(i,a,b)  for(ll i=a;i>=b;i--)
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define time        cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll lcm(ll a, ll b) { return a * (b / gcd(a, b)); }
const int N=100005;
void solve(){
    ll n,m,a,b;
    cin>>n>>m>>a>>b;
    ll lima=n/2;
    ll limb=m/2;
    if(a>limb || b>lima){
        cout<<"-1";
        return;
    }
    rep(i,0,n-1-b){
        rep(j,0,a-1) cout<<"0";
        rep(j,a,m-1) cout<<"1";
        cout<<endl;
    }
    rep(i,n-b,n-1){
        rep(j,0,a-1) cout<<"1";
        rep(j,a,m-1) cout<<"0";
        cout<<endl;
    }
}
signed main()
{
    ios
    int TESTS=1;
    //cin>>TESTS;
    while(TESTS--){
        solve();
    }
    time
    return 0;
}

Measured memory_bytes: 1280
#include <iostream>
#include <algorithm>
#include <string>

using namespace std;

int main()
{
  string S;
  int change;

  cin >> S;
  for (size_t i = 0; i < S.size(); ++i)
  {
    // Check pattern which starts with 0 (01010101 ...)
    if (i % 2 == 0 && S[i] == '0') {
      ++change;
    } else if (i % 2 == 1 && S[i] == '1') {
      ++change;
    }
  }
  cout << min(change, int(S.size() - change)) << endl;
  return 0;
}

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

using namespace std;

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

    int n,m;
    cin>>n>>m;

    if(n==m)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        // ABC158C - Tax Increase

        Scanner sc = new Scanner(System.in);

        int a = sc.nextInt();
        int b = sc.nextInt();

        int ans = -1;
        for (int i = 1; i <= 10000; i++) {
            if ((int)(i * 0.08) == a && 
                (int)(i * 0.10) == b) {
                    ans = i;
                    break;
                }
        }
        
        
       System.out.println(ans);
    }
}

Measured memory_bytes: 23764
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e3+7;
const int maxm=2e3+7;
//int M[maxn][maxn];
vector<int> edge[maxn];
int main()
{
	int n,m;scanf("%d%d",&n,&m);
	for(int i=1;i<=m;i++)
	{
		int u,v;scanf("%d%d",&u,&v);
		u--;v--;
		edge[u].push_back(v);
	}
	vector<int> ans;int mn=maxn;
	for(int s=0;s<n;s++)
	{
		vector<int> dis(maxn,-1);
		vector<int> pre(maxn,-1);
		queue<int> q;q.push(s);dis[s]=0;
		while(!q.empty())
		{
			int tmp=q.front();q.pop();
			for(int i=0;i<edge[tmp].size();i++)
			{
				int u=edge[tmp][i];
				if(dis[u]==-1)
				dis[u]=dis[tmp]+1,q.push(u),pre[u]=tmp;
			}
		}
		//for(int i=0;i<n;i++) cout<<dis[i]<<" ";
		//cout<<endl;	
		for(int t=0;t<n;t++)
		{
			if(dis[t]==-1||s==t) continue;
			vector<int> res;
			for(auto nt:edge[t])
			{
				if(nt==s)
				{
					int c=t;res.push_back(s);
					while(c!=s) res.push_back(c),c=pre[c];
					if(res.size()<mn)
					{
						mn=res.size();
						ans=res;
					}
				}
			}
		}
	}
	if(ans.size())
	{
		cout<<ans.size()<<endl;
		for(auto u:ans) cout<<u+1<<endl;
	}
	else puts("-1");
}

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

int main(void) {
	int N;
	cin >> N;
	int fN=0;
	int M = N;

	for (int i = 0; i < 8; i++) {
		fN += (N % 10);
		N -= (N % 10);
		N /= 10;
	}

	if (M % fN == 0) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}

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

#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define trav(a, x) for (auto& a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

int main() {
	int n; cin >> n;
	ll sum = 0;
	rep(i, 0, n) {
		int t; cin >> t;
		sum += t;
	}
	if (sum % 2 == 0) cout << "YES" << endl; else cout << "NO" << endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define MOD 1000000007
using namespace std;

typedef pair<int, int> P;
typedef pair<long long, long long> LLP;

int H, W;

P getNext(P pos) {
    P next = pos;
    if (next.first % 2 == 0) {
        if (next.second == W - 1) next.first++;
        else next.second++;
    } else {
        if (next.second == 0) next.first++;
        else next.second--;
    }
    return next;
}

bool isFinished(P pos) {
    if (H % 2 == 0) return pos.second == 0 && pos.first == H - 1;
    else return pos.second == W - 1 && pos.first == H - 1;
}

int main() {
    cin >> H >> W;
    int a[H][W];
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            scanf("%d", &a[i][j]);
        }
    }
    vector<P> ans_before, ans_after;
    P pos;
    pos.first = 0;
    pos.second = 0;
    bool hasCoin = false;

    while (!isFinished(pos)) {
        if (a[pos.first][pos.second] % 2 == 1) {
            if (hasCoin) hasCoin = false;
            else {
                hasCoin = true;
                ans_before.push_back(pos);
                ans_after.push_back(getNext(pos));
            }
        } else {
            if (hasCoin) {
                ans_before.push_back(pos);
                ans_after.push_back(getNext(pos));
            }
        }
        pos = getNext(pos);
    }

    cout << ans_before.size() << endl;
    for (int i = 0; i < ans_before.size(); i++) {
        printf("%d %d %d %d\n", ans_before[i].first + 1, ans_before[i].second + 1, ans_after[i].first + 1, ans_after[i].second + 1);
    }

    return 0;
}

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

// GCD, LCM
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

int main()
{
    ll X,i=100,ans=0;

    cin >> X;

    while(i<X){
        i*=1.01;
        ans++;
    }

    cout<<ans<<endl;

    return 0;
}

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

using namespace std;

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

    vector<int64_t> A(N);
    for (auto & x : A)
        cin >> x;

    vector<int64_t> dp1(N);
    vector<int64_t> dp2(N);
    dp1[0] = 0;
    dp1[1] = max(A[0], A[1]);
    dp2[0] = A[0];
    dp2[1] = max(A[0], A[1]);
    for (int i = 2; i < N; ++i)
    {
        dp2[i] = max(A[i] + dp2[i - 2], (i % 2) ? dp2[i-1] : (A[i] + dp2[i - 2]));
        dp1[i] = max(A[i] + dp1[i - 2], dp2[i-1]);
    }

    cout << dp1[N-1] << endl;

    /*if (N % 2 == 0)
    {
        int64_t odds = 0;
        int64_t evens = 0;

        for (int i = 0; i < N; i += 2)
        {
            odds += A[i];
        }

        for (int i = 1; i < N; i += 2)
        {
            evens += A[i];
        }

        cout << ((odds > evens) ? odds : evens) << endl;
    }
    else
    {
        int64_t median = A[N / 2];
        int64_t withMedian;
        int64_t withoutMedian;

        int64_t oddsBefore = 0;
        int64_t oddsAfter = 0;
        int64_t evensBefore = 0;
        int64_t evensAfter = 0;
        for (int i = 0; i < (N / 2) - 1; i++)
        {
            if (i % 2 == 0)
                oddsBefore += A[i];
            else
                evensBefore += A[i];
        }

        for (int i = (N / 2) + 2; i < A.size(); i++)
        {
            int j = i - (N / 2) + 2;
            if (j % 2 == 0)
                oddsAfter += A[i];
            else
                evensAfter += A[i];
        }

        withMedian = median + max(oddsBefore, evensBefore) + max(oddsAfter, evensAfter);

        oddsBefore = 0;
        oddsAfter = 0;
        evensBefore = 0;
        evensAfter = 0;
        for (int i = 0; i < (N / 2); i++)
        {
            if (i % 2 == 0)
                oddsBefore += A[i];
            else
                evensBefore += A[i];
        }
        for (int i = (N / 2) + 1; i < A.size(); i++)
        {
            int j = i - (N / 2) + 1;
            if (j % 2 == 0)
                oddsAfter += A[i];
            else
                evensAfter += A[i];
        }

        withoutMedian =  max(oddsBefore, evensBefore) + max(oddsAfter, evensAfter);

        cout << ((withMedian > withoutMedian) ? withMedian : withoutMedian) << endl;
    }*/

    return 0;
}


Measured memory_bytes: 8004
num = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

ans = 0
for n in range(num):
    if b[n] <= a[n]:
        ans += b[n]
        a[n] -= b[n]
    else:
        b[n] -= a[n]
        ans += a[n]
        a[n] = 0
        if b[n] <= a[n+1]:
            ans += b[n]
            a[n+1] -= b[n]
        else:
            ans += a[n+1]
            b[n] -= a[n+1]
            a[n+1] = 0

print(ans)




Measured memory_bytes: 18624
//#include "bits/stdc++.h"

#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>
#include<iomanip>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

//typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<int, double> pid;
typedef pair<double, int> pdi;
typedef pair<double, double> pdd;
typedef vector< vector<int> > mat;

template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

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

	int N, L;
	cin >> N >> L;

	vector<string> S(N);
	rep(i, 0, N)
	{
		cin >> S[i];
	}

	sort(all(S));

	rep(i, 0, N)
	{
		cout << S[i];
	}
	cout << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>


using namespace std;



int main(void){
    int N;
    scanf("%d",&N);
    int max=0;
    int ans=0;
    for(int i=0;i<N;i++){
        int po;
        scanf("%d",&po);
        if(max<po)max=po;
        ans+=po;
    }
    ans-=max/2;
    printf("%d",ans);
    return 0;
}


Measured memory_bytes: 384
n,m=map(int,input().split())
li=[tuple(map(int,input().split())) for i in range(m)]


#まず各頂点ごとに、どの頂点とつながってるかのリスト作る？
cho=[]
for i in range(n):
  temp=[]
  for x,y in li:
    if x==i+1:
      temp.append(y)
    if y==i+1:
      temp.append(x)
  cho.append(temp)
#cho[0]は、頂点1がどの頂点とつながってるかを記録してる


ans=0

#全ての頂点を訪問するまで深堀り続けるコードを書く。
#全てを訪問する前に、訪問済み頂点に来てしまったらbreak。
zumi=[1]
queue=[[cho[0],0,len(cho[0])]]
dankai=0

#print(queue)
while 1:
  #print("今は",dankai,"段目のを調べてます")
  if queue[dankai][1]<queue[dankai][2]:
    bango=queue[dankai][0][queue[dankai][1]]
    if bango not in zumi: #それが訪問済みの点でなければ、次にその頂点のchoを調べよう。
      dankai+=1
      #print("訪問済みじゃないので次の段を調べます")
      zumi.append(bango) #それを訪問済みにする。
      queue.append([cho[bango-1],0,len(cho[bango-1])])
      #「その頂点番号につながってる頂点」「その段階において、何番目を現在調査中か」「その段階の長さ」
      if dankai==n-1:
        ans+=1 #全部の頂点を調べ終わったら、答えが増えたということのため、+1する。
    else: #それが訪問済みの点であれば、同じ段階の次の点を訪問しよう
      #print("これは訪問済みなので同じ",dankai,"段目の次の頂点を調べます")
      queue[dankai][1]+=1
  else:
    #print("どうやらこの段目にはもう頂点がないので、ひとつ前の段に戻り、その段の次の頂点に移ります")
    dankai-=1
    if dankai<0:
      break
    #その段目の番号について、訪問済み
    zumi.pop()
    queue.pop()
    queue[dankai][1]+=1
    #そうやっていって、cho[0]の点を全て調べ終わってしまったら、末尾を削除し、上の段階に戻る。
print(ans)

Measured memory_bytes: 3188
#include <stdio.h>

int main(void)
{
	int sum,i,hon;
	
	while(1){
		scanf("%d",&sum);
		
		if(sum == 0){
			break;
		}
		for(i = 0;i < 9;i++){
			scanf("%d",&hon);
			sum -= hon;
		}
		printf("%d\n",sum);
	}
	
	return(0);
}

Measured memory_bytes: 1724
#配るDPで今度は解いてみる。
n=int(input())
H=list(map(int,input().split()))
#H[i]はi+1番目の足場の高さ
#dp[n] nまでのminimumコストを選んだときのコスト

dp= [float('inf') for i in range(n+2)]
dp[0]=0
for i in range(n-2):
    dp[i+2]=min(dp[i+2],dp[i]+abs(H[i+2]-H[i]))
    dp[i+1]=min(dp[i+1],dp[i]+abs(H[i+1]-H[i]))
#i=n-2
dp[n-1]=min(dp[n-1], dp[n-2]+abs(H[n-1]-H[n-2]))
print(dp[n-1])

Measured memory_bytes: 13928
#include <iostream>
#include <cmath>

using namespace std;

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

    int sum = 0;
    for (int i = 0; i < m; i++) {
        int v;
        cin >> v;
        sum += v;
    }
    n -= sum;
    if (n >= 0) {
        cout << n << endl;
    } else {
        cout << -1 << endl;
    }
}


Measured memory_bytes: 3636
class PriorityQueue
  def initialize(&comp)
    @heap = []
    @node_num = 0
    if !block_given?
      @comp = Proc.new { |x, y| x <= y }
    else
      @comp = comp
    end
  end

  attr_reader :heap

  def push(x)
    i = @node_num # 自分のノード番号
    @node_num += 1
    while i > 0
      par = (i - 1) / 2 # 親のノード番号
      break if @comp.call(@heap[par], x) # 逆転してないなら抜ける
      # 親ノードを下ろして自分を上に
      @heap[i] = @heap[par]
      i = par
    end
    @heap[i] = x
  end

  alias_method(:<<, :push)

  def pop
    # 最(小|大)値
    ret = @heap[0]
    # 根にもってくる値
    @node_num -= 1
    x = @heap[@node_num]
    # 根から下ろしていく
    i = 0
    while i * 2 + 1 < @node_num
      # 子どうしを比較
      a, b = i * 2 + 1, i * 2 + 2
      a = b if b < @node_num && !@comp.call(@heap[a], @heap[b])
      break if @comp.call(x, @heap[a])
      @heap[i] = @heap[a]
      i = a
    end
    @heap[i] = x
    return ret
  end

  def get
    @node_num == 0 ? nil : @heap[0]
  end

  def empty?
    return get.nil?
  end
end

n, m = gets.split.map(&:to_i)
a = gets.split.map(&:to_i).sort.reverse
q = PriorityQueue.new(){ |x, y| x > y }
a.each do |ai|
    q << ai
end
m.times do
    max_n = q.pop()
    q << (max_n / 2)
end
p q.heap.inject(:+)


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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}


int nextInt() { int x; scanf("%d", &x); return x;}

bool isSorted(vector<int> p) {
  for (int i = 1; i < (int)p.size(); i++) {
    if (p[i-1] > p[i]) return false;
  }
  return true;
}
int main2() {
  int N = nextInt();
  vector<int> p(N);
  REP(i, N) p[i] = nextInt();

  bool ans = isSorted(p);
  for (int i = 0; i < N; i++) {
    for (int j = i + 1; j < N; j++) {
      swap(p[i], p[j]);
      if (isSorted(p)) ans = true;
      swap(p[i], p[j]);
    }
  }
  if (ans)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
  return 0;
}

int main() {

#ifdef LOCAL
  for (;!cin.eof();cin>>ws)
#endif
    main2();
  return 0;
}


Measured memory_bytes: 384
long M=1e9+7,m[1<<18],h,w,a,s;p(a,b)long a;{return b?p(a*a%M,b/2)*(b%2?a:1)%M:1;}main(i){for(*m=1;i<1<<18;)m[i]=m[i-1]*i++%M;for(scanf("%d%d%d%d",&h,&w,&a,&i);i<w;)s=(s+m[h-a-1+i]*p(m[h-a-1],M-2)%M*p(m[i],M-2)%M*m[a+w-i-2]%M*p(m[a-1],M-2)%M*p(m[w-1-i++],M-2)%M)%M;printf("%d",s);}

Measured memory_bytes: 2176
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  bool D;
  D = false;
  int a,b,c;
  a = N % 10;
  N -= a;
  N = N/10;
  b = N % 10;
  N -= b;
  N = N/10;
  c = N % 10;
  if ( a == 7 ){
    D = true;
  }
  if ( b == 7 ) {
    D = true;
  }
  if ( c == 7 ) {
    D = true;
  }
  if ( D) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 3588
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <string>
#include <bitset>
#include <cstring>
#include <map>
#include <math.h>
#include <queue>
#include <set>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> P;
#define rep(i,n) for (int i = 0; i < n; i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define fir first
#define sec second
#define pb push_back
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 int INF = 1<<30;
const ll LINF = 1LL<<58;
const int mod = 1000000007;

int n, ans = INF, A, B, C;
vector<int> L;

void DFS(int i, int mp, int a, int b, int c){
	if(i == n){
		if(a==0 || b==0 | c==0)return;
		mp += abs(a-A) + abs(b-B) + abs(c-C) - 30;
		chmin(ans, mp);
		return;
	}
	DFS(i+1, mp, a, b, c);
	DFS(i+1, mp+10, a+L[i], b, c);
	DFS(i+1, mp+10, a, b+L[i], c);
	DFS(i+1, mp+10, a, b, c+L[i]);
}

int main(){
	cin >> n >> A >> B >> C;
	rep(i,n){
		int l;
		cin >> l;
		L.pb(l);
	}
	DFS(0,0,0,0,0);
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define F first
#define S second
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define Red ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define rep(i, n) for(int i =0 ; i < n; ++i)
#define pii pair < int, int >
typedef vector<int> vi;
typedef   long long ll;
const int mod =1e9+7;




void solve(){
	int n;
	cin>>n;
	int a[n+1],ans[n+1];
	for(int i=1;i<=n;i++){
		cin>>a[i];
		ans[a[i]]=i;
	}
	for(int i=1;i<=n;i++){
		cout<<ans[i]<<' ';
	}

}


int main(){
	Red;
	int t=1;
	//cin>>t;
	while(t--)
	solve();
	return 0;
}

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

int main() {
  int n;
  cin >> n;
  
  vector<int> d(n);
  for(int i=0 ; i<n ; i++){
    cin >> d[i];
  }
  
  int ans=0,x=1;
  while(x <= 100){
    for(int i=0 ; i<n ;i++){
      if(d[i] == x){
      ans++;
      break;
      }
    }
    x++;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Random;
import java.util.StringTokenizer;

//Main
public class Main {

	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		int n=sc.nextInt();
		if (n==0)
			System.out.println(1);
		if (n==1)
			System.out.println(0);

	}

	static final Random random = new Random();

	static void ruffleSort(int[] a) {
		int n = a.length;//shuffle, then sort 
		for (int i = 0; i < n; i++) {
			int oi = random.nextInt(n), temp = a[oi];
			a[oi] = a[i];
			a[i] = temp;
		}
		Arrays.sort(a);
	}

	static class FastScanner {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer("");

		String next() {
			while (!st.hasMoreTokens())
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		int[] readArray(int n) {
			int[] a = new int[n];
			for (int i = 0; i < n; i++)
				a[i] = nextInt();
			return a;
		}

		long nextLong() {
			return Long.parseLong(next());
		}
	}

}


Measured memory_bytes: 32584
#include<iostream>
#include<vector>
#include<cstring>
#include<cmath>
#include<set>
#include<queue>
#include<algorithm>
#include<climits>
#include<map>
#include<unordered_map>
#define ll long long

bool isPrime(ll n){
    if(n<=1)  return false;
    if(n<=3)  return true;
    if(n%2==0 || n%3==0) return false;
    for(ll i=5;i*i<=n;i=i+6)
        if(n%i==0||n%(i+2)==0)
           return false;
    return true;
}

#define w(t) ll t,tt=1;	cin>>t;		while(t--)
#define ps(x,y) fixed<<setprecision(y)<<x
#define setbits(x) __builtin_popcountll(x)
#define zrobits(x) __builtin_ctzll(x)
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define ff first
#define ss second
#define pb push_back
#define mp make_pair

#define vi vector<int>
#define vll vector<ll>
#define mii map<ll,ll>
#define umii unordered_map<ll,ll>
#define pi pair<int,int>
#define pll pair<ll,ll>
#define vpii vector<pair<int,int>>
#define vpll vector<pair<ll,ll>>

#define mod 1e9+7
#define inf 1e18

#define lln ll n; cin>>n
#define intn int n; cin>>n
#define YES cout<<"YES"
#define NO cout<<"NO"
#define strr    string str; cin>>str;
#define strn   n=str.length()
#define fr(a,n) for(ll i=a;i<n;i++)
#define loop for(ll i=0;i<n;i++)

using namespace std;

void solve (){
    intn;
    int ans=0;
    int num=0;
    fr(1,1e7){
        ++ans;
        num=(num*10+7)%n;
        if(!num){
            cout<<ans;
            return;
        }
    }
    cout<<-1;
}

int main(){
    IOS
    solve();
    return 0;
}

Measured memory_bytes: 3632
s=input()
numA = 0
ans = 0
for i in range(len(s)):
    if s[i] == 'A':
        numA += 1
    elif i < len(s)-1 and s[i] == 'B' and s[i + 1] == 'C':
        ans += numA
    elif i > 0 and s[i] == 'C' and s[i - 1] == 'B':
        pass
    else:
        numA = 0
print(ans)

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

int main() {
	int N;
	cin >> N;
  	vector<int> d(N);
  	int count = 0;
  	for(int i = 0; i < N; i++) {
      int nd = 0;
      cin >> nd;
      int j;
      for(j = 0; j < i; j++) {
        if(nd == d.at(j))
          break;
      }
      if(i == j) {
        d.at(i) = nd;
        count++;
      }
    }
  cout << count << endl;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
	"sort"
)

func main() {
	var N int
	fmt.Scan(&N)
	A := make([]int, 0, N)
	var input int
	for i := 0; i < N; i++ {
		fmt.Scan(&input)
		A = append(A, input)
	}
	num := 0
	for _, a := range A {
		if a < 0 {
			num += 1
		}
	}
	for i := 0; i < N; i++ {
		if A[i] < 0 {
			A[i] *= -1
		}
	}
	sort.Ints(A)
	var total uint64
	total = 0
	if num%2 == 0 {
		for _, a := range A {
			total += uint64(a)
		}
	} else {
		for i := 1; i < len(A); i++ {
			total += uint64(A[i])
		}
		total -= uint64(A[0])
	}

	fmt.Println(total)
}

Measured memory_bytes: 5504
#include<stdio.h>
void swap(int *, int *);
int main() {
	int x, y,r;
	scanf("%d%d", &x, &y);
	if (y > x) {
		swap(&x, &y);
	}
	while (y > 0) {
		r = x % y;
		x = y;
		y = r;
	}
	printf("%d", x);
	printf("\n");




	return 0;
}
void swap(int *x, int *y) {
	int temp;
	temp = *y;
	*y = *x;
	*x = temp;
}


Measured memory_bytes: 2108