akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <math.h>
using namespace std;
int kaijo(int num){
    int re = 1;
    if(num == 0) return 0;
    for(int i=1; i<num+1; i++){
        re*=i;
    }    
    return re;
}

int main(void){
    int n;
    cin >> n;
    vector<int> p(n);
    vector<int> q(n);
    for(int i=0; i<n; i++){
        cin >> p.at(i);
    }
    for(int i=0; i<n; i++){
        cin >> q.at(i);
    }
    
    int countp = 1;
    for(int i=0; i<n; i++){
        int hoge = p.at(i)-1;
        for(int j=0; j<i; j++){
            if(p.at(j) < p.at(i)){
                hoge--;
            }
        }
        countp += kaijo(n-1-i)*hoge;
    }
        int countq = 1;
    for(int i=0; i<n; i++){
        int hoge = q.at(i)-1;
        for(int j=0; j<i; j++){
            if(q.at(j) < q.at(i)){
                hoge--;
            }
        }
        countq += kaijo(n-1-i)*hoge;
    }
    
    int ans = abs(countp - countq);
    cout << ans << endl;
}


Measured memory_bytes: 256
/************************************/
/* NoobM							*/
/* File Name : abc.cpp				*/
/* Date : 25.07.2020 18:00:56 +06	*/
/************************************/

#include <bits/stdc++.h>

#define rr(i, b)    for (int i = 0; i < int(b); i++)
#define vi(n, a) vector <int> a(n); rr(i, n) cin >> a[i]
#define pvec(a) rr(i, a.size()) cout << a[i] << " "; cout << endl
#define bug(x) cout << #x << " " << x << endl
#define ll long long
#define vii vector <int>

using namespace std;

void solve() {
	int k = 8;
	int x;
	cin >> x;
	
	if(x > 1799) cout << 1 << endl;
	else if(x > 1599) cout << 2 << endl;
	else if(x > 1399) cout << 3 << endl;
	else if(x > 1199) cout << 4 << endl;
	else if(x > 999) cout << 5 << endl;
	else if(x > 799) cout << 6 << endl;
	else if(x > 599) cout << 7 << endl;
	else cout << 8 << endl;
	
}
 
int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
	
	int t = 1;
	//cin >> t;
	
	while (t--) {
		solve();
	}
    return 0;
}


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

int n, m, s, t, ans;
vector<vector<int>> g(300010);

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

    cin >> n >> m;
    rep(i, 0, m) {
        int a, b;
        cin >> a >> b;
        g[a].push_back(b + n);
        g[a + n].push_back(b + 2 * n);
        g[a + n * 2].push_back(b);
    }
    cin >> s >> t;
    queue<int> q;
    q.push(s);
    set<int> psd;
    psd.insert(s);

    for (ans = 1; !q.empty(); ans++) {
        for (int i = q.size(); i > 0; i--) {
            int v = q.front();
            if (v == t) {
                cout << ans / 3 << endl;
                return 0;
            }
            q.pop();
            for (auto e : g[v])
                if (psd.find(e) == psd.end()) {
                    q.push(e);
                    psd.insert(e);
                }
        }
    }
    cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 30720
#include <bits/stdc++.h>
#define IOS {ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);}
#define endl "\n"
#define int long long int
#define f(i, a, b) for(int i=a; i<b; i++)
#define fb(i, a, b) for(int i=a; i>=b; i--)
#define pb push_back
#define fi first
#define se second
#define vi vector <int>
#define pi pair <int, int>
#define S(x) (int) x.size()
#define LB lower_bound
#define UB upper_bound
#define fp(x, y) fixed<<setprecision(y)<<x
#define M 100005
#define mod 1000000007
#define PI 3.141592653589793238462643383279502884
using namespace std;

int func(int n)
{
	int i = 1, k = 2;
	while(n >= i)
	{
		i += k;
		k++;
	}
	return k-2;
}

void solve()
{
	int n, ans = 0;
	cin>>n;
	vi v;
	for(int i=2; i*i<=n; i++)
	{
		int c = 0;
		while(n%i == 0)
		{
			n /= i;
			c++;
		}
		if(c > 1) ans += func(c);
		else if(c == 1) ans++;
	}
	if(n > 2) ans++;
	cout<<ans;
}

int32_t main()
{
    IOS
    int t = 1;
    // cin>>t;
    f(tno, 1, t+1)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 3668
#include <bits/stdc++.h>
#define int long long
#define pb       push_back
#define io    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define all(a)      (a).begin(),(a).end()
#define endl        '\n'
#define F    first
#define S second
#define mod 1000000007 
#define N 200005
#define pii pair<int,int>
using namespace std;
int n,k;
vector<int> dp(N,INT_MAX);
int ans=0;
vector<int> v(N);
int a;
int fun(int x)
{
    
    if(x<0)
        return INT_MAX;
    if(dp[x] != INT_MAX)
        return dp[x];
    
    for(int i=1;i<=k;i++)
    {
        if(x-i>=0)
            dp[x]=min(dp[x],fun(x-i) + abs(v[x]-v[x-i]));
    }
    return dp[x];
}
void solve()
{
    for(int i=0;i<n;i++)dp[i]=INT_MAX;
    cin>>n>>k;
    dp[0]=0;
    
    for(int i=0;i<n;i++)cin>>v[i];
    cout<<fun(n-1);
}

signed main(){
    io;
    int t=1;
    //cin>>t;
    while(t--){
      solve();
    }
    return 0;
}

Measured memory_bytes: 8064
//Never stop trying
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;

template <typename T>
using ordered_set=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
//s.order_of_key(), *s.find_by_order()

using namespace std;
#define boost ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)

typedef string str;
typedef long long ll;
#define int ll
typedef double db;
typedef long double ld;

typedef pair<int,int> pi;
#define fi first
#define se second

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<str> vs;
typedef vector<pi> vpi;

#define pb push_back
#define eb emplace_back
#define pf push_front

#define lb lower_bound
#define ub upper_bound

#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define endl "\n"

const int MOD = 1e9+7; //998244353
const ll INF = 1e18;
const int nx[4]={0,0,1,-1}, ny[4]={1,-1,0,0}; //right left down up

int32_t main(){
   boost;
   str s,ss; cin>>s>>ss;
   int res=0;
   for(int i=0; i<sz(s); i++) if(s[i]!=ss[i]) res++;
   cout << res << endl;

   return 0;
}

Measured memory_bytes: 3808
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
using namespace std;
#define rep(i,x) for(ll i = 0; i < (ll)(x); i++)
#define rrep(i,x) for(ll i = (ll)(x)-1;0 <= i; i--)
#define reps(i,x) for(ll i = 1; i < (ll)(x)+1; i++)
#define rreps(i,x) for(ll i = (ll)(x); 1 <= i; i--)
#define debug(x) cerr << #x << ": " << (x) << "\n";
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<ll>>> vvvl;
const ll INF = numeric_limits<ll>::max()/4;
const int n_max = 330;
#define int ll

ll n;
vector<vector<vector<double>>> memo(n_max, vector<vector<double>>(n_max, vector<double>(n_max)));
double dfs(ll c1, ll c2, ll c3){
    double i = n - c1 - c2 - c3;
    if(memo[c1][c2][c3])return memo[c1][c2][c3];
    if(i == n)return 0.0;
    double ans = double(n);
    if(c1 > 0)ans += dfs(c1-1, c2, c3) * c1;
    if(c2 > 0)ans += dfs(c1+1, c2-1, c3) * c2;
    if(c3 > 0)ans += dfs(c1, c2+1, c3-1) * c3;
    // debug(c1);debug(c2);debug(c3); debug(ans);debug(i);debug(n);
    return memo[c1][c2][c3] =  ans / double(n - i);
}

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    cin >> n;
    vector<ll> a(n);
    rep(i,n) cin >> a[i];
    vector<ll> cnt(4);
    rep(i,n){
        cnt[a[i]]++;
    }

    // debug(dfs(2,0,0));

    cout << fixed << setprecision(15);
    cout << dfs(cnt[1], cnt[2], cnt[3]) << endl;
}

