akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <numeric>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

#define rep(i, N) for(int i = 0; i < N; ++i)

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

#define IN(l, r, x) ((l) <= (x) && (x) < (r))

using P = pair< int, int >;

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

    int n;
    cin >> n;

    s64 a[n][n];
    priority_queue< pair<s64, P>, vector< pair<s64, P> >, greater< pair<s64, P> > > pq;
    rep (i, n) rep (j, n)
    {
        cin >> a[i][j];
        pq.push(make_pair(a[i][j], P{i, j}));
    }

    s64 d[n][n];
    const s64 inf = 1e18;
    rep (i, n) for (int j = i + 1; j < n; ++j) d[i][j] = d[j][i] = inf;
    rep (i, n) d[i][i] = 0;

    s64 ans = 0;
    while (!pq.empty())
    {
        auto p = pq.top(); pq.pop();
        int from = p.second.first;
        int to = p.second.second;
        s64 cost = p.first;
        bool found = true;
        rep (i, n)
        {
            if (i == from || i == to) continue;
            if (d[from][i] + d[i][to] == cost)
            {
                found = false;
            }
            else if (d[from][i] + d[i][to] < cost)
            {
                cout << "-1\n";
                return 0;
            }
            else
            {
                d[from][to] = cost;
                d[to][from] = cost;
            }
        }
        if (found) ans += cost;
    }

    cout << ans / 2 << "\n";
    return 0;
}



Measured memory_bytes: 3184
#include <stdio.h>

#define MOD 2019

int main(void) {
  	int L, R, l, r, A, a;
    int c = 2018;
  	scanf("%d %d", &L, &R);
    if((R - L) >= 2019) {
        printf("0\n");
        return 0;
    }
    for (int i = L; i < R; i++) {
        for(int j = i + 1; j <= R; j++) {
            l = i % MOD;
            r = j % MOD;
            A = l * r;
            a = A % MOD;
            if (a < c) {
                c = a;
            }
        }
    }
    printf("%d", c);
    return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
int main(){
  int w,a,b,c=0;
  scanf("%d %d %d",&w,&a,&b);
  if(b-(a+w)<0&&a-(b+w)<0) printf("0");
  else if(b-(a+w)>a-(b+w)){
    printf("%d",b-(a+w));
  }
  else printf("%d",a-(b+w));
  return 0;
}

Measured memory_bytes: 128
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<string>
#include<complex>
#include<algorithm>
#include<vector>
#include<math.h>
#include<set>

int main()
{
	int x, y;
	scanf("%d%d", &x, &y);
	printf("%d\n", x + y / 2);

	return 0;
}

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

int main () {

  string s;
  cin >> s;
  int Odd = 0;
  if (s[0] == 'o') Odd +=100;
  if (s[1] == 'o') Odd +=100;
  if (s[2] == 'o') Odd +=100;
  cout << 700+Odd << endl;

  return 0;
}

Measured memory_bytes: 256
n=int(input())

l=[[[0]*10 for i in range(3)]for k in range(4)]

for m in range(n):
    house,floor,room,mem=map(int,input().split())
    
    l[house-1][floor-1][room-1]+=mem
    
for o in range(4):
    if o is not 0:
        print("####################")
    for p in range(3):
        for q in range(10):
            print(" %d"%(l[o][p][q]),end = "")
        print()


Measured memory_bytes: 5620
a, b, k = gets.chomp.split(" ").map(&:to_i)

numbers = []
for i in 1..[a, b].min
  if (a % i == 0 && b % i == 0)
    numbers.push(i)
  end
end
numbers.sort! {|a, b| b <=> a }
print("#{numbers[k-1]}\n")

Measured memory_bytes: 1788
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
#include <vector>

#include <cstring>
#include <set>
#include <map>
#include <queue>
#include <utility>

using namespace std;

typedef long long LL;

#define dump(c) { for (auto it = c.begin(); it != c.end(); ++it) if (it == c.begin()) cout << *it; else cout << ' ' << *it; cout << endl; } 


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

    vector<int> B(N-1);
    for (int i = 0; i < N-1; ++i) {
        cin >> B[i];
    }


    vector<int> A(N);
    A[0] = B[0];
    A[N-1] = B[N-2];
    LL ans = A[0] + A[N-1];

    for (int i = 1; i < N-1; ++i) {
        A[i] = min(B[i-1], B[i]);
        ans += A[i];
    }

    cout << ans << endl;

    return 0;
}


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

int main() {
    string s, t;
    cin >> s >> t;
    reverse(s.begin(), s.end());
    reverse(t.begin(), t.end());
    string ans = "";
    bool judge = false;
    for (int i = 0; i < s.size(); i++) {
        string tmp = s.substr(i, t.size());
        bool check = true;
        for (int j = 0; j < t.size(); j++) {
            if (tmp[j] != t[j] && tmp[j] != '?') {
                check = false;
                break;
            }
        }
        if (check) {
            string back = s.substr(0, i);
            string front = s.substr(i + t.size(), s.size());
            ans = back + t + front;
            judge = true;
            break;
        }
    }
    for (int i = 0; i < s.size(); i++) {
        if (ans[i] == '?') ans[i] = 'a';
    }
    reverse(ans.begin(), ans.end());
    cout << (judge ? ans : "UNRESTORABLE") << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
using namespace std;
int main(){
  int a,b,c;
  cin >> a >> b >> c;
  if(a+b+c>21) cout << "bust";
  else cout << "win";
  
  return 0;
}

Measured memory_bytes: 256
#include<queue>
#include<stack>
#include<math.h>
#include<cmath>
#include<bitset>
#include<stdio.h>
#include<string>
#include<map>
#include<algorithm>
#include<vector>
#include<iostream>
#include<utility>
#include<functional>
#include<deque>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int main(){
  ll p,q,x,y,a,v,b,w,t;
  cin >> a >> v >> b >> w >> t;
  x=a+t*v,y=b+t*w;
  p=a-t*v,q=b-t*w;
  if(a>b && p<=q){
    printf("YES\n");
    return 0;
  }
  else if(a<b  && x>=y){
    printf("YES\n");
    return 0;
  }
  else{
    printf("NO\n");
  }
  return 0;
}

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

