akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
// #define int ll
using PII = pair<ll, ll>;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()

template<typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template<typename T> bool IN(T a, T b, T x) { return a<=x&&x<b; }
template<typename T> T ceil(T a, T b) { return a/b + !!(a%b); }

template<typename T> vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts) {
    return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type
fill_v(T &t, const V &v) { t=v; }
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t, const V &v ) { for(auto &e:t) fill_v(e,v); }

template<class S,class T>
ostream &operator <<(ostream& out,const pair<S,T>& a) {
    out<<'('<<a.first<<','<<a.second<<')'; return out;
}
template<class T>
ostream &operator <<(ostream& out,const vector<T>& a){
    out<<'[';
    for(const T &i: a) out<<i<<',';
    out<<']';
    return out;
}
template<class T>
ostream &operator <<(ostream& out, const set<T>& a) {
    out<<'{';
    for(const T &i: a) out<<i<<',';
    out<<'}';
    return out;
}
template<class T, class S>
ostream &operator <<(ostream& out, const map<T,S>& a) {
    out<<'{';
    for(auto &i: a) out<<i<<',';
    out<<'}';
    return out;
}

int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0}; // DRUL
const int INF = 1<<30;
const ll LLINF = 1LL<<60;
const ll MOD = 1000000007;

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

    ll n, m, c;
    cin >> n >> m >> c;
    vector<ll> b(m);
    vector<vector<ll>> a(n, vector<ll>(m));
    REP(i, m) cin >> b[i];
    REP(i, n) REP(j, m) cin >> a[i][j];

    ll ans = 0;
    REP(i, n) {
        ll sum = c;
        REP(j, m) {
            sum += a[i][j] * b[j];
        }
        if(sum > 0) ans++;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<string>
#include<cctype>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
        int S;
        scanf("%d",&S);
        printf("%d:%d:%d\n",S/3600,(S-((S/3600)*3600))/60,S%60);
        return 0;
}

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


signed main()
{
 
ios_base::sync_with_stdio(false);
cin.tie(NULL);  
cout.tie(0);   
 
#ifndef ONLINE_JUDGE
    if(fopen("INPUT.txt","r"))
    {
    freopen ("INPUT.txt" , "r" , stdin);
    freopen ("OUTPUT.txt" , "w" , stdout);
    }
#endif      

    int x,y;
    int deg[5]={0};
    for(int i=0;i<3;i++)
    {
        cin>>x>>y;
        deg[x]++;
        deg[y]++;
    }
    sort(deg+1,deg+5);
    if(deg[1]==1 && deg[2]==1 && deg[3]==2 && deg[4]==2)
    {
        cout<<"YES";
    }
    else
    {
        cout<<"NO";
    }
    

}

Measured memory_bytes: 3600
/*
    Author:zeke
    
    pass System Test!
    GET AC!!
*/
#include <iostream>
#include <queue>
#include <vector>
#include <iostream>
#include <vector>
#include <string>
#include <cassert>
#include <algorithm>
#include <functional>
#include <cmath>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <map>
#include <iomanip>
#include <utility>
#include <stack>
#include <bitset>
using ll = long long;
using ld = long double;
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define rep3(var, min, max) for (ll(var) = (min); (var) < (max); ++(var))
#define repi3(var, min, max) for (ll(var) = (max)-1; (var) + 1 > (min); --(var))
#define Mp(a, b) make_pair((a), (b))
#define F first
#define S second
#define Icin(s) \
    ll(s);      \
    cin >> (s);
#define Scin(s) \
    ll(s);      \
    cin >> (s);
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 pair<ll, ll> P;
typedef vector<ll> V;
typedef vector<V> VV;
typedef vector<P> VP;
ll mod = 1e9 + 7;
ll MOD = 1e9 + 7;
ll INF = 1e18;
const int MAX = 1e7;
long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
ll S(ll p, ll y)
{
    return COM(p + 1, y + 1);
}
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    COMinit();
    ll r1, c1, r2, c2;
    cin >> r1 >> c1 >> r2 >> c2;
    ll res = 0;
    rep3(i, c1, c2 + 1)
    {
        res += S(r2 + i, i) + MOD;
        res -= S(r1 + i - 1, i);
        res %= MOD;
    }
    cout << res << endl;
}


Measured memory_bytes: 234624
#include <stdio.h>

int main(void)
{
    char map[16][16];
    int i,j;
    int flag;

    while (scanf("%s", map[0]) != EOF){
        for (i = 1; i < 8; i++){
            scanf("%s", map[i]);
            for (j = 8; j <= 15; j++){
                map[i][j] = '0';
            }
        }
        for (i = 8; i <= 15; i++){
            for (j = 0; j <= 15; j++){
                map[i][j] = '0';
            }
        }
        
        flag = 0;
        for (i = 0; i < 8; i++){
            for (j = 0; j < 8; j++){
                if (map[i][j] == '1'){
                    if (map[i][j+1] == '1' && map[i+1][j] == '1' && map[i+1][j+1] == '1'){
                        printf("A\n");
                        flag = 1;
                        break;
                    }else if (map[i+3][j] == '1'){
                        printf("B\n");
                        flag = 1;
                        break;
                    }else if (map[i][j+3] == '1'){
                        printf("C\n");
                        flag = 1;
                        break;
                    }else if (map[i+2][j-1] == '1'){
                        printf("D\n");
                        flag = 1;
                        break;
                    }else if (map[i+1][j+2] == '1'){
                        printf("E\n");
                        flag = 1;
                        break;
                    }else if (map[i+2][j+1] == '1'){
                        printf("F\n");
                        flag = 1;
                        break;
                    }else{
                        printf("G\n");
                        flag = 1;
                        break;
                    }

                }
            }
            if (flag == 1){
                break;
            }
        }

    }
    return (0);
}



Measured memory_bytes: 2028
parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
    K, N = parseMap(split(readline()))
    A = parseMap(split(readline()))
    A = [A;A[1]+K]
    B = diff(A)
    C = sum(B) - maximum(B)
    println(C)
end

main()

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

