akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

#define rep(i,m,n) for(int (i)=(int)(m);i<(int)(n);++i)
#define rep2(i,m,n) for(int (i)=(int)(n)-1;i>=(int)(m);--i)
#define REP(i,n) rep(i,0,n)
#define REP2(i,n) rep2(i,0,n)
#define FOR(i,c) for(decltype((c).begin())i=(c).begin();i!=(c).end();++i)
#define all(hoge) (hoge).begin(),(hoge).end()
#define en '\n'
using ll = long long;
using ull = unsigned long long;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;
typedef pair<ll, ll> P;
constexpr long long INF = 1LL << 60;
constexpr int INF_INT = 1 << 25;
constexpr long long MOD = (ll) 1e9 + 7;
//constexpr long long MOD = 998244353LL;
using ld=long double;
static const ld pi = 3.141592653589793L;
typedef vector<ll> Array;
typedef vector<Array> Matrix;


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

struct Edge {
	ll to, cap, rev;
	Edge(ll _to, ll _cap, ll _rev) {
	to = _to; cap = _cap; rev = _rev;
	}
};
using Edges = vector<Edge>;
using Graph = vector<Edges>;

void add_edge(Graph& G, ll from, ll to, ll cap, bool revFlag, ll revCap) {
	G[from].push_back(Edge(to, cap, (ll)G[to].size()));
	if (revFlag)G[to].push_back(Edge(from, revCap, (ll)G[from].size() - 1));
}

void solve(){
    string s;
    cin>>s;

    ll n=s.size();
    map<char,ll> mp;
    REP(i,n){
        mp[s[i]]++;
    }
    ll ans=n*(n-1)/2 + 1;
    for(auto i:mp){
        ans -= i.second*(i.second-1)/2;
    }
    cout<<ans<<en;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
	
	solve();
	//ll t;cin>>t;REP(i,t) solve();

    return 0;
}

Measured memory_bytes: 720
//#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector,fast-math")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,abm,mmx,popcnt,avx,avx2,tune=native")
           
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
           
using namespace std;
using namespace __gnu_pbds;
           
//#define int long long
  
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pld;
           
using matrix = vector<vector<ll>>;
template<typename T>
using kawaii_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
           
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
  
void FAST_IO() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    //cout.setf(ios::fixed);
    //cout.precision(20);
    #ifndef _offline
    //freopen("mincost.in", "r", stdin);
    //freopen("mincost.out", "w", stdout);
    #endif
}

const int INF = 1e9 + 7;
const int MAXN = 10;
const int MAXM = 1010;
char c[MAXN][MAXM];
int val[MAXN], sum[MAXN];

signed main() {
    FAST_IO();
    int n, m, k;
    cin >> n >> m >> k;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < m; ++j) {
            cin >> c[i][j];
        }
    }
    int ans = INF;
    for (int mask = 0; mask < (1 << (n - 1)); ++mask) {
        int cur = __builtin_popcount(mask);
        val[0] = 0;
        for (int i = 0; i < n - 1; ++i) {
            val[i + 1] = val[i];
            if (mask & (1 << i)) {
                val[i + 1]++;
            }
        }
        for (int i = 0; i <= val[n - 1]; ++i) {
            sum[i] = 0;
        }   
        for (int j = 0; j < m; ++j) {
            for (int i = 0; i < n; ++i) {
                sum[val[i]] += (c[i][j] == '1');
            }
            bool f = true;
            for (int i = 0; i <= val[n - 1]; ++i) {
                if (sum[i] > k) {
                    f = false;
                    break;
                }
            }
            if (f) {
                continue;
            }
            cur++;
            for (int i = 0; i <= val[n - 1]; ++i) {
                sum[i] = 0;
            }
            for (int i = 0; i < n; ++i) {
                sum[val[i]] += (c[i][j] == '1');
            }
            f = true;
            for (int i = 0; i <= val[n - 1]; ++i) {
                if (sum[i] > k) {
                    f = false;
                    break;
                }
            }
            if (!f) {
                cur = INF;
            }
        }
        ans = min(ans, cur);
    }
    cout << ans << '\n';
}   

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

int main()
{
    int x,y;
    while(1){
        cin>>x>>y;if(x==0&&y==0)break;
        cout<<min(x,y)<<" "<<max(x,y)<<endl;
    }
    
    return 0;
}




Measured memory_bytes: 3008
#include <bits/stdc++.h>
#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n,s) for(int i=(s);i<(n);i++)
#define rrep(i,n) for(int i=(n-1);i>=0;i--)
#define rreps(i,n,s) for(int i=s;i>=n;i--)
#define MOD 1000000007
using ll = long long;
using namespace std;
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 (a>b) { a=b; return 1; } return 0; }

int main(){
cin.tie(0);
ios::sync_with_stdio(false);
ll n, k;
cin >> n >> k;
vector<ll> cum(200005,0);
reps(i,200005,1){
    cum[i] =cum[i-1]+ i-1;
}

//選ぶ数字の数毎に組合せは重複しない
ll ans = 0;
reps(i,n+2,k){
    ll _min = cum[i];
    ll _max = cum[n+1]-cum[n+1-i];
    ans = (ans + _max - _min + 1)%MOD;
}

cout << ans << endl;

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

Measured memory_bytes: 4776
n=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
aa=sum(A) ; bb=sum(B)
if aa>bb:
    print("No");exit()
if aa==bb:
    if A==B:print("Yes");exit()
    print("No");exit()

C=[i-j for i,j in zip(A,B)]
D=[[0,0]]*n
for i in range(n):
    if C[i]>=0:
        D[i]= [0,C[i]]
    else:
        D[i]= [(-C[i]+ (C[i]%2))//2 , C[i]%2]
if sum([i[0] for i in D])>= sum([l[1] for l in D]):
    print("Yes")
else:
    print("No")

Measured memory_bytes: 73992
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace _0381
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] vs = RArInt();
            Console.WriteLine(Math.Abs(vs[1] - vs[0]));
        }
        static string RSt() { return Console.ReadLine(); }
        static int RInt() { return int.Parse(Console.ReadLine().Trim()); }
        static long RLong() { return long.Parse(Console.ReadLine().Trim()); }
        static double RDouble() { return double.Parse(Console.ReadLine()); }
        static string[] RArSt(char sep = ' ') { return Console.ReadLine().Trim().Split(sep); }
        static int[] RArInt(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => int.Parse(e)); }
        static long[] RArLong(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => long.Parse(e)); }
        static double[] RArDouble(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => double.Parse(e)); }
        static string WAr<T>(IEnumerable<T> array, string sep = " ") { return string.Join(sep, array.Select(x => x.ToString()).ToArray()); }
    }
}



