akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
using namespace std;

bool is_interger(int p){
  for (int i=1; i*i <= p ;i++){
    if (p==i*i) return true;
  }
  return false;
}

int main(){
  int n,d;
  cin >> n >> d;
  int des=0;
  int cnt=0;
  vector<vector<int>> s(n,vector<int>(d));
  for (int i=0; i < n; i++){
    for(int j=0; j< d; j++){
      cin >> s.at(i).at(j);
    }
  }
  for (int i=0; i < n; i++){
    for (int k=i+1; k < n; k++){
      for (int m=0; m < d; m++){
        des+=(s.at(i).at(m)-s.at(k).at(m))*(s.at(i).at(m)-s.at(k).at(m));
      }
      if (is_interger(des)) cnt++;
      des=0;
    }
  }
  cout << cnt << endl;
  return 0;
}

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

typedef long long ll;
typedef pair<int, int> P;
#define MOD 1000000007
#define INF (1 << 30)
#define INFll (1LL << 60)
#define REP(i, m, n) for(int i = (int)m; i < (int)n; ++i)
#define rep(i, n) REP(i, 0, n)

vector<int> edge[200020] = {};
vector<int> vec(200020);

void dfs(int v, int p) {
    for(auto nv : edge[v]) {
        if(nv == p) continue;
        vec[nv] += vec[v];
        dfs(nv, v);
    }
}

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

    int n, q; cin >> n >> q;
    rep(_, n-1) {
        int x, y;
        cin >> x >> y;
        x--, y--;
        edge[x].emplace_back(y);
        edge[y].emplace_back(x);
    }
    rep(i, q) {
        int p, x; cin >> p >> x;
        p--;
        vec[p] += x;
    }
    dfs(0, -1);
    rep(i, n) cout << vec[i] << (i == n-1 ? '\n' : ' ');
    return 0;
}

Measured memory_bytes: 23552
#include <iostream>
#include <vector>
#include <string>
#include <math.h>
#include <algorithm>
#include <set>
#include <iomanip>
#include <stdio.h>
#include <sstream>
#include <string>
#include <bits/stdc++.h>
using namespace std;
int main(void){
  int n,q;
  cin>>n>>q;
  vector<pair<string,int>> hoge(n);
  queue<pair<string,int>> ans;
  for(int i=0; i<n; i++){
    cin>>hoge.at(i).first>>hoge.at(i).second;
    ans.push(hoge.at(i));
  }
  
  long long int sec=0;
  while(!ans.empty()){
    if(ans.front().second<=q){
      sec+=ans.front().second;
      cout<<ans.front().first<<" "<<sec<<endl;
      ans.pop();
    }else{
      sec+=q;
      string s=ans.front().first;
      long long int i=ans.front().second-q;
      ans.pop();
      pair<string,int> var={s,i};
      ans.push(var);
    }
  }
}


Measured memory_bytes: 6796
import sys
input = sys.stdin.readline
from collections import *

