akhauriyash/Code-Regression huggingface dataset:
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <regex>
#define REP(i,n) for(int i = 0; i < n; i++)
#define FOR(i,j,n) for(int i = j; i < n; i++)
#define RFOR(i,j,n) for(int i = j-1; i >= n; i--)
#define PREC(n) fixed << setprecision(n)
#define print_array(v) REP(__k, v.size()) { cout << v[__k]; if(__k != v.size()-1) cout << " "; else cout << endl; } value
#define YesorNo(a) printf(a?"Yes\n":"No\n")
#define _LIBCPP_DEBUG 0
using namespace std;
int64_t MOD = 1000000007;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  int ans;
  if (b <= c) ans = 0; //重ならない a-b/c-d
  else if (d <= a) ans = 0; //重ならない c-d/a-b
  else if (a <= c && d <= b) ans = d - c; //a-bがc-dを覆う
  else if (c <= a && b <= d) ans = b - a; //c-dがa-bを覆う
  else if (a <= c && b <= d) ans = b - c; //a-c-b-dで重なる
  else if (c <= a && d <= b) ans = d - a; //c-a-d-bで重なる
  cout << ans << endl;
  return 0;
}
//templete by private_yusuke

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

using namespace std;
using namespace boost::multiprecision;

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REPI(i,a,b) for(int i=int(a);i<int(b);++i)
#define ALL(x) (x).begin(),(x).end()
inline cpp_int between(cpp_int n, cpp_int x) {
  if(n >= 0)
    return (n/x)+1;
  else
    return 0;
}

int main () {
  int k, n, a;

  cin >> k >> n;
  vector<int> as;

  REP(i, n) {
    cin >> a;
    as.push_back(a);
  }
  int longest = (k - as.back()) + as.front();


  REPI(i, 1, n) {
    longest = max(as[i] - as[i - 1], longest);
  }

  cout << k - longest << endl;
  return 0;
}


Measured memory_bytes: 1400
#include <bits/stdc++.h>
        using namespace std;
        #define rep(i,n) for( int i = 0 ; i < n ; i++ )
        typedef long long ll ;
        int main() {
          ll A , B ;
          cin >> A >> B ;
          ll ans = A * B ;
          if( A == 1 || B == 1 ){
            cout << 1 << endl;
            return 0 ;
          }
          cout << (ll) ( ans + 1 )/ 2<< endl;
        }

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(i=0;i<(n);i++)
#define loop(i,a,n) for(i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;

int main(void) {
    int i,j;
    int n;
    cin>>n;
    vi a(n),b(n);
    rep(i,n){
        cin >> a[i];
        b[i] = a[i];
    }
    sort(all(b));

    int ans = 0;
    rep(i,n){
        int p = lower_bound(all(b),a[i]) - b.begin();
        if(p%2 != i%2)ans++;
    }
    cout << (ans+1)/2 << endl;
}


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

int mod = 1000000007;
int64_t large = 9223372036854775807;
double PI = 3.141592653589793;

int main()
{
    int64_t N, M;
    cin >> N >> M;
    if (M < N * 2)
        cout << M / 2;
    else
        cout << (N * 2 + M) / 4;
}

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

#define FOR(i,a,b) for(int i= (a); i<((int)b); ++i)
#define RFOR(i,a) for(int i=(a); i >= 0; --i)
#define FOE(i,a) for(auto i : a)
#define ALL(c) (c).begin(), (c).end()
#define RALL(c) (c).rbegin(), (c).rend()
#define DUMP(x)  cerr << #x << " = " << (x) << endl;
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v,x) (std::find(v.begin(), v.end(), x) != v.end())
#define BIT(n) (1LL<<(n))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());

typedef long long LL;
template<typename T> using V = std::vector<T>;
template<typename T> using VV = std::vector<std::vector<T>>;
template<typename T> using VVV = std::vector<std::vector<std::vector<T>>>;

template<class T> inline T ceil(T a, T b) { return (a + b - 1) / b; }
template<class T> inline void print(T x) { std::cout << x << std::endl; }
template<class T> inline void print_vec(const std::vector<T> &v) { for (int i = 0; i < v.size(); ++i) {  if (i != 0) {std::cout << " ";} std::cout << v[i];} std::cout << "\n"; }
template<class T> inline bool inside(T y, T x, T H, T W) {return 0 <= y and y < H and 0 <= x and x < W; }
template<class T> inline double euclidean_distance(T y1, T x1, T y2, T x2) { return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)); }
template<class T> inline double manhattan_distance(T y1, T x1, T y2, T x2) { return abs(x1 - x2) + abs(y1 - y2); }

const int INF = 1L << 30;
const double EPS = 1e-9;
const std::string YES = "YES", Yes = "Yes", NO = "NO", No = "No";
const std::vector<int> dy4 = { 0, 1, 0, -1 }, dx4 = { 1, 0, -1, 0 };    // 4近傍（右, 下, 左, 上）
const std::vector<int> dy8 = { 0, -1, 0, 1, 1, -1, -1, 1 }, dx8 = { 1, 0, -1, 0, 1, 1, -1, -1 };

using namespace std;


bool can_delete(int idx, const vector<LL> &A, int K) {
    vector<bool> dp(K + 1, false);
    dp[0] = true;

    FOR(i, 0, A.size()) {
        if (i == idx) {
            continue;
        }

        for (int j = int(dp.size()) - 1; j >= 0; --j) {
            if (dp[j] and j + A[i] < dp.size()) {
                dp[j + A[i]] = true;
            }
        }
    }

    bool ok = true;
    FOR(i, 0, K) {
        if (dp[i] and i + A[idx] >= K) {
            ok = false;
        }
    }
    return ok;
}

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

	int N, K;
	cin >> N >> K;

	vector<LL> A(N);
	FOR(i, 0, N) {
	    cin >> A[i];
	}
	sort(ALL(A));

	int low = -1, high = N;
	while (high - low > 1) {
	    int idx = (low + high) / 2;
	    if (can_delete(idx, A, K)) {
	        low = idx;
	    }
	    else {
	        high = idx;
	    }
	}

	print(low + 1);
	return 0;
}

