akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<string.h>
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define SWAP(a,b) {a+=b;b=a-b;a-=b;}
#define INF 1000000000

int n,ma,mb,abc[40][3];
int suma = 0,sumb = 0,sumc = 0,minc = INF;

void roop(int q){
	
	if(minc < sumc) return;

	if(q == n){
		if(ma*sumb == mb*suma && sumc != 0){
			minc = minc < sumc ? minc:sumc;
		}
		return;
	}

	FOR(i,0,2){
		suma += abc[q][0] * i;
		sumb += abc[q][1] * i;
		sumc += abc[q][2] * i;

		roop(q+1);

		suma -= abc[q][0] * i;
		sumb -= abc[q][1] * i;
		sumc -= abc[q][2] * i;
	}
}

int main(){
	scanf("%d %d %d",&n,&ma,&mb);
	FOR(i,0,n) scanf("%d %d %d",&abc[i][0],&abc[i][1],&abc[i][2]);

	FOR(i,0,n-1){
		if(abc[i][2] > abc[i+1][2]){
			SWAP(abc[i][0],abc[i+1][0]);
			SWAP(abc[i][1],abc[i+1][1]);
			SWAP(abc[i][2],abc[i+1][2]);
		}
	}

	roop(0);

	if(minc == INF) printf("-1\n");
	else printf("%d",minc);
}

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

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	long long k, x;
	cin >> k >> x;
	if(500*k >= x) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

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

typedef long long ll;
const ll MOD = 1e9 + 7;
const long long INF = 1LL<<60;
const double PI=3.14159265358979323846;
const int NMAX=100005;
using namespace std;

ll dp[105][100010];

int main(){
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }

    for(int i = 0; i <= n; i++){
        for(int j = 0; j <= k; j++){
            dp[i][j] = 0;
            if(j == 0) dp[i][j] = 1;
        }
    }

    dp[1][1] = 1;
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= k; j++){
            if(i == 1 && j == 1) continue;
            dp[i][j] = (dp[i-1][j] + dp[i][j-1])%MOD;
            if(i-1 >= 0 && j-a[i-1]-1 >= 0) dp[i][j] -= dp[i-1][j-a[i-1]-1];
            if(dp[i][j] < 0) dp[i][j] += MOD;
        }
    }

    cout << dp[n][k]%MOD << endl;

    return 0;
}

Measured memory_bytes: 80128
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long LL;
typedef pair<LL,LL> P;
const LL mod=1e9+7;
const LL LINF=1LL<<62;
const int INF=1000000000;

int main(){
    int N,K;cin >> N >> K;
    vector<int> h(N);
    for (int i = 0; i < N; i++) {
        cin >> h[i];
    }
    vector<int> dp(N,INF);
    dp[0]=0;
    for (int i = 0; i < N-1; i++) {
        for (int j = 0; j < K; j++) {
            dp[i+1+j]=min(dp[i+1+j],dp[i]+abs(h[i+1+j]-h[i]));
        }
    }
    cout << dp[N-1] << endl;
    return 0;
}



Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include<string.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define Max(x,y,z) max(x,max(y,z))
#define Min(x,y,z) min(x,min(y,z))
#define fr(i,s,e) for(i=s;i<e;i++)
#define rf(i,s,e) for(i=s-1;i>=e;i--)
#define pb push_back
#define eb emblace_back
#define mp make_pair
#define ff first
#define ss second
#define int   long long
#define ll   long long
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
#define vl vector<long long>
#define inf (1LL<<61)
#define vi vector<int> 
#define vii vector< vector<int> >
#define vll vector< vector<long long> >
#define vpi vector< pair<int,int> >   
#define vpl vector< pair<ll,ll> >   
#define viii vector< vector<vector<int> > >
typedef pair<pair<int, int>,int> P;
#define cd complex<double>
#define PI 4*atan(1)
#define mod %1000000007
#define pi 3.14159265358979323846//20 decimals
#define ld long double
#define N 1001

int32_t main()
{
    IOS;
    /*#ifndef ONLINE_JUDGE
    freopen("int.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    #endif*/
    int n,k;
    cin>>n>>k;
    int ans=0;
    for(int i=1;i<=n;i++)
    {
        int y=k-i%k;
        //trace2(y,(y+y)%k);
        if((y+y)%k==0)
        {
            int x=i+y;
            int z=i+n;
            //trace3(x,z,(z-x)/k);
            if(z<x)
                continue;
            //trace1(((z-x+1)/k)*((z-x+1)/k));
            ans+=((z-x)/k+1)*((z-x)/k+1);
        }
    }   
    cout<<ans;
    return 0;
}

Measured memory_bytes: 256
//bismillahir rahmanir rahim            //Author:Fayed Anik
 
#include <bits/stdc++.h> 
 
using namespace std;
 
 
#define         ll                         long  long
#define         lf                         double 
#define         pb(x)                      push_back(x)
#define         ull                        unsigned long long
#define         sfl(a)                     scanf("%lld",&a)
#define         sf(a)                      scanf("%d",&a)
#define         pf(a)                      printf("%d\n",a)
#define         pfl(a)                     printf("%lld\n",a)
#define         pdl(a)                     printf("%llf\n",a)
#define         FOR(x,n)                   for(ll x=1;x<=n;++x)
#define         vii                        vector< ll > v
#define         pi                         3.14159265359
#define         mex                        10000000
#define         pii                        pair< ll , ll >
#define         mem(m,a)                   memset( m, a,sizeof m)
#define         mp(a,b)                    make_pair(a,b)
#define         maxn                       100000
#define         mod                        1000000007
#define         INF                        1e17
#define         f1                         first
#define         f2                         second
#define         all(v)                     v.begin(),v.end()
#define         PI                         acos(-1)
#define         printminusone              printf("-1\n")
#define         bug                        printf("bug")
#define         FILEIN                     freopen("in.txt","r",stdin)
#define         FILEOUT                    freopen("out.txt","w",stdout)