S = input()[:-1]
N = len(S)
S1 = S[:N//2]
S2 = S[N//2+1:]

if S==S[::-1] and S1==S1[::-1] and S2==S2[::-1]:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 38384
#include<bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <stack>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
using namespace std;
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
using namespace std;
//typedef tree<int, nuint_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> new_data_set; 
#define int long long
#define MOD 1000000007
#define what_is(x) cerr << #x << " is " << x << endl;
#define loop(i,a,n) for(int i=a;i<n;i++)

#define pb emplace_back
#define mp make_pair
#define ff first
#define ss second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, szof(x))
#define sortall(x) sort(aint(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
typedef pair<int, int> pt;


signed main() {
	
	//fastio();
//	#define LOCAL_DEFINE
	#ifdef LOCAL_DEFINE
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
	#endif
	//https://codeforces.com/contest/1084/problem/D
	// https://codeforces.com/contest/1155/problem/E
	//https://www.spoj.com/problems/MON2012/
	//https://codeforces.com/blog/entry/52726	
    int a,p;
    cin>>a>>p;
    cout<<(a*3+p)/2;
   
	return  0;


}


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

int main()
{
	string s;
	cin >> s;
	bool t = false;
	if (s.length() >= 4)
		if (s.substr(0, 4) == "YAKI")
			t = true;
	if (t)
		cout << "Yes";
	else
		cout << "No";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

ll ch[62];
int main() {
	ll n;
	cin>>n;
	for(ll i=0;i<n;i++){
		ll now;
		cin>>now;
		ll j=0;
		while(now!=0){
			ch[j]+=now%2;
			now/=2;
			j++;
		}
	}
	ll kei=1;
	ll ans=0;
	for(ll i=0;i<61;i++){
		ll now=ch[i];
		now=now*(n-now);
		now%=inf;
		now*=kei;
		ans+=now;
		kei*=2;
		kei%=inf;
		ans%=inf;
	}
	cout <<ans;
	// your code goes here
	return 0;
}

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

#include <queue>

#define Min(a,b) ((a)<(b)?(a):(b))
#define Max(a,b) ((a)>(b)?(a):(b))
#define Mabs(a,b) ((a)>(b)?(a)-(b):(b)-(a))
#define Abs(a) (a)>0?(a):(-(a))
template <typename QvQ> inline QvQ Min2(QvQ a,QvQ b){if(a<b) return a;return b;}
template <typename QvQ> inline QvQ Max2(QvQ a,QvQ b){if(a>b) return a;return b;}
template <typename QvQ> inline QvQ Abs2(QvQ a){if(a>0) return a;return -a;}

#define n1kw 10000000
#define inf 0x7f7f7f7f
#define dinf 0x3f3f3f3f
#define llinf 0x7f7f7f7f7f7f7f7f
#define lldinf 0x3f3f3f3f3f3f3f3f

#define ll long long
#define rei register int
#define inv inline void
#define inb inline bool
#define ini inline int

#define bl putchar(' ')
#define ed putchar('\n')
#define test std::cout<<"this:"
#define card system("pause")

#define read2(a,b) read(a),read(b)
#define write2(a,b) write(a),bl,write(b)
#define read3(a,b,c) read(a),read(b),read(c)
#define write3(a,b,c) write(a),bl,write(b),bl,write(c)

//char buf[1<<23],*p1=buf,*p2=buf,obuf[1<<23],*O=obuf;
//#define getchar() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)

template <typename QvQ>inv read(QvQ &x)
{
	x=0;int f=1;
	char c=getchar();
	for(;c<'0'||c>'9';c=getchar()) if(c=='-') f=-1;
	for(;c>='0'&&c<='9';c=getchar()) x=(x<<1)+(x<<3)+(c^48);
	x=x*f;
}
template <typename QvQ>inv write(QvQ x)
{
	if(x<0) x=-x,putchar('-');
	if(x>9) write(x/10);
	putchar(x%10+48);
}
using namespace std;
#define MAXN 100005
#define MAXM 200005
int k,x; 
int main()
{
	read2(k,x);
	int dq=x-k+1;
	while(dq<-1000000) ++dq;
	while(dq<=x+k-1&&dq<=1000000) write(dq++),bl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <map>
#include <math.h>
#include <iomanip>
#include <vector>
#include <queue>
#include <functional>
#include <random>
#include <time.h>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
ll w[300030], e[300030];
int main() {
	ll n;
	cin >> n;
	string s;
	cin >> s;
	for (int i = 0; i < s.size(); i++) {
		if (s[i] == 'W')w[i]=1;
		else e[i] = 1;
		if (i) {
			w[i] += w[i - 1];
			e[i] += e[i - 1];
		}
	}
	ll ans = 1e9;
	for (int i = 0; i < s.size(); i++) {
		ll cnt;
		if (i) {
			if (i == s.size() - 1)cnt = w[i - 1];
			else cnt = w[i - 1] + e[n - 1] - e[i];
		}
		else {
			cnt = e[n - 1] - e[i];
		}
		ans = min(ans, cnt);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 5380
// A Reward For a Carpenter
// 問題URL: http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0117&lang=jp
// 中央*右
//  
// 直感的で分かりやすいアルゴリズムだと思いました。scanfによる入出力に戸惑いました。

#include <iostream>
#include <cstdio>

using namespace std;

int n, m, a, b, c, d, ans=0, s, g, V, P;
int Cost[32][32]={};

const int inf = 1001001001;

void show(){ //隣接行列を表示
    for(int i = 1; i <= n; ++i)
        for(int j = 1; j <= n; ++j){
            if(Cost[i][j] == inf) cout << "INF ";
            else cout << Cost[i][j] << " ";
            if(j == n) cout << endl;
    } 
}

void solve(){
    for(int k = 1; k <= n; ++k)
        for(int i = 1; i <= n; ++i)
            for(int j = 1; j <= n; ++j)
                Cost[i][j] = min(Cost[i][j],Cost[i][k] + Cost[k][j]); //iからjまで行くのに、地点kを経由した方がコストが低ければ書き換える
    // show();

    cout << V - P - Cost[s][g] - Cost[g][s] << endl;
}

int main(){
    scanf("%d%d",&n,&m);

    for(int i = 1; i <= n; ++i) //隣接行列をinfで初期化
        for(int j = 1; j <= n; ++j) Cost[i][j] = inf;

    for(int i = 0; i < m; ++i){
        scanf("%d,%d,%d,%d",&a,&b,&c,&d);
        // cerr << "(a, b, c, d) = (" << a << ", " << b << ", " << c << ", " << d << ")" << endl;
        Cost[a][b] = c;
        Cost[b][a] = d;
    }
    scanf("%d,%d,%d,%d", &s, &g, &V, &P);
    // cerr << "(s,g,V,P) = (" << s << ", " << g << ", " << V << ", " << P  << ")" << endl; 
    // show();

    solve();
}


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

vector<int> dist(200005); // number of towns
map<int, int> mp; // wheter the town is visited or not

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

	int n;
	cin >> n;
	long long k;
	cin >> k;

	vector<int> a(n); //store the order of cities
	for (int i = 0; i < n; i++) {
		cin >> a[i]; // store the values of towns
		--a[i]; // to match to our indices because the first city is at position 1
	}

	int x = 1; // loop counter
	mp[0] = 0;

	int start = 0; // the first city
	int l, h; // low and high of loop

	for (int i = 0; i <= n; i++) {
		dist[x] = a[start]; // dist[x] is the destination after city jump
		if (mp.count(dist[x]) > 0) { // if already visited
			l = mp[dist[x]];
			h = x;
			break;
		}
		else
			mp[dist[x]] = x; // store the value in the map
		x++; // increase the loop counter
		start = a[start]; // teleported to next start
	}
	if (k < h)
		cout << dist[k] + 1; // because we start at index 0
	else {
		int loop = h - l;
		k -= l; // remove the other elements before the loop starts
		k = k % loop;
		cout << dist[l + k] + 1; // because we start at index 0
	}
	return 0;
}

Measured memory_bytes: 13760
# coding: utf-8
# Your code here!
import sys
read = sys.stdin.read
readline = sys.stdin.readline

n,a,b,*h = map(int,read().split())

ng = 0
ok = 10**9

d = a-b

def check(mid,d,b):
    res = 0
    for hi in h:
        hi -= b*mid
        res += max(0,(hi+d-1)//d)
    #print(mid,res)
    return res <= mid        

while ok-ng > 1:
    mid = (ok+ng)//2
    if check(mid,d,b):
        ok = mid
    else:
        ng = mid

#print(check(1,d,b),d)

print(ok)






Measured memory_bytes: 20000
#include <algorithm>
#include <array>
#include <cmath>
#include <iostream>
#include <set>
#include <string>
#include <utility>
#include <vector>

int main()
{
    int h, w, k;
    std::cin >> h >> w >> k;
    std::vector<std::pair<int, int>> blacks;
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            char c;
            std::cin >> c;
            if (c == '#') {
                blacks.emplace_back(i, j);
            }
        }
    }

    int ans = 0;
    int comb = (1 << (h + w));
    for (int i = 0; i < comb; i++) {
        int rest = 0;
        for (auto& e : blacks) {
            if (((i & (1 << e.first)) == 0) && ((i & (1 << (h + e.second))) == 0)) {
                rest++;
            }
        }
        if (rest == k) {
            ans++;
        }
    }
    std::cout << ans << "\n";
    return 0;
}


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

// iterator
#define REP(i,init, n) for(lli i=init;i<n;i++)
#define REPE(i,init, n) for(lli i=init;i<=n;i++)
#define REPIT(it,container) for(auto it = container.begin(); it != container.end(); it++)
#define REPIT_R(it,container) for(auto it = container.rbegin(); it != container.rend(); it++)

// input
#define cin1(x)             cin >> x
#define cin2(x, y)          cin >> x >> y
#define cin3(x, y, z)       cin >> x >> y >> z
#define ncin1(n, x)         REP(i, 0, n) {cin1(x[i]);}
#define ncin2(n, x, y)      REP(i, 0, n) {cin2(x[i], y[i]);}
#define ncin3(n, x, y, z)   REP(i, 0, n) {cin3(x[i], y[i], z[i]);}

#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))

typedef long long int lli;
typedef pair<lli, lli> P;

int main() {
    lli n;
    cin1(n);
    lli a[n*3];
    ncin1(n*3, a);


    lli l_que_total = 0;
    lli r_que_total = 0;
    priority_queue<lli, vector<lli>, greater<lli>> l_que;
    priority_queue<lli> r_que;
    REP(i, 0, n) {
        l_que.push(a[i]);
        l_que_total += a[i];
        r_que.push(a[n*3-1-i]);
        r_que_total += a[n*3-1-i];
    }

    lli l_que_totals[3*n];
    lli r_que_totals[3*n];
    l_que_totals[n-1] = l_que_total;
    r_que_totals[2*n] = r_que_total;
    REP(i, n, n*2) {
        l_que_total += a[i];
        l_que.push(a[i]);
        l_que_total -= l_que.top();
        l_que.pop();
        l_que_totals[i] = l_que_total;
    }
    for (lli i = 2*n-1; i >=n; i--) {
        r_que_total += a[i];
        r_que.push(a[i]);
        r_que_total -= r_que.top();
        r_que.pop();
        r_que_totals[i] = r_que_total;
    }
    lli ans = -LLONG_MAX;
    REPE(i, n-1, n*2-1) {
        ans = max(ans, l_que_totals[i] - r_que_totals[i+1]);
    }
    // l_que から全部取り出して足したやつ - r_que から全部取り出して足したやつ
    cout << ans << endl;
}


Measured memory_bytes: 5996
/// Tutorial: https://pastebin.com/zArycucT
/// Tutorial2: https://atcoder.jp/contests/abc132/submissions?f.User=snuke
#include <bits/stdc++.h>
using namespace std;
#define INF 1<<30
#define endl '\n'
#define maxn 1005
#define FASTIO ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
typedef long long ll;
const double PI = acos(-1.0);
#define dbg(x) cerr << #x << " = " << x << endl;
#define dbg2(x, y) cerr << #x << " = " << x << ", " << #y << " = " << y << endl;
#define dbg3(x, y, z) cerr << #x << " = " << x << ", " << #y << " = " << y << ", " << #z << " = " << z << endl;


int main()
{
    FASTIO
    /*
    //double start_time = clock();
#ifndef ONLINE_JUDGE
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    freopen("error.txt", "w", stderr);
#endif
//*/
    int T;
    //cin >> T;
    T = 1;
    for(int cs = 1; cs <= T; cs++){
      string s;
      cin >> s;
      sort(s.begin(), s.end());
      bool flag = false;
      if(s[0] == s[1] && s[2] == s[3] && s[0] != s[2]) flag = true;

      if(flag) cout << "Yes\n";
      else cout << "No\n";
    }

    //double end_time = clock();
    //printf( "Time = %lf ms\n", ( (end_time - start_time) / CLOCKS_PER_SEC)*1000);
    return 0;
}

Measured memory_bytes: 256
n=int(input())
a=[float('inf')]
a+=list(map(int,input().split()))
d=[1000 for i in range(n+1)]
for i in range(1,n+1):
    d[i]=max(d[i-1],d[i-1]//a[i-1]*a[i]+d[i-1]%a[i-1])
print(d[-1])

Measured memory_bytes: 9104
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = double;
using ld = long double;
template<typename T> using V = vector<T>;
template<typename T> using VV = vector<vector<T>>;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define all(v) (v).begin(),(v).end()
#define siz(v) (ll)(v).size()
#define rep(i,a,n) for(ll i=a;i<(ll)(n);i++)
#define repr(i,a,n) for(ll i=n-1;(ll)a<=i;i--)
#define lb lower_bound
#define ub upper_bound
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
const ll mod = 1000000007;
const ll INF = 1000000099;
const ll LINF = (ll)(1e18 +99);
vector<ll> dx={-1,1,0,0},dy={0,0,-1,1};
template<typename T,typename U> void chmin(T& t, const U& u){if(t>u)t=u;}
template<typename T,typename U> void chmax(T& t, const U& u){if(t<u)t=u;}
template<typename T>T gcd(T a,T b){return b?gcd(b,a%b):a;}
template<typename T>T mpow(T a, T n) {
  T res = 1;
  for(;n;n>>=1) {
    if (n & 1) res = res * a;
    a = a * a;
  }
  return res;
}


signed main(){
  cin.tie(0);ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(20);
  ll ans=0,n;cin>>n;
  map<PL,int> ma,ma2;
  priority_queue<PL> qlb,qlb2;
  priority_queue<PL,vector<PL>,greater<PL>> qrs,qrs2;
  rep(i,0,n){
    ll l,r;cin>>l>>r;
    qlb.emplace(l,r);
    qrs.emplace(r,l);
    ma[{l,r}]++;
  }

  ma2=ma;
  qlb2=qlb;
  qrs2=qrs;

  PL next;
  vector<PL> order(0);
  rep(i,0,n){
    if(i%2==0){//r
      next=qlb.top();
      while(ma[next]==0){
        qlb.pop();
        next=qlb.top();
      }
      ma[next]--;
      order.eb(next);
    }else{
      next=qrs.top();
      while(ma[{next.sc,next.fs}]==0){
        qrs.pop();
        next=qrs.top();
      }
      ma[{next.sc,next.fs}]--;
      order.pb(mp(next.sc,next.fs));
    }
  }

  ll now=0;
  repr(i,0,siz(order)){
    if(i%2==0 && now<order[i].fs){
      ans+=abs(order[i].fs-now);
      now=order[i].fs;
    }
     
    if(i%2==1 && order[i].sc<now){
      ans+=abs(now-order[i].sc);
      now=order[i].sc;
    }
    //cerr<<now<<" "<<ans<<endl;
  }
  ans+=abs(now);



  order.clear();
  rep(i,0,n){
    if(i%2==1){//l
      next=qlb2.top();
      while(ma2[next]==0){
        qlb2.pop();
        next=qlb2.top();
      }
      ma2[next]--;
      order.eb(next);
    }else{
      next=qrs2.top();
      while(ma2[{next.sc,next.fs}]==0){
        qrs2.pop();
        next=qrs2.top();
      }
      ma2[{next.sc,next.fs}]--;
      order.pb(mp(next.sc,next.fs));
    }
  }

  ll res=0;now=0;
  repr(i,0,siz(order)){
    if(i%2==1 && now<order[i].fs){
      res+=abs(order[i].fs-now);
      now=order[i].fs;
    }
     
    if(i%2==0 && order[i].sc<now){
      res+=abs(now-order[i].sc);
      now=order[i].sc;
    }
    //cerr<<now<<" "<<ans<<endl;
  }
  res+=abs(now);

  cout<<max(ans,res)<<endl;
}
//( ・ __ ・ ) KEEP BEING ORGANIZED
//CHECK overflow,vector_size,what to output?

Measured memory_bytes: 22112
/*==========================================================================*/
/*
    AUTHOR:    BPZ
	CREATED:   30.08.2020 11:06:58

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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s;
  cin >> s;
  int sum = 0;
  for (int i = 0; i < (int) s.size(); i++) {
  	sum += s[i] - '0';
  }
  sum % 9 == 0 ? cout << "Yes" << '\n' : cout << "No" << '\n';
  return 0;
}


Measured memory_bytes: 3740
#include <memory.h>

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <utility>
#include <vector>

using namespace std;

#define MOD 1000000007
#define INIT -1

int main() {
	int n, k;
	cin >> n >> k;
	long long int ans = 0;
	for (int b = k + 1; b <= n; b++) {
		ans += n / b * (b - k);
		ans += max(0, n - (n / b) * b - k + 1);
		if (k == 0) ans--;
		// cout << ans << endl;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
S = list(input())
i = 0
for s in range(len(S)):
  t = s + 1
  if S[s] == "U" or S[s] =="D":
    i += 1
  if t%2 !=0 :
    if S[s] == "R":
      i +=1
  if t%2==0:
    if S[s] == "L":
      i += 1
if i == len(S):
  print("Yes")
else:
  print("No")

Measured memory_bytes: 3060
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

using Pair = System.Collections.Generic.KeyValuePair<int, int>;

class Program
{
	public Program() { }

	static void Main(string[] args)
	{
		new Program().prog();
	}
	Scanner cin;
	const int MOD = 1000000007;
	const int INF = int.MaxValue;
	const double EPS = 1e-7;
	const double PI = 3.1415926536;

	void prog()
	{
		cin = new Scanner();
		int[,] dir8 = new int[8, 2] { { -1, -1 }, { -1, 0 }, { -1, 1 }, { 0, -1 }, { 0, 1 }, { 1, -1 }, { 1, 0 }, { 1, 1 } };
		int[,] dir4 = new int[4, 2] { { -1, 0 }, { 0, -1 }, { 0, 1 }, { 1, 0 } };

		int N = cin.nextInt();
		int K = cin.nextInt();
		int X = cin.nextInt();
		int Y = cin.nextInt();
		if (N <= K)
		{
			Console.WriteLine(N * X);
		}
		else
		{
			Console.WriteLine(K * X + (N - K) * Y);
		}
	}
}

class Scanner
{
	string[] s;
	int i;

	char[] cs = new char[] { ' ' };

	public Scanner()
	{
		s = new string[0];
		i = 0;
	}

	public string next()
	{
		if (i < s.Length) return s[i++];
		string st = Console.ReadLine();
		while (st == "") st = Console.ReadLine();
		s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
		i = 0;
		return next();
	}

	public int nextInt()
	{
		return int.Parse(next());
	}

	public long nextLong()
	{
		return long.Parse(next());
	}

	public double nextDouble()
	{
		return double.Parse(next());
	}
}

Measured memory_bytes: 2904
import java.util.Scanner;

public class Main{
 public static void main(String[] a){
     Scanner s = new Scanner(System.in);
     int i,x,now;
     boolean ch=false;
     x = s.nextInt();
     for(i=1;i<=x;i++){
         now=i;
         if(i%3==0)ch=true;
         while(now>0&&ch==false){
            if(now%10==3)ch=true;
            now/=10;
         }
         if(ch==true){
             ch=false;
             System.out.print(" "+i);
         }
     }
    System.out.println();
 }   
}


Measured memory_bytes: 28712
#include <iostream>
#include <cstring>
#include <map>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <set>
#include <vector>
#include <queue>
#include <list>
#include <numeric>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <math.h>
#include <stack>
#include <climits>
#include <bitset>
#include <utility>


using namespace std;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
// const ll INF = 1LL <<60;
// const int INF = 10000;

//最大公約数
ll gcd(ll x, ll y) {
  ll tmp = 0;
  if (x < y){
    tmp=x;
    x=y;
    y=tmp;
  }
  while (y > 0) {
    ll r = x % y;
    x = y;
    y = r;
  }
  return x;
}

//最大公倍数
ll lcm(ll x,ll y){
  return x/gcd(x,y)*y;
}

const int MAX = 1e6+1;
const int MOD = 1e9+7;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}


//階乗
ll kaijo(ll k){
    ll sum = 1;
    for (ll i = 1; i <= k; ++i)
    {
        sum *= i;
        sum%=1000000000+7;
    }
    return sum;
}

//for(int i = ; i < ; i++){}

ll lmax(ll s,ll t){
  if(s>t){
    return s;
  }
  else{
    return t;
  }
}

ll lmin(ll s,ll t){
  if(s<t){
    return s;
  }
  else{
    return t;
  }
}

long long modpow(long long res,long long a, long long n, long long mod) {
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

//sieve(MAX);でベクトルIsPrimeに「MAXまでの数値の素数の真偽」を格納する。
vector<bool> IsPrime;
void sieve(size_t max){
    if(max+1 > IsPrime.size()){     // resizeで要素数が減らないように
        IsPrime.resize(max+1,true); // IsPrimeに必要な要素数を確保
    } 
    IsPrime[0] = false; // 0は素数ではない
    IsPrime[1] = false; // 1は素数ではない

    for(size_t i=2; i*i<=max; ++i) // 0からsqrt(max)まで調べる
        if(IsPrime[i]) // iが素数ならば
            for(size_t j=2; i*j<=max; ++j) // (max以下の)iの倍数は
                IsPrime[i*j] = false;      // 素数ではない
}
// ここから開始
int main(){
  ll s;
  cin>>s;
  int x1 = 0;
  int y1 = 0;
  ll x2 = 1e9;
  int y2 = 1;
  // このように仮定すると、s + x3 = 1e9 * y3 となる。よって、x3%1e9 + s%1e9 = 1e9。
  ll x3 = ((ll)1e9 - s%1000000000)%1000000000;
  ll y3 = (s+x3)/1e9;
  cout<<x1<<" "<<y1<<" "<<x2<<" "<<y2<<" "<<x3<<" "<<y3;
  return 0;
}



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



int main(){
  long long n,d;
  cin >> n>>d;
  int counter = 0;
  rep(i,n){
    long long x,y;
    cin>>x >> y;
    
    if(x*x+y*y<=d*d) counter++;
  }
  cout << counter << endl;
  
}



Measured memory_bytes: 3644
from collections import deque

S = deque(input())
Q = int(input())

flip = 0
for _ in range(Q):
    q = input().split()
    if q[0] == "1":
        flip += 1
        flip %= 2
    else:
        if (int(q[1]) - 1 + flip)%2 == 0:
            S.appendleft(q[2])
        else:
            S.append(q[2])

S = list(S)
if flip == 0:
    print(*S, sep="")
else:
    print(*S[::-1], sep="")

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

int main()
{
  int a, b, c;
  cin >> a >> b >> c;
  int d = (10 * b) + c;
  if(d % 4 == 0)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
  return 0;
}

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

using namespace std;

vector<string> split(const string &s, char delim) {
  vector<string> elems;
  string item;
  for (char ch: s) {
    if (ch == delim) {
      if (!item.empty()) {
        elems.push_back(item);
      }
      item.clear();
    }
    else {
      item += ch;
    }
  }
  if (!item.empty()) {
    elems.push_back(item);
  }
  return elems;
}

string to_str_with_zero(int i, int w) {
  ostringstream sout;
  sout << std::setfill('0') << std::setw(w) << i;
  string s = sout.str();
  return s;
}

int letter_to_int(char c) {
  return tolower(c) - 'a';
}

bool array_equal(vector<int> a1, vector<int>a2) {
  if (a1.size() != a2.size()) {
    return false;
  }
  for (int i=0; i<a1.size(); i++) {
    if (a1.at(i) != a2.at(i)) {
      return false;
    }
  }
  return true;
}

int gcd(int a, int b) {
  if (a == b) {
    return a;
  }
  else if (a > b) {
    return gcd(a - b, b);
  }
  else {
    return gcd(a, b - a);
  }
}

char int_to_char(int a) {
  if (a == -1) {
    return 'z';
  }
  else {
    return 'a' + a;
  }
}

long nCr(int n, int r) {
    long ans = 1;
    for (int i = n; i > n - r; --i) {
        ans = ans*i;
    }
    for (int i = 1 ; i < r + 1; ++i) {
        ans = ans / i;
    }
    return ans;
}

long long modinv(long long a, long long m) {
    long long 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 divide_count(int a, int divider) {
  int r = 0;
  while(a % divider == 0) {
    a /= divider;
    r++;
  }
  return r;
}

int main() {
  std::cout << std::setprecision(9);
  long n;
  cin >> n;

  long i = sqrt(n);
  while(true) {
    if(n % i == 0) {
      break;
    }
    i--;
  }

  cout << (i - 1) + (n / i - 1) << endl;
}

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

using namespace std;

#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long unsigned int
#define vi vector<ll>
#define vvi vector<vi>
#define pii pair<int, int>
#define vii vector<pii>
#define pb push_back
#define B begin()
#define E end()
#define sz(A) (ll)(A).size()
#define F first
#define S second
#define loop(z, v) for(auto &z: v)
#define sp << ' ' << 
#define sps << ' '
#define nl "\n"
// #define nl endl
#define fat 1000000007
// #define fat 998244353

int main()
{
    boost;
    ll tt = 1, n, m, i, j, x, y, a ,b , c ,d;
    bool poss = true;
    string s;

    // cin >> tt;
    for(int _ = 1; _ <= tt; _++){
        // cout << "Case #" << _ << ": ";
        cin >> n;
        map<string, ll> mp;

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

        ll cnt = 0;
        loop(z, mp) cnt += (z.S > 0);

        cout << cnt << nl;
    }   
    return 0;
}

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

int main() {
  int a,b,c;
  cin >> a >> b >> c;
  int ab = a+b,ac = a+c,bc = b+c;
  if(ab <ac && ab<bc){
    cout << ab << endl;
    return 0;
  }
  else if(ac<ab && ac<bc){
    cout << ac << endl;
    return 0;
  }
  cout << bc << endl;
}


Measured memory_bytes: 3528
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

kill = 0 
for i in reversed(range(1, len(A))):
  if A[i] > 0:
    d = min(A[i], B[i-1])
    B[i-1] -= d
    A[i] -= d
    kill += d

  if (A[i-1] > 0):
    d = min(A[i-1], B[i-1])
    B[i-1] -= d
    A[i-1] -= d
    kill += d

print(kill)


Measured memory_bytes: 18624
#include <bits/stdc++.h>
using namespace std;
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back((a))
#define all(x) (x).begin(),(x).end()
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#define fi first
#define se second
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
void _dbg(string){cout<<endl;}
template<class H,class... T> void _dbg(string s,H h,T... t){int l=s.find(',');cout<<s.substr(0,l)<<" = "<<h<<", ";_dbg(s.substr(l+1),t...);}
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

#define INF 1120000000

int a[150], b[150], c[150];
int g[15][15];
int scc[1<<15];

int main(){
  int n,m;
  cin>>n>>m;
  fill(g[0], g[n], 0);
  rep(i,m){
    cin>>a[i]>>b[i]>>c[i];
    a[i]--;b[i]--;
    g[a[i]][b[i]] = g[b[i]][a[i]] = c[i];
  }

  rep(mask,1<<n){
    rep(i,m) if( (mask&(1<<a[i])) && (mask&(1<<b[i])) ){
      scc[mask] += c[i];
    }
  }

  const int ALL = (1<<n) - 1;

  vector<vector<int>> dp(1<<n, vector<int>(n, -INF));
  // [mask][i] mask内の頂点を使っていて，パスの終端がi のときの最大コスト
  dp[1][0] = 0;
  repl(mask, 1, 1<<n) rep(i,n) if(dp[mask][i] >= 0){
    // パスを伸ばす
    rep(j,n) if( !(mask&(1<<j)) && g[i][j]>0){
      dp[mask|(1<<j)][j] = max(dp[mask|(1<<j)][j], dp[mask][i] + g[i][j]);
    }

    // 補集合を考えてiのところに追加
    int sup = ALL - mask;
    int sub = sup;
    do {
      int nmask = mask | sub;
      int ncost = dp[mask][i] + scc[sub|(1<<i)];
      dp[nmask][i] = max(dp[nmask][i], ncost);

      sub = (sub-1)&sup;
    } while(sub>0);
  }

  cout << scc[ALL] - dp[ALL][n-1] << endl;

  return 0;
}


Measured memory_bytes: 3712
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define pa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};
#define pb push_back
#define fi first
#define be begin()
#define en end()
#define se second

using ll = long long;
using namespace std;
using pint = pair<int,int>;
using pll = pair<ll,ll>;
const int INFint = 1e9;
const ll INFll = 1e18;
ll MOD=1e9+7;

ll gcd(ll a, ll b) { return b?gcd(b,a%b):a; } //最大公約数
ll lcm(ll a, ll b) { return a/gcd(a,b)*b; } //最大公倍数

// aのn乗をMODで割りながら計算する
ll modpow(ll a, ll n) {
  long long res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % MOD;
    a = a * a % MOD;
    n >>= 1; // right shift
  }
  return res;
}

// MODを法としたaの逆元を計算する
ll modinv(ll a) {
  return modpow(a, MOD - 2);
}

int main(){
  int N; 
  cin>>N;
  vector<int> G[100001];
  vector<pair<int,int>> g(N-1);
  for (int i(0);i<N-1;i++){
    int a,b;
    cin>>a>>b;
    G[a].pb(b);
    G[b].pb(a);
    g[i] = {a,b};
  }
  queue<pair<int,int>> q;//number, color
  q.push({1,0});
  vector<int> pathed(N+1,0);
  map<int,map<int,int>> color;
  pathed[1] = 1;
  int K(0);
  while(!q.empty()){
    pair<int,int> now = q.front();q.pop();  
    //cout << now.first << " ";
    int color_num = 1;
    for (int i(0);i<G[now.first].size();i++){
      int next = G[now.first][i];
      if (pathed[next] == 0){
        if (color_num == now.second) color_num++;
        q.push({next,color_num});
        pathed[next] = 1;
    //    cout << color_num << endl;
        color[min(now.first,next)][max(now.first,next)] = color_num;
        K = max(K,color_num);
        color_num++;
      }
    }
  }
  cout << K << endl;
  for (int i(0);i<N-1;i++){
    int a = g[i].first;
    int b = g[i].second;
    cout << color[a][b] << endl;
  }
  return 0;
}



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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define sf scanf
#define pf printf
#define pb push_back
#define mp make_pair
#define PI ( acos(-1.0) )
#define mod 342307123
#define maxn 100005
#define IN freopen("C.in","r",stdin)
#define OUT freopen("output.txt","w",stdout)
#define FOR(i,a,b) for(i=a ; i<=b ; i++)
#define DBG pf("Hi\n")
#define INF 1000000000
#define i64 long long int
#define eps (1e-8)
#define xx first
#define yy second
#define ln 17
#define off 2
#define sq(x)  ((x)*(x))

using namespace __gnu_pbds;
using namespace std ;

typedef tree< i64, null_type, less<i64>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef pair<i64, i64> pii;

typedef pair<i64, i64> pii;

vector <int> g[1005] ;
int x[1005] , mn[1005] ;
int dp[5005]  ;

bool dfs(int u)
{
    int i , j , k , l , v ;

    int total = 0 ;

    for(i=0 ; i<g[u].size() ; i++)
    {
        v = g[u][i] ;
        bool ret = dfs(v) ;
        if(ret==0) return 0 ;
    }

    for(i=0 ; i<=5000 ; i++) dp[i]=0 ;
    dp[0] = 1 ;
/*
  4
1 2 1
1000 4001 5000 5000 */

    for(i=0 ; i<g[u].size() ; i++)
    {
        v = g[u][i] ;
        int temp[5005] ;
        for(j=0 ; j<=5000 ; j++) temp[j] = 0 ;
        for(j=0 ; j+x[v]<=5000 ; j++) temp[ j + x[v] ] |= dp[j] ;
        for(j=0 ; j+mn[v]<=5000 ; j++) temp[ j + mn[v] ] |= dp[j] ;

        for(j=0 ; j<=5000 ; j++) dp[j] = temp[j] ;

        total += (x[v] + mn[v]) ;
    }


    for(j=x[u] ; j>=0 ; j--)
    {
        if(  dp[j]==1 )
        {
            mn[u] = total - j ;
            return true ;
        }
    }
    return false ;
}

int main()
{
    int i , j , k , l , m , n ;

    scanf("%d",&n) ;

    FOR(i,2,n)
    {
        scanf("%d",&k) ;
        g[k].pb(i) ;
    }

    FOR(i,1,n) scanf("%d",&x[i]) ;

    bool ret = dfs(1) ;

    if(ret==true) printf("POSSIBLE\n") ;
    else printf("IMPOSSIBLE\n") ;

    return 0 ;
}


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

int in(){
  int a;
  cin >> a;
  return a;
}//int型関数の受け取り

void forin(int* x,int y){
  for (int i=0;i<y;i++){
    cin >> x[i];
  }
}//配列の受け取り

int intpow(int x,int y){
  double a=x,b=y;
  return pow(a,b);
}//(x,y) xをy乗する

int intfabs(int x){
  double a=x;
  return fabs(a);
}//(x) の絶対値

main(){
  int a=in(),b=in(),c=in();
  if (a*c<=b) cout << c;
  else cout << b/a;
  cout << endl;
}


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

public class Main {
	private static FastScanner sc = new FastScanner();

	public static void main(String[] args) {
		int n = sc.nextInt();
		
		int[] S = new int[n];
		for(int i=0; i<n; i++) {
			S[i] = sc.nextInt();
		}
		
		int q = sc.nextInt();
		
		int cnt = 0;
		for(int i=0; i<q; i++) {
			int T = sc.nextInt();
			
			int a = 0;
			int b = n-1;
			if(binarySearch(S, T, a, b)) {
				cnt++;
			}
		}
		
		System.out.println(cnt);
	}
	
	static boolean binarySearch(int[] S, int T, int a, int b) {
		int c = (a + b) / 2;
		if(T < S[c]) {
			b = c - 1;
			if(b < a) {
				return false;
			} else {
				return binarySearch(S, T, a, b);
			}
		} else if(T > S[c]) {
			a = c + 1;
			if(b < a) {
				return false;
			} else {
				return binarySearch(S, T, a, b);
			}
		} else {
			return true;
		}
	}

	static class FastScanner {
	    private final InputStream in = System.in;
	    private final byte[] buffer = new byte[1024];
	    private int ptr = 0;
	    private int buflen = 0;
	    private boolean hasNextByte() {
	        if (ptr < buflen) {
	            return true;
	        }else{
	            ptr = 0;
	            try {
	                buflen = in.read(buffer);
	            } catch (IOException e) {
	                e.printStackTrace();
	            }
	            if (buflen <= 0) {
	                return false;
	            }
	        }
	        return true;
	    }
	    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
	    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
	    private void skipUnprintable() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;}
	    public boolean hasNext() { skipUnprintable(); return hasNextByte();}
	    public String next() {
	        if (!hasNext()) throw new NoSuchElementException();
	        StringBuilder sb = new StringBuilder();
	        int b = readByte();
	        while(isPrintableChar(b)) {
	            sb.appendCodePoint(b);
	            b = readByte();
	        }
	        return sb.toString();
	    }
	    public long nextLong() {
	        return Long.parseLong(next());
	    }
	    public int nextInt(){
	    	return Integer.parseInt(next());
	    }
	}
}

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

a_list = []
b_list = []
for i in range(N):
    a_list.append(list(input()))

for i in range(M):
    b_list.append(list(input()))

test = True

for i in range(N-M):
    for j in range(N-M):
        if a_list[i][j:j+M] == b_list[0][:M]:
            test = True
            for k in range(1,M):
                if a_list[i+k][j:j + M] != b_list[k][:M+1]:
                    test = False
                    break
        else:
            test = False

        if test == True:
            break

    if test == True:
        break

if test == True:
  print('Yes')
else:
  print('No')

Measured memory_bytes: 3064
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<sstream>
#include<vector>
#include<queue>
#include<stack>
#include<string>
#include<climits>
#include<map>
#include<set>
#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define INF 1<<30
#define F first
#define S second
using namespace std;
typedef pair<int,bool> P;

int main(){
  string a,b;
  while(true){
    cin >> a >> b;
    if(a == "0" && b == "0")break;
    map<char,P> r;
    for(int i=0;i<4;i++){
      r.insert(map<char,P>::value_type(b[i],P(i,true)));
    }
    int hit,blow;
    hit = blow = 0;
    for(int i=0;i<4;i++){
      if(r[a[i]].S && i == r[a[i]].F){
	hit++;
      }
      else if(r[a[i]].S){
	blow++;
      }
    }
    cout << hit <<" " << blow << endl;
  }
return 0;
}

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

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

fn main() {
    let n:u32 = read();
    let a: Vec<u32> = (0..n).map(|_| read()).collect();
    let mut num = 999;
    for e in a {
        let mut nm = 0;
        let mut v = e;
        while v % 2 == 0 {
            v /= 2;
            nm += 1;
        }
        num = std::cmp::min(num,nm)
    }
    println!("{}", num);
}

Measured memory_bytes: 4352
N, M =  [int(i) for i in input().split(' ')]

min_num = 0
max_num = N
for i in range(M):
    low, high = [int(k) for k in input().split()]
    if low > min_num:
        min_num = low
    if high < max_num:
        max_num = high
if max_num - min_num < 0:
    print(0)
else:
    print(max_num - min_num + 1)

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <sstream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <numeric>
#include <cctype>
#include <cassert>

// BEGIN CUT HERE
#ifdef _MSC_VER
#include <agents.h>
#endif
// END CUT HERE 

#define FOR(i, a, b) for(int i = (a); i < (int)(b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define REV(v) v.rbegin(), v.rend()
#define MEMSET(v, s) memset(v, s, sizeof(v))
#define MP make_pair
#define MT make_tuple
#define X first
#define Y second

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;



int main(){
	int n;
	while (cin >> n, n){
		map<string, map<int, vector<int>>> in, out;
		set<string> st;
		rep(i, n){
			string s;
			char c;
			int h, m, id;
			cin >> s >> h >> c >> m >> c >> id;
			if (c == 'I') in[s][id].push_back(h * 60 + m);
			if (c == 'O') out[s][id].push_back(h * 60 + m);
			st.insert(s);
		}
		map<int, int> m;
		for (auto date : st){
			auto mpin = in[date];
			auto mpout = out[date];
			if (!mpin.count(0)) continue;
			vector<int> &gin = mpin[0], &gout = mpout[0];
			rep(i, gin.size()){
				for (auto x : mpin){
					int sum = 0;
					if (x.first == 0) continue;
					vector<int> &vin = mpin[x.first], &vout = mpout[x.first];
					rep(j, vin.size()){
						int t = max(min(gout[i], vout[j]) - max(gin[i], vin[j]), 0);
						sum += t;
					}
					m[x.first] += sum;
				}
			}
		}
		int ans = 0;
		for (auto p : m) ans = max(ans, p.second);
		cout << ans << endl;
	}

	return 0;
}

Measured memory_bytes: 1384
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
using P=pair<int,int>;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
const ll mod=1000000007;
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
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 (a>b) { a=b; return 1; } return 0; }
struct mint{
    using ull=unsigned long long int;
    ull v;
    mint(ll vv=0){s(vv%mod+mod);}
    mint& s(ull vv){
        v=vv<mod?vv:vv-mod;
        return *this;
    }
    //オーバーロード
    mint operator-()const{return mint()-*this;}//符号反転
    mint&operator+=(const mint&val){return s(v+val.v);}
    mint&operator-=(const mint&val){return s(v+mod-val.v);}
    mint&operator*=(const mint&val){
        v=ull(v)*val.v%mod;
        return *this;
    }
    mint&operator/=(const mint&val){return *this*=val.inv();}
    mint operator+(const mint&val){return mint(*this)+=val;}
    mint operator-(const mint&val){return mint(*this)-=val;}
    mint operator*(const mint&val){return mint(*this)*=val;}
    mint operator/(const mint&val){return mint(*this)/=val;}
    mint pow(int n)const{
        mint res(1),x(*this);
        while(n){
            if(n&1)res*=x;
            x*=x;
            n>>=1;
        }
        return res;
    }
    mint inv()const{return pow(mod-2);}
    //拡張ユークリッドの互除法
    /* mint inv()const{
        int x,y;
        int g=extgcd(v,mod,x,y);
        assert(g==1);
        if(x<0)x+=mod;
        return mint(x);
    }*/
    friend ostream& operator<<(ostream&os,const mint&val){
        return os<<val.v;
    }//出力
    bool operator<(const mint&val)const{return v<val.v;}
    bool operator==(const mint&val)const{return v==val.v;}
    bool operator>(const mint&val)const{return v>val.v;}
};
const ll MAX = 2000010;//設定
mint fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void init(){
    fac[0] = fac[1] = 1;
    for(int i=1;i<MAX;i++)fac[i]=fac[i-1]*i;
    finv[MAX-1]=fac[MAX-1].inv();
    for(int i=MAX-2;i>=0;i--)finv[i]=finv[i+1]*(i+1);
    for(int i=MAX-2;i>=1;i--)inv[i]=finv[i]+fac[i-1];
}
//階乗
mint factor(ll n,ll k){
  if (n<k) return 0;
  if (n<0 || k<0) return 0;
  return fac[n]*finv[k];
}
// 二項係数計算
mint COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * finv[k] * finv[n - k];
}
mint sum;
mint dp[5000][5000];
int main(){
int n,m;
cin>>n>>m;
V<int> a(n),b(m);
for(int i=0;i<n;i++)cin>>a[i];
for(int i=0;i<m;i++)cin>>b[i];
dp[0][0]=1;
for(int i=0;i<n;i++){
	sum=mint(0);
  for(int j=0;j<m;j++){
	  if(a[i]==b[j])dp[i+1][j+1]+=dp[i][j]+sum;
	  dp[i+1][j]+=dp[i][j];
	  sum+=dp[i][j];
  }
  dp[i+1][m]+=dp[i][m];
}
mint ans=0;
for(int i=0;i<=m;i++)ans+=dp[n][i];
cout<<ans<<endl;
}

Measured memory_bytes: 242560
import sys
import math
from collections import defaultdict

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N,num):
    if N<=0:
        for _ in range(num): return []
    elif num==1:
        return [I() for _ in range(N)]
    else:
        read_all = [tuple(II()) for _ in range(N)]
        return map(list,zip(*read_all))

