akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i < b; i++)
using namespace std;

int main() {
    int h, w;
    cin >> h >> w;

    vector<string> s(h);
    rep(i, 0, h) cin >> s[i];

    vector<vector<int>> dist(h, vector<int>(w, -1));

    queue<pair<int, int>> que;
    que.push(make_pair(0, 0));
    dist[0][0] = 0;

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

    while (!que.empty()) {
        pair<int, int> from = que.front();
        que.pop();

        rep(i, 0, 4) {
            int nx = from.first + dx[i];
            int ny = from.second + dy[i];

            if (nx < 0 || h <= nx || ny < 0 || w <= ny) continue;
            if (dist[nx][ny] != -1 || s[nx][ny] == '#') continue;

            dist[nx][ny] = dist[from.first][from.second] + 1;
            que.push(make_pair(nx, ny));
        }
    }

    int cnt = 0;
    rep(i, 0, h) rep(j, 0, w) cnt += (s[i][j] == '.');

    int ans = cnt - dist[h - 1][w - 1] - 1;
    cout << (dist[h - 1][w - 1] == -1 ? -1 : ans) << endl;
    
    return 0;
}

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

typedef long long ll;

int main()
{
    int n,i;
    cin >> n;
    vector<int> a(n);
    
    for(i = 0;i < n;++i){
        cin >> a.at(i);
    }
    sort(a.begin(),a.end());
    vector<pair<int,int>> p;
    int now = a.at(0);
    int number = 1;
    for(i = 1; i < n;++i){
        if(a.at(i) != now){
            p.emplace_back(now,number);
            now = a.at(i);
            number = 1;
        }else{
            ++number;
        }
    }
    p.emplace_back(now,number);
    int temp = 0;
    for(i = 0;i < p.size();++i){
        if(p.at(i).second % 2 == 0){
            ++temp;
        }
    }
    if(temp%2 == 0){
        cout << p.size() << endl;
    }else{
        cout << p.size()-1 << endl;
    }
    return 0;
}

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

using ll = long long;
using namespace std;
const int INFint = 2e9+1;
const ll INFll = 2e18+1;
ll MOD=1e9+7;


int main(){
  ll A,B,C,K;
  cin>>A>>B>>C>>K;
  ll ans(0);
  ans = min(A,K);
  if(K <= A+B){
    cout << ans << endl;
    return 0;
  }
  cout << A - (K - A - B) << endl;
  return 0;
}



Measured memory_bytes: 3632
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long ll;
// numeric_limits<int>::max()

int main(void)
{
    int N, K;
    cin >> N >> K;
    double ratio = 0;
//     vector<int> hoge(N+1);
    for (int i = 1; (i <= N); ++i) {
        int bar;
        if (K > i) {
            double rere = (double)K/i;
            double foo = log(rere) / log(2);
            bar = foo;
            if (foo > bar) ++bar;
            bar = pow(2, bar);
        } else {
            bar = 1;
        }
//         hoge[i] = N * pow(2, bar);
        ratio += 1.0 / (N * bar);
    }
    cout << setprecision(20) << ratio << endl;
//     cout << ratio << endl;

//     vector<int> huga(N+1);
//     int bunbo = hoge[1];
// //     int bunboTotal = 0;
//     int bunshiTotal = 0;
//     for (int i = 1; (i <= N); ++i) {
//         if (hoge[i] == 0) continue;
//         if (bunbo % hoge[i] != 0)
//             cout << "error" << endl;
//         huga[i] = bunbo / hoge[i];
// //         bunboTotal += hoge[i];
//         bunshiTotal += huga[i];
//     }
//     cout << setprecision(20) << (double)bunshiTotal/hoge[1] << endl;
    return 0;
}


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

using namespace std;

int main()
{
    int n;
    set<int> st;

    cin >> n;
    for (int i = 0; i < n; i++){
        int buf;

        cin >> buf;
        st.insert(buf);
    }

    cout << st.size() << endl;

    return 0;
}


Measured memory_bytes: 256
// AOJ 2904: GuruGuru
// 2019.2.23 bal4u

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

char S[1005], *s;

int main()
{
	int dir, f, ans;

	scanf("%s", s = S);
	dir = f = ans = 0;
	while (*s) {
		if (*s++ == 'L') dir = (dir + 3) % 4;
		else {
			dir = (dir + 1) % 4;
			f |= 1 << dir;
		}
		if (dir == 0) {
			if (f == 0xf) ans++;
			f = 0;
		}
	}
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 2056
/**
 *   Author: Praveen Ojha
 *   Created: 25 March 2019
 *   Time: 00:50:09
**/
#include <bits/stdc++.h>
using namespace std;
//#define int long long
#define mod 1000000007
#define PI 3.141592653589793238510
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define __ ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

typedef long double ld;
typedef pair<int,int> pii;
int n,m;
char grid[1005][1005];
int dp[1001][1001];  // dp[i][j] all paths from (0,0) to (i,j) 
// int solve(int i,int j){
// 	if(i>=n || j>=m)
// 		return 0;
// 	if(grid[i][j]=='#')
// 		return 0;
// 	if(i==n-1 && j==m-1)
// 		return 1;
// 	if(dp[i][j]!=-1)
// 		return dp[i][j];
// 	return dp[i][j]=(solve(i+1,j)+solve(i,j+1))%mod;
// }
void add_self(int &a,int b){
	a+=b;
	if(a>=mod)
		a-=mod;
}
int32_t main(){__
	//memset(dp,-1,sizeof dp);
	cin>>n>>m;
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			cin>>grid[i][j];
		}
	}
	dp[0][0]=1;
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			for(int r2:{i,i+1}){
				int c2=j;
				if(r2==i){
					c2++;
				}
				if(r2<n && c2<m && grid[i][j]=='.'){
					add_self(dp[r2][c2],dp[i][j]);
				}
			}
		}
	}
	cout<<dp[n-1][m-1]<<"\n";
return 0;
}

Measured memory_bytes: 5120
n=int(input())

#factor=[]
ans=0
for i in range(2,int(n**.5)+1):
	if n%i==0:
		cnt=1
		k=0
		while n%i==0:
			k+=1
			if cnt==k:
				ans+=1
				cnt+=1
				k=0
			#factor.append(i)
			n//=i

if n>1:
	#factor.append(n)
	ans+=1
print(ans)


