akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
    int N,A,B;
    cin>>N>>A>>B;
    cout<<min(A,B)<<" "<<(N-(A+B)<0?A+B-N:0)<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdlib>
#include<ctime>

using namespace std;

struct dice{
  int u,n,e,s,w,d;
};

int main(){

  srand((unsigned)time(NULL));

  dice d;
  dice d2;
  int tmp;
  int q,a,b;
  int rn;

  cin>>d.u>>d.s>>d.e>>d.w>>d.n>>d.d;
  cin>>q;
  d2=d;
  for(int i=0;i<q;i++){
    cin>>a>>b;
    while(1){
      rn=rand()%4;
      if(rn==0){
	tmp=d.u;
	d.u=d.s;
	d.s=d.d;
	d.d=d.n;
	d.n=tmp;
      }
      else if(rn==1){
	tmp=d.u;
	d.u=d.w;
	d.w=d.d;
	d.d=d.e;
	d.e=tmp;
      }
      else if(rn==2){
	tmp=d.u;
	d.u=d.n;
	d.n=d.d;
	d.d=d.s;
	d.s=tmp;
      }
      else if(rn==3){
	tmp=d.u;
	d.u=d.e;
	d.e=d.d;
	d.d=d.w;
	d.w=tmp;
      }
      if(d.u==a&&d.s==b){
	cout<<d.e<<endl;
	break;
      }
    }
    d=d2;
  }
}

Measured memory_bytes: 1164
n = int(input())
idx = 1
total = 0
tmp = n
while (tmp > 0): 
	if idx == len(str(n)):
		if idx % 2 == 1:
			total += (tmp - 1) * 10 ** (idx - 1)
			total += n % (10 ** (idx - 1)) + 1
	else:
		if idx % 2 == 1:
			total += 9 * 10 ** (idx - 1)
	tmp = int(tmp / 10)
	idx += 1
print (total)

Measured memory_bytes: 3064
#!/bin/sh
read x y

if [ "${x::1}" != "-" -a ${y::1} != "-" ] || [ "${x::1}" = "-" -a ${y::1} = "-" ]
then
	if [ $x -lt $y ]
	then
		ans=$((y - x))
	elif [ $x -gt $y ]
	then
		ans=$((x - y + 2))
	fi

	if [ $y -eq 0 ]
	then
		ans=$((ans - 1))
	fi
	
	echo $ans
	exit
fi

if [ "${x::1}" != "-" -a ${y::1} = "-" ]
then
	if [ "${x}" = "${y/-/}" ]
	then
		echo 1
		exit
	fi
	
	yy="${y/-/}"
	
	if [ $x -gt $yy ]
	then
		ans=$((x - yy + 1))
	elif [ $x -lt $yy ]
	then
		ans=$((yy - x + 1))
	fi

	if [ $y -eq 0 ]
	then
		ans=$((ans - 1))
	fi

	echo $ans
	exit
fi

if [ "${y::1}" != "-" -a ${x::1} = "-" ]
then
	if [ "${y}" = "${x/-/}" ]
	then
		echo 1
		exit
	fi
	
	xx="${x/-/}"
	
	if [ $y -gt $xx ]
	then
		ans=$((y - xx + 1))
	elif [ $y -lt $xx ]
	then
		ans=$((xx - y + 1))
	fi

	if [ $y -eq 0 ]
	then
		ans=$((ans - 1))
	fi

	echo $ans
	exit
fi


Measured memory_bytes: 1396
#include <iostream>
#include <vector>
#include <algorithm>
//#include <fstream>

using namespace std;

int main()
{
//	cut here before submit 
//	freopen ("testcase.tri", "r", stdin );
	int n;
	cin >> n;

	int i,j;
	vector <int> side (3, 0 );

	for (i = 0; i < n; ++i ){
		for (j = 0; j < 3; ++j ){
			cin >> side[j];
		} // end for

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

		if (side[2]*side[2] == side[1]*side[1] + side[0]*side[0] ){
			cout << "YES" << endl;
		}else{
			cout << "NO" << endl;
		} // end if
	} // end for
		
	return 0;
}

Measured memory_bytes: 0
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

def main():
    S=input()
    T=input()
    YesNo(S==T[:-1])

if __name__ == '__main__':
    main()


Measured memory_bytes: 61844
#include <algorithm>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int(i) = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define pb push_back
#define MP(a, b) make_pair((a), (b))
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;

int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    vector<vector<pii>> xy(N, vector<pii>());
    using pii = pair<int, int>;
    rep(i, N) {
        cin >> A[i];
        rep(j, A[i]) {
            int x, y;
            cin >> x >> y;
            x--;
            xy[i].pb(MP(x, y));
        }
    }
    int res = 0;
    for(int bit = 0; bit < (1 << N); ++bit) {
        vector<int> honest(N, 0);
        for(int i = 0; i < N; i++) {
            if(bit & (1 << i)) {
                honest[i] = 1;
            }
        }
        // rep(i, N) { cout << honest[i] << " "; }
        // cout << endl;
        int flag = 0;
        rep(i, N) {
            rep(j, xy[i].size()) {
                if(honest[i] && xy[i][j].second != honest[xy[i][j].first]) {
                    flag = 1;
                }
            }
        }
        if(flag == 0) {
            int cnt = 0;
            rep(i, N) {
                if(honest[i])
                    cnt++;
            }
            res = max(res, cnt);
        }
    }
    cout << res << endl;
    return 0;
}

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

#define MOD 1000000007

int main()
{
	int N;
	cin >> N;
	vector<int> T( N );
	for( int i = 0; i < N; i++ ) {
		cin >> T[i];
	}
	vector<int> A( N );
	for( int i = 0; i < N; i++ ) {
		cin >> A[i];
	}

	if( T[N - 1] != A[0] ) {
		cout << 0 << endl;
		return 0;
	}
	vector<int> t( N );
	for( int i = 0; i < N; i++ ) {
		if( i == 0 ) t[i] = 1;
		else if( T[i] > T[i - 1] ) t[i] = 1;
		if( t[i] && A[i] < T[i] ) {
			cout << 0 << endl;
			return 0;
		}
	}
	vector<int> a( N );
	for( int i = N - 1; i >= 0; i-- ) {
		if( i == N - 1 ) a[i] = 1;
		else if( A[i] > A[i + 1] ) a[i] = 1;
		if( a[i] && A[i] > T[i] ) {
			cout << 0 << endl;
			return 0;
		}
	}
	long long ans = 1;
	for( int i = 0; i < N; i++ ) {
		if( t[i] || a[i] ) {
			continue;
		}
		ans *= min( T[i], A[i] );
		ans %= MOD;
	}

	cout << ans << endl;
}


