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

int pl(int &a, int b){
  if(a + b <= 0){
    int c = - a - b + 1;
    a = 1;
    return c;
  }
  else{
    a += b;
    return 0;
  }
}

int mi(int &a, int b){
  if(a + b >= 0){
    int c = a + b + 1;
    a = - 1;
    return c;
  }
  else{
    a += b;
    return 0;
  }
}

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for(int i = 0; i < n; i++) cin >> a.at(i);
  
  int pl_sum = 0;
  int mi_sum = 0;
  long long pl_ans = 0;
  long long mi_ans = 0;
  
  for(int i = 0; i < n; i++){
    if(i % 2){
      pl_ans += mi(pl_sum, a.at(i));
      mi_ans += pl(mi_sum, a.at(i));
    }
    else{
      pl_ans += pl(pl_sum, a.at(i));
      mi_ans += mi(mi_sum, a.at(i));
    }
  }
  
  cout << min(pl_ans, mi_ans) << endl;
}

Measured memory_bytes: 640
//#include <bits/stdc++.h>
#include<iostream>
#include<stdio.h>
#include<bitset>
#include<algorithm>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<string>
#include<string.h>
#include<cmath>
#include<utility>
#include<functional>
#include<map>
#include<set>


#define FOR(i, a, b) for(long long int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for(long long int i=(a);i>=(b);i--)
#define MOD 1000000007
#define INF 1000000000 //2000000000
#define LLINF 1000000000000000000 //9000000000000000000
#define PI 3.14159265358979

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


int main(void) {

	while (1) {
		int n;
		int maxi = -1;
		int dp[86402] = {};
		int h, m, s;
		char c, d;

		cin >> n;
		if (n == 0) {
			break;
		}
		FOR(i, 1, n) {
			scanf("%2d%c%2d%c%2d", &h, &c, &m, &d, &s);
			dp[h * 3600 + m * 60 + s]++;
			scanf("%2d%c%2d%c%2d", &h, &c, &m, &d, &s);
			dp[h * 3600 + m * 60 + s ]--;
		}
		FOR(i, 1, 86401) {
			dp[i] += dp[i - 1];
		}
		FOR(i, 1, 86401) {
			if (dp[i] > maxi) {
				maxi = dp[i];
			}
		}
		cout << maxi << endl;
	}

	return 0;
}


Measured memory_bytes: 3496
//
// Created by Kiran Chavhan on 21/06/2020.
//

#include<iostream>
#include <vector>
#include <algorithm>

#define int long long
#define MOD 1000000007
using namespace std;

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,k;
    cin>>n>>k;
    vector<int>v(n);
    for(int i=0;i<n;i++){
        cin>>v[i];
    }
    sort(v.begin(),v.end());
    int sum=0;
    for(int i=0;i<k;i++){
        sum+=v[i];
    }
    cout<<sum;
}

Measured memory_bytes: 3196
#include <iostream>
#include <vector>
#include <string>
#define SIZE 3005

 std::string a,b;
 std::vector <int> text;
 int res, dp[SIZE][SIZE];

 int lcsLen() {
   for (int i=0; i<=a.length(); i++) {
     for (int j=0; j<=b.length(); j++) {

       if (i == 0 || j == 0) dp[i][j] = 0;
       else if (a[i-1] == b[j-1]) dp[i][j] = dp[i-1][j-1] + 1;
       else dp[i][j] = std::max(dp[i-1][j], dp[i][j-1]);

     }
   }

   return dp[a.length()][b.length()];

 }


 int main(void) {
    std::cin >> a >> b;
    res = lcsLen();

    char text[res+1];
    int  i=a.length(), j=b.length();
    text[res] = '#';

    while(i && j) {
       if(a[i-1] == b[j-1]) {
           text[--res] = a[--i];
           j--;
       } else if(dp[i-1][j] > dp[i][j-1]) i--;
         else j--;
    }

    int k=0;
    while(text[k] != '#') std::cout << text[k++];

    return 0;
 }




Measured memory_bytes: 35456
#include <bits/stdc++.h>
using namespace std;
#define fastio() ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define test() int t; cin>> t; while (t--)
#define scan(a, i) for (int j = 0; j < i; j++) cin>> a[j];
#define print(a, i) for (int j = 0; j < i; j++) cout<< a[j]<< endl;
int main() 
{
    fastio()
    int a, b, c, d;
    cin>> a>> b>> c>> d;
    if (a + b > c + d)
        cout<< "Left"<< endl;
    else if (a + b == c + d)    
        cout<< "Balanced"<< endl;
    else
        cout<< "Right"<< endl;
    return 0;
}


Measured memory_bytes: 256
#import numpy as np
import sys, math
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial#, gcd
from bisect import bisect_left, bisect_right #bisect_left(list, value)
sys.setrecursionlimit(10**7)
enu = enumerate
MOD = 10**9+7
def input(): return sys.stdin.readline()[:-1]
pl = lambda x: print(*x, sep='\n')

N = int(input())
S = [input() for _ in range(N)]

res = defaultdict(int)
for s in S:
    res[s] += 1

# print(res)
ans = ['AC', 'WA', 'TLE', 'RE']
for an in ans:
    if res[an]>0:
        print(an, 'x', res[an])
    else:
        print(an, 'x', 0)


Measured memory_bytes: 80364
import bisect

N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=list(map(int,input().split()))
A.sort()
B.sort()
C.sort()

ans = 0
for i in range(N):
    a = bisect.bisect_left(A,B[i])
    c = N - bisect.bisect_right(C,B[i])
    ans += a*c
print(ans)

Measured memory_bytes: 23232
#include <iostream>
using namespace std;
int main(void){
    
    int n,a,b,c,d,e,f,g,h;
    cin>>n>>a>>b>>c>>d;
    
    e = n / a;
    
    if(e * a < n){
        e = e + 1;
    }
    
    f = n / c;
    
    if(f * c < n){
        f = f + 1;
    }
    
    g = e * b;
    h = f * d;
    
    if(g < h){
        cout <<g<<endl;
    }else{
        cout <<h<<endl;
    }
}



Measured memory_bytes: 3116
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
#include<set>
#include<string>
#include<functional>
#include<queue>
#include<stack>
#include<math.h>
#define INF 999999

using namespace std;

typedef long long ll;

vector<int>primenumber;
int d[1050000];

