akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <sstream>
#include <stack>
#include <iomanip>
#include <numeric>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <map>
#include <set>
#include <vector>
#include <utility>
#include <queue>
#include <cmath>

#define BEGIN(x) x.begin()
#define END(x) x.end()
#define ALL(x) BEGIN(x), END(x)
#define PAIR make_pair
#define VEC(type) vector<type >
#define endl '\n'

#define FOR(i, A, B) for(auto i = (A);i != (B); i++)
#define FORD(i, A, B) for(auto i = (A);i != (B); i--)

#define READRANGE(begin, end) FOR(it, begin, end) cin >> *it
#define READVEC(V) READRANGE(BEGIN(V), END(V))

using namespace std;

typedef long long lint;
typedef pair<int, int> Pii;
typedef pair<int, lint> Pil;
typedef pair<lint, lint> Pll;
typedef pair<lint, int> Pli;

template<class U, class V>
istream& operator >>(istream& in, pair<U, V>& pr) {
    return in >> pr.first >> pr.second;
}

// ---- BEGIN LIBRARY CODE ----
// ---- END LIBRARY CODE ----
void io_init()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
};

int main(int argc, char **argv)
{
    io_init();

    // Actual program code starts here.
    int A, B, C, K;
    cin >> A >> B >> C >> K;
    int ret = 0, t;
    t = min(K, A);
    ret += t;
    K -= t;
    t = min(K, B);
    K -= t;
    ret -= min(K, C);
    cout << ret << endl;
    return 0;
};

Measured memory_bytes: 3640
#include <bits/stdc++.h> // Tomasz Nowak
using namespace std;     // XIII LO Szczecin
using L = long long;

vector<vector<int>> graph;
vector<vector<int>> dp; // dp[v][c] = number of ways to color subtree of v with color of v = c

constexpr int mod = int(1e9) + 7;
int mult(int a, int b) {
	return a * L(b) % mod;
}
int add(int a, int b) {
	return (a + b) % mod;
}

void DFS(int v = 0, int p = -1) {
	for(int u : graph[v])
		if(u != p) {
			DFS(u, v);
			dp[v][0] = mult(dp[v][0], add(dp[u][0], dp[u][1]));
			dp[v][1] = mult(dp[v][1], dp[u][0]);
		}
}

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

	int n;
	cin >> n;
	graph.resize(n);
	for(int edge = 0; edge < n - 1; ++edge) {
		int v, u;
		cin >> v >> u;
		--v, --u;
		graph[v].emplace_back(u);
		graph[u].emplace_back(v);
	}

	dp.resize(n, vector<int>{1, 1});
	DFS();
	cout << add(dp[0][0], dp[0][1]) << '\n';
}



Measured memory_bytes: 18176
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
#define pp pair<ll,ll>
#define ld long double
#define all(a) (a).begin(),(a).end()
#define mk make_pair
ll MOD=998244353;
int inf=1000001000;
ll INF=1e18+5;
ll mod=INF;

int main() {
    int n,s;
    cin >> n >> s;
    vector<vector<ll>> d(n+1,vector<ll>(s+1,0));
    d[0][0]=1;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    rep(i,n){
        d[i+1]=d[i];
        rep(j,s+1){
            if (a[i]+j>s) break;
            (d[i+1][a[i]+j]+=d[i][j])%=MOD;
        }
        rep(j,s+1){
            (d[i+1][j]+=d[i][j])%=MOD;
        }
    }
    cout << d[n][s] << endl;
}


Measured memory_bytes: 73680
n, k = map(int, input().split())
v = [0 for i in range(n)]
for i in range(n):
    v[i] = int(input())
v.sort()
min = 1000000000
for i in range(n - k + 1):
    if (min > v[i + k - 1] - v[i]):
        min = v[i + k - 1] - v[i]
print(min)

Measured memory_bytes: 7464
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,c;
    cin >> a >> b >> c;
    if(a > b)
    {
        swap(a,b);
    }
    if(b > c)
    {
        swap(b,c);
    }
    if(a > b)
    {
        swap(a,b);
    }
    cout << c * 10 + a + b;

    return 0;
}

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

#define pb push_back
#define fi first
#define se second
#define eb emplace_back

using namespace std;

typedef pair<int, int> ii;
typedef long long ll;
const int N = 1000007, inf = 0x3f3f3f3f;

const double pi = acos(-1);
int main() {
	ios::sync_with_stdio(0); cin.tie(0);

	double a, b, h, m;
	cin >> a >> b >> h >> m;

	double alpha = (h * 2.0 * pi / 12) + (m * 2 * pi/(12 * 60));
	double beta = m * 2.0 * pi / 60;

	double theta = alpha - beta;
	if(theta < 0) theta = -theta;

	theta = min(theta, 2 * pi - theta);

	double ans = a * a + b * b - 2.0 * a * b * cos(theta);
	cout << fixed << setprecision(10) << sqrt(ans) << '\n';
}

Measured memory_bytes: 4232
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <iostream>
#include<set>
#include<map>

using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < n; i++)
#define all(x) (x).begin(), (x).end()
#define grt() greater<int>()
#define grtl() greater<long long>()

int main() {
    int n;
    cin >> n;
    vector<int> a(n-1);
    set<int> as;
    rep(i, n-1)
    {
        cin >> a[i];
        as.insert(a[i]);
    }

    sort(all(a));
    map<int, int> am;
    for (auto i = as.begin(); i != as.end(); i++)
    {
        int num = upper_bound(all(a), *i) - lower_bound(all(a), *i);
        am.insert(make_pair(*i, num));
    }

    rep(i, n) {
        cout << am[i + 1] << "\n";
    }

}

Measured memory_bytes: 22804
import java.util.*;

public class Main {
    static Scanner scanner = new Scanner(System.in);

    public static void main(String[]$) {
        int n = scanner.nextInt();
        int[] a = new int[n];
        for (int i = 1; i <= n; i++) {
            a[scanner.nextInt() - 1] = i;
        }
        long ans = 0;
        TreeSet<Integer> set = new TreeSet<>(Arrays.asList(0, n + 1));
        for (int i = 0; i < n; i++) {
            set.add(a[i]);
            ans += (long)(i + 1) * (a[i] - set.lower(a[i])) * (set.higher(a[i]) - a[i]);
        }

        System.out.println(ans);
    }
}

