akhauriyash/Code-Regression huggingface dataset:
#line 1 "/mnt/c/Users/leafc/dev/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 = "Yes", T no = "No") { cout << (val ? yes : no) << endl; }

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;
}


#line 2 "tmp.cpp"

// [s,t)の要素で出来うる値を全部作る
void build(int s, int t, vl &a, vector<vl> &v) {
  int len = t - s;
  REP(i, (1 << len)) {
    ll tmp = 0;
    int cnt = __builtin_popcount(i);
    FOR(j, s, t) {
      if ((i >> (j - s)) % 2 == 1)
        tmp += a[j];
    }
    v[cnt].push_back(tmp);
  }
}

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

  int n, k;
  cin >> n >> k;
  ll l, r;
  cin >> l >> r;
  vl a(n);
  REP(i, n) { cin >> a[i]; }

  vector<vl> u(n / 2 + 5), v(n / 2 + 5);

  build(0, n / 2, a, v);
  build(n / 2, n, a, u);
  for (auto &el : v) {
    sort(ALL(el));
  }
  for (auto &el : u) {
    sort(ALL(el));
  }

  ll ans = 0;
  int size = v.size();
  REP(i, size) {
    for (const auto el : v[i]) {
      if (k - i < 0 || (int)u.size() <= k - i)
        continue;
      ans += upper_bound(ALL(u[k - i]), r - el) - lower_bound(ALL(u[k - i]), l - el);
    }
  }

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



Measured memory_bytes: 23428
h, w = gets.split.map &:to_i
w += 1
a = $<.read.tr("#.\n","10").to_i 2
m = ~-(1 << h*w) - (1 << h*w) / ~-(1 << w)
c = 0
while a != m 
	a |= a << 1 | a >> 1 | a << w | a >> w 
	a &= m
	c += 1
end
p c


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

// g++ -std=c++17 -O2 -Wall template.cpp -o template
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    string s = "ABC";
    if (n <= 999) {
        cout << "ABC";
    } else {
        cout << "ABD";
    }
    cout << endl;
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    // Solution
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define p(s) cout<<(s)<<endl
#define REP(i,n,N) for(int i=n;i<N;i++)
#define RREP(i,n,N) for(int i=N-1;i>=n;i--)
#define CK(n,a,b) ((a)<=(n)&&(n)<(b))
#define F first
#define S second
typedef long long ll;
using namespace std;
const int inf = 1e9+7;

int N, M, K;
map<int,int> m;
ll ans;
int main(){
    cin>>N;
    REP(i,0,N){
        int b;
        cin>>b;
        m[b]++;

    }
    for(auto a:m){
        if(a.second>a.first){
            ans+=a.second-a.first;

        }else if(a.second<a.first){
            ans+=a.second;
        }
    }
    p(ans);
    return 0;
}

Measured memory_bytes: 4736
#include <bits/stdc++.h>
using namespace std;
const int INF = 1<<30;
struct Hoge {
	int a, b;
};
int N, K;
vector<vector<int>> G;
vector<int> P;
vector<Hoge> hoge;

void f(int p, int q) {
	if (P[p] != INF) {
		hoge[p].a = hoge[p].b = P[p];
	} else {
		hoge[p].a = hoge[q].a - 1;
		hoge[p].b = hoge[q].b + 1;
	}
	for (int x : G[p]) if (x != q) {
		f(x, p);
		hoge[p].a = max(hoge[p].a, hoge[x].a - 1);
		hoge[p].b = min(hoge[p].b, hoge[x].b + 1);
	}
}

bool g(int p, int q) {
	if (P[p] == INF) {
		if (hoge[p].a <= P[q]-1 && P[q]-1 <= hoge[p].b) {
			P[p] = P[q]-1;
		} else if (hoge[p].a <= P[q]+1 && P[q]+1 <= hoge[p].b) {
			P[p] = P[q]+1;
		} else {
			return false;
		}
	}
	if (q >= 0 && abs(P[p] - P[q]) != 1) return false;
	for (int x : G[p]) if (x != q) {
		if (!g(x, p)) return false;
	}
	return true;
}

int main() {
	cin >> N;
	G.resize(N);
	for (int i = 1; i < N; ++ i) {
		int x, y;
		cin >> x >> y;
		-- x; -- y;
		G[x].push_back(y);
		G[y].push_back(x);
	}
	cin >> K;
	P.resize(N, INF);
	int v0 = -1;
	for (int i = 0; i < K; ++ i) {
		int v, p;
		cin >> v >> p;
		P[v-1] = p;
		if (i == 0) v0 = v-1;
	}
	hoge.resize(N);
	f(v0, -1);
	//for (int i = 0; i < N; ++ i) cout << hoge[i].a << " " << hoge[i].b << endl;
	if (g(v0, -1)) {
		cout << "Yes" << endl;
		for (auto x : P) {
			cout << x << endl;
		}
	} else {
		cout << "No" << endl;
	}
}


Measured memory_bytes: 13824
#include <stdio.h>

int main(){
  int A[100];
  int key;
  int i;
  int j;
  int n;


  scanf("%d",&n);
  
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }
  
  for(j=1;j<n;j++){
    key = A[j];
    
    for(i=0;i<n-1;i++){
    printf("%d ",A[i]);
    }
    printf("%d\n", A[i]);
    
    i=j-1;
    while(i>=0 && A[i]>key){
      A[i+1]=A[i];
      i--;
    }
    A[i+1]=key;
  }

  for(i=0;i<n-1;i++){
    printf("%d ",A[i]);
   }
  printf("%d\n", A[i]);
    
  return 0;
}

Measured memory_bytes: 600
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(i=0;i<n;i++)
#define loop(i,a,n) for(i=a;i<n;i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

typedef vector<int> vi;
typedef pair<int,int> pii;

int main(void) {
  int i,j;
  int n;
  cin>>n;
  vi a(n),ans;
  rep(i,n)cin>>a[i];
  for(i=n-1;i>=0;i-=2)ans.push_back(a[i]);
  for(i=n%2;i<n;i+=2)ans.push_back(a[i]);
  rep(i,n){
    if(i)cout<<" ";
    cout<<ans[i];
  }
  cout<<endl;
}


Measured memory_bytes: 3828
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
using namespace std;
#define INF 2147483647
#define int long long
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
//typedef long long int ll;


