akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <iostream>
//#include <algorithm>
// #include <iomanip>
#define ll long long

using namespace std;

const int MOD = 1000000007;

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

  int ans = 0;
  int half = str.length() / 2;
  for (int i = 0; i < half; i++) {
    int l = i;
    int r = str.length() - i - 1;

    // cout << "str[l]:" << str[l] << endl;
    // cout << "str[r]:" << str[r] << endl;

    if (str[l] != str[r]) {
      ans++;
    }
  }

  cout << ans << endl;
}


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

using namespace std;
using lint = long long;

int main(void)
{
    lint a = 100;
    lint x;
    cin >> x;
    int i;
    for(i = 0; a < x ;i++){
        a = a * 1.01;
    }

    cout << i << endl;
    return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <vector>

#define rep(i,x) for(int i=0;i<x;i++)
using ll = long long;
using namespace std;
int INF = 1001001001;

int main(){
    int n; cin >> n;
    vector<int> h(n);
    rep(i, n) cin >> h[i];
    h.push_back(INF);
    h.push_back(INF);
    vector<int> dp(n + 10, INF);    //余裕をもって要素数+10
    dp[0] = 0;
    rep(i, n){
        int nh1 = i + 1;
        int nh2 = i + 2;
        dp[nh1] = min(dp[nh1], dp[i] + abs(h[nh1] - h[i]));
        dp[nh2] = min(dp[nh2], dp[i] + abs(h[nh2] - h[i]));
    }
    cout << dp[n - 1] << endl;
}


Measured memory_bytes: 1024
n, m, c = map(int, input().split())
B = list(map(int, input().split()))
count = 0
for i in range(n):
    tmp = 0
    A = list(map(int, input().split()))
    for j in range(m):
        tmp += A[j]*B[j]
    if(tmp + c > 0):
        count += 1
print(count)


Measured memory_bytes: 3060
N = int(input())
G = [list(map(int, input().split())) for i in range(N)]


for k in range(N):
    for i in range(N):
        for j in range(N):
            if G[i][k] + G[k][j] < G[i][j]:
                print(-1)
                exit()

Need = [[True] * N for i in range(N)]
for k in range(N):
    for i in range(N):
        for j in range(N):
            if (i == k) or (j == k):
                continue
            if G[i][k] + G[k][j] == G[i][j]:
                Need[i][j] = False

ans = 0
for i in range(N):
    for j in range(N):
        if Need[i][j]:
            ans += G[i][j]

print(ans // 2)


Measured memory_bytes: 45148
import collections

def bfs(N):
    S = "abcdefghij"
    result = []
    deq = collections.deque(["a"])

    while deq:
        s = deq.popleft()
        if len(s) == N:
            result.append(s)
            continue
        else:
            for i in S[:len(set(s))+1]:
                deq.append(s + i)
    return result

N = int(input())
ans = bfs(N)
print('\n'.join(ans))

Measured memory_bytes: 16340
#include<bits/stdc++.h>
using namespace std;
#define INF 1e9
int main(){
  int n;
  while(cin>>n,n){
    int p[44],t[44];
    p[0]=t[0]=0;
    for(int i=1;i<=n;i++)cin>>p[i]>>t[i];
    int dp[44][4];
    for(int i=0;i<44;i++)
      for(int j=0;j<4;j++)
	dp[i][j]=INF;
    dp[0][0]=0;
    int ff=0;
    for(int i=1;i<=n;i++){
      int f=0;
      for(int j=0;j<4;j++){
	if(t[i-1]+p[i-1]*(j+1)+p[i]<=t[i]&&dp[i-1][j]!=INF){
	  dp[i][1]=min(dp[i][1],dp[i-1][j]+p[i-1]+p[i]);
	  f=1;
	}
	if(j==0)continue;
	if(t[i-1]+abs(p[i]-p[i-1])*(j)<=t[i]&&dp[i-1][j-1]!=INF){
	  dp[i][j]=min(dp[i][j],dp[i-1][j-1]+abs(p[i]-p[i-1]));
	  f=1;
	}
      }
      
      if(!f){
	cout<<"NG "<<i<<endl;
	ff++;
	break;
      }
    }
    if(ff)continue;
    int ans=INF;
    for(int i=0;i<4;i++)ans=min(ans,dp[n][i]);
    cout<<"OK "<<ans+p[n]<<endl;
  }
  return 0;
}




Measured memory_bytes: 3056
#include <iostream>
#include <stdio.h>
using namespace std;

int main(){
	int n;
	cin >> n;
	for(int i = 1; i <= n; i++){
		if(i%3){
			int cnt = 0;
			for(int j = i; j > 0; j /= 10){
				if(j%10 == 3) cnt++;
			}
			if(cnt > 0) cout << " " << i;
		}else{
			cout << " " << i;
		}
	}
	cout << endl;
	return 0;
}


Measured memory_bytes: 3116
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

int main() {
	int n, x, y; cin >> n >> x >> y;
	--x, --y;
	vector<int> ans(n - 1);
	for (int j = 0; j < n; ++j)
		for (int k = j + 1; k < n; ++k)
			++ans[min(k - j, abs(k - y) + abs(j - x) + 1) - 1];
	for (auto a : ans) cout << a << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <functional>
#include <cstdio>
#include <climits>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

template<typename T>
class custom_priority_queue : public priority_queue<T, vector<T> >
{
public:
    bool remove(const T& value) {
        auto it = find(this->c.begin(), this->c.end(), value);
        if (it != this->c.end()) {
            this->c.erase(it);
            make_heap(this->c.begin(), this->c.end(), this->comp);
            return true;
        } else {
            return false;
        }
    }
};

int main() {
    int N;
    ll C;
    cin >> N >> C;
    vector<ll> x(N), v(N), S(N);
    for (int i = 0; i < N; i++) {
        cin >> x[i] >> v[i];
    }

    S[0] = v[0];
    for (int i = 1; i < N; i++) {
        S[i] = S[i - 1] + v[i];
        // cout << i << "=" << S[i] << endl; 
    }

    ll ans = 0;

    vector<ll> m1(N), m2(N);
    m1[N - 1] = v[N - 1] - (C - x[N - 1]);
    m2[N - 1] = v[N - 1] - 2 * (C - x[N - 1]);

    for (int i = N - 2; i >= 1; i--) {
        m1[i] = max(m1[i + 1], S[N - 1] - S[i - 1] - (C - x[i]));
        m2[i] = max(m2[i + 1], S[N - 1] - S[i - 1] - 2 * (C - x[i]));
    }
    for (int i = 1; i <= N - 1; i++) {
        ans = max(ans, S[i - 1] - 2 * x[i - 1] + m1[i]);
        ans = max(ans, S[i - 1] - x[i - 1] + m2[i]);
    }

    for (int i = 0; i < N; i++) {
        ans = max(ans, S[i] - x[i]);
        if (i < N - 1) {
            ans = max(ans, S[N - 1] - S[N - 2 - i] - (C - x[N - 1 - i]));
        } else {
            ans = max(ans, S[N - 1] - (C - x[0]));
        }
    }

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


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

#define pb            push_back
#define mp            make_pair
#define ins           insert
#define endl          '\n'
#define all(x)        x.begin(),x.end()
#define debug(X)      { cerr<<endl<<(#X)<<" = "<<(X)<<endl; }
//#define cerr if(0)cerr

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;

int main() {
    ios_base::sync_with_stdio(0);cin.tie(0);
    ll n,h,k,atk=0;
    priority_queue<ll> m;

    cin>>n>>k;
    while (n--) {
        cin>>h;
        m.push(h);
    }

    if (k<m.size()) {
    while (k--) m.pop();

    while (!m.empty()) {
        atk+=m.top();
        m.pop();
    }
    }

    cout<<atk<<endl;

}



Measured memory_bytes: 2420
import collections as cl

n = int(input())
v_lst = list(map(int, input().split()))

odd_lst = [v_lst[i] for i in range(0, len(v_lst), 2)]
even_lst = [v_lst[i] for i in range(1, len(v_lst), 2)]

odd_value_dic = cl.Counter(odd_lst)
even_value_dic = cl.Counter(even_lst)

odd_value_tup_lst = sorted(odd_value_dic.items(), key=lambda x: x[1], reverse=True)
even_value_tup_lst = sorted(even_value_dic.items(), key=lambda x: x[1], reverse=True)


odds_first = odd_value_tup_lst[0][1]
evens_first = even_value_tup_lst[0][1]
ans = n - odds_first - evens_first
"""
print(odd_value_tup_lst)
print(even_value_tup_lst)
print()
"""

if odd_value_tup_lst[0][0] == even_value_tup_lst[0][0]:
    if len(odd_value_tup_lst) == len(even_value_tup_lst) == 1:
        ans = odd_value_tup_lst[0][1]
    elif len(odd_value_tup_lst) == 1:
        evens_first = even_value_tup_lst[1][1]
        ans = n - evens_first
    elif len(even_value_tup_lst) == 1:
        odds_first = odd_value_tup_lst[1][1]
        ans = n - odds_first
    elif odds_first - odd_value_tup_lst[1][1] > evens_first - even_value_tup_lst[1][1]:
        evens_first = even_value_tup_lst[1][1]
        ans = n - odds_first - evens_first
    else:
        odds_first = odd_value_tup_lst[1][1]
        ans = n - odds_first - evens_first

print(ans)


Measured memory_bytes: 21952
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

public class Main { // Template for CF
    public static class ListComparator implements Comparator<List<Integer>> {

        @Override
        public int compare(List<Integer> l1, List<Integer> l2) {
            for (int i = 0; i < l1.size(); ++i) {
                if (l1.get(i).compareTo(l2.get(i)) != 0) {
                    return l1.get(i).compareTo(l2.get(i));
                }
            }
            return 0;
        }
    }

    public static void main(String[] args) throws IOException {
        BufferedReader f = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(System.out);
        String str = f.readLine();
        int k = Integer.parseInt(f.readLine());
        // System.out.println(k);
        Set<String> set = new HashSet<>();
        for (int i = 0; i < str.length(); i++) {
            for (int j = 0; j < str.length(); j++) {
                if ((i + j) < str.length()) {
                    String a = "";
                    if (i + j == str.length() - 1) {
                        a = str.substring(i);
                    } else {
                        a = str.substring(i, i + j + 1);
                    }
                    set.add(a);
                    if (a.length() == k) {
                        break;
                    }
                }
            }
        }
        List<String> sorted = new ArrayList<>();
        sorted.addAll(set);
        Collections.sort(sorted);
        // System.out.println(sorted);
        out.println(sorted.get(k - 1));
        out.close();

    }

}


Measured memory_bytes: 25360
#include<stdio.h>
#include<stdlib.h>
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define fast_io cin.tie(0);cout.tie(0);ios::sync_with_stdio(0)
#define MOD 1000000007
using namespace std;

int main(){
	fast_io;
	ll n;
	cin>>n;
	vector<ll> v;
	while(n--){
        ll x;
        cin>>x;
        v.pb(x);
	}
	ll cnt = 0;
	for(int i=1;i<v.size()-1;i++){
        if(v[i]>v[i+1] && v[i]<v[i-1]){
            cnt++;
        }
        else if(v[i]>v[i-1] && v[i]<v[i+1]){
            cnt++;
        }
	}
	cout<<cnt;
}


Measured memory_bytes: 256
D = int(input())
C = [int(T) for T in input().split()]
S = [[] for TD in range(0,D)]
for TD in range(0,D):
    S[TD] = [int(T) for T in input().split()]
for TD in range(0,D):
    print(S[TD].index(max(S[TD]))+1)

Measured memory_bytes: 9500
#!/usr/bin/env python3
import sys, math


def solve(N: int):
    M = N / 1.08
    K = (N+1) / 1.08
    for i in range(N+1):
        if M <= i < K:
            print(i)
            return
    print(":(")
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    solve(N)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#include <random>
#include <ctime>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//#pragma GCC optimize("-O3")
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("avx2")
#define ll long long
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define pll pair<ll,ll>
#define ld double
#define pld pair<ld,ld>
#define pii pair<int,int>
#define sqr(a) ((a)*(a))
#define all(v) v.begin(),v.end()

using namespace std;
//using namespace __gnu_pbds;

ll MOD = 998244353;
const ll INF = 1e18;
const ld E = 1e-18;
const ld PI=acos(-1);
mt19937_64 rnd(time(0));
ll p1 = 31, p2 = 37, p3 = 7, p4 = rnd() % 100 + 1, md1 = MOD, md2 = 998244353, md3 = 998244357, md4 = rnd() % 1000000000;

//using ord_set=tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;

ll n, m, T, a[1000001];

ll binpow(ll h, ll r, ll md = MOD)
{
    ll l = 1;
    while (r)
    {
        if (r & 1) l *= h, l%=md;
        h *= h;
        h %= md;
        r /= 2;
    }
    return l;
}

ll gcd(ll x, ll y)
{
    if (x < y) swap(x, y);
    while (x && y)
    {
        x %= y;
        swap(x, y);
    }
    return x + y;
}

ll check(int h)
{
    ll j=0;
    while (h)
    {
        ll x=h, kl=0;
        while (x)
        {
            kl+=x&1;
            x/=2;
        }
        h%=kl;
        j++;
    }
    return j;
}


void solve()
{
    cin >> n;
    ll ans=0;
    vector<pll> v1, v2;
    for (int i = 1; i <= n; i++)
    {
        ll k, l, r;
        cin >> k >> l >> r;
        ans+=r;
        if (l-r>0)
            v1.pb(mp(l-r, k)); else v2.pb(mp(l-r, k));
    }
    sort(all(v1));
    reverse(all(v1));
    sort(all(v2));
    ll kl=0;
    set<int> s;
    for (int i = 1; i <= n; i++) s.insert(i);
    for (int i = 0; i < v1.size(); i++)
    {
        ll o=v1[i].se;
        if ((*s.begin())<=o)
        {
            auto u=s.upper_bound(o);
            u--;
            s.erase(u);
            ans+=v1[i].fi;
        }else
        {
            auto u=s.end();
            u--;
            s.erase(u);
        }
    }
    s.clear();
    for (int i = n; i > v1.size(); i--) s.insert(i);
    for (int i = 0; i < v2.size(); i++)
    {
        ll o=v2[i].se;
        auto u=s.upper_bound(o);
        if (u==s.end())
        {
            s.erase(s.begin());
            ans+=v2[i].fi;
        }else
        {
            s.erase(u);
        }
    }
    cout << ans << "\n";
}

int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    //freopen("capitals.in","r",stdin);
    //freopen("capitals.out","w",stdout);
    ios::sync_with_stdio(0);
    cin.tie(0);
    ll t=1;
    cin >> t;
    while (t--)
    {
        solve();
    }
    return 0;
}

/*
3
4 2
1 1
1 0
3 2
2 2

3 1
1 1
1 0
3 2

3 2
1 1
1 0
3 2
*/


Measured memory_bytes: 15692
import collections
N = int(input())
num = []
for _ in range(N):
	num.append(input())
count_dict = collections.Counter(num)
d =[]
for k,v in count_dict.items():
  d.append([k,v])

ans = 0
for i in range(len(d)):
	if d[i][1]%2 == 1:
		ans += 1

print(ans)

Measured memory_bytes: 27256
#include <iostream>
#include <cstring>
#include<vector>
#include <algorithm>
#include<cstdlib>
#include<set>
#include<math.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define rep(i,n) for(ll i=0;i<n;i++)

int main()
{
	ull n, a, b;
	cin >> n >> a >> b;
	ull c;
	c = a + b;
	ull x, y,z;
	x = (n - n % c) / c;
	y = n - x * c;
	if(y<=a)
	{
		z = y;
	}
	else
	{
		z = a;
	}

	ull ans;
	ans = a * x + z;
	cout << ans << "\n";


	return 0;
}

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

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> p(n);
  vector<ll> c(n);
  for (auto& e : p) {
    cin >> e;
    e--;
  }
  for (auto& e : c) cin >> e;

  vector<ll> s1(n), s2(n), d1(n), d2(n);
  for (int i = 0; i < n; i++) {
    if (d1[i]) continue;
    d1[i] = 1;
    for (int j = i; !d2[p[j]]; j = p[j]) {
      if (!d1[p[j]]) {
        s1[p[j]] = s1[j] + c[p[j]];
        d1[p[j]] = d1[j] + 1;
      } else {
        s2[p[j]] = (d2[j] ? s2[j] : s1[j]) + c[p[j]];
        d2[p[j]] = (d2[j] ? d2[j] : d1[j]) + 1;
      }
    }
  }

  ll r = -1e18;
  for (int i = 0; i < n; i++) {
    ll ri = 0;
    for (int j = i, ki = k; ki;) {
      if (d2[j] && 2 * (d2[j] - d1[j]) <= ki) {
        ll t = ki / (d2[j] - d1[j]) - 1;
        ri += t * (s2[j] - s1[j]);
        ki -= t * (d2[j] - d1[j]);
      } else {
        ri += c[p[j]];
        ki--;
        j = p[j];
      }
      r = max(r, ri);
      ri = max(ri, 0ll);
    }
  }
  cout << r << endl;
}


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

using namespace std;

using ll = long long;

const int mod = 1e9 + 7;

ll n, k;
// vector<vector<int>> arr;

// ll solve(int u, ll k){
//     if(k == 0) return 1;
//     ll res = 0;
//     for(int i = 0; i < n; i++){
//         if(arr[u][i]){
//             res = (res + solve(i, k-1))%mod;
//         }
//     }
//     return res;
// }

struct matrix {
    vector<vector<ll>> mt;
    matrix(){
        mt.resize(n, vector<ll>(n));
    }
};

matrix operator* (const matrix& a, const matrix& b){
    matrix res = matrix();
    for(int i = 0; i < a.mt.size(); i++){
        for(int j = 0; j < b.mt[0].size(); j++){
            for(int k = 0; k < b.mt.size(); k++){
                res.mt[i][j] = (res.mt[i][j] + (a.mt[i][k] * b.mt[k][j])%mod)%mod;
            }
        }
    }
    return res;
}
matrix operator^ (matrix a, ll p){
    matrix res = matrix();
    for(int i = 0; i < res.mt.size(); i++) res.mt[i][i] = 1;
    while(p){
        if(p%2){
            res = res * a;
        }
        a = a * a;
        p /= 2;
    }
    return res;
}

int main(){
    cin>>n>>k;
    matrix m = matrix();
    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            cin>>m.mt[i][j];
        }
    }
    m = m ^ k;
    ll res = 0;
    // for(int i = 0; i < n; i++) res = (res + solve(i, k))%mod;
    for(auto x : m.mt){
        for(auto y : x){
            res = (res + y)%mod;
        }
    }
    cout<<res<<endl;
    return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main() {
  int count = 0 , l,r,d;
  cin >> l >> r >> d;
  
  for ( int i = l ; i <= r ; i++ ) {
    if (i%d==0) {
      count++;
    }
  }
  
  cout << count << endl;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
#define int long long
#define f first
#define ss second
#define mp make_pair
#define pb push_back
std::mt19937 rng((int) std::chrono::steady_clock::now().time_since_epoch().count());

const int N = 1e5+2;
int cnt[N], a[N];
signed main()
{
    std::ios::sync_with_stdio(0);
    std::cin.tie(0);
    std::cout.tie(0);
    int n,i,j,k;
    std::cin >> n;
    for(int i=1; i<=n; i++)
    {
        std::cin >> a[i];
        cnt[a[i]]++;
    }
    int q, sum=0;
    for(i=1; i<=n; i++) sum += a[i];
    std::cin >> q;
    while(q--)
    {
        std::cin >> i >> j;
        sum -= cnt[i]*i;
        sum += cnt[i]*j;
        cnt[j] += cnt[i];
        cnt[i] = 0;
        std::cout << sum << "\n";
    }
    return 0;
}


Measured memory_bytes: 5180
def main():
    N, M = map(int, input().split())
    *A, = map(int, input().split())
    *B, = map(int, input().split())

    ans = f(N, M, A, B)
    print(ans)


def f(N, M, A, B):
    """
    1 ≤ N  ≤ 1000
    1 ≤ M  ≤ 1000
    1 ≤ Ai ≤ N×M <= 10^6
    1 ≤ Bj ≤ N×M <= 10^6

    書き方
        1マス目: N*M   通り
        2マス目: N*M-1 通り
        (N*M)! 通り: TLE

    A * B による組合せ:
        クロスしたマスそれぞれ行列の最大値が異なるなら、小さい方以下を書く
        クロスしたマスそれぞれ行列の最大値が同じならそこに書くしかない
            よって、他の行列にその値がある場合は書けない
        両方考慮しないと書けるか分からない
        A * B: TLE
    """
    ans = editorial(N, M, A, B)
    return ans


def editorial(N, M, A, B):
    """
    最大値をsortしておくと考えやすい
    考える順を逆順sortしておくと考えやすい
        ある数字の次の数字は
        そこまでしか置けない
        それ以前には置ける
    行6ならば
        列6以上にしか置けない
        列4に置くと最大値4を超えてしまう
        2通り
      9 8 4
    9|9| | |
    8| |8| |
    6| | | |

    7ならば
        行8以上には置ける: 2通り
        列8以上には置ける: 2通り
        2*2 = 4
        9と8はすでに置いてあるので-2
            全体からこれ以降をすべて除けば今まで使った数
            N * M - 7 = 3 * 3 - 7 = 2
        よって 2通り
    """
    A = sorted(A)  # , reverse=True)
    B = sorted(B)  # , reverse=True)
    # 探索の高速化と行列での最大値重複判定setの代わり
    d_a = {a: None for a in A}
    d_b = {b: None for b in B}
    if len(d_a) != N:
        return 0
    if len(d_b) != M:
        return 0

    def f(xs, y):
        """これのためにsort, yを超える個数
        sortしてあるので二分探索でもよい: TLEになるので必須
        """
        from bisect import bisect_left
        idx = bisect_left(xs, y)
        return len(xs) - idx

    def f_slow(xs, y):
        for i, x in enumerate(xs):
            if x < y:
                return i

        return i + 1

    ans = 1
    MOD = 10 ** 9 + 7
    for i in range(1, N * M + 1)[::-1]:
        in_a = i in d_a
        in_b = i in d_b

        a, b = 0, 0
        if in_a and in_b:
            # 場所固定
            pass
        elif in_a:
            # 片方の行・列から候補を探す
            b = f(B, i)
            ans = ans * b % MOD
        elif in_b:
            a = f(A, i)
            ans = ans * a % MOD
        else:
            a = f(B, i)
            b = f(A, i)
            # 候補
            # すべてのマスに対して前までの数字は埋まっている
            cells = a * b
            used = (N * M - i)
            ans = (cells - used) * ans % MOD
            # print("\t", cells, used)

        # print(i, ans, a, b, in_a, in_b)

    return ans


if __name__ == '__main__':
    main()


Measured memory_bytes: 45164
#include<bits/stdc++.h>
#define _ ios_base::sync_with_stdio(0);cin.tie(0);
#define REP(i,n) for(int i=0;i<(int)(n);i++)

using namespace std;
using ll=long long;
using ld=long double;
using d_i=pair<ld,int>;

template <typename T>
class Bit{
public:
  Bit(int size):bit(vector<T>(size+1)),size(size){}
  T sum(int i){
    int s=0;
    while(i>0){
      s+=bit[i];
      i-=i&-i;
    }
    return s;
  }
  void add(int i,T x){
    while(i<=size){
      bit[i]+=x;
      i+=i&-i;
    }
  }
private:
  Bit();
  vector<T> bit;
  int size;
};

ll n;
const int MAX_N=40010;
ld a[MAX_N],b[MAX_N],c[MAX_N];
d_i di[MAX_N];
ld _a[MAX_N],_b[MAX_N],_c[MAX_N];
ld solve(){
  REP(i,n) di[i]=d_i(a[i]/b[i],i);
  sort(di,di+n);
  REP(i,n){
    int j=di[i].second;
    _a[i]=a[j];
    _b[i]=b[j];
    _c[i]=c[j];
  }
  ld lo=-1e9,hi=1e9;
  REP(z,100){
    ld x=(lo+hi)/2;
    d_i yi[n];
    REP(i,n){
      yi[i]=d_i((_c[i]-_a[i]*x)/_b[i],i+1);
    }
    sort(yi,yi+n);
    Bit<int> bit(n);
    ll sum=0;
    REP(j,n){
      int i=yi[j].second;
      sum+=j-bit.sum(i);
      bit.add(i,1);
    }
    if(sum*2>=n*(n-1)/2) hi=x;
    else lo=x;
  }
  return lo;
}

int main(){ _;
  cin>>n;
  REP(i,n)cin>>a[i]>>b[i]>>c[i];
  ld x=solve();
  swap(a,b);
  ld y=solve();
  printf("%.15Lf %.15Lf\n",x,y);
}


Measured memory_bytes: 6656
#include <bits/stdc++.h>
 
#define rep(i,n) for(ll i=0;i<n;++i)
#define ALL(a) (a).begin(),(a).end()
 
using namespace std;
using ll  = long long;
using pll = pair<ll, ll>;
using pdd = pair<double, double>;
 
const ll MOD  = 1e9 + 7;
const ll LINF = 1LL << 60;
const int INF = 1e9 + 7;

//素数判定
bool isPrime(ll n){
    if(n == 2)return true;
    if(n == 1 || n == 0)return false;

    ll sq  = sqrt(n) + 1;
    ll tmp = n; 

    for(int i = 2; i <= sq; ++i){
        sq = sqrt(tmp) + 1;
        while(tmp%i == 0)tmp/=i;
    }

    if(tmp == n)return true;
    return false;
}

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

    ll rui[100010] = {};

    for(ll i = 1; i <= 100000; i+=2){
        if(isPrime(i) && isPrime((i+1)/2)){
            rui[i] = 1;
        }
    }

    rep(i, 100000)rui[i+1] += rui[i];

    rep(i, q){
        ll l, r;
        cin >> l >> r;

        cout << rui[r] - rui[l-1] << endl;
    }
}

Measured memory_bytes: 1408
#include <iostream>
#include <cstdio>
using namespace std;
int main()
{
	string a,b;
	cin>>a>>b;
	int len=a.length()+b.length();
	for(int i=0;i<len;i++) if(i%2==0) cout<<a[i/2];
	else cout<<b[i/2];
	return 0;
}

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

// Smam, Large, or Equal
// -1000 <= a, b <= 1000
int main(){
	int a, b;
	cin >> a;
	cin >> b;

	if (a < b){
		cout << "a < b" << endl;
	}else if(a > b){
		cout << "a > b" << endl;
	}else{
		cout << "a == b" << endl;
	}
	
	return 0;
}


Measured memory_bytes: 3108
#include <stdio.h>
#include<string.h>
int main()
{
    int i,j,flag=0;
    char a[5][5],b[5][5],temp;
  
    for(j=0;j<3;j++)
    scanf("%c",&a[0][j]);
    scanf("%c",&temp);
    for(j=0;j<3;j++)
    scanf("%c",&a[1][j]);
    for(i=0;i<2;i++)
    {
        for(j=0;j<3;j++)
        {
            b[i][j]=a[1-i][2-j];
        }
    }
   
    
    if(strcmp(a,b)==0)
    {
   flag=1;
    }
   else
    {
    flag=0;
    }
    
    if(flag)
          printf("YES");
          else
         printf("NO");
return 0;
}
    

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define endl '\n'
#define int long long int
using namespace std;
#define pii pair <int, int>
#define mii map<int, int>
#define pb push_back
#define deb(x) cout << #x << " " << x << endl
#define deb2(x, y) cout << #x << " " << x << " " << #y << " " << y << endl
#define Loop(s, e, itr) for (int itr = s; itr < e; itr++)
#define loop(n) for(int i = 0; i < n; i++)
#define vin vector<int>
#define w(t) int tc; cin >> tc; for(int t = 1; t <= tc; t++)
#define vec vector
#define mod 1000000007
#define all(x) x.begin(), x.end()

int dp[1002][1002];
int h, w;

int find(int i, int j){
    if(i > h or j > w) return 0;
    if(dp[i][j] == -1){
        dp[i][j] = (find(i+1, j) + find(i, j+1))%mod; 
    }
    return dp[i][j];
}

int32_t main(){
    memset(dp, -1, sizeof(dp));
    cin >> h >> w;
    char temp;
    dp[h][w] = 1;
    for(int i = 1; i <= h; i++){
        for(int j = 1; j <= w; j++){
            cin >> temp;
            if(temp == '#') dp[i][j] = 0;
        }
    }

    cout << find(1, 1);
}

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

av1 = sum(a) // n
if sum(a) % n == 0:
    av2 = av1
else:
    av2 = av1 + 1

ans1 = 0
ans2 = 0
for i in range(n):
    ans1 += (av1 - a[i]) ** 2
    ans2 += (av2 - a[i]) ** 2

print(min(ans1, ans2)) 

Measured memory_bytes: 3064
#include<stdio.h>
int main()
{
    int arr []= {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    int k;
    scanf ("%d",&k);
    printf("%d\n",arr[k-1]);

}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int) n; i++)
#define repb(i, n) for (int i = (int) n; i >= 0; i--)
#define reps(i, m, n) for (int i = (int) m; i < (int) n; i++)
#define repsb(i, m, n) for (int i = (int) m; i >= (int) n; i--)
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.begin(), v.end(),greater<int>());
#define pb(a) push_back(a)
#define ll long long int
const ll LLINF = 1e18 + 10;
int dy[] = { 0, 0, 1, -1, 0 };
int dx[] = { 1, -1, 0, 0, 0 };
template < class T > bool chmax(T & a,const T & b) { if (a < b) { a = b; return 1; } return 0; }
template < class T > bool chmin(T & a,const T & b) { if (b < a) { a = b; return 1; } return 0; }
//vector<vector<int>> vec(n_rows, vector<int>(n_cols, value));
using namespace std;
int main(int argc, char const * argv[]){
    int n;
    double ans=0;
    cin >> n;
    vector<double> v(n,-1);
    rep(i,n) cin>>v[i];
    VSORT(v)
    rep(i,n) {
        ans += v[i];
        if(i!=0)
            ans /= 2;
        
    }
    cout<<setprecision(5)<<ans<<endl;
    return 0;
}

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