Measured memory_bytes: 9264
const lines=readlines(open("/dev/fd/0"))
input()=shift!(lines)
int(s::String)=parse(Int32,s)
intSub(s::SubString{String})=parse(Int32,s)
intLine()=map(intSub,split(input()))
function main()
    h,w=intLine()
    s=Array(Int32,h,w)
    for i in 1:h
        t=input()
        for j in 1:w
            s[i,j]=t[j]>'#'
        end
    end
    a=copy(s)
    b=copy(s)
    c=copy(s)
    d=copy(s)
    for i in 1:h
        for j in 1:w
            if j>1
                a[i,j]=-~a[i,j-1]*s[i,j]
                b[i,w-j+1]=-~b[i,w-j+2]*s[i,w-j+1]
            end
            if i>1
                c[i,j]=-~c[i-1,j]*s[i,j]
                d[h-i+1,j]=-~d[h-i+2,j]*s[h-i+1,j]
            end
        end
    end
    print(maximum(a+b+c+d)-3)
end
main()

Measured memory_bytes: 242756
#include <bits/stdc++.h>
#define rep(i,cc,n) for(int i=cc;i<=n;++i)
#define drep(i,cc,n) for(int i=cc;i>=n;--i)
#define sz(s) (int)(s.size())
#define vecprint(v) rep(i,0,v.size()-1)cout << v[i] << " ";cout << endl;
#define arrprint(v,n) rep(i,0,n-1)cout << v[i] << " ";cout << endl;
#define matprint(v,n,m) rep(i,0,n-1){rep(j,0,m-1){cout << v[i][j] << " ";}cout << endl;}
using namespace std;
const int mod=1000000007;
const int INF=1001001001;
typedef long long ll;
typedef pair<int,int> P;

int main(){
    string s;
    cin >> s;
    int n = sz(s);
    int dp[n][2];
    ll ans = 0;
    dp[n-1][0] = (int)(s[n-1] - '0');
    dp[n-1][1] = 10 - (int)(s[n-1] - '0');
    // cout << dp[n-1][0] << " " << dp[n-1][1] << endl;
    drep(i,n-2,0){
        int keta = s[i] - '0';
        dp[i][0] = min(dp[i+1][0]+keta , dp[i+1][1]+keta+1);
        dp[i][1] = min(dp[i+1][0]+ 10 - keta , dp[i+1][1]+10 - (keta+1));
        // cout << dp[i][0] << " " << dp[i][1] << endl;
     }
    ans = min(dp[0][0],dp[0][1]+1);

    cout << ans << endl;
//  printf("%.10f\n",ans);

    return 0;
}

Measured memory_bytes: 9220
def main():
    H, W = map(int, input().split())
    n = H * W
    if H == 1:
        print(1)
    elif W == 1:
        print(1)
    elif n % 2 == 0:
        print(int(n / 2))
    else:
        print((n // 2) + 1)
    return 0


if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
#include <iostream>
#include <fstream>
#include <typeinfo>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <iomanip>
#include <cctype>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<25;
const double pi=acos(-1);
const double eps=1e-8;
const vi emp;

int d,c;

int main(){
	cin>>d>>c;
	cout<<d*c<<endl;
}

Measured memory_bytes: 1164
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
 
using namespace std;
 
typedef long long ll;
 
#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define per(i,a,b) for(ll i=(b-1);i>=(a);--i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define print(x) cout<<#x<<" = "<<x<<endl;
 
#define MOD 1000000007
 
ll d[210][210];
 
int main(){
	ll n;
	cin>>n;
	clr(d,-1);
	rep(i,0,40){
		string s;
		rep(j,0,200){
			s += "0";
		}
		rep(j,0,5){
			s[i+j*40] = '1';
		}
		cout << "?" << " " << s << endl;
		ll ans1;
		cin>>ans1;
		if(ans1==0){
			rep(j,0,5){
				rep(k,j+1,5){
					d[i+j*40][i+k*40] = 0;
				}
			}
		}
	}
	rep(i,0,n){
		rep(j,i+1,n){
			if(d[i][j]!=-1)continue;
			string s1;
			rep(l,0,n){
				if(l==i||l==j)s1+="1";
				else s1+="0";
			}
			cout << "?" << " " << s1 << endl;
			ll ans1;
			cin>>ans1;
			if(ans1==1){
				d[i][j] = 1;
			}
			else{
				d[i][j] = 0;
			}
		}
	}
	cout << "! ";
	vector<pair<ll,ll> > v;
	rep(i,0,200){
		rep(j,i+1,200){
			if(d[i][j] == 1){
				v.pb(mp(i,j));
			}
		}
	}
	rep(i,0,v.sz){
		cout << "(" << v[i].fi << "," << v[i].se << ")";
		if(i!=v.sz-1)cout << " ";
	}
	cout << endl;
	return 0;
}


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

#define REP(i, m, n) for (int i = (m); i < (int)(n); i++)
#define REPS(i, m, n) for (int i = (m); i <= (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define reps(i, n) for (int i = 0; i <= (int)(n); i++)
#define rrep(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define rreps(i, x) for (int i = (int)(x); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
typedef long long ll;
typedef pair<int, int> P;
const int inf = INT_MAX;
const ll INF = 1LL << 60;
const ll mod = 1e9 + 7;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val) { fill( (T*)array, (T*)(array+N), val ); }

const int MAX = 100010;
bool dp[110][MAX];
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);

    int N; cin >> N;
    vector<int> s(N); rep(i, N) cin >> s[i];
    dp[0][0] = true;
    rep(i, N) {
        rep(j, MAX) {
            if (!dp[i][j]) continue;
            dp[i+1][j] = dp[i][j];
            dp[i+1][j+s[i]] = dp[i][j];
        }
    }
    int res = 0;
    rep(i, MAX) if (i % 10 && dp[N][i]) res = max(res, i);

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

Measured memory_bytes: 8576
fn solve() {
    let s = std::io::stdin();
    let mut sc = Scanner { stdin: s.lock() };
    let S = sc.chars();
    let T = sc.chars();
    let mut cnt = 0;
    for (a, b) in S.iter().zip(T.iter()) {
        if a == b {
            cnt += 1;
        }
    }
    println!("{}", cnt);
}

fn main() {
    std::thread::Builder::new()
        .stack_size(64 * 1024 * 1024) // 64MB
        .spawn(|| solve())
        .unwrap()
        .join()
        .unwrap();
}