signed main(){
	
	int n;
	int a[111111],b[111111],c[111111],ans=0;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a[i]>>b[i];
		ans-=b[i];
		c[i]=a[i]+b[i];
	}
	sort(c,c+n,greater<int>());
	for(int i=0;i<n;i++){
		if(i%2==0)ans+=c[i];
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 2816
// lcmとか__builtin_popcountとかはg++ -std=c++17 default.cppみたいなかんじで

#include <bits/stdc++.h>
#define mod 1000000007
#define INF LLONG_MAX
#define ll long long
#define ln cout<<endl
#define Yes cout<<"Yes"<<endl
#define NO cout<<"NO"<<endl
#define YES cout<<"YES"<<endl
#define No cout<<"No"<<endl
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
using namespace std;
ll dx[4]={1,0,-1,0};
ll dy[4]={0,1,0,-1};

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

    ll  a,b,c,d,e,n,k,maxi=0,f=0,mini=INF,sum=0,q;
	string str,stra,straa;
    ll x,y,z;
    char ca,cb,cc;
    cin>>str;
    if(str[2]==str[3]&&str[4]==str[5]) Yes;
    else No;
    return 0;
}


Measured memory_bytes: 3612
#include<iostream>
#include<vector>
using namespace std;
int main(){
    int n,tmp,sum;
    vector<int> a,b,c;
    cin>>n;
    for(int i=0; i<n; i++){
        cin>>tmp;
        a.push_back(tmp);
    }
    for(int i=0; i<n; i++){
        cin>>tmp;
        b.push_back(tmp);
    }
    for(int i=0; i<n-1; i++){
        cin>>tmp;
        c.push_back(tmp);
    }

    sum=0;
    for(int i=0; i<n; i++){
        sum+=b[i];
    }
    for(int i=0; i<n-1; i++){
        if(a[i]+1==a[i+1]){
            //cout<<i<<":"<<a[i]<<" == "<<a[i+1]<<endl;
            sum+=c[a[i]-1];
        }
    }
    cout<<sum<<endl;
    return 0;
}

Measured memory_bytes: 256
from collections import Counter

N = int(input())
S = input()

counter = Counter(S)
r_count = counter['R']
g_count = counter['G']
b_count = counter['B']

ans = r_count * g_count * b_count
for i in range(N):
    for j in range(N):
        k = 2 * j - i
        if k > N-1:
            break
        if i < j < k and S[i] != S[j] and S[i] != S[k] and S[j] != S[k]:
            ans -= 1

print(ans)

Measured memory_bytes: 74184
#include <iostream>


int main() {

    int a, b;

    std::cin >> a >> b;

    int doubled_b = b * 2;

    if (doubled_b >= a) {
        std::cout << 0 << std::endl;
    } else {
        std::cout << a - doubled_b << std::endl;
    }

    return 0;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int(i) = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define pb push_back
#define MP(a, b) make_pair((a), (b))
template <class T> vector<T> make_vec(size_t a, T val) {
    return vector<T>(a, val);
}
template <class... Ts> auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec(ts...))>(a, make_vec(ts...));
}
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using Graph = vector<vector<int>>;
template <typename T> struct edge {
    int to;
    T cost;
    edge(int t, T c) : to(t), cost(c) {}
};
template <typename T> using WGraph = vector<vector<edge<T>>>;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;

template <ll MOD = 998244353, ll primroot = 3> class ConvolutionNTT {
  private:
    vector<ll> a, b;
    ll modpow(ll v, ll n) {
        ll x = 1, p = v;
        while(n > 0) {
            if(n % 2 == 0) {
                p = (p * p) % MOD;
                n /= 2;
            } else {
                x = (x * p) % MOD;
                n--;
            }
        }
        return x;
    }
    ll modinv(ll v) { return modpow(v, MOD - 2); }

  public:
    ConvolutionNTT(vector<ll> &_a, vector<ll> &_b) {
        a = _a;
        b = _b;
    }

    vector<ll> ntt_rec(vector<ll> a, bool is_inverse = false) {
        int n = a.size();
        if(n == 1)
            return a;
        vector<ll> f0, f1;
        for(int i = 0; i < (n / 2); i++) {
            f0.push_back(a[i * 2]);
            f1.push_back(a[i * 2 + 1]);
        }
        f0 = ntt_rec(f0, is_inverse), f1 = ntt_rec(f1, is_inverse);
        ll zeta = modpow(is_inverse ? modinv(primroot) : primroot, MOD / n);
        ll pow_zeta = 1;
        for(int i = 0; i < n; i++) {
            a[i] = (f0[i % (n / 2)] + pow_zeta * f1[i % (n / 2)])%MOD;
            pow_zeta *= zeta;
            pow_zeta %=MOD;
        }
        return a;
    }

    vector<ll> ntt(vector<ll> a, bool is_inverse) {
        vector<ll> ret = ntt_rec(a, is_inverse);
        int n = ret.size();
        if(is_inverse) {
            for(int i = 0; i < n; i++) {
                ret[i] *= modinv(n);
                ret[i] %= MOD;
            }
        }
        return ret;
    }

    vector<ll> convolve() {
        int s = a.size() + b.size() - 1;
        int t = 1;
        while(t < s)
            t *= 2;
        a.resize(t);
        b.resize(t);

        vector<ll> A = ntt(a, false);
        vector<ll> B = ntt(b, false);
        vector<ll> C(t);
        for(int i = 0; i < t; i++) {
            C[i] = (A[i] * B[i]) % MOD;
        }
        C = ntt(C, true);
        return C;
    }
};

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N, M;
    cin >> N >> M;
    vector<ll> A(N), B(M);
    rep(i, N) cin >> A[i];
    rep(i, M) cin >> B[i];
    ConvolutionNTT<> ntt(A, B);
    auto C = ntt.convolve();
    for(int i = 0; i < N + M - 1; i++)
        cout << C[i] << " ";
    cout << endl;
}


Measured memory_bytes: 93340
using System;
class ITP1_7_B
{
    static void Main()
    {
        while (true)
        {
            string[] input = Console.ReadLine().Split(' ');
            int n = int.Parse(input[0]);
            int x = int.Parse(input[1]);
            if (n == 0 && x == 0) break;
            int count = 0;
            for (int i = 1; i <= n; i++)
            {
                for (int j = i+1; j <= n; j++)
                {
                    for (int k = j+1; k <= n; k++)
                    {
                        if (i + j + k == x) count++;
                    }
                }
            }
            Console.WriteLine(count);
        }
        return;
    }
}

