akhauriyash/Code-Regression huggingface dataset:
l=map(str,raw_input().split())
cnt={}
w=ans=""
for i in l:
    if len(i)>len(w):
        w=i
    if cnt.has_key(i):
        cnt[i]+=1
    else:
        cnt[i]=1
t=0
for i in cnt:
    if cnt[i]>t:
        t=cnt[i]
        ans=i
print ans,w

Measured memory_bytes: 6224
#include<bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
#define mk make_pair
#define f first
#define s second
using namespace std;
int h,w,a[1199][1199],d[1199][1199],yy,xx,p,ans;
int dx[]={1,-1,0,0};
int dy[]={0,0,1,-1};
vector<pair<int,pair<int,int> > >v;
vector<pair<int,int> >vv;
bool used[1199][1199];
void bfs(){
  queue<pair<int,pair<int,int> > >q;
  q.push(mk(p,mk(yy,xx)));
  d[yy][xx]=p;
  while(!q.empty()){
    pair<int,pair<int,int> > g=q.front();q.pop();
    int ya=g.s.f,xa=g.s.s,dd=g.f;
    r(i,4){
      int y=ya+dy[i],x=xa+dx[i];
      if(y<0||y>=h||x<0||x>=w)continue;
      if(a[y][x]>dd){
        if(d[y][x]&&d[y][x]!=p)vv.push_back(mk(y,x));
        if(!d[y][x])q.push(mk(a[y][x],mk(y,x)));
        d[y][x]=p;
      }
    }
  }
}
void bfs2(int yy,int xx,int dd){
  queue<pair<int,pair<int,int> > >q;
  q.push(mk(dd,mk(yy,xx)));
  if(!used[yy][xx]){
    used[yy][xx]=1;
    while(!q.empty()){
      pair<int,pair<int,int> > g=q.front();q.pop();
      ans++;
      int yy=g.s.f,xx=g.s.s,dd=g.f;
      r(i,4){
        int y=yy+dy[i],x=xx+dx[i];
        if(y<0||y>=h||x<0||x>=w)continue;
        if(a[y][x]>dd&&!used[y][x]){
          q.push(mk(a[y][x],mk(y,x)));
          used[y][x]=1;
        }
      }
    }
  }
}
main(){
  cin>>h>>w;
  r(i,h)r(j,w){
    cin>>a[i][j];
    v.push_back(mk(a[i][j],mk(i,j)));
  }
  sort(v.begin(),v.end());
  r(i,h*w){
    yy=v[i].s.f,xx=v[i].s.s,p=v[i].f;
    if(d[yy][xx])continue;
    bfs();
  }
  r(i,vv.size())bfs2(vv[i].f,vv[i].s,a[vv[i].f][vv[i].s]);
  cout<<ans<<endl;
}

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

pub fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

pub fn read_n<T: FromStr>(n: usize) -> Vec<T> {
    read_n_logic::<T>(n, vec![])
}

pub fn read_n_logic<T: FromStr>(n: usize, mut a: Vec<T>) -> Vec<T> {
    match n {
        0 => a,
        _ => {
            a.push(read::<T>());
            read_n_logic(n - 1, a)
        }
    }
}
use std::cmp::{max, min};

fn main() {
    let s: String = read();
    if s == "ABC" {
        println!("ARC");
    } else {
        println!("ABC");
    }
}


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

typedef long long LL;

int main()
{
	LL a,b,k;
	cin>>a>>b>>k;
	LL sub=min(a,k);
	a-=sub; k-=sub;
	sub=min(b,k);
	b-=sub; k-=sub;
	cout<<a<<" "<<b<<endl;
	return 0;
}

Measured memory_bytes: 256
n, y = map(int, input().split())
k = y - 1000*n
count = 0
for i in range(0, 2001):
    for j in range(0, 4001):
        if 9000*i + 4000*j == k and n-i-j >= 0:
            a = i
            b = j
            c = n - i - j
            count = 1
            break
        else:
            pass
if count == 1:
    print(a, b, c)
else:
    print("-1 -1 -1")

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

using namespace std;

const int N = 18;
const int MASK = (1 << 16) + 5;

int n; long long a[N][N], cost[MASK], f[MASK];

int main() {
  cin >> n;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) {
      cin >> a[i][j];
    }
  }
  for (int mask = 0; mask < 1 << n; ++mask) {
    for (int i = 0; i < n; ++i) {
      if (mask & 1 << i) {
        for (int j = i + 1; j < n; ++j) {
          if (mask & 1 << j) {
            cost[mask] += a[i][j];
          }
        }
      }
    }
  }
  for (int mask = 1; mask < 1 << n; ++mask) {
    for (int submask = mask; submask > 0; submask = (submask - 1) & mask) {
      f[mask] = max(f[mask], cost[submask] + f[mask ^ submask]);
    }
  }
  cout << f[(1 << n) - 1] << endl;
  return 0;
}



Measured memory_bytes: 1280
#include<iostream>
#include<string>
#include<cstdio>
#include <cstring>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
typedef long double ld;
const ll INF = 1e+14;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
#define int long long

void Yes(){
	cout<<"Yes"<<endl;
	exit(0);
}
 
void No(){
	cout<<"No"<<endl;
	exit(0);
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
    int N, M; cin >> N >> M;
    pair<int, int> p[100100], q[100100];
    rep(i, N) {
        int a, b; cin >> a >> b;
        p[i] = make_pair(a, b);
        q[i] = make_pair(b, M - a);
    }
    sort(q, q + N);
    reverse(q, q + N);
    int ans = 0;
    set<int> s;
    rep(i, M) {
        s.insert((-1) * i);
    } 
    rep(i, N) {
        auto ite = s.lower_bound(q[i].sc * (-1));
        if(ite == s.end()) {
            continue;
        } else {
            s.erase(ite);
            ans += q[i].fr;
        }
    }
    cout << ans << endl;


    
	return 0;
}

Measured memory_bytes: 6528
#define NDEBUG

#include <unordered_map>
#include <functional>
#include <algorithm>
#include <iostream>
#include <cassert>
#include <cstring>
#include <iomanip>
#include <utility>
#include <numeric>
#include <string>
#include <vector>
#include <cmath>
#include <stack>
#include <queue>
#include <tuple>
#include <set>
#include <map>