Measured memory_bytes: 384
/* ＵＴＦ－８ */
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <array>
#include <queue>
#include <stack>
#include <algorithm>
#include <tuple>
#include <numeric>
#include <type_traits>
#include <limits>

#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>

#define USE_COLORED 1

#ifdef USE_COLORED
static const char stdout_pre[]  = "\033[1m"; // bold black
static const char stderr_pre[]  = "\033[31;1m"; // bold red
static const char stdxxx_post[] = "\033[m";

// 当然ながら GCC(g++)/libstdc++ 依存
#include <ext/stdio_filebuf.h>
using stdio_filebuf = __gnu_cxx::stdio_filebuf<char>;
class colored_stdio_filebuf : public stdio_filebuf {
private:
	const char* const pre_;
	const char* const post_;

public:
	colored_stdio_filebuf(FILE* fp, const char* pre, const char* post) : stdio_filebuf(fp, std::ios_base::out), pre_(pre), post_(post)
	{
	}

protected:
	std::streamsize xsputn(const char* s, std::streamsize count) override
	{
		stdio_filebuf::xsputn(pre_, strlen(pre_));
		auto ret = stdio_filebuf::xsputn(s, count);
		stdio_filebuf::xsputn(post_, strlen(post_));
		return ret;
	}
};
#endif

int main()
{
#ifdef USE_COLORED
	if (getenv("DEBUG")) {
		std::cout.rdbuf(new colored_stdio_filebuf(stdout, stdout_pre, stdxxx_post));
		std::cerr.rdbuf(new colored_stdio_filebuf(stderr, stderr_pre, stdxxx_post));
	} else
#endif
	{
		int fd = open("/dev/null", O_WRONLY);
		dup2(fd, 2);
		close(fd);
	}
	
	int A, B, C;
	std::cin >> A >> B >> C;
	if ((A > C && C > B) || (A < C && C < B))
		std::cout << "Yes\n";
	else
		std::cout << "No\n";
}


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

using namespace std;

unsigned long long M = 1000000007;


unsigned long long pow1(unsigned long long a, unsigned long long p) {
	if (p == 0) {
		return 1;
	}
	if (p % 2 == 0) {
		unsigned long long ans = pow1(a, p / 2);
		return (ans * ans) % M;
	}
	return (a * pow1(a, p - 1)) % M;
} 

main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	vector<unsigned long long> f(4000001, 1);
	for (long long l = 2; l < 4000001; l++) {
		f[(int)l] = (f[(int)l - 1] * l) % M;
	}
	long long a, b, x, y;
	cin >> a >> b;
	y = (2 * a - b) / 3;
	x = a - 2 * y;
	if (x < 0 || y < 0 || (2 * a - b) % 3 != 0) {
		cout << 0;
		return 0;
	}
	//cout << f[x + y] << "\n";
	cout << (((unsigned long long)(((unsigned long long)f[(int)x + (int)y] * pow1(f[(int)x], M - 2)) % M) * pow1(f[(int)y], M - 2)) % M);
}

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

struct dice{
  int num[10];
};

dice d, d2, t, z;

dice hoge(dice d){
  int temp = d.num[6];
  d.num[6] = d.num[2];
  d.num[2] = d.num[1];
  d.num[1] = d.num[5];
  d.num[5] = temp;
  return d;
}

dice fuga(dice d){
  int temp = d.num[6];
  d.num[6] = d.num[3];
  d.num[3] = d.num[1];
  d.num[1] = d.num[4];
  d.num[4] = temp;
  return d;
}

dice foo(dice d){
  int temp = d.num[2];
  d.num[2] = d.num[3];
  d.num[3] = d.num[5];
  d.num[5] = d.num[4];
  d.num[4] = temp;
  return d;
}

bool equal(dice a, dice b){
  for(int i = 1; i <= 6; i++){
    if(a.num[i] != b.num[i]) return false;
  }
  return true;
}


bool same(dice a, dice b){
  for(int i = 0; i < 4; i++){
    a = hoge(a);
    for(int j = 0; j < 4; j++){
      a = foo(a);
      if(equal(a,b))return true;
    }
  }
  a = fuga(a);
  for(int j = 0; j < 4; j++){
    a = foo(a);
    if(equal(a,b))return true;
  }
  a = fuga(a);
  a = fuga(a);
  for(int j = 0; j < 4; j++){
    a = foo(a);
    if(equal(a,b))return true;
  }
  
  return false;
}

int main(){
  int n, q, a;

  string s;

  for(int i = 1; i <= 6; i++){
    cin>>d.num[i];
  }
  
 for(int i = 1; i <= 6; i++){
    cin>>d2.num[i];
  }

 cout<<(same(d,d2)?"Yes":"No")<<endl;

  return 0;
}



Measured memory_bytes: 3104
#include <iostream>
#include <vector>
//#include <string>
#include <algorithm>
//#include <math.h>
//#include <queue>
//#include <stack>
//#include <iomanip>

// sometimes used
//#include <set>
//#include <map>
//#include <numeric>
//#include <list>
//#include <deque>
//#include <unordered_map>

typedef long long LL;
//typedef long double LD;
using namespace std;
 
//#define MOD 1000000007
//#define MAX 100100
//#define NIL -1

