akhauriyash/Code-Regression huggingface dataset:
S = input()
Q = int(input())
flag = True
from collections import deque
que=deque(S)

for i in range(Q):
    a = input().split()
    if a[0]=="1":
        flag = not flag

    else:
        f = a[1]
        c = a[2]
        if f=="1":
            if flag:
                que.appendleft(c)
            else:
                que.append(c)
        else:
            if flag:
                que.append(c)
            else:
                que.appendleft(c)

if not flag:
    que.reverse()

print("".join(que))

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

#define ll long long
#define INF_LL 1LL << 60
#define INF 99999999
#define MOD (ll)1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, a, n) for(int i = a; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

void put_double(double obj){printf("%.12f\n",obj);};

template < typename T > std::string to_string( const T& n )
{
    std::ostringstream stm ;
    stm << n ;
    return stm.str() ;
}

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; }


int main()
{
    char X,Y;
    cin >> X >> Y;

    if( X < Y ) cout << "<" << endl;
    else if( X == Y ) cout << "=" << endl;
    else cout << ">" << endl;
}


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

using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()
#define all2(a, b) (a).begin(), (a).begin() + (b)
#define debug(vari) cerr << #vari << " = " << (vari) << endl;

char *demangle(const char *demangle)
{
    int status;
    return abi::__cxa_demangle(demangle, 0, 0, &status);
}

