akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); ++i)
using namespace std;
typedef long long ll;
const int INF = 1001001001;

int main() {
    string S;

    cin >> S;

    if(S=="SAT") {
        cout << 1 << endl;
    } else if(S=="FRI") {
        cout << 2 << endl;
    } else if(S=="THU") {
        cout << 3 << endl;
    } else if(S=="WED") {
        cout << 4 << endl;
    } else if(S=="TUE") {
        cout << 5 << endl;
    } else if(S=="MON") {
        cout << 6 << endl;
    } else if(S=="SUN") {
        cout << 7 << endl;
    }

    return 0;
    
}

Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<algorithm>
using namespace std;
struct student{
	int i;
	int rank;
	bool operator < (const student& e)const{
		if(rank!=e.rank){
			return rank<e.rank;
		}
		return true;
	} 
}a[100010];
int main()
{
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		a[i].i=i;
		cin>>a[i].rank;
	}
	sort(a+1,a+n+1);
	for(int i=1;i<=n;i++){
		printf("%d ",a[i].i);
	}
	return 0;
} 

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

#define trace(...) __f( #__VA_ARGS__ , __VA_ARGS__ )
template <typename Arg1>
void __f( const char* name , Arg1&& arg1 ) {
        cerr << name << " : " << arg1 << "\n";
}
template <typename Arg1, typename... Args>
void __f( const char* na , Arg1&& arg1 , Args&&... args ) {
        const char* c = strchr( na + 1 , ',' );
        cerr.write( na , c - na ) << " : " << arg1 << " , ";
        __f( c + 1 , args... );
}
#define endl "\n"
#define all(V) V.begin(),V.end()
#define Unique(V) sort(all(V)),V.erase(unique(all(V)),V.end())
#define IO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef long long int LL;
typedef pair <int,int> pii;
const int MOD = 1e9 + 7;
const int inf = 1e9;
const double EPS = 1e-9;
const double PI = acos(-1.0);
const long long INF = 1e18;
const int N = 1e5 + 5;

int main( ) {
        IO;
        #ifdef LOCAL
            //freopen( "input.txt" , "r" , stdin );
        #endif // LOCAL
        string s;
        cin >> s;
        while( s.size() < 15 ) s += 'o';
        int cnt = 0;
        for( int i = 0; i < s.size(); i++ ) cnt += ( s[i] == 'o' );
        if( cnt >= 8 ) cout << "YES" << endl;
        else cout << "NO" << endl;
        return 0;
}










Measured memory_bytes: 256
import java.util.Scanner;
import java.lang.Math;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int A[] = new int[N+2], B[] = new int[N+1];
        for (int i = 0; i < N; i++) {
            A[i+1] = sc.nextInt();
        }

        int sum = 0;
        for (int i = 0; i <= N; i++) {
            sum += (B[i] = Math.abs(A[i+1] - A[i]));
        }
        for (int i = 0; i < N; i++) {
            System.out.println(sum - B[i] - B[i+1] + Math.abs(A[i+2] - A[i]));
        }
    }
}


Measured memory_bytes: 62644
#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>

int main()
{
	std::vector<int> n(5),m;
	int k;
	for (int i = 0;i < 5;i++)
	{
		std::cin >> n[i];
		if (n[i] % 10 != 0) { m.push_back(10 - n[i] % 10); }

	}

	if (m.size() == 0) { m.push_back(0); }

	std::cout << std::accumulate(n.begin(), n.end(), 0) + std::accumulate(m.begin(), m.end(), 0)
		- *(std::max_element(m.begin(), m.end())) << std::endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long double ld;
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n; cin >> n;
  vector<int> a(n);
  REP(i,n) cin >> a[i];
  ll lc = 1;
  REP(i,n) lc = lcm(lc, a[i]);
  ll bc = 0;
  REP(i,n) bc += lc/a[i];
  printf("%.9f\n", double(lc)/double(bc));
 
  return 0;
}


Measured memory_bytes: 3732
#include <algorithm>
#include <iostream>
#include <string>
#include <cstdlib>
#include <vector>

using namespace std;

int main() {
  int n;
  scanf("%d", &n);

  vector<int> H(n);

  for (int i = 0; i < n; i++) {
    int h;
    scanf("%d", &h);
    H[i] = h;
  }

  reverse(H.begin(), H.end());

  int len = H.size();
  int r = 0;

  int i = 0, j = 0, p = i;
  while (i < len) {
    int c = 0;
    j = i;
    p = i + 1;

    while (p < len && H[j] <= H[p]) {
      j = p;
      p++;
      // cout << H[j] << " vs " << H[i] << endl;
    }
    // cout << p << endl;
    c = p - i - 1;
    r = max(c, r);

    i = p;
  }
  
  cout << r << endl;

  return 0;
}


