akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

typedef int64_t s64;
int ri() {
	int n;
	scanf("%d", &n);
	return n;
}
int64_t rll() {
	long long n;
	scanf("%lld", &n);
	return n;
}

#define MOD 998244353
template<int mod>
struct ModInt{
    int x;
    ModInt():x(0){}
    ModInt(long long y):x(y>=0?y%mod:(mod-(-y)%mod)%mod){}
    ModInt &operator+=(const ModInt &p){
        if((x+=p.x)>=mod)x-=mod;
        return *this;
    }
    ModInt &operator-=(const ModInt &p){
        if((x+=mod-p.x)>=mod)x-=mod;
        return *this;
    }
    ModInt &operator*=(const ModInt &p){
        x=(int)(1LL*x*p.x%mod);
        return *this;
    }
    ModInt &operator/=(const ModInt &p){
        *this*=p.inverse();
        return *this;
    }
	ModInt &operator^=(long long p){
		ModInt res = 1;
		for (; p; p >>= 1) {
			if (p & 1) res *= *this;
			*this *= *this;
		}
		return *this = res;
	}
    ModInt operator-()const{return ModInt(-x);}
    ModInt operator+(const ModInt &p)const{return ModInt(*this)+=p;}
    ModInt operator-(const ModInt &p)const{return ModInt(*this)-=p;}
    ModInt operator*(const ModInt &p)const{return ModInt(*this)*=p;}
    ModInt operator/(const ModInt &p)const{return ModInt(*this)/=p;}
	ModInt operator^(long long p)const{return ModInt(*this)^=p;}
    bool operator==(const ModInt &p)const{return x==p.x;}
    bool operator!=(const ModInt &p)const{return x!=p.x;}
    explicit operator int() const { return x; }                           // added by QCFium
    ModInt operator=(const int p) {x = p; return ModInt(*this);} // added by QCFium
    ModInt inverse()const{
        int a=x,b=mod,u=1,v=0,t;
        while(b>0){
            t=a/b;
            a-=t*b;
            std::swap(a,b);
            u-=t*v;
            std::swap(u,v);
        }
        return ModInt(u);
    }
    friend std::ostream &operator<<(std::ostream &os,const ModInt<mod> &p){
        return os<<p.x;
    }
    friend std::istream &operator>>(std::istream &is,ModInt<mod> &a){
        long long x;
        is>>x;
        a=ModInt<mod>(x);
        return (is);
    }
};
typedef ModInt<MOD> mint;

struct MComb {
    std::vector<mint> fact;
    std::vector<mint> inversed;
    MComb(int n) { // O(n+log(mod))
        fact = std::vector<mint>(n+1,1);
        for (int i = 1; i <= n; i++) fact[i] = fact[i-1]*mint(i);
        inversed = std::vector<mint>(n+1);
        inversed[n] = fact[n] ^ (MOD-2);
        for (int i = n - 1; i >= 0; i--) inversed[i]=inversed[i+1]*mint(i+1);
    }
    mint ncr(int n, int r) {
        return (fact[n] * inversed[r] * inversed[n-r]);
    }
    mint npr(int n, int r) {
        return (fact[n] * inversed[n-r]);
    }
    mint nhr(int n, int r) {
        assert(n+r-1 < (int)fact.size());
        return ncr(n+r-1, r);
    }
};


int main() {
	int n = ri(), a = ri(), b = ri();
	s64 k = rll();
	MComb com(300001);
	mint res = 0;
	for (int i = 0; i <= n; i++) {
		s64 left = k - (int64_t) i * a;
		if (left % b) continue;
		if (left / b > n) continue;
		if (left < 0) break;
		res += com.ncr(n, i) * com.ncr(n, left / b);
	}
	std::cout << res << std::endl;
	
	return 0;
}


Measured memory_bytes: 2560
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#define ll long long
#define N 100010
#define TOP (1<<15)
using namespace std;

ll n,t,ans,a[N],sum[N],f[N],Xor[N];

inline ll read(){
	ll x=0,tmp=1;
	char ch=getchar();
	while(!isdigit(ch)){
		if(ch=='-') tmp=-1;
		ch=getchar();
	}
	while(isdigit(ch)){
		x=(x<<3)+(x<<1)+(ch^48);
		ch=getchar();
	}
	return tmp*x;
}

int main(){
	n=read();
	for(ll i=1; i<n; i++){
		ll x=read()+1,y=read()+1,z=read();
		a[x]^=z; a[y]^=z;
	}
	for(ll i=1; i<=n; i++) sum[a[i]]++;
	for(ll i=1; i<=15; i++){
		ans+=sum[i]>>1;
		t|=(sum[i]&1)<<(i-1);
	}
    for(ll i=1; i<TOP; i++) f[i]=f[i>>1]+(i&1);
    for(ll i=1; i<TOP; i++){
    	f[i]--;
    	for(ll j=0; j<15; j++){
        	if((i>>j)&1) Xor[i]^=j+1;
		}
	}
    for(ll i=1; i<TOP; i++){
        if(Xor[i]) continue;
        for(ll j=(i-1)&i; j; j=(j-1)&i){
        	if(!Xor[j]) f[i]=min(f[i],f[j]+f[i^j]);
		}   
    }
	cout<<ans+f[t]<<endl;
	return 0;
}

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

int main(){
    int n;
    cin >> n;
    int j = 1;
    int ans = 0;
    rep(i, n){
        int a;
        cin >> a;
        if(a==j){
            j++;
            continue;
        }else ans++;
    }
    if(ans == n) ans = -1;
    cout << ans << endl;
    return 0;
}

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

int main(){
    int N;
    int P[1000000];
  	int S[1000000];
  	int min = 1000000;
    int cnt = 1;
    cin >> N;
    for(int i=0; i<N; i++){
       cin >> P[i];
       if(P[i] < min) min = P[i];
       S[i] = min;
    }
    for(int i=0; i<N-1; i++){
      if(S[i] != S[i+1]) cnt++;
    };
    cout << cnt << endl;
}

Measured memory_bytes: 6912
from itertools import permutations as pm

def main():
  t = int(input())
  fact9 = 9 * 8 * 7 * 6 * 5 * 4 * 3 * 2
  for _ in range(t):
    l1 = list(map(int, input().split()))
    l2 = list(map(int, input().split()))
    ans1 = 0
    ans2 = 0
    for hand in pm(l2, 9):
      score1 = 0
      score2 = 0
      for i, j in zip(l1, hand):
        if i < j:
          score2 += (i + j)
        else:
          score1 += (i + j)
      if score1 < score2:
        ans2 += 1
      elif score1 > score2:
        ans1 += 1
    print(ans1 / fact9, ans2 / fact9)

main()


