akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int t = sc.nextInt();
    int c1;
    int t1;
    int cmin = 1024;
    for(int i=0; i<n; i++){
      c1 = sc.nextInt();
      t1 = sc.nextInt();
      if(t1 <= t){
        if(c1 < cmin)
          cmin = c1;
      }
    }
    if(cmin == 1024)
      System.out.println("TLE");
    else
      System.out.println(cmin);
  }
}


Measured memory_bytes: 23636
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    void run() {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long[] as = new long[n];
        int[] bc = new int[60];
        for (int i = 0; i < n; i++) {
            as[i] = sc.nextLong();
            for (int j = 0; j < 60; j++) {
                if (((as[i] >> j) & 1) == 1) {
                    bc[j]++;
                }
            }
        }

        long MOD = (long)1e9 + 7;
        long ans = 0;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < 60; j++) {
                if (((as[i] >> j) & 1) == 0) {
                    ans = (ans + (1L << j) % MOD * (bc[j])) % MOD;
                } else {
                    ans = (ans + (1L << j) % MOD * (n - bc[j])) % MOD;
                }
            }
        }
        long div = MOD / 2 + 1;
        System.out.println(ans * div % MOD);

    }

    void debug(Object... os) {
        System.err.println(Arrays.deepToString(os));
    }

    public static void main(String[] args) {
        new Main().run();
    }

}


Measured memory_bytes: 99536
#include <iostream>
#include <vector>

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

    int s = 1;
    for (int i=0; i<N; ++i) {
        int a;
        std::cin >> a;
        if (a == s) {
            s += 1;
        }
    }
    if (s == 1) {
        std::cout << -1 << std::endl;
    } else {
        std::cout << N - (s-1) << std::endl;
    }
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

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


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

vector<int> v;

long long int dfs(const vector<vector<int>> &graph, int now, int from)
{
    for (auto e : graph[now])
    {
        if (e == from)
            continue;

        v[e] += v[now];
        //cout<<e<<" "<<now<<" "<<v[e]<<endl;
        dfs(graph, e, now);
    }
}

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

    vector<vector<int>> graph(N);
    for (int i = 0; i < N; i++)
    {
        //v[i] = 0;
        v.push_back(0);
    }

    for (int i = 0; i < N - 1; ++i)
    {
        int a, b;
        cin >> a >> b;
        a--;
        b--;

        graph[a].push_back(b);
        graph[b].push_back(a);
    }
    for (int i = 0; i < Q; i++)
    {
        int p, x;
        cin >> p >> x;
        p--;
        v[p] += x;
    }

    dfs(graph, 0, -1);

    for (int i = 0; i < N; i++)
    {
        cout << v[i] << " ";
    }
    cout<<endl;

    return 0;
}

Measured memory_bytes: 26612
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

typedef pair<int, int> frac;

int P, Q, A, N;

frac Minus(frac f1, frac f2)
{
  frac f = make_pair(f1.first * f2.second - f1.second * f2.first, f1.second * f2.second);
  //printf("f.first, f.second = %d, %d\n", f.first, f.second);
  int a = abs(max(f.first, f.second));
  int b = abs(min(f.first, f.second));
  //printf("a, b = %d, %d\n", a, b);
  while (b > 0) {
    int t = b;
    b = a % b;
    a = t;
  }
  //printf("a = %d\n", a);
  f.first /= a;
  f.second /= a;
  return f;
}

int cmp(frac f1, frac f2)
{
  //cout << f1.first * f2.second - f2.first * f1.second << endl;;
  return f1.first * f2.second - f2.first * f1.second;
}

int search(frac f, int p, int n, int MIN)
{
  //printf("(f, p, n, MIN) = (%d / %d, %d, %d, %d)\n", f.first, f.second, p, n, MIN);
  int sum = 0;
  if (f.first == 0) {return 1;}
  if (A/p == 1 || n == 0) {return 0;}
  int Max;
  for (Max = 2;; Max++) {
    int x = 1, c;
    for (c = 0; x <= A / p && c <= n; c++) {
      x *= Max;
    }
    //printf("MAX, c = %d, %d\n", Max, c);
    if (cmp(f, make_pair(c, Max)) > 0) {
      //printf("ok\n");
      break;
    }
  }

  for (int m = min(Max, A/p); cmp(f, make_pair(1, m)) >= 0 && m >= MIN; m--) {
    //printf("m = %d\n", m);
    sum += search(Minus(f, make_pair(1, m)), p * m, n - 1, m);
  }
  //printf("ret: sum = %d\n", sum);
  return sum;
}

int main()
{
  while (scanf("%d %d %d %d ", &P, &Q, &A, &N) == 4) {
    if (P == 0 && Q == 0 && A == 0 && N == 0) {break;}
    
    cout << search(make_pair(P, Q), 1, N, 1) << endl;
  }
  return 0;
}

Measured memory_bytes: 884
#include <iostream>
#include <iomanip>

#define MAX_N 10

int a[MAX_N+1][MAX_N+1];
int n;

void solve() {
    // row sum
    for (int i=0; i<n; i++) {
        a[i][n] = 0;
        for (int j=0; j<n; j++) {
            a[i][n] += a[i][j];
        }
    }
    // column sum
    for (int j=0; j<n; j++) {
        a[n][j] = 0;
        for (int i=0; i<n; i++) {
            a[n][j] += a[i][j];
        }
    }
    // total sum
    a[n][n] = 0;
    for (int i=0; i<n; i++) a[n][n] += a[i][n];

    // output
    for (int i=0; i<n+1; i++) {
        for (int j=0; j<n+1; j++) {
            std::cout << std::setw(5) << a[i][j];
        }
        std::cout << std::endl;
    }
}

int main() {
    while(std::cin >> n, n) {
        for (int i=0; i<n; i++) {
            for (int j=0; j<n; j++) {
                std::cin >> a[i][j];
            }
        }
        solve();
    }
}



Measured memory_bytes: 3080
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <memory>
#include <numeric>
#include <set>
#include <stack>
#include <string>
#include <vector>

