akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
#define rep(i,x) for(ll i = 0; i < (ll)(x); i++)
#define pb push_back
#define eb emplace_back
#define debug(x) cerr << #x << ": " << (x) << "\n";
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<ll>>> vvvl;
const ll INF = numeric_limits<ll>::max()/4;
const ll MOD = 1e9+7;
const int n_max = 1e5+10;

int main(){
    ll q,h; cin >> q >> h;
    ll s,d; cin >> s >> d;
    ll n; cin >> n;
    vector<Pll> vec = {
        {q*8,1},
        {h*4,2},
        {s*2,4},
        {d,8}
    };
    sort(all(vec));
    ll ans = 0;
    ll id = 0;
    n *= 4;
    while(0 < n){
        ans += (n/vec[id].second) * (vec[id].first*vec[id].second / 8);
        n %= vec[id].second;
        id++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
loop do
  n = gets.to_i
  m = gets.to_i
  break if(n|m)==0
  hash = Hash.new{|hash,key|hash[key]=Array.new}
  m.times do
    a,b = gets.split.map(&:to_i)
    hash[a] << b
    hash[b] << a
  end
  friend=hash[1]
  if friend.empty?
    puts 0
    next
  end
  ans = friend.dup
  friend.each do |f|
    ans |=hash[f]
  end
  ans.delete(1)
  puts ans.size
end

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

int main(void){
    char S[11];
    scanf("%s", S);
    
    int i, j;
    int X;
    int Y = 753;
    int min = 1000000;
    for(i = 0; i<=strlen(S)-3; i++) {
        X = 100 * (int)(S[i] - '0') + 10 * (int)(S[i+1] - '0') + (int)(S[i+2] - '0');
        if(abs(Y - X) < min) {
            min = abs(Y - X);
        }
    }

    printf("%d\n", min);

    return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<utility>
typedef long long int ll;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<signed(n);i++)
#define EREP(i,n) for(int i=1;i<=signed(n);i++)
#define ALL(a) (a).begin(),(a).end()
using std::cout;
using std::vector;
using std::endl;
using std::cin;
using std::string;
using std::min;
//#define EVEL 1
#ifdef EVEL
#define DEB(X) cout << #X << ":" <<X<<" " ;
#define TF(f) f ? cout<<"true  " : cout<<"false ";
#define END cout<<"\n";
#else
#define DEB(X) {}
#define TF(f) {}
#define END {}
#endif
const int MOD = 1000000007;
const ll INF = 9e18;
typedef std::pair<int,int> P;
//struct edge {int to,cost;};
#define VMAX 100000+10
ll X[51],Y[51];
ll N,K,ans=INF;
int main(){
    std::ios_base::sync_with_stdio(false);
    cin>>N>>K;
    REP(i,N)cin>>X[i]>>Y[i];
    REP(i,N){
        for(int j=i+1;j<N;j++){
            for(int k=0;k<N;k++){
                for(int l=k+1;l<N;l++){
                    int num=0;
                    ll  fx=std::min({X[i],X[j],X[k],X[l]}),
                        lx=std::max({X[i],X[j],X[k],X[l]}),
                        fy=std::min({Y[i],Y[j],Y[k],Y[l]}),
                        ly=std::max({Y[i],Y[j],Y[k],Y[l]});
                    REP(m,N){
                        if(fx<=X[m]&&X[m]<=lx&&fy<=Y[m]&&Y[m]<=ly)num++;
                    }
                    if(num>=K)ans=std::min(ans,((lx-fx)*(ly-fy)));
                }
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}

//ABC075 D - Axis-Parallel Rectangle


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define For(i, l, r) for(register int i = (l), i##end = (int)(r); i <= i##end; ++i)
#define Fordown(i, r, l) for(register int i = (r), i##end = (int)(l); i >= i##end; --i)
#define Set(a, v) memset(a, v, sizeof(a))
using namespace std;

inline bool chkmin(int &a, int b) {return b < a ? a = b, 1 : 0;}
inline bool chkmax(int &a, int b) {return b > a ? a = b, 1 : 0;}

void File() {
#ifdef zjp_shadow
	freopen ("B.in", "r", stdin);
	freopen ("B.out", "w", stdout);
#endif
}

typedef long long ll;

const int N = 3e5 + 1e3;
const ll Mod = 998244353;

ll fac[N], ifac[N];

ll fpm(ll x, int power) {
	ll res = 1;
	for (; power; power >>= 1, (x *= x) %= Mod)
		if (power & 1) (res *= x) %= Mod;
	return res;
}

ll Comb(int n, int m) {
	if (n < 0 || m < 0 || m > n) return 0;
	return fac[n] * ifac[m] % Mod * ifac[n - m] % Mod;
}

void Init(int maxn) {
	fac[0] = ifac[0] = 1;
	For (i, 1, maxn) fac[i] = fac[i - 1] * i % Mod;
	ifac[maxn] = fpm(fac[maxn], Mod - 2);
	Fordown (i, maxn - 1, 1) ifac[i] = ifac[i + 1] * (i + 1) % Mod;
}

int main () {
	File();
	ll n, a, b, k;
	cin >> n >> a >> b >> k;

	Init(3e5);

	ll ans = 0;

	For (A, 0, n) {
		if ((k - a * A) % b) continue ;
		int B = (k - a * A) / b;
		if (B < 0 || B > n) continue ;
		(ans += Comb(n, A) * Comb(n, B) % Mod) %= Mod;
	//	For (C, 0, min(A, B)) (ans += Comb(n, C) * Comb(n - C, A - C) % Mod * Comb(n - (A - C) - C, B - C) % Mod) %= Mod;
	}

	printf ("%lld\n", ans);

    return 0;
}


Measured memory_bytes: 4992
#include<bits/stdc++.h>
#define LL long long
#define dl double
template <class T>
void rd(T &x){
  x=0;T f=1;char ch=getchar();
  while(ch<'0' || ch>'9'){if(ch=='-')f=-1;ch=getchar();}
  while(ch<='9' && ch>='0')x=x*10+ch-'0',ch=getchar();x*=f;
}
using namespace std;
const int N=1e5+10;
bool is[N];
int cnt,n;
void work(int x){
 cnt=0;
 for(int i=1;i*i<=x;i++){
  for(int j=1;j<=i && j*j<=x-i*i;j++){
   if(!is[x-i*i-j*j])continue;
   if(x-i*i-j*j > j*j)continue;
   int k=sqrt(x-i*i-j*j);
   if(j+k <= i)continue;
   if((i+j+k)%2)continue;
   if(i==j && j==k)cnt++;
   else if(i==j || j==k)cnt+=3;
   else cnt+=6;
  }
 }
 printf("%d\n",cnt);
}
int main(){
 // freopen("in.txt","r",stdin);
 // freopen("o.txt","w",stdout);
 rd(n);
 for(int i=1;i<=100000;i++)if((int)sqrt(i)*(int)sqrt(i) == i)is[i]=1;
 for(int i=1;i<=n;i++)work(2*i);
 return 0;
}
/**/

Measured memory_bytes: 3768
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define FOR(i,start,end) for(int i=start;i<=end;i++)
const int INF = 1001001001;
typedef long long ll;
const ll MOD=1000000007;
using namespace std;
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<class T>auto MAX(const T& a) { return *max_element(a.begin(),a.end()); }
template<class T>auto MIN(const T& a) { return *min_element(a.begin(),a.end()); }
template<class T, class U>U SUM(const T& a, const U& v) { return accumulate(a.begin(),a.end(), v); }
template<class T, class U>U COUNT(const T& a, const U& v) { return count(a.begin(),a.end(), v); }
template<class T, class U>int LOWER(const T& a, const U& v) { return lower_bound(a.begin(),a.end(), v) - a.begin(); }
template<class T, class U>int UPPER(const T& a, const U& v) { return upper_bound(a.begin(),a.end(), v) - a.begin(); }
int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
int LCM(int a, int b) { int g = GCD(a, b); return a / g * b; }

int main(void){
    // Your code here!
    string s;cin >> s;
    vector<int> a(4);
    rep(i,4) a[i] = s[i]-'0';
    vector<char> op(3); 
    for (int bit = 0;bit <(1<<3);++bit){
        int sum = a[0];
        rep(j,3){
            if (bit &(1<<j)){
                op[j] ='+';
                sum += a[j+1];
            }else{
                op[j] = '-';
                sum -= a[j+1];
            }
        }
        if (sum == 7){
            break;
        }
    }
    rep(i,3){
        cout << s[i] << op[i];
    }
    cout << s[3] << "=7" << endl;
}


Measured memory_bytes: 256
macro_rules! get_one {
    ($t:ty) => {{
        let mut line: String = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        line.trim().parse::<$t>().unwrap()
    }};

    ($t:ty; $n:expr) => {
        (0..$n).map(|_| get_one!($t)).collect::<Vec<_>>()
    };
}
macro_rules! get_vec {
    ($t:ty) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_| get_vec!($t)).collect::<Vec<_>>()
    };
}
fn main() {
    let _ = get_one!(usize);
    let v_a = get_vec!(usize);

    let xor = v_a.iter().fold(0_usize, |acc, a| acc ^ a);

    let v_ans: Vec<String> = v_a.iter().map(|a| a ^ xor).map(|x| format!("{}", x)).collect();

    let ans = v_ans.join(" ");

    println!("{}", ans);

}


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

using namespace std;
using LL = long long;
const int N = 1024;
const int INF = INT32_MAX - 1;
const double EPS = 1E-9;

int a[N]={0,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 n, m;

int main() {
    ios_base::sync_with_stdio(false);

#ifdef CF_DEBUG
    freopen("../cf/input.txt","r",stdin);
#endif

    int v;
    cin>>v;
    cout<<a[v]<<endl;
    return 0;
}

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

const ll INF = 1LL << 60;

ll R, C, M;
char S[50][50];
ll unit[50][50], on[50][50], off[50][50], Y[1000], X[1000];

bool dfs(ll y, ll x, ll gy, ll gx, vector<ll> &ty, vector<ll> &tx, vector< vector<bool> > &used) {
  if(used[y][x]) return false;
  used[y][x] = true;

  ty.push_back(y);
  tx.push_back(x);

  if(y == gy && x == gx) return true;

  ll dd[5] = { 0, -1, 0, 1, 0 };
  REP(i, 0, 4) {
    ll ny = y + dd[i], nx = x + dd[i + 1];
    if(0 <= ny && ny < R && 0 <= nx && nx < C && S[ny][nx] == '.') {
      if(dfs(ny, nx, gy, gx, ty, tx, used)) return true;
    }
  }

  ty.resize(ty.size() - 1);
  tx.resize(tx.size() - 1);

  return false;
}

int main(void) {
  cin >> R >> C >> M;
  REP(i, 0, R) REP(j, 0, C) cin >> S[i][j];
  REP(i, 0, R) REP(j, 0, C) cin >> unit[i][j];
  REP(i, 0, R) REP(j, 0, C) cin >> on[i][j];
  REP(i, 0, R) REP(j, 0, C) cin >> off[i][j];
  REP(i, 0, M) cin >> Y[i] >> X[i];

  ll y = Y[0], x = X[0];
  ll ans = on[y][x], t = 1;

  ll last[R][C];
  REP(i, 0, R) REP(j, 0, C) last[i][j] = -INF;
  last[y][x] = 0;

  REP(i, 0, M - 1) {
    vector<ll> ty, tx;
    vector< vector<bool> > used(R, vector<bool>(C, false));
    dfs(Y[i], X[i], Y[i + 1], X[i + 1], ty, tx, used);

    REP(j, 1, ty.size()) {
      y = ty[j];
      x = tx[j];

      if(last[y][x] < 0) {
        ans += on[y][x];
      } else {
        ll d = t - last[y][x];
        if(d * unit[y][x] <= off[y][x] + on[y][x]) {
          ans += d * unit[y][x];
        } else {
          ans += off[y][x] + on[y][x];
        }
      }

      last[y][x] = t++;
    }
  }

  REP(i, 0, R) REP(j, 0, C) {
    if(last[i][j] >= 0) ans += off[i][j];
  }

  cout << ans << endl;
}



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

int main(){
	float n, m;
	while(cin >> n >> m){
		if(n < 35.5 && m < 71.0) cout << "AAA" << endl;
		else if(n < 37.5 && m < 77.0) cout << "AA" << endl;
		else if(n < 40.0 && m < 83.0) cout << "A" << endl;
		else if(n < 43.0 && m < 89.0) cout << "B" << endl;
		else if(n < 50.0 && m < 105.0) cout << "C" << endl;
		else if(n < 55.0 && m < 116.0) cout << "D" << endl;
		else if(n < 70.0 && m < 148.0) cout << "E" << endl;
		else cout << "NA" << endl;
	}
}

Measured memory_bytes: 1220
#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 mod 1000000007
using namespace std;

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

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

    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long li;

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

    li n;
    cin >> n;
    vector<li> xs(3 * n);
    for (int i = 0; i < 3 * n; ++i) {
        cin >> xs[i];
        xs[i]--;
    }

    const li inf = 1LL << 50;
    vector<vector<li>> dp(n, vector<li>(n, -inf));
    vector<li> dp_maxx(n, -inf);
    vector<li> dp_maxy(n, -inf);
    li dp_max = -inf;

    auto update = [&](const li x, const li y, const li v) {
        dp[x][y] = max(dp[x][y], v);
        dp_maxx[y] = max(dp_maxx[y], v);
        dp_maxy[x] = max(dp_maxy[x], v);
        dp_max = max(dp_max, v);
    };

    update(xs[0], xs[1], 0);

    li offset = 0;
    for (int itr = 0; itr < n - 1; ++itr) {
        const li p = xs[2 + itr * 3];
        const li q = xs[2 + itr * 3 + 1];
        const li r = xs[2 + itr * 3 + 2];

        // add, use 3
        if (p == q && q == r) {
            offset++;
            continue;
        }

        vector<tuple<li, li, li>> updates;

        // add, use 2
        if (p == q || q == r || p == r) {
            li pair, rem;
            if (p == q) {
                pair = p;
                rem = r;
            } else if (q == r) {
                pair = q;
                rem = p;
            } else {
                pair = r;
                rem = q;
            }
            for (int k = 0; k < n; ++k) {
                updates.emplace_back(k, rem, dp[k][pair] + 1);
                updates.emplace_back(k, rem, dp[pair][k] + 1);
            }
        }

        // add, use 1
        updates.emplace_back(q, r, dp[p][p] + 1);
        updates.emplace_back(p, r, dp[q][q] + 1);
        updates.emplace_back(p, q, dp[r][r] + 1);

        // no-add, use 3
        // reusing the dp table to avoid O(n^2) updates.

        // no-add, use 2
        for (int k = 0; k < n; ++k) {
            updates.emplace_back(k, p, dp_maxx[k]);
            updates.emplace_back(k, p, dp_maxy[k]);
            updates.emplace_back(k, q, dp_maxx[k]);
            updates.emplace_back(k, q, dp_maxy[k]);
            updates.emplace_back(k, r, dp_maxx[k]);
            updates.emplace_back(k, r, dp_maxy[k]);
        }

        // no-add, use 1
        updates.emplace_back(p, q, dp_max);
        updates.emplace_back(p, r, dp_max);
        updates.emplace_back(q, r, dp_max);

        for (auto &upd: updates) {
            update(get<0>(upd), get<1>(upd), get<2>(upd));
        }
    }

    li ans = dp_max;
    for (int x = 0; x < n; ++x) {
        for (int y = 0; y < n; ++y) {
            if (x == y && y == xs[3 * n - 1]) {
                ans = max(ans, dp[x][y] + 1);
            }
        }
    }

    cout << ans + offset << endl;
    return 0;
}

Measured memory_bytes: 35412
k, n = map(int, input().split())
a = list(map(int, input().split()))

d = [None] * n
sum = 0
for i in range(n):
    if i == n-1:
        d[n-1] = k - a[n-1] + a[0]
    else:
        d[i] = a[i+1] - a[i]
    sum += d[i]
print(sum - max(d))

Measured memory_bytes: 26436
n = int(input())
dp = [[0]*4 for i in range(n+1)]
mod = 10**9+7

dp[0][0] = dp[0][1] = dp[0][2] = dp[0][3] = 1
dp[1][0] = dp[1][1] = dp[1][2] = dp[1][3] = 4

for i in range(2,n):
    for j in range(4):
        dp[i][j] = sum(dp[i-1])%mod
    dp[i][1] -= dp[i-2][0]
    dp[i][2] -= (dp[i-2][0] + dp[i-2][1])
    if i >= 3:
        dp[i][2] -= 3*dp[i-3][0]
        dp[i][1] += dp[i-3][1]
        

print(sum(dp[n-1])%mod)

Measured memory_bytes: 9180
N, X = map(int, input().split())
A = list(map(int, input().split()))
A.append(X)
A.sort()
distances = {}

for i in range(N):
    dist = A[i+1] - A[i]
    distances[dist] = None

def gcd(x, y):
    while y:
        x, y = y, x % y
    return x

distances = list(distances.keys())
gcd_calc = distances[0]

if N > 1:
    for dist in distances[1:]:
        gcd_calc = gcd(gcd_calc, dist)
        # if gcd_calc == 1:
        #     break

print(gcd_calc)


Measured memory_bytes: 14252
#include <iostream>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
int n, p, a[20010], b[20010];
int main(){
	cin >> n >> p;
	rep(i, n)a[i] = (i + 1) * 30000;
	for (int i = n;i > 0;i--)b[n - i] = i * 30000;
	rep(i, n - 1) {
		cin >> p;
		a[p - 1] += i + 1;
	}
	rep(i, n)cout << a[i] << " ";
	cout << endl;
	rep(i, n)cout << b[i] << " ";
	cout << endl;
	getchar();getchar();
	return 0;
}

Measured memory_bytes: 768
#include<iostream>
using namespace std;
int main()
{
	int X = 0, Y = 0;
	cin >> X >> Y;
	if (Y%2==1||4*X<Y||2*X>Y)
	{
		cout << "No";
	}
	else 
	{
		cout << "Yes";
	}
}

Measured memory_bytes: 3616
/*
	submission # - User: herp_sy
	https://atcoder.jp/contests/

	coding: utf-8
	lang: C++ (GCC 5.4.1)
*/

#include <bits/stdc++.h>
using namespace std;

// utility of stdin,stdout
#define _CRT_SECURE_NO_WARNINGS
#define OUT cout << 
#define BR << endl
#define RET return 0
#define TLong long long
#define TBMod 1000000007

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

	for (int i = 1; i <= n; ++i)
	{
		if((int)((double)i * 1.08) == n){
			OUT(i) BR;
			RET;
		}
	}
	OUT(":(") BR;
	RET;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <string>
#include <utility>
#include <queue>
using namespace std;
typedef long long int ll;

ll count(ll h) {
  if (h <= 1) return 1;
  else return 2 * count(h / 2) + 1;
}

int main() {
  ll H;
  cin >> H;
  cout << count(H) << endl;
  return 0;
}


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


struct Node {int parent,left,right,sib,dep,hei;};
Node a[30];


/*int sib(int x){
    rep(j,n){   //n未定義
    if(a[x].parent==a[j].parent)return j;
    }
}*/
void dep(int i,int p){
    a[i].dep=p;
    if(a[i].left!=-1)dep(a[i].left,p+1);
    if(a[i].right!=-1)dep(a[i].right,p+1);
}
    
int height(int i){
    int h1=0,h2=0;
    if(a[i].left!=-1)
        h1=height(a[i].left)+1;
    if(a[i].right!=-1)
        h2=height(a[i].right)+1;
    
    return a[i].hei=max(h1,h2);
}
void display(int i){
    cout<<"node "<<i<<": parent = "<<a[i].parent<<", sibling = "<<a[i].sib<<", "<<"degree = ";
    if(a[i].left!=-1&&a[i].right!=-1) cout<<2;
    else if(a[i].left!=-1||a[i].right!=-1)cout<<1;
    else cout<<0;
    cout<<", depth = "<<a[i].dep<<", height = "<<a[i].hei<<", ";
    if(a[i].parent==-1) cout<<"root"<<endl;
    else if(a[i].hei==0) cout<<"leaf"<<endl;
    else cout<<"internal node"<<endl;
}
int main(){
    int n;
    cin>>n;
    rep(i,n){
        a[i].parent=-1;
        a[i].sib=-1;
        a[i].left=-1;
        a[i].right=-1;
    }
    rep(i,n){
        int node,l,r;
        cin>>node>>l>>r;
        a[node].left=l;
        a[node].right=r;
        if(l>=0) {
            a[l].parent=node;
            a[l].sib=r;
        }
        if(r>=0) {
            a[r].parent=node;
            a[r].sib=l;
        }
    }
    int root;
    rep(i,n){
        if(a[i].parent==-1){
            root=i;
            break;
        }
    }
    dep(root,0);
    height(root);
    rep(i,n)display(i);

    return 0;

}


Measured memory_bytes: 3092
import java.util.Scanner;


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

Measured memory_bytes: 26208
#include<iostream>
#include<stack>
#include<queue>
#include<map>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define sc(x) scanf("%d",&x);
int n, m;
static const int MAX = 8;
int G[MAX][MAX];

void solve(){
    int res = 0, sub;
    int dp[(1<<n)][n];
    for (int i = 0; i < (1<<n); i++){
        for (int j = 0; j < n; j++){
            if (i == 1 && j == 0) dp[i][j] = 1;
            else dp[i][j] = 0;
        }
    }
    for (int i = 1; i < (1<<n); i++){
        for (int j = 0; j < n; j++){
            if (!(i & (1<<j))) continue;
            sub = i ^ (1<<j);
            for (int k = 0; k < n; k++){
                if (!(sub & (1<<k))) continue;
                if (G[k][j] == 1) dp[i][j] += dp[sub][k];
            }
        }
    }
    for (int i = 0; i < n; i++) res += dp[(1<<n) - 1][i];
    cout << res << endl;
}

int main(){
    sc(n) sc(m)
    int x, y;
    fill((int*)G, (int*)(G + n), 0);
    for (int i = 0; i < m; i++){
        sc(x) sc(y)
        x--; y--;
        G[x][y] = 1;
        G[y][x] = 1;
    }
    solve();
    return 0;
}

Measured memory_bytes: 256
import numpy as np

N,M,X = map(int,input().split())
ca=np.array([0]*(M+1))
ans = 10**7

for i in range(N):
    ca=np.vstack([ca,[int(i) for i in input().split()]])

for i in range(2**N):

    need_skills=np.array([0]+[X]*M)

    buy_item = [0]*N
    for j in range(N):
        if (i>>j)&1:
            buy_item[j]=1

    for k in range(N):
        need_skills -= ca[k+1]*buy_item[k]

    if np.all(need_skills<=0):
        ans = min(ans,-need_skills[0])

print(-1 if ans==10**7 else ans)


Measured memory_bytes: 27380
n, k = map(int, input().split())

snacklist = [0]*n

for num in range(0, k):
    d = input()

    boylist = list(map(int, input().split()))

    for bl in boylist:
        snacklist[bl-1] += 1


count = 0

for sl in snacklist:
    if sl == 0:
        count += 1

print(count)

Measured memory_bytes: 9116
S = input()

k = 'keyence'
if S[:7] == k or S[-7:] == k:
    print('YES')
    exit()
for i in range(len(S)):
    if S[:i] != k[:i]:
        if S[-7+i-1:] == k[-7+i-1:]:
            print('YES')
            exit()
        else:
            print('NO')
            exit()
print('NO')

Measured memory_bytes: 9064
#include <bits/stdc++.h>
#define DIM 3007
#define INF 1000000000000000007LL
using namespace std;

string s,t;
long long d[DIM][DIM];

int main()
{
    cin>>s>>t;
    for(int i = 1; i <= s.size(); ++i)
        for(int j = 1; j <= t.size(); ++j)
            if(s[i-1] == t[j-1]) d[i][j] = d[i-1][j-1]+1;
        else
            d[i][j] = max(d[i-1][j],d[i][j-1]);

    string ans;
    int r1 = s.size(), r2 = t.size();
    while(r1 && r2)
    {
        if(s[r1-1]==t[r2-1])
        {
            ans+=s[r1-1];
            r1--;
            r2--;
        }
        else if(d[r1-1][r2] > d[r1][r2-1])
            r1--;
        else
            r2--;
    }
    reverse(ans.begin(),ans.end());
    cout<<ans;

    return 0;
}


Measured memory_bytes: 70784
#include <iostream>
#include <fstream>
#include <stdio.h>
#include <vector>
#include <string>
#include <math.h>
#include <algorithm>
#include <map>
#include <set>

#define sz(x) ((int)x.size())
#define all(x) (x).begin(), (x).end()
#define pb(x) push_back(x)
#define mp(x, y) make_pair(x, y)

typedef long long int64;

using namespace std;

int main() {
	ios_base::sync_with_stdio(0);
	
	int n, m;
	cin >> n >> m;
	vector<int> ok(n, 0);
	vector<int> wrong(n, 0);
	for (int i = 0; i < m; ++i){
	    int p;
		cin >> p;
		--p;
		string s;
		cin >> s;
		if (s == "AC") {
		    ok[p] = 1;
		} else {
		    if (ok[p] == 0) {
		        ++wrong[p];
     		}
		}
	}
	int oks = 0;
	int penalty = 0;
	for (int i = 0; i < n; ++i) {
	    if (ok[i]) {
		    ++oks;
			penalty += wrong[i];
		}
	}
	cout << oks << " " << penalty << endl;
    return 0;
}


Measured memory_bytes: 1024
#define _USE_MATH_DEFINES
#pragma region include

#include <iostream>
#include <iomanip>
#include <stdio.h>

#include <sstream>
#include <algorithm>
#include <iterator>
#include <cmath>
#include <complex>

#include <string>
#include <cstring>
#include <vector>
#include <bitset>

#include <queue>
#include <set>
#include <map>
#include <stack>
#include <list>

#include <ctime>
////
//#include <random>//
#pragma endregion //#include
/////////

#pragma region typedef
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
#pragma endregion //typedef
////定数
const int INF = (int)1e9 + 10;
const LL MOD = (LL)1e9 + 7;
const LL LINF = (LL)4e18 + 20;
const LD PI = acos(-1.0);
const double EPS = 1e-9; 
/////////
using namespace::std;
//////////////

void solve() {
	int N;
	cin >> N;
	vector<int> T(N), X(N), Y(N);
	for (int i = 0; i < N; ++i) {
		cin >> T[i] >> X[i] >> Y[i];
	}
	int t = 0;
	int x = 0;
	int y = 0;
	bool ans = true;
	for (int i = 0; i < N; ++i) {
		int time = 0;
		int len = 0;
		time += abs(T[i] - t);
		len += abs(X[i] - x);
		len += abs(Y[i] - y);
		if (len > time) {//時間足りない
			ans = false;
			break;
		}
		int nokori = len - time;
		if (nokori & 1) {//往復で時間つぶし出来ない
			ans = false;
			break;
		}
		t = T[i];
		x = X[i];
		y = Y[i];
	}
	
	if (ans) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}

#pragma region main
signed main(void) {
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	std::cout << std::fixed;//小数を10進数表示
	cout << setprecision(16);//小数点以下の桁数を指定//coutとcerrで別	

	solve();
}
#pragma endregion //main()


Measured memory_bytes: 1408
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define vec vector
#define fi first
#define se second
#define eb emplace_back
#define ef emplace_front
#define pof pop_front()
#define pob pop_back()
#define Rep(i,n) for(li i=0,nn=(li)(n);i!=nn;++i)
#define Rep1(i,n) for(li i=1,nn=(li)(n)+1;i!=nn;++i)
#define Size(v) (li)(v.size())
#define SortA(v) sort(v.begin(),v.end())
#define SortD(v) sort(v.rbegin(),v.rend())
#define All(a) (a).begin(),(a).end()
#define Input(a) for(li ii=0,nn=(li)(a.size());ii!=nn;++ii){cin>>(a).at(ii);}
#define Input2(a,b) for(li ii=0,nn=(li)(a.size());ii!=nn;++ii){cin>>(a).at(ii)>>(b).at(ii);}
#define mp make_pair
using li = int64_t;
using intl = int64_t;
using vi = vec<li>;
using vb = vec<bool>;
using vvi = vec<vi>;
using qi = deque<li>;
using pi = pair<li, li>;
using vpi = vec<pi>;
using si = set<li>;
using vsi = vec<si>;
using mii = map<li, li>;
using vmii = vec<mii>;
vec<li> dx = {0, 1, 0, -1, 1, 1, -1, -1};
vec<li> dy = {1, 0, -1, 0, 1, -1, 1, -1};
constexpr li INF = LLONG_MAX;
constexpr li mod = 1000000007;

void Yes(li b) {
	if (b)cout << "Yes";


	else cout << "No";
}
void yes(li b) {
	if (b)cout << "yes";
	else cout << "no";
}

int main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	cout.precision(16);

	li N,M;
	  cin >>N>>M;
  if(M==0){cout << 1;return 0;}
  si unoperated;
  Rep1(i,N){
    unoperated.emplace(i);
  }
  
  vsi friends(N+1);
  intl A,B;
  Rep(i,M){
    cin >>A>>B;
    friends[A].insert(B);
    friends[B].insert(A);
  }
  
  vi fnum(N+1);
  Rep1(i,N){
    fnum[i] = friends[i].size();
  }

  li maxi=0;
  
  vi island(N+1,0);
  vi inum(N+1,0);
  intl n;
  intl j=0;
  while(!unoperated.empty()){
    ++j;
    n = *unoperated.begin();
    unoperated.erase(n);
    inum[n] = j;
    ++island[j];
    
    deque<int> next;
    next.eb(n);
    while(!next.empty()){
      n = next.front();
      next.pop_front();
      for(auto&& f :friends[n]){
        if(inum[f]==0){
          inum[f] = j;
          next.eb(f);
          ++island[j];
          unoperated.erase(f);
        }
      }
    }

    maxi =max(maxi,island[j]);
    
  }

  cout <<maxi;

   

}

Measured memory_bytes: 45552
#include "bits/stdc++.h"

using namespace std;

using ll = long long;
using ld = long double;
using P = pair<int, int>;
constexpr ld EPS = 1e-12;
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr int MOD = 1e9 + 7;

template <typename T>
void printv(const vector<T> &v)
{
    int sz = v.size();
    for (int i = 0; i < sz; i++)
    {
        cout << v[i] << " \n"[i == sz - 1];
    }
}

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

    string s;cin>>s;
    int n = s.size();
    ll ret = 0;
    ll cnt = 0;
    for(int i=0;i<=n-2;i++)
    {
        if(s[i]=='A') cnt++;
        else if(s.substr(i,2)=="BC")
        {
            ret += cnt;
            i++;
        }
        else
        {
            cnt = 0;
        }
    }
    cout << ret << endl;
}


Measured memory_bytes: 720
#include<iostream>
using namespace std;
const int P = 1e9 + 7;
int qp(int a,int b) {int r = 1; while(b) {if(b & 1) r = 1ll * r * a % P; a = 1ll * a * a % P; b >>= 1;} return r;}
int n;
int main()
{
    cin >> n;
    int ans = qp(10, n), k;
    k = 2ll * qp(9, n) % P;
    ans = (ans - k + P) % P;
    k = qp(8, n);
    ans = (ans + k) % P;
    cout << ans;
}

Measured memory_bytes: 3628
#include<iostream>
#include<cstring>
using namespace std;
const int MAX=200002;
char bit[MAX];
int main(){
    cin>>bit;
    int len=strlen(bit);
    int sum=0;
    for(int i=0;i<len;i++)
    {
        sum+=bit[i]-'0';
    }
    if(sum%9)
    {
        cout<<"No";
    }
    else
    {
        cout<<"Yes";
        /* code */
    }
    
    //system("pause");
}

Measured memory_bytes: 3724
# ABC75, B - minesweeper
h, w = [int(el) for el in input().split(' ')]
S = [list(input()) for i in range(h)]

dx = [0, 1, 1, 1, 0, -1, -1, -1]
dy = [1, 1, 0, -1, -1, -1, 0, 1]



for i in range(h):
    for j in range(w):
        if S[i][j] == '.':
            count = 0
            for k in range(8):
                nx = j + dx[k]
                ny = i + dy[k]
                if (0 <= nx < w) and (0 <= ny < h):
                    if S[ny][nx] == '#':
                        count += 1
            S[i][j] = str(count)



[print(''.join(S[i])) for i in range(h)]


Measured memory_bytes: 3188
S = input()
if len(S) != 26:
    for i in range(26):
        if chr(ord('a') + i) not in S:
            print(S + chr(ord('a') + i))
            break
elif S == 'zyxwvutsrqponmlkjihgfedcba':
    print(-1)
else:
    can = []
    for i in range(26):
        if len(can) >= 1 and can[-1] > ord(S[-1-i]):
            for s in can:
                if s > ord(S[-1-i]):
                    print(S[:-1-i] + chr(s))
                    exit(0)
        can.append(ord(S[-1-i]))


Measured memory_bytes: 3064
import sys

read = sys.stdin.buffer.read


def main():
    N, M, Q, *LRPQ = map(int, read().split())
    LR = LRPQ[: 2 * M]
    PQ = LRPQ[2 * M :]

    A = [[0] * (N + 1) for _ in range(N + 1)]
    for l, r in zip(LR[::2], LR[1::2]):
        A[l][r] += 1

    for i in range(N):
        for j in range(N):
            A[i + 1][j + 1] += A[i][j + 1] + A[i + 1][j] - A[i][j]

    ans = []
    for p, q in zip(PQ[::2], PQ[1::2]):
        ans.append(A[q][q] - A[q][p - 1] - A[p - 1][q] + A[p - 1][p - 1])

    print('\n'.join(map(str, ans)))
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 48548
#include <algorithm>
#include <climits>
#include <iostream>
#include <string>
#include <utility>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <iomanip>
#include <cmath>
#include <stack>

using namespace std;
using ll = long long int;

template <class T> ostream &operator<<(ostream &os, vector<T> &v) {
  for (auto i = v.begin(); i != v.end(); i++) {
    os << *i << " ";
  }
  return os;
}


void solve(std::string A){
  ll x = 0;
  ll len = A.size();
  for(ll i=0; i<26; i++) {
    ll cnt = 0;
    for(auto c : A) {
      if(c == 'a'+i)
	cnt++;
    }
    x += cnt*(cnt-1) / 2;
  }
  std::cout << (len * (len-1))/2 - x + 1<< std::endl;
}

int main(){
  std::string A;
  std::cin >> A;
  solve(A);
  return 0;
}



Measured memory_bytes: 772
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define f(i, x, n) for (int i = x; i < (int)(n); ++i)

int const N = 1500, md = 998244353;
char g[N][N + 1];
int an = 1;
vector<int> ga[N >> 1];

void ad(int x) { f(i, 0, x)an = (ll)an * 2 % md; }

void up(char &a, char b){
	if (a == '?')a = b;
	else if (b != '?' && a != b)an = 0;
}

void up(int a, int b, int c, int d) { up(g[a][b], g[c][d]); }

char gt(pair<int, int> const &p) { return g[p.first][p.second]; }

void flp(char &c){
	if (c == 'o')c = 'x';
	else if (c == 'x')c = 'o';
}

void ad(auto v, int n){
	if (n & 1){
		int s = 0;
		for (auto &u: v)if (gt(u) == '?')++s;
		ad(s);
		return;
	}
	int mx = 0;
	for (auto &u: v)mx = max(mx, u.first + u.second);
	vector<pair<char, int> > z;
	for (auto &u: v)if (u.first + u.second == mx)z.emplace_back(gt(u), u.second - u.first >> 1);
	sort(z.begin(), z.end());
	reverse(z.begin(), z.end());
	vector<int> p(z.size());
	f(i, 0, z.size())p[z[i].second] = i;
	f(i, 0, z.size())ga[i].clear();
	int sm = 0;
	for (auto &u: v)if (u.first + u.second < mx){
		int a = p[u.second - u.first >> 1], b = p[u.first + u.second >> 1];
		if (a > b)swap(a, b);
		if (gt(u) == '?')ga[a].push_back(b), ++sm;
		else if (gt(u) == 'o'){
			flp(z[a].first);
			flp(z[b].first);
		}
	}
	f(i, 0, z.size())if (!ga[i].empty()){
		int t = ga[i][0];
		while (ga[i].size() > 1){
			int k = ga[i].back();
			ga[i].pop_back();
			if (k == t)continue;
			int kk = t;
			if (k > kk)swap(k, kk);
			ga[k].push_back(kk);
		}
	}
	f(i, 0, z.size())if (!ga[i].empty()){
		if (z[i].first == 'o')flp(z[ga[i][0]].first);
		else if (z[i].first == '?')ad(1);
		--sm;
	}else if (z[i].first == 'o')an = 0;
	ad(sm);
}

int main(){
	int n;
	scanf("%d", &n);
	f(i, 1, n)scanf("%s", g[i] + 1);
	vector<pair<int, int> > v;
	f(j, 1, (n >> 1) + 1)f(i, 1, j + 1){
		v.emplace_back(i, j);
		if (j != n - j)v.emplace_back(i, n - j);
	}
	f(k, 0, v.size()){
		int i = v[k].first, j = v[k].second;
		up(i, j, j, i);
		up(i, j, n - i, n - j);
		up(i, j, n - j, n - i);
	}
	vector<pair<int, int> > l, r;
	for (auto &u: v)if (u.first + u.second & 1)r.emplace_back(u); else l.emplace_back(u);
	ad(l, n >> 1);
	ad(r, n - 1 - (n >> 1));
	printf("%d\n", an);
}

Measured memory_bytes: 93416
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>

#define int long long
#define MOD7 1000000007
#define MOD9 1000000009

#define rep(i, n) for (int i = 0; i < (n); i++)
#define itrep(i, a) for (auto i = (a).begin(); i != (a).end(); i++)
#define REP(i, a, n) for (int i = (a); i <= (n); i++)
#define all(a) (a).begin(), (a).end()
#define mp(a, b) make_pair((a), (b))

using namespace std;

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

template<class T> void inputVector(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < v.size(); i++) cin >> v[i];
}

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

	vector<int> a;
	inputVector(a, N);

	sort(all(a));

	int ret = a[0];
	double big = a.back();
	rep(i, N) {
		if (abs(big / 2 - ret) > abs(big / 2 - a[i])) {
			ret = a[i];
		}
	}

	cout << a.back() << " " << ret << endl;

    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
using ll = long long;
using P = pair<int,int>;
template <class T> void chmin(T &a, const T &b) noexcept { if (b < a) a = b; }
template <class T> void chmax(T &a, const T &b) noexcept { if (a < b) a = b; }
void debug_out() { cout << "\n"; }
template <class T, class... Args>
void debug_out(const T &x, const Args &... args) { cout << x << " "; debug_out(args...);}
#ifdef _DEBUG
  #define debug(...) debug_out(__VA_ARGS__)
#else
  #define debug(...) 
#endif

const int mod = 1000000007;
// const int mod = 998244353;
struct mint {
  ll x;
  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;}
  bool operator==(const mint rhs) const { return x == rhs.x; }
  bool operator!=(const mint rhs) const { return x != rhs.x; }
};
istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}