Measured memory_bytes: 289664
#include<iostream>
#include<algorithm>


using namespace std;

int main() {
	int n, a[100];
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		if (i != 0)cout << " ";
		cout << a[i];
	}
	cout << endl;

	for (int i = 1; i < n; i++) {
		int v = a[i], j=i-1;
		while (j >= 0 && a[j] > v) {
			a[j + 1] = a[j];
			j--;
		}
		a[j + 1] = v;
		for (int k = 0; k < n; k++) {
			if (k != 0)cout << " ";
			cout << a[k];
		}
		cout << endl;
	}

	return 0;
}

Measured memory_bytes: 3072
N,K=map(int,input().split())
S=input()
S=list(S)
if S[K-1]=="A":
    S[K-1]="a"
elif S[K-1]=="B":
    S[K-1]="b"
else:
    S[K-1]="c"
print("".join(map(str,S)))

Measured memory_bytes: 3060
// 二分探索法
#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>;
#define INF ll(1e+18)+100;

int main(){
    int n;
    cin>>n;
    int red=0;
    vector<char> r(n);
    rep(i,n){
        cin>>r[i];
        if(r[i]=='R') red++;
    }
    if(red==n || red==0){
        cout<<"0"<<endl;
        return 0;
    }
    int w=0;
    rep(i,red){
        if(r[i]=='W') w++;
    }
    cout<<w<<endl;
    return 0;
}

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

using namespace std;

#define M_DEBUG if (0)

/******************************************************************************
	typedef
******************************************************************************/
typedef unsigned long long int ullint;

/******************************************************************************
	Main
******************************************************************************/
/*
 : : : :
 3|6|9|12...
 -+-+-+-
 2|4|6|8...
 -+-+-+-
 1|2|3|4...
*/
int main()
{
	ullint n = -1;
	cin >> n;
	assert(n >= 1 && n <= pow(10, 12));

	ullint sqrt_n = sqrtl(n);
	ullint moveCnt = n;
	for (ullint i = 2; i <= sqrt_n; i++) // 1行目はいらない
	{
		ullint j = n / i;
		if (i * j != n)
		{
			continue;
		}

		ullint tmpCnt = i + j - 2;
		if (tmpCnt < moveCnt)
		{
			moveCnt = tmpCnt;
		}
		M_DEBUG cout << "( " << i << ", " << j << ") : " << i * j << " -> " << moveCnt << endl;
	}

	cout << ((moveCnt == n) ? n - 1 : moveCnt) << endl;

	return 0;
}


Measured memory_bytes: 256
program main
    use,intrinsic :: iso_fortran_env
    implicit none
    integer(int64):: n,k,i,f,l,next,ans,ii
    integer(int64), allocatable:: a(:),ind(:),lp(:)
    logical,allocatable:: went(:)


    read*, n,k
    allocate(a(n),ind(n))
    allocate(went(n))
    read*, a(:)
    went(:) = .false.
    i=0
    f=0
    l=0

    if (n >= k) then
        ans = 1
        do i=1,k
            ans = a(ans)
        end do
        print'(i0)', ans
        stop
    end if


    next = 1
    i=1
    ind(:) = 0
    do
        if (went(next)) exit
        went(next) = .true.
        ind(next) = i
        next = a(next)
        i=i+1
    end do
    f = ind(next)
    l = i
    allocate(lp(0:l-f-1))
    do ii=0,l-f-1
        lp(ii) = next
        next = a(next)
    end do
    print'(i0)', lp(mod(k-f+1,l-f))
end program main

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

using namespace std;

int main() {
    int n, a[111];
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        scanf("%d", a + i);
    }
    int ans = 1e9;
    for (int i = -100; i <= 100; i++) {
        int sum = 0;
        for (int j = 0; j < n; j++){
            sum += (a[j] - i) * (a[j] - i);
        }
        ans = min(ans, sum);
    }
    cout << ans << endl;
    return 0;
}

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

const int INF = 1001001001;
const ll INF_LL = 1001001001001001001LL;

const int M = 1000005;

