akhauriyash/Code-Regression huggingface dataset:
#include<cmath>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<vector>
#include<set>
const int MAXN=5e5+10;
const double eps=1e-8;
const int MOD=1000000007;
using namespace std;
typedef  long long ll;
ll a[100005],b[100005];
int main()
{
    ll n,ans=0;
    cin>>n;
    a[0]=0;
    for(int i=1;i<=n+1;i++)
        cin>>a[i];
    b[0]=0;
    ll t=0;
    for(int i=1;i<=n;i++)
    {
        cin>>b[i];
        if(b[i]<=a[i])
        {
            ans+=b[i];
        }
        else if(b[i]<=a[i]+a[i+1])
        {
            ans+=b[i];
            a[i+1]-=(b[i]-a[i]);
        }
        else
        {
            ans+=a[i]+a[i+1];
            a[i+1]=0;
        }
    }
    cout<<ans<<endl;
    return 0;
}



Measured memory_bytes: 1792
def main():

    N = int(input())
    numsList = [i for i in map(int,input().split())]
    for i in numsList:
        if i%2 != 0:
            print(0)
            exit()

    flag = True
    ans = 0

    while(flag):
        numsList = [ i//2 for i in numsList]        
        for target in numsList:
            if target%2 != 0:
                flag = False
                break
        ans += 1
    
    print(ans)




if __name__== "__main__":
    main() 






Measured memory_bytes: 3060
#include<algorithm>
#include<complex>
#include<ctype.h>
#include<iomanip>
#include<iostream>
#include<map>
#include<math.h>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<stdio.h>
#include<string>
#include<string>
#include<vector>

using namespace std;
typedef long long ll;

#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("Yes")
#define p_no() p("No")

template < typename T >
void vprint(T &V){
	for(auto v : V){
    	cout << v << " ";
	}
	cout << endl;
}

const ll mod = 1e9 + 7;
const ll inf = 1e18;

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

    // input
    ll N, M, K;
    cin >> N >> M >> K;

    FOR(n, 0, N+1){
        FOR(m, 0, M+1){
            ll k = n*M + m*N -2*n*m;
            if(k==K){
                p_yes();
                return 0;
            }
        }
    }

    p_no();
    return 0;
}

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

int main(void){
    
    int a,b;
    cin >>a>>b;

    int max;
    if(a+b > a-b) max = a+b;
    else max = a-b;

    if(max < a*b) max = a*b;
    cout<<max<<endl;

    
    return 0;

}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    static int N;
    static int[] w;

    public static void main(String args[]) {
        Scanner scanner = new Scanner(System.in);
        N = scanner.nextInt();

        w = new int[N];
        for(int i = 0; i < N; i++) {
            w[i] = scanner.nextInt();
        }

        scanner.close();

        int ans = Integer.MAX_VALUE;
        int s1 = 0;
        for(int i = 0; i < N - 1; i++) {
            int s2 = 0;
            for(int j = N - 1; i + 1 <= j; j--) {
                s2 += w[j];
            }
            s1 += w[i];
            ans = Math.min(ans, Math.abs(s1 - s2));
        }

        System.out.println(ans);
    }
}

Measured memory_bytes: 22996
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <iterator>
using namespace std;

struct state {
  int h, m;
  state(int h, int m) : h(h), m(m) {}
  bool operator<(const state& rhs) const {
    return h * 60 + m < rhs.h * 60 + rhs.m;
  }
  bool operator==(const state& rhs) const {
    return h * 60 + m == rhs.h * 60 + rhs.m;
  }
};

int main() {
  int n, m;
  vector<state> v;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    int h, m;
    cin >> h >> m;
    v.emplace_back(h, m);
  }
  cin >> m;
  for (int i = 0; i < m; ++i) {
    int h, m;
    cin >> h >> m;
    v.emplace_back(h, m);
  }

  sort(begin(v), end(v));
  v.erase(unique(begin(v), end(v)), end(v));
  for (int i = 0; i < v.size(); ++i) {
    printf("%d:%02d%c", v[i].h, v[i].m, (i == v.size() - 1 ? '\n' : ' '));
  }
}

Measured memory_bytes: 3212
using System;
using System.Linq;
using System.IO;
using System.Text;
using System.Collections;
using System.Collections.Generic;
using System.Text.RegularExpressions;
 
class Program
{
    static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        double debt = 100000.0;
        const double point = 1000.0;
        for (int i = 0; i < n; i++)
        {
            debt *= 1.05;
            debt = Math.Ceiling(debt / point) * point;
        }
        Console.WriteLine(debt);
    }
}

Measured memory_bytes: 9004
#include<cstdio>
#include<iostream>
#define f(i,a,b) for(register int i=a;i<=b;++i)
#define max(a,b) a>b?a:b
using namespace std;
int n,height,m,cnt,ans;
int main() {
    scanf("%d", &n);
    f(i, 1, n) {
    	scanf("%d",&height);
    	if(m < height) {
    		ans = max(ans, cnt);
    		cnt = 0;
    	}
    	else ++cnt;
    	m = height;
	}
	printf("%d",max(ans, cnt));
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<climits>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define scan(arg) cin>>arg
#define prin(arg) cout<<arg<<"\n"
#define prin2(arg1,arg2) cout<<arg1<<" "<<arg2<<"\n"
using namespace std;
typedef long long ll;
const int NMAX=1<<17;
int H,W;
int h,w;
int main(){
  scan(H);scan(W);scan(h);scan(w);
  prin((H-h)*(W-w));
  
  return 0;
}


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


int N,M;

int main(){


  cin >> N;
  bool open = false;
  set<string> ID;       
  for(int i = 0; i < N ; i++){
    string tmp;
    cin >> tmp;
    ID.insert(tmp);
  }

  cin >> M;
  for(int i = 0; i < M ; i++){
    string tmp;  
    cin >> tmp;

    if(ID.count(tmp) == 0){
      cout <<"Unknown " << tmp << endl;
    }
    else{
      if(open){
	open = false;
	cout << "Closed by " << tmp << endl;
      }else{
	open =true;
	cout << "Opened by " << tmp << endl;
      }
    } 
  }
  return 0;
}

Measured memory_bytes: 1232
#pragma region include
#include <stdio.h>
#include <string>
#include <iostream>
#include <cstdlib>
#include <algorithm>
#pragma endregion
using namespace std;

#pragma region マクロ
// 配列の長さを取得する(ただし関数内ではポインタサイズに注意)
#define SIZE_OF_ARRAY(array) sizeof(array) / sizeof(*array)

// ソート
#define Sort(array, length) sort(array, array + length)
#define SortDESC(array, length) sort(array, array + length, greater<>())

// 配列の最大値、最小値取得
#define MAX_OF_ARRAY(array, length) *max_element(array, array + length)
#define MIN_OF_ARRAY(array, length) *min_element(array, array + length)
#pragma endregion

#pragma region Utility
#pragma region 配列要素の合計値を取得
template <typename T>
T getSum(T array[], int length)
{
    T sum = 0;
    for (int i = 0; i < length; i++)
    {
        sum += array[i];
    }
    return sum;
}
#pragma endregion

#pragma region ToString(int)
string ToString(int i)
{
    char buffer[1000];
    sprintf(buffer, "%d", i);
    return string(buffer);
}
#pragma endregion
#pragma endregion

int main()
{
    // ***  問題のpathを記載 ***
    // https://atcoder.jp/contests/abc156/tasks/abc156_a

    // 標準入力から値を取得
    int n, rate;
    scanf("%d %d", &n, &rate);

    int ans;
    if (n >= 10)
    {
        ans = rate;
    }
    else
    {
        ans = rate + (100 * (10 - n));
    }

    // 結果出力
    printf("%d\n", ans);

    // 成功時は必ず0を返す
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		
		int n = scanner.nextInt();
		
		int a[] = new int[n];
		
		for (int i = 0; i < n; i++) {
			a[i] = scanner.nextInt();
		}
		
		boolean flag = true;
		int count = 0;
		int j = 0;
		
		while(flag) {
			flag = false;
			for (int i = n - 1; i >= j + 1; i--) {
				if (a[i] < a[i - 1]) {
					int temp = a[i];
					a[i] = a[i - 1];
					a[i - 1] = temp;
					flag = true;
					count++;
				}
			}
			j++;
		}
		
		for (int i = 0; i < n-1; i++) {
			System.out.print(a[i] + " ");
		}
		System.out.println(a[n - 1]);
		
		System.out.println(count);
	}
} 



