akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define all(v) v.begin(), v.end()
#define sz(v) v.size()
#define INF 100000000000000 //10^14
template <typename T>
bool chmax(T &a, const T& b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T>
bool chmin(T &a, const T& b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
int main()
{
    ll N, M;
    cin >> N >> M;
    vector<ll> A(N);
    rep(i, N) cin >> A.at(i);
    vector<ll> acc(N+1, 0);
    rep(i, N){
        acc.at(i+1) = acc.at(i) + A.at(i);
    }
    map<ll, ll> rem;
    set<ll> plu;
    rep(i, N+1){
        rem[acc.at(i) % M]++;
        if(rem[acc.at(i) % M] >= 2){
            plu.insert(acc.at(i) % M);
        }
    }
    ll ans = 0;
    for(auto i : plu){
        ans += rem[i] * (rem[i] - 1) / 2;
    }
    cout << ans << endl;
}

Measured memory_bytes: 10000
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#define rep(i,n) for(int i=0;i<(n);i++)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define psortfirst(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.first<b.first;});
#define All(x) (x).begin(),(x).end()
using namespace std;
using pii  = pair<int,int>;
long long gcd(long long a, long long b){return (b == 0 ? a : gcd(b, a%b));}
long long lcm(long long a, long long b){return a*b/gcd(a,b);}
int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}
int BinarySearch(int key,int n,int S[]){
  int l=0,r=n;
  while(r-l>1){
    int mid=(l+r)/2;
    if(S[mid]>key)r=mid;
    else l=mid;
  }
  return S[l]==(key?1:0);
}
typedef long long ll;
#define MOD 1000000007
#define EPS 10e-8

int main() {
  ll N,A,K=0;cin >> N;
  A=N;
  while(N>0){
    K+=N%10;
    N/=10;
  }
  cout << (A%K==0 ? "Yes" : "No")<< endl;
}

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

class Program {
    static string ReadLine() { return Console.ReadLine().Trim(); }
    static int ReadInt() { return int.Parse(Console.ReadLine()); }
    static int[] ReadInts() { return ReadLine().Split().Select(int.Parse).ToArray(); }
    static string[] ReadStrings() { return ReadLine().Split(); }

    static void Display(int[] xs) {
//        for (int i = 0; i < xs.Length; i++) {
//            if (i > 0) Console.Write(' ');
//            Console.Write(xs[i]);
//        }
//        Console.WriteLine();

        string[] ss = new string[xs.Length];
        for (int i = 0; i < xs.Length; i++) {
            ss[i] = xs[i].ToString();
        }

        Console.WriteLine(string.Join(" ", ss));
    }

    static void Main() {
        int n = ReadInt();
        int[] xs = ReadInts();
        if (n != xs.Length) throw new Exception();

        Display(xs);
        for (int i = 1; i < xs.Length; i++) {
            int key = xs[i];
            // insert xs[i] into the sorted sequence xs[0..j-1]
            int j = i - 1;
            while (j >= 0 && xs[j] > key) {
                xs[j+1] = xs[j];
                j--;
            }
            xs[j+1] = key;

            // output
            Display(xs);
        }
    }
}

Measured memory_bytes: 6060
#include <stdio.h>
typedef long long int llint;

int main()
{
    int n;
    int a[100050];
    int a2[100050];
    int b[100050];
    scanf("%d",&n);
    for(int i=0;i<n+1;i++)
    {
        scanf("%d",&a[i]);
        a2[i]=a[i];
    }
    for(int i=0;i<n;i++)
    {
        scanf("%d",&b[i]);
    }

    llint ans=0;
    for(int i=0;i<n;i++)
    {
        if(a[i]>=b[i])
        {
            a[i]-=b[i];
            ans+=b[i];
        }
        else
        {
            ans+=a[i];
            b[i]-=a[i];
            a[i]=0;
            if(a[i+1]>=b[i])
            {
                a[i+1]-=b[i];
                ans+=b[i];
            }
            else
            {
                ans+=a[i+1];
                a[i+1]=0;
            }
        }
    }
    int count1=0;
    int count2=0;
    for(int i=0;i<n+1;i++)
    {
        count1+=a[i];
        count2+=a2[i];
    }
    printf("%lld\n",ans);
    // printf("%d\n",count2-count1);
}

Measured memory_bytes: 896
import java.util.*;
import java.io.BufferedReader;
import java.io.BufferedOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.OutputStream;


public class Main {
    void run() {
        Kattio io = new Kattio(System.in, System.out);
        int[] table = new int[100005];
        for (int i = 0; i < table.length; i++)
            table[i] = -1;
        for (int i = 1; i * (i + 1) <= 200000; i++) {
            if (i * (i + 1) % 2 == 0) {
                table[i*(i+1)/2] = i;
            }
        }
        int n = io.getInt();
        if (table[n] == -1) {
            System.out.println("No");
        } else {
            System.out.println("Yes");
            int x = n, time = table[n], y = n;
            System.out.println(time+1);
            int[][] res = new int[time+1][time+1];
            int i = 0, j = 1;
            for (int t = 0; t < time; t++) {
                for (int _i = i; _i < time; _i++) {
                        res[t][_i] = x;
                        x--;
                }
                for (int _j = j; _j < time+1; _j++) {
                    res[_j][t] = y;
                    y--;
                }
                i++; j++;

            }
            for (int t = 0; t < time + 1; t++) {
                System.out.printf("%d ", time);
                for (int k = 0; k < time; k++) {
                    System.out.printf("%d ", res[t][k]);
                }
                System.out.println();
            }
        }
    }

    public static void main (String [] args) {
        new Main().run();
    }
}

class Kattio extends PrintWriter {
    public Kattio(InputStream i) {
		super(new BufferedOutputStream(System.out));
		r = new BufferedReader(new InputStreamReader(i));
    }
    public Kattio(InputStream i, OutputStream o) {
		super(new BufferedOutputStream(o));
		r = new BufferedReader(new InputStreamReader(i));
    }

    public boolean hasMoreTokens() {
		return peekToken() != null;
    }

    public int getInt() {
		return Integer.parseInt(nextToken());
    }

    public double getDouble() { 
		return Double.parseDouble(nextToken());
    }

    public long getLong() {
		return Long.parseLong(nextToken());
    }

    public String getWord() {
		return nextToken();
    }

    private BufferedReader r;
    private String line;
    private StringTokenizer st;
    private String token;

    private String peekToken() {
	if (token == null) 
	    try {
		      while (st == null || !st.hasMoreTokens()) {
		    	line = r.readLine();
		    	if (line == null) return null;
		    	st = new StringTokenizer(line);
			}
				token = st.nextToken();
	    	} catch (IOException e) { }
		return token;
    }

    private String nextToken() {
		String ans = peekToken();
		token = null;
		return ans;
    }
}


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

class Main{
    public static void main(String[] args){
	BufferedReader sc=new BufferedReader(new InputStreamReader(System.in));
	try {
	    String[] source = sc.readLine().split(" ");
	    Map<String, Integer> wordMap = new HashMap<String, Integer>();
	    int count = 0, wordlength = 0;
	    String wordmax = null, wordcount = null;
	    for(String word : source){
		Integer a = wordMap.get(word);
		if(a == null)
		    a = new Integer(1);
		else
		    a++;
		wordMap.put(word, a);
		if(a>count){
		    count = a;
		    wordcount = word;
		}
		if(word.length() > wordlength){
		    wordlength = word.length();
		    wordmax = word;
		}
	    }
	    System.out.println(wordcount+" "+wordmax);
	}
	catch(Exception e){
	    System.out.println("Error");
	}
    }
}

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

#define rep(i,j,n) for(int i=(j);i<(n);i++)
#define erep(i,j,n) for(int i=(j);i<=(n);i++)
#define all(i) i.begin(),i.end()
#define rall(i) i.rbegin(),i.rend()
#define INF 1e9
const int mod = 1e9+7;

typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vi> vvi;
typedef pair<int, int> pi;
typedef long long i64;

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

  int n;
  cin >> n;
  bool ok = true;
  string w;
  cin >> w;

  set<string> st;
  st.insert(w);
  char s = w[w.size() - 1];
  rep(i, 1, n) {
    cin >> w;
    if(st.count(w) || s != w[0]) ok = false;
    st.insert(w);
    s = w[w.size() - 1];
  }
  if(ok) cout << "Yes\n";
  else cout << "No\n";
}


