akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <vector>
#include <cstring>
#include <cstdio>
#include <cstdlib>
using namespace std;

signed main(){
    cin.tie(0); 
    ios::sync_with_stdio(false);
    int a,b,k;
    int count[110];
    int j=0;
    cin>>a>>b>>k;
    for(int i=1;i<=min(a,b);i++){
        if(a%i==0 && b%i==0){
            count[j]=i;
            j++;
        }
    }
    cout<<count[j-k]<<"\n";
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string s;
  cin >> s;
  
  vector<string> a(7);
  a={"SUN","MON","TUE","WED","THU","FRI","SAT"};
  
  for(int i=1; i<7; i++){
  if(s==a[i]){
    cout << abs(7-i) << endl;
  }
  }
 
  if(s==a[0]){
    cout << 7 << endl;
  }
  
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
	int d,n,temp=1;
	
	cin >>d >>n;
	for(int i=0;i<d;i++)temp*=100;
	if(d==0){
		if(n<100)cout<<n<<endl;
		else cout<<n+n/100<<endl;
	}
	else{
		if(n==100)cout<<(n+1)*temp<<endl;
		else cout<<n*temp<<endl;
	}
	return 0;
}

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

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

	int n; cin >> n;
	vector<int>a(n);
	for (auto &it : a)
		cin >> it;
	vector<int>ans(n);
	ans[0] = 0;
	ans[1] = abs(a[0] - a[1]);
	for (int i = 2; i < n; i++)
		ans[i] = min(ans[i - 1] + abs(a[i] - a[i - 1]), ans[i - 2] + abs(a[i] - a[i - 2]));
	cout << ans[n - 1];

	return 0;
}

Measured memory_bytes: 3972
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<functional>
#include<vector>
#include<queue>
#include<stack>
#include<set>
#include<map>
using namespace std;
#define MOD 1000000007
#define f(i,n) for(long long i=0;i<(long long)(n);i++)
#define N 610

int main() {
	long long n, m;
	long long x, y, z;
	long long dp[N][N];
	long long dp2[N][N];
	long long s, ans;
	scanf("%lld %lld", &n, &m);
	f(i, N) {
		f(j, N) {
			dp[i][j] = 0;
			dp2[i][j] = 0;
		}
	}
	dp[1][0] = 1;
	f(i, m) {
		f(i, n + 1) {
			f(j, n + 1) {
				dp2[i + j][0] += (dp[i][j])*i;
				dp2[i + j][0] %= MOD;
				dp2[i][j] += (dp[i][j])*j;
				dp2[i][j] %= MOD;
				dp2[i][j + 1] += (dp[i][j])*(n - i - j);
				dp2[i][j + 1] %= MOD;
			}
		}
		f(i, n + 1) {
			f(j, n + 1) {
				dp[i][j] = dp2[i][j];
				dp2[i][j] = 0;
			}
		}
	}
	printf("%lld\n", dp[n][0]);
	return 0;
}


Measured memory_bytes: 6016
#include <iostream>
using namespace std;
int main(){
  string s;cin>>s;
  int ret = 0;
  for(int i = s.size()-1; 0 < i; i--){
    if(s[i] == 'Z'){
      ret = i;
      break;
    }
  }
  for(int i = 0; ret > i; i++){
    if(s[i] == 'A'){
      cout << ret -i+1 << endl;
      return 0;
    }
  }
}

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

int main(void) {
  int N, M;
  cin >> N >> M;
  vector<vector<int>> years(N + 1);
  vector<int> vp, vy;
  for (int i = 0; i < M; i++) {
    int p, y;
    cin >> p >> y;
    vp.push_back(p);
    vy.push_back(y);
    years[p].push_back(y);
  }
  for (int i = 0; i <= N; i++) {
    if (!years[i].empty()) {
      sort(years[i].begin(), years[i].end());
    }
  }

  for (int i = 0; i < M; i++) {
    auto it = lower_bound(years[vp[i]].begin(), years[vp[i]].end(), vy[i])
              - years[vp[i]].begin();
    printf("%06d%06d\n", vp[i], it + 1);
  }
  return 0;
}

Measured memory_bytes: 7792
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout<<(ans)<<endl
#define STI(s) atoi(s.c_str())
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define _LIBCPP_DEBUG 0
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;}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);};};
const int MOD = 1000000007;
const int INF = INT_MAX;
const ll LLINF = 1LL<<62;
//g++ -std=c++1z main.cpp
//.\a.exe
int main(){
///////////////////////////////////////////////////////////
int n,a=0;
cin >> n;
string s;
cin >> s;
if(n%2==1){
    cout << "No" << endl;
    return 0;
}
for(int i=0;i<n/2;i++){
    if(s[i]!=s[i+n/2]){
        cout << "No" << endl;
        return 0;
    }
}
cout << "Yes" << endl; 
//////////////////////////////////////////////////////////
}

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

int main(void){
  int n, a = 0;
  cin >> n;
  
  for( int i = 0 ; i < n ; i++ ){
    string s;
    cin >> s;
    if( s == "Y" )  a = 1;
  }
  if( a == 0 ){
    cout << "Three" << endl;
  }
  else{
    cout << "Four" << endl;
  }
}

Measured memory_bytes: 3596
use std::str::FromStr;
use std::fmt::Debug;

fn read_as_vec<T>() -> Vec<T>
where T: FromStr, <T as FromStr>::Err : Debug{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().split_whitespace().map(|c| T::from_str(c).unwrap()).collect()

}

