akhauriyash/Code-Regression huggingface dataset:
from itertools import permutations
from sys import stdin

def main():
    I = [int(input()) for _ in [0] * 5]

    ans = float('inf')
    for i in permutations(I):
        p = 0
        for j in i[:4]:
            p += ((j + 9) // 10) * 10
        p += i[4]
        ans = min(ans, p)
    print(ans)

input = lambda: stdin.readline()
main()


Measured memory_bytes: 3060
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
typedef long long ll; 
using namespace std;

ll n, m; 

template < typename T >
inline T read()
{
	T x = 0, w = 1; char c = getchar();
	while(c < '0' || c > '9') { if(c == '-') w = -1; c = getchar(); }
	while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return x * w; 
}

int main()
{
#ifndef ONLINE_JUDGE
	freopen("cpp.in", "r", stdin), freopen("cpp.out", "w", stdout);
#endif
	n = read <ll> (), m = n / 11 * 2ll, n %= 11;
	if(!n) { printf("%lld\n", m); return 0; }
	else if(n <= 6) { printf("%lld\n", m + 1); return 0; }
	else printf("%lld\n", m + 2); 
	return 0; 
}


Measured memory_bytes: 3124
K = int(input())
res = 0
for i in range(1,K+1):
  if i % 2 == 0:
    for j in range(i+1,K+1):
      if j%2 !=0:
        res+=1
  else:
    for j in range(i+1,K+1):
      if j%2 ==0:
        res+=1
        
print(res)

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




int main() {
    
    int n;
    cin>>n;
    int k;
    cin>>k;
    int q;
    cin>>q;
    vector<int> a(n+1,k);
    for(int i=0;i<q;i++){
        int x;
        cin>>x;
        a[x]++;
    }
    int s=0;
    for(int i=1;i<=n;i++){
        s+=a[i]-k;
    }

    for(int i=1;i<=n;i++){
        a[i]=k-(s-a[i]+k);
        if(a[i]>0){
            cout<<"Yes"<<endl;
        }
        else{
            cout<<"No"<<endl;
        }
        // cout<<a[i]<<" ";
    }
    
	return 0;
}


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


int main(){
  int n,i;
  double a,top1,top2,now,max;
  a=0.0;
  top1=0.0;
  top2=0.0;
  now=0.0;
  max=0.0;
  cin >> n;
  priority_queue<
    int,
    vector<int>,
    greater<int>
  > que;

  for(i=0;i<n;i++){
    cin >> a;
    que.push(a);
  }

  for(i=1;i<n;i++){
    if(i==1){
    top1=que.top();
    que.pop();
    top2=que.top();
    que.pop();
    now=(top1+top2)/2.0;
  }else{
  top1=que.top();
  que.pop();
  now = (now+top1)/2.0;
}
    if(i==n-1){
      max=now;
    }

  }
  que.pop();

  cout << max << "\n";


  return(0);



}

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


public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] abcd = br.readLine().split("");
        int sum;
        
        for (int i = 0; i < (1<<3); i++) {
            String str = abcd[0];
            for (int j = 0; j < 3; j++) {
                if ((i & (1<<j)) >= 1) {
                    str += "+" + abcd[j+1]; 
                }
                else {
                    str += "-" + abcd[j+1]; 
                }
            }
            
            sum = Integer.parseInt(String.valueOf(str.charAt(0)));
            for (int k = 0; k < 6; k += 2) {
                if (str.charAt(k+1) == '+') {
                    sum += Integer.parseInt(String.valueOf(str.charAt(k+2)));
                }
                else {
                    sum -= Integer.parseInt(String.valueOf(str.charAt(k+2)));
                }
            }
            //System.out.println(str);
            if (sum == 7) {
                    System.out.println(str+"=7");
                    break;
            }
        }
        
        
        
        //System.out.println(sum);
    }
}


Measured memory_bytes: 21332
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
using namespace std;
int main() {
	int x, a, b;
	cin >> x >> a >> b;
	x -= a;
	do {
		x -= b;
	} while (x >= 0);
	cout << x + b << "\n";
}

Measured memory_bytes: 3660
#include <iostream>
#include <string>
#include <vector>
//#include <algorithm>
using namespace std;

int main() {
  int n;
  cin >> n;
  int tmpn = n;

  int total = 0;

  while(tmpn > 0){
    int s = tmpn % 10;
    total += s;
    tmpn /= 10;
  }

  if(n % total == 0){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }

}


Measured memory_bytes: 256
n, k = map(int, input().split())
score = list(map(int, input().split()))
score = {"r": score[2], "s": score[0], "p": score[1]}
# ord(r) = 114
# r の時はp s -> r p -> s を出すことになる。
t = input()
l = len(t)
ans = 0
for i in range(k):
    cnt = 0
    pre = ""
    while True:
        if k * cnt + i >= l:
            break
        if t[k * cnt + i] != pre:
            ans += score[t[k * cnt + i]]
            # print(k * cnt + i, t[k * cnt + i], ans)
            pre = t[k * cnt + i]
        else:
            pre = ""
        cnt += 1
print(ans)


Measured memory_bytes: 3316
#include<bits/stdc++.h>
using namespace std;
struct UnionFind{
  vector<int> parent;
  vector<int> dist;
  UnionFind(int x=1){
    parent.clear();
    parent.resize(x,-1);
    dist.clear();
    dist.resize(x,0);
  }
  int find(int x){
    if(parent[x]<0)return x;
    return find(parent[x]);
  }
  int depth(int x){
    if(parent[x]<0)return 0;
    return depth(parent[x])+dist[x];
  }
  bool same(int x,int y){
    return (find(x)==find(y));
  }
  int size(int x){
    return -parent[find(x)];
  }
  void unite(int x,int y,int k=0){
    k+=depth(y);
    k-=depth(x);
    k*=-1;
    x=find(x);
    y=find(y);
    if(x==y)return;
    if(size(x)<size(y)){
      swap(x,y);
      k*=-1;
    }
    parent[x]+=parent[y];
    parent[y]=x;
    dist[y]=k;
  }
};




int main(){
  int n,q;
  scanf("%d %d",&n,&q);
  UnionFind T(n);
  for(int i=0;i<q;i++){
    int type,x,y;
    scanf("%d %d %d",&type,&x,&y);
    if(type==0){
      int a;
      scanf("%d",&a);
      T.unite(x,y,a);
    }else{
      
      if(!T.same(x,y)){
        printf("?\n");
      }else{
        printf("%d\n",T.depth(x)-T.depth(y));
      }
    }
  }
  return 0;
}



