akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;

namespace AtCoderSolve
{
    class Solve
    {
        const int mod = 1000000007;
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            var input = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int N = input[0];
            int M = input[1];

            Console.WriteLine(Math.Max(Math.Max(N + M, N * M), N - M));

            Console.Out.Flush();
        }
    }



    public class Calculation
    {
        
    }

    public class Graph
    {
        
    }
}

Measured memory_bytes: 13396
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<deque>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#include<functional>
#include<unordered_set>
#include<iomanip>
#include<cassert>
#include<regex>
#include<bitset>
#include<complex>
#include<chrono>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(),x.end()
using ll=long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;

ll gcd(ll n, ll m) {
	ll tmp;
	while (m!=0) {
		tmp = n % m;
		n = m;
		m = tmp;
	}
	return n;
}

ll lcm(ll n, ll m) {
	return abs(n * m) / gcd(n, m);//gl=xy
}
 
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
 
using namespace std;

//ここから


void solve(){
  vector<vector<int>>c(3,vector<int>(3));
  rep(i,3){
    rep(j,3)cin>>c[i][j];
  }
  bool ng=false;
  int sub[3];
  sub[0]=c[0][0]-c[0][1],sub[1]=c[0][1]-c[0][2],sub[2]=c[0][2]-c[0][0];
  rep(i,2){
    rep(j,3){
     if(sub[j]!=c[i+1][j]-c[i+1][(j+1)%3])ng=true; 
    }
  }
  sub[0]=c[0][0]-c[1][0],sub[1]=c[1][0]-c[2][0],sub[2]=c[2][0]-c[0][0];
  rep(i,2){
    rep(j,3){
      if(sub[j]!=c[j][i+1]-c[(j+1)%3][i+1])ng=true;
    }
  }
  if(ng)cout<<"No";
  else cout<<"Yes";
}

int main(){
	ios::sync_with_stdio(false);
  cin.tie(0);
	cout<<fixed<<setprecision(15);
  solve();
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define Rint register int
using namespace std;
typedef long long LL;
const int N = 203;
int n, dis[N], ans, q[N], front, rear;
bool s[N][N];
inline void bfs(int x){
	memset(dis, -1, sizeof dis);
	front = rear = dis[x] = 0; q[rear ++] = x;
	while(front < rear){
		int now = q[front ++];
		for(Rint i = 1;i <= n;i ++)
			if(s[now][i]){
				if(~dis[i]){
					if((dis[i] & 1) == (dis[now] & 1)){puts("-1"); exit(0);}
				} else {
					dis[i] = dis[now] + 1;
					q[rear ++] = i;
				}
			}
	}
}
int main(){
	scanf("%d", &n);
	for(Rint i = 1;i <= n;i ++)
		for(Rint j = 1;j <= n;j ++){
			int ch = getchar();
			while(ch != '0' && ch != '1') ch = getchar();
			s[i][j] = (ch == '1');
		}
	for(Rint i = 1;i <= n;i ++){
		bfs(i);
		for(Rint j = 1;j <= n;j ++) ans = max(ans, dis[j]);
	}
	printf("%d", ans + 1);
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int sum = 100000;

		for(int i = 0; i < n; i++){
			sum *= 1.05;
			if(sum % 1000 != 0){
				sum += 1000 - sum % 1000;
			}
		}
		System.out.println(sum);
	}
}

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


int t[100001];
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n,c,k;
	cin>>n>>c>>k;
	int ans=1,cur=0,from;
	for(int i=1;i<=n;i++){
		cin>>t[i];
	}
	sort(t+1,t+n+1);
	cur=1;
	from=t[1];
	for(int i=2;i<=n;i++){
		if(cur==c||t[i]-from>k){
			ans++;
			cur=1;
			from=t[i];
		}
		else{
			cur++;
		}
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define	endl		'\n'
#define pii         pair<ll, ll>
#define vi          vector<ll>
#define vvi			vector<vi>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll)x.size()
#define hell        1000000007
#define rep(i,a,b)	for(ll i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define tr(c,i)		for(typeof((c).begin() i = (c).begin(); i != (c).end(); i++)
#define present(c,x)	((c).find(x) != (c).end()) 
#define cpresent(c,x)	(find(all(c),x) != (c).end()) 
#define int ll
using namespace std;

#define N  100005

int n, m, q1;
vector<int> a;
int maxv;
int q[51][4];

void dfs(int n1, int prev)
{
	if(n1==n)
	{
		int score = 0;

		rep(i, 0, q1)
		{
			if(a[q[i][1]-1] - a[q[i][0]-1]==q[i][2])
				score+=q[i][3];
		}

		maxv = max(maxv, score);
		return;
	}

	rep(i, prev, m+1)
	{
		a.pb(i);
		dfs(n1+1, i);
		a.pop_back();
	}

	return;
}

int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	#endif
	int TESTS=1;
//	cin>>TESTS;
	while(TESTS--)
	{
		cin >> n >> m >> q1;

		rep(i, 0, q1)
		{
			rep(j, 0, 4)
			cin >> q[i][j];
		}

		maxv = 0;

		dfs(0, 1);

		cout << maxv;
	}
	return 0;
}

Measured memory_bytes: 3620
import { readFileSync } from 'fs'

const toTimeList = (books: number[]) =>
  books.reduce((acc, v, i) => (acc.push(acc[i] + v), acc), [0])

function main(input: string) {
  const [[N, M, K], deskA, deskB] = input.split('\n').map(v => v.split(' ').map(Number))

  const timeListA = toTimeList(deskA)
  const timeListB = toTimeList(deskB)

  let result = 0
  let b = M
  for (const [a, time] of timeListA.entries()) {
    if (time > K) break

    while (timeListB[b] + time > K) {
      --b
    }

    result = Math.max(result, a + b)
  }

  console.log(result)
}

main(readFileSync('/dev/stdin', 'utf8').trim())


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

