akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<cctype>
#include <fstream>
#include <time.h>
#include <iterator>




#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define m0(x) memset(x,0,sizeof(x))
#define print(x) cout<<x<<endl;
#define pe(x) cout<<x<<" ";
#define lb(v,n) lower_bound(v.begin(), v.end(), n);
#define ub(v,n) upper_bound(v.begin(), v.end(), n);
#define int long long
#define all(x) (x).begin(), (x).end()
using namespace std;
int MOD = (ll)1000000000 + 7;
const ll INF = 1e17;
const double pi = acos(-1);
const double EPS = 1e-10;
typedef pair<int, int>P;

set<int>st;
int f(int n) {
	if (n % 2 == 0) {
		return n / 2;
	}
	else return 3 * n + 1;
}
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N; cin >> N;
	int pos = N;
	st.insert(N);
	int cnt = 1;
	while (true) {
		pos = f(pos);
		cnt++;
		if (st.find(pos) != st.end()) {
			print(cnt);
			return 0;
		}
		st.insert(pos);
	}
}

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

using namespace std;

void solve(const vector<int>& a, int L){
    for(int i=1;i<a.size();i++){
        if(a[i-1]+a[i] < L) continue;
        cout << "Possible" << endl;
        for(int j=1;j<i;j++) cout << j << endl;
        for(int j=a.size()-1;j>=i;j--) cout << j << endl;
        return;
    }
    cout << "Impossible" << endl;
}

int main(){
    int N, L;
    while(cin >> N >> L){
        vector<int> a(N);
        for(auto& t : a) cin >> t;
        solve(a, L);
    }
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

const int N = 200000;
vector<int> G[N];

int solve()
{
    int n,m,k;
    scanf(" %d %d %d", &n, &m, &k);

    vector<int> q(k),x(k),y(k);
    rep(i,k) scanf(" %d %d %d", &q[i], &x[i], &y[i]);

    int l=0,r=k+1;
    while(r-l>1)
    {
        rep(i,n+m) G[i].clear();

        bool ok = true;
        int mid = (l+r)/2;
        rep(i,mid)
        {
            if(q[i]==1)
            {
                int a=x[i]-1, b=y[i]-1;
                G[a].pb(b);
                G[b].pb(a);
            }
            else
            {
                int a=x[i]-1, club=y[i]-1+n;
                G[a].pb(club);
                G[club].pb(a);
            }
        }

        vector<bool> vis(n+m);
        rep(i,n)if(!vis[i])
        {
            set<int> club;
            vis[i] = true;
            queue<int> que;
            que.push(i);
            while(!que.empty())
            {
                int v = que.front();
                que.pop();
                for(int e:G[v])
                {
                    if(!vis[e])
                    {
                        vis[e]=true;
                        que.push(e);
                        if(e>=n) club.insert(e);
                    }
                }
            }

            if(club.size()>1)
            {
                ok=false;
                break;
            }
        }

        if(ok) l=mid;
        else r=mid;
    }

    if(r==k+1) r=0;
    return r;
}

int main()
{
    printf("%d\n", solve());
    return 0;
}

Measured memory_bytes: 14316
#include<iostream>

using namespace std;

int main()
{
	int d,s_d;
	int fx;
	
	for(;cin >> d;)
	{
		fx=0;
		
		for(s_d=d;d<600;d+=s_d)
			fx+=d*d*s_d;
		
		cout << fx << endl;
	}
}

Measured memory_bytes: 0
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}
 
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};
 
    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}
 
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };
 
    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };
 
    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };
 
    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };
 
    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}
 
//
// # Examples
//
// # integers
// input! { n: usize, m: usize, ... }
//
// # array
// input! { n: usize, v: [u64; n], }
//
// # matrix
// input! { n: usize, m: usize, mat: [[]] }
//
// # string
// input! { s: chars }
//
// 3 4
// ####
// #..#
// .#.#
//
// input!{
//     h: usize,
//     w: usize,
//     board: [chars; h],
// }
 
// https://practice.contest.atcoder.jp/tasks/practice_1

fn main() {
    input! { n: usize, nums: [i64;5] }
    let mut min = std::i64::MAX;
    for e in nums.iter() {
        if min > *e {
            min=*e;
        }
    }
    let min :usize = min as usize;
    let mut stay = n/min;
    if n%min > 0 { stay += 1; }
    println!("{}", stay + 4);
}

Measured memory_bytes: 4352
#include <iostream>
#include <cstring>
#include <algorithm>

char s1[1000], s2[1000];
int dp[1001][1001];

int main()
{
	std::cin >> s1 >> s2;

	int s1_len = std::strlen(s1);
	int s2_len = std::strlen(s2);

	for (int i = 0; i < 1001; ++i)
	{
		dp[0][i] = i;
		dp[i][0] = i;
	}

	for (int i = 1; i <= s1_len; ++i)
	{
		for (int j = 1; j <= s2_len; ++j)
		{
			if (s1[i - 1] == s2[j - 1])
			{
				dp[i][j] = dp[i - 1][j - 1];
			}
			else
			{
				dp[i][j] = std::min({dp[i - 1][j] + 1, dp[i][j - 1] + 1, dp[i - 1][j - 1] + 1});
			}
		}
	}

	std::cout << dp[s1_len][s2_len] << std::endl;
}


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

using namespace std;
typedef long long ll;

const int INF = 2e9;
template <class T> void chmin(T &a, T b) { if (a > b) a = b; }

const int MN = 1010;
const int MM = 5010;
vector<int> g[MN];
int n;
int x[MN];
int dp[MM], ndp[MM];
int mw[MN];

void imp() {
    cout << "IMPOSSIBLE\n";
    exit(0);
}

