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

using namespace std;
typedef long long ll;

int main() {
    ll n, k;
    scanf("%lld%lld", &n, &k);
    vector<int> a(n + 1);
    for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
    vector<bool> vis(n + 1);
    vector<int> idx(n + 1);
    int l1 = 0, p = 1;
    while (k && !vis[p]) {
        idx[l1] = p;
        vis[p] = 1, l1++, k--, p = a[p];
    }
    int l2 = 0;
    while (k && vis[p]) {
        idx[l2] = p;
        vis[p] = 0, l2++, p = a[p];
    }
    printf("%d\n", k == 0 ? p : idx[k % l2]);
}


Measured memory_bytes: 4860
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <functional>
#include <queue>
#include <string>
#include <cstring>
#include <numeric>
#include <cstdlib>
#include <cmath>
#include <map>
using namespace std;

typedef long long ll;

#define INF 10e17 // 4倍しても(4回足しても)long longを溢れない
#define rep(i,n) for(int i=0; i<n; i++)
#define rep_r(i,n,m) for(int i=m; i<n; i++)
#define END cout << endl
#define MOD 1000000007
#define pb push_back
#define sorti(x) sort(x.begin(), x.end())
#define sortd(x) sort(x.begin(), x.end(), std::greater<int>())

int main() {
  string a,b,c;
  int n;
  cin >> n;
  cin >> a;
  cin >> b;
  cin >> c;
  ll ans = 0;
  for (int i = 0; i < n; ++i) {
    map<char, int> mp;
    mp[a[i]] += 1;
    mp[b[i]] += 1;
    mp[c[i]] += 1;
    vector<int> vec;
    for (auto itr : mp) {
      vec.push_back(itr.second);
    }
    sortd(vec);
    ans += 3 - vec[0];
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
def main():
    _, W, *C = map(int, open(0).read().split())
    dp = [0]*(W+1)
    for v, w in zip(*[iter(C)]*2):
        for i in range(W-w, -1, -1):
            d_new = dp[i]+v
            if dp[i+w] < d_new:
                dp[i+w] = d_new
    print(max(dp))

if __name__ == '__main__':
    main()



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

int main() {
    string s;
    cin >> s;
    if (s[0] != s[1] && s[1] != s[2] && s[2] != s[3]) {
        cout << "Good" << endl;
    } else {
        cout << "Bad" << endl;
    }
    return 0;
}

Measured memory_bytes: 3592
#include <iostream>
#include <vector>
#include <math.h>

using namespace std;

int main()
{
	int N;
	int ave = 0, ans = 0;
	cin >> N;

	vector<int> a(N);

	for (int i = 0; i < N; i++)
	{
		cin >> a[i];
		ave += a[i];
	}
	ave = round(double(ave) / double(N));

	for (int i = 0; i < N; i++)
	{
		ans += pow(a[i] - ave, 2);
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
const int Y = 1010;
const int M = 15;
const int D = 25;
#define REP(i, j) for(int i = 0; i < j; i++)
#define FOR(i, j, k) for(int i = j; i < k; i++)

int main(){
    int ans[Y][M][D];
    REP(i, Y) REP(j, M) REP(k, D) ans[i][j][k] = 0;
    for(int i = 999; i >= 1; i--){
        for(int j = 10; j >= 1; j--){
            for(int k = 20; k >= 1; k--){
                if(k == 20 && i % 3 != 0 && j % 2 == 0) continue;

                int bef;
                if(ans[i][j][k + 1] != 0) bef = ans[i][j][k + 1];
                else if(j != 10) bef = ans[i][j + 1][1];
                else bef = ans[i + 1][1][1];

                ans[i][j][k] = bef + 1;
            }
        }
    }

    int n; cin >>n;
    REP(z, n){
        int y, m, d;
        cin >>y >>m >>d;
        cout <<ans[y][m][d] <<endl;
    }
    return 0;
}

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

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
using pll = pair<ll,ll>;

#define INF (1LL << 60)
#define MOD 1000000007
#define PI 3.14159265358979323846

#define REP(i,m,n) for(ll (i)=(m),(i_len)=(n);(i)<(i_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define PR(x) cout << (x) << endl
#define PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define REV(x) reverse(ALL((x)))
#define ASC(x) sort(ALL((x)))
#define DESC(x) ASC((x)); REV((x))
#define pb push_back
#define eb emplace_back

int main()
{
    ll N;
    cin >> N;

    ll maxcnt = 0, max = 1;
    REP(i,1,N+1) {
        ll cnt = 0;
        ll n = i;
        while(true) {
            if(n % 2 == 1) break;
            else {
                n /= 2;
                ++cnt;
            }
        }
        if(maxcnt < cnt) {
            maxcnt = cnt;
            max = i;
        }
    }
    PR(max);

    return 0;
}

/*



*/

Measured memory_bytes: 3620
class Dice:
	def __init__(self, ls):
		self.ls = ls
		self.now = 0
	
	def roll(self, direction):
		if direction == 'E': pat = [5, 2, 0, 3]
		elif direction == 'N': pat = [5, 4, 0, 1]
		elif direction == 'W': pat = [5, 3, 0, 2]
		elif direction == 'S': pat = [5, 1, 0, 4]

		tmp = self.ls[pat[0]]
		for i in range(4):
			try:
				self.ls[pat[i]] = self.ls[pat[i+1]]
			except(IndexError):
				pass
		self.ls[pat[-1]] = tmp
		
	def top(self):
		return self.ls[self.now]

dice = Dice(list(input().rstrip().split()))
for cmd in list(input().rstrip()):
	dice.roll(cmd)
print(dice.top())


Measured memory_bytes: 5564
#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;

int main(){
    int n; cin >> n;
    vector<int> nums(n);
    
    for(auto &val : nums) cin >> val;
    reverse(nums.begin(), nums.end());
    
    for(int i = 0; i < n-1; i++){
        cout << nums[i] << " ";
    }
    cout << nums[n-1] << endl;
    
    return 0;
}

Measured memory_bytes: 3084
/**
 *    author:  morato
 *    created: 06.09.2020 23:19:47
**/
#include <bits/stdc++.h>

using namespace std;

void shift(char& ch, int k) {
  while (k--) {
    ch++;
    if (ch > 'Z') {
      ch = 'A';
    }
  }
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s;
  int k;
  cin >> k >> s;
  for (char& c : s) shift(c, k);
  cout << s << '\n';
  return 0;
}

Measured memory_bytes: 3660
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define fi first
#define se second
#define pb push_back
using namespace std;

int h,w,ans;
char mdo[30][30];
bool use[30][30];
int dx[]={1,-1,0,0};
int dy[]={0,0,1,-1},myAns;
queue< pair< int , pair< int , int > > > q;

int fn( int f , int c ){

    while( !q.empty() ) q.pop();
    use[f][c] = true;
    q.push( { 0 , { f ,c } } );
    myAns = 0;

    while( !q.empty() ){
        auto nd = q.front();
        q.pop();

        nd.fi++;
        for(int i=0; i<4; i++){
            nd.se.fi+=dx[i];
            nd.se.se+=dy[i];

            if( nd.se.fi >= 0 && nd.se.fi < h && nd.se.se >= 0 && nd.se.se < w && !use[ nd.se.fi ][ nd.se.se ] && mdo[ nd.se.fi ][ nd.se.se ]=='.' ){
                use[ nd.se.fi ][ nd.se.se ] = true;
                q.push( nd );
                myAns = nd.fi;
            }


            nd.se.fi-=dx[i];
            nd.se.se-=dy[i];
        }
    }

    return myAns;
}

int main()
{

    ios_base::sync_with_stdio(false);
    cin.tie(0);

    cin >> h >> w;
    for(int i=0; i<h; i++) for(int j=0; j<w; j++) cin >> mdo[i][j];

    for(int i=0; i<h; i++){
        for(int j=0; j<w; j++){
            if( mdo[i][j]=='.' ){
                for(int x=0; x<h; x++) for(int y=0; y<w; y++) use[x][y] = false;
                ans = max( ans , fn( i , j ) );
            }
        }
    }

    cout << ans;

    return 0;
}


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

int main()
{
  int n;
  cin >> n;
  
  n %= 10;
  if (n == 3) cout << "bon" << endl;
  else if ((n == 0) || (n == 1) || (n == 6) || (n == 8)) cout << "pon" << endl;
  else cout << "hon" << endl;
  
  return 0;
}

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

using namespace std;

typedef long long int Int;

int F;
int A,B,C,D,E;
int Create[31];

int W,S;

void Sugar(void) {
    float maxi = 0.0;

    for(int i = 0;i <= F/100;i++) {
        if(Create[i]) {
            for(int a = 0;C*a <= E*i;a++) {
                for(int b = 0;D*b <= E*i;b++) {
                    if(C*a+D*b > E*i || i*100+(C*a+D*b) > F)
                        break;
                    if((100.0*(C*a+D*b))/(i*100.0+(C*a+D*b)) >= maxi) {
                            maxi = (100.0*(C*a+D*b))/(i*100.0+(C*a+D*b));
                            W = i*100;
                            S = C*a+D*b;
                    }
                }
            }
        }
    }

    return;
}

int main(void) {
    cin>>A>>B>>C>>D>>E>>F;

    for(int i = 0;i <= 30;i++) {
        for(int j = 0;j <= 30;j++) {
            if(100*A*i + 100*B*j > F)
                break;
            Create[(100*A*i+100*B*j)/100] = 1;
        }
    }

    Sugar();

    cout<<W+S<<" "<<S<<endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for(int i=0;i<(int)n;i++)
#define PI acos(-1)
#define fast_io ios_base::sync_with_stdio(false) ; cin.tie(0); cout.tie(0);
ll mod=1e9+7;

ll rep_pow(ll a, ll b){//繰り返し2乗法
    if(b==0) return 1;
    else if(b%2==0){
        ll memo = rep_pow(a, b/2);
        return memo*memo%mod;
    }else{
        return rep_pow(a, b-1)*a%mod;
    }
}

ll nCr(ll n, ll r){//mod逆元使ったnCr
    ll ret=1;
    rep(i,r){
        ret *= n-i;//分子
        ret %= mod;
        ret *=rep_pow(r-i, mod-2);//mod逆元によりr!で割ると同値
        ret %= mod;
    }
    return ret;
}
ll gcd(ll a, ll b){ if(b==0) return a; return gcd(b, a%b);}



int main(){
    fast_io

    int n;cin>>n;
    ll a, b;
    vector<pair<ll, ll>> p;
    rep(i,n) {
        cin>>a>>b;
        p.push_back(make_pair(a, b));
    }
    sort(p.begin(), p.end());
    cout<<p[n-1].first+p[n-1].second<<endl;
    return 0;
}

Measured memory_bytes: 2420
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <cmath>
#include <set>
#include <algorithm>
#include <iomanip>

typedef long long ll;
const ll MOD = 1e9 + 7;
const long long INF = 1LL<<60;
const double PI=3.14159265358979323846;
const int NMAX=100005;
using namespace std;


int main(){
    int n, k;
    cin >> n >> k;
    vector<int> kk(101,0);
    for(int i = 0; i < k; i++){
        int d;
        cin >> d;
        for(int j = 0; j < d; j++){
            int a;
            cin >> a;
            kk[a] = 1;
        }
    }

    int ans = 0;
    for(int i = 1; i <= n; i++){
        if(kk[i] == 0) ans++;
    }

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

Measured memory_bytes: 3628
#include <stdio.h>
#define N 100
#define NIL -1
#define INF 2000000000
int n;
int main(){
  int i,j,u,v,min=INF,count=0;
  int G[N][N];
  int pi[N];
  int d[N];
  int color[N];
  scanf("%d",&n);
  
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      scanf("%d",&G[i][j]);
    }
  }
  
  for(u=0;u<n;u++){
    d[u] = INF;
    pi[u] = NIL;
    color[u] = 0;
  }

  d[0] = 0;
  
  while(1){
    min = INF;
    for(i=0;i<n;i++){
      if(color[i] != 1 && d[i] < min){
	min = d[i];
	u = i;
      }
    }

    if(min == INF){
      break;
    }

    color[u] = 1;

    for(v=0;v<n;v++){
      if(G[u][v] != -1 && color[v] != 1 && G[u][v] < d[v]){
	pi[v] = u;
	d[v] = G[u][v];
      }
    }
  }

  for(i=0;i<n;i++){
    count += d[i];
  }

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



Measured memory_bytes: 2052
#include "bits/stdc++.h"
using namespace std;
const int INF = 1001001001;
int main() {
	int N,M,L;
	cin >> N >> M >>L; 
	vector<vector<int>> dist(N, vector<int>(N, INF));
	for (int n = 0; n < N; ++n) {
		dist[n][n] = 0;
	}
	for (int n = 0;n<M;++n) {
		int a, b, c;
		cin >> a >> b >> c;
		--a;
		--b; 
		dist[b][a] = c;
		dist[a][b] = c;
	}
	//わーしゃるふろいど
	for (int k = 0;k<N;++k) {
		for (int i = 0;i<N;++i) {
			for (int j = 0;j<N;++j) {
				dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
			}
		}
	}
	vector<vector<int>> dist2(N, vector<int>(N, INF));
	for (int i = 0; i < N; ++i) {
		for (int j = 0;j < N; ++j) {
			if (dist[i][j] <= L) {
				dist2[i][j] = 1;
			}
		}
	}
	//わーしゃるふろいど
	for (int k = 0; k < N; ++k) {
		for (int i = 0; i < N; ++i) {
			for (int j = 0; j < N; ++j) {
				dist2[i][j] = min(dist2[i][j], dist2[i][k] + dist2[k][j]);
			}
		}
	}

	int Q;
	cin >> Q;
	for (int n = 0;n<Q;++n) {
		int s, t;
		cin >> s >> t;
		--s;
		--t;
		int ans = dist2[s][t];
		if (INF == ans) {
			cout << -1 <<endl;
		}
		else{
			cout << ans -1<<endl;
		}
	}
	return 0;
}

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


#define li          long long int
#define rep(i,to)   for(li i=0;i<((li)(to));i++)
#define repp(i,start,to)    for(li i=(li)(start);i<((li)(to));i++)
#define pb          push_back
#define sz(v)       ((li)(v).size())
#define bgn(v)      ((v).begin())
#define eend(v)     ((v).end())
#define allof(v)    (v).begin(), (v).end()
#define dodp(v,n)       memset(v,(li)n,sizeof(v))
#define bit(n)      (1ll<<(li)(n))
#define mp(a,b)     make_pair(a,b)
#define rin rep(i,n)
#define EPS 1e-12
#define ETOL 1e-8
#define MOD 1000000007
typedef pair<li, li> PI;

#define INF bit(60)

#define DBGP 1


#define idp if(DBGP)
#define F first
#define S second
#define p2(a,b)     idp cout<<a<<"\t"<<b<<endl
#define p3(a,b,c)       idp cout<<a<<"\t"<<b<<"\t"<<c<<endl
#define p4(a,b,c,d)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<endl
#define p5(a,b,c,d,e)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<endl
#define p6(a,b,c,d,e,f)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<endl
#define p7(a,b,c,d,e,f,g)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<endl
#define p8(a,b,c,d,e,f,g,h)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<endl
#define p9(a,b,c,d,e,f,g,h,i)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<endl
#define p10(a,b,c,d,e,f,g,h,i,j)        idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<"\t"<<j<<endl
#define foreach(it,v)   for(__typeof((v).begin()) it=(v).begin(); it!=(v).end(); ++it)
#define p2p(x)      idp p2((x).F, (x).S)
#define dump(x,n)   idp{rep(i,n){cout<<x[i]<<" ";}puts("");}
#define dump2(x,n)  idp{rep(i,n){cout<<"["<<x[i].F<<" , "<<x[i].S<<"] ";}puts("");}
#define dumpi(x)    idp{foreach(it, x){cout<<(*it)<<" ";}puts("");}
#define dumpi2(x)   idp{foreach(it, x){cout<<"["<<(it)->F<<" , "<<(it)->S<<"] ";}puts("");}

#define read2d(a,w,h)   rep(i,h)rep(j,w)cin>>a[i][j]
#define dump2d(a,w,h)   rep(i,h){rep(j,w)cout<<a[i][j]<<" ";puts("");}

typedef pair<li, li> PI;


li n, k;
li a[200200];

int main() {
    cin >> n >> k;
    rin{
        cin >> a[i];
    }
    repp(i, k, n) {
        if (a[i] > a[i - k]) {
            puts("Yes");
        } else {
            puts("No");
        }
    }

    return 0;
}

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

using namespace std;

#define allof(x) (x).begin(), (x).end()

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;



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

    int N, i;
    cin >> N >> i;
    cout << N - i + 1;

}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
const int mod = 1e9 + 7;

int main()
{
    long long n, m;
    cin >> n >> m;
    if( n > m ) swap(n, m);
    if(m == n + 1)
    {
        long long res = 1;
        while(n > 1)
        {
            res *= n;
            res %= mod;
            n--;
        }
        res *= res;
        res %= mod;
        res *= m;

        printf("%lld\n", res % mod);
    }

    else if(n == m)
    {
        long long res = 1;
        while(n > 1)
        {
            res *= n;
            res %= mod;
            n--;
        }
        res *= res;
        res %= mod;
        printf("%lld\n", (2 * res) % mod ) ;
    }
    else puts("0");

}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <functional>
#include <iostream>
#include <string>
#include <vector>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repR(i, n) for(int i = (n) - 1; i > -1; i--)
#define rep1(i, n) for(int i = 1; i < (int)(n + 1); i++)
#define rep1R(i, n) for(int i = (n); i > 0; i--)
typedef long long ll;
typedef unsigned long long ull;
using namespace std;

int main() {
  vector<int> A(3); cin >> A[0] >> A[1] >> A[2];
  int ans1 = abs(A[1] - A[0]) + abs(A[2] - A[1]);
  int ans2 = abs(A[2] - A[0]) + abs(A[1] - A[2]);
  int ans3 = abs(A[0] - A[1]) + abs(A[2] - A[0]);
  int ans4 = abs(A[2] - A[1]) + abs(A[0] - A[2]);
  int ans5 = abs(A[0] - A[2]) + abs(A[1] - A[0]);
  int ans6 = abs(A[1] - A[2]) + abs(A[0] - A[1]);
  cout << min({ans1, ans2, ans3, ans4, ans5, ans6}) << endl;
  return 0;
}


Measured memory_bytes: 256
n = list(input())
li = []
for i in range(len(n)):
    li.append(int(n[i]))
if li[-1] == 2 or li[-1] == 4 or li[-1] == 5 or li[-1] == 7 or li[-1] == 9:
    print("hon")
elif li[-1] == 0 or li[-1] == 1 or li[-1] == 6 or li[-1] == 8:
    print("pon")
else:
    print("bon")

Measured memory_bytes: 9196
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <cstring>

using namespace std;
// ascending order
#define vsort(v) sort(v.begin(), v.end())
// descending order
#define vsort_r(v) sort(v.begin(), v.end(), greater<int>())
#define vunique(v) unique(v.begin(), v.end())
#define mp make_pair
#define ts(x) to_string(x)
#define rep(i, a, b) for(int i = (int)a; i < (int)b; i++)
#define repm(i, a, b) for(int i = (int)a; i > (int)b; i--)
#define bit(a) bitset<8>(a)
#define des_priority_queue priority_queue<int, vector<int>, greater<int> >
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1e18;

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

	int a[3];
	rep(i, 0, 3) cin >> a[i];
	int arr[] = {0, 1, 2};
	int ans = 1000000;

	do {
		int tmp = 0;
		rep(i, 1, 3) {
			tmp += abs(a[arr[i]] - a[arr[i - 1]]);
		}
		ans = min(ans, tmp);
	} while(next_permutation(arr, arr + 3));
	cout << ans << endl;


}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <queue>
#include <utility>
using namespace std;

#define rep2(x,from,to) for(int x=(from);(x)<(to);(x)++)
#define rep(x,to) rep2(x,0,to)
int n, q;
queue<pair<string, int> > qu;
int main() {
	cin >> n >>	q;
	rep(i,n) {
		string s;
		int t;
		cin >> s >> t;
		qu.push(make_pair(s, t));	
	}
	int time = 0;
	while(!qu.empty()) {
		pair<string, int> p = qu.front();
		qu.pop();
		if(p.second > q) {
			p.second -= q;
			time += q;
			qu.push(p);
		} else {
			time += p.second;
			cout << p.first << " " << time << endl;
		}
	}
	return 0;
}



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

using namespace std;

const int INF = 1e8;
struct Edge {
    int src, dst;
    Edge(int f, int t) :
        src(f), dst(t) {}
};

using Edges = vector<Edge>;
using Graph =  vector<Edges>;
using Array = vector<int>;
using Matrix = vector<Array>;

// g[i][i] = 0, g[i][j] = INF ((i,j) \nin E)
void WarshallFloyd(Matrix &dist) {
    int n = dist.size();

    for (int k = 0; k < n; ++k)
        for (int i = 0; i < n; ++i)
            for (int j = 0; j < n; ++j) {
                if (dist[i][k] == INF || dist[k][j] == INF)
                    continue;
                if (dist[i][j] > dist[i][k] + dist[k][j])
                    dist[i][j] = dist[i][k] + dist[k][j];
            }
}


bool Augment(const Graph& g, int u,
             vector<int>& matchTo, vector<bool>& visited) {
    if (u < 0)
        return true;

    for (auto e : g[u])
        if (!visited[e.dst]) {
            visited[e.dst] = true;
            if (Augment(g, matchTo[e.dst], matchTo, visited)) {
                matchTo[e.src] = e.dst;
                matchTo[e.dst] = e.src;
                return true;
            }
        }

    return false;
}

// ?????¨??°??????G=(A;B, E)????????§??????????????°????±???????
// A:[0,L-1], B:[L,g.size()-1]
int BipartiteMatching(const Graph& g, int L) {
    const int n = g.size();
    Edges matching;
    vector<int> matchTo(n, -1);
    int match = 0;

    for (int u = 0; u < L; ++u) {
        vector<bool> visited(n);
        if (Augment(g, u, matchTo, visited))
            ++match;
    }

    for (int u = 0; u < L; ++u)
        if (matchTo[u] >= 0) // make explicit matching
            matching.emplace_back(Edge(u, matchTo[u]));

    return match;
}

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

    int n, m, l;

    while (cin >> n >> m >> l) {
        if (n == 0 && m == 0 && l == 0)
            break;

        // Caluculate all pair shortest distance
        int u, v, d;
        Matrix dist(n, Array(n, INF));
        for (int i = 0; i < m; ++i) {
            cin >> u >> v >> d;
            dist[u][v] = dist[v][u] = d;
        }
        for (int i = 0; i < n; ++i)
            dist[i][i] = 0;
        WarshallFloyd(dist);

        // Find Minimum Path Cover
        Graph g(2 * l);
        vector<pair<int, int>> tp(l);
        for (int i = 0; i < l; ++i)
            cin >> tp[i].second >> tp[i].first;

        sort(tp.begin(), tp.end());

        for (int i = 0; i < l; ++i)
            for (int j = i + 1; j < l; ++j)
                if (tp[i].first + dist[tp[i].second][tp[j].second] <= tp[j].first)
                    g[i].emplace_back(Edge(i, j + l));

        cout << l - BipartiteMatching(g, l) << '\n';
    }

    return 0;
}

Measured memory_bytes: 8164
// In god we trust
 
#include <bits/stdc++.h>
#include <chrono>
#include <algorithm>
#include <signal.h>
#include <thread>
 
#define pb push_back
#define fi first
#define se second
#define Vi vector<int>
#define Vb vector<bool>
#define Pi pair<int, int>
#define MP make_pair
#define MT make_tuple
#define Q queue
#define Qi Q<int>
#define INF 1000000000 
#define LINF 1000000000000000000
#define int long long
using namespace std;
using namespace std::chrono;



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

  int n, m;
  cin >> n >> m;
  int h[n];
  bool d[n];
  for (int i = 0; i < n; i++)
    d[i] = false;
  
  for (int i = 0; i < n; i++)
    cin >> h[i];
  for (int i = 0; i < m; i++){
    int a, b;
    cin >> a >> b;
    a--, b--;
    if (h[a] < h[b])
      d[a] = true;
    else if (h[a] > h[b])
      d[b] = true;
    else
      d[b] = true, d[a] = true;
  }

  int cnt = 0;
  for (int i = 0; i < n; i++)
    if (not d[i])
      cnt++;
  cout << cnt << endl;
  
}


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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
//const ull mod = 1e9 + 7;
const ll mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

// debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
  os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
  for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
  for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

// conversion number to bit
string num2bit(ll num, ll len){
  string bit = "";
  REP(i, len){
    bit += char('0'+(num>>i & 1));
  }
  return bit;
}

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

    ll a, b, c;
    cin >> a >> b >> c;

    ll x = 4*a*b;
    ll y = (c-a-b);

    if(y<0){
    	cout << "No" << endl;
    }else{
    	if(x<y*y) cout << "Yes" << endl;
    	else cout << "No" << endl;
    }
    return 0;
}

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