#define int long long

#define ii pair<int,int>
#define fi first
#define sc second

#define all(x) (x).begin(),(x).end()

void solve() {
  int n, q;
  cin >> n >> q;
  string s;
  cin >> s;
  vector<int> a(n);
  for (int i = 1; i < n; i++) {
    a[i] = a[i - 1];
    if (s.substr(i - 1, 2) == "AC") a[i]++;
  }
  for (int i = 0; i < q; i++) {
    int l, r;
    cin >> l >> r;
    l--; r--;
    cout << a[r] - a[l] << '\n';
  }
}

signed main() {
#ifdef _DEBUG
  // freopen("in" , "r", stdin );
  // freopen("out", "w", stdout);
#endif
  ios::sync_with_stdio(0); cin.tie(0);
  int T = 1;
  // cin >> T;
  while (T--) solve();
}


Measured memory_bytes: 4196
#include <bits/stdc++.h>
using namespace std;
#define INF 1000000007
int main()
{
    int n,k;
    cin>>n>>k;
    int arr[n+1];
    for(int i=1;i<=n;i++)
    cin>>arr[i];
    int dp[n+1];
    for(int i=0;i<=n;i++)
    dp[i]=INF;
    dp[1]=0;
    dp[2]=abs(arr[2]-arr[1]);
    for(int i=3;i<=n;i++)
    {
        for(int j=max(i-k,1);j<i;j++)
        {
            dp[i]=min(dp[i],dp[j]+abs(arr[i]-arr[j]));
        }
    }
    cout<<dp[n]<<"\n";
}

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