void dfs(int v, int p) {
    for (int i = 0; i < int(g[v].size()); i++) {
        int u = g[v][i];
        if (u == p) continue;
        dfs(u, v);
    }

    fill(dp, dp + x[v] + 1, INF);
    dp[0] = 0;
    for (int i = 0; i < int(g[v].size()); i++) {
        int u = g[v][i];
        if (u == p) continue;

        for (int j = 0; j <= x[v]; j++) {
            ndp[j] = INF;
            if (j - x[u] >= 0) {
                chmin(ndp[j], dp[j-x[u]] + mw[u]);
            }
            if (j - mw[u] >= 0) {
                chmin(ndp[j], dp[j-mw[u]] + x[u]);
            }
        }
        copy(ndp, ndp + x[v] + 1, dp);
    }
    if (int(g[v].size()) == 0) {
        mw[v] = 0;
    } else {
        mw[v] = *min_element(dp, dp + x[v] + 1);
    }
    if (mw[v] == INF) imp();
}

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

    cin >> n;
    for (int i = 1; i < n; i++) {
        int p;
        cin >> p; p--;
        g[p].push_back(i);
    }
    for (int i = 0; i < n; i++) {
        cin >> x[i];
    }

    dfs(0, -1);
    cout << "POSSIBLE\n";
    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <cmath>
#define P pair<double,string>
using namespace std;

int main(){
  int n;
  vector<P> v;
  int pp,a,b,c,d,e,f,s,m;
  P p;

  while( cin >> n && n ){
    v.clear();
    for( int i=0;i<n;i++ ){
      cin >> p.second >> pp >> a >> b >> c >> d >> e >> f >> s >> m;

      int g = - ( f*m*s - pp );
      int t = a+b+c+ m*(d+e);
      p.first = (double)g / t;

      v.push_back( p );
    }
    sort( v.begin(),v.end() );
    for( unsigned int i=0;i<v.size();i++ ){
      cout << v[i].second;
      cout <<  endl;
    }
    cout << "#" << endl;
  }

  return 0;
}

Measured memory_bytes: 0
n = int(input())
S = dict()
for i in range(n):
    word = input()
    if word not in S:
        S[word] = 1
    else:
        S[word] += 1
S = sorted(S.items(), key=lambda x:x[1], reverse=True)

max_v = S[0][1]
ans = []
for k,v in S:
    if v == max_v:
        ans.append(k)
    else:
        break
ans = sorted(ans)
for i in ans:
    print(i)

Measured memory_bytes: 114520
import sys
import heapq
from operator import itemgetter
from collections import deque, defaultdict
from bisect import bisect_left, bisect_right
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
MOD = 10**9 + 7

def sol():
    N = int(input())
    A = list(map(int, input().split()))

    S = sum(A)

    if S % (N * (N + 1) // 2) != 0:
        print('NO')
        return

    K = S // (N * (N + 1) // 2)
    for diff in [A[i] - A[i - 1] for i in range(N)]:
        if K - diff < 0 or (K - diff) % N != 0:
            print('NO')
            return

    print('YES')


sol()

Measured memory_bytes: 14632
#include <bits/stdc++.h>
using namespace std;
int main()
{
	long long sum=0;
	long long N;
	cin>>N;
	long long T=N;
	while(N){sum+=N%10; N/=10;}
	printf("%s",(T%sum==0)?"Yes":"No");
	return 0;
}

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

using namespace std;

typedef long long ll;

const ll MOD = 1000000007;
const int MAXW = 50, MAXH = 50;

const int di[4] = {-1, 0, 1, 0};
const int dj[4] = {0, 1, 0, -1};

int w, h;
string a[MAXH];
bool visited[MAXH][MAXW];
bool iswhite, isblack;
int cnt = 0;
int answ = 0, ansb = 0;

void dfs(int i, int j){
    visited[i][j] = true;
    cnt++;
    for(int k=0;k<4;k++){
        if(i + di[k] < 0 || i + di[k] >= h || j + dj[k] < 0 || j + dj[k] >= w) continue;
        if(a[i + di[k]][j + dj[k]] == 'W') iswhite = true;
        else if(a[i + di[k]][j + dj[k]] == 'B') isblack = true;
        else if(!visited[i + di[k]][j + dj[k]]) dfs(i + di[k], j + dj[k]);
    }
}

void solve(int i, int j){
    iswhite = false, isblack = false;
    cnt = 0;

    dfs(i, j);

    if(iswhite && !isblack){
        answ += cnt;
    }else if(isblack && !iswhite){
        ansb += cnt;
    }
}


int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    while(1){
        cin >> w >> h;
        if(w == 0 && h == 0) break;
        for(int i=0;i<h;i++){
            cin >> a[i];
        }
        // initialization
        memset(visited, 0, sizeof visited);
        ansb = 0, answ = 0;
        for(int i=0;i<h;i++){
            for(int j=0;j<w;j++){
                if(a[i][j] == '.' && !visited[i][j]){
                    solve(i, j);
                }
            }
        }
        cout << ansb << " " << answ << endl;
    }
}


Measured memory_bytes: 3228
#include<stdio.h>

static const int N = 1000;

void trace(int A[], int n){
  int i;
  for ( i = 1; i <= n; i++ ){
    if ( i > 1 ) printf(" ");
    printf("%d", A[i]);
  }
  printf("\n");
}

int main(){
  int n, i, j;
  int A[N+1];
  scanf("%d", &n);

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

for (i = 2; i <= n; i++)
{
     int t = A[i];
     int x = i - 1;
     while(x > 0 && A[x] > t)
     {
          A[x + 1] = A[x];
          x--;
     }
     A[x + 1] = t;
     trace(A, n);
}


  return 0;
}

Measured memory_bytes: 608
L = list(map(int,list(input())))
for i in range(8):
    Str = '{:03b}'.format(i)
    cnt = L[0]
    for j in range(3):
        if Str[j] == '0':
            cnt -= L[j+1]
        else:
            cnt += L[j+1]
    if cnt == 7:
        ans = str(L[0])
        for j in range(3):
            if Str[j] == '0':
                ans += '-'
            else:
                ans += '+'
            ans += str(L[j+1])
        ans += '=7'
        print(ans)
        break

Measured memory_bytes: 3064
// C - Boxes and Candies

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// const int INF = 2147483647;
// const ll INF = 9223372036854775807;
// const int MOD = 1e9 + 7;