// [0, max)
#define FOR0(var, max) for (sl (var) = 0; (var) < (max); ++(var))
// [min, max)
#define FORi(var, min, max) for (sl (var) = (min); (var) < (max); ++(var))
// [min, max)
#define FORi_INV(var, min, max) for (sl (var) = (max) - 1; (var) + 1 > (min); --(var))

#define FORITER(var, iter) for (auto (iter) = (var).begin(); (iter) != (var).end(); (iter)++)
#define FORITER_INV(var, iter) for (auto (iter) = (var).rbegin(); (iter) != (var).rend(); (iter)++)

// a < b < c
#define LTLT(a, b, c) (((a) < (b)) && ((b) < (c)))
// a <= b < c
#define LELT(a, b, c) (((a) <= (b)) && ((b) < (c)))
// a < b <= c
#define LTLE(a, b, c) (((a) < (b)) && ((b) <= (c)))
// a <= b <= c
#define LELE(a, b, c) (((a) <= (b)) && ((b) <= (c)))

#ifndef NDEBUG
#  define MASSERT(cond) m_assert(cond, __LINE__, #cond);
#else
#  define MASSERT(...)
#endif

using namespace std;

using uc = unsigned char;
using ui = unsigned int;
using ul = unsigned long long int;

using sc = signed char;
using si = signed int;
using sl = signed long long int;

using ld = long double;

void m_assert(const bool& cond, const sl& line, const char *condstr) {
  if (!cond) {
    cerr << "Assertion Failed: " << condstr << " at line " << line << endl;
    exit(1);
  }
}

template <class T>
T gcd(T a, T b) {
  while (b) {
    T t = a % b;
    a = b;
    b = t;
  }
  return a;
}

static sl A, B;

void solve(void) {
  cout << A * B / gcd(A, B) << endl;
}

int main(void) {
  cin >> A >> B;
  solve();
  return 0;
}

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

int main() {
  string S;
  cin >> S;
  if (S.size()<4) {
    cout << "No" << endl;
  }
  else {
    if (S.at(0)=='Y' && S.at(1)=='A' && S.at(2)=='K' && S.at(3)=='I') {
      cout << "Yes" << endl;
    }
    else {
      cout << "No" << endl;
    }
  }
}


Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) (x).begin(),(x).end()
#define ll long long
int main(){
  ll N,X;
  cin>>N>>X;
  vector<int> A(N);
  rep(i,N) cin>>A[i];
  sort(all(A));
  ll ans=0;
  rep(i,N){
    X-=A[i];
    if(i!=N-1&&X>0||!X) ans++;
    else break;
  }
  cout<<ans<<endl;
  
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <set>

std::set<int> walls[200005];

int main(){
  int H,W,N;
  scanf("%d %d %d",&H,&W,&N);
  for(int i=0;i<N;i++){
    int X,Y;
    scanf("%d %d",&X,&Y);
    walls[X].insert(Y);
  }
  int range=1;
  for(int x=1;x<H;x++){
    if(walls[x+1].size()&&*walls[x+1].begin()<=range){
      printf("%d\n",x);
      return 0;
    }
    if(!walls[x+1].count(range+1)){
      range++;
    }
  }
  printf("%d\n",H);
  return 0;
}


Measured memory_bytes: 18944
#include <iostream>
#include <vector>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
 
using namespace std;
 
class dice{
public:
    int d[6];
    void set(int n, int x){
        d[n] = x;
    }
    int get(int n){
        return d[n];
    }
    void rotate(char c){
        int tmp;
        switch (c){
        case 'W':
            tmp = d[3];
            d[3] = d[0];
            d[0] = d[2];
            d[2] = d[5];
            d[5] = tmp;
            break;
        case 'E':
            tmp = d[5];
            d[5] = d[2];
            d[2] = d[0];
            d[0] = d[3];
            d[3] = tmp;
            break;
        case 'N':
            tmp = d[0];
            d[0] = d[1];
            d[1] = d[5];
            d[5] = d[4];
            d[4] = tmp;
            break;
        case 'S':
            tmp = d[4];
            d[4] = d[5];
            d[5] = d[1];
            d[1] = d[0];
            d[0] = tmp;
            break;
        }
    }
    void espin(){
        rotate('S');
        rotate('E');
        rotate('N');
    }
    bool operator ==(dice e){
        bool flag;
        string s = "SESESE";
        for (int i = 0; i < 6; i++){
            e.rotate(s[i]);
            if (d[0] == e.get(0)){
                for (int j = 0; j < 4; j++){
                    flag = true;
                    for (int k = 1; k < 6; k++){
                        if (d[k] != e.get(k)) flag = false;
                    }
                    if (flag) return true;
                    e.espin();
                }
            }
            if (i == 5) return false;
        }
    }
};
 
int main(){
    int tmp, n;
    bool flag = true;
    cin >> n;
    vector<dice> d(n);
    for (int i = 0; i < n; i++){
        for (int j = 0; j < 6; j++){
            cin >> tmp;
            d[i].set(j, tmp);
        }
    }
    for (int i = 0; i < n; i++){
        for (int j = i + 1; j < n; j++){
            if (d[i] == d[j]){
                cout << "No" << endl;
                flag = false;
                i = j = n;
            }
        }
    }
    if (flag) cout << "Yes" << endl;
}

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

using namespace std;
typedef long long ll;

int main() {
    int n;
    cin >> n;
    ll ret = 0;
    for (int i = 1; i <= n; i++) {
        ll count = n / i;
        ret += count * (count + 1) / 2 * i;
    }
    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 3604
import collections
N = int(input())
A = list(map(int, input().split()))

l = []
r = []
al = []
for i, x in enumerate(A):
  if i % 2 == 0:
    l.append(x)
  else:
    r.append(x)
  al.append(x)

c = collections.Counter(l)
d = collections.Counter(r)
e = collections.Counter(al)

if len(e.keys()) <= 1:
  print(N//2)
  exit()
else:
  mx = -1
  ans = 0
  ck = max(c.items(), key=lambda x:x[1])[0]
  cmx = max(c.items(), key=lambda x:x[1])[1]

  dk = max(d.items(), key=lambda x:x[1])[0]
  dmx = max(d.items(), key=lambda x:x[1])[1]

  if ck == dk:
    if cmx > dmx:
      ans += N//2 - cmx
      print(ans)
      print(c.most_common(2))
      print(d.most_common(2))
      ans += N//2 - (d.most_common(2)[1][1])
    elif cmx < dmx:
      ans += N//2 - dmx
      ans += N//2 - (c.most_common(2)[1][1])
    else:
      if c.most_common(2)[1][1] >= d.most_common(2)[1][1]:
        ans += N//2 - dmx
        ans += N//2 - (c.most_common(2)[1][1])
      else:
        ans += N//2 - cmx
        ans += N//2 - d.most_common(2)[1][1]
  else:
      ans += N//2 - cmx
      ans += N//2 - dmx

print(ans)


Measured memory_bytes: 29784
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.IOException;
import java.io.InputStream;

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

    static class ACoffee {
        PrintWriter out;
        InputReader in;

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            this.out = out;
            this.in = in;
            String st = n();
            if (st.charAt(2) == st.charAt(3) && st.charAt(4) == st.charAt(5))
                pn("Yes");
            else
                pn("No");

        }

        String n() {
            return in.next();
        }

        void pn(String zx) {
            out.println(zx);
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1)
                throw new UnknownError();
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new UnknownError();
                }
                if (numChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        public String next() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            StringBuffer res = new StringBuffer();
            do {
                res.appendCodePoint(c);
                c = read();
            } while (!isSpaceChar(c));

            return res.toString();
        }

        private boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

    }
}



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