int main(){
    string s,ans="";
    ll n;
    sfl(n);
    cin>>s;
    for(ll i=0;i<s.size();i++){
        ll x=s[i]-'A';
        x = (x+n)%26;
        char c= 'A'+x;
        ans += c;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main(){
    int hitpoint,attack,result;
    cin >> hitpoint;
    cin >> attack;
    if(hitpoint%attack==0){
        result=hitpoint/attack;
    }else{
        result=hitpoint/attack+1;
    }
    cout << result << endl;
}

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

using namespace std;

#define endl "\n"

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

    string a, b;
    cin >> a >> b;
    int dp[a.size() + 1][b.size() + 1];
    memset(dp, 0, sizeof dp);

    for (int i = 1; i <= a.size(); i++) {
        for (int j = 1; j <= b.size(); j++) {
            if (a[i - 1] == b[j - 1]) {
                dp[i][j] = max(dp[i - 1][j - 1] + 1, dp[i][j - 1]);
            } else {
                dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
            }
        }
    }

    // for (int i = 0; i <= a.size(); i++) {
    //     for (int j = 0; j <= b.size(); j++) {
    //         cout << dp[i][j] << " ";
    //     }
    //     cout << endl;
    // }
    int index = dp[a.size()][b.size()];

    char lcs[index + 1];
    lcs[index] = '\0';

    int i = a.size(), j = b.size();
    while (i > 0 && j > 0) {
        if (a[i - 1] == b[j - 1]) {
            lcs[index - 1] = a[i - 1];  // Put current character in result
            i--;
            j--;
            index--;  // reduce values of i, j and index
        } else if (dp[i - 1][j] > dp[i][j - 1])
            i--;
        else
            j--;
    }

    cout << lcs << endl;
    return 0;
}

Measured memory_bytes: 38660
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <numeric>
#include <bitset>

using namespace std;
using ll = long long;
using ld = long double;
const ll mod =  1000000007;

#define REP(i, n) for (ll i = 0; i < (n); ++i)
#define REP_FROM(i, j, n) for (ll i = (j); i < (n); ++i)
#define all(x) (x).begin(),(x).end()

ll power(ll base, ll exponent, ll module){ if(exponent % 2){ return power(base, exponent - 1, module) * base % module; }else if(exponent){ ll root_ans = power(base, exponent / 2, module); return root_ans * root_ans % module; }else{ return 1; }}
ll inverse(ll x){ return power(x, mod - 2, mod);}
ll gcd(ll a, ll b) {if(a < b) gcd(b, a);ll r;while(r=a%b) {a=b;b=r;}return b;}
struct combination{ vector<ll> fact, inv; combination(int sz) : fact(sz + 1), inv(sz + 1){ fact[0] = 1; for(int i = 1; i <= sz; i++){ fact[i] = fact[i - 1] * i % mod; } inv[sz] = power(fact[sz], mod - 2, mod); for(int i = sz - 1; i >= 0; i--){ inv[i] = inv[i + 1] * (i + 1) % mod; } } ll C(int p, int q) const{ if(q < 0 || p < q) return 0; return (fact[p] * inv[q] % mod * inv[p - q] % mod); } };

const int V = 100005;
vector<vector<int>> to(V*2);
bool visited[V*2];
vector<ll> cnt;
void dfs(int v) {
  if(visited[v]) return;
  visited[v] = true;
  cnt[v/V]++;
  for (int next: to[v]) dfs(next);
} 

signed main() {
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  REP(i, n) {
    int x,y;
    cin >> x >> y;
    x--;y--;
    y += V;
    to[x].push_back(y);
    to[y].push_back(x);
  }
  ll ans = 0;
  REP(v, V*2) {
    cnt = vector<ll>(2);
    dfs(v);
    ans += cnt[0]*cnt[1];
  }
  cout << ans - n << endl;
  return 0;
}


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

using namespace std;

using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

constexpr int I_INF = numeric_limits<int>::max();
constexpr ll L_INF = numeric_limits<ll>::max();

//==================================

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

    ll N, K;
    cin >> N >> K;

    int ans = 0;
    while (N > 0) {
        N /= K;
        ++ans;
    }

    cout << ans << endl;

    return 0;
}

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

using namespace std;

#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)

void cut(vector<int>& cards, int k) {
  int const N = cards.size();
  vector<int> ncards;
  
  for(int i=k; i<N; i++)
    ncards.push_back(cards[i]);
  for(int i=0; i<k; i++)
    ncards.push_back(cards[i]);

  cards = ncards;
}

void shuffle(vector<int>& cards) {
  int const N = cards.size();
  vector<int> ncards;

  int fst = 0, snd = N/2;
  for(int i=0; i<N; i++) {
    if(i%2)
      ncards.push_back(cards[snd++]);
    else
      ncards.push_back(cards[fst++]);
  }
  
  cards = ncards;
}

int main() {
  int n;
  
  cin >> n;
  vector<int> cards(2*n);
  for(int i=0; i<2*n; i++) cards[i] = i+1;
  int m;
  cin >> m;
  
  for(int i=0; i<m; i++) {
      int k;
      cin >> k;
      if(k) cut(cards, k);
      else shuffle(cards);
  }
  
  EACH(i, cards)
    cout << *i << endl;
  
  return 0;
}

Measured memory_bytes: 1224
import java.util.Scanner;

/**
 * HonestOrUnkind2
 */
public class Main {

    public static void main(String[] args) throws Exception {
        try (Scanner sc = new Scanner(System.in)) {
            int N = sc.nextInt();

            int[] A = new int[N];
            int[][] X = new int[N][N];
            int[][] Y = new int[N][N];

            for (int i = 0; i < N; i++) {
                A[i] = sc.nextInt();
                for (int j = 0; j < A[i]; j++) {
                    X[i][j] = sc.nextInt() - 1;
                    Y[i][j] = sc.nextInt();
                }
            }

            int ans = 0;

            for (int i = 1; i < (1 << N); i++) {
                int ans2 = 0;

                long[] honest = new long[N];
                for (int j = 0; j < N; j++) {
                    honest[j] = (i >> j) & 1;
                }

                for (int j = 0; j < N; j++) {
                    if (honest[j] == 1) {
                        ans2++;

                        for (int k = 0; k < A[j]; k++) {
                            if (honest[X[j][k]] != Y[j][k]) {
                                ans2 = -1;
                                j = N;
                                break;
                            }
                        }
                    }
                }

                ans = Math.max(ans, ans2);
            }

            System.out.println(ans);
        }
    }

}


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

using namespace std;

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

const int inf = 1e9;

