akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(),v.end()
#define _GLIBCXX_DEBUG

using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vd = vector<double>;
using vvi = vector<vi>;
using vvll = vector<vll>;
using vvd = vector<vd>;
using vvvi = vector<vvi>;
using vvvll = vector<vvll>;
using vvvd = vector<vvd>;

const double pi=3.141592653589793;

int main() {
    ll n;
    cin>>n;
    ll a[n];
    rep(i,n){
        cin>>a[i];
    }
    ll s=a[0],num=a[0],l=0,r=0;
    int b=1;//b=1の時rを増やす
    ll ans=1;
    while (r<n-1 || b==0 ){
        if (b==1){
            r+=1;
            num=num^a[r];
            s+=a[r];
            if (s==num){
                ans+=r-l+1;
            }
            else{
                b=0;
            }
        }
        else{
            num=num^a[l];
            s-=a[l];
            l+=1;
            if (s==num){
                ans+=r-l+1;
                b=1;
            }
        }
    }
    cout<<ans<<endl;

    return 0;
}

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

using namespace std;
typedef long long ll;

const ll MOD = 998244353;

class mint{
    ll n;
public:
    mint(ll m = 0){
        n = ((m % MOD) + MOD) % MOD;
    }
    mint operator-() const {
        return mint(-n);
    }
    mint& operator+=(const mint& m){
        n += m.n;
        if(n >= MOD) n -= MOD;
        return *this;
    }
    mint& operator-=(const mint& m){
        n += MOD - m.n;
        if(n >= MOD) n -= MOD;
        return *this;
    }
    mint& operator*=(const  mint& m){
        n *= m.n;
        n %= MOD;
        return *this;
    }
    mint operator+(const mint& m) const{
        mint res(*this);
        res += m;
        return res;
    }
    mint operator-(const mint& m) const{
        mint res(*this);
        res -= m;
        return res;
    }
    mint operator*(const mint& m) const{
        mint res(*this);
        res *= m;
        return res;
    }
    mint pow(ll t) const{
        if(t == 0) return mint(1);
        mint m = pow(t>>1);
        m *= m;
        if(t & 1 == 1) m *= *this;
        return m;
    }
    // for prime modulo
    mint inv() const{
        return pow(MOD-2);
    }
    mint& operator/=(const mint& m){
        (*this) *= m.inv();
        n %= MOD;
        return *this;
    }
    mint operator/(const mint& m) const{
        mint res(*this);
        res /= m;
        return res;
    }
    friend ostream& operator<<(ostream& os, const mint& m){
        os << m.n;
        return os;
    }
};

ll N,M,K;
mint fact[200010];
mint fact_inv[200010];
mint mpow[200010];

mint comb(ll a,ll b){
    return fact[a] * fact_inv[b] * fact_inv[a-b];
}