int main(void){
  int n; cin >> n;
  vector<int> a(n);
  rep(i,n) cin >> a[i];

  vector<int> cnt(M,0);
  for(auto x : a){
    if(cnt[x] != 0){
      cnt[x]=2;
      continue;
    }
    for(int i = x;i<M;i+=x) cnt[i]++;
  }

  int ans = 0;
  for(auto x : a){
    if(cnt[x]==1) ans++;
  }

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


Measured memory_bytes: 8012
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <iomanip>
#include <bitset>
#include <set>
#include <map>
#include <stdio.h>
#include <numeric>

#define rep(i,n) for (long long int i = 0; i < (n); i++)
#define rep1(i,n) for (long long int i = 1; i < (n); i++)
#define FOR(i,a,b) for (int i=(a); i < (b); i++)
#define INF 100000000000
#define MOD 1000000007 //10^9+7
using namespace std;
using ll = long long;
using P = pair<int, int>;

// 負の数にも対応した % 演算
long long mod(long long val, long long m) {
    long long res = val % m;
    if (res < 0) res += m;
    return res;
}

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

long long lcm(ll a, ll b)
{
    return a / gcd(a, b) * b ;
}

int main()
{
    int n; cin >> n;
    ll ans = 0;
    rep(i,n) {
        int tmp; cin >> tmp;
        ans += --tmp;
    }

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


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <set>
using namespace std;
int main(){
	long long n;
	cin>>n;
	vector<long long> a;
	for(long long i=2;i*i<=n;i++){
		if(n%i==0){
			a.push_back(i);
			if(i*i!=n){
				a.push_back(n/i);
			}
		}
	}
	set<long long> ans;
	ans.insert(n);
	for(int i=0;i<a.size();i++){
		long long m=n;
		while(m%a[i]==0){
			m/=a[i];
		}
		m%=a[i];
		if(m==1){
			ans.insert(a[i]);
		}
	}
	n--;
	if(n==1){
		cout<<ans.size()<<endl;
	}else{
		a.clear();
		ans.insert(n);
		for(long long i=2;i*i<=n;i++){
			if(n%i==0){
				a.push_back(i);
				if(i*i!=n){
					a.push_back(n/i);
				}
			}
		}
		for(int i=0;i<a.size();i++){
			long long m=n+1;
			while(m%a[i]==0){
				m/=a[i];
			}
			m%=a[i];
			if(m==1){
				ans.insert(a[i]);
			}
		}
		cout<<ans.size()<<endl;
	}
	return 0;
}

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

namespace AOJ.Volume3
{
    public class BatonRelayGame
    {
        public static int Main()
        {
            var input = Console.ReadLine().Split(' ');
            int n = int.Parse(input[0]);
            int m = int.Parse(input[1]);
            int q = int.Parse(input[2]);

            // ?????¬????????±
            input = Console.ReadLine().Split(' ');
            var relay = new int[m];
            for(int i = 0; i < m; i++) { relay[i] = int.Parse(input[i]); }

            // ??????
            input = Console.ReadLine().Split(' ');
            var question = new int[q];
            for(int i = 0; i < q; i++) { question[i] = int.Parse(input[i]); }

            // ??????????????????
            var students = new List<int>();
            for (int i = 0; i < n; i++) { students.Add(i); }

            // ??????????????¬???
            int current = 0;
            foreach(var r in relay)
            {
                bool clockwise = (r % 2 == 0);
                if (clockwise)
                {
                    current += r;
                    while(current >= students.Count) { current -= students.Count; }
                }
                else
                {
                    current -= r;
                    while(current < 0) { current += students.Count; }
                }
                students.RemoveAt(current);
                if(current >= students.Count) { current = 0; }
            }

            // ??????????????????
            foreach(var i in question)
            {
                Console.WriteLine(students.Count(x => x == i) == 1 ? 1 : 0);
            }

            return 0;
        }
    }
}

Measured memory_bytes: 22460
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
using namespace std;
const int M = 1e5 + 10;
int a[M] , b[M] , ha[M] , hb[M];
bool vis[M] , have[M];
vector<int>vc[M];
void dfs(int u) {
    vis[u] = true;
    int len = vc[u].size();
    for(int i = 0 ; i < len ; i++) {
        int v = vc[u][i];
        if(vis[v]) continue;
        dfs(v);
    }
}
int main() {
    int n;
    cin >> n;
    a[0] = 0;
    for(int i = 1 ; i <= n ; i++) {
        cin >> a[i];
        a[0] ^= a[i];
        ha[i] = a[i];
    }
    ha[0] = a[0];
    b[0] = 0;
    for(int i = 1 ; i <= n ; i++) {
        cin >> b[i];
        b[0] ^= b[i];
        hb[i] = b[i];
    }
    hb[0] = b[0];
    sort(ha , ha + n + 1);
    sort(hb , hb + n + 1);
    for(int i = 0 ; i <= n ; i++) {
        if(ha[i] != hb[i]) {
            cout << -1 << endl;
            return 0;
        }
    }
    for(int i = 0 ; i <= n ; i++) {
        a[i] = upper_bound(ha , ha + 1 + n , a[i]) - ha;
        b[i] = upper_bound(hb , hb + 1 + n , b[i]) - hb;
    }
    int ans = 0;
    memset(have , false , sizeof(have));
    memset(vis , false , sizeof(vis));
    for(int i = 0 ; i <= n ; i++) {
        if(a[i] != b[i] || i == 0) {
            if(i) ans++;
            have[a[i]] = true , have[b[i]] = true;
            vc[a[i]].push_back(b[i]);
        }
    }
    for(int i = 0 ; i <= n ; i++) {
        if(!vis[i] && have[i]) {
            dfs(i) , ans++;
        }
    }
    ans--;
    ans = max(ans , 0);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 10624
using System;
using System.Linq;
using System.Collections.Generic;
class Program
{
    static void Main(string[] args)
    {
        string[] s = Console.ReadLine().Split(' ');
        Console.WriteLine(
            s[0].Last() == s[1].First() &&
            s[1].Last() == s[2].First() ?
            "YES" : "NO");
    }
}


Measured memory_bytes: 11220
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0;i<(n);i++)
#define rep2(i,a,n) for(int i=a;i<n;i++)
#define been(ix) (ix).begin(),(ix).end()
using namespace std;
typedef long long ll; 
typedef vector<int> vi;
typedef vector<long long> vl;
const ll INFL = 1e18;
const int INF = 1001001001; 
typedef pair<int,int> P;
#define foreach(ix,i) for(auto& (ix) : (i))
typedef long double ld;
const int mod =1000000007;

int main(){
    int h,w,d;cin>>h>>w>>d;
    vector<P> a(h*w+1);
    rep(i,h){
        rep(j,w){
            int A;cin>>A;
            a[A]={i+1,j+1};
        }
    }
    int sum[h*w+1];
    rep(i,d){
        sum[i+1]=0;
        for(int j =i+d+1;j<=h*w;j+=d){
            sum[j]=sum[j-d]+abs(a[j].first-a[j-d].first)+abs(a[j].second-a[j-d].second);
        }
    }
    int q;cin>>q;
    rep(_,q){
        int r,l;
        cin>>l>>r;
        cout<<sum[r]-sum[l]<<endl;
    }
}

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

long long lcm(long long x,long long y)
{ 
	long long temp;
    if(x < y)  
    {  
        temp = x;  
        x = y;  
        y = temp;  
    }   
    while(y != 0)  
    {  
        temp = x % y;  
        x = y;  
        y = temp;  
    } 
    return x;
}

int main()
{
	cin.tie(0);
	cout.tie(0); 
	ios::sync_with_stdio(false);	
	int n;
	cin >> n;
	long long a[n];
	long long b = 1;
	for(int i = 0; i < n; i++)
	{
		cin >> a[i];	
	}
	for(int i = 0; i < n; i++)
	{
		b = a[i] / lcm(b,a[i]) * b;
	}
	
	cout << b;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	int a,b;
	cin >> a >> b;
	char s[100][100];
	int bomb[100][100];
	for(int i=1;i<=a;i++){
		for(int j=1;j<=b;j++){
			cin >> s[i][j];
			if(s[i][j]=='#'){
				bomb[i-1][j-1]++;
                bomb[i-1][j]++;
                bomb[i-1][j+1]++;
                bomb[i][j-1]++;
                bomb[i][j+1]++;
                bomb[i+1][j-1]++;
                bomb[i+1][j]++;
                bomb[i+1][j+1]++;
			}
		}
	}
	for(int i=1;i<=a;i++){
		for(int j=1;j<=b;j++){
			if(s[i][j]=='#'){
				cout << "#";
			}else{
				cout << bomb[i][j];
			}
		}
		cout << endl;
	}

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll msap[3001][3001];
ll c[3001][3001][4];
inline ll max(ll a,ll b)
{
	return a>b? a:b;
}
inline ll max4(ll a1,ll b1,ll c1,ll d1)
{
	ll e1=max(a1,b1),f1=max(c1,d1);
	return e1>f1? e1:f1;
}
inline ll max3(ll a1,ll b1,ll c1)
{
	ll d1=max(a1,b1);
	return d1>c1? d1:c1;
}
int main()
{
	ll ans=0;
	int n,m,k;
	cin>>n>>m>>k;
	for(int i=1;i<=k;i++)
	{
		ll x,y,v;
		cin>>x>>y>>v;
		msap[x][y]=v;
	}
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=m;j++)
		{
			ll f=max4(c[i-1][j][0],c[i-1][j][1],c[i-1][j][2],c[i-1][j][3]);
			c[i][j][0]=max(f,c[i][j-1][0]);
			ans=max(ans,c[i][j][0]);
			for(int l=1;l<=3;l++)
			{
				if(msap[i][j])
				{
					if(l==1)
					{
						c[i][j][l]=f+msap[i][j];
					}
					if(c[i][j-1][l-1])
					{
						c[i][j][l]=max(c[i][j][l],c[i][j-1][l-1]+msap[i][j]);
					}
				}
				if(c[i][j-1][l])
				{
					c[i][j][l]=max(c[i][j][l],c[i][j-1][l]);
				}
				ans=max(ans,c[i][j][l]);
			}
		}
	}
		
	cout<<ans<<endl;
}

Measured memory_bytes: 355220
import java.io.InputStream;
import java.io.PrintStream;
import java.util.Scanner;

public class Main {
	InputStream in = System.in;
	PrintStream out = System.out;

	public void _main(String[] args) {
		Scanner sc = new Scanner(in);

		int r = sc.nextInt();
		int D = sc.nextInt();
		int x = sc.nextInt();

		int[] a = new int[10 + 1];
		a[0] = x;

		for (int i = 1; i <= 10; i++) {
			a[i] = r * a[i - 1] - D;
		}

		for (int i = 1; i <= 10; i++) {
			out.println(a[i]);
		}

		sc.close();

	}

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

}


Measured memory_bytes: 21716
n, x = map(int, input().split())


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

total=0
ans=0
for i in range(n):
  total += a[i]
 
  if total > x:
    ans = i
    break
  elif total ==x:
    ans = i+1
    break
  else:
    ans=i
  
print(ans)

Measured memory_bytes: 3060
def match(s, t, i):
    for pos in range(len(t)):
        if s[i + pos] != "?" and t[pos] != s[i + pos]:
            return False
    return True


def main():
    s = input()
    t = input()

    for i in reversed(range(len(s) - len(t) + 1)):
        if match(s, t, i):
            s = s[:i] + t + s[i + len(t):]
            print(s.replace("?", "a"))
            return
    print("UNRESTORABLE")


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <stdio.h>


int main(void){
    
    int a,b;
    scanf("%d",&a);
    scanf("%d",&b);

    if (a <= 8){
        if (b <= 8){
            printf("Yay!");
        }
        else printf(":(");
    }
    else printf(":(");

    return 0;

}

Measured memory_bytes: 128
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Math;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            A();
        }

        static void A()
        {
            var LR = ReadSplitLong();
            var L = LR[0];
            var R = LR[1];

            var min = long.MaxValue;
            for (var i = L; i < R; i++)
            {
                for (var j = i + 1; j <= R; j++)
                {
                    if (i * j % 2019 == 0)
                    {
                        Println(0);
                        return;
                    }
                    min = Min(min, i * j % 2019);
                }
            }
            Println(min);
        }


        static List<long> ReadLines(long n)
        {
            var l = new List<long>();
            for (long i = 0; i < n; i++)
            {
                l.Add(ReadLong());
            }
            return l;
        }

        static IEnumerable<int> Range(int start, int stop)
        {
            if (start < 0 || stop < 0 || start > stop || (start <= 0 && stop <= 0))
                return new List<int>();

            return Enumerable.Range(start, stop - start);
        }

        static bool IsDigit(string str)
        {
            var i = 0;
            return int.TryParse(str, out i);
        }

        static int SumDigits(long num)
        {
            return num.ToString().Select(x => x.ToString()).Sum(int.Parse);
        }

        static int[] ToIntArray(string str)
        {
            return str.Select(x => x.ToString()).Select(int.Parse).ToArray();
        }

        static long Gcd(long a, long b) => b == 0 ? a : Gcd(b, a % b);
        static long Lcm(long a, long b) => a / Gcd(a, b) * b;

        static bool IsPrime(int x)
        {
            if (x <= 1 || (x != 2 && x % 2 == 0)) return false;
            if (x == 2) return true;

            for (int i = 3; i < x; i += 2)
                if (x % i == 0) return false;

            return true;
        }

        static string Read() => Console.ReadLine();
        static int ReadInt() => int.Parse(Read());
        static long ReadLong() => long.Parse(Read());

        static List<string> ReadSplit() => Read().Split().ToList();
        static List<int> ReadSplitInt() => Read().Split().Select(int.Parse).ToList();
        static List<long> ReadSplitLong() => Read().Split().Select(long.Parse).ToList();

        static void Print(object value) => Console.Write(value.ToString());
        static void Println(object value) => Console.WriteLine(value.ToString());

        static string Join<T>(IEnumerable<T> list) => string.Join("", list);
    }

    public static class MyExtensions
    {
        public static string Slice(this string str, int start = 0, int stop = 0)
        {
            if (start > str.Length || stop > str.Length || start < 0 || stop < 0)
                return "";

            if (stop == 0) stop = str.Length;
            return str.Substring(start, stop - start);
        }
    }
}


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