Measured memory_bytes: 1792
import sys
S = input()
op = ['+', '-']
for op1 in op:
    for op2 in op:
        for op3 in op:
            if eval(S[0] + op1 + S[1] + op2 + S[2] + op3 + S[3]) == 7:
                print(S[0] + op1 + S[1] + op2 + S[2] + op3 + S[3] + '=7')
                sys.exit()


Measured memory_bytes: 3060
#include <iostream>
#include <iomanip>
#include <vector>
#include <cmath>
#include <utility>
#include <algorithm>
#include <map>
#include <climits>

#define ll long long
#define max(A, B) ((A) > (B) ? (A) : (B))
#define min(A, B) ((A) < (B) ? (A) : (B))

using namespace std;

int main() {
  int t; cin >> t;
  int a[t], b[t], c[t], dpA[t], dpB[t], dpC[t], dp[t];
  dp[0] = dpA[0] = dpB[0] = dpC[0] = 0;
  cin >> a[0] >> b[0] >> c[0];
  for (int i = 1; i < t; i++) {
    cin >> a[i] >> b[i] >> c[i];
    dpA[i] = max(dpB[i - 1] + b[i - 1], dpC[i - 1] + c[i - 1]);
    dpB[i] = max(dpA[i - 1] + a[i - 1], dpC[i - 1] + c[i - 1]);
    dpC[i] = max(dpA[i - 1] + a[i - 1], dpB[i - 1] + b[i - 1]);
  }
  cout << max(a[t - 1] + dpA[t - 1], max(b[t - 1] + dpB[t - 1], c[t - 1] + dpC[t - 1])) << endl;
}


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

int main(){
	int n;
	cin >> n;
	vector<int> a(n);
	vector<int> b(n);
	vector<int> acount(n+1);
	vector<int> bcount(n+1);
	rep(i,n){
		cin >> a[i];
		acount[a[i]]++;
	}
	rep(i,n){
		cin >> b[i];
		bcount[b[i]]++;
	}
	REP(i,n){
		if(acount[i] + bcount[i] > n){
			cout << "No" << endl;
			return 0;
		}
	}
	sort(b.rbegin(),b.rend());
	queue<int> que;
	rep(i,n){
		if(a[i] == b[i]) que.push(i);
	}
	srand((unsigned int)time(NULL));
	while(!que.empty()){
		int p = que.front(); que.pop();
		int idx = rand() % n;
		swap(b[p], b[idx]);
		if(b[p] == a[p]) que.push(p);
		if(b[idx] == a[idx]) que.push(idx);
	}
	cout << "Yes" << endl;
	rep(i,n) cout << b[i] << " ";
	cout << endl;
    return 0;
}

Measured memory_bytes: 6776
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = uint32_t;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    ll n, k;
    cin >> n >> k;
    vector<int> a(n), f(n);
    for (auto &&i : a) scanf("%d", &i);
    for (auto &&i : f) scanf("%d", &i);
    sort(a.begin(),a.end());
    sort(f.begin(),f.end(), greater<>());
    ll ng = -1, ok = 1000000000001;
    while(ok-ng > 1){
        auto mid = (ok+ng)/2;
        ll s = 0;
        for (int i = 0; i < n; ++i) {
            s += max<ll>(0, a[i]-mid/f[i]);
        }
        (s > k ? ng : ok) = mid;
    }
    cout << ok << "\n";
    return 0;
}

Measured memory_bytes: 1792
import sys
import bisect
from functools import lru_cache
from collections import defaultdict
inf = float('inf')
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**6)
def input(): return sys.stdin.readline().rstrip()
def read():
  return int(readline())
def reads():
  return map(int, readline().split())
X=read()
if(X>=30):
    print("Yes")
else:
    print("No")

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

int main() {
  int N,M;
  cin >> N >> M;
  
  vector<int> A(M);
  vector<int> B(M);
  
  vector<vector<int>> data(N + 1);
  
  
  
  for(int i = 0 ; i < M ; i++){
    cin >> A.at(i);
    cin >> B.at(i);
    data.at(A.at(i)).push_back(B.at(i));
    data.at(B.at(i)).push_back(A.at(i));
  }
  
  
  queue<int> q;
  
  vector<int> length(N + 1,0);
  vector<int> to(N + 1,1);

  vector<bool> flag(N + 1,false);
  
  length.at(1) = 1;
  to.at(1) = 0;
  
  q.push(1);
  
  while(1){
    if(q.empty()){
      break;
    }
    
    int now = q.front();
    q.pop();
    if(flag.at(now) == true){
      continue;
    }
    
    flag.at(now) = true;
    
    
    for(int64_t j = 0 ; j < data.at(now).size() ; j++){
      int temp = data.at(now).at(j);
      if(flag.at(temp) == true){
        continue;
      }
      
      q.push(temp);
      if(length.at(temp) == 0){
        length.at(temp) = length.at(now) + 1;
        to.at(temp) = now;
      }else if(length.at(temp) >= length.at(now) + 1){
        length.at(temp) = length.at(now) + 1;
        to.at(temp) = now;
      } 
    }
  }
  
  cout << "Yes" << endl;
  for(int64_t i = 2 ; i <= N ; i++){
    cout << to.at(i) << endl;
  }
}

Measured memory_bytes: 12172
#include <bits/stdc++.h>
#define pb push_back
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define db(x) (cerr << #x << ": " << (x) << '\n')
#define cps CLOCKS_PER_SEC
#define tests(t) int t; cin >> t; while(t--)
#define iceil(n, x) (((n) + (x) - 1) / (x))
#define ll long long
#define ld double
#define eb emplace_back
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define sz size()
#define all(v) (v).begin(), (v).end()
#define uni(v) sort(all(v)), (v).erase(unique(all(v)), (v).end())
#define fi first
#define se second
#define bitcount(x) __builtin_popcount(x)
#define PI acos(-1.0)
#define EPS 1e-9
#define mod 1000000007

#define par pair<int, int>
#define maxn 200005

using namespace std;
///All indexing is 0-based
using namespace __gnu_pbds;
template<class key, class cmp = std::less<key>>
using ordered_set = tree<key, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
///methods: find_by_order(k); & order_of_key(k);
///To make it an ordered_multiset, use pairs of (value, time_of_insertion)
///to distinguish values which are similar

int a,b,c;


int main()
{
    #ifdef acm
    freopen("a.in","r",stdin);
    #endif // acm
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    cin >> a >> b >> c;
    if(a+b+c>=22)
        cout << "bust\n";
    else
        cout << "win\n";



}


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

int main() {
  int h, w;
  cin >> h >> w;
  vector<vector<char>> a(h, vector<char>(w));
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      cin >> a.at(i).at(j);
    }
  }
  vector<bool> row(h, 0);//行のうち出力すべきものを保持する
  vector<bool> col(w, 0);//列のうち出力すべきものを保持する
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (a.at(i).at(j) == '#') {
        row.at(i) = 1;
        break;
      }
    }
  }
  for (int j = 0; j < w; j++) {
    for (int i = 0; i < h; i++) {
      if (a.at(i).at(j) == '#') {
        col.at(j) = 1;
        break;
      }
    }
  }
    
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (row.at(i) and col.at(j))
      cout << a.at(i).at(j);
    }
    if (row.at(i))
      cout << endl;
  }
}