signed main()
{
    int N;

    while (cin >> N, N) {
        vector<int> hp(N);

        rep(i, N) {
            cin >> hp[i];
        }

        int M;

        cin >> M;

        vector<pair<int,int>> S, A;

        rep(i, M) {
            string s;
            int mp, dmg;
            cin >> s >> mp >> s >> dmg;
            if (s == "Single") S.push_back(make_pair(mp, dmg));
            else A.push_back(make_pair(mp, dmg));
        }

        vector<int> dp1(100010, inf), dp2(100010, inf);
        dp1[0] = dp2[0] = 0;

        for (int i = 0; i < S.size(); ++i) {
            int mp = S[i].first, dmg = S[i].second;
            for (int j = 0; j <= 100000; ++j) {
                if (j - dmg >= 0) {
                    dp1[j] = min(dp1[j], dp1[j - dmg] + mp);
                } else {
                    dp1[j] = min(dp1[j], mp);
                }
            }
        }

        for (int i = 0; i < A.size(); ++i) {
            int mp = A[i].first, dmg = A[i].second;
            for (int j = 0; j <= 100000; ++j) {
                if (j - dmg >= 0) {
                    dp2[j] = min(dp2[j], dp2[j - dmg] + mp);
                } else {
                    dp2[j] = min(dp2[j], mp);
                }
            }
        }

        int mi = inf;

        for (int a = 0; a <= 100000; ++a) {
            int sum = dp2[a];

            for (int i = 0; i < N; ++i) {
                if (hp[i] - a >= 0) {
                    sum += dp1[hp[i] - a];
                }
            }

            mi = min(mi, sum);
        }

        cout << mi << endl;
    }
}

Measured memory_bytes: 4476
#include <iostream>
#include <vector>
//#include "../cxx-prettyprint/prettyprint.hpp"
using std::vector;

int main() {
    int H, W;
    std::cin >> H >> W;

    vector<vector<char>> s(H, vector<char>(W));
    vector<vector<bool>> black_bits(H, vector<bool>(W, false));
    for (int i = 0; i < H; i ++) {
        for (int j = 0; j < W; j++) {
            std::cin >> s[i][j];
            if (s[i][j] == '#') black_bits[i][j] = true;
        }
    }

    for (int i = 0; i < H; i ++) {
        for (int j = 0; j < W; j ++) {
            if (!black_bits[i][j]) continue;

            bool cond_up    = i > 0     && black_bits[i - 1][j];
            bool cond_down  = i < H - 1 && black_bits[i + 1][j];
            bool cond_left  = j > 0     && black_bits[i][j - 1];
            bool cond_right = j < W - 1 && black_bits[i][j + 1];

            if (!(cond_up || cond_down || cond_left || cond_right)) {
                std::cout << "No" << std::endl;
                return 0;
            }
        }
    }
    std::cout << "Yes" << std::endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#define slmt 101    /*slmt:手札文字数限界*/
#define winp 3    /*勝利ポイント*/
#define drowp 1    /*引き分けポイント*/

int main(void){
    char tarou[slmt], hanako[slmt];    /*tarou:太郎手札, hanako:花子手札*/
    int times, x;    /*times:ゲーム回数, x:ループ変数*/
    int twin=0, hwin=0;    /*twin:太郎勝利回数, hwin:花子勝利回数*/
    
    /*入力部*/
        scanf("%d\n", &times);    /*ゲーム回数を読み取る*/
        /*ゲーム状況の読み込みは判定とともに行う*/
        
    /*判定部*/
        for(x=0; times>x; x++){    
            scanf("%s %s\n", &tarou, &hanako);    /*ゲーム状況読み込み*/
            if (strcmp(&tarou, &hanako) > 0){    /*勝敗判定＆ポイント加算*/
                twin += winp;    /*太郎勝利加算*/
            }else if (strcmp(&tarou, &hanako) < 0){
                hwin += winp;    /*花子勝利加算*/
            }else{
                twin += 1;    /*引き分け加算*/
                hwin += 1;
            }
        }
        
    /*出力部*/
        printf("%d %d\n", twin, hwin);    /*各ポイントを1行出力*/
        
    return 0;
}

Measured memory_bytes: 608
#include <bits/stdc++.h> 
using namespace std; 
typedef long long ll;
const int mxN=1e9;
const ll mod = 1e9+7;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	
    int n,m;
    cin>>n>>m;

    char v[n][m];
    int dp[n][m];

    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            cin>>v[i][j];
        }
    }
    
    memset(dp,0,sizeof(dp));
    int ans = 0;

    dp[0][0]=1;

    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            if(v[i][j]=='#') continue;
            if(j>0)dp[i][j] = (dp[i][j]+dp[i][j-1])%mod;
            if(i>0)dp[i][j] = (dp[i][j]+dp[i-1][j])%mod;
        }
    }

    cout<<dp[n-1][m-1];
}

Measured memory_bytes: 8356
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;

int main() {
  int n, m, x;
  cin >> n >> m >> x;
  VVI a(n, VI(m));
  VI c(n);
  rep(i, n) {
    cin >> c.at(i);
    rep(j, m) { cin >> a.at(i).at(j); }
  }
  ll mincost = 1e9;
  rep(i, 1 << n) {
    ll sum = 0;
    VI asum(m);
    rep(j, n) {
      if (((i >> j) & 1) == 1) {
        sum += c.at(j);
        rep(k, m) { asum.at(k) += a.at(j).at(k); }
      }
    }
    bool achieve = true;
    rep(j, m) {
      if (x > asum.at(j)) {
        achieve = false;
        break;
      }
    }
    if (achieve) {
      mincost = min(sum, mincost);
    }
  }
  if (mincost == 1e9) {
    mincost = -1;
  }
  cout << mincost << endl;
  return 0;
}


Measured memory_bytes: 3632
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<set>

using namespace std;

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

	for (int i = 0; i < S.length() - 8; i++) {
		cout << S[i];
	}
	cout << endl;

}


Measured memory_bytes: 3604
import copy
import heapq
import math
import fractions

def j(n):
    if n:print("Yes")
    else:print("No")
    exit(0)
rem = 10 ** 9 + 7

"""
def ct(x,y):
    if (x>y):print("+")
    elif (x<y): print("-")
    else: print("?")
"""

def ip():
    return int(input())
def iprow():
    return [int(i) for i in input().split()]