int main() {
    int64_t N, M;
    std::cin >> N >> M;

    int64_t A;
    for (int i = 0; i < M; ++i) {  
        std::cin >> A;
        N -= A;
    }

    if (N >= 0) {
        std::cout << N << std::endl;
    } else {
        std::cout << -1 << std::endl;
    }

    return 0;
}


Measured memory_bytes: 3636
from math import cos, sin, sqrt, radians
short, long, hour,minit = map(int,input().split())

short_kaku = 90 - (30 * hour + 0.5 * minit)
short_x = short * cos(radians(short_kaku))
short_y = short * sin(radians(short_kaku))

long_kaku = 90 - 6 * minit
long_x = long * cos(radians(long_kaku))
long_y = long * sin(radians(long_kaku))

distance = sqrt((short_x - long_x) ** 2 + (short_y - long_y) ** 2)

print(distance)


Measured memory_bytes: 9460
#include<bits/stdc++.h>
using namespace std;
int n;
char s[10];
int cnta,cntw,cntt,cntr;
int main()
{
	cnta = cntw = cntt = cntr = 0;
	scanf("%d", &n);
	for(int i = 1; i <= n; i ++)
	{
		scanf("%s",s);
		if(s[0] == 'A') cnta ++;
		if(s[0] == 'W') cntw ++;
		if(s[0] == 'T') cntt ++;
		if(s[0] == 'R') cntr ++; 
	}
	printf("AC x %d\n",cnta);
	printf("WA x %d\n",cntw);
	printf("TLE x %d\n",cntt);
	printf("RE x %d\n",cntr);
	return 0;
}


