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


#define ll long long
#define ld long double
#define pb push_back
#define all(n) n.begin(),n.end()
#define eb emplace_back
#define endl "\n"
#define pll pair<ll,ll>
#define YES cout <<"YES"<<endl;
#define NO cout <<"NO"<<endl;
#define ff first
#define ss second
#define setpre(x) fixed<<setprecision(x)
#define PI 3.14159265358979323846

using namespace std;
const ll maxn=1e6+100;
vector<ll> adj[maxn];
ll a[maxn];
ld calcAngle(double h, double m)
{
    // validate the input
   /* if (h <0 || m < 0 || h >12 || m > 60)
        printf("Wrong input");*/

    if (h == 12) h = 0;
    if (m == 60) m = 0;

    // Calculate the angles moved
    // by hour and minute hands
    // with reference to 12:00
    ld hour_angle = 0.5 * (h * 60 + m);
    ld minute_angle = 6 * m;

    // Find the difference between two angles
    ld angle = abs(hour_angle - minute_angle);

    // Return the smaller angle of two possible angles
    angle = min(1.0*360 - angle, angle);

    return angle;
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
  /*  if (fopen("A.INP","r"))
    {
         freopen("A.INP","r",stdin);
        freopen("A.OUT","w", stdout);
    }*/
    ld a, b, h, m;
    cin>>a>>b>>h>>m ;
    cout <<setpre(12);

    ld k= calcAngle(h,m);
    //k=60.0;
   // cout <<cos(k*PI/180.0)<<" "<<cos(90.0*PI/180.0)<<endl;
    //cout <<k<<endl;
    ld ans=sqrt(a*a+b*b-2*a*b*cos(1.0*k*PI/180.0));
    cout <<ans;

}


Measured memory_bytes: 27620
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
 
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=(n)-1;i>=0;i--)
#define VSORT(v) sort(v.begin(), v.end())
#define DVSORT(v) sort(v.begin(), v.end(),greater<int>())
#define SORT(v, n) sort(v, v+n)
#define DSORT(v,n) sort(v, v+n,greater<int>())
#define vi vector<int>
#define pb push_back
#define P pair<int,int>
#define Pll pair<ll,ll>

template <class T> void chmin(T&a,const T&b) { a = min(a,b); }
template <class T> void chmax(T&a,const T&b) { a = max(a,b); }
 
void print(){cout<<endl;}
template <class Head, class... Tail>
void print(Head&& h,Tail&&... t){ 
	if(sizeof...(t)==0)
		cout<<h;
	else
		cout<<h<<' ';
	print(move(t)...);
}
 
const double EPS =1e-9;
const int INF =2e+9;
const ll INFL =9e+18;
const long MOD =1e+9+7;
#define PI 3.14159265258979

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