fn read_as_string() -> String{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

fn main(){
    let line : Vec<u32> = read_as_vec();

    let (n, m) = (line[0], line[1]);

    if (n-1)/2 >= m-1{
        println!("YES");
    }else{
        println!("NO");
    }
        
}

Measured memory_bytes: 4352
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <ctype.h>
#include <deque>
#include <queue>
#include <cstring>
#include <set>
#include <list>
#include <map>
#include <random>
#include <unordered_map>
#include <stdio.h>

using namespace std;

typedef long long ll;
typedef std::vector<int> vi;
typedef std::vector<bool> vb;
typedef std::vector<string> vs;
typedef std::vector<double> vd;
typedef std::vector<long long> vll;
typedef std::vector<std::vector<int> > vvi;
typedef vector<vvi> vvvi;
typedef vector<vll> vvll;
typedef std::vector<std::pair<int, int> > vpi;
typedef vector<vpi> vvpi;
typedef std::pair<int, int> pi;
typedef std::pair<ll, ll> pll;
typedef std::vector<pll> vpll;

const long long mod = 1000000007;

#define all(c) (c).begin(),(c).end()
#define sz(c) (int)(c).size()
#define forn(i, a, b) for(int i = a; i < b; i++)

#define pb push_back
#define mp make_pair

int main()
{
//#ifndef ONLINE_JUDGE
//    freopen("input.txt", "rt", stdin);
//    freopen("output.txt", "wt", stdout);
//#endif
    string s;
    cin>>s;
    int n = 0;
    int e = 0;
    for(auto x:s) {
        if(x=='N') n = n|1;
        if(x=='S') n = n|2;
        if(x=='W') e = e|1;
        if(x=='E') e = e|2;
    }
    if(n ==1 ||n==2 ||e==1||e==2) cout<<"No"<<endl;
    else cout<<"Yes"<<endl;
    
    
    
}



Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <utility>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <math.h>
#include <string.h>
#include <iomanip>
#include <numeric>
#include <cstdlib>
#include <cstdint>
#include <cmath>
#include <functional>
#include <limits>
#include <cassert>
#include <bitset>

using namespace std;

/* template */

using ll = long long;

void debug_out() { std::cout << std::endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cout << H << " ";
  debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cout << "debug: "; debug_out(__VA_ARGS__)
#else
#define debug(...) 
#endif

#define rep(i, a, n) for (int i = (int)(a); i < (int)(n); i++)
#define rrep(i, a, n) for (int i = ((int)(n-1)); i >= (int)(a); i--)
#define Rep(i, a, n) for (long long i = (long long)(a); i< (long long)(n); i++)
#define RRep(i, a, n) for (long long i = ((long long)(n-1ll)); i>=(long long)(a); i--)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()

template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
  for (std::size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  return os;
}

struct Edge{
    int to;
    ll weight;
    Edge(int t, ll w) : to(t), weight(w){ }
};

struct edge{
    int from;
    int to;
    ll weight;
    edge(int f,int t,ll w) : from(f), to(t), weight(w){ }
};


using Graph = vector<vector<Edge>>;
using graph = vector<vector<int>>;
using edges = vector<edge>;

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

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

template <class T>
T lcm(T a, T b){
    return (a*b)/gcd(a,b);
}

ll ctoi(char c) {
	switch (c) {
	case '0': return 0; case '1': return 1; case '2': return 2;
	case '3': return 3; case '4': return 4; case '5': return 5;
	case '6': return 6; case '7': return 7; case '8': return 8;
	case '9': return 9;  default: return 0;
	}
}

constexpr ll LNF = 1LL<<50;

constexpr int INF = 1e9+7;

const long double PI=3.14159265358979323846;


vector<int> dx = {1,0,-1,1,-1,0};
vector<int> dy = {1,1,1,0,0,-1};

/* template */

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    vector<int> a(n);
    int ans = 0;
    rep(i,0,n){
        cin >> a[i];
        if(a[i]%2==1 && (i+1)%2==1){
            ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3644
package main

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

var (
	read  = bufio.NewReader(os.Stdin)
	write = bufio.NewWriter(os.Stdout)
)

func yesno(result bool) {
	if result {
		fmt.Fprintln(write, "Yes")
	} else {
		fmt.Fprintln(write, "No")
	}
}

func printansStr(result bool, a, b string) {
	if result {
		fmt.Fprintln(write, a)
	} else {
		fmt.Fprintln(write, b)
	}
}

func printansInt(result bool, a, b int) {
	if result {
		fmt.Fprintln(write, a)
	} else {
		fmt.Fprintln(write, b)
	}
}

var isInitCom = false
var max = int64(10000)
var mod = int64(1000000007)
var fac = make([]int64, max)
var finv = make([]int64, max)
var inv = make([]int64, max)

func combInit() {
	fac[0], fac[1] = 1, 1
	finv[0], finv[1] = 1, 1
	inv[1] = 1
	for i := int64(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
	}
}

func comb(n, k int64) int64 {
	if !isInitCom {
		combInit()
		isInitCom = true
	}

	if n < k {
		return 0
	}
	if n < 0 || k < 0 {
		return 0
	}
	return fac[n] * (finv[k] * finv[n-k] % mod) % mod
}

func main() {
	defer write.Flush()

	var n int
	fmt.Fscan(read, &n)

	ans := n
	for i := 1; i <= int(math.Sqrt(float64(n))); i++ {
		if n%i != 0 {
			continue
		}
		cnt := (i - 1) + (n/i - 1)
		if ans > cnt {
			ans = cnt
		}
	}
	fmt.Fprintln(write, ans)
}


Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <numeric>
#include <vector>
#include <queue>
#include <map>
typedef unsigned long long ull;
typedef long long ll;
#define MAX 15
using namespace std;
int main() {
  int n, s;
  cin >> n;
  int t=n/100;
  s = 111*t;
  if(n <= s) cout << s << endl;
  else {
    s = 111*(t+1);
    cout << s << endl;
  }

  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>

#define DEBUG 0

typedef struct {
	int a;
	int b;
	int c;
} Menu;

int compare(const void *a,const void *b)
{
	return ((Menu *)b)->c - ((Menu *)a)->c;
}

int main(void)
{
	Menu *menu;
	int n,*a,*b,*c,i;
	long ans=0;
	scanf("%d",&n);
	menu = (Menu *)malloc(sizeof(Menu) * (n + (n%2)));
	for (i=0;i<n;i++) {
		scanf("%d %d",&menu[i].a,&menu[i].b);
		menu[i].c = menu[i].a+menu[i].b;
	}
	if (n%2==1) {
		menu[n].a = 0;
		menu[n].b = 0;
		menu[n].c = -1;
	}

	qsort(menu,n+n%2,sizeof(Menu),compare);

	for (i=0;i<n;i+=2) {
		ans += menu[i].a;
		ans -= menu[i+1].b;
	}
	printf("%ld\n",ans);
	
	return 0;
}


Measured memory_bytes: 2556
import java.util.Scanner;
class Main {
	int x,i = 1;
	public void suzuki(){
		Scanner sc = new Scanner(System.in);
		x = sc.nextInt();
		while(x != 0){
			System.out.println("Case" + " " + i + ":" + " " + x);
			x = sc.nextInt();
			i++;
		}
	}
	public static void main(String[] args){
		new Main().suzuki();
	}
}

Measured memory_bytes: 33164
class Node():
    def __init__(self, id, children):
        self.id = id
        self.children = children

N = int(raw_input())
nodes = {}
for _ in range(N):
    d = map(int, raw_input().split())
    id,k,cs = d[0],d[1],d[2:]
    nodes[id] = Node(id, cs)

roots = range(N)
for i in range(N):
    [roots.remove(j) for j in nodes[i].children]
    nodes[i].children = [nodes[j] for j in nodes[i].children]

data = []
def traverse(node, p, d):
    id = node.id
    cs = map(lambda x:x.id, node.children)
    if p == -1:
        t = "root"
    elif len(cs) == 0:
        t = "leaf"
    else:
        t = "internal node"
    s = "node {}: parent = {}, depth = {}, {}, {}".format(id,p,d,t,cs)
    data.append((id, s))
    
    for child in node.children:
        traverse(child, id, d+1)

root = roots[0]
traverse(nodes[root], -1, 0)
for _,s in sorted(data, key=lambda x:x[0]):
    print s


Measured memory_bytes: 85936
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
using P = pair<int, int>;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
template<class T> void assign(V<T>& v, int n, const T& a = T()) { v.assign(n, a); }
template<class T, class... U> void assign(V<T>& v, int n, const U&... u) { v.resize(n); for (auto&& i : v) assign(i, u...); }

const V<> di = {1, 0, -1, 0}, dj = {0, 1, 0, -1};

int main() {
  cin.tie(NULL); ios::sync_with_stdio(false);
  int h, w, k; cin >> h >> w >> k;
  V<string> a(h); for (int i = 0; i < h; i++) cin >> a[i];
  int si, sj;
  for (int i = 0; i < h; i++) for (int j = 0; j < w; j++) if (a[i][j] == 'S') {
    si = i, sj = j;
    break;
  }
  VV<> d; assign(d, h, w, -1);
  queue<P> q;
  d[si][sj] = 0; q.emplace(si, sj);
  while (!q.empty()) {
    int i, j; tie(i, j) = q.front(); q.pop();
    for (int k = 0; k < 4; k++) {
      int ni = i + di[k], nj = j + dj[k];
      if (ni < 0 or ni >= h or nj < 0 or nj >= w or a[ni][nj] == '#') continue;
      if (d[ni][nj] == -1) {
        d[ni][nj] = d[i][j] + 1; q.emplace(ni, nj);
      }
    }
  }
  int mi = 1e9;
  for (int i = 0; i < h; i++) for (int j = 0; j < w; j++) {
    if (0 <= d[i][j] and d[i][j] <= k) mi = min({mi, i, h - 1 - i, j, w - 1 - j});
  }
  cout << (mi + k - 1) / k + 1 << '\n';
}

Measured memory_bytes: 3456
<?php
fscanf(STDIN, "%d", $n);

$check = false;
for($i=1; $i<10; $i++) {
  for($j=1; $j<10; $j++) {
    if($i*$j == $n) {
      $check = true;
    break;
    }
  }
}
if($check == true) echo "Yes";
else echo "No";

Measured memory_bytes: 3828
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i, n) for (ll i = 0; i < n; i++)
#define rrep(i, n) for (ll i = n - 1; i >= 0; i--)
#define Rep(i, r, n) for (ll i = r; i < n; i++)
#define RRep(i, r, n) for (ll i = n - 1; i <= r; i--)
#define debug(x) cout << #x << ' ' << '=' << ' ' << (x) << endl;
#define fs first
#define sc second
#define int long long
#define pb push_back
#define mp make_pair
const int dx[] = {0, -1, 0, 1};
const int dy[] = {1, 0, -1, 0};
const int MOD = (1000000007);
//const int MOD = (998244353);
//const int INF = (1 << 30)-1;
const int INF = (1LL << 60)-1;
const double EPS = (1 >> 30);

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return 1;} return 0;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return 1;} return 0;}

using Graph = vector<vector<pair<int, int>>>;
using Ki = vector<vector<int>>;
using Vi = vector<int>;

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(10);
    //---------------------------------------------
    
    string s;
    string t;
    cin>>s>>t;
    int n,m;
    n=s.size();
    m=t.size();
    int dp[n+1][m+1];
    rep(i,n+1) rep(j,m+1) dp[i][j]=0;

    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            if(s[i-1]==t[j-1]){
                dp[i][j]=dp[i-1][j-1]+1;
            }
            else{
                dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
            }
        }
    }    

    string ans="";
    int x=n;
    int y=m;
    while(x>0&&y>0){
        if(dp[x][y]==dp[x-1][y]){
            x--;
        }
        else if(dp[x][y]==dp[x][y-1]){
            y--;
        }
        else{
            x--;
            y--;
            ans.push_back(s[x]);
        }
    }
    reverse(all(ans));
    cout<<ans<<endl;
}