string s;
int n;
int dp[18][2];

int solve(int i, int f)
{
    if(i == n) return 0;
    if(dp[i][f] != -1) return dp[i][f];

    int ans = 0;
    for(int d = 0; d <= (f? 9 : (s[i]-'0')); d++)
        ans = max(ans, d + solve(i+1, f? 1 : (d < s[i]-'0')));
    return dp[i][f] = ans;
}

int main() 
{
    ios_base::sync_with_stdio(false); cin.tie(0);
    while(cin >> s)
    {
        n = s.size();
        memset(dp, -1, sizeof dp);
        cout << solve(0,0) << '\n';
    }
    return 0;
}

Measured memory_bytes: 256
/**
 * The man who codes no bugs
 * McCheng is the man studying Maths in CUHK with IQ200
 * @author McCheng
 */

#include <bits/stdc++.h>
using namespace std;

class ELogs {
public:
    static constexpr int kStressCount = 0;
    static void generateTest(ostream& test) {}
	void solve(istream& cin, ostream& cout) {
int n;
cin>>n;
int k;cin>>k;
vector<long long> a(n);
        for (int i = 0; i < n; i++) {
            cin>>a[i];
        }
        long long l=1,r=1000000000;
        while (l<r){
            long long mid=(l+r)/2;
            long long cnt=0;
            for (auto i : a) {
                cnt+=i/mid-1;
                if (i%mid!=0) cnt++;
            }
            if (cnt<=k){
                r=mid;
            }else l=mid+1;
//            cout<<l<<" "<<r<<"\n";
        }
        cout<<r;
	}
};

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    istream &in(cin);
    ostream &out(cout);
    out << fixed;
    out.precision(20);
    ELogs solver;
    solver.solve(in, out);
}


Measured memory_bytes: 4752
#include <iostream>
#include<vector>

using namespace std;

int main() {
	
	int h, n;
	cin >> h >> n;

	vector<int> a(n);
	for (int &x : a) cin >> x;

	for (int x : a) {
		h -= x;
	}
	if (h <= 0) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	
	return 0;
}

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

int main(){
    int n; //宝石の個数
    cin >> n;

    vector<int> val(n); //宝石の価値
    vector<int> cos(n); //宝石のコスト
    for(int i=0; i<n; i++) cin >> val[i];
    for(int i=0; i<n; i++) cin >> cos[i];

    vector<int> benefits(n); //宝石の価値　宝石のコスト
    for(int i=0; i<n; i++){
        benefits[i] = val[i] - cos[i];
    }

    sort(benefits.begin(),benefits.end());
    int ans = 0;
    for(int i=n-1; i>=0; i--){
        if(benefits[i] < 0) break;
        else ans += benefits[i];
    }

    cout << ans << endl;

}

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

