akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<climits>
#include<iostream>
#include<string>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<map>
#include<set>

using  ll = long long;
using ull = unsigned long long;
using namespace std;
#define pb push_back
int dy[]={0, 0, 1, -1, 1, 1, -1, -1};
int dx[]={1, -1, 0, 0, 1, -1, -1, 1};
constexpr ll kINF = 1152921504606846976;//2^60
constexpr double kEPS = 1e-6;

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define rep(i,n) REP(i,n)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep(i,n) RREP(i,n)
#define mp make_pair
#define fi first
#define sc second

ll H,W;
char a[1010][1010];

ll dp[1010][1010];

constexpr ll p = 1000000007;

static inline ll mod(ll a) {return a % p;}
static inline void modadd(ll& a, ll b) {a = mod(a + b);} 

int main(void) {
  cin >> H >> W;

  rep (i, H)
    cin >> &a[i][0];

  dp[0][0] = 1;

  rep (i, H) {
    rep (j, W) {
      if (a[i][j] == '#') continue;

      if (i > 0) modadd(dp[i][j], dp[i - 1][j]);
      if (j > 0) modadd(dp[i][j], dp[i][j - 1]);
    }
  }

  cout << dp[H-1][W-1] << endl;
}

Measured memory_bytes: 9216
import copy
import time
import random

t1 = time.time()

def calc(T):
    res = 0
    L = [0]*26
    for i in range(D):
        res += S[i][T[i]-1]
        L[T[i]-1] = i+1
        for j in range(26):
            res -= C[j]*(i+1-L[j])
    return res
    
D = int(input())
C = [int(c) for c in input().split()]
S = [[int(s) for s in input().split()] for _ in range(D)]

T = [0]*D
for i in range(D):
    temp = -1
    for j in range(26):
        if temp < S[i][j]:
            temp = S[i][j]
            idx = j+1
    T[i] = idx

p = calc(T)

while time.time()-t1 < 1.8:
    i = random.randint(0, D-1)
    for j in range(26):
        temp = copy.deepcopy(T)
        temp[i] = j+1
        newp = calc(temp)
        if p < newp:
            T[i] = j+1
            p = newp

for t in T:
    print(t)

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

using namespace std;

#define endl            "\n"
#define sz(x)          (int) (x.size())
#define all(v)          v.begin(), v.end()
#define isOdd(n)       (n&1)
#define pow(n, m)      (ll)powl(n, m)
#define clr(x, val)     memset(x, val, sizeof(x))

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


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

    int n; cin >> n;
    pair<int, int> d1, d2;
    for(int i = 0; i < n; i++){
        int a1, a2; cin >> a1 >> a2;
        if(!i) d1 = {a1, a2};
        else if(i == 1) d2 = {a1, a2};
        else{
            if(d1.first == d1.second && d2.first == d2.second &&  a1 ==  a2)
                return cout << "Yes", 0;
            d1 = d2, d2 = {a1, a2};
        }
    }
    cout << "No";
    return 0;
}


Measured memory_bytes: 3636
line1 = input()
post1, post2 = map(int, line1.split())

postal_list = postal_code = input().split("-")

if len(postal_list) == 2:
    if post1 == len(postal_list[0]) and post2 == len(postal_list[1]):
        print ("Yes")
    else:
        print ("No")
else:
    print ("No")


Measured memory_bytes: 2940
#include <iostream>
#include <vector>
#include <queue>
#include <string>
#include <algorithm>
#define PI 3.141592653589
typedef long long ll;
const int MOD = 1000000007;
const int INF = 2002002002;
const int di[] = { -1, 0, 1, 0 };
const int dj[] = { 0, -1, 0, 1 };
using namespace std;

int main() {
	int n, m;
	cin >> n >> m;
	// それぞれの展望台について
	vector<int> h(n);
	for (int i = 0; i < n; i++)
		cin >> h[i];
	vector<int> a(m), b(m);
	for (int i = 0; i < m; i++) {
		cin >> a[i] >> b[i];
		a[i]--;
		b[i]--;
	}
	vector<vector<int>> com(n);
	int ans = 0;
	for (int i = 0; i < m; i++) {
		// com[i] : 展望台a[i]がつながっている展望台
		com[a[i]].push_back(b[i]);
		com[b[i]].push_back(a[i]);
	}
	for (int i = 0; i < n; i++) {
		int count = 0;
		for (int j = 0; j < com[i].size(); j++) {
			if (h[i] > h[com[i][j]])
				count++;
		}
		if (count == com[i].size())
			ans++;
	}
	cout << ans << endl;
	return 0;
}


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

using ll = long long;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define ddrep(i, n) for (int i = n; i > 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define ssrep(i, s, t) for (int i = s; i <= t; ++i)

#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))

using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
    os << "(" << p.first << "," << p.second << ")";
    return os;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
    os << "{";
    rep(i, (int)v.size()) {
        if (i)
            os << ",";
        os << v[i];
    }
    os << "}";
    return os;
}

template <typename T, size_t S> void printArray(const T (&array)[S]) {
    for (auto val : array)
        std::cout << val << ", ";
    std::cout << "\n";
}

const int mod = 1e9 + 7;
const int inf = 1e9 + 5;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << std::setprecision(10);

    int n; std::cin >> n;
    vi cnt(27, inf);
    rep(i, n) {
        string s; std::cin >> s;
        vi tmp(27);
        for (char &c : s) {
            tmp[c-'a']++;
        }
        rep(j, 27) chmin(cnt[j], tmp[j]);
    }
    string ans;
    rep(i, 27) {
        rep(j, cnt[i]) ans += 'a'+i;
    }
    std::cout << ans << "\n";
}


Measured memory_bytes: 256
/*
Cerberus97
Hanit Banga
*/

#include <iostream>
#include <iomanip>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>

using namespace std;

#define pb push_back
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL)

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

const int N = 1e5 + 10;
const ll inf = 1e17, SX = 1e15;

struct edge {
	int v; ll w;
};

vector<edge> g1[N], g2[N];
ll dist1[N], dist2[N], ans[N];

void dijkstra(vector<edge> *g, ll *dist, int s, int n);

int main() {
	fast_cin();
	int n, m, s, t;
	cin >> n >> m >> s >> t;
	for (int i = 1; i <= m; ++i) {
		int u, v, a, b;
		cin >> u >> v >> a >> b;
		g1[u].pb({v, a});
		g1[v].pb({u, a});
		g2[u].pb({v, b});
		g2[v].pb({u, b});
	}
	dijkstra(g1, dist1, s, n);
	dijkstra(g2, dist2, t, n);
	for (int u = 1; u <= n; ++u) {
		ans[u - 1] = dist1[u] + dist2[u];
	}
	for (int i = n - 2; i >= 0; --i) {
		ans[i] = min(ans[i], ans[i + 1]);
	}
	for (int i = 0; i <= n - 1; ++i) {
		cout << SX - ans[i] << '\n';
	}
}