Measured memory_bytes: 70656
<?php
fscanf(STDIN, '%d %d', $k, $x);
$start = $x - $k + 1;
$end = $x + $k - 1;
for ($i = $start; $i <= $end; $i++) {
    echo $i;
    if ($i === $end) echo PHP_EOL;
    else echo ' ';
}

Measured memory_bytes: 4604
#include <algorithm>
#include <array>
#include <iostream>
#include <set>
#include <string>
#include <vector>

using namespace std;

using ll = long long;

long long choose(array<vector<int>, 256> &ch_pos, char ch, int i, int j) {
  auto it = upper_bound(ch_pos[ch].begin(), ch_pos[ch].end(), j);
  long long ans = distance(it, ch_pos[ch].end());
  bool found = binary_search(it, ch_pos[ch].end(), 2 * j - i);
  if (found) {
    ans = max(0ll, ans - 1);
  }

  return ans;
}

int main(int argc, const char *argv[]) {
  int n;
  string s;
  cin >> n >> s;

  array<vector<int>, 256> ch_pos;
  for (int i = 0; i < n; i++) {
    ch_pos[s[i]].push_back(i);
  }

  array<char, 3> kinds{'B', 'G', 'R'};
  long long ans = 0;
  do {
    vector<int> &pos1 = ch_pos[kinds[0]], &pos2 = ch_pos[kinds[1]];
    for (int i = 0; i < pos1.size(); i++) {
      for (int j = 0; j < pos2.size(); j++) {
        if (pos1[i] < pos2[j]) {
          ans += choose(ch_pos, kinds[2], pos1[i], pos2[j]);
        }
      }
    }
  } while (next_permutation(kinds.begin(), kinds.end()));
  cout << ans << '\n';
  return 0;
}

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