int main() {
  int n;
  cin >> n;
  deque<int> q;
  for(auto i = 0; i < n; ++i) {
    int a;
     cin >> a;
    if(i&1) q.emplace_front(a);
    else    q.emplace_back(a);
  }
  if(n&1) {
    auto first = true;
    while(!q.empty()) {
      if(!first) cout << " ";
      first = false;
      cout << q.back();
      q.pop_back();
    }
    cout << endl;
  } else {
    auto first = true;
    while(!q.empty()) {
      if(!first) cout << " ";
      first = false;
      cout << q.front();
      q.pop_front();
    }
    cout << endl;
  }
}


Measured memory_bytes: 2944
#line 1 "/workspaces/compro/lib/template.hpp"


#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) (v).begin(), (v).end()
#define coutd(n) cout << fixed << setprecision(n)
#define ll long long int
#define vl vector<ll>
#define vi vector<int>
#define MM << " " <<

using namespace std;

template <class T> void say(bool val, T yes, T no) { cout << (val ? yes : no) << "\n"; }

void say(bool val, string yes = "Yes", string no = "No") { say<string>(val, yes, no); }

template <class T> void chmin(T &a, T b) {
  if (a > b)
    a = b;
}

template <class T> void chmax(T &a, T b) {
  if (a < b)
    a = b;
}

// C++ 17に完全移行したら消す
// 最大公約数を求める
template <class T> T gcd(T n, T m) { return n ? gcd(m % n, n) : m; }

// 最小公倍数を求める
template <class T> T lcm(T n, T m) {
  int g = gcd(n, m);
  return n * m / g;
}

// 重複を消す。計算量はO(NlogN)
template <class T> void unique(std::vector<T> &v) {
  std::sort(v.begin(), v.end());
  v.erase(std::unique(v.begin(), v.end()), v.end());
}