int main(void){
	int H,W;
	string tem;
	cin>>H>>W;

	REP(i,H){
		REP(j,W){
			cin>>tem;
			if(tem=="snuke")
				printf("%c%d\n",'A'+j,i+1);
		}
	}
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define 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 pb(a) push_back(a)
#define INF 999999999
#define m0(x) memset(x,0,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))



using namespace std;


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




ll gcd(ll x, ll y) {
	ll m = max(x, y), n = min(x, y);
	if (m%n == 0)return n;
	else return gcd(m%n, n);
}
ll lcm(ll x, ll y) {
	return x / gcd(x, y)*y;
}

ll myPow(ll x, ll n, ll m) {
	if (n == 0)
		return 1;
	if (n % 2 == 0)
		return myPow(x * x % m, n / 2, m);
	else
		return x * myPow(x, n - 1, m) % m;
}

long long nCr(int n, int r) {
	if (r > n / 2) r = n - r; // because C(n, r) == C(n, n - r)
	long long ans = 1;
	int i;

	for (i = 1; i <= r; i++) {
		ans *= n - r + i;
		ans /= i;
	}

	return ans;
}

ll F(ll a, ll b) {
	ll c1=0, c2=0;
	while (a > 0) {
		a /= 10;
		c1++;
	}
	while (b > 0) {
		b /= 10;
		c2++;
	}
	return max(c1, c2);
}

map<char, ll>mp;
int main() {
	string A; cin >> A;
	ll l = A.length();
	ll ans = l * (l - 1) / 2+1;
	REP(i, l) {
		mp[A[i]]++;
	}
	for (auto x : mp) {
		if (x.second > 1) {
			ll m = x.second;
			ans -= m * (m - 1) / 2;
		}
	}
	cout << ans << endl;
	return 0;
}




Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define int int64_t
signed main(){	
  int n,a,ans=0;
  cin>>n;
  for(int i=1;i<=n;i++){
    cin>>a;
    if(i%2==1&&a%2==1) ans++;
  }
  cout<<ans<<"\n";
}

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

using namespace std;

#define FastIO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

#define nl "\n"
#define sp " "
#define int long long
#define PI 3.141592653589793
#define scanstr(s) cin>>ws; getline(cin,s);

void solve()
{
	int a;
	cin>>a;
	cout<<a+a*a+a*a*a<<nl;
	return ;
}

int32_t main()
{
	FastIO;
	solve();
	return 0;
}


Measured memory_bytes: 3608
#include<iostream>
using namespace std;
long n,s;
bool f(long b)
{
	long sum=0;
	long _n=n;
	while(_n)
	{
		sum+=_n%b;
		_n/=b;
	}
	return sum==s;
}
main()
{
	cin>>n>>s;
	if(n==s)
	{
		cout<<n+1<<endl;
		return 0;
	}
	for(long i=2;i*i<=n;i++)
		if(f(i))
		{
			cout<<i<<endl;
			return 0;
		}
	long minb=n+1;
	for(long i=1;i*i<=n;i++)
	{
		long b=(n-s)/i+1;
		if(b>1&&f(b))
		{
			minb=min(minb,b);
		}
	}
	cout<<(minb==n+1?-1:minb)<<endl;
}


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

typedef long long int ll;
#define rep(i,n) for (i = 0; i < n; ++i) 
#define REP(i,k,n) for (i = k; i < n; ++i) 
#define REPR(i,k,n) for (i = k; i >= n; --i) 
#define WATCH(x) cout << (#x) << " is " << (x) << endl

#define PB push_back
#define N 300101
#define SZ 3001
#define LB lower_bound
#define M 1000000007
#define UB upper_bound
#define MP make_pair
#define LD long double
#define F first
#define S second

typedef vector< long long int > vi;
typedef vector< vi > vvi;
typedef pair< int,int > ii;

#define sz(a) int((a).size())
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(auto i=c.begin() ; i != c.end() ; i++)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end()
#define flash ios_base::sync_with_stdio(false); cin.tie(NULL),cout.tie(NULL);

int main()
{   
   
   
   ll p , q ,r;
   cin >>p >> q >> r;
   
   ll max = p+q;
   if(max > q+r)
   {
       max = q+r;
   }
   if(max > r+p)
   {
       max = r+p;
   }
   
   cout << max << endl;
   
}


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


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

#define INF bit(60)

#define DBGP 1


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

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

typedef pair<li, li> PI;


int main() {
	string s;
	cin >> s;
	li n = sz(s);
	stack<li> esu;
	li res = n;
	rep(i, n) {
		if (s[i] == 'S') {
			esu.push(i);
		} else {
			if (esu.empty()) {
				//
			} else {
				res -= 2;
				esu.pop();
			}
		}
	}
	cout << res << endl;

	return 0;
}

Measured memory_bytes: 1284
n = int(input())
log = []

for i in range(n):
    s, p = map(str, input().split())
    log.append([s, int(p), i])

b = sorted(log, key=lambda x: x[0])
c = sorted(log, key=lambda x: x[1], reverse=True)

num = []

for i in range(n):
    for j in range(n):
        if b[i][0] == c[j][0]:
            if c[j][2] not in num:
                print(c[j][2]+1)
                num.append(c[j][2])

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

int main() {

  long long int n, a, b, c, x, input;

  while( true ) {

    cin >> n >> a >> b >> c >> x;

    if ( n == 0 ) break;

    vector< long long int > y;

    for ( long long int i = 0; i < n; i++ ) {

      cin >> input;

      y.push_back( input );

    }

    long long int cnt = 0;
    long long int ans = 0;

    for ( ans = 0; true; ans++ ) {

      if ( ans > 10000 ) {
	cout << -1 << endl;
	break;
      }

      if ( x == y[cnt] ) {
	cnt++;
	if ( cnt == n ) {
	  cout << ans << endl;
	  break;
	}
      }

      x = ( a * x + b ) % c;

    }

  }

  return 0;

}

Measured memory_bytes: 1212
#include <bits/stdc++.h> 
using namespace std;
int main(){
	int N;
	cin >> N;
	string W[101];//配列は大きめにとる

	for (int i = 1; i <= N; i++) {
		cin >> W[i];
	}

	for (int i = 2; i <= N; i++) {
		for (int j = 1; j < i; j++) {
			if (W[i] == W[j]) {
				cout << "No";
				return 0;
			}
		}
		if (W[i][0] != W[i - 1][W[i - 1].length() - 1]) {
            //次の最初と1個前の最後の長さ−１を参照
			cout << "No";
			return 0;
		}
	}
	cout << "Yes";
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <functional>

using namespace std;

#define fst first
#define scd second
#define PB push_back
#define MP make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define omajinai ios::sync_with_stdio(false);cin.tie(0)
#define rep(i,x) for(int i=0;i<(int)(x);++i)
#define rep1(i,x) for(int i=1;i<=(int)(x);++i)

using ll=long long;
using ld=long double;
using vi=vector<int>;
using vvi=vector<vi>;
using pii=pair<int, int>;
using vpii=vector<pii>;

template<class T,class U>ostream&operator<<(ostream&os,const pair<T,U>p){os<<"("<<p.fst<<", "<<p.scd<<")";return os;}
template<class T>ostream&operator<<(ostream&os,const vector<T>v){rep(i,v.size()){if(i)os<<", ";os<<v[i];}return os;}
template<typename T>T&max(T&a,T&b){if(a>=b)return a;return b;}
template<typename T>T&min(T&a,T&b){if(a < b)return a;return b;}
template<typename T>bool chmax(T&a,T b){if(a < b){a=b;return true;}return false;}
template<typename T>bool chmin(T&a,T b){if(a > b){a=b;return true;}return false;}
int in(){int a;scanf("%d",&a);return a;}
ll lin(){ll a;scanf("%lld",&a);return a;}

constexpr int inf = 1e9;
constexpr ll linf = 3e18;
constexpr double eps = 1e-9;

int main()
{
    int N = in();
    string s, t; cin >> s >> t;

    rep(i, N+1) {
        string A = s + t.substr(N-i, i);
        rep(j, N) {
            if (A[i+j] != t[j]) goto nxt;
        }
        cout<<A.length()<<endl;
        break;
nxt:;
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>
// *テンプレート*
#define int long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define P pair<int, int>
// aよりbの方が小さかったら、aの値をbの値に置き換える。(swapではない！)
template<class T> inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
// aよりbの方が大きかったら、aの値をbの値に置き換える。
template<class T> inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}

using namespace std;
typedef long long ll;
using Graph = vector<vector<int>>;
//最大公約数
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	return gcd(b, a % b);
}
//最小公倍数
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
// 素数かどうか判定
bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}

const long long MOD = 1000000007;
const long long INF = 1LL << 60;
// *テンプレートここまで*

// pair -> vector<pair<int,int>> 
//		   AandB.push_back(make_pair(a[i],b[i]))

class Union_Find {
private:
	vector<int>par;
	vector<int>rank;
public:
	Union_Find(int n) {
		rep(i, n) {
			par.push_back(i);
			rank.push_back(0);
		}
	}
	int find(int x) {
		if (par.at(x) == x)return x;
		else return par.at(x) = find(par.at(x));
	}
	void unite(int x, int y) {
		x = find(x); y = find(y);
		if (x == y)return;
		if (rank.at(x) < rank.at(y)) {
			par.at(x) = y;
		}
		else {
			par.at(y) = x;
			if (rank.at(x) == rank.at(y))rank.at(x)++;
		}
	}
	bool same(int x, int y) {
		return find(x) == find(y);
	}
};

signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n, k, l; cin >> n >> k >> l;
	Union_Find road(n), train(n);
	rep(i, k) {
		int a, b; cin >> a >> b;
		road.unite(a - 1, b - 1);
	}
	rep(i, l) {
		int a, b; cin >> a >> b;
		train.unite(a - 1, b - 1);
	}
	map<P, int>m;
	rep(i, n) {
		m[P(road.find(i), train.find(i))]++;
	}
	rep(i, n - 1) {
		cout << m[P(road.find(i), train.find(i))] << " ";
	}
	cout << m[P(road.find(n - 1), train.find(n - 1))] << endl;
	return 0;
}