Measured memory_bytes: 768
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif
//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long ll;
const int maxN = 5005;
const int mod = (int)1e9 + 7;
int mult(int a, int b) {
    return (1LL * a * b) % mod;
}
int sum(int a, int b) {
    int s = a + b;
    if (s >= mod) s -= mod;
    return s;
}
int sub(int a, int b) {
    int s = a - b;
    if (s < 0) s += mod;
    return s;
}
int n, a, b;
int dp[maxN][2][2];
int pw2[maxN];
int ans[maxN][2];
int real_dp[maxN];
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
//    freopen("input.txt", "r", stdin);
    cin >> n >> a >> b;
    if (a < b) swap(a, b);
    for (int i = 1; i < a; i++) {
        for (int x = 0; x < 2; x++) {
            for (int y = 0; y < 2; y++) {
                if (x == y) {
                    if (x == 0) {
                        dp[i][x][y] = 1;
                    }
                    if (x == 1 && i >= b) {
                        dp[i][x][y] = 1;
                    }
                }
                if (y == 1) {
                    for (int z = b; z < i; z++) {
                        dp[i][x][y] = sum(dp[i][x][y], dp[i - z][x][y ^ 1]);
                    }
                }
                else {
                    for (int z = 1; z < i; z++) {
                        dp[i][x][y] = sum(dp[i][x][y], dp[i - z][x][y ^ 1]);
                    }
                }
            }
        }
    }
    for (int i = 1; i <= n; i++) {
        real_dp[i] = dp[i][0][0];
    }
    pw2[0] = 1;
    for (int i = 1; i <= n; i++) pw2[i] = mult(2, pw2[i - 1]);
    for (int len = 1; len <= n; len++) {
        for (int en = 0; en < 2; en++) {
            if (en == 1) {
                if (len < b) {
                    ans[len][1] = 1;
                }
            }
            else {
                ans[len][0] = sum(real_dp[len], dp[len][1][0]);
            }
            for (int sz = 1; sz < len; sz++) {
                if (en == 1) {
                    if (sz < b) {
                        ans[len][1] = sum(ans[len][1], ans[len - sz][0]);
                    }
                }
                else {
                    ans[len][0] = sum(ans[len][0], mult(real_dp[sz], ans[len - sz][1]));
                }
            }
        }
    }
    for (int i = 1; i <= n; i++) {
        ans[n][1] = sum(ans[n][1], mult(ans[i][1], dp[n - i][0][1]));
    }
    cout << sub(pw2[n], sum(ans[n][0], ans[n][1]));
    return 0;
}

Measured memory_bytes: 3796
#include<iostream>
#include<vector>
#include<string>
#include<math.h>
#include<algorithm>
using namespace std;
#define USINT_MAX 4294967295