int main(){
	
	/*
	for(int i=0; i<7; i++){
		int a,b;
		cin >> a >> b;
		cout << a - b <<endl;
		*/
	/*
	for(int i=0; i<4; i++){
		int T, K;
		cin >> T >> K;
		if(T == 1){
			cout << K*6000 << endl;
		}
		else if(T == 2){
			cout << K*4000 << endl;
		}
		else if(T == 3){
			cout << K*3000 << endl;
		}
		else{
			cout << K*2000 << endl;
		}

	}
	*/
	/*
	int n;
	cin >> n;
	for(int i=0; i<n; i++){
		int x, y, b, p;
		cin >> x >> y >> b >> p;

		if(b >= 5 && p >= 2){
			cout << (x*b + y*p)*4/5 << endl;
		}

		else{
			cout << min(x*b + y*p,(x * max(b,5) + y * max(p,2))*4/5 ) << endl;
		}
	}
	*/
	/*	
	for(int data = 0; data<100; data++){
		int n;
		cin >> n;
		if(n == 0)return 0;

		int  N = n;
		bool jud = false;

		for(int i=0; i<n; i++){
			int k;
			cin >> k;
			if(k == 0) N--;
			else if(k > 1)jud = true;
		}

		if(jud == false) cout << "NA" << endl;
		else cout << N+1 << endl;


	}
	*/
	/*
	for(int D = 0; D < 100; D++){

		int n;
		cin >> n;
		if(n == 0)return 0;
		int hand[10] = {};
		int ba = 0;

		string top;
		cin >> top;

		for(int i=0; i<100; i++){
			if(top[i] == 'M') hand[i%n]++;
			if(top[i] == 'S'){
				ba += hand[i%n]+1;
				hand[i%n] = 0;
			}
			if(top[i] == 'L'){
				hand[i%n]+=ba+1;
				ba = 0;
			}
		}

		sort(hand,hand+n);

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

	}
	*/
	/*
	int q;
	cin >> q;

	for(int i=0; i<q; i++){
		int c,a,n,ans = 0;
		cin >> c >> a >> n;
		int can = min(min(c,a),n);
		//can
		ans+=can;
		c-=can;
		a-=can;
		n-=can;

		//acc
		int acc = min(c/2,a);
		ans+=acc;
		a-=acc;
		c-=acc*2;

		//ccc
		ans+=c/3;

		cout << ans << endl;

	}
	*/

	int team,change,second;
	cin >> team >> change >> second;

	int tv[100100] = {},point[100100] = {},top = 1,secb = 0;//,tv[byousuu],point[id]


	for(int i=1; i<=change+1; i++){

		if(i == change+1){
			tv[top]+= second-secb;
			break;
		}

		int num,sec,poi;
		cin >> num >> sec >> poi;
		tv[top] += sec-secb;

		secb = sec;

		point[num]+=poi;

		if(num != top){
			if(point[num] > point[top] || (point[num] == point[top] && num < top) )top = num;
		}
		else if(poi < 0){
			for(int j=1; j<=team; j++){
				if(point[j] > point[top] || (point[j] == point[top] && j < top)) top = j;
			}
		}
	}

	for(int i=1; i<=team; i++){
		if(tv[i] > tv[top]) top = i;
	}

	cout << top << endl;


	return 0;

}



Measured memory_bytes: 3900
// 解説どおり
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)

int r, g, b, n;

int solve() {
  int cnt{};
  REP(i, 3001) {
    REP(k, 3001) {
      int m = i * r + k * g;
      if (n >= m && (n - m) % b == 0)
        ++cnt;
    }
  }
  return cnt;
}