Measured memory_bytes: 90472
#include <bits/stdc++.h>
using namespace std;
#define int                     long long int
#define ld                      long double
#define pb                      push_back
#define MOD                     2019
#define inf                     3e18
#define vi                      vector<int>
#define vld                     vector<ld>
#define pii                     pair<int,int>
#define mii                     map<int,int>
#define fi                      first
#define se                      second
#define fastIO                  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define db(...)                 __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) { cerr << " "<< name << " : " << arg1 <<'\n'; }
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
    const char* comma = strchr(names + 1, ',');
    cerr.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...);
}

void inp_out()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    freopen("debug.txt", "w", stderr);
    #endif
}

int32_t main()
{
	fastIO
	inp_out();
	string s;
	cin>>s;
	vector<int> mp(MOD);
	int val=0;
	mp[val]++;
	int pot=1,ans=0;
	for (int i = s.size()-1; i>=0; --i)
	{
		val=(val+(s[i]-'0')*pot)%MOD;
		pot=(pot*10)%MOD;
		ans+=mp[val];
		mp[val]++;
	}
	cout<<ans;


	return 0;
}

Measured memory_bytes: 3764
#include <bits/stdc++.h>
#define inf 1000000007
#define mod 1000000007
//#pragma GCC optimize(2)
//#define int long long
using namespace std;
template <typename T> void read(T &x){
	x=0;char ch=getchar();int fh=1;
	while (ch<'0'||ch>'9'){if (ch=='-')fh=-1;ch=getchar();}
	while (ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();
	x*=fh;
}
template <typename T> void write(T x) {
	if (x<0) x=-x,putchar('-');
	if (x>9) write(x/10);
	putchar(x%10+'0');
}
template <typename T> void writeln(T x) {
	write(x);
	puts("");
}
int n,m;
signed main()
{
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin>>n>>m;
	for(int i=1;i<=m;i++)
	{
		int a;
		cin>>a;
		n-=a;
	}
	cout<<(n<0?-1:n)<<endl;
	return 0;
}


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

bool check(vector<int> &a, long long K, int thr) {
    long long c = 0;
    for (int i : a) {
        if (i > thr) {
            c += (i / thr) - int(i%thr==0);
        }
        if (c > K) {
            // cout << c << endl;
            return false;
        }
    }
    // cout << c << endl;
    return true;
}


int main() {
    long long N, K;
    cin >> N >> K;
    vector<int> a(N);
    for (int i = 0; i < N; i++) {
        cin >> a[i];
    }
    int L = 0;
    int R = 1000000000;
    int M;
    while (R-L > 1) {
        M = (L+R)/2;
        // cout << L << " " << R << " " << M << endl;
        if (check(a, K, M)) {
            // cout << " ok" << endl;
            R = M;
        } else {
            // cout << " ng" << endl;
            L = M;
        }
    }
    cout << R << endl;
    return 0;
}


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

int main(){

  long n,d;

  while(cin >> n, n){

    while(n >= 13){

      d = 0;

      if(n%2 == 1){
	for(int i=3;i*i<=n;i+=2){
	  if(d == 1) break;

	  if(i*i <= n-8){
	    if((n-8)%i == 0) d = 1;
	  }
	  if(i*i <= n-6){
	    if((n-6)%i == 0) d = 1;
	  }
	  if(i*i <= n-2){
	    if((n-2)%i == 0) d = 1;
	  }
	  if(n%i == 0) d = 1;
	}
	n -= 2;
      }

      else{
	n--;
	continue;
      }

      if(!d){
	cout << n+2 << endl;
	break;
      }
    }

  }
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n) for(i=0;i<n;i++)
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
int main()
{
    ///"In the name of Allah,most gracious and most merciful"///
    ll t,ac=0,wa=0,tle=0,re=0;
    cin>>t;
    string a="AC",a1="WA",a2="TLE",a3="RE";
    while(t--)
    {
        string s;
        cin>>s;
        if(s==a)
            ac++;
        else if(s==a1)
            wa++;
        else if(s==a2)
            tle++;
        else if(s==a3)
            re++;

    }
    cout<<"AC"<<" x "<<ac<<endl;
    cout<<"WA"<<" x "<<wa<<endl;
    cout<<"TLE"<<" x "<<tle<<endl;
    cout<<"RE"<<" x "<<re<<endl;

    return 0;
}




Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> LL;

int main(void){
    ll a,b,c;cin>>a>>b>>c;
    ll p = c-b-a;
    if(p<0){
        cout<<"No"<<endl;
        return 0;
    }

    ll r = p*p;
    ll l = 4*a*b;

    if(r>l){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
}

Measured memory_bytes: 256
/*~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=
*$* WRITER:kakitamasziru/OxOmisosiru *$*
~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=*/
#ifdef LOCAL_JUDGE
#define _GLIBCXX_DEBUG //FOR THE DEBUG! COMMENT OUT THIS WHEN SUBMITTING!
#endif
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <iomanip>
#include <limits>//setprecision
//#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
//#include <unordered_set> //unordered_set
#include <stack> // stack
#include <deque> // deque
#include <math.h>//pow,,,
#include <cmath>//abs,,,
#include <bitset> // bitset
//It is so troublesome that I include bits/stdc++.h !
using namespace std;

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
const long long INF = 10010010010010;
const long long MOD = 1000000007;
typedef pair<int,int> P;

//Solve N^M. This, mod_pow use Iterative Square Method.
long long mod_pow(long long N, long long M) {
    if (M == 0) return 1;
    long long res = mod_pow((N * N) % MOD, M / 2);
    //最下位ビット(*N)が1の時は単独でNをかける
    if (M & 1) res = (res * N) % MOD;

    return res %= MOD;
}

long long gcd(long long a, long long b) {
    if (b == 0) return a;
    else return gcd(b, a % b);
}
long long lcm(long long a, long long b) {
    return a / gcd(a, b) * b ;
}

int main() {
    int N;cin >> N;
    vector<int> retu(N*2);
    for(int i = 0;i<N*2;i++) cin >> retu.at(i);
    sort(retu.begin(),retu.end());
    int ans = 0;
    for(int i = 0;i<N*2;i+=2){
        ans += min(retu.at(i),retu.at(i+1));
    }
    cout << ans << endl;
}


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

dp=[float('inf')]*(n+1)
dp[0]=0
moneys=[6,9]
for money in range(n+1):
    if dp[money]!=float('inf'):

        for i in moneys:
            cnt=0
            while money+i**cnt<=n:
                dp[money+i**cnt]=min(dp[money]+1,dp[money+i**cnt])
                cnt+=1
print(dp[-1])

Measured memory_bytes: 47824
#include "bits/stdc++.h"
 
typedef long long ll;
#define int ll
#define fi first
#define se second
#define SORT(a) sort(a.begin(),a.end())
#define rep(i,n) for(int i = 0;i < (n) ; i++) 
#define REP(i,n) for(int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define INF LLONG_MAX/2
#define all(x) (x).begin(),(x).end()
#define debug(x) cerr<<#x<<": "<<x<<endl
#define debug_vec(v) cerr<<#v<<":";rep(i,v.size())cerr<<" "<<v[i];cerr<<endl
using namespace std;
ll pow(ll x,ll n){
    ll ans = 1;
    while(n > 0){
        if(n%2 == 1) ans = ans * x;
        x = x * x;
        n = n >> 1;
    }
    return ans;
}
signed main(){
    int x;
    cin >> x;
    vector<int> p;
    for(int i = 1;i <= 40;i++){
        for(int j = 2;j <= 10;j++){
            int c = pow(i,j);
            if(c > x)break;
            p.push_back(c);
        }
    }
    SORT(p);
    cout << p[p.size()-1] << endl;


    return 0; 
}

// g++ -std=c++14 code1.cpp
// rm -r -f test;oj dl https://yahoo-procon2019-qual.contest.atcoder.jp/tasks/yahoo_procon2019_qual_d
// rm -r -f test;oj dl http://abc097.contest.atcoder.jp/tasks/abc097_b

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(2**20)

class Node:
    def __init__(self, parent, left, right):
        self.parent = parent #親
        self.left = left #一番左の子ノード
        self.right = right #すぐ右の兄弟

def get_depth(T: dict, u: int):
    """
    T: 木構造
    u: ノード番号
    """
    d = 0
    while T[u].parent is not None:
        u = T[u].parent
        d += 1

D = {} #深さを保存

def get_all_depth(T: dict, u: int, p: int):
    """
    一度に全てのノードの深さを再帰的に取得する。
    p: 現在扱う深さ
    """
    D[u] = p
    if T[u].right is not None:
        get_all_depth(T, T[u].right, p) #兄弟から入れていく（深さは同じ）
    if T[u].left is not None:
        get_all_depth(T, T[u].left, p+1) #1つ深く潜る

def ret_children(T: dict, u: int):
    children = []
    c = T[u].left
    while c is not None:
        children.append(c)
        c = T[c].right
    return children

# 答え出力
def print_for_a_node(T: dict, node: int, D: dict):
    node_type = "internal node" if T[node].left is not None else "leaf"
    if T[node].parent is None: #親ノードが無ければ
        parent = -1
        node_type = "root"
    else:
        parent = T[node].parent
    children = ret_children(T, node)
    print(
        f"node {node}: parent = {parent}, depth = {D[node]}, {node_type}, {children}"
    )

# 入力
n = int(input())

T = {k: Node(None, None, None) for k in range(n)}

for _ in range(n):
    tmp = list(map(int, input().split()))
    if tmp[1] == 0: # 子ノードがなければ次へ
        continue
    T[tmp[0]].left = tmp[2] # 一番左の子ノード
    T[tmp[2]].parent = tmp[0] # 子ノードの親（自分）
    prev_sibling = tmp[2]
    for sib in tmp[3:]:
        T[prev_sibling].right = sib
        T[sib].parent = tmp[0]
        prev_sibling = sib

for node in range(n):
    if T[node].parent is None:
        get_all_depth(T, node, 0)
        # Dに深さが格納された
        break
for node in range(n):
    print_for_a_node(T, node, D)


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

int main(){
  int a,n,i,kotae=0;
  cin>>n;
  for(i=0;i<n;i++){
    cin>>a;
    if(a!=i+1){
      kotae++;
    }
  }
  if(kotae<=2){
    cout<<"YES";
  }else{
    cout<<"NO";
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using vi = vector<int>;
using vvi = vector<vi>;
#define ote(x) cout<<(x)<<endl
#define all(x) (x).begin(),(x).end()
#define rp(i,s,e) for(int i=(s);i<(e);++i)

int main(){
	int N,A; cin>>N>>A;
	ote(N*N-A);
}


Measured memory_bytes: 256
class Dice():

    def __init__(self, label):
        self.label = label

    def north(self):
        self.change([2, 6, 3, 4, 1, 5])

    def west(self):
        self.change([3, 2, 6, 1, 5, 4])

    def east(self):
        self.change([4, 2, 1, 6, 5, 3])

    def south(self):
        self.change([5, 1, 3, 4, 6, 2])

    def change(self, convert):
        num = []
        for i in range(6):
            num.append(self.label[convert[i] - 1])
        self.label = num


def main():
    dice = Dice([int(x) for x in input().split()])
    for c in input():
        if c == 'N':
            dice.north()
        elif c == 'W':
            dice.west()
        elif c == 'E':
            dice.east()
        elif c == 'S':
            dice.south()
    print(dice.label[0])


if __name__ == '__main__':
    main()

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

int main() {
  int a, b;
  cin >> a >> b;
  if (a == 1) {
    a = 14;
  }
  if (b == 1) {
    b = 14;
  }
  if (a < b) {
    cout << "Bob" << endl;
  }
  else if (a == b) {
    cout << "Draw" << endl;
  }
  else {
    cout << "Alice" << endl;
  }
}


Measured memory_bytes: 256
N = int(input())
li = list()
for i in range(N):
    a, b = [int(x) for x in input().split()]
    li.append([a,b])

count = 0
for i in li:
    if count < 3:
        if i[0] == i[1]:
            count += 1
        else:
            count = 0
    else:
        break

if count >= 3: print('Yes')
else: print('No')


Measured memory_bytes: 9188
#include <iostream>
#include <vector>
#include <cmath>
#include <typeinfo>
#include <set>
#include <bitset>
#include <string>
#include <map>
#include <algorithm>
#include <iomanip>
#include <numeric>
using namespace std;
typedef long long ll;

int main(){
  int n;
  ll k;
  cin >> n >> k;
  vector<int> a(n);
  for(int i=0; i<n; i++){
    cin >> a[i];
    a[i] -= 1;
  }

  int count = 0;
  vector<int> v(n, -1);
  int now = 0;
  int next;
  v[now] = 0;
  int nn;
  while(true){
    next = a[now];
    if(v[next]==-1){
      count += 1;
      v[next] = count;
      //cout << "V[" << next+1 << "] = " << count << endl;
      now = next;
      if(count == k){
        cout << now+1 << endl;
        exit(0);
      }
    }else{
      nn = (k-v[next])%(v[now]-v[next]+1);
      now = next;
      for(int i=0; i<nn; i++){
        now = a[now];
      }
      cout << now+1 << endl;
      exit(0);
    }
  }
} 

Measured memory_bytes: 5156
#include <bits/stdc++.h>
using namespace std;
// long long mod=180143987779;
// vector<long long > t(4*100001);
// bool comp(tuple<int,int,int> a,tuple<int,int,int> b)
// {
//   if(get<0>(a)<get<0>(b))
//   {
//     return false;
//   }
//   else if(get<0>(a)==get<0>(b) && get<1>(b)<get<1>(a))
//   {
//     return true;
//   }
//   else
//   {
//     return true;
//   }
// }
// void buildseg(long long  x,long long  l,long long  r,vector<long long > &a,long long  modi)
// {
//   if(l==r)
//   {
//     t[x]=a[l]%modi;
//   }
//   else
//   {
//     long long  mid=(l+r)/2;
//     buildseg(2*x+1,l,mid,a,modi);
//     buildseg(2*x+2,mid+1,r,a,modi);
//     t[x]=(t[2*x+1]+t[2*x+2])%modi;
//   }
// }
// long long  sum(long long  x,long long  l1,long long  r1,long long  l,long long  r,long long  modi)
// {
//   if(l>r)
//   {
//     return 0;
//   }
//   else if(l1==l && r1==r)
//   {
//     return t[x];
//   }
//   else
//   {
//     long long  mid=(l1+r1)/2;
//     return (sum(2*x+1,l1,mid,l,min(r,mid),modi)+sum(2*x+2,mid+1,r1,max(l,mid+1),r,modi))%modi;
//   }
// }
// void update(long long  x,long long  l,long long  r,long long  value,long long  pos,long long  modi)
// {
//   if(l==r)
//   {
//     t[x]=value%modi;
//   }
//   else
//   {
//     long long  mid=(l+r)/2;
//     if(mid>=pos)
//     {
//       update(2*x+1,l,mid,value,pos,modi);
//     }
//     else
//     {
//         update(2*x+2,mid+1,r,value,pos,modi);
//     }
//     t[x]=(t[2*x+1]+t[2*x+2])%modi;
//   }
// }
// void prdoubleseg(long long  n)
// {
//   for(long long  i=0;i<4*n;i++)
//   {
//     cout<<t[i]<<" ";
//   }
//   cout<<endl;
// }
// void dfs(double x,  vector<vector<double> > &adj,vector<set<double> > &v,double &count,vector<double> &vis)
// {
//   v[x].insert(count);
//   vis[x]=1;
//   for(auto i : adj[x])
//   {
//     if(vis[i]==0)
//     {
//       vis[i]=1;
//       dfs(i,adj,v,count,vis);
//     }
//   }
// }
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int T;
   T=1;
  while(T--)
  {
    string s,t;
    cin>>s>>t;
     if(t.substr(0,t.size()-1)==s)
     cout<<"Yes"<<endl;
     else
     cout<<"No"<<endl;
  }


   return 0;
}


Measured memory_bytes: 3580
N, M = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(N)]
cd = [list(map(int, input().split())) for _ in range(M)]
ans = []
t = 0

def distance(xy1, xy2):
    return (abs(xy1[0] - xy2[0]) + abs(xy1[1] - xy2[1]))

for xy in ab:
    temp = float('inf')
    for j, xy2 in enumerate(cd):
        dis = distance(xy, xy2)
        if temp > dis:
            temp = dis
            t = j
    ans.append(t+1)
for a in ans:
    print(a)



Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {
  public static void main (String[] args) {
    Scanner in = new Scanner(System.in);

    while (in.hasNext()) {
      String S = in.next();
      int[] count = new int[26];

      for (int i = 0; i < S.length(); ++i) {
        ++count[S.charAt(i) - 'A'];
      }
      
      int count2 = 0;
      for (int i = 0; i < count.length; ++i) {
        if (count[i] == 2) {
          ++count2;
        }
      }

      if (count2 == 2) {
        System.out.println("Yes");
      } else {
        System.out.println("No");
      }
    }
  }
}

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

#define rep(i, n) for(int i=0; i < n; i++)
#define reps(i, n) for(int i=1; i <= n; i++)
#define INF 1e9
#define ALL(v) v.begin(), v.end()

using namespace std;
using ll=long long;


int main() {
  int n;cin>> n;
  int ds[n];rep(i,n)cin >> ds[i];
  sort(ds,ds+n);

  int left=ds[n/2-1];
  int right=ds[n/2];
  if(left==right){cout << 0;return 0;}

  cout << right-left;
}

Measured memory_bytes: 640
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char) 
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main(){
    let n: i32 = read();
    let x: i32 = read();
    let mut ans = None;
    'outer: for i in 0..n+1 {
        for j in 0..n-i+1 {
            for k in 0..n-i-j+1 {
                if i+j+k != n { continue; }
                if i*10000 + j*5000 + k*1000 == x {
                    ans = Some((i,j,k));
                    break 'outer;
                }
            }
        }
    }
    let (x, y, z) = ans.unwrap_or((-1, -1, -1));
    println!("{} {} {}", x, y, z);
}