Measured memory_bytes: 18660
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <cmath>
#include <cassert>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <numeric>
#include <complex>
#include <list>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <utility>
#include <functional>
#include <iterator>

using namespace std;

#define dump(n) cerr<<"# "<<#n<<"="<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define iter(c) __typeof__((c).begin())
#define foreach(i,c) for(iter(c) i=(c).begin();i!=(c).end();++i)
#define all(c) (c).begin(),(c).end()
#define mp make_pair

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

const int INFTY=1<<29;

int solve(const vector<ull>& g,ull flg,int cur)
{
	int n=g.size();
	if(flg==(1ull<<n)-1)
		return 0;
	
	int res=INFTY;
	repi(i,cur,n)
		res=min(res,1+solve(g,flg|g[i],i+1));
	return res;
}

int main()
{
	for(int n,m;scanf("%d%d",&n,&m),n|m;){
		if(n>32) puts("require 64-bit integer.");
		vector<ull> g(n);
		rep(i,n)
			g[i]=1ull<<i;
		rep(i,m){
			int s,d; scanf("%d%d",&s,&d);
			g[s]|=1ull<<d;
			g[d]|=1ull<<s;
		}
		
		ull flg=0;
		int res=solve(g,flg,0);
		printf("%d\n",res);
	}
	
	return 0;
}

Measured memory_bytes: 1188
package main

import "fmt"

func main() {
	var a, b, c int
	fmt.Scan(&a, &b, &c)

	max := &a
	if *max < b {
		max = &b
	}
	if *max < c {
		max = &c
	}
	*max *= 10

	fmt.Println(a + b + c)
}