using namespace std; 

int main(){
	
	int n;
	
	cin >> n; 
	
	int ans = 0;
	
	int big = 0;
	
	vector<int> container(15);
	
	for(int i=0;i<n;i++){
		cin >> container[i];
		ans += container[i];
		big = max(container[i],big);
	}
	
	ans-=big;
	
	ans+=big/2;
	
	cout << ans << endl;
	
    return 0;
}


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

typedef long long ll;

vector<ll> num,cnt;

void divide(ll n)
{
	ll a = n;
	for (ll i = 2; i * i <= n; i++)
	{
		if( a % i == 0 )
		{
			num.push_back(i);
			int z = 0;
			while( a % i == 0 )
			{
				a /= i;
				z ++;
			}
			cnt.push_back(z);  
		}
	}
	if( a > 1 )
	{
		num.push_back(a);
		cnt.push_back(1); 
	}
}

int slove(int n)
{
	for (int i = 1; ; i++)
	{
		if( (1 + i ) * i / 2 > n ) return i - 1;
	}
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll n;
	cin >> n;
	divide(n);
	ll ans = 0;
	for (int i = 0; i < cnt.size(); i++)
	{
		ans += slove(cnt[i]);
	}
	cout << ans << '\n';
	return 0;
}


Measured memory_bytes: 3196
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using uint = unsigned int;
#define rep(i,n) for(int i=0;i<int(n);i++)
#define rep1(i,n) for(int i=1;i<=int(n);i++)
#define per(i,n) for(int i=int(n)-1;i>=0;i--)
#define per1(i,n) for(int i=int(n);i>0;i--)
#define all(c) c.begin(),c.end()
#define si(x) int(x.size())
#define pb emplace_back
#define fs first
#define sc second
template<class T> using V = vector<T>;
template<class T> using VV = vector<vector<T>>;
template<class T,class U> void chmax(T& x, U y){if(x<y) x=y;}
template<class T,class U> void chmin(T& x, U y){if(y<x) x=y;}
template<class T> void mkuni(V<T>& v){sort(all(v));v.erase(unique(all(v)),v.end());}
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
	return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
	o<<"{";
	for(const T& v:vc) o<<v<<",";
	o<<"}";
	return o;
}
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