void dijkstra(vector<edge> *g, ll *dist, int s, int n) {
	for (int i = 1; i <= n; ++i) {
		dist[i] = inf;
	}
	dist[s] = 0;
	priority_queue<pll, vector<pll>, greater<pll>> pq;
	pq.push({0, s});
	while (!pq.empty()) {
		auto cur = pq.top();
		pq.pop();
		int u = cur.second;
		if (dist[u] < cur.first) {
			continue;
		}
		for (auto &e : g[u]) {
			if (dist[u] + e.w < dist[e.v]) {
				dist[e.v] = dist[u] + e.w;
				pq.push({dist[e.v], e.v});
			}
		}
	}
}

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

using namespace std;


int main()
{
	int a,b ,c;
	int  k;
	cin >> a >> b>>c;
	cin >> k;
	cout << a + b + c + max(max(a, b), c)*(pow(2, k) - 1)<<endl;
    return 0;
}



Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define np next_permutation
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define pi acos(-1.0)
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
//cout << fixed << setprecision (20);   小数点以下2０桁まで
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'0'+=16;        で大文字に
//'大文字'+=32;    で小文字に
//s[i]-'0'でchar文字→int数に;
//string s = to_string(int数);
//int n = stoi(string文字列)
//実行時間制約2秒では２×10^8回くらいまで計算できる


int main() {
  int m,d;
  cin >> m>>d;
  
  int ans = 0;
  
  for(int i=4;i<=m;i++){
    for(int j=22;j<=d;j++){
      if(j/10>=2 && j%10>=2 && (j/10)*(j%10)==i) ans++;
    }
  }
    
  cout << ans << endl;
  
}

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

# AtCoder Beginner Contest
# Problem C

if __name__ == '__main__':
    n = int(input())
    a = list(map(int, input().split()))
    count = 0

    from collections import Counter
    counted_a = Counter(a)

    for x in counted_a:
            if counted_a[x] >= x:
                count += counted_a[x] - x
            else:
                count += counted_a[x]

    print(count)


Measured memory_bytes: 18164
#include<bits/stdc++.h>
#define inf 1000000000
#define ll long long
using namespace std;
int main()
{
    int n;
    scanf("%d",&n);
    if(n%2==0)
        printf("%lf",0.5);
    else
        printf("%lf",(n/2+1)/(double)(n));
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int maxn = 200005;
const int maxm = maxn*10;
const int inf = 0x3f3f3f3f;
typedef long long ll;

int a[maxn];
ll sum[maxn];
ll cal(int l,int r){
    return sum[r] - sum[l-1];
}
int main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int n;
    cin>>n;
    for(int i = 1;i<=n;i++) {
        cin>>a[i]; sum[i] = sum[i-1] + a[i];
    }
    ll ans = 2e18;
    int l = 1,r = 3;
    for(int i = 2;i<=n-2;i++) {
        while(l+1<i && abs(cal(1,l)-cal(l+1,i)) >= abs(cal(1,l+1)-cal(l+2,i))) ++l;
        while(r+1<n && abs(cal(i+1,r)-cal(r+1,n)) >= abs(cal(i+1,r+1)-cal(r+2,n))) ++r;
        vector<ll>v;
        v.push_back(cal(1,l));
        v.push_back(cal(l+1,i));
        v.push_back(cal(i+1,r));
        v.push_back(cal(r+1,n));
        sort(v.begin(),v.end());
        ans = min(ans,abs(v[0] - v[3]));
    }
    cout<<ans<<'\n';
    return 0;
}

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

map <string, string> child_parent;
string lastname[2000];

bool child(string a, string b){
	if (child_parent[a] == b) return true;
	else return false;
}

bool parent(string a, string b){
	if (a == child_parent[b]) return true;
	else return false;
}

bool sibling(string a, string b){
	if (child_parent[a] == child_parent[b]) return true;
	else return false;
}

bool ancestor(string a, string b){
	if (child_parent[b] == "none") return false;
	else if (parent(a, b)) return true;
	else return ancestor(a, child_parent[b]);
}

bool descendant(string a, string b){
	return ancestor(b, a);
}

int main(void){

	int n, m;

	while (cin >> n >> m, n, m){

		child_parent.clear();
		cin.ignore();

		for (int i = 0; i < n; i++){
			string s;
			getline(cin, s);

			int count = 0;
			for (int j = 0; j < s.size(); j++){
				if (s[j] == ' ') count++;
			}

			if (count == 0) child_parent[s] = "none";
			else child_parent[s.substr(count)] = lastname[count - 1];

			lastname[count] = s.substr(count);

		}

		for (int i = 0; i < m; i++){
			string a, b,relate, buff;
			cin >> a >> buff >> buff >> relate >> buff;
			char bb[200];
			scanf(" %[^.].", &bb);
			b = bb;

			bool flag = false;
			if (relate == "child") flag = child(a, b);
			else if (relate == "parent") flag = parent(a, b);
			else if (relate == "sibling") flag = sibling(a, b);
			else if (relate == "descendant") flag = descendant(a, b);
			else if (relate == "ancestor") flag = ancestor(a, b);

			if (flag) cout << "True" << endl;
			else cout << "False" << endl;
		}

		

		cout << endl;

	}

	return 0;
}

Measured memory_bytes: 1396
#include<bits/stdc++.h>
#define MAX 2000001
#define VMAX 10000
using namespace std;

int main() {
  int C[VMAX+1];
  int n; scanf("%d", &n);
  vector<int> A(n+1),B(n+1);

  for (int i=0;i<=VMAX;i++) C[i]=0;
  for (int i=0;i<n;i++) {
    scanf("%d", &A[i+1]);
    C[A[i+1]]++;
  }

  for (int i=1;i<=VMAX;i++) C[i]=C[i]+C[i-1];
  for (int i=1;i<=n;i++) {
    B[C[A[i]]]=A[i];
    C[A[i]]--;
  }
  for (int i=1;i<=n;i++) {
    if (i>1) printf(" ");
    printf("%d", B[i]);
  }
  printf("\n");
  return 0;
}