int main() {
	char s[100000];
	int n, a, b, temp = 0, temp2 = 0;
	cin >> n >> a >> b;
	cin >> s;
	for (int i = 0; i < n; i++) {
		if (s[i] == 'a') {
			if (temp < a + b) { cout << "Yes" << endl; temp++; }
			else cout << "No" << endl;
		}
		if (s[i] == 'b') {
			if (temp < a + b&&temp2 < b){ cout << "Yes" << endl; temp++; temp2++; }
			else cout << "No" << endl;
		}
		if (s[i] == 'c')cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
#include <ctime>
#include <unordered_map>
#include <stdlib.h>
using namespace std;
#define ll  long long int
#define mod 1000000007
#define modd 998244353
#define com(a,n) for(ll i=0;i<n;i++) cin>>a[i];
#define pri(a,n) for(ll i=0;i<n;i++) cout<<a[i]<<endl;
#define speed ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
/*__builtin_clz();
__builtin_ctz();
__builtin_popcount();*/
int main()
{
    speed;
    string s,t;
    cin>>s>>t;
    cout<<t+s<<"\n";
    cerr << "\nTime elapsed: " << 1000 * clock()/CLOCKS_PER_SEC << "ms\n";
}
 
 
 
 
 
// bool prime[100000];
 
// // int gcdExtended(int a, int b, int *x, int *y) ;
// ll modInverse(int a, int m) 
// { 
//     int x, y; 
//     int g = gcdExtended(a, m, &x, &y); 
//     // if (g != 1) 
//     //     cout << "Inverse doesn't exist"; 
//     // else
//     // { 
//         // m is added to handle negative x 
//         int res = (x%m + m) % m; 
//         return res; 
//     // } 
// } 
  
// // // C function for extended Euclidean Algorithm 
// int gcdExtended(int a, int b, int *x, int *y) 
// { 
//     // Base Case 
//     if (a == 0) 
//     { 
//         *x = 0, *y = 1; 
//         return b; 
//     } 
  
//     int x1, y1; // To store results of recursive call 
//     int gcd = gcdExtended(b%a, a, &x1, &y1); 
  
//     // Update x and y using results of recursive 
//     // call 
//     *x = y1 - (b/a) * x1; 
//     *y = x1; 
  
//     return gcd; 
// } 
// ll modu(ll x)
// {
//     if(x<0)
//     {
//         x+=mod;
//     }
//     else 
//     {
//         x=x%mod;
//     }
//     return x;
// }
 
// void SieveOfEratosthenes(int n) 
// { 
//     // Create a boolean aay "prime[0..n]" and initialize 
//     // all entries it as true. A value in prime[i] will 
//     // finally be false if i is Not a prime, else true. 
     
//     memset(prime, true, sizeof(prime)); 
  
//     for (int p=2; p*p<=n; p++) 
//     { 
//         // If prime[p] is not changed, then it is a prime 
//         if (prime[p] == true) 
//         { 
//             // Update all multiples of p greater than or  
//             // equal to the square of it 
//             // numbers which are multiple of p and are 
//             // less than p^2 are already been marked.  
//             for (int i=p*p; i<=n; i += p) 
//                 prime[i] = false; 
//         } 
//     } 
//     prime[1]=false;
  
//     // Print all prime numbers 
//     // for (int p=2; p<=n; p++) 
//     //    if (prime[p]) 
//     //       cout << p << " "; 
// } 
// ll power(ll x, unsigned ll y, ll p) 
// { 
//     ll res = 1;      // Initialize result 
  
//     x = x % p;  // Update x if it is more than or  
//                 // equal to p 
  
//     while (y > 0) 
//     { 
//         // If y is odd, multiply x with result 
//         if (y & 1) 
//             res = (res*x) % p; 
  
//         // y must be even now 
//         y = y>>1; // y = y/2 
//         x = (x*x) % p;   
//     } 
//     return res; 
// } 

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<ll>;
using vs = vector<string>;
#define  rep(i,n) for(ll i = 0; i < (n); ++i)
#define  red(i,n) for(ll i = (n)-1; i >= 0; --i)
#define  all(a)   begin(a),end(a)
#define  pb(a)    push_back(a)
#define  yn(a)    cout << ( (a)?"Yes\n":"No\n" );
inline ll gcd(ll a,ll b) { return b?gcd(b,a%b):a; }
const ll INF = 1e9+9, LINF = 1e18;


int main()
{
    ll n,x=0;
    cin>>n;
    string s=to_string(n);
    for(char c:s)x+=c-'0';
    yn(!(n%x));
    return 0;
}


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

#define rep(i, a, b) for ( int i = (a); i < (b); i++ )
#define per(i, a, b) for ( int i = (b)-1; i >= (a); i--)
#define pb push_back
#define bg begin()
#define en end()

using namespace std;

typedef long long ll;

static const long long MAX = 100100;
static const long long MOD = 1000000007;

long long ans = 1;
int N, M;
bool isprime[1000000005];
vector<int> prime, v;
map<int, int> m;

long long fac[MAX],   // i!    mod p iの階乗
          finv[MAX],  // i!^-1 mod p iの階乗の逆元
          inv[MAX];   // i^-1  mod p iの逆元 inverse


void eratosthenes_seive(int n) {

  for (int i = 2; i*i <= n+1; i++) isprime[i] = true;

    for (int i = 2; i*i <= n+1; i++) {
      if ( isprime[i] == true ) {
        prime.pb(i);
        for (int j = i + i; j*j <= n+1; j += i) {
            isprime[j] = false;
        };
      }
    }
    return;
}

void prime_factrization(int n) {

    for (int i = 0; i < prime.size(); i++) {
        if (n % prime[i] == 0) {
            v.pb(prime[i]);
            while (n % prime[i] == 0) {
                m[prime[i]]++;
                n /= prime[i];
            }
        }
    }
    if (n > 1) {
      v.pb(n);
      m[n]++;
    }
  
  return;
}

 
void comb_init() {
    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 combination(long long n, long long k) {
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n-k] % MOD) % MOD;
}


int main(void) {
    scanf("%d %d", &N, &M);

   
    eratosthenes_seive(M);
    prime_factrization(M);
    comb_init();
    
    for (int i = 0; i < v.size(); i++) {
        ans *= combination(m[v[i]] + N - 1LL, m[v[i]]*1LL);
        ans %= MOD;
      }
    
    
    printf("%lld\n", ans);
    return 0;
}
 


Measured memory_bytes: 6400
using System;

namespace ABC131C
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Console.ReadLine().Split();
            var A = long.Parse(input[0]) - 1L;
            var B = long.Parse(input[1]);
            var C = long.Parse(input[2]);
            var D = long.Parse(input[3]);

            var l = Lcm(C, D);
            var underB = B - B / C - B / D + B / l;
            var lessA = A - A / C - A / D + A / l;

            Console.WriteLine(underB - lessA);
        }

        static long Gcd(long m, long n)
        {
            long tmp;
            while (m % n != 0)
            {
                tmp = n;
                n = m % n;
                m = tmp;
            }
            return n;
        }

        static long Lcm(long m, long n)
        {
            return m * n / Gcd(m, n);
        }
    }
}


Measured memory_bytes: 11092
package main

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

func main() {

	sc := bufio.NewScanner(os.Stdin)
	sc.Scan()
	in := sc.Text()

	v := strings.Split(in, " ")
	a, _ := strconv.Atoi(v[0])
	b, _ := strconv.Atoi(v[1])

	fmt.Print(a * b)
	fmt.Print(" ")
	fmt.Println(a*2 + b*2)
}



Measured memory_bytes: 1072
#include<string>
#include<string.h>
#include<map>
#include<set>
#include<vector>
#include<stdio.h>
#include<math.h>
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
int cnt;
int main()
{
int X,A,B;
cin>>X>>A>>B;
int m=X-A;
cnt=m/B;
m=m-cnt*B;
cout<<m;
system("pause");
return 0;
}

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

using namespace std;