Measured memory_bytes: 17928
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL_DEFINE
#include "../../DEBUG.hpp"
#endif
vector<vector<int>> Q;
vector<int> seq;
int n, m, q;
int ans;
// this function recursively builds the sequence of length n
// i means we are at the ith position in the sequence and num
// means that element at position i >= num (remember that the sequence has to be
// non decreasing.
void solve(int i, int num) {
  if (i == n) {
  // this means we have already made a sequence of length n
  // which is currently stored in seq
  // now just use brute force to check how many conditions of Q are satisfied and
  // accordingly update ans.
    int temp = 0;
    for (int j = 0; j < q; j++) {
      if (seq[Q[j][1] - 1] - seq[Q[j][0] - 1] == Q[j][2]) {
        temp += Q[j][3];
      }
    }
    ans = max(temp, ans);
    return;
  }
  // else we have not yet completed the sequence making process.
  // we can place all, numbers from num to m at the position i.
  for (int j = num; j <= m; j++) {
    seq.push_back(j);
    // every time, we place a number at the ith position we, try
    // building the rest, of the sequence, update the answer, remove the 
    // last inserted element and go for the next j.
    solve(i + 1, j);
    seq.pop_back();
  }
}

int main(void) {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  ans = 0;
  cin >> n >> m >> q;
  Q.resize(q, vector<int>(4));
  for (int i = 0; i < q; i++) {
    for (int j = 0; j < 4; j++) {
      cin >> Q[i][j];
    }
  }
  solve(0, 1);
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 3676
#include <iostream>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <limits>
#include <string>
#include <algorithm>
#include <unordered_set>
#include <unordered_map>
#include <map>
#include "math.h"
#include "assert.h"

using namespace std;


#define BUFF ios::sync_with_stdio(false)
#define epsilon 1e-07
#define pi 2 * acos(0.0);
#define mod 1000000007   // 1e9+7
#define ll long long
#define cerr if(false)cerr
#define watch(x) cerr << #x << " = " << x << endl;

/*

	Segment Tree
		- utilizada para consultar e atualizar valores em llervalos de v[0..n).
		- operações: 
			- build - O(n lg n).
			- search - O(lg n) - consulta o valor mínimo contido no llervalo [0..n-1].
			- add - O(lg n) - atualiza o valor de v(i).

			- soma (nulo = 0), mínimo (nulo = inf), etc.

*/

void build_segment_tree(vector<ll> & v, vector<ll> & st, ll nulo) {
	ll n = v.size();
	ll k = 1;

	while (pow(2, k) < n) k++;
	ll ns = pow(2,k);
	st.resize(2*ns);

	for(ll i=ns; i<2*ns; i++) {
		if (i - ns < n) st[i] = v[i-ns];
		else st[i] = nulo;
	}
 
	ll start = ns;
	ll delta = 2*ns;
	for(ll pot=k; pot>=0; pot--) {
		ll sz = pow(2,pot);
		for(ll i=start; i<delta; i+=2) {
			st[i/2] = max(st[i], st[i+1]);
		}
		delta = start;
		start /= 2;
	}

}

ll search(ll i, ll j, vector<ll> & st) {
	ll n = st.size() / 2;
	i += n;
	j += n;
	bool i_last = false;
	bool j_last = false;
	ll t = 0;
	while (i <= j) {
		if (!i_last and (i % 2 == 1 or j_last)) {
			t = max(t, st[i]);
			i++;
		}
		if (!j_last and (j % 2 == 0 or i_last)) {
			t = max(t, st[j]);
			j--;
		}
		if (!i_last and i % 2 == 1) {
			i_last = true;
		}
		if (!j_last and j % 2 == 0) {
			j_last = true;
		}
		i = i / 2;
		j = j / 2;
	}
	return t;
}

void add(ll x, ll i, vector<ll> & st) {
	ll n = st.size() / 2;
	i += n;
	st[i] += x;
	ll t = st[i];
	while (i >= 1) {
		st[i] = max(st[i], t);
		i /= 2;
	}
}

void show(vector<ll> & st) {
	cout << st.size() << ": ";
	for(ll i=0; i<st.size(); i++) {
		cout << st[i] << " ";
	}
	cout << endl;
}

int main() {

	ll n;
	cin >> n;
	vector<ll> h(n), a(n), dp(n+1, 0); 
	vector<ll> st;
	build_segment_tree(dp, st, 0);

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

	for(ll i=0; i<n; i++) {
		dp[h[i]] = max(dp[h[i]], search(0, h[i]-1, st) + a[i]);
		add(dp[h[i]], h[i], st);
	}

	ll ans = 0;
	for(ll i=0; i<=n; i++) {
		ans = max(ans, dp[i]);
	}
	cout << ans << endl;
}


Measured memory_bytes: 9088
import sys

N = int(input())

if N < 10:
    print('Yes')
else:
    for p in range(2, 10):
        if N % p == 0 and N / p < 10:
            print('Yes')
            break
        elif p == 9 and (N % p != 0 or N / p > 10):
            print('No')

Measured memory_bytes: 3064
N = int(input())
said = []
Wnow = input()
said.append(Wnow)

for i in range(N-1):
  Wnxt = input()
  if Wnow[-1] != Wnxt[0]:
    print('No')
    exit()
  if Wnxt in said:
    print('No')
    exit()
  said.append(Wnxt)
  Wnow = Wnxt
  
print('Yes')
  

Measured memory_bytes: 2940
#include <iostream>
#include <vector>
#include <string>
#include <cctype>
#include <cmath>
#include <iomanip>
#include <climits>
#include <cfloat>
#include <algorithm>
#define PB push_back
#define ll long long
#define ull unsigned long long
#define uint unsigned
#define PIE (3.14159265358979323846)
#define MOD 1000000007;
using namespace std;

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

    int a {}, b {};
    cin >> a >> b;
    if ((a+b)%2) cout<<"IMPOSSIBLE"<<endl;
    else cout<<(a+b)/2<<endl;
    return 0;
}


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

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

    for (int i = 0; i < 1000; i++) {
        if ( (a*i) % b == c ) {
            cout << "YES" << endl;
            return 0;
        }
    }

    cout << "NO" << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
 