Measured memory_bytes: 512
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<set>
#include<map>
#include<queue>
#define REP(i,a) for (int i = 0;i < (a);++i)
#define FOR(i,a,b) for (int i = (a);i < (b); ++i)
#define FORR(i,a,b) for (int i = (a);i >= (b); --i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SORT(list) sort(ALL((list)));
#define MOD 1000000007
using namespace std;
using ll = long long;
int main(){
    string t;
    ll n,k,r,s,p;
    cin >> n >> k >> r >> s >> p;
    cin >> t;
    ll answer = 0;
    bool passed[n];
    REP(i,n)passed[i] = false;
    REP(i,k){
        if(t[i]=='r')answer+=p;
        else if(t[i]=='s')answer+=r;
        else if(t[i]=='p')answer+=s;
        //cout << answer << endl;
    }
    FOR(i,k,n){
        if(t[i]!=t[i-k]){
            if(t[i]=='r')answer+=p;
            else if(t[i]=='s')answer+=r;
            else if(t[i]=='p')answer+=s;
        }
        else{
            if(passed[i-k]){
                if(t[i]=='r')answer+=p;
                else if(t[i]=='s')answer+=r;
                else if(t[i]=='p')answer+=s;
            }
            else{
                passed[i]=true;
            }
        }
        //cout << answer << endl;
    }
    cout << answer << endl;
    return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include<algorithm>
#include<string>
#include<sstream>
#include<iomanip>
#include<limits>
#include<deque>
#include<map>
#include<list>
#include<set>
#include <unordered_set>
#include<vector>
#include<cmath>
#include<cstdio>
#include<memory>
#include<bitset>

using namespace std;


int main(void) {
	int a[3], b[3];
	for (int i = 0; i < 3; i++) {
		cin >> a[i] >> b[i];
	}
	map<int, int> mp;

	for (int i = 0; i < 3;i++) {
		mp[a[i]] += 1;
		mp[b[i]] += 1;
	}

	int count = 0;
	int count1 = 0;
	int count2 = 0;

	for (pair<int, int> x : mp) {
		count++;
		if (x.second == 2) { count2++; }
		if (x.second == 1) { count1++; }
	}

	if (count == 4 && count1 == 2 && count2 == 2) {
		cout << "YES" << endl;
	}
	else { cout << "NO" << endl; }


	return 0;
}

Measured memory_bytes: 256
//include
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath> 
#include <iomanip>
#include <math.h>
#include <utility>
#include <functional>
#include <cstdlib>
//using
using namespace std;
using vl = vector <long long>;
using vs = vector <string>;
using vc = vector <char>;
using ll= long long;
using vvl = vector<vector<ll> >;
using vvc = vector<vector<char> >;
//vector<vector<char> > hyou(N, vector<char>(N));
using vd = vector <double>;
//define
//#define int long long
#define rep(i,n) for(int i=0; i<n; i++)
#define print(n) cout<<n<<endl;
#define sortp(d) sort(d.begin(),d.end()) //1234
#define sortm(d) sort(d.rbegin(),d.rend()) //4321
//素数判定　O(√A) 
bool is_prime(int x){
 if(x<=1) return false;
 for(int i=2;i*i<=x;i++)
 if(x%i==0) return false;
 return true;
 }
/*順列生成
do {
  // 順列に対する処理
} while (next_permutation(配列変数.begin(), 配列変数.end()));*/

//絶対値　abs()
//文字→数字　'0' アルファベット→数字　'a'　'A'が65番,'a'が97番だわ
//型キャスト　char('a'+1)
//reverse 回文
//if(isupper('A')){puts("Aは大文字です");}
/*各位の和　
int sum = 0;
for(int i = 0; i <= 5; i++){
   sum += n%10;
   n /= 10;  
}
*/

//グローバル変数宣言
ll p=0,q=0,r=0;

int main()
{
  ll n;
  cin>>n;
  vl d1(n),d2(n);
  rep(i,n){
    cin>>d1[i];
    cin>>d2[i];
    if(d1[i]==d2[i])p++;
    else {q=max(p,q);p=0;}
  }
  q=max(p,q);
  if(q>=3)print("Yes")
  else print("No")

}


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

int main(){
    int a,b;
    char op;
    cin >> a >> op >> b;
    if( op == '+' ){
        cout << a + b<< endl;
    }else{
        cout << a - b << endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define sf1(n) scanf("%d",&n)
#define sf2(n,q) scanf("%d %d",&n,&q)
#define f first
#define ss second
#define pb push_back
#define lli long long
#define mem(ar,false) memset(ar,false,sizeof(ar))
#define mpr make_pair
#define endl "\n"
#define mod 1000000007
#define inf 9000000000000000000LL
using namespace std;

int ar[200005];
int n,k;
int dp[100005];
int func(int i)
{

    if(i==n-1)
        return 0;
    if(dp[i]!=-1)
        return dp[i];
    int ret = INT_MAX;

    for(int j=1;j<=k;j++)
    {
        if(i+j<n)
            ret = min(ret,abs(ar[i]-ar[i+j])+func(i+j));
    }
    return dp[i] = ret;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //mem(dp,-1);
    cin >> n >> k;
    for(int i=0; i<n; i++)
        cin >> ar[i];

  //   int ans = func(0);
    for(int i=1; i<n; i++)
    {
        int ret = INT_MAX;
        for(int j=1;j<=k;j++)
        {
            if(i-j>=0)
                ret = min(ret,dp[i-j]+abs(ar[i]-ar[i-j]));
        }
        dp[i] = ret;
    }

    cout << dp[n-1] << endl;
    return 0;

}


Measured memory_bytes: 4388
#include<bits/stdc++.h>
const int mod=1e9+7;
typedef long long ll;
const int N=2e3+5;

int n;
std::vector<std::pair<ll,int> > v;
ll dp[N][N];
ll solve(int l,int r)
{
	if(dp[l][r]>=0) return dp[l][r];
	if(r<l) return dp[l][r]=0;
	int i=n-r+l;//当前正在放第i个
	return dp[l][r]=std::max(
		v[i].first*std::abs(v[i].second-l)+solve(l+1,r),
		v[i].first*std::abs(v[i].second-r)+solve(l,r-1)
	);
}
int main()
{
	// freopen("a.in","r",stdin);
	scanf("%d",&n);
	v.push_back(std::make_pair(0,0));
	for(int i=1;i<=n;i++)
	{
		ll j;
		scanf("%lld",&j);
		v.push_back(std::make_pair(j,i));
	}
	std::sort(v.rbegin(),v.rend()-1);
	memset(dp,-1,sizeof(dp));
	printf("%lld\n",solve(1,n));
	return 0;
}


Measured memory_bytes: 35392
#include<cstdio>
#include<iostream>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<list>
#include<map>
#include<algorithm>

using namespace std;

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

    if (r < 1200) {
        cout << "ABC" << endl;
    } else if (r < 2800) {
        cout << "ARC" << endl;
    } else {
        cout << "AGC" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
#define int long long
using P = pair<int,int>;
 
template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
  out << "(" << a.first << "," << a.second << ")";
  return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
  out << "["; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
  return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
  out << "["; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
  return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
  out << "{"; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
  return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
  out << "{"; bool first = true;
  for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
  return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
vector< P > res;
signed main(){
    int n;cin >> n;
    for(int i = 2;i*i <= n;i++){
        if(n%i == 0){
            int ret = 0;
            while(n%i == 0 && n){
                n/= i;
                ret++;
            }
            res.emplace_back(i,ret);
        }
        
    }
    if(n > 1)res.emplace_back(n,1);
    //for(auto p:res){
    //    cout << p.first << " " << p.second << endl;
    //}
    int ans = 0;
    for(auto p:res){
        int num = p.second;
        for(int i = 1;num - i >= 0;i++){
            num -= i;
            ans++;

        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3652
#include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
#define mygc(c) (c)=getchar_unlocked()
#define mypc(c) putchar_unlocked(c)
void reader(int& x) { int k, m = 0; x = 0; for (;;) { mygc(k); if (k == '-') { m = 1; break; }if ('0' <= k&&k <= '9') { x = k - '0'; break; } }for (;;) { mygc(k); if (k<'0' || k>'9')break; x = x * 10 + k - '0'; }if (m) x = -x; }
void writer(int x, char c) { int s = 0, m = 0; char f[10]; if (x<0)m = 1, x = -x; while (x)f[s++] = x % 10, x /= 10; if (!s)f[s++] = 0; if (m)mypc('-'); while (s--)mypc(f[s] + '0'); mypc(c); }
template<class T> void writerLn(T x) { writer(x, '\n'); }
using namespace std;
typedef pair<int, int>P;

vector<P>E[100000];
int d[100000], b[100000], cnt[200001], u[200000], v[200000], r[200000], que[100000];
int main() {
	int n, m, q; reader(n); reader(m); reader(q);
	rep(i, m) {
		reader(u[i]); reader(v[i]); u[i]--; v[i]--; r[i] = q;
	}
	rep(i, q) {
		int a; reader(a); r[a - 1] = i;
	}
	rep(i, m) {
		E[u[i]].emplace_back(P(v[i], r[i]));
		E[v[i]].emplace_back(P(u[i], r[i]));
	}
	d[0] = 1; b[0] = q;
	int s = 0, g = 1;
	while (s != g) {
		int p = que[s++];
		rep(i, E[p].size()) {
			P v = E[p][i];
			if (d[v.first] == 0) {
				d[v.first] = d[p] + 1; que[g++] = v.first;
			}
			if (d[v.first] == d[p] + 1)
				b[v.first] = max(b[v.first], min(b[p], v.second));
		}
	}
	rep(i, n)cnt[b[i]]++;
	int ans = 0;
	rep(i, q) {
		ans += cnt[i];
		writer(ans, '\n');
	}
}

Measured memory_bytes: 15772
//#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>

using namespace std;


template<class T>
bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}


const int INF = 1e9+7;

void solve() {
    int N, K; cin >> N >> K;
    vector<int> h(N);
    for (int i = 0; i < N; i++) cin >> h[i];

    vector<int> dp(N, INF);

    dp[0] = 0;

    for (int i = 0; i < N; i++) {
        for (int j = 1; j <= K; j++) {
            if (i+j < N) {
                chmin(dp[i+j], dp[i] + abs(h[i] - h[i+j]));
            }
        }
    }

    cout << dp[N-1] << endl;
}


int main() {
    solve();
    return 0;
}

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

template<Int MOD = 1000000007>
struct Mod{
  Int prev=0;
  vector<Int> fact,inv,finv;
  Mod(){}
  Mod(Int n){init(n);}
  
  Int pow(Int x,Int n){
    Int res=1;
    while(n){
      if(n&1) (res*=x)%=MOD;
      (x*=x)%=MOD;
      n>>=1;
    }
    return res;
  }
  
  Int inverse(Int a){
    return pow(a,MOD-2);
  }
  
  void init(Int n){
    if(prev>=n) return;
    prev=n;
    fact=inv=finv=vector<Int>(n);
    
    fact[0]=1;
    for(Int i=1;i<n;i++)
      fact[i]=(fact[i-1]*i)%MOD;
    
    inv[1]=1;
    for(Int i=2;i<n;i++)
      inv[i]=inv[MOD%i]*(MOD-MOD/i)%MOD;
    
    finv[0]=1;
    for(Int i=1;i<n;i++)
      finv[i]=finv[i-1]*inv[i]%MOD;
  }
  
  Int comb(Int n,Int k){
    Int res=1;
    for(Int i=0;i<k;i++){
      res*=(n-i)%MOD;
      res%=MOD;
      res*=inverse(i+1);
      res%=MOD;
    }
    return res;
  }
  
  //only for prime MOD
  Int C(Int n,Int k){
    if(k<0||k>n) return 0;
    return fact[n]*finv[k]%MOD*finv[n-k]%MOD;
  }

  Int H(Int n,Int k){
    return C(n+k-1,n);
  }
  
  Int montmort(Int n){
    Int res=0,rinv=1;
    for(Int k=2;k<=n;k++){
      (rinv*=inverse(k))%=MOD;
      if(k%2) (res+=MOD-rinv)%=MOD;
      else (res+=rinv)%=MOD;
    }
    for(Int i=1;i<=n;i++)
      (res*=i)%=MOD;
    return res;
  }
  
  // calculate P(t) from given points in [0,N]
  Int LagrangePolynomial(vector<Int> &y,Int t){
    Int n=y.size()-1;
    init(n+1);
    Int num=1;
    for(Int i=0;i<=n;i++)
      num=num*((t-i)%MOD)%MOD;
    Int res=0;
    for(Int i=0;i<=n;i++){
      Int tmp=(y[i]*num%MOD)*inverse((t-i)%MOD)%MOD;
      tmp=tmp*finv[i]%MOD;
      tmp=tmp*finv[n-i]%MOD;
      if((n-i)&1) tmp=MOD-tmp;
      res=(res+tmp)%MOD;
    }
    return res;
  }
};

//INSERT ABOVE HERE
signed main(){
  const Int MOD = 1e9+7;
  Mod<MOD> mod(2e5);
  Int n,k;
  cin>>n>>k;
  cout<<mod.C(n-1,k-1)<<endl;
  return 0;
}



Measured memory_bytes: 7468
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using PLL = pair<ll, ll>;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repn(i,n) for(int i = 0; i <= (int)(n); i++)
#define srep(i,l,n) for(int i = l; i < (int)(n); i++)
#define srepn(i,l,n) for(int i = l; i <= (int)(n); i++)
#define drep(i,n) for(int i = (int)(n-1); i >= 0; i--)
#define drepn(i,n) for(int i = (int)(n); i >= 0; i--)
#define size(s) (int)s.size()
#define debug(var)  do{std::cout << #var << " : ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }
template<typename T> inline istream& operator>>(istream &i, vector<T> &v) {rep(j, size(v)) i >> v[j]; return i;}
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; }
template<class T> T gcd(T a, T b) {if(b==0)return a; else return gcd(b,a%b);}
template<class T> T lcm(T a, T b) {return a/gcd(a,b)*b;}
template<class T = int> using V = vector<T>;
template<class T = int> using VV = vector<V<T>>;
bool isIn(int i, int j, int h, int w) {return i >= 0 && i < h && j >= 0 && j < w;}
void Yes(){cout << "Yes" << endl;}
void No(){cout << "No" << endl;}
void YES(){cout << "YES" << endl;}
void NO(){cout << "NO" << endl;}
void err() {cout << -1 << endl;}
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
#define ep emplace_back

const int MOD = 1000000007;
const int INF = 1e9;

#define PI acos(-1);
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,1,-1};
int ddx[8] = {1,1,1,-1,-1,-1,0,0};
int ddy[8] = {0,1,-1,0,1,-1,1,-1};


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    V<> a(n);
    cin >> a;
    sort(all(a));
    cout << a[n - 1] - a[0] << endl;
}

Measured memory_bytes: 3572
import java.util.*;
//https://atcoder.jp/contests/abc104/tasks/abc104_b
import java.util.regex.Pattern;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        final String S = sc.next();
        sc.close();
        final String R = "^A[a-z][a-z]*C[a-z]*[a-z]$";
        Pattern p = Pattern.compile(R);

        if (p.matcher(S).find())
            System.out.println("AC");
        else
            System.out.println("WA");
    }
}

Measured memory_bytes: 22740
#include <iostream>
using namespace std;
int main()
{
	int x_1, x_2, y_1, y_2;
	cin >> x_1 >> y_1 >> x_2 >> y_2;
	int x_variable, y_variable;
	x_variable = x_2 - x_1;
	y_variable = y_2 - y_1;
	int x_3, x_4, y_3, y_4;
	x_3 = x_2 - y_variable;
	y_3 = y_2 + x_variable;
	x_4 = x_3 - x_variable;
	y_4 = y_3 - y_variable;

	cout << x_3 << " " << y_3 << " " << x_4 << " " << y_4 << endl;
	return 0;


}

Measured memory_bytes: 256
use std::io;
#[allow(dead_code)]
fn read<T: std::str::FromStr>() -> T {
    let mut n = String::new();
    io::stdin().read_line(&mut n).unwrap();
    n.trim().parse().ok().unwrap()
}
#[allow(dead_code)]
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut n = String::new();
    io::stdin().read_line(&mut n).unwrap();
    n.trim()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

fn main() {
    loop {
        let s: String = read();
        if s == "-" {
            break;
        }
        let m: usize = read();
        let mut q = std::collections::VecDeque::new();
        for c in s.chars() {
            q.push_back(c);
        }
        for _i in 0..m {
            let h: usize = read();
            for _j in 0..h {
                let c = q.pop_front().unwrap();
                q.push_back(c);
            }
        }
        for c in q {
            print!("{}", c);
        }
        println!();
    }
}



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

int main() {
	int n,q,a[200000+25],l,r,x,re=0;
	cin >> n;
	for(int i=0; i<n; i++) 
	{
		cin>>a[i];
		re ^= a[i];
	}
	for(int i=0; i<n; i++)
	{
		cout<<(re^a[i])<<" ";
	}
	return 0;
}

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

// using ll = long long;
#define int long long

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPS(i, r, n) for (int i = (r); i < (n); ++i)
#define REPR(i, n) for(int i = (n); i >= 0; --i) // from n to 0
#define REPRS(i, r, n) for(int i = (n); i >= (r); --i) // from n to r
#define COUTB(x) cout << (x) << "\n"
#define COUTS(x) cout << (x) << " "
#define PB push_back
#define SORT(obj) sort((obj).begin(), (obj).end())
#define SORTR(obj) sort((obj).begin(), (obj).end(), greater<>())
#define ALL(obj) (obj).begin(), (obj).end()
#define MOD 1000000007
#define PI (acos(-1))

int global_count[10][10];

int getHead(int a) {
  string s = to_string(a);
  return (int) s[0] - '0';
}
int getTail(int a) {
  string s = to_string(a);
  return (int) s[s.length()-1] - '0';
}
/***** MAIN *****/
signed main() {
  int n;
  scanf("%d",&n);
  if(n == 10) {
    cout << 9 << endl;
    return 0;
  }
  if(n < 10) {
    cout << n << endl;
    return 0;
  }
  REPS(i,1,n+1) {
    ++global_count[getHead(i)][getTail(i)];
  }
  int ans = 0;
  REPS(i,1,10) {
    REPS(j,1,10) {
      if(global_count[i][j] > 0 && global_count[j][i] > 0) ans += global_count[i][j] * global_count[j][i];
    }
  }
  cout << ans;
  cout << "\n";
  return 0;
}
/***** MAIN *****/


Measured memory_bytes: 256
#define rep(i, n) for (int i = 0; i < (n); i++)
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int MOD = 1000000007;
// MAX int 2,147,483,647 -> 10桁
// MAX ll 9,223,372,036,854,775,807 -> 19桁
// MAX O(n) 10^8 -> 8回
// double pi = M_PI or acos(-1)
// printf("%.10f\n", ans);

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) {
        int tmp;
        cin >> tmp;
        a.at(i) = --tmp;
    }

    vector<int> answers(n);
    rep(i, n) {
        answers.at(a.at(i)) = i;
    }

    rep(i, n) {
        cout << answers.at(i) + 1 << " ";
    }
    cout << endl;

    return 0;
}


