akhauriyash/Code-Regression huggingface dataset:
import java.util.*;

public class Main {
  public static void main(String args[]) {
    Scanner sc = new Scanner(System.in);
    int A = sc.nextInt(), B = sc.nextInt(), K = sc.nextInt();
    int total = B + 1 - A;
    
    if(total<=K*2) {
      for(int i=A; i<=B; i++) {
      System.out.println(i);
      } 
    } else {
      for(int j=A; j<A+K; j++) {
        System.out.println(j);
      }
      int C = B-K+1;
      for(int k=C; k<C+K; k++) {
        System.out.println(k);
      }
      
    }
  }
}

Measured memory_bytes: 23124
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define yorn(f) cout<<((f)?"Yes":"No")<<endl;
#define YORN(f) cout<<((f)?"YES":"NO")<<endl;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, n) for (int i = 1; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define put(x) cout << x << endl;
#define println(x) cout << x << endl;
using namespace std;
signed main()
{
    ld l;
    cin >> l;
    l /= 3;
    printf("%.12Lf\n", l * l * l); 
    return 0;
}

Measured memory_bytes: 3756
#include <algorithm>
#include <iostream>

using namespace std;

int main() {
  int n, k;
  int l[50];
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    cin >> l[i];
  }
  sort(l, l + n, greater<int>());
  int ans = 0;
  for (int i = 0; i < k; i++) {
    ans += l[i];
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3188
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    // 文字列の入力
    String s = sc.next();
    String t = sc.next();

    if (t.substring(0, s.length()).equals(s) && t.length() == s.length() + 1) {

      System.out.println("Yes");
    } else {

      System.out.println("No");
    }
  }
}


Measured memory_bytes: 35708
def solve(a, b, c):
    # a + b + 2 * sqrt(a*b) < c
    # 4 * a * b < (c - a - b) ** 2
    if c < a + b:
        return "No"
    if 4 * a * b < (c - a - b) ** 2:
        return "Yes"
    else:
        return "No"


def main():
    a, b, c = map(int, input().split())
    res = solve(a, b, c)
    print(res)


def test():
    assert solve(2, 3, 9) == "No"
    assert solve(2, 3, 10) == "Yes"


if __name__ == "__main__":
    test()
    main()


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

long long N;
long long a[100005];
long long ans[100005];
//     val   , num
map<long long, long long> memo;
//        pos
vector<long long> V;

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

	V.push_back(0);
	for(long long i = 1; i < N; i++){
		if(a[V.back()] < a[i]){
			V.push_back(i);
		}
	}

	for(long long i = V.size() - 2; i >= 0; i--){
		while(memo.rbegin()->first > a[V[i]]){
			ans[V[i+1]] += (memo.rbegin()->first - a[V[i]])*memo.rbegin()->second;
			memo[a[V[i]]] += memo.rbegin()->second;
			memo.erase(memo.rbegin()->first);
		}
	}
	for(auto m : memo){
		ans[0] += m.first * m.second;
	}
	//ans[V[0]] += memo.begin()->second;

	for(long long i = 0; i < N; i++){
		cout << ans[i] << endl;
	}
}


Measured memory_bytes: 9720
#include <bits/stdc++.h>
#define int long long
#define ll long long
using ull = unsigned long long;
using namespace std;
#define dump(x)                             \
    if (dbg) {                              \
        cerr << #x << " = " << (x) << endl; \
    }
#define overload4(_1, _2, _3, _4, name, ...) name
#define FOR1(n) for (ll i = 0; i < (n); ++i)
#define FOR2(i, n) for (ll i = 0; i < (n); ++i)
#define FOR3(i, a, b) for (ll i = (a); i < (b); ++i)
#define FOR4(i, a, b, c) for (ll i = (a); i < (b); i += (c))
#define FOR(...) overload4(__VA_ARGS__, FOR4, FOR3, FOR2, FOR1)(__VA_ARGS__)
#define FORR(i, a, b) for (int i = (a); i <= (b); ++i)
#define bit(n, k) ((n >> k) & 1) /*nのk bit目*/
namespace mydef {
const int INF = 1ll << 60;
const int MOD = 1e9 + 7;
template <class T>
bool chmin(T& a, const T& b) {
    if (a > b) {
        a = b;
        return 1;
    } else
        return 0;
}
template <class T>
bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return 1;
    } else
        return 0;
}
void Yes(bool flag = true) {
    if (flag)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}
void No(bool flag = true) {
    Yes(!flag);
}
void YES(bool flag = true) {
    if (flag)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
}
void NO(bool flag = true) {
    YES(!flag);
}
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T& val) {
    std::fill((T*)array, (T*)(array + N), val);
}
bool dbg = false;
}  // namespace mydef
using namespace mydef;
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(), (v).end()
#define SZ(x) ((int)(x).size())
#define vi vector<int>
#define vvi vector<vector<int>>
#define vp vector<pair<int, int>>
#define vvp vector<vector<pair<int, int>>>
#define pi pair<int, int>
//#define P pair<int, int>
//#define V vector<int>
//#define S set<int>
#define asn ans


void solve() {
}

signed main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    string N;
    cin >> N;
    int n = N[N.size() - 1] - '0';
    if (n == 3) {
        cout << "bon" << endl;
    } else if (n == 0 || n == 1 || n == 6 || n == 8) {
        cout << "pon" << endl;
    } else
        cout << "hon" << endl;


    solve();
    return 0;
}


Measured memory_bytes: 3644
#include <bits/stdc++.h>
#define inf (long long)1e13
using namespace std;

long long n, k;
vector<long long> h;
long long dp[500][500][500] = {0};

long long solve();

int main() {
  cin >> n >> k;
  h.resize(n);
  for(int i = 0; i < n; ++i) cin >> h[i];
  cout << solve() << endl;
  return 0;
}

