akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize("O3")

#include "bits/stdc++.h"
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
tree<int,int,greater<int>,rb_tree_tag,tree_order_statistics_node_update> map_t;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define F0R(i, a) for(int i = 0; i < (a); ++i)
#define sz(x) (int)x.size()
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
#define REV(x) reverse(x.begin(),x.end())
int dx[]={-1,0,1,0};
int dy[]={0,-1,0,1};
int n,m,k;
vector<vector<char>> arr;
vector<vector<vector<bool>>> vis;
int start[2],dest[2];
int lvl=0;

bool bfs() {
    set<pair<int,int>> q;
    q.insert({start[0],start[1]});
    while(true) {
        if(q.empty())
            break;
        lvl++;
        set<pair<int,int>> tq;
        while(!q.empty()) {
            pair<int,int> cur=*q.begin();
            q.erase(*q.begin());;
            vis[cur.first][cur.second][0]=true;
            vis[cur.first][cur.second][1]=true;
            F0R(i,4) {
                pair<int,int> nxt=cur;
                F0R(j,k) {
                    nxt.first+=dy[i];
                    nxt.second+=dx[i];
                    if(nxt.first==dest[0] && nxt.second==dest[1])
                        return true;
                    if(q.find(nxt)!=q.end())
                        break;
                    if(nxt.first>=n || nxt.first<0 || nxt.second>=m || nxt.second<0 || (dy[i]!=0 && vis[nxt.first][nxt.second][0]) || (dx[i]!=0 && vis[nxt.first][nxt.second][1]) 
                            || arr[nxt.first][nxt.second]=='@')
                        break;
                    if(dy[i]!=0 && nxt.first<n && nxt.first>=0 && nxt.second<m && nxt.second>=0 && arr[nxt.first][nxt.second]=='.')
                        vis[nxt.first][nxt.second][0]=true;
                    if(dx[i]!=0 && nxt.first<n && nxt.first>=0 && nxt.second<m && nxt.second>=0 && arr[nxt.first][nxt.second]=='.')
                        vis[nxt.first][nxt.second][1]=true;
                    tq.insert({nxt.first,nxt.second});
                }
            }
        }
        q=tq;
    }
    return false;
}

int main() {
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin >> n >> m >> k;
    cin >> start[0] >> start[1];
    start[0]--; start[1]--;
    cin >> dest[0] >> dest[1];
    dest[0]--; dest[1]--;
    arr.assign(n,vector<char>(m,0));
    vis.assign(n,vector<vector<bool>>(m,vector<bool>(2,false)));
    F0R(i,n) {
        F0R(j,m)
            cin >> arr[i][j];
    }
    bool res=bfs();
    if(res)
        cout << lvl;
    else
        cout << -1;

    return 0;
}


