akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, a, b) for(int i = a; i < b; i++)
#define rrep(i, a, b) for(int i = b - 1; i >= a; i--)
#define ALL(a) a.begin(), a.end()
#define pii pair<int,int>
#pragma GCC optimize("Ofast")
#define pcnt __builtin_popcount
#define buli(x) __builtin_popcountll(x)
#define pb push_back
#define mp make_pair
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define isSquare(x) (sqrt(x)*sqrt(x) == x)
template<class T>bool chmax(T &a, const T &b) {if(a<b){a = b; return 1;} return 0; };
template<class T>bool chmin(T &a, const T &b) {if(a>b){a = b; return 1;} return 0; };
inline void IN(void){return;}
template <typename First, typename... Rest> void IN(First& first, Rest&... rest){cin >> first;IN(rest...);return;}
inline void OUT(void){cout << "\n";return;}
template <typename First, typename... Rest> void OUT(First first, Rest... rest){cout << first << " ";OUT(rest...);return;}
const double EPS = 1e-9;
const int mod = 1e9 + 7;
const int INF = 1e9;
const long long LLINF = 1e18;
long long lcm(ll a, ll b){return a * b / __gcd(a,b);}
struct IoSetup { IoSetup() {
    cin.tie(nullptr);ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    cerr << fixed << setprecision(10);
} } iosetup;

static const int MAX=3005;

ll MOD;
ll fact[MAX], fact_inv[MAX];

ll comb(ll n, ll r){
    return (fact[n] * fact_inv[r]) % MOD * fact_inv[n-r] % MOD;
}

long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}//mod mでの逆元aを計算

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

int main(){
    iosetup;
    int p; IN(p);
    MOD = p;
    vector<int> a(p);
    rep(i, 0, p) cin >> a[i];

    fact[0] = 1;
    for(int i = 0; i < MOD - 1; i++) fact[i+1] = fact[i] * (i+1) % MOD;
    fact_inv[MOD-1] = modpow(fact[MOD-1], MOD - 2, MOD);
    for(int i = MOD - 2; i >= 0; i--) fact_inv[i] = fact_inv[i+1]%MOD*(i+1)%MOD;

    cout << a[0];
    rep(i, 1, p){
        ll ans = 0;
        rep(j, 0, p) if(a[j] == 1){
            if((p-1-i)%2 == 0) ans -=(comb(p-1, i) * modpow(j,p-1-i, p))%p;
            else ans += (comb(p-1, i) * modpow(j, p-1-i, p))%p;
        }
        ans %= p;
        if(ans < 0) ans += p;
        cout << " ";
        cout << ans;
    }
    cout << endl;
    
    return 0;
}

Measured memory_bytes: 512
import sys
readline=sys.stdin.readline

S = int(readline())

# 最も多い箱の数は、N = S // 3個
# Nから1個の箱i個に対して、残った数値（S - 3 * i）を分ける場合の数を足し合わせる

N = S // 3

DIV = 10 ** 9 + 7
n = (10 ** 6) * 2
g1 = [1] * 2 + [0] * (n - 2) # 元テーブル
g2 = [1] * 2 + [0] * (n - 2) #逆元テーブル
inverse = [0, 1] + [0] * (n - 2) #逆元テーブル計算用テーブル