const int N = 200 * 1000 + 10;

int n, Q, ans[N] = {};
bool vis[N], flag = 0;
vector <int> gr[N];

void dfs(int v, int p) {
	for (auto u: gr[v]) 
		if (u != p) {
			ans[u] += ans[v];
			dfs(u, v);
		}
}

void get() {
	cin >> n >> Q;
	for (int i = 0; i < n - 1; i++) {
		int x, y;
		cin >> x >> y;
		x--, y--;
		gr[x].push_back(y);
		gr[y].push_back(x);
	}
	for (int i = 0; i < Q; i++) {
		int p, x;
		cin >> p >> x;
		ans[--p] += x;
	}	
}

int main() {
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	get();
	dfs(0, -1);
	for (int i = 0; i < n; i++)
		cout << ans[i] << " ";	
}

Measured memory_bytes: 23552
#include <bits/stdc++.h>
 
using namespace std;
 
int main()
{
    int X,Y;
    cin >> X >> Y;
    if (Y >= 2*X && Y <= 4*X && Y%2 == 0)
    {
        cout << "Yes";
    }else
    {
        cout << "No";
    }
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
const int INF=1145141919,MOD=1e9+7;
const long long LINF=1145141919810364364;

bool used[26];

int main(){
	string s; cin>>s;
	if(s=="zyxwvutsrqponmlkjihgfedcba"){
		cout<<-1<<endl;
		return 0;
	}
	for(auto i:s) used[i-'a']=1;
	for(int i=0;i<26;i++){
		if(!used[i]){
			char x=i+'a';
			cout<<s+x<<endl;
			return 0;
		}
	}
	for(int i=25;i>=0;i--){
		int tmp=s[i]-'a';
		used[tmp]=0;
		s=s.substr(0,i);
		// cout<<s<<endl;
		for(int j=tmp+1;j<26;j++){
			if(!used[j]){
				char x=j+'a';
				cout<<s+x<<endl;
				return 0;
			}
		}
	}
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll unsigned long long int
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int x,y;
    cin>>x>>y;
    if(y%2!=0){
        cout<<"No";
        return 0;
    }else{
    if(y>=x*2&&y<=x*4)
    {
        cout<<"Yes";
    }else{
    cout<<"No";
    }

    }


    return 0;
}


Measured memory_bytes: 3628
N = gets.to_i
A = gets.split.map(&:to_i).sort

a_min, a_max = A.minmax

if a_max - a_min > 1
  puts 'No'
  exit
end

if a_min == a_max
  if a_min == 1 || a_min == N - 1
    puts 'Yes'
  elsif 2 * a_min <= N
    puts 'Yes'
  else
    puts 'No'
  end
else
  y = A.count(a_max)
  x = N - y

  if x < a_max && 2 * (a_max - x) <= y
    puts 'Yes'
  else
    puts 'No'
  end
end


Measured memory_bytes: 11248
#include<iostream>
using namespace std;
const int MAXN=1e4+5;
int A[MAXN];
int n;
bool find(int x){
	for(int i=0;i<n;i++){
		if(x==A[i])return true;
	}
	return false;
}
int main(){
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>A[i];
	}
	int q;
	cin>>q;
	int res=0;
	for(int i=0;i<q;i++){
		int key;
		cin>>key;
		if(find(key))res++;
	}
	cout<<res<<endl;
	return 0;
}


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

using namespace std;

typedef long long int64;

const int INF = 1000;

int main()
{
  int64 H, W, h, w;
  int64 mat[500][500];

  cin >> H >> W >> h >> w;
  for(int i = 0; i < H; i++) {
    for(int j = 0; j < W; j++) {
      if(i % h == h - 1 && j % w == w - 1) {
        mat[i][j] = -(h * w - 1) * INF - 1;
      } else {
        mat[i][j] = INF;
      }
    }
  }

  int64 ret = 0;
  for(int i = 0; i < H; i++) {
    for(int j = 0; j < W; j++) {
      ret += mat[i][j];
    }
  }

  if(ret <= 0) {
    cout << "No" << endl;
  } else {
    cout << "Yes" << endl;
    for(int i = 0; i < H; i++) {
      for(int j = 0; j < W; j++) {
        cout << mat[i][j] << " ";
      }
      cout << endl;
    }
  }
}


Measured memory_bytes: 3584
#include<bits/stdc++.h>
using namespace std;
int a,b;
int main()
{
	scanf("%d%d",&a,&b);
	for(int i=1;i<=2000;i++)
	{
		if(i*8/100==a&&i/10==b)
		{
			cout<<i;
			return 0;
		}
	}
	cout<<-1;
	return 0;
}


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

using namespace std;