Measured memory_bytes: 256
s=list(input())
a='abcdefghijklmnopqrstuvwxyz'
a_li=list(a)

s_set=set(s)
a_set=set(a_li)

if s_set==a_set:
    print('None')
else:
    result=list(a_set-s_set)
    result.sort()
    print(result[0])

Measured memory_bytes: 3956
/*
    Author:zeke
    
    pass System Test!
    GET AC!!
*/
#include <iostream>
#include <queue>
#include <vector>
#include <iostream>
#include <vector>
#include <string>
#include <cassert>
#include <algorithm>
#include <functional>
#include <cmath>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <map>
#include <iomanip>
#include <utility>
#include <stack>
#include <bitset>
using ll = long long;
using ld = long double;
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define rep3(var, min, max) for (ll(var) = (min); (var) < (max); ++(var))
#define repi3(var, min, max) for (ll(var) = (max)-1; (var) + 1 > (min); --(var))
#define Mp(a, b) make_pair((a), (b))
#define F first
#define S second
#define Icin(s) \
    ll(s);      \
    cin >> (s);
#define Scin(s) \
    ll(s);      \
    cin >> (s);
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;
}
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef vector<V> VV;
typedef vector<P> VP;
ll mod = 1e9 + 7;
ll MOD = 1e9 + 7;
ll INF = 1e18;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    VV dp(s.size() + 1, V(13));
    dp[0][0] = 1;
    rep(i, s.size())
    {
        rep(j, 13)
        {
            if (s[i] == '?')
            {
                rep(k, 10)
                {
                    ll g=(j*10 + k)%13;
                    dp[i + 1][g] += dp[i][j];
                    if(dp[i + 1][g]>=MOD)dp[i + 1][g]-=MOD;
                }
            }
            else
            {
                ll g=(j * 10 + (s[i] - '0'))%13;
                dp[i + 1][g] += dp[i][j];
                if(dp[i + 1][g]>=MOD)dp[i + 1][g]-=MOD;
            }
        }
    }
    cout << dp[s.size()][5] << endl;
}


Measured memory_bytes: 13648
#include<iostream>
#include<queue>

using namespace std;

int main(){
	queue<string> procces;
	queue<int> p_time;
	int n; cin >> n;
	int q; cin >> q;
	int all_time = 0;
	for (int i = 0; i < n; i++){
		string pro; cin >> pro;
		int time; cin >> time;
		procces.push(pro);
		p_time.push(time);
	}
	while (!procces.empty()){
		if (p_time.front() <= q){
			all_time += p_time.front();
			cout << procces.front() << " " << all_time << endl;
			procces.pop();
			p_time.pop();
		}else{
			all_time += q;
			string p_tmp = procces.front();
			procces.pop();
			procces.push(p_tmp);
			int t_tmp = p_time.front();
			p_time.pop();
			p_time.push(t_tmp-q);
		}
	}

return 0;
}

Measured memory_bytes: 5736
N,W = map(int, input().split())
w = [0] * N
v = [0] * N
for i in range(N):
    w[i], v[i] = map(int, input().split())
    
dp=[[0 for i in range(N+1)] for j in range(W+1)] 
for n in range(1,N+1):
    for e in range(1,W+1):
        if e-w[n-1]>=0:
            dp[e][n]=max(dp[e][n-1],dp[e-w[n-1]][n-1]+v[n-1])
        else:
            dp[e][n]=dp[e][n-1]
#print(dp)
print(dp[-1][-1])

Measured memory_bytes: 169004
N, M, K = map(int, input().split())
A = [0] + list(map(int, input().split()))
B = [0] + list(map(int, input().split()))

for i in range(1, N+1):
  A[i] += A[i-1]

for i in range(1, M+1):
  B[i] += B[i-1]


ans = 0
b_count = M
for a_count in range(N+1):
  if A[a_count] > K:
    continue

  while A[a_count] + B[b_count] > K:
    b_count -= 1

  ans = max(ans, a_count + b_count)
print(ans)