int main() {
    LL n;
    LL k;
    LL ans=0;
    cin >> n >> k;
    vector<LL> p(n);
    for(LL i=0; i<n; i++){
        cin >> p[i];
    }

    sort(p.begin(), p.end());
    for(LL i=0; i<k; i++){
        ans+=p[i];
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i,n) for(ll i=0; i<(n); i++)
#define REP2(i,x,n) for(ll i=x; i<(n); i++)
const long long INF = numeric_limits<long long>::max();
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;
}
int main()
{
    ll H, W;
    cin >> H >> W;
    vector<string> maps(H);
    
    vector<bool> ws(W, false);
    vector<bool> hs(H, false);

    for ( ll i = 0; i < H; ++ i ){
        cin >> maps[i];
        
        if ( maps[i].find('#') != string::npos ){
            hs[i] = true;
        }
        for ( ll j = 0; j < maps[i].size(); ++ j ){
            ws[j] = ws[j] | (maps[i][j] == '#');
        }
    }

    for ( ll i = 0; i < H; ++ i ){
        if ( !hs[i] )   continue;
        for ( ll j = 0; j < W; ++ j ){
            if ( !ws[j] )   continue;
            cout << maps[i][j];
        }
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 3616
program main
  implicit none
  character(100) :: n2, n, n3
  character(1) :: c
  integer :: k, l, i1, i2, i3, j1, j2, j3, j4, res
  read *, n2
  n3 = "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
  n = n3
  l = len(trim(n2))
  n(100-l+1:100) = trim(n2)
  read *, k
  res = 0
  if (k == 1) then
    do i1 = 1, 100
      do j1 = 1, 9
        n2 = n3
        write (c, "(i0)") j1
        n2(i1:i1) = c(1:1)
        if (n2 <= n) res = res + 1
      end do
    end do
  else if (k == 2) then
    do i1 = 1, 100
      do i2 = i1 + 1, 100
        do j1 = 1, 9
          do j2 = 1, 9
            n2 = n3
            write (c, "(i0)") j1
            n2(i1:i1) = c(1:1)
            write (c, "(i0)") j2
            n2(i2:i2) = c(1:1)
            if (n2 <= n) res = res + 1
          end do
        end do
      end do
    end do
  else
    do i1 = 1, 100
      do i2 = i1 + 1, 100
        do i3 = i2 + 1, 100
          do j1 = 1, 9
            c = n(i1:i1)
            read (c, *) j4
            if (i1 == 100 - l + 1 .and. j1 == j4) then
              do j2 = 1, 9
                do j3 = 1, 9
                  n2 = n3
                  write (c, "(i0)") j1
                  n2(i1:i1) = c(1:1)
                  write (c, "(i0)") j2
                  n2(i2:i2) = c(1:1)
                  write (c, "(i0)") j3
                  n2(i3:i3) = c(1:1)
                  if (n2 <= n) res = res + 1
                end do
              end do
            else if (i1 == 100 - l + 1 .and. j1 < j4) then
              res = res + 9 * 9
            else if (i1 > 100 - l + 1) then
              res = res + 9 * 9
            end if
          end do
        end do
      end do
    end do
  end if
  print "(i0)", res
end program main


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
n,m=map(int,input().split())
A=[]
for i in range(n):
  x,y,z=map(int,input().split())
  A.append([x,y,z])
ans=-float("inf")
for i in range(8):
  key=str(bin(i))[2:].zfill(3)
  B=[]
  for a in A:
    b=0
    for k in range(3):
      if key[k]=="0":
        b+=a[k]
      else:
        b-=a[k]
    B.append(b)
  B.sort(reverse=True)
  ans=max(ans,sum(B[:m]))
print(ans)

Measured memory_bytes: 3188
s = input()
s = s[::-1]
m = [0] * 2019
m[0] = 1
a = 0
d = 1
ans = 0
for si in s:
    a = (a + int(si) * d) % 2019
    d = (d * 10) % 2019
    ans += m[a]
    m[a] += 1
print(ans)


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

#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define FOR(e, c) for (auto &e : c)
#define SORT(v, n) sort(v, v + n);
#define vsort(v) sort(v.begin(), v.end());
#define rvisort(v) sort(v.begin(), v.end(), greater<int>());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
// #define int long long
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) int(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using ul = unsigned long;

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

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

ll GCD(ll a, ll b) { return b ? GCD(b, a%b) : a; }
ll LCM(ll a, ll b) { return a * b / GCD(a, b); }

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

inline bool inside(int y, int x, int H, int W) {
    return (y >= 0 && x >= 0 && y < H && x < W);
}


int n;
vector<int> G[100005];
ll dp[100005][2]; // dp[i][j]:=iを根としてj色で塗る場合の場合の数

void dfs(int v, int p){
  
  for(auto to: G[v]){
    if(p!=to){
      dfs(to, v);
    }
  }
  
  ll white=1;
  ll black=1;
  for(auto to: G[v]){
    if(to == p) continue;
    (white*=(dp[to][0]+dp[to][1]))%=MOD;
    (black*=(dp[to][0]))%=MOD;
  }
  dp[v][0]=white;
  dp[v][1]=black;
}

int main(){
  cin>>n;
  rep(i,n-1){
    int x,y; cin>>x>>y;
    x--; y--;
    G[x].push_back(y);
    G[y].push_back(x);
  }
  
  dfs(0, -1);
  
  cout<<(dp[0][0]+dp[0][1])%MOD<<endl;
}

Measured memory_bytes: 14208
using System;

class Program
{
    static void Main(string[] args)
    {
        var c = Console.ReadLine()[0];
        if (c == 'A') Console.WriteLine('T');
        else if (c == 'C') Console.WriteLine('G');
        else if (c == 'G') Console.WriteLine('C');
        else if (c == 'T') Console.WriteLine('A');
    }
}


Measured memory_bytes: 13140
#include <bits/stdc++.h>
using namespace std;
int N;
string S;

bool f(int n)
{
  int cnt = 0;
  for (int i = n; i < N - n; i++)
  {
    if (S[i] == '1')
      cnt++;
  }
  return cnt == 0 || cnt == (N - 2 * n);
}

int main()
{
  cin >> S;
  N = S.size();
  int l = N / 2, r = N + 1;
  while (r - l > 1)
  {
    int m = (r + l) / 2;
    if (f(N - m))
      l = m;
    else
      r = m;
  }
  cout << l << endl;
}


Measured memory_bytes: 3776
#include <stdio.h>
int n,k,s,sum;
void calc(int a,int b,int c){
    if(a>n || b>k || c>s)
        return;
    if(b==k && c==s){
        sum++;
        return;
    }
    calc(a+1,b+1,c+a+1);
    calc(a+1,b,c);
}
int main(void){
    for(;sum=0,scanf("%d %d %d",&n,&k,&s),n+k+s;){
        calc(0,0,0);
        printf("%d\n",sum);
    }
    return 0;
}

Measured memory_bytes: 600
n = int(input())
a = map(int, input().split())
b = map(int, input().split())

d = 0
c = 0
for x, y in zip(a, b):
  if x < y:
    d += (y - x) // 2
  else:
    c += x - y

print('Yes' if d >= c else 'No')


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

using namespace std;

#define fio ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define int long long
#define double long double
#define endl '\n'

const int mod = (int) 1e9 + 7;
int n , D;
vector<int> a;
int cache[10001][101][2];

int solve(int i , int d , int small) {
    if(i >= n) {
        return d == 0;
    }
    if(cache[i][d][small] != -1) {
        return cache[i][d][small];
    }
    int res = 0;
    for(int dig = 0; dig <= (small ? 9 : a[i]); dig++) {
        res += solve(i + 1 , (d + dig) % D , small | (dig < a[i]));
        if(res >= mod) {
            res -= mod;
        }
    }
    return cache[i][d][small] = res;
}

signed main() {
    fio;
    string s; cin >> s >> D;
    n = (int) s.length();
    a.resize(n);
    for(int i = 0; i < n; i++) {
        a[i] = s[i] - '0';
    }
    
    memset(cache , -1 , sizeof(cache));
    int answer = solve(0 , 0 , 0) - 1;
    if(answer < 0) {
        answer += mod;
    }
    cout << answer << endl;

    return 0;
}




Measured memory_bytes: 16896
#include<iostream>
using namespace std;
int main()
{
  long long int h,w,n,c;
  cin>>h>>w>>n;
  if(h>w)
  {
    if(n%h==0)
    c=n/h;
    else
      c=(n/h)+1;
  }
  else
    {
    if(n%w==0)
    c=n/w;
    else
      c=(n/w)+1;
  }
  cout<<c;
  return 0;
}

Measured memory_bytes: 256
h,w = map(int,input().split())
s = [str(input()) for i in range(h)]
num = [[-1] * w for i in range(h)]
num[0][0] = 0
now = {(0,0)}
for i in range(1,2501):
    tmp = set()
    for x,y in now:
        if x > 0:
            if s[x-1][y] == "." and num[x-1][y] == -1:
                num[x-1][y] = i
                tmp.add((x-1,y))
        if x < h-1:
            if s[x+1][y] == "." and num[x+1][y] == -1:
                num[x+1][y] = i
                tmp.add((x+1,y))
        if y > 0:
            if s[x][y-1] == "." and num[x][y-1] == -1:
                num[x][y-1] = i
                tmp.add((x,y-1))
        if y < w-1:
            if s[x][y+1] == "." and num[x][y+1] == -1:
                num[x][y+1] = i
                tmp.add((x,y+1))
    now = tmp
if num[-1][-1] == -1:
    print(-1)
else:
    print(h * w-num[-1][-1]-sum([s[i].count("#") for i in range(h)])-1)

Measured memory_bytes: 3064
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <bitset>
#include <set>
#include <stack>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define all(i,n) (i),(i+n)

int dx4[4]={1,0,-1,0};
int dy4[4]={0,-1,0,1};
int dx8[8]={1,0,-1,1,-1,1,0,-1};
int dy8[8]={1,1,1,0,0,-1,-1,-1};
int dx9[9]={0,1,0,-1,1,-1,1,0,-1};
int dy9[9]={0,1,1,1,0,0,-1,-1,-1};

typedef pair<int, int> P;
typedef pair<string, int> SP;
typedef long long ll;
typedef pair<ll, ll> PLL;

const int INF = 1e9;
const ll LLINF = 1e18;
const int MAX_V = 1e6+1;
const ll mod = 1000000007;
// << fixed << setprecision
// --------------------------------------
string s;
int dp[100005][2];
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  cin >> s;
  dp[0][0] = 1;
  REP(i, s.length()) {
    if(s[i] == '0') {
      dp[i + 1][1] = dp[i][1];
      dp[i + 1][0] = dp[i][0];
    } else {
      dp[i + 1][1] = (dp[i][0] + dp[i][1]) % mod;
    }

    if(s[i] == '0') {
      (dp[i + 1][1] += dp[i][1] * 2 % mod) %= mod;
    } else {
      (dp[i + 1][0] += dp[i][0] * 2 % mod) %= mod;
      (dp[i + 1][1] += dp[i][1] * 2 % mod) %= mod;
    }
  }
  cout << (dp[s.length()][0] + dp[s.length()][1]) % mod << endl;
}


Measured memory_bytes: 4528
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <math.h>
#include <cmath>
#include<cctype>
#include<string>
#include<set>
#include<iomanip>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include<bitset>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility> 
using namespace std;
using ll = long long;
template<typename T>using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
const ll inf = 1LL << 60;
#define all(x) (x).begin(),(x).end()
#define puts(x) cout << x << endl
#define rep(i,m,n) for(ll i = m;i < n;++i)
#define pb push_back
#define fore(i,a) for(auto &i:a)
#define rrep(i,m,n) for(ll i = m;i >= n;--i)


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

	int N, A, B;
	cin >> N >> A >> B;
	if ((abs(A - B)+1) % 2 == 0)puts("Borys");
	else puts("Alice");
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
  cin.tie(0),cout.tie(0);
  ios::sync_with_stdio(false);
  ll x,y,z,k,a[1000]={},b[1000]={},c[1000]={},i,j,l;
  cin >> x >> y >> z >> k;
  for(i=0; i<x; i++) {
    cin >> a[i];
  }
  for(i=0; i<y; i++) {
    cin >> b[i];
  }
  for(i=0; i<z; i++) {
    cin >> c[i];
  }
  vector<ll> v;
  sort(a,a+x,greater<ll>());
  sort(b,b+y,greater<ll>());
  sort(c,c+z,greater<ll>());
  for(i=0; i<x; i++) {
    for(j=0; j<y; j++) {
      for(l=0; l<z; l++) {
        if((i+1)*(j+1)*(l+1)<=k) {
          v.push_back(a[i]+b[j]+c[l]);
        }
      }
    }
  }
  sort(v.begin(),v.end(),greater<ll>());
  for(int i=0; i<k; i++) {
    cout << v[i] << endl;
  }
}

