akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <queue>
#include <deque>
#include <math.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;

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_MAX	2,147,483,647 = 2*1.0e9

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

  int answer = 3 * r * r;
  cout << answer << endl;

  return 0;
}



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

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

	int a;
	vector<int> ans(n-1, 0);
	for (int i = 0; i < n-1; i++) {
		cin >> a;
		ans.at(a - 1)++;
	}
	for (int i = 0; i < n-1; i++) {
		cout << ans.at(i) << endl;
	}
	cout << 0 << endl;

	return 0;
}

Measured memory_bytes: 3964
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        Scanner scan = new Scanner(System.in);
        int h=scan.nextInt();
        int a=scan.nextInt();
        int c=0;
        for(;h>0;){
            h-=a;
            c++;
        }
        System.out.println(c);


    }

}

Measured memory_bytes: 22484
#include <iostream>
using namespace std;
int main(void){
    // 定義：容器１を「 A 」、容器２「  B 」、水の移動「 C 」と置く
    int A, B, C;
    cin >> A >> B >> C;
    
    // 計算：容器２の水の残り ＝ 容器２の水の量 ー （ 容器１の水が入る量 ー 容器１の水の量 ）
    int ans = C - (A - B);
    
    // 比較：容器２に見水が残っているか確認する
    if(ans > 0) cout << ans << endl;
    else cout << 0 << endl;
    
    return 0;
}


Measured memory_bytes: 256
n = gets.chomp.to_i
v = []
n.times {
  a, b = gets.chomp.split(' ').map(&:to_i)
  v.push({:a => a, :b => b})
}
x = v.sort{|l,r| r[:a] <=> l[:a]}[0]
puts (x[:a] + x[:b]).to_s

Measured memory_bytes: 33000
a = [list(map(int,input().split())) for i in range(3)]
for i in range(int(input())):
  i = int(input())
  bo = True
  while(bo):
    for k,a_1 in enumerate(a[0]):
      if a_1 == i:
        a[0][k] = None
        bo = False
    for k,a_2 in enumerate(a[1]):
      if a_2 == i:
        a[1][k] = None
        bo = False
    for k,a_3 in enumerate(a[2]):
      if a_3 == i:
        a[2][k] = None
        bo = False
    bo = False
s = "No"
while(s == "No"):
  if (a[0][0] == a[1][1]) and (a[1][1] == a[2][2]):
    s = "Yes"
  if (a[2][0] == a[1][1]) and (a[1][1] == a[0][2]):
    s = "Yes"
  for l in a:
    if len(set(l)) == 1:
      s = "Yes"
  for i in range(3):
    if len(set([a[0][i], a[1][i], a[2][i]])) == 1:
      s = "Yes"
  break
print(s)


Measured memory_bytes: 3064
n, k = map(int, input().split())
a = list(map(int, input().split()))

    
li_cnt_0 = [0]*100
li_cnt_1 = [0]*100
for times in range(100):
    for i in range(n):
        if a[i] % 2 == 1:
            li_cnt_1[times] += 1
        if a[i] % 2 == 0:
            li_cnt_0[times] += 1
        a[i] = a[i] // 2

li_cnt_0 = li_cnt_0[::-1]
li_cnt_1 = li_cnt_1[::-1]
k  = format(k, '0100b')
dp = [[0]*2 for i in range(101)]

flag = False
for i in range(len(k)):
    cnt_0 = li_cnt_0[i]
    cnt_1 = li_cnt_1[i]
    
    # is_smaller = 0 -> is_smaller = 0
    if k[i] == "0":
        dp[i+1][0] = dp[i][0] + cnt_1 * 2**(99 - i)
    else:
        dp[i+1][0] = dp[i][0] + cnt_0 * 2**(99 - i)

    # is_smaller = 1 -> is_smaller = 1
    if flag:
        if k[i] == "0":
            dp[i+1][1] = max(dp[i][1] + cnt_1 * 2**(99 - i), dp[i+1][1])
            dp[i+1][1] = max(dp[i][1] + cnt_0 * 2**(99 - i), dp[i+1][1])
        else:
            dp[i+1][1] = max(dp[i][1] + cnt_1 * 2**(99 - i), dp[i+1][1])
            dp[i+1][1] = max(dp[i][1] + cnt_0 * 2**(99 - i), dp[i+1][1])

    # is_smaller = 0 -> is_smaller = 1
    if k[i] == "0":
        pass
    else:
        flag = True
        dp[i+1][1] = max(dp[i][0] + cnt_1 * 2**(99 - i), dp[i+1][1])

print(max(dp[len(k)][0], dp[len(k)][1]))


Measured memory_bytes: 69088
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N, M = MAP()

key_lis = []
key_cost = []

for _ in range(M):
	a, b = MAP()
	c = LIST()
	key = 0
	for x in c:
		key += 2**(x-1)
	key_lis.append(key)
	key_cost.append(a)


dp = [INF]*(1<<N)
dp[0] = 0

for S in range(1<<N):
	for i, key in enumerate(key_lis):
		dp[S|key] = min(dp[S|key], dp[S]+key_cost[i])

if dp[-1] == INF:
	print(-1)
else:
	print(dp[-1])

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

typedef long long ll;

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

    ll L[n+1];
    L[0] = 2;
    L[1] = 1;
    for(int i = 2; i <= n; i++){
        L[i] = L[i-1]+L[i-2];
    }

    cout << L[n] << endl;
    return 0;
}

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

using namespace std;

using ll = long long;
using ull = unsigned long long;

int bfs(queue<pair<int,int>> n, std::vector<int> v){
	pair<int,int> p = n.front();
	n.pop();
	if (p.first == 0) {
		return p.second;
	}
	int count = p.second + 1;
	for (size_t i = 0; i < v.size(); i++) {
		if (p.first >= v[i] && p.first < v[i] * 9) {
			int flag = true;
			queue<pair<int,int>> nn(n);
			while (!nn.empty()) {
				pair<int,int> pp = nn.front();
				nn.pop();
				if (pp.first == p.first - v[i]) {
					flag = false;
					break;
				}
			}
			if (flag) {
				n.push(make_pair(p.first - v[i], count));
			}
		}
	}

	return bfs(n,v);
}