int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  vector<ll> cnt(n,0); //登場回数
  mint ans = 1;
  rep(i,n) {
    if (a[i] > 0) ans *= cnt[a[i]-1] - cnt[a[i]]; 
    else ans *= 3 - cnt[a[i]];
    cnt[a[i]]++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
//BEGIN CUT HERE
const Int MOD=1e9+9; //<- alert!!!
typedef vector<Int> arr;
typedef vector<arr> mat;
arr mul(const mat &a,arr& b,Int mod){
  arr res(b.size(),0);
  for(int i=0;i<(int)b.size();i++)
    for(int j=0;j<(int)a[i].size();j++)
      (res[i]+=a[i][j]*b[j])%=mod;
  return res;
}
mat mul(const mat& a,const mat& b,Int mod){
  mat res(a.size(),arr(b[0].size(),0));
  for(int i=0;i<(int)a.size();i++)
    for(int j=0;j<(int)b[0].size();j++)
      for(int k=0;k<(int)b.size();k++)
	(res[i][j]+=a[i][k]*b[k][j])%=mod;
  return res;
}
mat mat_pow(mat a,Int n,Int mod){
  mat res(a);
  for(int i=0;i<(int)a.size();i++)
    for(int j=0;j<(int)a[i].size();j++)
      res[i][j]=(i==j);
  while(n){
    if(n&1) res=mul(a,res,mod);
    a=mul(a,a,mod);
    n>>=1;
  }
  return res;
}
//END CUT HERE
mat base;
mat memo[100];
void init(mat a,Int mod){
  base=mat(a);
  for(int i=0;i<(int)base.size();i++)
    for(int j=0;j<(int)base.size();j++)
      base[i][j]=i==j;
  memo[0]=a;
  for(int k=1;k<70;k++)
    memo[k]=mul(memo[k-1],memo[k-1],mod);
}
inline mat mat_pow2(Int n,Int mod){
  mat res(base);
  int k=0;
  while(n){
    if(n&1) res=mul(memo[k],res,mod);
    n>>=1;
    k++;
  }
  return res;
}

typedef pair<Int,Int> P;
signed main(){
  Int w,h,n,cnt=0;
  while(cin>>w>>h>>n,w||h||n){
    Int x[n],y[n];
    for(Int i=0;i<n;i++) cin>>x[i]>>y[i];
    P p[n];
    for(Int i=0;i<n;i++) p[i]=P(y[i],x[i]);
    sort(p,p+n);
    for(Int i=0;i<n;i++) x[i]=p[i].second,y[i]=p[i].first;
    arr a(w,0);
    a[0]=1;
    mat b(w,arr(w,0));
    for(Int i=0;i<w;i++){
      for(Int j=0;j<w;j++) b[i][j]=0;
      b[i][i]=1;
      if(i-1>=0) b[i][i-1]=1;
      if(i+1<w)  b[i][i+1]=1;
    }
    init(b,MOD);
    Int d=1;
    for(Int k=0;k<n;k++){
      if(y[k]==d) continue;
      a=mul(mat_pow2(y[k]-d-1,MOD),a,MOD);
      Int j=k;
      mat c=b;
      while(j<n&&y[k]==y[j]){
	for(Int i=0;i<w;i++) c[x[j]-1][i]=0;
	j++;
      }
      a=mul(c,a,MOD);
      d=y[k];
    }
    a=mul(mat_pow2(h-d,MOD),a,MOD);
    cout<<"Case "<<++cnt<<": "<<a[w-1]<<endl;
  }
  return 0;
}

/*
  verified on 2018/01/17
  http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2397
*/



Measured memory_bytes: 6376
// 標準入力から一行を読み取り、指定の型に変換する
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

// 標準入力から一行を読み取り、空白文字で分割し、各要素を指定の型に変換する関数
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect()
}