def ips():
    return (int(i) for i in input().split())
def ipmultiplerow(n):
    a = []
    for i in range(n):
        a.append(ip())
    return a
def printrow(a):
    for i in a:
        print(i)


def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)

count = 0
n= ip()
a = iprow()
currentnum = 1
for i in range(n):
    if currentnum == a[i]:
        currentnum+=1
    else:
        count+=1
if count == n:
    print(-1)
    exit(0)
print(n-currentnum+1)

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

int min_solve=1000000;

int main() {
    int d, g;
    cin >> d >> g;

    vector<int> unit_ten(d);
    vector<int> clear_ten(d);
    vector<int> p(d);
    vector<int> c(d);
    rep (i, d) cin >> p[i] >> c[i];

    rep (i, d) {
        unit_ten[i] = 100*(i+1);
        clear_ten[i] = unit_ten[i] * p[i] + c[i];
    }

    // 2^d通りのbit全探索、全回答するかしないか
    for (int bit=0; bit<(1<<d); ++bit){
        int sum_point = 0;
        int solved = 0;
        // d桁確認
        // cout << bit << ' ' << ~bit << endl;
        rep(i, d) {
            // i桁目が1ならTrue
            if (bit & (1<<i)) {
                // cout << i << "桁目 1" << endl;
                // i桁目を足す
                sum_point += clear_ten[i];
                // p[i]問解いた
                solved += p[i];
            }
        }
        // 点数が目標を超えていれば
        if (sum_point >= g) {
            min_solve = min(min_solve, solved);
        // 超えていなければ、完全回答以外で超えられるものを探す
        } else {
            //cout << "超えていない" << endl;
            rep(i, d) {
                // i桁目が0ならTrue
                if (~bit & (1<<i)) {
                    //cout << i << "桁目 0" << endl;
                    // i問目を使って点数を超えるための回答数
                    // 切り上げ割り算 (a + (b - 1)) / b
                    int nb_solve_to_over = ((g-sum_point)+(unit_ten[i]-1)) / unit_ten[i];
                    // 問題数より少ないか
                    if (nb_solve_to_over < p[i]) {
                        // 少なければ、min_solveを更新
                        min_solve = min(min_solve, solved + nb_solve_to_over);
                    }
                }
            }
        }
    }

    cout << min_solve << endl;

    return 0;
}

/*
2 700
3 500
5 800

*/

Measured memory_bytes: 256
#include<stdio.h>
 int main(void){
     int n,b,f,r,v,i,j,k;
     int a[20][20][20] = {0};
     scanf("%d",&n);

     for(i=0;i<n;i++){
        scanf("%d %d %d %d",&b,&f,&r,&v);
        if(b==1){
            a[0][f-1][r-1]+=v;
        }
        else if(b==2){
            a[1][f-1][r-1]+=v;
        }
        else if(b==3){
            a[2][f-1][r-1]+=v;
        }
        else{
            a[3][f-1][r-1]+=v;
        }

     }

     for(i=0;i<4;i++){
        for(j=0;j<3;j++){
            for(k=0;k<10;k++){
                        printf(" %d",a[i][j][k]);
            }
            printf("\n");
        }
        if(i!=3){
            printf("####################\n");
        }
     }

    return 0;
 }

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

int main()
{
    int H = 0;
    int W = 0;
    while(1)
    {
        cin >> H >> W;
        if (H == 0 && W == 0)
            break;
        else
        {
            for (int i = 0; i < H; i++)
            {
                for (int j = 0; j < W; j++)
                {
                    if ((i + j) % 2 == 0)
                        cout << "#";
                    else
                        cout << ".";
                }
                cout << endl;
            }
        }
        cout << endl;
    }
}


Measured memory_bytes: 3092
#include <bits/stdc++.h>
#define maxn 100010
#define maxm 200010
#define inf 0x3f3f3f3f3f3f3f3f
using namespace std;
typedef long long LL;
const LL mod = 1e9 + 7;
int ne[maxn], tot;
bool vis[maxn];
LL dist1[maxn], dist2[maxn], ways1[maxn], ways2[maxn];
struct Edge { int from, to, ne; LL w; }edge[maxm<<1];
void add(int u, int v, LL w) {
    edge[tot] = {u, v, ne[u], w};
    ne[u] = tot++;
}
struct node {
    int v; LL c;
    bool operator < (const node nd) const { return c > nd.c; }
};
int n;
void dfs(int src, LL* dist, LL* ways) {
    memset(vis, 0, sizeof vis);
    for (int i = 1; i <= n; ++i) dist[i] = inf;
    vis[src] = true; dist[src] = 0; ways[src] = 1;
    priority_queue<node> q;
    while (!q.empty()) q.pop();
    while (true) {
        for (int j = ne[src]; ~j; j = edge[j].ne) {
            int v = edge[j].to;
            if (vis[v]) continue;
            LL now = edge[j].w + dist[src];
            if (now == dist[v]) (ways[v] += ways[src]) %= mod;
            else if (now < dist[v]) {
                dist[v] = now; ways[v] = ways[src];
                q.push({v, now});
            }
        }
        while (!q.empty() && vis[q.top().v]) q.pop();
        if (q.empty()) break;
        vis[src = q.top().v] = true;
    }
}
int main() {
    memset(ne, -1, sizeof ne);
    int m, s, t;
    scanf("%d%d%d%d", &n,&m,&s,&t);
    for (int i = 0; i < m; ++i) {
        int u, v; LL w;
        scanf("%d%d%lld", &u,&v,&w);
        add(u, v, w), add(v, u, w);
    }
    dfs(s, dist1, ways1);
    dfs(t, dist2, ways2);
    //assert(dist1[t] == dist2[s]);
    //assert(ways1[t] == ways2[s]);
    LL ww = ways1[t];	
    LL ans = ww * (ww-1) % mod;
    LL dis = dist1[t];
    if (!(dis & 1)) {
        LL half = dis >> 1;
        for (int i = 1; i <= n; ++i) if (dist1[i] == half && dist2[i] == half) {
            LL temp = ways1[i] * ways2[i] % mod;
            ans = (ans - (temp * (temp-1)) % mod + mod) % mod;
        }
    }
	//cout<<ans<<endl;
    for (int i = 0; i < m; ++i) {
        int id = i<<1,
            u = edge[id].from, v = edge[id].to;
        if (dist1[u] > dist1[v]) swap(u, v);
        if (dist1[u] + edge[id].w + dist2[v] == dis && (dist1[u]<<1) < dis && (dist2[v]<<1) < dis) {
            LL temp = ways1[u] * ways2[v] % mod;
            ans = (ans - (temp * (temp-1)) % mod + mod) % mod;
        }
    }
    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 16852
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication34
{
    class Program
    {
        static void Main()
        {
            int[] a = Console.ReadLine().Split().Select(int.Parse).ToArray();
            Array.Sort(a);
            Array.Reverse(a);
            for(int b = 0; b < a.Length; b++)
            {
                if (a.Length - 1 == b) { Console.WriteLine(a[b]);break; }
                Console.Write(a[b]+" ");
            }
        }
    }
}

Measured memory_bytes: 9704
n = int(input())
l = list(map(int, input().split(" ")))
f = 0
for _ in l:
    for j in range(n - 1, 0, -1):
        if l[j] < l[j - 1]:
            l[j], l[j - 1] = l[j - 1], l[j]
            f += 1
print(*l)
print(f)


Measured memory_bytes: 5608
#include<stdio.h>
#include<iostream>

using namespace std;

int main()
{
	char s[2][3];
	for(int i=0;i<2;i++)
		for(int j = 0;j<3;j++)
			cin >> s[i][j];
	if(s[0][0]==s[1][2]&&s[0][1]==s[1][1]&&s[0][2]==s[1][0])
	printf("YES\n");
	else
	printf("NO\n");
} 

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

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    int ans[n];
    vector<int> temp(n); 
    temp = a;
    sort(a.begin(), a.end(), greater<int>());
    int max = a[0];
    int second_max = a[1];
    a = temp;
    for (int i = 0; i < n; i++) {
        if (a[i] == max) {
            ans[i] = second_max;
        } else {
            ans[i] = max;
        }
    }

    for (int i = 0; i < n; i++) {
        cout << ans[i] << endl;
    }
}