Measured memory_bytes: 144808
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int main(){
	int n,m;
	cin>>n>>m;
	vector<int> a(n);
	rep(i,m){
		int k;
		cin>>k;
		rep(j,k){
			int x;
			cin>>x;
			a[--x]+=1<<i;
		}
	}
	int p=0;
	rep(i,m){
		int x;
		cin>>x;
		p+=x*(1<<i);
	}
	int ans=0;
	int all=1<<n;
	rep(i,all){
		int ret=0;
		rep(j,n)if((1<<j)&i)ret^=a[j];
		if(ret==p)++ans;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define vlli vector<ll>
#define vi vector<int>
#define vs vector<string>
#define vplli vector< pair< ll,ll> >
#define plli pair< ll,ll >
#define vps vector< pair< string, string> >
#define vpi vector< pair< int, int> >
#define all(x) x.begin(), x.end()
#define fast ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define forn(i,a,n) for(ll i=a;i<n;i++)
#define scan(arr,a,n) for(ll i=(a);i<(n);i++)cin>>(arr)[i];
#define print(arr,a,n) for(ll i=(a);i<(n);i++)cout<<(arr)[i]<<" ";

ll add(ll x, ll y) {ll res = x + y; return (res >= mod ? res - mod : res);}
ll mul(ll x, ll y) {ll res = x * y; return (res >= mod ? res % mod : res);}
ll sub(ll x, ll y) {ll res = x - y; return (res < 0 ? res + mod : res);}
ll power(ll x, ll y) {ll res = 1; x %= mod; while (y) {if (y & 1)res = mul(res, x); y >>= 1; x = mul(x, x);} return res;}
ll mod_inv(ll x) {return power(x, mod - 2);}


int main(){
    fast;
    ll n;
    cin>>n;
    ll a=0,w=0,t=0,r=0;
    string s;
    forn(i,0, n){
        cin>>s;
        if(s=="AC"){
            a++;
        }
        else if(s=="WA")w++;
        else if(s == "TLE")t++;
        else r++;
    }
    cout<<"AC x "<<a<<endl;
    cout<<"WA x "<<w<<endl;
    cout<<"TLE x "<<t<<endl;
    cout<<"RE x "<<r<<endl;
}

Measured memory_bytes: 3656
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<long, long> PLL;
typedef long long LL;
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
#define INF 10000000


LL dp[2][3][101];//dp[連続日数][種類][日数]

int main(){
	int n,k;
	cin>>n>>k;
	CLR(dp);
	vector<int>check[101];
	REP(i,k){
		int a,b;
		cin>>a>>b;
		a--;b--;
		check[a].PB(b);
	}
	REP(i,3){
		if(!check[1].empty()&&!check[2].empty()&&check[1][0]==i&&check[2][0]==i){
			dp[0][i][0]=0;
		}else if(!check[0].empty()){
			dp[0][check[0][0]][0]=1;
		}else dp[0][i][0]=1;
	}
	FOR(i,1,n){
		if(!check[i].empty()){
			int t=check[i][0];
			REP(j,3)REP(k,2)if(t!=j){
				dp[0][t][i]+=dp[k][j][i-1];
				dp[0][t][i]%=10000;
			}
			dp[1][t][i]+=dp[0][t][i-1];
			dp[1][t][i]%=10000;
			continue;
		}
			
		REP(j,3)REP(j2,3){
			if(j!=j2)REP(k,2){
				dp[0][j][i]+=dp[k][j2][i-1];
				dp[0][j][i]%=10000;
			}else{
				dp[1][j][i]+=dp[0][j][i-1];
				dp[1][j][i]%=10000;
			}
		}
	}
	LL sum=0;
	REP(i,3)REP(j,2){
		sum+=dp[j][i][n-1];
		sum%=10000;
	}
	cout<<sum<<endl;
	return 0;
}

Measured memory_bytes: 1196
n, kosuu = map(int, input().split())
XY, X, Y = [], [], []

for _ in range(n):
    x, y = map(int, input().split())
    X.append(x)
    Y.append(y)
    XY.append([x,y])

X = sorted(X, reverse=True)
Y = sorted(Y, reverse=True)

s_min = 10**20
for i in range(n):
    for j in range(n):
        for k in range(n):
            for l in range(n):
                count = 0
                x_max = X[i]
                x_min = X[-1*(j+1)]
                if x_max <= x_min:
                    continue
                y_max = Y[k]
                y_min = Y[-1*(l+1)]
                if y_max <= y_min:
                    continue

                s = abs(x_max-x_min)*abs(y_max-y_min)

                for m in range(n):
                    x = XY[m][0]
                    y = XY[m][1]
                    if (x <= x_max and x >= x_min) and (y <= y_max and y >= y_min):
                        count += 1
                if count >= kosuu:
                    s_min = min(s, s_min)

print(s_min)



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

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

int main() {
    /*変数定義，入力*/
    string weather;
    cin >> weather;


    //int A, B;cin >> A >> B;
    //vector<int> a(N);  rep(i, N) cin >> a[i];
    
    /*演算*/
    if(weather == "Sunny") cout << "Cloudy";
    else if(weather == "Cloudy") cout << "Rainy";
    else cout << "Sunny";
    /*出力*/
    cout << endl;

    /*終了*/
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<utility>
#include<cmath>
#include<string>
#include<cstring>
#include<map>
#include<queue>
#include<set>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define prin(arg) cout<<arg<<"\n"
#define prin2(arg1,arg2) cout<<arg1<<" "<<arg2<<"\n"
#define fill(arg,n) memset(arg,n,sizeof(arg))
#define mp make_pair
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<int,int> pi;
typedef vector<int> vi;
typedef set<int> si;
typedef string str;
const int INF=1e+9;
const ll INFLL=1e+17;
const ll MOD=1e+9+7;
int N;
ll K;
int a[100010],b[100010];
ll d[100010];
bool f[100010];
vi edge[100010];
ll res;
void add_edge(int from,int to){
  edge[from].pb(to);
  edge[to].pb(from);    
}
void rec(int v){
  rep(i,edge[v].size()){
    int w=edge[v][i];
    if(f[w]) continue;
    f[w]=true;
    res=(res*(K-d[v]))%MOD;    
    d[v]++;d[w]++;
    rec(w);
  }
}
int main(){
  cin>>N>>K;
  rep(i,N-1){
    cin>>a[i]>>b[i];
    a[i]--;b[i]--;
  }
  rep(i,N-1) add_edge(a[i],b[i]);
  rep(i,N){
    d[i]=1;
    f[i]=false;
  }
  f[0]=true;
  res=K;
  rec(0);
  prin(res);
  return 0;
}


Measured memory_bytes: 10880
//#define __USE_MINGW_ANSI_STDIO 0
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define IN(a, b, x) (a<=x&&x<b)
#define MP make_pair
#define PB push_back
const int INF = (1LL<<30);
const ll LLINF = (1LL<<60);
const double PI = 3.14159265359;
const double EPS = 1e-12;
const int MOD = 1000000007;
//#define int ll

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }

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

VI g[2010];
int a[2010], b[2010];

int dist[2010];
void dfs(int v, int p) {
  // cout << v << " " << p << " " << dist[v] << endl;
  for(int i: g[v]) {
    if(i == p) continue;
    chmin(dist[i], dist[v] + 1);
    dfs(i, v);
  }
}

signed main(void)
{
  int n, k;
  cin >> n >> k;
  REP(i, n-1) {
    cin >> a[i] >> b[i];
    a[i]--, b[i]--;
    g[a[i]].PB(b[i]);
    g[b[i]].PB(a[i]);
  }


  if(k%2) {
    int ret = INF;
    REP(i, n-1) {
      REP(i, n) dist[i] = INF;
      dist[a[i]] = dist[b[i]] = 0;
      dfs(a[i], -1); dfs(b[i], -1);
      int tmp = 0;
      REP(i, n) if(dist[i] > (k-1)/2) ++tmp;
      chmin(ret, tmp);
      // cout << "i:" << i << " ret:" << ret << endl;
    }
    cout << ret << endl;
  } else {
    int ret = INF;
    REP(i, n) {
      REP(i, n) dist[i] = INF;
      dist[i] = 0;
      dfs(i, -1);
      int tmp = 0;
      REP(i, n) {
        // cout << dist[i] << " ";
        if(dist[i] > k/2) ++tmp;
      }
      // cout << endl;
      chmin(ret, tmp);
      // cout << "i:" << i << " ret:" << ret << endl;
    }
    cout << ret << endl;
  }

  return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <iomanip>
#include <cassert>

#include <cstring>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <limits>
#include <queue>
#include <unordered_map>
#include <list>
#include <set>
#include <numeric>
using namespace std;

using ll = long long;

#define rep_init(i, init, n) for(int i = (init); i < (n); ++i)
#define rep(i, n) rep_init(i, 0, n)

ll pes(vector<ll>& v, ll b)
{
	ll sum = 0;
	rep(i, v.size())
	{
		sum += abs(v[i] - b);
	}

	return sum;
}

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

	vector<ll> A(N);
	rep(i, N)
	{
		cin >> A[i];
		A[i] -= i + 1;
	}

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

	int k = N / 2;
	ll ans;
	while (true)
	{
		ll p = pes(A, A[k]);

		if (k+1 < N)
		{
			if (p > pes(A, A[k+1]))
			{
				k = (N - 1 + k + 1) / 2;
				continue;
			}
		}

		if (k-1 >= 0)
		{
			if (p > pes(A, A[k-1]))
			{
				k = (k-1) / 2;
				continue;
			}
		}

		ans = p;
		break;
	}

	cout << ans << endl;
}

Measured memory_bytes: 4776
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;
using ll = long long;
int main()
{
    const ll INF = 1e9;
    ll N,W;
    cin >> N >> W;
    ll w[N],v[N];
    ll v_max = 0;
    for(ll i = 0;i < N;i++)
    {
        cin >> w[i] >> v[i];
        if(v[i] > v_max)
        {
            v_max = v[i];
        }
    }
    ll dp[N + 1][N * v_max + 1];
    for(ll i = 0;i < N + 1;i++)
    {
        for(ll j = 0;j < N * v_max + 1;j++)
        {
            dp[i][j] = INF;
        }
    }
    dp[0][0] = 0;
    for(ll i = 0;i < N;i++)
    {
        for(ll j = 0;j <= N * v_max;j++)
        {
            if(j < v[i])
            {
                dp[i + 1][j] = dp[i][j];
            }
            else
            {
                dp[i + 1][j] = min(dp[i][j],dp[i][j - v[i]] + w[i]);
            }
        }
    }
    ll ans = 0;
    for(ll i = 0;i <=N *  v_max;i++)
    {
        if(dp[N][i] <= W)
        {
            ans = i;
        }
    }
    cout << ans << "\n";

    return 0;
}

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

int main() {
    int a,b;
    cin >> a >> b;
    vector<int> s ={-1,0,2,0,1,0,1,0,0,1,0,1,0};
    if(s.at(a)==s.at(b)){
        cout << "Yes";
    }
    else{
        cout << "No";
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define mod 1000000007
using namespace std;

int main () {
  ll N;
  cin >> N;
  
  ll ans = 1;
  for (ll i = 1; i <= N; i++) {
    ans = ans*i%mod;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
import sys
from collections import deque


# sys.stdin = open('d1.in')


def read_int_list():
    return list(map(int, input().split()))


def read_str_list():
    return input().split()


def read_int():
    return int(input())


def read_str():
    return input()


def main():
    n = read_int()
    adj = [[] for u in range(n+1)]
    for i in range(n - 1):
        a, b, c = map(int, input().split())
        adj[a].append((b, c))
        adj[b].append((a, c))

    d = [0] * (n+1)
    q, k = read_int_list()

    # Q = [(k, 0, 0)]
    Q = deque([(k, 0, 0)])
    while Q:
        u, parent, dist = Q.popleft()
        for v, w in adj[u]:
            if v != parent:
                Q.append((v, u, dist+w))
        d[u] = dist

    res = [0] * q
    for i in range(q):
        x, y = map(int, input().split())
        res[i] = d[x] + d[y]
    print(*res, sep='\n')


main()


Measured memory_bytes: 50324
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <list>
#include <queue>
#include <tuple>
#include <deque>
#include <algorithm>
#include <numeric>
#include <iomanip>
#include <utility>
#include <complex>
#include <functional>
using namespace std;
const int MOD = 1000000007;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = (1 << 28);
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
int h, w, d, q;
int a[300][300];
//vector<int> l r;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> h>>w>>d;
    vector<pair<int, pair<int,int> > > dis[d];
    for (int i = 0; i < h; i++)
    {
        for(int j=0;j<w;j++){
            int temp;
            cin>>temp;
            dis[temp%d].push_back(make_pair(temp,make_pair(i+1,j+1)));
        }
    }
    cin>>q;
    /*for(int i=0;i<q;i++){
        int templ, tempr;
        cin>>templ>>tempr;
        l.push_back(templ);
        r.push_back(tempr);
    }*/
    for(int i=0;i<d;i++){
        sort(ALL(dis[i]));
    }
    vector<int> dist[d];
    for(int i=0;i<d;i++){
        dist[i].push_back(0);
        for(int j=1;j<dis[i].size();j++){
            int now=dist[i][dist[i].size()-1];
            now+=abs(dis[i][j].second.first-dis[i][j-1].second.first)+abs(dis[i][j].second.second-dis[i][j-1].second.second);
            dist[i].push_back(now);
            //cout<<now<<"\n";
        }
    }
    for(int i=0;i<q;i++){
        int l, r;
        cin>>l>>r;
        if(r%d!=0){
        int ans=dist[r%d][r/d]-dist[r%d][l/d];
        cout<<ans<<"\n";
        }
        else{
            int ans=dist[r%d][r/d-1]-dist[r%d][l/d-1];
            cout<<ans<<"\n";
        }
    }

}


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

using namespace std;

#define REP(i,n) for(int i=0; i<int(n); i++)
#define FOR(i,m,n) for(int i=int(m); i<int(n); i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define VI vector<int>
#define VLL vector<long long>
#define VVI vector<vector<int>>
#define VVLL vector<vector<long long>>
#define VC vector<char>
#define VS vector<string>
#define VVS vector<vector<string>>
#define VVC vector<vector<char>>
#define fore(i,a) for(auto &i:a)
typedef long long ll;
typedef pair <int, int> P;
const int  INF = 2147483647;
const ll INFL = 9223372036854775807;
const ll mod = 1000000007;




int main() {
	string s;
	int k;
	cin >> s >> k;
	REP(i, s.size()) {
		if (s[i] != 'a') {
			int a = 'z' - s[i] + 1;
			if (a <= k) {
				s[i] = 'a';
				k -= a;
			}
		}
	}
	s[s.size() - 1] = 'a' + (k + s[s.size() - 1] - 'a') % 26;
	cout << s << endl;
	return 0;

}


Measured memory_bytes: 512
#include <iostream>
#include <string.h>
#define MAX 100
using namespace std;

int main(void)
{
     int N, W, H, S, T;
     while (cin >> N && N) {
	  cin >> W >> H;
	  int field[W][H];
	  memset(field, 0, sizeof(field));
	  for (int i = 0; i < N; i++) {
	       int x, y;
	       cin >> x >> y;
	       field[x - 1][y - 1] = 1;
	  }
	  cin >> S >> T;
	  int max = 0, count;
	  for (int i = 0; i < W - S + 1; i++) {
	       for (int j = 0; j < H - T + 1; j++) {
		    count = 0;
		    for (int s = i; s < i + S; s++) {
			 for (int t = j; t < j + T; t++) {
			      if(field[s][t] == 1) count++;
			 }
		    }
		    if (max < count) max = count;
	       }
	  }
	  cout << max << endl;
     }
     
     return 0;
}

Measured memory_bytes: 1196
import sys

N,M=map(int,input().split())
ope=[]
for i in range(M):
    ope.append(tuple(map(int,input().split())))

state=[1]*N
red=[0]*N
red[0]=1
for i in range(M):
    x,y=ope[i]
    if red[x-1]:
        if state[x-1]>1:
            red[x-1]=1
            red[y-1]=1
        else:
            red[x-1]=0
            red[y-1]=1
    state[x-1]-=1
    state[y-1]+=1

print(sum(red))


Measured memory_bytes: 60248
#include <stdio.h>

int main(void)
{

    long l_monsterHP;
    int i_skillNum;
    int i_skillDetail;
    long l_totalDamage = 0;

    scanf("%ld%d", &l_monsterHP, &i_skillNum);

    for (int count = 0; count < i_skillNum; count++)
    {
        scanf("%d", &i_skillDetail);
        l_totalDamage += i_skillDetail;
    }

    if (l_totalDamage >= l_monsterHP)
    {
        printf("Yes");
    }
    else
    {
        printf("No");
    }

}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;   

typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> isPair;
using vvll = vector< vector<ll> >;
using vll = vector<ll> ;
#define Pll pair<ll,ll>
#define vpll vector<pll>
#define sll set<ll>
#define mll map<ll,ll>

const ll inf=1e18;
const ll maxs = 1e5;
const ll mod = 1e9+7;

#define mp make_pair
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define ff first
#define ss second
#define LB lower_bound
#define UB upper_bound
#define line cout<<endl;
#define fr(i,a,b) for(int i=a;i<=b;++i)
#define all(n) n.begin(),n.end()
#define present(s,x) (s.find(x) != s.end()) 
#define cpresent(s,x) (find(all(s),x) != s.end()) 
#define tr(container, it) for(__typeof(container.begin()) it = container.begin(); it != container.end(); it++) 
#define fastio(); ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define mst(x,a) memset(x,a,sizeof(x))

ll n;
ll a[3003];
ll dp[3003][3003];

ll solve(ll l,ll r,ll sum)
{
    if(dp[l][r]!=-1)
        return dp[l][r];
    if(l==r)
        return dp[l][r] = a[l];
    
    if(l+1==r)  
        return dp[l+1][r] = max(a[l],a[r]);
    
    
    return dp[l][r] = max(sum - solve(l+1,r,sum-a[l]) , sum - solve(l,r-1,sum-a[r]) );
}


int main() 
{
    fastio();
	ll t=1;
    //cin>>t;
    while(t--)
	{
        cin>>n;
        ll sum=0;
        for(ll i=0;i<n;i++)
        {   cin>>a[i];
            sum+=a[i];
        }
        memset(dp,-1,sizeof dp);
        ll first = solve(0,n-1,sum);
        ll second = sum - first;
        cout<<first-second;
    }
	
	return 0;
}

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

int main()
{
  int x, y;
  cin >> x >> y;
  for (int i = 0; x != 0 || y != 0; i++)
  {
    if(x>y){
      int tmp = x;
      x = y;
      y = tmp;
    }
    cout << x << " " << y << endl;
    cin >> x >> y;
  }
}


Measured memory_bytes: 3088
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<sstream>
#include<cmath>
#include<numeric>
#include<map>
#include<stack>
#include<queue>
#include<list>
#include<set>
#include<cstring>
using namespace std;
long long int mod = 1e9 + 7;
int inf = 1e9;

int main() {
  int n, w; cin >> n >> w;
  vector<int> c(n);
  vector<int> v(n);
  for(int i=0; i<n; i++) {
    cin >> c[i] >> v[i];
  }
  int vv = 200000;
  vector<long long int> dp(vv+1, 1e12);
  dp[0] = 0;
  for(int i=1; i<=n; i++) {
    for(int j=vv; j>=0; j--){
      if(j - v[i-1] >= 0) {
        dp[j] = min(dp[j], dp[j-v[i-1]]+c[i-1]);
      }
    }
  }

  long long int ans = 0;
  for(long long int i=0; i<=vv; i++) {
    if(dp[i] <= w) ans = max(ans, i);
  }
  cout << ans << endl;
  return 0;
}



//EOF


Measured memory_bytes: 1792
#ifdef _MSC_VER
#pragma warning(disable : 4996)
#include <intrin.h>
#define __builtin_popcount __popcnt
#endif

#include <limits.h>
#include <math.h>
#include <time.h>

#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <complex>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

#define REP(i, n) for (int i = 0; i < n; ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; --i)
#define FOR(i, m, n) for (int i = m; i < n; ++i)
#define FORR(i, m, n) for (int i = m - 1; i >= n; --i)
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v, n) reverse(v, v + n);
#define VREVERSE(v) reverse(v.begin(), v.end())
#define ll long long
#define print(x) cout << (x) << '\n'
#define pe(x) cout << (x) << " "
#define DEBUG(x) cout << #x << ": " << x << endl
#define lb(v, n) lower_bound(v.begin(), v.end(), (n))
#define ub(v, n) upper_bound(v.begin(), v.end(), (n))
#define int long long
//#define double long double
#define all(x) (x).begin(), (x).end()
#define print_space(v) REP(i, v.size()) cout << v[i] << ((i == v.size() - 1) ? "\n" : " ")
template <typename T1, typename T2> inline void chmin(T1& a, T2 b) {
	if (a > b) a = b;
}
template <typename T1, typename T2> inline void chmax(T1& a, T2 b) {
	if (a < b) a = b;
}
typedef pair<int, int> pii;
typedef array<int, 3> arr3;
std::random_device rd;
std::mt19937 mt(rd());
constexpr ll MOD = 1e9 + 7;
constexpr int MAX = 200020;
const double pi = acos(-1);
constexpr double EPS = 1e-8;
constexpr ll INF = 1e18;

int dp[51][2510];
struct edge {
	int to, cost, t;
};
vector<edge>G[55];
int C[55], D[55];
bool done[55][2550];

void solve() {
	int N, M, S; cin >> N >> M >> S;
	S = min(S, (int)2500);
	REP(i, M) {
		int u, v, a, b; cin >> u >> v >> a >> b;
		u--, v--;
		G[u].push_back({ v,a,b });
		G[v].push_back({ u,a,b });
	}
	REP(i, N)cin >> C[i] >> D[i];
	priority_queue<arr3, vector<arr3>, greater<arr3>>que;
	arr3 s;
	s[0] = 0;
	s[1] = 0;
	s[2] = S;
	que.push(s);
	REP(i, N)REP(j, 2501)dp[i][j] = 1e18;
	dp[0][S] = 0;
	while (!que.empty()) {
		arr3 ar = que.top(); que.pop();
		int now = ar[1],  c = ar[2];
		int d = ar[0];
		if (dp[now][c] < d)continue;
		//pe(now); pe(c); print(d);

		REP(i, 2) {
			if (c + C[now]*i > 2500)break;
			if (dp[now][c] + D[now] * i < dp[now][c + C[now] * i]) {
				dp[now][c + C[now] * i] = dp[now][c] + D[now] * i;
				que.push({ dp[now][c + C[now] * i] ,now,c + C[now] * i });
			}
		}
		for (auto e : G[now]) {
			if (e.cost > c)continue;
			if (dp[now][c] + e.t < dp[e.to][c - e.cost]) {
				dp[e.to][c - e.cost] = dp[now][c] + e.t;
				que.push({ dp[e.to][c - e.cost] ,e.to,c - e.cost });
			}
		}
	}
	FOR(i, 1, N) {
		int mn = 1e18;
		REP(j, 2501) {
			chmin(mn, dp[i][j]);
		}
		cout << mn << endl;
	}
}

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	// int q; cin >> q;
	// while (q--)
	solve();
}


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

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            const string ANSUCCESS = "No";
            const string SUCCESS = "Yes";

            var input = Console.ReadLine();
            if (input.Distinct().Count() == 2)
            {
                Console.WriteLine(SUCCESS);
                return;
            }
            Console.WriteLine(ANSUCCESS);
        }
    }
}