int main()
{
    int n;
    cin >> n;
    int x[n + 1];
    for(int i = 1; i <= n; i++)
    {
        cin >> x[i];
    }

    int a[n + 1];
    memcpy(a, x, sizeof(x));

    sort(a + 1, a + n + 1, greater<int>());

    int midVal = a[(1 + n - 1) / 2];
    for(int i = 1; i <= n; i++)
    {
        if(x[i] < midVal)
        {
            cout << midVal << endl;
        }
        else
        {
            cout << a[(1 + n - 1) / 2 + 1] << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 3712
#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
typedef  long long ll;
int gcd(int f , int s){if(s==0)return f;else return gcd(s,f%s);}
int const N = 600005;
ll const M = 998244353;
long double const ep = .000000000000000001;

int main() {

	int a , b ;
	cin >> a >> b;
	if(a + b ==15){
		printf("+\n");
	}else if(a*b==15){
		printf("*\n");
	}else printf("x\n");
	return 0;	
}

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

template <int MOD_> struct modnum {
	static constexpr int MOD = MOD_;
	static_assert(MOD_ > 0, "MOD must be positive");
 
private:
	using ll = long long;
 
	int v;
 
	static int minv(int a, int m) {
		a %= m;
		assert(a);
		return a == 1 ? 1 : int(m - ll(minv(m, a)) * ll(m) / a);
	}
 
public:
 
	modnum() : v(0) {}
	modnum(ll v_) : v(int(v_ % MOD)) { if (v < 0) v += MOD; }
	explicit operator int() const { return v; }
	friend std::ostream& operator << (std::ostream& out, const modnum& n) { return out << int(n); }
	friend std::istream& operator >> (std::istream& in, modnum& n) { ll v_; in >> v_; n = modnum(v_); return in; }
 
	friend bool operator == (const modnum& a, const modnum& b) { return a.v == b.v; }
	friend bool operator != (const modnum& a, const modnum& b) { return a.v != b.v; }
 
	modnum inv() const {
		modnum res;
		res.v = minv(v, MOD);
		return res;
	}
	modnum neg() const {
		modnum res;
		res.v = v ? MOD-v : 0;
		return res;
	}
 
	modnum operator- () const {
		return neg();
	}
	modnum operator+ () const {
		return modnum(*this);
	}
 
	modnum& operator ++ () {
		v ++;
		if (v == MOD) v = 0;
		return *this;
	}
	modnum& operator -- () {
		if (v == 0) v = MOD;
		v --;
		return *this;
	}
	modnum& operator += (const modnum& o) {
		v += o.v;
		if (v >= MOD) v -= MOD;
		return *this;
	}
	modnum& operator -= (const modnum& o) {
		v -= o.v;
		if (v < 0) v += MOD;
		return *this;
	}
	modnum& operator *= (const modnum& o) {
		v = int(ll(v) * ll(o.v) % MOD);
		return *this;
	}
	modnum& operator /= (const modnum& o) {
		return *this *= o.inv();
	}
 
	friend modnum operator ++ (modnum& a, int) { modnum r = a; ++a; return r; }
	friend modnum operator -- (modnum& a, int) { modnum r = a; --a; return r; }
	friend modnum operator + (const modnum& a, const modnum& b) { return modnum(a) += b; }
	friend modnum operator - (const modnum& a, const modnum& b) { return modnum(a) -= b; }
	friend modnum operator * (const modnum& a, const modnum& b) { return modnum(a) *= b; }
	friend modnum operator / (const modnum& a, const modnum& b) { return modnum(a) /= b; }
};
using num = modnum<int(1e9) + 7>;

const int MAXN = 5005;
int N;
int M;
string s;

num dp[MAXN][MAXN];

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	cin >> N >> s;
	M = int(s.size());

	dp[0][0] = 1;
	for (int i = 0; i < N; i++) {
		for (int j = 0; j <= i; j++) {
			dp[i+1][j+1] += dp[i][j] * 2;
			dp[i+1][max(j-1, 0)] += dp[i][j];
		}
	}

	num ans = dp[N][M];
	for (int i = 0; i < M; i++) ans /= 2;

	cout << ans << '\n';

	return 0;
}


Measured memory_bytes: 98176
N = gets.to_i
As = gets.split.map(&:to_i)
Q = gets.to_i
BCs = readlines.map{_1.split.map(&:to_i)}

s = As.sum
h = As.each_with_object(Hash.new(0)){|a, h| h[a] += 1}
BCs.each do |b, c|
  if n = h.delete(b)
    s += (c - b)*n
    h[c] += n
  end
  puts s
end

Measured memory_bytes: 32684
k, n = list(map(int, input().split()))
x = list(map(int, input().split()))
x.sort()
df = [0] * (n - 1)
for i in range(n - 1):
    df[i] = abs(x[i + 1] - x[i])

df = sorted(df, reverse=True)
print(sum(df[k - 1 :]))


Measured memory_bytes: 20644
using System;
using System.IO;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Numerics;
using System.Threading.Tasks;
using System.Text.RegularExpressions;
using static System.Math;
using Debug = System.Diagnostics.Debug;
using LayoutKind = System.Runtime.InteropServices.LayoutKind;
using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions;
using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute;


static class P
{
    static void Main()
    {
        var dg = Console.ReadLine().Split().Select(int.Parse).ToArray();
        var d = dg[0];
        var g = dg[1];
        var pc = Enumerable.Repeat(0, d).Select(_ => Console.ReadLine().Split().Select(int.Parse).ToArray()).ToArray();
        int res = int.MaxValue;
        for (int i = 0; i < (1 << d); i++)
        {
            int remain = g;
            int count = 0;
            int max = -1;
            for (int j = 0; j < d; j++)
            {
                if (((i >> j) & 1) == 1)
                {
                    remain -= (j + 1) * pc[j][0] * 100 + pc[j][1];
                    count += pc[j][0];
                }
                else max = j;
            }
            if (max == -1)
            {
                if (remain <= 0) res = Min(res, count);
                continue;
            }
            if (remain > ((max + 1) * 100) * pc[max][0]) continue;
            count += (int)Ceiling((double)Max(0, remain) / ((max + 1) * 100));
            res = Min(res, count);
        }
        Console.WriteLine(res);
    }
}


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

#define SIZE 10

int ary[SIZE];

string solve(int a, int b, int f) {
	if (f >= 10) return "YES";
	
	if (ary[f] > a) return solve(ary[f], b, f + 1);
	if (ary[f] > b) return solve(a, ary[f], f + 1);

	return "NO";
}

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

	for (int i = 0; i++ < n;) {
		for (int j = 0; j < SIZE; j++) {
			cin >> ary[j];
		}
		cout << solve(0, 0, 0) << endl;
	}
	return 0;
}

Measured memory_bytes: 3140
s = input()
n  = len(s)
ans = [0]*n
rstrk = 0
lstrk = 0
for i in range(n):
    rstrk += 1
    if s[i] == "L":
        ans[i-1] += rstrk//2
        ans[i] += (rstrk+1)//2
        rstrk = 0
for i in range(n-1,-1,-1):
    lstrk += 1
    if s[i] == "R":
        ans[i+1] += lstrk//2
        ans[i] += (lstrk+1)//2
        lstrk = 0
    ans[i]-=1
print(*ans)

Measured memory_bytes: 10824
#include <cstdio>
#include <cstring>
#include <string>
#include <iostream>
using namespace std;

string s[55];
string ans;
int cnt[55][26];
int n;

int main() {
	cin >> n;
	for (int i=1; i<=n; ++i) {
		cin >> s[i];
		for (int j=0; j<s[i].length(); ++j) {
			cnt[i][s[i][j]-'a']++;
		}
	}
	ans = "";
	for (int i=0; i<26; ++i) {
		int c = 100000;
		for (int j=1; j<=n; ++j) c = min(c, cnt[j][i]);
		for (int j=1; j<=c; ++j) ans += ('a'+i);
	}
	cout << ans << '\n';
	return 0;
}




Measured memory_bytes: 256
use std::cmp;
use std::collections::VecDeque;

fn get_line() -> String {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().to_string()
}

fn main() {
    let n = get_line().parse().unwrap();

    let mut xs = Vec::new();

    for _ in 0..n {
        let mut s: Vec<_> = get_line().chars().collect();
        s.sort();
        xs.push(s.into_iter().collect());
    }

    for c in solve(&mut xs) {
        print!("{}", c);
    }
    println!("");
}

fn solve(xs: &mut Vec<VecDeque<char>>) -> Vec<char> {
    let mut res = Vec::new();

    let mut c = true;
    while c {
        let mut m = 'z';
        for i in 0..xs.len() {
            m = cmp::min(m, xs[i][0]);
        }

        let mut b = true;
        for i in 0..xs.len() {
            if xs[i][0] == m {
                xs[i].pop_front();

                if xs[i].is_empty() {
                    c = false;
                }
            }
            else {
                b = false;
            }
        }

        if b {
            res.push(m);
        }
    }

    res
}


Measured memory_bytes: 4352
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		while(true){
			String[] inputNum = br.readLine().split(" ");

			int H = Integer.parseInt(inputNum[0]);
			int W = Integer.parseInt(inputNum[1]);

			if (H == 0 && W == 0) {
				break;
			}

			for (int i = 0; i < H; i++) {
				for (int j = 0; j < W; j++) {
					if (((i%2 == 0) && (j%2 == 0)) || ((i%2 != 0) && (j%2 != 0))) {
						System.out.print("#");
					}else{
						System.out.print(".");
					}
				}
				System.out.println("");
			}
			System.out.println("");
		}


	}

}

