akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;
int main()
{
	int S, A, B;
	cin >> A >> B;

	S = A + B;
	if (S%2==0)
	{
		cout << S / 2 << endl;
	}
	else
	{
		cout << "IMPOSSIBLE" << endl;
	} 
}

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

const int N = 1e5 + 10;
const int mod = 1e9 + 7;

int n, a[N];
int solve(){
	int st = 0;
    if(n & 1){
        if(a[0] != 1)	return 0;
        st = 2;
    } else {
		st = 1;
    }
    int ans = 1;
    for(int i=st; i<=n; i+=2){
		if(a[i] != 2)	return 0;
		ans <<= 1;
		if(ans >= mod)	ans = ans - mod;
    }
    return ans;
}

int main(){
	int x;
	while(~scanf("%d", &n)){
		memset(a, 0, sizeof(a));
        for(int i=0; i<n; i++){
			scanf("%d", &x);
            if(x >= n){
				x = n;
            }
            a[x]++;
        }
        printf("%d\n", solve());
	}
	return 0;
}


Measured memory_bytes: 640
#include<iostream>
using std::cin;
using std::cout;
using std::endl;

#include<map>
using std::map;

#include<string>
using std::string;

#include<stdlib.h>
long long int P=1000000007;

int main(void){
	int N,M;
	long long int ans=1;
	scanf("%d %d",&N,&M);
	long long int a,b;

	if(N<M){a=M;b=N;}else{a=N;b=M;}
	if(a-b>1){printf("0");return 0;}

	for(int x=1;x<=a;x++){
		if(x<=b){
			ans=(ans*x)%P;
		}
		ans=(ans*x)%P;
	}
	if(a-b==0){
		ans=(ans*2)%P;
	}
	printf("%lld",ans);
	return 0;
}

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

int main(){
    double a, b, h, m;
    cin >> a >> b >> h >> m;
    double x;

    double y=360*(h/12)+m*0.5;
    double z=m*6;
    double c;
    if(y>=z) c=y-z;
    else c=z-y;
    if(c>180) c=360-c;
    c=(2*M_PI)*(c/360);

    x=a*a+b*b-2*a*b*cos(c);
    x=sqrt(x);

    cout << std::fixed << setprecision(20) << x << endl;
}

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


void dfs(int keta, ll val, vector<ll> &all){

    // cout << val << endl;
    all.push_back(val);
    if(keta >= 10) return;

    // 次のketaへ進む
    for(int v: {3, 5, 7}){
        dfs(keta+1, val*10+v, all);
    }
}

// header area
int main(){
    int N; cin >> N;
    vector<ll> all;
    for(int v: {3, 5, 7}){
        dfs(1, v, all);
    }

    sort(all.begin(), all.end());

    int count = 0;
    rep(i, (int)all.size()){
        if(all[i] > N) break;
        string st_all = to_string(all[i]);
        // cout << st_all <<endl;
        if(st_all.find("3")!=string::npos && st_all.find("5")!=string::npos  && st_all.find("7")!=string::npos){
            // cout << st_all <<endl;
            count++;
        }
        
    }

    cout << count << endl;
    
    return 0;
}

Measured memory_bytes: 1400
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
template<class T>inline bool chmax(T &a, const T &b){if(a < b){a = b; return 1;}return 0;}
template<class T>inline bool chmin(T &a, const T &b){if(a > b){a = b; return 1;}return 0;}
typedef long long ll;
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int A, B; cin >> A >> B;
  cout << max({A+B, A-B, A*B}) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int n,x;
	cin>>n;
	long long ans = 0, sum = 0;
	for(int i=1;i<=n;i++)
	{
		cin>>x;
		if(x==0)
		{
			ans+=sum/2;
			sum=0;
		}
		else sum += x;
	}
	cout<<ans+sum/2<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
long long N,a[100005],b[100005];
long long ans;
int main(void){
    cin>>N;
    for(int i=0;i<N;i++){
        cin>>a[i]>>b[i];
    }
    for(int i=N-1;i>=0;i--){
        if((a[i]+ans)%b[i]!=0){
            ans=ans+b[i]-(a[i]+ans)%b[i];
        }
    }
    cout<<ans<<endl;
    
}


Measured memory_bytes: 1792
import sys
input = sys.stdin.readline


n, m = map(int, input().split())
P = list(map(lambda x: int(x)-1, input().split()))


class UnionFind:
    def __init__(self, num):
        self.parent = list(range(num))

    def get_root(self, node):
        root = self.parent[node]
        if root == node:
            return root
        else:
            root = self.get_root(root)
            self.parent[node] = root
            return root

    def are_in_same_union(self, node1, node2):
        root1 = self.get_root(node1)
        root2 = self.get_root(node2)
        if root1 == root2:
            return True
        else:
            return False

    def unite(self, node1, node2):
        root1 = self.get_root(node1)
        root2 = self.get_root(node2)
        if root1 == root2:
            return
        self.parent[root2] = root1


uf = UnionFind(n)
for _ in range(m):
    x, y = map(int, input().split())
    x -= 1
    y -= 1
    uf.unite(x, y)


count = 0
for i in range(n):
    num = P[i]
    if num == i:
        count += 1
    else:
        if uf.are_in_same_union(i, num):
            count += 1

print(count)


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

int main() {
  ll x, y;
  cin >> x >> y;
  ll ans = (1LL << 31) - 1;

  ll x_inv = x * -1;
  ll y_inv = y * -1;

  if (x <= y) ans = min(ans, y - x);
  if (x <= y_inv) ans = min(ans, y_inv - x + 1);
  if (x_inv <= y) ans = min(ans, y - x_inv + 1);
  if (x_inv <= y_inv) ans = min(ans, y_inv - x_inv + 2);

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


Measured memory_bytes: 3604
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cwchar>
#include <cwctype>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <codecvt>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
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; }
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize("Ofast")
using namespace std;
typedef long long int ll;
typedef long double ld;
const ll INF=(1LL<<62);
const ld pi=acosl((ld)-1);
const ll mod = 1000000007;
// const ll mod = 1234567;
const int dx[4]={0,1,0,-1};
const int dy[4]={1,0,-1,0};
const int ddx[8]={1,0,-1,-1,-1,0,1,1};
const int ddy[8]={1,1,1,0,-1,-1,-1,0};
#define endn "\n"

