akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
long long dp[3005][3005];
long long MOD=998244353;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	long long a, b, c, d;
	cin>>a>>b>>c>>d;
	memset(dp, 0, sizeof dp);
	dp[a][b]=1;
	for(int i=a;i<=c;i++){
		for(int j=b;j<=d;j++){
			if(i+j==a+b) continue;
			dp[i][j]=(dp[i-1][j]*j+dp[i][j-1]*i)%MOD-((dp[i-1][j-1])*(i-1)*(j-1))%MOD;
			dp[i][j]=(dp[i][j]+MOD)%MOD;
		}
	}
	cout<<dp[c][d];
}

Measured memory_bytes: 74164
<?php
define("MOD", 10**9+7);
$str = str();
$n = strlen($str);
for($j = 0; $j < 13; $j++){
  $dp[$n-1][$j] = 0;
}
if($str[$n-1] == "?"){
  for($i = 0; $i < 10; $i++){
    $dp[$n-1][$i] = 1;
  }
}else{
  $dp[$n-1][$str[$n-1]] = 1;
}
$c = 0;
$m = 1;
for($i = $n-2; $i>=0; --$i){
  $m*=10;
  $m%=13;
  for($j = 0; $j < 13; ++$j){
    $dp[$i][$j] = 0;
  }
  $dpi = &$dp[$i];
  $dpip = $dp[$i+1];
  if($str[$i] != "?"){
    $diff = $m*intval($str[$i])%13;
    for($j = 0; $j < 13; ++$j){
      $dpi[($j+$diff)%13] = $dpip[$j];
    }
  }else{
    for($k = 0; $k < 10; ++$k){
      $diff = $m*intval($k)%13;
      for($j = 0; $j < 13; ++$j){
        $dpi[($j+$diff)%13] += $dpip[$j];
        $c+=$dpip[$j];
      }
    }
  }
  for($j = 0; $j < 13; $j++){
    $dp[$i][$j] = $dp[$i][$j] % MOD;
  }
}
echo $dp[0][5];


function str(){
  return trim(fgets(STDIN));
}
function ints(){
  return array_map("intval", explode(" ", trim(fgets(STDIN))));
}
function int(){
  return intval(trim(fgets(STDIN)));
}
function o(...$val){
    if(count($val)==1)$val = array_shift($val);
    $trace = debug_backtrace();
    echo $trace[0]['line'].")";
    if(is_array($val)){
        if(count($val) == 0){
            echo "empty array";
        }elseif(!is_array(current($val))){
            echo "array:";
            echo implode(" ", $val)."\n";
        }else{
            echo "array:array\n";
            foreach($val as $row){
                echo implode(" ", $row)."\n";
            }
        }
    }else{
        echo $val."\n";
    }
}


Measured memory_bytes: 78712
/*
    Problem 15
    https://atcoder.jp/contests/abc145/tasks/abc145_c
*/
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
const int MAX = 10000;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */
/* function */
double dist(double x1, double y1, double x2, double y2) {
    double dx = x1 - x2, dy = y1 - y2;
    return sqrt(dx * dx + dy * dy);
}
/* main */
int main(){
    int N;
    cin >> N;
    vector<double> x(N), y(N);
    for (int i = 0; i < N; i++) cin >> x[i] >> y[i];
    double sum = 0.0;
    double cnt = 0.0;
    vector<int> p(N);
    iota(p.begin(), p.end(), 0);
    do {
        cnt++;
        for (int i = 0; i < N - 1; i++)
            sum += dist(x[p[i]], y[p[i]], x[p[i+1]], y[p[i+1]]);
    } while (next_permutation(p.begin(), p.end()));
    cout << setprecision(10) << sum / cnt << '\n';
}

Measured memory_bytes: 3852
import java.util.*;
public class Main{
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] a = new int[n];
    int[] b = new int[n];
    int m=0;
    for(int i = 0;i<n;i++){
      a[i] = sc.nextInt();
      if(a[i]%2==0){
        b[m] = a[i];
        m++;
      }
    }
    if(approved(b)){
      System.out.println("APPROVED");
    }else{
      System.out.println("DENIED");
    }
  }
  static boolean approved(int[] n){
    for(int i = 0;i<n.length;i++){
      if(n[i]%3!=0&&n[i]%5!=0){
        return false;
      }
    }
    return true;
  }
}


Measured memory_bytes: 22740
#include <bits/stdc++.h>
#include <boost/multi_array.hpp>
#include <boost/optional.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/algorithm.hpp>
#include <boost/range/adaptors.hpp>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/algorithm/string/classification.hpp> // is_any_of
#include <boost/algorithm/string/split.hpp>
#include <boost/algorithm/string/join.hpp>
#include <boost/algorithm/string/replace.hpp>
#include <boost/math/tools/minima.hpp>

const int MOD = 1e9+7;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = (n); i >= 0; --i)

namespace adaptor = boost::adaptors;
using namespace std;
using boost::math::tools::brent_find_minima;
using boost::irange;
using boost::algorithm::join;
using boost::algorithm::split;
using boost::algorithm::replace_all;
using boost::multiprecision::cpp_int;
using ll = long long;
using P = pair<int, int>;

// TOP
void	Main()
{
	int n, m;
	cin >> n >> m;

	string	s;
	for (int i = 0; i < n; i++)
		s.push_back('0');
	bitset<4>	bs;
	rep(i, m)
	{
		int a;
		char b;
		cin >> a >> b;
		if (!bs.test(a) || s.at(a - 1) == b)
		{
			s.at(a - 1) = b;
			bs.set(a);
		}
		else
		{
			cout << -1 << endl;
			return ;
		}

	}
	if (n > 1 && bs.test(1) && s.at(0) == '0')
		cout << -1 << endl;
	else if (n == 1)
		cout << s << endl;
	else
	{
		if (!bs.test(1))
			s.at(0) = '1';
		cout << s << endl;
	}

}
// END