Measured memory_bytes: 25992
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define _USE_MATH_DEFINES
#include <math.h>
#define rep(i,n) for(int i = 0;i < n;i++)
#define NIL = -1;
#define all(x) x.begin(),x.end()
const ll INF = 1LL<<60;
const ll mod = 1e9 + 7;
 
int digit(ll x) {
    if (x / 10 == 0) return 1;
    return digit(x / 10) + 1;
}
 
ll gcd(long long a,long long b) {
    if (a < b) swap(a,b);
    if (b == 0) return a;
    
    return gcd(b,a%b);
}
 
ll lcm(ll a,ll b){
    return ((a * b == 0)) ? 0 : (a / gcd(a,b) * b);
}
 
double DegreeToRadian(double degree){
    return degree * M_PI / 180.0;
}
 
 
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};
 
 
///////////////////////////////////////////////////////////////////////////////////

int main(){
    int n;
    long long k;
    cin >> n >> k;
    vector<int> a(n);
    vector<int> l(n, -1);
    for (int i = 0;i < n;i++){
        cin >> a[i];
        a[i]--;
    }

    int cur = 0;
    int cnt = 0;

    while(l[cur] == -1){
        l[cur] = cnt++;
        cur = a[cur];
        if (cnt == k){
            cout << cur + 1 << endl;
            return 0;
        }
    }

    k -= l[cur];
    int cycle = cnt - l[cur];
    k %= cycle;
    for(int i = 0;i < k;i++){
        cur = a[cur];
    }

    cout << cur + 1 << endl;
    return 0;
}

Measured memory_bytes: 4804
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<queue>
#include<deque>
#include<cmath>
#include<map>
#include<unordered_map>
#include<set>
#include<cstring>
#include<iomanip> //cout << fixed << setprecision(15) << x << endl;

using namespace std;
typedef long long ll;
const ll INF = 1e9 + 6;
const ll MOD = 1e9 + 7;
const ll LLINF = 1e18;
#define Pint pair<int, int>
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rnr(i,a,b) for(int i=int(a);i>=int(b);i--)
#define rep(i,b) rng(i,0,b)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
/* -- template -- */