using namespace std;

typedef long long ll;

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

	string x, y;
	cin >> x >> y;

	if(x > y){
		cout << ">" << endl;
	}else if(x == y){
		cout << "=" << endl;
	}else{
		cout << "<" << endl;
	}
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<deque>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const int inf=1e9+7;
const ll INF=1LL<<60 ;
const ll mod=1e9+7 ;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
#define debug(x)  cout << #x << " = " << (x) << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
//#define int long long

void swp(int& a, int i, int j) {
    int bi = (a>>i) & 1, bj = (a>>j) & 1;
    a -= (bi << i) + (bj << j);
    a += (bi << j) + (bj << i);
}

//0 ~ n - 1 bit目に着目
vector<int> resolve(int n, int a, int b) {
    if(n == 1) {
        return {a, b};
    }
    int exchange = n - 1;
    for(int k = 0; k <= n - 1; ++k) {
        if(((a>>k) & 1) != ((b>>k) & 1)) {
            exchange = k;
            break;
        }
    }
    swp(a, exchange, n - 1);
    swp(b, exchange, n - 1);
    int c = a ^ 1; // n >= 2
    int d = c ^ (1<<(n - 1));
    auto zenhan = resolve(n - 1, a, c);
    auto kohan = resolve(n - 1, d, b);
    vector<int> res;
    for(auto& v: zenhan) {
        res.push_back(v);
    }
    for(auto& v: kohan) {
        res.push_back(v);
    }
    for(auto& v: res) {
        swp(v, exchange, n - 1);
    }
    return res; 
}

void solve() {
	int n, a, b; cin >> n >> a >> b;
    int bitcnt = 0;
    rep(i, 17) {
        if(((a>>i) & 1) != ((b>>i) & 1)) bitcnt ++;
    }
    if(bitcnt % 2 == 0) {
        cout << "NO" << endl;
    } else {
        cout << "YES" << endl;
        auto ans = resolve(n, a, b);
        for(auto& v: ans) {
            cout << v << " ";
        }
        cout << endl;
    }
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//init();
	solve();
	//cout << "finish" << endl;
    return 0;
}


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

typedef pair<int,int>   II;
typedef vector< II >      VII;
typedef vector<int>     VI;
typedef vector< VI > 	VVI;
typedef long long int 	LL;
typedef unsigned long long int ULL;

#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(a) (int)(a.size())
#define ALL(a) a.begin(),a.end()
#define SET(a,b) memset(a,b,sizeof(a))
#define LET(x,a) __typeof(a) x(a)

#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
//Works for forward as well as backward iteration

#define gu getchar
#define pu putchar
#define si(n) scanf("%d",&n)
#define dout(n) printf("%d\n",n)
#define sll(n) scanf("%lld",&n)
#define lldout(n) printf("%lld\n",n)

#define DRT() int t; si(t); while(t--)

#define PlUSWRAP(index,n) index = (index+1)%n		//index++; if(index>=n) index=0
#define MINUSWRAP(index,n) index = (index + n -1)%n 	//index--; if(index<0) index=n-1
#define ROUNDOFFINT(d) d = (int)((double)d + 0.5)	//Round off d to nearest integer

#define FLUSHN while(gu()!='\n')
#define FLUSHS while(gu()!=' ')

#define TRACE

#ifdef TRACE
#define trace1(x)                cerr << #x << ": " << x << endl;
#define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
#define trace4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;
#define trace5(a, b, c, d, e)    cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl;
#define trace6(a, b, c, d, e, f) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl;

#else

#define trace1(x)
#define trace2(x, y)
#define trace3(x, y, z)
#define trace4(a, b, c, d)
#define trace5(a, b, c, d, e)
#define trace6(a, b, c, d, e, f)

#endif

#define off ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)


int main()
{
	//  #ifndef ONLINE_JUDGE
 //    freopen("input.txt", "r", stdin);
 //    freopen("output.txt", "w", stdout);
	// #endif
  LL n,x;
  cin>>n>>x;
  vector<LL> l(n);
  for(LL i=0;i<n;i++)
  {
    cin>>l[i];
  }
  LL sum=0;
  LL ind=0;
  // while(sum <= x)
  // {
  //   sum = sum + l[ind];
  //   ind++;
  // }
  vector<LL> cum(n+1);
  cum[0]=0;
  rep(i,1,n+1)
  cum[i]=cum[i-1]+l[i-1];
  auto it = lower_bound(cum.begin(),cum.end(), x);
  LL ans = it-cum.begin();
  if(cum[ans] == x)
  	ans++;
  cout<<ans;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>

int main(void) {
  int A[3];
  int N, i = 0;
  int a, b, c;
  int max;

  scanf("%d", &N);

  while(i++ < N) {
    scanf("%d %d %d", &a, &b, &c);

    if(a > b) {
      A[2] = b;
      if(a > c) {
        A[0] = a;
        A[1] = c;
      }
      else {
        A[0] = c;
        A[1] = a;
      }
    }
    else {
      A[2] = a;
      if(b > c) {
        A[0] = b;
        A[1] = c;
      }
      else {
        A[0] = c;
        A[1] = b;
      }
    }

    if(pow(A[0], 2) == pow(A[1], 2) + pow(A[2], 2)) {
      printf("YES\n");
    }
    else printf("NO\n");
  }

  return 0;
}



Measured memory_bytes: 2044
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>

using namespace std;

#define square(s) (s)*(s)
#define scast(type,e) static_cast<type>(e)
#define rep(i,n) for(int i = 0; i < n;i++)
#define range(a) a.begin(),a.end()


template<class T>
using vec = vector<T>;
using ll = long long;
using ull = unsigned long long;

constexpr ll mod = 1000000007;

int main() {
	int r;
	cin >> r;
	cout << 3 * r * r << endl;

	return 0;
}

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

int main(){
  // input
  ll n, m;
  cin >> n >> m;

  // distribute each prefecture
  vector<vector<ll>> r(100010);
  vector<ll> p(m), y(m);
  rep(i, 0, m){
    cin >> p[i] >> y[i];
    r[p[i]].push_back(y[i]);
  }
  
  // in prefecture, x set
  map<ll, bool> seen;
  vector<map<ll, ll>> o(100010); // o[prefecture][year] 
  for(auto t : p){
    if(seen[t]) continue;
    seen[t] = true;
    sort(r[t].begin(), r[t].end());
    rep(i, 0, r[t].size()){
        o[t][r[t][i]] = i + 1;  
    }
  }

  rep(i, 0, m){
    string s = to_string(p[i]);
    // front id
    ll lm = s.size();
    rep(j, 0, 6-lm){
        s = "0" + s;
    }
    // back id
    ll ty = o[p[i]][y[i]];
    string ss = to_string(ty);
    lm = ss.size();
    rep(j, 0, 6-lm){
        ss = "0" + ss;
    }
    cout << s + ss << endl;
  }

  return 0;
}


Measured memory_bytes: 27308
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll mod2 = 998244353;
const ll INF = 1e18;
const long double EPS = 1e-10;

int main() {
  int n, a, b;
  cin >> n >> a >> b;

  cout << min(a * n, b) << endl;


  
  return 0;
}

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

using namespace std;

int main() {
    std::ios::sync_with_stdio(false); 
    cin.tie(nullptr);
    
    int N, W;
    cin >> N >> W;
    vector<int> w(N), v(N);
    for (int i = 0; i < N; ++i) {
        cin >> w[i] >> v[i];
    }

    vector<long long> dp(W + 1, 0);
    for (int i = 0; i < N; ++i) {
        for (int j = W - w[i]; j >= 0; --j) {
            dp[j + w[i]] = max(dp[j + w[i]], dp[j] + v[i]);
        }
    }
    cout << *max_element(begin(dp), end(dp)) << "\n";
    return 0;
}

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

#define int long long

int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};
int A, B;
bool m[100][100];