Measured memory_bytes: 4352
#include <stdio.h>
int main(void){
	int h,w;
	scanf("%d%d",&h,&w);
	int b[h];
	for(int i=0;i<h;i++){
		b[i]=0;
	}
	int a[h][w];
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			scanf("%d",&a[i][j]);
			a[i][j]=a[i][j]%2;
			if(a[i][j])b[i]++;
		}
	}
	int n=0;
	int e,f;
	for(int i=0;i<h;i++){
		e=0;f=-1;
		for(int j=0;j<b[i]/2;j++){
			e=f+1;
			while(a[i][e]%2==0)e++;
			f=e+1;
			while(a[i][f]%2==0)f++;
			n+=f-e;
			for(int k=f;k>e;k--){
				//printf("%d %d %d %d\n",i+1,k+1,i+1,k);
			}
		}
		if(b[i]%2){
			e=f+1;
			while(a[i][e]%2==0)e++;
			n+=w-1-e;
			for(int k=e;k<w-1;k++){
				//printf("%d %d %d %d\n",i+1,k+1,i+1,k);
			}
		}
	}
	int m=0;
	for(int i=0;i<h;i++){
		m+=b[i]%2;
	}
	f=-1;
	for(int i=0;i<m/2;i++){
		e=f+1;
		while(b[e]%2==0)e++;
		f=e+1;
		while(b[f]%2==0)f++;
		n+=f-e;
	}
	
	printf("%d\n",n);
	
	for(int i=0;i<h;i++){
		e=0;f=-1;
		for(int j=0;j<b[i]/2;j++){
			e=f+1;
			while(a[i][e]%2==0)e++;
			f=e+1;
			while(a[i][f]%2==0)f++;
			n+=f-e;
			for(int k=e;k<f;k++){
				printf("%d %d %d %d\n",i+1,k+1,i+1,k+2);
			}
		}
		if(b[i]%2){
			e=f+1;
			while(a[i][e]%2==0)e++;
			n+=w-1-e;
			for(int k=e;k<w-1;k++){
				printf("%d %d %d %d\n",i+1,k+1,i+1,k+2);
			}
		}
	}
	
	f=-1;
	for(int i=0;i<m/2;i++){
		e=f+1;
		while(b[e]%2==0)e++;
		f=e+1;
		while(b[f]%2==0)f++;
		n+=f-e;
		for(int k=f;k>e;k--){
			printf("%d %d %d %d\n",k+1,w,k,w);
		}
	}
}

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