for i in range(2, n):
  g1[i] = (g1[i - 1] * i) % DIV
  inverse[i] = (-inverse[DIV % i] * (DIV // i)) % DIV
  g2[i] = (g2[i - 1] * inverse[i]) % DIV

def nCr(n, r, DIV):
  if (r < 0 or r > n):
    return 0
  r = min(r, n-r)
  return g1[n] * g2[r] * g2[n-r] % DIV

ans = 0
for i in range(N, 0, -1):
  rest = S - 3 * i
  if rest <= 0:
    ans += 1
    continue
  # rest個をi個の箱に分ける
  # rest + i - 1 C min(rest, i - 1)
  ans += nCr(rest + i - 1, rest, DIV)
  ans %= DIV
  
print(ans)

Measured memory_bytes: 158924
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main()
{   ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n,k;
    cin >> n >> k;
    int a[n];
    int s=0;
    for(int i=0;i<n;i++)
    {
        cin >> a[i];
    }
    sort(a,a+n);
    for(int i=0;i<k;i++)
    {
        s=s+a[i];
    }
    cout << s <<endl;
    return 0;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define inf 1001001001001001001
#define mod 1000000007
#define mod2 998244353
#define pi acos(-1)
#define all(v) v.begin(),v.end()

ll gcd(ll a,ll b){
    if(b>a) swap(a,b);
    if(b==0) return a;
    return gcd(b,a%b);
}
ll lcm(ll a,ll b){
    ll g=gcd(a,b);
    return a/g*b;
}
ll rep_jijo(ll n,ll x){
    if(x==0) return 1;
    if(x%2==0){
        ll t=rep_jijo(n,x/2);
        return t*t;
    }
    return n*rep_jijo(n,x-1);
}

int main(){
    int h1,m1,h2,m2,k;
    cin >> h1 >> m1 >> h2 >> m2 >> k;
    int tim=(h2-h1)*60+(m2-m1);
    int ans=tim-k;
    cout << max(0,ans) << endl;
    return 0;
}

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

int main() {
	int n;
	cin >> n;
	vector<int> a(n);
	rep(i, n)cin >> a[i];
	int maxa = 0;
	rep(i, n)rep(j, n) {
		maxa = max(maxa, abs(a[i] - a[j]));
	}
	cout << maxa << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REP2(i, x, n) for(int i = x; i < (int)(n); i++)
#define ALL(n) begin(n), end(n)
//struct cww{cww(){ios::sync_with_stdio(false);cin.tie(nullptr);}}star;
const long long INF = numeric_limits<long long>::max();

int MOD = 1000000007;

std::vector<int> sieve(int n) {
  std::vector<int> res(n);
  std::iota(res.begin(), res.end(), 0);
  for (int i = 2; i*i < n; ++i) {
    if (res[i] < i) continue;
    for (int j = i*i; j < n; j += i)
      if (res[j] == j) res[j] = i;
  }
  return res;
}

std::vector<int> factor(int n, const std::vector<int>& min_factor) {
  // min_factor は sieve() で得られたものとする
  std::vector<int> res;
  while (n > 1) {
    res.push_back(min_factor[n]);
    n /= min_factor[n];
    // 割った後の値についても素因数を知っているので順次求まる
  }
  return res;
}


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

  vector<long long> a(n);
  vector<int> factors;
  vector<int> min_factors = sieve(1000001);

  REP(i, n) {
    scanf("%d", &a[i]);
    vector<int> temp_factors = factor(a[i], min_factors);
    auto temp_itr = temp_factors.begin();
    for(auto itr = factors.begin(); itr != factors.end(); ++itr) {
      if (temp_itr != temp_factors.end()) {
        if (*itr == *temp_itr) {
          ++temp_itr;
          continue;
        } else {
          if (*temp_itr < *itr) {
            itr = factors.insert(itr, *temp_itr);
            ++temp_itr;
          } else {
            continue;
          }
        }
      } else {
        break;
      }
    }
    for(temp_itr; temp_itr != temp_factors.end(); ++temp_itr) {
      factors.push_back(*temp_itr);
    }
  }

  long long sum = 0;

  REP(i, n) {
    long long value = 1;
    vector<int> temp_factors = factor(a[i], min_factors);

    auto temp_itr = temp_factors.begin();
    for(auto itr = factors.begin(); itr != factors.end(); ++itr) {
      if (temp_itr != temp_factors.end()) {
        if (*itr == *temp_itr) {
          ++temp_itr;
          continue;
        } else {
          if (*temp_itr < *itr) {
          } else {
            value = value * (*itr) % MOD;
          }
        }
      } else {
        value = value * (*itr) % MOD;
      }
    }
    sum = (sum + value) % MOD;
  }

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


Measured memory_bytes: 4352
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<vector>
#include<functional>
#include<iomanip>
#include<cmath>
#include<queue>
#include<limits>
#include<cassert>
#include<set>
#include<tuple>
#include<map>

#define PB push_back
#define ALL(a)  (a).begin(),(a).end()
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

using namespace std;
typedef long long ll;

double a, b, c, d, e, f;
vector<double> water, sugar;
double ans[2] = {};
double conmax = 0.0;

int main()
{
	int n;
	cin >> n;
	map<int, int> mp;
	int cnt = 0;
	for (int i = 0; i < n; i++) {
		int a;
		cin >> a;
		if (mp[a] == 0) {
			mp[a]++;
			cnt++;
		}
		else {
			mp[a]--;
			cnt--;
		}
	}
	cout << cnt << endl;
	return 0;
}


Measured memory_bytes: 4992
#include<bits/stdc++.h>
using namespace std;
 
#define P(p) cout<<(p)<<endl
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v) sort(v.begin(), v.end(),greater<int>());
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return
#define lb(v,n) lower_bound(v.begin(),v.end(),n)
#define ub(v,n) upper_bound(v.begin(),v.end(),n)
#define mae(v) max_element(v.begin(),v.end())
#define mie(v) min_element(v.begin(),v.end())
#define INF 0x7FFFFFFF
#define mod 1000000007
typedef long long ll;
////////////////////////////////////////////////////////////

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

	ll ans=0;

	rep(i,0,n){
		int a;
		cin >> a;
		ans += a-1;
	}

	cout << ans << endl;
	ret 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(void){
	int n,i,j;
	int ans[4];
	string t;
	string s[4] = {"AC", "WA", "TLE", "RE"};
	cin >> n;
	for(i = 0; i < 4; i++) ans[i] = 0;
	for(i = 0; i < n; i++){
		cin >> t;
		for(j = 0; j < 4; j++){
			if(t == s[j])	ans[j]++;
		}
	}
	for(i = 0; i < 4; i++)	cout << s[i] << " x " << ans[i] << endl;
	return 0;
}

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

int main(){
  int n;
  cin >> n;
  int h[n];
  for(int i = 0;i < n;i++){
    cin >> h[i];
  }
  int ans = 0,cur = 0;
  for(int i = 0;i < n-1;i++){
    if(h[i] >= h[i+1]){
      cur++;
    }
    else{
      ans = max(ans,cur);
      cur = 0;
    }
  }
  ans = max(ans,cur);
  cout << ans << endl;
}

Measured memory_bytes: 640
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
using namespace std;

long long D[210];

int main() {
  long long N, K, T, U, V, L;
  cin >> N >> K >> T >> U >> V >> L;
  for (int i = 0; i < N; ++i) {
    cin >> D[i+1];
  }
  D[0] = 0;
  D[N+1] = L;
  long long ninjin = 0;
  double ret = 0;
  double boostDist = 0;
  for (int i = 0; i < N + 1; ++i) {
    double dist = D[i+1] - D[i];
    if (boostDist >= dist) {
      ret += dist / V;
      boostDist -= dist;
    } else {
      double restDist = dist - boostDist;
      ret += boostDist / V;
      long long use = min(ninjin, (long long)ceil(restDist / (V * T)));
      ninjin -= use;
      boostDist = V * T * use;
      if (boostDist > restDist) {
        ret += restDist / V;
        boostDist -= restDist;
      } else {
        ret += boostDist / V;
        ret += (restDist - boostDist) / U;
        boostDist = 0;
      }
    }
    ++ninjin;
    if (ninjin > K) {
      ninjin = K;
      boostDist = V * T;
    }
  }
  printf("%.9f\n", ret);
}

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

int main() {
  string s;
  cin >> s;
  int q;
  cin >> q;
  int t,f;
  string c;
  int rev = 0;
  REP(i,q) {
    cin >> t;
    if (t==1) {
      rev++;
    } else {
      cin >> f >> c;
      if (f==1) {
        if (rev%2) {
          s.push_back(c[0]);
        } else {
          s.insert(0,c);
        }
      } else {
        if (rev%2) {
          s.insert(0,c);
        } else {
          s.push_back(c[0]);
        }
      }
    }
  }
  if (rev%2==1) reverse(s.begin(),s.end());
  cout << s << endl;
  return 0;
}

Measured memory_bytes: 900
def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    B = bin(K)[2:]
    B = B[::-1]
    BB = len(bin(10 ** 12)) - 2
    T = [0] * BB
    for i in range(BB):
        T[i] = sum((a & (1 << i)) >> i for a in A)
    if K == 0:
        print(sum(A))
        return
    m = 0
    def h(i, f):
        if i < 0:
            return 0
        if i >= len(B):
            return (T[i] << i) + h(i - 1, False)
        if f:
            return (max(T[i], N - T[i]) << i) + h(i - 1, f)
        if B[i] == '0':
            return (T[i] << i) + h(i - 1, False)
        return max((T[i] << i) + h(i - 1, True), ((N - T[i]) << i) + h(i - 1, False))
    print(h(BB - 1, False))

main()


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

long long lucas_number(int N) {
    long long l0 = 2;
    long long l1 = 1;

    if (N == 1) {
        return l1;
    }

    long long l = l0 + l1;

    for (int i=2; i<N; i++) {
        long long l2 = l + l1;
        l1 = l;
        l = l2;
    }

    return l;
}

int main() {
    using namespace std;

    int N;
    cin >> N;

    long long l = lucas_number(N);

    cout << l << endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner s = new Scanner(System.in);

		int[] numArr = new int[3];

		for (int i = 0; i < 3; i++) {
			numArr[i] = s.nextInt();
		}
		int K = s.nextInt();

		Arrays.sort(numArr);

		for (int i = 0; i < K; i++) {
			numArr[2] = numArr[2] * 2;
		}
		System.out.println(numArr[2] + numArr[1] + numArr[0]);
	}

}


Measured memory_bytes: 21844
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC169B
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            string[] input = Console.ReadLine().Split(' ');
            ulong M = 1;
            int over = 0;
            for (int i = 0; i < N; i++)
            {
                ulong A1 = ulong.Parse(input[i]);
                if (A1 <= 1000000000000000000 / M & A1!=0)
                {
                    M *= A1;
                }
                else
                {
                    over = -1;
                }
            }
            for (int j = 0; j < N; j++)
            {
                long Ai = long.Parse(input[j]);
                if (Ai == 0)
                {
                    M = 0;
                    over = 0;
                }
            }
            if (over == -1)
            {
                Console.WriteLine("-1");
            }
            else
            {
                Console.WriteLine(M);
            }
            //Console.WriteLine(input[0].Length);
            //Console.WriteLine(input[1].Length);
        }
    }
}


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