#ifdef LOCAL
#define show(x) cerr << "LINE" << __LINE__ << " : " << #x << " = " << (x) << endl
void dmpr(ostream& os){os<<endl;}
template<class T,class... Args>
void dmpr(ostream&os,const T&t,const Args&... args){
	os<<t<<" ~ ";
	dmpr(os,args...);
}
#define shows(...) cerr << "LINE" << __LINE__ << " : ";dmpr(cerr,##__VA_ARGS__)
#define dump(x) cerr << "LINE" << __LINE__ << " : " << #x << " = {";  \
	for(auto v: x) cerr << v << ","; cerr << "}" << endl;
#else
#define show(x) void(0)
#define dump(x) void(0)
#define shows(...) void(0)
#endif

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);		//DON'T USE scanf/printf/puts !!
	cout << fixed << setprecision(20);

	string s; cin >> s;
	int N = s.size();
	rep(i,N) if(s[i] == '?') s[i] = 'D';
	cout << s << endl;
}


Measured memory_bytes: 3744
N = 10**9+7

s = input()
l = len(s)
dp=[[0]*13 for i in range(l+1)]
dp[0][0]=1

c = 1
for i in range(l):
    x = s[-1-i]
    if x == '?':
        for k in range(10):
            for j in range(13):
                dp[i+1][(k*c+j)%13]+=dp[i][j]
                dp[i+1][(k*c+j)%13]%=N
    else:
        k = int(x)
        for j in range(13):
            dp[i+1][(k*c+j)%13]+=dp[i][j]
            dp[i+1][(k*c+j)%13]%=N
    c*=10
    c%=13
