akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define WHOLE(v) (v).begin(), (v).end()
#define REV_WHOLE(v) (v).rbegin(), (v).rend()
using i64 = int64_t;
using namespace std;
template<typename T> using rev_priority_queue = priority_queue<T, vector<T>, greater<T>>;
template<class S, class T> void map_init(map<S, T> &m, S k, T v){if(!m.count(k)) m[k] = v;}
void R_YESNO(bool p) { cout << (p ? "YES" : "NO") << endl; }
void R_YesNo(bool p) { cout << (p ? "Yes" : "No") << endl; }

int main() {
    i64 X, Y;
    cin >> X >> Y;
    cout << (abs(X - Y) <= 1 ? "Brown" : "Alice") << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm> 
#include <queue>
#include <functional>
using namespace std;

int w, h;
int vx[] = { 1, 0, -1, 0, };
int vy[] = { 0, 1, 0, -1, };
char field[101][101];
bool used[101][101];

void dfs(int x, int y){
    used[x][y] = true;
    for (int i = 0; i < 4; i++){
        int nextx = x + vx[i];
        int nexty = y + vy[i];
        if (0 < nextx && nextx < w + 1 && 0 < nexty && nexty < h + 1 && !used[nextx][nexty]
            && field[nextx][nexty] == field[x][y]){
            dfs(nextx, nexty);
        }
    }

    return;
    
}

int main(void){

    while (true){

        cin >> h >> w;

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

        for (int i = 1; i <= h; i++){
            for (int j = 1; j <= w; j++){
                cin >> field[j][i];
                used[j][i] = false;
            }
        }

        int ans = 0;

        for (int i = 1; i <= w; i++){
            for (int j = 1; j <= h; j++){
                if (!used[i][j]){
                    ans++;
                    dfs(i, j);
                }
            }
        }

        cout << ans << endl;
    }
    

}

Measured memory_bytes: 3728
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <sstream>
#include <utility>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
#define all(c) (c).begin(), (c).end()
#define loop(i,a,b) for(ll i=a; i<ll(b); i++)
#define rep(i,b) loop(i,0,b)
#define each(e,c) for(auto&e:c)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define lb lower_bound
#define ub upper_bound
#ifdef DEBUG
#define dump(...) (cerr<<#__VA_ARGS__<<" = "<<(DUMP(),__VA_ARGS__).str()<<" ["<<__LINE__<<"]"<<endl)
struct DUMP:ostringstream{template<class T>DUMP &operator,(const T&t){if(this->tellp())*this<<", ";*this<<t;return *this;}};
#else
#define dump(...)
#endif
template<class T> ostream& operator<<(ostream& os, vector<T> const& v){
    rep(i,v.size()) os << v[i] << (i+1==v.size()?"":" ");
    return os;
}

/*
  max 666*1000
 */

int P;
int a[6];
int val[6] = {500,100,50,10,5,1};

// xテ・ツ??」ツ?ッテ」ツつ嘉」ツ??
int pay(int x){
    int rem = x;
    int c = 0;
    rep(i,6){
        int k = min(a[i], rem/val[i]);
        rem -= k*val[i];
        c += k;
    }
    return rem ? 1e8 : c;
}

// テ」ツ?甘」ツ?、テ」ツつ?
int change(int x){
    int rem = x;
    int c = 0;
    rep(i,6){
        int k = rem/val[i];
        rem -= k*val[i];
        c += k;
    }
    return c;
}

int main(){
    while(cin >> P && P){
        rep(i,6) cin >> a[i];
        reverse(a,a+6);
        int ans = 1e8;
        int M = 0;
        rep(i,6) M+=a[i]*val[i];
        loop(i,P,max(M,P+10001)){
            int x = pay(i);
            if(x==1e8) continue;
            int y = change(i-P);
            //dump(x,y);
            ans = min(ans, x+y);
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using ll = long long;
using vi = vector<int>; using vvi = vector<vi>;
const ll MOD = 1e9+7; ll INF = 1LL << 60;
const vi d8x = {1, 0, -1, 0, 1, -1, -1, 1}; vi d8y = {0, 1, 0, -1, 1, 1, -1, -1};
const vi d4x = {1, 0, -1, 0}; vi d4y = {0, 1, 0, -1};
//---------------------------------------

int main(){
    int n; cin>>n;
    vector<string> s(n);
    rep(i,n) cin>>s[i];
    vector<vector<char>> box(n,vector<char>(10));
    rep(i,n){
        rep(j,10){
            box[i][j]=s[i][j];
        }
    }
    rep(i,n){
        sort(all(box[i]));
    }
    vector<string> new_s(n);
    rep(i,n){
        rep(j,10){
            new_s[i]+=(box[i][j]);
        }
    }
    sort(all(new_s));

    ll ans=0;
    ll cnt=1;
    rep(i,n-1){
        if(new_s[i]==new_s[i+1]){
            cnt++;
        }else{
            if(cnt>=2){
                ans+=(cnt*(cnt-1)/2);
            }
            cnt=1;
        }
    }
    if(cnt>=2){
                ans+=(cnt *(cnt-1)/2);
            }
    cout<<ans<<endl;
}

Measured memory_bytes: 19840
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

mod = 10**9+7
s = int(readline())

dp = [1] * 3000

dp[0] = 0
dp[1] = 0
dp[2] = 0

for i in range(3, 2020):
    for j in range(i+3, s+1):
        dp[j] += dp[i]
        dp[j] %= mod
print(dp[s])

Measured memory_bytes: 9284
#include<iostream>
#include<unordered_map>
#include<bitset>
#include<math.h>
#include<vector>
#include<set>
#include<algorithm>
#include<ctype.h>
#include<unordered_set>
#include<string>
#include<iomanip>
#include<queue>
#include<limits>
#include<map>
#include<stack>
#include<iterator>
#include<cstring>
 
#include<deque>
#define pi 3.141592653589793238
#include<chrono>
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define MOD 1000000007
#define INF 999999999999999999 
#define pb push_back
#define ff first
#define ss second
 
#define mt make_tuple
#define ll long long
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>

using namespace __gnu_pbds;
 
 
typedef tree<ll, null_type, less_equal<ll>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
 
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 
int main() {
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    fast;
    ll T = 1, i, j;
    
    //cin >> T;
    while (T--) {
        
        string s, t;
        cin >> s >> t;
        ll n = s.size();
        ll m = t.size();
        vector<vector<ll>> prefs(n + 1, vector<ll>(26)), preft(m + 1, vector<ll>(26));
        for(i = 0; i < n; i++){
            for(j = 0; j < 26; j++){
                prefs[i + 1][j] = prefs[i][j];
            }
            prefs[i + 1][s[i] - 'A']++;
        }
        for(i = 0 ; i < m; i++){
            for(j = 0; j < 26; j++){
                preft[i + 1][j] = preft[i][j];
            }
            preft[i + 1][t[i] - 'A']++;
        }
        ll q;
        cin >> q;
        while(q--){
            ll a, b, c, d;
            cin >> a >> b >> c >> d;
            ll c1, c2;
            c1 = prefs[b][0] - prefs[a - 1][0] + 2 * (prefs[b][1] - prefs[a - 1][1]);
            c2 = preft[d][0] - preft[c - 1][0] + 2 * (preft[d][1] - preft[c - 1][1]);
            ll val = abs(c1 - c2);
            //cout << c1 << " " << c2 << endl;
            if(val % 3 == 0){
                cout << "YES\n";
            } 
            else{
                cout << "NO\n";
            }
        }
    }
    return 0;
}

Measured memory_bytes: 51764
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <queue>
#include <stack>
#include <stdlib.h>
using namespace std;
#define rep(i,n) for (int i = 0; i <n; i++) 

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

using namespace std;

int main(){
    string s="aiu";
    std::cin >> s;
    if(s<="2019/04/30")std::cout << "Heisei" << std::endl;
        else std::cout << "TBD " << std::endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main
{
    public static void main(String[] args)
    {
      //入力
      Scanner sc = new Scanner(System.in);
      int n = sc.nextInt();
      int k = sc.nextInt();
      int[] h = new int[n];
      //System.out.println(n);
      //System.out.println(k);
      for(int i=0;i<n;i++) {
        h[i] = sc.nextInt();
      }
      //for(int i=0;i<n;i++) {
        //System.out.println(h[i]);
      //}
      
      //計算
      int rideNumber = 0;
      for(int i=0;i<n;i++) {
        if(h[i]>=k) {
          rideNumber += 1;
        }
        //System.out.println(rideNumber);
      }
      
      //出力
      System.out.println(rideNumber);
      
    }
      
}



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

#define ll long long int
	int h,w,white=0;

void print(auto dq, int iter){
	cout << "on iteration " << iter << "\n";
	char arr[h+2][w+2]={'.'};
	for(auto it:dq){
		arr[it.first][it.second] = '#';
		// cout << it.first << " " << it.second << "\n";
	}
	for(int i=1;i<=h;i++){
		for(int j=1;j<=w;j++){
			cout << arr[i][j] << " \n"[j==w];
		}
	}
}

int main(){
	cin >> h >> w;
	deque<pair<int,int> > dq;
	char arr[h+2][w+2]={'/'};
	for(int i=1;i<=h;i++){
		for(int j=1;j<=w;j++){
			cin >> arr[i][j];
			if(arr[i][j]=='#'){
				// black
				dq.push_back(make_pair(i,j));
			}
		}
	}
	while(dq.empty() == false){
		white += 1;
		deque<pair<int,int> > var_dq;
		while(dq.empty() == false){
			auto cur = dq.front();
			int i=cur.first,j=cur.second;
			dq.pop_front();
			if(arr[1+cur.first][cur.second] == '.'){
				arr[1+cur.first][cur.second] = '#';
				var_dq.push_back(make_pair(i+1,j));
			}if(arr[cur.first-1][cur.second] == '.'){
				arr[cur.first-1][cur.second] = '#';
				var_dq.push_back(make_pair(i-1,j));
			}if(arr[cur.first][cur.second+1] == '.'){
				arr[cur.first][cur.second+1] = '#';
				var_dq.push_back(make_pair(i,j+1));
			}if(arr[cur.first][cur.second-1] == '.'){
				arr[cur.first][cur.second-1] = '#';
				var_dq.push_back(make_pair(i,j-1));
			}
			// arr[cur.first][1+cur.second] = '#';
			// arr[cur.first][cur.second-1] = '#';
			// arr[cur.first-1][cur.second] = '#';
		}
			dq=var_dq;
			// print(dq,white);
		// for(int i=1;i<=h;i++){
		// 	for(int j=1;j<=w;j++){
		// 		if(arr[i][j]=='#')
		// 			dq.push_back(make_pair(i,j));
		// 	}
		// }

	}

	cout << white-1 << "\n";

	return 0;
}

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

int main() {
  int N;
  cin >> N;
  int a[N];
  for(int i=0; i<N; i++) {
    cin >> a[i];
  }
  int b[100001]={0};
  //sort(a, a+N);
  for(int i=0; i<N; i++) {
    b[a[i]]++;
  }
  int c[100001]={0}, ans=0;
  for(int i=1; i<100000; i++) {
    c[i]+=b[i-1]+b[i]+b[i+1];
    if(ans<c[i]) {
      ans=c[i];
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 1408
N,M,X,Y = map(int,input().split())
x = list(map(int,input().split()))
y = list(map(int,input().split()))
x.sort(reverse = True)
y.sort()

x_max = x[0]
y_min = y[0]
result = "War"
for z in range(X+1,Y+1):
    if x_max < z <= y_min:
        result = "No War"
        break

print(result)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define fs first
#define sc second
typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<char> vc;
typedef vector<tuple<ll,ll>> vtl;
typedef pair<ll, ll> l_l;
#define EPS (1e-7)
#define INF (1e12)
#define PI (acos(-1))


void solve(){
    ll n;

    cin>>n;
    vl a(n+1);
    rep(i,n)cin>>a[i];
    ll ans=INF;
    ll summ=0,sum=0;
    rep(i,n)summ+=a[i];
    rep(i,n){
        summ-=a[i];
        sum+=a[i];
        ans=min(ans,abs(summ-sum));
    }
   cout<<ans<<endl;
}

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


Measured memory_bytes: 1792
#include<cstdio>
#include<cstdlib>
//#include<iostream>
//using namespace std;
#define MAX 2000001
#define VMAX 10000
int main()
{
  unsigned short *A, *B;
  int C[VMAX + 1];
  int n, i, j;
  scanf("%d", &n);

  A = (unsigned short*)malloc(sizeof(short) * (n+1));
  B = (unsigned short*)malloc(sizeof(short) * (n+1));

  for(i=0; i<=VMAX; i++)
    C[i] = 0;
  for(i=0; i<n; i++)
  {
    scanf("%hu", &A[i+1]);
    C[A[i+1]]++;
  }
  for(i=1; i<=VMAX; i++)
    C[i] = C[i] + C[i-1];
  for(j=n; j>0; j--)
  {
    B[C[A[j]]] = A[j];
    C[A[j]]--;
  }
  for(i=1; i<=n; i++)
  {
    if(i > 1) printf(" ");
    printf("%d", B[i]);
  }
  printf("\n");

  return 0;
}



Measured memory_bytes: 10596
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
 
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=(n)-1;i>=0;i--)
#define VSORT(v) sort(v.begin(), v.end())
#define SORT(v, n) sort(v, v+n)
#define VREV(v,n) reverse(v,v+n)
#define REV(v,n) reverse(v,v+n)
#define vi vector<int>
#define pf push_front
#define pb push_back
#define P pair<int,int>
#define Pll pair<ll,ll>

template<class T, size_t N> size_t countof(const T (&array)[N]) { return N; }
template <class T> void chmin(T&a,const T&b) { a = min(a,b); }
template <class T> void chmax(T&a,const T&b) { a = max(a,b); }
 
void print(){cout<<"\n";}
template <class Head, class... Tail>
void print(Head&& h,Tail&&... t){ 
	if(sizeof...(t)==0)
		cout<<h;
	else
		cout<<h<<' ';
	print(move(t)...);
}

void mprint(auto *matrix,auto N){
	REP(i,N) cout<<matrix[i]<<(i!=N-1?' ':'\n');
	return;
}

const double EPS =1e-9;
const int INF =2e+9;
const ll INFL =9e+18;
const long MOD =1e+9+7;
#define PI 3.14159265258979

#define iP pair<int,P>
int dy[]={0, 0, 1, -1, 1, 1, -1, -1};
int dx[]={1, -1, 0, 0, 1, -1, -1, 1};

inline int in(){int x; cin>>x; return x;}

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

	int min=INF,sum,N;
	cin>>N>>sum;
	REP(i,N){
		int tem;
		cin>>tem;
		chmin(min,tem);
		sum-=tem;
	}

	print(N+sum/min);

	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int n,s,min,max,p,i;
  while(scanf("%d",&n),n){
    min=1100;
    max=0;
    for(i=s=0;i<n;i++){
      scanf("%d",&p);
      s+=p;
      if(max<p)max=p;
      if(min>p)min=p;
    }
    printf("%d\n",(s-max-min)/(n-2));
  }
  return 0;
}
  

Measured memory_bytes: 600
object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val n = sc.nextInt()

  if (n % 2 == 0) {
    println(0.5)
  } else {
    val m = n.toDouble
    println("%.9f".format(((m + 1) / 2) / m))
  }
}

Measured memory_bytes: 25928
# ABC054C - One-stroke Path
from itertools import permutations as perm


def main():
    N, M, *A = map(int, open(0).read().split())
    E = {(i, j) for i, j in zip(A[::2], A[1::2])}
    ans = 0
    for path in perm(range(2, N + 1), N - 1):  # check all possible paths (O(N!))
        path = (1,) + path
        if all((i, j) in E or (j, i) in E for i, j in zip(path, path[1:])):
            ans += 1
    print(ans)


if __name__ == "__main__":
    main()

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

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		
		int n = stdIn.nextInt();
		int m = stdIn.nextInt();
		int k = stdIn.nextInt();
		
		int chou = n * m;
		
		
		for(int i = 0; i <= n; i++) {
			for(int j = 0; j <= m; j++) {
				
				if(k == i*(m-j)+j*(n-i)) {
					System.out.println("Yes");
					return;
				}
				
				
			}
		}
		System.out.println("No");
		
		
	}

}


Measured memory_bytes: 21844
#include<stdio.h>
#include<iostream>
#include<cstring>
#include<iomanip>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
using namespace std;
typedef long long ll;
const int maxn=505;
string s[maxn];
bool mark[maxn][maxn];
ll cnt1=0,cnt2=0,ans=0;
int n,m,dx[maxn]={0,1,-1,0,0},dy[maxn]={0,0,0,-1,1};
void dfs(int x,int y){
	if(s[x][y]=='#')
		cnt1++;
	else	
		cnt2++;
	mark[x][y]=true;
	for(int i=1;i<=4;i++){
		int tox=x+dx[i],toy=y+dy[i];
		if(tox>=1&&tox<=n&&toy>=0&&toy<m&&!mark[tox][toy]&&s[tox][toy]!=s[x][y])
			dfs(tox,toy);
	}
}
int main(){
	//freopen("","r",stdin);
	//freopen("","w",stdout);
	ios::sync_with_stdio(false);
	cin>>n>>m;
	for(int i=1;i<=n;i++)
		cin>>s[i];
	memset(mark,false,sizeof(mark));
	for(int i=1;i<=n;i++)
		for(int j=0;j<m;j++){
			if(!mark[i][j]){
				cnt1=cnt2=0;	
				dfs(i,j);
				ans+=cnt1*cnt2;
				//cout<<cnt1<<" "<<cnt2<<" "<<i<<" "<<j<<endl;
			}
		}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 18176
#include <cstdio>
#include <stack>
#include <utility>

using namespace std;

typedef pair<int, int> point;

int w, h;
int c[50][50];
const int d[8][2] = {{1, 0}, {1, 1}, {0, 1}, {-1, 1}, {-1, 0}, {-1, -1}, {0, -1}, {1, -1}};

int count()
{
    stack<point> s;
    bool v[50][50] = {};
    int n = 0;

    for (int y = 0; y < h; ++y) {
        for (int x = 0; x < w; ++x) {
            if (v[x][y] || c[x][y] == 0)
                continue;

            s.push(point(x, y));
            v[x][y] = true;
            ++n;
            while (!s.empty()) {
                int x = s.top().first, y = s.top().second;
                s.pop();

                for (int i = 0; i < 8; ++i) {
                    int xx = x + d[i][0], yy = y + d[i][1];
                    if (0 <= xx && xx < w && 0 <= yy && yy < h
                            && !v[xx][yy] && c[xx][yy] == 1) {
                        s.push(point(xx, yy));
                        v[xx][yy] = true;
                    }
                }
            }
        }
    }

    return n;
}

int main()
{
    for (;;) {
        scanf("%d %d", &w, &h);
        if (w == 0 && h == 0)
            break;

        for (int i = 0; i < h; ++i)
            for (int j = 0; j < w; ++j)
                scanf("%d", &c[j][i]);

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

    return 0;
}

Measured memory_bytes: 1064
#include <bits/stdc++.h>
using namespace std;
void alert(vector<int64_t> vec){
  int64_t N = vec.size();
  for(int64_t i=0; i<N-1; i++) cout << vec.at(i) << " ";
  cout << vec.at(N-1) << endl;
}
vector<int64_t> next(vector<int64_t> a){
  int64_t N = a.size();
  for(int64_t i=0; i<N; i++){
    if(a.at(i)==0){
      a.at(i)=1;
      return a;
    }
    else a.at(i)=0;
  }
  return {-1};
}

vector<int64_t> st(int64_t M, vector<int64_t> buy, vector<vector<int64_t>> A){
  vector<int64_t> res(M);
  int64_t N = A.size();
  for(int64_t i=0; i<N; i++){
    if(buy.at(i)==1){
      for(int64_t j=0; j<M; j++){
        res.at(j) += A.at(i).at(j);
      }
    }
  }
  return res;
}

int64_t check(vector<int64_t> st, int64_t X){
  int64_t N = st.size();
  for(int64_t i=0; i<N; i++){
    if(st.at(i)>=X){}
    else return 0;
  }
  return 1;
}

int64_t yen(vector<int64_t> buy, vector<int64_t> C){
  int64_t res = 0;
  int64_t N = C.size();
  for(int64_t i=0; i<N; i++){
    if(buy.at(i)==1) res += C.at(i);
  }
  return res;
}

int main(){
  int64_t N, M, X;
  cin >> N >> M >> X;
  vector<int64_t> C(N);
  vector<vector<int64_t>> A(N);
  for(int64_t i=0; i<N; i++){
    cin >> C.at(i);
    for(int64_t j=0; j<M; j++){
      int64_t a; cin >> a;
      A.at(i).push_back(a);
    }
  }
  vector<int64_t> buy(N);
  int64_t ans = 10000000;
  for(int64_t i=0; i<pow(2,N); i++){
    if(buy.at(0)==-1){
      break;
    }
    if(check(st(M,buy,A),X)==1){ 
      ans = min(ans,yen(buy,C));
    }
    buy = next(buy);
  }
  if(ans == 10000000){
    cout << -1 << endl;
    return 0;
  }
  cout << ans << endl;
}

Measured memory_bytes: 4116
#include<iostream>
using namespace std;
int main()
{
	int n,m;
	cin>>n>>m;
	int t1,t2;
	cin>>t1>>t2;
	m--;
	for(int i=0;i<m;i++)
	{
		int x,y;
		cin>>x>>y;
		if(x>t1)
		t1=x;
		
		if(y<t2)
		t2=y;
		
	}
	if(t2>=t1)
	cout<<t2-t1+1;
	else
	cout<<"0";
	return 0;
}

Measured memory_bytes: 256
int main(void){
	int a[110], n, k, j, i, l;
	
	scanf("%d", &n);
	
	for(i=0; i<n; i++){
		scanf("%d", &a[i]);
	l=l+a[i]*a[i];
    }
  for(k=1;k<101;k++){
    j=0;
    for(i=0; i<n;i++){
      j=j+(a[i]-k)*(a[i]-k);
    }
    if(l<=j){
      printf("%d\n", l);
    	return 0;
    }
    l=j;
  }
      
      
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <string>

const int NIL = -1;
struct node
{
  int parent = NIL;
  int left = NIL;
  int right = NIL;
};



using vector = std::vector<int>;
using iterator = vector::iterator;

void populate_tree(vector pre_order, iterator& itr_key, iterator in_begin, iterator in_end, vector& post_order)
{
  if (in_begin >= in_end)
    {
      return;
    }
  auto key= *itr_key;
  auto itr = in_begin;
  while (itr != in_end)
    {
      if (*itr == *itr_key)
        {
          break;
        }
      ++itr;
    }

  ++itr_key;

  populate_tree(pre_order, itr_key, in_begin, itr, post_order);
  populate_tree(pre_order, itr_key, itr+1, in_end, post_order);
  //std::cout << key << " ";
  post_order.push_back(key);

}

auto print_vector = [](iterator begin, iterator end){
                      while(begin != end)
                        {
                          std::cout << *begin;
                          ++begin;
                          if (begin == end) std::cout << std::endl;
                          else std::cout << " ";
                        }
                    };

int main()
{
  int n;
  std::cin >> n;

  vector pre_order, in_order, post_order;
  for(int i=0; i<n; ++i)
    {
      int tmp;
      std::cin >>tmp;
      pre_order.push_back(tmp);
    }
  for(int i=0; i<n; ++i)
    {
      int tmp;
      std::cin >>tmp;
      in_order.push_back(tmp);
    }

  auto itr_key = pre_order.begin();
  populate_tree(pre_order, itr_key, in_order.begin(), in_order.end(), post_order);
  print_vector(post_order.begin(), post_order.end());
}



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

typedef long long ll;
ll n;
vector<ll> a[2]; // a[0], a[1]はそれぞれAを順方向、逆方向に並べたもの
ll ans = 1e18;
ll dp[2][200010][20]; // dp[i][j][k]はa[i]のj番目をk回4倍したときj番目以降を単調増加にするのに必要な4倍する回数
// aとdpは1-indexed

int main(){
//	cin.tie(0);
//	ios::sync_with_stdio(false);
	cin >> n;
	a[0].resize(n+1);
	a[1].resize(n+1);
	for(int i=0; i<n; ++i){
		cin >> a[0][i+1];
		a[1][n-i] = a[0][i+1];
	}
	for(int i=0; i<16; ++i)
		for(int j=0; j<2; ++j)
			dp[j][n][i] = i; // n番目は末尾なのでn番目に対する4倍の回数だけで決まる
	for(int i=n-1; i>=1; --i){
		for(int j=0; j<16; ++j){
			for(int k=0; k<2; ++k){
				ll t = a[k][i];
				ll u = a[k][i+1];
				t <<= 2*j; //i番目の値をj回4倍
				int cnt = 0;
				while(t > u){
					u <<= 2; //i+1番目の値がt以上になるまで4倍
					++cnt;
				}
				if(cnt >= 16) dp[k][i][j] = j + dp[k][i+1][15] + (n - i) * (cnt - 15); // i+1番目を16回以上4倍したとき、15を超える分*(i+1~nまでの個数n-i)を加算
				else dp[k][i][j] = j + dp[k][i+1][cnt];
			}
		}
	}
/*	for(int i=0; i<2; ++i){
		cout << i << "\n";
		for(int j=0; j<n; ++j)
			for(int k=0; k<20; ++k)
				cout << dp[i][j][k] << (k == 19 ? "\n" : " ");
		cout << "\n";
	}
*/	for(int i=0; i<=n; ++i) // 左からi個をマイナスにしたとき
		ans = min(ans, i + 2 * (dp[1][n-i+1][0] + dp[0][i+1][0]));
	cout << ans << "\n";
}

Measured memory_bytes: 65920
a, b = map(int, input().split())
s = {1, 3, 5, 8, 7, 10, 12}
t = {4, 6, 9, 11}
u = {2}
if a in s and b in s:
    print("Yes")
elif a in t and b in t:
    print("Yes")
elif a in u and b in u:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 9128
import sys
input = lambda: sys.stdin.readline().rstrip()

def main():
    a, b, k = map(int, input().split())
    cnt = 0
    for i in range(min(a,b), 0, -1):
        if a%i==0 and b%i==0:
            cnt += 1
        if cnt == k:
            print(i)
            return
        
if __name__ == '__main__':
    main()

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

#define REP(i, n) for(int i=0; i<n;i++)
#define REPR(i, n) for(int i=n-1 ; i>=0; i--)
#define FOR(i, m, n) for(int i=m; i<n; i++)

#define INF 2e9
#define ll long long

int main(){
    int n, m;
    int i, j, k;
    cin>>n>>m;
    int l[m], r[m], ans[n];
    int max, min;
    for(i = 0; i<n; i++){
        ans[i] = 0;
    }
    for(i=0; i<m; i++){
        cin>>l[i]>>r[i];
        //cout<<"l="<<l[i]<<"r="<<r[i];
        if(i==0){
            max = r[i];
            min = l[i];
        }
        else{
            if(min<l[i]){
                min = l[i];
            }
            if(max>r[i]){
                max = r[i];
            }
        }
    }
    if(max-min+1<=0){
        cout<<"0"<<endl;
    }
    else{
        cout<<max-min+1<<endl;
    }
    //cout<<max<<endl<<min<<endl;

    return 0;
}

Measured memory_bytes: 1408
#include <cstdio>
#include <map>
using namespace std;

int main(){
  map<int,long long> data;
  int a, b, n;
  long long k, x = 0;
  scanf("%d %lld", &n, &k);
  for(int i = 0; i < n; i++){
    scanf("%d %d", &a, &b);
    data[a] += b;
  }
  auto itr = data.begin();
  for(; x >= k || k > x + itr->second; itr++){
    x += itr->second;
  }
  printf("%d\n", itr->first);

  return 0;
}


Measured memory_bytes: 4224
#define CIN_ONLY 0
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1000000007;
const double PI = 3.14159265358979323846;

int a[100];
int cnt[100];

int main()
{
	if (CIN_ONLY) {
		ios::sync_with_stdio(0);
		cin.tie(0);
	}
	int n;
	cin >> n;
	int maxd = 0;
	for (int i = 0; i < n; ++i) {
		scanf("%d", &a[i]);
		maxd = max(maxd, a[i]);
		++cnt[a[i]];
	}
	int low = (maxd + 1) / 2;
	int nlow = 1;
	if (maxd % 2) {
		nlow = 2;
	}
	for (int i = 1; i < low; ++i) {
		if (cnt[i]) {
			cout << "Impossible" << endl;
			return 0;
		}
	}
	if (cnt[low] != nlow) {
		cout << "Impossible" << endl;
		return 0;
	}
	for (int i = low + 1; i <= maxd; ++i) {
		if (cnt[i] < 2) {
			cout << "Impossible" << endl;
			return 0;
		}
	}
	cout << "Possible" << endl;
	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <cmath>
using namespace std;
typedef long long unsigned int ll;
 
int main() {
	
  string s;
  string t;
  int a,b,c,d,i,j,k;
  cin >> s;
  
  for(i=0; i < s.length() ; i++){
	if(s[i]=='1') t+='1';
    if(s[i]=='0') t+='0';
    if(s[i]=='B'&&t.length()>=1) t.pop_back();
  }
  
  cout << t <<endl;
  
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <tuple>

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i <= (n); i++)
#define show(a, n) rep(i,n) {cout<<a[i]<<' ';} cout<<endl;

using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef long long ll;
typedef vector<ll> vll;
typedef pair<long long, long long> pll;

const int INF = 1 << 30;
const long long INFL = 1LL << 62;
const int MOD = 1000000007;
const int MAX = 100000;
const int N = 100010;

int bfs(vector<vi>& wx, vector<vi>& wy) {
	int h = wx.size();
	int w = wx[0].size() + 1;
	vector<vi> d(h, vi(w, 0));
	queue<pii> que;
	que.push(pii(0, 0));
	d[0][0] = 1;
	while(!que.empty()) {
		pii p = que.front();
		que.pop();
		int i = p.first, j = p.second;
		if(i < h-1 && wy[i][j] == 0 && d[i+1][j] == 0) {
			d[i+1][j] = d[i][j] + 1;
			que.push(pii(i+1, j));
		}
		if(i > 0 && wy[i-1][j] == 0 && d[i-1][j] == 0) {
			d[i-1][j] = d[i][j] + 1;
			que.push(pii(i-1, j));
		}
		if(j < w-1 && wx[i][j] == 0 && d[i][j+1] == 0) {
			d[i][j+1] = d[i][j] + 1;
			que.push(pii(i, j+1));
		}
		if(j > 0 && wx[i][j-1] == 0 && d[i][j-1] == 0) {
			d[i][j-1] = d[i][j] + 1;
			que.push(pii(i, j-1));
		}
	}
	return d[h-1][w-1];
}

int main() {
//	cout << fixed << setprecision(15);
	vi ans;
	while(true) {
		int w, h;
		cin >> w >> h;
		if(w == 0 && h == 0) break;
		vector<vi> wx(h, vi(w-1)), wy(h-1, vi(w));
		rep(i, 2*h - 1) {
			if(i % 2 == 0) rep(j, w-1) cin >> wx[i/2][j];
			else rep(j, w) cin >> wy[i/2][j];
		}
		ans.push_back(bfs(wx, wy));
	}
	for(auto i : ans) cout << i << endl;
}



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

public class Main
{
	public static void main(String[] ar)throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		PrintWriter out = new PrintWriter(System.out);
		int n = Integer.parseInt(br.readLine());
		String[] s = br.readLine().split(" ");
		int[] a = new int[n];
		for(int i=0;i<n;i++)
			a[i]=Integer.parseInt(s[i]);
		int sum=0,pos=0,f=0;
		for(int i=0;i<n;i++)
			sum+=a[i];
		double avg = ((double)sum)/n;
		double[] b = new double[n];
		for(int i=0;i<n;i++)
			b[i]=Math.abs(a[i]-avg);
		double min=Integer.MAX_VALUE;
		int min_pos=-1;
		for(int i=0;i<n;i++)
		{
			if(b[i]<min)
			{
				min=b[i];
				min_pos=i;
			}
		}
		out.println(min_pos);
		//out.println((int)(Math.ceil((n*2)/k)+Math.ceil((n*5)/k)+Math.ceil((n*8)/k))); 
		out.flush();
		
	}
}



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

typedef pair<int,int> P;

struct S {
  int x, y, d;
  S() {}
  S(int x, int y, int d) : x(x), y(y), d(d) {}
};

const int MAX_H = 11;
const int MAX_W = MAX_H;
const int dx[] = {1,0,-1,0};
const int dy[] = {0,1,0,-1};
map<char,int> conv1;
map<int,char> conv2;
int path[300];

int H, W;
char G[MAX_H][MAX_W];

void make() {
  conv1['R'] = 0;
  conv1['D'] = 1;
  conv1['L'] = 2;
  conv1['U'] = 3;
  conv2[0] = 'R';
  conv2[1] = 'D';
  conv2[2] = 'L';
  conv2[3] = 'U';
}

int canJump(int x, int y, int d) {
  for(int l = 1; ; ++l) {
    int nx = x + l*dx[d];
    int ny = y + l*dy[d];
    if(nx < 0 || nx >= W) return -1;
    if(ny < 0 || ny >= H) return -1;
    if(G[ny][nx] == '.') continue;
    if(G[ny][nx] == 'o') return l;
  }
  return -1;
}

bool rec(int x, int y, int d, int max_step, int step) {
  if(step == max_step) {
/*
    for(int i = 0; i < H; ++i) {
      for(int j = 0; j < W; ++j) cout << G[i][j];
      cout << endl;
    }
*/
    return true;
  }
  for(int k = -1; k <= 1; ++k) {
    int nd = (d+k+4)%4;
    int l = canJump(x,y,nd);
    if(l == -1) continue;
    int nx = x + l*dx[nd];
    int ny = y + l*dy[nd];
    G[y][x] = '.';
    path[step] = nd;
    if(rec(nx,ny,nd,max_step, step+1)) return true;
    G[y][x] = 'o';
  }
  return false;
}

int count() {
  int cnt = 0;
  for(int i = 0; i < H; ++i) {
    for(int j = 0; j < W; ++j) {
      if(G[i][j] == 'o') ++cnt;
    }
  }
  return cnt;
}

void solve(int sx, int sy, int sd) {
  int step = count() - 1;
  rec(sx,sy,sd,step,0);
  for(int i = 0; i < step; ++i)
    cout << conv2[path[i]];
  cout << endl;
}


int main() {
  make();
  while(cin >> H >> W && (H | W)) {
    int sx, sy, sd;
    for(int i = 0; i < H; ++i) {
      for(int j = 0; j < W; ++j) {
        cin >> G[i][j];
        if(G[i][j] != '.' && G[i][j] != 'o') {
          sx = j;
          sy = i;
          sd = conv1[G[i][j]];
          G[i][j] = 'o';
        }
      }
    }
    solve(sx,sy,sd);
  }
  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using ld = long double;
const int INF = (1<<30)-1;
const long long LINF = (1LL<<62)-1;
const long double PI = acos(-1.0L);
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  sort(a.begin(), a.end());
  cout << a.back()-a[0] << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s,s2; cin>>s>>s2;
  int len=s.length();
  int c=0;
  for(int i=0;i<len;i++)
    if(s[i]!=s2[i])
      c++;
  cout<<c;
}


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

using namespace std;


typedef long long ll;

ll M=1e9+7;

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


  ll ans=(m+1)%M; // d=0

  n--;

  if(n){
    ll t=(m/n)%M;
    
    ans=(ans+t*2)%M; // a0=0 d!=0

    ans=(ans+2*t*((m%n)%M)%M)%M;
    
    n%=M;

    ans=(ans+((t-1)*t%M)*(n)%M)%M;

  }

  cout<<ans<<endl;

  return 0;
}

Measured memory_bytes: 3092
import datetime
import string
import re
import math

N=int(input())
input = input()
str = []
for i in range(N):
    str.append(input[i])
str.reverse()

count = 0
begin = 0
end = len(str) - 1
while True:
    if begin < len(str):
        while str[begin] == 'W':
            begin += 1
            if begin == len(str):
                break

    if end >= 0:
        while str[end] == 'R':
            end -= 1
            if end == -1:
                break

    if begin < end:
        str[begin] = 'R'
        str[end] = 'W'
        begin += 1
        end -= 1
        count += 1
    elif begin >= len(str) and end > -1:
        if end != len(str) - 1:
            if str[end + 1] == 'R':
                str[end] = 'W'
                end -= 1
                count += 1
            else:
                end -= 1
        else:
            end -= 1
    elif begin < len(str) and end <= -1:
        if begin != 0:
            if str[begin - 1] == 'W':
                str[begin] = 'R'
                begin += 1
                count += 1
            else:
                begin += 1
        else:
            begin += 1
    else:
        print(count)
        break

Measured memory_bytes: 11780
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <algorithm>
#include <functional>

using namespace std;

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n,x;
    cin >> n >> x;
    
    vector<int> xi(n);
    //cin >> xi[0];

    int i=0;
    while(cin >> xi[i]){
        i++;
    }
    
    sort(xi.begin(),xi.end());
    i=0;
    for(auto a:xi){
        x -= a;
        if(x<0)break;
        i++;
    }
    if(x>0)i--;
    cout << i << endl;
    
    
    return 0;
}

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

#define SCD(t) scanf("%d",&t)
#define SCLD(t) scanf("%ld",&t)
#define SCLLD(t) scanf("%lld",&t)
#define SCC(t) scanf("%c",&t)
#define SCS(t) scanf("%s",t)
#define SCF(t) scanf("%f",&t)
#define SCLF(t) scanf("%lf",&t)
#define MEM(a, b) memset(a, (b), sizeof(a))
#define FOR(i, j, k, in) for (int i=j ; i<k ; i+=in)
#define RFOR(i, j, k, in) for (int i=j ; i>=k ; i-=in)
#define REP(i, j) FOR(i, 0, j, 1)
#define RREP(i, j) RFOR(i, j, 0, 1)
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define IN(A, B, C) assert( B <= A && A <= C)
#define MP make_pair
#define PB push_back
#define INF (int)1e9
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
const double pi=acos(-1.0);
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<pii> vii;
typedef vector<vi> vvi;
typedef map<int,int> mpii;
typedef set<int> seti;
typedef multiset<int> mseti;
typedef long int int32;
typedef unsigned long int uint32;
typedef long long int int64;
typedef unsigned long long int  uint64;

int main(int argc, const char * argv[]) {
    int n;
    SCD(n);
    int v[n][3];
    FOR(i, 0, n, 1)
        FOR(j, 0, 3, 1)
            SCD(v[i][j]);
    FOR(i, 1, n, 1) {
        FOR(j, 0, 3, 1) {
            v[i][j] += max(v[i - 1][(j + 1) % 3], v[i - 1][(j + 2) % 3]);
        }
    }
    
    printf("%d\n", max(max(v[n - 1][0], v[n - 1][1]), v[n - 1][2]));
}


Measured memory_bytes: 1408
tate,yoko=map(int,input().split())
b=[]
for i in range(tate):
  b.append(list(input()))
tatecheck=[]
for i in range(tate):
  flag=1
  for j in range(yoko):
    if b[i][j]=='#':
      flag=0
      break
  if flag==1:
    tatecheck.append(i)
tatecheck.reverse()
for i in tatecheck:
  del b[i]
yokocheck=[]
tate=len(b)
yoko=len(b[0])
for i in range(yoko):
  flag=1
  for j in range(tate):
    if b[j][i]=='#':
      flag=0
      break
  if flag==1:
    yokocheck.append(i)
yokocheck.reverse()
for i in yokocheck:
  for j in range(tate):
    del b[j][i]
tate=len(b)
for i in range(tate):
  print("".join(b[i]))

Measured memory_bytes: 3192
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rep3(i, l, n) for (int i = l; i < n; ++i)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define out(a) cout << a << endl
#define outa(a, n) rep(_, n) cout << a[_] << " "; cout << endl
#define SZ(v) (int)v.size()
#define inf (int)(1e9+7)

int main() {
    int n;
    cin >> n;
    pii a[n];
    rep(i, n) { cin >> a[i].F; a[i].S = i; }
    int b[n];
    rep(i, n) b[i] = a[i].F;
    sort(a, a + n);
    if (a[n / 2 - 1].F == a[n / 2].F) {
        rep(i, n) out(a[n / 2].F);
        return 0;
    }
    rep(i, n) {
        if (b[i] <= a[n / 2 - 1].F) {
            out(a[n / 2].F);
        } else out(a[n / 2 - 1].F);
    }
}


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

int digSum(int n){
  int sum=0;
    while(n>0){
    sum+=(n%10);
    n/=10;
    }
  return sum;
    }

int main(){
  int N, A, B;
  cin>>N>>A>>B;
  int cnt=0;
  int total=0;
  for(int i =1;i<=N;++i){
  int sum=digSum(i);
    if(sum>=A&&sum<=B){
      total+=i;
    }
  }
  cout<<total<<endl;
}


Measured memory_bytes: 3132
#include "bits/stdc++.h"
using namespace std;
const int maxn = 555;
int M(){
    string s;
    if(!(cin >> s)) return 0;
    if(s.size() < 4) printf("No\n");
    else{
        while(s.size() > 4) s.pop_back();
        if(s == "YAKI") printf("Yes\n");
        else printf("No\n");
    }
    return 1;
}
int main(){
    while(M());
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define lper(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ins insert
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};
ll modfac(ll a){
    ll ans=1;
    while(a>1){
        ans*=a;
        ans%=1000000007;
        a--;
    }
    return ans;
}
ll modinv(ll a,ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m; 
    if (u < 0) u += m;
    return u;
}
struct UnionFind {
    vector<int> par;
    
    UnionFind(int n) : par(n, -1) {}

    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }
    
    bool same(int x, int y) {
        return root(x) == root(y);
    }
    
    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y);
        par[x] += par[y];
        par[y] = x;
        return true;
    }
    
    int size(int x) {
        return -par[root(x)];
    }
};
ll modpow(ll a, ll n, ll mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
int main(){
    ll n,a,b;cin >> n >>a >>b;
    ll p=n/(a+b);
    ll d=n%(a+b);
    cout << p*a+min(d,a)<< endl;
}

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

int main() 
{
 ios_base::sync_with_stdio(false);
 cin.tie(nullptr);
 cout.tie(nullptr);
 string a, b;
 cin >> a >> b;
 int n = (int) a.size();
 int m = (int) b.size();
 vector<vector<int>> dp(n+1, vector<int> (m+1));
 for(int i = 1; i <= n; i++) {
  for(int j = 1; j <= m; j++) {
   if(a[i-1] == b[j-1]) dp[i][j] = max(dp[i-1][j-1] + 1, max(dp[i-1][j], dp[i][j-1]));
   else dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
  }
 }
 //cout << dp[n][m] << '\n';
 int i = n, j = m;
 string ans = "";
 while(i > 0 && j > 0) {
  if(a[i-1] == b[j-1]) {
   ans += a[i-1];
   i--, j--;
  }
  else {
   if(dp[i-1][j] > dp[i][j-1]) i--;
   else j--;
  }
 }
 reverse(ans.begin(), ans.end());
 cout << ans << '\n';
 return 0;
}


Measured memory_bytes: 38508
k,n = map(int,input().split())
l = list(map(int,input().split()))
lis = [0]
for i in range(n-1):
    a = l[i+1]-l[i]
    if a > lis[0]:
        lis[0] = a
distance = k - l[n-1] + l[0]
if distance > lis[0]:
    print(k-distance)
else:
    print(k-lis[0])

Measured memory_bytes: 26436
import numpy as np
N = int(input())
A = np.array(list(map(int, input().split())))
B = np.array(list(map(int, input().split())))
C = np.array(list(map(int, input().split())))

tmp = A[1:]

tmp = np.append(tmp, -1)

add = A[np.where((tmp-A)==1)]

ans = B.sum() + C[add-1].sum()
print(ans)

Measured memory_bytes: 12492
#include <bits/stdc++.h>
using namespace std;
 
#define MOD 1000000007
#define INF 2000000000
#define MAX 100001
//#define int ll
#define ll long long
#define ld long double
#define vi vector<int>
#define pa pair<int, int>
#define pb push_back
#define mp make_pair
 
#define INIT ios::sync_with_stdio(false);cin.tie(0);
#define VAR(type, ...)type __VA_ARGS__;MACRO_VAR_Scan(__VA_ARGS__);
template<typename T> void MACRO_VAR_Scan(T& t) { cin >> t; }
template<typename First, typename...Rest>void MACRO_VAR_Scan(First& first, Rest&...rest) { cin >> first; MACRO_VAR_Scan(rest...); }
#define VEC(type, c, n) vector<type> c(n);for(auto& i:c)cin>>i;
#define MAT(type, c, m, n) vector<vector<type>> c(m, vector<type>(n));for(auto& r:c)for(auto& i:r)cin>>i;
 
#define BR cout << "\n";
#define SP cout << " ";
#define ENDL cout<<endl;
#define OUT(d) cout<<(d);
#define OUTL(d) cout<<(d)<<endl;
#define YES OUTL("YES")
#define Yes OUTL("Yes")
#define NO OUTL("NO")
#define No OUTL("No")
#define RET return 0;
 
#define REP(i, n) for(int i=0;i<(n);i++)
#define RREP(i, n) for(int i=n-1;i>=0;--i)
#define FOR(i, m, n) for(int i = m;i < n; i++)
#define RFOR(i, a, b) for(int i=(a)-1;i>=(b);--i)
#define AREP(a, n) for(auto (a):(n))
#define ALL(a) (a).begin(),(a).end()
#define IN(n, a, b) ((a)<=(n)&&(n)<(b))

signed main(){ INIT;
    VAR(int, n, a, b);
    VAR(string, s);
    int passA = 0, passB = 0;

    REP(i, n){
        if(s[i] == 'a' && passA + passB < a + b){
            Yes;
            passA++;
        }else if(s[i] == 'b' && passA + passB < a + b && passB < b){
            Yes;
            passB++;
        }else{
            No;
        }
    }
RET;}


Measured memory_bytes: 848
h, w, k = map(int, input().split())
s = [input() for _ in range(h)]

ans = [[0 for _ in range(w)] for _ in range(h)]

num = 0
f = False
for i, j in enumerate(s):
    tmp = j.find("#")
    if tmp == -1:
        if f:
            ans[i] = ans[i - 1]
        continue
    else:
        num += 1
        for k in range(tmp + 1):
            ans[i][k] = num
        for l in range(tmp + 1, w):
            if j[l] == ".":
                ans[i][l] = num
            else:
                num += 1
            ans[i][l] = num
        if f == False:
            f = True
            for x in range(i):
                ans[x] = ans[i]

for i in ans:
    print(*i)

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

using namespace std;

const int maxn=3000;
typedef long long ll;

ll dp[maxn][maxn][2];
ll l[maxn];

int main(){
	int n;
	scanf("%d", &n);
	bool p=(n+1)%2;
	for(int i=0; i<n; i++){
		scanf("%lld", &l[i]);
		dp[i][i][p]=l[i];
	}
	for(int j=1; j<n; j++){
		p^=1;
		for(int i=0; i+j<n; i++){
			dp[i][i+j][p^1]=min(dp[i+1][i+j][p^1], dp[i][i+j-1][p^1]);
			dp[i][i+j][p]=max(dp[i+1][i+j][p]+l[i], dp[i][i+j-1][p]+l[i+j]);
		}
	}
	printf("%lld\n", dp[0][n-1][0]-dp[0][n-1][1]);
	return 0;
}

Measured memory_bytes: 139520
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String {
            bytes
                .by_ref()
                .map(|r| r.unwrap() as char)
                .skip_while(|c| c.is_whitespace())
                .take_while(|c| !c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_imports)]
use std::cmp::{min, max};

fn main() {
    input!{
        h: usize,
        w: usize,
        v: [chars; h]
    }
    if v.iter().map(|l| l.iter().filter(|&&x| x == '#').count()).sum::<usize>() == h + w - 1 {
        println!("Possible");
    } else {
        println!("Impossible");
    }
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

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

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

    map<ll,ll> mp;

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

    ll ans = 0;
    for (auto p : mp){
        if (p.first <= p.second){
            ans += (p.second - p.first);
        }
        else{
            ans += p.second;
        }
    }

    cout << ans << endl;
    
}

Measured memory_bytes: 9896
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#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,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n; cin >> n;
  vector<ll> L(n+1);
  L[0] = 2, L[1] = 1;
  for(int i=2; i<=n; i++) L[i] = L[i-1] + L[i-2];
  cout << L[n] << "\n";
  return 0;
}


Measured memory_bytes: 3656