Measured memory_bytes: 40068
#include <string>
#include <vector>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <map>
#include <list>
#include <set>
#include <numeric>
#include <queue>
#include <stack>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <climits>
#include <cfloat>
#include <ctime>
#include <complex>
#include <cassert>
#include <array>
#include <bitset> 
#include <unordered_map>
#include <random>

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

const int L=1e5+10;
vector<int> ps[L];
int ds[L];
int v[L];
int d[L];
int c[L];
int r[L];
int main() {
	int N,M,Q;
	cin >> N >> M;
	memset(ds,-1,sizeof(ds));
	for(int i=0;i<M;i++){
		int a,b;
		cin >> a >> b;
		ps[a].push_back(b);
		ps[b].push_back(a);
	}
	cin >> Q;
	//cerr << "aaa " << Q << endl;
	for(int i=0;i<Q;i++){
		cin >> v[i] >> d[i] >> c[i];
	}
	//cerr << "bbb" << endl;
	for(int i=Q-1;i>=0;i--)
	{
		if(ds[v[i]]>=d[i])
		{
			continue;
		}
		ds[v[i]]=d[i];
		vector<int> cur,nex;
		if(r[v[i]]==0)
		{
			r[v[i]]=c[i];
		}
		cur.push_back(v[i]);
		for(int j=d[i]-1;j>=0;j--)
		{
			//cerr << i << ", " << j << endl;
			nex.clear();
			for(auto w:cur){
				for(auto k:ps[w])
				{
					if(ds[k]<j)
					{
						ds[k]=j;
						if(r[k]==0){
							r[k]=c[i];
						}
						nex.push_back(k);
					}
				}
			}
			nex.swap(cur);
		}
	}
	for(int i=1;i<=N;i++)
	{
		cout << r[i] << endl;
	}


	return 0;
}



Measured memory_bytes: 8944
import java.io.IOException;
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {

		new Main().run();
	}

	private void run() throws IOException {
		Scanner scanner = new Scanner(System.in);
		while (true) {
			int D = scanner.nextInt();
			int N = scanner.nextInt();
			if ((D | N) == 0)
				break;
			int[] a = new int[N];
			int[] e = new int[N];
			int[] r = new int[N];
			for (int i = 0; i < N; i++) {
				int aa = scanner.nextInt();
				int ee = scanner.nextInt();
				int rr = scanner.nextInt();
				a[i] = aa;
				e[i] = ee;
				r[i] = rr;
			}
			int[][] dp = new int[D + 1][101];
			for (int[] d : dp)
				Arrays.fill(d, INF);
			dp[D][0] = 0;
			for (int i = D; i > 0; i--) {
				for (int j = 0; j <= 100; j++) {
					if (dp[i][j] == INF)
						continue;
					for (int k = 0; k < N; k++) {
						if (j < r[k])
							continue;
						dp[Math.max(0, i - a[k])][Math.min(100, j + e[k])] = Math
								.min(dp[Math.max(0, i - a[k])][Math.min(100, j
										+ e[k])], dp[i][j] + 1);
					}
				}
			}
			int ret = INF;
			for (int i = 0; i < 101; i++)
				ret = Math.min(ret, dp[0][i]);
			System.out.println(ret == INF ? "NA" : ret);
		}

	}

	int INF = 1 << 30;
}

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

int main() {
    int N;
    cin >> N;
    int A[N];
    for (int i = 0; i < N; i++)
    {
        A[i] = 0;
        cin >> A[i];
    }
    
    for (int i = 0; i < N; i++)
    {
        if (A[i] % 2 == 0) {
            if (A[i] % 3 != 0 && A[i] % 5 != 0)
            {
                cout << "DENIED" << endl;
                return 0;
            }
        }
    }
    cout << "APPROVED" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include<algorithm>
#include<string>
#include <cmath>
#include <vector>
#include <map>
#include <cstdio>
#include <iomanip>
#include <numeric>
#pragma region Macros
#define int long long
#define double long double
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979323846;
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<=n;i++)
#define LAST(x) x[x.size()-1]
#define ALL(x) (x).begin(),(x).end()
#define swap(a,b) (a += b,b = a - b,a -= b)
#define CEIL(a,b) ((a+b-1)/b)
int FACT(int a) {
	if (a == 0)
		return 1;
	else
		return a * FACT(a - 1);
}
int nPr(int n, int r) {
	int s = n - r + 1;
	int sum = 1;
	for (int i = s; i <= n; i++)
		sum *= i;
	return sum;
}
//int nCr(int n, int r)
int nCr2(int n, int r) {
	return FACT(n) / (FACT(r) * FACT(n - r));
}
int GCD(int a, int b) // assuming a,b >= 1
{
	if (a < b)
		swap(a, b);
	if (b == 0)
		return a;
	if (a % b == 0)
		return b;
	return GCD(b, a % b);
}
int LCM(int a, int b) // assuming a,b >= 1
{
	return  a * b / GCD(a, b);
}
//int COUNTDIV(int n) 素因数分解して+1してかける奴
int COUNTDIV2(int n) {
	int ans = 0;
	REP(i, n) {
		if (n % i == 0)
			ans++;
	}
	return ans;
}
double LOG(int a, int b) {
	return log(b) / log(a);
}
inline bool BETWEEN(int x, int min, int max) {
	if (min <= x && x <= max)
		return true;
	else
		return false;
}
inline bool PRIMEOR (int x) {
	if (x ==1)
		return false;
	if (x == 2)
		return true;
	if (x%2==0)
		return false;
	double sqrtx = sqrt(x);
	for (int i = 3; i <= sqrtx; i += 2) {
		if (x % i == 0)
			return false;
	}
	return true;
}

using namespace std;
#pragma endregion
signed main() {
	int N,x,max=0;
	string ans = "Yes";
	cin >> N;
	rep(i, N) {
		cin >> x;
		if (max < x)
			max = x;
		else if(max > x + 1)
			ans = "No";
	}
	cout << ans <<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>

using namespace std;

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

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cout<<*i<<" "; cout<<endl; }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;