Measured memory_bytes: 3588
S = str(input())
odd = []
even = []
A = False
B = False

for i in range(len(S)):
    if i % 2 == 0:
        odd.append(S[i])
    else:
        even.append(S[i])

for i in range(len(odd)):
    if odd[i] == 'R' or odd[i] == 'U' or odd[i] == 'D':
        A = True
    else:
        A = False
        break

for i in range(len(even)):
    if even[i] == 'L' or even[i] == 'U' or even[i] == 'D':
        B = True
    else:
        B = False
        break

if len(S) == 1:
    if A == True:
        print('Yes')
    else:
        print('No')
else:
    if A == True and B == True:
        print('Yes')
    else:
        print('No')

Measured memory_bytes: 3064
#input of int(split by space)
def get_i()
  return gets.chomp.split(" ").map(&:to_i)
end
#input of float(split by space)
def get_f()
  return gets.chomp.split(" ").map(&:to_f)
end
#input of string(split by space)
def get()
  return gets.chomp.split(" ")
end
#input of string(split per one character)
def get_nsp()
  return gets.chomp.split("")
end
#yes or no decision
def yn_judge(bool,y="Yes",n="No")
  return bool ? y : n 
end
#create of array
def array(size1,init=nil,size2=-1)
  if size2==-1
    return Array.new(size1){init}
  else
    return Array.new(size2){Array.new(size1){init}}
  end
end

def max(a,b)
    return a>b ? a : b
end

def min(a,b)
    return a>b ? b : a
end

INF=Float::INFINITY

K,A,B=get_i
if B-A<=1
    puts K+1
else
    k=K-(A-1)
    puts A+(k/2)*(B-A)+k%2
end

Measured memory_bytes: 1788
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <functional>

using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
int A,B,C;






int main()
{

	cin >> A >> B >> C;

	if(A%2 == 0 || B%2 == 0 || C%2 == 0){
		cout << 0;
		return 0;
	}

	vector <int> l;
	l.resize(3);
	l[0] = A;
	l[1] = B;
	l[2] = C;
	sort(l.begin(),l.end());

	cout << (long long)l[0] * l[1];




}



Measured memory_bytes: 256
x, n = map(int, input().split())
p = list(map(int, input().split()))

p = set(p)

diff = 101
indx = 0
ans = (101, 0)
if n != 0:
    for now in range(0, 102):
        if now not in p:
            now_diff = abs(now - x)
            ans = min(ans, (now_diff, now))
    print(ans[1])
else:
    print(x)


Measured memory_bytes: 9188
#include <cstdio>
#include <cctype>
#include <utility>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;

#define gcu getchar_unlocked
#define pcu putchar_unlocked
#define _T template <typename T>
#define _HT template <typename H, typename... T>
#define _il inline
#define _in _il int in
#define _sc _il bool scan
_T T in(int c){T n=0;bool m=false;while(isspace(c)){c=gcu();}if(c=='-')m=true,c=gcu();
	do{n=10*n+(c-'0'),c=gcu();}while(c>='0'&&c<='9');return m?-n:n;}
_in() {return in<int>(gcu());}
_T T scan(T &n){int c=gcu();return c==EOF?false:(n=in<T>(c),true);}
_sc(char &c){c=gcu();gcu();return c!=EOF;}
#ifdef _GLIBCXX_STRING
_sc(string &s){int c;s="";
	for(;;){c=gcu();if(c=='\n'||c==' ')return true;else if(c==EOF)return false;s+=c;}}
#endif
_HT _sc(H &h, T&&... t){return scan(h)&&scan(t...);}
#define _vo _il void out
#define _vl _il void outl
_vo(bool b) {pcu('0'+b);}
_vo(const char *s){while(*s)pcu(*s++);}
_vo(char c){pcu(c);}
#ifdef _GLIBCXX_STRING
_vo(string s){for(char c:s)pcu(c);}
#endif
_T _vo(T n){static char buf[20];char *p=buf;
	if(n<0)pcu('-'),n*=-1;if(!n)*p++='0';else while(n)*p++=n%10+'0',n/=10;
	while (p!=buf)pcu(*--p);}
_vl(){out('\n');}
#ifdef _GLIBCXX_VECTOR
_T _vo(vector<T> &v){for(T &x:v)out(&x == &v[0]?"":" "),out(x);outl();}
#endif
_HT _vo(H&& h, T&&... t){out(h);out(move(t)...);}
template <typename... T> _vl(T&&... t){out(move(t)...);outl();}

struct team {
	int id, s = 0, t = 0;
	vector<int> w;
	bool operator < (team a) {
		return s == a.s ? t == a.t ? id < a.id : t < a.t : s > a.s;
	}
};

int main() {
	for (int T, P, R; T = in(), P = in(), R = in();) {
		vector<team> t(T);
		int i = 1;
		for (team &x: t) {
			x.id = i++;
			x.w = vector<int>(P);
		}
		int p, s;
		string m;
		while (R--) {
			scan(i, p, s, m);
			auto &u = t[i - 1];
			if (m[0] == 'C') {
				u.s++;
				u.t += u.w[p - 1] * 1200 + s;
			} else
				u.w[p - 1]++;
		}
		sort(t.begin(), t.end());
		for (team x: t)
			outl(x.id, ' ', x.s, ' ', x.t);
	}
}


Measured memory_bytes: 2624
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <math.h>
#include <assert.h>
#include <vector>

using namespace std;
typedef long long ll;
static const double EPS = 1e-9;
static const double PI = acos(-1.0);

#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define FOR(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define FOREQ(i, s, n) for (ll i = (s); i <= (ll)(n); i++)
#define FORIT(it, c) for (__typeof((c).begin())it = (c).begin(); it != (c).end(); it++)
#define DEC(i, s) for (ll i = (s); i >= 0; i--)

#define SIZE(v) (ll)((v).size())
#define MEMSET(v, h) memset((v), h, sizeof(v))
#define FIND(m, w) ((m).find(w) != (m).end())


