akhauriyash/Code-Regression huggingface dataset:
//参考：https://qiita.com/DaikiSuyama/items/9dba963ba74396b9b7fd
//インクルード(アルファベット順)
#include <algorithm>     //sort,二分探索,など
#include <bitset>        //固定長bit集合
#include <cmath>         //pow,logなど
#include <complex>       //複素数
#include <deque>         //両端アクセスのキュー
#include <functional>    //sortのgreater
#include <iomanip>       //setprecision(浮動小数点の出力の誤差)
#include <iostream>      //入出力
#include <iterator>      //集合演算(積集合,和集合,差集合など)
#include <map>           //map(辞書)
#include <numeric>       //iota(整数列の生成),gcdとlcm(c++17)
#include <queue>         //キュー
#include <set>           //集合
#include <stack>         //スタック
#include <string>        //文字列
#include <unordered_map> //イテレータあるけど順序保持しないmap
#include <unordered_set> //イテレータあるけど順序保持しないset
#include <utility>       //pair
#include <vector>        //可変長配列

using namespace std;
typedef long long ll;

//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPD(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i <= (ll)(b); i++)
#define FORD(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 INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 1000000007    //10^9+7:合同式の法
#define MAXR 100000       //10^5:配列の最大のrange(素数列挙などで使用)
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define FIR first    //pairの一つ目の要素
#define SEC second   //pairの二つ目の要素