int main(int argc, char const *argv[]) {
	int n;
	std::cin >> n;
	std::vector<int> v;
	v.push_back(1);
	int i = 1;
	while (pow(6,i) <= n) {
		v.push_back(pow(6,i));
		i++;
	}
	i = 1;
	while (pow(9,i) <= n) {
		v.push_back(pow(9,i));
		i++;
	}
	sort(v.begin(),v.end());
	reverse(v.begin(),v.end());
	queue<pair<int,int>> que;
	que.push(make_pair(n,0));

	std::cout << bfs(que,v) << '\n';
	return 0;
}


Measured memory_bytes: 896
import math

def is_prime(n):
    if n == 2 or n == 3: return True
    if n%2 == 0 or n < 2: return False
    for i in range(3, int(n**0.5)+1, 2):
        if n%i == 0:
            return False
    return True

N = int(input())
ans = 1
for p in [i for i in range(N+1) if is_prime(i)]:
    e = 0
    for n in range(1, N+1):
        while n % p == 0:
            n //= p
            e += 1
    ans *= e + 1
ans %= 10**9 + 7
print(ans)

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

int main(){
    int n, k;
    cin >> n >> k;
    int H[n];
    for(int i = 0; i < n; i++){
        cin >> H[i];
    }
    sort(H, H+n);
    long long int count = 0;
    for (int i = 0; i < n-k; i++){
        count += H[i];
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 1024
function main()
    x = parse(Int, readline())
    if 400 <= x < 600
        println(8)
    elseif 600 <= x < 800
        println(7)
    elseif 800 <= x < 1000
        println(6)
    elseif 1000 <= x < 1200
        println(5)
    elseif 1200 <= x < 1400
        println(4)
    elseif 1400 <= x < 1600
        println(3)
    elseif 1600 <= x < 1800
        println(2)
    elseif 1800 <= x < 2000
        println(1)
    end

end

main()

Measured memory_bytes: 156260
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

    public static void main(final String[] args) {
        try (final Scanner sc = new Scanner(System.in)) {
            final int n = sc.nextInt();
            final int k = sc.nextInt();
            final String s = sc.next();

            List<Integer> nums = new ArrayList<Integer>();
            int now = 1; // これにより、numsの最初の要素は必ず1に対応する（文字列の最初の要素が1でないときでも）
            int count = 0;
            for (int i = 0; i < n; i++) {
                if (s.charAt(i) == (char) ('0' + now)) {
                    count += 1;
                } else {
                    nums.add(count);
                    now = 1 - now; // now ^= 1もあり
                    count = 1;
                }
            }
            nums.add(count);
            // numsの末尾も1に対応させたいので、0対応で終わっていたら（数が偶数個なら）1に対応する要素を追加（実際は存在しないので数は0）
            if (nums.size() % 2 == 0) {
                nums.add(0);
            }
            int ans = 0;
            int add = 2 * k + 1;
            for (int i = 0; i < nums.size(); i += 2) {
                int temp = 0;
                int left = i;
                int right = Math.min(left + add, nums.size());
                for (int j = left; j < right; j++) {
                    temp += nums.get(j);
                }
                ans = Math.max(ans, temp);
            }
            System.out.println(ans);
        }
    }

}


Measured memory_bytes: 27244
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var Arr=(input.trim()).split("\n");
var a=Arr[0].split(" ").map(Number);
var b=Arr[1].split(" ").map(Number);
var sumA=a.reduce(function(a,b){return a+b;});
var sumB=b.reduce(function(a,b){return a+b;});
console.log(Math.max(sumA,sumB));

Measured memory_bytes: 7380
#include<bits/stdc++.h>
#define rep1(i,n,a) for(int i=0;i<n;i+=a)
#define rep2(i,n,a) for(int i=a;i<n;i++)
#define rep3(n)     for(int i=0;i<n;i++)
#define inarr(arr,n) rep1(i,n,1)cin>>arr[i]
#define ll long long int
#define pb push_back
#define all(v) v.begin(),v.end()
#define trav(a,x) for(auto x:a)
#define endl "\n"
#define eb emplace_back
#define fr first
#define sc second
#define gcd(a,b) __gcd(a,b)
#define pres(a,x) a.find(x)!=a.end()
#define sz(a) (int)a.size()
#define pii pair<int,int>
#define psi pair<string,int>
#define pss pair<string,string>
#define pll pair<ll,ll>
#define vec vector<int>
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define ret return 0
#define pi 3.1415926536
#define hell 1000000007
#define narak 998244353
const int inf1=1e9;
const ll inf2=1e18;
using namespace std;
int dirs[4][2] ={{1,0},{-1,0},{0,1},{0,-1}};
// syntax for min priority_queue of pairs
// priority_queue<pair<ll,ll>,vector<pair<ll,int>>,greater<pair<ll,int>>> q;
int solve(){
  int n,k,s;cin>>n>>k>>s;
  int arr[n]={0};
  rep3(k){
    arr[i]=s;
  }
  int z=s+1;
  if(s==inf1)z=s-1;
  for(int i=k;i<n;i++)arr[i]=z;
  rep3(n)cout<<arr[i]<<" ";cout<<endl;
}
int main(){
    IOS;
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int t=1;//cin>>t;
    while(t--){
        solve();
    }
    ret;
}
 


Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
void solve() {
        int y;
        cin >> y;
        for(int x=y*100/108;;x++) {
                int z = x*108/100;
                if(z == y) {
                        cout << x << endl;
                        return;
                }
                else if(z > y)
                        break;
        }
        cout << ":(" << endl;
        return;
}
int main() {
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        cout.tie(NULL);
        solve();
        return 0;
}



Measured memory_bytes: 256
#include <set>
#include <map>
#include <unordered_map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const double EPS = 1e-9;
const double INF = 2147483647;
#define rep(i, n) rep3(i, 0, n)
#define rep2(i, n) rep3(i, 1, n+1)
#define rep3(i, x, n) for(ll i = x; i < (ll)(n); i++)

template<class T>
void printv(vector<T> v) {
    for(auto it = v.begin(); it != v.end(); it++){
        cout << *it << ",";
    }
    cout << endl;
}

int main(void){
    vector<ll> x(6);
    rep2(i,5)cin>>x[i];
    rep2(i,5)if(x[i]==0)cout<<i;
}


Measured memory_bytes: 3596
import java.util.*;

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

        int n = sc.nextInt();
        int l = sc.nextInt();
        int[] apple = new int[n];

        for(int i = 0; i < n; i++){
            apple[i] = l + i;
        }
        int sum = 0;

        for (int i = 0; i < n; i++)
            sum += apple[i];
        System.out.println(sum - abs_min(apple));
        sc.close();  
    }

    static int abs_min(int[] a){
        int min = a[0];
        for (int i = 1; i < a.length; i++){
            if (Math.abs(a[i]) < Math.abs(min))
                min = a[i];
        }
        return min;
    }
}