int main(){
	int n;
	while(cin>>n,n){
		vector<int> a(n);
		REP(i,n)cin>>a[i];
		sort(a.begin(),a.end());
		int ans = -1;
		REP(i,n/2+1){
			int j = i + n/2;
			if(j < n && a[j] == a[i]){
				ans = a[i];
				break;
			}
		}
		if(ans!=-1){
			cout<<ans<<endl;
		}else{
			cout<<"NO COLOR"<<endl;
		}
	}

	return 0;
}

Measured memory_bytes: 4852
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define PI 3.141592653589793
#define rep(i, n) for (int i = 0; i < (n); i++)
#define REP(i, a, n) for (int i = a; i < (n); i++)
#define rrep(i, n, k) for (int i = (n); i >= (k); i--);
#define all(x) (x).begin(), (x).end()
#define vi vector<int>
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
template<class T>vector<T> make_vector(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto make_vector(size_t a, Ts... ts){return vector<decltype(make_vector<T>(ts...))>(a, make_vector<T>(ts...));}
const int MOD = 1e9 + 7;
const int INF = 2e18;

signed main() {
    int N, M;
    cin >> N >> M;
    vector<vector<int>> G(N + 1);
    for (int i = 0; i < M; i++) {
        int A, B;
        cin >> A >> B;
        G[A].push_back(B);
        G[B].push_back(A);
    }
    set<int> even, odd;
    bool two = true;
    {
        vector<bool> check(N + 1, false);
        function<void(int, int)> dfs = [&](int now, int count) {
            if (count % 2 == 0) {
                if (odd.find(now) != odd.end()) two = false;
                else even.insert(now);
            } else {
                if (even.find(now) != even.end()) two = false;
                else odd.insert(now);
            }
            if (check[now]) return;
            check[now] = true;
            for (auto next : G[now]) {
                dfs(next, count + 1);
            }
        };
        dfs(1, 0);
    }
    if (two) {
        cout << even.size() * odd.size() - M << endl;
    } else {
        int base = N * (N - 1) / 2;
        cout << base - M << endl;
    }
}


Measured memory_bytes: 12032
n = int(input())
data = list(map(int, input().split()))   # 1行にある複数の値を整数にして、リストにしまう

vmin = min(data)  # 最小値
vmax = max(data)  # 最大値
vsum = sum(data)  # 合計

print(vmin, vmax, vsum)  


Measured memory_bytes: 6588
from copy import deepcopy
mod = 10 ** 9 + 7
n, m = map(int, input().split())
s = list(map(int, input().split()))
t = list(map(int, input().split()))
ans = [1 for i in range(m + 1)]
for i in s:
    ans2 = deepcopy(ans)
    cnt = 0
    for j in range(m):
        ans2[j] = (cnt + ans2[j]) % mod
        if i == t[j]:
            cnt = (cnt + ans[j]) % mod
    ans2[-1] = (cnt+ ans2[-1]) % mod
    ans = deepcopy(ans2)
print(ans[-1])

Measured memory_bytes: 82684
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include<cmath>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
typedef long long ll;
const int mo = 1e9 + 7;
struct mint
{
    int n;
    mint(int n = 0) : n(n) {}
};
mint operator+(mint a, mint b) { return (a.n += b.n) >= mo ? a.n - mo : a.n; }
mint operator-(mint a, mint b) { return (a.n -= b.n) < 0 ? a.n + mo : a.n; }
mint operator*(mint a, mint b) { return 1LL * a.n * b.n & mo; }
mint &operator+=(mint &a, mint b) { return a = a + b; }
mint &operator-=(mint &a, mint b) { return a = a - b; }
mint &operator*=(mint &a, mint b) { return a = a * b; }
ostream &operator<<(ostream &o, mint a) { return o << a.n; }

void solve()
{
    int n,h;
    cin>>n>>h;
    int a=0;
    vector<int> b(n);
    rep(i,n)
    {
        int c;
        cin>>c>>b[i];
        a=max(a,c);
    }
    
    sort(begin(b),end(b));
    int ret=0;
    while(h>0&&!b.empty())
    {
        int t=b.back();
        if(t<=a)break;
        ret++;
        h-=t;
        b.pop_back();
    }
    
    if(h>0)ret+=(h+a-1)/a;
    cout<<ret<<endl;
}
signed main()
{
    cin.tie(0);
    ios::sync_with_stdio(0);
    solve();
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vb = vector<bool>;
using vc = vector<char>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using pii = pair<int, int>;
#define rep(i,n) for(int i=0; i<(int)(n);i++)

int main(){
  int n;
  string s;
  cin >> n >> s;
  int count;
  int maxi = -1;
  for(int i=0;i<=n-2;i++){
    set<char> moji;
    for(int j=0;j<=i;j++){
      moji.insert(s.at(j));
    }
    set<char> moji2;
    for(int j=i+1;j<=n-1;j++){
      if(moji.count(s.at(j))){
        moji2.insert(s.at(j));
      }
    }
    int tmp = moji2.size();
    maxi = max(maxi,tmp);
  }
  cout << maxi << endl;
}


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

string str;
int main()
{
	int n;
	cin >> n >> str;
	int a = 0;
	int cnt = 0;
	int l = 0, r = 0;
	for (int i = 0; i < n; i++) {
		if (str[i] == '(') cnt++, l++;
		else cnt--, r++;
		if (cnt < 0) cnt++, a++; 
	}
	for (int i = 1; i <= a; i++) putchar('(');
	cout << str;
	if (r-l-a >= 1) for (int i = 1; i <= r-l-a; i++) putchar(')');
	if (r-l-a <= 1) while (r-l-a < 0) {putchar(')'), r++; }
	puts("");
	return 0;
}

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

public class Main {

	static BufferedReader in;
	static PrintWriter out;
	static StringTokenizer tok;

	void solve() throws IOException {
		String s = readString();

		long ans = 0;

		for (long i=0; i<1<<(s.length()-1); i++) {
			int prev = 0;
			for (int j=0; j<s.length()-1; j++) {
				if (((i>>j) & 1) == 1) {
					ans += Long.parseLong(s.substring(prev, j+1));
					prev = j+1;
				}
			}
			ans += Long.parseLong(s.substring(prev, s.length()));
		}

		out.println(ans);
	}


	public static void main(String[] args) throws IOException {
		in = new BufferedReader(new InputStreamReader(System.in));
		out = new PrintWriter(System.out);
		tok = new StringTokenizer("");
		Main main = new Main();
		main.solve();
		out.close();
	}

	String readString() throws IOException {
		while (!tok.hasMoreTokens()) {
			tok = new StringTokenizer(in.readLine(), " .");
		}
		return tok.nextToken();
	}

	int readInt() throws IOException {
		return Integer.parseInt(readString());
	}

	long readLong() throws IOException {
		return Long.parseLong(readString());
	}

	double readDouble() throws IOException {
		return Double.parseDouble(readString());
	}

	int[] readArr(int n) throws IOException {
		int[] res = new int[n];
		for (int i = 0; i < n; i++) {
			res[i] = readInt();
		}
		return res;
	}

	long[] readArrL(int n) throws IOException {
		long[] res = new long[n];
		for (int i = 0; i < n; i++) {
			res[i] = readLong();
		}
		return res;
	}

	void readArr2(int[] A, int[] B) throws IOException {
		int n = A.length;
		for (int i = 0; i < n; i++) {
			A[i] = readInt();
			B[i] = readInt();
		}
	}

	void readArrL2(long[] A, long[] B) throws IOException {
		int n = A.length;
		for (int i = 0; i < n; i++) {
			A[i] = readLong();
			B[i] = readLong();
		}
	}
}


Measured memory_bytes: 8660
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);

		char[] s = sc.next().toCharArray();
		char[] t = sc.next().toCharArray();

		int dp[][] = new int[s.length + 1][t.length + 1];

		for(int i = 1; i <= s.length; i++){
			for(int j = 1; j <= t.length; j++){
				dp[i][j] = Math.max(dp[i][j - 1], dp[i - 1][j]);

				if(s[i - 1] == t[j - 1]){
					dp[i][j] = Math.max(dp[i - 1][j - 1] + 1, dp[i][j]);
				}

//				System.out.print(dp[i][j]+" ");
			}
//			System.out.println();
		}

		String result = "";

		int i = s.length;
		int j = t.length;
		while(i > 0 && j > 0){
			if(dp[i][j] == dp[i][j - 1]){
				j--;
			}
			else if(dp[i][j] == dp[i - 1][j]){
				i--;
			}
			else {
				result = s[i - 1] + result;
				i--;
				j--;
			}
		}
		System.out.println(result);
	}

}


