akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>x;
	cout<<x/3<<endl;
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 256
#define __USE_MINGW_ANSI_STDIO 0
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <set>
using namespace std;


int sumdigit(int x){
   int sum = 0;
    while(x != 0){
        sum += x % 10;
        x /= 10;
    }
    return sum;
}
int main(){
   int N;
   cin >> N;
   if(N % sumdigit(N) == 0) cout << "Yes" << endl;
   else cout << "No" << endl;
   

}



Measured memory_bytes: 256
#include <stdio.h>
#include<stdlib.h>
int main()
{
    int k,n,i,max,t;
    int a[200000];
    scanf("%d %d",&k,&n);
    for(i=0;i<n;i++)
        scanf("%d",&a[i]);
    max=a[1]-a[0];
    for(i=2;i<n;i++)
    {
        if(max<(a[i]-a[i-1]))
            max=a[i]-a[i-1];
    }
    t=k-a[n-1]+a[0];
    if(t>max)
        max=t;
    printf("%d",k-max);
}


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

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

    for (size_t i = s.size()-1; i > 0; --i)
    {
        size_t size = i/2;
        if (s.substr(0, size) == s.substr(size, size))
        {
            cout << 2*size << endl;
            break;
        }
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
double a[10][10];
int main()
{
    for(int k = 1;k <= 3;k++)
        for(int j = 1;j <= 3;j++)
            cin >> a[k][j];
    if(a[1][2] + a[2][3] + a[3][1] + a[1][3] + a[2][1] + a[3][2] == (a[1][1] + a[2][2] + a[3][3]) * 2)
        cout << "Yes";
    else
        cout << "No";
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int H=1,W=1,i=1,s,w=1;
  while(w == 1){
    scanf("%d%d",&H,&W);
    if(H == 0 && W == 0)break;
    for(s=0;s<H;s++){
      for(i=0;i<W-1;i++)printf("#");
      printf("#\n");
     
    }printf("\n");
  }
  
  return 0;
}

Measured memory_bytes: 588
#include <stdio.h>
int main() {
  int N, count, num, i;
  count = 0;
  num = 1;
  scanf("%d", &N);
  int a[N];
  for (i = 0; i < N; ++i) {
    scanf("%d", &a[i]);
    if (num == a[i]) {
      ++num;
    } else {
      ++count;
    }
  }
  if (count == N) {
    printf("-1\n");
  } else {
    printf("%d\n", count);
  }
  return 0;
}

Measured memory_bytes: 896
#include<bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
string s;
cin>> s;
int max=0;
int x=0;
for(int i=0;i<n;i++){
	if(s[i]=='I'){
		x++;
	}else if(s[i]=='D'){
		x--;
	}
	if(x>=max){
		max=x;
	}
}
	cout <<max;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void) {
	// ????????¢???????????¨???
	int height, width;
	// ??¢?????¨?????¨
	int area, circum;
	cin >> height >> width;
	area = height * width;
	circum = (height + width) * 2;
	cout << area << " " << circum << endl;
	return 0;
}

Measured memory_bytes: 1164
# -*- coding: utf-8 -*-

import sys
import copy

sys.setrecursionlimit(1000000)

# input = sys.stdin.readline

# ~~~~~~~~~~~~~~~~~~~~~_(＾～＾ ｣ ∠)_~~~~~~~~~~~~~~~~~~~~~

N = int(input())

V = list(map(int, input().split()))
C = list(map(int, input().split()))

ans = 0
for i in range(N):
    ans += max(0, V[i] - C[i])

print(ans)

Measured memory_bytes: 3444
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define LINF (ll)INF*INF
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(int i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

#define int ll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef vector<pii> vp;

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


signed main(void) {
    int n;
    bool c = false;
    while(cin >> n){
        if(c)cout << endl;
        c = true;
        vs s(8,"     ");
        rep(i,5){
            if(n%10 >= 5)s[1][4-i] = '*';
            else s[0][4-i] = '*';
            s[2][4-i] = '=';
            switch (n%5) {
                case 0: s[4][4-i] = s[5][4-i] = s[6][4-i] = s[7][4-i] = '*';break;
                case 1: s[3][4-i] = s[5][4-i] = s[6][4-i] = s[7][4-i] = '*';break;
                case 2: s[3][4-i] = s[4][4-i] = s[6][4-i] = s[7][4-i] = '*';break;
                case 3: s[3][4-i] = s[4][4-i] = s[5][4-i] = s[7][4-i] = '*';break;
                case 4: s[3][4-i] = s[4][4-i] = s[5][4-i] = s[6][4-i] = '*';break;
            }
            n /= 10;
        }
        rep(i,8)cout << s[i] << endl;
    }

}



Measured memory_bytes: 3088
#include <bits/stdc++.h>
 
#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
 
#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=(int)(a)-1;i>=(int)(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)
 
#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define bit(n) (1LL<<(n))
 
// #define DEBUG
 
#ifdef DEBUG
    #define dump(...) fprintf(stderr, __VA_ARGS__)
#else
    #define dump(...)
#endif
 
template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}
 
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
 
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int inf = INT_MAX;
const ll INF = LLONG_MAX;
const ll MOD = 1000000007LL;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
 
ll extgcd(ll a,ll b,ll& x,ll& y){x=1,y=0;ll g=a;if(b!=0) g=extgcd(b,a%b,y,x),y-=a/b*x;return g;}
ll ADD(const ll &a, const ll &b, const ll mod=MOD) { return (a+b)%mod;}
ll SUB(const ll &a, const ll &b, const ll mod=MOD) { return (a-b+mod)%mod;}
ll MUL(const ll &a, const ll &b, const ll mod=MOD) { return (1LL*a*b)%mod;}
ll DIV(const ll &a, const ll &b, const ll mod=MOD) {ll x,y; extgcd(b,mod,x,y);return MUL(a,(x+mod)%mod,mod);}
 