Measured memory_bytes: 21716
//#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please

const int cm = 1 << 17;
char cn[cm], * ci = cn + cm, ct;
inline char getcha() {
	if (ci - cn == cm) { fread(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}
inline int getint() {
	int A = 0;
	if (ci - cn + 16 > cm) while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';
	else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
	return A;
}

int D[1001][1001];

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


	int N = getint(), K = getint();

	int gyaku = 0;
	rep(i, N) {
		int x = getint(), y = getint();
		char c = getcha();
		getcha();
		int xx = x / K;
		int yy = y / K;
		if (c == 'W' ^ ((xx ^ yy) & 1)) {
			gyaku++;
			D[x - xx * K][y - yy * K]--;
		}
		else D[x - xx * K][y - yy * K]++;
	}

	for (int i = K - 1; i >= 0; i--) {
		for (int j = K - 1; j >= 0; j--) {
			D[i][j] += D[i][j + 1] + D[i + 1][j] - D[i + 1][j + 1];
		}
	}
	int saidai = -1e9;
	rep(i, K) rep(j, K) {
		int kari = D[i][0] + D[0][j] - D[i][j] - D[i][j];
		saidai = max(saidai, kari);
		saidai = max(saidai, D[0][0] - kari);
	}
	printf("%d", gyaku + saidai);

	Would you please return 0;
}

Measured memory_bytes: 4224
using System;
using System.Collections.Generic;
class Program
{
    static void Main(string[] args)
    {

        while (true)
        {
            //??\???????????°
            int count = int.Parse(Console.ReadLine());
            //???????????¶
            if( count == 0)
            {
                break;
            }
            //??\???
            String[] aryData = Console.ReadLine().Split(' ');

            double sum = 0;
            double average = 0;

            foreach( string s in aryData)
            {
                sum += double.Parse(s);
            }

            average = sum / count;

            sum = 0;

            foreach (string s in aryData)
            {
                sum += (double.Parse(s) - average) * (double.Parse(s) - average);
            }

            Console.WriteLine(string.Format("{0:f8}", Math.Sqrt(sum / count)));

        }
        

       
    }
}

Measured memory_bytes: 9508
from fractions import gcd

N = int(input())
A = list(map(int, input().split()))
curr1, curr2 = [0], [0]
for i in range(N):
  curr1 += [gcd(A[i],curr1[-1])]
  curr2 += [gcd(A[N-1-i],curr2[-1])]

if N ==2:
  print(max(A[0],A[1]))
else:
  ans = []
  for i in range(N):
    ans += [gcd(curr1[i],curr2[N-1-i])]
    
  print(max(ans))

  
  

Measured memory_bytes: 16152
a, b = input().split()
sumA = ""
sumB = ""
for i in range(int(b)):
    sumA +=""+str(a)
for i in range(int(a)):
    sumB +=""+str(b)
if(int(sumA)>int(sumB)):
    print(sumA)
elif(int(sumB)>int(sumA)):
    print(sumB)
elif(int(sumA) == int(sumB)):
    print(sumA)

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

using namespace std;

int main()
{
    int N,med1,med2;
    int buf;
    vector<int> X,Xo;
    

    scanf("%d",&N);
    for(int i=0;i<N;i++)
    {
        scanf("%d",&buf);
        X.push_back(buf);
        Xo.push_back(buf);
    }    
    sort(X.begin(),X.end());

    med1 = X[N/2-1];
    med2 = X[N/2];

    for(int i=0;i<N;i++)
    {
        if(Xo[i]<=med1)        
            printf("%d\n",med2);
        else
            printf("%d\n",med1);        
    }
    return 0;
}

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

int main(void){

	int n,x,y,b,p;

	cin >> n;
	for(int i=0;i<n;i++){
		cin >> x >> y >> b >> p;
		if(b >= 5 && p >= 2)cout << (x * b + y * p)/10*8 << endl;
		else if(b >= 5){
			if(x * b + y * p > (x * b + y * (p + (2 - p)))/10*8)cout << (x * b + y * (p+(2-p)))/10*8 << endl;
			else cout << x * b + y * p << endl;
		}
		else if(p >= 2){
			if(x * b + y * p > (x * (b + (5 - b)) + y * p)/10*8)cout << (x * (b + (5 - b)) + y * p)/10*8 << endl;
			else cout << x * b + y * p << endl;
		}
		else cout << x * b + y * p << endl;
			
	}
	return 0;
}

Measured memory_bytes: 1164
#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(){
    string s;
    cin >> s;
    if(s=="AAA" || s=="BBB") cout << "No" << endl;
    else cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define p pair<int, int>
using namespace std;

struct info{
    int ye, ci, idx; 
};

bool operator<(const info &a, const info &b){
    return a.ye < b.ye;
}

vector<info> v[100005];
int main(){
    int n, m;
    cin >> n >> m;
    for(int i = 0; i < m; i++){
        int pp, y;
        cin >> pp >> y;
        pp--;
        v[pp].push_back((info){y, pp, i});
    }
    vector<p> ans[m];
    for(int i = 0; i < n; i++){
        if(v[i].size() == 0) continue;
        sort(v[i].begin(), v[i].end());
        for(int j = 0; j < v[i].size(); j++){
            ans[v[i][j].idx].push_back(p(v[i][j].ci, j));
        }
    }
    for(int i = 0; i < m; i++){
        printf("%06d%06d\n", ans[i][0].first + 1, ans[i][0].second + 1);
    }
    return 0;
}

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

int main(){
    string s,t;
    int cnt=0;
    cin >>s>>t;
    rep(i,3){
        if(s[i]==t[i]) cnt++;
    }
    cout<<cnt<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;;
#define ll long long
#define rep(i, n) for(int i = 0;i < n;i++)
#define repr(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define INF 1<<30
#define LINF 1LL<<62
#define all(x) (x).begin(), (x).end()
#define mp make_pair
#define pb push_back
const int MOD = 1000000007;
 
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n,q;
  cin >> n>> q;
  vector<ll> s(n),t(n),x(n);
  rep(i,n){
      cin >> s[i] >> t[i] >> x[i];
  }
  vector<ll> d(q);
  rep(i,q){
      cin >> d[i];
  }
  vector<ll> imo[q+1];
  rep(i,n){
      ll st = max(0ll,s[i]-x[i]);
      ll en = max(0ll,t[i]-1-x[i]);
      auto itl = lower_bound(all(d), st);
      auto itu = upper_bound(all(d), en);
      ll poss = itl - d.begin();
      ll pose = itu - d.begin();
      imo[poss].push_back(x[i]);
      imo[pose].push_back(x[i]);
  }
  set<ll> se;
  rep(i,q){
     rep(j,imo[i].size()){
         auto it = se.find(imo[i][j]);
         if(it==se.end()){
             se.insert(imo[i][j]);
         }else{
             se.erase(it);
         }
     }
     if(se.size()){
         cout << *se.begin()<< endl;
     }else{
         cout << -1 << endl;
     }
  }

}

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

typedef long long ll;

const int N = 1e5 + 5;

int n;
ll l;
ll a[N];

int main()
{
	scanf("%d%lld", &n, &l);
	int mark = 0;
	for (int i = 1; i <= n; i ++)
	{
		scanf("%lld", &a[i]);
		if (a[i] + a[i - 1] >= l)
			mark = i;
	}
	if (mark == 0)
	{
		printf("Impossible");
	}
	else
	{
		mark --;
		printf("Possible\n");
		for (int i = 1; i <= mark - 1; i ++)
			printf("%d\n", i);
		for (int i = n - 1; i >= mark + 1; i --)
			printf("%d\n", i);
		printf("%d", mark);
	}
	return 0;
}

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

MOD = 1000000007  # type: int


def fact(a):
    ans = 1
    while a > 0:
        ans *= a
        ans %= MOD
        a -= 1
    return ans


def solve(N: int, M: int):
    if abs(N-M) > 1:
        print(0)
        return
    if N == M:
        print(2*pow(fact(N), 2) % MOD)
    else:
        print(max(N, M)*pow(fact(min(N, M)), 2) % MOD)

    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    solve(N, M)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for(int i=0;i<(int)n;i++)
struct edge{int from, to;};

int main(){
    int h,w;
    cin>>h>>w;
    char s[h][w];
    rep(i,h){
        rep(j,w){
            cin>>s[i][j];
        }
    }
    const int dx[8]={1,0,-1,0,1,-1,-1,1};
    const int dy[8]={0,1,0,-1,1,1,-1,-1};

    rep(i,h){
        rep(j,w){
            if(s[i][j]=='#') continue;

            int num=0;
            for(int d=0;d<8;++d){
                const int ni=i+dy[d];
                const int nj=j+dx[d];

                if(ni<0 or h<=ni) continue;
                if(nj<0 or w<=nj) continue;
                if(s[ni][nj]=='#') num++;
            }
            s[i][j]=char(num+'0');
        }
    }

    rep(i,h){
        rep(j,w){
            cout<<s[i][j];
        }
        cout<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <assert.h>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;
typedef long long ll;
typedef long double ld;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define sz(x) ((int)(x).size())
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<ld> vld;
typedef vector<vector<int>> vvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<ld>> vvd;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;


int main() {
    cout << setprecision(30);
    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);

    ll a, b;
    cin >> a >> b;
    ll ans = (b - 1 + a - 2) / (a - 1);
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <bitset>
#include <string>
#include <cstdio>
#include <math.h>
using namespace std;

const long long int INF = 998244353;

int main(void)
{
    long long N, K;
    cin >> N >> K;
    vector<long long> L(K), R(K);
    for (long long i = 0; i < K; i++)
    {
        cin >> L[i] >> R[i];
    }

    vector<long long> dp(N + 1, 0), dpsum(N + 1,  0);
    dp[1] = 1;
    dpsum[1] = 1;

    for (long long i = 2; i <= N; i++)
    {
        for (int j = 0; j < K; j++)
        {
            int li = i - R[j];
            int ri = i - L[j];
            if (ri < 1) continue;
            li = std::max(li, 1);

            dp[i] += (dpsum[ri] - dpsum[li-1] + INF) % INF;
            dp[i] %= INF;
        }
        dpsum[i] = dpsum[i - 1] + dp[i];
        dpsum[i] %= INF;
    }

    cout << dp[N] << endl;
}

Measured memory_bytes: 6332
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
typedef vector<ll> vl;
typedef pair<vl,vl> t;

int main(){
	string a,b;cin>>a>>b;cout<<b+a<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
#define all(obj) obj.begin(), obj.end()
#define db(x) cerr << #x << ":" << x << " "
#define dbl(x) cerr << #x << ":" << x << "\n"
#define dbv(vec) cerr << #vec << ":"; for (auto e : vec) cerr << e << " "; cout << "\n"
#define dbvv(vv) cerr << #vv << ":\n"; for (auto vec : vv) { for (auto e : vec) cerr << e << " "; cerr << endl; }
#define YN(f) cout << (f ? "YES" : "NO") << endl
#define Yn(f) cout << (f ? "Yes" : "No") << endl
#define yn(f) cout << (f ? "yes" : "no") << endl
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;

int main () {
	int N; cin >> N;
	cout << ((N + 1) / 2) << endl;
}

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

int main(){
  int w,a,b;
  cin >> w >> a >> b;
  
  int ar=a+w, br=b+w;
  if(b > ar) cout << (b-ar) << endl;
  else if(a > br) cout << (a-br) << endl;
  else cout << 0 << endl;
  
  return 0;
}

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

int n,a[100001];

int main(){
    while(cin>>n,n){
        int sum=0,ans=0;
        r(i,n)cin>>a[i],sum+=a[i];
        r(i,n)if(sum>=n*a[i])ans++;
        cout<<ans<<endl;
    }
}


Measured memory_bytes: 3104
#include <iostream>

using namespace std;
int s[14], h[14], c[14], d[14];

int main() {
    int n, num;
    char suit;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> suit >> num;
             if (suit == 'S') s[num] = 1;
        else if (suit == 'H') h[num] = 1;
        else if (suit == 'C') c[num] = 1;
        else if (suit == 'D') d[num] = 1;
    }
    for (int i = 1; i <= 13; ++i) if(!s[i])cout << 'S' << ' ' << i << endl;
    for (int i = 1; i <= 13; ++i) if(!h[i])cout << 'H' << ' ' << i << endl;
    for (int i = 1; i <= 13; ++i) if(!c[i])cout << 'C' << ' ' << i << endl;
    for (int i = 1; i <= 13; ++i) if(!d[i])cout << 'D' << ' ' << i << endl;
    return 0;
}


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

using ll = long long;

int main() {
    ll N, C;
    cin >> N >> C;
    vector<ll> x(N), v(N), rev_x(N), rev_v(N);
    for(int i = 0; i < N; ++i) {
        cin >> x[i] >> v[i];
        rev_x[N - i - 1] = C - x[i];
        rev_v[N - i - 1] = v[i];
    }

    vector<ll> dp1(N + 1), rev_dp1(N + 1);
    vector<ll> dp2(N + 1), rev_dp2(N + 1);
    dp1[0] = rev_dp1[0] = 0;
    dp2[0] = rev_dp2[0] = 0;
    for(int i = 0; i < N; ++i) {
        dp1[i + 1] = (i != 0 ? dp1[i] + x[i - 1] : 0) + v[i] - x[i];
        dp2[i + 1] = (i != 0 ? dp2[i] + 2 * x[i - 1] : 0) + v[i] - 2 * x[i];
        rev_dp1[i + 1] = (i != 0 ? rev_dp1[i] + rev_x[i - 1] : 0) + rev_v[i] - rev_x[i];
        rev_dp2[i + 1] = (i != 0 ? rev_dp2[i] + 2 * rev_x[i - 1] : 0) + rev_v[i] - 2 * rev_x[i];
    }
    ll ans = 0;
    for(int i = 0; i < N; ++i) {
        dp1[i + 1] = max(dp1[i + 1], dp1[i]);
        dp2[i + 1] = max(dp2[i + 1], dp2[i]);
        ans = max({ans, rev_dp1[i + 1], rev_dp2[i + 1]});
    }
    ans = max(ans, dp1[N]);

    for(int i = 0; i < N; ++i) {
        ll t1 = rev_dp1[i], t2 = rev_dp2[i];
        const int rev_pos = N - i;
        t1 += max(dp2[rev_pos], 0LL);
        t2 += max(dp1[rev_pos], 0LL);
        ans = max({ans, t1, t2});
    }
    cout << ans << endl;
}


Measured memory_bytes: 6528
# 初期入力
import sys
input = sys.stdin.readline
N = int(input())
A = list(map(int, input().split()))
A.sort(reverse =True)
A1 =A[1:] +A[1:]
A1.sort(reverse =True)
ans =[A[0]] +A1


print(sum(ans[:N-1]))

Measured memory_bytes: 31276
#include<stdio.h>

int main(){
    int a,b,c;
    scanf("%d %d %d",&a,&b,&c);
    if(a<=b && b<=c)
    printf("%d %d %d\n",a,b,c);
    else if(a<=c && c<=b)
    printf("%d %d %d\n",a,c,b);
    else if(b<=a && a<=c)
    printf("%d %d %d\n",b,a,c);
    else if(b<=c && c<=a)
    printf("%d %d %d\n",b,c,a);
    else if(c<=a && a<=b)
    printf("%d %d %d\n",c,a,b);
    else
    printf("%d %d %d\n",c,b,a);
    return 0;
}


Measured memory_bytes: 2108
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <vector>
#include <cmath>
using namespace std;

int main() {
    int a, b;

    cin >> a >> b;

    cout << ceil((double) (a + b) / 2.0) << endl;
    return 0;
}

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

int main() {
//write your code here
int s,s1,s2,s3;
cin>>s;
s1=s/100;
s2=s/10-s1*10;
s3=s-100*s1-10*s2;

cout<< s1+s2+s3<<endl;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define SIZE 200005
#define INF 1000000005LL
#define MOD 1000000007

using namespace std;
typedef long long ll;
typedef pair <int,int> P;

int K;
int V;

struct edge{int to,cost;};
vector<edge> G[SIZE];
int d[SIZE];

void dijkstra(int s){
	priority_queue<P, vector<P>, greater<P>> que;
	fill(d,d+V,INF);
	d[s] = 0;
	que.push(P(0,s));

	while(!que.empty()){
		P p = que.top();que.pop();
		int v = p.second;
		if(d[v] < p.first)continue;
		for(int i=0;i<G[v].size();i++){
			edge e = G[v][i];
			if(d[e.to] > d[v] + e.cost){
				d[e.to] = d[v] + e.cost;
				que.push(P(d[e.to],e.to));
			}
		}
	}
}

int main()
{
	cin >> K;
	V = K;
	rep(i,0,K){
		G[i%K].push_back((edge){(i+1)%K,1});
	}
	rep(i,0,K) {
		int j = (i*10)%K;
		G[i%K].push_back((edge){j,0});
	}
	dijkstra(1);
	cout << d[0]+1 << endl;

	return 0;
}


Measured memory_bytes: 9084
#include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i,N) for(int i=0;i<N;++i)
typedef long long int LL;

LL N, D, X, ans;

int main()
{
	in >> N >> D >> X;
	std::vector<LL>A(N);
	rep(i, N) in >> A[i];
	rep(i, N)
	{
		LL day = 1;
		while (true)
		{
			if (day > D) break;
			ans++;
			day += A[i];
		}
	}
	out << ans + X << std::endl;
	return 0;
}


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

using ll = long long;

template <typename T>
class fenwick_tree {
public:
    fenwick_tree(int n_) : n(n_), dat(n) {}

    void add(int i, T value) {
        for(; i < n; i |= i + 1) {
            dat[i] += value;
        }
    }

    T sum(int i) const {
        T res = 0;
        for(; i >= 0; i = (i & (i + 1)) - 1) {
            res += dat[i];
        }
        return res;
    }
    T sum(int l, int r) {
        return sum(r - 1) - sum(l - 1);
    }

private:
    const int n;
    vector<T> dat;
};


int main() {
    string s; cin >> s;
    const int n = s.size();
    vector<vector<int>> ps(26);
    for(int i = 0; i < n; ++i) {
        ps[s[i] - 'a'].push_back(i);
    }

    if(2 <= count_if(ps.begin(), ps.end(), [] (auto const& v) { return (v.size() & 1) == 1; })) {
        cout << -1 << endl;
        return 0;
    }

    vector<int> iter(26);
    vector<bool> skip(n);
    fenwick_tree<int> bit(n);
    ll ans = 0, fixed_num = 0;
    for(int i = 0; fixed_num < n / 2; ++i) {
        if(skip[i]) continue;
        const int c = s[i] - 'a';

        if(iter[c] + 1 == (int)ps[c].size()) {
            ans += 1;
            int j = i + 1;
            while(skip[j]) ++j;
            const int c2 = s[j] - 'a';
            swap(s[i], s[j]);
            --ps[c2][iter[c2]];
            ++ps[c][iter[c]];
            --i;
            continue;
        }

        const int l = i + bit.sum(i);
        const int to = n - l - 1;
        const int cur = ps[c].back() + bit.sum(ps[c].back());
        //cout << i << " => l, to, cur: " << l << " " << to << " " << cur << endl;
        assert(cur <= to);
        skip[ps[c].back()] = true;

        ans += to - cur;

        bit.add(ps[c].back(), -1);
        ps[c].pop_back();
        ++fixed_num;
        ++iter[c];
    }

    cout << ans << endl;
}


Measured memory_bytes: 2300
import fractions as f

n,x = list(map(int,input().split()))
if n == 1:
    skip = int(input())
    if x == skip:
        print(0)
    else:
        print(abs(x-skip))
else:
    skip = list(map(int,input().split()))
    skip.append(x)
    skip = sorted(skip)
    margin = list()
    for i in range(len(skip)-1):
        margin.append(skip[i+1]-skip[i])
    margin = sorted(margin)
    test = margin[0]
    for i in range(len(margin)):
        test = f.gcd(test,margin[i])
    print(test)

Measured memory_bytes: 16280
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;

char s[500][500];
int ans[500][500];
int flag[500];

int main() {
  int h, w, k;
  cin >> h >> w >> k;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      cin >> s[i][j];
      if (s[i][j] == '#') {
        flag[i] = 1;
      }
    }
  }

  int cnt = 1, x = 0;
  for (int i = 0; i < h; i++) {
    if (flag[i] == 0) {
      continue;
    }
    for (int j = 0; j < w; j++) {
      if (s[i][j] == '#' && x == 0) {
        ans[i][j] = cnt;
        x++;
      }
      else if (s[i][j] == '#' && x == 1) {
        cnt++;
        ans[i][j] = cnt;
      }
      else {
        ans[i][j] = cnt;
      }
      if (j == w - 1) {
        cnt++;
        x = 0;
      }
    }
  }

  vector<int> z;
  for (int i = 0; i < h; i++) {
    if (flag[i] == 0) {
      z.push_back(i);
    }
    else {
      if (z.size() == 0) {
        continue;
      }
      for (int j = z[0]; j < i; j++) {
        for (int k = 0; k < w; k++) {
          ans[j][k] = ans[i][k];
        }
      }
      z.clear();
    }
  }
  z.clear();
  for (int i = h - 1; i >= 0; i--) {
    if (flag[i] == 0) {
      z.push_back(i);
    }
    else {
      if (z.size() == 0) {
        continue;
      }
      for (int j = z[0]; j > i; j--) {
        for (int k = 0; k < w; k++) {
          ans[j][k] = ans[i][k];
        }
      }
      z.clear();
    }
  }


  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      cout << ans[i][j] << ' ';
    }
    cout << endl;
  }
}