#line 2 "abc172_b.cpp"

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

  string s, t;
  cin >> s >> t;
  int n = s.length();
  int ans = 0;
  REP(i, n) {
    if (s[i] != t[i]) {
      ans++;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 3732
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int maxn=2e5+5;
int a[maxn];
int ans[maxn];
int d[maxn];
int vis[maxn];
vector<int>E[maxn];
int n;
int len;
void dfs(int fa)
{
    vis[fa]=1;
    int blen,be=0;
    int p;
    for(auto &v:E[fa])
    {
        if(vis[v])
            continue;
        blen=len;
        if(d[len]<a[v])
        {
            d[++len]=a[v];
        }
        else
        {
            p=lower_bound(d+1,d+1+len,a[v])-d;
            be=d[p];
            d[p]=a[v];
        }
        ans[v]=len;
        dfs(v);
        if(be)d[p]=be;
        len=blen;
    }

}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>n;
	for(int i=1;i<=n;i++)
    {
        cin>>a[i];
    }
    for(int i=1;i<n;i++)
    {
        int u,v;
        cin>>u>>v;
        E[u].push_back(v);
        E[v].push_back(u);
    }
    d[1]=a[1];
    len=1;
    dfs(1);
    ans[1]=1;
    for(int i=1;i<=n;i++)
    {
        cout<<ans[i]<<'\n';
    }
}


Measured memory_bytes: 31300
from sys import stdin, setrecursionlimit


def main():
    n = int(stdin.readline())
    s = [stdin.readline()[:-1] for _ in range(n)]
    keys = list(set(s))
    keys.sort()
    summary = {}

    for key in keys:
        summary[key] = 0

    m = 0
    for si in s:
        summary[si] += 1
        m = max(summary[si], m)

    for key in keys:
        if summary[key] == m:
            print(key)


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()

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

using namespace std;

int main() {
	int sx, sy, tx, ty;
	cin >> sx >> sy >> tx >> ty;
	for (int i = sx; i < tx; i++) {
		cout << "R";
	}
	for (int i = sy; i < ty; i++) {
		cout << "U";
	}
	for (int i = sx; i < tx; i++) {
		cout << "L";
	}
	for (int i = sy; i < ty; i++) {
		cout << "D";
	}
	cout << "D";
	for (int i = sx; i < tx + 1; i++) {
		cout << "R";
	}
	for (int i = sy; i < ty + 1; i++) {
		cout << "U";
	}
	cout << "L";
	cout << "U";
	for (int i = sx; i < tx + 1; i++) {
		cout << "L";
	}
	for (int i = sy; i < ty + 1; i++) {
		cout << "D";
	}
	cout << "R\n";
}

Measured memory_bytes: 256
Inlist = []

while True:
    val = list(map(int, input().split()))
    H, W = val[0], val[1]
    if H == 0 and W == 0:
        break
    else:
        Inlist.append(val)
    
for HW in Inlist:
    H, W = HW[0], HW[1]
    for h in range(H):
        if h == 0 or h == H-1:
            print('#'*W,end='\n')
        else:
            print('#'+'.'*(W-2)+'#',end='\n')
    print()


Measured memory_bytes: 5620
// Akshit Awasthi
#include <bits/stdc++.h>
#define int long long
#define float long double
#define pb push_back
#define all(x) x.begin(), x.end()
#define fastio                    \
    std::ios::sync_with_stdio(0); \
    std::cin.tie(NULL);           \
    std::cout.tie(NULL)
#define mod1 1000000007
#define mod2 998244353
#define INF 1e18
#define PI 3.1415926535
using namespace std;

const int mod = mod2;

int power(int a, int n, int p = mod) {
    if (n < 0)
        return 0;
    int ans = 1;
    while (n) {
        if (n & 1)
            ans = (ans * a) % p;
        a = (a * a) % p;
        n >>= 1;
    }
    return ans;
}

int inverse(int x, int p = mod) {
    return power(x, p - 2);
}

const int maxN = 2e6 + 1;
int powers[maxN];
int t[4 * maxN], lazy[4 * maxN], pwsum[maxN];

void pre(void) {
    powers[0] = 1;
    for (int i = 1; i < maxN; i++) {
        powers[i] = (10 * powers[i - 1]) % mod;
    }
}

void build(int v, int tl, int tr) {
    if (tl > tr)
        return;
    if (tl == tr) {
        pwsum[v] = powers[tl];
    } else {
        int tm = (tl + tr) / 2;
        build(v * 2, tl, tm);
        build(v * 2 + 1, tm + 1, tr);
        pwsum[v] = (pwsum[v * 2] + pwsum[v * 2 + 1]) % mod;
    }
    t[v] = pwsum[v];
}

void push(int v) {
    if (lazy[v] == -1)
        return;
    t[v * 2] = (lazy[v] * pwsum[v * 2]) % mod;
    t[v * 2 + 1] = (lazy[v] * pwsum[v * 2 + 1]) % mod;
    lazy[v * 2] = lazy[v];
    lazy[v * 2 + 1] = lazy[v];
    lazy[v] = -1;
}

void update(int v, int tl, int tr, int l, int r, int addend) {
    if (l > r)
        return;
    // push(v);
    if (l == tl && tr == r) {
        t[v] = (pwsum[v] * addend) % mod;
        lazy[v] = addend;
        return;
    } else {
        push(v);
        int tm = (tl + tr) / 2;
        update(v * 2, tl, tm, l, min(r, tm), addend);
        update(v * 2 + 1, tm + 1, tr, max(l, tm + 1), r, addend);
        t[v] = (t[v * 2] + t[v * 2 + 1]) % mod;
    }
}

void solve(void) {
    int n, q;
    cin >> n >> q;
    // reverse(powers, powers + n);
    build(1, 0, n - 1);
    for (int i = 0; i < 4 * maxN; i++) lazy[i] = -1;
    // cout << t[1] << '\n';
    while (q--) {
        int l, r, d;
        cin >> l >> r >> d;
        // l--;
        // r--;
        l = n - l;
        r = n - r;
        swap(l, r);
        update(1, 0, n - 1, l, r, d);
        cout << t[1] << '\n';
    }
}

int32_t main(void) {
#ifdef AKSHIT_PC
    cout.setf(ios::unitbuf);
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    freopen("error.txt", "w", stderr);
#endif
    fastio;
    pre();
    int t = 1;
    // cin >> t;
    for (int i = 1; i <= t; i++) {
        // cout << "Case #" << i << ": ";
        solve();
    }
    return 0;
}


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

a = sorted(list(map(int, input().split())))

ans = 0
d_min = a[-1]
for i in range(n-1):
  d = abs(a[-1]/2 - a[i])
  if d < d_min:
    d_min = d
    ans = a[i]
    
print('{} {}'.format(a[-1], ans))


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

//const int mod = 1000000007;
const int mod = 998244353;
template<typename T,T MOD = 1000000007>
struct Mint{
    static constexpr T mod = MOD;
    T v;
    Mint():v(0){}
    Mint(signed v):v(v){}
    Mint(long long t){v=t%MOD;if(v<0) v+=MOD;}

    Mint pow(long long k){
        Mint res(1),tmp(v);
        while(k){
            if(k&1) res*=tmp;
            tmp*=tmp;
            k>>=1;
        }
        return res;
    }

    static Mint add_identity(){return Mint(0);}
    static Mint mul_identity(){return Mint(1);}

    Mint inv(){return pow(MOD-2);}

    Mint& operator+=(Mint a){v+=a.v;if(v>=MOD)v-=MOD;return *this;}
    Mint& operator-=(Mint a){v+=MOD-a.v;if(v>=MOD)v-=MOD;return *this;}
    Mint& operator*=(Mint a){v=1LL*v*a.v%MOD;return *this;}
    Mint& operator/=(Mint a){return (*this)*=a.inv();}

    Mint operator+(Mint a) const{return Mint(v)+=a;}
    Mint operator-(Mint a) const{return Mint(v)-=a;}
    Mint operator*(Mint a) const{return Mint(v)*=a;}
    Mint operator/(Mint a) const{return Mint(v)/=a;}

    Mint operator-() const{return v?Mint(MOD-v):Mint(v);}

    bool operator==(const Mint a)const{return v==a.v;}
    bool operator!=(const Mint a)const{return v!=a.v;}
    bool operator <(const Mint a)const{return v <a.v;}

    static Mint comb(long long n,int k){
        Mint num(1),dom(1);
        for(int i=0;i<k;i++){
            num*=Mint(n-i);
            dom*=Mint(i+1);
        }
        return num/dom;
    }
};
template<typename T,T MOD> constexpr T Mint<T, MOD>::mod;
template<typename T,T MOD>
ostream& operator<<(ostream &os,Mint<T, MOD> m){os<<m.v;return os;}
template<typename T,T MOD>
istream& operator>>(istream &os,Mint<T, MOD> &m){os>>m.v;return os;}

// https://github.com/atcoder-live/library/blob/master/comb.cpp
template<typename T,T MOD = 1000000007>
struct combination{
    vector<Mint<T, MOD>> fact, ifact;
    combination(int n): fact(n+1), ifact(n+1) {
        assert(n < mod);
        fact[0] = 1;
        for(int i = 1; i <= n; ++i) {
            fact[i] = fact[i-1]*i;
        }
        ifact[n] = fact[n].inv();
        for(int i = n; i >= 1; --i) {
            ifact[i-1] = ifact[i]*i;
        }
    }
    Mint<T, MOD> operator ()(int n, int k) {
        if(k < 0 || k > n) return Mint<T, MOD>(0);
        return fact[n]*ifact[k]*ifact[n-k];
    }
};

int main() {
    int n, m, k;
    cin >> n >> m >> k;
    combination<long long, mod> c(n + 10);
    Mint<long long, mod> ans(0);
    Mint<long long, mod> col(m);
    for(int x = n-1; x >= 0; --x) {
        Mint<long long, mod> now = col;
        now *= c(n-1, n - 1 - x);
        if( x <= k) ans += now;
        col *= m - 1;
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin >> n;
    vector <long long> a(n,0);
    for (int i=0; i<n; i++){
        cin >> a[i];
    }
    long long m = 0;
    int f = 1;
    long long prev = -1;
    for (int i=n-1; i>=0; i--){
        if (a[i] > i){
            f = 0;
            break;
        }
        else{
            if (a[i] < prev-1){
                f = 0;
                break;
            }
            else{
                if (a[i] == prev -1){

                }
                else{
                    m+=a[i];
                }
            }
            prev = a[i];
        }
    }
    if (f){
        cout << m;
    }
    else{
        cout << "-1";
    }
    return 0;
}

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

void print6(int a, int b)
{
  cout << setfill('0') << right << setw(6) << a;
  cout << setfill('0') << right << setw(6) << b << endl;
  cout << setfill(' ');
}

struct tri{
  int a;
  int b;
  int c;

  bool operator<(const tri &another) const
  {
    if(a != another.a)
      return a < another.a;

    if(b != another.b)
      return b < another.b;

    return c < another.c;
  };
};

int main(void)
{
  int N, M;
  cin >> N >> M;
  vector<tri> vp(M);
  //vector<vector<int> > vv(N, vector<int>(M, 0));
  for(int i = 0; i < M; i++){
    cin >> vp[i].a >> vp[i].b;
    vp[i].c = i;
  }
  sort(vp.begin(), vp.end());
  int cnt = 1;
  int last_p = 0;
  vector<tri> ans(M);
  for(int i = 0; i < M; i++){
    if(last_p != vp[i].a){
      last_p = vp[i].a;
      cnt = 1;
    }
    ans[i].a = vp[i].c;
    ans[i].b = vp[i].a;
    ans[i].c = cnt;
    cnt++;
  }

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

  for(int i = 0; i < M; i++){
    print6(ans[i].b, ans[i].c);
  }
}


Measured memory_bytes: 3840
import java.util.*;

public class Main {

	public static int span; // 何日間のスケジューリングをするか
	public static int minus[]; // 26種類のコンテストの飽きやすさ
	public static int plus[][]; // 26種類のコンテストの満足感

	public static void main(String[] args) {

		// 入力
		Scanner sc = new Scanner(System.in);
		span = Integer.parseInt(sc.next()); // 何日間のスケジューリングをするか
		minus = new int[26]; // 26種類のコンテストの飽きやすさ
		for (int i = 0; i < 26; i++) {
			minus[i] = Integer.parseInt(sc.next());
		}
		plus = new int[span][26]; // 26種類のコンテストの満足感
		for (int d = 0; d < span; d++) {
			for (int i = 0; i < 26; i++) {
				plus[d][i] = Integer.parseInt(sc.next());
			}
		}

		// 適当にスケジュールを作って提出してみる

		// 26種類のコンテストを順番に開催
		int input1[] = new int[span];
		for (int d = 0; d < span; d++) {
			input1[d] = (d % 26) + 1;
		}
		int output1 = calc(input1);
		// System.out.println("満足度結果： "output1);

		for (int d = 0; d < span; d++) {
			System.out.println(input1[d]);
		}

	}

	public static int calc(int[] input) {

		int last[] = new int[26]; // 各コンテストが最終開催日から何日経過しているか
		int result = 0; // ユーザ満足度

		for (int d = 0; d < span; d++) {

			// lastの更新
			for (int i = 0; i < 26; i++) {
				if (i == input[d] - 1) {
					last[i] = 0;
				} else {
					last[i]++;
				}
			}

			// 開催による満足度アップ
			result += plus[d][input[d] - 1];

			// 日数経過による満足度ダウン
			for (int i = 0; i < 26; i++) {
				result -= minus[i] * last[i];
			}
		}

		return result;
	}
}


Measured memory_bytes: 42764
use proconio::{input, fastout};

#[fastout]
fn main() {
    input! {
        h: usize, w: usize,
        mut costs: [[usize; 10]; 10],
        arr: [[i8; w]; h],
    }

    for k in 0..10 {
        for i in 0..10 {
            for j in 0..10 {
                costs[i][j] = std::cmp::min(costs[i][j], costs[i][k]+costs[k][j])
            }
        }
    }

    let mut ans = 0;
    for ai in arr {
        for aij in ai {
            if aij >= 0 { ans += costs[aij as usize][1]; }
        }
    }

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


Measured memory_bytes: 2324
#include<bits/stdc++.h>
using namespace std;
map<string,int> m;
string s,t,u;
int n,len;
void init();

int getx(){
  int res=0,f=0;
  for(int i=0;i<len;i++){
    if('1'<=s[i]&&s[i]<='9')f=1;
    if(f&&s[i]!='.')res++;
  }
  return res;
}

void solve(){
  int p=-1,x=getx(),a;
  for(int i=0;i<len;i++)
    if(s[i]=='.')p=i;
  if(p==-1)s+='.',p=len++;
  if(m.find(t)!=m.end()){
    a=m[t]; 
    for(int i=0;i<abs(a);i++)
      if(a>0)
	if(p==len-1)s[len-1]='0',s+='.',p=len++;
	else swap(s[p],s[p+1]),p++;
      else
	if(p==0)s[0]='0',s='.'+s,len++;
	else swap(s[p],s[p-1]),p--;
  }
  int idx=0,ansidx;
  for(int i=0;i<len;i++)
    if('1'<=s[i]&&s[i]<='9'){
      idx=i;
      break;
    }
  ansidx=p-idx-1;
  if(p<idx)ansidx++;
  int cnt=0,z=0;
  for(int i=0;i<len;i++){
    if(s[i]=='.')continue;
    if(s[i]!='0'){
      z=i;
      break;
    }
  }
  while(cnt<x){
    if(cnt==1)cout<<'.';
    if(s[z]=='.')z++;
    cout<<s[z],z++,cnt++;
  }
  cout<<" * 10^"<<ansidx<<' '<<u<<endl;
}

int main(){
  init();
  cin>>n;
  while(n--){
    cin>>s>>t;
    len=s.size();
    if(m.find(t)!=m.end()){
      cin>>u;
    }else u=t;
    solve();
  }
  return 0;
}

void init(){
  m["yotta"]=24; m["zetta"]=21;
  m["exa"]=18; m["peta"]=15;
  m["tera"]=12; m["giga"]=9;
  m["mega"]=6; m["kilo"]=3;
  m["hecto"]=2; m["deca"]=1;
  m["deci"]=-1; m["centi"]=-2;
  m["milli"]=-3; m["micro"]=-6;
  m["nano"]=-9; m["pico"]=-12;
  m["femto"]=-15; m["ato"]=-18;
  m["zepto"]=-21; m["yocto"]=-24;
}

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

int main() {
//  freopen("in.txt", "r", stdin);
//  freopen("out.txt", "w", stdout);
  int n, k;
  cin >> n >> k;
  cout << 1 + (n - 2) / (k - 1);
  return 0;
}


Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)

func Scanner() string {
	sc.Scan()
	return sc.Text()
}

func main() {
	buf := make([]byte, 0)
	sc.Buffer(buf, 100000007)
	sc.Split(bufio.ScanWords)
	n, _ := strconv.Atoi(Scanner())
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i], _ = strconv.Atoi(Scanner())
	}
	ans := 0
	l := make([]int, n)
	s := make([]int, n)
	for i := 0; i < n; i++ {
		if a[i]+i < n {
			l[a[i]+i]++
		}
		if i-a[i] > 0 {
			s[i-a[i]]++
		}
	}
	for i := 0; i < n; i++ {
		ans += l[i] * s[i]
	}
	fmt.Println(ans)
}

