akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int main() {
  int H,W;
  cin >> H >> W;
  vector<string> s(H);
  for(int i=0;i < H;i++){
    cin >> s.at(i);
  }
  for(int i=0;i < H;i++){
    for(int j=0;j < W;j ++){
      if(s.at(i).at(j) == '.'){
        s.at(i).at(j) = '0';
      }
    }
  }
  for(int i=0;i < H;i++){
    for(int j=0;j < W;j ++){
      if(s.at(i).at(j) == '#'){
        if(i + 1 < H && s.at(i+1).at(j) != '#'){
          s.at(i+1).at(j) ++;
        } 
        if(i - 1 >= 0 && s.at(i-1).at(j) != '#'){
          s.at(i-1).at(j) ++;
        } 
        if(j + 1 < W && s.at(i).at(j+1) != '#'){
          s.at(i).at(j+1) ++;
        } 
        if(j-1 >= 0 && s.at(i).at(j-1) != '#'){
          s.at(i).at(j-1) ++;
        } 
        if(i + 1 < H &&  j + 1 < W && s.at(i+1).at(j + 1) != '#'){
          s.at(i+1).at(j+1) ++;
        } 
        if(i + 1 < H && j - 1 >= 0 && s.at(i+1).at(j-1) != '#'){
          s.at(i+1).at(j-1) ++;
        } 
        if(i - 1 >= 0 && j + 1 < W&& s.at(i-1).at(j+1) != '#'){
          s.at(i-1).at(j+1) ++;
        } 
        if(i - 1 >= 0 && j - 1 >= 0 && s.at(i-1).at(j-1) != '#'){
          s.at(i-1).at(j-1) ++;
        } 
      }
    }
  }
  for(int i=0;i < H;i++){
    cout << s.at(i) << endl;
  }
}

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

dp = [[0]*3 for i in range(n+1)]
a = []

for i in range(n):
    a.append(list(map(int,input().split())))

for i in range(n):
    for j in range(3):
        for k in range(3):
            if j==k:
                continue
            dp[i+1][j] = max(dp[i+1][j],dp[i][k] + a[i][j])

print(max(dp[n]))


Measured memory_bytes: 101596
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#include <cstring>

int main(void){
	std::string str;
	std::getline(std::cin, str);
	int n = std::stoi(str);
	int c_array[50][26];
	memset(c_array,0,sizeof(int) * 50 * 26);
	for(int i=0;i<n;i++){
		std::getline(std::cin, str);
		for(int j=0;j<str.size();j++){
			char c = str.at(j);
			c_array[i][c - 'a']++;
		}
	}
	for(int i=0;i<26;i++){
		int m=500000;
		for(int j=0;j<n;j++){
			m = std::min(c_array[j][i],m);
		}
		for(int j=0;j<m;j++)std::cout << static_cast<char>(i + 'a');
	}
	std::cout << std::endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main(){
	
	int num=0;
	int i=0;
	string str;
	cin>>str;
	
	while(i<4){
	
		
		if(str[i]=='+'){
		num++;
		}else{
		num--;
		}
		i++;
	}
	cout<<num<<endl;

return 0;

}



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

using namespace std;

#define INF 1000000007
#define LINF (1LL << 62)
#define PI 3.14159265358979

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

inline i64 mod(i64 a, i64 m) { return (a % m + m) % m; }

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



int n, a[101010];
int cnt[101010];
void solve(){
	cin >> n;
	for(int i = 0; i < n; i++){
		cin >> a[i];
		cnt[a[i]]++;
		cnt[a[i]+1]++;
		cnt[a[i]+2]++;
	}
	
	int ma = 0;
	for(int i = 0; i < 101010; i++){
		chmax(ma,cnt[i]);
	}
	cout << ma << endl;
}

int main(){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	int t = 1;
	//cin >> t;
	while(t--){
		solve();
	}
	
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <set>
#include <utility>
#include <math.h>
#include <climits>
#include <string>
#include <iomanip>
#include <stack>
#include <queue>
#define f(i,n) for(int i=0;i<n;i++)
#define f1(i,a,b) for(int i=a;i<b;i++)
#define ld long double
#define mod 1000000007
#define mp make_pair
#define pb push_back
#define mii map<int,int>
#define msi map<string,pair<int,int>>
#define pii pair<int,int>
#define F first
#define S second
#define PI 3.1415926535
typedef long long ll;
using namespace std;
ll dp[100002];
void solve(ll k,ll n,ll arr[])
{
    f1(i,1,k+1)
    {
        f1(j,1,n+1)
        {
            if(i-arr[j]>=0&&dp[i-arr[j]]==0)
            dp[i]=1;
        }
    }
}
int main()
{

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,k;
    cin>>n>>k;
    ll arr[n+1];
    f1(i,1,n+1)
    cin>>arr[i];
    solve(k,n,arr);
    if(dp[k]==1)
    cout<<"First"<<endl;
    else
    cout<<"Second"<<endl;
}


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

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl





using ll = long long;

const ll mod = 1e9+7;
const int maxn = 1e6 + 5;



int n;

map<string, int> MP;

int ask(vector<int> v) {
    assert((int)v.size() == n);
    cout<<"? ";
    for (int i: v) cout<<i+1<<" ";
    cout<<endl;
    string res;
    if (res == "-1") out("fk");
    cin>>res;
    return MP[res];
}

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);  cout.tie(0);
    MP["Red"] = 0;
    MP["Blue"] = 1;

    cin>>n;

    vector<int> v;
    for (int i=0; i<n; i++) {
	v.push_back(i);
    }

    int a0 = ask(v);
    int lo = 0;
    int hi = n;
    while (hi-lo>1) {
	int mid=(lo+hi)/2;
	vector<int> tmp;
	for (int i=0; i<n; i++) {
	    tmp.push_back(mid+i);
	}
	if (ask(tmp)==a0) {
	    lo = mid;
	} else {
	    hi = mid;
	}
    }


    vector<int> ans(2*n, -1);

    int i1 = lo;
    int i2 = i1+n;
    //watch(i1+1);
    
    
    ans[i1] = a0;
    ans[i2] = 1-a0;

    for (int i=0; i<2*n; i++) {
	if (ans[i] == -1) {
	    vector<int> v = {i};
	    if (i1<=i && i<=i2) {
		for (int j=0; j<i1; j++) {
		    v.push_back(j);
		}
		for (int j=i2+1; j<2*n; j++) {
		    v.push_back(j);
		}
	    } else {
		for (int j=i1+1; j<i2; j++) {
		    v.push_back(j);
		}
	    }
	    ans[i] = ask(v);
	}
    }


    cout<<"! ";
    for (int i: ans) {
	cout<<(i==0 ? "R" : "B");
    }
    cout<<endl;    
    return 0;
}