Measured memory_bytes: 81164
s = list(input())
n = [None]*2
if "S" in s and "N" in s:
  n[0] = 1
elif "S" in s and "N" not in s:
  n[0] = 0
elif "S" not in s and "N" in s:
  n[0] = 0
if "W" in s and "E" in s:
  n[1] = 1
elif "W" in s and "E" not in s:
  n[1] = 0
elif "W" not in s and "E" in s:
  n[1] = 0
if n.count(1)==2:
  print("Yes")
elif 0 in n:
  print("No")
elif None in n and n.count(1) == 1:
  print("Yes")

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

signed main() {
	string s;
	cin>>s;
	int n = s.size();
	int sum = 0;
	rep(i,n){
		sum+=s[i] - '0';
	}
	if(sum%9==0) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
}


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

using namespace std;
inline void read(int &x){
    char ch;
    bool flag=false;
    for (ch=getchar();!isdigit(ch);ch=getchar())if (ch=='-') flag=true;
    for (x=0;isdigit(ch);x=x*10+ch-'0',ch=getchar());
    x=flag?-x:x;
}

inline void read(long long &x){
    char ch;
    bool flag=false;
    for (ch=getchar();!isdigit(ch);ch=getchar())if (ch=='-') flag=true;
    for (x=0;isdigit(ch);x=x*10+ch-'0',ch=getchar());
    x=flag?-x:x;
}


inline void write(int x){
    static const int maxlen=100;
    static char s[maxlen];
        if (x<0) {   putchar('-'); x=-x;}
    if(!x){ putchar('0'); return; }
    int len=0; for(;x;x/=10) s[len++]=x % 10+'0';
    for(int i=len-1;i>=0;--i) putchar(s[i]);
}

int a,b,c,d,e,f;
int anss=0,answ=0;

void dfs(int x,int sums,int sumw){
if (x>4)
    {
        if ( sums+sumw>f)
            return ;
        if ( sums > sumw/100*e )
            return ;
        //printf("%d %d\n",sums,sumw);
        if( sums * ( anss+answ ) >= anss * (sums+sumw) )
            {
                anss=sums;
                answ=sumw;
            }
        return ;
    }
dfs(x+1,sums,sumw);
for (int i=0;sums+sumw<=f;i++)
    {
        if (x==1)
            sumw+=100*a;
        if (x==2)
            sumw+=100*b;
        if (x==3)
            sums+=c;
        if (x==4)
            sums+=d;
        dfs(x+1,sums,sumw);
    }
}

int main(){
    read(a);read(b);read(c);read(d);read(e);read(f);
    dfs(1,0,0);
    printf("%d %d\n",anss+answ,anss);
    return 0;
}

Measured memory_bytes: 256
var main = function main(input) {
  var args = input.split(' ')
  var average = (+args[0] + +args[1]) / 2
  var point = average % 1
  if (point >= 0.5) {
      average = average + 0.5
      var point2 = average % 1
      average = average - point2
  } else {
      average = average - point
  }
  console.log(average)
}
 
main(require('fs').readFileSync('/dev/stdin', 'utf-8'))


Measured memory_bytes: 7624
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;

public class Main {
    private static Scanner sc;
    public static void main(String[] args) {
        Main instance = new Main();
        sc = instance.new Scanner();
        instance.solve();
    }

