akhauriyash/Code-Regression huggingface dataset:
import sys
if sys.platform =='ios':
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline

N = [int(x) for x in input().rstrip()]
n = len(N)-1

for i in range(2**n):
	op = ['+'] * n
	for j in range(n):
		if (i>>j & 1) == 1:
			op[n-j-1] = '-'
	
	op.append('')
	formula = ""
	for num,o in zip(N, op):
		formula += str(num)+o
	if eval(formula) == 7:
		print("{}=7".format(formula))
		sys.exit()

Measured memory_bytes: 3064
// C - Bugged
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
#define all(x) (x).begin(),(x).end()
#define MAX 10000 // N*si = 100*100

int main(){
	int N; cin>>N;
	int maxi = 0;
	vi dp(MAX+1);
	for(int i=1; i<=N; ++i){
		int s; cin>>s;
		for(int j=MAX; j>=s; --j){
			dp[j] = max(dp[j], dp[j-s] + s);
			maxi = max(maxi, (dp[j]%10? dp[j]: 0));
		}
	}
	cout<< maxi <<endl;
}

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

typedef long long lli;

string C = "+-*";

int k;
string op[3];
string s;
lli pos, ans;

lli f1(), f2(), f3(), f4();

lli calc(lli a, lli b, char c) {
  if(c == '+') return a + b;
  if(c == '-') return a - b;
  if(c == '*') return a * b;
}

lli f1(lli d) {
  if(d == k) {
    lli x = 0;
    if(s[pos] == '(') {
      ++pos;
      x = f1(0);
      ++pos;
    } else {
      string num;
      while(isdigit(s[pos])) num += s[pos++];
      x = atoll(num.c_str());
    }
    return x;
  } else {
    lli x = f1(d + 1), i;
    while((i = op[d].find(s[pos])) != string::npos) {
      ++pos; x = calc(x, f1(d + 1), op[d][i]);
    }
    return x;
  }
}

void rec(lli j) {
  if(j == C.size()) {
    pos = 0;
    ++k;
    ans = max(ans, f1(0));
    --k;
    return;
  }
  op[k] += C[j];
  rec(j+1);
  op[k].erase(op[k].end()-1);
  if(op[k].size()) {
    ++k;
    op[k] += C[j];
    rec(j+1);
    op[k].erase(op[k].end()-1);
    --k;
  }
}

