akhauriyash/Code-Regression huggingface dataset:
import java.util.*

fun main(args : Array<String>) {
    val (n, m, q) = readLine()!!.split(" ").map { it.toInt() }
    val qq = mutableListOf<Item>()

    repeat(q) {
        val (a, b, c, d) = readLine()!!.split(" ").map { it.toInt() }
        qq.add(Item(a-1, b-1, c, d))
    }

    val dfs = Stack<IntArray>()
    for (i in 1..m) {
        val a = IntArray(n){0}
        a[0] = i
        dfs.push(a)
    }

    var max = 0

    while (dfs.isNotEmpty()) {
        val a = dfs.pop()
        if (a.last() != 0) {
            max = max.coerceAtLeast(qq.map { if (a[it.idx2] - a[it.idx1] == it.diff) it.score else 0 }.sum())
            continue
        }

        val lastIdx = a.indexOfLast { it != 0 }
        for (i in a[lastIdx]..m) {
            val newA = a.copyOf()
            newA[lastIdx+1] = i
            dfs.push(newA)
        }
    }

    println(max)
}

data class Item(val idx1: Int, val idx2: Int, val diff: Int, val score: Int)

Measured memory_bytes: 58268
#include <cstdio>

typedef long long LL;
const int Mod = 1000000007;
const int MN = 3005;

int N, M;
int f[2][MN], g[2][MN], Ans;

int main() {
	scanf("%d%d", &N, &M);
	int o = 0;
	for (int i = 1; i <= N; ++i) f[o][i] = 1;
	g[o][0] = 1;
	for (int i = 1; i <= M; ++i) {
		o ^= 1;
		for (int j = 0; j <= N; ++j) f[o][j] = g[o][j] = 0;
		for (int j = 0; j <= N; ++j) {
			if (j) {
				f[o][j] = (f[o][j] + f[o ^ 1][j - 1]) % Mod;
				g[o][j] = ((LL)g[o][j] + g[o ^ 1][j - 1] + g[o ^ 1][j]) % Mod;
				if (j == 1) g[o][j] = (g[o][j] + f[o ^ 1][j]) % Mod;
				else f[o][j] = (f[o][j] + f[o ^ 1][j]) % Mod;
			}
			if (j < N) {
				g[o][j] = ((LL)g[o][j] + g[o ^ 1][j + 1] + g[o ^ 1][j]) % Mod;
				if (!j) g[o][j] = (g[o][j] + f[o ^ 1][j + 1]) % Mod;
				else f[o][j] = ((LL)f[o][j] + f[o ^ 1][j + 1] + f[o ^ 1][j]) % Mod;
			}
		}
	}
	for (int j = 0; j <= N; ++j) Ans = (Ans + g[o][j]) % Mod;
	printf("%d\n", Ans);
	return 0;
}

Measured memory_bytes: 1776
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

N, K = map(int, input().split())

ans = 0
if K == 0:
    ans = N*N
else:
    for b in range(K+1, N+1):
        ans += (N//b)*(b-K)
        r = N % b
        ans += max(0, r-K+1)
print(ans)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#include <string>
#include <algorithm>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
const  int INF = 1001001001;
using Graph = vector<vector<int>>;


int main(){

    int h1,m1,h2,m2,k;
    cin >> h1 >> m1 >> h2>> m2 >> k;

    int time = (h2*60) + m2 - (h1*60) - m1 - k;

    cout << time << endl;
    
    return 0;
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
//#define ll long long
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
#define rep(i, n) REP(i, 0, n)
#define rep_rev(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
#define all(x) (x).begin(),(x).end()
ll tmp1,tmp2,tmp3;
const ll mod = 1000000007;
const int INF = 1e9;
const ll INFLONG = 1e18;
void swap(ll *x,ll *y){
  ll tmp;
  tmp = *x;
  *x = *y;
  *y = tmp;
}

// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
  long long res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

// a^{-1} mod を計算する
long long modinv(long long a, long long mod) {
  return modpow(a, mod - 2, mod);
}

int main() {
  ll n;
  cin >> n;
  vector<ll> vec(n);
  rep(i,n){
    cin >> vec[i];
  }
  ll sum = 0;
  ll ans = 0;
  ll kai = 1;
  rep(i,n-1){
    kai = (kai * (i+1)) % mod;
    vec[i] = vec[i+1] - vec[i];
  }
  rep(i,n-1){
    sum = (sum + kai * modinv(i+1,mod) % mod) % mod;
    ans = ans + vec[i] * sum % mod;
    ans %= mod;
  }
  cout << ans << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(false);cin.tie(0)
#define pb push_back
#define ff first
#define ss second
#define all(a) a.begin(),a.end()
#define int long long
const int MOD=998244353;
const int N=1e5+5;

int gcd(int n,int m)
{
    if(n==0)
        return m;
    else
        return gcd(m%n,n);
}
int n,s;
int dp[3005][3005];
int a[3005];
int go(int pos,int sum)
{
    if(sum==s)
        return n-pos+2;
    if(sum>s)
        return 0;
    if(pos==n+1)
        return 0;
    int &ans=dp[pos][sum];
    if(ans!=-1)
        return ans;
    ans=0;
    ans+=go(pos+1,sum);
    ans+=go(pos+1,sum+a[pos]);
    ans%=MOD;
    return ans;
}
int32_t main()
{
    IOS;
    cin>>n>>s;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
    }
    memset(dp,-1,sizeof(dp));
    int sum=0;
    for(int i=1;i<=n;i++)
    {

        sum+=go(i,0);
        sum%=MOD;
    }
    cout<<sum<<endl;




    
    
 
 
    
 
 
    
    
}

Measured memory_bytes: 70912
#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>;

long gcd(long x, long y) {
  // assume x > y
  if (x % y == 0)
    return y;
  else
    return gcd(y, x % y);
}

void solve(ll A, ll B, long C, long D) {

  // get LCM of C & D
  if (C < D)
    swap(C, D);
  const ll lcm = C * D / gcd(C, D);

  const ll total = B - A + 1;
  const ll cs = B / C - (A - 1) / C;
  const ll ds = B / D - (A - 1) / D;
  const ll cds = B / lcm - (A - 1) / lcm;
  cout << (total - cs - ds + cds ) << endl;
}

int main(){
  // int 3E4  long 2E9  ll 9E18
  cin.tie(0);
  ios::sync_with_stdio(false);

  ll A, B;
  cin >> A >> B;
  long C, D;
  cin >> C >> D;
  solve(A, B, C, D);
  return 0;
}


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

int main()
{
    string s,t,u;
    cin>>s>>t;
    
    int a,b;
    cin>>a>>b;
    
    cin>>u;
    
    u==s? a-- : b--;
    
    cout<<a<<" "<<b;
    return 0;
} 


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(I,A,B)          for(int I=A; I<B; I++)
#define LL                  long long
#define PII                 pair<int,int>
#define MOD                 1000000007
#define MAX                 1000005
#define READ(A)             freopen(A,"r",stdin)

int main() {
    char S[4];
    bool B=false;
    scanf("%s",S);
    FOR(I,0,3){
        if(S[I]=='7'){
            B=true;
        }
    }
    if(B)printf("Yes\n");
    else printf("No\n");
}


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

using namespace std;
// ascending order
#define vsort(v) sort(v.begin(), v.end())
// descending order
#define vsort_r(v) sort(v.begin(), v.end(), greater<int>())
#define vunique(v) unique(v.begin(), v.end())
#define mp make_pair
#define ts(x) to_string(x)
#define rep(i, a, b) for(int i = (int)a; i < (int)b; i++)
#define repm(i, a, b) for(int i = (int)a; i > (int)b; i--)
#define bit(a) bitset<8>(a)
#define des_priority_queue priority_queue<int, vector<int>, greater<int> >
#define all(v) (v).begin(), (v).end()
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1ll << 60;

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

bool is_prime(int n) {
	for(int i = 2; i * i <= n; i++) {
		if(n % i == 0) return false;
	}
	return n != 1;
}

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

    int Q;
    cin >> Q;
    vector<int> a(100010);
    rep(i, 1, 100011) {
        if(i % 2 == 0) continue;
        if(is_prime(i) and is_prime((i + 1) / 2)) a[i - 1] = 1;
        else a[i - 1] = 0;
    }

    vector<int> s(100011, 0);
    rep(i, 0, 100010) s[i + 1] = s[i] + a[i];

    vector<int> rsl;
    rep(i, 0, Q) {
        int left, right;
        cin >> left >> right;
        rsl.push_back(s[right] - s[left - 1]);
    }

    rep(i, 0, rsl.size()) cout << rsl[i] << endl;

}


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

int n;
int v[3005];
long long dp[3005][3005];

int main(){

    cin>>n;

    for(int i=1;i<=n;i++)
        cin>>v[i];

    for(int i=1;i<=n;i++)
        dp[i][i]=v[i];

    for(int i=n-1;i>=1;i--)
        for(int j=i+1;j<=n;j++)
            dp[i][j]=max(v[i]-dp[i+1][j],v[j]-dp[i][j-1]);

    cout<<dp[1][n];

}


Measured memory_bytes: 70016
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define FORR(i, m, n) for (int i = (m); i >= (n); i--)
#define REP(i, n) FOR(i, 0, (n))
#define REPR(i, n) FORR(i, (n) - 1, 0)
#define REP1(i, n) FOR(i, 1, (n) + 1)
#define ALL(c) (c).begin(), (c).end()
#define sz(v) (int)v.size()
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
const int MOD = 1000000007;
const int INF = 1000000001;
const ll LINF = 1000000001000000001LL;
const char EOL = '\n';
 
void solve();
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(numeric_limits<double>::max_digits10);
    solve();
    return 0;
}
 