Measured memory_bytes: 3820
# -*- coding: utf-8 -*-

n,k = map(int, raw_input().split())

array = [0]*(10**5+1)
num = 0        
index = 0
for i in range(n):
    a,b = map(int, raw_input().split())
    array[a] += b
for i in range(10**5+1):
    num += array[i]
    if(num>=k):
        index = i
        break
    

print(index)

Measured memory_bytes: 8068
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define INF 1000000000
#define mod 1000000007
using ll=long long;
const ll LINF=1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
// ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return true;}return false;}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    
    ll n;cin>>n;
    string s="";
    while(n){
        n--;
        s.push_back('a'+n%26);
        n/=26;
    }
    reverse(ALL(s));
    cout<<s<<endl;
    return 0;
}


Measured memory_bytes: 3652
#include<iostream>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<limits>
#include<sstream> 
#include<unordered_map>      

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;

const int inf = numeric_limits<int>::max() >> 2;
const ll linf = numeric_limits<ll>::max() >> 2;
const ull ulinf = numeric_limits<ull>::max() >> 2;
const double pi = acos(-1);
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int dx8[8]={-1,0,1,-1,1,-1,0,1};
const int dy8[8]={-1,-1,-1,0,0,1,1,1};

#define p_queue(i) priority_queue<i> 
#define rp_queue(i) priority_queue<i, vector<i>, greater<i>> 
#define umap(i,j) unordered_map<i,j>
#define P(p) cout<<(p)<<endl
#define PS(p) cout<<(p)<< " "
#define PN cout << endl
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i = (n-1); i >= (int)(m); i--)
#define inrep(n,a) for(int i = 0; i < (int)(n); i++)cin >> a[i];
#define mod(i) ((i)%(ll)(1e9 + 7))
#define divm(a,b) (mod(a * modpow((ll)b,(ll)(1e9+5))))
#define rsort(a,b,c) sort(a, b, greater<c>())
#define vsort(v) sort(v.begin(), v.end())
#define rvsort(v,c) sort(v.begin(), v.end(), greater<c>()) 
#define ft first
#define sd second
#define pb push_back
#define it insert
#define sz(x) ((int)(x).size())
#define lb(a,n,k) (lower_bound(a,a+n,k) - (a)) 
#define vlb(a,k)  (lower_bound(a.begin(),a.end(),k) - a.begin())
#define ub(a,n,k) (upper_bound(a,a+n,k) - (a)) 
#define vub(a,k)  (upper_bound(a.begin(),a.end(),k) - a.begin())
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return


ll modpow(ll i,ll j){ ll tmp=1; while(j){ if(j%2)tmp=mod(tmp*i);i=mod(i*i);j/=2;}return tmp;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }


/*
vector<string> split(const string &str, char sep){
    vector<string> v;
    stringstream ss(str);
    string buffer;
    while( getline(ss, buffer, sep) ) {
        v.push_back(buffer);
    }
    return v;
}
*/

/*
ll ncr[100][100];
ll nCr(int n, int r){if(n==r) ret ncr[n][r] = 1; if(r==0) ret ncr[n][r] = 1; if(r==1) ret ncr[n][r] = n;if(ncr[n][r]) ret ncr[n][r]; ret ncr[n][r] = nCr(n-1,r) + nCr(n-1,r-1);}

ll npr[100][100]={};
ll nPr(int n,int r){if(npr[n][r])ret npr[n][r];if(r==0)ret npr[n][r] = 1;if(r==1)ret npr[n][r] = n;ret npr[n][r] = n * nPr(n-1,r-1);}

ll nHr(int n,int r){ret nCr(n+r-1,r);}
*/

///////////////////////////////////////////////////////////////////////////