int main() {
  sort(C.begin(), C.end());
  while(cin >> s) {
    s += '$';
    ans = LLONG_MIN;
    k = 0;
    do {
      rec(0);
    } while(next_permutation(C.begin(), C.end()));
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 1224
/*
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
      //////////////////////////////////////////
	 \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

 Work hard in silence , let success make a noise!
	- The harder I work THE GREATER MY SUCCCESS -
	'''''''''''''''''''''''''''''''''''''''''
	|	XXX IOI 2018 - Tokyo Japan      |
	'''''''''''''''''''''''''''''''''''''''''
	 It's hard to beat a person who never gives up,
		 and this person can be you!

	  ///////////////////////////////////
       \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
||||||||||||||||||||||||||||||||||||||||||||||||||||||||


*/
#include <bits/stdc++.h>

#define fr first
#define sc second
#define mk make_pair
#define pb push_back
#define ll long long
#define in freopen(".in", "r", stdin)
#define out freopen(".out", "w", stdout)

using namespace std;

const long long INF = (long long)1e17 + 7;
const long long Ln = (long long)1e12 + 7;
const int N = (int)1e6 + 7;
const int sz = (int)1e5 + 7;
const double PI = 3.141592;
const int MX = (int)1e9 + 7;

inline int max(int a, int b)
{
 	if (a > b)return a;

	return b;
}
inline int min(int a, int b)
{
 	if (a < b)return a;

	return b;
}

int a[2001];
main()
{
    int n, x, y;
    int mx = -1;
    cin >> n >> x >> y;

    for (int i = 1; i <= n; i++){
        cin >> a[i];
    }

    mx = abs(y - a[n]);
    if (n == 1)
    {
        cout << mx;
        return 0;
    }
    cout << max(mx, abs(a[n] - a[n - 1]));
}




Measured memory_bytes: 256
from collections import deque

S = deque(list(input()))

f = False

for i in range(int(input())):
    q = input().split()
    
    if q[0] == '1': f = not f
    else:
        if not f:
            if q[1] == '1': S.appendleft(q[2])
            else: S.append(q[2])
        else:
            if q[1] == '1': S.append(q[2])
            else: S.appendleft(q[2])
        
if f: S.reverse()
print(''.join(map(str, list(S))))

Measured memory_bytes: 12388
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
/* **************************************************************************
//二分图匹配（匈牙利算法的dfs实现）
//初始化：g[][]两边顶点的划分情况
//建立g[i][j]表示i->j的有向边就可以了，是左边向右边的匹配
//g没有边相连则初始化为0
//uN是匹配左边的顶点数，vN是匹配右边的顶点数，要记得初始化
//调用：res=hungary();输出最大匹配数
//优点：适用于稠密图，DFS找增广路，实现简洁易于理解
//时间复杂度:O(VE)
//***************************************************************************/
//顶点编号从0开始的
const int maxn=510;
int uN,vN;//u,v数目
int g[maxn][maxn];
int a[maxn],b[maxn],c[maxn],d[maxn];
int link[maxn];
bool used[maxn];
bool dfs(int u){//从左边开始找增广路径
    int v;
    for(v=0;v<vN;v++)//这个顶点编号从0开始，若要从1开始需要修改
      if(g[u][v]&&!used[v])
      {
          used[v]=true;
          if(link[v]==-1||dfs(link[v]))
          {//找增广路，反向
              link[v]=u;
              return true;
          }
      }
    return false;
}
 
int hungary(){
    int res=0;
    int u;
    memset(link,-1,sizeof(link));
    for(u=0;u<uN;u++)
    {
        memset(used,0,sizeof(used));
        if(dfs(u)) res++;
    }
    return res;
}
int main(){
	int n;
	scanf("%d",&n);
	for(int i = 1;i<=n;i++){
		scanf("%d%d",&a[i],&b[i]);
	}
	for(int i = 1;i<=n;i++){
		scanf("%d%d",&c[i],&d[i]);
	}
	for(int i = 1;i<=n;i++){
		for(int j = 1;j<=n;j++){
			if(a[i]<c[j]&&b[i]<d[j]) g[i-1][j-1] = 1;
		}
	}
	uN = vN = n;
	int res = hungary();
	printf("%d\n",res);
	return 0;
} 

Measured memory_bytes: 512
import java.util.*;
public class Main {
	public static void main(String[] args){
      	//データ取り込み
		Scanner sc = new Scanner(System.in);
      	ArrayList<Integer> list = new ArrayList<Integer>();
      	
		int A = sc.nextInt();
      	int B = sc.nextInt();
      	int K = sc.nextInt();
        for(int i=1;i<A+1;i++){
        	if(A%i==0 &&B%i==0){
            	list.add(i);
            }
        }
       Collections.reverse(list);
      	
          System.out.println(list.get(K-1)); 
        
		     
      
    }
}

Measured memory_bytes: 23252
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, n) for(int i = 1; i <= (int)(n); i++)
const long long INF = 1LL << 60;
int main() 
{
    long long a, b, x,y;
    cin >> a >> b >> x;
	
  	y=(a-1)/x+1;
    if(a==0)
    	y=0;

    cout << b/x+1-y << endl;
}

Measured memory_bytes: 384
#include <iostream>

using namespace std;

int main(){
    int N, T;
    int c, t;
    cin >> N >> T;
    
    int min_c;
    min_c = 1001;
    
    for(int i=0;i<N;i++){
        cin >> c >> t;
        if(T>=t){
            if(min_c>c){
                min_c = c;
            }
        }
    }
        
    if(min_c == 1001)
        cout << "TLE" << endl;
    else
        cout << min_c << endl;
        
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define IOS ios_base::sync_with_stdio(false); cin.tie(0);
#define pb push_back
#define pf push_front
#define PI acos(-1)
#define EPS 1e-5
#define sz(v) ((int)(v).size())
#define all(v) v.begin(),v.end()
#define forn(i, n) for(ll i=0;i<(ll)n;i++)
#define fi first
#define se second
 

int main() {
	ll a, b;
	cin >> a >> b;
	ll r = a / __gcd(a, b) * b;
	cout << r << endl;
	return 0;
}



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

using namespace std;


// Bismilahir Rahmanir Rahim


typedef unsigned int ui;
typedef long long int lli;
typedef unsigned long long int ulli;
typedef short int si;
typedef unsigned short int usi;
typedef pair <int, int> pii;


#define CASE false
#define TEST false
#define BUFFER true
#define TIME false
#define DEBUG true
#define SET_GEN false
#define _ << " " <<
#define __ << "\n"
#define ff first
#define ss second
#define RANGE(a, b) (rand() % (b-a+1) + a)


const double pi = acos(-1.);
const double eps = 1e-7;
const int high = 2e9;
const int inf = 2147483647;
const int _inf = -2147483648;
const lli INF = 1e18;
const int mod = 1e9+7;


void delay(int sec); // DEBUG


void solution(void)
{	
	ulli n, w;
	
	cin >> n >> w;
	const int maxn = n*1000;
	const int nf = 1e9 +1;
	
	vector <ulli> dp(maxn+1, nf);
	dp[0] = 0;
	
	
	for(int i = 0; i < n; ++i) {
		ulli weight, val;
		cin >> weight >> val;
		
		for(int j = maxn-val; j >= 0; --j) {
			dp[j+val] = min(dp[j+val], dp[j] + weight);
		}	
	}
	
	int ans;
	
	for(int i = 0; i <= maxn; ++i) {
		if (dp[i] <= w) ans = i;
	}
	
	cout << ans __;
	

    return ;
}

int main(int argc, char *arv[])
{
    #if BUFFER
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    #endif

    #if SET_GEN
    srand((unsigned int) time(0));
    #endif

    int t = 1;

    #if CASE
    int cnt = 1;
    #endif

    #if TEST
    cin >> t;
    #endif

    #if TIME
    clock_t start_time, end_time;
    double time_elapsed;
    #endif


    while(t--) {

        #if TIME
        start_time = clock();
        #endif

        #if CASE
        cout << "Case " << cnt++ << ": ";
        #endif

        solution();

        #if TIME
        end_time = clock();

        time_elapsed = (double) (end_time - start_time) / CLOCKS_PER_SEC;

        cout << "\nRuntime: " << fixed << setprecision(7) << time_elapsed << "\n";
        #endif
    }


    return 0;
}

void delay(int sec)
{
    int mili_sec = 1000 * sec;

    clock_t start_time = clock();

    while (clock() < start_time + mili_sec);

    return ;
}


Measured memory_bytes: 3960
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String n = sc.next();
		String a = n.substring(n.length()-1);
		int num = Integer.parseInt(a);
		if(num==2||num==4||num==5||num==7||num==9) {
			System.out.println("hon");

		}
		else if(num==0||num==1||num==6||num==8) {
			System.out.println("pon");

		}
		else {
			System.out.println("bon");

		}

	}

}


Measured memory_bytes: 35804
#include <iostream>
#include <cstring>
#include <climits>
#include <vector>
#define int long long
using namespace std;
struct edge{int fr,to,co;};
const int INF=INT_MAX;
const int MAX_V=5000;
const int MAX_E=5000;
edge es[MAX_E];
vector <int> es2[MAX_V];
int v,e,d[MAX_V],f[MAX_V];

void dfs(int s){
  f[s]=1;
  for(int i=0;i<es2[s].size();i++) if(!f[es2[s][i]]) dfs(es2[s][i]);
}

void bellman(int s){
  fill(d,d+v,INF);
  d[s]=0;
  for(;;){
    bool u=0;
    for(int i=0;i<e;i++){
      edge e=es[i];
      if(d[e.fr]!=INF&&d[e.to]>d[e.fr]+e.co){
	d[e.to]=d[e.fr]+e.co;
	u=1;
      }
    }
    if(!u) break;
  }
}

bool bellman_f(){
  fill(d,d+MAX_V,0);
  for(int i=0;i<v;i++){
    for(int j=0;j<e;j++){
      edge e=es[j];
      if(d[e.to]>d[e.fr]+e.co){
	d[e.to]=d[e.fr]+e.co;
	if(i==v-1) return 1;
      }
    }
  }
  return 0;
}