int		main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(15);
	Main();
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void)
{
	int E,Y;
	
	scanf("%d %d",&E,&Y);
	
	if(E==0)
	{
		if(Y<=1911)
		printf("M%d\n",Y-1867);
		else if(Y<=1925)
		printf("T%d\n",Y-1911);
		else if(Y<=1988)
		printf("S%d\n",Y-1925);
		else
		printf("H%d\n",Y-1988);
	}
	else if(E==1)
	printf("%d\n",Y+1867);
	else if(E==2)
	printf("%d\n",Y+1911);
	else if(E==3)
	printf("%d\n",Y+1925);
	else if(E==4)
	printf("%d\n",Y+1988);
	return 0;
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
using namespace std;
 
int main() {
 char a,b,c;
 cin>>a>>b;
 
 if(a=='9'||b=='9'){
 	cout<<"Yes"<<endl;
 }
 else {
 	cout<<"No"<<endl;
 }
  
 return 0;
 }

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

int main() {
  int a, b, n, ans;

  cin >> a >> b;

  n = b - a;

  ans = n * (1 + n) / 2 - b;
  
  cout << ans << endl;

  return 0;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define stoi stoll
using ll=long long;
using vi=vector<int>;
using pii=pair<int,int>;
#define ALL(c) begin(c),end(c)
#define RALL(c) rbegin(c),rend(c)
#define ITR(i,b,e) for(auto i=(b);i!=(e);++i)
#define FORE(x,c) for(auto &&x:c)
#define REPF(i,a,n) for(int i=a,i##len=(int)(n);i<i##len;++i)
#define REP(i,n) REPF(i,0,n)
#define REPR(i,n) for(int i=(int)(n);i>=0;--i)
#define SZ(c) ((int)c.size())
#define CONTAIN(c,x) (c.find(x)!=end(c))
#define INSEG(l,x,r) ((l)<=(x)&&(x)<(r))
#define dump(...)
#define pb push_back
#define _ 0
const signed INF_=1001001001; const long long INF=1001001001001001001LL;
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) {
    ITR(i,begin(v),end(v))os<<*i<<(i==end(v)-1?"":" ");return os;}
template<class T> istream& operator>>(istream &is,vector<T> &v) {
    ITR(i,begin(v),end(v)) is>>*i;return is;}
template<class T,class U> istream& operator>>(istream &is, pair<T,U> &p) {
    is>>p.first>>p.second;return is;}
template<class T, class U> bool chmax(T &a,const U &b){return a<b?a=b,1:0;}
template<class T, class U> bool chmin(T &a,const U &b){return a>b?a=b,1:0;}
template <class T> void PSUM(T& c) {partial_sum(begin(c), end(c), begin(c));}
template<class T> using heap=priority_queue<T,vector<T>,greater<T>>;
struct before_main_function {
    before_main_function() {
        cin.tie(0); ios::sync_with_stdio(false);
        cout << setprecision(15) << fixed;
        #define endl "\n"
    }
} before_main_function;
//------------------8<------------------------------------8<--------------------

signed main() {
    int N;
    cin >> N;
    vi a(N);
    cin >> a;
    double s = accumulate(ALL(a),0.0);
    s /= N;
    int ans = INF;
    double mn = INF;
    REP(i, N) {
        if (chmin(mn, abs(a[i] - s))) {
            ans = i;
        }
    }
    cout << ans << endl;
    return (0^_^0);
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i) = 0; (i) < (n); (i)++)
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }


int main() {
    int n;
    string s;
    cin >> n >> s;
    vector<char> table(26);
    for(int i = 0; i < s.size(); i++){
        char ans = s[i] + n > 'Z' ? s[i] + n - 26 : s[i] + n;
        cout << ans;
    }
    cout << endl;
}


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

using namespace std;

int n;
int a[2000010];
bool vis[2000010];
int prime[2000010];
void primej()
{
	vis[0] = vis[1] = 1;
	for(int i = 2; i <= n; i++)
	{
		 if(!vis[i])
		 {
		 	prime[++prime[0]] = i;
		 }
		 for(int j = 1; j <= prime[0], i * prime[j] <= n; j++)
		 {
			 vis[i*prime[j]] = 1;
	        if (i % prime[j] == 0) 
			{
	            break;
	        }
	    }
	}
}
bool paircoprime()
{
	set<int> fc;
	for(int i = 1; i <= n; i++)
	{
		int x=a[i];
        for(int j=1; prime[j]*prime[j]<=x; j++)
        if(x%prime[j]==0)
        {
         	if(fc.count(prime[j])) return 0;
              fc.insert(prime[j]);
            while(x%prime[j]==0) x/=prime[j];
        }
        if(x>1)
        {
            if(fc.count(x)) return 0;
            fc.insert(x);
        }	
	}
	return 1;
}
int gcd(int x, int y)
{
	return !y ? x : gcd(y, x % y);
}
bool setcoprime()
{
	int x = a[1];
	//cout << a[1] << endl;
	for(int i = 2; i <= n; i++)
	{
		x = gcd(x, a[i]);
	//cout << gcd(6, 10) << endl;
	}
	if(x == 1)
	{
		return true;
	}
	else
	{
		return false;
	}
}
int main()
{
	cin >> n;
	for(int i = 1; i <= n; i++)
	{
		cin >> a[i];
	}
	primej();
	if(paircoprime())
	{
		printf("pairwise coprime\n");
	}
	else if(setcoprime())
	{
		printf("setwise coprime\n");
	}
	else
	{
		printf("not coprime\n");
	}
	return 0;
}

Measured memory_bytes: 8824
#include<stdio.h>
#define INF 2140000000
#define N 102
#define white 0
#define gray 1
#define black 2

int color[N],p[N],d[N];      //ｐは親、ｄは距離

void dijkstra(int a[][N],int n){
  int i,mincost,u;

  for(i=0;i<n;i++){           //色と距離を初期化
    color[i]=white;
    d[i]=INF;
  }

  d[0]=0;                  //配列の０から考えるので、d[0]の距離は０で親はいないのでp[0]はー１
  p[0]=-1;

  while(1){
    mincost=INF;

    for(i=0;i<n;i++){             //辺の中で一番小さいものを探す
      if(color[i]!=black && d[i]<mincost){
        mincost=d[i];
        u=i;
      }
    }

    if(mincost==INF) break;     //すべての探索が終わっている場合、プログラムを終了させる

    color[u]=black;          //移動した先の頂点を黒にする

    for(i=0;i<n;i++){
      if(color[i]!=black && a[u][i]!=-1 && d[i]>a[u][i]+d[u]){  //辺があり、一番小さいものを探\\
し出す
        d[i]=a[u][i]+d[u];
        p[i]=u;
        color[i]=gray;
      }
    }
  }
}

void print(int a[][N], int n){
  int i;
  for(i=0;i<n;i++){    //0は距離がないので、１から始まる。
    printf("%d %d\n",i,d[i]);
  }
}

int main(){
  int a[N][N],n,i,j,v,k,u,c;

  scanf("%d",&n);

  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      a[i][j]=-1;
    }
  }

  for(i=0;i<n;i++){
    scanf("%d%d",&u,&k);
    for(j=0;j<k;j++){
      scanf("%d%d",&v,&c);
      a[u][v]=c;
    }
  }

  dijkstra(a,n);
  print(a,n);

  return 0;
}