Measured memory_bytes: 8024
#include <iostream>
#include <string>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
using namespace std;

int main(){
    int a, b, c;
    cin >> a >> b >> c;
    int ans = a*b*c / max(max(a, b), c) / 2;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import sys


def main():
    N = int(sys.stdin.readline().rstrip())
    A = [int(x) for x in sys.stdin.readline().rstrip().split()]

    A.sort(reverse=True)

    B = []
    for j in range(N // 2 + 1):
        B.append(A[j])
        B.append(A[j])

    # print(B[:N])
    B[0] = 0

    print(sum(B[:N]))


main()


Measured memory_bytes: 31572
/*
name:       Egyptian Tourist
PlatForm:   CodeForces/SPOJ...etc
LANG:       C++
DIV:        Training
TIME:       *
RATE:       *
*/

/*
Time Consumed:*
Problem Topics: *
*/
#include <bits/stdc++.h>
#include <iostream>

using namespace std;
//----------------------------------//

typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;

//-------------------------------------------------------//
#define rep(i,a,b) for (int i = (a), _b = (b); i <= _b; i++)
#define repr(i,a,b) for (int i = (a), _b = (b); i >= _b; i--)
#define lp(i,n) for (int i = 0, _n = (n); i < _n; i++)
#define lpr(i,n) for (int i = (n) - 1; ~i; i--)
#define foreach(it, ar) for ( typeof(ar.begin()) it = ar.begin(); it != ar.end(); it++ )
//-------------------------------------------------------------------------------------//

#define clr(ar, val) memset(ar, val, sizeof(ar))
//----------------------------------------------//

#define inn freopen("in.in","r",stdin)
#define outt freopen("out.out","w",stdout)
#define PI 3.1415926535897932385
#define ll long long
#define ull unsigned long long
#define mp make_pair
#define pb push_back
#define pob pop_back
#define bit(n) (1<<(n))
#define Last(i) ( (i) & (-i) )
#define all(v) ((v).begin()), ((v).end())
#define sq(x) ((x) * (x))
#define INF INT_MAX
#define Ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);

//-------------------------------------------------------------//
#ifndef DEBUG
#define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1)
{
    cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args)
{
    const char* comma = strchr(names + 1, ',');
    cerr.write(names, comma - names) << " : " << arg1<<" | ";
    __f(comma+1, args...);
}
#else
#define debug(...)
#endif
//------------------------------------------------------------//
template<class T, class T2>
T _f_pow(T a, T2 b)
{
    T res = 1;
    while (b > 0)
    {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}
#define N (int)1e5 + 5
int _h[N];
int dp[N];
int n;

int solve()
{
    //printf("Solve(%d)\n", i);
    for(int i = 2; i <= n; i++)
    {
        dp[i] = dp[i-1] + abs(_h[i] - _h[i-1]);
        if(i > 2)
            dp[i] = min(dp[i], dp[i-2] + abs(_h[i] - _h[i-2]));
    }
    return dp[n];
}
int main()
{
    Ios;
    //inn;//outt;
    //auto tt = clock();
    cin >> n;
    rep(i, 1, n)
        cin >> _h[i];
//    lp(i, n)
//      printf("%d\t", _h[i]);
//      system("pause 5");
    //clr(dp, -1);
    printf("%d\n", solve());
    //cout << (double(clock() - tt)/CLOCKS_PER_SEC * 1.00) << endl;
    return 0;
}


Measured memory_bytes: 1152
#include<bits/stdc++.h>
using namespace std;
int main()
{
       int n,m,a,b,i,j,t;
       while(cin>>a>>b)
       {
              if(a==b)
              {
                     cout<<a<<endl;
              }
              else if(a<b)
              {
                     cout<<a<<endl;
              }
              else cout<<a-1<<endl;
       }
       return 0;
}



Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

namespace AtCoderCs
{
    class Program
    {
        static void Main()
        {

            var Arg = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray();


            if (Arg[0] < Arg[2])
            {

                Arg[2] -= Arg[0];
                Arg[0] = 0;

                if (Arg[1] < Arg[2])
                {

                    Arg[1] = 0;

                }
                else Arg[1] -= Arg[2];

            }
            else
            {

                Arg[0] -= Arg[2];

            }

            Console.WriteLine(Arg[0] + " " + Arg[1]);

        }

    }
}


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

int main(){
    long long n, k;
    std::cin >> n >> k;
    
    long long nkNum = n/k;
    long long nkHalfNum = 0;
    if(k%2 == 0){
        nkHalfNum = (n + k/2)/k;
    }
    
    long long ans = nkNum*nkNum*nkNum + nkHalfNum*nkHalfNum*nkHalfNum;
    std::cout << ans << std::endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <list>

using namespace std;

#ifdef _MSC_VER
#define __typeof__ decltype
template <class T> int __builtin_popcount(T n) { return n ? 1 + __builtin_popcount(n & (n - 1)) : 0; }
#endif

#define foreach(it, c) for (__typeof__((c).begin()) it=(c).begin(); it != (c).end(); ++it)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define popcount __builtin_popcount

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

template <class T> void max_swap(T& a, const T& b) { a = max(a, b); }
template <class T> void min_swap(T& a, const T& b) { a = min(a, b); }

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

const double PI = acos(-1.0);
const int dx[] = { 0, 1, 0, -1 };
const int dy[] = { 1, 0, -1, 0 };



int roman_to_n(const string& s)
{
	static const int num[] = { 1, 5, 10, 50, 100, 500, 1000 };
	static const char* roman = "IVXLCDM";

	vector<int> digits(s.size());
	for (int i = 0; i < s.size(); ++i)
		digits[i] = num[strchr(roman, s[i]) - roman];

	int res = accumulate(digits.begin(), digits.end(), 0);
	for (int i = 0; i < digits.size() - 1; ++i)
		if (digits[i] < digits[i + 1])
			res -= 2 * digits[i];
	return res;
}
string to_roman(int n)
{
	static const char* roman[][10] = {
		{ "", "I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX" }, 
		{ "", "X", "XX", "XXX", "XL", "L", "LX", "LXX", "LXXX", "XC" },
		{ "", "C", "CC", "CCC", "CD", "D", "DC", "DCC", "DCCC", "CM" },
		{ "", "M", "MM", "MMM", "MMMM", "MMMMM" },
	};

	stringstream res;
	for (int i = 3, j = 1000; i >= 0; --i, j /= 10)
		res << roman[i][(n / j) % 10];
	return res.str();
}
int main()
{
	string s;
	while (cin >> s)
		cout << roman_to_n(to_roman(roman_to_n(s))) << endl;
}

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

#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define MIN(a) *min_element(all(a))
#define MAX(a) *max_element(all(a))
#define SUM(a, b) accumulate(all(a), b)
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define RREP(i, n) for(int (i)=(n)-1; (i)>=0; (i)--)
#define FOR(i, m, n) for(int (i)=(m); (i)<(n); i++)
#define FORR(i, m, n) for(int (i)=(n)-1; (i)>=(m); i--)
#define ios() cin.tie(0), ios::sync_with_stdio(false)
#define debug(x) cerr << #x << " = " << x << endl
//#define int long long

typedef long long ll;
typedef unsigned long long ull;
//ll const MOD = 998244353;
ll const MOD = 1e9+7;
ll const INF = 1e18;

template<typename T> int size(const T& a){return (int)a.size();}
template<typename T> T Div(T a, T b){return (a + b - 1) / b;}
template<typename T> bool chmin(T& a, const T& b){if(a > b){a = b; return true;} return false;}
template<typename T> bool chmax(T& a, const T& b){if(a < b){a = b; return true;} return false;}



signed main(){
    int n, k;
    string s;
    cin >> n >> k >> s;

    queue<int> que;
    que.push(0);

    int ans = 0, flag = s[0] - '0', cnt = 1 - (s[0] - '0');

    for(int i=1; i<n; i++){
        if(s[i] == '1' && s[i-1] == '0') que.push(i);
        if(s[i] == '0' && s[i-1] == '1'){
            cnt++;
            if(cnt > k){
                int l = que.front();
                que.pop();
                chmax(ans, i - l);
            }
        }
    }

    chmax(ans, n - que.front());



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

Measured memory_bytes: 512
using System;
using System.Linq;

namespace AtCoder {
    class Program {

        static void Main() {
            long[] abn = Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
            long a = abn[0], b = abn[1], n = abn[2];
            long x = b - 1 <= n ? b - 1 : x = n;
            Console.WriteLine(a * x / b - a * (x / b));
        }
    }
}

Measured memory_bytes: 28240
package main

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

const mod = 1000000007

var cs [][]int

func initCmb(x int) {
	cs = make([][]int, x+1)
	for i := range cs {
		cs[i] = make([]int, i+1)
		cs[i][0], cs[i][len(cs[i])-1] = 1, 1
		for j := 1; j < len(cs[i])-1; j++ {
			cs[i][j] = (cs[i-1][j-1] + cs[i-1][j]) % mod
		}
	}
}

func cmb(x, y int) int {
	if y > x {
		return 0
	}
	return cs[x][y]
}

func max(x, y int) int {
	if x > y {
		return x
	}
	return y
}

var wr = bufio.NewWriter(os.Stdout)

func main() {
	var n, k int
	fmt.Scan(&n, &k)

	initCmb(max(n-k+1, k-1))
	for i := 1; i <= k; i++ {
		wr.WriteString(strconv.Itoa(cmb(n-k+1, i)*cmb(k-1, i-1)%mod) + "\n")
	}
	wr.Flush()
}


Measured memory_bytes: 18304
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int a = in.nextInt();
		int b = in.nextInt();
		in.nextLine();
		String s = in.nextLine();

		int pass = 0;
		int overseaPass = 0;

		for (int i = 0; i < n; i++) {
			if (i == n - 1) {
				if (s.charAt(i) == 'c') {
					System.out.print("No");
				} else if (s.charAt(i) == 'a') {
					if (pass < a + b) {
						System.out.print("Yes");
						pass++;
					} else {
						System.out.print("No");
					}
				} else if (s.charAt(i) == 'b') {
					if (pass < a + b && overseaPass < b) {
						System.out.print("Yes");
						pass++;
						overseaPass++;
					} else {
						System.out.print("No");
					}
				}
			} else {
				if (s.charAt(i) == 'c') {
					System.out.println("No");
				} else if (s.charAt(i) == 'a') {
					if (pass < a + b) {
						System.out.println("Yes");
						pass++;
					} else {
						System.out.println("No");
					}
				} else if (s.charAt(i) == 'b') {
					if (pass < a + b && overseaPass < b) {
						System.out.println("Yes");
						pass++;
						overseaPass++;
					} else {
						System.out.println("No");
					}
				}
			}
		}
	}
}


Measured memory_bytes: 23936
s = gets.chomp
l = s[0..1].to_i
r = s[2..3].to_i
if 1 <= l && l <= 12
  if 1 <= r && r <= 12
    puts "AMBIGUOUS"
  else
    puts "MMYY"
  end
else
  if 1 <= r && r <= 12
    puts "YYMM"
  else
    puts "NA"
  end
end

Measured memory_bytes: 3836
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
#define rep(i,x) for(int i = 0; i < x; i++)
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>> vvvi;
const ll N = 1e9+7;
const int n_max = 1e5+10;
int main(){
    int n; cin >> n;
    vector<int> h(n);
    rep(i,n) cin >> h[i];
    bool ok = true;
    for(int i = n-1;i > 0; i--){
        if(h[i] <= h[i-1] - 2){
            ok = false;
            break;
        }
        else if(h[i] == h[i-1] - 1){
            h[i-1]--;
        }
    }
    if(ok)cout << "Yes" << endl;
    else cout << "No" << endl;
    // rep(i,n)cout << h[i] << " ";
    return 0;
}

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

#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define read()          freopen("in.txt","r",stdin)
#define write()         freopen("out.txt","w",stdout)
#define sf(n)           scanf("%d",&n)
#define sfd(n)          scanf("%lf",&n)
#define sl(x)           scanf("%I64d",&x)
#define sfl(n)          scanf("%lld", &n)
#define sfc(n)          scanf(" %c",&n)
#define sful(n)         scanf("%llu",&n)
#define ull             unsigned long long
#define endll           pf("\n")
#define pf              printf
#define PI              acos(-1.0)
#define eps             1e-12
#define mem(a,b)        memset(a,b,sizeof(a))
#define pb              push_back
#define xx              first
#define yy              second
#define pii             pair<int, int>
#define pll             pair<ll, ll>
#define MP make_pair
#define ll              long long
#define uniq(a)      a.erase(unique(a.begin(), a.end()), a.end())
#define cnd tree[idx]
#define lnd tree[idx<<1]
#define rnd tree[(idx<<1)+1]
#define lndp (idx<<1),(b),((b+e)>>1)
#define rndp ((idx<<1)+1),(((b+e)>>1)+1),(e)
#define inf 1999999999
#define MOD  1000000007
#define mod1 1000000009
#define var    int n,m,i,j,c=0,t,l,r,mid,z=0,k,x,y
#define aloc(n,t) ((t*)malloc((n)*sizeof(t)))

int dx[8]={0,0,1,1,-1,-1,1,-1};  //8 direction
int dy[8]={1,-1,1,-1,1,-1,0,0};
//int dx[4]={1,-1,0,0};  //4 direction
//int dy[4]={0,0,1,-1};

int n,m,dp[1000005];

int fn(int pos)
{
    if(pos==0)
    {
        return 1;
    }
    int &z = dp[pos];
    if(z!=-1)return z;
    z=0;
    for(int i=3;i<=pos;i++)
    {
        if(pos-i>=0)z+=fn(pos-i);
        z%=MOD;
    }
    return z;
}

int main()
{
    sf(n);
    mem(dp,-1);

    int ans = fn(n);

    cout<<ans<<endl;
}


Measured memory_bytes: 7664
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define int long long
#define double long double
#define mod 1000000007
#define F first
#define S second
#define P pair<long long,long long>
#define all(a) a.begin(),a.end()
#define INF 10000000000000000
#define endl '\n'
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using namespace std;

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

    string s; cin>>s;
    vector<int> vec(3,0);
    rep(i,s.size()){
        vec.at(s.at(i)-'a')++;
    }
    sort(all(vec));
    int a=vec.at(1)-vec.at(0),b=vec.at(2)-vec.at(1);
    if(a+b>=0 and a+b<=1)cout<<"YES"<<endl;
    else cout<<"NO"<<endl;

}

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

using namespace std;

int main() {
  long long l, r;
  cin >> l >> r;

  long long result = l*(l+1) % 2019;
  for (long long i = l; i <= r && i <= l+2019; i++) {
    for (long long j = i + 1; j <= r && j <= i+2019; j++) {
      long long v = (i*j) % 2019;
      if (result > v) {
        result = v;
      }
    }
  }

  cout << result << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Map;
import java.util.Queue;
import java.util.Scanner;
import java.util.Set;
import java.util.TreeSet;

public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int all = 0;
		int dn = 0;
		int tyo = 0;
		int ei = 0;
		
		while(sc.hasNext()){
			ArrayList<Integer> len = new ArrayList<Integer>(3);
			for(int i = 0; i < 3; i++){
				len.add(sc.nextInt());
			}
				
			Collections.sort(len, Collections.reverseOrder());
			
			if(len.get(0) >= len.get(1) + len.get(2)){
				System.out.println(all + " " + tyo + " " + ei + " " + dn);
				return;
			}
			
			all++;
			
			int a = len.get(0) * len.get(0);
			int bc = len.get(1) * len.get(1) + len.get(2) * len.get(2);
			
			if(a < bc){
				ei++;
			}else if(a > bc){
				dn++;
			}else{
				tyo++;
			}
		}
		
	}

}

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
  
    string s;
    cin >> s;
    int bac = s.length()-1;
    int fro = 0;
    int ans = 0;
    while(true){
      if(bac <= fro)  break;
      if(s[fro] == s[bac]){
        ++fro;
        --bac;
      }else{
        if(s[fro] == 'x' && s[bac] != 'x'){
          ++ans;
          ++fro;
        }else if(s[fro] != 'x' && s[bac] == 'x'){
          ++ans;
          --bac;
        }else{
          cout << "-1\n";
          return 0;
        }
      }
    }

    cout << ans << '\n';

    return 0;
}