signed main(){
  int r;
  cin>>v>>e>>r;
  for(int i=0;i<e;i++) cin>>es[i].fr>>es[i].to>>es[i].co,es2[es[i].fr].push_back(es[i].to);
  dfs(r);
  for(int i=0;i<e;i++) if(!f[es[i].fr]||!f[es[i].to]) es[i].fr=es[i].to=es[i].co=0;
  if(bellman_f()){
    cout<<"NEGATIVE CYCLE"<<endl;
    return 0;
  }
  bellman(r);
  for(int i=0;i<v;i++){
    if(d[i]==INF) cout<<"INF"<<endl;
    else cout<<d[i]<<endl;
  }
  return 0;
}

Measured memory_bytes: 3420
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
vector <int> c;
vector <int> a,b;

int main() {


  c.push_back(0);
  for(int i=1;c[i-1]<=1000010;i++) c.push_back(i*(i+1)*(i+2)/6);
   
  for(int i=0;i<=1000001;i++) {
    a.push_back(i);
    b.push_back(i);
  }
  
  for(int i=0;i<c.size();i++) {
    for(int j=1;j<=1000000;j++) {
      
      if(j-c[i] >=0) { 
     
	if(a[j-c[i]] >= 0) a[j] = min(a[j], a[j-c[i]]+1);

	if(c[i] % 2 == 1 && b[j-c[i]] >=0){
	  b[j] = min(b[j],b[j-c[i]]+1);
	}
      }
      
    }
  }

 while(1) {
    int m;
  cin >> m;
  if(m == 0) break;
  
  cout << a[m] <<" " << b[m] << endl;
  
  }
  return 0;
}

Measured memory_bytes: 9336
#include <cstdio>
#include <algorithm>

using namespace std;

int main() {
    int t1, t2;
    long long a1, a2, b1, b2;
    
    scanf("%d %d", &t1, &t2);
    scanf("%lld %lld %lld %lld", &a1, &a2, &b1, &b2);
    
    if (t1 * a1 + t2 * a2 == t1 * b1 + t2 * b2) {
        puts("infinity");
        
        return 0;
    }
    
    if (t1 * a1 + t2 * a2 < t1 * b1 + t2 * b2) {
        swap(a1, b1);
        swap(a2, b2);
    }
    
    if (a1 > b1) {
        puts("0");
    } else {
        long long c = t1 * a1 + t2 * a2 - t1 * b1 - t2 * b2;
        long long p = t1 * (b1 - a1);
        long long f = 0;
        
        if (p % c == 0) f = 1;
        
        printf("%lld\n", p / c * 2 + 1 - f);
    }
    
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define F first
#define S second

using namespace std;
typedef pair<int,int> P;

const int MOD=1000000007;
int INF=100100100100100;
P po[100010];
priority_queue<int> que; 
signed main(){
  int n,m;cin>>n>>m;
  rep(i,n){
    cin>>po[i].F>>po[i].S;
  }
  sort(po,po+n);
  int ima=0;
  int ans=0;
  for(int nok=1;nok<=m;nok++){
    while(ima<n && po[ima].F<=nok){
      que.push(po[ima].S);
      ima++;
    }
    if(!que.empty()){
      ans+=que.top();
      que.pop();
    }
  }
  cout<<ans<<endl;
    
  return 0;
}


Measured memory_bytes: 2936
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		char[] S = sc.next().toCharArray();
		sc.close();
		Arrays.sort(S);
		if(S[0] == S[3]) System.out.println("No");
		else if(S[0] == S[1] && S[2] == S[3]) System.out.println("Yes");
		else System.out.println("No");
	}
}

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

    int main()
    {
        int i,j;
        char S[27];
        scanf("%s",S);
        for(i = 0;S[i];i++)
        {
            for(j = i+1;S[j];j++)
            {
               if(S[i] == S[j])
               {
                printf("no\n");
                return 0;
                }
            }

        }
        printf("yes\n");
        return 0;

    }


Measured memory_bytes: 128
#include<iostream>
#include<cstdio>
#include<cmath>
#include<string>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<set>
#include<map>
using namespace std;
#define isNum(a) (a>='0'&&a<='9')
#define SP putchar (' ')
#define EL putchar ('\n')
#define inf 2147483647
#define File(a) freopen(a".in", "r", stdin), freopen(a".out", "w", stdout)
template<class T1>inline void read(T1&);
template<class T1>inline void write(T1);
int main () {
    int n, t, a;
    double mini=1e9;
    int ans=0;
    read(n);
    read(t);
    read(a);
    for (int i=1; i<=n; ++i) {
        int h;
        read(h);
        double now=t-h*0.006;
        if (abs(now-a)<abs(mini-a)) {
            mini=now;
            ans=i;
        }
    }
    write(ans);
    EL;
    return 0;
}
template<class T1>void read(T1 &r_e_a_d) {
    T1 k=0;
    char ch=getchar();
    int flag=1;
    while (!isNum(ch)) {
        if (ch=='-') {
            flag=-1;
        }
        ch=getchar();
    }
    while (isNum(ch)) {
        k=(k<<1)+(k<<3)+ch-'0';
        ch=getchar();
    }
    r_e_a_d = flag*k;
}
template<class T1>void write(T1 w_r_i_t_e) {
    if (w_r_i_t_e<0) {
        putchar('-');
        write(-w_r_i_t_e);
    }else {
        if (w_r_i_t_e<10) {
            putchar(w_r_i_t_e+'0');
        }else {
            write(w_r_i_t_e/10);
            putchar((w_r_i_t_e%10)+'0');
        }
    }
}


Measured memory_bytes: 256
#include<stdio.h>

int main(){
  long n = 0;
  char str[300000] = {};
  long i = 0;
  long letnum = 0;
  long height = 0;
  long highest = 0;
  long highi = 0;
  long cnt = 0;
  scanf("%ld",&n);
  scanf(" %s",str);
  for(i=0;i<n;i++){
    if(str[i] == 'W'){
      height--;
    }else if(str[i] == 'E'){
      height++;
    }
    if(height > highest){
      highest = height;
      highi = i;
    }
  }
  for(i=0;i<n;i++){
    if(i < highi && str[i] == 'W'){
      cnt++;
    }
    if(i > highi && str[i] == 'E'){
      cnt++;
    }
  }
  
  printf("%ld",cnt);
}
        
  

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