fn main() {
    let n: usize = read();
    let a: Vec<u64> = read_vec();

    // 対象の数を決める。1から見つかる度にインクリメント。
    let mut search_number = 1_u64;
    let mut break_count = 0;

    for i in 0..n
    {
        // 対象の数である場合
        if a[i] == search_number
        {
            // このレンガは砕かなくて良い
            search_number += 1;
            continue;
        }

        break_count += 1;
    }

    if search_number == 1 { println!("-1"); }
    else { println!("{}", break_count); }
}


Measured memory_bytes: 10492
#include <iostream>
#include <map>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;

int main(void) {
  ios::sync_with_stdio(false);
  map<string, int> cards;
  int N;
  cin >> N;
  rep(i, N) {
    string s;
    cin >> s;
    cards[s]++;
  }

  int M;
  cin >> M;
  rep(i, M) {
    string t;
    cin >> t;
    cards[t]--;
  }

  int answer = 0;
  for (auto card : cards) {
    answer = max(answer, card.second);
  }
  cout << answer << endl;
  return 0;
}

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

using namespace std;
typedef long long ll;

int main()
{
    ll N;
    char alph[] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l',
                    'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};
    char ans[1000] = {0};

    cin >> N;
    N = N - 1;
    int c = 0;
    while (N >= 26) {
        int x = N % 26;
        ans[c] = alph[x];
        N = N / 26 - 1;
        c++;
    }
    ans[c] = alph[N];
    c++;

    for (int i = c - 1; i >= 0; i--) {
        printf("%c", ans[i]);
    }
    puts("");

    return 0;
}