Measured memory_bytes: 2044
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		
		int A,B,T;
		A=sc.nextInt();
		B=sc.nextInt();
		T=sc.nextInt();
		int total=0;
		for(int i=A;i<T+0.5;i=i+A) {
			total+=B;
			
		}
		System.out.println(total);
	}
		
	
	
		
	}
		

Measured memory_bytes: 23892
#include <iostream>
#include <iomanip>
#include <ios> 
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>
#include <map>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define sz(c) ((int)(c).size())

using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> P;
typedef pair<int, pair<int, int>> PP;
//const int MAX=;

template <typename T,typename E>
struct SegmentTree{
	using F = function<T(T,T)>;
	using G = function<T(T,E)>;
	using H = function<E(E,E)>;
	int n,height;
	F f;
	G g;
	H h;
	T ti;
	E ei;
	vector<T> dat;
	vector<E> laz;
	  SegmentTree(F f,G g,H h,T ti,E ei):
	    f(f),g(g),h(h),ti(ti),ei(ei){}
  
	void init(int n_){
		n=1;height=0;
		while(n<n_) n<<=1,height++;
		dat.assign(2*n,ti);
		laz.assign(2*n,ei);
	}
	void build(const vector<T> &v){
		int n_=v.size();
		init(n_);
		for(int i=0;i<n_;i++) dat[n+i]=v[i];
		for(int i=n-1;i;i--)dat[i]=f(dat[(i<<1)|0],dat[(i<<1)|1]);
	}
	inline T reflect(int k){
		return laz[k]==ei?dat[k]:g(dat[k],laz[k]);
	}
	inline void eval(int k){
		if(laz[k]==ei) return;
		laz[(k<<1)|0]=h(laz[(k<<1)|0],laz[k]);
		laz[(k<<1)|1]=h(laz[(k<<1)|1],laz[k]);
		dat[k]=reflect(k);
		laz[k]=ei;
	}
	inline void thrust(int k){
		for(int i=height;i;i--) eval(k>>i);
	}
	inline void recalc(int k){    
		while(k>>=1)dat[k]=f(reflect((k<<1)|0),reflect((k<<1)|1));
	}
	void update(int a,int b,E x){
		thrust(a+=n);
		thrust(b+=n-1);
		for(int l=a,r=b+1;l<r;l>>=1,r>>=1){
			if(l&1) laz[l]=h(laz[l],x),l++;
			if(r&1) --r,laz[r]=h(laz[r],x);
		}
		recalc(a);
		recalc(b);
	}
	void set_val(int a,T x){
		thrust(a+=n);
		dat[a]=x;laz[a]=ei;
		recalc(a);
	}
	T query(int a,int b){
		thrust(a+=n);
		thrust(b+=n-1);
		T vl=ti,vr=ti;
		for(int l=a,r=b+1;l<r;l>>=1,r>>=1) {
			if(l&1) vl=f(vl,reflect(l++));
			if(r&1) vr=f(reflect(--r),vr);
		}
		return f(vl,vr);
	}
};

int main(){
	int N,M;
	cin>>N>>M;
	priority_queue<PP, vector<PP>, greater<PP>> que;
	rep(i,N){
		int l, r;
		cin>>l>>r;
		r++;
		PP p=make_pair(r-l, make_pair(l,r));
		que.push(p);
	}
	
	auto f=[](int a, int  b){return a+b;};
	SegmentTree<int,int> seg(f,f,f,0,0);
	
	seg.init(M+1);
	int mb=N;
  	bool rem=true;
	rep1(d,M){
		while(rem){
			PP pp=que.top();
			if(pp.first<d){
				P p=pp.second;
				int l=p.first;
				int r=p.second;
				seg.update(l,r,1);
				que.pop();
				mb--;
				
			}
			else break;
			if(que.empty()) rem=false;
		}
		int ans=mb;
		for(int i=0; i<=M; i+=d){
			ans+=seg.query(i,i+1);
		}
		cout<<ans<<endl;
	}
}

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

using namespace std;

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

  int min_c = 10000,min_t=10000;
  for (int i = 0; i < N; ++i)
  {
    int c, t;
    cin >> c >> t;

    if (t <= T)
    {
      if (min_c > c)
      {
        min_t = t;
        min_c = c;
      }
    }
  }

  if (min_t <= 1000) cout << min_c << endl;
  else cout << "TLE" << endl;
}

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

using namespace std;

