akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Linq;//リストの使用
using System.Collections.Generic;
class Program
{
static bool[] isPrimes = makePrimeList(100000);//i-1が素数かどうか

	static void Main()
	{
		long n = long.Parse(Console.ReadLine());
		string answer = n.ToString() + ":";

    List<long> answers = Factoring(n);
    for(long i = 0; i < answers.Count(); i++)
    {
      answer += " " + answers[(int)i].ToString();
    }
    
		Console.WriteLine(answer);//WriteLineをWriteとすると、改行なしで出力。
	}

  static List<long> Factoring(long originalNum)//引数をO(√n)で素因数分解。リストには同じ数も含む。
  {
    List<long> answers = new List<long>();
    for(long i = 2; i <= Math.Sqrt(originalNum); i++)
    {
      if(!isPrimes[i-1]) continue;//素数でないとき
      else
      {
        while(originalNum % i == 0)
        {
          originalNum /= i;
          answers.Add(i);
        }
      }
    }
    if(originalNum != 1) answers.Add(originalNum);
    return answers;
  }

  static bool[] makePrimeList(long maxPrime)//「引数1以上」max以下の素数判定。エラトステネスの篩を用いる。
  {
    bool[] isPrimes = new bool[maxPrime];//素数リスト
    isPrimes[0] = false;//1は素数でないのでfalse
    for(long i = 1; i < maxPrime; i++) isPrimes[i] = true;//素数と仮定してtrue
    
    for(long i = 2; i <= Math.Sqrt(maxPrime); i++)
    {
      if(isPrimes[i-1])
      {
        for (long j = i*2; j <= maxPrime; j+=i)
        {
          isPrimes[j-1] = false;//素数でないのでfalse
        }
      }
    }

    return isPrimes;
  }
  
}


Measured memory_bytes: 20364
n = int(input())
a = [int(i) for i in input().split()]
pari = [0] * 30
for i in range(30):
    for j in a:
        pari[i] += (j&(1<<i))>>i

ans = a[:]

for i in range(30):
    if pari[i]%2:
        for j in range(n):
            if a[j]&(1<<i):
                ans[j] -= 1<<i
            else:
                ans[j] += 1<<i

print(' '.join([str(i) for i in ans]))

Measured memory_bytes: 105204
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = s; i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << endl;
#define CFYN(n) cout << ( (n) ? "YES":"NO") << endl;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;

int main(void)
{
    IOS
    const char C = 'C';
    string s; cin >> s;
    string s1(s), s2(s), s3(s),s4(s);
    int l = s.size();
    int k; cin >> k;
    ll ans = 0;
    if (l == 1) {
        ans = k / 2;
    } else {
        // c1:1文字目を変えない c2:1文字目を変える c3:末尾を変える c4:両端変更
        ll c1 = 0, c2 = 1, c3 = 1, c4 = 2;
        s2[0] = C; s3[l-1] = C;
        s4[0] = C; s4[l-1] = C;
        FOR(i,1,l) {
            if (s1[i-1] == s1[i]) {
                c1++; s1[i] = C;
            }
            if (s2[i-1] == s2[i]) {
                c2++; s2[i] = C;
            }
            if (s3[l-i] == s3[l-i-1]) {
                c3++; s3[l-i-1] = C;
            }
            if (s4[i-1] != C  && s4[i-1] == s4[i]) {
                c4++; s4[i] = C;
            }
        }
        cerr << c1 << " " << c2 << " " << c3 << " " << c4 << endl;
        if (k == 1) ans = c1;
        else if  (s1[0] != s1[l-1]) ans = c1 * k;
        else {
            // 1. 14141..
            ans = c1 * ((k+1) / 2) + c4 * (k / 2);
            // 2. 22222...
            ans = min(ans,c2 * k);
            // 3. 33333...
            ans = min(ans,c3 * k);
            // 4. 12222...
            ans = min(ans,c2 * (k-1) + c1);
            // 5. 33...331
            ans = min(ans,c3 * (k-1) + c1);
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#include <unordered_map>
#define endl "\n"
#define all(v) v.begin(),v.end()
#define allr(s) s.rbegin(),s.rend()
#define RT(s) return cout<<s,0
#define watch(x) cout << (#x)<<" = "<<x<<endl
#define sz(s)	(int)(s.size())
#define PI acos(-1)
#define EPS 1e-3
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<ll> row;
typedef vector<row> matrix;
int dy[] = { 1, -1, 0, 0, -1, 1, 1, -1 };
int dx[] = { 0, 0, 1, -1, 1, -1, 1, -1 };
void file() {
#ifndef ONLINE_JUDGE
	freopen("in.txt", "r", stdin);
	//freopen("out.txt", "w", stdout);
#else
	//freopen("street.in", "r", stdin);
	//freopen("out.txt", "w", stdout);
#endif
}
void fast() {
	std::ios_base::sync_with_stdio(0);
	cin.tie(NULL);
}


int main() {
	//file();
	fast();
	int T, x; cin >> T >> x;
	cout << setprecision(10) << T / (double)x << endl;
	return 0;
}

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

#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y

using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;

using f32 = float;
using f64 = double;

#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) for(i64 i = 1; i <= n; ++i)
#define RREP(i, n) for(i64 i = n - 1; i >= 0 ; --i)
#define RREPS(i, n) for(i64 i = n; i >= 1; --i)

#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))

#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define pb push_back
#define mp make_pair

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

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }

template<typename T, size_t N>
i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); }


struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;


#define MAX_H 300
#define MAX_W 300
char G[MAX_H][MAX_W];
i64 Colored[MAX_H][MAX_W];

int main() {
    using P = pair<i64, i64>;
    i64 H, W, K; cin >> H >> W >> K;
    i64 num = 0;
    vector<P> point;
    vector<i64> C(H, 0);
    REP(y, H) {
        REP(x, W) {
            cin >> G[y][x];
            if (G[y][x] == '#') {
                C[y]++;
                point.emplace_back(y, x);
            }
        }
    }

    i64 color = 1;
    REP(y, H) {
        if (C[y] == 0) continue;

        i64 cy = C[y];
        REP(x, W) {
            char c = G[y][x];
            Colored[y][x] = color;
            if (c == '#') {
                cy--;
                if (cy > 0) color++;
            }
        }
        color++;
    }

    for (P &p : point) {
        i64 y = p.first;
        i64 x = p.second;
        i64 color = Colored[y][x];
        while (x < W && Colored[y][x] == color) x++;

        while (0 <= (x - 1) && Colored[y][x - 1] == color) {
            x--;
            i64 ny = y;
            while ((ny + 1) < H && C[ny + 1] == 0) {
                ny++;
                Colored[ny][x] = color;
            }
            ny = y;
            while (0 <= (ny - 1) && C[ny - 1] == 0) {
                ny--;
                Colored[ny][x] = color;
            }
        }
    }

    REP(y, H) {
        REP(x, W) cout << Colored[y][x] << " ";
        cout << endl;
    }


    return 0;
}