Measured memory_bytes: 512
M,D= list(map(int, input().split()))
ans=0
for i in range(M):
    for j in range(22,D+1):
        if str(j)[1]=='0' or str(j)[1]=='1':
            continue
        elif i+1==int(str(j)[0])*int(str(j)[1]):
            ans+=1
print(ans)

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

int main(){
    int n;
    cin >> n;
    int i,j,k;
    vector<int> v;
    for(i=0;i<n;i++){
        cin >> k;
        v.push_back(k);
    }
    for(i=0;i<n;i++) cout << v[i] << (i==n-1?'\n':' ');
    for(i=1;i<n;i++){
        for(j=0;j<i;j++){
            if(v[j]>v[i]){
                k=v[i];
                v.erase(v.begin()+i);
                v.insert(v.begin()+j,k);
                break;
            }
        }
        for(j=0;j<n;j++) cout << v[j] << (j==n-1?'\n':' ');
    }
    return 0;
}


Measured memory_bytes: 3156
import java.io.IOException;
import java.util.Arrays;

public class Main {

	public static void main(String[] args) {
		while (true) {
			int w = nextInt();
			if (w == 1) {
				break;
			}

			System.out.print(w + ":");

			boolean[] is_prime = new boolean[w + 1];// 素数判定表
			Arrays.fill(is_prime, true);// まずは全部trueで埋める

			for (int i = 2; i <= w; i++) {
				if (i % 7 != 1 && i % 7 != 6) {
					// 月曜土曜数でなければスキップ
					continue;
				}

				if (is_prime[i]) {
					// 月曜土曜素数であれば割ってみる
					if (w % i == 0) {
						System.out.print(" " + i);
					}
					for (int j = i * 2; j <= w; j += i) {
						// iの整数倍は素数ではない
						is_prime[j] = false;
					}
				}

			}
			System.out.println();

		}
	}