int main() {
  string S1, S2;
  cin >> S1 >> S2;
  if (S1.at(0) == S2.at(2) && S1.at(1) == S2.at(1) && S1.at(2) == S2.at(0))
    printf("YES");
  else
    printf("NO");
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fo(i, x, y) for(int i = x, B = y; i <= B; i ++)
#define ff(i, x, y) for(int i = x, B = y; i <  B; i ++)
#define fd(i, x, y) for(int i = x, B = y; i >= B; i --)
#define ll long long
#define pp printf
using namespace std;

const int M = 1e6 + 5;
int fi[M], nt[M], to[M], r[M], tot = 1;
int S, T, co[M], d[M], cur[M];
void link(int x, int y, int z) {
	nt[++ tot] = fi[x], to[tot] = y, r[tot] = z, fi[x] = tot;
	nt[++ tot] = fi[y], to[tot] = x, r[tot] = 0, fi[y] = tot;
}
int w[M], w0;
int bfs() {
	fo(i, 1, T) d[i] = 0, cur[i] = fi[i];
	w[w0 = 1] = S; d[S] = 1;
	for(int i = 1; i <= w0; i ++) {
		int x = w[i];
		for(int j = fi[x]; j; j = nt[j]) if(r[j])
			if(!d[to[j]]) d[to[j]] = d[x] + 1, w[++ w0] = to[j];
	} 
	return d[T] > 0;
}
int dg(int x, int flow) {
	if(x == T) return flow;
	int use = 0;
	for(int i = cur[x]; i; i = nt[i], cur[x] = i)
		if(d[x] + 1 == d[to[i]] && r[i]) {
			int t = dg(to[i], min(flow - use, r[i]));
			r[i] -= t, r[i ^ 1] += t, use += t;
			if(use == flow) return use;
		}
	return use;
}
const int N = 1e5 + 5;

int n, p[N], q[N], bp[N], bq[N];
int ans;

int main() {
	scanf("%d", &n);
	fo(i, 1, n) scanf("%d", &p[i]), p[i] ++;
	fo(i, 1, n) scanf("%d", &q[i]), q[i] ++;
	fo(i, 1, n) if(!bp[i]) {
		int x = i;
		do
			bp[x] = i, x = p[x];
		while(x != i);
	}
	fo(i, 1, n) if(!bq[i]) {
		int x = i;
		do
			bq[x] = i, x = q[x];
		while(x != i);
	}
	fo(i, 1, n) bq[i] += n;
	S = 2 * n + 1, T = S + 1;
	ans = n;
	fo(i, 1, n) {
		if(p[i] == i && q[i] == i) ans --; else
		if(p[i] == i) link(S, bq[i], 1); else
		if(q[i] == i) link(bp[i], T, 1); else {
			link(bp[i], bq[i], 1);
			if(p[i] == q[i]) link(bq[i], bp[i], 1);
		}
	}
	while(bfs()) ans -= dg(S, 1 << 30);
	pp("%d\n", ans);
}


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

char S[10][10];

int main()
{
    int H, W;
    cin >> H >> W;

    int countx = 0;

    for(int i=1; i<=H; i++)
        for(int j=1; j<=W; j++)
        {
            cin >> S[i][j];
            countx+= (S[i][j]=='#');
        }

    int x = 1, y = 1, flag = 0;

    while(!(x==H && y==W))
    {
        if(S[x+1][y]=='#')
            x++;
        else if(S[x][y+1]=='#')
            y++;
        else
        {
            flag = 1;
            break;
        }
    }

    if(!flag && countx==H+W-1)
        printf("Possible\n");
    else
        printf("Impossible\n");

    return 0;
}


Measured memory_bytes: 764
//B058.cpp (B)
#include <iostream>
#include <string>
using namespace std;

int main(){
  string O,E;
  cin >> O >> E;
  for(int i = 0; i < E.size(); i++){
    cout << O[i] << E[i];
  }
  if(O.size() > E.size()) cout << O[O.size()-1] << endl;
  else cout << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
   long long a, b, c, k, ans;
   cin >> a >> b >> c >> k;
   ans=min(k, a);
   k-=a;
   if(k>0){
      k-=b;
   }
   if(k>0){
      ans-=min(k, c);
   }
   cout << ans <<endl;
   
   return 0;
}



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

pair<int, int> f(int x) {
    int a,b;
    a = x%10;
    while(x>=10) x/=10;
    b = x;
    return make_pair(a, b);    
}

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

    map<pair<int,int>,int> mp;
    for (int i=1; i<=n; i++) {
        mp[f(i)]++;
    }

    ll ans = 0;
    for (auto v : mp) {
        pair<int, int> p = v.first;
        ll c = v.second;
        ll d = mp[make_pair(p.second, p.first)];

        ans += c*d;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=205,INF=1<<30;
int dp[2*MAX][MAX][MAX];

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int H,W;cin>>H>>W;
    vector<vector<int>> S(H,vector<int>(W));
    
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            cin>>S[i][j];
        }
    }
    
    for(int s=2;s<=H+W;s++){
        for(int a=1;a<=H;a++){
            if(1<=s-a&&s-a<=W){
                for(int b=1;b<=H;b++){
                    if(1<=s-b&&s-b<=W){
                        if(a==b){
                            for(int bit=0;bit<4;bit++){
                                dp[s][a][b]=max(dp[s][a][b],dp[s-1][a-bit/2][b-bit%2]+S[a-1][s-a-1]);
                            }
                        }else{
                            for(int bit=0;bit<4;bit++){
                                dp[s][a][b]=max(dp[s][a][b],dp[s-1][a-bit/2][b-bit%2]+S[a-1][s-a-1]+S[b-1][s-b-1]);
                            }
                        }
                    }
                }
            }
        }
    }
    
    cout<<dp[H+W][H][H]<<endl;
}






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

ll f(ll x) {
  ll t=0;
  if(x%2!=0)
    t=0;
  else
    t=x;
  if((x+1)/2%2!=0)
    return 1^t;
  else
    return t;
}

int main() {
  ll A,B;
  cin >> A >> B;
  cout << (f(A-1)^f(B)) << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <unordered_map>
#include <utility>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <cstdio>

using namespace std;

#define REP(i,n,m) for( long long int i = (n); i < (m); i++ )
#define ll long long
#define ALL(a) (a).begin(), (a).end()
#define SORT(v) sort( ALL(v) );
#define LAST(v) v[v.size()-1]
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,-1,sizeof(a))
#define pi pair<int, int>
#define MP make_pair
#define PB push_back
#define IIN(a) int a; cin >> a;
#define LIN(a) ll a; cin >> a;
#define SIN(a) string a; cin >> a;
#define EPS (1e-10)
#define INF 1000000000000LL

int MOD=1000000007;
int dx[4] = {0, 0, -1, 1};
int dy[4] = {1, -1, 0, 0};
//In ASCII code: '0' = 48; 'A' = 65; 'a' = 97



signed main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
      LIN( n )
  SIN( s )
  SIN( t )
for (int i = n; i >= 1; i--) {
loop:
		for (int j = 0; j < i; j++) {
			if (s[n-i+j] != t[j]) {
				i--;
				goto loop;
			}
		}
		cout << 2*n - i << endl;
		return 0;
	}
	cout << 2*n << endl;
	return 0;
    return 0;
}


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

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

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

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

ll modpow(ll a, ll n, ll m)
{
    if(n == 0) return 1;
    ll t = modpow(a, n >> 1, m);
    t = t * t % m;
    if(n & 1) t = t * a % m;
    return t; 
}

int main()
{
    ll N;
    cin >> N;
    vec C(N);
    REP(i,0,N) cin >> C[i];

    ASC(C);
    ll ans = 0;
    REP(i,0,N) ans = (ans + (N - i + 1) * C[i]) % MOD;
    ans = (ans * modpow(4, N-1, MOD)) % MOD;
    PR(ans);

    return 0;
}

/*



*/

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

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