int main() {
    //freopen("input.txt", "r", stdin);
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    int a[2][n];
    for(int i = 0; i < n; i++) {
        cin >> a[0][i];
    }
    for(int i = 0; i < n; i++) {
        cin >> a[1][i];
    }
    int sum1 = accumulate(a[0], a[0] + n, 0);
    int sum2 = accumulate(a[1], a[1] + n, 0);
    int ans = 0;
    int ps1 = 0, ps2 = 0;
    for(int i = 0; i < n; i++) {
        ps1 += a[0][i];
        ans = max(ans, ps1 + (sum2 - ps2));
        ps2 += a[1][i];
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <math.h>
#include <complex>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <functional>
#include <assert.h>
#define int long
#define ll long long
#define fi first
#define se second
#define rep(i, n) for(int i = 0; i < n; i++)
const int INF = 1e9;
using namespace std;

signed main() {
    int N; cin >> N;
    int ans=0;
    int maxL=0,minR=INF;
    int L[N],R[N];
    rep(i,N){
        cin >> L[i] >> R[i];
        L[i]--;
        maxL=max(L[i],maxL);
        minR=min(R[i],minR);
        ans=max(R[i]-L[i],ans);
    }
    ans+=max((int)0,minR-maxL);
    vector<pair<int,int>> p;
    rep(i,N){
        int a=max((int)0,minR-L[i]);
        int b=max((int)0,R[i]-maxL);
        p.push_back(make_pair(a,b));
    }
    sort(p.begin(),p.end());
    //aを昇順でソートしてminRを含むグループにすべて持ってもらう
    //そこからmaxLのグループｓに一つずつ渡していく
    int s=INF;
    rep(i,N){
        if(i) ans=max(ans,s+p[i].fi);
        s=min(s,p[i].se);
    }
    cout << ans << endl;
}

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

const int MAXN = 1010;
int G[MAXN*2][MAXN*2];

int calc(int x1, int y1, int x2, int y2)
{
    return G[x2][y2] - G[x1][y2] - G[x2][y1] + G[x1][y1];
}

int main()
{
    int n,k,x,y;
    char ch;
    scanf("%d %d",&n,&k);
    for(int i = 0; i < n; ++i)
    {
        scanf("%d %d %c",&x,&y,&ch);
        x = x%(2*k);
        y = y%(2*k);
        if(ch == 'W')
            y += k;
        ++G[x%(2*k)+1][y%(2*k)+1];
    }
    for(int i = 1; i <= 2*k; ++i)
        for(int j = 1; j <= 2*k; ++j)
            G[i][j] = G[i][j] + G[i-1][j] + G[i][j-1] - G[i-1][j-1];

    int res = 0, sum;
    for(int i = 1; i <= k; ++i)
    {
        for(int j = 1; j <= k; ++j)
        {
            sum = calc(0,0,i,j);
            sum += calc(i,j,i+k,j+k);
            sum += calc(i+k,j+k,2*k,2*k);
            sum += calc(i+k,0,2*k,j);
            sum += calc(0,j+k,i,2*k);
            sum = max(sum,n-sum);
            res = max(res,sum);
        }
    }
    printf("%d\n",res);
    return 0;
}


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

int main(){
  int n,m;
  long long int a=1;
  cin >> n >> m;
  if(abs(n-m)>=2){
    cout << 0 << endl;
    return 0;
  }
  for(int i=1;i<=n;i++){
    a = (a*i)%1000000007;
  }
  for(int i=1;i<=m;i++){
    a = (a*i)%1000000007;
  }
  if(n==m){
    a = (a*2)%1000000007;
    cout << a << endl;
  }else{
    cout << a << endl;
  }
  return 0;
}


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

//template
#define rep(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define ALL(v) (v).begin(),(v).end()
typedef long long int ll;
const int inf = 0x3fffffff; const ll INF = 0x1fffffffffffffff; const double eps=1e-12;
template<typename T>inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T>inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
//end

typedef pair<int,int> P;
typedef pair<int,P> T;

char g[1010][1010];
int dst[1010][1010];
int dx[]={1,-1,0,0},dy[]={0,0,1,-1};

int main(){
   int h,w; cin>>h>>w;
   int x,y,gx,gy;
   cin>>x>>y>>gx>>gy;
   x--; y--; gx--; gy--;
   rep(i,0,h)rep(j,0,w){
      cin>>g[i][j];
      dst[i][j]=inf;
   }
   dst[x][y]=0;
   priority_queue<T,vector<T>,greater<T>> que; que.push({0,{x,y}});
   while(!que.empty()){
      auto [d,pos]=que.top(); que.pop();
      if(dst[pos.first][pos.second]<d)continue;
      rep(i,0,4){
         int tx=pos.first+dx[i],ty=pos.second+dy[i];
         if(tx<0 or tx>h or ty<0 or ty>w or g[tx][ty]=='#')continue;
         if(chmin(dst[tx][ty],d))que.push({d,{tx,ty}});
      }
      rep(i,-2,3)rep(j,-2,3){
         int tx=pos.first+i,ty=pos.second+j;
         if(tx<0 or tx>h or ty<0 or ty>w or g[tx][ty]=='#')continue;
         if(chmin(dst[tx][ty],d+1))que.push({d+1,{tx,ty}});
      }
   }
   if(dst[gx][gy]==inf)cout<<"-1"<<endl;
   else cout<<dst[gx][gy]<<endl;
   return 0;
}


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

int main() {
  int a,b;
  string s;
  cin >> s;
  for(int i =0;i != s.size();i++){
    if(s[i] == 'A') {
      a = i;
      break;
    }
  }
   for(int i =s.size()-1;i != 0;i--){
    if(s[i] == 'Z') {
      b = i;
      break;
    }
  }
   cout << (b-a)+1 << endl;
  return 0;
}


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

using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

constexpr int I_INF = numeric_limits<int>::max();
constexpr ll L_INF = numeric_limits<ll>::max();

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

ll N, M;
using Graph = vector<Vi>;
Graph g;
Vi pre;
Vi dist;

void solve() {
    cin >> N >> M;
    g.resize(N);
    for (ll i = 0; i < M; i++) {
        int u, v;
        cin >> u >> v;
        --u, --v;
        g[u].emplace_back(v);
        g[v].emplace_back(u);
    }

    pre.assign(N, -1);
    dist.assign(N, -1);
    queue<Pii> q;
    q.emplace(0, 0);
    dist[0] = 0;
    while (!q.empty()) {
        auto [idx, d] = q.front();
        q.pop();
        for (const auto& to : g[idx]) {
            if (dist[to] != -1) continue;
            pre[to] = idx;
            dist[to] = d + 1;
            q.emplace(to, d + 1);
        }
    }

    cout << "Yes\n";
    for (ll i = 1; i < N; i++) {
        cout << pre[i] + 1 << "\n";
    }
}

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

int main() {
#ifdef FASTIO
    cin.tie(0), cout.tie(0);
    ios::sync_with_stdio(false);
#endif
#ifdef FILEINPUT
    ifstream ifs("./in_out/input.txt");
    cin.rdbuf(ifs.rdbuf());
#endif
#ifdef FILEOUTPUT
    ofstream ofs("./in_out/output.txt");
    cout.rdbuf(ofs.rdbuf());
#endif
    solve();
    cout << flush;
    return 0;
}

Measured memory_bytes: 10860
import java.util.*;
public class Main {

  public static void main(String[] args) { 
      Scanner sc = new Scanner(System.in);
      int a = sc.nextInt();
      int b = sc.nextInt();
      int c = sc.nextInt();
      int d = sc.nextInt();

      while(true) {
        c -= b;
        if(c <= 0) {
          System.out.println("Yes");
          return;
        }
        a -= d;
        if(a <= 0) {
          System.out.println("No");
          return;
        }
      }
  }
}

Measured memory_bytes: 35704
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

const int MAX = 1000000;
bool prime[MAX];
vector<int> V;
int ans;

void make(){
  fill(prime,prime+MAX,1);
  prime[0] = prime[1] = 0;
  for(int i = 2; i*i < MAX; i++)
    if(prime[i])
      for(int j = 2*i; j < MAX; j+=i)
	prime[j] = 0;

  V.push_back(2);
  for(int i = 3; i < MAX; i+=2)
    if(prime[i]) V.push_back(i);

}

int solve(int p, int m){
  int num = upper_bound(V.begin(),V.end(),p+m)-
    lower_bound(V.begin(),V.end(),p-m);
  return num-1;
}
int main(){
  make();
  int num;
  while(cin >> num && num){
    ans = 0;
    for(int i = 0; i < num; i++){
      int p,m;
      cin >> p >> m;
      ans += solve(p,m);
    }
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>

using namespace std;

int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    sort(a.begin(), a.end(), greater<int>());
    int alice = 0;
    int bob = 0;
    for (int i = 0; i < n; ++i) {
        if (i % 2) bob += a[i];
        else alice += a[i];
    }
    cout << alice - bob << endl;

    return 0;
}

Measured memory_bytes: 256
import copy as cp
N,K = input().split()
P = input().split()
# P=(int(x) for x in input().split())
PP = [int(n) for n in P]
# print(PP)
print(sum(sorted(PP)[0:int(K)]))
# print(PP)
# C = sorted(PP)
# print(C[0:int(K)])
# ll=cp.copy(sorted(P))
# aa = [50, 80, 80, 100, 120]
# print(ll[0:2])
# print(aa[0:2])
# print(P)

Measured memory_bytes: 9384
#include<stdio.h>
int main()
{
	double N, a, counter=0;
	scanf("%lf", &N);
	for(a=0; a <=14; a++){
		if(fmod(N-7*a,4)==0 && N>=7*a && N>=1 && N<=100){
			counter = counter + 1;
			break;
		}
	}
	if(counter==1){
		printf("Yes");
	}else{
		printf("No");
	}
	return 0;
}

Measured memory_bytes: 128
import sys
import math
import fractions

sys.setrecursionlimit(10000)
INF = float('inf')


def inp():
    return int(input())


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


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


def Yesif(cond):
    print('Yes' if cond else 'No')


def YESIF(cond):
    print('YES' if cond else 'NO')


def yesif(cond):
    print('yes' if cond else 'no')


N = inp()
A = inl()

ans = {A[1]}
gcd = A[0]
for a in A[1:]:
    ans = {fractions.gcd(r, a) for r in ans}
    ans.add(gcd)
    gcd = fractions.gcd(gcd, a)

print(max(ans))


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

using namespace std;

vector <long long> a;

long long tbl[2*100000] = {0}; // 何番目に訪れた？

int main(){
  int n;
  unsigned long long k;
  int tmp;
  cin >> n >> k;
  cin.ignore();

  for(int i = 0; i < n; i++){
    cin >> tmp;
    --tmp;
    a.push_back(tmp);
  }
  cin.ignore();

  // Nまでだったら砂ぽに求める
  if(k <= n){
    int point = 0;
    while(k > 0){
      --k;
      point = a[point];
    }
    cout << point + 1 << endl;
    return 0;
  }

  // どっかでループができている
  for(int i = 0; i < 2*100000; i++){
    tbl[i] = -1;
  }

  tbl[0] = 0; // 0は0番目
  int point = 0;
  long long loop;
  int l_start = 0;
  int cnt = 0;
  while(true){
    tmp = a[point];
    ++cnt;
    if(point == tmp){ // それ以上移動しない
      cout << point + 1 << endl;
      return 0;
    }
    if(tbl[tmp] >= 0){ // tmpと
      loop = cnt - tbl[tmp];
      l_start = tmp;
      tbl[tmp] = cnt;
      break;
    }
    tbl[tmp] = cnt;
    point = tmp;
  }

  /*
  for (int i = 0; i < n; i++){
    cout << tbl[i] << " " << flush;
  }
  cout << endl;
  cout << "loop " << loop << endl;
  cout << "l_start " << l_start << endl;
  */
  // ループをあらためてたどる
  k -= tbl[l_start];
  k %= loop;

  // あとは素直にたどるだけ
  point = l_start;
  while( k > 0){
    k--;
    point = a[point];
  }
  cout << point+1 << endl;
  return 0;
}


Measured memory_bytes: 6388
//#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <stdio.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <time.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;

#define fi first
#define se second
#define mp make_pair
 
const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll MOD3 = 1812447359;
const ll INF = 1ll << 62;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

int N; string S;
ll ans = 0;

int Solve(ll sum, ll now, int turn){
  if (turn == N){
    ans += sum + now;
    return 0;
  }
  Solve(sum + now, 0, turn + 1);
  now *= 10; now += S[turn] - '0';
  Solve(sum, now, turn + 1);
  return 0;
}

int main(){
  cin >> S; N = S.length();
  Solve(0, 0, 0);
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
use std::io;

fn procon_read<T: std::str::FromStr>() ->  Vec<T> {
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).expect("");
    let iter = buf.split_whitespace();
    let mut v: Vec<T> = Vec::new();
    for i in iter {
        v.push(i.parse().ok().unwrap());
    }
    v
}

fn main() {
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).expect("");
    let s = buf.trim();
    if s == "RRR" {
        println!("3");
    }else if s == "RRS" || s == "SRR" {
        println!("2");
    }else if s == "RSS" || s == "SRS" || s == "SSR" || s == "RSR" {
        println!("1");
    }else {
        println!("0");
    }
}

Measured memory_bytes: 2120
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
long long inf=(long long)1E17;
#define i_7 (long long)(1E9+7)
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
using namespace std;
long long gcd(long long a, long long b){
  if(a<b){
    swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd(b,a%b);
  }
}
 
long long lcm(long long x, long long y){
  return (x/gcd(x,y))*y;
}
 
class UnionFind {
    public:
    //各頂点の親の番号を格納する。その頂点自身が親だった場合は-(その集合のサイズ)を入れる。
    vector<int> Parent;
    
    //クラスを作るときは、Parentの値を全て-1にする。
    //以下のようにすると全てバラバラの頂点として解釈できる。
    UnionFind(int N) {
        Parent = vector<int>(N, -1);
    }
    
    //Aがどのグループに属しているか調べる
    int root(int A) {
        if (Parent[A] < 0) return A;
        return Parent[A] = root(Parent[A]);
    }
    
    //自分のいるグループの頂点数を調べる
    int size(int A) {
        return -Parent[root(A)];//先祖をrootで取っておきたい。
    }
    
    //AとBをくっ付ける
    bool connect(int A, int B) {
        //AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
        A = root(A);
        B = root(B);
        if (A == B) {
            //すでにくっついてるからくっ付けない
            return false;
        }
        
        //大きい方(A)に小さいほう(B)をくっ付けたい
        //大小が逆だったらAとBをひっくり返す。
        if (size(A) < size(B)) swap(A, B);
        
        //Aのサイズを更新する
        Parent[A] += Parent[B];
        //Bの親をAに変更する
        Parent[B] = A;
        
        return true;
    }
};
 
int main(){
  int a,b;
  cin>>a>>b;
  if(a==b){
    cout<<"Draw"<<endl;
  }else if(a==1){
    cout<<"Alice"<<endl;
  }else if(b==1){
    cout<<"Bob"<<endl;
  }else if(a>b){
    cout<<"Alice"<<endl;
  }else{
    cout<<"Bob"<<endl;
  }
  return 0;
}


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

int main() {
	ios::sync_with_stdio(0), cin.tie(0);
	int n;
	cin >> n;
	int ans = 0;
	vector<vector<int> > dist(n, vector<int>(n));
	vector<vector<bool> > occupied(n, vector<bool>(n, true));
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			dist[i][j] = min(min(i+1, n-i), min(j+1, n-j));
		}
	}
	vector<int> bfs;
	bfs.reserve(n * n);
	const int mx[4] = {0, 1, 0, -1};
	const int my[4] = {1, 0, -1, 0};
	for (int _ = 0; _ < n * n; _++) {
		int cur;
		cin >> cur;
		cur--;
		int sx = cur / n, sy = cur % n;
		occupied[sx][sy] = false;
		dist[sx][sy]--;
		ans += dist[sx][sy];
		bfs.clear();
		bfs.push_back(cur);
		for (int s = 0; s < int(bfs.size()); s++) {
			int v = bfs[s];
			int x = v / n, y = v % n;
			for (int d = 0; d < 4; d++) {
				int nx = x + mx[d], ny = y + my[d];
				if (0 <= nx && nx < n && 0 <= ny && ny < n) {
					int nd = occupied[nx][ny] + dist[x][y];
					if (nd < dist[nx][ny]) {
						dist[nx][ny] = nd;
						bfs.push_back(nx * n + ny);
					}
				}
			}
		}
	}
	cout << ans << '\n';
}