const ll PRIME_SIZE = 1000010;
ll psize;
bool bprime[PRIME_SIZE+1];
ll prime[PRIME_SIZE+1];
ll Eratosthenes(ll n) {
  psize = 0;
  memset(bprime, true, sizeof(bprime));
  bprime[0] = bprime[1] = false;
  for (ll i = 2; i <= n; i++) {
    if (!bprime[i]) { continue; }
    prime[psize++] = i;
    for (ll j = i + i; j <= n; j += i) {
      bprime[j] = false;
    }
  }
  return psize;
}

int main() {
  ll l;
  Eratosthenes(1000001);
  while (cin >> l, l) {
    ll ans = 0;
    REP(i, psize) {
      if (l == 1) { break; }
      ll size = 0;
      while (l % prime[i] == 0) {
        l /= prime[i];
        size++;
      }
      if (size != 0) {
        ans = ans * (1LL + 2LL * size) + size;
        //cout << ans << " " << size << endl;
      }
    }
    if (l != 1) { ans = ans * (1 + 2) + 1; }
    ans++;
    cout << ans << endl;
  }
  return 0;
}

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

int main () {
  int N;
  cin >> N;
  vector<int>a(N);
  vector<int>count(9,0);
  for (int i = 0; i < N; i++) {
    cin >> a.at(i);
    if (a.at(i) >= 3200){
      count.at(8)++;
    }
    else {
      count.at(a.at(i)/400)++;
    }
  }
  
  int M = 0;
  for (int i = 0; i < 8; i++) {
    if (count.at(i) > 0){
      M++;
    }
  }
  
  cout << max(M,1) << ' ' << M+count.at(8) << endl;
}

Measured memory_bytes: 3620
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigDecimal;

public class Main {

	/** 桁数の上限 */
	private static final int NUMBER_OF_DIGIT_LIMIT = 80;

	/** オーバーフロー時の出力文字列 */
	private static final String OVERFLOW_MESSAGE = "overflow";

	/**
	 * 80桁までの2つの数の合計を求める。
	 *
	 * @param args
	 */
	public static void main(String[] args) throws IOException {

		// 入力値を受け取る
		BigDecimal[][] pairList = readPairList();

		for (BigDecimal[] pair : pairList) {

			boolean overflow = false;
			BigDecimal sum = BigDecimal.ZERO;

			for (BigDecimal value : pair) {
				if (isOverflow(value)){
					// 指定桁数を超えていたらフラグを立てて処理を止める
					overflow = true;
					break;
				}
				// 合計値に加算する
				sum = sum.add(value);
			}

			if (!overflow) {
				// 合計値がオーバーフローしているかチェックする
				overflow = isOverflow(sum);
			}

			// 出力
			printResult(sum, overflow);
		}

	}

	/**
	 * 標準入力から空白区切りの数値を取得し、2次元配列として返却する。
	 *
	 * @return 整数ペアの2次元配列（2×データ数）
	 */
	protected static BigDecimal[][] readPairList() throws IOException {

		BufferedReader reader = new BufferedReader(new InputStreamReader(
				System.in));

		// 最初にデータの個数を取得する
		int numberOfLine = Integer.parseInt(reader.readLine());

		// 1行につき1データ、2行ずつ取り込む
		final int NUMBER_OF_ELEMENT = 2;
		BigDecimal[][] pairList = new BigDecimal[numberOfLine][NUMBER_OF_ELEMENT];
		for (int i = 0; i < pairList.length; i++) {
			for (int j = 0; j < pairList[i].length; j++) {
				String line = reader.readLine();
				pairList[i][j] = new BigDecimal(line);
			}
		}

		if (reader != null) {
			reader.close();
		}

		return pairList;
	}

	/**
	 * 引数で渡された値がオーバーフローしているかどうかを判定する。
	 *
	 * @param value チェック対象の値
	 * @return オーバーフローしていれば true、そうでなければ false
	 */
	protected static boolean isOverflow(BigDecimal value) {
		return (value.toPlainString().length() > NUMBER_OF_DIGIT_LIMIT);
	}

	/**
	 * 結果を出力する。
	 *
	 * @param sum 合計値
	 * @param overflow オーバーフローしていたかどうかのフラグ
	 */
	protected static void printResult(BigDecimal sum, boolean overflow) {

		if (overflow){
			// オーバーフローしていた場合は、専用メッセージを表示する
			System.out.println(OVERFLOW_MESSAGE);

		} else {
			// オーバーフローしていない場合は、合計値を表示する
			System.out.println(sum.toPlainString());
		}
	}
}

Measured memory_bytes: 19112
#include<stdio.h>

int main(void) {  int a,b,c;  int tmp,i,j;    scanf("%d %d %d",&a,&b,&c);    if(a>b)  {   tmp = a;   a = b;   b = tmp;  }    if(a>c)  {   tmp = a;   a = c;   c = tmp;  }    if(b>c)  {   tmp = b;   b = c;   c = tmp;  }    printf("%d %d %d\n",a,b,c);    return 0; }

Measured memory_bytes: 1024
//g++ -std=c++14 test.cpp -o test.out
//問題URL
//https://atcoder.jp/contests/nikkei2019-qual/tasks/nikkei2019_qual_d

//参考：
//https://scrapbox.io/ganariya/AtCoder%E5%85%A8%E5%9B%BD%E7%B5%B1%E4%B8%80%E3%83%97%E3%83%AD%E3%82%B0%E3%83%A9%E3%83%9F%E3%83%B3%E3%82%B0%E7%8E%8B%E6%B1%BA%E5%AE%9A%E6%88%A6%E4%BA%88%E9%81%B8_D%E5%95%8F%E9%A1%8C500%E7%82%B9_%E3%80%8CRestore_the_Tree%E3%80%8D

//ポイント：トポロジカルソート

#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <vector>
#include <queue>
#include <stack>
#include <map> 
#include <unordered_map> 
#include <utility>
#include <limits.h>
#include <bitset>
#include <set>
using namespace std;
 
#define LL long long int
const LL INF = (1LL<<60);
const int INF_INT = 2147483647-1e6-1;
const LL mod = 1000000007ll;
const int mod_int = 1000000007;

LL N,M;
vector<vector<LL>> out;
vector<vector<LL>> in;

vector<LL> ans;