int main(){
    int S,h,m,s;
    cin >>S;
    h = S / 3600;
    m = (S % 3600)/60;
    s = S % 60;
    
    cout << h <<":"<< m <<":"<< s << endl;
    return 0;
}


Measured memory_bytes: 3104
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <utility>
#include <functional>

using namespace std;

int main() {
	char a, b;

	cin >> a >> b;
	cout << (a == 'H' ? b : (b == 'H' ? 'D' : 'H')) << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
//#include <list>
//#include <queue>
//#include <unordered_map>
#include <algorithm>
//#include <string>
#include <cstring>
#include <cmath>
using namespace std;

//
//https://vjudge.net/contest/372054#problem/N
//https://vjudge.net/problem/AtCoder-dp_n/origin
//Rod Cut and cows problem like from middle
int n;
vector<long long int> pr;
long long int count(int i,int k,int j)
{
	if(i==0)
		return pr[j];
	return pr[j]-pr[i-1];
}

long long int make(vector<long long int> &a, vector<vector<long long int> > &dp, long long int i, long long int j)
{
	//cout<<i<<" "<<j<<"\n";
	if(i>j || j>=n || i>=n || i<0 || j<0)
		return 0;
	if(dp[i][j]!=0)
	{
		return dp[i][j];
	}
	if(i==j)
	{
		dp[i][j]=0;
		return 0;
	}
	/*if(i+1==j)
	{
		dp[i][j]=a[i]+a[j];
		return dp[i][j];
	}*/
	for(int k=i;k<=j;k++)
	{
		if(dp[i][j]==0)
		{
			dp[i][j]=make(a, dp, i, k) + make(a, dp, k+1, j) + count(i,k,j);
		}
		else
		{
			dp[i][j]=min(dp[i][j], make(a, dp, i, k)+make(a,dp,k+1,j)+count(i,k,j));
		}
	}
	return dp[i][j];
}

int main()
{
	//int n;
	long long int i,j,k,m;
	long long int x,y,z;
	cin>>n;
	//cout<<n<<"\n";
	vector<long long int> a(n);
	pr.resize(n);
	for(i=0;i<n;i++)
	{
		cin>>a[i];
		if(i==0)
		{
			pr[i]=a[i];
		}
		else
		{
			pr[i]=pr[i-1]+a[i];
		}
	}
	vector<vector<long long int> > dp(n, vector<long long int> (n,0));
	make(a,dp,0,n-1);
	/*for(i=0;i<n;i++)
	{
		for(j=0;j<n;j++)
		{
			cout<<dp[i][j]<<" ";
		}
		cout<<"\n";
	}*/
	cout<<dp[0][n-1];
	return 0;
}

Measured memory_bytes: 4840
import sys
import heapq


def input():
    return sys.stdin.readline().strip()


MOD = 10 ** 9 + 7
sys.setrecursionlimit(20000000)


def main():
    X, Y, A, B, C = map(int, input().split())
    red = list(map(int, input().split()))
    green = list(map(int, input().split()))
    nocolor = list(map(int, input().split()))

    red.sort()
    green.sort()
    nocolor.sort()
    answer = sum(red[A - X :]) + sum(green[B - Y :])
    heap = red[A - X :] + green[B - Y :]
    heapq.heapify(heap)
    flag = 0
    while heap and flag < C:
        m = heapq.heappop(heap)
        if nocolor[flag] > m:
            answer -= m
            answer += nocolor[flag]
            heapq.heappush(heap, nocolor[flag])
            flag += 1
        else:
            heapq.heappush(heap, m)
            flag += 1

    print(answer)


if __name__ == "__main__":
    main()


Measured memory_bytes: 23456
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, a, b) for (int i = (a); i < (b); i++)
//#include "library/debug.cpp"
using P = pair<ll, ll>;

struct combination {
    ll mod;
    vector<ll> fac, finv, inv;

    combination(int n, ll m)
        : fac(n), finv(n), inv(n) {
        mod = m;
        fac[0] = fac[1] = 1;
        finv[0] = finv[1] = 1;
        inv[1] = 1;
        for (int i = 2; i < n; i++) {
            fac[i] = fac[i - 1] * i % mod;
            inv[i] = mod - inv[mod % i] * (mod / i) % mod;
            finv[i] = finv[i - 1] * inv[i] % mod;
        }
    }

    ll c(int n, int k) {
        if (n < k)
            return 0;
        if (n < 0 || k < 0)
            return 0;
        return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
    }
};

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

    ll n, a, b, k;
    cin >> n >> a >> b >> k;
    ll mod = 998244353;
    combination x(700000, mod);
    ll ans = 0;
    for (ll i = 0; i <= n; i++) {
        if ((k - a * i) % b != 0) continue;
        ll j = (k - a * i) / b;
        ans += x.c(n, i) * x.c(n, j);
        ans %= mod;
    }
    cout << ans << endl;
    return 0;
}

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

public class Main {
	public static void main(String[] args){

		try {
			InputStreamReader isr = new InputStreamReader(System.in);
			BufferedReader br = new BufferedReader(isr);
			String buf = br.readLine();
			StringTokenizer st=new StringTokenizer(buf," ");
			int a = Integer.parseInt(st.nextToken());
			int b = Integer.parseInt(st.nextToken());

			System.out.println( a * b + " "+ 2 * ( a + b ) );

		} catch(IOException e) {
			System.err.println(e);
		}
	}
}

Measured memory_bytes: 16876
#include <stdio.h>
int main(){
  int A, B, a, count=0;
  int c[5];
  scanf("%d%d", &A, &B);
  for (; A<B+1 ;A++){
    a = A;
    for (int i=0; i<5; i++){
      c[i]=a%10;
      a/=10;
    }
    if (c[0]==c[4] && c[1]==c[3]){
      count++;
    }
  }
  printf("%d",count);
  return 0;
}

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