Measured memory_bytes: 3056
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
#define Nmax 200010
#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define RFOR(i,a,b) for(long long i = (b-1);i>=a;i--)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ITR(itr,mp) for(auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define RITR(itr,mp) for(auto itr = (mp).rbegin(); itr != (mp).rend(); ++itr)
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<P> Graph;
 
int main() {
	ll N,K;
	cin >> N >> K;
	ll a,b,cnt=0,A[Nmax]={},B[Nmax]={};
	REP(i,N){
		cin >> a >> b;
		A[a]+=b; //aが何個あるか
	}
	REP(i,100001){
		cnt+=A[i];
		if(cnt>=K){
			cout << i << endl;
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 1792
#include<algorithm>
#include<complex>
#include<ctype.h>
#include<iomanip>
#include<iostream>
#include<map>
#include<math.h>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<stdio.h>
#include<string>
#include<string>
#include<vector>

using namespace std;
typedef long long ll;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define pn(s) cout << (#s) << " " << (s) << endl

const ll mod = 1e9 + 7;
const ll inf = 1e18;

bool canXOR(ll a, ll b){
    if(a+b == (a^b)){
        return true;
    }else{
        return false;
    }
}

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

    // input
    int N;
    cin >> N;
    
    vector<ll> A(N);
    FOR(i, 0, N){
        cin >> A.at(i);
    }

    // F[i] = iからどこまで右に行けるか
    vector<ll> F(N);

    ll state = 0;
    ll head = 0; // どこまで行けるか
    // i 現在地
    FOR(i, 0, N){
        // 行けるところまで進む
        while(canXOR(state, A[head]) && head < N){
            state ^= A[head];
            head++;
        }
        F[i] = head - 1;

        // もう進めない
        if(F[i] == i){
            state = 0;
        }
        // 終了前, iの分を削除
        else{
            state -= A[i];
        }
    }

    // cout << "F ";
    // FOR(i, 0, N){
    //     cout << F[i] << " ";
    // }
    // cout << endl;

    ll answer = 0;
    FOR(i, 0, N){
        ll diff = F[i] - i + 1;
        answer += diff;
    }

    p(answer);
    
    return 0;
}

Measured memory_bytes: 3456
#include <cmath>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <functional>
#include <queue>
#include <iostream>
#include <string.h>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <cstdint>
#include <climits>
#include <unordered_set>
#include <sstream>
#include <stack>

using namespace std;

#define ll long long int

int main()
{
    int n;
    cin >> n;
    vector<ll> a(n);
    for(int i = 0;i < n;i++)
    {
        cin >> a[i];
    }
    list<ll> r;
    for(int i = 0;i < n;i++)
    {
        if(i % 2 == 0)
        {
            r.push_back(a[i]);
        }
        else
        {
            r.push_front(a[i]);
        }
    }
    if(n % 2 == 0)
    {
        for(auto e: r)
        {
            cout << e << " ";
        }
    }
    else
    {
        for(auto e = r.rbegin();e != r.rend();e++)
        {
            cout << *e << " ";
        }
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 9984
n=int(input())
s=list(input())

ans=0
for i in range(10):
    if str(i) in s:
        first=s.index(str(i))
        ss=s[first+1:]
        for j in range(10):
            if str(j) in ss:
                sec=ss.index(str(j))

                for k in range(10):
                    if str(k) in ss[sec+1:]:
                        ans+=1

print(ans)

Measured memory_bytes: 9956
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include<cmath>
#include<limits>
#define ll long long
#define ALL(x) (x).begin(),(x).end()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define int_INF 2147483647
#define pint_INF 2000000000
#define ll_INF 	9123372036854775807
#define MOD 100000007
#define vi vector<int>
#define vvi vector<vector<int>>
#define vll vector<long long>
#define pii pair<int,int>
#define vpii vector<pair<int,int>>
using namespace std;

//余裕についてdp?
int main() {
	int N; cin >> N;
	vi A(N);
	rep(i, N) {
		cin >> A[i];
	}
	vector<vector<ll>> dp(N, vll(3,-ll_INF)); //dp[i][j] jは余裕を表す

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

		dp[1][0] = A[1];
		dp[1][1] = A[0];
		dp[1][2] = -ll_INF;

		dp[2][0] = A[2];
		dp[2][1] = A[1];
		dp[2][2] = A[0];

		for (int i = 3; i < N; i++) { // 0 Origin
			if (i % 2 == 1) { // 1 Origin and Even nubmer indexed  A
				dp[i][2] = -ll_INF;
				dp[i][1] = dp[i - 1][2] + A[i - 1];
				dp[i][0] = max(dp[i - 1][2], dp[i - 1][1]) + A[i];
			}
			else {
				dp[i][2] = dp[i - 1][1];
				dp[i][1] = dp[i - 1][0];
				dp[i][0] = max({ dp[i - 2][0],dp[i - 2][1],dp[i - 2][2] }) + A[i];
			}
		}

		cout << max({ dp[N - 1][0],dp[N - 1][1],dp[N - 1][2] }) << endl;
	}
	
}

Measured memory_bytes: 14876
#include <bits/stdc++.h>
#define ll long long
#define pii pair<int, int>
#define pdd pair<double, double>
#define V vector<int>
#define inf 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f3f
#define db(x) cout << #x << "=" << (x) << endl
#define db2(x, y) cout << #x << "=" << (x) << " " << #y << "=" << (y) << endl
#define db3(x, y, z) cout << #x << "=" << (x) << " " << #y << "=" << (y) << " " << #z << "=" << (z) << endl

using namespace std;
const int mod = 1e9 + 7;
const int maxn = 1e5 + 7;
const double eps = 1e-9;

int a[maxn];
int main()
{
    #ifdef AFei
    freopen("in.txt", "r", stdin);
    #endif

    int N, M, Q;
    cin >> N >> M >> Q;
    for(int x, i = 0; i < Q; ++ i)
    {
        scanf("%d", &x);
        a[x-1] ++;
    }
    for(int i = 0; i < N; ++ i)
    {
        if(Q-a[i] < M)
            puts("Yes");
        else
            puts("No");
    }

    return 0;
}


Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		int K = sc.nextInt();
		int now = A;
		for (int i=0;i<K;i++) {
			if (A+i<=B) {
				now =A+i;
				System.out.println(now);
			}
		}
		for (int i=K-1;i>=0;i--) {
			if (B-i>now) {
				System.out.println(B-i);
			}
		}
	}
}

Measured memory_bytes: 36192
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 10000000000000000
#define MOD 1000000007
typedef pair<int, int> P;

bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n % i == 0)return false;
	}
	return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}