//snippet from kenkoooo
pub struct Scanner<R> {
    stdin: R,
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn read_line(&mut self) -> String {
        use std::io::Read;
        let buf = self
            .stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b'\n' || b == b'\r')
            .take_while(|&b| b != b'\n' && b != b'\r')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }

    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 8572
#include <bits/stdc++.h>
using namespace std;
//#define cerr if (false) cerr
#define db(x) cerr << #x << "=" << x << endl
#define db2(x, y) cerr << #x << "=" << x << "," << #y << "=" << y << endl
#define db3(x, y, z) cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z << endl
#define dbv(v) cerr << #v << "="; for (auto _x : v) cerr << _x << ", "; cerr << endl
#define dba(a, n) cerr << #a << "="; for (int _i = 0; _i < (n); ++_i) cerr << a[_i] << ", "; cerr << endl
template <typename A, typename B>
ostream& operator<<(ostream& os, const pair<A, B>& x) {
	return os << "(" << x.first << "," << x.second << ")";
}
typedef long long ll;
typedef long double ld;
int main() {
	int n, d;
	scanf("%d%d", &n, &d);
	int ans = 0;
	for (int i = 0; i < n; ++i) {
		int x, y;
		scanf("%d%d", &x, &y);
		if ((ll)x * x + (ll)y * y <= (ll)d * d) {
			++ans;
		}
	}
	printf("%d\n", ans);
}


Measured memory_bytes: 3800
import sys
readline = sys.stdin.readline

N = int(readline())

ans = [0] * (N + 1)

for x in range(1, int(N ** 0.5) + 1):
  for y in range(1, int(N ** 0.5) + 1):
    for z in range(1, int(N ** 0.5) + 1):
      val = x ** 2 + y ** 2 + z ** 2 + x * y + y * z + z * x
      if val <= N:
        ans[val] += 1
        
for i in range(1, len(ans)):
  print(ans[i])

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

using namespace std;

int main(){
    int n,k;
    cin>>n>>k;
    int zer=n/k,half=n/k;
    if(n%k>=k/2){
        half++;
    }
    if(k%2){
        cout<<1ll*zer*zer*zer<<endl;
    }
    else{
        cout<<1ll*zer*zer*zer+1ll*half*half*half<<endl;
    }
    return 0;
}

Measured memory_bytes: 3576
import fractions

A, B, C, D = map(int, input().split())


def lcm(a, b):
    return a // fractions.gcd(a, b) * b


nA = (A - 1) // C + (A - 1) // D - (A - 1) // lcm(C, D)
nA = A - 1 - nA
nB = B // C + B // D - B // lcm(C, D)
nB = B - nB
print(nB - nA)


Measured memory_bytes: 5176
import scala.io.StdIn
 
 
object Main extends App {
  val n  = StdIn.readLine().toInt
  val a  = StdIn.readLine().split(" ").map(_.toInt)
 
  def solve(a: Array[Int]): Int = {
 
    val b = a.scanLeft(0) {(acc, x) => gcd(acc, x)}
    val c = a.scanRight(0) {(acc, x) => gcd(acc, x)}
 
    val d = for (x <- 0 to a.length -1) yield {
      gcd(b(x), c(x + 1))
    }
    d.max
  }
 
  def gcd(x: Int, y: Int) :Int = {
    if (y == 0 ) x
    else gcd(y, (x % y))
  }
 
  println(solve(a))
 
}

Measured memory_bytes: 53100
N, M, C = list(map(int, input().split()))
B = [int(i) for i in input().split()]
A = [list(map(int, input().split())) for _ in range(N)]

count = 0

for a in A:
    c = sum([a[i]*B[i] for i in range(M)])
    if c+C > 0:
        count += 1
print(count)

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

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

    int N;
    cin >> N;
    vector<int> A(N);

    rep(i, N) cin >> A[i];

    int res = 0;
    while(true) {
        rep(i, N) {
            if (A[i] == 0 or A[i] % 2 != 0) {
                cout << res << "\n";
                return 0;
            }
            else
                A[i] /= 2;
        }
        ++res;
    }
}

Measured memory_bytes: 256
import java.io.*;
import java.util.List;
import java.util.ArrayList;

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

	public Main(){
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));

		List<String> lines = new ArrayList<String>();
		try{
			String line;
			while((line = in.readLine()) != null){
				lines.add(line);
			}
		}catch(IOException err){
			err.printStackTrace();
		}

		for(int i=0; i<lines.size(); i++){
			String[] nums = lines.get(i).split(" ");
			int a = Integer.parseInt(nums[0]);
			int b = Integer.parseInt(nums[1]);
			int num = a + b;

			int digit = 0;
			while(num != 0){
				num = num / 10;
				digit++;
			}

			System.out.println(digit);
		}
	}
}

Measured memory_bytes: 10000
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <algorithm>

#include <bits/stdc++.h>
#include <cmath>
#include <limits>

using namespace std;
typedef long long LL;

int main(int argc, char* argv[]){
	cin.tie(0);
	ios::sync_with_stdio(false);

	int N;
	map<string, int> mp;
	
	cin >> N;
	for(int i = 1; i <= N; i++){
		string s;
		cin >> s;
		if(mp.count(s) == 0){
			mp[s] = 1;
		}
		else{
			mp[s]++;
		}
	}
	int max = 0;
	for(auto itr = mp.begin(); itr != mp.end(); itr++){
		int c = itr->second;
		if(max < c){ max = c; }
	}
	vector<string> v;
	for(auto itr = mp.begin(); itr != mp.end(); itr++){
		string s = itr->first;
		int c = itr->second;
		if(c == max){
			v.push_back(s);
		}
	}
	sort(v.begin(), v.end());
	for(int i=0; i<v.size(); i++){
		printf("%s\n", v[i].c_str());
	}
	return 0;
}

Measured memory_bytes: 26096
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define bug(x) cerr<<#x<<"="<<x<<endl;
#define el printf("\n");
const ll mod = 1e7;




inline ll nxt() {
	ll x;
	scanf("%lld\n",&x);
	return x;
}
inline void print(int n){
    printf("%d ",n);
}


ll nCr(ll n ,ll k){
    if( k==n || k==0 )return 1;
    return (nCr(n-1,k-1)%mod+nCr(n-1,k)%mod)%mod;
}

int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);
    string s;
    cin>>s;
    if(s=="AAA"||s=="BBB")printf("No\n");
    else printf("Yes\n");



}


Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<string>
#include<cstring>
#include<algorithm>

using namespace std;