int main(void){
    ll l, r;
    ll mi = 2019;

    cin >> l >> r;
    for(ll i = l; i <= r; i++){
        for(ll j = i + 1; j <= r; j++){
            mi = min(mi, (i * j) % 2019);
            if(mi == 0){
                cout << mi << endl;
                return 0;
            }
        }
    }
    cout << mi << endl;
    return 0;

}

Measured memory_bytes: 256
N = int(input())
link = [set() for i in range(N)]
for i in range(N-1):
    u, v, w = map(int,input().split())
    link[u-1] |= {(v-1,w)}
    link[v-1] |= {(u-1,w)}
check = [(0, 0, -1)]
ans = [-1 for i in range(N)]
while check:
    now, d, From = check.pop()
    ans[now] = d % 2
    for next, dist in link[now]:
        if next == From:
            continue
        else:
            check.append((next, d + dist, now))
print('\n'.join(map(str,ans)))

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

int main()
{
    string s; cin>>s;
    int cnt[128]={};
    for(e: s) cnt[e]=1;

    bool ok=true;
    if (cnt['N']^cnt['S']) ok=false;
    if (cnt['E']^cnt['W']) ok=false;
    cout<<(ok ? "Yes" : "No")<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string.h>
#include <utility> 
#include <tuple>
#include <iterator>
#include <functional>
#include <numeric>
using namespace std;
#define rep(i,n) for(long i=0; i<n; i++)


void solve(){
  int n,d;
  cin >> n >> d;
  int ans;
  int tmp = d*2+1;
  if(n%tmp == 0) ans = n/tmp;
  else ans = n/tmp+1;
  cout << ans << endl;
}

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


Measured memory_bytes: 256
#include<stdio.h>
int main(void){
    int N;  
    scanf("%d",&N);
    for(int i=1;i<=9;i++){
        for(int j=1;j<=9;j++){
            if(i*j==N){
                printf("Yes\n");
                return 0;
            }
        }
    }
    printf("No\n");
}

Measured memory_bytes: 128
# coding: utf-8
import sys
#from operator import itemgetter
sysread = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
#from heapq import heappop, heappush
#from collections import defaultdict
sys.setrecursionlimit(10**7)
#import math
#from itertools import product, accumulate, combinations, product
#import bisect
#import numpy as np
#from copy import deepcopy
#from collections import deque

INF = 1 << 50



def run():
    N = int(sysread())
    XL = []
    for i in range(N):
        x,l = map(int, sysread().split())
        XL.append((x-l, l+x))
    XL = sorted(XL, key = lambda x:x[1])
    #print(XL)
    ans = 0
    pre_end = - (1 << 50)
    for left,right in XL:
        if pre_end <= left:
            ans += 1
            pre_end = right
    print(ans)


if __name__ == "__main__":
    run()

Measured memory_bytes: 24628
H,W=map(int,input().split())
A=[0]*H
for i in range(H):
    A[i]=list(map(int,input().split()))
    for j in range(W):
        A[i][j]%=2
f=0
LIST=[]
for i in range(H):
    if(i%2==0):
        t=0
    else:
        t=W-1
    for j in range(W):
        k=abs(j-t)
        if(A[i][k]==1):
            if(f==1):
                q=i
                w=k
                while(True):
                    T=[]
                    T.append(a+1)
                    T.append(b+1)
                    if((b==0 and a%2==1) or (b==(W-1) and a%2==0)):
                        a+=1
                    elif(a%2==0):
                        b+=1
                    else:
                        b-=1
                    T.append(a+1)
                    T.append(b+1)
                    LIST.append(T)                        
                    if(q==a and w==b):
                        f=0
                        A[a][b]=0
                        break
                    
            else:
                a=i
                b=k
                A[a][b]=0
                f=1
        
print(len(LIST))
for i in range(len(LIST)):
    T=""
    for j in range(len(LIST[i])):
        T=T+str(LIST[i][j])+" "
    print(T[0:-1])


Measured memory_bytes: 29788
#include<iostream>
using namespace std;
typedef long long ll;

const int MAX_N = 303;
const int MAX_A = 303;
const ll MOD = 998244353;

ll A[MAX_N], dp[MAX_N][MAX_N * MAX_A], sub_dp[MAX_N][MAX_N * MAX_A];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    ll sum = 0;
    for (int i = 1; i <= N; i++) {
        cin >> A[i];
        sum += A[i];
    }
    // main
    dp[0][0] = 1;
    for (int i = 1; i <= N; i++) {
        for (int j = 0; j <= sum; j++) {
            dp[i][j] = (dp[i][j] + (dp[i - 1][j] * 2) % MOD) % MOD;
            if (j - A[i] >= 0) dp[i][j] = (dp[i][j] + dp[i - 1][j - A[i]]) % MOD;
        }
    }
    // sub
    sub_dp[0][0] = 1;
    for (int i = 1; i <= N; i++) {
        for (int j = 0; j <= sum; j++) {
            sub_dp[i][j] = (sub_dp[i][j] + sub_dp[i - 1][j]) % MOD;
            if (j - A[i] >= 0) sub_dp[i][j] = (sub_dp[i][j] + sub_dp[i - 1][j - A[i]]) % MOD;
        }
    }
    ll not_ans = (MOD - (sum % 2 == 0 ? sub_dp[N][sum / 2] : 0)) % MOD;
    for (int i = (sum + 1) / 2; i <= sum; i++) {
        not_ans = (not_ans + dp[N][i]) % MOD;
    }
    ll ans = 1;
    for (int i = 0; i < N; i++) ans = (ans * 3) % MOD;
    cout << (ans - (3 * not_ans) % MOD + MOD) % MOD << endl;
    return 0;
}

Measured memory_bytes: 433664
n,m,x = map(int,input().split())
a = list(map(int,input().split()))
cnt_r = 0
cnt_l = 0
road = [True]*(n+1)
for i in a:
    road[i] = False
for i in range(x,n+1):
    if not road[i]:
        cnt_r += 1
for i in range(x,-1,-1):
    if not road[i]:
        cnt_l += 1
ans = min(cnt_r,cnt_l)
print(ans)