using namespace std;

typedef long long LL;
const int MOD = 1000000007;

int main(){
    int N, X;
    LL D;

    LL inv[2005] = {};
    inv[1] = 1;
    for(int i = 2; i < 2005; i++) {
        inv[i] = inv[MOD % i] * (MOD - MOD / i) % MOD;
    }

    while(cin >> N >> D >> X && N > 0) {

        static LL dp[2005][2005] = {};
        LL sum[2005] = {};

        dp[0][0] = 1;
        REP(i, N + 2) sum[i + 1] = sum[i] + dp[0][i];

        REP(i, N + 2) {
            REP(j, N + 2) {
                //dp[i + 1][j] = dp[i][j - 1] + dp[i][j - 2] + ... + dp[i][j - X + 1]
                //dp[i + 1][j] = sum[j] - sum[j - X + 1]
                dp[i + 1][j] = sum[j] - (j - X + 1 >= 0 ? sum[j - X + 1] : 0);
                dp[i + 1][j] += MOD;
                dp[i + 1][j] %= MOD;
            }
            REP(j, N + 2){
                sum[j + 1] = (sum[j] + dp[i + 1][j]);
                sum[j + 1] %= MOD;
            }
        }

        LL C = 1;
        LL ans = 0;

        for(int i = 1; i <= N && i <= D; i++) {
            // C(D, i) * dp[i][N]
            C *= (D - i + 1) % MOD;
            C %= MOD;
            C *= inv[i];
            C %= MOD;

            ans += C * dp[i][N] % MOD;
            ans %= MOD;
        }

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

Measured memory_bytes: 32568
#include <algorithm>
#include <cmath>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <cassert>
#include <functional>

using namespace std;

#define LOG(...) printf(__VA_ARGS__)
//#define LOG(...)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())
#define CLR(a) memset((a), 0 ,sizeof(a))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

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

int main() {
vector<int> numbers(5);
REP(i, 5){
	cin >> numbers[i];
}
RSORT(numbers);
cout << numbers[0] << " " << numbers[1] << " " << numbers[2] << " " << numbers[3] << " " << numbers[4] << endl;
}

Measured memory_bytes: 3080
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;
public class Main {
    static int gcd(int a, int b){
        if(a == 0){
            return b;
        }
        return gcd(b%a,a);
    }
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int arr[] = new int[n];
        for (int i = 0; i < arr.length; i++) {
            arr[i] = sc.nextInt();
        }
        int gcd = gcd(arr[0],arr[1]);
        if(gcd != 1) {
            for (int i = 2; i < n; i++) {
                gcd = gcd(gcd,arr[i]);
                if(gcd == 1) break;
            }
        }
        System.out.println(gcd);
    }
}

Measured memory_bytes: 50124
#include <iostream>
#include <stack>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <cstring>
#include <vector>
#include <cmath>
#include <utility>
#define ll long long
using namespace std;

int main() {
    int n,k;
    cin>>n>>k;
    if(n%k==0)
        cout<<0;
    else
        cout<<1;
    
}


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

typedef long long int ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<ll, ll> Pair;
typedef vector<Pair> VP;

#define MOD 1000000007
#define times(n) rep(_idx, n)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, s, n) for(int i = (int)(s); i < (int)(n); i++)
#define all(a) (a).begin(),(a).end()
#define in(a, l, r) (l <= a && a < r)
#define pb push_back
#define mk make_pair
#define out(x) cout << (x) << endl;
#define DU(x) cerr << #x << " = " << (x) << endl;

template<typename _Ty>ostream& operator << (ostream& ostr, const vector<_Ty>& v) {if (v.empty()) {ostr << "[]";return ostr;}ostr << "[" << v.front();for (auto itr = ++v.begin(); itr != v.end(); itr++) {ostr << ", " << *itr;}ostr << "]";return ostr;}

int main() {
    int N, M; cin >> N >> M;
    priority_queue<int> que; times(N) { int val; cin >> val; que.push(val); }
    
    times(M) {
        int val = que.top() / 2;
        que.pop();
        que.push(val);
    }
    long ans = 0;
    while(!que.empty()) { ans += que.top(); que.pop(); }
    out(ans);
}

Measured memory_bytes: 892
#include<bits/stdc++.h>
using namespace std;
int H,W;
int ans[100][100];
char ch;

int main(){
  cin>>H>>W;
  for(int i=0;i<H;i++){
    int cnt=-1;
    for(int j=0;j<W;j++){
      cin>>ch;
      if(ch=='c')cnt=0;
      else if(cnt!=-1)cnt++;
      if(j)cout<<' ';
      cout<<cnt;
    }
    cout<<endl;
  }
  return 0;
}

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

using namespace std;
typedef long long ll;

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    for(int i=1;i<=5;i++)
    {
        int x;
        cin >> x;
        if(x==0) cout << i << "\n";
    }
    return 0;
}