void solve(){
    //ある頂点iに入っていく辺の個数をin_num[i]とおく
    vector<LL> in_num(N+1,0);
    LL start;//トポロジカルソートのスタート地点にしたい点
    for(int i=1;i<=N;i++){
        in_num[i] = in[i].size();
        if(in_num[i]==0) start = i;
    }

    queue<LL> q;
    //dist,parentにはトポロジカルソートの結果を格納
    vector<LL> dist(N+1,0);//点startから点iへの距離的なもの
    vector<LL> parent(N+1,0);//点iの直接の親をparent[i]とする
    q.push(start);
    dist[start] = 0;
    while(!q.empty()){
        LL now = q.front();q.pop();
        for(LL next:out[now]){
            if(dist[next]<dist[now]+1){
                dist[next] = dist[now]+1;
                parent[next] = now;
                in_num[next]--;
                if(in_num[next]==0) q.push(next);
            }
        }
    }

    ans = vector<LL>(N+1,0);
    for(int i=1;i<=N;i++){
        ans[i] = parent[i];
    }
}

int main(){
    cin >> N >> M;
    out = vector<vector<LL>>(N+1);
    in = vector<vector<LL>>(N+1);
    for(int i=0;i<N+M-1;i++){
    	LL u,v;cin >> u >> v;
    	out[u].push_back(v);
        in[v].push_back(u);
    }

    solve();

    for(int i=1;i<=N;i++)cout << ans[i] << endl;
    return 0;
}

Measured memory_bytes: 14336
#include<iostream>
#include<string>
#include<map>
#include<iostream>
#include<math.h>
#include<vector>
#include<algorithm>
#include<time.h>
#include<limits.h>
#include<unordered_map>
#include<set>
#include<queue>
#include <iomanip>
using namespace std;
#define inf LLONG_MAX
const int N = 1e7 + 1;
#define int long long
void solve() {
    int n,m,k; cin >> n >> m >> k;
    int a[n], b[m];
    for (int i = 0; i < n; i ++) cin >> a[i];
    for (int i = 0; i < m; i ++) cin >> b[i];
    int i = 0, j = 0, c = 0;
}
vector<int> p(N, 1);
void solve2() {
    int n; cin >> n;
    int s = 0;
    for (int i = 2; i <= n; i ++) {
        for (int j = i; j <= n; j += i) {
            p[j] ++;
        }
    }
    for (int i = 1; i <= n; i ++) {
        s += (i * p[i]);
//        cout << i << " " << p[i] << endl;
    }
    cout << s << endl;
}
int32_t main() {
        solve2();

}


Measured memory_bytes: 81208
#include <bits/stdc++.h>
 
#define ALL(l)  (l).begin(),(l).end()
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
typedef long long ll;
ll mod =  1000000007;
ll maxn = 1000000000;
 
//---------------------------------------------------------------------------------------------------
using vi = vector<int>; // intの1次元の型に vi という別名をつける
using vll = vector<ll>; // intの1次元の型に vi という別名をつける
using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける
using vs = vector<string>; // stringの1次元の型に vs という別名をつける
using pll = pair<ll, ll>; // これ以降 pii という型名はpair<ll, ll> と同じ意味で使える
//---------------------------------------------------------------------------------------------------
 
int main(){
   
    ll k,n,sk;
    cin>>k>>n;
    vll a(n);
    rep(i,n)cin>>a.at(i);
    sk=k-(a.at(n-1)-a.at(0));
    rep(i,n-1){
        sk=max(sk,a.at(i+1)-a.at(i));
        
    }
    cout<<k-sk<<endl;;
}
   



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

typedef long long ll;

#define min(a, b) ((a) < (b))? (a):(b)
#define max(a, b) ((a) > (b))? (a):(b)
#define abs(a) ((a) < (0)? -(a):(a))
#define rep(i, n) REP(i, 0, (n))
#define REP(i, a, n) for(typeof(n) i=(a); i<(n); i++)
#define pb push_back

int main() {
	int N; cin >> N;
	string s; cin >> s;
	for(string head: {"SS", "SW", "WS", "WW"}) {
	    string ans = head;
	    REP(i, 1, N+1) {
	        string tail = ans.substr(ans.size()-2, 2);
	        if(s[i%N]=='o') ans.pb((tail=="SS"||tail=="WW")? 'S':'W');
	        else ans.pb((tail=="SS"||tail=="WW")? 'W':'S');
	    }
	    if(ans.substr(N,2)==head) {cout << ans.substr(0, N) << endl; return 0;}
	}
	cout << "-1" << endl;
}


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

/* short */
#define pb push_back
#define mp make_pair
#define Fi first
#define Se second
#define ALL(v) begin(v), end(v)
#define RALL(v) rbegin(v), rend(v)

/* REPmacro */
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define REP(i, n) for(int i = 0; i < (n); i++)
#define EACH(begin, end) for(auto itr = (begin); itr != (end); itr++)

/* function */
#define IN(x) cin >> x
#define DEBUG(x) cerr << (x) << " "
#define LN() cerr << "\n"
#define PRINT(x) cout << (x) << endl
#define BR cout << endl

/* const */
const int INF = 1001001001; // 10^9
const ll LINF = 1001001001001001001; // 10^18
const int MOD = 1e9 + 7;



ll N = 0;
ll A, B, C, D;
ll ret = 0;

ll _lcm(ll x, ll y) {
  ll a = max(x, y);
  ll b = min(x, y);
  ll r = a%b;
  while(r != 0) {
    a = b;
    b = r;
    r = a%b;
  }
  return x*y/b;
}

void input() {
  IN(A);
  IN(B);
  IN(C);
  IN(D);
}

void solve() {
  ll a = (A-1) - (A-1)/C - (A-1)/D + (A-1)/_lcm(C, D);
  ll b = B - B/C - B/D + B/_lcm(C, D);
  PRINT(b-a);
}

int main(void){
  input();
  solve();
}


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


using namespace std;

int main() {
	int a, b;
	cin >> a >> b;
	if (a - b - b < 0) {
		cout << 0 << endl;
		return 0;
	}
	cout << a - b - b << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args){

        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] A = new int[N];
        int[] B = new int[N];
        int[] C = new int[N];

        for(int i=0;i<N;i++){
            A[i] = sc.nextInt();
            B[i] = sc.nextInt();
            C[i] = sc.nextInt();
        }
        int[][] dp = new int[N+1][3];
        for(int i=1 ;i<=N;i++ ){
            dp[i][0]= A[i-1] + Math.max(dp[i-1][1],dp[i-1][2]);
            dp[i][1]= B[i-1] + Math.max(dp[i-1][0],dp[i-1][2]);
            dp[i][2]= C[i-1] + Math.max(dp[i-1][0],dp[i-1][1]);
        }
        int res = Math.max(dp[N][0],dp[N][1]);
        res = Math.max(res,dp[N][2]);
        System.out.println(res);
    }
}