int main()
{
    int N;
    string S;
    cin >> N;
    vector<int> vec(N);
    rep(i, N) cin >> vec[i];

    int ans = 0;
    rep(i,N-1){
        rep2(j,i+1,N){
            ans += vec[i] * vec[j];
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i = a; i < b; i++)
#define REP(i, n) FOR(i, 0, n)
#define INF 999999999
typedef long long ll;
using namespace std;
int main() {
    int X, A, B;
    cin >> X >> A >> B;
    X -= A;
    X -= B*(X/B);
    cout << X << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cstdio>
#include <cassert>
#include <cmath>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

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

const int INF = 1 << 29;

struct Edge {
    int to;
    int dist;
    int cost;

    Edge() {}
    ~Edge() {}

    Edge(int a, int b, int c):
        to(a), dist(b), cost(c) {}
};


struct Status {
    int pos;
    int prev;
    int dist;
    int cost;

    Status() {}
    ~Status() {}

    Status(int a, int b, int c, int d):
        pos(a), prev(b), dist(c), cost(d) {}

    bool operator == (const Status& s) const {
        return dist == s.dist;
    }

    bool operator < (const Status& s) const {
        return dist < s.dist;
    }

    bool operator > (const Status& s) const {
        return dist > s.dist;
    }
};



int solve() {
    int N, M;
    vector<vector<Edge>> graph;
    map<pair<int,int>,int> costs;
    
    cin >> N >> M;
    if (N == 0 && M == 0) {
        return false;
    }

    graph.resize(N);

    for (int j = 0; j < M; ++j) {
        int u, v, d, c;
        cin >> u >> v >> d >> c;
        --u; --v;

        graph[u].push_back(Edge(v, d, c));
        graph[v].push_back(Edge(u, d, c));
        costs[make_pair(u, v)] = c;
        costs[make_pair(v, u)] = c;
    }

    priority_queue<Status, vector<Status>, greater<Status>> pq;
    vector<Status> best(N, Status(-1, -1, INF, INF));

    Status start = Status(0, -1, 0, 0);
    pq.push(start);
    best[0] = start;

    int ret = 0;

    while (!pq.empty()) {
        Status st = pq.top(); pq.pop();
        if (st.prev != best[st.pos].prev) {
            continue;
        }

        if (st.prev >= 0) {
            ret += costs[make_pair(st.pos, st.prev)];
        }

        for (Edge& e: graph[st.pos]) {
            Status new_st = Status(e.to, st.pos,
                    st.dist + e.dist,
                    st.cost + e.cost);
            if (new_st < best[e.to]) {
                best[e.to] = new_st;
                pq.push(new_st);
            } else if (new_st == best[e.to] && e.cost < best[e.to].cost - best[best[e.to].prev].cost) {
                best[e.to] = new_st;
                pq.push(new_st);
            }
        }
    }

    cout << ret << endl;
    return true;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    while(solve());
    return 0;
}

Measured memory_bytes: 6808
// I SELL YOU...! 
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<chrono>
#include<iomanip>
#include<map>
#include<set>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using TP = tuple<ll,ll,ll>;
void init_io(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(18);
}
signed main(){
  init_io();
  ll a,b;
  cin >> a >> b;
  cout << a*b<<endl;
}


Measured memory_bytes: 3664
import math

N,M=map(int,input().split())
student=[list(map(int,input().split())) for _ in range(N)]
check=[list(map(int,input().split())) for _ in range(M)]
#print(student,check)
#print("\n")
for i in range(N):
    dist = float("inf")
    point = 0
    for j in range(M):
        if abs(student[i][0]-check[j][0])+abs(student[i][1]-check[j][1])<dist:
            dist=abs(student[i][0]-check[j][0])+abs(student[i][1]-check[j][1])
            point=j+1
        #print(point,dist)
    print(point)


Measured memory_bytes: 39792
use std::io::*;
use std::str::*;

fn read<T: FromStr>(s: &mut StdinLock) -> Option<T> {
    let s = s
        .by_ref()
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect::<String>();
    s.parse::<T>().ok()
}

fn main() {
    let s = stdin();
    let mut s = s.lock();
    let N: i32 = read(&mut s).unwrap();

    if N < 105 {
        println!('0');
    } else if N < 135 {
        println!('1');
    } else if N < 165 {
        println!('2');
    } else if N < 189 {
        println!('3');
    } else if N < 195 {
        println!('4')
    } else {
        println!('5')
    }
}


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

//repetition
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)

//container util
#define all(x) (x).begin(),(x).end()

//typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;

//const value
//const ll MOD = 1e9 + 7;
const ll INF = 1e10;
//const int dx[] = {0,1,0,-1};//{0,0,1,1,1,-1,-1,-1};
//const int dy[] = {1,0,-1,0};//{1,-1,0,1,-1,0,1,-1};

//conversion
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
inline ll toLL(string s) {ll v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
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 dp[1<<18][51];

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n; cin >> n;
  int card[2][n];
  rep(i,n) cin >> card[0][i];
  rep(i,n) cin >> card[1][i];

  // dp tanle init
  rep(i,1<<n) rep(j,51) dp[i][j] = 1e10;
  dp[0][0] = 0;

  // solve
  rep(state,(1<<n)-1) rep(maxNum,51) {
    ll nextIdx = __builtin_popcountll(state);

    rep(i,n){
      if( ((state>>i) & 1) == 1 ) continue;
      ll cardFlag = abs(nextIdx - i)%2;

      if(card[cardFlag][i] >= maxNum ){ // 設置できる
        // 遷移コストの計算
        ll mvCost = 0;
        FOR(j,0,i) if(((state>>j) & 1) == 0 ) mvCost++;

        chmin(dp[state | (1<<i)][card[cardFlag][i]], dp[state][maxNum] + mvCost);
      }
    }
  }

  ll ans = INF;
  rep(i,51) ans = min(dp[(1<<n)-1][i],ans);
  
  if(ans == INF)  cout << -1 << endl;
  else            cout << ans << endl;

  return 0;
}


Measured memory_bytes: 104704
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <complex>
typedef long long int LL;
using namespace std;

// 插入此處

double s(LL n) {
    LL c = n;
    LL d = 0;
    while (c > 0) {
        d += (c % 10);
        c /= 10;
    }
    return d;
}

double snuke(LL n) {
    return double(n) / s(n);
}

int main() {
    // printf("%lf\n", pow(10LL, 15LL));
    int k;
    scanf("%d", &k);
    int count = 0;

    LL interval = 1;
    LL x = 1;
    while (count < k) {
        if (snuke(x) <= (double)interval) {
        // if (snuke(x) <= snuke(x + interval)) {
            printf("%lld\n", x);
            x += interval;
            count++;
        } else {
            x -= interval;
            interval *= 10;
            x += interval;
        }
    }

    // for (count = 1; count < 10 && count <= k; count++) {
    //     printf("%d\n", count);
    // }
    // for (LL digit = 1; count <= k; digit++) {
    //     LL g = pow(10LL, digit);
    //     for (LL i = 2; i <= 10 && count <= k; i++) {
    //         printf("%lld\n", g * i - 1);
    //         count++;
    //     }
    // }
}


Measured memory_bytes: 128
#include <iostream>
#include <string>
using namespace std;
int main(void){
    string s;
    cin >> s;
    long long int q;
    cin >> q;
     
    for(long long int i=0;i<q;i++){
        string in;
        cin >> in;
        if(in=="print"){
            long long int a,b;
            cin>>a>>b;
            cout<< s.substr(a,b-a+1)<<endl;
             
        }else if(in=="reverse"){
            long long int a,b;
            cin>>a>>b;
            string k=s;
            for(long long int j=a;j<=b;j++){
                s[j]=k[a+b-j];
            }
        }else if (in=="replace"){
            long long int a,b;
            cin>>a>>b;
            for(long long int j=a;j<=b;j++){
                char c;
                cin>>c;
                s[j]=c;
            }
        }
    }
}


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

int main()
{
    int a,b,c;

    scanf("%d %d %d",&a,&b,&c);

    if(a+b+c <= 21)
    printf("win\n");
    else
    {
        printf("bust\n");
    }
    

    return 0;
}

Measured memory_bytes: 128
n = gets.to_i
a = gets.split.map(&:to_i)
sum = []
s = 0
a.each do |ai|
  s += ai
  sum << s
end
ans = 0
(0...n).each do |i|
  ans += a[i] * (s - sum[i])
end
puts ans % 1000000007


Measured memory_bytes: 35580
#include<bits/stdc++.h>
using namespace std;
const int N=1e4,M=1e9+7;
long long n,m,i,j;
char c[N][N];
long long dp[N][N];
main(){
    cin>>n>>m;
    for(i=1;i<=n;i++){
        for(j=1;j<=m;j++)cin>>c[i][j];
    }
    dp[1][1]=1;
    for(i=1;i<=n;i++){
        for(j=1;j<=m;j++){
            if(c[i][j] == '#')continue;
            if(c[i-1][j] == '.')dp[i][j]=(dp[i][j]+dp[i-1][j])%M;
            if(c[i][j-1] == '.')dp[i][j]=(dp[i][j]+dp[i][j-1])%M;
        }
    }
    cout<<dp[n][m]<<endl;
}

Measured memory_bytes: 90624
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
  int n;
  cin >> n;

  ll name[5] = {0, 0, 0, 0, 0};
  for (int i = 0; i < n; i++)
  {
    string s;
    cin >> s;

    if (s[0] == 'M')
    {
      name[0]++;
    }
    else if (s[0] == 'A')
    {
      name[1]++;
    }
    else if (s[0] == 'R')
    {
      name[2]++;
    }
    else if (s[0] == 'C')
    {
      name[3]++;
    }
    else if (s[0] == 'H')
    {
      name[4]++;
    }
  }

  ll res = 0;
  for (int i = 0; i < 3; i++)
  {
    for (int j = i + 1; j < 4; j++)
    {
      for (int k = j + 1; k < 5; k++)
      {
        res += name[i] * name[j] * name[k];
      }
    }
  }

  cout << res << endl;
}

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

int main(){
 int a,b;
 char op;

 int num[3000];
 int count = 0;

 while(1){
  cin >> a >> op >> b;
  if( op == '?' ){
   break;
  }

  if( op == '+' ){
   num[count] = a+b;
  }else if( op == '-' ){
   num[count] = a-b;
  }else if( op == '*' ){
   num[count] = a*b;
  }else if( op == '/' ){
   num[count] = a/b;
  }
  count++;
 }

 for( int i=0; i<count; i++ ){
  cout << num[i] << endl;
 }

 return 0;
}


Measured memory_bytes: 3104
from collections import defaultdict
N, K, Q = map(int,input().split())
d = defaultdict(int)
for _ in range(Q):
  a = int(input())
  d[a]+=1
for i in range(1,N+1):
  if K-Q+d[i]>0:
    print('Yes')
  else:
    print('No')

Measured memory_bytes: 89364
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees#, log2, log
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
from decimal import Decimal
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7
from decimal import *

Q, H, S, D = MAP()
N = INT()

ans1 = 4*Q*N
ans2 = 2*H*N
ans3 = S*N
ans4 = D*(N//2) + min(4*Q, 2*H, S)*(N%2)

print(min(ans1, ans2, ans3, ans4))

Measured memory_bytes: 5708
#include "bits/stdc++.h"
#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##_len=(b);i<i##_len;++i)
#define MSVC_UNKO(x)x
#define rep(...)MSVC_UNKO(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define all(c)c.begin(),c.end()
#define write(x)cout<<(x)<<'\n'
using namespace std; typedef long long ll; template<class T>using vv = vector<vector<T>>;
template<class T>auto vvec(int n, int m, T v) { return vv<T>(n, vector<T>(m, v)); }
template<class T, class U>bool chmax(T& a, U&& b) { return a < b ? a = b, 1 : 0; }
template<class T, class U>bool chmin(T& a, U&& b) { return b < a ? a = b, 1 : 0; }
constexpr int INF = 1 << 29, MOD = int(1e9) + 7; constexpr ll LINF = 1LL << 60;
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); }; }aaaa;