int main() {
  int n;
  cin >> n;
  int go[10][10] = {};
  int ans = 0;
  for (int i = 1; i <= n; ++i) {
    string s = to_string(i);
    go[s[0] - '0'][s.back() - '0']++;
  }
  
  for (int i = 1; i <= n; ++i) {
    string s = to_string(i);
    ans += go[s.back() - '0'][s[0] - '0'];
  }
  cout << ans << endl;
  return 0;
}


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

using namespace std;
long long int LCM(long long int a,long long int b);
int main(){
    long long int N,M;
    long long int ans,memo;
    string S,T;
    cin >> N >> M;
    cin >> S;
    cin >> T;

    ans=LCM(N,M);
    memo=LCM(ans/N,ans/M);
    for(long long int i=0;i<ans;i+=memo){
        if(S[i*N/ans]!=T[i*M/ans]){
            cout << "-1";
            return 0;
        }
    }
    cout << ans;
    return 0;
}
long long int LCM(long long int a,long long int b){
    int n=a,m=b;
    while(1){
        if(n>m){
            n=n%m;
            if(n==0) {
                return a*b/m;
            }
        } else {
            m=m%n;
            if(m==0) {
                return a*b/n;
            }
        }
    
    }
    return -1;
}


Measured memory_bytes: 512
#include <iostream>
using namespace std;
#include <string>
 