#define INF 1000000000
#define MOD 1000000007
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
#define int long long

struct Setup {
    Setup() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(20);
    }
} SETUP;

signed main() {
    int k;
    string s;
    cin >> k >> s;
    map<char, int> mp;
    for (auto c : s) {
        mp[c]++;
    }

    int ans = 1;
    for (auto p : mp) {
        ans = (ans * (p.second + 1)) % MOD;
    }
    cout << ans - 1 << endl;
}


Measured memory_bytes: 512
# def fibb(n):
#     if n == 1 or n == 2:
#         return 1
#     else:
#         return fibb(n-1)+fibb(n-2)

n = int(input())
fibb = [0]*45
fibb[0:2] = [1,1]
for i in range(2,45):
    fibb[i] = fibb[i-1] + fibb[i-2]
print(fibb[n])


Measured memory_bytes: 5600
#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
#define FIO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long
#define vi vector<ll>
#define pb push_back
#define F first
#define S second
#define all(v) (v).begin(),(v).end()
#define pii pair<ll,ll>
#define vii vector<pii>
#define MOD 1000000007LL
#define mod2 10000007LL
#define calc_fact(n) tgamma(n+1)


signed main()
{
    FIO;
    ll n,a,ans=0,j=1;
    cin>>n;
    vi v;
    for(ll i=0;i<n;i++)
    {
        cin>>a;
        v.pb(a);
    }
    sort(v.rbegin(),v.rend());
    ans=v[0];
    ll cnt=n-2;
    while(j<n and cnt>0)
    {
        if(cnt==1)
        ans+=v[j];
        else
        ans+=(v[j]*2);
        j++;
        cnt-=2;
    }
    cout<<ans;
}

Measured memory_bytes: 5324
N=int(input())
H=list(map(int,input().split()))

def loop(H):
    tmp=0
    for h in H:
        if h<tmp:
            return("No")
        elif tmp <=h-1:
            tmp=h-1
        elif tmp<=h:
            tmp=h
    return "Yes"
print(loop(H))

Measured memory_bytes: 14380
def main():
    N = int(input())
    A = [int(input()) for i in range(N)]
    L = [0]*(N+1)
    for i, a in enumerate(A, start=1):
        L[i] = max(L[i-1], a)

    R = [0]*(N+2)
    for i in range(N)[::-1]:
        R[i] = max(R[i+1], A[i])

    for i in range(N):
        print(max(L[i], R[i+1]))


if __name__ == '__main__':
    main()


Measured memory_bytes: 92872
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin >> n;
    vector<long long int> a,b;
    for(int i = 0;i < n + 1;i++)
    {
        long long int x;
        cin >> x;
        a.push_back(x);
    }
    for(int i = 0;i < n;i++)
    {
        long long int x;
        cin >> x;
        b.push_back(x);
    }
    long long int count = 0;
    for(int i = 0;i < n;i++)
    {
        if(b.at(i) > a.at(i))
        {
            count += a.at(i);
            b.at(i) -= a.at(i);
            if(b.at(i) > a.at(i + 1))
            {
                count += a.at(i + 1);
                a.at(i + 1) = 0;
            }
            else
            {
                count += b.at(i);
                a.at(i + 1) -= b.at(i);
            }    
        }
        else
        {
            count += b.at(i);
        }
    }
    cout << count;
    
    return 0;
}

Measured memory_bytes: 2548
#include<stdio.h>
#include<stdlib.h>
struct node{   
  int key;
  struct node *parent;
  struct node *right;
  struct node *left;
};
typedef struct node *Node;
Node root;
void insert(int);
void preorder(Node);
void inorder(Node);
int binarysearch(int key, Node root);
int main()
{
  int size, key;
  char Op[10];  

  scanf("%d",&size);

  for(int i=0;i<size;i++){
    scanf("%s",Op);
    if(Op[0]=='i')
    {
      scanf("%d",&key);
      insert(key);
    }
    if(Op[0]=='f')
    {
       scanf("%d",&key);
       if(binarysearch(key,root)==0)
           printf("no\n");
       else
           printf("yes\n");
       
    }
    if(Op[0]=='p')
    {
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
      
    }
  }
  return 0;
}

void insert(int key)
{
  Node y,x,z;
  y=NULL;
  x=root;
  z=malloc(sizeof(struct node));
  z->key=key;
  z->left=NULL;
  z->right=NULL;
  while(x!=NULL){
    y=x;
    if( z->key < x->key )x=x->left;
    else x=x->right;
  }
  z->parent=y;
  if(y==NULL){
    root=z;
  }
  else if(z->key<y->key){
      y->left=z;
  }
  else{
    y->right=z;
  }
}

void preorder(Node root)
{
  printf(" %d",root->key);
  if(root->left!=NULL){
    preorder(root->left);
  }
  if(root->right!=NULL){
    preorder(root->right);
  }
   
}
void inorder(Node root)
{
  if(root->left!=NULL ){
    inorder(root->left);
  }
    printf(" %d",root->key);
  if(root->right!=NULL ){
    inorder(root->right); 
  }
}

int binarysearch(int key, Node root)
{
  Node T;
  T=root;
  while(T!=NULL && T->key!=key){
    if(key<T->key)T=T->left;
    else T=T->right;
  }
  if(T==NULL)return 0;
  else return 1;
}



Measured memory_bytes: 20468
use std::io::Read;
use std::cmp::max;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf);
    let mut iter = buf.split_whitespace();
    let x:i32 = iter.next().unwrap().parse().unwrap();
    let y:i32 = iter.next().unwrap().parse().unwrap();
    println!("{}", max(max(x+y, x-y), x*y));
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int i,ii,n=0,t;
  cin >> t;
  while(cin >> i >> ii){
    if(i == ii){
      n++;
    }else{
    n = 0;
    }
    if(n == 3){
      cout << "Yes";
      return 0;
    }
  }
  cout << "No";
  return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define SORT(x) sort((x).begin(), (x).end())