int main() {
	int N, x;
	cin >> N >> x;

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


	ll ans = 0;
	for (int i=0; i<N-1; i++) {
		int y = max(a[i] + a[i+1] - x, 0); // 減らさなければいけない数
		if (a[i+1] >= y) {
			a[i+1] -= y;
		} else {
			a[i+1] = 0;
		}
		ans += y;
	}

	cout << ans << endl;

	return 0;
}

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

N = int(input().strip())
S_list = [input().strip() for _ in range(N)]
#-----

S_dic = {}

for s in S_list:
    S_dic.setdefault(s, 0)
    S_dic[s] += 1

S_dic_sorted = sorted(S_dic.items(), key = lambda x: x[1], reverse=True)
max_cnt_S = S_dic_sorted[0][1]
ans = []

for k,v in S_dic_sorted:
    if v == max_cnt_S:
        ans.append(k)

ans.sort()

for word in ans:
    print(word)


Measured memory_bytes: 47244
#include <algorithm>
#include <iostream>
using namespace std;
typedef long long ll;
int main(){
	int n,i;
	cin>>n;
	double y[n],ans;
	for(i=0;i<n;i++)cin>>y[i];
	sort(y,y+n);
	ans=(y[0]+y[1])/2;
	for(i=2;i<n;i++)ans=(y[i]+ans)/2;
	cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <map>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <set>
#include <vector>
#include <queue>
#include <list>
#include <numeric>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <math.h>
#include <stack>
#include <climits>
#include <bitset>
#include <utility>


using namespace std;
typedef long long ll;

//最小公倍数
ll gcd(ll x, ll y) {
  ll tmp = 0;
  if (x < y){
    tmp=x;
    x=y;
    y=tmp;
  }
  while (y > 0) {
    ll r = x % y;
    x = y;
    y = r;
  }
  return x;
}

//最大公倍数
ll lcm(ll x,ll y){
  return x/gcd(x,y)*y;
}

//階乗
ll kaijo(ll k){
    ll sum = 1;
    for (ll i = 1; i <= k; ++i)
    {
        sum *= i;
        sum%=1000000000+7;
    }
    return sum;
}

//for(int i = ; i < ; i++){}

ll lmax(ll s,ll t){
  if(s>t){
    return s;
  }
  else{
    return t;
  }
}

ll lmin(ll s,ll t){
  if(s<t){
    return s;
  }
  else{
    return t;
  }
}
// ここから開始

int main(){
  int a,b;
  char op;
  cin>>a>>op>>b;
  if(op=='+')cout<<a+b<<endl;
  else cout<<a-b<<endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long[] a = new long[n];
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
        }
        long[] b = new long[n];
        for (int i = 0; i < n; i++) {
            b[i] = sc.nextInt();
        }
        long[] c = new long[n];
        for (int i = 0; i < n; i++) {
            c[i] = sc.nextInt();
        }
        Arrays.sort(a);
        Arrays.sort(b);
        Arrays.sort(c);
        System.out.println(solve(a, b, c));
    }

    private static long solve(long[] a, long[] b, long[] c) {
        int n = a.length;
        long[] bmemo = new long[n];
        int cidx = 0;
        for (int j = 0; j < n; j++) {
            for (int k = cidx; k < n; k++) {
                if (b[j] >= c[k]) {
                    cidx++;
                } else {
                    bmemo[j] = n - k;
                    break;
                }
            }
        }
        for (int i = n - 2; i >= 0; i--) {
            bmemo[i] += bmemo[i + 1];
        }
        long sum = 0;
        int bidx = 0;
        for (int i = 0; i < n; i++) {
            for (int j = bidx; j < n; j++) {
                if (a[i] >= b[j]) {
                    bidx++;
                } else {
                    sum += bmemo[j];
                    break;
                }
            }
        }
        return sum;
    }
}


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

const ll mod = pow(10, 9) + 7;

int main()
{
  ll n, k;
  cin >> n >> k;
  ll res = 0;
  for (ll i = k; i <= n + 1; i++) {
    res += (i * (n - i + 1) + 1) % mod;
  }
  cout << res % mod << endl;

  return 0;
}


Measured memory_bytes: 3584
# https://atcoder.jp/contests/abc067/tasks/arc078_a

n = int(input())
nums = [int(i) for i in input().split()]

for i in range(n - 1):
    nums[i + 1] += nums[i]

ans = float('inf')
for i in range(n - 1):
    x = nums[i]
    y = nums[-1] - nums[i]
    ans = min(ans, abs(x - y))
print(ans)


Measured memory_bytes: 100544
#include <stdio.h>