signed main() {
    cin >> A >> B;
    for (int i = 0; i < 100; i++) {
        for (int j = 0; j < 50; j++) {
            m[i][j] = true;
        }
    }
    for (int i = 0; i < A - 1; i++) {
        m[i % 50 * 2 + 1][i / 50 * 2 + 1] = false;
    }
    for (int i = 0; i < B - 1; i++) {
        m[i % 50 * 2 + 1][i / 50 * 2 + 51] = true;
    }
    cout << 100 << " " << 100 << endl;
    for (int i = 0; i < 100; i++) {
        for (int j = 0; j < 100; j++) {
            if (m[i][j]) {
                cout << "#";
            } else {
                cout << ".";
            }
        }
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
typedef long long ll;
typedef long double ld;

int main(){
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
   	ll n,w;
   	cin >> n >> w;
   	vector <vector<ll>> dp(n,vector<ll>(w+1,0));
   	vector <pair<ll,ll>> arr(n);
   	for (int z=0;z<n;z++){
   		cin >> arr[z].first >> arr[z].second;
   	}
   	for (int z=0;z<=w;z++){
   		if (z >= arr[0].first){
   			dp[0][z] = arr[0].second;
   		}
   	}
   	for (int z=1;z<n;z++){
   		for (int x=0;x<=w;x++){
   			if (x-arr[z].first < 0){
   				dp[z][x] = dp[z-1][x];
   			} else 
   			dp[z][x] = max(dp[z-1][x],dp[z-1][x-arr[z].first]+arr[z].second);
   		} 
   	}
   	cout << dp[n-1][w] << endl;
   	cin >> n;
}


Measured memory_bytes: 79488
N, M = list(map(int, input().split()))

brk_stair = [1] * (N + 1)
dp = [0] * (N + 1)

for _ in range(M):
    brk_stair[int(input())] = 0

#print(brk_stair)

dp[0] = 1
dp[1] = 1 * brk_stair[1]

for i in range(2, N + 1):
    dp[i] = (dp[i - 1] + dp[i-2]) * brk_stair[i]

print(dp[-1] % 1000000007)


Measured memory_bytes: 463476
#include <iostream>
#include <queue>
#include <vector>

using namespace std;

struct edge{int to, cost;};
typedef pair<long, int> P;
const long INF = (long)1e15;

vector<edge> G_y[100000];
vector<edge> G_s[100000];

long d_y[100000];
long d_s[100000];

void dijkstra(int s, long d[], vector<edge>G[]){
    priority_queue<P, vector<P>, greater<P>> que;
    fill(d, d+100000, INF);
    d[s] = 0;
    que.push(P(0, s));
    while(!que.empty()){
        P p = que.top();que.pop();
        int v = p.second;
        if(d[v] < p.first) continue;
        for(int i = 0; i < G[v].size(); i++){
            edge e = G[v][i];
            if(d[v] + e.cost < d[e.to]){
                d[e.to] = d[v] + e.cost;
                que.push(P(d[e.to], e.to));
            }
        }
    }
}


int main(){
    int n, m, s, t;
    long money = (long)1e15;
    long ans[100001];
    cin >> n >> m >> s >> t;
    s--;t--;
    for(int i = 0; i < m; i++){
        int u, v, a, b;
        cin >> u >> v >> a >> b;
        u--;v--;
        G_y[u].push_back((edge){v, a});
        G_y[v].push_back((edge){u, a});
        G_s[u].push_back((edge){v, b});
        G_s[v].push_back((edge){u, b});
    }
    
    dijkstra(s, d_y, G_y);
    dijkstra(t, d_s, G_s);
    ans[n] = 0;
    for(int i = n-1; i >= 0; i--){
        ans[i] = max(ans[i+1], money-(d_y[i]+d_s[i]));
    }
    for(int i = 0; i < n; i++){
        cout << ans[i] << endl;
    }
}

Measured memory_bytes: 16252
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  
  int answer=0;
  for (int i=1; i <= n; i++){
    if(i%2 == 0){continue;}
    int yakusuu=0;
    for(int j=1 ; j <= i; j++){
      
      if(i%j == 0){yakusuu++;}
      if (i==j && yakusuu == 8){answer++;}
    }
    
  }
  cout << answer << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <cmath>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <iostream>
#include <random>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include <fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;

using ll = long long;
using vll = vector<ll>;
using pll = pair<ll, ll>;
using qll = queue<ll>;
using vb = vector<bool>;
using mll = map<ll, ll>;
using sll = stack<ll>;
#define REP(i,n) for(ll i(0);(i)<(n);(i)++)
#define rep(i,n) for(ll i(0);(i)<(n);(i)++)
#define ALL(a) a.begin(), a.end()
#define elnd endl //* missspell check


void solve(std::string s, std::string t){
    vector<vll> a(26);
    REP(i, s.length()){
        //* a[i] is already sorted
        a[s[i]-'a'].push_back(i); 
    }
    
    ll pt=0; ll cnt = 0;
    REP(i, t.length()){
        ll x = t[i]-'a';
        if(a[x].size()==0){
            cout << -1 << endl;
            return;
        }
        ll pos = lower_bound(ALL(a[x]), pt) - a[x].begin();
        if(pos < a[x].size()){
            pt = a[x][pos] + 1;
        }
        else{ //* no valid >= pt
            pt = a[x][0]+1;
            cnt++;
        }
    }
    cout << cnt*s.length()+pt << endl;
}

int main(){
    std::string s;
    std::cin >> s;
    std::string t;
    std::cin >> t;
    solve(s, t);
    return 0;
}


Measured memory_bytes: 1712
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <numeric>

using namespace std;
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define reppe(i,a,b) for(int i = (int)(a) ; i <= (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)
#define repme(i,a,b) for(int i = (int)(a) ; i >= (int)(b) ; --i)

typedef long long ll;

long long GCD(long long a, long long b){if(b==0)return a;return GCD(b,a%b);}

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

    ll dp[110][2][100];
    fill( ( long long * )dp, ( long long * )dp + sizeof( dp ) / sizeof( long long ), 0 );
    dp[0][0][0] = 1;
    int L = S.size();

    repp(i,0,L) {
        int D = S[i] - '0';
        repp(j,0,2) {
            repp(k, 0, 100) {
                reppe(d, 0, (j ? 9 : D)) {
                    if (d == 0) dp[i + 1][j || (d < D)][k] += dp[i][j][k]; 
                    else dp[i + 1][j || (d < D)][k + 1] += dp[i][j][k];
                }
            }
        }
    }
    cout << dp[L][0][K] + dp[L][1][K] << endl;
}



Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <random>
#include <chrono>
#include <queue>
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
#define INF 1000000000
#define MOD 1000000007
#define EPS 0.00000001


int main (){
    int Q, H, S, D; cin >> Q >> H >> S >> D;
    int N; cin >> N;
    
    int mn2 = min(8*Q, min(4*H, min(2*S, D)));
    int mn1 = min(4*Q, min(2*H, S));
    cout << (ll)N/2 * mn2 + N%2 * mn1 << endl;

    return 0;
}



Measured memory_bytes: 256
#include <stdio.h>
#define _USE_MATH_DEFINES
#include <math.h>

double heron(double x , double y , double x1 , double y1 , double x2 , double y2){
	double d1 , d2 , d3 , s;
	d1 = sqrt(pow(x-x1 , 2) + pow(y-y1 , 2));
	d2 = sqrt(pow(x1-x2 , 2) + pow(y1-y2 , 2));
	d3 = sqrt(pow(x2-x , 2) + pow(y2-y , 2));
	s = (d1 + d2 + d3) / 2;
	return sqrt(s * (s - d1) * (s - d2) * (s - d3));	
}

int main(void){
	double x1 , y1 , x2 , y2 , x3 , y3 , xp , yp , area_1 , area_2 , area_3 , area_p;
	while(scanf("%lf %lf %lf %lf %lf %lf %lf %lf" , &x1 , &y1 , &x2 , &y2 , &x3 , &y3 , &xp , &yp)!=EOF){
		area_1 = heron(x1 , y1 , x2 , y2 , xp , yp);
		area_2 = heron(x2 , y2 , x3 , y3 , xp , yp);
		area_3 = heron(x3 , y3 , x1 , y1 , xp , yp);
		area_p = heron(x1 , y1 , x2 , y2 , x3 , y3);
		if(fabs(area_p - (area_1 + area_2 + area_3)) < 0.000001) printf("YES\n");
		else printf("NO\n");
	}
return 0;
}

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

using namespace std;


int main(){

    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);

    int n;
    cin>>n;
    set<string> s;
    for (int i=0; i<n; i++){
        string curr;
        cin>>curr;
        s.insert(curr);
    }
    cout<<s.size();
}

Measured memory_bytes: 19204
#include<bits/stdc++.h>
using namespace std;
const int maxn=100010;
int dp[maxn][3]={0};
int A[maxn][3];
int main(){
	int n;
	scanf("%d",&n); 
	for(int i=0;i<n;i++){
		scanf("%d%d%d",&A[i][0],&A[i][1],&A[i][2]);
	}
	dp[0][0]=A[0][0];
	dp[0][1]=A[0][1];
	dp[0][2]=A[0][2];
	for(int i=1;i<n;i++){
		dp[i][0]=max(dp[i-1][1],dp[i-1][2])+A[i][0];
		dp[i][1]=max(dp[i-1][0],dp[i-1][2])+A[i][1];
		dp[i][2]=max(dp[i-1][0],dp[i-1][1])+A[i][2];
		
	}
	int temp=dp[n-1][0];
	if(temp<dp[n-1][1])	temp=dp[n-1][1];
	if(temp<dp[n-1][2])	temp=dp[n-1][2];
	printf("%d",temp);
	return 0;
}

Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
#define lli long long int
#define mod 1000000007
#define M 100005
#define rep(i,a,b) for(lli i=a;i<b;i++)
#define pii pair<lli,lli> 
#define Itr vector<lli> :: iterator
void fast()
{
	std::ios_base::sync_with_stdio(false);
	cin.tie(0);
}

lli a[M] ; 
void solve(lli n)
{
	lli ans=0,sum=0,ctr=0;
	sort(a,a+n);
	lli l=0,r=n-1;
	for(lli i=n-1;i>=1;i--)
	{
		l = 0 , r=i-1;
		while(l<r)
		{
			if(a[l]+a[r]>a[i])
			{
				ctr+=(r-l);
				r--;
			}
			else
				l++;
		}
	}
	cout<<ctr<<"\n";
}
int main()
{
	fast();
	lli t,n;
	t=1;
	while(t--)
	{
		cin>>n;
		rep(i,0,n)cin>>a[i];
		lli ans = 0;
		solve(n); 
	}
return 0;
}

Measured memory_bytes: 256
s = int(input())
A = []
A.append(s)
for i in range(2, 1000001):
  if s % 2 == 0:
    s = int(s / 2)
  else:
    s = 3 * s + 1
  if s in A:
    print(i)
    exit()
  else:
    A.append(s)

Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

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

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

  if (m == 1) {
    cout << "IMPOSSIBLE" << endl;
    return 0;
  }

  vector<vector<int>> vp(n + 1);
  rep(i, 0, m) {
    int a, b;
    cin >> a >> b;
    vp[a].push_back(b);
  }

  for (auto v : vp[1]) {
    for (auto x : vp[v]) {
      if (x == n) {
        cout << "POSSIBLE" << endl;
        return 0;
      }
    }
  }
  cout << "IMPOSSIBLE" << endl;
}