Measured memory_bytes: 5616
//
//  main.cpp
//  ProgrammingContestChallengeBook2
//
//  Created by Hisaki Kobayashi on 2020/04/04.
//  Copyright © 2020 Hisaki Kobayashi. All rights reserved.
//

#include <iostream>
#include <stdio.h>
#include <string>
#include <bits/stdc++.h>
#include <stdlib.h>
//#include "mylibrary.hpp"

int gcd(int a, int b)
{
   if (a%b == 0)
   {
       return(b);
   }
   else
   {
       return(gcd(b, a%b));
   }
}

using namespace std;
int main(){
//    int N; cin >> N;
//
//    int hyaku=(N/100)%10,zyu=(N/10)%10,iti=N%10;
//
//    if(hyaku==7 || zyu == 7 || iti == 7)
//        cout << "Yes" << endl;
//    else{
//        cout << "No" << endl;
//    }
//
//
    
//
//    long N; cin >> N;
//
//    vector<int> A(7,0);
//
//    int div=1;
//    long sum=0;
//    for(int i=1;i<=N;i++){
//        if(i%3!=0 && i%5!=0){
//            sum+=i;
//        }
//    }
//    cout << sum << endl;

    
    int a, b, c,K;
    cin >> K;
    
    long sum=0;
    for(a=1;a<=K;a++){
        for(b=1;b<=K;b++){
            for(c=1;c<=K;c++){
                sum+=gcd(gcd(a, b),c);
            }
        }
    }
    
    cout << sum << endl;

    
    
    return 0;
 
}


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

using namespace std;


long long f(long long b, long long n) {
    long long ret = 0;
    while (n) {
        ret += n % b;
        n /= b;
    }
    return ret;
}

void run_case() {
//    n / b + (n % b) = s
//    let x = floor(n / b)
//    x + n - x * b = s
//    x - x * b = s - n
//    x * b - x = n - s
//    x ( b- 1 ) = n - s
//    b = (n-s) / x + 1

    long long n, s;
    cin >> n >> s;
    const int N = 1e6;
    if (n == s) {
        cout << n + 1 << endl;
        return;
    }

    if (s > n) {
        cout << -1 << endl;
        return;
    }

    for (int i = 2; i <= N; i++) {
        if (f(i, n) == s) {
            cout << i << endl;
            return;
        }
    }

    long long ans = n + n;
    for (int x = N; x >= 1; x--) {
        long long b = (n - s) / x + 1;
        if (b >= 2 && x == n / b && (n - s) % x == 0 && f(b, n) == s) {
            cout << b << endl;
            return;
        }
    }

    cout << -1 << endl;

}


int main() {


    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t = 1;
    //cin >> t;
    while (t--)run_case();


    return 0;
}
 
 
 
 
 
 
 
 


Measured memory_bytes: 3588
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<string>
#include<iostream>
using namespace std;
int r1[101010], r2[101010];
int main()
{
	string s, t;
	cin >> s >> t;
	for (int i = 0; i < s.size(); i++)r1[i + 1] = r1[i] + (s[i] - 'A' + 1);
	for (int i = 0; i < t.size(); i++)r2[i + 1] = r2[i] + (t[i] - 'A' + 1);
	int query;
	scanf("%d", &query);
	for (int i = 0; i < query; i++)
	{
		int za, zb, zc, zd;
		scanf("%d%d%d%d", &za, &zb, &zc, &zd);
		if ((r1[zb] - r1[za - 1]) % 3 == (r2[zd] - r2[zc - 1]) % 3)printf("YES\n");
		else printf("NO\n");
	}
}

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

using namespace std;

#define F first
#define S second
#define modulo ll (1e9 + 7)
#define EPS 1e-9

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

void init(){
    cin.tie(0);
    cin.sync_with_stdio(0);
}

const int N = 1e5, M = 109, OO = 0x3f3f3f3f;
const ll llOO = 0x3f3f3f3f3f3f3f3f;


void go(int tc){

    int t;  cin >> t;

    map<string, int> mp;
    while(t--){
        string s;   cin >> s;
        mp[s]++;
    }

    cout << "AC x " << mp["AC"] << '\n';
    cout << "WA x " << mp["WA"] << '\n';
    cout << "TLE x " << mp["TLE"] << '\n';
    cout << "RE x " << mp["RE"] << '\n';

}

int main(){
    init();

//    freopen("in.in", "r", stdin);
//    freopen("out.out", "w", stdout);

    int t = 1, tc = 1;
//    cin >> t;
    while(t--)  go(tc++);
}

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

int dp[100];

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


int main(){
  int a, b;
  cin >> a >> b;
  int c = (max(a, b) + min(a, b)) / 2;
  if((max(a, b) + min(a, b)) % 2 == 0) cout << c << endl;
  else cout << "IMPOSSIBLE" << endl;
}


/*





















*/




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, L[10], sum, MAX;
  sum = 0;
  MAX = 0;
  cin >> N ;
  for (int i = 0; i < N; i++){
  cin >> L[i];
  }
  
  for (int i = 0; i < N; i++){
    sum += L[i];
    if (MAX < L[i]){
      MAX = L[i];
    }
  }
  if ( sum - MAX > MAX ){
    cout << "Yes";
  }
  else{
    cout << "No";
  }
}