Measured memory_bytes: 5656
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
#include <bits/stdc++.h>
using namespace std;
 
 
int main() {
	int N;
	vector <long long int> A;
	long long int res = 1;
	long long int MAX = 1000000000000000000;
 
	cin >> N;
 
	rep(i, N){
		long long int tmp; 
		cin >> tmp;
		if(tmp == 0){
			res = 0;
			break;
		}else if(res == -1){
			continue;
		}else if(MAX/res < tmp){
			res = -1;
		}else{
			res = res*tmp;
		}
	}
 
	cout << res;
		
	return 0;
}

Measured memory_bytes: 3632
#include<iostream>
#include<string>
#include<vector>
#include<utility>
#include<queue>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<complex>
#define INF 1047483647
#define llINF 9223372036854775807
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long

using namespace std;
int main(){
  int n,ma,mb;
  cin>>n>>ma>>mb;
  int ans=INF;
  int dp[50][405][405];
  for(int i=0;i<50;i++)
    for(int j=0;j<405;j++)
      for(int k=0;k<405;k++)
	dp[i][j][k]=INF;
  dp[0][0][0]=0;
  for(int i=0;i<n;i++){
    int a,b,c;cin>>a>>b>>c;
    for(int j=0;j<401;j++){
      for(int k=0;k<401;k++){
	if(dp[i][j][k]==INF)continue;
	dp[i+1][j][k]=min(dp[i+1][j][k],dp[i][j][k]);
	dp[i+1][j+a][k+b]=min(dp[i+1][j+a][k+b],dp[i][j][k]+c);
      }
    }
  }
  for(int i=1;i<401;i++){
    for(int j=1;j<401;j++){
      if(i*mb==j*ma)ans=min(ans,dp[n][i][j]);
    }
  }
  if(ans==INF)ans=-1;
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 32256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        long x = sc.nextLong();
        long y = sc.nextLong();
        long ans = 0;
        long pow = 1;
        while(x * pow <= y){
            pow *= 2;
            ans++;
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
#include <fstream>
#include <stdlib.h>
#include <ctime>
typedef long long ll;
typedef long double ld;

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << setprecision(100);
  //  freopen("input.txt","r",stdin);
    int a,b;
    cin>>a>>b;
    if((b-1)%(a-1)==0) cout<<(b-1)/(a-1);
    else cout<<(b-1)/(a-1)+1;
    return 0;
}


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

ll keta(ll n)
{
  ll k = 0;
  while(n != 0)
  {
    n /= 10;
    k++;
  }
  return k;
}  
//2^iの位の数を返す
ll pla(ll n,ll i)
{
  ll x = pow(2,i + 1),y = pow(2,i);
  return n % x / y;
}



int main() 
{
  ll S; cin>>S;
  ll K=keta(S)-1;
  ll ans=0;
  rep(i,pow(2,K))
  {
    ll moto=S;
    for(ll j=K;j>=0;j--)
    {
      if(j==0||pla(i,j-1)==1)
      {
        ll p=pow(10,j);
        ans+=moto/p;
        //cout<<moto/p<<endl;
        moto%=p;
        //cout<<moto<<" "<<ans<<endl;
      }  
    }  
  } 
  cout<<ans<<endl;
  return 0;
}

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

int main() {
  int a, b;
  cin >> a >> b;
  if(a > 0 && b > 0) {
    cout << "Positive" << "\n";
    return 0;
  } else if((a >= 0 && b <= 0) || (a <= 0 && b >= 0)) {
    cout << "Zero" << "\n";
    return 0;
  } else {
    if((b - a) % 2 == 0) {
      cout << "Negative" << "\n";
      return 0;
    } else {
      cout << "Positive" << "\n";
      return 0;
    }
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define ppb         pop_back
#define mii         map<ll int,ll int>
#define msi         map<string,ll int>
#define mis         map<ll int, string>
#define rep(i,a,b)    for(ll int i=a;i<b;i++)
#define mpi         map<pair<ll int,ll int>,ll int>
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define vii         vector<pair<ll int, ll int>>
#define vs          vector<string>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
//#define time        cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
// cerr<<1.0/CLOCKS_PER_SEC<<endl;
using namespace std;
#define N  1000000007 
#define MAXN   200005
//ll int dp[1001][100005];
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cout.precision(15);
ll int n,k;
cin>>n>>k;
vi a(n);
rep(i,0,n)
cin>>a[i];
ll int dp[n+1][k+1];
ll int pre[n+1][k+1];
rep(i,0,n+1)
{
rep(j,0,k+1)
{
if(i==0 && j==0)
{dp[i][j]=1;
pre[0][0]=1;}
else if(j==0)
{dp[i][j]=1;pre[i][j]=1;}
else if(i==0)
{dp[i][j]=0;pre[i][j]=1;}
else
{
dp[i][j]=0;
pre[i][j]=0;
if(j>a[i-1])
dp[i][j]=(pre[i-1][j]-pre[i-1][j-a[i-1]-1]+N)%N;
else
dp[i][j]=pre[i-1][j]%N;	
pre[i][j]=(pre[i][j-1]%N+dp[i][j]%N)%N;
}}}
cout<<dp[n][k];

}


Measured memory_bytes: 158080
#define _CRT_SECURE_NO_WARNINGS
#define _SCL_SECURE_NO_WARNINGS
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <algorithm>
#include <functional>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
#include <sstream>
#include <numeric>
#include <list>
#include <bitset>
#include <fstream>

using namespace std;
#define REP(i,a,n) for(int i = (a); i < (int)(n); ++i)
#define REM(i,a,n) for(int i = ((n) - 1); i >= (a); --i)
#define EPS 1e-11
#define INF 0x3FFFFFFF
#define INFLL 0x3FFFFFFF3FFFFFFF
#define INFD 1.0e+308
#define FLOAT setprecision(16)
const double PI = 3.1415926535897932;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<LL, LL> PP;

template <class T, class U>
istream& operator>>(istream& ist, pair<T, U>& right) { return ist >> right.first >> right.second; }
template <class T, class U>
ostream& operator<<(ostream& ost, pair<T, U>& right) { return ost << right.first << ' ' << right.second; }
template <class T, class TCompatible, size_t N>
void Fill(T(&dest)[N], const TCompatible& val) { fill(begin(dest), end(dest), val); }
template <class T, class TCompatible, size_t M, size_t N>
void Fill(T(&dest)[M][N], const TCompatible& val) { for (int i = 0; i < M; ++i) Fill(dest[i], val); }
//sum, 累積和
// 負のときの割り算に注意
#if 0
#include <array>
#include <unordered_set>
#include <unordered_map>
template<class T>
using PriorityQ = priority_queue<T, vector<T>, greater<T> >;	// コスト小を優先
#endif

//#ifdef _DEBUG
//#include "IntMod.h"
//#include "Union_Find.h"
//#include "Graph.h"
//#include "Suffix_Array.h"
//#include "Matrix.h"
//#endif

#ifdef __GNUC__
typedef __int128 LLL;
istream& operator>> (istream& ist, __int128& val) { LL tmp;  ist >> tmp; val = tmp; return ist; }
ostream& operator<< (ostream& ost, __int128 val) { LL tmp = val; ost << tmp; return ost; }
#endif

int N;
int main() {
	cin >> N;
	LL a = 1, b = 2, c;
	REP(i, 0, N) {
		c = b;
		b = a;
		a = b + c;
	}
	cout << b << endl;
	return 0;
}


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

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

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

  int c = 1;
  for(int i=1; i<n; i++){
    if(s[i] != s[i-1])c++;
  }
  cout << c << endl;
  return 0;

}

Measured memory_bytes: 512
#include <cassert>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <numeric>
#include <algorithm>

using namespace std;
using lint = long long;
constexpr int MOD = 1000000007, INF = 1010101010;
constexpr lint LINF = 1LL << 60;

template <class T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
	for (const auto &e : vec) os << e << (&e == &vec.back() ? "\n" : " ");
	return os;
}