long long solve() {
  long long ans = inf;
  for(int i = 0; i <= n; ++i)
    for(int j = 0; j <= n; ++j)
      for(int l = 0; l <= k; ++l) dp[i][j][l] = inf;
  dp[0][0][k] = 0;
  for(int i = 0; i < n; ++i)
    for(int j = 0; j <= i; ++j)
      for(int l = 0; l <= k; ++l) {
        // not use
        long long now = h[i];
        if(j > 0) now = max(0LL, h[i] - h[j - 1]);
        dp[i + 1][i + 1][l] =
            min(dp[i + 1][i + 1][l], dp[i][j][l] + now);
        // use
        if(l < k)
          dp[i + 1][j][l] =
              min(dp[i + 1][j][l], dp[i][j][l + 1]);
      }
  for(int i = 0; i <= n; ++i)
    for(int j = 0; j <= k; ++j) ans = min(ans, dp[n][i][j]);
  return ans;
}


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

using namespace std;

int main()
{

    long long int a, v, b, w, t;
    cin >> a >> v >> b >> w >> t;

    if (w - v >= 0)
    {
        cout << "NO" << endl;
        return 0;
    }
    else
    {
        long long int d = v - w;
        if (abs(a - b) <= d * t)
        {
            cout << "YES" << endl;
        }
        else
        {
            cout << "NO" << endl;
        }
    }

    return 0;
}

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

int main() {
    string n;
    cin >> n;
    cout << count(n.begin(), n.end(), '2') << endl;
}


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