int mod_pow(int n, int p, int m) {
	if (p == 0) return 1;
	if (p % 2 == 0) {
		int t = mod_pow(n, p / 2, m);
		return (t * t) % m;
	}
	return n * mod_pow(n, p - 1, m) % m;
}
int extGCD(int a, int b, int& x, int& y) {
	if (b == 0) {
		x = 1;
		y = 0;
		return a;
	}
	long long d = extGCD(b, a % b, y, x);
	y -= a / b * x;
	return d;
}
int modinv(int a, int m) {
	int b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}

int perm[1000001];

int comb(int n, int r) {
	return perm[n] * modinv(perm[n - r], MOD) % MOD * modinv(perm[r], MOD) % MOD;
}

signed main() {
	perm[0] = 1;
	for (int i = 1; i <= 1000000; i++) {
		perm[i] = perm[i - 1] * i % MOD;
	}

	int n, m, ans = 1;
	cin >> n >> m;
	int now = 2;
	map<int, int>mp;
	while (now * now <= m) {
		if (m % now == 0) {
			m /= now;
			mp[now]++;
		}
		else now++;
	}
	if (m != 1) {
		mp[m]++;
	}
	for (auto i = mp.begin(); i != mp.end(); i++) {
		int a = i->second;
		ans *= comb(a + n - 1, n - 1);
		ans %= MOD;
	}
	cout << ans << endl;

	return 0;
}

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

int main(){
  int n;
  cin >> n;
  string s;
  map<string, int> mp;
  rep(i,n){
    cin >> s;
    mp[s]++;
  }

  int mx = 0;

  for(auto p : mp) mx = max(mx, p.second);

  for(auto p : mp){
    if(p.second != mx) continue;
    cout << p.first << endl;
  }
  
  return 0;
}


Measured memory_bytes: 25216
#include<bits/stdc++.h> 
//#define <- プログラムの文字列を置換する
//typedef <- 新しい型に名前を付けるためのキーワード

using namespace std;

#define MAX_N 100000

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

const double PI = 3.141592653589793;
const long long MOD = 1e9 + 7;
const long long INF = 1e15;
const int INF_INT = 1e9;

int main(){
    int N;
    cin >> N;
    map<int,int> m;
    for(int i = 0; i < N;i++){
        int a;
        cin >> a;
        auto ite = m.find(a);
        if(ite != m.end()) m.erase(a);
        else m.insert(make_pair(a,1));
    }
    cout << m.size() << endl;
    return 0;
}


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

int main(){
	int H, W, N; cin >> H >> W >> N;
	cout << (N+max(H, W)-1)/max(H, W) << endl;
	return 0;
}


Measured memory_bytes: 256
/**
 * Motto:   To Become Better Than Me
 * Author: cherry0697
 **/

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

#define rep(i,n) for(i=0;i<n;i++)
#define repc(i,a,n) for(i=a;i<n;i++)
#define repa(i,a,n) for(i=a;i<=n;i++)
#define repb(i,a,n) for(i=a;i>=n;i--)
#define trav(a,x) for(auto a=x.begin();a!=x.end();a++)
#define all(x) x.begin(),x.end()
#define pb push_back
typedef long long ll;
typedef long double ld;
typedef vector <long long int> vi;

void solve()
{
  map <ll,ll> m1;
  ll n;
  cin>>n;

  ll x,i;

  rep(i,n-1)
  {
    cin>>x;
    m1[x]++;
  }

  rep(i,n)
  {
    cout<<m1[i+1]<<"\n";
  }
}

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

  int t;
  t=1;

  while(t--)
    solve();

return 0;
}


Measured memory_bytes: 16156
#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;

const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;
const int MOD=1000000007;

int a[20];
int dp[1<<20];

int main(){
	int n,K;cin>>n>>K;
	rep(i,n){
		scanf("%d",&a[i]);
	}
	rep(i,1<<n){
		int sum=0;
		rep(j,n){
			if(i>>j&1)sum+=a[j];
		}
		if(sum==K)dp[i]=1;
	}
	rep(i,n)rep(j,1<<n){
		if(!(j>>i&1))dp[j|1<<i]+=dp[j];
	}
	int Min=INT_MAX;
	rep(i,1<<n){
		int x=((1<<n)-1)^(i);
		if(dp[x]==0){
			Min=min(Min,__builtin_popcount(i));
		}
	}
	cout<<Min<<endl;
}


Measured memory_bytes: 7344
#include<bits/stdc++.h>
#include<stdio.h>
#include<stdlib.h>
using namespace std;
int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
 
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
 
    long double n,x,t,ans=0;
    cin>>n>>x>>t;
    ans=n/x;
    if(ans>(int)ans)ans=((int)ans)+1;
    long long int f= (int)(ans*t);
    cout<<f<<"\n";
}

Measured memory_bytes: 3692
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();
        long m = sc.nextLong();
        sc.close();

        System.out.println(Math.abs((n-2) * (m-2)));
    }
}


Measured memory_bytes: 21972
num=input()

digit=len(num)
DIGIT=digit
num=int(num)
#桁数が1,3,5の場合数える
count=0

while digit!=0:

    if digit%2==0:
        digit-=1
        continue
    if digit==DIGIT:
        count+=num-10**(digit-1)+1
    else:
        count+=10**(digit)-10**(digit-1)
    
    digit-=1


print(count)

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