int main() {
    int N;
    cin >> N;
    vector<int> X(N);
    rep(i, N) cin >> X[i];

    vector<pair<int, int>> xn(N);
    rep(i, N) xn[i] = { X[i], i };
    sort(all(xn));

    vector<pair<int, int>> task(N);
    rep(i, N) task[i] = { xn[i].second + 1, xn[i].second };

    int k = 0;
    queue<pair<int, int>> res, free;
    vector<int> ans;
    for (int i = 0; i < N * N; ) {
        if (!res.empty() && res.front().second == i + 1) {
            ans.push_back(res.front().first);
            i++;
            free.emplace(res.front().first, N - res.front().first);
            res.pop();
        }
        else if (!res.empty() && res.front().second < i + 1) {
            break;
        }
        else if (k < N) {
            if (task[k].second == 0) {
                res.emplace(task[k].first, X[task[k].first - 1]);
                k++;
                continue;
            }
            else {
                ans.push_back(task[k].first);
                i++;
                task[k].second--;
            }
        }
        else if (!free.empty() && free.front().second > 0) {
            ans.push_back(free.front().first);
            i++;
            free.front().second--;
        }
        else if (!free.empty() && free.front().second == 0) {
            free.pop();
        }
        else {
            break;
        }
    }

    if (ans.size() == N * N) {
        write("Yes");
        rep(i, N * N) cout << ans[i] << (i == N * N - 1 ? '\n' : ' ');
    }
    else write("No");
}

Measured memory_bytes: 2292
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {

		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		int ans = 0;

		List<Integer> list = new ArrayList<>();

		for (int i = 1; i <= N; i++) {
			list.add(sc.nextInt());
		}

		Map<Integer, Integer> map = new HashMap<Integer, Integer>();
		for (Integer s : list) {
		    Integer i = map.get(s);
		    map.put(s, i == null ? 1 : i + 1);
		}

		for (Integer key : map.keySet()) {
		    if (key > map.get(key)) {
				ans += map.get(key);
			} else if (key < map.get(key)) {
				ans += (map.get(key) - key);
			}
		}
		System.out.println(ans);
		sc.close();
	}
}

Measured memory_bytes: 61104
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    long long x, k, d;
    cin >> x >> k >> d;
    x = abs(x);
    long long ans;
    if(x/d > k){
        ans = x - d*k;
    }
    else{
        long long a = k - x/d;
        if(a%2)ans = x - d*(x/d + 1);
        else ans = x - d*(x/d);
    }
    cout << abs(ans) << endl;
}


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

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define LCM(a, b) (a) / __gcd((a), (b)) * (b)
#define CEIL(a, b) (a)/(b)+(((a)%(b))?1:0)
#define ln '\n'

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

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1e9 + 7;
static const int SIZE = 200005;

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

vector<LL> Div(LL n) {
    vector<LL> ret;
    for(LL i = 1; i * i <= n; ++i) {
        if(n % i == 0) {
            ret.pb(i);
            if(i * i != n) ret.pb(n / i);
        }
    }
    sort(all(ret));
    return ret;
}

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

    int N;
    cin >> N;
    LL cnt[SIZE] = {};
    for(int i = 2; i <= N; ++i) {
        int t = i;
        int c = 2;
        while(c * c <= i && t > 1) {
            while(t % c == 0) {
                ++cnt[c];
                t /= c;
            }
            ++c;
        }
        cnt[t]++;
    }

    LL res = 1;
    for(int i = 2; i <= N; ++i) {
        res = res * (cnt[i] + 1) % MOD;
    }
    cout << res << endl;

    return 0;
}



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

int n,m[205][205];

void matrix_chain_multiplication(int *p){
  int i,j,l,q,k;
  
  for(i=1; i<=n; i++){
    m[i][i] = 0;
  }
  
  for(l=2; l<=n; l++){
    for(i=1; i<=n-l+1; i++){
      j = i + l -1;
      m[i][j] = INT_MAX;
      for(k=i; k<=j-1; k++){
	q = m[i][k] + m[k+1][j] + p[i-1]*p[k]*p[j];
	if(q < m[i][j]) m[i][j] = q;
      }
    }
  }
}

main(){
  int i,a,b,p[205];
  
  scanf("%d",&n);
  for(i=0; i<n; i++){
    scanf("%d %d",&a,&b);
    if(i == 0){
      p[i] = a;
      p[i+1] = b;
    }
    else p[i+1] = b;
  }
  
  matrix_chain_multiplication(p);
  
  printf("%d\n",m[1][n]);
  
  return 0;
}

Measured memory_bytes: 676
a,b,k = gets.split.map(&:to_i)
aa = []
bb = []
for i in 1..a do
  if a%i == 0
    aa << i
  end
end

for j in 1..b do
  if b%j == 0
    bb << j
  end
end
c = aa & bb
p c.reverse[k-1]