Measured memory_bytes: 5244
from collections import defaultdict
import sys
sys.setrecursionlimit(10**9)
input=sys.stdin.readline
N,K,L=map(int,input().split())

def get_par(x):
  if x == par_list[x]:
    return x
  else:
    par_list[x] = get_par(par_list[x])
    return par_list[x]
def merge(x,y):
  par_x = get_par(x)
  par_y = get_par(y)
  if par_x != par_y:
    par_list[par_y] = par_x
def is_same(x,y):
  return get_par(x) == get_par(y)

par_list=list(range(N+1))
for _ in range(K):
  p,q=map(int,input().split())
  merge(p,q)
for i in range(1,N+1):
  par_list[i]=get_par(i)
par_list_road=par_list[:]
  
par_list=list(range(N+1))
for _ in range(L):
  r,s=map(int,input().split())
  merge(r,s)
for i in range(1,N+1):
  par_list[i]=get_par(i)
par_list_rail=par_list[:]

#print(par_list_road)
#print(par_list_rail)
answer_dic=defaultdict(int)
for i in range(1,N+1):
  road_i=par_list_road[i]
  rail_i=par_list_rail[i]
  answer_dic[(road_i,rail_i)]+=1
  
answer_list=[]
for i in range(1,N+1):
  road_i=par_list_road[i]
  rail_i=par_list_rail[i]
  answer_list.append(answer_dic[(road_i,rail_i)])
  