Measured memory_bytes: 640
#include<iostream>
#include <stdlib.h>
#include <algorithm>
#include <string>
#include <vector>
typedef long long int ll;
using namespace std;
int main() {
	ll x;
	int D,r;
	cin >> r>> D >>x;
	for(int i=0;i<10;i++){
		cout<<r*x-D<<endl;
		x=r*x-D;
	}
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>

int main() {
    int k;
    char s[101];
    scanf("%d%s", &k,s);
    if (k >= strlen(s))printf("%s", s);
    else {
        for (int i = 0; i < k; i++)printf("%c", s[i]);
        printf("...");
    }
    return 0;
}

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

int main() {

    int N;
    cin >> N;
    
    int V[N], C[N];
    
    for (int i = 0; i < N; i++) {
      cin >> V[i];
    }
    for (int i = 0; i < N; i++) {
      cin >> C[i];
    }
    
    int ans = 0;
    for (int i = 0; i < N; i++) {
      ans += ( (V[i]-C[i]>0)? V[i]-C[i] : 0);
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define clr(i, j)     memset(i, j, sizeof(i))
#define pb            push_back
 
typedef long long     ll;
 
//-*-*-*-*-*-*-*-*-
 
 
 
ll n,m,k,x,y,r;
ll dp[9999999][2];
ll a;ll aa[9900000];ll mp[990000];
 
 
int main()
{
   
   set<ll>v;  
ll ans=0;
 ll mx=0;
  cin>>n; ll f=0;
  for(ll i=0;i<n;i++){cin>>aa[i];a=aa[i];mp[a]++;mx=max(mx,a);}
   for(ll i=0;i<n;i++){if(aa[i]!=mx){f=max(f,aa[i]);}}
  for(ll i=0;i<n;i++){if(aa[i]==mx&&mp[mx]<2){cout<<f;}else{cout<<mx;}cout<<endl;}
 
  

  
   }

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

#define IOS		    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ld 		    long double
#define ll 		    long long int
#define ull 	   	unsigned long long int
#define pb		    push_back
#define mp		    make_pair
#define F		    first
#define S		    second
#define lb		    lower_bound
#define ub		    upper_bound
#define deb(x)      cout<<"#x "<<x<<"\n";
#define trace(x,y)  cout<<"#x "<<x<<" #y "<<y<<"\n";


const int mod = 1e9;
int n, k;

int main(){
    IOS;
    cin >> n>> k;
    int a[n+1];
    memset(a,0,sizeof(a));
    for(int i = 0 ; i  < k ;i++){
        int q;
        cin >> q;
        while(q--){
            int tp;
            cin >> tp;
            a[tp]++;
        }
    }
    int ans = 0;
    for(int i =1; i<= n ;i++){
        if(a[i] == 0)ans++;
    }
    cout<<ans<<"\n";
return 0;
}

Measured memory_bytes: 3652
import re
S = re.split("(..)", input())[1::2]
S[0] = int(S[0])
S[1] = int(S[1])

if 0 < S[0] <= 12:
    if 0 < S[1] <= 12:
        print("AMBIGUOUS")
    else:
        print("MMYY")
elif 0 < S[1] <= 12:
    print("YYMM")
else:
    print("NA")

Measured memory_bytes: 3188
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <string>
#include <set>
#include <cstdint>
#include <numeric>
#define INF 1000000000
#define LLINF 2000000000000000000
#define MOD 1000000007
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define LOOP(i,N) for(int i=0;i<N;i++)
#define LOOP1(i,N) for(int i=1;i<=N;i++)
typedef pair<int,int> P;
typedef pair<int,pair<int,int> > PP;
#define int long long

int abbs(int a){
  if(a<0)return -a;
  return a;
}

signed main(){
    int a[4];
    LOOP(i,4){
      cin >> a[i];
    }
    int ans = -LLINF;
    LOOP(i,2){
      LOOP(j,2){
        if(ans < a[i]*a[j+2]){
          ans = a[i]*a[j+2];
        }
      }
    }
    cout << ans << endl;

}


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

int main(){
  short *a,*b;
  int i,j,n;
  int c[10001];
  scanf("%d",&n);

  a=malloc(sizeof(short)*n+1);
  b=malloc(sizeof(short)*n+1);
  for(i=0;i<=10000;i++){
    c[i]=0;
  }
  for(i=0;i<n;i++){
    scanf("%hu",&a[i+1]);
    c[a[i+1]]++;
  }

for(i=1;i<=10000;i++){
  c[i]=c[i]+c[i-1];

}

for(j=1;j<=n;j++){
  b[c[a[j]]]=a[j];
  c[a[j]]--;
}


for(i=1;i<=n;i++){
  if(i==n){
    printf("%d",b[i]);
  }
  else {
    printf("%d ",b[i]);
  }


}
printf("\n");

return 0;

}

Measured memory_bytes: 8460
#include<bits/stdc++.h>
#define ll long long
#define rep(i,a,n) for(int i=a;i<=n;i++)
#define per(i,n,a) for(int i=n;i>=a;i--)
#define endl '\n'
#define mem(a,b) memset(a,b,sizeof(a))
#define IO ios::sync_with_stdio(false);cin.tie(0);
using namespace std;
const int INF=0x3f3f3f3f;
const ll inf=0x3f3f3f3f3f3f3f3f;
const int mod=1e9+7;
const int maxn=1e5+5;
int a[20][20],c[20],cur[20];int n,m,k,ans=INF;
void dfs(int x,int sum){
    for(int i=1;i<=m;i++){
        cur[i]+=a[x][i];
    }
    int fg=1;
    for(int i=1;i<=m;i++){
        if(cur[i]<k) fg=0;
    }
    if(fg==1) {ans=min(ans,sum+c[x]);}
    for(int i=x+1;i<=n;i++){
        dfs(i,sum+c[x]);
        for(int j=1;j<=m;j++){
            cur[j]-=a[i][j];
        }
    }
}
int main(){
    cin>>n>>m>>k;
    for(int i=1;i<=n;i++){
        cin>>c[i];
        for(int j=1;j<=m;j++){
            cin>>a[i][j];
        }
    }
    for(int i=1;i<=n;i++){
        mem(cur,0);
        dfs(i,0);
    }
    if(ans!=INF) cout<<ans<<endl;
    else cout<<-1<<endl;
}

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

int a,b;
std::string c;

int main(){
  cin >> a >> b;
  if(a < b){ c = "<";}
  else if(a == b){ c = "==";}
  else { c = ">";}

  cout << "a " << c << " b" << endl;
  
  return 0;
  }

Measured memory_bytes: 3136
#include <bits/stdc++.h>
#define endl '\n'

using namespace std;
template<class T, class T2> inline void chkmax(T &x, const T2 &y) { if(x < y) x = y; }
template<class T, class T2> inline void chkmin(T &x, const T2 &y) { if(x > y) x = y; }
const int MAXN = (1 << 20);

int n, q;
vector<int64_t> len;

void read()
{
	cin >> n >> q;
	
	len.push_back(n);
	for(int i = 0; i < q; i++)
	{
		int64_t v;
		cin >> v;
		while(!len.empty() && len.back() >= v) len.pop_back();
		len.push_back(v);
	}	
}

int64_t answer[MAXN];
int64_t add[MAXN];

void rec(int l, int r)
{
	if(l > r) return;

	int mid = (l + r) >> 1;
	//answer[mid] = solve_number(mid);

	if(answer[mid] == answer[l - 1])
		for(int i = l; i <= mid; i++)
			answer[i] = answer[mid];
	else 
		rec(l, mid - 1);

	if(answer[mid] == answer[r + 1])
		for(int i = mid; i <= r; i++)
			answer[i] = answer[mid];
	else
		rec(mid + 1, r);
}

void solve()
{
	q = len.size() - 1;

	add[q] = 1;
	for(int i = q; i >= 0; i--)
	{
		int64_t p = len[i];
		while(p)
		{
			if(p <= len[0])
			{
				answer[p] += add[i];
				p = 0;
				break;
			}

			int idx = lower_bound(len.begin(), len.end(), p) - len.begin() - 1;			
			int64_t cnt = p / len[idx];

			p -= cnt * len[idx];
			add[idx] += cnt * add[i];
		}
	}

	for(int i = n; i >= 0; i--)
		answer[i] += answer[i + 1];

	for(int i = 1; i <= n; i++)
		cout << answer[i] << endl;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	read();
	solve();
	return 0;
}



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

int main(){
    
    int A , B , C; cin >> A >> B >> C;
    
    if(A <= C && C <= B){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;
using System.Collections;
public class Program {
  public static void Main() {
    // 終了後回答
    int N = int.Parse(Console.ReadLine());
    string[] names = new string[N];
    for (int i = 0; i < N; i++) {
      names[i] = Console.ReadLine();
    }
    long[] MARCH = new[]{ 'M', 'A', 'R', 'C', 'H' }.Select(c => (long)names.Count(s => s[0] == c)).ToArray();
    long M = MARCH[0], A = MARCH[1], R = MARCH[2], C = MARCH[3], H = MARCH[4];
    // MARCH(5C3=10): MAR, MAC, MAH, MRC, MRH, MCH, ARC, ARH, ACH, RCH;
    long res = M*A*R + M*A*C + M*A*H + M*R*C + M*R*H + M*C*H + A*R*C + A*R*H + A*C*H + R*C*H;
    Console.WriteLine(res);
  }
}


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

int main() {
  ios::sync_with_stdio(false);
  
  int N, A;
  cin >> N >> A;

  int ans = A;

  for (int i = 1; i < N; i++) {
    cin >> A;
    ans = __gcd(ans, A);
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
def main():
    N = int(input())
    A = [int(input()) - 1 for _ in range(N)]

    on = [False] * N
    x = 0
    count = 0
    while x != 1:
        c = A[x]
        if on[c]:
            print(-1)
            return
        on[c] = True
        x = c
        count += 1
    
    print(count)

main()

Measured memory_bytes: 7852
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <map>
#include <iomanip>	
#include <deque>
#include <set>
#define rep(i,a,b) for(int i=a;i<b;++i)
#define rrep(i,a,b) for(int i=a;i>=b;--i)
#define fore(i,a) for(auto &i:a)
#define INF INT_MAX/2;
typedef long long ll;
using namespace std;
using vi = vector<int>;
using vll = vector<ll>;
ll mod = 1e9 + 7;
//ll llmax = 10000000000000000000ll;
using namespace std;
using Graph = vector<vector<int>>;


int cnt_digit(ll N)
{
	int digit = 0;

	while (N > 0)
	{
		N /= 10;
		digit++;
	}
	return digit;
}


 // 最大公約数計算
 
ll gcd(ll a, ll b)
{
	if (b == 0) {
		return a;
	}
	else {
		return gcd(b, a % b);
	}
}
// 最小公倍数の計算

ll lcm(ll a, ll b)
{
	ll g = gcd(a, b);

	return a / g * b;
}

struct union_find
{
	vector<int> par, r;
	union_find(int n)
	{
		par.resize(n);
		r.resize(n);
		init(n);
	}


	void init(int n)
	{
		for (int i = 0; i < n; i++) par[i] = i;
		for (int i = 0; i < n; i++) r[i] = 0;
	}

	int find(int x)
	{
		if (par[x] == x)return x;
		else return find(par[x]);
	}

	void unite(int x, int y)
	{
		x = find(x);
		y = find(y);

		if (r[x] < r[y])
		{
			par[x] = y;
		}
		else
		{
			par[y] = x;
			if (r[x] == r[y])
			{
				r[x]++;
			}
		}
	}
};



int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n,d,x;
	cin >> n >> d >> x;
	int ans = x;
	rep(i, 0, n) {
		int a;
		cin >> a;
		ans += 1 + (d - 1) / a;
	}
	
	cout << ans << endl;
 
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int mod=1000000007;
long long f(int a){
  if(a==1){
    return 1;
  }
  return a*f(a-1)%mod;
}
int main(){
  int n,m;
  cin >> n >> m;
  if(n==m){
    cout << 2*f(n)%mod*f(m)%mod << endl;
  }
  else if(abs(n-m)==1){
    cout << f(n)%mod*f(m)%mod << endl;
  }
  else{
    cout << 0 << endl;
  }
}

Measured memory_bytes: 1792
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<numeric>

using namespace std;

typedef long long ll;

int main(){
	int n; scanf("%d", &n);
	ll a[200000];
	for(int i = 0; i < n; i++) scanf("%lld", &a[i]);
	ll s = a[0], b = accumulate(a + 1, a + n, 0LL);
	ll res = abs(s - b);
	for(int i = 1; i < n - 1; i++){
		s += a[i]; b -= a[i];
		res = min(res, (ll)abs(s - b));
	}
	printf("%lld\n", res);
	return 0;
}

Measured memory_bytes: 1664
#include<iostream>
#define K 1500001
using namespace std;
int h[K],w[K],n,m,i,j,p[1500],k;
int main(){
  while(1){
    for(i=1;i<K;i++)h[i]=0,w[i]=0;
    cin>>n>>m;if(n==0)break;
    for(i=0;i<n;i++){
      cin>>p[i];
      for(j=i,k=0;j>=0;j--,k+=p[j])h[p[i]+k]++;
    }
    for(i=0;i<m;i++){
      cin>>p[i];
      for(j=i,k=0;j>=0;j--,k+=p[j])w[p[i]+k]++;
    }
    n=0;
    for(i=1;i<K;i++)n+=h[i]*w[i];
    cout<<n<<endl;
  }
  return 0;
}

Measured memory_bytes: 12884
// https://atcoder.jp/contests/abc085/tasks/abc085_c

#include <iostream>

using namespace std;

int main() {
    int n, y;

    cin >> n >> y;

    for (int i = 0; i <= n; i++)
    {
        if (10000 * i > y) { break; }

        for (int j = 0; j <= n - i; j++) {
            int remaining = y - 10000 * i - 5000 * j;

            if (remaining == 1000 * (n - i - j)) {
                cout << i << " " << j << " " << n - i -j << endl;
                return 0;
            }
        }
    }

    cout << "-1 -1 -1" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

#define N 100000

typedef struct{
  char mark;
  int num;
}Card;

Card A[N], C[N];
int count=0;

void change(Card n, Card m){
  Card x;
  x = n;
  n = m;
  m = x;
}

int partition(Card A[], int p, int r){
  int i, j, x, n;
  Card B;
  x = A[r].num;
  i = p-1;
  for(j=p; j<r; j++){
    if(A[j].num <= x){
      i++;
      B = A[j];
      A[j] = A[i];
      A[i] = B;
    }
  }
  B = A[r];
  A[r] = A[i+1];
  A[i+1] = B;
  return i+1;
}

void quicksort(Card A[], int p, int r){
  int q;
  if(p < r){
    q = partition(A, p, r);
    quicksort(A, p, q-1);
    quicksort(A, q+1, r);
  }
}

void Merge(Card C[], int left, int mid, int right){
  int n1 = mid - left;
  int n2 = right - mid;
  Card L[n1+1], R[n2+1];
  int i, j, k;

  for(i=0; i<n1; i++){
    L[i] = C[left + i];
  }

  for(i=0; i<n2; i++){
    R[i] = C[mid + i];
  }

  L[n1].num = R[n2].num = 1000000000;
  i = j = 0;
  for(k=left; k<right; k++){
    count++;
    if (L[i].num <= R[j].num){
      C[k] = L[i];
      i++;
    }
    else{
      C[k] = R[j];
      j++;
    }
  }
}

void MergeSort(Card C[], int left, int right){
  int mid;
  if(left+1 < right){
    mid = (left + right)/2;
    MergeSort(C, left, mid);
    MergeSort(C, mid, right);
    Merge(C, left, mid, right);
  }
}

int main(){
  int i, n, j, frag=0;
  scanf("%d",&n);
  for(i=0; i<n; i++) {
    scanf("%s%d", &A[i].mark, &A[i].num);
    C[i] = A[i];
  }
  quicksort(A, 0, n-1);
  MergeSort(C, 0, n);
  for(i=0; i<n; i++){
    if(A[i].num == C[i].num && A[i].mark == C[i].mark)
      frag++;
  }
  if(frag == n) printf("Stable\n");
  else printf("Not stable\n");
  for(i=0; i<n; i++) printf("%s %d\n",&A[i].mark, A[i].num);
  return 0;
}

Measured memory_bytes: 2952
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include<map>
#include<list>
#include<cctype>
#include<climits>
#include<bitset>
#include<stack>

using namespace std;

typedef long long ll;

const int dx[4] = { 1, 0, -1, 0 }, dy[4] = { 0, 1, 0, -1 };
const int MAX = 19;
int W, H, fld[10][10];
int P, sx, sy;
map<pair<pair<int, int>, int>, int> memo;

inline int CountBit(int s)
{
	int res = 0;
	for (int i = 0; i < P; i++) res += (s >> i) & 1;
	return res;
}

inline bool IsInside(int x, int y)
{
	return 0 <= x && x < W && 0 <= y && y < H;
}

inline bool CanDown(int x, int y, int s, int noBits)
{
	if (x == sx && y == sy && noBits == P) return true;
	if (fld[y][x] == -1) return false;
	return ((s >> fld[y][x]) & 1) == 0;
}

int DFS(int x, int y, int s, int &order)
{
	order++;
	int noBits = CountBit(s);
	if (x == sx && y == sy && noBits == P) return 1;
	pair<pair<int, int>, int> state = make_pair(make_pair(x, y), s);
	if (noBits < MAX)
	{
		map<pair<pair<int, int>, int>, int>::iterator itr = memo.find(state);
		if (itr != memo.end()) return itr->second;
	}
	int sum = 0, cnt = 0;
	for (int i = 0; i < 4; i++)
	{
		int nx = x + dx[i], ny = y + dy[i];
		while (IsInside(nx, ny) && !CanDown(nx, ny, s, noBits))
			nx += dx[i], ny += dy[i];
		if (!IsInside(nx, ny)) continue;
		sum += DFS(nx, ny, s | (1 << fld[ny][nx]), cnt);
	}
	order += cnt;
	if (noBits < MAX && !(noBits >= 14 && cnt <= 50)) memo[state] = sum;
	return sum;
}

signed main()
{
	while (cin >> W >> H, W || H)
	{
		memo.clear();
		P = 0;
		for (int i = 0; i < H; i++)
		{
			for (int j = 0; j < W; j++)
			{
				cin >> fld[i][j];
				if (fld[i][j] == 0) fld[i][j] = -1;
				else if (fld[i][j] == 1) fld[i][j] = P++;
				else sx = j, sy = i, fld[i][j] = -1;
			}
		}
		int cnt = 0;
		printf("%d\n", DFS(sx, sy, 0, cnt));
	}
	return 0;
}

Measured memory_bytes: 24276
#include <cstdio>
#include <cstring>
#include <algorithm>
 
using namespace std;
 
typedef long long ll;
 
int num[100005],s[100005];
int id[100005],now[100005];
bool vis[100005];
int ans[100005];
 
int main() {
  int n;
  scanf("%d",&n);
  for(int i=1;i<=n;i++) {
    scanf("%d",&num[i]);
    if (i>1) s[i-1]=num[i]-num[i-1];
  }
  for(int i=1;i<n;i++) id[i]=i;
  int m;
  ll k=0;
  scanf("%d%lld",&m,&k);
  for(int i=1;i<=m;i++) {
    int x;
    scanf("%d",&x);
    swap(id[x-1],id[x]);
  }
  for(int i=1;i<n;i++)
    if (!vis[i]) {
      int x=i,cnt=0;
      while (!vis[x]) {
        now[cnt++]=x;
        vis[x]=1;
        x=id[x];
      }
      for(int i=0;i<cnt;i++)
        ans[now[i]]=now[(i+k)%cnt];
    }
  ll sum=num[1];
  for(int i=1;i<=n;i++) {
    printf("%lld.0\n",sum);
    sum+=s[ans[i]];
  }
  return 0;
}


Measured memory_bytes: 3456
#include "bits/stdc++.h"
using namespace std;
using ll = long long; using ull = unsigned long long;
//#define int ll
using vb = vector<bool>; using vvb = vector<vb>;
using vi = vector<int>; using vvi = vector<vi>;
using vl = vector<ll>; using vvl = vector<vl>;
template<class T> using V = vector<T>;
template<class T> using VV = vector<V<T>>;
#define fi first
#define se second
#define maxs(x,y) (x=max(x,y))
#define mins(x,y) (x=min(x,y))
using pii = pair<int,int>; using pll = pair<ll,ll>;
#define FOR(i,a,b) for(ll i = (a); i < (ll)(b); ++i)
#define REP(i,n) FOR(i,0,n)
#define RFOR(i,a,b) for(ll i = (ll)(b)-1;i >= a;--i)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define eb(val) emplace_back(val)
const double PI = acos(-1), EPS = 1e-10;
const ll MOD = 1e9+7;
void cioacc(){//accelerate cin/cout
  cin.tie(0);
  ios::sync_with_stdio(false);
}
void printvec(const vector<int> &v){
  REP(i,v.size()-1) cout << v[i] <<" ";
  cout << v.back() << endl;
}
signed main(){
  int n;
  cin >> n;
  vi a(n);
  REP(i,n) cin >> a[i];
  int c = 0;
  REP(i,n){
    auto itr = min_element(a.begin()+i,a.end());
    if(i!=distance(a.begin(),itr)){
      swap(a[i],*itr);
      c++;
    }
  }
  printvec(a);
  cout << c << endl;
}



Measured memory_bytes: 3088
#include<bits/stdc++.h>
#define FIO ios::sync_with_stdio(false)
#define N 100100
#define INF 0x3f3f3f3f
#define LL long long int
using namespace std;
struct node{
	int x,y,tag;
	string ans;
}T[N];
int cnt[N];
bool cmp(node a,node b){
	if(a.x==b.x)
		return a.y<b.y;
	return a.x<b.x;
}
bool cmp2(node a,node b){
	return a.tag<b.tag;
}
string fun(int x){
	string str1(6,'0');
	string str2(6,'0');
	int pos=5;
	int temp=x;
	while(temp){
		str1[pos--]+=temp%10;
		temp/=10;
	}
	pos=5;
	cnt[x]++;
	temp=cnt[x];
	while(temp){
		str2[pos--]+=temp%10;
		temp/=10;
	}
	return str1+str2;
}
int main(){
	int a,n;
	cin>>a>>n;
	for(int i=1;i<=n;i++){
		cin>>T[i].x>>T[i].y;
		T[i].tag=i;
	}
	sort(T+1,T+1+n,cmp);
	for(int i=1;i<=n;i++){
		T[i].ans=fun(T[i].x);
	}
	sort(T+1,T+1+n,cmp2);
	for(int i=1;i<=n;i++){
		cout<<T[i].ans<<endl;
	}
}


Measured memory_bytes: 9728
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>
#include<bits/stdc++.h>
using namespace std;
using namespace __gnu_pbds;


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


#define pf                  printf
#define sf(a)               scanf("%d",&a)
#define sfl(a)              scanf("%lld",&a)
#define sff(a,b)            scanf("%d %d",&a,&b)
#define sffl(a,b)           scanf("%lld %lld",&a,&b)
#define sfff(a,b,c)         scanf("%d %d %d",&a,&b,&c)
#define sfffl(a,b,c)        scanf("%lld %lld %lld",&a,&b,&c)
#define sffff(a,b,c,d)      scanf("%d %d %d %d",&a,&b,&c,&d)
#define sffffl(a,b,c,d)     scanf("%lld %lld %lld %lld",&a,&b,&c,&d)
#define sfffff(a,b,c,d,e)   scanf("%d %d %d %d %d",&a,&b,&c,&d,&e)
#define sfffffl(a,b,c,d,e)  scanf("%lld %lld %lld %lld %lld",&a,&b,&c,&d,&e)
#define sfc(a)              scanf("%c",&a)
#define pii                 pair<int,int>
#define ms(a,b)             memset(a,b,sizeof(a))
#define pb(a)               push_back(a)
#define pbp(a,b)            push_back({a,b})
#define db                  double
#define ft                  float
#define ll                  long long
#define ull                 unsigned long long
#define pii                 pair<int,int>
#define ff                  first
#define ss                  second
#define sz(x)               x.size()
#define all(x)              x.begin(),x.end()
#define CIN                 ios_base::sync_with_stdio(0); cin.tie(0)
#define max3(a, b, c)       max(a, b) > max(b, c) ? max(a, b) : max(b, c)
#define min3(a, b, c)       min(a, b) < min(b, c) ? min(a, b) : min(b, c)
#define for0(i,n)           for(int i=0;i<n;i++)
#define for1(i,n)           for(int i=1;i<=n;i++)
#define forrev(i,n)         for(int i=n-1; i>=0; i--)
#define forab(i,a,b)        for(int i=a;i<=b;i++)
#define forba(i,b,a)        for(int i=b;i>=a;i--)
#define stlloop(x)          for(__typeof(x.begin()) it=x.begin();it!=x.end();it++)
#define gcd(a, b)           __gcd(a, b)
#define lcm(a, b)           ((a)*((b)/gcd(a,b)))
#define case1(z)            cout<<"Case "<<z<<": "
#define case2(z)            printf("Case %d: ",z)
#define PI                  acos(-1) //3.14159265358979323846264338328
#define valid(tx,ty)        tx>=0 && tx<row && ty>=0 && ty<col
#define intlim              2147483648
#define N                   2000007
#define inf                 100000008
#define mod                 1000000007

vector<ll>comp;
vector<ll>v[N];
ll visited[N];
void dfs(ll s)
{
    comp.pb(s);
    visited[s]=1;
    for(ll i=0;i<v[s].size();i++)
    {
        if(visited[v[s][i]]==0)
        {
            dfs(v[s][i]);
        }
    }
}



int main()
{
    ll n,m,i,x,y,mx=0;
    cin>>n>>m;
    for1(i,m)
    {
        cin>>x>>y;
        v[x].pb(y);
        v[y].pb(x);
    }
    for1(i,n)
    {
        if(visited[i]==0)
        {
            dfs(i);
            x = comp.size();
            mx = max(mx,x);
            comp.clear();
        }
    }
    cout<<mx<<endl;
    return 0;
}





















Measured memory_bytes: 68988
#include <bits/stdc++.h>
#define f(i,n) for(int i=0;i<(n);i++)
#define P pair<int,int>
#define mod 1000000007
#define S second
#define F first
#define int long long
using namespace std;
vector<int> v;
int x[200010],b[100010],c[100010];
void mutu(int a,int aa){
	int l=0,r=(int)(v.size());
	while(r-l>=1){
		int i=(r+l)/2;
		if(a==0){
			if(v[i]==b[aa]){
				b[aa]=i;
				return ;
			}
			else if(v[i]<b[aa]) l=i+1;
			else r=i;
		}
		else{
			if(v[i]==c[aa]){
				c[aa]=i;
				return ;
			}
			else if(v[i]<c[aa]) l=i+1;
			else r=i;
		}
	}
}
signed main(){
	int a,ans=0;
	cin>>a;
	f(i,a){
		cin>>b[i]>>c[i];
		v.push_back(b[i]);
		v.push_back(c[i]);
	}
	sort(v.begin(),v.end());
	for(int i=1;i<v.size();i++){
		loop:;
		if(v[i]==v[i-1]){ 
			v.erase(v.begin()+i);
			goto loop;
		}
	}
	f(i,a){
		mutu(0,i);
		mutu(1,i);
	}
	f(i,a){
		x[b[i]]++;
		x[c[i]]--;
	}
	ans=x[0];
	for(int i=1;i<v.size();i++){
		x[i]+=x[i-1];
		ans=max(ans,x[i]);
	}
	cout<<ans<<endl;
	return 0;
}



Measured memory_bytes: 7816
N=int(input())
s=[]
total=0
A=0
B=0
BA=0
for i in range(N):
    tmp=input()
    while True:
        if len(tmp)>=2:
            if "AB" in tmp[:2]:
                total+=1
                tmp=tmp[2:]
            else:
                break
        else:
            break
    while True:
        
        if len(tmp)>=2:
            if "AB" in tmp[-2:]:
                total+=1
                tmp=tmp[-2:]
            else:
                break
        else:
            break
    total+=tmp.count("AB")
    if len(tmp)>0:
        if tmp[0]=="B" and tmp[-1]=="A":
            BA+=1
        elif tmp[0]=="B":
            B+=1
        elif tmp[-1]=="A":
            A+=1

if BA>0:
    if B>0 and A>0:
        total+=BA+1
        B-=1
        A-=1
    elif A>0:
        total+=BA
    elif B>0:
        total+=BA
    else:
        total+=BA-1
        
        
print(total+min(A,B))


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

using namespace std;

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int d;
	cin >> d;
	if (d==25) cout << "Christmas";
	else if (d==24) cout << "Christmas Eve";
	else if (d==23) cout << "Christmas Eve Eve";
	else cout << "Christmas Eve Eve Eve";
	return 0;
}

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

int main(){
  int x,n;
  cin >> x >> n;
  vector<pair<int,int>>  vp(102);
  rep(i,102){
    vp[i] = {abs(i-x),i};
  }
  rep(i,n){
    int p;
    cin >> p;
    vp[p].first = 100;
  }
  sort(all(vp));
  cout << vp[0].second << endl;
}

Measured memory_bytes: 3572
#include <cstdio>
#include <cmath>
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <algorithm>
#include <queue>
using namespace std;
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define REP(i,n) for(ll i=0;i<n;i++)
#define REPR(i,n) for(ll i=n-1;i>=0;i--)

typedef long long ll;
#define INF 1e18

int main(){
	ll n; cin>>n;
	ll r; cin>>r;
	if(n<10){
		r+=100*(10-n);
	}
	cout<<r<<endl;
	return 0;
}

Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author yassin
 */

#include <bits/stdc++.h>

using namespace std;

using i64 = long long;

class agc023_a {
public:
    void solve(istream& in, ostream& out) {
        int N;
        in >> N;
        vector<i64> A(N);
        for (int i = 0; i < N; ++i) {
            in >> A[i];
        }
        i64 sum = 0, res = 0;
        map<i64, int> m;
        m[0] = 1;
        for (int i = 0; i < N; ++i) {
            sum += A[i];
            res += m[sum];
            ++m[sum];
        }
        out << res << "\n";
    }
};

int main() {
	std::ios::sync_with_stdio(false); cin.tie(nullptr);
	agc023_a solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


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

using namespace std;

long long N;
bool is_ok(long long X, long long k) {
  if (k == 1) {
    return false;
  }
  while (X % k == 0) {
    X /= k;
  }
  return X % k == 1;
}

int main() {
  cin >> N;

  long long ans = 0;

  for (long long k = 1; k * k <= N; k++) {
    if (N % k != 0) {
      continue;
    }
    if (k != 1) {
      ans += is_ok(N, k);
    }
    if (N / k > k) {
      ans += is_ok(N, N / k);
    }
  }

  for (long long k = 1; k * k <= N - 1; k++) {
    if ((N - 1) % k != 0) {
      continue;
    }
    if (k != 1) {
      ans++;
    }
    if ((N - 1) / k > k) {
      ans++;
    }
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 3644
S = input()
T = input()
result = True

arrayS = []
arrayT = []
for i in range(len(S)):
    if S[i] in arrayS:
        if arrayT[arrayS.index(S[i])] != T[i]:
            result = False
            break
    elif T[i] in arrayT:
        result = False
        break
    else:
        arrayS.append(S[i])
        arrayT.append(T[i])

print('Yes' if result else 'No')


Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define MOD 1000000007
#define INF 1234567890
#define pii pair<LL,LL>
#define LL long long
using namespace std;

LL fpow(LL a, LL b) {
    LL ans = 1;
    while (b) {
        if (b & 1) {
            ans *= a;
            ans %= MOD;
        }
        a *= a;
        a %= MOD;
        b >>= 1;
    }
    return ans;
}

LL fac[2000005], inv[2000005];

void precompute(LL x) {
    fac[0] = 1;
    inv[0] = 1;
    for (LL i=1;i<=x;i++) {
        fac[i] = fac[i-1] * i;
        fac[i] %= MOD;
        inv[i] = fpow(fac[i], MOD-2);
    }
}

LL c(LL n, LL k) {
    if (n < k) return 0;
    LL ret = fac[n];
    ret *= inv[k];
    ret %= MOD;
    ret *= inv[n-k];
    ret %= MOD;
    return ret;
}

int main () {
    //clock_t start = clock();
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    LL k;
    string s;
    cin >> k >> s;
    LL n = s.size();
    precompute(2000000);

    LL ans = 0;
    for (int i=0;i<=k;i++) {
        LL tmp = 1;
        tmp *= fpow(26, i);
        tmp %= MOD;
        tmp *= fpow(25, k-i);
        tmp %= MOD;
        tmp *= c(n-1+k-i, n-1);
        tmp %= MOD;
        ans += tmp;
        ans %= MOD;
    }
    cout << ans << endl;
    //cerr << fixed << setprecision(3) << (clock()-start)*1./CLOCKS_PER_SEC << endl;
    return 0;
}

Measured memory_bytes: 35656
#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
 
/*** Template Begins ***/
 
typedef unsigned long long    ll;
typedef pair<ll,ll>  pll;
typedef pair<ll, pair<int, int> > plll;
typedef vector<long long>  vll;
typedef vector<pll>  vp;
typedef long double ld;
#define pb           push_back
#define INF          INT_MAX/10
#define F            first
#define S            second
#define mp           make_pair
// #define ios          ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define hell         1000000007
// #define h 998244353
#define all(a)       (a).begin(),(a).end()
ll power(ll x, ll y, ll p)
{
  ll res = 1;
  x = x % p;
  while (y > 0)
  { 
    if (y & 1) 
      res = (res*x) % p;
    y = y>>1;
    x = (x*x) % p;
  } 
  return res; 
} 
const int MAXN = 2e5+5;

// Debug //
#define trace(x)                 cerr << #x << ": " << x << endl;
#define trace1(x)                cerr << #x << ": " << x << endl;
#define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
#define trace4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;
#define trace5(a, b, c, d, e)    cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl;
// #define trace6(a, n,i;b, c, d, e, f) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;

// Constants //
 
/*** Template Ends ***/
ll fact[400005];
ll inv(ll val)
{
  return power(val,hell-2,hell);
}
ll ncr(ll n,ll r)
{
  return ((fact[n]*inv(fact[r]))%hell*inv(fact[n-r])%hell)%hell;
}

void solve()
{
  ll n,k,i;
  cin>>n>>k;
  fact[0]=1;
  for(i=1;i<400005;i++)
  {
    fact[i] = fact[i-1]*i;
    fact[i]%=hell;
  }
  if(k>=n-1)
  {
    cout<<ncr(2*n-1,n);
  }
  else
  {
    ll ans=0;
    for(i=0;i<=k;i++)
    {
      ans=ans+(ncr(n,i)*ncr(n-1,n-i-1))%hell;
      // trace(ans);
      ans%=hell;
    }
    cout<<ans;
  }
}
int main()
{ 
  // ios;
  // fxreopen("inputt.txt", "w", stdout);
  ll t;
  // cin >> t;
  t=1;
  while(t--)
    solve();
  return 0;
}

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

int main()
{
	float n, t, a, d;
	cin >> n >> t >> a;
	cin >> d;
	d = abs(t - 0.006*d - a);
	int j = 0;
	for (int i = 1; i < n; i++)
	{
		int c;
		cin >> c;
		auto b = abs(t - 0.006*c - a);
		if (b < d)
		{
			d = b;
			j = i;
		}
	}
	cout << j + 1 << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

/*
 * 何回目の探索で来たのかを入れておく
 * 同じ回数目の探索ならループで、違うならもう既にそのループはカウント済み
 */
class E{
	int loop;
	int x;
	int y;
	
	E(int a,int b){
		loop=0;
		x=a;
		y=b;
	}
	
}
public class Main {
	E map[][];
	int count,sx,sy;
	public static void main(String[] args) {
		new Main().run();
	}
	void run(){
		Scanner sc=new Scanner(System.in);
		
		while(true){
			int n=sc.nextInt();
			if(n==0) break;
			map=new E[n][n];
			for(int i=0;i<n;i++){
				for(int j=0;j<n;j++){
					int a=sc.nextInt();
					int b=sc.nextInt();
					map[j][i]= new E(a,b);
				}
			}
			int c=1;
			count=0;
			for(int i=0;i<n;i++){
				for(int j=0;j<n;j++){
					if(map[j][i].loop==0){
						sx=j;sy=i;
//						System.out.println("!");
						solve(j, i, c);
						c++;
						//count++;
					}
				}
			}
			System.out.println(count);
		}
	}
	
	void solve(int mx,int my,int c){
//		System.out.println(mx+" "+my+"  "+map[mx][my].x+" "+map[mx][my].y);
		
		if(0<map[mx][my].loop){
			if(c==map[mx][my].loop){
				count++;
			}
				return;
		}
		
		int a=map[mx][my].x;
		int b=map[mx][my].y;
		
		map[mx][my].loop=c;
		
		solve(a, b, c);
	}

}

Measured memory_bytes: 60352
N, M, C = map(int, input().split())
B = list(map(int, input().split()))
A = [list(map(int, input().split())) for _ in range(N)]
ans = 0
for i in range(N):
    hantei = C
    for j in range(M):
        hantei += A[i][j] * B[j]
    if hantei > 0: ans += 1
print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define mod 1000000007
#define ll long long int
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
using namespace std;

bool isPrime(ll n) 
{ 
    if (n <= 1)  return false; 
    if (n <= 3)  return true; 
  
    if (n%2 == 0 || n%3 == 0) return false; 
  
    for (int i=5; i*i<=n; i=i+6) 
        if (n%i == 0 || n%(i+2) == 0) 
           return false; 
    return true; 
} 

ll power(ll x,ll y) 
{ 
	if(x == 0) 
        return 0; 
    if (y == 0) 
        return 1; 
    else if (y % 2 == 0) 
        return power(x, y / 2) * power(x, y / 2); 
    else
        return x * power(x, y / 2) * power(x, y / 2); 
} 

int main()
{
	#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
	#endif

    fastio
    ll t, i, j, x;
    cin>>t;
    if(t%1000==0)
    	cout<<0;
    else
    cout<<1000-(t%1000);
}

Measured memory_bytes: 3648
//52行目から編集
#include <iostream>
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <cassert>

using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define eb emplace_back

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vector<int> > vvi;
typedef vector<vector<ll> > vvl;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;

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

int main(int argc, char const *argv[])
{
    ll n;cin>>n;
    ll ans=0;
    for(ll i=1;i*i<=n-1;i++){
        if((n-1)%i==0){
            if(i!=1)ans++;
            if(i*i!=n-1)ans++;
        }
    }
    for(ll i=1;i*i<=n;i++){
        if(n%i==0){
            if(i!=1){
                ll m=n;
                while(m && m%i==0){
                    m/=i;
                }
                ans += (m%i==1);
            }
            if(i*i==n)continue;
            ll m=n;
            while(m && m%(n/i)==0){
                m/=(n/i);
            }
            ans+=(m%(n/i)==1);
        }
    }
    cout<<ans<<'\n';
    return 0;
}























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

int main(){
    vector<int> a(3);
    rep(i,3) cin >> a[i];
    sort(a.begin(),a.end());
    cout << (a[0] == a[1] ? a[2] : a[0]) << endl;
    
    return 0;
}


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

#define sws ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define INFINITO 1000000000
#define ll long long
#define vi vector<int>
#define pb push_back
#define pii pair<int, int>
#define mp make_pair
#define ff first
#define ss second
#define vvi vector<vi>
#define all(x) x.begin(), x.end()
#define fo(i, n) for( int i = 0; i < n; i++ )


int main() {

    int a, b, k;
    cin >> a >> b >> k;
    set<int> ns;

    for ( int i = 0; i < k and i + a <= b; i++ ) {
        cout << i + a << endl;
        ns.insert(i + a);
    }
    for ( int i = 0; i < k; i++ ) {
        if ( ns.find(b - k + 1 + i) != ns.end() or b - k + 1 + i < a ) continue;
        if ( b - k + 1 + i > b ) break;
        cout << b - k + 1 + i << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int a[100005];

typedef long long ll;

int main() {

	int N, x;

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

	int i;

	for (i = 0; i < N; i++) {
		scanf(" %d",&a[i]);
	}
	ll sum = 0ll;
	for (i = 0; i < N - 1; i++) {
		if (a[i] + a[i + 1] > x) {
			int eat = a[i + 1] + a[i] - x;
			sum += (ll)eat;
			if (eat <= a[i + 1]) { a[i + 1] -= eat; }
			else {
				a[i] -= eat - a[i + 1];
				a[i + 1] = 0;
			}
		}
	}
	printf("%lld\n",sum);

	return 0;
}

Measured memory_bytes: 512
//--- pE ---//
import java.util.*;
import java.lang.*;
import java.io.*;
public class Main {
	public static void main (String[] args) throws java.lang.Exception {
		new Solution();
	}
}
class Solution {
	Reader reader;
	PrintWriter out;
	public Solution() {
		reader = new Reader();
		out = new PrintWriter(System.out);
		while (reader.hasNext()) {
			run_case();
		}
		out.flush();
	}

	private void run_case() {
		long n = reader.nl();
		long m = reader.nl();
		long k = reader.nl();
		long ans = 0;
		buildFact((int)n+1);
		for (int i=0; i<=k; i++) {
			ans += pm(m-1,n-1-i, mod) * m % mod * nCr((int)n-1, i) % mod;
			// out.println(ans);
			ans %= mod;
		}
		out.println(ans);
		return;
	}

	long[] fact;
	long[] fact_inv;
	long mod = (long)998244353;
	// long mod = (long)1e9+7;
	private void buildFact(int n) {
	    fact = new long[n+1];
	    fact_inv = new long[n+1];

	    fact[0] = 1;
		fact_inv[0] = 1;
	    for (int i=1; i<n+1; i++) {
	        fact[i] = fact[i-1] * i % mod;
	        fact_inv[i] = pm(fact[i], mod - 2, mod);
	    }
	    return;
	}

	private long nCr(int n, int r) {
	    return 1L * fact[n] * fact_inv[r] % mod * fact_inv[n - r] % mod;
	}

	private long pm(long x, long y, long mod) {
	    long res = 1;
	    x = x % mod;
	    while (y > 0) {
	        if ((y & 1) == 1) res = (res * x) % mod;
	        y = y >> 1;
	        x = (x * x) % mod;
	    }
	    return res;
	}



}


class Reader {
	BufferedReader br;
	StringTokenizer st;
	public Reader(){
		try {
			br = new BufferedReader(new InputStreamReader(System.in));
			st = new StringTokenizer(br.readLine());
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	public String next() {
		if (st.hasMoreTokens()) return st.nextToken();
		try {
			st = new StringTokenizer(br.readLine());
		} catch (Exception e) {
			e.printStackTrace();
		}
		return st.nextToken();
	}
	public boolean hasNext() {
		try {
			if (!st.hasMoreTokens() && !br.ready()) return false;
			else return true;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return false;
	}
	public int ni() {return Integer.parseInt(this.next());}
	public long nl() {return Long.parseLong(this.next());}
	public String ns() {return this.next();}
}


Measured memory_bytes: 35888
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Console = System.Console;

namespace Atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = ReadInt();
            var S = Read();
            int ret = 0;
            int cal = 0;
            for (int i = 0; i < N; i++)
            {
                if (S[i] == 'I')
                {
                    ++cal;
                }else if (S[i] == 'D')
                {
                    --cal;
                }

                ret = Math.Max(cal, ret);
            }

            Console.WriteLine(ret);
        }

        private static readonly Func<string> Read = () => Console.ReadLine();
        private static readonly Func<string[]> ReadStringArray = () => Console.ReadLine().Split();
        private static readonly Func<int> ReadInt = () => int.Parse(Console.ReadLine());
        private static readonly Func<long> ReadLong = () => long.Parse(Console.ReadLine());
        private static readonly Func<int[]> ReadIntArray = () => Console.ReadLine().Split().Select(int.Parse).ToArray();
        private static readonly Func<long[]> ReadLongArray = () => Console.ReadLine().Split().Select(long.Parse).ToArray();
        private static readonly Action<string> Cw = str => Console.WriteLine(str);
    }
}

Measured memory_bytes: 11092
n, m = map(int, input().split())

if n < m: # n >= m
    n, m = m, n

if m + 1 == n or m == n:
    # m! * 1 or 2 * n!
    if m + 1 == n:
        ans = 1
    else:
        ans = 2
    k = 1
    for i in range(1, n + 1):
        k *= i
        if i == m:
            ans *= k
        k = k % (10**9 + 7)
    ans *= k
    print(ans % (10**9 + 7))
else:
    print(0)

Measured memory_bytes: 9184
#include "bits/stdc++.h"
using namespace std;

#define sz(x) (int)(x.size())
#define FOR(i,L,R) for(int i = L; i <= R; i++)
#define int long long

const int N = 2e5 + 2, inf = 1e18;

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

    int L, R;
    cin >> L >> R;
    vector<int> one;
    FOR(i,L,min(L+10,R)) {
        one.push_back(i);
    }    
    FOR(i,max(R-10,L),R) {
        one.push_back(i);
    }
    if (L <= 0 && 0 <= R) 
        one.push_back(0);

    cin >> L >> R;
    vector<int> two;
    FOR(i,L,min(L+10,R)) {
        two.push_back(i);
    }    
    FOR(i,max(R-10,L),R) {
        two.push_back(i);
    }
    if (L <= 0 && 0 <= R) 
        two.push_back(0);
    int ans = -2 * inf;
    for(int x : one) for(int y : two) 
        ans = max(ans, 1LL * x * y);
    cout << ans;
}


Measured memory_bytes: 3660
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class T>
using Table = vector<vector<T>>;
const ld eps=1e-9;

//// < "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\a.txt"
int main() {
	int sum = 0;
	for (int i = 0; i < 10; ++i) {
		int a; cin >> a; sum += a;
	}
	cout << sum << endl;
	return 0;
}

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

int main()
{

  int H, W;

  while(cin >> H >> W){
    if(!H && !W) break;

    for(int i = 0; i < H; i++){
      for(int j = 0; j < W; j++){
        if(i == 0 || i == H - 1) cout << "#";

        else{
          if(j == 0 || j == W - 1) cout << "#";
          else cout << ".";
        }
      }

      cout << endl;

    }

    cout << endl;

  }

  return 0;

}

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

public class Main {

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

    void solve() {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        long[] a = new long[N];
        long A = 0;
        for (int i = 0; i < N; i++) {
            a[i] = sc.nextInt();
            A += a[i] - 1;
        }
        System.out.println(A);
    }
}

Measured memory_bytes: 25776
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
int c = a/3600;
int d = a-3600*c;
int e = d/60;
int f = d-60*e;
		System.out.println(c+":"+e+":"+f);
	}
}


Measured memory_bytes: 26140