#define ALL(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < n; i++)
#define reps(i, m, n) for (ll i = m; i < n; i++)
#define repr(i, m, n) for (ll i = m; i >= n; i--)
#define dame {cout<< "-1" <<"\n"; return;}
template <class T> bool maxi(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> bool mini(T &a, const T &b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
#define INF2 1000000000000000037
#define INF  1000000007
#define MOD  1000000007
#define PI (acos(-1))
using namespace std;
using ll = long long;
using ld = long double;
using P  = pair<ll,ll>;
//--GLOBAL---------------------------------

//--MAIN-----------------------------------
void Main() {
    ll N; cin>>N;
    ll ct=0;
    vector<ll> A(N);
    rep(i,N) cin>>A[i];
    if(A[0]!=0) dame;
    rep(i,N-1){
        if(A[i+1]>A[i]+1) dame;
        if(i==N-2 or A[i+2]!=A[i+1]+1) ct+=A[i+1];
    }
    cout<< ct <<"\n";
}
//--START----------------------------------
int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
}
//-----------------------------------------


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define ft first
#define sd second
#define fr(i,n) for(int i=0;i<(n);++i)
#define Fr(i,n) for(int i=1;i<=(n);++i)
#define ifr(i,n) for(int i=(n)-1;i>=0;--i)
#define iFr(i,n) for(int i=(n);i>0;--i)

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int h,w;
    cin>>h>>w;
    vector<vector<char>> s(h,vector<char>(w));
    fr(i,h) fr(j,w) cin>>s[i][j];
    vector<vector<int>> cv(h,vector<int>(w)),ch(h,vector<int>(w));
    int ka;
    fr(i,h){
        ka=0;
        fr(j,w+1){
            if(j==w||s[i][j]=='#'){
                if(ka){
                    for(int k=j-1;k>=0&&s[i][k]=='.';--k){
                        ch[i][k]=ka;
                    }
                    ka=0;
                }
            }
            else{
                ka++;
            }
        }
    }
    fr(j,w){
        ka=0;
        fr(i,h+1){
            if(i==h||s[i][j]=='#'){
                if(ka){
                    for(int k=i-1;k>=0&&s[k][j]=='.';--k){
                        cv[k][j]=ka;
                    }
                    ka=0;
                }
            }
            else{
                ka++;
            }
        }
    }
    int ans=0;
    fr(i,h) fr(j,w) ans=max(ans,ch[i][j]+cv[i][j]-1);
    cout<<ans<<endl;
}

Measured memory_bytes: 35712
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <queue>
typedef long long ll;
//typedef pair<int, int> P;
const int INF = 1<<30; 
const int MOD = 1e9 + 7;
const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};
using namespace std;

int main()
{
    string s;
    ll cnt = 0;

    cin >> s;

    for(ll i=s.size()-1,j=0 ;i >= 0; i--){
        if(s[i] == 'W'){
            cnt += i-j;
            j++;
        }
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
int main()
{
    int n;
    cin >> n;
    long long dp[n + 100] = {0};
    int m;
    cin >> m;
    int a[m];
    for (int i = 0; i < m; i++)
    {
        cin >> a[i];
        dp[a[i]] = MOD;
    }
    dp[0] = 1;
    for (int i = 0; i <= n; i++)
    {
        if (dp[i] == MOD)
            continue;
        if (i >= 1 && dp[i - 1] != MOD)
            dp[i] += dp[i - 1];
        if (i >= 2 && dp[i - 2] != MOD)
            dp[i] += dp[i - 2];
        dp[i] %= MOD;
    }
    cout << dp[n] << endl;
}

Measured memory_bytes: 1408
#include <algorithm>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>

using namespace std;

int main()
{
  long long a, b, k;
  scanf("%lld%lld%lld", &a, &b, &k);
  if(b - a < 2 * k) {
    for(long long i = a; i <= b; i++) {
      printf("%lld\n", i);
    }
  } else {
    for(long long i = a; i < a + k; i++) {
      printf("%lld\n", i);
    }
    for(long long i = b - k + 1; i <= b; i++) {
      printf("%lld\n", i);
    }
  }
  return 0;
}


Measured memory_bytes: 888
/*Function Template*/
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int MAX = 510000;
const int MOD = 1000000007;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define Rep(i, n) for(ll i = 1; i < (n); i++)
#define ALL(a)  (a).begin(),(a).end()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll fac[MAX], finv[MAX], inv[MAX];


template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }

}
ll Len(ll n) {
  ll s=0;
  while(n!=0) s++, n/=10;
  return s;
}


ll Sint(ll n) {
  ll m=0,s=0,a=n;
  while(a!=0) s++, a/=10;
  for(ll i=s-1;i>=0;i--) m+=n/((ll)pow(10,i))-(n/((ll)pow(10,i+1)))*10;
  return m;
}


ll Svec(vector<ll> v){
  ll n=0;
  for(ll i=0;i<v.size();i++) n+=v[i];
  return n;
}


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;
}


ll Factorial(ll n){
  ll m=1;
  while(n>=1) m*=n,n--;
  return m;
}

void runlength(string s,vector<pair<char,ll>> &p){
  ll x=1;
  if(s.size()==1){
    p.push_back(pair<char,ll>(s[0],1));
  }
  for(ll i=0;i<s.size()-1;i++){
    if(s[i]==s[i+1]){
      x++;
      if(i==s.size()-2){
        p.push_back(pair<char,ll>(s[i],x));
      }
    }else{
      p.push_back(pair<char,ll>(s[i],x));
      x=1;
      if(i==s.size()-2){
        p.push_back(pair<char,ll>(s[s.size()-1],x));
      }
    }
  }
}