Measured memory_bytes: 3648
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <sstream>
#include <stdio.h>

using namespace std;

int main(void) {
    int N;
    cin >> N;
    vector<int> A(N, 0);

    for (int i = 0; i < N; i++) scanf("%d", &A[i]);

    for (int i = 0; i < N; ++i) {
        auto v = A[i];
        int j = i - 1;
        while(j >= 0 && v < A[j]) {
            A[j + 1] = A[j];
            --j;
        }
        A[j + 1] = v;
        ostringstream os;
        for_each(A.begin(), A.end() - 1,
                 [&os](const int& e){
                     os << e << " ";
                 });
        os << *(A.end() - 1);
        cout << os.str() << endl;
    }
    return 0;
}



Measured memory_bytes: 3252
#include<bits/stdc++.h>
#define fori(j,n) for(ll i=j;i<n;i++)
#define forb(n,j) for(ll i=n-1;i>=0;i--)
#define endl "\n"
#define pb push_back
#define ll long long
#define mp make_pair
#define ff first
#define ss second
#define vec vector<ll>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

using namespace std;

void wldd()
{
	string s;
	cin >> s;
	ll ans = 0 ;
	fori(0, s.size())
	{
		ans += (s[i] - '0');
	}
	if (ans % 9 == 0)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}
