akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= (n); i++)
#define repi(i, a, b) for (int i = (a); i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define bit(b) (1ull << (b))

using namespace std;
using i32 = int;
using u32 = unsigned int;
using i64 = long long;
using u64 = unsigned long long;
using f64 = double;
using f80 = long double;
using pii = pair<i32, i32>;
using vi32 = vector<i32>;
using vu32 = vector<u32>;
using vi64 = vector<i64>;
using vu64 = vector<u64>;
using vf64 = vector<f64>;
using vf80 = vector<f80>;
using vstr = vector<string>;
using vpii = vector<pii>;
using vvi32 = vector<vi32>;
using vvu32 = vector<vu32>;
using vvi64 = vector<vi64>;
using vvu64 = vector<vu64>;
using vvf64 = vector<vf64>;
using vvf80 = vector<vf80>;

template<typename T, typename S> bool amax(T &x, S y) { if (x < y) { x = y; return 1; } return 0; }
template<typename T, typename S> bool amin(T &x, S y) { if (y < x) { x = y; return 1; } return 0; }

template<int mod> class modint {
public:
  int x;
  modint(): x(0) {}
  modint(int a) { x = a % mod; if (x < 0) x += mod; }
  modint &operator+=(modint that) { x = (x + that.x) % mod; return *this; }
  modint &operator-=(modint that) { x = (x + mod - that.x) % mod; return *this; }
  modint &operator*=(modint that) { x = (long long) x * that.x % mod; return *this; }
  modint &operator/=(modint that) { return *this *= that.inverse(); }
  modint operator-() { return modint(-this->x); }
  friend ostream& operator<<(ostream &out, modint m) { return out << m.x; }
  modint inverse() {
    int a = x, b = mod, u = 1, v = 0;
    while (b) { int t = a / b; a -= t * b; u -= t * v; swap(a, b); swap(u, v); }
    return modint(u);
  }
#define op(o, p) modint operator o(modint that) { return modint(*this) p that; }
  op(+, +=) op(-, -=) op(*, *=) op(/, /=)
#undef op
#define op(o) bool operator o(modint that) const { return x o that.x; }
  op(==) op(!=) op(<) op(<=) op(>) op(>=)
#undef op
};

using mint = modint<1000000007>;

mint dp[110][10];

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(16);
  cerr << fixed << setprecision(16);
  int h, w, k;
  cin >> h >> w >> k;
  if (w == 1) {
    cout << 1 << endl;
    return 0;
  }
  dp[0][0] = 1;
  rep(i, h) rep(j, bit(w - 1)) {
    if (j & (j >> 1)) {
      continue;
    }
    rep(l, w) {
      if (j & bit(l)) {
        dp[i + 1][l + 1] += dp[i][l];
        dp[i + 1][l] += dp[i][l + 1];
        l++;
      } else {
        dp[i + 1][l] += dp[i][l];
      }
    }
  }
  cout << dp[h][k - 1] << endl;
  return 0;
}


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

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

    int n, k;
    cin >> n >> k;

    cout << (n % k ? 1 : 0) << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
 
using namespace std;
 
int main() {
    int i,j;
    int r,c;
    int buf;
    
    
        cin >> r >> c;
    
    //STL?????蔵?????????????????則????????則????????????????????其 //????????即???
    //vector< vector<int> > my_table[r][c];
    
    //????????即???(??則??????+1??????)
    int **t = new int* [r+1];
    for(i=0;i<r+1;i++) t[i] = new int [c+1];
    
    //????????????
    for(i=0;i<r;i++){
        for(j=0;j<c;j++){
            cin >> t[i][j];            
        }
    }
    
    for(i=0;i<r;i++){
        t[i][c]=0;
        for(j=0;j<c;j++){
            t[i][c]+=t[i][j];          
        }
    }
    for(i=0;i<=c;i++){
        t[r][i]=0;
        for(j=0;j<r;j++){
            t[r][i]+=t[j][i];            
        }
    }
    
    
    
    
    for(i=0;i<=r;i++){
        for(j=0;j<=c;j++){
            cout << t[i][j];   
            if(j!=c) cout << " ";
        }
        cout << endl;
    }
    
        return 0;
}

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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REP1(i,n) for(int i=1, i##_len=(n); i<i##_len; ++i)
#define ll long long
static const int MAX = 10000;
static const ll INFTY = 1e12;

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; }

const ll MRINF = 5000000000000000;

int main() {

  ll N;
  cin >> N;
  vector<ll> A(N);
  REP(i, N)cin >> A[i];
  ll money = 1000;
  ll downflag = 0;
  ll upflag = 1;
  ll kabu = 0;

  for(int i = 1; i < N; i++){
    if(A[i-1] < A[i]){
      if(upflag==1){
        kabu = money / A[i-1];
        money = money % A[i-1];
      }
      downflag = 1;
      upflag = 0;
    }else if(A[i-1] > A[i]){
      if(downflag==1){
        money += kabu * A[i-1];
        kabu = 0;
      }
      downflag = 0;
      upflag = 1;
    }

    // cout << money << " " << kabu << endl;
    
  }

  if(A[N-1] >= A[N-2]){
    money += kabu * A[N-1];
  }

  cout << money << endl;




}
/*
                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . __
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
         pass System Test!
*/

Measured memory_bytes: 3628
import java.util.*;
public class Main {
	public static void main(String[] args)  {
		Scanner scan = new Scanner(System.in);
		int n = Integer.parseInt(scan.next());
		int m = Integer.parseInt(scan.next());
		int[][] py = new int[m][3];
		int[] count = new int[n];
		for (int i = 0;i < m; ++i){
			py[i][0] = Integer.parseInt(scan.next());
			py[i][1] = Integer.parseInt(scan.next());
			py[i][2] = i;
		}

		Arrays.sort(py,(x,y)->Integer.compare(x[1], y[1]));
		String[] ans = new String[m];
		for (int i = 0;i < m; ++i){
			ans[py[i][2]] =  String.format("%06d%06d", py[i][0], ++count[py[i][0]-1]);
		}

		for (int i =0;i < m; ++i){
			System.out.println(ans[i]);
		}

	}

}


//end

