akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

const int MAX_N = 1e5 + 5;
const int MAX_L = 20; // ~ Log N
const long long MOD = 1e9 + 7;
const long long INF = 1e9 + 7;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef vector<vi> vvi;

#define LSOne(S) (S & (-S))
#define isBitSet(S, i) ((S >> i) & 1)





int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    #ifdef LOCAL
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif

    ll x,k,d;
    cin>>x>>k>>d;
    x=abs(x);
	ll flag=0;
    if(x/d>k){
    	flag=x-d*k;
	}
	else{
		int y=x/d;
		k=k-y;
		if(k%2==0)
		flag=x-y*d;
		else{
			flag=min((x-(y*d)+d),(x-(y*d)-d));
		}
		
	}
	
	cout<<abs(flag)<<endl;
	return 0;
}

Measured memory_bytes: 3636
#include<stdio.h>
int main()
{
	int a,b,c,d;
	scanf("%d %d %d %d",&a,&b,&c,&d);
	if(a+b>c+d) printf("Left\n");
	else if(a+b<c+d) printf("Right");
	else printf("Balanced");
}

Measured memory_bytes: 1720
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdint.h>
#include <tuple>
#include <utility>
#include <vector>

using namespace std;

typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
static const double EPS = 1e-12;
static const double PI = acos(-1.0);
static const ll MOD = 1000000007;

#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(a) (a).begin(), (a).end()
#define DEBUG(x) cout << #x << ": " << x << endl

const string YES = "Yes";
const string NO = "No";

bool solve(long long N, std::vector<std::string> S) {
  vector<pair<ll, ll>> min_last_up;
  vector<pair<ll, ll>> min_last_down;
  REP(i, S.size()) {
    ll count = 0;
    ll min_ = 0;
    REP(j, S[i].size()) {
      if (S[i][j] == '(') {
        count++;
      } else {
        count--;
        min_ = min(min_, count);
      }
    }
    if (count >= 0) {
      min_last_up.emplace_back(min_, count);
    } else {
      min_last_down.emplace_back(min_ - count, -count);
    }
  }
  sort(ALL(min_last_up), greater<>());
  sort(ALL(min_last_down), greater<>());
  // REP(i, min_last_up.size()) {
  //   cout << min_last_up[i].first << " " << min_last_up[i].second << endl;
  // }
  // cout << endl;
  // REP(i, min_last_down.size()) {
  //   cout << min_last_down[i].first << " " << min_last_down[i].second << endl;
  // }
  ll up = 0;
  REP(i, min_last_up.size()) {
    ll min_ = min_last_up[i].first;
    ll last = min_last_up[i].second;
    if (up + min_ < 0) {
      return false;
    }
    up += last;
  }
  ll down = 0;
  REP(i, min_last_down.size()) {
    ll min_ = min_last_down[i].first;
    ll last = min_last_down[i].second;
    if (down + min_ < 0) {
      return false;
    }
    down += last;
  }
  return up == down;
}

int main() {
  long long N;
  scanf("%lld", &N);
  std::vector<std::string> S(N);
  for (int i = 0; i < N; i++) {
    std::cin >> S[i];
  }
  cout << (solve(N, std::move(S)) ? YES : NO) << endl;
  return 0;
}


Measured memory_bytes: 42148
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n,a[100010],b=0;
  cin>>n;
  for(int i=0;i<n;++i)cin>>a[i];
  for(int i=0;i<n;++i){
    if(i+1==a[a[i]-1])b++;
  }
  cout << b/2 << endl;
  return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <map>
#include <string>
#include <utility>
#include <algorithm>
#include <bitset>
#include <numeric>
#include <math.h>
#include <tuple>
#include <queue>
#include <set>

