akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
 
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int i = 1;
        do{
            int x = i;
            if(x%3 == 0){
                System.out.printf(" %d", i);
                continue;
            }
            do{
                if(x%10 == 3){
                    System.out.printf(" %d", i);
                    break;
                }
                x /= 10;
            }while(x > 0);
        }while( ++i <= n );
        System.out.printf("\n");
    }
}


Measured memory_bytes: 40748
#include <iostream>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <vector>
using namespace std;
int main() {
    int N, K; cin >> N >> K;
    vector<int> H(N, 0);
    for (int i = 0; i < N; ++i) cin >> H[i];
    sort(H.begin(), H.end(), greater<int>());
    unsigned long long int cnt = 0;
    for (int i = 0; i < N; ++i) {
        if (K > 0) {
            K--;
        }
        else {
            cnt += H[i];
        }
    }
    cout << cnt << endl;
}


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

int main(){
  int k, x;
  cin >> k >> x;
  for(int i= max(-1000000, x-k+1); i<= min(1000000, x+k-1); ++i){
    if(i == min(1000000, x+k-1)) cout << i << endl;
    else cout << i << " ";
  }
}

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

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

  vector<pair<int, int>> v(N);
  rep(i,0,N-1) cin >> v.at(i).first >> v.at(i).second;

  vector<int> ord(N);
  rep(i,0,N-1) ord[i] = i;

  double sum = 0;
  int cnt = 0;
  do {
    double d = 0;
    rep(i,1,ord.size()-1) {
      int p = ord[i-1], q = ord[i];
      int dx = v.at(p).first - v.at(q).first;
      int dy = v.at(p).second - v.at(q).second;
      d += sqrt(dx * dx + dy * dy);
    }
    sum += d;
    cnt++;
  } while (next_permutation(ord.begin(), ord.end()));

  printf("%.10f\n", sum / cnt);
  return 0;
}


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

int cnt = 0, m;
int G[14] = {1, 4 , 13, 40, 121, 364, 1093, 3280, 9841, 29524, 88573, 265720, 797161, 2391484};
int array[1000005];

void insertionSort(int n, int g){
	int v;
	for(int i = g ; i < n ; i++){
		v = array[i];
		int j = i - g;
		while(j >= 0 && array[j] > v){
			array[j + g] = array[j];
			j -= g;
			cnt++;
		}
		array[j + g] = v;
	}
} 

void shellSort(int n){
	int h;
	for(h = 1 ; ; ){
		if(h > n){
			break;
		}
		
		h = 3 * h + 1;
	}
		
		for(int i = 0 ; i < 14 ; i++){
			if(h == G[i]){
				m = i;
			}
			for(int i = m - 1 ; i >= 0 ; i--){
				insertionSort(n, G[i]);
			}
		}
}

int main(){
	int n;
	cin >> n;
	for(int i = 0 ; i < n ; i++){
		cin >> array[i];
	}
	
	shellSort(n);
	
	cout << m << endl;
	
	for(int i = m - 1 ; i >= 0 ; i--){
		cout << G[i];
		cout << " ";
	}
	
	cout << endl;
	cout << cnt << endl;
	
	for(int i = 0 ; i < n ; i++){
		cout << array[i] << endl;
	}
	
	return 0;
	
}

Measured memory_bytes: 5064
object Main extends App {
  val inputs: Seq[String] = scala.io.Source.stdin.getLines().toList
  val n = inputs.head.toInt

  println(solve(n))

  def solve(n: Int): Int = {
    n % 1000 match {
      case 0 => 0
      case v => 1000 - v
    }
  }
}

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


typedef pair<int,int> pii;

int ans = 0;

void solve(string S, vector<vector<pii>> v){
  if(S.size() < v.size()){
    solve(S + "0", v);
    solve(S + "1", v);
  } else {     
    // 1になっている人について、Sと状況が一致しているかどうか判定する
    // 全て一致していたら、人数が答えの候補
    int tmpans = 0;
    
    for(int i = 0; i < S.size(); i++){
      if(S[i] == '0') continue;
      // iさんが正直者かどうか
      tmpans++;
      bool flg = true;
      for(auto x: v[i]){
        // x.first さんが x.secondであるかどうか
        if(S[x.first] - '0' != x.second){
          flg = false;
          break;
        }
      }
      if(!flg){
        tmpans = 0;
        break;
      }
    }
    // cerr << S << " " << tmpans << " " << ans << endl;
    if(tmpans > ans){
      ans = tmpans;
    }
  }
}

int main(){
  int N;
  cin >> N;
  vector<vector<pii>> v(N);
  for(int i = 0; i < N; i++){
    int n;
    cin >> n;
    for(int j = 0; j < n; j++){
      int tmp1, tmp2;
      cin >> tmp1 >> tmp2;
      v.at(i).push_back(make_pair(tmp1-1,tmp2));
    }
  }
  
  solve("", v);
  cout << ans << endl;
  
}

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

int main(void){
	int N, M, C;
	cin >> N >> M >> C;
	vector<int> B(M);
	for(int i = 0; i < M; ++i){
		cin >> B[i];
	}
	vector<vector<int>>A(N, vector<int>(M));
	for(int i = 0; i < N; ++i){
		for(int j = 0; j < M; ++j){
			cin >> A[i][j];
		}
	}
	int ans = 0;
	for(int i = 0; i < N; ++i){
		int sum = 0;
		for(int j = 0; j < M; ++j){
			sum += A[i][j] * B[j];
		}
		if(sum + C > 0){
			ans++;
		}
	}
	cout << ans << endl;
}

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

using namespace std;

template <class RandomIt, class T=typename RandomIt::value_type>
void csort(RandomIt first, RandomIt last, T ub) {
    /* Counting sort */
    vector<T> counter(ub+1);
    for (RandomIt it=first; it<last; ++it)
        ++counter[*it];

    for (RandomIt it=counter.begin()+1; it<counter.end(); ++it)
        *it += it[-1];

    vector<T> output(last-first);
    for (RandomIt it=last-1; it>=first; --it) {
        output[counter[*it]-1] = *it;
        --counter[*it];
    }

    for (RandomIt in=output.begin(), out=first; out<last; (++in, ++out))
        *out = *in;
}

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

    vector<int> a(n);
    int k=0;
    for (size_t i=0; i<n; ++i) {
        scanf("%d", &a[i]);
        if (k < a[i])
            k = a[i];
    }

    csort(a.begin(), a.end(), k);

    for (size_t i=0; i<n; ++i)
        printf("%d%c", a[i], i<n-1? ' ':'\n');

    return 0;
}