Measured memory_bytes: 3808
def solve(n,a)
  a.sort!
  return false if a[-1]-a[0] >= 2

  cnt = [0,0]
  a.each do |v|
    cnt[v-a[0]] += 1
  end

  if cnt[1] == 0 
    if a[0] == n-1 || a[0] <= n/2
      return true
    else
      return false
    end
  elsif cnt[1] == 1
    return false
  else
    kind = [cnt[0]+1,cnt[0]+cnt[1]/2]
    if kind.min <= a[-1] && a[-1] <= kind.max
      return true
    else
      return false
    end
  end
end

n = gets.to_i
a = gets.split.map(&:to_i)

puts solve(n,a) ? "Yes" : "No"


Measured memory_bytes: 8840
#include <iostream>
#include <cstdio>
#include <algorithm>
#define N 1005
using namespace std;

typedef long long ll;
ll n, m, mx, s, a[N][3], b[N];
ll t[2] = {-1, 1};
int main()
{
	ll i, j, k;
	cin >> n >> m;
	for (i = 0; i < n; i++) scanf("%lld %lld %lld", &a[i][0], &a[i][1], &a[i][2]);
	for (i = 0; i < 8; i++) {
		for (j = 0; j < n; j++) {
			b[j] = 0;
			for (k = 0; k < 3; k++) {
				b[j] += a[j][k] * t[(i & (1 << k)) > 0];
			}
		}
		sort(b, b + n, greater<ll>());
		s = 0;
		for (j = 0; j < m; j++) s += b[j];
		mx = max(mx, s);
	}
    cout << mx << endl;
    return 0;
}

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

using namespace std;

int main(){
  while(1){
    int v;
    scanf("%d", &v);
    if(v==0) break;

    int i;
    list<int> data;
    for(i=0;v;i++){
      switch(v%8){
      case 0:
      case 1:
      case 2:
      case 3:
        data.push_back(v%8);
        break;
      case 4:
        data.push_back((v%8)+1);
        break;
      case 5:
      case 6:
      case 7:
        data.push_back((v%8)+2);
        break;
      }
      v /= 8;
    }

    v = data.size();
    for(i=0;i<v;i++){
      printf("%d", data.back());
      data.pop_back();
    }
    puts("");
  }
}

Measured memory_bytes: 820
#include <bits/stdc++.h>
using namespace std;
#define dhoom ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);  
typedef long long ll;
typedef long double ld;
const ll inf = 1e18;
const int nax = 2e6 + 7;
const ll mod = 1e9 + 7;
//ll tree[4 * nax];
//9uS-22RSwk7gQqh

int main()
{
	string s;
	cin >> s;
	int n = s.size();
	for(int i = n - 2 ; i  >= 0 ; i--){
			if(i % 2 == 0 && s.substr(0 , i/2) == s.substr(i/2,i/2))
			{
				cout << i << endl;
				return 0;
			}
	}
	return 0;
} 




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

using namespace std;

using int64 = long long;

template< class T >
struct BinaryIndexedTree {
  vector< T > data;

  BinaryIndexedTree(int sz) {
    data.assign(++sz, 0);
  }

  T sum(int k) {
    T ret = 0;
    for(++k; k > 0; k -= k & -k) ret += data[k];
    return (ret);
  }

  void add(int k, T x) {
    for(++k; k < data.size(); k += k & -k) data[k] += x;
  }
};

int N, L;

int64 solve(vector< int > X) {
  int N = (int) X.size();
  X.push_back(L);
  BinaryIndexedTree< __int128_t > uku(X.size());
  for(int i = 0; i + 1 < X.size(); i++) uku.add(i, X[i + 1] - X[i]);

  BinaryIndexedTree< __int128_t > beet(X.size());
  for(int i = 0; i + 1 < X.size(); i++) beet.add(i, 1LL * (X[i + 1] - X[i]) * i);


  int64 ret = 0;
  for(int i = N - 1; i >= 0; i--) { // 右端を固定
    int64 sub = 0;

    {
      int ok = i, ng = -1;
      while(ok - ng > 1) {
        int j = (ok + ng) / 2;
        int64 rightRest = (i - j - 1); //i-j-1はjが大きいほど小さくなる
        int64 leftLeft = (N - i - 1);

        if(rightRest < leftLeft) ok = j;
        else ng = j;
      }

      sub += 1LL * uku.sum(ok - 1) * (N - i - 1);
      sub += 1LL * (uku.sum(i - 1) - uku.sum(ok - 1)) * i;
      sub -= 1LL * (uku.sum(i - 1) - uku.sum(ok - 1));
      sub -= 1LL * (beet.sum(i - 1) - beet.sum(ok - 1));
    }

    {

      int ok = i, ng = N;
      while(ng - ok > 1) {
        int j = (ok + ng) / 2;

        int64 rightRest = i;
        int64 leftLeft = j - i; // jが大きいほど大きくなる

        if(leftLeft < rightRest) ok = j;
        else ng = j;
      }

      sub -= 1LL * (uku.sum(ok) - uku.sum(i)) * i;
      sub += 1LL * (beet.sum(ok) - beet.sum(i));


      sub += 1LL * (uku.sum(N - 1) - uku.sum(ok)) * i;

    }
    sub *= 2;

    ret = max(ret, sub + X[i]);
  }

  return ret;
}

int main() {
  cin >> L >> N;
  vector< int > X(N + 1);
  X[0] = 0;
  for(int i = 1; i <= N; i++) cin >> X[i];
  int64 ret = solve(X);
  for(auto &p : X) p = (L - p) % L;
  sort(begin(X), end(X));
  cout << max(ret, solve(X)) << endl;
}


Measured memory_bytes: 8824
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <math.h>
 
// ===============================================================
 