Measured memory_bytes: 13268
import math
n, d = map(int, input().split())
x = [list(map(int, input().split())) for _ in range(n)]

count = 0
for i in range(n-1):
    for j in range(i+1, n):
        distance = 0
        for k in range(d):
            distance += (x[i][k] - x[j][k]) ** 2
        if math.sqrt(distance).is_integer():
            count += 1

print(count)


Measured memory_bytes: 3060
/**
 * @brief AtCoder Regular Contest 061<br>
 * C- たくさんの数式 / Many Formulas
 *
 * bit全検索パターン
 * @see https://arc061.contest.atcoder.jp/tasks/arc061_a
 */
#include <iostream>
using namespace std;

int main() {
  string S; cin >> S;
  int len{static_cast<int>(S.size())};

  long total{};
  for (int i{}; i < (1 << (len - 1)); ++i) {
    long temp = S[0] & 0xF;
    for (int j{}; j < len - 1; ++j) {
      if (i & (1 << j)) {
        total += temp;
        temp = 0;
      }
      temp *= 10;
      temp += S[j + 1] & 0xF;
    }
    total += temp;
  }

  cout << total << endl;
  return 0;
}


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

int main(){
  int n,k,a,s;
  while(cin>>n>>k,n||k){
    int m=-10001;a=0;
    queue<int> q;
    n-=k;
    while(k--){
      cin>>s;
      a+=s;q.push(s);
    }
    m=max(m,a);
    while(n--){
      cin>>s;
      q.push(s);
      a=a+s-q.front();
      q.pop();
      m=(m>a)?m:a;
    }
    cout<<m<<endl;
  }
  return 0;
}