main(){
  int n, m, p, sum, input[100];
  while(cin >> n >> m >> p && (n|m|p)){
    sum = 0;
    for(int i=0;i<n;i++){
      cin >> input[i];
      sum += input[i] * 100;
    }
    int ans = sum *(100-p) / 100;
    if(input[m-1]) ans /= input[m-1];
    else ans = 0;
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 0
N, D, A = map(int, input().split())
XH = [[0, 0] for _ in range(N)]

for i in range(N):
    XH[i][0], XH[i][1] = map(int, input().split())

XH.sort()
# XH

ans = 0
P = 0
hist = []
j = 0
for i in range(N):
    X, H = XH[i]
    while True:
        if j >= len(hist):
            break
        if hist[j][0] >= X:
            break
        if hist[j][0] < X:
            P -= hist[j][1]
            j += 1
    
    if H - P > 0:
        if (H - P) % A == 0:
            bomb = (H - P) // A
        else:
            bomb = (H - P) // A + 1
        ans += bomb
        P += bomb * A
        hist.append((X + 2 * D, bomb * A))
    

print(ans)

Measured memory_bytes: 78324
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const int inf = 1e9;
const ll INF = 1e18;
const double pi = 3.14159265358979323846;
#define rep(i,n) for(ll i=0;i<n;i++)

int main(){
	int n;cin>>n;
	pair<int,int> t[n];
	rep(i,n) cin>>t[i].second>>t[i].first;

	sort(t,t+n);

	int s[n+1];s[0]=0;
	rep(i,n) s[i+1]=s[i]+t[i].second;

	bool ans=1;
	rep(i,n){
		if(s[i+1]>t[i].first){
			cout<<"No"<<"\n";
			return 0;
		}
	}
	cout<<"Yes"<<"\n";
	
}

Measured memory_bytes: 2560
#include<iostream>
#include<string>
#include<algorithm>    
#include<cmath>
#include<map>
#include<vector>
#include<math.h>
#include<stdio.h>
#include<stack>
#include<queue>
#include<tuple>
#include<cassert>
#include<set>
//#include<bits/stdc++.h>
using ll = long long;
using namespace std;
const ll INF = 10000000000000000;
const ll mod = 1000000007;
signed main() {
    ll n, m, a, b, cnt = 0, ans = 1; cin >> n;
	for (int h = 0; h < n; h++) {
		cin >> a >> b;
		if (cnt < a) { cnt = a; ans = a + b; }
	}
	cout << ans << endl;
	cin >> n; return 0;
}

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

int main() {
  ll n, c;
  cin >> n >> c;
  vector<pair<ll, ll>> sushi(n);  // 登場位置、カロリー
  for (ll i = 0; i < n; i++) {
    ll x, v;
    cin >> x >> v;
    sushi[i] = make_pair(x, v);
  }

  // 時計回り、半時計回りでi番目まで見た時の最大スコアをメモ
  vector<ll> to1(n + 1), to2(n + 1), ha1(n + 1), ha2(n + 1);
  ll sowa = 0;
  for (int i = 0; i < n; i++) {
    sowa += sushi[i].second;
    to1[i + 1] = max(to1[i], sowa - sushi[i].first);
    to2[i + 1] = max(to2[i], sowa - sushi[i].first * 2);
  }
  sowa = 0;
  for (int i = n; i > 0; i--) {
    sowa += sushi[i - 1].second;
    ha1[i - 1] = max(ha1[i], sowa - (c - sushi[i - 1].first));
    ha2[i - 1] = max(ha2[i], sowa - (c - sushi[i - 1].first) * 2);
  }

  // 上で求めたものを使って答えを求める
  ll ans = 0;
  for (int i = 0; i <= n; i++) {
    ans = max(ans, to1[i] + ha2[i]);
    ans = max(ans, ha1[i] + to2[i]);
  }

  cout << ans << endl;
}


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

typedef long long ll;

using namespace std;


int n,name_l,ans=0,in_l;
char name[102],in[1020];

int solve(char a[]){
    for(int j=0;in[j]!='\0';j++){
        if(name[0]!=in[j]) continue;
        
        for(int k=j+1;in[k]!='\0';k++){
            if(name[1]!=in[k]) continue;
            
            for(int l=2;;l++){
                if(name_l==l)
                    return 1;
                if(j+(k-j)*l>=in_l)
                    break;
                if(in[j+(k-j)*l]!=name[l])
                    break;
            }
        }
    }
    return 0;
}

int main(){
    scanf("%d%s",&n,name);
    
    for(name_l=0;name[name_l]!='\0';name_l++);
    
    for(int i=0;i<n;i++){
        scanf("%s",in);
        for(in_l=0;in[in_l]!='\0';in_l++);
        ans+=solve(in);
    }
    
    printf("%d\n",ans);
    
    return 0;
}

Measured memory_bytes: 1192
#include <iostream>
#include <vector>
#include <stack>
#include <string>
#include <cmath>
#include <sstream>
#include <queue>
#include <map>
#include <cstring>
#include <unordered_set>
#include <algorithm>
#include <iomanip>
#include <unordered_map>
#include <random>
using namespace std;


int main() {
    int n;
    int oddNums = 0;
    cin >> n;
    vector<int> nums(n);
    for (int i = 0; i < n; ++i) {
        cin >> nums[i];
        oddNums += (nums[i] & 1);
    }
    string answer = (oddNums & 1) ? "NO" : "YES";
    cout << answer << endl;
    return 0;
}

Measured memory_bytes: 640
import sys
S = input()
A = [int(a) for a in list(S)]
N = 4
crt = 7

for i in range(2**(N-1)):
  i_ = i
  j = 1
  tmp = A[0]
  while j < N:
    if i_ % 2 == 0:
      tmp += A[j]
    else:
      tmp -= A[j]
    i_ = i_>>1
    j += 1
  #print(tmp, i) 
  if tmp == crt:
    T = str(A[0])
    i_ = i
    j = 1
    while j < N:
      if i_ % 2 == 0:
        T += "+"
      else:
        T += "-"
      T += str(A[j])
      i_ = i_>>1
      j += 1
    T += "=7"
    print(T)
    sys.exit()
    

Measured memory_bytes: 61924
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <complex>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <cstring>

#define REP(i,x) for(int i=0 ; i<(int)(x) ; i++)
#define ALL(x) (x).begin(),(x).end()
#define LL long long

using namespace std;

int main(){
    int N;
    cin >> N;
    vector<LL> A(3*N);
    REP(i, 3*N)cin >> A[i];
    multiset<LL> left;
    multiset<LL> right;
    multiset<LL> erased;
    LL left_sum = 0;
    LL right_sum = 0;
    for(int i=0; i<N; i++){
        left_sum += A[i];
        left.insert(A[i]);
    }
    for(int i=N; i<3*N; i++){
        right_sum += A[i];
        right.insert(A[i]);
    }
    REP(i, N){
        multiset<LL>::reverse_iterator it = right.rbegin();
        right_sum -= *it;
        erased.insert(*it);
        right.erase((++it).base());
    }
    LL res = left_sum - right_sum;
    for(int i=N; i<2*N; i++){
        left_sum += A[i];
        left.insert(A[i]);
        multiset<LL>::iterator it = left.begin();
        left_sum -= *it;
        left.erase(it);

        if(erased.count(A[i])==0){
            right_sum -= A[i];
            multiset<LL>::iterator jt = erased.begin();
            right_sum += *jt;
            erased.erase(jt);
        }else{
            erased.erase(erased.find(A[i]));
        }
        // cerr << left_sum << " " << right_sum << endl;

        res = max(res, left_sum - right_sum);
    }
    cout << res << endl;

    return 0;
}


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



int main()
{
  int a, b, c;
  cin >> a >> b >> c;
  int cnt[11] = {0};
  cnt[a]++;
  cnt[b]++;
  cnt[c]++;
  if(cnt[5] == 2 and cnt[7] == 1) {
      cout << "YES";
  } else {
      cout << "NO";
  }
  
}

Measured memory_bytes: 3592
import numpy as np


def solve(s):
    MOD = 10 ** 9 + 7
    dp = np.zeros(13, dtype=np.int64)
    dp[0] = 1
    idx = np.zeros(13, dtype=np.int8)
    for i in range(13):
        idx[i * 10 % 13] = i
    window = np.ones(10, dtype=np.int8)
    for c in s:
        if c == '?':
            tdp = dp[idx]
            ndp = np.concatenate([tdp[4:], tdp])
            dp = np.convolve(ndp, window, mode='valid') % MOD
        else:
            dp = np.roll(dp[idx], int(c))
    return dp[5]


s = input()
print(solve(s))


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

const ll mod = 1e9+7;

ll mpow(ll x,ll n){
    ll res = 1;
    while(n != 0){
        if(n&1) res = res*x % mod;
        x = x*x % mod;
        n = n >> 1; 
    }
    return res;
}
ll fac(ll i){
    static ll fatorial[200000+1]={};

    if(fatorial[i]) return fatorial[i];
    else if(i==0) return fatorial[0] = 1;
    else return fatorial[i] = fac(i-1)*i % mod;
}
ll ifac(ll i){
    static ll ifactorial[200000+1]={};

    if(ifactorial[i]) return ifactorial[i];
    else if(i==0) return ifactorial[0] = 1;
    else return ifactorial[i] = ifac(i-1)*mpow(i,mod-2) % mod;
}
ll comb(ll a,ll b){
    if(a==0 && b==0) return 1;
    if(a<b || a<0) return 0;
    ll tmp = ifac(a-b)*ifac(b) % mod;
    return tmp*fac(a) % mod;
}

ll sum_manh(ll n,ll m,ll k){
    ll res = 0;

    for(int d = 1;d <= n-1;d ++){
        res = (res + (d*(n-d)%mod)*mpow(m,2)*comb(n*m-2,k-2))%mod;
    }
    return res;
}

int main(){
    ll n,m,k;
    cin >> n >> m >> k;

    cout << (sum_manh(n,m,k) + sum_manh(m,n,k))%mod << endl;

    return 0;
}

Measured memory_bytes: 6528
local n = io.read("*n")
local p = {0}
for i = 2, n do
  p[i] = io.read("*n")
end
local base = {}
local t = {}
local x = {}
for i = 1, n do
  base[i] = 0
  t[i] = {}
  x[i] = io.read("*n")
end
local valid = true
for i = n, 1, -1 do
  local tgt = x[i] - base[i]
  if tgt < 0 then
    valid = false
    break
  end
  -- get highest value y where dp[y] == true
  local dp = {}
  for j = 1, tgt do
    dp[j] = false
  end
  local sum = base[i]
  for j = 1, #t[i] do
    local tv = t[i][j]
    sum = sum + tv
    for k = tgt - tv, 1, -1 do
      if dp[k] then dp[k + tv] = true end
    end
    if tv <= tgt then dp[tv] = true end
  end
  local r = 0
  for j = tgt, 1, -1 do
    if dp[j] then r = j break end
  end
  if 1 < i then
    local v1 = x[i] -- base[i] + r <= x[i]. "bese[i] + r" became x[i].
    local v2 = sum - base[i] - r
    local parent = p[i]
    if v2 < v1 then v1, v2 = v2, v1 end
    base[parent] = base[parent] + v1
    if v1 < v2 then table.insert(t[parent], v2 - v1) end
  end
end
print(valid and "POSSIBLE" or "IMPOSSIBLE")


Measured memory_bytes: 1704
n, A, B, C = map(int, input().split())
l = [int(input()) for _ in range(n)]

from collections import deque

ans = float('inf')

def dfs(i, abc, cost):
    global ans
    stack = deque([[i, abc, cost]])
    while stack:
        i, abc, cost = stack.pop()
        a, b, c = abc
        if i == n:
            if a * b * c:
                ans = min(ans, abs(A-a) + abs(B-b) + abs(C-c) + cost*10)
            continue
        for e in (0, 1, 2, 3):
            n_cost = cost
            n_abc = abc[:]
            if e < 3:
                if abc[e]:
                    n_cost += 1
                n_abc[e] += l[i]
            stack.append([i + 1, n_abc, n_cost])

dfs(0, [0,0,0], 0)

print(ans)

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

vector<bool> primeVector() {
  vector<bool> prime(100001, true);
  prime[0] = false;
  prime[1] = false;
  for(int i=2;i<100001;i++) {
    if(prime[i]) {
      for(int j=i+i;j<100001;j+=i) prime[j] = false;
    }
  }

  return prime;
}

int main() {
  vector<int> like2017(0);
  vector<bool> prime = primeVector();
  for(int i=3;i<100001;i++) {
    if(prime[i] && prime[(i + 1) / 2]) like2017.push_back(i);
  }

  int Q;
  cin >> Q;
  for(int i=0;i<Q;i++) {
    int l, r;
    cin >> l >> r;
    int start = like2017.size();
    int end = like2017.size();
    for(int j=0;j<like2017.size();j++) {
      if(like2017[j] >= l && start == like2017.size()) start = j;
      if(r < like2017[j]) {
        end = j;
        break;
      }
    }
    cout << end - start << endl;
  }
}

Measured memory_bytes: 640
#include<queue>
#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;
int main()
{
    int n,m;
    cin>>n>>m;
    if(n==1&&m==0)
    {cout<<0;
    return 0;
	}
    int temp=1;
    int a[10];
    memset(a,-1,sizeof(a));
    for(int i=0;i<m;i++)
    {
    	int s,c;
    	cin>>s>>c;
    	if(a[s]!=-1&&a[s]!=c)
    	{
    		cout<<-1;
    		return 0;
		}
		else
		a[s]=c;
	}
    if(n==1)
    {
    	if(a[1]==-1)
    	{
    		cout<<0;
    		return 0;
		}
		else
		{
			cout<<a[1];
			return 0;
		}
	}
	else
	{
		if(a[1]==0)
		{cout<<-1;
		return 0;
		}
		if(a[1]==-1)
		cout<<1;
		else
		cout<<a[1];
		for(int j=2;j<=n;j++)
		{
			if(a[j]!=-1)
			cout<<a[j];
			else
			cout<<0;
		}
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define lli long long int
using namespace std;
#define S second
#define F first
#define pb push_back 
#define M1 1000000007
#define M2 998244353
#define plli pair<lli,lli>
#define setit set<lli>::iterator seti
#define mapit map<lli,lli> ::iterator mapi
#define MP make_pair
#define MT make_tuple
// map      iterator->first  iterator.first
// map      mp[key]=value
// set      *s.begin()
// vector   v[j]=value
// pair     p.first p.second
// vector of pairs v[j].first v[j].second
// tuple    get<index>(tuple_name)
// vector of tuples get<index>(v[j])  sort(v.begin(),v.end())
//priority queue .top() .pop() .push()
// __gcd(x,y)
#define fr(j,a,b) for(j=a;j<b;j++)


int power(int x, unsigned int y, int p)  
{    int res = 1;    
     x = x % p;
     if (x == 0) return 0;
     while (y > 0)  
     {  if (y & 1)  
        res = (res*x) % p;  
        y = y>>1;
        x = (x*x) % p;  
     }  
    return res;  
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    lli t,i,m,j,n,x,k,f,g,q,r,w,l,a,b,c;
    cin>>a>>b>>c;
    cout<<c<<" "<<a<<" "<<b;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdint>
#include<cstdlib>
template<typename T>
void fin(T const& t){ std::cout << t << std::endl; exit(0); }

// input
uint64_t getZ() {
  uint64_t v = 0; int c;
  while((c = getchar_unlocked()) >= '0') v=v*10+c-'0';
  return v;
}

int const MAXN = 2500;
int const INF = 1e9+5;
int N, M, P;
struct edge{
  int cost, from, to;
  edge(int f = 0, int t = 0, int c = 0): cost(c), from(f), to(t) {}
};
std::vector<edge> G;
int d[MAXN];
bool valid[MAXN];

int main() {
  N = getZ(); M = getZ(); P = getZ();
  for(int i = 0; i < M; ++i) {
    int f = getZ()-1, t = getZ()-1, c = getZ()-P;
    G.emplace_back(f, t, c);
  }
  // valid nodes
  std::fill_n(valid, N, false);
  valid[N-1] = true;
  for(int i = 0; i < N-1; ++i) for(auto& e: G) valid[e.from] |= valid[e.to];
  std::fill_n(d, N, -INF);
  d[0] = 0;
  for(int i = 0; i < N; ++i) for(auto& e: G) {
    if(!valid[e.to]) continue;
    if(d[e.from] == -INF) continue;
    int nd = d[e.from] + e.cost;
    if(d[e.to] < nd) {
      if(i == N-1) fin(-1);
      d[e.to] = nd;
    }
  }
  int ans = std::max(d[N-1], 0);
  fin(ans);
  return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <iomanip>
#define ld long double
using namespace std;
const int maxn = 3000;
const ld pi = 4.0*atan(1.0);
int n,l;
int t[maxn+1];
struct pt
{
	ld x;
	ld y;
};
pt centroid;

pt add(pt x,pt y)
{
	return {x.x+y.x,x.y+y.y};
}

int main()
{
	ios_base::sync_with_stdio(0);
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	cin >> n >> l;
	for (int i=1; i<=n; i++)
		cin >> t[i];
	sort(t+1,t+1+n);
	
	for (int i=1; i<=n; i++)
	for (int j=i+1; j<=n; j++)
	{
		ld midAngle = 2*pi*((ld) t[i]+(ld) t[j])*0.5/(ld) l;
		pt midPoint = {cos(midAngle),sin(midAngle)};
		centroid.x+=midPoint.x*(n-(j-i+1));
		centroid.y+=midPoint.y*(n-(j-i+1));
		
		midAngle+=pi;
		midPoint = {cos(midAngle),sin(midAngle)};
		
		centroid.x+=midPoint.x*(j-i-1);
		centroid.y+=midPoint.y*(j-i-1);
	}
	
	// centroid becomes orthocenter
	//centroid.x*=(1.0/3.0);
	//centroid.y*=(1.0/3.0);
	
	centroid.x/=((ld) n*((ld) n-1.0)*((ld) n-2.0)/6.0);
	centroid.y/=((ld) n*((ld) n-1.0)*((ld) n-2.0)/6.0);
	
	cout << setprecision(20) << fixed << centroid.x << ' '<< centroid.y << '\n';
	
	
	
	return 0;
}


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

typedef long long ll;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define each(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); ++itr)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second

struct state{ int r,s,jump; };

const ll INF=12345678901234LL;
// i??????, j????????????, k??????????£???°????????£???????????¨
ll dp[150][10][150];

int k[150];
int x[150][10], d[150][10];

int main()
{
    int n,m;
    while(scanf(" %d %d", &n, &m),n)
    {
        rep(i,n)
        {
            scanf(" %d", &k[i]);
            rep(j,k[i]) scanf(" %d %d", &x[i][j], &d[i][j]);
        }

        fill(dp[0][0],dp[150][0],INF);

        queue<state> que;
        // 0??????
        rep(i,k[0])
        {
            que.push(state{0,i,0});
            dp[0][i][0]=0;
        }
        // 1??????
        if(m>0)
        {
            rep(i,k[1])
            {
                que.push(state{1,i,1});
                dp[1][i][1]=0;
            }
        }

        ll ans=INF;

        while(!que.empty())
        {
            state now=que.front();
            que.pop();

            if(now.r == n-1 || (now.r == n-2 && now.jump < m))
            {
                ans = min(ans, dp[now.r][now.s][now.jump]);
                continue;
            }

            // ??????????????£??????
            rep(i,k[now.r+1])
            {
                ll add=(d[now.r][now.s]+d[now.r+1][i])*abs(x[now.r][now.s]-x[now.r+1][i]);

                if(dp[now.r+1][i][now.jump] > dp[now.r][now.s][now.jump]+add)
                {
                    dp[now.r+1][i][now.jump] = dp[now.r][now.s][now.jump]+add;
                    que.push(state{now.r+1,i,now.jump});
                }
            }

            // ???????£???°???????????£??????
            if(now.jump<m)
            {
                rep(i,k[now.r+2])
                {
                    ll add=(d[now.r][now.s]+d[now.r+2][i])*abs(x[now.r][now.s]-x[now.r+2][i]);

                    if(dp[now.r+2][i][now.jump+1] > dp[now.r][now.s][now.jump]+add)
                    {
                        dp[now.r+2][i][now.jump+1] = dp[now.r][now.s][now.jump]+add;
                        que.push(state{now.r+2,i,now.jump+1});
                    }
                }
            }
        }

        printf("%lld\n", ans);
    }
    return 0;
}

Measured memory_bytes: 5020
//بِسْمِ ٱللَّٰهِ ٱلرَّحْمَٰنِ ٱلرَّحِيمِ
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef double db;

#define endl "\n"

const int MOD = 1000000007;


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

    int a, b, sum = 0;
    cin >> a >> b;
    int ara[a];
    for(int i = 0 ; i < a ; i++)cin >> ara[i];
    sort(ara,ara+a);
    for(int i = (a - b) ; i < a; i++){
        sum += ara[i];
    }
    cout << sum << endl;

    return 0;
}


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

using namespace std;

int main(void)
{
    int n, l;
    int sum = 0;
    cin >> n >> l;
    int r = l + n - 1;
    int eat;

    if(l >= 0) eat = l;
    else if(r <= 0) eat = r;
    else eat = 0;

    cout << (r+l)*(r-l+1)/2 - eat << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <bits/stdc++.h>
#include <queue>
#include <math.h>
#include <bitset>
#define INF 100000000000
#define N 200000
#define ll long long
using namespace std;

int main(){
    ll n,m;
    cin>>n>>m;
    
    vector<pair<int,int>> data[n+1];
    
    for (ll i=1; i<=m; i++){
        ll p,q;
        cin>>p>>q;
        data[p].push_back(make_pair(q,i));
    }
    
    int b[m+1];
    int c[m+1];
    
    for (ll i=1; i<=n; i++){
        sort(data[i].begin(),data[i].end());
        for (ll j=0; j<data[i].size(); j++){
            b[data[i][j].second]=i;
            c[data[i][j].second]=j+1;
        }
    }
    
    for (int i=1; i<=m; i++){
        printf("%06d%06d\n", b[i], c[i]);
    }
}

Measured memory_bytes: 7808
from collections import deque

s = deque(input().strip())
q = int(input())

reverseFlag = 0

for _ in range(q):
    query = input().strip()
    if query[0] == "1":
        reverseFlag = 1 - reverseFlag
    else:
        lf = reverseFlag + int(query[2])
        if lf % 2 == 0:
            s.append(query[4])
        else:
            s.appendleft(query[4])

if reverseFlag == 1:
    s.reverse()
print("".join(s))


Measured memory_bytes: 76120
#include<iostream>
using namespace std;
int main(){
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	int i=0;
	while(a>0&&c>0){
		if(i%2!=0){
			a=a-d;
		}
		else{
			c=c-b;
		}
		i++;
	}
	if(a<=0){
		cout<<"No";
	}
	else{
		cout<<"Yes";
	}
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, s, e) for (ll (i) = (s); (i) < (e); ++(i))
#define per(i, s, e) for (ll (i) = (s); (i) >= (e); --(i))
#define all(x) x.begin(),x.end()

void dfs(ll root, ll self, vector<vector<ll>> &to, vector<ll> &res) {
  for (ll u : to[self]) {
    if (u == root) continue;
    res[u] += res[self];
    dfs(self, u, to, res);
  }

}

int main(void) {
  ll n, q; cin >> n >> q;
  vector<vector<ll>> to(n);
  rep(i, 0, n-1) {
    ll a, b; cin >> a >> b;
    --a; --b;
    to[a].push_back(b);
    to[b].push_back(a);
  }

  vector<ll> ans(n, 0);
  rep(i, 0, q) {
    ll p, x; cin >> p >> x;
    --p;
    ans[p] += x;
  }

  dfs(-1, 0, to, ans);

  rep(i, 0 , n) {
    cout << ans[i] << " ";
  }
  cout << endl;
}


Measured memory_bytes: 30464
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(a); (i)<(b); ++(i))
#define rFor(i, a, b) for(int (i)=(a)-1; (i)>=(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef pair<int, lint> pil;
typedef pair<lint, int> pli;
template<class T>bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}
template<class T>bool chmin(T &a, const T &b){if(a>b){a=b; return true;} return false;}

constexpr lint mod = 1e9+7;
constexpr lint INF = mod*mod;
constexpr int MAX = 100010;

int main(){
        vector<char> c[10];
        c[1]={'.', ',', '!', '?', ' '};
        char cur='a';
        For(i, 2, 10){
                rep(j, i==7 || i==9 ? 4 : 3){
                        c[i].push_back(cur);
                        ++cur;
                }
        }
        int q;
        scanf("%d", &q);
        while(q--){
                string s;
                cin>>s;
                int n=s.size();
                string t;
                int l=0;
                while(l<n){
                        if(s[l]=='0'){
                                ++l;
                                continue;
                        }
                        int r=l;
                        while(r<n && s[l]==s[r]) ++r;
                        t+=c[s[l]-'0'][(r-l-1)%(int)c[s[l]-'0'].size()];
                        l=r;
                }
                cout << t << "\n";
        }
}


Measured memory_bytes: 3208
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
#define REP(i,s,n) for(int i = s; i < n; i++)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
using Graph = vector<vector<int>>;
int main(){
  int n;
  cin >> n;
  int ac = 0,wa = 0,tle = 0,re = 0;
  rep(i,n){
    string tmp;
    cin >> tmp;
    if(tmp == "AC")ac++;
    else if(tmp == "WA")wa++;
    else if(tmp == "TLE")tle++;
    else re++;
  } 
  cout << "AC x " << ac << endl;
  cout << "WA x " << wa << endl;
  cout << "TLE x " << tle << endl;
  cout << "RE x " << re << endl;
  return 0;
}


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

					#define mp make_pair
					#define pb push_back
					#define sqr(x) (x) * (x)
					#define sors(s) sort(s.begin(), s.end())
					#define sz(s) s.size()
					#define B begin()
					#define E end()
					#define F first
					#define S second
					#define I insert
					#define N 222222
					#define M 1000000007
					
					using namespace std;
					typedef long long ll;
					typedef vector<int> vi;
					typedef pair<int,int> pii;
					typedef set<int> si;
					typedef set<string> ss;
					typedef multiset<int> mi;
					typedef map<string, int> msi;
     				typedef vector<pair<int, int>> vii;
     				
					int n; string s, x;
					int main()
					{	
                      cin >> n >> s;
                      for (int i = 0; i < sz(s); i ++)
                      {
                        if (s[i] != s[i + 1])
                          x += s[i];
                      }				
                      cout << sz(x);
					}

Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <vector>
#include <deque>

#define int long long
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPS(i,n) for(int i=1, i##_len=(n); i<=i##_len; ++i)

#define INF (1e9)

using namespace std;

int K;

struct Edge
{
    int to, cost;
};

typedef pair<int, int> P;

int dist[100001];
vector<Edge> ve[100001];

signed main()
{
    cin >> K;

    REP(i, K)
    {
        Edge e1;
        e1.to = (i+1) % K;
        e1.cost = 1;
        ve[i].push_back(e1);

        Edge e2;
        e2.to = (i*10) % K;
        e2.cost = 0;
        ve[i].push_back(e2);
    }

    REP(i, K) dist[i] = INF;
    dist[1] = 1;

    deque<P> d;
    d.push_front(P(1,0));
    while (!d.empty())
    {
        P p = d.front();
        d.pop_front();
        int v = p.first;
        if (dist[v] < p.second) continue;
        REP(i, ve[v].size())
        {
            Edge& e = ve[v][i];
            if (dist[e.to] > dist[v] + e.cost)
            {
                dist[e.to] = dist[v] + e.cost;
                if (e.cost == 1) d.push_back(P(e.to, dist[e.to]));
                if (e.cost == 0) d.push_front(P(e.to, dist[e.to]));
            }
        }
    }

    cout << dist[0] << endl;

    return 0;
}

Measured memory_bytes: 8832