signed main()
{
    //入力の高速化用のコード
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    ll A, B, C, X, Y;
    cin >> A >> B >> C >> X >> Y;

    ll ans = 0;
    if (A + B > 2 * C)
    {
        ans += 2 * C * min(X, Y);

        if (X > Y)
        {
            ans += A > 2 * C ? 2 * C * (X - Y) : A * (X - Y);
        }
        else
        {
            ans += B > 2 * C ? 2 * C * (Y - X) : B * (Y - X);
        }
    }
    else
    {
        ans = A * X + B * Y;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3588
import numpy as np

N = int(input())
A = [list(map(int, input().split())) for l in range(2)]

col_1 = np.zeros(N)
col_1[0] = A[0][0]
col_2 = np.zeros(N)
col_2[N-1] = A[1][-1]
for i in range(1,N):
  col_1[i] = col_1[i-1] + A[0][i]
  col_2[N-1-i] = col_2[N-i] + A[1][N-1-i]
  
solve = []
for i in range(N):
  solve.append(col_1[i] + col_2[i])
  
ans = int(max(solve))
print(ans)

Measured memory_bytes: 12504
//____________________________________________________________________\\
  //________________________________NAMAN_________________________________\\
 //________________________________TALAYCHA________________________________\\
//__________________________________________________________________________\\

#include <bits/stdc++.h>
#define ll long long
#define what_is(x)  cerr << #x << " is " << x << endl;
#define pmin priority_queue <int, vector<int>, greater<int> >
#define pmax priority_queue <int>
typedef long double ld;
#define sz(a) int((a).size())
 #define tr(container, it) \
for(typeof(container.begin()) it = container.begin(); it != container.end(); it++)
#define pb push_back
#define ppb pop_back
#define endl '\n'
#define mii map<ll , ll >
#define mis map<ll int, string>
#define msi map<string, ll int>
#define pii pair<ll int, ll int>
#define vi vector<ll>
#define st set<ll>
#define vii vector<pair<ll int, ll int>>
#define vs vector<string>
#define all(a) (a).begin(), (a).end()
#define F first
#define S second
#define mp make_pair
#define INF (1ll << 60)
#define DEBUG    cerr<<"/n>>>I'm Here<<</n"<<endl;
#define rep(i, a, b )   for (ll i = a; i < b; i++)
#define tep(i, a, b )   for (ll i = a; i < b; i = i + 2)
#define rrep(i, a, b)  for (ll i = a; i >= b; i--)
#define bs binary_search
#define mp make_pair
#define present(c, x) ((c).find(x) != (c).end())
#define cpresent(c, x) (find(all(c), x) != (c).end())
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll lcm(ll a, ll b) { return a * (b / gcd(a, b)); }
#define N 200200
#define mod 998244353


#define ios                                                                    \
  ios_base::sync_with_stdio(false);                                            \
cin.tie(0);                                                                  \
cout.tie(0);

using namespace std;


 ll fun (ll a,ll b , int m )
 {
   if(b==0)
   return 1;
   else if(b%2==0)
   {
     return fun((a*a)%m,b/2,m);
   }
   else
   return a*fun((a*a)%m,(b-1)/2,m)%m;
 
 }
 

 //___________________________________________________________________________
//-------------------------START----------------------------------------------

double s=0,d=0;


void solve()
{
  ll n,mi=INT_MIN,y,x1,y1;
int x;
 long long  m;
 long double z;
 cin>>x>>y;
 //cout<<x<<' '<<y<<endl;
x1=( long long)(( long long)(x)*(long long)(x));
y1=( long long)(( long long)(y)*(long long)(y));
 m=( long long)(( long long)(x1)+(long long)(y1));
 z=(double)(sqrt(m));
 //cout<<m<<" "<<z<<endl;
  if(z<=d)
  {
    s++;
  }
 // cout<<z<<endl;
  return ;
}


   //___________________________________________________________________________
//---------------------------END----------------------------------------------




int main() {

  // int t=1000000;
   //sieve(N);
    #ifndef ONLINE_JUDGE 
  freopen("input.txt" , "r", stdin);
  freopen("out12.txt" , "w", stdout);
    #endif  

  ios int TESTS = 1;
   cin>>TESTS;
   cin>>d;
  // cout<<d<<endl;
  while (TESTS--) {
    solve();

  }
  cout<<s;
  return 0;
}


Measured memory_bytes: 3768
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repe(i, n) for (int i = 0; i <= (n); ++i)
#define repe1(i, n) for (int i = 0; i <= (n); ++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
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; }
typedef long long ll;
const int INF = 1e9;
const ll mod = 1000000007;
int gcd(int a,int b){return b?gcd(b,a%b):a;}

int main() {
	string s;
  cin >> s;
  int l = 0;
  int cnt = 0;
  int r = s.size()-1;
  while(l <= r) {
    if (s[l] != s[r]) {
      cnt++;
    }
    l++;
    r--;
  }
  cout << cnt << "\n";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i <= (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define printa(x,m,n) for(ll i = (m); i <= n; i++){cout << (x[i]) << " ";} cout<<endl;

ll n, m, buf;

int main(){
	cin.tie(0); ios::sync_with_stdio(false);
	
	cin >> n >> m;
	
	priority_queue<ll> a, b;
	rep(i, 1, n){cin >> buf; a.push(buf);}
	rep(j, 1, m){cin >> buf; b.push(buf);}
	
	ll ans = 1;
	rrep(k, n*m, 1){
		if(a.empty()){
			if(b.empty()){
				ans *= k;
			}
			else{
				if(b.top() == k){
					ans *= n;
					b.pop();
				}
				else{
					ans *= n*(m-b.size())-(n*m-k);
				}
			}
		}
		else{
			if(b.empty()){
				if(a.top() == k){
					ans *= m;
					a.pop();
				}
				else{
					ans *= m*(n-a.size())-(n*m-k);
				}
			}
			else{
				if(a.top() == k){
					if(b.top() == k){
						a.pop();
						b.pop();
					}
					else{
						ans *= m-b.size();
						a.pop();
					}
				}
				else{
					if(b.top() == k){
						ans *= n-a.size();
						b.pop();
					}
					else{
						ans *= ((n-a.size())*(m-b.size())-(n*m-k));
					}
				}
			}
		}
		ans %= MOD;
	}
	
	print(ans)
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
ll const INF = 1LL << 60;

int main() {
  ll K;
  cin >> K;
  if (K % 2 == 0) {
    cout << -1 << endl;
    return 0;
  }
  ll cur = 7;
  for (int i = 0; i < 1000000; i++) {
    ll mod = (cur + K) % K;
    if (mod == 0) {
      cout << i + 1 << endl;
      return 0;
    }
    cur = mod * 10 + 7;
  }
  cout << -1 << endl;
  return 0;
}

Measured memory_bytes: 3596
#include <iostream>

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

using namespace std;
using ll = long long;

ll dp[100005][13];


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

	int length = S.length();

	dp[0][0] = 1;

	for (int i = 1; i < length + 1; i++) {
		if (S[i - 1] == '?') {
			rep(j, 10) {
				rep(k, 13) {
					dp[i][(10 * k + j) % 13] += dp[i - 1][k];
					dp[i][(10 * k + j) % 13] %= MOD;
				}
			}
		}
		else {
			int x = S[i - 1] - '0';

			rep(j, 13) {
				dp[i][(10 * j + x) % 13] += dp[i - 1][j];
				dp[i][(10 * j + x) % 13] %= MOD;
			}
		}
	}

	cout << dp[length][5] << endl;

	return 0;
}

Measured memory_bytes: 10624
fn main(){
  loop {
    let n: usize = read();

    if n == 0 { break; }
    
    let mut va: Vec<u32> = read_vec();
    va.sort();
    
    let s:u32 = va.iter().sum();
    
    // println!("{:?}", s);

    let mut l: i32 = -1;
    let mut r: i32 = n as i32;

    while l + 1 < r {
      let m: i32 = (l + r) / 2;

      if va[m as usize] * (n as u32) <= s {
        l = m;
      } else {
        r = m;
      }
    }

    println!("{:?}", r);
  }
}

fn read<T>() -> T
  where T: std::str::FromStr,
        T::Err: std::fmt::Debug
{
  let mut buf = String::new();
  std::io::stdin().read_line(&mut buf).expect("failed to read");
  buf.trim().parse().unwrap()
}

fn read_vec<T>() -> Vec<T>
  where T: std::str::FromStr,
        T::Err: std::fmt::Debug
{
  let mut buf = String::new();
  std::io::stdin().read_line(&mut buf).expect("failed to read");
  buf.split_whitespace().map(|e| e.parse().unwrap()).collect()
}



Measured memory_bytes: 5052
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>
using namespace std;

template<typename A, typename B> bool chmin(A &a, const B &b){ return b < a && (a = b, true); }
template<typename A, typename B> bool chmax(A &a, const B &b){ return a < b && (a = b, true); }

int main(){
  int a,b,c,d,e,k;
  cin >> a >> b >> c >> d >> e >> k;
  if (e - a <= k){
    cout << "Yay!\n";
  }
  else{
    cout << ":(\n";
  }
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <math.h>
#include <cmath>
#include <limits.h>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <functional>
#include <stdio.h>
using namespace std;

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

const int inf = 1001001000;
const int mod = 1000000007;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int digitsum(int i){
    int t = i;
    int ret = 0;
    while(t){
        ret += t%10;
        t /= 10;
    }
    return ret;
}

int main(){
    int h,w;
    cin >> h >> w;
    while(h--){
        string s;
        cin >> s;
        cout << s << endl;
        cout << s << endl;
    }
}



Measured memory_bytes: 256
#include<cstdio>
int d,n;
int main() {
	scanf("%d %d",&d,&n);
	if(n==100) printf("101");
	else printf("%d",n);
	switch(d) {
		case 0:puts("");break;
		case 1:puts("00");break;
		case 2:puts("0000");break;
	}
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
    int n,a,b,i,c,ans,k;
    cin>>a>>b>>c;
    cin>>n;
    k=max(a,max(b,c));
    ans=a+b+c-k;
    for(i=1;i<=n;i++)
        k=k*2;

    ans=ans+k;
    cout<<ans;

        return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
#define ld long double
#define pi pair<int,int>
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()
#define sz(x) ((int)x.size())
#define ln(x) ((int)x.length())
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define endl '\n'
#define dbg(x) cout<<#x<<": "<<x<<endl
#define clr(x,v) memset(x, v, sizeof(x))
#define dblout(x) cout << setprecision(x) << fixed;
#define FASTIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
const double eps = 1e-9;
const double PI = acos(-1.0);
const ll mod = 1e9 + 7;
const int MAXN = 1e5 + 5;
vector<int> prime;
int lp[MAXN];
void init()
{
    lp[1] = 1;
    for(int i = 2; i < MAXN; i++)
    {
        if(!lp[i])
            lp[i] = i, prime.pb(i);
        for(int j = 0; j < sz(prime) && i * 1LL * prime[j] < 1LL * MAXN; j++)
        {
            lp[i * prime[j]] = prime[j];
            if(i % prime[j] == 0)
                break;
        }
    }
}
void factorise(int n, map<int, int> &freq)
{
    if(n == 0)
        return;
    while(n % 2 == 0)
        freq[2]++, n /= 2;
    for(int i = 3; i <= sqrt(n); i += 2)
        if(n % i == 0)
            freq[i]++, n /= i;
    if(n > 1)
        freq[n]++;
}

void cp()
{
    ll n;
    ll x, m;
    cin >> n >> x >> m;

    bool can = true;

    map<int, int> freqx, freqm;
    factorise(x, freqx);
    factorise(m, freqm);

    for(auto &pf : freqm)
        if(!freqx.count(pf.ff))
            can = false;

    if(can || n <= m)
    {
        ll sum = x % m;
        ll op = 1;
        while(op < n)
        {
            ll rem = x % m;
            rem = (rem * rem) % m;
            if(rem == 0)
                break;
            // dbg(rem);
            sum += rem;
            x = rem;
            op++;
        }
        cout << sum << endl;
    }
    else
    {
        // there must be repetitions;
        // atmost m?
        x %= m;
        vector<int> last_occur(m, -1);
        vector<int> series(1, x);
        last_occur[x] = 0;
        int rep = -1;
        for(int i = 1; i < m + 5; i++)
        {
            ll rem = (x * x) % m;
            if(~last_occur[rem])
            {
                rep = i - last_occur[rem];
                break;
            }
            else
                series.pb(rem), last_occur[rem] = i;
            x = rem;
        }
        // dbg(rep);
        // dbg(sz(series));
        // rep must be > 0
        if(~rep)
        {
            int start = sz(series) - rep;
            n -= start;
            ll mul = n / rep;
            ll extra = n % rep;
            ll sum = 0;
            for(int i = 0; i < start; i++)
                sum += series[i];

            for(int i = start; i < sz(series); i++)
                sum += mul * series[i];
            for(int i = 0; i < extra; i++)
                sum += series[start + i];
            cout << sum << endl;
        }
    }
}

int main()
{
    FASTIO;
    int t;
    t = 1;
    init();
    // cin >> t;
    while(t--)
    {
        cp();
    }
    return 0;
}

Measured memory_bytes: 4436
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#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() {
    char sa[110], sb[110], sc[110];
    int posa = 0, posb = 0, posc = 0;
    cin >> sa;
    cin >> sb;
    cin >> sc;
    char turn = 'a';
    while (1) {
        if (turn == 'a') {
            if (posa == strlen(sa)) {
                break;
            }
            turn = sa[posa];
            posa++;
        }
        else if (turn == 'b') {
            if (posb == strlen(sb)) {
                break;
            }
            turn = sb[posb];
            posb++;
        }
        else {
            if (posc == strlen(sc)) {
                break;
            }
            turn = sc[posc];
            posc++;
        }
    }
    if (turn == 'a') {
        cout << "A" << endl;
    }
    else if (turn == 'b') {
        cout << "B" << endl;
    }
    else {
        cout << "C" << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A,B,K;
  cin >> A >> B >> K;
  int count = 0;
  
  while (A != 0 && B != 0) {
    
    if (A > B) {
      
      A = A % B;
  
    }
      
    else {
      
      B = B % A;
  
    }
  }
  
  if (A != 0) {
    int i = A;
    while (count < K) {
      
      if (A % i == 0) {
        count++;
      }
      
      i--;
    }
    
    cout << i + 1 << endl;
  }
  
  
   if (B != 0) {
    int i = B;
    while (count < K) {
      
      if (B % i == 0) {
        count++;
      }
      
      i--;
    }
    
    cout << i + 1 << endl;
  }
}
    

Measured memory_bytes: 256
#include <iostream>
#define SENTINEL 1000000001
using namespace std;
int comp = 0;

void Merge(int arr[], int left, int mid, int right) {
    int n1 = mid - left;
    int n2 = right - mid;
    int arr1[n1] = {};
    int arr2[n2] = {};
    for (int i = 0; i < n1; i++) {
        arr1[i] = arr[left + i];
    }

    for (int i = 0; i < n2; i++) {
        arr2[i] = arr[mid + i];
    }
    arr1[n1] = SENTINEL;
    arr2[n2] = SENTINEL;
    int i = 0;
    int j = 0;
    for(int k = left; k < right; k++) {
        comp++;
        if (arr1[i] < arr2[j]) {
            arr[k] = arr1[i];
            i++;
        } else {
            arr[k] = arr2[j];
            j++;
        }
    }
}

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

int main() {
    int pickles, i;
    cin >> i;
    int array[i] = {};
    for (int j = 0; j < i; j++) {
        cin >> array[j];
    }
    MergeSort(array, 0, i);
    for (int k = 0; k < i; k++) {
        if (k != i - 1) cout << array[k] << " ";
        else cout << array[k] << endl;
    }
    cout << comp << endl;
}


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

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	int64_t a,b,c;
	cin>>a>>b>>c;
	if(c-a-b>0&&4*a*b<(c-a-b)*(c-a-b))cout<<"Yes\n"s;
	else cout<<"No\n"s;
}

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

int main() {
  string n;
  cin >> n;
  if (n.at(0) == '1') {
    n.at(0) = '9';
  }
  else if (n.at(0) == '9') {
    n.at(0) = '1';
  }
  if (n.at(1) == '1') {
    n.at(1) = '9';
  }
  else if (n.at(1) == '9') {
    n.at(1) = '1';
  }
  if (n.at(2) == '1') {
    n.at(2) = '9';
  }
  else if (n.at(2) == '9') {
    n.at(2) = '1';
  }
  cout << n << endl;
}

Measured memory_bytes: 256
DEBUG = False

def dprint(*args):
    if DEBUG:
        print(*args)

n = int(input())
p = [int(i) for i in input().split(' ')]

num = 1
num_min = p.pop(0)
dprint(n, num_min, p)

for i in p:
  if i < num_min:
    num_min = i
    num += 1
  dprint(num, num_min)
  if i == 1:
    break

print(num)


Measured memory_bytes: 26012
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(long long)(n);i++)
#define all(a) a.begin(), a.end()
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
const ll MOD=1e9+7;
const ll INF=1e18;
const int MAX=510000;
const double pi=acos(-1);
int dx[8] = {1,0,-1,0,1,1,-1,-1};
int dy[8] = {0,1,0,-1,-1,1,1,-1};
// int d[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};



int main(){
  cin.tie(0);
  ios::sync_with_stdio(false); 
  
  int n;
  cin >> n;
  vector<ll>a(n),b(n);
  rep(i,n) cin >> a[i] >> b[i];
  sort(a.begin(),a.end());
  sort(b.begin(),b.end());
  ll c,d;
  if(n&1){
    c=a[n/2];
    d=b[n/2];
    cout << d-c+1 << endl;
  }
  else{
    c=a[n/2]+a[n/2-1];
    d=b[n/2]+b[n/2-1];
    cout << d-c+1 << endl;
  }
  return 0;
}


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

#define DEBUG(x) cout<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cout<<#v<<":";for(int i=0;i<v.size();i++) cout<<" "<<v[i]; cout<<endl

typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
const int inf = 1000000001;
const ll INF = 1e18 * 4;
#define MOD 1000000007
#define mod 1000000009
#define pi 3.14159265358979323846
#define Sp(p) cout<<setprecision(15)<<fixed<<p<<endl;
int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };

static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;
static const int N = 1010;

int n;
//i番目からadj[i].second番目はつながっていて、重みはadj[i].first
vector< vector< pair<double, int> > > adj(N, vector< pair<double, int> >());
vector<double> d(N, inf * 4.0);

void dijkstra() {
	priority_queue< pair<double, int>, vector< pair<double, int> >, greater< pair<double, int> > > pq;
	int i;
	vi color(n + 2, WHITE);

	d[0] = 0;
	pq.push(make_pair(0, 0));
	color[0] = GRAY;

	while (!pq.empty()) {
		pair<double, int> f = pq.top();
		pq.pop();
		int u = f.second;
		color[u] = BLACK;
		if (d[u]<f.first) {
			continue;
		}
		for (i = 0; i < adj[u].size(); i++) {
			int v = adj[u][i].second;
			if (color[v] == BLACK) {
				continue;
			}
			if (d[v]>d[u] + adj[u][i].first) {
				d[v] = d[u] + adj[u][i].first;
				pq.push(make_pair(d[v], v));
				color[v] = GRAY;
			}
		}
	}
}

int main() {
	ll xs, ys, xt, yt;
	scanf("%lld%lld%lld%lld", &xs, &ys, &xt, &yt);
	int i, j;
	scanf("%d", &n);
	vl x(n + 2), y(n + 2), r(n + 2);
	x[0] = xs; y[0] = ys; r[0] = 0;
	x[1] = xt; y[1] = yt; r[1] = 0;
	for (i = 2; i < n + 2; i++) {
		scanf("%lld%lld%lld", &x[i], &y[i], &r[i]);
	}
	for (i = 0; i < n + 2; i++) {
		for (j = i + 1; j < n + 2; j++) {
			double d = sqrt((x[i] - x[j])*(x[i] - x[j]) + (y[i] - y[j])*(y[i] - y[j]));
			d -= (r[i] + r[j]);
			if (d < 0) {
				d = 0;
			}
			adj[i].push_back(make_pair(d, j));
			adj[j].push_back(make_pair(d, i));
		}
	}

	dijkstra();
	Sp(d[1]);

}

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

int main() {

    string S;
    cin >> S;

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


    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
use proconio::{input, fastout};
use proconio::marker::{Chars};
use proconio::marker::Usize1;
use std::cmp::*;

macro_rules! debug {
      ($($a:expr),*) => {
          eprintln!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

fn gcd_2(mut a: usize, mut b: usize) -> usize {
    let mut x = a;
    let mut y = b;
    if a<b {
        let mut tmp = a;
        a = b;
        b = tmp;
    } 
    let mut r = a % b;
    while r!=0 {
        a = b;
        b = r;
        r = a % b;
    }
    x/b * y
}

#[fastout]
fn main() {
    input!{
        n: usize,
        t: [usize;n],
    }

    let mut d = t[0];
    for i in 1..n {
        d = gcd_2(d, t[i]);
    }
    debug!(d);
    println!("{}", d);
}


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

public class Main{
  public static void main(String[] args){
  	
  	//Optional : To state what to input (Comment ouot if needed)
	//System.out.println("Please input a number within 1 ~ 100");
  	
  	Scanner stdn = new Scanner(System.in);
  	
  	//Initialization interger 
	int x = 0;
  	double y = 0;
 		x = stdn.nextInt();
	  	if(x > 0 && x < 101){
	  		y = Math.pow((double)x,3d);
	  		x = (int)y;
	  	}
	    System.out.println(x);
  }
}

Measured memory_bytes: 26212
using System;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Linq;
using System.Collections.Generic;
using System.Text.RegularExpressions;

class Program
{
    const string Yes = "Yes";
    const string No = "No";
    const char White = '.';
    const char Black = '#';
    const long Mod = 1000000007;

    static void Main(string[] args) {
        checked {
#if DEBUG
            MyDebugger.Test(process, "../TextFile1.txt");
            //TestCaseMaker.MakeTestCase1("../TextFile2.txt");
            //MyDebugger.Test(process, "../TextFile2.txt");
#else
            object ret = process(new StreamReader(Console.OpenStandardInput()));
            if(ret != null) Console.WriteLine(ret);
#endif
        }
    }

    static object process(TextReader input) {
        var n = long.Parse(input.ReadLine());

        long co = 0;//= 1; //a==0

        for(long a = 1; a<=n; a++) {
            for(long b = 1; b<=n; b++) {
                if(a*b < n) {
                    co++;
                } else {
                    break;
                }
            }
        }

        return co;
    }

    static long[] ToIntArray(string strs, int n) {
        var ret = new long[n];
        var spl = strs.Split(' ');
        for (int i = 0; i < n; i++)
            ret[i] = long.Parse(spl[i]);
        return ret;
    }
}


Measured memory_bytes: 27460
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
#define all(x) (x).begin(), (x).end()
ll inf = LLONG_MAX;
long double pi = M_PI;
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}

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

  deque<char> dq;
  for (ll i = 0; i < s.size(); i++) dq.push_back(s[i]);

  ll cnt = 0;
  for (ll i = 0; i < q; i++) {
    ll x;
    cin >> x;

    if (x == 1) {
      cnt++;
    }
    else {
      ll y;
      char c;
      cin >> y >> c;

      if (y == 1 && cnt % 2 == 0) {
        dq.push_front(c);
      }
      else if (y == 1 && cnt % 2 == 1) {
        dq.push_back(c);
      }
      else if (y == 2 && cnt % 2 == 0) {
        dq.push_back(c);
      }
      else {
        dq.push_front(c);
      }
    }
  }

  if (cnt % 2 == 0) {
    while (dq.size() > 0) {
      cout << dq.front();
      dq.pop_front();
    }
    cout << endl;
  }
  else {
    while (dq.size() > 0) {
      cout << dq.back();
      dq.pop_back();
    }
    cout << endl;
  }
}

Measured memory_bytes: 896
n = int(input())

ans=0
tmp=0
for i in range(1, int(n**0.5)+1):
    if n%i == 0:
        if i != 1 and n%(i-1)==n//(i-1):
            ans+=i-1
        tmp=n//i
        if i != tmp:
            if n%(tmp-1)==n//(tmp-1):
                ans+=tmp-1
print(ans)


Measured memory_bytes: 3060
import java.io.*;
import java.util.*;

//Main class start
public class Main {
    // solution starts here!!!
    public void solve() throws IOException {
        int s = in.ni();
        int w = in.ni();
      if(w>=s)out.println("unsafe");
      else out.println("safe");




    } //Solution ENDS Here !!!

    FastScanner in;
    FastWriter out;
    long maxLong = Long.MAX_VALUE  ,  minlong = Long.MIN_VALUE;
    int maxInt = Integer.MAX_VALUE ,  minInt = Integer.MIN_VALUE;
    double PI = 3.141592653589793238462643383279502884197169399;
    int digit(long s){int ans = 0;while(s>0){s/=10;ans++;}return ans;}
    long gcd(long a, long b){return (b==0)?a:gcd(b,a%b);}
    int gcd(int a, int b){return (b==0)?a:gcd(b,a%b);}
    int bit(long n){return (n==0)?0:(1+bit(n&(n-1)));}

    public void run() {
        try {
            in = new FastScanner();
            out = new FastWriter();

            solve();

            out.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }


    class FastWriter extends PrintWriter {
        FastWriter() throws FileNotFoundException {
            super(System.out);
        }

        void printNext(int i) {
            print(i);
            print(' ');
        }

        void printNext(long i) {
            print(i);
            print(' ');
        }

        void printNext(char ch) {
            print(ch);
            print(' ');
        }


        <T extends Iterable<Integer>> void printIterable(T o) {
            for (Integer t : o) {
                printNext(t);
            }
        }

        void printlnArray(int[] a) {
            for (int i : a) {
                printNext(i);
            }
            println();
        }

        void printlnArray(long[] a) {
            for (long i : a) {
                printNext(i);
            }
            println();
        }


    }

    class FastScanner {
        BufferedReader br;
        StringTokenizer st;


        boolean ready() throws IOException {
            return (br.ready() || st.hasMoreTokens());
        }

        FastScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }
        char nc(){
            return next().charAt(0);
        }

        double nd(){
            return Double.parseDouble(next());
        }

        int ni() {
            return Integer.parseInt(next());
        }

        long nl() {
            return Long.parseLong(next());
        }

    }

    public static void main(String[] arg) {
        new Main().run();
    }
}


Measured memory_bytes: 32840
#include "bits/stdc++.h"

#define REP(i, n, N) for(int i=(n); i<(N); i++)
#define RREP(i, n, N) for(int i=(N-1); i>=n; i--)
#define CK(n, a, b) ((a)<=(n)&&(n)<(b))
#define ALL(v) (v).begin(),(v).end()
#define MCP(a, b) memcpy(b,a,sizeof(b))
#define p(s) cout<<(s)<<endl
#define p2(a, b) cout<<(a)<<" "<<(b)<<endl
#define v2(T) vector<vector<T>>
typedef long long ll;
using namespace std;
const ll mod = 1e9 + 7;
const ll inf = 1e18;

int N, M;
int h, w;
int main() {
	cin >> N >> M;
	cin >> h >> w;
	p((N-h)*(M-w));

	return 0;
}


Measured memory_bytes: 256
#include<cstdio>
using namespace std;
int main(){
    int n,k,x,y=0;
    scanf("%d %d",&n,&k);
    x=(1<<n);
    if(n==1&&k==0){
        printf("1 1 0 0\n");
        return 0;
    }
    if(x<=k||(n==1&&k==1)){
        printf("-1\n");
    }
    else{
        printf("%d ",k);
        for(int i=0;i<x;i++){
            if(i!=k){
                printf("%d ",i);
            }
        }
        printf("%d ",k);
        for(int i=x-1;i>=0;i--){
            if(k!=i){
                printf("%d ",i);
            }
        }
        printf("\n");
    }
}


Measured memory_bytes: 1792
import java.util.*;

public class Main {
    public static void main(final String[] args) {
        final Scanner sc = new Scanner(System.in);
        // 整数の入力
        // final int a = sc.nextInt();
        // 文字列の入力
        // final String s1 = sc.next();
        final int varN = Integer.parseInt(sc.next());
        int acCnt = 0;
        int waCnt = 0;
        int tleCnt = 0;
        int reCnt = 0;

        for (int i = 0; i < varN; i++) {
            switch (sc.next()) {
                case "AC":
                    acCnt++;
                    break;
                case "WA":
                    waCnt++;
                    break;
                case "TLE":
                    tleCnt++;
                    break;
                case "RE":
                    reCnt++;
                    break;
            }
        }
        sc.close();

        System.out.println("AC x " + acCnt);
        System.out.println("WA x " + waCnt);
        System.out.println("TLE x " + tleCnt);
        System.out.println("RE x " + reCnt);
    }
}

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

using namespace std;
int n, a[2000];
int ans;
int main() {
    ios_base::sync_with_stdio(0);
    cin >> n;
    for (int i = 1; i <= n; i++) cin >> a[i];
    int i = 1;
    while (i <= n) {
        int j = i;
        while (j <= n && a[j] == a[i]) j++;
        ans += (j - i) / 2;
        i = j;
    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int n;
	int card[52]={};
	int i, no;
	char c;
	scanf("%d\n", &n);
	for(i=0; i<n; i++) {
		if(i<n-1) {
			scanf("%c%d\n", &c, &no);
		}
		else scanf("%c%d", &c, &no);
		no--;
		if(c=='S') card[no]=1;
		else if(c=='H') card[no+13]=1;
		else if(c=='C') card[no+26]=1;
		else if(c=='D') card[no+39]=1;
	}
	
	for(i=0; i<52; i++) {
		if(card[i]==0) {
			if(i/13==0) printf("S %d\n", i%13+1);
			else if(i/13==1) printf("H %d\n", i%13+1);
			else if(i/13==2) printf("C %d\n", i%13+1);
			else if(i/13==3) printf("D %d\n", i%13+1);
		}
	}
	return 0;
}


Measured memory_bytes: 596
def is_even(x):
    half = x//2
    if half * 2 == x:
        return 1
    else:
        return 0

def abs(x):
    if x >= 0:
        return x
    else:
        return -x

if __name__ == "__main__":
    N = int(input())
    A = list(map(int,input().split()))
    minus_count = 0
    B = 0
    for a in A:
        if a < 0:
            minus_count += 1
    if is_even(minus_count):
        for a in A:
            B += abs(a)
    else:
        C = [abs(a) for a in A]
        c = min(C)
        B = sum(C) - 2 * c
    print(B)

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

#define rep(i, n) for(int i = 0; i<(n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
using ll = long long;

int main() {
    ll S;
    cin >> S;
    ll x1, y1, x2, y2, x3, y3;
    x1 = y1 = 0;

    ll t = sqrt(S);
    if (t * t == S) {
        x2 = t;
        y2 = 0;
        x3 = 0;
        y3 = t;
    } else {
        x2 = t + 1;
        y2 = x2 * x2 - S;
        x3 = 1;
        y3 = t;
    }

//    cout << x1 << " " << y1 << " " << x2 << " " << y2 << " " << x3 << " " << y3 << endl;

    if (t * t == S) {
        cout << "0 0 " << t << " " << "0 0 " << t << "\n";
        return 0;
    }
    t += 1;
    ll e = t * t - S;
    cout << "0 0 " << t << " " << e << " " << "1 " << t << "\n";
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(long long i = 0;i < n;i++)
#define repr(i, n) for(int i = n;i >= 0;i--)
#define Sort(v, n) sort(v, v+n);
#define VSort(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define INF 999999999
const ll MOD = 1000000007;


int main() {
    string s;
    cin >> s;
    int k;
    cin >> k;
    vector<string> vec;
    for(int i = 0;i < s.size();i++) {
        for(int j = 1;j <= k;j++) {
            vec.pb(s.substr(i,j));
        }
    }
    VSort(vec)
    vec.erase(std::unique(vec.begin(), vec.end()), vec.end());
    cout << vec[k-1];
}

Measured memory_bytes: 1660
#include <iostream>
#include <string>
using namespace std;
int pmCalc(int a, int b, int x);
char selectOp(int x);
int main()
{
    int A,B,C,D;
    string S;
    cin >> S;
    A = S[0] - '0';
    B = S[1] - '0';
    C = S[2] - '0';
    D = S[3] - '0';
    for(int i=0; i<2; i++)
    {
    	for(int j=0; j<2; j++)
    	{
    		for(int k=0; k<2; k++)
    		{
    		    int y = pmCalc(pmCalc(pmCalc(A,B,i),C,j),D,k);
    		    if(y==7)
    		    {
    		    	cout << A << selectOp(i) << B << selectOp(j)
    		    	     << C << selectOp(k) << D << "=7" <<  endl;
    		    	return 0;
    		    }
    		}
    	}
    }
	return 0;
}

int pmCalc(int a, int b, int x)
{
    if(x==0) return a+b;
    else return a-b;
}

char selectOp(int x)
{
	if(x==0) return '+';
	else return '-';
}

Measured memory_bytes: 256
from sys import stdin
s,t = stdin.readline().strip(),stdin.readline().strip()
dp = [[0]*len(s) for _ in range(len(t))]
maxi = [0]*len(s)
for i,val in enumerate(t):
    maxi1 = []
    for x in range(len(s)):
        if s[x] == val:
            dp[i][x] = (0 if x==0 else maxi[x-1])+1
        maxi1.append(max((0 if x==0 else maxi1[x-1]),dp[i][x]))
    for j in range(len(maxi)):
        maxi[j] = max(maxi[j],maxi1[j])
n = max(map(max,dp))
ans,i,j = [],len(t)-1,len(s)-1
while n:
    fl = 0
    for x in range(i,-1,-1):
        for y in range(j,-1,-1):
            if dp[x][y] == n:
                ans.append(s[y])
                fl = 1
                i,j = x-1,y-1
                break
        if fl:
            break
    n -= 1
print(''.join(ans[::-1]))

Measured memory_bytes: 146256
N = int(input())

Qs = [0 for _ in range(N)]
for i in range(N):
    tmp = int(input())
    Qs[tmp - 1] = i - 1

result, tmp = 1, 1
for i in range(N - 1):
    if Qs[i] < Qs[i + 1]:
        tmp += 1
    else:
        result = max(result, tmp)
        tmp = 1

print(N - max(result, tmp))

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


int dp[100];

//最大公約数
int gcd(int x, int y){
  if(x % y == 0) return 1;
  return gcd(y, x % y);
}
//最小公倍数
int lcm(int x, int y){
  return x * y / gcd(x, y);
}
//フィボナッチ数列
//配列dpを-1で初期化する
int fib(int n){
  if(n == 0 || n == 1) return dp[n] = 1;
  if(dp[n] != -1) return dp[n];
  return dp[n] = fib(n - 1) + fib(n - 2);
}
//階乗計算(factorial)
int fact(int n){
  if(n = 1) return 1;
  return n * fact(n - 1);
}
//累乗計算(Exponentiation)
//x**y
ll expo(int x, int y){
  ll ans = 1;
  rep(i, y){
    ans *= x;
  }
  return ans;
}
//桁数
int keta(ll x){
  if(x == 0) return 1;
  int res = 0;
  while(x){
    x /= 10;
    res++;
  }
  return res;
}


int main(){
  int p, q, r;
  cin >> p >> q >> r;
  int ans = p + q + r;
  ans -= max(max(p, q), max(q, r));
  cout << ans << endl;
}


/*





















*/


Measured memory_bytes: 256
use std::io::prelude::*;

fn input<T>() -> T
where
    T: std::str::FromStr,
{
    let stdin = std::io::stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}

fn main() {
    let n: usize = input();
    let a: Vec<i64> = (0..n).map(|_| input()).collect();

    let mut sum = vec![0; n + 1];
    for i in 0..n {
        sum[i + 1] = sum[i] + a[i];
    }

    let mut ans = i64::max_value();
    for i in 1..n {
        ans = std::cmp::min(ans, (sum[i] - (sum[n] - sum[i])).abs());
    }

    println!("{}", ans);
}


Measured memory_bytes: 8444
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <functional>
using namespace std;

vector<int> Centroid(const vector<vector<int>> &g) {
        int n = g.size();
        vector<int> centroid;
        vector<int> sz(n);
        function<void (int, int)> dfs = [&](int u, int prev) {
                sz[u] = 1;
                bool is_centroid = true;
                for (auto v : g[u]) if (v != prev) {
                        dfs(v, u);
                        sz[u] += sz[v];
                        if (sz[v] > n / 2) is_centroid = false;
                }
                if (n - sz[u] > n / 2) is_centroid = false;
                if (is_centroid) centroid.push_back(u);
        };
        dfs(0, -1);
        return centroid;
}

int main() {
        int n;
        scanf("%d", &n);
        vector<vector<int>> g(n);
        vector<vector<pair<int ,int>>> gg(n);
        for (int i = 0; i < n - 1; i ++) {
                int a, b, c;
                scanf("%d%d%d", &a, &b, &c);
                a --, b --;
                g[a].push_back(b);
                g[b].push_back(a);
                gg[a].emplace_back(b, c);
                gg[b].emplace_back(a, c);
        }
        long long ans = 0;
        vector<int> sz(n);
        function<void (int, int)> dfs = [&](int u, int prev) {
                sz[u] = 1;
                for (auto e : gg[u]) {
                        int v = e.first, cost = e.second;
                        if (v == prev) continue;
                        dfs(v, u);
                        sz[u] += sz[v];
                        ans += min(sz[v], n - sz[v]) * (long long) 2 * cost;
                }                                 
        };
        dfs(0, -1);
        auto centroid = Centroid(g);
        if (centroid.size() == 1) {
                int mi = 0x3f3f3f3f;
                for (auto e : gg[centroid[0]]) {
                        mi = min(mi, e.second);
                }
                ans -= mi;
        } else {
                for (auto e : gg[centroid[0]]) {
                        if (e.first == centroid[1]) {
                                ans -= e.second;
                                break;
                        }
                }
        }
        printf("%lld\n", ans);
        return 0;
}


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

static const int INF=1e9;
static const int MOD=1000000007;
typedef long long ll;
typedef pair<int,int> P;

int main(){
    ll N,M,K; cin >> N >> M >> K;
    ll a[N],b[M];
    for(int i=0;i<N;i++){
        cin >> a[i];
    }
    for(int j=0;j<M;j++){
        cin >> b[j];
    }
    for(int i=1;i<N;i++){
        a[i]+=a[i-1];
    }
    for(int i=1;i<M;i++){
        b[i]+=b[i-1];
    }
    int ans=0;
    for(int i=0;i<N;i++){
        ll tmp=K-a[i];
        if(tmp<0) break;
        int ind=upper_bound(b,b+M,tmp)-b;
        //cout << i << " " <<  ind << endl;
        ans=max(ans,i+1+ind);
    }
    int j=upper_bound(b,b+M,K)-b;
    ans=max(ans,j);
    cout << ans << endl;
}


Measured memory_bytes: 6712
list_length = int(input())
list_num = list(map(int, input().split()))

for num in range(1,list_length+1):
    list_num[num-1] = list_num[num-1] - (num+1)

max = 0

list_num.sort()

if (list_length % 2 != 0):
    b = list_num[(list_length+1)//2 - 1]
else:
    b = list_num[list_length//2 - 1]


for num in range(1,list_length+1):
    max += abs(list_num[num-1] - b )


print (max)


Measured memory_bytes: 26128
import decimal

from math import ceil


def solve(k, a, b):
    if k <= a:
        return 1
    if a <= b:
        return -1
    ka = decimal.Decimal(k - a)
    ab = decimal.Decimal(a - b)
    return ceil(ka / ab) * 2 + 1


print(solve(*map(int, input().split())))


Measured memory_bytes: 5844
#include<cstdio>
#include<cstring>
#include<algorithm>
int n,ans=0x3f3f3f3f;
char S[500100];
int main(){
	scanf("%s",S+1);
	n=strlen(S+1);
	for(int i=1;i<n;i++)
		if(S[i]!=S[i+1])ans=std::min(ans,std::max(i,n-i));
	if(ans==0x3f3f3f3f)printf("%d\n",n);
	else printf("%d\n",ans);
}

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

int n, m;
int mem[4010][6010][3];

void add(int &x, int v)
{
    x = (x + v) % m;
}

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

    mem[1][1][0] = 1;
    for(int i = 1; i <= 2 * n; i++)
    {
        for(int j = 1; j <= 3 * n - 1; j++)
        {
            for(int k = 0; k < 3; k++)
            {
                if(k == 0)
                    add(mem[i][j + 1][0], mem[i][j][k]);
                else
                    add(mem[i + 1][j + 1][0], mem[i][j][k]);

                if(k < 2)
                    add(mem[i][j + 1][k + 1], 1LL * mem[i][j][k] * j % m);
            }
        }
    }
    
    int r = 0;
    for(int i = 1; i <= n; i++)
        for(int k = 0; k < 3; k++)
            add(r, mem[i][3 * n][k]);
    add(r, mem[n + 1][3 * n][0]);

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


Measured memory_bytes: 281984
import sys
input = sys.stdin.readline


def main():
    N = int(input())
    K = int(input())

    ans = float('inf')
    for i in range(2**N):
        num = 1
        for j in range(N):
            if (i>>j)&1:
                num *= 2
            else:
                num += K
        ans = min(ans, num)
    
    print(ans)
                


if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
n = int(input())

lis = []

for i in range(n):
    array = list(map(int, input().split()))
    lis.append(array)

lis.sort(reverse=True, key=lambda x:x[2])
ans_list = []

for i in range(101):
    for j in range(101):
        h = abs(i-lis[0][0]) + abs(j-lis[0][1]) + lis[0][2]
        flag = True
        for k in range(1, n):
            dist = abs(i - lis[k][0]) + abs(j - lis[k][1])
            if h - dist == lis[k][2]:
                continue
            elif h - dist <= 0 and lis[k][2] == 0:
                continue
            else:
                flag = False
                break
        if flag is True:
            print(i, j, h)


Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <cmath>
#include <iomanip>

using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
template<class T>using vv = vector<vector<T>>;

// #define rep(i,n) for(int i=0;i<(n);++i)
#define all(f,c,...) (([&](decltype((c)) cccc) { return (f)(begin(cccc), end(cccc), ## __VA_ARGS__); })(c))
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)

#define rrep(i,n) for(int i=(n);i>=0;--i)
const int dx[4]={1,0,-1,0}, dy[4]={0,1,0,-1};
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;}

// debug
template<class T>ostream& operator<<(ostream& os,const vector<T>& vec){os<<"{";for(int i=0;i<vec.size();++i)os<<(i?", ":"")<<vec[i];os<<"}";return os;}
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>& rhs){os<<"("<<rhs.first<<", "<<rhs.second<<")";return os;}

#ifdef LOCAL
void debug() {cerr << "\n";}
template<class First> void debug(const First& first) {cerr<<first<<"\n";}
template<class First, class... Rest> void debug(const First& first, const Rest&... rest) {cerr<<first<<",";debug(rest...);}
#else
#define debug(...) 42
#endif


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

  ll ans = X / 500;
  ans *= 1000;
  ans += floor((X % 500) / 5) * 5;
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long ll;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

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

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

int main() {
    ll x;
    cin >> x;
    ll count = x / 11;
    if (x % 11 == 0) cout << count * 2;
    else if(x % 11 <= 6) cout << count * 2 + 1;
    else cout << count * 2 + 2;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  vector<int> b(101);
  for (int i = 0; i < n; i++) {
    b[a[i]]++;
  }
  int count = 0;
  for (int j = 0; j < 101; j++) {
    if (b[j] != 0) {
      count++;
    }
  }
  cout << count << endl;
}

Measured memory_bytes: 3568