Measured memory_bytes: 1344
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <set>
#include <string>
#include <iomanip>
using namespace std;

int main(){
    int x,a,b; cin >> x >> a >> b;
    string ans;
    if ( abs(x-a) >  abs(x-b)) ans = "B";
    else ans = "A";
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define all(v) v.begin(), v.end()
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<ll> vec;
typedef vector<vec> mat;
ll mod=1e9+7;
ll inv(ll a){
    ll n=mod-2,ans=1;
    while(n>0){
        if(n&1) ans=ans*a%mod;
        n=n/2;
        a=a*a%mod;
    }
    return ans;
}
ll A[200001];
void init(){
    A[0]=1;
    rep(i,200000) A[i+1]=A[i]*(i+1)%mod;
}
ll nCk(ll n,ll k){
    return A[n]*inv(A[k])%mod*inv(A[n-k])%mod;
}
int main(){
    ll n,B[200001],a=-1,b,c,num[200001]={0};
    cin>>n;
    rep(i,n+1) cin>>B[i],num[B[i]]++;
    init();
    rep(i,n) if(num[i+1]==2) c=i+1;
    rep(i,n+1)if(B[i]==c){
        if(a==-1) a=i;
        else b=i;
    }
    rep(i,n+1){
        ll ans=nCk(n+1,i+1)-(i==0);
        if(0<i&&i<=a+n-b) (ans+=-nCk(a+n-b,i)+mod)%=mod;
        cout<<ans<<"\n";
    }
}

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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  cout.precision(10);
  cout<<fixed;
  int H, N;
  cin>>H>>N;
  int sum=0;
  while(N--) {
    int x;
    cin>>x;
    sum+=x;
  }
  if(sum>=H) cout<<"Yes\n";
  else cout<<"No\n";
  return 0;
}