Measured memory_bytes: 18408
#include <bits/stdc++.h>
using namespace std;
string s,t,ss;
int dp[3001][3001];
int nxt[3001][3001];
int f(int p,int q){
	if(p==s.size() || q==t.size())return 0;
	int &ans=dp[p][q];
	if(~ans)return ans;
	ans=0;
	if(s[p]==t[q]){
		ans=f(p+1,q+1)+1;
	}
	ans=max(ans,f(p+1,q));
	ans=max(ans,f(p,q+1));
	if(s[p]!=t[q])ans=max(ans,f(p+1,q+1));
	return ans;
}
int dx[]={1,0,1};
int dy[]={1,1,0};
int main(int argc, char const *argv[])
{
	memset(dp,-1,sizeof dp);
	cin>>s>>t;
	s+="$";
	t+="#";
	int x=0,y=0,len=f(0,0),ll=0;
	while(len!=ll){
		for(int i=0;i<3;i++){
			int val=dp[x+dx[i]][y+dy[i]]+(i==0 && s[x]==t[y]);
			if(val==dp[x][y]){
				if(i==0 && s[x]==t[y]){
					ss+=s[x];
					ll++;
				}
				x+=dx[i];
				y+=dy[i];
				break;
			}
		}
	}
	cout<<ss<<endl;
	return 0;
}

Measured memory_bytes: 36224
#include <bits/stdc++.h>
#define ll long long

using namespace std;

const int maxm = 18;
const int maxn = (1<<16) + 100;
const int base = (int)1e9+7;

int a[maxn],fact[maxn],finv[maxn],f[maxm][maxn],res,n,m;

int sum(int a,int b) {
    return (a+b)%base;
}

int sub(int a, int b) {
    return (a-b+base)%base;
}

int mul(int a,int b) {
    return (a*1ll*b)%base;
}

int power(int a,int b) {
    int res=1;
    while (b>0) {
        if (b&1) {
            res = mul(res,a);
        }
        a = mul(a,a);
        b>>=1;
    }
    return res;
}

int inv(int a) {
    return power(a,base-2);
}

int C(int k,int n) {
    if (n<k) return 0;
    return mul(fact[n],mul(finv[k],finv[n-k]));
}

int main() {
  //  freopen("in.txt","r",stdin);
   // freopen("out.txt","w",stdout);
    ios_base::sync_with_stdio(0); cin.tie(0);
    fact[0] = 1; fact[1] = 1;
    finv[0] = 1; finv[1] = 1;
    for (int i=2;i<=maxn;i++) {
        fact[i] = mul(fact[i-1],i);
        finv[i] = inv(fact[i]);
        //cout<<fact[i]<<endl;
    }
    cin>>n>>m;
    vector<int> a;
    for (int i=1;i<=m;i++) {
        int x;
        cin>>x;
        a.push_back(x);
    }
   // cout<<n<<" "<<m<<" "<<(1<<n)<<endl;
    reverse(a.begin(),a.end());
    f[0][0]= 1;
    for (int i=0;i<m;i++)
        for (int tt=0;tt<(1<<n);tt++) {
            if (f[i][tt] < 1) continue;
            f[i+1][tt] = sum(f[i+1][tt],f[i][tt]);
            for (int j=0;j<n;j++)
                if ((tt & (1<<j)) == 0) {
                   // cout<<C((1<<j) - 1,(1<<n) - tt - a[i])<<" "<<fact[1<<j]<<endl;
                    f[i+1][tt + (1<<j)] = sum(f[i+1][tt + (1<<j)],mul(f[i][tt],mul(C((1<<j) - 1,(1<<n) - tt - a[i]),fact[1<<j])));
                }
           // cout<<i<<" "<<tt<<" "<<f[i+1][tt]<<endl;
        }
    res=0;
    for (int tt=0;tt<(1<<n);tt++) {
       // cout<<f[m][tt]<<endl;
        if (__builtin_popcount(tt) % 2 == 0 ) res = sum(res,mul(f[m][tt],fact[(1<<n) - tt - 1]));
        else res = sub(res,mul(f[m][tt],fact[(1<<n) - tt - 1]));
    }
    res = mul(res,(1<<n));
    cout<<res;
}


Measured memory_bytes: 4352
N = int(input())

def num_divisors_table(n):
    table = [0] * (n + 1)
    
    for i in range(1, n + 1):
        for j in range(i, n + 1, i):
            table[j] += 1
    
    return table

table = num_divisors_table(N)

ans = 0
for i in range(1, N+1):
  ans += i * table[i]

print(ans)

Measured memory_bytes: 146156
n = int(input())
S = list(map(int, input().split()))
q = int(input())
T = list(map(int, input().split()))

cnt = 0

for t in T:
    left = 0
    right = n
    while left < right:
        mid = (left + right) // 2
        if t == S[mid]:
            cnt += 1
            break
        elif t < S[mid]:
            right = mid
        else:
            left = mid + 1
            
print(cnt)


Measured memory_bytes: 16708
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc *bufio.Scanner

func init() {
	// 100MB
	bufsize := 100 * 1024 * 1024
	sc = bufio.NewScanner(os.Stdin)
	sc.Buffer(make([]byte, bufio.MaxScanTokenSize), bufsize)
	sc.Split(bufio.ScanWords)
}
func readInt() int              { return readIntArray(1)[0] }
func readInt2() (int, int)      { a := readIntArray(2); return a[0], a[1] }
func readInt3() (int, int, int) { a := readIntArray(3); return a[0], a[1], a[2] }
func readIntArray(n int) []int {
	s := readStringArray(n)
	a := make([]int, n)
	for i := range a {
		a[i], _ = strconv.Atoi(s[i])
	}
	return a
}
func readString() string            { return readStringArray(1)[0] }
func readString2() (string, string) { a := readStringArray(2); return a[0], a[1] }
func readStringArray(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		sc.Scan()
		a[i] = sc.Text()
	}
	return a
}
func max(ns ...int) int {
	max := ns[0]
	for _, n := range ns {
		if n > max {
			max = n
		}
	}
	return max
}
func min(ns ...int) int {
	min := ns[0]
	for _, n := range ns {
		if n < min {
			min = n
		}
	}
	return min
}
func abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

func main() {
	S := readString()
	Q := readInt()

	front, back := make([]rune, 0, 1001001), make([]rune, 0, 1001001)
	var rev bool
	for i := 0; i < Q; i++ {
		t := readInt()
		if t == 1 {
			rev = !rev
			continue
		}

		f := readInt()
		c := []rune(readString())[0]
		if f == 1 {
			if rev {
				back = append(back, c)
			} else {
				front = append(front, c)
			}

		} else {
			if rev {
				front = append(front, c)
			} else {
				back = append(back, c)
			}

		}
	}

	if rev {
		fmt.Printf(string(Reverse(back)))
		fmt.Printf(string(Reverse([]rune(S))))
		fmt.Printf(string(front))
		return
	}
	fmt.Printf(string(Reverse(front)))
	fmt.Printf(S)
	fmt.Printf(string(back))
}