Measured memory_bytes: 8576
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll cnt[100010];
vector<ll> b;
int main() {
    int n,f=1;
    cin>>n;
    for(int i=0;i<n;i++){
        ll k;
        cin>>k;
        cnt[k]++;
        if(cnt[k]==1)
            b.push_back(k);
        if(i!=0&&k==0)
            f=0;
    }
    sort(b.begin(),b.end());
    ll ans=1;
    for(int i=0;i<=n;i++){
        for(int j=0;j<cnt[i+1];j++){
            ans*=cnt[i];
            ans%=998244353;
        }
    }
    if(!f)
        cout<<'0';
    else 
    cout<<ans;


}

Measured memory_bytes: 2168
import java.util.*;

public class Main {
	void solve() {
		Scanner scan = new Scanner(System.in);
		int a = scan.nextInt();
		int b = scan.nextInt();
		int n = scan.nextInt();
		int[] s = new int[n];
		int[] f = new int[n];
		int out = 0;
		for(int i = 0; i < n; i++) {
			s[i] = scan.nextInt();
			f[i] = scan.nextInt();
			if(a < f[i] && b > s[i]) out = 1;
		}
		System.out.println(out);
		scan.close();
	}
	
	public static void main(String[] args) {
		new Main().solve();
	}
}