int main() {
  cin >> r >> g >> b >> n;
  cout << solve() << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <iostream>
#include<math.h>
#include<bitset>
#include<iomanip>
#include<queue>
using namespace std;

int main() {
	int N, M; cin >> N >> M;
	vector<int> L(M),R(M);
	for (int i = 0; i < M; i++) {
		cin >> L[i] >> R[i];
	}
	sort(L.begin(), L.end());
	sort(R.begin(), R.end());
	if(R[0] - L[M - 1]>=0)cout << R[0]- L[M - 1]+1 << endl;
	else cout << 0 << endl;
}



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

int main(){
  char S[200002];
  scanf("%s",S);
  int l=strlen(S);
  for(int i=0;i<l;i++){
    if(S[i]=='?'){
      if(i>0&&S[i-1]=='P') S[i]='D';
      else if(S[i+1]=='D') S[i]='P';
      else if(S[i+1]=='?'){
        S[i]='P';
        S[i+1]='D';
      }else S[i]='D';
    }
  }
  printf("%s\n",S);
  return 0;
}

Measured memory_bytes: 1840
#include<stdio.h>

int main(void)
{
	long int time[100];	//かかる時間を格納
	int i=0;
	long int N;
	scanf("%ld",&N);
	while(i<=4)
	{
		scanf("%ld",&time[i]);
		i++;
	}
	
	long int min=time[0];
	i=1;
	while(i<=4)
	{
		if(min>time[i])
			min=time[i];	//最小値を求める
		i++;
	}
	
	if(N%min==0)
	{
		printf("%ld",N/min+4);
	}
	else
	{
		printf("%ld",N/min+5);
	}
	
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <queue>
#include <algorithm>
#include <vector>

using namespace std;

typedef long long ll;
const int MAXN = 1e5+10;

int n, m;
double a[MAXN];

void solve() {
  priority_queue<double> pque;
  for (int i=0;i<n;i++) {
    pque.push(a[i]);
  }
  for (int i=0;i<m;i++) {
    double v = pque.top();
    pque.pop();
    pque.push(v / 2.0);
  }
  ll sum = 0;
  while (!pque.empty()) {
    ll v = (ll)pque.top();
    pque.pop();
    sum += v;
  }
  cout << sum << endl;
}

int main() {
  cin >> n >> m;
  for (int i=0;i<n;i++) {
    cin >> a[i];
  }
  solve();
}


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

int main() {
    int n;
    cin >> n;
    set<string> st;
    for (int i = 0; i < n; i++) {
        string s;
        cin >> s;
        st.insert(s);
    }
    cout << st.size() << endl;
}

Measured memory_bytes: 19228
#include <stdio.h>
   
int main()
{
    int a, b, c, x, y, z;
    z = 0;
    scanf("%d %d %d\n", &a, &b, &c);
    for(x = a; x <= b; x++)
    {
        y = c / x;
        if(c == y * x)
        {
            z = z + 1;
        }
    }
    printf("%d\n", z);
    return 0;
}

Measured memory_bytes: 600
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */


import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

/**
 *
 * @author nai
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) throws Exception{
        // TODO code application logic here
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
        int B = sc.nextInt();
        int C = sc.nextInt();
        int X = sc.nextInt();
        int cou = 0;
        
        for(int a = 0 ; a < A + 1 ; a++ ){
            for(int b = 0 ; b < B + 1 ; b++ ){
                int c = (X - 500 * a - 100 * b) / 50;
                if(0 <= c && c <= C){
                    cou++;
                }
            }
        }
        System.out.println(cou);
    }
  }
    



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

using namespace std;

using ll = long long;
#define long long long

int main(void) {
    vector<ll> sq(2e5);
    for(ll i=0; i*i<2e5; i++)
        sq[i*i] = 1;

    ll n, d;
    cin >> n >> d;

    vector<vector<ll>> x(n, vector<ll>(d));
    for(auto &l: x) for(auto &c: l) cin >> c;

    ll r = 0;
    for(ll i=0; i<n; i++)
        for(ll j=i+1; j<n; j++) {
            ll s = 0;
            for(ll k=0; k<d; k++)
                s += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
            if(sq[s]) r++;
        }
    cout << r << endl;

}


Measured memory_bytes: 1792
#include<iostream>
#include<cstdio>

using namespace std;
int S[100010];
int main(void){
    int n,q,t,ans=0;

    scanf("%d",&n);
    for(int i=0;i<n;i++)scanf("%d",&S[i]);

    scanf("%d",&q);
    for(int i=0;i<q;i++){
        scanf("%d",&t);

        int Min=0,Max=n-1,center=0;
        
        for(int j=0;j<18 && Max!=Min;j++){
            center=(Max+Min)/2;
            if(t>S[center]){
                Min=center;
            }else{
                Max=center;
            }
        }
        if(S[Max]==t)ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1596
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define fr(i,j,k) for(int i=j;i<k;i++)
#define f(n) fr(i,0,n)
#define f1(n) fr(i,1,n+1)
#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
const ll mod = 1e9 + 7;
const int maxn = 1e5+5;
vector<int>tar;
ll v[maxn];
ll b[65];
void ins(ll x) {
    for (int i = 0 ; i < tar.size() ; i++) {
        if (x & (1LL<<(tar[i]))) {
            if (b[i]) {
                x ^= b[i];
            }
            else {
                b[i] = x;
                break;
            }
        }
    }
}
void go() {
    int n;
    cin >> n;
    ll sum = 0;
    f1(n) {
        cin >> v[i];
        sum ^= v[i];
    }
    for (int i = 60 ; i >= 0 ; i--) {
        if (sum & (1LL<<i)) {

        }
        else {
            tar.pb(i);
        }
    }
    f1(n) {
        ins(v[i]);
    }
    ll ans = 0;
    for (int i = 0 ; i < tar.size() ; i++) {
        if (b[i] && !(ans & (1LL<<tar[i]))) {
            ans ^= b[i];
        }
    }
    cout << ans + (sum ^ ans) << '\n';
}
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int c = 0;
    int t;
    if (!c) {
        t = 1;
    }
    else {
        cin >> t;
    }
    while (t--) {
        go();
    }
}


Measured memory_bytes: 4432
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); i++)
#define all(x) (x).begin(), (x).end()
#define bit(x) (1L << (x))
using ll = long long;
using namespace std;

template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
 
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
        return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}

using graph = vector<vector<int>>;

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

        graph g(n);
        rep (i, m) {
                int u, v;
                cin >> u >> v;
                --u; --v;
                g[u].push_back(v);
                g[v].push_back(u);
        }

        vector<int> ans(n, -1);
        queue<int> st;

        st.push(0);
        while (!st.empty()) {
                int tp = st.front();
                st.pop();

                for (int u : g[tp]) {
                        if (ans[u] != -1) continue;
                        ans[u] = tp + 1;
                        st.push(u);
                }
        }

        cout << "Yes" << endl;
        for (int i=1; i<n; i++) cout << ans[i] << endl;

        return 0;
}


Measured memory_bytes: 10152
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <iostream>
#include <fstream>

#include "bits/stdc++.h"

#define REP(i,x,y) for(int i=(x);i<(y);i++)
#define RREP(i,x,y) for(int i=(y)-1;i>=(x);i--)
#define all(x) (x).begin(),(x).end()
//#define int long long

using namespace std;

// conversion
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

#define dump(x)  cout << #x << " = " << (x) << endl
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl

typedef long long ll;

const ll MOD = 1e9 + 7;

class DHandstand2 {
public:
    void solve(std::istream& in, std::ostream& out) {
        int N;
        in >> N;
        vector<ll> tens(10), tenSums(10);
        tens[0] = 1; tenSums[0] = 1;
        REP(i,1,tens.size()) tens[i] = tens[i-1] * 10;
        REP(i,1,tenSums.size()) tenSums[i] = tenSums[i-1] + tens[i];

        ll answer = 0;
        REP(i,1,N+1) {
            string str = to_string(i);
            if (str.back() == '0') continue;
            else if (str.size() == 1) answer++;
            else if (str.front() < str.back()) {
                if (str.size() != 2) answer += tenSums[str.size() - 3] * 2;
            } else if (str.front() == str.back()) {
                if (str.size() == 2) {
                    answer += 3;
                } else {
                    answer += (tenSums[str.size() - 3] + 1 + stoi(str.substr(1, str.size()-2))) * 2 + 1;
                }
            } else {
                answer += tenSums[str.size() - 2] * 2;
            }
        }
        out << answer << "\n";
    }
};


int main() {
	DHandstand2 solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
cin>>n;
string s[n],t;
for(int i=0;i<n;i++){
cin>>s[i];
sort(s[i].begin(),s[i].end());
}
for(int i=0;i<s[0].size();i++){
bool f=true;
for(int j=1;j<n;j++){
if(!binary_search(s[j].begin(),s[j].end(),s[0][i])){
f=false;
break;
}
}
if(f){
t.push_back(s[0][i]);
for(int j=1;j<n;j++){
for(int k=0;k<s[j].size();k++){
if(s[j][k]==s[0][i]){
s[j][k]='#';
break;
}
}
}
}
}
sort(t.begin(),t.end());
cout<<t;
}

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

int main(void) {
  int N, ma = -1, mai = -1;
  cin >> N;
  for (int i = 1; i <= N; i++) {
    int count = 0;
    int tmp = i;
    while (tmp % 2 == 0 && tmp != 1) {
      tmp /= 2;
      count++;
    }

    if (ma < count) {
      ma = count;
      mai = i;
    }
  }
  cout << mai << endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.util.Map.Entry;
import java.io.*;
import java.lang.reflect.Array;
import java.math.BigInteger;

import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;
 
public class Main //implements Runnable
{
    static long mod=1000000007;
//    static int dx[]={-1,0,1,0};
//    static int dy[]={0,-1,0,1};

    public static void main(String[] args)   throws Exception, IOException{        
        Reader sc = new Reader(System.in);
        PrintWriter out=new PrintWriter(System.out);

//        int n=sc.nextInt();
        char c[]=sc.nextString().toCharArray();
        char d[]=sc.nextString().toCharArray();
        int r=0;
        for (int i = 0; i < d.length; i++) {
            if(c[i]==d[i])r++;		
		}
        
        out.println(r);
     	out.flush();
    }
    
    static boolean validpos(int x,int y,int r, int c){
        return x<r && 0<=x && y<c && 0<=y;
    }

    static void db(Object... os){
        System.err.println(Arrays.deepToString(os));
    }
}

//class P {
//	int x, y;
//	P(int  x, int y) {
//	  this.x=x;
//	  this.y=y;
//	}
//}

//class P implements Comparable<P>{
//    int a,b;
//    P(int a, int b) {
//    	this.b=b;
//    	this.a=a;
//    }
//
//    public int compareTo(P p){
//    	if(a==p.a) return b-p.b;
//        return -p.a+a;
//    }
//}

class Reader
{ 
    private BufferedReader x;
    private StringTokenizer st;
    
    public Reader(InputStream in)
    {
        x = new BufferedReader(new InputStreamReader(in));
        st = null;
    }
    public String nextString() throws IOException
    {
        while( st==null || !st.hasMoreTokens() )
            st = new StringTokenizer(x.readLine());
        return st.nextToken();
    }
    public int nextInt() throws IOException
    {
        return Integer.parseInt(nextString());
    }
    public int[] nextIntArray(int size) throws IOException{
        int r[] = new int[size];
        for (int i = 0; i < size; i++) {
            r[i] = this.nextInt(); 
        }
        return r;
    }
    public long[] nextLongArray(int size) throws IOException{
        long r[] = new long[size];
        for (int i = 0; i < size; i++) {
            r[i] = this.nextLong(); 
        }
        return r;
    }
    public long nextLong() throws IOException
    {
        return Long.parseLong(nextString());
    }
    public double nextDouble() throws IOException
    {
        return Double.parseDouble(nextString());
    }
}


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

int main() {
    int n, m;
    cin >> n >> m;
    vector<pair<int, int>> job(n);
    for (auto &e: job) cin >> e.first >> e.second;
    
    sort(job.rbegin(), job.rend());
    
    priority_queue<int> q;
    

    int ans = 0;
    for (int i = m-1; i >= 0; i--) {
        while (!job.empty() && job.back().first <= m-i) {
            q.push(job.back().second);
            job.pop_back();
        }
        if (!q.empty()) {
            ans += q.top();
            q.pop();
        }
    }
    cout << ans << endl;
        
        
                                
    
    return 0;
}

Measured memory_bytes: 1660
#include<iostream>
#include <string>
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
#define ll long long int
#define ld long double
#define pb push_back
#define endl "\n"
#define mp make_pair
#define sz(v) (int)(v.size())
#define len(s) (int)(s.length())
#define M 1000000007
#define all(v) v.begin(),v.end()
#define fr(a,b,c) for(ll i=a;i<=b;i+=c)
#define inarr(arr,n); for(ll i=0;i<n;i++) cin >> arr[i];
#define outarr(arr,n); for(ll i=0;i<n;i++) cout<<arr[i]<<" ";
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
const ll inf = 9e18;
const ld pi = 2*acos(0.0); 
using namespace std;
ll power(ll a,ll n) 
{
    if(n==0){
        return 1;
    }
    ll p=power(a,n/2) % M;
    p = (p * p) % M;
    if (n%2==1)
    {
        p=(p*a)%M;
    }
    return p;
}
ll gcd(ll a, ll b) 
{ 
    if (a == 0) 
        return b; 
    return gcd(b % a, a); 
}
const int N=1e6+5;
vector <ll> sieve(N,0); 
void si() 
{
    sieve[1]=1;
    for(int i=2;i<N;i++){
        if(sieve[i]==0){
            for(int j=i;j<N;j+=i){
                sieve[j]=i;
            }
        }
    }
}
int main(){
    ios;
    int n;
    cin>>n;
    vector <ll> a(n);
    inarr(a,n);
    vector <ll> curr(n,0);
    curr[n-1]=a[n-1];
    for(int i=n-2;i>=0;i--){
        curr[i]=curr[i+1]+a[i];
    }
    ll ans=0;
    for(int i=0;i<n-1;i++){
        ans+=(a[i]*(curr[i+1]%M))%M;
        ans=ans%M;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 14260
/**
    And in the end, the love you take is equal to the love you make.

        I LOVE YOU LAURA.
**/

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>

#define _CRT_SECURE_NO_DEPRECATE
#define _CRT_DISABLE_PERFCRIT_LOCKS

#define findOrder find_by_order
#define orderKey order_of_key

#define isOn(mask, i) (mask & (1 << i))
#define turn(mask, i) (mask |= (1 << i))
#define switch(mask, i) (mask &= ~(1 << i))
#define change(mask, i) (mask ^= (1 << i))
#define lowbit(mask) (mask & (-mask))
#define turnAll(mask, n) (mask = (1 << n) - 1)
#define switchLastBit(mask) (mask & (mask - 1))
#define turnLastZero(mask) (mask | (mask + 1))
#define modulo(x, mod) ((x) & (mod - 1))
#define log2(x) (31 - __builtin_clz(x))

#define mkp make_pair
#define pb push_back
#define pf push_front
#define eb emplace_back
#define ef emplace_front
#define ins insert
#define rsz resize
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound

#define sz(x) ((int)x.size())
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)

#define debug(x) (cerr << x << " ")

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

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

typedef pair<int, int> ii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdb;
typedef pair<int, ii> tri;
typedef complex<ld> cd;

typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<ld> vdb;
typedef vector<cd> vcd;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<vll> matrix;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_tree;

const ll mod = 1e9+7;
const int maxn = 1e5+2;
const int pi = 2 * acos(0.0);
const db eps = 1e-9;

ll n, m;
vll graph[maxn];
ll dp[maxn];

ll dfs (int node){
    ll &ans = dp[node];

    if (ans != -1) return ans;

    for (auto v: graph[node]){
        ans = max(ans, dfs(v) + 1);
    }
    return ans;
}

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

    memset(dp, -1, sizeof dp);

    cin >> n >> m;

    for (int i = 1; i <= m; i++){
        int a, b; cin >> a >> b;

        graph[a].pb(b);
    }

    ll ans = 0;
    for (int i = 1; i <= n; i++){
        ans = max(ans, dfs(i) + 1);
    }

    cout << ans << "\n";

    return 0;
}