Measured memory_bytes: 110192
#include <bits/stdc++.h>
using namespace std;
const int N = 2005;
char s[N][N];
int up[N][N][2][2], a[N][N], b[N], las[N], L[N], R[N];
int solve(int n) {
	vector<int> q;
	q.push_back(0);
	b[0] = b[n + 1] = 0;
	for (int i = 1; i <= n; ++ i) {
		while (b[q.back()] >= b[i]) q.pop_back();
		L[i] = q.back();
		q.push_back(i);
	}
	q.clear();
	q.push_back(n + 1);
	for (int i = n; i >= 1; -- i) {
		while (b[q.back()] >= b[i]) q.pop_back();
		R[i] = q.back();
		q.push_back(i);
	}
	int ans = 0;
	for (int i = 1; i <= n; ++ i) ans = max(ans, b[i] * (R[i] - L[i]));
	return ans;
}
int main() {
	int n, m;
	scanf("%d%d", &n, &m);
	for (int i = 1; i <= n; ++ i) {
		scanf("%s", s[i] + 1);
		for (int j = 1; j <= m; ++ j) a[i][j] = s[i][j] == '#';
	}
	for (int i = 1; i <= n; ++ i) {
		for (int j = 2; j <= m; ++ j) {
			for (int x = 0; x < 2; ++ x) {
				for (int y = 0; y < 2; ++ y) {
					up[i][j][x][y] = (a[i][j] ^ x) != (a[i][j - 1] ^ y) ? 0 : up[i - 1][j][x][y] + 1;
				}
			}
		}
	}
	int ans = n;
	for (int i = 1; i <= n; ++ i) {
		for (int j = 2; j <= m; ++ j) {
			b[j - 1] = up[i - 1][j][a[i][j]][a[i][j - 1]] + 1;
		}
		ans = max(ans, solve(m - 1));
	}
	printf("%d\n", ans);
}



Measured memory_bytes: 82688
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=100005;
ll sum,n,a[N],b[N];
int main()
{ios_base::sync_with_stdio(0);
    cin>>n;
    for(int i=1;i<=n+1;i++)cin>>a[i];
    for(int i=1;i<=n;i++)cin>>b[i];
    for(int i=n+1;i>=0;i--){
        ll val=min(b[i],a[i]);
        b[i]-=val;a[i]-=val;
        sum+=val;
        val=min(b[i-1],a[i]);
        b[i-1]-=val;a[i]-=val;
        sum+=val;
    }
    cout<<sum<<'\n';
    return 0;
}


Measured memory_bytes: 1792
x,y,z,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
a.sort(reverse=True)
b.sort(reverse=True)
c.sort(reverse=True)
res = []
for i in range(x):
    for j in range(y):
        if (i+1) * (j+1) > k:
            break
        for l in range(z):
            if (i+1) * (j+1) * (l+1) > k:
                break
            res.append(a[i]+b[j]+c[l])
res.sort(reverse=True)
for i in range(k):
    print(res[i])



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

/**
 * vector<int>ar(3);
 * for(auto&e:ar){
 *     scanf("%d",&e);
 * }
 * sort(ar.begin(),ar.end())
 * int sum=accumulate(ar.begin(),ar.end(),0);
 ***/

int main(){
    double pai=3.141592653589;
    vector<int> v(3);
    for (auto&e:v) {
        scanf("%d",&e);
    }
    sort(v.begin(),v.end());
    printf("%d %d %d\n",v[0],v[1],v[2]);
    return 0;
}

Measured memory_bytes: 3216
#include <iostream>
#include <random>
#include <chrono>
#include <algorithm>
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
using namespace std;
typedef long long ll;
const ll MOD = (ll)1e9 + 7;
const int N = 2e5+5, inf = 1e9+5;
ll add(ll x, ll y) { x += y; if (x >= MOD) return x - MOD; return x; }
ll sub(ll x, ll y) { x -= y; if (x < 0) return x + MOD; return x; }
ll mult(ll x, ll y) { return (x * y) % MOD; }
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

ll st[N*4];
ll get(int node, int ql, int qr, int l, int r) {
    if (r < ql || qr < l) return 0;
    if (ql <= l && r <= qr) return st[node];
    else {
        ll max1 = get(node*2, ql, qr, l, (l+r)/2);
        ll max2 = get(node*2+1, ql, qr, (l+r)/2+1, r);
        return max(max1, max2);
    }
}

void update(int node, int ql, int qr, int l, int r, ll x) {
    if (r < ql || qr < l) return;
    if (l == r) st[node] = x;
    else {
        update(node*2, ql, qr, l, (l+r)/2, x);
        update(node*2+1, ql, qr, (l+r)/2+1, r, x);
        st[node] = max(st[node*2], st[node*2+1]);
    }
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    int n; cin >> n;
    vector<int> h(n), a(n);
    rep (i, 0, n) cin >> h[i];
    rep (i, 0, n) cin >> a[i];

    ll maxx = 0;
    for (int i = 0; i < n; ++i) {
        ll curr = get(1, 0, h[i]-1, 0, N) + a[i];
        maxx = max(maxx, curr);
        update(1, h[i], h[i], 0, N, curr);
    }
    cout << maxx << endl;
    return 0;
}

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

using namespace std;

int main() {
  int t, n, k, x[1000000+10], s[1000000+10], ans = 0;
  cin >> t;
  for(int i = 0; i < t; i++) {
    cin >> n >> k;
    for(int j = 0; j < n; j++) cin >> x[j];
    for(int j = 0; j < n-1; j++) s[j] = x[j+1]-x[j];
    if(n > 1) {
      sort(&s[0], &s[n-1]);
      for(int j = 0; j < max(0, n-1-(k-1)); j++) ans += s[j];
    }
    cout << ans << endl;
    ans = 0;
  }
  return 0;
}
  
      

Measured memory_bytes: 3760
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>

using namespace std;

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define REPO(i, n) for(int i = 1;i <= n;i++)
#define ll long long
#define INF 1999999999
#define MINF -1999999999
#define INF64 1999999999999999999
#define ALL(n) n.begin(),n.end()
#define ABS(a,b) max(a,b) - min(a,b)

queue<ll> s;
ll n,ans = 0;

void dfs(ll a) {
	if (a < 1000000000) {
		s.push(a);
		dfs(a * 10 + 3);
		dfs(a * 10 + 5);
		dfs(a * 10 + 7);
	}
}
int main() {
	cin >> n;
	dfs(3);
	dfs(5);
	dfs(7);
	REP(i, INF) {
		if (s.empty()) break;
		string a = to_string(s.front());
		if (a.find('3') != string::npos and a.find('5') != string::npos and a.find('7') != string::npos and s.front() <= n) ans++;
		s.pop();
	}
	cout << ans << endl;
}	


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