#################

H,W,D = II()
A = []
for _ in range(H):
    A.append(III())
Q = I()
L,R = Line(Q,2)

d = defaultdict(tuple)
for i in range(H):
    for j in range(W):
        d[A[i][j]-1] = (i,j)

a = [0]*(H*W)
for i in range(H*W)[::-1]:
    if i+D <= H*W-1:
        a[i] = a[i+D] + abs(d[i+D][0]-d[i][0]) + abs(d[i+D][1]-d[i][1])

for i in range(Q):
    print(a[L[i]-1]-a[R[i]-1])

Measured memory_bytes: 81756
if isfile("mystdin.txt");mystdin=open("mystdin.txt","r");redirect_stdin(mystdin);end
pI(x)=parse(BigInt,x)
pM(x::Array{SubString{String},1})=map(pI,x)
function main()
  n=pI(readline())
  a=1
  for p=[i for i=2:n if all(i%j != 0 for j=2:i-1)]
    a*=sum(fld(n,p^i) for i=1:10)+1
  end
  println(a%(10^9+7))
end
main()
if isdefined(Base, :mystdin);close(mystdin);end


Measured memory_bytes: 174984
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll x,y;
ll z;
int main(){
  cin>>x>>y;
  z= x/ __gcd(x,y) * y;
  if(x%y==0){
    cout<<-1<<endl;
    return 0;
  }

  
  cout<< z+x <<endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
int main() {
	int n,k;
	scanf("%d %d", &n, &k);
	if (n % k == 0) {
		printf("0\n");
	}
	else {
		printf("1\n");
	}
	return 0;
}


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

int main(){
    int n;
    cin >> n;
    vector<int> d1(n);
    vector<int> d2(n);
    int count = 0;
    for(int i = 0; i < n; i++){
        cin >> d1[i] >> d2[i];
        if(d1[i] == d2[i]){
            count++;
            if(count >= 3) {
                cout << "Yes" << endl;
                return 0;
            }
        }else{
            count = 0;
        }
    }
    cout << "No" << endl;
}

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

const long long INF = 1000000000;

typedef long long ll;

#define writeln(n) cout<<n<<"\n"
#define rep(i,n) for(int i=0; i<(n); ++i)

typedef pair<int, int> P;
typedef pair<string, int> Psi;


vector<ll> A(1010),B(1010),C(1010);



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


	int x,y,z,k;cin>>x>>y>>z>>k;

	rep(i,x){
		cin>>A[i];
	}
	rep(i,y){
		cin>>B[i];
	}
	rep(i,z){
		cin>>C[i];
	}

	sort(A.begin(),A.end(),greater<ll>());
	sort(B.begin(),B.end(),greater<ll>());
	sort(C.begin(),C.end(),greater<ll>());

	vector<ll> ans;

	for(int i=0; i<x; i++){
		for(int j=0; j<y; j++){
			for(int l=0; l<z; l++){
				if((i+1)*(j+1)*(l+1) > k)break;
				ans.push_back(A[i]+B[j]+C[l]);


			}
		}
	}
	sort(ans.begin(),ans.end(),greater<ll>());

	rep(i,k){
		writeln(ans[i]);
	}
}



Measured memory_bytes: 1400
#include <bits/stdc++.h>
 
using namespace std;
 
#define lli long long int
#define REP(i,s,l) for(lli i=s;i<l;i++)
#define DEBUG 0
#define INF (1LL<<50)
 
signed main(){
 
 	string s;
 	cin>>s;

 	for(lli i=1;i<4;i++){
 		if(s[i]==s[i-1]){
 			cout<<"Bad"<<endl;
 			return 0;
 		}
 	}
 	cout<<"Good"<<endl;

	return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


def sum_of_arithmetic_progression(s, d, n):
    return n * (2 * s + (n - 1) * d) // 2


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


def lcm(a, b):
    g = gcd(a, b)
    return a / g * b


def solve():
    N = int(input())
    print(ceil(N, 2))


def main():
    solve()


if __name__ == '__main__':
    main()


Measured memory_bytes: 9916