Measured memory_bytes: 256
{-# OPTIONS_GHC -O2 -funbox-strict-fields #-}
{-# LANGUAGE MultiWayIf #-}
import qualified Data.ByteString.Char8 as BS
import qualified Data.IntMap.Strict    as M
import           Data.Maybe            (fromJust, fromMaybe)

main :: IO ()
main = do
  n <- readLn
  as <- map readInt . BS.words <$> BS.getLine
  print . fromMaybe 0 $ solve n as

solve :: Int -> [Int] -> Maybe Int
solve n as = do
  let m = filter (\(_, v) -> v >= 2) . M.toDescList $ M.fromListWith (+) [(a, 1) | a <- as]
  (x, m') <- findBar m
  (y, _)  <- findBar m'
  return $ x * y

findBar :: [(Int, Int)] -> Maybe (Int, [(Int, Int)])
findBar m = do
  (k, v) <- if null m then Nothing else Just $ head m
  if
    | v >= 4 -> Just (k, m)
    | v >= 2 -> Just (k , tail m)
    | otherwise -> Nothing


readInt :: BS.ByteString -> Int
readInt = fst . fromJust . BS.readInt


Measured memory_bytes: 17788
// ConsoleApplication1.cpp : アプリケーションのエントリ ポイントを定義します。
//

//#include "stdafx.h"

#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <functional>

//085 B

using namespace std;
int main()
{
	int N;
	cin >> N;
	int a[110];
	for (int i = 0; i < N; i++) cin >> a[i];

	int backets[110] = {};
	for (int i = 0; i < N; i++) {
		backets[a[i]] = a[i];
	}
	int cnt = 0;
	for (int i = 0; i < 100; i++) {
		if (backets[i + 1] != 0) cnt++;
	}
	cout << cnt << endl;


	

	return 0;
}



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

ll dp[3005][3005][4];


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


  ll val[r+5][c+5];
  memset(val,0,sizeof(val));

  for(ll i=0;i<k;i++)
  {
    ll a,b,c;
    cin>>a>>b>>c;
    a--;
    b--;
    val[a][b]=c;
  }
  for(ll i=0;i<r;i++)
  {
    for(ll j=0;j<c;j++)
    {
      dp[i][j][1]=val[i][j];
    }
  }
  /*for(ll i=0;i<r;i++)
    {
      for(ll j=0;j<c;j++)
      {
        cout<<val[i][j]<<" ";
      }
      cout<<endl;
    }*/


  for(ll j=1;j<c;j++)
  {
    for(k=1;k<4;k++)
    {
      dp[0][j][k]=max(dp[0][j][k],dp[0][j-1][k-1]+val[0][j]);
      dp[0][j][k]=max(dp[0][j][k],dp[0][j-1][k]);
    }
    
  }



  for(ll i=1;i<r;i++)
  {
    for(ll j=0;j<c;j++)
    {

      for(ll k=0;k<4;k++)
      {
        dp[i][j][0]=max(dp[i][j][0],dp[i-1][j][k]);
      }
      dp[i][j][1]=max(dp[i][j][1],dp[i][j][0]+val[i][j]);
      
      if(j!=0)
      for(ll k=1;k<4;k++)
      {
        dp[i][j][k]=max(dp[i][j-1][k],dp[i][j][k]);        
        dp[i][j][k]=max(dp[i][j][k],dp[i][j-1][k-1]+val[i][j]);
        dp[i][j][k]=max(dp[i][j][k-1],dp[i][j][k]);
      }
    }
  }
  /*cout<<endl;
  for(ll i=0;i<c;i++)
  {
    for(ll k=0;k<4;k++)
    {
      cout<<dp[1][i][k]<<" ";
    }
    cout<<endl;
  }*/



  ll ans=0;
  for(ll k=0;k<4;k++)
  {
    ans=max(dp[r-1][c-1][k],ans);
  }
  cout<<ans<<endl;
  return 0;

}

Measured memory_bytes: 355792
#include <bits/stdc++.h>
using namespace std;
int main() {
  int A, B, C, D, E;
  cin >> A >> B >> C >> D >> E;
  if(A == 0) {
    cout << 1 << endl;
  }
  if(B == 0) {
    cout << 2 << endl;
  }
  if(C == 0) {
    cout << 3 << endl;
  }
  if(D == 0) {
    cout << 4 << endl;
  }
  if(E == 0) {
    cout << 5 << endl;
  }
}

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

int main() {
	// your code goes here
	int a,b,c,k;
	cin>>a>>b>>c>>k;
	int count = 0;
	while(b<=a)
	{
		b*=2;
		count++;
	}
	while(c<=b)
	{
		c*=2;
		count++;
	}
	if(count<=k)
	{
		cout<<"Yes";
	}
	else
	{
		cout<<"No";
	}
	return 0;
}

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

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
using vec_b = vector<bool>;
using vec_str = vector<string>;
using graph = mat;
using edge = pair<ll,ll>;
using wgraph = vector<vector<edge>>;

#define INF (1LL << 60)
#define MOD 1000000007

#define REP(i,m,n) for(ll (i)=(m),i##_len=(n);(i)<(i##_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define _PR(x) cout << (x) << endl
#define _PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define pb push_back


int main()
{
    ll N;
    cin >> N;
    vec A(N);
    REP(i,0,N) cin >> A[i];

    ll k = 1;
    REP(i,0,N) {
        if(A[i] == k) ++k;
    }
    if(N-k+1 < N) _PR(N-k+1);
    else _PR(-1);


    return 0;
}

/*



*/

Measured memory_bytes: 1792
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;

int main() {
  ll n;
  while(cin>>n,n) {
    int ans = 0;
    for (ll i = 5; i<=n; i*=5)
      ans += n/i;
    cout << ans << endl;
  }

}

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

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

const int INF=1010101010;
int dp[5001];
int nx[5001];
int min1[5001], min2[5001];

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

    vector<int> a(n);
    for(int i=1; i<n; ++i) scanf(" %d", &a[i]);

    fill(dp,dp+5001,INF);
    dp[0]=0;

    rep(i,n/2+1) min1[i]=dp[i];
    min2[0]=INF;
    for(int i=1; i<=n/2; ++i) min2[i]=dp[i-1];

    int ans=INF;

    for(int i=1; i<n; ++i)
    {
        rep(j,n/2+1) nx[j]=min(min1[j],min2[j])+a[i];

        rep(j,n/2+1) min1[j]=min(min1[j], nx[j]);
        for(int j=n/2; j>=1; --j) min2[j]=min(min2[j-1],nx[j-1]);

        rep(j,n/2+1) dp[j]=nx[j];

        ans=min(ans,dp[n/2]);
        if(n/2-n+i>=0) ans=min(ans,dp[n/2-n+i]);
    }

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

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

int main() {
	string s;
	cin >> s;
	int n = s.size();
	int mind = 1000000000;
	int no;
	for(int i = 0;i < n-2;i++){
	    int curno = 100*(s[i]-'0')+10*(s[i+1]-'0')+(s[i+2]-'0');
	    int diff = abs(curno-753);
	    if(diff < mind){
	        mind = diff;
	        no = curno;
	    }
	}
	cout << mind << endl;
	return 0;
}

Measured memory_bytes: 256
#![allow(unused_imports)]
#![allow(unused_macros)]
#![allow(non_snake_case)]
#![allow(dead_code)]
#![allow(unused_variables)]
#![allow(unused_mut)]
#![allow(unused_assignments)]
use proconio::input;
use proconio::marker::*;
use std::collections::*;
use std::cmp::*;
use std::mem::swap;
use std::f64::consts::*;

const MOD: u64 = 1000000007;
const INF: usize = std::usize::MAX / 4;

fn main() {
    input! {
        N: usize,
        M: usize,
        A: [usize; N],
    }

    let S = A.iter().sum();

    if A.iter().filter(|&a| a * 4 * M >= S).count() >= M {
        println!("Yes");
    } else {
        println!("No");
    }
}


Measured memory_bytes: 2180
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;
import std.bigint;
import std.ascii;


void main()
{
  auto n = readln.chomp.to!int;
  writeln(n*800-(n/15)*200);
}


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

int main()
{
    long long a,x,y,b;
    cin>>a;
    b=sqrt(a);

    for (int i=b;i>0;i--)
    {
        if (a%i==0)
        {
        x=i;
        break;
        }
    }
    y=a/x;
    cout<<(x+y-2)<<endl;


    return 0;
}


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

int main(void){
    std::string s;
    std::cin >> s;
    if(s[2] == s[3] && s[4] == s[5]){
        std::cout << "Yes" << std::endl;
    }else{
        std::cout << "No" << std::endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
using namespace std;
int main()
{
	int a,b,c;
	scanf("%d%d%d",&a,&b,&c);
	long long ans;
	if (a+b>=c) ans=b+c;else ans=a+1+b*2;
	printf("%lld\n",ans);
}

Measured memory_bytes: 128
s=list(input())

E=0
W=0
N=0
S=0

for i in range(len(s)):
    if s[i]=="E":
        E=1
    elif s[i]=="W":
        W=1
    elif s[i]=="N":
        N=1
    elif s[i]=="S":
        S=1
if E==W and N==S:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
#include <bitset>
#include <functional>
#include <queue>
#include <utility>
#include <map>
using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define dump(x)  cerr << #x << " = " << (x) << endl;
typedef long long LL;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
typedef pair<string, PII> PSI;
typedef pair<vector<int>, vector<int>> PVV;
const int INF = 1 << 29;	// 十分大きい値にする, INT_MAX にしないのはオーバーフロー対策

const int MAX_N = 1e+5, MAX_M = 1e+5;
const int MOD = 1000000007;

int N, M;
int a[MAX_N + 1];
bool safe[MAX_N + 1];
long long ans;
LL memo[MAX_N + 1];

LL dfs(int stair, int max)
{
	LL ans = 0;
	LL tmp = 0;

	if (stair > max)
		return 0;
	else if (stair == max)
		return 1;

	if (safe[stair] == false)
		return 0;

	for (int i = 1; i <= 2; i++) {
		if (memo[stair + i] == -1) {
			memo[stair + i] = dfs(stair + i, max);
		}
		ans = (ans + memo[stair + i]) % MOD;
	}

	return ans;
}

void solve()
{
	cin >> N >> M;

	FOR(i, 0, N + 1) {
		safe[i] = true;
		memo[i] = -1;
	}

	FOR(i, 0, M) {
		cin >> a[i];
		safe[a[i]] = false;
	}

	// 昇順ソート
	sort(a, a + N, [](const int& x, const int& y) { return x < y; });

	// 足場が2連続で壊れていれば無理
	FOR(i, 0, M - 1) {
		if (a[i + 1] - a[i] == 1) {
			cout << "0" << endl;
			return;
		}
	}

	ans = dfs(0, N);
	
	cout << ans << endl;
}

int main(void)
{
	solve();

	return 0;
}


Measured memory_bytes: 7808
import java.io.IOException;
import java.util.ArrayList;
import java.util.Scanner;

class Main {
	public static void main(String args[]) throws IOException {
		@SuppressWarnings("resource")
		Scanner cin = new Scanner(System.in);
		ArrayList<String> inLines = new ArrayList<String>();
		for (; cin.hasNext();) {
			inLines.add(cin.nextLine());
		}
		Solver solver = new Solver();
		solver.solve(inLines);
	}
}

class Solver {

	public void solve(ArrayList<String> inLines) {
		long mod = 1000000007;
		long N = Integer.parseInt(inLines.get(0));
		long ans = 1;
		for (int i = 1; i <= N; i++) {
			ans = (ans * i) % mod;
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 23892
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
int N, M,bigL,smallR;
int L[100000], R[100000];

cin >> N >> M;
for (int i = 0; i < M; i++){
	cin >> L[i] >> R[i];
}

bigL = 0;
smallR = 100000;

for (int i = 0; i < M; i++){
	if (bigL < L[i]){
		bigL = L[i];
	}
		if (smallR > R[i]){
			smallR = R[i];
		}
	}
if (smallR - bigL+1 <= 0){
	cout << 0 << endl;
	return 0;
}
cout << smallR - bigL+1 << endl;
return 0;
}

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

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

#define forn(i, a, n) for (int i = a; i < n; ++i)
#define ford(i, a, n) for (int i = n - 1; i >= a; --i)
#define fore(i, a, n) for (int i = a; i <= n; ++i)
#define all(a) (a).begin(), (a).end()
#define fs first
#define sn second
#define trace(a)\
	for (auto i : a) cerr << i << ' ';\
	cerr << '\n'
#define eb emplace_back

#ifndef M_PI
const ld M_PI = acos(-1.0);
#endif

const ld eps = 1e-9;
const int INF = 2000000000;
const ll LINF = 1ll * INF * INF;
const ll MOD = 1000000007;

bool isPrime(int x) {
	for (int i = 2; i * i <= x; ++i)
		if (x % i == 0)
			return false;
	return true;
}

int main() {
	int n;
	scanf("%d", &n);
	vector<ll> s(n);
	forn(i, 0, n) scanf("%lld", &s[i]);
	vector<int> primes;
	forn(i, 2, 1e5 + 10)
		if (isPrime(i))
			primes.eb(i);
	vector<ll> p2, p3;
	for (int i : primes) p2.eb(1ll * i * i);
	for (int i : primes) {
		ll cb = 1ll * i * i * i;
		if (cb < 1e10 + 10) p3.eb(cb);
		else break;
	}
	map<ll, int> cnt;
	for (ll x : s) {
		for (ll j : p3) {
			if (j > x) break;
			while (x % j == 0) x /= j;
		}
		cnt[x]++;
	}
	ll ans = 0;
	map<ll, char> used;
	for (auto p : cnt) {
		ll x = p.fs;
		if (used.count(x)) continue;
		if (x == 1) {
			ans += 1;
		} else {
			used[x] = 1;
			ll inv = 1, rad = 1;
			forn(j, 0, p3.size()) {
				if (x % p2[j] == 0) {
					x /= p2[j];
					inv *= primes[j];
				}
				if (x % primes[j] == 0) {
					x /= primes[j];
					rad *= primes[j];
				}
			}
			ll root = (ll)(sqrt(x) + 0.1);
			if (root * root == x) {
				auto it = lower_bound(all(primes), root);
				if (it != primes.end() && *it == root) {
					x = 1;
					inv *= root;
				}
			}
			rad *= x;
			ld res = (ld)inv * rad * rad;
			if (res > 2e10) {
				ans += p.sn;
			} else {
				inv = inv * rad * rad;
				used[inv] = 1;
				auto ptr = cnt.find(inv);
				if (ptr == cnt.end()) ans += p.sn;
				else ans += max(p.sn, ptr->sn);
			}
		}
	}
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 16640
#include <iostream>
#include <fstream>
#include <vector>
#include <cassert>
#include <algorithm>

using namespace std;


/**
* @fn
* /\/\/\/
* @brief 奇数個目で一番頻出のやつ(A1)がなにかを調べる
*        偶数個目で同様に行い(B1)、N - (A1+B1)を回答。ただし、A1=B1の場合は、次に多くでてくるやつにする(A2>=B2ならA2)
*        すべてA2がない場合は、B2。B2もなければ、無なので、N-A1+0となる
* @param (引数名) 引数の説明
* @param (引数名) 引数の説明
* @return 戻り値の説明
* @sa 参照すべき関数を書けばリンクが貼れる
* @detail 詳細な説明
*/
int main(){
    int N,tmp;
    vector<int> v_odd(100001,0);
    vector<int> v_even(100001,0);
//    std::ifstream in("input.txt");
//    std::cin.rdbuf(in.rdbuf());

    cin >> N;


    for(int i = 0; i < N; i++)
    {
        cin >> tmp;
        if(i % 2 == 0)v_even[tmp]++;
        else{v_odd[tmp]++;}
    }

    int max_odd,max_even,second_odd,second_even;
    //配列番号がほしい
    
    std::vector<int>::iterator max_odd_iter = std::max_element(v_odd.begin(), v_odd.end());
    int max_odd_index = std::distance(v_odd.begin(), max_odd_iter);
    max_odd = *max_odd_iter;

    std::vector<int>::iterator max_even_iter = std::max_element(v_even.begin(), v_even.end());
    int max_even_index = std::distance(v_even.begin(), max_even_iter);
    max_even = *max_even_iter;

    //2番目を取得
    //削除した後は要素番号は必要ないのでよしとする
    v_odd.erase(v_odd.begin()+ max_odd_index);
    v_even.erase(v_even.begin()+ max_even_index);

    std::vector<int>::iterator second_odd_iter = std::max_element(v_odd.begin(), v_odd.end());
    //int second_odd_index = std::distance(v_odd.begin(), second_odd_iter);
    second_odd = *second_odd_iter;

    std::vector<int>::iterator second_even_iter = std::max_element(v_even.begin(), v_even.end());
    //int second_even_index = std::distance(v_even.begin(), second_even_iter);
    second_even = *second_even_iter;

    int A,B;
    //maxの値が一致していたら
    if(max_odd_index == max_even_index)
    {
        //A2,B2がなかったら?
        //A2を取得
        //A1を削除してmaxを取得
        //B2
        if(second_odd >= second_even)
        {
            A = second_odd;
            B = max_even;
        }
        else
        {
            A = max_odd;
            B = second_even;
        }
    }
    else
    {
        A = max_odd;
        B = max_even;
    }

    int res;

    res = N -(A+B);
    cout << res << endl;
}



Measured memory_bytes: 1024
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define MOD 1000000007

int main(void) {
	char S[100010];
	int i, len;
	long long K;
	scanf("%s", &S);
	scanf("%lld", &K);
	len = strlen(S);

	for (i=0;i<len;i++) {
		if (i == len-1) {
			S[i] = 97 + (S[i]-97 + (char)(K%26)) % 26;
		} else if (S[i] != 'a' && K >= 123-S[i] ) {
			K -= 123-S[i];
			S[i] = 'a';
		} 
	}

	printf("%s\n", S);
	return 0;
}

Measured memory_bytes: 384
package main

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

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

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

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

func max_s(a, b int) (int, int) {
	if a > b {
		return a, b
	}
	return b, a
}

const m = 1000000000

func main() {
	sc.Split(bufio.ScanWords)

	S := getInt()
	a := m
	b := 1
	/*	var c, d int
		if S == int(1e18) {
			c = 0
			d = m
		} else if S <= m {
			c = S
			d = 0
		} else {
			c = m - S%m
			d = (S + c) / m
		}
	*/
	var c, d int
	if S == int(1e18) {
		c = 0
		d = m
	} else if S <= m {
		c = S
		d = 0
	} else {
		c = m - S%m
		d = S/m + 1

	}

	out(0, 0, a, b, c, d)

}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define ff first
#define ss second
#define debug(x) cerr<<#x<<" "<<x<<endl;
#define f(i,n) for(ll i=0; i<n; i++)
#define f1(i,n) for(ll i=1; i<=n; i++)
#define fr(i,n) for(ll i=n-1; i>=0; i--)
#define f1r(i,n) for(ll i=n; i>0; i--)
#define mst(arr,val) memset(arr,val,sizeof(arr))
#define all(x) x.begin(),x.end()

typedef long long int ll;
typedef pair<ll,ll> pii;
ll M=1e9+7;
ll M2=998244353;
void show(vector<ll> v)
{
    for(int i=0; i<v.size(); i++)
        cout<<v[i]<<" ";
    cout<<"\n";
}
void showrev(vector<ll> v)
{
    for(int i=0; i<v.size(); i++)
        cout<<v[v.size()-i-1]<<" ";
    cout<<"\n";
}
void showarr(ll arr[],ll n)
{
    for(ll i=0; i<n; i++)
        cout<<arr[i]<<" ";
    cout<<"\n";
}
void showpv(vector<pair<ll,ll> > v)
{
    f(i,v.size())
        cout<<"("<<v[i].ff<<","<<v[i].ss<<")"<<" ";
    cout<<"\n";
}
void showmap(map<ll,ll> m)
{
    for(auto i:m)
        cout<<" ("<<i.ff<<","<<i.ss<<") ";
    cout<<"\n";
}
ll knapSack(ll W, ll wt[], ll val[], ll n)
{
   ll i, w;
   ll K[n+1][W+1];

   // Build table K[][] in bottom up manner
   for (i = 0; i <= n; i++)
   {
       for (w = 0; w <= W; w++)
       {
           if (i==0 || w==0)
               K[i][w] = 0;
           else if (wt[i-1] <= w)
                 K[i][w] = max(val[i-1] + K[i-1][w-wt[i-1]],  K[i-1][w]);
           else
                 K[i][w] = K[i-1][w];
       }
   }

   return K[n][W];
}

int main()
{
    IOS
    ll T = 1,Q=1;
    //cin>>T;

    while(T--)
    {
        ll n,w; cin>>n>>w;
        ll wth[n],val[n];
        f(i,n)
            cin>>wth[i]>>val[i];
        ll ans = knapSack(w,wth,val,n);
        cout<<ans<<"\n";
    }
    return 0;
}


Measured memory_bytes: 79232
#include<bits/stdc++.h>
using namespace std;
#ifdef LOCAL_DEBUG
  #include "LOCAL_DEBUG.hpp"
#endif
#define int long long

signed main(){

  int n, k; cin >> n >> k;
  vector<int> h(n);
  int ans = 0;
  for(int i = 0; i < n; i++){
    cin >> h[i];
    ans += h[i];
  }
  sort(h.rbegin(),h.rend());

  for(int i = 0; i < min(n, k); i++){
    ans -= h[i];
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1920
//#define _USE_MATH_DEFINES
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("O3")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
//#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#pragma GCC diagnostic ignored "-Wmissing-declarations"
#define FINAL_OUT(x) {cout << (x) << '\n'; exit(0); }
inline int safe_mul(const int x, const int y) __attribute__ ((warn_unused_result));


int const maxn = 2505;
vector<pair<int,int>> gr[maxn];

void dfs(vector<bool>& used, int v) {
    used[v] = true;
    for (const auto& pa:  gr[v])
    if (!used[pa.first])
        dfs(used, pa.first);
}

int main()
{
//    freopen("in.txt","r", stdin);
    cout << fixed << setprecision(20);
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);


    int n,m,p;
    cin >> n >> m >> p;

    vector<tuple<int,int,int>> ed;
    for (int i = 0; i < m; ++i) {
        int a,b,c;
        cin >> a >> b >> c;
        gr[a].emplace_back(b, c);
        ed.emplace_back(a, b, c);
    }

    int64_t const INF = 1000000000000000009LL;
    vector<int64_t> dist(n + 1, INF);
    dist[1] = 0;
    vector<bool> st(n + 1, false);
    for (int i = 0; i <= 4 * n; ++i)
    for (const auto& tu : ed) {
        int x,y,c;
        tie(x,y,c) = tu;
        if (dist[x] != INF && dist[y] > dist[x] + p - c) {
            dist[y] = dist[x] + p - c;
            if (i > 2 * n)
                st[y] = true;
        }
    }

    vector<bool> used(n + 1, false);
    for (int i = 1; i <= n; ++i)
        if (st[i])
            dfs(used, i);

    if (used[n])
        FINAL_OUT(-1);


    int64_t ans = 0;
    fill(begin(dist), end(dist), -INF);
    dist[1] = 0;
    for (int i = 0; i <= 4*n; ++i)
    for (const auto& tu : ed) {
        int x,y,c;
        tie(x,y,c) = tu;
        if (dist[x] > -INF && dist[y] < dist[x] + c - p) {
            dist[y] = dist[x] + c - p;
        }
    }
    if (dist[n] <= -INF)
        FINAL_OUT(-1);

    cout << max<int64_t>(0, dist[n]) << endl;
}


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

long long teleport(long long start, long long num, vector<long long> *A)
{
	long long now = start;
	for (long long i = 0; i < num; i++)
	{
		now = (*A)[now];
	}
	return now;
}

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

	long long N, K;
	long long first;
	long long second;
	long long loop_point;
	scanf("%lld %lld", &N, &K);

	vector<long long> A(N + (long long)1);
	A[0] = (long long)-1;
	for (long long i = 1; i < N + (long long)1; i++) //A[0]は使わない
	{
		scanf("%lld", &A[i]);
	}

	vector<long long> time(N + 1, -1);
	time[0] = -1;
	time[1] = 0;
	long long now = (long long)1;
	while (true)
	{
		if (time[A[now]] == (long long)-1)
		{
			time[A[now]] = time[now] + (long long)1;
			now = A[now];
		}
		else
		{
			first = time[A[now]];
			second = time[now] + (long long)1;
			loop_point = A[now];
			// cout << "loop " << loop_point << "\n";
			// cout << "first " << first << "\n";
			// cout << "second " << second << "\n";
			break;
		}
	}

	if (K < first)
	{
		cout << teleport((long long)1, K, &A);
	}
	else
	{
		long long num = (K - first) % (second - first);
		// cout << "num=" << num << "\n";
		cout << teleport(loop_point, num, &A);
	}
	return 0;
}

Measured memory_bytes: 6448
// Marcin Knapik
#include<bits/stdc++.h>

#pragma GCC optimize("O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")

using namespace std;

//#include <ext/pb_ds/assoc_container.hpp> // order_of_key
//#include <ext/pb_ds/tree_policy.hpp> // find by order
//using namespace __gnu_pbds; 
//#define ordered_set tree< int , null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>  

// const ll MAX_LL = 0xFFFFFFFFFFFFFFFF;
// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define losuj(a, b) uniform_int_distribution<ull>(a, b)(rng)
#define losuj_real(a, b) uniform_real_distribution<long double>(a, b)(rng)

typedef long double             ld;
typedef long long               ll;
typedef unsigned long long      ull;
typedef pair<ll, ll>            pll;
typedef pair<int, int>          ii;
typedef vector<int>             vi;
typedef vector<ii>              vii;
typedef vector<vi>              vvi;
typedef vector<vector<ii>>      vvii;
typedef vector< ll >            vll;
typedef vector< pll >           vpll;
 
#define sz(a)                   (int)(a).size()
#define pb                      push_back
#define all(c)                  (c).begin(), (c).end()
#define rall(c)                 (c).rbegin(), (c).rend()
#define FOR(i, a)               for (int i = 0; i < (a); i++)
#define f                       first
#define s                       second
#define rr "\e[31m "
#define bb "\e[m "

template <class T> inline bool setmin(T &a, T b){if (a > b)return a = b, 1;return 0;}
template <class T> inline bool setmax(T &a, T b){if (a < b)return a = b, 1;return 0;}
 
template<class T> inline T fast(T a,T b,T mod) {ll res = 1; while(b){if(b&1) res = (res*a)%mod;a = (a*a)%mod;b >>= 1;}return res;}
template<class T> inline T russian(T a, T b, T mod) {ll res = 0; while(b){if(b&1) res = (res + a)%mod; a = (a+a)%mod; b>>=1;}return res;}
template <class T> istream &operator>>(istream &os, vector<T> &container){for (auto &u : container)os >> u;return os;}
template <class T> ostream &operator<<(ostream &os, const vector<T> &container){for (auto &u : container)os << u << " ";return os;}
template<typename T> inline T gcd(T a, T b) { while (b)swap(a %= b, b); return a; }

const ll INF = 1e9 + 7;
const ll mod = 998244353;
const ll N = 1e6+7;
const ll T = 1<<20;
const ll BIG_INF = 1e18 + 7;

ll n, m;

ll koszt[N];
ll dp[N];
int tab[35][34];

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);	
	
	cin >> n;
	FOR(i, n)
		FOR(j, n)
			cin >> tab[i][j];
	FOR(i, (1<<n)){
		for(int j = 0; j < n; j++)
			for(int k = 0; k < n; k++)
				if(i & (1<<j) && i & (1<<k))
					koszt[i] += tab[j][k];
		for(int j = i; j > 0; j = (j-1)&i)
			dp[i] = max(dp[i], dp[i-j] + koszt[j]);
	}

	cout << dp[(1<<n)-1]/2 << '\n';
}	


Measured memory_bytes: 4864
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,sse3,sse4,popcnt,abm,mmx")

#include <bits/stdc++.h>   
#include <stdio.h>    
 
using namespace std;
     
#define F first
#define S second
#define lb lower_bound               
#define ub upper_bound
#define pb push_back
#define pf push_front    
#define ppb pop_back
#define mp make_pair
#define bpp __builtin_popcountll                                                                                        
#define sqr(x) ((x) * (x)) 
#define al 0x3F3F3F3F
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define in insert
#define ppf pop_front
#define endl '\n'
//#define int long long
 
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
 
const int mod = (int)1e9 + 7;
const int N = (int)2e5 + 123;
const ll inf = (ll)3e18 + 1;

const double pi = acos (-1.0);
const double eps = 1e-7;
const int dx[] = {0, 0, 1, 0, -1};
const int dy[] = {0, 1, 0, -1, 0};

int n, dp[111], l[111], x, ans = 1;

inline void boost () {                    
   ios_base :: sync_with_stdio (NULL);
   cin.tie (NULL), cout.tie (NULL);          
}                                                     

inline void Solve () {
   cin >> n >> x;
   for (int i = 1; i <= n; i ++) cin >> l[i];
   for (int i = 2; i <= n + 1; i ++) {
      dp[i] = dp[i - 1] + l[i - 1];
      ans += (dp[i] <= x);
   }
   cout << ans;

}                                     

main () {                                       
// freopen (".in", "r", stdin);    
// freopen (".out", "w", stdout);              
   boost ();
   int tt = 1;
// cin >> tt;   
   while (tt --) {
      Solve ();
   }                                               
   return 0;      
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main(){
    string s,t;
    cin>>s>>t;
    string sub;
    bool x=false;
    for (int i=0; i<s.size(); i++) {
        if(s==t){
            x=true;
            break;
        }else{
            sub=s.substr(1,s.size());
            s[s.size()-1]=s[0];
            s.replace(0, s.size()-1, sub);
        }
    }
    if(x){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <functional>
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int H, W;
    cin >> H >> W;
    rep(i, H) {
        string S; cin >> S;
        cout << S << endl;
        cout << S << endl;
    }

    return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) throws IOException{
        BufferedReader reader = new BufferedReader((new InputStreamReader(System.in)));
        String[] l = reader.readLine().split(" ");
        int N = Integer.parseInt(l[0]);
        int M = Integer.parseInt(l[1]);
        if(N==M) System.out.println("Yes");
        else System.out.println("No");
    }
}


Measured memory_bytes: 22484
/*
これを入れて実行
g++ code.cpp
./a.out
 */
 
#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#include <cstring>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <math.h>
#include <tuple>
#include <iomanip>
#include <bitset>
#include <functional>

#define all(x) (x).begin(),(x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
using namespace std;
typedef long long ll;
typedef long double ld;
 
int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};
 
const long long INF = 1LL << 62;
const ll MOD = 1e9 + 7;
 
bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}
 
ll gcd(ll a, ll b){
	if (b == 0)return a;
	return gcd(b, a % b);
}
 
ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}
 
ll nCr(ll n, ll r){
    if(r == 0 || r == n){
        return 1;
    } else if(r == 1){
        return n;
    }
    return (nCr(n - 1, r) + nCr(n - 1, r - 1));
}
 
ll nPr(ll n, ll r){
    r = n - r;
    ll ret = 1;
    for (ll i = n; i >= r + 1; i--) ret *= i;
    return ret;
}
 
//-----------------------ここから-----------
int main(void){
    ll n, m;
    cin >> n >> m;
    vector<ll> x(n), y(m);
    rep(i,n) cin >> x[i];
    rep(i,m) cin >> y[i];

    ll xx = 0;
    rep(i, n){
        xx += (x[i] * i) % MOD;
        xx %= MOD;
        xx -= x[i] * ((n - i - 1) % MOD);
        xx %= MOD; 
    }

    ll yy = 0;
    rep(i, m){
        yy += (y[i] * i) % MOD;
        yy %= MOD;
        yy -= y[i] * ((m - i - 1) % MOD);
        yy %= MOD; 
    }

    
    ll ans = xx * yy % MOD;
    while(ans < 0) ans += MOD;
    cout << ans % MOD << endl;
}

Measured memory_bytes: 1792