int main(void){
	int N;
	scanf("%d",&N);
	int ans=0;
	if(N>=105) ans++;
	if(N>=135) ans++;
	if(N>=165) ans++;
	if(N>=189) ans++;
	if(N>=195) ans++;
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 128
void main(){
  import std.stdio, std.string, std.conv, std.algorithm;

  int n; rd(n);
  auto c=new long[](n-1), s=new long[](n-1), f=new long[](n-1);
  foreach(i; 0..(n-1)) rd(c[i], s[i], f[i]);

  auto best=new long[](n);
  long inf=1_000_000_000_000_000_000;
  fill(best, inf);
  auto tot=new long[](n);
  for(auto i=0, t=inf; i+1<n; t=best[i]+c[i], i++){
    best[i]=min(t, s[i]);
    auto cur=best[i];
    for(auto j=i; j+1<n; j++){
      auto k=((cur-s[j])+f[j]-1)/f[j];
      k=max(0, k);
      auto st=s[j]+k*f[j];
      cur=st+c[j];
    }
    tot[i]=cur;
  }
  writefln("%(%s\n%)", tot);
}

void rd(T...)(ref T x){
  import std.stdio, std.string, std.conv;
  auto l=readln.split;
  assert(l.length==x.length);
  foreach(i, ref e; x){
    e=l[i].to!(typeof(e));
  }
}
void wr(T...)(T x){
  import std.stdio;
  foreach(e; x) write(e, " ");
  writeln();
}

Measured memory_bytes: 380
#include <iostream>
#include <cstdint>

using namespace std;

int main() {
  int64_t A, B, K;
  
  cin >> A >> B >> K;
  
  int64_t diff_A = A - K;
  if (diff_A < 0) {
    B -= (K - A);
    if (B < 0) B = 0;
    cout << "0 " << B << endl;
  } else {
    cout << diff_A << " " << B << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    
    int N;
    cin >> N;

    map<string, int>m;

    REP(i, N) {
        string s;
        cin >> s;
        m[s] += 1;
    }

    int M;
    cin >> M;
    REP(i, M) {
        string s;
        cin >> s;
        m[s] -= 1;
    }

    int ans = 0;
    for (auto p: m) {
        if (p.se > ans) ans = p.se;
    }

    cout << ans << endl;
    
}


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

void solve(unsigned long long H, unsigned long long W)
{
    unsigned long long hodd = (H - 1) / 2 + 1, heven = H - hodd;
    unsigned long long wodd = (W - 1) / 2 + 1, weven = W - wodd;
    if (H == 1 || W == 1)
    {
        cout << 1 << endl;
    }
    else
    {
        cout << hodd * wodd + heven * weven << 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()
{
    unsigned long long H, W;
    cin >> H >> W;
    solve(H, W);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int A,B,C;      //A：500円 B：100円 C：50円
    int X=0;        //合計金額
    int count=0;      //通り数
  	int N=0;

    cin >> A >> B >> C;
    cin >> X;
    
    for(int i=0; i<=A; i++){     //500円玉ループ
         for(int j=0; j<=B; j++){      //100円玉ループ
              for(int k=0; k<=C; k++){       //50円玉ループ
                N = 500*i + 100*j + 50*k;
                //cout << N << endl;
                if(N == X){
                   count++;
                }
              }                
         }
    }
    
    cout << count << endl;      //通り数出力
    return 0;
}

Measured memory_bytes: 256
class Dice(object):
    def __init__(self, faces):
        self.top = faces[0]
        self.front = faces[1]
        self.right = faces[2]
        self.left = faces[3]
        self.back = faces[4]
        self.bottom = faces[5]

    def rotate(self, command):
        pre_top = self.top
        if command == "N":
            self.top = self.front
            self.front = self.bottom
            self.bottom = self.back
            self.back = pre_top
        elif command == "E":
            self.top = self.left
            self.left = self.bottom
            self.bottom = self.right
            self.right = pre_top
        elif command == "W":
            self.top = self.right
            self.right = self.bottom
            self.bottom = self.left
            self.left = pre_top
        elif command == "S":
            self.top = self.back
            self.back = self.bottom
            self.bottom = self.front
            self.front = pre_top
        elif command == "R":
            pre_front = self.front
            self.front = self.left
            self.left = self.back
            self.back = self.right
            self.right = pre_front


def main() -> None:
    dice = [Dice(list(map(int, input().split()))) for _ in range(int(input()))]

    for a in range(len(dice)):
        for b in range(a):
            dice_x = dice[a]
            dice_y = dice[b]

            for i in range(4):
                dice_x.rotate("N")
                for j in range(4):
                    dice_x.rotate("E")
                    for k in range(4):
                        dice_x.rotate("R")

                        if dice_x.top != dice_y.top:
                            pass
                        elif dice_x.bottom != dice_y.bottom:
                            pass
                        elif dice_x.left != dice_y.left:
                            pass
                        elif dice_x.right != dice_y.right:
                            pass
                        elif dice_x.front != dice_y.front:
                            pass
                        elif dice_x.back != dice_y.back:
                            pass
                        else:
                            print("No")
                            return
    print("Yes")


if __name__ == "__main__":
    main()



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

int main() {
  char c;
  cin >> c;
  if(c == 'a' || c == 'i' || c == 'u' || c == 'e' || c == 'o'){
    cout << "vowel" << endl;
  }
  else{
    cout << "consonant" << endl;
  }
}


Measured memory_bytes: 256
import java.util.Scanner;

class Main{

    static int bubbleSort(int[] a, int n){
        boolean flag = true;
        int cnt = 0;
        while(flag){
            flag = false;
            for(int j = n - 1; j >= 1; j--){
                if(a[j-1] > a[j]){
                    int tmp = a[j];
                    a[j] = a[j-1];
                    a[j-1] = tmp;

                    flag = true;
                    cnt++;
                }
            }
        }
        return cnt;
    }

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

        int n = scn.nextInt();
        int[] a = new int[n];
        for(int i = 0; i < n; i++){
            a[i] = scn.nextInt();
        }

        int cnt = bubbleSort(a, n);

        for(int i = 0; i < n-1; i++){
            System.out.print(a[i] + " ");
        }
        System.out.println(a[n-1]);
        System.out.println(cnt);
    }
}



Measured memory_bytes: 26360
import sys,bisect,string,math,time,functools,random,fractions
from heapq import heappush,heappop,heapify
from collections import deque,defaultdict,Counter
from itertools import permutations,combinations,groupby
rep=range;R=range
def Golf():n,*t=map(int,open(0).read().split())
def I():return int(input())
def S_():return input()
def IS():return input().split()
def LS():return [i for i in input().split()]
def MI():return map(int,input().split())
def LI():return [int(i) for i in input().split()]
def LI_():return [int(i)-1 for i in input().split()]
def NI(n):return [int(input()) for i in range(n)]
def NI_(n):return [int(input())-1 for i in range(n)]
def StoLI():return [ord(i)-97 for i in input()]
def ItoS(n):return chr(n+97)
def LtoS(ls):return ''.join([chr(i+97) for i in ls])
def RA():return map(int,open(0).read().split())
def GI(V,E,ls=None,Directed=False,index=1):
    org_inp=[];g=[[] for i in range(V)]
    FromStdin=True if ls==None else False
    for i in range(E):
        if FromStdin:
            inp=LI()
            org_inp.append(inp)
        else:
            inp=ls[i]
        if len(inp)==2:
            a,b=inp;c=1
        else:
            a,b,c=inp
        if index==1:a-=1;b-=1
        aa=(a,c);bb=(b,c);g[a].append(bb)
        if not Directed:g[b].append(aa)
    return g,org_inp
def GGI(h,w,search=None,replacement_of_found='.',mp_def={'#':1,'.':0},boundary=1):
    #h,w,g,sg=GGI(h,w,search=['S','G'],replacement_of_found='.',mp_def={'#':1,'.':0},boundary=1) # sample usage
    mp=[boundary]*(w+2);found={}
    for i in R(h):
        s=input()
        for char in search:
            if char in s:
                found[char]=((i+1)*(w+2)+s.index(char)+1)
                mp_def[char]=mp_def[replacement_of_found]
        mp+=[boundary]+[mp_def[j] for j in s]+[boundary]
    mp+=[boundary]*(w+2)
    return h+2,w+2,mp,found
def TI(n):return GI(n,n-1)
def accum(ls):
    rt=[0]
    for i in ls:rt+=[rt[-1]+i]
    return rt
def bit_combination(n,base=2):
    rt=[]
    for tb in R(base**n):s=[tb//(base**bt)%base for bt in R(n)];rt+=[s]
    return rt
def gcd(x,y):
    if y==0:return x
    if x%y==0:return y
    while x%y!=0:x,y=y,x%y
    return y
def YN(x):print(['NO','YES'][x])
def Yn(x):print(['No','Yes'][x])
def show(*inp,end='\n'):
    if show_flg:print(*inp,end=end)

mo=10**9+7
inf=float('inf')
FourNb=[(-1,0),(1,0),(0,1),(0,-1)];EightNb=[(-1,0),(1,0),(0,1),(0,-1),(1,1),(-1,-1),(1,-1),(-1,1)];compas=dict(zip('WENS',FourNb));cursol=dict(zip('LRUD',FourNb))
l_alp=string.ascii_lowercase
#sys.setrecursionlimit(10**7)
read=sys.stdin.buffer.read;readline=sys.stdin.buffer.readline;input=lambda:sys.stdin.readline().rstrip()

########################################################################################################################################################################

show_flg=False
show_flg=True

ans=0

n=I()

ans=10-n//200
print(ans)


Measured memory_bytes: 78280
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
typedef long double ld;
const ll INF = 1e+14;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second

ll f(int bit, int k) {
    if(bit & (1<<k)) return 1LL;
    return -1LL;
}

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

    int N, M; cin >> N >> M;
    ll x[1010], y[1010], z[1010];
    ll ans = 0;
    rep(i, N) cin >> x[i] >> y[i] >> z[i];

    for(int bit = 0; bit < (1<<3); bit++) {
        ll m[1010];
        ll maxi = 0;
        rep(i, N) m[i] = x[i] * f(bit, 0) + y[i] * f(bit, 1) + z[i] * f(bit, 2);
        sort(m, m + N, greater<ll>());
        rep(i, M) maxi += m[i];
        ans = max(ans, maxi);
    }

    cout << ans << "\n";   

    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <string>
#include <algorithm>
#include <iostream>
#include <string>
#include <map>
#include <set>
#include <functional>
#include <iostream>
#define INF 1000
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

struct edge{
	int to,cap,rev;
	edge(){}
	edge(int tt,int cc,int rr){
		to=tt;
		cap=cc;
		rev=rr;
	}
};

vector<edge> G[601];
int level[601];
int iter[601];
int data[601][601];

void add_edge(int from,int to,int cap){
	G[from].push_back(edge(to,cap,G[to].size()));
	G[to].push_back(edge(from,cap,G[from].size()-1));
	data[from][to]=G[from].size()-1;
	data[to][from]=G[to].size()-1;
}

void change_flow(int from,int to,int cap){
	if(cap==1){
		G[from][data[from][to]].cap=1;
		G[to][data[to][from]].cap=1;
	}else{
		G[from][data[from][to]].cap=0;
		G[to][data[to][from]].cap=0;
	}
}

int check_flow(int from,int to){
	return G[from][data[from][to]].cap;
}

void bfs(int s){
	memset(level,-1,sizeof(level));
	queue<int> que;
	level[s]=0;
	que.push(s);
	while(que.size()){
		int v=que.front();
		que.pop();
		for(int i=0;i<G[v].size();i++){
			edge &e=G[v][i];
			if(e.cap>0 && level[e.to]<0){
				level[e.to]=level[v]+1;
				que.push(e.to);
			}
		}
	}
}

int dfs(int v,int t,int f){
	if(v==t)return f;
	for(int &i=iter[v];i<G[v].size();i++){
		edge &e=G[v][i];
		if(e.cap>0 && level[v]<level[e.to]){
			int d=dfs(e.to,t,min(f,e.cap));
			if(d>0){
				e.cap-=d;
				G[e.to][e.rev].cap+=d;
				return d;
			}
		}
	}
	return 0;
}

int max_flow(int s,int t){
	int flow=0;
	while(1){
		bfs(s);
		if(level[t]<0)return flow;
		memset(iter,0,sizeof(iter));
		int f;
		while((f=dfs(s,t,INF))>0){
			flow+=f;
		}
	}
}

vector<int> vec;
bool used[601];

int back_dfs(int s,int t,int f){
	if(s==t)return f;
	used[s]=true;
	for(int i=0;i<G[s].size();i++){
		edge &e=G[s][i];
		if(!used[e.to] && e.cap>0){
			int d=back_dfs(e.to,t,min(f,e.cap));
			if(d>0){
				e.cap-=d;
				G[e.to][e.rev].cap+=d;
				return d;
			}
		}
	}
	return 0;
}

int n,m,q;

int main(void){
	scanf("%d%d%d",&n,&m,&q);
	memset(data,-1,sizeof(data));
	for(int i=0;i<m;i++){
		int f,t;
		scanf("%d%d",&f,&t);
		f--;
		t--;
		add_edge(f,t,1);
	}
	int res=max_flow(0,n-1);
	for(int i=0;i<q;i++){
		int t,a,b;
		scanf("%d%d%d",&t,&a,&b);
		a--;
		b--;
		if(t==1){
			if(data[a][b]==-1)add_edge(a,b,1);
			else{
				change_flow(a,b,1);
			}
		}else{
			memset(used,false,sizeof(used));
			int type=check_flow(a,b);
			change_flow(a,b,0);
			if(type==0){
				if(back_dfs(a,b,1)==1){
				}else{
					memset(used,false,sizeof(used));
					back_dfs(n-1,b,1);
					memset(used,false,sizeof(used));
					back_dfs(a,0,1);
					res--;
				}
			}else if(type==2){
				if(back_dfs(b,a,1)==1){
				}else{
					memset(used,false,sizeof(used));
					back_dfs(n-1,a,1);
					memset(used,false,sizeof(used));
					back_dfs(b,0,1);
					res--;
				}
			}
		}
		res+=max_flow(0,n-1);
		printf("%d\n",res);
	}
	return 0;
}

Measured memory_bytes: 5124
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define All(V) V.begin(), V.end()
typedef long long int ll;
typedef pair<int, int> P;
const ll MOD = 1e9+7, INF = 1e9;

int main()
{
  int n, m; cin >> n >> m;//m:重量
  vector<ll> weight(n), value(n);
  vector<vector<ll>> dp(n+1, vector<ll>(m+1));
  rep(i, n) cin >> weight[i] >> value[i];
  for(int i = 0; i < n; i++){
    for(int j = 0; j <= m; j++){
      if(j - weight[i] >= 0){
        dp[i+1][j] = max(dp[i+1][j], dp[i][j-weight[i]]+value[i]);
      }
      dp[i+1][j] = max(dp[i+1][j], dp[i][j]);
    }
  }
  cout << dp[n][m] << endl;
  system("pause");
}

Measured memory_bytes: 80256
#include<iostream>
using namespace std;
#include<vector>
#include<functional>
#include<limits>
template<typename T>
struct segtree{
	using F=function<T(T,T)>;
	const F calcfn,updatefn;
	int n;
	T defvalue;
	vector<T>dat;
	segtree(int n_=0,T defvalue_=numeric_limits<T>::max(),
		const F calcfn_=[](T a,T b){return a<b?a:b;},
		const F updatefn_=[](T a,T b){return b;}
	):defvalue(defvalue_),calcfn(calcfn_),updatefn(updatefn_)
	{
		n=1;
		while(n<n_)n<<=1;
		dat.assign(2*n-1,defvalue);
	}
	void copy(const vector<T>&v)
	{
		for(int i=0;i<v.size();i++)dat[i+n-1]=v[i];
		for(int i=n-2;i>=0;i--)dat[i]=calcfn(dat[i*2+1],dat[i*2+2]);
	}
	void update(int i,T a)
	{
		i+=n-1;
		dat[i]=updatefn(dat[i],a);
		while(i>0)
		{
			i=(i-1)/2;
			dat[i]=calcfn(dat[2*i+1],dat[2*i+2]);
		}
	}
	T query(int a,int b)//[a,b)
	{
		int L=(a<0?0:a>n?n:a)+n-1;
		int R=(b<0?0:b>n?n:b)+n-1;
		T lret=defvalue,rret=defvalue;
		for(;L<R;L>>=1,R>>=1)
		{
			if(!(L&1))lret=calcfn(lret,dat[L]);
			if(!(R&1))rret=calcfn(dat[--R],rret);
		}
		return calcfn(lret,rret);
	}
};
int N,K;
int A[3<<17];
main()
{
	cin>>N>>K;
	for(int i=0;i<N;i++)cin>>A[i];
	segtree<int>P(3<<17,0,[](int a,int b){return a<b?b:a;},[](int a,int b){return a<b?b:a;});
	for(int i=0;i<N;i++)
	{
		int u=P.query(A[i]-K,A[i]+K+1);
		P.update(A[i],u+1);
	}
	cout<<P.query(0,3<<17)<<endl;
}


Measured memory_bytes: 8536
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, 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
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
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

N = INT()
W = LIST()

S1 = W[0]
S2 = sum(W) - S1
diff = abs(S1-S2)

for T in range(1, N-1):
	S1 += W[T]
	S2 -= W[T]
	diff2 = abs(S1 - S2)
	diff = min(diff, diff2)

print(diff)

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

int main() {
  int k;
  cin >> k;
  
  queue<ll> q;
  for (int i = 1; i <= 9; i++) {
    q.push(i);
  }
  
  int count = 0;
  while (true) {
    count ++;
    if (count == k) {
      cout << q.front() << endl;
      break;
    }
    
    for (int i = -1; i <= 1; i++) {
      if (q.front() % 10 != 0 || i != -1) {
        if (q.front() % 10 != 9 || i != 1) {
          q.push(q.front() * 10 + (q.front() % 10) + i);
        }
      }
    }
    q.pop();
  }
  return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
using namespace std;

int main(){
    int n;
    cin >> n;
    vector<long long> lucas(100);
    lucas[0] = 2, lucas[1] = 1;
    for (int i = 2; i < 100; i++) {
        lucas[i] = lucas[i-1] + lucas[i-2];
    }
    cout << lucas[n] << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using ll = int_fast64_t;

const int MAX = 1e7;
const int MOD = 1e9+7;

ll fac[MAX], finv[MAX], inv[MAX];

void combinit(){
        fac[0] = fac[1] = finv[0] = finv[1] = inv[1] = 1;
        for(int i=2; i<MAX; i++){
                fac[i] = fac[i-1] * i % MOD;
                inv[i] = MOD - inv[MOD%i] * (MOD/i) % MOD;
                finv[i] = finv[i-1] * inv[i] % MOD;
        }
}

ll comb(int n, int k){
        if(n<k or n<0 or k<0) return 0;
        return fac[n] * (finv[k] * finv[n-k] % MOD) % MOD;
}

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

        if((x+y)%3!=0 or x*2<y or x>y*2){
                puts("0");
                return 0;
        }

        combinit();
        printf("%ld\n", comb((x+y)/3, (2*x-y)/3));
        return 0;
}

Measured memory_bytes: 234624
from collections import deque
N,M = map(int,input().split())
edge = [[]for i in range(N+M)]
for i in range(N):
    l = list(map(int,input().split()))[1:]
    for j in l:
        edge[i].append(N+j-1)
        edge[N+j-1].append(i)
A = [0]*(N+M)
A[0] = 1
queue = deque([0])
while queue != deque([]):
    p = queue.popleft()
    for i in edge[p]:
        if A[i] == 0:
            A[i] = 1
            queue.append(i)
if sum(A[:N]) == N:
    print("YES")
else:
    print("NO")

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



int main() {
    int n,m;
    cin >> n >> m;
    int a[n+1];
    long long sum=0;
    rep(i,n) {
        cin >> a[i];
        sum+=a[i];
        }
        //cout << sum << endl; 
int cnt=0;
    rep (i,n){
        //cout << a[i] << endl;
        if(a[i]>=((1.0/(4*m))*sum)) cnt ++;
        //cout << cnt << endl;
    }
if (cnt >=m) cout << "Yes" << endl;
else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <assert.h>
#include <queue>
#include <string.h>
#include <string>
#include <set>
#include <memory.h>
#include <functional>
#include <bitset>
using namespace std;
#define ll long long

const int N = 1e3+15;

int a[N];

void solve() {
    string s;
    cin>>s;
    int ret = (int)s.size();
    for(int i=0;i<(int)s.size()-1;++i) {
        if(s[i]!=s[i+1]) {
            ret = min(ret, max(i+1, (int)s.size() -i-1));
        }
    }
    cout<<ret<<endl;
}
int main() {
    //freopen("/Users/gotop/Documents/ps_practice/ps_practice/input.txt", "r", stdin);
    solve();
}


Measured memory_bytes: 512
<?php
 
fscanf(STDIN, '%d', $n);
$dict = array();
for ($i = 0; $i < $n; $i++) {
    $line = trim(fgets(STDIN));
    if ($line[0] === 'i') {
        $dict[substr($line, 7)] = 1;
    } else {
        echo empty($dict[substr($line, 5)]) ? 'no' : 'yes', PHP_EOL;
    }
}


Measured memory_bytes: 54660
// #![feature(slice_patterns)]
// CE on stable...
use std::io;
use std::cmp;

// fn main () {
//     if let [a,b,c,d] = read_ints()[..] {
//         println!("{}", cmp::max(a*b,c*d));
//     };
// }
//
fn main () {
    let v = read_ints();
    println!("{}", cmp::max(v[0]*v[1], v[2]*v[3]));
}

fn read_ints () -> Vec<u32>{
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).ok();
    buf.split_whitespace().map(|n| n.parse().unwrap()).collect()
}

Measured memory_bytes: 380
Nstring=input()
# Python3 program to Split string into characters 
def split(word): 
    return [char for char in word]  
Numberlist=split(Nstring)
flag=0
if int(Numberlist[0])==7:
  flag=1
if int(Numberlist[1])==7:
  flag=1
if int(Numberlist[2])==7:
  flag=1
if flag==1:
  print('Yes')
else:
  print('No')

Measured memory_bytes: 9136
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int MAXN = 16;
const int MAXM = (1 << MAXN);
ll dp[MAXM], c[MAXM], a[MAXN][MAXN];
int main()
{
    int n; scanf("%d", &n);
    for (int i = 0; i < n; i++)
        for (int j = 0; j < n; j++)
            scanf("%lld", &a[i][j]);
    for (int s = 0; s < (1 << n); s++)
        for (int i = 0; i < n; i++)
            for (int j = 0; j < i; j++) if (((s >> i) & 1) && ((s >> j) & 1))
                c[s] += a[i][j];
    for (int s = 0; s < (1 << n); s++) dp[s] = -1e18;
    dp[0] = 0;
    for (int U = 1; U < (1 << n); U++)
        for (int s = U; s; s = (s - 1) & U)
            dp[U] = max(dp[U], dp[U ^ s] + c[s]);
    printf("%lld\n", dp[(1 << n) - 1]);
    return 0;
}

Measured memory_bytes: 1280
#include<algorithm>
#include<climits>
#include<cmath>
#include<cstdlib>
#include<iomanip>
#include<iostream>
#include<numeric>
#include<string>
#include<utility>
#include<vector>

using namespace std;
//--------------------

int main() {
	string res = "Yes";
	string S; cin >> S;
	long mylen = S.length();

	for (int i = 0; i < mylen; i++) {
		if (S[i] == 'b' && S[mylen - 1 - i] != 'd') res = "No";
		if (S[i] == 'd' && S[mylen - 1 - i] != 'b') res = "No";
		if (S[i] == 'p' && S[mylen - 1 - i] != 'q') res = "No";
		if (S[i] == 'q' && S[mylen - 1 - i] != 'p') res = "No";
	}
	cout << res << endl;
}

Measured memory_bytes: 512
#include<stdio.h>
#define mod 1000000007

long long modiv(long long a,long long b){
	if(b==0)return 1;
	if(b%2)return (a*modiv(a,b-1))%mod;
	long long i;
	i=modiv(a,b/2);
	return (i*i)%mod;
}

long long ncm(int a,int b){
	long long r1=1,r2=1,r3=1,i;
	for(i=a;i>0;i--)r1*=i,r1%=mod;
	for(i=b;i>0;i--)r2*=i,r2%=mod;
	for(i=a-b;i>0;i--)r3*=i,r3%=mod;
	r2=(r2*r3)%mod;
	long long r=(r1*modiv(r2,mod-2));
	return (r+mod)%mod;
}

int main(){
	int x,y,i;
	long long ans=0;
	scanf("%d%d",&x,&y);
	if((x+y)%3!=0)puts("0");
	else{
		int a=(x+y)/3;
		if(a%2==0){
			int ax=(a/2)*3;
			int ay=ax;
			for(i=0;i<=a/2;i++){
				if(x==ax+i&&y==ay-i){
					printf("%lld\n",ncm(a,a/2-i));
					return 0;
				}if(x==ax-i&&y==ay+i){
					printf("%lld\n",ncm(a,a/2-i));
					return 0;
				}
			}
			puts("0");
			return 0;
		}else{
			int ax=(a/2)*3+2,ay=(a/2)*3+1;
			for(i=0;i<=a/2;i++){
				if(x==ax+i&&y==ay-i){
					printf("%lld\n",ncm(a,a/2-i));
					return 0;
				}if(y==ax+i&&x==ay-i){
					printf("%lld\n",ncm(a,a/2-i));
					return 0;
				}
			}
			puts("0");
			return 0;
		}
	}
	return 0;
}


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

int main() {
  string s;
  cin >> s;
  int a, z;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == 'A') {
      a = i;
      break;
    }
  }
  for (int i = s.size() - 1; i >= 0; i--) {
    if (s[i] == 'Z') {
      z = i;
      break;
    }
  }
  cout << z - a + 1 << endl;
}

Measured memory_bytes: 640
import sys

input=sys.stdin.readline

N=int(input())
p=[]
for i in range(N):
    x,y=map(int,input().split())
    p.append([x,y])
mod=998244353

pow=[1]
for i in range(N):
    pow.append((pow[-1]*2)%mod)

p.sort(key=lambda x:x[1])
for i in range(N):
    p[i][1]=i+1


data=[[0 for i in range(4)] for i in range(N)]
#A1 ... AnのBIT(1-indexed)
n=N
BIT = [0]*(n+1)

#A1 ~ Aiまでの和 O(logN)
def BIT_query(idx):
    if idx==0:
        return 0
    res_sum = 0
    while idx > 0:
        res_sum += BIT[idx]
        idx -= idx&(-idx)
    return res_sum

#Ai += x O(logN)
def BIT_update(idx,x):
    while idx <= n:
        BIT[idx] += x
        idx += idx&(-idx)
    return

p.sort()
for i in range(N):
    x,y=p[i]
    a,b=i,BIT_query(y)
    data[i][0]=a-b
    data[i][3]=b
    BIT_update(y,1)

BIT=[0]*(n+1)
for i in range(N-1,-1,-1):
    x,y=p[i]
    a,b=N-1-i,BIT_query(y)
    data[i][1]=a-b
    data[i][2]=b
    BIT_update(y,1)

ans=0
for i in range(N):
    ban=0
    for j in range(4):
        ban+=(pow[data[i][j]]-1)*pow[data[i][j-1]]
        ban%=mod
    ans+=pow[N]-ban-1
    ans%=mod
print(ans)


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

#define lol long long
#define gcd(x,y) __gcd(x,y)
#define mt make_tuple
#define mp make_pair
#define fi first
#define se second
#define fixed fixed<<setprecision(10)
using namespace std;
using pii=pair<int,int>;
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
template <class A> inline lol abs(A &a) { return (a < 0 ? -a : a); }
const lol Mod=(1e9)+7;
const lol mod=998244353;
const int dx[]={1,0,-1,0,1,1,-1,-1};
const int dy[]={0,1,0,-1,1,-1,1,-1};
lol n,k,r;
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  double a,b,h,m;
  cin >>a>>b>>h>>m;
  double ans;
  ans=a*a+b*b;
  double sum=2*a*b;
  double kaku;
  kaku=6*m;
  
  double p=kaku;
  h*=30;
  h+=30*m/60.0;
  //cout <<kaku<<'\n';
  //cout <<h<<'\n';
  kaku=abs(p-h);
  kaku=min(kaku,min(360+p-h,360+h-p));
  if(kaku>360+p-h) kaku=360+p-h;
  if(kaku>360-p+h) kaku=360-p+h;
  //cout <<kaku<<'\n';
  if(kaku==90) sum=0;
  else{
  kaku=kaku*M_PI/180.0;
  sum*=cos(kaku);
  }
  //cout <<ans<<' '<<sum<<'\n';
  ans-=sum;  cout <<fixed<<sqrt(ans)<<'\n';
  return (0);
}


Measured memory_bytes: 4228
#include<bits/stdc++.h>
using namespace std; 
typedef long long ll;
typedef long double ld;
#define fr first
#define sc second
#define pb push_back
const ll mod = 998244353;
const int N = 1e6+205;
void solve(){
	int x,y,xx,yy;
	cin>>x>>y>>xx>>yy;
	int dx = x-xx;
	int dy = y-yy;
	cout<<xx+dy<<" "<<yy-dx<<" "<<x+dy<<" "<<y-dx<<endl;
}
int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int t=1; 
//	cin>>t; 
	while(t--){
		solve();
	}
	return 0;
}


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

int main(){
   int n;
   cin >> n;
   int w[n];
   int v = 0;
   for(int i=0; i<n; i++){
      cin >> w[i];
      v += w[i];
   }
   int o = 0;
   int ans = 100010;
   for(int i=0; i<n; i++){
      o += w[i];
      ans = min(ans,abs(o-(v-o)));
   }
   cout << ans << endl;
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))

cnt = 0
ans = 0
m = float("INF")
for i in range(N):
  if A[i] < 0:
    cnt += 1
  m = min(m, abs(A[i]))
  ans += abs(A[i])

if cnt % 2 == 1:
  ans -= 2 * m

print(ans)

Measured memory_bytes: 14332
package main

import "fmt"

func main() {
	// Code for A - Takoyaki
	var N, X, T int
	fmt.Scanf("%d %d %d", &N, &X, &T)

	var ans int
	if N%X == 0 {
		ans = T * (N / X)
	} else {
		ans = T * (N/X + 1)

	}
	fmt.Println(ans)
}


Measured memory_bytes: 1832