#ifdef LOCAL
#include "debug.h"
#else
#define DEBUG(...)
#endif

struct mo_t {
  int n;
  vector<pair<int, int>> lr;
  mo_t(int _n) : n(_n) {}
  void add(int l, int r) { lr.emplace_back(l, r); }
  template <class AL, class AR, class RL, class RR, class O>
  void run(AL add_left, AR add_right, RL remove_left, RR remove_right, O out) {
    int q = size(lr), bs = n / clamp<int>(sqrt(q), 1, n);
    vector<int> ord(q);
    iota(begin(ord), end(ord), 0);
    sort(begin(ord), end(ord), [&](int i, int j) {
      auto [li, ri] = lr[i];
      auto [lj, rj] = lr[j];
      li /= bs, lj /= bs;
      return li != lj ? li < lj : li & 1 ? ri > rj : ri < rj;
    });
    int l = 0, r = 0;
    for (int i : ord) {
      auto [li, ri] = lr[i];
      while (l > li) add_left(--l);
      while (r < ri) add_right(r++);
      while (l < li) remove_left(l++);
      while (r > ri) remove_right(--r);
      out(i);
    }
  }
};

int main() {
  cin.tie(nullptr)->sync_with_stdio(false);
  int n, q;
  cin >> n >> q;
  vector<int> c(n);
  for (auto&& e : c) cin >> e, --e;
  mo_t mo(n);
  vector<int> res(q), cnt(n);
  int cur = 0;
  auto add = [&](int i) {
    cur += cnt[c[i]]++ == 0;
  };
  auto remove = [&](int i) {
    cur -= --cnt[c[i]] == 0;
  };
  auto out = [&](int id) {
    res[id] = cur;
  };
  while (q--) {
    int l, r;
    cin >> l >> r;
    --l;
    mo.add(l, r);
  }
  mo.run(add, add, remove, remove, out);
  for (int e : res) {
    cout << e << '\n';
  }
}