    private void solve() {
        try {
            int N = sc.nextInt();
            int Q = sc.nextInt();
            String S = sc.next();
            String R = new StringBuffer(S).reverse().toString();
            int[] l = new int[S.length()];
            int[] r = new int[S.length()];
            Arrays.fill(l, 0);
            Arrays.fill(r, 0);
            int tmpl = 0;
            int tmpr = 0;
            for (int i = 1; i < S.length(); i++) {
                l[i] = tmpl;
                if (S.charAt(i-1) == 'A' && S.charAt(i) == 'C') {
                    tmpl++;
                    l[i] = tmpl;
                }

                r[i] = tmpr;
                if (R.charAt(i-1) == 'C' && R.charAt(i) == 'A') {
                    tmpr++;
                    r[i] = tmpr;
                }
            }
            int a, b;
            for (int i = 0; i < Q; i++) {
                a = sc.nextInt();
                b = sc.nextInt();
                System.out.println(tmpl - l[a-1] - r[S.length()-b]);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private class Scanner {
        String[] s;
        int i;
        BufferedReader br;
        String regex = " ";

        public Scanner() {
            s = new String[0];
            i = 0;
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        @Override
        protected void finalize() throws Throwable {
            try {
                super.finalize();
            } finally {
                destruction();
            }
        }

        private void destruction() throws IOException {
            if (br != null) br.close();
        }

        public String next() throws IOException {
            if (i < s.length) return s[i++];
            String st = br.readLine();
            while (st == "") st = br.readLine();
            s = st.split(regex, 0);
            i = 0;
            return s[i++];
        }

        public int nextInt() throws NumberFormatException, IOException {
            return Integer.parseInt(next());
        }

        public Long nextLong() throws NumberFormatException, IOException {
            return Long.parseLong(next());
        }

        public Double nextDouble() throws NumberFormatException, IOException {
            return Double.parseDouble(next());
        }
    }
}

Measured memory_bytes: 49744
#include <iostream>
#include<utility>
#include<iomanip>
#include<cmath>
#include<algorithm>
#include<cfloat>
#include<functional>
#include<string>
#include<numeric>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<cctype>
#include<iterator>
#include <stdio.h>
#include <string.h>
#include <sstream>
//#include<conio.h>
#define ReadFile freopen("input.txt","r",stdin)
#define WriteFile freopen("output.txt","w",stdout)
#define MEGA_MIND ios_base::sync_with_stdio(0);cin.tie(0); cout.tie(0);
#define M_PI 3.14159265358979323846
#define mod 1000000007
#define endl "\n"
using namespace std;
using ll = long long;
using lli = long long int;
using ld = long double;


const int N = 5e6 + 5, inf = 2e9;


int main()
{
	MEGA_MIND
		int n;
	cin >> n;
	if (n % 2)
		cout << (n + 1) / 2 << endl;
	else
		cout << n / 2 << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <vector>
#include <string.h>

using namespace std;

void print_a_b(char* str, int a, int b){
	for(int i = a; i < b+1; i++){
		cout << str[i];
	}
	cout << endl;
	return;
}

void reverse_a_b(char* str, int a, int b){
	int count = (b+1 - a) / 2;
	for(int i = 0; i < count; i++){
		char tmp = str[a+i];
		str[a+i] = str[b-i];
		str[b-i] = tmp;
	}
}

void replace_a_b(char* str, int a, int b, char* p){
	int index = 0;
	for(int i = a; i < b+1; i++){
		str[i] = p[index];
		index++;
	}
}

int main(){
	char* str = (char*)calloc(1000, sizeof(char));
	int num;
	cin >> str >> num;
	for(int i = 0; i < num; i++){
		string order;
		int a, b;
		cin >> order >> a >> b;
		
		if(order == "replace"){
			char* p = (char*)calloc(b-a+1, sizeof(char));
			cin >> p;
			replace_a_b(str, a, b, p);
		}
		else if(order == "reverse"){
			reverse_a_b(str, a, b);
		}
		else if(order == "print"){
			print_a_b(str, a, b);
		}
	}
}



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

int limit,n,m,x;

int a[111],b[111],c[111],d[111];
string damy;
int dp[1111][111];
bool used[1111][111];
int MAX[1111];

void Input(){
  rep(i,m){
    cin>>damy>>c[i]>>d[i];
  }
  rep(i,n){
    cin>>damy>>a[i]>>b[i];
  }
}

void init(){
  memset(MAX,0,sizeof(MAX));
  memset(dp,0,sizeof(dp));
  memset(used,0,sizeof(used));
}

void DP(){
  used[0][0]=1;
  for(int k=0;k<n;k++){
    for(int i=limit;i>=0;i--){
      for(int j=n;j>=0;j--){
	if(used[i][j]){
	  if(i+a[k]<=limit){
	    used[i+a[k]][j+1]=1;
	    dp[i+a[k]][j+1]=max(dp[i+a[k]][j+1],dp[i][j]+b[k]);
	  }
	}
      }
    }
  }

  for(int i=0;i<=limit;i++){
    for(int j=x;j<=n;j++){
      MAX[i]=max(MAX[i],dp[i][j]);
    }
  }

  int ans=0;

  for(int i=0;i<m;i++){
    for(int j=i+1;j<m;j++){
      for(int k=0;k<limit;k++){
	if(k+c[i]+c[j]>limit)break;
	ans=max(ans,MAX[k]+d[i]+d[j]);
      }
    }
  }

  for(int i=0;i<m;i++){
    for(int k=0;k<limit;k++){
      if(k+c[i]>limit)break;
      ans=max(ans,MAX[k]+d[i]);
    }
  }

  cout << ans << endl;
  
}


int main(){
  while( cin>>limit>>m>>n>>x,limit){
    Input();
    init();
    DP();
  }
}


Measured memory_bytes: 3612
require 'pp'
IS_DEBUG = true
# IS_DEBUG = false
def dputs str
	if(IS_DEBUG)
		puts str
	end
end
def dpp str
	if(IS_DEBUG)
		pp str
	end
end

a,b=gets.chomp.split(' ').map{|n| n.to_i}
if(a+b==15)
	puts "+"
elsif(a*b==15)
	puts "*"
else
	puts "x"
end


Measured memory_bytes: 2044
n=int(input())
x=input().split()
y=0
while y<n:
    x[y]=int(x[y])
    y+=1
other=0
gray=0
brown=0
green=0
cyan=0
blue=0
yellow=0
orange=0
red=0
for i in x:
    if i<=399:
        gray=1
    elif i<=799:
        brown=1
    elif i<=1199:
        green=1
    elif i<=1599:
        cyan=1
    elif i<=1999:
        blue=1
    elif i<=2399:
        yellow=1
    elif i<=2799:
        orange=1
    elif i<=3199:
        red=1
    else:
        other+=1
mi=gray+brown+green+cyan+blue+yellow+orange+red
ma=other+mi
if mi==0:
    mi=1
print(mi,ma)


Measured memory_bytes: 3064
N=int(input())
b=list(map(int,input().split()))
ans=[]
turn=N
while(b):
    last=-1
    for i in range(len(b)):
        if i+1==b[i]:
            last=i
    if last==-1:
        print(-1)
        exit()
    ans.append(last+1)
    del b[last]
    
print(*ans[::-1],sep='\n')

Measured memory_bytes: 3060
#include<stdio.h>
int main(){
	int a,b,wa;
	char k;
	scanf("%d",&a);
	wa=a;
	while(k!='='){
		scanf("%c",&k);
		switch(k){
			case '+':
				scanf("%d",&b);
				wa=wa+b;
				break;
			case '-':
				scanf("%d",&b);
				wa=wa-b;
				break;
			case '*':
				scanf("%d",&b);
				wa=wa*b;
				break;
			case '/':
				scanf("%d",&b);
				wa=wa/b;
				break;
		}
	}
	printf("%d\n",wa);
	return 0;
}



Measured memory_bytes: 2064
#include "stdio.h"
#define lnth(a,l) for(l=0;a[l];l++)


int main(){
	int s=0,n,t;
	scanf("%d",&n);
	t = n;
	while(t){
		s += t%10;
		t/=10;
	}
	//printf("%d",s);
	printf(n%s==0?"Yes":"No");
}


Measured memory_bytes: 128
import java.util.Scanner;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
        int y = sc.nextInt();
        System.out.println(gcd(x,y));
        sc.close();
    }   
    public static void swap(int x,int y){
    int tmp=x;
        x=y;
        y=tmp;
    }
    public static int gcd(int x,int y){
        if(x<y){
        swap(x,y);
    }
        while(y>0){
        int r=x%y;
            x=y;
            y=r;
        }  
        return x;
        }
    }



Measured memory_bytes: 26292
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <numeric> // accumulate(v.begin(), v.end(), 0)

using namespace std;
#define ll long long

int main(){
  int N, C;
  cin >> N >> C;
  vector< vector<int> > D(C, vector<int>(C));
  vector< vector<int> > Co(N, vector<int>(N));
  for(int i=0; i<C; i++)
    for(int j=0; j<C; j++)
      cin >> D[i][j];
  for(int i=0; i<N; i++)
    for(int j=0; j<N; j++)
      cin >> Co[i][j];
  vector<int> dp0(C, 0);
  vector<int> dp1(C, 0);
  vector<int> dp2(C, 0);
  for(int i=0; i<N; i++){
    for(int j=0; j<N; j++){
      for(int c=0; c<C; c++){
	if((i + j) % 3 == 0){
	  dp0[c] += D[Co[i][j]-1][c];
	} else if((i + j) % 3 == 1){
	  dp1[c] = dp1[c] + D[Co[i][j]-1][c];
	} else if((i + j) % 3 == 2){
	  dp2[c] = dp2[c] + D[Co[i][j]-1][c];
	}
      }
    }
  }
  int ans = 1000 * 500 * 500;
  for(int i=0; i<C; i++)
    for(int j=0; j<C; j++)
      if(i != j)
	for(int k=0; k<C; k++)
	  if(i != k && j != k)
	    ans = min(ans, dp0[i] + dp1[j] + dp2[k]);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1280
#include<bits/stdc++.h>
using namespace std;
int main(){
  char a,b;
  cin>>a>>b;
  if(a=='D'&&b=='D') cout<<"H\n";
  else if(a=='D') cout<<"D\n";
  else if(a=='H'&&b=='H') cout<<"H\n";
  else cout<<"D\n";
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#ifdef __DEBUG__
    #define DBG(X) cout << #X << " = " << (X) << endl;
    #define SAY(X) cout << (X) << endl;
#else
    #define DBG(X)
    #define SAY(X)
#endif

using namespace std;

using ll = long long int;
using ull = unsigned long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

int dx[]={1, 0, -1, 0, 1,-1, 1,-1};
int dy[]={0, 1, 0, -1, 1, 1,-1,-1};
const int INT_INF = (int)(2e9);
const ll  LL_INF = (ll)(2e18);

inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const map<T, S> p) { for (auto el : p) cout << "[" << el.first << ";" << el.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const deque<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const set<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for (auto& elem : ret) cin >> elem; return ret; }

int N,K;
string S;
void input(){
    fast_io();
    cin >> N >> K;
    cin >> S;
}

int solve(){
    vector<int> cnt;
    char c = '1';
    int cn = 0;
    for (int i = 0; i < N; i++)
    {
        if(S[i]==c) cn++;
        else{
            cnt.push_back(cn);
            cn = 1;
            if(c=='0') c='1';
            else c='0';
        }
    }
    cnt.push_back(cn);
    cnt.push_back(0);
    DBG(cnt)
    // cntから連続するk+1個の和の最大値。
    // if(cnt.size()<=K+2) {cout << N << endl; return 0;}
    vector<int> cntSUM(cnt.size()+1,0);
    int ans = 0;
    for (int i = 0; i < cnt.size(); i++) cntSUM[i+1] = cntSUM[i]+cnt[i];
    DBG(cntSUM)
    for (int i = 0; i < cntSUM.size(); i++)
    {
        if(i%2){
            if(i-(2*K+1)>=0) ans = max(ans,cntSUM[i]-cntSUM[i-(2*K+1)]);
            else ans = max(ans,cntSUM[i]);
        }
    }
    cout << ans << endl;
    // 1 0 1 0 1 0 1 0
    return 0;
}   

int main()
{
    input();
    solve();
    return 0;
}

Measured memory_bytes: 1272
using System;

namespace ABC124C
{
    class Program
    {
        static void Main(string[] args)
        {
            var raw = Console.ReadLine();

            var a = raw.ToCharArray();

            var count = 0;

            for (int i = 1; i < a.Length; i++)
            {
                if (a[i-1] == a[i])
                {
                    count++;
                    if (a[i] == '0')
                    {
                        a[i] = '1';
                    }
                    else
                    {
                        a[i] = '0';
                    }
                }
            }

            Console.WriteLine(count);
        }
    }
}


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

int main(void) {

    int h, w;
    while(cin >> h >> w){

      if( h == 0 && w == 0 ) break;

      for(int i=0; i<h; i++){
        for(int j=0; j<w; j++){
          cout << "#";
        }
        cout << endl;
      }
      cout << endl;
    }


    return 0;
}

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

int frog(long int n, int h[])
{
  int dp[n+1]={0}, i;

  for(i=2 ; i<=n ; i++)
  {
    int op1=abs(h[i]-h[i-1])+dp[i-1];
    int op2= i==2 ? pow(10,9) : abs(h[i]-h[i-2])+dp[i-2];
    dp[i]=min(op1, op2);
}
    return dp[n];
              }
int main()
{long int n, i;
 cin>>n;
 int h[n+1];
 h[0]={0};
 for(i=1 ; i<=n ; i++)
   cin>>h[i];

 cout<<frog(n, h);

 return 0;
}

Measured memory_bytes: 4372
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <unordered_map>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
#include <assert.h>
#include <unordered_map>
#include <fstream>
#include <ctime>
#include <complex>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef pair<int,int> pii;
typedef vector<P> vpl;
typedef tuple<ll,ll,ll> tapu;
#define rep(i,n) for(int i=0; i<(n); i++)
#define REP(i,a,b) for(int i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 2020000;
ll dy[8] = {1,-1,0,0,1,-1,1,-1};
ll dx[8] = {0,0,1,-1,1,-1,-1,1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
	if(a>b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
	if(a<b){
		a = b; return true;
	}
	else return false;
}
template<typename T> inline void print(T &a){
    for(auto itr = a.begin(); itr != a.end(); itr++){
		cout << *itr << " ";
	}
    cout << "\n";
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){
	cout << "debug: " << a << " " << b << "\n";
}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << "debug: " << a << " " << b << " " << c << "\n";
}
void mark() {cout << "#" << "\n";}
ll pcount(ll x) {return __builtin_popcountll(x);}
const int mod = 1e9 + 7;
//const int mod = 998244353;

vl divisor(ll k){
	vl c;
	for(ll i=1; i*i<=k; i++){
		if(k % i == 0){
			c.push_back(i);
			if((k / i) != i){
				c.push_back(k/i);
			}
		}
	}
	sort(c.begin(), c.end());
	return c;
}

long long extGCD(long long a, long long b, long long &x, long long &y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    long long d = extGCD(b, a%b, y, x);
    y -= a/b * x;
    return d;
}

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

int main(){
	ll n; cin >> n;
	n *= 2;
	ll tmp = n;
	while(tmp % 2 == 0) tmp /= 2;
	if(tmp == 1){
		cout << n-1 << "\n";
		return 0;
	} 
	vl div = divisor(n);
	ll ans = linf;
	for(auto i : div){
		ll j = n / i;
		if(GCD(i,j) == 1){
			ll x,y;
			extGCD(i,-j,x,y);
			if(x != 0 && y != 0) chmin(ans, min(x*i,y*j));
		}
	}
	cout << ans << "\n";
}

Measured memory_bytes: 3752
#include <stdio.h>
#include <string.h>
char S[3010];
char T[3010];
int dp[3010][3010];
int prev[3010][3010];
int M = 10000;
char ans[3010];
int max(int a,int b){
	if(a<b)return b;
	else return a;
}
int main(){
	scanf("%s",S);
	scanf("%s",T);
	int A = strlen(S);
	int B = strlen(T);
	for(int i=1;i<=A;i++){
		for(int j=1;j<=B;j++){
			dp[i][j]=max(dp[i][j-1],dp[i-1][j]);
			if(dp[i][j-1]>dp[i-1][j])prev[i][j]=i*M+j-1;
			else prev[i][j]=(i-1)*M+j;
			if(S[i-1]==T[j-1]){
				if(dp[i][j]<dp[i-1][j-1]+1){
					dp[i][j]=dp[i-1][j-1]+1;
					prev[i][j]=(i-1)*M+j-1;
				}
			}
		}
	}
	int i=A,j=B;
	int idx = 3000;
	ans[idx--]=0;
	while(i!=0&&j!=0){
		int pi = prev[i][j]/M, pj = prev[i][j]%M;
		if(dp[pi][pj]<dp[i][j])ans[idx--]=S[pi];
		i=pi;
		j=pj;
	}
	printf("%s\n",ans+idx+1);
	return 0;
}

Measured memory_bytes: 70784
#include<bits/stdc++.h>
#define int long long
using namespace std;
constexpr int mod=1e9+7;
signed main(){
    int n,k;
    cin>>n>>k;
    if(k%2==1)
        cout<<(n/k)*(n/k)*(n/k)<<endl;
    else
        cout<<(n/k)*(n/k)*(n/k)+(n/(k/2)-n/k)*(n/(k/2)-n/k)*(n/(k/2)-n/k)<<endl;
}


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

int main(){

    int n;
    cin >> n;

    int t;
    vector<int> ec(100001,0),oc(100001,0);

    rep(i,n){
        if(i%2==0){
            cin >> t;
            ec[t]++;
        }else{
            cin >> t;
            oc[t]++;
        }
    }

    auto ema=max_element(ec.begin(),ec.end());
    auto oma=max_element(oc.begin(),oc.end());

    int em=*ema;
    int om=*oma;

    if(distance(ec.begin(),ema)==distance(oc.begin(),oma)){
        *ema=0;
        *oma=0;

        auto esec=max_element(ec.begin(),ec.end());
        auto osec=max_element(oc.begin(),oc.end());

        int es=*esec;
        int os=*osec;

        cout << n-max(em+os,om+es) << endl;
    }else{
        cout << n-em-om << endl;
    }
    return 0;
}

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

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

typedef long long ll;
using namespace std;

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

  int A, B, C, X;
  cin >> A >> B >> C >> X;

  int ans = 0;
  REP(a, A + 1) {
    REP(b, B + 1) {
      int sum = a * 500 + b * 100;
      if (sum > X) {
        break;
      }
      if (sum == X) {
        ++ans;
        break;
      }

      REP(c, C + 1) {
        if (sum + c * 50 == X) {
          ++ans;
          break;
        }
      }
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256