int main(){
    ll n,k;
    cin >> n >> k;
    ll ans = n;

    ans = min(ans, n%k);
    n %= k;
    ans = min(ans,abs(n-k));
    P(ans);
    return  0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
public class ABC123B{
    public static void Main(){
        int a, b, c, d, e, k = -1, ans = 0;
        a = int.Parse(System.Console.ReadLine());
        b = int.Parse(System.Console.ReadLine());
        c = int.Parse(System.Console.ReadLine());
        d = int.Parse(System.Console.ReadLine());
        e = int.Parse(System.Console.ReadLine());

        int[] time = new int[]{a,b,c,d,e};
        int remain = 9;
        for(int i = 0; i < 5; i++) {
            if (remain >= time[i] % 10 && time[i] % 10 != 0) {
                remain = time[i] % 10;
                k = i;
            }
        }
        for(int i = 0; i < 5; i++) {
            if (i == k) {
                ans += ((int) time[i] / 10) * 10 + remain;
            } else if (time[i] % 10 != 0){
                ans += ((int) time[i] / 10) * 10 + 10;
            } else {
                ans += ((int) time[i] / 10) * 10;
            }
        }
        
        System.Console.WriteLine(ans);
        
    }
}


Measured memory_bytes: 13140
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <functional>

using namespace std;

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

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

struct SegmentTree {
	ll init_val;
	int n;
	vector<ll> dat;
	
	SegmentTree(int _n) {
		init_val = -INF;
		n = 1;
		while (n < _n) n *= 2;
		dat.clear();
		dat.resize(2 * n - 1, init_val);
	}
	
	void update(int k, ll a) {
		k += n - 1;
		dat[k] = a;
		
		while (k > 0) {
			k = (k - 1) / 2;
			dat[k] = max(dat[2 * k + 1], dat[2 * k + 2]);
		}
	}
	
	ll query(int a, int b, int k, int l, int r) {
		if (r <= a || b <= l) return init_val;
		if (a <= l && r <= b) return dat[k];
		return max(query(a, b, k * 2 + 1, l, (l + r) / 2), query(a, b, k * 2 + 2, (l + r) / 2, r));
	}
	
	ll query(int a, int b) {
		return query(a, b, 0, 0, n);
	}
};

ll n, d;
ll x[30], y[30];

void dfs(int pos, int end, P sum, vector<P> &v) {
	if (pos == end) {
		v.push_back(sum);
		return;
	}
	
	dfs(pos + 1, end, P(sum.first + x[pos], sum.second - y[pos]), v);
	dfs(pos + 1, end, P(sum.first - x[pos], sum.second + y[pos]), v);
	dfs(pos + 1, end, sum, v);
}


int main() {
	
    cin >> n >> d;
    REP(i,n) cin >> x[i] >> y[i];
     
	vector<P> s, u;
     
    dfs(0, n / 2, P(0, 0), s);
    dfs(n / 2, n, P(0, 0), u);
	
	sort(s.rbegin(), s.rend());
	sort(u.begin(), u.end());
	
	s.erase(unique(s.begin(), s.end()), s.end());
	u.erase(unique(u.begin(), u.end()), u.end());
	
	SegmentTree seg(u.size());
	REP(i, u.size()) seg.update(i, u[i].second);
	
	int l = 0, r = 0;
	ll ans = -INF;
	REP(i, s.size()) {
		while (l < u.size() && u[l].first < -d - s[i].first) l++;
		while (r < u.size() && u[r].first <= d - s[i].first) r++;
		
		ans = max(ans, s[i].second + seg.query(l, r));
	}
	
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 713372
/**
*    author:  boutarou
*    created: 02.08.2020 21:35:32
**/

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

ll n, k;
vector<ll>a;

bool check(int x) {
    ll res = 0;
    rep(i, n) {
        if (a[i] % x == 0) res += a[i] / x - 1;
        else res += a[i] / x;
    }
    return res <= k;
}

int main() {
    cin >> n >> k;
    rep(i, n) {
        ll x;
        cin >> x;
        a.push_back(x);
    }
    ll ok = 1e9, ng = 0;
    while((ok - ng) > 1) {
        ll mid = (ok + ng) / 2;
        if (check(mid)) ok = mid;
        else ng = mid;
    }
    cout << ok << endl;
    return 0;
}

Measured memory_bytes: 5276
#include<cstdio>
#include<iostream>
#include<map>
#include<set>
#include<vector>
#include<cstring>
#include<cassert>
#include<sstream>
#include<cmath>
#include<algorithm>
#include<queue>
#include<limits>
#include<ctime>
#include<stack>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
	ll N,K;
	cin >> N >> K;
	
	ll d[10];
	for(ll i=0;i<K;i++){
		cin >> d[i];
		}
		
    ll ans = N;
    for(ll i=N;i<=N*10;i++){
    	ll temp = i;
    	ll cnt = 0;
    	while(temp > 0){
    		ll num = temp%10;
    		for(ll k = 0; k<K;k++){
    			if(num == d[k]) cnt +=1;
    			}
    		temp/=10;
    	}
    	if(cnt == 0){
    		ans = i;
    		break;
    	}
    }
	
	cout << ans << endl;
	
	return 0;
	}

Measured memory_bytes: 3628
#include <stdio.h>
int main(void)
{
	int a, b, c;

	scanf("%d %d %d", &a, &b, &c);

	if ((a<b)&&(b<c))
	{
		printf("Yes\n");
	}
	else
	{
		printf("No\n");
	}

	return 0;
}


Measured memory_bytes: 2048
#include <bits/stdc++.h>
#define INF 2000000000000000000
#define ll long long
#define pb push_back
using namespace std;


const ll MAX = 510010;
const ll mod = 1000000007;
vector<ll> fac(MAX), finv(MAX), inv(MAX);
bool init_called = false;
//=============modinv============================
void COMinit() {
  init_called = true;
  fac.at(0) = 1;
  fac.at(1) = 1;
  finv.at(0) = 1;
  finv.at(1) = 1;
  inv.at(1) = 1;
  for (ll i = 2; i < MAX; i++){
    fac.at(i) = fac.at(i - 1) * i % mod;
    inv.at(i) = mod - inv.at(mod % i) * (mod / i) % mod;
    finv.at(i) = finv.at(i - 1) * inv.at(i) % mod;
  }
}

ll COM(ll n, ll k){
  if (!init_called) {
    COMinit();
  }
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac.at(n) * (finv.at(k) * finv.at(n - k) % mod) % mod;
}
//=================================================

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll mod = pow(10, 9) + 7;
  ll N, K;
  cin >> N >> K;
  ll M = min(N, K);
  ll ans = 0;
  for (ll i = 1; i <= M; ++i) {
    ll temp = COM(N, i);
    temp *= COM(N - 1, i);
    temp %= mod;
    ans += temp;
    ans %= mod;
  }
  cout << ans + 1 << "\n";
}


Measured memory_bytes: 14992
#include <bits/stdc++.h>
using namespace std;
char a[1000001],b[1000001];
int main()
{
	scanf("%s\n",a);
	scanf("%s",b);
	if(strcmp(a,b)==0)
	{
		printf("No\n");
		return 0;
	}
	sort(a,a+strlen(a));
	sort(b,b+strlen(b));
	
	
	if(a[0]<b[strlen(b)-1]){
		printf("Yes");
		return 0;
	}
	
	
	if(strcmp(a,b)<0) printf("Yes");
	else printf("No");
	return 0;
}

