akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>

using namespace std;

int main(){
	int n, m, s, t, q, i, j;
	int id, color = 0;
	bool answer_yes = false;

	// enter
	cin >> n >> m;
	vector< vector<int> > Adj(n);
	vector<int> Stack;
	vector<int> Check(n, 0);
	vector<int>::iterator it, itend;
	for (i = 0; i < m; i++) {
		cin >> s >> t;
		Adj[s].push_back(t);
		Adj[t].push_back(s);
	}
	/*for (i = 0; i < n; i++) {
		cout << "\n" << i << " : " << flush;
		for (auto it2 = Adj[i].begin(); it2 != Adj[i].end(); it2++) {
			cout << *it2 << " " << flush;
		}
	}
	cout << endl;*/

	// calculate
	for (i = 0; i < n; i++) {
		if (Check[i] == 0) {
			color++;
			Stack.push_back(i);
			Check[i] = color;
			while (!Stack.empty()) {
				id = Stack.back();
				//cout << "\nid : " << id << " color : " << color << endl;
				itend = Adj[id].end();
				for (it = Adj[id].begin(); it != itend; it++) {
					if (!Check[*it]) {
						Stack.push_back(*it);
						Check[*it] = color;
						break;
					}
				}
				if (it == itend) {
					Stack.pop_back();
				}
			}
		}
	}

	//find
	cin >> q;
	for (i = 0; i < q; i++) {
		cin >> s >> t;		
		if (Check[s] == Check[t]) {
			cout << "yes" << endl;
		} else {
			cout << "no" << endl;
		}
	}
	
	return 0;
}

Measured memory_bytes: 9384
S = list(input())
N = len(S) + 1

ans_l = [-1] * N
ans_l[0] = 0
combo = 0
for i in range(N - 1):
    if S[i] == '<':
        combo += 1
    else:
        combo = 0
    ans_l[i + 1] = combo

ans_r = [-1] * N
ans_r[-1] = 0
combo = 0
for j in range(N - 1):
    i = N - 2 - j
    if S[i] == '>':
        combo += 1
    else:
        combo = 0
    ans_r[i] = combo

# print("#", ans_l)
# print("#", ans_r)
ans = [max(tmp_l, tmp_r) for tmp_l, tmp_r in zip(ans_l, ans_r)]

print(sum(ans))

Measured memory_bytes: 35760
#include <stdio.h>

