akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
const int INF = 1e18;

using namespace std;


signed main() {
  int N, M;
  cin >> N >> M;
  if(N == M) Yes;
  else No;

  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
//int mapp[100001][100001];
int main(){
    int n,m;
    cin>>n>>m;
    for(int i=0;i<m;i++){
        int x,y;
        cin>>x>>y;
        if(x>n-x+1)x=n-x+1;
        if(y>n-y+1)y=n-y+1;
        if(y<x){
           // cout<<"??????";
            if(y%3==0)cout<<3<<endl;
            else  if(y%3==1)cout<<1<<endl;
            else cout<<2<<endl;
        }
        else{
            if(x%3==0)cout<<3<<endl;
            else  if(x%3==1)cout<<1<<endl;
            else cout<<2<<endl;
        }
    }
}

Measured memory_bytes: 3080
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String in = sc.nextLine();
		sc.close();
		List<String> list = Arrays.asList(in.split(""));
		int size = list.size();
		if (size % 2 != 0) {
			System.out.println("No");
			return;
		}
		for (int i = 0; i < size; i++) {
			if (i % 2 == 0) {
				if (!list.get(i).equals("h")) {
					System.out.println("No");
					return;
				}
			} else {
				if (!list.get(i).equals("i")) {
					System.out.println("No");
					return;
				}
			}
		}
		System.out.println("Yes");

	}
}


Measured memory_bytes: 21844
import sys
sys.setrecursionlimit(10**9)
from collections import defaultdict

IA = lambda: map(int,input().split())
IAS= lambda: map(str,input().split())

n,m=IA()
a=list(IA())
ans=float(0)

N=int(200005)
s=[int(0) for i in range(N)]

s[1]=a[0]
for i in  range(1,n):
    s[i+1]=s[i]+a[i]
   

    
for i in  range(1,n+1):
   

    if i+m-1>n:break
    #print(s[i+m-1]-s[i-1])
    sum1=(s[i+m-1]-s[i-1]+m)/2

    #print(sum1)
    ans=max(ans,sum1)
    
print("%.12lf"%ans)




Measured memory_bytes: 25564
#include<iostream>
using namespace std;
int main()
{
	int w,h,x,y,r,t=0;
	cin>>w>>h>>x>>y>>r;
	if(x>=r&&y>=r)
	{
		if((w-x)>=r&&(h-y)>=r)
		{
		t=1;}
	}
	if(t==1)
	cout<<"Yes"<<endl;
	else
	cout<<"No"<<endl;
	
	return  0;
 } 


Measured memory_bytes: 3136
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

int main() {
    int n;
    cin >> n;
    vector<int> v(n);
    for(int i = 0; i < n; i++){
        cin >> v[i];
    }
    int q;
    cin >> q;

    for(int i = 0; i < q; i++){
        int b, e, k;
        cin >> b >> e >> k;
        int ans = 0;
        ans = count(v.begin()+b, v.begin()+e, k);
        cout << ans << endl;
    }
}


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

long long getNumberOfWays(vector<vector<char>> grid,int rows,int cols) {
    long long res=0;
    if(rows==0)return 0;
    if(cols==0)return 0;
    vector<vector<long long>> dp(rows,vector<long long>(cols,0));
    dp[0][0]=1;
    for(int i=0;i<rows;i++) {
        for(int j=0;j<cols;j++) {
            if(grid[i][j]=='#') {
                dp[i][j]=0;
            } else{
                dp[i][j]+=(i==0?(j==0?0:dp[i][j-1]):(j==0?dp[i-1][j]:dp[i-1][j]+dp[i][j-1]))%(long long)(1e9+7);
            }
            //cout<<dp[i][j]<<" ";
        }
        //cout<<endl;
    }
    res=dp[rows-1][cols-1];
    return res;
}

int main(void){
    int rows=0,cols=0;
    cin>>rows>>cols;
    vector<vector<char>> grid(rows,vector<char>(cols,0));
    for(int i=0;i<rows;i++) {
        for(int j=0;j<cols;j++) {
            cin>>grid[i][j];
        }
    }
    cout<<getNumberOfWays(grid,rows,cols)<<endl;
}


Measured memory_bytes: 13012
N = int(input())
A = (input()).split()
for i in range(0,N):
    A[i] = int(A[i])
for i in range(0,N):
    innum = A[i]
    j = i - 1
    while j>=0 and innum < A[j]:
        A[j+1] = A[j]
        j = j -1
    A[j+1] = innum
    for j in range(0,N):
        if j < N-1:
            print(A[j], end=" ")
        else:
            print(A[j])

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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  long long sum = 0;
  for (int i = 1; i <= n; i++) {
    if ((i % 3 == 0) || (i % 5 == 0)) {
      continue;
    } 
    sum += (long long)i;
  }
  cout << sum << '\n';
  return 0;
}

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

using namespace std;

template<class T>
inline bool bigOne(T &a, T b) {
    if (a < b) {
        swap(a, b);
        return true;
    }
    return false;
}

int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

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

    vector<int> A(N);
    for (int i = 0; i < N; ++i) cin >> A[i];

    vector<int> left(N + 1, 0), right(N + 1, 0);
    for (int i = 0; i < N; ++i) left[i + 1] = gcd(left[i], A[i]);
    for (int i = N - 1; i >= 0; --i) right[i] = gcd(right[i + 1], A[i]);

    int res = 0;
    for (int i = 0; i < N; ++i) {
        int leftMax = left[i];
        int rightMax = right[i + 1];
        bigOne(res, gcd(leftMax, rightMax));
    }

    cout << res << endl;
    return 0;
}


Measured memory_bytes: 1408
package main

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