Measured memory_bytes: 256
/* Isn't passion overrated?*/

#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define ll long long
using namespace std;
ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}
ll mod = 998244353;
ll power(ll a, ll x)
{
    if(x == 0)
        return 1;
    ll ans = power(a, x/2);
    ans *= ans;
    ans %= mod;
    if(x % 2)
        ans *= a;
    return ans % mod;
}

vector<ll>per(200010);

ll ncr(ll n, ll i)
{
    return (per[n] * power(per[i], mod-2) % mod * power(per[n-i], mod-2) % mod) % mod;
}
int main()
{
    ios_base:: sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
    ll n, m, k;
    cin >> n >> m >> k;
    per[0] = 1;
    ll h = per.size();
    for(ll i = 1; i < h; i++)
    {
        per[i] = i * per[i-1];
        per[i] %= mod;
    }
    ll ans = 0;
    for(ll i = 0; i <= k; i++)
    {
        ll temp = ncr(n-1, i);
        temp = temp * m;
        temp %= mod;
        temp = temp * power(m-1,n-1-i);
        ans += temp;
        ans %= mod;
    }
    cout<<ans % mod;
    return 0;
}


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

using namespace std;
using ll = long long;

int n, m, q, ans = 0;
int a[50], b[50], c[50], d[50];

void dfs(vector<int> x) {
	if ((int)x.size() == n + 1) {
		int sum = 0;
		rep(i, q) {
			if (x[b[i]] - x[a[i]] != c[i]) continue;
			sum += d[i];
		}
		ans = max(ans, sum);
		return;
	}
	x.push_back(x.back());
	while (x.back() <= m) {
		dfs(x);
		x.back()++;
	}
}