#define FOR(i, a, b) for(long long int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for(long long int i=(a);i>=(b);i--)
#define MOD 1000000007
#define INF 1000000000 //2000000000
#define LLINF 1000000000000000000 //9000000000000000000
#define PI 3.14159265358979

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

int main(void) {
	
	while (1) {
		bool flag = true;
		int n, m;
		int post = -1;
		int posh = -1;
		int mini = INF;
		int sa = 0;
		int tasu = 0;
		int hasu = 0;
		int taro[101] = {};
		int hana[101] = {};

		cin >> n >> m;
		if (n == 0 && m == 0) {
			break;
		}
		FOR(i, 1, n) {
			cin >> taro[i];
			tasu += taro[i];
		}
		FOR(i, 1, m) {
			cin >> hana[i];
			hasu += hana[i];
		}
		sa = tasu - hasu;
		if (sa % 2 == 1||sa%2==-1) {
			flag = false;
		}
		FOR(i, 1, n) {
			FOR(t, 1, m) {
				if (sa / 2 == taro[i] - hana[t]) {
					if (mini > taro[i] + hana[t]) {
						mini = taro[i] + hana[t];
						post = i;
						posh = t;
					}
				}
			}
		}
		if (post == -1) {
			flag = false;
		}
		if (flag) {
			cout << taro[post] << " " << hana[posh] << endl;
		}
		else {
			cout << -1 << endl;
		}
	}

}


Measured memory_bytes: 2980
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#include <map>
typedef long long ll;
#define REP(i, n) for(ll i = 0; i < n; i++)
#define REPR(i, n) for(ll i = n; i >= 0; i--)
#define FOR(i, m, n) for(ll i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using Graph = vector<vector<int>>;


template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
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;
    cout << u << endl;
    return u;
}

 
int main() {
    ll n,k;
    cin >> n >> k;
    vector<ll> a(n);
    REP(i, n){
        cin >> a[i];
    }
    ll point = 1;
    FOR(i, k+1,n+1){
        string ans = "No";
        if(a[i-k-1] < a[i-1]){
            ans = "Yes";
        }
        cout << ans << endl;
    }
}



Measured memory_bytes: 4840
n = int(input())
a = list(map(int, input().split()))

ans = 0

for i in range(1,n-1):
  if a[i-1] < a[i] and a[i] < a[i+1] or a[i-1] > a[i] and a[i] > a[i+1]:
    ans += 1

print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)     for(int i = 0; i < (int)(n); i++)
#define rep2(i, m, n) for(int i = m; i < (int)(n); i++)
#define MOD 1000000007
#define Graph vector<vector<int>>

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

  bool ans = false;

  if(S.at(0) == S.at(1)){
    if((S.at(2) == S.at(3)) && (S.at(0) != S.at(2))) ans = true;
  }else if(S.at(0) == S.at(2)){
    if((S.at(1) == S.at(3)) && (S.at(0) != S.at(1))) ans = true;
  }else if(S.at(0) == S.at(3)) {
    if((S.at(1) == S.at(2)) && (S.at(0) != S.at(1))) ans = true;
  }

  if(ans){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define vll vector<ll>
#define vvll vector<vll>
#define mll map<ll,ll>
#define f(i,m,n) for(i=m;i<n;i++)
#define ee endl
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define take(v,n) for(i=0;i<n;i++) cin>>v[i];
#define NO() cout<<"NO"<<endl
#define YES() cout<<"YES"<<endl
#define fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define sot(v) sort(v.begin(),v.end());
bool isPrime(int n) 
{ 
    // Corner cases 
    if (n <= 1)  return false; 
    if (n <= 3)  return true; 
  
    // This is checked so that we can skip  
    // middle five numbers in below loop 
    if (n%2 == 0 || n%3 == 0) return false; 
  
    for (int i=5; i*i<=n; i=i+6) 
        if (n%i == 0 || n%(i+2) == 0) 
           return false; 
  
    return true; 
}

void solve()
{
    ll i,j,k,l,n;
    cin>>n;
    vll v(n);
    take(v,n);
    sot(v);
    ll ans=0;
    if(n<=2)
    {
        cout<<0<<ee;
        return;
    }
    for(i=0;i<n-1;i++)
    {
        for(j=i+1;j<n-1;j++)
        {
            if(v[i]==v[j])
                continue;
            for(k=j+1;k<n;k++)
            {
                if(v[j]!=v[k] && v[j]!=v[k])
                {
                    if(v[i]+v[j]>v[k])
                        ans++;
                }
            }
        }
    }
    cout<<ans<<ee;
}


int main() {
    fast;
    ll i,j,l,k,t,n;
    t=1;
    while(t--)
    solve();
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#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 FORR(i, m, n) for(int i = m;i >= n;i--)
#define INF 999999

ll min(ll a, ll b){
	if (a<b) return a;
	else return b;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	vector<ll> a(5);
	REP(i, 5){cin >> a[i];}
	ll ans = 0;
	REP(i, 5){
		ans += 10 *((a[i]-1)/10 + 1);
	}
	ll temp = 10;
	REP(i, 5){
		if (a[i]%10 == 0){continue;}
		temp = min(temp, a[i]%10);
	}
	cout << ans-10+temp << endl;
}

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

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

int main(void) {
  int N;
  cin >> N;
  
  int min = 100000;
  
  for (int a = 1; a < N; ++a) {
    int b = N - a;
    int sum = getSum(a) + getSum(b);
    if (sum < min) min = sum;
  }
  
  cout << min << endl;
  
  return 0;
}

Measured memory_bytes: 256
fn main() {
	let mut s = String::new();
	std::io::stdin().read_line(&mut s).unwrap();
	let s: Vec<_> = s.trim().chars().collect();
	let ac =
		s[0] == 'A' &&
		s[2..s.len() - 1].iter().fold(0, |r, &c| if c == 'C' { r + 1 } else { r }) == 1 &&
		s.iter().fold(0, |r, &c| if c.is_lowercase() { r + 1 } else { r }) == s.len() - 2;
	println!("{}", if ac { "AC" } else { "WA" });
}


Measured memory_bytes: 4352
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
			Scanner sc = new Scanner(System.in);
			int N = sc.nextInt();
			long sum = 0;
			int min = 1000000;
			int max = -1000000;
			
			for(int i = 0; i < N; i++) {
				int number = sc.nextInt();
					if(min > number) {
						min = number;
					}
					if(max < number) {
						max = number;
					}
				sum += number;
			}

			System.out.printf("%d ",min);
			System.out.printf("%d ",max);
			System.out.printf("%d\n",sum);
	}

}