int main()
{
	int n;
	
	primenumber.push_back(2);
	d[2] = 1;

	int maxn = 0;

	while (cin >> n) {
		if (maxn<n) {
			for (int i = max(maxn+1,3); i <= n; i++) {
				int ope = 1;
				for (int j = 0; j < primenumber.size(); j++) {
					if (primenumber[j] * primenumber[j] > i)break;
					if (i%primenumber[j] == 0) {
						ope = 0;
						break;
					}
				}
				if (ope == 1)primenumber.push_back(i);
				d[i] = primenumber.size();
			}
			maxn = n;
		}
		cout << d[n] << endl;
	}
	
	return 0;
}

Measured memory_bytes: 7044
#include<bits/stdc++.h>
#define N 1000005
#define mod 1000000007
using namespace std;
template<typename T>
inline void in(T &x)
{
	x=0;
	char c=getchar();
	bool fu=0;
	while(c<'0'||c>'9'){if(c=='-')fu=1;c=getchar();}
	while(c>='0'&&c<='9')x=(x<<1)+(x<<3)+(c^48),c=getchar();
}
int n,a[N],has[N];
bool not_prime[N],pairwise=1,setwise=1;
void produce(int lim)
{
	not_prime[1]=1;
	for(int i=2;i<=lim;++i)
	{
		if(!not_prime[i])
		{
			bool flag=0;
			int cnt=0;
			if(has[i])cnt+=has[i];
			for(int j=i+i;j<=lim;j+=i)
			{
				not_prime[j]=1;
				if(has[j])
				{
					cnt+=has[j];
				}
			}
			if(cnt>1)pairwise=0;
			if(cnt==n)setwise=0;
		}
	}
}
int main()
{
	in(n);
	for(int i=0;i<n;++i)
	{
		int t;
		in(t);
		++has[t];
	}
	produce(N-1);
	if(pairwise)puts("pairwise coprime");
	else if(setwise)puts("setwise coprime");
	else puts("not coprime");
	return 0;
}

Measured memory_bytes: 8524
import sys
sys.setrecursionlimit(10**9)

maxK = 10**5
#maxK = 20

K = int(input())

As = []
def dfs(i, maxD, x):
    if i == maxD:
        As.append(x)
        if len(As) >= maxK:
#            print(As)
            print(As[K-1])
            sys.exit()
    else:
        y = x%10
        x *= 10
        if y-1 >= 0:
            dfs(i+1, maxD, x+y-1)
        dfs(i+1, maxD, x+y)
        if y+1 <= 9:
            dfs(i+1, maxD, x+y+1)

for d in range(1, 11):
    for x in range(1, 10):
        dfs(1, d, x)


Measured memory_bytes: 7236
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using VI = vector<int>;
using VL = vector<ll>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);(i)++)
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);(i)++)
#define rFOR(i,a,n) for(int (i)=(n)-1;(i)>=(a);(i)--)
#define erFOR(i,a,n) for(int (i)=(n);(i)>=(a);(i)--)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
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; }
inline void init() { cout.tie(nullptr); cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }

struct edge {
    int from, to; ll cost;
    edge(int s, int t, ll w = 0) : from(s), to(t), cost(w) {}
};
bool tpz(vector<vector<edge>> g, VI& ans, VI& len) {
    int v = g.size(); ans.clear(), len.resize(v, 0);
    vector<int> in(v, 0);
    for (auto es : g)for (edge e : es)in[e.to]++;
    queue<int> que;
    FOR(i, 0, v)if (in[i] == 0) {
        que.push(i);
        len[i] = 1;
    }

    while (!que.empty()) {
        int now = que.front(); que.pop();
        ans.push_back(now);
        for (edge next : g[now]) {
            if (--in[next.to] == 0) {
                que.push(next.to);
                chmax(len[next.to], len[now] + 1);
            }
        }
    }
    return v == ans.size();
}

int main() {
    init();

    int n;
    cin >> n;
    vector<VI> a(n, VI(n)), wh(n, VI(n, -1));
    FOR(i, 0, n)FOR(j, 0, n - 1) {
        cin >> a[i][j];
        wh[i][--a[i][j]] = j;
    }

    vector<vector<edge>> g(n * (n - 1) / 2);
    map<pair<int, int>, int> map;
    int o = 0;
    FOR(i, 0, n)FOR(j, 0, n - 1) {
        int x = i, y = a[i][j];
        if (x > y)swap(x, y);
        if (map[{x, y}])continue;
        if ((i != 0 || j != 0) && (x == 0 && y == a[0][0]))continue;
        map[{x, y}] = o++;
    }
    FOR(i, 0, n)FOR(j, 0, n - 2) {
        int x = i, y = a[i][j], X = i, Y = a[i][j + 1];
        if (x > y)swap(x, y);
        if (X > Y)swap(X, Y);
        g[map[{ x, y }]].push_back(edge(map[{ x, y }], map[{ X, Y }], 1));
    }
    
    VI ans, len;
    if (tpz(g, ans, len)) {
        int mlen = 0;
        for (int i : len)chmax(mlen, i);
        cout << mlen << "\n";
    }
    else cout << "-1\n";
}


Measured memory_bytes: 117488
import java.util.*;
class Main{
public static void main(String args[]){
Scanner sc =new Scanner(System.in);
List<String> store = new ArrayList<String>();
while(sc.hasNextLine()){
store.add(sc.nextLine());
}
String[] input = store.get(0).split(" "); 
int W = Integer.parseInt(input[0]);
int H = Integer.parseInt(input[1]);
int x = Integer.parseInt(input[2]);
int y = Integer.parseInt(input[3]);
int r = Integer.parseInt(input[4]);
if(x>=r && x<=W-r && y>=r && y<=H-r){
System.out.println("Yes");
}else{
System.out.println("No");
}
}
}

Measured memory_bytes: 26332
fun main(){
    val n = readLine()!!.split(" ").map { it.toInt() }[0]
    val a = n % 10
    if (a == 2 || a == 4 || a == 5 || a== 7 || a == 9) println("hon")
    else if (a == 0 || a == 1 || a== 6 || a == 8) println("pon")
    else println("bon")
}

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