using namespace std;

int main(){
    int n,k,ans = 0;
    cin >> n >> k;
    vector<int>v(n);
    
    for(int i = 0;i < n;i++)
        cin >> v[i];
    
    sort(v.begin(),v.end(),greater<int>());

    for(int i = 0;i < k;i++)
        ans += v[i];
    
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include <cassert>
#include <random>

using namespace std;

typedef long long ll;
int K = 30;

//return first index(0 ~ N-1) which exceed thres. If not exist, return N
int search(ll *arr, int N, ll thres){
    int left = -1;
    int right = N;

    while (right - left > 1){
        int middle = (left + right) / 2;
        if (arr[middle] < thres){
           left = middle;
        } else {
            right = middle;
        }
    }
    assert (left == right - 1);
    return right;
}

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

    ll *a = new ll[N];
    ll *b = new ll[N];
    ll *aa = new ll[N];
    ll *bb = new ll[N];

    for (int i = 0; i < N; i++){
        cin >> a[i];
    }
    for (int i = 0; i < N; i++){
        cin >> b[i];
    }

    ll ret = 0;
    for (int k = 0; k < K; k++){
        ll base = 1 << (k+1);
        for (int i = 0; i < N; i++){
            aa[i] = a[i] % base;
            bb[i] = b[i] % base;
        }
        sort(aa, aa+N);
        sort(bb, bb+N);

        ll cnt = 0;
        for (int i = 0; i < N; i++){
            int x = search(bb, N, 1*(1<<k) - aa[i]);
            int y = search(bb, N, 2*(1<<k) - aa[i]);
            int z = search(bb, N, 3*(1<<k) - aa[i]);
            cnt += (y - x) + (N - z);
        }

        if (cnt % 2 == 1){
            ret += (1<<k);
        }
    }
    cout << ret << endl;

    return 0;
}

Measured memory_bytes: 6528
N = int(input())
A = []
for i in range(N):
    A.append(int(input()))

max_num = max(A)
A_bk = A[:]
if (A.count(max_num)>=2):
    for i in range(N):
        print(max_num)
else:
    for i in range(N):
        if (A[i] != max_num):
            print(max_num)
        else:
            A_bk.remove(max_num)
            print(max(A_bk))

Measured memory_bytes: 14080
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
using namespace std;
int main(){
  int n,y,b,r,t,no;
  double ans,max;
  while(1){
    cin >> n;
    if(n==0)break;
    cin >> y;
    max=0;
    for(int i=0;i<n;i++){
      cin >> b >> r >> t;
      if(t==2){
	ans = pow(1.0+(double)r/100.0,y);
      }else{
	ans = 1.0 + y*(double)r/100.0;
      }
      if(max<ans)max=ans,no=b;
    }
    cout << no <<endl;
  }
}

Measured memory_bytes: 1164
import java.util.Scanner;

public class Main {
    public static void main(final String args[]) {
        Scanner scanner = new Scanner(System.in);
        final int rows = scanner.nextInt();
        final int columns = scanner.nextInt();
        final int targetBlack = scanner.nextInt();
        for (int rowPushes = 0; rowPushes <= rows; rowPushes++) {
            for (int columnPushes = 0; columnPushes <= columns; columnPushes++) {
                int black = rowPushes * columns + columnPushes * rows - 2 * rowPushes * columnPushes;
                if (black == targetBlack) {
                    System.out.println("Yes");
                    System.exit(0);
                }
            }
        }
        System.out.println("No");
    }
}

Measured memory_bytes: 25556
import copy

N, M, X = map(int, input().split())

Clist = []

for i in range(N):
    Clist.append(list(map(int, input().split())))

anslist = []


def dfs(index, tmplist):
    if index >= N:
        anslist.append(copy.copy(tmplist))
        return

    s = list(tmplist)

    for i in range(M+1):
        s[i] += Clist[index][i]

    dfs(index+1, s)
    dfs(index+1, tmplist)


dfs(0, [0]*(M+1))

ans = -1

for al in anslist:
    flg = True
    for a in range(1, M+1):
        if al[a] < X:
            flg = False

    if flg:
        if ans == -1:
            ans = al[0]
        else:
            ans = min(ans, al[0])


print(ans)


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

using ll = long long;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define ddrep(i, n) for (int i = n; i > 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define ssrep(i, s, t) for (int i = s; i <= t; ++i)

#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))

using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
    os << "(" << p.first << "," << p.second << ")";
    return os;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
    os << "{";
    rep(i, (int)v.size()) {
        if (i)
            os << ",";
        os << v[i];
    }
    os << "}";
    return os;
}

template <typename T, size_t S> void printArray(const T (&array)[S]) {
    for (auto val : array)
        std::cout << val << ", ";
    std::cout << "\n";
}

const int mod = 1e9 + 7;
const int inf = 1e9 + 5;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << std::setprecision(10);

    int a, b, c, k; std::cin >> a >> b >> c >> k;
    int ans = 0;
    if (k > 0 && a > k) ans += k, k = 0;
    else if (k > 0) k -= a, ans += a;
    if (k > 0 && b > k) k = 0;
    else if (k > 0) k -= b;
    if (k > 0 && c > k) ans -= k, k = 0;
    else if (k > 0) ans -= c, k -= c;
    std::cout << ans << "\n";
}


Measured memory_bytes: 3652
//#include "bits/stdc++.h"

#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>
#include<iomanip>
#include<unordered_set>
#include<bitset>
#include<complex>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

//typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;
typedef vector< vector<int> > mat;

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

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD =  (int)1e9 + 7;
const double EPS = 1e-9;

signed main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	string S;
	int l = 0, r = 0;
	cin >> S;

	rep(i, 0, SZ(S))
	{
		if (i % 2 == 0&&S[i]=='p')
		{
			l++;
		}
		if (i % 2 == 1 && S[i] == 'g')
		{
			r++;
		}
	}

	cout << r - l << endl;

	return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