typedef long long ll;
typedef vector<ll> vl;      typedef vector<int> vi;
typedef vector<vl> vvl;     typedef vector<vi> vvi;
typedef pair<ll, ll> pll;   typedef pair<int, int> pii;
#define forn(i,n) for(int i=0;i<n;i++)
#define rforn(i,n) for(int i=n-1;i>=0;i--)
#define forne(i,n) for(int i=1;i<=n;i++)
#define forse(i,s,e) for(int i=s;i<e;i++)
#define rforse(i,s,e) for(int i=e-1;i>=s;i--)
#define all(x) x.begin(),x.end()
#define sz(x) (int)x.size()
#define MOD 1000000007
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define fill(a,x) memset(a,x,sizeof a);
#define trav(a,x) for(auto &a:x)
#define INF ll(1e18)
#ifdef SHUBHAM107
#include "../trace.h"
#else
#define trace(args...)
#endif
void update(vi &BIT, int value, int index){
    int n = BIT.size() - 1;
    while(index<=n){
        BIT[index] += value;
        index += index & (-index);
    }
}
int query(vi &BIT, int index){
    int sum = 0;
    while(index>0){
        sum += BIT[index];
        index -= index & (-index);
    }
    return sum;
}
int query(vi &BIT, int l, int r){
    return query(BIT, r) - query(BIT, l-1);
}
typedef pair<int, pii> piii;
void solve() {
    int n, q;
    cin >> n >> q;

    vector<int> BIT(n + 1), arr(n);

    for (int i = 0; i < n; i++) {
        cin >> arr[i];
    }

    vector<piii> Queries(q);

    for (int i = 0; i < q; i++) {
        int l, r;
        cin >> l >> r;
        l--, r--;
        Queries[i] = {r, {l, i}};
    }

    map<int, int> last;
    sort(all(Queries));

    int cur = 0;
    vector<int> ans(q);
    for (piii que: Queries) {
        int l = que.S.F, r = que.F, ind = que.S.S;

        while (cur < n && cur <= r) {
            if (last.count(arr[cur])) {
                update(BIT, -1, last[arr[cur]]);
            }
            last[arr[cur]] = cur + 1;
            update(BIT, 1, cur + 1);
            cur++;
        }
        ans[ind] = query(BIT, l + 1, r + 1);
    }

    for (int i: ans)
        cout << i << '\n';
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
#ifdef SHUBHAM107
    freopen("inp.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    freopen("err.txt", "w", stderr);
#endif
    int t = 1;
    // cin >> t;
    while (t--) {
        solve();
    }
}


Measured memory_bytes: 38944
# -*- coding: utf-8 -*-
"""
Created on Wed Sep 23 15:20:49 2020

@author: liang
"""

N, Y = map(int, input().split())
y = Y //1000

a = 0
while a <= N and y - 10*a >=0:
    bt = y - N - 9*a
    ct = 5*N - y + 5*a
    if bt < 0 or ct < 0:
        a += 1
        continue
    if bt % 4 == 0 and ct % 4 == 0:
        b = bt//4
        c = ct//4
        print(a,b,c)
        break
    a += 1
else:
    print(-1,-1,-1)

Measured memory_bytes: 9196
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>

using namespace std;

int main()
{
    long long int t, a, k;

    cin >> t >> a >> k;

    for (int i = 0; i < k; i++) {
        if (i%2 == 0) {
            if (t%2) {
                t--;
            }
            a += (t / 2);
            t /= 2;
        }
        else {
            if (a%2) {
                a--;
            }
            t += (a/2);
            a /= 2;
        }
    }

    cout << t << " " << a << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		ManyFormulas game = new ManyFormulas();
//		game.run();
		game.runWithBit();
	}
}

class ManyFormulas {
	
	String S;
	String[] nums;
	int N;
	
	ManyFormulas() {
		Scanner cin = new Scanner(System.in);
		this.S = cin.nextLine();
		this.nums = new String[S.length()];
		char[] tmp = S.toCharArray();
		for (int i = 0; i < S.length(); i++) {
			nums[i] = String.valueOf(tmp[i]);
		}
		this.N = nums.length;
	}
	
	void run() {
		boolean[] contained = new boolean[nums.length];
		long allSum = dfs(0, contained);
		System.out.println(allSum);
	}
	
	void runWithBit() {
		long allSum = 0;
		for (int i = 0; i < 1 << N - 1; i++) {
			allSum += calculateSumWith(i);
		}
		System.out.println(allSum);
	}
	
	long calculateSumWith(int bit) {
		long sum = 0;
		long tmpNum = 0;
		int digit = 1;
		bit = bit << 1;
//		System.out.println("================");
//		System.out.println("bit: " + Integer.toBinaryString(bit));
		
		for (int j = 0; j < N; j++) {
			if ((bit >> j & 1) == 1) {
				sum += tmpNum;
				tmpNum = 0;
				digit = 1;
			}
//			System.out.println("num: " + nums[N - j - 1]);
			tmpNum += Long.valueOf(nums[N - j - 1]) * digit;
			digit *= 10;
		}
		sum += tmpNum;
//		System.out.println(sum);
		return sum;
	}
	
	long dfs(int depth, boolean[] contained) {
		if (depth == nums.length - 1) {
			return calculateSum(contained);
		}
		return dfs(depth + 1, copyArray(contained)) + dfs(depth + 1, setFlagAtIndex(contained, depth)); 
	}
	
	long calculateSum(boolean[] contained) {
		long sum = 0;
		long tmpNum = 0;
		int digit = 1;
	
		for (int i = contained.length - 1; i >= 0; i--) {
			if (contained[i]) {
				sum += tmpNum;
				digit = 1;
				tmpNum = 0;
			} 
			tmpNum += Long.valueOf(nums[i]) * digit;
			digit *= 10;
		}
		sum += tmpNum;
		return sum;
	}
	
	boolean[] setFlagAtIndex(boolean[] arr, int index) {
		boolean[] newArr = copyArray(arr);
		newArr[index] = true;
		return newArr;
	}
	
	boolean[] copyArray(boolean[] arr) {
		boolean[] newArr = new boolean[arr.length];
		for (int i = 0; i < arr.length; i++) {
			newArr[i] = arr[i];
		}
		return newArr;
	}
	
	void printArray(boolean[] arr) {
		for (int i = 0; i < arr.length; i++) {
			System.out.print(arr[i] + " ");
		}
		System.out.println();
	}
}


Measured memory_bytes: 9812
#include <iostream>
using namespace std;
int main(){

  int H, A;
  
  cin>> H>> A;
  
  int x = 0;
  if(H%A !=0)
    x=1;
  
  int ans = H/A;
  ans += x;
  
  cout<< ans<<endl;
    
  
  return 0;

}


Measured memory_bytes: 256
#include <stdio.h>

       

       int main(void) {

           int X, A, B;

         

           scanf("%d %d %d" , &X, &A, &B);

    

           int D = A + X;



           if(A >= B) {

              printf("delicious");

           }else if(D >= B){

              printf("safe");

           }else{

              printf("dangerous");

           }

    }

Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>

using namespace std;

#define mp make_pair
#define pb push_back
#define ll long long

ll poww(ll a, ll b, ll mod) {
    ll ans = 1;
    while (b > 0) {
        if (b & 1) ans = (ans * a) % mod;
        b >>= 1;
        a = (a * a) % mod;
    }
    return ans;
}