	static int nextInt() {
		int c;
		try {
			c = System.in.read();
			while (c != '-' && (c < '0' || c > '9'))
				c = System.in.read();
			if (c == '-')
				return -nextInt();
			int res = 0;
			while (c >= '0' && c <= '9') {
				res = res * 10 + c - '0';
				c = System.in.read();
			}
			return res;
		} catch (IOException e) {
			e.printStackTrace();
		}
		return -1;
	}

	static char nextChar() {
		try {
			int b = System.in.read();
			while (b != -1 && (b == ' ' || b == '\r' || b == '\n'))
				;
			if (b == -1)
				return 0;
			return (char) b;
		} catch (IOException e) {
		}
		return 0;
	}

}

Measured memory_bytes: 55680
unittest
{
	assert( [ "6", "1 2 3 4 5 6" ].parse.expand.solve == 12 );
	assert( [ "5", "-1000 -100 -10 0 10" ].parse.expand.solve == 0 );
	assert( [ "10", "1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000" ].parse.expand.solve == 5000000000 );
	assert( [ "27", "18 -28 18 28 -45 90 -45 23 -53 60 28 -74 -71 35 -26 -62 49 -77 57 24 -70 -93 69 -99 59 57 -49" ].parse.expand.solve == 295 );
}



import std.algorithm;
import std.conv;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	input.popFront;
	auto as = input.front.split.to!( long[] );
	return tuple( as );
}