int main(){
  int a, b, c, k, ans=0;
  cin >> a >> b >> c >> k;

  if(k<=a)ans = k;
  else if(a<k&&k<=a+b)ans = a;
  else ans = a-(k-a-b);

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


Measured memory_bytes: 3632
'''
問題：
    a,b,c からなる長さ 3 の文字列 S が与えられます。
    S を abc を並び替えて作ることができるかどうか判定してください。
'''
'''
制約：
    |S|=3
    S は a,b,c からなる
'''

def abc093a(input: str) -> str:
    str_list = ["abc", "acb", "bac", "bca", "cab", "cba"]

    if input not in str_list:
        return "No"
    else:
        return "Yes"

s = str(input())
print(abc093a(s))


Measured memory_bytes: 8972
#include "bits/stdc++.h"
using namespace std;
#define Rep(i,n) for(int i=0;i<(int)(n);i++)
#define For(i,n1,n2) for(int i=(int)(n1);i<(int)(n2);i++)
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define RREP(i,n) for(ll i=((ll)(n)-1);i>=0;i--)
#define FOR(i,n1,n2) for(ll i=(ll)(n1);i<(ll)(n2);i++)
#define RFOR(i,n1,n2) for(ll i=((ll)(n1)-1);i>=(ll)(n2);i--)
#define all(a)  (a).begin(),(a).end()
#define SORT(a) sort((a).begin(),(a).end())
#define oorret 0
#define oor(x) [&](){try{x;} catch(const out_of_range& oor){return oorret;} return x;}()
#define IOS cin.tie(0),ios::sync_with_stdio(false)
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
template<typename T1, typename T2> inline bool chmin(T1& a, T2 b) { if (a > b) { a = b; return 1; }return 0; }
template<typename T1, typename T2> inline bool chmax(T1& a, T2 b) { if (a < b) { a = b; return 1; }return 0; }
template<class Type>struct is_vector : std::false_type {};
template<class ValueType, class Alloc>struct is_vector<std::vector<ValueType, Alloc>> : std::true_type {};
template <typename T> inline ostream& operator << (ostream& out, const vector<T>& v) {
	if (v.empty())return out;
	constexpr bool is_vector_v = is_vector<T>::value;
	if (is_vector_v)for (auto itr = v.begin(); itr != v.end();)out << (*itr), out << ((++itr != v.end()) ? "\n" : "");
	else for (auto itr = v.begin(); itr != v.end();)out << (*itr), out << ((++itr != v.end()) ? " " : "");
	return out;
}
inline void put() {}
template<class T> inline void put(const T& first) { std::cout << first << "\n"; }
template<class T, class... N> inline void put(const T& first, const N& ... rest) { std::cout << first << " "; put(rest...); }
inline void putn() {}
template<class T, class... N> inline void putn(const T& first, const N& ... rest) { std::cout << first << "\n"; putn(rest...); }

int main() {
	IOS;
	int a, b, x;
	cin >> a >> b >> x;
	double res;
	if (a * a * b / 2 >= x) {
		double t = (double)2 * x / a / b / b;
		res = atan(t);
		const double pi = 3.14159265358979;
		res *= 360;
		res /= pi * 2;
		res = 90 - res;
	} else {
		int t = a * a * b - x;
		double temp = (double)t / a / a / a * 2;
		res = atan(temp);
		const double pi = 3.14159265358979;
		res *= 360;
		res /= pi * 2;
		
	}
	
	cout << setprecision(20) << res << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define f first
#define sc second
using namespace std;
typedef long long int ll;
typedef string str;
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    bool x; cin >> x;
    cout << !x << "\n";
}


Measured memory_bytes: 3652
#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <set>

using namespace std;

int bfs(int n, vector<set<int> > vs, vector<int> val,  set<int> s, int sum, int node) {
    if (node == n) return sum;
    
    set<int> a, b;
    a = s;
    b = vs[node];
    a.insert(b.begin(), b.end());
    if (a.size() == s.size() + b.size()) {
        return max(bfs(n, vs, val, s, sum, node+1), bfs(n, vs, val, a, sum+val[node], node+1));
    }
    else return bfs(n, vs, val, s, sum, node+1);
}

int main(void){
    int n;
    while (cin>>n && n) {
        vector<set<int> > vs(n);
        vector<int> val(n);
        for (int i = 0; i < n; i++) {
            int m;
            cin >> m >> val[i];
            for (int j = 0; j < m; j++) {
                int a, b;
                cin >> a >> b;
                for (int k = a; k < b; k++) vs[i].insert(k);
            }
        }
        set<int> s;
        int ans = bfs(n, vs, val, s, 0, 0);
        cout << ans << endl;
    }
}

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

#入力ループ
list = []
for i in range(n):
    list.append(int(input()))

#入力リストを降順にソート
new_list = sorted(list,reverse=True)

#出力ループ
for c in range(n):
    if new_list[0] == list[c]:
        print(new_list[1])
    else:
        print(new_list[0])


Measured memory_bytes: 14112
fn main() {
	let mut s = String::new();
	use std::io::Read;
	std::io::stdin().read_to_string(&mut s).unwrap();
	let mut s = s.split_whitespace();
	let x: usize = s.next().unwrap().parse().unwrap();
	let y: usize = s.next().unwrap().parse().unwrap();
	let a: usize = s.next().unwrap().parse().unwrap();
	let b: usize = s.next().unwrap().parse().unwrap();
	let c: usize = s.next().unwrap().parse().unwrap();
	let mut p: Vec<i64> = s.by_ref().take(a).map(|a| a.parse().unwrap()).collect();
	let mut q: Vec<i64> = s.by_ref().take(b).map(|a| a.parse().unwrap()).collect();
	p.sort_by_key(|&a| std::cmp::Reverse(a));
	q.sort_by_key(|&a| std::cmp::Reverse(a));
	p.truncate(x);
	q.truncate(y);
	p.extend(q);
	p.extend(s.take(c).map(|a| a.parse::<i64>().unwrap()));
	p.sort();
	println!("{}", p.iter().rev().take(x + y).sum::<i64>());
}


Measured memory_bytes: 8200
// include
// ------------------------------------------------
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <math.h>

using namespace std;

// func
// ------------------------------------------------
int CalcSumOfDigit(int n);      // 各桁の和を計算する。
long long getDigit(long long n);      // 数字の桁数を取得する。
string upper(string str);       // 英字を大文字に変換する。
string lower(string str);       // 英字を小文字に変換する。

// define
// ------------------------------------------------
#define all(a)        (a).begin(),(a).end()
#define rall(a)       (a).rbegin(),(a).rend()
#define sz(a)         int((a).size())
#define rep(i,n)      for(int(i)=0;(i)<(n);(i)++)
#define repe(i,n)     for(int(i)=0;(i)<=(n);(i)++)
#define vsort(v)      sort((v).begin(),(v).end())
#define rvsort(v)     sort(rall((v)))
#define vi            vector<int>
#define GCD(a,b)      __gcd((a),(b))
#define LCM(a,b)      ((a)/GCD((a),(b))*(b))
#define kiriage(a,b)  ((a)+(b)-1)/(b)

const int INF = 1e9;

typedef long long ll;
typedef unsigned long long ull;

// code
// ------------------------------------------------
int main() {

  ll n,m;
  map<ll,ll> d,t;
  cin >> n;
  rep(i,n)
  {
    ll buf;
    cin >> buf;
    d[buf]++;
  }

  cin >> m;
  rep(i,m)
  {
    ll buf;
    cin >> buf;
    t[buf]++;
  }
  
  bool flg = true;
  for(auto itr = t.begin(); itr != t.end(); ++itr)
  {
    ll t_n = itr->first;
    ll t_v = itr->second;
    if(d[t_n] < t_v)
    {
      flg = false;
      break;
    }
  }

  if(flg) cout << "YES" << endl;
  else cout << "NO" << endl;


  
  return 0;
}
// funcの実体
// ------------------------------------------------
ll getDigit(ll n)
{
  int i = 1;
  while(1)
  {
    n = n / 10;
    if(n == 0)
      break;
    i++;
  }
  return i;
}
ll CalcSumOfDigit(ll n)
{
  ll s = 0;
  while(n)
  {
    s += n % 10;
    n = n / 10;
  }
  return s;
}

string upper(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(97 <= *itr && *itr <= 122)
    {
      *itr = *itr - 32;
    }
  }
  return str;
}