#ifdef _DEBUG
template <class T>
void dump(const char* str, T &&h) { cerr << str << " = " << h << "\n"; };
template <class Head, class... Tail>
void dump(const char* str, Head &&h, Tail &&... t) {
	while (*str != ',') cerr << *str++; cerr << " = " << h << "\n";
	dump(str + (*(str + 1) == ' ' ? 2 : 1), t...);
}
#define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__)
#else 
#define DMP(...) ((void)0)
#endif

int main() {

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

	string N;
	cin >> N;
	reverse(N.begin(), N.end());
	N += '0'; //番兵

	int ans = 0;
	bool carry = false;
	for (int i = 0; i < N.size(); i++) {

		int now = N[i] - '0' + carry;

		if (now == 5) {
			ans += 5;
			carry = N[i + 1] - '0' >= 5;
		}
		else {
			ans += min(now, 10 - now);
			carry = now > 5;
		}

	}

	cout << ans << "\n";

	return 0;
}

Measured memory_bytes: 1948
/*
[ ( ^ _ ^ ) ]
*/

// problem: atc/abc162_b

import java.io.*;
import java.util.*;


public class Main {
    int INF = (int)1e9;
    long MOD = 1000000007;


    void solve(InputReader in, PrintWriter out) throws IOException {
        long n = in.nextInt();
        long sum = 0;
        for(long i=1; i<=n; i++) {
            if(i%3==0 || i%5==0) {

            } else {
                sum += i;
            }
        }
        out.println(sum);
    }
    

    public static void main(String[] args) throws IOException {
        InputReader in = new InputReader();
        PrintWriter out = new PrintWriter(System.out);
        int t = 1;//in.nextInt();
        while(t-- >0) {
            new Main().solve(in, out);
        }
        out.close();
    }
    
    public static void show(Object... o) {
        System.out.println(Arrays.deepToString(o));
    }
    
    static class InputReader {
        static BufferedReader br;
        static StringTokenizer st;
        public InputReader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }
        String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }
        int nextInt() { return Integer.parseInt(next()); }
        long nextLong() { return Long.parseLong(next()); }
        double nextDouble() { return Double.parseDouble(next()); }
    }
}

Measured memory_bytes: 25844
let n, k = Scanf.sscanf (read_line()) "%d %d" (fun n k ->
  n, k
)
let u = k * (n / k)
let _ = 
  (
    if n - u < abs (n - u - k) then n - u else abs (n - u - k)
  ) |> Printf.printf "%d\n"


Measured memory_bytes: 384
a,b,c = map(int,input().split())
cnt=0
x=[a,b,c]
while x[0]!=x[1] or x[1]!=x[2] or x[2]!=x[0]:
    x.sort()
    if x[2]>=x[0]+2:
        x[0]+=2
        cnt+=1
    else:
        x[0]+=1
        x[1]+=1
        cnt+=1
print(cnt)



Measured memory_bytes: 38512
#include <iostream>
#include <iomanip>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>

using namespace std;