Measured memory_bytes: 41740
def s0():return input()
def s1():return input().split()
def s2(n):return [input() for x in range(n)]
def s3(n):return [input().split() for _ in range(n)]
def s4(n):return [[x for x in s] for s in s2(n)]
def n0():return int(input())
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(input()) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]
def t3(n):return [tuple(int(x) for x in input().split()) for _ in range(n)]
def p0(b,yes="Yes",no="No"): print(yes if b else no)
# from sys import setrecursionlimit
# setrecursionlimit(1000000)
# from collections import Counter,deque,defaultdict
# import itertools
# import math
# import networkx as nx
# from bisect import bisect_left,bisect_right
# from heapq import heapify,heappush,heappop
n,m=n1()
LR=n3(m)

m=0
M=10**10
for l,r in LR:
    m=max(m,l)
    M=min(M,r)
ans=M-m

p0(M>=m,M-m+1,0)

Measured memory_bytes: 21168
#青の人の解答（hir35）

from collections import Counter
n = int(input())
a = list(map(int, input().split()))

#それぞれの数字が何回ずつ出現したかをカウント
c = Counter(a)

#リストpに10＾6+1個のTrueを格納
p = [True] * (10 ** 6 + 1)

#list(set())で重複したものを取り除いてからリストにできる
s = list(set(a))

#sの要素一つ一つを見ていく
for x in s:
    t = x * 2
    #tが10^6以下ならば，p[t]にFalseを代入
    #つまり，x(aに格納されている数)の倍数がfalseに
    while t <= 10 ** 6:
        p[t] = False
        t += x
ans = 0

for x in a:
    #もしその数が一つしかなくて，倍数がないならans+1
    if c[x] == 1 and p[x] == True:
        ans += 1
print(ans)

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

using ll = long long;
using vint = vector<int>;
using vvint = vector<vint>;
using pint = pair<int, int>;
using vpint = vector<pint>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;
#define repi(n) for (int i = 0; i < n; i++)
#define repj(n) for (int j = 0; j < n; j++)
#define repk(n) for (int k = 0; j < n; k++)
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, a, b) for (int i = a; i < b; i++)
#define repv(itr) for (auto&& v : itr)
#define swap(x, y)    \
  {                   \
    auto ___temp = x; \
    x = y;            \
    y = ___temp;      \
  }

const int dx[] = {-1, 0, 0, 1, -1, -1, 1, 1};
const int dy[] = {0, -1, 1, 0, -1, 1, -1, 1};
template <typename T>
T minptr(T begin, T end) {
  T re = begin;
  for (T i = begin + 1; i != end; i++) {
    if (*i < *re) re = i;
  }
  return re;
}
template <typename T>
T maxptr(T begin, T end) {
  T re = begin;
  for (T i = begin + 1; i != end; i++) {
    if (*i > *re) re = i;
  }
  return re;
}
int __vmax(int x) {
  return INT_MAX;
}
double __vmax(double x) {
  return 1e+300;
}
ll __vmax(ll x) {
  return LLONG_MAX;
}
int __vmin(int x) {
  return INT_MIN;
}
double __vmin(double x) {
  return -1e+300;
}
ll __vmin(ll x) {
  return LLONG_MIN;
}
template <typename T>
vector<T> lis(T begin, T end, bool allowequal = false, bool lds = false) {
  using V = typename iterator_traits<T>::value_type;
  int n = end - begin;
  vector<V> a(n, lds ? __vmin(*begin) : __vmax(*begin));
  vector<int> id(n);
  if (lds && allowequal) {
    for (int i = 0; i < n; i++) {
      id[i] = n - 1 -
              (lower_bound(a.rbegin(), a.rend(), begin[i]) - 1 - a.rbegin());
      a[id[i]] = begin[i];
    }
  } else if (lds) {
    for (int i = 0; i < n; i++) {
      id[i] = n - 1 -
              (upper_bound(a.rbegin(), a.rend(), begin[i]) - 1 - a.rbegin());
      a[id[i]] = begin[i];
    }
  } else if (allowequal) {
    for (int i = 0; i < n; i++) {
      id[i] = upper_bound(a.begin(), a.end(), begin[i]) - a.begin();
      a[id[i]] = begin[i];
    }
  } else {
    for (int i = 0; i < n; i++) {
      id[i] = lower_bound(a.begin(), a.end(), begin[i]) - a.begin();
      a[id[i]] = begin[i];
    }
  }
  int m = *maxptr(id.begin(), id.end());
  vector<T> re(m + 1);
  for (int i = n - 1; i >= 0; i--) {
    if (id[i] == m) re[m--] = begin + i;
  }
  return re;
}
template <typename T>
T gcd(T a, T b) {
  return b ? gcd(b, a % b) : a;
}

int main() {
  string s;
  cin >> s;
  int result = INT_MIN;
  int n = s.length();
  repi(n) {
    repj(n - i + 1) {
      result = max(result, j);
      char c = i + j >= n ? ' ' : s[i + j];
      if (c != 'A' && c != 'T' && c != 'G' && c != 'C') break;
    }
  }
  cout << result << endl;
}


Measured memory_bytes: 256
import math
n,m = map(int,input().split())
mod = 10**9+7
fact_n = math.factorial(n) % mod
fact_m = math.factorial(m) % mod

if abs(n-m) >= 2:
  print(0)
elif n == m:
  print((fact_n * fact_m * 2) % mod)
else:
  print((fact_n * fact_m) % mod)

Measured memory_bytes: 10112
import math
a,b,x = list(map(int, input().split()))

h = ((x/a)/b)*2
w = b
r = math.sqrt(h*h + w*w)

if h <= a:
    theta = math.atan2(w,h)
    print(math.degrees(theta))
else:
    y = (x/a - a*b/2)*2/a
    theta = math.atan2(b-y,a)
    print(math.degrees(theta))

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

int n;
string s;

int main() {
	int i;
	
	cin >> n >> s;
	for (i = 1; i < n; i++) {
		if (s[i - 1] == 'x' && s[i] == 'x') {
			break;
		}
	}
	cout << i << endl;
	return 0;
}

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