string lower(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(65 <= *itr && *itr <= 90)
    {
      *itr = *itr + 32;
    }
  }
  return str;
}


Measured memory_bytes: 25216
#include <bits/stdc++.h>
using namespace std;
#define PII pair<int, int>
#define LL long long
#define LD long double
#define VI vector<int>
#define VPII vector<PII>
#define F first
#define S second
#define MP make_pair
#define PB push_back
#define pb pop_back
#define FOR(a,s,d) for (int a = (s); a <= (int)(d); ++a)
#define FORD(a,s,d) for (int a = (s); a >= (int)(d); --a)
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define ALL(x) x.begin(), x.end()
#define siz(x) ((int)x.size())
#define Sim template <class s
Sim, class d> ostream & operator<<(ostream &os, pair<s,d> x){return os << "<" << x.f << ", " <<
  x.s << "> ";}
Sim> auto operator<<(ostream &os, s x) -> typename enable_if<!is_same<s,string>::value,
  decltype(x.begin(), os)>::type
{ int o = 0; os << "{"; for (auto c : x) {if(o++) os << ", "; os << c;}return os << "} ";}
void dor() {cerr << endl;}
Sim, class ...t> void dor(s x, t...y) {cerr << x << " "; dor(y...);}
#ifdef DEB
#define debug(c...) dor(__FUNCTION__, ":", __LINE__, ": ", c)
#else
#define debug(...)
#endif
const int M = 55;

int n, T[2][M];
bool dp[M][M][M];
set<int> S[M][M];

bool must(int a, int b)
{
  for (auto x : S[a][b])
  {
    if (dp[a - 1][x][T[1][b]])
    {
      return false;
    }
  }
  return true;
}

int main()
{
  //ios_base::sync_with_stdio(0);
  //cin.tie(0);
  for (int i = 0; i < M; i++)
  {
    dp[0][i][i] = true;
  }
  for (int i = 1; i < M; i++)
  {
    for (int j = 0; j < M; j++)
    {
      for (int k = 0; k <= j; k++)
      {
        dp[i][j][k] = dp[i - 1][j][k] | dp[i - 1][j % i][k];
      }
    }
  }
  scanf("%d", &n);
  for (int j = 0; j < 2; j++)
  {
    for (int i = 0; i < n; i++)
    {
      scanf("%d", T[j] + i);
      if (j == 0)
      {
        S[M - 1][i].insert(T[j][i]);
      }
    }
  }
  for (int i = 0; i < n; i++)
  {
    if (!dp[M - 1][T[0][i]][T[1][i]])
    {
      printf("-1\n");
      return 0;
    }
  }
  LL res = 0;
  for (int i = M - 1; i > 0; i--)
  {
    bool cant = false;
    for (int j = 0; j < n; j++)
    {
      if (must(i, j))
      {
        cant = true;
        break;
      }
    }
    if (cant)
    {
      res += (1LL<<i);
    }
    for (int j = 0; j < n; j++)
    {
      for (auto x : S[i][j])
      {
        S[i - 1][j].insert(x);
        if (cant)
        {
          S[i - 1][j].insert(x % i);
        }
      }
    }
  }
  printf("%lld\n", res);
  return 0;
}

Measured memory_bytes: 1920
#include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i,N) for(LL i=0;i<N;++i)
typedef long long int LL;

LL N, Q;
std::string s;
std::vector<char>t, d;

bool check1(LL p)
{
	rep(i, Q)
	{
		if (s[p] == t[i])
		{
			if (d[i] == 'L') --p;
			else ++p;
		}
		if (p < 0) return true;
		if (p >= N) return false;
	}
	return false;
}

bool check2(LL p)
{
	rep(i, Q)
	{
		if (s[p] == t[i])
		{
			if (d[i] == 'L') --p;
			else ++p;
		}
		if (p < 0) return false;
		if (p >= N) return true;
	}
	return false;
}

int main()
{
	in >> N >> Q >> s;
	t.resize(Q); d.resize(Q);
	rep(i, Q) in >> t[i] >> d[i];

	LL left1 = 0, right1 = N + 1;
	while (right1 - left1 > 1)
	{
		LL mid = (left1 + right1) / 2;
		if (check1(mid)) left1 = mid;
		else right1 = mid;
	}

	LL left2 = -1, right2 = N;
	while (right2 - left2 > 1)
	{
		LL mid = (left2 + right2) / 2;
		if (check2(mid)) right2 = mid;
		else left2 = mid;
	}

	out << std::max<LL>(left2 - right1 + 1, 0) << std::endl;
}


Measured memory_bytes: 900
#include <bits/stdc++.h>
#define pt(sth) cout << sth << "\n"
#define chmax(a, b) {if(a<b) a=b;}
#define chmin(a, b) {if(a>b) a=b;}
#define moC(a, s, b) (a)=((a)s(b)+MOD)%MOD
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
static const ll INF=1e18;
static const ll MAX=101010;
static const ll MOD=1e9+7;

/*
 for(i=0; i<N; i++)
   cin >> a[i];
*/


int main(void) {
  ll i, j, k;
  string s;
  cin >> s;
  
  ll cnt=0;
  string t="";
  for(i=0; i<s.size(); i++) {
    if(s[i]=='A') cnt++;
    else t+=s[i];
  }
  
  ll f=1;
  if(t!="KIHBR") f=0;
  if(cnt>4) f=0;
  
  for(i=0; i<s.size(); i++) {
    string s2=s.substr(i, 2);
    
    if(s2=="KA") f=0;
    if(s2=="IA") f=0;
    if(s2=="AA") f=0;
  }
  
  if(f) pt("YES");
  else pt("NO");
  
}



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