Measured memory_bytes: 1400
#include<iostream>
using namespace std;
int main(){
	int n,r,d[55],cp[55],p,c;
	while(cin>>n>>r){
		if(n==0 && r==0)break;
		for(int i=1;i<=n;i++){
			d[i]=n-i+1;
		}
		for(int i=0;i<r;i++){
			cin>>p>>c;
			for(int j=1;j<=p-1;j++){
				cp[j]=d[j];
			}
			for(int j=1;j<=c;j++){
				d[j]=d[p+j-1];
			}
			for(int j=1;j<=p-1;j++){
				d[c+j]=cp[j];
			}
		}
		cout<<d[1]<<endl;

	}
	return 0;
}

Measured memory_bytes: 1160
//   _/                _/                 _/_/_/   _/
//_/_/_/_/   _/_/   _/_/_/_/   _/_/    _/       _/_/
// _/     _/    _/   _/     _/    _/  _/_/_/     _/
//_/     _/    _/   _/     _/    _/  _/    _/   _/
// _/_/   _/_/       _/_/   _/_/      _/_/     _/
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<queue>
#include<vector>
#include<random>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const double pi=3.14159265358979323846;
const int inf=1e9;
const ll INF=1e18;
int main() {
  cin.tie(0),cout.tie(0);
  ios::sync_with_stdio(false);
  ll h,cnt=1,ans=0,x=1;
  cin >> h;
  while(h) {
    h/=2;
    cnt++;
  }
  for(int i=0; i<cnt-1; i++) {
    ans+=x;
    x*=2;
  }
  cout << ans << endl;
 }

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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,a,b) for(int i=(a);i<(b);i++)
#define pb push_back
#define eb emplace_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second