Measured memory_bytes: 7936
#include <stdio.h>
#include <string.h>

int main(void){
  char str[200000];
  scanf("%s",str);

  int start,end;
  for(int i = 0;;i++){
    if(str[i] == 'A'){
      start = i;
      break;
    }
  }
  for(int i = strlen(str);;i--){
    if(str[i] == 'Z'){
      end = i;
      break;
    }
  }
  printf("%d\n",end-start+1);

  return 0;
}

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

int main()
{
 int n;
    cin>>n;
    int base=1;
    while(base<=n)
    {
        base*=2;
    }
    vector<ll> tree (2*base);
    vector<int> h(n),a(n);
    for(int i=0;i<n;i++)
        cin>>h[i];
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }
    vector<ll> dp(n+1);
    for(int flower=0;flower<n;flower++)
    {
        int x=h[flower]+base;
        ll best=0;
        while(x>1)
        {
            if(x%2==1)
            {
                best=max(best,tree[x-1]);
            }
            x/=2;
        }
        dp[h[flower]]=best+a[flower];
        for(int i=base+h[flower];i>=1;i/=2)
        {
            tree[i]=max(tree[i],dp[h[flower]]);
        }
    }
    ll ans=0;
    for(int i=0;i<=n;i++)
    {
        ans=max(ans,dp[i]);
    }
    cout<<ans<<endl;
}

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