int main(){
  long long n,k;
  long long a[100000];
  cin >> n >> k;

  int zp = -1;
  for(int i = 0;i < n;i++){
    cin >> a[i];
  }

  long long ans = LLONG_MAX;
  for(int i = 0;i+k-1 < n;i++){
    if((a[i] < 0 && a[i+k-1] > 0) || (a[i] > 0 && a[i+k-1] < 0)){
      ans = min(ans,min(llabs(a[i]),llabs(a[i+k-1]))*2+max(llabs(a[i]),llabs(a[i+k-1])));
    }else if(a[i] < 0){
      ans = min(ans,llabs(a[i]));
    }else{
      ans = min(ans,llabs(a[i+k-1]));
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <numeric>
#include <cmath>

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

int mx8[] = {0,0,1,-1,-1,1,-1,1};
int my8[] = {-1,1,0,0,-1,-1,1,1};
int mx4[] = {1,-1,0,0};
int my4[] = {0,0,-1,1};
const int MOD = 1000000007;


int main(){
    ll x, k, d;
    cin >> x >> k >> d;
    x = abs(x);

    ll s = x / d;
    if(s >= k){cout << x - d * k << endl; return 0;}

    ll MIN_right = x - d * s;
    if((k - s) % 2 == 0){
        cout << MIN_right << endl;
    }else{
        cout << abs(MIN_right-d) << endl;
    }
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
#define int long long
#define P(x) {if (debug) cout << x << endl;}
#define H(x) P(#x << ": " << (x))
#define FR(i,a,b) for (int i=(a); i<(b); i++)
#define F(i,n) FR(i,0,n)
#define DR(i,a,b) for (int i=(b); i-->(a);)
#define D(i,n) DR(i,0,n)
#define S(s) (int)(s).size()
#define ALL(v) v.begin(), v.end()
#define MI(a,v) a = min(a,v)
#define MA(a,v) a = max(a,v)
#define V vector
#define pb push_back
#define mt make_tuple
using namespace std;
template<class T> ostream &operator<<(ostream &os, V<T> v) {
    F(i,S(v)) os<<(i?" ":"")<<v[i];
    return os;
}
const bool debug = 1;
const int M=1e6+3;

V<int> fact;

void euclid(int a, int b, int &x, int &y, int &d) {
    if (b == 0) x=1, y=0, d=a;
    else euclid(b, a%b, y, x, d), y -= a/b*x;
}

int inv(int a, int m=M) { // a^-1 (mod m)
    int x,y,d; euclid(a,m,x,y,d);
    return (x + m) % m;
}
int ipow(int a, int b) {
    if (b == 0) return 1;
    int rt = ipow(a, b/2);
    (rt *= rt) %= M;
    return b%2 ? (rt*a)%M : rt;
}
int safeMod(int n) {
    return (n%M+M)%M;
}

int ans(int x, int d, int n) {
    if (d == 0)
        return ipow(x, n);
    int a = (x * inv(d)) % M;
    if (a == 0 || a+n-1 >= M)
        return 0;
    return ipow(d,n) * fact[a+n-1] % M * inv(fact[a-1]) % M;
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    fact.resize(M);
    fact[0] = 1;
    FR(i,1,M) fact[i] = fact[i-1] * i % M;
    int nq; cin>>nq;
    F(qq,nq) {
        int x,d,n; cin>>x>>d>>n;
        cout<<ans(x,d,n)<<"\n";
    }
}

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

int descending_compare(const void *a, const void *b){
    if (*(int*)a > *(int*)b){
        return -1;
    }else if (*(int*)a == *(int*)b){
        return 0;
    }else{
        return 1;
    }
}

int ascending_compare(const void *a, const void *b){
    if (*(int*)a < *(int*)b){
        return -1;
    }else if (*(int*)a == *(int*)b){
        return 0;
    }else{
        return 1;
    }
}


int lower_bound(int *a, int n, int key){
    int left, mid, right;
    left = 0, right = n;
    mid = (left + right)/2;
    while ((left+1 != mid || mid+1 != right) && mid != left){
        if (key > a[mid]){
            left = mid;
        }else{
            right = mid+1;
        }
        mid = (left + right)/2;
    }
    if (a[left] >= key)return left;
    if (a[mid] >= key)return mid;
    if (a[right] >= key)return right;
    return n;
}

//greatest common divisor
unsigned long gcd(unsigned long x, unsigned long y){
    if (y == 0){ 
        return x;
    }else if (x > y){
        return gcd(y, x % y);
    }else{
        return gcd(x, y % x);
    }
}

unsigned long lcm(unsigned long x, unsigned long y){
    unsigned long g = gcd(x, y);
    return x*y/g;

}



long long factorial(int x){
    long long rtn = 1;
    int i;
    for (i = x; i > 1; i--){
        rtn = (rtn*i);
    }
    return rtn;
}
char s[100005];

int main(void){
    scanf("%s", s);
    char keyword[4][10] = {"remaerd", "resare", "maerd", "esare"};
    int len[4];
    for (int i = 0; i < 4; i++){
        len[i] = strlen(keyword[i]);
    }

    int i = strlen(s) - 1;
    while (i >= 0){
        int now = i;
        for (int j = 0 ; j < 4; j++){
            int flag = 1;
            if (len[j]-1 > i){
                continue;
            }
            for (int k = 0; k < len[j]; k++){
                if (keyword[j][k] != s[i-k]){
                    flag = 0;
                    break;
                }
            }
            if (flag == 1){
                i -= len[j];
                break;
            }
        }
        if (now == i){
            break;
        }
    }

    if (i == -1){
        printf("YES\n");
    }else{
        printf("NO\n");
    }
    
}

Measured memory_bytes: 256
#include <algorithm>
#include <deque>
#include <iostream>
#include <map>
#include <math.h>
#include <string.h>
#include <vector>

using namespace std;
int main() {
    int A,B;
    cin >> A >> B;
    cout << (A<=8&&B<=8 ? "Yay!" : ":(" ) << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        String line = sc.nextLine();
        String[] line1 = line.split(" ");
        int a = Integer.parseInt(line1[0]);
        int b = Integer.parseInt(line1[1]);
        if(a < 10 && b < 10)    System.out.println(a * b);
        else System.out.println(-1);
    }
}

Measured memory_bytes: 22996
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define re register
#define gc get_char
#define pc putchar 
#define cs const

cs int N=2003;
vector<int> edge[N];
inline void addedge(int u,int v){
	edge[u].push_back(v);
	edge[v].push_back(u);
}

int cnt,ans=0x7fffffff;
int lim;

void dfs(int u,int fa,int dep){
	if(dep>lim/2)++cnt;
	for(int re e=0,v;e<edge[u].size();++e){
		v=edge[u][e];
		if(v^fa)dfs(v,u,dep+1);
	}
}

int n;
signed main(){
	scanf("%d%d",&n,&lim);
	for(int re i=1;i<n;++i){
		int u,v;
		scanf("%d%d",&u,&v);
		addedge(u,v);
	}
	if(lim&1){
		for(int re u=1;u<=n;++u)
		for(int re e=0;e<edge[u].size();++e){
			cnt=0;dfs(u,edge[u][e],0);
			dfs(edge[u][e],u,0);
			ans=min(ans,cnt);
		}
	}
	else {
		for(int re i=1;i<=n;++i){
			cnt=0;
			dfs(i,0,0);
			ans=min(ans,cnt);
		}
	}
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define int long long
#define ll long long
using ull = unsigned long long;
using namespace std;
#define dump(x)                             \
    if (dbg) {                              \
        cerr << #x << " = " << (x) << endl; \
    }
#define overload4(_1, _2, _3, _4, name, ...) name
#define FOR1(n) for (ll i = 0; i < (n); ++i)
#define FOR2(i, n) for (ll i = 0; i < (n); ++i)
#define FOR3(i, a, b) for (ll i = (a); i < (b); ++i)
#define FOR4(i, a, b, c) for (ll i = (a); i < (b); i += (c))
#define FOR(...) overload4(__VA_ARGS__, FOR4, FOR3, FOR2, FOR1)(__VA_ARGS__)
#define FORR(i, a, b) for (int i = (a); i <= (b); ++i)
#define bit(n, k) ((n >> k) & 1) /*nのk bit目*/
namespace mydef {
const int INF = 1ll << 60;
const int MOD = 1e9 + 7;
template <class T>
bool chmin(T& a, const T& b) {
    if (a > b) {
        a = b;
        return 1;
    } else
        return 0;
}
template <class T>
bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return 1;
    } else
        return 0;
}
void Yes(bool flag = true) {
    if (flag)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}
void No(bool flag = true) {
    Yes(!flag);
}
void YES(bool flag = true) {
    if (flag)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
}
void NO(bool flag = true) {
    YES(!flag);
}
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T& val) {
    std::fill((T*)array, (T*)(array + N), val);
}
bool dbg = true;
}  // namespace mydef
using namespace mydef;
#define pb push_back
//#define mp make_pair
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(), (v).end()
#define SZ(x) ((int)(x).size())
#define vi vector<int>
#define vvi vector<vector<int>>
#define vp vector<pair<int, int>>
#define vvp vector<vector<pair<int, int>>>
#define pi pair<int, int>
//#define P pair<int, int>
//#define V vector<int>
//#define S set<int>
#define asn ans


void solve() {
}

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

    string S;
    cin >> S;
    int ans = S.size();

    for (auto c : S) {
        int tmp = 0;
        for (int i = 0; i < S.size();) {
            int j = i;
            while (j < S.size() && !(S[i] != c ^ S[j] != c))
                j++;
            if (S[i] != c)
                chmax(tmp, j - i);
            i = j;
        }
        chmin(ans, tmp);
    }

    cout << ans << endl;

    solve();
    return 0;
}


Measured memory_bytes: 3576
#include <algorithm>
#include <iostream>
#include <queue>
#include <string>
#include <vector>
#include <math.h>

using namespace std;

#define INF 210000000
#define int long long

static long long gcd(long long a, long long b) {
  int amari = a % b;
  int c = b;
  if (amari == 0) {
    return b;
  } else {
    return gcd(b, amari);
  }
}

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

signed main() {
    int n,m,x;
    cin >> n >> m >> x;
    vector<int> a;
    int ans = 0;
    for(int i=0;i<m;i++){
        int tmp;
        cin >> tmp;
        if(tmp > x){
            ans++;
        }
        a.push_back(tmp);
    }
    if(m < ans * 2){
        cout << m - ans;
    }else{
        cout << ans;
    }
}



Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <set>
#include <map>
#include <algorithm>

#define int long long
#define MOD7 1000000007
#define MOD9 1000000009

#define rep(i, n) for (int i = 0; i < (n); i++)
#define REP(i, a, n) for (int i = (a); i <= (n); i++)
#define all(a) (a).begin(), (a).end()