using vint=vector<int>;
using pint=pair<int,int>;
using vpint=vector<pint>;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

template<class A,class B>
ostream& operator<<(ostream& ost,const pair<A,B>&p){
	ost<<"{"<<p.first<<","<<p.second<<"}";
	return ost;
}

template<class T>
ostream& operator<<(ostream& ost,const vector<T>&v){
	ost<<"{";
	for(int i=0;i<v.size();i++){
		if(i)ost<<",";
		ost<<v[i];
	}
	ost<<"}";
	return ost;
}

signed main(){
	int r;cin>>r;
	cout<<r*r<<endl;
	return 0;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strconv"
	"strings"
)

func main() {
	io := NewIo(os.Stdin, os.Stdout)
	defer io.Flush()
	x, k, d := io.NextInt(), io.NextInt(), io.NextInt()
	x = Abs(x)
	q := x / d
	r := x % d
	if k-q < 0 {
		x = x - k*d
	} else if (k-q)%2 == 0 {
		x = r
	} else {
		x = Abs(r - d)
	}
	io.Println(x)
}

// Abs retuns absolutevalue of input
func Abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

// Io is I/O object
type Io struct {
	reader    *bufio.Reader
	writer    *bufio.Writer
	tokens    []string
	nextToken int
}

// NewIo returns a new Io instance
func NewIo(r io.Reader, w io.Writer) *Io {
	return &Io{
		reader: bufio.NewReader(r),
		writer: bufio.NewWriter(w),
	}
}

// Flush flushes writer
func (io *Io) Flush() {
	err := io.writer.Flush()
	if err != nil {
		panic(err)
	}
}

// NextLine scans a line from stdin
func (io *Io) NextLine() string {
	var buffer []byte
	for {
		line, isPrefix, err := io.reader.ReadLine()
		if err != nil {
			panic(err)
		}
		buffer = append(buffer, line...)
		if !isPrefix {
			break
		}
	}
	return string(buffer)
}

// Next return a word from stdin
func (io *Io) Next() string {
	for io.nextToken >= len(io.tokens) {
		line := io.NextLine()
		io.tokens = strings.Fields(line)
		io.nextToken = 0
	}
	r := io.tokens[io.nextToken]
	io.nextToken++
	return r
}

// NextInt returns an integer from stdin
func (io *Io) NextInt() int {
	i, err := strconv.Atoi(io.Next())
	if err != nil {
		panic(err)
	}
	return i
}

// Println is a wrapper of fmt.Fprintln
func (io *Io) Println(a ...interface{}) {
	fmt.Fprintln(io.writer, a...)
}


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

int main()
{
    ll n, k; cin >> n >> k;
    ll m = 0;
    if (n > k) {
        m = n%k;
        
    }else{
        m = n;
    }
    m = min(m, abs(m - k));
     
    cout << m << endl;
    return 0;
}


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

using namespace std;

ifstream fi("BOOKS.INP");
ofstream fo("BOOKS.OUT");

#define fi cin
#define fo cout

int n,K,c[2001],g[2001];
int A[11][2001],N[2001],f[2][2001][11];

bool cmp(int x,int y)
{
    return x>y;
}

void nhapdl()
{
    fi>>n>>K;
    for (int i=1; i<=n; ++i)
    {
        fi>>c[i]>>g[i];
        A[g[i]][++N[g[i]]]=c[i];
    }
    for (int i=1; i<=10; ++i) sort(A[i]+1,A[i]+N[i]+1,cmp);
}

void xuli()
{
    int l=0;
    for (int i=10; i>=1; --i)
    {
        l=1-l;
        int sum;
        for (int j=0; j<=K; ++j)
        {
            sum=0;
            for (int t=0; t<=N[i] && t<=j; ++t)
            {
                sum+=A[i][t];
                f[l][j][i]=max(f[l][j][i],f[1-l][j-t][i+1]+sum+t*(t-1));
            }
        }
    }
    fo<<f[l][K][1]<<'\n';
}

int main()
{
    nhapdl();
    xuli();
}

Measured memory_bytes: 1472
n = int(input())
p = list(map(int, input().split()))
p_index = sorted([[p[i], i] for i in range(n)], key=lambda x: x[0])
q = [p_index[i][1] for i in range(n)]

a = [n * (i + 1) for i in range(n)]
b = list(reversed(a))

a = [a[i] + q[i] - 1 for i in range(n)]

print(" ".join(list(map(str, a))))
print(" ".join(list(map(str, b))))

Measured memory_bytes: 10132
// Try AtCoder
// author: Leonardone @ NEETSDKASU