int main() {
    #define int ll
    int n; cin >> n;
    int a[n];
    map<int, int> m;
    rep(i, n) cin >> a[i], m[a[i]]++;
    ll ans = 0;
    for(auto itr = m.begin(); itr != m.end(); ++itr) {
        ans += itr -> first * itr -> second;
    }
    int q; cin >> q;
    vector<ll> anses;
    rep(i, q) {
        int b, c; cin >> b >> c;
        ans -= m[b] * b;
        ans += m[b] * c;
        m[c] += m[b];
        m[b] = 0;
        anses.pb(ans);
    }
    rep(i, q) {
        cout << anses[i] << endl;
    }
}


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

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

  vector<int> x(n);
  rep(i,n) cin >> x[i];
  int ans = 0;
  
  rep(i,n) {
    int m = min(x[i], abs(x[i]-k));
    ans += 2*m;
  }

  cout << ans << endl;
}

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

 
int main() {
   int n;
   cin>>n;
   vector<int> d(n);
   rep(i,n)cin>>d[i];
   sort(d.begin(),d.end());
   cout<<d[n/2]-d[n/2-1]<<endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i, s, n) for (int i = (s); i < (n); ++i)
#define rrep(i, n, g) for (int i = (n)-1; i >= (g); --i)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define len(x) (int)(x).size()
#define dup(x, y) (((x) + (y)-1) / (y))
#define pb push_back
#define Field(T) vector<vector<T>>
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  int a, b;
  cin >> a >> b;
  if (a == b)
    cout << a * 2 << endl;
  else
    cout << max(a, b) * 2 - 1 << endl;
}

Measured memory_bytes: 3564
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long double ld;

int dp[2][2000005];

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	string s;
	cin >> s;
	s.reserve();
	s += string(1000000, '0');
	int n = s.size();
	dp[0][0] = 0;   // dig円支払い
	dp[1][0] = 2e9; // 10^(d+1)円支払い、お釣りをもらう
	REP(i,n){
		int dig = s[i] - '0';
		dp[0][i+1] = min(dp[0][i]+dig, dp[1][i]+dig+1);
		dp[1][i+1] = min(dp[0][i]+(10-dig), dp[1][i]+(10-dig)-1);
	}
	
	cout << min(dp[0][n], dp[1][n]) << '\n';
	return 0;
}



Measured memory_bytes: 18804
#include <iostream>
#include <unordered_set>
#include <cstdint>
#include <vector>
#include <string>
#include <climits>
#include <set>
#include <algorithm>
#include <math.h>
using namespace std;

int main()
{
	int n;
	cin >> n;
	unordered_set<int> niz;

	for (int i = 1; i <= 9; i++)
		for (int j = 1; j <= 9; j++)
			niz.insert(i * j);

	if (niz.find(n) != niz.end())
		cout << "Yes";
	else cout << "No";
}

Measured memory_bytes: 3608
/*
    author - NIRANJAN E.N.S
    account - flyHigher
    codeforces
*/
#include <bits/stdc++.h>
using namespace std;

#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define deb3(x,y,z) cout << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z << endl

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<string> vs;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef vector<char> vc;

#define fr first
#define sd second
#define mp make_pair
#define pb push_back
#define all(v) v.begin(), v.end()

#define fo(i,n) for(int i = 0; i < int(n); i++)
#define fo1(i,n) for(int i = 1; i < int(n); i++)
#define fom(i,n,m) for(int i = m; i < int(n); i++)
#define rfo(i,n) for(int i = int(n-1); i >= 0; i--)
#define rfo1(i,n) for(int i = int(n-1); i >= 1; i--)
#define rfom(i,n,m) for(int i = int(n-1); i >= (int)m; i--)

#define M0(a) memset(a, 0, sizeof(a))
#define M1(a) memset(a, -1, sizeof(a))
#define V0(v,n) v.resize(n,0);
#define V1(v,n) v.resize(n,-1);
#define VV0(v,n,m) v.resize(n,vi(m,0));
#define VV1(v,n,m) v.resize(n,vi(m,-1));
#define VVL0(v,n,m) v.resize(n,vl(m,0));
#define VVL1(v,n,m) v.resize(n,vl(m,-1));

const ll inf  = 1e9+7;
const ll mod  = 1e9+7;
const ll maxn = 1e5+7;

void print_int(vi);
void print_ll(vl);
ll power(ll,ll);

inline ll inv(int a) {
    return power(a, mod-2);
}

void solve() {
    int k;
    string s;
    cin>>k>>s;
    int n = s.length();
    for(int i=0;i<min(k,n);i++)
        cout<<s[i];
    if(n>k)
        cout<<"...";
    cout<<endl;
}   

int main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    int T=1;
    //cin>>T;
    for(int t=1;t<=T;t++) {
        //cout<<"Case #"<<t<<": ";
        solve();
    }

    return 0;
}

void print_int(vi v) {
    for(int i:v)
        cout<<i<<" ";
    cout<<endl;
}

void print_ll(vl v) {
    for(ll i:v)
        cout<<i<<" ";
    cout<<endl;
}