Measured memory_bytes: 26372
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_set>
#include <vector>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int, int>> vpii;
typedef vector<pair<ll, ll>> vpll;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<vc> vvc;
typedef vector<vs> vvs;
typedef vector<vll> vvll;
typedef map<int, int> mii;
typedef set<int> si;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define arep(i, v) for (auto i : v)
#define irep(it, stl) for (auto it = stl.begin(); it != stl.end(); it++)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define STLL(s) strtoll(s.c_str(), NULL, 10)
#define mp(p, q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define fi first
#define se second
#include <atcoder/all>
using namespace atcoder;
constexpr int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template <class T>
inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
inline void dump(T& v) {
    irep(i, v) { cout << (*i) << ((i == --v.end()) ? '\n' : ' '); }
}
template <class T, class U>
inline void dump(map<T, U>& v) {
    irep(i, v) { cout << i->first << " " << i->second << '\n'; }
}
inline string getline() {
    string s;
    getline(cin, s);
    return s;
}
inline void yn(const bool b) { b ? fin("yes") : fin("no"); }
inline void Yn(const bool b) { b ? fin("Yes") : fin("No"); }
inline void YN(const bool b) { b ? fin("YES") : fin("NO"); }
struct io {
    io() {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
};
const int INF = INT_MAX;
constexpr ll LLINF = 1LL << 61;
constexpr ll MOD = 1000000007;
constexpr ld EPS = 1e-11;

/* --------------------   ここまでテンプレ   -------------------- */

int main() {
    int Q;
    cin >> Q;
    while (Q--) {
        ll n, m, a, b;
        cin >> n >> m >> a >> b;
        cout << floor_sum(n, m, a, b) << endl;
    }
}

Measured memory_bytes: 3600
import sys 
sys.setrecursionlimit(10**6)

N = int(input())
h = [*map(lambda x: int(x), input().split())]

#bottom-up
def iterative_method(final):
    i = 0
    min_table = {0: 0}

    while (i < final):
        if i+1 in min_table:
            min_table[i+1] =  min(min_table[i+1], min_table[i] + abs(h[i+1] - h[i]))
        else:
            min_table[i+1] = min_table[i] + abs(h[i+1] - h[i])
        try:
            if i+2 in min_table:
                min_table[i+2] = min(min_table[i+2], min_table[i] + abs(h[i+2] - h[i]))
            else:
                min_table[i+2] = min_table[i] + abs(h[i+2] - h[i])
        except:
            break
        i += 1