int main(){
    cin >> N >> M >> K;
    fact[0] = mint(1);
    mpow[0] = mint(1);
    for(int i=1;i<=N;i++){
        fact[i] = fact[i-1] * mint(i);
        mpow[i] = mpow[i-1] * mint(M-1);
    }
    for(int i=0;i<=N;i++) fact_inv[i] = fact[i].inv();
    mint ans = mint(0);
    for(int i=0;i<=K;i++){
        ans += comb(N-1, i) * mint(M) * mpow[N - (i+1)];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 8344
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <vector>

#define rep(i, x, n) for(int i = x; i < n; i++)
using namespace std;
const long long INF = 1LL << 60;

long long GCD(long long a, long long b) {
    if(b == 0)
        return a;
    else
        return GCD(b, a % b);
}
long long LCM(long long a, long long b) {
    long long g = GCD(a, b);
    return a / g * b;
}
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}
int main() {
    int H, W;
    cin >> H >> W;
    vector<string> S(H);
    rep(i, 0, H) { cin >> S[i]; }
    bool ok = true;
    rep(i, 0, H) {
        rep(j, 0, W) {
            if(S[i][j] == '#') {
                bool t = false;
                if(i != 0) {
                    if(S[i - 1][j] == '#') {
                        t = true;
                    }
                }
                if(i != H - 1) {
                    if(S[i + 1][j] == '#') {
                        t = true;
                    }
                }
                if(j != 0) {
                    if(S[i][j - 1] == '#') {
                        t = true;
                    }
                }
                if(j != W - 1) {
                    if(S[i][j + 1] == '#') {
                        t = true;
                    }
                }
                if(!t) {
                    ok = false;
                    break;
                }
            }
        }
    }
    if(ok) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 256
fun main(args: Array<String>) {
    val (n, k) = readLine()?.split(" ")?.map(String::toInt) ?: return
    val (r, s, p) = readLine()?.split(" ")?.map(String::toInt) ?: return
    val tList = readLine() ?: return

    fun rps(
        tList: String,
        winT: Char,
        evenT: Char,
        index: Int,
        k: Int,
        win: Int,
        history: MutableList<Char>
    ) =
        if (index < k) {
            history.add(winT)
            win
        } else {
            val h = history[index - k]
            when {
                h != winT -> {
                    history.add(winT)
                    win
                }
                h == tList[index - k] -> {
                    history.add(winT)
                    win
                }
                else -> {
                    history.add(evenT)
                    0
                }
            }
        }

    var total = 0L
    val history = mutableListOf<Char>()
    tList.forEachIndexed { i, t ->
        when (t) {
            'r' -> {
                total += rps(tList, 'p', 'r', i, k, p, history)
            }
            's' -> {
                total += rps(tList, 'r', 's', i, k, r, history)
            }
            'p' -> {
                total += rps(tList, 's', 'p', i, k, s, history)
            }
        }
    }
    println(total)
}

Measured memory_bytes: 42004
#include <iostream>
#include <iomanip>
#include <cmath>
#include <vector>
#include <queue>
#include <limits>
#include <algorithm>
#include <string>
using namespace std;

static int64_t P = 1000000007;
static vector<int64_t> _power, _inverse;

static int64_t nCr(int64_t n, int64_t r)
{
	int64_t result = _power[n];
	result *= _inverse[r];
	result %= P;
	result *= _inverse[n - r];
	result %= P;
	return result;
}

int main()
{
	int64_t H, W, A, B;
	cin >> H >> W >> A >> B;

	_power.resize(H + W);
	_power[0] = 1;
	for (int64_t i = 1; i < H + W; i++) {
		_power[i] = _power[i - 1] * i;
		_power[i] %= P;
	}

	_inverse.resize(H + W);
	for (int32_t i = 0; i < H + W; i++) {
		_inverse[i] = 1;
		int64_t value = 1;
		for (int32_t j = 0; j < 32; j++) {
			if (j == 0)
				value = _power[i];
			else
				value *= value;
			value %= P;

			if ((P - 2) & (1 << j)) {
				_inverse[i] *= value;
				_inverse[i] %= P;
			}
		}
	}

	int64_t res = 0;
	for (int32_t i = B; i < W; i++) {
		int64_t x, y;

		x = i;
		y = H - A - 1;
		int64_t comb0 = nCr(x + y, x);

		x = W - 1 - i;
		y = H - 1 - (H - A);
		int64_t comb1 = nCr(x + y, x);

		res += comb0 * comb1;
		res %= P;
	}

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

Measured memory_bytes: 3328
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define rep(i,m,n) for(int i=(int)(m);i<(int)(n);++i)
#define rREP(i,m,n) for(int (i)=(n)-1; (i)>=(m);--(i))
#define all(x) (x).begin(),(x).end()
#define out(y,x,h,w) (y)<0||(x)<0||(y)>=(h)||(x)>=(w)
constexpr int INF = 1000000001;
constexpr ll mod = 1000000007;
constexpr double PI = 3.1415926535897932;

template<class T>inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
template<class T>inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
inline void init() {
	cin.tie(nullptr); cout.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

int main() {
	init();
	
	string s; cin >> s;
	int a = INF, z = 0;
	rep(i, 0, s.size()) {
		if (s[i] == 'A')chmin(a, i);
		if (s[i] == 'Z')chmax(z, i);
	}
	cout << z - a + 1 << "\n";

	return 0;
}

Measured memory_bytes: 720
import java.util.Scanner;
import java.util.Stack;

/**
 * Created by codoge on 2017/6/11.
 */
public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        scanner.nextLine();
        String s = scanner.nextLine();
        char[] ch = s.toCharArray();
        Stack<Integer> left = new Stack<>();
        Stack<Integer> right = new Stack<>();
        for (int i = 0; i < n; i++) {
            if (ch[i] == '(') {
                left.push(i);
            } else {
                if (!left.isEmpty())
                    left.pop();
                else
                    right.push(i);
            }
        }
        String ret = "";
        for (int j = 0; j < right.size(); j++)
            ret += '(';
        ret += s;
        for (int j = 0; j < left.size(); j++)
            ret += ')';
        System.out.println(ret);
    }
}


Measured memory_bytes: 25556
#include <stdio.h>

int main(void)
{
    int x, n, p[100];
    int i;
    int u, d;
    int f;
    scanf("%d %d", &x, &n);
    if (n == 0) {
        printf("%d\n", x);
        return 0;
    }
    for (i = 0; i < n; i++) {
        scanf("%d", &(p[i]));
    }
    u = x;
    do {
        f = 0;
        for (i = 0; i < n; i++) {
            if (p[i] == u) {
                f = 1;
                break;
            }
        }
        if (f == 1) {
            u++;
        }
    } while (f == 1);
    d = x;
    do {
        f = 0;
        for (i = 0; i < n; i++) {
            if (p[i] == d) {
                f = 1;
                break;
            }
        }
        if (f == 1) {
            d--;
        }
    } while (f == 1);
    if ((u - x) < (x - d)) {
        printf("%d\n", u);
    } else {
        printf("%d\n", d);
    }
    return 0;
}

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

int n;
int a[300100],sum[25][300100];

int check(int l,int r)
{
	for (int j=0;j<20;j++)
		if (sum[j][r]-sum[j][l-1]>1) return 0;
	return 1;
}

int find(int L,int R)
{
	int l=L,r=R,mid,ans;
	while (l<=r)
	{
		mid=(l+r)>>1;
		if (check(L,mid)) ans=mid,l=mid+1;
		else r=mid-1; 
	}
	return ans;
}

long long ans=0;
int main()
{
	scanf("%d",&n);
	for (int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
		for (int j=0;j<20;j++)
			if (a[i]&(1<<j))
				sum[j][i]=sum[j][i-1]+1; else sum[j][i]=sum[j][i-1];
	}
	
	for (int i=1;i<=n;i++)
	{
		int tmp=find(i,n);
		ans+=tmp-i+1;
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 25088
#include<bits/stdc++.h>
using namespace std;
const long long maxn=1e10+5;
int main(){
	int n,sum=0;
	cin>>n;
	int min=maxn;
	for(int i=1;i<=n;i++){
		int x;
		cin>>x;
		if(x<=min){
		sum++;
		min=x;}
	}
	cout<<sum;
	
	
	
	
	return 0;
}

Measured memory_bytes: 256
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

using namespace std;
typedef long long ll;

//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
//xにはvectorなどのコンテナ
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
#define D()
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 10000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素

int main(){
	ll a;
	cin >> a;
	ll x,y=a/3,z=a/5,w=a/15;
	x=((pow(a,2)+a)/2)-((pow(y,2)+y)/2)*3-((pow(z,2)+z)/2)*5+((pow(w,2)+w)/2)*15;

	cout << x << endl;

}



Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> PAIR;
const int N = 1e3+5;
const int INF = 0x3f3f3f3f;

inline void bfs(int n){
	int cnt = 0;
	priority_queue <ll,vector<ll>,greater<ll> > q;
	for(int i = 1;i <= 9;++i) q.push(i);
	
	while(!q.empty()){
		ll now = q.top();q.pop();
		cnt++;
		if(cnt == n){
			printf("%lld\n",now);
			return ;
		}
		
		ll temp = now%10;
		if(temp-1ll >= 0ll) q.push(now*10ll+temp-1ll);
		if(temp >= 0) q.push(now*10ll+temp);
		if(temp+1ll <= 9ll) q.push(now*10ll+temp+1ll);
	}
	return ;
}

int main(){
	int n;
	scanf("%d",&n);
	bfs(n);
    return 0;
}

Measured memory_bytes: 2420
/* cerberus97 - Hanit Banga */

#include <iostream>
#include <iomanip>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>

using namespace std;

#define pb push_back
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL)

typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;

const int N = 1e5 + 10;

int main() {
	fast_cin();
	int a, b, c;
	cin >> a >> b >> c;
	if (a == b and b == c) {
		cout << "Yes\n";
	} else {
		cout << "No\n";
	}
}

Measured memory_bytes: 256
/*
g++ -std=c++11 -Wall -O2 -o main.exe main.cpp
./main.exe
*/

#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <climits>
//intの最大値: INT_MAX
//longの最大値: LONG_MAX
//long longの最大値: LLONG_MAX
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <vector>
#include <map>
#include <functional>
#include <algorithm>
#include <complex>
#include <numeric>
#include <queue>
#include <stack>
#include <tuple>
//最大公約数: gcd()
//最小公倍数: lcm()

#define ll long long int

using namespace std;

template <typename T>
void sortasc(vector<T> &v){ //vectorを昇順にソート
    sort(v.begin(), v.end(), std::less<T>());
    return;
}

template <typename T>
void sortdesc(vector<T> &v){ //vectorを降順にソート
    sort(v.begin(), v.end(), std::greater<T>());
    return;
}

//------------------------------------------------------------------------------

int main(){
	int k;
	string s;
	cin >> k >> s;
	if((int)s.length() > k) cout << s.substr(0, k) << "..." << endl;
	else cout << s << endl;
	return 0;
}


Measured memory_bytes: 3600
#include<iostream>
#include<string.h>
#include<vector>
#include<algorithm>
using namespace std;
int main()
{
    int a[101];
    memset(a,0,sizeof(a));
    vector<int>vec;
    int in;
    while(cin>>in){
        a[in]++;
    }
    int m=0;
    for(int i=0;i<101;i++){
        if(a[i]>m){
            m=a[i];
            vec.clear();
            vec.push_back(i);
        }
        else if(a[i]==m){
            vec.push_back(i);
        }
    }
    sort(vec.begin(),vec.end());
    for(int i=0;i<vec.size();i++){
        cout<<vec[i]<<endl;
    }
    return 0;
}

Measured memory_bytes: 1216
def q3():
    """ C - Exception Handling """
    N = int(input())
    A = []
    for n in range(N):
        A.append(int(input()))

    max_A = max(A)
    second_A = sorted(A, reverse=True)[1]
    for n in range(N):
        if A[n] == max_A:
            print(second_A)
        else:
            print(max_A)

            
if __name__ == '__main__':
    q3()


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

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define pi pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define mod 1000000007
// #define mod 998244353
using namespace std;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, m;
	cin >> n >> m;
	vector<bool> flag(n);
	vector<int> count(n);
	for (int i = 0; i < n; i++)
	{
		count[i] = 1;
	}
	flag[0] = 1;
	while (m--)
	{
		int x, y;
		cin >> x >> y;
		x--;
		y--;
		if (flag[x])
		{
			if (count[x] == 1)
			{
				flag[x] = 0;
				count[x]--;
				flag[y] = 1;
				count[y]++;
			}
			else
			{
				count[x]--;
				flag[y] = 1;
				count[y]++;
			}
		}
		else
		{
			count[x]--;
			count[y]++;
		}
	}
	int ans = 0;
	for (int x : flag)
	{
		ans += x;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 640
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace AtCoder
{
	public class ABC
	{
		static void Main(string[] args)
		{
			Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });


			//int[] vs = Console.ReadLine().Split().Select(int.Parse).OrderBy(p => p).ToArray();
			int n = int.Parse(Console.ReadLine());
			string ans = "No";
			for (int a = 1; a < 10; a++) {
				for (int b = a; b < 10; b++) {
					if (n == a * b) {
						ans = "Yes";
					}
				}
			}
			Console.WriteLine(ans);


			Console.Out.Flush();
		}
	}
}


Measured memory_bytes: 13140
import sys
import heapq
sys.setrecursionlimit(100002)
input=sys.stdin.readline
n,m=map(int,input().split())
a=list(map(int,input().split()))
for i in range(n):
  a[i]=-a[i]
heapq.heapify(a)
for i in range(m):
  heapq.heappushpop(a,-(-a[0]//2))
print(-sum(a))


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

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

    int i;
    int a;
    for(i = 0; i < (int)s.size(); i++) {
        if (s.at(i) == 'A') {
            a = i;
            break;
        }
    }

    int z;
    for(i = 0; i < (int)s.size(); i++) {
        if (s.at(i) == 'Z') {
            z = i;
        }
    }

    cout << z - a + 1 << endl;
}


Measured memory_bytes: 640
// C - Shopping Street
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
#define rp(i,s,e) for(int i=(int)(s);i<(int)(e);++i)

int main(){
	int n; cin>>n;
	vvi F(n, vi(10));
	rp(i, 0, n) rp(j, 0, 10) cin>>F[i][j];
	vvi P(n, vi(10+1));
	rp(i, 0, n) rp(j, 0, 10+1) cin>>P[i][j];
	int64_t ans = -10000000*100;
	rp(i, 1, 1<<10){
		int64_t s = 0;
		rp(j, 0, n){
			int cj = 0;
			rp(k, 0, 10) if(i>>k & 1 && F[j][k]) cj++;
			s += P[j][cj];
		}
		ans = max(ans, s);
	}
	cout<< ans <<endl;
}


Measured memory_bytes: 3644
#include <iostream>
#include <algorithm>
#include <limits>

int main(int argc, char const* argv[])
{
  int n;
  std::cin >> n;

  int cnt = std::numeric_limits<int>::max();
  for (int i = 0; i < n; ++i) {
    long a;
    std::cin >> a;

    int cnt_i = 0;
    while (true) {
      if (0x1 & a || a == 0) {
        break;
      }
      a /= 2;
      ++cnt_i;
    }
    cnt = std::min(cnt_i, cnt);
  }

  std::cout << cnt << std::endl;


  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<utility>
#include<queue>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<map>
#include<set>
#include<complex>
#define INF 2147483647
#define llINF 9223372036854775807
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long

using namespace std;
int main(){
  int d;
  while(cin>>d,d){
    int n,m;cin>>n>>m;
    vector<ll>num,num2(m);
    num.pb(0);
    ll ans=0;
    for(int i=0;i<n-1;i++){ll a;cin>>a;num.pb(a);}
    for(int i=0;i<m;i++)cin>>num2[i];
    num.pb(d);
    sort(num.begin(),num.end());
    for(int i=0;i<m;i++){
      ans+=min(abs(*(lower_bound(num.begin(),num.end(),num2[i]))-num2[i]),abs(num2[i]-*(lower_bound(num.begin(),num.end(),num2[i])-1)));
//      cout<<ans<<endl;
    }
    cout<<ans<<endl;
  }
  return 0;
}



Measured memory_bytes: 3892
#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>;

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

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

int main() {
  int n, m;
  cin >> n >> m;
  int total = 0;
  rep(i, m) {
    int a;
    cin >> a;
    total += a;
    if (total > n) {
      cout << -1 << endl;
      return 0;
    }
  }
  cout << n - total << endl;
  return 0;
}

Measured memory_bytes: 3620
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <iomanip>
using namespace std;

int index(char c){
	return (int)c - (int)'0';
}
int main(){
	string s;
	while(getline(cin, s)){
		double num = 0;
		double a, b;
		stack<double> si;
		string::iterator iter = s.begin();
		while(iter != s.end()){
			if((*iter) == '+'){
				a = si.top(); si.pop();
				b = si.top(); si.pop();
				num = a + b;
				si.push(num);
			}else if(((*iter) == '-') && (iter + 1 == s.end() || !isdigit(iter[1]))){
				a = si.top(); si.pop();
				b = si.top(); si.pop();
				num = b - a;
				si.push(num);
			}else if(((*iter) == '-') && (iter + 1 != s.end()) && isdigit(*(++iter))){
				vector<double> vd;
				vd.push_back(index(*iter));
				while(++iter != s.end() && isdigit(*iter)){
					vd.push_back(index(*iter));
				}
				double c = 0;
				double n = 1;
				for(vector<double>::reverse_iterator iter = vd.rbegin();
					iter != vd.rend(); iter++){
						c += (*iter) * n;
						n = n * 10;
				}
				c = c * -1;
				num = c;
				si.push(c);
			}else if((*iter) == '*'){
				a = si.top(); si.pop();
				b = si.top(); si.pop();
				num = a * b;
				si.push(num);
			}else if((*iter) == '/'){
				a = si.top(); si.pop();
				b = si.top(); si.pop();
				num = b / a;
				si.push(num); 
			}else if(isdigit(*iter)){
				vector<double> vd;
				vd.push_back(index(*iter));
				while(++iter != s.end() && isdigit(*iter)){
					vd.push_back(index(*iter));
				}
				double c = 0;
				double n = 1;
				for(vector<double>::reverse_iterator iter = vd.rbegin();
					iter != vd.rend(); iter++)
				{
					c += (*iter) * n;
					n = n * 10;
				}
				num = c;
				si.push(c);
			}
			if(iter != s.end())iter++;
		}
		cout << fixed << setprecision(6) << num << endl;
	}
	return 0;
}

Measured memory_bytes: 0
a=[1,6,36,216,1296,7776,46656,9,81,729,6561,59049]
n=int(input())
dp=[0]*(n+1)
dp[0]=0#0円は0通り
for i in range(1,n+1):
    s=[]
    for j in a:
        if i-j<0:
            continue
        s.append(dp[i-j])
    dp[i]=min(s)+1
print(dp[-1])


Measured memory_bytes: 42856
import sys

n = sys.stdin.readline().rstrip()
l = len(n)

def main():
    dp0 = [None] * (l + 1)
    dp1 = [None] * (l + 1)
    dp0[0] = 0
    dp1[0] = 1

    for i in range(l):
        d = int(n[i])
        dp0[i+1] = min(dp0[i]+d, dp1[i]+10-d)
        dp1[i+1] = min(dp0[i]+d+1, dp1[i]+10-d-1)
    
    return dp0[l]

if __name__ == '__main__':
    ans = main()
    print(ans)

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

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

const int INF = 1e9;
const int mod = 1e9+7;

int main()
{
    int n;
    cin >> n;
    int a[n];
    double ave = 0;
    for(int i = 0; i < n; i++){
        cin >> a[i];
        ave += a[i];
    }

    int ans;
    double an = 110;
    ave /= n;
    for(int i = 0; i < n; i++){
        if(abs(ave-a[i]) < an){
            an = abs(ave-a[i]);
            ans = i;
        }
    }

    cout << ans << endl;

    return 0;
}

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

#define pb push_back

#define F first
#define S second
#define all(x) x.begin(), x.end()
#define debug(x) cerr << #x << " " << x << '\n'
using namespace std;

typedef long long ll;
typedef long double ld;
typedef string str;
typedef pair<ll, ll> pll;

const ld PI = 3.14159265359;

const ll MOD = (ll) 1e9 + 7;
const ll MAXN = (ll) 2e5 + 10;
const ll INF = (ll) 9223372036854775;
const ld EPS = (ld) 1e-8;

char c[MAXN], d[MAXN];
ll q, n;
str s;

ll check(ll x){
	for(int i = 1; i <= q; i++){
		if(s[x] == c[i]){
			if(d[i] == 'L') x --;
			else x ++;
		}
		if(x < 0) return -1;
		//debug(x);
		if(x == n) return 1;
	}
	return 0;
}

int main(){
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin >> n >> q;
	//str s;
	cin >> s;
	for(int i = 1; i <= q; i++){
		cin >> c[i] >> d[i];
	}
	//debug(q);
	ll ans = 0;
	ll l = -1, r = n;
	ll mid;
	while(l + 1 < r){
		mid = (l + r) / 2;
		if(check(mid) == -1) l = mid;
		else r = mid;
	}
	ans += (l + 1);
	
	l = -1; r = n;
	
	while(l + 1 < r){
		mid = (l + r) / 2;
		if(check(mid) == 1) r = mid;
		else l = mid;
	}
	//debug(r);debug(check(1));
	ans += (n - r);
	cout << n - ans;
	return 0;
}



Measured memory_bytes: 976
#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>;

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

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

int main() {
  int a, b, h, m;
  cin >> a >> b >> h >> m;
  double b_range = 360 / 60 * m;
  double a_range = 360 / 12 * h;
  a_range += m / 60.0 * 30;

  double range = 0.0;
  if (a_range > b_range) {
    range = a_range - b_range;
  } else {
    range = b_range - a_range;
  }

  if (range > 180) range = 360 - range;
  double result;
  result = sqrt(pow(a, 2) + pow(b, 2) - 2 * a * b * cos(range * (M_PI / 180)));

  printf("%.20f\n", result);
  return 0;
}

Measured memory_bytes: 4136
N = int(input())
H = [int(x) for x in input().split()]
L = []
count = 0
L.append(0)

for n in range(len(H)-1):
    if H[n]-H[n+1]>=0:
        count += 1
        L.append(count)
    else:
        count = 0

print(max(L))


Measured memory_bytes: 14252
function Main(input){
    const arr = input.split('\n');
    const X = Number(arr[0].split(' ')[1]);
    const xi = arr[1].split(' ').map(Number);
    const xi_cal = xi.map(val => Math.abs(val-X));
    const GCD = (n, m) => {
        if(n % m === 0) return m;
        return GCD(m, n % m);
    }
    console.log(xi_cal.reduce((a,b) =>GCD(a,b)));
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 40364
#include<bits/stdc++.h>
#define ll long long int
#define l(i,a,b) for(ll i=a;i<b;i++)
using namespace std;
int main(){
	int n,m;
	cin>>n>>m;
	if(m==n) cout<<"Yes\n";
	else cout<<"No\n";
	
}

Measured memory_bytes: 3556
#include <bits/stdc++.h>
#include <iostream>
#include<math.h>
using namespace std;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
int main()
{
    int N, A, B, C, D;
    cin >> N >> A >> B >> C >> D;
    string S;
    cin >> S;
    bool ikeru = true;
    for (int i=A-1; i<C-1; i++) {
        if (S[i] == '#') {
            continue;
        }

        if (S[i+1] == '#' && S[i+2] == '#') {
            ikeru = false;
            break;
        }

    }

    for (int i=B-1; i<D-1; i++) {
        if (S[i] == '#') {
            continue;
        }

        if (S[i+1] == '#' && S[i+2] == '#') {
            ikeru = false;
            break;
        }

    }

    if (C > D) {
        bool murikamo = true;
        for (int i=B-1; i<D; i++) {
            if (S[i] == '#') {
                continue;
            }

            if (S[i-1] != '#' && S[i+1] != '#') {
                murikamo = false;
                break;
            }
        }

        if (murikamo) {
            ikeru = false;
        }
    }

    if (ikeru) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 3692
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef pair<int, int> P;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vd = vector<double>;
using vvd = vector<vector<double>>;
using vvvd = vector<vector<vector<double>>>;
using vb = vector<bool>;
using vvb = vector<vector<bool>>;
using vs = vector<string>;
using pint = pair<int, int>;
using Graph = vvi;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
bool cmp(pint a, pint b) {return a.second < b.second;}

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

    ll ans = 0;
    ll cnt = 1;
    while(h >= 1) {
        ans += cnt;
        cnt *= 2;
        h /= 2;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
int main(){
  int N, X, m, count = 0;
  cin >> N >> X;
  vector<int>alchemy(N);
  for(int i = 0; i < N; i++){
    cin >> alchemy.at(i);
    X -= alchemy.at(i);
    count += 1;
  }
  if(X == 0){
    cout << count << endl;
  }
  else{
    sort(alchemy.begin(), alchemy.end());
    count += X / alchemy.at(0);
    cout << count << endl;
  }
}

Measured memory_bytes: 256
#include <stdio.h>          // printf(), scanf()
#include <stdlib.h>         // qsort()
#include <stdbool.h>

#define MAX_N 200
#define max(a, b) ((a) > (b) ? (a) : (b))

typedef struct doll_tbl
{
	short h;
	short r;
} doll_t;

short N;
doll_t doll[MAX_N];

int
cmp_func(const void *l_, const void *r_)
{
	const doll_t *l = (const doll_t*) l_;
	const doll_t *r = (const doll_t*) r_;

	if (l->h < r->h)
		return -1;

	if (l->h > r->h)
		return 1;

	return 0;
}

int
solve()
{
	short dp[MAX_N];

	qsort(doll, N, sizeof(doll_t), cmp_func);

	int count = 0;
	for (int i = 0; i < N; ++i)
	{
		dp[i] = 1;
		for (int j = 0; j < i; ++j)
		{
			if (doll[j].h < doll[i].h && doll[j].r < doll[i].r)
				dp[i] = max(dp[i], dp[j] + 1);
		}

		count = max(count, dp[i]);
	}

	return count;
}

int
main(int argc, char **argv)
{
	while (true)
	{
		int n, m;
		scanf("%d", &n);
		if (n == 0)
			break;

		for (int i = 0; i < n; ++i)
			scanf("%hd%hd", &doll[i].h, &doll[i].r);

		scanf("%d", &m);
		for (int i = 0; i < m; ++i)
			scanf("%hd%hd", &doll[n + i].h, &doll[n + i].r);

		N = n + m;
		printf("%d\n", solve());
	}

	return 0;
}


Measured memory_bytes: 1844
using System;

class Program
{
  public static long getMin(long[] values,long num)
  {
    long min = values[0];
    for(int i = 1;i < num;i++)
    {
      if(min > values[i]) min = values[i];
    }
    return min;
  }

  public static long getMax(long[] values,long num)
  {
    long max = values[0];
    for(int i = 1;i < num;i++)
    {
      if(max < values[i]) max = values[i];
    }
    return max;
  }

  public static long getSum(long[] values,long num)
  {
    long sum = 0;
    for(int i = 0;i < num;i++)
    {
      sum += values[i];
    }
    return sum;
  }

  public static void Main(string[] args)
  {
    int num = int.Parse(Console.ReadLine());
    string[] read = Console.ReadLine().Split(' ');
    long[] values = new long[num];
    for(int i = 0;i < num;i++) values[i] = long.Parse(read[i]);
    long min = getMin(values,num);
    long max = getMax(values,num);
    long sum = getSum(values,num);
    Console.WriteLine("{0} {1} {2}",min,max,sum);
  }
}

Measured memory_bytes: 9880
import java.io.BufferedReader
import java.util.*
import kotlin.math.abs
import kotlin.math.min

fun main() = abc175c()

@OptIn(ExperimentalStdlibApi::class)
fun abc175c() = SimpleFastIOWithToken_abc175c().exec {
    var (x, count, dist) = List(3) { readLong() }
    if (x < 0) x *= -1

    if (x > dist) {
        val moveCount = min(x / dist, count)
        x -= moveCount * dist
        count -= moveCount
    }

    if (count == 0L) return@exec println(x)

    val answer = if (count % 2 == 0L) x else abs(x - dist)

    println(answer)
}

// region kokokara template dayo (^o^)
@Suppress("unused", "HasPlatformType", "MemberVisibilityCanBePrivate", "ClassName")
private class SimpleFastIOWithToken_abc175c(private val separator: String = System.lineSeparator()) {
    private val br: BufferedReader = System.`in`.bufferedReader()
    private var st: StringTokenizer = StringTokenizer("")
    private val sb: StringBuilder = StringBuilder()
    private fun prepareNext() = run { if (!st.hasMoreTokens()) st = StringTokenizer(br.readLine()) }

    fun readString(): String = run { prepareNext() }.run { st.nextToken() }
    fun readInt(): Int = Integer.valueOf(readString())
    fun readLong(): Long = java.lang.Long.valueOf(readString())

    fun println(): Unit = run { sb.append(separator) }
    fun print(any: Any): Unit = run { sb.append(any) }
    fun println(any: Any): Unit = run { sb.append(any.toString() + separator) }

    fun exec(action: SimpleFastIOWithToken_abc175c.() -> Unit) {
        var t: Throwable? = null
        Thread(null, { action() }, "solve", 128 * 1024 * 1024)
            .apply { setUncaughtExceptionHandler { _, t1 -> t = t1 } }
            .apply { start() }.join()
        t?.let { throw it }
        kotlin.io.print(sb)
    }

    fun readLine(): Nothing = error("readLine is disabled.")
}
// endregion kokomade template dayo (^o^)


Measured memory_bytes: 34656
#include <bits/stdc++.h>
using namespace std;
int main() {
	string s; cin >> s;
	map<int, string> mp;
	mp[2] = mp[4] = mp[5] = mp[7] = mp[9] = "hon";
	mp[0] = mp[1] = mp[6] = mp[8] = "pon";
	mp[3] = "bon";
	cout << mp[s.back() - '0'];
}

Measured memory_bytes: 3628
# ALDS1_2_D: Shell Sort

#N = 5
#A = [5, 1, 4, 3, 2]

#N = 3
#A = [3, 2, 1]

A = []
N = int(input())
for i in range(N):
    A.append(int(input()))

def insertionSort(A, N, g, cnt):
    #print(" ".join(map(str, A)))
    for i in range(g, N):
        v = A[i]
        j = i - g
        while j >= 0 and A[j] > v:
            A[j+g] = A[j]
            j = j - g
            cnt += 1
        A[j+g] = v
        #print(" ".join(map(str, A)))
    return cnt
    
def shellSort(A, N):
    cnt = 0
    #m = 2
    #listG = [4, 1] 
    h = 1
    listG = []
    while h <= N:
        listG.append(h)
        h = 3*h + 1
    listG = listG[::-1]
    m = len(listG)
    
    for g in listG:
        cnt = insertionSort(A, N, g, cnt)
        #print(A)
        
    print(m)
    print(" ".join(map(str, listG)))
    print(cnt)
    for v in A:
        print(v)

shellSort(A, N)


Measured memory_bytes: 45516
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <sstream>
#include <cmath>
#include <set>
#include <iomanip>
#include <deque>
#include <stdio.h>
#include <fstream>
using namespace std;

#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 FILL(Itr,n) fill((Itr).begin(),(Itr).end(),n)
#define REMOVE(Itr,n) (Itr).erase(remove((Itr).begin(),(Itr).end(),n),(Itr).end())
#define UNIQUE(Itr) sort((Itr).begin(),(Itr).end()); (Itr).erase(unique((Itr).begin(),(Itr).end()),(Itr).end())
#define LBOUND(Itr,val) lower_bound((Itr).begin(),(Itr).end(),(val))
#define UBOUND(Itr,val) upper_bound((Itr).begin(),(Itr).end(),(val))
#define MOD 1000000007
typedef long long ll;
typedef pair<int,int> P;

int N,M,Q;
vector<int> v,d,c;
int dp[100010];
int color[100010];
vector<int> G[100010];
bool used[100010];

void bfs(int ver, int dep, int col){
    queue< pair<int,int> > que;
    que.push(make_pair(ver,dep));
    while(que.size()!=0){
        int vt = que.front().first;
        int dt = que.front().second;
        que.pop();
        if(used[vt])continue;
        used[vt] = true;
        if(dp[vt]>=dt)continue;
        dp[vt] = dt;
        if(color[vt]==0)color[vt] = col;
        if(dt==0)continue;
        REP(i,G[vt].size()){
            que.push(make_pair(G[vt][i],dt-1));
        }
    }
}

int main(){
    
    cin>>N>>M;
    REP(i,M){
        int a,b; cin>>a>>b;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    
    cin>>Q;
    REP(i,Q){
        int vt,dt,ct;
        cin>>vt>>dt>>ct;
        v.push_back(vt);
        d.push_back(dt);
        c.push_back(ct);
    }
    
    REP(i,100010)dp[i] = -1;
    
    RREP(i,Q){
        if(dp[v[i]]<d[i]){
            REP(j,100010)used[j] = false;
            bfs(v[i],d[i],c[i]);
        }
    }
    
    for(int i=1;i<=N;i++)cout<<color[i]<<endl;
    
    return 0;
}

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

// ?????¬???????????¬??????
#pragma region MACRO
#define P(x) cout << (x) << endl
#define p(x) cout << (x)
#define PED cout << "\n"
#define rep(i,n) for(int i=0; i<(int)n; ++i)
#define REP(i,x,n) for(int i=x; i<(int)n; ++i)
#define repi(i,n) for(int i=0; i<=(int)n; ++i)
#define REPI(i,x,n) for(int i=x; i<=(int)n; ++i)
#define ILP while(true)
#define FOR(i,c) for(__typeof((c).begin())!=(c).begin(); i!=(c).end(); ++i)
#define ALL(c) (c).begin(), (c).end()
#define mp make_pair
#pragma endregion

// ???
#pragma region TYPE_DEF
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<string, string> pss;
typedef pair<string, int> psi;
typedef pair<int, string> pis;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long double> vld;
typedef vector<long> vl;
typedef vector<long long> vll;
typedef vector<string> vs;
#pragma endregion

// Effective std
#pragma region ESTD
template<typename C, typename T> int count(C& c, T t) { return count(ALL(c), t); }
template<typename C, typename F> int count_if(C& c, F f) { return count_if(ALL(c), f); }
template<typename C, typename T> void erase(C& c, T t) { remove(ALL(c), t), c.end(); }
template<typename C> void remove(vector<C>& c, unsigned int index) { c.erase(c.begin()+index); }
template<typename C, typename T, typename U> void replace(C& c, T t, U u) { replace(ALL(c), t, u); }
template<typename C, typename F, typename U> void replace_if(C& c, F f, U u) { (ALL(c), f, u); }
template<typename C> void reverse(C& c) { reverse(ALL(c)); }
template<typename C> void sort(C& c) { sort(ALL(c)); }
template<typename C, typename Pred> void sort(C& c, Pred p) { sort(ALL(c), p); }
#pragma endregion

// ?????°
#pragma region CONST_VAL
constexpr int PI = (2*acos(0.0));
constexpr int EPS = (1e-9);
constexpr int MOD = (int)(1e9+7);
constexpr int INF = 100000000;
#pragma endregion

struct Point {
    double x;
    double y;
};

double Abs(double x) {
    return x >=0 ? x : -x;
};

double Square(const Point& P, const Point& Q, const Point& R) {
    Point A = {Q.x-P.x, Q.y-P.y};
    Point B = {R.x-P.x, R.y-P.y};
    return Abs(A.x*B.y-A.y*B.x);
};

bool solve(const Point& P, const Point& Q, const Point R, const Point O) {
    return (Square(P,Q,R) > Square(O,P,Q) + Square(Q, R, O));
}

int main()
{
    Point A, B, C, D;
    char c;
    while(cin>>A.x>>c>>A.y>>c>>B.x>>c>>B.y>>c>>C.x>>c>>C.y>>c>>D.x>>c>>D.y) {
        if(solve(A,B,C,D) || solve(B,C,D,A) || solve(C,D,A,B) || solve(D,A,B,C))
            P("NO");
        else
            P("YES");

    }
    return 0;
}

Measured memory_bytes: 3212
import java.util.Scanner;


public class Main {
	
	static Scanner sc = new Scanner(System.in);
	
	static int n;
	static double[] x = new double[4];
	static double[] y = new double[4];
	static double x1, x2, y1, y2,a ,b;

	public static void main(String[] args) {
		n = sc.nextInt();
		
		for(int i=0; i < n; i++){
			read();
			solve();
		}

	}
	
	static boolean read() {
		
		for(int j=0; j < 4; j++){
			x[j] = sc.nextDouble();
			y[j] = sc.nextDouble();
		}
		
		x1 = x[0] - x[1];
		x2 = x[2] - x[3];
		y1 = y[0] - y[1];
		y2 = y[2] - y[3];
		a = y1/x1;
		b = y2/x2;
		
		return true;
	}
	
	static void solve(){
		if(a == b){
			System.out.println("YES");
		}else{
			System.out.println("NO");
		}
	}

}

Measured memory_bytes: 12000
#![allow(non_snake_case, unused)]
use std::cmp::*;
use std::collections::*;
use std::f64::consts::*;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn mod_pow(mut b: usize, mut e: usize, m: usize) -> usize {
    let mut res = 1;

    while (e > 0) {
        if ((e & 1) == 1) {
            res = (res * b) % m;
        }
        e >>= 1;
        b = (b * b) % m;
    }
    res
}

fn main() {
    input!{
        n: usize,
        mut a: [usize; n],
    }
    let mut valid_flag = true;
    a.sort();
    if a[0] == 0 {
        for i in 1..n {
            if a[i] != (i + 1) / 2 * 2 {
                valid_flag = false
            }
        }
    } else {
        for i in 0..n {
            if a[i] != (i / 2) * 2 + 1 {
                valid_flag = false
            }
        }
    }

    let res = mod_pow(2, n/2, 1_000_000_007);

    println!("{}", if valid_flag {res} else {0});
}


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

int main(){
	string s;
	cin>>s;
	if(s=="RRR"){
		cout<<3<<endl;
	} 
	else if(s=="SRR" or s=="RRS"){
		cout<<2<<endl;
	} 
	else if(s=="RSS" or s=="SRS" or s=="SSR" or s=="RSR"){
		cout<<1<<endl;
	} 
	else{
		cout<<0<<endl;
	} 
	return 0;
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(v) v.begin(), v.end()
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++) 
#define Rep(n) for (ll _ = 0; _ < (ll)(n); _++) 
#define fs first
#define sc second

// 1次元vectorの出力
template <class S>
void print(vector<S> &v){for(ll i=0; i<(ll)v.size(); i++){
		cerr << v[i] << ' ';
	}
	cerr << endl;
}

// 2次元vectorの出力
template <class S>
void print(vector<vector<S>> &v) {
  	for (ll i = 0; i < (ll)v.size(); i++) {
    	for (ll j = 0; j < (ll)v[i].size(); j++) {
      		cerr << v[i][j] << ' ';
    	}
    	cerr << endl;
  	}
}

const int mod = 1000000007;
struct mint {
  ll x;  // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod - a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const { return mint(*this) += a; }
  mint operator-(const mint a) const { return mint(*this) -= a; }
  mint operator*(const mint a) const { return mint(*this) *= a; }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod - 2); }
  mint& operator/=(const mint a) { return *this *= a.inv(); }
  mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x; }
ostream& operator<<(ostream& os, const mint& a) { return os << a.x; }

mint perm(int n, int r){
	if(r == 0) return mint(1);
	mint res(n);
	for(int i=n-1; i>n-r; i--){
		res *= i;
	}
	return res;
}

mint ans;
int n,k;

void dfs(int node, vector<vector<int>> &tree, int par){
	int c = k-2;
	for(int child: tree[node]){
		if(child != par){
			ans *= c--;
			dfs(child, tree, node);
		}
	}
}

int main(void){
	cin >> n >> k;
	vector<vector<int>> tree(n,vector<int>());
	Rep(n-1){
		int a,b; cin >> a >> b;
		a--; b--;
		tree[a].push_back(b);
		tree[b].push_back(a);
	}
	ans += k;
	ans *= perm(k-1, tree[0].size());
	for(int node: tree[0]){
		dfs(node, tree, 0);
	}
	cout << ans << endl;
}

Measured memory_bytes: 11520
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <queue>
#include <sstream>
#include <stack>
#include <time.h>
#include <vector>
#include <complex>
#include <map>
#include <set>
#include <iomanip>
#include <math.h>
#include <stdlib.h>
#include <list>
#include <utility>
#include <memory>
#include <cstring>
#include <fstream>
#include <numeric>
#include <assert.h>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll k,a,b;
int main(){
	cin>>k>>a>>b;
	if (b<=a){
		cout<<k+1;
		return 0;
	}
	if (k<=a-1){
		cout<<k+1;
		return 0;
	}
	k-=a-1;
	int el=k%2;
	int ee=k/2;
	cout<<max(a+ee*(b-a)+el,1+k+a-1);
}

Measured memory_bytes: 256
n, m = map(int, input().split())
if n > m:
  n, m = m, n
if n == 1:
  if m == 1:
    print(1)
  elif m == 2:
    print(0)
  else:
    print(m - 2)
elif n == 2:
  print(0)
else:
  print((n - 2) *(m - 2))


Measured memory_bytes: 3060
#include <iostream>
using namespace std;
int main(){
 int x1,x2,x3,x4,x5;
 cin >> x1 >> x2 >> x3 >> x4 >> x5;
 
     if(x1 == 0){
        x1 += 1;
   cout << x1 << endl;
     }
 else if(x2 == 0){
       x2 += 2;
   cout << x2 << endl;
 }
 else if(x3 == 0){
       x3 += 3;
   cout << x3 << endl;
 }
 else if(x4 == 0){
       x4 += 4;
   cout << x4 << endl;
 }
 else if(x5 == 0){
       x5 += 5;
   cout << x5 << endl;
 }


 }


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

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

int main() {
	int H, W;
	while(cin >> W >> H, H) {
		bool ng[17][17] = { 0 };
		int n;
		cin >> n;
		while(n--) {
			int x, y;
			cin >> x >> y;
			ng[y][x] = true;
		}

		int dp[17][17] = { 0 };
		dp[1][1] = 1;
		for(int y = 1; y <= H; y++) {
			for(int x = 1; x <= W; x++) {
				for(int k = 0; k < 2; k++) {
					int nx = x + dx[k], ny = y + dy[k];
					if(1 <= nx && nx <= W && 1 <= ny && ny <= H && !ng[ny][nx]) {
						dp[ny][nx] += dp[y][x];
					}
				}
			}
		}

		cout << dp[H][W] << endl;
	}
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define input freopen("1.txt","r",stdin);
#define output freopen("output.txt","w",stdout);
#define ll long long int
#define pb push_back
#define eb emplace_back
#define vi vector<int>
#define vii vector<vi>
#define vl vector<ll>
#define vll vector<vl>
#define pll pair<ll,ll>
#define mp make_pair
#define vpl vector<pll> 
using namespace std;
 
const int mod=1e9+7;
const int maxn=2e5+2;
map<string,int> m;
void solve() {
    int N;
    cin>>N;
    string s;
    m.clear();
    for(int i=0;i<N;i++) {
        cin>>s;
        m[s]++;
    }
    cout<<"AC"<<" "<<"x"<<" "<<m["AC"]<<"\n";
     cout<<"WA"<<" "<<"x"<<" "<<m["WA"]<<"\n";
      cout<<"TLE"<<" "<<"x"<<" "<<m["TLE"]<<"\n";
       cout<<"RE"<<" "<<"x"<<" "<<m["RE"]<<"\n";
}


int main() {
    fast
    int t; 
    t=1;
    while(t--) solve();
    return 0;
}

Measured memory_bytes: 3652