ll power(ll n,ll p) {
    ll res = 1;
    while(p!=0) {
        if(p&1)
            res = res*n;
        n = n*n;
        p = p>>1;
    }
    return res;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  	cin >> N;
  if(N % 1110 == N % 10 || (N % 1000) % 111 == 0) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

const int Z = 1e9+7;

int bexp(int a, int x) {
    if (x == 0) {
        return 1;
    }
    if (x % 2 == 1) {
        return 1ll * a * bexp(a, x - 1) % Z;
    }
    int t = bexp(a, x / 2);
    return 1ll * t * t % Z;
}

int inv(int a) {
    return bexp(a, Z - 2);
}

int main() {
    ios::sync_with_stdio(false);

    int x, y;
    cin >> x >> y;

    if ((x + y) % 3 != 0) {
        cout << 0 << endl;
        return 0;
    }

    int step = (x + y) / 3;
    if (x < step || y < step) {
        cout << 0 << endl;
        return 0;
    }

    x -= step;
    y -= step;

    int ans = 1;
    for (int i = 1; i <= x + y; i++) {
        ans = 1ll * ans * i % Z;
    }
    for (int i = 1; i <= x; i++) {
        ans = 1ll * ans * inv(i) % Z;
    }
    for (int i = 1; i <= y; i++) {
        ans = 1ll * ans * inv(i) % Z;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
#include<iomanip>
#include<sstream>
#include<map>
#include<cmath>
using namespace std;
#define rep(i,n) for(int i = 0;i < n;i++)
#define req(i,n) for(int i = 1;i <=n;i++)
#define rrep(i,n) for(int i = n -1;i >= 0;i--)
#define ALL(a) a.begin(),a.end()
typedef long long ll;
typedef long double ld;
const ll MOD =  1000000007;
const ll INF =  1LL << 60;
int n, m, x, y;ll z = 0, w, h, sum = 0, ans = 0;
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T & val) {
    std::fill((T*)array, (T*)(array + N), val);
}
struct Corr {
    ll x;
    ll y;
    ll z;
};
int main(void) {
    cin >> n >> m;
    ll dp[110][110]; vector<Corr> a(m);
    Fill(dp, INF);
    rep(i, m) {
        cin >> x >> y >> z;
        x--; y--;
        dp[x][y] = z;
        dp[y][x] = z;
        a[i] = { x,y,z };
    }
    rep(i, n) dp[i][i] = 0;
    rep(i, n) {
        rep(j, n) {
            rep(k, n) {
                dp[j][k] = min(dp[j][k], dp[j][i] + dp[i][k]);
            }
        }
    }
    rep(i, m) {
        bool f = 0;
        rep(j, n) {
            if (dp[j][a[i].x] + a[i].z == dp[j][a[i].y]) {
                f = 1; break;
            }
            if (dp[j][a[i].y] + a[i].z == dp[j][a[i].x]) {
                f = 1; break;
            }
        }
        if (!f) ans++;
    }cout << ans << endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0,i##_max=(N);i<i##_max;++i)
#define repp(i,l,r) for(int i=(l),i##_max=(r);i<i##_max;++i)
#define per(i,N) for(int i=(N)-1;i>=0;--i)
#define perr(i,l,r) for(int i=r-1,i##_min(l);i>=i##_min;--i)
#define all(arr) (arr).begin(), (arr).end()
#define SP << " " <<
#define SPF << " "
#define SPEEDUP cin.tie(0);ios::sync_with_stdio(false);
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL; 
  typedef pair<ll,char> PLC; 
  typedef pair<char,ll> PCL; 

inline void YesNo(bool b){ cout << (b?"Yes" : "No") << endl;}
inline void YESNO(bool b){ cout << (b?"YES" : "NO") << endl;}
inline void Yay(bool b){ cout << (b?"Yay!" : ":(") << endl;}

int main(void){
  SPEEDUP
  cout << setprecision(15);
  int N;cin >> N;
  vector<int> v(N);
  rep(i,N){
    cin >> v[i];
    --v[i];
  }
  set<int> st;
  int s = 0, g = 1;
  bool sat = false;
  int count = 0;
  while(true){
    if(s==g){
      sat = true;
      break;
    }
    if(st.count(s)) break;
    st.insert(s);
    s = v[s];
    ++count;
  }
  if(sat) cout << count << endl;
  else cout << -1 << endl;
  return 0;
}


Measured memory_bytes: 5376
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,n) for(int i=0;i<(n);i++)
#define all(t) (t).begin(),(t).end()
#define MOD 1000000007
typedef long long ll;
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}else{return 0;}}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}else{return 0;}}
template <class T> inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template <class T> inline T LCM(T a,T b){return a*b/GCD(a,b);}

int d[]={4,1,10,9,12,3};

int main(){
	string s;
	cin >> s;
	reverse(all(s));
	ll dp[100010][15];
	FOR(i,100010)FOR(j,15)dp[i][j]=0;
	dp[0][0]=1;
	for(int i=1;i<=(int)s.size();i++){
		int v=d[i%6];
		if(s[i-1]=='?'){
			FOR(j,10){
				int x=v*j%13;
				FOR(k,13){
					dp[i][k]+=dp[i-1][(k+13-x)%13];
					dp[i][k]%=MOD;
				}
			}	
		}else{
			v=v*(s[i-1]-'0')%13;
			FOR(j,13){
				dp[i][j]=dp[i-1][(j+13-v)%13];
			}
		}
		
	}
	cout << dp[(int)s.size()][5] << endl;
}

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


int main(){
    ll k;
    cin >> k;
    queue<ll> lun;
    rep(i,9){
        lun.push(i+1);
    }
    ll x, cnt=0;
    while(cnt<k){
        x = lun.front();
        lun.pop();
        // cout << x << ' ';
        for(int j=-1;j<=1;j++){
            ll d = x%10 +j;
            if(0<=d and d<=9){
                lun.push(x*10+d);
                // cout << x*10+d << ' ';
            }
        }
        // cout << "\n";
        cnt +=1;
    }
    cout << x << endl;
    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define erep(i,a,b) for(int i=a;i<=(int)(b);++i)
#define per(i,a,b) for(int i=(b);i>(a);--i)
#define eper(i,a,b) for(int i=((int)(a));i>=b;--i)
#define pb push_back
#define mp make_pair
#define INF (1<<31)-1
#define MOD 1000000007
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
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 dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a, b)*b;}

int sx, sy, gx, gy;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
    cin >> sx >> sy >> gx >> gy;
    string ans = "";
    int a = gx-sx, b = gy-sy;
    rep(i, 0, a) ans += "R";
    rep(i, 0, b) ans += "U";
    rep(i, 0, a) ans += "L";
    rep(i, 0, b) ans += "D";
    ans += "D";
    a++, b++;
    rep(i, 0, a) ans += "R";
    rep(i, 0, b) ans += "U";
    ans += "LU";
    rep(i, 0, a) ans += "L";
    rep(i, 0, b) ans += "D";
    ans += "R";
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    long[] A = new long[N];
    long[] B = new long[N];
    for (int i = 0; i < N; i++) {
      A[i] = sc.nextLong();
      B[i] = sc.nextLong();
    }
    long ans = 0;
    for (int i = N - 1; i >= 0; i--) {
      A[i] += ans;
      long tmp = 0;
      if (A[i] % B[i] != 0) {
        tmp = B[i] - (A[i] % B[i]);
      }
      ans += tmp;
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 88656