void solve() {
    int n, k;
    cin >> n >> k;
    vector<int> h(n);
    REP(i, n) cin >> h[i];
    vector<int> dp(n, 0);
    REP1(i, n - 1) {
        dp[i] = dp[i - 1] + abs(h[i] - h[i - 1]);
        FOR(j, 2, k + 1) if (i - j >= 0) dp[i] = min(dp[i], dp[i - j] + abs(h[i] - h[i - j]));
    }
    cout << dp[n - 1] << EOL;
}


Measured memory_bytes: 1024
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<string> s(N);
  for (int i=0; i<N; i++) cin >> s[i];
  int M;
  cin >> M;
  vector<string> t(M);
  int ans = 0;
  for (int i=0; i<M; i++) cin >> t[i];
  for (int i=0; i<N; i++) {
    int cnt = 0;
    for (int j=0; j<N; j++) {
      if (s[j] == s[i]) cnt++;
    }
    for (int k=0; k<M; k++) {
      if (s[i] == t[k]) cnt--;
    }
    ans = max(cnt,ans);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <string>
#include <map>
#include <set>
#include <queue>

#define ll long long
#define REP(i,n) for(int i = 0; i < (n); ++i)
#define PI 3.141592653589
#define MOD 1000000007

using namespace std;

template<typename T> T gcd(T a, T b){ return (a % b)? gcd(b, a%b) : b; }
template<typename T> T lcm(T a, T b){ return a * b / gcd(a, b); }

ll iterative_pow(ll a, ll x, ll mod){
    ll answer = 1;

    while(x > 0){
        //Step1: xの二進数表記の1桁目に1があるとき　例えばx = 10なら1010なので，2回目と4回目はifの中に入る
        if((x & 1) == 1){
            //Step2: i回目の判定で中に入ったとき，a^(2^i)をかける（ようになっている）
            //x = 10なら1010なので，2回目はa^2を，4回目はa^8をかける
            //1回目はa，2回目はa^2，3回目はa^4，4回目はa^8，5回目はa^16となっている
            answer = answer * a % mod;
        }
        //Step3: ifの中に入らなくても，Step2でa^iをかけられるようにaの値は更新しておく
        a = a * a % mod;
        //Step4: xの値を半分にする（x /= 2と同義）これによってStep1で1桁目だけ見ればよくなる
        x >>= 1;
    }
    return answer;
}

ll comb(ll n, ll r, ll mod){
    
    vector<ll> x(n+5), y(n+5);
    //Step1: 階乗を準備
    x[0] = 1;
    for(int i = 1; i < n + 1; i++){
        x[i] = x[i-1] * i % mod;
    }

    //Step2: n!の逆数を計算
    y[n] = iterative_pow(x[n], mod-2, mod);
    // cerr << y[n] << endl;
    //Step3: 階乗の逆数を，y[n]から遡って計算（ポイント！！）
    for(int i = n; i >= 1; i--){
        y[i-1] = y[i] * i % mod;
    }

    //Step4: nCr = n!/r!(n-r)!だから...
    // cerr << x[n] << endl << y[r] << endl << y[n-r] << endl;
    return (((x[n] * y[r]) % mod) * y[n-r]) % mod;
}

int main(void){
    int s;
    cin >> s;

    int k = 1;
    ll ans = 0;
    while(s-3*k>=0){
        int n = s-3*k;
        //cout << comb(n+k-1, k-1, MOD) << endl;
        ans += comb(n+k-1, k-1, MOD) % MOD;
        k++;
    }
    cout << ans % MOD<< endl;
    return 0;
}

Measured memory_bytes: 3540
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
#include<stdio.h>
using namespace std;

//繰り返し
#define REP(i, m, n) for(int i=(int)m; i<(int)n; ++i)
#define rep(i, n) REP(i, 0, n)
#define RREP(i, m, n) for(int i=(int)m; i>=(int)n; --i)
#define rrep(i, m) RREP(i, m, 0)

//簡略化
typedef long long ll;
typedef pair<int, int> pint;
typedef pair<ll, ll> P;

//定義
const int INF = 1e9+7;
const ll LINF = 1e18;
const ll MOD = 1e9+7;

//最大最小
template<typename T> inline void chmin(T &a, const T &b) {if(a>b) a=b;}
template<typename T> inline void chmax(T &a, const T &b) {if(a<b) a=b;}

//GCD&LCM
ll gcd(ll x, ll y) {
  if(y==0) return x;
  else return gcd(y, x%y);
}

ll lcm(ll x, ll y) {
  return (x*y)/gcd(x, y);
}

//-----------------------

int main() {

  ll l,r, min = 2019, cnt = 0;
  cin >> l >> r;

  if(r-l>=2019) {
    cout << 0 << endl;
    return 0;
  }

  for(ll i=l; i<=r; ++i) {
    for(ll j=i+1; j<=r; ++j) {
      if(min>(i*j)%2019) {
        min = (i*j)%2019;
      }
    }
  }

  cout << min << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <stack>
#include <deque>
#include <cmath>
#include <map>
using ll = long long;
using namespace std;

int main() {
    int d, g;
    cin >> d >> g;
    int p[11], c[11];
    for (int i = 0; i < d; i++) cin >> p[i] >> c[i];
    
    int ans = 1e9;
    for (int mask = 0; mask < (1 << d); mask++) {
        int s = 0, num = 0, rest_max = -1;
        for (int i = 0; i < d; i++) {
            if (mask >> i & 1) {
                s += 100 * (i+1) * p[i] + c[i];
                num += p[i];
            }
            else{
                rest_max = i;
            }
        }
        if (s < g) {
            int s1 = 100 * (rest_max + 1);
            int need = (g - s -1) / s1 + 1;
            if (need >= p[rest_max]) {
                continue;
            }
            num += need;
        }
        ans = min(ans, num);
    }
    cout << ans << endl;
}


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

typedef struct Node{
  int key;
  Node *prev;
  Node *next;
} Node;

class DList{
public:
  DList(){
    // nil = (Node*)malloc(sizeof(Node));
    nil = new Node;
    nil->next = nil;
    nil->prev = nil;
  }
  ~DList(){
    delete nil;
  }
  void insert(int key){
    Node *x = new Node;
    x->key = key;
    x->next = nil->next;
    nil->next->prev = x;
    nil->next = x;
    x->prev = nil;
  }
  Node* listSearch(int key){
    Node *cur = nil->next;
    while(cur != nil && cur->key != key) cur = cur->next;
    return cur;
  }
  void deleteNode(Node *t){
    if(t == nil) return;
    t->prev->next = t->next;
    t->next->prev = t->prev;
    delete t;
  }
  void deleteKey(int x){
    Node *t = listSearch(x);
    deleteNode(t);
  }
  void deleteFirst(){
    deleteNode(nil->next);
  }
  void deleteLast(){
    deleteNode(nil->prev);
  }
  void printList(){
    Node *cur = nil->next;
    int isf = 0;
    while(1){
      if(cur == nil) break;
      if(isf++>0) printf(" ");
      printf("%d", cur->key);
      cur = cur->next;
    }
    printf("\n");
  }

private:
  Node *nil;
};


int main(){
  int key, n;
  // int size = 0;
  char com[20];
  // int np = 0, nd = 0;
  scanf("%d", &n);
  DList dl;
  // init();
  for(int i=0; i<n; i++){
    scanf("%s%d", com, &key);
    if(com[0] == 'i'){
      dl.insert(key);
      // np++;
      // size++;
    }
    else if(com[0] == 'd'){
      if(strlen(com) > 6){
        if(com[6] == 'F') dl.deleteFirst();
        else dl.deleteLast();
      }
      else{
        dl.deleteKey(key);
        // nd++;
      }
      // size--;
    }
  }

  dl.printList();

  return 0;
}



Measured memory_bytes: 34408
#include <iostream>


using namespace std;


int main(){
	int a, b;
	cin >> a >> b;
	if (!(a % 3) || !(b % 3) || !((a + b) % 3)){
		cout << "Possible";
	}
	else{
		cout << "Impossible";
	}

	return 0;
}

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

using namespace std;

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

#define reps(i,f,n) for(int i = int(f); i <= int(n); i++)
#define rep(i,n) reps(i,0,int(n)-1)
#define rrep(i,n) for(int i = n-1; i >= 0; i--)

#define all(x) (x).begin(),(x).end()
#define X first
#define Y second

#define sz size()
#define eb emplace_back
#define pb push_back

int l[200000];

int main(void){
  int n,x;
  int ans = 0;
  cin >> n;
  rep(i,n){
    cin >> l[i+1];
  }

  reps(i,0,n){
    if(l[l[i]] == i)ans++;
  }

  cout << ans/2 << endl;
  return 0;
}


Measured memory_bytes: 768
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int n,cnt,A,B,a[101010],b[201001],t[101010];
bool d[101010];
bool check(int *k)
{
for(int i=1;i<=n;i++)
if(t[i]!=k[i]) return 0;
return 1;
}
void dfs(int x)
{
	if(x>=n+1)
	{
	cnt++;
		if(check(a)) A=cnt;
		if(check(b)) B=cnt;
		return ;
	}
	for(int i=1;i<=n;i++)
	if(!d[i])
	{
		t[x]=i;d[i]=1;
		dfs(x+1);
		d[i]=0;
	}
}
int main()
{
scanf("%d",&n);
	for(int i=1;i<=n;i++)
	scanf("%d",&a[i]);
	for(int i=1;i<=n;i++)
	scanf("%d",&b[i]);
	dfs(1);
	printf("%d\n",abs(A-B));
	return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(int argc, char const *argv[]) {
  int a, b, c, ans = 3;
  cin >> a >> b >> c;
  if (a==b) ans--;
  if (b==c) ans--;
  if (c==a) ans--;
  if (ans==0) ans = 1;
  cout << ans << endl;
  return 0;
}


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

using ll = long long;

int main() {
    int M, D, ans = 0;
    cin >> M >> D;
    for (int i = 1; i <= M; i++) {
        for (int j = 1; j <= D; j++) {
            int d1 = j % 10;
            int d10 = j / 10;
            if (d1 < 2 || d10 < 2) continue;
            if (d1 * d10 == i) ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
	
	int num, a, b, c, ans;
	
	while(1){
		ans = 0;
		if(scanf("%d",&num) == EOF){
			
			break;
			
		}
		for(a = 0; a <= 9; a++){
			for(b = 0; b <= 9; b++){
				for(c = 0; c <= 9; c++){
					if(((num - c - b - a) >= 0) && ((num - c - b - a) <= 9)){
						ans++;
					}
				}
			}
		}
		
		printf("%d\n", ans);
		
	}
	
    return 0;
}

Measured memory_bytes: 596
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdlib>
using namespace std;
int main()
{
	int n,b;
	vector<int> a;
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> b;
		a.push_back(b);
	}
	sort(a.rbegin(), a.rend());
	cout << abs(a[0] - a[n - 1]) << endl;
	return 0;
}

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

#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
typedef long long ll;

const long long INF = 1LL << 60;

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

    map<string, bool> check;
    vector<ll> cnt(5, 0);
    string cmb[10] = {"012", "013", "014", "023", "024", "034", "123", "124", "134", "234"};
    char comp[5] = {'M', 'A', 'R', 'C', 'H'};

    rep(i, N) {
        string S;
        cin >> S;
        bool flag = false;
        int index;
        rep(i, 5) {
            if (S[0] == comp[i]) {
                flag = true;
                index = i;
                break;
            }
        }
        if (flag) {
            if (check.count(S) == 0) {
                check[S] = 1;
                cnt[index]++;
            }
        }
    }

    ll ans = 0;
    rep(i, 10) {
        ans += (cnt[(cmb[i][0] - '0')] * cnt[(cmb[i][1] - '0')] * cnt[(cmb[i][2] - '0')]);
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 11136
use proconio::input;

fn main() {
	input! {
		n: String
	}

	let mut all_num = 0;

	for s in n.as_str().chars() {
		let num: i32 = s as i32 -48;
		all_num += num;
	}
	if all_num % 9 == 0 {
		println!("Yes");
	}
	else {
		println!("No");
	}
}


Measured memory_bytes: 2244
#include "bits/stdc++.h"
using namespace std;
#define fst first
#define scd second
int main()
{
	long long n, a, b;
	scanf("%lld%lld%lld", &n, &a, &b);
	long long cnt, mod;
	cnt = n / (a + b);
	mod = n % (a + b);
	printf("%lld\n", a * cnt + min(a, mod)); 
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
//F6編譯，右上三角形執行，ctrl+c強制停止執行  F5開啟exe
#define ll long long
#define maxn 2000005
#define mod 1000000007
using namespace std;

typedef pair<int, int> P;

ll power(ll a, ll k)
{
    ll res = 1;
    while (k)
    {
        if (k & 1)
            res = res * a % mod;
        a = a * a % mod;
        k /= 2;
    }
    return res;
}
ll inv(ll k) { return power(k, mod - 2); }

ll fac[maxn];

ll cal(ll r, ll c)
{ //C(r+c+2,r+1)
    r++, c++;
    return (fac[r + c] * inv(fac[r] * fac[c] % mod) % mod + mod - 1) % mod;
}

int main()
{
    fac[0] = 1;
    for (int i = 1; i < maxn; i++)
        fac[i] = fac[i - 1] * i % mod;
    ll r1, r2, c1, c2;
    cin >> r1 >> c1 >> r2 >> c2;
    ll ans = cal(r2, c2);
    ans = (ans - cal(r1 - 1, c2) + mod) % mod;
    ans = (ans - cal(r2, c1 - 1) + mod) % mod;
    ans = (ans + cal(r1 - 1, c1 - 1)) % mod;
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 15872
#include <bits/stdc++.h>
using namespace std;
const int N = 2000;
int ab[100000], ac[100000], bc[100000];
bool match(char x, char y){
    return x == '?' || y == '?' || x == y;
}
int main(){
    string a,b,c;
    cin >> a >> b >> c;
    int A = a.length();
    int B = b.length();
    int C = c.length();
    for (int i = 0; i < A; i++) for (int j = 0; j < B; j++) if (!match(a[i],b[j])) ab[i-j+50000] = true;
    for (int i = 0; i < A; i++) for (int j = 0; j < C; j++) if (!match(a[i],c[j])) ac[i-j+50000] = true;
    for (int i = 0; i < B; i++) for (int j = 0; j < C; j++) if (!match(b[i],c[j])) bc[i-j+50000] = true;
    int ans = 3*N;
    for (int i = -2*N; i <= 2*N; i++){
        for (int j = -2*N; j <= 2*N; j++){
            if (!ab[i+50000] && !ac[j+50000] && !bc[j-i+50000]){
                int L = min(0,min(i,j));
                int R = max(A,max(B+i,C+j));
                ans = min(ans,R-L);
            }
        }
    }
    printf("%d",ans);
}


Measured memory_bytes: 256
import java.util.*;
public class Main{
	public static void main(String[] args) { 
		Scanner sc = new Scanner(System.in);
		while(true){
			int n = sc.nextInt();
			int a[][]=new int[n][4];
			int b[][]=new int[n][4];
			if(n==0)break;
			for(int cnt=0;cnt<n;cnt++){
				for(int j=0;j<4;j++)
					a[cnt][j]=sc.nextInt();
				for(int j=0;j<4;j++)
					b[cnt][j]=sc.nextInt();
			} 		


			for(int c=0;c<n;c++){
				int ans=0,ians=0,jans=0,kans=0;
				for(int i=0;i<4;i++){
					for(int j=0;j<4;j++){
						if(i==0&&j==1||i==1&&j==0||i==2&&j==3){
							ians+=a[c][i]*b[c][j];
							//System.out.println(a[c][i]*b[c][j]);
						}else if(i==0&&j==2||i==2&&j==0||i==3&&j==1){
							jans+=a[c][i]*b[c][j];
							//System.out.println(a[c][i]*b[c][j]);
						}else if(i==0&&j==3||i==3&&j==0||i==1&&j==2){
							kans+=a[c][i]*b[c][j];
							//System.out.println(a[c][i]*b[c][j]);
						}else if(i==0&&j==0){
							ans += a[c][i]*b[c][j];//1/1
							//System.out.println(a[c][i]*b[c][j]);
						}else if(i==3&&j==2){
							ians+=-a[c][i]*b[c][j];//-i k/j
							//System.out.println(-a[c][i]*b[c][j]);
						}else if(i==1&&j==3){
							jans+=-a[c][i]*b[c][j];//-j i/k
							//System.out.println(-a[c][i]*b[c][j]);
						}else if(i==2&&j==1){
							kans+=-a[c][i]*b[c][j];//-k j/i
							//System.out.println(-a[c][i]*b[c][j]);
						}else if(i==1&&j==1||i==2&&j==2||i==3&&j==3){
							ans+=-a[c][i]*b[c][j];//-1 ii jj kk
							//System.out.println(-a[c][i]*b[c][j]);
						}
					}									
				}
				System.out.println(ans+" "+ians+" "+jans+" "+kans);
			}
		}
	}
}

Measured memory_bytes: 23804
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  int r;
  int h;
  int e;
  cin >> n >> r;
  if(n<10){
    e = 10-n;
    h = 100*e;
    cout << r+h << endl;
  } else{
    cout << r << endl;
  }
}


Measured memory_bytes: 256
#include <stdio.h>


void stack(int *b, int *a, int m){
    int i, j, flag;
    int new_b[100];

    if(m==1){
        if(b[0] == 1){
            a[0] = 1;
        }else{
            a[0] = -1;
        }
    }else{
        for(i=0;i<m;i++){
            if(b[i] > i+1){
                break;
            }
        }
        if(i != m){
            a[m-1] = -1;
        }else{
            flag = 0;
            for(i=0;i<m;i++){
                if(b[i] == i+1){
                    for(j=i+1;j<m;j++){
                        new_b[j-1] = b[j];
                    }
                    stack(new_b, a, m-1);
                    if(a[m-2] == -1){
                        new_b[i] = b[i];
                        continue;
                    }else{
                        a[m-1] = i+1;
                        flag = 1;
                        break;
                    }
                }else{
                    new_b[i] = b[i];
                }
            }
            if(flag == 0){
                a[m-1] = -1;
            }
        }
    }
}

int main(void)
{
    int n;
    int b[100];

    int i;
    int a[100];

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

    stack(b, a, n);

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

    return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>
#include <cstring>
#include <cmath>
#include <stack>
#include <iomanip>
#include <tuple>
#include <functional>
#include <cfloat>
#include <map>
#include <stdio.h>
#include <string.h>
using ll = long long;

//LLONG_MAX
#define int long long
#define CONTAINS(v,n) (find((v).begin(), (v).end(), (n)) != (v).end())
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ARY_SORT(a, size) sort((a), (a)+(size))
#define MAX(a,b) (((a) > (b)) ? (a) : (b))
#define MIN(a,b) (((a) < (b)) ? (a) : (b))
#define REMOVE(v,a) (v.erase(remove((v).begin(), (v).end(), (a)), (v).end()))
#define REVERSE(v) (reverse((v).begin(), (v).end()))
#define LOWER_BOUND(v,a) (lower_bound((v).begin(), (v).end(), (a)))
#define UPPER_BOUND(v,a) (upper_bound((v).begin(), (v).end(), (a)))
#define REP(i, n) for (int (i)=0; (i) < (n); (i)++)
#define CONTAINS_MAP(m, a) (m).find((a)) != m.end()

using namespace std;


//1<<17 = 2^17 = 131072
#define SEG_MAX (1 << 18)
int seg[SEG_MAX * 2] = { 0 };

//[a,b]にxを加算 (節点kをベースに[l,r]に足す)
void add(int a, int b, int x, int k = 0, int l = 0, int r = SEG_MAX - 1)
{
	if (a <= l && r <= b)
	{
		seg[k] += x;
	}
	else
	{
		int l0 = l;
		int r0 = l + (r - l) / 2;
		int l1 = r0 + 1;
		int r1 = r;
		if (a <= r0)
		{
			int kk = 2 * k + 1;
			add(a, b, x, kk, l0, r0);
		}
		if (l1 <= b)
		{
			int kk = 2 * k + 2;
			add(a, b, x, kk, l1, r1);
		}
	}
}

int get(int index)
{
	int sum = 0;
	int k = SEG_MAX - 1 + index; //根
	while (true)
	{
		sum += seg[k];
		if (k == 0) break;
		k = (k - 1) / 2;
	}
	return sum;
}




int N, D, A;
struct St
{
	int x, h;
	bool operator < (const St& st) const
	{
		return (x < st.x);
	}
};
St st[2000010];

signed main()
{
	cin >> N >> D >> A;
	REP(i, N)
	{
		int x, h;
		cin >> x >> h;
		st[i].x = x;
		st[i].h = h;
	}
	ARY_SORT(st, N);

	//int first = 0;
	//while (true)
	//{
	//	if (first >= N - 1) break;
	//	if (st[0].x + D < st[first + 1].x) break;
	//	first++;
	//}

	int ans = 0;
	int right = 0;
	for (int i = 0; i < N; i++)
	{
		while(true)
		{
			if (right >= N - 1) break;
			if (st[i].x + (D * 2) < st[right + 1].x) break;
			right++;
		}

		int g = get(i);
		if (g < st[i].h)
		{
			int rest = st[i].h - g;
			int cnt = ceil(rest / (double)A);
			int dam = cnt * A;
			add(0, right, dam);
			ans += cnt;
		}

		//cout << i << " : ";
		//REP(i, N)
		//{
		//	cout << get(i) << " ";
		//}
		//cout << endl;
	}
	cout << ans << endl;
}


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

int main(){
	string s;
	while(cin>>s, s!="0"){
		long long sum=0;
		for(int i=0; i<s.size(); i++)
			sum += (long long)(s[i]-'0');
		cout << sum << endl;
	}
}


Measured memory_bytes: 3168
import sys
import math
import bisect

def solve(A, B):
    C = []
    for i in range(3):
        C.append([0]*3)
    for b in B:
        for i in range(3):
            for j in range(3):
                if A[i][j] == b:
                    C[i][j] = 1
    '''
    print('A: ' + str(A))
    print('B: ' + str(B))
    print('C: ' + str(C))
    '''
    for i in range(3):
        if C[i][0] and C[i][1] and C[i][2]:
            return True
        if C[0][i] and C[1][i] and C[2][i]:
            return True
    if C[0][0] and C[1][1] and C[2][2]:
        return True
    if C[2][0] and C[1][1] and C[0][2]:
        return True
    return False

def main():
    A = []
    for i in range(3):
        A.append(list(map(int, input().split())))
    B = []
    for _ in range(int(input())):
        B.append(int(input()))
    if solve(A, B):
        print('Yes')
    else:
        print('No')

if __name__ == "__main__":
    main()


Measured memory_bytes: 3188
(format t "~A~%" (let ((a (read))
                       (b (read)))
                   (if (= a 1)
                       (if (= b 1)
                           "Draw"
                           "Alice")
                       (if (= b 1)
                           "Bob"
                           (cond ((= a b) "Draw")
                                 ((> a b) "Alice")
                                 (t "Bob"))))))

Measured memory_bytes: 9064
# coding: utf-8
# Your code here!
line= list(map(int,input().split()))
N = line[0]
K = line[1]
#0~Nの連続した整数から
#K個以上(N+1)個以下だけ選ぶ
answer = 0
for i in range (K,N+2):
    minit = i*(i-1)/2
    maximum = (2*N-i+1)*i/2
    
    num = maximum-minit+1
    answer += num
 
if answer >=(10**9+7):
    print(int(answer%(10**9+7)))
    
else:
    print(int(answer))

Measured memory_bytes: 9204
#include <iostream>
#include <math.h>

using namespace std;

int main(void){
  int r, d, x, sum;
  int i, j;
  cin >> r >> d >> x;
  sum = x;
  for(i = 1; i <= 10; i++){
    sum = r * sum - d;
    cout << sum << endl;
  }
  return 0;
}

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

using namespace std;

typedef long long ll;
typedef vector <int> vi;
typedef vector <vector <int>> vii;
typedef vector <long long> vll;
typedef vector <string> vs;
typedef vector <char> vc;
typedef set <int> si;
typedef set <string> ss;
typedef queue <int> qi;
typedef queue <long long> qll;
typedef queue <string> qs;
typedef queue <char> qc;
typedef struct board board;
typedef pair <int, int> pi;
typedef pair <long long, long long> pll;
typedef pair <int, pair<int, int>> pii;

#define eb emplace_back
#define ppb pop_back
#define clr(a) a.clear()
#define F first
#define S second
#define mkp make_pair

#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()

#define left(x) x * 2
#define right(x) x * 2 + 1

#define meme(a, b, c) fill(a + 1, a + 1 + b, c)

#define max(a, b) (a > b ? a : b)
#define min(a, b) (a > b ? b : a)
#define abs(a) (a > 0? a : -(a))

#define move(s) s += "#"

#define eprintf(...) fprintf(stderr, __VA_ARGS__);

template <typename T>
void printArr(const T * arr, int s, int fn) {
    for (int i = s; i <= fn; ++ i) cout << arr[i] << " ";
    cout << '\n';
}

template <typename T>
long long minArr(const T * arr, int s, int fn) {
    ll res = 1e16 + 1;
    for (int i = s; i <= fn; ++ i) {
        res = min(res, arr[i]);
    }
    return res;
}

template <typename T>
void printVec(const T * arr) {
    for (int i = 0; i < sz(arr); ++ i) cout << arr[i] << " ";
    cout << '\n';
}

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

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

void to_pray() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cerr << "Ready\n";
}

const int N = 1e5 + 10;
const int NN = 1e3 + 10;
const int NNN = 2e3 + 9;
const int MOD = 1e9 + 7;
const int INF = 1e9 + 7;
const ll LLINF = 1e12 + 7;
const int EPS = 1e-9 - 8;
const int vN = 2e4 + 10;
const int sz = (1 << 22) - 1;
const double PI = acos(-1);

string s;

map <string, ll> mp;

int main () {
    to_pray();

    ll n;
    cin >> n;
    
    for (int i = 1; i <= n; ++ i) {
    	string s;
    	cin >> s;
    	sort(all(s));
    	mp[s]++;
    }
    
    ll res = 0;

    for (auto& to : mp) {
    	ll s = to.second;
    	res += (ll)s * (s - 1) / 2;
    }
    cout << res;
    //eprintf("%.18lf seconds\n", (double)clock() / CLOCKS_PER_SEC);
    cout << '\n';
    return 0;
}


Measured memory_bytes: 11264
// Author : Mohamed Sameh
#include <bits/stdc++.h>
typedef long long ll ;
#define pb push_back
#define f first
#define s second
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define SZ(a) (int)a.size()
#define Flush fflush(stdout);
using namespace std ;
const int N = 16;
const ll MN = -1e9*N;
int n;
int a[N][N];
ll dp[(1<<N)];
ll value[(1<<N)];
int arr[N];
ll solve(int msk = (1<<n)-1)
{
  if (!msk)return 0;
  ll &ret = dp[msk];
  if (~ret)return ret;
  ret = MN;
  for (int cur_msk = msk; cur_msk; cur_msk=(cur_msk-1)&msk)
  {
    ret = max(ret, value[cur_msk] + solve(msk^cur_msk));
  }
  return ret;
}
ll get_cost(int sz)
{
  ll ret = 0;
  for (int i = 0; i < sz; i++)
    for (int j = i+1; j < sz; j++)
      ret += a[arr[i]][arr[j]];
  return ret;
}
int main()
{
  scanf("%d", &n);
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++)
      scanf("%d", a[i]+ j);
  memset(dp, -1, sizeof dp);
  for (int i = 0; i < (1<<n); i++)
  {
    int idx = 0;
    for (int j = 0; j < n; j++)
    {
      if (i & (1<<j))arr[idx++] = j;
    }
    value[i] = get_cost(idx);
  }
  printf("%lld\n", solve());
}


Measured memory_bytes: 4820
n,K = map(int, input().split(' '))

#n,k = 3, 2

res = 0

for k in range(K, n+2):
  first = k * (k-1) / 2
  last = (2 * n - k + 1) * k / 2
  res += (last - first + 1) 
print(int(res%(10**9+7)))

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

int dp[100005],size;



int myfunc(int arr[],int n)
{
	if(n==size-1)
		return 0;
	else if(n>size)
		return INT_MAX;
	
	//cout<<"f";
	if(dp[n]!=-1)
		return dp[n];
	else
		dp[n]=min((myfunc(arr,n+1)+abs(arr[n+1]-arr[n])),(myfunc(arr,n+2)+abs(arr[n+2]-arr[n])));
	
	//printf("\ndp[n]==%d",dp[n]);
	return dp[n];
	return 100;
}

int main()
{
	//scanf("%d",&m);
	int n,i;
	//int arr[]={60,10,20,50,30,40};
	cin>>n;
	int arr[n];
	for(i=0;i<n;i++)
		cin>>arr[i];
	size=n;
	std::fill_n(dp,n,-1);
	
	//for(i=0;i<6;i++)
	//	cout<<dp[i]<<"\n";
	int ans=myfunc(arr,0);
	cout<<ans<<"\n";
	return 0;
}

Measured memory_bytes: 4096
import sys
import numpy as np

# 実行環境(0:vscode, 1:atcoder)
MODE = 1

# 入力の次元
DIMENSION = 2

# int型に変換
INT_TYPE = 1

if not (MODE):
    with open("input.txt", "r") as f:
        s = f.read()
else:
    s = sys.stdin.read()

if DIMENSION == 0:
    if INT_TYPE == 1:
        s = int(s)
elif DIMENSION == 1:
    if INT_TYPE == 0:
        s = s.split()
    elif INT_TYPE == 1:
        s = [int(x) for x in s.split()]
elif DIMENSION == 2:
    if INT_TYPE == 0:
        s = [x.split() for x in s.splitlines()]
    elif INT_TYPE == 1:
        s = [[int(y) for y in x.split()] for x in s.splitlines()]

N = s[0][0]
a = s[1]

cnt = 0
for i in range(0, N, 2):
    if a[i] % 2 == 1:
        cnt += 1
print(cnt)


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

struct Rect {
	int w, d;
};

int main() {
	int n, w, d;
	while (cin >> n >> w >> d) {
		if (w == 0) break;

		vector<Rect> v(1, (Rect){w, d});
		
		int p, s;
		while (n--) {
			cin >> p >> s;
			p--;
			s %= (v[p].w + v[p].d) * 2;

			if (s <= v[p].w) {
				// north
				v.push_back((Rect){min(s, v[p].w-s), v[p].d});
				v.push_back((Rect){max(s, v[p].w-s), v[p].d});				
			} else if (s <= v[p].w + v[p].d) {
				// east
				s -= v[p].w;
				v.push_back((Rect){v[p].w, min(s, v[p].d-s)});
				v.push_back((Rect){v[p].w, max(s, v[p].d-s)});
			} else if (s <= v[p].w * 2 + v[p].d) {
				// south
				s -= v[p].w + v[p].d;
				v.push_back((Rect){min(s, v[p].w-s), v[p].d});
				v.push_back((Rect){max(s, v[p].w-s), v[p].d});
			} else {
				// west
				s -= v[p].w * 2 + v[p].d;
				v.push_back((Rect){v[p].w, min(s, v[p].d-s)});
				v.push_back((Rect){v[p].w, max(s, v[p].d-s)});
			}
			v.erase(v.begin()+p);
		}

		sort(v.begin(), v.end(), [](const Rect& a, const Rect& b){
			return a.w * a.d < b.w * b.d;
		});
		for (int i=0; i<(int)v.size(); ++i) {
			cout << (i == 0 ? "" : " ") << v[i].w * v[i].d;
		}
		cout << endl;
	}
}


Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <array>
#include <set>
#include <cmath>
#include <string>
#include <queue>
#include <list>
#include <stack>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cassert>
#include <iomanip> // std::std::setprecision(X)
#include <limits>  //std::numeric_limits<int>::max(), min()

typedef long long ll;

int main (void) {
  std::string S; std::cin >> S;

  std::vector<int> ans(S.size());
  int rr = 0;
  for(int i=0; i<S.size()-1; i++) {
    if ( S.substr(i,2) == "RL" ) {
      ans[i]   += (int)( rr / 2 ) + 1;
      ans[i+1] += std::ceil((double)rr/2) + 1;
      //std::cout << i << " " << ans[i] << " " << ans[i+1] << std::endl;
      rr = 0;
      i++;
    }
    else if ( S[i] == 'R' ) {
      rr++;
    }
  }

  int ll = 0;
  for(int i=S.size()-1; i>=1; i--) {
    if ( S.substr(i-1,2) == "RL" ) {
      ans[i] += (int)( ll / 2 );
      ans[i-1]   += std::ceil((double)ll/2);
      //std::cout << i << " " << ans[i] << " " << ans[i+1] << std::endl;
      ll = 0;
      i--;
    }
    else if ( S[i] == 'L' ) {
      ll++;
    }
  }

  for(auto&& v : ans) std::cout << v << " ";
  std::cout << std::endl;

  return 0;
}


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

int main() {
	int n; cin >> n;
	vector<int> p(n), q(n);
	for (int i = 0; i < n; i++) {
		cin >> p.at(i);
	}
	for (int i = 0; i < n; i++) {
		cin >> q.at(i);
	}
	int a, b;
	vector<int> v(n);
	for (int i = 0; i < n; i++) {
		v.at(i) = i + 1;
	}
	int cnt = 0;
	do {
		cnt++;
		bool ok = true;
		for (int i = 0; i < n; i++) {
			if (p.at(i) != v.at(i)) ok = false;
		}
		if (ok) a = cnt;
		ok = true;
		for (int i = 0; i < n; i++) {
			if (q.at(i) != v.at(i)) ok = false;
		}
		if (ok) b = cnt;
	} while (next_permutation(v.begin(), v.end()));
	cout << abs(a - b) << endl;
}

Measured memory_bytes: 256
s=int(input())
p=10**9+7
if s<=2:
    print(0)
    exit()
n=s//3
ans=0
def f(n,k,p):
    if k==0:
        return 1
    elif k%2==0:
        return (f(n,k//2,p)**2)%p
    else:
        return (n*f(n,k-1,p))%p

for k in range(1,n+1):
    a=1
    b=1
    for j in range(k-1):
        a=(a*(s-3*k+1+j))%p
        b=(b*(j+1))%p
    ans=(ans+a*f(b,p-2,p))%p

print(ans%p)



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

int prime (int);
int main(){
	//素数判定プログラム
	int N,a[10000];
	int i,count=0;

	scanf("%d",&N);

	for(i=0;i<N;i++){
		scanf("%d",&a[i]);
	}	

	for(i=0;i<N;i++){
		if(prime(a[i]) == 0) count++;
	}

	printf("%d\n",count);	
	return 0;
}

int prime (int a)
{
	int j,b;
	int Ans,count;

	Ans=0;
	b=0;

	if(a == 2){
		b = 0;
		return b;
	}
	else if (a%2 == 0){
		b = 1;
			return b;
		}
	else{
		for(j=3;j<=sqrt(a);j+=2)
		{
			if(a%j == 0){
				b=1;
				break;
			}
		}
	}
	return b;
}

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

int main(int argc, char **argv)
{
  ll n;
  cin>>n;
  ll count=0;
  ll flag=0;
  for(ll i=0;i<n;i++){
    ll x;
    ll y;
    cin>>x>>y;
    if (x==y) count++;
    else count=0;
    
    if (count==3){
      flag=1;
      break;
    }
  }
  if (flag) cout<<"Yes\n";
  else cout<<"No\n";
	return 0;
}


Measured memory_bytes: 3632
def main():
    N, M, Q = list(map(int, input().split()))
    ABCD = []
    for _ in range(Q):
        a, b, c, d = map(int, input().split())
        ABCD.append((a - 1, b - 1, c, d))
    ABCD.sort()
    A = [-1] * N

    def helper(n, m):
        if n == N:
            return sum(d for a, b, c, d in ABCD if A[b] - A[a] == c)
        t = 0
        for i in range(m, M + 1):
            A[n] = i
            t = max(t, helper(n + 1, i))
        return t

    return helper(0, 1)
        

print(main())


Measured memory_bytes: 9196
#include<bits/stdc++.h>
#define IO ios::sync_with_stdio(false), cin.tie(0)
#define INF 0x3f3f3f3f
typedef long long ll;
using namespace std;

int main()
{
	IO;
	set<string>s;
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		string ss;
		cin>>ss;
		s.insert(ss);
	}
	cout<<s.size()<<endl;
	return 0;
}







Measured memory_bytes: 19248
#include<iostream>
#include<string>
#include<iomanip>
using namespace std;

int main(){
	int a,b;
	cin>>a>>b;
	double x=a;
	double y=b;
	cout<<a/b<<" ";
	cout<<a%b<<" ";
	printf("%.111lf\n",x/y);
}



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

int main(){
  ll N,M;
  cin>>N>>M;
  vector<ll> S(N);
  for(int i=0;i<N;i++){
    cin>>S[i];
    S[i]%=M;
    if(i)
      S[i]=(S[i]+S[i-1])%M;
  }
  sort(S.begin(),S.end());
  ll ima=0,cnt=1,ans=0;
  for(int i=0;i<N;i++){
    if(S[i]==ima)
      cnt++;
    if(S[i]!=ima){
      ans+=cnt*(cnt-1)/2;
      ima=S[i];
      cnt=1;
    }else if(i==N-1)
      ans+=cnt*(cnt-1)/2;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 1024
from fractions import gcd

t = int(input())
a = []
d = 0
for i in range(t):
  a.append(list(map(int,input().split())))
for j in a:
  if j[0] < j[1] or j[1] > j[3]:
    print("No")
  else:
    b = j[0] % j[1]
    k = gcd(j[1],j[3])
    c = j[0] % k
    d = j[2] % k
    if c > d:
      e = j[2] + c - d
    else:
      e = j[2] + k + c - d

    if j[1] > e:
      print("No")
    else:
      print("Yes")
    
    
    


Measured memory_bytes: 5088
#include <bits/stdc++.h>
//----***やべーやつら***----
using namespace std;
#define int long long

//----***型定義***----
using ll = long long;
using P = pair<int,int>;

//----***Like a Pythonista***----
#define REP(ii,jj,nn) for (ll ii=jj;ii<(nn);ii++)
#define RREP(ii,nn,jj) for (ll ii = nn; jj<ii;ii--)
#define each(i,...) for (auto&& i:__VA_ARGS__)
#define ALL(vec) (vec).begin(),(vec).end()
#define sum(...) accumulate(ALL(__VA_ARGS__),0LL)
#define dsum(...) accumulate(ALL(__VA_ARGS__),0.0)
#define vec(type,name,...) vector<type> name(__VA_ARGS__)
template<class T> inline auto max(const T& a){ return *max_element(ALL(a)); }
template<class T> inline auto min(const T& a){ return *min_element(ALL(a)); }
inline ll gcd(ll a,ll b){if(b == 0) return a;return  gcd(b,a%b);}
inline ll lcm(ll a,ll b){ll g = gcd(a,b);return a / g * b;}

//----***定数***----
#define MOD 1000000007
#define INF 100000000000000000
#define EPS 1e-9
#define PI  acos(-1)
const vector<vector<int>> DXY={{-1,0},{1,0},{0,-1},{0,1}};

//----***パーツ***----
#define fi first
#define se second
#define pb push_back
#define re return
#define br break

//----***入出力***---
void print() { std::cout << "\n"; }
template <class T>void print(const T &x) {std::cout << x<<"\n";}
template <class T, class... Args>void print(const T &x, const Args &... args) {std::cout << x << " ";print(args...);}
#define debug(var)  do{std::cerr << #var << " ↓ "<<"\n";view(var);}while(0);
#define dbg cerr<<"🥺🥺🥺🥺🥺🥺"<<endl;
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }

//----***初期時読み込み***----
struct initial{initial(){cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(15);};}initial_;


signed main(){
  int X;cin>>X;
  int ans=1,tmp;
  REP(i,2,X){
    REP(j,2,X){
      tmp=pow(i,j);
      if(tmp>X)br;
      ans=max(ans,tmp);
    }
  }
  print(ans);

}


Measured memory_bytes: 256
h,w=map(int,input().split())
ans=50000
for a,b in [(w,h),(h,w)]:
    for i in range(b):
        for c,d in [(a,b-i), (b-i,a)]:
            l=[i*a,c*(d//2),c*(d-d//2)]
            ans=min(ans,max(l)-min(l))
print(ans)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ll, P> P3;
typedef pair<P ,P> PP;
constexpr ll MOD = ll(1e9) + 7;
constexpr int IINF = INT_MAX;

int h, w;
vector<string> s;

// k列目とk+1列目の間の最小消去コスト
int solve(int k){
    vector<vector<int> > pos(26), cost(h+1, vector<int>(h+1,0)), dp(h+1, vector<int>(h+1,IINF/2));
    for(int i=0;i<h;i++){
        pos[s[i][k]-'a'].push_back(i);
    }
    // imos
    for(int j=0;j<h;j++){
        for(auto &i : pos[s[j][k+1]-'a']){
            int d = j-i;
            if(d >= 0){
                cost[d][0]++;
                cost[h-j+d][h-j]--;
            }
            else{
                d = abs(d);
                cost[0][d]++;
                cost[h-i][h-i+d]--;
            }
        }
    }
    for(int i=0;i<h;i++){
        for(int j=0;j<h;j++){
            cost[i+1][j+1] += cost[i][j];
        }
    }
    dp[0][0] = 0;
    for(int i=0;i<h;i++){
        dp[i+1][0] = dp[i][0] + cost[i][0];
        dp[0][i+1] = dp[0][i] + cost[0][i];
    }
    for(int i=0;i<h;i++){
        for(int j=0;j<h;j++){
            dp[i+1][j+1] = min(dp[i+1][j]+cost[i+1][j], dp[i][j+1]+cost[i][j+1]);
        }
    }
    return dp[h][h];
}

int main() {
    cin >> h >> w;
    s.resize(h);
    for(int i=0;i<h;i++){
        cin >> s[i];
    }
    int ans = 0;
    for(int i=0;i<w-1;i++){
        ans += solve(i);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1200
def main():
    n = int(input())
    a = list(map(int, input().split()))
    x, y = a[0], a[1]
    nim = 0
    for i in range(2, n):
        nim ^= a[i]
    ans = 0

    while((x ^ y) != nim):
        for i in range(50, -1, -1):
            j = (nim >> i) & 1
            xy = ((x >> i) ^ (y >> i)) & 1
            if j != xy:
                m = min(x % (2**i)+1, 2**i-(y % (2**i)))
                if x % (2**i)+1 == 2**i-(y % (2**i)):
                    print(-1)
                    return
                x -= m
                y += m
                ans += m
                if x <= 0:
                    print(-1)
                    return
                break
        else:
            if (x ^ y) != nim:
                print(-1)
                return
    print(ans)


main()


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

#define pi 3.141592654
#define fix(n) cout << fixed << setprecision(n)

#define rep(i,a,b) for(int i=a;i<b;i++)
#define ren(i,a,b) for(int i=a;i>=b;i--)

#define ll  long long
#define ull unsigned long long

#define mp make_pair
#define pb push_back
#define fi first
#define se second

#define vi      vector<int>
#define pii     pair<int,int>
#define piii    pair<pair<int,int>,int>
#define all(v)  v.begin(), v.end()

int mod = 1000000007;
const int N = 500005;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	int a, b;
	cin >> a >> b;
	if ( a + b == 15)
	{
		cout << '+';
		return 0;
	}
	if ( a*b == 15)
	{
		cout << "*";
		return 0;
	}
	cout << "x";
	return 0;
}


Measured memory_bytes: 256