fn main() {
    let mut stdin = String::new();
    std::io::Read::read_to_string(&mut std::io::stdin(), &mut stdin).unwrap();
    let mut stdin = stdin.split_whitespace();
    let mut get = || stdin.next().unwrap();
    macro_rules! get {
        ($t:ty) => (get().parse::<$t>().unwrap());
        () => (get!(i64));
    }
    
    let a = get!();
    let b = get!();
    
    let ans = std::cmp::max(0, a - 2 * b);
    
    println!("{}", ans);
}

Measured memory_bytes: 4352
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int main() {
	int N;
	int a;
	vector<int>V;
	cin >> N;
	for (int i = 0; i < N;++i) {
		cin >> a;
		V.push_back(a);
	}
	sort(V.begin(), V.end(),greater<int>());
	int Asum = 0;
	int Bsum = 0;
	for (int i = 0; i < N; i += 2) {
		Asum += V[i];
	}
	for (int i = 1; i< N; i += 2) {
		Bsum += V[i];
	}
	cout << Asum - Bsum << endl;
	return 0;
}


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

int main() {
    int a[5], k;
    rep(i, 5) cin >> a[i];
    cin >> k;

    rep(i, 4) {
        for(int j=i+1; j<5; j++) {
            if(a[j] - a[i] > k) {
                cout << ":(" << endl;
                return 0;
            }
        }

    }

    cout << "Yay!" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
#include <string.h>
#include <queue>
using namespace std;

int main() {
	int A,B,C,s=0;
	bool ans=false;
	cin>>A>>B>>C;
	s=C;
	while(s<A*B+C)
	{
		s+=A;
		if(s%B==0){
			ans=true;
			break;
			}
	}
	cout<<(ans?"YES":"NO");
}

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

typedef pair<int, int> P;

#define int long long

signed main(){
    int n;
    int b[110];

    priority_queue<P, vector<P>, greater<P> > que;
    cin >> n;

    for(int i = 0;i < n-1;i++){
        cin >> b[i];
        que.push({b[i], i});
    }

    int a[110];
    memset(a, -1, sizeof(a));

    while(!que.empty()){
        int num = que.top().first;
        int idx = que.top().second;
        que.pop();
        if(a[idx] == -1) a[idx] = num;
        if(a[idx+1] == -1) a[idx+1] = num;
    }

    int ans = 0;
    for(int i = 0;i < n;i++){
        ans += a[i];
    }

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


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<iostream>
#define mod 1000000007
typedef long long int lli;
using namespace std;
int main()
{
	ios_base::sync_with_stdio(false); 
	std::cin.tie(NULL);
	std::cout.tie(NULL);
	lli n,m;
	cin>>n>>m;
	cout<<((n*(n-1))+(m*(m-1)))/2<<endl;
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define FOR(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define REPD(i, n) for (ll i = (ll)(n)-1; i >= 0; i--)
const ll INF = 1LL << 60;
const int INF32 = 1 << 29;
const ll MOD = 1000000007;
using Graph = vector<vector<int>>; // グラフ型
using pint = pair<int, int>;

int main()
{
    int A, B, H, M;
    cin >> A >> B >> H >> M;
    ld thetaA = 30 * H % 360 + 0.5 * M;
    if (thetaA >= 360)
    {
        thetaA -= 360;
    }
    ld thetaB = 6 * M;
    ld theta = abs(thetaA - thetaB);
    // if (theta > 180)
    // {
    //     theta -= 180;
    // }
    ld ans = sqrt(ld(A * A) + ld(B * B) - ld(2 * A * B * cos(theta * 3.14159265358979323846 / 180)));
    cout << setprecision(18) << ld(ans) << endl;
}

Measured memory_bytes: 4164
import java.util.*;

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

        if(TapDance(0, S)){
            System.out.println("No");
        } else {
            System.out.println("Yes");
        }
    }
    public static boolean TapDance(int index, String S) {
        if (index >= S.length()) {
            return false;
        }
        if ((index + 1) % 2 == 1) { // odd
            if (S.charAt(index) == 'R' ||
                S.charAt(index) == 'U' ||
                S.charAt(index) == 'D' ) {
                return TapDance(index + 1, S);
            }
            return true;
        } else {    // even
            if (S.charAt(index) == 'L' ||
                S.charAt(index) == 'U' ||
                S.charAt(index) == 'D' ) {
                return TapDance(index + 1, S);
            }
            return true;
        }
    }
}


Measured memory_bytes: 23636
#include<iostream>

using namespace std;

int main(){

    int year, month, day;
    char s1, s2;
    cin >> year >> s1 >> month >> s2 >> day;

    if (year >= 2020) {
        cout << "TBD" << endl;
    }
    if (year <= 2018) {
        cout << "Heisei" << endl;
    }
    if (year == 2019) {
        if (month >= 5) {
            cout << "TBD" << endl;
        }else{
            cout << "Heisei" << endl;
        }
    }

    return 0;
}

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

int main(){
  int a[5];
  for(int i=0;i<5;++i) {
    cin >> a[i];
    if(a[i]==0) {
      cout << i+1;
      return 0;
    }
  }
}


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

using namespace std;
using ll = long long;


int main()
{
	int n; 
	cin >> n;
	vector<int> a(n);
	for(int i = 0; i < n; i++)cin >> a[i];
	vector<int> cnt(200000), cnte(200000);
	for(int  i = 0; i < n; i+= 2)cnt[a[i]]++;
	int oelement = max_element(cnt.begin(), cnt.end()) - cnt.begin(), ocnt = *max_element(cnt.begin(), cnt.end());
	*max_element(cnt.begin(), cnt.end()) = 0;

	for(int i = 1; i < n; i += 2) cnte[a[i]]++;
	auto itr = max_element(cnte.begin(), cnte.end());
	int eelement = itr - cnte.begin(), ecnt = *itr;
	*itr = 0;
	/*
	for(int i = 0; i < n; i++)cout << cnt[i] << " ";
	cout << endl;
	*/

	if(eelement == oelement) {
		int on = *max_element(cnt.begin(), cnt.end());
		int en = *max_element(cnte.begin(), cnte.end());
		cout << min(n - (ecnt + on), n - (ocnt + en)) << endl;
	}else {
		cout << n - (ecnt + ocnt) << endl;
	}
}

Measured memory_bytes: 2176
#include<iostream>
#include<vector>
#include<cmath>
#include<cstdio>
#include <iomanip>
using namespace std;

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

int pathcount(int N) {
	int ans;
	int kaijyo[9];
	kaijyo[0] = 1;
	kaijyo[1] = 1;
	kaijyo[2] = 2;
	kaijyo[3] = 6;
	kaijyo[4] = 24;
	kaijyo[5] = 120;
	kaijyo[6] = 720;
	kaijyo[7] = 5040;
	kaijyo[8] = 40320;

	ans = 2 * kaijyo[N - 2] + 2 * (kaijyo[N] - 2 * kaijyo[N - 1]) / (N - 1);

	return ans;
}

int main() {

	int N;
	vector<int> x;
	vector<int> y;
	int kaijyo[9];
	kaijyo[0] = 1;
	kaijyo[1] = 1;
	kaijyo[2] = 2;
	kaijyo[3] = 6;
	kaijyo[4] = 24;
	kaijyo[5] = 120;
	kaijyo[6] = 720;
	kaijyo[7] = 5040;
	kaijyo[8] = 40320;

	cin >> N;
	int tmpx;
	int tmpy;

	REP(i, N) {
		cin >> tmpx >> tmpy;
		x.push_back(tmpx);
		y.push_back(tmpy);
	}

	double pathsum = 0;
	FOR(i, 0, N) {
		FOR(j, i + 1, N) {
			pathsum += sqrt((x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j]));
		}
	}
	cout << fixed << setprecision(10);
	cout << pathsum * (double)pathcount(N) / kaijyo[N] << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
// #include <numeric>

#define FAST ios_base::sync_with_stdio(false); cin.tie(0)
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
typedef long long int ll;
#define iceil(a,b) (x+y-1)/y
#define min(x,y)(x<y?x:y)
 
using namespace std;
typedef pair<int, int> P;


int main() {
	FAST;

	int n;
	cin >> n;

	int a[n];
	rep(i,n) {cin >> a[i]; a[i] -= (i+1);}

	sort(a, a+n);
	size_t median_index = n/2;
	double median = (n%2==0? static_cast<double>(a[median_index] + a[median_index - 1]) / 2 : a[median_index]);

	long ans = 0;
	rep(i,n) ans += abs(a[i] - (long)median);
	cout << ans << "\n";

	return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<cmath>
#include<map>
#include<set>
#include<stack>
#include<string>
#include<algorithm>
#include <vector>
#include<cstdio>
#include <numeric>
#include <queue>
#include <list>
#include <math.h>
#include <stdio.h>
#include <math.h>
#include <errno.h>
#include <fenv.h>
#include <iomanip>
using namespace std;
using Graph = vector<vector<int> >;
int main(){
    int N,M;cin>>N>>M;
    Graph G(N);
    for (int i = 0; i < M; ++i) {
        int a, b;
        cin >> a >> b;
        a--;
        b--;

        //cout<<"hi"<<endl;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    //for(int i=0;i<N;i++){
        //cout<<G[i][0]<<endl;
    //}
    vector<int> dist(N, -1); // 全頂点を「未訪問」に初期化
    queue<int> que;
    dist[0] = 0;
    que.push(0);
    while (!que.empty()) {
        int v = que.front(); // キューから先頭頂点を取り出す
        que.pop();
        for (int nv : G[v]) {
            if (dist[nv] != -1) continue; // すでに発見済みの頂点は探索しない

            // 新たな白色頂点 nv について距離情報を更新してキューに追加する
            dist[nv] = v + 1;
            que.push(nv);
        }
    }
    cout<<"Yes"<<endl;
    for(int i=1;i<N;i++){
        cout<<dist[i]<<endl;
    }



    
}

Measured memory_bytes: 10168
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
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; }

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

int main(){
    
    int K; cin >> K;
    ll ans=0;
    for (int i=1; i<=K; i++){
        for (int j=1; j<=K; j++){
            for (int k=1; k<=K; k++){
                ans+=gcd(i,gcd(j,k));
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3624
import bisect
N = 10**6
dp = [0] * (N+1)
dp[0], dp[1] = 1, 1
prime = []
for i in range(2,N+1):
    if dp[i]==0:
        prime.append(i)
        for j in range(N//i+1):
            dp[j*i] = 1

like2017 = []
for p in prime:
    query = (p+1)//2
    idx = bisect.bisect_left(prime, query)
    if prime[idx] == query:
        like2017.append(p)
    

Q = int(input())
for q in range(Q):
    l, r = map(int,input().split())
    l = bisect.bisect_left(like2017, l)
    r = bisect.bisect_right(like2017, r)
    print (r-l)

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

typedef long long ll;
typedef unsigned long long ull;
typedef string st;
typedef double db;
typedef vector<long long> vecll;
typedef vector<char> vechar;
typedef vector<string> vecst;

int main(){
    ll A, B;
    cin >> A >> B;
    ll ans = 0;
    for(ll i = A; i <  B + 1; i++){
        st sti = to_string(i);
        if(sti.at(0) == sti.at(4) && sti.at(1) == sti.at(3)) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
long long n,m;
cin>>n;
if(360%n==0)
    cout<<360/n<<endl;
 else
  {
    m=360;
      while(1)
      {
          m+=360;
          if(m%n==0){
              cout<<m/n<<endl;
            return 0;}

      }


  }
 return 0;
}


Measured memory_bytes: 3604
N = int(input())
T = list(map(int,input().split()))
S = 0
for i in range(len(T)):
    list.sort(T, reverse=False)
    S = (T[0]+T[1])/2
    T.append(S)    
    T.pop(0)
    T.pop(0)
    
    if len(T) ==1:break
print(T[0])

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

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s;
    cin >> s;
    int n = (int) s.size() + 1;
    vector<int> bs(n), cs(n);
    bs[0] = 0;
    for (int i = 1; i < n; ++i) {
        if (s[i-1] == '<') {
            bs[i] = bs[i-1] + 1;
        } else {
            bs[i] = 0;
        }
    }
    cs[n-1] = 0;
    for (int i = n-2; i >= 0; --i) {
        if (s[i] == '>') {
            cs[i] = cs[i+1] + 1;
        } else {
            cs[i] = 0;
        }
    }
    long long sum = 0;
    for (int i = 0; i < n; ++i) {
        sum += max(bs[i], cs[i]);
    }
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 4764
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
template<typename T1,typename T2> bool chmin(T1 &a,T2 b){if(a<=b)return 0; a=b; return 1;}
template<typename T1,typename T2> bool chmax(T1 &a,T2 b){if(a>=b)return 0; a=b; return 1;}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);

    int a,b,c;
    cin>>a>>b>>c;
    cout << c << " " << a << " " << b << endl;
    
}

Measured memory_bytes: 256
/*
 *  author : Atul Anand   
 *  created on : Wed Apr 01 2020
 */

import java.io.*;
import java.util.*;

public class Main{

    public static void main(String[] args) throws IOException {
        int N = in.nextInt();
        String S = in.next();
        if((N & 1) == 0){
            if(S.substring(0, N/2).equals(S.substring(N/2))){
                println("Yes");
            }
            else{
                println("No");
            }
        }   
        else{
            println("No");
        }
        in.close();
        out.close();
    }

    static int MIN = Integer.MIN_VALUE;
    static int MAX = Integer.MAX_VALUE;
    static Reader in = new Reader();
    static PrintWriter out = new PrintWriter(System.out);

    static void read(int arr[], int N) throws IOException { 
    	for(int i = 0; i < N; i++){ 
    		arr[i] = in.nextInt(); 
    	} 
    }
    
    static void read(long arr[], int N) throws IOException { 
    	for(int i = 0; i < N; i++){ 
    		arr[i] = in.nextLong(); 
    	} 
    }
    
    static void read(String arr[], int N) throws IOException { 
    	for(int i = 0; i < N; i++){ 
    		arr[i] = in.next(); 
    	} 
    }
    
    static void print(Object O) {  
    	out.print(O); 
    }
    
    static void println(Object O) { 
    	out.println(O); 
    }
    
    static void println(int arr[]) { 
    	for(int i = 0; i < arr.length; i++){ 
    		print(arr[i]+" "); 
    	} 
    	println(""); 
    }

    static void println(int arr[][]) { 
    	for(int i = 0; i < arr.length; i++){ 
    		println(arr[i]); 
    	}
    }
    
    static void debug(Object O) { 
    	System.out.println(O); 
    }
}

class Reader {
    BufferedReader reader;
    StringTokenizer tokenizer;

    Reader() {
        reader = new BufferedReader(new InputStreamReader(System.in));
        tokenizer = new StringTokenizer("");
    }

    String next() throws IOException {
        while (!tokenizer.hasMoreTokens() ) { 
            tokenizer = new StringTokenizer(reader.readLine()); 
        }
        return tokenizer.nextToken();
    }

    int nextInt() throws IOException { 
        return Integer.parseInt(next()); 
    }
    
    double nextDouble() throws IOException { 
        return Double.parseDouble(next());
    }
    
    long nextLong() throws IOException { 
        return Long.parseLong(next()); 
    }
    
    String nextLine() throws IOException { 
        return reader.readLine(); 
    }
    
    void close() throws IOException { 
        reader.close(); 
    }
}

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

#define debug(x) cout <<"DEBUG"<<" "<< #x << ":" << x << '\n'

// n回繰り返し
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順
#define rep1(i,n) for(int i = 1; i <= ((int)(n)); i++) // 1-indexed昇順
#define rrep(i,n) for(int i = ((int)(n)-1); i >= 0; i--)  // 0-indexed降順
#define rrep1(i,n) for(int i = ((int)(n)); i >= 1; i--)   // 1-indexed降順
#define all(x) (x).begin(),(x).end()

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vii;  // 2次元配列
typedef vector<ll> vll;
typedef vector<double> vd;
typedef pair<int, int> PII;

template<typename T>
using vec = vector<T>;
template<class T>
using maxheap = std::priority_queue<T>;
template<class T>
using minheap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

template<class T,class U> inline bool chmax(T &a, const U &b){if(a<b){a=b;return 1;}return 0;}
template<class T,class U> inline bool chmin(T &a, const U &b){if(a>b){a=b;return 1;}return 0;}

const ld Pi = std::acos(-1.0L);
const ll infll = (1LL<<62)-1;
const int inf = (1<<30)-1;
const int mod = 1000000007;
// const int mod = 998244353;


/*FUNCs=================================================*/


/*MAIN==================================================*/
signed main(){
    int _StartTime_ = clock();
    cin.tie(nullptr);
    ios::sync_with_stdio(false);   //cin cout 高速化
    // cout << fixed << setprecision(15);

    int n; cin >> n;
    string s; cin >> s;
    
    int cnt = 0;
    // 暗証番号を全探索
    for(int i = 0; i < 1000; ++i) {
        string t = to_string(i);
        if(t.size()==1) t = "00" + t;
        else if(t.size()==2) t = "0" + t;
        
        int j = 0;
        char ch = t[j];
        bool can = 0;
        for(int i = 0; i < n; ++i) {
            if(s[i]==ch) {
                if(j==2) {
                    can = 1;
                    break;
                }
                ++j;
                ch = t[j];
            }
        }
        if(can) ++cnt;
    }

    cout << cnt << '\n';

    // printf("ExcutionTime: %d /ms\n",1000*(int)((clock()-_StartTime_)/CLOCKS_PER_SEC));
}

Measured memory_bytes: 384
#include<stdio.h>
int main(void){
    int n,m,l,i,j;
    long int sum=0;
    int a[100][100],b[100][100];
    scanf("%d %d %d",&n,&m,&l);
    for(i=0;i<n;i++){
        for(j=0;j<m;j++){
            scanf("%d",&a[i][j]);
        }
    }
    for(i=0;i<m;i++){
        for(j=0;j<l;j++){
            scanf("%d",&b[i][j]);
        }
    }
    for(i=0;i<n;i++){
        for(j=0;j<l;j++){
            for(int k=0;k<m;k++){
                sum+=a[i][k]*b[k][j];
            }
            printf("%ld",sum);
            if(j==l-1){
                printf("\n");
            }else{
                printf(" ");
            }
            sum=0;
        }
    }
    return 0;
}


Measured memory_bytes: 2104