using namespace std;
using ll = long long;
using vl = vector<long long>;
using vll = vector<vector<long long>>;
using vs = vector<string>;
using vc = vector<char>;
using vcc = vector<vector<char>>;
using vm = vector<short>;
using vmm = vector<vector<short>>;
using pii = pair<int, int>;
using psi = pair<string, int>;
using ld = long double;
using ull = unsigned long long;
 
// ===============================================================
 
ll gcd(ll a, ll b)
{
	if (a % b == 0)
	{
		return(b);
	}
	else
	{
		return(gcd(b, a % b));
	}
}
//最大公約数
ll lcm(ll a, ll b)
{
	return a * b / gcd(a, b);
}
//最小公倍数
ll box(double a) 
{
	ll b = a;
	return b;
}
//切り捨て
ll fff(double a) 
{
	ll b = a + 0.5;
	return b;
}
//四捨五入
ll sum(ll n) { 
	return (1 + n) * n / 2;
}
//1から整数nまでの合計
bool prime(ll a)//素数判定、primeならtrue,違うならfalse
{
	if (a < 2) return false;
	else if (a == 2) return true;
	else if (a % 2 == 0) return false;
	double sqrtNum = sqrt(a);
	for (int i = 3; i <= sqrtNum; i += 2)
	{
		if (a % i == 0)
		{
			return false;
		}
	}
 
	// 素数である
	return true;
}
//素数判定
struct UnionFind {
	vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2
 
	UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
		for (int i = 0; i < N; i++) par[i] = i;
	}
 
	int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
		if (par[x] == x) return x;
		return par[x] = root(par[x]);
	}
 
	void unite(int x, int y) { // xとyの木を併合
		int rx = root(x); //xの根をrx
		int ry = root(y); //yの根をry
		if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
		par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
	}
 
	bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
		int rx = root(x);
		int ry = root(y);
		return rx == ry;
	}
}; // // //Unionfind木 // // //Unionfind木
//Unionfind木
 
// ===============================================================
 
int main() {
	ll a, b;
	cin >> a >> b;
	ll ans = 2018;
	for (ll i = a; i <= min(a+4038,b); i++) {
		for (ll j = a; j <= min(a+4038,b); j++) {
			if (i != j) {
				if (i * j % 2019 == 0) {
					ans = 0;
					break;
				}
				if (i * j % 2019 < ans) {
					ans = i * j % 2019;
				}
			}
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 3688
n, t = map(int, input().split())
tl = list(map(int, input().split()))
tl.append(10 ** 10)
tt = 0
for i, v in enumerate(tl):
    if i == 0:
        te = v + t
    else:
        tt += min(t, 10 ** 10 if te < v else t - (te - v))
        te = v + t
print(tt)


Measured memory_bytes: 26832
n, k = map(int, input().split())
r, s, p = map(int, input().split())

t = str(input())

t_ = ''
ans = 0
for i in range(n):
    if i < k:
        if t[i] == 'r':
            t_ += 'p'
            ans += p
        elif t[i] == 's':
            t_ += 'r'
            ans += r
        else:
            t_ += 's'
            ans += s
    elif i+k <= n-1:
        if t[i] == 'r':
            if t_[i-k] != 'p':
                t_ += 'p'
                ans += p
            else:
                if t[i+k] == 'p':
                    t_ += 'r'
                else:
                    t_ += 's'
        elif t[i] == 's':
            if t_[i-k] != 'r':
                t_ += 'r'
                ans += r
            else:
                if t[i+k] == 'p':
                    t_ += 'p'
                else:
                    t_ += 's'
        else:
            if t_[i-k] != 's':
                t_ += 's'
                ans += s
            else:
                if t[i+k] == 's':
                    t_ += 'p'
                else:
                    t_ += 'r'
    else:
        if t[i] == 'r':
            if t_[i-k] != 'p':
                t_ += 'p'
                ans += p
            else:
                if t[i-k] == 'r':
                    t_ += 's'
                else:
                    t_ += 'r'
        elif t[i] == 's':
            if t_[i-k] != 'r':
                t_ += 'r'
                ans += r
            else:
                if t[i-k] == 'p':
                    t_ += 's'
                else:
                    t_ += 'p'
        else:
            if t_[i-k] != 's':
                t_ += 's'
                ans += s
            else:
                if t[i-k] == 'r':
                    t_ += 'p'
                else:
                    t_ += 'r'
print(ans)
#print(t_)


Measured memory_bytes: 3444
#include <stdio.h>
int n, q;
long long p = 10000000;
long long v[1024 * 256 + 1];
long long w[1024 * 256 + 1];
long long u[100000];
long long l[100000];
int s[1024];
int ss, uu;
long long e[512 + 1];
long long ee[128 + 1];
long long ef[128 + 1];
long long d[1024][1024];
long long te, ans;
int ar, br;
int main() {
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) {
		scanf("%lld%lld", v + i, w + i);
	}
	scanf("%d", &q);
	for (int i = 0; i < q; i++) {
		scanf("%lld%lld", u + i, l + i);
	}
	d[0][0] = 0;
	s[0] = 1;
	for (int i = 1; i < 1024; i++) {
		te = w[i] * p + v[i];
		ss = s[i / 2];
		for (int j = 0; j < s[i / 2]; j++) {
			e[j] = d[i / 2][j] + te;
		}
		ar = 0, br = 0;
		d[i / 2][ss] = p * p;
		e[ss] = p * p;
		s[i] = 2 * ss;
		while (ar + br < s[i]) {
			if (d[i / 2][ar] < e[br]) {
				d[i][ar + br] = d[i / 2][ar];
				ar++;
			}
			else {
				d[i][ar + br] = e[br];
				br++;
			}
		}
		for (int j = 1; j < s[i]; j++) {
			if (d[i][j - 1] % p > d[i][j] % p) {
				d[i][j] = d[i][j - 1];
			}
		}
	}
	for (int i = 0; i < q; i++) {
		uu = u[i];
		ans = 0;
		if (uu >= 1024) {
			ss = 1;
			e[0] = 0;
			while (uu >= 1024) {
				te = w[uu] * p + v[uu];
				for (int k = 0; k < ss; k++) {
					ee[k] = e[k];
					ef[k] = e[k] + te;
				}
				ar = 0, br = 0;
				ee[ss] = p * p;
				ef[ss] = p * p;
				while (ar < ss || br < ss) {
					if (ee[ar] < ef[br]) {
						e[ar + br] = ee[ar];
						ar++;
					}
					else {
						e[ar + br] = ef[br];
						br++;
					}
				}
				uu /= 2;
				ss *= 2;
			}
			for (int j = 1; j < ss; j++) {
				if (e[j - 1] % p > e[j] % p) {
					e[j] = e[j - 1];
				}
			}
			ar = ss - 1;
			for (int j = 0; j < s[uu]; j++) {
				while (ar + 1 && (d[uu][j] + e[ar]) / p > l[i])ar--;
				if (!(ar + 1))break;
				if ((d[uu][j] + e[ar]) % p > ans) {
					ans = (d[uu][j] + e[ar]) % p;
				}
			}
		}
		else {
			for (int j = 0; j < s[uu]; j++) {
				if (d[uu][j] / p <= l[i]) {
					if (d[uu][j] % p > ans) {
						ans = d[uu][j] % p;
					}
				}
			}
		}
		printf("%lld\n", ans);
	}
}

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

#define pow(n) (n)*(n)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()

using namespace std;

/* function */



/* code */
int main (void) 
{

  /* Variable_Proclamation */
  int A, B, C;    // input
  int X, Y;    // input

  int high_dem, low_dem;
  int start_cost;
  int rem, rem_cost;
  int total_fee;

  /* Input, Array_Proclamation */
  cin >> A >> B >> C;
  cin >> X >> Y;


  /* Initialize */
  total_fee = 0;



  /* Calculation */  
  start_cost = min(A+B, C*2);

  if(X > Y)
  {
    high_dem = X;
    low_dem  = Y;
    rem_cost = min(A, C*2);
  }
  else if(X <= Y)
  {
    high_dem = Y;
    low_dem  = X;
    rem_cost = min(B, C*2);
  }
  

  total_fee += start_cost * low_dem;

  rem        = high_dem - low_dem;
  total_fee += rem_cost * rem;



  /* Output */
  cout << total_fee << endl;


  return 0;

}


/* entity */



Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner stdIn = new Scanner(System.in);
		while(true){
			String str = stdIn.next();
			if(str.equals("-")){
				break;
			}
			int m = stdIn.nextInt();
		
			for(int i=0;i<m;i++){
				int shuffle = stdIn.nextInt();
				String str1 = str.substring(0,shuffle);
				String str2 = str.substring(shuffle,str.length());
				str = str2+str1;
			}
		
			System.out.println(str);
		}
	}
}