int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n; cin >> n;

    vi hist(n+1);
    rep(i, 1, n+1){
        int x = i;
        rep(j, 2, n+1){
            while(x % j == 0){
                hist[j]++;
                x /= j;
            }
        }
    }

    const int M = 76;
    vi dp(M); dp[1] = 1;
    rep(i, 1, n+1){
        if(hist[i] == 0) continue;

        rrep(k, M){
            if(dp[k] == 0) continue;

            rep(j, 1, hist[i]+1){
                int nk = k * (j + 1);
                if(nk >= M) continue;

                dp[nk] += dp[k];
            }
        }
    }

    cout << dp[M-1] << endl;

    return 0;
}


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

#define REP(i,n) for(ll i=0;i<(ll)n;i++)
#define dump(x)  cerr << "Line " << __LINE__ << ": " <<  #x << " = " << (x) << "\n";
#define spa << " " <<
#define fi first
#define se second
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()

using ld = long double;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pdd = pair<ld, ld>;

template<typename T> using V = vector<T>;
template<typename T> using P = pair<T, T>;
template<typename T> vector<T> make_vec(size_t n, T a) { return vector<T>(n, a); }
template<typename... Ts> auto make_vec(size_t n, Ts... ts) { return vector<decltype(make_vec(ts...))>(n, make_vec(ts...)); }
template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){os << "(" << v.first << ", " << v.second << ")"; return os;}
template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { for (auto &e : v) os << e << ' '; return os; }
template<class T> ostream& operator<<(ostream& os, const vector<vector<T>> &v){ for(auto &e : v){os << e << "\n";} return os;}
struct fast_ios { fast_ios(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;

template <class T> void UNIQUE(vector<T> &x) {sort(ALL(x));x.erase(unique(ALL(x)), x.end());}
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
void fail() { cout << -1 << '\n'; exit(0); }
inline int popcount(const int x) { return __builtin_popcount(x); }
inline int popcount(const ll x) { return __builtin_popcountll(x); }
template<typename T> void debug(vector<vector<T>>&v,ll h,ll w){for(ll i=0;i<h;i++)
{cerr<<v[i][0];for(ll j=1;j<w;j++)cerr spa v[i][j];cerr<<"\n";}};
template<typename T> void debug(vector<T>&v,ll n){if(n!=0)cerr<<v[0];
for(ll i=1;i<n;i++)cerr spa v[i];
cerr<<"\n";};

const ll INF = (1ll<<62);
// const ld EPS   = 1e-10;
// const ld PI    = acos(-1.0);
const ll mod = (int)1e9 + 7;
//const ll mod = 998244353;

int main(){

    ll N, M;
    cin >> N >> M;

    scc_graph G(N);
    REP(i, M){
        ll a, b;
        cin >> a >> b;
        G.add_edge(a, b);
    }

    auto res = G.scc();
    
    cout << res.size() << endl;
    for(auto &v: res){
        cout << v.size() << " ";
        cout << v << endl;
    }

    return 0;
}

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

using namespace std;

#define sint(a) scanf("%d",&a)
#define sint2(a,b) scanf("%d %d",&a,&b)
#define sll(a) scanf("%lld",&a)
#define sll2(a,b) scanf("%lld %lld",&a,&b)
#define ll long long
const double pi=acos(-1);
const int maxn=1e6+10;
const int mod=1e9+7;


int main()
{
    double n;
    cin>>n;
    printf("%f",(n/3)*(n/3)*(n/3));
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, start, end) for (long long i = start; i < end; ++i)
#define repreverse(i, start, end) for (long long i = start; i >= end; --i)
#define all(x) (x).begin(), (x).end()
#define len(x) ((long long)(x).size())
#define g(a, b) __gcd((a), (b))
#define l(a, b) ((a) / __gcd((a), (b)) * (b))
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vllvll = vector<vll>;
using pll = pair<ll, ll>;
template<class T>void print1d(T x,ll n=-1){if(n==-1)n=x.size();rep(i,0,n){cout<<x[i]<<' ';}cout<<'\n';}
template<class T>void print2d(T x,ll r=-1,ll c=-1){if(r==-1)r=x.size();if(c==-1)c=x[0].size();rep(i,0,r)print1d(x[i],c);}
template<class T, class U>bool haskey(T mp, U key) { return mp.find(key) != mp.end(); }
template<class T, class U>bool isin(T el, U container) { return find(all(container), el) != container.end(); }
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
template<class T>ld deg2rad(T deg) { return M_PI * deg / 180.0; }
template<class T>ld rad2deg(T rad) { return 180.0 * rad / M_PI; }
ll intpow(ll a,ll n){ll p=1;while(n){if(n&1)p*=a;a*=a;n>>=1;}return p;}
const long double pi = M_PI;
const long long big = 1LL << 50;
const long long inf = 1LL << 60;
const long long mod = 1e9 + 7;



int main()
{
        string S, T;
        cin >> S >> T;
        map<char, ll> mp1, mp2;
        rep(i, 0, len(S)) mp1[S[i]]++;
        rep(i, 0, len(T)) mp2[T[i]]++;

        multiset<ll> ms1, ms2;
        for (auto el : mp1) {
                ms1.insert(el.second);
        }
        for (auto el : mp2) {
                ms2.insert(el.second);
        }
        multiset<ll> res;
        set_intersection(all(ms1), all(ms2), inserter(res, res.begin()));
        if (len(res) == len(ms1)) {
                cout << "Yes" << endl;
        } else {
                cout << "No" << endl;
        }
}

Measured memory_bytes: 776
#include <bits/stdc++.h>
using namespace std;
#define FOR(I,A,B) for(int I = int(A); I < int(B); ++I)
#define FORR(I,A,B) for(int I = int((B)-1); I >= int(A); --I)

int main(){

	double dp[302][302][302]={};
	int n;
	cin >> n;
	int a[4]={};
	FOR(i,0,n){
		int k;
		cin >> k;
		a[k]++;
	}
	// (x+y+z)/n*dp[x][y][z] = dp[x-1][y][z] * x/n
	//				+dp[x+1][y-1][z] *y/n
	//				+dp[x][y+1][z-1] *z/n
	//				+ 1
  	// x,y,z->1,2,3個の皿の個数
  
  	// 式を見ると
  	// zが小さい方、yが小さい方、xが小さいものから決まっていく
	FOR(z,0,n+1){
		FOR(y,0,n+1){//FOR(z,0,a[2])としないように
			FOR(x,0,n+1){//FOR(z,0,a[1])としないように
				if(x==0&&y==0&&z==0)continue;
				if(x>0)dp[x][y][z] += dp[x-1][ y][ z] * (double)x/(double)n;
				if(y>0)dp[x][y][z] += dp[x+1][y-1][z] * (double)y/(double)n;
				if(z>0)dp[x][y][z] += dp[x][y+1][z-1] * (double)z/(double)n;
				dp[x][y][z] += 1.0;
				dp[x][y][z] /= double(x+y+z)/(double)n;
			}
		}
	}
	cout << setprecision(15) << dp[a[1]][a[2]][a[3]] << endl;
}

Measured memory_bytes: 215424
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {

    public static void main(String[] args) {
        FastScanner scan = new FastScanner(System.in);
        final int N = scan.nextInt();
        long[] A = new long[N + 1];
        for (int i = 0; i < N + 1; i++) {
            A[i] = scan.nextLong();
        }
        long[] B = new long[N];
        for (int i = 0; i < N; i++) {
            B[i] = scan.nextLong();
        }

        long totalBeated = 0;
        for (int i = 0; i < N; i++) {
            long beated = Long.min(A[i], B[i]);
            totalBeated += beated;
            B[i] -= beated;
            beated = Long.min(A[i + 1], B[i]);
            totalBeated += beated;
            A[i + 1] -= beated;
        }
        System.out.println(totalBeated);
    }

    static class FastScanner {
        private BufferedReader reader = null;
        private StringTokenizer tokenizer = null;

        public FastScanner(InputStream in) {
            reader = new BufferedReader(new InputStreamReader(in));
            tokenizer = null;
        }

        public String next() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public String nextLine() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    return reader.readLine();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }

            return tokenizer.nextToken("\n");
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public double nextDouble() {
             return Double.parseDouble(next());
         }

        public int[] nextIntArray(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++)
                a[i] = nextInt();
            return a;
        }

        public long[] nextLongArray(int n) {
            long[] a = new long[n];
            for (int i = 0; i < n; i++)
                a[i] = nextLong();
            return a;
        } 
    }
}