Measured memory_bytes: 3064
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.PriorityQueue;
import java.util.Scanner;

class Main {
    static final int MOD = 1000000007;
    static final int INF = 1 << 30;

    Main() {
        Scanner sc = new Scanner(System.in);
        String N = sc.next();
        System.out.println(N.charAt(0)+""+(N.length()-2)+""+N.charAt(N.length()-1));
    }

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


Measured memory_bytes: 23764
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#ifdef tabr
#include "library/debug.cpp"
#else
#define debug(...) 0
#endif

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s;
    cin >> s;
    int q;
    cin >> q;
    string a, b;
    int rev = 0;
    while (q--) {
        int t;
        cin >> t;
        if (t == 1) {
            rev ^= 1;
        } else {
            int f;
            cin >> f;
            char c;
            cin >> c;
            if (rev == 0) {
                if (f == 1) {
                    a.push_back(c);
                } else {
                    b.push_back(c);
                }
            } else {
                if (f == 1) {
                    b.push_back(c);
                } else {
                    a.push_back(c);
                }
            }
        }
    }
    // a + s + b
    if (rev == 0) {
        reverse(a.begin(), a.end());
        cout << a << s << b << endl;
    } else {
        reverse(s.begin(), s.end());
        reverse(b.begin(), b.end());
        cout << b << s << a << endl;
    }
    return 0;
}

Measured memory_bytes: 1040
#include<algorithm>
#include<bitset>
#include<cmath>
#include<complex>
#include<cstdlib>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<string>
#include<utility>
#include<vector>

using namespace std;

#define ll long long
#define pal pair<ll,ll>
#define pad pair<double,double>
#define PB push_back
#define MP make_pair
#define F first
#define S second

const ll MOD = 1e9+7;
const ll INF = 1e18;
const double EPS = 1e-8;

long long MODPOW(long long x, long long n) {
    long long ret = 1;
    while (n > 0) {
        if (n & 1) ret = ret * x % MOD;
        x = x * x % MOD;
        n >>= 1;
    }
    return ret;
}

template<typename T,typename U>
bool chmax(T& max, const U& x){
	if(max<x){
		max = x;
		return true;
	}
	return false;
}

template<typename T,typename U>
bool chmin(T& min, const U& x){
	if(min>x){
		min = x;
		return true;
	}
	return false;
}


int main(){
	ll n,m,k,ans=0;
	cin >> n >> m >> k;
	vector<ll> a(n+1,0),b(m+1,0);
	ll tmp;
	for(ll i=1;i<=n;i++){
		cin >> tmp;
		a[i]=a[i-1]+tmp;
	}
	for(ll i=1;i<=m;i++){
		cin >> tmp;
		b[i]=b[i-1]+tmp;
	}
	for(ll i=0;i<=n;i++){
		if(k<a[i]){
			continue;
		}
		ll rest = upper_bound(b.begin(),b.end(),k-a[i])-b.begin();
		chmax(ans,i+rest-1);
	}
	cout << ans << endl;
}

Measured memory_bytes: 6376
#include<bits/stdc++.h>
#define int long long
using namespace std;
int n,m,lsg;
int read(){
	char c=getchar();while (c!='-'&&(c<'0'||c>'9'))c=getchar();
	int k=1,kk=0;if (c=='-')k=-1,c=getchar();
	while (c>='0'&&c<='9')kk=kk*10+c-'0',c=getchar();return k*kk;
}int doit(int x){int k=1;for (int i=2;i<=x;i++)(k*=i)%=lsg;return k;}
signed main(){
	n=read();m=read();lsg=1e9+7;if (abs(n-m)==0)cout<<doit(n)*doit(m)*2%lsg<<endl;
		else if (abs(n-m)==1)cout<<doit(n)*doit(m)%lsg<<endl;else cout<<0<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define SP ios_base::sync_with_stdio(false); cin.tie(NULL);
using namespace std;
 
int main()
{
  	SP;
	int d,t,s;
  	cin>>d>>t>>s;
  	if(s*t>=d)
      cout<<"Yes"<<endl;
  	else
      cout<<"No"<<endl;
  	return 0;
}

Measured memory_bytes: 3652
import collections

def comb2(n):
    return (n*(n-1))//2

n = int(input())
a = list(map(int,input().split()))

ans = [0]*(n+1)
res = 0

for i in range(n):
    ans[i+1] = a[i]+ans[i]

col = collections.Counter(ans)

for i in col:
    res += comb2(col[i])

print(res)


Measured memory_bytes: 41752
#include<queue>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<vector>
#include<set>
#define ll long long
#define mod 1000000007
using namespace std;
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*10+ch-'0';
        ch=getchar();
    }
    return x*f;
}
const int N=1e5+10;
const int M=1e7+10;
vector<int> a[N];
const int inf=0x3f3f3f3f;
ll min(ll x,ll y)
{
    return x<y?x:y;
}
int n,m,t,flag,c[N],cnt,tot,ans[N],pre[N];
void dfs(int u,int fa){
    if(flag) return;
    int v,f=0;
    for(int i=0;i<a[u].size();i++){
        v=a[u][i];
        if(v==fa) continue;
        if(c[v]!=1) cnt++;
        else continue;
        ans[t++]=v;
        c[v]=1;
        if(cnt>=n){
            flag=1;
            return;
        }
        dfs(v,u);
        break;
    }
}
void dfs2(int u,int fa){
    if(flag) return;
    int v,f=0;
    //cout<<u<<endl;
    for(int i=0;i<a[u].size();i++){
        v=a[u][i];
        if(v==fa) continue;
        if(c[v]!=1) cnt++;
        else continue;
        pre[tot++]=v;
        c[v]=1;
        if(cnt>=n){
            flag=1;
            return;
        }
        dfs2(v,u);
        break;
    }
}
int main()
{
    while(~scanf("%d%d",&n,&m))
    {
        memset(c,0,sizeof(c));
        int u,v;
        for(int i=0;i<=n;i++) a[i].clear();
        for(int i=0;i<m;i++)
        {
            u=read();v=read();
            a[u].push_back(v);
            a[v].push_back(u);
        }
        t=flag=cnt=0;
        ans[t++]=1;
        c[1]=1;
        dfs(1,1);
        flag=tot=0;
        dfs2(1,1);
        printf("%d\n",t+tot);
        int f=1;
        for(int i=tot-1;i>=0;i--){
            if(!f) printf(" ");
            if(f) f=0;
            printf("%d",pre[i]);
        }
        for(int i=0;i<t;i++){
            if(!f) printf(" ");
            if(f) f=0;
            printf("%d",ans[i]);
        }
        puts("");
    }
    return 0;
}