Measured memory_bytes: 3904
import java.util.Scanner;


public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
			
			int S = sc.nextInt();
			int T = sc.nextInt();
			int C =0;
			if(S>T) {
				C=T;
			}else {
				C=S;
			}
			
			
			int l =1;
			for(int i=C;i>1;i--) {
			if(Math.floorMod(S, i)==0) {
					if(Math.floorMod(T, i)==0){
						l=i;
						break;

					}
				}
			}
	
			
			System.out.println((long)S*(long)T/l);
	}	

}

Measured memory_bytes: 35892
N = gets.chop.to_i
a = gets.chop.split.map(&:to_i)

if N==1
  if a[0] == 0
    p 1
  else
    p 0
  end
  exit
end

n = N / 2

if N % 2 == 0
  start = 1
  tmp_sum = 1
else
  start = 2
  tmp_sum = 2
end

(n-1).times do
  start += 2
  tmp_sum += start
end


if tmp_sum*2 != a.inject(:+)
  p 0
  exit
end

ans = 1


MOD = 10**9 + 7


n.times do
  ans = ans * 2 % MOD
end


p ans

Measured memory_bytes: 8716
#include<bits/stdc++.h>
#define N 10010
#define rep(i, l, r) for(register int i = l; i <= r; ++i)
using namespace std;
char a[N];
int main()
{
	int n;
	scanf("%d",&n);
	scanf("%s",a);
	rep(i,0,strlen(a)-1)
	{
		a[i]+=n;
		while(a[i]>'Z')
		{
			a[i]-='Z'-'A'+1;
		}
	}
	printf("%s",a);
	return 0;
}