using namespace std;

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

int nextInt() {int a; cin >> a; return a;}
char nextChar() {char a; cin >> a; return a;}
double nextDouble() {double a; cin >> a; return a;}
string nextString() {string a; cin >> a; return a;}

void inputVector(vector<int> &v, int &n) {rep(i,n){v.push_back(nextInt());}}
void inputVector(vector<double> &v, int &n) {rep(i,n){v.push_back(nextDouble());}}
void inputVector(vector<string> &v, int &n) {rep(i,n){v.push_back(nextString());}}

signed main() {
    int n, m;
    while (cin >> n >> m) {
	if (!n) break;
	vector<int> a, b;
	inputVector(a, n);
	inputVector(b, m);

	int suma = 0;
	int sumb = 0;
	rep(i, n) suma += a[i];
	rep(i, m) sumb += b[i];

	int mina = -1;
	int minb = -1;
	rep(i, n) {
	    rep(j, m) {
		if ((a[i] - b[j]) * 2 != suma - sumb) continue;
		if (mina == -1 || a[i] + b[j] < mina + minb) {
		    mina = a[i];
		    minb = b[j];
		}
	    }
	}
	if (mina == -1) cout << -1 << endl;
	else cout << mina << " " << minb << endl;
    }

    return 0;
}

Measured memory_bytes: 3104
n=int(input())
x=[]
y=[]
a=0
for _ in range(n):
    x1,y1=input().split()
    x.append(x1)
    y.append(y1)
for i in range(n):
    if y[i]=="JPY":
        a+=int(x[i])
    elif y[i]=="BTC":
        a+=float(x[i])*380000.0
print(a)

Measured memory_bytes: 3060
#include<stdio.h>
#include<iostream>
#include<vector>
#include<math.h>
#include<queue>
#include<map>
#include<algorithm>
#include<string.h>
#include<functional>
#include<limits.h>
#include<stdlib.h>
#include<string>
#include<unordered_map>
#include<set>
using namespace std;

#define intmax INT_MAX
#define lmax LONG_MAX
#define uintmax UINT_MAX
#define ulmax ULONG_MAX
#define llmax LLONG_MAX
#define ll long long
#define rep(i,a,N) for((i)=(a);(i)<(N);(i)++)
#define rrp(i,N,a) for((i)=(N)-1;(i)>=(a);(i)--)
#define llfor ll i,j,k
#define sc(a) cin>>a
#define pr(a) cout<<a<<endl
#define pY puts("YES")
#define pN puts("NO")
#define py puts("Yes")
#define pn puts("No")
#define pnn printf("\n")
#define sort(a) sort(a.begin(),a.end())
#define push(a,b) (a).push_back(b)
#define llvec vector<vector<ll>>
#define charvec vector<vector<char>>
#define sizeoof(a,b) (a,vector<ll>(b))
#define llpvec vector<pair<ll,ll>>
/*繰り上げ除算*/ll cei(ll x,ll y){ll ans=x/y;if(x%y!=0)ans++;return ans;}
/*最大公約数*/ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
/*最小公倍数*/ll lcm(ll x,ll y){return x/gcd(x,y)*y;}
/*n乗*/ll llpow(ll x,ll n){ll i,ans=1;rep(i,0,n)ans*=x;return ans;}
/*階乗*/ll fact(ll x){ll i,ans=1;rep(i,0,x)ans*=(x-i);return ans;}
/*nCr*/ll ncr(ll n,ll r){return fact(n)/fact(r)/fact(n-r);}
/*nPr*/ll npr(ll n,ll r){return fact(n)/fact(n-r);}
/*primejudge*/bool prime(ll a){if(a<=1)return false;ll i;for(i=2;i*i<=a;i++){if(a%i==0)return false;}return true;}
llfor;///////////////////////////////////////////////////////////
ll a[100010];
bool ex[100010];
ll ans=0;

void light(ll x){
 //pr(x);
 if(x==1)return;
 if(ex[x]==true){
  ans=-1;return;
 }
 ans++;
 ex[x]=true;
 light(a[x]-1);
}

int main(){
 ll n;sc(n);
 ans=0;
 bool flag=false;
 rep(i,0,n){
  ex[i]=false;
  sc(a[i]);
  if(a[i]==2)flag=true;
 }
 if(flag)light(0);
 else ans=-1;
 pr(ans);
return 0;}

Measured memory_bytes: 4472
using System;
using System.Linq;
using System.Collections.Generic;

public class Hello
{
    static void Main()
    {
        string s_num = Console.ReadLine();
        char[] c_num = s_num.ToCharArray();

        for(int i = 0; i < c_num.Length; i++)
        {
            if (c_num[i] == '1') c_num[i] = '9';
            else if (c_num[i] == '9') c_num[i] = '1';
        }

        Console.WriteLine(new String(c_num));
    }
}

Measured memory_bytes: 11092
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.ArrayDeque;
import java.util.NoSuchElementException;
import java.util.PriorityQueue;
import java.util.Queue;

public class Main {
	int N,K;
	int[] alpha;

	private class P implements Comparable<P>{
		int a,b;
		public P(int a,int b){
			this.a = a;
			this.b = b;
		}
		public int compareTo(P p){
			return p.b - this.b;
		}
	}

	public void solve() {
		N = nextInt();
		K = nextInt();
		alpha = new int[26];
		for(int i = 0;i < N;i++){
			alpha[next().charAt(0) - 'A']++;
		}

		PriorityQueue<P> pq = new PriorityQueue<P>();
		Queue<P> tmp = new ArrayDeque<P>();
		for(int i = 0;i < 26;i++)pq.add(new P(i,alpha[i]));
		int k = 0;
		int cnt = 0;
		int bit = 0;
		while(pq.size() > 0){
			P p = pq.poll();
			if(p.b == 0)continue;

			if(((bit >> p.a)&1) == 1){
				tmp.add(p);
				continue;
			}
			bit |= (1 << p.a);
			cnt++;
			if(cnt == K){
				k++;
				cnt = 0;
				bit = 0;
				while(tmp.size() > 0){
					pq.add(tmp.poll());
				}
			}
			pq.add(new P(p.a,p.b - 1));
		}

		out.println(k);
	}