Measured memory_bytes: 15464
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
#include<unordered_map>
#include<fstream>
#include<list>
#include<functional>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pi;
typedef pair<double,double> pd;
typedef pair<double,ll> pdl;
#define F first
#define S second
const ll E=1e18+7;
const ll MOD=1000000007;




ll merge(vector<ll> &A,ll left,ll mid,ll right){
    ll n1 = mid - left;
    ll n2 = right - mid;
    vector<ll> L(n1+1,E),R(n2+1,E);
    ll count=0;
    for(int i=0;i<n1;i++){
        L[i] = A[left + i];
    }
    for(int i=0;i<n2;i++){
        R[i] = A[mid + i];
    }
    ll i = 0;
    ll j = 0;
    for(ll k=left;k<right;k++){
        count++;
        if(L[i] <= R[j]){
            A[k] = L[i];
            i++;
        }
        else{
            A[k] = R[j];
            j++;
        }
    }
    return count;
}

ll mergeSort(vector<ll> &A,ll left,ll right){
    ll count=0;
    if( left+1 < right){
        ll mid = (left + right)/2;
        count+=mergeSort(A, left, mid);
        count+=mergeSort(A, mid, right);
        count+=merge(A, left, mid, right);
    }
    return count;
}

int main(){
    ll n;
    cin>>n;
    vector<ll> a(n);
    for(int i=0;i<n;i++){cin>>a[i];}
    ll count=mergeSort(a,0,a.size());
    for(int i=0;i<n;i++){cout<<a[i]; if(i!=n-1){cout<<" ";}}
    cout<<endl<<count<<endl;
    return 0;
}



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