Measured memory_bytes: 3968
N = int(input())
H = list(map(int, input().split()))

dp = [10**10] * N
dp[0] = 0
for i in range(N-1):
  dp[i+1] = min([dp[i] + abs(H[i+1]-H[i]), dp[i+1]])
  if i + 2 < N:
    dp[i+2] = min([dp[i] + abs(H[i+2]-H[i]), dp[i+2]])

print(dp[-1])

Measured memory_bytes: 13976
#include <iostream>
#include <string>
#include <array>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <unordered_set>
#include <unordered_map>

#define FOR(i, a, b) for(decltype(b) i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;

using namespace std;

int main()
{
	ll a, b, c, k;
	cin >> a >> b >> c >> k;
	

	
	cout << (a + b + c + (max({a,b,c}) * ((1 << k) - 1))) << endl;

	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int A = scan.nextInt();
		int B = scan.nextInt();
		int C = scan.nextInt();
		int K = scan.nextInt();
		int ans = 0;

		int point1 = Math.min(A, K);
		int point0 = 0;
		int pointMinus1 = 0;


		if(K - point1 > 0) {
			point0 = Math.min(B, K-point1);

			if(K - point1 - point0 > 0) {
				pointMinus1 = K - point1 - point0;
			}

		}

		ans = point1 * 1 + point0 * 0 - pointMinus1 * 1;

		System.out.println(ans);
		scan.close();

	}
}


Measured memory_bytes: 35604
#include <bits/stdc++.h>
using namespace std;
#define int           long long
#define pb            push_back
#define mp            make_pair
#define PI            3.14159265
#define M             1000000007
#define MM            998244353
#define fr            first
#define sc            second
#define all(v)        (v).begin(),(v).end()
#define rall(v)       (v).rbegin(),v.rend()
#define vc            vector
#define vi            vector<int>
#define pii           pair<int,int>
#define psi           pair<string,int>
#define pis           pair<int,string>
#define mii           map<int,int>
#define msi           map<string,int>

int solve() {
    int n; cin>>n;
    double a[n],ans=0;
    for (int i = 0; i < n; ++i)
    {
        cin>>a[i];
        ans+=1/a[i];
    }
    cout<<fixed;
    cout<<setprecision(9)<<1/ans;
}

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

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

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define repr(i,n) for(int i=(int)(n-1);i>=0;i--)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout << #x"=" << x <<endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) bitset<32>(x).count()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;
typedef pair<int, P> PIP;
typedef pair<ll, ll> PL;
typedef pair<P, ll> PPL;
typedef set<int> S;

#define INF INT_MAX/3

#define MAX_N 1000000001

int main(){
	cin.sync_with_stdio(false);
	int a, b ,c;
	cin >> a >> b >> c;

	int len[11] = {};
	len[a]++;
	len[b]++;
	len[c]++;

	if(len[5] == 2 && len[7] == 1) {
		cout << "YES" << endl;
	} else {
		cout << "NO" << endl;
	}

	return 0;
}

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


using namespace std;

int i,j,k;

int main(){
    int n,x,y;
    cin >>n>>x>>y;
    int graph[n+1][n+1];
    int ans[n];
    REP(i,n){ans[i]=0;}
    for(i=1;i<n;i++){
        for(j=i+1;j<=n;j++){
            graph[i][j]=min(j-i,abs(i-x)+abs(j-y)+1);
            ans[graph[i][j]]++;
        }
    }
    
    for(i=1;i<=n-1;i++){
        cout<<ans[i]<<endl;
    }

    return 0;
}


Measured memory_bytes: 15744
def find_power(n,mod):
    # 0!からn!までのびっくりを出してくれる関数(ただし、modで割った値に対してである）
    powlist=[0]*(n+1)
    powlist[0]=1
    powlist[1]=1
    for i in range(2,n+1):
        powlist[i]=powlist[i-1]*i%(mod)
    return powlist

def find_inv_power(n):
    #0!からn!までの逆元を素数10**9+7で割ったあまりリストを作る関数
    powlist=find_power(n,10**9+7)
    check=powlist[-1]
    first=1
    uselist=[0]*(n+1)
    secondlist=[0]*30
    secondlist[0]=check
    secondlist[1]=check**2
    for i in range(28):
        secondlist[i+2]=(secondlist[i+1]**2)%(10**9+7)
    a=format(10**9+5,"b")
    for j in range(30):
        if a[29-j]=="1":
            first=(first*secondlist[j])%(10**9+7)
    uselist[n]=first
    for i in range(n,0,-1):
        uselist[i-1]=(uselist[i]*i)%(10**9+7)
    return uselist