// エイリアス
using  ll = long signed long;
using ull = long unsigned long;
using  ld = long double;
using   P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;

// 汎用マクロ
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define FOREACH(i,q) for (auto &i : q)
#define UNIQUE(v) do { sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end()); } while (false)
#define SZ(x) ((int)(x).size())
template <class T>inline bool chmin(T &a, const T b) {if (a > b) { a = b; return true;} return false;}
template <class T>inline bool chmax(T &a, const T b) {if (a < b) { a = b; return true;} return false;}
template <class T>inline void line_out(const vector<T> vec) {int n = SZ(vec); rep(i, n) { cout << vec[i]; if(i < n-1) cout << " ";}cout << endl;}
const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1 << 28;
const ll INF64 = 1ll << 55;
const int mod = 1000000007;
//const int mod = 998244353;
struct mint
{
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a)
  {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a)
  {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a)
  {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const
  {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const
  {
    mint res(*this);
    return res -= a;
  }
  mint &operator++()
  {
    if ((x += 1) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator--()
  {
    if ((x += mod - 1) >= mod)
      x -= mod;
    return *this;
  }
  mint operator*(const mint a) const
  {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const
  {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const
  {
    return pow(mod - 2);
  }
  mint &operator/=(const mint a)
  {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const
  {
    mint res(*this);
    return res /= a;
  }
};

int main()
{
  ll n, k;
  cin >> n >> k;
  ll ans = 0;
  for(int b = 1; b <= n; ++b) {
    ll p = (n+1)/b;
    ans += p*max(b-k, 0ll);
    if(k == 0) --ans;
    ans += max(0ll, ((n+1)%b-k));
  }
  cout << ans << endl;
}


Measured memory_bytes: 3568
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <cstdio>
#include <string>
#include <vector>
#include <random>
#include <chrono>
#include <utility>
#include <numeric>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <sstream>
#include <assert.h>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <unordered_map>
using namespace std;

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(bool x) {cerr << (x ? "true" : "false");}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}

template<typename T, typename V> void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i : x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";} void _print() {cerr << "]\n";}
template <typename T, typename... V>void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifdef HOME
#warning CHECK int:ll::INT_MAX:LLONG_MAX
#define maxn 20
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define maxn 2000006
#define gcd __gcd
#define debug(x...)
#endif

#define ff first
#define endl '\n'
#define ss second
#define inf 0x3f3f3f3f
#define MOD 1000000007
#define PI 3.14159265358979323846264338327950L
#define f(i,x,n) for(int i=x;i<=n;i++)
#define fr(i,x,n) for(int i=x;i>=n;i--)
struct _ { ios_base::Init i; _() { ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); } } _;

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

bool is_month(int x) {
	return (0 < x and x < 13);
}

int main() {

	string s; cin >> s;
	int ff = stoi(s.substr(0, 2));
	int ss = stoi(s.substr(2));

	if (is_month(ff) and is_month(ss)) cout << "AMBIGUOUS";
	else if (!is_month(ff) and is_month(ss)) cout << "YYMM";
	else if (is_month(ff) and !is_month(ss)) cout << "MMYY";
	else cout << "NA";


	return 0;
}

Measured memory_bytes: 3056
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;
use rand::prelude::*;
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
#[allow(unused_imports)]
use std::f64::consts::*;
use std::time::*;

#[allow(unused)]
const INF: usize = std::usize::MAX / 4;
#[allow(unused)]
const M: usize = 1000000007;

fn ss(n: usize) -> isize {
    (n * (n + 1) / 2) as isize
}

fn calc_score(t: &Vec<usize>, c: &Vec<isize>, s: &Vec<Vec<isize>>) -> isize {
    let n = c.len();
    let d = t.len();
    let mut last = vec![0; n];
    let mut score = 0;
    for i in 0..d {
        let ti = t[i];
        score += s[i][ti];
        last[ti] = i + 1;
        for j in 0..n {
            score -= c[j] * (i + 1 - last[j]) as isize;
        }
    }
    score
}

fn initial_guess(c: &Vec<isize>, s: &Vec<Vec<isize>>) -> Vec<usize> {
    let n = c.len();
    let d = s.len();
    let mut t = vec![0; d];
    let mut last = vec![0; n];
    for i in 0..d {
        t[i] = (0..n)
            .max_by_key(|&j| {
                s[i][j]
                    - (0..n)
                        .map(|k| c[k] * (i + 1 - last[k]) as isize)
                        .sum::<isize>()
            })
            .unwrap();
        last[t[i]] = i + 1;
    }
    t
}

fn improve(
    t: &mut Vec<usize>,
    score: isize,
    c: &Vec<isize>,
    s: &Vec<Vec<isize>>,
    di: usize,
) -> isize {
    let n = c.len();
    let d = s.len();

    let mut last = vec![0; n];
    for i in 0..di {
        last[t[i]] = i + 1;
    }
    let mut next = vec![d + 1; n];
    for i in (di + 1..d).rev() {
        next[t[i]] = i + 1;
    }

    let f =
        |j| s[di][j] - c[j] * (ss(di - last[j]) + ss(next[j] - di - 2) - ss(next[j] - last[j] - 1));
    let remove_score = f(t[di]);

    t[di] = (0..n).max_by_key(|&j| f(j)).unwrap();
    score + f(t[di]) - remove_score
}

fn main() {
    let start = SystemTime::now();
    let limit = Duration::from_millis(1950);
    let n = 26;
    input! {
        d: usize,
        c: [isize; n],
        s: [[isize; n]; d],
    }
    let mut t = initial_guess(&c, &s);
    let mut rng = thread_rng();
    let mut score = calc_score(&t, &c, &s);
    let mut best_score = score;
    let mut best_t = t.clone();
    eprintln!("{}", score);
    let mut iter = 0;
    loop {
        let prev_score = score;
        for di in 0..d {
            score = improve(&mut t, score, &c, &s, di);
        }
        if prev_score == score {
            if score > best_score {
                eprintln!("{}", score);
                best_score = score;
                best_t = t.clone()
            } else {
                t = best_t.clone();
            }
            t[rng.gen_range(0, d)] = rng.gen_range(0, n);
            score = calc_score(&t, &c, &s);
        }
        iter += 1;
        if start.elapsed().unwrap() >= limit {
            break;
        }
    }
    eprintln!("{}", iter);
    eprintln!("{}", best_score);
    for &ti in &best_t {
        println!("{}", ti + 1);
    }
}


Measured memory_bytes: 2768
<?php

class Answer
{
    private $num;
    private $sequence;
    private $m;
    private $count = 0;
    private $interval;
    public function __construct()
    {
        ini_set('memory_limit', '-1');
        $this->num = fgets(STDIN);
        for ($i = 0; $i < $this->num; $i++) {
            $this->sequence[] = trim(fgets(STDIN));
        }
    }

    public function getAnswer(){
        $ans = $this->shellSort($this->sequence, $this->num);
        echo $this->m . PHP_EOL;
        echo join(' ', $this->interval) . PHP_EOL;
        echo $this->count . PHP_EOL;
        for ($i = 0; $i < count($ans); $i++) {
            echo $ans[$i] . PHP_EOL;
        }
    }

    public function insertSort($seq, $interval, $num)
    {
        for ($i = $interval; $i < $num; $i++) {
            $tmp = $seq[$i];
            $j = $i - $interval;
            while ($j >= 0 && $seq[$j] > $tmp) {
                $seq[$j + $interval] = $seq[$j];
                $j = $j - $interval;
                $this->count++;
            }
            $seq[$j + $interval] = $tmp;
        }
        return $seq;
    }

    public function shellSort($seq, $num)
    {
        for ($i = 1; $i <= $num; $i = 3 * $i + 1) {
            $this->interval[] = $i;
        }
        $this->m = count($this->interval);
        $this->interval = array_reverse($this->interval);
        for ($i = 0; $i < $this->m; $i++) {
            $seq = $this->insertSort($seq, $this->interval[$i], $num);
        }
        return $seq;
    }
}
$answer = new Answer;
$answer->getAnswer();


Measured memory_bytes: 375116
from collections import Counter

N = int(input())

Alist = list(map(int, input().split()))
counter = Counter(Alist)

Q = int(input())
Clist = []
cnt_list = []

for _ in range(Q):
    b, c = map(int, input().split())
    Clist.append(c-b)
    num = counter[b]
    cnt_list.append(num)
    counter[b] = 0
    counter[c] += num

base = sum(Alist)

for (diff, cnt) in zip(Clist, cnt_list):
    ans = base + diff * cnt
    print(ans)
    base = ans


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

using namespace std;

int a[345678];
long long ans;

int main() {
  int n;
  cin >> n;
  for (int i = 0; i < 3 * n; i++) cin >> a[i];
  sort(a, a + 3 * n);
  for (int i = 0; i < n; i++) ans += a[3 * n - 2 - 2 * i];
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1536
H, W, A, B = map(int, input().split())

line_s = '0' * A + '1' * (W - A)
opps_s = '1' * A + '0' * (W - A)

for _ in range(B):
    print(line_s)

for _ in range(H - B):
    print(opps_s)


Measured memory_bytes: 3956
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<map>
#include<iomanip>
#include<queue>
#include<stack>
#include<time.h>
//もう二度とつかわん//
//    ↓ ↓　↓　　 //
#define ll long long
//    ↑　↑　↑    //
//フェルマー方程式の恨み//
#define rep(i,n) for(int i=0;i<n;i++)
#define ggr getchar(); getchar();return 0;
using namespace std;
//素数判定
bool prime(ll n) {
	if (n == 1)return false;
	for (int i = 2; i*i <= n; i++) {
		if (n%i == 0)return false;
	}
	return true;
}
signed main() {
	ll n;
	string s;
	cin >> n >> s;
	ll cnta = 0, cntb = 0;
	rep(i, n) {
		if (s[i] == 'R')cnta++;
		else cntb++;
	}
	if (cnta > cntb)puts("Yes");
	else puts("No");
	ggr
}


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

#define rep(i, a) for (int i = 0; i < (a); ++i)
#define FORV(a, A) for (auto &a : A)

using namespace std;

using ll = long long;

void Main() {
  string S;
  cin >> S;
  ll K;
  cin >> K;

  char c = 0;
  int num = -1;
  vector<int> count;
  for (auto s : S) {
    if (c == s) {
      count[num]++;
    } else {
      count.push_back(1);
      c = s;
      num++;
    }
  }
  ll ans = 0;
  if (S[0] != S[S.size() - 1]) {
    rep(i, num + 1) ans += count[i] / 2;
    ans *= K;
  } else if (num == 0) {
    ans = (count[0] * K) / 2;
  } else {
    count[0] += count.back();
    rep(i, num) ans += count[i] / 2;
    ans *= (K - 1);

    count[0] -= count.back();
    rep(i, num + 1) ans += count[i] / 2;
  }
  cout << ans << endl;
}

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  Main();
  return 0;
}


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

int main() {	
	int n, m;
	int a[100][100]={0}, b[100]={0}, c[100]={0};
	
	cin >> n >> m;
	for (int i=0; i<n; i++) {
		for (int j=0; j<m; j++)	{
			cin >> a[i][j];
		}
	}
	for (int i=0; i<m; i++) {
		cin >> b[i];
	}
	
	for (int i=0; i<n; i++) {
		for (int j=0; j<m; j++)	{
			c[i] += a[i][j] * b[j];
		}
	}
	
	for (int i=0; i<n; i++) {
		cout << c[i] << endl;
	}
	
	return 0;
}


Measured memory_bytes: 3168
#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
#include <cmath>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <deque>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <unordered_map>
#include <bitset>
#include <sstream>
#define mop 1000000007

using namespace std;
int m[101][101] = {};

int main() {
    
    int n;
    cin >> n;
    for (int i=0;i<n;i++){
        int p,k;
        cin >> p >> k;
        for (int j=0;j<k;j++){
            int q;
            cin >> q;
            m[i+1][q] = 1;
        }
    }
    for (int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            if(j-1){
                cout << " ";
            }
            cout << m[i][j];
        }
        cout << endl;
    }


}


Measured memory_bytes: 3092
s = input()

if len(s) % 2 == 0:
    s1 = s[:int(len(s)/2)]
    s2 = s[int(len(s)/2):][::-1]
else:
    s1 = s[:int(len(s)/2)]
    s2 = s[int(len(s)/2)+1:][::-1]

#print(s1)
#print(s2)
count = 0
for i in range(len(s1)):
    if not s1[i] == s2[i]:
        count += 1

print(count)

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

using namespace std;

int main()
{
    int n;
    int sort[1000000];

    while (cin >> n, n) {
        int cnt = 0;

        for (int i = 0; i < n; i++)
            cin >> sort[i];

        for (int i = n - 1; i > 0; i--) {
            for (int j = 0; j < i; j++) {
                if (sort[j] > sort[j + 1]) {
                    swap(sort[j], sort[j + 1]);
                    cnt++;
                }
            }
        }
        cout << cnt << endl;
    }

    return 0;
}

Measured memory_bytes: 1164
#include<stdio.h>
int main(){
  int n,a,b,c,d;
  scanf("%d",&n);
  d=n%10;
  n=n/10;
  c=n%10;
  n=n/10;
  b=n%10;
  n=n/10;
  a=n%10;
  if(a+b+c+d==7){
    printf("%d+%d+%d+%d=7\n",a,b,c,d);
  }
  else if(a-b+c+d==7){
    printf("%d-%d+%d+%d=7\n",a,b,c,d);
  }
  else if(a+b-c+d==7){
    printf("%d+%d-%d+%d=7\n",a,b,c,d);
  }
  else if(a+b+c-d==7){
    printf("%d+%d+%d-%d=7\n",a,b,c,d);
  }
  else if(a-b-c+d==7){
    printf("%d-%d-%d+%d=7\n",a,b,c,d);
  }
  else if(a-b+c-d==7){
    printf("%d-%d+%d-%d=7\n",a,b,c,d);
  }
  else if(a+b-c-d==7){
    printf("%d+%d-%d-%d=7\n",a,b,c,d);
  }
  else{
    printf("%d-%d-%d-%d=7\n",a,b,c,d);
  }
  return 0;
}


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

int main() {
    int N;
    cin >> N;
    vector<P> p;
    for (int i = 0; i < N; i++)
    {
        int j;
        cin >> j;
        p.push_back(make_pair(j, i));
    }
    
    int sum = 0;
    for (auto &x : p)
    {
        if (x.first - x.second != 1)
        {
            sum++;
        }
        
    }
    
    if (sum > 2)
    {
        cout << "NO" << endl;
    } else
    {
        cout << "YES" << endl;
    }

  return 0;
}


Measured memory_bytes: 256
#include<cmath>
#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;
const int MAXN=200005;
int N,Root=1;
vector<int>P[MAXN];
int main(){
	//freopen("tree.in","r",stdin);
	//freopen("tree.out","w",stdout);
	scanf("%d",&N);
	if(int(log2(N))==log2(N)){
		printf("No\n");
		return 0;
	}
	P[1].push_back(2);
	P[2].push_back(3);
	P[3].push_back(1+N);
	P[1+N].push_back(2+N);
	P[2+N].push_back(3+N);
	for(int i=4;i<N;i+=2){
		P[Root].push_back(i);
		P[Root].push_back(i+N+1);
		P[i].push_back(i+1);
		P[i+N+1].push_back(i+N);
	}
	if(N%2==0){
		int ed=N,f=0,Sum=0;
		for(int i=25;i>=0;i--)
			if(ed&(1<<i))f=(1<<i),Sum+=f;
		int t1,t2;
		t1=f,t2=Sum-t1+N+1;
		P[ed].push_back(t1);
		P[ed+N].push_back(t2);
	}
	printf("Yes\n");
	for(int i=1;i<=2*N;i++){
		int size=P[i].size();
		for(int j=0;j<size;j++)
			printf("%d %d\n",i,P[i][j]);
	}
}

Measured memory_bytes: 10488
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		new Main().run();
	}

	private void run() {
		Scanner scanner = new Scanner(System.in);
		while (true) {
			me = scanner.nextInt();
			if (me == 0)
				break;
			n = scanner.nextInt();
			a = new int[n + 2];
			for (int i = 1; i <= n; i++)
				a[i] = scanner.nextInt();
			n += 2;
			boolean[] vis = new boolean[n];
			bfs(0, vis);
			if (!vis[n - 1]) {
				System.out.println("NG");
				continue;
			}
			boolean ok = true;
			for (int s = 1; s < n - 1; s++) {
				if (vis[s]) {
					boolean[] vis2 = new boolean[n];
					vis2[s] = true;
					bfs(s, vis2);
					if (!vis2[n - 1]) {
						ok = false;
						break;
					}
				}
			}
			System.out.println(ok ? "OK" : "NG");
		}
	}

	private void bfs(int s, boolean[] vis) {
		Deque<Integer> deque = new ArrayDeque<Integer>();
		deque.push(s);
		while (!deque.isEmpty()) {
			int x = deque.poll();
			for (int d = 1; d <= me; d++) {
				int xx = Math.min(x + d, n - 1);
				xx = Math.max(Math.min(xx + a[xx], n - 1), 0);
				if (!vis[xx]) {
					vis[xx] = true;
					deque.push(xx);
				}
			}
		}
	}

	int n, me;
	int[] a;
}

