akhauriyash/Code-Regression huggingface dataset:
import java.util.*;

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

	int n = sc.nextInt();

	while(n!=0){

	    w = sc.nextInt();
	    h = sc.nextInt();

	    field = new int[n][2];
	    for(int i=0; i<n; i++){
		field[i][0] = sc.nextInt();//ØÌxÀW
		field[i][1] = sc.nextInt();//ØÌyÀW
	    }

	    int s = sc.nextInt();
	    int t = sc.nextInt();

	    int count = 0;
	    int max = 0;
	    for(int i=1; i<=h; i++){//ÍÍð1¸Â¸ç·
		for(int j=1; j<=w; j++){
		    count = 0;
		    for(int k=0; k<n; k++){
			if(field[k][0]>=j && field[k][0]<=j+s-1//ÍÍàÉ êÎ 
			   && field[k][1]>=i && field[k][1]<=i+t-1)count++;
		    }
		    if(count>max)max = count;
		}
	    }	   
	    
	    System.out.println(max);

	    n = sc.nextInt();
	}
    }
}

Measured memory_bytes: 12000
#include <stdio.h>
#include <stdlib.h>
typedef long long ll;
#define rep(i,n) for(int i=0;i<(int)(n);i++)

//ll
#define QMAX 10101010
typedef struct quet{ ll que[QMAX], front, back; } QUEUE;
QUEUE *make_queue(){ QUEUE *q = malloc(sizeof(QUEUE)); q->back = 0; q->front = 0; return q;}
void push(QUEUE *q, ll val){ q->que[q->back++] = val; if(q->back == QMAX) q->back = 0; }
ll pop(QUEUE *q){ ll val = q->que[q->front++]; if(q->front == QMAX) q->front = 0; return val; }
ll front(QUEUE *q){ return q->que[q->front]; }
int size(QUEUE *q){ return (q->back - q->front < 0? QMAX + q->back - q->front:q->back - q->front); }

int main(){
    int n,ans=0; scanf("%d", &n);
    ll val = 0;
    QUEUE *q = make_queue();
    push(q, 3);
    push(q, 5);
    push(q, 7);
    while(1){
        ll tmp = pop(q);
        if(tmp > n) break;
        push(q, tmp*10+3);
        push(q, tmp*10+5);
        push(q, tmp*10+7);
        val = tmp;
        int cnt[20] = {0};
        while(tmp) { cnt[tmp%10]++; tmp /= 10; }
        if(cnt[3]&&cnt[5]&&cnt[7]) ans++;
    }

    printf("%d\n", ans);
}


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

#define ll long long
#define ar array

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

	int k, n;
	cin >> k >> n;
	int a[n];
	for(int i=0; i<n; ++i)
		cin >> a[i];
	int ans=a[0]+k-a[n-1];
	for(int i=0; i+1<n; ++i)
		ans=max(a[i+1]-a[i], ans);
	cout << k-ans;
}

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

using namespace std;

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

    int n;
    cin>>n;

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

    arr.erase(unique(arr.begin(),arr.end()),arr.end());

    for(int i=0;i<arr.size();i++) cout<<arr[i]<<(i==arr.size()-1?'\n':' ');

    return 0;
}



Measured memory_bytes: 3368
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pi;
typedef pair<ll, ll> pll;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;

#define imx INT_MAX
#define imn INT_MIN
#define llmx LLONG_MAX
#define llmn LLONG_MIN
#define INF         100000000000000000
#define PI          3.1415926535897932384626433832795l



#define fi first
#define se second
#define pb push_back
#define f_s(a) sort(a.begin(), a.end())
#define b_s(a) sort(a.rbegin(), a.rend())
#define p(a) cout<<a<<"\n"


// ll mod = 1000000007;
// #define l(i, )
// #define rl(i, a, b) for(int i = a; i < b; i++)






// struct mycomp {
//     bool operator() (const pair<int,int> &a, const pair<int,int> &b) const{
//         if (a.second-a.first != b.second-b.first)
//         return (a.second-a.first > b.second-b.first);
//         return a.first < b.first;
//     }
// };



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


ll extended_gcd(ll a, ll b, ll& x, ll& y)
{
	if(b==0)
	{
		x=1;
		y=0;
		return a;
	}
	ll x1, y1;
	ll d = extended_gcd(b, a%b, x1, y1);
	x=y1;
	y=x1-y1*(a/b);
	return d;
}

////////////////////SIEVE OF ERATOSTHENES//////////////////////
vector<int> sieveoferatosthenes(int n)
{
	vector<bool> prime(n+1, true);
	for(int i = 2; i <= sqrt(n); i++)
	{
		if(prime[i])
		{
			for(int j = i*i; j<=n; j+=i)
			{
				prime[j]=false;
			}
		}
	}	
	vector<int> all_primes;
	for(int i = 2; i <=n; i++)
	{
		if(prime[i]) all_primes.pb(i);
	}
	return all_primes;
}

////////////////////BINARY EXPONENTIATION///////////////////////
ll bin_exp(ll a, ll b, ll mod)
{
	ll ans = 1;
	while(b)
	{
		if(b%2)
		{
			b--;
			ans = (ans%mod*a%mod)%mod;
		}
		b/=2;
		a = (a%mod*a%mod)%mod;
	}
	return ans;
}


///////////////////////////BFS//////////////////////////////////
void bfs(vector<int>& distance, vector<int> a[], vector<bool>& visited, int u, vector<int>& parent)
{
	visited[u]=true;
	parent[u]=-1;
	distance[u]=0;
	queue<int> q;

	q.push(u); 
    while (!q.empty()) { 
  
        int f = q.front(); 
        q.pop(); 
  		for(int i =0; i < a[f].size(); i++)
  		{
  			if(visited[a[f][i]]==false)
  			{
  				distance[a[f][i]]=distance[f]+1;
  				parent[a[f][i]]=f;
  				visited[a[f][i]]=true;
  				q.push(a[f][i]);
  			}
  		}
    } 

}

void solve()
{

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

	// #ifndef ONLINE_JUDGE
	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
	// #endif
	char c;
	cin>>c;
	if(isupper(c)) p('A');
	else p('a');
	// int n;
	// cin>>n;
	return 0;
}

Measured memory_bytes: 3672
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;

string s;