Measured memory_bytes: 3604
n,a,b=map(int,input().split())
mod=10**9+7

def nCmMOD(A,B,Mod):
    num,den=1,1
    for i in range(B):
        num*=(A-i)
        den*=(i+1)
        num%=Mod
        den%=Mod
    return (num*pow(den,Mod-2,Mod))%Mod

A=nCmMOD(n,a,mod)
B=nCmMOD(n,b,mod)

def power_func(a,n,p):
  bi=str(format(n,"b"))#2進表現に
  res=1
  for i in range(len(bi)):
    res=(res*res) %p
    if bi[i]=="1":
      res=(res*a) %p
  return res
An=power_func(2,n,mod)

print((An-1+mod*2-A-B)%mod)

Measured memory_bytes: 38512
import bisect
ans = 0
N = int(input())
a = list(map(int,input().split()))
b = [True for _ in range(N)]
c = [True for _ in range(N)]
a.sort()
digit = 40
y = 2 ** (digit+1) -1
while len(a)>1:
    if b[-1]==False:
        a.pop(-1)
        b.pop(-1)
        continue
    x = a.pop(-1)
    b.pop(-1)
    while x < 2**digit:
        digit -= 1
        y = 2 ** (digit+1) -1
    z = x^y
    z += 1
    ll =  bisect.bisect_left(a,z)
    rr =  bisect.bisect_right(a,z)
    if rr-ll>0:
        rr -= 1
        if b[ll]==False:
            pass
        elif b[rr]==True:
            b[rr]=False
            ans += 1
        else:
            lll = ll
            rrr = rr
            while rrr-lll>1:
                if b[(rrr+lll)//2]:
                    lll = (rrr+lll)//2
                else:
                    rrr = (rrr+lll)//2
            b[lll] = False
            ans += 1           
print(ans)

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

using namespace std;

typedef long long int ll;
#define pb push_back
#define ALL(a) (a).begin() , a.end()

int mod = 1e9 + 7;
int add(int a, int b){
	if(a + b >= mod)return a+ b - mod;
	return a + b;
}
int mul(int a, int b){
	return 1LL * a * b  % mod;
}
int const N = 100 * 1010;

/********************i**********************************/
void solve(){
	int n, m;
	cin >> n >> m;
	vector<vector<int>> dp(n+1, vector<int> (m + 1, 0));
	dp[0][1] = 1;
	for(int x = 0; x<n; x++){
		string s; cin >> s;
		for(int y = 0; y<m; y++){
			if(s[y] == '.'){
				dp[x+1][y+1] = add(dp[x][y+1], dp[x+1][y]);
			}
		}	
	}

	cout << dp[n][m];
}


/******************************************************/
int main()
{
	ios_base::sync_with_stdio(false);cin.tie(nullptr);
	int t;
	t = 1;
	// cin >> t;
	while(t--){
		solve();
	}
}

Measured memory_bytes: 4224
s = input()
iter = 0
if s[0] =="R"and s[1]=="R" and s[2]=="R":
  print(3)
elif s[0] =="R"and s[1]=="R":
  print(2)
elif s[1]=="R" and s[2]=="R":
  print(2)
elif s[0] =="R"or s[1]=="R" or s[2]=="R":
  print(1)
elif s[0] =="R"and s[2]=="R":
  print(1)
else:
  print(0)

Measured memory_bytes: 9132
#include "bits/stdc++.h"
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
*this << "[";
for (auto it = d.b; it != d.e; ++it)
*this << ", " + 2 * (it == d.b) << *it;
ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define cool ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define int  long long int
#define pb push_back
#define fe first
#define lb lower_bound 
#define ub upper_bound
#define pii pair<pair<int,int>,pair<int,int> >
#define se second
#define endl "\n"
#define pi pair<int, int>
#define mi          map<int,int>
#define mii         map<pi,int>
#define vi vector<int> 
#define vvi vector<vi>
#define bs   binary_search
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rep1(i,a,b) for(int i=a;i<=b;i++)	
#define all(c) (c).begin(),(c).end()
#define sz(x)       (int)x.size() 
#define PI 3.14159265358979323846

 const int N=2e5+5;

 int mod= 1e9+7;
 int dx[4]={0,0,+1,-1};
 int dy[4]={+1,-1,0,0};  
 
 
int po(int a, int b) {
	a %= mod;
	int res = 1;
	while (b > 0) {
		if (b & 1)
			res = (res * a) % mod;
		a =(a*a) % mod;
		b >>= 1;
	}
	 return res;	
   }


int k,n;


void solve() {
      cin>>k>>n;
      vi a(n,0);
      rep(i,0,n)
        cin>>a[i];
      sort(all(a));
      int mini=1e18,ans=0;
      rep1(i,-1000,1000) {
		    int yo=abs(k-i);
		    if(yo<mini && !(bs(all(a),i))) {
				  mini=yo;
				  ans=i;
				}
		  } 
		  
		  cout<<ans<<endl; 
		
    
 }

    
int32_t main() {
	cool;
	int t=1;
	//cin>>t;
	while(t--)
	  solve();

return 0;	   
}


Measured memory_bytes: 3624
#include<iostream>
#include<algorithm>
using namespace std;
long long n,m;
int main()
{

    cin>>n>>m;
        long long s[3];
         if(n<2||m<2)return 0;
        else if(n%3==0||m%3==0)
        cout<<0<<endl;
    else
    {
        long long r1=m/2;
        long long r2=m-r1;
        long long ans=1e11;
       for(int i=0;i<=n;i++)
       {
           s[0]=r1*(n-i);
           s[1]=r2*(n-i);
           s[2]=m*i;
           sort(s,s+3);
           ans=min(ans,s[2]-s[0]);
       }
        r1=n/2;
        r2=n-r1;
        for(int i=0;i<=m;i++)
        {
            s[0]=r1*(m-i);
            s[1]=r2*(m-i);
            s[2]=n*i;
            sort(s,s+3);
            ans=min(ans,s[2]-s[0]);
        }
        long long a1=m/3;
        long long a2=(m-a1)/2;
        long long a3=m-a1-a2;
        s[0]=a1*n;
        s[1]=a2*n;
        s[2]=a3*n;
        sort(s,s+3);
        ans=min(ans,s[2]-s[0]);
        a1=n/3;
        a2=(n-a1)/2;
        a3=n-a1-a2;
        s[0]=a1*m;
        s[1]=a2*m;
        s[2]=a3*m;
        sort(s,s+3);
        ans=min(ans,s[2]-s[0]);
        cout<<ans<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
import bisect


n = int(input())
A = [int(input()) for _ in range(n)]

def LIS2(A):
    n = len(A)
    INF = max(A)+10
    L = [INF]*n
    length = 0

    for i in range(n):
        ins_ind = bisect.bisect_left(L,A[i])
        if length == ins_ind:
            length += 1
        L[ins_ind] = A[i]
    
    return length,L

L , _ = LIS2(A)
print(L)






Measured memory_bytes: 10468
#include<cstdio>
#include<iostream>
using namespace std;
#define MAX 51

int A[50];
int n;

int solve (int i,int m){
    if(m == 0) return 1;
    else if(i >= n) return 0;

    int res = solve(i+1,m-A[i]) || solve(i+1,m);
    return res;
}
int main(){
    int q,m;
    int ans;
    cin >> n;
    for(int i=0;i<n;i++){
        cin >> A[i];
    }
    cin >> q;
    for(int i=0;i<q;i++){
        cin >> m;
        if(solve(0,m)) cout << "yes" << endl;
        else
        {
            cout << "no" << endl;
        }
    }
    return 0;
}


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

string divide[4] = {"dream", "dreamer", "erase", "eraser"};

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

  // 後ろから解くかわりにすべての文字列を「左右反転」する
  reverse(S.begin(), S.end());
  for (int i = 0; i < 4; ++i) reverse(divide[i].begin(), divide[i].end());

  // 端から切っていく
  bool can = true;
  for (int i = 0; i < S.size();) {
    bool can2 = false;
    for (int j = 0; j < 4; ++j) {
      string d = divide[j];
      if (S.substr(i, d.size()) == d) {
        can2 = true;
        i += d.size();
      }
    }
    if (!can2) {
      can = false;
      break;
    }
  }

  if (can)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
}


Measured memory_bytes: 512
#include <iostream>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <deque>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <map>
#include <stack>
#include <set>
#include <sstream>
#define IOS ios_base::sync_with_stdio(0); cin.tie(0);
#define mod 1000000007
#define eps 1e-6
#define ll long long
#define INF 0x3f3f3f3f
#define MEM(x,y) memset(x,y,sizeof(x))
using namespace std;
int dt[][2]= {{1,0},{-1,0},{0,1},{0,-1},{0,0}};
//typedef pair<int, int> P;
//priority_queue<int, vector<int>, greater<int> > q;
const int manx=2e3+10;//顶点个数的最大范围
const int mamx=2e4+10;//边数的最大范围（最多有几条路，可以看）
int cnt[manx];
struct node{
    int v,next,w;
}a[mamx];
int d[manx][manx],head[manx];
bool vis[manx];
int n,m,s,e,k=0;
void add(int u,int v,int w)
{
    a[++k].next=head[u];
    head[u]=k;
    a[k].v=v;
    a[k].w=w;
}
void dij()
{
    for(int i=1;i<=n;i++) d[s][i]=1e9;
    memset(vis,0,sizeof(vis));
    priority_queue<pair<int,int> >q;
    d[s][s]=0;
    q.push(make_pair(0,s));
    while(q.size()){
        int u=q.top().second;
        q.pop();
        if(vis[u]) continue;
        vis[u]=1;
        for(int i=head[u];i;i=a[i].next)
        {
            int v=a[i].v,w=a[i].w;
            if(d[s][v]>d[s][u]+w)
                d[s][v]=d[s][u]+w,q.push(make_pair(-d[s][v],v));
        }
    }
}
int main()
{   
    int x,y;
    cin >> n >> x >> y;
    for(int i=1;i<=n;i++){
        add(i,i+1,1);
        add(i+1,i,1);
    }
    add(x,y,1);add(y,x,1);
    for(int i=1;i<=n;i++)s=i,dij();
    for(int i=1;i<=n;i++){
        for(int j=i+1;j<=n;j++){
            cnt[d[i][j]]++;
        }
    }
    for(int i=1;i<n;i++)cout<<cnt[i]<<endl;
}

Measured memory_bytes: 16000
#include <iostream>
#include <cstdlib>

using namespace std;

int f( int p, int x ) {
  return p * ( 100 + x ) / 100;
}

int main() {
  while( 1 ) {
    int x, y, s;
    int tmpmax = 0;
    cin >> x >> y >> s;
    if( !( x | y | s ) ) { break; }
    for( int p1 = 1; p1 < s; p1++ ) {
      for( int p2 = 1; p2 < s; p2++ ) {
        if( f( p1, x ) + f( p2, x ) == s ) {
          tmpmax = max( tmpmax, f( p1, y ) + f( p2, y ) );
        }
      }
    }
    cout << tmpmax << endl;
  }
  return EXIT_SUCCESS;
}

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

//#define int long long
#define ll long long
#define all(v) (v).begin(), (v).end()
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<n;++i)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define EPS (1e-7)
#define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef pair<ll, ll> P;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
typedef vector<vector<vector<ll> > > vvvl;
ll MOD = 1000000007;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);
//cout<<fixed<<setprecision(10);

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;}
template<class T> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};