bool solve(){
    ll n,q;cin>>n>>q;   
    vector<ll>v(n,0);
    while(q--){
        ll a,b;cin>>a>>b;a--;b--;
        v[a]++;
        v[b]++;
    }
    bool isOUT=false;
    rep(i,n)isOUT|=(v[i]%2);
    cout<<(isOUT ? "NO" : "YES")<<endl;
    return false;
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout<<fixed<<setprecision(30);
    solve();
}


Measured memory_bytes: 1152
import java.awt.Point;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;
public class Main{
    static char[][] mat;
    static int[][] cs;
    static int INF = Integer.MAX_VALUE/2;
    static int H,W;
    public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
        H = sc.nextInt();
        W = sc.nextInt();
        sc.nextLine();
        mat = new char[H][W];
        int posMarcadas = 0;
        int movX[] = new int[]{-1,1,0,0};
	int movY[] = new int[]{0,0,-1,1};
        
        String line;
        for(int i = 0; i < H; i++){
            line = sc.nextLine();
            for(int j = 0; j < W; j++){
                mat[i][j] = line.charAt(j);
                if(mat[i][j] == '#')
                    posMarcadas++;
            }
        }
        
        cs = new int[H][W];
        for(int[] c : cs)
            Arrays.fill(c, INF);
        cs[0][0] = 0;
        
        Queue<Pair<Integer, Point>> q = new LinkedList<Pair<Integer, Point>>();
        q.offer(new Pair(1, new Point(0,0)));
        Pair<Integer, Point> t;
        int x, y;
        int d;
        while(!q.isEmpty()){
            t = q.poll();
            d = t.first;
            x = t.second.x;
            y = t.second.y;
            
            if(x == H-1 && y == W-1)
                break;
            
            for(int i = 0; i < 4; i++){
                if(valido(x + movX[i], y + movY[i], d+1)){
                    q.offer(new Pair(d+1, new Point(x + movX[i], y + movY[i])));
                    cs[x + movX[i]][y + movY[i]] = d+1;
                }
            }
        }
        
        if(cs[H-1][W-1] != INF){
            System.out.println((H*W)-posMarcadas-cs[H-1][W-1]);
        }else{
            System.out.println(-1);
        }
    }
    private static boolean valido(int x, int y, int d){
        if(x >= 0 && x < H && y >= 0 && y < W && mat[x][y] == '.' && d < cs[x][y])
            return true;
        return false;
    }
    static class Pair<T, R>{
        T first;
        R second;
        public Pair(T f, R s){
            first = f;
            second = s;
        }
    }
}

Measured memory_bytes: 23892
#include <bits/stdc++.h>
#define rep(i, n) for(int i= 0; i < (n); i++)
using ll= long long int;
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
ll mod= 1e9 + 7;

struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }

    int size(int x) {
      int count=1;
        while(par[x]!=x){
          count++;
          x=par[x];
        };
      return count;
    }

};

int main() {
  int n;
  cin >>n;
  UnionFind tree(n);
  int m;
  cin >>m;

  rep(i,m){
    int a,b;
    cin >> a >>b;
    a--;b--;
    tree.unite(a,b);
  }
  int ans=0;
  int a[n]={};
  rep(i,n){
    a[tree.root(i)]++;
  }
  rep(i,n){chmax(ans,a[i]);}
  cout << ans << endl;
}

Measured memory_bytes: 11052
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
char a[5],b[5];
int main(){
	scanf("%s",a);
	scanf("%s",b);
	int cnt=0;
	for(int i=0;i<=2;i++)
		if(a[i]==b[i]) cnt++;
	cout<<cnt<<endl;
	return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include<bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=0;i<b;i++)
#define REP(i,a,b) for(int i=0;i<=b;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define inf (1ll<<60)
#define Yes(f) cout <<(f?"Yes":"No")<<endl//fが真の場合Yesを出力、偽の場合Noを出力
#define yes(f) cout <<(f?"yes":"no")<<endl
#define YES(f) cout <<(f?"YES":"NO")<<endl
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v),greater<int>())

using namespace std;

const int mod=1e9+7;

signed main(){
    int x,a;
    cin >> x >> a;
    if(x<a)
    {
        cout << 0 << endl;
        return 0;
    }
    else 
    {
        cout << 10 << endl;
        return 0;
    }
}


Measured memory_bytes: 256
N, K = map(int, input().split())
MOD = 998244353
move = []

for _ in range(K):
  L, R = map(int, input().split())
  move.append((L, R))

dp = [0]*N
dp[0] = 1
accumdp = [0, 1]

for i in range(1, N):
  for l, r in move:
    dp[i] += accumdp[max(i-l+1, 0)] - accumdp[max(i-r, 0)]
  dp[i] %= MOD
  accumdp.append((accumdp[-1] + dp[i])%MOD)

print(dp[-1])

Measured memory_bytes: 24820
import sys
input = lambda : sys.stdin.readline().rstrip()

def segfun(x, y):
    return min(x, y)
ide_ele = float("inf")


class SegmentTree:
    def __init__(self, n, ele, segfun):
        self.ide_ele = ele
        self.segfun = segfun
        self.n = n
        self.N0 = 1 << n.bit_length()
        self.data = [self.ide_ele] * (self.N0 * 2)
 
    def update(self, l, r, val):
        l += self.N0
        r += self.N0
        while l < r:
            if l & 1:
                self.data[l] = self.segfun(self.data[l], val)
                l += 1
            if r & 1:
                self.data[r - 1] = self.segfun(self.data[r - 1], val)
                r -= 1
            l //= 2
            r //= 2
 
    def query(self, i):
        i += len(self.data) // 2
        ret = self.data[i]
        while i > 0:
            i //= 2
            ret = self.segfun(ret, self.data[i])
        return ret