Measured memory_bytes: 18316
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);//入力される整数x

		for (int i = 1; i <= 10000; i++) {//データセットの個数
			int x = sc.nextInt();

			if (x != 0) {
				System.out.println("Case " + i + ": " + x);
			} else {
				break;

			}
			
		}

	}

}



Measured memory_bytes: 40916
def main():
    S = input()
    def helper(s):
        l, r = 0, len(s) -1
        while l < r:
            if s[l] != s[r]:
                return False
            l += 1
            r -= 1
        return True

    N = len(S)
    if helper(S) and helper(S[:(N-1)//2]) and helper(S[(N+3)//2-1:]):
        print('Yes')
    else:
        print('No')
    

main()

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define stoi stoll
using pii=pair<int,int>;
using vi = vector<int>;
using vvi = vector<vi>;
#define all(c) begin(c),end(c)
#define rall(c) rbegin(c),rend(c)
#define fore(x,c) for(auto &&x:c)
#define rep(i,a,n) for(int i=a,i##len=(int)(n);i<i##len;++i)
#define rrep(i, a, n) for(int i=(int)(n-1);i>=a;--i)
#define sz(c) ((int)c.size())
#define contains(c,x) (c.find(x)!=end(c))
#define inseg(l,x,r) ((l)<=(x)&&(x)<(r))
#define dump(...)
#define pb push_back
#define _ 0
const signed INF_=1001001001; const long long INF=1001001001001001001LL;
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) {
    for (auto i = begin(v); i != end(v); i++) os<<*i<<(i==end(v)-1?"":" ");return os;}
template<class T> istream& operator>>(istream &is,vector<T> &v) {
    for (auto i = begin(v); i != end(v); i++) is>>*i;return is;}
template<class T,class U> istream& operator>>(istream &is, pair<T,U> &p) {
    is>>p.first>>p.second;return is;}
template<class T, class U> bool chmax(T &a,const U &b){return a<b?a=b,1:0;}
template<class T, class U> bool chmin(T &a,const U &b){return a>b?a=b,1:0;}
template <class T> void psum(T& c) {partial_sum(begin(c), end(c), begin(c));}
template<class T> using heap=priority_queue<T,vector<T>,greater<T>>;
struct before_main_function {
    before_main_function() {
        cin.tie(nullptr); ios::sync_with_stdio(0);
        cout << setprecision(15) << fixed;
        // #define endl "\n"
    }
} before_main_function;
//------------------8<------------------------------------8<--------------------

void zalgo(string &S, function<void(int, int)> update) {
    vi A(sz(S));
    A[0] = S.size();
    update(0, A[0]);
    int i = 1, j = 0;
    while (i < S.size()) {
        while (i+j < S.size() && S[j] == S[i+j]) ++j;
        A[i] = j;
        update(i, A[i]);
        if (j == 0) {
            ++i; continue;
        }
        int k = 1;
        while (i+k < S.size() && k+A[k] < j) {
            A[i+k] = A[k];
            update(i+k, A[k]);
            ++k;
        }
        i += k; j -= k;
    }
}
signed main() {
    int N;
    cin >> N;
    string S;
    cin >> S;

    int ans = 0;
    rep(i, 0, N) {
        auto t = S.substr(i);
        zalgo(t, [&](int i, int v) {
            if (v <= i) {
                chmax(ans, v);
            }
        });
    }
    cout << ans << endl;
    return (0^_^0);
}



Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  vector<int> h(n);
  for (int i=0;i<n;i++){
    cin >> h[i];
  }
  int count=1;
  int a=h[0];
  for (int i=1;i<n;i++){
    if(h[i]>=a){
      count++;
      a=h[i];//0~i番目の中で最大のものがaとなる
    }
  }
  cout << count << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
#include<string>
#include<math.h>
using namespace std;
typedef long long int ll;

void solve(){
    int n,k;cin>>n>>k;
    ll a[n];
    for(int i=0;i<n;i++) cin>>a[i];
    for(int i=0;i<n-k;i++){
        if(a[i+k]>a[i]) 
            cout<<"Yes\n";
        else
            cout<<"No\n";
    }
    cout<<"\n";
}

int main()
{
    int t;//cin>>t;
    t=1;
    while(t--)
    solve();
    return 0;
}

Measured memory_bytes: 5156
#include <iostream>
#include <sstream>
#include <stack>
#include <iomanip>
#include <numeric>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <map>
#include <set>
#include <vector>
#include <utility>
#include <queue>
#include <cmath>

#define BEGIN(x) x.begin()
#define END(x) x.end()
#define ALL(x) BEGIN(x), END(x)
#define PAIR make_pair
#define VEC(type) vector<type >
#define endl '\n'

#define FOR(i, A, B) for(auto i = (A);i != (B); i++)
#define FORD(i, A, B) for(auto i = (A);i != (B); i--)

#define READRANGE(begin, end) FOR(it, begin, end) cin >> *it
#define READVEC(V) READRANGE(BEGIN(V), END(V))

using namespace std;

typedef long long lint;
typedef pair<int, int> Pii;
typedef pair<int, lint> Pil;
typedef pair<lint, lint> Pll;
typedef pair<lint, int> Pli;

template<class U, class V>
istream& operator >>(istream& in, pair<U, V>& pr) {
    return in >> pr.first >> pr.second;
}

template<class U, class V>
ostream& operator <<(ostream& out, pair<U, V>& p) {
    return out << p.first << " " << p.second;
}

template<class T>
ostream& operator <<(ostream& out, vector<T> vec) {
    for (T& e : vec)
        out << e << " ";
    return out << endl;
}

// ---- BEGIN LIBRARY CODE ----
// ---- END LIBRARY CODE ----
void io_init()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
};