Measured memory_bytes: 62216
N, M =  (int(i) for i in input().split())
A =  [int(i) for i in input().split()]
B =  [int(i) for i in input().split()]

A.sort()
B.sort()

v = [0] * (N*M+1)
e = [0] * (N*M+1)
for i in range(N):
    for j in range(M):
        v[min(A[i],B[j])] += 1
        if A[i] == B[j]:
            e[A[i]] += 1

res = 1
vim = 0
for i in range(N*M, 0, -1):
    if v[i] == 0:
        if vim > 0:
            res *= vim
            res %= 1000000007
            vim -= 1
        else:
            res = 0
            break
    elif v[i] == 1:
        pass

    else:
        if e[i] == 0:
            res *= v[i]
            res %= 1000000007
        elif e[i] == 1:
            pass
        else:
            res = 0
            break
        vim += v[i] - 1

res %= 1000000007
print(res)

Measured memory_bytes: 18804
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
typedef long long ll ;
#define rep(i, a, b) for (int i = a; i <= b; ++ i) 
const int N = 200005 ;
using namespace std ;

int n, m, bit[N] ;
ll a[N], d[N] ;

int find(ll ave) {
	int l = 1, r = d[0] ;
	for ( ; l <= r; ) {
		int mid = (l + r) / 2 ;
		if (d[mid] == ave) return mid ;
		if (ave < d[mid]) r = mid - 1 ;
			else l = mid + 1 ;
	}
	return 0 ;
}