def combi(a,b,n,r,mod):
    if n<r:
        return 0
    elif n>=r:
        return (a[n]*b[r]*b[n-r])%(mod)
aa=find_power(10**5,10**9+7)
bb=find_inv_power(10**5)
mod=10**9+7

n,k=map(int,input().split())
lists=list(map(int,input().split()))
import collections 
L=collections.Counter(lists)
L=dict(L)
uselist=[]
for a,v in L.items():
    uselist.append((a,v))
uselist=sorted(uselist,key=lambda x:x[0])
maxlist=[(0,0)]

counter=0
for some in uselist:
    counter+=some[1]
    maxlist.append((some[0],counter))

MAX=0

for j in range(1,len(maxlist)):
    MAX+=(combi(aa,bb,maxlist[j][1],k,mod)-combi(aa,bb,maxlist[j-1][1],k,mod))*maxlist[j][0]
    MAX=MAX%mod

  
uselist=uselist[::-1]

maxlist=[(0,0)]

counter=0
for some in uselist:
    counter+=some[1]
    maxlist.append((some[0],counter))

MIN=0

for j in range(1,len(maxlist)):
    MIN+=(combi(aa,bb,maxlist[j][1],k,mod)-combi(aa,bb,maxlist[j-1][1],k,mod))*maxlist[j][0]
    MIN=MIN%mod

print((MAX-MIN)%mod)

Measured memory_bytes: 38900
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

int main()
{
    ll N;
    int m,k,d,s;
    cin >>N >>m >>k >>d >>s;

    int start = s;

    int id = 0;
    map<ll,int> r2id;

    vector<int> a(m),b(m),c(m);
    rep(i,m)
    {
        ll r;
        scanf(" %d %d %lld", &a[i], &b[i], &r);

        if(!r2id.count(r)) r2id[r] = id++;
        c[i] = r2id[r];
    }

    int n;
    if(id<N) n = id+1;
    else n = id;

    map<int,int> last;
    multiset<int> ss;
    rep(i,n)
    {
        last[i] = 0;
        ss.insert(0);
    }

    int idx = 0;
    rep(_,k)
    {
        s += d;
        while(idx<m && a[idx]<=s)
        {
            ss.erase(ss.find(last[c[idx]]));

            if(last[c[idx]]<a[idx]) last[c[idx]] = a[idx]+b[idx];
            else last[c[idx]] = last[c[idx]] + b[idx];

            ss.insert(last[c[idx]]);
            ++idx;
        }

        auto itr = ss.begin();
        if(*itr>s) s = *itr;
    }

    printf("%d\n", s-start);
    return 0;
}

Measured memory_bytes: 19148
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        SumofgcdofTuples solver = new SumofgcdofTuples();
        solver.solve(1, in, out);
        out.close();
    }

    static class SumofgcdofTuples {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int k = in.nextInt();

            long result = 0;
            for (int i = 1; i <= k; i++) {
                for (int j = 1; j <= k; j++) {
                    for (int l = 1; l <= k; l++) {
                        result += gcd(gcd(i, j), l);
                    }
                }
            }
            out.append(String.valueOf(result));
        }

        static long gcd(long a, long b) {
            return b == 0 ? a : gcd(b, a % b);
        }

    }
}