int main() {
	
	int N = 0;
	scanf("%d",&N);
	
	int save = 0, count = 0;
	for( int i = 0; i < 4; i++ ){
		save = N % 10;
		if( save == 2 ){
			count++;
		}
		N = N / 10;
	}
	
	printf("%d",count);
	
	return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
#include <stdlib.h>

int linearSearch(int a[], int n, int key){
  int i;
  for(i = 0; i < n; i++){
    if(a[i] == key){
      return 1;
    }
  }
  return 0;
}

int main(void){
  int n, i, q, c = 0;
  int *a;
  int *b;

  scanf("%d", &n);
  a = (int *)malloc(n * sizeof(int));
  for(i = 0; i < n; i++){
    scanf("%d", &a[i]);
  }

  scanf("%d", &q);
  b = (int *)malloc(q * sizeof(int));
  for(i = 0; i < q; i++){
    scanf("%d", &b[i]);
  }

  for(i = 0; i < q; i++){
    c += linearSearch(a, n, b[i]);
  }

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

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

using namespace std;

const int Nmax = 3005, Mod = 1e9 + 7;
int i, red, n, m, dp[Nmax][Nmax][2], ans;

void add(int &x, int y)
{
    x += y;
    if(x >= Mod) x -= Mod;
}

int main()
{
  //  freopen("input", "r", stdin);

    cin >> n >> m;

    for(i=1; i<=n; ++i) dp[0][i][0] = 1;
    dp[0][0][1] = 1;

    for(i = 0; i <= m; ++i)
        for(red = 0; red <= n; ++red)
        {
            if(red)
            {
                add(dp[i+1][red-1][1], dp[i][red][1]);
                add(dp[i+1][red-1][red == 1], dp[i][red][0]);

                add(dp[i+1][red][1], dp[i][red][1]);
                add(dp[i+1][red][red == 1], dp[i][red][0]);
            }

            if(red < n)
            {
                add(dp[i+1][red+1][1], dp[i][red][1]);
                add(dp[i+1][red+1][0], dp[i][red][0]);

                add(dp[i+1][red][1], dp[i][red][1]);
                add(dp[i+1][red][0], dp[i][red][0]);
            }
        }

    for(i=0; i<=n; ++i) add(ans, dp[m][i][1]);
    cout << ans << '\n';

    return 0;
}


Measured memory_bytes: 70784
#include<iostream>
#include<math.h>
#include<cstdio>
using namespace std;
int main(){
	while(1){
		int n,cnt=0;
		int a,b,c,d;
		cin>>n;
		if(cin.eof()) {break;}
 		for(int a=0;a<=9;a++){
		  for(int b=0;b<=9;b++){
		    for(int c=0;c<=9;c++){
		       for(int d=0;d<=9;d++){
			  if(a+b+c+d==n) cnt++;
			}
		    }
		  }
		}
 	        cout<<cnt<<endl;
	}
	return 0;	
}

Measured memory_bytes: 1160
import std.stdio;
import std.algorithm;
import std.string;
import std.functional;
import std.array;
import std.conv;
import std.math;
import std.typecons;
import std.regex;
import std.range;

void main(){

    while(true){
	int h,w;
	string[] map;
	auto s = readln().split().to!(int[]);
	h = s[0];
	w = s[1];
	if(h==0&&w==0) break;
	for(int i=0;i<h;i++){
	    map ~= readln().chomp();
	}
	int x,y;
	int[101][101] used;
	while(true){
	    used[y][x] = true;
	    if(map[y][x] == '>') x++;
	    else if(map[y][x] == '<') x--;
	    else if(map[y][x] == '^') y--;
	    else if(map[y][x] == 'v') y++;
	    else if(map[y][x] == '.') {
		writeln(x," ",y);
		break;
	    }
	    if(used[y][x]){
		writeln("LOOP");
	    	break;
	    }
	}
    }
}

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

using namespace std;

int main() {
	int n;
	cin >> n;
	int freq[n+1];
	for (int i = 0; i <= n; i++) {
		freq[i] = 0;
	}
	int arr[n-1];
	for (int i = 0; i < n-1; i++) {
		cin >> arr[i];
		++freq[arr[i]];
	}
	for (int i = 1; i <= n; i++) {
		cout << freq[i] << endl;
	}
	
	
	return 0;
}

Measured memory_bytes: 5152
#include<bits/stdc++.h>
#define rep(i,n) for(int (i) = 0;(i) < (n);(i)++)
#define SORT(c) sort((c).begin(),(c).end())
#define MOD 1000000007 //S(vector).size()
using namespace std;
typedef long long ll;

int main(void){
  int m, d;
  cin >> m >> d;

  int d1 = d % 10;
  int d2 = d / 10;
  int cnt = 0;
  for(int ju = 2; ju < d2; ju++){
    for(int i = 2; i <= 9; i++){
      if(ju * i <= m){
        cnt++;
      }
    }
  }
  for(int i = 2; i <= d1; i++){
    if(i * d2 <= m) cnt++;
  }
  cout << cnt <<endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(v) v.begin(), v.end()
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define fs first
#define sc second

int comb(int n, int r) {
  int si = 1;
  int bo = 1;
  for (int i = 0; i < r; i++) {
    bo = (bo * (i + 1));
    si = (si * (n - i));
  }
  return si / bo;
}

int main(void){
  int m, n;
  cin >> m >> n;
  int ans = 0;
  if (m > 1) ans += comb(m, 2);
  if (n > 1) ans += comb(n, 2);
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for(ll i = 0; i < n; i++)
const ll INF = 100100100100;


ll combination(ll n, ll r){
    if(n < r) return 0;
    if(r == 0||r == n) return 1;
    else if(r == 1) return n;
    return (combination(n - 1, r - 1) + combination(n - 1, r));
}

bool checkKaibun(string str){
    string checkStr = str;
    reverse(checkStr.begin(), checkStr.end());
    if(str == checkStr) return true;
    else return false;
}

int keta(ll num){
    int digits = 0;
    while(num > 0){
        num /= 10;
        digits++;
    }
    return digits;
}


int main(){
    string A, B, C;
    cin >> A >> B >> C;
    int a, b, c;
    a = b = c = 0;
    int al, bl, cl;
    al = A.length();
    bl = B.length();
    cl = C.length();
    char turn = 'a';
    while(1){
        switch(turn){
            case 'a':
            if(a == al){
                cout << 'A' << endl;
                return 0;
            }
            turn = A[a];
            a++;
            break;
            case 'b':
            if(b == bl){
                cout << 'B' << endl;
                return 0;
            }
            turn = B[b];
            b++;
            break;
            case 'c':
            if(c == cl){
                cout << 'C' << endl;
                return 0;
            }
            turn = C[c];
            c++;
            break;
        }
    }

}

Measured memory_bytes: 256
S=list(input())
if 'N' in S and 'S' not in S:
    print('No')
elif 'S' in S and 'N' not in S:
    print('No')
elif 'W' in S and 'E' not in S:
    print('No')
elif 'E' in S and 'W' not in S:
    print('No')
else:
    print('Yes')

Measured memory_bytes: 61768
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <sstream>
#include <cmath>
#include <set>
#include <iomanip>
#include <deque>
using namespace std;
typedef long long ll;

#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define RREP(i,n) for(int (i)=(int)(n)-1;i>=0;i--)
#define FOREACH(i,Itr) for(auto (i)=(Itr).begin();(i)!=(Itr).end();(i)++)
#define REMOVE(Itr,n) (Itr).erase(remove((Itr).begin(),(Itr).end(),n),(Itr).end())
#define UNIQUE(Itr) sort((Itr).begin(),(Itr).end()); (Itr).erase(unique((Itr).begin(),(Itr).end()),(Itr).end())
#define LBOUND(Itr,val) lower_bound((Itr).begin(),(Itr).end(),(val))
#define UBOUND(Itr,val) upper_bound((Itr).begin(),(Itr).end(),(val))


int cnt[100010];
bool used[100010];

int main(){
    
    int N,Q; cin>>N>>Q;
    for(int i=1;i<=100000;i++)cnt[i]=i;
    REP(i,100010)used[i]=false;
   
    int pos=1;
    used[2]=true;
    REP(i,Q){
        int A,B; cin>>A>>B;
        if(A==pos){
            pos=B;
        }else if(B==pos){
            pos=A;
        }
        swap(cnt[A],cnt[B]);
        used[cnt[pos-1]]=used[cnt[pos]]=used[cnt[pos+1]]=true;
    }
    
    int ans=0;
    for(int i=1;i<=N;i++)if(used[i])ans++;
    cout<<ans<<endl;
    
    return 0;
}


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

using namespace std;
#define int long long
string h[729];
int ans1[729];
int ans2[729][729];
int ans3[729*729];
int sal1[729*729];
int sal(int ans)
{
    int y=1;
    int u=ans;
    while(ans!=0)
    {
        int x=ans%3;
        if(x==1)
        {
            u+=y;
        }
        else if(x==2)
        {
            u-=y;
        }
        ans/=3;
        y*=3;
    }
    return u;
}
int32_t main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    for(int i=0;i<729*729;++i)
    {
        sal1[i]=sal(i);
    }
    int n;
    cin>>n;
    int x=1;
    for(int i=0;i<n;++i)
    {
        x*=3;
    }
    n=12;
    string s;
    cin>>s;
    for(int i=0;i<729;++i)
    {
        int ans=i;
        for(int j=0;j<s.size();++j)
        {
            if(s[j]=='R')
            {
                ++ans;
                ans%=729;
                if(ans==0)
                {
                    h[i]+='R';
                }
            }
            else
            {
                ans=sal1[ans];
                h[i]+='S';
                if(h[i].size()>=2 && h[i][h[i].size()-2]=='S')
                {
                    h[i].erase(h[i].begin()+h[i].size()-1);
                    h[i].erase(h[i].begin()+h[i].size()-1);
                }
            }
        }
        //cout<<i<<" i "<<ans<<" ans "<<endl;
        ans1[i]=ans;
        //cout<<ans1[i]<<" ans1[i] "<<endl;
    }
    for(int i=0;i<729;++i)
    {
        for(int j=0;j<729;++j)
        {
            int ans=j;
            for(int k=0;k<h[i].size();++k)
            {
                if(h[i][k]=='S')
                {
                    ans=sal1[ans];
                }
                else
                {
                    ++ans;
                    ans%=729;
                }
            }
            ans2[i][j]=(ans*729+ans1[i]);
            ans3[i+729*j]=ans2[i][j];
        }
    }
    for(int i=0;i<x;++i)
    {
        cout<<ans3[i]%x<<" ";
    }
    return 0;
}


Measured memory_bytes: 17048
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;

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

const long double pi = 3.141592653589793;

#define debug(x) cout << #x << " = " << (x) << endl;
#define rep(i, n) for(int i = 0;i < n;i++)
#define pb push_back
#define mp make_pair
#define mod 1000000007

ll dp[310][310][310];
int n, m, maxm, minm, medm, y, z, x;

int A[5][5][310];

int main() {
	std::ios::sync_with_stdio(false);
    //freopen("input.in","r",stdin);
  	//freopen("output.out","w",stdout);
	cin>>n>>m;
	rep(i, n) {
		A[1][1][i+1] = A[2][1][i+1] = A[3][1][i+1] = 400;
		A[1][2][i+1] = A[2][2][i+1] = A[3][2][i+1] = 0;
	}

	rep(i, m) {
		cin>>x>>y>>z;
		A[z][1][y] = min(A[z][1][y], x);
		A[z][2][y] = max(A[z][2][y], x);
	}

	dp[0][0][0] = 1;
	rep(k, n+1)
	rep(i, n+1)
	rep(j, n+1) {
		if(dp[i][j][k] == 0) continue;
		maxm = max(i, max(j, k));
		minm = min(i, min(j, k));
		medm = i+j+k-maxm-minm;

		if(i+j+k == 0) {
			if(maxm+1 <= n)
				dp[maxm+1][j][k] =
				dp[i][maxm+1][k] =
				dp[i][j][maxm+1] = dp[0][0][0];
			continue;
		}

		// minm medm maxm
		if(A[1][1][maxm] != 400 && A[1][1][maxm] <= medm) {
			dp[i][j][k] = 0;
			continue;
		}
		if(A[2][1][maxm] != 400 && (A[2][1][maxm] <= minm || A[2][2][maxm] > medm)) {
			dp[i][j][k] = 0;
			continue;
		}
		if(A[3][1][maxm] != 400 && A[3][2][maxm] > minm) {
			dp[i][j][k] = 0;
			continue;
		}

		if(maxm+1 <= n) {
			dp[maxm+1][j][k] += dp[i][j][k];
			dp[i][maxm+1][k] += dp[i][j][k];
			dp[i][j][maxm+1] += dp[i][j][k];
			dp[maxm+1][j][k] %= mod;
			dp[i][maxm+1][k] %= mod;
			dp[i][j][maxm+1] %= mod;
		}
	}

	ll ans = 0;
	rep(i, n+1)
	rep(j, n+1)
	rep(k, n+1)
		if(i == n || j == n || k == n) ans = (ans+dp[i][j][k])%mod;

	cout<<ans<<endl;

	return 0;
}


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

int main(void){
    int num, i;
    string str;
    vector<int> v;
    v.resize(10);

    for(i = 0; i < 10; i++){
        cin >> v[i];
    }

    sort(v.begin(), v.end());
    for(int i = 1; i < 4; i++){
        cout << v[v.size() - i] << endl;
    }
}

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

typedef pair<int,int> pii;

int n,k;

vector<pii> adj;
int isi[105];

int main(){
	scanf("%d%d",&n,&k);
	if(k>((n-1)*(n-2)/2)){
		cout << "-1\n";
		return 0;
	}
//	adj.push_back(make_pair(1,2));
	int cur = (n-1)*(n-2)/2;
	for(int i=2;i<=n;i++) adj.push_back(make_pair(1,i));
	for(int i=2;i<=n;i++){
		for(int j=i+1;j<=n;j++){
			if(cur == k) break;
			adj.push_back(make_pair(i,j));
			cur--;
		}
	}
	cout << adj.size() << endl;
	for(int i=0;i<adj.size();i++){
		cout << adj[i].first << " " << adj[i].second << endl;
	}
	return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
using namespace std;
int main(){
  vector<int> a(3);
  int tmp=0;
  int tmp1;
  rep(i,3){
      cin >> a[i];
      if(tmp > a[i]) {
          tmp = a[i];
          tmp1 = i;
      }
  }
  int ans = 1000000000;
  tmp = 0;
  rep(i,3){
      tmp = 0;
      rep(j,3){
          tmp += abs(a[j]-a[i]);
          tmp1 = a[j];
      }
      ans = min(ans,tmp);
  }
  cout << ans << endl;
  return 0; 

}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<queue>
#include<stack>
#include<string>
#include<cmath>
#include<algorithm>
#include<bitset>
#include<map>
#include<functional>
#include<set>
#include<numeric>

#pragma region
using namespace std;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define rep(i,n) FOR(i,0LL,n)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define rrep(i,n) RFOR(i,0LL,n)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define COUNT(a,x,y) upper_bound(all(a), y) - lower_bound(all(a), x)
#define UNIQUE(a) sort(all(a)); a.erase(unique(all(a)), a.end())
#define SUM(a) accumulate(all(a),0LL)
#define scan(x) scanf("%lld",&x)
#define pb push_back
typedef long long int ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<string> vs;
typedef map<ll, ll> MAP;
typedef set<ll> SET;
typedef double D;
const ll inf = 2222222222222222222LL;
const ll mod = 1000000007LL;
const D pi = acos(-1);
const D eps = 1e-10;

ll n = 0, m = 0, ans = 0, cnt = 0, tmp = 0, ma = -inf, mi = inf;
string s;
bool ok, flag;
ll dx[5] = { 1,-1,0,0,0 }, dy[5] = { 0,0,1,-1,0 };
ll ddx[9] = { 1,-1,0,0,1,1,-1,-1,0 }, ddy[9] = { 0,0,1,-1,1,-1,1,-1,0 };
#pragma endregion
#define MAX 111111

vll edge[MAX];

int main(void) {

  cin >> n >> m;
  MAP mp;
  rep(i, m) {
	ll a, b;
	cin >> a>> b;
	edge[a].pb(b);
  }

  FOR(i, 1, n + 1) {
	if (mp[i]) {
	  ans++;
	  mp.clear();
	}
	rep(j, edge[i].size()) mp[edge[i][j]]++;
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 8704
#include<iostream>
#include<vector>
#include<cstring>
#include<algorithm>
#include<math.h>
#include<queue>
#include<deque>
#include<map>

#define rep(i, n) for(int i = 0;i < (n);i++)
#define rrep(i, n) for(int i = (n);i >= 0;i--)
#define FOR(i, m, n) for(int i = (m);i < (n);i++)

using namespace std;
using ll = long long;

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 (b<a) { a=b; return 1;} return 0;}

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


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

ll dp[19][2];

int main() {
    ll n; cin >> n;
    string s = to_string(n);
    int len = s.size();

    memset(dp, -1, sizeof(dp));
    dp[0][0] = 0;

    for (int i = 0; i < len; i++)
    {
        int d = s[i] - '0';
        // cout << 'i' << endl;
        for (int j = 0; j < 2; j++) {
            if (dp[i][j] == -1) continue;
            for (int k = 0; k <= (j ? 9 : d); k++) {
                chmax(dp[i+1][j || (k<d)], dp[i][j] + k); 
            }
        }
        // for (int j = 0; j < 2; j++)
        // {
        //     cout << dp[i+1][j] << endl;
        // }
        
    }
    
    cout << max(dp[len][1], dp[len][0]) << endl;

    return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <cstring>
#include <numeric>
#include <algorithm>
#include <fstream>
#include <functional>
#include <array>
#include <map>
#include <queue>
#include <time.h>
#include <limits.h>
#include <set>
#include <stack>
#include <random>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#define rep(i,s,n) for(int i = (s); (n) > i; i++)
#define REP(i,n) rep(i,0,n)
#define RANGE(x,a,b) (min(a,b) <= (x) && (x) <= max(a,b)) //hei
#define DUPLE(a,b,c,d) (RANGE(a,c,d) || RANGE(b,c,d) || RANGE(c,a,b) || RANGE(d,a,b))
#define INCLU(a,b,c,d) (RANGE(a,c,d) && (b,c,d))
#define PW(x) ((x)*(x))
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define MODU 1000000007LL
#define bitcheck(a,b)   ((a >> b) & 1)
#define bitset(a,b)      ( a |= (1 << b))
#define bitunset(a,b)    (a &= ~(1 << b))
#define MP(a,b) make_pair((a),(b))
#define Manh(a,b) (abs((a).first-(b).first) + abs((a).second - ((b).second))
#define pritnf printf
#define scnaf scanf
#define itn int
#define PI 3.141592653589


#define izryt bool
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T & val) {
	std::fill((T*)array, (T*)(array + N), val);
}
pll Dir[4] = {
	{ -1 ,0 },{ 0 , 1 },{ 1 ,0 },{ 0 ,-1 }
};

//[a, b)
#define Getsum(ar, a,b) (ar[b] - ar[a])
#define chmax(a,b) a = max(a,b)
#define chmin(a,b) a = min(a,b)

struct Edge {
	int from, to;
	ll w;
	bool operator<(const Edge& rhs) const {
		return MP(w, MP(from, to)) < MP(rhs.w, MP(rhs.from, rhs.to));
	}

};
typedef vector<vector<Edge>> Graph;

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

ll facmemo[200000] = {};

ll factorial(ll n) {//階乗
	if (facmemo[n] != 0) return facmemo[n];
	if (n == 0) return 1;
	ll ret = n * factorial(n - 1);
	ret %= MODU;
	return facmemo[n] = ret;
}

ll mod_pow(ll x, ll n, ll mod) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res * x %mod;
		x = x * x%mod;
		n >>= 1;
	}
	return res;
}
ll divmod(ll a, ll b, ll m) { // a/b(mod m)
								  // a/b (mod m)
								  // a*b^-1
								  // b^-1 * b = 1
								  // b^(m-1) = 1 
								  // b^(m-2) * b = 1
								  // b^-1 = b^(m-2)

								  // a/b = a * b^(m-2)

	return (a * 1LL * mod_pow(b, m - 2, m)) % m;
}
ll ncr(ll n, ll r) {
	if (r == 0) return 1;
	if (n < r) return 1;
	return divmod(factorial(n), (factorial(r) * (factorial(n - r))) % MODU, MODU);
}

bool sankaku(int a, int b, int c) {
	return a <= b + c && b <= a + c && c <= b + a;
}
ll lcm(ll m, ll n)
{
	return m * n / gcd(m, n);
}

signed main() {
	int n;
	int cou[10][10] = {};
	cin >> n;

	rep(i,1, n + 1) {
		int last = i % 10;
		int fist = i;
		while (fist >= 10) {
			fist /= 10;
		}
		cou[fist][last]++;
	}

	ll ans = 0;
	rep(i, 1,10) {
		rep(j, 1,10) {
			ans += cou[i][j] * cou[j][i];
		}
	}
	cout << ans << endl;
	return 0;
}


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

N, K = map(int, input().split())
A = list(map(int, input().split()))
MOD = 10**9+7
p, n = [], []

for i in range(N):
    if A[i]>=0:
        p.append(A[i])
    else:
        n.append(A[i])

ok = False

if len(p)>0:
    if N==K:
        if len(n)%2==0:
            ok = True
    else:
        ok = True
else:
    if K%2==0:
        ok = True

if not ok:
    A.sort(key=lambda x: abs(x))
    ans = 1
    
    for Ai in A[:K]:
        ans *= Ai
        ans %= MOD

    print(ans)
    exit()

p.sort(reverse=True)
n.sort()

if K%2==1:
    ans = p[0]
    p = p[1:]
else:
    ans = 1
    
l = []
    
for i in range(len(p)//2):
    l.append(p[2*i]*p[2*i+1])
    
for i in range(len(n)//2):
    l.append(n[2*i]*n[2*i+1])

l.sort(key=lambda x: abs(x), reverse=True)

for li in l[:K//2]:
    ans *= li
    ans %= MOD
    
print(ans)


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

int main(){
  
  while(1){
    int n=0;
    pair <int,int> a[201] ={};
    cin >>n;
    if(n == 0)break;
    int xmax=0,xmin=0,ymax=0,ymin=0;
    a[0]=make_pair(0,0);
    for(int i=1;i<n;i++){
      int num=0,hougaku=0;
      cin >> num >> hougaku;
      if(hougaku ==0){a[i].first =a[num].first - 1;
	a[i].second =a[num].second;}
      if(hougaku ==1){a[i].second=a[num].second - 1;
	a[i].first=a[num].first;}
      if(hougaku ==2){a[i].first =a[num].first + 1;
	a[i].second =a[num].second;}
      if(hougaku ==3){a[i].second=a[num].second + 1;
	a[i].first=a[num].first;}
      xmax=max(xmax,a[i].first);
      xmin=min(xmin,a[i].first);
      ymax=max(ymax,a[i].second);
      ymin=min(ymin,a[i].second);
    }

    cout << xmax - xmin + 1 <<" " << ymax - ymin +1 << endl;
   
  }




}



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

using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
#define REP(i,N) for(int i=0;i<N;i++)

int main()
{
    int n; cin>>n;
    vector<pair<int,int>> v(n,{0,0});
    vector<pair<int,int>> w(n,{0,0});
    for(int i=0;i<n;i++){
        cin>>v[i].first>>v[i].second;
    }
    sort(all(v), [](pair<int,int> a, pair<int,int> b){return a.second<b.second;});
    set<int> visited;
    w[0] = v[0];
    for(int i=1;i<n;i++){
        w[i] = {w[i-1].first + v[i].first, v[i].second};
    }
    bool b = false;
    for(int i=0;i<n;i++){
        if(w[i].first>w[i].second){
            b = true;
            cout<<"No"<<endl;
            break;
        }
    }
    if(!b){
        cout<<"Yes"<<endl;
    }
    return 0;
}


Measured memory_bytes: 3328
n = gets.to_i
xs = gets.strip.split.map(&:to_i)
sorted = xs.sort.reverse

median = sorted[(n + 1) / 2 - 1]
median2 = sorted[(n + 1) / 2]

xs.each do |x|
  if x < median
  then
    puts median
  else
    puts median2
  end
end


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

// int/long:		-2,147,483,648 - 2,147,483,647 (-2^31 <= int < 2^31)
// long/long long:	-9,223,372,036,854,775,808 - 9,223,372,036,854,775,807 (-2^63 <= long < 2^63)

// lower_bound(A.begin(), A.end(), N)
// upper_bound(...

// A.erase(unique(A.begin(), A.end()), A.end())

// bit: &/and, |/or, ^/xor, ~/not

// getline(cin, String)
// while (getline(cin, S)) {}

// cout <<fixed <<setprecision(10)

// priority_queue<int> q;
// priority_queue<int, vector<int>, less<int>> q; // Default: vector, less
// priority_queue<vector<int>, vector<vector<int>>, greater<vector<int>>> q;

// Graph
// Warshall-Floyd: Distance between each node, N^3
// Dijkstra: Distance from the start node, N^2
// DFS(Depth-First Search)

//
// Notes
//
// When specified less than N, try full scan.
// RE: empty vector
// Check Qs
// long/int
// xor -> count each bit
// Check values
// 	1,000,000 -> Loop
// 	100,000	-> vector(int:400KB, long:800KB) 

#define	INF (1<<30)
//1,073,741,824
//= 536,870,912 *2

#define	MOD 1000000007

#define	Rep0(i, n)	for (int i=0; i<n; i++)
#define	Rep1(i, n)	for (int i=1; i<=n; i++)
#define Sort(P)	sort(P.begin(), P.end())
#define Rev(P)	reverse(P.begin(), P.end())

void unique_count(vector<int> &a, vector<vector<int>> &b) {
	// erase(b.begin(), b.end());
	for (int i=0; i<a.size(); i++)
		if ((i>0)&&(a.at(i)==a.at(i-1)))
			b.back().at(1)++;
		else
			b.push_back({a.at(i), 1});
	return;
}

int	main() {
	int N;
	cin >>N;
	vector<int> A(N, 0);
	Rep0(i, N)
		cin >>A.at(i);
	Sort(A);
	vector<vector<int>> B;
	unique_count(A, B);
	if (A.size()==B.size())
		cout <<"YES" <<endl;
	else
		cout <<"NO" <<endl;
	return 0;
}



Measured memory_bytes: 13232
#include <bits/stdc++.h> // only for GCC
using namespace std;

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

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

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef unsigned long long ULL;

#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())

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

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

#define CLR(a) memset((a), 0 ,sizeof(a))

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

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

int main() {
  int b, r, g, c, s, t;
  
  while(cin >> b >> r >> g >> c >> s >> t, b+r+g+c+s) {
    int coin = 100;
    
    int bonus = b*5 + r*3;
    REP(i, bonus) coin += 13;
    coin += (b+r) * 12 + c * -1 + g * 4;
    
    t -= b + r + g + c + s + bonus;
    coin -= 3 * t;
    cout<< coin << endl;
  }
}

Measured memory_bytes: 1160
import java.util.*;
 
public class Main {
 
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
 
        while(true){
            int n = sc.nextInt();
            if(n==0) break;
            int[] ans = new int[86401];
             
            for(int i=0;i<n;i++){
                String s = sc.next();
                String t = sc.next();
                int a = Integer.valueOf(s.substring(0,2))*3600 + Integer.valueOf(s.substring(3,5))*60 + Integer.valueOf(s.substring(6,8));
                int b = Integer.valueOf(t.substring(0,2))*3600 + Integer.valueOf(t.substring(3,5))*60 + Integer.valueOf(t.substring(6,8));  
                for(int j=a;j<b;j++) ans[j]++;
            }   
            Arrays.sort(ans);
            System.out.println(ans[86400]);
        }
    }
}

Measured memory_bytes: 69204
#include <iostream>
#include <string>
#include <stack>
#include <sstream>
using namespace std;

int main(){ 
    stack<int> s;

     while(1){
        string c; cin >> c;
        if(cin.eof())
            break;
        
        if(c=="+"){
            int x(0);
            x += s.top();
            s.pop();
            x += s.top();
            s.pop();
            s.push(x);
        }else if(c=="-"){
            int x = s.top();
            s.pop();    
            x = s.top() - x;
            s.pop();
            s.push(x);
        }else if(c=="*"){
            int x = s.top();
            s.pop();
            x *= s.top();
            s.pop();
            s.push(x);
        }else{
            istringstream is2(c);
            int x;
            is2 >> x;
            s.push(x);
        }
    }

    cout << s.top() << endl;
    return 0; 
}


Measured memory_bytes: 3176
#include <stdio.h>
#include <string.h>
 
int main(){
	int x,ac,wa,tle,re;
	char c[16];
	ac=wa=tle=re=0;
	scanf("%d",&x);
	for(int i=0; i<x; i++){
		scanf("%s",&c);
		if (strcmp(c,"AC") == 0) ac++;
		else if (strcmp(c,"WA") == 0) wa++;
		else if (strcmp(c,"TLE") == 0) tle++;
		else if (strcmp(c,"RE") == 0) re++;
	}
	printf("AC x %d\n", ac);
	printf("WA x %d\n", wa);
	printf("TLE x %d\n", tle);
	printf("RE x %d\n", re);
 
	return 0;
}

Measured memory_bytes: 1700
def digitSum(n):
    s = str(n)
    array = list(map(int, s))
    return sum(array)

N = int(input())
answer = float("inf")
for i in range(1,N//2+1):
  A = i 
  B = N - A
  answer = min(answer, digitSum(A) + digitSum(B))

print(answer)
  

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

using namespace std;

int main()
{
    int n, m, result_val = 0;
    string buf;
    map<string, int> cards;

    cin >> n;
    for(int i = 0; i < n; ++i) {
        cin >> buf;
        cards[buf]++;
    }
    cin >> m;
    for(int i = 0; i < m; ++i) {
        cin >> buf;
        cards[buf]--;
    }

    for(pair<string, int> card : cards) {
        result_val = max(result_val, card.second);
    }

    cout << result_val << endl;
    return 0;
}


Measured memory_bytes: 256
N = int(input())
S = list(input())

S = list(S)
res = 0
for i in range(1, N):
    S1 = set(S[:i])
    S2 = set(S[i:])
    if(len(S1.intersection(S2)) > res):
        res = len(S1.intersection(S2))

print(res)


Measured memory_bytes: 3060
package main

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

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func getNextUint64(scanner *bufio.Scanner) uint64 {
	i, _ := strconv.ParseUint(getNextString(scanner), 10, 64)
	return i
}

func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}

func main() {
	fp := os.Stdin
	wfp := os.Stdout

	if len(os.Args) > 1 {
		fp, _ = os.Open(os.Args[1])
		if len(os.Args) > 2 {
			wfp, _ = os.Create(os.Args[2])
		}
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(wfp)

	q := getNextInt64(scanner)
	h := getNextInt64(scanner)
	s := getNextInt64(scanner)
	d := getNextInt64(scanner)

	tt := Teas{
		Tea{
			unit:  1,
			price: q,
		},
		Tea{
			unit:  2,
			price: h,
		},
		Tea{
			unit:  4,
			price: s,
		},
		Tea{
			unit:  8,
			price: d,
		},
	}

	sort.Sort(tt)

	n := getNextInt64(scanner) * 4

	var ans int64

	for _, t := range tt {
		ans += (n / t.unit) * t.price
		n %= t.unit
	}

	fmt.Fprintln(writer, ans)
	writer.Flush()
}

type Tea struct {
	unit, price int64
}

type Teas []Tea

func (a Teas) Len() int           { return len(a) }
func (a Teas) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
func (a Teas) Less(i, j int) bool { return a[i].price*8/a[i].unit < a[j].price*8/a[j].unit }


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#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())

int main() {
  int n;
  cin >> n;
  repn(i,10001){
    if(i>n){break;}
    if (i%3==0){
      cout << " " << i;
      continue;
      }
    int x = i;

    while(x>0){
      if (x%10==3){
        cout << " " << i;
        break;
        }
      x/=10;
    }
    
  }
  cout << endl;
  
}


Measured memory_bytes: 3096
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <bitset>
#include <random>
#include <complex>
#include <assert.h>

using namespace std;
typedef long long ll;

template<typename T>
inline bool chmin(T& x, T a) {
	if (x >= a) { x = a; return true; }
	return false;
}

template<typename T>
inline bool chmax(T& x, T a) {
	if (x <= a) { x = a; return true; }
	return false;
}

/////////////         modの計算

#define MOD_IS_PRIME
const ll mod = 998244353LL;

inline ll mod_adjust(ll a) {
	if (a >= mod) {
		return a % mod;
	}
	if (a < 0) {
		a *= -1;
		a--;
		if (a >= mod) { a %= mod; }
		a++;
		return mod - a;
	}
	return a;
}
inline ll mod_add(ll a, ll b) {
	return mod_adjust(a % mod + b % mod);
}
inline ll mod_sub(ll a, ll b) {
	return mod_adjust(a % mod - b % mod);
}
inline ll mod_multi(ll a, ll b) {
	return mod_adjust(mod_adjust(a) * mod_adjust(b));
}

int main() {
	int N, S; cin >> N >> S;
	vector<int> a(N, 0);
	for (int i = 0; i < N; i++) {
		cin >> a[i];
	}
	vector<vector<ll>> v(N);
	for (int i = 0; i < N; i++) {
		v[i].resize(S + 1);
		for (int j = 0; j <= S; j++) {
			v[i][j] = 0;
		}
	}

	ll ans = 0;
	if (a[0] <= S) {
		v[0][a[0]] = 1;
	}
	for (int i = 1; i < N; i++) {
		if (a[i] == S) {
			ans = mod_add(ans, mod_multi(i + 1, N - i));
		}
		else if (a[i] < S) {
			ans = mod_add(ans, mod_multi(v[i - 1][S - a[i]], N - i));
		}
		for (int j = 1; j <= S; j++) {
			v[i][j] = v[i - 1][j];
		}
		for (int j = a[i] + 1; j <= S; j++) {
			v[i][j] = mod_add(v[i][j], v[i - 1][j - a[i]]);
		}
		if (a[i] <= S) {
			v[i][a[i]] = mod_add(v[i][a[i]], i + 1);
		}
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 70784
n, m = map(int, input().split())
ans = n * m

if n > 1 or m > 1:
    if n >= 2 and m >= 2:
        ans -= 4
    else:
        ans -= 2

if n > 1:
    ans -= max((m - 2) * 2, 0)

if m > 1:
    ans -= max((n - 2) * 2, 0)

print(ans)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define int long long
using namespace std;
int n,m,a[500][500],f[500],flag[500],ans;
bool fk[500],ff;
int read(){
	char c=getchar();while (c!='-'&&(c<'0'||c>'9'))c=getchar();
	int kk=1,k=0;if (c=='-')kk=-1,c=getchar();
	while (c>='0'&&c<='9')k=k*10+c-'0',c=getchar();return kk*k;
}
signed main(){
	n=read();m=read();for (int i=1;i<=n;i++)for (int j=1;j<=m;j++)a[i][j]=read();
	for (int i=1;i<=n;i++)f[i]=1,flag[a[i][1]]++;ff=1;ans=1e9;
	while (ff){
		int k=0;for (int i=1;i<=m;i++)if (flag[i]>flag[k])k=i;
		if (k==0)break;ans=min(ans,flag[k]);fk[k]=1;
		for (int i=1;i<=n;i++){
			while (fk[a[i][f[i]]]&&f[i]<n+1)flag[a[i][f[i]]]--,f[i]++,flag[a[i][f[i]]]++;
			ff&=f[i]<n+1;
		}
	}cout<<ans<<endl;
}


Measured memory_bytes: 1408
import std.functional,
       std.algorithm,
       std.bigint,
       std.string,
       std.traits,
       std.array,
       std.range,
       std.stdio,
       std.conv;

void main() {
  ulong[] XY = readln.chomp.split.to!(ulong[]);
  ulong X = XY[0],
        Y = XY[1];
  ulong n;

  while (X*2^^n <= Y) {
    n++;
  }

  writeln(n);
}


Measured memory_bytes: 256
#幅優先探索（BFS）を利用
# 頂点と辺の数を入力する
N, M = map(int, input().split())
# 隣接リストを作成する
list_adjlist = [[] for _ in range(N + 1)]
# 辺のリストを作成する
list_edge = []
# 辺を入力し、隣接リストおよび辺のリストに格納する
for _ in range(M):
    a, b = map(int, input().split())
    list_edge.append((a, b))
    list_adjlist[a].append(b)
    list_adjlist[b].append(a)

def FIFO(list_FIFO, node):
    if node != None:
        list_FIFO.append(node)
        return None
    return list_FIFO.pop(0)

# 橋の総数（all_bridge）を初期化する
all_bridge = 0

# uv間の辺がなくても、uからvへたどり着けるか探索
for u, v in list_edge:
    # uv間の辺が橋かどうか（uv_bridge）を初期化する（初期状態：1＝橋である）
    uv_bridge = 1
    # FIFOキューを初期化する
    list_FIFO = []
    # FIFOキューに入れたことのある点かどうかをチェックするリスト（list_check）を初期化する
    list_check = [False] * (N + 1)
    # FIFOキューにuを追加する
    FIFO(list_FIFO, u)
    # uをFIFOキューに入れた点としてチェックする
    list_check[u] = True
    # FIFOキューが空でない、かつvにたどり着いていない限り、幅優先探索
    while list_FIFO != [] and list_FIFO[-1] != v:
        # FIFOキューから点（node）を取り出す
        node = FIFO(list_FIFO, None)
        # nodeの隣接点（adjnode）について繰り返す
        for adjnode in list_adjlist[node]:
            # adjnodeがFIFOキューに入れたことのある点だった場合
            if list_check[adjnode]:
                # 以降の処理は行わずに次の隣接点に移る
                continue
            # adjnodeがvだった場合
            if adjnode == v:
                # nodeがuでない場合
                if node != u:  
                    # uv_bridgeを更新する（0＝橋でない）
                    uv_bridge = 0
                    # FIFOキューにadjnodeを追加する
                    FIFO(list_FIFO, adjnode)
                    # 繰り返しを終了する
                    break
            # adjnodeがv出ない場合
            else:
                # FIFOキューにadjnodeを追加する
                FIFO(list_FIFO, adjnode)
                # adjnodeをFIFOキューに入れた点としてチェックする
                list_check[adjnode] = True
    # all_bridgeにuv_bridgeを加える
    all_bridge += uv_bridge
                
# all_bridgeを出力する
print(all_bridge)      

Measured memory_bytes: 3064
h,w = map(int, input().split())
ans_min = 10 ** 10
if h % 3 == 0 or w % 3 == 0:
	ans_min = 0

else:
	for a in range(w+1):
		sa = h * a
		if h % 2 == 0:
			sb = (w-a) * (h // 2)
			sc = (w-a) * (h // 2)
		else:
			sb = (w-a) * (h // 2 + 1)
			sc = (w-a) * (h // 2)
		ans = max(sa,sb,sc) - min(sa,sb,sc)
		if ans_min > ans:
			ans_min = ans

	for a in range(h+1):
		sa = w * a
		if w % 2 == 0:
			sb = (h-a) * (w // 2)
			sc = (h-a) * (w // 2)
		else:
			sb = (h-a) * (w // 2 + 1)
			sc = (h-a) * (w // 2)
		ans = max(sa, sb, sc) - min(sa, sb, sc)

		if ans_min > ans:
			ans_min = ans
if ans_min > h:
	ans_min = h
if ans_min > w:
	ans_min = w
print(ans_min)

Measured memory_bytes: 3188
N=int(input())
A=list(map(int,input().split()))
B = list(map(int, input().split()))
c=0
for i in range(N):
    m=min(A[i],B[i])
    A[i]-=m
    B[i]-=m
    c+=m
    if B[i]>=0:
        M=min(A[i+1],B[i])
        A[i+1]-=M
        B[i]-=M
        c+=M
print(c)


Measured memory_bytes: 18624
#include <bits/stdc++.h>
using namespace std;
int main(void){
    // Your code here!
    int n;cin>>n;
    map<int,int>m;
    for(int i=0;i<n;i++)
    {
        int k;cin>>k;
        m[k-1]+=1;
        m[k]+=1;
        m[k+1]+=1;
        
    }
    int max=-1;
    for(auto x: m)
    {
        max = max<x.second ? x.second:max;
        
    }
    
    cout<<max;
    return 0;
}


Measured memory_bytes: 4736
#      
import collections, atexit, math, sys, bisect 

sys.setrecursionlimit(1000000)
def getIntList():
    return list(map(int, input().split()))    

try :
    #raise ModuleNotFoundError
    import numpy
    def dprint(*args, **kwargs):
        #print(*args, **kwargs, file=sys.stderr)
        # in python 3.4 **kwargs is invalid???
        print(*args,  file=sys.stderr)
    dprint('debug mode')
except Exception:
    def dprint(*args, **kwargs):
        pass



inId = 0
outId = 0
if inId>0:
    dprint('use input', inId)
    sys.stdin = open('input'+ str(inId) + '.txt', 'r') #标准输出重定向至文件
if outId>0:
    dprint('use output', outId)
    sys.stdout = open('stdout'+ str(outId) + '.txt', 'w') #标准输出重定向至文件
    atexit.register(lambda :sys.stdout.close())     #idle 中不会执行 atexit
    
 
#print(N)
S = input()
r = 0
tb = 0
for c in S:
    if c== 'B':
        tb+=1
    else:
        r += tb

print(r)







Measured memory_bytes: 41564
N,M,C=map(int,input().split())
b=list(map(int,input().split()))
ans=0

for i in range(N):
    temp=C
    a=list(map(int,input().split()))
    for j in range(M):
        temp+=a[j]*b[j]
    if temp>0:
        ans+=1
    
print(ans)


Measured memory_bytes: 3060
#include<iostream>
#include<string>

using namespace std;

int main() {
	int ans = 0;
	string s;
	cin >> s;
	char tmp = s[0];
	for (int i = 1; i < s.size(); i++) {
		if (tmp != s[i]) {
			ans++;
			tmp = s[i];
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <iomanip> //! for setprecision(10)
#include <math.h>
#include <algorithm>
#include <functional> 
#include <string>
#include <vector>

#include <cstring>
#include <set>
#include <map>
#include <queue>
#include <utility>

using namespace std;

typedef long long LL;

#define dump(c) { for (auto it = c.begin(); it != c.end(); ++it) if (it == c.begin()) cout << *it; else cout << ' ' << *it; cout << endl; } 
#define rep(i,n) for (int i = 0; i < (n); ++i)

const int MOD = 1000000007;

int N, K, C;
string S;

int dp[200005]; //! max days Mr Takahashi can work from i-th day
int last[200005]; //! last working day for i

int dp2[200005]; //! max days Mr Takahashi can work from tomrrow until i-th day

//! return true if Mr Takahashi can work K days even if he does not work on off-th day
bool check(int off)
{
    int before = dp[off-1];
    int lastWorkingDay = last[off-1];
    int firstWorkableDay = max(off+1, lastWorkingDay+C);
    int after = dp2[firstWorkableDay];
    // cout << "off = " << off << ", befoe = " << before << ", lastWorkingDay = " << lastWorkingDay << ", firstWorkableDay = " << firstWorkableDay << ", after =" << after << ", before+after = " << (before+after) << endl;
    return (K <= before + after);
}

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

    cin >> N >> K >> C >> S;

    int prev = -999999;
    last[0] = prev;
    for (int i = 1; i <= N; ++i) {
        if (S[i-1] != 'x' && prev+C < i) {
            dp[i] = dp[i-1]+1;
            last[i] = i;
            prev = i;
        } else {
            dp[i] = dp[i-1];
            last[i] = last[i-1];
        }
    }
    int next  = 999999;
    for (int i = N; 1 <= i; --i) {
        if (S[i-1] != 'x' && i < next-C) {
            dp2[i] = dp2[i+1]+1;
            next = i;
        } else {
            dp2[i] = dp2[i+1];
        }
    }

    // cout << "dp--------" << endl;
    // for (int i = 1; i <= N; ++i) {
    //     cout << dp[i] << ' ';
    // }
    // cout << endl;

    // cout << "last--------" << endl;
    // for (int i = 1; i <= N; ++i) {
    //     cout << last[i] << ' ';
    // }
    // cout << endl;

    // cout << "dp2--------" << endl;
    // for (int i = 1; i <= N; ++i) {
    //     cout << dp2[i] << ' ';
    // }
    // cout << endl;

    for (int off = 1; off <= N; ++off) {
        if (!check(off)) {
            cout << off << endl;
        }
    }

    return 0;
}


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

int main(){
    int A, B;
    cin >> A >> B;

    if(A % 3 == 0 || B % 3 == 0 || (A + B) % 3 == 0){
        cout << "Possible" <<endl;
    }
    else{
        cout << "Impossible" << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
template<class T>inline bool chmax(T &a, const T &b){if(a < b){a = b; return 1;}return 0;}
template<class T>inline bool chmin(T &a, const T &b){if(a > b){a = b; return 1;}return 0;}
typedef long long ll;
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  // ABC079C - Train Ticket
  string S; cin >> S;
  int A, B, C, D;
  A = S[0] - '0';
  B = S[1] - '0';
  C = S[2] - '0';
  D = S[3] - '0';
  vector<int> BCD = {B, C, D};
   
  int ans = A;
  bool flag = false;
  string op = to_string(A);
  REP(i, 1 << 3){
    REP(j, 3){
      if((i >> j) & 1 == 1){
        ans += BCD[j];
      }else{
        ans -= BCD[j];
      }
    }
    if(ans == 7){
      REP(k, 3){
        if((i >> k) & 1 == 1){
          op += "+" + to_string(BCD[k]);
        }else{
          op += "-" + to_string(BCD[k]);
        }
      }
      cout << op + "=7" << endl;
      return 0;
    }
    ans = A; // 初期化を忘れずに
  }
}

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

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define itn int

typedef long long ll;
typedef pair<ll,ll> p;


int main()
{
  string s;
  cin >> s;
  int n = 0;
  int w = 0;
  int x = 0;
  int e = 0;
  for (int i = 0; i < int(s.size()); i++) {
    if(s[i] == 'N') n++;
    if(s[i] == 'W') w++;
    if(s[i] == 'S') x++;
    if(s[i] == 'E') e++;
  }

  if(n > 0 && w > 0 && x > 0 && e > 0) cout << "Yes" << endl;
  else if((n == 0 && x == 0) && (w > 0 && e > 0)) cout << "Yes" << endl;
  else if((n > 0 && x > 0) && (w == 0 && e == 0)) cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 256
import java.awt.*;
import java.util.*;

public class Main {

    public static void main(String args []) {

        Scanner scan = new Scanner(System.in);

        int h = scan.nextInt();
        int w = scan.nextInt();
        int ch = scan.nextInt() -1;
        int cw = scan.nextInt() -1;
        int dh = scan.nextInt() -1;
        int dw = scan.nextInt() -1;

        Point start = new Point(ch, cw);
        ArrayDeque<Point> dq = new ArrayDeque<>();
        ArrayDeque<Point> magicDq = new ArrayDeque<>();
        Point[] move = {new Point(0,-1), new Point(1,0), new Point(0,1), new Point(-1,0)};
        dq.add(start);

        char[][] map = new char[h][w];
        int [][] magicCount = new int[h][w];
        int [][] visited = new int[h][w];
        visited[ch][cw] = 1;

        for (int i = 0; i<h; i++) {

            map[i] = scan.next().toCharArray();
        }

        map[ch][cw] = '#';

        while(dq.size()>0) {

            Point a = dq.removeFirst();
            magicDq.addLast(a);

            for (int i=0; i<4; i++) {
                int x = a.x + move[i].x;
                int y = a.y + move[i].y;

                if (x <0 || x>=h || y<0 || y>=w) {
                    continue;
                }

                if (map[x][y] == '.') {
                    dq.addLast(new Point(x,y));
                    visited[x][y] = 1;
                    magicCount[x][y] = magicCount[a.x][a.y];
                    map[x][y] = '#';
                }
            }

            if (dq.isEmpty()) {

                while(magicDq.size()>0) {
                    Point b = magicDq.removeFirst();
                    for (int i = -2; i <= 2; i++) {

                        for (int j = -2; j <= 2; j++) {
                            int x = b.x + i;
                            int y = b.y + j;

                            if (x < 0 || x >= h || y < 0 || y >= w) {
                                continue;
                            }

                            if (map[x][y] == '.') {
                                dq.addLast(new Point(x, y));
                                map[x][y] = '#';
                                magicCount[x][y] = magicCount[b.x][b.y] + 1;
                                visited[x][y] = 1;
                            }
                        }
                    }
                }
            }
        }

        if (visited[dh][dw] > 0) {
            System.out.println(magicCount[dh][dw]);

        } else {
            System.out.println(-1);
        }

    }
}


Measured memory_bytes: 66432