int main() {
    int cnt = 0;
    string s;
    while (cin >> s) {
        int n = s.size();
        bool ok = true;
        for (int i=0; i<n-i; ++i) {
            if (s[i] != s[n-1-i]) {
                ok = false;
                break;
            }
        }
        cnt += ok;
    }
    cout << cnt << endl;
    return 0;
}

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

#define println(msg) cout << msg << endl
#define sort_vec(vec) sort(vec.begin(), vec.end()) 

int main() {
  // 入力
  int N, x;
  cin >> N >> x;

  vector<int> a(N);
  for (int i = 0; i < N; i++) {
    cin >> a.at(i);
  }
  
  // 計算
  sort_vec(a);

  int count = 0;
  for (auto i = a.begin(); i != a.end(); i++) { 
    x -= *i;
    count++;
    
    if (x < 0) {
      count--;
      break;
    }
  }
  
  if (count > 0 && x > 0) {
    count--;
  }

  // 出力
  println(count);
}


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

using namespace std;

#define rep(i,n) for(int i=0;i<(n);i++)
#define repa(i,a,n) for(int i=(a);i<(n);i++)
#define rrep(i,n) for(int i=n;i>=0;i--)
#define rrepa(i,a,n) for(int i=n;i>=(a);i--)
#define all(a) (a).begin(),(a).end()
#define MOD 1000000007
#define cmax(a,b) a=max(a,b)
#define cmin(a,b) a=min(a,b)
#define vc vector

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;

int main(){

    string s,t;
    cin>>s>>t;

    int cnt=0;
    rep(i,s.length()-t.length()+1){
        int tmp=0;
        rep(j,t.length()){
            if(s[i+j]==t[j])tmp++;
        }
        cmax(cnt,tmp);
    }

    cout<<t.length()-cnt<<"\n";

    return 0;

}

Measured memory_bytes: 3624
import java.util.*;
import java.util.Arrays;


public class Main{
  
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String s = sc.next();
    boolean[] c = new boolean[26];
    for(int i=0;i<s.length();i++){
      c[s.charAt(i)-'a'] = true;
    }
    for(int i=0;i<26;i++){
      if(!c[i]){
        System.out.printf("%c\n",('a'+i));
        break;
      }

      else if(i==25){
        System.out.println("None");

      }
    }
    
  }
}
                          
                         
                    
    
    
    
    
    
    


Measured memory_bytes: 24128
#include <iostream>
#include <assert.h>
#include <vector>
#include <unordered_map>
#include <queue>
#include <climits>
#include <cmath>
#include <algorithm>
using namespace std;
constexpr int64_t MOD = 1e9 + 7;

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

  string T;
  cin >> T;
  string R;
  for (int i = 0; i < (int)T.size(); i++) {
    if (T[i] == '?') {
      R += 'D';
    } else {
      R += T[i];
    }
  }
  cout << R << endl;

  return 0;
}



Measured memory_bytes: 3824
#include <cstdio>
#include <cstdlib>
#include <cstring>

struct Node{
	int key;
	Node *next,*prev;
};

Node *nil;

void init(){
	nil = (Node *)malloc(sizeof(Node));
	nil->next = nil;
	nil->prev = nil;
}

void insert(int key){
	Node *x = (Node *)malloc(sizeof(Node));
	x->key = key;
	// 番兵の直後に要素を追加
	x->next = nil->next;
	nil->next->prev = x;
	nil->next = x;
	x->prev = nil;
}

Node* listSearch(int key){
	Node *cur=nil->next; // 番兵の次の要素から辿る
	while(cur!=nil&&cur->key!=key){
		cur=cur->next;
	}
	return cur;
}

void deleteNode(Node *t){
	if(t == nil) return;
	t->prev->next = t->next;
	t->next->prev = t->prev;
	free(t);
}

void deleteFirst(){
	deleteNode(nil->next);
}

void deleteLast(){
	deleteNode(nil->prev);
}

void deleteKey(int key){
	deleteNode(listSearch(key));
}

void printList(){
	Node *cur = nil->next;
	int isf=0;
	while(1){
		if(cur==nil) break;
		if(isf++>0) printf(" ");
		printf("%d",cur->key);
		cur = cur->next;
	}
	printf("\n");
}

int main(){
	int key,n,i;
	int size = 0;
	char com[20];
	int np = 0,nd=0;
	scanf("%d",&n);
	init();
	for(i=0;i<n;i++){
		scanf("%s%d",com,&key);
		if(com[0]=='i'){insert(key); np++; size++;}
		else if(com[0]=='d'){
			if(strlen(com)>6){
				if(com[6]=='F') deleteFirst();
				else if(com[6]=='L') deleteLast();
			}else{
				deleteKey(key); nd++;
			}
			size--;
		}
	}
	
	printList();
	
	return 0;
}



Measured memory_bytes: 33872
#include <bits/stdc++.h>
#define REP(i, s, n) for (int i = s; i < (int)(n); i++)
#define ALL(a) a.begin(), a.end()
#define MOD 1000000007
using namespace std;
using ll = long long;

int main() {
    long double a, b; cin >> a >> b;
    cout << (ll)floor(a * b) << endl;

    return 0;
}

Measured memory_bytes: 3720
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define FOR(i, s, n) for (int i = (s); i < (n); i++)
#define RFOR(i, s, n) for (int i = (n) - 1; i >= (s); i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, 0, n)
#define ALL(a) a.begin(), a.end()
const long long MOD = 1e9+7, INF = 1e18;
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(){
	int a;
	cin>>a;
	string s;
	cin>>s;
	if(a>=3200)cout<<s<<endl;
	else cout<<"red"<<endl;
}


Measured memory_bytes: 764
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func Scan() string {
	sc.Scan()
	return sc.Text()
}
func iScan() int {
	n, _ := strconv.Atoi(Scan())
	return n
}
func fScan() float64 {
	n, _ := strconv.ParseFloat(Scan(), 64)
	return n
}
func stringToInt(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}
func SScan(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = Scan()
	}
	return a
}
func iSScan(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = iScan()
	}
	return a
}
func abs(x int) int {
	if x < 0 {
		x = -x
	}
	return x
}
func larger(a, b int) int {
	if a < b {
		return b
	} else {
		return a
	}
}
func smaller(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}
func max(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x < a[i] {
			x = a[i]
		}
	}
	return x
}
func min(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x > a[i] {
			x = a[i]
		}
	}
	return x
}
func sum(a []int) int {
	x := 0
	for _, v := range a {
		x += v
	}
	return x
}