n, q = map(int, input().split())
stx = []
for _ in range(n):
    s, t, x = map(int, input().split())
    stx.append([x, s - x, t - x])
# stx.sort(reverse=True)
d = [int(input()) for _ in range(q)]

import bisect

seg = SegmentTree(q, ide_ele, segfun)

for x, start, last in stx:
    l = bisect.bisect_left(d, start)
    r = bisect.bisect_left(d, last)
    seg.update(l, r, x)

for i, j in enumerate(d):
    res = seg.query(i)
    if res == float("inf"):
        print(-1)
    else:
        print(res)
    



Measured memory_bytes: 129784
#include <iostream>
#include <vector>
#include <cassert>
#include <algorithm>
#include <functional>
#include <cmath>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <map>
#include <iomanip>
#include <limits>
using ll = long long;
using ld = long double;
int MOD = 1e9 + 7;
using namespace std;
struct UnionFind
{
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N)
    { //最初は全てが根であるとして初期化
        for (int i = 0; i < N; i++)
            par[i] = i;
    }

    int root(int x)
    { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x)
            return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y)
    {                     // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry)
            return;   //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y)
    { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};
int main(){
    ll n;
    cin>>n;
    ll k=n/11;
    ll j=n%11;
    if(j==0){
        cout<<k*2<<endl;
        return 0;
    }
    if(j>6){
        cout<<k*2+2<<endl;
    }else{
        cout<<k*2+1<<endl;
    }
}

Measured memory_bytes: 384
import java.util.ArrayList;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		s += "T";
		int x = sc.nextInt();
		int y = sc.nextInt();
		int right = 0;
		while (s.startsWith("F")) {
			s = s.substring(1);
			right++;
		}
		x -= right;
		ArrayList<Integer> RorL = new ArrayList<>();
		ArrayList<Integer> UorD = new ArrayList<>();
		boolean isRorL = true;
		int count = 0;
		for (char c : s.toCharArray()) {
			if (c == 'T') {
				if (isRorL) {
					if (count != 0) {
						RorL.add(count);
					}
				} else {
					if (count != 0) {
						UorD.add(count);
					}
				}
				count = 0;
				isRorL = !isRorL;
			} else {
				count++;
			}
		}
		final int magic = 17000;
		x += magic;
		y += magic;
		//テーブル構築//dp[i][j]でi回目の操作で座標軸上のn+magicに居られるかどうか
		boolean xdp[][] = new boolean[RorL.size() + 1][2*magic+100];
		boolean ydp[][] = new boolean[UorD.size() + 1][2*magic+100];
		//dp初期条件
		xdp[0][magic] = true;
		ydp[0][magic] = true;
		//dp
		for (int i = 0; i < RorL.size(); i++) {
			for (int j = 0; j < 2*magic+100; j++) {
				if (xdp[i][j]) {
					if (j - RorL.get(i) >= 0) {
						xdp[i + 1][j - RorL.get(i)] = true;
					}
					if (j + RorL.get(i) < 2*magic+100) {
						xdp[i + 1][j + RorL.get(i)] = true;
					}
				}
			}
		}
		for (int i = 0; i < UorD.size(); i++) {
			for (int j = 0; j < 2*magic+100; j++) {
				if (ydp[i][j]) {
					if (j - UorD.get(i) >= 0) {
						ydp[i + 1][j - UorD.get(i)] = true;
					}
					if (j + UorD.get(i) < 2*magic+100) {
						ydp[i + 1][j + UorD.get(i)] = true;
					}
				}
			}
		}
		if (xdp[RorL.size()][x] && ydp[UorD.size()][y]) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}
}

Measured memory_bytes: 171324
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> VI;

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; }
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    map<int, int> b;
    rep (i, n) {
       cin >> a[i];
       b[-(a[i] - i)]++;
    }
    ll ans = 0;
    rep (i, n) {
        ans += b[a[i] + i];
        b[-(a[i] - i)]--;
    }
    cout << ans << endl;
}

Measured memory_bytes: 20984
var m = input => {
  var a = input.split(' ');
  var K = parseInt(a[0]);
  var S = parseInt(a[1]);
  var s = 0;
  for(let i=0;i<=K;i++){
    for(let j=0;j<=K;j++){
      var v = S-(i+j);
      if(v >= 0 && v <= K){
        s++;
      }
    }
  }
  console.log(s);
}
m(require('fs').readFileSync('/dev/stdin', 'utf8'));

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

#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 reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit32(x) (1 << (x))
#define bit64(x) (1ll << (x))
#define sz(v) ((int) v.size())

using namespace std;