void put(int x) {
	for ( ; x <= d[0]; x += x & (- x)) 
		bit[x] ++ ;
}

int get(int x) {
	int ret = 0 ;
	for ( ; x; x -= x & (- x)) 
		ret += bit[x] ;
	return ret ;
}

int main() {
	scanf("%d%d", &n, &m) ;
	rep(i, 1, n) scanf("%lld", &a[i]), a[i] -= m ;
	rep(i, 2, n) a[i] += a[i - 1] ;
	rep(i, 0, n) d[++ d[0]] = a[i] ;
	sort(d + 1, d + d[0] + 1) ;
	d[0] = unique(d + 1, d + d[0] + 1) - (d + 1) ;
	put(find(a[0])) ;
	ll ans = 0 ;
	rep(i, 1, n) {
		ans += get(find(a[i])) ;
		put(find(a[i])) ;
	}
	printf("%lld\n", ans) ;
	return 0 ;
}

Measured memory_bytes: 4096
def bubble_sort(a, n)
    swap = 0
    for i in 1..(n - 1) do
        flag = false

        (n - 1).downto(i) do |j|
            if a[j - 1] > a[j]
                a[j - 1], a[j] = a[j], a[j - 1]
                swap += 1
                flag = true
            end
        end
        break unless flag
    end
    puts a.join(" ")
    return swap