print(dp[l][5])


Measured memory_bytes: 96152
import bisect
import heapq
import itertools
import math
import operator
import os
import re
import string
import sys
from collections import Counter, deque, defaultdict
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter, mul, add, xor

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7

N = int(sys.stdin.readline())
A = list(map(int, sys.stdin.readline().split()))
B = list(map(int, sys.stdin.readline().split()))

ans = 0
for i, b in enumerate(B):
    ans += min(A[i] + A[i + 1], b)
    b -= min(A[i], b)
    A[i + 1] -= min(A[i + 1], max(0, b))
print(ans)


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

int main(){
    int m;
    while(true){
        cin >> m;
        int mi,ma;
        cin >> mi >> ma;
        if(m==0&&mi==0&&ma==0)break;
        int k[m];
        for(int i=0;i<m;i++)cin >>k[i];
        int ans=0; int num=0;
        for(int i=mi-1;i<ma;i++){
            if(k[i]-k[i+1]>=num){
                num=k[i]-k[i+1];
                ans=i+1;
            }
        }
        cout << ans << endl;
    }
}


Measured memory_bytes: 3080
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1000000007;
const int INF = 1e+9;


int main()
{
	int n = 0;
	cin >> n;
    int ct = 0;
    pair <pair<string, int>, int> p[110];

    for (int i = 0; i < n; i++)
    {
        string name = "";
        int score = 0;
        cin >> p[i].first.first >> p[i].first.second;
        p[i].first.second = p[i].first.second * (-1);
        p[i].second = i + 1;
    }
    sort(p, p+n);

    for (int i = 0; i < n; i++)
    {
        cout << p[i].second << "\n";
    }

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
#define rep(i,m,n) for(int i=m;i<n;i++)
#define co(n) cout<<n<<endl
#define all(n) (n).begin(),(n).end()
#define pb(n,m) n.push_back(m)
#define fix(n) cout<<fixed<<setprecision(n);
using namespace std;
//using bint=boost::multiprecision::cpp_int;
typedef long long ll;
typedef unsigned long long ull;

int main(){
  double pi=3.1415926535;
  double a,b,c; cin>>a>>b>>c;
  double rad=pi*c/180;
  fix(12);
  co(0.5*a*b*sin(rad));
  double l=pow(a*a+b*b-2*a*b*cos(rad),0.5);
  co(l+a+b);
  co(b*sin(rad));
  return 0;
}


Measured memory_bytes: 3576
#include <iostream>
#include <stdio.h>
#include <string>
#include <algorithm>
#include <math.h>

using namespace std;

int main() {
	int n, a[100], max, min;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	max = a[0];
	min = a[0];
	for (int i = 1; i < n; i++) {
		if (a[i] > max) {
			max = a[i];
		}
		if (a[i] < min) {
			min = a[i];
		}
	}
	cout << max - min << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <utility>
#include <functional>
#include <iomanip>
#include <typeinfo>
#include <iterator>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <tuple>
#include <map>
#include <set>
#include <numeric>
using namespace std;


typedef long long       ll;
typedef struct edge_ { ll to; ll cost; } edge;
typedef vector<int>     vi;
typedef vector<ll>      vll;
typedef vector<double>  vd;
typedef vector<bool>    vb;
typedef vector<string>  vs;
typedef vector<char>    vc;
typedef vector<edge>    ve;
typedef pair<int, int>  pii;
typedef pair<ll, ll>    pll;
typedef vector<pii>     vpii;
typedef vector<pll>     vpll;
typedef vector<vll>		vvll;
typedef vector<vi>		vvi;
typedef vector<ve>      vve;
typedef vector<vc>		vvc;

#define repr(itr, bgn, end) for (ll itr = (ll)bgn; itr < (ll)end; ++itr)
#define rep(itr, end) repr(itr, 0, end)
#define reprrev(itr, bgn, end) for (ll itr = (ll)end - 1; itr >= (ll)bgn; --i)
#define reprev(itr, end) reprrev(itr, 0, end)
#define all(container) container.begin(), container.end()
#define sortall(container) sort(all(container))
#define yn(cond) cond ? (cout << "Yes" << endl) : (cout << "No" << endl)
#define YN(cond) cond ? (cout << "YES" << endl) : (cout << "NO" << endl)

// 定数
#define LLONG_MAX numeric_limits<ll>::max()
#define INT_MAX numeric_limits<int>::max()
constexpr double PI = 3.14159265358979323846;
constexpr ll INF = 1 << 15;
constexpr ll MOD = (ll)1e9 + 7;
constexpr double EPS = 1e-7;

// よく使うもの
constexpr int dy[4] = { 0, 1, 0, -1 };
constexpr int dx[4] = { 1, 0, -1, 0 };


// vector入力
template<typename T>
istream& operator >> (istream& is, vector<T>& vec) {
	for (T& x : vec) is >> x;
	return is;
}

// vector出力
template<typename T>
ostream& operator << (ostream& os, vector<T>& vec) {
	for (T& x : vec) os << x << " ";
	return os;
}

// pair出力
template<typename S, typename T>
ostream& operator << (ostream& os, pair<S, T>& p) {
	os << p.first << " " << p.second;
	return os;
}



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

	vi Snum, Tnum;
	vc Skey, Tkey;

	for (int i = 0; i < S.length(); i++) {
		bool exist = false;
		for (int j = 0; j < Skey.size(); j++) {
			if (S[i] == Skey[j]) {
				Snum[j]++;
				exist = true;
				break;
			}
		}

		if (!exist) {
			Skey.push_back(S[i]);
			Snum.push_back(1);
		}

		exist = false;
		for (int j = 0; j < Tkey.size(); j++) {
			if (T[i] == Tkey[j]) {
				Tnum[j]++;
				exist = true;
				break;
			}
		}

		if (!exist) {
			Tkey.push_back(T[i]);
			Tnum.push_back(1);
		}
	}

	sortall(Snum);
	sortall(Tnum);

	yn(Snum == Tnum);

	return 0;
}

Measured memory_bytes: 776
#include <stdio.h>
#include <stdlib.h>
int cmp(const void *a,const void *b){
    return *(int*)a-*(int*)b;
}
int main(void){
    int n;
    int i,sum,tem,ans;
    int s[100];
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d",&s[i]);
    }
    qsort(s,n,sizeof(s[0]),cmp);
    //for(i=0;i<n;i++)printf("%d\n",s[i]);
    for(i=0;i<n;i++)sum+=s[i];
    if(sum%10!=0){printf("%d\n",sum);
        return 0;
    }
    for(i=0;i<n;i++){
        tem=sum;
        tem-=s[i];
        if(tem%10!=0)break;
    }
    if(i==n){printf("0\n");
        return 0;
    }
    printf("%d\n",tem);
    return 0;
}

