akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define mod 1000000007
#define mod1 998244353
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long int li;
typedef unsigned long long int ull;
using namespace std;
bool sortbysec(const pair<li,li>&a,const pair<li,li>&b)
{
    return (a.second<b.second);
}
vector<li>p;
void dfs(vector<li>v[],li visit[],li s)
{
  visit[s]=1;
  p.push_back(s+1);
  for(auto i=v[s].begin();i!=v[s].end();i++)
  {
    if(!visit[*i])
      dfs(v,visit,*i);
  }
}
int main()
{
fast_io
li k,n,i;
cin>>k>>n;
li arr[n],a[n],ans=0;
for(i=0;i<n;i++)
cin>>arr[i];
for(i=0;i<n-1;i++)
a[i]=arr[i+1]-arr[i];
a[n-1]=k-arr[n-1]+arr[0];
sort(a,a+n);
for(i=0;i<n-1;i++)
ans+=a[i];
cout<<ans;
return 0;
}


Measured memory_bytes: 3328
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <cmath>
#include <queue>
#include <deque>
#include <set>
#include <iomanip>
#include <utility>
typedef long long ll;
typedef long double ld;
using namespace std;

vector<string> v;

int main(void){
    int N;
    cin >> N;
    v.resize(N);
    for(int i=0; i<N; ++i){
        cin >> v[i];
    }
    sort(v.begin(), v.end());
    int ans=1;
    for(int i=1; i<N; ++i){
        if(v[i-1]!=v[i]) ++ans;
    }
    cout << ans << endl;
    return 0;
}


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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int n, k;
  cin >> n >> k;
  
  vector<int> a(n);
  for (int i = 0; i < n; i++) cin >> a.at(i);
  
  sort(a.begin(), a.end());
  
  int l = -1, r = n;
  while (r - l > 1) {
    int mid = (l + r) / 2;
    vector<vector<bool>> dp(n + 1, vector<bool>(k + 1, false));
    dp[0][0] = true;
    for (int i = 0; i < n; i++) {
      for (int j = 0; j <= k; j++) {
        if (i == mid) {
          dp[i + 1][j] = dp[i][j];
        }
        else if (dp[i][j]) {
          dp[i + 1][j] = true;
          if (j + a.at(i) <= k) dp[i + 1][j + a.at(i)] = true;
        }
      }
    }
    bool need = false;
    for (int j = max(k - a.at(mid), 0); j < k; j++) {
      if (dp[n][j]) need = true;
    }
    if (need) r = mid;
    else l = mid;
  }
  
  cout << l + 1 << '\n';
}

Measured memory_bytes: 6684
package main

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

type trump struct {
	suit  string
	value int
}

func (t trump) String() string {
	return fmt.Sprintf("%s%d", t.suit, t.value)
}

func printTrumpArray(values []trump) {
	strValues := make([]string, len(values))
	for i, elm := range values {
		strValues[i] = fmt.Sprintf("%v", elm)
	}
	fmt.Printf("%v\n", strings.Join(strValues, " "))
}

func bubbleSort(tr []trump) int {
	flag := true
	count := 0
	for {
		if !flag {
			break
		}
		flag = false

		for j := len(tr) - 1; j >= 1; j-- {
			if tr[j].value < tr[j-1].value {
				tmp := tr[j]
				tr[j] = tr[j-1]
				tr[j-1] = tmp
				count++
				flag = true
			}
		}
	}
	return count
}

func selectionSort(tr []trump) int {
	count := 0
	for i := 0; i < len(tr); i++ {
		minj := i
		for j := i; j < len(tr); j++ {
			if tr[j].value < tr[minj].value {
				minj = j
			}
		}

		if i != minj {
			tmp := tr[i]
			tr[i] = tr[minj]
			tr[minj] = tmp
			count++
		}
	}
	return count
}

// func isStable(in []trump, out []trump) bool {
// 	for i := 0; i < len(in); i++ {
// 		for j := i + 1; j < len(in); j++ {
// 			for a := 0; a < len(in); a++ {
// 				for b := a + 1; b < len(in); b++ {
// 					if in[i] == in[j] && in[i] == out[b] && in[j] == out[a] {
// 						return false
// 					}
// 				}
// 			}
// 		}
// 	}
// 	return true
// }

func isStable(in []trump, out []trump) bool {
	for i := 0; i < len(in); i++ {
		if in[i].suit != out[i].suit {
			return false
		}
	}
	return true
}

func printStable(isStable bool) {
	if isStable {
		fmt.Println("Stable")
		return
	}
	fmt.Println("Not stable")
}

func main() {
	var arraySize int
	fmt.Scan(&arraySize)

	values := make([]trump, arraySize)

	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	for i := 0; i < arraySize; i++ {
		sc.Scan()
		s := sc.Text()
		// fmt.Println("scan", s)
		v, _ := strconv.Atoi(s[1:2])
		t := trump{suit: s[0:1], value: v}
		values[i] = t
	}

	// printTrumpArray(values)

	values1 := append([]trump{}, values...)
	values2 := append([]trump{}, values...)

	bubbleSort(values1)
	printTrumpArray(values1)
	stable := isStable(values, values1)
	printStable(true)

	selectionSort(values2)
	printTrumpArray(values2)
	stable = isStable(values1, values2)
	printStable(stable)

}



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

int main(){
    int a,b;
    cin >> a >> b;

    int d,r;
    double f;

    d = a / b;
    r = a % b;
    f = (double)a / b;

    cout << d << " " << r << " " << fixed << setprecision(5) << f << endl;
}