Measured memory_bytes: 1788
#include <algorithm>
#include <iostream>
#include <stack>
#include <queue>
#include <cmath>
#include <string>
#include <iterator>
#include <map>
#include <set>
#include <iomanip>
#include <vector>
#include <fstream>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
using Graph = vector<vector<int>>;
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
#define rep(i, N) for(int i = 0; i < N; i++)
#define rep2(i, l, r) for (ll i = (ll)l; i < (ll)(r); i++)
#define INF 1000000000000000000
#define MAX 200001
#define MOD 1000000007
#define F "test.txt"

template <typename T > inline string toString(const T &a) {ostringstream oss; oss << a; return oss.str();};

int main(){
    ll H, W;
    cin >> H >> W;
    ll ans = 0;
    vector<string> S(H);
    rep(i,H) cin >> S[i];
    vector<vector<int>> seen(H, vector<int>(W,0));
    rep(i,H){
        rep(j,W){
            if(seen[i][j] == 1) continue;
            queue<pair<int,int>> q;
            q.push({i,j});
            seen[i][j] = 1;
            ll white = 0;
            ll black = 0;
            while(!q.empty()){
                int x = q.front().second;
                int y = q.front().first;
                q.pop();
                if(S[y][x] == '.') white++;
                else black++;
                for(int A = 0; A < 4; A++){
                    int n_x = x + dx[A];
                    int n_y = y + dy[A];
                    if(n_x < 0 or W <= n_x or n_y < 0 or H <= n_y or seen[n_y][n_x] == 1) continue;
                    if(S[y][x] != S[n_y][n_x]){
                        q.push({n_y,n_x});
                        seen[n_y][n_x] = 1;
                    }
                }
            }
            ans += white*black;
        }
    }
    cout << ans << endl;
}

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

using namespace std;

int n, x[505], y[505], k, s, ans;

void test(int a) {
	long long nd = 0;
	for (int i = 0; i < n; i++)
		y[i] = x[i] % a;
	sort(y, y + n);
	int ta = 0, tb = n - 1;
	while (ta != tb) {
		int tmp = min(y[ta], a - y[tb]);
		y[ta] -= tmp;
		y[tb] += tmp;
		nd += tmp;
		if (y[ta] == 0)
			ta++;
		else
			tb--;
	}
	if (nd > k)
		return;
	// printf("a=%d nd=%lld\n", a, nd);
	ans = max(ans, a);
}