int32_t main()
{
	IOS;
	/*ll t;
	cin >> t;
	while (t--)*/ wldd();
	return 0;
}

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

int main() {
  int n,m;
  cin >> n >> m;
  int a[101],b[101];
  for(int i=0;i<m;i++) cin >> a[i] >> b[i];
  
  int  bmin=0,bmax=0,ans=0;
  while(bmax != n) {
    ans++;
    if(ans > m) break;
    bmax=0;
    for(int i=0;i<m;i++) 
      if(bmin+1 >= a[i] && b[i] > bmax) bmax = b[i];
    if(bmin == bmax) ans = m+1;    
    //  cout <<"bmin="<< bmin <<" bmax="<<bmax<< endl;
    bmin = bmax;
  }

  if(ans > m) cout <<"Impossible"<<endl;
  else cout << ans << endl;

  return 0;
}
	

Measured memory_bytes: 1164
n=int(input())
a=list(map(int,input().split()))
flg=0
l=[]
m,k=1000,0
for i in range(n-1):
    if flg==0:
        if a[i+1]>a[i]:
            l.append((flg,i))
            flg=1
    else:
        if a[i+1]<a[i]:
            l.append((flg,i))
            flg=0
if a[n-1]>=a[n-2]:
    l.append((1,n-1))