//type Query struct {
//	T int
//	F int
//	C rune
//}
//
//func (q *Query) Process(s []rune, rev bool) ([]rune, bool) {
//	if q.T == 1 {
//		//	fmt.Printf("(REV) s: %s, rev: %t -> (%s, %t)\n", s, rev, s, !rev)
//		return s, !rev
//	}
//
//	//befores := s
//	if q.F == 1 {
//		if rev {
//			s = append(s, q.C)
//		} else {
//			s, s[0] = append(s[:1], s[0:]...), q.C
//		}
//	} else {
//		if rev {
//			s, s[0] = append(s[:1], s[0:]...), q.C
//		} else {
//			s = append(s, q.C)
//		}
//	}
//
//	//fmt.Printf("(APD) s: %s, rev: %t -> (%s, %t)\n", befores, rev, s, rev)
//	return s, rev
//}
//
//func main() {
//	S := readString()
//	Q := readInt()
//
//	qs := make([]Query, Q)
//	var rev bool
//	r := make([]rune, 0, 1001001)
//	r = append(r, []rune(S)...)
//	for i := 0; i < Q; i++ {
//		t := readInt()
//		qs[i].T = t
//		if t == 1 {
//			r, rev = qs[i].Process(r, rev)
//			continue
//		}
//
//		f := readInt()
//		c := []rune(readString())[0]
//		qs[i].F = f
//		qs[i].C = c
//		r, rev = qs[i].Process(r, rev)
//	}
//
//	if rev {
//		fmt.Println(string(Reverse(r)))
//		return
//	}
//	fmt.Println(string(r))
//}
//
func Reverse(runes []rune) []rune {
	for i, j := 0, len(runes)-1; i < j; i, j = i+1, j-1 {
		runes[i], runes[j] = runes[j], runes[i]
	}
	return runes
}


Measured memory_bytes: 11384
#include <stdio.h>
#include <math.h>

int main(void){
    long long N, tmp_N;
    int count, divisor, i;
    double limit;
    count = 1;

    scanf("%lld", &N);
    if(N >= 3)
        count++;

    limit = sqrt(N-1);
    for(i = 2; i < limit; i++){
        if((N-1) % i == 0)
            count += 2;
    }
    if((N-1) % i == 0)
        count++;

    limit = sqrt(N);
    for(i = 2; i <= limit; i++){
        if(N % i == 0){
            tmp_N = N;
            divisor = i;
            while(tmp_N % divisor == 0)
                tmp_N /= divisor;
            if(tmp_N % divisor == 1)
                count++;
        }
    }
    printf("%d\n", count);

    return 0;
}


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

#define mp make_pair
#define pb push_back
#define REP(i,a,n) for(int i = a;i < (n);i++)
#define rep(i,n) for(int i = 0;i < (n);i++)
#define all(s) s.begin(), s.end()
#define rall(s) s.rbegin(), s.rend()
#define range(x,min,max) ((min) <= (x) && (x) <= (max))

using namespace std;

typedef long long LL;
typedef vector<int> VI;
typedef vector<vector<int> > VVI;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef pair<int,int> PII;

const int DX[]={1,0,-1,0},DY[]={0,-1,0,1};

int main(){
	cin.tie(0);
   	ios::sync_with_stdio(false);
	int h, w;
	while (1) {
		cin >> h >> w;
		if (h == 0 && w == 0) break;
		PII ans = PII(150, 150);
		int wh_len = h * h + w * w;
		int min_h = h;
		REP (i, 1, 151) {
			REP (j, 1, 151) {
				if (i >= j) continue;
				int len = i * i + j * j;
				if (len >= wh_len) {
					if (len == wh_len && h >= i) continue;
					int ans_len = ans.first * ans.first + ans.second * ans.second;
					ans = (len < ans_len)? mp(i, j) : ans;
				}
			}
		}
		cout << ans.first << " " << ans.second << endl;
	}
	return 0;
}

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

//#define int long long
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<n;++i)
#define exrep(i, a, b) for(ll i = a; i < b; i++)
#define out(x) cout << x << endl
#define EPS (1e-7)
#define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<bool> > vvb;
typedef vector<vector<double> > vvd;
typedef vector<vector<string> > vvs;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
typedef vector<vector<vector<ll> > > vvvl;
ll MOD = 1000000007;
const long long L_0 = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);
//cout<<fixed<<setprecision(10);

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template<class T> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
//以降 cin の入力元が 'input.txt' になる
//std::ifstream in("input.txt");
//std::cin.rdbuf(in.rdbuf());

signed main()
{   
    gearup;
    ll n,m; cin >> n >> m;
    vpii p;
    rep(i,m){
        int a,b;cin >> a >> b;
        p.push_back({b,a});
    }
    sort(all(p));
    int res = 0;
    int endtime = 0;
    rep(i,m){
        if (p[i].second >= endtime) {
            endtime = p[i].first;
            ++res;
        }
    }
    cout << res << endl;
}



Measured memory_bytes: 4264
#include <bits/stdc++.h>
#define err(args...) {}
#ifdef DEBUG
#include "_debug.cpp"
#endif
using namespace std;
using ll = long long;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    bool ans = false;
    for(int i = 0; i <= n; i++) {
        for(int j = 0; j <= n; j++) {
            ans |= 4 * i + 7 * j == n;
        }
    }
    cout << (ans ? "Yes" : "No") << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define rep(i,n) for (int i = 0; i < (n); i++)
typedef pair<int,int> P;
const int INF = 100000000;

int main() {
    int N;
    cin >> N;
    int a[N] = {0};
    int tmp;
    rep(i,N-1) {
        cin >> tmp;
        a[tmp-1]++;
    }
    rep(i,N) {
        cout << a[i] << endl;
    }
}


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

pair<map<ll, ll>, set<ll>> prime_factor(ll n){
    map<ll, ll> res;
    set<ll> primes;
    for(ll i = 2; i*i <= n; ++i) {
        if(n%i==0) primes.insert(i);

        while(n%i == 0){
            ++res[i];
            n /= i;
        }
    }
    if(n != 1) {
        res[n] = 1;
        primes.insert(n);
    }
    return make_pair(res, primes);
}

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

    ll n;
    cin >> n;

    pair<map<ll, ll>, set<ll>> p = prime_factor(n);
    map<ll, ll> mp = p.first;
    set<ll> st = p.second;

    cout << n << ":";
    for(auto prime: st){
        rep(_, mp[prime]) cout << " " << prime;
    }

    cout << endl;

    return 0;
}