Measured memory_bytes: 256
/*
 * Author: RainAir
 * Time: 2019-10-27 20:03:18
 */
#include <algorithm>
#include <iostream>
#include <cstring>
#include <climits>
#include <cstdlib>
#include <cstdio>
#include <bitset>
#include <vector>
#include <cmath>
#include <ctime>
#include <queue>
#include <stack>
#include <map>
#include <set>

#define fi first
#define se second
#define U unsigned
#define P std::pair
#define LL long long
#define pb push_back
#define MP std::make_pair
#define all(x) x.begin(),x.end()
#define CLR(i,a) memset(i,a,sizeof(i))
#define FOR(i,a,b) for(int i = a;i <= b;++i)
#define ROF(i,a,b) for(int i = a;i >= b;--i)
#define DEBUG(x) std::cerr << #x << '=' << x << std::endl

int main(){
    int n;scanf("%d",&n);
    FOR(i,1,9){
        FOR(j,1,9){
            if(i*j == n){
                puts("Yes");
                return 0;
            }
        }
    }
    puts("No");
    return 0;
}


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

typedef pair<int, int> P;

static const int MAX_H = 1000;
static const int MAX_W = 1000;
static const int MAX_N = 9;

int H, W, N;
int gh = -1, gw = -1;
char grid[MAX_H][MAX_W + 1];
int count[MAX_H][MAX_W];
P factory[MAX_N + 1];