int main() {
  int K, X;
  cin >> K >> X;
  int sum = 500 * K;
  string ans;
  if (sum >= X) {
    ans = "Yes";
  } else {
    ans = "No";
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h> 
using namespace std; 
int gi() { 
	int res = 0, w = 1; 
	char ch = getchar(); 
	while (ch != '-' && !isdigit(ch)) ch = getchar(); 
	if (ch == '-') w = -1, ch = getchar(); 
	while (isdigit(ch)) res = res * 10 + ch - '0', ch = getchar(); 
	return res * w; 
}
typedef long long LL; 
const int MAX_N = 1e5 + 5; 
int N, a[MAX_N]; 
LL s[MAX_N]; 
bool check(int mid) { 
	LL now = s[mid]; 
	for (int i = mid + 1; i <= N; i++) 
		if (1ll * a[i] <= now * 2) now += a[i]; 
		else return 0;
	return 1; 
} 
int main () { 
#ifndef ONLINE_JUDGE 
    freopen("cpp.in", "r", stdin); 
#endif 
	N = gi(); 
	for (int i = 1; i <= N; i++) a[i] = gi(); 
	sort(&a[1], &a[N + 1]); 
	for (int i = 1; i <= N; i++) s[i] = s[i - 1] + a[i]; 
	int l = 1, r = N, ans = N; 
	while (l <= r) { 
		int mid = (l + r) >> 1; 
		if (check(mid)) ans = mid, r = mid - 1;
		else l = mid + 1; 
	} 
	printf("%d\n", N - ans + 1); 
    return 0; 
} 

Measured memory_bytes: 4960
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define x first
#define y second

using namespace std;

typedef long long ll;

int main()
{
 	//freopen("input.txt", "r", stdin);
 	//freopen("output.txt", "w", stdout);
 	ios_base::sync_with_stdio(0); cin.tie(0);
 	int h1, m1, h2, m2, k;
 	cin >> h1 >> m1 >> h2 >> m2 >> k;
 	int len = (h2 * 60 + m2 - h1 * 60 - m1);
 	cout << len - k << '\n';
 	return 0;
}

Measured memory_bytes: 3640
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(void){
   int k,i,countwin;
   char str[100],s[100],*p;

   fgets(str,sizeof(str),stdin);

   p=strtok(str," \n");
   strcpy(s,p);
   k=strlen(s);

   for(i=0,countwin=0;i<k;i++){
     if(s[i]=='o'){
         countwin++;
      }
   }
    if((15-k)+countwin>=8){
        printf("YES");
     }else{
         printf("NO");
      }

  return 0;
}

Measured memory_bytes: 128
;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
;文字列 -> 整数
(defn Int [s] (Integer/parseInt s))
;文字列 -> 文字列
(defn Str [s] s)

;scanf的なノリで1行をいい感じに読み取る
;定数が重いので注意
(defn input [varTypes]
    (mapv 
        (fn [f s] (f s)) ;文字列sに関数fを適用する
        varTypes         ;適用する関数
        (clojure.string/split 
            (read-line)  ;1行を読み込み
            #" "         ;区切り文字
        )
    )
)

;スペース区切りの整数を受け取る
;速い
(defn inputFast [varType]
    (map
        varType
        (clojure.string/split 
            (read-line)  ;1行を読み込み
            #" "         ;区切り文字
        )
    )
)

(defn floor [a b] (quot a b))
(defn ceil [a b] (floor (- (+ a b) 1) b))
(defn abs [a] (if (> 0 a) (- 0 a) a))


;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


;---main---
(dosync
    (def l1 (inputFast Str))
    (def l2 (inputFast Int))
    (let [[A] l1] (let [[K] l2]
        (def B (ref (list)))
        (def len (count A))
        (doseq [i (range 0 len)]
            (doseq [j (range 1 6)]
                (if (<= (+ i j) len)
                    (alter B conj (subs A i (+ i j)))
                )
            )
        )
        (alter B distinct)
        (alter B sort)
        (println (nth (deref B) (- K 1)))
    ))
)





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

#define REP(i,n) for(long long i=0;i<n;++i)
#define REPR(i,n) for(long long i=n;i>=0;--i)
#define REPI(itr,v) for(auto itr=v.begin();itr!=v.end();++itr)
#define REPIR(itr,v) for(auto itr=v.rbegin();itr!=v.rend();++itr)
#define FOR(i,a,b) for(long long i=a;i<b;++i)
#define SORT(v,n) sort(v, v+n)
#define SORTV(v) sort(v.begin(), v.end())
#define ALL(v) v.begin(),v.end()
#define llong long long
#define INF 999999999
#define MOD 1000000007
#define pb push_back
#define pf push_front
#define MP make_pair
#define SV(v) {for(long long sitr=0;sitr<v.size();++sitr){cin>>v[sitr];}}

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

using namespace std;

typedef pair<int,int> pii;

int main(){

  int n, m;
  cin >> n >> m;

  vector<string> word(n), word_rev(n), slate(m);
  REP(i,n){
    cin >> word[i];
    word_rev[i] = word[i];
    reverse(ALL(word_rev[i]));
  }
  REP(i,m){
    cin >> slate[i];
  }

  sort(ALL(word));
  sort(ALL(word_rev));

  REP(i,m){
    int idx = slate[i].find("?");

    //ない時
    if(idx == -1){
      if(slate[i][0] == '*'){
        string tmp = slate[i].substr(1, slate[i].length()-1);
        reverse(ALL(tmp));
        cout << distance(lower_bound(ALL(word_rev), tmp), lower_bound(ALL(word_rev), tmp+"~")) << endl;
      }else if(slate[i].back() == '*'){
        string tmp = slate[i].substr(0, slate[i].length()-1);
        //cerr << tmp << endl;
        cout << distance(lower_bound(ALL(word), tmp), lower_bound(ALL(word), tmp+"~")) << endl;
      }else{
        cout << distance(lower_bound(ALL(word), slate[i]), upper_bound(ALL(word), slate[i])) << endl;
      }
    }else{
      //ある時
      int ans = 0;
      REP(j,26){
        
        slate[i][idx] = 'a' + j;
        if(slate[i][0] == '*'){
          string tmp = slate[i].substr(1, slate[i].length()-1);
          reverse(ALL(tmp));
          ans += distance(lower_bound(ALL(word_rev), tmp), lower_bound(ALL(word_rev), tmp+"~"));
        }else if(slate[i].back() == '*'){
          string tmp = slate[i].substr(0, slate[i].length()-1);
          //cerr << tmp << endl;
          ans += distance(lower_bound(ALL(word), tmp), lower_bound(ALL(word), tmp+"~"));
        }else{
          ans += distance(lower_bound(ALL(word), slate[i]), upper_bound(ALL(word), slate[i]));
        }
      }
      cout << ans << endl;
    }
  }

  return 0;
}




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

#define INF INT_MAX
#define UINF UINT_MAX
#define MOD 1000000007
#define REP(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()

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

using namespace std;

int main() {
    ll a,b,k;
    cin >> a >> b >> k;

    ll aa = a,bb = b;
    aa = a - k;
    aa = aa < 0 ? 0 : aa;

    if(k - a > 0){
        bb = b - (k - a);
        bb = bb < 0 ? 0 : bb;
    }

    cout << aa << " " << bb << endl;
    return 0;
}

Measured memory_bytes: 256
l,r = map(int,input().split())
a = l%2019
b = r%2019
if r - l >= 2019:
  print("0")
if r - l < 2019:
  if a < b:
    li = []
    for i in range(a,b):
      for j in range(i+1,b+1):
        li.append((i*j)%2019)
    print(min(li))  
  else:
    print("0")

Measured memory_bytes: 75416
import math
from itertools import accumulate

def eratosthenes(n):
    prime_list = []
    num_list=[i for i in range(2, n+1)]
    limit = math.sqrt(n)
    while True:
        if limit <= num_list[0]:
            return prime_list + num_list
        prime_list.append(num_list[0])
        num_list = [e for e in num_list if e % num_list[0] != 0]

max_lr = 100000
er_list = eratosthenes(max_lr)
count = [0] * max_lr


for i in range(len(er_list)):
    if (er_list[i]+1)//2 in er_list:
        count[er_list[i]] = 1
            
count = list(accumulate(count))
            
Q = int(input())
for i in range(Q):
    l, r = map(int, input().split())
    print(count[r]-count[l-1])

Measured memory_bytes: 14424
#include <iostream>
#include <cstring>

using namespace std;

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

int main() {
	char str[1001];
	cin >> str;

	REP(i,strlen(str)) {
		str[i] = (str[i]>='A'+3) ? ((str[i] - 'A' - 3) % 26 + 'A')
			: ( (str[i] - 'A' + 26 - 3) % 26 + 'A');
	}
	cout << str << endl;

}

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

int main() {
  int a;
  cin>>a;
  int b,c,d,e;
  b = a/1000;
  c = (a - 1000*b)/100;
  d = (a - 1000*b - 100*c)/10;
  e = a - 1000*b - 100*c - 10*d;
  if((b==c&&b==d)||(c==d&&c==e)){
    cout<<"Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
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; }
typedef long long ll;
const long long INF = 1LL << 60;
typedef pair<int, int> P;
vector<ll> res;
const long long MAX_V = 3234566667;

void dfs(ll num) {
    if (num > MAX_V) return ;
    res.push_back(num);
    int be = num % 10;
    int a1 = be - 1, a2 = be + 1;
    if (a1 >= 0) dfs(num * 10 + a1);
    if (a2 <= 9) dfs(num * 10 + a2);
    dfs(num * 10 + be);
    return ;
}

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

    repd(i, 1, 10) {
        dfs(i);
    }

    sort(all(res));

    cout << res[K - 1] << endl;
    return 0;
}

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

int main() {
  long long n, m;
  cin >> n >> m;
  if (n == 1 && m == 1) {
    cout << 1 << endl;
  } else if (n == 1) {
    cout << m - 2 << endl;
  } else if (m == 1) {
    cout << n - 2 << endl;
  } else {
    cout << (n * m - n * 2 - m * 2 + 4) << 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 rep1(i, n) for (int i = 1; i <= (int)(n); i++)
typedef int64_t Int;

int main(){
   Int N, Z, W; cin >> N >> Z >> W;
   vector<Int> A(N);
   rep(i,N) cin >> A[i];

   if(N == 1){
       cout << abs(A[0] - W) << endl;
   } else {
       cout << max(abs(A[N-1]-A[N-2]), abs(A[N-1]-W)) << endl;
   }
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#pragma GCC target("avx2")
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/rope>

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;
//change null_type here for map/set
typedef tree<int,null_type,less<int>,rb_tree_tag,
            tree_order_statistics_node_update> indexed_set;
typedef long long int  ll;
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define mem(a,b) memset(a,b,sizeof(a))
#define pii pair<int,int>
#define F first
#define S second

template<class T>inline bool read(T &x){
    int c=getchar();int sgn=1;
    while(~c&&c<'0'||c>'9'){if(c=='-')sgn=-1;c=getchar();}
    for(x=0;~c&&'0'<=c&&c<='9';c=getchar())x=x*10+c-'0';
    x*=sgn; return ~c;
}
///START HERE
///indexed_set pbd;
//pbd.insert()
//auto x = pbd.find_by_order(2);
//int od=pbd.order_of_key(7)
///rope<int> rp;
//rp.push_back()
//RandomAccess like vector
//mutable_begin, mutable_end()

int main(){
    ///read()+printf
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    //fast;
    int n;
    cin>>n;
    map<string,int> mp;
    for(int i=0;i<n;i++){
        string st;
        cin>>st;
        mp[st]++;
    }
    cout<<"AC"<<" x "<<mp["AC"]<<endl;
    cout<<"WA"<<" x "<<mp["WA"]<<endl;
    cout<<"TLE"<<" x "<<mp["TLE"]<<endl;
    cout<<"RE"<<" x "<<mp["RE"]<<endl;



    return 0;
}


Measured memory_bytes: 3632
import java.util.*;
import static java.lang.Integer.*;
import static java.lang.Long.*;
import static java.lang.Math.*;
import static java.lang.System.*;

public class Main {
	public static void main(String[] args) {
		int i=0;
		int j=0;
		int k=0;
		Scanner sc = new Scanner(in);
		char[] c = sc.next().toCharArray();
		sc.close();
		int[] n = new int[4];
		for (i = 0; i < 4; i++) {
			n[i] = c[i] - '0';
		}
		int[] op = {+1, -1};
LABEL:	for (i = 0; i < 2; i++) {
			for (j = 0; j < 2; j++) {
				for (k = 0; k < 2; k++) {
					if(n[0]+op[i]*n[1]+op[j]*n[2]+op[k]*n[3]==7) {
						break LABEL;
					}
				}
			}
		}
		out.print(n[0]);
		out.print(i==0?"+":"-");
		out.print(n[1]);
		out.print(j==0?"+":"-");
		out.print(n[2]);
		out.print(k==0?"+":"-");
		out.print(n[3]);
		out.println("=7");
	}
}


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

int main(){
    int s,w;
    cin >> s >> w;
    string ans = "safe";
    if(s <= w) ans = "unsafe";
    cout << ans << endl;
}

Measured memory_bytes: 3596
H,W = map(int,(input().split()))
N = int(input())
a = list(map(int,(input().split())))
b = [[0]*W for _ in range(H)]
nowx,nowy = 0,0
nowc = 0
for i in range(H*W):
    b[nowx][nowy] = nowc +1
    a[nowc] -= 1
    if a[nowc] == 0:
        nowc += 1
    if nowy %2 == 0:
        if nowx + 1 >= H:
            nowy += 1
        else:
            nowx += 1
    else:
        if nowx - 1 < 0:
            nowy += 1
        else:
            nowx -= 1

for i in range(H):
    print(*b[i])

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

#define ll long long int

using namespace std;

vector<ll> calc_divisor(ll n) {
  vector<ll> res;
  for (ll i = 1LL; i*i <= n; ++i) {
    if (n % i == 0) {
      res.push_back(i);
      ll j = n / i;
      if (j != i) res.push_back(j);
    }
  }
  sort(res.begin(), res.end());
  return res;
}


int main() {
  ll n;
  cin >> n;
  const auto & div1 = calc_divisor(n-1);
  const auto & div2 = calc_divisor(n);
  ll res = div1.size() - 1;
  for (auto d : div2) {
    if (d == 1) continue;
    ll nn = n;
    while (nn % d == 0) nn /= d;
    if ((nn-1)%d == 0) ++res;
  }
  cout << res << endl;
}


Measured memory_bytes: 3604
package main

import (
	"fmt"
	"strings"
)

type point struct {
	x, y   int
	road   bool
	marked bool
}

func newPoint(x, y int, road bool) *point {
	return &point{
		x:    x,
		y:    y,
		road: road,
	}
}

type queue struct {
	arr []*point
}

func newQueue() *queue {
	return &queue{
		arr: make([]*point, 0),
	}
}

func (q *queue) enqueue(point *point) {
	q.arr = append(q.arr, point)
}

func (q *queue) dequeue() *point {
	p := q.arr[0]
	q.arr = q.arr[1:]
	return p
}

func (q *queue) empty() bool {
	return len(q.arr) == 0
}

func main() {
	var h, w int
	fmt.Scanf("%d %d", &h, &w)
	var ch, cw int
	fmt.Scanf("%d %d", &ch, &cw)
	var dh, dw int
	fmt.Scanf("%d %d", &dh, &dw)

	table := make([][]*point, 0, h)
	for i := 0; i < h; i++ {
		var row string
		fmt.Scanf("%s", &row)
		rows := make([]*point, 0, w)
		for j, v := range strings.Split(row, "") {
			rows = append(rows, newPoint(i, j, v == "."))
		}
		table = append(table, rows)
	}

	q := newQueue()
	warr := make([]*point, 0)
	start := table[ch-1][cw-1]
	start.marked = true
	q.enqueue(start)
	warr = append(warr, start)
	var count int
	for !q.empty() {
		p := q.dequeue()
		if p.x == dh-1 && p.y == dw-1 {
			fmt.Println(count)
			return
		}

		if within(p.x-1, p.y, h, w) {
			next := table[p.x-1][p.y]
			if next.road && !next.marked {
				next.marked = true
				q.enqueue(next)
				warr = append(warr, next)
			}
		}
		if within(p.x+1, p.y, h, w) {
			next := table[p.x+1][p.y]
			if next.road && !next.marked {
				next.marked = true
				q.enqueue(next)
				warr = append(warr, next)
			}
		}
		if within(p.x, p.y-1, h, w) {
			next := table[p.x][p.y-1]
			if next.road && !next.marked {
				next.marked = true
				q.enqueue(next)
				warr = append(warr, next)
			}
		}
		if within(p.x, p.y+1, h, w) {
			next := table[p.x][p.y+1]
			if next.road && !next.marked {
				next.marked = true
				q.enqueue(next)
				warr = append(warr, next)
			}
		}

		if !q.empty() {
			continue
		}
		count++

		c := make([]*point, len(warr))
		copy(c, warr)
		warr = make([]*point, 0)
		for _, p := range c {
			for x := p.x - 2; x <= p.x+2; x++ {
				for y := p.y - 2; y <= p.y+2; y++ {
					if within(x, y, h, w) {
						next := table[x][y]
						if next.road && !next.marked {
							next.marked = true
							q.enqueue(next)
							warr = append(warr, next)
						}
					}
				}
			}
		}
	}

	fmt.Println(-1)
}

func within(x, y, h, w int) bool {
	return x >= 0 && x < h && y >= 0 && y < w

}


Measured memory_bytes: 68704
package main

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

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

// min, max, asub, absなど基本関数
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func asub(a, b int) int {
	if a > b {
		return a - b
	}
	return b - a
}

func abs(a int) int {
	if a >= 0 {
		return a
	}
	return -a
}

func lowerBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] >= x
	})
	return idx
}

func upperBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] > x
	})
	return idx
}