int main(){
  
  int N;
  
  cin >> N;
  
  char s[256];
  
  cin >> s;
  
  int r,b;
  
  for(int i=0; i < N; i++){
    if(s[i] == 'R')
      r++;
    
    else if(s[i] == 'B')
      b++;
  }
  
  if(r > b){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}
      
    

Measured memory_bytes: 256
#include <iostream>
#include <climits>
#include <set>
#include <string>
#include <algorithm>
#include <vector>
#define MAX 1000000007


using namespace std;
#define ll long long
#define dbg if(0)
#define ISRANGE(val,lo,hi) ((lo<=val)&&(val<hi))



int main(){
    ll ans,n;
    cin >>n;
    int flag=1;

    for(int i=0;i<50000;i++){
        if ((i*108)/100==n){
            cout <<i<<endl;
            flag=0;
            break;
        }
    }
    if (flag)cout<<":("<<endl;

    return 0;

}

Measured memory_bytes: 384
MOD = 1000000007
BITS = 61
n = gets.to_i
a = gets.split.map(&:to_i)

ans = 0

BITS.times {|b|
    popcnt = 0
    m = 1 << b
    a.each {|x|
        popcnt += 1 if x & m != 0
    }
    ans += popcnt * (n-popcnt) * 2**b
}

p ans % MOD

Measured memory_bytes: 36868
//Awwawa! Dis cold yis ratten buy tEMMIE!
#include <bits/stdc++.h>
#define ll long long
#define maxn 100005 /*rem*/
#define mod 998244353
#define db double
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define pi pair<int, int>
#define fi first
#define se second

template <typename T> bool chkmax(T &x,T y){return x<y?x=y,true:false;}
template <typename T> bool chkmin(T &x,T y){return x>y?x=y,true:false;}

using namespace std;
ll ksm(ll a, ll b) {
   if (!b) return 1;
   ll ns = ksm(a, b >> 1);
   ns = ns * ns % mod;
   if (b & 1) ns = ns * a % mod;
   return ns;
}
int main() {
	int h1, h2, m1, m2, k;
	cin >> h1 >> m1 >> h2 >> m2 >> k;
	int ans = (h2 - h1) * 60 + (m2 - m1) - k;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3636
/*Whose woods these are I think I know.
His house is in the village though;
He will not see me stopping here
To watch his woods fill up with snow.

My little horse must think it queer
To stop without a farmhouse near
Between the woods and frozen lake
The darkest evening of the year.

He gives his harness bells a shake
To ask if there is some mistake.
The only other sound’s the sweep
Of easy wind and downy flake.

The woods are lovely, dark and deep,
But I have promises to keep,
And miles to go before I sleep,
And miles to go before I sleep.*/

#include<bits/stdc++.h>
using namespace std;
#define lli long long int
#define pb push_back
#define fi first
#define se second
#define MOD 1000000007
const int maxn= 100010;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int k=0,g=0;lli sum=0ll;
    cin>>k;
    for(int i=1;i<=k;++i)
        for(int j=1;j<=k;++j)
            for(int l=1;l<=k;++l)
            {
                g=__gcd(i,j);
                g=__gcd(g,l);
                sum+=g;
            }
    cout<<sum<<endl;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define OP ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define F first
#define S second
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int i = 0; i < n; ++i)
#define repr(i,n) for(int i = n - 1; i >= 0; --i)
#define Rep(i, a, n) for(int i = (a); i <=(n); ++i)
#define repst(i, n) for(auto it = n.begin(); it != n.end(); ++it)
#define Repr(i, a, n) for(int i = (n); i >= (a); --i)
typedef long long ll;
typedef std::vector<int> vi;
typedef std::pair<int, int> pii;
const int inf = int(1e9);
const int mod = inf + 7;
const double PI = acos(-1.0);
using namespace std;
const int N = 1e5 + 155;
template<typename T>
inline void read(T&x){
    x=0;int f=1;char ch = getchar();
    while(ch<'0' ||ch>'9'){ if(ch=='-')f=-1;ch=getchar(); }
    while(ch>='0' && ch<='9'){ x=x*10+ch-'0'; ch=getchar(); }
    x*=f;
}

void solve(){
    int n;
    cin >> n;
    int a[n];
    int sum = 0;
    rep(i, n) {
        cin >> a[i];
        sum += a[i];
    }
    sort(a, a + n);
    cout << sum - a[n - 1] / 2;
}
 
int main(){
    OP
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int t = 1;
    while(t--)
    solve();
    return 0;
}

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

using namespace std;

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

#define REP(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, a, b) for(int i=(a); i<(b); ++i)
#define FORR(i, a, b) for(int i=(b)-1; i>=(a); --i)

#define DEBUG(x) cout<<#x<<": "<<(x)<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";REP(i, v.size())cout<<' '<<v[i];cout<<'\n'
#define ALL(a) (a).begin(), (a).end()

template<typename T> inline void CHMAX(T& a, const T b) {if(a<b) a=b;}
template<typename T> inline void CHMIN(T& a, const T b) {if(a>b) a=b;}

constexpr ll MOD=1000000007ll;
// constexpr ll MOD=998244353ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

const double EPS=1e-9;
#define EQ0(x) (abs((x))<EPS)
#define EQ(a, b) (abs((a)-(b))<EPS)

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  // cout<<setprecision(10)<<fixed;
  int n, k, a[252521];
  cin>>n>>k;
  REP(i, n){
    cin>>a[i];
  }
  FOR(i, k, n){
    cout<<(a[i]>a[i-k] ? "Yes" : "No")<<'\n';
  }
  return 0;
}


Measured memory_bytes: 4444
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define all(a) (a).begin(), (a).end()

using ll = long long;

ll N, K;
std::vector<ll> xs;
ll c = -1;
ll ans = std::numeric_limits<ll>::max()>>2;

int main()
{
  scanf( "%lld%lld", &N, &K );

  rep( i, N )
  {
    ll x;
    scanf( "%lld", &x );
    xs.emplace_back( x );


    if( c == -1 && x >= 0 )
      c = i;
    
    if( x == 0 )
      --N, --K, xs.pop_back();
  }

  if( c == -1 )
    c = N;

  if( K <= 0 )
  {
    puts("0");

    return 0;
  }

  rep( i, c+1 )
  {
    if( c+K-i-1 >= N )
      continue;

    //printf( "[%d] %lld+%lld\n", i, xs[c-i], xs[c+K-i-1] );

    if( !i )
      ans = std::min( ans, llabs(xs[c+K-1]) );

    if( xs[c+K-1-i] < 0 )
      ans = std::min( ans, llabs(xs[c-K]) );
    
    if( xs[c-i] < 0 && xs[c+K-i-1] > 0 )
    {
      ans = std::min( ans, 2*llabs(xs[c-i])+llabs(xs[c+K-i-1]) );
      ans = std::min( ans, llabs(xs[c-i])+2*llabs(xs[c+K-i-1]) );
    }
  }
  
  printf( "%lld\n", ans );

  return 0;
}

Measured memory_bytes: 1400
def p_a():
    n = input()
    b = ""
    for i in n:
        if b == i:
            print("Bad")
            exit()
        b = i
    print("Good")

def p_b():
    pass


def p_c():
    pass


def p_d():
    pass


def p_e():
    pass


def p_f():
    pass


if __name__ == '__main__':
    p_a()


Measured memory_bytes: 38512
#include <iostream>
using namespace std;
int cost[5]={0,6000,4000,3000,2000};
int main() {
	int t,n;
	for(int i=0;i<4;i++)
	{
		cin >> t >> n;
		cout << cost[t]*n << endl;
	}
	return 0;
}

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

using ll=long long;
const ll MOD=1e9+7;

int main(){
  int A,B,C,D;
  cin >> A >> B >> C >> D;
  int owari=min(B,D);
  int hajimari=max(A,C);
  int ans=max(0,owari-hajimari);
  cout << ans << endl;
}

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