using i64 = long long;
using f80 = long double;
using vi32 = vector<int>;
using vi64 = vector<i64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << endl; exit(0); }
inline void no() { cout << "No" << endl; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); return a / gcd(a, b) * b; }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> inline void amax(T &x, T y) { x = max(x, y); }
template <typename T> inline void amin(T &x, T y) { x = min(x, y); }
template <typename T> inline T exp(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { each(x, v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }

void solve() {
  string s, t;
  cin >> s >> t;
  int n = sz(s);
  int m = sz(t);
  vi32 sum_s(n + 1);
  vi32 sum_t(m + 1);
  rep(i, n) sum_s[i + 1] += sum_s[i] + (s[i] == 'A');
  rep(i, m) sum_t[i + 1] += sum_t[i] + (t[i] == 'A');
  int q;
  cin >> q;
  auto id = [](int x, int y) {
    if (x == y) return 0;
    if (x > y) {
      int diff = x - y;
      return diff % 3;
    } else {
      int diff = y - x;
      return (3 - diff % 3) % 3;
    }
  };
  rep(qi, q) {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    a--, c--;
    int sA = (b - a) - (sum_s[b] - sum_s[a]);
    int sB = (b - a) - sA;
    int tA = (d - c) - (sum_t[d] - sum_t[c]);
    int tB = (d - c) - tA;
    if (id(sA, sB) == id(tA, tB)) {
      cout << "YES" << endl;
    } else {
      cout << "NO" << endl;
    }
  }
}

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

using namespace std;

typedef long long ll;
typedef pair<ll,ll> pll;

#define X first
#define Y second


const int N=1e5+10;

int n,a[N];

string solve(){
    int pos=1;
    while (pos<=n&&a[pos]==a[1]) pos++;
    if (pos==n+1){
        if (a[1]==n-1)  return "Yes";
        if (a[1]<=n/2) return "Yes"; 
        return "No";
    }
    if (a[1]>a[pos]) swap(a[1],a[pos]);
    int n1=count(a+1,a+n+1,a[1]),n2=count(a+1,a+n+1,a[pos]);
    if ((n1+n2!=n)||(a[pos]-a[1]!=1)) return "No";
    if (n2<=1) return "No";
    int mi_col=n1+1;
    int ma_col=n1+(n2/2);
    if (mi_col<=a[pos]&&a[pos]<=ma_col) return "Yes";
    return "No";
}
int main(){
    cin>>n;
    for(int i=1;i<=n;i++) cin>>a[i];
    cout<<solve();
}


Measured memory_bytes: 640
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int top, stack[1000];

void push(int c){

  stack[++top]=c;

}

int pop(){

  top--;

  return stack[top+1];

}

int main(){

  int x,first,second;
  char s[100];
  top=0;
  
  while(scanf("%s",s)!=EOF){
    
    if(s[0]=='+'){
      
      second=pop();
      
      first=pop();
      
      push(first+second);

    }
    else if(s[0]=='-'){

      second=pop();
      
      first=pop();
      
      push(first-second);

    }
    else if(s[0]=='*'){

      second=pop();
      
      first=pop();
      
      push(first*second);

    }
    else{
      
      push(atoi(s));

    }
  }


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

  return 0;
}



Measured memory_bytes: 2108
#include<cstdio>
#include<vector>
#include<algorithm>
#include<utility>
#include<numeric>
#include<iostream>
#include<array>
#include<string>
#define _USE_MATH_DEFINES

#include<math.h>
#include<unordered_map>

#define min(a,b) (a)>(b)?(b):(a)
#define max(a,b) (a)>(b)?(a):(b)

using namespace std;

int main()
{
	int s[1000];
	int n;

	while (true)
	{
		cin >> n;

		if (n == 0)
		{
			break;
		}

		double ave = 0.0;
		for (int i = 0; i < n; i++)
		{
			cin >> s[i];
			ave += s[i];
		}
		ave /= (double)n;

		double alpha = 0.0;
		for (int i = 0; i < n; i++)
		{
			alpha += (s[i] - ave)*(s[i] - ave);
		}
		alpha /= (double)n;
		printf("%lf\n", sqrt(alpha));
	}
}

Measured memory_bytes: 3196
import itertools

N = input()
K = int(input())
lN = len(N)

if K == 1:
    ans = int(N[0])+9*(lN-1)
    print(ans)

elif K == 2:
    not0 = 1000
    for i in range(1,lN):
        if int(N[i]) != 0:
            not0 = i
            break
    ans = 0
    n = [i for i in range(lN)]
    for v in itertools.combinations(n,2):
        if v[0] != 0:
            ans += 9*9
        else:
            if not0 >= v[1]:
                ans += (int(N[0])-1)*9 + int(N[v[1]])
            else:
                ans += int(N[0])*9
    print(ans)

else:
    not0f = 1000
    not0s = 1000
    for i in range(1,lN):
        if int(N[i]) != 0:
            not0f = i
            break
    for i in range(not0f+1,lN):
        if int(N[i]) != 0:
            not0s = i
            break
    ans = 0
    n = [i for i in range(lN)]
    for v in itertools.combinations(n,3):
        if v[0] != 0:
            ans += 9*9*9
        else:
            if not0f == v[1]:
                if not0s >= v[2]:
                    ans += (int(N[0])-1)*9*9
                    ans += (int(N[v[1]])-1)*9
                    ans += int(N[v[2]])
                else:
                    ans += (int(N[0])-1)*9*9
                    ans += int(N[v[1]])*9
            elif not0f < v[1]:
                ans += int(N[0])*9*9
            else:
                ans += (int(N[0])-1)*9*9
    print(ans)


Measured memory_bytes: 3188
#include<stdio.h>
int main(void)
{
    int W,H,x,y,r;
	scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);
	if(H>=y+r && W>=x+r && 0<=x-r && 0<=y-r){
	    printf("Yes\n");
	}
	else{
	    printf("No\n");
	}
	return 0;
}

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

#define ll long long

void swap (int *x, int *y) {
  int temp;

  temp = *x;
  *x = *y;
  *y = temp;

  return;
}


//naosu
long int gcd(long int a,long int b){
  long int c;

  while (b > 0){
    c = a % b;
    a = b;
    b = c;
  }

  return a;
}

int upll(const void*a, const void*b){
  return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;
}

int downll(const void*a, const void*b){
  return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;
}

void sortup(ll*a,int n){
  qsort(a,n,sizeof(ll),upll);
}

void sortdown(ll*a,int n){
  qsort(a,n,sizeof(ll),downll);
}

long int modpow(long int a,long int n,long int mod){
  long int ans=1;
  while(n>0){
    if(n & 1){
      ans=ans*a%mod;
    }
    a=a*a%mod;
    n/=2;
  }
  return ans;
}

long int modinv(long int a,long int mod){
  return modpow(a,mod-2,mod);
}

int max(int a,int b){
  if(a<b){
    return b;
  }
  else{
    return a;
  }
}

int min(int a,int b){
  if(a<b){
    return a;
  }
  else{
    return b;
  }
}

void chmax(int *a,int b){
  if(*a < b){
    *a = b;
  }

  return;
}

void chmin(int *a,int b){
  if(*a > b){
    *a =b;
  }

  return;
}


long int lcm(long int a,long int b){
  return a/gcd(a,b)*b;
}


long int f(long int n,long int c,long int d){
  long int cnt=n/c+n/d-n/lcm(c,d);
  return n-cnt;
}


/****************************************\
| Thank you for viewing my code:)        |
| Written by RedSpica a.k.a. RanseMirage |
| Twitter:@asakaakasaka                  | 
\****************************************/

int main(void){
  int x;
  scanf("%d",&x);

  printf("%d\n",!x);

  return 0;
}

Measured memory_bytes: 1712
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
const bool debug=false;
#define DEBUG if(debug==true)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
ll W,H,x,y;
int main(void) {
    cin >> W >> H >> x >> y;
    if(W%2==1&&H%2==1){
        cout << W*H/2 << ".5" << " ";
    }
    else cout << W*H/2 << " ";

    // printf("%10f ",res);
    // cout << scientific << setprecision(30) <<res << " ";
    if(abs(W-x*2)==0&&abs(H-y*2)==0)cout << "1" << endl;
    else cout << "0" << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<string>
#include<cmath>
#include<math.h>
#include<vector>
#include<algorithm>
#include<map>
#pragma warning(disable: 4996)
#define rep(i,n) for(int i = 1; i < (n); i++)
using namespace std;
using ll = long long;

int f[101];

int main() {
	
	int L;
	cin >> L;
	vector<int> c(L);
	vector<int> F(101);
	int cnt = 1;
	cin >> c[0];
	if (c[0] < 0) {
		cout << cnt << endl;
		return 0;
	}
	F[c[0]] = 1;
	int i = 1;
	while(i<L) {
		cin >> c[i];
		cnt++;
		if (c[i] > 0) {
			if (F[c[i]] == 0) {
				F[c[i]] = 1;
			}
			else {
				std::cout << cnt << endl;
				return 0;
			}
		}

		if (c[i] < 0) {

			if (c[i] ==-1* c[i - 1]) {
				F[c[i-1]]= 0;
				c.pop_back();
				c.pop_back();
				i -= 2; L -= 2;
			}
			else {
				std::cout << cnt << endl;
				return 0;
			}

		}
		i++;
	}

	std::cout << "OK" << endl;
	return 0;
}


Measured memory_bytes: 3116
#include <iostream>
#include <string>
#include <cstdint>
#include <bitset>
#include <vector>
#include <thread>
#include <stack>
#include <map>



int main()
{
	int n;
	std::cin >> n;
	std::string s;
	std::map<std::string, int>mp;
	for (int i = 0; i < n; i++)
	{
		std::cin >> s;
		mp[s]++;
	}

	printf("AC x %d\n", mp["AC"]);
	printf("WA x %d\n", mp["WA"]);
	printf("TLE x %d\n", mp["TLE"]);
	printf("RE x %d\n", mp["RE"]);
}

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

using namespace std;
using ll = long long;
using ull = unsigned long long;

constexpr ll LLINF {1001002003004005006};//ll = 9*LLINF
constexpr int INTINF {1000000000};//int = 2*INTINF

#define  rep(i,n)   for(int i = 0; i < (n); ++i)
#define rrep(i,n)   for(int i = 1; i <= (n); ++i)
#define drep(i,n)   for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for(int i = s; i < t;  ++i)

template<typename T>
void maxs(T& x, T&& y) {
  x=std::max(x,y);
}
template<typename T>
void maxs(T& x, T& y) {
  x=std::max(x,y);
}

template<typename T>
void mins(T& x, T&& y) {
  x=std::min(x,y);
}
template<typename T>
void mins(T& x, T& y) {
  x=std::min(x,y);
}

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

  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  int ans {};
  rep(i,n) {
    if (i%2==0 && a[i]%2==1) {
      ++ans;
    }
  }
  cout << ans << '\n';
}


Measured memory_bytes: 3652
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
using namespace std;
int f(int x){
	return x*x;
}
int n,a[1001],cnt,ans,ans2,ans3;
int main(){
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        cnt+=a[i];
    }
    int t=cnt/n;
    for(int i=1;i<=n;i++){ 
        ans+=f(a[i]-t);
        ans2+=f(a[i]-t-1);
        ans3+=f(a[i]-t+1);
    }
    int tt=ans<ans2? ans:ans2;
    tt=tt>ans3?ans3:tt;
    cout<<tt<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<functional>
using namespace std;
#define INF 1e15
#define MOD 1000000007

#define rep(i,n) for(int i=0;i<n;i++)
#define int long long
typedef long long ll;
typedef pair<int, int> P;
#define END system("PAUSE");return 0
int n, m;
P a[111111];
int cnt = 0, ans = 0;
signed main() {
	cin >> n >> m;
	rep(i, n)cin >> a[i].first >> a[i].second;
	sort(a, a + n);
	rep(i, n) {
		if (cnt + a[i].second >= m) {
			ans += (m - cnt)*a[i].first;
			break;
		}
		else {
			cnt += a[i].second;
			ans += a[i].first*a[i].second;
		}
	}
	cout << ans << endl;
	END;
}


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

#define MOD 1000000007
#define rep(i, n) for(ll i=0; i < (n); i++)
#define rrep(i, n) for(ll i=(n)-1; i >=0; i--)
#define ALL(v) v.begin(),v.end()
#define rALL(v) v.rbegin(),v.rend()
#define FOR(i, j, k) for(ll i=j;i<k;i++)
#define debug_print(var) cerr << #var << "=" << var <<endl;
#define DUMP(i, v)for(ll i=0;i<v.size();i++)cerr<<v[i]<<" "

using namespace std;
typedef long long int ll;
typedef vector<ll> llvec;
typedef vector<double> dvec;
typedef pair<ll, ll> P;
typedef long double ld;
struct edge{ll x, c;};

ll mod(ll a, ll mod){
  ll res = a%mod;
  if(res<0)res=res + mod;
  return res;
}

ll modpow(ll a, ll n, ll mod){
  ll res=1;
  while(n>0){
    if(n&1) res=res*a%mod;
    a=a*a%mod;
    n>>=1;
  }
  return res;
}

ll modinv(ll a, ll mod){
  return modpow(a, mod-2, mod);
}

ll gcd(ll a, ll b){
  ll r = a%b;
  if(r==0) return b;
  else return gcd(b, a%b);
}

bool is_prime(ll n){
  ll i = 2;
  if(n==1)return false;
  if(n==2)return true;
  bool res = true;
  while(i*i <n){
    if(n%i==0){
      res = false;
    }
    i = i+1;
  }

  //if(i==1)res = false;
  if(n%i==0)res=false;
  return res;
}

struct UnionFind{
  ll N;
  llvec p;
  llvec cnt;
  UnionFind(ll n){
    N = n;
    p=llvec(N);
    cnt=llvec(N, 0);
    rep(i, N){
      p[i] = i;
      cnt[i] = 1;
    }
  }

  void con(ll a, ll b){
    P at = root(a);
    P bt = root(b);
    if(at.second!=bt.second){
      if(at.first>bt.first){
        swap(at, bt);
        swap(a, b);
      }
      p[at.second] = bt.second;
      cnt[bt.second]+=cnt[at.second];
      p[a]=bt.second;
    }
  }

  P root(ll a){
    ll atmp = a;
    ll c=0;
    while(atmp!=p[atmp]){
      atmp = p[atmp];
      c++;
    }
    p[a] = atmp;
    return {c, atmp};
  }

  bool is_con(ll a, ll b){
    P at=root(a);
    P bt=root(b);
    return at.second == bt.second;
  }
  
};

struct dijkstra{
  ll N;
  llvec d;
  vector<vector<edge>> e;
  dijkstra(ll n){
    N = n;
    //d = llvec(N, 1e18);
    e = vector<vector<edge>>(N);
  }

  void add_edge(ll from, ll to, ll cost){
    e[from].push_back({to, cost});
  }

  void run(ll start){
    priority_queue<P, vector<P>, greater<P>> que;
    que.push({0, start});
    d = llvec(N, 1e18);
    d[start]=0;
    while(!que.empty()){
      P q = que.top();que.pop();
      ll dc = q.first;
      ll x = q.second;
      if(dc>d[x]){
        continue;
      }else{
        for(auto ip: e[x]){
          if(d[ip.x]<=d[x]+ip.c){
            continue;
          }else{
            d[ip.x]= d[x]+ip.c;
            que.push({d[ip.x], ip.x});
          }
        }
      }
    }
  }  
};


/**************************************
** A main function starts from here  **
***************************************/
int main(){
  ll A, B;
  cin >> A >> B;
  for(ll c=1;c<=3;c++){
    if((A*B*c)%2==1){
      cout << "Yes";
      return 0;
    }
  }
  cout << "No";
  return 0;
}


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

int main(){
  int N;
  int tmp;
  int sum=0;

  cin >> N;
  tmp = N;

  while(tmp>0){
    sum+=tmp % 10;
    tmp = tmp / 10;
  }

  if(N%sum==0) cout << "Yes" << endl;
  else         cout << "No"  << endl;

  return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int n = input.nextInt();
        int tmp = 1;
        for (int i = 0; i < n; i++){
            int a = input.nextInt();
            if (a%2 == 0){
                tmp *= 2;
            }
        }
        int ans = (int)Math.pow(3,n) - tmp;
        System.out.println(ans);
    }
}

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