Measured memory_bytes: 3220
#include<bits/stdc++.h>
using namespace std;
typedef int sign;
typedef long long ll;
#define For(i,a,b) for(register sign i=(sign)(a);i<=(sign)(b);++i)
#define Fordown(i,a,b) for(register sign i=(sign)(a);i>=(sign)(b);--i)
const int N=100+5;
template<typename T>bool cmax(T &a,T b){return (a<b)?a=b,1:0;}
template<typename T>bool cmin(T &a,T b){return (a>b)?a=b,1:0;}
template<typename T>T read()
{
	T ans=0,f=1;
	char ch=getchar();
	while(!isdigit(ch)&&ch!='-')ch=getchar();
	if(ch=='-')f=-1,ch=getchar();
	while(isdigit(ch))ans=(ans<<3)+(ans<<1)+(ch-'0'),ch=getchar();
	return ans*f;
}
template<typename T>void write(T x,char y)
{
	if(x==0)
	{
		putchar('0'),putchar(y);
		return;
	}
	if(x<0)
	{
		putchar('-');
		x=-x;
	}
	static char wr[20];
	int top=0;
	for(;x;x/=10)wr[++top]=x%10+'0';
	while(top)putchar(wr[top--]);
	putchar(y);
}
void file()
{
#ifndef ONLINE_JUDGE
	freopen("A.in","r",stdin);
	freopen("A.out","w",stdout);
#endif
}
int n,p;
int a[N];
void input()
{
	n=read<int>(),p=read<int>();
	For(i,1,n)a[i]=read<int>();
}
ll C[N][N];
int num[3];
void work()
{
	For(i,0,n)
	{
		C[i][0]=1;
		For(j,1,i)C[i][j]=C[i-1][j-1]+C[i-1][j];
	}
	ll ans=0;
	For(i,1,n)num[a[i]%2]++;
	for(int i=p;i<=num[1];i+=2)ans+=C[num[1]][i]*(1ll<<num[0]);
	write(ans,'\n');
}
int main()
{
//	file();
	input();
	work();
	return 0;
}



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

#define rep(i,n) for(i = 0;i < n;++i)
#define all(v) v.begin(), v.end()
using ll = long long;

int main()
{
    ll i,j;
    ll ans = 0;
    for(i = 0;i < 3;++i){
        ll a;
        cin >> a;
        ans += a;
    }
    if(ans <= 21) cout << "win" << endl;
    else cout << "bust" << endl;
    return 0;
}

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

int main() {
  ll x;
  cin >> x;

  ll n = x / 11;
  ll m = x % 11;

  ll ans = 2 * n;
  if (m != 0) {
    if (m < 7)
      ans += 1;
    else
      ans += 2;
  }
  cout << ans << endl;
}

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

int a[1000005];
int main(){
    int n;
    while(cin>>n,n){
        for(int i = 0;i < n;i++)cin>>a[i];
        int cnt = 0;
        for(int i = 0;i < n;i++){
            for(int j = 0;j < n-i-1;j++){
                if(a[j]>a[j+1]){
                    swap(a[j],a[j+1]);
                    cnt++;
                }
            }
        }
        cout<<cnt<<endl;
    }
}

Measured memory_bytes: 1160
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
using namespace std;

void Main() {
    // input
        u_int32_t K, N;
        cin >> K;
        cin >> N;
        vector<u_int32_t> A(N+1);
        vector<u_int32_t> diff(N+1);


        for (u_int32_t i = 1; i <= N; i++) {
            cin >> A[i];
        }

        diff[0] = 0;
        for (u_int32_t i = 1; i<= N - 1; i++) {
            diff[i] = A[i+1] - A[i]; 
        }
        diff[N] = K - A[N] + A[1];

        u_int32_t maxDiff = 0;
        for (u_int32_t i = 1; i <= N; i++) {
            maxDiff = max(maxDiff, diff[i]);
        }


    // translate
        cout << K - maxDiff << endl;


    // output

}