#ifdef _DEBUG_
#define dump(val) cerr << __LINE__ << ":\t" << #val << " = " << (val) << endl
#else
#define dump(val)
#endif

using namespace std;

typedef long long int ll;

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

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n, x;
    cin >> n >> x;
    int ans = 1;
    int d = 0;
    REP(i, 0, n) {
        int a;
        cin >> a;
        d += a;
        if (d <= x) {
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
import sys
import itertools

def can_be_composed(n, min_list, max_list, m, A):
	for i in range(1, n + 1):
		if m < min_list[i - 1]:
			continue
		if m > max_list[i - 1]:
			continue

		combination_list = list(itertools.combinations(A, i))
		for l in combination_list:
			if m == sum(l):
				return True

	return False

#fin = open("test.txt", "r")
fin = sys.stdin

n = int(fin.readline())
A = list(map(int, fin.readline().split()))
A.sort()
q = int(fin.readline())
m_list = list(map(int, fin.readline().split()))

min_list = [0]
min_list[0] += A[0]
for i in range(1, n):
	min_list.append(min_list[i - 1] + A[i])

max_list = [0]
max_list[0] += A[n - 1]
for i in range(1, n):
	max_list.append(max_list[i - 1] + A[n - i - 1])

for m in m_list:
	if can_be_composed(n, min_list, max_list, m, A):
		print("yes")
	else:
		print("no")

Measured memory_bytes: 60572
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long ll;
ll strtoint(string str);
int main(){
	fast;
	ll n,s=0; cin>>n;
	s+=(n/500)*1000;
	n%=500;
	s+=(n/5)*5;
	cout<<s<<'\n';
	return 0;
}
ll strtoint(string str){
	ll x=0;
	stringstream ss;
	ss<<str;
	ss>>x;
	return x;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        // TODO code application logic here
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int d = sc.nextInt();
        System.out.println(a*b-(b*c+a*d-c*d));
    }

}


Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll ZERO = 0;
const int Inf = 1000000000;
const ll INF= 1e18;
const ll MOD = 1000000007;
const double PI = 3.1415926535897;
typedef pair<ll,ll> P;

int main() {
    int K,T;
    cin >> K >> T;
    vector<int> vec(T);
    for(int i = 0;i < T;i++) {
        cin >> vec.at(i);
    }
    sort(vec.begin(),vec.end());
    cout << max(0,vec.at(T - 1) - (K - vec.at(T - 1)) - 1) << endl;
}

Measured memory_bytes: 256
#include<stdio.h>

#define N 1000000

int a[N], G[N], count = 0, m = 1;

void insertionSort(int n, int g){
  int i, j, v;
  for(i = g ; i < n ; i++){
    v = a[i];
    j = i - g;

    while(j >= 0 && a[j] > v){
      a[j + g] = a[j];
      j = j - g;
      count++;
    }
    a[j + g] = v;
  }
}


void shellSort(int n){
  int i, h = n;
  G[0] = 1;

  while(1){
    G[m] = G[m - 1]*3 + 1;
    if(G[m] > n) break;
    m++;
  }

  for(i = m - 1 ; i >= 0 ; i--){
    insertionSort(n, G[i]);
  }
}


int main(){
  int i, n;

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

  shellSort(n);

  printf("%d\n", m);
  for(i = m - 1 ; i > 0 ; i--) printf("%d ", G[i]);

  printf("%d\n", G[0]);

  printf("%d\n", count);

  for(i = 0 ; i < n ; i++) printf("%d\n", a[i]);

  return 0;
}


Measured memory_bytes: 5652
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <list>
#include <ctime>
#include <sstream>
#include <queue>
#include <stack>
#include <random>
#include <bitset>
#include <numeric>
#include <cassert>
using namespace std;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long long ll;
#define rep(x, b, e) for(int x=(b); x<(e); ++x)
#define ford(x, b, e) for(int x=((int)(b))-1; x>=(e); --x)
#define all(c) c.begin(),c.end()
#define sz(x) ((int)((x).size()))
#define pb push_back
#define st first
#define nd second
#define mp(x,y) make_pair(x,y)
typedef short int sint;

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it) {
	*this << ((it != d.b) ? ", " : "") << *it;
  }
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

int main() {
	ios_base::sync_with_stdio(false);

	int a, b;
	cin >> a >> b;
	cout << a *b << endl;
	
}

Measured memory_bytes: 3652
import java.util.Scanner;

import javax.sql.rowset.serial.SerialArray;

public class Main {

		public static void main(String[] args){
			
			Scanner sc = new Scanner(System.in);
			// 整数の入力
			// スペース区切りの整数の入力
			String str = sc.next();
			String[] strArray = str.split("");

			int cnt = 0;
			for (int i = 0; i < strArray.length; i++) {
//				for (int j = i + 1; j < strArray.length; j++) {
				    // 1文字ずつ表示
			        if (strArray[i].toString().equals("+")){
					    cnt++;
			        }else{
			        	cnt--;
			        }
//				}
			}
		    System.out.println(cnt);
    	    return;
			

		}
}


Measured memory_bytes: 21716
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <set>
using namespace std;

int main()
{
    int N;
    cin >> N;
    set<int> s;
    for (int i = 0; i < N; i++)
    {
        int x;
        cin >> x;
        if (s.count(x) > 0)
        {
            cout << "NO" << endl;
            return 0;
        }
        s.insert(x);
    }
    cout << "YES" << endl;
}

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

typedef long long ll;
typedef long double lld;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef set<int> si;
typedef map<string, int> msi;
typedef pair<ll, ll> pll;
typedef pair<ll, pair<ll, ll>> plll;

void solve()
{
  ll n;
  cin >> n;
  string s;
  cin >> s;
  ll r = 0, w = 0;
  for (int i = 0; i < n; i++)
  {
    if (s[i] == 'R')
      r++;
    if (s[i] == 'W')
      w++;
  }
  ll ans = 0;
  for (int i = 0; i < r; i++)
  {
    if (s[i] == 'W')
      ans++;
  }
  cout << ans << endl;
  return;
}
int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);

  // int t;
  // cin >> t;
  // for (int i = 0; i < t; i++)
  // {
  //   solve();
  // }
  solve();
}