int main() {
  int A, B;
  scanf("%d%d", &A, &B);

  if (A % 3 == 0 || B % 3 == 0 || (A + B) % 3 == 0) {
    printf("Possible");
  } else {
    printf("Impossible");
  }
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include<algorithm>
#include<iomanip>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for(int i=m;i<(int)(n);i++)
typedef pair<int,int> pint;
typedef long long ll;
const int inf   = 1<<30;
const ll  longinf = 1LL<<60;
int dx[4]={1,0,-1,0}, dy[4]={0,1,0,-1};
int main(){
  int n;
  cin>>n;
  int a[n];
  rep(i,n){
    scanf("%d",&a[i]);
    }
  int i=n-1;
  while(i>=0){
    cout<<a[i]<<" ";
    i-=2;
    }
  if(n%2==0){
    for(int i=0;i<n;i+=2)
      cout<<a[i]<<" ";
    }
  else{
    for(int i=1;i<n;i+=2)
      cout<<a[i]<<" ";
    }
  cout<<endl;
  return 0;
  }

      


Measured memory_bytes: 2944
#include <bits/stdc++.h>
#define all(vec) vec.begin(), vec.end()
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
constexpr ll INF = (1LL << 30) - 1LL;
constexpr ll LINF = (1LL << 60) - 1LL;
constexpr double eps = 1e-9;
constexpr ll MOD = 1000000007LL;
template <typename T> bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
};
template <typename T> bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
};
template <typename T> ostream &operator<<(ostream &os, vector<T> v) {
    for (int i = 0; i < v.size(); i++) {
        os << v[i] << (i + 1 == v.size() ? "\n" : " ");
    }
    return os;
}
template <typename T> vector<T> make_v(size_t a) { return vector<T>(a); }
template <typename T, typename... Ts> auto make_v(size_t a, Ts... ts) {
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type fill_v(T &t, const V &v) {
    t = v;
}
template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type fill_v(T &t, const V &v) {
    for (auto &e : t) {
        fill_v(e, v);
    }
};
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    vector<vector<int>> G(3 * n);
    for (int i = 0; i < m; i++) {
        int u, v;
        cin >> u >> v;
        --u;
        --v;
        G[u].push_back(v + n);
        G[u + n].push_back(v + 2 * n);
        G[u + 2 * n].push_back(v);
    }
    int s, g;
    cin >> s >> g;
    --s;
    --g;
    vector<int> d(3 * n, INF);
    queue<int> q;
    d[s] = 0;
    q.push(s);
    while (!q.empty()) {
        int v = q.front();
        q.pop();
        for (auto &e : G[v]) {
            if (d[e] > d[v] + 1) {
                d[e] = d[v] + 1;
                q.push(e);
            }
        }
    }
    if (d[g] == INF) {
        cout << -1 << endl;
    } else {
        cout << d[g] / 3 << endl;
    }
}