signed main()
{   
    gearup;
    int a,b; cin >> a >> b;
    int res = 0;
    for(int i=a;i<=b;i++){
        string s = to_string(i);
        if(s[0] == s[4] && s[1] == s[3])res++;
    }
    cout << res << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>

using namespace std;
using pii = pair<int, int>;

int main() {
  int n;
  map<string, vector<pii>> m;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    string s;
    int p;
    cin >> s >> p;
    m[s].emplace_back(p, i + 1);
  }
  for (auto &p : m) {
    sort(p.second.begin(), p.second.end(), [](const pii a, const pii b) { return a > b; });
    for (const auto &i : p.second) cout << i.second << endl;
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define IO ios::sync_with_stdio(false), cin.tie(0)
#define INF 0x3f3f3f3f
typedef long long ll;
using namespace std;

int main()
{
	IO;
	string s;
	cin>>s;
	int len=s.length();
	for(int i=0;i<len/2;i++){//akasaka
		if(s[i]!=s[len-i-1]){
			cout<<"No"<<endl;
			return 0;
		}
	} 
	int tmp=len/2;
	for(int i=0;i<tmp/2;i++){
		if(s[i]!=s[tmp-i-1]){
			cout<<"No"<<endl;
			return 0;
		}
	}
	for(int i=len/2+2;i<len;i++){
		if(s[i]!=s[len-i-1]){
			cout<<"No"<<endl;
			return 0;
		}
	}
	cout<<"Yes"<<endl;
 	return 0;
}







Measured memory_bytes: 256
#include <stdlib.h>

#define MAX 100
#define WHITE 0
#define GRAY 1
#define BLACK 2

int n,M[MAX][MAX];

int prim(){
  int u,minv,v,sum=0;
  int i,d[MAX],p[MAX],col[MAX];
  for(i=0;i<n;i++){
    d[i]=9999;
    p[i]=-1;
    col[i]=WHITE;
  }
  d[0]=0;

  while(1){
    minv=9999;
    u=-1;
    for(i=0;i<n;i++){
      if(minv>d[i] && col[i]!=BLACK){
        u=i;
        minv=d[i];
      }
    }
    if(u==-1) break;
    col[u]=BLACK;
    for(v=0;v<n;v++){
      if(col[v]!=BLACK && M[u][v]!=10000){
        if(d[v]>M[u][v]){
          d[v]=M[u][v];
          p[v]=u;
          col[v]=GRAY;
        }
      }
    }
  }
  sum=0;
  for(i=0;i<n;i++){if(p[i]!=-1) sum+=M[i][p[i]];}
  return sum;
}

int main(){
  int i,j,e;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      scanf("%d",&e);
      if(e==-1){
        M[i][j]=10000;
      }else M[i][j]=e;
    }
  }
  printf("%d\n",prim());
  return 0;
}