int main(){
	string s;
	cin>>s;
	int a=s[0]-'0';
	if(s.size()>1&&s[s.size()-1]!='9'){
		cout<<(s.size()-1)*9+a-1<<endl;
	}
	else if(s.size()>1){
		cout<<(s.size()-1)*9+a<<endl;
	}
	else{
		cout<<a<<endl;
	}
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	_ "container/heap"
	"fmt"
	"math"
	"os"
	_ "sort"
	"strconv"
)

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

// Arithmetic
func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

func ceil(a, b int) int {
	if a%b == 0 {
		return a / b
	} else {
		return a/b + 1
	}
}

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

func lcm(a, b int) int {
	return a / gcd(a, b) * b
}

// Sort
type RuneSlice []rune

func (a RuneSlice) Len() int           { return len(a) }
func (a RuneSlice) Less(i, j int) bool { return a[i] < a[j] }
func (a RuneSlice) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

// Main
const MOD = int(1e+9) + 7
const INF = 1 << 60

func main() {
	sc := NewScanner()
	wtr := bufio.NewWriter(os.Stdout)
	defer wtr.Flush()
	L := sc.nextFloat()
	q := math.Pow(L, 3)

	fmt.Fprintln(wtr, q/27.0)
}


Measured memory_bytes: 640
N = int(input())
S = input()
tmp_c = 0
count = 0
for i in range(N):
    if tmp_c == 0 and S[i]=="A":
        tmp_c = tmp_c + 1
    elif tmp_c == 1 and S[i]=="B":
        tmp_c = tmp_c + 1
    elif tmp_c == 1 and S[i]=="A":
        tmp_c = 1
    elif tmp_c == 1:
        tmp_c = 0
    elif tmp_c == 2 and S[i]=="C":
        count = count + 1
        tmp_c = 0
    elif tmp_c == 2 and S[i]=="A":
        tmp_c = 1
    elif tmp_c == 2:
        tmp_c = 0
print(count)
    


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