print(*answer_list)

Measured memory_bytes: 51980
//JSD
#include<iostream>
#include<map>
#include<algorithm>
#define ll long long 
using namespace std;
int main(){
	int n;
	cin>>n;
	if(n==1) {
		cout<<1;
		return 0;
	}
	ll ans=0;
	map<string ,ll > m;
	for(int i=0;i<n;i++){
		string s;
		cin>>s;
		sort(s.begin(),s.end());	
		m[s]++;
	}
	for(auto x: m){
		ans+=((x.second*(x.second-1))/2);
	}
	cout<<ans<<"\n";
	return  0;
}

Measured memory_bytes: 11136
#include <bits/stdc++.h>
#define INF (int)1e9
#define endl "\n"
#define ll long long
#define ull unsigned long long

using namespace std;

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

    cout << (a[2] == a[3] and a[4] == a[5] ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int N = sc.nextInt();
		
		String currentWord = sc.next();
		List<String> words = new ArrayList<>();
		words.add(currentWord);
		
		String lastWord = "";
		
		for (int i = 0; i < N - 1; i++) {
			currentWord = sc.next();
			if (words.contains(currentWord)) {
				System.out.println("No");
				return;
			}
			lastWord = words.get(words.size() - 1);
			if (lastWord.substring(lastWord.length() - 1).equals(currentWord.substring(0, 1))) {
				words.add(currentWord);
			} else {
				System.out.println("No");
				return;
			}
		}
		System.out.println("Yes");
	}
}


Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define SZ(x) ((int)(x).size())
#define debug(x) cerr << #x << ": " << x << '\n'
#define INF 999999999
typedef long long int Int;
using ll = long long;
using VI = vector<int>;

int main(){
  int n,k;cin >> n >> k;
  int ans = 0;
  vector<int> a(n);
  for(auto &i:a) cin >> i;
  sort(a.rbegin(),a.rend());
  for(int i=0;i<k;i++){
    ans += a[i];
  }
  cout << ans << endl;
}


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

using namespace std;
typedef long long ll;
typedef pair<int,int>pa;

const int N=2e5+100;
const int mod=1e9+7;
ll x[N],y[N];

ll A[N];
ll qpow(ll x,ll n)
{
    ll sum=1;
    while(n){
        if(x&1) sum=sum*x%mod;
         x=x*x%mod;
         n>>=1;
    }
    return sum;
}
void init()
{
    A[0]=1;
   for(int i=1;i<=1e5;i++)
      A[i]=A[i-1]*i%mod;
}
ll C(ll x,ll y)
{
    if(y==0) return 1;
    //return A[x]*qpow(A[y],mod-2)%mod*qpow(A[x-y],mod-2)%mod;
     return A[x]/A[y]/A[x-y];
}
int main()
{
    ios::sync_with_stdio(0);cin.tie(0);
    ll n,m;
    cin>>n>>m;
    for(int i=1;i<=n;i++)
        cin>>x[i];
    for(int i=1;i<=m;i++)
         cin>>y[i];
    ll xx=0,yy=0;
    for(int i=1;i<=n;i++){
        xx=(xx+(i-1)*x[i]-(n-i)*x[i])%mod;
    }
    for(int i=1;i<=m;i++){
        yy=(yy+(i-1)*y[i]-(m-i)*y[i])%mod;
    }
    cout<<xx*yy%mod;
    return 0;
}



Measured memory_bytes: 5240
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, core.bitop;

enum inf3 = 1_001_001_001;
enum inf6 = 1_001_001_001_001_001_001L;
enum mod = 1_000_000_007L;