Measured memory_bytes: 44140
open System

let a,b,x=stdin.ReadLine().Split()|>Array.map double|>fun c -> double c.[0],double c.[1],double c.[2]
[<EntryPoint>]
let main argv =
    let f r = r*180.0/Math.PI
    let V =a*a*b
    if x>=(V/2.0) then atan (2.0*((a*a*b)-x)/(a*a*a)) else atan ((a*b*b)/(2.0*x))
    |>f
    |>stdout.WriteLine
    0

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

int main()
{
	int date[13][32];
	for(int i = 1;i<=31;i++)date[1][i] = i;
	for(int i = 1;i<=28;i++)date[2][i] = i+3;
	for(int i = 1;i<=31;i++)date[3][i] = i+4;
	for(int i = 1;i<=31;i++)date[4][i] = i;
	for(int i = 1;i<=31;i++)date[5][i] = i+2;
	for(int i = 1;i<=31;i++)date[6][i] = i+5;
	for(int i = 1;i<=31;i++)date[7][i] = i;
	for(int i = 1;i<=31;i++)date[8][i] = i+3;
	for(int i = 1;i<=31;i++)date[9][i] = i+6;
	for(int i = 1;i<=31;i++)date[10][i] = i+1;
	for(int i = 1;i<=31;i++)date[11][i] = i+4;
	for(int i = 1;i<=31;i++)date[12][i] = i+6;
	
	int month,day;
	while(true)
	{
		cin >> month;
		cin >> day;
		if(month==0&&day==0)break;
		switch (date[month][day] % 7)
		{
			case 0:
			cout << "Wednesday" << endl;
			break;
			case 1:
			cout << "Thursday" << endl;
			break;
			case 2:
			cout << "Friday" << endl;
			break;
			case 3:
			cout << "Saturday" << endl;
			break;
			case 4:
			cout << "Sunday" << endl;
			break;
			case 5:
			cout << "Monday" << endl;
			break;
			case 6:
			cout << "Tuesday" << endl;
			break;
		}

	}

	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#include <iostream>
#include <limits>
#include <numeric>
#include <type_traits>
 
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define srt(i) sort(i.begin(), i.end())
#define rvt(i) sort(i.begin(), i.end(), greater<int>())
 
int main() {
  string n;
  cin >> n;
 
  rep(i, 3){
    char c = n.at(i);
 
    if(c=='7') {
      cout << "Yes" << endl;
      return 0;
    }
  }
 
  cout << "No" << endl;
}

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

int main()
{
    
        ll h;
        cin >> h;
        ll height = log(h) / log(2);
        ll ans = 1;
        ll temp = 1;
        for (int i = 1; i <= height; i++) {
            ans = ans * 2;
            temp += ans;
        }
        cout << temp<<endl;
    
}

Measured memory_bytes: 3768
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int main(){
    ll a,b,c,k,ans=0;
    cin>>a>>b>>c>>k;
    ll temp = min(k,a);
    k-=temp;
    a-=temp;
    ans+=temp;
    if(k>0){
        temp = min(k,b);
        k-=temp;
        b-=temp;
        if(k>0){
            temp = min(k,c);
            k-=temp;
            ans-=temp;
            cout<<ans;
            return 0;
        }
        else{
            cout<<ans;
        }
    }
    else{
        cout<<ans;
    }
    return 0;
}

Measured memory_bytes: 3632
import java.util.*;
import java.util.stream.*;

public class Main {

  public static void main(String[] args) {
    Scanner in = new Scanner(System.in);
    int N = in.nextInt(), M = in.nextInt();
    Pair[] pair = new Pair[N];
    for (int i = 0; i < N; i++) {
      pair[i] = new Pair(in.nextInt(), in.nextInt());
    }
    Arrays.sort(pair, (x, y) -> x.A - y.A);
    PriorityQueue<Pair> pq = new PriorityQueue<>((x, y) -> y.B - x.B);
    int pos = 0;
    long ans = 0;
    for (int i = 1; i <= M; i++) {
      while (pos < N && pair[pos].A <= i) {
        pq.offer(pair[pos++]);
      }
      Pair p = pq.poll();
      if (p != null) {
        ans += p.B;
      }
    }
    System.out.println(ans);
  }
}

class Pair {
  int A, B;

  public Pair(int A, int B) {
    this.A = A;
    this.B = B;
  }

  public String toString() {
    return String.format("(%d, %d)", this.A, this.B);
  }
}


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



int main() {
 

  char a,b;
  cin>>a>>b;


  bool flg;
  if(a=='H'){
    if(b=='H')
      flg=true;
    else if(b=='D')
      flg=false;
  }else if(a=='D'){
    if(b=='H')
      flg=false;
    else if(b=='D')
      flg=true;
  }

  if(flg)
    cout<<'H'<<endl;
  else
    cout<<'D'<<endl;

	return 0;
}

Measured memory_bytes: 3592
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;

vector<int> lis(const vector<int> &a) {
/* #define Index_of(as, x) distance(as.begin(), lower_bound(as.begin(), as.end(),\ */
/*  x)) */ 
#define Index_of(as, x) \
  distance(as.begin(), upper_bound(as.begin(), as.end(), x))
  const int n = a.size();
  vector<int> A(n, INF);
  vector<int> id(n);
  for (int i = 0; i < n; ++i) {
    id[i] = Index_of(A, a[i]);
    A[id[i]] = a[i];
  }
  int m = *max_element(id.begin(), id.end());
  vector<int> b(m + 1);
  for (int i = n - 1; i >= 0; --i)
    if (id[i] == m) b[m--] = a[i];
  return b; 
}

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

  vector<int> A(N);
  REP(i, N) cin >> A[i];
  REP(i, N) A[i] *= -1;

  vector<int> vec = lis(A);

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

  return 0;
}