type shop struct {
	a, b int
}

// Datas :
type Datas []shop

func (p Datas) Len() int {
	return len(p)
}

func (p Datas) Swap(i, j int) {
	p[i], p[j] = p[j], p[i]
}

func (p Datas) Less(i, j int) bool {
	return p[i].a < p[j].a
}

func main() {
	sc.Split(bufio.ScanWords)

	N, M := getInt(), getInt()
	s := make(Datas, N)
	for i := 0; i < N; i++ {
		a, b := getInt(), getInt()
		s[i] = shop{a, b}
	}
	sort.Sort(s)

	total := 0
	for _, e := range s {
		n := min(e.b, M)
		total += n * e.a
		M -= n
		if M == 0 {
			break
		}
	}
	out(total)
}


Measured memory_bytes: 3840
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ for(auto it : P) { s << "<" << it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ for(auto it : P) { s << "<" << it.first << "->" << it.second << "> "; } return s << endl; }



int N, M, Q;
vector<long long> a, b, c, d;

long long score(const vector<int> &A) {
    long long res = 0;
    for (int i = 0; i < Q; ++i) if (A[b[i]] - A[a[i]] == c[i]) res += d[i];
    return res;
}

long long dfs(vector<int> &A) {
    if (A.size() == N) {
		return score(A);
	}
	long long res = 0;
    int prev_last = (A.empty() ? 0 : A.back());
    for (int add = prev_last; add < M; ++add) {
        A.push_back(add);
        res = max(res, dfs(A));
        A.pop_back();
    }
	return res;
}