#include <boost/range/adaptors.hpp>
#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;
using namespace boost::adaptors;

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

    string s;
    cin >> s;

    unordered_map<pair<string, string>, int64_t,
                  boost::hash<pair<string, string>>>
            m;
    for (auto u : irange(0uL, 1uL << n)) {
        bitset<18> bs(u);

        string s1, s2;
        for (auto i : irange(0L, n)) {
            if (bs[i]) {
                s1.push_back(s[i]);
            } else {
                s2.push_back(s[i]);
            }
        }

        ++m[make_pair(s1, s2)];
    }

    int64_t ans = 0;
    for (auto u : irange(0uL, 1uL << n)) {
        bitset<18> bs(u);

        string s1, s2;
        for (auto i : irange(n, 2 * n) | reversed) {
            if (bs[i - n]) {
                s1.push_back(s[i]);
            } else {
                s2.push_back(s[i]);
            }
        }

        ans += m[make_pair(s1, s2)];
    }

    cout << ans << endl;
}

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

using namespace std;
int main(){
	int c,b;
	cin>>c>>b;
	bool a[4];
	for(int i=1;i<4;i++){
		a[i]=true;
	}
	a[c]=false;
	a[b]=false;
	for(int i=1;i<4;i++){
		if(a[i]==true){
			cout<<i;
			break;
		}
	}
	return 0;
}

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

using namespace std;

const char *TABLE[] = {
	"100101",
	"10011010",
	"0101",
	"0001",
	"110",
	"01001",
	"10011011",
	"010000",
	"0111",
	"10011000",
	"0110",
	"00100",
	"10011001",
	"10011110",
	"00101",
	"111",
	"10011111",
	"1000",
	"00110",
	"00111",
	"10011100",
	"10011101",
	"000010",
	"10010010",
	"10010011",
	"10010000",
	"101",
	"000000",
	"000011",
	"10010001",
	"010001",
	"000001"
};

const char *load_table(char c){
	switch(c){
		case ' ': return TABLE[26];
		case '\'': return TABLE[27];
		case ',': return TABLE[28];
		case '-': return TABLE[29];
		case '.': return TABLE[30];
		case '?': return TABLE[31];
		default: return TABLE[c - 'A'];
	}
}

char bin2c(const string &s){
	int c = 0;
	for(int i = 0; i < s.size(); ++i){ c = (c << 1) | (s[i] - '0'); }
	switch(c){
		case 26: return ' ';
		case 27: return '.';
		case 28: return ',';
		case 29: return '-';
		case 30: return '\'';
		case 31: return '?';
		default: return static_cast<char>(c + 'A');
	}
}

int main(){
	string s;
	while(getline(cin, s)){
		string bin;
		for(int i = 0; i < s.size(); ++i){
			bin += load_table(s[i]);
		}
		while(bin.size() % 5 != 0){ bin += "0"; }
		for(int i = 0; i < bin.size(); i += 5){
			cout << bin2c(bin.substr(i, 5));
		}
		cout << endl;
	}
	return 0;
}

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

int cnt = 2, seze = 5e4, A = 0, B = 1, tA, tB, A0, A1, B0, B1;
int pow2[110], wA[110], wB[110], tmp[110];