Measured memory_bytes: 3328
#include<bits/stdc++.h>
#define int long long
#define mx 105
using namespace std;
int n;
int weight[mx];
int value[mx];
int dp[105][100005];
int dfs(int n,int w){
	if(dp[n][w] != -1){
		return dp[n][w];
	}
	if(n == 0){
		return 0;
	}
	int a = dfs(n-1,w);
	int b = 0;
	if(w >= weight[n])
	b = dfs(n-1,w-weight[n]) + value[n];
	dp[n][w] = max(a,b);
	return max(a,b);
}
signed main(){
//	freopen("input.txt","r",stdin);
	int w;
	cin>>n>>w;
	for(int i=1;i<=n;i++){
		cin>>weight[i]>>value[i];
	}
	memset(dp,-1,sizeof(dp));
	cout<<dfs(n,w);
}

Measured memory_bytes: 82304
#pragma GCC optimize("Ofast")

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

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pop_b pop_back
#define pf push_front
#define pop_f pop_front
#define mt make_tuple
#define eb emplace_back
#define sf(x) sizeof(x)
#define len(x) x.length()
#define sz(x) x.size()
#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)

#define LB(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define UB(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
typedef long long ll;
typedef pair<ll,ll> ii;
typedef long double ld; 
typedef vector<int> vi;
typedef vector<set<ll>> vset;
typedef vector<ll> vl;
typedef vector<ld> vd;
typedef deque<ll> dql;
typedef deque<int> dqi;
typedef unsigned long long ull;
typedef tuple<int,int,int> State;

#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << ", ";
	err(++it, args...);
	cout<<"\n";
}

#define vmax(type)   std::numeric_limits<type>::max()
#define vmin(type)   std::numeric_limits<type>::min()
#define each(a,x) for( auto &a:(x))
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n) - 1; i >= 0; i--)
#define rep2(i, l, r) for (ll i = (l); i < (r); i++)
#define rep2r(i, l, r) for (ll i = (r) - 1; i >= (l); i--)
#define range(a) a.begin(), a.end()
#define deb(x) cout<<#x<<" "<<x<<endl;
#define cinai(a, n) vi a(n); rep(i, n) { cin>>a[i]; }
#define cinal(a, n) vl a(n); rep(i, n) { cin>>a[i]; }
#define coutai(a, n) rep(i, n) { cout<<a[i]<<" "; } ent;
#define coutal(a, n) rep(i, n) { cout<<a[i]<<" "; } ent;
#define ent cout<<endl;
#define resize_vec(a) a.resize(unique(a.begin(), a.end()) - a.begin());
#define ms(dp, x) memset(dp, x, sf(dp))
#define endl '\n'