Measured memory_bytes: 2032
#include <bits/stdc++.h>
#define REP(i, n) for(ll i = 0; i < (ll)n; i++)
#define FOR(i, a, b) for(ll i = (a); i < (ll)b; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF (1ll << 60)
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;
using vl = vector<ll>;
using vvl = vector<vl>;
typedef double db;
typedef string str;
typedef pair<ll, ll> p;
constexpr int MOD = 1000000007;
using ll = long long;
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;
}

void print(const std::vector<int> &v) {
    std::for_each(v.begin(), v.end(), [](int x) { std::cout << x << " "; });
    std::cout << std::endl;
}

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

long long lcm(long long a, long long b) {
    long long temp = gcd(a, b);
    return temp ? (a / temp * b) : 0;
}

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

int main() {
    ll X;
    cin >> X;
    if(X == 2) {
        cout << 2 << endl;
        return 0;
    }
    if(X == 1) {
        cout << 1 << endl;
        return 0;
    }
    if(X % 2 == 0) {
        X++;
    }
    for(ll i = X; i < INF; i += 2) {
        if(is_prime(i)) {
            cout << i << endl;
            return 0;
        }
    }
}


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

#define DUMP(x) cerr << #x << "=" << x << endl
#define DUMP2(x, y) cerr<<"("<<#x<<", "<<#y<<") = ("<<x<<", "<<y<<")"<< endl
#define BINARY(x) static_cast<bitset<16> >(x)

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