    print(min_table[final])

#topdown
def recursive_method(n):
    memo = [-1]*n
    memo[0] = 0
    memo[1] = abs(h[1] - h[0])
    def recurse(i):
        if memo[i] != -1:
            return memo[i]
        else:
            memo[i] = min( recurse(i-1) + abs(h[i] - h[i-1]), recurse(i-2) + abs(h[i] - h[i-2]))
            return memo[i]
    return recurse(n-1)

    

print(recursive_method(N))

Measured memory_bytes: 125840
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef string str;
typedef vector<ll> vel;
typedef vector<str> ves;
#define REP(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
#define rep(i, b) REP(i, 0, b)
const ll mod = 1000000007;
const double pi = 3.14159265358979;

int main() {
    ll n;
    cin >> n;ll cnt = 0, cnt1 = 0, cnt2 = 0, cnt3 = 0;
    ves s(n);
    rep(i, n) {
        cin >> s[i];
        rep(j, s[i].size() - 1) {
            if(s[i][j] == 'A' && s[i][j+1] == 'B') {
                cnt++;
            }
        }
    }
    rep(i, n){
        if(s[i][0] == 'B' && s[i][s[i].size()-1] == 'A') {
            cnt1++;
        }
        if(s[i][0] == 'B' && s[i][s[i].size()-1] != 'A') {
            cnt2++;
        }
        if(s[i][0] != 'B' && s[i][s[i].size()-1] == 'A') {
            cnt3++;
        }
    }
    if(cnt1 == 0){
        cout << cnt + min(cnt2, cnt3) << endl;
    }
    else {
        if(cnt2 + cnt3 != 0){
            cout << cnt + cnt1 + min(cnt2, cnt3) << endl;
        }
        else {
            cout << cnt + cnt1 - 1 << endl;
        }
    }
}

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

#define endl '\n'
#define ends ' '
#define die(x) return cout << x << endl, 0
#define all(v) v.begin(), v.end()
#define sz(x) (int)(x.size())
#define debug(x) cerr << #x << ": " << x << endl
#define debugP(p) cerr << #p << ": {" << p.first << ", " << p.second << '}' << endl
typedef long long ll;
typedef pair<ll, ll> pii;
const ll INF = 2e15;
const ll MOD = 1e9 + 7;

////////////////////////////////////////////////////////////////////

const int N = 2e5 + 5;

ll DS[N], DT[N];
ll DPS[N], DPT[N];
vector<pii> G[N];

void Dijkstra(ll s, ll dis[N], ll dp[N]) {
	for (int i = 1; i < N; i++)
		dis[i] = INF;
	dis[s] = 0;
	dp[s] = 1;
	set< pair<ll, ll> > pq; pq.insert(make_pair(0, s));
	while (!pq.empty()) {
		int v = pq.begin() -> second; pq.erase(pq.begin());
		for (pii e : G[v]) {
			ll u = e.first, w = e.second;
			if (dis[v] + w < dis[u]) {
				pq.erase(make_pair(dis[u], u));
				dis[u] = dis[v] + w;
				dp[u] = 0;
				pq.insert(make_pair(dis[u], u));
			}
			if (dis[v] + w == dis[u]) dp[u] = (dp[u] + dp[v]) % MOD;
		}
	}
}
ll sq(ll x) { return (1LL * x * x) % MOD; }

int main() {

	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	
	int n, m, s, t; cin >> n >> m >> s >> t;
	for (int i = 0; i < m; i++)  {
		int v, u, w; cin >> v >> u >> w;
		G[v].push_back(make_pair(u, w));
		G[u].push_back(make_pair(v, w));
	}
	Dijkstra(s, DS, DPS);
	Dijkstra(t, DT, DPT);
	if (!DPS[t])
		return cout << 0 << endl, 0;
	ll ans = (1LL * DPS[t] * DPT[s]) % MOD;
	ll d = DS[t];
	for (int v = 1; v <= n; v++) 
		if (DS[v] + DT[v] == d && DS[v] == DT[v]) 
			ans = (ans - sq((1LL * DPS[v] * DPT[v]) % MOD) + MOD) % MOD;
	for (int v = 1; v <= n; v++) 
		for (pii e : G[v]) {
			ll u = e.first, w = e.second;
			if (DS[v] + w + DT[u] == d && abs(DS[v] - DT[u]) < w)
				ans = (ans - sq((1LL * DPS[v] * DPT[u]) % MOD) + MOD) % MOD;
		}
	ans += MOD;
	ans %= MOD;
	cout << ans << endl;

	return 0;
}



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

int main() {
  int N, K;
  cin >> N >> K;

  bool dis[10] = {};
  for (int i = 0; i < K; ++i) {
    int D;
    cin >> D;
    dis[D] = true;
  }

  int ans = N;
  while (true) {
    bool f = false;
    int s = ans;
    while (s) {
      f |= dis[s % 10];
      s /= 10;
    }

    if (!f) break;
    ans++;
  }

  cout << ans << endl;
}


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

enum class DominoDir {
    YOKO,
    TATE,
};

void main_()
{
    ll N;
    cin >> N;
    string S1, S2;
    cin >> S1 >> S2;

    if (N == 1) {
        cout << 3 << endl;
        return;
    }

    DominoDir dd = (S1[0] == S1[1]) ? DominoDir::YOKO : DominoDir::TATE;
    ll ans = (dd == DominoDir::YOKO) ? 6 : 3;

    for (ll i = (dd == DominoDir::YOKO) ? 2 : 1; i < N; i += (dd == DominoDir::YOKO) ? 2 : 1) {
        if (i < N - 1 && S1[i] == S1[i + 1]) { // 横
            ans *= (dd == DominoDir::YOKO) ? 3 : 2;
            dd = DominoDir::YOKO;
        } else { //縦
            ans *= (dd == DominoDir::YOKO) ? 1 : 2;
            dd = DominoDir::TATE;
        }
        ans %= (ll)1e9 + 7;
    }
    cout << ans << endl;
}
int main()
{
    cin.tie(nullptr);
    cout.tie(nullptr);
    ios_base::sync_with_stdio(false);
    main_();
    return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <functional>
#include <utility>
#include <tuple>
#include <cctype>
#include <bitset>
#include <complex>
#include <cmath>
#include <array>
#include <numeric>
using namespace std;
#define INF 0x3f3f3f3f
#define INFLL 0x3f3f3f3f3f3f3f3fLL
#define MOD 998244353
//#define MOD 1000000007
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pint;
typedef pair<ll,ll> pll;
typedef tuple<int,int,int> tint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<ull> vull;
typedef vector<pint> vpint;
int dx[8]={0,0,-1,1,1,1,-1,-1};
int dy[8]={-1,1,0,0,1,-1,1,-1};
const int SIZE=100050;
//↑templete
#define rep(i,a,n) for(int i=a; i<n; i++)
#define repq(i,a,n) for(int i=a; i<=n; i++)
ll fact_mod(ll n, ll mod) {
    ll f = 1; repq(i,2,n) f = f * (i % MOD) % MOD;
    return f;
}
// 繰り返し二乗法 (再帰バージョン)
ll mod_pow(ll x, ll n, ll mod) {
    if(n == 0) return 1;
    ll res = mod_pow((x * x) % mod, n / 2 , mod);
    if(n & 1) res = (res * x) % mod;
    return res;
}
int main(){
	int N;
	cin>>N;
	vint A;
	ll dist[SIZE]={};
	int maxi=0;
	ll ans=1;
	for(int i=0;i<N;i++){
		int a;
		cin>>a;
		A.pb(a);
		dist[a]++;
		maxi=max(maxi, a);
		if(a==0 && i!=0){
			cout<<0<<endl;
			return 0;
		}
	}
	if(A[0]!=0){
		cout<<0<<endl;
		return 0;
	}
	for(int i=1;i<=maxi;i++){
		ans*=mod_pow(dist[i-1], dist[i], MOD);
		ans%=MOD;
	}
	cout<<ans<<endl;
	return 0;
}

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

int main(void){
    int n;
    cin >> n;
    if(n >= 195)cout << 5 << endl;
    else if(n >= 189)cout << 4 << endl;
    else if(n >= 165)cout << 3 << endl;
    else if(n >= 135)cout << 2 << endl;
    else if(n >= 105)cout << 1 << endl;
    else cout << 0 << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <random>
#include <chrono>
#include <queue>
#include <ctime>
#include <cassert>
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
#define fs first
#define sc second
#define INF 1000000000
#define MOD 1000000007
#define EPS 0.00000001


int main(){
    int A, B; cin >> A >> B;
    int ret = 0;
    for(int i=A; i<=B; i++){
        string S = to_string(i);
        reverse(S.begin(), S.end());
        if(S==to_string(i)) ret++;
    }
    cout << ret << endl;
    return 0;
}





Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split()))
l={}
r={}
for i in range(n):
    x=i+1+a[i]
    if x in l:
        l[x]+=1
    else:
        l[x]=1