int main() {
	cin >> n >> m >> q;
	rep(i, q) cin >> a[i] >> b[i] >> c[i] >> d[i];
	dfs(vector<int> (1, 1));
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3600
#include<iostream>
#include<string>
using namespace std;
int main(){
  string b[3],s;
  while(1){
    cin>>b[0];
    s="";
    if(b[0]=="0")
      break;
    cin>>b[1];
    cin>>b[2];
    int flag=0;
    for(int i=0;i<3;i++){
      if(b[0].at(i)==b[1].at(i)&&b[2].at(i)==b[1].at(i)&&b[0].at(i)!='+') s=b[0].at(i);
      if(b[i].at(0)==b[i].at(1)&&b[i].at(1)==b[i].at(2)&&b[i].at(0)!='+') s=b[i].at(0);
    }
    if(b[0].at(0)==b[1].at(1)&&b[1].at(1)==b[2].at(2)&&b[0].at(0)!='+') s=b[0].at(0);
    if(b[0].at(2)==b[1].at(1)&&b[1].at(1)==b[2].at(0)&&b[0].at(2)!='+') s=b[0].at(2);

    if(s=="b"||s=="w") cout<<s<<endl;
    else cout<<"NA"<<endl;
  }
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
int main(){
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int N, x;
  cin >> N;
  int arr[N];
  for(int i = 0; i < N; i++) arr[i] = 0;
  N--;
  while(N--){
    cin >> x;
    arr[x - 1] += 1;
  }
  for(int y : arr) cout << y << "\n";
}

Measured memory_bytes: 4428
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

class Program
{
    static void Main(string[] args)
    {
        string[] arrStr = Console.ReadLine().Split(' ');
        List<int> lstInt = new List<int>();

        for(int i = 0; i < arrStr.Length; i++)
        {
            lstInt.Add(int.Parse(arrStr[i]));
        }

        if(lstInt[1] - lstInt[0] == lstInt[2] - lstInt[1])
        {
            Console.WriteLine("YES");
        }
        else
        {
            Console.WriteLine("NO");
        }
    }
}



Measured memory_bytes: 13140
def koch(p1,p2):
    s=[(2*p1[0]+p2[0])/3,(2*p1[1]+p2[1])/3]
    t=[(p1[0]+2*p2[0])/3,(p1[1]+2*p2[1])/3]
    m=[(p1[0]+p2[0])/2,(p1[1]+p2[1])/2]
    mu=[-(p2[1]-p1[1])*3**.5/6,(p2[0]-p1[0])*3**.5/6]
    u=[m[0]+mu[0],m[1]+mu[1]]
    return [s,u,t]
ans=[[0,0],[100,0]]
n=int(input())
for _ in range(n):
    now=ans.copy()
    ans=[]
    l=0
    r=1
    c=len(now)
    while r<c:
        ans.append(now[l])
        ans+=koch(now[l],now[r])
        l+=1
        r+=1
    ans.append(now[l])
for p in ans:
    print(*p)


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

#define all(x) (x).begin(),(x).end()
#define fastio ios_base::sync_with_stdio(false)

typedef double db;
typedef long long ll;
typedef unsigned long long ull;

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

int main() {
	fastio;
	int n, m; cin >> n >> m;
	ll sum = 0;
	for(int i = 0; i < m; ++i) {
		int val; cin >> val;
		sum += val;
	}

	if(sum > n)
		cout << "-1\n";
	else
		cout << n - sum << endl;
	return 0;
}

Measured memory_bytes: 3656
#include <bits/stdc++.h>
using namespace std;
 
int main(){

  long long N; cin >> N;
  
  int rootN = pow(N,0.5);
  
  
  for(int i=rootN; i>0; i--){
    if(N%i == 0){
      cout << i + (N/i) -2 << endl;
      return 0;
    }
  }
  
  cout << rootN << endl;
}

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

using namespace std;

typedef long long llint;

int main() {
  int n;
  llint k;
  cin >> n >> k;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    a[i]--;
  }
  vector<int> cnt(n, 0);
  int now = 0;
  for (int i = 0; i < 2 * n; i++) {
    if (i == k) {
      cout << now + 1 << endl;
      return 0;
    }
    cnt[now]++;
    now = a[now];
  }
  llint l = 0;
  for (int i = 0; i < n; i++) {
    if (cnt[i] > 1) l++;
  }
  vector<bool> used(n, false);
  now = 0;
  while (!used[now]) {
    used[now] = true;
    now = a[now];
    k--;
  }
  k %= l;
  while (k--) {
    now = a[now];
  }
  cout << now + 1 << endl;

  return 0;
}

Measured memory_bytes: 4796
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
typedef long long ll ;
#define rep(i, a, b) for (int i = a; i <= b; ++ i) 
const int N = 200005 ;
using namespace std ;

int n, H, e, d[2][N], fa[N], sz[N] ;
bool vis[N] ;

int getfa(int x) {
	return (fa[x] == x ? x : fa[x] = getfa(fa[x])) ;
}

int main() {
	scanf("%d%d", &n, &H) ;
	int x1, y1, x2, y2, x, y ;
	rep(i, - H + 1, H) fa[H + i] = H + i ;
	rep(i, 1, n) {
		scanf("%d%d%d%d", &x1, &x2, &y1, &y2) ;
		x = y1 ? H - y1 : H + x1 ;
		y = y2 ? H + y2 : H - x2 ;
		++ d[0][y], ++ d[1][x] ;
		x = getfa(x), y = getfa(y) ;
		if (x != y) fa[x] = y, sz[y] += sz[x] ;
		++ sz[y] ;
	}
	rep(i, 1, H) if (d[0][H + i] > d[1][H + i]) {
		printf("NO\n") ;
		return 0 ;
	}
	rep(i, - H + 1, - 1) if (d[0][H + i] < d[1][H + i]) {
		printf("NO\n") ;
		return 0 ;
	}
	rep(i, - H + 1, H) if (d[0][H + i] != d[1][H + i]) {
		vis[getfa(H + i)] = true ;
	}
	rep(i, - H + 1, H) if (getfa(H + i) == H + i && !vis[H + i] && sz[H + i] > 0) {
		printf("NO\n") ;
		return 0 ;
	}
	printf("YES\n") ;
	return 0 ;
}

Measured memory_bytes: 384
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author dyominov
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        AMeasure solver = new AMeasure();
        solver.solve(1, in, out);
        out.close();
    }

    static class AMeasure {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            String s = in.next();
            if (s.length() == 2) {
                out.print(s);
            } else {
                out.print(new StringBuilder(s).reverse());
            }
        }

    }

    static class InputReader implements AutoCloseable {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public void close() {
        }

    }
}