using namespace std;

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

    int N;
    cin >> N;

    vector<int> H(N);

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

    int ans;
    ans = 0;
    for(int i_hotel = 0; i_hotel < N; i_hotel++){
        bool exist_higher_hotel = false;
        for(int j_hotel = 0; j_hotel < i_hotel; j_hotel++){
            if(H[i_hotel] < H[j_hotel]){
                exist_higher_hotel = true;
            }
        }
        if(!exist_higher_hotel){
            ans++;
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
import Foundation

var line = readLine()!.components(separatedBy: " ")
let H1 = Int(line[0])!
let M1 = Int(line[1])!
let H2 = Int(line[2])!
let M2 = Int(line[3])!
let K = Int(line[4])!

print((H2 - H1) * 60 + (M2 - M1) - K)


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

using namespace std;
const int N = 200001;
int n;
vector<pair<int, int>> v;
void mx(int& a, int b){
  if(a < b)
    a = b;
}
void mn(int& a, int b){
  if(a > b)
    a = b;
}
pair<int, int> solve_sub(vector<pair<int, int>> v){
  int m = v.size();
  if(m == 0)
    return {1000000000, 0};
  int x[m];
  int y[m];
  int a, b;
  for(int i = 0;i < m;i++)
    x[i] = v[i].first, y[i] = v[i].second;
  int b_min, b_max;
  int res = 1e9 + 1;
  b_max = x[m - 1];
  int mny, mni;
  mny = 1e9 + 1;
  for(int i = 0;i < m;i++){
    if(y[i] < mny){
      mny = y[i];
      mni = i;
    }
  }
  for(int i = 0;i < m;i++){
    if(x[i] > mny)break;
    b_min = x[i];
    if(b_max - b_min < res){
      res = b_max - b_min;
      a = b_min, b = b_max;
    }
    b_max = max(b_max, y[i]);
  }

  b_max = 0;
  for(int i = 0;i < m;i++){
    if(i == mni){
      mx(b_max, y[i]);
    }else{
      if(x[i] < mny)
        mx(b_max, y[i]);
      else
        mx(b_max, x[i]);
    }
  }
  if(b_max - mny < res){
    a = mny, b = b_max;
  }
  res = min(res, b_max - mny);
  return {a, b};
}

int main(){
  cin >> n;
  if(n == 1){
    cout << 0;
    return 0;
  }
  v.resize(n);
  for(auto& el : v){
    cin >> el.first >> el.second;
    if(el.first > el.second)
      swap(el.first, el.second);
  }

  sort(v.begin(), v.end());
  long long res = 1e18 + 1;
  int r_min = v[0].first;
  int r_max, b_min, b_max;
  int mxi, mxy, mni, mny;
  mxy = -1;
  mny = 1e9 + 1;
  for(int i = 0;i < n;i++){
    if(v[i].second > mxy){
      mxy = v[i].second;
      mxi = i;
    }
    if(v[i].second < mny){
      mny = v[i].second;
      mni = i;
    }
  }
  // case 1: b_max is max
  res = 1ll * (v[n - 1].first - v[0].first) * (mxy - mny);

  // cases 2: 
  r_max = mxy;
  vector<pair<int, int>> sub;
  for(int i = 0;i < n;i++){
    if(i == 0 || i == mxi)continue;
    sub.push_back(v[i]);
  }
  pair<int, int> sol = solve_sub(sub);
  mn(sol.first, v[0].second);
  mn(sol.first, v[mxi].first);
  mx(sol.second, v[0].second);
  mx(sol.second, v[mxi].first);
  res = min(res, 1ll * (r_max - r_min) * (sol.second - sol.first));
  cout << res;

}


Measured memory_bytes: 9556
#include<iostream>
#include<string>
using namespace std;
int main(){
int i,j,h,b;
string s,t;
while(cin>>s>>t){
if(s=="0")break;
h=b=0;
for(i=0;i<4;i++){
if(s[i]==t[i])h++;
for(j=0;j<4;j++)if(i!=j&&s[i]==t[j])b++;
}
cout<<h<<" "<<b<<endl;
}
return 0;
}

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

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

	vector<int> vecn(N);
	for (int i = 0; i < M; i++) {
		int a, b;
		cin >> a >> b;
		vecn.at(a - 1) += 1;
		vecn.at(b - 1) += 1;
	}
	for (int j = 0; j < N; j++) {
		cout << vecn.at(j) << endl;
	}
}

Measured memory_bytes: 256
import java.util.Scanner

fun main(args:Array<String>){

    val cin = Scanner(System.`in`)
    var count = Array(4,{Array(3,{Array<Int>(10,{0})})})

    val n = cin.nextInt()
    for(i in 1..n) count[cin.nextInt()-1][cin.nextInt()-1][cin.nextInt()-1] += cin.nextInt()
    

    for(i in 0..3){
	    for(j in 0..2){
	        for(k in 0..9){
		        print(" ${count[i][j][k]}")
	        }
	        println()
    	}
	    if(i < 3) println("####################")
    }
}



Measured memory_bytes: 30808
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
using namespace std;
#define INF 2000000007
#define LINF 100000000000000007
#define MOD 1000000007
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define repb(i, n) for (int i = n - 1; i >= 0; i--)
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
//typedef long long int ll;
typedef pair<int,int> P;
struct edge{int to,cost;};
int ceil2(int a,int b){if(a%b){return a/b+1;}else{return a/b;}}
int n,k,ans;
string s;
signed main(){
	cin>>n>>s;
	int j=n-1;
	rep(i,n){
		if(s[i]=='W'){
			while(j>=0 && s[j]!='R'){
				j--;
			}
			if(i>=j)break;
			swap(s[i],s[j]);
			j--;
			ans++;
		}
	}
	//cout<<s<<endl;
	cout<<ans<<endl;
}

Measured memory_bytes: 3756
function Main(input) {
    input = input.trim().split('\n');
    const k = parseInt(input[0].split(' ')[2], 10);
    const a = input[1].split(' ');
    const b = input[2].split(' ');

    let t = 0;
    for(let i=0; i<b.length; i++){
        t += parseInt(b[i], 10);
    }

    let j = b.length;
    let ans = 0;
    for(let i=0; i<=a.length; i++){
        while(j > 0 && t > k) {
            j--;
            t -= parseInt(b[j]);
        }
        if(t > k) break;
        if(ans < i+j) ans = i+j;
        if(i === a.length) break;
        t += parseInt(a[i], 10);
    }
    console.log(ans);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 68000
parseInt(x) = parse(Int, x)

function main()
	n = parseInt(readline())
	s = Array{Int}(n)
	for i in 1:n
		s[i] = parseInt(readline())
	end
	s = sort(s)
	k = sum(s)
    flg = 0
	if k%10 != 0
		println(k)
    	flg = 1
	else
		for i in 1:n
			if s[i]%10 != 0
				println(k-s[i])
				flg = 1
				break
			end
		end
		if flg == 0
			println(0)
		end
	end
end

main()

Measured memory_bytes: 112212
#include <iostream>
#include <algorithm>
#include <vector>
typedef int TInt;
typedef std::vector<TInt> TList;
TList Input()
{
    int Count;
    std::cin >> Count;
    TList List(Count);
    for(int i = 0; i < Count; ++i){
        std::cin >> List[i];
    }
    return List;
}
TInt BubbleSort(TList& List)
{
    TInt Count = 0;
    bool Flag = true;
    while(Flag){
        Flag = false;
        for(std::size_t i = 0; i+1 < List.size(); ++i)
        {
            if(List[i] > List[i+1]){
                std::swap(List[i], List[i+1]);
                Flag = true;
                Count++;
            }
        }
    }
    return Count;
}

void Output(const TList& List)
{
    TList::const_iterator It = List.begin();
    std::cout << *(It++);
    for(; It != List.end(); ++It){
        std::cout << " " << *It;
    }
    std::cout << std::endl;
}
int main()
{
    TList List = Input();
    TInt Count = BubbleSort(List);
    Output(List);
    std::cout << Count << std::endl;
    return 0;
}

Measured memory_bytes: 1196
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;

namespace AtCoder.D
{
    internal static class CR
    {
        public static string GetText() { return Console.ReadLine(); }
        public static List<string> GetTexts() { return Console.ReadLine().Split(' ').ToList(); }
        public static long GetLong() { return long.Parse(Console.ReadLine()); }
        public static List<long> GetLongs() { return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToList(); }
    }

    public class Program
    {
        public static long N { get; private set; }

        public static void Main() { var r = GetResult(); Debug.WriteLine(r); Console.Write(r); }

        private static object GetResult()
        {
            N = CR.GetLong();

            var queue = new Queue<long>();
            for (int i = 1; i < 10; i++)
            {
                queue.Enqueue(i);
            }

            var x = 0L;
            for (int i = 0; i < N; i++)
            {
                x = queue.Dequeue();
                var mod = x % 10;
                if (mod == 0)
                {
                    queue.Enqueue(10 * x);
                    queue.Enqueue(10 * x + 1);
                }
                else if (mod == 9)
                {
                    queue.Enqueue(10 * x + 8);
                    queue.Enqueue(10 * x + 9);
                }
                else
                {
                    queue.Enqueue(10 * x + mod - 1);
                    queue.Enqueue(10 * x + mod);
                    queue.Enqueue(10 * x + mod + 1);
                }
            }
            return x;
        }
    }
}


Measured memory_bytes: 15072
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n;
	string s;
	int r=0,b=0;
	cin>>n;
	cin>>s;
	for(int i=0;i<n;i++){
		if(s[i]=='R'){
			r++;
		}else{
			b++;
		}
	}
	if(r>b){
		cout<<"Yes"<<endl;
	}else{
		cout<<"No"<<endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main() {
	int n, x;
	int p = 0;
	vector<int> vec;
	cin >> n >> x;
	for (int i = 0; i < n; ++i) {
		int a;
		cin >> a;
		p = p + a;
		vec.push_back(a);
	}
	x = x - p;
	sort(vec.begin(), vec.end());
	n = n + x / vec[0];
	cout << n << endl;
	system("pause");
	return 0;
}

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

inline void fastRead_int(int &x) {
    register int c = getchar_unlocked();
    x = 0;
    int neg = 0;

    for(; ((c<48 || c>57) && c != '-'); c = getchar_unlocked());

    if(c=='-') {
      neg = 1;
      c = getchar_unlocked();
    }

    for(; c>47 && c<58 ; c = getchar_unlocked()) {
      x = (x<<1) + (x<<3) + c - 48;
    }

    if(neg)
      x = -x;
}

int main(){

	int n, k;
	fastRead_int(n); fastRead_int(k);

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

	vector<bool> dp(k+1, false);

	for (int i = 0; i <= k; ++i) {
		for (int j = 0; j < n; ++j) {
			if(i >= arr[j]){
				if(!dp[i - arr[j]])dp[i] = true;
			}
		}
	}

	cout << (dp[k] ? "First" : "Second") << endl;
	
	return 0;
}

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

int main() {
    int N; cin >> N;
    vector<pair<int,int>> p;
    int b;
    for(int i=1;i<=N;i++){
        int a; cin >> a;
        p.push_back(make_pair(a,i));
    }
    sort(p.begin(),p.end(),greater<pair<int,int>>());
    if(p[0].first==p[1].first) b=200010;
    else b=p[0].second;
    for(int i=1;i<=N;i++){
        if(i!=b)
        cout << p[0].first << endl;
        else
        cout << p[1].first << endl;
    }


    return 0;
}

Measured memory_bytes: 3312
dic = {}
n = int(input())
for _ in range(n):
    command = input().split(' ')
    opecode = command[0]
    operand = command[1]
    if opecode == 'insert':
        dic[operand] = operand
    elif opecode == 'find':
        if dic.get(operand) != None:
            print('yes')
        else:
            print('no')


Measured memory_bytes: 37980
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp>     // Including tree_order_statistics_node_update
using namespace __gnu_pbds;
using namespace std;
/*
         ########     ########   ########   #########   ##       #######   ##       #######
         #      #     #      #   #      #       #       # #      #     #   # #      #     #
         #      #     #      #   #      #       #       #  #     #     #   #  #     #     #
         ########     #      #   #      #       #       #   #    #     #   #   #    #     #
         ###          #      #   #      #       #       #    #   #######   #    #   #######
         #  #         #      #   #      #       #       #   #    #     #   #   #    #     #
         #   #        #      #   #      #       #       #  #     #     #   #  #     #     #
         #    #       #      #   #      #       #       # #      #     #   # #      #     #
         #     #      ########   ########       #       ##       #     #   ##       #     #     
*/

#define rep(i, a, b) for (__typeof((b)) i = (a); i < (b); i++)
#define nrep(i, a, b) for (__typeof((b)) i = (a); i > (b); i--)
#define all(a) (a).begin(), (a).end()
#define ff first
#define ss second
#define ppi pair<int, int>
#define pppi pair<ppi, int>
#define vi vector<int>
#define vii vector<ppi>
#define viii vector<pppi>
#define vs vector<string>
#define pb push_back
#define bitcount __builtin_popcount //count no's of ones in a set bit
#define prq priority_queue
#define mp make_pair
#define mem(x, val) memset((x), (val), sizeof(x));
#define sz(x) (int)x.size()
#define M_PI 3.14159265358979323846
#define rootdada                      \
    ios_base::sync_with_stdio(false); \
    cin.tie(0);                       \
    cout.tie(0);
#define test  \
    int t;    \
    cin >> t; \
    while (t--)
#define debug(a)          \
    cerr << #a << ": ";   \
    for (auto i : a)      \
        cerr << i << " "; \
    cerr << '\n';
#define trace(a) cerr << #a << ": " << a << "\n"
#define print(ar, n)            \
    for (int u = 0; u < n; u++) \
    {                           \
        cout << ar[u] << " ";   \
    }                           \
    cout << endl;
#define int long long
#define M 1000000007
#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
signed main()
{
    rootdada;
    // #ifndef ONLINE_JUDGE
    //     freopen("input.txt", "r", stdin);
    //     //   freopen("output.txt", "w", stdout);
    //     //  freopen("error.txt", "w", stderr);
    // #endif
    int a, b;
    cin >> a >> b;
    int l = a * b;
    cout << l << endl;
}

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

using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;

#define REP(i, n, m) for(ll i=n; i<(ll)m; ++i)
#define IREP(i, n, m) for(ll i=n-1; i>=m; --i)
#define rep(i, n) REP(i, 0, n)
#define irep(i, n) IREP(i, n, 0)
#define all(v) v.begin(), v.end()

int main(){
    ll n, m;
    cin >> n >> m;
    vll a(m), b(m);
    vll f(m);
    rep(i, m){
        cin >> a[i] >> b[i];
        rep(j, b[i]){
            ll c;
            cin >> c;
            f[i] |= 1<<(c-1);
        }
    }

    ll dp[m+1][1<<12] = {};
    rep(i, m+1) rep(j, 1<<n) dp[i][j] = -2;
    function<ll(ll, ll)> solve = [&](ll nd, ll o){
        if(dp[nd][o]>=-1) return dp[nd][o];
        if(o==(1<<n)-1) return dp[nd][o]=0ll;
        if(nd>=m) return dp[nd][o]=-1ll;
        ll oo = o | f[nd];
        ll t0 = solve(nd+1, o);
        ll t1 = solve(nd+1, oo);
        ll t = 1ll<<60;
        t = t0>=0? min(t, t0) : t;
        t = t1>=0? min(t, t1+a[nd]) : t;
        t = t<(1ll<<60)? t : -1;
        dp[nd][o] = t;
        return t;
    };
    cout << solve(0, 0) << endl;
}


Measured memory_bytes: 32384
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define REP(i,s,n) for(int i=s; i<(n); ++i)
#define ALL(n) begin(n),end(n)
using ll = long long;
const ll INF = numeric_limits<long long>::max();

int main(){
    int N, M;
    vector<int> A(N);
    cin >> N >> M;
    REP(i, 0, N) cin >> A[i];

    int sum = 0;
    REP(i, 0, N) sum += A[i];
    
    int cnt = 0;
    REP(i, 0, N){
        if (A[i] >= (float)sum / 4 / M){
            cnt++;
        }
    }

    if (cnt >= M){
        cout << "Yes" << endl;
    } else{
        cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 16640
n,m,x = map(int,input().split())
c = []
a = []
ans = 10**9
for i in range(n):
    p = list(map(int,input().split()))
    c.append(p[0])
    a.append(p[1:])
for i in range(2**n):
    point = [0]*m
    res = 0
    for j in range(n):
        
        if (i>>j)%2:
            res += c[j]
            for k in range(m):
                point[k] += a[j][k]
    point.sort()
    if point[0] >= x:
        ans = min(ans,res)
    
if ans == 10**9:ans = -1
            
print(ans)    

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

using namespace std;

typedef long long ll;
typedef unsigned int ui;
typedef pair<int, int> pi;

#define fi first
#define se second

int read() {
  int res = 0, w = 1; char c = getchar();
  while (!isdigit(c) && c != '-') c = getchar();
  if (c == '-') c = getchar(), w = -1;
  while (isdigit(c)) res = (res << 1) + (res << 3) + c - '0', c = getchar();
  return res * w;
}

const int N = 3e5 + 10;
const int Mod = 998244353;

int n;
char s[N];

int main() {
  n = read();
  scanf("%s", s + 1);
  int r = 0, g = 0, b = 0, rg = 0, rb = 0, gb = 0;
  int ans = 1;
  for (int i = 1; i <= 3 * n; i++) {
    if (s[i] == 'R') {
      if (gb) {
        ans = 1ll * ans * gb % Mod;
        gb--; 
      } else if (g) {
        ans = 1ll * ans * g % Mod;
        g--, rg++;
      } else if (b) {
        ans = 1ll * ans * b % Mod;
        b--, rb++;
      } else {
        r++;
      }
    } else if (s[i] == 'G') {
      if (rb) {
        ans = 1ll * ans * rb % Mod;
        rb--; 
      } else if (r) {
        ans = 1ll * ans * r % Mod;
        r--, rg++;
      } else if (b) {
        ans = 1ll * ans * b % Mod;
        b--, gb++;
      } else {
        g++;
      }
    } else {
      if (rg) {
        ans = 1ll * ans * rg % Mod;
        rg--; 
      } else if (g) {
        ans = 1ll * ans * g % Mod;
        g--, gb++;
      } else if (r) {
        ans = 1ll * ans * r % Mod;
        r--, rb++;
      } else {
        b++;
      }
    }
  } 
  for (int i = 1; i <= n; i++) ans = 1ll * ans * i % Mod;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 512
import java.util.Scanner;

public class Main {
	static int acnt = 0, bcnt = 0;
	static boolean memo[][];

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		StringBuilder sb = new StringBuilder();
		int n = sc.nextInt();
		int m = sc.nextInt();
		int[] map1 = new int[n];
		int[] map2 = new int[n];
		int a, b;
		for (int i = 0; i < m; i++) {
			a = sc.nextInt();
			b = sc.nextInt();
			if (a == 1) {
				map1[b - 1]++;
			}
			if (b == n) {
				map2[a - 1]++;
			}
		}
		String str = "IMPOSSIBLE";
		for (int i = 0; i < n; i++) {
			if (map1[i] >= 1 && map2[i] >= 1) {
				str = "POSSIBLE";
				break;
			}
		}
		System.out.println(str);
	}
}


Measured memory_bytes: 95652
# python3 (3.4.3)
import sys
input = sys.stdin.readline

# main
N = int(input())

mod = 10**9+7
# bitも上から見ていくので逆順にして扱いやすくする
binN = format(N,"061b")[::-1]

dp = [[0,0,0] for _ in range(61)]
dp[60][0] = 1

for i in range(59,-1,-1):
    # i桁目のbitが 1
    if binN[i]=="1":
        dp[i][0] = dp[i+1][0]
        dp[i][1] = dp[i+1][0] + dp[i+1][1]
        dp[i][2] = 2*dp[i+1][1] + 3*dp[i+1][2]
    # i桁目のbitが 0
    else:
        dp[i][0] = dp[i+1][0] + dp[i+1][1]
        dp[i][1] = dp[i+1][1]
        dp[i][2] = dp[i+1][1] + 3*dp[i+1][2]

    for j in range(3):
        dp[i][j] %= mod

print((dp[0][0] + dp[0][1] + dp[0][2]) % mod)

Measured memory_bytes: 3064
# -*- coding: utf-8 -*-
"""
Created on Tue May 28 22:22:21 2019

@author: Yamazaki Kenichi
"""
import heapq

Q = int(input())
Q2 = [input() for i in range(Q)]

ans = []
Al,Ar = [-(-(10**9+1))],[10**9+1]
B = 0
flg = False
for q in Q2:
    if q[0] == '1':
#        input
        d, a, b = map(int,q.split())
        if not flg:
            heapq.heappush(Al,-a)
            B += b
            flg = True
            continue
        
#        C = abs(a - (-Al[0]))
        if len(Al) == len(Ar):
            if a < Ar[0]:
#                C = abs(a - (-Al[0]))
                heapq.heappush(Al,-a)
#                C = abs(a - (-Al[0]))
#            elif a < Ar[0]:
#                heapq.heappush(Al,-(heapq.heappop(Ar)))
#                heapq.heappush(Ar,a)
                C = abs(a - (-Al[0]))
            else:
                heapq.heappush(Ar,a)
                heapq.heappush(Al,-(heapq.heappop(Ar)))
                C = abs(a - (-Al[0]))
        else:
            if a < Ar[0]:
                C = abs(a - (-Al[0]))
                heapq.heappush(Al,-a)
                heapq.heappush(Ar,-(heapq.heappop(Al)))
#                C = abs(a - (-Al[0]))
#            elif a < A[]
            else:
                C = abs(a - (-Al[0]))
                heapq.heappush(Ar,a)
#                C = abs(a - (-Al[0]))
        B += (b + C)
#        print(Al,Ar,a,B,b)
    else:
#        output
        ans.append([(-Al[0]),B])
        
for c in ans:
    print(' '.join(map(str,c)))



Measured memory_bytes: 35756
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; --i)
#define whole(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
using P = pair<int, int>;
#define debug(var) cerr << "[" << #var << "] " << var << endl
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
const ll mod = 1000000007;
const int dx[] = {-1,0,1,0};
const int dy[] = {0,-1,0,1};


int main(){
    ll n, a, b;
    cin >> n >> a >> b;
    vector<ll> x(n);
    rep(i, n) cin >> x[i];
    ll ans = 0;
    rep(i, n) {
        if (i==0) continue;
        ll c = a*(x[i]-x[i-1]);
        chmin(c, b);
        ans += c;
    }
    
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3968
#include<bits/stdc++.h>
using namespace std;
char s[100010][20];
string str[100010];
map<string,int>vis;
int main()
{
	int n;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=10;j++)
		{
			cin>>s[i][j];
		}
		sort(s[i]+1,s[i]+11);
		for(int j=1;j<=10;j++)
		{
			str[i]+=s[i][j];
		}
	}
	long long ans=0;
	for(int i=1;i<=n;i++)
	{
		ans+=vis[str[i]];
		vis[str[i]]++;
	}
	cout<<ans<<endl;
	return 0;
}

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

typedef long long ll;
typedef unsigned long long ull;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define RFOR(i,a,b) for(int i=(b-1);i>=(a);--i)
#define REP(i,n)   FOR(i,0,n)
#define RREP(i,n)   RFOR(i,0,n)
#define SORT(s) sort(s.begin(), s.end())
#define P pair<int, int>
#define mp make_pair

const double INF = 1e+09;
const int MOD = 1e9+7;

using namespace std;

template <typename _Ty>
ostream& operator << (ostream& ostr, const vector<_Ty>& v) {if (v.empty()) {ostr << "{ }"; return ostr;}
    ostr << "{" << v.front(); for (auto itr = ++v.begin(); itr != v.end(); itr++) {ostr << ", " << *itr;}
    ostr << "}";
    return ostr;}

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

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

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

vector<int> uniq(vector<int> vec){
  sort(vec.begin(), vec.end());
  vec.erase(unique(vec.begin(), vec.end()), vec.end());
  return vec;}

vector<ll> divisor(ll n) {
vector<ll> ret;
for(int64_t i = 1; i * i <= n; i++) {
  if(n % i == 0) {
    ret.push_back(i);
    if(i * i != n) ret.push_back(n / i);
  }
}
  sort(begin(ret), end(ret));
  return (ret);
}
void permu(int n){
  vector<int> perm(n);
  REP(i, n) perm[i] = i;
do{
  cout << perm  << endl;
}
while (next_permutation(perm.begin(), perm.end()));
return;}

vector<pair<ll, int>> prime_div(ll n){
  vector<pair<ll, int>> res;
  for (ll i=2; i*i <= n;i++){
    if (n%i == 0){
      int a = 0;
      while(n%i == 0){
        n /= i;
        a++;
      }
      pair<ll, int> tmp;
      tmp.first = i;
      tmp.second = a;
      res.push_back(tmp);
    }
  }
  if (n != 1){
    pair<ll, int> now;
    now.first = n;
    now.second = 1;
    res.push_back(now);}
  return res;
}


// printf("%.10f\n" , ans);
int main(void){
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  int buy = (n+1000-1)/1000;
  cout << buy * 1000 - n << endl;
  return 0;
}



Measured memory_bytes: 3628
import sys
input = sys.stdin.buffer.readline

N, A, B = map(int, input().split())
H = [int(input()) for _ in range(N)]

ok = 10**18
ng = 0

def isOk(n):
    cnt = 0
    for h in H:
        h -= B * n
        if h > 0:
            cnt += -(-h // (A - B))
    return cnt <= n

while ok - ng > 1:
    mid = (ok + ng) // 2
    if isOk(mid):
        ok = mid
    else:
        ng = mid

print(ok)

Measured memory_bytes: 7064
#include <iostream>
#include <unordered_map>
#include <algorithm>
#include <cmath>

using namespace std;

int main() {
    int d, n, ans = 0, cnt = 1;
    cin >> d >> n;
    while(cnt <= n){
        ans++;
        int p = 0, m = ans ;
        while(m % 100 == 0){
            m /= 100;
            p++;
        }
        if(p == d) cnt++;
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 256
import heapq

N, C = map(int, input().split())
TVs = [[] for i in range(C)]
for i in range(N):
    s, t, ch = map(int, input().split())
    TVs[ch - 1].append((s, t))

pq = []
for ch, TVc in enumerate(TVs):
    if not TVc: continue
    TVc.sort()
    heapq.heappush(pq, (TVc[0][0] - 0.5, ch))

states = [0] * C
iTVs = [0] * C

prev = 0
ans = 0
while pq:
    tm, ch = heapq.heappop(pq)
    if tm != prev:
        ans = max(ans, sum(states))
        prev = tm

    if states[ch] == 0:
        # チャンネルchの番組録画を、時刻tmから開始
        states[ch] = 1
        heapq.heappush(pq, (TVs[ch][iTVs[ch]][1], ch)) # 終了時刻をpqに追加
    else:
        # チャンネルchの番組録画を、時刻tmで終了
        states[ch] = 0
        iTVs[ch] += 1
        if iTVs[ch] >= len(TVs[ch]): continue

        if tm == TVs[ch][iTVs[ch]][0]:
            # 録画範囲が連続しているならば、次の番組録画を開始
            states[ch] = 1
            heapq.heappush(pq, (TVs[ch][iTVs[ch]][1], ch)) # 終了時刻をpqに追加
        else:
            heapq.heappush(pq, (TVs[ch][iTVs[ch]][0] - 0.5, ch)) # 次の開始時刻をpqに追加

print(ans)


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

typedef long long ll;
typedef pair<ll,ll> pi;
typedef vector <ll> vi;
typedef vector <pi> vpi;
#define f first
#define s second
#define FOR(i,s,e) for(ll i=s;i<=ll(e);++i)
#define DEC(i,s,e) for(ll i=s;i>=ll(e);--i)
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define lbd(x, y) lower_bound(all(x), y)
#define ubd(x, y) upper_bound(all(x), y)
#define aFOR(i,x) for (auto i: x)
#define mem(x,i) memset(x,i,sizeof x)
#define fast ios_base::sync_with_stdio(false),cin.tie(0)

int N,M;
int ans[10];

int main(){
	fast;
	
	cin>>N>>M;
	
	mem(ans,-1);
	
	if (N == 1 && M == 0){
		cout<<0;
		return 0;
	}
	FOR(i,0,M-1){
		int s,c;
		cin>>s>>c;
		if (ans[s] != -1 && ans[s] != c){
			cout<<-1;
			return 0;
		}
		
		if (s == 1 && c == 0 && N > 1){
			cout<<-1;
			return 0;
		}
		
		ans[s] = c;
	}
	
	if (ans[1] == -1) ans[1] = 1;
	

	FOR(i,1,N){
		if (ans[i] == -1) cout<<0;
		else cout<<ans[i];
	}
	
}



Measured memory_bytes: 256
fun main(args: Array<String>) {
    while (true) {
        val (a, b) = readLine()!!.split(" ").map { it.toInt() }
        if (a==0 && b==0) break
        println("${"#".repeat(b)}")
        print("#${".".repeat(b-2)}#\n".repeat(a-2))
        println("${"#".repeat(b)}")
        println()
    }
}


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


using namespace std;

const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;


#define DEBUG

#ifdef DEBUG
#define PRINT(A) std::cout << (#A) << ":" << (A) << std::endl;
#else
#define PRINT(A)
#endif

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


int A, B;
int a[10010][10010], b[1000];
int dp[10010][3];
 
int main()
{
    ll N; cin >> N;
    ll A[N+10];
    rep(i,N){
        A[i] = 0;
    }
    for(ll i = 2; i <= N; i++){
        ll B;
        cin >> B;
        A[B] += 1;
    }

    for(int i = 1; i <= N; i++){
        cout << A[i] << endl;
    }
    return 0;
}


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

#define ff first
#define ss second
#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define w(x) int t; cin >> t; while(t--)
#define rep(i, a, b) for(int i = a; i <= b; i++)
#define repd(i, b, a) for(int i = b; i >= a; i--)
#define mk(arr,n,type) type* arr = new type[n];
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vl vector<ll>
#define um unordered_map
#define us unordered_set
#define pqm priority_queue<int>
#define pqmi priority_queue<int, vi, greater<int>>
#define lb(v, val) lower_bound(v.begin(), v.end(), val) - v.begin();
#define ub(v, val) upper_bound(v.begin(), v.end(), val) - v.begin();
#define setbits(x) __builtin_popcountll(x)
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define out(flag) flag ? cout << "NO" << endl : cout << "YES" << endl;
#define MAX 100001
#define mod 998244353
#define inf 1e18
#define PI 3.1415926535

void IO() {
	fast;
}

int solve(vector<vector<int>>& adj, vector<int>& dp, int curr, int n, int m) {
	if (adj[curr].size() == 0) {
		// cout << curr << endl;
		dp[curr] = 0;
		return 0;
	}
	if (dp[curr] != -1) {
		return dp[curr];
	}
	for (int i = 0; i < adj[curr].size(); i++) {
		dp[curr] = max(dp[curr], solve(adj, dp, adj[curr][i], n, m));
	}
	dp[curr]++;
	return dp[curr];
}

int main() {

	IO();

	int n, m;
	cin >> n >> m;
	vector<vector<int>> adj(n + 1, vector<int>());
	for (int i = 0; i < m; i++) {
		int a, b;
		cin >> a >> b;
		adj[a].push_back(b);
	}
	vector<int> dp(n + 1, -1);
	for (int i = 1; i <= n; i++) {
		if (dp[i] == -1) {
			solve(adj, dp, i, n, m);
		}
	}
	// solve(adj, dp, 1, n, m);
	int maxi = INT_MIN;
	for (int i = 0; i <= n; i++) {
		// cout << i << " " << dp[i] << endl;
		maxi = max(maxi, dp[i]);
	}
	cout << maxi << endl;


	return 0;
}


Measured memory_bytes: 9600
#include<stdio.h>
#include<string>
#include<utility>
#include<iostream>
#include<queue>
#include<math.h>
#include<algorithm>
#include<vector>
#include<map>
#include<stack>
#include<bitset>

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

int main(){
    int n;
    scanf("%d",&n);
    ll a[100005]={};
    int alz=1;
    int kep[3]={-1,-1,-1};
    int c[3]={1,0,0};
    int count=1;
    REP(i,n){
        scanf("%lld",&a[i]);
        if(a[i]!=0)alz=0;
    }
    if(n%3==1 || n%3==2){
        if(alz==1)printf("Yes\n");
        else printf("No\n");
        return 0;
    }
    kep[0]=a[0];
    for(int i=1;i<n;i++){
        int judge=1;
        REP(j,count){
            if(kep[j]==a[i]){
                judge=0;
                c[j]++;
            }
        }
        if(judge==1){
            if(count>=3){
                printf("No\n");
                return 0;
            }
            else{
                kep[count]=a[i];
                c[count]++;
                count++;
            }
        }
    }
    //REP(i,3)printf("###%d\n",kep[i]);
    //REP(i,3)printf("###%d\n",c[i]);
    if(count==1){
        if(alz==1)printf("Yes\n");
        else printf("No\n");
        return 0;
    }
    if(count==2){
        if(alz==1)printf("Yes\n");
        else if(c[0]==c[1]*2 && kep[1]==0){
            printf("Yes\n");
        }
        else if(c[1]==c[0]*2 && kep[0]==0){
            printf("Yes\n");
        }
        else printf("No\n");
        return 0;
    }
    if(count==3){
        if(c[0]==c[1] && c[1]==c[2]){
            if((kep[0]^kep[2])==kep[1])printf("Yes\n");
            else printf("No\n");
        }
        else printf("No\n");
        return 0;
    }
}

Measured memory_bytes: 1152
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define  fo(i,n) for(ll i=0;i<n;i++)
#define rfo(i,n) for(ll i=n;i>=0;i--)
#define fori(it, x) for (__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define pb push_back
#define deb(x) cout<< #x << " = "<<x<<endl;
#define F first
#define S second
#define MP make_pair
#define all(x) (x).begin(), (x).end()
void solve()
{
	ll n;
	cin>>n;
	ll ans=0;
	ll A[n];
	fo(i,n){cin>>A[i];
	}	
	for(ll j=0;j<n;j=j+2)
	{
		if(A[j]%2 != 0)
		{
			ans++;
		}
	}
	cout<<ans;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
	solve();
    return 0;
}

Measured memory_bytes: 3648
const int LG = 21;
const int FN = 400005;
const long long MOD = 1e9 + 7;
const long long INF = 1e9;
const long long INFLL = 1e18;

#include <bits/stdc++.h>

using namespace std;

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

#define forn(i, n) for (int (i) = 0; (i) != (n); (i)++)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define fi first
#define se second
#define re return
#define pb push_back
#define uniq(x) sort(all(x)); (x).resize(unique(all(x)) - (x).begin())

#ifdef LOCAL
#define dbg(x) cerr << __LINE__ << " " << #x << " " << x << endl
#define ln cerr << __LINE__ << endl
#else
#define dbg(x) void(0)
#define ln void(0)
#endif // LOCAL

int cx[4] = {-1, 0, 1, 0};
int cy[4] = {0, -1, 0, 1};
string Ans[2] = {"Yes", "No"};
string ANS[2] = {"YES", "NO"};

ll inq(ll x, ll y)
{
    if (!y) re 1 % MOD;
    ll l = inq(x, y / 2);
    if (y % 2) re l * l % MOD * x % MOD;
    re l * l % MOD;
}

ll rev(ll x)
{
    return inq(x, MOD - 2);
}

bool __precomputed_combinatorics = 0;
vector<ll> __fact, __ufact, __rev;

void __precompute_combinatorics()
{
    __precomputed_combinatorics = 1;
    __fact.resize(FN);
    __ufact.resize(FN);
    __rev.resize(FN);
    __rev[1] = 1;
    for (int i = 2; i < FN; i++) __rev[i] = MOD - __rev[MOD % i] * (MOD / i) % MOD;
    __fact[0] = 1, __ufact[0] = 1;
    for (int i = 1; i < FN; i++) __fact[i] = __fact[i - 1] * i % MOD, __ufact[i] = __ufact[i - 1] * __rev[i] % MOD;
}

ll fact(int x)
{
    if (!__precomputed_combinatorics) __precompute_combinatorics();
    return __fact[x];
}

ll cnk(int n, int k)
{
    if (k < 0 || k > n) return 0;
    if (!__precomputed_combinatorics) __precompute_combinatorics();
    return __fact[n] * __ufact[n - k] % MOD * __ufact[k] % MOD;
}

int Root(int x, vector<int> &root)
{
    if (x == root[x]) return x;
    return root[x] = Root(root[x], root);
}

void Merge(int v, int u, vector<int> &root, vector<int> &sz)
{
    v = Root(v, root), u = Root(u, root);
    if (v == u) return;
    if (sz[v] < sz[u])
    {
        sz[u] += sz[v];
        root[v] = u;
    }
    else
    {
        sz[v] += sz[u];
        root[u] = v;
    }
}

int ok(int x, int n)
{
    return 0 <= x && x < n;
}

void bfs(int v, vi &dist, vector<vi> &graph)
{
    fill(all(dist), -1);
    dist[v] = 0;
    vi q = {v};
    for (int i = 0; i < q.size(); i++)
    {
        for (auto u : graph[q[i]])
        {
            if (dist[u] == -1)
            {
                dist[u] = dist[q[i]] + 1;
                q.push_back(u);
            }
        }
    }
}


signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    double n, m, d;
    cin >> n >> m >> d;
    printf("%.9f", (m - 1) * (1 + (d != 0)) * (n - d) / n / n);
}

/* Note:
Check constants at the beginning of the code.
    N is set to 4e5 but be careful in problems with large constant factor.
    Setting N in every problem is more effective.
Check corner cases.
    N = 1
No def int long long for now.
Add something here.
*/


Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
INF = float("inf")


def yes():
    print("YES")  # type: str


def no():
    print("NO")  # type: str


def solve(A: str, B: str, C: str):
    if A[-1] == B[0] and B[-1] == C[0]:
        yes()
    else:
        no()
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = next(tokens)  # type: str
    B = next(tokens)  # type: str
    C = next(tokens)  # type: str
    solve(A, B, C)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
#include <map>

using namespace std;


int main() {
	int a, b;
	cin >> a >> b;
	cout << max(max(a+a-1,a+b), b+b-1) << endl;

	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <climits>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <string>
#include <sstream>
#include <vector>
#include <map>
#include <set>
#include <complex>
#include <functional>
#include <utility>
#include <iterator>

#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i, m, n) for(int i = (m); i < (int)(n); ++i)
#define ALL(x) (x).begin(), (x).end()
#define INF 2000000000

#ifdef LOCAL
  #define dprintf(...) fprintf(stdout, __VA_ARGS__)
#else
  #define dprintf(...) 0
#endif

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef unsigned int uint;

//const double PI = 3.1415926535897932384626433832795;

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

  if(b % a == 0) {
    ans = a + b;
  }
  else {
    ans = b - a;
  }

  cout << ans << endl;

  return 0;
}


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

main(){
  int n,a,b;cin >> n >> a >> b;
  int d=b-a;
  if(d%2 == 0){ 
    cout << "Alice" << endl;
    return 0;
  } else {
    cout << "Borys" << endl;
    return 0;
  }
} 


Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define SIZE 300005
#define MOD 1000000007LL
#define INF 1 << 30
#define LLINF 1LL << 60
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define DOWN(i,b,a) for(int i=b;i>=a;i--)
#define SET(a,c) memset(a,c,sizeof a)
#define FORALL(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define FOREACH(i,c) for(auto (i) : (c))
#define BIT(i,j) ((i)>>(j))&1
#define ALL(o) (o).begin(), (o).end()
#define ERASE(o) (o).erase(unique((o).begin(),(o).end()), (o).end())
#define SQ(x) ((x)*(x))
using namespace std;
typedef long long ll;
typedef pair<ll,ll> Pll;
typedef pair<int, int> Pii;
typedef pair<double, double> Pdd;
typedef complex<double> dcomplex;
template<typename T> inline void priv(vector<T>a){REP(i,a.size()){cerr<<a[i]<<((i==a.size()-1)?"\n":" ");}}
ll gcd(ll a,ll b){int c=max(a,b);int d=min(a,b);return c==0||d==0?c:gcd(c%d,d);}
ll lcm(ll a,ll b){return a==0||b==0?0:a*b/gcd(a,b);}
ll fact(ll a){ll b=1;FOR(i,1,a)b*=i;return b;}

int n;
int a[10][10];
int di[] = {0,1,1,2};
int dj[] = {0,0,1,0};

bool canPos(int i, int j, int t)
{
  switch(t)
  {
    case 3:
      if(i<=1||i>=8||j<=1||j>=8) return false;
      FOR(k,-2,2) FOR(l,-(2-abs(k)),(2-abs(k))) if(a[i+k][j+l]==0) return false;
      return true;
    case 2:
      if(i<=0||i>=9||j<=0||j>=9) return false;
      FOR(k,-1,1) FOR(l,-1,1) if(a[i+k][j+l]==0) return false;
      return true;
    case 1:
      if(i<=0||i>=9||j<=0||j>=9) return false;
      FOR(k,-1,1) FOR(l,-(1-abs(k)),1-abs(k)) if(a[i+k][j+l]==0) return false;
      return true;
    default:
      return false;
  }
}

void turn(int i, int j, int t, int c)
{
  switch(t)
  {
    case 3:
      FOR(k,-2,2) FOR(l,-(2-abs(k)),(2-abs(k))) a[i+k][j+l]+=c;
      break;
    case 2:
      FOR(k,-1,1) FOR(l,-1,1) a[i+k][j+l]+=c;
      break;
    case 1:
      FOR(k,-1,1) FOR(l,-(1-abs(k)),1-abs(k)) a[i+k][j+l]+=c;
    default:
      break;
  }
}

bool dfs(int n)
{
  if(n==0)
  {
    REP(i,10) REP(j,10) if(a[i][j] > 0) return false;
    return true;
  }
  REP(i,10) REP(j,10) if(a[i][j])
  {
    int x, y;
    FOR(t,1,3) if(canPos(y=i+di[t],x=j+dj[t],t))
    {
      turn(y,x,t,-1);
      if(dfs(n-1)) {printf("%d %d %d\n",x,y,t); return true;}
      turn(y,x,t,1);
    }
    return false;
  }
  return false;
}

int main()
{
  cin >> n;
  REP(i,10) REP(j,10) cin >> a[i][j];
  dfs(n);
  return 0;
}

Measured memory_bytes: 3232
#include<stdio.h>
int main(void)
{
  int a,b;
  double t;
  double ans;
  int ans2;
  
  scanf("%d %d %lf",&a,&b,&t);
  t+=0.5;
  ans=t/(double)a;
  ans2=(int)ans;
  ans2*=b;
  printf("%d\n",ans2);
  return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	set<string>s1;
	for(int i=0; i<n; i++)
	{
		string s;
		cin>>s;
		s1.insert(s);
	}
	cout<<s1.size()<<endl;
}

Measured memory_bytes: 19164
#include <cstdio>
#include <iostream> 
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
 
using namespace std;
using ll = long long;
using ull = unsigned long long;
 
const ll INF = 1e16;
const ll MOD = 1e9 + 7;

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



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

	if(abs(a - c) <= d || (abs(a - b) <= d && abs(b - c) <= d)){
		cout << "Yes" << endl;
	}
	else{
		cout << "No" << endl;
	}
}

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

using namespace std;
#define ll long long
#define ld long double
#define  P pair<ll,ll>
#define FOR(i,n,m) for(ll i=n; i<(ll)m;i++)
#define FORr(i,n,m) for(ll i=n; i>=(ll)m; i--)
#define FORm(i,m) for(auto i=m.begin();i!=m.end();i++)
#define VEC2(x,a,b) vector<vector<ll>> x = vector<vector<ll>>(a,vector<ll>(b,0))
#define sortAl(v) sort(v.begin(),v.end())
#define sortAlr(v) sort(v.begin(),v.end()); reverse(v.begin(),v.end())
#define cinv(v,n,m) FOR(i,n,m) cin>>v.at(i)
#define coutv(v,n,m) FOR(i,n,m) cout<<v.at(i) <<" "; cout<<endl
#define cout(n) cout<<fixed<<setprecision(n)

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

    ll res=0;
    FOR(i,0,4){
      if(x%10==2){
        res++;
      }
      x/=10;
    }
    cout<<res<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;

#define ll long long
#define ld long double
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define gcd __gcd
#define lcm(a, b) ((a) * (b) / gcd((a), b))
#define all(x) x.begin(), x.end()
#define rep(i, x, n) for (ll i = x; i < n; i++)
#define fastio() ios_base::sync_with_stdio(NULL); cin.tie(0); cout.tie(0)
#define endl '\n'

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

//OJ freopen Template
//void OJF(const char* inp, const char* out) {
//	freopen(inp, "r", stdin);
//	freopen(out, "w", stdout);
//}

int n;
int a[10];
bool used[10] = {false};
ld sum = 0;
ld tmp = 0;
vector<struct coord> td;
float cnt = 0;

struct coord {
	float x, y;
};

float cord(coord x, coord y) {
	return sqrt((x.x - y.x) * (x.x - y.x) + (x.y - y.y) * (x.y - y.y));
}

void calc() {
	tmp = 0;
	for (int i = 1; i < n; i++) {
		tmp += cord(td[a[i]], td[a[i + 1]]);
	}
	sum += tmp;
}

void back(int pos) {
	if (pos == n + 1) {
		calc();
		cnt += 1;
		return;
	}
	for (int i = 1; i <= n; i++) {
		if (!used[i]) {
			a[pos] = i;
			used[i] = true;
			back(pos + 1);
			used[i] = false;
		}
	}
}

signed main()
{
	//OJF("*.inp", "*.out");
	fastio();
	cin >> n;
	td.assign(n + 1, {});
	rep(i, 0, n) {
		cin >> td[i + 1].x >> td[i + 1].y;
	}
	back(1);
	cout << fixed << setprecision(7) << sum / cnt;
}


Measured memory_bytes: 256