auto solve( long[] as )
{
	// 3つ以下なら一番大きい数を選ぶだけ
	if( as.length <= 3 ) return as.reduce!max;
	
	// dp[ i番目 ][ 選ばなかった要素の数 ] = 選んだ要素の和
	auto dp = new long[][]( as.length + 2, ( as.length.signed % 2 ) + 2 );
	foreach( ref dpp; dp ) dpp[] = long.min;
	dp[ 0 ][ 0 ] = 0;
	foreach( i, a; as )
	{
		foreach( j; 0 .. dp[ i ].length.signed )
		{
			if( dp[ i ][ j ] == long.min ) continue;
			
			// 選ぶ
			if( i + 2 < dp.length ) dp[ i + 2 ][ j ] = max( dp[ i + 2 ][ j ], dp[ i ][ j ] + a );
			
			// 選ばない
			if( j + 1 < dp[ i ].length ) dp[ i + 1 ][ j + 1 ] = max( dp[ i + 1 ][ j + 1 ], dp[ i ][ j ] );
		}
	}
	return dp[ $ - 1 ][ $ - 1 ];
}


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

#define x first
#define y second
#define pb push_back
#define mp make_pair

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

#define ll long long
#define ld long double

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    map<ll, int> ma;
    ll ans = 0;
    for (int i = 0; i < n; ++i) {
        ll a;
        cin >> a;
        ans += ma[i - a];
        ++ma[a + i];
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 26328
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)