int main() {
	int N, K;
	cin >> N >> K;
	bool A[N];
	for (int i = 0; i < N; i++)
		A[i] = false;
	for (int i = 0; i < K; i++) {
		int d;
		cin >> d;
		for (int j = 0; j < d; j++) {
			int Ai;
			cin >> Ai;
			A[Ai-1] = true;
		}
	}
	int cnt = 0;
	for (int i = 0; i < N; i++) {
		if (A[i] == false)
			cnt++;
	}
	cout << cnt << endl;
	return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
using ll = long long;


int main(){
    string N;
    cin >> N;
    ll size = N.size();


    // 最上位桁を繰り上げると1,繰り上げないと0
    ll dp[size+1][2] = {};
    bool moveUp =false;
    dp[1][0] = N[size-1]-'0';
    dp[1][1] = 10-(N[size-1]-'0');
    for(ll i=1LL;i<size;i++){
        int digit = N[size-1-i] - '0';
        if(digit == 9){
            dp[i+1][0] = dp[i][1] + digit;
        }else{
            dp[i+1][0] = min(dp[i][0] + digit,dp[i][1] +digit+1);
        }
        dp[i+1][1] = min(dp[i][0] +(10-digit),dp[i][1] +(9-digit) );
    }

    cout << min(dp[size][0],dp[size][1]+1) << endl;
    
    return 0;
}

Measured memory_bytes: 17028
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <cstdio>
#include <string>
#include <vector>
#include <random>
#include <chrono>
#include <utility>
#include <numeric>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <sstream>
#include <assert.h>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <unordered_map>
using namespace std;

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(bool x) {cerr << (x ? "true" : "false");}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}

template<typename T, typename V> void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i : x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";} void _print() {cerr << "]\n";}
template <typename T, typename... V>void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifdef HOME
#warning CHECK int:ll::INT_MAX:LLONG_MAX
#define maxn 20
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define maxn 2000006
#define gcd __gcd
#define debug(x...)
#endif

#define ff first
#define endl '\n'
#define ss second
#define inf 0x3f3f3f3f
#define MOD 1000000007
#define PI 3.14159265358979323846264338327950L
#define f(i,x,n) for(int i=x;i<=n;i++)
#define fr(i,x,n) for(int i=x;i>=n;i--)
struct _ { ios_base::Init i; _() { ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); } } _;

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


int main() {

	string s; cin >> s;
	cout << string(s.length(), 'x');

	return 0;
}

Measured memory_bytes: 3092
#define _USE_MATH_DEFINES

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>

using namespace std;

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

long long int INF = 1e18;
long long int MOD = 1e9 + 7;

int main(){
	
	int N, H, W;
	cin >> N >> H >> W;
	
	cout << (N - H + 1) * (N - W + 1) << endl;
	
	return 0;
}


Measured memory_bytes: 256
from itertools import combinations
initials = {'M':0,'A':0,'R':0,'C':0,'H':0}
for _ in range(int(input())):
  name = input()
  initials[name[0]] = initials.get(name[0],0)+1
answer = 0
for initial in combinations('MARCH',3):
  answer += initials[initial[0]]*initials[initial[1]]*initials[initial[2]]
print(answer)

Measured memory_bytes: 9212
using System;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using static System.Console;

namespace ConsoleApp2
{
    class Program
    {
        static public int[] Sarray() { return ReadLine().Split().Select(int.Parse).ToArray(); }
        static public List<int> Slist() { return new List<int>(ReadLine().Split().Select(int.Parse)); }
        static void Main(string[] args)
        {
            var AB = Sarray();
            WriteLine(AB[0] * AB[1]);
        }

    }
}


Measured memory_bytes: 28084
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;

#define pb(a) push_back(a)
#define all(x) (x).begin(), (x).end()

#define FOR(i, a, n) for (int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define SORT(a) sort(all(a))
#define REVERSE(a) reverse(all(a))

#define PRINT(str) printf(#str "\n")
#define yOUT PRINT(Yes)
#define nOUT PRINT(No)
#define YOUT PRINT(YES)
#define NOUT PRINT(NO)

//関数定義
//最大公約数
ll gcd(ll a, ll b);

//最小公倍数
ll lcm(ll a, ll b);

int main() {
  // ========================================================
  string a, b, c;
  cin >> a >> b;
  int num1, num2;
  cin >> num1 >> num2 >> c;
  if (a == c)
    num1--;
  else
    num2--;
  cout << num1 << " " << num2 << endl;
}

//最大公約数
ll gcd(ll a, ll b) {
  if (!b) return a;
  return gcd(b, a % b);
}

//最小公倍数
ll lcm(ll a, ll b) { return a * b / gcd(a, b); }

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

using namespace std;

typedef long long ll;
typedef vector <ll> v_ll;
typedef vector <vector <ll> > vv_ll;
typedef vector < pair <ll,ll> > vp_ll;
typedef vector < vector < pair <ll,ll> > > vvp_ll;
typedef pair <ll,ll> p_ll;

ll M,K;

int main(){
  cin >>M >> K;
  ll mx=((1<<M)-1);
  if (K>mx){cout << -1 << endl;return 0;}
  if (M==1){
    if (K==0){cout << "0 0 1 1" << endl;return 0;}
    //if (K==1){cout << -1 << endl;return 0;}
    cout << -1 << endl;
    return 0;
  }

  cout << K;
  for(ll i=0;i<=mx;i++){
    if (K!=i){
      cout <<" "<< i;
    }
  }
  cout <<" "<< K;
  for(ll i=mx;i>=0;i--){
    if (K!=i){
      cout <<" "<< i;
    }
  }
  cout << endl;
}


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

int a[100];

int main()

{	
	int s=0, n, max,min;
	cin >> n;
	for (int i=0;i<n;i++)
	{
		cin >>a[i];
	}
	max=a[0];
	min=a[0];
	for (int i=0;i<n;i++)
	{
		if(a[i]>max)
		max=a[i];
		if(a[i]<min)
		min=a[i];
	}
	cout << max-min;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args){
    
    Scanner sc = new Scanner(System.in);
        String n = sc.next();
        char[]nn = n.toCharArray();

        for(int i=0; i<3; i++){               
            if(nn[i]=='1'){
                System.out.print('9'); 
            }else{
                System.out.print('1');                 
            }
 	    }
}
}


Measured memory_bytes: 23892
#pragma GCC optimize("O3")
#pragma GCC target("avx")
#include <stdio.h>
#include <stdlib.h>
#define min(a, b) ((a) < (b) ? (a) : (b))
#define max(a, b) ((a) > (b) ? (a) : (b))
#define abs(a) ((a) > 0 ? (a) : (-1 * (a)))
#define rep(i, n) for ((i) = 0; (i) < (n); (i)++)
#define rep2(i, s, e) for ((i) = (s); (i) < (e); (i)++)