int main() {
    cin >> N >> M >> Q;
    a.resize(Q); b.resize(Q); c.resize(Q); d.resize(Q);
    for (int q = 0; q < Q; ++q) {
        cin >> a[q] >> b[q] >> c[q] >> d[q];
        --a[q], --b[q];
    }
    vector<int> A;
	cout << dfs(A) << endl;
}


Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
typedef long long int LL;
typedef long double LD;
typedef pair<int, int> P;

const int MOD = 1e9 + 7;
const int INF = 1 << 30;

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

  LL N, M, res;
  cin >> N >> M;
  if (N * 2 > M) {
    res = M / 2;
  } else {
    res = N;
    M -= N * 2;
    res += M / 4;
  }
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 764
#include <stdio.h>
#include <math.h>
int main(void){
    double a,b,c,S,L,h,rad;
    scanf("%lf %lf %lf",&a,&b,&c);
    rad = (c/180)*M_PI;
    S = (a*b*sin(rad))/2;
    L = a+b+sqrt(a*a+b*b-2*a*b*cos(rad));
    h = b*sin(rad);
        printf("%f %f %f",S,L,h);
    return 0;
}

Measured memory_bytes: 648
/*
Anki:未済
作成日:①2020/03/14
*/

#include <stdio.h>
#define K 32

int main()
{
    int k, n[K] = { 1, 1, 1, 2, 1, 2, 1, 5, 
                  2, 2, 1, 5, 1, 2, 1, 14, 
                  1, 5, 1, 5, 2, 2, 1, 15, 
                  2, 2, 5, 4, 1, 4, 1, 51 };

    scanf( "%d", &k );
    printf( "%d\n", n[k-1] );

    return 0;
}

Measured memory_bytes: 128
N, D = map(int, input().split())
X = []
Y = []
for i in range(N):
  x, y = map(int, input().split())
  X.append(x)
  Y.append(y)
ans = 0
for i in range(N):
  if D >= (X[i] ** 2 + Y[i] ** 2) ** (1/2):
    ans += 1
print(ans)


Measured memory_bytes: 24848
//              +-- -- --++-- +-In the name of ALLAH-+ --++-- -- --+              \\

#include <bits/stdc++.h>

#define F first
#define S second
#define _sz(x) (int)x.size()

using namespace std ;
using ll = long long ;
using ld = long double ;
using pii = pair <int , int> ;

int n , k ;
bool bad[30] ;

inline bool ok (int x) {
	while (x) {
		int dig = x % 10 ;
		if (bad[dig]) return 0 ;
		x /= 10 ;
	}
	return 1 ;
}

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

	cin >> n ;

	cin >> k ;
	while (k --) { int x ; cin >> x ; bad[x] = 1 ; }

	for (; ; n ++) if (ok(n)) return cout << n << '\n' , 0 ; 	
}


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

typedef long long ll;

int main() {
    string S;
    cin >> S;
    string t = "keyence";
    int cnt = 0;
    for (int i = 0; i < 7; i++) {
        if (S[i] == t[i]) {
            cnt++;
        }
    }
    if (cnt == 7) {
        cout <<  "YES" << endl;
        return 0;
    }
    cnt = 0;
    for (int i = 0; i < 7; i++) {
        if (S[S.size()-1-i] == t[7-1-i]) {
            cnt++;
        }
    }
    if (cnt == 7) {
        cout << "YES" << endl;
        return 0;
    }
    string t1 = "";
    int i = 0;
    while (true) {
        if (S[i] == t[i]) {
            t1 += S[i];
            i++;
        } else {
            break;
        }
    }
    string t2 = "";
    for (int j = i; j < 7; j++) {
        if (S[S.size()-7+j] == t[j]) {
            t2 += t[j];
        }
    }
    if (t1+t2 == "keyence") {
        cout << "YES" << endl;
        return 0;
    }
    cout << "NO" << endl;
}


Measured memory_bytes: 256