func main() {
	sc := NewScanner()
	S := sc.Next()
	Q := sc.NextInt()
	pre := bytes.NewBuffer([]byte{})
	after := bytes.NewBuffer([]byte{})
	isAfter := true
	for i := 0; i < Q; i++ {
		query := sc.NextLine()
		if query == "1" {
			isAfter = !isAfter
		} else {
			split := strings.Split(query, " ")
			addAfter := split[1] == "2"
			if isAfter == addAfter {
				after.WriteByte(split[2][0])
			} else {
				pre.WriteByte(split[2][0])
			}
		}
	}

	if isAfter {
		p := pre.Bytes()
		reverse(p, 0, len(p))

		fmt.Print(string(p))
		fmt.Print(S)
		fmt.Print(after)
	} else {

		p := after.Bytes()
		reverse(p, 0, len(p))
		fmt.Print(string(p))

		p = []byte(S)
		reverse(p, 0, len(p))
		fmt.Print(string(p))

		fmt.Print(pre)

	}
}
func reverse(a []byte, start int, length int) {
	var end = start + length - 1
	for start < end {
		a[start], a[end] = a[end], a[start]
		start++
		end--
	}
}

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r: rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}
func (s *Scanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(s.Next(), 10, 64)
	return v
}

func (s *Scanner) NextFloat() float64 {
	v, _ := strconv.ParseFloat(s.Next(), 64)
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 0)
			result = append(result, int(v))
			start = s.p + 1
		}
	}

	return result
}
func (s *Scanner) NextInt64Array() []int64 {
	s.pre()
	start := s.p
	result := []int64{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 64)
			result = append(result, v)
			start = s.p + 1
		}
	}
	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}


Measured memory_bytes: 5760
#include<iostream>
#include<cstring>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<iomanip>
using namespace std;
#define rep(i,s,n);for(int i = s;i<n;i++)
#define repe(i,s,n);for(int i = s;i<=n;i++)
#define pb push_back
#define fi first
#define se second
typedef long long ll;
typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
static const ll maxLL = (ll)1 << 62;
const int INF = 1<<29;
const int MOD = 1000000009;