Measured memory_bytes: 128
#pragma region RegionDefs
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0,i##_len=(n);i<i##_len;++i)
#define reps(i,l,r) for(int i=(l),i##_len=(r);i<i##_len;++i)
#define all(x) begin(x),end(x)
using namespace std;
typedef long long ll;
const ll INF = 1e9;
template<class T=ll> using V = vector<T>;
template<class T=ll> using PQ = priority_queue<T>;
template<class T=ll> using PQG = priority_queue<T, V<T>, greater<T>>;
const ll MOD = 1000000007LL;
void in() {}
template<class Head, class... Tail>
void in(Head&& head, Tail&&... tail) { cin >> head; in(move(tail)...); }
#define IN(...) ll __VA_ARGS__; in(__VA_ARGS__)
#define INS(T, ...) T __VA_ARGS__; in(__VA_ARGS__)
#define VIN(T, v, n) V<T> v(n); for(auto& _elem:v)cin>>_elem
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 y0 y__0
#define y1 y__1
#define j0 j__0
#define j1 j__1
#define YN(e) cout << ((e) ? "YES" : "NO") << endl
#define yn(e) cout << ((e) ? "Yes" : "No") << endl
#pragma endregion RegionDefs

const int MAX = 510000;

long long fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

long long PER(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * finv[n - k] % MOD;
}