set<lint> lunset;
const lint LIMIT = 1LL << 35;

void recurse(int i, lint num)
{
    if (num >= LIMIT)
        return;

    lunset.insert(num);

    int start = i == 0 ? 1 : 0, last = num % 10;
    FOR(d, start, 10)
        if (i == 0 || abs(d - last) <= 1) {
            recurse(i + 1, num * 10 + d);
        }
};

int main(int argc, char **argv)
{
    io_init();

    // Actual program code starts here.
    recurse(0, 0LL);
    VEC(lint) V(ALL(lunset));
    int K;
    cin >> K;
    cout << V[K] << endl;
    return 0;
};

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

int main()
{
    int n, a, b;
    cin >> n >> a >> b;
    
    int sum = 0, temp2 = 0;
    
    for(int i = 1; i <= n; i++)
    {
        int temp = i;
        while(temp)
        {
            temp2 += temp % 10;
            temp /= 10;
        }
        if(temp2 >= a && temp2 <= b)
        {
            sum += i;
        }
        temp2 = 0;
    }
    
    cout << sum << endl;
    return 0;
}


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

int A[100005], B[100005], A2[100005], B2[100005];

int main() {
	string str, str2;
	int qu;
	cin >> str >> str2;
	str.insert(str.begin(), ' ');
	str2.insert(str2.begin(), ' ');
	if (str[1] == 'A')A[1] = 1;
	else B[1] = 1;
	if (str2[1] == 'A')A2[1] = 1;
	else B2[1] = 1;
	for (int i = 2; i < str.size(); i++) {
		A[i] = A[i - 1]; B[i] = B[i - 1];
		A[i] += (str[i] == 'A');
		B[i] += (str[i] == 'B');
	}
	for (int i = 2; i < str2.size(); i++) {
		A2[i] = A2[i - 1]; B2[i] = B2[i - 1];
		A2[i] += (str2[i] == 'A');
		B2[i] += (str2[i] == 'B');
	}
	cin >> qu;
	for (int aa, bb, c, d, ite = 1; ite <= qu; ite++) {
		scanf("%d %d %d %d", &aa, &bb, &c, &d);
		int x = A[bb] - A[aa - 1];
		int y = B[bb] - B[aa - 1];
		int acnt = A2[d] - A2[c - 1];
		int bcnt = B2[d] - B2[c - 1];
		x += 2 * y;
		acnt += 2 * bcnt;
		if (x % 3 == acnt % 3)puts("YES");
		else puts("NO");
	}
}

Measured memory_bytes: 2432
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    String s = sc.next();
    if(n%2==1){
      System.out.println("No");
      return;
    }
    if(s.substring(0,n/2).equals(s.substring(n/2,n)))System.out.println("Yes");
    else System.out.println("No");
  }
}

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

using lint = long long int;
constexpr lint MOD = 1000000007;

int n;

vector<lint> factorial;
vector<lint> facInv;

template <typename T>
T power(T x, T n, T mod)
{
    T ans = 1;
    while (n > 0)
    {
        if (n & 1)
            ans = ans * x % mod;
        x = x * x % mod;
        n >>= 1;
    }
    return ans;
}

void cPrecal(int n)
{
    factorial = facInv = vector<lint>(n + 1, 1);
    for (int i = 1; i <= n; i++)
    {
        factorial[i] = factorial[i - 1] * i % MOD;
        facInv[i] = power(factorial[i], MOD - 2, MOD);
    }
}
lint nCr(int n, int r)
{
    if (n < r || r < 0)
        return 0;
    else
        return (factorial[n] * facInv[r] % MOD) * facInv[n - r] % MOD;
}


int main()
{
    cin >> n;
    vector<int> exist(n + 1, -1);
    int dup;
    for (int i = 0; i < n+1; i++)
    {
        cin >> dup;
        if (exist[dup] >= 0)
        {
            dup = i - exist[dup];
            break;
        }
        exist[dup] = i;
    }

    cPrecal(n + 1);

    for (int k = 1; k <= n + 1; k++) cout << (nCr(n + 1, k) - nCr(n - dup, k-1) + MOD) % MOD << endl;
    return 0;
}

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

int main(){
    int n;
    cin>>n;
    pair<int,int> p[n];
    for(int i=0;i<n;i++){
        int a,b;
        cin>>a>>b;
        p[i]={b,a};
    }
    sort(p,p+n);
    int t=0;
    for(int i=0;i<n;i++){
        t+=p[i].second;
        if(t>p[i].first){
            cout<<"No"<<endl;
            return 0;
        }
    }
    cout<<"Yes"<<endl;
}