int main() {
	puts("32926");
	puts("+ 0 1 3");
	puts("+ 3 3 3");
	puts("< 1 3 3");
	pow2[0] = ++cnt;
	for (int i = 1; i <= 30; ++i) pow2[i] = ++cnt, printf("+ %d %d %d\n", pow2[i - 1], pow2[i - 1], pow2[i]);
	tA = ++cnt, tB = ++cnt;
	printf("+ %d %d %d\n", A, pow2[0], tA);
	printf("+ %d %d %d\n", B, pow2[0], tB);
	A0 = ++seze, A1 = ++seze, B0 = ++seze, B1 = ++seze;
	for (int i = 30; ~i; --i) {
		printf("+ %d %d %d\n", pow2[i], A0, A1);
		wA[i] = ++cnt;
		printf("< %d %d %d\n", A1, tA, wA[i]);
		tmp[0] = ++seze;
		printf("+ %d %d %d\n", wA[i], tmp[0], tmp[0]);
		for (int j = 1; j <= i; ++j) tmp[j] = ++seze, printf("+ %d %d %d\n", tmp[j - 1], tmp[j - 1], tmp[j]);
		printf("+ %d %d %d\n", A0, tmp[i], A0);
	}
	for (int i = 30; ~i; --i) {
		printf("+ %d %d %d\n", pow2[i], B0, B1);
		wB[i] = ++cnt;
		printf("< %d %d %d\n", B1, tB, wB[i]);
		tmp[0] = ++seze;
		printf("+ %d %d %d\n", wB[i], tmp[0], tmp[0]);
		for (int j = 1; j <= i; ++j) tmp[j] = ++seze, printf("+ %d %d %d\n", tmp[j - 1], tmp[j - 1], tmp[j]);
		printf("+ %d %d %d\n", B0, tmp[i], B0);
	}
	for (int i = 0; i <= 30; ++i)
		for (int j = 0; j <= 30; ++j) {
			tmp[0] = ++seze;
			printf("+ %d %d %d\n", wA[i], wB[j], tmp[0]);
			printf("< %d %d %d\n", pow2[0], tmp[0], tmp[0]);
			for (int k = 1; k <= i + j; ++k) tmp[k] = ++seze, printf("+ %d %d %d\n", tmp[k - 1], tmp[k - 1], tmp[k]);
			printf("+ %d %d %d\n", 2, tmp[i + j], 2);
		}
	return 0;
}

Measured memory_bytes: 3696
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>

using namespace std;

bool CheckTriangle(int a, int b, int c)
{
	bool result = true;

	result &= (a >= b + c) ? false : true;
	result &= (b >= a + c) ? false : true;
	result &= (c >= b + a) ? false : true;

	return result;

}

int main()
{
	int n;
	int d[2000];
	int remain[2000];

	cin >> n;

	for (int i = 0; i < n; i++)
	{
		cin >> d[i];
	}
	sort(d, d + n);
	/*for (int i = 0; i < n; i++)
	{
		cout <<  d[i] << ' ';
	}
	cout << "\n";*/
	
	long long resultCount = 0;

	for (int i = 0; i < n; i++)
	{
		for (int j = i+1; j < n; j++)
		{
			for (int k = j+1; k < n; k++)
			{
				bool check = d[i] + d[j] > d[k];
				if (check)
				{
					//cout << d[i] << ' ' << d[j] << ' ' << d[k] << endl;
					resultCount++;
					//break;
				}
				else
				{
					break;
				}
			}
		}
	}

	cout << resultCount;

	//system("pause");
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define GET_REP(_1, _2, _3, NAME, ...) NAME
#define rep(...) GET_REP(__VA_ARGS__, irep, _rep)(__VA_ARGS__)
#define rep1(...) GET_REP(__VA_ARGS__, irep1, _rep1)(__VA_ARGS__)
#define _rep(i, n) irep (i, 0, n)
#define _rep1(i, n) irep1(i, 1, n)
#define irep(i, a, n) for (int i = a; i < (int)(n); ++i)
#define irep1(i, a, n) for (int i = a; i <= (int)(n); ++i)
#define rrep(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define rrep1(i, n) for (int i = (int)(n); i >= 1; --i)
#define allrep(X, x) for (auto &&X : x)
#define all(x) begin(x), end(x)
#define debug(x) cout << #x " => " << (x) << endl
#ifdef LOCAL
  #include "../../Lib/cout_container.hpp"
#endif
using lint = long long;
constexpr int MOD = (int)1e9 + 7;
constexpr double EPS = 1e-9;
using namespace std;
namespace { struct INIT { INIT() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(15); } } INIT; }

int count_bit(unsigned long long data) {
  data = (data & 0x5555555555555555) + ((data & 0xAAAAAAAAAAAAAAAA) >> 1);
  data = (data & 0x3333333333333333) + ((data & 0xCCCCCCCCCCCCCCCC) >> 2);
  data = (data & 0x0F0F0F0F0F0F0F0F) + ((data & 0xF0F0F0F0F0F0F0F0) >> 4);
  data = (data & 0x00FF00FF00FF00FF) + ((data & 0xFF00FF00FF00FF00) >> 8);
  data = (data & 0x0000FFFF0000FFFF) + ((data & 0xFFFF0000FFFF0000) >> 16);
  data = (data & 0x00000000FFFFFFFF) + ((data & 0xFFFFFFFF00000000) >> 32);
  return data;
}

int main(void) {
  int h, w, k;
  cin >> h >> w >> k;
  vector<vector<bool>> v(h, vector<bool>(w));
  rep (i, h) rep (j, w) {
    char c;
    cin >> c;
    v[i][j] = c == '1';
  }
  int bitmax = 1 << (h - 1);
  int mini   = INT_MAX;
  rep (bit, bitmax) {
    int bitnum = count_bit(bit);
    int sum = bitnum;
    // 縦横ブロックの現在値
    vector<int> block(bitnum + 1);
    bool ok = true;
    rep (i, w) {
      // 縦ブロック
      vector<int> hblock(bitnum + 1);
      // 縦ブロックidx
      int bi = 0;
      // 縦ブロック内の1の個数
      int block_sum = 0;
      rep (j, h) {
        bool sep = (bit >> j) & 1;
        if (v[j][i]) ++block_sum;
        if (sep || j == h - 1) {
          hblock[bi] = block_sum;
          if (block_sum > k) {
            ok = false;
            break;
          }
          block_sum = 0;
          ++bi;
        }
      }
      rep (j, bitnum + 1) {
        block[j] += hblock[j];
        if (block[j] > k) {
          ++sum;
          block = hblock;
          break;
        }
      }
    }
    if (!ok) continue;
    mini = min(mini, sum);
  }
  cout << mini << endl;
  return 0;
}

Measured memory_bytes: 256
#define rep(i, N) for(int (i) = 0; (i) < (N); (i) ++)

#define rep2(i, N, s) for(int (i) = (s); (i) < (N) + (s); (i) ++)
#define rrep(i, N) for(int (i) = (N) - 1; (i) >= (0); (i) --)
#define rrep2(i, N, s) for(int (i) = (s); (i) >= (s) - (N) + 1; (i) --)
#define INF 1e9
#include <cmath>
#include <limits>