void marge(int *, int);

int a[200010], p[200010], m[200010];
int main(void)
{

    int i, j, n, pi = 1, mp = 0, mi = 0, p1;
    long long total = 0;
    scanf("%d", &n);
    rep(i, n)
    {
        scanf("%d", a + i);
        p[i] = i + a[i];
        m[i] = i - a[i];
    }
    marge(p, n);
    marge(m, n);
    p[n] = p[n - 1] + 1;
    rep2(i, 1, n + 1)
    {
        p1 = p[i - 1];
        if (p[i] < m[mp])
            continue;
        while (p1 > m[mp] && mp < n)
            mp++;
        if (p[i] == p[i - 1])
        {
            pi++;
            continue;
        }

        rep2(j, mp, n)
        {
            if (p1 > m[j])
            {
                continue;
            }
            else if (p1 == m[j])
            {
                total += pi;
            }
            else
            {
                mp = j;
                break;
            }
        }
        pi = 1;
    }

    printf("%lld", total);
    return 0;
}

void marge(int *a, int n)
{

    if (n == 1)
        return;

    int *tmp;
    tmp = (int *)malloc((n) * sizeof(int));
    marge(a, n / 2);
    marge(a + n / 2, n - n / 2);

    for (int i = 0; i < n / 2; i++)
        tmp[i] = a[i];
    for (int i = n / 2; i < n; i++)
        tmp[i] = a[n / 2 + n - i - 1];

    int lp = 0, rp = n - 1, p = 0;
    int l3, r3;
    while (p < n)
    {
        l3 = tmp[lp];
        r3 = tmp[rp];
        if (l3 < r3)
        {
            a[p] = l3;
            lp++;
            p++;
        }
        else
        {
            a[p] = r3;
            rp--;
            p++;
        }
    }

    return;
}

Measured memory_bytes: 39000
#include <bits/stdc++.h>
using namespace std;
int main() {
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  if(abs(a-c)<=d)
    cout<<"Yes"<<endl;
  else if(abs(a-b)<=d&&abs(b-c)<=d)
    cout<<"Yes"<<endl;
  else
    cout<<"No"<<endl;
}

Measured memory_bytes: 256
n, x = map(int, input().split())
a = list(map(int, input().split()))+[0]
ans = 0
for i in range(n):
    if a[i+1] + a[i] <= x:
        continue
    else:
        ans += (a[i+1] + a[i] - x)
        a[i+1] = max(0, x - a[i])
        # print(ans)
        # print(a)
print(ans)

Measured memory_bytes: 14540
N, A, B, C = gets.split.map(&:to_i)
L = N.times.map{gets.to_i}

def calc(i, j, xs, z)
  mp = (j - i) * 10
  while i <= j
    z -= xs[i]
    i += 1
  end
  z.abs + mp
end

ans = Float::INFINITY
L.permutation(N).each do |ar|
  for i in 0...(N - 2)
    a = calc(0, i, ar, A)
    next if a >= ans
    for j in (i + 1)...(N - 1)
      b = calc(i + 1, j, ar, B)
      next if a + b >= ans
      for k in (j + 1)...N
        c = calc(j + 1, k, ar, C)
        tot = a + b + c  
        ans = tot if tot < ans 
      end 
    end 
  end 
end 
puts ans

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

int main() {
    int N, Cx, Cy, xdif, ydif, k, temp_H;

    cin >> N;

    int x[N], y[N], h[N];


    for (k=0; k<N; k++){
        cin >> x[k];
        cin >> y[k];
        cin >> h[k];
    }

    for (Cx = 0; Cx <= 100; Cx++){
        for (Cy = 0; Cy <= 100; Cy++){

            for (k=0; k<N; k++){
                if (h[k]>0){
                    xdif = max(x[k] - Cx, Cx - x[k]);
                    ydif = max(y[k] - Cy, Cy - y[k]);
                    temp_H = h[k] + xdif + ydif;
                    break;
                }
            }

            for (k=0; k<N; k++){
                xdif = max(x[k] - Cx, Cx - x[k]);
                ydif = max(y[k] - Cy, Cy - y[k]);
                if (h[k] != max(temp_H - xdif - ydif, 0) ) break;
                }

            if (k==N){
                cout << Cx << ' ';
                cout << Cy << ' ';
                cout << temp_H << '\n';
                Cx = 101;
                Cy = 101;
            }

            }
        }
    }


Measured memory_bytes: 256
# import sys
# sys.setrecursionlimit(10 ** 6)
# import bisect
# from collections import deque
# from decorator import stop_watch
# 
# 
# @stop_watch
def solve(N, X, M):
    mods = [-1 for i in range(M)]
    number = 1
    mods[X] = number
    An = X ** 2 % M
    while mods[An] == -1:
        number += 1
        mods[An] = number
        # print('aaa', An, mods[An],An ** 2 % M)
        An = An ** 2 % M
    # print(An, mods[An], max(mods))
    loop_num = max(mods) - (mods[An] - 1)
    tag = (N - (mods[An] - 1)) % loop_num
    ans = 0
    for i in range(M):
        # if mods[i] - 1 == tag:
        #     print(i)
        #     return
        if mods[i] == -1:
            continue
        elif mods[i] < mods[An]:
            ans += i
        else:
            x = N - (mods[An] - 1)
            if tag != 0 and mods[i] - mods[An] < tag:
                ans += i * (x // loop_num + 1) if x >= 0 else 0
            else:
                ans += i * (x // loop_num) if x >= 0 else 0
    print(ans)



if __name__ == '__main__':
    # S = input()
    # N = int(input())
    N, X, M = map(int, input().split())
    # A = [int(i) for i in input().split()]
    # B = [int(i) for i in input().split()]
    # AB = [[int(i) for i in input().split()] for _ in range(N)]
    solve(N, X, M)

    # # test
    # from random import randint
    # from func import random_str
    # solve()


Measured memory_bytes: 11316
#include <bits/stdc++.h>
typedef long long lint;
using namespace std;

int main() {
    string s;
    cin >> s;
    int ans;
    if (s == "RRR") {
        ans = 3;
    } else if (s == "RRS" || s == "SRR") {
        ans = 2;
    } else if (s == "SSS") {
        ans = 0;
    } else {
        ans = 1;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3604