Measured memory_bytes: 256
-- [Char]あるいは String を Int にする
toInt :: (String -> Int)
toInt x = read x ::Int

--入力を受け取り、[Int]にする
getInts = do
  x <- getLine
  let y = (map $ toInt) $ words x -- 半角スペースで分割してInt にする
  return y

-- C
divisor :: Int -> [Int]
divisor n = [m | m <- [1..half], n `mod` m == 0]
            where
                half = n `div` 2

prime :: Int -> Bool
prime n = length (divisor n) == 1 

main = do
    x <- readLn :: IO Int
    putStrLn $ show (head $ filter prime [x..])


Measured memory_bytes: 508
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>

using namespace std;

int MAX = 1e6+2;
int main(){
	int n, i, m, arr[MAX];
	cin >> n;
	n = n%10;
	if (n==2 or n==4 or n==5 or n==7 or n==9){
		cout << "hon";
	}
	else if (n==0 or n==1 or n==6 or n==8){
		cout << "pon";
	}
	else{
		cout << "bon";
	}
}

Measured memory_bytes: 3608
# coding: utf-8
# Your code here!

# 両方とも正しいならば YES、そうでないならば NO を出力してください。

A, B, C = input().split()

# print(A)
# print(B)
# print(C)

if A[-1] == B[0] and B[-1] == C[0]:
 print('YES')
else:
 print('NO')