int main() {
	int N;
	string S;
	cin >> N >> S;
	int ans = 0;
	for (int i = 0; i+2 < N; ++i) {
		if (S.substr(i, 3) == "ABC") {
			++ans;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 3572
n = int(input())
d = [0]*n

for i in range(n):
  d[i] = int(input())
  
d.sort()

ans = 0

i = 0
while True:
  if i == n-1:
    break
  if d[i] != d[i+1]:
    ans += 1
    i += 1
  else:
    if max(d) == d[i]:
      break
    else:
      i += 1
print(ans+1)

Measured memory_bytes: 63792
#include<bits/stdc++.h>
#define INF 9223372036854775807LL
#define inf 1000000007
#define SYOU(x) setprecision(x+1)
#define lol long long
#define mp make_pair
#define fi first
#define se second
using namespace std;
using pii = pair<int, int>;
lol abs(lol x,lol y){return(x>y?x-y:y-x);}
lol max(lol x,lol y){if(x>y)return x;return y;}
lol min(lol x,lol y){if(x<y)return x;return y;}
int han[100010];
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >>n;
  int d[100001];
  for(int i=0;i<n;i++){
    cin >>d[i];
    han[d[i]]++;
  }
  int p=n/2;
  int sum=0;
  int ans=0;
  for(int i=1;i<=100000;i++){
    sum+=han[i];
    if(p==sum) ans++;
  }
  cout <<ans<<'\n';
  return (0);
}


Measured memory_bytes: 1024
import java.util.*;
import java.io.*;
import java.math.BigInteger;
 
public class Main {
	public static long mod = 1000000007;
	
	public static void main(String[] args) {
	Scanner s = new Scanner(System.in);
	long a = s.nextLong();
	long b = s.nextLong();
	long c = s.nextLong();
	long d = s.nextLong();
	
	long max = Long.MIN_VALUE;
	max = Math.max(max, a*c);
	max = Math.max(max, a*d);
	max = Math.max(max, b*c);
	max = Math.max(max, b*d);

	System.out.println(max);
    
  }
}

Measured memory_bytes: 35744
#include <stdio.h>
#include <string.h>

int main(void)
{
	int i, sum;
	char x[1001];
	
	while (1) {
		scanf("%s", x);
		if (!strcmp(x, "0")) {
			break;
		}
		
		sum = 0;
		i = 0;
		while (x[i] != '\n' && x[i] != '\0') {
			sum += x[i] - '0';
			i++;
		}
		printf("%d\n", sum);
	}
	
	return 0;
}

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

int main(){
  int N, X;
  cin >> N >> X;
  vector <int> m(N);
  for (int i=0; i<N; i++){
    cin >> m[i];
  }
  int sum=0;
  for (int i=0; i<N; i++){
    sum+=m[i];
  }
  int count=N;
  sort(m.begin(),m.end());
  while (1){
    sum+=m.at(0);
    count++;
    if (sum>X){
      break;
    }
  }
  cout << count-1 << endl;
}



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

using namespace std;

struct node { int parent, left, right; };
node t[100005];
bool iniflg = true;

int pretreewalk(int nodenum) {
	if (nodenum == -1) {
		return 0;
	}
	cout << " " << nodenum;
	pretreewalk(t[nodenum].left);
	pretreewalk(t[nodenum].right);
	return 0;
}
int intreewalk(int nodenum) {
	if (nodenum == -1) {
		return 0;
	}
	intreewalk(t[nodenum].left);
	cout << " " << nodenum;
	intreewalk(t[nodenum].right);
	return 0;
}
int posttreewalk(int nodenum) {
	if (nodenum == -1) {
		return 0;
	}
	posttreewalk(t[nodenum].left);
	posttreewalk(t[nodenum].right);
	cout << " " << nodenum;
	return 0;
}

int main() {

	int n;
	cin >> n;

	for (int i = 0; i < n; i++) {
		t[i].parent = -1;
		t[i].left = -1;
		t[i].right = -1;
	}

	for (int i = 0; i < n; i++) {

		int nodenum;
		int c1, c2;
		cin >> nodenum >> c1 >> c2;

		t[nodenum].left = c1;
		t[nodenum].right = c2;
		t[c1].parent = nodenum;
		t[c2].parent = nodenum;

	}
	int inival=0;
	for (int i = 0; i < n; i++) {
		if (t[i].parent == -1) { inival = i; break; }
	}

	cout << "Preorder" << endl;
	pretreewalk(inival);
	cout << endl;
	cout << "Inorder" << endl;
	intreewalk(inival);
	cout << endl;
	cout << "Postorder" << endl;
	posttreewalk(inival);
	cout << endl;

}


Measured memory_bytes: 3100
#include <iostream>
#include <vector>

using namespace std;

int main(){
  int h, w;
  cin >> h >> w;
  vector<string> i_str(h+2);
  string top_last_str(w+2, '#');
  i_str.at(0) = top_last_str;
  for (int i = 0; i < h; ++i){
    string temp;
    cin >> temp;
    temp = "#" + temp + "#";
    i_str.at(i+1) = temp; 
  }
  i_str.at(h + 1) = top_last_str;
  for (int i = 0; i < h + 2; ++i){
    cout << i_str.at(i) << endl;
  }
}

Measured memory_bytes: 3604
#include<bits/stdc++.h>
using namespace std;
string s[101][101];
int n,m;
int main(){
	cin>>n>>m;
	for(int i=1;i<=n;i++)
	    for(int j=1;j<=m;j++){
	    	cin>>s[i][j];
	    	if(s[i][j]=="snuke"){
	    		cout<<(char)(j+'A'-1);
	    		cout<<i;
	    		cout<<endl;
	    		return 0;
			}
		}
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define MAX (ll)(1e5)
#define MOD (ll)(1e9 + 7)
#define INF (ll)(1e18 + 3)
#define PI (double)(3.14159265)

using namespace std;
using ll = long long;
using ld = long double;

int main () {
	int n;
	cin >> n;
	string st;
	cin >> st;
	for (int i = 0; i < st.size (); i++) {
		int xx = st[i] - 'A';
		xx += n;
		xx %= 26;
		cout << char ('A' + xx);
	}
	cout << "\n";
}
		


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define vl vector
#define pb push_back
using namespace std;
int main()
{
    ll a,b,i,j,n,k;
    string s;
    cin>>n>>s;
    ll flag=0;
    for(i=0;i<1000;i++)
    {
        string t;
        t=to_string(i);
        a=t.size();
        for(j=0;j<3-a;j++)
        {
            t="0"+t;
        }
        k=0;
        for(j=0;j<s.size();j++)
        {
            if(s[j]==t[k]) k++;
            if(k==3) break;
        }
        if(k==3) flag++;
    }
    cout<<flag;
}

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

int a, b;

int main() {
	cin >> a >> b;
	if(a > b) swap(a, b);
	if(a == 1 && b == 2) cout << 3;
	if(a == 2 && b == 3) cout << 1;
	if(a == 1 && b == 3) cout << 2;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
int main()
{
    int m, f, r;
    char Grade;
    while(true){
        std::cin >> m >> f >> r;
        if (m == -1 && f == -1 && r == -1){
            break;
        } else if (m == -1 || f == -1){
            Grade = 'F';
        } else if (m + f >= 80){
            Grade = 'A';
        } else if (m + f >= 65){
            Grade = 'B';
        } else if (m + f >= 50){
            Grade = 'C';
        } else if (m + f >= 30){
            if (r >= 50){
                Grade = 'C';
            } else {
                Grade = 'D';
            }
        } else {
            Grade = 'F';
        }
        std::cout << Grade << std::endl;
    }
    return 0;
}

Measured memory_bytes: 3100
#include <bits/stdc++.h>
#include <algorithm>
#include <math.h>
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
#define INF 999999999
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

using llong = long long;
using namespace std;

int main(){
    llong n,h[100002];
    cin >> n;
    rep(i,n) cin >> h[i];
    reverse(h,h+n);
    rep(i,n-1){
        if(h[i] < h[i+1]){
            if(h[i] == h[i+1]-1) h[i+1]--;
            else{
                cout << "No" << endl;
                return 0;
            }
        }
    }
    cout << "Yes" << endl;
}

Measured memory_bytes: 1024
using System;

class Program
{
    static void Main(string[] args)
    {
        var x = int.Parse(Console.ReadLine());
        var ans = 1L;

        for (int i = 2; i <= x; i++)
        {
            if (prim(i))
            {
                var ei = 0;
                for (int j = 2; j <= x; j++)
                {
                    ei += ord(i, j);
                }
                ans = ans * (ei + 1) % 1000000007;
            }
        }

        Console.WriteLine(ans);
    }

    static int ord(int n, int m)
    {
        var ans = 0;
        while (m % n == 0)
        {
            ans++;
            m /= n;
        }
        return ans;
    }

    static bool prim(int n)
    {
        for (int i = 2; i < n; i++)
        {
            if (n % i == 0)
            {
                return false;
            }
        }
        return true;
    }
}


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

using namespace std;

#define rep(i, n) for(int i = 0; i < n; ++i)
#define all(x) (x).begin(),(x).end()
#define endl "\n"

using ll = long long;
using P = pair<int,int>;

const int MOD = 1e9 + 7;
const int INF = 1001001001;

int main (){
    string s;
    cin >> s;

    int ans = 0;
    rep(i, 6){
        if(s[i] == '1'){
            ans++;
        }
    }

    cout << ans << endl;


    return 0;
}

Measured memory_bytes: 256
N = int(input())
S = input()

from collections import Counter

m = Counter(S)

ans = m['R']*m['G']*m['B']
non = 0


for i in range ((N-1)//2):
    st = 0
    while st + (i+1)*2 < N:
        if S[st] != S[st+i+1] and S[st+i+1] != S[st+2*(i+1)] and S[st] != S[st+2*(i+1)]:
            non += 1
        st += 1
        
print(ans-non)

Measured memory_bytes: 68612
#include<stdio.h>
int main(void){
  	int a;
  scanf("%d",&a);
  if(a % 10 == 2 || a % 10 == 4 || a % 10 == 5 || a % 10 == 7 || a % 10 == 9){
    	printf("hon");
  }else if(a % 10 == 0 || a % 10 == 1 || a % 10 == 6 || a % 10 == 8){
		printf("pon");
  }else{
		printf("bon");
  }
  return 0;
}

Measured memory_bytes: 1728
#include <algorithm>
#include <bitset>
#include <cctype>
#include <complex>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
template<class T> inline T sqr(T x) {return x*x;}

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

#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair
#define each(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define exist(s,e) ((s).find(e)!=(s).end())
#define range(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  range(i,0,n)
#define clr(a,b) memset((a), (b) ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

const double eps = 1e-10;
const double pi  = acos(-1.0);
const ll INF =1LL << 62;
const int inf =1 << 29;

int main(void){
    vi s;
    for(int n, k, m, res; cin >> n >> k >> m, n; cout << s[m] << endl){
        s = vi(n);
        m--;
        rep(i, n) s[i] = i + 1;

        while(1 < s.size()){
            s.erase(s.begin() + m);
            m = (m + k - 1) % s.size();
        }
    }

	return 0;
}

Measured memory_bytes: 1296
# Your code here!
n,m=gets.split
n=n.to_i
m=m.to_i


if m==0
    puts "Yes"
    exit
end


arr1=Array.new(n,10**10)
arr2=[]
n.times{
 arr2<<[]   
    
}

now=[]
k=0
m.times{
   a,b,c=gets.split
   a=a.to_i
   b=b.to_i
   c=c.to_i
   arr2[a-1]<<[c,b]
   arr2[b-1]<<[(-1)*c,a]
   
   if k==0
       now=[a]
   end
   k+=1
}

arr1[now[0]-1]=0




ss=0
n.times{
    if arr2[ss].length==0
        arr1[ss]=50
    end
    ss+=1
    
    
}







loop{
    
        ll=now.length
        j=0
            ll.times{
                
                
                key=now[j]
                lll=arr2[key-1].length
                
                                t=0
                                lll.times{
                                if    arr1[arr2[now[j]-1][t][1]-1]<10**10 && arr1[arr2[now[j]-1][t][1]-1]!=arr1[now[j]-1]+arr2[now[j]-1][t][0]
                                    puts "No"
                                    exit
                                elsif     arr1[arr2[now[j]-1][t][1]-1]<10**10
                                
                                
                                else 
                                arr1[arr2[now[j]-1][t][1]-1]=arr1[now[j]-1]+arr2[now[j]-1][t][0]
                                      now<<arr2[now[j]-1][t][1]
                                      
                                      
                                end
                                t+=1
                                }
                                
                
               j+=1 
            }
            
    now=now[ll..-1]
    
   if now.length==0 && arr1.max<10**10
   break
   
   
   elsif now.length==0
   
    rr=arr1.index(10**10)
    
    now=[rr+1]
    arr1[rr]=0
   
   end
   
    
    
    
    
}



puts "Yes"

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

using namespace std;

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

    string ans = "Good";
    for (int i = 0; i < S.length() - 1; ++i) {
        if (S[i] == S[i + 1]) {
            ans = "Bad";
            break;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
a = []
12.times do
  a << Array.new(10, 0)
end

n = gets.chomp.to_i

n.times do
  b, f, r, v = gets.chomp.split.map(&:to_i)

  a[(b-1) * 3 + f - 1][r - 1] += v
end

12.times do |i|
  puts " #{a[i].join(' ')}"

  break if i == 11
  puts "####################" if i % 3 == 2
end



Measured memory_bytes: 6892
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N; cin >> N;
    vector<int> L(N); for (auto &l : L) cin >> l;
    sort(begin(L), end(L));
    int ans = 0;
    for (int i = 0; i < N; i++) {
        int k = i;
        for (int j = i + 1; j < N; j++) {
            while (k < N && L[k] < L[i] + L[j]) k++;
            ans += k - j - 1;
        }
    }
    cout << ans << endl;
    return 0;
}


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

AB = []
for i in range(M):
    AB.append(list(map(int,input().split())))


ans = [1]*N

for j in range(M):
    if H[AB[j][0]-1] > H[AB[j][1]-1]:
        ans[AB[j][1]-1] = 0
    elif H[AB[j][0]-1] < H[AB[j][1]-1]:
        ans[AB[j][0]-1] = 0
    else:
        ans[AB[j][1]-1] = 0
        ans[AB[j][0]-1] = 0
        
print(sum(ans))

Measured memory_bytes: 32032
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;

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

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

// Self settings
// clang-format off
#define MAX_N 100000
#define REP(i, N) for (int i = 0; i < (int)(N); ++i)
#define SLN(i,N) (i == N-1 ? "\n" : " ")
ll fact(ll n) { ll res = 1; for(ll i=2;i<=n;++i) res = res * i; return res;}
ll nCr(ll n, ll r) {return (fact(n)/fact(n-r)*fact(r)) ;}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
const ll MOD = 1e9+7;
const ll INF = 1LL << 60;
const int inf = 1 << 31;
// clang-format on

char date[11];

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

  date[3] = '8';
  cout << date << endl;

  return 0;
}


Measured memory_bytes: 384
import itertools

N,M,X = map(int, input().split())
books = list()
for _ in range(N): books.append(list(map(int, input().split())))

MAX_COST = 1e5*12+1
min_cost = MAX_COST
selector = [i for i in range(N)]
for n in range(1, len(selector)+1):
	for conb in itertools.combinations(selector,n):
		cost = 0
		rikai = [0 for _ in range(M)]
		for sel in conb:
			cost += books[sel][0]
			for i in range(M): rikai[i] += books[sel][i+1]
		if all(a >= X for a in rikai):
			if cost < min_cost: min_cost = cost

if min_cost != MAX_COST:
	print(min_cost)
else:
	print(-1)

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

int main() {
	string a, b;
	cin >> a >> b;
	int n = a.length(), m = b.length();
	vector<vector<int> > dp(n+5,vector<int>(m+5));
	//int ans = 0;
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= m; j++) {
			if (a[i-1] == b[j-1]) {
				dp[i][j] = max(dp[i][j],dp[i-1][j-1]+1);
			} else {
				dp[i][j] = max(dp[i-1][j],dp[i][j-1]);
			}
			//ans = max(ans,dp[i][j]);
		}
	}
	int x = n, y = m;
	vector<char> lcs;
	while (x > 0 && y > 0) {
		if (a[x-1] == b[y-1]) {
			lcs.emplace_back(a[x-1]);
			x--; y--;
		}
		else if (dp[x-1][y] > dp[x][y-1]) x--;
		else y--;
	}
	reverse(lcs.begin(),lcs.end());
	for (auto it: lcs) cout << it;
	return 0;
}

Measured memory_bytes: 35712
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		StringBuilder sb = new StringBuilder();
		int n = sc.nextInt();
		long[] a = new long[n * 3];
		long sum = 0;
		// 偶数＋偶数＝偶数　奇数＋奇数＝偶数
		int cnt = 1;
		for (int i = 0; i < n * 3; i++) {
			a[i] = sc.nextInt();
		}
		Arrays.sort(a);
		while (cnt != n + 1) {
			sum += a[n * 3 - 2 * cnt];
			cnt++;
		}
		System.out.println(sum);
	}
}


Measured memory_bytes: 96824
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

typedef struct {
  char suit;
  char value;
}Card;

//void bubble(Card, int);
//void selection(Card, int);
//void print(Card, int);
//int isStable(Card, Card, int);

void bubble(Card A[100], int N){
  int i,j;
  Card t;
  for(i=0;i<N;i++){
    for(j=N-1;j>=i+1;j--){
      if(A[j].value<A[j-1].value){
        t=A[j];A[j]=A[j-1];A[j-1]=t;
      }
    }
  }
}

void selection(Card A[], int N){
  int i,j,minj;
  Card t;
  for(i=0;i<N;i++){
    minj=i;
    for(j=i;j<N;j++){
      if(A[j].value<A[minj].value) minj=j;
    }
    t=A[i];A[i]=A[minj];A[minj]=t;
  }
}

void print(Card A[], int N){
  int i;
  for(i=0;i<N;i++){
    if(i>0) printf(" ");
    printf("%c%c",A[i].suit,A[i].value);
  }
  printf("\n");
}

int isStable(Card C1[], Card C2[], int N){
  int i;
  for(i=0;i<N;i++){
    if(C1[i].suit!=C2[i].suit) return 1;
  }
  return 0;
}

int main(){
  Card C1[100],C2[100];
  int M;
  char ch;
  int i,j;

  scanf("%d",&M);
  for(i=0;i<M;i++) scanf(" %c%c",&C1[i].suit,&C1[i].value);

  for(i=0;i<M;i++) C2[i]=C1[i];

  bubble(C1,M);
  selection(C2,M);
  print(C1,M);
  printf("Stable\n");
  print(C2,M);
  if(isStable(C1,C2,M)==0){
    printf("Stable\n");
  }
  else{
    printf("Not stable\n");
  }

  return 0;
}




Measured memory_bytes: 2100
LIMIT = 1e-10
n = gets.to_i
n.times{
  arr = gets.split.map(&:to_f)
  ab = [arr[2] - arr[0], arr[3] - arr[1]]
  rab = Math.sqrt(ab[0]**2 + ab[1]**2)
  ab = [ab[0]/rab, ab[1]/rab]
  cd = [arr[6] - arr[4], arr[7] - arr[5]]
  rcd = Math.sqrt(cd[0]**2 + cd[1]**2)
  cd = [cd[0]/rcd, cd[1]/rcd]
  if ((ab[0] - cd[0]).abs < LIMIT && (ab[1] - cd[1]).abs < LIMIT) || ((ab[0] + cd[0]).abs < LIMIT && (ab[1] + cd[1]).abs < LIMIT)
    puts "YES"
  else
    puts "NO"
  end
}

Measured memory_bytes: 8720
#include<cstdio>
#include<iostream>
#include<cstring>
#define RG register
#define LL long long
using namespace std;
LL n,a[6],minn=1e15+1;
template<typename I>inline void read(I&ot){
	I ch=getchar(), x=0, f=1;
	while(ch<'0' || ch>'9'){if(ch=='-') f=-1; ch=getchar();}
	while(ch>='0' && ch<='9'){x=10*x+ch-'0'; ch=getchar();}
	ot=x*f;}
template<typename I,typename... U>inline void read(I&x,U&... y){read(x); read(y...);}
inline LL mi(LL x,LL y){return x<y ? x : y;}
int main()
{
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	read(n);
	for(int i=1;i<=5;i++)
	{
		read(a[i]);
		minn=mi(a[i],minn);
	}
	if(n%minn==0) printf("%lld\n",n/minn+4);
	else printf("%lld\n",n/minn+5);
//	fclose(stdin); fclose(stdout);
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
const ll INF = 1LL << 60;

string alpha="ABCEDFGHIJKLMNOPQRSTUVWXXY";

int main(){
    int n;
    string s;
    cin >> n >> s;
    for(int i=0; i<s.size(); i++){
        //Zを超える=90を超える
        //char+intをすることでで数値に変換される
        if(s[i]+n>90){
            cout << char(64+(s[i]+n)%90);
        }
        else{
            cout << char(s[i]+n);
        }
    }
}

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

int main() {
	int n, m;
	cin >> n >> m;
	if (n % 2 == 1) {
		for (int i = 1; i <= m; i++) {
			cout << i << ' ' << n+1-i << '\n';
		}
	} else {
		int a = n / 4;
		for (int i = 1; i <= m; i++) {
			if (i <= a) cout << i << ' ' << n+1-i << '\n';
			else cout << i << ' ' << n-i << '\n';
		}
	}
	return 0;
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using VI = vector<int>;
using VL = vector<ll>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);(i)++)
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);(i)++)
#define rFOR(i,a,n) for(int (i)=(n)-1;(i)>=(a);(i)--)
#define erFOR(i,a,n) for(int (i)=(n);(i)>=(a);(i)--)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
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; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& input, vector<T>& v) { for (auto& elemnt : v)input >> elemnt; return input; }