Measured memory_bytes: 21332
#include <bits/stdc++.h>
using namespace std;
int n, k;
string s;
int main() {
	cin >> n >> k >> s;
	int cnt = 0;
	for (int i=0; i<n-1; i++) {
		if (s[i] == s[i+1]) cnt++;
	}
	cout << min(n - 1, cnt + k * 2) << endl;
	return 0;
}

Measured memory_bytes: 512
while True:
    a,op,b = map(str,input().split())
    a = int(a)
    b = int(b)

    if op=="?": 
        break
    else:
        if op == "+":
            print(a+b)
        elif op == "-":
            print(a-b)
        elif op == "*":
            print(a*b)
        elif op == "/":
            print(a//b)



Measured memory_bytes: 5592
# -*- coding: utf-8 -*-
from sys import stdin
# import numpy as np
# import sys
# sys.setrecursionlimit(10**4)

def _li(): return list(map(int, stdin.readline().split()))
def _li_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def _lf(): return list(map(float, stdin.readline().split()))
def _ls(): return stdin.readline().split()
def _i(): return int(stdin.readline())
def _f(): return float(stdin.readline())
def _s(): return stdin.readline()[:-1]


N = _i()
table = {}
for i in range(1, 10):
    for j in range(1, 10):
        count = 0
        if i == j:
            count += 1
        a, b = str(j), str(i)
        for order in range(len(str(N)) - 1):
            min_x = int(a + "0" * order + b)
            if min_x > N:
                break
            max_x = int(a + "9" * order + b)
            if max_x <= N:
                count += 10 ** order
            else:
                assert str(N)[0] == a
                offset = 1 if str(N)[-1] < b else 0
                count += int(str(N)[1:-1]) - offset + 1
        table[(i, j)] = count

ans = 0
for i in range(1, N+1):
    if i % 10 == 0:
        continue
    ans += table[(int(str(i)[0]), int(str(i)[-1]))]

print(ans)


Measured memory_bytes: 3444
/**
*    author:  souzai32
*    created: 13.08.2020 01:38:59
**/

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

int main() {

    int n;
    cin >> n;
    vector<int> d(n);
    rep(i,n) cin >> d.at(i);
    long long ans=1;
    if(d.at(0)!=0) ans=0;
    sort(d.begin(),d.end());
    if(n>2){
        if(d.at(1)==0) ans=0;
    }

    long x=1,y=1;
    for(int i=1; i<n; i++){
        if(d.at(i-1)==d.at(i)) y++;
        else if(d.at(i-1)+1==d.at(i)){
            x=y;
            y=1;
        }
        else ans=0;
        ans*=x;
        ans%=998244353;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3768
/*
** 二叉搜索树的插入
** 中序和前序输出
*/

# include <cstdio>
# include <cstdlib>

struct Node {
    int key;
    Node *parent, *left, *right;
};

Node *root, *NIL;

void inorder(Node *u) {
    if (u == NIL)
        return;
    inorder(u->left);
    printf(" %d", u->key);
    inorder(u->right);
}

void preorder(Node *u) {
    if (u == NIL)
        return;
    printf(" %d", u->key);
    preorder(u->left);
    preorder(u->right);
}

void insert(int k) {
    Node *y = NIL;
    Node *x = root;

    Node *z = (Node *)malloc(sizeof(Node));
    z->key = k;
    z->left = NIL;
    z->right = NIL;

    while (x != NIL) {
        y = x;
        if (z->key < x->key)
            x = x->left;
        else
            x = x->right;
    }

    z->parent = y;

    if (y == NIL)
        root = z;
    else if (z->key < y->key)
        y->left = z;
    else
        y->right = z;
}

void solve() {
    int n, x;
    char com[10];

    scanf("%d", &n);    
    for (int i = 0; i < n; i++) {
        scanf("%s", com);
        if (com[0] == 'i') {
            scanf("%d", &x);
            insert(x);
        }
        else {
            inorder(root);
            printf("\n");
            preorder(root);
            printf("\n");
        }
    }
}

int main() {
    // freopen("infile", "r", stdin);
    // freopen("outfile", "w", stdout);
    solve();
    return 0;
}


Measured memory_bytes: 26116
#include <bits/stdc++.h>
#include <typeinfo>
#include <cxxabi.h>
#ifdef LOCAL
  #include "dbgtoki.hpp"
  #define DUMP(i) dump((string)TOSTRING(i), demangle(typeid(i).name()), __LINE__ , i) 
DbgTimer D_t;
  #define TSTART() D_t.start()
  #define TSTOP() D_t.stop()
#else
  #define DUMP(i) 
  #define TSTART()
  #define TSTOP()  
#endif
 
#define TOSTRING(x) #x
#define SZ(x) (int)(x).size()
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(s) (s).begin(), (s).end()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()) , v.end());

using namespace std;
typedef long long unsigned int llu;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;

struct Edge{
public:
  int from,to,cost;
  Edge(){}
  Edge(int _from,int _to,int _cost){
    from = _from;
    to = _to;
    cost = _cost;
  }
};

typedef vector<Edge> Edges;
typedef vector<Edges> Graph;


const int EPS = 1e-9;



int main (){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n,m;
  while(cin >> n >> m){
    TSTART();
    Graph G(n);
    REP(i,m){
      int a,b;
      cin >> a >> b;
      a--;b--;
      G[a].push_back(Edge(a,b,0));
      G[b].push_back(Edge(b,a,0));
    }

    REP(i,n){
      cout << SZ(G[i]) << endl;
    }
    TSTOP();
  }
  return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstring>
#include <map>
#include <cmath>
#include <set>
#include <bitset>
using namespace std;

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

#define N 5010
#define X first
#define Y second

const int INF=1<<30;
const int Mod=1000000007;


int main()
{
	//freopen("in.in","r",stdin);
	//freopen("out.out","w",stdout);
	
	int x,i; cin >> x;
	for (i=1,x--;x>0;i++,x-=i); 
	printf("%d\n",i);
	
	return 0;
}

Measured memory_bytes: 256
n = gets.to_i;
array = (1..n).to_a;
P = gets.split.map(&:to_i);
Q = gets.split.map(&:to_i);

p_index = 0;
q_index = 0;
array.permutation(n).each.with_index do |v,i|
  p_index = i if P == v;
  q_index = i if Q == v;
end

ans = p_index - q_index;

puts ans.abs;

Measured memory_bytes: 14784
import java.text.DecimalFormat;
import java.util.stream.LongStream;
import java.util.stream.IntStream;
import java.io.*;
import java.util.*;

public class Main {

    public static void main(String[] args) {
        FastScanner sc = new FastScanner();
        PrintWriter out = new PrintWriter(System.out);

        AtCoder problem = new AtCoder(sc);
        problem.solve(out);

        out.flush();
    }

}

class AtCoder {

    int H, W, h, w;

    AtCoder(FastScanner sc) {
        H = sc.nextInt();
        W = sc.nextInt();
        h = sc.nextInt();
        w = sc.nextInt();
    }

    void solve(PrintWriter out) {
        out.println(H * W - (h * W + w * H) + h * w);
    }

}

// https://qiita.com/p_shiki37/items/a0f6aac33bf60f5f65e4
class FastScanner {

    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;

    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        } else {
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }

    private int readByte() {
        if (hasNextByte()) {
            return buffer[ptr++];
        } else {
            return -1;
        }
    }

    private static boolean isPrintableChar(int c) {
        return 33 <= c && c <= 126;
    }

    public boolean hasNext() {
        while (hasNextByte() && !isPrintableChar(buffer[ptr])) {
            ptr++;
        }
        return hasNextByte();
    }

    public String next() {
        if (!hasNext()) {
            throw new NoSuchElementException();
        }
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while (isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    public long nextLong() {
        if (!hasNext()) {
            throw new NoSuchElementException();
        }
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while (true) {
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            } else if (b == -1 || !isPrintableChar(b)) {
                return minus ? -n : n;
            } else {
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }

    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) {
            throw new NumberFormatException();
        }
        return (int) nl;
    }

    public double nextDouble() {
        return Double.parseDouble(next());
    }
}


Measured memory_bytes: 21460
import java.util.Scanner;

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

        int d = sc.nextInt();
        int n = sc.nextInt();

        long num = 1;
        if (d != 0) {
            num = 100;
            for (int i = 1; i < d; i++) {
                num *= 100;
            }
        }

      	if (n == 100)
          	n = 101;
        num *= n;

        System.out.print(num);
    }
}


Measured memory_bytes: 23764
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int a,b;
  cin>>a>>b;
  if(a==1){
    if(b==1)
      cout<<"Draw"<<endl;
    else
      cout<<"Alice"<<endl;
  }
  else if(b==1)
    cout<<"Bob"<<endl;
  else{
    if(a>b)
    cout<<"Alice"<<endl;
    if(a==b)
      cout<<"Draw"<<endl;
    if(a<b)
      cout<<"Bob"<<endl;
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
  int n,a,b;
  cin>>n>>a>>b;
  int mi=min(a,b);
  if(a+b>=n)
    cout<<mi<<" "<<a+b-n<<endl;
  else if(n==a && n==b)
    cout<<n<<" "<<n<<endl;
  else
    cout<<mi<<" "<<'0'<<endl;
  return 0;
}

Measured memory_bytes: 256