var mod int = 1000000007

func main() {
	buf := make([]byte, 0)
	sc.Buffer(buf, mod)
	sc.Split(bufio.ScanWords)
	n, k := iScan(), iScan()
	a := iSScan(n)
	for i := k; i < n; i++ {
		if a[i] <= a[i-k] {
			fmt.Println("No")
		} else {
			fmt.Println("Yes")
		}
	}
}


Measured memory_bytes: 5916
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	private static class Dice {
		private String top;
		private String bottom;
		private String front;
		private String back;
		private String left;
		private String right;

		public Dice(
				String top,
				String front,
				String right,
				String left,
				String back,
				String bottom)
		{
			this.top = top;
			this.front = front;
			this.right = right;
			this.left = left;
			this.back = back;
			this.bottom = bottom;
		}

		public String operationE() {
			String tmp = this.top;
			this.top = this.left;
			this.left = this.bottom;
			this.bottom = this.right;
			this.right = tmp;

			return this.top;
		}

		public String operationN() {
			String tmp = this.top;
			this.top = this.front;
			this.front = this.bottom;
			this.bottom = this.back;
			this.back = tmp;

			return this.top;
		}

		public String operationS() {
			String tmp = this.top;
			this.top = this.back;
			this.back = this.bottom;
			this.bottom = this.front;
			this.front = tmp;

			return this.top;
		}

		public String operationW() {
			String tmp = this.top;
			this.top = this.right;
			this.right = this.bottom;
			this.bottom = this.left;
			this.left = tmp;

			return this.top;
		}
	}

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		String[] label = br.readLine().split(" ");
		Dice dice = new Dice(label[0], label[1], label[2], label[3], label[4], label[5]);

		String text = br.readLine();

		String result = label[0];
		for (int i = 0; i < text.length(); i++) {
			if (text.charAt(i) == 'E') {
				result = dice.operationE();
			} else if (text.charAt(i) == 'N') {
				result = dice.operationN();
			} else if (text.charAt(i) == 'S') {
				result = dice.operationS();
			} else if (text.charAt(i) == 'W') {
				result = dice.operationW();
			}
		}
		System.out.println(result);
	}
}

Measured memory_bytes: 23996
import sys
input = sys.stdin.readline