Measured memory_bytes: 17940
#include <iostream>
using namespace std;
int main(void){
    int n, w[101], v=1e9;
    cin >> n;
    w[0] = 0;
    for(int i=1;i<=n;i++){
        cin >> w[i];
        w[i] += w[i-1];
    }
    for(int i=1;i<n;i++){
        v = min(v, abs(w[i] - w[n] + w[i]));
    }
    cout << v << endl;
}


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

const int nax=303;
char a[nax][nax];
int res[nax][nax];
int h,w,k;

void solve(int aa,int bb,int cc,int dd,int t)
{

    for(int i=aa;i<=bb;i++)
    {
        for(int j=cc;j<=dd;j++)
        {
            res[j][i]=t;
        }
    }
}

bool czy[nax];

int main()
{
    int t=1;
    int last=1;
    cin>>h>>w>>k;
    for(int i=1;i<=h;i++)
    {
        for(int j=1;j<=w;j++)
        {
            cin>>a[i][j];
            if(a[i][j]=='#') czy[j]=true;
        }
    }
    for(int j=w-1;j>=1;j--)
    {
        if(czy[j+1]==true) czy[j]=true;
    }
    for(int j=1;j<=w;j++)
    {
        int idx=-1;
        int up=1;
        bool ok = false;
        if(j==w-1) ok = true;
        for(int i=1;i<=h;i++)
        {
            if(a[i][j]=='#')
            {
                idx=j;
                if(czy[j+1]==true)
                {
                    solve(last,j,up,i,t);
                }
                else solve(last,w,up,i,t);
                t++;
                up=i+1;
            }
        }
        if(czy[j+1]==true) solve(last,j,up,h,t-1);
        else solve(last,w,up,h,t-1);
        if(idx!=-1) last=j+1;
        if(czy[j+1]==false) break;
    }
    for(int i=1;i<=h;i++)
    {
        for(int j=1;j<=w;j++)
        {
            cout<<res[i][j]<<" ";
        }
        cout<<endl;
    }
    return 0;
}


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

int main() {
    int n;
    scanf("%d", &n);
    vector<int> a(n,0);
    rep(i, n) {
        scanf("%d", &a[i]);
    }
    int count = 0;
    bool flag = false;
    while (!flag) {
        flag = true;
        for (int i = 0; i < n-1; i++) {
            if (a[i] > a[i+1]) {
                swap(a[i], a[i+1]);
                flag = false;
                count++;
            }
        }
    }
    rep(i, n) {
            printf("%d", a[i]);
            if (i != n - 1) printf(" ");
        }
    printf("\n%d\n", count);
}


Measured memory_bytes: 3216
#include<stdio.h>
#define N 20000

int main(void)
{
	int i,a[N],b[N];
	char op[N];
	for(i=0;i<N;i++){
		a[i] = 0;
		b[i] = 0;
	}
	scanf("%d %c %d",&a[0],&op[0],&b[0]);

	i=0;
	while(op[i] != '?'){
		i++;
		scanf("%d %c %d",&a[i],&op[i],&b[i]);
	}
	
	i=0;
	while(op[i] != '?'){
		switch(op[i]){
			case '+' : printf("%d\n",a[i]+b[i]);
					   break;
			case '-' : printf("%d\n",a[i]-b[i]);
					   break;
			case '*' : printf("%d\n",a[i]*b[i]);
					   break;
			case '/' : printf("%d\n",a[i]/b[i]);
					   break;
		}
		i++;
	}	
	return 0;
}

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

using namespace std;

#define LOG(...) fprintf(stderr, __VA_ARGS__)
//#define LOG(...)
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); ++i)
#define RFOR(i, a, b) for (int i = (int)(b - 1); i >= (int)(a); --i)
#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 ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(RALL(c))
#define SZ(a) ((int)(a).size())
#define BIT(x, i) (((x) >> (i)) & 1)
#define SQ(x) ((x) * (x))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define INF 100000000

int H, W, S;

int M;
int field[32][32];
int sum[32][32][32][32];
pii dp[32][32][32][32];

int group_sum(int x1, int y1, int x2, int y2) {
    if (sum[x1][y1][x2][y2] != -1) return sum[x1][y1][x2][y2];
    if (x1 == x2 && y1 == y2) {
        return sum[x1][y1][x1][y1] = field[y1][x1];
    }

    int m = 0;
    FOR(x, x1, x2) {
        m = group_sum(x1, y1, x, y2) + group_sum(x + 1, y1, x2, y2);
    }
    FOR(y, y1, y2) {
        m = group_sum(x1, y1, x2, y) + group_sum(x1, y + 1, x2, y2);
    }
    return sum[x1][y1][x2][y2] = m;
}

pii rec(int x1, int y1, int x2, int y2) {
    if (dp[x1][y1][x2][y2].first != -1) return dp[x1][y1][x2][y2];
    pii ma = {0, 0};
    int r = S - (M - sum[x1][y1][x2][y2]);
    if (r >= 0) {
        ma = {1, r};
    }
    FOR(x, x1, x2) {
        pii a = rec(x1, y1, x, y2), b = rec(x + 1, y1, x2, y2);
        ma = max(ma, {a.first + b.first, min(a.second, b.second)});
    }
    FOR(y, y1, y2) {
        pii a = rec(x1, y1, x2, y), b = rec(x1, y + 1, x2, y2);
        ma = max(ma, {a.first + b.first, min(a.second, b.second)});
    }
    return dp[x1][y1][x2][y2] = ma;
}

int main() {
    while (cin >> H >> W >> S, H | W | S) {
        M = 0;
        REP(y, H) REP(x, W) {
            cin >> field[y][x];
            M += field[y][x];
        }

        fill_n((int *)sum, 32 * 32 * 32 * 32, -1);
        fill_n((pii *)dp, 32 * 32 * 32 * 32, make_pair(-1, 0));

        group_sum(0, 0, W - 1, H - 1);
        pii res = rec(0, 0, W - 1, H - 1);
        cout << res.first << " " << res.second << endl;
    }
}