Measured memory_bytes: 93096
n = int(input())
state_ls_ls = [0] * n
a_ls = [0] * n
for i in range(n):
    a = int(input())
    a_ls[i] = a
    state_ls = [list(map(int, input().split())) for _ in range(a)]
    state_ls_ls[i] = state_ls

num_pat = 2 ** n
ans = 0
for i in range(num_pat):
    pattern = [0] * n
    for j in range(n):
        if ((i>>j)&1):
            # 1は正直者
            pattern[j] = 1
    # 以下矛盾ないか検証
    TF = True
    # patternで「正直」がいたら検証
    for k in range(n):
        if pattern[k] == 1:
            for l in range(a_ls[k]):
                st_person, st_kind = state_ls_ls[k][l]
                st_person -= 1
                if pattern[st_person] != st_kind:
                    TF = False
    if TF:
        ans = max(ans, pattern.count(1))
print(ans)

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

int main(){
    
    int i, N, count = 0;
    
    string S, T;
    cin >> S >> T;
    
    N = S.size();
    
    for (i = 0; i < N; i++){
        
        if (S.at(i) != T.at(i)) count++;
    }
    
    cout << count << "\n";

    return 0;
}



Measured memory_bytes: 3580
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rrep(i,n) for(ll i = 1; i <= (n); ++i)
#define drep(i,n) for(ll i = (n)-1; i >= 0; --i)
#define all(v) v.begin(),v.end()
#define len(x) (ll)(x).length()
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define pb push_back
#define sz(x) (ll)(x).size()
#define v(T) vector<T>
#define vv(T) vector<vector<T>>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
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/gcd(a,b)*b;}
const int INF=1e9;
const ll MX = 1e18;
const ll MOD=INF+7;
const int di[] = {-1,0,1,0};
const int dj[] = {0,-1,0,1};
const double PI=acos(-1);
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
#define YN {puts("YES");}else{puts("NO");}
const ll MAX = 1000001;
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {fac[0] = fac[1] = 1;finv[0] = finv[1] = 1;inv[1] = 1;for (ll i = 2; i < MAX; i++){fac[i] = fac[i - 1] * i % MOD;inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;finv[i] = finv[i - 1] * inv[i] % MOD;}}
long long COM(ll n, ll k){if (n < k) return 0;if (n < 0 || k < 0) return 0;return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;}

int main() {
  int n,d;
  cin>>n>>d;
  d=d*2+1;
  cout<<(n+d-1)/d<<endl;
}


Measured memory_bytes: 3584
def resolve():
    MOD = 998244353
    N, S = map(int, input().split())
    A = list(map(int, input().split()))

    dp = [[0] * (S + 1) for _ in range(N + 1)]
    dp[0][0] = 1

    for i in range(N):
        dp[i + 1][0] += 1
        for s in range(S + 1):
            dp[i + 1][s] += dp[i][s]
            dp[i + 1][s] %= MOD
            if s + A[i] <= S:
                dp[i + 1][s + A[i]] += dp[i][s]
                dp[i + 1][s + A[i]] %= MOD
    ans = 0
    for i in range(1, N + 1):
        ans += dp[i][S]
        ans %= MOD
    print(ans)


if __name__ == "__main__":
    resolve()


Measured memory_bytes: 135336
import java.util.*;

public class Main {
  public static void main(String[] args) {
     Scanner sc = new Scanner(System.in);      
     
     String S = sc.next();
     
     int N = S.length();
     
     boolean flag = false;
     
     for(int i = 1;i < N;i++){
         if(isGoo(S)){
            if(!flag){
              flag = true;
            }else{
              System.out.println(S.length());
              return;
            }
         }
         S = S.substring(0,S.length() - 1);
     }          
     
  }
  
  private static boolean isGoo(String S){
      if(S.length()%2 != 0){
          return false;
      }      
      for(int i = 0;i < S.length()/2;i++){
          if(S.charAt(i) != S.charAt(S.length()/2 + i)){
              return false;
          }
      }     
      return true;
  }
  
}


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