int main(){
    int i;
    int a[3][3];
    rep(i,0,3){
        rep(j,0,3)cin>>a[i][j];
    }
    rep(i,0,3){
        int x=min(a[i][0],min(a[i][1],a[i][2]));
        rep(j,0,3)a[i][j]-=x;
    }
    rep(j,0,3){
        int x=min(a[0][j],min(a[1][j],a[2][j]));
        rep(i,0,3)a[i][j]-=x;
    }
    bool can=true;
    rep(i,0,3){
        rep(j,0,3){
        if(a[i][j]!=0)can=false;
        }
    }
    if(can)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <array>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <utility>
#include <cstdlib>
#include <cmath>
#define INF 987654321
#define INT_MAX 2147483647
#define MIN(a, b) ((a) < (b) ? a : b)
#define MAX(a, b) ((a) > (b) ? a : b)

using namespace std;



int main() {
    
    string S;
    cin >> S;
    bool prev = true;
    int cnt = 0;
    int mcnt = 0;
    for(int i = 0; i < 3; i++) {
        if(S[i] == 'R') {
            cnt++;
            if(prev) {
                mcnt = MAX(mcnt, cnt);
            }
        }
        else {
            cnt = 0;
        }
    }
    cout << mcnt;

}


Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string a,b;
    cin>>a;
    cin>>b;
    if(a.size()>b.size())
    {
        puts("GREATER");
        return 0;
    }
    if(a.size()<b.size())
    {
        puts("LESS");
        return 0;
    }
    for(int i=0; i<a.size(); i++)
    {
        if(a[i]>b[i])
        {
            puts("GREATER");
            return 0;
        }
        if(a[i]<b[i])
        {
            puts("LESS");
            return 0;
        }
    }
    puts("EQUAL");
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define INF 1000000000
#define rep(i, n) for(int i = 0; i < n; i++)
#define ALL(x) (x).begin(), (x).end()  //昇順
#define RALL(x) (x).rbegin(), (x).rend() // 降順
const long long mod = 1e9+7;
typedef priority_queue<int> PQ;
typedef vector<long long> Vl;
typedef vector<int> VI;  // VI a(n);
typedef vector<string> VS;  
typedef vector<char> VC; 
typedef vector<VS> VSS;
typedef vector<VC> VCC;    
typedef vector<VI> VVI;   // VVI a(n,vector<int>(m)) n * m 
typedef vector<Vl> VVl;
typedef pair<int, int> PII;
typedef map<int, int> MP;   //MP a;
typedef vector<pair<int, int> > PS;
typedef long long ll;  //ll とdoubleは違う
template <class T>  // chmax(max, a);
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> //chmin(min,a)
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
template<typename T>   // operator << (cout,a);
ostream& operator << (ostream& os, vector<T>& v) {
    os << "{";
    rep(i, (int)v.size()) { os << v[i] << (i < v.size() - 1 ? ", " : ""); }
    os << "}";
    return os;
}

int main(){
    double d,x,y,n,h,k,max=-100000,min=1000000000,ans=0,sum=0;
    string s,t;
    cin >> n >> k;
    VI a(n);
    VI b(n+1);
    VI m(n+1);
    rep(i,n){
        cin >> a[i];
	}
    sort(ALL(a));
    rep(i,n){
        b[a[i]]++;
    }
    rep(i,n+1){
        if(b[i]>0){
            sum++;
        } 
    }

    if(sum<=k){
        cout << 0 << endl;
        return 0;
    }
    sort(ALL(b));
    rep(i,n+1){
        if(b[i]>0){
            if(sum-1<= k){
                ans += b[i];
                cout << ans << endl;
                break;
            }
            else{
                sum--;
                ans += b[i];
            }
        }
    }
    return 0;
}
  


Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
int main(){

  int N;
  int M;
  cin >> N >> M;
  
  vector<int> L(M);
  vector<int> R(M);
  
  vector<int> A(N);
  
  for(int i = 0;i < N;++i){
    A[i] = i + 1;
  }
  
  int num = 1e7;
  
  int num2 = -1;
  
  int num3 = 0;
  
  for(int i = 0;i < M;++i){
    cin >> L[i];
    cin >> R[i];
  }
  
  for(int i = 0;i < M;++i){
     num = min(num,R[i]);
  }
  
  
  for(int j = 0;j < M;++j){
    num2 = max(num2,L[j]);
  }
  
  
  for(int i = 0;i < N;++i){
    if(A[i] >= num2 && A[i] <= num){
      num3++;
    }
  }
  
  cout << num3 << endl;
}


Measured memory_bytes: 1408
n = int(input())
l = list(map(int, input().split()))
l.sort()
c = 1
i = 0
while i < n:
  c *= l[i]
  i += 1
  if c > 1000000000000000000:
    break
if c <= 1000000000000000000:
  print(c)
else:
  print(-1)

Measured memory_bytes: 21576
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod = 1e9 + 7;
const ll inf = (1 << 30) - 1;
const ll infll = (1LL << 61) - 1;

int a, b, k;

int main()
{
    cin >> a >> b >> k;
    for (int i = a; i >= 0; i--)
    {
        k -= a % i == 0 && b % i == 0;
        if (k == 0)
        {
            cout << i << 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 N = sc.nextInt();
        int[] mountains = new int[N];
        for (int i = 0; i < N; i++) {
            mountains[i] = sc.nextInt();
        }
        
        int max = 0;
        int count = 0;
        
        for (int i = 0; i < N; i++) {
        	
        	if (max <= mountains[i]) {
        		count++;
        		max = mountains[i];	
        	}
        }

		
		System.out.println(count);
	}
}


Measured memory_bytes: 21844
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <string>
#include <map>
#include <unordered_map>
#include <iomanip>
#include <unordered_set>
#include <stack>
#include <queue>
#include <bitset>

#define MOD 1000000007
#define pi 3.14159265358979

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

ll field[3005][3005];
ll dp[3005][3005][4];

int main()
{
	int r, c, k;
	cin >> r >> c >> k;

	memset(dp, 0, sizeof(dp));
	memset(field, 0, sizeof(field));

	for (int i = 0; i < k; i++)
	{
		int x, y, v;
		cin >> x >> y >> v;
		field[x - 1][y - 1] = v;
	}

	dp[0][0][0] = 0;
	if (field[0][0])
		dp[0][0][1] = field[0][0];

	for (int i = 1; i < r; i++)
	{
		dp[i][0][0] = max(dp[i - 1][0][0], dp[i - 1][0][1]);
		if (field[i][0])
			dp[i][0][1] = max( dp[i - 1][0][0] + field[i][0], dp[i - 1][0][1] + field[i][0]);
	}

	for (int i = 1; i < c; i++)
	{
		dp[0][i][1] = max(dp[0][i - 1][1], dp[0][i - 1][0] + field[0][i]);
		dp[0][i][2] = max(dp[0][i - 1][2], dp[0][i - 1][1] + field[0][i]);
		dp[0][i][3] = max(dp[0][i - 1][3], dp[0][i - 1][2] + field[0][i]);
	}
	
	for (int i = 1; i < r; i++)
	{
		for (int j = 1; j < c; j++)
		{
			if (!field[i][j])
			{
				dp[i][j][0] = max({ dp[i][j - 1][0], dp[i - 1][j][0], dp[i - 1][j][1], dp[i - 1][j][2], dp[i - 1][j][3] });
				dp[i][j][1] = dp[i][j - 1][1];
				dp[i][j][2] = dp[i][j - 1][2];
				dp[i][j][3] = dp[i][j - 1][3];
			}
			else
			{
				dp[i][j][0] = max({ dp[i][j - 1][0], dp[i - 1][j][0], dp[i - 1][j][1], dp[i - 1][j][2], dp[i - 1][j][3] });
				dp[i][j][1] = max({ dp[i][j - 1][1], dp[i][j - 1][0] + field[i][j], dp[i - 1][j][0] + field[i][j], dp[i - 1][j][1] + field[i][j], dp[i - 1][j][2] + field[i][j], dp[i - 1][j][3] + field[i][j] });
				dp[i][j][2] = max(dp[i][j - 1][2], dp[i][j - 1][1] + field[i][j]);
				dp[i][j][3] = max(dp[i][j - 1][3], dp[i][j - 1][2] + field[i][j]);
			}
		}
	}

	cout << max({ dp[r - 1][c - 1][0], dp[r - 1][c - 1][1], dp[r - 1][c - 1][2],dp[r - 1][c - 1][3] });

	return 0;
}


Measured memory_bytes: 355920
import itertools

A=range(0,int(input())+1)
B=range(0,int(input())+1)
C=range(0,int(input())+1)
X=int(input())

res=[]

for a,b,c in itertools.product(A,B,C):
    res.append(500*a+100*b+50*c)
    
print(res.count(X))

Measured memory_bytes: 8404
#include <stdio.h>
 
int X;
int parent[100001];
int sibling[100001];
int degree[100001];
 
int Depth(int i) {
  if(parent[i] == -1) return 0;
  return Depth(parent[i]) + 1;
}
 
int Height(int i) {
  int j, h;

  h = 0;
  for(j = 0; j < X; ++j) {
    if(parent[j] == i) {
      int tmp = Height(j) + 1;
      if(tmp > h) h = tmp;
    }
  }
  return h;
}
 
int main() {
  int i,j;

  scanf("%d", &X); 

  for(i = 0; i < X; ++i) {
    parent[i] = -1;
    sibling[i] = -1;
    degree[i] = 0;
  }
  for(i = 0; i < X; ++i) {
    int id, left, right;

    scanf("%d %d %d", &id, &left, &right);
    if(left != -1) {
      parent[left] = id;
      sibling[left] = right;
      ++degree[id];
    }
    if(right != -1) {
      parent[right] = id;
      sibling[right] = left;
      ++degree[id];
    }
  }
 
  for(i = 0; i < X; ++i) {
    int depth = Depth(i);

    printf("node %d: parent = %d, sibling = %d, degree = %d, depth = %d, height = %d, ",i, parent[i], sibling[i], degree[i], depth, Height(i));

    if(depth == 0) {
      printf("root\n");
    }
    else if(degree[i] == 0) {
      printf("leaf\n");
    } 
    else {
      printf("internal node\n");
    }
  }
                                                                            
  return 0;

}

Measured memory_bytes: 620
#include <cstdio>
#include <algorithm>
using namespace std;
#define ll long long
int main(){
	ll n;
	scanf("%lld", &n);
	ll a[n];
	for (ll i = 0; i < n; i++) scanf("%lld", &a[i]);
	ll dp[n][n];
	if (n % 2 == 0){
		for (ll i = 0; i < n; i++) dp[i][i] = -a[i];
	}else{
		for (ll i = 0; i < n; i++) dp[i][i] = a[i];
	}
	for (ll i = 1; i < n; i++){
		for (ll j = 0; i + j < n; j++){
			if ((n - i) % 2 == 0){
				dp[j][i + j] = min(-a[j] + dp[j + 1][i + j], -a[i + j] + dp[j][i + j - 1]);
			}else{
				dp[j][i + j] = max(a[j] + dp[j + 1][i + j], a[i + j] + dp[j][i + j - 1]);
			}
		}
	}
	printf("%lld\n", dp[0][n - 1]);
}

Measured memory_bytes: 70272
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <map>
#include <iomanip>
#define intt long long

int main() {
	char a; std::cin >> a;
	if ('a' <= a && a <= 'z')
		std::cout << "a" << std::endl;
	else
		std::cout << "A" << std::endl;

}


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

int main(){
  int n; cin>>n;
  vector<int> p(n);
  for (int i=0; i<n; i++) cin>>p[i];
  int cnt=0;
  for (int j=0; j<n; j++){
    if (j+1!=p[j]) cnt+=1;
  }
  cout<<(cnt==0 | cnt==2 ? "YES" : "NO")<<endl;
}

Measured memory_bytes: 256
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <ctime>
#include <iterator>
#include <bitset>
#include <numeric>
#include <list>
#include <iomanip>
using namespace std;


typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
	v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
	stringstream ss;
	ss << f;
	ss >> t;
}


#define REP(i,n) for(int i=0;i<int(n);++i)
#define ALL(v) (v).begin(),(v).end()
#define RALL(v) (v).rbegin(),(v).rend()
#define PB push


#define MOD 1000000007LL
#define EPS 1e-10

int main()
{
	int N;
	cin >> N;
	cout << N * ( N + 1 ) / 2 << endl;
	return 0;
}


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

using namespace std;

#define all(x) x.begin(), x.end()
#define sz(x) (int) x.size()
#define pb push_back
#define endl '\n'
#define snd second
#define fst first
#define fastio cin.tie(NULL),cout.sync_with_stdio(true)

typedef long long int ll;
typedef unsigned long long int ull;
typedef vector <int> vi;
typedef pair <ll,int> ii;
typedef pair <ii,int> iii;

const int mod = 1e9 + 7;
const int N = 200005;

void solve(){
    int n;
    cin >> n;
    vi a(n), b(n);
    for(int i = 0; i < n; i++){
        cin >> a[i] >> b[i];
    }
    sort(all(a));
    sort(all(b));
    if(n&1) {
        cout << b[n/2] - a[n/2] + 1 << endl;
    } else {
        cout << (b[n/2-1] + b[n/2]) - (a[n/2-1] + a[n/2]) + 1 << endl;
    }
}


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


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

   typedef long long ll;
   typedef pair<ll, ll> Pii;
   typedef vector<ll> vi;
   typedef vector<vector<ll>> vvi;


   const double EPS = (1e-7);
   const ll INF =(1e13);
   const double PI = (acos(-1));
   const ll MOD = ll(1e9) + 7;

   #define REP(i, n) for(ll i = 0; i < (ll)(n); i++)
   #define REPR(i, n) for(ll i = n; i > -1; i--)
   #define FOR(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
   #define ALL(x) (x).begin(),(x).end()
   #define SORT(x) sort((x).begin(), (x).end())
   #define REVERSE(x) reverse((x).begin(), (x).end())
   #define SZ(x) ((ll)(x).size())
   #define pb push_back
   #define mp make_pair

   //chmax(a, b): a>bならaをbで更新　更新したときにtrueを返す
   //chmin(a, b): a<bならaをbで更新　更新したときにtrueを返す
   template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
   template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

   #define dump(x) cerr<< #x << "= " << (x) << endl;

   ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
   ll pow(ll a, ll b){if (b == 0) return 1; else if (b % 2 == 0) return pow(a * a, b / 2); else return pow(a * a, b / 2) * a;}


   ll dx[4]={1,0,-1,0};
   ll dy[4]={0,1,0,-1};

   // O( n )
   vvi identity(ll n) {
     vvi A(n, vi(n));
     REP(i, n) A[i][i] = 1;
     return A;
   }
   // O( n )
   ll inner_product(const vi &a, const vi &b) {
     ll ans = 0;
     REP(i, a.size()){
       ans += a[i] * b[i];
     }
     return ans;
   }
   // O( n^2 )
   vi mul(const vvi &A, const vi &x) {
     vi y(A.size());
     for (ll i = 0; i < A.size(); ++i)
       for (ll j = 0; j < A[0].size(); ++j){
         y[i] = A[i][j] * x[j];
         y[i] %= MOD;
       }
     return y;
   }
   // O( n^3 )
   vvi mul(const vvi &A, const vvi &B) {
     vvi C(A.size(), vi(B[0].size()));
     for (ll i = 0; i < C.size(); ++i)
       for (ll j = 0; j < C[i].size(); ++j)
         for (ll k = 0; k < A[i].size(); ++k){
           C[i][j] += A[i][k] * B[k][j];
           C[i][j] %= MOD;
         }
     return C;
   }
   // O( n^3 log e )
   vvi pow(const vvi &A, ll e) {
     return e == 0 ? identity(A.size())  :
        e % 2 == 0 ? pow(mul(A, A), e/2) : mul(A, pow(A, e-1));
   }

const ll MAX_N = 50;
ll N, K;

int main(){
  cin >> N >> K;
  vvi a(N, vi(N));
  REP(i, N){
    REP(j, N){
      cin >> a[i][j];
    }
  }
  vvi b = pow(a, K);
  ll ans = 0;
  REP(i, N){
    REP(j, N){
      ans += b[i][j];
      ans %= MOD;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 1536
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<int,int> P;
const LL mod=1000000007;
const LL LINF=1LL<<60;
const int INF=1<<30;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
 

int main(){
    int n,l;cin >> n >> l;
    int sum = 0;
    for (int i = 0; i < n; i++) {
        sum += l+i;
    }
    int ans = INF,t=0;
    for (int i = 0; i < n; i++) {
        if(ans > abs(sum-(sum-(l+i)))){
            ans = abs(sum-(sum - (l+i)));
            t=sum - (l+i);
        }
    }
    cout << t << endl;
    return 0;
}


Measured memory_bytes: 256
package main

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

func main() {
	r := bufio.NewReader(os.Stdin)
	s, _ := r.ReadString('\n')
	if s[2] == s[3] && s[4] == s[5] {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


Measured memory_bytes: 1772
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;

const int MAXN = 100010;
char str[ MAXN ];
int main()
{
    int length = 0, k;
    scanf("%s", str);
    length = strlen(str);
    cin >> k;
    for (int i = 0; i < length; ++i)
        if (str[i] != 'a' && k >= 'z' - str[i] + 1) {
            k -= 'z' - str[i] + 1;
            str[i] = 'a';
        }
    if (k > 0) {
        int tp = str[ length - 1 ] - 'a';
        //cerr << tp << endl;
        tp = (tp + k) % 26;
        str[ length - 1 ] = tp + 'a';
    }
    printf("%s\n", str);
    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())

using namespace std;
using ll = long long;

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; }
constexpr int INF = 1001001001;
constexpr long long INFL = (1LL<<60);
constexpr double eps = (1e-9);

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

  ll n, m, k;
  cin >> n >> m >> k;

  vector<ll> a(n), b(m);
  rep(i, n) cin >> a[i];
  rep(i, m) cin >> b[i];

  ll tmp = 0;
  int x = -1;

  // a を読めるだけ読む
  for (int i = 0; i < n; i++) {
    if (k >= a[i]) {
      tmp++;
      x = i;
      k -= a[i];
    } else {
      break;
    }
  }

  cerr << "tmp: " << tmp << "  k: " << k << endl;

  ll ans = tmp;

  for (int i = 0; i < m; i++) {
    k -= b[i];
    while (k < 0 && x >= 0) {
      k += a[x];   // a の x 番目を読まなかったことにする
      x--;
      tmp--;
    }
    if (k >= 0) tmp++;
    else break;   // b に集中して読み切った
    chmax(ans, tmp);
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 6360
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <functional>
#include <utility>
#include <tuple>
#include <cctype>
#include <bitset>
#include <complex>
#include <cmath>
#include <array>
#include <numeric>
using namespace std;
#define INF 0x3f3f3f3f
#define INFLL 0x3f3f3f3f3f3f3f3fLL
//#define mod 998244353
#define MOD 1000000007
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
#define INT_MAX INF
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pint;
typedef pair<ll,ll> pll;
typedef tuple<int,int,int> tint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<ull> vull;
typedef vector<pint> vpint;
int dx[8]={0,0,-1,1,1,1,-1,-1};
int dy[8]={-1,1,0,0,1,-1,1,-1};
const int SIZE=200050;
int main() {
	int N;
	cin>>N;
	vint W;
	int sum=0;
	for(int i=0;i<N;i++){
		int w;
		cin>>w;
		W.pb(w);
		sum+=w;
	}
	int ans=INF;
	for(int i=0;i<N;i++){
		int temp=0;
		for(int j=0;j<=i;j++)
			temp+=W[j];
		ans=min(ans,abs(temp-sum+temp));
	}
	cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rep1(i,n) for(int i=1;i<=(int)n;i++)
#define rep2(i,j,n) for(int j=i;j<n;j++)
#define rep3(i,j,n) for(int j=i;j<=n;j++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define sp(n) cout << fixed << setprecision(n)
typedef long long ll;
using namespace std;
int main(void){
    ll n,m;cin>>n>>m;
    vector<ll> a(n);
    rep(i,n) cin>>a[i];
    vector<ll> b(n);
    b[0]=a[0];
    rep(i,n-1) b[i+1]=b[i]+a[i+1];
    map<ll,ll> mp;
    rep(i,n) mp[b[i]%m]++;
    ll res=0;
    for(auto&p:mp){
        if(p.first==0)res+=p.second;
        res+=(p.second)*(p.second-1)/2;
    }
    cout<<res<<endl;
}



Measured memory_bytes: 5760
S=input()
S=list(S)
N=len(S)

x=0
for i in range(1,N):
    if S[i-1]=="0":
        if S[i-1]==S[i]:
            S[i]="1"
            x+=1
    else:
        if S[i-1]==S[i]:
            S[i]="0"
            x+=1

print(x)

Measured memory_bytes: 49392
import scala.annotation.tailrec
import scala.collection.mutable

object Main extends App {
  import scala.io.StdIn._

  solve()
  @tailrec
  def solve(second: Boolean = false): Unit = {
    val Array(n, m) = readLine.trim.split(' ').map(_.toInt)
    if (n == 0 && m == 0) return
    if (second) println()
    val menu = Array.tabulate(n) { rank ⇒
      val Array(name, limit, time) = readLine.trim.split(' ')
      (name, Menu(name, limit.toInt, time.toInt, rank))
    }.toMap

    val customers = Array.tabulate(m) { _ ⇒
      val order = readLine.trim.split(' ')
      new Customer(order.head.toInt, order.drop(2).map(menu))
    }

    val hall = new Hall(customers, menu.toArray.map(_._2))

    println(
      f(hall).mkString("\n")
    )
    solve(true)
  }
  @tailrec
  def f(hall: Hall, time: Int = 0): Array[Int] = {
    hall.nextCustomer() match {
      case None ⇒ hall.allCustomers.map(_.lastServeTime)
      case Some(c) if c.time <= time ⇒
        val menu = c.unServedMenu.head
        val waiting = hall.currentWaiting(menu, time)
        hall.serve(menu, math.min(waiting, menu.limit), time + menu.time)
        f(hall, time + menu.time)
      case Some(c) ⇒ f(hall, c.time)
    }
  }

  class Hall(private[this] val customers: Array[Customer], menu: Array[Menu]) {
    private[this] val waiting = mutable.Map[String, List[Customer]]().withDefaultValue(Nil).also{map ⇒
      customers.reverseIterator.foreach{c ⇒
        c.unServedMenu.foreach(m ⇒ map(m.name) ::= c)
      }
    }
    private[this] var firstIn: Int = 0
    def nextCustomer(): Option[Customer] = Some(firstIn).filter(customers.indices.contains).map(customers)
    def serve(menu: Menu, dish: Int, time: Int): Unit = {
      val (s, r) = waiting(menu.name).splitAt(dish)
      s.foreach(_.serve(menu, time))
      waiting(menu.name) = r
      while(firstIn < customers.length && customers(firstIn).isServeAll){
        firstIn += 1
      }
    }
    def currentWaiting(menu: Menu, time: Int): Int = {
      waiting(menu.name).takeWhile(_.time <= time).length
    }
    def allCustomers: Array[Customer] = customers
  }


  class Customer(val time: Int, order: Seq[Menu]) {
    private[this] var orders: List[Menu] = order.sorted.toList
    private[this] var lastServed = -1
    def serve(menu: Menu, servedTime: Int): Unit = {
      orders = orders.span(_ != menu) match {
        case (a, Nil) ⇒ a
        case (a, _::b) ⇒ a ::: b
      }
      lastServed = servedTime
    }
    def unServedMenu: Iterable[Menu] = orders
    def lastServeTime = lastServed
    def isNotServeAll: Boolean = !isServeAll
    def isServeAll: Boolean = orders.isEmpty
  }
  case class Menu(name: String, limit: Int, time: Int, rank: Int) extends Ordered[Menu] {
    override def compare(that: Menu): Int = if (time == that.time) rank.compare(that.rank) else that.time.compare(time)
  }
  implicit class Scope[T](val value: T) extends AnyVal {
    @inline
    def let[A](func: T ⇒ A): A = func(value)
    @inline
    def also(func: T ⇒ Unit): T = {
      func(value)
      value
    }
  }
}



Measured memory_bytes: 75764
n=int(input())
a=sorted(list(map(int,input().split())))
b=list(map(int,input().split()))
c=sorted(list(map(int,input().split())))

def bin_a(list,bi):
    ok=-1
    ng=n
    while abs(ok-ng)>1:
        mid=(ok+ng)//2
        if bi>list[mid]:
            ok=mid
        else:
            ng=mid
    return ok+1
def bin_c(list,bi):
    ok=n
    ng=-1
    while abs(ok-ng)>1:
        mid=(ok+ng)//2
        if bi<list[mid]:
            ok=mid
        else:
            ng=mid
    return n-ok

cnt=0
for i in range(n):
    cnt+=bin_a(a,b[i])*bin_c(c,b[i])
    #print(bin_a(a,b[i]),bin_c(c,b[i]))
print(cnt)

Measured memory_bytes: 24052
/*================================================================
*
*   创 建 者： badcw
*   创建日期： 2020/6/21 20:04
*
================================================================*/
#include <bits/stdc++.h>

#define ll long long
using namespace std;

const int maxn = 10;
const int mod = 1e9+7;
ll qp(ll a, ll n, ll mod = ::mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

int main(int argc, char* argv[]) {
    ll n;
    scanf("%lld", &n);
    string s;
    while (n > 0) {
        if (n % 26 == 0) {
            s += 'z';
//            putchar('z');
            n --;
        } else {
            s += 'a' + n % 26 - 1;
//            putchar('a' + n % 26 - 1);
        }
        n /= 26;
    }
    reverse(s.begin(), s.end());
    cout << s << endl;
    return 0;
}

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

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            A();
        }

        static void A()
        {
            var PQR = ReadSplitInt().OrderBy(x => x).ToArray();
            Println(PQR[0] + PQR[1]);
        }

        static IEnumerable<int> Range(int start, int stop)
        {
            if (start < 0 || stop < 0 || start > stop || (start <= 0 && stop <= 0))
                return new List<int>();

            return Enumerable.Range(start, stop - start);
        }

        static bool IsDigit(string str)
        {
            var i = 0;
            return int.TryParse(str, out i);
        }

        static int SumDigits(long num)
        {
            return num.ToString().Select(x => x.ToString()).Sum(int.Parse);
        }

        static int[] ToIntArray(string str)
        {
            return str.Select(x => x.ToString()).Select(int.Parse).ToArray();
        }

        static int Gcd(int a, int b) => b == 0 ? a : Gcd(b, a % b);

        static bool IsPrime(int x)
        {
            if (x <= 1 || (x != 2 && x % 2 == 0)) return false;
            if (x == 2) return true;

            for (int i = 3; i < x; i += 2)
                if (x % i == 0) return false;

            return true;
        }

        static string Read() => Console.ReadLine();
        static int ReadInt() => int.Parse(Read());
        static long ReadLong() => long.Parse(Read());

        static List<string> ReadSplit() => Read().Split().ToList();
        static List<int> ReadSplitInt() => Read().Split().Select(int.Parse).ToList();
        static List<long> ReadSplitLong() => Read().Split().Select(long.Parse).ToList();

        static void Print(object value) => Console.Write(value.ToString());
        static void Println(object value) => Console.WriteLine(value.ToString());

        static string Join<T>(IEnumerable<T> list) => string.Join("", list);
    }

    public static class MyExtensions
    {
        public static string Slice(this string str, int start = 0, int stop = 0)
        {
            if (start > str.Length || stop > str.Length || start < 0 || stop < 0)
                return "";

            if (stop == 0) stop = str.Length;
            return str.Substring(start, stop - start);
        }
    }
}

Measured memory_bytes: 13396
A, B, C, D, E, F = [int(x) for x in input().split()]


ablist = []

a, b = 0, 0
while (100 * A * a + 100 * B * b <= F):
    while (100 * A * a + 100 * B * b <= F):
        ablist.append((a, b))
        b += 1
    a += 1
    b = 0
ablist.remove((0, 0))

wlist = [100 * A * ab[0] + 100 * B * ab[1] for ab in ablist]
wset = set(wlist)

cdlist = []
c, d = 0, 0
while (C * c + D*d <= F):
    while (C * c + D * d <= F):
        cdlist.append((c, d))
        d += 1
    c += 1
    d = 0

slist = [C * cd[0] + D * cd[1] for cd in cdlist]
sset = set(slist)

max_rate = -1
ret_sw = 0
ret_s = 0

for w in wset:
    for s in sset:
        if s + w <= F:
            rate = s / (s + w)
            if rate <= E/(E+100):
                if max_rate < rate:
                    max_rate = rate
                    ret_sw = s + w
                    ret_s = s

print("{} {}".format(ret_sw, ret_s))



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

int	main() {
	long x, y;
	cin >>x >>y;
	long B=0;
	while (x!=y) {
		if (y>0) {
			if (x>y) {
				x=-x;
				B++;
			} else if (x>=0) {
				B +=y-x;
				x=y;
			} else if (x>=-y) {
				x=-x;
				B++;
			} else {
				B += -y-x;
				x=-y;
			}
		} else {
			if (x>=-y) {
				x=-x;
				B++;
			} else if (x>=0) {
				B +=-y-x;
				x=-y;
			} else if (x>y) {
				x=-x;
				B++;
			} else {
				B +=y-x;
				x=y;
			}
		}
	}
	cout <<B <<endl;
	return 0;
}


Measured memory_bytes: 256
def combination(n, r):
    r = min(r, n-r)
    tmp = 1
    for i in range(r):
        tmp *= (n-i)
    for i in range(r):
        tmp //= (i+1)
    return tmp


def main():
    N, P = map(int, input().split())
    A = list(map(int, input().split()))
    odds = 0
    for a in A:
        if a % 2 == 1:
            odds += 1
    ans = 0
    for i in range(P, odds+1, 2):
        ans += combination(odds, i)
    ans *= 2**(N-odds)
    print(ans)


if __name__ == "__main__":
    main()


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

int main(){
  int n;
  cin >> n;
  int p[n];
  rep(i, n) cin >> p[i];
  int ans = 0;
  rep(i, n-1){
    if(p[i] == i+1) {
      swap(p[i], p[i+1]);
      ans++;
    }
  }
  if(p[n-1] == n) ans++;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 640
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define MT make_tuple
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
#define RT return
#define vv(a,b,c,d) vector<vector<a> >(b,vector<a>(c,d))
#define vvv(a,b,c,d,e) vector<vector<vector<a> > >(b,vv(a,c,d,e))
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vll = vector<ll>;

template<int MOD>
class ModInt {
public:
    ModInt() :value(0) {}
    ModInt(long long val) :value((int)(val<0 ? MOD + val%MOD : val%MOD)) { }

    ModInt& operator+=(ModInt that) {
        value = value + that.value;
        if (value >= MOD)value -= MOD;
        return *this;
    }
    ModInt& operator-=(ModInt that) {
        value -= that.value;
        if (value<0)value += MOD;
        return *this;
    }
    ModInt& operator*=(ModInt that) {
        value = (int)((long long)value * that.value % MOD);
        return *this;
    }
    ModInt &operator/=(ModInt that) {
        return *this *= that.inverse();
    }
    ModInt operator+(ModInt that) const {
        return ModInt(*this) += that;
    }
    ModInt operator-(ModInt that) const {
        return ModInt(*this) -= that;
    }
    ModInt operator*(ModInt that) const {
        return ModInt(*this) *= that;
    }
    ModInt operator/(ModInt that) const {
        return ModInt(*this) /= that;
    }
    ModInt pow(long long k) const {
        ModInt n = *this, res = 1;
        while (k) {
            if (k & 1)res *= n;
            n *= n;
            k >>= 1;
        }
        return res;
    }
    ModInt inverse() const {
        long long a = value, b = MOD, u = 1, v = 0;
        while (b) {
            long long t = a / b;
            a -= t * b;
            swap(a, b);
            u -= t * v;
            swap(u, v);
        }
        return ModInt(u);
    }
    int toi() const { return value; }

private:
    int value;
};
typedef ModInt<1000000007> mint;
ostream& operator<<(ostream& os, const mint& x) {
    os << x.toi();
    return os;
}

string S;
int N; // 3<=N<=10^5
string T = "ABC";

mint dp[100005][4];

void f(int i, int j, char c) {
    dp[i + 1][j] += dp[i][j];
    if (j < 3 && T[j] == c) {
        dp[i + 1][j + 1] += dp[i][j];
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);

    cin >> S;
    N = sz(S);
    dp[0][0] = 1;

    rep(i, N) {
        char c = S[i];
        rep(j, 4) {
            if (c != '?') {
                f(i, j, c);
            } else {
                for (char d = 'A'; d <= 'C'; ++d) {
                    f(i, j, d);
                }
            }
        }
    }
    cout << dp[N][3] << endl;
}

Measured memory_bytes: 2048
#include<iostream>
#include<algorithm>
using namespace std;
int dp[10][1<<10][331], n; //nの制約は自明だけど sはどれくら(ry ← 331か
int rec( int now, int used,int sum){
  if( sum < 0 ) return 0;
  if( now == n ) return sum == 0;
  if(~dp[now][used][sum]) return dp[now][used][sum];
  int ret = 0;
  for(int i = 0 ; i < 10 ; i++ ){
    if((used >> i) & 1)
      ret += rec( now + 1, used&~(1 << i), sum - i * (now + 1));
  }
  return dp[now][used][sum] = ret;
}
int main(){
  int s;
  while(cin >> n >> s){
    fill_n( **dp, 10 * (1 << 10) * 331, -1);
    cout << rec( 0, (1 << 10) - 1, s) << endl;
  }
}

Measured memory_bytes: 14400
#include <stdio.h>

int main(void) {
	int a, b, n;
	int i;
	int ans;
	while (scanf("%d %d %d", &a, &b, &n) != EOF) {
		ans = 0;
		a %= b;
		for (i = 0; i < n; i++) {
			ans += a * 10 / b;
			a = a * 10 % b;
		}
		printf("%d\n", ans);
	}
	return 0;
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
#define FIO ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define FOR(a,b,c) for(int a = (b); a <= (c); a++)
#define RFOR(a,b,c) for(int a = (b); a >= (c); a--)
#define all(x) (x).begin(), (x).end()
#define vi vector <int>
#define vvi vector <vi>
#define ll long long
#define vll vector <ll>
#define vvl vector <vll>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define eb emplace_back
#define ep emplace
#define fs first
#define sd second
#define mod 998244353
#define EPS 1e-9
#define tc int t; cin >> t; while(t--)
using namespace std;


int main() {
	FIO;
	int n, m, q; cin >> n >> m >> q;
	vi a, b, c, d;
	a = b = c = d = vi(55);
	vi arr(55);
	int ans = 0;
	FOR(i, 1, q)
		cin >> a[i] >> b[i] >> c[i] >> d[i];

	function <void(int,int)> go = [&](int here, int lv) {
		if (lv == n + 1) {
			int sum = 0;
			FOR(i, 1, q) {
				if (arr[b[i]] - arr[a[i]] != c[i]) continue;
				sum += d[i];
			}
			ans = max(ans, sum);
			return;
		}
		FOR(i, here, m) {
			arr[lv] = i;
			go(i, lv + 1);
		}
	};

	go(1, 1);
	cout << ans << '\n';
	return 0;
}

Measured memory_bytes: 3660
#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 1000000001


int main(){
	
	int N;
	cin>>N;
	
	int ans = 1;
	for(int i=1;i<=N;i++){
		ans = mod(ans * i);
	}
	
	cout<<ans<<endl;
	
    return 0;
}



Measured memory_bytes: 256
//============================================================================
// Name        :
// Author      : John Purcell
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>
#include <functional>
#include <iomanip>

using namespace std;

#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() {
    double L;
    cin>>L;
    cout << fixed << setprecision(10);

    cout<<L*L*L/27<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<n+1;i++)
#define sort(A) sort(A.begin(),A.end())
#define reverse(A) reverse(A.begin(),A.end())
typedef long long ll;
typedef pair<int,int> P;

int main(){
  vector<int> a(3);
  rep(i,3) cin >> a[i];
  sort(a);
  int ans = 0;
  if((a[1]-a[0])%2){
    ans = a[2] - a[1] + (a[1]-a[0])/2 + 2;
  }else{
    ans = a[2] - a[1] + (a[1]-a[0])/2;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
#include<string.h>
#include<math.h>
#define ll long long
using namespace std;
ll b[1000005];
int main()
{
    int n;
    scanf("%d",&n);
    
    ll a[100005],i;
    
    for(i=0; i<n; i++)
        scanf("%lld",&a[i]);
    memset(b,0,sizeof(b));
    if(n>=1e5)
        a[-2]=0;
    if(a[0]!=0)
            printf("0\n");
    else
    {
        ll ans=1;
        for(i=0;i<n;i++)
            b[a[i]]++;
        for(i=1;i<n;i++)
        {
            ans*=b[a[i]-1];
            ans%=998244353;
        }

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


Measured memory_bytes: 8832
#include <bits/stdc++.h>
#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() {
    ll a,b,c,d,ans;
    cin >> a >> b >> c >> d;
    ans = a*c;
    ans = max(ans, a*d);
    ans = max(ans, b*c);
    ans = max(ans, b*d);
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
#define forloop(n) for(int i = 0; i < n; i++)
#define ll long long
 
#define mod 1000000007

ll ebob(ll a, ll b){
	if(a == 0) return b;
	return ebob(b%a, a);
}
int main(){
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	ll a,b,k; cin>>a>>b>>k;
	if(a > k){
		a -= k;
		k = 0;
	}else{
		k -= a;
		a = 0;
	}
	if(b > k){
		b -= k;
		k = 0;
	}else{
		k -= b;
		b = 0;
	}
	cout<<a<<" "<<b;
	return 0;
}

Measured memory_bytes: 256
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
from bisect import bisect_left 
def main():
    n = int(readline())
    d = [int(i) for i in readline().split()]
    INF = int(1e5)+1
    d.sort()
    ins_pos = n//2    
    cnt = 0 
    for k in range(1, INF):
        idx = bisect_left(d, k)
        if idx == ins_pos:
            cnt += 1
    print(cnt)
if __name__ == '__main__':
    main()


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

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

  if (S == "Sunny") {
    printf("Cloudy");
  } else if (S == "Cloudy") {
    printf("Rainy");
  } else {
    printf("Sunny");
  }
  return 0;
}


Measured memory_bytes: 256