int main() {
	scanf("%d%d", &n, &k);
	for (int i = 0; i < n; i++) {
		scanf("%d", x + i);
		s += x[i];
	}
	for (int i = 1; i * i <= s; i++) {
		if (s % i)
			continue;
		test(i);
		test(s / i);
	}
	printf("%d\n", ans);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define debug(x) cout<<#x<<"="<<x<<endl;

using namespace std;

int main(void)
{
	int n;
	scanf("%d",&n);
	if(n/10==9||n%10==9)printf("Yes");
	else printf("No");
	return 0;
}

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

using namespace std;

typedef long long ll;

const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = (ll)1e9 + 7;

int main()
{
  string s; cin >> s;
  int n = s.size();
  int gx, gy; scanf("%d %d", &gx, &gy);
  vector<int> X, Y;
  int i = 0;
  while (i < n and s[i] == 'F') { ++i; }
  int start_x = i;
  int dir = 0;
  while (i < n) {
    if (s[i] == 'T') {
      dir = 1 - dir;
      ++i;
    }
    else {
      int j = i;
      while (j < n and s[j] == 'F') { ++j; }
      int cnt = j - i;
      if (dir == 0) { X.push_back(cnt); }
      else { Y.push_back(cnt); }
      i = j;
    }
  }
  set<int> cur_x;
  cur_x.insert(start_x);
  for (int i = 0; i < (int)X.size(); ++i) {
    set<int> next_x;
    for (int x : cur_x) {
      next_x.insert(x + X[i]);
      next_x.insert(x - X[i]);
    }
    cur_x = next_x;
  }

  set<int> cur_y;
  cur_y.insert(0);
  for (int i = 0; i < (int)Y.size(); ++i) {
    set<int> next_y;
    for (int y : cur_y) {
      next_y.insert(y + Y[i]);
      next_y.insert(y - Y[i]);
    }
    cur_y = next_y;
  }

  bool ok = cur_x.count(gx) == 1 and cur_y.count(gy) == 1;
  printf("%s\n", ok ? "Yes" : "No");
  return 0;
}


Measured memory_bytes: 768
#include <bits/stdc++.h>
#define REP(i, a, n) for (long long i = (a); i < (long long)(n); ++i)
#define REPC(i, a, n) for (long long i = (a); i <= (long long)(n); ++i)
#define ALL(t) t.begin(), t.end()
#define RALL(t) t.rbegin(), t.rend()
#define MATINIT(type, row, col, init)                                          \
  vector<vector<type>>(row, vector<type>(col, init));
#define Yes(cond) cout << (cond ? "Yes" : "No") << endl;
#define YES(cond) cout << (cond ? "YES" : "NO") << endl;
using namespace std;
using LL = long long;
using ULL = unsigned long long;
template <class T> using VEC = std::vector<T>;
template <class T> using MAT = std::vector<std::vector<T>>;
void DUMP() { cerr << endl; }
template <class Head, class... Tail> void DUMP(Head &&head, Tail &&... tail) {
  cerr << head << ", ";
  DUMP(std::move(tail)...);
}
template <typename T> ostream &operator<<(ostream &os, vector<T> &vec) {
  os << "{";
  for (auto v : vec)
    os << v << ",";
  os << "}";
  return os;
}
template <typename T> ostream &operator<<(ostream &os, set<T> &s) {
  os << "{";
  for (auto p : s)
    os << p << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, map<T1, T2> &m) {
  os << "{";
  for (auto p : m)
    os << p << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, pair<T1, T2> p) {
  os << "[" << p.first << " " << p.second << "]";
  return os;
}

int main() {
  int N;
  cin>>N;
  VEC<int>A(N);
  VEC<pair<int, int>> B(N);
  REP(i,0,N){
    cin>>A[i];
    B[i].first=A[i];
    B[i].second=i+1;
  }
  sort(ALL(B));
  REP(i,0,N){
    cout<<B[i].second<<" ";
  }
  cout<<endl;


  return 0;
}


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

using ll = long long;

#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0, a1, a2, a3, a4, x, ...) x
#define debug_1(x1) cerr << #x1 << ": " << x1 << endl
#define debug_2(x1, x2) \
  cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << endl
#define debug_3(x1, x2, x3)                                               \
  cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " \
       << x3 << endl
#define debug_4(x1, x2, x3, x4)                                           \
  cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " \
       << x3 << ", " #x4 << ": " << x4 << endl
#define debug_5(x1, x2, x3, x4, x5)                                       \
  cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " \
       << x3 << ", " #x4 << ": " << x4 << ", " #x5 << ": " << x5 << endl
#define debug(...)                                                      \
  CHOOSE((__VA_ARGS__, debug_5, debug_4, debug_3, debug_2, debug_1, ~)) \
  (__VA_ARGS__)

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define unique(v) v.erase(unique(v.begin(), v.end()), v.end());

// UnionFind
// coding: https://youtu.be/TdR816rqc3s?t=726
// comment: https://youtu.be/TdR816rqc3s?t=6822
struct UnionFind {
  vector<int> d;
  UnionFind(int n = 0) : d(n, -1) {}
  int find(int x) {
    if (d[x] < 0) return x;
    return d[x] = find(d[x]);
  }
  bool unite(int x, int y) {
    x = find(x);
    y = find(y);
    if (x == y) return false;
    if (d[x] > d[y]) swap(x, y);
    d[x] += d[y];
    d[y] = x;
    return true;
  }
  bool same(int x, int y) { return find(x) == find(y); }
  int size(int x) { return -d[find(x)]; }
};

void solve(long long N, long long M, std::vector<long long> A,
           std::vector<long long> B) {
  vector<ll> ans(M + 1);

  ll s = N * (N - 1) / 2;
  ans.at(M) = s;
  UnionFind uf = UnionFind(N);
  for (int i = M - 1; i >= 0; i--) {
    ll n1 = uf.size(A.at(i));
    ll n2 = uf.size(B.at(i));
    if (uf.unite(A.at(i), B.at(i))) {
      ans.at(i) = ans.at(i + 1) - n1 * n2;
    } else {
      ans.at(i) = ans.at(i + 1);
    }
  }

  rep(i, M) cout << ans.at(i + 1) << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You
// use the default template now. You can remove this line by using your custom
// template)
int main() {
  long long N;
  scanf("%lld", &N);
  long long M;
  scanf("%lld", &M);
  std::vector<long long> A(M);
  std::vector<long long> B(M);
  for (int i = 0; i < M; i++) {
    scanf("%lld", &A[i]);
    scanf("%lld", &B[i]);
    // 0-indexed
    A.at(i)--;
    B.at(i)--;
  }
  solve(N, M, std::move(A), std::move(B));
  return 0;
}


Measured memory_bytes: 5908
#include <bits/stdc++.h>
using namespace std;
#define INF 1<<30
#define endl '\n'
#define maxn 100005
#define tc printf("Case %d: ", cs)
#define tcn printf("Case %d:\n", cs);
#define FASTIO ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
typedef long long ll;
const double PI = acos(-1.0);

#define dbg1(x) cerr << #x << " = " << x << endl;
#define dbg2(x, y) cerr << #x << " = " << x << ", " << #y << " = " << y << endl;
#define dbg3(x, y, z) cerr << #x << " = " << x << ", " << #y << " = " << y << ", " << #z << " = " << z << endl;
#define dbg4(w,x, y, z) cerr << #w << " = " << w << ", " <<#x << " = " << x << ", " << #y << " = " << y << ", " << #z << " = " << z << endl;

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

template < typename T >
ostream &operator << ( ostream & os, const vector< T > &v ) {
	os << "{";
	for (auto it = v.begin(); it != v.end(); ++it) {
		if ( it != v.begin() ) os << ", ";
		os << *it;
	}
	return os << "}";
}

template < typename T >
ostream &operator << ( ostream & os, const set< T > &v ) {
	os << "[";
	for (auto it = v.begin(); it != v.end(); ++it) {
		if ( it != v.begin()) os << ", ";
		os << *it;
	}
	return os << "]";
}

template < typename F, typename S >
ostream &operator << ( ostream & os, const map< F, S > &v ) {
	os << "[";
	for (auto it = v.begin(); it != v.end(); ++it) {
		if ( it != v.begin() ) os << ", ";
		os << it -> first << " = " << it -> second ;
	}
	return os << "]";
}

#define dbg(args...) do {cerr << #args << " : "; faltu(args); } while(0)

clock_t tStart = clock();
#define timeStamp dbg("Execution Time: ", (double)(clock() - tStart)/CLOCKS_PER_SEC)

void faltu () { cerr << endl; }

template <typename T>
void faltu( T a[], int n ) {
	for (int i = 0; i < n; ++i) cerr << a[i] << ' ';
	cerr << endl;
}

template <typename T, typename ... hello>
void faltu( T arg, const hello &... rest) { cerr << arg << ' '; faltu(rest...); }
// Program showing a policy-based data structure.
#include <ext/pb_ds/assoc_container.hpp> // Common file 
#include <ext/pb_ds/tree_policy.hpp>
#include <functional> // for less 
#include <iostream>
using namespace __gnu_pbds;
using namespace std;
// GNU link : https://goo.gl/WVDL6g
typedef tree<int, null_type, less_equal<int>, rb_tree_tag,
        tree_order_statistics_node_update>
        new_data_set;

/**___________________________________________________**/



int main()
{
// 	FASTIO
// 	///*
// #ifndef ONLINE_JUDGE
// 	freopen("in.txt", "r", stdin);
// 	freopen("out.txt", "w", stdout);
// 	freopen("error.txt", "w", stderr);
// #endif
// //*/
	int T;
	//scanf("%d", &T);
	T = 1;
	for (int cs = 1; cs <= T; cs++) {
		int n;
		cin >> n;
		cout << (n * n * n) << endl;
	}
	return 0;
}

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

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

  int n, l;
  cin >> n >> l;
  vector<string> s(n);
  for (int i = 0; i < n; i++) {
    cin >> s[i];
  }
  sort(s.begin(), s.end());
  for (string &t : s) {
    cout << t;
  }
  cout << '\n';
  return 0;
}

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

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

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

	int n; cin>>n;
	vector<int> dp(n + 1, n);
	dp[0] = 0;
	for(int i = 0; i < n; i++){
		dp[i + 1] = min(dp[i + 1], dp[i] + 1);
		int prd = 6;
		while(i + prd <= n){
			dp[i + prd] = min(dp[i + prd], dp[i] + 1);
			prd *= 6;
		}
		prd = 9;
		while(i + prd <= n){
			dp[i + prd] = min(dp[i + prd], dp[i] + 1);
			prd *= 9;
		}
	}
	cout<<dp[n]<<endl;

	return 0;
}

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