# 1~nまでの逆元(mod m) O(n)
def mod_inv_list(n:int, m:int):
    # inv_t[i]: iの法mの下での逆元
    inv_t = [0] + [1]
    for i in range(2,n):
        inv_t += [inv_t[m % i] * (m - m//i) % m]
    return inv_t

def main():
    N = int(input())
    x = [int(i) for i in input().split()]
    MOD = 10**9 + 7

    inv_acum = mod_inv_list(N,MOD)
    for i in range(1,N):
        inv_acum[i] = (inv_acum[i] + inv_acum[i-1]) % MOD

    ans = 0
    for i in range(1,N):
        ans += (x[i] - x[i-1]) * inv_acum[i]
        ans %= MOD

    for i in range(1,N):
        ans = (ans * i) % MOD

    print(ans)

if __name__ == "__main__":
    main()

Measured memory_bytes: 14296
#include <bits/stdc++.h>
#include <stdio.h>
#include<iostream>
#include<cstdio>
#include<bitset>
#include<algorithm>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<string>
#include<string.h>
#include<cmath>
#include<utility>
#include<functional>
#include<map>
#include<set>
#include<cctype>
#include<fstream>
#include <numeric>
#include <iomanip>
#include <cstring> 
using namespace std;
using ll=long long;

#define FOR(i, a, b) for( int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for( int i=(a);i>=(b);i--)
#define LFOR(i, a, b) for( long long int i=(a);i<=(b);i++)
#define LRFOR(i, a, b) for(long long int i=(a);i>=(b);i--)
#define MOD 1000000007
#define LLONG_MAXs 9223372036854775800

#include <iostream>
#include <cmath>
using namespace std;
 

 
bool isPrimeNum( ll x ){ // 素数である場合 true を返す
  if( x <= 1 ){ // 1以下である場合は素数でないことがすぐにわかる
    return false;
  }
  // sqrt( double型 ) は引数の平方根を double型で返すので、int型でキャスト
  int n = (int)sqrt( (double)x );
  for( int i = 2; i <= n; i++ ){
    if( x % i == 0 ){ // 割り切る整数がある場合、即判定終了
      return false;
    }
  }
  return true; // 割り切る整数がない場合、素数である
}

constexpr ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
constexpr ll lcm(ll a,ll b){return a*b/gcd(a,b);}
constexpr ll abs(ll a,ll b){
if(a>=b)return a-b;
if(a<b)return b-a;
}
constexpr ll min(ll a,ll b){
if(a>=b)return b;
if(a<b)return a;
}

constexpr ll max(ll a,ll b){
if(a>=b)return a;
if(a<b)return b;
}

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

struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

int main() {
  ll ans=0;
  ll N;

  cin>>N;
  ll X[N];
  ll Xorg[N];

  FOR(i,0,N-1){
    cin>>X[i];
    Xorg[i]=X[i];
  }
  sort(X,X+N);
  FOR(i,0,N-1){
    if(Xorg[i]>=X[N/2]){
cout<<X[N/2-1]<<endl;
    }else{
cout<<X[N/2 ] <<endl;
    }
  }

//cout<<ans<<endl;
return 0;

}
 


Measured memory_bytes: 5248
"use strict";
    
const main = arg => {
    arg = arg.trim().split("\n");
    const A = parseInt(arg[0].split(" ")[0]);
    const B = parseInt(arg[0].split(" ")[1]);
    
    let answer = 0;
    
    console.log(Math.ceil((B - 1) / (A - 1)));
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 21064
package main

import(
    "fmt"
)

func main() {
    var a , b , c int
fmt.Scan(&a)
fmt.Scan(&b)
fmt.Scan(&c)
    if a<=b && b<=c {
        fmt.Println(a, b, c)
    } else if a<=c && c<=b {
        fmt.Println(a, c, b)
    } else if b<=a && a<=c {
        fmt.Println(b, a, c)
    } else if b<=c && c<=a {
        fmt.Println(b, c, a)
    } else if c<=a && a<=b {
        fmt.Println(c, a, b)
    } else if c<=b && b<=a {
        fmt.Println(c, b, a)
    }
}



Measured memory_bytes: 1160
import java.time.Instant;
import java.util.*;
import java.util.function.ToLongFunction;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

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

		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int P = sc.nextInt();

		System.out.println((A*3 + P) /2 );



	}

	static class Pair<T1, T2>   {
		int n;
	    T1 a;
	    T2 b;
	    public Pair(int n, T1 a,T2 b) {
	        this.n = n;
	    	this.a = a;
	        this.b = b;
	    }

	    T1 getA(){
	    	return a;
	    }

	    T2 getB(){
	    	return b;
	    }

	}
}




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

using namespace std;
using ll = long long;
using P = pair<int, int>;


int main() {
	ll n, d,e,f;
	int c = 0;
	cin >> n >> d;
	rep(i, n) {
		cin >> e>>f;
		e = abs(e);
		f = abs(f);
		if (e * e + f * f <= d*d) {
			c = c + 1;
		}
	}
	cout << c << endl;
	return 0;
}

Measured memory_bytes: 3632
n, m, l = map(int, input().split())
a = [[int(num) for num in input().split()] for i in range(n)]
b = [[int(num) for num in input().split()] for i in range(m)]
c = [[0 for i in range(l)] for j in range(n)]
for i in range(l):
    for j in range(n):
        for k in range(m):
            c[j][i] += a[j][k] * b[k][i]

for i in range(n):
    for j in range(l):
        if j == l - 1:
            print(c[i][j])
        else:
            print("{0} ".format(c[i][j]), end = "")

Measured memory_bytes: 9080
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=sys.stdin.readline
def resolve():
    N=int(input())
    dp=[[[[0]*4 for _ in range(4)] for _ in range(4)] for _ in range(N+1)]
    # initialize(n=3)
    NG={(0,1,2),(1,0,2),(0,2,1)}
    from itertools import product
    for i,j,k in product(range(4),repeat=3):
        if (i,j,k) in NG: continue
        dp[3][i][j][k]=1
    # iterate
    for n in range(4,N+1):
        for i,j,k,l in product(range(4),repeat=4):
            if dp[n-1][i][j][k]==0: continue
            if (j,k,l) in NG: continue
            if (i,j,l)==(0,1,2): continue
            if (i,k,l)==(0,1,2): continue
            dp[n][j][k][l]+=dp[n-1][i][j][k]
    # calculate
    ans=0
    for i,j,k in product(range(4),repeat=3):
        ans+=dp[N][i][j][k]
    print(ans%MOD)

resolve()

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

int main(){
  int r,g,b, A =0;
  cin >> r >> g >> b;
  A = r*100 + g*10 + b;
  if(A%4 ==0) cout<< "YES" << endl;
  else cout<< "NO" << endl;
  
 
}

Measured memory_bytes: 3644
def f(y,x,a):
  M.append([y,x])
  while M:
    y,x=M.pop()
    if A[y][x]==a:
      A[y][x]=' '
      for i,j in [[0,-1],[-1,0],[0,1],[1,0]]: M.append([y+i,x+j])
  return 1

M=[]
while 1:
  H,W=map(int,raw_input().split())
  if H==W==0: break
  A=[list(' '*(W+2)) for _ in range(H+2)]
  for i in range(H): A[i+1][1:W+1]=list(raw_input())
  c=0
  for i in range(1,H+1):
    for j in range(1,W+1):
      a=A[i][j]
      if a!=' ': c+=f(i,j,a)
  print c

Measured memory_bytes: 6608
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mp make_pair
#define pb push_back
#define x first
#define y second
#define pii pair<int, int>
#define p3i pair<pii, int>
#define pll pair<ll, ll>
#define p3l pair<pll, ll>
#define lseg L, (L+R)/2, N*2+1
#define rseg (L+R)/2+1, R, N*2+2
#define ub upper_bound
#define lb lower_bound
#define p_q priority_queue
#define MN 1000000009

int n, q;
char a, b;
map<char, char> m;
int main(){
    while(cin >> n)
    {
        m.clear();
        if (n==0) break;
        for (int l=0; l<n; ++l){
            cin >> a >> b;
            m[a]=b;
        }
        cin >> q;
        for (int l=0; l<q; ++l){
            cin >> a;
            if (m.count(a)==0) cout << a;
            else cout << m[a];
        }
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 3076
import java.util.*;


public class Main {
    public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String line = sc.nextLine();
		if ("AAA".equals(line) || "BBB".equals(line)) {
		    System.out.println("No");
		} else {
		    System.out.println("Yes");
		}
		
    }
}


Measured memory_bytes: 35528
import scala.io.Source.stdin

object Main extends App {
  def decode(s:String) = {
    def scan(t:String,i:Int):String = {
      if(i >= s.length) t
      else {
        if(s(i) == '@') scan(t + (s(i+2).toString * s(i+1).asDigit),i+3)
        else scan(t + s(i),i+1)
      }
    }
    scan("",0)
  }

  stdin.getLines.foreach { s=> println(decode(s)) }
}

Measured memory_bytes: 43892
#include <bits/stdc++.h>
using namespace std;
#define maxn 200005
#define inf 1e17
#define eps 1e-6
#define ll long long
#define ull unsigned long long
#define main() int main()
#define pii pair<int, ll>
#define pb push_back
#define mp make_pair
#define fir first
#define sec second
#define sa(x) scanf("%d",&x)
#define sab(x,y) scanf("%d%d",&x,&y)
#define pa(x) printf("%d",&x)
#define pab(x,y) printf("%d%d",x,y) 
#define ms(a,x) memset(a,x,sizeof(a))
#define IO ios::sync_with_stdio(0);cin.tie(0)
#define endl '\n'
#define ff0(i,n) for(int i=0;i<n;++i)
#define ff1(i,n) for(int i=1;i<=n;++i)
main()
{
    int a[3];
    ff0(i,3)cin>>a[i];
    sort(a,a+3);
    if((a[0]==a[1]&&a[0]!=a[2])||(a[0]!=a[1]&&a[1]==a[2])){
    	cout<<"Yes"<<endl;
	}
	else
	cout<<"No"<<endl;
}

Measured memory_bytes: 764
S = input()
ans = True

i = 0
while i < len(S):
    if i % 2 == 0 and S[i]=="L":
        ans = False
    elif i % 2 == 1 and S[i]=="R":
        ans = False
    else:
        t = 1
    i += 1
   
if ans:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3060
#include "bits/stdc++.h"
using namespace std;

#define show(x) cerr << #x << " = " << x << endl ;
#define input_from_file freopen("input.txt","r",stdin)
#define output_to_file freopen("output.txt" , "w",stdout)
#define fastio ios_base::sync_with_stdio(0)
#define endl '\n'

const int N = 1e5+1 , mod = 1e9+7;
vector < int > adj[N];	
int dp[N][2];
bitset < N > vis;
long long ans = 0;
void dfs(int v , int pv)
{
	for(int i : adj[v])
	{
		if(i == pv) continue;
		dfs(i , v);
		dp[v][0] = (1LL*dp[v][0] * dp[i][1])%mod;
		dp[v][1] = (1LL*dp[v][1]*(dp[i][0] + dp[i][1]))%mod;
	}
	return;
}
int main()
{
	 #ifdef LOCAL
        input_from_file;
        output_to_file;
    #endif
	fastio;cin.tie(0);cout.tie(0);
	int n, x, y; cin >> n ;
	for(int i = 1 ; i < n ; ++i)
	{
		cin >> x >> y ;
		adj[x].emplace_back(y);
		adj[y].emplace_back(x);
	}
	for(int i = 0 ; i < N ; ++i)
		dp[i][0] = 1 , dp[i][1] = 1;
	dfs(1 , 0);
	cout << (dp[1][0]+dp[1][1])%mod;

	return 0;
}

Measured memory_bytes: 13440
import sys
from collections import Counter
n, m = [int(i) for i in sys.stdin.readline().split()]
s_ls = [int(i) for i in sys.stdin.readline().split()]
a_ls = [i // 2 for i in s_ls]
ct = Counter(a_ls)
flg = False
for k in ct.keys():
    while k % 2 == 0 and k:
        if ct[k // 2] > 0:
            flg = True
            break
        k //= 2
if flg:
    print(0)
else:
    def gcd(a, b):
        while a and b:
            if a < b:
                b %= a
            else:
                a %= b
        return max(a, b)

    def scm(a, b):
        _gcd = gcd(a, b)
        return a * b // _gcd

    flg = True
    res = a_ls[0]
    for a in a_ls[1:]:
        res = scm(res, a)
        if res > m:
            flg = False
            break

    if flg:
        print((m - res) // (res * 2) + 1)
    else:
        print(0)

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

int main()
{
	int n,x,y,i,j;
	bool flag=0;
	scanf("%d",&n);
	for(i=1;i<=9;i++)
	{
		for(j=1;j<=9;j++)
		{
			if(i*j==n)
			{
				flag=1;
				break;
			}
		}
	}
	if(flag)printf("Yes\n");
	else printf("No\n");
	return 0;
}

Measured memory_bytes: 128
/*input
3 0
1000000000 1000000000 1000000000
*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout << (#x) << " is " << (x) << endl
#define debug cout << "hi" << endl

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

const int MOD = 1e9 + 7;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n, k; cin >> n >> k;
    ll ans = 0;
    vector<ll> h(n);
    for(int i = 0; i < n; i++) cin >> h[i];
    sort(h.begin(), h.end());
	for(int i = 0; i < n - k; i++) ans += h[i];
	cout << ans;

    return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <bits/stdc++.h>
#include <math.h>

using namespace std;

int main(){
    int saitei=10;
    int ans=0;
    vector<int> hoge(5);
    for(int i=0;i<5;i++){
        cin>>hoge.at(i);
        int fuga=hoge.at(i)%10;
        if(fuga!=0) saitei=min(fuga,saitei);
        
        if(fuga==0) ans+=hoge.at(i);
        else ans+=hoge.at(i)+10-fuga;
    }
    
    cout<<ans-10+saitei<<endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using vc = vector<char>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
#define rep(i, n) for (ll i = 0; i < (n); i++)
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
#ifndef ONLINE_JUDGE
    #define debug(x) cerr << #x << ": " << x << endl;
#else
    #define debug(x)
#endif

int main() {
    cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(20);

    ll N, M, K;
    cin >> N >> M >> K;
    
    vll A(N), B(M), SA(N+1, 0), SB(M+1, 0);
    rep(i,N) {
        cin >> A[i];
        SA[i+1] = SA[i] + A[i];
    }
    rep(i,M) {
        cin >> B[i];
        SB[i+1] = SB[i] + B[i];
    }

    ll ans = 0;
    rep(i, N+1) {
        if(SA[i] > K) break;
        ll tmp = i - 1 + (lower_bound(SB.begin(), SB.end(), K-SA[i]+1) - SB.begin());
        chmax(ans, tmp);
    }
    cout << ans << endl;
}


Measured memory_bytes: 9480
from math import cos, sqrt, pi

A, B, H, M = map(int, input().split())

long_arch = H/12 + M/12/60
short_arch = M / 60

diff = abs(long_arch - short_arch)
smaller_diff = min(diff, 1-diff)

c2 = A*A + B*B - 2*A*B*cos(smaller_diff*2*pi)
print(sqrt(c2))


Measured memory_bytes: 9500
#include<bits/stdc++.h>
#define forr(i, a, b) for(int i = (a); i < (b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = 1; i <= (n); i++)
#define ALL(a) (a.begin()),(a.end())
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll, ll> LP;
const ll LINF = 1LL<<60;
const int INF = 1001001001;
const int MOD = 1000000007;

/* --------------------------------------------------- */

int main() {
    int n, m;
    cin >> n >> m;
    vector<vector<int>> to(n);
    rep(i, m) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        to[a].push_back(b);
        to[b].push_back(a);
    } 
    vector<int> ans(n);
    queue<int> q;
    vector<int> dist(n, INF);
    bool check;
    auto update = [&](int t, int v) {
        if(dist[t] != INF) return;
        check = true;
        dist[t] = v;
        q.push(t);
    };
    update(0, 0);
    while(!q.empty()) {
        int t = q.front();
        q.pop();
        rep(i, to[t].size()) {
            check = false;
            int nt = to[t][i];
            update(nt, dist[t] + 1);
            if(check) ans[nt] = t + 1;
        }
    }
    puts("Yes");
    rrep(i, n - 1) {
        cout << ans[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 10624