akhauriyash/Code-Regression huggingface dataset:
#if loc||local
#define _GLIBCXX_DEBUG
#endif

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

#define rep(i,n) for(ll i=0;i<(n);++i)
using ll = int_fast64_t;
using pll = pair<ll,ll>;
constexpr ll INF = 1LL<<60;
constexpr ll MOD = 1e9+7;
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;}
#if loc||local
template<class T>void dump(T&& t){cerr<<t<<endl;}
template<class T,class... Ts> void dump(T&& h, Ts&&... t){cerr<<h<<", ";dump(forward<Ts>(t)...);}
#else
void dump(){}
template<class T,class... Ts> void dump(T&& h, Ts&&... t){}
#endif
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
template<class T> ostream &operator<<(ostream& os,vector<T>const& v){for(auto const& vi:v)os<<vi<<" ";return os;}
template<class T,class U> ostream &operator<<(ostream& os,pair<T,U>const& p){os<<p.first<<","<<p.second;return os;}
template<class T>vector<T> vec(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto vec(size_t a, Ts... ts){return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...));}

signed main(){

  ll d,t,s;
  cin>>d>>t>>s;

  cout<<(t*s>=d?"Yes":"No")<<endl;

}

Measured memory_bytes: 3592
#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>;

int comb(int n, int k) {
  int res = 1;
  rep(i, k) res *= n - i;
  rep(i, k) res /= k - i;
  return res;
}

int main() {
  string n;
  int k;
  cin >> n >> k;
  int ans = 0;
  for (int i = 0; i <= n.size(); i++) {
    int nz = 0;
    rep(j, i) if (n[j] != '0') nz++;
    if (nz > k) continue;
    if (n.size() - i < k - nz) continue;
    if (i == n.size()) {
      ans++;
      break;
    }
    if (n[i] == '0') continue;
    if (k > nz) ans += (n[i] - '0' - 1) * comb(n.size() - i - 1, k - nz - 1) * pow(9, k - nz - 1);
    if (n.size() - i > k - nz) ans += comb(n.size() - i - 1, k - nz) * pow(9, k - nz);
    // printf("ans = %d\n", ans);
  }
  cout << ans << endl;
  return 0;
}

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

class Radix {
private:
  const char* s;
  int a[128];
public:
  Radix(const char* s = "0123456789ABCDEF") : s(s) {
    int i;
    for(i = 0; s[i]; ++i)
      a[(int)s[i]] = i;
  }
  string to(long long p, int q) {
    int i;
    if(!p)
      return "0";
    char t[64] = { };
    for(i = 62; p; --i) {
      t[i] = s[p % q];
      p /= q;
    }
    return string(t + i + 1);
  }
  string to(const string& t, int p, int q) {
    return to(to(t, p), q);
  }
  long long to(const string& t, int p) {
    int i;
    long long sm = a[(int)t[0]];
    for(i = 1; i < (int)t.length(); ++i)
      sm = sm * p + a[(int)t[i]];
    return sm;
  }
};