end

n = gets.to_i
a = gets.split.map(&:to_i)

puts bubble_sort(a, n)



Measured memory_bytes: 6868
N, T = [int(i) for i in input().split(" ")]
c = []
t = []

for i in range(N):
    t = [int(i) for i in input().split(" ")]
    if t[1] <= T:
        c.append(t[0])
        t.append(t[1])

if c == []:
    print("TLE")
else:
    print(min(c))

Measured memory_bytes: 3060
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iomanip>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
constexpr int di[] = { 0, 1, 0, -1 }, dj[] = { 1, 0, -1, 0 };
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define sort(v) sort((v).begin(), (v).end())
#define sortr(v) sort((v).rbegin(), (v).rend())
#define all(v) (v).begin(), (v).end()
#define MAX 10000005
constexpr int inf = 100000000;

int n, a[10000000];

int main() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		scanf("%d", &a[i]);
	}
	int q, k, sum = 0;
	cin>>q;
	for (int i = 0; i < q; i++) {
		scanf("%d", &k);
		if (*lower_bound(a, a + n, k) == k) {
			sum++;
		}
	}
	cout << sum << endl;
	return 0;
}












Measured memory_bytes: 3428
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)  for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define pb emplace_back
#define eb emplace_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define ub(v,k) (upper_bound(all(v),k)-v.begin())
#define fi first
#define se second
#define pi M_PI
#define PQ(T) priority_queue<T>
#define SPQ(T) priority_queue<T,vector<T>,greater<T>>
#define dame(a) {out(a);return 0;}
#define decimal cout<<fixed<<setprecision(15);
#define dupli(a) erase(unique(all(a)),a.end())
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> PP;
typedef tuple<ll,ll,ll,ll> PPP;
typedef multiset<ll> S;
using vi=vector<ll>;
using vvi=vector<vi>;
using vvvi=vector<vvi>;
using vp=vector<P>;
using vvp=vector<vp>;
using vb=vector<bool>;
using vvb=vector<vb>;
const ll inf=1001001001001001001;
const int INF=1001001001;
const int mod=1000000007;
const double eps=1e-10;
template<class T> bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<class T> bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<class T> void out(T a){cout<<a<<'\n';}
template<class T> void outp(T a){cout<<'('<<a.fi<<','<<a.se<<')'<<'\n';}
template<class T> void outvp(T v){rep(i,v.size())cout<<'('<<v[i].fi<<','<<v[i].se<<')';cout<<'\n';}
template<class T> void outvvp(T v){rep(i,v.size())outvp(v[i]);}
template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<'\n';}
template<class T> void outvv(T v){rep(i,v.size())outv(v[i]);}
template<class T> bool isin(T x,T l,T r){return (l)<=(x)&&(x)<=(r);}
template<class T> void yesno(T b){if(b)out("yes");else out("no");}
template<class T> void YesNo(T b){if(b)out("Yes");else out("No");}
template<class T> void YESNO(T b){if(b)out("YES");else out("NO");}
template<class T> void noyes(T b){if(b)out("no");else out("yes");}
template<class T> void NoYes(T b){if(b)out("No");else out("Yes");}
template<class T> void NOYES(T b){if(b)out("NO");else out("YES");}
void outs(ll a,ll b){if(a>=inf-100)out(b);else out(a);}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll modpow(ll a,ll b){a%=mod;if(b==0)return 1;if(b&1)return a*modpow(a,b-1)%mod;ll k=modpow(a,b/2);return k*k%mod;}
ll p(ll i){
    return i*i*i*i*i;
}
int main(){
    ll n;cin>>n;
    REP(i,0,inf){
        REP(j,0,inf){
            ll k=p(i)-p(j);
            if(k<n)break;
            if(k==n){
                cout<<i<<' '<<j<<endl;
                return 0;
            }
        }
        for(ll j=-1;j>=-inf;j--){
            ll k=p(i)-p(j);
            if(k>n)break;
            if(k==n){
                cout<<i<<' '<<j<<endl;
                return 0;
            }
        }
    }
}