Measured memory_bytes: 1536
def main():
    n = int(input())
    ds = input().split()
    if n % 2:
        print(0)
        return

    nds = sorted(list(map(lambda x: int(x), ds)))
    print(nds[n//2] - nds[(n//2)-1])


if __name__ == '__main__':
    main()


Measured memory_bytes: 15196
import java.util.*;

public class Main{
  public static void main(String[] args) {
    Scanner sc=new Scanner(System.in);
    int a=sc.nextInt();
    int b=sc.nextInt();
    if ((a+b)%2==0) {
      System.out.println((a+b)/2);
    }else{
      System.out.println("IMPOSSIBLE");
    }
  }
}


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

class UnionFind {
  public:

  //par[i]:parent of i. rank[i]:rank(depth) of the group with i.
  vector<int> par, rank; 

  UnionFind(int n) {
    par = vector<int>(n, -1);
    rank = vector<int>(n, 0);
  }

  int root(int x) {               //root(x):root of x
    return (par[x] < 0) ? x : par[x] = root(par[x]);
  }

  int size(int x) {               //the number of edge of the group with x
    return -par[root(x)];
  }

  bool same(int x, int y) {       //judge whether x & y is in the same group.
    return root(x) == root(y);
  }

  void unite(int x, int y) {      //unite group with x & group with y.
    x = root(x);
    y = root(y);
    if (x == y) return;

    if (rank[x] < rank[y]) swap(x, y);
    par[x] += par[y];
    par[y] = x;
    if (rank[x] == rank[y]) rank[x]++;
  }
};


int main() {
  int n, m;
  cin >> n >> m;
  int a[m], b[m];
  rep(i, m) {
    cin >> a[i] >> b[i];
    --a[i]; --b[i];
  }
  
  ll ans[m];
  ans[m-1] = (ll)n * (n-1) / 2;
  UnionFind uni(n);
  for (int i = m-1; i >= 1; --i) {
    if (uni.same(a[i], b[i]) ) {
      ans[i-1] = ans[i];
    }
    else {
      ans[i-1] = ans[i] - (ll)uni.size(a[i]) * (ll)uni.size(b[i]);
      uni.unite(a[i], b[i]);
    }
  }
  
  rep(i, m) {
    cout << ans[i] << endl;
  }
  return 0;
}

Measured memory_bytes: 3712
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; i++)
#define RFOR(i, a, n) for (ll i = (ll)n - 1; i >= (ll)a; i--)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) RFOR(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define bra(first, second) '(' << first << ',' << second << ')'
constexpr ll MOD = 1000000007;
//constexpr ll MOD = 998244353;
ll INF = 1001001001001001001;
long double EPS = 1e-9;
long double PI = 3.141592653589793238;
template <typename T>
void remove(std::vector<T> &vector, unsigned int index)
{
   vector.erase(vector.begin() + index);
}

using Graph = vector<vector<tuple<ll, ll, ll>>>;

// MOD確認

int main(){
   ll A,V,B,W,T;
   cin >> A >> V >> B >> W >> T;
   if(V < W){
      cout << "NO" << endl;
      return 0;
   }
   if(abs(A-B) <= T * abs(V-W))cout << "YES" << endl;
   else cout << "NO" << endl;
}


Measured memory_bytes: 3632
#include <stdio.h>
 
int main(void){
 
  int x, p, i, j, y, h;
  int a[101][101] = {0};
     
  scanf("%d", &x);
   
  for(i = 0; i < x; i++){
    scanf("%d%d", &p, &y);
    for(j = 0; j < y; j++){
      scanf("%d", &h);
      a[p][h] = 1;
    }
  } 

  for(i = 0; i < x; i++){
    for(j = 0; j < x; j++){
      printf("%d%c", a[i+1][j+1], (j == x - 1?'\n':' '));
    }
  }

  return 0;

}

Measured memory_bytes: 648
fun isPrime(x: Int): Boolean {
    var i = 2
    while (i * i <= x) {
        if (x % i == 0) return false
        i++
    }
    return true
}

fun main(args: Array<String>) {
    var x = readLine()!!.toInt()
    while (true) {
        if (isPrime(x)) {
            println(x)
            return
        }
        x++
    }
}

Measured memory_bytes: 31872
money = [int(input()) for i in range(3)]
N = int(input())

res = 0

for l in range(money[0]+1):
    for m in range(money[1]+1):
        for n in range(money[2]+1):
            if N == 500*l + 100*m + 50*n:
                res += 1

print(res)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define MOD 1000000007
const int INF = 1LL<<30;


int main() {
    int n;
    cin>>n;
    vector<pair<ll,int>> v(n);
    vector<ll> a(n),b(n);
    rep(i,n){
        cin>>a[i]>>b[i];
        v[i]={a[i]+b[i],i};
    }

    sort(all(v));
    reverse(all(v));
    ll st=0,sa=0;
    rep(i,n){
        if(i%2==0) st+=a[v[i].second];
        else sa+=b[v[i].second];
    }

    //cout<<st<<" "<<sa<<endl;
    cout<<st-sa<<endl;
}

Measured memory_bytes: 6300
#include <iostream>
#include <vector>
#include <cmath>
#include <iomanip>
#include <algorithm>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)

int main() {
	int a,b;
	cin>>a>>b;
	cout<<a-1+min(1,b/a);
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define Maxn 150007
int n,a,b,cnt,len;
int ans[Maxn],ans1[Maxn];
pair<int,int> que[Maxn];
int main()
{
    scanf("%d%d%d",&n,&a,&b);
    b^=a;
    cnt=0;
    for (int i=0;i<n;i++)
        if ((1<<i)&b) ++cnt;
    if (cnt%2==0)
    {
        printf("NO\n");
        return 0;
    }
    printf("YES\n");
    cnt=0;
    for (int i=0;i<n;i++)
        if ((1<<i)&b) que[++cnt]=make_pair(i,1);
    for (int i=0;i<n;i++)
        if (!((1<<i)&b)) que[++cnt]=make_pair(i,0);
    int t=2;
    ans[1]=0,ans[2]=(1<<que[1].first);
    len=2;
    while (t<=cnt)
    {
        if (que[t].second==1)
        {
            int pos1=que[t].first,pos2=que[t+1].first;
            int val1=(1<<pos1),val2=(1<<pos2);
            t+=2;
            int tmp=0;
            for (int i=1;i<=len;i++)
            {
                if (i==1)
                {
                    ans1[++tmp]=ans[i];
                    ans1[++tmp]=ans[i]^val2;
                    ans1[++tmp]=ans[i]^val1^val2;
                    ans1[++tmp]=ans[i]^val1;
                } else if (i%2==0)
                {
                    ans1[++tmp]=ans[i]^val1;
                    ans1[++tmp]=ans[i];
                    ans1[++tmp]=ans[i]^val2;
                    ans1[++tmp]=ans[i]^val1^val2;
                } else
                {
                    ans1[++tmp]=ans[i]^val1^val2;
                    ans1[++tmp]=ans[i]^val2;
                    ans1[++tmp]=ans[i];
                    ans1[++tmp]=ans[i]^val1;
                }    
            }
            len=tmp;
            for (int i=1;i<=len;i++)
                ans[i]=ans1[i];
        } else
        {
            int pos=que[t].first;
            int val=(1<<pos);
            ++t;
            int tmp=0;
            for (int i=1;i<=len;i++)
            {
                if (i%2==1)
                {
                    ans1[++tmp]=ans[i];
                    ans1[++tmp]=ans[i]^val;
                } else
                {
                    ans1[++tmp]=ans[i]^val;
                    ans1[++tmp]=ans[i];
                }
            }
            len=tmp;
            for (int i=1;i<=len;i++)
                ans[i]=ans1[i];
        }
    }
    for (int i=1;i<=len;i++)
        printf("%d ",ans[i]^a);
    printf("\n");
    return 0;
}

Measured memory_bytes: 4864
import heapq
from collections import deque
from enum import Enum
import sys
import math
from _heapq import heappush, heappop

BIG_NUM = 2000000000
MOD = 1000000007
EPS = 0.000000001


N = int(input())

table = [None] * N
check = [False] * (N+1)
MAP = {}
rev_MAP = {}
perm_index = 0


def recursive(index):
    global perm_index
    if index == N:
        tmp = 0
        for i in range(N):
            tmp = 10*tmp+table[i]

        MAP[perm_index] = tmp
        rev_MAP[tmp] = perm_index
        perm_index += 1
        return

    for i in range(1,(N+1)):
        if check[i]:
            continue
        check[i] = True
        table[index] = i
        recursive(index+1)
        check[i] = False


def outPut(num):
    S = deque()
    while True:
        S.appendleft(num%10)
        num //= 10
        if num == 0:
            break
    print("%d"%(S.popleft()),end="")
    while len(S) > 0:
        print(" %d"%(S.popleft()),end="")
    print()



recursive(0)

tmp = 0

for i in list(map(int,input().split())):
    tmp = 10*tmp+i

index = rev_MAP[tmp]
if index > 0:
    outPut(MAP[index-1])

outPut(tmp)

if index+1 in MAP:
    outPut(MAP[index+1])




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

using namespace std;

const long long INF = 1e9;

vector<vector<long long>> dp;

string s, t;

long long dfs(int pos, char al, int start, int f = 0) {
  auto& res = dp[pos][al-'a'];
  if (res != -1) {
    return res;
  }
  if (s[pos] == al) {
    return res = 1;
  }
  if (start == pos && f) {
    return res = INF;
  }
  res = dfs((pos+1) % s.length(), al, start, 1);
  if (res != INF) res++;
  return res;
}

int main() {
  cin >> s >> t;
  dp.resize(s.length(), vector<long long>(26, -1));
  long long res = 0;
  for (int i = 0; i < t.length(); i++) {
    int r = dfs(res % s.length(), t[i], res % s.length());
    if (r == INF) {
      cout << -1 << endl;
      return 0;
    }
    res += r;
  }
  cout << res << endl;
}

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

int main(){
  int A, B, S;
  cin >> A >> B;
  
  if(A<=5){
    S=0;
  }
  else if(A>=13){
    S=B;
  }
  else{
    S=B/2;
  }
  
  cout << S <<endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <climits>
#include <cstring>
#include <string>
#include <vector>
#include <cmath>
#include <map>

using namespace std;

#define ll long long
#define mod 1000000007
#define vi vector<int>
#define vll vector<ll>
#define pb(x) push_back(x)

ll power(int x, unsigned int y){
    ll res = 1;
    while(y > 0){
        if(y & 1) res = res * x;
        y >>= 1;
        x *= x;
    }
    return res;
}

void solve(){
    ll a, b, c, k;
    cin >> a >> b >> c >> k;

    ll ans = 0;
    if(a >= k && k) ans += k, k = 0;
    else ans += a, k -= a;

    if(b && k) k = max((ll)0, k - b);

    if(k) ans -= k;

    cout << ans;
}

int main(){

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    solve();

}

Measured memory_bytes: 3608
A, B, K = map(int, input().split())
for i in range(K):
    if i % 2 == 0:
        if A % 2 == 1:
            A -= 1
        B += A // 2
        A = A // 2
    else:
        if B % 2 == 1:
            B -= 1
        A += B // 2
        B = B // 2
        
print(str(A) + " " + str(B))

Measured memory_bytes: 3060
a = input()
b = input()

def tonum(x):
    tmp = []
    ans = []
    for i in x:
        if i in tmp:
            ans.append(tmp.index(i))
        else:
            tmp.append(i)
            ans.append(len(tmp)-1)
            
    return(ans)

a = tonum(a)
b = tonum(b)

if(a==b):
    print("Yes")
else:
    print("No")

Measured memory_bytes: 6832
#include<bits/stdc++.h>
using namespace std;
#define forn(i,a,b) for (int i = a; i < b; i++)
int main()
{
    int n,k,i;
  double ans=0.0f;
    cin>>n>>k;
    
    //forn(i,1,n+1)
      for(i=1;i<n+1;i++)
    {
        int p=(k%i!=0)? k/i+1 : k/i;
        int x=ceil(log2(p));
        //cout<<x<<"\n";
        ans+=(1/(double)(n))*pow(0.5,x);
    }
    cout<<setprecision(12)<<ans;
   cout<<endl;
	return 0;
}

Measured memory_bytes: 512
import sys
range = xrange
input = raw_input


n = int(input())
A = [int(x) for x in input().split()]

A.sort()

sign_stack = []
value_stack = [(A[n-1],A[0])]
numb = A[n-1] - A[0]
for i in reversed(range(1,n-1)):
    if A[i] >= 0:
        sign_stack.append(-1)
        numb = -numb
        value_stack.append((A[i], numb))
        numb = A[i] - numb
    else:
        sign_stack.append(1)
        value_stack.append((numb, A[i]))
        numb = numb - A[i]
sign_stack.append(1)

print numb
for sign,(x,y) in zip(sign_stack, value_stack):
    if sign>0:
        print x,y
    else:
        print y,x


Measured memory_bytes: 60128
#include <bits/stdc++.h>
using namespace std;
int main() {
  int r;
  cin >> r;
  if (r < 1200) {
    cout << "ABC" << endl;
  } else if (r < 2800) {
    cout << "ARC" << endl;
  } else {
    cout << "AGC" << endl;
  }
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
  int A,B;
  
  scanf("%d %d",&A,&B);
   
  if(A==1) A=14;
  if(B==1) B=14;
  
  if(A>B) printf("Alice");
  else if(A<B) printf("Bob");
  else printf("Draw");
  
  return 0;
}

Measured memory_bytes: 128