Measured memory_bytes: 3720
A, B, C, X, Y = map(int, input().split())

ans = 0
if A + B >= C * 2:
  if X < Y:
    ans = X * C * 2
    if B < C * 2:
      ans += (Y - X) * B
    else:
      ans += (Y - X) * C * 2
  else:
    ans = Y * C * 2
    if A < C * 2:
      ans += (X - Y) * A
    else:
      ans += (X - Y) * C * 2
else:
  ans = A * X + B * Y

print(ans)

Measured memory_bytes: 3064
#include <stdio.h>

int main(void)
{
	int i;
	int count = 0;
	char s[4], t[4];

	scanf("%s", s);
	scanf("%s", t);

	//天気予報と一致した天気をカウントする
	for (i = 0; i < 3; i++) {
		if (s[i] == t[i]) {
			count++;
		}
	}

	printf("%d\n", count);

	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <queue>
#include <vector>
#include <bitset>
#include <string>
#include <cmath>
#include <set>
#include <deque>
#define Rep(i, x, y) for (int i = x; i <= y; i ++)
#define Dwn(i, x, y) for (int i = x; i >= y; i --)
#define RepE(i, x) for (int i = pos[x]; i; i = g[i].nex)
#define ev g[i].y
#define eps 1e-10
#define pb push_back
#define pf push_front
using namespace std;
typedef long long ll;
typedef double db;
const int N = 100005, mod = 1000000007;
ll n;
int m;
deque<int> a, b;
void work(ll x) {
	if (x == 1) return ;
	work(x / 2);
	++ m;
	a.pb(m), b.pb(m);
	if (x & 1) {
		++ m;
		a.pb(m), b.pf(m);
	}
}
int main()
{
	scanf ("%lld", &n);
	work(n + 1);
	printf("%d\n", m * 2);
	Rep(i, 0, m - 1) printf("%d ", a[i]);
	Rep(i, 0, m - 1) printf("%d ", b[i]);

	return 0;
}

Measured memory_bytes: 256
from collections import deque


def submit():
    n, a, b, c = map(int, input().split())
    llist = [int(input()) for _ in range(n)]

    def update(st, h):
        return st[0] + h, st[1] + 1

    def cost(st, goal):
        return (st[1] - 1) * 10 + abs(goal - st[0])

    def rec_search(ast, bst, cst, rest):
        # 処理し終わった
        if not rest:
            if ast[1] == 0 or bst[1] == 0 or cst[0] == 0:
                return float('inf')
            else:
                return cost(ast, a) + cost(bst, b) + cost(cst, c)
        else:
            head = rest[0]
            rest = rest[1:]

            # headをAに使う
            acost = rec_search(update(ast, head), bst, cst, rest)
            # headをBに使う
            bcost = rec_search(ast, update(bst, head), cst, rest)
            # headをCに使う
            ccost = rec_search(ast, bst, update(cst, head), rest)
            # headを使わない
            ncost = rec_search(ast, bst, cst, rest)

            return min(acost, bcost, ccost, ncost)


    # それぞれl合計、個数を保存
    ast = (0, 0)
    bst = (0, 0)
    cst = (0, 0)
    
    cost = rec_search(ast, bst, cst, llist)
    print(cost)


if __name__ == "__main__":
    submit()

Measured memory_bytes: 49624
import sys
sys.setrecursionlimit(10 ** 9)
# input = sys.stdin.readline    ####
def int1(x): return int(x) - 1
def II(): return int(input())
def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())
def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def MS(): return input().split()
def LS(): return list(input())
def LLS(rows_number): return [LS() for _ in range(rows_number)]
def printlist(lst, k=' '): print(k.join(list(map(str, lst))))
INF = float('inf')
# from math import ceil, floor, log2
# from collections import deque
# from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product, permutations
# from heapq import heapify, heappop, heappush
# import numpy as np
# from numpy import cumsum  # accumulate
from fractions import gcd
# from math import gcd
def lcm(x, y):
  return x // gcd(x, y) * y

def solve():
    a, b = MI()
    print(lcm(a, b))

if __name__ == '__main__':
    solve()


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

#define INF 1e9
#define MAX 100005
#define xx first
#define yy second
#define pb push_back
#define mp make_pair
#define ull long long
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define nl '\n'
#define zai <<' '<<
#define all(a) a.begin(),a.end()
#define pc __builtin_popcount
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;

int main(){
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	int a,b;
	cin >> a >> b;
	if(a>=13)cout << b;
	else if(a>=6 && a<=12)cout << b/2;
	else if(a<=5)cout << 0;
	return 0;
}

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

int main()
{
	int a, b, c;
	cin >> a >> b >> c;
	if (a <= b)
	{

		if (a <= c)
		{
			if (b <= c)
			{
				cout << a << " " << b << " " << c << endl;
			}
			else
			{
				cout << a << " "  << c << " " << b << endl;
			}
		}
		else
		{
			cout << c << " " << a << " " << b << endl;
		}
		
	}
	else if (b <= c)
	{

		if (c <= a)
		{
			cout << b << " " << c << " " << a << endl;
		}
		else
		{
			cout << b << " " << a << " " << c << endl;
		}
	}
	else
	{
		cout << c << " " << b << " " << a << endl;
	}


	return 0;
}


Measured memory_bytes: 3104
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=3010;
const ll INF=1e18;
int a[N];
ll dp[N][N][2];
int read()
{
	int x=0,f=1;char ch=getchar();
	while (ch<'0'||ch>'9') {if (ch=='-') f=-1;ch=getchar();}
	while (ch>='0'&&ch<='9') x=(x<<1)+(x<<3)+(ch&15),ch=getchar();
	return x*f;
}
int main()
{
	int n=read();
	for (register int i=1;i<=n;++i) a[i]=read();
	for (register int i=1;i<=n;++i) dp[i][i][0]=a[i],dp[i][i][1]=-a[i];
	for (register int i=n;i>=1;--i)
	  for (register int j=i+1;j<=n;++j)
	  {
	  	  dp[i][j][0]=max(dp[i+1][j][1]+a[i],dp[i][j-1][1]+a[j]);
	  	  dp[i][j][1]=min(dp[i+1][j][0]-a[i],dp[i][j-1][0]-a[j]);
	  }
	printf("%lld\n",dp[1][n][0]);
	return 0;
}