//#define OCTAS
#ifdef OCTAS
static const int dh[] = {-1, -1, -1, 0, 0, +1, +1, +1};
static const int dw[] = {-1, 0, +1, -1, +1, -1, 0, +1};
#else
static const int dh[] = {-1, 0, 0, +1};
static const int dw[] = {0, -1, +1, 0};
#endif

// CAUTION!!!
// Call init_count() first!!!
//
void init_count() {
  fill_n(::count[0], MAX_H * MAX_W, -1);
}

int bfs(int h, int w) {
  queue<P> que;
  ::count[h][w] = 0;
  que.push(P(h, w));

  while (!que.empty()) {
    P p = que.front();
    que.pop();
    int cnt = ::count[p.first][p.second];
    if (p.first == gh && p.second == gw) {
      return cnt;
    }
    ++cnt;
    for (int i = 0; i < sizeof(dh) / sizeof(int); ++i) {
      int nh = p.first + dh[i];
      int nw = p.second + dw[i];
      if (nh < 0 || nh >= H ||
          nw < 0 || nw >= W ||
          ::count[nh][nw] >= 0 ||
          grid[nh][nw] == 'X')
        continue;
      ::count[nh][nw] = cnt;
      que.push(P(nh, nw));
    }
  }

  return -1;
}

int main() {
  scanf("%d%d%d", &H, &W, &N);
  for (int h = 0; h < H; ++h) {
    scanf("%s", &grid[h][0]);
    for (int w{}; w < W; ++w) {
      if (grid[h][w] == 'S') {
        factory[0].first = h;
        factory[0].second = w;
      } else if ('1' <= grid[h][w] && grid[h][w] <= '9') {
        int i = grid[h][w] & 0xF;
        factory[i].first = h;
        factory[i].second = w;
      }
    }
  }

  int total{};
  for (int i{1}; i <= N; ++i) {
    init_count();
    gh = factory[i].first;
    gw = factory[i].second;
    total += bfs(factory[i-1].first, factory[i-1].second);
  }

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



Measured memory_bytes: 8152
#include<iostream>
#include<math.h>
#include<vector>
#include<algorithm>
#include<numeric>
#include<map>
#include<queue>
#include<deque>
#include<set>
#include<cstdio>
#include<cstring>
#include<string>
using namespace std;
typedef long long ll;
typedef vector<int> vec;
typedef vector<vector<int>> mat;

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

    ll M=max(a,b);
    ll m=min(a,b);
    return gcd(m,M%m);
}