ll powm(ll a, ll b, ll mod) {
	ll res=1;
	while(b) {
		if(b&1)
			res=(res*a)%mod;
		a=(a*a)%mod;
		b>>=1;
	}
	return res;
}

ll mod = 1e9 + 7;
const ll N = 1000005;
const ll inf = 1e9;

void solve()
{
	ll n, x, m;
	cin>>n>>x>>m;
	ll val = x;
	mod = m;
	map<ll, ll> mp;
	ll sum = 0;
	rep(i, min(100ll, n)){
		sum = (sum + val);
		val = (val * val)%mod;
	}
	if(n >= 100)
		n -= 100;
	else{
		cout<<sum<<endl;
		return;
	}
	ll cyc = 0, sum1 = 0;
	rep(i, 2*m+1){
		if(mp.find(val) != mp.end()){
			break;
		}
		sum1 += val;
		cyc++;
		mp[val] = i;
		val = (val * val) % m;
	}
	sum += sum1 * (n / cyc);
	rep(i, n%cyc){
		sum += val;
		val = (val * val) % mod;
	}
	cout<<sum<<endl;
}

// #define _DEBUG 
// #define testCases
signed main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);
	cout << fixed << setprecision(15);
	
	int tc = 1;
#ifdef testCases
	cin>>tc;
#endif
	while(tc--)
	{
#ifdef _DEBUG
	int tt = clock();
#endif
		solve();
		
#ifdef _DEBUG
		cerr << "TIME = " << clock() - tt << endl;
		tt = clock();
#endif
	}
	return 0;
}


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