#include <vector>
#include <iostream>
#include <algorithm>
#include <queue>
#include <string>
using namespace std;

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

int main(){
    string s;
    cin >> s;
    ll K;
    cin >> K;
    ll tmp = 0;
    for(int i = 0; i < s.size() && i < K; i++){
        if(s[i] != '1'){
            cout << s[i] << endl;
            return 0;
        }
    }
    cout << 1 << endl;
    return 0;
}


Measured memory_bytes: 256
from math import gcd
def lcm(x,y):
    return x*y//gcd(x,y)
n = int(input())
a_ls = [0] * n
b_ls = [0] * n
for i in range(n):
    a_ls[i], b_ls[i] = map(int,input().split())
add = 0
for i in range(n-1,-1,-1):
    a = a_ls[i] + add
    b = b_ls[i]
    if a % b == 0:
        continue
    else:
        diff = b - a%b
        add += diff
print(add)



Measured memory_bytes: 16788
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int num = 100*a + 10*b + c;
		System.out.println((num%4 > 0)?"NO":"YES");
	}
}

Measured memory_bytes: 21844
import numpy as np
N, M, *L = map(int, open(0).read().split())
L = [np.array(m) for m in zip(*[iter(L)]*3)]
ans = 0
for i in range(8):
  X = []
  c = []
  for j in range(3):
    if i%2==1:
      c.append(-1)
    else:
      c.append(1)
    i >>= 1
  c = np.array(c)
  X = list(map(lambda x:sum(x*c), L))
  X.sort(reverse=True)
  ans = max(ans, sum(X[:M]))
print(ans)

Measured memory_bytes: 12564
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define show(x) cout<<x<<'\n'
#define showh(x) cout<<x<<' '
#define go(i,a,n) for(ll i=a;i<n;i++)
#define gor(i,a,n) for(ll i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define mod 1000000007
bool prime[100001];

bool ispoweroftwo(ll x)
{
    return x && !(x & (x-1));
}
ll xorcal(ll n)
{
    if(n%4==0)
        return n;
    if(n%4==1)
        return 1;
    if(n%4==2)
        return n+1;
    if(n%4==3)
        return 0;
}
void sieve(ll n)
{
    memset(prime,true,sizeof(prime));
    prime[0]=false;
    prime[1]=false;
    for(ll i=2;i*i<=n;i++)
    {
        if(prime[i]==true)
        {
            for(ll j=i*i;j<=n;j+=i)
            {
                prime[j]=false;
            }
        }
    }
    show(prime[89]);
}
bool isprime(ll n)
{
    if (n<=1) return false;
    if (n<=3) return true;

    if(n%2==0 or n%3==0) return false;

    for(ll i=5;i*i<=n;i+=6)
    {
        if(n%i==0 or n%(i+2)==0) return false;
    }
    return true;
}

ll modinverse(ll a,ll m)
{
    ll m0 = m;
    ll y = 0, x = 1;

    if (m == 1)
      return 0;

    while (a > 1)
    {
        ll q = a / m;
        ll t = m;

        m = a % m; a = t;
        t = y;

        y = x - q * y;
        x = t;
    }

    if (x < 0)
       x += m0;

    return x;
}

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

ll power(ll A, ll B)
{
    if (A == 0)
        return 0;
    if (B == 0)
        return 1;

    ll y;
    if (B % 2 == 0) {
        y = power(A, B / 2);
        y = (y * y) % mod;
    }

    else {
        y = A % mod;
        y = (y * power(A, B - 1) % mod) % mod;
    }

    return (ll)((y + mod) % mod);
}

int main()
{
    ios_base::sync_with_stdio(false);
    ll n;
    cin>>n;
    ll a[n];
    go(i,0,n)
    {
        cin>>a[i];
    }
    ll flag=0;
    map<ll,ll>m;
    go(i,0,n-1)
    {
        if(a[i]>a[i+1])
        {
            a[i]--;
            if(a[i]>a[i+1])
            {
                show("No");
                exit(0);
            }
            m[i]++;
        }
    }
    go(i,0,n-1)
    {
        if(a[i]>a[i+1])
        {
            go(j,0,i+1)
            {
                    if(a[j]>a[i+1])
                    {
                        if(m[j]==1)
                        {
                            show("No");
                            exit(0);
                        }
                        a[j]--;
                    }
            }
        }
    }
    go(i,0,n-1)
    {
        if(a[i]>a[i+1])
        {
            show("No");
            exit(0);
        }
    }
    show("Yes");
    return 0;
}


Measured memory_bytes: 4224
#include<iostream>
#include <bits/stdc++.h>
#include<string>
#include<algorithm>
using namespace std;
typedef pair<int,int> P;


int main(){
    int N, W;
    cin >> N >> W;
    int v[N+1], w[N+1];
    for(int i =1 ; i < N+1; ++i){
        cin >> v[i] >> w[i] ;
    }
    int dp[N+1][W+1];
    for(int i=0;i<W+1;++i){
        dp[0][i]=0;
    }
    for(int i =1;i<N+1;++i){
        for(int j =0;j<W+1;++j){
            //i番目のアイテムが入れられる場合は、入れた場合と入れない場合の価値を比較
            if(w[i] <= j){
                if(dp[i-1][j-w[i]]+v[i] > dp[i-1][j]){
                    dp[i][j]=dp[i-1][j-w[i]]+v[i];
                        }
                else{
                    dp[i][j]=dp[i-1][j];
                }
            }            
            //i番目が入れられない場合は、問答無用で前の数値を入れる
            else{
                 dp[i][j] = dp[i-1][j];
            }
        }
    }
    cout << dp[N][W] << endl;
    return 0;
}


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

#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y

using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;

using f32 = float;
using f64 = double;

#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) for(i64 i = 1; i <= n; ++i)
#define RREP(i, n) for(i64 i = n - 1; i >= 0 ; --i)
#define RREPS(i, n) for(i64 i = n; i >= 1; --i)

#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))

#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define pb push_back
#define mp make_pair
#define F first
#define S second

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }

template<typename T, size_t N>
i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); }


struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;


#define N 5
i64 T[N];

