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

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

	long N;
	cin >> N;

	long MAX, P, cnt;
	MAX = 0;
	P = 0;
	long A[N];
	for(long i = 0; i < N; i++) {
		cin >> A[i];
		if (MAX < A[i]) {
			MAX = A[i];
			cnt = 1;
		} else if (MAX == A[i]) {
			P = A[i];
			cnt++;
		} else if (P < A[i]) {
			P = A[i];
		}
	}

	for(long i = 0; i < N; i++) {
		if (A[i] == MAX && cnt == 1)
			cout << P << endl;
		else
			cout << MAX << endl;
	}

	return 0;
}


Measured memory_bytes: 3200
#include <iostream>
#include <algorithm>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <functional>
#include <string>
#include <cstdlib>
#include <numeric>
#include <cstdbool>
#include <map> 
#include<set>
#include<queue>

typedef long long ll;


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

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 long long INF = 1000000000000000;
typedef pair<int, int> P;
ll ma = 1000000000 + 7;
ll h, w, n, m,k; string s; string sp;
char maze[60][60];
int dis[60][60];
int dx[4] = { 1, 0, -1, 0 };
int dy[4] = { 0, 1, 0, -1 };

int main() {
	string a, b, c;
	cin >> a >> b >> c;
	int na = a.size();
	int nb = b.size();
	int nc = c.size();
	int flg = 1;
	for(int ia = 0,ib=0,ic=0;;) {
		if (flg == 1) {
			if (a[ia] == 'a') {
				ia++; flg = 1;
			}
			else if (a[ia] == 'b') {
				ia++; flg = 2;
			}
			else if (a[ia] == 'c') {
				ia++; flg = 3;
			}
		}
		else if (flg == 2) {
			if (b[ib] == 'a') {
				ib++; flg = 1;
			}
			else if (b[ib] == 'b') {
				ib++; flg = 2;
			}
			else if (b[ib] == 'c') {
				ib++; flg = 3;
			}
		}
		else if (flg == 3) {
			if (c[ic] == 'a') {
				ic++; flg = 1;
			}
			else if (c[ic] == 'b') {
				ic++; flg = 2;
			}
			else if (c[ic] == 'c') {
				ic++; flg = 3;
			}
		}
		if (ia == na&&flg==1) {
			cout << "A" << endl;
			return 0;
		}
		else if (ib == nb&&flg==2) {
			cout << "B" << endl;
			return 0;
		}
		else if (ic == nc&&flg==3) {
			cout << "C" << endl;
			return 0;
		}
	}
}

Measured memory_bytes: 256
function Main(s) {
  var s = s.split("\n");
  var s = [
    s[0].split(" ").map(e => Number(e)),
    s[1].split(" ").map(e => Number(e)),
    s[2].split(" ").map(e => Number(e))
  ];
  var t, cnt, a2, a3, b1, b2, b3;
  for (var a1 = 0; a1 <= s[0][0]; a1++) {
    cnt = 0;
    b1 = s[0][0] - a1;
    b2 = s[0][1] - a1;
    b3 = s[0][2] - a1;
    a2 = s[1][0] - b1;
    a3 = s[2][0] - b1;
    t = [
         [a1+b1,a1+b2,a1+b3],
         [a2+b1,a2+b2,a2+b3],
         [a3+b1,a3+b2,a3+b3]
           ];
    for (var i = 0; i < 3; i++) {
      for (var j = 0; j < 3; j++) {
        if (s[i][j] === t[i][j]) cnt++;
      }
    }
    if (cnt === 9) {
      console.log("Yes");
      return;
    }
  }
  console.log("No")
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

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

  long long int m_rule=0;
  for(int i=0;i<s.size();i++){
    if(s[i]=='*'){
      long long int pro=s[i-1]-'0';
      for(i=i+2;i<s.size();i+=2){
	if(s[i]=='*'){
	  pro*=s[i-1]-'0';
	}
	else{
	  break;
	}
      }
      pro*=s[i-1]-'0';
      m_rule+=pro;
    }
  }
  if(s.size()==1) m_rule=s[0]-'0';
  if(s.size()>1  && s[1]=='+') m_rule+=s[0]-'0';
  if(s.size()>2 && s[s.size()-2]=='+') m_rule+=s[s.size()-1]-'0';
  for(int i=2;i+1<s.size();i++){
    if(s[i-1]=='+' && s[i+1]=='+'){
      m_rule+=s[i]-'0';
    }
  }

  long long int l_rule=s[0]-'0';
  for(int i=1;i<s.size();i+=2){
    if(s[i]=='+') l_rule+=s[i+1]-'0';
    else l_rule*=s[i+1]-'0';
  }

  if(l_rule==ans && m_rule==ans) cout<<"U"<<endl;
  else if(l_rule==ans) cout<<"L"<<endl;
  else if(m_rule==ans) cout<<"M"<<endl;
  else cout<<"I"<<endl;
  return 0;

}

Measured memory_bytes: 3160
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <cmath>
#include <climits>

#define X first
#define Y second
#define vsort(v) sort((v).begin(), (v).end())
#define vrev(v) reverse((v).begin(), (v).end())

// stoi(s): string to int
// stod(s): string to double

// INT_MAX
// INT_MIN
// LLONG_MAX
// LLONG_MIN
// DBL_MIN
// DBL_MAX
// LDBL_MIN
// LDBL_MAX

// A-Z: 65~90
// a-z: 97~122
// |a-z| = 26

using namespace std;
using ll = long long;

int main(int argc, const char * argv[]) {
    vector<int> v(3);
    for (int i = 0; i < 3; i++) {
        cin >> v[i];
    }
    vsort(v);
    cout << v[0] * v[1] / 2 << endl;
}


Measured memory_bytes: 256
//g++ -std=c++14 test.cpp -o test.out
//問題URL
//https://atcoder.jp/contests/abc167/tasks/abc167_f

//ポイント：
//どう貪欲にとっていいか分からなくなったら、正負で分けるのも手
//左右反転なんて手もある

#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <vector>
#include <queue>
#include <stack>
#include <map> 
#include <unordered_map> 
#include <utility>
#include <limits.h>
#include <bitset>
#include <set>
using namespace std;
 
#define LL long long int
const LL INF = (1LL<<60);
const int INF_INT = 2147483647-1e6-1;
const LL mod = 1000000007ll;
const int mod_int = 1000000007;

LL N;
string S[1000000];

string ans = "No";