Measured memory_bytes: 2940
main :: IO ()
main = do
  ls <- getLine
  if ls == "0"
    then return ()
    else do
      let ls' = map (read :: String -> Int) (words ls)
          ls'' = [min i 10 | i <- ls']
          ans = point ls''
      putStrLn $ show ans
      main


point :: [Int] -> Int
point ls
  | initScore > 21 = 0
  | initScore > 11 = initScore
  | (count 1 ls) == 0 = initScore
  | (count 1 ls) == 1 = initScore + 10
  | (count 1 ls) >= 2 && initScore > 1 = initScore + 10
  | otherwise = initScore + 20
  where initScore = sum ls
        count n ls = foldl f 0 ls
          where f i x
                  | x == n = i + 1
                  | otherwise = i

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

int main(){
    int N;
    cin >> N;
    map<string,int> m;
    ll ans = 0;
    rep(i,N){
        string s;
        cin >> s;
        sort(s.begin(), s.end());
        ans += m[s]; m[s]++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 11136
#include<stdio.h>
#include<string.h>
int main()
{
    int length,k,i;
    char s[104];
    scanf("%d",&k);
    scanf("%s",&s);
    length=strlen(s);
    if(length>k)
    {
        s[k]='.';
        s[k+1]='.';
        s[k+2]='.';
        for(i=0;i<=k+2;i++)
            printf("%c",s[i]);
    }
    else
    {
        for(i=0;i<length;i++)
            printf("%c",s[i]);
    }
    return 0;
}


Measured memory_bytes: 1664
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <numeric>
#include <array>
#include <cmath>
#include <memory>
using namespace std;
//変数デバッグ
#define DEB(variable) cout << #variable << '=' << variable << endl

//for簡易表記(引数ミス防止)
#define FOR(LoopVariable,numberOFbegin,numberOFend) for (int LoopVariable = (numberOFbegin); (LoopVariable) < (numberOFend); (LoopVariable)++)
#define DEFOR(LoopVariable,numberOFbegin,numberOFend) for (int LoopVariable = (numberOFbegin)-1; (LoopVariable) >= (numberOFend); (LoopVariable)--)
#define REP(LoopVariable,numberOFend) for(int LoopVariable = 0;(LoopVariable)<(numberOFend);LoopVariable++)

constexpr long long int linf = numeric_limits<long long int>::max()-5;
constexpr int inf= numeric_limits<int>::max()-5;
constexpr long long int mod = 1000000007;

int main(){

    long long int a,b,c,x,y;
    cin>>a>>b>>c>>x>>y;

    cout << min(min(max(x, y) * 2 * c, a * x + b * y),min(x,y)*2*c+abs(x-y)*(x>y?a:b)) << endl;

    return 0;
}


Measured memory_bytes: 256
q,h,s,d=map(int,input().split())
n=int(input())
Q=4*q
H=2*h
S=s
D=d/2
b=[Q,H,S,D]
a=sorted(b)
if a[0]==D and n%2==1:
    ans=(n//2)*d+a[1]
elif a[0]==D:
    ans=(n//2)*d
else:
    ans=n*a[0]
print(ans)

Measured memory_bytes: 3064
n, m = list(map(int, input().split()))
data = []
data1 = []
data2 = []
for i in range(m):
    data.append(list(map(int, input().split())))
for i in range(m):
    data1.append(data[i][0])
    data2.append(data[i][1])
if min(data2) - max(data1)  + 1 > 0:
    print(min(data2) - max(data1) + 1)
else:
    print(0)

Measured memory_bytes: 29076
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <numeric>
#include <set>
#include <list>
#include <bitset>
#include <cstdlib>
#include <map>
using ll = long long int;
using namespace std;

int main()
{
    int N, H, W, ans = 0;
    cin >> N >> H >> W;
    for (int i = 0; i < N; i++)
    {
        int a, b;
        cin >> a >> b;
        if ((H <= a) && (W <= b))
        {
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

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

int main() {
	int h, w;

	while(cin >> h >> w) {
		if(h==0 && w==0) break;

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

	return 0;
}


Measured memory_bytes: 3084
#include <stdio.h>

int main(){
  int S;
  scanf("%d", &S);

  int h, m, sec;

  h = S / 3600;
  S = S % 3600;
  m = S / 60;
  sec = S % 60;

  printf("%d:%d:%d\n", h, m, sec);

  return 0;
}

Measured memory_bytes: 592
#include <bits/stdc++.h>
using namespace std;
const long long int INF = 1e18;

// computational complexity : O(E*logV)

struct edge{ int to, cost; };
int V,E;
vector<vector<edge>> graph;
vector<long long int> d;// shortest distances

void Dijkstra(int s){// s = starting point
    priority_queue<
        pair<int, int>// temporarily keeping (shortest distance, vertex)
        , vector<pair<int, int>>, greater<pair<int, int>>// shorter ones first
    > pq;

    // initialize (INF)
    for(int i=0; i<V; i++){
        d[i] = INF;
    }
    d[s] = 0;
    pq.push({0,s});

    // search
    pair<int, int> current;// (shortest-distance confirmed, vertex)
    while(!pq.empty()){
        current = pq.top(); pq.pop();

        int v = current.second;
        if(d[v] < current.first){
            continue;// ignore (not the shortest path)
        }
        // else (need to check)
        for(edge e : graph[v]){// adjacent nodes
            if(d[e.to] > d[v] + e.cost){
                d[e.to] = d[v] + e.cost;// update minimum cost
                pq.push({d[e.to], e.to});
            }
        }
    }
}

int main(){
    int s;// starting point
    cin >> V >> E >> s;
    graph.resize(V*2500);
    d.resize(V*2500);
    if(s > 2499) s = 2499;

    for(int i=0; i<E; i++){
        int u, v, a, b;
        cin >> u >> v >> a >> b;
        u -= 1;
        v -= 1;
        for(int j=2499; j-a>=0; j--){
            graph[u*2500 + j].push_back({v*2500 + j - a, b});
            graph[v*2500 + j].push_back({u*2500 + j - a, b});
        }
    }
    for(int v=0; v<V; v++){
        int c, d;
        cin >> c >> d;
        for(int j=0; j<2500; j++){
            graph[v*2500 + j].push_back({v*2500 + min(j + c, 2499), d});
        }
    }

    V *= 2500;
    Dijkstra(s);// starting from s
    V /= 2500;

    for(int i=1; i<V; i++){
        long long int ans = INF;
        for(int j=0; j<2500; j++){
            ans = min(ans, d[i*2500+j]);
        }
        cout << ans << endl;
    }
    return 0;
}

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

using namespace std;
using ll = long long;
using ld = long double;

//#define int long long
//signed main(){
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int h,w,n;
    cin >> h >> w >> n;
    vector<int> a(n);
    for(int i = 0; i < n; i++) {
        cin >> a[i];
    }
    vector<int> c(h*w);
    int k=0;
    for(int i = 0; i < n; i++) {
        for(int j = 0; j < a[i]; j++) {
            c[k]=(i+1);
            k++;
        }
    }

    for(int i = 0; i < h; i++) {
        if(i%2){
            for(int j = 0; j < w; j++) {
                cout << c[i*w+j] << " ";
            }
        }
        else{
            for(int j = 0; j < w; j++) {
                cout << c[i*w+(w-1-j)] << " ";
            }
        }
        cout << "\n";
    }

    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
using namespace std;

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

int main()
{
    int n, a[200005] = {}, m[200005] = {};
    cin >> n;
    rep(i, n)
    {
        cin >> a[i];
        m[i] = a[i];
    }

    sort(m, m + n);
    int maxv1 = m[n - 1];
    int maxv2 = m[n - 2];

    rep(i, n)
    {
        if (a[i] == maxv1)
        {
            cout << maxv2 << endl;
        }
        else
        {
            cout << maxv1 << endl;
        }
    }
}

Measured memory_bytes: 3200
import java.util.*;
public class Main{
	public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
      String str = sc.next();
      String s1 = str.substring(0,2);
      String s2 = str.substring(2,4);
      int x = Integer.parseInt(s1);
      int y = Integer.parseInt(s2);
      if(x>=1 && x<=12 && y>=1 && y<=12) System.out.println("AMBIGUOUS");
      else if(x>=1 && x<=12) System.out.println("MMYY");
      else if(y>=1 && y<=12) System.out.println("YYMM");
      else System.out.println("NA");
    }
}


Measured memory_bytes: 20688
n=int(input())
*h,=map(int,input().split())

dp=[float('inf')]*n
dp[0]=0
for i in range(n-1):
      dp[i+1]=min(dp[i+1],dp[i]+abs(h[i]-h[i+1]))
      if i<n-2:
            dp[i+2]=min(dp[i+2],dp[i]+abs(h[i]-h[i+2]))
print(dp[-1])


Measured memory_bytes: 13980
#include <stdio.h>
#include <set>
#include <vector>
#include <utility>
#include <algorithm>
typedef long long ll;
using namespace std;

ll min(ll a, ll b) {
  return a < b ? a : b;
}

int main(void) {
  ll i, j, k, n, ans = 0;
  scanf("%lld", &n);
  pair< pair<ll, ll>, ll>  x[n], y[n];
  pair<ll, ll> a[n];
  bool flg[n];
  for(i = 0; i < n; ++i) flg[i] = true;
  flg[0] = false;
  for(i = 0; i < n; ++i) {
    scanf("%lld%lld", &a[i].first, &a[i].second);
    y[i].first.first = x[i].first.second = a[i].second, y[i].first.second = x[i].first.first = a[i].first;
    x[i].second = y[i].second = i;
  }
  sort(x, x + n); sort(y, y + n);
  vector< pair<ll, ll> > vec[n];
  for(i = 1; i < n; ++i) {
    vec[x[i - 1].second].push_back(make_pair(min(abs(x[i - 1].first.first - x[i].first.first), abs(x[i - 1].first.second - x[i].first.second)), x[i].second));
    vec[x[i].second].push_back(make_pair(min(abs(x[i - 1].first.first - x[i].first.first), abs(x[i - 1].first.second - x[i].first.second)), x[i - 1].second));
    vec[y[i - 1].second].push_back(make_pair(min(abs(y[i - 1].first.first - y[i].first.first), abs(y[i - 1].first.second - y[i].first.second)), y[i].second));
    vec[y[i].second].push_back(make_pair(min(abs(y[i - 1].first.first - y[i].first.first), abs(y[i - 1].first.second - y[i].first.second)), y[i - 1].second));
  }
  set< pair<ll, ll> > se;
  for(i = 0; i < vec[0].size(); ++i) se.insert(vec[0][i]);
  for(i = 1; i < n; ++i) {
    while(!flg[(*se.begin()).second]) se.erase(se.begin());
    pair<ll, ll> p = *se.begin();
    se.erase(se.begin());
    flg[p.second] = false;
    ans += p.first;
    for(j = 0; j < vec[p.second].size(); ++j) if(flg[vec[p.second][j].second]) se.insert(vec[p.second][j]);
  }
  printf("%lld", ans);
  return 0;
}


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

int main(){
  double A,B;cin >> A>>B;
  int H,M;cin >>H>>M;
  cout << fixed << setprecision(9);
  double kakudo = (60*H-11*M)*M_PI;
  double l=sqrt(pow(A,2)+pow(B,2)-(2*A*B*cos(kakudo/360)));
  cout << l << endl;
}

Measured memory_bytes: 4264