Measured memory_bytes: 141568
import java.util.Scanner;
//import java.util.Arrays;
public class Main {
	public static void main(String[] args) throws java.io.IOException {
		Scanner scan = new Scanner(System.in);
		int n;
		int cun = 0;
		
		while(scan.hasNext()){
			n = scan.nextInt();
			if(n == 0){
				break;
			}
			while(n != 1){
				if(n % 2 == 0){
					n = n/2;
					++cun;
				}else{
					n = n*3 + 1;
					++cun;
				}
			}
			System.out.println(cun);
			cun = 0;
		}
	}
}

Measured memory_bytes: 26024
W, H, N = map(int, input().split())
w = h = 0
for i in range(N):
    x, y, a = map(int, input().split())
    if a == 1:
        w = max(w, x)
    elif a == 2:
        W = min(W, x)
    elif a == 3:
        h = max(h, y)
    else:
        H = min(H, y)
print(max(0, (W - w)) * max(0, (H - h)))



Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
   ll int a,b,k;
   cin>>a>>b>>k;
   if(a+b>k)
   {
     ll int z=a-k;
       if(z>=0)
        cout<<z<<" "<<b<<endl;
       else
       {
           ll int z1=(a+b)-k;
           cout<<"0"<<" "<<z1<<endl;
       }

   }
   else
    cout<<"0"<<" "<<"0"<<endl;




    return 0;
}


Measured memory_bytes: 256
import java.io.*;
import java.util.*;

public class Main {

	final static long MOD = 1000000007;
	public static String[] Ws = null;
	public static int wsIndx = 0;
	public static BufferedReader in = null;
	public static void main(String[] args) throws Exception {
		solution(args);
		if(in!=null){
			in.close();
		}
	}

	public static void solution(String[] args) throws Exception{

		int A =nextInt();
		int B =nextInt();
		int C =nextInt();
		int D =nextInt();

		String ans ="Balanced";
		if(A+B>C+D){
			ans="Left";
		}
		if(A+B<C+D){
			ans="Right";
		}

		System.out.println(ans);

	}
	public static String[] toStringArray(String s) {
		String[] tmp = new String[s.length()];
		char[] c = s.toCharArray();
		for (int i = 0; i < tmp.length; i++) {
			tmp[i] = String.valueOf(c[i]);
		}
		return tmp;
	}

	public static void check() throws Exception{
		if(in == null){
			in = new BufferedReader(new InputStreamReader(System.in));
		}
		if(Ws==null || Ws.length<=wsIndx){
			Ws = in.readLine().split(" ");
			wsIndx=0;
		}
	}
	public static int nextInt()throws Exception{
		check();
		return Integer.parseInt(Ws[wsIndx++]);
	}

	public static long nextLong()throws Exception{
		check();
		return Long.parseLong(Ws[wsIndx++]);
	}

	public static String nextString()throws Exception{
		check();
		return Ws[wsIndx++];
	}