const int maxN = 250011;

const ll mod = 1000000007;
const ll base = 500167;
const ll inv_base = poww(base, mod - 2, mod);

const ll mod2 = 1000000009;
const ll base2 = 503803; 
const ll inv_base2 = poww(base2, mod2 - 2, mod2);

struct hash_key {
    ll v1, v2;

    hash_key() {v1 = v2 = 0;}
    hash_key(ll _v1, ll _v2) {v1 = _v1 % mod; v2 = _v2 % mod2;}
    hash_key(ll x) { v1 = (mod + x) % mod, v2 = (mod2 + x) % mod2; }

    bool operator<(const hash_key &who) const {
        return mp(v1, v2) < mp(who.v1, who.v2);
    }
    
    bool operator==(const hash_key &who) const {
        return mp(v1, v2) == mp(who.v1, who.v2);
    }

    void operator*=(const hash_key who) {
        v1 = (v1 * who.v1) % mod;
        v2 = (v2 * who.v2) % mod2;
    }

    void operator+=(const hash_key who) {
        v1 = (v1 + who.v1) % mod;
        v2 = (v2 + who.v2) % mod2;
    }

    void operator-=(const hash_key who) {
        v1 = (v1 + mod - who.v1) % mod;
        v2 = (v2 + + mod2 - who.v2) % mod2;
    }

    hash_key get_inv()const {
        return {poww(v1, mod - 2, mod), poww(v2, mod2 - 2, mod2)};
    }
};

struct smart_map {
    map<hash_key, ll> M;
    hash_key bonus;

    smart_map() {
        M.clear();
        bonus = {1, 1};
    }

    void operator*=(hash_key who) {
        bonus *= who;
    }

    void add(hash_key x) {
        x *= bonus.get_inv();
        M[x]++;
    }

    ll query(hash_key x) {
        x *= bonus.get_inv();
        return M[x];
    }
};

ll n, i;
char s[maxN];
smart_map data;
ll ans;

hash_key act, full;
const hash_key to_left = {base, base2};
const hash_key to_right = {inv_base, inv_base2};

int main()
{
   // freopen("test.in","r",stdin);

    scanf("%d\n%s", &n, s + 1);

    data.add(hash_key(0));
    act = hash_key(0);

    for (i = n; i >= 1; i--) {
        if (s[i] == '+') act += 1;    
        if (s[i] == '-') act += -1;
        if (s[i] == '<') act *= to_left;
        if (s[i] == '>') act *= to_right;
    }

    full = act;
    act = hash_key(0);

    for (i = n; i >= 1; i--) {
        if (s[i] == '+') act += 1;    
        if (s[i] == '-') act += -1;
        if (s[i] == '<') act *= to_left, data *= to_left;
        if (s[i] == '>') act *= to_right, data *= to_right;
    
        hash_key src = act;
        src -= full;
        ans += data.query(src);

        data.add(act);
    }

    printf("%lld", ans);

    return 0;
}


Measured memory_bytes: 31744
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(obj)   (obj).begin(),(obj).end()

#define debug(var)  do{std::cout << __LINE__ << "> " << #var << ": ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }

using namespace std;
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;

void Main() {
	int N; cin >> N;
	int n_tmp = N;
	int keta = 0;
	while (n_tmp) {
		n_tmp /= 10;
		++keta;
	}
	int res = 0;
	for (int i = keta - 1; i > 0; --i) {
		if (i % 2 == 0) continue;
		res += pow(10, i) - pow(10, i - 1);
	}
	if (keta % 2 != 0) {
		res += N - pow(10, keta - 1) + 1;
	}
	cout << res << endl;
}

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


Measured memory_bytes: 256
sx, sy, tx, ty = map(int, input().split())

dx, dy = tx - sx, ty - sy
print('U' * dy + 'R' * (dx + 1) + 'D' * (dy + 1) + 'L' * (dx + 1) + 'U' + \
      'R' * dx + 'U' * (dy + 1) + 'L' * (dx + 1) + 'D' * (dy + 1) + 'R')


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

#define rep(i,n) for(int i = 0; i < n; i++)
#define Rep(i,n) for(int i = 1; i <= n; i++)
#define sz(x) int(x.size())
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define YesorNo(a) printf(a ? "Yes\n" : "No\n")
#define endl '\n'
#define fi first
#define se second
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
template<class T> using V = vector<T>;
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
const int inf = (1<<30)-1;
const ll infll = (1LL<<62)-1;
ll ceil(const ll &a, const ll &b){return ((a)+(b)-1)/b;}
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; }
 
// dp[i][j][cnt] = 座標(i,j), i行目でcnt個拾うときの価値の最大値
ll dp[3010][3010][4] = {};

