akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include<vector>
#include<climits>
#include<algorithm>
#include<bitset>
#include<cmath>
#include<functional>
#include <numeric>
using namespace std;
using ll = long long;
int main(){
  ll K,A,B;
  ll num=0;
  cin>>K>>A>>B;
  if(A+1>=B||A>=K+1){
    cout<<K+1<<endl;
    return 0;
  }
  K-=(A-1);
  num+=(B-A)*(K/2)+A;
  if(K%2==1){
    num++;
  }
  cout<<num<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib> 
#include <ctime>
#include <unordered_map>
#include <limits.h>
using namespace std;
typedef long long ll;
int main() {
	ll N, A, B;
	cin >> N >> A >> B;
	ll x = B - A;
	if ((x & 0x1) == 0) {
		cout << x / 2 << endl;
	}
	else {
		cout << min(A - 1, N - B) + 1 + (B - A - 1) / 2 << endl;
	}
}

Measured memory_bytes: 256
use fixedbitset::FixedBitSet;
use proconio::{input, marker::Usize1};

fn main() {
    input! {
        n: usize,
        ass: [[Usize1]],
    }

    let mut snukes = FixedBitSet::with_capacity(n);
    for a in ass.into_iter().flatten() {
        snukes.insert(a);
    }
    println!("{}", n - snukes.count_ones(..));
}


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

def main():

    N = int(input())
    S = []
    for i in range(N):
        S.append(input())

    setS = set()

    for i in S:
        setS.add(i)

    ans = len(setS)

    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 35620
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <unordered_map>

using namespace std;
using ll = long long;
constexpr int MOD = 1e9+7;

void _cin(){} template <class Head, class... Tail> void _cin(Head&& head, Tail&&... tail){ cin >> head; _cin(forward<Tail>(tail)...); }
void _cout(){ cout << "\n"; } template <class Head, class... Tail> void _cout(Head&& head, Tail&&... tail){ cout << head; _cout(forward<Tail>(tail)...); }
int gcd(int a, int b){ return (b == 0) ? a : gcd(b, a % b); }

#define Sq(x) (x)*(x)
#define For(i, n) for(int i = 0; i < (n); i ++)
#define Rep(n) For(_, n)
#define Range(c) c.begin(), c.end()
#define RevRange(c) c.rbegin(), c.rend()
#define Contains(c, x) (find(Range(c), x) != c.end())
#define Search(rb, re, x) distance(rb, find(rb, re, x))
#define Sort(a) sort(Range(a))
#define DeSort(a) sort(RevRange(a))
#define Reverse(c) reverse(Range(c))
#define Unique(a) a.erase(unique(Range(a)), a.end())
#define Vec2(T, n, m, xs) vector<vector<T>> xs(n, vector<T>(m))
#define Sum(a) accumulate(Range(a), 0)
#define Cusum(T, xs, sxs) vector<T> sxs(xs.size()+1); For(i, (int)xs.size()) sxs[i+1] = sxs[i] + xs[i]
#define Cin(T, ...) T __VA_ARGS__; _cin(__VA_ARGS__)
#define Cins(T, n, xs) vector<T> xs(n); For(i, n) cin >> xs[i]
#define Cins2(T, n, xs, ys) vector<T> xs(n), ys(n); For(i, n) cin >> xs[i] >> ys[i]
#define Cins3(T, n, xs, ys, zs) vector<T> xs(n), ys(n), zs(n); For(i, n) cin >> xs[i] >> ys[i] >> zs[i]
#define Cinss(T, n, m, xs) Vec2(T, n, m, xs); For(i, n) For(j, m) cin >> xs[i][j]
#define Cinm(T, n, map) unordered_map<T, int> map; Rep(n){ Cin(T, x); map[x] ++; }
#define Cout(...) _cout(__VA_ARGS__)
#define Couts(xs) for(const auto &e : xs) cout << e << " "; cout << "\n"
#define Coutyn(cond) Cout((cond) ? "yes" : "no")
#define CoutYn(cond) Cout((cond) ? "Yes" : "No")
#define CoutYN(cond) Cout((cond) ? "YES" : "NO")

int main(void){
    Cin(int, a, b);
    Cout(max({a+a-1, a+b, b+b-1}));
}

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

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    scanf("%lld",&N);
    long long L;
    scanf("%lld",&L);

    vector<string> S(N);
    for(int i = 0 ; i < N ; i++){
        cin >> S[i];
    }
    sort(S.begin(), S.end());
    for (auto i=S.begin(); i!=S.end(); i++) {
        cout << *i;
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 3668
n,m = gets.chomp.split.map(&:to_i)
ss = n.times.map{gets.chomp.split.map(&:to_i)}
cs = m.times.map{gets.chomp.split.map(&:to_i)}

ss.each do |a,b|
	min_dist = 10**18
	ans = -1
	cs.each_with_index do |(c,d), i|
		dist = (a-c).abs + (b-d).abs
		if dist < min_dist
			ans = i + 1 
			min_dist = dist
		end
	end
	puts ans
end

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

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

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

int main() {
  ll n, g = 0, cnt[1000005] = {};
  cin >> n;

  rep(i, n) {
    ll a;
    cin >> a;
    cnt[a]++;
    g = gcd(g, a);
  }
  bool ok = true;
  for (ll i = 2; i < 1000005; i++) {
    ll sum = 0;
    for (ll j = i; j < 1000005; j += i) sum += cnt[j];
    if (sum > 1) ok = false;
  }
  cout << (ok ? "pairwise coprime" : g == 1 ? "setwise coprime" : "not coprime")
       << endl;
  return 0;
}

Measured memory_bytes: 11416
n = int(input())
a = list(map(int, input().split()))
mod = 1000000007
b = []
for i in range(n):
  b.append(a[i])
i = n-2
while i >= 0:
  b[i] += b[i+1]
  b[i] %= mod
  i -= 1
#print(a)
#print(b)
ans = 0
for i in range(n-1):
  ans += a[i]*b[i+1]%mod
  ans %= mod
print(ans)

Measured memory_bytes: 106636
#include <stdio.h>

int main() {
    int n, rank, markI;
    char markC;
    scanf("%d", &n);
    int card[4][13] = {};
  
    for (int i=0; i<n; i++) {
        scanf("%*c%c %d", &markC, &rank);
        switch (markC) {
            case 'S':
                markI = 0;
                break;
            case 'H':
                markI = 1;
                break;
            case 'C':
                markI = 2;
                break;
            case 'D':
                markI = 3;
                break;
        }
        card[markI][rank-1] = 1;
    }
    for (int j=0; j<4; j++) {
        for (int k=0; k<13; k++) {
            if (card[j][k] == 1) {continue;}
            switch (j) {
                case 0: markC = 'S'; break;
                case 1: markC = 'H'; break;
                case 2: markC = 'C'; break;
                case 3: markC = 'D'; break;
            }
            printf("%c %d\n", markC, k+1);
        }
    }
    return 0;
}



Measured memory_bytes: 2056
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define DUMP(x)  cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for(ll i = m; i < n; i++)
#define IFOR(i, m, n) for(ll i = n - 1; i >= m; i-- )
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define FOREACH(x,a) for(auto& (x) : (a) )
#define ALL(v) (v).begin(), (v).end()

const ll MOD = 1e9+7;

int main(){
  ll n,m; cin >> n >> m;
  vector<ll> s(n), t(m);
  REP(i,n) cin >> s[i];
  REP(i,m) cin >> t[i];

  vector<vector<ll>> dp(n+1, vector<ll>(m+1,0));
  vector<vector<ll>> sum(n+1, vector<ll>(m+1,0));
  dp[0][0] = 1;
  REP(i,n+1) sum[i][0] = 1;
  REP(j,m+1) sum[0][j] = 1;
  
  FOR(i,1,n+1) FOR(j,1,m+1){
    if(s[i-1] == t[j-1]) dp[i][j] = sum[i-1][j-1];
    sum[i][j] = (MOD + sum[i][j-1] + sum[i-1][j] - sum[i-1][j-1] + dp[i][j])%MOD;
  } 
  cout << sum[n][m] << endl;
}


Measured memory_bytes: 62976
#include<string>
#include<stdio.h>
#include<stdlib.h>
using namespace std;

char ctable[4] = {'m', 'c', 'x', 'i'};
int table[4] = {1000, 100, 10, 1};

int rmcxi(){
	int r = 0;
	string s;
	cin>>s;
	int start = 0;
	for(int i = 0; i < s.size();i++){
		for(int j = 0; j < 4; j++){
			if(s[i] == ctable[j]){
				if(start == i){
					r += table[j];
				}else{
					r += atoi(s.substr(start, i-start).c_str()) * table[j];
					#ifdef DEUBG
					cout<<"DEBUG: "<<s.substr(start, i-start)<<endl;
					cout<<"DEBUG r: "<<r<<endl;
					#endif
				}
				start = i+1;
			}
		}
	}
	return r;
}
void wmcxi(int n){
	int num[4];
	for(int i = 0; i < 4; i++){
		num[i] = n/table[i];
		n = n%table[i];
		if(num[i]){
			if(num[i] > 1)cout<<num[i];
			cout<<ctable[i];
		}
	}
	cout<<endl;
}

int main(){
	int N;
	cin>>N;
	while(N--){
		int a, b;
		a = rmcxi();
		b = rmcxi();
		#ifdef DEBUG
		cout<<"a: "<<a<<", b: "<<b<<endl;
		#endif
		wmcxi(a+b);
	}
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
typedef long long lli;
#define mod 1000000007
#define mod2 998244353
#define fori(n) for (int i = 0; i < n; i++)
#define forj(n) for (int j = 0; j < n; j++)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define fast ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define endl "\n"
#define sortvec(a) sort(a.begin(), a.end())

void print(){cout<<endl;}
template<typename T,typename... Args>
void print(T a, Args... args) {cout<<a<<" ";print(args...);}
lli llipowerp(lli x, lli y, lli p)
{
    lli res = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1) res = (res * x) % p;
        y = y >> 1;
        x = (x * x) % p;
    }
    return res;
}
lli binarySearch(vector<int> arr, int l, int r, int x)
{
    if (r >= l)
    {
        lli mid = l + (r - l) / 2;
        if (arr[mid] == x)
            return mid;
        if (arr[mid] > x)
            return binarySearch(arr, l, mid - 1, x);
        return binarySearch(arr, mid + 1, r, x);
    }
    return -1;
}
template <typename T>
inline void printvec(vector<T> inp){
    for(auto it:inp) cout<<it<<" ";
    cout << endl;
}
//---------------------------------------------------------------------------------
lli tsum(lli n){
    return ((n*(n+1))/2)%mod;
}

int main()
{
    lli n,k;
    cin>>n>>k;
    
    lli ans=0;
    vector<lli> sums(n+1,0);
    lli curr=0;
    for(int i=0;i<=n;i++){
        curr+=i;
        curr%=mod;
        sums[i]=curr;
    }
    lli temp=0;
    //printvec(sums);
    for(int i=k;i<=n;i++){
        
        //print(i,sums[n],sums[n-i],sums[i-1]);
        temp=sums[n];
        temp=temp+mod-sums[n-i];
        temp%=mod;
        temp=temp+mod-sums[i-1]+1;
        temp%=mod;
        ans=(ans+temp)%mod;
       //cout<<ans<<endl;
    }
    cout<<ans+1<<endl;

}

Measured memory_bytes: 4844
use proconio::input;

fn main() {
    input! {
        a: i32,
        mut b: i32,
        mut c: i32,
        K: usize,
    }

    let mut flag = false;
    for i in 0..=K {
        for j in 0..=K {
            for k in 0..=K {
                let x = a * (1 << i);
                let y = b * (1 << j);
                let z = c * (1 << k);
                if i + j + k <= K && x < y && y < z {
                    flag = true;
                }
            }
        }
    }

    let ans = if flag { "Yes" } else { "No" };

    println!("{}", ans);
}


Measured memory_bytes: 2140
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;

int main(int argc, char* argv[]){
    int N, a, alice = 0, bob = 0;
    bool b = 0;
    vector<int> v;
    cin >> N;
    for(int i = 0; i < N; i++){
        cin >> a;
        v.push_back(a);
    }
    sort(v.begin(), v.end(), greater<int>());
    for(auto vi:v){
        b ^= 1;
        if(b) alice += vi;
        else bob+= vi;
    }
    cout << alice - bob << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
char a[2005],b[2005];
int n,pre[2005],nxt[2005],ans=1e9,mx[2005];
void solve(){
	for(int i=0;i<n;i++){
		pre[i]=nxt[i]=0;
		for(int p=0;p<n;pre[i]++,p++) if(b[(i-p+n)%n]=='1') break;
		for(int p=0;p<n;nxt[i]++,p++) if(b[(i+p)%n]=='1') break;
	}
	for(int i=0;i<n;i++){
		int tot=0;
		memset(mx,0,sizeof(mx));
		for(int p=0;p<n;p++) if(a[p]!=b[(p+i)%n])
			tot++,mx[pre[p]]=max(mx[pre[p]],nxt[p]-i);
		int mn=1e9,cnt=0;
		for(int p=n-1;~p;p--)
			mn=min(mn,cnt+p),cnt=max(cnt,mx[p]);
		ans=min(ans,2*mn+i+tot);
	}
}
int main(){
	scanf("%s%s",a,b);
	n=strlen(a);
	int suma=0,sumb=0;
	for(int i=0;i<n;i++) suma+=a[i]-'0',sumb+=b[i]-'0';
	if(!sumb&&!suma) return puts("0"),0;
	if(!sumb) return puts("-1"),0;
	solve();
	for(int i=0;i+i<n;i++) swap(a[i],a[n-i-1]),swap(b[i],b[n-i-1]);
	solve();
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 256
import sys

sys.setrecursionlimit(int(1e6))

n, m = map(int, input().split())

graph = {}
graph_rev = {}

for i in range(m):
    s, t = map(int, input().split())
    if s not in graph:
        graph[s] = set()
    graph[s].add(t)
    if t not in graph_rev:
        graph_rev[t] = set()
    graph_rev[t].add(s)

order = []
visited = set()


def dfs1(i):
    visited.add(i)
    if i in graph:
        for t in graph[i]:
            if t not in visited:
                dfs1(t)
    order.append(i)


for i in range(n):
    if i not in visited:
        dfs1(i)

group = [-1] * n
visited.clear()


def dfs2(i, g):
    visited.add(i)
    group[i] = g
    if i in graph_rev:
        for t in graph_rev[i]:
            if t not in visited:
                dfs2(t, g)


group_id = 0

while len(order) > 0:
    v = order.pop()
    if v in visited:
        continue
    dfs2(v, group_id)
    group_id += 1

q = int(input())
ans = []

for i in range(q):
    u, v = map(int, input().split())
    ans.append(1) if group[u] == group[v] else ans.append(0)

for a in ans:
    print(a)



Measured memory_bytes: 22332
#include <iostream>
#include <vector>
#include <cstring>

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

using namespace std;

class Dice {
private:
    vector<int> num, i_num;

public:
    enum FACE {TOP, FRONT, RIGHT, LEFT, BACK, BOTTOM}; 
    enum MOVE {TOP_TO_FRONT, TOP_TO_RIGHT, TOP_TO_LEFT, TOP_TO_BACK, FRONT_TO_LEFT, FRONT_TO_RIGHT};

    const int tb[6][4] = {
        {FRONT, TOP, BACK, BOTTOM},
        {RIGHT, TOP, LEFT, BOTTOM},
        {LEFT, TOP, RIGHT, BOTTOM},
        {BACK, TOP, FRONT, BOTTOM},
        {LEFT, FRONT, RIGHT, BACK},
        {RIGHT, FRONT, LEFT, BACK}
    };

    Dice() 
    { 
        num.assign(6, -1);
        i_num.resize(6);
        i_num = {1, 3, 5, 2, 4, 6};
    }

    Dice(int t, int f) 
    {
        num.resize(6), i_num.resize(6);
        i_num = {1, 3, 5, 2, 4, 6};
        roll(t, f);
    }

    void set_identity(vector<int> i) { num = i_num = i; }

    int top() {return num[TOP];}
    int bottom() {return num[BOTTOM];}
    int right() {return num[RIGHT];}
    int left() {return num[LEFT];}
    int front() {return num[FRONT];}
    int back() {return num[BACK];}
    int get(FACE f) { return num[f]; }

    void rotate(int move)
    {
        int tmp = num[tb[move][0]];
        rep(i, 3) num[tb[move][i]] = num[tb[move][i+1]];
        num[tb[move][3]] = tmp;
    }
    
    bool roll(int t, int f)
    {
        num = i_num;
        for (int j=0; j<6; j++) {
            for (int i=0; i<4; i++) {
                if (num[0] == t && num[1] == f) return true;
                rotate(FRONT_TO_RIGHT);
            }
            if (j%2) rotate(TOP_TO_FRONT);
            else rotate(TOP_TO_RIGHT);
            if (num[0] == t && num[1] == f) return true; // ???????
        }
        return false;
    }

    void print()
    {
        cerr << "[" << num[0] << ", " << num[FRONT] << ", " 
            << num[RIGHT] << "]" << endl;
    };

    bool operator == (const Dice &other) { return num == other.num; }
};

bool equal(Dice &d1, Dice &d2)
{
    bool tmp= false;
    for (int i=0; i<6; i++) {
        for (int j=0; j<4; j++) {
            d1.rotate(d1.FRONT_TO_RIGHT);
            tmp |= (d1 == d2);
        }
        if (i%2) d1.rotate(d1.TOP_TO_RIGHT);
        else d1.rotate(d1.TOP_TO_FRONT);
        tmp |= (d1 == d2);
    }
    return tmp;
}

int main()
{
    int N; cin >> N;
    vector<Dice> d(N);
    rep(i, N) {
        vector<int> tmp(6);
        rep(j, 6) cin >> tmp[j];
        d[i].set_identity(tmp);
    }

    rep(i, N) {
        rep(j, N) {
            if (i == j) continue;
            if (equal(d[i], d[j])) {
                cout << "No" << endl;
                return 0;
            }
        }
    }

    cout << "Yes" << endl;
}

Measured memory_bytes: 3160
#include <stdio.h>

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

	return 0;
}



Measured memory_bytes: 2036
#include<bits/stdc++.h>
#define ll long long int
#define ld long double
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
using namespace std;

int main(){
    fast;
    ll n, x, y, z;
    cin >> n;
    ld ans = 2*n*3.14;
    cout << ans;
    return 0;
}
//                                     #!!{*[$um1t_Kum@r]*}!!#


Measured memory_bytes: 3800
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
using namespace std;

long long cnt;
int l;
int A[1000000];
int n;
std::vector<int> G;

void insertionSort(int A[], int n, int g){
	for(int i=g; i < n; i++){
		int v = A[i];
		int j = i - g;
		while(j>=0 && A[j] > v){
			A[j+g] = A[j];
			j -= g;
			cnt++;
		}
		A[j + g] = v;
	}
}
void shellSort(int A[], int n){
	for(int h = 1; ; ){
		if(h > n) break;
		G.push_back(h);
		h = 3*h + 1;
	} 
	for(int i = G.size()-1; i >= 0; i--){
		insertionSort(A, n, G[i]);
	}
}
int main(){
	cin >> n;
	for(int i = 0; i < n; i++) scanf("%d", &A[i]);
	cnt = 0;
	
	shellSort(A,n);

	cout << G.size() << endl;
	for(int i = G.size()-1; i >= 0; i--){
		printf("%d", G[i]);
		if(i) printf(" ");
	}
	printf("\n");
	printf("%d\n", cnt);
	for(int i = 0; i < n; i++) printf("%d\n", A[i]);
	return 0;
}


Measured memory_bytes: 7212
#define _CRT_SECURE_NO_WARNINGS
//#define _USE_MATH_DEFINES
#include<stdio.h>
//#include<stdlib.h>
//#include<math.h>
#include<string.h>
//#include<time.h>
#define P(type,x) fprintf(stdout,"%"#type"\n",x)

int main() {
	char bw[10], *pt;
	int board[3][3], i, j, k, m, sum[9], f;
	while (1) {
		for (i = 0; i < 3; i++) {
			fscanf(stdin, "%s", bw);
			if (bw[0] == '0') return 0;
			pt = bw;
			j = 0;
			while (*pt) {
				if (*pt == 'b') board[i][j] = 1;
				else if (*pt == 'w') board[i][j] = -1;
				else board[i][j] = 0;
				j++, pt++;
			}
		}
		for (k = 0, i = 0; k < 3; k++, i += 2) {
			sum[i] = board[k][0] + board[k][1] + board[k][2];
			sum[i + 1] = board[0][k] + board[1][k] + board[2][k];
		}
		sum[i] = board[1][1] + board[0][0] + board[2][2];
		sum[i + 1] = board[1][1] + board[0][2] + board[2][0];
		f = 0;
		for (i = 0; i < 9; i++) {
			if (sum[i] == 3) { f = 1; break; }
			else if (sum[i] == -3) { f = 2; break; }
		}
		P(s, f == 1 ? "b" : f == 2 ? "w" : "NA");

	}
	return 0;
}

Measured memory_bytes: 536
from sys import stdin
input = stdin.readline

n = int(input())
s = input()
i, j = 0, n - 1
ans = 0
while i < j:
	while i < j and s[i] == 'R':
		i += 1
	while i < j and s[j] == 'W':
		j -= 1
	if i < j:
		ans += 1
	i += 1
	j -= 1
print(ans)


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

int main() {
	int n;
	cin>>n;
	int a, b;
	cin>>a>>b;
	int c1=0;
	int c2=0;
	int c3=0;
	for(int i=0; i<n; i++){
		int x;
		cin>>x;
		if(x<=a){
			c1++;
		}
		else if(x>=b+1){
			c3++;
		}
		else{
			c2++;
		}
	}
	int mini1=min(c1, c2);
	mini1=min(mini1, c3);
	cout<<mini1;
	return 0;
}

Measured memory_bytes: 3644
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;

// template {{{  0 
// using {{{ 1
using ll = long long int;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vii = vector<pii>;
using vll = vector<pll>;
// }}} 1
// definition {{{ 1
// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x,y) scanf("%d%d", &x, &y)
#define Scd3(x,y,z) scanf("%d%d%d", &x, &y, &z)
#define Scll(x) scanf("%lld", &x)
#define Scll2(x,y) scanf("%lld%lld", &x, &y)
#define Scll3(x,y,z) scanf("%lld%lld%lld", &x, &y, &z)
#define Scc(c) scanf("%c", &c);
#define Scs(s) scanf("%s", s);
#define Scstr(s) scanf("%s", &s);
// }}} 2
// constants {{{ 2
#define EPS (1e-7)
#define INF (2e9)
#define PI (acos(-1))
// }}} 2
// systems {{{ 2
#define Repe(x,y,z) for(ll x = z; x < y; x++)
#define Rep(x,y) Repe(x,y,0)
#define RRepe(x,y,z) for(ll x = y-z-1; x >= 0; x--)
#define RRep(x,y) RRepe(x,y,0)
// }}} 2
// output {{{ 2
#define YesNo(a) (a)?printf("Yes\n"):printf("No\n")
#define YESNO(a) (a)?printf("YES\n"):printf("NO\n")
// }}} 2
// }}} 1
// input {{{ 1
// }}} 1
// }}} 0

int main() {

    int a,b;
    Scd2(a,b);
    int ans = 0;
    Rep(i,a) ans += b;

    printf ("%d\n", ans );

    return 0;
}



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

int main() {
  int a,b,c;
  cin >> a >> b >> c;
  int s;
  s = a + b + c;
 
  if(s >= 22){
    cout << "bust" << endl;
  }
  
  if(s <= 21){
    cout << "win" << endl;
  }
  
  
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
    int y=700,i;
    char S[3];
    cin >> S[0] >> S[1] >> S[2];
    for(i=0; i<3; i++){
        if(S[i] == 'o'){
            y += 100;
        }
    }
    cout << y << endl;
    return 0;
    }

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

int main()
{
    int a,b;
    cin>>a>>b;
    if(a>=13)
    {
        cout<<b<<endl;
    }
    else if(a>=6 && a<=12)
    {
        cout<<(b/2)<<endl;
    }
    else if(a<=5)
    {
        cout<<0<<endl;
    }
}
















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

public class Main{
	 public static void main(String[] args) {
		 char [] station = new char[52];
		 for(int i=0;i<26;i++) {
			 station[i] = (char)('A'+i);
		 }
		 for(int i=0;i<26;i++) {
			 station[i+26] = (char)('a'+i);
		 }
		 Arrays.sort(station);
		 //for(int i=0;i<52;i++) System.err.print(station[i]);
	   
		 try (Scanner sc = new Scanner(System.in)) {
	        while(true) {
	            int n = sc.nextInt();
	            if(n==0) break;
	            int[] key = new int[n];
	            for(int i=0;i<n;i++) {
	            	key[i] = sc.nextInt();
	            }
	            String str = sc.next();
	            String ans = "";
	            for(int i=0;i<str.length();i++) {
	            	char c = str.charAt(i);
	            	int b = key[i%n];
	            	int x = Arrays.binarySearch(station, c);
	            	if(x-b>=0) {
	            		ans += station[x-b];
	            	}else {
	            		ans += station[x-b+52];
	            	}
	            }
	            System.out.println(ans);
	        }
	    }
	 }
}



Measured memory_bytes: 35352
<?php
// $n = (int)trim(fgets(STDIN));
$input = explode(' ', trim(fgets(STDIN)));

$x = (int)$input[0];
$y = (int)$input[1];
$a = (int)$input[2];
$b = (int)$input[3];
$c = (int)$input[4];

$all = [];
$input = explode(' ', trim(fgets(STDIN)));
foreach ($input as $v) {
	$all[] = [
		"v" => (int)$v,
		"s" => "p",
	];
}

$input = explode(' ', trim(fgets(STDIN)));
foreach ($input as $v) {
	$all[] = [
		"v" => (int)$v,
		"s" => "q",
	];
}

$input = explode(' ', trim(fgets(STDIN)));
foreach ($input as $v) {
	$all[] = [
		"v" => (int)$v,
		"s" => "r",
	];
}
usort($all, function($a, $b){
	return $b["v"] - $a["v"];
});
$x_list = [];
$y_list = [];
$r_list = [];
$idx = 0;
while (count($x_list) + count($y_list) + count($r_list) < $x + $y) {
	$tmp = $all[$idx];
	if ($tmp["s"] == "r") {
		$r_list[] = $tmp["v"];
	} elseif ($tmp["s"] == "p" && count($x_list) < $x) {
		$x_list[] = $tmp["v"];
	} elseif ($tmp["s"] == "q" && count($y_list) < $y){
		$y_list[] = $tmp["v"];
	}
	$idx += 1;
}
// var_dump($x_list);
// var_dump($y_list);


echo array_sum($x_list) + array_sum($y_list) + array_sum($r_list);

Measured memory_bytes: 147300
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll; typedef long double ld;
const int INF32 = 1e9+10;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int A[3]; cin >> A[0] >> A[1] >> A[2];
  sort(A, A+3);
  int ans = A[0] + A[1] + A[2]*10;
  cout << ans << endl;
}


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

d=dict()
for i in a:
  if i not in d:
    d[i]=1
  else:
    d[i]+=1
    
#print(d)
    
ans1=dict()
ans2=dict()

for i in d.keys():
  ans1[i]=d[i]*(d[i]-1)//2
  ans2[i]=(d[i]-1)*(d[i]-2)//2
  
#print(ans1)
#print(ans2)
  
s=0
for i in d.values():
  s+=i*(i-1)//2
  
ans=[0 for i in range(n)]
for i in range(n):
  ans[i]=s-ans1[a[i]]+ans2[a[i]]
  
for i in ans:
  print(i)

Measured memory_bytes: 112076
#pragma region
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue> 
#include <stack>
#include <set>
#include <list>

using namespace std;
typedef long long ll;
//#define rep(i, s, e) for (int(i) = (s); (i) < (e); ++(i))
#define rep(i, e) for (int(i) = 0; (i) < (e); ++(i))
#define rrep(i, s) for (int(i) = (s) - 1; (i) >= 0; --(i))
#define all(x) x.begin(),x.end()
#pragma endregion


int main()
{
	string s; cin >> s;
	vector<bool> alp(26, false);
	if (s.size() == 26)
	{
		string tmp = s;
		if (next_permutation(all(tmp)))
		{
			string res = "";
			rep(i, tmp.size())
			{
				res += tmp[i];
				if (tmp[i] != s[i])break;
			}
			cout << res << endl;
		}
		else
		{
			cout << -1 << endl;
		}
	}
	else
	{
		for (char x : s)alp[x - 'a'] = true;
		rep(i, 26)if (!alp[i])
		{
			s.push_back(i + 'a');
			break;
		}
		cout << s << endl;
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <queue>
#include <unordered_map>

using namespace std;

typedef long long lld;

int main()
{
    lld t;
    lld n;
    while(cin >> n) {
        vector<lld> nums;
        for(int i = 0; i < n; ++ i) {
            cin >> t;
            nums.push_back(t);
        }
        lld ans = nums[0] - 1;
        nums[0] = 1;
        lld mins = 1;
        for(int i = 1; i < n; ++ i) {
            if(nums[i] <= mins + 1) {
                mins = max(mins, nums[i]);
                continue;
            }
            lld t = nums[i] / (mins + 1LL);
            if(nums[i] == t * (mins + 1LL)) {
                if(t == 2) {
                    ans ++;
                    nums[i] == 1LL;
                }
                else {
                    ans += t - 1LL;
                    nums[i] = 1LL;
                }
            }
            else {
                nums[i] = 1LL;
                ans += t;
            }

        }

        cout << ans << endl;
    }

    return 0;
}


Measured memory_bytes: 1400
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		FastScanner in = new FastScanner(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskB solver = new TaskB();
		solver.solve(1, in, out);
		out.close();
	}

	static class TaskB {
		public void solve(int testNumber, FastScanner in, PrintWriter out) {
			int n = in.nextInt();
			int[] a = new int[n];
			for (int i = 0; i < n; i++) {
				a[i] = in.nextInt();
			}
			long ans = 0;
			for (int mask = 0; mask + 1 < 1 << n; mask++) {
				long cur = 1;
				for (int i = 0; i < n; i++) {
					int x = 0;
					for (int j = a[i] - 1; j <= a[i] + 1; j++) {
						if ((j % 2 == 0) == ((mask & (1 << i)) == 0)) {
							++x;
						}
					}
					cur *= x;
				}
				ans += cur;
			}
			out.println(ans);
		}

	}

	static class FastScanner {
		private BufferedReader in;
		private StringTokenizer st;

		public FastScanner(InputStream stream) {
			in = new BufferedReader(new InputStreamReader(stream));
		}

		public String next() {
			while (st == null || !st.hasMoreTokens()) {
				try {
					st = new StringTokenizer(in.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return st.nextToken();
		}

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

	}
}



Measured memory_bytes: 23380
def f(n):
  return (n**2-n)//2
ans=0
N=int(input())
d=dict()
for i in range(N):
  s="".join(sorted(input()))
  if s not in d:
    d[s]=0
  d[s]+=1
for i in d:
  ans+=f(d[i])
print(ans)


Measured memory_bytes: 17852
#include<stdio.h>
 
int main(){
  char s[3];
  int counter = 0;
  
  scanf("%s",s);
  
  if(s[0] == '1') ++counter;
  if(s[1] == '1') ++counter;
  if(s[2] == '1') ++counter;
  
  printf("%d",counter);
  
  return 0;
}

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

int main() {
  string s,t;
  cin>>s>>t;
  sort(s.begin(), s.end());
  sort(t.begin(), t.end());
  reverse(t.begin(), t.end());
  if (s<t) puts("Yes");
  else puts("No");
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define rep( i, n, m ) for(int i = ( n ); i < ( m ); i++)
#define rep_d( i, n, m ) for(int i = ( n ) - 1; i >= ( m ); i--)
#define sort_asc( X ) sort(( X ).begin(), ( X ).end())
#define sort_desc( X ) sort(( X ).begin(), ( X ).end(), greater <>())
#define all( X ) ( X ).begin(), ( X ).end()

template <class T> bool chmax( T& a, T b );
template <class T> bool chmin( T& a, T b );
int* eratosthenes( int N );
bool bit_search( int pattern, int N );
template <class T> void cumulative_sum( T array, size_t N );

const ll INF = 1LL << 60;
const int k_mod = 1e9 + 7;

template <typename T, typename K> struct P {
	T a; K b;
};
typedef struct {
	vector <int> to;
	bool is_visited = false;
} node;
typedef struct {
	int to;
	int cost;
	P <int, int> change;
} edge;

int main(){
	int K; cin >> K;
	int surplus7 = 7 % K;
	rep( i, 0, K ){
		if (surplus7 == 0){
			cout << i + 1 << endl;
			return 0;
		}
		surplus7 = ( surplus7 * 10 + 7 ) % K;
	}
	cout << "-1\n";
}

int* eratosthenes( int N ){
	int* prime_array = new int[ N + 1 ];
	int lim = N;
	prime_array[ 0 ] = 0;
	prime_array[ 1 ] = 0;
	rep( i, 2, N + 1 ){
		prime_array[ i ] = 1;
	}
	rep( i, 2, lim ){
		if (prime_array[ i ] == 0)
			continue;
		lim = N / i;
		for(int j = i * 2; j < N + 1; j += i){
			prime_array[ j ] = 0;
		}
	}
	return prime_array;
}
template <class T> void cumulative_sum( T array, size_t N ) {
	rep( i, 1, N + 1 ){
		array[ i ] += array[ i - 1 ];
	}
}
template <class T> bool chmax( T& a, T b ) {
	if (a < b){
		a = b; return true;
	}
	return false;
}
template <class T> bool chmin( T& a, T b ) {
	if (a > b){
		a = b; return true;
	}
	return false;
}
bool bit_search( int pattern, int N ){
	int cnt = 0;
	rep( bit, 0, N ){
		if (pattern & ( 1 << bit )){
			cnt++;
		}
	}
	return true;
}


Measured memory_bytes: 3648
#include <iostream>

using namespace std;

int max(int a, int b){
	if (a > b){
		return a;
	}
	else{
		return b;
	}
}

int min(int a, int b){
	if (a < b){
		return a;
	}
	else{
		return b;
	}
}

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

	int maximum, minimum;

	maximum = min(a,b);
	minimum = max(0,a+b-n);

	cout << maximum << " " << minimum << endl;
	return 0;
}

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

using namespace std;

long a, b, c, d;

long f(long x)
{
	return (x - x/c - x/d + x/(c*d/__gcd(c,d)));
}

void solve(void)
{
	cin >> a >> b >> c >> d;
	cout << f(b) - f(a-1) << endl;
}

int main()
{
	solve();
	//cout << "yui(*-v・)yui" << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long a1[13]={1,2,4,7,12,20,29,38,52,101},a2[13]={1,2,4,7,12,20,30,39,67,101};
long long n,w=1,mp[15][15];
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)mp[i][i]=0;
	for(int i=1;i<=n;i++)
	{
		for(int j=i+1;j<=n;j++)mp[i][j]=mp[j][i]=w*a1[j-i-1];
		w*=a2[n-i];
	}
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=n;j++)cout<<mp[i][j]<<' ';
		cout<<endl;
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
using namespace std;

typedef long long ll;

int main () {
	int N;
	char c[200005];
	cin >> N;
	cin >> c;
	vector <int> w, r;
	int cnt = 0;
	int st = 0;
	int nr=0;
	for (int i=0; i<N; i++) {
		if ((st==0&&c[i]=='R') || (st==1&&c[i]=='W')) {
			if (st==0)
				w.push_back (cnt);
			else 
				r.push_back (cnt);
			st = 1-st;
			cnt = 1;
		} else {
			cnt ++;
		}
		if (c[i]=='R')
			nr ++;
	}
	if (st==0)
		w.push_back (cnt);
	else 
		r.push_back (cnt);
	
	if (w.size()==0 || r.size()==0) {
		cout << 0 << endl;
		return 0;
	} else if (r.size()==1 && c[0]=='R') {
		cout << 0 << endl;
		return 0;
	}


	bool f = c[N-1] == 'W';
	while (c[N-1]=='W')
		N --;

	int wi = 0, ri = r.size()-1, ri2 = 0;
	int wi2 = f ? (w.size()-2) : (w.size()-1);
	int ans = 0, left = 0;
	int right = N-1;
	while (left<right) {
//		cout << left << " " << right << endl;
		if (w[wi]<r[ri]) {
			ans += w[wi];
			left += w[wi] + r[ri2];
			right -= w[wi];
			r[ri] -= w[wi];
			wi ++; ri2++;
		} else if (w[wi]>r[ri]) {
			ans += r[ri];
			left += r[ri];
			right -= r[ri] + w[wi2];
			w[wi] -= r[ri];
			ri --; wi2 --;
		} else {
			ans += w[wi];
			left += w[wi]+r[ri2];
			right -= r[ri]+w[wi2];
			wi ++; ri2 ++;
			ri --; wi2 --;
		}
	}
	if (nr=='W')
		ans ++;

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 4004
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair< ll, ll > Pi;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<=(n);i++)
#define rep3(i,i0,n) for(int i=i0;i<(n);i++)
#define pb push_back
#define mod 1000000007
const ll INF = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}
#define all(x) x.begin(), x.end()
#define mp make_pair
bool compare(Pi a, Pi b) {
    if(a.first != b.first){
        return a.first < b.first;
        
    }else{
        return a.second < b.second;
    }
}


bool In_map(ll y,ll x,ll h,ll w){
    if(y<0 || x<0 || y>=h || x>=w){
        return 0;
    }else{
        return 1;
    }
}
const vector<ll> dx{1,0,-1,0};
const vector<ll> dy{0,1,0,-1};


int main() {
    ll H,W,K;
    cin >>H>>W>>K;

    vector<vector<ll>>  dp(H+1,vector<ll>(W));
    dp[0][0] = 1;
    rep(i,H){
        rep(j,W){
            ll A=0,B=0,C=0;
            rep(bit,1<<(W-1)){
                vector<bool> S(W-1);
                ll flag =0;
                ll p=0;
                rep(k,W-1){
                    if(bit&(1<<k)){
                        S[k]=1;
                    }
                    if(p==1&&S[k]==1){
                        flag =1;
                        break;
                    }
                    p=S[k];
                    
                }
                
                if(flag == 0){
                    ll c=0,a=0;
                    if(j!=0){
                        if(S[j-1]==1){
                            C++;
                            c=1;
                        }
                    }
                    if(j!=W-1){
                        if(S[j]==1){
                            A++;
                            a=1;
                        }
                    }
                    if(c==0&&a==0){
                        B++;
                    }
                    
                } 
            }
            
            if(j!=0){
                dp[i+1][j] = (dp[i+1][j]+dp[i][j-1]*C)%mod;
            }
            if(j!=W-1){
                dp[i+1][j] = (dp[i+1][j]+dp[i][j+1]*A)%mod;
            }
            dp[i+1][j] = (dp[i+1][j]+dp[i][j]*B)%mod;
            
        }
    }
    
    cout << dp[H][K-1] << endl;


    return 0;
    

}

Measured memory_bytes: 3624
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <ctime>
#include <iterator>
#include <bitset>
#include <numeric>
#include <list>
#include <iomanip>
#include <cassert>

#if __cplusplus >= 201103L
#include <array>
#include <tuple>
#include <initializer_list>
#include <unordered_set>
#include <unordered_map>
#include <forward_list>

#define cauto const auto&
#define ALL(v) begin(v),end(v)
#else
#define ALL(v) (v).begin(),(v).end()
#endif

using namespace std;


namespace{
typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
	v.assign(a, vector<T>(b, t));
}
template <class T> inline T &chmin(T &x, const T &y){ return x = min(x, y); }
template <class T> inline T &chmax(T &x, const T &y){ return x = max(x, y); }
template <class F, class T>
void convert(const F &f, T &t){
	stringstream ss;
	ss << f;
	ss >> t;
}


#define REP(i,n) for(int i=0;i<int(n);++i)
#define RALL(v) (v).rbegin(),(v).rend()


#define MOD 1000000007LL
#define EPS 1e-8


void mainmain(){
	int n;
	cin >> n;
	
	int k;
	for(k = 1; ; ++k){
		int ex = k * (k - 1) / 2;
		if(ex > n){
			puts("No");
			return;
		}
		if(ex == n){ break; }
	}

	VV(int) ans(k);
	int val = 0;
	for(int i = 0; i < k; ++i)
	for(int j = i + 1; j < k; ++j){
		++val;
		ans[i].push_back(val);
		ans[j].push_back(val);
	}
	printf("Yes\n%d\n", k);
	for(cauto v : ans){
		printf("%d", (int)v.size());
		for(int x : v){
			printf(" %d", x);
		}
		puts("");
	}
}



}
int main() try{
//	ios::sync_with_stdio(false); cin.tie(0);
	cout << fixed << setprecision(10);
	cerr << fixed << setprecision(4);
	mainmain();
}
catch(...){}


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


int main() {
    double a, b, x; cin >> a >> b >> x;

    double ans;
    if (x <= (a * a * b) / 2.0){
        double theta_rad = atan((2.0 * x) / (a * b * b));
        ans = theta_rad * (180.0 / M_PI);
        ans = 90.0 - ans;
    } else {
        double theta_rad = atan(2.0 * (a * a * b - x) / (a * a * a));
        ans = theta_rad * (180.0 / M_PI);
    }

    cout << fixed;
    cout << setprecision(6);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <complex>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <cstring>
#include <stack>
#include <cmath>
#include <iomanip>
#include <sstream>
#include <cassert>

using namespace std;

typedef long long ll;
typedef ll li;
typedef pair<int,int> PI;
#define EPS (1e-10L)
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define F first
#define S second
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define SZ(a) (int)((a).size())
#define ALL(a) a.begin(),a.end()
#define FOR(it,a) for(__typeof(a.begin())it=a.begin();it!=a.end();++it)
void pkuassert(bool t){t=1/t;};
/*
int dx[]={0,1,0,-1,1,1,-1,-1};
int dy[]={1,0,-1,0,-1,1,1,-1};
*/

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

priority_queue<pair<PI,vector<PI> > > q;
vector<PI> cv;
set<PI> rock;
set<vector<PI> > app;
PI cc;

int dist(PI a,PI b){
  int cx=a.F-b.F;
  int cy=a.S-b.S;
  if(cx==0 && cy==0) return 0;
  rep(i,6)
    if(cx==dx[i] && cy==dy[i]) return 1;

  return 2;
}

map<PI,int> shortest;
int X,Y;
void next(int idx){

  if(idx==n){
    if(app.count(cv)) return;
    rep(i,n){
      if(i && dist(cv[i-1],cv[i])!=1) return;
      if(i+1<n && dist(cv[i],cv[i+1])!=1) return;
      for(int j=0;j<=i-2;++j)
        if(dist(cv[i],cv[j])<=1) return;
    }
    int ddx=X-cv[0].F;
    int ddy=Y-cv[0].S;
    if(!shortest.count(mp(ddx,ddy))) return;
    if((shortest[mp(ddx,ddy)]-cc.S+1)>20) return;
    q.push(mp(mp(-(shortest[mp(ddx,ddy)]-cc.S+1),cc.S-1),cv));
    return;
  }
  
  next(idx+1);
  
  rep(i,6){
    cv[idx].F += dx[i];
    cv[idx].S += dy[i];
    if(!rock.count(cv[idx]) &&
       (idx==0 || dist(cv[idx],cv[idx-1])==1))
      next(min(idx+2,n));
    cv[idx].F -= dx[i];
    cv[idx].S -= dy[i];
  }
}



void solve(){
  cv.clear();
  cv.resize(n);
  rep(i,n) cin >> cv[i].F >> cv[i].S;
  int k;
  cin >> k;
  rock.clear();
  rep(i,k) {
    int x,y;
    cin >> x >> y;
    rock.insert(mp(x,y));
  }
  cin >> X >> Y;
  q=priority_queue<pair<PI,vector<PI> > >();
  q.push(mp(mp(0,0),cv));
  app.clear();
  int oc=0;
  while(!q.empty()){
    cc=q.top().F;
    cv=q.top().S;
    q.pop();
    int dix=cv[0].F-X;
    int diy=cv[0].S-Y;
    if(-cc.F>20) continue;
    if(-cc.S>20) return;
    if(app.count(cv)) continue;
    if(cv[0].F==X && cv[0].S==Y){
      cout << -cc.S << endl;
      return;
    }
    if(cc.S!=oc){
      oc=cc.S;
      //cout << cc << endl;
    }
    app.insert(cv);
    next(0);
  }
  cout << -1 << endl;
}

int main(int argc, char *argv[])
{
  queue<pair<PI,int> > q;
  q.push(mp(mp(0,0),0));
  while(!q.empty()){
    PI cv=q.front().F;
    int cc=q.front().S;
    q.pop();
    if(shortest.count(cv)) continue;
    if(cc>20) continue;
    shortest[cv] = cc;
    rep(i,6) q.push(mp(mp(cv.F+dx[i],cv.S+dy[i]),cc+1));
  }
  
  while(cin >> n && n) solve();
  return 0;
}

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

using namespace std;

#define rep(i, n) for (int i = 0; i < n; ++i)
#define stl_rep(itr, x) for (auto itr = x.begin(); itr != x.end(); ++itr)
#define stl_repr(itr, x) for (auto itr = x.rbegin(); itr != x.rend(); ++itr)
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()

using llong = long long int;

const static int MOD = 1000000000 + 7;
const static int inf = INT_MAX / 2;
const static llong INF = 1LL << 31;
const static int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

int main (int argc, char *argv[]) {
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n;
    cin >> n;

    if (n >= 1 && n <= 9) {
        cout << n << endl;
    } else if (n >= 10 && n <= 99) {
        cout << 9 << endl;
    } else if (n >= 100 && n <= 999) {
        cout << 9 + n - 100 + 1 << endl;
    } else if (n >= 1000 && n <= 9999) {
        cout << 909 << endl;
    } else if (n >= 10000 && n <= 99999) {
        cout << 909 + n - 10000 + 1 << endl;
    } else {
        cout << 90909 << endl;
    }

    return 0;
}

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

class Factorial {
    public:
        friend class Combination; // 組み合わせ
        Factorial(const unsigned int mod, const unsigned int size) : m_mod(mod), m_size(size) {
        }
        ~Factorial() {
            delete[] m_fact;
            delete[] m_inv;
            delete[] m_fact_inv;
        }
        // 階乗テーブルの計算
        void InitFact() {
            m_fact = new unsigned long long int [m_size];
            m_fact[0] = 1;
            m_fact[1] = 1;
            for (unsigned int i = 2; i < m_size; ++i) {
                m_fact[i] = m_fact[i - 1] * i % m_mod;
            }
            return;
        }
        void InitFactInv() {
            m_inv = new unsigned long long int [m_size];
            m_fact_inv = new unsigned long long int [m_size];
            m_inv[1] = 1;
            m_fact_inv[0] = 1;
            m_fact_inv[1] = 1;
            for (unsigned int i = 2; i < m_size; ++i) {
                m_inv[i] = m_mod - m_inv[m_mod % i] * (m_mod / i) % m_mod;
                m_fact_inv[i] = m_fact_inv[i - 1] * m_inv[i] % m_mod;
            }
        }
        void Init() {
            InitFact();
            InitFactInv();
            return;
        }
    private:
        const unsigned int m_mod;
        const unsigned int m_size;;
        unsigned long long int* m_fact;
        unsigned long long int* m_inv;
        unsigned long long int* m_fact_inv;
};

class Combination {
    public:
        const static unsigned long long int nCk(const unsigned int n, const unsigned int k, Factorial& fact) {
            return fact.m_fact[n] * (fact.m_fact_inv[k] * fact.m_fact_inv[n - k] % fact.m_mod) % fact.m_mod;
        }
};

const static unsigned int MOD = 1e9 + 7;

int main(void) {
    int h, w, a, b;
    cin >> h >> w >> a >> b;
    Factorial fact(MOD, h + w);
    fact.Init();
    long long int result = 0;
    for (int i = b; i < w; ++i) {
        result += (Combination::nCk(i + h - a - 1,  i, fact) * Combination::nCk(a + w - i - 2 , a - 1, fact) % MOD);
        result %= MOD;
    }
    cout << result << endl;
    return 0;
}



Measured memory_bytes: 8012
#include<bits/stdc++.h>
using namespace std;
int main()
{	
    int m;
    cin>>m;
    
    int q;
	cin>>q;
	
	string s;
	cin>>s;
	
    int a[m+1];
    a[0]=0;
    
    for(int i=1;i<m;i++)
    {
    	if(s[i-1]=='A' && s[i]=='C')
    	{
    		a[i]=a[i-1]+1;
    		
		}
		
		else
		
		    a[i]=a[i-1];
	}
	
	for(int i=1;i<=q;i++)
	{
		int x,b;
		cin>>x>>b;
		cout<<a[b-1]-a[x-1]<<endl;
	}
	return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define REP(a,b,c) for(int a=b; a<(int)c; a++)
#define REPE(a,b,c) for(int a=b; a<=(int)c; a++)
#define REPD(a,b,c) for(int a=b; a>=(int)c; a--)
#define rep(a,b) REP(a,0,b)
#define repd(a,b) REPD(a,b,0)
typedef long long int ll;
using namespace std;

int main(){
  while(true){
    int a,L;
    cin >> a >> L;
    if(a==0 && L==0) break;
    map<int, int> n_map;
    int cnt = 0;
    while(true){
      if(n_map.find(a) != n_map.end()) break;
      n_map[a] = cnt++;
      vector<int> list;
      rep(i,L){
        list.push_back(a%10);
        a /= 10;
      }
      sort(list.begin(),list.end());
      int max_num = 0, min_num = 0;
      rep(i,L){
        max_num *= 10;
        max_num += list[L-i-1];
        min_num *= 10;
        min_num += list[i];
      }
      a = max_num - min_num;
    }
    cout << n_map[a] << " " << a << " "<< cnt-n_map[a] << endl;
  }
  return 0;
}

Measured memory_bytes: 1212
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
    string a,b;
    cin>>a;
    cin>>b;
    int i = 0;
    for(i = 0; i < a.length(); i++){
        a = a[a.length()-1] + a;
        a.pop_back();
        if(a == b){
            cout<<"Yes"<<endl;
            break;
        }
    }

    if(i == a.length()){
        cout<<"No"<<endl;
    }
}

Measured memory_bytes: 256
import java.util.Arrays;
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(b%a==0){
        System.out.println(a+b);
      }else{
        System.out.println(b-a);
      }
    }
}


Measured memory_bytes: 22740
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int H, W, i1, i2;
    
    
    while (1) {
    
        cin >> H >> W;
        if (H == 0 && W == 0) break;
            
        for (i1=0; i1<H; i1++) {
            
            for (i2=0; i2<W; i2++){
                cout << "#";
            }
            
            cout << endl;
        }
        
        cout << endl;
        
    }
    
}

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

int main() {
  int n;
  cin >> n;
  vector<int> L(n);
  rep(i,n) cin >> L[i];
  sort(L.begin(), L.end());
  int ans = 0;
  rep(b,n) {
    int r = b+1;
    rep(a,b) {
      int ab = L[a]+L[b];
      while (r < n && L[r] < ab) ++r;
      int l = b+1;
      ans += max(0,r-l);
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256