int main() {
    Radix r;
    int N,K;
    cin >> N >> K;
    cout << r.to(N, K).length() << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <map>

#include <algorithm>
#include <queue>
#include <cctype>

using namespace std;

#define rep(i, n) for (int i = 0; i < n; i++)

int N, K;
long long h[100003];
long long dp[100003];
const long long MAX = 1LL << 60;

int main() {
    fill(dp, dp + 100003,MAX);
    cin >> N >> K;
    rep(i, N) {
        cin >> h[i];
    }
    dp[0] = 0;
    rep(i, N - 1) {
        rep(k, K) {
            if ((i + k + 1) > N) break;
            dp[i + k + 1] = min(dp[i + k + 1], dp[i] + abs(h[i + k + 1] - h[i]));
        }
    }
    cout << dp[N-1] << '\n';
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define int long long
#define range(i, a, b) for(int i = (a); i < (b); i++)
#define rep(i, a) range(i, 0, a)
using namespace std;

int N, A, B;
vector <int> h;

template <class T>
bool c(T mid) {
    vector <int> tmp = h;
    rep (i, N) h[i] -= B * mid;

    for (int i = 0; i < N; i++) {
        if (h[i] > 0) mid -= h[i] / (A - B) + (h[i] % (A - B) != 0);
    }

    h = tmp;
    return mid < 0;
}

template <class T>
T execute(T low, T high) {
    for(int i = 0; i < 100; i++) {
        T mid = (high + low) / 2;
        (c(mid) ? low : high) = mid;
    }
    return high;
}

signed main() {
    cin >> N >> A >> B;
    h = vector <int> (N);
    rep (i, N) cin >> h[i];

    cout << execute(0LL, 1000000000LL) << endl;

    return 0;
}

Measured memory_bytes: 1792
#include<stdio.h>
#include<string.h>

int max(int a, int b) {
	if (a > b)return a;
	else return b;
}
int lcs(char x[], char y[], int m, int n) {
	int c[1001][1001];
	int i, j;
	int maxl = 0;
	for (i = 1; i <= m; i++) {
		c[i][0] = 0;
	}
	for (j = 1; j <= n; j++) {
		c[0][j] = 0;
	}
	for (i = 1; i <= m; i++) {
		for (j = 1; j <= n; j++) {
			if (x[i - 1] == y[j - 1]) {
				c[i][j] = c[i - 1][j - 1] + 1;
			}
			else {
				c[i][j] = max(c[i - 1][j], c[i][j - 1]);
			}
			maxl = max(maxl, c[i][j]);
		}
	}

	return maxl;
}
int main() {
	int n;
	int i;
	char x[1001], y[1001];

	scanf("%d", &n);

	for (i = 0; i < n; i++) {
		scanf("%s", x);
		scanf("%s", y);
		printf("%d\n", lcs(x, y, strlen(x), strlen(y)));

	}
	return 0;
}


Measured memory_bytes: 5632
MOD = 10**9 + 7

X, Y = map(int, input().split())

def getComb(n, k, MOD):
    if n < k:
        return 0
    if n-k < k:
        k = n-k
    comb = 1
    for x in range(n-k+1, n+1):
        comb = (comb * x) % MOD
    d = 1
    for x in range(1, k+1):
        d = (d * x) % MOD
    comb *= pow(d, MOD-2, MOD)
    return comb % MOD

if (X+Y)%3:
    ans = 0
else:
    K = (X+Y)//3
    if X < K or Y < K:
        ans = 0
    else:
        ans = getComb(K, X-K, MOD)

print(ans)


Measured memory_bytes: 3064
#include<iostream>
#include<stdio.h>
#include <vector>
#include <algorithm>
using namespace std;
     
int main(){
  //整数の時はint
  int  n,ans0=0,ans1=0,ans2=0,ans3=0;
  //文字の時はstring
  string s;
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>s;
    if(s=="AC")ans0++;
    else if(s=="WA")ans1++;
    else if(s=="TLE")ans2++;
    else if(s=="RE")ans3++;
  }

  cout<<"AC x "<<ans0<<endl;
  cout<<"WA x "<<ans1<<endl;
  cout<<"TLE x "<<ans2<<endl;
  cout<<"RE x "<<ans3<<endl;

  return 0;
}


Measured memory_bytes: 3536
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;

int main(){
	int K,S;
	int count=0;
	cin >> K >> S;
	int x,y,z;
	for(x=0;x<K+1;x++){
		for(y=0;y<K+1;y++){
			if(S-x-y >= 0 && S-x-y <= K){
				count++;
			}
		}
	}
	cout << count << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
double f(double x, int *v, int *l, int *r, int N) {
  double V = INT_MAX;
  for (int i = 0; i < N; i++) {
    if (x < l[i]) {
      V = min(V,v[i]+l[i]-x);
    } else if (x <= r[i]) {
      V = min(V,1.0*v[i]);
    } else {
      V = min(V,v[i]+x-r[i]);
    }
  }
  return V;
}
int main() {
  int N;
  cin >> N;
  int t[N+1];
  t[0] = 0;
  for (int i = 1; i <= N; i++) {
    cin >> t[i];
    t[i] += t[i-1];
  }
  N += 2;
  int v[N], l[N], r[N];
  double distance = 0;
  v[0] = 0;
  v[N-1] = 0;
  l[0] = 0;
  r[0] = 0;
  l[N-1] = t[N-2];
  r[N-1] = t[N-2];
  for (int i = 1; i < N-1; i++) {
    l[i] = t[i-1];
    r[i] = t[i];
    cin >> v[i];
  }
  for (double x = 0.5; x <= t[N-2]; x += 0.5) {
    distance += 0.25*(f(x,v,l,r,N)+f(x-0.5,v,l,r,N));
  }
  cout.precision(20);
  cout << fixed << distance;
}

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

using namespace std;

#define INF (1 << 30)
#define INFL (1LL << 62)
#define MOD7 1000000007
#define MOD9 1000000009
#define EPS 1e-10

using ll = long long;
using ull = unsigned long long;

int main() {
    int n, r;
    cin >> n >> r;
    if (n >= 10)
        cout << r << endl;
    else
        cout << r + 100 * (10 - n) << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MM = 1000000000;
const int MOD = MM + 7;
const int MAX = 510000;
#define rep(i, n) for(ll i=0; i<n; i++)
#define Rep(i, j, n) for(ll i=j; i<n; i++)
#define all(vec) vec.begin(), vec.end()
template<class T> inline bool chmin(T& a, T b) {if(a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) {if(a < b) {a = b; return true;} return false;}
const ll INF = 1LL << 60;

int main() {
    ll n; cin >> n;
    ll ans = 0;
    Rep(i, 1, n+1) ans += i * (n/i) * (n/i + 1) / 2;
    cout << ans << endl;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
// #include <iostream>
// #include <vector>
// #include <map>
// #include <algorithm>
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())

template<typename T>
T mod(T a, T b){
    return (a + b) % b;
}

template<typename T>
T gcd(T a, T b){
    if (b == 0) return a;
    return gcd(b, a % b);
}

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

// n を素因数分解
map<ll, ll> factor(ll n){
    map<ll, ll> mp;
    for (ll i = 2; i*i <= n; i++) {
        while (n % i == 0) {
            mp[i]++;
            n /= i;
        }
    }

    if (n > 1) {
        mp[n]++;
    }

    return mp;
}

// 文字列に "hoge" が含まれているか
// string str = "hogepiyo";
// if (str.find("hoge") != string::npos) {
//     cout << "文字列が含まれています" << endl;
// }

// char to string
// char c = 'a';
// string str = {c};

void solve(){
    int N;
    cin >> N;

    vector<ll> A(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }

    ll x1 = 0;
    ll sign = 1;
    for (int i = 0; i < N; i++) {
        if (i % 2 == 0) {
            sign = 1;
        } else {
            sign = -1;
        }

        x1 += sign * A[i];
    }

    x1 /= 2;
    vector<ll> rain(N);
    rain[0] = x1;
    for (int i = 1; i < N; i++) {
        rain[i] = A[i-1] - rain[i-1];
    }

    for (int i = 0; i < N; i++) {
        if (i == 0) {
            cout << 2*rain[i];
        } else {
            cout << " " << 2*rain[i];
        }
    }


    return;
}

int main(int argc, char const* argv[])
{
    solve();
    return 0;
}


Measured memory_bytes: 2816
a[99999],x,r;main(n,m){
for(scanf("%d%d",&n,&m);++x<n;a[x]+=a[x-1])scanf("%d",a+x);
for(n=0;m;m--)scanf("%d",&x),r=(r+abs(a[n]-a[n+x]))%100000,n+=x;
x=!printf("%d\n",r);}

Measured memory_bytes: 984
def main():
    N, M, = map(int, input().split())
    H = list(map(int, input().split()))
    paths = [tuple(map(int, input().split())) for _ in range(M)]

    not_good = set()

    for a, b in paths:
        if H[a-1] >= H[b-1]:
            not_good.add(b-1)

        if H[a-1] <= H[b-1]:
            not_good.add(a-1)

    print(N - len(not_good))
    # print(not_good)


if __name__ == '__main__':
    main()


Measured memory_bytes: 31072
import qualified Data.Vector                   as V
import           Data.List
import           Control.Applicative
import           Control.Monad

main :: IO ()
main = do
  s <- getLine
  putStrLn $ solve s ['a' .. 'z']

solve :: String -> String -> String
solve s []       = "None"
solve s (c : cs) = if c `elem` s then solve s cs else [c]


Measured memory_bytes: 7164
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
	cin >> N;
	double num, ans;
	string S;
	ans = 0;
		for (int i = 0; i < N; i++) {
			cin >> num >> S;
			if (S == "JPY") ans += num;
			else ans += num * 380000;
		}
		cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ctype.h>
using namespace std;
 
 
int main(){
    int X,Y,Xa,Ya;
    cin>>X>>Y>>Xa>>Ya;

    int fx=Xa-X,fy=Ya-Y;
    cout<<Xa-fy<<" ";
    cout<<Ya+fx<<" ";
    cout<<Xa-fx-fy<<" ";
    cout<<Ya-fy+fx<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <unordered_map>
#include <stack>
#include <queue>
#include <utility>

#include <cassert>
#include <cmath>
#include <cstdio>

using namespace std;

#define fi first
#define se second
#define mkp make_pair
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define FOR(i,a,b) for(ll i=(a); i < (b); i++)
#define RFOR(i,a,b) for(ll i=(b)-1; i >= (a); i--)
#define rep(i,n) FOR(i,0,(n))
#define rrep(i,n) RFOR(i,0,(n))

int main() {
	vector<int> v(3);
	cin >> v[0] >> v[1] >> v[2];
	sort(all(v));
	int res = 0;
	if(v[0]%2 != v[1]%2 || v[0]%2 != v[2]%2) {
		if(v[0]%2 == v[1]%2) {
			v[0]++; v[1]++;
		}
		else if(v[1]%2 == v[2]%2) {
			v[1]++; v[2]++;
		}
		else {
			v[0]++; v[2]++;
		}
		res++;
	}
	res += (v[2]-v[0])/2;
	res += (v[2]-v[1])/2;
	cout << res << endl;
	return 0;
}


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

#define pb push_back
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define REP(i,n) for(int _n=n, i=0;i<_n;++i)
#define FOR(i,a,b) for(int i=(a),_b=(b);i<=_b;++i)
#define FORD(i,a,b) for(int i=(a),_b=(b);i>=_b;--i)
#define trav(a, x) for (auto& a : x)
using ull = uint64_t;
using ll = int64_t;
using PII = pair<int, int>;
using VI = vector<int>;
#define INF (1ll<<60)

string to_string(string s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string) s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A, typename B> string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; }
template <typename A> string to_string(A v) {
bool first = true; string res = "{";
for (const auto &x : v) { if (!first) { res += ", "; } first = false; res += to_string(x); }
res += "}"; return res; }
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H); debug_out(T...); }
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

int main() {
    ios::sync_with_stdio(false), cin.tie(0);
    ll N, M;
    cin >> N >> M;
    vector<ll> V(N);
    REP(i, N) cin >> V[i];
    unordered_map<ll, int> R;
    ll sum = 0;
    ll ans = 0;
    REP(i, N) {
        sum = (sum + V[i]) % M;
        if (sum == 0) ans++;
        ans += R[sum];
        R[sum]++;
    }
    cout << ans << '\n';

}

Measured memory_bytes: 4492
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int n;
  string a,b,c;
  cin >> n >> a >> b >> c;
  int ans=0;
  for(int i=0;i<n;i++){
    if(a[i]==b[i] && b[i]==c[i]){ans+=0;}
    else if(a[i]!=b[i] && b[i]!=c[i] && c[i]!=a[i]){ans+=2;}
    else{ans+=1;}
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
program main
    use,intrinsic :: iso_fortran_env
    implicit none
    integer(int32):: x,a,b

    read*, x,a,b

    if (abs(x-a) < abs(x-b)) then
        print'(a)', 'A'
    else
        print'(a)', 'B'
    end if
    
end program main

Measured memory_bytes: 640
import sys
input = lambda: sys.stdin.readline().strip()

def main():
    N = int(input())
    a_lst = map(int, input().split())

    a_lst = sorted(a_lst)
    alice_score = 0
    bob_score = 0
    for _ in range(0,N,2):
        alice_score += a_lst.pop() if a_lst else 0
        bob_score += a_lst.pop() if a_lst else 0
    print(alice_score - bob_score)

main()


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

int day(int y, int m, int d) {
  int ans = 0;
  for(int i = 1; i < y; i++) {
    bool uruu = false;
    if(i % 4 == 0) {
      if(i % 100 == 0) {
	if(i % 400 == 0) {
	  uruu = true;
	}
      } else {
	uruu = true;
      }
    }
    if(uruu) {
      ans += 366;
    } else {
      ans += 365;
    }
  }
  m--;
  if(m >= 1) ans += 31;
  if(m >= 2) {
    bool uruu = false;
    if(y % 4 == 0) {
      if(y % 100 == 0) {
	if(y % 400 == 0) {
	  uruu = true;
	}
      } else {
	uruu = true;
      }
    }
    if(uruu) ans += 29;
    else     ans += 28;
  }
  if(m >= 3) ans += 31;
  if(m >= 4) ans += 30;
  if(m >= 5) ans += 31;
  if(m >= 6) ans += 30;
  if(m >= 7) ans += 31;
  if(m >= 8) ans += 31;
  if(m >= 9) ans += 30;
  if(m >= 10) ans += 31;
  if(m >= 11) ans += 30;

  ans += d;

  return ans;
}

int main() {
  int y1, m1, d1;
  int y2, m2, d2;
  while(cin >> y1 >> m1 >> d1 >> y2 >> m2 >> d2) {
    if(y1 == -1 && m1 == -1 && d1 == -1 && y2 == -1 && m2 == -1 && d2 == -1)
      break;

    cout << day(y2,m2,d2) - day(y1,m1,d1) << endl;
  }
  return 0;
}

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

int main() {
  int A, B, C;
  cin >> A >> B >> C;
  if (A < C && C < B) {
    cout << "Yes" << endl;
  } else if (B < C && C < A) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
import sys
from collections import Counter

c = None

def resolve(in_, out):
    n = int(in_.readline())
    a = tuple(map(int, in_.readline().split()))

    c = dict(Counter(a))

    total = sum(v * (v - 1) // 2 for v in c.values())

    for ai in a:
        ans = total - (c[ai] - 1)
        print(ans, file=out)


def main():
    resolve(sys.stdin.buffer, sys.stdout)


if __name__ == '__main__':
    main()


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

int main() {
  int n, m, x;
  cin >> n >> m >> x;
  int masu[110] = {0};
  for (int i = 0; i < m; i++) {
    int a;
    cin >> a;
    masu[a]++;
  }

  int cnt1 = 0, cnt2 = 0;
  for (int i = 0; i < n; i++) {
    if (i < x) {
      cnt1 += masu[i];
    }
    else {
      cnt2 += masu[i];
    }
  }

  cout << min(cnt1, cnt2) << endl;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double lb;
#define REP(i,j,n) for (int i=j;i<(n);i++)
#define RREP(i,n,j) for (int i = n; j<=i;i--)
#define print(out) cout<< out  << "\n";
#define all(vec) vec.begin(),vec.end()
#define mod 1000000007
const int INF = 1e9;
typedef pair<ll,ll> P;

int ans=0;
ll N;
set<ll> sft_set{3,5,7};

ll dfs(ll n){
  if(n>N){return 0;}
  int cnt0=0,cnt1=0,cnt2=0;
  ll tmp_n=n;
  while(tmp_n>0){
    if(tmp_n%10==3)cnt0++;
    if(tmp_n%10==5)cnt1++;
    if(tmp_n%10==7)cnt2++;
    tmp_n=tmp_n/10;
  }
  ll ret=(min({cnt0,cnt1,cnt2})>0?1:0);
  for(ll j:sft_set){
    ret+=dfs(n*10+j);
  }
  return ret;
}

int main(){
  cin>>N;
  ll ans = dfs(0);
  print(ans);

}


Measured memory_bytes: 256
// Problem : A - Remaining Balls
// Contest : AtCoder - AtCoder Beginner Contest 154
// URL : https://atcoder.jp/contests/abc154/tasks/abc154_a
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

//Macros

#define ll long long
#define db long double
#define pb push_back
#define eb emplace_back
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define mi map<int,int>
#define mii map<pii,int>
#define fi first
#define se second
#define all(a) (a).begin(),(a).end()
#define sz(x) (int)x.size()
#define mod 1000000007
#define EPS 1e-9
#define io ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define inf 1e10
#define PI acos(-1.0)
#define int long long
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define N 100005

//Solution

void solve(){
    string s,t,u;
    int a,b;
    cin>>s>>t>>a>>b>>u;
    if(s == u) a--;
    else b--;
    cout<<a<<' '<<b<<endl;
}

signed main(){
    io;
    //freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
    int tests;
    //cin>>tests;
    tests = 1;
    while(tests--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 3656
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007
int main() {
	string s;
	cin>>s;
	if(s=="AAA"||s=="BBB"){
		cout << "No";
	}
	else{
		cout << "Yes";
	}
	// your code goes here
	return 0;
}

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

#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define RFOR(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define LL long long
#define INF INT_MAX

const double EPS = 1e-14;
const double PI  = acos(-1.0);


int main(){
  int a, b;
  cin >> a >> b;

  int ans = a % b == 0 ? 0 : 1;
  cout << ans << endl;
}


Measured memory_bytes: 256
def prim():
 a=int(input())
 # l=[i for i in range(1,a)]
 l1=[]
 for j in range(0,a):
  for i in range(2,a+j):
      l1.append((a+j)%i)
  if 0 not in l1:
      return a+j
  l1=[]
  # print(a+j)
print(prim())


Measured memory_bytes: 6936
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <sstream>
#include <map>
#include <set>
#include <bitset>

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1<<30
#define pb push_back
#define mp make_pair

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

ll n, m;
ll c;

ll lcm(ll m, ll n) {
	if(m == 0 || n == 0) return 0;
	return ((m / __gcd(m,n)) * n);
}

ll f(vector<ll> v) {
	int k = v.size();
	c = 0;
	ll ret = 0;
	rep(i, 1<<k) {
		ll x = 1;
		int cnt = 0;
		bool ch = false;
		rep(j, k) {
			if(i & (1<<j)) {
				x = lcm(x, v[j]);
				cnt++;
			}

			if(x > n) {
				ch = true;
				break;
			}
		}

		if(x == 1LL) continue;
		if(ch) continue;

		ll o = n / x, s;

		if(o % 2LL == 0) {
			s = (o / 2LL) * (2LL * x + (o - 1LL) * x);
		} else {
			s = o * (x + (o - 1LL) * x / 2LL);
		}

		if(cnt % 2 == 0) {
			ret -= s;
			c -= o;
		} else {
			ret += s;
			c += o;
		}
	}

	return ret;
}

int main() {
	while(cin >> n >> m) {
		if(n == 0 && m == 0) break;

		bool flag = false;
		vector<ll> v(m);
		rep(i, m) {
			cin >> v[i];
			if(v[i] == 1) {
				flag = true;
			}
		}

		if(flag) {
			cout << fixed;
			cout.precision(20);
			cout << 0.0 << endl;
			continue;
		}

		ll sum = n * (n + 1) / 2LL;
		ll ret = f(v);
		ll res = sum - ret;
		double cnt = n - c;

		cout << fixed;
		cout.precision(20);
		cout << res / cnt << endl;
	}

	return 0;
}

Measured memory_bytes: 1280
require 'date'
d1 = Date.new(2018,1,1)
a, b = gets.split(" ").map(&:to_i)
d2 = Date.new(2018,a,b)
ans = 0
(d1..d2).each do |dd|
  ans += 1 if dd.day == dd.month
end
puts ans

Measured memory_bytes: 2168
#include<bits/stdc++.h>
using namespace std;
#define F0(i,n) for(int i=0;i<int(n);++i)
#define F1(i,n) for(int i=1;i<=int(n);++i)
#define X first
#define Y second
#define PB push_back
#define MP make_pair
typedef long long ll;
typedef pair<int,int> pii;
int m10[200010];
int mod_pow(int x, int pow) {
    // (x * 10^pow)%2019
    return (x * m10[pow]) % 2019;
}
int main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    m10[0] = 1;
    F1(i, 200010-1){
        m10[i] = (m10[i-1] * 10) % 2019;
    }

    string s;
    cin>>s;
    
    int n = int(s.size());
    vector<int> t(n+2);
    vector<int> ctr(2019, 0);
    t[n] = 0; ++ctr[0];
    for(int i=n-1; i>=0; --i){
        t[i] = (t[i+1] + mod_pow(s[i]-'0', n-1-i)) % 2019;
        ++ctr[t[i]];
    }
    ll a = 0;
    F0(i, 2019) {
        if(ctr[i])
            a += ctr[i] * (ctr[i]-1) / 2;
    }
    cout << a<<endl;
}


Measured memory_bytes: 5152
/* BISMILLAHIR RAHMANIR RAHIM */
#include<bits/stdc++.h>
using namespace std;
#define ll        long long
#define ull       unsigned long long
#define si(x)     scanf("%d", &x)
#define sll(x)    scanf("%lld", &x)
#define ssll(x,y)    scanf("%lld %lld", &x ,&y)
#define sd(x)     scanf("%lf", &x)
#define l0(i,n)   for(ll i=0; i<n; i++)
#define MAX       100005
#define maxn 	  200002
#define pb 		  push_back
#define mk 		  make_pair
#define endl	  "\n"
#define INF 	  1000000000
#define MOD		  1000000007
#define imie(...) "[" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "


int main ()
{
		ios::sync_with_stdio(0);
		cin.tie(0);
		//CODE TONOY
		int l,r,d;
		cin >> l >> r >> d;
		int cnt = 0;
		for (int i=l ; i<=r ; i++)
		{
			if(i%d==0)
			cnt++;
		}
		cout << cnt << endl;
		return 0;  
}  


Measured memory_bytes: 3636
#include<bits/stdc++.h>
#include<boost/variant.hpp>
using namespace std;
typedef long long ll;
typedef vector<boost::variant<bool, ll, int, string, double, char*>> any;
template<typename T> inline void pr(const vector<T> &xs){
	for(int i=0; i<xs.size()-1; i++) cout<<xs[i]<<" ";
	(xs.empty()?cout:(cout<<xs[xs.size()-1]))<<endl;
}
template<typename T> inline void debug(const vector<T> &xs){
#ifdef DEBUG
	pr(xs);
#endif
}

int main(){
	int N, K;
	cin >> N >> K;
	string S;
	cin >> S;

	int x=0, o=0;
	int ans = 0;
	for(int i=0; i<N-1; i++){
		if(S[i]=='R'&&S[i+1]=='L') x++;
		else if(S[i]=='L'&&S[i+1]=='R') o++;
	}

	for(int i=0; i<N; i++){
		if(i<N-1&&S[i]=='R'&&S[i+1]=='R') ans++;
		else if(i>0&&S[i]=='L'&&S[i-1]=='L') ans++;
	}

	debug(any{x, o, ans});
	if(2*K<x+o){
		cout << ans + 2*K << endl;
	} else {
		cout << ans + x + o << endl;
	}

	return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000007;
 
int main(){
  int A, B, C;
  cin >> A >> B >> C;
  if(C < A) cout << "NO" << endl;
  else if(C > A+B) cout << "NO" << endl;
  else cout << "YES" << endl;
}

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



using namespace std;

int a[4][3][10];

int main() {
    int n;
    int b, f, r, v;
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> b >> f >> r >> v;
        a[b - 1][f - 1][r - 1] += v;
    }

    for (int i = 0; i < 4; i++) {
        for (int j = 0; j < 3; j++) {
            for (int k = 0; k < 10; k++) {
                cout << " " << a[i][j][k];
            }
            cout << endl;
        }
        if (i != 3) {
            cout << "####################" << endl;
        }
       
    }
}


Measured memory_bytes: 3088
using namespace std;

#include <bits/stdc++.h>

int main(){
    int N;
    cin >> N;
    bool fail = false;
    int prev;
    cin >> prev;
    prev -= 1;
    for ( int i = 1; i < N; i ++ ){
        int k;
        cin >> k;
        if ( k < prev ) fail = true;
        else if ( k > prev ) k -= 1;
        prev = k;
    }
    if ( !fail ) cout << "Yes";
    else cout << "No";
}


Measured memory_bytes: 256
#include<stdio.h>

int main(){
	int a, b;
	scanf("%d %d", &a, &b);
	if(a > b){
		printf("a > b\n");
	}else if(a < b){
		printf("a < b\n");
	}else{
		printf("a == b\n");
	}
	return 0;
}

Measured memory_bytes: 1008
package main

import (
	"bufio"
	"flag"
	"fmt"
	"math"
	"os"
	"strconv"
)

var scanner *bufio.Scanner

func nextInt() int {
	scanner.Scan()

	var i, _ = strconv.Atoi(scanner.Text())

	return i
}

func nextString() string {
	scanner.Scan()

	return scanner.Text()
}

func initScanner() {
	scanner = bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
}

// math functuon
func maxInt(a, b int) int {
	return int(math.Max(float64(a), float64(b)))
}
func minInt(a, b int) int {
	return int(math.Min(float64(a), float64(b)))
}

// 階乗
func factorial(n int64) int64 {
	if n < 1 {
		return 1
	}

	return n * factorial(n-1)
}

// 順列
func permutation(n, k int64) int64 {
	return factorial(n) / factorial(n-k)
}

// 組み合わせ
func combination(n, k int64) int64 {
	if k == 0 || k == n {
		return 1
	}

	return permutation(n, k) / factorial(k)
}

// logger
var isDebug = true

func log(format string, args ...interface{}) {
	if !isDebug {
		return
	}

	fmt.Printf(format+"\n", args...)
}

func main() {
	var debugFlag = flag.Bool("debug-mode", false, "debug flag")
	flag.Parse()
	isDebug = *debugFlag

	initScanner()

	var x, a = nextInt(), nextInt()

	if x < a {
		fmt.Println(0)
	} else {
		fmt.Println(10)
	}
}


Measured memory_bytes: 640
// Example program
#include <iostream>
#include <string>
using namespace std;

int main()
{
    // 整数の入力
    int N;
    cin >> N;
    // 配列の入力
    int a[N];
    for ( int i = 0; i < N; i++ ) cin >> a[i];
    // 代入
    int tempmin=a[0];
    int tempmax=a[0];
    // 計算
    for(int i=0;i<N;i++){
        // 最大値求める
        if(a[i]>tempmax) tempmax=a[i];
        // 最小値求める
        if(a[i]<tempmin) tempmin=a[i];
    }
    // 出力
    cout << tempmax - tempmin << endl;
    return 0;
}

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

int main() {
    int n, m; cin >> n >> m;
    vector<vector<int64_t>> ab(n,vector<int64_t>(2));
    rep(i,n){
        cin >> ab[i][0] >> ab[i][1];
    }
    sort(ab.begin(),ab.end());
    int cnt = 0;
    int64_t cost = 0;
    rep(i,n){
        int64_t ai = ab[i][0];
        int64_t bi = ab[i][1];
        if(bi < m-cnt){
            cnt += bi;
            cost += ai*bi;
        }
        else{
            cost += ai*(m-cnt);
            break;
        }
    }
    cout << cost << endl;
}


Measured memory_bytes: 5760
w,h,n=map(int,input().split())
A1=[0]
A2=[w]
A3=[0]
A4=[h]
for i in range(n):
  x,y,a=map(int,input().split())
  if a==1:
    A1.append(x)
  elif a==2:
    A2.append(x)
  elif a==3:
    A3.append(y)
  else:
    A4.append(y)
if min(A2)>max(A1) and min(A4)>max(A3):
  print((min(A2)-max(A1))*(min(A4)-max(A3)))
else:
  print(0)

Measured memory_bytes: 3064
//Vinh chep code cua nhi quoc gia, dung chui Vinh hu hu :(
#include <iostream>
#define md 1000000007
using namespace std;
long long n,k,a[100005],f[105][100005];
int main()
{
    cin>>n>>k;
    for (long long i = 1; i <= n; ++i)
        cin>>a[i];
    for (long long i = 0; i <= k; i++)
    {
        f[0][i]=1;
    }
    
    for (long long i = 1; i <= n; ++i)
    {
        for (long long j = 0; j <= k; ++j)
        {
            if (j <= a[i])
            {
                f[i][j]+=f[i-1][j];
                if (f[i][j]>md) f[i][j]-=md;
            } else
            {
                long long tmp= f[i-1][j] - f[i-1][j-a[i]-1];
                tmp%=md;
                if (tmp < 0) tmp+=md;
                f[i][j]+=tmp;
                if (f[i][j]>md) f[i][j]-=md;
            }
            if (j>0) f[i][j]+=f[i][j-1];
            if (f[i][j]>md) f[i][j]-=md;
        }
    }
    if (k == 0)
    {
        cout<<1;
        return 0;
    }
    long long res=f[n][k]-f[n][k-1];
    if (res<0) res+=md;
    cout<<res;
    return 0;
}

Measured memory_bytes: 82540
#include <bits/stdc++.h>
using namespace std;
using  unll = unsigned long long ;

int main() {
  int h,n;
  cin >> h >> n;
  for(int i=0;i<n;i++){
    int a;
    cin >> a;
    h -= a;
  }
  
  if( h <= 0 ){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  
  return 0;
}

Measured memory_bytes: 256
def solve(string):
    base = int(string) if len(string) % 2 == 1 else 10**(len(string) - 1) - 1
    excepts = sum([9 * 10**(i - 1) for i in range(2, len(string), 2)])
    return str(base - excepts)


if __name__ == '__main__':
    print(solve(input()))


Measured memory_bytes: 2940
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <numeric>
#include <list>
#include <deque>
#include <string>
#include <sstream>
#include <tuple>
using namespace std;
int main() {
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    int even,odd;
    even = odd = 0;
    for (int i=0; i<n; i++) {
        int temp;
        cin >> temp;
        if (temp % 2 == 0) even += 1;
        else odd += 1;
    }
    if (odd % 2 == 0) {
        cout << "YES" << '\n';
    } else {
        cout << "NO" << '\n';
    }
    return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define print(x) cout << (x) << endl;
#define printa(x, n) for(ll i = 0; i < n; i++) {cout << (x[i]) << " ";} cout << endl;
using namespace std;
using ll = long long;

int main(void) {
    ll n;
    cin >> n;

    ll ans = 0;

    for (ll i = 1LL; i * i <  n; i++) {
        if ((n - i) % i == 0) if (n % ((n - i) / i) != 0) ans += (n - i) / i;
    }
    
    cout << ans << endl;
    return 0;
}

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

#define loop for (;;)
#define repeat(i, n) for (int i = 0; i < (n); i++)

using namespace std;

int main() {
  pair<int, int> prices[6] = {
    make_pair(2, 380),
    make_pair(3, 550),
    make_pair(5, 850),
    make_pair(2 * 5, 380 * 5 * 80 / 100),
    make_pair(3 * 4, 550 * 4 * 85 / 100),
    make_pair(5 * 3, 850 * 3 * 88 / 100)
  };
  int dp[51] = {0};
  fill(dp+1, dp+51, 100000);
  for (int i = 2; i <= 50; i++)
    repeat(j, 6)
      if (i - prices[j].first >= 0)
        dp[i] = min(dp[i], dp[i-prices[j].first] + prices[j].second);
      else
        break;
  loop {
    int needed;
    cin >> needed;
    if (!needed) return 0;
    cout << dp[needed / 100] << endl;
  }
}

Measured memory_bytes: 0
from collections import deque
from sys import stdin
input = stdin.readline

n,q = map(int, input().split())
olist = deque()
for i in range(n):
    p,t = map(str, input().split())
    olist.append([p, int(t)])
count = 0
while olist:
    order = olist.popleft()
    remaintime = order[1] - q
    if remaintime > 0:
        count += q
        olist.append([order[0], remaintime])
    else:
        count += order[1]
        print(order[0], count)


Measured memory_bytes: 13296
#include<algorithm>
#include<complex>
#include<ctype.h>
#include<iomanip>
#include<iostream>
#include<fstream>
#include<map>
#include<math.h>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<stdio.h>
#include<string>
#include<string>
#include<vector>

using namespace std;
typedef long long ll;

#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("Yes")
#define p_no() p("No")

const ll mod = 1e9 + 7;
const ll inf = 1e18;

template < typename T >
void vprint(T &V){
	for(auto v : V){
    	cout << v << " ";
	}
	cout << endl;
}

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

    // input
    ll N;
    cin >> N;

    vector<ll> A(N);
    FOR(i, 0, N){
        cin >> A.at(i);
    }

    ll answer = 0;
    ll sum = 0;
    FOR(i, 0, N){
        if(A[i]==0){
            answer += sum/2;
            sum = 0;
        }
        else{
            sum += A[i];
        }
    }
    answer += sum/2;

    p(answer);
    
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std ;
#define ll long long
inline int D(){
    int t ;
    scanf( "%d" , &t ) ;
    return t ;
}
inline ll LLD(){
    ll t ;
    scanf( "%lld" , &t ) ;
    return t ;
}


//#########################################

int main() {
    int a,b,c,d;
    scanf("%d %d %d %d",&a,&b,&c,&d);
    int mx=max(a,c);
    int mn=min(b,d);
    mn-=mx;

    if(mn>=0){
        printf("%d\n",mn);
    }
    else
        printf("0\n");


}


Measured memory_bytes: 256
#include <iostream>
#include <math.h>
using namespace std;
int main(int argc, char* argv[])
{
	int A,B,C,D,E;
	cin>>A;
	cin>>B;
	cin>>C;
	cin>>D;
	cin>>E;
	int a1,b1,c1,d1,e1;
	int i;
	int maxV=0;
	for (i=0;i<=130;i+=10){
		if (A<=i){
			a1=i-A;
			A=i;
			break;
		}
	}
	maxV=max(maxV,a1);
	for (i=0;i<=130;i+=10){
		if (B<=i){
			b1=i-B;
			B=i;
			break;
		}
	}
	maxV=max(maxV,b1);
	for (i=0;i<=130;i+=10){
		if (C<=i){
			c1=i-C;
			C=i;
			break;
		}
	}
	maxV=max(maxV,c1);
	for (i=0;i<=130;i+=10){
		if (D<=i){
			d1=i-D;
			D=i;
			break;
		}
	}
	maxV=max(maxV,d1);
	for (i=0;i<=130;i+=10){
		if (E<=i){
			e1=i-E;
			E=i;
			break;
		}
	}
	maxV=max(maxV,e1);
	cout<<A+B+C+D+E-maxV<<endl;
	return 0;
}

Measured memory_bytes: 256
fun main() {
	readLine()
	val a = readLine()!!.split(" ").map {it.toInt()}
	val m = mutableMapOf<Int,Long>()
	println(a.withIndex().reversed().map {(i,v)->
		m[i-v] = (m[i-v] ?: 0)+1
		m[i+v] ?: 0L
	}.sum())
}


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

long long n, k, t, u, v, l;
vector<bool> road;
vector<long long> d;

long double solve();

int main() {
  cout << fixed << setprecision(10);
  cin >> n >> k >> t >> u >> v >> l;
  d.resize(n);
  for(int i = 0; i < n; ++i) cin >> d[i];
  cout << solve() << endl;
  return 0;
}

long double solve() {
  long long now = 0, cnt = 0, ud = 0, vd = 0;
  road.assign(l + 1, 0);
  for(int i = 0; i < n; ++i) road[d[i]] = 1;
  for(int i = 1; i <= l; ++i) {
    if(now < i)
      ++ud;
    else
      ++vd;
    if(road[i]) {
      if(now < i)
        now = i + t * v;
      else
        ++cnt;
    }
    if(cnt > k || (cnt != 0 && now <= i)) {
      now = i + t * v;
      --cnt;
    }
  }
  return (long double)ud / u + (long double)vd / v;
}


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

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> H(N);
  for (int &e : H) cin >> e;
  vector<vector<int>> G(N);
  for (int i = 0; i < M; i++) {
    int a, b;
    cin >> a >> b;
    a--; b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  
  int ans = 0;
  for (int i = 0; i < N; i++) {
    int h = H[i];
    bool b = true;
    for (int e : G[i]) {
      if (H[e] >= h) b = false;
    }
    if (b) {
      ans += 1;
    }
  }
  
  cout << ans << endl;
}

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

#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")

#define fi first
#define se second
#define pb push_back
#define last(s) (s)[(s).size()-1]
#define all(a) (a).begin(),(a).end()
#define elif else if
#define left asdasd
#define next zaza
#define prev azaz
#define cclear cout<<flush;
#define x0 kerker
#define time chas
#define y0 lolik
#define kchay ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define files freopen("little.in", "r", stdin);freopen("little.out", "w", stdout);

using namespace std;

using llong = long long;
using ld = long double;
using itn = int;
using ii = pair<int,int>;\
using ull = unsigned long long;
using pll = pair<llong, llong>;
using psi = pair<string, int>;
using ll = pair<llong, llong>;

const llong over999 = 1e9;
const ld over999ld = 1e18+1;
const llong md = 1e9+7;
const ld eps = 1e-9;
const ld Pi = acos(-1);
const llong nich = 0;
const llong mnogo = 300;

/**/


llong n, m,ans;
int32_t main() {
    kchay;
    
    cin >> n >> m;
    
    ans = (n>1)*2 + (m > 1) * 2;
    ans += (max(0ll, n-2) + max(0ll, n-2)*(n>1))*(m>1);
    ans += (max(0ll, m-2) + max(0ll, m-2)*(m>1))*(n>1);
    // cout << ans << endl;
    cout << n*m - ans;
    return 0;
}

Measured memory_bytes: 256
use std::cmp::max;

fn main() {
    let mut buf = String::new();
    let handle = std::io::stdin();
    let n: usize = {
        handle.read_line(&mut buf).unwrap();
        let tmp = buf.trim().parse().unwrap();
        buf.clear();
        tmp
    };
    let abcs: Vec<Vec<isize>> = {
        let mut tmp = Vec::with_capacity(n);
        for i in 0..n {
            handle.read_line(&mut buf).unwrap();
            let t: Vec<isize> = buf.trim().split_whitespace().map(|a| a.parse().unwrap()).collect();
            buf.clear();
            tmp.push(t);
        }
        tmp
    };
    let mut memo = vec![vec![-1; 3]; n];
    for i in 0..3 {
        memo[0][i] = abcs[0][i];
    }
    for i in 0..3 {
        dp(i, n-1, n, &abcs, &mut memo);
    }
    println!("{}", memo[n-1].iter().max().ok_or("wtf").unwrap());
}

fn dp(which: usize, i: usize, n: usize, abcs: &Vec<Vec<isize>>, memo: &mut Vec<Vec<isize>>) -> isize {
    if i == 0 {
        return memo[0][which];
    }
    if memo[i][which] == -1 {
        if which == 0 {
            memo[i][which] = max(dp(1, i-1, n, abcs, memo) + abcs[i][which], dp(2, i-1, n, abcs, memo) + abcs[i][which]);
        } else if which == 1 {
            memo[i][which] = max(dp(0, i-1, n, abcs, memo) + abcs[i][which], dp(2, i-1, n, abcs, memo) + abcs[i][which]);
        } else if which == 2 {
            memo[i][which] = max(dp(0, i-1, n, abcs, memo) + abcs[i][which], dp(1, i-1, n, abcs, memo) + abcs[i][which]);
        } else {
            panic!("no which");
        }
    }
    memo[i][which]
}

Measured memory_bytes: 24828
#include<stdio.h>
int main(void){
    int n;
    scanf("%d",&n);
    int a,b;
    a=n%100;
    b=a%10;
    if(n/100==7||a/10==7||b==7){
        printf("Yes\n");
    }else{
        printf("No\n");
    }
    return 0;
}

Measured memory_bytes: 1660
#define _CRT_SECURE_NO_WARNINGS
#include <cassert>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;


const int SZ = 5003;
int N;
ll A[SZ];
vector<int> adj[SZ];

void readInput() {
	//freopen("input.txt", "r", stdin);
	cin >> N;
	for (int i=1; i<=N; i++) cin >> A[i];
	for (int z=0; z<N-1; z++) {
		int u, v; cin >> u >> v;
		adj[u].push_back(v);
		adj[v].push_back(u);
	}
}


int tsz[SZ];
ll D[SZ][SZ];
bool E[SZ][SZ];

void solve(int p, int u) {
	tsz[u] = 1;
	D[u][0] = A[u];
	E[u][0] = A[u] > 0;
	if (adj[u].size()==1 && adj[u][0]==p) return;

	for (int v : adj[u]) if (v != p) solve(u, v);
	for (int v : adj[u]) if (v != p) {
		static ll DD[SZ];
		static bool EE[SZ];
		memset(DD, 1, sizeof(DD));
		memset(EE, 0, sizeof(EE));

		for (int a=0; a<tsz[u]; a++) for (int b=0; b<tsz[v]; b++) {
			DD[a+b] = min(DD[a+b], D[u][a]+D[v][b]);
			if (D[v][b]<0 || E[v][b]) DD[a+b+1] = min(DD[a+b+1], D[u][a]);
		}
		if (A[u]>0) for (int a=0; a<tsz[u]; a++) for (int b=0; b<tsz[v]; b++) {
			if (A[v]>0) EE[a+b] = EE[a+b] || (E[u][a] && E[v][b]);
			if (D[v][b]<0 || E[v][b]) EE[a+b+1] = EE[a+b+1] || E[u][a];
		}

		tsz[u] += tsz[v];
		memcpy(D[u], DD, sizeof(D[u]));
		memcpy(E[u], EE, sizeof(E[u]));
	}
}



int main() {
	readInput();
	solve(-123, 1);

	int ans = 1e9;
	for (int k=0; k<N; k++) {
		if (D[1][k] < 0) ans = min(ans, k);
		if (E[1][k]) ans = min(ans, k);
	}
	cout << ans << endl;

	return 0;
}

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

#define all(x) x.begin(), x.end()

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int MN = 1e5 + 5, LN = 17, INF = 0x3f3f3f3f, MOD = 1e9 + 7;

int main() {
    ios_base::sync_with_stdio(false), cin.tie(nullptr);
    string s; cin >> s;
    int ret = 0;
    for (int i = 0; i < (s.length() + 1) / 2; i++) {
        if (s[i] == 'p') ret--;
    }
    for (int i = (s.length() + 1) / 2; i < s.length(); i++) {
        if (s[i] == 'g') ret++;
    }
    cout << ret << '\n';
    return 0;
}

Measured memory_bytes: 512
#include<stdio.h>

#define MAX 50000000

int A[MAX], n;

int partition(int p, int r){

  int x, i, j, tmp;

  x = A[r];
  i = p - 1;

  for(j = p; j < r; j++){
    if(A[j] <= x){
      i++;

      tmp = A[i];
      A[i] = A[j];
      A[j] = tmp;
    }
  }
  tmp = A[i + 1];
  A[i + 1] = A[r];
  A[r] = tmp;

  return i + 1;
}

int main(){

  int i, q;

  scanf("%d", &n);

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

  q = partition(0, n - 1);

  for(i = 0; i < n; i++){
    if(i)
      printf(" ");
    if(i == q)
      printf("[");
    printf("%d", A[i]);
    if(i == q)
      printf("]");
  }
  printf("\n");

  return 0;
}


Measured memory_bytes: 2160
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <fstream>
#include <sstream>
#include <iomanip>
#define ll long long

using namespace std;

long long MOD = 1000000007;

int main(){
    int N;
    cin >> N;
    vector<int> W(N+1,0);
    for(int i=1; i<=N; i++){
        cin >> W[i];
        W[i]+=W[i-1];
    }
    int ans=MOD;
    for(int i=0; i<=N; i++){
        ans=min(ans,abs(W[N]-2*W[i]));
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <iterator>

using namespace std;

int w, h;
string str[30];

int search(int y, int x){
	if(x < 0 || x >= w || y < 0 || y >= h){
		return 0;
	}
	if(str[y][x] == '#'){
		return 0;
	}
	str[y][x] = '#';
	int ret = 1;
	ret += search(y, x - 1);
	ret += search(y, x + 1);
	ret += search(y - 1, x);
	ret += search(y + 1, x);
	return ret;
}

int main(){
	
	while(true){
		cin >> w >> h;
		if(w == 0 && h == 0){
			break;
		}
		for(int i = 0; i < h; i++){
			cin >> str[i];
		}
		int ans;
		for(int i = 0; i < h; i++){
			for(int j = 0; j < w; j++){
				if(str[i][j] == '@'){
					ans = search(i, j);
				}
			}
		}
		cout << ans << endl;
	}
	
	return 0;
}

Measured memory_bytes: 3112
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
    string S;
    cin >> S;
    int c = 0;
    for ( int i = 0; i < S.size(); i++ ) {
        if ( S[i] == 'x' ) c++;
    }
    string ans = (c >= 8 ? "NO" : "YES");
    cout << ans << '\n';
    return 0;
}

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

int n, t, x, y, px, py, pt;

int main() {
	scanf("%d", &n);
	while (n--) {
		scanf("%d%d%d", &t, &x, &y);
		int md = abs(px - x) + abs(py - y);
		if (md > t - pt) {
			puts("No");
			return 0;
		}
		if (md % 2 != (t - pt) % 2) {
			puts("No");
			return 0;
		}
		px = x; py = y; pt = t;
	}
	puts("Yes");
}

Measured memory_bytes: 256
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
#include<list>
#include<bitset>
#include<stack>
#include<memory>
#include<numeric>
using namespace std;
using namespace std::chrono;
typedef long long int llint;
typedef double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
/*cout<<fixed<<setprecision(20);cin.tie(0);ios::sync_with_stdio(false);*/
const llint mod=1000000007;
const llint big=2.19e14+1;
const long double pai=3.141592653589793238462643383279502884197;
const long double eps=1e-12;
template <class T,class U>bool mineq(T& a,U b){if(a>b){a=b;return true;}return false;}
template <class T,class U>bool maxeq(T& a,U b){if(a<b){a=b;return true;}return false;}
llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);}
llint lcm(llint a,llint b){if(a==0){return b;}return a/gcd(a,b)*b;}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());}
template<class T>llint LBI(const vector<T>&ar,T in){return lower_bound(ar.begin(),ar.end(),in)-ar.begin();}
template<class T>llint UBI(const vector<T>&ar,T in){return upper_bound(ar.begin(),ar.end(),in)-ar.begin();}

bool solve(void){
	int i,h,w,n;cin>>h>>w>>n;
	vector<pair<int,int>>ami(n);
	for(i=0;i<n;i++){cin>>ami[i].fir>>ami[i].sec;ami[i].fir--;ami[i].sec--;}
	SO(ami);REV(ami);
	vector<int>go(w);
	for(i=0;i<w;i++){
		int L;
		if(i%2==0){L=i+h;}
		else{L=i-h;}
		if(L<0){L=abs(L)-1;}L%=w*2;if(L>=w){L=w+w-1-L;}
		go[i]=L;
		
	}
	for(auto it:ami){
		int x,y;
		tie(y,x)=it;
		int L=x-y;if(L<0){L=abs(L)-1;}L%=w*2;if(L>=w){L=w+w-1-L;}
		int R=x+1+y;R%=w*2;if(R>=w){R=w+w-1-R;}
		swap(go[L],go[R]);
	}
	for(i=0;i<w;i++){cout<<go[i]+1<<endl;}
	return false;
}
int main(void){
	cout<<fixed<<setprecision(20);
	cin.tie(0);ios::sync_with_stdio(false);
	while(solve()){}
	return 0;
}



Measured memory_bytes: 5192
#include<iostream>
using namespace std;
int main(){
  int n,m,lmax,rmin,num;
  cin >> n >> m;
  int l,r;
  cin >> l >> r;
  lmax = l;
  rmin = r;
  for(int i=0;i<m-1;i++){
    cin >> l >> r;
    lmax = (lmax>l)?lmax:l;
    rmin = (rmin<r)?rmin:r;
  }
  num = rmin-lmax+1;
  if(num<0)num=0;
  num = (n<num)?n:num;
  cout << num << endl;
}


Measured memory_bytes: 256