Measured memory_bytes: 26584
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <cstdio>
#include <string>
#include <cmath>
#include <queue>
//#include <bits/stdc++.h>
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repr(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i,i0,n) for(int (i)=(i0);(i)<(n);(i)++)
#define FORR(i,i0,n) for(int (i)=(n)-1; (i)>=(i0);(i)--)
#define rn return
#define fi first
#define se second
typedef std::pair<int,int> P;
using namespace std;
using ll = long long;



int main(){
    
    int N, A,B;
    cin >> N >> A >> B;
    vector<int> X(N);
    rep(i,N) cin >> X[i];
    ll ans = 0;
    FOR(i,0,N-1) 
        ans += min((ll)(X[i+1]-X[i])*A,(ll) B);
    cout << ans;
    rn 0;
}

Measured memory_bytes: 640
package main

import (
	"fmt"
)

func main() {
	mod := 1000000007
	var n int
	fmt.Scanf("%d", &n)
	arr := make([]int, n, n)
	b := make([]int, n+1, n+1)
	for i := 0; i < n; i++ {
		fmt.Scanf("%d", &arr[i])
		b[i+1] = b[i] + arr[i]
	}

	var ans int
	for i := 0; i < n-1; i++ {
		sum := (b[n] - b[i+1]) % mod
		ans += arr[i] * sum
		ans %= mod
	}
	fmt.Println(ans)
}


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

using namespace std;

long long gcd(long long i, long long j) {

	//ユークリッドの互除法で最大公約数を求める
	//2変数の場合

	if (i < j) { swap(i, j); }

	while (i%j != 0) {
		long long r;
		r = i % j;
		if (r == 0) { return j; }
		else { i = j; j = r; }
	}
	return j;
}

long long lcm(vector<long long> &a,int n) {

	//2変数のlcmはa*b/gcdこれを繰り返す

	long long i1 = a[0];
	long long i2 = a[1];
	long long tlcm = (i1 / gcd(i1, i2))*i2;

	for (int i = 2; i < n; i++) {
		tlcm = (a[i] / gcd(a[i], tlcm))*tlcm;
	}
	return tlcm;
}

int main() {

	int n;
	cin >> n;
	long long i0;
	if (n == 1) { cin >> i0; cout << i0 << endl; return 0; }

	vector<long long> a(n,0);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}

	long long lcmout = lcm(a,n);

	cout << lcmout << endl;
}

Measured memory_bytes: 256
n, X = map(int, input().split())
x = list(map(int, input().split()))
rec = []
for i in range(n):
    rec.append(abs(X - x[i]))


def gcd(a, b):
    if b == 0:
        return a
    else:
        return gcd(b, a % b)


rec = sorted(rec)
gc =  rec[0]
for i in range(1, n):
    gc = gcd(rec[i], gc)

print(gc)


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

#define MAXN 123456
#define f first
#define s second
#define debug(x) cout << "DEBUG: " << x << endl

int n, k, resp;

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

    int aux;
    while(n--){
        cin >> aux;
        if(aux>=k){
            resp++;
        }
    }
    cout << resp << endl;
}


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

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


int main()
{
	string S;
	cin>>S;
	int cnt=0;
	int sc=0;
	bool del=false;
	for(int i=0;i<S.length();i++)
	{
		if(S[i]=='T')
		{
			sc--;
		}
		if(S[i]=='S')
		{
			if(i!=0&&S[i-1]=='T')
			{
				if(sc<0)
				{
					cnt-=sc;
					sc=0;
				}
			}
			sc++;
		}
	}
	cnt+=sc;
	cout<<cnt<<endl;
}