ll COM(ll n,ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

const int MAX_N=100010;
vector<bool> sieve_of_eratosthenes(){
  vector<bool> isPrime(MAX_N+1,true);
  for(int i=2;i<=MAX_N;i++){
    if(isPrime[i]){
      for(int j=2*i;j<=MAX_N;j+=i){
        isPrime[j]=false;
      }
    }
  }
  return isPrime;
}



/*↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/
int main() {
  IOS;
  ll n;
  string s;
  cin>>n>>s;
  ll left=0;
  ll right=0;
  rep(i,s.size()){
    if(s[i]=='(') right++;
    if(s[i]==')'){
      if(right==0) left++;
      else right--;
    }
  }
  string ans="";
  rep(i,left) ans+='(';
  ans+=s;
  rep(i,right) ans+=')';
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

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

    int x, m;
    cin >> x >> m;

    if (n < 1000000) {
        ll s = 0;
        for (int i = 0; i < n; i++) {
            s += x;
            x = (ll)x * x % m;
        }
        cout << s << endl;
        exit(0);
    }

    vector<int> a(m), b(m, -1);
    int i1 = -1, i2 = -1;
    for (int i = 0;; i++) {
        if (b[x] < 0) {
            a[i] = x;
            b[x] = i;
            x = (ll)x * x % m;
        } else {
            i1 = i;
            i2 = b[x];
            break;
        }
    }

    ll s = 0;
    for (int i = i2; i < i1; i++) {
        s += a[i];
    }
    int l = i1 - i2;
    n -= i2;
    ll k = n / l;
    s *= k;
    for (int i = i2; i < i2 + (int)(n - k * l); i++) {
        s += a[i];
    }
    for (int i = 0; i < i2; i++) {
        s += a[i];
    }

    cout << s << endl;

    return 0;
}

Measured memory_bytes: 4052
//#define _GLIBCXX_DEBUG
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmax(T& a, 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 1; } return 0; }
const int INF = 1000000000;

int main() {
    IOS;
    ll N;
    cin >> N;
    N--;
    ll ans = 0;
    // https://oeis.org/search?q=5%2C8%2C10%2C14%2C16%2C20&sort=&language=english&go=Search
    for (int k=1; k<=N; k++){
        ans += N/k;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3648
package main

import "fmt"

func main() {
	// Code for C - Strange Bank
	var N int
	fmt.Scan(&N)

	//N = 127
	var ans int
	var min int = 1000000
	var temp int
	var count int
	for i := 0; i <= N; i++ {
		if 6*i > N {
			break
		}
		for j := 0; j <= N; j++ {
			ans = 0
			if 6*i+9*j > N {
				break
			} else {
				ans += N - 6*i - 9*j

				temp = i
				for {
					count = temp / 6
					ans += temp % 6
					if count != 0 {
						temp = count
					} else {
						break
					}
				}

				temp = j
				for {
					count = temp / 9
					ans += temp % 9
					if count != 0 {
						temp = count
					} else {
						break
					}
				}

				if min > ans {
					min = ans
					//fmt.Println(6*i, 9*j, N-6*i-9*j, ans)
				}
			}
		}
	}

	fmt.Println(min)
}


Measured memory_bytes: 1788
#include<stdio.h>
#include<string.h>
#define Max(x,y) ((x>y)?x:y)
#define min(x,y) ((x<y)?x:y)
int d[10005][10005];
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
int main(){
	int n,r,i,j,k,a,b,x,y;
	int ma,mb,mx,my,ans1,ans2;
	while(1){
		scanf("%d%d",&n,&r);
		if(n==0 && r==0)break;
		memset(d,0,sizeof(d));
		ma=mb=10001;mx=my=-1;
		for(i=0;i<n;i++){
			scanf("%d%d%d%d",&a,&b,&x,&y);
			a++,b++,x++,y++;
			d[a][b]++;
			d[x][y]++;
			d[x][b]--;
			d[a][y]--;
			mx=Max(mx,Max(a,x));
			my=Max(my,Max(b,y));
			ma=min(ma,min(a,x));
			mb=min(mb,min(b,y));
		}
		mx++,my++;
		ans1=ans2=0;
		for(i=ma;i<=mx;i++){
			x=0;
			for(j=mb;j<=my;j++){
				x+=d[i][j];
				d[i][j]=x;
			}
		}
		for(j=mb;j<=my;j++){
				x=0;
			for(i=ma;i<=mx;i++){
				x+=d[i][j];
				d[i][j]=x;
				if(d[i][j]>0)ans1++;
				if(r==2){
					if(d[i-1][j]==0 && d[i][j]>0)ans2++;
					if(d[i][j]==0 && d[i-1][j]>0)ans2++;
					
					if(d[i][j-1]==0 && d[i][j]>0)ans2++;
					if(d[i][j]==0 && d[i][j-1]>0)ans2++;
				}
			}
		}
		/*if(r==2){
		for(i=ma;i<=mx;i++){
			for(j=mb;j<=my;j++){
					if(d[i][j]>0){
						for(k=0;k<4;k++)
							if(d[i+dy[k]][j+dx[k]]==0)ans2++;
					}
			}
		}
		}*/
		printf("%d\n",ans1);
		if(r==2)printf("%d\n",ans2);
	}
	return 0;
}

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

int main() {
  int a,b,c,d;
  string s;
  cin >> s;
  a = s[0]-'0';
  b = s[1]-'0';
  c = s[2]-'0';
  d = s[3]-'0';
  char op1,op2,op3;
  if(a+b+c+d == 7){
    op1 = '+';
    op2 = '+';
    op3 = '+';
  }
  if(a-b+c+d == 7){
    op1 = '-';
    op2 = '+';
    op3 = '+';
  }
  if(a+b-c+d == 7){
    op1 = '+';
    op2 = '-';
    op3 = '+';
  }
  if(a+b+c-d == 7){
    op1 = '+';
    op2 = '+';
    op3 = '-';
  }
  if(a-b-c-d == 7){
    op1 = '-';
    op2 = '-';
    op3 = '-';
  }
  if(a+b-c-d == 7){
    op1 = '+';
    op2 = '-';
    op3 = '-';
  }
  if(a-b+c-d == 7){
    op1 = '-';
    op2 = '+';
    op3 = '-';
  }
  if(a-b-c+d == 7){
    op1 = '-';
    op2 = '-';
    op3 = '+';
  }
  cout << a << op1 << b << op2 << c << op3 << d << '=' << 7 << endl;
}