    y=i+1-a[i]
    if y in r:
        r[y]+=1
    else:
        r[y]=1

ans=0
for i in l:
    if i in r:
        ans+=l[i]*r[i]
print(ans)

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

long long modpow(long long a, long long b, long long m) {
	long long p = 1, q = a;
	for (int i = 0; i < 32; i++) {
		if ((b / (1LL << i)) % 2 == 1) { p *= q; p %= m; }
		q *= q; q %= m;
	}
	return p;
}
long long Div(long long a, long long b, long long m) {
	return (a*modpow(b, m - 2, m)) % m;
}

string S; long long N, A[100009], power[100009], inv[100009], E[100009], mod = 2147483647; vector<int>vec;

long long getans(long long L, long long R) {
	if (L < 0) return -1000000007;
	return (E[R] - E[L] + mod) * inv[L] % mod;
}

long long check(long long L, long long R) {
	if (L < 0) return (1LL << 30);
	return min(abs(R - L), mod - abs(R - L));
}

bool solve(int pos) {
	if (pos == -1) return false;
	// Step 1: 最小値を決めて探索する, 右から左へ読む
	for (int i = 1; i <= 18; i++) {
		int cx = S.size() - 1; bool flag = true;
		while (cx >= 0) {
			long long V = 0;
			if (A[cx] >= i) { V = A[cx]; cx--; }
			else {
				if (cx == 0) V = -1;
				else V = A[cx] * 10LL + A[cx - 1];
				cx -= 2;
			}
			if (V < i || V > i + pos || cx == -2) { flag = false; break; }
		}
		if (flag == true) {
			return true;
		}
	}

	// Step 2: 桁数を決めて探索する
	for (int i = 2; i < S.size(); i++) {
		vector<long long>G;
		long long vase = getans((int)S.size() - i, (int)S.size()); G.push_back(vase);
		int cx = S.size() - i; bool flag = true;
		while (cx > 0) {
			long long t1 = getans(cx - (i - 1), cx);
			long long t2 = getans(cx - (i + 0), cx);
			long long t3 = getans(cx - (i + 1), cx);
			if (check(t1, vase) <= pos) { cx -= (i - 1); G.push_back(t1); }
			else if (check(t2, vase) <= pos) { cx -= (i + 0); G.push_back(t2); }
			else if (check(t3, vase) <= pos) { cx -= (i + 1); G.push_back(t3); }
			else { flag = false; break; }
		}
		if (flag == true) {
			sort(G.begin(), G.end()); G.erase(unique(G.begin(), G.end()), G.end());
			for (int j = 0; j < G.size(); j++) {
				for (int k = j + 1; k < G.size(); k++) {
					if (check(G[j], G[k]) > pos) flag = false;
				}
			}
			if (flag == true) {
				return true;
			}
		}
	}
	return false;
}

int main() {
	cin >> S; reverse(S.begin(), S.end()); for (int i = 0; i < S.size(); i++) A[i] = (S[i] - '0');

	if (S.size() == 2) {
		cout << abs(S[0] - S[1]) << endl;
		return 0;
	}

	long long maxn = 0, minx = 10;
	for (int i = 0; i < S.size(); i++) {
		maxn = max(maxn, A[i]);
		minx = min(minx, A[i]);
	}
	power[0] = 1; for (int i = 1; i <= 100000; i++) power[i] = (power[i - 1] * 10LL) % mod;
	inv[0] = 1; inv[1] = Div(1LL, 10LL, mod); for (int i = 2; i <= 100000; i++) inv[i] = (inv[i - 1] * inv[1]) % mod;
	for (int i = 0; i < S.size(); i++) E[i + 1] = (E[i] + power[i] * (long long)(S[i] - '0')) % mod;
	
	for (int i = (maxn - minx - 1); i >= -1; i--) {
		bool I = solve(i);
		if (I == false) { cout << i + 1 << endl; break; }
	}
	return 0;
}


Measured memory_bytes: 6460
#include <bits/stdc++.h>
#define rep(I,n) for (int I = 0; I < (n); ++I)
#define FOR(I,k,n) for(int I=(k);I<(n);++I)
using namespace std;
typedef long long ll;
 
int main() {
    
    string s;
    cin >> s;
    
    if(s=="MON"){
        cout << 6 << endl;
    }
    
    if(s=="TUE"){
        cout << 5 << endl;
    }
    
    if(s=="WED"){
        cout << 4 << endl;
    }
    
    if(s=="THU"){
        cout << 3 << endl;
    }
    
    if(s=="FRI"){
        cout << 2 << endl;
    }
    
    if(s=="SAT"){
        cout << 1 << endl;
    }
    
    if(s=="SUN"){
        cout << 7 << endl;
    }
    
  
  
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int N,A,B,s;
    scanf("%d",&N);
    if(N==1)
    {
        printf("Hello World\n");
    }
    else if(N==2)
    {
        scanf("%d%d",&A,&B);
        s=A+B;
        printf("%d\n",s);
    }
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
//登録しよう！→ https://www.youtube.com/channel/UCRXsI3FL_kvaVL9zoolBfbQ
using namespace std;
using ll = long long;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}//a,bの最大公約数(gcd)を求める
ll lcm(ll a,ll b){return abs(a*b)/gcd(a,b);}//a,bの最小公倍数(lcm)を求める
vector<ll> enum_div(ll n){vector<ll> ret;for(int i=1 ; i*i<=n ; i++){if(n%i == 0){ret.push_back(i);if(i!=1 && i*i!=n)ret.push_back(n/i);}}ret.push_back(n);return ret;}
//↑nの約数を求める
vector<bool> IsPrime; void sieve(size_t max){if(max+1 > IsPrime.size())IsPrime.resize(max+1,true);IsPrime[0] = false;IsPrime[1] = false;for(size_t i=2; i*i<=max; ++i)if(IsPrime[i])for(size_t j=2; i*j<=max; ++j)IsPrime[i*j] = false;}
//↑エラトステネスの篩で素数を求める
#define roundup(divisor,dividend) (divisor + (dividend - 1)) / dividend //切り上げ割り算
#define all(x) (x).begin(),(x).end() //xの初めから終わりまでのポインタ
#define size_t ll //size_tは自動でllに変換される
#define pb(x) push_back(x)
#define gre greater //sortを降順にする
#define pri_queue priority_queue //優先度付きキュー
#define syo(x) fixed << setprecision(x) //iostreamで小数をx桁表示
const int mod = 1000000007;
ll n,k,ans=0;
int main(){ //srand((unsigned)time(NULL));
  cin >> n >> k;
  while(n/k >= 1){
    n /= k;
    ans++;
  }
  cout << ans+1 << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n-1);i>=0;i--)
