akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(int)(n); i++)

using namespace std;
using LL = long long;
using P = pair<int,int>;

int main(){
	int N, K;
	cin >> N >> K;
	LL div=N/K;
	LL ans=div*div*div;
	if(K%2==1){
		cout << ans << endl;
		return 0;
	}
	LL div2=div+1;
	if(div*K+K/2>N) div2--;
	ans+=div2*div2*div2;
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
n = int(input())
name = [0]*5
for i in range(n):
    s = input()
    if s[0] == 'M':
        name[0] += 1
    elif s[0] == 'A':
        name[1] += 1
    elif s[0] == 'R':
        name[2] += 1
    elif s[0] == 'C':
        name[3] += 1
    elif s[0] == 'H':
        name[4] += 1

lst = []
for i in range(2**5):
    s = format(i,'b').rjust(5,'0')
    if s.count('1') == 3:
        lst.append(s)

ans = 0
for l in lst:
    c = 1
    for i in range(5):
        if l[i] == '1':
            c *= name[i]
    ans += c
print(ans)


Measured memory_bytes: 3188
import sys
import itertools

def warshall_floyd(d, n):
    #d[i][j]: iからjへの最短距離
    for k in range(n):
        for i in range(n):
            for j in range(n):
                d[i][j] = min(d[i][j],d[i][k] + d[k][j])
    return d

N, M, R = map(int, sys.stdin.readline().split())
r = list(map(int, sys.stdin.readline().split()))

# 全点間の距離
d = [[float("inf")]*N for i in range(N)] 
for _ in range(M):
	a, b, c = map(int, sys.stdin.readline().split())
	d[a-1][b-1] = c
	d[b-1][a-1] = c

d = warshall_floyd(d, N)
# print(d)

# 探索順の全組み合わせを試して、最小を見つける
ans = float("inf")
for comb in itertools.permutations(r):
	dist = 0
	for i in range(R-1):
		dist += d[comb[i]-1][comb[i+1]-1]
	ans = min(ans, dist)

print(ans)

Measured memory_bytes: 74972
#include<iostream>
#include<algorithm>
#include<math.h>
#include<cstdio>
#include<ctype.h>
#include<stdio.h>
#include<set>
#include<vector>
#include<map>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<numeric>
#include<string>
typedef long long ll;
using namespace std;
 
ll gcd(ll a, ll b){
if(a<b){return gcd(b,a);}
else if(a%b){return gcd(b,a%b);}
else{return b;}
}
int main(){
ll a,b,c;
cin>>a>>b>>c;
ll ans = 0;
    if(a==b&&b==c&&a%2==0){
    cout<<-1<<endl; return 0;
    }
    while(gcd((a,b),c)%2!=1){
  ans++;
  int x=(b+c)/2,y=(c+a)/2,z=(a+b)/2;
  a=x,b=y,c=z;
    }
cout<<ans<<endl;

}

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

int main(){
    int n,check;
    long a[100005]={};
    int cnt1=0,cnt2=0; 
    cin>>n;
    for(int i=0; i<n; i++){
        cin>>a[i];
        if(a[i]%4==0)
            cnt1++;
        else if(a[i]%2==0)
            cnt2++;
    }
    if(cnt2>=2){
        cnt1+=cnt2/2;
        n-=cnt2/2;
    }
    if(cnt1==0){
        cout<<"No"<<endl;
    }else if((n-cnt1)%2==0){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const ll INF = 1e18;
const ll MOD = 1e9 + 7;
const double EPS = 1e-8;

template<typename T> T chmax(T& a, const T& b){return a = (a > b ? a : b);}
template<typename T> T chmin(T& a, const T& b){return a = (a < b ? a : b);}

template <typename T, typename U> T pow_fast(T x, U n) {
    T ret = (T)1;
    while(n) {
        if(n & (U)1) ret *= x;
        x *= x;
        n >>= 1;
    }
    return ret;
}

template <typename ModType, ModType MOD> struct ModInt {
    ModType val;
    ModInt() : val(0) {}
    ModInt(ModType x) : val(x % MOD) {
        if(val < 0) val += MOD;
    };
    operator ModType() const { return val; }
    ModInt &operator+=(const ModInt &m) {
        val += m.val;
        if(val >= MOD) val -= MOD;
        return *this;
    }
    ModInt &operator-=(const ModInt &m) {
        val -= m.val;
        if(val < 0) val += MOD;
        return *this;
    }
    ModInt &operator*=(const ModInt &m) {
        (val *= m.val) %= MOD;
        return *this;
    }
    ModInt &operator/=(const ModInt &m) {
        *this *= m.inverse();
        return *this;
    }
    ModInt operator+(const ModInt &m) const { return ModInt(*this) += m; }
    ModInt operator-(const ModInt &m) const { return ModInt(*this) -= m; }
    ModInt operator*(const ModInt &m) const { return ModInt(*this) *= m; }
    ModInt operator/(const ModInt &m) const { return ModInt(*this) /= m; }
    ModInt inverse() const { return pow_fast(*this, MOD - 2); }
    ModInt pow(ModType n) const {return pow_fast(*this, n); }

    friend std::ostream &operator<<(std::ostream &os, const ModInt &rhs) {
        os << rhs.val;
        return os;
    }
    friend std::istream &operator>>(std::istream &is, ModInt &rhs) {
        ModType value;
        is >> value;
        rhs = ModInt(value);
        return is;
    }
};

using mint = ModInt<ll, MOD>;

mint c(int n, int r) {
    mint ret = 1;
    rep(i, r) {
        ret *= mint(n - i);
        ret /= mint(i+1);
    }
    return ret;
}


int main(){
    int n, a, b;
    cin >> n >> a >> b;
    mint all = mint(2).pow(n);
    all -= c(n, a);
    all -= c(n, b);
    cout << all - mint(1) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <fstream>
#include <stdio.h>
#include <math.h>
#include <time.h>
#include <string>
#include <tuple>
#include <vector>
#include <map>
#include <unordered_map>
#include <list>
#include <set>
#include <stack>
#include <queue>
#include <cstdlib>
#include <algorithm>
#include <random>
#include <cassert>
using namespace std;
#define LL long long
#define MP(a, b) make_pair(a, b)
#define POWER9 1000000000
#define MOD POWER9+7
#undef INT_MIN
#undef INT_MAX
#define INT_MIN -2147483647
#define INT_MAX 2147483647
#define LL_MIN (LL)-9223372036854775807
#define LL_MAX (LL)9223372036854775807
#define PI 3.14159265359

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

	int N;
	cin >> N;
	int X[200000];
	vector<int> sorted;
	for(int i=0; i<N; i++){
		cin >> X[i];
		sorted.push_back(X[i]);
	}
	sort(sorted.begin(), sorted.end());
	for(int i=0; i<N; i++){
		if(X[i] <= sorted[N/2-1]) cout << sorted[N/2] << endl;
		else cout << sorted[N/2-1] << endl;
	}

	return 0;
}



Measured memory_bytes: 3956
def main():
    n, m = map(int, input().split())
    ans_dict = dict() # {問題i : [ACしたかどうか、ACに関係なく累計WA数]}

    for _ in range(m):
        p, s = input().split()

        if p not in ans_dict: # 初見の場合
            if s == "AC": # 正解
                ans_dict[p] = [1, 0]
            else: # 不正解
                ans_dict[p] = [0, 1]
        else: # 初見じゃない場合
            if ans_dict[p][0] == 1: # 正解済み
                continue
            else: # 未正解
                if s == "AC":
                    ans_dict[p][0] = 1
                else:
                    ans_dict[p][1] += 1

    ac_count = 0
    wa_count = 0
    for item in ans_dict.items():
        if item[1][0] == 1: # 正解済み
            ac_count += 1
            wa_count += item[1][1]

    print(ac_count, wa_count)


if __name__ == "__main__":
    main()


Measured memory_bytes: 103328
#include <bits/stdc++.h>
#define REP(i, m, n) for(int (i) = (m); (i) < (n); ++i)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
using namespace std;
using Graph = vector<vector<int>>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
const int MOD = 1e9+7;
const int INF = 1<<30;
const ll LINF = 1LL<<60;


int main()
{
    cin.tie(0);
    ios_base::sync_with_stdio(0);
    int n;
    cin >> n;
    vector<long double> a(n);
    rep(i, n) {
        cin >> a[i];
        if (a[i] == 0) {
            cout << 0 << endl;
            return 0;
        }
    }

    long double res = 1;
    rep(i, n) {
        if (res * a[i] > pow(10, 18)) {
            cout << -1 << endl;
            return 0;
        }
        res *= a[i];
    }

    cout << (ll)res << endl;

    return 0;
}

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

int main(){
  int n;
  while(cin >> n, n){
    vector<string> name(n);
    int scene[50][50] = {};
    int point[50] = {};

    for(int i=0;i<n;i++){
      int m,d;
      cin >> name[i] >> m;
      for(int j=0;j<m;j++){
	cin >> d;
	scene[i][d]++;
      }
    }

    for(int i=0;i<=30;i++){
      int sum = 0;
      for(int j=0;j<n;j++)sum += scene[j][i];
      for(int j=0;j<n;j++)point[j] += scene[j][i] * (n+1-sum);
    }

    int id = 0, minp = point[0];
    for(int i=0;i<n;i++){
      if(minp > point[i]){
	id = i; minp = point[i];
      }else if(minp == point[i] && name[id] > name[i]){
	id = i;
      }
    }
    cout << minp << " " << name[id] << endl;
  }
}

Measured memory_bytes: 1236
L, R = list(map(int,input().split()))
if R - L >= 690:
    ans = 0
else:
    ans = 10 ** 9 + 7
    for i in range(L, R + 1):
        for j in range(i + 1, R + 1):
            ans = min(ans, (i * j) % 2019)
print(ans)

Measured memory_bytes: 39024
#include <iostream>
#include <algorithm>
#include <cmath>
#include <set>
#include <vector>
#include <map>
#include <sstream>
using namespace std;

void solve() {
	int MOD = 998244353;
	int n, k;
	cin >> n >> k;
	vector<pair<int, int>> v;
	for(int i = 0; i < k ; i++) {
		int a, b;
		cin >> a >> b;
		v.push_back({a, b});
	}
	int dp[n + 1];
	dp[1] = 1;
	for(int i = 2; i <= n; i++) {
		dp[i] = 0;
	}
	map<int, int> add;
	map<int, int> rem;
	sort(v.begin(), v.end());
	int cur = 0;
	for(int i = 1; i < n; i++) {
		if(add[i] > 0) {
			cur = ((cur % MOD) + (add[i] % MOD)) % MOD;
		}
		if(i > 1) dp[i] = cur;
		if(dp[i] <= 0) continue;
		for(int j = 0; j < k; j++) {
			if(i + v[j].first > n) continue;
			if(add[i + v[j].first] <= 0) add[i + v[j].first] = 0;
			add[i + v[j].first] = ((add[i + v[j].first] % MOD) + (dp[i] % MOD)) % MOD;
			int red = min(n, i + v[j].second);
			rem[red] = ((rem[red] % MOD) + (dp[i] % MOD)) % MOD;
		}
		if(rem[i] > 0) {
			cur = ((cur + MOD) - rem[i]) % MOD;
		}
	}
	if(add[n] > 0) {
		cur = ((cur % MOD) + (add[n] % MOD)) % MOD;
	}
	cout << cur << endl;
}
 
int main () {
	int t = 1;
	for(int tt = 0; tt < t; tt++) solve();
	return 0;
}

Measured memory_bytes: 23124
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> p2;
bool func(string s){
  ll n=ll(s.length());
  for(ll i=0;i<n/2;i++)
    if(s[i]!=s[n-i-1])
      return false;
  return true;
}
void solve(){
  string s;
  cin>>s;
  ll n=ll(s.length());
  if(func(s)&&func(s.substr(0,(n-1)/2))&&func(s.substr((n+3)/2-1,n-(n+3)/2+1)))
    cout<<"Yes";
  else
    cout<<"No";
}
int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ll q=1;
  for(ll i=1;i<=q;i++)
    solve();
}

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

vector<vector<pair<int,int>>> G(100001);
stack<int> s;

void dfs(vector<int> &k, int N){
  if(s.empty()==0){
    int a=s.top();
    if(G.at(a).size()==0){
      s.pop();
    }
    else{
      if(k.at(G.at(a).at(G.at(a).size()-1).first)==2){
        k.at(G.at(a).at(G.at(a).size()-1).first)=(k.at(a)+G.at(a).at(G.at(a).size()-1).second)%2;
        s.push(G.at(a).at(G.at(a).size()-1).first);
      }
      G.at(a).pop_back();
    }
    dfs(k,N);
  }
  else{
    for(int i=1; i<=N; i++){
      cout << k.at(i) << endl;
    }
  }
}

int main() {
  int N;
  cin >> N;
  vector<int> k(N+1,2);
  for(int i=0; i<N-1; i++){
    long a,b,c;
    cin >> a >> b >> c;
    G.at(a).push_back(make_pair(b,c%2));
    G.at(b).push_back(make_pair(a,c%2));
  }
  s.push(1);
  k.at(1)=0;
  dfs(k,N);
}


Measured memory_bytes: 6784
s = input()
n = len(s)

for i in range(n-1):
    if(s[i]==s[i+1]):
        print('{} {}'.format(i+1,i+2))
        exit()

for i in range(n-2):
    if(s[i]==s[i+2]):
        print('{} {}'.format(i+1,i+3))
        exit()

print('{} {}'.format(-1,-1))

Measured memory_bytes: 67372
t1, t2 = (int(x) for x in input().split())
a1, a2 = (int(x) for x in input().split())
b1, b2 = (int(x) for x in input().split())

if a1 < b1:
    a1, b1 = b1, a1
    a2, b2 = b2, a2

if a1 * t1 + a2 * t2 > b1 * t1 + b2 * t2:
    print(0)
    exit()
elif a1 * t1 + a2 * t2 == b1 * t1 + b2 * t2:
    print("infinity")
    exit()

d1 = (a1 - b1) * t1
d2 = (b2 - a2) * t2
k = d1 // (d2 - d1)
if d1 % (d2 - d1) == 0:
    print(2 * k)
else:
    print(2 * k + 1)


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

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

typedef long long int lli;
typedef unsigned long long ull;
typedef complex<double> point;

template<typename P, typename Q>
ostream& operator << (ostream& os, pair<P, Q> p)
{
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

lli fn(vector<lli> a, lli b)
{
  lli sum = 0;
  for (int i = 0; i < a.size(); ++i) {
    sum += abs(a[i] - (b + i));
  }
  return sum;
}

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

  int n;
  while (cin >> n) {
    vector<lli> a(n);
    each (i, a) cin >> i;


    lli large = 1e9 + 10;
    lli small = -large;
    lli right, left;
    for (int loop = 1000; loop--; ) {
      left = (large - small) / 3.0 + small;
      right = (large - small) * 2.0 / 3.0 + small;
      
      lli dl = fn(a, left);
      lli dr = fn(a, right);
      
      if (dr < dl) small = left;
      else large = right;      
    }

    lli x = fn(a, small);
    lli y = fn(a, small + 1);
    lli z = fn(a, large);
    cout << min({x, y, z}) << endl;
  }
  
  return 0;
}


Measured memory_bytes: 3428
using System;

namespace agc040a
{
    class Program
    {
        static void Main(string[] args)
        {
            string S = Console.ReadLine();
            long ans = 0;
            int[] A = new int[S.Length+1];
            int[] B = new int[S.Length+1];
            int countL = 0;
            int countR = 0;
            for(int i = 0; i < S.Length;i++){
                if(S[i] == '<'){
                    countL++;
                }else{
                    countL = 0;
                }
                A[i+1] = countL;
            }
            for(int i = S.Length-1; i >= 0;i--){
                if(S[i] == '>'){
                    countR++;
                }else{
                    countR = 0;
                }
                B[i] = countR;
            }
            for(int i = 0; i < A.Length; i++){
                ans += Math.Max(A[i],B[i]);
            }
            Console.WriteLine(ans);
            
        }
    }
}

Measured memory_bytes: 16736
n, a, b = map(int, input().split())

ans = 0

for i in range(1, n + 1):
    num = i
    total = 0
    while True:
        total += num % 10
        num //= 10
        if num == 0:
            break
    if a <= total <= b:
        ans += i

print(ans)


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

int main () {
  int a, b;
  char op;
  while (1) {
    cin >> a >> op >> b;
    if (op == '+') {
      cout << a + b;
    } else if (op == '-') {
      cout << a - b;
    } else if (op == '*') {
      cout << a * b;
    } else if (op == '/') {
      cout << a / b;
    } else {
      break;
    }
    cout << endl;
  }

  return 0;
}

Measured memory_bytes: 1164
#[allow(unused_imports)]
use itertools::Itertools;
#[allow(unused_imports)]
use num::Integer;
#[allow(unused_imports)]
use proconio::derive_readable;
use proconio::fastout;
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;
#[allow(unused_imports)]
use std::cmp;

#[fastout]
fn main() {
    input! {
        x: i32,
        n: usize,
        p: [i32; n],
    }
    let p: std::collections::BTreeSet<_> = p.into_iter().collect();
    let mut ans = 0;
    let mut md = x;
    for i in 0..=101 {
        if !p.contains(&i) {
            if (x - i).abs() < md {
                ans = i;
                md = (x - i).abs();
            }
        }
    }

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


Measured memory_bytes: 2160
#include <iostream>
#include <algorithm>
#include <vector>
#include <tuple>
#include <cstring>
#include <queue>


#define REP(i, n) for(int (i) = 0; (i) < (n); ++(i))
#define eREP(i, n) for(int (i) = 0; (i) <= (n); ++(i))
#define rREP(i, n) for(int (i) = (n) - 1; (i) >= 0; ++(i))
#define ALL(TheArray) TheArray.begin(), TheArray.end()

template <class T> inline T& chmax(T& a, T b){return (a < b) ? a = b : a;}
template <class T> inline T& chmin(T& a, T b){return (a > b) ? a = b : a;}

using lli = long long int;
using pli = std::pair<lli, int>;

std::vector<lli> A, B;

int main(void){
    std::priority_queue<pli> Q;
    int n; scanf("%d", &n);
    A.resize(n); B.resize(n);
    REP(i, n) scanf("%lld", &A[i]);
    REP(i, n) {scanf("%lld", &B[i]); 
        if(A[i] < B[i]) Q.push(pli(B[i], i));
        else if(A[i] > B[i]){puts("-1"); return 0;}
    }


    lli res = 0;
    while(not Q.empty()){
        int idx; lli v = 0;
        std::tie(std::ignore, idx) = Q.top(); Q.pop();
        if(not Q.empty()) std::tie(v, std::ignore) = Q.top();
        int idx_p = (idx-1 + n) % n;
        int idx_l = (idx+1) % n;
        lli V = B[idx_p] + B[idx_l];
        lli K1 = (B[idx] - A[idx]) / V; if(K1 == 0) K1 = 1;
        //lli K2 = (B[idx] - v) / V; K2++;
        lli K3 = K1;
        //if(A[idx_p] != B[idx_p] or A[idx_l] != B[idx_l]){
          //  if(K3 > K2) K3 = K2;
        //}
        B[idx] -= K3 * V; res += K3;
        if(B[idx] < A[idx]) break;
        else if(B[idx] > A[idx]){
            Q.push(pli(B[idx], idx));
        }
    }
    bool same = true;
    REP(i, n) if(A[i] != B[i]){
        same = false;
        break;
    }
    if(same) printf("%lld\n", res);
    else puts("-1");
    return 0;
}


Measured memory_bytes: 9584
/*
 * Author : Andrew J
*/
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define all(x) x.begin() , x.end()
#define rall(x) x.rbegin() , x.rend()
#define vz(x) x.size()
using ll = long long;
using ii = pair <int , int>;
void in(int &x);
const int N = 2e5 + 10;
const int INF = 1e9 + 50;
const int MOD = 998244353;
int n, k;
int Moves[N];

ll subs(ll a , ll b) {
  return (((a - b) % MOD) + MOD * 2) % MOD;
}

ll rangeSum(int l , int r , vector <ll> &ss) {
  return subs(ss[l] , ss[r + 1]);
}

int main() {
  in(n); in(k);
  vector <ii> segment(k);
  for (int i = 0, l, r ; i < k ; i++) {
    in(l); in(r);
    segment[i] = {l , r};
  }

  sort(all(segment));

  vector <ll> dp(2 * (n + 1) , 0);
  vector <ll> ss(n + 5 , 0);
  dp[n] = 1, ss[n] = 1;
  for (int i = n - 1 ; i >= 1 ; i--) {
    for (int j = 0 ; j < k ; j++) {
      if (i + segment[j].fi > n) break;
      (dp[i] += rangeSum(min(i + segment[j].fi , n) , min(i + segment[j].se , n) , ss)) %= MOD;
    }
    ss[i] = (ss[i + 1] + dp[i]) % MOD;
  }
  printf("%lld\n" , dp[1]);
  return 0;
}

void in(int &x){
	bool neg = false;
	register int c;
	x = 0;
	c = getchar();
	if(c == '-'){
		neg = true;
		c = getchar();
	}
	for (; c > 47 && c < 58; c = getchar())
	x = (x << 1) + (x << 3) + c - 48;
	if (neg) x *= -1;
}


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

using namespace std;


int main(int argc, char const *argv[])
{
    int n;
    cin >> n;
    vector<int> H(n, 0);
    for (int i = 0; i < n; i++) {
        cin >> H[i];
    }

    bool ans = true;
    for (int i = n - 2; i >= 0 && ans; i--) {
        if (H[i] <= H[i + 1]) {
            continue;
        }
        H[i] -= 1;
        if (H[i] <= H[i + 1]) {
            continue;
        } else {
            ans = false;
        }
    }
    if (ans) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>

// using namespace __gnu_pbds;
using namespace std;

#define fbo find_by_order
#define ook order_of_key
#define fi first
#define se second
#define long long long
typedef pair<int,int> ii;
typedef pair<int,ii> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
// typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
// mt19937_64 rng(std::chrono::system_clock::now().time_since_epoch().count());

// /mnt/c/Users/vince/Desktop/POST-IOI/ 

const long MOD = 998244353;
int n, k; 
int L[200003], R[200003];
long dp[400003], pref[400003];

int main()
{
	// ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	// freopen("input.in", "r", stdin);

	scanf("%d %d", &n, &k);
	for(int i = 0; i < k; i++)
		scanf("%d %d", &L[i], &R[i]);

	dp[1] = 1;
	long sum = 0;
	for(int i = 1; i <= n; i++)
	{
		sum = (sum+pref[i])%MOD;
		dp[i] = (dp[i]+sum)%MOD;
		// printf("%lld ", dp[i]);
		for(int j = 0; j < k; j++)
		{
			pref[i+L[j]] += dp[i];
			pref[i+L[j]] %= MOD;
			pref[i+R[j]+1] -= dp[i];
			pref[i+R[j]+1] %= MOD;
		}
	}
	// printf("\n");
	printf("%lld\n", (dp[n]+MOD)%MOD);
}

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

using namespace std;

#define M 1000000007
#define pb push_back
#define f first
#define s second
#define rep(i, st, ed) for(int i=st; i<ed; i++)
#define repn(i, st, ed) for(int i=st; i<=ed; i++)
#define repb(i, ed, st) for(int i=ed; i>=st; i--)

typedef long long ll;
typedef unsigned long long int llt;
typedef long double ld;

const long double PI  =3.141592653589793238463;
const int N = 5e5 + 10;

vector<int> g[N];
bool viss[N];
int vis[N];

// Normal DFS
void dfs(int curr, int par)
{
  for(auto x: g[curr])
    if(x != par)
      dfs(x, curr);
}

// DFS with visiting status
void dfs1(int curr, int par)
{
  viss[curr] = 1;
  for(auto x: g[curr])
    if(!viss[x])
      dfs1(x, curr);
}

// DFS with strongly connected component
void dfs2(int curr, int par, int num)
{
  vis[curr] = num;
  for(auto x: g[curr])
    if(vis[x] == 0)
      dfs2(x, curr, num);
}

// XOR from 0 to n
ll fxor(ll n)
{
  if(n < 0) return 0;
  if(n % 4 == 3) return 0;
  else if(n % 4 == 0) return n;
  else if(n % 4 == 1) return n^(n-1);
  else if(n%4 == 2) return n^(n-1)^(n-2);
}

// Power in logn with mod 1000000007
llt ppow(llt x, llt y)
{
  llt res = 1;
  while(y > 0){
    if(y&1)
      res = (res * x)%M;
    y = y >> 1;
    x = (x * x)%M;
  }
  return res;
}

// Factorial with dp
llt factdp[N];
llt fact(llt x)
{
  if(x == 0) return 1;
  if(x == 1) return 1;
  if(factdp[x] != -1) return factdp[x];
  return factdp[x] = (x*fact(x-1))%M;
}

// String return to base b
string ansConv ="";
void convert10tob(llt N, int b)
{
     if (N == 0)
        return;
     int x = N % b;
     N /= b;
     if (x < 0)
        N += 1;
     convert10tob(N, b);
     ansConv += to_string(x);
     return;
}

// Convert string to num wiht base b
llt convertstrtob(string a, int b)
{
  llt aa = 0;
  llt mul = 1;
  for(int i=a.length()-1; i>=0; i--)
  {
    int curr = a[i] - '0';
    aa += (curr * mul);
    mul *= b;
  }
  return aa;
}

// Union Find algo with array
// Find()
int findpar(int curr, int arr[])
{
  while(arr[curr] != curr) curr = arr[curr];
  return curr;
}
// Union()
void Union(int b, int spa, int arr[])
{
  while(arr[b] != b)
  {
    int c = arr[b];
    arr[b] = spa;
    b = c;
  }
  arr[b] = spa;
}

// Main Code

int main()
{
int a, b, c;
cin>>a>>b>>c;
if(a <= c && c <= b)
{
  puts("Yes");
}
else
puts("No");
  return 0;
}


Measured memory_bytes: 12160
S=input()
T=input()

sts = [set([]) for _ in range(26)]
rsts = [set([]) for _ in range(26)]

for i in range(len(S)):
    a = ord(S[i])-ord('a')
    b = ord(T[i])-ord('a')
    sts[a].add(b)
    rsts[b].add(a)

res=True
for st in sts:
    if res and len(st)>1:
        print('No')
        res=False
for st in rsts:
    if res and len(st)>1:
        print('No')
        res=False
if res:
    print('Yes')


Measured memory_bytes: 3760
#include <bits/stdc++.h>
using namespace std;
int n;
int a[100005];
struct node{
	long long x,y;
}b[100005];
int main()
{
	cin >> n;
	long long m=0;
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
	}
	sort(a+1,a+1+n);
	int t=0;
	int j;
	m=a[n];
	for(j=2;j<n;j++)
	{
		if(a[j]>0) break;
		else
		{
			b[t].x=m;
			b[t++].y=a[j];
			m-=a[j];
		}
	}
	if(j==n)
	{
		b[t].x=m;
		b[t++].y=a[1];
		m-=a[1];
		cout << m << endl;
		for(int i=0;i<t;i++)
		printf("%lld %lld\n",b[i].x,b[i].y);
	}
	else if(j==n-1)
	{
		b[t].x=a[1];
		b[t++].y=m;
		m=a[1]-m;
		b[t].x=a[j];
		b[t++].y=m;
		m=a[j]-m;
		cout << m << endl;
		for(int i=0;i<t;i++)
		printf("%lld %lld\n",b[i].x,b[i].y);
	}
	else
	{
		b[t].x=a[1];
		b[t++].y=m;
		m=a[1]-m;
		for(int i=j+1;i<n;i++)
		{
			b[t].x=m;
			b[t++].y=a[i];
			m-=a[i];
		}
		b[t].x=a[j];
		b[t++].y=m;
		m=a[j]-m;
		cout << m << endl;
		for(int i=0;i<t;i++)
		printf("%lld %lld\n",b[i].x,b[i].y);
	}
}

Measured memory_bytes: 3840
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<queue>
#include<map>
using namespace std;
template<typename T>
inline void read(T& s)
{
    s=0;int f=1;char c=getchar();
    while(c<'0' || c>'9'){if(c=='-')f=-1;c=getchar();}
    while(c>='0' && c<='9'){s=s*10+c-'0';c=getchar();}
    s*=f;
}
int l;
int bt[25];
int main()
{
	cin>>l;
	int le=0;
	while((l>>le))	le++;
	int tot=0;
	for(int i=0;i<le;i++)
		if((l>>i)&1)
			bt[tot++]=i;
	cout<<le<<' '<<le*2+tot-3<<endl;
	for(int i=1;i<le;i++)
	{
		cout<<i<<' '<<i+1<<' '<<0<<endl;
		cout<<i<<' '<<i+1<<' '<<(1<<(le-i-1))<<endl;
	}
	int sum=(1<<(le-1))-1;
	for(int i=tot-2;i>=0;i--)
	{
		sum++;
		cout<<1<<' '<<le-bt[i]<<' '<<sum<<endl;
		sum+=(1<<(bt[i]))-1;
	}
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define pf push_front
#define mod 1000000007
#define endl '\n'
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

int main()
{
    ll n,i;
    cin>>n;
    string s;
    cin>>s;
    ll ans=1;
    for(i=1;i<n;i++)
    {
        if(s[i]!=s[i-1])
        {
            ans++;
        }

    }
    cout<<ans<<endl;
}


Measured memory_bytes: 512
import math
mod=1000000007
N,M=map(int,input().split())
if abs(N-M)>1:
  print(0)
else:
  n=math.factorial(N)
  m=math.factorial(M)
  if n==m:
    print(2*n*m%mod)
  else:
    print(n*m%mod) 


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

const int MAX_N = 100009;

int n, k, a[MAX_N];

int s[MAX_N];

int main() {
    while (true) {
        s[0] = 0;

        cin >> n >> k;
        if (n == 0 && k == 0) break;

        for (int i = 0; i < n; i++) {
            cin >> a[i];
            s[i+1] = s[i] + a[i];
        }

        int ans = -1000000007;
        for (int i = 0; i + k <= n; i++) {
            ans = max(ans, s[i+k] - s[i]);
        }
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 3752
/*
    Author : DemonStar
*/

#pragma GCC optimize("Ofast")
// #pragma GCC optimize("unroll-loops")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx2,tune=native")

#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<pair<int, int>, null_type, less<pair<int, int>>, rb_tree_tag, tree_order_statistics_node_update>
#define fast                      \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);                   \
    cout.tie(0);
#define ll long long
#define pi pair<int, int>
#define pl pair<long long, long long>
#define pld pair<long double, long double>
#define endl '\n'
#define loop(i, n) for (ll i = 0; i < n; i++)
#define rep(i, begin, end) for (__typeof(begin) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define all(x) x.begin(), x.end()
#define vl vector<ll>
#define vi vector<int>
#define ml map<ll, ll>
#define vpl vector<pair<ll, ll>>
const ll mod = 1e9 + 7;

template <typename T, typename TT>
ostream &operator<<(ostream &os, const pair<T, TT> &t)
{
    return os << t.first << " " << t.second;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &t)
{
    for (auto &i : t)
        os << i << " ";
    return os;
}
template <typename T>
istream &operator>>(istream &is, vector<T> &v)
{
    for (T &t : v)
        is >> t;
    return is;
}
template <typename T1, typename T2>
istream &operator>>(istream &is, vector<pair<T1, T2>> &v)
{
    for (pair<T1, T2> &t : v)
        is >> t.first >> t.second;
    return is;
}

int main()
{
    int n;
    cin >> n;
    vector<double> v(n);
    cin >> v;
    vector<vector<double>> dp(n + 1, vector<double>(n + 1, 0));
    for (int i = 0; i <= n; i++)
    {
        for (int j = 0; j <= i; j++)
        {
            if (!i)
                dp[i][j] = 1;
            else if (!j)
                dp[i][j] = dp[i - 1][j] * (1 - v[i - 1]);
            else
                dp[i][j] = dp[i - 1][j - 1] * v[i - 1] + dp[i - 1][j] * (1 - v[i - 1]);
        }
    }
    // cout << dp << endl;
    double ans = 0;
    for (int i = n / 2 + 1; i <= n; i++)
        ans += dp[n][i];
    printf("%.10lf", ans);
#ifdef LOCAL
    cerr
        << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif

    return 0;
}

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

int n1;
int a[1000000];
int binary(int num){
    int B = 0; 
    int T = n1-1; 
    while(B<=T){
        int mid = (B+T)/2;
            if(a[mid]<num){ 
                B = mid+1;
            }
            else if(a[mid]>num){ 
                T = mid-1;
            }
            else{
                return 1;
            }
    }
    return 0;
}
    

int main(){
    cin >> n1;
    for(int i=0;i<n1;i++){
        cin >> a[i];
    }
    int count = 0;
    int n2;
    int num;
    cin >> n2;
    for(int i=0;i<n2;i++){
        cin >> num;
        if(binary(num)){
            count++;
        }
    }
    cout << count << endl;
}


Measured memory_bytes: 3476
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;

import java.util.*;

public class Main {
    long MOD = (long) 1e9 + 7;

    InputStream in;
    OutputStream out;

    public Main() {
        this(System.in, System.out);
    }

    public Main(InputStream in, OutputStream out) {
        this.in = in;
        this.out = out;
    }

    void run() {
        Scanner sc = new Scanner(this.in);
        PrintWriter out = new PrintWriter(this.out);

        // write your code
        long n = sc.nextLong();

        long cnt = factors(n - 1).size() - 1;
//        debug(factors(n - 1), cnt);

        HashSet<Long> facts = factors(n);

        for (long i : facts) {
            if (i == 1) continue;
            long t = n;
            while (t % i == 0) t /= i;
//            debug(i, t, t % i);
            if (t % i == 1) cnt++;
        }

        out.println(cnt);

        out.flush();
    }

    HashSet<Long> factors(long n) {
        HashSet<Long> facts = new HashSet<>();
        for (long i = 1; i * i <= n; i++) {
            if (n % i == 0) {
                facts.add(i);
                facts.add(n / i);
            }
        }
        return facts;
    }

    void debug(Object... os) {
        System.err.println(Arrays.deepToString(os));
    }

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

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

int main(){
    double xs, ys, xt, yt;
    cin >> xs >> ys >> xt >> yt;
    ll N;
    cin >> N;
    vector<double> x(N+2), y(N+2), r(N+2);
    rep(i, 1, N+1) cin >> x[i] >> y[i] >> r[i];
    x[0] = xs; y[0] = ys; r[0] = 0;
    x[N+1] = xt; y[N+1] = yt; r[N+1] = 0;
    vector<vector<double>> D(N+2, vector<double>(N+2));
    rep(i, 0, N+1){
        rep(j, i+1, N+2){
            double dx = x[i] - x[j];
            double dy = y[i] - y[j];
            double l = sqrt(dx * dx + dy * dy);
            D[i][j] = max(0.0, l - r[i] - r[j]);
            D[j][i] = max(0.0, l - r[i] - r[j]);
        }
    }
    ll srt = 0;
    vector<double> d(N+2, 1e18);
    /* dijkstra's scope */{
        priority_queue<pair<double,ll>, vector<pair<double,ll>>, greater<pair<double,ll>>> que;
        que.push({0.0, srt});
        d[srt] = 0.0;
        while(!que.empty()){
            auto q = que.top();
            que.pop();
            if(q.first > d[q.second]) continue;
            rep(i, 0, N+2){
                if(i == q.second) continue;
                if(d[i] <= q.first + D[q.second][i]) continue;
                d[i] = q.first + D[q.second][i];
                que.push({d[i], i});
            }
        }
    }
    printf("%.12lf\n", d[N+1]);
    return 0;
}

Measured memory_bytes: 14192
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
 
x, a, b = MAP()
if abs(a-x) > abs(b-x):
	print("B")
else:
	print("A")

Measured memory_bytes: 5332
#include <iostream>
#include <utility>
#include <queue>
using namespace std;

int h, w, ans;
char a[1000][1000];
int c[1000][1000];
queue<pair<int, int>> q;

void Walk(int x,int y,int count) {
	if (a[x][y]=='.') {
		q.push({ x,y });
		a[x][y] = '#';
		c[x][y] = count;
		if (ans < count)ans = count;
	}
}

int main()
{
	cin >> h >> w;
	for (size_t i = 0; i < h; i++)
		for (size_t j = 0; j < w; j++) {
			cin >> a[i][j];
			if (a[i][j] == '#')
				q.push({ i,j });
		}
	while (!q.empty())
	{
		pair<int, int> t = q.front();
		q.pop();
		if (t.first - 1 >= 0)Walk(t.first - 1, t.second, c[t.first][t.second] + 1);
		if (t.first + 1 <= h)Walk(t.first + 1, t.second, c[t.first][t.second] + 1);
		if (t.second - 1 >= 0)Walk(t.first, t.second - 1, c[t.first][t.second] + 1);
		if (t.second + 1 <= w)Walk(t.first, t.second + 1, c[t.first][t.second] + 1);
	}
	cout << ans << endl;
}

Measured memory_bytes: 9856
#include <bits/stdc++.h>
#define rep(i,n) for (int i = (0); i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define show(x) cout << #x << " = " << (x) << endl
#define show2(x,y) cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl
#define show3(x,y,z) cout << #x << " = " << (x) << ", " << #y << " = " << (y) <<  ", " << #z << " = " << (z) << endl
#define showv(v) rep(i,v.size()) printf("%d%c", v[i], i==v.size()-1?'\n':' ')
#define showv2(v) rep(j,v.size()) showv(v[j])
#define showt(t,n) rep(i,n) printf("%d%c", t[i], i==n-1?'\n':' ')
#define showt2(t,r,c) rep(j,r) showt(t[j],c)
#define showvp(p) rep(i,p.size()) printf("%d %d\n", p[i].first, p[i].second);
#define printv(v) rep(i,v.size()) printf("%d\n", v[i])
#define printt(t,n) rep(i,n) printf("%d\n", t[i])
#define incl(v,x) find(rng(v),x)!=v.end()
#define incls(s,c) s.find(c)!=string::npos
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define bit(n,k) ((n>>k)&1) // nのk bit目
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vs = vector<string>;
using P = pair<int, int>;
using T = tuple<int, int, int>;
using vp = vector<P>;
using vt = vector<T>;
const int mod = 1000000007;
const double EPS = 1e-9;
const int INF = (1<<30)-1;
//const ll INF = (1LL<<62)-1;
#define dame { puts("No"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
//inline int in() { int x; scanf("%d",&x); return x;}
template<class T = int> inline T in() { T x; cin >> x; return (x);}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main () {
  int n, m;
  cin >> n >> m;
  vi k(m);
  vvi s(m);
  rep(i,m) {
    cin >> k[i];
    s[i] = vi(k[i]);
    rep(j,k[i]) cin >> s[i][j];
  }
  vi p(m);
  rep(i,m) cin >> p[i];

  int ans = 0;
  rep(b,1<<n) {
    int total = 0;
    rep(i,m) {
      int cnt = 0;
      rep(j,k[i]) {
        if (bit(b,s[i][j]-1)) cnt++;
      }
      if (cnt%2 == p[i]) total++;
    }
    if (total == m) ans++;
  }
  cout << ans << endl;
  return 0;
}

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

using namespace std;

#define INF 1001000100010001000
#define MOD 1000000007
#define EPS 1e-10
#define int long long
#define rep(i, N) for (int i = 0; i < N; i++)
#define Rep(i, N) for (int i = 1; i < N; i++)
#define For(i, a, b) for (int i = (a); i < (b); i++)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define pii pair<int, int>
#define vi vector<int>
#define vvi vector<vi >
#define vb vector<bool>
#define vvb vector<vb >
#define vp vector< pii >
#define all(a) (a).begin(), (a).end()
#define Int(x) int x; cin >> x;
#define int2(x, y) Int(x); Int(y);
#define int3(x, y, z) Int(x); int2(y, z);
#define in(x, a, b) ((a) <= (x) && (x) < (b))
#define fir first
#define sec second
#define ffir first.first
#define fsec first.second
#define sfir second.first
#define ssec second.second
#define Decimal fixed << setprecision(10)

//int dxy[5] = {0, 1, 0, -1, 0};
// cmd

bool solve(string &st, int len)
{
    if (st.size() / 2 < len) return false;

    set<string> yui;
    for (int i = st.size() - len - len; i >= 0; i--) {
        //cout << "call : " << st.substr(i+len, len) << endl;
        yui.insert(st.substr(i+len, len));
        //cout << "get : " << st.substr(i, len) << endl;
        if (yui.find(st.substr(i, len)) != yui.end()) {
            return true;
        }
    }
    return false;
}

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

    Int(n);
    string st;
    cin >> st;
    
    int left = 0, right = n;

    while (right - left > 1) {
        int mid = (right + left) / 2;
        if (solve(st, mid)) {
            left = mid;
        } else {
            right = mid;
        }
    }

    cout << left << endl;

    return 0;
}


Measured memory_bytes: 4352
S = gets.chomp

ans1 = S.unpack('C*').each_with_index.any?{|s, idx| s == 'L'.ord && (idx % 2) == 0}
ans2 = S.unpack('C*').each_with_index.any?{|s, idx| s == 'R'.ord && (idx % 2) == 1}

puts (ans1 || ans2) ? 'No' : 'Yes'


Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define END getchar();getchar();return 0
bool bou[10];

signed main() {
	int n, k;
	cin >> n >> k;
	bool bou[10];
	for (int i = 0; i < 10; i++) bou[i] = true;
	for (int i = 0; i < k; i++) {
		int a;
		cin >> a;
		bou[a] = false;
	}
	int cnt = n;
	while (1) {
		int now = cnt;
		bool suc = true;
		while (now > 0) {
			if (!bou[now % 10]) {
				cnt++;
				suc = false;
				break;
			}
			now /= 10;
		}
		if (suc) {
			cout << cnt << endl;
			END;
		}
	}

	END;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
  string S;
  int N,K;
  cin >> N >> K >> S;
  
  if(S.at(K-1) == 'A'){
    S.at(K-1) = 'a';
  }else if(S.at(K-1) == 'B'){
    S.at(K-1) = 'b';
  }else{
    S.at(K-1) = 'c';
  }
  
  cout << S << endl;
     
}


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


#define N 3
#define true 1
#define false 0


int x[4]={0,-1,0,1};
int y[4]={1,0,-1,0};
int l;
int w[N][N];

void swap(int *s,int *t){

  int tmp = *s;
  
  *s = *t;
  *t = tmp;
  
  return;

}


int abc(){

  int i,j,s = 0,r;
  
  for(i = 0; i < N; i++){
    for(j = 0; j < N; j++){
      if(w[i][j] == 0) continue;
      r = w[i][j] - 1;
      s += abs(r / N - i) + abs(r % N - j);
    }
  }
  
  return s;

}


int dfs(int d,int p,int ay,int ax){

  int i,m = abc();
  
  if(m == 0)return true;
  
  if(d + m > l)return false;
  
  for(i = 0; i < 4; i++){
    if(abs(i - p) == 2)continue;
    
    int tx = ax + x[i], ty = ay + y[i];
    
    if(tx < 0 || ty < 0 || tx >= N || ty >= N) continue;
    
    swap(&w[ty][tx],&w[ay][ax]);
    
    if(dfs(d + 1,i,ty,tx))return true;
    
    swap(&w[ty][tx],&w[ay][ax]);
  }
  
  return false;

}


void Solved(int ay,int ax){

  for(l = 0; ; l++){
    if(dfs(0,99,ay,ax)){
      printf("%d\n",l);
      return ;
    }
  }

}

int main(){

  int i,j,ax,ay;
   
   for(i = 0; i < N; i++){
     for(j = 0; j < N; j++){
       scanf("%d",&w[i][j]);
        if(w[i][j] == 0){
	  ay = i;
	  ax = j;
	}
     }
   }
     
   Solved(ay,ax);
     
     return 0;
}



Measured memory_bytes: 2084
#include <stdio.h>
#include <math.h>
#define N 1000000007
long long int power(long long int m,long long int n);
int main(void){
    long long int m,n;
    long long x;
    scanf("%lld %lld",&m,&n);
    x=power(m,n);
    printf("%lld\n",x);
    
    return 0;
}

long long int power(long long int m,long long int n){
    if(n==1) return m;
    else if(n%2==0){
        //偶数
        return(power((m*m)%N,n/2));
    }
    else {
        //奇数
        return(power((m*m)%N,n/2)*m%N);
    }
}


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

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

    if (N == M) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,m;
int t[100100];
int all;
inline void xzyopr()
{
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>t[i];
		all+=t[i]; 
	}
	cin>>m;
	for(int i=1;i<=m;i++)
	{
		int p,x;
		cin>>p>>x;
		cout<<all-t[p]+x<<'\n';
	}
}
signed main()
{
	xzyopr();
	return 0;
}


Measured memory_bytes: 256
#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>;
void fail() {
    cout << -1;
    exit(0);
}
int main() {
    int n;
    cin >> n;
    ++n;
    vector<ll> a(n), b(n);
    for (ll& i : a) cin >> i;
    if (n == 1) return cout << (a[0] == 1 ? 1 : -1), 0;
    b[n - 1] = a[n - 1];
    for (int i = n - 2; i >= 0; --i) b[i] = b[i + 1] + a[i];
    ++a[0];
    ll m = 1, r = 0;
    for (int i = 0; i < n; ++i) {
        r += m = min(m * 2ll, b[i]) - (i ? a[i] : b[0] <= 1 ? 0 : a[i]);
        if (m < 0) return cout << "-1\n", 0;
    }
    rep(i, n) r += a[i];
    cout << r - 1 << endl;
    return 0;
}

Measured memory_bytes: 4828
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
using namespace std;

int main(int argc, const char * argv[]) {
    int x;
    cin >> x;
    
    int ans = -1;
    for (int i = x; i >= 1; i--) {
        for (int j = sqrt(i); j >= 2; j--) {
            if (i % j == 0) {
                double y = i;
                bool flag = true;
                while (y != 1.0 && flag) {
                    y /= j;
                    if (y < 1.0) {
                        flag = false;
                    }
                }
                if (flag && ans < i) {
                    ans = i;
                }
            }
        }
    }
    if (ans == -1) {
        ans = 1;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
/*
 *
 *   Author     : Amit Kumar
 *   Date 	: June 22, 2019
 * 
 */

#include <bits/stdc++.h>

//#define MORE_THAN_ONE_TESTCASE // COMMENT IT

#define vi vector<int>
#define vl vector<long long>
#define mii map<int , int>
#define mll map<long long , long long>
#define msi map<string , i>
#define msl map<string , long long>
#define si set<int>
#define sl set<long long>
#define pii pair<int , int >
#define psi pair<string,int>
#define psl pair<string , long > 
#define pll pair<long long , long long>
#define vpii vector<pii>
#define vpll vector<pll>
#define vpsi vector<psi>
#define vpsl vector<psl>
#define _ub upper_bound
#define _lb lower_bound
#define bint long long int
#define _in(x) scanf("%lld",&x)
#define _f first
#define _s second
#define _all(x) x.begin(),x.end()
#define _pb push_back
#define _eb emplace_back
#define _mp make_pair
#define _iv(v) for(auto &i:v){cin>>i;}
#define _ov(v) for(auto i:v){cout<<i<<" ";}cout<<endl;
#define _ovn(v) for(auto i:v){cout<<i<<endl;}
#define _euv(v) for(auto i:v){cerr<<i<<" ";}cerr<<endl;
#define _eovn(v) for(auto i:v){cerr<<i<<endl;}
#define _os(s) for(auto itr:s){cout<<itr<<" ";}cout<<endl;
#define _osn(s) for(auto itr:s){cout<<itr<<endl;}
#define _eos(s) for(auto itr:s){cerr<<itr<<" ";}cerr<<endl;
#define _eosn(s) for(auto itr:s){cerr<<itr<<endl;}
#define _rep(x) for(auto i=0 ; i<(x); ++i)
#define _repe(x) for(auto i=0; i<=(x); ++i)
#define _irep(a,b) for(auto i=(a); i<(b); ++i)
#define _irepe(a,b) for(auto i=(a); i<=(b); ++i)
#define _crep(a,b,c) for(auto i=(a); i<(b); i+=(c))
#define _crepe(a,b,c) for(auto i=(a); i<=(b); i+=(c))
#define _min(x,y) ((y) ^ (((x) ^ (y)) & (-((x) < (y)))))
#define _max(x,y) ((x) ^ (((x) ^ (y)) & (-((x) < (y)))))
#define endl '\n'
using namespace std;




auto SOLUTION_FUNCTION( void ) ->void {

    // your solution goes here 

    string s;
    cin>>s;
    if(s[0]==s[1] or s[1]==s[2] or s[2]==s[3])
        puts("Bad");
    else
        puts("Good");



    return ;
}




int main(void){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    cout<<setprecision(10);
    cout<<fixed;
    cout<<boolalpha;
#ifdef MY_LOCAL_PROJECT
    freopen("input","r",stdin);
    freopen("output","w",stdout);
#endif
    int testcase = 1;


#ifdef MORE_THAN_ONE_TESTCASE
    cin>>testcase;
#endif
    
    while(testcase--){
        SOLUTION_FUNCTION();
    }

#ifdef MY_LOCAL_PROJECT
    cout<<"Time : "<<1.0*(double)clock()/CLOCKS_PER_SEC<<endl;
#endif
    return 0;
}


Measured memory_bytes: 256
n = int(input())
A = [int(x) for x in input().split()]
B = []
if n % 2 == 0:
    for i in range(n // 2, 0, -1):
        B.append(A[2 * i - 1])
    for j in range(n // 2):
        B.append(A[2*j])
else:
    for k in range(n // 2, -1, -1):
        B.append(A[2 * k])
    for h in range(1, n // 2+1):
        B.append(A[2*h-1])


print(*B, sep=" ")


Measured memory_bytes: 26020
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<cmath>
#include<string>

#define ls (t<<1)
#define rs ((t<<1)+1)
#define mid ((l+r)>>1)
#define fi first
#define se second
#define mk make_pair
#define pb push_back

#define N 1005
#define M 200005
#define seed 23333

using namespace std;
int i,j,m,n,p,k,vis[N];
double dis[N],a,b,c,d;
struct Cyc{
	double x,y,r;
}A[N];
double sqr(double x)
{
		return x*x;
}
double dist(Cyc a,Cyc b)
{
		return max(0.,sqrt(sqr(a.x-b.x)+sqr(a.y-b.y))-a.r-b.r);
}
int main()
{
		scanf("%lf%lf%lf%lf",&a,&b,&c,&d);
		scanf("%d",&n);
		A[0]=(Cyc){a,b,0};
		A[n+1]=(Cyc){c,d,0};
		for (i=1;i<=n;++i) scanf("%lf%lf%lf",&A[i].x,&A[i].y,&A[i].r);
		for (i=1;i<=n+1;++i) dis[i]=1e18;
		for (i=1;i<=n+1;++i)
		{
				k=-1;
				for (j=0;j<=n;++j) if (!vis[j]&&(k==-1||dis[k]>dis[j])) k=j;
				vis[k]=1;
				for (j=1;j<=n+1;++j)
					if (!vis[j]&&dis[k]+dist(A[j],A[k])<dis[j])
						dis[j]=dis[k]+dist(A[j],A[k]);
		}
		printf("%.10lf\n",dis[n+1]);
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int W, H, x, y, r;

	scanf("%d%d%d%d%d", &W, &H, &x, &y, &r);

	if ((x + r <= W) && (y + r <= H) && (x - r >= 0) && (y - r >= 0))
		printf("Yes\n");
	else
		printf("No\n");

	return 0;
}

Measured memory_bytes: 584