int main()
{
	cin>>s;
	int L = s.size() - 8;
	//printf("%d\n", L);
	string x = "";
	for(int i = 0; i < L; i++) x += s[i];
	cout<<x<<endl;
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
typedef unsigned long long int ulli;
#define vec(s) vector
;
#define vvec(s) vector<vector
> ;
typedef vector<lli> vi;
typedef vector<vi> vvi;
typedef pair<lli,lli> pii;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define YN(x) cout<<(bool x?"Yes":"No")<<endl;
#define out(s) cout<<s<<endl;
#define pb(s) push_back(s);
#define sp " ";
#define INF 10000000000
#define all(s) s.begin(),s.end()
void vout(vector<int> v){
    for(int i=0;i<v.size();i++)
    cout<<v.at(i)<<endl;
}
int main(){
    lli n;
    cin>>n;
    lli ans=0;
    rep(i,n+1){
        int now=i*1.08;
        if(now==n){ans=i;break;}
    }
    if(ans==0){
        out(":(");
    }
    else{
        out(ans);
    }
}

Measured memory_bytes: 256
#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>;

const int MAX_N = 1e5;
bool is_prime[MAX_N];
int sum[MAX_N];
bool calc_prime(int n) {
  int root = sqrt(n);
  for (int i = 2; i <= root; i++) {
    if (n % i == 0) return false;
  }
  return true;
}

bool like(int n) { return is_prime[n] && is_prime[(n + 1) / 2]; }

int main() {
  is_prime[2] = 1;
  for (int i = 3; i < MAX_N; i += 2) is_prime[i] = calc_prime(i);
  ll cnt = 0;
  for (int i = 1; i <= MAX_N; i += 2) {
    if (like(i)) cnt++;
    sum[i] = cnt;
  }

  int q;
  cin >> q;
  rep(i, q) {
    int l, r;
    cin >> l >> r;
    ll ans = sum[r] - sum[l];
    if(like(l)) ans += 1;
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 1152
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

	Scanner sca = new Scanner(System.in);
	int n = sca.nextInt();
	int a[] = new int[n];
	int sum = 0;
	for(int i = 0; i < n; i++) {
		a[i] = sca.nextInt();
	}
	for(int i = 0; i < n; i++) {
		if(sum + 1 == a[i]) {
			sum++;
		}
	}

	if(sum == 0) {
		System.out.println(-1);
	}
	else {
		System.out.println(n-sum);
	}

	sca.close();
	}
}

Measured memory_bytes: 76516
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <numeric>
#include <cmath>
#include <cassert>

using namespace std;

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

#define rep(i,n) for(int i=0;i<(n);++i)
#define all(x) x.begin(),x.end()

const ll mod = 1e9+7;
const ll INF = 1e9;

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int main()
{
	int n;
	cin>>n;
	vector<int>b(n+1);
	b[0]=INF;
	b[n]=INF;
	for (int i = 1; i < n; i++){
		cin>>b[i];
	}
	int ans = 0;
	rep(i,n) ans += min(b[i],b[i+1]);
	cout<<ans<<endl;
	return 0;
}

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

using namespace std;

#define DBG cerr << '!' << endl;
#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define rep(i,s,g) for(ll (i) = (s);(i) < (g);++i)
#define rrep(i,s,g) for(ll (i) = (s);i >= (g);--(i))
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int W = 0;W < (n);W++)cerr << v[W] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int aaa = 0;aaa < i;aaa++){for(int bbb = 0;bbb < j;bbb++)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(10)
#define INF 1000000000
#define MOD 1000000007

typedef long long ll;
typedef pair<ll,ll> P;

int main()
{
	int n,q;cin >> n >> q;
	REP(i,q){
		int a,b;cin >> a >> b;
		if(n == 1){
			cout << min(a,b) << endl;
		}
		else{
			while(a != b){
				if(a < b)swap(a,b);
				a = (a + (n - 2)) / n;
			}
			cout << a << endl;
		}
	}
	return 0;
}

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

using namespace std;

//#define _FILES
#define PB push_back
#define MP make_pair
#define X first
#define Y second

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

    #ifdef _FILES
        freopen("","r",stdin);
        freopen("","w",stdout);
    #endif // _FILES
    long long n, a, b;
    cin >> n >> a >> b;

    if (b < a)
    {
        cout << 0 << endl;
        return 0;
    }

    if (n == 1)
    {
        if (a == b)
        {
            cout << 1 << endl;
        }
        else
        {
            cout << 0 << endl;
        }
        return 0;
    }
    long long ans = (n - 1) * b + a - ((n-1) * a + b) + 1;
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
using namespace std;
long long mod=1000000007;
long long dp[310][310][310];
int main(){
	int a,b;scanf("%d%d",&a,&b);
	if(a>b){
		printf("0\n");
		return 0;
	}
	dp[0][0][1]=1;
	for(int i=0;i<b;i++){
		for(int j=0;j<=a;j++){
			for(int k=0;k<=a;k++){
				if(!dp[i][j][k])continue;
				dp[i+1][j+1][k]=(dp[i+1][j+1][k]+dp[i][j][k]*(a-j-k))%mod;
				dp[i+1][0][j+k]=(dp[i+1][0][j+k]+dp[i][j][k]*k)%mod;
				dp[i+1][j][k]=(dp[i+1][j][k]+dp[i][j][k]*(j))%mod;
			}
		}
	}
	printf("%lld\n",dp[b][0][a]);
}

Measured memory_bytes: 110720
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define FAST {ios_base::sync_with_stdio(false);cin.tie(NULL);}
#define f(i, a, b) for(ll i=a; i<b; i++)
#define fr(i,a,b) for(ll i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define pll pair<ll,ll>
#define LB lower_bound
#define UB upper_bound
#define endl "\n"
using namespace std;

int main()
{
    FAST
    int n;cin>>n;
    int l[n];
    f(i,0,n) cin>>l[i];
    int ans=0;
    f(i,0,n)
    {
        f(j,i+1,n)
        {
            f(k,j+1,n)
            {
                int a=l[i],b=l[j],c=l[k];
                if(l[i]!=l[j] && l[j]!=l[k] && l[k]!=l[i])
                {
                    if(a+b>c && a+c>b && b+c>a) ans++;
                }
            }
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 3632
n, m = map(int, input().split())
x = list(map(int, input().split()))

if n >= m:
    ans = 0
else:
    x.sort()
    cheak = [0]*(m-1)
    
    for i in range(m-1):
        cheak[i] = abs(x[i+1]-x[i])
    cheak.sort(reverse=True)
    
    for j in range(n-1):
        cheak.pop(0)
    
    ans = sum(cheak)
print(ans)

Measured memory_bytes: 13960
H, W = map(int, input().split())
ah = [input() for _ in range(H)]

chs = {h for h in range(H) if all(a == '.' for a in ah[h])}
cws = {w for w in range(W) if all(a[w] == '.' for a in ah)}

for h in range(H):
    if h not in chs:
        print(''.join(ah[h][w] for w in range(W) if w not in cws))

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//INSERT ABOVE HERE
signed main(){
  Int n;
  cin>>n;
  Int ans=0;
  Int op=0,en=0,bt=0;
  for(Int i=0;i<n;i++){
    string s;
    cin>>s;
    if(s.front()=='B'&&s.back()=='A') bt++;
    else if(s.front()=='B') en++;
    else if(s.back()=='A') op++;
    
    for(Int j=0;j+1<(Int)s.size();j++)
      if(s[j]=='A'&&s[j+1]=='B') ans++;    
  }
  
  if(bt){
    ans+=bt-1;
    if(op) ans++,op--;
    if(en) ans++,en--;    
  }
  
  ans+=min(op,en);
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class Program
{
    static void Main(string[] args)
    {
            // 入力
            int iA = int.Parse(Console.ReadLine().Trim());
            int iB = int.Parse(Console.ReadLine().Trim());
            int iH = int.Parse(Console.ReadLine().Trim());

            System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
            sw.Start();

            // 解析
            int iOut = (iA + iB) * iH / 2;

            // 出力
            Console.WriteLine("{0}", iOut.ToString());

            sw.Stop();
#if DEBUG
            Console.WriteLine();
            Console.WriteLine("{0}", sw.Elapsed.ToString());
            Console.WriteLine("続行するには何かキーを押してください．．．");
            Console.ReadKey();
#endif
    }
}


Measured memory_bytes: 11220
#include <bits/stdc++.h>
#define ALL(v) v.begin(), v.end()
#define MOD 1000000007
#define INF 1000000011
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i++)
using namespace std;
typedef long long ll;
 
int main(){
  string s;
  cin>>s;
  ll n=s.size();
  vector <ll> vecl{};
  vector <ll> vecr{};
  ll mo[n];
  ll pl[n];
  ll ans[n];
  rep(i, n){
    mo[i]=0;
  pl[i]=0;
  ans[i]=0;}
  
  for(int i=0;i<s.size()-1;i++){
    if(s[i]=='R'&&s[i+1]=='L'){
      vecl.push_back(i);}
  }
  
  for(int i=0;i<s.size()-1;i++){
    if(s[i]=='R'&&s[i+1]=='L'){
      vecr.push_back(i+1);}
  }
  
  ll lv=1;
  ll rv=0;
  
  for(int i=1;i<n;i++){
    if(lv<vecl.size()){
    if(i==vecl[lv]){
      lv++;}
    }
      
    if(rv<vecr.size()){
     if(i==vecr[rv]){
      rv++;}
    }
  
    if(s[i]=='L'){
      mo[i]=vecl[lv-1];}
    else{
      mo[i]=vecr[rv];}
    
  }
 
  
  mo[0]=vecr[0];
  

  
  for(int i=0;i<n;i++){
    if(s[i]=='L'){
      ll p=i;
      ll dis=p-mo[i];
  if(dis%2==0){
    pl[i]=mo[i];}
      else{
        pl[i]=mo[i]+1;}
    }
    else{
      ll p=i;
      ll dis=p-mo[i];
      if(dis%2==0){
        pl[i]=mo[i];}
      else{
        pl[i]=mo[i]-1;}
    }
  }

  
  
  
  for(int i=0;i<n;i++){
    ans[pl[i]]+=1;}
  
  rep(i, n-1){
    cout<<ans[i]<<" ";}
  cout<<ans[n-1]<<endl;
  
  
 
 
}

Measured memory_bytes: 3960
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
using namespace std;
int main(){
	int n,l;
	string str[100];
	scanf("%d%d",&n,&l);
	for(int i=0;i<n;i++) cin >> str[i];
	sort(str,str+n);
	string ans = "";
	for(int i=0;i<n;i++) ans += str[i];
	cout << ans << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <string.h>
#define MAXN 500005
#define LL long long
#define lson l, m, rt << 1
#define rson m + 1, r, rt << 1 | 1
#define MOD 1000000007
using namespace std;
int use[MAXN], n;
LL T1[MAXN], T2[MAXN];
void add(int k, int num, LL T[])
{
    while(k <= n)
    {
        T[k] += num;
        T[k] %= MOD;
        k += k & -k;
    }
}
LL read(int k, LL T[])
{
    LL sum = 0;
    while(k)
    {
        sum += T[k];
        sum %= MOD;
        k -= k & -k;
    }
    return sum;
}
struct Node
{
    LL sum, lazy, num;
}tree[MAXN << 2];
void pushUp(int rt)
{
    tree[rt].sum = tree[rt << 1].sum + tree[rt << 1 | 1].sum;
    tree[rt].num = tree[rt << 1].num + tree[rt << 1 | 1].num;
}
void pushDown(int rt)
{
    if(tree[rt].lazy)
    {
        tree[rt << 1].sum += (tree[rt << 1].num * tree[rt].lazy);
        tree[rt << 1].sum %= MOD;

        tree[rt << 1 | 1].sum += (tree[rt << 1 | 1].num * tree[rt].lazy);
        tree[rt << 1 | 1].sum %= MOD;

        tree[rt << 1].lazy += tree[rt].lazy;
        tree[rt << 1].lazy %= MOD;

        tree[rt << 1 | 1].lazy += tree[rt].lazy;
        tree[rt << 1 | 1].lazy %= MOD;

        tree[rt].lazy = 0;
    }
}
void buildTree(int l, int r, int rt)
{
    tree[rt].lazy = tree[rt].sum = tree[rt].num = 0;
    if(l == r)
    {
        if(!use[l]) tree[rt].num = 1;
        return;
    }
    int m = (l + r) >> 1;
    buildTree(lson);
    buildTree(rson);
    pushUp(rt);
}

void update(int ll, int rr, LL add, int l, int r, int rt)
{
    if(ll <= l && r <= rr)
    {
        tree[rt].lazy += add;
        tree[rt].lazy %= MOD;
        tree[rt].sum += (tree[rt].num * add);
        tree[rt].sum %= MOD;
        return;
    }
    pushDown(rt);
    int m = (l + r) >> 1;
    if(ll <= m) update(ll, rr, add, lson);
    if(rr >  m) update(ll, rr, add, rson);
    pushUp(rt);
}
int star[MAXN];
LL fac[MAXN];
int main()
{
    scanf("%d", &n);
    fac[0] = 1LL;
    for(int i = 1; i <= n; i++) fac[i] = fac[i - 1] * (LL)i % MOD, use[i] = 0;
    for(int i = 1; i <= n; i++)
    {
        scanf("%d", &star[i]);
        use[star[i]] = 1;
    }
    buildTree(1, n, 1);
    int sum = 0;
    for(int i = 1; i <= n; i++)
    {
        if(!use[i])
        {
            sum++;
            add(i, 1, T2);
        }
    }
    LL ans = fac[sum];
    int suf = 0;
    for(int i=n;i>0;i--){
		LL tmp1 = 0, tmp2 = 0;
		if(star[i]){
			LL x = read(star[i] - 1, T1);
			tmp1 = x * fac[sum] % MOD * fac[n - i] % MOD;
			LL y = read(star[i], T2);
			if(sum >= 1)
				tmp2 = y * suf % MOD * fac[sum-1] % MOD * fac[n-i] % MOD;
			ans = (ans + tmp1 + tmp2) % MOD;
			add(star[i], 1, T1);
			if(star[i] < n) update(star[i] + 1,n,1,1,n,1);
		}
		else{
			if(sum >= 2)
				tmp1 = ((LL)sum * (sum - 1) / 2) % MOD * fac[sum-2] % MOD * suf % MOD * fac[n-i] % MOD;
			if(sum >= 1)
				tmp2 = tree[1].sum % MOD * fac[sum-1] % MOD * fac[n-i] % MOD;
//			printf("tmp1 = %lld\ntmp2 = %lld\n",tmp1,tmp2);
			ans = (ans + tmp1 + tmp2) % MOD;
			suf++;
		}
//		printf("i = %d ans = %lld\n",i,ans);
	}
    printf("%d\n", (int)ans);
    return 0;
}


Measured memory_bytes: 40448
#include <bits/stdc++.h>
using namespace std;
#define INF 100005
#define maxx 1000000000000

int n;
long long a[INF+5];
long long mem[INF];

long long rec(int pos)
{
    if(pos==n-1)
    {
        return 0;
    }
    if(mem[pos]!=-1) return mem[pos];
    long long tot=maxx;
    long long left=abs(a[pos]-a[pos+1]);
    long long right=abs(a[pos]-a[pos+2]);
    if(pos+1<n)
    {
        tot=min(tot,left+rec(pos+1));
    }
    if(pos+2<n)
    {
        tot=min(tot,right+rec(pos+2));
    }
    return mem[pos]=tot;
}

int main()
{
    memset(a,0,sizeof(a));
    memset(mem,-1,sizeof(mem));
    scanf("%d",&n);
    for(int i=0;i<n;i++)
    {
        scanf("%lld",&a[i]);
    }
    long long ans=rec(0);
    printf("%lld\n",ans);
}


Measured memory_bytes: 8064
#include<stdio.h>
int main(){
    long N,K;
    scanf("%ld %ld", &N,&K);
    long d[40],j=1,r=1;
    d[0]=K;
    for (long i=K;i>0;i/=2){
        if(K&j){
            d[r++]=(K-j)|(j-1);
        }
        j*=2;
    }
    long A,B,sum[40]={};
    for (long i=0;i<N;i++){
        scanf("%ld %ld", &A,&B);
        for (int j=0;j<r;j++){
            if((d[j]|A)==d[j]){
                sum[j]+=B;
            }
        }
    }
    for(long i=0;i<r;i++){
        if (sum[0]<sum[i]){
            sum[0]=sum[i];
        }
    }
    printf("%ld\n",sum[0]);
    return 0;
}

Measured memory_bytes: 128
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

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


        List<Integer> group1 = Arrays.asList(1,3,5,7,8,10,12);
        List<Integer> group2 = Arrays.asList(4,6,9,11);
        List<Integer> group3 = Arrays.asList(2);

        if((group1.contains(x) && group1.contains(y)) || (group2.contains(x) && group2.contains(y))){
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }

    }
}


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

int main() {
    int  n;
    cin>>n;
    
    
    int* input = new int[n];
    for(int i=0;i<n;i++) {
        int num;
        cin>>num;
        
        input[i]=num;
    }
    bool flag = true;
    for(int i=0;i<n;i++) {
        if(input[i] != i+1) {
            flag = false;
        }
    }
    
    if(flag) {
        cout<<"YES"<<endl;
        return 0;
    }
    
    for(int i=0;i<n and flag==false;i++) {
        if(input[i] != i+1) {
            int temp = input[i];
            input[i] = input[temp-1];
            input[temp-1] = temp;
            
            flag = true;
        }
    }
    
    for(int i=0;i<n;i++) {
        // cout<<input[i]<<" ";
        if(input[i] != i+1) {
            flag = false;
        }
    }
    
    if(flag) {
        cout<<"YES"<<endl;
        return 0;
    } else {
        cout<<"NO"<<endl;
        return 0;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cctype>

inline int readInt() {
	int s = 0, c;
	while (!isdigit(c = getchar()));
	do s = s * 10 + c - '0';
	while (isdigit(c = getchar()));
	return s;
}

int a = readInt(), b = readInt(), c = readInt(), ans = 0;
int flag[110] = { 0 };

int main() {
	++flag[a]; ++flag[b]; ++flag[c];
	for (int i = 1; i <= 100; ++i) {
		if (flag[i] != 0) {
			++ans;
		}
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 256
def myAnswer(Q: int, H: int, S: int, D: int, N: int) -> int:
    H = min(H, Q*2)
    S = min(S, H*2)
    D = min(D, S*2)
    total = 0
    while N != 0:
        if(N < 2):
            total += S
            N -= 1
        else:
            total += (N//2) * D
            N = N % 2
    return total


def modelAnswer():
    tmp = 1


def main():
    Q, H, S, D = map(int, input().split())
    N = int(input())
    print(myAnswer(Q, H, S, D, N))


if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#define sc second
#define fi first
#define pii pair <int,int>
#define ll long long
#define lowbit(a) a&-a
using namespace std;

inline int read(){
	int sum=0,f=1;char ch=getchar();
	while(ch>'9' || ch<'0'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0' && ch<='9'){sum=sum*10+ch-'0';ch=getchar();}
	return f*sum;
}

const int N=100005;
const int Mod=1e9+7;
int n,m,a[N],b[N],d[N],t1,t2;
ll t[N],ans=1;
pair <int,int> c[N];

inline void add(int x,ll k){
	for(int i=x;i<=t2;i+=lowbit(i)) t[i]=(t[i]+k)%Mod;	
}

inline ll ask(int x){
	ll ret=0;
	for(int i=x;i;i-=lowbit(i)) ret=(ret+t[i])%Mod;
	return ret;
}

bool cmp(pii a,pii b){return a.fi!=b.fi? a.fi<b.fi:a.sc>b.sc;}

signed main(){
	n=read();m=read();
	for(int i=1;i<=n;i++) a[i]=read();
	for(int i=1;i<=m;i++) b[i]=read();
	for(int i=1;i<=n;i++){
		if(a[i]<=b[1]||a[i]>=b[m]) continue;
		int k=lower_bound(b+1,b+m+1,a[i])-b;
		if(a[i]==b[k]) continue;
		c[++t1]=pii(a[i]-b[k-1],b[k]-a[i]);d[++t2]=b[k]-a[i];
	}
	sort(d+1,d+t2+1);int l=unique(d+1,d+t2+1)-d-1;
	for(int i=1;i<=t1;i++){
		c[i].second=lower_bound(d+1,d+l+1,c[i].second)-d;
	}
	sort(c+1,c+t1+1,cmp);t1=unique(c+1,c+t1+1)-c-1;
	for(int i=1;i<=t1;i++){
		ll sum=ask(c[i].sc-1)+1;
		ans=(ans+sum)%Mod;add(c[i].sc,sum);
	}
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 2560
def main():
    import sys

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

    n, h = map(int, input().split())
    aa, bb = [], []
    for i in range(n):
        a, b = map(int, input().split())
        aa.append(a)
        bb.append(b)
    bb.sort(reverse=True)
    maxa = max(aa)
    cnt = 0
    i=0
    
    while i < n and h > 0:
        if bb[i] > maxa:
            h -= bb[i]
            cnt+=1
        i+=1
    if h > 0:
        cnt += (h+maxa-1)//maxa
        
    print(cnt)
        
        
if __name__ == '__main__':
    main()

Measured memory_bytes: 17244
#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>
#include <math.h>
#include <stdbool.h>
#include <algorithm>
#include <vector>
#include <map>
using namespace std;

class Point {
    public:
    double x, y;

    Point(double x = 0, double y = 0): x(x), y(y) {}

    Point operator + (Point p) { return Point(x+p.x, y+p.y); }
    Point operator - (Point p) { return Point(x-p.x, y-p.y); }
    Point operator * (double a) { return Point(a*x, a*y); }
    Point operator / (double a) { return Point(x/a, y/a); }

    double abs() {return sqrt(norm()); }
    double norm() {return x*x + y*y; }
};

double getMinLR(vector<Point>&, int m0, int m1, int m, double delta);
double getClosestPair(vector<Point>& v, int m0, int m1, bool isSorted);

int main(){
    #if 0
    std::ifstream in("test.txt");
    std::cin.rdbuf(in.rdbuf());
    #endif

    int n;
    cin >> n;
    vector<Point> zPoints(n);

    for (int i=0; i<n; i++){
        cin >> zPoints[i].x >> zPoints[i].y;
    }

    cout << fixed << setprecision(10) << getClosestPair(zPoints, 0, n-1, false) << endl;

    return 0;
}

bool xComp(Point p1, Point p2){   
    return  (p1.x < p2.x);
}

bool yComp(Point p1, Point p2){   
    return  (p1.y < p2.y);
}

double getMinLR(vector<Point>& v, int m0, int m1, int m, double delta){
    vector<Point> zMargin; //点mからx座標が+-deltaの範囲にいる点の集合
    zMargin.push_back(v[m]);
    for (int i=m-1; i>=m0; i--){
        if ( (v[m].x - v[i].x) > delta ) break;
        zMargin.push_back(v[i]);
    }
    for (int i=m+1; i<=m1; i++){
        if ( (v[i].x - v[m].x) > delta ) break;
        zMargin.push_back(v[i]);
    }

    sort(zMargin.begin(), zMargin.end(), *yComp); //y方向にsort
    int n = zMargin.size();
    Point buffer(zMargin[n-1].x, zMargin[n-1].y + 2*delta );
    for (int i=0; i<4; i++){
        zMargin.push_back(buffer);
    }

    double minLR = delta;

    for (int i=0; i<n-1; i++){
        for (int j=i+1; j<=i+5; j++){
            double distance = (zMargin[j] - zMargin[i]).abs();
            minLR = (distance < minLR)? distance : minLR;
        }
    }
    
    return minLR;
}

double getClosestPair(vector<Point>& v, int m0, int m1, bool isSorted=true){
    if (m0 == m1){ //１点の場合はInfinityを返す
        return __DBL_MAX__;
    }
    if (m0 + 1 == m1){ //２点の場合は２点間の距離を返す。後にdeltaの有限性を保証
        return (v[m0] - v[m1]).abs();
    }

    if(!isSorted) sort(v.begin(), v.end(), *xComp); //最初だけx座標で昇順にsort
    int m = (m0 + m1) / 2;
    double minL = getClosestPair(v, m0, m);
    double minR = getClosestPair(v, m+1, m1);
    double delta = min(minL, minR);
    double minLR = getMinLR(v, m0, m1, m, delta);

    return min(delta, minLR);
}



Measured memory_bytes: 7444
import java.util.*;

public class Main{

    Scanner sc = new Scanner(System.in);

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

    void run() {
        int k = sc.nextInt();
        int a = sc.nextInt();
        int b = sc.nextInt();

        for (int i=a; i<=b; i++) {
            if (i % k ==0) {
                System.out.println("OK\n");
                return;
            }
        }

        System.out.println("NG\n");
    }
}


Measured memory_bytes: 35704
#include <cmath>
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <utility>
#include <iomanip>

#define int long long int
#define rep(i, n) for(int i = 0; i < (n); ++i)

using namespace std;

typedef pair<int, int> P;

const int INF = 1e15;
const int MOD = 1e9+7;

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

    if(n == 1 && m == 1){
        cout << 1 << endl;
        return 0;
    }
    if(n == 1 || m == 1){
        cout << n*m - 2 << endl;
        return 0;
    }
    if(n == 2 || m == 2){
        cout << 0 << endl;
        return 0;
    }
    cout << n * m - (n + m) * 2 + 4 << endl;

    return 0;
}


Measured memory_bytes: 888
#include <stdio.h>

int main(void){
	long long a, b, gcd, lcm;
	long long i, tmp;
	
	while (scanf("%lld %lld", &a, &b) != EOF){
		if (a > b){
			i = a;
			gcd = b;
			tmp = 1;
		}
		if (b > a){
			i = b;
			gcd = a;
			tmp = 1;
		}
		if (a == b){
			gcd = a;
			tmp = 0;
		}
		while (tmp){
			tmp = i%gcd;
			i = gcd;
			if (tmp) gcd = tmp;
		}
		lcm = a*b/gcd;
		printf("%lld %lld\n", gcd, lcm);
	}
	
	return 0;
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
#define chmin(a, b) ((a)=min((a), (b)))
#define chmax(a, b) ((a)=max((a), (b)))
#define fs first
#define sc second
#define eb emplace_back
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;

const ll MOD=1e9+7;
const ll INF=1e18;

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

int main(){
    int n; cin>>n;
    vector<int> a(n);
    map<int, int> mp;
    for(int i=0; i<n; i++){
        cin>>a[i];
        mp[a[i]]++;
    }
    sort(a.begin(), a.end(), greater<int>());

    int ans=0;
    for(int i=0; i<n; i++){
        for(ll num=2; num<=1e18; num*=2){
            if(num/2<=(ll)a[i] && (ll)a[i]<num){
                int x=num-a[i];

                if(a[i]==x){
                    if(1<mp[a[i]]){
                        mp[a[i]]-=2;
                        ans++;
                    }
                }
                else if(mp[a[i]] && mp[x]){
                    mp[a[i]]--;
                    mp[x]--;
                    ans++;
                }
                break;
            }
        }
    }
    cout << ans << endl;
}

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

const int MOD = 1000000007;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define copy(from, to) copy(from.begin(), from.end(), back_inserter(to))
#define sort(a) sort(a.begin(), a.end())
#define reverse(s) reverse(s.begin(), s.end())
#define p(s) cout << (s) << endl

typedef long long ll;
using namespace std;

template<class T>
void load(vector<T> &v, int n) {
  for (int i = 0; i < n; ++i) {
    T t;
    cin >> t;
    v.push_back(t);
  }
}

template<class T>
T max(vector<T> &v) {
  return *max_element(v.begin(), v.end());
}

template<class T>
T min(vector<T> &v) {
  return *min_element(v.begin(), v.end());
}

void py(bool isUpper = false) {
  if (isUpper) {
    p("YES");
  } else {
    p("Yes");
  }
}

void pn(bool isUpper = false) {
  if (isUpper) {
    p("NO");
  } else {
    p("No");
  }
}

bool check(const string &s) {
  return s.substr(0, s.length() / 2) == s.substr(s.length() / 2, s.length() / 2);
}

int main() {
  string s;
  cin >> s;

  for (int i = 2; i < s.length(); i += 2) {
    int length = s.length() - i;
    string s1 = s.substr(0, length / 2);
    string s2 = s.substr(length / 2, length / 2);

    if (s1 == s2) {
      p(length);
      return 0;
    }
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define rREP(i,a,n) for(int (i)=(n)-1; (i)>=(a);--(i))
#define all(x) (x).begin(),(x).end()
#define out(y,x,h,w) (y)<0||(x)<0||(y)>=(h)||(x)>=(w)
constexpr int INF = 1000000001;
constexpr ll mod = 1000000007;
constexpr double PI = 3.1415926535897932;

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;
}
inline void init() {
	cin.tie(nullptr); cout.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

int main() {
	init();

	int N; cin >> N; 
	cout << (N + 1) / 2 << "\n";


	return 0;
}

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

int main() {

  int A1,A2,A3,result;
  cin >> A1 >> A2 >> A3;

  result = A1+A2+A3;
  if(result > 21){
    cout << "bust" << endl;
  }else{
    cout << "win" << endl;
  }
}


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

int main(){
    int sumA, A[3];
    for(int i=0; i<3; i++) cin >> A[i];
    sumA = A[0]+A[1]+A[2];
    if(sumA<22) cout << "win" <<endl;
    else cout << "bust" <<endl;
}

Measured memory_bytes: 256
#include <iostream>
// #include <cassert>
#include <vector>
#include <algorithm>
#include <climits>

#include <stack>
#include <queue>
// #include <deque>
#include <set>
#include <map>
// #include <string>
// #include <unordered_set>
// #include <unordered_map>

#include <tuple>
// #include <cmath>
// #include <numeric>

using namespace std;
typedef long long ll;
typedef pair<long,long> pll;
typedef pair<int,int> pii;
typedef pair<int,long> pil;
typedef pair<long,int> pli;
typedef vector<vector<long long>> vvll;
typedef vector<vector<long>> vvl;
typedef vector<vector<int>> vvi;
typedef vector<int> vi;
typedef vector<long> vl;
typedef vector<long long> vll;

#define emplace_back pb
const char el = '\n';

/*
Edge cases:


*/

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

    ll n; ll k; cin>>n>>k;


    ll posmod = n%k;
    if (k==1) {
        cout<<0<<el;
        return 0;
    }
    cout<<min(posmod,k-posmod)<<el;
}

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

int main() {
  long n,a,b,c,d,e,ans,mintrans;
  cin >> n >> a >> b >> c >> d >> e;
  mintrans=min(min(a,b),min(c,min(d,e)));
  if(n%mintrans==0) ans=n/mintrans+4;
  else ans=n/mintrans+5;
  cout << ans << endl;
}

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

using namespace std;

int main() {
  int x;
  cin >> x;
  long long ans = x / 500 * 1000;
  x -= x / 500 * 500;
  ans += x / 5 * 5;
  cout << ans << endl;

  return 0;
}
/* vim:set fdm=marker: */


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

int main() {
    long W, H, x, y;
    cin >> W >> H >> x >> y;
    double ans = (double) W / 2 *  (double) H;
    cout << setprecision(15) <<  ans << " ";
    if(2 * x == W && 2 * y == H)     cout << 1 << endl;
    else     cout << 0 << endl;;

    return 0;  

}

Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
#include <cassert>

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

int c[10][10];

int main() {
    int H, W;
    cin >> H >> W;
    rep(i, 10) {
        rep(j, 10) {
            cin >> c[i][j];
        }
    }
    rep(k, 10) {
        rep(i, 10) {
            rep(j, 10) {
                c[i][j] = min(c[i][j], c[i][k] + c[k][j]);
            }
        }
    }
#if 0
    rep(i, 10) {
        rep(j, 10) {
            printf("%4d ", c[i][j]);
        }
        printf("\n");
    }
#endif
    int tmp;
    uint64_t ret = 0;
    rep(i, H) {
        rep(j, W) {
            cin >> tmp;
            if(tmp >= 0)
                ret += c[tmp][1];
        }
    }
    cout << ret << endl;

    return 0;
}



Measured memory_bytes: 3184
using System;
using System.Collections.Generic;

public class DateSet
{
    //0?????\????????§??°????????????????????????????????????
    static void Main(string[] args)
    {
        /*---??£?¨???¨---*/
        int i = 0;
        int k;
        List<int> list = new List<int>();
        /*---??£?¨???¨---*/

        //0?????\????????§????????????
        while (true){
            list.Add(int.Parse(Console.ReadLine()));
            if(list[i] == 0){
                break;
            }
            i++;
        }

        /*0?????§????????????????????????*/
        for(k = 0; k < i; k++){
            Console.WriteLine("Case {0}: {1}", k+1, list[k]);
        }
    }
}

Measured memory_bytes: 9348
function main(input) {
  const formatted_input = input.split('\n').map(x => parseInt(x));

  const N = formatted_input[0];
  var necks = [];
  for(var i=1;i<=5;i++){
    necks.push(formatted_input[i]);
  }
  const bottle_neck = Math.min(...necks);
  var bottle_neck_time = Math.floor(N/bottle_neck);
  if(N%bottle_neck>0){bottle_neck_time++;}

  var result = 4 + bottle_neck_time;

//  console.log(N);
//  console.log(bottle_neck);
//  console.log(bottle_neck_time);
  console.log(result);
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));



Measured memory_bytes: 7372
#include <stdio.h>

int main(void)
{
	int a,b,c;
	scanf("%d %d %d",&a,&b,&c);
	if(a<=b&&b<=c){
			printf("%d %d %d\n",a,b,c);
	}
	else if(a<=c&&c<=b){
			printf("%d %d %d\n",a,c,b);
	}
	else if(b<=a&&a<=c){
			printf("%d %d %d\n",b,a,c);
	}
	else if(b<=c&&c<=a){
			printf("%d %d %d\n",b,c,a);
	}
	else if(c<=a&&a<=b){
			printf("%d %d %d\n",c,a,b);
	}
	else{
			printf("%d %d %d\n",c,b,a);
	}
	return 0;
}

Measured memory_bytes: 1784
double M,N,e,f,g,a[20][3],*x,*y;
n,i,j,v[20];
D(d,m,c){
	if(m==0){
		for(N=i=0;i<d-1;i++)for(j=i+1;j<d;j++)x=a[v[i]],y=a[v[j]],N+=(e=x[0]-y[0])*e+(f=x[1]-y[1])*f+(g=x[2]-y[2])*g;
		if(M<N)M=N;
	}else for(;c<=n-m;c++)v[d]=c,D(d+1,m-1,c+1);
}
main(m){
	scanf("%d%d",&n,&m);if(m<2)puts("0"),exit(0);
	for(i=0;i<n;i++)scanf("%lf%lf%lf",a[i],a[i]+1,a[i]+2);
	M=0;D(0,m,0);printf("%f\n",M),exit(0);
}

Measured memory_bytes: 664
/*Remember: The Struggle is Important*/

//CF,CC,AtC,SPOJ: hp1999
//HE: hemant269
//HR: hemant2132

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

#define     int          long long int
#define     ld           long double
#define     fast()       ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define     all(x)       x.begin(),x.end()
#define     mem(a,b)     memset(a,b,sizeof(a))
#define     gcd(a,b)     (__gcd((a),(b)))
#define     lcm(a,b)     (((a)*(b))/gcd((a),(b)))
#define     pb           push_back
#define     ins          insert
#define     pii          pair<int,int>
#define     F            first
#define     S            second
#define     makep        make_pair
#define     maket        make_tuple
#define     show(x)      for(auto c:x)cout<<c<<" ";cout<<"\n";
#define     show2(x)     for(auto c:x)cout<<c.F<<" "<<c.S<<"\n";

const int inf=1e18,M=1e9+7;
const int N=1e5+10;

vector<int> v[N];

int dp1[N],dp2[N];

void dfs(int x,int p)
{
    dp1[x]=dp2[x]=1;

    for(auto c:v[x])
    {
        if(c==p)
            continue;

        dfs(c,x);

        dp1[x]=(dp1[x]*dp2[c])%M;
        dp2[x]=(dp2[x]*((dp1[c]+dp2[c]))%M)%M;
    }
}

void solve()
{
    mem(dp1,0);
    mem(dp2,0);

    int n;
    cin>>n;

    int a,b;
    for(int i=1;i<n;++i)
    {
        cin>>a>>b;
        v[a].pb(b);
        v[b].pb(a);
    }

    dfs(1,-1);

//    for(int i=1;i<=n;++i)
//        cout<<i<<" "<<dp1[i]<<" "<<dp2[i]<<"\n";

    int ans=(dp1[1]+dp2[1])%M;;
    cout<<ans;
}

int32_t main()
{
    fast();

    int t=1;
    //cin>>t;
    while(t--)
    {
        solve();
        //cout<<"\n";
    }

    return 0;
}




Measured memory_bytes: 12800
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
using ll=long long;
static const ll mod = 1e9 + 7;
static const ll INF = 1LL << 50;
using namespace std;

//繰り返し二乗法
template <typename T>
T doubling(T a, T p) {
	if (p == 0)return 1;//出口
	if (p % 2 == 0) {//pを半分にしていく
		T half = doubling<T>(a, p / 2);
		return half % mod * half % mod;
	}
	else {//pが奇数ならpを偶数にする
		return a * doubling<T>(a, p - 1) % mod;
	}
}

//combination その2(逆元) O(nlonP):PはmodP
template<typename T>
T combination(T n, T r) {
	if (r > n - r)return combination<T>(n, n - r);
	T mul = 1;
	T div = 1;
	for (unsigned long long int i = 0; i < r; i++) {
		mul *= n - i;
		div *= i + 1;
		mul %= mod;
		div %= mod;
	}
	//逆元
	T ans = mul * doubling(div, mod - 2) % mod;//a^(-1)=a~(p-2) (mod p)
	return ans;
}

int main() {
	ll n, m, k;
	cin >> n >> m >> k;
	ll cmb = combination<ll>(n * m - 2, k - 2);//選ぶ2点を固定したときの残りの点の選び方
	ll ans = 0;
	rep(x, m) {
		ans += x * (m - x) * n * n % mod;
		ans %= mod;
	}
	rep(y, n) {
		ans += y * (n - y) * m * m % mod;
		ans %= mod;
	}
	cout << ans * cmb % mod << endl;
}

Measured memory_bytes: 256
alp = [chr(i) for i in range(97, 97+26)]

import sys
input = sys.stdin.readline

S = input().rstrip()
N = len(S)

dp = [[N]*26 for _ in range(N+1)]

Best = [-1]*(N+1)

for i in reversed(range(N)):
    s = S[i]
    b = 10**14
    for k in range(26):
        if Best[dp[i+1][k]] < b:
            b = Best[dp[i+1][k]]
        if s == alp[k]:
            dp[i][k] = i
        else:
            dp[i][k] = dp[i+1][k]
    Best[i] = b+1

b = 10**14
for k in range(26):
    if Best[dp[0][k]] < b:
        b = Best[dp[0][k]]
L = b+1

ans = ""
ind = -1
for _ in range(L+1):
    best = Best[max(dp[ind+1])]
    for k in range(26):
        if Best[dp[ind+1][k]] == best:
            ans += alp[k]
            if ind != N:
                ind = dp[ind+1][k]
            break
print(ans)

Measured memory_bytes: 105888
#include <iostream>
using namespace std;
int main(){
  int x;
  int counter=0;
  while(1){
    cin >> x;
    if(x==0)break;
    counter++; // counter = counter +1;
                // counter +=1;
    cout << "Case " <<counter << ": " << x <<endl;

  }
  return 0;
}

Measured memory_bytes: 3068
import java.util.*;
public class Main{
 public static void main(String[] args){
   Scanner sc = new Scanner(System.in);
 
   int w = sc.nextInt();
   int a = sc.nextInt();
   int b = sc.nextInt();
   
   int ans ;
   if(a<b)
   {
     if(a+w<b) ans = b-a-w; 
     else ans =0;
   }
   else
   {
     if(b+w<a) ans = a-b-w;
     else ans =0;
   }
   System.out.println(ans);
 }
}

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

#define rep(i, b) for(int i = 0; i < b; i++)
#define repi(i, a, b) for(int i = a; i < b; i++)
#define all(c) c.begin(),c.end()
#if defined(_MSC_VER) || __cplusplus > 199711L
#define aut(r,v) auto r = (v)
#else
#define aut(r,v) __typeof(v) r = (v)
#endif
#define each(it,o) for(aut(it, (o).begin()); it != (o).end(); ++ it)
#define MAX_V 1001
#define MAX_E 401
#define INF INT_MAX
#define MOD 1000000007
#define EPS 1e-7
typedef long long ll;
inline int toInt(std::string s) { int v; std::istringstream sin(s); sin >> v; return v; }
template<class T> inline std::string toString(T x) { std::ostringstream sout; sout << x; return sout.str(); }
using namespace std;

typedef double D;      // 座標値の型。doubleかlong doubleを想定
typedef complex<D> P;  // Point
typedef pair<P, P> L;  // Line
#define X real()
#define Y imag()
typedef pair<int, int> pii;

int main()
{
	int ans = 0;
	string s;
	cin >> s;
	string ss = "CODEFESTIVAL2016";
	rep(i, s.size())
	{
		if (s[i] != ss[i]) ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define all(v) (v).begin(),(v).end()
typedef long long ll;
 
int main(){
    int n, m;
    cin >> n >> m;
    if (n > m) n = m;
    vector<int> x(m), dist(m-1);
    rep(i, m) cin >> x[i];
    sort(all(x));
    ll ans = 0;
    rep(i, m-1) {
        int tmp = abs(x[i] - x[i+1]);
        ans += tmp;
        dist[i] = tmp;
    }
    sort(all(dist), greater<>());
    rep(i, n-1) {
        ans -= dist[i];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define all(v) v.begin(), v.end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define INF 2e9
signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    long long a,b,gyo0=0,gyo1=0,re0=0,re1=0,h,w,count,c,d;
    string s;
    cin>>a>>b>>c>>d;
    if(a*b<c*d){
        cout<<c*d<<'\n';
    }
    else{
        cout<<a*b<<'\n';
    }
    return(0);
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <climits>
#include <cmath>
#include <functional>
#include <map>
// #include <bits/stdc++.h>
using namespace std;

#define size_t int
typedef long long ll;
#define int long long
typedef vector<int> VI;
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define debug(x) cerr << #x << " = " << (x) << " (line " << __LINE__ << ")" << endl;
#define debug1(i, x) cerr << "(" << (i) <<  ") " << #x << " = " << (x) << " (line " << __LINE__ << ")" << endl;
#define debug2(i, j, x) cerr << "(" << (i) << ", " << (j) <<  ") " << #x << " = " << (x) << " (line " << __LINE__ << ")" << endl;
template <typename T> class vec2d : public vector<vector<T>> {
public:
    vec2d(int H, int W): vector<vector<T>> (H, vector<T>(W)) {
    }
};
template <typename T> istream& operator >> (istream& is, vector<T>& vec){
  for(T& x: vec) is >> x;
  //for(int i=0; i<vec.size(); i++) is >> x[i]; とかでもいいです。
  return is;
}
template <typename T> ostream& operator << (ostream& os, vector<T>& vec){
  REP(i, vec.size()) {
    os << vec[i] << ( i+1 == vec.size() ? "" : " " );
  }
  return os;
}
struct aaa{
    aaa(){
        cin.tie(0); ios::sync_with_stdio(0);
        // cout<<fixed<<setprecision(20);
    };
}aaaaaaa;

signed main(signed argc, char **argv) {
  char S[100010];
  cin >> S;
  int a = 0;
  int b = 0;
  for (size_t i = 0; S[i] != 0; i++) {
    if (S[i] == '0') {
      a++;
    } else {
      b++;
    }
  }
  int x = a > b ? b : a;
  cout << x*2 << endl;
  return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define forn(i, a, b) for (int i = a; i < b; ++i)
#define SZ(x) int(x.size())
#define pb push_back
#define F first
#define S second
void dbg_out() { cerr << endl; }
template <typename Head, typename... Tail>
void dbg_out(Head H, Tail... T) {
  cerr << ' ' << H;
  dbg_out(T...);
}

bool f(string s) {
  for (int i = 0, j = SZ(s) - 1; i < j; i++, j--)
    if (s[i] != s[j]) return false;
  return true;
}

int main() {
#ifdef LOCAL
  freopen("h.txt", "r", stdin);
// freopen("main.txt", "w", stdout);
#define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
#else
  ios::sync_with_stdio(0);
  cin.tie(0);
#define endl '\n'
#define dbg(...) 18
#endif
  int a, b, c = 0;
  string s;
  cin >> a >> b;
  while (a <= b) {
    s = to_string(a);
    c += f(s);
    a++;
  }
  cout << c << endl;
  return 0;
}

Measured memory_bytes: 3672
#include<bits/stdc++.h>
#include<algorithm>
#include<math.h>
using namespace std;
long long int lcm(long long int a,long long int b){
  long long int n;
  n=a*b/__gcd(a,b);
  return n;
}
using ll =long long int;
#define ci(a) cin>>a
#define co(a) cout<<a<<endl
#define gcd(a,b) __gcd(a,b)
#define vec vector<ll>
#define for(i,a,b) for(int i=a;i<b;i++)
#define sort(a,b) sort(a.begin(),b.end())
//gcd 最大公約数
//lcm 最小公倍数
//double 少数（変数）
//string 文字列（変数）
//sqrt 平方根
//ceil 天井関数
//floor 床関数
//abs 絶対値
//pow 累乗
//cbrt  立方根
//hypot 平方和の平方根
 
int main() {
  double w,h,a,b;
  ci(w);ci(h);ci(a);ci(b);
  co(w*h/2);
  ll c=0;
  if(w==2*a&&h==2*b)
    c=1;
  co(c);
}

Measured memory_bytes: 256