int i,j,k,n,m,sss,sssss,dist[200];
char ppp,seat[200],next[200];


int main(){
	while(scanf("%d %d%*c",&n,&m)*n){
		for(k=0;k<n;k++){
			seat[k]='#';
			next[k]='#';
			dist[k]=99999;
		}
		seat[n]='\0';

		for(k=0;k<m;k++){
			scanf("%c%*c",&ppp);

			sss=-1;sssss=-1;
			switch(ppp){
				case 'A':
					for(i=0;i<n;i++){if(seat[i]=='#'){sss=i;break;}}
				break;
				case 'B':
					for(i=n-1;i>=0;i--){
						if(seat[i]=='#' && next[i]!='A'){sss=i;break;}
						if(sssss<0 && seat[i]=='#')sssss=i;
					}
					if(sss==-1)sss=sssss;
				break;
				case 'C':
					if(k==0)sss=n/2;
					else{
						for(i=0;i<n;i++){
							if(seat[i]!='#'){
								if(i+1<n && seat[i+1]=='#'){sss=i+1;break;}
								if(i-1>=0 && seat[i-1]=='#'){sss=i-1;break;}
							}
						}
					}
				break;
				case 'D':
					sssss=0;
					for(i=0;i<n;i++){
						if(dist[i]>sssss){sss=i;sssss=dist[i];}
					}
				break;
			}

			seat[sss]=ppp;
			if(sss>0)next[sss-1]=ppp;
			next[sss+1]=ppp;
			for(i=0;sss-i>=0;i++){if(dist[sss-i]>i)dist[sss-i]=i; else break;}
			for(i=1;sss+i<n;i++){if(dist[sss+i]>i)dist[sss+i]=i; else break;}
		}
		
		printf("%s\n",seat);
	}
	return 0;
}

Measured memory_bytes: 588
using System;

public class Test
{
    public static void Main()
    {

        var times = int.Parse(Console.ReadLine());// ?????°???????????????

        for (int i = 0; i < times; i++)
        {
            //??????????????????????????????????????????
            string line = Console.ReadLine();

            Console.WriteLine(line.Replace("Hoshino", "Hoshina"));
        }
    }
}

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

int main(){
    ll K; cin >> K;
    cout << 50 << endl;
    vector<ll> ans(50, 0);
    rep(i, 0, 50) ans[i] = i;
    rep(i, 0, 50) ans[i] += K / 50;
    rep(i, 0, K%50) ans[49-i]++; 
    rep(i, 0, 50){
        if(i!=0) cout <<" ";
        cout << ans[i];
    }
    cout << endl;
    return 0;
}

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

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;

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

int main() {
    int n;
    ll ans = 0;
    int m[10][10] = {};
    cin >> n;

    for (int i = 1; i <= n; i++) {
        int a = i / pow(10, int(log10(i)));
        int b = i % 10;
        m[a][b]++;
    }

    for (int i = 1; i <= n; i++) {
        int a = i / pow(10, int(log10(i)));
        int b = i % 10;

        if (a == 0 || b == 0)
            continue;
        ans += m[b][a];
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n) for(ll i=0; i<(ll)n; i++)
#define REPR(i, n) for(ll i=(ll)n-1; i>=0; i--)
#define FOR(i, m, n) for(ll i=(ll)m; i<(ll)n; i++)
#define FORR(i, m, n) for(ll i=(ll)m-1; i>=(ll)n; i--)
#define ALL(x) (x).begin(), (x).end()
#define ASC(v) sort(ALL(v));
#define DESC(v) sort(ALL(v), greater<int>());
#define UNIQ(a) sort(ALL(a));(a).resize(unique(ALL(a)) - a.begin());
#define PRINTD(x, d) cout << fixed << setprecision(d) << x << "\n";
#define DEBUG(x) cout<<#x<<": "<<x<<"\n"
const double PI = acos(-1);
ll lcm(ll a, ll b) { return a / __gcd(a, b) * b; }
bool isprime(int x){ int i; if(x<2)return 0; else if(x==2) return 1; if(x%2==0) return 0; for(i=3; i*i<=x; i+=2) if(x%i==0) return 0; return 1; }
int digsum(int n) { int r=0; while(n>0) { r+=n%10; n/=10; } return r; }
vector<string> split(string s, char p){vector<string>v;stringstream m(s);string b;while(getline(m,b,p))v.push_back(b);return v;}
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; }
struct nya{ nya(){ cin.tie(0); ios::sync_with_stdio(false); } }nyan;

int main(){
    string N;
    cin >> N;
    if (N.substr(0,1)=="9" || N.substr(1,1)=="9") cout << "Yes\n";
    else cout << "No\n";
}


Measured memory_bytes: 256
while True:
    n,x = map(int,input().split())
    cnt = 0
    if n == 0 and x == 0:
        break
    else:
        for i in range(1,n):
            for j in range(i+1,n):
                for k in range(j+1,n+1):
                    if i + j + k == x:
                        cnt += 1
    print(cnt)


Measured memory_bytes: 5596
use proconio::input;

fn main() {
    input! {
        n: usize, // 展望台
        m: usize, // 道
        h: [i32; n], // 標高
        ab: [(usize, usize); m],
    }
    let mut res_vec = vec![true; n];

    for (a, b) in ab{
        if h[a - 1] >= h[b - 1] {
            res_vec[b - 1] = false;
        }
        if h[b - 1] >= h[a - 1] {
            res_vec[a - 1] = false;
        }
    }

    println!("{}", res_vec.iter().filter(|x| x == &&true).count());
}

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