Measured memory_bytes: 7040
s=int(input())
lis=[s]
for i in range(2,10**7):
  if lis[i-2]%2==0:
    if lis[i-2]//2 in lis:
      print(i)
      break
    else:
      lis.append(lis[i-2]//2)
  else:
    if 3*lis[i-2]+1 in lis:
      print(i)
      break
    else:
      lis.append(3*lis[i-2]+1)
  

Measured memory_bytes: 2940
N,K = map(int,input().split())
S = list(input())
ans = ""
if S[K-1] == "A":
  S[K-1] = "a"
if S[K-1] == "B":
  S[K-1] = "b"
if S[K-1] == "C":
  S[K-1] = "c"
for n in S:
    ans += n
print(ans)


Measured memory_bytes: 3060
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

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

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef unsigned long long ULL;

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

#define MP make_pair
#define EACH(i,c) for(auto i: c)
#define SORT(c) sort((c).begin(),(c).end())

#define ALL(a)  (a).begin(),(a).end()

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

	LL a = 100;
	int ret = 0;

	while(1){
		ret++;
		a *= 1.01;
		if(X <= a) break;
	}

	cout << ret << endl;


	return 0;
}


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

#define ALL(v) v.begin(), v.end()
#define V vector
#define P pair
using ll = long long;
using ld = long double;
const int MOD = 1e9+7;