	public static void main(String[] args) {
		out.flush();
		new Main().solve();
		out.close();
	}

	/* Input */
	private static final InputStream in = System.in;
	private static final PrintWriter out = new PrintWriter(System.out);
	private final byte[] buffer = new byte[2048];
	private int p = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (p < buflen)
			return true;
		p = 0;
		try {
			buflen = in.read(buffer);
		} catch (IOException e) {
			e.printStackTrace();
		}
		if (buflen <= 0)
			return false;
		return true;
	}

	public boolean hasNext() {
		while (hasNextByte() && !isPrint(buffer[p])) {
			p++;
		}
		return hasNextByte();
	}

	private boolean isPrint(int ch) {
		if (ch >= '!' && ch <= '~')
			return true;
		return false;
	}

	private int nextByte() {
		if (!hasNextByte())
			return -1;
		return buffer[p++];
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = -1;
		while (isPrint((b = nextByte()))) {
			sb.appendCodePoint(b);
		}
		return sb.toString();
	}

	public int nextInt() {
		return Integer.parseInt(next());
	}

	public long nextLong() {
		return Long.parseLong(next());
	}

	public double nextDouble() {
		return Double.parseDouble(next());
	}
}

Measured memory_bytes: 11360
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vll = vector<long long>;
using vp = vector<pair<int, int>>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvll = vector<vector<long long>>;
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 (b<a) {a=b; return 1;} return 0;}