#define FOR(i,n,m) for(int i=n;i<=(int)(m);i++)
#define RFOR(i,n,m) for(int i=(int)(n);i>=m;i--)
#define all(x) (x).begin(),(x).end()
#define sz(x) int(x.size())
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
const double PI=3.14159265358979323846;
using namespace std;
vector<int> dy={1,0,-1,0};
vector<int> dx={0,1,0,-1};
template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

double dist(pair<double,double> a, pair<double,double> b) {
    double ax,ay,bx,by;
    tie(ax,ay)=a;
    tie(bx,by)=b;
    return sqrt((ax-bx)*(ax-bx)+(ay-by)*(ay-by));
}


int main() {
    int n;
    cin>>n;
    vector<pair<double,double>> xy(n);
    rep(i,n) {
        double x,y;
        cin>>x>>y;
        xy[i]={x,y};
    }
    
    sort(all(xy), [](const auto &p1, const auto &p2) {
        return atan2l(p1.second, p1.first) < atan2l(p2.second, p2.first);
    });
    
    rep(i,n) xy.push_back(xy[i]);
    
    double ans=0;
    rep(left,n) {
        FOR(k,1,n) {//使う数
            double x=0,y=0;
            rep(i,k) {
                x+=xy[left+i].first;
                y+=xy[left+i].second;
            }
            ans=max(ans,dist({0,0},{x,y}));
        }
    }
    
    cout<<fixed<<setprecision(12)<<ans<<endl;
    
}


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

using namespace std;
int main(){
  int n;
  cin>>n;
  vector<int>h(n);
  int ans=0;

  for (int i=0;i<n;++i){
      cin>>h[i];
      ans+=h[i]; 
  }

  int mini=ans;
  int prefix_sum=0;
  for(int i=0;i<n;++i){
      cin>>h[i];
      prefix_sum+=h[i];
      mini=min(mini,abs(prefix_sum-(ans-prefix_sum)));
  }
  cout<<mini<<endl;
  return 0;
}

Measured memory_bytes: 256
N, K = list(map(int, input().split()))
S = list(input())

L = [1]

for i in range(1, N):
	if S[i] == S[i - 1]:
		L[-1] += 1
	else:
		L.append(1)