#define in_range(x, y, w, h) (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))
#define ALL(a) (a).begin(),(a).end()

typedef long long ll;
const int INF   = 1e9;
const ll  INFLL = 1e18;
typedef pair<int, int> PII;
typedef vector<vector<int>> Graph;
int dx[4]={0, -1, 1, 0}, dy[4]={-1, 0, 0, 1};

int main()
{
    ios::sync_with_stdio(false);
    int N, C; 
    cin >> N >> C;
    vector<vector<int>> D(C, vector<int>(C));
    rep(i, C) rep(j, C) cin >> D[i][j];

    vector<map<int, int>> c_freq(3);
    rep(y, N) rep(x, N) {
        int C; cin >> C;
        C--;
        c_freq[(y+x)%3][C]++;
    }

    int ans = INF;
    rep(c1, C) rep(c2, C) rep(c3, C) {
        if (c1 == c2 || c2 == c3 || c3 == c1) continue;
        int cost = 0;
        vector<int> new_color = {c1, c2, c3};
        rep(i, 3) {
            rep(c, C) {
                cost += D[c][new_color[i]] * c_freq[i][c];
            }
        }
        ans = min(ans, cost);
    }
    cout << ans << endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<bool> vb;
typedef vector<char> vc;
#define INF __INT32_MAX__
#define LINF __LONG_LONG_MAX__

int main() {
    int N; cin >> N;
    vi A(N); rep(i, N) cin >> A[i];

    bool allplus = true;
    bool allminus = true;
    bool isok = true;
    rep(i, N) {
        if (A[i] < 0) allplus = false;
        if (A[i] > 0) allminus = false;

        if ((i != N - 1) && (A[i] > A[i + 1])) {
            isok = false;
        }
    }
    if (isok) {
        cout << 0 << endl;
        return 0;
    }

    if (allplus) {
        cout << (N - 1) << endl;
        for (int i = 1; i < N; i++) {
            cout << (i) << " " << (i + 1) << endl;
        }
    } else if (allminus) {
        cout << (N - 1) << endl;
        for (int i = N - 2; i >= 0; i--) {
            cout << (i + 2) << " " << (i + 1) << endl;
        }
    } else {
        int amax = -INF;
        int amaxi;
        int amin = INF;
        int amini;
        rep(i, N) {
            if (A[i] > amax) {
                amax = A[i];
                amaxi = i;
            }

            if (A[i] < amin) {
                amin = A[i];
                amini = i;
            }
        }

        cout << (2 * N - 2) << endl;
        if (abs(amax) >= abs(amin)) {
            rep(i, N) {
                if (i != amaxi) {
                    cout << (amaxi + 1) << " " << (i + 1) << endl;
                }
            }
            for (int i = 1; i < N; i++) {
                cout << (i) << " " << (i + 1) << endl;
            }
        } else {
            rep(i, N) {
                if (i != amini) {
                    cout << (amini + 1) << " " << (i + 1) << endl;
                }
            }
            for (int i = N - 2; i >= 0; i--) {
                cout << (i + 2) << " " << (i + 1) << endl;
            }
        }

    }
}

Measured memory_bytes: 3644