int main() {
    REP(i, N) cin >> T[i];

    i64 mint = 100000000;
    i64 perm[] = {0, 1, 2, 3, 4};
    do {
        i64 t = T[perm[0]];
        REPS(i, N - 1) {
            if (t % 10 > 0) {
                t = (t / 10 + 1) * 10;
            }
            t += T[perm[i]];
        }
        chmin(mint, t);
    } while (next_permutation(perm, perm + N));

    cout << mint << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define F first
#define S second
#define pii pair<int, int>
#define sz size()
#define pb push_back

using namespace std;

const int maxn = 1e5 + 12;
int n, a[maxn], dp[maxn], ans;
vector < pii > v[maxn];

int main() 
{
    cin >> n;
    for (int i = 1; i <= n; i ++) {
        cin >> a[i];
    }
    dp[2] += abs (a[2] - a[1]);
    for (int i = 3; i <= n; i ++) {
        dp[i] = min (dp[i - 1] + abs (a[i] - a[i - 1]), dp[i - 2] + abs (a[i] - a[i - 2]));
    }
    cout << dp[n];
}


Measured memory_bytes: 3328
from collections import Counter

N = int(input())
V = map(int, input().split())

odd = Counter()
even = Counter()

for i, v in enumerate(V):
    cnt = even if i % 2 else odd
    cnt[v] += 1

oddCmn = odd.most_common(2)
evenCmn = even.most_common(2)

oddCmn.append((0, 0))
evenCmn.append((0, 0))

od = 0
ev = 0
if oddCmn[od][0] == evenCmn[ev][0]:
    if oddCmn[od][1] + oddCmn[od + 1][1] < evenCmn[ev][1] + evenCmn[ev + 1][1]:
        ev += 1
    else:
        od += 1


print(N - oddCmn[od][1] - evenCmn[ev][1])


Measured memory_bytes: 21224
import java.io.*;
import java.nio.CharBuffer;
import java.util.NoSuchElementException;

public class Main {

    public static void main(String[] args) {
        SimpleScanner scanner = new SimpleScanner(System.in);
        PrintWriter writer = new PrintWriter(System.out);

        long n = scanner.nextLong();
        long ans = n - 1;
        for (long i = 2; i * i <= n; ++i)
            if (n % i == 0) {
                ans = Math.min(ans, i - 1 + n / i - 1);
            }
        writer.println(ans);

        writer.close();
    }

    private static class SimpleScanner {

        private static final int BUFFER_SIZE = 10240;

        private Readable in;
        private CharBuffer buffer;
        private boolean eof;

        SimpleScanner(InputStream in) {
            this.in = new BufferedReader(new InputStreamReader(in));
            buffer = CharBuffer.allocate(BUFFER_SIZE);
            buffer.limit(0);
            eof = false;
        }


        private char read() {
            if (!buffer.hasRemaining()) {
                buffer.clear();
                int n;
                try {
                    n = in.read(buffer);
                } catch (IOException e) {
                    n = -1;
                }
                if (n <= 0) {
                    eof = true;
                    return '\0';
                }
                buffer.flip();
            }
            return buffer.get();
        }

        private void checkEof() {
            if (eof)
                throw new NoSuchElementException();
        }

        private char nextChar() {
            checkEof();
            char b = read();
            checkEof();
            return b;
        }

        private String next() {
            char b;
            do {
                b = read();
                checkEof();
            } while (Character.isWhitespace(b));
            StringBuilder sb = new StringBuilder();
            do {
                sb.append(b);
                b = read();
            } while (!eof && !Character.isWhitespace(b));
            return sb.toString();
        }

        private int nextInt() {
            return Integer.parseInt(next());
        }

        private long nextLong() {
            return Long.parseLong(next());
        }

        private double nextDouble() {
            return Double.parseDouble(next());
        }
    }
}

Measured memory_bytes: 22868
using System;
using System.Linq;
class Program
{
    static void Main()
    {
        //string[] input = Console.ReadLine().Split();
        int a=int.Parse(Console.ReadLine());
        int b = int.Parse(Console.ReadLine());
        int c = int.Parse(Console.ReadLine());
        //string a = Console.ReadLine();
        Console.WriteLine(((double)(a+b)/2)*c);
        Console.ReadLine();
    }
}


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

int N, C, K;
vector<int> T;

int main() {
    scanf("%d %d %d", &N, &C, &K);
    T.resize(N);
    for(int i = 0; i < N; i++) {
        scanf("%d", &T[i]);
    }
    sort(T.begin(), T.end());
    int cnt = 0;
    int s = 0;
    for(int i = 0; i < N; i++) {
        if(i == 0 || T[i] - T[s] > K || i - s >= C) {
            cnt++;
            s = i;
        }
    }
    printf("%d", cnt);
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lvector vector<ll>
#define cvector vector<char>
#define svector vector<string>
#define lque queue<ll>
#define lpque priority_queue<ll>
#define dlpque priority_queue<ll,lvector,greater<ll>>
#define P pair<ll,ll>
#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()
#define rep(i,n) for(ll i=0; i<n; ++i)
#define print(a) cout << (a) << endl

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n,x,y,num=0;cin>>n;
  bool b=false;
  rep(i,n) {
    cin>>x>>y;
    if(x==y) num++;
    else num=0;
    if(num==3) b=true;
  }
  print(b?"Yes":"No");
  return 0;
}

Measured memory_bytes: 3648
#include<iostream>
#include<cstdio>
#include<cmath>
#include<vector>
#include<queue>
#include<map>
#include<algorithm>
#include<set>
#include<complex>
#include<string>
#include<cstring>
using namespace std;
#define rep2(x,from,to) for(int x=(from);(x)<(to);(x)++)
#define rep(x,to) rep2(x,0,to)
#define INF 100000000
#define debug(x) cout<<#x<<": "<<x<<endl

#define all(x) x.begin(),x.end()
typedef pair<int,int> P;
typedef pair<int,P> PP;
int n;
double x;
string u;
double wa;
int main()
{
	cin>>n;
	rep(i,n)
	{
		cin>>x>>u;
		if(u=="JPY")
		{
			wa+=x;
		}
		else
		{
			wa+=x*380000.0;
		}
	}
	cout<<wa<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>

unsigned long long getNumOfAttack(unsigned long long H)
{
	if (H == 1)
		return 1;
	else
		return 1 + 2 * getNumOfAttack(H / 2);
}

int main()
{
	unsigned long long H;

	scanf("%llu", &H);
	printf("%llu\n", getNumOfAttack(H));
	return 0;
}

Measured memory_bytes: 256