Measured memory_bytes: 1792
import java.util.Arrays;
import java.util.Scanner;
import java.util.stream.IntStream;

public class Main {

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int n = scanner.nextInt();
			long k = scanner.nextLong();
			Data[] datas = new Data[n];
			IntStream.range(0, n).forEach(i -> datas[i] = new Data(scanner.nextInt(), scanner.nextInt()));
			Arrays.sort(datas);
			for (Data data : datas) {
				k -= data.count;
				if (k <= 0) {
					System.out.println(data.number);
					return;
				}
			}
		}
	}

	/**
	 * 数字と個数を格納するクラス
	 */
	private static class Data implements Comparable<Data> {

		/** 数字 */
		int number;
		/** 個数 */
		int count;

		Data(int number, int count) {
			super();
			this.number = number;
			this.count = count;
		}

		@Override
		public int compareTo(Data o) {
			return number - o.number;
		}
	}
}


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

int main(){

  int N;
  cin>>N;
  
  string s;
  cin>>s;
  if(N>=3200)cout<<s;
  else cout<<"red";
  
}


Measured memory_bytes: 256
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
constexpr long long MOD = 1000000000 + 7;
constexpr long long INF = 100000000000000000;
const double PI = acos(-1);

#define n 8
#define FREE -1
#define NOT_FREE 1

int row[8], col[n], dpos[2 * n - 1], dneg[2 * n - 1];

bool x[n][n];

void initalize() {
	for (int i = 0; i < n; i++) {
		row[i] = FREE;
		col[i] = FREE;
	}
	for (int i = 0; i < 2 * n - 1; i++) {
		dpos[i] = FREE;
		dneg[i] = FREE;
	}
}

void printBoard() {
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			if (x[i][j]) {
				if (row[i] != j)return;
			}
		}
	}
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			cout << (row[i] == j ? "Q" : ".");
		}
		cout << endl;
	}
}

void recursive(int i) {
	if (i == n) {
		printBoard();
		return;
	}
	for (int j = 0; j < n; j++) {
		if (NOT_FREE == col[j] || NOT_FREE == dpos[i + j] || NOT_FREE == dneg[i - j + n - 1])continue;
		row[i] = j;
		col[j] = dpos[i + j] = dneg[i - j + n - 1] = NOT_FREE;
		recursive(i + 1);
		row[i] = col[j] = dpos[i + j] = dneg[i - j + n - 1] = FREE;
	}
}

int main() {
	initalize();
	int k;
	cin >> k;
	for (int i = 0; i < k; i++) {
		int r, c;
		cin >> r >> c;
		x[r][c] = true;
	}
	recursive(0);
}

Measured memory_bytes: 3076
#include <algorithm>
#include <iostream>
#include <math.h>
#include <string>
using namespace std;
int main() {
  int n; cin>>n;
  int a[n],ans[n]={};
  for(int i=0;i<n;i++) cin>>a[i];
  for(int i=0;i<n;i++){
    while(a[i]%2==0){
      a[i]=a[i]/2; ans[i]++;
    }
  }
  sort(ans,ans+n);
  cout<<ans[0]<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cctype>
#include <complex>
#include <iomanip>
#include <iostream>
#include <queue>
#include <set>
#include <string>
#include <vector>

using std::cin;
using std::cout;
using std::endl;

using std::string;
using std::to_string;
using std::vector;
using std::set;
using std::queue;
using std::priority_queue;

using std::min;
using std::max;
using std::sort;
using std::abs;

int main() {
    char c;
    cin >> c;
    bool ans = c == 'a' || c == 'i' || c == 'u' || c == 'e' || c == 'o';
    cout << (ans ? "vowel" : "consonant") << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.lang.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int k = sc.nextInt();
        for (int i = 0; i < k; i++) {
            if (i % 2 == 0) {
                if (a % 2 == 1) {
                    a--;
                }
                a /= 2;
                b += a;
            } else {
                if (b % 2 == 1) {
                    b--;
                }
                b /= 2;
                a += b;
            }
        }
        System.out.println(a + " " + b);
    }
}


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


long long A;
long long B;
long long C;
long long N;
vector<long long> l(8-1+1);

long long solve(long long n, long long a, long long b, long long c){
	if (n == N) {
		if (a != 0 && b != 0 && c != 0) return abs(A-a)+abs(B-b)+abs(C-c); else return 100000000001;
	}
	long long ret;
	if (a == 0) ret = solve(n+1, a+l[n], b, c); else ret = solve(n+1, a+l[n], b, c)+10;
	if (b == 0) ret = min(ret,solve(n+1, a, b+l[n], c)); else ret = min(ret,solve(n+1, a, b+l[n], c)+10);
	if (c == 0) ret = min(ret,solve(n+1, a, b, c+l[n])); else ret = min(ret,solve(n+1, a, b, c+l[n])+10);
	ret = min(ret,solve(n+1, a, b, c));

	return ret;
}

int main(){

	scanf("%lld",&N);
	scanf("%lld",&A);
	scanf("%lld",&B);
	scanf("%lld",&C);
	for(int i = 0 ; i <= N-1 ; i++){
		scanf("%lld",&l[i]);
	}
	long long res = solve(0, 0, 0, 0);
	printf("%lld\n", res);
	return 0;
}


Measured memory_bytes: 256
import scala.io.StdIn.{readInt,readLine}
  
object Main {