int main() {
    init();

    int n; ll a, b;
    cin >> n >> a >> b;
    VL x(n); cin >> x;

    ll ans = 0;
    FOR(i, 0, n - 1) {
        ans += min(a * (x[i + 1] - x[i]), b);
    }
    cout << ans << "\n";
}

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

int main(){
    int K,S;
    cin >> K >> S;
    int ans=0;
    for(int x=0; x<=K;++x){
        for(int y=0;y<=K;++y){
            int z = S-x-y;
            if(z>=0 && z<=K)ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import sys
n,h=map(int,input().split())
l=[list(map(int,input().split())) for i in range(n)]
l.sort()
x=l[-1][0]
L=[]
for i in range(n):
  if l[i][1]>x:
    L.append(l[i][1])
L.sort()
L.reverse()
ct=0
for i in range(len(L)):
  h-=L[i]
  ct+=1
  if h<=0:
    print(ct)
    sys.exit()
print(ct+(h+x-1)//x)

Measured memory_bytes: 28396
#include <stdio.h>
int dfs(int n, int s, int x){  
    int sum=0;  
if(n==0 && s==0)
return 1; 
if(n>0){      
    for(int i=x; i<10; i++){     
        if(s-i>=0) 
        sum+=dfs(n-1, s-i, i+1);  
        }
        }  
        return sum;
    
}
        int main(void){ 
            int n, s;  
        while(scanf("%d %d",&n,&s)!= EOF){  
            if(n==0 && s==0) 
        break;      
        printf("%d\n",dfs(n, s, 0)); 
        } 
    return 0;
        
    }



Measured memory_bytes: 2040