int main(){
    ll A,B;cin>>A>>B;
    ll N=gcd(A,B);

    ll M=sqrt(N)/1;
    ll ans=1;
    for(int i=2;i<=M;i++){
        if(N%i==0)ans++;
        while(N%i==0)
            N/=i;  
    }
    if(N!=1)ans++;

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

Measured memory_bytes: 256
#include <bits/stdc++.h> 
using namespace std; 
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define flash ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define debug(x) cerr << " - " << #x << ": " << x << endl;
#define debugs(x, y) cerr << " - " << #x << ": " << x << " " << #y << ": " << y << endl;
#define all(x) (x).begin(),(x).end()
#define sz(x) (ll)x.size()
#define ll long long
#define INF 1000000000
#define MOD 1000000007
#define pb push_back
#define ve vector<ll>
#define dos pair<ll,ll>
#define vedos vector<dos>
#define rand mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
struct greateri
{
    template<class T>
    bool operator()(T const &a, T const &b) const { return a > b; }
};
bool isprime[1000011];
int main()
{
  //flash;
  set<ll>primes;
  memset(isprime,1,sizeof isprime);
  isprime[0]=0;
  isprime[1]=0;
  for (ll i = 2; i <= 1000000; ++i)
  {
    if(isprime[i])
    {
      primes.insert(i);
      for (ll j = i*i; j <= 1000000; j+=i)
      {
        isprime[j]=0;
      }
    }
  }
  ll yo;
  cin>>yo;
  auto ka = primes.lower_bound(yo);
  cout<<(*ka);
  return 0;
}
//code the AC sol !
// BS/queue/map


Measured memory_bytes: 4864
from collections import Counter

def factorize(N):
    p = 2
    PRIME = []
    while p * p <= N:
        if N % p == 0:
            N //= p
            PRIME.append(p)
        else:
            p += 1
    if N > 1:
        PRIME.append(N)
    return Counter(PRIME)

n = int(input())

prime = factorize(n)
ans = 0
for i in prime:
    for j in range(1,prime[i]+1):
        if n % i ** j == 0:
            n //= i ** j
            ans += 1
print(ans)

Measured memory_bytes: 9464
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
using namespace std;
int a, b, c;
int main() {
    cin >> a >> b >> c;
    cout << a + b + c - max(max(a, b), c) << endl;
    return 0;
}


Measured memory_bytes: 256
N=input()
L=tuple(map(int,input().split()))
l=[0]*1001
g=[0]*1001
for i in L:
    l[i]+=1
for i in range(1,1001):
    g[i]=g[i-1]+l[i]
a=0
for i in range(1,999):
    for j in range(i+1,1000):
        a+=l[i]*l[j]*(g[min(i+j-1,1000)]-g[j])
for i in range(1,1001):
    if l[i]>1:
        t=l[i]*(l[i]-1)//2
        for j in range(1,i):
            a+=t*l[j]
        if l[i]>2:
            a+=t*(l[i]-2)//3
        for j in range(i+1,min(1001,i*2)):
            a+=t*l[j]
print(a)

Measured memory_bytes: 42332
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string.h>
#define ll long long 
#define inf 0x3f3f3f
using namespace std;
int main()
{
	int a[100005];
	int n,k;
	while(scanf("%d %d",&n,&k)!=EOF)
	{
		for(int i=0;i<n;i++)
		scanf("%d",&a[i]);
		sort(a,a+n);
		int mi=999999999;
		for(int i=0;i<=n-k;i++)
		{
			mi=min(mi,a[i+k-1]-a[i]);
		}
		printf("%d\n",mi);
	}
	return 0;
 } 

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

template<typename T>
void chmax(T &a,T b){
  if(a<b)a=b;
}

signed main(){
  int n;cin>>n;
  map<string,int> m;
  while(n--){
    string s;cin>>s;
    m[s]++;
  }
  int ans=0;
  for(auto p:m)chmax(ans,p.second);
  for(auto p:m)if(p.second==ans)cout<<p.first<<endl;
}


Measured memory_bytes: 25216
/*

*/
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<algorithm>
#include<vector>
#include<set>
#include<stack>
#include<queue>
#include<map>
#include<cmath>
#include<bitset>
using namespace std;
#define ll long long
#define N 200003
#define INF  0x3f3f3f3f3f3f3f3f
#define mod 998244353
#define mkp make_pair
#define lson rt<<1, l, mid
#define rson rt<<1|1, mid+1, r
template <typename T> inline void read(T &x){char c; bool nega=0; while((!isdigit(c=getchar()))&&(c!='-')); if(c=='-'){nega=1; c=getchar();} x=c-48; while(isdigit(c=getchar())) x=x*10+c-48; if(nega) x=-x;}
template <typename T> inline void writep(T x){if(x>9) writep(x/10); putchar(x%10+48);}
template <typename T> inline void write(T x){if(x<0){ putchar('-'); x=-x;} writep(x);}
template <typename T> inline void writeln(T x){write(x); putchar('\n');}
//#define _DEBUG_
int n, a[N];
ll ret;
int main(){
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int i, j, t, cnt;
	#ifdef _DEBUG_
	freopen("D Chat in a Circle.in", "r", stdin);
	//freopen(".out", "w", stdout);
	#endif
	cin>>n;
	for(i=0; i<n; i++)
		cin>>a[i];
	sort(a, a+n, greater<int>());
	
	ret = 0; 
	ret = a[0];
	cnt = n-2;
	for(i=1; ; i++){
		if(cnt>=2){
			ret += a[i]*2;
			cnt-=2;
		} else if(cnt==1) {
			ret += a[i];
			break;
		} else
			break;
	}
	
	cout<<ret<<endl;
	

	return 0;
}



Measured memory_bytes: 4436
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
const ll INF = 1LL << 60;
const ll MOD = 1000000007;
template <class T>
bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}
template <class C>
void print(const C &c, std::ostream &os = std::cout) {
    std::copy(std::begin(c), std::end(c), std::ostream_iterator<typename C::value_type>(os, " "));
    os << std::endl;
}

ll dp[51][51][2501];

int main() {
    int n, a;
    cin >> n >> a;
    vi x(n);
    for (int i = 0; i < n; ++i) {
        cin >> x[i];
    }
    dp[0][0][0] = 1;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
            for (int k = 0; k < 2501; ++k) {
                dp[i + 1][j][k] += dp[i][j][k];
                if (k + x[i] < 2501)
                    dp[i + 1][j + 1][k + x[i]] += dp[i][j][k];
            }
        }
    }
    ll ret = 0;
    for (int i = 1; i <= n; ++i) {
        for (int j = 1; j < 2501; ++j) {
            if (j % i == 0 && j / i == a)
                ret += dp[n][i][j];
        }
    }
    cout << ret << "\n";
    return 0;
}

Measured memory_bytes: 50176
// #define _GLIBCXX_DEBUG

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
void dump_func()
{
    cerr << endl;
}
template <class Head, class... Tail>
void dump_func(Head &&h, Tail &&... t)
{
    cerr << h << (sizeof...(Tail) == 0 ? "" : ", "),
        dump_func(forward<Tail>(t)...);
}
#define dump(...)                                                             \
    cerr << "/* " << #__VA_ARGS__ << " :[" << __LINE__ << ":" << __FUNCTION__ \
         << "]" << endl,                                                      \
        dump_func(__VA_ARGS__), cerr << "*/\n\n";
typedef long long ll;

int main()
{
    int w, al, bl;
    cin >> w >> al >> bl;
    int ar = al + w, br = bl + w;
    int res = 0;

    if (ar < bl) {  // aが左
        res = bl - ar;
    }
    else if (br < al) {  // bが左
        res = al - br;
    }
    cout << res << endl;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
typedef long long int lint;


int main(){
    int k, x;
    cin >> k >> x;
    int b = x-k+1;
    for(int i=0; i<2*k-1; i++){
        cout << b << " ";
        b++;
    }
    return 0;
}

Measured memory_bytes: 256