const int mod = 1000000007;
// const int mod = 998244353;
struct mint {
    long long x;
    mint(long long x=0) : x((x % mod + mod) % mod) {}
    mint operator-() const { return mint(-x);}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
    mint operator+(const mint a) const { return mint(*this) += a;}
    mint operator-(const mint a) const { return mint(*this) -= a;}
    mint operator*(const mint a) const { return mint(*this) *= a;}
    mint pow(long long t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    mint inv() const { return pow(mod-2);}
    mint& operator/=(const mint a) { return *this *= a.inv();}
    mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n;
    cin >> n;
    string s, t;
    cin >> s >> t;
    vi a;
    rep(i, n) {
        if (s[i] == s[i+1]) {
            a.pb(0);
            i++;
        } else {
            a.pb(1);
        }
    }
    mint ans = 1;
    rep(i, sz(a)) {
        if (i == 0) {
            if (a[i] == 0) {
                ans *= 3 * 2;
            } else {
                ans *= 3;
            }
        } else {
            if (a[i-1] == 0 && a[i] == 0) {
                ans *= 3;
            } else if (a[i-1] == 0 && a[i] == 1) {
                ans *= 1;
            } else if (a[i-1] == 1 && a[i] == 0) {
                ans *= 2;
            } else if (a[i-1] == 1 && a[i] == 1) {
                ans *= 2;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main()
{
  int d, sort, x, y;

  scanf("%d %d", &x, &y);

  while(1){   
     if(y >= x){
    sort = x;
    x = y;
    y = sort;
  }
          if(y == 0){
       printf("%d\n", x);
       break;
     }
     x = x % y;

  }

  return 0;
}
  



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

using namespace std;

const int mod=1e9+7;
const string sp=" ";

void run();

void init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(12);
}

signed main(){
    init();
    run();
    return 0;
}

void run(){
    int a,b;
    cin>>a>>b;
    if((a+b)%2)cout<<"IMPOSSIBLE"<<endl;
    else cout<<(a+b)/2<<endl;
}

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

int main() {
	int N;
  	cin >> N;
  	string s;
  	cin >> s;
  	int count=0;
  	for(int i=0;i<N-2;i++){
      if(s.at(i) =='A' &&s.at(i+1) =='B' &&s.at(i+2) =='C')count++;
	}
	cout<<count<<endl;
}


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

int main(){
  int n;
  vector<long> lucas(87,0);
  lucas.at(0) = 2;
  lucas.at(1) = 1;
  cin >> n;
  for(int i = 2; i<=n; i++)
    lucas.at(i) = lucas.at(i-1) + lucas.at(i-2);
  cout << lucas.at(n) << endl;
    
}

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

#define ll long long
#define endl '\n'
#define REP(i, a, n) for(int i=a; i<n; ++i)
#define pb push_back
#define sz(x) (int)((x).size())
#define all(x) (x).begin(), (x).end()

typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

const double PI = 3.141592653589793238460;
const ll mod = 1e9+7;

void FAST(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
}

bool comp(const pair<int, int> &a, const pair<int, int> &b){
  return (a.first > b.second);
}
int main(){
  FAST();
  //Code goes past here:
  int k;
  string s;
  cin >> k >> s;

  if(s.length() <= k)
    cout << s << endl;
  else{
    string ans(s.begin(), s.begin() + k);
    ans += "...";
    cout << ans << endl;
  }

  return 0;
}


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

int main() {
    // input
    int n, m;
    cin >> n >> m;
    int a[n], b, c;
    vector<pair<int, int> > cb(m);
    rep(i, n) cin >> a[i];
    rep(i, m) {
        cin >> b >> c;
        cb[i] = make_pair(c, b);
    }    
    sort(a, a + n);
    sort(cb.begin(), cb.end());
    reverse(cb.begin(), cb.end());

    // solve
    int idx = 0;
    bool fin = false;
    rep(i, m) {
        rep(j, cb[i].second) {
            if (a[idx] < cb[i].first) {
                a[idx++] = cb[i].first;
            } else {
                fin = true;
            }
            if (idx >= n) fin = true;
            if (fin) break;
        }
        if (fin) break;
    }
    ll ans = accumulate(a, a + n, 0L);
    cout << ans << endl;
}

Measured memory_bytes: 1408
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define int long long
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF (LLONG_MAX - 1e5)
#define fcout cout << fixed << setprecision(10)

using namespace std;

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    double T, X;
    cin >> T >> X;
    fcout << T / X << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <map>
#include <queue>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using T = tuple<int, int, int>;
const int iINF = 1001001001;
const long long llINF = 1LL << 60;
vector<ll> sum, p;
ll rec(ll n, ll x)
{
	if (n == 0) return x <= 0 ? 0 : 1;
	else if (x <= 1 + sum[n - 1]) return rec(n - 1, x - 1);
	else return p[n - 1] + 1 + rec(n - 1, x - sum[n - 1] - 2);
}
int main()
{
	// ABC115-D, 1084, 20:46(UNSOLVED),
	ll n, x; cin >> n >> x;
	sum.resize(n); p.resize(n);
	sum[0] = p[0] = 1;
	for (int i = 1; i < n; ++i) {
		sum[i] = sum[i - 1] * 2 + 3;
		p[i] = p[i - 1] * 2 + 1;
	}
	cout << rec(n, x) << endl;
	return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> lpair;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define print2(x,y) cout << (x) << " " << (y) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " ";} cout<<endl;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    ll d[100010];
    rep(i,0,N) cin >> d[i];
    sort(d, d+N);
    ll ans = 0;
    ll v = d[N/2] - d[N/2-1];
    print(v);
    
}

Measured memory_bytes: 1024
import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, core.stdc.stdio;

void main() {
    auto N = readln.chomp.to!int;
    auto A = readln.split.map!(to!int).array;

    if (N % 3 != 0) {
        writeln(A.map!(a => a == 0).all ? "Yes" : "No");
    } else {
        int[int] cnt;
        foreach (a; A) cnt[a] += 1;
        int[] B;
        foreach (k, v; cnt) {
            if (v % (N / 3) != 0) {
                writeln("No");
                return;
            }
            while (v > 0) {
                B ~= k;
                v -= N / 3;
            }
        }
        if (B.length != 3) {
            writeln("No");
            return;
        }
        if (B[0] != (B[1] ^ B[2])) {
            writeln("No");
            return;
        }
        writeln("Yes");
    }
}


Measured memory_bytes: 9360
#include<bits/stdc++.h>
using namespace std;priority_queue<pair<int,int> >Q;int n,q,a,b,d[1000010];int main(){cin>>n>>q;a=n;while(a--)Q.push(make_pair(0,a)),d[a]=0;while(q--){cin>>a>>b;a=n-a,d[a]+=b;Q.push(make_pair(d[a],a));while(1){a=Q.top().first,b=Q.top().second;if(d[b]==a){cout<<n-b<<" "<<a<<endl;break;}Q.pop();}}return 0;}

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

int f(int n){
 if(n % 2 == 0) return n / 2;
  else return 3 * n + 1;
}

int main(void){
  string S;
  cin >> S;
  for(int i = 0; i < S.length(); i++){
    if(S[i] == '1') cout << '9';
    else if (S[i] == '9') cout << '1';
    else cout << S[i];
  }
  return 0;
}

Measured memory_bytes: 256
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define ll long long
#define N 100010
#define M 1010

using namespace std;
int n, m, cnt;
int fath[N];

int read() {
	int s = 0, f = 0; char ch = getchar();
	while (!isdigit(ch)) f |= (ch == '-'), ch = getchar();
	while (isdigit(ch)) s = s * 10 + (ch ^ 48), ch = getchar();
	return f ? -s : s;
}

int father(int x) {
	if (x != fath[x]) fath[x] = father(fath[x]);
	return fath[x];
}

int main() {
	n = read(), m = read();
	for (int i = 1; i <= n; i++) fath[i] = i;
	for (int i = 1, x, y; i <= m; i++) {
		x = read(), y = read();
		int fx = father(x), fy = father(y);
		if (fx != fy) {
			cnt++;
			fath[fx] = fy;
		}
	}
	n--;
	if (cnt == n) puts("0");
	else cout << n - cnt << "\n";
}

Measured memory_bytes: 3612
#include <iostream>
#include <math.h>
using namespace std;
 
int main(){
  double x;
  cin>>x;
  int i=0;
  double a=100;
  while(a<x){
    a=floor(a*1.01);
    i+=1;
  }
  cout << i<<endl;
  return 0;
}

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


int main() {
    int x;
    cin >> x;
    if(x < 30){
        cout << "No" << endl;
    }
    else{
        cout << "Yes" << endl;
    }

    return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define INF 1.0e9
using namespace std;
typedef long long ll;

string S, T;

int main() {
    cin >> S >> T;
    int size = S.length();
    map<char, char> mp_S;
    map<char, char> mp_T;
    bool f = true;
    for (int i = 0; i < size; i++) {
        mp_S[S[i]] = T[i];
        mp_T[T[i]] = S[i];
    }
    for (int i = 0; i < size; i++) {
        if (mp_S[S[i]] != T[i]) {
            f = false;
            break;
        }
        else if (mp_T[T[i]] != S[i]) {
            f = false;
            break;
        }
    }
    if (f) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
    return 0;
}

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

int main(){
    int n,x;
    cin>>n>>x;
    vector<int> a(n);
    ll sum=0;
    rep(i,n){
        cin>>a[i];
        sum+=a[i];
    }
    sort(a.begin(),a.end());
    int cnt=0;
    
    if(sum==x) cout<<n<<"\n";
    else if(sum<x){
        rep(i,n){
            if(a[i]>x) break;
            else{
                cnt++;
                x-=a[i];
            }
        }
        cout<<cnt-1<<"\n";
    }
    else{
        rep(i,n){
            if(a[i]>x) break;
            else{
                cnt++;
                x-=a[i];
            }
        }
        cout<<cnt<<"\n";
    }
    return 0;
}

Measured memory_bytes: 3604
S=input()
T=input()
X=0
for i in range(len(S)):
    s=S[i]
    if ord(s)>96:
        X+=1
        S=S.replace(s,chr(X+47))
Y=0
for i in range(len(T)):
    t=T[i]
    if ord(t)>96:
        Y+=1
        T=T.replace(t,chr(Y+47))
print('Yes'if S==T else'No')

Measured memory_bytes: 3632
import itertools
from collections import deque,defaultdict,Counter
from itertools import accumulate
import bisect
from heapq import heappop,heappush
from fractions import gcd
from copy import deepcopy
import math
import queue
#import numpy as np
#import sympy as syp(素因数分解とか)
Mod = 1000000007
import sys

sys.setrecursionlimit(100000) 
  
def sieve_of_eratosthenes(n):
    if not isinstance(n,int):
        raise TypeError("n is not int")
    if n<2:
        raise ValueError("n is not effective")
    prime = [1]*(n+1)
    for i in range(2,int(math.sqrt(n))+1):
        if prime[i] == 1:
            for j in range(2*i,n+1):
                if j%i == 0:
                    prime[j] = 0
    res = []
    for i in range(2,n+1):
        if prime[i] == 1:
            res.append(i)
    return res

def factorial(i):
    if i == 1:
        return 1
    else:
        return i*factorial(i-1)
 
class UnionFind:
    def __init__(self,n):
        self.parent = [i for i in range(n+1)]
        self.rank = [0 for i in range(n+1)]
    
    def findroot(self,x):
        if x == self.parent[x]:
            return x
        else:
            y = self.parent[x]
            y = self.findroot(self.parent[x])
            return y
    
    def union(self,x,y):
        px = self.findroot(x)
        py = self.findroot(y)
        if px < py:
            self.parent[py] = px
        else:
            self.parent[px] = py
 
    def same_group_or_no(self,x,y):
        return self.findroot(x) == self.findroot(y)




def main(): #startline--------------------------------------------
    n,m = map(int,input().split())
    p = list(map(int,input().split()))
    xy = [list(map(int,input().split())) for i in range(m)]
    un = UnionFind(n)
    ans = 0
    for i in range(m):
        un.union(xy[i][0]-1,xy[i][1]-1)
    for i in range(n):
        if un.same_group_or_no(i,p[i]-1):
            ans += 1
    print(ans)
if __name__ == "__main__":
    main() #endline===============================================
    

Measured memory_bytes: 38112
import java.util.Scanner;


public class Main {
	
	public static void main(String[] args){
		final Scanner sc = new Scanner(System.in);
		
		final int N = sc.nextInt();
		
		for(int i = 0; i < N; i++){
			final int X = sc.nextInt();
			final int Y = sc.nextInt();
			final int W = sc.nextInt();
			final int H = sc.nextInt();
			
			if(X == 0 && Y == 0 && W == 0 && H == 0){
				break;
			}
			
			final int X2 = X + W;
			final int Y2 = Y + H;
			
			final int n = sc.nextInt();
			
			int count = 0;
			
			for(int j = 0; j < n; j++){
				int x = sc.nextInt();
				int y = sc.nextInt();
				
				if(X <= x && x <= X2 && Y <= y && y <= Y2){
					count++;
				}
			}
			
			System.out.println(count);
		}
		
	}
}	

Measured memory_bytes: 12000
#include <bits/stdc++.h>
#define int long long
const int MOD=1e9+7;
using pii=std::pair<int,int>;
using namespace std;

string s;
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> s;
    if(s[1] == 'B')
        s[1] = 'R';
    else
        s[1] = 'B';
    cout << s << "\n";
    return 0;
}

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

#define FOR(i, a, b) for(int i = a;i < b;i++)
#define For(i, a) FOR(i, 0, a)
#define REV(i, a, b) for(int i = b-1;i >= a;i--)
#define Rev(i, a) REV(i, 0, a)
#define REP(a) For(i, a)
#define DEBUG_PRINT(...) fprintf(stderr, __VA_ARGS__)

using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
typedef vector<int> vi;
void print_pair(pi a){
  cerr<<"("<<a.first<<", "<<a.second<<") ";
}
template<int T1, int T2>
void print_2d(int a[T1][T2], int x, int y){
  For(i, x){
    For(j, y){
      cerr<<a[i][j]<<" ";
    }
    cerr<<endl;
  }
}

template<typename T>
int sgn(T val){
  return (T(0)<val)-(val<T(0));
}

tuple<long long,long long,long long> egcd(long long a,long long b){
  if(a==0||b==0)return std::make_tuple(0LL,0LL,0LL);
  long long sa=sgn(a),sb=sgn(b);
  a=std::abs(a);b=std::abs(b);
  long long p=1,q=0,r=0,s=1;
  while(b>0){
    long long c=a/b;
    long long d;
    d=a;a=b;b=d%b;
    d=p;p=q;q=d-c*q;
    d=r;r=s;s=d-c*s;
  }
  return std::make_tuple(a,p*sa,r*sb);
}

long long inverse(long long a,long long m){
  auto b=egcd(a,m);
  if(std::get<0>(b)!=1)return 0;
  return (std::get<1>(b)<0)?std::get<1>(b)+m:std::get<1>(b);
}

long long factorial(long long a,long long m){
  long long ret=1;
  for (long long i = 1; i <= a; i++) {
    ret*=(i%m);
    ret%=m;
  }
  return ret;
}
long long partial_factorial(long long a,long long n,long long m){
  long long ret=1;
  for (long long i = 0; i < n; i++) {
    ret*=(a-i)%m;
    ret%=m;
  }
  return ret;
}
long long combination_prime(long long n,long long r,long long m){
  long long ret;
  long long fact_r=factorial(r,m);
  ret=inverse(fact_r,m);
  long long pfact_n=partial_factorial(n,r,m);
  ret*=pfact_n;
  ret%=m;
  return ret;
}
long long cache_cmb[1000000],cache_inv_fact[1000000];
bool cached=false;
long long combination_cached(long long n,long long r,long long m){
  if(cached==false){
    cached=true;
    cache_inv_fact[1]=1;
    for (long long i = 2; i <= n; i++) {
      cache_inv_fact[i]=(m-m/i)*cache_inv_fact[m%i]%m;
    }
    cache_cmb[0]=1;
    for (long long i = 1; i <= n/2; i++) {
      cache_cmb[i]=cache_cmb[i-1]*(n-i+1)%m*cache_inv_fact[i]%m;
    }
  }
  r=min(r,n-r);
  return cache_cmb[r];
}

ll N,A,B,K;
vector<pair<ll,ll> > pat;
const long long mod=998244353;
ll inv[300005],c[300005];
int main()
{
        ll n,a,b,k,ans=0;scanf("%lld%lld%lld%lld",&n,&a,&b,&k);
        inv[1]=1;for(ll i=2;i<=n;i++) inv[i]=(mod-mod/i)*inv[mod%i]%mod;
        c[0]=1;for(ll i=1;i<=n;i++) c[i]=c[i-1]*(n-i+1)%mod*inv[i]%mod;
        for(ll i=0,j;i<=n;i++)
        {
                if(a*i>k) break;
                if((k-a*i)%b==0) j=(k-a*i)/b; else continue;
                if(j>n) continue;
                ans+=combination_cached(n,i,mod)*combination_cached(n,j,mod)%mod,ans%=mod;
        }
        printf("%lld\n",ans);
        return 0;
}


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

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

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

int main() {
  ll n, m;
  string s, t;
  cin >> n >> m >> s >> t;

  ll ans = lcm(n, m);
  ll g = gcd(n, m);
  ll np = n / g;
  ll mp = m / g;

  rep(i, g) if (s[np * i] != t[mp * i]) ans = -1;
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 3728
import java.util.Map;
import java.util.Scanner;

public class Main {

    /**
     * 本処理を実行します。
     */
    public static void execute() {
        Scanner sc = new Scanner(System.in);

        int r = nextInt(sc);
        int g = nextInt(sc);

        int s = g - r;

        out(g + s);
    }

    /**
     * 次の標準入力をintで受け取ります。
     * @return 標準入力値(int)
     */
    public static int nextInt(Scanner sc) {
        return sc.nextInt();
    }

    /**
     * 次の標準入力をStringで受け取ります。
     * @return 標準入力値(String)
     */
    public static String nextString(Scanner sc) {
        return sc.next();
    }

    /**
     * 次の標準入力を指定回数分intで受け取ります。
     * @param n 取得回数
     * @return 取得した標準入力値の配列(int)
     */
    public static int[] nextInts(Scanner sc, int n) {
        int[] arr = new int[n];

        for (int i = 0; i < n; i++) {
            arr[i] = nextInt(sc);
        }

        return arr;
    }

    /**
     * 標準出力にオブジェクトを出力します。
     * @param o 出力対象
     */
    public static void out(Object o) {
        System.out.println(o);
    }

    public static void main(String[] args) {
        execute();
    }

    public static void putCountMap(Map<Integer, Integer> map, int value) {
        if (map.containsKey(value)) {
            map.put(value, map.get(value) + 1);
        } else {
            map.put(value, 1);
        }
    }
}



Measured memory_bytes: 23124
//
//  abc148_e.cpp
//  learningCplusplus
//
//  Created by Tran Duc Chinh on 2020/04/04.
//  Copyright © 2020 Tran Duc Chinh. All rights reserved.
//

#include <iostream>
#include <queue>
#include <map>
#include <algorithm>
#include <math.h>
using namespace std;
typedef long long ll;
ll mod = 1000000007;
ll INF = 1000000007;
#define PI 3.14159265

const int MAX = 110000;

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

std::vector<int> permutations;

int gcd(int a, int b) {
   if (b == 0)
      return a;
   return gcd(b, a % b);
}

int main() {
  ll n;
  std::cin >> n;
  if (n%2 == 1) {
    std::cout << 0 << std::endl;
    return 0;
  }

  ll divisor = 10;
  ll ans = 0;
  ll acc = n/divisor;
  while (acc > 0) {
    ans += acc;
    divisor *= 5;
    acc = n/divisor;
  }
  std::cout << ans << std::endl;
  return 0;
}



Measured memory_bytes: 256
#include<stdio.h>

int main(){
	int i,n,a[10000],b[10000],a_score=0,b_score=0;
	while(1){
		a_score=0;
		b_score=0;
		scanf("%d",&n);
		if(n==0)break;
		for(i=0;i<n;i++){
			scanf("%d %d",&a[i],&b[i]);}
		for(i=0;i<n;i++){
			if(a[i]>b[i])a_score+=a[i]+b[i];
			if(a[i]==b[i]){
				a_score+=a[i];
				b_score+=b[i];}
			if(a[i]<b[i])b_score+=a[i]+b[i];}
		printf("%d %d\n",a_score,b_score);
}
	return 0;}

Measured memory_bytes: 0
import numpy as np
h, w = map(int, input().split())
board = [list(str(input())) for _ in range(h)]
for j in range(2):
    board = [i for i in board if i.count('#') != 0]
    board = np.array(board)
    board = board.T
    board = board.tolist()
for i in board:
    print(*i, sep='')

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

int main(){
  int h,w;
  cin >>h >>w;
  string s[h];
  rep(i,h) cin >>s[i];
  vector<bool> row(h,false);
  vector<bool> col(w,false);
  rep(i,h){
    rep(j,w){
      if(s[i][j]=='#'){
        row[i]=true;
        col[j]=true;
      }
    }
  }
  rep(i,h){
    if(row[i]){
     rep(j,w){
       if(col[j]) cout <<s[i][j];
     }
     cout << endl;
    }
  }
  return 0; 
}

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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long

const int N = 1e5 + 105;

int a[N], n, cache[N], k = 2;

int dp(int i){
    int &ans = cache[i];
    if(ans != -1)
    return ans;
    ans = 1e18;
    bool flag = 0;
    for(int j = 1; j <= k; ++j){
        if(i + j < n){
            ans = min(ans, abs(a[i] - a[i + j]) + dp(i + j));
            flag = 1;
        }
    }
    if(!flag)
    ans = 0;
    return cache[i] = ans;
}

void solve(){
    cin >> n >> k;
    for(int i = 0; i < n; ++i)
    cin >> a[i];
    memset(cache, -1, sizeof cache);
    cout << dp(0);
}

int32_t main(){
    IOS;
    int t = 1;
    bool test = 0;
    if(test) cin >> t;
    for(int i = 1; i <= t; ++i)
    solve();
    return 0;
}

/*

  
*/
  

Measured memory_bytes: 11460