Measured memory_bytes: 256
s = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
k = int(input())
print(s[k-1])

Measured memory_bytes: 38256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] str = Console.ReadLine().Split(' ');
            int[] num = Array.ConvertAll(str, new Converter<string, int>(s => int.Parse(s)));

            Array.Sort(num);

            for (int i = 0; i < num.Length; i++)
            {
                if (i == 0) Console.Write(""+ num[i]);
                else Console.Write(" " + num[i]);
            }
            Console.WriteLine();
        }
    }
}

Measured memory_bytes: 9244
import java.util.Scanner;

class Main{
    
    public static void main(String[] args){
        
        Scanner sc = new Scanner(System.in);
        
        int x = 1, y = 1, i = 1;
        
        while(i <= 3000){
            
            x = sc.nextInt();
            y = sc.nextInt();
            
            if(x == 0 && y == 0){
                break;
            }
            if(x >= y){
                System.out.printf("%d %d\n", y, x);
            }else if(y >= x){
                System.out.printf("%d %d\n", x, y);
            }
            
            i++;
        }
    }
}


Measured memory_bytes: 41056
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <cmath>
#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())

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 a, b;
    cin >> a >> b;

    if (1 <= a && a <= 9 && 1 <= b && b <= 9)
    {
        cout << a * b << endl;
    }
    else
    {
        cout << -1 << endl;
    }

    return 0;
}

Measured memory_bytes: 256
import collections
n = int(input())
a = [int(i) for i in input().split()]
q = int(input())
bc = []
for i in range(q):
  bc.append(list(map(int, input().split())))

c = collections.Counter(a)
ans = sum(a)
for i in range(q):
  add = bc[i][1] - bc[i][0]
  cnt = c[bc[i][0]]
  
  ans += cnt * add
  c[bc[i][1]] += c[bc[i][0]]
  c[bc[i][0]] = 0;
  
  print(ans)

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

#define ll long long
#define ii pair<ll, ll>
#define vi vector<int>
#define vl vector<ll>
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define ff first
#define ss second
#define pi acos(-1.0)
#define oo 1000000007
#define loo 10000000000000007

#define prime 1000000007

#define W(x) cerr << "\033[31m" << #x << " = " << x << "\033[0m" << "\n";
using namespace std;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	
	int mat[3][3];
	for (int i = 0; i < 3; ++i){
		for (int j = 0; j < 3; ++j){
			cin >> mat[i][j];
		}
	}

	int n; cin >> n;
	set<int> a;
	for (int i = 0; i < n; ++i){
		int x; cin >> x;
		a.insert(x);
	}

	for (int i = 0; i < 3; ++i){
		if(a.find(mat[i][0]) != a.end() && 
			a.find(mat[i][1]) != a.end() &&
			a.find(mat[i][2]) != a.end()){
			cout << "Yes\n";
			return 0;
		}
		if(a.find(mat[0][i]) != a.end() && 
			a.find(mat[1][i]) != a.end() &&
			a.find(mat[2][i]) != a.end()){
			cout << "Yes\n";
			return 0;
		}
	}
	if(a.find(mat[0][0]) != a.end() && 
		a.find(mat[1][1]) != a.end() &&
		a.find(mat[2][2]) != a.end()){
		cout << "Yes\n";
		return 0;
	}
	if(a.find(mat[2][0]) != a.end() && 
			a.find(mat[1][1]) != a.end() &&
			a.find(mat[0][2]) != a.end()){
			cout << "Yes\n";
			return 0;
		}

		cout << "No\n";



	
	return 0;
}

Measured memory_bytes: 3628
//S.G.N.//
#include <bits/stdc++.h>
using namespace std;
typedef vector< long long > vi;
typedef long long ll;
#define sz(a) int((a).size())
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define endl "\n"
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define fr(n) for(ll i=0;i<n;i++)
#define tr(a) for(auto it=a.begin();it!=a.end();it++)
#define N 998244353445 
#define PI 3.1415926535897932384
#define F first
#define S second
#define mp make_pair
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define mod 1000000007


void solve()
{
 ll n;
 cin>>n;
 ll a[n];
 fr(n)
 cin>>a[i];
    ll dp1[n][n];
    ll dp2[n][n];
    fr(n)
    {
      rep(j,0,n)
      {
        if(i==j){
          dp1[i][j]=0;
        
        dp2[i][j]=a[i];
      }
      else{
        dp1[i][j]=10000000000000000;
        dp2[i][j]=10000000000000000;
}

      }
    }
  rep(i,1,n+1)
  {
    rep(j,0,n-i+1)
    {
      rep(k,j,j+i-1){
      if(dp1[j][j+i-1]+dp2[j][j+i-1]>dp1[j][k]+dp1[k+1][j+i-1]+2*dp2[j][k]+2*dp2[k+1][j+i-1]){
      dp2[j][j+i-1]=dp2[j][k]+dp2[k+1][j+i-1];
      dp1[j][j+i-1]=dp1[j][k]+dp1[k+1][j+i-1]+dp2[j][k]+dp2[k+1][j+i-1];
    }
    }
    //cout<<dp1[j][j+i-1]<<" "<<dp2[j][j+i-1]<<endl;
    }
  }
cout<<dp1[0][n-1];
}
int main()
{
  
  #ifndef ONLINE_JUDGE
     * freopen("input.txt", "r", stdin);
      freopen("output.txt", "w", stdout);
  #endif
  FAST
  ll test;
test=1;
  //cin>>test;
  while(test--)
  {
    solve();
  }
  return 0;
}


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

using namespace std;

int main(){
  int N;
  unordered_set<string> v;
  
  cin >> N;
  for(int i=0; i<N; i++){
    string temp;
    cin >> temp;
    v.emplace(temp);
  }
  
  cout << v.size() << endl;
  return 0;
}

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

int main(){

	int a;
	int b;
	
	double d,r,f;

    cin >> a >> b ;
	
	d=a/b;
	r=a%b;
	f=1.00000*a/b;
	
	cout << fixed << setprecision(0) << d << " " << r << " " << fixed << setprecision(5) << f <<endl;
}