using namespace std;
typedef long long int ll;
typedef pair <int, int> P;

const ll MOD=1000000007;

map<int, int> prime_factor(int n){
    map<int, int> res;
    for (int i=2; i*i<=n; i++){
        while(n%i==0){
            ++res[i];
            n/=i;
        }
    }
    if (n!=1) res[n]=1;
    return res;
}

int main() {
    int N;
    cin >> N;
    map<int, int> m;
    rep(i,1,N+1){
        rep(j,1,N+1){
            m[j]+=prime_factor(i)[j];
        }
    }
    ll ans=1;
    rep(i,1,N+1){
        ans*=m[i]+1;
        ans%=MOD;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define INF 1000000000000000000
#define MOD 1000000007
using Graph=vector<vector<int>>;

int main(){
  int L;
  cin>>L;
  vector<ll> A(L);
  for(int i=0;i<L;i++){
    cin>>A.at(i);
  }

  vector<vector<ll>> dp(L+1,vector<ll>(5,INF));
  for(int j=0;j<5;j++){
    dp.at(0).at(j)=0;
  }
  for(int i=0;i<L;i++){
    if(A.at(i)==0){
      dp.at(i+1).at(0)=dp.at(i).at(0);
      dp.at(i+1).at(1)=min<ll>(dp.at(i).at(0),dp.at(i).at(1)+2);
      dp.at(i+1).at(2)=min<ll>({dp.at(i).at(0),dp.at(i).at(1)+2,dp.at(i).at(2)+1});
      dp.at(i+1).at(3)=min<ll>({dp.at(i).at(0),dp.at(i).at(1)+2,dp.at(i).at(2)+1,dp.at(i).at(3)+2});
      dp.at(i+1).at(4)=min<ll>({dp.at(i).at(0),dp.at(i).at(1)+2,dp.at(i).at(2)+1,dp.at(i).at(3)+2,dp.at(i).at(4)});
    }else if(A.at(i)%2==1){
      dp.at(i+1).at(0)=dp.at(i).at(0)+A.at(i);
      dp.at(i+1).at(1)=min<ll>(dp.at(i).at(0)+A.at(i),dp.at(i).at(1)+1);
      dp.at(i+1).at(2)=min<ll>({dp.at(i).at(0)+A.at(i),dp.at(i).at(1)+1,dp.at(i).at(2)});
      dp.at(i+1).at(3)=min<ll>({dp.at(i).at(0)+A.at(i),dp.at(i).at(1)+1,dp.at(i).at(2),dp.at(i).at(3)+1});
      dp.at(i+1).at(4)=min<ll>({dp.at(i).at(0)+A.at(i),dp.at(i).at(1)+1,dp.at(i).at(2),dp.at(i).at(3)+1,dp.at(i).at(4)+A.at(i)});
    }else{
      dp.at(i+1).at(0)=dp.at(i).at(0)+A.at(i);
      dp.at(i+1).at(1)=min<ll>(dp.at(i).at(0)+A.at(i),dp.at(i).at(1));
      dp.at(i+1).at(2)=min<ll>({dp.at(i).at(0)+A.at(i),dp.at(i).at(1),dp.at(i).at(2)+1});
      dp.at(i+1).at(3)=min<ll>({dp.at(i).at(0)+A.at(i),dp.at(i).at(1),dp.at(i).at(2)+1,dp.at(i).at(3)});
      dp.at(i+1).at(4)=min<ll>({dp.at(i).at(0)+A.at(i),dp.at(i).at(1),dp.at(i).at(2)+1,dp.at(i).at(3),dp.at(i).at(4)+A.at(i)});
    }
  }

  cout<<dp.at(L).at(4)<<endl;
}


Measured memory_bytes: 15872