int main() {
    int n; cin >> n;
    V<ll> a(n * 3);
    for(int i = 0; i < n * 3; i++) cin >> a[i];

    sort(ALL(a));

    // 1 2 3 4 5 5 7 8 9
    ll ans = 0;
    for(int i = 0; i < 2 * n; i+=2){
        ans += a[3 * n - 2 - i];
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 5636
#include <bits/stdc++.h>
#define fr(i, n, m) for(int i = (n); i < (m); i ++)
#define pb push_back
#define st first
#define nd second

using namespace std;
typedef long long ll;
ll dp[3000][3000];

int main()
{
    int n, x;
    cin >> n >> x;
    int a[n];
    fr(i, 0, n) cin >> a[i];

    memset(dp, 0, sizeof(dp));
    dp[0][0] = 1;


    fr(i, 0, n){
        for(int j = 2500; j >= 0; j --){
            fr(k, 0, n){
                dp[j + a[i]][k + 1] += dp[j][k];
            }
        }
    }
    ll ans = 0;
    fr(i, 1, n + 1){
        ans += dp[i * x][i];
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 70528
#include <stdio.h>
#include <iostream>

using namespace std;

int main(){
    long long n,x;
    long long a[100010];
    cin>>n>>x;
    for(int i=0;i<n;i++) cin>>a[i];
    long long ans=0ll;
    for(int i=0;i<n-1;i++){
        if(a[i]+a[i+1]>x){
            ans+=(a[i]+a[i+1]-x);
            if(a[i]>x){
                a[i+1]=0;
            }
            else{
                a[i+1]=x-a[i];
            }
        }
    }
    
    cout<<ans<<endl;
    return 0;
}

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

long long N;
long long L[4000];

void input()
{
    cin >> N;
    for(long long int i = 1; i <= N; i++)
        cin >> L[i];
}
void solve()
{
    input();
    vector<long long> v(N);
    for(long long int i = 0; i < N; i++)
        v[i] = L[i+1];
    sort(v.begin(), v.end());
    long long  ans = 0;
    for(long long i= N - 1; i >= 0; i--)
    {
        for(long long j= i - 1; j>= 0; j--)
        {
            auto itr = lower_bound(v.begin(), v.end(), v[i] + v[j]);
            long long ng = distance(itr, v.end());
            ans += (N - 1 -i) - ng;
        }
    }
    cout << ans << endl;
    return;
}

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


Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
	static StringBuilder sb=new StringBuilder();
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String input = sc.nextLine();
		char[] c = input.toCharArray();
		
		for(char c1:c){
			if(c1 >= 'a' && c1 <= 'z'){
				sb.append((char)(c1-32));
			}else if(c1 >= 'A' && c1 <= 'Z'){
				sb.append((char)(c1+32));
			}else{
				sb.append((char)(c1));
			}
		}
		
		//出力
		System.out.println(sb);
	}
	
}


Measured memory_bytes: 26168
#include <iostream>
#include <cmath>
using namespace std;
int main(void)
{
	int i;
	double n, m, x0, x, temp, ans=0;

	cin>>n>>m;

	x0=pow(0.5, m);
	x=1.0-x0;
	temp=(100*(n-m)+1900*m);

	for(i=1; i<10000; i++){
		ans+=x0*temp*i*pow(x, i-1);
	}
	cout<<(int)(ans+0.5)<<endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
using ll=long long int;
using ld=long double;
using VI=vector<ll>;
using VD=vector<ld>;
using VVI=vector<VI>;
using VC=vector<char>;
using VVC=vector<VC>;
using VS=vector<string>;
using PLL =pair<ll,ll>;
using PLD=pair<ld,ld>;
using VPLL=vector<PLL>;
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element((x).begin(),(x).end())
#define MIN(x) *min_element((x).begin(),(x).end())
#define SORTR(x) sort((x).rbegin(),(x).rend())
#define SORT(x) sort((x).begin(),(x).end())
#define SUM(x) accumulate((x).begin(),(x).end(), 0)
#define FILL(x,a) fill(x.begin(),x.end(),a)
#define EACH(i,x) for(typeof((x).begin()) i=(x).begin(); i!=(x).end(); ++i)
#define COUT(x) cout<<x<<"\n"

const ll INF = 1e18;
const ld EPS   = 1e-10;
const int MOD  = int(1e9)+7;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template <class BidirectionalIterator>
bool next_partial_permutation(BidirectionalIterator first, BidirectionalIterator middle,BidirectionalIterator last){reverse(middle, last); return next_permutation(first , last);}
ll gcd(ll x, ll y) { return (x % y)? gcd(y, x % y): y; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
ll GCD(VI v){ll a = v[0]; for (ll i = 1; i<SIZE(v); i++) {a = gcd(a, v[i]);} return a;}
ll LCM(VI v){ll a = v[0]; for (ll i = 1; i<SIZE(v); i++) {a = lcm(a, v[i]);} return a;}


void Main()
{
	ll n=0,a,b,h; string s="";
	ll res=0; string sres="Yes";
	cin>>a;
	cin>>b;
	cin>>h;
	res=(a+b)*h/2;

	cout << res << "\n";
	return;
}

int main()
{
	std::cin.tie(0);
	std::ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
	Main();
}


Measured memory_bytes: 256
/*
    Author - Param Kothari
    Ah shit, here we go again
*/
 
/* Ordered Set Implementaton:

#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 

using namespace __gnu_pbds;

typedef tree<
    int,
    null_type,
    less<int>,
    rb_tree_tag,
    tree_order_statistics_node_update>
ordered_set;
*/

#include <bits/stdc++.h>
 
using namespace std;

#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define pb push_back
#define mk make_pair 
 
typedef long long ll;
typedef long double ld;

void solve(){
    string s;
    cin >> s;
    if(s[2] == s[3] && s[4] == s[5]){
        cout << "Yes\n";
    }
    else cout << "No\n";
    return;
}
 
int main(){
    IOS;
    int t = 1;
    //cin >> t;
    while(t--){
        solve();
    }
    return 0;
}


Measured memory_bytes: 256
parseInt(x::String) = parse(Int, x)
parseInt(x::SubString{String}) = parse(Int, x)
parseInt(x::Char) = parse(Int, x)
parseInt(x::Float64) = trunc(Int, x)
parseFloat(x::String) = parse(Float64, x)
parseFloat(x::Int) = trunc(Float64, x)
parseFloat(x::SubString{String}) = parse(Float64, x)
parseFloat(x::Char) = parse(Float64, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
    s=chomp(readline())
    i=length(s)
    ans="YES"
    while i>0
        if i<=4
            ans="NO"
            break
        elseif s[i-4:i]=="dream" || s[i-4:i]=="erase"
            i-=5
        elseif i<=5
            ans="NO"
            break
        elseif s[i-5:i]=="eraser"
            i-=6
        elseif i<=6
            ans="NO"
            break
        elseif s[i-6:i]=="dreamer"
            i-=7
        else
            ans="NO"
            break
        end
    end
    println(ans)
end
main()

Measured memory_bytes: 116752
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <fstream>
#include <sstream>
#include <iomanip>

using namespace std;

long long MOD = 1000000007;

int main(){
    int A,B;
    cin >> A >> B;
    cout << max(max(A+B, A-B), A*B) << endl;
}

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

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

  if (N % 10 == 3) {
    cout << "bon" << endl;
  }
  else if (N % 10 == 0 || N % 10 == 1 || N % 10 == 6 || N % 10 == 8) {
    cout << "pon" << endl;
  }
  else {
    cout << "hon" << endl;
  }
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define mod 1000000007
#define pb push_back
#define pi pair<int,int>
#define vi vector<int>
#define vpi vector< pi >
const int N=110;

int dp[N][10];
int h,w,k;

int hh(int y,int x)
{
	if(x>=w||x<0||y<0) return 0;
	
	if(y==0)
	{
		//cout<<y<<" "<<x<<" "<<msk<<"\n";
		if(x==k-1) return 1;
		return 0;
	}
	//cout<<y<<" "<<x<<" "<<msk<<"\n";
	if(dp[y][x]!=-1) return dp[y][x];
	int ans=0;
	for(int i=0;i<(1<<(w-1));i++)
	{
		int f=0;
		for(int j=0;j<=w-2;j++)
		{
			if(i&(1<<j) && i&(1<<(j+1)))
				f=1;
		}
		if(f) continue;
		//cout<<"wtf";
		if(i&(1<<x))
			ans=(ans+hh(y-1,x+1))%mod;
		else if(x>0 && i&(1<<(x-1)))
			ans=(ans+hh(y-1,x-1))%mod;
		else
			ans=(ans+hh(y-1,x))%mod;
	}
	dp[y][x]=ans;
	return ans;
}

int main()
{
	cin>>h>>w>>k;
	memset(dp,-1,sizeof dp);
	ll ans=0;
	//cout<<w-2<<" 12\n";
	for(int i=0;i<(1<<(w-1));i++)
	{
		int f=0;
		for(int j=0;j<=w-2;j++)
		{
			if((i&(1<<j)) && (i&(1<<(j+1))))
				f=1;
		}
		if(f) continue;
		//cout<<i<<"hh\n";
		if(i&1)
		ans=(ans+hh(h-1,1))%mod;
		else
		ans=(ans+hh(h-1,0))%mod;
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        AizuMinCoinChange solver = new AizuMinCoinChange();
        solver.solve(1, in, out);
        out.close();
    }

    static class AizuMinCoinChange {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int m = in.nextInt();
            int n = in.nextInt();
            int[] a = new int[n];

            for (int i = 0; i < n; i++) {
                a[i] = in.nextInt();
            }

            out.printf("%d\n", minCoins(m, a, n));
        }

        private int minCoins(int m, int[] a, int n) {
            int[] dp = new int[m + 1];

            for (int i = 1; i < m + 1; i++) {
                dp[i] = Integer.MAX_VALUE - 1;
                for (int j = 0; j < n; j++) {
                    if (i >= a[j]) {
                        dp[i] = Math.min(dp[i], 1 + dp[i - a[j]]);
                    }
                }
            }

            return dp[m];
        }

    }
}




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


int main(){
    int N,K;
    cin>>N>>K;
    int ans=(N-1)/(K-1);
    if((N-1)%(K-1)==0)cout<<ans<<endl;
    else cout<<ans+1<<endl;
}

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

#define REP(i, n) for(decltype(n) i = 0; i < n; i++)

#define ALL(c)   c.begin(), c.end()
#define SORT(c)  std::sort(ALL(c))
#define RSORT(c) std::sort(ALL(c), std::greater<decltype(c)::value_type>())

using namespace std;
using ll = long long;

const int MOD  = (int)1e9 + 7;
const int INF  = (int)1e9 + 1;
const ll  LINF = (ll)1e18 + 1;

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

    string S;
    std::cin >> S;

    int    ans  = 1;
    string prev = S.substr(0, 1);
    for(size_t i = 1; i < S.size(); i++) {
        if(prev != S.substr(i, 1)) {
            prev = S.substr(i, 1);
        }
        else {
            prev = S.substr(i, 2);
            i++;
        }
        if(i != S.size()) ans++;
    }

    std::cout << ans << std::endl;

    return 0;
}


Measured memory_bytes: 720
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string>
#include<iostream>
#define mod 1000000007
using namespace std;
int main()
{
	char c;
	scanf("%c",&c);
	if(c=='A') printf("T");
	else if(c=='T') printf("A");
	else if(c=='C') printf("G");
	else printf("C");
}

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

#define all(x) begin(x), end(x)

using i64 = int_fast64_t;
using u64 = uint_fast64_t;
using f64 = double;
using p64 = pair<i64, i64>;

constexpr i64 INF = INT_FAST64_MAX / 2;

void solve() {
    i64 n;
    cin >> n;
    vector<vector<i64>> a(n, vector<i64>(n));
    for (auto& e : a) for (auto& f : e) cin >> f;

    vector<i64> dp(1 << n, -1);
    auto f = [&](auto g, i64 t) -> i64 {
        if (dp[t] != -1) return dp[t];

        i64 res = 0;
        for (i64 i = 0; i < n; i++) {
            for (i64 j = i + 1; j < n; j++) {
                if ((t >> i) & 1 && (t >> j) & 1) res += a[i][j];
            }
        }

        for (i64 u = (1 << n) - 1; u > 0; u--) {
            u &= t;
            if (u != t && (t ^ u) != t) res = max(res, g(g, u) + g(g, t ^ u));
        }

        return dp[t] = res;
    };

    cout << f(f, (1 << n) - 1) << endl;
}

int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
}


Measured memory_bytes: 3724
#include <stdio.h>

int gcd(long a, long b);

int main(void)
{
	long a, b;
	
	while (scanf("%ld%ld", &a, &b) != EOF){
		printf("%d\n", gcd(a, b));
	}
	
	return (0);
}

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

Measured memory_bytes: 596
N, K = map(int, raw_input().split())
V = map(int, raw_input().split())

ans = 0
for l in range(K+1):
  for r in range(K+1):
    if l+r<=K and l+r<=N:
      T = V[:l]+(V[-r:] if r>0 else [])
      T = sorted(T)[::-1]
      for _ in range(K-l-r):
        if len(T)>0 and T[-1]<0:
          T.pop()
      ans = max(ans, sum(T))
print ans


Measured memory_bytes: 2692
import java.util.Scanner;

public class Main{
    public static void main(String[] arg){
        int a, b, c, d;
        c = 0;
        d = 0;
        Scanner scan = new Scanner(System.in);
        a = scan.nextInt();
        b = scan.nextInt();
        c = a * b;
        d = 2 * a + 2 * b;
        System.out.println(c +" "+ d);
    }
}


Measured memory_bytes: 26232
#include <stdio.h>
int main()
{
    int x,n,sum=0;
    while (scanf("%d",&x)!=EOF)
    {
        n=x;
   while (x!= 0)
    {
        sum=sum*10+x%10;
        x /=10;
    }
    if (n==sum)
    printf("Yes\n");
    else
    printf("No\n");
    sum=0;
    }
   return 0;
}

Measured memory_bytes: 128
#ifdef DEBUG
#include "../utils.cpp"
#endif
#include <bits/stdc++.h>
/*
Problem
 
Category
DP
 
URL:
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DPL_1_C&lang=ja

考察:
ナップサック問題。何個でも買える
dp[i][w] = 重さw以下でi番目までの品物を使ったときの価値の最大値
dp[i][w] = max(dp[i-1][w], dp[i][w-w_i]+ v_i)
O(N*W)

Date: 2020/04/18
*/
 

using namespace std;
using ll = int64_t;
#define int int64_t

 
/* ==== declarations ====== */
// functions
void solve();
void getInput();
 
// global variables
int N, W;
vector<vector<int>> dp;
vector<int> V;
vector<int> Weights;

/* ======================== */

void getInput() {
    cin>>N>>W;
    V = vector<int>(N, 0);
    Weights = vector<int>(N, 0);
    
    for(int i=0; i<N; ++i) {
        cin>>V[i]>>Weights[i];
    }
}
 
 
void solve() {
    dp = vector<vector<int>>(N, vector<int>(W+1, 0));
    for(int j=0; j<W+1; ++j) {
        int w = Weights[0];
        if (j - w >= 0)
            dp[0][j] = dp[0][j-w] + V[0];
        else dp[0][j] = 0;        
    }
    for(int i=1; i<N; ++i) {
        for(int j=0; j<W+1; ++j) {
            if (j-Weights[i] < 0) dp[i][j] = dp[i-1][j];
            else dp[i][j] = max(dp[i-1][j], dp[i][j-Weights[i]]+V[i]);
        }
    }
    cout<<dp[N-1][W]<<endl;
}
 
 
 
signed main(){
    getInput();
    solve();
    return 0;
}




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


void solve(long long N, long long K, std::vector<long long> h){
  sort(h.begin(), h.end());

  long long answer = pow(10, 9);

  for (int i=0;i<N-K+1;i++) {
    if (answer > h[K+i-1] - h[i]) answer = h[K+i-1] - h[i];
  }

  cout << answer << endl;
}

// Generated by 1.1.3 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    scanf("%lld",&N);
    long long K;
    scanf("%lld",&K);
    std::vector<long long> h(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&h[i]);
    }
    solve(N, K, std::move(h));
    return 0;
}


Measured memory_bytes: 1024
#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 crep(i) for(char i='a';i<='z';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(){
    int A,B,C,D;cin >> A >> B >> C >> D;
    cout<<(A<C ? max(min(B,D)-C,0) : max(min(B,D)-A,0)) << endl;
}

Measured memory_bytes: 256