Measured memory_bytes: 3240
#include <math.h>
#include <iostream>

using namespace std;

int main()
{
  int n,x,y;
  
  cin >> n >> x >> y;
  
  int maxSub = min(x,y);
  
  int minSub = y + x - n;
  
  if( minSub < 0 ) minSub = 0;
  
  cout << maxSub << " " << minSub << endl;
}

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

int main(){
  int N;
  string S;
  cin>> N >> S;
  int str = S.length();
  for (int i = 0; i < str ; i++) {
  if (S[i] + N <= 'Z') {
    S[i] += N;
  } else {
    S[i] = S[i] + N - 26;
  }
  }
  cout << S << '\n';
}


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

using namespace std;

typedef long long ll;

vector<set<int>> graph(200001);
vector<bool> visited(200001, false);

int cnt = 0;

void dfs(int u) {
    visited[u] = true;
    cnt++;
    for(auto& v : graph[u]) {
        if(!visited[v])
            dfs(v);
    }
}

int main() {
    int n, m;
    cin >> n >> m;
    while(m--) {
        int x, y;
        cin >> x >> y;
        graph[x].insert(y);
        graph[y].insert(x);
    }

    int ans = 0;
    for(int i = 1; i <= n; i++) {
        if(!visited[i]) {
            dfs(i);
            ans = max(ans, cnt);
            cnt = 0;
        }
    }
    cout << ans << endl;

    return 0;
}



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

int main(){
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  int time = 0;
  if(B < C || D < A) {
    time =0;
  }else{
    time = min(B, D) - max(A, C);
  }
  
  cout << time << endl;
}

Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <iomanip>
using namespace std;
#define int long long

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

    int h,w,k; cin >> h >> w >> k;
    vector<vector<char> > c(h,vector<char>(w));

    for(int i = 0;i < h;i ++){
        for(int j = 0;j < w;j ++){
            cin >> c.at(i).at(j);
        }
    }

    vector<vector<char> > d(h,vector<char> (w));

    vector<int> seni(h+w+1);

    int ans = 0;
    int count;

    while(seni.at(0) == 0){
        for(int i = 0;i < h;i ++){
            for(int j = 0;j < w;j ++) d.at(i).at(j) = c.at(i).at(j);
        }

        for(int i = 0;i < h;i ++){
            if(seni.at(h+w-i) == 1){
                for(int j = 0;j < w;j ++) d.at(i).at(j) = '.';
            }
        }
        for(int i = 0;i < w;i ++){
            if(seni.at(w-i) == 1){
                for(int j = 0;j < h;j ++) d.at(j).at(i) = '.';
            }
        }

        count = 0;
        for(int i = 0;i < h;i ++){
            for(int j = 0;j < w;j ++){
                if(d.at(i).at(j) == '#') count ++;
            }
        }

        if(count == k) ans ++;

        seni.at(h+w) ++;

        for(int i = h+w;i > 0;i --){
            if(seni.at(i) > 1){
                seni.at(i) = 0;
                seni.at(i-1) ++;
            }
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define FOR(i, a, b) for(ll i = (ll)a; i <= (ll)b; i++)
#define DEC(i, a, b) for(ll i = (ll)a; i >= (ll)b; i--)
typedef pair<ll, ll> pi;
typedef pair<pi, ll> pii;
typedef pair<pi, pi> pipi;
#define f first
#define s second
typedef vector<ll> vi;
typedef vector<pi> vpi;
typedef vector<pii> vpii;
#define pb push_back
#define pf push_front
#define all(v) v.begin(), v.end()
#define disc(v) sort(all(v)); v.resize(unique(all(v)) - v.begin());
#define INF (ll) 1e9 + 100
#define LLINF (ll) 1e18
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define sandybridge __attribute__((optimize("Ofast"), target("arch=sandybridge")))
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());    //can be used by calling rng() or shuffle(A, A+n, rng)
inline ll rand(ll x, ll y) { ++y; return (rng() % (y-x)) + x; } //inclusivesss

ll n, x, m, vis[100005], ans, cur;
vi v;

int main() {
	fastio; cin >> n >> x >> m;
	FOR(i, 1, n) {
		if (vis[x] != 0) {
			ans += accumulate(v.begin(), v.begin()+vis[x]-1, 0ll);
			ll cyc = i - vis[x];
			ans += (n-vis[x]+1)/cyc * accumulate(v.begin()+vis[x]-1, v.end(), 0ll);
			ans += accumulate(v.begin()+vis[x]-1, v.begin()+vis[x]-1 + ((n-vis[x]+1) % cyc), 0);
			break;
		} else {
			vis[x] = i;
			cur += x;
			v.pb(x);
			x = (x*x) % m;
		}
	}
	cout << (ans == 0 ? cur : ans);
}


Measured memory_bytes: 4724
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <iterator>  // std::back_inserter()
#include <set>
#include <map>
#include <algorithm>  // std::copy()
#include <functional>  // std::greater<T>()
#include <utility>  // std::swap()
#include <numeric>  // accumulate(ALL(vec), 0)  0 は初期値
#include <cmath>
#include <climits>  // INT_MIN
#include <cctype>  // std::isdigit()
#include <iomanip>  // std::setprecision()
using namespace std;

#define ALL(obj) (obj).begin(), (obj).end()
#define REP(i, n) for (int i=0; i < (int)(n); i++)  // 0 ~ n-1
#define REPN(i, n) for (int i=1; i <= (int)(n); i++)  // 1 ~ n
#define MIN(vec) min_element(ALL((vec)))  // イテレータのため、値を取り出すときは * を先頭につける
#define MAX(vec) max_element(ALL((vec)))
#define IDX(vec, element_iter) distance((vec).begin(), element_iter)
#define SUM(vec) accumulate(ALL((vec)), 0)  // 0 は初期値
#define COPY(vec1, vec2) copy(ALL(vec1), back_inserter(vec2))  // vec1をvec2にコピーする vec2は空にしておく必要あり
typedef long long ll;

const int MOD = 1000000007;  // 1 000 000 007


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

    // input
    ll A, B, X;
    cin >> A >> B >> X;
    
    // calculation
    if (X == 1) {
        cout << B - A + 1 << "\n";
    } else {
        if (A == 0) {
            cout << (B/X) + 1 << "\n";
        } else {
            cout << ((B/X) + 1) - (((A-1)/X) + 1) << "\n";
        }
    }
    
    return 0;
}


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