Measured memory_bytes: 15336
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rrep(i,a,b) for(ll i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()

int main(void){
    ll n;
    cin >> n;

    ll n1 = 0, n2 = 0;
    rrep(i, sqrt(n), 1){
        if(n % i == 0){
            ll tmp = i;
            while(tmp){
                tmp /= 10;
                n1++;
            }
            tmp = n / i;
            while(tmp){
                tmp /= 10;
                n2++;
            }
            break;
        }
    }

    cout << max(n1, n2) << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream> 
#include <algorithm>
#include <vector>
#include <cstdlib>
#include <sstream>
#include <vector>
#include<math.h>


using namespace std;
#define rep(i, n) for ( int i = 0; i < ( int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < ( int)(n); i++)

int main() {
	int n,i=0,j=0,k=0,p=0,m,x,y,z;
	cin >> n;
	vector<int>l(n);

	rep(i, n) {
		cin >> l.at(i);
		
	}
	
	

	rep(i, n) {
		rep2(j,i+1, n) {
			rep2(k,j+1, n) {
				
				x = l.at(i);
				y = l.at(j);
				z = l.at(k);

				if (x == y || y == z || z == x)
					continue;

				if (x + y > z && y + z > x && z + x > y) {
					p++;
				}
					
			}
			
		}
		
	}
	
	cout << p << endl;
	return 0;
}

Measured memory_bytes: 3636
#include <stdio.h>
#include <string.h>
int main(){
    int n,count=0,i,j,k,l,p,q;
    char name[26];
    scanf("%d",&n);
    scanf("%s",name);
    p=strlen(name);
    for (i=0; i<n; i++) {
        char plate[101];
        scanf("%s",plate);
        q=strlen(plate);
        for (j=0; j<q-p+1; j++) {
            for (k=1; j+k*p-k<q; k++) {
                l=0;
                while (name[l]==plate[j+k*l]&&l<p) {
                    l++;
                    if (l==p) {
                        count++;
                        break;
                    }
                }
                if (l==p) {
                    break;
                }
            }
            if (l==p) {
                break;
            }
        }
    }
    printf("%d\n",count);
    return 0;
}

Measured memory_bytes: 600
#include "bits/stdc++.h"
using namespace std;
typedef long long int lint;
typedef pair<lint, lint> plint;
typedef pair<double long, double long> pld;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for(lint i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(lint i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
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 T1, typename T2> pair<T1, T2> operator+(const pair<T1, T2>& l, const pair<T1, T2>& r) { return make_pair(l.first + r.first, l.second + r.second); }
template<typename T1, typename T2> pair<T1, T2> operator-(const pair<T1, T2>& l, const pair<T1, T2>& r) { return make_pair(l.first - r.first, l.second - r.second); }
const lint MOD = 1e9 + 7, INF = 1e18;


lint D;
lint decrease[26];
lint satis[365][26];
lint prv[26];

lint downscore(lint passed) {
	lint sum = 0;
	REP(i, 26) {
		sum += decrease[i] * (passed - prv[i]);
	}
	return -sum;
}

int main() {
	cin >> D;
	REP(i, 26) {
		cin >> decrease[i];
	}
	REP(i, D) {
		REP(j, 26) {
			cin >> satis[i][j];
		}
	}

	lint score = 0;
	REP(i, D) {
		lint maxv = -INF, max_idx = -1;
		cout << 10;
		if (i != D - 1) cout << endl;
	}
	return 0;
}


Measured memory_bytes: 3724
N=int(input())
s=0
minus=10**18
flag=True
for i in range(N):
    a,b=map(int,input().split())
    if a>b:
        minus=min(minus,b)
        flag=False
    elif b>a:
        flag=False
    s+=a
if flag:
    print(0)
else:
    print(s-minus)

Measured memory_bytes: 51800
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <numeric>
typedef long long Int;
#define rep(i,a,b) for(Int i=a;i<b;++i)
#define rrep(i,a,b) for(Int i=a;i>=b;--i)
using namespace std;

long long NumDivisor(long long n) {
    long long res = 0;

    for(long long i = 1; i*i <= n; ++i) {
        if (n%i == 0) {
            ++res;
            if (i != n/i) ++res;
        }
    }

    return res;
}

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

    Int N; cin >> N;
    Int res = 0;
    for(Int i = 1; i <= N; i += 2) {
        if (NumDivisor(i) == 8) ++res;
    }

    cout << res << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
using namespace std;
int ans[1<<20];
string s;
vector<int> simu(vector<int> &v){
    int i,n = v.size();
    vector<int> w;
    for(i=0;i<n;i+=2){
        int x = max(v[i] - v[i + 1],v[i + 1] - v[i]);
        if(s[x - 1]=='0') w.push_back(min(v[i],v[i + 1]));
        else w.push_back(max(v[i],v[i + 1]));
    }
    return w;
}

void solve(vector<int> v,int dig, int num){
    int i,n = v.size();
    if(n==1){
        ans[num] = v[0];
        //cout << v[0] << endl;
        return ;
    }
    vector<int> w;
    for(int i=1;i<n;i++){
        w.push_back(v[i]);
    }
    w.push_back(v[0]);
    solve(simu(v),dig + 1,num);
    solve(simu(w),dig + 1,num|(1<<dig));
}

vector<int> v;
int main(){
    int i,n;
    cin >> n >> s;
    for(i=0;i<(1<<n);i++){
        int x; cin >> x;
        v.push_back(x);
    }
    solve(v,0,0);
    for(i=0;i<(1<<n);i++){
        cout << ans[i] << endl;
    }
}


Measured memory_bytes: 9376
#include<iostream>
#include<string.h>
#include<vector>
#include<list>
#include<stdio.h>
#include<math.h>
#include<iomanip>
#include<map>
#include<stack>
#include<queue>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) range(i,0,b)
#define debug(x) cout << "debug " << x << endl;
using namespace std;

int main(){
    char inp;
    bool space = false;
    int i = 0;
    vector<char> outp;
    vector<char>::iterator it;
    while(scanf("%c",&inp) != EOF){
        if(inp == ' ' || inp == '.' || inp == ',' || inp == '\n' || inp == '\0'){
            if(outp.size() > 2 && outp.size() < 7 && outp.size() != 0){
                if(i != 0) cout << ' ';
                for(it = outp.begin(); it != outp.end(); it++){
                    cout << *it;
                }
                i++;
            }
            outp.clear();
        }else{
            outp.push_back(inp);
        }
    }
    cout << endl;
}

Measured memory_bytes: 1200
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int a, b;
    for(int i = 1; i <= 100000; i++) {
        cin >> a >> b ;
        if(a == 0 && b == 0) {
            return 0;
        } else {
            cout << (a < b ? a : b) << " " << (a < b ? b : a) << endl;
        }
    }
}



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

int main() {
	long long int n, m, plan, now = 1, sum = 0, d[100001] = {}, D[100001] = {};
	cin >> n >> m;

	for(int i = 1; i < n; i++){
		cin >> d[i];
		D[i] = d[i] + D[i - 1];
	}
	
	for(int i = 0; i < m; i++){
		cin >> plan;
		if(plan > 0){
			sum += D[now + plan - 1] - D[now - 1];
		} else{
			sum += D[now - 1] - D[now + plan - 1];
		}
		
		now += plan;
	}
	
	cout << sum % 100000 << endl;
	
	return 0;
}

Measured memory_bytes: 2728
import java.util.Scanner;

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

	int n = scan.nextInt();
	int[] l = new int[n];
	int[] r = new int[n];
	for(int i = 0; i < n; i++){
	    l[i] = scan.nextInt();
	    r[i] = scan.nextInt();
	}

	int sum = 0;
	for(int i = 0; i < n; i++){
	    sum += r[i]-l[i]+1;
	}

	System.out.println(sum);
    }
}


Measured memory_bytes: 26120
from math import gcd
K = int(input())

ans = 0
for a in range(1, K + 1):
    ans += a
    for b in range(a + 1, K + 1):
        tmp = gcd(a, b)
        ans += tmp * 6
        for c in range(b + 1, K + 1):
            ans += gcd(tmp, c) * 6
print(ans)


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

int main(){
  string a, b, c;
  cin >> a >> b >> c;
  if (a.at(a.size() - 1) == b.at(0) && b.at(b.size() - 1) == c.at(0)) cout << "YES" << endl;
  else cout << "NO" << endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main () {

    

    int n; 
    cin >> n;

    int nums[n];
    for (int i = 0; i < n; i++) cin >> nums[i];

    int m;
    cin >> m;

    for (int i = 0; i < m; i++){

        int res = 0;

        int p, t;
        cin >> p >> t;

        for (int j = 0; j < n; j++){
            if (j + 1 == p){
                res += t;
            } else {
                res += nums[j];
            }
        }

        cout << res << endl;
    }



    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static final MyScanner in = new MyScanner();

	public static void main(String[] args) {

		long H = in.nextLong();
		long W = in.nextLong();

		if ( H == 1 || W == 1) {
			System.out.println(1);
			return;
		}

		long all = H * W;
		long answer = all % 2 == 0 ? all / 2 : all / 2 + 1;
		System.out.println(answer);
	}


	public static class MyScanner {
		Scanner sc = new Scanner(System.in);
		String next() { return sc.next();}
		int nextInt() { return Integer.valueOf(sc.next());}
		long nextLong() { return Long.valueOf(sc.next()); }
	}
}

Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
#define int long long
inline int read() {
	int x(0),neg(1);char ch(getchar());
	while(!isdigit(ch)) {
		if (ch=='-') neg=-1;
		ch=getchar();
	}
	while(isdigit(ch)) {
		x=(x<<1)+(x<<3)+(ch^48);
		ch=getchar();
	}
	return x*neg;
}
int vis[100005];
int n;
deque<pair<int,int> > q;
signed main() {
    n=read();
    q.push_front(make_pair(1,1));
    while(!q.empty()) {
        pair<int,int> p=q.front();
        q.pop_front();
        if(!vis[p.first]) {
            vis[p.first]=1;
            if(p.first==0) {
                printf("%lld\n",p.second);
                break;
            }
            q.push_front(make_pair((p.first*10)%n,p.second));
            q.push_back(make_pair((p.first+1)%n,p.second+1));
        }
    }
    return 0;
}

Measured memory_bytes: 2688
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using T = tuple<ll,int,int>;
const ll inf = numeric_limits<ll>::max()/3;
const ll mod = 1e9 + 7;

int main(void){
  int n;
  cin >> n;
  auto a = vector< ll >(n);
  auto calc = vector< ll >(n);
  for(int i = 0;i < n;++i){
    cin >> a[i];
  }
  calc[0] = 0;
  for(int i = 1;i < n;++i){
    calc[i] = a[i-1] - calc[i-1];
  }
  ll a0 = (a[n-1] - calc[n-1])/2;
  cout << a0 * 2;
  for(int i = 1;i < n;++i){
    if(i % 2 == 1){
      cout << " " << (calc[i] - a0) * 2;
    } else {
      cout << " " << (a0 + calc[i]) * 2; 
    }
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 2944
<?php
list($A, $B, $C) = sscanf(trim(fgets(STDIN)), "%d %d %d");
list($K) = sscanf(trim(fgets(STDIN)), "%d");
for ($i = 0; $i < $K; $i++) {
    if ($B <= $A) {
        $B *= 2;
    } else if ($C <= $B) {
        $C *= 2;
    } else {
        break;
    }
}
if (($A < $B) && ($B < $C)) {
    print("Yes");
} else {
    print("No");
}


Measured memory_bytes: 16160
#include<bits/stdc++.h>
using namespace std;
 
int main() {
	long long k,n,m;
	cin>>n>>m>>k;
	
	vector<long long> arr1(n+2,0);
	vector<long long> arr2(m+2,0);
	
	for(int i=1;i<=n;i++)
	{
	    cin>>arr1[i];
	    arr1[i]+=arr1[i-1];
	}
	
	for(int i=1;i<=m;i++)
	{
	    cin>>arr2[i];
	    arr2[i]+=arr2[i-1];
	}
	
	int j=m,ans=0;
	
	for(int i=0;i<=n;i++)
	{
	    if(arr1[i]>k)
	    break;
	    while(arr2[j]>(k-arr1[i]))
	    j--;
	    
	    ans=max(ans,(i+j));
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 6368
n = gets.to_i
a = gets.chomp.split
mul = 1
if a.include?("0")
    puts 0
else
    n.times do |i|
        mul *= a[i].to_i
        break if mul > 10 ** 18
    end
    puts mul > 10 ** 18 ? -1 : mul
end


Measured memory_bytes: 22636
#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef tuple<ll,ll,ll> T;
const long long INF = 1LL<<60;
const int MOD = 1000000000+7;
#define rev(s) (string((s).rbegin(), (s).rend()))
template < typename T > inline string toString( const T &a ) { ostringstream oss; oss << a; return oss.str(); };
// cout << fixed << setprecision(10) << ans << endl; 有効桁数指定
// *min_element(c + l, c + r) *max_element(c + l, c + r) 配列の中のmin-max
// int dx[8]={1,1,0,-1,-1,-1,0,1};
// int dy[8]={0,1,1,1,0,-1,-1,-1};
// int dx[4]={1,0,-1,0};
// int dy[4]={0,1,0,-1};
// ~ は、-1の時だけfalse
// struct Edge {
//   int to, id;
//   Edge(int a, int b): to(a), id(b) {}
// };

int a[310];

int num[4];

double dp[310][310][310];

int main(int argc, char const *argv[])
{
	int n;cin>>n;

	rep(i,n) {
		cin>>a[i];
		num[a[i]]++;
	}

	rep(i,n+1) {
		rep(j,n+1) {
			rep(k,n+1) {
				if (i>0||j>0||k>0) {
					dp[i][j][k]+=(double)n/(i+j+k);
					if (i>0) dp[i][j][k]+=dp[i-1][j+1][k]*i/(i+j+k);
					if (j>0) dp[i][j][k]+=dp[i][j-1][k+1]*j/(i+j+k);
					if (k>0) dp[i][j][k]+=dp[i][j][k-1]*k/(i+j+k);
				}
			}
		}
	}

	cout << fixed << setprecision(15) << dp[num[3]][num[2]][num[1]] << endl;


	return 0;
}

Measured memory_bytes: 227584
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <stack>
#include <string>
#include <unordered_set>
#include <vector>

using namespace std;
using LLONG = long long;
const LLONG MOD = 1000000007;

const LLONG Solve(const bool isOddPositive, int N, const vector<LLONG> &as)
{
    LLONG ret = 0;
    LLONG sum = 0;
    // i番目までの総和が期待した符号になっているかどうか判定
    // 期待した符号になっていない場合は，和が最低限（±1）になるまで
    // aiを増減すればよい：O(N)
    for (int i = 0; i < N; ++i)
    {
        sum += as[i];
        bool shouldIncrease = isOddPositive ?
            (i % 2 == 0 && sum <= 0) : (i % 2 == 1 && sum <= 0);
        bool shouldDecrease = isOddPositive ?
            (i % 2 == 1 && sum >= 0) : (i % 2 == 0 && sum >= 0);
        // 和が1になるまでaiを増やす
        if (shouldIncrease)
        {
            ret += 1 - sum;
            sum = 1;
        }
        // 和が-1になるまでaiを減らす
        if (shouldDecrease)
        {
            ret += sum - (-1);
            sum = -1;
        }
    }
    return ret;
}

int main()
{
    int N; cin >> N;
    vector<LLONG> as(N); for (auto &ai : as) cin >> ai;
    // 総和が正から始まる場合と，負から始まる場合をそれぞれ計算し
    // 変更回数が少ない方を選ぶ：O(N)
    auto ans = min(Solve(true, N, as), Solve(false, N, as));
    cout << ans << endl;
}


Measured memory_bytes: 1024
S = input()
O = ['R','U','D']
E = ['L','U','D']
flag = True
for i in range(len(S)):
  if i%2 == 0:
    if S[i] not in O:
      flag = False
      break
  else:
    if S[i] not in E:
      flag = False
      break
if flag:
  print('Yes')
else:
  print('No')

Measured memory_bytes: 3064
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <list>
#include <numeric>
#include <map>	
#include <cmath>
#include <string>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define Cout(s) cout<<s<<endl
using namespace std;
typedef long long ll;
string Yes(bool b) { if (b) { return "Yes"; } else { return "No"; } }
string YES(bool b) { if (b) { return "YES"; } else { return "NO"; } }
//================================================
int ketawa(int a) {
	if (a < 10)return a;
	else return a % 10 + ketawa(a / 10);
}

int a = 1, b = 0, c, d, n, k = 0, ans = 0;
string s, t;

int main()
{
	int n; cin >> n;
	vector<int> x(n); rep(i, n)cin >> x[i];
	double ans ;
	sort(all(x)); ans = x[0];
	rep(i, n - 1) {
		ans = (ans + x[i + 1]) / 2;
	}
	printf("%.5f\n", ans);

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,s,n) for(int i=(s); i<(n); i++)
#define all(v) v.begin(),v.end()
#define res(n) resize(n)
#define rev(v) reverse(v.begin(),v.end())
#define sor(v) sort(v.begin(),v.end())
#define outve(v) for(auto i : v) cout << i << " ";cout << endl
#define in(n,v) for(int i=0; i<(n); i++){cin >> v[i];}
#define out(n) cout << (n) << endl
#define fi first
#define se second
#define vector ve
#define priority_queue pq
using namespace std;
typedef long long ll;


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

    double ans = 0;

    ll a = 0;
    if (d == 0) a = n;
    else if(1+d <= n-d) a = 2*d + (n-2*d)*2;
    else a = (n+1-(1+d)) + (n-(n-d));

    //out(a);


    ans = (double(m)-1)/double(n)/double(n)*a;
    cout << fixed << setprecision(10);
    out(ans);

    return 0;
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PII;
typedef pair<ll , ll> PLL;
typedef long double ld;

#define pb push_back
#define all(c) c.begin(),c.end()
#define allr(c) c.rbegin(),c.rend()
#define mod 1000000007
#define PI 3.14159265
#define endl '\n'
#define MAX

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

    string str;
    cin >> str;
    ll ans = 0, c = 0;
    for (auto it : str) {
        if (it == 'W') {
            ans += c;
        }
        else {
            c++;
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 720
d,g = map(int,input().split())
p = [0]*d
c = [0]*d
for i in range(d): p[i],c[i] = map(int,input().split())
point = [i*100 for i in range(1,d+1)]
ans = float("inf")

for i in range(1<<d):
    score = 0
    cnt = 0
    for j in range(d):
        if i>>j & 1:
            cnt += p[j]
            score += point[j] * p[j] + c[j]
    if score >= g:
        ans = min(cnt,ans)
        continue
    for j in range(d)[::-1]:
        if i>>j & 1: continue
        x = min((g-score+point[j]-1)//point[j],p[j]-1)
        cnt += x
        score += point[j]*x
        if score >= g:
            ans = min(ans, cnt)
            break
print(ans)

Measured memory_bytes: 3064
/*
  Contest 069
  A - K-City
  Rakesh Kumar --> 01/09/2020
 */

#include <bits/stdc++.h>

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

    int n = 0, m = 0;
    std::cin >> n >> m;
    std::cout << (n - 1) * (m - 1) << std::endl;

    return 0;
}


Measured memory_bytes: 3608
def LCS():
    str1 = raw_input()
    str2 = raw_input()
    
    after = [0] * (len(str2) + 1)
    
    for i in xrange(1, len(str1) + 1):
        before = after + []
        for j in xrange(1, len(str2) + 1):
             if str1[i - 1] == str2[j - 1]:
                 after[j] = before[j - 1] + 1
             elif after[j - 1] > before[j]: #this is equal to 'max(after[j - 1], before[j])'
                 after[j] = after[j - 1]
    return after[j]

n = input()
for k in xrange(n):
    print LCS()

Measured memory_bytes: 6476
#include<bits/stdc++.h>
#define inf 1e15
#define ll long long int
#define mod 1000000007
using namespace std;
ll dp[500][500];
ll sum[500][500];
ll mincost(ll a[],ll i,ll j)
{
    if(i>=j)
        return 0;
    if(dp[i][j]!=-1)
        return dp[i][j];
    ll minc=inf;
    for(ll k=i;k<j;k++)
    {
        minc=min(minc,sum[i][j]+mincost(a,i,k)+mincost(a,k+1,j));
    }
    return dp[i][j]=minc;
}
int main()
{
    ll n;
    cin>>n;
    ll a[n+1];
    for(ll i=1;i<=n;i++)
    {
        cin>>a[i];
    }
    memset(dp,-1,sizeof(dp));
    for(ll i=1;i<=n;i++)
    {
        for(ll j=1;j<=n;j++)
        {
            if(i==j)
                sum[i][j]=a[i];
            else
                sum[i][j]=a[j]+sum[i][j-1];
        }
    }
    cout<<mincost(a,1,n)<<endl;
    return 0;
}


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

const int kN = 100 + 5;
int a[kN];

struct Dinic {
    struct Edge {
        int to; long long cap; int rev;
        Edge(int a, long long b, int c) : to(a), cap(b), rev(c) {}
    };

    vector<Edge> g[kN];
    int lev[kN], qu[kN], ql, qr;

    void AddEdge(int a, int b, long long c) {
        g[a].emplace_back(b, c, g[b].size() - 0);
        g[b].emplace_back(a, 0, g[a].size() - 1);
    }

    bool Bfs(int s, int t) {
        memset(lev, -1, sizeof(lev));
        ql = qr = 0;
        lev[qu[qr++] = s] = 0;
        while (ql < qr) {
            int x = qu[ql++];
            for (Edge &e : g[x]) {
                if (e.cap > 0 && lev[e.to] == -1) {
                    lev[e.to] = lev[x] + 1;
                    qu[qr++] = e.to;
                }
            }
        }
        return lev[t] != -1;
    }

    long long Dfs(int x, int t, long long flow) {
        if (x == t) return flow;
        long long res = 0;
        for (Edge &e : g[x]) {
            if (e.cap > 0 && lev[e.to] == lev[x] + 1) {
                long long fl = Dfs(e.to, t, min(flow - res, e.cap));
                e.cap -= fl;
                g[e.to][e.rev].cap += fl;
                res += fl;
            }
        }
        if (!res) lev[x] = -1;
        return res;
    }

    long long operator()(int s, int t) {
        long long res = 0;
        for (; Bfs(s, t); res += Dfs(s, t, 1e15));
        return res;
    }
} flow;

int main() {
    int n; scanf("%d", &n);
    for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
    long long res = 0;
    for (int i = 1; i <= n; ++i) {
        if (a[i] > 0) res += a[i];
        if (a[i] >= 0) flow.AddEdge(i, n + 1, a[i]);
        else flow.AddEdge(0, i, -a[i]);
        for (int j = i + i; j <= n; j += i) flow.AddEdge(i, j, 1e12);
    }
    printf("%lld\n", res - flow(0, n + 1));
    return 0;
}


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

class Program
{
    static void Main(string[] args)
    {
        var S = int.Parse(Console.ReadLine());
        
        var YY = S / 100;
        var MM = S % 100;
        
        if (YY > 12) {
            if (MM == 0) {
                Console.WriteLine("NA");
            } else if (MM > 12) {
                Console.WriteLine("NA");
            } else {
                Console.WriteLine("YYMM");
            }
        } else if (1 <= YY && YY <= 12) {
            if (MM == 0) {
                Console.WriteLine("MMYY");
            } else if (MM > 12) {
                Console.WriteLine("MMYY");
            } else {
                Console.WriteLine("AMBIGUOUS");
            }
        } else {
            if (MM == 0) {
                Console.WriteLine("NA");
            } else if (MM > 12) {
                Console.WriteLine("NA");
            } else {
                Console.WriteLine("YYMM");
            }
        }
    }
}


Measured memory_bytes: 11092
import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
public class Main
{
	public static void main (String[] args) throws java.lang.Exception
	{
	    Scanner sc=new Scanner(System.in);
	    int looplim=sc.nextInt();
	    for(int iter=0;iter<looplim;iter++)
	    {
	     
	        // your code goes here
	    System.out.print("ACL");
	        
	    }
	    
	}
}


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

using namespace std;

using int64 = long long;
const int mod = 998244353;

const int64 infll = (1LL << 60) - 1;
const int inf = (1 << 30) - 1;

struct IoSetup {
  IoSetup() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    cerr << fixed << setprecision(10);
  }
} iosetup;


template< typename T1, typename T2 >
ostream &operator<<(ostream &os, const pair< T1, T2 > &p) {
  os << p.first << " " << p.second;
  return os;
}

template< typename T1, typename T2 >
istream &operator>>(istream &is, pair< T1, T2 > &p) {
  is >> p.first >> p.second;
  return is;
}

template< typename T >
ostream &operator<<(ostream &os, const vector< T > &v) {
  for(int i = 0; i < (int) v.size(); i++) {
    os << v[i] << (i + 1 != v.size() ? " " : "");
  }
  return os;
}

template< typename T >
istream &operator>>(istream &is, vector< T > &v) {
  for(T &in : v) is >> in;
  return is;
}

template< typename T1, typename T2 >
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }

template< typename T1, typename T2 >
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

template< typename T = int64 >
vector< T > make_v(size_t a) {
  return vector< T >(a);
}

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

template< typename T, typename V >
typename enable_if< is_class< T >::value == 0 >::type fill_v(T &t, const V &v) {
  t = v;
}

template< typename T, typename V >
typename enable_if< is_class< T >::value != 0 >::type fill_v(T &t, const V &v) {
  for(auto &e : t) fill_v(e, v);
}

template< typename F >
struct FixPoint : F {
  FixPoint(F &&f) : F(forward< F >(f)) {}

  template< typename... Args >
  decltype(auto) operator()(Args &&... args) const {
    return F::operator()(*this, forward< Args >(args)...);
  }
};

template< typename F >
inline decltype(auto) MFP(F &&f) {
  return FixPoint< F >{forward< F >(f)};
}

int main() {
  int N, K;
  cin >> N >> K;
  vector< int > H(N);
  cin >> H;
  sort(H.rbegin(), H.rend());
  int64 ret = 0;
  for(int i = K; i < N; i++) {
    ret += H[i];
  }
  cout << ret << endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>

using namespace std;

int main(void) {
	int N;
	cin >> N;
	string str;
	cin >> str;
	for (int i = 0; i < str.length(); ++i) {
		if (str[i]+N > 'Z') {
			cout << (char)('A'+(str[i]+N-'Z'-1));	
		}
		else {
			cout << (char)(str[i]+N);
		}
	}
	cout << endl;
	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>

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;
#define int long long
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repr(i,n) for(ll i=n;i>=0;i--)
#define P pair<ll, ll>
#define sz(x) (ll)x.size()
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define VE vector<ll>
#define COUT(x) cout<<(x)<<endl
#define MA map<ll,ll>
#define SE set<ll>
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,VE,greater<ll>>
#define COUT(x) cout<<(x)<<endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define EPS (1e-10)
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
bool prime(ll n) {
	for (ll i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}


const long long MOD = 1000000007;
const long long INF = 1LL << 60;


const int MAX_N = 100010;
signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n, m; cin >> n >> m;
	VE a(n); rep(i, n)cin >> a[i];
	int ans = 0;
	sort(ALL(a));
	int l = 0; int r = 1000000000000;
	// にぶたんをしようね！！！！
	while (r - l > 1) {
		int mid = (l + r) / 2;
		int sum = 0;
		rep(i, n) {
			sum += a.end() - lower_bound(ALL(a), mid - a[i]);
		}
		if (sum >= m)l = mid;
		else r = mid;
	}
	int tmp = 0;
	// 累積和をしようね！！！！
	VE sum(n + 1); sum[0] = 0;
	rep(i, n)sum[i + 1] = sum[i] + a[i];
	rep(i, n) {
		// にぶたんをしようね！！！！
		int x = upper_bound(ALL(a), l - a[i]) - a.begin();
		ans += sum[n] - sum[x]; ans += a[i] * (n - x);
		tmp += n - x;
	}
	ans += l * (m - tmp);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1792
import java.util.*;
public class Main {
 public static void main(String[] args) {
 Scanner sc = new Scanner(System.in);

   String str = sc.next();
// System.out.print(str.charAt(1));  テスト

  if(str.charAt(2) == str.charAt(3) && str.charAt(4) == str.charAt(5)) {
       System.out.print("Yes");
} else {
      System.out.print("No");
}


}
}

Measured memory_bytes: 21716
import numpy as np
import heapq

# S = input()
# n = int(input())
# V = list(map(int, input().split()))

x,y,z,K = map(int, input().split())

li = [
    sorted(list(map(int, input().split()))),
    sorted(list(map(int, input().split()))),
    sorted(list(map(int, input().split()))),
]
cand = []

m = li[0][x-1] + li[1][y-1] + li[2][z-1]
heapq.heappush(cand, (-m, x-1, y-1, z-1))
memo = set()
res = 0

while res < K:
    m,i,j,k = heapq.heappop(cand)

    if (i,j,k) in memo:
        continue
    memo.add((i,j,k))
    print(-m)
    res += 1

    if i > 0:
        m = li[0][i-1] + li[1][j] + li[2][k]
        heapq.heappush(cand, (-m, i-1, j, k))
    if j > 0:
        m = li[0][i] + li[1][j-1] + li[2][k]
        heapq.heappush(cand, (-m, i, j-1, k))
    if k > 0:
        m = li[0][i] + li[1][j] + li[2][k-1]
        heapq.heappush(cand, (-m, i, j, k-1))
        


Measured memory_bytes: 20344
#4
#1 3 1 1
N = int(input())
ret = [int(_) for _ in input().split(" ")]

_min = 10**1000
for i in range(len(ret)):
  S1 = sum(ret[:i+1])
  S2 = sum(ret[i+1:])
  diff = abs(S1-S2)
  if _min > diff:
    index = i
    #print (S1, S2, i)
    _min = diff

print (_min)

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

#include <bits/stdc++.h>
#define mod 1000000007
#define INF 1001001001
#define ll long long
#define ln cout<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define double long double
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define rep1(i,n) REP(i,1,n+1)
using namespace std;

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

    ll a,b,c,m,n,maxi=0,f=0,mini=INF,sum=0;
    string str,sub;
    ll h,w;
    string str1;
    ll dp[230000];
    rep(i,220000) dp[i]=0;
    cin>>n;
    vector<ll> v(n+1);
    rep(i,n) cin>>v[i+1];
    v[0]=0;
    dp[0]=INF;
    dp[1]=0;
    v[0]=INF;
    for(ll i=2;i<=n;i++){
        dp[i]+=min(abs(v[i]-v[i-2])+dp[i-2],abs(v[i]-v[i-1])+dp[i-1]);
        //cout<<i<<" "<<dp[i]<<endl;
    } 
    cout<<dp[n]<<endl;


    return 0;
}


Measured memory_bytes: 2816
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <cmath>
#include <map>
#include <climits>
#include <cassert>
#include <algorithm>
#include <utility>

using namespace std;
using Int = long long int;
using UInt = unsigned long long int;
using VI = vector<long long int>;
using VVI = vector<vector<long long int> >;


int main(void) {
    char a;
    cin >> a;
    if (a >= 'A' && a <= 'Z') {
        cout << 'A' << endl;
    } else if (a >= 'a' && a <= 'z') {
        cout << 'a' << endl;
    }
    return 0;
}


Measured memory_bytes: 3556
#include <iostream>
#include <math.h>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <iomanip>
#include <string.h>

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

typedef long long lint;

using namespace std;

int main(){
  int A,B;
  cin>>A>>B;
  int ans=0;
  FOR(i,A,B+1){
    if((i/10000)%10==i%10 and (i/1000)%10==(i/10)%10)ans++;
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
import scala.math.{min,max}

object Main {
  val sc = new java.util.Scanner(System.in)
  def classify(h: Double) = h match {
    case x if x < 165 => 1
    case x if x < 170 => 2
    case x if x < 175 => 3
    case x if x < 180 => 4
    case x if x < 185 => 5
    case _ => 6
  }
  def main(args: Array[String]) {
    val n = sc.nextInt
    val hist = (1 to n).map(_ => sc.nextDouble).groupBy(classify).map(a => a._1 -> a._2.size)
    for(i <- 1 to 6) {
      println(i.toString + ":" + "*"*hist.getOrElse(i, 0))
    }
  }
}

Measured memory_bytes: 45900
# your code goes here
N,M = map(int,input().split())
 
S = input()
T = input()
 
def gcd(a, b):
	while b:
		a, b = b, a % b
	return a
 
if gcd(N,M) == 1:
	if S[0]==T[0]:
		print(N*M)
	else:
		print(-1)
else:
	tmp = gcd(N,M)
 
	ans = True
	for i in range(tmp):
		if S[N//tmp*i] != T[M//tmp*i]:
			ans = False
	if ans == True:
		print(N * M // tmp)
	else:
		print(-1)

Measured memory_bytes: 3316
X = int(input())
if 400<=X<=599:
  print(8)
elif 600<=X<=799:
  print(7)
elif 800<=X<=999:
  print(6)
elif 1000<=X<=1199:
  print(5)
elif 1200<=X<=1399:
  print(4)
elif 1400<=X<=1599:
  print(3)
elif 1600<=X<=1799:
  print(2)
else:
  print(1)

Measured memory_bytes: 9184
#include<iostream>
#include<math.h>
using namespace std;

#define ll long long int



int main ()
{
 ll n,t,i,k,sum=0;
 cin>>n;
 ll a[n],b[n],c[n];
 for(i=0;i<n;i++)
 {
     cin>>a[i];
 }
 for(i=0;i<n;i++)
 {
     cin>>b[i];

     sum+=b[i];
 }

 for(i=0;i<n-1;i++)
 {
     cin>>c[i];
 }
 for(i=1;i<n;i++)
 {
     if(a[i]==a[i-1]+1)
     {
         sum+=c[a[i-1]-1];
     }
 }
 cout<<sum;



return 0;
}


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

int main() {
  
  int N,A,B;
  cin >> N;
  
  B = N;

  while (N != 0) {
    A += N % 10;
    N = N / 10;
  }
 if (B % A == 0) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }

}

Measured memory_bytes: 3488
import java.util.*;

public class Main {

	public static long solve(final int n, final int k, int s, int g) {
		long ans = 0;
		if(s <= 0 && g >= n - 1)return 0;
		if(s == g) {
			ans = 1 + solve(n, k, s, g + k - 1);
			for(int i = 1; i < k; ++i) {
				long tmp = 1 + solve(n, k, s - i, g + k - i - 1);
				ans = Math.min(tmp,  ans);
			}
			return ans;
		}
		
		s += k - 2;
		g = n - 1 - g + k - 2;
		if(s < 0)s = 0;
		if(g < 0)g = 0;
		ans += (long)s / (long)(k - 1);
		ans += (long)g / (long)(k - 1);
		
		return ans;
	}
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt(), k = sc.nextInt();
		int a[] = new int[n];
		int p = 0;
		for(int i = 0; i < n; ++i) {
			a[i] = sc.nextInt();
			if(a[i] == 1)p = i;
		}
		sc.close();
		long ans = solve(n, k, p, p);
		System.out.println(ans);
	}

}


Measured memory_bytes: 50192
n=int(input())
h=list(map(int,input().split()))
dp=[0]*n
dp[0]=0
dp[1]=abs(h[1]-h[0])
for i in range(2,n):
    dp[i]=min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]))

print(dp[n-1])

Measured memory_bytes: 13980
#include <set>
#include <map>
#include <cmath>
#include <cstdio>
#include <vector>
#include <cstring>
#include <iostream>
#include <algorithm>

using namespace std;

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

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<pii> vpii;

template <class T>
void read(T &x)
{
	char ch;
	for (ch=getchar();(ch<'0'||ch>'9')&&ch!='-';) ch=getchar();
	x=0;int t=1;if (ch=='-') {ch=getchar();t=-1;}
	for (;ch>='0'&&ch<='9';ch=getchar()) x=x*10+ch-'0';
	x*=t;
}

int main()
{
	#ifndef ONLINE_JUDGE
		//freopen("input.txt","r",stdin);
		//freopen("output.txt","w",stdout);
	#endif
	ll n,a;
	cin>>n>>a;ll ans=n;
	for (int i=2;i<=40;i++)
	{
		int x=2;
		while (1)
		{
			ll t=1;
			for (int j=1;j<=i;j++)
			{
				t*=x;if (t>n) break;
			}
			if (t>n) break;x++;
		}
		ll t=1;
		for (int j=1;j<=i;j++) t*=(x-1);
		ll s=a*(i-1)+(x-1)*i;
		while (t<n)
		{
			s++;t=t/(x-1)*x;
		}
		ans=min(ans,s);
	}
	cout<<ans<<endl;
	return 0;
}



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

bool f(int n)
{
    bool f3, f5, f7;
    f3 = f5 = f7 = false;

    for (; n; n /= 10) {
        int t = n % 10;

        f3 |= (t == 3);
        f5 |= (t == 5);
        f7 |= (t == 7);

        if (t != 3 && t != 5 && t != 7) {
            return false;
        }
    }

    return (f3 && f5 && f7 ? true : false);
}
void g(int& n)
{
    string s = to_string(n);

    for (int i = 0; i < s.size() - 1; i++) {
        int t = s[i] - '0';

        if (t && t != 3 && t != 5 && t != 7) {
            n += stoi(string(s.size() - i - 1, '9'));
            return;
        }
    }

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

    int ans = 0;
    for (int i = 1; i <= n; i++) {
        //cerr << i << endl;
        ans += f(i);
        g(i);
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256