Measured memory_bytes: 640
import collections

n = int(input())
v = list(map(int,input().split()))
v1 = v[::2]
v2 = v[1::2]
v1 = collections.Counter(v1)
v2 = collections.Counter(v2)
ans = 0
if v1.most_common()[0][0] == v2.most_common()[0][0]:
    if v1.most_common()[0][1] < v2.most_common()[0][1]:
        ans += n//2 - v2.most_common()[0][1]
        ans += n//2 - v1.most_common()[1][1]
        print(ans)
    elif v1.most_common()[0][1] > v2.most_common()[0][1]:
        ans += n//2 - v1.most_common()[0][1]
        ans += n//2 - v2.most_common()[0][1]
        print(ans)
    else:
        if v1.most_common()[0][1] == n//2:
            print(n//2)
        else:
            if v1.most_common()[1][1] > v2.most_common()[1][1]:
                ans += n//2 - v2.most_common()[0][1]
                ans += n//2 - v1.most_common()[1][1]
                print(ans)
            else:
                ans += n//2 - v1.most_common()[0][1]
                ans += n//2 - v2.most_common()[1][1]
                print(ans)
else:
    ans += n//2 - v1.most_common()[0][1]
    ans += n//2 - v2.most_common()[0][1]
    print(ans)


Measured memory_bytes: 18784
#include "bits/stdc++.h"
using namespace std;
#define fi first
#define se second

constexpr int MAXN = 1000 + 42;

int C[MAXN][MAXN];
int S[MAXN], P[MAXN];

int main() {
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  for (int i = 1; i <= N; i++) {
    for (int j = 0; j < N - 1; j++) {
      int a;
      cin >> a;
      C[i][j] = a;
    }
  }
  int K = 0, Q = N * (N - 1) / 2;
  vector<int> R(N);
  iota(R.begin(), R.end(), 1);
  while (Q) {
    if (R.empty()) {
      K = -1;
      break;
    }
    vector<int> T;
    for (int a : R) {
      int b = C[a][S[a]++];
      if (P[b] == a) {
        if (S[a] != N - 1) {
          T.push_back(a);
        }
        if (S[b] != N - 1) {
          T.push_back(b);
        }
        Q--;
      }
      P[a] = b;
    }
    K++;
    R = T;
  }
  cout << K << endl;

  return 0;
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int K;
    cin >> K;
    vector<long long> dp[11];
    vector<long long> ans;
    for (int i = 1; i < 10; i++)
    {
        dp[1].push_back(i);
        ans.push_back(i);
    }
    for (int i = 2; i < 11; i++)
    {
        for (auto &x : dp[i - 1])
        {
            int tmp = x % 10;
            if (tmp + 1 < 10)
            {
                dp[i].push_back(10 * x + tmp + 1);
            }
            if (tmp - 1 >= 0)
            {
                dp[i].push_back(10*x + tmp - 1);
            }
            dp[i].push_back(10 * x + tmp);
        }
        for (auto &x : dp[i])
        {
            ans.push_back(x);
        }
    }
    sort(ans.begin(), ans.end());
    cout << ans[K - 1] << endl;
}

Measured memory_bytes: 4976
package main

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

func main() {
	In := readLineInt()
	M, D := In[0], In[1]
	if M > D {
		fmt.Println(M - 1)
	} else {
		fmt.Println(min(M, D))
	}
}

/////////////////////////////////////////

func readLineInt() []int {
	result := make([]int, 0)
	for _, v := range strings.Split(readLine(), " ") {
		i, _ := strconv.Atoi(v)
		result = append(result, i)
	}
	return result
}

var reader = bufio.NewReaderSize(os.Stdin, 1e6)

func readLine() string {
	result := make([]byte, 0, 1e6)
	for {
		line, remains, e := reader.ReadLine()
		if e != nil {
			panic(e)
		}
		result = append(result, line...)
		if !remains {
			break
		}
	}
	return string(result)
}

func min(a ...int) int {
	result := int(^uint(0) >> 1)

	for _, i := range a {
		if result > i {
			result = i
		}
	}

	return result
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
using LL = long long;
const LL LINF = 1e18;
using namespace std;
#define COUT(v) cout<<(v)<<endl
#define CIN(n)  long long int(n);cin >> (n)
#define YES(n) cout<<((n)? "YES" : "NO")<<endl
#define Yes(n) cout<<((n)? "Yes" : "No")<<endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) <<endl

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

#define FOREACH(x,a) for(auto& (x) : (a) )

#define ALL(obj) (obj).begin(),(obj).end()

#define P pair<int,int>
#define V vector<int>
#define S set<int>
#define pb(v) push_back(v)
int main(){
    CIN(W);CIN(H);CIN(N);
    vector<vector<bool>> m;
    REP(w,H){
        vector<bool> l;
        REP(s,W){
            l.push_back(false);
        }
        m.push_back(l);
    }
    REP(a,N){
        CIN(X);CIN(Y);CIN(A);
        if(A==1){
            REP(a,H){
                REP(b,X){
                    m.at(a).at(b)=true;
                }
            }
        }
        if(A==2){
            REP(a,H){
                FOR(b,X,W){
                    m.at(a).at(b)=true;
                }
            }
        }
        if(A==3){
            REP(a,Y){
                REP(b,W){
                    m.at(a).at(b)=true;
                }
            }
        }
        if(A==4){
            FOR(a,Y,H){
                REP(b,W){
                    m.at(a).at(b)=true;
                }
            }
        }
    }
    int ans = 0;
    REP(a,H){
        REP(b,W){
            if(!m.at(a).at(b))ans++;
        }
    }
    COUT(ans);
    return 0;
}


Measured memory_bytes: 256
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.*;


public class Main {
    int N;
    private class Pair implements Comparable<Pair> {
        String s;
        int p;
        int index;
        public Pair(String s, int p, int index) {
            this.s = s;
            this.p = p;
            this.index = index;
        }

        public int compareTo(Pair other) {
            if (s.equals(other.s)) {
                return other.p - this.p;
            }
            return this.s.compareTo(other.s);
        }
    }
    private void solve() {
        N = nextInt();
        ArrayList<Pair> pairs = new ArrayList<>();
        for(int i = 0;i < N;i++) {
            pairs.add(new Pair(next(), nextInt(), i));
        }

        Collections.sort(pairs);

        for(Pair pair: pairs) {
            out.println(pair.index + 1);
        }
    }

    public static void main(String[] args) {
        out.flush();
        new Main().solve();
        out.close();
    }

    /* Input */
    private static final InputStream in = System.in;
    private static final PrintWriter out = new PrintWriter(System.out);
    private final byte[] buffer = new byte[4096];
    private int p = 0;
    private int buflen = 0;

    private boolean hasNextByte() {
        if (p < buflen)
            return true;
        p = 0;
        try {
            buflen = in.read(buffer);
        } catch (IOException e) {
            e.printStackTrace();
        }
        if (buflen <= 0)
            return false;
        return true;
    }

    public boolean hasNext() {
        while (hasNextByte() && !isPrint(buffer[p])) {
            p++;
        }
        return hasNextByte();
    }

    private boolean isPrint(int ch) {
        if (ch >= '!' && ch <= '~')
            return true;
        return false;
    }

    private int nextByte() {
        if (!hasNextByte())
            return -1;
        return buffer[p++];
    }

    public String next() {
        if (!hasNext())
            throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = -1;
        while (isPrint((b = nextByte()))) {
            sb.appendCodePoint(b);
        }
        return sb.toString();
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }

    public long nextLong() {
        return Long.parseLong(next());
    }

    public double nextDouble() {
        return Double.parseDouble(next());
    }
}


Measured memory_bytes: 22356
N = int(input())
cnt = 0
lenn = len(str(N))
for i in range(1, N+1):
    num = str(i)
    s = int(num[-1])
    e = int(num[0])
    if s != 0:
        if lenn == 1:
            cnt += 1
        elif lenn == 2:
            if s == e:
                cnt += 1
            if s * 10 + e <= N:
                cnt += 1
        else:
            if s == e:
                cnt += 1
            for k in range(2, lenn + 1):
                if k == lenn:
                    if s < int(str(N)[0]):
                        cnt += 10 ** (k-2)
                    elif s == int(str(N)[0]) and e <= int(str(N)[-1]):
                        cnt += int(str(N)[1:lenn-1]) + 1
                    elif s == int(str(N)[0]) and e > int(str(N)[-1]):
                        if int(str(N)[1:lenn-1]) >= 0:
                            cnt += int(str(N)[1:lenn-1])
                else:
                    cnt += 10 ** (k-2)
print(cnt)


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

int main()
{
    int x,y;
    cin >> x >> y;
    // x > y に入れ替え
    if(x < y){
        int tmp = x;
        x = y;
        y = tmp;
    }
    //cout << x << " " << y << endl;
    
    while(y != 0){
        int tmp = x;
        x = y;
        y = tmp%y;
        //cout << x << " " << y << endl;
    }
    cout << x << endl;
   
}


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

using namespace std;

int ans, n, m, k[10], s[10][10], p[10];

int main(){
	cin >> n >> m;
	for(int i = 0; i < m; ++i){
		cin >> k[i];
		for(int j = 0; j < k[i]; ++j){
			cin >> s[i][j];
		}
	}
	for(int i = 0; i < m; ++i) cin >> p[i];
	
	for(int bit = 0; bit < (1 << n); ++bit){
		int lights[m] = {0};
		bool on[m] = {false};
		bool isall = true;
		for(int i = 0; i < n; ++i){
			for(int j = 0; j < k[i]; ++j){
				lights[i] += bit&(1<<(s[i][j]-1))?1:0;
			}
		}
		for(int i = 0; i < m; ++i) if(lights[i]%2 != p[i]) isall = false;
		if(isall) ans++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
  int y, m, d;
  while (cin >> y >> m >> d) {
    if (1989 < y || (1989 == y && 108 <= m * 100 + d))
      cout << "heisei" << " " << y - 1988 << " " << m << " " << d << endl;
    else if (1926 < y || (y==1926 && 1225 <= m * 100 + d))
      cout << "showa" << " " << y - 1925 << " " << m << " " << d << endl;
    else if (1912 < y || (y==1912 && 730 <= m * 100 + d))
      cout << "taisho" << " " << y - 1911 << " " << m << " " << d << endl;
    else if (1868 < y || (y==1868 && 908 <= m * 100 + d))
      cout << "meiji" << " " << y - 1867 << " " << m << " " << d << endl;
    else
      cout << "pre-meiji" << endl;
  }
}


Measured memory_bytes: 3100
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a) (a).begin(),(a).end()
#define vi vector<int>
#define pb push_back
#define INF 999999999


int under(int dif,int m){
	int ret=0;
	while(ret+dif<=m)ret+=dif;
	return ret;
}

int lower(int dif,int m){
	int ret = 0;
	while(ret<m)ret+=dif;
	return ret;
}

int upper(int dif,int m){
	int ret = 0;
	while(ret<=m)ret+=dif;
	return ret;
}

int main(){
	int n,m;
	while(cin>>n>>m){
		if(n==0&&m==0)break;
		int ans=-1;
		
		vector<int> v(n);
		rep(i,n)cin>>v[i];
		
		int time=under(v[0],m),dif=v[0],pos=1;
		vector<pair<pii,int>> vec;
		
		for(int i=1;i<n;i++){
			int ntime,ndif=v[i],npos=i+1;
			if( (ndif<=dif&&upper(v[i],time)>m) || (ndif>dif&&lower(v[i],time)>m) ){
				pos = npos;
				dif = ndif;
				time = under(v[i],m);
				if(time>m){ans=npos;break;}
				vec.pb(make_pair(pii(time,dif),pos));
			}else{
				if(ndif<=dif)ntime=upper(v[i],time);
				if(ndif>dif) ntime=lower(v[i],time);
				if(ntime>m){ans=npos;break;}
				vec.pb(make_pair(pii(ntime,ndif),pos));
			}
		}
		if(ans!=-1)cout<<ans<<endl;
		else{
			sort(all(vec));
			if(vec[0].first==vec[1].first)cout<<n<<endl;
			else cout<<vec[0].second<<endl;
		}
	}

}

Measured memory_bytes: 3104
#include<iostream>
using namespace std;
int main()
{
    unsigned int num,div;
    cin>>num;
    div=num%10;
    if(div==2 || div==4 || div==5 || div==7 || div==9) cout<<"hon"<<endl;
    else if(div==0 || div==1 || div==6 || div==8) cout<<"pon"<<endl;
    else cout<<"bon"<<endl;
    return 0;
}


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


int main(){
	int n, m;
	cin >> n >> m;
	vector<int> l(m), r(m);
	rep(i,m)cin >> l[i] >> r[i];
	sort(l.rbegin(), l.rend());
	sort(r.begin(), r.end());
	int count = r[0] - l[0] +1;
	if(count <= 0) count = 0;

	cout << count << endl;
	return 0;

}


Measured memory_bytes: 1024
import java.util.Scanner;
public class Main{

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		
		int a = stdIn.nextInt();
		int b = stdIn.nextInt();
		
		int x = stdIn.nextInt();
		
		
		if(a*a*b <= 2*x) {
			double h = 2*(a*b-(double)x/a)/(double)a;
			double kakudo =Math.toDegrees(Math.atan2(h, a));
			System.out.println(kakudo);
		}else {
			double h = 2 * x/((double)a*b);
			double kakudo = Math.toDegrees(Math.atan2(b, h));
			System.out.println(kakudo);
			
		}
		
		
		
	}

}


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

int n,m;
string obj[222];
int memo[200200];

int rec(int state){
  if(memo[state]>=0)return memo[state];

  int cnt = 0, tmp = state;
  vector<int> col(m);
  rep(i,m){ col[i] = tmp%3; tmp/=3; }

  rep(i,n){
    bool f = true;
    rep(j,m){
      if(col[j] == 1 && obj[i][j] == '1')f = false;
      if(col[j] == 2 && obj[i][j] == '0')f = false;
      if(!f)break;
    }
    if(f)cnt++;
  }
  if(cnt<=1)return memo[state] = 0;

  int res = m;
  rep(i,m){
    if(col[i]==0){
      int maxv = 0;

      for(int k=1;k<=2;k++){
	col[i] = k;
	int nstate = 0;
	for(int j=m-1;j>=0;j--)nstate = nstate*3 + col[j];
	maxv = max(maxv, rec(nstate));
      }
      res = min(res, maxv);
      col[i] = 0;
    }
  }
  return memo[state] = res+1;
}

int main(){
  cin.tie(0); ios::sync_with_stdio(0);
  while(cin >> m >> n, m){
    rep(i,n)cin >> obj[i];

    memset(memo,-1,sizeof(memo));
    cout << rec(0) << endl;
  }
}

Measured memory_bytes: 2008
#include <stdio.h>
int main(void)
{
 int a,b,c;
 scanf("%d",&a);
 scanf("%d",&b);
 scanf("%d",&c);
 if(a<b&&b<c){
  printf("Yes\n");
 }
 else{
  printf("No\n");
 }
 return 0;
}

Measured memory_bytes: 580
n, m = (int(x) for x in input().split())

if n == 1 or m == 1:
  ans = 1
else:
  if n % 2 == 0:
    ans = n * m // 2
  else:
    if m % 2 == 0:
      ans = n * m // 2
    else:
      ans = n * m // 2 + 1
print(ans)


Measured memory_bytes: 2940
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <atcoder/all>

using namespace std;

#define REP(i,n) for((i)=0;(i)<(int)(n);(i)++)
#define snuke(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)

int main(void){
	string s;
	int K,i;
	cin >> K;
	REP(i,K) s += "ACL";
	cout << s << endl;
	return 0;
}


Measured memory_bytes: 3568
def rm_123(A):
	if len(A) == 0: return 1
	for a in set(A):
		if set([a,a+1,a+2]) <= set(A):
			A1 = A[:]
			for i in range(3): A1.remove(a+i)
			return judge(A1)

def rm_111(A):
	if len(A) == 0: return 1
	for a in set(A):
		if A.count(a) >= 3:
			A1 = A[:]
			for i in range(3): A1.remove(a)
			return judge(A1)

def judge(A):
	return rm_123(A) or rm_111(A)
	
for _ in range(input()):
	n = map(int,raw_input().split())
	R = []; G = []; B = []
	s = raw_input().split()
	for i in range(len(n)):
		if   s[i] == "R": R.append(n[i])
		elif s[i] == "G": G.append(n[i])
		elif s[i] == "B": B.append(n[i])
	print 1 if judge(R) and judge(G) and judge(B) else 0
	

Measured memory_bytes: 4276
#include <iostream>
#include <vector>
using namespace std;
int main(void){
    int n,d;
    cin >> n >> d;
    vector<vector<int>> x(n,vector<int>(d));
    
    for(int i = 0;i < n;i++){
          for(int j = 0;j < d;j++){
                cin >> x[i][j];
          }
    }
    
    int ans = 0;
    for(int i = 0;i < n - 1;i++){
          for(int j = i + 1;j < n;j++){
                int t = 0;
               for(int k = 0;k < d;k++){
                     t += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
               } 
               for(int k = 1;k * k <= t;k++){
                     if(k * k == t)ans++;
               }
          }
    }
    
    cout << ans << endl;
}


Measured memory_bytes: 256
from sys import stdin
S = (stdin.readline().rstrip())

s1 = S[0:len(S)//2]
s2 = S[(len(S)+3)//2-1:]

def f(s):
    flag = True
    for i,j in zip(s[:len(s)//2],s[::-1][:len(s)//2]):
        if i != j:
            flag = False
    return flag

if f(s1) and f(s2) and f(S):
    print("Yes")
else:
    print("No")

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

int main(){
  string s;
  cin >> s;
  for(int i=0;i<s.size();++i){
    if(s[i]=='C'){
      for(int j=i;j<s.size();++j){
	if(s[j]=='F'){
	  cout << "Yes" << endl;
	  return 0;
	}
      }
    }
  }
  cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256