void main() {
    int n;
    scan(n);

    auto x = new int[](n);
    auto y = new int[](n);
    auto h = new int[](n);

    foreach (i ; 0 .. n) {
        scan(x[i], y[i], h[i]);
    }

    int k = -1;
    foreach (i ; 0 .. n) {
        if (h[i] > 0) {
            k = i;
            break;
        }
    }

    foreach (cx ; 0 .. 101) {
        foreach (cy ; 0 .. 101) {
            int H = h[k] + abs(cx - x[k]) + abs(cy - y[k]);

            bool ok = true;

            foreach (i ; 0 .. n) {
                if (max(0, H - abs(cx - x[i]) - abs(cy - y[i])) != h[i]) {
                    ok = false;
                    break;
                }
            }

            if (ok) {
                writefln("%d %d %d", cx, cy, H);
                return;
            }
        }
    }
}





















void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}

void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

bool chmin(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x > arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}

bool chmax(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x < arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    string s , t , u ;
    int a , b ;
    cin>> s>> t;
    cin>> a>> b;
    cin>>u;
    if(s == u){
    a--;
    cout<< a <<" "<< b;
    }else{
    b--;
    cout<< a <<" "<< b;
    }

        return 0;
}


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

bool Solve() {
  int n;
  cin >> n;
  set<string> said;
  char c = '\0';
  for (int i = 0; i < n; ++i) {
    string w;
    cin >> w;
    if (c && w.front() != c)
      return false;
    if (!said.insert(w).second)
      return false;
    c = w.back();
  }
  return true;
}

int main() {
  if (Solve())
    cout << "Yes\n";
  else
    cout << "No\n";
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long int lli;
using namespace std;
//Correct memoized soln
int fn(vector<vector<int>> inp, vector<vector<int>>& t){
	t[inp.size() - 1][0] = 0;
	t[inp.size() - 1][1] = 0;
	t[inp.size() - 1][2] = 0;

	for(int i = inp.size() - 2; i >= 0; i--){
		for(int j = 0; j < 3; j++){
			if(j == 0){
				t[i][j] = inp[i][j] + max(t[i + 1][1], t[i + 1][2]);
			}
			else if(j == 1){
				t[i][j] = inp[i][j] + max(t[i + 1][0], t[i + 1][2]);
			}
			else{
				t[i][j] = inp[i][j] + max(t[i + 1][0], t[i + 1][1]);
			}
		}
	}

	return max({t[0][0], t[0][1], t[0][2]});
}
int main(){
	int n, a, b, c;
	cin >> n;

	vector<vector<int>> inp(n + 1, vector<int>());
	vector<vector<int>> t(n + 1, vector<int>(3, -1));

	for(int i = 0; i < n; i++){
		cin >> a >> b >> c;
		inp[i].push_back(a);
		inp[i].push_back(b);
		inp[i].push_back(c);
	}
	cout << fn(inp, t) << endl;
}

Measured memory_bytes: 16640
// SeeAlso: https://atcoder.jp/contests/abc154/tasks/abc154_c

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define MAX 100000
#define NIL -1
#define MOD 1000000007

typedef int _loop_int;
#define rep(i,n) for(int i = 0; i < n; i++)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define debug(x) cout<<#x<<": "<<x<<endl
#define debig_vec(v) cout<<#v<<":";rep(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

// 最大公約数
inline constexpr ll gcd(ll a,ll b){if(!a||!b)return 0;while(b){ll c=b;b=a%b;a=c;}return a;}
// 最小公倍数
inline constexpr ll lcm(ll a,ll b){if(!a||!b)return 0;return a*b/gcd(a,b);}

#define print2D(h, w, arr) rep(i, h) { rep(j, w) cout << arr[i][j] << " "; cout << endl; }
template<class T> void print(const T& x){cout << setprecision(12) << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }

int main (){ 
    ll n;
    set<ll> a;
    cin >> n;

    rep(i, n) {
        ll c;
        cin >> c;
        a.insert(c);
    }

    print((a.size()==n)?"YES":"NO");

    return 0;
}


Measured memory_bytes: 9600
#include <bits/stdc++.h>
using namespace std;
int sqr(int x){
	return x*x;
}
int main()
{
	int n,a[101];
	cin>>n;
	int ans=0;
	for(int i=1;i<=n;i++){
		cin>>a[i];
		ans+=sqr(a[i]-0);
	}
	for(int x=-100;x<=100;x++)
	{
		int tmp=0;
		for(int i=1;i<=n;i++){
			tmp+=sqr(a[i]-x);
		}
		ans=min(ans,tmp);
	}
	cout<<ans;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<cmath>
using namespace std;
int main(void) {
	int N,n,count=0;
	cin >> N;

	for (int i = 3; i >= 0; i--) {
		n = N / pow(10, i);
		N -= n * pow(10, i);
		if (n == 2)
			count++;
	}

	cout << count << endl;

	return 0;
}

Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;

struct Scanner<R: Read> {
    reader: R,
}

#[allow(dead_code)]
impl<R: Read> Scanner<R> {
    fn new(reader: R) -> Scanner<R> {
        Scanner { reader: reader }
    }

    fn safe_read<T: FromStr>(&mut self) -> Option<T> {
        let token = self.reader.by_ref().bytes().map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        if token.is_empty() {
            None
        } else {
            token.parse::<T>().ok()
        }
    }

    fn read<T: FromStr>(&mut self) -> T {
        if let Some(s) = self.safe_read() {
            s
        } else {
            writeln!(stderr(), "Terminated with EOF").unwrap();
            std::process::exit(0);
        }
    }
}

fn main() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin);

    loop {
        let m: i32 = sc.read();
        let f: i32 = sc.read();
        let r: i32 = sc.read();
        let ans = match (m, f, r) {
            (-1, -1, -1) => break,
            (-1, _, _) | (_, -1, _) => 'F',
            _ if m + f >= 80 => 'A',
            _ if m + f >= 65 => 'B',
            _ if m + f >= 50 => 'C',
            _ if m + f >= 30 && r >= 50 => 'C',
            _ if m + f >= 30 => 'D',
            _ => 'F',
        };
        println!("{}", ans);
    }    
}



Measured memory_bytes: 5032
/* {{{ */
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}
/* }}} */