int main(){
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  int e = c-a;
  int f = d-b;
  cout<<c-f<<' '<<d+e<<' '<<a-f<<' '<<b+e<<'\n';
  return 0;
}

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

int main() {
    int a,p;
    cin >> a >>p;
    if (a>=13)
        cout << p;
    else if (a >=6 && a<=12)
        cout << p/2;
    else
        cout << 0;
    
    return 0;
}

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

typedef long long ll;

// static const int MAX = 1e6;
// static const int NIL = -1;
// static const ll INF = 1<<21;
// static const ll MOD = 1e9 + 7;

bool compPair(const pair<int, int>& arg1, const pair<int, int>& arg2) {
    return arg1.first > arg2.first;
}

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

    ll a, sum=0, ans=0;
    for(int i=0;i<n+1;i++) {
        if(i==n) a=0;
        else cin >> a;
           
        if(a==0) {
            ans += sum/2;
            sum = 0;
        }
        else sum += a;
    }

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


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

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

int H,W;
string A[10];
const ll mo=998244353;

ll comb(ll N_, ll C_) {
	const int NUM_=400001;
	static ll fact[NUM_+1],factr[NUM_+1],inv[NUM_+1];
	if (fact[0]==0) {
		inv[1]=fact[0]=factr[0]=1;
		for (int i=2;i<=NUM_;++i) inv[i] = inv[mo % i] * (mo - mo / i) % mo;
		for (int i=1;i<=NUM_;++i) fact[i]=fact[i-1]*i%mo, factr[i]=factr[i-1]*inv[i]%mo;
	}
	if(C_<0 || C_>N_) return 0;
	return factr[C_]*fact[N_]%mo*factr[N_-C_]%mo;
}

int R[10];
int C[10];
ll memo_all[12][12];
ll memo[12][12];

ll hoge_all(int H,int W) {
	if(memo_all[H][W]>=0) return memo_all[H][W];
	if(H==0 || W==0) return 1;
	
	ll dp[11][11][2]={};
	int y,x;
	for(y=1;y<=H;y++) dp[y][0][0]=comb(H,y);
	for(x=1;x<=W;x++) dp[0][x][1]=comb(W,x);
	
	FOR(y,H) FOR(x,W) {
		int y2,x2;
		for(y2=y+1;y2<=H;y2++) dp[y2][x][0]+=dp[y][x][1]*comb(H-y,y2-y)%mo;
		for(x2=x+1;x2<=W;x2++) dp[y][x2][1]+=dp[y][x][0]*comb(W-x,x2-x)%mo;
	}
	
	ll ret=0;
	FOR(x,W) ret+=dp[H][x][0];
	FOR(y,H) ret+=dp[y][W][1];
	return memo_all[H][W]=ret%mo;
	
}

ll hoge(int H,int W) {
	if(memo[H][W]>=0) return memo[H][W];
	ll ret=0;
	int x,y;
	FOR(y,H+1) FOR(x,W+1) ret+=comb(H,y)*comb(W,x)%mo*hoge_all(y,x)%mo*hoge_all(H-y,W-x)%mo;
	return memo[H][W]=ret%mo;
}

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>H>>W;
	FOR(y,H) {
		cin>>A[y];
		FOR(x,W) if(A[y][x]=='#') {
			R[y] |= 1<<x;
			C[x] |= 1<<y;
		}
	}
	MINUS(memo);
	MINUS(memo_all);
	
	int rm,cm;
	ll ret=hoge_all(H,W);
	FOR(rm,1<<H) FOR(cm,1<<W) if(rm&&cm) {
		int did=0;
		FOR(y,H) if((rm&(1<<y)) && (((R[y]&cm)==0)||(~R[y]&cm)==0)) did = 1;
		FOR(x,W) if((cm&(1<<x)) && (((C[x]&rm)==0)||(~C[x]&rm)==0)) did = 1;
		if(did==0) ret+=hoge(H-__builtin_popcount(rm),W-__builtin_popcount(cm));
	}
	cout<<ret%mo<<endl;
}


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


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

using namespace std;

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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,n) for(int i=1;i<=(int)(n);i++)
#define rep3(i,n) for(int i=0;i<=(int)(n);i++)
#define REP(i,m,n) for(int i=m;i<(int)(n);i++)
#define repll(i,n) for(ll i=0;i<(ll)(n);i++)
#define repll2(i,n) for(ll i=1;i<=(ll)(n);i++)
#define REPLL(i,m,n) for(ll i=m;i<(ll)(n);i++)
#define INF (int)1e9
#define LINF (ll)4e18
#define MOD (ll)(1e9)+7
#define MP make_pair
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define PI 3.1415926535898
#define NP(v) next_permutation(v.begin(),v.end())

//------------------------------------------------------

int main() {
    int n, m, k;
    cin >> n >> m >> k;

    bool can = false;

    rep3(i, n) {

        rep3(j, m) {
            if (i * m + j * n - 2 * i * j == k) can = true;
        }
    }

    Yes(can);

    return 0;
}

Measured memory_bytes: 256
use std::str::FromStr;
use std::io::Read;
use std::ops::Sub;
use std::convert::From;

pub trait AsZeroOrigin {
    fn as_zero_origin(self) -> Self;
}

pub trait AsZeroOriginWithMatrix {
    fn as_zero_origin(self) -> Self;
}

impl<T> AsZeroOrigin for Vec<T>
where
    T: Sub<T, Output = T> + From<u8>,
{
    fn as_zero_origin(self) -> Self {
        self.into_iter().map(|i| i - T::from(1)).collect()
    }
}

impl<T> AsZeroOriginWithMatrix for Vec<Vec<T>>
where
    T: Sub<T, Output = T> + From<u8>,
{
    fn as_zero_origin(self) -> Self {
        self.into_iter()
            .map(|v| v.into_iter().map(|i| i - T::from(1)).collect())
            .collect()
    }
}

pub trait Convert<T>
where
    T: FromStr,
{
    fn read_one(&mut self) -> T;
    fn to_vec(&mut self, n: usize) -> Vec<T>;
    fn to_matrix(&mut self, n: usize, m: usize) -> Vec<Vec<T>>;

    fn to_tuples<U>(&mut self, n: usize) -> Vec<(T, U)>
    where
        U: FromStr;
}