int	main() {
	int N;
	cin >>N;
	vector<int> a(N+1);
	vector<int> B(N+1, -1);
	for (int i=1; i<=N; i++) cin >> a.at(i);
	int SS=0;
	for (int i=N; i>0; i--) {
		int j=i+i;
		int S=0;
		while (j<=N) {
			S+=B.at(j);
			j +=i;
		}
		if (a.at(i)==S%2) {
			B.at(i)=0;
		} else {
			B.at(i)=1;
			SS++;
		}
	}
	cout << SS << endl;
	if (0==SS) return 0;
	for (int i=1; i<=N; i++) {
		if (1==B.at(i)) {
			cout <<i <<' ';
		}
	}
	cout <<endl;
	return 0;
}




Measured memory_bytes: 2432
#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> llP;

ll mod(ll a, ll b){
  ll ret=a%b;
  if(ret<0) ret+=b;
  return ret;
}

ll modpow(ll a,ll b,ll c){
  ll res=1;
  while(b>0){
    if(b&1) res=mod(res*a,c);
    a=mod(a*a,c);
    b>>=1;
  }
  return res;
}

int main() {
  int n,k;
  cin>>n>>k;
  int r,s,p;
  cin>>r>>s>>p;
  string t;
  cin>>t;
  ll ans=0;
  for(int i=0;i<min(n,k);i++){
    int cnt=0;
    for(int j=i;j<n;j+=k){
      if(j==i){
        if(t[j]=='r')ans+=p;
        else if(t[j]=='s')ans+=r;
        else ans+=s;
        cnt++;
      }
      else{
        if(t[j]!=t[j-k]){
          if(t[j]=='r')ans+=p;
          else if(t[j]=='s')ans+=r;
          else ans+=s;
          cnt=1;
        }
        else{
          if(cnt%2==0){
            if(t[j]=='r')ans+=p;
            else if(t[j]=='s')ans+=r;
            else ans+=s;
          }
          cnt++;
        }
      }
    }
  }
  cout<<ans<<endl;
  return 0;
}



Measured memory_bytes: 3776
import java.awt.*;
import java.util.*;

public class Main {

    public static void main(String[] args) {
        // write your code here
        Scanner scanner = new Scanner(System.in);

        int h = scanner.nextInt();
        int w = scanner.nextInt();

        int[][] cost = new int[10][10];
        for (int i = 0; i < 10; i++) {
            Arrays.setAll(cost[i], i1 -> scanner.nextInt());
        }

        for (int i = 0; i < 10; i++) {
            if (i == 1) {
                continue;
            }
            int standard = cost[i][1];
            Deque<Point> stack = new ArrayDeque<>();
            for (int j = 0; j < 10; j++) {
                if (i == j) {
                    continue;
                }
                if (cost[i][j] < cost[i][1]) {
                    stack.addFirst(new Point(j, cost[i][j]));
                }
            }
            while (!stack.isEmpty()) {
                Point p = stack.removeFirst(); // 先頭の座標を取得後、削除
                for (int k = 0; k < 10; k++) {
                    if (p.x == k) {
                        continue;
                    }
                    int v = p.y + cost[p.x][k];
                    if (v < standard) {
                        if (k == 1) {
                            standard = v;
                        } else {
                            stack.add(new Point(k, v));
                        }
                    }
                }
            }
            cost[i][1] = standard;
        }
        long ans = 0;
        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                int v = scanner.nextInt();
                if (v > - 1) {
                    ans += cost[v][1];
                }
            }
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 56744
#define _USE_MATH_DEFINES
#define INF 100000000
#include <iostream>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>

using namespace std;

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

static const double EPS = 1e-8;


int tx[] = {-1,0,1,0};
int ty[] = {0,1,0,-1};

int path[501][501];


int main(){
	int n,k;
	while(~scanf("%d %d",&n,&k)){
		if(n==k && k==0) break;

		vector<string> nums;
		for(int i=0;i<n;i++){
			string num;
			cin >> num;
			nums.push_back(num);
		}

		sort(nums.begin(),nums.end());
		map<string,int> visited;


		vector<int> choice;
		for(int j=0;j<n-k;j++) choice.push_back(0);
		while(choice.size()!=n) choice.push_back(1);

		int res=0;
		do{
			vector<string> str;

			for(int j=0;j<choice.size();j++){
				if(choice[j]==1) str.push_back(nums[j]);
			}

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

			do{
				string num;
				for(int j=0;j<str.size();j++) num.append(str[j]);
				if(visited.find(num) == visited.end()){
					visited[num]=1;
					res++;
				}
			}while(next_permutation(str.begin(),str.end()));
		}while(next_permutation(choice.begin(),choice.end()));

		printf("%d\n",res);
	}
}

Measured memory_bytes: 0
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();

		int[] p = new int[n];
		int[] sei = new int[n];
		int count = 0;

		for (int i = 0; i < n; i++) {
			p[i] = sc.nextInt();
			sei[i] = p[i];
		}

		Arrays.parallelSort(sei);

		for (int i = 0; i < n; i++) {
			if (p[i] != sei[i]) {
				count++;
			}
		}

		if (count <= 2) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}

		sc.close();

	}
}

Measured memory_bytes: 35884
#include <bits/stdc++.h>
#define rep(a,n) for (int a = 0; a < (n); ++a)
using namespace std;
using ll = long long;
typedef pair<int,int> P;
typedef pair<ll,P> PP;
typedef vector<vector<int> > Graph;
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 ll INF = 1e18;