  def find(s:String) = {
    if(s.length<6) "NA"
    else if(s(0)=='>') {
      if(s(1) == ''') { // maybeA
        var isA = true
        val s2 = s.drop(2).dropRight(1)
        if(s2(s2.length/2) != '#') isA = false
        else {
          val s3 = s2.split("#")
          if(s3(0)!=s3(1) || s3(0).exists(_!='=')) isA = false
        }
        if(isA && s(s.length-1)=='~') "A" else "NA"
      } else if (s(1) == '^') { // maybeB
        var isB = true
        for(i<-2 until s.length-2 by 2) {
          if(s(i)!='Q' || s(i+1)!='=') {
            isB = false
          }
        }
        if(isB && s(s.length-2)=='~' && s(s.length-1)=='~') "B" else "NA"
      } else {
        "NA"
      }
    } else "NA"
  }

  def main(args:Array[String]) = {
    val n = readInt
    for(i<-1 to n) {
      val s = readLine.trim
      println(find(s))
    }
  }
}

Measured memory_bytes: 46452
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class AtCoderA
{
    static void Main()
    {
        var sc = new Scanner();

        int n = sc.NextInt();

        Dictionary<int, int> dic = new Dictionary<int, int>();

        for (int i = 0; i < n; i++)
        {
            int num = sc.NextInt();
            if (!dic.ContainsKey(num))
            {
                dic.Add(num, 0);
            }
            dic[num]++;
        }

        int answer = dic.Where(i => i.Value % 2 == 1).Count();

        Console.WriteLine(answer);
    }

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}

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

#define debug(x) cerr << #x << ": " << x << endl
#define debugArray(x,n) for(long long hoge = 0; (hoge) < (n); ++ (hoge)) cerr << #x << "[" << hoge << "]: " << x[hoge] << endl
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vll;
const ll INF = LLONG_MAX/2;
const ll MOD = 1e9+7;
const double EPS=1e-12;

signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll L,R;cin>>L>>R;
  if(R/2019-(L-1)/2019>0){
    cout<<0<<endl;
    return 0;
  }
  ll ans = 2019;
  for(ll i=L;i<=R;i++){
    for(ll j=i+1;j<=R;j++){
      ans = min(ans,i*j%2019);
    }
  }
  cout<<ans<<endl;
  return 0;
}


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

#define   mp make_pair
#define   pb push_back
#define   ff first 
#define   ss second
#define   IOS ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define   endl "\n" 
#define   pll pair<ll, ll>
#define   all(x) x.begin(), x.end()
#define   vll vector<ll> 

const ll inf = (ll)(1e17 + 17);
const ll mod = (ll)(1e9 + 7);
vector<vector<pll>> adj;
ll n;
ll recurse(ll idx, ll mask) {
  if(idx == n) {
    bool foo = true;
    for(ll i = 0; i < n; i++) {
      if(mask&(1ll<<i)) {
        for(auto it: adj[i+1]) {
          ll zz = (((mask)&(1ll<<(it.ff-1))) > 0);
          if(it.ss != zz) foo = false;
        }
      }
    } 
    if(foo) return __builtin_popcountll(mask);
    return -inf;
  }
  ll ans = -inf; 
  ans = max(ans, recurse(idx+1, mask));
  ans = max(ans, recurse(idx+1, (mask|1ll<<idx)));
  return ans;
}
int main(){
 IOS
#ifdef SHAN
    freopen("input.txt" , "r" , stdin);  
#endif
  cin >> n;
  adj.resize(n+1);
  for(ll i = 1; i <= n; i++) {
    ll sz;
    cin >> sz;
    for(ll j = 0; j < sz; j++) {
      ll x, y;
      cin >> x >> y;
      adj[i].pb(mp(x, y));
    }
  }
  ll ans = max(0LL, recurse(0, 0));
  cout << ans << endl;
  return 0;
} //good night.

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

void solve(long long S) {
  LL ans = 100000;
  while (S > 0) {
    ans = min(ans, abs(753 - S % 1000));
    S /= 10;
  }
  cout << ans << endl;
}

int main() {
  long long S;
  scanf("%lld", &S);
  solve(S);
  return 0;
}


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

int main(){
  int N,T,A;
  cin>>N>>T>>A;
  T*=1000;
  A*=1000;
  int ans;
  int m=1e9;
  int l;
  for(int i=0;i<N;i++){
    cin>>l;
    if(abs(T-l*6-A)<m){
      m=abs(T-l*6-A);
      ans=i;
    }
  }
  cout<<ans+1<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
using vll = vector<vl>;
using Pll = pair<ll, ll>;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(v) v.begin(), v.end()
#define sz(x) ((int) x.size())
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
const int MOD = 1e9+7;
const ll INF = 2e15;
template<class T> void print(const T& t){ cout << t << 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; }
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}

int main(){
  ll n;
  cin >> n;
  if(n%2==1){
    print(0);
    return 0;
  }
  ll count_5 = 0;
  ll num5 = 1;
  while(num5<=n){
    num5 *= 5;
    ll tmp = n / (num5 * 2);
    count_5 += tmp;
  }
  print(count_5);
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
struct pp
{
   string ori;
   int score;
};
pp p[510];
int c[1000];
bool cmp(const pp&a,const pp&b)
{
    if(a.ori!=b.ori)
        return a.ori<b.ori;
    else
        return a.score>b.score;
}

int main()
{
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>p[i].ori>>p[i].score;
        c[p[i].score]=i+1;
        //cout<<"+"<< c[p[i].score];

    }
     sort(p,p+n,cmp);

    for(int i=0;i<n;i++)
    {
        cout<<c[p[i].score]<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,b) for(ll i=(a);i<=(b);i++)
#define bug(x) do{cerr<<#x<<": "<<x<<"\n";}while(0)
#define bugv(x) do{cerr<#x<<': "';for(auto&e:x)cerr<<e<<" ";cerr<<"\n";}while(0)
#define END(x) do{cout<<(x)<<endl;exit(0);}while(0)

using namespace std;
using ll=long long;

int main() {
  ios_base::sync_with_stdio(false); cin.tie(nullptr);
  string s; cin >> s;
  // rep(i,0,3) if (s[i]<'0' or s[i]>'9' or s.size()!=4) END("NA\n");
  int a = (s[0]-'0')*10+s[1]-'0';
  int b = (s[2]-'0')*10+s[3]-'0';
  if(a>0 and a<=12 and b>0 and b<12) END("AMBIGUOUS");
  if( (a>0 and a<=12) or (b>0 and b<=12)) {
    if (a==0 or a>12) END("YYMM");
    if (b==0 or b>12) END("MMYY");
    END("AMBIGUOUS");
  } else END("NA\n");

  return 0;
}


Measured memory_bytes: 256
n,m=map(int,input().split())
g=[list() for _ in range(n+1)]
side=[list(map(int,input().split())) for i in range(m)]
for a,b in side:
	g[a].append(b)
	g[b].append(a)
cnt=0
def dfs(x,s):
	ed[x-1]=1
	for i in g[x]:
		if s!={x,i} and ed[i-1]==0:dfs(i,s)
cnt=0
for i in range(m):
	ed=[0]*n
	dfs(1,set(side[i]))
	if 0 in ed:cnt+=1
print(cnt)


Measured memory_bytes: 3064
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {

	static Scanner scanner;
	public static void main(String[] args) {
	    scanner = new Scanner(System.in);

	    int N=gi();
	    int M=gi();
	    long[] A=new long[M];
	    long[] B=new long[M];
	    Map<Long, Integer> map=new HashMap<Long, Integer>();

	    long sum=0;
	    for(int i=0; i<M; i++) {
	        A[i]=gl();
	        B[i]=gl();
	        if(A[i]==1) {
	        	if(map.containsKey(B[i])) {
	        		System.out.println("POSSIBLE");
                    return;
	        	} else {
	        		map.put(B[i], 0);
	        	}
	        }
	        if(B[i]==N) {
	        	if(map.containsKey(A[i])) {
	        		System.out.println("POSSIBLE");
                    return;
	        	} else {
	        		map.put(A[i], 0);
	        	}
	        }
	    }


		System.out.println("IMPOSSIBLE");
	}

	// 文字列として入力を取得
	public static String gs() {
		return scanner.next();
	}

	// intとして入力を取得
	public static int gi() {
		return Integer.parseInt(scanner.next());
	}

	// longとして入力を取得
	public static long gl() {
		return Long.parseLong(scanner.next());
	}

	// doubleとして入力を取得
	public static double gd() {
		return Double.parseDouble(scanner.next());
	}
}

Measured memory_bytes: 76292
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        //奇数２つパターン
        //偶数２つパターン
        int np = 0;
        int mp = 0;
        if (n > 1) {
            np = n*(n-1)/2;
        }
        if (m > 1) {
            mp = m*(m-1)/2;
        }
        System.out.println(np+mp);
    }
}

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

int main()
{
    ll n,k,i,j,ans=0,sum=0,a,b,c,d,x,y;
     cin>>a>>b>>c>>d;
     if(a>0&&b>0 && c>0 && d>0)
     {
               cout<<b*d;return 0;
     }
     else cout<<max(max(a*c,b*d),max(a*d,b*c));

}
//sure wrng

Measured memory_bytes: 3632
N = int(input())
arr = [[0] * 10 for _ in range(10)]
ans = 0
for i in range(1, N+1):
    s = str(i)
    head = int(s[0])
    tail = int(s[-1])
    if head == tail:
        ans += 1
    ans += arr[tail][head] * 2
    arr[head][tail] += 1
print(ans)

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

int n, m;
int p[1005];
int sum=0;

void solve(){
  for(int i=0;i<n;i++){
    cin >> p[i];
    sum+=p[i];
  }
  sort(p,p+n);
  reverse(p,p+n);
  for(int i=m-1;i<n;i+=m){
    sum-=p[i];
  }
  cout << sum << endl;
  sum=0;
}

int main(){
  while(cin >> n >> m){
    if(n==0 && m==0) break;
    solve();
  }
}

Measured memory_bytes: 3056
#include <iostream>                                   
                                                      
char judge_grade(short m, short f, short r) {         
    if(m == -1 || f == -1) return 'F';                
                                                      
    if(m + f >= 80) return 'A';                       
    if(m + f >= 65) return 'B';                       
    if(m + f >= 50) return 'C';                       
    if(m + f >= 30) {                                 
        if(r >= 50) return 'C';                       
        return 'D';                                   
    }                                                 
                                                      
    return 'F';                                       
}                                                     
                                                      
int main(int argc, char *argv[]) {                    
    int m, f, r = 0;                                  
                                                      
    while(std::cin >> m >> f >> r, !(m == -1 && f == -1 && r == -1)) {
        std::cout << judge_grade(m, f, r) << std::endl;
    }                                                 
    return 0;                                         
}

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

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

	int K;
	cin >> K;
	vector<int> foodNum(K);
	for(int i = 0; i < K; i++)
	{
		cin >> foodNum.at(i);
	}

	for(int i = 1; i < N; i++)
	{
		int K;
		cin >> K;
		vector<int> foodNum2(K);

		for(int j = 0; j < K; j++)
		{
			cin >> foodNum2.at(j);
		}

		for(int j = 0; j < foodNum.size(); j++)
		{
			bool frag = false;

			for(int l = 0; l < foodNum2.size(); l++)
			{
				if(foodNum.at(j) == foodNum2.at(l)){
					frag = true;
					break;
				}
			}

			if(frag == false){
				foodNum.erase(foodNum.begin() + j);
				j--;
			}
		}
		
		
	}

	cout << foodNum.size() << endl;
	
}

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

int main() {
  int n;
  cin >> n;
  
  if (n % 10 == 3){
    cout << "bon" << endl;
  }
  else if (n % 10 == 0 || n % 10 == 1 || n % 10 == 6 || n % 10 == 8){
    cout << "pon" << endl;
  }
  else{
    cout << "hon" <<endl;
  }
}

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

int main() {

	long long n, m; cin >> n >> m;	
	
	vector<long long> c;
	for (long long i = 1; i * i <= m; ++i) {
		if (m % i == 0LL) {
			if(i * n <= m) c.push_back(i);
			if (m / i * n <= m) c.push_back(m / i);
		}
	}
	
	sort(c.begin(), c.end());

	cout << c[c.size() - 1] << endl;
	return 0;
}

Measured memory_bytes: 256
N, K = gets.split.map(&:to_i)
L = []
R = []
K.times do
    l, r = gets.split.map(&:to_i)
    L << l
    R << r
end

MOD = 998244353

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

dp[0] = 1

for i in 1 .. N - 1
    sp[i] = (sp[i - 1] + dp[i - 1]) % MOD
    for l, r in L.zip(R)
        dp[i] += sp[[0, i - l + 1].max] - sp[[0, i - r].max]
    end
    dp[i] %= MOD
end

puts dp[N - 1]

Measured memory_bytes: 17524
/*** akshaykumar99 ***/
 
#include<bits/stdc++.h> 
using namespace std;
 
const long long MOD = 1e9+7;
const long double PI = acos(-1);
const long long N = 5e2+1;
 
typedef long long ll;
typedef long double ld;

void test_case()
{
	ll n, x, t;
	cin >> n >> x >> t;
	ll z = ceil(n * 1.0 / x);
	cout << z * t << '\n';

}
 
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL); 
    ll tc=1;
    // cin>>tc;
    while(tc--)
        test_case();
    return 0;
}


Measured memory_bytes: 3612