fn main() {
    input! {
        n: usize,
        a: [usize1;n],
        b: [u32;n],
        c: [u32;n-1]
    }
    let mut res = b[a[0]];
    for i in 1..n {
        res += b[a[i]];
        if a[i-1] + 1 == a[i] {
            res += c[a[i]-1];
        }
    }
    println!("{}", res);
}
/* vim:set foldmethod=marker: */


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+10;
int n;
int a[N];
string s;
void solve(){
    cin>>s;
    if(s[s.size() - 1] == 's'){cout<<s<<"es"<<endl;return;}
    cout<<s<<"s"<<endl;
    
}
int main(){
    int t=1;
    //cin>>t;
    while(t--){
        solve();
    }
}

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

int main(){
	int n;
	cin >> n;
	int k;
	cin >> k;
	vector<int> vec(n);
	for (int i = 0; i < n; i++) cin >> vec.at(i);
	int ans = 0;
	for (int i = 0; i < n; i++) {
		ans += min(vec.at(i), k - vec.at(i)) * 2;
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
y, m, d =  gets.chomp.split("/").map(&:to_i)
if y < 2019
  puts "Heisei"
  exit
elsif y <= 2019
  if m <= 4
    puts "Heisei"
    exit
  else
    puts "TBD"
    exit
  end
else
  puts "TBD"
  exit
end

Measured memory_bytes: 1788
def c_make_a_rectangle(N, A):
    from collections import Counter
    stick = Counter(A)  # ある長さの棒が何本あったか
    rectangle = []
    for length, num in sorted(stick.items(), reverse=True):  # 長いもの順に見る
        rectangle.extend([length] * (num // 2))  # 2本組を何個作れるか
    ans = 0 if len(rectangle) <= 1 else rectangle[0] * rectangle[1]
    return ans

N = int(input())
A = [int(i) for i in input().split()]
print(c_make_a_rectangle(N, A))

Measured memory_bytes: 21284
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define rREP(i,m,n) for(int (i)=(n)-1; (i)>=(m);--(i))
#define all(x) (x).begin(),(x).end()
#define out(y,x,h,w) (y)<0||(x)<0||(y)>=(h)||(x)>=(w)
constexpr int INF = 1000000001;
constexpr ll mod = 1000000007;
constexpr double PI = 3.1415926535897932;

template<class T>inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
template<class T>inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
inline void init() {
	cin.tie(nullptr); cout.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

int main() {
	init();

	ll N, A, B;
	cin >> N >> A >> B;
	ll x = A + B;
	ll cnt = N / x;
	ll ans = A * cnt;
	if (N - x*cnt >= A) {
		ans += A;
	}
	else {
		ans += N - x*cnt;
	}
	cout << ans << "\n";
		
	return 0;
}

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

using namespace std;

int main() {
	ios_base::sync_with_stdio(false);
	int k, n;
	cin>>k>>n;
	int sum = 0;
	int maxInterval = 0;
	int last = -1;
	for (int i = 0; i < n; i++) {
		int cur;
		cin>>cur;
		if (last != -1) {
			maxInterval = max(maxInterval, cur - last);
			sum += cur - last;
		}
		last = cur;
	}
	maxInterval = max(maxInterval, k - sum);
	cout<<k - maxInterval<<endl;
	return 0;
}

Measured memory_bytes: 256
n=int(input())
c=[[0]*10 for i in range(10)]
for i in range(1,n+1):
  s=str(i)
  c[int(s[0])][int(s[-1])]+=1
ans=0
for i in range(10):
  for j in range(10):
    ans+=c[i][j]*c[j][i]
print(ans)

Measured memory_bytes: 40428
x,k,d = map(int,input().split())
x = abs(x)
num = x//d
a = x-d*num
b = abs(a-d)
if x >= (d*k):
  print(x-(d*k))
  exit()
else:
  if min(a,b) == b:
    num += 1
  if (k-num) % 2 == 0:
    print(min(a,b))
  else:
    print(max(a,b))
  

Measured memory_bytes: 9088
main :: IO ()
main = do
    [x1, y1, x2, y2] <- fmap (map read . words) getLine :: IO [Int]
    let dx = x1 - x2
        dy = y1 - y2
    putStrLn
        $  (show (x2 + dy))
        ++ " "
        ++ (show (y2 - dx))
        ++ " "
        ++ (show (x1 + dy))
        ++ " "
        ++ (show (y1 - dx))


Measured memory_bytes: 508
#include <algorithm>
#include <cassert>
#include <iostream>
#include <set>
#include <vector>

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

int main() {

  int n, q;
  cin >> n >> q;
  struct E {
    int t, val;
    bool add;
  };
  vector<E> events;
  rep(_, n) {
    int s, t, x;
    cin >> s >> t >> x;
    events.push_back(E{s - x, x, true});
    events.push_back(E{t - x, x, false});
  }
  sort(events.begin(), events.end(),
       [&](const auto &lhs, const auto &rhs) { return lhs.t == rhs.t ? rhs.add : lhs.t < rhs.t; });
  const int inf = 1e9 + 7;
  vector<int> cand(n * 2, inf);
  set<int> s;
  rep(i, n * 2) {
    const auto &ev = events[i];
    if (ev.add) {
      s.insert(ev.val);
    } else {
      s.erase(ev.val);
    }
    if (s.size() > 0) {     // 工事中がひとつ以上ある
      cand[i] = *s.begin(); // 最左 (原点に近い座標)
    }
  }
  while (q--) {
    int d;
    cin >> d;
    auto it = upper_bound(
        events.begin(), events.end(), E{d, 0, false},
        [&](const auto &lhs, const auto &rhs) { return lhs.t < rhs.t; });
    auto j = it - events.begin();
    if (j == 0 or j == n * 2) {
      cout << -1 << endl;
      continue;
    }
    auto ans = cand[j - 1];
    if (ans == inf) ans = -1;
    cout << ans << endl;
  }
  return 0;
}


Measured memory_bytes: 17772
#include<stdio.h>

/**
 * src から dst までの最短距離を求める
 */
int solve(int src, int dst) {
  int answer = 0;
  if (src == dst) return 0;
  if (src % 2 != 0) { answer++; src++; }
  if (dst % 2 != 0) { answer++; dst--; }
  answer += solve(src / 2, dst / 2);
  return answer;
}

int main(){
  int N, s, d, i;
  scanf("%d", &N);
  for ( i = 0; i < N; i++ ){
    scanf("%d %d", &s, &d);
    printf("%d\n", solve(s, d));
  }
  return 0;
}




Measured memory_bytes: 2112
S=int(input())
L=[S]
ind=1
while True:    
  if L[ind - 1] % 2 == 0:
    s = L[ind - 1] // 2
  else:
    s = L[ind - 1] * 3 + 1
  
  if L.count(s) != 0:
    ind += 1
    break
  ind += 1
  L.append(s)
print(ind)

Measured memory_bytes: 3060