Measured memory_bytes: 3240
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <tuple>
#include <cmath>
#include <iomanip>
#include <map>
#include <cstring> //memset(dp,0,sizeof(dp))
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define repp(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
//小数点以下　cout << fixed << setprecision(10) << num << endl;
//桁数はlog10(mid)でやれ　log(mid)/log(10)はWA
//long*long<0で判定するな
//開区間と閉区間
//アルファベットが何番目かは x=s[i]-'a'
//bfsはmain()内で　rep(i,h)rep(j,w)rep(i,4)でバグ
//切り上げ：(a+(b-1))/b
//32bit以上は 1ull<<j]
// map 初期値0 for(auto itr=mp.begin();itr!=mp.end();++itr) itr->fi itr->se で全探索
// for(auto u:mp) u.fi u.se も可能
int main(){
    int a,b; cin >> a >> b;
    cout << 6-a-b << endl;
}


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

typedef long long ll;
typedef long double ld;

using namespace std;

const ll INF = 1e18;
const ll maxn = 2e5+10;
const ll mod = 1e9+7;

ll n , m , k;
ll dp[maxn], a[maxn];

int main()
{
    cin>> n >> k;
    for(ll i = 1; i <= n; i++) cin>>  a[i];

    for(ll i = 1; i <= k; i++)
        for(ll j = 1; j <= n; j++)
            if(a[j] <= i)
                dp[i] = max(dp[i], 1-dp[i-a[j]]);

    if(dp[k] == 1) cout<<"First";
    else cout<<"Second";
}










Measured memory_bytes: 1024
def factorisation(n):
  res = dict()
  i = 1
  while i * i <= n:
    i += 1
    if n % i != 0:
      continue
    res[i] = 0
    while n % i == 0:
      n //= i
      res[i] += 1
  if n > 1:
    res[n] = 1
  return res

n = int(input())
ind = factorisation(n)
ans = 0
for p in ind.keys():
  a = 1
  while ind[p] >= a:
    ind[p] -= a
    ans += 1
    a += 1
print(ans)
  

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

int main() {
    int N;
    cin >> N;
    vector<int> d(N);
    for (int i = 0; i < N; i++) {
        cin >> d[i];
    }

    sort(d.begin(), d.end());
    int half = d.size()/2;
    int left = d[half-1];
    int right = d[half];

    int count = 0;

    if (left == right) count = 0;
    else count = right-left;

    cout << count << endl;
    return 0;
}

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

int main() {
    int n;
    long long a;
    long long minValue = 1000000;
    long long maxValue = -1000000;
    long long sum = 0;
    
    cin >> n;
    
    for(int i = 0; i < n; i++){
        cin >> a;
        if(a < minValue) minValue = a;
        if(a > maxValue) maxValue = a;
        sum += a;
    }
    cout << minValue << " " << maxValue << " " << sum << endl;
    
    return 0;
}

Measured memory_bytes: 3116
#include <bits/stdc++.h>
using namespace std;
#define rep0(i,n) for(ll (i) = 0; (i) < (n); ++(i))
#define rrep0(i,n) for(ll (i) = (n) - 1; (i) >= 0; --(i))
#define rep1(i,n) for(ll (i) = 1; (i) <= (n); ++(i))
#define rrep1(i,n) for(ll (i) = (n); (i) >= 1; --(i))
#define nfor(i,a,b) for(ll (i) = (a); (i) < (b); ++(i))
#define rnfor(i,a,b) for(ll (i) = (a) - 1; (i) >= (b); --(i))
#define ll long long
#define mod (1000000007)
#define pf(x) cout << (x) << endl
#define all(x) (x).begin(),(x).end()

ll gcd(ll a,ll b){
    if(a < b)swap(a, b);
    if(b == 0) return a;
    return gcd(b,a%b);
}

ll lcm(ll a,ll b){
    ll g = gcd(a,b);
    return a / g * b;
}

ll factorial(ll n){
    ll t = 1;
    rep1(i, n)t *= i;
    return t;
}

ll combinations(ll n, ll k) {
    ll r = 1;
    rep1(i, k)r = r * n-- / i;
    return r;
}

int main(){
    ll n;
    cin >> n;
    vector<pair<ll, ll>> t(n);
    rep0(i, n){
        ll a,b;
        cin >> a >> b;
        t[i] = make_pair(b, a);
    }
    sort(all(t));
    ll cnt = 0;
    rep0(i, n){
        cnt += t[i].second;
        if(cnt > t[i].first){
            pf("No");
            return 0;
        }
    }
    pf("Yes");
    return 0;
}


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

int main(void){
    int D,G; cin >> D >> G;
    vector<int> p(D), c(D);
    for(int i=0; i<D; i++){
        cin >> p[i] >> c[i];
    }

    int ans=1001;

    for(int i=0; i<pow(2,D); i++){                                   //どの問題を全部取るのか管理するビット列
        int totalScore=0;                                            //累計スコア
        int solvedProblem=0;                                         //解いた問題数
        int unfinished=0;                                            //部分的に解く問題のインデックスを格納する変数

        for(int j=0; j<D; j++){                                      //jは問題の種類を表すインデックスとして使う
            if((i&(1<<j))!=0){
                totalScore+=p[j]*100*(j+1);                          //全部正解する
                totalScore+=c[j];                                    //ボーナスがつく
                solvedProblem+=p[j];    
            }
            else unfinished=j;
        }

        if(totalScore<G){                                            //まだ目標点に到達していない時はunfinishedから得点しないといけない
            int rest=ceil((double)(G-totalScore)/(100*(unfinished+1)));      //目標点に到達するために解く必要がある問題の数
            if(rest>=p[unfinished]) continue;                        //この数は問題数より真に小さいことが必要(完全に解ききってもいけない)
            else{
                solvedProblem+=rest;
            }
        }
        ans=min(ans,solvedProblem);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
//verma_ankit484

#include<bits/stdc++.h>
typedef long long ll;

using namespace std;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	#ifdef AV
	freopen("int.txt", "r", stdin);
	#endif
	ll n;
	cin >> n;
	vector<ll> vc(n+1, 0);
	for(ll i = 1; i <= n; i++) {
		cin >> vc[i];
	}
	ll sum = 0;
	ll dp[n+1] = {0};
	dp[2] = abs(vc[1]-vc[2]);
	for(ll i = 3; i <= n; i++) {
		if(dp[i-1]+abs(vc[i]-vc[i-1]) < dp[i-2]+abs(vc[i]-vc[i-2])) {
			dp[i] = dp[i-1]+abs(vc[i]-vc[i-1]);
		}
		else {
			dp[i] = dp[i-2]+abs(vc[i]-vc[i-2]);
		}
	}
	cout << dp[n] << '\n';
	return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <list>
#define ll long long
using namespace std;
int main()
{
  ios_base::sync_with_stdio(0);
  string str;
  cin >> str;
  int f=0;
  for(int i=0;i<str.length();i++)
  {
    if(str[i]=='9'){
      f=1;
      break;
    }
  }
  if(f)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<utility>
#include<queue>
#include<string>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;
typedef pair<int,int> pii;

int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int h,w;
bool inside(pii pick){
	if(pick.first<h && pick.first>=0 && pick.second<w && pick.second>=0)return true;
	else return false;
}

int main(){
	while(1){
		cin>>h>>w;
		if(h==0 && w==0)break;
		int ans=0;
		char dt[h][w];
		string s;
		rep(i,h){
			cin>>s;
			rep(j,w)dt[i][j]=s[j];
		}
		rep(i,h){
			rep(j,w){
				if(dt[i][j]!='-'){
					ans++;
					queue<pii> que;
					que.push(pii(i,j));
					while(!que.empty()){
						pii now=que.front(),alt;
						que.pop();
						rep(k,4){
							alt=now;
							alt.first+=dy[k];
							alt.second+=dx[k];
							if(inside(alt) && dt[alt.first][alt.second]==dt[now.first][now.second] && dt[alt.first][alt.second]!='-'){
								que.push(alt);
							}
						}
						dt[now.first][now.second]='-';
					}
				}
			}
		}
		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 1236
#include<stdio.h>
int main(){

  char ch;
  int num,counter[26] = {};
  
  while( scanf("%c", &ch) != EOF ){

    if ( ch >= 'a' && ch <= 'z' ){
      num = ch - 'a';
    } else if ( ch >= 'A' && ch <= 'Z' ){
      num = ch - 'A'; 
    } else{
      continue;
    }
    counter[num]++;

  }

  int i;

  for ( i = 0 ; i < 26 ; i++ ){

    ch = 'a' + i;
    printf("%c : %d\n", ch, counter[i]);
    
  }

  return 0;

}

Measured memory_bytes: 540
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=5e15;

const ll N=2e5+10;
vector<map<ll,ll>> si(N),dp(N);
vector<set<ll>> G(N);
ll n;

ll mpow(ll x, ll n) {
  ll ans=1;
  while(n>0) {
    if(n&1) {
      ans=ans*x%mod;
    }
    x=x*x%mod;
    n>>=1;
  }
  return ans;
}

vec tfact(1e7+1);
void fact(ll n) {
  for(ll i=0;i<=n;i++) {
    if(i==0) {
      tfact[i]=1;
    }
    else {
      tfact[i]=tfact[i-1]*i%mod;
    }
  }
}

ll dfs1(ll f, ll ff) {
  if(si[f][ff]) return si[f][ff];
  ll res=0;
  for(auto p:G[f]) {
    if(p==ff) continue;
    res+=dfs1(p,f);
  }
  if(ff) si[ff][f]=n-res-1;
  return si[f][ff]=res+1;
}

ll dfs2(ll f,ll ff) {
  if(dp[f][ff]) return dp[f][ff];
  ll res=1;
  if(dp[f][0]) {
    res=dp[f][0];
    (res*=mpow(dfs2(ff,f),mod-2)*tfact[dfs1(ff,f)]%mod)%=mod;
    (res*=mpow(tfact[dfs1(f,0)-1],mod-2))%=mod;
  }
  else {
    for(auto p:G[f]) {
      if(p==ff) continue;
      (res*=dfs2(p,f)*mpow(tfact[dfs1(p,f)],mod-2)%mod)%=mod;
    }
  }
  (res*=tfact[dfs1(f,ff)-1])%=mod;
  return dp[f][ff]=res;
}

void bfs(ll f) {
  queue<ll> q;
  q.push(f);
  while(q.size()) {
    ll n=q.front();
    q.pop();
    dfs2(n,0);
    for(auto p:G[n]) {
      if(dp[p][0]) continue;
      q.push(p);
    }
  }
}

int main() {
  cin >> n;
  for(ll i=0;i<n-1;i++) {
    ll a,b;
    cin >> a >> b;
    G[a].insert(b);
    G[b].insert(a);
  }
  fact(N);
  bfs(1);
  for(ll i=1;i<=n;i++) {
    cout << dfs2(i,0) << endl;
  }
}

Measured memory_bytes: 202368
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

int main()
{
	char X, Y;
	cin >> X >> Y;

	if (X > Y)
		cout << ">" << endl;
	else if (X < Y)
		cout << "<" << endl;
	else
		cout << "=" << endl;

	return 0;
}


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



int main(void){
  int N;
  cin >> N ;
  vector<int64_t> L(87);
  L[0]=2;
  L[1]=1;
  if(N==0){
    cout << L[0] << endl;
    return 0;
  }
  if(N==1){
    cout << L[1] << endl;
    return 0;
  }
  
  for(int i=2;i<N+1;i++)
    L[i]=L[i-1]+L[i-2];
  
  cout << L[N] << endl;
}


      
  

Measured memory_bytes: 256
#include <stdio.h>

int toindex(char);
char tosuit(int);

int main(void) {
    int n, idx, num, tbl[4][13] = {};
    char buf[2];
    for(scanf("%d", &n); n--; tbl[toindex(buf[0])][~-num]++) {
        scanf("%1s %d", buf, &num);
    }
    for(n = 0; n < 52; n++) {
        idx = n / 13, num = n % 13;
        tbl[idx][num] || printf("%c %d\n", tosuit(idx), -~num);
    }
    return 0;
}

int toindex(char suit) {
    int rslt;
    switch(suit) {
      case 'S':
        rslt = 0;
        break;
      case 'H':
        rslt = 1;
        break;
      case 'C':
        rslt = 2;
        break;
      case 'D':
        rslt = 3;
        break;
    }
    return rslt;
}

char tosuit(int index) {
    return index-- ? index-- ? index-- ? 'D' : 'C' : 'H' : 'S';
}

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

int main(){
	
	int x,s[31]={};
	
	for( int i=0 ; i<28 ; i++ ){
		cin >> x ;
		s[x] = 1 ;
	}
	
	for( int i=1 ; i<31 ; i++ ){
		if( s[i] == 0 ) cout << i << endl ;
	}
	
return 0;
}

Measured memory_bytes: 1164
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(a); (i)<(b); ++(i))
#define rFor(i, a, b) for(int (i)=(a)-1; (i)>=(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
#define double long double
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef pair<lint, lint> pll;
typedef complex<double> xy_t;
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(a>b){a=b; return true;} return false;}

constexpr lint mod = 1e9+7;
constexpr lint INF = mod*mod;
constexpr int MAX = 100010;

int main(){
    int n, m;
    scanf("%d%d", &n, &m);
    int pena[n];
    bool ac[n];
    rep(i, n){
        pena[i]=0;
        ac[i]=false;
    }
    int cnt=0, num=0;
    rep(i, m){
        int p;
        string s;
        cin>>p>>s;
        --p;
        if(s=="AC" && !ac[p]){
            ++cnt;
            num+=pena[p];
            ac[p]=true;
        }
        else if(s=="WA") ++pena[p];
    }
    printf("%d %d\n", cnt, num);
}

Measured memory_bytes: 768
#include <iostream>
#include <bitset>
#include <fstream>
#include <string>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <functional>
#include <cctype>
#include <list>
#include <limits>
//#include <boost/multiprecision/cpp_int.hpp>

const double EPS = (1e-10);


using namespace std;
using Int = long long;
//using namespace boost::multiprecision;

const Int MOD = 1000000007;

Int mod_pow(Int x, Int n) {
    Int res = 1;
    while(n > 0) {
        if(n & 1) res = (res * x) % MOD; //ビット演算(最下位ビットが1のとき)
        x = (x * x) % MOD;
        n >>= 1; //右シフト(n = n >> 1)
    }
    return res;
}

Int dp[100005];
Int a[100005];

int main(){
    cin.tie(0);

    int N; cin >> N;
    for (int i = 0; i < N; i++){
        cin >> a[i];
    }
    Int INF = 100000000000;
    fill(dp, dp+100005, INF);
    dp[0] = -1;
    for (int i = 0; i < N; i++){
        int j = (int)(lower_bound(dp, dp+100005, a[i]) - dp);
        dp[j] = a[i];
    }
    int ans;
    for (int i = N; i >= 1; i--){
        if (dp[i] != INF){
            ans = i;
            break;
        }
    }
    cout << ans << endl;

}



Measured memory_bytes: 4684
n = int(input())
x = map(int, input().split()[:n-1])
y = map(int, input().split()[:n-1])
if x == y:
    print(0)
else:
    l1 = [i for i in range(1, n+1)]
    l2 = list(l1)
    def fact(k):
        return 1 if k <= 1 else k * fact(k-1)

    def get_lex_order(n, l, z):
        t = 0
        for i, m in enumerate(z):
            k = l.index(m)
            l.remove(m)
            t += k * fact(n - i - 1)
        return t + 1
    print(abs(get_lex_order(n, l1, x) - get_lex_order(n, l2, y)))

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

#define rep(i,n) for(i = 0;i < n;++i)
#define all(v) v.begin(), v.end()
using ll = long long;

int main()
{
    ll i,j;
    ll n,s;
    cin >> n >> s;
    vector<ll> a(n);
    for(i = 0;i < n;++i){
        cin >> a.at(i);
    }
    const ll MOD = 998244353;
    vector<vector<ll>> dp(n+1,vector<ll>(s+1,0));
    dp.at(0).at(0) = 1;
    for(i = 1;i <= n;++i){
        rep(j,s+1){
            if(j < a.at(i-1)) dp.at(i).at(j) = 2*dp.at(i-1).at(j);
            else dp.at(i).at(j) = 2*dp.at(i-1).at(j) + dp.at(i-1).at(j - a.at(i-1));
            dp.at(i).at(j) %= MOD;
        }
    }
    cout << dp.at(n).at(s) << endl;
    return 0;
}

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

int main(){
  vector<int> a(3);
  cin >> a.at(0) >> a.at(1) >> a.at(2);
  sort(a.begin(),a.end());
  cout << abs(a.at(0) - a.at(1)) + abs(a.at(1) - a.at(2));
}


Measured memory_bytes: 3620
#include <cstdio>
#include <iostream>
#include <algorithm>

using namespace std;

int ot[110][110];

int main(){
  int a,b,flg=0; scanf("%d%d",&a,&b);
  if(a<b) swap(a,b),flg=1; b--;
  for(int i=1;i<=25 && a;i++)
    for(int j=1;j<=25 && a;j++){
      a--;
      for(int k=1;k<=3;k++)
	for(int s=1;s<=3;s++)
	  ot[(i-1)*4+k][(j-1)*4+s]=1;
    }
  for(int i=1;i<=25 && b;i++)
    for(int j=1;j<=25 && b;j++){
      b--;
      ot[(i-1)*4+2][(j-1)*4+2]=0;
    }
  printf("%d %d\n",100,100);
  for(int i=1;i<=100;i++,putchar('\n'))
    for(int j=1;j<=100;j++) putchar(ot[i][j]==flg?'#':'.');
  return 0;
}


Measured memory_bytes: 256
n,k = map(int,input().split())
s = list(str(input()))
if s[k-1] == "A":
    s[k-1] = "a"
if s[k-1] == "B":
    s[k-1] = "b"
if s[k-1] == "C":
    s[k-1] = "c"
print("".join(s))

Measured memory_bytes: 3060
r, g, b, n = map(int,input().split())
cnt = 0
for i in range(n+1):
    for j in range(n+1):
        if ((n - ((i*r) + j*g)) % b == 0) and ((n - ((i*r) + (j*g))) >= 0) :
            #print(n - (i*r) + (j*g))
            cnt += 1
print(cnt)

Measured memory_bytes: 41324
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <bitset>
#include<vector>
#include<cstdlib>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
#define rep(i,k) for(int i=0;i<k;i++)
ll n, m, i, j, k,o,p,l,z;
ll a[100005], b[100005],inf=1000000000000;

ll s[100005],t[100005], xx[100005];

ll tansaku(ll x,ll n,ll* s) {
	int max,min, mid ;
	min = 0; 	max = n + 1; 
	while (max - min > 1) {
		mid = (min + max) / 2;
		
		if (s[mid] > x) {
			max = mid;
		}
		else {
			min = mid;
		}
	//	cout << max << "\n";
	}	
	return max;

}

ll hikaku(ll* s, ll* t, ll o, ll p,ll k) {
	ll z = min((abs(s[o] - k) + abs(s[o] - t[p])), (abs(t[p] - k) + abs(s[o] - t[p])));
	ll zz = min((abs(s[o] - k) + abs(s[o] - t[p-1])), (abs(t[p-1] - k) + abs(s[o] - t[p-1])));
	ll za = min((abs(s[o - 1] - k) + abs(s[o - 1] - t[p])), (abs(t[p] - k) + abs(s[o - 1] - t[p])));
	ll zb = min((abs(s[o - 1] - k) + abs(s[o - 1] - t[p-1])), (abs(t[p-1] - k) + abs(s[o - 1] - t[p-1])));
	z = min(z, zz);
	return min(z, min(za, zb));
}


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

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

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

string S;
int main(){
    cin >> S;
    int a = stoi(S.substr(0, 2));
    int b = stoi(S.substr(2, 2));
    if(1 <= a && a <= 12 && 1 <= b && b <= 12){
        cout << "AMBIGUOUS" << endl;
    }else if(1 <= a && a <= 12){
        cout << "MMYY" << endl;
    }else if(1 <= b && b <= 12){
        cout << "YYMM" << endl;
    }else{
        cout << "NA" << endl;
    }
}


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

public class Main {
    public static void main(String args[]){
        Scanner stdIn = new Scanner(System.in);
        
        //int a = stdIn.nextInt();
        //int b = stdIn.nextInt();
        //int x = stdIn.nextInt();
        //int num[] = new int[3];
        String s = stdIn.next();
        char c[] = s.toCharArray();
        //int sum = 0;
        //boolean flag = true;
        //for(int i = 0; i < s.length(); i++){
        //}
        
        Arrays.sort(c);
        
        if(c[0] == 'a' && c[1] == 'b' && c[2] == 'c'){
        	System.out.println("Yes");
        }else{
        	System.out.println("No");
        }
        
        //System.out.println();
        //System.out.print();
    }
}


Measured memory_bytes: 23636
#include <cstdio>

void swap(int & x, int & y)
{
	x = x ^ y;
	y = x ^ y;
	x = x ^ y;
}

int main()
{
	int a, b, c;
	scanf("%d%d%d", &a, &b, &c);
	
	if (a > b) swap(a, b);
	if (a > c) swap(a, c);
	if (b > c) swap(b, c);
	
	printf("%d", c - a);
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define fi first
#define se second
#define PI (acos(-1))

template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}
template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){
	int len=d.size();
	rep(i,len){
		s<<d[i];if(i<len-1) s<<" ";
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){
	int len=d.size();
	rep(i,len){
		s<<d[i]<<endl;
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){
	s<<"{ ";
	for(auto itr=v.begin();itr!=v.end();++itr) {
		if (itr!=v.begin()) {s<< ", ";}
		s<<(*itr);
	}
	s<<" }";
	return s;
}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){
	s<<"{"<<endl;
	for(auto itr=m.begin();itr!=m.end();++itr){
		s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;
	}
	s<<"}"<<endl;
	return s;
}

const ll mod=1e9+7;
const ll inf=1e15;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int a,b,c;
  cin>>a>>b>>c;
  if((a+b==c)||(b+c==a)||(c+a==b)) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

Measured memory_bytes: 256
# input()
# int(input())
# map(int, input().split())
# list(map(int, input().split()))
# list(map(int, list(input()))) # スペースがない数字リストを読み込み
import math
import fractions
import sys
import bisect
import heapq  # 優先度付きキュー(最小値取り出し)
import collections
from collections import Counter
from collections import deque
import pprint
import itertools

sr = lambda: input()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

"""nを素因数分解"""
"""2以上の整数n => [[素因数, 指数], ...]の2次元リスト"""


def factorization(n):
    arr = []
    temp = n
    if n == 1:
        return arr

    for i in range(2, int(-(-n ** 0.5 // 1)) + 1):
        if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                temp //= i
            arr.append([i, cnt])

    if temp != 1:
        arr.append([temp, 1])

    if arr == []:
        arr.append([n, 1])

    return arr


# a^n
def power(a, n, mod):
    x = 1
    while n:
        if n & 1:
            x *= a % mod
        n >>= 1
        a *= a % mod
    return x % mod


# n*(n-1)*...*(l+1)*l
def kaijo(n, l, mod):
    if n == 0:
        return 1
    a = n
    tmp = n - 1
    while (tmp >= l):
        a = a * tmp % mod
        tmp -= 1
    return a


inf = 10 ** 18
mod = 10 ** 9 + 7

h,w = lr()
s = [input() for i in range(h)]
dicw = [[0 for j in range(w)] for i in range(h)]
dich = [[0 for j in range(w)] for i in range(h)]
# まずは横方向の情報を格納
for i in range(h):
    ind = 0
    now = 0
    while ind < w:
        now = 0
        while ind < w and s[i][ind] == '.':
            now+=1
            ind+=1
        for j in range(now):
            dicw[i][ind-1-j] = now
        ind+=1
for i in range(w):
    ind = 0
    now = 0
    while ind < h:
        now = 0
        while ind < h and s[ind][i] == '.':
            now+=1
            ind+=1
        for j in range(now):
            dich[ind-1-j][i] = now
        ind+=1

ans = 0
for i in range(h):
    for j in range(w):
        if s[i][j] == '.':
            ans = max(ans, dich[i][j]+dicw[i][j]-1)
print(ans)


Measured memory_bytes: 149668
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
//26のn乗を入れる配列
vector<ll>npower;
//26のn乗＋n-1乗+...1乗を入れる配列
vector<ll>npower_sigma;

ll np=1;
npower.push_back(1);
npower_sigma.push_back(0);
//1-indexedにしつつ、npsigma[0]を0にする
while(np<1e16)
{ 
  np*=26;
  npower.push_back(np);
  npower_sigma.push_back(np+npower_sigma.back());
}
//rep(i,npower.size())cout <<i<<":"<<npower[i]<<":"<<npower_sigma[i]<<endl;
ll n;
cin>>n;
n--;

int d=1;
for (ll i = npower_sigma.size()-1; i>0; i--)
{ if(n>=npower_sigma[i]){d=i+1;break;} }

//cout<<"";

string ans="";
n=n-npower_sigma[d-1];
for (int i = d; i>0; i--)
{//n=n-npower_sigma[d-1];
 ans.push_back(n/npower[d-1]+'a');
 //cout<<d<<":"<<n<<":"<<n/npower[d-1]<<endl;
 d--;
 if(d!=0)n=n%npower[d];
 //n= d==0 ? n:n%npower[d];
}

cout<<ans<<endl;

}
/*vector <int> a(3);
for (int i = 0; i < n; i++) {
    cin >> a.at(i);
  }*/

Measured memory_bytes: 3596
#include <stdio.h>

int main(void)
{
	int W,H,x,y,r;
	
	scanf("%d%d%d%d%d",&W,&H,&x,&y,&r);
	if (x >= r && x <= W - r && y >= r && y <= H - r )
		printf("Yes\n");
	else
		printf("No\n");




	return 0;
	
}


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

int main() {
  int N, A;
  cin >> N;
  cin >> A;
  
  if(N % 500 <=A){
    cout << "Yes" << endl;
  }
  
 else{
   cout << "No" << endl;
 }
}
    


Measured memory_bytes: 3616
import numpy as np
from bisect import bisect_right

N, M, K = map(int, input().split())
A: np.ndarray = np.array([0] + list(map(int, input().split())))
B: np.ndarray = np.array([0] + list(map(int, input().split())))

if A.sum() + B.sum() <= K:
    print(N + M)
    exit()

A_cumsum = A.cumsum()
B_cumsum = B.cumsum()

# print(f'{A_cumsum=}')
# print(f'{B_cumsum=}')

ans = 0
for i in range(N + 1):
    A_time = A_cumsum[i]
    if A_time > K:
        continue
    j = bisect_right(B_cumsum, K - A_time) - 1
    ans = max(ans, i + j)
print(ans)


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

const int MOD = 1000000007;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define copy(from, to) copy(from.begin(), from.end(), back_inserter(to))
#define _sort(a) sort(a.begin(), a.end())
#define _sortd(a) sort(a.rbegin(), a.rend())
#define reverse(s) reverse(s.begin(), s.end())
#define p(s) cout << (s) << endl

typedef long long ll;
using namespace std;

template<class T>
void load(vector<T> &v, int n) {
  for (int i = 0; i < n; ++i) {
    T t;
    cin >> t;
    v.push_back(t);
  }
}

template<class T>
T max(vector<T> &v) {
  return *max_element(v.begin(), v.end());
}

template<class T>
T min(vector<T> &v) {
  return *min_element(v.begin(), v.end());
}

void py(bool isUpper = false) {
  if (isUpper) {
    p("YES");
  } else {
    p("Yes");
  }
}

void pn(bool isUpper = false) {
  if (isUpper) {
    p("NO");
  } else {
    p("No");
  }
}

int main() {
  int x;
  cin >> x;
  if (x == 0) {
    cout << 1 << endl;
  } else {
    cout << 0 << endl;
  }
}

Measured memory_bytes: 3592
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);++i)
typedef long long llong;
using namespace std;

int main(){
	int n,lim;
	cin>>n>>lim;
	
	vector<int> w(n),v(n);
	llong sumw=0;
	int sumv=0;
	REP(i,n){
		cin>>w[i]>>v[i];
		sumw+=w[i];
		sumv+=v[i];
	}
	
	vector<llong> dp(sumv+1,sumw);//価値iに必要な最小重さdp[i].
	dp[0]=0;
	REP(i,n){
		for(int j=sumv;j>=0;--j){
			if(j>=v[i]) dp[j]=min(dp[j],dp[j-v[i]]+w[i]);
			else break;
		}
	}
	
	for(int i=sumv;i>=0;--i){
		if(dp[i]<=lim){
			cout<<i<<endl;
			return 0;
		}
	}
}

Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {
	static boolean[][] connected;
	static boolean[] arrived;
	static int ans = 0;
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int m = sc.nextInt();

		// make a map
		connected = new boolean[n][n];
		for (int i = 0; i < m; i++) {
			int a = sc.nextInt() - 1; // start at 0
			int b = sc.nextInt() - 1;
			connected[a][b] = true;
			connected[b][a] = true;
		}

		arrived = new boolean[n];
		search(arrived, 0);

		System.out.println(ans);

		sc.close();
	}

	// search
	static void search(boolean[] arrived, int arrive) {
		if (arrived[arrive]) {
			return;
		} else {
			arrived[arrive] = true;
		}

		if (isAccomplish(arrived)) {
			ans++;
			return;
		}

		for (int i = 0; i < connected.length; i++) {
			if (connected[arrive][i]) {
				search(copyArray(arrived), i);
			}
		}
	}

	// copy a array
	static boolean[] copyArray(boolean[] arr1) {

		boolean[] arr2 = new boolean[arr1.length];
		for (int i = 0; i < arr1.length; i++) {
			arr2[i] = arr1[i];
		}

		return arr2;
	}

	// check accomplish
	static boolean isAccomplish(boolean[] arr) {
		for (int i = 0; i < arr.length; i++) {
			if (!arr[i]) {
				return false;
			}
		}
		return true;
	}

}


Measured memory_bytes: 22612
//by azidoazideazide(c2n14)
#include<iostream>
#include<string>
#include<cmath>
#include<algorithm> //#include<map>
#include<vector>
using namespace std;
typedef long long ll;
//#include<fstream>
//ifstream fin("rps.in");
//ofstream fout("rps.out");
//#define pb push_back
int main(){
	ios::sync_with_stdio(0);
	int n;
  cin>>n;
  cout<<n*n*n<<endl;
return 0;
}


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

using namespace std;
using ll = long long;

const int Mo = 998244353;
vector<ll> fac, ifac;

ll qpow(ll b, ll p)
{
  ll res = 1;
  while (p > 0)
  {
    if (p & 1)
      res = res * b % Mo;
    b = b * b % Mo;
    p >>= 1;
  }
  return res;
}

ll comb(ll m, ll n)
{
  return ((ifac[m] * fac[n]) % Mo * ifac[n - m]) % Mo;
}

int main()
{
  int n, m, k;
  ll res = 0;
  scanf("%d%d%d", &n, &m, &k);

  fac = vector<ll>(n + 1);
  ifac = vector<ll>(n + 1);
  fac[0] = ifac[0] = 1;
  for (ll i = 1; i <= n; ++i)
  {
    fac[i] = fac[i - 1] * i % Mo;
    ifac[i] = qpow(fac[i], Mo - 2);
  }

  ll t = qpow(m - 1, n - k - 1) * m % Mo;
  for (int i = 0; i <= k; ++i)
  {
    res += t * comb(k - i, n - 1);
    res %= Mo;
    t = t * (m - 1) % Mo;
  }

  printf("%lld\n", res);
  return 0;
}


Measured memory_bytes: 6460
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long int lld;
#define INF (1<<20)

lld calc(lld now,lld num,int c){
  if(c == 0) return now + num;
  else if(c == 1) return now - num;
  else if(c == 2) return now * num;
  else return now / num;
}

int main(){
  char str;
  string com="+-*/";
  lld ans = 0;
  cin >> ans; // ???????????°???
  while(cin >> str){
    if(str == '=') break;
    for(int i=0;i<4;i++){
      if(str == com[i]) {
	lld num = 0;
	cin >> num;
	ans = calc(ans,num,i);
	break;
      }
    }
  }
  cout << ans << endl;
}

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

int main(void){
    string s;
    cin >> s;
    
    bool ok = true;
    for(int i=0;i<s.size();i++){
        if(i%2==0){
            if(s[i]!='R' && s[i]!='U' && s[i]!='D') ok = false; 
        }else{
            if(s[i]!='L' && s[i]!='U' && s[i]!='D') ok = false;
        }
    }
    if(ok) cout << "Yes" << endl;
    else cout << "No" << endl;
}

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


#define MAX 2012

int h;
int w;

char room[MAX][MAX];
bool a[MAX][MAX];
int dp[MAX][MAX];

pair<int, int> dq[MAX];

int maxi[MAX];

int s[MAX][MAX][2][2];  //i-1,i,0,1
int main(){
	cin >> h >> w;
	for (int i = 0; i < h; i++){
		scanf("%s", room[i]);
	}
	for (int i = 0; i < h; i++){
		for (int j = 0; j < w; j++){
			if (room[i][j] == '.'){
				a[i][j] = 0;
			}
			else{
				a[i][j] = 1;
			}
		}
	}
	for (int i = 1; i < h; i++){
		for (int j = 0; j < 2; j++){
			for (int k = 0; k < 2; k++){
				for (int kk = w - 1; kk >= 0; kk--){
					int w = ((a[i - 1][kk] ^ j) == (a[i][kk] ^ k));
					s[i][kk][j][k] = w;
					if (w){
						s[i][kk][j][k] += s[i][kk + 1][j][k];
					}
				}
			}
		}
	}
	for (int j = 0; j < w; j++){
		int ds = 0;
		for (int i = 1; i <= h; i++){
			int tmp = w - j;
			if (i){
				tmp = s[i][j][a[i - 1][j]][a[i][j]];
			}
			int len = tmp;
			int id = i-1;
			while (ds){
				pair<int, int> f = dq[ds - 1];
				if (f.first < len){
					break;
				}
				ds--;
				maxi[f.first] = max(maxi[f.first], i - f.second);
				id = f.second;
			}
			dq[ds] = make_pair(len, id);
			ds++;
		}
	}
	for (int i = MAX - 2; i >= 0; i--){
		maxi[i] = max(maxi[i], maxi[i + 1]);
	}
	int ans = 0;
	for (int i = MAX - 1; i >= 0; i--){
		ans = max(ans, maxi[i] * i);
	}
	ans = max(ans, h);
	ans = max(ans, w);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 72832
#include <cstdio>
#include <utility>
using namespace std;

#define gcu getchar_unlocked
#define ii inline int in
ii(int c) {
	int n = 0;
	bool minus = false; if (c == '-') minus = true, c = gcu();
	do {n = 10 * n + (c - '0'), c = gcu();} while (c >= '0');
	//return n; }
	return minus ? -n : n; }
ii() {return in(gcu());}
//void scan(string &s) {for (char c; !isspace(c = gcu()); s += c);}
inline bool scan(int &n) {int c=gcu();return c==EOF?false:(n=in(c),true);}
#undef ii
#define pcu putchar_unlocked
template <typename T>
void out(T n) {
	static char buf[20];
	char *p = buf;
	if(n < 0) pcu('-'), n *= -1;
	if (!n) *p++ = '0';
	else while (n) *p++ = n % 10 + '0', n /= 10;
	while (p != buf) pcu(*--p); }
void out(const char *s){while(*s)pcu(*s++);}
void out(char c){pcu(c);}
//void out(string &s){for (char c: s) pcu(c);}
template <typename head, typename... tail>
void out(head&& h, tail&&... t){out(h);out(move(t)...);}
//template <typename T>
//void out(vector<T> &v){for(T &x:v)out(' '),out(x);out('\n');}
//void out(vector<T> &v){for(T &x:v)out(&x == &v[0]?"":" "),out(x);out('\n');}
#undef svo

int main() {
	int a, rect = 0, rhombus = 0;
	while (scan(a)) {
		int b = in(), c = in();
		if (a * a + b * b == c * c)
			rect++;
		else if (a == b)
			rhombus++;
	}
	out(rect, '\n', rhombus, '\n');
}


Measured memory_bytes: 2632
#include <bits/stdc++.h>
#define REP(i, n) for(ll i = 0; i < (ll)n; i++)
#define FOR(i, a, b) for(ll i = (a); i < (ll)b; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1000000000000000
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;
typedef pair<ll, ll> p;
constexpr int MOD = 1000000007;
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 print(const std::vector<int> &v) {
    std::for_each(v.begin(), v.end(), [](int x) { std::cout << x << " "; });
    std::cout << std::endl;
}

int main() {
    string N;
    cin >> N;
    int fx = 0;
    REP(i, N.size()) { fx += (N[i] - '0'); }
    int n = stoi(N);
    if(n % fx == 0) {
        cout << "Yes" << endl;
        return 0;
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0;i < n;i++)
#define REP(i,n,k) for(int i = n;i < k;i++)
#define P(p) cout << (p) << endl;
#define sP(p) cout << setprecision(15) << fixed << p << endl;
#define vi vector<int>
#define printv(v) for(int i = 0;i < v.size();i++)P(v[i]);
#define printt(a,b) cout << a << " " << b << endl; 
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
int dx[] = { 1, -1 , 0 , 0};
int dy[] = { 0,  0,  1, -1};
int MOD = 1e9 + 7;

void solve() {
    int n; 
    cin >> n;
    int count = 0;
    rep(i,n){
        int a;
        cin >> a;
        if(a != i+1)count++;
    }

    if(count <= 2) {
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
}

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, seisu) for(int i = 0; i < (int)(seisu); i++)
typedef long long ll;
///vector<pair<string, int>>;

int main(){
  int a, b;
  cin >> a >> b;
  string aa = to_string(a);
  string bb = to_string(b);
  string cc = aa + bb;
  int c = atoi(cc.c_str());
  
  int check = 0, i = 1;
  while(check == 0 && i < c/2 + 1){
    int kazu = c/i;
    if(kazu == i && c%i == 0) {
      check = 1;
      
    }
    else i++;
  }
  if (check == 1) cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 3636
/* package whatever; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
class Main {
  private static void solve(int n, int k, int q, int[] a) {
    int[] points = new int[n];
	for (int index : a) {
	  points[index - 1] += 1;
	}
	StringBuilder sb = new StringBuilder();
	for (int i = 0; i < n; i++) {
	  sb.append(points[i] + k - q > 0 ? "Yes" : "No");
	  if (i < n - 1) sb.append("\n");
	}
	System.out.println(sb.toString());
  }
  public static void main (String[] args) throws java.lang.Exception {
	Scanner sc = new Scanner(System.in);
	String[] nums = sc.nextLine().split(" ");
	int n = Integer.parseInt(nums[0]);
	int k = Integer.parseInt(nums[1]);
	int q = Integer.parseInt(nums[2]);
	int[] a = new int[q];
	for (int i = 0; i < q; i++) {
	  a[i] = Integer.parseInt(sc.nextLine());
	}
	solve(n, k, q, a);
  }
}

Measured memory_bytes: 95580
#include <bits/stdc++.h>
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define ll long long
#define pb push_back
#define ff first
#define ss second
#define pll pair<ll,ll>
#define all(v) v.begin(),v.end()
#define mod 998244353
#define mx 1000002
mt19937 myrand(time(0));

ll n,s;
ll a[3002],dp[3002][3002];

ll call(ll pos, ll rem){
    if(pos>n) return rem==0;
    ll &ret=dp[pos][rem];
    if(ret!=-1) return ret;
    ret=0;
    ret=(ret+2*call(pos+1,rem))%mod;
    if(rem>=a[pos]){
        ret=(ret+call(pos+1,rem-a[pos]))%mod; 
    }
    return ret;
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(),cout.tie();
    cin>>n>>s;
    for(int i=1;i<=n;i++) cin>>a[i];
    memset(dp,-1,sizeof dp);
    ll ans=call(1,s);
    cout<<ans<<endl;
    return 0;
}


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

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define lcm( a, b ) (a)/__gcd((a),(b))*(b)
#define endl '\n'

using namespace std;

typedef long long LL;
typedef pair< int, int > P;
typedef pair< LL, LL > LP;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1000000007;
static const int SIZE = 200005;

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

LL fac[SIZE], finv[SIZE], inv[SIZE];
void combInit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for( int i = 2; i < SIZE; ++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 comb(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;

}

vector< int > Div( int n ) {
    vector< int > ret;
    for( int i = 1; i * i <= n; ++i ) {
        if( n % i == 0 ) {
            ret.pb( i );

            if( i * i != n ) ret.pb( n / i );
        }
    }
    sort( all( ret ) );
    return ret;
}

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

    vector< int > v;
    int k;
    for( int i = 0; i < 3; ++i ) {
        int a;
        cin >> a;
        v.pb(a);

    }
    cin >> k;

    sort(all(v));
    for( int i = 0; i < k; ++i ) {
        v[2] *= 2;

    }
    cout << v[0] + v[1] + v[2] << endl;
    return 0;
}



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

using namespace std;
vector<int> G[200010];
int d[200010],p[200010];
vector<int> num[3];
void dfs(int s, int p){
	for(int v:G[s]){
		if(v==p) continue;
		d[v] = d[s] + 1;
		dfs(v,s);
	}
}

int main(){
	int i,n;
	cin >> n;
	for(i=0;i<n - 1;i++){
		int a,b; cin >> a >> b;
		a--; b--;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	d[0] = 0;
	dfs(0,-1);
	int od = 0,ev = 0;
	for(i=0;i<n;i++){
		if(d[i]&1) od++;
		else ev++;
	}
	for(i=1;i<=n;i++){
		num[i%3].push_back(i);
	}
	if(od<=num[0].size()){
		for(i=0;i<n;i++){
			if(d[i]&1){
				p[i] = num[0].back();
				num[0].pop_back();
			}else{
				if(num[1].size()){
					p[i] = num[1].back();
					num[1].pop_back();
				}else if(num[2].size()){
					p[i] = num[2].back();
					num[2].pop_back();
				}else{
					p[i] = num[0].back();
					num[0].pop_back();
				}
			}
		}
	}else if(ev<=num[0].size()){
		for(i=0;i<n;i++){
			if(d[i]&1){
				if(num[1].size()){
					p[i] = num[1].back();
					num[1].pop_back();
				}else if(num[2].size()){
					p[i] = num[2].back();
					num[2].pop_back();
				}else{
					p[i] = num[0].back();
					num[0].pop_back();
				}
			}else{
				p[i] = num[0].back();
				num[0].pop_back();
			}
		}
	}else{
		for(i=0;i<n;i++){
			if(d[i]&1){
				if(num[1].size()){
					p[i] = num[1].back();
					num[1].pop_back();
				}else{
					p[i] = num[0].back();
					num[0].pop_back();
				}
			}else{
				if(num[2].size()){
					p[i] = num[2].back();
					num[2].pop_back();
				}else{
					p[i] = num[0].back();
					num[0].pop_back();
				}
			}
		}
	}
	for(i=0;i<n;i++){
		cout << p[i] << " ";
	}
	cout << endl;
}
	

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

using namespace std;

#define pii pair<int,int>
#define ll long long
#define s second
#define f first

// TARO = 0 JIRO = 1

const int MAX_K=10e5+5,MAX_N=105;
int n,j,k,a[MAX_N];
bool b1,b2,dp[MAX_K][2];

int main(){
  ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
  cin >> n >> k;
  for(int i=0;i<n;++i){
    cin >> a[i];
  }
  for(int i=0;i<a[0];++i){
    dp[i][0]=1;
    dp[i][1]=0;
  }
  for(int i=a[0];i<=k;++i){
    j=0;b1=1;b2=0;
    while(j<n && a[j]<=i){
        if(dp[i-a[j]][1]==0){b1=0;}
        if(dp[i-a[j]][0]==1){b2=1;}
        ++j;
    }
    dp[i][0]=b1;dp[i][1]=b2;
  }
   if(!dp[k][0]){cout << "First";}
   else{cout << "Second";}
}

Measured memory_bytes: 512
use std::io::*;
use std::str::FromStr;

pub fn read<T: FromStr>() -> T {
  let stdin = stdin();
  let stdin = stdin.lock();
  let token: String = stdin
    .bytes()
    .map(|c| c.expect("failed to read char") as char)
    .skip_while(|c| c.is_whitespace())
    .take_while(|c| !c.is_whitespace())
    .collect();
  token.parse().ok().expect("failed to parse token")
}

fn main() {
  let n = read::<i32>();
  let mut a = vec![];
  let mut b = vec![];
  let mut ans = 0;

  for _ in 0..n + 1 {
    let a_i = read::<i64>();
    a.push(a_i)
  }
  for _ in 0..n {
    let b_i = read::<i64>();
    b.push(b_i)
  }

  // b[n]
  for i in 0..n {
    let idx = (n - i - 1) as usize;
    if a[idx + 1] >= b[idx] {
      ans += b[idx];
      a[idx + 1] = a[idx + 1] - b[idx];
    } else {
      ans += a[idx + 1];
      b[idx] = b[idx] - a[idx + 1];


      if a[idx] >= b[idx] {
        ans += b[idx];
        a[idx] = a[idx] - b[idx];
      } else {
        ans += a[idx];
        a[idx] = 0;

      }
    }
  }

  println!("{:?}", ans);
}



Measured memory_bytes: 6396