for flg,i in l:
    if flg==0:
        k+=m//a[i]
        m-=(m//a[i])*a[i]
    else:
        m+=k*a[i]
        k=0
print(m)

Measured memory_bytes: 9260
//
//  main.cpp
//  1_4
//
//  Created by Keita on 2020/03/11.
//  Copyright © 2020 Keita. All rights reserved.
//

#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cstring>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_map>
#include <map>
using namespace std ;

void doProblemA(){
    string S;
    cin >> S;
    if(S == "SSS"){
        cout << 0 << endl;
    }else if(S == "SSR" or S == "SRS" or S == "RSS" or S == "RSR"){
        cout << 1 << endl;
    }else if(S == "SRR" or S == "RRS"){
        cout << 2 << endl;
    }else{
        cout << 3<< endl;
    }
}

int main(int argc, const char * argv[]){
    // insert code here...
    doProblemA();
    return 0;
}



Measured memory_bytes: 3228
#encoding: utf-8

N, M = map(int, input().split())

foods = [0] * M
ans = 0

for i in range(N):
    a = list(map(int, input().split()))
    for j in range(1, len(a)):
        foods[a[j] - 1] += 1
        if foods[a[j] - 1] == N:
            ans += 1

print(ans)

Measured memory_bytes: 3060
#include<iostream>

using namespace std;

int main(){
	long n,k;
	cin>>n>>k;
	if(n%k==0){
		cout<<0<<endl;
		
	}
	else{
		long m=n/k, minNum;
		minNum = min(abs(n-m*k), abs(n - (m+1)*k));
		cout<<minNum<<endl;
	}
	return 0; 
}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    val n = readLine()?.toInt() ?: 0
    val input = readLine() ?: ""
    val input_list = input.split(" ")
        .map(String::toInt) 
    val asc_list = (1..n).toList()

    var count = 0
    input_list.zip(asc_list)
        .forEach {
            when (it.first == it.second) {
                true -> {}
                false -> count++
            }
        }
    when (count > 2 ) {
        true -> println( "NO" )
        false -> println( "YES" )
    }
}