long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

void solve()
{
    COMinit();
    IN(n, m);
    ll s = PER(m, n);
    ll sign = -1;
    reps(i, 1, n+1) {
        s = (s + MOD * MOD + sign * PER(m-i, n-i) * COM(n, i)) % MOD;
        sign = -sign;
    }
    cout << s * PER(m, n) % MOD << endl;
}

int main()
{
    cin.tie(0); cout.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(numeric_limits<double>::max_digits10);

    solve();

    return 0;
}

Measured memory_bytes: 15492
#include <stdio.h>
#include <string.h>
#include <stdbool.h>

#define M 1046527
#define NIL (-1)
#define L 14

static char H[M][L];

static int getChar(char ch)
{
    if (ch == 'A') {
        return 1;
    } else if (ch == 'C') {
        return 2;
    } else if (ch == 'G') {
        return 3;
    } else if (ch == 'T') {
        return 4;
    } else {
        return 0;
    }
}

static int getKey(char* s)
{
    int key = 0;
    int p = 1;

    for (int i = 0; i < strlen(s); i++) {
        key += p * getChar(s[i]);
        p *= 5;
    }

    return key;
}

static int h1(int key)
{
    return key % M;
}

static int h2(int key)
{
    return 1 + (key % (M - 1));
}

static int hash(int key, int i)
{
    return (h1(key) + i * h2(key)) % M;
}

static bool find(char* s)
{
    int key = getKey(s);

    for (int i = 0;; i++) {
        int h = hash(key, i);
        if (strcmp(H[h], s) == 0) {
            return true;
        } else if (H[h][0] == '\0') {
            return false;
        }
    }

    return false;
}