Measured memory_bytes: 3580
n,k=map(int,input().split())
a=list(map(int,input().split()))
x=0
for i in range(n):
    for j in range(i+1,n):
        if a[i]>a[j]:
            x+=1
y=0
for i in range(n):
    for j in range(n):
        if a[i]>a[j]:
            y+=1
cnt=(x*k)+(k*(k-1)//2*y)
print(cnt%(10**9+7))

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

int main(){
    using namespace std;
    unsigned long N;
    cin >> N;
    vector<pair<unsigned long, unsigned long>> pts(N);
    for(auto&& [x, y] : pts)cin >> x >> y;
    sort(begin(pts), end(pts), [](auto a, auto b){return a.first + a.second < b.first + b.second;});
    const auto& manhattan_distance = [](const pair<unsigned long, unsigned long>& a, const pair<unsigned long, unsigned long>& b) -> unsigned long {
        return max(a.first, b.first) + max(a.second, b.second) - min(a.first, b.first) - min(a.second, b.second);
    };
    const auto& sweep = [&pts, &manhattan_distance](const pair<unsigned long, unsigned long>& from) -> pair<unsigned long, unsigned long> {
        unsigned long now{manhattan_distance(from, pts[0])};
        pair<unsigned long, unsigned long> ret{pts[0]};
        for(const auto& i : pts)if(const auto& tmp = manhattan_distance(from, i); tmp > now){
                now = tmp;
                ret = i;
            }
        return ret;
    };
    unsigned long ans{0};
    auto p{pts[0]};
    for(unsigned long i{0}; i < 100; ++i)p = sweep(p);
    ans = max(ans, manhattan_distance(p, sweep(p)));
    sort(begin(pts), end(pts), [](auto a, auto b){return a.first + b.second < b.first + a.second;});
    p = pts[0];
    for(unsigned long i{0}; i < 100; ++i)p = sweep(p);
    ans = max(ans, manhattan_distance(p, sweep(p)));
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 6420
import java.util.HashSet;
import java.util.Scanner;

class Main {

	/*
	 * https://onlinejudge.u-aizu.ac.jp/#/problems/ALDS1_4_C
	 */

	public static void main(String[] args) {
		HashSet<String> dictionary = new HashSet<>();
		Scanner scanner = new Scanner(System.in);
		int n = Integer.parseInt(scanner.next());
		for(int i=0; i<n; i++) {
			String order = scanner.next();
			if(order.equals("find")) {
				String target = scanner.next();
				if(dictionary.contains(target)) {
					System.out.println("yes");
				}else {
					System.out.println("no");
				}
			}else {
				//order == "insert"
				dictionary.add(scanner.next());
			}
		}
		scanner.close();
	}

}



Measured memory_bytes: 259856
#include<iostream>
#include<string>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<vector>
#include<functional>
#include<iomanip>
#include<queue>
#include<cassert>
#include<tuple>
#include<set>
#include<map>
#include<list>
#include<bitset>

#define PB push_back
#define ALL(a)  (a).begin(),(a).end()
#define DWN(a)  (a).begin(),(a).end(), greater<int>()
#define rep(i, m) for (int i = 0; i < m; i++)
#define REP(i, n, m) for (int i = n; i < m; i++)

#define mod 1000000007

using namespace std;

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

const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };
const int INF = (int)1e9;

int sm[200002];
int tt[200002];

int main() {
	int n, z, w;
	cin >> n >> z >> w;
	int a[2010];
	rep(i, n) cin >> a[i];
	if (n == 1) {
		cout << abs(a[0] - w) << endl;
	}
	else {
		cout << max(abs(a[n - 1] - a[n - 2]), abs(a[n - 1] - w)) << endl;
	}
	return 0;
}

Measured memory_bytes: 256
from itertools import permutations as pe
from scipy.sparse.csgraph import floyd_warshall as wf
n,m,r=map(int,input().split())
s=[[(0 if i==j else float("inf"))for j in range(n+1)]for i in range(n+1)]
g=list(pe(list(map(int,input().split()))))
for i in range(m):
    a,b,c=map(int,input().split())
    s[a][b]=c
    s[b][a]=c
s=wf(s,directed=False)
k=float("inf")
for i in range(len(g)):
    d=g[i]
    c=0
    for j in range(1,len(d)):
        c+=s[d[j-1]][d[j]]
        if c>=k:
            break
    else:
        k=min(c,k)
print(int(k))

Measured memory_bytes: 24984
#include <stdio.h>

int main(void){
  int s, m, h;
  scanf("%d", &s);
  m = s / 60;
  h = m / 60;
  s = s % 60;
  m = m % 60;
  printf("%d:%d:%d\n", h, m, s);
  return 0;
}

Measured memory_bytes: 1836
#include<cstdio>
int main()
{
    int n,x;
    scanf("%d",&n);
    for(int i=1;i<=n;++i)
    {
	scanf("%d",&x);
	if(x&1) continue;
	if(x%3&&x%5) return puts("DENIED"),0;
    }
    puts("APPROVED");
}


Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <algorithm>
#define _USE_MATH_DEFINES
#include <cmath>
#include <numeric>
#include <iomanip>
#include <deque>
#include <tuple>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <sstream>
#include <stdexcept>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>

#define rep(i, x) for (int i = 0; i < (int)(x); i++)
#define FOR(i, a, done) for (int i = (a); i < (done); ++i)
#define all(a) (a).begin(), (a).end()
#define x first
#define y second
#define debug(a) cout << (a) << endl
namespace mp = boost::multiprecision;
using cpp_int = mp::cpp_int;
using ll = long long;
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 (a > b)
	{
		a = b;
		return 1;
	}
	return 0;
}