Measured memory_bytes: 37864
#include<bits/stdc++.h>
using namespace std;
const int N=410;
const int mod=998244353;
typedef vector<int> vi;
typedef pair<vi,vi> pvv;
#define pb push_back
#define sz(a) int(a.size())
#define fi first
#define se second

int n,h[N],pw[N];

pvv operator*(const pvv &a,const pvv &b) {
	pvv ret;int n=sz(a.fi)-1,m=sz(b.fi)-1;
	ret.fi.resize(n+m+1);ret.se.resize(n+m+1);
	for(int i=0;i<=n;i++)
		for(int j=0;j<=m;j++) {
			ret.fi[i+j]=(ret.fi[i+j]+1ll*a.fi[i]*b.fi[j]+1ll*a.fi[i]*b.se[j]+1ll*a.se[i]*b.fi[j])%mod;
			ret.se[i+j]=(ret.se[i+j]+1ll*a.se[i]*b.se[j])%mod;
		}
	return ret;
}

pvv add(const pvv &a) {
	int n=sz(a.fi)-1;
	pvv ret;ret.fi.resize(n+1);ret.se.resize(n+1);
	for(int i=0;i<=n;i++) {
		ret.se[i]=(1ll*a.se[i]*(pw[n-i]-1)%mod+a.fi[i]+a.se[i])%mod;
		ret.fi[i]=(1ll*a.fi[i]*(pw[n-i]-1))%mod;
	}
	return ret;
}