void solve(){
	vector<pair<LL,LL>> left2right;
	vector<pair<LL,LL>> right2left;
	for(int i=0;i<N;i++){
		LL unclosed = 0;//閉じられていない(の数
		LL min_unclosed = 0;//最下点
		for(int j=0;j<S[i].size();j++){
			if(S[i][j]=='(') unclosed++;
			else unclosed--;
			min_unclosed = min(min_unclosed,unclosed);
		}
		if(unclosed>=0) left2right.push_back(pair<LL,LL>(min_unclosed,unclosed));
		else right2left.push_back(pair<LL,LL>(min_unclosed-unclosed,-unclosed));
	}
	sort(left2right.begin(),left2right.end(),greater<pair<LL,LL>>());
	sort(right2left.begin(),right2left.end(),greater<pair<LL,LL>>());

	LL now = 0;
	for(int i=0;i<left2right.size();i++){
		LL down = left2right[i].first;
		LL up = left2right[i].second;
		//cout << down << " " << up << endl;
		if(now+down<0) return;
		now += up;
	}
	LL highest = now;
	now = 0;
	for(int i=0;i<right2left.size();i++){
		LL down = right2left[i].first;
		LL up = right2left[i].second;
		if(now+down<0) return;
		now += up;
	}
	if(highest==now) ans = "Yes";
}