n = len(L)
if S[0] == "1":
	if n // 2 <= K:
		print(N)
	else:
		if S[-1] == "1":
			x = L[0]
			for i in range(K):
				x += L[2 * i + 1] + L[2 * i + 2]
			val = x
			for i in range(int(n // 2) - K):
				val += L[2 * (i + K) + 1] + L[2 * (i + K) + 2] - L[2 * i] - L[2 * i + 1]
				if val > x:
					x = val
			print(x)
		else:
			x = L[0]
			for i in range(K):
				x += L[2 * i + 1] + L[2 * i + 2]
			val = x
			for i in range(int(n // 2) - K - 1):
				val += L[2 * (i + K) + 1] + L[2 * (i + K) + 2] - L[2 * i] - L[2 * i + 1]
				if val > x:
					x = val
			val += L[-1] - L[-2 * K - 1] - L[-2 * K - 2]
			if val > x:
				x = val
			print(x)			

else:
	if (n + 1) // 2 <= K:
		print(N)
	elif (n - 1) // 2 == K and S[0] == "0" and S[-1] == "0":
		print(max(N - L[0], N - L[-1]))
	else:
		if S[-1] == "1":
			LL = [L[-1 - i] for i in range(n)]
			x = LL[0]
			for i in range(K):
				x += LL[2 * i + 1] + LL[2 * i + 2]
			val = x
			for i in range(int(n // 2) - K - 1):
				val += LL[2 * (i + K) + 1] + LL[2 * (i + K) + 2] - LL[2 * i] - LL[2 * i + 1]
				if val > x:
					x = val
			val += L[0] - LL[-2 * K + 1] - LL[-2 * K]
			if val > x:
				x = val
			print(x)
		else:
			LL = L[1:]
			x = LL[0]
			for i in range(K):
				x += LL[2 * i + 1] + LL[2 * i + 2]
			val = x
			for i in range(int((n - 1) // 2) - K - 1):
				val += LL[2 * (i + K) + 1] + LL[2 * (i + K) + 2] - LL[2 * i] - LL[2 * i + 1]
				if val > x:
					x = val
			val += L[-1] - LL[-2 * K + 1] - LL[-2 * K]
			if val > x:
				x = val

			LL = [L[-2 - i] for i in range(n - 1)]
			y = LL[0]
			for i in range(K):
				y += LL[2 * i + 1] + LL[2 * i + 2]
			val = y
			for i in range(int((n - 1) // 2) - K - 1):
				val += LL[2 * (i + K) + 1] + LL[2 * (i + K) + 2] - LL[2 * i] - LL[2 * i + 1]
				if val > y:
					y = val
			val += L[0] - LL[-2 * K + 1] - LL[-2 * K]
			if val > y:
				y = val
			print(max(x, y))

Measured memory_bytes: 6316
#include <stdio.h>

void merge(int left,int mid,int right);
int mergesort(int left,int right);

#define NUM 500000

int n1,n2;
int S[NUM],L[NUM],R[NUM];

int Q = 0;

int main()
{
  int n,i,k;
  
  scanf("%d",&n);
  for(i = 0;i < n;i++){
    scanf("%d",&S[i]);
  }
  S[i] = 0;
  
  k = mergesort(0,n);
  printf("%d",S[0]);
  for(i = 1;i < n;i++){
    printf(" %d",S[i]);
  }
  printf("\n");
  printf("%d\n",Q);

  return 0;

}

void merge(int left,int mid,int right)
{
  int i,j,k;
  
  
  n1 = mid - left;
  n2 = right - mid;

  

  for(i = 0;i < n1 ;i++) {
    L[i] = S[left + i];
    
  }
  for(i = 0;i < n2 ;i++) {
    R[i] = S[mid + i];
  }
  L[n1] = 1000000000;
  R[n2] = 1000000000;

  i = 0;
  j = 0;

  for(k = left;k < right;k++){
    if(L[i] <= R[j]){
      S[k] = L[i];
      i++;
      Q++;
    }
    else {
      S[k] = R[j];
      j++;
      Q++;
    }
  }
}

int mergesort(int left,int right)
{
  int mid;
  if(left+1 < right){
    mid = (left+right)/2;
    mergesort(left,mid);
    mergesort(mid,right);
    merge(left,mid,right);
  }
}



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

using namespace std;

int main()
{
	long long H, A, buf=0, ans = 0;

	cin >> H >> A;

	while (buf < H)
	{
		buf += A;
		ans++;
	}

	cout << ans << endl;
}

Measured memory_bytes: 256
from math import ceil
N, K = list(map(int, input().split()))

A = list(map(int, input().split()))

def possible(A, K, target):
    count = 0

    for a in A:
        count += ceil(a / target) - 1
    return count <= K

left = 1
right = max(A)

while left < right:
    mid = (left + right) // 2
    if possible(A, K, mid):
        right = mid
    else:
        left = mid + 1

print(right)


Measured memory_bytes: 104644
import java.util.*;

/**
 * Base_version
 */ 

class Main { 
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
      	int x = sc.nextInt();
      	int t = sc.nextInt();
        System.out.println(Math.max(x - t, 0));
    }
}

Measured memory_bytes: 21716
#include<iostream>
#include<string>
#include<algorithm>
#include<queue>
#include<vector>
#include<cstdlib>
#include<set>

using namespace std;

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

#include<iostream>

int main(){
    int const INF = 100000000;
    int n;
    cin >> n;
    int dp[3][n+1];
    rep(i, 3)rep(j, n + 1) dp[i][j] = INF;
    rep(i, n + 1) dp[0][i] = i;
    rep(i, 3) dp[i][0] = 0;
    rep(j, n){
        dp[1][j+1] = dp[0][j+1];
        for (int i = 6; i <= n; i *= 6){
            if (j + 1 >= i){
                dp[1][j+1] = min(dp[1][j+1], min(dp[0][j+1], dp[1][j-i+1] + 1));
            }else{
                dp[1][j+1] = min(dp[0][j+1], dp[1][j+1]);
            }
        }
    }
    rep(j, n){
        dp[2][j+1] = dp[1][j+1];
        for (int i = 9; i <= n; i *= 9){
            if (j + 1 >= i){
                dp[2][j+1] = min(dp[2][j+1],min(dp[1][j+1], dp[2][j-i+1] + 1));
            }else{
                dp[2][j+1] = min(dp[1][j+1], dp[2][j+1]);
            }
        }
    }
    // rep(i, 3){
    //     rep(j, n + 1){
    //         cout << dp[i][j] << " ";
    //     }
    //     cout << endl;
    // }
    cout << dp[2][n] << endl;
}

Measured memory_bytes: 1408
from sys import exit
from collections import defaultdict as dd
n = int(input())
A = list(map(int, input().split()))

dic = dd(int)
for i, a in enumerate(A):
    dic[i+1] = a

baisu = dd(set)
for num in range(1, n+1):
    for i in range(1, n+1):
        if num * i > n:
            break
        baisu[num * i].add(num)
#print(baisu)

box = dd(int)

#dic -> baisu -> box
for num in range(n, 0, -1):
    kosu = dic[num]
    for yakusu in list(baisu[num]):
        dic[yakusu] += kosu
        dic[yakusu] %= 2
        box[num] += kosu

ans = []
for i in range(1, n+1):
    if box[i] >= 1:
        ans.append(i)
print(sum([i > 0 for i in ans]))
print(*ans, sep=" ")

Measured memory_bytes: 258860
a = input()
dif = 0

for i in range(len(a) - 1) :
  for j in range(len(a)) :
    if i + j + 1 == len(a) :
      break
    if (a[i] == a[i + j + 1]) :
      dif = 1
  
if dif :
  print ('no')
else :
  print ('yes')

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define ADD(a, b) a = (a + ll(b)) % mod
#define MUL(a, b) a = (a * ll(b)) % mod
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)
#define all(a) (a).begin(), (a).end()
#define sz(v) (int)(v).size()
#define pb push_back
#define sec second
#define fst first
#define debug(fmt, ...) Debug(__LINE__, ":", fmt, ##__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<int, pi> ppi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> mat;
typedef complex<double> comp;
void Debug() {cerr << '\n'; }
template<class FIRST, class... REST>void Debug(FIRST arg, REST... rest){
	cerr<<arg<<" ";Debug(rest...);}
template<class T>ostream& operator<<(ostream& out,const vector<T>& v) {
	out<<"[";if(!v.empty()){rep(i,0,sz(v)-1)out<<v[i]<<", ";out<<v.back();}out<<"]";return out;}
template<class S, class T>ostream& operator<<(ostream& out,const pair<S, T>& v){
	out<<"("<<v.first<<", "<<v.second<<")";return out;}
const int MAX_N = 500010;
const int MAX_V = 100010;
const double eps = 1e-6;
const ll mod = 1000000007;
const int inf = 1 << 30;
const ll linf = 1LL << 60;
const double PI = 3.14159265358979323846;
mt19937 rng; //use it by rng() % mod, shuffle(all(vec), rng)
///////////////////////////////////////////////////////////////////////////////////////////////////

int L, R;

void solve() {
	cin >> L >> R;
	if(R - L + 1 >= 2019) cout << 0 << "\n";
	else {
		L %= 2019;
		R %= 2019;
		if(R < L) R += 2019;
		int res = 2019;
		for(int i = L; i <= R; i++) {
			for(int j = i + 1; j <= R; j++) {
				MIN(res, i * j % 2019);
			}
		}
		cout << res << "\n";
	}
}

uint32_t rd() {
	uint32_t res;
#ifdef __MINGW32__
	asm volatile("rdrand %0" :"=a"(res) ::"cc");
#else
	res = std::random_device()();
#endif
	return res;
}

int main() {
#ifndef LOCAL
	ios::sync_with_stdio(false);
    cin.tie(0);
#endif
    cout << fixed;
	cout.precision(20);
    cerr << fixed;
	cerr.precision(6);
	rng.seed(rd());
#ifdef LOCAL
	//freopen("in.txt", "wt", stdout); //for tester
    freopen("in.txt", "rt", stdin);
#endif	
	solve();
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
	return 0;
}



Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int h, w, n;
  cin >> h >> w >> n;
  int x= max(h,w);
  int ans;
  if(n%x==0)
  {
    ans=n/x;
  }
  else
  {
    ans=1+(n/x);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
import java.util.InputMismatchException;
class Main{
public static void main(String args[]){

    Scanner scan = new Scanner(System.in);
    try{
int a = scan.nextInt();
int b = scan.nextInt();
int c = scan.nextInt();

if(a<b && b<c){

System.out.println("Yes");
}


else{

System.out.println("No");
}










}catch (InputMismatchException e) {
        	System.out.println("try again!!");
        }





}
}



Measured memory_bytes: 26224
//Name: SIRO Challenge
//Level: 3
//Category: グラフ,Graph,縮約,巡回セールスマン問題,TSP,練習問題
//Note:

/**
 * 問題となるのはいくつの店を回ったかであるから、あるパターンで店が訪問済みになる最短時間を覚えておけば良い。
 * これは巡回セールスマン問題のようにすればできる。
 * ただし、与えられたグラフに対してそのまま訪問済みの店集合を持たせるように拡張すると、頂点数が多くなりすぎるため、先に縮約しておく。
 * 縮約は、全点対最短距離を求めておき、スタートと店だけからなるグラフに再構成すればよい（Dijkstra法などを使えばもっと速くなる）。
 *
 * グラフが連結とは限らないことに注意。
 *
 * オーダーは O(N^3 + L^2 2^L)。
 */

#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <algorithm>
#include <unordered_map>

using namespace std;

bool solve() {
    int N, M, L, S, T;
    if(!(cin >> N >> M >> L >> S >> T)) return false;
    if(!N && !M && !L && !S && !T) return false;
    --S;

    vector<vector<int>> org_g(N, vector<int>(N, -1));
    for(int i = 0; i < M; ++i) {
        int a, b, c;
        cin >> a >> b >> c;
        --a; --b;
        org_g[a][b] = org_g[b][a] = c;
    }
    for(int i = 0; i < N; ++i) {
        org_g[i][i] = 0;
    }
    for(int k = 0; k < N; ++k) {
        for(int i = 0; i < N; ++i) {
            for(int j = 0; j < N; ++j) {
                if(org_g[i][k] == -1 || org_g[k][j] == -1) continue;
                const int nl = org_g[i][k] + org_g[k][j];
                if(org_g[i][j] == -1 || org_g[i][j] > nl) {
                    org_g[i][j] = nl;
                }
            }
        }
    }

    // グラフを再構築する。
    unordered_map<int,int> dict;
    dict[0] = S;
    vector<vector<int>> graph(L+1, vector<int>(L+1, -1));
    vector<int> es(L+1, 0);
    for(int i = 1; i <= L; ++i) {
        int j;
        cin >> j >> es[i];
        --j;
        for(const auto &p : dict) {
            graph[p.first][i] = graph[i][p.first] = org_g[p.second][j];
        }
        dict[i] = j;
    }
    for(int i = 0; i <= L; ++i) {
        graph[i][i] = 0;
    }

    // TSP
    vector<vector<int>> dp(1<<(L+1), vector<int>(L+1, -1));
    dp[0][0] = 0;
    for(int pat = 0; pat < (1<<(L+1)); ++pat) {
        for(int i = 0; i <= L; ++i) {
            if(dp[pat][i] == -1) continue;
            for(int j = 0; j <= L; ++j) {
                if(graph[i][j] == -1) continue;
                const int nt = dp[pat][i] + graph[i][j] + es[j];
                const int np = pat | (1<<j);
                if(nt <= T && (dp[np][j] == -1 || dp[np][j] > nt)) {
                    dp[np][j] = nt;
                }
            }
        }
    }

    int ans = 0;
    for(int pat = 0; pat < (1<<(L+1)); ++pat) {
        if(dp[pat][0] != -1) {
            ans = max(ans, __builtin_popcount(pat & ~1));
        }
    }
    cout << ans << endl;
    return true;
}

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

    while(solve()) ;
    return 0;
}

Measured memory_bytes: 14860
#include <stdio.h>
#include <stdlib.h>

int main()
{
    int a,b,c,x;
    int ways = 0;
    scanf("%d%d%d%d",&a,&b,&c,&x);
    for(int i = a;i >= 0; i--){

        for(int j = b; j >= 0; j--){
            for(int k = c; k >= 0; k--){
                if((500 * i + 100 * j + 50 * k) == x){
                    ways++;
                }
            }
        }
    }
    printf("%d\n",ways);
    return 0;
}


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

int N, M;

int main() {
    cin >> N >> M;
  
    vector<long long int> a[3];
  
    for (int i = 0; i < N; ++i) {
        for (int j = 0; j < 3; ++j) {
            long long num; cin >> num;
            a[j].push_back(num);
        }
    }
  
  //bit処理
  
  
   long long int ant = 0;
  
    for (int k = 0; k < (1<<3); k++) {
        vector<long long> b;
      
        for (int i = 0; i < N; i++) {
          
            long long int  tmp = 0;
            for (int j = 0; j < 3; j++) {
              
                if (k & (1<<j)) tmp += a[j][i];
                else tmp -= a[j][i];
            }
            b.push_back(tmp);
        }
        sort(b.begin(), b.end(), greater<long long>());
        long long sum = 0;
        for (int i = 0; i < M; ++i) {
            sum += b[i];
        }
      
        ant = max(ant , sum);
    }
    cout << ant << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <sstream>
#include <iomanip>
#include <set>
using namespace std;
typedef long long int ll;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define yes cout << "yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
#define no cout << "no" << endl

const int INF = 1001001001;
const int mod = 1000000007;
#define PI 3.14159265359;

void P(int x) {cout << x << endl;}
void P(long x) {cout << x << endl;}
void P(double x) {cout << x << endl;}
void P(ll x) {cout << x << endl;}
void P(string x) {cout << x << endl;}
void P(char x) {cout << x << endl;}

ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

int main() {
  int n, x;
  cin >> n >> x;
  int ans = 1;
  int now = 0;
  rep (i, n) {
    int tmp;
    cin >> tmp;
    now += tmp;
    if (x >= now) ans++;
  }
  P(ans);
  return 0;

}

Measured memory_bytes: 256
#include"iomanip"
#include"iostream"
#include"limits"
#include"cmath"
#include"vector"
#include"algorithm"
#include"list"
#include"queue"
#include"stack"
#include"set"
#include"unordered_set"
#include"map"
#include"unordered_map"
#include"string"
#include"cstring"
#include"assert.h"
using namespace std;
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define mp make_pair
#define pb push_back
#define mset(a,b) memset(a,b,sizeof(a))
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int maxn=1e5+5;
int r[maxn][31];
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,c;
    cin>>n>>c;
    for(int i=0;i<n;++i)
    {
        int s,t,c1;
        cin>>s>>t>>c1;
        c1--;
        r[s][c1]++;
        r[t+1][c1]--;
    }
    for(int i=1;i<maxn;++i)
    {
        for(int c1=0;c1<30;++c1)
        {
            r[i][c1]+=r[i-1][c1];
        }
    }
    int ans=0;
    for(int i=1;i<=1e5;++i)
    {
        int tot=0;
        for(int c1=0;c1<30;++c1)
        {
            if(r[i][c1]>0)
            {
                tot++;
            }
        }
        ans=max(ans,tot);
    }
    cout<<ans<<'\n';
}
















Measured memory_bytes: 12416
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		char[] arr = sc.next().toCharArray();
		int num = 0;
		boolean plus = true;
		boolean si = false;
		boolean xs = false;
		long[] keis = new long[6];
		for (char c : arr) {
		    if (c == '+') {
		        if (xs) {
		            if (plus) {
		                keis[1] = num;
		            } else {
		                keis[1] = -num;
		            }
		        }
		        num = 0;
		        plus = true;
		    } else if (c == '-') {
		        if (xs) {
		            if (plus) {
		                keis[1] = num;
		            } else {
		                keis[1] = -num;
		            }
		        }
		        num = 0;
		        plus = false;
		    } else if (c == '^') {
		        si = true;
		        xs = false;
		    } else if (c == 'x') {
		        if (num == 0) {
		            num = 1;
		        }
		        xs = true;
		    } else {
		        if (si) {
		            int v = c - '0';
		            if (plus) {
		                keis[v] = num;
		            } else {
		                keis[v] = -num;
		            }
		            si = false;
		        } else {
		            num = num * 10 + c - '0';
		        }
		    }
		}
		if (plus) {
		    keis[0] = num;
		} else {
		    keis[0] = -num;
		}
		int ji = 0;
		for (int i = 5; i >= 0; i--) {
		    if (keis[i] != 0) {
		        ji = i;
		        break;
		    }
		}
		int[] ans = new int[ji];
		for (int i = 1; i <= Math.abs(keis[0]) && ji > 0; i++) {
		    long result = 0;
		    for (int j = 0; j <= 5; j++) {
		        result += (long)Math.pow(i, j) * keis[j];
		    }
		    if (result == 0) {
		        ji--;
		        ans[ji] = -i;
		    }
		    result = 0;
		    for (int j = 0; j <= 5; j++) {
		        result += (long)Math.pow(-i, j) * keis[j];
		    }
		    if (result == 0) {
		        ji--;
		        ans[ji] = i;
		    }
		}
		Arrays.sort(ans);
		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < ans.length; i++) {
		    sb.append("(x");
		    if (ans[i] >= 0) {
		        sb.append("+");
		    }
		    sb.append(ans[i]).append(")");
		}
		System.out.println(sb);
	}
}



Measured memory_bytes: 26312
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define ios ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
int main() {
	ios;
	ll n,m,i;
	cin>>n>>m;
	vector<ll> a(n);
	int c,d=-1,f=0; ll x;
	for( i=0;i<n;i++){
		cin>>a[i];
		x=a[i];
		c=0;
		while((!f) && x%2==0) {
			c++; x/=2;
		}
		if(d==-1) d=c;
		else if(c!=d) f=1;
	}
	if(f) cout<<0<<"\n";
	else
	{
		ll lcm=1;
		for(i=0;i<n;i++)
		{
			a[i]/=2;
			lcm=a[i]/(__gcd(lcm,a[i]))*lcm;
		}
		if(m<lcm) cout<<0<<"\n";
		else
		{
		// m=(m+lcm-1)/lcm;
		// cout<<(m+1)/2;
		cout<<(m/lcm+1)/2;
		}
	}
	
	
	return 0;
}

Measured memory_bytes: 1024
module app;

import core.bitop;

import std.algorithm;
import std.array;
import std.bigint;
import std.container.rbtree;
import std.conv;
import std.stdio;
import std.string;
import std.traits;

struct Input
{
	int d, t, s;
}

void parseInput(T)(out Input input, T adapter)
{
	with (input)
	{
		adapter.readf!"%d "(d);
		adapter.readf!"%d "(t);
		adapter.readf!"%d"(s);
	}
}

struct Output
{
}

auto main2(Input* input)
{
	with (input)
	{
		return (d + s - 1) / s <= t ? "Yes" : "No";
	}
}

alias retType = ReturnType!main2;
static if (!is(retType == void))
{
	unittest { writeln("begin unittest"); }
	auto _placeholder_ = ReturnType!main2.init;

	unittest // example1
	{
		string example =
`1000 15 80`;
		if (example.empty) return;
		Input input = void;
		parseExample(input, example);
		auto result = main2(&input);
		printResult(result);
		assert(result == "Yes");
	}

	unittest // example2
	{
		string example =
`2000 20 100`;
		if (example.empty) return;
		Input input = void;
		parseExample(input, example);
		auto result = main2(&input);
		printResult(result);
		assert(result == "Yes");
	}

	unittest // example3
	{
		string example =
`10000 1 1`;
		if (example.empty) return;
		Input input = void;
		parseExample(input, example);
		auto result = main2(&input);
		printResult(result);
		assert(result == "No");
	}

	unittest { writeln("end unittest"); }

	void parseExample(out Input input, string example)
	{
		parseInput(input, new StringAdapter(example));
	}
}

class StdinAdapter
{
	// readf!"%s"は使えない
	// https://issues.dlang.org/show_bug.cgi?id=19820
	uint readf(alias format, A...)(auto ref A args) { return std.stdio.readf!format(args); }
	string readln() { return std.stdio.readln().strip(); }
}

class StringAdapter
{
	import std.format;
	string _s;
	this(string input) { _s = input; }
	uint readf(alias format, A...)(auto ref A args) { return _s.formattedRead!format(args); }
	string readln()
	{
		auto i = _s.countUntil("\n");
		if (i == -1) i = _s.length;
		string ret = _s[0..i];
		_s = _s[i..$];
		return ret;
	}
}

void printResult(T)(T result)
{
	static if (isFloatingPoint!T) writefln("%f", result);
	else writeln(result);
}

void main()
{
	Input input = void;
	parseInput(input, new StdinAdapter());
	static if (is(retType == void))
		main2(&input);
	else
	{
		auto result = main2(&input);
		printResult(result);
	}
}


Measured memory_bytes: 2812