Measured memory_bytes: 17792
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

from math import atan,tan,pi

a,b,x = map(int,read().split())

def max_volume(theta):
    # 弧度法にする
    theta = theta/180*pi
    if theta<atan(b/a):
        # 半分より上のパターン
        area = a*b-a*a*tan(theta)/2
    else:
        area = b*(b/tan(theta))/2
    return area*a

left = 0 # おさまっている
right = 90 # あふれている
while right - left > 1e-7:
    mid = (left+right)/2
    if max_volume(mid) <= x:
        right = mid
    else:
        left = mid

answer = (left+right)/2
print(answer)


Measured memory_bytes: 3064
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define CK(N, A, B) (A <= N && N < B)
#define REP(i, a, b) for (int i = a; i < b; i++)
#define RREP(i, a, b) for (int i = (b - 1); a <= i; i--)
#define F first
#define S second
#define ll long long

const int INF = 1e9;
const long long LLINF = 1e18;

using namespace std;

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

/*==================================================*/
/*variable*/
ll N, a;
/*==================================================*/
/*function*/

/*==================================================*/

int main() {
    cin>>N;

    vector<ll> v4;
    vector<ll> v2;
    vector<ll> v1;

    REP(i,0,N) {
        cin>>a;
        if(a % 4 == 0){
            v4.push_back(a);
        }else if(a % 2 == 0){
            v2.push_back(a);
        }else{
            v1.push_back(a);
        }
    }

    ll d[100010];
    REP(i,0,N) d[i] = -1;

    int ind = -1;
    REP(i,0,v4.size()){
        ind += 2;
        if(ind >= N) break;
        d[ind] = v4[i];
    }

    if(ind >= N){
        cout<<"Yes"<<endl;
        return 0;
    }

    ind++;
    REP(i,0,v2.size()){
        if(ind >= N) break;
        d[ind] = v2[i];
        ind++;
    }

    int cnt = 0;
    REP(i,0,N){
        if(cnt == v1.size()) break;
        if(d[i] == -1) d[i] = v1[cnt], cnt++;
    }

    //test
//    REP(j,0,N) cout<<d[j]<<" ";
//    cout<<endl;

    REP(i,0,N-1){
        if((d[i] * d[i+1]) % 4LL != 0LL || d[i]==-1 || d[i+1]==-1){
            cout<<"No"<<endl;
            return 0;
        }
    }
    cout<<"Yes"<<endl;

    return 0;
}