	public static int[] nextInts()throws Exception{
		check();
		int[] tmp = new int[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Integer.parseInt(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static long[] nextLongs()throws Exception{
		check();
		long[] tmp = new long[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Long.parseLong(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static String[] nextStrings()throws Exception{
		check();
		wsIndx=Ws.length;
		return Ws;
	}


}


Measured memory_bytes: 21204
#include"bits/stdc++.h"
using namespace std;
using ll=long long;
template<typename T=ll>inline T in(istream&is=cin){T ret;is>>ret;return ret;}
template<typename T>inline auto vec2(typename vector<T>::size_type h,typename vector<T>::size_type w,T v=T()){return vector<vector<T>>(h,vector<T>(w,v));}

constexpr auto mod=static_cast<ll>(1e9+7);
ll mypow(ll x, ll y)
{
    return y==0?1:y%2==0?mypow(x%mod*x%mod,y/2):x%mod*mypow(x%mod,y-1)%mod;
}
int main()
{
    ll n=in(),k=in();
    ll ans=0;
    vector<ll>p(k+1);
    for(int g=k;g>=1;--g){
        ll foo=mypow(k/g,n);
        for(ll i=g*2;i<=k;i+=g)foo=(mod+foo-p[i])%mod;
        ans+=(p[g]=foo)*g;
        ans%=mod;
    }
    cout<<ans<<endl;
}


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

int chmin(int a,int b){
  //b:answer_min
  if(a < b){
    b = a;
  }
  return b;
}

int main(){
  int n;
  scanf("%d",&n);
  int h[n],dp[n];
  for(int i=0; i<n; i++){
    scanf("%d",&h[i]);
    dp[i] = 1 << 25;
  }
  dp[0] = 0;
  dp[1] = abs(h[1]-h[0]); 
  
  for(int i=2; i<n; i++){
    dp[i] = chmin(dp[i-1] + abs(h[i] - h[i-1]), dp[i-2] + abs(h[i] - h[i-2]));
  }
  
  printf("%d", dp[n-1]);
  
  return 0;
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define whole(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
using P = pair<int, int>;
#define debug(var) cerr << "[" << #var << "] " << var << endl
#define chmin(x, y) x = min(x, y)
const ll mod = 1000000007;
const int dx[] = {-1,0,1,0};
const int dy[] = {0,-1,0,1};


int main(){
    int n, k;
    cin >> n >> k;
    string s;
    cin >> s;
    vector<P> v;
    
    P now;
    rep(i, n) {
        if (i==0) {
            if (s[i]=='1') now.first = -1;
            else v.emplace_back(-1, -1);
        }
        if (i>0 && s[i]=='1' && s[i-1]=='0') now.first = i;
        if (i<n-1 && s[i]=='1' && s[i+1]=='0') {
            now.second = i;
            v.push_back(now);
        }
        if (i==n-1) {
            if (s[i]=='1') {
                now.second = n;
                v.push_back(now);
            }
            else {
                v.emplace_back(n, n);
            }
        }
    }
    
    if (k>=v.size()-1) {
        cout << n << endl;
        return 0;
    }
    int l = 0;
    int r = k;
    int ans = 0;
    while (r<=v.size()-1) {
        int res = v[r].second - v[l].first + 1;
        if (v[r].second==n) res--;
        if (v[l].first==-1) res--;
        ans = max(res, ans);
        l++; r++;
    }
    


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


Measured memory_bytes: 1020
#include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <vector>

const int MOD = 1e9 + 7;
const int iINF = 2147483647 / 2;
const long long int llINF = 9223372036854775807 / 2;

using namespace std;
using ll = long long int;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vvvl = vector<vector<vector<ll>>>;

typedef pair<ll, ll> pll;
bool paircomp(const pll &a, const pll &b) {
  if (a.first == b.first)
    return a.second < b.second;
  return a.first < b.first;
}

#define REP(i, n) for (ll i = 0; i < (n); i++)
#define RREP(i, n) for (ll i = (n)-1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define AUTO(i, m) for (auto &i : m)
#define ALL(a) (a).begin(), (a).end()
#define MAX(vec) *std::max_element(vec.begin(), vec.end())
#define MIN(vec) *std::min_element(vec.begin(), vec.end())
#define ARGMAX(vec)                                                            \
  std::distance(vec.begin(), std::max_element(vec.begin(), vec.end()))
#define ARGMIN(vec)                                                            \
  std::distance(vec.begin(), std::min_element(vec.begin(), vec.end()))
#define REV(T) greater<T>()
#define PQ(T) priority_queue<T, vector<T>, greater<T>>
#define VVL(a, b, c) vector<vector<ll>>(a, vector<ll>(b, c))
#define VV(T, a, b, c) vector<vector<T>>(a, vector<T>(b, c))
#define VVVL(a, b, c, d)                                                       \
  vector<vector<vector<ll>>>(a, vector<vector<ll>>(b, vector<ll>(c, d)))
#define VVV(T, a, b, c, d)                                                     \
  vector<vector<vector<T>>>(a, vector<vector<T>>(b, vector<T>(c, d)))
#define SP(a) setprecision(a)
#define SQRT(a) sqrt((long double)(a))
#define DPOW(a, b) pow((long double)(a), (long double)(b))
#define UNIQUE(vec)                                                            \
  do {                                                                         \
    sort(ALL((vec)));                                                          \
    (vec).erase(std::unique(ALL((vec))), (vec).end());                         \
  } while (0)

ll POW(ll n, ll m) {
  if (m == 0) {
    return 1;
  } else if (m % 2 == 0) {
    ll tmp = POW(n, m / 2);
    return (tmp * tmp);
  } else {
    return (n * POW(n, m - 1));
  }
}

int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll H, A;
  cin >> H >> A;
  if (H % A == 0)
    cout << (H / A) << endl;
  else
    cout << 1 + (H / A) << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int N=110;
int n,m,a[N],b[N],cnt;
int main(){
    scanf("%d%d",&m,&n);
    for(int i=1;i<=n;i++){
        scanf("%d",&a[i]);
        if(a[i]&1)cnt++;
    }
    if(cnt>2){puts("Impossible");return 0;}
    int flag=0;
    for(int i=1;i<=n;i++){
        if(a[i]&1){
            if(flag)swap(a[i],a[n]);
            else swap(a[i],a[1]),flag=1;
        }
    }
    for(int i=1;i<=n;i++)printf("%d%c",a[i]," \n"[i==n]);
    if(n==1){
    	if(a[1]==1){
    		printf("%d\n%d\n",1,1);
    		return 0;
    	}
    	printf("%d\n",2);
    	printf("%d %d\n",a[1]-1,1);
    	return 0;
    }
    b[1]=a[1]+1;
    for(int i=2;i<=n;i++)b[i]=a[i];
    b[n]--;
    if(b[n])printf("%d\n",n);
    else printf("%d\n",n-1);
	if(!b[n])n--;
    for(int i=1;i<=n;i++)printf("%d%c",b[i]," \n"[i==n]);
    return 0;
}

Measured memory_bytes: 256
x=int(input())
def f(a,p):
    return 5*a**4+10*(a**3)*p+10*(a**2)*(p**2)+5*a*(p**3)+p**4
for i in range(1,x+1):
    if i*i>x:
        break
    if x%i==0:
        p=i;q=x//i
        if p**4%5==q%5:
            for b in range(-1000,1000):
                if f(b,p)==q:
                    print(b+p,b)
                    exit(0)
        p=-1*i;q=(-1)*(x//i)

        for b in range(-1000,1000):
            if f(b,p)==q:
                print(b,b+p)
                exit(0)
        


Measured memory_bytes: 67752
#include <bits/stdc++.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++)
using ll = long long;
using VL = vector<ll>;
using VVL = vector<vector<ll>>;
using P = pair<ll, ll>;

// chmin, chmax関数
template<typename T, typename U, typename Comp=less<>>
bool chmax(T& xmax, const U& x, Comp comp={}) {
    if(comp(xmax, x)) {
        xmax = x;
        return true;
    }
    return false;
}
template<typename T, typename U, typename Comp=less<>>
bool chmin(T& xmin, const U& x, Comp comp={}) {
    if(comp(x, xmin)) {
        xmin = x;
        return true;
    }
    return false;
}

// Yes-Noを出力する問題で楽をする
void Ans(bool f){
    if(f) cout << "Yes" << endl;
    else cout << "No" << endl;
}

//---------------------------

int main(){
    char a,b; cin >> a >> b;
    if(a==b) cout << "H" << endl;
    else cout << "D" << endl;
    return 0;
}

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

#include <iostream>
using namespace std;
int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  if (int((c + b - 1) / b) <= int((a + d - 1) / d)) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 3568
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner std = new Scanner(System.in);
        int h = std.nextInt();
        int a = std.nextInt();
        int count = 0;
        while (h > 0) {
            h = h - a;
            count++;
        }

        System.out.println(count);
    }
}


Measured memory_bytes: 22228
import fractions

a,b,c,d=map(int,input().split())
def cal(x,div1,div2):
    ret1=x//div1
    ret2=x//div2
    ret3=x//int(((div1*div2)/fractions.gcd(div1,div2)))
    return x-(ret1+ret2-ret3)
print(cal(b,c,d)-cal(a-1,c,d))


Measured memory_bytes: 77268