int a[1111111], b[1111111];
int main() {
    int n, S = 0, T = 0, D = 0;
    cin >> n;
    for(int i = 0; i < n; i++) {
        string z;
        cin >> z;
        int d = 0, s = 0;
        for(auto c : z)
            if(c == '(')
                d++;
            else
                d--, s = max(s, -d);
        if(d > 0)
            a[s] += d, S = max(S, s);
        else
            s = max(s + d, 0), b[s] += d, T = max(T, s);
        D += d;
    }
    int x = 0;
    if(D)
        goto no;
    for(int s = 0; s <= S; s++) {
        if(s > x)
            goto no;
        x += a[s];
    }
    x = 0;
    for(int s = 0; s <= T; s++) {
        if(s > x)
            goto no;
        x -= b[s];
    }
    cout << "Yes" << endl;
    return 0;
no:
    cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 3636
#include<stdio.h>

int gcd(int n, int m){
    int r;
    if (n > m){
        int t = m;
        m = n;
        n = t;
    }
    while ((r = m % n) != 0){
        m = n;
        n = r;
    }
    return n;
}

int main(void){

    int K,i,j,k;
    int ans = 0;

    scanf("%d",&K);
    for(i = 1;i <= K;i++){
        for(j = 1;j <= K;j++){
            for(k = 1;k <= K;k++){
                ans += gcd(gcd(i,j),k);
            }
        }
    }

    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 1728
#include <bits/stdc++.h>
using namespace std;
#define rep(i, s, e) for (int i = s; i < e; ++i)
#define sort_(a) sort(a.begin(), a.end())
#define rsort(a) sort(a.rbegin(), a.rend())
#define sum(a) accumulate(a.begin(), a.end(), 0LL)
#define __lcm(a, b) std::__detail::__lcm(a, b)
typedef long long ll;
const long mod = 1e9 + 7;

int main(void) {
#ifdef DEBUG
  freopen("input.txt", "r", stdin);
#endif

  ios_base::sync_with_stdio(false);
  cin.tie(0);

  string S;
  cin >> S;
  replace(S.begin(), S.end(), ',', ' ');
  cout << S << endl;

  return 0;
}


Measured memory_bytes: 256
import sys
## io ##
def IS(): return sys.stdin.readline().rstrip()
def II(): return int(IS())
def MII(): return list(map(int, IS().split()))
def MIIZ(): return list(map(lambda x: x-1, MII()))
## dp ##
def DD2(d1,d2,init=0): return [[init]*d2 for _ in range(d1)]
def DD3(d1,d2,d3,init=0): return [DD2(d2,d3,init) for _ in range(d1)]
## math ##
def to_bin(x: int) -> str: return format(x, 'b') # rev => int(res, 2)
def to_oct(x: int) -> str: return format(x, 'o') # rev => int(res, 8)
def to_hex(x: int) -> str: return format(x, 'x') # rev => int(res, 16)
MOD=10**9+7
def divc(x,y) -> int: return -(-x//y)
def divf(x,y) -> int: return x//y
def gcd(x,y):
    while y: x,y = y,x%y
    return x
def lcm(x,y): return x*y//gcd(x,y)
def enumerate_divs(n):
    """Return a tuple list of divisor of n"""
    return [(i,n//i) for i in range(1,int(n**0.5)+1) if n%i==0]
def get_primes(MAX_NUM=10**3):
    """Return a list of prime numbers n or less"""
    is_prime = [True]*(MAX_NUM+1)
    is_prime[0] = is_prime[1] = False
    for i in range(2, int(MAX_NUM**0.5)+1):
        if not is_prime[i]: continue
        for j in range(i*2, MAX_NUM+1, i): is_prime[j] = False
    return [i for i in range(MAX_NUM+1) if is_prime[i]]
def prime_factor(n):
    """Return a list of prime factorization numbers of n"""
    res = []
    for i in range(2,int(n**0.5)+1):
        while n%i==0: res.append(i); n //= i
    if n != 1: res.append(n)
    return res
## libs ##
import itertools as it
import functools as ft
from collections import deque, Counter
from heapq import heapify, heappop, heappush
from bisect import bisect_left
#======================================================#
def main():
    n = II()
    DIV = 10**9+7
    divp = [1]*10**3
    for i in range(1,n+1):
        for p in prime_factor(i):
            divp[p] += 1
    print((ft.reduce(lambda x,y: x*y, divp))%DIV)

if __name__ == '__main__':
    main()

Measured memory_bytes: 3796
# 再帰の深さが1000を超えそうなときはこれをやっておく
import sys
sys.setrecursionlimit(10**7)

N, M = map(int,input().split())
# 入力のつもり。esはよくある隣接リストで辺を表したもの。
#N = 5
#es = [[1,2,3],[0,2],[0,1],[0,4],[3]] # False
#es = [[1,3],[0,2],[1,3],[0,2,4],[3]] # True
es = [[] for i in range(N)]
for i in range(M):
  a, b = map(int,input().split())
  a, b = a-1, b-1
  es[a].append(b)
  es[b].append(a)
  
#n個の頂点の色を初期化。0:未着色、1:黒、-1:白
colors = [0 for i in range(N)] 

#頂点vをcolor(1 or -1)で塗り、再帰的に矛盾がないか調べる。矛盾があればFalse
def dfs(v,color):
    #今いる点を着色
    colors[v] = color
    #今の頂点から行けるところをチェック
    for to in es[v]:
        #同じ色が隣接してしまったらFalse
        if colors[to] == color:
            return False
        #未着色の頂点があったら反転した色を指定し、再帰的に調べる
        if colors[to] == 0 and not dfs(to, -color):
            return False
    #調べ終わったら矛盾がないのでTrue
    return True

#2部グラフならTrue, そうでなければFalse
def is_bipartite():
    return dfs(0,1) # 頂点0を黒(1)で塗ってDFS開始

if is_bipartite():
  B = colors.count(1)
  W = colors.count(-1)
  ans = B * W - M
else:
  ans = int(N * (N - 1) / 2) - M
  
  
print(ans)  
  
  
  

Measured memory_bytes: 35360
#include <bits/stdc++.h>
using namespace std;
const int mod=998244353;
int k,n;
int read(){
    int x=0,y=1;
    char ch=getchar();
    while(ch<48||ch>57){if(ch==45)y=-1;ch=getchar();}
    while(ch>=48&&ch<=57)x=(x<<3)+(x<<1)+(ch^48),ch=getchar();
    return x*y;
}
long long c[4005][4005],f[2005][2005];
void pre(){
	c[0][0]=1;
	for(int i=1;i<=4000;i++){
		c[i][0]=1;
		for(int j=1;j<=i;j++)
			c[i][j]=(c[i-1][j]+c[i-1][j-1])%mod;
	}
	f[0][0]=1;
	for(int i=1;i<=2000;i++){
		f[i][0]=1;
		for(int j=1;j<=2000;j++){
			if(i&1)
				f[i][j]=(f[i-1][j]+f[i-1][j-1])%mod;
			else
				f[i][j]=(f[i-1][j]+f[i][j-1])%mod;
		}
	}
	return ;
}
long long ans[4005];
int main(){
//    freopen("AT4362.in","r",stdin);
//    freopen("AT4362.out","w",stdout);
	k=read();n=read();
	pre();
	for(int i=2;i<=k;i++)
		for(int j=0;j<=n;j++)
			ans[i]=(ans[i]+c[k-i+n-j][n-j]*f[i-1][j]%mod)%mod;
	ans[k+1]=f[k][n];
	for(int i=2;i<=k+1;i++)printf("%lld\n",ans[i]);
	for(int i=k+2;i<=2*k;i++)printf("%lld\n",ans[k+1-(i-k-1)]);
    return 0;
}


Measured memory_bytes: 112652
N = int(input())
l = []
for i in range(2):
  a = [int(x) for x in input().split()]
  l.append(a)
ans = 0
for i in range(N):
  kosuu = 0
  for j in range(i+1):
    kosuu += l[0][j]
  for j in range(i,N):
    kosuu += l[1][j]
  ans = max(kosuu,ans)
print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
int main()
{
    string s,t;
    cin>>s>>t;
    vector<char> v;
    int i,j,k,sl,tl;
    sl = s.size();
    tl = t.size();
    int dp[sl+1][tl+1];
    for(i = 0 ; i <= sl;i++)
        dp[i][0] = 0;
    for(i = 0 ; i <= tl;i++)
        dp[0][i] = 0;

    for(i=1;i<=sl;i++)
    {
        for(j = 1; j<=tl ;j++)
        {
            if(s[i-1] == t[j-1])
            {
                dp[i][j] = dp[i-1][j-1]+1;
            }
            else
            {
                dp[i][j] = max(dp[i-1][j],dp[i][j-1]);
            }

        }
    }
/*for(i = 0 ; i <= sl; i++)
{
    for(j = 0 ; j <= tl ; j++)
        cout<<dp[i][j];
    cout<<endl;
}*/
    i = sl;
    j = tl;
    while(dp[i][j] != 0)
    {
        if(dp[i][j] == dp[i-1][j])
            i--;
        else if(dp[i][j] == dp[i][j-1])
            j--;
        else
        {
            v.pb(s[i-1]);
            i--;
            j--;
        }
    }

    for(i = v.size()-1 ; i>= 0 ; i--)
        cout<<v[i];

    return 0;
}


Measured memory_bytes: 35456
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll MOD = 1'000'000'007;
const ld PI = acos(-1);  
const ld EPS = 0.0000000001;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define REP(i, n) for(ll i=0; i<(ll)(n); i++)
#define REPD(i, n) for(ll i=n-1; 0<=i; i--)
#define FOR(i, a, b) for(ll i=a; i<(ll)(b); i++)
#define FORD(i, a, b) for(ll i=a; (ll)(b)<=i; i--)
#define ALL(x) x.begin(), x.end()
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int main(){
    string s;   cin >> s;
    vector<ll> key(26, 0);
    REP(i, s.size()){
        key[s[i]-'a'] += 1;
    }
    if(s.size()<26){
        cout << s;
        REP(i, 26){
            if(0<key[i]) continue;
            printf("%c\n", i+'a');
            return 0;
        }
    }else{
        int n=s.size();
        priority_queue<char, vector<char>, greater<char>> que;
        REPD(i, n-1){
            que.push(s[i+1]);
            if(s[i]<s[i+1]){
                cout << s.substr(0, i);
                while(1){
                    if(que.top()<s[i]){
                        que.pop();  continue; 
                    }
                    cout << que.top() << endl;
                    return 0;
                }
            }
        }
        cout << -1 << endl;
    }
}


Measured memory_bytes: 3696
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <queue>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <climits>
//#include "h.h"
using namespace std;

#define ll long long
#define pint pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define mp make_pair
#define pm(first, second) pb(mp(first, second))
#define SPACE " "
#define fpf first.first
#define fps first.second
#define spf second.first
#define sps second.second

#define all(X) (X).begin(), (X).end()

int main(){

	int a, b;
	cin >> a >> b;
	if(a <= 5)cout << "0" << endl;
	else if(a <= 12)cout << b / 2 << endl;
	else cout << b << endl;

	return 0;
}


Measured memory_bytes: 256
hoge = input().split()
N = int(hoge[0])
M = int(hoge[1])

mi = 0
ma = N

for j in range(M):
    i = input().split(" ")
    l = int(i[0])
    r = int(i[1])
    if l >= mi:
        mi = l
    if r <= ma:
        ma = r
r = ma - mi + 1
if r > 0:
    print(r)
else:
    print(0)

Measured memory_bytes: 9216
n=gets.to_i
s=gets.chomp

ans=0
(n-1).times do |i|
  a=s[0,i+1]
  b=s[i+1,n-i-1]
  curr=0
  bit_a=Array.new(26,0)
  bit_b=Array.new(26,0)
  a.length.times do |j|
    bit_a[a[j].ord-"a".ord]+=1
  end
  b.length.times do |j|
    bit_b[b[j].ord-"a".ord]+=1
  end
  26.times do |j|
    curr+=1 if bit_a[j]>0 && bit_b[j]>0
  end
  ans=curr if ans<curr
end
puts ans


Measured memory_bytes: 14360
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF=1001001001;
const int mod=1e9+7;

int f(int x){
  int sum=0;
  while(x){
    sum+=x%10;
    x/=10;
  }
  return sum;
}
int main(){
  int N;
  cin>>N;
  int ans=INF;
  for(int i=1;i<=N-1;i++){
    int A=i,B=N-i;
    chmin(ans,f(A)+f(B));
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 3620
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <climits>
#include <bitset>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<pair<int,int>> vpii;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvc;
typedef vector<vector<string>> vvs;
#define rep(i,n) for(int i=0;i<n;i++)
#define fin(ans) cout<<(ans)<<endl
#define P 1000000007
#define STI(s) atoi(s.c_str())//string to int
#define mp(p,q) make_pair(p,q)
#define Sort(a) sort(a.begin(),a.end())
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
const int INF = INT_MAX;
const long long LLINF = 1LL<<60;
//g++ -std=c++1z temp.cpp
//./a.exe



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

int n,p[100]={},count = 0,ans;
cin >> n;
for (int i = 1; i < n+1; i++)
{
    cin >> p[i];
}


for (int i = 1; i < n+1; i++)
{
    if (i != p[i])
    {
        count++;
    }
    
}

if (count == 2 || count == 0)
{
    cout << "YES" << endl;
}else
{
    cout << "NO" << endl;
}






//////////////////////////////////////////////////////
return 0;}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pint = pair<int,int>;


const long long INFLL = 1LL << 60;
const int INFI = 1000000000;

long long mod = pow(10,9)+7;
long long func(long long n){
    long long ans=1;
    while(n>0){
        ans*=n;
        ans = ans%mod;
        n--;
    }
    return ans;
}


int main() {
    long long N,M; cin>>N>>M;
    long long ans=1;
    if(abs(N-M)>=2) cout << 0 << endl;
    else{
        ans *= func(N); 
        ans *= func(M); 
        if(N==M) cout << ans*2%mod << endl;
        else cout << ans%mod << endl;
    }
}



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

int main (){
  
  int i,j,b,f,r,v,n;
  int num1[3][10],num2[3][10],num3[3][10],num4[3][10];
  
  cin >> n;
      for (int i=0;i<3;i++){
	
	for(int j=0;j<10;j++){
	  
	  num1[i][j]=0;
	  num2[i][j]=0;
	  num3[i][j]=0;
	  num4[i][j]=0;
	}
      }
	
	while(n>0){
	  cin >> b >> f >> r >> v ;
	  
    if(b == 1){
      num1[f-1][r-1]+=v;
    }else if(b == 2){
      num2[f-1][r-1]+=v;
    }else if(b == 3){
      num3[f-1][r-1]+=v;
    }else if(b == 4){ 
      num4[f-1][r-1]+=v;
    }
    n--;
  }
      
  
    for(i=0;i<3;i++){
      for(j=0;j<10;j++){
	cout << " " << num1[i][j];
      }cout << endl;
    }
    
    
    for(i=0;i<20;i++){
      cout << "#";
    }cout << endl;
    
    
    
    
    for(i=0;i<3;i++){
      for(j=0;j<10;j++){
	cout << " " << num2[i][j];
    }cout << endl;
    }
    
    for(i=0;i<20;i++){
      cout << "#";
    }cout << endl;
    
    
    for(i=0;i<3;i++){
      for(j=0;j<10;j++){
	cout << " " << num3[i][j];
      }cout << endl;
    }
    
    for(i=0;i<20;i++){
      cout << "#";
    }cout << endl;
    
    for(i=0;i<3;i++){
      for(j=0;j<10;j++){
	cout << " " << num4[i][j];
      }cout << endl;
    }
    
}  


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

int main(){
  int n;
  string s;
  cin >> n >> s;
  int a[26],b[26];
  for(int i=0;i<26;i++){
    a[i]=0;
    b[i]=0;
  }
  int ans=0;
  for(int i=0;i<n;i++){
    int count=0;
    for(int j=0;j<i;j++){
      a[s.at(j)-'a']++;
    }
    for(int j=i;j<n;j++){
      b[s.at(j)-'a']++;
    }
    for(int k=0;k<26;k++){
      if(a[k]!=0&&b[k]!=0){
        count++;
      }
    }
    ans=max(ans,count);
    for(int j=0;j<26;j++){
      a[j]=0;
      b[j]=0;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
N = int(input())
if N<=111:
    print(111)
elif N<=222:
    print(222)
elif N<=333:
    print(333)
elif N<=444:
    print(444)
elif N<=555:
    print(555)
elif N<=666:
    print(666)
elif N<=777:
    print(777)
elif N<=888:
    print(888)
elif N<=999:
    print(999)


Measured memory_bytes: 38384
#include <bits/stdc++.h>
using namespace std;
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_CAT_I(x,y) x ## y

using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;
using f32 = float;
using f64 = double;
using ll = long long;
constexpr i64 INF = 1010000000000000017LL;
constexpr i64 MOD = 1000000007LL;
constexpr f64 EPS = 1e-12;
constexpr f64 PI = 3.14159265358979323846;
#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))
struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;
    ProconInit() {
        cin.tie(nullptr); ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH) cout << unitbuf;
    }
} PROCON_INIT;

void solve() {
    int a[3][3];
    bool res[3][3];
    FOR(i, 0, 3){
        FOR(j, 0, 3){
            cin >> a[i][j];
            res[i][j] = false;
        }
    }
    int n; cin >> n;
    vector<int> b(n); FOR(i, 0, n) cin >> b[i];

    FOR(k, 0, n) {
        FOR(i, 0, 3){
            FOR(j, 0, 3) {
                if (a[i][j] == b[k]) res[i][j] = true;
            }
        }
    }

    FOR(i, 0, 3){
        if (res[i][0] && res[i][1] && res[i][2]) {
            cout << "Yes" << endl; 
            return;
        }
        if (res[0][i] && res[1][i] && res[2][i]) {
            cout << "Yes" << endl;
            return;
        }
    }

    if (res[0][0] && res[1][1] && res[2][2]) {
        cout << "Yes" << endl;
        return;
    }
    if (res[2][0] && res[1][1] && res[0][2]) {
        cout << "Yes" << endl;
        return;
    }
    cout << "No" << endl;
}

signed main() {
    solve();
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cctype>
#include <cstring>
using namespace std;
int main()
{
    string card;
    int m = 0, h;
    while (1)
    {
        cin >> card;
        if (card == "-")
        {
            break;
        }
        cin >> m;
        for (int i = 0; i < m; i++)
        {
            cin >> h;
            string str1 = card.substr(0, h);
            string str2 = card.substr(h, card.size() - h);
            card = str2.append(str1);
        }
        cout << card << endl;
    }
    return 0;
}


Measured memory_bytes: 3148
#include<algorithm>
#include<cassert>
#include<cmath>
#include<cstdio>
#include<iostream>
#include<map>
#include<numeric>
#include<stack>
#include<string>
#include<deque>
#include<queue>
#include<vector>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const ll INF = 1e18;
const ll mod = 1e9+7;
const double PI = acos(-1);  // PI = 3.141593...

int main() {
    string S;
    cin >> S;
    if (S == "Sunny") {
        cout << "Cloudy" << endl;
    }
    else if(S == "Cloudy") {
        cout << "Rainy" << endl;
    }
    else{
        cout << "Sunny" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
p = 10**9+7
def pow(X,k):
    if k==0:
        return [[1 if i==j else 0 for j in range(N)] for i in range(N)]
    if k==1:
        return X
    if k%2==0:
        Y = pow(X,k//2)
        Z = [[0 for _ in range(N)] for _ in range(N)]
        for i in range(N):
            for j in range(N):
                for m in range(N):
                    Z[i][j] = (Z[i][j]+Y[i][m]*Y[m][j])%p
        return Z
    else:
        Y = pow(X,(k-1)//2)
        Z = [[0 for _ in range(N)] for _ in range(N)]
        for i in range(N):
            for j in range(N):
                for m in range(N):
                    Z[i][j] = (Z[i][j]+Y[i][m]*Y[m][j])%p
        Z1 = [[0 for _ in range(N)] for _ in range(N)]
        for i in range(N):
            for j in range(N):
                for m in range(N):
                    Z1[i][j] = (Z1[i][j]+Z[i][m]*X[m][j])%p
        return Z1
N,K = map(int,input().split())
A = [list(map(int,input().split())) for _ in range(N)]
X = pow(A,K)
cnt = 0
for i in range(N):
    for j in range(N):
        cnt = (cnt+X[i][j])%p
print(int(cnt))

Measured memory_bytes: 46556
def main():
    s = input().replace('BC', 'X')[::-1]
    N = len(s)
    count = 0
    tmp = 0
    for i in range(N):
        if s[i] == 'X':
            tmp += 1
        elif s[i] == 'A':
            count += tmp
        else:
            tmp = 0
    print(count)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3500