Measured memory_bytes: 2036
#include <bits/stdc++.h>
using namespace std;
#define DEBUG 0
#define nl          '\n'
#define fori(n)			for(int i = 0; i < n; ++i) 
#define forj(n)			for(int j = 0; j < n; ++j)
#define fork(n)			for(int k = 0; k < n; ++k)
#define forl(n)			for(int l = 0; l < n; ++l)
#define pq priority_queue
#define umap unordered_map
#define uset unordered_set
#define ppb push_back
typedef long long ll;typedef pair<int,int> pii;typedef vector<bool> vbool;
typedef vector<int> vint;typedef vector<ll> vll;typedef long double ld;
typedef vector<vector<int>> vvi; typedef vector<vbool> vvb;

const ll N = 100010;
const ll INF = 0x3f3f3f3f;
const ll MOD = 1e9 + 7;

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	string s,t; int a,b; cin >> s >> t >> a >> b;
	string u; cin >> u;
	if (u == s) cout << a-1 << " " << b << nl;
	else cout << a << " " << b-1 << nl;
	
	#if DEBUG
	cerr << "Time: " << (ld)clock() / CLOCKS_PER_SEC << " s" << nl;
	#endif
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; i++)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define reps(i,a,b) for(int i= a; i < b; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main()
{
  int n, m;
  ll k;
  cin >> n >> m >> k;
  vector<ll> A(n, 0);
  vector<ll> B(m, 0);
  rep(t, n) cin >> A.at(t);
  rep(j, m) cin >> B.at(j);
  vector<ll> culA(n+1, 0);
  vector<ll> culB(m+1, 0);
  reps(r, 1, n+1) {
    culA.at(r) = culA.at(r-1) + A.at(r-1);
  }
  reps(l, 1, m+1) {
    culB.at(l) = culB.at(l-1) + B.at(l-1);
  }
  ll ans = 0;
  ll bp = m;
  rep(i, n+1) {
    ll tmp = culA.at(i) + culB[bp];
    while(tmp > k && bp > 0) {
      bp--;
      tmp = culA.at(i) + culB.at(bp);
    }
    if (tmp <= k) {
      ll res = bp + i;
      ans = max(ans, res);
    }
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 9596
main = do
  s <- getContents
  putStr . unlines . map (show . length . primesUnder . read) . lines $ s

primesUnder n = takeWhile (<= n) primes


-- The following efficient Eratosthenes' sieve is borrowed from:
-- http://en.literateprograms.org/Sieve_of_Eratosthenes_(Haskell) and
-- https://wiki.haskell.org/Prime_numbers

primes = [2, 3, 5] ++ ([7, 9 ..] `minus` nonprimes)
nonprimes = foldr1 union' [[p*p, p*p + 2*p ..] | p <- tail primes]
  where
    union' (x:xs) ys = x : union xs ys

-- union and subtraction of two infinite sorted sets
union (x:xs) (y:ys) =
  case compare x y of
    LT -> x : union xs (y:ys)
    EQ -> x : union xs ys
    GT -> y : union (x:xs) ys
minus (x:xs) (y:ys) =
  case compare x y of
    LT -> x : minus xs (y:ys)
    EQ -> minus xs ys
    GT -> minus (x:xs) ys

Measured memory_bytes: 12224
//#include <bits/stdc++.h>
#include <iostream>
#include <vector>
using namespace std;
using Int = int_fast64_t;

class edge{
public:
	Int cost;
	size_t from, to;
	edge(Int c, size_t f, size_t t){
		cost = c;
		from = f;
		to = t;
	}
};
using edges = vector<edge>;
using graph = vector<edges>;
void readgraph(graph &g, size_t E, bool D, bool C, bool Z){ // E:num_of_edges, D:directed, C:costed, Z:already 0-indexed
	for(size_t i=0; i<E; ++i){
		edge e(1, 0, 0);
		if(!C) cin >> e.from >> e.to;
		else cin >> e.from >> e.to >> e.cost;
		if(!Z){
			--e.from;
			--e.to;
		}
		g[e.from].push_back(e);
		if(!D){
			swap(e.from, e.to);
			g[e.from].push_back(e);
		}
	}
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	Int n, m, l; cin >> n >> m >> l;
	graph g(n);
	readgraph(g, m, false, true, false);
	vector<vector<Int>> d(n, vector<Int>(n, 1e18));
	for(Int i=0; i<n; ++i) d[i][i] = 0;
	for(auto v:g)
		for(auto e:v)
			d[e.from][e.to] = e.cost;
	for(Int k=0; k<n; ++k)
		for(Int i=0; i<n; ++i)
			for(Int j=0; j<n; ++j)
				d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
//	for(Int i=0; i<n; ++i)
//		for(Int j=0; j<n; ++j)
//			cout << i << " " << " " << j << " " << d[i][j] << "\n";
	graph h(n);
	for(Int i=0; i<n; ++i)
		for(Int j=0; j<n; ++j){
			if(i == j) continue;
			if(d[i][j] <= l) h[i].push_back(edge(1, i, j));
		}
	vector<vector<Int>> c(n, vector<Int>(n, 1e18));
	for(Int i=0; i<n; ++i) c[i][i] = 0;
	for(auto v:h)
		for(auto e:v)
			c[e.from][e.to] = e.cost;
//	for(Int i=0; i<n; ++i)
//		for(Int j=0; j<n; ++j)
//			cout << i << " " << " " << j << " " << c[i][j] << "\n";
	for(Int k=0; k<n; ++k)
		for(Int i=0; i<n; ++i)
			for(Int j=0; j<n; ++j)
				c[i][j] = min(c[i][j], c[i][k] + c[k][j]);
//	for(Int i=0; i<n; ++i)
//		for(Int j=0; j<n; ++j)
//			cout << i << " " << " " << j << " " << c[i][j] << "\n";
	Int q; cin >> q;
	while(q--){
		Int s, t; cin >> s >> t; --s; --t;
		cout << (c[s][t] == 1e18 ? -1 : c[s][t]-1) << "\n";
	}
//	for(Int i=0; i<n; ++i)
//		for(auto e:h[i])
//			cout << e.cost << " " << e.from << " " << e.to << "\n";
}

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

using namespace std;

#define debug(n) cerr << #n << ':' << n << endl;
#define dline    cerr << __LINE__ << endl;

using ll = long long;
template<class T, class U> using P = pair<T,U>;
template<class T> using Heap = priority_queue<T>;
template<class T> using heaP = priority_queue<T,vector<T>,greater<T>>;
template<class T,class U> using umap = unordered_map<T,U>;
template<class T> using uset = unordered_set<T>;

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

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

template<class T, size_t N, class U>
void Fill(T (&a)[N], const U&v){
    fill((U*)a,(U*)(a+N),v);
}

template<class T>
istream& operator >> (istream&is, vector<T>&v){
  for(auto&e:v)is >> e;
  return is;
}

int main(){
  ll n; cin >> n;
  vector<ll> v(n+1); cin >> v;
  ll sum = 0;
  ll ans = 0;
  for(auto&e:v)sum += e;  
  ll xmin=1,xmax=1;
  for(ll i = 0; i < n+1; ++i){
    ans += xmax;
    if(v[i] > xmax) {
      cout << -1 << endl;
      return 0;
    }
    xmin -= v[i];
    xmax -= v[i];
    xmin = max(0LL,xmin);
    xmax *= 2;
    sum -= v[i];
    if(xmax > sum) xmax = sum;
  }
  cout << ans << endl; 
  return 0;
}


Measured memory_bytes: 4056
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<numeric>
#include<map>
#include<iostream>
using namespace std;
#define rep(i,n) for(int i = 0;i<((int)(n));i++)
#define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(int i = ((int)(b));i>=((int)(a));i--)
typedef long long ll;
typedef pair<ll, ll> mp;

//

int main(void){
	bool can=true;
	ll n,t2=0,x2=0,y2=0,t,x,y;
	cin>>n;
	rep(i,n){
		cin>>t>>x>>y;
		ll d = abs(x-x2)+abs(y-y2);
		if(d<=(t-t2) && ((t-t2)-d)%2==0){
			x2=x;
			y2=y;
			t2=t;
		}else{
			can=false;
		}
	}
	if(can){
		cout<<"Yes"<<endl;
	}else{
		cout<<"No"<<endl;
	}
	return 0;
}

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



int main(){
int n;
std::cin >> n;
int t[100000]={};
int x[100000]={};
int y[100000]={};
int success=1;

for (int i = 0; i < n; i++) {
  std::cin >> t[i]>>x[i]>>y[i];
}

for (int i = 0; i < n; i++) {
  if(i==0){
    if(t[0]%2==0 && (x[0]+y[0])%2==0 && x[0]+y[0]<=t[0]);
    else if(t[0]%2==1 && (x[0]+y[0])%2==1 && x[0]+y[0]<=t[0]);
    else success=0;
  }
  else if(abs(t[i]-t[i-1])%2==0 && abs(x[i]-x[i-1]+y[i]-y[i-1])%2==0 && abs(x[i]-x[i-1])+abs(y[i]-y[i-1])<=t[i]-t[i-1]);
  else if(abs(t[i]-t[i-1])%2==1 && abs(x[i]-x[i-1]+y[i]-y[i-1])%2==1 && abs(x[i]-x[i-1])+abs(y[i]-y[i-1])<=t[i]-t[i-1]);
  else {success=0;}

  if(success==0)break;
}

if(success==1)std::cout << "Yes" << '\n';
else std::cout << "No" << '\n';


return 0;
}


Measured memory_bytes: 1408