int main(void){
  int r,D;int x[100];
  cin >> r >> D >> x[0];
  
  for(int i = 1; i<11;++i){
    x[i] = r * x[i-1] - D;
    cout << x[i] << endl;    
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define f first
#define s second
#define pb push_back
#define fix  cout<<std::fixed;
#define mk make_pair
#define N 100005
#define mod 1000000007
#define time  cerr<< '\n' << "Time elapsed :" << clock() * 1000.0 / CLOCKS_PER_SEC << " ms\n" ;
#define IOS        ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
int main()
{
  ll n;cin>>n;
  ll a[n+5];
  ll dp[n+5]={0};
  for(int i=1;i<=n;i++)
  {
    cin>>a[i];
  }
  dp[2]=abs(a[2]-a[1]);
  dp[1]=0;
  for(int i=3;i<=n;i++)
  {
    dp[i]=min( abs(a[i]-a[i-2])+dp[i-2], abs(a[i]-a[i-1])+dp[i-1] );
  }cout<<dp[n];

}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define REP(i, n) for(ll i = 0; i < (ll)n; i++)
#define REPvec(itr, mp) for(auto itr = mp.begin();itr != mp.end(); itr ++)
#define all(x) x.begin(), x.end()
#define MOD 1000000007//1e9+7
using namespace std;
typedef long long unsigned int ll;
typedef vector<int >    vecint;
typedef vector<double >    vecd;
typedef vector<vector<int> >  vec2int;
typedef vector<vector<double> >  vec2d;
typedef vector<ll >     vecll;
typedef vector<string > vecstr;
typedef vector<bool > vecbool;
typedef vector<vector< bool > > vec2bool;
typedef vector<bool > vecbool;
////////////////////////////////////////////////
int main()
{
  ll q, h, s, d; cin >> q >> h >> s >> d;
  ll n; cin >> n;
  ll x = min(4*q, min(2*h, s));
  // cout << x << endl;
  if(2*x <= d){
    cout << n*x << endl;
  }else{
    cout << d*(n/2) + x*(n - 2*(n/2)) << endl;
  }
} 


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

int main() {
    int N, K; cin >> N >> K;
    vector<int> A(N), M(N);
    REP(i, 0, N) cin >> A[i];

    M[0] = A[0];
    REP(i, 1, N) M[i] = max(M[i - 1], A[i]);

    ll ans = 1LL << 60;
    for (int bit = 0; bit < (1 << N); bit++) {

        int count = 1; ll prev = A[0], increase = 0;
        REP(i, 1, N) {
            int a = A[i]; ll prevMax = max(prev, (ll)M[i - 1]);
            if (bit & (1 << i)) {
                if (a <= prevMax) {
                    increase += prevMax - a + 1;
                    a = prevMax + 1;
                }
                count++;
                prev = a;
            }
        }
        if (count >= K) {
            // cout << "bit : " << bit << ", increase : " << increase << endl;
            ans = min(ans, increase);
        }
    }
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner

object Main {
  def main(args: Array[String]): Unit = {
    val sc: Scanner = new Scanner(System.in)
    val n: Int = sc.nextLine.toInt
    val a: Int = sc.nextLine.toInt

    if (n % 500 > a) println("No")
    else println("Yes")
  }

}


Measured memory_bytes: 25540
count = [[[0 for i in range(10)] for j in range(3)] for k in range(4)]
n = int(input())
for i in range(n):
    b,f,r,v = map(int,input().split())
    count[b-1][f-1][r-1] += v
fst = 1
for k in count:
    if fst == 1:
        fst = 0
    else:
        print("#"*20)
    for j in k:
        for i in j:
            print(" " + str(i),end = '')
        print()


Measured memory_bytes: 5624
#include<bits/stdc++.h>
using namespace std;
int main()
{
          string a,b;
          cin>>a;
          b=a;
          reverse(a.begin(),a.end());
          if(a[0]=='s')
                    cout<<b<<"es\n";
          else
                    cout<<b<<"s\n";
return 0;
}


Measured memory_bytes: 3596
//https://atcoder.jp/contests/abc165/tasks/abc165_d
//2020-05-02
#include <iostream>
#include <string>
#include <vector>
#include <array>
#include <queue>
#include <stack>
#include <deque>
#include <algorithm>
#include <functional>
#include <cmath>
#include <map>
#include <iomanip>
using namespace std;

int main()
{
    long long A,B,N;
    cin >> A >> B >> N;
    long long ans =0;
    if(N<B){
        ans = ((A*N)/B)-A*(N/B);
    }else{
        long long tmp = ((N/B)*B)-1;
        ans = (A*tmp)/B -A *(tmp/B);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3160
#include <iostream>
#include <string>
#include <algorithm>
#include <utility>
#include <iomanip>
#include <functional>
#include <queue>
#include <stack>
#include <map>
#include <vector>
#include <cmath>
#include <cctype>
#include <cstdio>
#define ll long long
#define INF 1e+15
#define MOD 1000000007
using namespace std;


int main(){
    ll y=0;
    double b=0;
    
    int N;
    cin >> N;
    
    for(int i=0; i<N; i++){
        double x;
        string u;
        cin >> x >> u;
        if(u=="JPY"){
            y+=x;
        }else{
            b+=x;
        }
    }
    
    cout<< fixed << setprecision(6) <<  y + 380000*b <<endl;
    return 0;
}


Measured memory_bytes: 256
from sys import stdin
N,A,B = [int(x) for x in stdin.readline().rstrip().split()]
if (B - A) % 2 == 0:
    print((B-A)//2)
else:
    ans1 = 0
    a1 = A
    b1 = B
    ans1 += (a1-1)
    b1 -= (a1-1)
    a1 = 1
    
    if b1 % 2 == 0:
        b1 -= 1
        ans1 += 1
    ans1 += ((b1 -1)//2)
    
    ans2 = 0
    a2 = A
    b2 = B
    ans2 += (N-B)
    a2 += (N-B)
    b2 += (N-B)
    if (a2 % 2) != (b2 % 2):
        a2 += 1
        ans2 += 1
    ans2 += ((b2 - a2)//2)
    print(min(ans1,ans2,B-1,N-A))

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


using namespace std;
long long a[100005];
int cmp(int x,int y) {


   return x>y;
}
int main() {

    int n;
    cin>>n;
    for(int i=0;i<n;i++) {
        scanf("%lld",&a[i]);

    }

    sort(a,a+n,cmp);

    int flag=0;
    int flag1=-1;
    int flag2=-1;
    for(int i=0;i<n-1;i++) {
        if(a[i]==a[i+1]) {
            flag++;
            i++;
            if(flag1==-1) {
                flag1=i;
                continue;
            }
            if(flag2==-1) {
                flag2=i;
            }
        }
        if(flag==2) {
            cout<<a[flag1]*a[flag2]<<endl;
            return 0;
        }
    }

    cout<<0<<endl;



    return 0;
}


Measured memory_bytes: 1024
#include <iostream>

using namespace std;

int main() {
    int n;
    cin >> n;
    bool ans = false;
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;
        if (a % 2 == 1) {
            ans = true;
            break;
        }
    }

    cout << (ans ? "first" : "second") << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <climits>
#include <cmath>
#include <string>
using namespace std;

typedef long long ll;
#define mk make_pair

#define FOR(i,m,n) for(ll i=m; i<n; i++)
#define FORIN(i,m,n) for(ll i=m; i<=n; i++)
#define FOR1(i,n) for(ll i=1; i<n; i++)
#define FOR0(i,n) for(ll i=0; i<n; i++)
#define COUT(x) cout << x
#define CIN(x) cin >> x
#define ENDL cout << endl
#define SPACE1 cout << " "
#define SPACE2 cout << "  "
#define SPACE3 cout << "   "
#define ALL(x) (x).begin(),(x).end()

template<typename T>
void DEBUG(string xxx,T x) {cout << xxx << ": " << x;}

ll lengthInteger(ll n)
{ ll i=1;  while(n/(ll)pow(10,i) > 0) i++;  return i;}

bool hasN(ll N, ll length, ll n)
{bool hasN=false;FOR0(i,length+1){if((n/(ll)pow(10,i)) % 10 == N) hasN=true;  }return hasN;}

ll GCD(ll a, ll b)
{if(a<b) swap(a,b);ll r;while(a%b != 0) {r = a%b;a = b;b = r;}return b;}

string S;
ll I[4];
vector<ll> answer(3);
bool dfs(ll d,vector<ll> bit) {
    if(d == 3) {
        ll sum = I[0];
        FOR(i,0,3) {
            if(bit[i] == 0) sum += I[i+1];
            else sum -= I[i+1];
        }
        if(sum == 7) {
            FOR(i,0,3) answer[i] = bit[i];
            return true;
        }
    } else {
        bool x,y;
        bit.push_back(0);
        x = dfs(d+1,bit);
        bit.pop_back();
        bit.push_back(1);
        y = dfs(d+1,bit);
        if(x||y) return true;
    }
    return false;
}

int main () {
    CIN(S);
    FOR(i,0,4) {
        I[i] = (ll)S[i] - 48;
    }

    vector<ll> a;
    dfs(0,a);

    FOR(i,0,3) {
        COUT(I[i]);
        if(answer[i] == 0) COUT('+');
        else COUT('-');
    }COUT(I[3]); COUT("=7"); ENDL;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define pii pair<int,int>
const long long MOD=1e9+7;

int main() {
  int a,b,c;
  cin>>a>>b>>c;
  bool ans=true;
  if(a==b && b==c) ans=false;
  if(a!=b && b!=c && c!=a) ans=false;
  if(ans) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  return 0;
}

Measured memory_bytes: 256
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#include <iostream>
#include <vector>
#include <algorithm>
#include <limits>
#include <utility>
#include <string>
#include <queue>
#include <cmath>
#include <array>

typedef long long ll;

ll solve(const std::string s)
{
    const int len = s.length();
    std::vector<int> count(2019, 0);
    std::vector<int> mul(2019, 0);
    std::vector<int> count_next(2019, 0);
    std::vector<int> mul_next(2019, 0);

    for (int i = 0; i < len; i++) {

        int n = s[i] - '0';
        if (i >= 3) {
            int m = (s[i - 3] - '0') * 100
                  + (s[i - 2] - '0') * 10
                  + (s[i - 1] - '0');
            mul[m]++;
        }

        for (int j = 0; j < 2019; j++) {
            int next = (j * 10 + n) % 2019;
            if (next == 0) {
                count[j] += mul[j];
            }
            count_next[next] = count[j];
            mul_next[next] = mul[j];
        }
        count_next.swap(count);
        mul_next.swap(mul);
    }

    ll ans = 0;
    for (int i = 0; i < 2019; i++) {
        ans += count[i];
    }

    return ans;
}

int main(int argc, char *argv[])
{
    std::string s;

    std::cin >> s;

    ll ans = solve(s);

    std::cout << ans << std::endl;

    return 0;
}


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

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<pii, int> data;

int l[1000000];
int n;

bool valid(int k) {
  vector<data> v;
  for(int i = 0; i < n; i++) {
    if(i == 0) {
      v.push_back({{1, l[i]}, 1});
      continue;
    }
    bool cleanse = false;
    while(true) {
      if(v.empty()) return false;
      data curr = v[v.size()-1];
      if(cleanse) {
        if(curr.second < k) {
          v.pop_back();
          if(curr.first.first < curr.first.second) {
            v.push_back({{curr.first.first, curr.first.second-1}, curr.second});
          }
          v.push_back({{curr.first.second, curr.first.second}, curr.second+1});
          v.push_back({{curr.first.second+1, l[i]}, 1});
          break;
        }
        else {
          v.pop_back();
          continue;
        }
      }
      else if(curr.first.first > l[i]) {
        v.pop_back();
      }
      else if(l[i] > curr.first.second) {
        v.push_back({{curr.first.second+1, l[i]}, 1});
        break;
      }
      else {
        // [curr.first, curr.second]
        // l[i] is >= curr.first, <= curr.second
        v.pop_back();
        int currD = curr.second;
        if(currD == k) {
          cleanse = true;
          continue;
        }
        if(l[i]-1 >= curr.first.first) v.push_back({{curr.first.first, l[i]-1}, currD});
        v.push_back({{l[i], l[i]}, currD+1});
        break;
      }
    }
    /*
    printf("AFTER %d\n", i);
    for(auto x: v) {
      printf("%d %d %d\n", x.first.first, x.first.second, x.second);
    }
    */
  }
  return true;
}

void solve() {
  cin >> n;
  for(int i = 0; i < n; i++) {
    cin >> l[i];
  }
  int lhs = 1;
  int rhs = n;
  while(lhs < rhs) {
    int mid = (lhs+rhs)/2;
    if(valid(mid)) rhs = mid;
    else lhs = mid+1;
  }
  cout << lhs << endl;
}


int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL); cout.tie(NULL);
  solve();
}


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

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;

    for (int i = 0; i < s.length(); ++i){
        if(i%2==0)cout << s[i];
    }
    cout << endl;
}

Measured memory_bytes: 592
def d_median_of_medians(N, A):
    class BIT(object):
        def __init__(self, n):
            self.size = n
            self.tree = [0] * (self.size + 1)

        def __str__(self):
            return '[{}]'.format(', '.join(map(str, self.tree)))

        def sum(self, index):
            # 1からindexまでの和を計算
            ret = 0
            x = index
            while x > 0:
                ret += self.tree[x]
                x -= x & (-x)
            return ret

        def add(self, index, value):
            # tree[index]にvalueを加算
            x = index
            while x <= self.size:
                self.tree[x] += value
                x += x & (-x)

    def pair(x):
        a_prime = [-1] * N
        for k in range(N):
            if A[k] >= x:
                a_prime[k] = 1  # x未満か否かを{-1, 1}に圧縮

        s = [0]
        min_s = 0
        max_s = 0
        tmp = 0
        # 累積和と最小値, 最大値を同時に計算
        for a in a_prime:
            tmp += a
            min_s = min(min_s, tmp)
            max_s = max(max_s, tmp)
            s.append(tmp)

        bit_size = max_s - min_s + 1  # BITのサイズ
        bit = BIT(bit_size)
        ans = 0
        for sk in s:
            sk -= (min_s - 1)  # sの最小値を1に調整
            ans += bit.sum(sk)
            bit.add(sk, 1)
        return ans

    # l<=rとなる(l, r)の取り方について、その半分以上の値を返す最大の値が中央値
    border_median = (N * (N + 1) // 2 + 1) // 2
    ok = 0
    ng = 10**9 + 3
    while ng - ok > 1:
        mid = (ok + ng) // 2
        if pair(mid) >= border_median:
            ok = mid
        else:
            ng = mid
    ans = ok
    return ans

N = int(input())
A = [int(i) for i in input().split()]
print(d_median_of_medians(N, A))

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

int main() {

	int X, Y, Z;
	cin >> X >> Y >> Z;

	int count = 0;
	X -= 2 * Z;

	while (X >= Y) {
		X -= Y;
		count++;
		X -= Z;
	}

	cout << count << endl;



	return 0;
}

Measured memory_bytes: 256
def main():
    n = int(input())
    A = list(map(int,input().split()))
    m = int(input())
    for _ in range(m):
        a,b,c = map(int,input().split())
        A[a:c] = A[b:c]+A[a:b]
    print (' '.join(map(str,A)))



if __name__ == '__main__':
    main()




Measured memory_bytes: 5640
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(ll i=(n)-1;i>=0;i--)
#define range(i,a,n) for(ll i=(a);i<(n);i++)
#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI (3.1415926535897932384)

int dx[]={1,0,-1,0,1,-1,-1,1},dy[]={0,1,0,-1,1,1,-1,-1};
template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S sumvec(vector<S>&a){return accumulate(all(a),S());}
template<class S>S maxvec(vector<S>&a){return *max_element(all(a));}
template<class S>S minvec(vector<S>&a){return *min_element(all(a));}
ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
int sgn(const double&r){return (r>EPS)-(r<-EPS);} // a>0  : sgn(a)>0
int sgn(const double&a,const double&b){return sgn(a-b);} // b<=c : sgn(b,c)<=0

template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>void tf(bool b,S t,T f){if(b)puta(t);else puta(f);}
void YN(bool b){tf(b,"YES","NO");}
void Yn(bool b){tf(b,"Yes","No");}
void yn(bool b){tf(b,"yes","no");}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1;for(auto s:t){os<<(a?"":" ")<<s;a=0;}return os;}
template<class S>auto&operator>>(istream&is,vector<S>&t){for(S&a:t)cin>>a;return is;}


int main(void){
  	cin.tie(0);
  	ios::sync_with_stdio(false);
  	
  	string s,t,u;
    ll a,b;
    cin>>s>>t>>a>>b>>u;
    
    if(s==u) a--;
    if(t==u) b--;
    cout<<a<<" "<<b<<endl;

}


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


#define long long long int

using namespace std;


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

    long n, m;
    cin >> n >> m;
    n = (n % m);
    cout << (min(n, abs(n - m)));
    return 0;
}




Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <climits>
#include <string>
#include <bitset>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<pair<string,int>> vpsi;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#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 fin(ans) cout<<(ans)<<endl
#define STI(s) atoi(s.c_str())
#define mp(p,q) make_pair(p,q)
#define pb(n) push_back(n)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define Sort(a) sort(a.begin(),a.end())
#define Rort(a) sort(a.rbegin(),a.rend())
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
const int P = 1000000007;
const int INF = INT_MAX;
const ll LLINF = 1LL<<60;

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

int n,m;
cin >> n >> m;
int p;
string s;
vector<bool> ac(n+1);
int a=0;
vi w(n+1);
for(int i=1;i<=m;++i){
    cin >> p >> s;
    if(ac[p])continue;
    if(s=="AC"){
        a++;
        ac[p]=true;
    }else{
        w[p]++;
    }
}
int ans=0;
for(int i=1;i<=n;++i){
    if(ac[i])ans+=w[i];
}
cout << a << " " << ans << endl;

//////////////////////////////////////////////////////
return 0;}


Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <climits>

using namespace std;

int main() {
    int n;
    cin >> n;
    vector<int> v[n];
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < 3; ++j) {
            int e;
            cin >> e;
            v[i].push_back(e);
        }
    }
    for (int i = 0; i < n - 1; ++i) {
        v[i+1][0] = max(v[i][1] + v[i + 1][0], v[i][2] + v[i + 1][0]);
        v[i+1][1] = max(v[i][0] + v[i + 1][1], v[i][2] + v[i + 1][1]);
        v[i+1][2] = max(v[i][0] + v[i + 1][2], v[i][1] + v[i + 1][2]);
    }
    printf("%d\n", max(v[n - 1][0], max(v[n - 1][1], v[n - 1][2])));
}

Measured memory_bytes: 5760
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}
fn main() {
    let v = read_vec::<usize>();
    let (n, m) = (v[0], v[1]);
    let a = read_vec::<usize>()
        .into_iter()
        .map(|x| x - 1)
        .collect::<Vec<_>>();
    let sum = (1..n)
        .map(|i| {
            if a[i] >= a[i - 1] {
                a[i] - a[i - 1]
            } else {
                m + a[i] - a[i - 1]
            }
        })
        .sum::<usize>() as i64;
    let mut count = vec![0i64; 2 * m];
    let mut rate = vec![0i64; 2 * m];
    for i in 1..n {
        let cost;
        if a[i] >= a[i - 1] {
            cost = a[i] - a[i - 1];
            count[a[i]] += 1;
            count[a[i - 1] + 1] -= 1;
            rate[a[i]] += cost as i64 - 1;
        } else {
            cost = m + a[i] - a[i - 1];
            count[m + a[i]] += 1;
            count[a[i - 1] + 1] -= 1;
            rate[m + a[i]] += cost as i64 - 1;
        }
    }
    let mut current_count = 0;
    let mut gain = vec![0; 2 * m];
    let mut current_gain = 0;
    for i in (0..2 * m).rev() {
        current_gain -= current_count;
        current_gain += rate[i];
        gain[i] = current_gain;
        current_count += count[i];
    }

    let gain = (0..m).map(|x| gain[x] + gain[m + x]).collect::<Vec<_>>();
    let max_gain = gain.iter().max().unwrap();
    println!("{}", sum - max_gain);
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


Measured memory_bytes: 12540