int main(){
    int h, w, k;
    cin >> h >> w >> k;
    V<V<int>> v(h+2,V<int>(w+2));
    rep(i,k) {
        int y, x;
        cin >> y >> x;
        int c;
        cin >> c;
        v[y][x] = c;
    }

    rep(i,h+1)rep(j,w+1)rep(l,4) {
        { // ↑
            int ny = i + dy[0];
            int nx = j + dx[0];
            chmax(dp[ny][nx][0], dp[i][j][l]);
            chmax(dp[ny][nx][1], dp[i][j][l] + v[ny][nx]);
        }
        { // →
            int ny = i + dy[1];
            int nx = j + dx[1];
            chmax(dp[ny][nx][l], dp[i][j][l]);
            if(l < 3) chmax(dp[ny][nx][l+1], dp[i][j][l] + v[ny][nx]);
        }
    }
    ll ans = 0;
    rep(l,4) {
        chmax(ans, dp[h][w][l]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 320976
#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<algorithm>
#include<cmath>
using namespace std;
#define INF 0x3f3f3f3f
#define _rep(i,a,b) for(int i=(a);i<=(b);++i)
int n,r;

int main()
{
    #ifdef __LOCAL__
        freopen("1.in","r",stdin);
        freopen("1.out","w",stdout);
    #endif
    cin>>n>>r;
    if(n>=10)
        cout<<r;
    else
        cout<<r+100*(10-n);
    
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define MOD 1000000007
int dx[] = {1,0,-1,0};
int dy[] = {0,-1,0,1};

int main(){
    ll n;
    cin >> n;
    vector<int> A(n);
    for(int i=0;i<n;i++) cin >> A[i];
    int ans = 0;
    int cnt = 1;
    for(int x : A){
        if(x == cnt) cnt++;
        else ans++;
    }
    if(ans == n) ans = -1;
    cout << ans << endl;

}


Measured memory_bytes: 1024
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) {
		try {
			BufferedReader br = new BufferedReader(new InputStreamReader(
					System.in));
			StringBuilder s=new StringBuilder(); 
			int val = Integer.parseInt(br.readLine());
			int x = 0;

			for (int i = 1; i <= val; i++) {
				if (i % 3 == 0) {
					s.append(" " + i);
}else if(i % 10 == 3){
s.append(" " + i);
				} else {
					x = i / 10;
					while (x != 0) {
						if (x % 10 == 3) {
							s.append(" " + i);
							break;
						}
						x /= 10;
					}
				}
			}
			System.out.println(s);
			br.close();
		} catch (Exception e) {
			System.err.println(e);
		}
	}
}

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

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	int a,b; cin>>a>>b;
	if(a>=10||b>=10) cout<<-1<<endl;
	else cout<<a*b<<endl;
	return 0;
}

Measured memory_bytes: 256
// B - Balance

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF = 2147483647;
// const ll INF = 9223372036854775807;
// const int MOD = 1e9 + 7;

int W[100];

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

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

	int ans = INF;
	int grp1 = 0;
	int grp2 = sum;
	for (int i=0; i<N-1; i++) {
		grp1 += W[i];
		grp2 -= W[i];
		ans = min(ans, abs(grp1 - grp2));
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
c1=list(map(int,input().split()))
c2=list(map(int,input().split()))
c3=list(map(int,input().split()))
 
 
if (sum(c1)+sum(c2)+sum(c3))%3!=0:
    print("No")
    exit()
elif c2[0]-c1[0]!=c2[1]-c1[1] or c2[0]-c1[0]!=c2[2]-c1[2] or c2[2]-c1[2]!=c2[1]-c1[1]:
    print("No")
    exit()
elif c3[0]-c1[0]!=c3[1]-c1[1] or c3[0]-c1[0]!=c3[2]-c1[2] or c3[2]-c1[2]!=c3[1]-c1[1]:
    print("No")
    exit()
elif c3[0]-c2[0]!=c3[1]-c2[1] or c3[0]-c2[0]!=c3[2]-c2[2] or c3[0]-c2[0]!=c3[1]-c2[1]:
    print("No")
    exit()   
    
elif c1[1]-c1[0]!=c2[1]-c2[0] or c3[1]-c3[0]!=c2[1]-c2[0] or c1[1]-c1[0]!=c3[1]-c3[0]:
    print("No")
    exit()
elif c1[2]-c1[0]!=c2[2]-c2[0] or c3[2]-c3[0]!=c2[2]-c2[0] or c1[2]-c1[0]!=c3[2]-c3[0]:
    print("No")
    exit()    
elif c1[2]-c1[1]!=c2[2]-c2[1] or c3[2]-c3[1]!=c2[2]-c2[1] or c1[2]-c1[1]!=c3[2]-c3[1]:
    print("No")
    exit()      
    
else:
    print("Yes")

Measured memory_bytes: 3192
import java.util.*;

public class Main {
	public static void main(String[] args) {
		
		Scanner keyboard = new Scanner(System.in); 
		
		int H = keyboard.nextInt();
		int W = keyboard.nextInt();
		int M = keyboard.nextInt();
		
		HashMap<Long, Integer> Bakuha = new HashMap<Long, Integer>();
		long MaxH = 3*100000;
		int[]sumH = new int[H];
		int[]sumW = new int[W];
		int SH = 0;
		int SW = 0;
		
		for(int i = 0; i<M; i++) {
			int inH = keyboard.nextInt()-1;
			int inW = keyboard.nextInt()-1;
			Bakuha.put((inH*MaxH)+inW, 1); 
			sumH[inH] ++;
			sumW[inW] ++;
			if(sumH[inH]>= SH) {
				SH = sumH[inH];
			} 
			if(sumW[inW]>= SW) {
				SW = sumW[inW];
			}
		}
		
		ArrayList<Integer> SHindex = new ArrayList<Integer>();
		ArrayList<Integer> SWindex = new ArrayList<Integer>();
		
		for(int h=0; h<H; h++) {
			if(sumH[h] == SH) {
				SHindex.add(h);
			}
		}	
		for(int w=0; w<W; w++) {
			if(sumW[w] == SW) {
				SWindex.add(w);
			}	
		}
		
		int ans = SH+SW-1;//最低の爆破可能数、鳩の巣に被っている
		
		if((long)SHindex.size()*SWindex.size() > M) {//鳩の巣Mより交点の数が大きいとき
			ans = SH+SW;
		}else {//鳩の巣Mより交点の数が小さいとき、交点は鳩の巣に被っているかもしれない
			for(int i=0; i<SHindex.size(); i++) {
				for(int j=0; j<SWindex.size(); j++) {
					if (!Bakuha.containsKey(SHindex.get(i)*MaxH+SWindex.get(j))) { //HashMapに既にキーがないとき、鳩の巣に被っていない
						ans = SH+SW;
					}
				}
			}
		}
		
		System.out.print(ans);
		keyboard.close();
	}
}


Measured memory_bytes: 90512
#include <bits/stdc++.h>
using namespace std;
#define mod 998244353
#define MOD 1000000007
#define inf 0x3f3f3f3f
#define linf 0x3f3f3f3f3f3f3f3fll
typedef long long ll;
typedef pair<int,int> pii;
typedef unsigned long long ull;
const int maxn=5e5+10;
pair<ll,ll> robot[maxn];
int n,tor[maxn];
inline void add1(ll &a,ll b)
{
	b%=mod;
	a+=b;
	if(a>=mod)
	{
	//	exit(-1);
		a-=mod;
	}
}
struct BIT
{
	ll bit[maxn];
	inline void add(int x,ll v)
	{
		x++;
		v%=mod;
		while(x<maxn)
		{
			add1(bit[x],v);
			bit[x]%=mod;
			x+=x&-x;
		}
	}
	inline ll sum(int x)
	{
		x++;
		ll ret=0;
		while(x>0)
		{
			add1(ret,bit[x]);
			ret%=mod;
			x-=x&-x;
		}
		return ret;
	}
}tree;
struct mxBIT
{
	int bit[maxn];
	inline void add(int x,int v)
	{
		x++;
		while(x<maxn)
		{
			bit[x]=max(bit[x],v);
			x+=x&-x;
		}
	}
	inline int sum(int x)
	{
		int ret=0;
		x++;
		while(x>0)
		{
			ret=max(ret,bit[x]);
			x-=x&-x;
		}
		return ret;
	}
}tree2;
int main()
{
//	freopen("data.in","r",stdin);
//	freopen("my.out","w",stdout);
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%lld%lld",&robot[i].first,&robot[i].second);
		robot[i].second+=robot[i].first;
	}
	sort(robot+1,robot+1+n);
	for(int i=1;i<=n;i++)
	{
//		cout<<robot[i].first<<" "<<robot[i].second<<endl;
	}
//	system("pause");
	tor[n]=n;
	tree2.add(n,n);
	for(int i=n-1;i>=1;i--)
	{
		tor[i]=i;
		tree2.add(i,i);
		int p=lower_bound(robot+1,robot+1+n,make_pair(robot[i].second,-linf))-robot;
		p--;
		tor[i]=tree2.sum(p);
		tree2.add(i,tor[i]);
	//	cout<<p<<endl;
	//	if(robot[i].second>robot[i+1].first)tor[i]=tor[i+1];
	//	else tor[i]=i;
	}
	for(int i=1;i<=n;i++)
	{
		if(i!=tor[i])
		{
//			cout<<i<<" "<<tor[i]<<" "<<robot[i].first<<" "<<robot[i].second<<" "<<robot[tor[i]].first<<endl;
		}
		
	}
//	cout<<endl;
//	system("pause");
	tree.add(0,1);
	for(int i=1;i<=n;i++)
	{
		ll tmp=tree.sum(i-1);
		tmp%=mod;
//		cout<<i<<" "<<tmp<<endl;
		tree.add(tor[i],tmp);
	}
	ll ans=tree.sum(n+100);
	ans%=mod;
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 11392
#include<iostream>
#include<queue>
using namespace std;

const int INF = 1<<30;

// lr-0 left, lr-1 right
struct data{
    int i, j, lr, cost;
    bool operator<(const data other)const{
        return cost > other.cost;
    }
};

#define inRange(x,a,b) (a <= x && x < b)
int di[9] = {-2, -1, -1, 0, 0, 0, 1, 1, 2};
int dj[9] = {-1, -1, -2, -1, -2, -3, -1, -2, -1};

int main(){
    int w, h;
    while(cin >> w >> h, w+h){
        char mat[h][w];
        for(int i = 0; i < w*h; i++)    cin >> mat[i/w][i%w];
        int dp[2][h][w];
        for(int i = 0; i < 2; i++)  for(int j = 0; j < h; j++)  for(int k = 0; k < w; k++)  dp[i][j][k] = INF;
        priority_queue<data> pq;
        for(int j = 0; j < w; j++){
            if(mat[h-1][j] == 'S')  pq.push(data({h-1, j, 0, 0})), pq.push(data({h-1, j, 1, 0}));
        }
        int ans = 1<<30;
        while(!pq.empty()){
            data d = pq.top();  pq.pop();
            int i = d.i, j = d.j, lr = d.lr, cost = d.cost;
            if(dp[lr][i][j] <= cost)    continue;
            dp[lr][i][j] = cost;
            if(mat[i][j] == 'T'){
                ans = min(ans, dp[lr][i][j]);
                continue;
            }
            for(int k = 0; k < 9; k++){
                int ni = i+di[k], nj = j + (2*lr-1)*dj[k];
                if(inRange(ni,0,h)&&inRange(nj,0,w)&&mat[ni][nj]!='X'&&mat[ni][nj]!='S'){
                    int ncost = cost;
                    if(mat[ni][nj] != 'T')  ncost += mat[ni][nj]-'0';
                    if(dp[1-lr][ni][nj] > ncost){
                        pq.push(data({ni,nj,1-lr,ncost}));
                    }
                }
            }
        }
        if(ans == 1<<30)    ans = -1;
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 3128
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
char str[200005],res[200005];
int main()
{
    ll a,b,c,d,e,f=0,i,j,r,p,s;
    cin>>a>>b>>r>>s>>p;
    getchar();
    gets(str);
    for(i=0; i<strlen(str); i++)
    {
        if(str[i]=='r')
            res[i]='p';
        else if(str[i]=='s')
            res[i]='r';
        else if(str[i]=='p')
            res[i]='s';
        if(i>=b)
        {
            if(res[i-b]==res[i])
                res[i]='0';
        }
        if(res[i]=='r')
            f+=r;
        else if(res[i]=='s')
            f+=s;
        else if(res[i]=='p')
            f+=p;
    }
    cout<<f<<endl;

}


Measured memory_bytes: 384
#pragma region _head

#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<map>
#include<set>
#include<iomanip>
#include<queue>
#include<stack>
#include<numeric>
#include<utility>
#include<regex>

void Init() {
	std::cin.tie(0); std::ios::sync_with_stdio(false);
	struct Init_caller { Init_caller() { Init(); } }caller;
}

#pragma region _define

#define int LL
#define f(i,a,b) for(LL i=a;i<b;i++)
#define f_vI(v,n) f(i,0,n)cin>>v[i]
#define f_v2I(v1,v2,n) f(i,0,n)cin>>v1[i]>>v2[i]
#define f_v3I(v1,v2,v3,n) f(i,0,n)cin>>v1[i]>>v2[i]>>v3[i]
#define f_vO(v,n) f(i,0,n)cout<<v[i]<<endl
#define ei else if
#define all(a) a.begin(),a.end()
#define size(s) ((LL)s.size())
#define F first
#define S second
#define check() cout<<"! ! !"
#define endl "\n"
#define _y() cout<<"Yes"<<endl
#define _Y() cout<<"YES"<<endl
#define _n() cout<<"No"<<endl
#define _N() cout<<"NO"<<endl
#define int_INF 1<<29
#define ll_INF 1LL<<60
#define MOD 1000000007

#pragma endregion

#pragma region _using

using namespace std;

using LL = long long;
using st = string;
using vi = vector<LL>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vd = vector<double>;
using vvd = vector<vd>;
using vvvd = vector<vvd>;
using vc = vector<char>;
using vvc = vector<vc>;
using vs = vector<st>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvvb = vector<vvb>;
using qi = queue<LL>;
using qc = queue<char>;
using qs = queue<st>;
using si = stack<LL>;
using sc = stack<char>;
using ss = stack<st>;
using pi = pair<LL, LL>;
using ppi = pair<pi, LL>;
using mll = map<LL, LL>;
using mcl = map<char, LL>;
using vpi = vector<pi>;
using vppi = vector<ppi>;

#pragma endregion

struct edge {
	int from, to, cost;
};

void y_n(bool p) {
	p ? _y() : _n();
}

void Y_N(bool p) {
	p ? _Y() : _N();
}

LL gcd(LL a, LL b) {
	LL r;
	while ((r = a % b) != 0) {
		a = b;
		b = r;
	}
	return b;
}
LL lcm(LL a, LL b) {
	return (a / gcd(a, b) * b);
}

//素数判定
bool is_prime(int n) {
	for (int i = 2; i*i <= n; i++) {
		if (n % i == 0) {
			return false;
		}
	}
	return true;
}

//階乗計算
LL factorial(LL n) {
	LL a = 1, ret = 1;
	while (a < n) {
		a++;
		ret *= a;
		ret %= MOD;
	}
	return ret;
}


#pragma endregion 


/*****************************************************************************/
signed main(void) {
	st s;
	cin >> s;
	int ans = 0;
	f(i, 1, size(s)) {
		if (i+1<size(s)&&s[i] == s[i - 1] && s[i] == s[i + 1]) {
			if (s[i] == '0') {
				s[i] = '1';
			}
			else {
				s[i] = '0';
			}ans++;
			i++;
			continue;
		}
		if (s[i] == s[i - 1]) {
			if (s[i] == '0') {
				s[i] = '1';
			}
			else {
				s[i] = '0';
			}
			ans++;
		}
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 512
PROGRAM predictionAndRestriction
      IMPLICIT NONE
      integer,parameter :: prec = 8
      integer(prec) :: n,rsp(0:2),k, ans=0
      character(10**5) :: t
      integer(prec) :: i,j, used(10**5),best,tt(10**5)
      
      read*,n,k
      read*,rsp(0:2)
      read*,t
      
      do i = 1,n
        select case( t(i:i) )
        case( 'r' )
          tt(i) = 6
        case( 's' )
          tt(i) = 7
        case( 'p' )
          tt(i) = 8
        end select
      end do
      
        do j = 1,n
          best = mod( tt(j)-1,3 )
          
          if( j-k<=0 )then
            used(j) = best
            ans = ans + rsp( best )
            cycle
          end if
          
          if( best==used(j-k) )then
            if( j+k<=n )then
              used(j) = mod(tt(j+k),3)
            else
              used(j) = mod(best+1,3)
            end if
          else
            used(j) = best
            ans = ans + rsp( best )
          end if
          
        end do
      
      print*,ans
      stop
      
      
      do i = 1,n
        select case( used(i) )
        case(0)
          t(i:i) = 'r'
        case(1)
          t(i:i) = 's'
        case(2)
          t(i:i) = 'p'
        end select
      end do
      print*,t(1:n)
      
      END PROGRAM

Measured memory_bytes: 2084
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <bitset>
#include <math.h>
#include <iomanip>
#include <queue>
#define inp(X) cin >> X
#define out(X) cout << X << endl
#define out16(X) cout << setprecision(16) << X << endl
#define rep(i,n) for(int i=0;i<n;i++ )
#define rep2(i,f,n) for(int i=f;i<n;i++ )
#define MAX(A) *max_element(A.begin(),A.end())
#define MIN(A) *min_element(A.begin(),A.end())
#define SORT(A) sort(A.begin(),A.end())
typedef long long int ll;
using vi = std::vector<int>;

using namespace std;

#define MOD 1000000007
#define INF 1000000001

ll gcd(ll x, ll y){
	if(y==0) return x;
	return gcd(y,x%y);
}

bool bfs(vector<vector<int>> g, vector<int> &dist, int sv)
{
	queue<int> q;
	q.push(sv);
	dist[sv]=0;
	while(!q.empty()){
		int now = q.front(); q.pop();
		for(auto v : g[now]){
			if(dist[v]!=-1) continue;
			dist[v] = dist[now]+1;
			q.push(v);
		}
	}
}

int main(void) {
	int n,k; cin >> n >> k;
	vi a(n); rep(i,n) cin >> a[i];
	vector<bool> dp(k+1,false);//残りi個で順番が来た時の勝敗 true:勝ち false:負け
	rep2(r,1,k+1)rep(i,n)
		dp[r] = a[i]<=r ? ( dp[r] || !dp[r-a[i]] ) : dp[r];
	if(dp[k]) out("First");
	else out("Second");
}




Measured memory_bytes: 256
from sys import stdin
def main():
    input = stdin.readline
    h, w = map(int, input().split())

    def banpei_grid(H,W):
       S = ["#" * (W + 2)]
       for i in range(H):
           S += ["#" + input()+ "#"]
       S += ["#" * (W + 2)]
       return S
       
    s = banpei_grid(h, w)

    from itertools import product
    for i, j in product(range(h), range(w)):
        ss = s[i][j]
        if ss == "#":
            if s[i+1][j] == "#":
                continue
            elif s[i][j+1] == "#":
                continue
            elif s[i-1][j] == "#":
                continue
            elif s[i][j-1] == "#":
                continue

            else:
                print("No")
                exit()
    else:
        print("Yes")


if __name__ == '__main__':
    main()

Measured memory_bytes: 38896
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<queue>
#include<map>
#include<stack>
#include<set>
#include<cstdlib>

using namespace std;

#define LL long long
const int inf = 0x3f3f3f3f;
const int maxn = 1e5 + 5;
int n;
void ex_gcd(LL a, LL b, LL &d, LL &x, LL &y) {
  if (!b) {
    d = a, x = 1, y = 0;
  } else {
    ex_gcd(b, a % b, d, y, x);
    y -= x * (a / b);
  }
}
LL ex_crt(LL *m, LL *r, int n) {
  LL M = m[1], R = r[1], x, y, d;
  for (int i = 2; i <= n; ++i) {
    ex_gcd(M, m[i], d, x, y);
    if ((r[i] - R) % d)
      return -1;
    x = (r[i] - R) / d * x % (m[i] / d);
    R += x * M;
    M = M / d * m[i];
    R %= M;
  }
  return R > 0 ? R : R + M;
}
LL m[maxn], r[maxn];
LL lcm(LL a,LL b){
  return a/__gcd(a,b)*b;
}
int main() {
  int M;
  while (~scanf("%d%d",&n,&M)) {
    LL X=1,y=1;
    for (int i = 1; i <= n; ++i){
      scanf("%lld", &m[i]);
      X=lcm(X,m[i]);
    }
    for(int i=1;i<=n;i++){
      r[i]=m[i]/2;
      y=lcm(y,r[i]);
    }
    LL x=ex_crt(m,r,n);
    if(x==-1||x>M){
      cout<<0<<endl;
    }else{
      cout<<1+(M-x)/X<<endl;
    }
  }
  return 0;
}



Measured memory_bytes: 1792