int main()
{
	char s[105];
	int a,b,ans,t;
	while(~scanf("%d %d",&a,&b))
	{
		ans=0;
		scanf("%s",s);
		t=strlen(s);
		if(s[a]=='-')
			ans++;
		for(int i=0;i<a;i++)
		{
			if(s[i]>='0' && s[i]<='9')
				ans++;
		}
		for(int i=a+1;i<t;i++)
		{
			if(s[i]>='0' && s[i]<='9')
				ans++;
		}
		if(ans==t)
			printf("Yes\n");
		else
			printf("No\n");
	}
	return 0;
}


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

#define REP(i, s, n) for (int i = s; i < n; ++i)
#define rep(i, n) REP(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define SORT_INV(c) sort((c).begin(), (c).end(), greater<int>())

#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG false
#define LL long long
#define Dev 1000000007

// sort(a.begin(), a.end(), std::greater<int>());
using namespace std;

int main()
{

    int n;
    cin >> n;
    double ans = 0;
    rep(i, n)
    {
        double x;
        string u;
        cin >> x >> u;
        if (u == "JPY")
            ans += x;
        else
        {
            ans += x * 380000;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <ctime>
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <memory.h>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <unordered_map>
#include <unordered_set>
using namespace std;
typedef long double LD;
typedef long long LL;
typedef pair<LL, LL> pll;
typedef pair<int, int> pii;
typedef vector<int> vi;
#ifdef LOCAL
#define DEBUG(x) { cerr << "# " << #x << ": " << x << endl;}
#else
#define DEBUG(x)
#endif
mt19937_64 mt(time(0));
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i
　　　　／　　　＼　 　  |　|
　　　 /　　 /￣￣￣￣/　　|
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿
　 　　　＼/＿＿＿＿/　（u　⊃
---------------------------------------------------------------------------------------------------*/
const int mod = 1e9 + 7;
const int MAXN = 2000 + 10;
const int MAXM = 700;
int dp[MAXN][MAXM];

int main() {
  ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  cout.precision(10); cout << fixed;
#ifdef LOCAL
  freopen("../test.txt", "r", stdin);
    // freopen("../output.txt", "w", stdout);
#endif
  dp[0][0] = 1;
  for (int j = 1; j < MAXM; j++) {
    LL sum = 0;
    for (int i = 0; i < MAXN; i++) {
      sum = (sum + dp[i][j-1]) % mod;
      dp[i][j] = sum;
    }
  }

  int sum; cin >> sum;
  LL ret = 0;
  for (int i = 1; sum - i*3 >= 0; i++) {
    ret = (ret + dp[sum-i*3][i]) % mod;
  }
  cout << ret << '\n';






/*---------------------------------------Coding Space End------------------------------------------*/
#ifdef LOCAL
  cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s." << endl;
#endif
  return 0;
}
/* author:  txingml */
/* picture is from hamayanhamayan(CF handle) */


Measured memory_bytes: 8720
#include<stdio.h>
#include<stdlib.h>

int main() {
	int n; long long int *(a);
	a = (long long int*)malloc(sizeof(long long int) * 200001);
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%d", &a[i]);
	}

	long long int max = a[0];
	long long int sum = 0;

	for (int i = 1; i < n; i++)
	{
		if (max > a[i]) sum += (long long int)(max - a[i]);
		else if (max < a[i]) max = a[i];
	}
	
	printf("%lld\n", sum);
	return 0;
}

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

//#define int long long
struct Fast {Fast(){std::cin.tie(0);ios::sync_with_stdio(false);}} fast;

/* cpp template {{{ */

/* short */
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define Fi first
#define Se second
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define X real()
#define Y imag()

/* REPmacro */
#define REPS(i, a, n) for (ll i = (a); i < (ll)(n); ++i)
#define rep(i, n) REPS(i, 0, n)
#define REP0(i,n) for (ll i = 0; i <= (ll)(n); ++i)
#define REP1(i,n) for (ll i = 1; i <= (ll)(n); ++i)
#define RREP(i, n) REPS(i, 1, n + 1)
#define DEPS(i, a, n) for (ll i = (a); i >= (ll)(n); --i)
#define DEP(i, n) DEPS(i, n, 0)
#define EACH(i, n) for (auto&& i : n)

/* debug */
#define debug(x) cerr << x << " " << "(L:" << __LINE__ << ")" << '\n';

/* alias */
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using pii = pair<int, int>;
using D = double;
using P = complex<D>;
using vs = vector<string>;
template <typename T> using PQ = priority_queue<T>;
template <typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

/* const */
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7;
const D EPS = 1e-9;
const int dx[] = {0, 1, 0, -1, 1, -1, 1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};

/* func */
inline bool inside(int y, int x, int H, int W) {return y >= 0 && x >= 0 && y < H && x < W;}
inline int in() {int x; cin >> x; return x;}
inline ll IN() {ll x; cin >> x; return x;}
inline vs split(const string& t, char c) {vs v; stringstream s(t); string b; while(getline(s, b, c)) v.eb(b); return v;}
template <typename T> inline bool chmin(T& a, const T& b) {if (a > b) a = b; return a > b;}
template <typename T> inline bool chmax(T& a, const T& b) {if (a < b) a = b; return a < b;}
template <typename T, typename S> inline void print(const pair<T, S>& p) {cout << p.first << " " << p.second << endl;}
template <typename T> inline void print(const T& x) {cout << x << '\n';}
template <typename T, typename S> inline void print(const vector<pair<T, S>>& v) {for (auto&& p : v) print(p);}
template <typename T> inline void print(const vector<T>& v, string s = " ") {rep(i, v.size()) cout << v[i] << (i != (ll)v.size() - 1 ? s : "\n");}
template<typename T>
istream& operator >> (istream& is, vector<T>& vec){
  for(T& x: vec) is >> x;
  //for(int i=0; i<vec.size(); i++) is >> x[i]; とかでもいいです。
  return is;
}
template<typename T>
ostream& operator << (ostream& os, vector<T>& vec){
  for(int i=0; i<vec.size(); i++){
    os << vec[i] << ( i+1 == vec.size() ? "" : " " );
  }
  return os;
}
/* }}} */
signed main() 
{
  int n=in();
  string s;
  cin>>s;
  int sum=0,x=0;
  rep(i,s.length())
  {
    if(s[i]=='I') sum++;
    if(s[i]=='D') sum--;
    x=max(sum,x);
  }
  print(x);

  return 0;
}

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

int main(void)
{
	int n, ans = 0;
	cin >> n;
	for(int i = 0; i < n; ++i) {
		int b;
		cin >> b;
		if (b % 2 == 0) {
			for (int j = 0; b % 2 == 0; ++j) {
			    ++ans;
			    b /= 2;
			}
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
   string s,s1,s2;
   cin>>s;
  s1="es";
  s2="s";
  if(s[s.length()-1]=='s') s.append(s1);
  else s.append(s2);
  cout<<s;
    return 0;
}

Measured memory_bytes: 3624
// aarsh01rsh@gmail.com
// Aarsh Sharma
#include<bits/stdc++.h>
using namespace std;

string to_string(string s) {
  return '"' + s + '"';
}
string to_string(char ch) {
  string s(1, ch);
  return '\'' + s + '\'';
}
string to_string(const char *s) {
  return to_string((string)s);
}
string to_string(bool b) {
  return (b ? "true" : "false");
}
template <typename A, typename B>
string to_string(pair<A, B> p) {
return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}

#ifndef ONLINE_JUDGE
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

#define f(i, x, n) for (int i = x; i < n; i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define F first
#define S second
#define pb push_back
#define endl "\n"
#define unique(v) v.erase(unique(v.begin(), v.end()), v.end());
#define fast_io() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)

typedef long long int ll;
#define int ll
typedef pair<ll, ll> pll;
typedef vector<vector<ll>> matrix;
typedef vector<ll> vll;

const ll mod = 1e9 + 7;
const ll inf = LLONG_MAX;
const ll N = 1e5 + 10;

int32_t main() {
  fast_io();

  int n; cin >> n;
  vector<double> a(n); f (i, 0, n) cin >> a[i];
  sort(all(a));
  double ans = a[0];
  f (i, 1, n) {
    ans = (ans+a[i])/2;
  }
  cout << ans;

  return 0;
}

Measured memory_bytes: 256
import copy
s=[]
i=0
n=int(input())
while i!=n:
    s.append(int(input()))
    i+=1
maxx=max(s)
g=s.count(maxx)
i=0
j=0

#print(g)
while i!=n:
    a = s[j]
    if maxx == a and g < 2:
        a=s[j]
        del s[j]
        print(max(s))
        s.append(a)
    else:
        print(maxx)
        j+=1

    i+=1

Measured memory_bytes: 13024
#include<bits/stdc++.h>
const int INF = 10000000;


int n,m;
int l = -INF;
int r = INF;
void input()
{
    std::cin>>n>>m;
    for(int i=0;i<m;i++)
    {
        int a,b;
        std::cin>>a>>b;
        l = std::max(l,a);
        r = std::min(r,b);
    }
}

int main(){
    input();
    std::cout << std::max(0, r - l + 1) << std::endl;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define rep(i, n) for(int i=0;i<(n);++i)
#define per(i, n) for(int i=(n)-1;i>=0;--i)
#define repa(i, n) for(int i=1;i<(n);++i)
#define foreach(i, n) for(auto &i:(n))
#define pii pair<int, int>
#define pll pair<long long, long long>
#define all(x) (x).begin(), (x).end()
#define bit(x) (1ll << (x))
const ll MOD = (ll)1e9+7;
const int INF = (ll)1e9+7;
const ll INFLL = (ll)1e18;
using namespace std;
template<class t>
using vvector = vector<vector<t>>;
template<class t>
using vvvector = vector<vector<vector<t>>>;
template<class t>
using priority_queuer = priority_queue<t, vector<t>, greater<t>>;
template<class t, class u> bool chmax(t &a, u b){if(a<b){a=b;return true;}return false;}
template<class t, class u> bool chmin(t &a, u b){if(a>b){a=b;return true;}return false;}

ll modpow(ll x, ll b){
	ll res = 1;
	while(b){
		if(b&1)res = res * x % MOD;
		x = x * x % MOD;
		b>>=1;
	}
	return res;
}

ll modinv(ll x){
	return modpow(x, MOD-2);
}

bool was_output = false;
template<class t>
void output(t a){
	if(was_output)cout << " ";
	cout << a;
	was_output = true;
}
void outendl(){
	was_output = false;
	cout << endl;
}


int main(){
	int n;
	cin >> n;
	int ans = 0;
	vector<int> pay({25, 10, 5, 1});
	foreach(i, pay){
		ans += n / i;
		n %= i;
	}

	cout << ans << endl;

	return 0;
}



Measured memory_bytes: 3088
#include <stdio.h>
#include <stdlib.h>

int binary_search(long long *list, int s_ind, int e_ind, long long search_val)
{
	if (s_ind >= e_ind) {
		return list[s_ind] == search_val ? s_ind : -1;
	}

	int mid_ind = s_ind + ((e_ind - s_ind) / 2);

	if (list[mid_ind] < search_val) {
		return binary_search(list, mid_ind+1, e_ind, search_val);
	}
	else if (list[mid_ind] > search_val) {
		return binary_search(list, s_ind, mid_ind-1, search_val);
	}
	else {
		return mid_ind;
	}
}

int main(int argc, char *argv[])
{
	int i, n, q, cnt;
	long long S[100000];
	scanf("%d", &n);
	for (i = 0; i < n; i++) {
		long long num;
		scanf("%lld", &num);
		S[i] = num;
	}

	cnt = 0;
	scanf("%d", &q);
	for (i = 0; i < q; i++) {
		long long num;
		scanf("%lld", &num);
		if (binary_search(S, 0, n - 1, num) > -1) {
			++cnt;
		}
	}

	printf("%d\n", cnt);
	return 0;
}

Measured memory_bytes: 1380
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
using namespace std;

int main() {
    for (;;) {
        int n, a[100000];
        int ave = 0;
        cin >> n;
        if (0 == n) {
            break;
        }
        for (int i = 0; i < n; ++i) {
            cin >> a[i];
            ave += a[i];
        }
        ave /= n;
        int under = 0;
        for (int i = 0; i < n; ++i) {
            if (a[i] <= ave) {
                ++under;
            }
        }
        cout << under << endl;
    }
    return 0;
}



Measured memory_bytes: 3124
S = input()
AS = S[:2]
BS = S[2:]
if 1<=int(AS)<=12 and 1<=int(BS)<=12:
    print('AMBIGUOUS')
elif 1<=int(AS)<=12:
    print('MMYY')
elif 1<=int(BS)<=12:
    print('YYMM')
else:
    print('NA')

Measured memory_bytes: 9176
import java.util.*;
import java.lang.*;

public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        if (N%2 == 0) {
            System.out.println(N);
        }else{
            System.out.println(N*2);
        }
    }
}

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

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

  vector<bool> vecall(M, true);
  vector<bool> vec(M, false);

  for (int i = 0; i < N; i++)
  {
    int K; cin >> K;
    for (int j = 0; j < K; j++)
    {
      int A; cin >> A; A--;
      vec[A] = true;
    }
    for (int j = 0; j < M; j++)
    {
      vecall[j] = vecall[j] and vec[j];
      vec[j] = false;
    }
  }

  int count = 0;
  for (int i = 0; i < M; i++)
  {
    if (vecall[i]) count++;
  }

  cout << count << endl;
}


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

#define DEBUG(x) cerr << #x << ": " << x << endl;
#define ll long long

int main() {
    int n, k, x, y;
    cin >> n >> k >> x >> y;
    int sum = 0;

    if (n < k) {
        sum += x * n;
    } else {
        sum += x * k;
    }

    if (n > k) {
        sum += y * (n-k);
    } else {
        sum += 0;
    }

    cout << sum << endl;

    return 0;
}

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

int m,n,f[55][55];
string s1,s2;

int main()
{
    cin>>s1;
    s1=' '+s1;
    s2=" AKIHABARA";
    int m=s1.size()-1;
    int n=s2.size()-1;
    for(int i=1;i<=m;i++)
        for(int j=1;j<=n;j++)
            if(s1[i]==s2[j])
                f[i][j]=f[i-1][j-1]+1;
            else
                f[i][j]=max(f[i-1][j],f[i][j-1]);
    if(f[m][n]==m)
    {
        string ss="";
        for(int i=1;i<=m;i++)
            if(s1[i]!='A')
                ss+=s1[i];
        if(ss=="KIHBR")
            cout<<"YES";
        else
            cout<<"NO";
    }
    else
        cout<<"NO";
}


Measured memory_bytes: 256
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>

#include <iostream>
#include <string>

#include <algorithm>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <vector>

#define PB push_back
#define MP make_pair

#define FOR(i, b, e) for(int i=(b);i<(e);i++)
#define REP(i, n) FOR(i,0,n)

#define ALL(v) (v).begin(),(v).end()

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;

typedef pair<int, int> PII;

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<PII> VPII;

const int MOD = 1000000007;
const int INF = 1e9;

const double EPS = 1e-9;
const double PI = acos(-1.0);

const int DX[4] = {1, 0, -1, 0};
const int DY[4] = {0, 1, 0, -1};

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

int L[] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};

int K;

int main() {
    cin >> K;
    cout << L[K - 1] << endl;
    return 0;
}

Measured memory_bytes: 256
///https://agc020.contest.atcoder.jp/tasks/agc020_c?lang=en
///http://petr-mitrichev.blogspot.com/2018/01/
#include<bits/stdc++.h>
#define i64 long long
#define inf 1000000000000000000
using namespace std;

int ara[2001];
bitset<2001*2001>bset;//[2];
int main()
{
    int n;
    scanf("%d",&n);

    int sum=0,mx=0;
    for(int i=1; i<=n; i++)
        scanf("%d",&ara[i]);


  //  sort(ara+1,ara+n+1);

    for(int i=1; i<=n; i++)
    {
        sum+=ara[i];
        mx=max(mx,ara[i]);
    }

    int avg=(sum+2-1)/2, last=mx*n;

    bset[0]=1;
    for(int i=1; i<=n; i++)
        bset= bset | (bset<<ara[i]);


    for(int i=avg; i<=last; i++)
    {
        if(bset[i]==1)
        {
            printf("%d\n",i);
            return 0;
        }
    }


    return 0;
}


Measured memory_bytes: 2176
#include <iostream>
#include <vector>
#include <set>
#include <string>
#include <algorithm>
typedef long long ll;
using namespace std;

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


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

using namespace std;
using llong = long long;
using ldbl = long double;
using P = pair<llong, llong>;

#define ALL(x) x.begin(), x.end()

const llong inf = llong(1e18)+7;
const llong mod = 1e9+7;

llong GCD(llong a, llong b){
	a = abs(a), b = abs(b);
	if(a < b) swap(a, b);
	if(b == 0) return a;
	while(b){
		a %= b;
		swap(a,b);
	}

	return a;
}

llong LCM(llong a, llong b){
	return a / GCD(a, b) * b;
}

int main(){
	llong W, H, C;
	cin >> W >> H >> C;
	llong l = GCD(W,H);
	cout << W/l*H/l*C << endl;

	return 0;
}


Measured memory_bytes: 3096
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from itertools import permutations, accumulate, combinations, combinations_with_replacement
from math import sqrt, ceil, floor, factorial
from bisect import bisect_left, bisect_right, insort_left, insort_right
from copy import deepcopy
from operator import itemgetter
from functools import reduce
from fractions import gcd
import sys
def input(): return sys.stdin.readline().rstrip()
def I(): return int(input())
def Is(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def TI(): return tuple(map(int, input().split()))
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def TIR(n): return [TI() for _ in range(n)]
def S(): return input()
def Ss(): return input().split()
def LS(): return list(input())
def SR(n): return [S() for _ in range(n)]
def SsR(n): return [Ss() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
sys.setrecursionlimit(10**6)
MOD = 10**9+7
INF = float('inf')
# ----------------------------------------------------------- #

n, k = Is()
A = LI()
A = [-1] + A
# print(A)

B = [1]
visited = {1}
loopstart = -1
def dfs(num):
    global loopstart
    tmp = A[num]
    if tmp in visited:
        loopstart = tmp
    else:
        B.append(tmp)
        visited.add(tmp)
        dfs(tmp)

dfs(1)
# print(loopstart)
# print(B)
# print(visited)

C = []
for i in range(len(B)):
    if B[i] == loopstart:
        C = B[i:]
# print(C)
lb = len(B)
lc = len(C)
if k < lb:
    print(B[k])
else:
    print(C[(k-lb) % lc])


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

int main() {
  int a,b;
  cin >> a >> b;
  int ans =0;
  while (a<=b){
    string s ;
    s = to_string(a);
    if(s.at(0)==s.at(4)){
       if(s.at(1)==s.at(3)){
          ans ++ ;
       }
    }
    a++;
  }
  cout <<ans ;
}


Measured memory_bytes: 256
package main

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

var debug = false

var sc = bufio.NewScanner(os.Stdin)

func main() {
	var n int
	if sc.Scan() {
		n, _ = strconv.Atoi(sc.Text())
	}
	var targets []string
	for i := 0; i < n; i++ {
		if sc.Scan() {
			targets = append(targets, sc.Text())
		}
	}

	res := GetAnswer(n, targets)
	fmt.Printf("%v\n", res)
}

// GetAnswer ...
func GetAnswer(n int, targets []string) string {
	prt("inputs: n:%v targets:%#v", n, targets)
	result := "Yes"

	targetArray := [][]int{}
	targetArray = append(targetArray, []int{0, 0, 0})
	for _, t := range targets {
		arr := getIntArray(t)
		targetArray = append(targetArray, arr)
	}
	prt("targetArr: %v", targetArray)

	for i := 0; i < n; i++ {
		pos := math.Abs(float64(targetArray[i+1][1]-targetArray[i][1])) + math.Abs(float64(targetArray[i+1][2]-targetArray[i][2]))
		ntime := targetArray[i+1][0] - targetArray[i][0]
		prt("pos: %d, ntime:%d", int(pos), ntime)
		if int(pos) > ntime {
			result = "No"
			break
		}
		if int(pos)%2 != ntime%2 {
			result = "No"
			break
		}
	}

	return result
}

func getIntArray(str string) []int {
	strarr := strings.Split(str, " ")
	intarr := []int{}
	for _, st := range strarr {
		ti, _ := strconv.Atoi(st)
		intarr = append(intarr, ti)
	}
	return intarr
}

func prt(format string, inputs ...interface{}) {
	if debug {
		fmt.Printf(format+"\n", inputs...)
	}
}

Measured memory_bytes: 18688
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=205,mod=1e9+7;
ll ans,f[N],invf[N];
ll C(int n,int m)
{
    return f[n]*invf[n-m]%mod*invf[m]%mod;
}
int n,k,tot,cnt,pos[N],l[N],p[N],vv[N];
char s[N];
bool vis[N];
bool check()
{
    memset(vis,false,sizeof(vis[0])*(k+3));
    memset(vv,0,sizeof(vv[0])*(k+3));
    if(cnt>tot) return false;
    int j=1;
    for(int i=cnt;i>=1;i--)
    {
        int x=pos[j++];
        vis[x]=true;
        if(l[i]>=2)
        {
            if(!p[x]) return false;
            vis[p[x]]=true;
            vv[p[x]]=i;
        }
        else vv[x]=i;
    }
    int sum=0;
    for(int i=k;i>=1;i--)
        if(!vis[i]) sum++;
        else if(vv[i])
        {
            int x=max(0,l[vv[i]]-2);
            if(sum<x) return false;
            sum-=x;
        }
    return true;
}
bool dfs(int mn,int dep,int len)
{
    cnt=dep;
    if(!check()) return false;
    int s=dep+1;
    for(int i=1;i<=dep;i++)
        if(l[i]==1) s++;
    else s+=2*(l[i]-1)-1+2;
    ll res=C(n-len+s-1,s-1)*f[dep]%mod;
    int t=1;
    for(int i=2;i<=dep;i++)
        if(l[i]!=l[i-1]) res=res*invf[t]%mod,t=1;
    else t++;
    res=res*invf[t]%mod;
    ans=(ans+res)%mod;
    if(dep+1>tot) return true;
    for(int i=mn;i<=k;i++)
    {
        int nlen=len;
        if(dep!=0) nlen++;
        if(i<=2) nlen++;
        else nlen+=2*(i-1)-1;
        if(nlen>n) break;
        l[dep+1]=i;
        if(!dfs(i,dep+1,nlen)) break;
    }
    return true;
}
int main()
{
    f[0]=invf[0]=f[1]=invf[1]=1;
    for(int i=2;i<N;i++) f[i]=f[i-1]*i%mod,invf[i]=(mod-mod/i)*invf[mod%i]%mod;
    for(int i=2;i<N;i++) invf[i]=invf[i-1]*invf[i]%mod;
    scanf("%d%d",&n,&k);
    scanf("%s",s+1);
    for(int i=1;i<=k;i++)
        if(s[i]=='r')
    {
        pos[++tot]=i;
        for(int j=i+1;j<=k;j++)
            if(!vis[j]&&s[j]=='b')
        {
            p[i]=j;vis[j]=true;break;
        }
    }
    dfs(1,0,0);
    printf("%lld\n",ans);
}


Measured memory_bytes: 256
#include <stdio.h>

int main() {
    int N;
    scanf ("%d", &N);
    int p[N+1], q[N+1];
    int index, countMismatch = 0;

    for (index = 1; index <= N; index++) {
        scanf ("%d", &p[index]);
        q[index] = index;

        if (p[index] != q[index])
            countMismatch++;
    }

    if (countMismatch<=2)
        printf ("YES\n");
    else
        printf ("NO\n");

    return 0;
}


Measured memory_bytes: 128
#include <stdio.h>
#include <string.h>
int main(void){
  int bng[3][3];
  int ans[3][3];

  for(int i=0;i<3;i++){
    for(int j=0;j<3;j++){
      scanf("%d",&bng[i][j]);
      ans[i][j]=0;
    }
  }
  int n,b,x;
  scanf("%d",&n);
  for(x=0;x<n;x++){
    scanf("%d",&b);
    for(int i=0;i<3;i++){
     for(int j=0;j<3;j++){
      if(bng[i][j]==b){
        ans[i][j]=1;
      }
     }
   }
  }
  int w=0;
  if(ans[0][0]+ans[0][1]+ans[0][2]==3)
    w=1;
  if(ans[1][0]+ans[1][1]+ans[1][2]==3)
  w=1;
  if(ans[2][0]+ans[2][1]+ans[2][2]==3)
  w=1;
  if(ans[0][0]+ans[1][0]+ans[2][0]==3)
  w=1;
  if(ans[0][1]+ans[1][1]+ans[2][1]==3)
  w=1;
  if(ans[0][2]+ans[1][2]+ans[2][2]==3)
  w=1;
  if(ans[0][0]+ans[1][1]+ans[2][2]==3)
  w=1;
  if(ans[0][2]+ans[1][1]+ans[2][0]==3)
  w=1;

  if(w==1){
    printf("Yes\n");
  }else{
    printf("No");
  }
  return 0;
}

Measured memory_bytes: 1728
#include <string.h>
#include <iostream>

using namespace std;

int main()
{
	const int MAX_NO  = 9;
	const int MAX_NOS = 9;
	const int MAX_SUM = 100;

	int n[50], s[50], c = 0, dp[MAX_NOS + 1][MAX_NO + 1][MAX_SUM + 1];

	long long SUM = 0;

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

	for (int i = 0; i < MAX_NO; i++)
	{
		dp[1][i][i] = 1;
	}

	for (int N = 2; N <= MAX_NOS; N++)
	{
		for (int i = 1; i <= MAX_NO; i++)
		{
			for (int j = 1; j <= MAX_SUM; j++)
			{
				if (j - i >= 0)
				{
					for (int k = 0; k < i; k++)
					{
						dp[N][i][j] += dp[N - 1][k][j - i];
					}
				}
			}
		}
	}

	while (true)
	{
		cin >> n[c] >> s[c];

		if (n[c] == 0 && s[c] == 0) { goto Exit; }

		c++;
	}

Exit:;

	for (int p = 0; p < c; p++)
	{
		SUM = 0;

		for (int i = 0; i <= MAX_NO; i++)
		{
			SUM += dp[n[p]][i][s[p]];
		}

		cout << SUM << endl;
	}

	return 0;
}

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

int main(){
  int N;
  string S;
  cin >> N; 
  cin >> S;
  for(int i=0; i<S.size(); i++){
    if(S[i]+N > (int)'Z'){
      int n = N;
      n = n- ('Z'-S[i]);
      S[i] = (char)('A'-1+n);
    }else
      S[i] =(char)S[i]+N;
  }
  for(int i=0; i<S.size(); i++){
    cout << S[i];
  }
  cout << endl;
  return 0;
}

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

using namespace std;

#define int long long
#define rep(i,n) for(int i = 0; i < (n); i++)
#define INF ((long long)1e18)
#define MOD ((int)1e9+7)
#define endl "\n"

#define yn(f) ((f)?"Yes":"No")
#define YN(f) ((f)?"YES":"NO")

#define MAX 11000


int dp[MAX];



signed main(){
	// cin.tie(0);
	// ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);

	int hoge[10] = {INF,2,5,5,4,5,6,3,7,6};
	int N, M, n;
	vector<int> A;
	int nd, a;

	
	cin>>N>>M;
	
	n = N;
	
	for(int i = 0; i < M; i++){
		cin>>a;
		A.push_back(a);
	}
	sort(A.begin(),A.end());
	
	dp[0] = 0;
	
	for(int i = 1; i <= N; i++){
		dp[i] = -INF;
		for(int j = 0; j < A.size(); j++){
			if(hoge[A[j]] > i) continue;
			dp[i] = max(dp[i-hoge[A[j]]]+1,dp[i]);
		}
	}
	
	for(int i = N; i;){
		int num = -1;
		for(int j = 0; j < A.size(); j++){
			if(i-hoge[A[j]] < 0 ) continue;
			if(dp[i-hoge[A[j]]] == dp[i]-1)num = j;
		}
		i -= hoge[A[num]];
		cout<<A[num];
	}
	cout<<endl;
	
	return 0;
}

Measured memory_bytes: 384
n,a,b=map(int,input().split())
s=list(input())
nover=0
tot=0
for i in range(n):
    if tot<a+b:
        if s[i]=='a':
            print('Yes')
            tot+=1
        elif s[i]=='b' and nover<b:
            print('Yes')
            nover+=1
            tot+=1
        else:
            print('No')
    else:
        print('No')


Measured memory_bytes: 53880
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf = 10**9

s = input()
f = [False] * 4
for c in s:
    if c == 'N':
        f[0] = True
    elif c == 'S':
        f[1] = True
    elif c == 'W':
        f[2] = True
    else:
        f[3] = True
if f[0] == f[1] and f[2] == f[3]:
    print("Yes")
else:
    print("No")


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

int main()
{
	char zero = '0';
	char ABCD[5];
	int a, b, c, d;
	int iSign[24] = {1,1,1,1,-1,1,1,-1,-1,1,1,-1,-1,1,1,-1,-1,1,-1,-1,-1,-1,1,-1};
	char cSign[24] = {'+','+','+','+','-','+','+','-','-','+','+','-','-','+','+','-','-','+','-','-','-','-','+','-'};
	int* pi = iSign;
	char* pc = cSign;

	cin >> ABCD;
	a = ABCD[0] - zero;
	b = ABCD[1] - zero;
	c = ABCD[2] - zero;
	d = ABCD[3] - zero;

	for (int i=0;i<24;i+=3) {
		if (a+b*(*(pi+i))+c*(*(pi+i+1))+d*(*(pi+i+2))==7) {
			cout << ABCD[0] << *(pc+i) << ABCD[1] << *(pc + i + 1) <<ABCD[2] << *(pc + i + 2) << ABCD[3] << "=7";
			return 0;
		}
	}
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
#define ALL(x) (x).begin(), (x).end()
const long long INF = 1e18;
using namespace std;
typedef long long ll;
int main() {
  string S;
  cin >> S;

  ll N = S.length();

  ll ans[N];
  REP(i, N) ans[i] = 0;

  bool back = false;
  ll odd = 0, even = 0;

  REP(i, N) {
    ll prev_i;

    if (!back) {
      if (S[i] == 'L') {
        back = true;
        prev_i = i;
        if (i % 2 == 0) {
          ans[i] += even + 1;
          ans[i - 1] += odd;
        } else {
          ans[i] += odd + 1;
          ans[i - 1] += even;
        }
        even = 0, odd = 0;
      } else {
        if (i % 2 == 0) {
          even++;
        } else {
          odd++;
        }
      }
    } else {
      if (S[i] == 'L') {
        if ((i - prev_i) % 2 == 0) {
          ans[prev_i]++;
        } else {
          ans[prev_i - 1]++;
        }
      } else {
        back = false;
        if (i % 2 == 0) {
          even++;
        } else {
          odd++;
        }
      }
    }
  }
  REP(i, N) cout << ans[i] << " ";
  return 0;
}

Measured memory_bytes: 1408
#include <iostream>

using namespace std;

int main(void) {
	int N;
	cin >> N;
	int num;
	int count = 0;
	for (int i = 0; i < N; ++i) {
		cin >> num;
		if (num != i+1) {
			++count;
		}
	}
	if (count > 2) {
		cout << "NO" << endl;
	}
	else {
		cout << "YES" << endl;
	}
	return 0;
}



Measured memory_bytes: 256