void upd(pvv &ret,pvv v) {
	if(ret.fi.empty()) ret=v; else ret=ret*v;
}

pvv dp(int l,int r,int k) {
	if(l==r&&k>h[l]) {
		pvv ret;ret.fi.resize(2);ret.se.resize(2);
		ret.fi[1]=1;ret.se[0]=1;return ret;
	}
	int t=*min_element(h+l,h+r+1);
	if(t<k) {
		pvv ret;int lst=l;
		for(int i=l;i<=r;i++)
			if(h[i]<k) {
				if(lst<=i-1) upd(ret,dp(lst,i-1,k));
				upd(ret,dp(i,i,k));lst=i+1;
			}
		if(lst<=r) upd(ret,dp(lst,r,k));
		return ret;
	}
	return add(dp(l,r,k+1));
}

int main() {
	cin>>n;pw[0]=1;for(int i=1;i<=n;i++) cin>>h[i],pw[i]=2ll*pw[i-1]%mod;
	pvv ret=dp(1,n,1);int ans=0;
	for(int i=0;i<=n;i++) ans=(ans+1ll*((i&1)?mod-1:1)*ret.se[i])%mod;
	cout<<ans;
	return 0;
}


Measured memory_bytes: 512
#include <iostream>
#define NMAX 1002
using namespace std;
int main(){
	int N,A[NMAX];
	bool answer = true;
	cin >> N;
	for (int i = 0; i < N; ++i)
	{
		cin >> A[i];
		if(A[i]%2 == 0){
			if(A[i]%3 != 0 && A[i]%5 != 0){
				answer = false;
			}
		}
	}

	if(answer){ 
		cout << "APPROVED\n";
	}else{
		cout << "DENIED\n";
	}

	return 0;
}

Measured memory_bytes: 256
// finish date: 2018/07/14
#include <bits/stdc++.h>

using namespace std;

#define FOR(i, a, b) for(int (i)=a;(i)<(b);(i)++)
#define rep(i, n)  FOR(i,0,n)
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>>
        vvvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<double> vd;
typedef vector<vector<double>> vvd;
typedef vector<vector<vector<double>>>
        vvvd;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<string> vs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, pair<int, int>> plii;
const int bigmod = 1000000007;
const int INF = 1050000000;
const long long INFll = 100000000000000000;


int main() {
    int N;
    string S;
    cin >> N >> S;
    ll ans = 0;

    map<pair<string, string>, int> que;
    string S1, S2;
    rep(k, 1 << N) {
        S1 = "";
        S2 = "";
        rep(i, N) {
            if (k & (1 << i)) S1 += S[i + N];
            else S2 += S[i + N];
        }
        que[make_pair(S1, S2)]++;
    }


    rep(k, 1 << N) {
        S1 = "";
        S2 = "";
        rep(i, N) {
            if (k & (1 << i)) S1 = S[i] + S1;
            else S2 = S[i] + S2;
        }
        ans += que[make_pair(S2, S1)];
    }

    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 87040