Measured memory_bytes: 35852
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define vtpl(x,y,z) vector<tuple<x,y,z>>
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
ll modpow(ll a, ll n, ll mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
int main(){
    string s;cin >> s;
    ll sz=s.size();
    ll ans=0;
    ll pop=0;
    rep(i,sz){
        if(s[i]=='1'){
            ll tmp=modpow(3,sz-i-1,MOD);
            tmp%=MOD;
            tmp*=modpow(2,pop,MOD);
            tmp%=MOD;
            ans+=tmp;
            ans%=MOD;
            pop++;
        }
    }
    ans+=modpow(2,pop,MOD);
    cout <<ans%MOD<<endl;
}

Measured memory_bytes: 512
n = int(input())
a = list(map(int,input().split()))
cnt_2 = []
cnt_4 = []
for i in a:
  if i%4 == 0:
    cnt_4.append(i)
  elif (i%4 != 0) and (i%2 == 0):
    cnt_2.append(i)
if len(cnt_2) == 0:
  if len(cnt_4)*2+1 >= n:
    print('Yes')
  else:
    print('No')
else:
  if len(cnt_2)+len(cnt_4)*2 >= n:
    print('Yes')
  else:
    print('No')

Measured memory_bytes: 14252
#include <map>
#include <queue>
#include <cmath>
#include <ctime>
#include <vector>
#include <cstdio>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <tr1/unordered_map>
#define mo 1000000007
#define num(x) (x>='0' && x<='9')
typedef unsigned long long ull;
typedef long long ll;
using namespace std::tr1;
using namespace std;
int read(){
    int p=0, q=1;
    char ch=getchar();
    while (!num(ch))
        (ch=='-'?q=-1:0),
        ch=getchar();
    while (num(ch)) p=p*10+ch-'0', ch=getchar();
    return p*q;
}
int power(ll a, int b){
	ll c=1;
	while (b){
		if (b&1) c=c*a%mo;
		a=a*a%mo;
		b>>=1;
	}
	return c;
}
char s[2000], t[2000];
int main(){
	scanf("%s%s", s, t);
	int n=strlen(s), m=strlen(t), ans=2000;
	for (int i=0;i+m<=n;i++){
		int sum=0;
		for (int j=0;j<m;j++)
			if (s[i+j]!=t[j]) sum++;
		ans=min(ans,sum);
	}
	cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3684
n = int(input())
mod = 10**9+7
r_1,r_2,r_3 = 1,1,1

for i in range(n):
    r_1 = r_1 * 10 % mod
    r_2 = r_2 * 9 % mod
    r_3 = r_3 * 8 % mod

print((r_1-r_2-r_2+r_3)%mod)

Measured memory_bytes: 9196
#include<bits/stdc++.h>
using namespace std;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int k,n;
    int arr[1000]={};
    cin>>n>>k;
    for(int i=0;i<n;i++){
        cin>>arr[i];
    }
    sort(arr,arr+n);
    int p=0;
    for(int i=0;i<k;i++){
        p+=arr[i];
    }
    cout<<p<<'\n';

return 0;
}


//      *   *  *****  *   *  *   *   ****  ****    ****     **  ***
//     *   *  *      **  *  *   *  *      *   *  *        * *  *  *
//    *****  *****  * * *  *   *  *      ****   *       *  *    *
//   *   *      *  *  **  *   *  *      *  *   *       *****  *
//  *   *  *****  *   *   ***    ****  *   *    ****     *   ****

//     ****  *   *  *   *   ***   *   *  *****  *   *
//    *     *   *  *   *  *   *  *   *  *      *   *
//    ***  *****  *   *  *****  * * *  ****   *   *
//      *   *    *   *  *   *  * * *  *      *   *
//  ****   *     ***   *   *   * *   *****   ***


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

#define ll long long
#define vi vector<int>
#define pb push_back
#define P pair<int,int>
#define PP pair<P,int>
#define fi first
#define se second
#define INF (1<<30)
#define MOD 1000000007
#define all(a) (a).begin(),(a).end()


signed main(){
    int a,b;
    cin>>a>>b;
    vi vec(a);
    for(int i=0;i<b;i++){
        int x,y;
        cin>>x>>y;
        x--;y--;
        vec[x]++;
        vec[y]++;
    }
    for(auto t:vec){
        cout<<t<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
#include <stack>
#include <set>
#include <bitset>
#include <functional>
using namespace std;
#define fast_io ios_base::sync_with_stdio (false) ; cin.tie(0) ; cout.tie(0) ;
#define ll long long int
#define rep(i,n) for(ll i=0; i<(ll)(n); i++)
#define reps(i,n) for(ll i=1; i<=(ll)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
ll MOD;
#define INF (int)(1123456789)
#define LINF (long long int)(112345678901234567)
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
#define all(v) v.begin(), v.end()
typedef pair<int, int> Pii;
typedef pair<ll, ll> Pll;

ll mpow(ll a, ll b){
  if(b==0) return 1;
  else if(b%2==0){ll memo = mpow(a,b/2); return memo*memo%MOD;}
  else return mpow(a,b-1) * a % MOD;
}
ll lpow(ll a, ll b){
  if(b==0) return 1;
  else if(b%2==0){ll memo = lpow(a,b/2); return memo*memo;}
  else return lpow(a,b-1) * a;
}
ll gcd(ll a, ll b){
  if(b==0) return a;
  else return gcd(b, a%b);
}
vector<ll> kaijo_memo;
ll kaijo(ll n){
  if(kaijo_memo.size() > n) return kaijo_memo[n];
  if(kaijo_memo.size() == 0) kaijo_memo.push_back(1);
  while(kaijo_memo.size() <= n) kaijo_memo.push_back(kaijo_memo[kaijo_memo.size()-1] * kaijo_memo.size() % MOD);
  return kaijo_memo[n];
}
vector<ll> gyaku_kaijo_memo;
ll gyaku_kaijo(ll n){
  if(gyaku_kaijo_memo.size() > n) return gyaku_kaijo_memo[n];
  if(gyaku_kaijo_memo.size() == 0) gyaku_kaijo_memo.push_back(1);
  while(gyaku_kaijo_memo.size() <= n) gyaku_kaijo_memo.push_back(gyaku_kaijo_memo[gyaku_kaijo_memo.size()-1] * mpow(gyaku_kaijo_memo.size(), MOD-2) % MOD);
  return gyaku_kaijo_memo[n];
}

ll nCr(ll n, ll r){
  if(n == r) return 1;//0個の丸と-1個の棒みたいな時に時に効く？不安.
  if(n < r || r < 0) return 0;
  ll ret = 1;
  if(n <= 1e7){
    ret *= kaijo(n); ret %= MOD;
    ret *= gyaku_kaijo(r); ret %= MOD;
    ret *= gyaku_kaijo(n-r); ret %= MOD;
  }else{
    rep(i,r){
      ret *= n-i; ret %= MOD;
      ret *= mpow(r-i, MOD-2); ret %= MOD;
    }
  }
  return ret;
}

int main(void){
  fast_io
  cout<<fixed<<setprecision(15);

  ll n,m;cin>>n>>m;
  ll N = 3*n;
  MOD = m;
  ll ans = 0;

  rep(i,N){
    rep(j,N){
      ll k = N - i * 2 - j * 3; 
    
      if(i+j > n) continue;

      ans += kaijo(N) * mpow(mpow(2,i), MOD-2) % MOD * mpow(mpow(3,j), MOD-2) % MOD * gyaku_kaijo(i) % MOD * gyaku_kaijo(j) % MOD * gyaku_kaijo(k) % MOD;
      //cout<<ans<<" "<<mpow(mpow(3,j), MOD-2) * 6<<endl;
      //cout<<i<<" "<<j<<" "<<ans<<endl;
      ans %= MOD;
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 384
package main

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

var sc = bufio.NewScanner(os.Stdin)

func readInt() int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return i
}

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

func main() {
	sc.Split(bufio.ScanWords)
	n, m := readInt(), readInt()

	h := make([]int, n)
	for i := 0; i < n; i++ {
		h[i] = readInt()
	}

	// graph := make([][]int, n)
	// for i := 0; i < m; i++ {
	// 	a, b := readInt(), readInt()
	// 	a--
	// 	b--
	// 	graph[a] = append(graph[a], b)
	// 	graph[b] = append(graph[b], a)
	// }
	// fmt.Println(graph)

	// for i := 0; i < n; i++ {
	// 	for j := 0; j < m; j++ {
	// 		if h[i] > graph[]
	// 	}
	// }

	graph := make(map[int]int, n)
	for i := 0; i < n; i++ {
		graph[i] = 0
	}

	for i := 0; i < m; i++ {
		a, b := readInt(), readInt()
		a--
		b--
		if graph[a] < h[b] {
			graph[a] = h[b]
		}
		if graph[b] < h[a] {
			graph[b] = h[a]
		}
	}
	ans := 0
	for k, v := range graph {
		if h[k] > v {
			ans++
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 7092
#include <bits/stdc++.h>
using namespace std;
int main () {
  long N;
  cin >> N;
  vector<long> data(N), sub(N);
  long sum = 0;
  for(int i = 0; i < N; i++){
    cin >> data.at(i);
  }
  sub.at(N - 1) = data.at(N - 1);
  for(int i = N - 2; i >= 0; i--){
    sub.at(i) = sub.at(i + 1) + data.at(i);
  }
  long ans = 0, a;
  for(int i = 0; i < N; i++){
    a = sub.at(i) - data.at(i);
    a %= 1000000007;
    ans += a * data.at(i);
    ans %= 1000000007;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 6352
import java.util.*;

public class Main {

  public static void main (String[] args) {

    Scanner sc = new Scanner(System.in);
    
    String abcd = sc.next();
    sc.close();

    String[] ABCD = abcd.split("");

    String result = "";
    
    int[] ans = new int[8];

    ans[0] = Integer.valueOf(ABCD[0]) + Integer.valueOf(ABCD[1]) + Integer.valueOf(ABCD[2]) + Integer.valueOf(ABCD[3]);
    ans[1] = Integer.valueOf(ABCD[0]) + Integer.valueOf(ABCD[1]) + Integer.valueOf(ABCD[2]) - Integer.valueOf(ABCD[3]);
    ans[2] = Integer.valueOf(ABCD[0]) + Integer.valueOf(ABCD[1]) - Integer.valueOf(ABCD[2]) + Integer.valueOf(ABCD[3]);
    ans[3] = Integer.valueOf(ABCD[0]) + Integer.valueOf(ABCD[1]) - Integer.valueOf(ABCD[2]) - Integer.valueOf(ABCD[3]);
    ans[4] = Integer.valueOf(ABCD[0]) - Integer.valueOf(ABCD[1]) - Integer.valueOf(ABCD[2]) - Integer.valueOf(ABCD[3]);
    ans[5] = Integer.valueOf(ABCD[0]) - Integer.valueOf(ABCD[1]) - Integer.valueOf(ABCD[2]) + Integer.valueOf(ABCD[3]);
    ans[6] = Integer.valueOf(ABCD[0]) - Integer.valueOf(ABCD[1]) + Integer.valueOf(ABCD[2]) - Integer.valueOf(ABCD[3]);
    ans[7] = Integer.valueOf(ABCD[0]) - Integer.valueOf(ABCD[1]) + Integer.valueOf(ABCD[2]) + Integer.valueOf(ABCD[3]);

    if (ans[0] == 7) { result = ABCD[0] + "+" + ABCD[1] + "+" + ABCD[2] + "+" + ABCD[3] + "=7"; }
    if (ans[1] == 7) { result = ABCD[0] + "+" + ABCD[1] + "+" + ABCD[2] + "-" + ABCD[3] + "=7"; }
    if (ans[2] == 7) { result = ABCD[0] + "+" + ABCD[1] + "-" + ABCD[2] + "+" + ABCD[3] + "=7"; }
    if (ans[3] == 7) { result = ABCD[0] + "+" + ABCD[1] + "-" + ABCD[2] + "-" + ABCD[3] + "=7"; }
    if (ans[4] == 7) { result = ABCD[0] + "-" + ABCD[1] + "-" + ABCD[2] + "-" + ABCD[3] + "=7"; }
    if (ans[5] == 7) { result = ABCD[0] + "-" + ABCD[1] + "-" + ABCD[2] + "+" + ABCD[3] + "=7"; }
    if (ans[6] == 7) { result = ABCD[0] + "-" + ABCD[1] + "+" + ABCD[2] + "-" + ABCD[3] + "=7"; }
    if (ans[7] == 7) { result = ABCD[0] + "-" + ABCD[1] + "+" + ABCD[2] + "+" + ABCD[3] + "=7"; }

    System.out.println(result);

  }

}

Measured memory_bytes: 21972
#include<iostream>

using namespace std;

int main() {
	int x, a, b;

	cin >> x >> a >> b;

	int kyoriA = abs(x - a);
	int kyoriB = abs(x - b);

	if (kyoriA > kyoriB) {
		cout << "B" << endl;
	}
	else {
		cout << "A" << endl;
	}

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
typedef long long ll;
#define _GLIBCXX_DEBUG
int main()	{
  int k,n;
  int sum=0;
  cin>>k>>n;
  vector<int>a(n);
  rep(i,n) cin>>a[i];
  vector<int>d(n);
  for(int i=1;i<n;i++){
    d[i]=a[i]-a[i-1];
  }
  d[0]=k+a[0]-a[n-1];
  sort(d.begin(),d.end());
  rep(i,n-1)
    sum+=d[i];
  cout<<sum<<endl;
}

Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <iomanip>
using namespace std;
using i64 = int64_t;
#define rep(i, j, n) for(int i = (j); i < (n); ++i)
#define rrep(i, j, n) for(int i = (n) - 1; (j) <= i; --i)
constexpr i64 MOD = 1000000007;
constexpr i64 INF = 1LL << 60;

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

	int n; cin >> n;
	int* t = new int[n];
	int* v = new int[n];
	int tall = 0;
	rep(i, 0, n) {
		cin >> t[i];
		t[i] *= 2;
		tall += t[i];
	}
	rep(i, 0, n) cin >> v[i], v[i] *= 2;



	vector<int> limit(tall + 1, 0);
	int now = 0;
	rep(i, 0, n) {
		rep(j, now, now + t[i]) limit[j] = v[i];
		now += t[i];
	}

	vector<vector<double>> dp(tall + 1, vector<double>(220, -1.0));
	// dp[i][j] := 時間iで速度jの時の最大移動距離

	dp[0][0] = 0.0;
	rep(i, 0, tall) {
		rep(j, 0, limit[i] + 1) {
			if (dp[i][j] == -1.0) continue;
			// 加速
			if (j != limit[i]) dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i][j] + j + 0.5);
			// そのまま
			dp[i + 1][j] = max(dp[i + 1][j], dp[i][j] + j);
			if (j) dp[i + 1][j - 1] = max(dp[i + 1][j - 1], dp[i][j] + j - 0.5);
		}
	}
	cout << fixed << setprecision(10) << dp[tall][0] / 4.0 << endl;
	delete[] t, v;
	return 0;
}

Measured memory_bytes: 73520