int main(){
    ll n;
    cin >> n;
    vector<string>st(n);
    rep(i,n)cin>>st[i];
    vector<string>yoko(n*2+1);
    vector<string>tate(n*2+1);
    rep(i,n){
        string now = st[i];
        now += st[i].substr(0,n-1);
        yoko[i]=now;
    }
    for(int i=n;i<2*n-1;i++){
        yoko[i]=yoko[i-n];
    }
    rep(i,n){
        string now = "";
        rep(j,n){
            now += st[j][i];
        }
        now += now.substr(0,n-1);
        tate[i]=now;
    }
    for(int i=n;i<2*n-1;i++){
        tate[i]=tate[i-n];
    }
    ll cnt = 0;
    rep(i,n){
        rep(j,n){
            bool flag = true;
            rep(k,n){
                if(tate[i+k].substr(j+k,n-k)!=yoko[j+k].substr(i+k,n-k))flag=false;
            }
            if(flag)cnt++;
        }
    }
    cout << cnt << endl;
    return 0;
}



Measured memory_bytes: 4540
#include <stdio.h>
#include<vector>
#include<iostream>
#include<string>
#include<deque>
#include<queue>
#include<stack>
#include<list>
#include<cmath>
using namespace std;


int main() {
	int n, m, c;
	int t;
	int sum=0;
	vector<int> B;
	int ans = 0;
	cin >> n >> m >> c;
	for (int i = 0; i < m; i++)
	{
		cin >> t;
		B.push_back(t);
	}

	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < m; j++)
		{
			cin >> t;
			sum += t * B[j];
		}
		if (sum > -1 * c)
		{
			ans++;
		}
		sum = 0;
	}
	cout << ans << endl;



	return 0;
}


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

int main() {
  string a;
  cin >> a;
  if ("A" <= a && a <= "Z") {
    cout << "A" << endl;
  }
  else if ("a" <= a && a <= "z") {
    cout << "a" << endl; 
  }
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i,a,n) for(ll i = a;i < n;i++)
#define rrep(i,a,n) for(ll i = n; i >= a;i--)
#define index_check(i,n) if(i > n-1 || i < 0) continue; 
#define LINF 1e18
#define INF 1e9
using namespace std;

#define fs first
#define sc second

using P = pair<ll,ll>;
using Pll = pair<P,ll>;
using PQ = priority_queue<P,vector<P>,greater<P>>;


const ll MOD = 1e9+7;


signed main(){
    string s;
    cin >> s;
    string t = "YAKI";
    if(s.size() < 4){
        cout << "No" << endl;
        return 0;
    }
    rep(i,0,4){
        if(s[i] != t[i]){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 3596
import unittest


class TestA(unittest.TestCase):
    def test_1(self):
        self.assertEqual(think(1, 3), 3)

    def test_2(self):
        self.assertEqual(think(0, 1), 0)

    def test_3(self):
        self.assertEqual(think(32, 21), 58)


def solve():
    a, p = read()
    result = think(a, p)
    write(result)


def read():
    return read_int(2)


def read_int(n):
    return read_type(int, n)


def read_float(n):
    return read_type(float, n)


def read_type(t, n):
    return list(map(lambda x: t(x), read_line().split(' ')))[:n]


def read_line(n=0):
    if n == 0:
        return input().rstrip()
    else:
        return input().rstrip()[:n]


def think(a, p):
    return (a * 3 + p) // 2


def write(result):
    print(result)


if __name__ == '__main__':
    # unittest.main()
    solve()

Measured memory_bytes: 5644
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long ul;
// for文短縮類
#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPD(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i <= (ll)(b); i++)
#define FORD(i, a, b) for (ll i = a; i >= (ll)(b); i--)
// iteratorのbeginとendをまとめて渡す
#define ALL(x) (x).begin(), (x).end()
//略
#define PB push_back  // vectorヘの挿入
#define MP make_pair  // pairのコンストラクタ
#define F first       // pairの一つ目の要素
#define S second      // pairの二つ目の要素
//出力
#define COUT(x) cout << (x) << endl
#define SCOUT(x) cout << (x) << " "
#define ENDL cout << endl
/************ Combination wtih MOD ************
const int MAX = 510000;
const int MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];
// preprocess for some tables
void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++) {
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}
// combination
long long COM(int n, int k) {
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
*******************************************************/

struct UnionFInd {
  vector<ll> par;

  UnionFInd(ll N) : par(N) {
    for (ll i = 0; i < N; i++) {
      par[i] = i;
    }
  }

  ll root(ll x) {
    if (par[x] == x) return x;
    return par[x] = root(par[x]);
  }

  void unite(ll x, ll y) {
    ll rx = root(x);
    ll ry = root(y);
    if (rx == ry) return;
    par[rx] = par[ry];
  }

  bool same(ll x, ll y) {
    ll rx = root(x);
    ll ry = root(y);
    return rx == ry;
  }
};

int main(int argc, char *argv[]) {
  // input高速化。cinとcoutの結合解除。scanfとprintfは使えない。
  cin.tie(0);
  ios_base::sync_with_stdio(0);

  ll n, q;
  cin >> n >> q;
  vector<ll> com(q);
  vector<ll> x(q);
  vector<ll> y(q);
  REP(i, q) {
    ll comi, xi, yi;
    cin >> comi >> xi >> yi;
    com[i] = comi;
    x[i] = xi;
    y[i] = yi;
  }
  UnionFInd uf(n);
  REP(i, q) {
    if (com[i] == 0) {
      uf.unite(x[i], y[i]);
    } else {
      if (uf.same(x[i], y[i])) {
        cout << "1" << endl;
      } else {
        cout << "0" << endl;
      }
    }
  }
}


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

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

int main(void)
{
    int N,Y,x,y,z, r;
    cin >> N >> Y;
    REP(x, N) {
        REP(y, N - x) {
             z = (Y - (x * 10000 + y * 5000)) / 1000 ;
             if(x+y+z==N) {
                 cout << x << " " << y << " " << z << endl;
                 return 0;
             }
        }
    }
    cout << "-1 -1 -1"<< endl;
}



Measured memory_bytes: 256