int main() {
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


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

typedef long long ll;
ll mod = 1000000007;
const double PI = 3.141592653589793238460;
const int INF = 1e9+5;
int ans = INF;
int x;
void recur(int cost[], vector<int> books[], vector<int>& knowledge, int start, int n, int m, int& res){

    bool flag=true;
    for(int i = 0; i<m; i++){
        if(knowledge[i]<x){
            flag=false;
            break;
        }
    }

    if(flag){
        ans = min(ans, res);
        return;
    }

    for(int i = start; i < n; i++){

        res+=cost[i];
        for(int j=0; j<m; j++){
            knowledge[j]+=books[i][j];
        }
        recur(cost, books, knowledge, i+1, n, m, res);
        res-=cost[i];
        for(int j=0; j<m; j++){
            knowledge[j]-=books[i][j];
        }
    }
}

int main(){

    ios::sync_with_stdio(false);
    cin.tie(0);

    int n, m;
    cin >> n >> m >> x;
    int cost[n];
    vector<int> books[n];    

    for(int i=0; i<n; i++){
        cin >> cost[i];
        for(int j=0; j<m; j++){
            int t;
            cin >> t;
            books[i].push_back(t);
        }
    }

    vector<int> knowledge(m,0);
    int res = 0;
    recur(cost, books, knowledge, 0, n, m, res);

    ans==INF?cout<<(-1):cout<<ans;

    return 0;
}


Measured memory_bytes: 3668
#include <iostream>
#include <sstream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <bitset>
#include <assert.h>
#include <deque>
using namespace std;

typedef unsigned long long UL;
typedef long long LL;
typedef long double LD;
#define LP(i, a, b) for (int i = int(a); i < int(b); i++)
#define LPE(i, a, b) for (int i = int(a); i <= int(b); i++)
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
typedef vector<vector<PII> > WAL;
typedef vector<vector<int> > SAL;
#define Ep 1e-8
#define INF 1e9
#define LINF 1e18

/*
 test N = 2;

 */
int const MaxSize = 200000 + 5;
int A[MaxSize], sA[MaxSize], N;

int main() {

	ios_base::sync_with_stdio(false);
	//freopen("/Users/georgeli/A_1.in", "r", stdin);
	cin >> N;

	LP(i, 0, N)
	{
		cin >> A[i];
		sA[i] = A[i];
	}

	sort(sA, sA + N);

	int eM = sA[N / 2];

	LP(i, 0, N)
	{
		if (A[i] < eM) {
			cout << eM << endl;
			//} else if (sA[i] > eM) {
		} else {

			cout << sA[N / 2 - 1] << endl;
		}
	}

	return 0;
}


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

using namespace std;

#define int long long

#ifndef bhupixb
    #define var(...)
    #define stl(...)
#endif

#define single_test

void solve() {
    string s, t;
    cin >> s >> t;
    int mx = s.size();
    int n = s.size(), m = t.size();
    for (int i = 0; i + m - 1 < n; ++i) {
        int cnt = 0;
        for (int j = 0; j < m; ++j) {
            cnt += s[i+j] != t[j];
        }
        var(cnt);
        mx = min(mx, cnt);
    }
    cout << mx << '\n';
}

signed main() {
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t = 1;
    #ifndef single_test
        cin >> t;
    #endif
    for (int i = 1; i <= t; ++i) {
        // cout << "Case #" << i << ": ";
        solve();
    }

    return 0;
}

Measured memory_bytes: 3644
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <algorithm>
#define _USE_MATH_DEFINES
#include <cmath>
#include <numeric>
#include <iomanip>
#include <deque>
#include <tuple>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <sstream>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>

#define rep(i, x) for (int i = 0; i < (int)(x); i++)
#define FOR(i, a, done) for (int i = (a); i < (done); ++i)
#define all(a) (a).begin(), (a).end()
#define F first
#define S second
#define pb push_back
#define pf push_front

namespace mp = boost::multiprecision;
using cpp_int = mp::cpp_int;
using ll = long long;
using namespace std;

ll M = 1000000007;
typedef pair<int, int> P;

int main()
{
    string s;
    cin>>s;
    int n=s.size()+1;
    vector<int>a(n);
    int more=0,less=0;
    rep(i,n-1){
        if(s[i]=='<'){
            more++;
        }else{
            more=0;
        }
        a[i+1]=more;
    }
    rep(i,n-1){
        int ite=n-2-i;
        if(s[ite]=='>'){
            less++;
        }else{
            less=0;
        }
        a[ite]=max(less,a[ite]);
    }
       
    /*rep(i,n){
        cout<<a[i]<<" ";
    }
    cout<<endl;*/
    ll ans=0;
    rep(i,n){
        ans+=a[i];
       // cout<<a[i]<<" ";
    }
    cout<<ans<<endl;

}


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

int main(){
    int n, k;
    cin >> n >> k;
    vector<int> tree;

    for(int i = 0; i< n;i++){
        int a; 
        cin >> a;
        tree.push_back(a);
    }

    sort(tree.begin(), tree.end());

    int min = 1000000000;
    for(int i = 0; i < tree.size()-k+1; i++){
        int d = abs(tree[i] - tree[i+k-1]);
        if(min > d){
            min = d;
        }
    }
    cout << min << endl;
    
}

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

const ll mod = 1e9 + 7;

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

/*-------------------------------------------*/

int X[4] = {0, 1, 0, -1}, Y[4] = {1, 0, -1, 0};

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

    int h, w, ans = 0;
    cin >> h >> w;
    char c[h][w];
    rep(i, h) rep(j, w) cin >> c[i][j];

    rep(i, h) rep(j, w) {
        if(c[i][j] == '#') continue;
        queue<pair<int, int>> que;
        que.push({i, j});
        int d[h][w] = {};
        d[i][j] = 1;
        while(!que.empty()) {
            int x = que.front().first, y = que.front().second;
            chmax(ans, d[x][y]);
            que.pop();
            rep(k, 4) {
                int nx = x + X[k], ny = y + Y[k];
                if(0 <= nx && nx < h && 0 <= ny && ny < w && d[nx][ny] == 0 &&
                   c[nx][ny] == '.') {
                    d[nx][ny] = d[x][y] + 1;
                    que.push({nx, ny});
                }
            }
        }
    }

    cout << ans - 1 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define INF 1000000009
typedef long long ll;
#define REP(i,n) for(int i=0;i<(n);++i)
#define RREP(i,n) for(int i=(n)-1;i>=0;--i)
#define rollcall cout<<"I'm Sucu."<<endl;
#define YES(s) s?cout << "YES" << endl:cout << "NO" << endl
#define Yes(s) s?cout << "Yes" << endl:cout << "No" << endl
#define Taka(s) s?cout << "Takahashi" << endl:cout << "Aoki" << endl
#define out(s,t,u) s?cout << t << endl:cout << u << endl
#define int ll
#define Endl endl


signed main(){
    int x,a,b;
    cin >> x >> a >> b;
    out(abs(x-a)<abs(x-b),"A","B");
    return 0;
}   



Measured memory_bytes: 256
/*mokosucio's file*/
#include <bits/stdc++.h>

using namespace std;

#define pb push_back
#define fs first
#define sc second
#define forn(i, n) for (ll i = 0; i < (ll) (n); ++i)
#define IO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)

using ll = long long;
const ll inf = 1e9+5; 

const double PI =  3.14159265;

int main(){
	IO;
	ll n, cnt = 0;
	cin>>n;
	forn(i,n+1){
		if(i%3!=0 && i%5!=0)cnt+=i;
	}
	cout<<cnt<<"\n";
	return 0;
}



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

long long max(long long a, long long b) {
    if (a<b) return b;
    else return a;
}
long long min(long long a, long long b) {
    if (a>b) return b;
    else return a;
}

long long mindist(const long long n, long long a, long long b) {
    long long h = n/2;
    if (h%2) {
        if (min(llabs(h-a),llabs(h+1-a)) > min(llabs(h-b),llabs(h+1-b))) return b;
        else if (min(llabs(h-a),llabs(h+1-a)) == min(llabs(h-b),llabs(h+1-b))) return min(a,b);
        else return a;
    } else {
        if (llabs(h-a) > llabs(h-b)) return b;
        else if (llabs(h-a) == llabs(h-b)) return min(a,b);
        else return a;
    }
}

int main(void) {
    int i, N;
    long long a[100010], m, r;
    scanf("%d", &N);
    for (i=0;i<N;i++) scanf("%lld", &a[i]);

    m = a[0];
    for (i=1;i<N;i++) m = max(m,a[i]);
    r = a[0];
    for (i=1;i<N;i++) r = mindist(m,r,a[i]);

    printf("%lld %lld\n", m, r);

    return 0;
}

Measured memory_bytes: 896
n,m = map(int, input().split())
sws=[]
for _ in range(m):
  sws.append(list(map(int, input().split()))[1:])
p = list(map(int, input().split()))

ans=0
for i in range(2**n):
  for j in range(m):
    t = 0
    for sw in sws[j]:
      if ((i >> (sw-1)) & 1):
        t += 1
    if t%2 != p[j]:
      break
  else:
    ans+=1
print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define vi vector<ll>
#define vvi vector<vi>
#define substr(s,f,t) (s.substr(f-1,t-f+1))
#define ALL(a) (a).begin(),(a).end()
#define Yes(hoge) cout<<((hoge)?"Yes":"No")<<endl;
#define YES(hoge) cout<<((hoge)?"YES":"NO")<<endl;
using namespace std;
struct Grid{ll x,y,t;};
struct Edge{ll to,cost;};
struct Graph{vector<vector<Edge>>E;int V;
  const ll Inf = llINF;const int MAX_V=201010;vector<ll>d;
  Graph(int n):E(n){d.resize(MAX_V);E.resize(n);V=n;}
  void init(){for(int i=0;i<MAX_V;i++)d[i]=Inf;}
  void add_edge(ll from,ll to,ll cost){E[from].pb({to,cost});}
};
ll gcd(ll a,ll b){
    ll r=a%b; 
    while(r!=0){a=b;b=r;r=a%b;}
    return b;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n;cin>>n;
  if(n<=5){
    if(n==3){cout<<2<<" "<<5<<" "<<63<<endl;return 0;}
    int ki[10]={6,2,10,3,9,4};
    int gu[10]={2,10,3,9,4,8};
    if(n%2){
      for(int i=0;i<n;i++)
	cout<<ki[i]<<" ";
      cout<<endl;
    }else{
      for(int i=0;i<n;i++)
	cout<<gu[i]<<" ";
      cout<<endl;
    }
    return 0;
  }
  vvi num(10);
  num[0].pb(0);
  for(int i=2;i<=30000;i++)
    num[i%6].pb(i);
  // if(n<=5){
    ll now=2;
    vi ans;
    ll sum=0;
    ll cnt[10]={};
    cnt[0]++;
    for(int i=0;i<n;i++){
      if(now==1||now==5){now=(now+1)%6;}
      ans.pb(num[now][cnt[now]]);
      sum+=num[now][cnt[now]];
      cnt[now]++;
      now++;
    }
    // cout<<sum<<endl;
    if(sum%6==0){
      for(ll a:ans)cout<<a<<" ";
      cout<<endl;
    }else{
      if(sum%6==5){
	for(int i=0;i<ans.size();i++)
	  if(ans[i]%6==3){ans.erase(ans.begin()+i);break;}
	ans.pb(num[4][cnt[4]]);
      }else if(sum%6==3){
	for(int i=0;i<ans.size();i++)
	  if(ans[i]%6==3){ans.erase(ans.begin()+i);break;}
	ans.pb(num[0][cnt[0]]);
      }else if(sum%6==2){
	for(int i=0;i<ans.size();i++)
	  if(ans[i]%6==2){ans.erase(ans.begin()+i);break;}
	ans.pb(num[0][cnt[0]]);
      }
      for(ll a:ans)cout<<a<<" ";
      cout<<endl;
    }/*
  }else{
    ll now=0;
    vi ans;
    ll sum=0;
    ll cnt=0;
    for(int i=0;i<n;i++){
      if(now==1||now==5){now=(now+1)%6;if(now==0)cnt++;}
      ans.pb(num[now][cnt]);
      sum+=num[now][cnt];
      now++;
    }
    if(sum%6==0){
      for(ll a:ans)cout<<a<<" ";
      cout<<endl;
    }else{
      sum-=ans.back();
      for(ll a:ans)cout<<a<<" ";
      cout<<num[6-sum%6][cnt+1]<<endl;
    }
    }*/
  return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>
int main(void)
{
int i,  j, k, x, n;
int m = 0;

while(1){
scanf("%d %d",&n,&x);

if(n == 0 && x == 0)
break;

for(i = 1; i <= n; i++){
 for(j = 1; j <= n; j++){
  for(k = 1; k <= n; k++){
if(i + j + k == x){
if(i != j && j != k && k != i)
m++;
}
}
}
}
printf("%d\n",m / 6);
m = 0;
}
return 0;
}

Measured memory_bytes: 600
#include<cstdio>
#include<cmath>
using namespace std;

int main() {
	int a;
	scanf("%d",&a);
	int h;
	int m;
	int s;

	h = a / 3600;
	m = (a % 3600) / 60;
	s = (a % 3600) % 60;

	printf("%d:%d:%d\n",h,m,s);

	return 0;
}


Measured memory_bytes: 2720
#include <iostream>
#include <stdio.h>
#include <string>
#include <math.h>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cassert>
#include <utility>
#include <numeric>
#include <cstring>
using namespace std;
using ll = long long;

int main(){
    string S;
    cin >> S;

    if (S[0]==S[1]&&S[1]!=S[2] &&S[2]==S[3]){
        cout << "Yes";
    }
    else if (S[0]==S[2]&&S[0]!=S[1] &&S[1]==S[3]){
        cout << "Yes";
    }
    else if (S[0]==S[3]&&S[0]!=S[1] &&S[1]==S[2]){
        cout << "Yes";
    }
    else cout << "No";

    


}

Measured memory_bytes: 256
#include"bits/stdc++.h"
#define F(i,j,n) for(register int i=j;i<=n;i++)
#define D(i,j,n) for(register int i=j;i>=n;i--)
#define ll long long
#define N 1000010
using namespace std;
int n,g,l,m,ans;char s[N],t[N];
queue<int> q;
int main()
{
	scanf("%d%s%s",&n,s+1,t+1);
	for(g=1;g<=n;g++)if(s[g]!=t[g])break;
	if(g==n+1){puts("0");return 0;}g=n+1;
	D(i,n,1){
		g=min(i,g);
		while(g>0&&s[g]!=t[i])g--;
		if(g<=0){puts("-1");return 0;}
		if(g==l)continue;l=g;
		while(q.size()&&i<q.front()-q.size()+1)q.pop();
		q.push(g);
		ans=max(ans,(int)q.size());
	}
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 6272
function main(input) {
  var input = input.split(" ");
  var N = input[0];
  var A = input[1];
  var B = input[2];
  
  var s = N * A;
  
  if (s<B) console.log(s);
  else console.log(B);
}

main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 7496
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
using namespace std;
int main() {
  int A,B;
  cin >> A >> B;
  int cnt = 0;
  for (int i=1; i<10; i++) {
    for (int j=0; j<10; j++) {
      for (int k=0; k<10; k++) {
        int x = 10001*i + 1010*j + 100*k;
        if (A <= x && x <= B) cnt++;
      }
    }
  }
  cout << cnt << endl;
}

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

int main(){
    int n;
    cin>>n;
    vector<int>a(n);
    rep(i,n)cin>>a[i];
    int r=0,sum=0;
    ll ans=0;
    rep(l,n){
        while(r<n&&(sum^a[r])==(sum+a[r])){
            sum+=a[r];
            r++;
        }
        ans+=r-l;
        if(l==r)r++;
        else sum-=a[l];
    }
    cout<<ans<<endl;
}

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

 struct node{
 
   unsigned int key;

   struct node *next;
 
   struct node *prev;
 
 };
 
 
 typedef struct node * NodePointer;

 NodePointer nil;
 
 NodePointer listSearch(int key){
   NodePointer cur = nil->next;
     while(cur != nil && cur->key != key){
       cur = cur->next;
 }
   return cur;
 }
 
 
 void init(){
 
   nil = malloc(sizeof(struct node));
 
   nil->next = nil;
 
   nil->prev = nil; 
 }
 
 
 void printList(){
 
   NodePointer cur = nil->next;
   int isf = 1;
 
   while(1){
 
     if ( cur == nil ) break;
 
     if ( isf == 0)  printf(" ");

    printf("%d", cur->key);
 
     cur = cur->next;
 
     isf = 0;   
   }
 
   printf("\n");
 
 }
 
 
 void deleteNode(NodePointer t){
   if(t==nil) return;
   t->prev->next = t->next;
   t->next->prev = t->prev;
   free(t);
 }
 
 
 void deleteFirst(){
   NodePointer t = nil->next;
 
   if ( t == nil ) return;
 
   deleteNode(t);
 
 } 
 void deleteLast(){
   deleteNode(nil->prev);
 }
  
 void delete(int key){
   deleteNode(listSearch(key));
  }
 
 void insert(int key){
 
   NodePointer x;
 
   x = malloc(sizeof(struct node));
 
   x->key = key;
   x->next = nil->next;
   nil->next->prev = x;
   nil->next = x;
   x->prev = nil;
 }
 
 
 int main(){
 
   int key, n, i;
 
   int size = 0;
 
   char com[20];
 
   int np = 0, nd = 0;

   scanf("%d", &n);
 
   init();
 
   for ( i = 0; i < n; i++ ){
 
     scanf("%s%d", com, &key);
 
     if ( com[0] == 'i' ) {insert(key); np++; size++;}

     else if ( com[0] == 'd' ) {
 
       if (strlen(com) > 6){
 
 if ( com[6] == 'F' ) deleteFirst();
 
 else if ( com[6] == 'L' ) deleteLast();
 
       } else {
 
 delete(key); nd++;
 
       }
 
       size--;
 
     }
   }
 
    printList();
 
   return 0;
 
 }

Measured memory_bytes: 31788
import java.util.Scanner;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.Collections;

public class Main{
	
	// a < b
	public static long gcd(long a, long b){
		if(b % a == 0){
			return a;
		}
		long mod = b % a;
		
		return gcd(mod, a);
	}
	
	public static long lcm(long a, long b){
		long lower = 0;
		long higher = 0;
		if(a < b){
			lower = a;
			higher = b;
		} else {
			lower = b;
			higher = a;
		}
		
		return lower / gcd(lower, higher) * higher;
	}
	
	public static void main(String... args){
		Scanner scan = new Scanner(System.in);
		LinkedList<Long> times = new LinkedList<>();
		
		// input
		int num = scan.nextInt();
		for(int i = 0; i < num; i++){
			times.push(scan.nextLong());
		}
		
		// check
		Collections.sort(times);
		while(times.size() > 1){
			times.push(lcm(times.pop(), times.pop()));
		}
		
		// answer
		System.out.println(times.pop());
		
	}
		
}

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

using i32 = int_fast32_t;
using i64 = int_fast64_t;

int main() {
    i32 n, m;
    cin >> n >> m;
    vector<vector<i32>> g(n*3);
    for (i32 i = 0; i < m; i++) {
        i32 u, v;
        cin >> u >> v, u--, v--;
        for (i32 j = 0; j < 3; j++) {
            g[u*3 + j].push_back(v*3 + (j+1)%3);
        }
    }
    i32 s, t;
    cin >> s >> t, s--, t--;

    queue<i32> q;
    q.push(s*3);
    vector<i32> dist(n*3, -1);
    dist[s*3] = 0;
    while (!q.empty()) {
        i32 a = q.front(); q.pop();
        for (auto& e : g[a]) {
            if (dist[e] != -1) continue;
            dist[e] = dist[a] + 1;
            q.push(e);
        }
    }
    
    cout << (dist[t*3] % 3 == 0 ? dist[t*3] / 3 : -1) << endl;
}


Measured memory_bytes: 18944
#include <bits/stdc++.h>
#define sz(v)   ((int)(v).size())
#define  all(v)    ((v).begin()),((v).end())
#define  allr(v)    ((v).rbegin()),((v).rend())
#define   pb         push_back
#define   mp         make_pair
#define    clr(v,d)      memset( v, d ,sizeof(v))
#define     PI                       acos(-1)
typedef  long long     ll ;
typedef  unsigned long long ull;
const double eps= (1e-9);
using namespace std;
int dcmp(long double a,long double b){   return fabsl(a-b)<=eps ? 0: (a>b)? 1:-1  ;}
int getBit(ll num, int idx) {return ((num >> idx) & 1ll) == 1;}
int setBit1(int num, int idx) {return num | (1<<idx);}
ll setBit0(ll num, int idx) {return num & ~(1ll<<idx);}
ll flipBit(ll num, int idx) {return num ^ (1ll<<idx);}
void GO(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);}
int countNumBit1(int mask) {int ret=0; while (mask) 	{mask &= (mask-1);++ret;	}return ret;}
const int N=1000+5,mod=1e9+7;
int fr,fc,tr,tc,m,n;
string v[N];
deque<pair<pair<int,int>,int > > dq;
int dist[N][N];
bool vis[N][N];
int bfs(){
  clr(dist,-1);
  dist[fr][fc]=0;
  dq.pb(mp(mp(fr,fc),0));
  while(sz(dq)>0){

    int cur_r= dq.front().first.first;
    int cur_c= dq.front().first.second;
    int dd= dq.front().second;

    dq.pop_front();

    if(cur_r==tr&&cur_c==tc) return dd;

    if(vis[cur_r][cur_c]) continue;

    vis[cur_r][cur_c]=1;

    for(int i=max(0,cur_r-2);i<=min(n-1,cur_r+2);i++){
        for(int j=max(0,cur_c-2);j<=min(m-1,cur_c+2);j++){
            int co= (abs(cur_r-i)+abs(cur_c-j)==1?0:1);
            if(v[i][j]=='#') continue;
            if(dist[i][j]==-1||dist[i][j]>=dd+co){
                dist[i][j]=dd+co;
                if(co==0) dq.push_front(mp(mp(i,j),dd+co));
                else
                    dq.push_back(mp(mp(i,j),dd+co));
            }
        }
    }
  }
  return -1;
}
int main(){
    GO();
    int T;
    T=1;
    while(T--){
         cin>>n>>m;
         cin>>fr>>fc>>tr>>tc;
         fr--;
         fc--;
         tr--;
         tc--;
         for(int i=0;i<n;i++) cin>>v[i];
         cout<<bfs()<<"\n";
    }

}




























































































































































































Measured memory_bytes: 10132