int main(){
    cin >> N;
    for(int i=0;i<N;i++)cin >> S[i];

    solve();

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

Measured memory_bytes: 42164
#include<stdio.h>
#include<iostream>
using namespace std;
int main()
{
	int n;
	int v[60], c[60];
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> v[i];
	}
	for (int i = 0; i < n; i++) {
		cin >> c[i];
	}
	int result = 0;
	for (int i = 0; i < n; i++) {
		if (v[i] > c[i]) {
			result += (v[i] - c[i]);
		}
	}
	cout << result;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
// #pragma GCC optimize("O3")
using namespace std;
#ifdef _debug
#define dout(i) cout << #i << ' ' << i << ' '
#else 
#define dout(i) //
#endif
using ll = long long;
using ull = unsigned long long;
using ul = unsigned;
using db = double;
string s;
ll k;
ll dp[2][1000];
void make(){
	dp[1][0] = 1;
	for(int i = 1;i < s.size();++i){
		if(s[i] == s[i-1]){
			dp[1][i] = dp[0][i-1] + 1;
			dp[0][i] = dp[1][i-1];
		}
		else {
			dp[0][i] = dp[0][i-1];
			dp[1][i] = dp[0][i-1] + 1;
		}
		assert(dp[0][i] <= dp[1][i]);
	}
}
bool same(){
	for(int i = 1;i < s.size();++i)if(s[i] != s[i-1])return false;
	return true;
}
int main(){
	ios_base::sync_with_stdio(0), cin.tie(0);
	cin >> s >> k;
	ll res = 0;
	if(s.size() == 1)cout << k / 2 << '\n';
	else{
		if(same())cout << k * s.size() / 2 << '\n';
		else{
			make();
			if(s.front() != s.back() || k == 1)cout << dp[0][s.size()-1] * k << '\n';
			else{
				res = dp[1][s.size()-1] * (k-1) + dp[0][s.size()-1];
				reverse(s.begin(), s.end());
				make();
				res = min(res, dp[1][s.size()-1] * (k-1) + dp[0][s.size()-1]);
				cout << res << '\n';
			}
		}
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int x,y;
  int X,Y;
  cin >> x >>y;
  if(x == 4||x ==6||x==9||x==11){
    X = 2;
  }
  else if(x==2){
    X =3;
  }
  else{
    X =1;
  }
    if(y == 4||y ==6||y==9||y==11){
    Y = 2;
  }
  else if(y==2){
    Y =3;
  }
  else{
    Y =1;
  }
  if(X==Y){
    cout << "Yes";
  }
  else{
    cout << "No";
  }
}

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

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#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 repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

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

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define INF2 (1e18)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

const long long mod = 998244353;

int main(){
    int n;
    cin >> n;
    vi d(n);
    rep(i, n) cin >> d[i];
    if (d[0] != 0) {
        cout << 0 << endl;
        return 0;
    }
    vi cnt(n);
    rep(i, n) cnt[d[i]]++;
    ll ans = 1;
    rep1(i, n-1) {
        if (d[i]-1<0) {
            cout << 0 << endl;
            return 0;
        }
        ans = ans * cnt[d[i]-1] % mod;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3992
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int cnt=0,i,j,k,n,r=0,g=0,b=0;
    string ptr;
    cin>>n>>ptr;

    for(i=0; i<ptr.length(); i++)
    {
        if(ptr[i]=='R')
            r++;
        if(ptr[i]=='G')
            g++;
        if(ptr[i]=='B')
            b++;
    }
    for(i=0; i<n; i++)
    {
        for(j=i+1; j<n; j++)
        {
            if(ptr[i]!=ptr[j])
            {
                if(2*j-i>=n)
                    break;
                if(ptr[2*j-i]!=ptr[i]&&ptr[2*j-i]!=ptr[j])
                    cnt++;
            }
        }
    }
cout<<(r*g*b)-cnt<<endl;
}


Measured memory_bytes: 3612
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>

using namespace std;


int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(12);

    int S;
    cin >> S;

    const long long MOD = 1000000007;

    vector<long long> dp(S + 1, 0);
    dp[0] = 1;
    for (int i = 0; i < S; ++i) {
        for (int j = S - i; j >= 3; --j) {
            (dp[j + i] += dp[i]) %= MOD;
        }
    }

    cout << dp[S] << '\n';
    return 0;
}

Measured memory_bytes: 3664
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define mod 1000000007
#define pb push_back
#define nl cout<<"\n"
#define db(x) cout<<x<<" "
#define fi(a,b) for(int i=a;i<b;i++)
#define fj(a,b) for(int j=a;j<b;j++)
#define fk(a,b) for(int k=a;k<b;k++)
#define F first
#define S second
#define UM unordered_map<int,int>
#define MP map<int,int>
#define mxsize (int)1e6
void fun(){
    int n;
    cin>>n;
    int h[n];
    fi(0,n) cin>>h[i];
    int dp[2];
    dp[0]=0;
    dp[1]=abs(h[1]-h[0]);
    fi(2,n){
        int temp=dp[1];
        dp[1]=min(dp[0]+abs(h[i]-h[i-2]),dp[1]+abs(h[i]-h[i-1]));
        dp[0]=temp;
    }
    cout<<dp[1]<<"\n";
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    #ifndef ONLINE_JUDGE
        freopen("/ATOM/input.txt", "r", stdin);
        freopen("/ATOM/output.txt", "w", stdout);
    #endif
    int t=1;
    // cin>>t;
    while(t--){
        fun();
    }
}

Measured memory_bytes: 4028
// C - Cat Snuke and a Voyage
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;

int main(){
	int N,M; cin>>N>>M;
	vi P(N);
	while(M--){
		int a,b; cin>>a>>b;
		if(a==1) P[b-1] = P[b-1] & 0b10 | 0b01;
		if(b==N) P[a-1] = P[a-1] & 0b01 | 0b10;
	}
	string ans = "IMPOSSIBLE";
	while(N--)
		if(P[N] == 0b11){
			ans = "POSSIBLE";
			break;
		}
	cout<< ans <<endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#pragma GCC optimize("O3","Ofast")
using namespace std;

template<class T> ostream& operator<<(ostream &os,vector<T> V){os<<"[ ";for(auto v:V)os<<v<<" ";return os<<"]";}
template<class L,class R> ostream& operator<<(ostream &os,pair<L,R> P){return os<<"("<<P.first<<","<<P.second<<")";}
#define DEBUG1(x) cout  << '>' << " " << #x << ':' << " " <<  x << endl;
#define DEBUG2(x,y) cout  << '>' << " " << #x << ':' << " " <<  x <<  " " << #y << ':' << " " <<  y <<endl;
#define DEBUG3(x,y,z) cout  << '>' << " " << #x << ':' << " " <<  x << " " << #y << ':' << " " <<  y <<" " << #z << ':' << " " <<  z << " " <<endl;
#define FASTIO ios_base::sync_with_stdio(false); cin.tie(NULL);

#define TC int t; cin >> t;while(t--)
#define forn(i,n) for(int i=0;i<n;i++)

#define ALL(x) x.begin(),x.end()
#define LL long long int
#define PB push_back
#define EB emplace_back
#define F first
#define S second
#define endl "\n"

typedef pair<int,int>PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<PII> VPII;

const int mod = 10*9+7;
const int inf = 2e9;
const LL linf = 2e18;
const double eps = 1e-9;

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

int main(){
    
    int n;
    cin >> n;
    int dp1[n], dp2[n], dp3[n];
    int a[n], b[n], c[n];
    for (int i = 0; i < n;i++){
        cin >> a[i] >> b[i] >> c[i];
    }
    dp1[0] = a[0];
    dp2[0] = b[0];
    dp3[0] = c[0];
    for (int i = 1; i < n;i++){
        dp1[i] = a[i] + max(dp2[i - 1], dp3[i - 1]);
        dp2[i] = b[i] + max(dp1[i - 1], dp3[i - 1]);
        dp3[i] = c[i] + max(dp2[i - 1], dp1[i - 1]);
    }
    cout << max(dp3[n - 1], max(dp2[n - 1], dp1[n - 1]));
    return 0;
}

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

int N;
long long atcount = 0;

int main(){
    cin >> N;
    for(int a = 1; a < N + 1; a++){
        for(int b = 1; b < N + 1; b++){
            for(int c = 1; c < N + 1; c++){
                atcount += __gcd(__gcd(a, b), c);
            }
        }
    }
    cout << atcount << endl;
}

Measured memory_bytes: 3636
#include "iostream"
#include "algorithm"
#include "string"
#include "vector"
#include "cmath"
#include "bitset"
#define lp(n) for (int i = 0; i < n; i++)
#define lop(n,i) for (int i = 0; i < n; i++)
#define mod 1000000007
#define ll long long int
#define sp ' '
#define intmax 2147483647
#define intmin -2147483647
#define llmax 9223372036854775807
using namespace std;

ll n, m;

int main(){
	cin >> n >> m;
	if (n == 1 && m == 1)
		cout << 1 << endl;
	else if (n == 1)
		cout << m - 2 << endl;
	else if (m == 1)
		cout << n - 2 << endl;
	else cout << (m - 2)*(n - 2) << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<set>
#include<map>
#include<vector>
#include<string>

using namespace std;

int main()
{
  set<string> dict;
  vector<string> vdict;
  map< pair<string,string>, int > M;
  const char *cdict[] = {"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y","z","ld", "mb", "mp", "nc", "nd", "ng", "nt", "nw", "ps", "qu", "cw","ts"};
  for(int i = 0; i < 38; ++i){
    string s = cdict[i];
    dict.insert(s);
    vdict.push_back(s);
  }
  int n;
  cin >> n;
  string text,s;
  getline(cin,s);
  for(int i = 0; i < n; ++i){
    getline(cin,s);
    text += s+"$";
  }
  for(int i = 0; i < text.length(); ++i){
    if(text[i] == ' ')text[i]='$';
  }
  text += "$$$$$$";
  for(int i = 0 ; i < text.length(); ++i){
    if(text[i]=='$' || text[i] == ' ')continue;
    string pre,suf;
    pre += text[i];
    pre += text[i+1];
    if(dict.find(pre)!=dict.end()){
      if( text[i+2] == '$' || text[i+2] == ' ')continue;
      suf += text[i+2];
      suf += text[i+3];
      if( dict.find(suf) != dict.end() ){
	M[ make_pair(pre,suf) ]++;
	++i;
      }else{
	suf = text[i+2];
	//cout << pre << ' ' << suf << endl;
	M[ make_pair(pre,suf) ]++;
	++i;
      }
    }else{
      pre = text[i];
      if( text[i+1] == '$' || text[i+1] == ' ')continue;
      suf = text[i+1];
      suf += text[i+2];
      if( dict.find(suf) != dict.end() ){
	M[ make_pair(pre,suf) ]++;
      }else{
	suf = text[i+1];
	M[ make_pair(pre,suf) ]++;
      }
    }
  }
  map<string, pair<string,int> > A;
  for(map< pair<string,string>, int >::iterator itm = M.begin(); itm != M.end(); ++itm){
    if( A.find( itm->first.first ) == A.end() ){
      A[itm->first.first] = make_pair( itm->first.second, itm->second );
    }else{
      if( A[itm->first.first].second < itm->second ){
	A[itm->first.first] = make_pair( itm->first.second, itm->second );
      }else if( A[itm->first.first].second == itm->second && A[itm->first.first].first > itm->first.second ){
	A[itm->first.first] = make_pair( itm->first.second, itm->second );
      }
    }
  }
  for(int i = 0; i < vdict.size(); ++i){
    map<string, pair<string,int> > :: iterator itm = A.find( vdict[i] );
    if( itm == A.end() ){
      cout << vdict[i] << " a 0" << endl;
    }else{
      cout << itm->first << ' ' << itm->second.first << ' ' << itm->second.second << endl;
    }
  }
  return 0;
}

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

using namespace std;

const int N = 105;
const int K = 100005;
const int MOD = 1e9 + 7;

int n, k, a[N], f[N][K], sum[N][K];

inline int get (int idx, int l, int r) {
  int res = sum[idx][r];
  if (l > 0) {
    res -= sum[idx][l - 1];
    if (res < 0) res += MOD;
  }
  return res;
}

int main() {
  cin >> n >> k;
  for (int i = 1; i <= n; ++i) cin >> a[i];
  f[0][0] = 1;
  for (int j = 0; j <= k; ++j) {
    sum[0][j] = 1;
  }
  for (int i = 1; i <= n; ++i) {
    for (int j = 0; j <= k; ++j) {
      sum[i][j] = f[i][j] = get(i - 1, j - a[i], j);
      if (j) {
        sum[i][j] += sum[i][j - 1];
        if (sum[i][j] >= MOD) sum[i][j] -= MOD;
      }
    }
  }
  cout << f[n][k] << endl;
  return 0;
}



Measured memory_bytes: 82176
#include<bits/stdc++.h>
using namespace std;
typedef int sign;
typedef long long ll;
#define For(i,a,b) for(register sign i=(sign)(a);i<=(sign)(b);++i)
#define Fordown(i,a,b) for(register sign i=(sign)(a);i>=(sign)(b);--i)
const int N=1e6+5;
template<typename T>bool cmax(T &a,T b){return (a<b)?a=b,1:0;}
template<typename T>bool cmin(T &a,T b){return (a>b)?a=b,1:0;}
template<typename T>T read()
{
    T ans=0,f=1;
    char ch=getchar();
    while(!isdigit(ch)&&ch!='-')ch=getchar();
    if(ch=='-')f=-1,ch=getchar();
    while(isdigit(ch))ans=(ans<<3)+(ans<<1)+(ch-'0'),ch=getchar();
    return ans*f;
}
template<typename T>void write(T x,char y)
{
    if(x==0)
    {
        putchar('0'),putchar(y);
        return;
    }
    if(x<0)
    {
        putchar('-');
        x=-x;
    }
    static char wr[20];
    int top=0;
    for(;x;x/=10)wr[++top]=x%10+'0';
    while(top)putchar(wr[top--]);
    putchar(y);
}
void file()
{
#ifndef ONLINE_JUDGE
	freopen("F.in","r",stdin);
	freopen("F.out","w",stdout);
#endif
}
int n,m,a[N],b[N];
void input()
{
    n=read<int>(),m=read<int>();	
    For(i,1,n)a[i]=read<int>();
    For(i,1,m)b[i]=read<int>();
}
int l[N],r[N],top;
int q[N];
struct node
{
    int x,y;
    bool operator < (const node &s)const
    {
        return x==s.x?y>s.y:x<s.x;
    }
	bool operator == (const node &s)const
	{return x==s.x&&y==s.y;}
}e[N];
const int inf=0x3f3f3f3f;
void init()
{
    int st=1,ed=n;
    while(st<=n&&a[st]<b[1])st++;
    while(ed>=1&&a[ed]>b[m])ed--;
    top=ed-st+1;
	if(top<=0){puts("1");exit(0);}
	For(i,1,top)a[i]=a[i+st-1];
    //cerr<<st<<' '<<ed<<endl;
	int pos;
    For(i,1,top)
    {
        pos=upper_bound(b+1,b+m+1,a[i])-b;
        r[i]=b[pos]-a[i];
        l[i]=a[i]-b[pos-1];
		assert(pos>1);assert(pos<=m);
    }
    ++top;l[top]=r[top]=-1;
	For(i,1,top)e[i].x=l[i];
    q[0]=top;
    For(i,1,top)q[i]=r[i];
    sort(q+1,q+q[0]+1);
    q[0]=unique(q+1,q+q[0]+1)-q-1;
    For(i,1,top)e[i].y=lower_bound(q+1,q+q[0]+1,r[i])-q;
}
const int mo=1e9+7;
int sum[N];
void add(int x,int v)
{
    assert(x>0);
	for(;x<=q[0];x+=x&-x)sum[x]=(sum[x]+v)%mo;
}
int cal(int x)
{
    int res=0;
    for(;x;x-=x&-x)res=(res+sum[x])%mo;
    return res;
}
void work()
{
    sort(e+1,e+top+1);
	top=unique(e+1,e+top+1)-e-1;
	assert(q[0]<=top);
	//For(i,1,top)cout<<e[i].x<<' '<<e[i].y<<endl;
	add(1,1);
	For(i,2,top)add(e[i].y,cal(e[i].y-1));
	write(cal(q[0]),'\n');
}
int main()
{
//	file();
    input();
    init();
    work();
    return 0;
}

Measured memory_bytes: 14976
#include <algorithm>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <cassert>
#include <iostream>
#include <queue>
#include <sstream>
#include <string>
#include <stack>
#include <set>
#include <vector>

using namespace std;

#define all(c) ((c).begin()), ((c).end())
#define dump(c) cerr << "> " << #c << " = " << (c) << endl;
#define iter(c) __typeof((c).begin())
#define tr(i, c) for (iter(c) i = (c).begin(); i != (c).end(); i++)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, a, b) for (int i = (int)(a); i <= (int)(b); i++)

#define mp make_pair
#define fst first
#define snd second
#define pb push_back

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<string> vs;
typedef pair<int,int> pii;

const int INF = 1 << 29;
const double EPS = 1e-10;

template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& p){
    return os<<'('<<p.first<<','<<p.second<<')';
}
template<typename T>
ostream& operator<<(ostream& os,const vector<T>& a){
    os<<'[';
    rep(i,a.size()) os<<(i?" ":"")<<a[i];
    return os<<']';
}


int H, W;
char map[110][110];
bool visited[110][110];

void go(int x, int y) {
	visited[y][x] = true;
	static int dx[4] = {1, 0, -1, 0};
	static int dy[4] = {0, 1, 0, -1};
	rep(d, 4) {
		int tx = x + dx[d];
		int ty = y + dy[d];
		if (tx < 0 || tx >= W || ty < 0 || ty >= H) continue;
		if (visited[ty][tx]) continue;
		if (map[y][x] != map[ty][tx]) continue;
		go(tx, ty);
	}
}

int main() {
	for(; cin >> H >> W, (H|W) != 0; ) {
		rep(i, H) rep(j, W) {
			cin >> map[i][j];
		}
		int ans = 0;
		memset(visited, false, sizeof(visited));
		rep(i, H) rep(j, W) {
			if (!visited[i][j]) {
				go(j, i);
				ans++;
			}
		}
		cout << ans << endl;
	}

	return 0;
}

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

int n,k,hed[100010],cnt,ans,dis[100010],fa[100010];
struct node
{
	int to,next;
}a[200010];
inline void add(int from,int to)
{
	a[++cnt].to=to;
	a[cnt].next=hed[from];
	hed[from]=cnt;
}
inline void dfs(int x)
{
	dis[x]=1;
	for(int i=hed[x];i;i=a[i].next)
	{
		int y=a[i].to;
		if(y==fa[x])
		continue;
		fa[y]=x;
		dfs(y);
		dis[x]=max(dis[x],dis[y]+1);
	}
	if(dis[x]>=k&&fa[x]>1)
	{
		dis[x]=0;
		++ans;
	}
}
int main()
{
	scanf("%d%d",&n,&k);
	for(int i=1;i<=n;++i)
	{
		int x;
		scanf("%d",&x);
		if(i==1)
		{
			if(x!=1)
			++ans;
		}
		else
		add(x,i);
	}
	dfs(1);
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 4480
#include <bits/stdc++.h>
typedef long long ll;
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)
using namespace std;
ll x[5];
const ll INF=1e8;
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll ans=INF;
	REP(i,5){
		cin>>x[i];
	}
	sort(x,x+5);
	do{
		ll sm=0;
		REP(i,5){
			if(i<4){
				sm+=(x[i]+9)/10*10;
			}else{
				sm+=x[i];
			}
		}
		ans=min(ans,sm);
	}while(next_permutation(x,x+5));
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>

 int main(void){
    char str[20],strr[20];
    int i,j;
    scanf("%s",str);
    for(i=0;i<20;i++){
      if(str[i]=='\0')
        break;
    }
    i--;
    for(;i>=0;i--){
    printf("%c",str[i]);
    }
    printf("\n");
    return 0;
}
    

Measured memory_bytes: 520
#include<iostream>
#include<cstring>
#include<stdio.h>
#define int long long
using namespace std;
const int N=5e5,M=15,MOD=998244353;
int a[N];
int f[N];
int x[M],y[M];
int n,m;
int qzh[N];
inline int modbez(int a,int b){
	register int res=a%b;
	if(res<0)
		return res+b;
	else
		return res;
}
void DP(){
	f[n]=1;
	for(int i=n;i>=1;i--){
		for(int j=1;j<=m;j++){
			f[i]=modbez(f[i]+qzh[i+x[j]]-qzh[i+y[j]+1],MOD);
		}
		qzh[i]=modbez(qzh[i+1]+f[i],MOD);
	}
	cout<<f[1]%MOD<<endl;
}
void common_DP(){
	f[n]=1;
	for(int i=n;i>=1;i--)
		for(int j=1;j<=m;j++)
			for(int k=x[j];k<=y[j];k++){
				if(i+k<=n){
					f[i]=(f[i]+f[i+k])%MOD;
				}
			}
	cout<<f[1]<<endl;
}
signed main(){
	memset(f,0,sizeof(f));
	memset(a,0,sizeof(a));
	cin>>n>>m;
	for(int i=1;i<=m;i++){
		cin>>x[i]>>y[i];
	}
	if(n<1e4)
		common_DP();
	else
		DP();
}










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

#define int long long

const int INF = 1e15;

struct Edge {
  int to, d, c;  
};

int s, g;
int n, m;
vector<Edge> G[31];

typedef pair<int, int> P;
typedef pair<double, int> E;
typedef pair<E, P> PE;

double dij() {
  double ret = INF;  
  bool used[n+1][n+1][101];
  fill_n(**used, (n+1)*(n+1)*101, false);
  priority_queue<PE, vector<PE>, greater<PE> > q;  
  q.push(PE(E(0, n), P(s, 1)));  
  while ( !q.empty() ) {
    PE e = q.top(); q.pop();    
    double c = e.first.first;
    int pre = e.first.second;    
    int u = e.second.first, v = e.second.second;
    // cout << u << " " << v << endl;
    if ( u == g && v == 1 ) {
      
    }

    if ( used[u][pre][v] ) continue;
    used[u][pre][v] = true;    
    for ( Edge &f : G[u] ) {
      if ( pre == f.to ) continue;      
      if ( f.c < v ) continue;
      if ( f.to == g && v == 1 ) {
	ret = min(ret, c+(double)f.d);	
      }
      q.push(PE(E(c+(double)f.d/v, u), P(f.to, v)));      
      q.push(PE(E(c+(double)f.d/v, u), P(f.to, v+1)));
      if ( v >= 2 ) q.push(PE(E(c+(double)f.d/v, u), P(f.to, v-1)));      
    }
  }

  return ret;
}

signed main() {  
  while ( cin >> n >> m, n ) {
    for ( int i = 0; i < 31; i++ ) G[i].clear();    
    cin >> s >> g;
    s--; g--;
    for ( int i = 0; i < m; i++ ) {
      int a, b, d, c;
      cin >> a >> b >> d >> c;
      a--; b--;
      G[a].emplace_back(Edge{b, d, c});
      G[b].emplace_back(Edge{a, d, c});
    }

    double ans = dij();
    if ( ans >= INF-100 ) cout << "unreachable" << endl;
    else printf("%.10lf\n", ans);    
  }
  
  return 0;
}



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

typedef long long ll;

int main() {
	ios::sync_with_stdio(0);
	
	ll n;
	cin >> n;
	string s;
	ll m = 0, a = 0, r = 0, c = 0, h = 0;
	while (cin >> s) {
		if (s[0] == 'M') m++;
		if (s[0] == 'A') a++;
		if (s[0] == 'R') r++;
		if (s[0] == 'C') c++;
		if (s[0] == 'H') h++;
	}
	ll ans;
	ans = m*a*r + m*a*c + m*a*h + m*r*c + m*r*h + m*c*h + a*r*c + a*r*h + a*c*h + r*c*h;
	cout << ans;
	
	return 0;
}

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

int main(){
    int N; cin >> N;
    string S; cin >> S;
    int cnt = 0;
    int pre = 0;
    rep(i, 0, N-2){
        if(S[i] == 'A' && S[i+1] == 'B' && S[i+2] == 'C') cnt++;
    }
    cout << cnt << endl;
}

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

#define repr(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define repr_inv(i,a,b) for(int i=(int)(a);i>=(int)(b);i--)
#define rep(i,n) repr(i,0,n)
#define MOD 1000000007
#define PI 3.1415926535
using namespace std;
int main(void)
{
	string s;

	cin>>s;

	rep(i, (int)s.size()){
		if(i%2==0){
			cout<<s[i];
		}
	}
	cout<<endl;
}



Measured memory_bytes: 512
import sys
DBG = True
n,m,c =      map(int, input().split())
b   = list(map(int, input().split()))
cnt = 0
for i in range(n):
  a   = list(map(int, input().split()))
  sum = c
  for j in range(m):
      sum += a[j] * b[j]
  if sum > 0:
      cnt += 1

print(cnt)


Measured memory_bytes: 3060
x=int(input())
value=0
index=0
hashmap=dict()
while value<int(1e18)+1:
    value=index**5
    hashmap[value]=index
    index+=1
#print(hashmap)    
 
for i in range(1,1000):
    b1=x+ i**5
    b2=x+(-i)**5
    if hashmap.get(b1)!=None:
        print(hashmap[b1],i)
        break
    if hashmap.get(abs(b2))!=None:
        print(hashmap[abs(b2)],-i)
        break     


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

int main() {
    int N, C, K; cin >> N >> C >> K;
    int T[N];
    for (int i = 0; i < N; i++) cin >> T[i];
    sort(T, T + N);

    int ans = 0, pas = 0, minT = T[0];
    for (int i = 0; i < N; i++) {
        if (pas == C) { ans++; pas = 0; minT = T[i]; }
        if (minT <= T[i] && T[i] <= minT + K) pas++;
        else { ans++; pas = 1; minT = T[i]; }
        if (i == N - 1) {
            if (pas > 0) ans++;
        } 
    }
    cout << ans << endl;
}

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

int main(){
  int a,b;
  cin >> a >> b;
  char s[12];
  cin >> s;
    
    for(int i=0;i<a;++i){
      if(!('0'<=s[i] && s[i] <='9')){ //if(!(~)) == if(Not(~))
        cout << "No" << endl;
        return 0;
      }
    }
  if(s[a] !='-'){
    cout << "No" << endl;
    return 0;
  }
for(int i=a+1;i<a+b;i++){
  if(!('0'<=s[i] && s[i] <= '9')){
    cout << "No" << endl;
    return 0;
  }
}
  cout << "Yes" << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		try (Scanner sc = new Scanner(System.in);) {
			long n = sc.nextLong();

			final int MOD = 1000000007;

			long a = pow(10, n, MOD);
			long b = pow(9, n, MOD);
			long c = pow(8, n, MOD);

			long result = m_sub(a, b, MOD);
			result = m_sub(result, b, MOD);
			result = m_add(result, c, MOD);

			System.out.println(result);

		} catch (Exception e) {
			e.printStackTrace();
		}

	}

	//return a^b mod M O(logB)
	public static long pow(long a, long b, int M) {
		long ret = 1;
		long tmp = a;
		while (b > 0) {
			if ((b & 1) == 1)
				ret = (ret * tmp) % M;
			tmp = (tmp * tmp) % M;
			b = b >> 1;
		}
		return ret;
	}

	public static long m_add(long a, long b, int MOD) {
		return ((a + b) % MOD);
	}

	public static long m_sub(long a, long b, int MOD) {
		long value = (a - b) % MOD;
		if (value < 0) {
			value += MOD;
		}
		return value;
	}

}

Measured memory_bytes: 35648
// Package main provides
//
// File:  main.go
// Author: ymiyamoto
//
// Created on Thu Jul 11 07:43:17 2019
//
package main

import (
	"fmt"
	"math"
)

func main() {
	var n, d int
	fmt.Scan(&n, &d)

	xs := make([][]float64, n)
	for i := range xs {
		xs[i] = make([]float64, d)
		for j := range xs[i] {
			fmt.Scan(&xs[i][j])
		}
	}

	var ans int
	for i := range xs {
		for j := i + 1; j < len(xs); j++ {
			total := 0.0
			for k := range xs[i] {
				d := xs[i][k] - xs[j][k]
				total += d * d
			}
			t := int(math.Sqrt(total))
			if t*t == int(total) {
				ans++
			}
		}
	}
	fmt.Println(ans)
}


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

int main() {
  int n, a[3]; cin >> n >> a[0] >> a[1] >> a[2];
  vector<int> l(n);
  for (int i = 0; i < n; i++) cin >> l[i];
  vector<int> s(3);
  int ans = 1e9;
  for (int i = 0; i < (1 << (2*n)); i++) {
    s[0] = s[1] = s[2] = 0;
    int score = 0;
    for (int j = 0; j < n; j++) {
      int t = (i >> (2*j))&3;
      if (t == 3) continue;
      if (s[t] > 0) score += 10;
      s[t] += l[j];
    }
    bool flag = true;
    for (int j = 0; j < 3; j++) flag &= s[j] > 0;
    if (!flag) continue;
    for (int j = 0; j < 3; j++) score += abs(s[j] - a[j]);
    ans = min(ans, score);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <algorithm>

using namespace std;

int main()
{
    int x, arr[100005] , dp[100005];
    cin >> x;
    for (int i = 0; i < x; i++)
        cin >> arr[i];
    for (int i = 0; i < x; i++)
        dp[i] = 1000000000;

    dp[0] = 0;
    dp[1] = abs(arr[1] - arr[0]);
    for (int i = 2; i < x; i++)
        dp[i] = min(dp[i - 1] + abs(arr[i] - arr[i - 1]), dp[i - 2] + abs(arr[i] - arr[i - 2]));
    cout << dp[x - 1];
    return 0;
}

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

bool is_prime(int n){
   if (n<=1) return false;
   for (int i=2;i*i<=n;i++) 
      if(n%i==0) return false;
   return true;
}

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

   int q=x;
   while(!is_prime(q)) q++;

   cout << q << endl;
   return 0;  
}

Measured memory_bytes: 256
s = list(input())
t = list(input())

#print(s)
#print(t)

sset = list(set(s))
tset = list(set(t))

#print(sset)
#print(tset)

s_getindex = []
t_getindex = []

for j in range(len(sset)):
    s_getindex.append([i for i, x in enumerate(s) if x == sset[j]])

for jj in range(len(tset)):
    t_getindex.append([ii for ii, y in enumerate(t) if y == tset[jj]])

#print(s_getindex)
#print(t_getindex)

check_s = []
check_t = []
ans = 0

for k in range(len(sset)):
    if len(s_getindex[k]) != 1:
        for m in s_getindex[k]:
            check_s.append(t[m])
#        print(check_s)
#        print(len(set(check_s)))
        if len(set(check_s)) != 1:
            ans = ans + 1
#            print(s[m])
        check_s.clear()

for kk in range(len(tset)):
    if len(t_getindex[kk]) != 1:
        for mm in t_getindex[kk]:
            check_t.append(s[mm])
        if len(set(check_t)) != 1:
            ans = ans + 1
#            print(t[mm])
        check_t.clear()

#print(ans)

if ans == 0:
    print("Yes")
else:
    print("No")


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

bool binarySearch(int key, int n, int S[]) {
    int l = 0, r = n;
    while(l < r) {
        int m = (l + r) / 2;
        if(S[m] == key) {
            return true;
        } else if(key < S[m]) {
            r = m;
        } else {
            l = m + 1;
        }
    }
    return false;
}

int main() {
    int n, q, cnt = 0;
    int S[200000], T[100000];
    cin >> n;
    for(int i = 0; i < n; i++) {
        cin >> S[i];
    }
    cin >> q;
    for(int i = 0; i < q; i++) {
        cin >> T[i];
        if(binarySearch(T[i], n, S)) {
            cnt++;
        }
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 3692
#include<bits/stdc++.h>
using namespace std;
int main() {
    long long n,m;
    cin>>n>>m;
    long long x, ara1[100001];
    long long a, b;
    a=b=0;
    int ia;
    for(int i=1; i<=n; i++) {
        cin>>x>>ara1[i];
        if(a<x ) {
            a=x;
            ia=i;
        }
    }
    sort(ara1+1,ara1+n+1);
    int ninjamoves=0;
    for(int i=n; i>=1; i--) {
        if(ara1[i]>=a) {
            ninjamoves++;
            m-=ara1[i];
            if(m<=0) {
                cout<<ninjamoves<<endl;
                return 0;
            }
        }
    }
    ninjamoves+=(m/a);
    if(m%a){
        ninjamoves++;
    }
    cout<<ninjamoves<<endl;
}


Measured memory_bytes: 1024
#include<deque>
#include<list>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<vector>
#include<algorithm>
#include<string>
#include<iostream>
#include<sstream>
#include<cmath>
#include<cstdio>
using namespace std;
struct S{
  char s[11];
};
int b[10],n,m;
vector<int> a[10],x,y,q,r;
char t[11],u[11];
vector<S> s;
int fi(int p){
  int i,j;
  if(p==n){
    for(i=0;i<m;++i){
      if(q[i]!=x[i]||r[i]!=y[i])
	break;
    }
    if(i==m){
      if(u[0]=='\0')
	copy(t,t+11,u);
      else
	return 1;
    }
  }else{
    for(i=0;i<10;++i){
      if(b[i]){
	int fl=-1;
	for(j=0;j<m;++j){
	  if(0){
	  }else if(s[j].s[p]-'0'==i){
	    ++q[j];
	    if(q[j]>x[j])
	      fl=0;
	  }else if(a[i][j]){
	    ++r[j];
	    if(r[j]>y[j])
	      fl=0;
	  }
	}
	if(fl){
	  b[i]=0;
	  t[p]='0'+i;
	  if(fi(p+1))
	    return 1;
	  b[i]=-1;
	}
	for(j=0;j<m;++j){
	  if(0){
	  }else if(s[j].s[p]-'0'==i){
	    --q[j];
	  }else if(a[i][j]){
	    --r[j];
	  }
	}
      }
    }
  }
  return 0;
}
int main(){
  int i,j;
  while(cin>>n>>m,n||m){
    S c;
    s.assign(m,c);
    x.assign(m,0);
    y.assign(m,0);
    for(i=0;i<10;++i)
      a[i].assign(m,0);
    for(i=0;i<m;++i){
      cin>>s[i].s>>x[i]>>y[i];
      for(j=0;j<n;++j)
	a[s[i].s[j]-'0'][i]=-1;
    }
    fill(b,b+10,-1);
    fill(t,t+11,0);
    fill(u,u+11,0);
    q.assign(m,0);
    r.assign(m,0);
    if(fi(0)||u[0]=='\0')
      cout<<"NO"<<endl;
    else
      cout<<u<<endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include<algorithm>
#include<iomanip>
#include<iostream>
#include<map>
#include<map>
#include<set>
#include<stack>
#include<string>
#include<vector>
#include<bitset>
#include<cmath>
using namespace std;
#define FOR(i,a,b) for(int i=(a); i<int(b); ++i)
#define RFOR(i,a,b) for(int i=(b)-1; i>=int(a); --i)
#define rep(i,n) FOR(i,0,n)
#define rep1(i,n) FOR(i,1,int(n)+1)
#define rrep(i, n) RFOR(i, 0, n)
#define rrep1(i, n) RFOR(i, 1, int(n) + 1)
#define all(c) begin(c), end(c)
#define al(d) d.begin(),d.end()
using namespace std;
template <typename T>
void putv(vector<T>& V){
	// cout << "The elements in the vector are: " << endl;
	for(auto x: V)
		cout << x << " ";
	cout << endl;
}
template <class T>
vector<T> getv(int n){
	vector<T> vec;
	rep(i,n){
		T input;
		cin >> input;
		vec.emplace_back(input);
	}
	return vec;
}
using AdjList = vector<vector<int>>;
using Weight = int;
using Flow = int;
struct Edge {
	int src, dst;
	Weight weight;
	Flow cap;
	Edge() : src(0), dst(0), weight(0) {}
	Edge(int s, int d, Weight w) : src(s), dst(d), weight(w) {}
};
using Edges = std::vector<Edge>;
using Graph = std::vector<Edges>;
using Array = std::vector<Weight>;
using Matrix = std::vector<Array>;

void add_edge(Graph &g, int a, int b, Weight w = 1) {
	g[a].emplace_back(a, b, w);
	g[b].emplace_back(b, a, w);
}
void add_arc(Graph &g, int a, int b, Weight w = 1) { g[a].emplace_back(a, b, w); }

// Recieve edge(=(int,int)) as an adj list.
AdjList getadj(int N, int M){
	// Initialize all lists of the graph as a empty vector.
	vector<int> init;
	vector<vector<int>> graph(N,init);

	rep(i,M){
		int a, b;
		cin >> a >> b;
		graph[a-1].emplace_back(b-1);
		graph[b-1].emplace_back(a-1);
	}
// rep(i,N)
// 	putv(graph[i]);
	return graph;
}

long long Manhattan_dist(long long x1, long long y1, long long x2, long long y2){return abs(x1-x2) + abs(y1-y2);}

void out(bool ans){
	if(ans == true) cout << "yes" << endl;
	else cout << "no" << endl;
}
void Out(bool ans){
	if(ans == true) cout << "Yes" << endl;
	else cout << "No" << endl;
}
void OUT(bool ans){
	if(ans == true) cout << "YES" << endl;
	else cout << "NO" << endl;
}
unsigned long long gcd(const unsigned long long a, const unsigned long long b){
	return (b==0) ? a : gcd(b,a%b);
}

int main(){
	int N;
	cin >> N;
	vector<vector<int>> F,P;
	vector<int> vec;
	rep(i,N){
		vec = getv<int>(10);
		F.emplace_back(vec);
	}
	rep(i,N){
		vec = getv<int>(11);
		P.emplace_back(vec);
	}
	int max = -1e9;
	int sum = 0;
	int cntr[N] = {};
	for(int num=1; num<1024; num++){
		string joisino = bitset<10>(num).to_string();
		rep(i,N){
			rep(j,10) if(F[i][j]==1 && joisino[j]=='1') cntr[i]++;
			sum += P[i][cntr[i]];
		}
		if(sum > max) max = sum;
		rep(i,N) cntr[i] = 0;
		sum = 0;
	}
	cout << max << endl;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
typedef long long ll;
ll n,m,MOD=1e9+7,a,b,ans,bik[2000001],k,tw[2000001];
string s;
ll f(ll x,ll y){
    if(y==0)return 1;
    if(y%2==0)return f(x,y/2)*f(x,y/2)%MOD;
    return x*f(x,y-1)%MOD;
}
ll comb(ll x, ll y){
    return bik[x]*f(bik[x-y],MOD-2)%MOD*f(bik[y],MOD-2)%MOD;
}
int main(void){
    cin>>k>>s;
    tw[0]=1;
    for(int i=1;i<=2000000;i++){
        tw[i]=25*tw[i-1];
        tw[i]%=MOD;
    }
    bik[0]=1;
    for(ll i=1;i<=2000000;i++){
        bik[i]=bik[i-1]*i;
        bik[i]%=MOD;
    }
    n=s.size();
    for(ll i=n;i<=n+k;i++){
        ans+=tw[n+k-i]*comb(n+k,i);
        ans%=MOD;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 35576
// vjudge 259706 D
#include <cstdio>
#include <algorithm>
#include <vector>
const int MAXN = 510;

std::vector<int> T[MAXN];
int N, M, Q;

namespace FastIO {
	template <typename T>
	void read(T & x) {
		x = 0; register char ch = getchar();
		for (; ch < '0' || ch > '9'; ch = getchar());
		for (; ch >= '0' && ch <= '9'; x = (x << 3) + (x << 1) + (ch ^ '0'), ch = getchar());
	}
}

int main() {
	using FastIO::read;
	read(N), read(M), read(Q);
	for (int i = 0, Li, Ri; i < M; i++) {
		read(Li), read(Ri);
		T[Li].push_back(Ri);
	}
	for (int i = 1; i <= 500; i++) std::sort(T[i].begin(), T[i].end());
	for (int i = 0, l, r; i < Q; i++) {
		read(l), read(r);
		int ans = 0;
		for (; l <= r; l++) {
//			printf("l=%d ?%d\n", l, std::upper_bound(T[l].begin(), T[l].end(), r) == T[l].end());
			ans += std::upper_bound(T[l].begin(), T[l].end(), r) - T[l].begin();
		}
		printf("%d\n", ans);
	}
	return 0;
}

Measured memory_bytes: 2304
#include<iostream>
#include<algorithm>
using namespace std;
int main() {
	int a, b, c, d, n = 0, ans = 0, ans2 = 0;
	string s;
	cin >> n;
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= n; j++) {
			if (i <= j)continue;
			else if (i % 2 == 0) {
				if (j % 2 == 1)ans++;
			}
			else if(i%2==1){
				if (j % 2 == 0)ans++;
			}

		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from math import *
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
# import numpy as np
sys.setrecursionlimit(int(pow(10,6)))
# sys.stdin = open("sort.in", "r")
# sys.stdout = open("out.txt", "w")
mod = int(pow(10, 9) + 7)
mod2 = 998244353
def data(): return sys.stdin.readline().strip()
def out(*var, end="\n"): sys.stdout.write(' '.join(map(str, var))+end)
def l(): return list(sp())
def sl(): return list(ssp())
def sp(): return map(int, data().split())
def ssp(): return map(str, data().split())
def l1d(n, val=0): return [val for i in range(n)]
def l2d(n, m, val=0): return [l1d(n, val) for j in range(m)]

# @lru_cache(None)
t=1
# t=int(input())
for _ in range(t):
    a=l()[0]
    print(a+a*a+a*a*a)




Measured memory_bytes: 10632
k = int(input())
import math
from functools import reduce
def gcd(*numbers):
    return reduce(math.gcd, numbers)
def gcd_list(numbers):
    return reduce(math.gcd, numbers)
ans = 0
for a in range(1,k+1):
    for b in range(1,k+1):
        for c in range(1,k+1):
            ans += gcd(a,b,c)
print(ans)

Measured memory_bytes: 69568
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define BOOST {ios_base::sync_with_stdio(false);cin.tie(NULL);}

typedef long long ll;

vector<int> dp(100000,-1);
int cost(vector<int> &h,int k,int n)
{
    if(dp[n]!=-1)
        return dp[n];
    if(n<=0)
        return 0;
    int cst = INT32_MAX;
    for(int i=n-1;i>=0 && i>=n-k;i--)
    {
        cst = min(cst,cost(h,k,i)+abs(h[n]-h[i]));
    }
    return dp[n] = cst;
}
int main()
{
    BOOST
    int n,k;
    cin>>n>>k;
    vector<int> h(n,0);
    for(int i=0;i<n;i++)cin>>h[i];
    cout<<cost(h,k,n-1)<<'\n';
    return 0;
}

Measured memory_bytes: 11824
from collections import Counter

def pr(s):
    c=0
    while 1:
        b=s
        t=Counter(s)
        s=[t[i] for i in s]
        c+=1
        if b==s:break
    return s,c-1

while 1:    
    le=int(input())
    if not le:break
    s=list(map(int,input().split()))
    s,c=pr(s)
    print(c)
    print(" ".join(map(str,s)))


Measured memory_bytes: 6000
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
using Graph=vector<vector<int>>;
using edge= struct{int to;ll cost;};


template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}

int n,m;
ll mod=1000000007;

int main(){
  int n,m;cin>>n>>m;
  VL a(m);
  VL dp(n+1);
  dp[0]=1;
  REP(i,m){
    cin>>a[i];
    a[i]=a[i];
  }
  REP(i,n+1){
    dp[i]=1;
  }
  REP(i,m){
    dp[a[i]]=-1;
  }
  if(dp[1]==-1){
    dp[1]=0;
  }
  else{
    dp[1]=1;
  }
  for(int i=2;i<n+1;i++){
    if(dp[i]==-1){
      dp[i]=0;
      continue;
    }
    dp[i]=dp[i-1]+dp[i-2];
    if(dp[i]>mod){
      dp[i]=dp[i]%mod;
    }
  }
cout<<dp[n]<<endl;
}




Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <string>
#include <cstdlib>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <stack>
#include <math.h>
#define rep(i, n) for(int i = 0; i < (n); ++i)
using namespace std;
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 long long INF = 1LL << 60;

// --------write my code!!!!!----------//

int main(){
    int n; cin >> n;
    if(n==3 || n==5 || n==7) cout << "YES" << endl;
    else cout << "NO" << endl;
}


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

int main(){
  int n,x;
  cin >> n >> x;
  vector<int> l;
  for(int i = 0;i < n;i++){
    int a;
    cin >> a;
    l.push_back(a);
  }
  int count = 1;
  int length = 0;
  for(int i = 0;i < n;i++){
    length += l[i];
    if(length > x){
      break;
    }
    else count++;
  }
  cout << count << endl;
}


Measured memory_bytes: 256