ll M = 1000000007;

void solve()
{
	int n,k;
	cin>>n>>k;
	vector<int>a(n);
	//int mina=1e9;
	int minplace=0;
	rep(i,n){
		cin>>a[i];
	}
	int ans=0;

	ans+=ceil((double)(n-1)/(k-1));
	cout<<ans<<endl;
}

int main()
{
	//ios::sync_with_stdio(false);
	cin.tie(nullptr);
	solve();
	return 0;
}


Measured memory_bytes: 640
from collections import defaultdict
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
AtoZ = [chr(i) for i in range(65,65+26)]
atoz = [chr(i) for i in range(97,97+26)]

def inpl(): return list(map(int, input().split()))
def inpl_s(): return list(input().split())

N = int(input())
aa = inpl()
SUM = sum(aa)
SUMaa_L = [0]
SUMaa_R = [SUM]

tmp = 0
for a in aa:
	tmp += a
	SUMaa_L.append(tmp)
	SUMaa_R.append(SUM-tmp)

cutL = []
l = 1
SUML = SUMaa_L[l]
for cutM in range(2,N-1):
	SUM = SUMaa_L[cutM]
	while SUML < SUM/2:
		l += 1
		SUML = SUMaa_L[l]
	l1,l2 = SUMaa_L[l-1], SUMaa_L[l]
	r1,r2 = SUM-l1, SUM-l2
	if abs(l1-r1) > abs(l2-r2):
		cutL.append([l2,r2])
	else:
		cutL.append([l1,r1])

cutR = []
r = N-1
SUMR = SUMaa_R[r]
for cutM in reversed(range(2,N-1)):
	SUM = SUMaa_R[cutM]
	while SUMR < SUM/2:
		r -= 1
		SUMR = SUMaa_R[r]
	l1,l2 = SUMaa_R[r+1], SUMaa_R[r]
	r1,r2 = SUM-l1, SUM-l2
	if abs(l1-r1) > abs(l2-r2):
		cutR.append([l2,r2])
	else:
		cutR.append([l1,r1])

ans = INF
for i in range(N-3):
	a,b = cutL[i]
	c,d = cutR[N-4-i]
	ans = min(ans,max(a,b,c,d)-min(a,b,c,d))

print(ans)

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

int main() {
	// your code goes here
	long long int n;
	cin >> n;
	int count;
	count=n/100000000+(n/10000000)%10+(n/1000000)%10+(n/10000)%10+(n/1000)%10+(n/100)%10+(n/10)%10+n%10+(n/100000)%10;
	if(n%count==0){
		cout << "Yes" << endl;
	}
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
#![allow(
    non_snake_case,
    unused_variables,
    unused_assignments,
    unused_mut,
    dead_code
)]
//use permutohedron::LexicalPermutation as _;
use proconio::input;
//use proconio::marker::Chars;
//use proconio::marker::Usize1;
//use std::collections::HashSet;
//use std::collections::HashMap;
//use std::collections::BTreeMap;
use std::cmp::*;
// use std::num;
fn main() {
    input! {
        X:usize,Y:usize,A:usize,B:usize,C:usize,
       mut p:[i64;A],
       mut q:[i64;B],
       mut r:[i64;C]
    }
    p.sort_by_key(|&num| Reverse(num));
    q.sort_by_key(|&num| Reverse(num));
    r.sort_by_key(|&num| Reverse(num));
    // 各林檎を食べる数をa,b,cとすると、無色をc個食べる時の総和sumを求めると？
    //let mut ans = vec![0i64; C];
    //  println!("p {:?}", p);    println!("q {:?}", q);    println!("r {:?}", r);
    let mut a = X;
    let mut b = Y;
    let mut c = 0;
    let mut sum = 0;
    for i in 0..a {
        sum += p[i]
    }
    for i in 0..b {
        sum += q[i]
    }
    //  println!("a {}, b {}, sum {}", a, b, sum);
    //ans[0] = sum;
    // ここから計算
    for c in 0..C {
        if b == 0 || (a > 0 && p[a - 1] <= q[b - 1]) {
            if p[a - 1] < r[c] {
                sum = sum - p[a - 1] + r[c];
                a -= 1;
            }
        } else {
            if b > 0 && q[b - 1] < r[c] {
                sum = sum - q[b - 1] + r[c];
                b -= 1;
            }
        }
        if a == 0 && b == 0 {
            break;
        }
    }
    println!("{}", sum);
}


Measured memory_bytes: 7700
#include <iostream>
#include <string>

int main()
{
	std::string A[50], B[50];
	int N, M;

	std::cin >> N >> M;
	int i;
	for( i = 0; i < N; i++ ){
		std::cin >> A[i];
	}
	for( i = 0; i < M; i++ ){
		std::cin >> B[i];
	}

	int j;
	//A中にBを探すための始点を指定
	for( i = 0; i < N - M + 1; i++ ){
		for( j = 0; j < N - M + 1; j++ ){
			//AとBの一致を一列ずつ見る
			int k;
			for( k = 0; k < M; k++ ){
				if( A[i + k].substr(j, M) != B[k] ){	//文字列.substr(始点の位置, 切り出す文字数)
					break;
				}
				if( k == M - 1 ){
					std::cout << "Yes" << std::endl;
					return 0;
				}
			}
		}
	}

	std::cout << "No" << std::endl;

	return 0;
}

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


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

void solve() {
    double L; cin >> L;
    long double l = L/3.0;
    cout << fixed << setprecision(10) << powl(l, 3.0);
    // cout << ans << "\n";
}

signed main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    solve();
    return 0;
}

Measured memory_bytes: 640