typedef long long int lli;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef pair<float, float> ff;
typedef vector<ii> vii; 
typedef vector<ff> vff;


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin>>n;
    vi ab(n);
    for (int i=0;i<n;i++) {cin >> ab[i];}
    lli ans = 0;
    for (int i=0;i<n-1;i++) {
        for(int j=i+1;j<n;j++){
            ans += (ab[i]*ab[j]);
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
#define pb push_back
#define pii pair < int, int >
#define F first
#define S second
#define int  long long int
#define sync ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#pragma GCC optimize ("Ofast")
#pragma GCC optimize ("unroll-loops")
using namespace std;
/// khodaya komak kon

/// ba z_func hatman dafe baad bezan
const int MAX_N = 5e5 + 5;
char a[MAX_N];
int N, pre[MAX_N], nxt[MAX_N];
bool check(int pos) {
	bool f1 = (!pre[pos]) || (pos % (pos - pre[pos]));
	bool f2 = (nxt[pos + 1] == N + 1) || (N - pos) % (N - pos - (N - nxt[pos + 1] + 1));
	if (f1 && f2) return 1;
	else return 0;
}
int32_t main () {
	scanf("%s", a + 1);
	N = strlen(a + 1);
	pre[1] = 0;
	for (int i = 2, j = 0; i <= N; i++) {
		while (j && a[j + 1] != a[i]) j = pre[j];
		if (a[j + 1] == a[i]) ++j;
		pre[i] = j;
	}
	nxt[N] = N + 1;
	for (int i = N - 1, j = N + 1; i; i--) {
		while (j <= N && a[j - 1] != a[i]) j = nxt[j];
		if (a[j - 1] == a[i]) --j;
		nxt[i] = j;
	}
	if (!pre[N] || N % (N - pre[N])) return puts("1\n1") & 0;
	if (pre[N] == N - 1) return printf("%d\n1\n", N) & 0;
	int ans = 0;
	for (int i = 1; i < N; i++) ans += check(i);
	printf("2\n%d\n", ans);
    return 0;
}


Measured memory_bytes: 8576
def calc1(x,y,N): # x != y
    d = len(str(N))
    if d == 1:
        re = 0
    elif d == 2:
        if N >= x*(10**(d-1)) + y:
            re = 1
        else:
            re = 0
    else:
        s_high = str(x) + '9'*(d-2) + str(y)
        s_low = str(x) + '0'*(d-2) + str(y)
        if N >= int(s_high):
            re = int(str('1'*(d - 1)))
        else:
            re = int('1'*(d-2))
            if N >= int(s_low):
                re += (N - int(s_low))//10 + 1
    return re

def calc2(x,y,N): # x == y
    d = len(str(N))
    if d == 1:
        if x <= N:
            re = 1
        else:
            re = 0
    elif d == 2:
        if N >= x*(10**(d-1)) + y:
            re = 2
        else:
            re = 1
    else:
        s_high = str(x) + '9'*(d-2) + str(y)
        s_low = str(x) + '0'*(d-2) + str(y)
        if N >= int(s_high):
            re = int(str('1'*(d - 1))) + 1
        else:
            re = int('1'*(d-2)) + 1
            if N >= int(s_low):
                re += (N - int(s_low))//10 + 1
    return re
N = int(input())
ans = 0
for i in range(1,10):
    for j in range(1,10):
        if i != j:
            ans += calc1(i,j,N)*calc1(j,i,N)
for i in range(1,10):
    ans +=calc2(i,i,N)**2
print(ans)

Measured memory_bytes: 3188
//
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
// #define MOD 1000000007
#define rp(i,n) for(int i=0;i<(n);i++)
#define up(i,s,e,d) for(int i=(s);i<(e);i+=(d))
#define ot(x) cout<<(x)
#define ote(x) cout<<(x)<<endl
#define all(x) (x).begin(),(x).end()

int main(){
	int N;cin>>N;
	map<char,ll> S;
	string T{"MARCH"};
	rp(i,N){
		string s;cin>>s;
		rp(j,T.size()) if(s[0]==T[j]) S[s[0]]++;
	}

	// for(auto e:S)cout<<e.first<<","<<e.second<<",";ote("\n---");///

	if(S.size()<1){
		cout<< 0 <<endl;
		return 0;
	}

	map<string,ll> C;
	// ll ans = 0;
	for(auto a:S){
		for(auto b:S){
			if(a==b)continue;
			for(auto c:S){
				if(a==c || b==c)continue;
				string s{a.first,b.first,c.first};
				sort(all(s));
				// cout<<s<<"\n";///
				decltype(C)::iterator it = C.find(s);
				if(it==C.end()){
					C[s] += a.second * b.second * c.second;
					// cout<<s<<","<<C[s]<<"\n";
				}
			}
		}
	}

	ll ans = 0;
	for(auto e:C){
		// cout<<"("<<e.first<<","<<e.second<<"),";
		ans += e.second;
	}
	// ote("\n--");//
	ote(ans);
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/STACK:256000000")
#define _USE_MATH_DEFINES
#include<iostream>
#include<vector>
#include<string>
#include<stack>
#include<algorithm>
#include<cmath>
#include<set>
#include<queue>
#include<sstream>
#include<utility>
#include<map>
#include<ctime>
#include<cstdio>
#include<cassert>
#include<functional>
#include<unordered_map>
#include<deque>
#include<cmath>





using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef pair<char, char> pcc;
typedef pair<double, double> pdd;

#define show(x) cerr << x
#define debug(x) show(#x << ": " << (x) << endl)

const long double PI = 3.14159265358979323846;
const long double eps = 1e-5;
const ll INF = numeric_limits<int>::max();
const ll LINF = numeric_limits<ll>::max();
const ll mod = 1000 * 1000 * 1000 + 7;


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


void solve() {
    int x;
    cin >> x;
    cout << 360 / gcd(360, x) << endl;



}


//#define LOCAL

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



#ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif	
    return 0;
}


Measured memory_bytes: 3156
#include <iostream>
#include <queue>

using namespace std;

#define NIL -1

struct Node { int parent, left, right, key; };
Node tree[500001];
int treesize;
int root = NIL;

void in(int id)
{
	if (id == NIL) return;
	cout << " " << tree[id].key;
	in(tree[id].left);
	in(tree[id].right);
}

void pre(int id) 
{
	if (id == NIL) return;
	pre(tree[id].left);
	cout << " " << tree[id].key;
	pre(tree[id].right);
}

void insert(int key)
{
	int y = NIL;
	int x = root;
	while (x != NIL)
	{
		y = x;
		if (key < tree[x].key) x = tree[x].left;
		else x = tree[x].right;
	}
	tree[treesize].parent = y;

	if (y == NIL) root = treesize;
	else if (key < tree[y].key) tree[y].left = treesize;
	else tree[y].right = treesize;
	
	tree[treesize].left = NIL; 
	tree[treesize].right = NIL; 
	tree[treesize].key = key;
	
	treesize++;
}


int main(void)
{
	int n;
	string str;

	cin >> n;

	for (int i = 0; i < n; i++) 
	{
		cin >> str;

		if (str == "insert") 
		{
			int key;
			cin >> key;
			insert(key);
		}
		else if(str == "print")
		{
			pre(root);
			cout << endl;
			in(root);
			cout << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 10772
s = input()
if s == 'SUN':
  print(7)
elif s == 'MON':
  print(6)
elif s == 'TUE':
  print(5)
elif s == 'WED':
  print(4)
elif s == 'THU':
  print(3)
elif s == 'FRI':
  print(2)
elif s == 'SAT':
  print(1)  

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double D;
typedef pair<ll,ll> P;
#define M 998244353
#define F first
#define S second
#define PB push_back
#define INF 100000000000000000
void NO(void){
	printf("0\n");
	exit(0);
}
int xr[1505];
bool vis[1505];
vector<int>g[1505];
int dfs(int v){
	vis[v]=true;
	int res=xr[v];
	for(int i=0;i<g[v].size();i++){
		int u=g[v][i];
		if(!vis[u]){
			res^=dfs(u);
		}
	}
	return res;
}
void check(int pn,int p[1505][1505],int po,ll &ans){
	if(pn%2==0){
		for(int i=0;i<po;i++)ans=ans*2LL%M;
		return;
	}
	for(int i=0;i<pn;i++){
		g[i].clear();
		vis[i]=false;
		xr[i]=0;
	}
	for(int i=0;i<pn;i++){
		for(int j=0;j<pn;j++){
			if(p[i][j]==-1){
				g[i].PB(j);
				g[j].PB(i);
			}
			if(p[i][j]==1){
				xr[i]^=1;
				xr[j]^=1;
			}
		}
	}
	ll s=0;
	for(int i=0;i<pn;i++){
		if(!vis[i]){
			int w=dfs(i);
			if(w==1)NO();
			s++;
		}
	}
	for(int i=0;i<po-pn+s;i++)ans=ans*2LL%M;
}
int n,m[1505][1505],p[1505][1505],q[1505][1505],pn,qn,po,qo;
ll ans=1LL;
int main(void){
	cin>>n;
	n--;
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			char x;
			scanf(" %c",&x);
			if(x=='o')m[i][j]=1;
			else if(x=='x')m[i][j]=0;
			else m[i][j]=-1;
		}
	}
	pn=(n+1)/2+1;
	qn=n/2+1;
	for(int i=0;i<pn;i++)for(int j=0;j<pn;j++)p[i][j]=-2;
	for(int i=0;i<qn;i++)for(int j=0;j<qn;j++)q[i][j]=-2;
	for(int i=0;i*2<n;i++){
		for(int j=0;j+i+1<pn;j++){
			int k=i*2+j;
			int x=-1;
			if(m[k][j]!=-1&&x!=-1&&x!=m[k][j])NO();
			else if(m[k][j]!=-1)x=m[k][j];
			if(m[j][k]!=-1&&x!=-1&&x!=m[j][k])NO();
			else if(m[j][k]!=-1)x=m[j][k];
			if(m[n-1-k][n-1-j]!=-1&&x!=-1&&x!=m[n-1-k][n-1-j])NO();
			else if(m[n-1-k][n-1-j]!=-1)x=m[n-1-k][n-1-j];
			if(m[n-1-j][n-1-k]!=-1&&x!=-1&&x!=m[n-1-j][n-1-k])NO();
			else if(m[n-1-j][n-1-k]!=-1)x=m[n-1-j][n-1-k];
			p[i][j+i+1]=x;
			if(x==-1)po++;
		}
	}
	for(int i=0;i<n;i++){
		for(int j=0;j+i+1<qn;j++){
			int k=i*2+1+j;
			int x=-1;
			if(m[k][j]!=-1&&x!=-1&&x!=m[k][j])NO();
			else if(m[k][j]!=-1)x=m[k][j];
			if(m[j][k]!=-1&&x!=-1&&x!=m[j][k])NO();
			else if(m[j][k]!=-1)x=m[j][k];
			if(m[n-1-k][n-1-j]!=-1&&x!=-1&&x!=m[n-1-k][n-1-j])NO();
			else if(m[n-1-k][n-1-j]!=-1)x=m[n-1-k][n-1-j];
			if(m[n-1-j][n-1-k]!=-1&&x!=-1&&x!=m[n-1-j][n-1-k])NO();
			else if(m[n-1-j][n-1-k]!=-1)x=m[n-1-j][n-1-k];
			q[i][j+i+1]=x;
			if(x==-1)qo++;
		}
	}
	check(pn,p,po,ans);
	check(qn,q,qo,ans);
	printf("%lld\n",ans);
}


Measured memory_bytes: 25856
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

#include <bits/stdc++.h>
using namespace std;

const int M=1000010;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int n;
  cin>>n;
  
  vector<int> A(n);
  rep(i,n) cin>>A[i];
  sort(ALL(A));
  
  vector<int> C(M);
  
  rep(i,n){
    if(C[A[i]]!=0){
      C[A[i]]=2;
      continue;
    }
    for(int j=A[i];j<M;j+=A[i]){
      C[j]++;
    }
  }
  
  int cnt=0;
  rep(i,n){
    if(C[A[i]]==1) cnt++;
  }
  
  cout<<cnt<<endl;
  
  return 0;
}

Measured memory_bytes: 8008
#include <iostream>
#include <vector>
#define T 1001
#define M 1000000007
#define E e[x][i]
#define S e[x].size()
using namespace std;
typedef long long ll;
ll func(int);
int N,s,t;
string n[T];
vector<int> e[T];
 
main(){
  cin>>N;
  for(int i=0;i<N;i++) cin>>n[i];
  for(int i=0;i<N-1;i++) cin>>s>>t,e[s-1].push_back(t-1);
  cout<<func(0)%M<<endl;
}

ll func(int x){
  ll res=0,res2=1;
  if(!e[x].size()){
    if(n[x]=="E") return 1;
    if(n[x]=="E?") return 2;
    return 0;
  }
  if(n[x][0]=='E'){
    for(int i=0;i<S;i++) res2*=func(E);
    if(n[x]=="E?") res2++;
    return res2%M;
  }
  if(n[x][0]=='A'){
    for(int i=0;i<S;i++) res+=func(E);
    if(n[x]=="A?") res++;
    return res%M;
  }
  if(n[x][0]=='R'){
    for(int i=0;i<S;i++) res2*=(1+func(E));
    if(n[x]=="R") res2--;
    return res2%M;
  }
}

Measured memory_bytes: 1356
import copy
n,m,q=map(int,input().split())
Q=[]
for i in range(q):
    a,b,c,d=map(int,input().split())
    Q.append([a-1,b-1,c,d])    
B=[]
def dfs(A,l):
    if l==n:
        B.append(A)
    else:
        for i in range(A[-1],m+1):
            nA=copy.copy(A)
            nA.append(i)
            dfs(nA,l+1)
dfs([1],1)

ans=0
for ls in B:
    cnt=0
    for que in Q:
        if ls[que[1]]-ls[que[0]]==que[2]:
            cnt+=que[3]
    ans=max(cnt,ans)
print(ans)

Measured memory_bytes: 19724
/*
 VIVEK UPADHYAY
 MANIT, BHOPAL
 */

#include<iostream>
#include<algorithm>
#include<vector>
#include<cstdlib>
#include<unistd.h>
#include<string>
#include<cstring>
#include<stack>
#include<queue>
#include<utility>
#include<cmath>
#include<set>
#include<unordered_map>
#include<cstdio>
#include<map>
#include<numeric>
using namespace std;


#define F first
#define S second
#define mk(x,y) make_pair(x,y)
#define pb(x) push_back(x)

typedef long long ll;
const int MAXN = 1e3 ;
const int MAX = 1e7;
double pi = 3.1415926535897932384626433832795;
const ll inf=1e10 ;

int main(){
    
    int N ;
    cin >>N ;
    int c = N/1000 ;
    cout<<"AB"<<(char)('C' + c)<<endl;
    return 0;
}


Measured memory_bytes: 256
s = input()[::-1]

mod = 2019
ans = 0
d = 0
L = [0]
memo = [0]
for i in s:
    S =str(i)
    tmp = int(S)*pow(10,d,mod)%mod
    tmp = L[-1] + tmp
    L.append(tmp%mod)
    d +=1

from collections import Counter
L = Counter(L)

for v in L.values():
    ans +=v*(v-1)//2
print(ans)

Measured memory_bytes: 16576
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N,i,j,k,sum;
  cin>>N;
  vector<int> V(N);
  vector<int> C(N);
  for(i=0;i<N;i++)cin>>V[i];
  for(j=0;j<N;j++)cin>>C[j];
  sum = 0;
  for(k=0;k<N;k++){
    if(V[k]>C[k])sum+=(V[k]-C[k]);
  }
  cout<<sum<<endl;
}


Measured memory_bytes: 256
// {{{
#include <iostream>
#include <iomanip>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <complex>
#include <vector>
#include <list>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <string>
#include <algorithm>
#include <numeric>
using namespace std;

#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define FOR(i, a, b) for(ll i = static_cast<ll>(a); i < static_cast<ll>(b); i++)
#define FORR(i, a, b) for(ll i = static_cast<ll>(a); i >= static_cast<ll>(b); i--)
#define REP(i, n) for(ll i = 0ll; i < static_cast<ll>(n); i++)
#define REPR(i, n) for(ll i = static_cast<ll>(n); i >= 0ll; i--)
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> IP;
typedef pair<ll, LP> LLP;

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

constexpr int INF = 100000000;
constexpr ll LINF = 10000000000000000ll;
constexpr int MOD = static_cast<int>(1e9 + 7);
constexpr double EPS = 1e-9;
// }}}

ll N, X;

void init()
{
}

inline ll getLayerNum(int level)
{
    return (1ll << (level+2)) - 3;
}

inline ll getPattyNum(int level)
{
    return (1ll << (level+1)) - 1;
}

inline ll getPattyNumLevel1(ll x)
{
    if(x <= 1) return 0;
    if(x <= 4) return x-1;
    return 3;
}

ll rec(ll x, int level)
{
    if(x == 0) return 0;
    if(x == 1) return (level == 0 ? 1 : 0);
    if(level == 1) return getPattyNumLevel1(x);
    ll nPrevLayers = getLayerNum(level-1);
    if(x <= nPrevLayers + 1){
        return rec(x-1, level-1);
    }
    return getPattyNum(level-1) + 1 + rec(x-nPrevLayers-2, level-1);
}

void solve()
{
    cout << rec(X, N) << endl;
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N >> X;
    solve();
    return 0;
}

// vim:set foldmethod=marker:


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define lb lower_bound
#define ub upper_bound
typedef long long ll;
const int INF = 100000000;
const long INF64 = 1000000000000000ll;
const ll MOD = 1000000007ll;

int main(){
	string s;
	std::cin >> s;
	int ans=0;
	for (int i = 1; i < s.size()/2; i++) {
		if(s.substr(0,i)==s.substr(i,i))ans=i*2;
	}
	std::cout << ans << std::endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <sstream>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstring>

using namespace std;

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

typedef long long ll;

int main(){
    int n;
    cin >> n;
    while(n!=0){
        int bs[10][10]; 
        REP(i,10)REP(j,10)cin >> bs[i][j];
        int flip[10][10]; 
        int ans[10][10]; 
        REP(i,1<<10){
            memset(flip,0,sizeof(flip));
            memset(ans,0,sizeof(ans));
            REP(j,10){
                if((i>>j)&1){
                    ans[0][j]=1;
                    flip[0][j]^=1;
                    if(j-1>=0)flip[0][j-1]^=1;
                    if(j+1<10)flip[0][j+1]^=1;
                    flip[1][j]^=1;
                }
            }
            FOR(y,1,10){
                REP(x,10){
                    if(flip[y-1][x] ^ bs[y-1][x]){
                        ans[y][x]=1;
                        flip[y-1][x]^=1;
                        flip[y][x]^=1;
                        if(x-1>=0)
                            flip[y][x-1]^=1;
                        if(x+1<10)
                            flip[y][x+1]^=1;
                        if(y+1<10)
                            flip[y+1][x]^=1;
                    }
                }
            }

            int flag=1;
            REP(y,10){
                REP(x,10){
                    if(flip[y][x] ^ bs[y][x]){
                        flag=0;
                        y=10;
                        break;
                    }
                }
            }

            if(flag){
                REP(y,10){
                    REP(x,10){
                        cout << ans[y][x]  << (x==9 ? "\n" : " ");
                    }
                }
                break;
            }
        }
        n--;
    }
    return 0;
}

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

#define ll long long
#define MOD 1000000007




int main(){
    double w,h;
    cin>>w>>h;
    double x,y;
    cin>>x>>y;


    double fl = w*h;

    double max = fl/2;

    int j=0;
    if(x==w/2&&y==h/2){
        j++;
    }

    cout<<fixed<<setprecision(5)<<max<<" "<<j<<endl;

}



Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
const int INF = (int)1e9 + 7;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main() {
    const int MAXV = (int)1e3;
    int N, W; cin >> N >> W;
    vector<int> w(N), v(N);
    for (int i = 0; i < N; i++) cin >> w[i] >> v[i];

    vector<vector<int>> dp(N + 1, vector<int>((N + 1) * MAXV + 1, INF));
    dp[0][0] = 0;
    for (int i = 0; i < N; i++) for (int val = 0; val <= N * MAXV; val++) {
        chmin(dp[i + 1][val], dp[i][val]);
        chmin(dp[i + 1][val + v[i]], dp[i][val] + w[i]);
    }
    int ans = 0;
    for (int val = 0; val <= N * MAXV; val++) if (dp[N][val] <= W) {
        chmax(ans, val);
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;
typedef long long ll;
const ll N = 2e5+5, P = 1e9+7;
ll n, c[N], cnt[N], dp[N];

int main(){
    ll i;
    while(scanf("%lld", &n) != EOF){
        memset(dp, 0, sizeof(dp));
        for(i = 1; i <= n; i++){
            scanf("%lld", &c[i]);
            cnt[c[i]] = 0;
        }
        dp[0] = 1, i = 1;
        while(i <= n){
            dp[i] = dp[i-1] + cnt[c[i]];
            cnt[c[i]] += dp[i-1];
            dp[i]%=P, cnt[c[i]]%=P;
            i++;
            while(c[i]==c[i-1]) dp[i]=dp[i-1], i++; // 可能出错
        }
        printf("%lld\n", dp[n]);
    }

    return 0;
}

Measured memory_bytes: 4992
#include <iostream>
#include <algorithm>
#include <string>

using namespace std;

int main() {
    size_t N;
    string s;
    cin >> N >> s;

    char c[]="SW";
    for (int q=0; q<4; ++q) {
        string res;
        res.push_back(c[q%2]);
        res.push_back(c[q/2]);
        for (size_t i=1; i<=N; ++i)
            res.push_back((s[i%N]=='o'? 'S':'W')^res.back()^res[(i+N-1)%N]);

        if (!(res[0] == res[N] && res[1] == res[N+1]))
            continue;

        return !(cout << res.substr(0, N) << endl);
    }

    cout << "-1\n";
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define dunk(a) cout << (a) << endl
using namespace std;
typedef long long ll;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int a, b;
	cin >> a >> b;
	int ans = 0;
	for (int i = a; i <= b; ++i) {
		string T = to_string(i);
		if (T[0] == T[4] && T[1] == T[3]) ans++;
	}

	dunk(ans);

	return 0;
}

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

using namespace std;

const int MAXN=1e5+1;

int x,y,a,b,c,p[MAXN],q[MAXN],r[MAXN],nowr;
long long ans=0;
priority_queue<int,vector<int>,greater<int> > apple;

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0),cout.tie(0);
	cin>>x>>y>>a>>b>>c;
	for(int i=1; i<=a; ++i) cin>>p[i];
	for(int i=1; i<=b; ++i) cin>>q[i];
	for(int i=1; i<=c; ++i) cin>>r[i];
	sort(p+1,p+1+a);
	sort(q+1,q+1+b);
	sort(r+1,r+1+c);
	for(int i=a; i>=a-x+1 && i>=0; --i) apple.push(p[i]);
	for(int i=b; i>=b-y+1 && i>=0; --i) apple.push(q[i]);
	nowr=c;
	while(apple.size()<x+y && nowr>0) apple.push(r[nowr--]);
	while(nowr>0) {
		if(r[nowr]>apple.top()) {
			apple.pop();
			apple.push(r[nowr--]);
		} else break;
	}
	while(!apple.empty()) {
		ans+=apple.top();
		apple.pop();
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 2552
#include<bits/stdc++.h>
using namespace std;
#define itn int
#define rep(i,x,y) for(int i=x;i<y;i++)
#define range(a) a.begin(),a.end()
#define print(A,n) rep(i,0,n){cout<<(i ? " ":"")<<A[i];}cout<<endl;
#define pprint(A,m,n) rep(j,0,m){print(A[j],n);}
const long mod=1e9+7;
const int size=1e5;
const int INF=1e9;
int main(){
	long K,A,B;cin>>K>>A>>B;
	if(A>=K) cout<<1<<endl;
	else if(A>B) cout<<2*((K-B-1)/(A-B))+1<<endl;
	else cout<<-1<<endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main{
  public static void main(String[]args){
    Scanner sc = new Scanner(System.in);
    int K = sc.nextInt();
    int A = sc.nextInt();
    long B = sc.nextLong();
    long ans = 1;
    if(B-A <= 1){
      ans += K;
    }else{
      K -= A-1;
      ans += A-1;
      ans += (K/2)*(B-A);
      if(K%2 == 1){
        ans++;
      }
    }
    System.out.println(ans);
  }
}


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

int main() {
  int N, M, sum;
  cin >> N >> M;
  sum =0;
  vector <int> vec (M);
  
  for (int i =0; i<M; i++){
    cin >> vec.at(i);
    sum += vec.at(i);
  }
  
  if (N>=sum){
  cout << N-sum << endl;
  }
  else {
    cout << -1 << endl;
  }
  
  
}


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

#define dump(...) do{print_vars(cout<<"# "<<#__VA_ARGS__<<'=',__VA_ARGS__);cout<<endl;}while(0)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define all(c) begin(c),end(c)
#define mp make_pair
#define mt make_tuple

using uint=unsigned;
using ll=long long;
using ull=unsigned long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using vd=vector<double>;
using vvd=vector<vd>;
using vs=vector<string>;

template<typename T,typename U>bool chmin(T& a,const U& b){return a>b?(a=b,1):0;}
template<typename T,typename U>bool chmax(T& a,const U& b){return a<b?(a=b,1):0;}

void print_vars(ostream&){}
template<typename Car,typename... Cdr>
void print_vars(ostream& os,const Car& car,const Cdr&... cdr){
	print_vars(os<<car<<(sizeof...(cdr)?",":""),cdr...);
}

template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& p){
	return os<<'('<<p.first<<','<<p.second<<')';
}

template<int I,typename Tuple>
void print_tuple(ostream&,const Tuple&){}
template<int I,typename Car,typename... Cdr,typename Tuple>
void print_tuple(ostream& os,const Tuple& t){
	os<<get<I>(t)<<(sizeof...(Cdr)?",":"");
	print_tuple<I+1,Cdr...>(os,t);
}
template<typename... Args>
ostream& operator<<(ostream& os,const tuple<Args...>& t){
	print_tuple<0,Args...>(os<<'(',t);
	return os<<')';
}

template<typename Ch,typename Tr,typename C>
basic_ostream<Ch,Tr>& operator<<(basic_ostream<Ch,Tr>& os,const C& c){
	os<<'[';
	for(auto i=begin(c);i!=end(c);++i)
		os<<(i==begin(c)?"":" ")<<*i;
	return os<<']';
}

constexpr int INF=1e9;
constexpr int MOD=1e9+7;
constexpr double EPS=1e-9;

int main()
{
	#ifndef _GLIBCXX_DEBUG
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	constexpr char endl='\n';
	#endif

	for(int n,k;cin>>n>>k&&n|k;){
		ll res=0;
		for(int b=k+1;b<=n;b++)
			res+=(n+1)/b*(b-k)+max((n+1)%b-k,0);
		if(k==0) res-=(n-k);  // (0,b)を除外する
		cout<<res<<endl;
	}
}


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

#define rep(i,n) for(long long int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(long long int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(long long int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define pb(q) push_back(q)
#define P pair<int,int>
#define Abs(a,b) max(a,b)-min(a,b)
#define YES(condition) if(condition){cout << "YES" << endl;}else{cout << "NO" << endl;}
#define Yes(condition) if(condition){cout << "Yes" << endl;}else{cout << "No" << endl;}
#define Cout(x) cout<<(x)<<endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) << endl
#define possible(n) cout << ((n) ? "possible" : "impossible"  ) << endl
#define Size(n) (n).size()

typedef long long ll;

using namespace std;

const int INF = 1e9,MOD = 1e9 + 7;
const ll LINF = 1e18;

//long long int kaizyo(long long int hh){
  //  cmp=1;
    //while(hh>1){
      //  cmp=(cmp*hh)%MOD;
        //hh--;
    //}
    //return cmp;
//}

//while(x!=0){
            //sum+=x%10;
           // x/=10;
        //}
        //各桁の和

//pair<int,int> p[100000];
//P r[100000];
//cin >> tmp;
//p[i]=make_pair(tmp,i);
//cout << p[i].second+1 << endl;//ペアの右側つまりiを出力

//s.find(w[i])==string::npos
//findの使い方

//for(int i=0;i<n;i++){
   // b[i]=x%2;
    //x/=2;
  //}二進数

long long int n,cnt=0,ans=0,a[10000000],b,c,cmp,cmpp,m,h,w,x,y,k,t,sum=0,pos;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
string alph("YAKI"),s;
bool fl=true;

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

      cin >> s;
      rep(i,4){
          if(s[i]!=alph[i]){
              Cout("No");
              return 0;
          }
      }
      Cout("Yes");
return 0;
}


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

string s[3];
int main() {
	rep(i, 3) {
		cin >> s[i];
		reverse(s[i].begin(), s[i].end());
	}
	int turn = 0;
	while (!s[turn].empty()) {
		char c = s[turn].back();
		s[turn].pop_back();
		turn = c - 'a';
	}
	printf("%c\n", turn + 'A');
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<stdbool.h>
#include<string.h>
#include<math.h>
#include<ctype.h>

typedef long long ll;

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

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

ll max(ll a, ll b) { return (a > b) ? a : b; }

ll min(ll a, ll b) { return (a < b) ? a : b; }

ll asc(const void* a, const void* b) { return *(ll*)a - *(ll*)b; }

ll dsc(const void* a, const void* b) { return *(ll*)b - *(ll*)a; }

bool flag;

int main() {
	ll n,k,ans=0;
	scanf("%lld%", &n);
	for (int i = 1; i <= sqrt(n); i++) {
		if (!(n % i)) k = i;
	}
	
	printf("%d", (int)log10(n / k) + 1);

	return 0;
}

Measured memory_bytes: 2432
from collections import defaultdict
n = int(input())
A=[int(i)//400 for i in input().split()]
dd = defaultdict(int)
t=0
for i in A:
    if i>=8:
        t+=1
        continue
    else:
        dd[i]+=1
print(max(len(dd), 1),(len(dd)+t))


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

int main(){
	int sum=0,n;
	cin>>n;
	int p[n];
	for(int i=0;i<n;i++){
		cin>>p[i];
		sum+=p[i];
	}
	sort(p,p+n);
	cout<<sum-p[n-1]/2;
	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(x) x.begin(),x.end()
#define REVERSE(x) reverse(x.begin(),x.end())
#define P pair<int,int>
typedef long long LL;
const int INF=1000000007;
using namespace std;
int  main(){
  LL N,M;
  cin>>N>>M;
  LL A[N],B[N];
  vector<pair<LL,LL>>drink(N);
  REP(i,N){
    cin>>drink[i].first;
    cin>>drink[i].second;
  }
  sort(ALL(drink));
  LL sum=0;
  LL pay=0;
  LL cnt=0;
  for(int i=0;sum<M;i++){
    if(sum+drink[i].second>M){
      cnt=i;
      break;
    }
    else{
      sum+=drink[i].second;
      pay+=drink[i].first*drink[i].second;
    }
  }
  pay+=(M-sum)*drink[cnt].first;
  cout<<pay;
}

Measured memory_bytes: 1792
# coding: utf-8

n = input()
a = [input() for _ in xrange(n)]
i = 1
c = 0

while True:
    a[i-1], i = 0, a[i-1]
    c += 1

    if i == 2:
        print c
        exit()

    if a[i-1] == 0:
        print -1
        exit()


Measured memory_bytes: 5764
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
typedef long long ll;
typedef double lf;
typedef pair<ll,ll> ii;
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define RST(i,n) memset(i,n,sizeof i)
#define SZ(a) (int)a.size()
#define ALL(a) a.begin(),a.end()
#define X first
#define Y second
#define mkp make_pair
#define pb push_back
#define eb emplace_back
#define pob pop_back
#ifdef cold66
#define debug(...) do{\
    fprintf(stderr,"%s - %d (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
    _do(__VA_ARGS__);\
}while(0)
template<typename T>void _do(T &&_x){cerr<<_x<<endl;}
template<typename T,typename ...S> void _do(T &&_x,S &&..._t){cerr<<_x<<", ";_do(_t...);}
template<typename _a,typename _b> ostream& operator << (ostream &_s,const pair<_a,_b> &_p){return _s<<"("<<_p.X<<","<<_p.Y<<")";}
template<typename It> ostream& _OUTC(ostream &_s,It _ita,It _itb)
{
    _s<<"{";
    for(It _it=_ita;_it!=_itb;_it++)
    {
        _s<<(_it==_ita?"":",")<<*_it;
    }
    _s<<"}";
    return _s;
}
template<typename _a> ostream &operator << (ostream &_s,vector<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,set<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a,typename _b> ostream &operator << (ostream &_s,map<_a,_b> &_c){return _OUTC(_s,ALL(_c));}
template<typename _t> void pary(_t _a,_t _b){_OUTC(cerr,_a,_b);cerr<<endl;}
#define IOS()
#else
#define debug(...)
#define pary(...)
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0);
#endif // cold66
//}
template<class T> inline bool chkmax(T &a, const T &b) { return b > a ? a = b, true : false; }
template<class T> inline bool chkmin(T &a, const T &b) { return b < a ? a = b, true : false; }
template<class T> using MaxHeap = priority_queue<T>;
template<class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;

const ll MAXn=1e5+5,MAXlg=__lg(MAXn)+2;
const ll MOD=1000000007;
const ll INF=0x3f3f3f3f;

int fa[MAXn],sz[MAXn],d[MAXn];
int fd(int x){
  return fa[x] = (x==fa[x] ?x:fd(fa[x]));
}
void uni(int x,int y){
  x = fd(x);
  y = fd(y);
  if( sz[x]<sz[y] ) swap(x,y);
  sz[x] += sz[y];
  sz[y] = 0;
  fa[y] = x;
}
int main(){
  IOS();
  int n,m;
  cin>>n>>m;
  REP1(i,n) fa[i] = i,sz[i] = 1;
  REP1(i,n){
    int x;
    cin>>x;
    d[x] = i;
  }
  REP(i,m){
    int x,y;
    cin>>x>>y;
    uni(x,y);
  }
  int cnt = 0;
  REP1(i,n)if( fd(i)==fd(d[i]) ) cnt++;
  cout<<cnt<<endl;
}


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

#include<stdio.h>
#include<algorithm>
#include<iostream>
#include<string.h>
#include<string>
#include<math.h>
#include<vector>

using namespace std;

typedef long long ll;
typedef pair<int,int> pa;

#define fst first 
#define snd second

const int maxn=1500005;
const double pi=acos(-1.0);
const ll mod=1000000007;

int n,x[55],y[55];

int fat[55];

int ans,ct;

int fa(int i)
{
	if(fat[i]==i) return i;
	return fat[i]=fa(fat[i]);
}
void unit(int i,int j)
{
	i=fa(i);j=fa(j);
	if(i!=j) --ct,fat[i]=j;
}



int main()
{
	//ios_base::sync_with_stdio(false);
	int i,j,k,l;
	scanf("%d",&n);
	for(i=0;i<n;i++) scanf("%d %d",x+i,y+i);
	ans=n;
	for(i=0;i<n;i++)
	{
		for(j=0;j<n;j++)
		{
			int p=x[i]-x[j],q=y[i]-y[j];
			if(p==0&&q==0) continue;
			for(k=0;k<n;k++) fat[k]=k;
			ct=n;
			for(k=0;k<n;k++) for(l=0;l<n;l++) if(k!=l&&x[k]-x[l]==p&&y[k]-y[l]==q) unit(k,l);
			ans=min(ans,ct);
		}
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 256