static bool insert(char* s)
{
    int key = getKey(s);

    for (int i = 0;; i++) {
        int h = hash(key, i);
        if (strcmp(H[h], s) == 0) {
            return true;
        } else if (H[h][0] == '\0') {
            strcpy(H[h], s);
            return false;
        }
    }

    return false;
}

int main()
{
    int n;
    char command[7];
    char s[L];

    scanf("%d", &n);

    for (int i = 0; i < M; i++) {
        H[i][0] = '\0';
    }

    for (int i = 0; i < n; i++) {
        scanf("%s %s", command, s);

        if (command[0] == 'i') {
            insert(s);
        } else {
            if (find(s)) {
                printf("yes\n");
            } else {
                printf("no\n");
            }
        }
    }

    return 0;
}


Measured memory_bytes: 16100
x, k, d = map(int, input().split())

if abs(x//d) >= k:
    print(abs(abs(x)-abs(k*d)))
else:
    if (k-(x//d))%2 == 0:
        print(abs(x%d))
    else:
        print(abs(abs(x%d)-abs(d)))

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

int main() {
    int n, age;
    while (scanf("%d",&n), n) {
        int num[7] = {};
        for (int i=0; i<n; ++i) {
            scanf("%d",&age);
            if (60 <= age) ++ num[6];
            else ++ num[age/10];
        }
        for (int i=0; i<7; ++i) {
            printf("%d\n", num[i]);
        }
    }
    return 0;
}

Measured memory_bytes: 1028
#include <stdio.h>

int main(void)
{
	int d;
	int i;
	int ans;
	
	while (scanf("%d", &d) != EOF){
		ans = 0;
		
		for (i = 0; i < 600; i += d){
			ans += (d * i * i);
		}
		
		printf("%d\n", ans);
	}
	
	return (0);
}

Measured memory_bytes: 1024
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv,
    std.functional, std.math, std.numeric, std.range, std.stdio, std.string,
    std.random, std.typecons, std.container;

ulong MAX = 1_000_100, MOD = 1_000_000_007, INF = 1_000_000_000_000;
alias sread = () => readln.chomp();
alias lread(T = long) = () => readln.chomp.to!(T);
alias aryread(T = long) = () => readln.split.to!(T[]);
alias Node = Tuple!(long, "p", long, "dist");
alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less);

void main()
{
    auto n = lread();
    auto TREE = new Node[][](n, 0);
    auto color = new long[](n);
    foreach (_; iota(n - 1))
    {
        long u, v, w;
        scan(u, v, w);
        TREE[u - 1] ~= Node(v - 1, w);
        TREE[v - 1] ~= Node(u - 1, w);
    }
    // TREE.each!(x => x.writeln());
    color[0] = 1;
    dfs(TREE, color, 0, 0);
    foreach (e; color)
        writeln(e - 1);
}

void dfs(T)(T tree, long[] color, long current, long dist)
{
    foreach (node; tree[current])
    {
        if (!color[node.p])
        {
            if ((dist + node.dist) % 2)
                color[node.p] = 2;
            else
                color[node.p] = 1;
            dfs(tree, color, node.p, dist + node.dist);
        }
    }
}

void scan(TList...)(ref TList Args)
{
    auto line = readln.split();
    foreach (i, T; TList)
    {
        T val = line[i].to!(T);
        Args[i] = val;
    }
}


Measured memory_bytes: 24444
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>

using namespace std;

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

	int ans = 0;

	if (a + b > 2 * c)
	{
		ans += min(x, y) * c * 2;

		int sa = abs(x - y);

		if (x - y > 0)
		{
			if (a > 2 * c)
			{
				ans += sa * c * 2;
			}
			else
			{
				ans += sa * a;
			}
		}
		else
		{
			if (b > 2 * c)
			{
				ans += sa * c * 2;
			}
			else
			{
				ans += sa * b;
			}
		}
	}
	else
	{
		ans += a * x;
		ans += b * y;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define ll long long
#define imfor(i, n) for(int i = 0; i < n; i++)
using namespace std;
ll MOD = 1000000007;

int main() {
    string s;
    cin >> s;
    char tmp = s[0];
    int ans = 0;
    for (int i = 1; i < s.size(); i++) {
        if (s[i] != tmp) {
            ans++;
            tmp = s[i];
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
//#include <atcoder/all>
#define rep(i, n) for (int i = 0; i < (n); ++i)
//using namespace atcoder;
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define FOR(i, a, b) for (ll i = a; i <= (ll)(b); i++)
//xにはvectorなどのコンテナ
#define ALL(x) (x).begin(), (x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size())      //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))   //最大値を求める
#define MIN(x) *min_element(ALL(x))   //最小値を求める
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define inf 2147483647    //int値の最大値
#define MOD 1000000007    //10^9+7:合同式の法
#define MAXR 100000       //10^5:配列の最大のrange(素数列挙などで使用)
//略記
#define PB push_back                            //vectorヘの挿入
#define MP make_pair                            //pairのコンストラクタ
#define F first                                 //pairの一つ目の要素
#define S second                                //pairの二つ目の要素
#define CST(x) cout << fixed << setprecision(x) //小数点以下の桁数指定
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;
}
int gcd(int a, int b)
{
    if (b == 0)
        return a;
    else
        return gcd(b, a % b);
}
int lcm(int a, int b)
{
    return a * b / gcd(a, b);
}

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

    int n;
    cin >> n;
    bool b = false;
    for (int i = 1; i < 10; i++)
    {
        for (int j = 1; j < 10; j++)
        {
            if (i * j == n)
            {
                b = true;
                break;
            }
        }
        if (b)
            break;
    }
    if (b)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}


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

int main(){
  double a,b,t; cin >> a >> b >> t;
  for(int i=1;i<100;i++){
      if(t+0.5<a*i)break;
      cnt+=b;
  }
  cout << cnt  << endl;
 
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REPR(i, n) for(int i = n - 1;i >= 0;i--)
#define FOR(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
#define ll long long
#define INF 1e9
int main()
{
    bool judge = true;
    int x, y;
    cin >> x >> y;
    if(x * 2 > y || x * 4 < y || y % 2 == 1) judge = false;

    if(judge == true) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

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

int main(){
  int t;
  cin >> t;
  while(t--) {
    ll n, m, a, b;
    cin >> n >> m >> a >> b;
    cout << floor_sum(n,m,a,b) << endl;
  }
  return 0;
}


Measured memory_bytes: 3564