impl<'a, T> Convert<T> for ::std::str::SplitWhitespace<'a>
where
    T: FromStr,
{
    fn read_one(&mut self) -> T {
        let word = self.next().unwrap();
        word.parse().ok().unwrap()
    }

    fn to_vec(&mut self, n: usize) -> Vec<T> {
        (0..n)
            .map(|_| self.next().unwrap().parse().ok().unwrap())
            .collect::<Vec<_>>()
    }

    fn to_matrix(&mut self, n: usize, m: usize) -> Vec<Vec<T>> {
        (0..n).map(|_| self.to_vec(m)).collect::<Vec<_>>()
    }

    fn to_tuples<U>(&mut self, n: usize) -> Vec<(T, U)>
    where
        U: FromStr,
    {
        (0..n)
            .map(|_| {
                let a = self.next().unwrap().parse().ok().unwrap();
                let b = self.next().unwrap().parse().ok().unwrap();
                (a, b)
            })
            .collect::<Vec<_>>()
    }
}

pub fn read_stdin() -> String {
    let mut s = String::new();
    ::std::io::stdin().read_to_string(&mut s).unwrap();
    s
}

fn evaluate(v: &Vec<Vec<usize>>, n: usize) -> u64 {
    let mut all = 0..n;
    for range in v {
        if all.start < range[0] {
            all.start = range[0];
        }
        if all.end > range[1] + 1 {
            all.end = range[1] + 1;
        }
    }

    all.len() as u64
}

fn main() {
    let source = read_stdin();
    let mut iter = source.split_whitespace();
    let n: usize = iter.read_one();
    let m: usize = iter.read_one();
    let ranges: Vec<Vec<usize>> = iter.to_matrix(m, 2).as_zero_origin();

    println!("{}", evaluate(&ranges, n));
}


Measured memory_bytes: 14588
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

prefix_A = [0] * (N + 1)
for i, a in enumerate(A, 1):
    prefix_A[i] = prefix_A[i - 1] + a
prefix_B = [0] * (M + 1)
for j, b in enumerate(B, 1):
    prefix_B[j] = prefix_B[j - 1] + b


res = 0
for i in range(N + 1):
    cur = prefix_A[i]
    if cur == K:
        res = max(i, res)
    elif cur < K:
        left = 0
        right = M + 1
        while right - left > 1:
            mid = (left + right) // 2
            if cur + prefix_B[mid] <= K:
                left = mid
            else:
                right = mid
        res = max(res, i + left)


print(res)

Measured memory_bytes: 46904
package main

import (
	"fmt"
)

func main() {
	var n, a, b, c, d int
	fmt.Scan(&n)
	fmt.Scan(&a)
	fmt.Scan(&b)
	fmt.Scan(&c)
	fmt.Scan(&d)
	var s string
	fmt.Scan(&s)

	blocked := make(map[int]bool)
	for i := 0; i < n; i++ {
		if s[i] == '#' {
			blocked[i+1] = true
		} else {
			blocked[i+1] = false
		}
	}

	if b < c && c < d {
		prevBlocked := false
		for i := b + 1; i < d; i++ {
			if prevBlocked && blocked[i] {
				fmt.Println("No")
				return
			} else if blocked[i] {
				prevBlocked = true
			} else {
				prevBlocked = false
			}
		}
		prevBlocked = false
		for i := a + 1; i < c; i++ {
			if prevBlocked && blocked[i] {
				fmt.Println("No")
				return
			} else if blocked[i] {
				prevBlocked = true
			} else {
				prevBlocked = false
			}
		}
		fmt.Println("Yes")
	} else if c < b && b < d {
		prevBlocked := false
		for i := b + 1; i < d; i++ {
			if prevBlocked && blocked[i] {
				fmt.Println("No")
				return
			} else if blocked[i] {
				prevBlocked = true
			} else {
				prevBlocked = false
			}
		}
		prevBlocked = false
		for i := a + 1; i < c; i++ {
			if prevBlocked && blocked[i] {
				fmt.Println("No")
				return
			} else if blocked[i] {
				prevBlocked = true
			} else {
				prevBlocked = false
			}
		}
		fmt.Println("Yes")
	} else {
		passable := false
		for i := b - 1; i < d; i++ {
			if !blocked[i] && !blocked[i+1] && !blocked[i+2] {
				passable = true
				break
			}
		}
		if !passable {
			fmt.Println("No")
			return
		}
		prevBlocked := false
		for i := b + 1; i < d; i++ {
			if prevBlocked && blocked[i] {
				fmt.Println("No")
				return
			} else if blocked[i] {
				prevBlocked = true
			} else {
				prevBlocked = false
			}
		}
		prevBlocked = false
		for i := a + 1; i < c; i++ {
			if prevBlocked && blocked[i] {
				fmt.Println("No")
				return
			} else if blocked[i] {
				prevBlocked = true
			} else {
				prevBlocked = false
			}
		}
		fmt.Println("Yes")
	}
}


Measured memory_bytes: 8704
#include <iostream>

using namespace std;

template <typename T, typename U>
T max(T l, U r)
{
	return (l < r) ? r : l;
}

int main()
{
	int64_t K, A, B;
	cin >> K >> A >> B;
	if (A + 2 >= B || K < (A + 1))
	{
		cout << K + 1;
	}
	else {
		int64_t n = (K - (A + 1)) / 2;
		cout << B + n * (B - A) + (K - (A + 1)) % 2;
	}
}

Measured memory_bytes: 256
h, w, a, b = map(int, input().split())

MOD = 10 ** 9 + 7
f = [1] * 300005
for i in range(2, 300005):
    f[i] = (f[i - 1] * i) % MOD

def comb(k, n):
    if n < k:
        return 0
    if k == 0 or n == k:
        return 1
    return (f[n] * pow(f[k], MOD - 2, MOD) * pow(f[n - k], MOD - 2, MOD)) % MOD

ans = 0
for i in range(h - a):
    ans += comb(i, i + b - 1) * comb(w - b - 1, w + h - 2 - i - b) % MOD
    ans %= MOD
print(ans)



Measured memory_bytes: 14836