akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader
import java.io.InputStream
import java.io.InputStreamReader
import java.io.PrintWriter
import java.util.*

fun PrintWriter.solve(sc: FastScanner) {
    val s = sc.nextLine()
    val r = s.toCharArray().map { it.toString().toInt() }.sum() % 9
    println(if (r == 0) "Yes" else "No")
}

fun main() {
    val writer = PrintWriter(System.out, false)
    writer.solve(FastScanner(System.`in`))
    writer.flush()
}

class FastScanner(s: InputStream) {
    private var st = StringTokenizer("")
    private val br = BufferedReader(InputStreamReader(s))

    fun next(): String {
        while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine())

        return st.nextToken()
    }

    fun nextInt() = next().toInt()
    fun nextLong() = next().toLong()
    fun nextLine() = br.readLine()
    fun nextDouble() = next().toDouble()
    fun ready() = br.ready()
}


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

#define mp make_pair
#define ff first
#define ss second
#define pii pair <int,int>
#define pb push_back
#define debug(x)  cerr << #x << " = " << x << endl
using namespace std ;
typedef long long ll ;
const int mx=100000+5 ;
int h[mx] ;
int dp[mx] ;

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int n,k , x=0;
	cin >> n >> k ;
	for(int i =1 ; i<=n ; i++){
		cin >> h[i] ;
		dp[i] = 1000000000 ;
	}
	dp[1] = 0 ;
	if(k >= n){
		k = n-1 ;
	}
	for(int i =2 ; i<=k ;i++){
		dp[i] = abs(h[1] - h[i]) ;
	}
	for(int i =k+1 ; i <= n ; i++){
		for(int j =i ; j >= i-k ; j--){
			dp[i] = min(dp[i] , dp[j]+abs(h[j]-h[i])) ;
		}
	}
	cout << dp[n] ;
	return 0 ;
}


Measured memory_bytes: 4416
import re
import sys
cadena = list()
lines = sys.stdin.readlines()
for linea in lines:
    c = linea.split()
    c = list(map(str,c))
list(c)
sent_str= str()
for i in c: 
    sent_str += (str(i) + " " )
sent_str = sent_str[:-1] 
textoSoloMayusculas = re.sub('[^A-Z]', '', sent_str)
a = list(textoSoloMayusculas)
a.pop(1)
f = "".join(a)
print(f)

Measured memory_bytes: 3188
import sys
import math
import collections
import bisect
import copy

# import numpy as np

sys.setrecursionlimit(10 ** 7)
INF = 10 ** 16
MOD = 10 ** 9 + 7
# MOD = 998244353

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))
na1 = lambda: list(map(lambda x: int(x) - 1, sys.stdin.readline().split()))


# ===CODE===


def main():
    h, w, k = ns()
    dp = [[0 for _ in range(w)] for __ in range(h + 1)]
    dp[0][0] = 1
    fibo = [1, 2]
    for i in range(10):
        fibo.append(fibo[-1] + fibo[-2])

    for y in range(1, h + 1):
        for x in range(w):
            if x == 0:
                # from U
                dp[y][x] += dp[y - 1][x] * fibo[max(0, w - 1 - 1)]
                if w > 1:
                    # from R
                    dp[y][x] += dp[y - 1][x + 1] * fibo[max(0, w - 1 - 2)]
            elif x == w - 1:
                # from U
                dp[y][x] += dp[y - 1][x] * fibo[max(0, w - 1 - 1)]
                if w > 1:
                    # from L
                    dp[y][x] += dp[y - 1][x - 1] * fibo[max(0, w - 1 - 2)]
            else:
                # from U
                dp[y][x] += dp[y - 1][x] * fibo[x - 1] * fibo[max(0, w - 1 - x - 1)]
                # from L
                dp[y][x] += dp[y - 1][x - 1] * fibo[max(0, x - 1 - 1)] * fibo[max(0, w - 1 - x - 1)]
                # from R
                dp[y][x] += dp[y - 1][x + 1] * fibo[x - 1] * fibo[max(0, w - 1 - x - 2)]
            dp[y][x] %= MOD

    print(dp[h][k - 1])


if __name__ == '__main__':
    main()


Measured memory_bytes: 70320
// tsukasa_diary's programing contest code template
#include <bits/stdc++.h>
using namespace std;
#define TSUKASA_DIARY_S_TEMPLATE
// define
#define for_(i,a,b) for(int i=(a);i<(b);++i)
#define for_rev(i,a,b) for(int i=(a);i>=(b);--i)
#define allof(a) (a).begin(),(a).end()
#define minit(a,b) memset(a,b,sizeof(a))
#define size_of(a) int((a).size())
#define cauto const auto
// typedef
typedef long long lint;
typedef double Double;
typedef pair< int, int > pii;
template< typename T > using Vec = vector< T >;
template< typename T > using Matrix = Vec< Vec< T > >;
template< typename T > using USet = unordered_set< T >;
template< typename T, class C > using MyUSet = unordered_set< T, C >;
template< typename T, typename F > using UMap = unordered_map< T, F >;
template< typename T, typename F, class C > using MyUMap = unordered_map< T, F, C >;
// hash
class PiiHash { public: size_t operator () (const pii& p) const { return (p.first << 16) | p.second; } };
// popcount
inline int POPCNT(int x) { return __builtin_popcount(x); }
inline int POPCNT(lint x) { return __builtin_popcount(x); }
// inf
const int iINF = 1L << 30;
const lint lINF = 1LL << 60;
// eps
const Double EPS = 1e-9;
const Double PI = acos(-1);
// inrange
template< typename T >
inline bool in_range(T v, T mi, T mx) { return mi <= v && v < mx; }
template< typename T >
inline bool in_range(T x, T y, T W, T H) { return in_range(x,0,W) && in_range(y,0,H); }
// neighbor clockwise
const int DX[4] = {0,1,0,-1}, DY[4] = {-1,0,1,0};
const int DX_[8] = {0,1,1,1,0,-1,-1,-1}, DY_[8] = {-1,-1,0,1,1,1,0,-1};
// variable update
template< typename T > inline void modAdd(T& a, T b, T mod) { a = (a + b) % mod; }
template< typename T > inline void minUpdate(T& a, T b) { a = min(a, b); }
template< typename T > inline void maxUpdate(T& a, T b) { a = max(a, b); }
// converter
template< typename F, typename T >
inline void convert(F& from, T& to) {
	stringstream ss;
	ss << from; ss >> to;
}



int main() {
	int N;
	cin >> N;
	Vec< int > L(2*N, 0);
	for_(i,0,2*N) cin >> L[i];
	sort(allof(L));
	int ans = 0;
	for_(i,0,2*N) {
		ans += L[i];
		++i;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<fstream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<math.h>
#include<algorithm>
#include<iomanip>
#include<set>
 
#define P 1000000007
 
using namespace std;
 
int fastpow(int e, int x) {
  if(x == 0) {
    return 1;
  }
  if(x % 2 == 0) {
    return fastpow(e*e, x / 2);
  } else {
    return e * fastpow(e, x - 1);
  }
}
 
int main() {
  int n;
  cin >> n;
  vector<long long> x;
  x.resize(n);
  for(int i = 0; i < n; i++) cin >> x[i];
 
  long long l;
  int q;
  cin >> l >> q;
  vector<pair<int, int>> query;
  query.resize(q);
  for(int i = 0; i < q; i++) {
    cin >> query[i].first >> query[i].second;
    if(query[i].first > query[i].second) {
      int tmp = query[i].first;
      query[i].first = query[i].second;
      query[i].second = tmp;
    }
    query[i].first--;
    query[i].second--;
  }
  vector<vector<long long>> path;
  path.resize(n);
  for(int i = 0; i < n; i++) {
    auto it = upper_bound(x.begin(), x.end(), x[i] + l);
    if(it - x.begin() == i) {
      path[i].push_back(i);
      continue;
    }
    it--;
    path[i].push_back(it - x.begin());
  }
  int cnt = 0;
  for(int k = 1; k < n; k *= 2) {
    for(int i = 0 ; i < n; i++) {
      path[i].push_back(path[path[i][cnt]][cnt]);
    }
    cnt++;
  }

  for(int i = 0; i < q; i++) {
    long long ans = 0;
    int now = query[i].first;
    while(true) {
      if(now >= query[i].second) break;
      auto p = lower_bound(path[now].begin(), path[now].end(), query[i].second);
      if(p == path[now].begin()) {
        ans++;
        break;
      }
      p--;
      ans += fastpow(2, p - path[now].begin());
      now = *p;
    }
    cout << ans << endl;
  }
 
  return 0;
}

Measured memory_bytes: 32128
N = int(input())
A = list(map(int, input().split()))
b1 = 0
for i, a in enumerate(A):
    if i % 2 == 0:
        b1 += a
    else:
        b1 -= a

B = [0 for _ in range(N)]
B[0] = b1
for i in range(N - 1, 0, -1):
    if i == N - 1:
        B[i] = 2 * A[i] - B[0]
    else:
        B[i] = 2 * A[i] - B[i + 1]

print(*B)


Measured memory_bytes: 65636
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int N;cin>>N;
    vector<int>vec(N);
    int count=0;
    int m=0;
    for(int i=0;i<N;i++){
        cin>>vec[i];
        if(m<=vec[i]){
            m=vec[i];
            count++;
        }
    }
    cout<<count<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>	
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define ld long double
#define pii pair <int, int>
#define sz(a) (int)(a.size()) 
#define resize(v) v.resize(unique(all(v)) - v.begin()); 
#define all(a) a.begin(), a.end()
#define forit(it, s) for(__typeof(s.begin()) it = s.begin(); it != s.end(); it ++)

// random_device rd; mt19937 g(rd());    
                                        	
using namespace std;
using namespace __gnu_pbds;
 
void Fast_Read_Out()
{
    ios_base::sync_with_stdio(0);
    cin.tie(), cout.tie();
}
 
void Random()
{
    unsigned int seed;                                                                        
    asm("rdtsc" : "=A" (seed));
    srand(seed);        
}
 
unsigned int Time()
{
     unsigned int time = clock() / 1000.00;                           
     return time;
}

template<typename T> using ordered_set = tree <T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; 
 
const int mod = (int)1e9 + 7;
const int N = (int)1e5 + 132;
 
int n, m;
int d[N], x[N], y[N], z[N];
int ans;
int p[N];
bool used[N];
vector <int> g[N];

int Get(int v)
{
	if(p[v] == v) return v;
	return p[v] = Get(p[v]);
}

void Merge(int x, int y)
{
	x = Get(x), y = Get(y);
	if(x == y) return;
	p[x] = y;
}

void dfs(int v)
{
	used[v] = 1;
	for(auto to : g[v])
		if(!used[to])
			dfs(to);
}

int main ()
{
	#ifdef JUDGE
		freopen("input.txt", "r", stdin);
	#endif		
	Fast_Read_Out();
	Random();   
	cin >> n >> m;
	for(int i = 1; i <= n; i++) p[i] = i;
	for(int i = 1; i <= m; i++)
	{
		cin >> x[i] >> y[i] >> z[i];    
		g[x[i]].pb(y[i]);
		g[y[i]].pb(x[i]);
		Merge(x[i], y[i]);
	}
	for(int i = 1; i <= n; i++)
		if(!used[i])
		{
			ans++;
			dfs(i);
		}
	cout << ans;
}                                

Measured memory_bytes: 10624
st = input()

l = st.split()
h1, m1, h2, m2, k = int(l[0]), int(l[1]), int(l[2]), int(l[3]), int(l[4])

time1 = h1*60 + m1
time2 = h2*60 + m2

print(time2-time1-k)


Measured memory_bytes: 9176
#include<stdio.h>

int main() {
  int a,b,mix;
     scanf("%d %d",&a,&b);

     mix = a + b;  
  
  if( mix%3 == 0 || a%3==0 || b%3==0){
    printf("Possible");
  }else{
    printf("Impossible");
  }

}


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

int main() {
    int n;
    cin >> n;
    string a[n+10];
    vector<int>b(n);
    rep(i,n){
        cin >> a[i];
    }
    sort(a, a+n);
    int j = 0;
    int cnt = 0;
    int maxi = 0;
    rep(i, n){
        if(a[i] == a[i+1]){
            cnt++;
            maxi = max(maxi, cnt); }
        if(a[i] != a[i+1]){cnt = 0;}
    }
    cnt = 0;
    rep(i, n){
        if(a[i] == a[i+1]){
            cnt++;
            if (cnt == maxi){
                cout << a[i] << endl;
            }
            }
        if(a[i] != a[i+1]){j++, cnt = 0;}
    }
    if(maxi == 0){
        rep(i, n){
            cout << a[i] << endl; 
    }   
    }
}

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

#define int long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define uniqueV(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define dbg(x) cerr << #x << ": " << x << endl;
#define dbg2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define dbg3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define dbgB(value, size) cerr<<#value<<": "<<bitset<size>(value) << endl;
#define line() cerr << "---------------" << endl;

const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, -1, 1};
const double PI = 3.14159265358979323846;

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

template<typename T>
void print1(T begin, T end) {
  while (begin != end) {
    cout << (*begin) << " ";
    *begin++;
  }
  cout << endl;
}

template<typename T>
void print2(T Array, int height, int width) {
  for (int i = 0; i < height; i++) {
    for (int j = 0; j < width; j++) {
      cout << " " << Array[i][j];
    }
    cout << endl;
  }
}

void print() { std::cerr << endl; }
template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
  std::cerr << head << " ";
  print(std::forward<Tail>(tail)...);
}

template<class T>
void Add(T &a, const T &b, const T &mod=1000000007) {
  int val = ((a % mod) + (b % mod)) % mod;
  if (val < 0) { val += mod; }
  a = val;
}

template <typename X, typename T> auto vectors(X x, T a) { return vector<T>(x, a); }
template <typename X, typename Y, typename Z, typename... Zs> auto vectors(X x, Y y, Z z, Zs... zs) { auto cont = vectors(y, z, zs...); return vector<decltype(cont)>(x, cont); }

// ------------------------------------------------------------------------------------------

int a[10];

int solve() {
  int ret = 0;

  repp (i, 0, 4) {
    int val = a[i];
    ret += a[i];
    while (1) {
      if (val % 10 == 0) break;
      val++;
    }
    // dbg(a[i] + val - a[i])
    ret += val - a[i];
  }

  ret += a[4];

  return ret;
}

signed main() {
  rep (i, 5) {
    cin >> a[i];
  }

  sort(a, a+5);

  int ans = 1e18;
  do {
    int t = solve();
    // print1(a, a+5);
    // dbg(t)
    // line()
    chmin(ans, t);
  } while (next_permutation(a, a+5));


  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
from collections import deque

s=input()
q=int(input())

R=True
ans=deque(list(s))
count=0
for i in range(q):
    l=list(map(str,input().split()))
    if int(l[0])==1:
        if R:
            R=False
        else:
            R=True
        count+=1
    else:
        f,c=int(l[1]),l[2]
        if f==1 and R:
            ans.appendleft(c)
        elif f==2 and R:
            ans.append(c)
        elif f==1 and (not R):
            ans.append(c)
        elif f==2 and (not R):
            ans.appendleft(c)

if count%2==0:
    print(''.join(ans))
else:
    print(''.join(reversed(ans)))

Measured memory_bytes: 8932
li1 = []
li2 = []
for i, s in enumerate(input()):
    if s == "\\":
        li1.append(i)
    elif s == "/" and li1:
        j = li1.pop()
        c = i - j
        while li2 and li2[-1][0] > j:
            c += li2[-1][1]
            li2.pop()
        li2.append((j, c))
if li2:
    li3 = list(zip(*li2))[1]
    print(sum(li3))
    print(len(li3), *li3)
else:
    print(0, 0, sep="\n")



Measured memory_bytes: 6496
pos=[0]*(200005)
ind=0
for i in range(int(input())):
	x=int(input())
	if x!=pos[ind]:
		ind+=1
		pos[ind]=x
ans=[0]*(ind+1)
per=[0]*200005
ans[0]=1
for i in range(1,ind+1):
	per[pos[i]]=(per[pos[i]]+ans[i-1])%1000000007
	ans[i]=per[pos[i]]
print(ans[i])

Measured memory_bytes: 20340
while True:
    x=int(input())
    y=1000-x
    a=0
    b=0
    a+=y//500
    b=y%500
    a+=b//100
    b=b%100
    a+=b//50
    b=b%50
    a+=b//10
    b=b%10
    a+=b//5
    b=b%5
    a+=b//1
    if x==0:
        break
    print(int(a))


Measured memory_bytes: 5588
#include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <string>
#include <map>
#include <algorithm>
using namespace std;


int main()
{
	int x, a;
	cin >> x >> a;

	if(x < a)
		cout << 0 << endl;
	else
		cout << 10 << endl;

	return 0;
}

Measured memory_bytes: 256
A, B, C = map(int, input().split())

if (A == B) & (A != C):
    ans = 'Yes'
elif (B == C) & (B != A):
    ans = 'Yes'
elif (C == A) & (C != B):
    ans = 'Yes'
else:
    ans = 'No'

print(ans)

Measured memory_bytes: 3060
from collections import deque

n, x, y = map(int, input().split())
dist = [[i - 1, i + 1] for i in range(n)]
dist[0].pop(0)
dist[-1].pop()
dist[x - 1].append(y - 1)
dist[y - 1].append(x - 1)
list = [0] * n

def line(num):
    pos = deque([[num, 0]])
    dp = [-1] * n

    while len(pos) > 0:
        now, depth = pos.popleft()
        dp[num] = 0
        for i in dist[now]:
            if dp[i] > 0:
                continue
            dp[i] = depth + 1
            pos.append([i, depth + 1])
    for i in dp:
        list[i] += 1
for i in range(n):
    line(i)
for i in range(1, n):
    print(int(list[i] / 2))

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

int main(){
  int n,x;
  cin>>n>>x;
  vector<int>m(n);
  rep(i,n) cin>>m[i];
  
  sort(m.begin(),m.end());
  
  int cnt=0;
  rep(i,n){
    if(x-m[i]>=0){
    x-=m[i];
    cnt++;
  }else break;
  }
  while(x-m[0]>=0){
    cnt++;
    x-=m[0];
  }
  
  cout<<cnt<<endl;
  return 0;
}

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

using namespace std;
#define PB push_back
#define MP make_pair
#define LL long long
#define int LL
#define FOR(i,a,b) for(int i = (a); i <= (b); i++)
#define RE(i,n) FOR(i,1,n)
#define REP(i,n) FOR(i,0,(int)(n)-1)
#define R(i,n) REP(i,n)
#define VI vector<int>
#define PII pair<int,int>
#define LD long double
#define FI first
#define SE second
#define st FI
#define nd SE
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())

template<class C> void mini(C& _a4, C _b4) { _a4 = min(_a4, _b4); }
template<class C> void maxi(C& _a4, C _b4) { _a4 = max(_a4, _b4); }

template<class TH> void _dbg(const char *sdbg, TH h){ cerr<<sdbg<<'='<<h<<endl; }
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
  while(*sdbg!=',')cerr<<*sdbg++;cerr<<'='<<h<<','; _dbg(sdbg+1, a...);
}

template<class T> ostream& operator<<(ostream& os, vector<T> V) {
  os << "["; for (auto& vv : V) os << vv << ","; os << "]";
  return os;
}

#ifdef LOCAL
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define debug(...) (__VA_ARGS__)
#define cerr if(0)cout
#endif

#define MAX 100010
int n;
int t[MAX];
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout << fixed << setprecision(11);
  cerr << fixed << setprecision(6);
  cin >> n;
  R(i,n){
    cin >> t[i];
  }
  sort(t,t+n);
  t[n] = 1e15;
  int pom = t[0] & 1;
  int i = 0;
  while(pom < n){
    pom += 2;
    while(t[i] + i < pom) i++;
    if((t[i] + i + pom) & 1)pom++;
  }
  cout << (pom == n ? "Second" : "First") << "\n";
}


Measured memory_bytes: 1024
#include <cstring>
#include <map>
#include <unordered_map>
#include <string>
#include <list>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <cstdio>
#include <iostream>
#include <set>
#include <unordered_set>
using namespace std;

#define MAX(a,b) (a>b?a:b)
#define MIN(a,b) (a<b?a:b)
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef pair<int, int> pii;

int gi() {
    int a;
    scanf("%d", &a);
    return a;
}

ll gli() {
    ll a;
    scanf("%lld", &a);
    return a;
}

int a[200000];

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n = gi();
    ll sum = 0;
    for (int i = 0; i < n; i++) {
        a[i] = gi();
        sum += a[i];
    }

    ll s1 = 0;
    ll res = sum;
    for (int i = 0; i < n; i++) {
        ll s2 = sum - a[i] - s1;
        ll alt = s1-s2+a[i];
        if (alt >= 0)
            res = MIN(res, alt);
        alt = s2-s1+a[i];
        if (alt >= 0)
            res = MIN(res, alt);
        s1 += a[i];
    }

    cout << res << endl;

    return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<vector>
#include<cmath>
#define mem0(x) memset(x,0,sizeof(x))
#define memff(x) memset(x,0xff,sizeof(x))
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repp(i,a,b) for(int i=a;i<=b;i++)
#define per(i,b,a) for(int i=b;i>a;i--)
#define perr(i,b,a) for(int i=b;i>=a;i--)
#define MAX_N 5050
#define MAX_M 5050
#define MAX_P 1000010
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int,int> P;
map<int,int> m;
const int INF=1<<29;
const int MOD=1e9+7;
int par[MAX_N];
int rank[MAX_N];
int dx[4]={-1,0,1,0};
int dy[4]={0,-1,0,1};
int GCD(int a,int b){if(b==0) return a;return GCD(b,b%a);}
void init(int n){rep(i,0,n){par[i]=i;rank[i]=0;}}
int find(int x){return x==par[x]?x:par[x]=find(par[x]);}
void unite(int x,int y){x=find(x);y=find(y);if(x==y) return;if(rank[x]<rank[y]){par[x]=y;}else{par[y]=x;if(rank[x]==rank[y])rank[x]++;}}
bool same(int x,int y){return find(x)==find(y);}
struct node{int x,y;};
bool cmp(int x,int y){return x>y;}
bool ccmp(node x1,node x2){return x1.x>x2.x;}
LL mod_pow(LL x, LL n,LL mod){LL res=0;while(n>0){if(n&1) res=res*x%mod;x=x*x%mod;n>>=1;}return res;}
int prime[MAX_P];
bool is_prime[MAX_P];
int x;
int sieve(int  n)
{
    int p=0;
    repp(i,0,n)
    {
        is_prime[i]=true;
    }
    is_prime[0]=is_prime[1]=false;
    repp(i,2,n)
    {
        if(is_prime[i])
        {
            prime[p++]=i;
            for(int j=2*i;j<=n;j+=i)
            is_prime[j]=false;
        }
    }
    return p;
}
int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    while(~scanf("%d",&x))
    {
        printf("%d\n",sieve(x));
    }
    return 0;
}

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

constexpr int mod = 1e9 + 7;

int dp[301][301][301];

struct segment {
    int l, x;
    segment(int l_, int x_) : l(l_), x(x_) {}
};

int main() {
    int n, m; cin >> n >> m;
    vector<vector<segment>> seg(n + 1);
    for(int i = 0; i < m; ++i) {
        int l, r, x; cin >> l >> r >> x;
        seg[r].emplace_back(l, x);
    }

    //vector<vector<vector<int>>> dp(n + 1, vector<vector<int>>(n + 1, vector<int>(n + 1)));
    dp[0][0][0] = 1;
    for(int rp = 0; rp < n; ++rp) {
        for(int i = 0; i <= rp; ++i) {
            for(int j = i; j <= rp; ++j) {
                array<int, 3> max_v = {{0, 0, rp + 1}}, cur = {{i, j, rp}};
                do {
                    do {
                        array<int, 3> nxt;
                        for(int k = 0; k < 3; ++k) {
                            nxt[k] = max(cur[k], max_v[k]);
                        }
                        (dp[nxt[0]][nxt[1]][nxt[2]] += dp[cur[0]][cur[1]][cur[2]]) %= mod;
                    } while(next_permutation(max_v.begin(), max_v.end()));
                } while(next_permutation(cur.begin(), cur.end()));
            }
        }
        const int r = rp + 1;
        for(auto const& s : seg[r]) {
            const int l = s.l;
            if(s.x == 1) {
                for(int i = 0; i < r; ++i) {
                    for(int j = l; j < r; ++j) {
                        dp[i][j][r] = dp[i][r][j] = dp[r][i][j] = 0;
                        dp[j][i][r] = dp[j][r][i] = dp[r][j][i] = 0;
                    }
                }
            } else if(s.x == 2) {
                for(int i = 0; i < l; ++i) {
                    for(int j = 0; j < l; ++j) {
                        dp[i][j][r] = dp[i][r][j] = dp[r][i][j] = 0;
                    }
                }
                for(int i = l; i < r; ++i) {
                    for(int j = l; j < r; ++j) {
                        dp[i][j][r] = dp[i][r][j] = dp[r][i][j] = 0;
                    }
                }
            } else if(s.x == 3) {
                for(int i = 0; i < l; ++i) {
                    for(int j = 0; j < r; ++j) {
                        dp[i][j][r] = dp[i][r][j] = dp[r][i][j] = 0;
                        dp[j][i][r] = dp[j][r][i] = dp[r][j][i] = 0;
                    }
                }
            }
        }
    }

    int ans = 0;
    for(int i = 0; i < n; ++i) {
        for(int j = i; j < n; ++j) {
            vector<int> idx = {i, j, n};
            do {
                (ans += dp[idx[0]][idx[1]][idx[2]]) %= mod;
            } while(next_permutation(idx.begin(), idx.end()));
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 106880
import sys
def vanish_on_left(i, n, s, tds):
    for t, d in tds:
        if s[i] != t:
            continue
        if d == 'L':
            if i == 0:
                return True
            i -= 1
        else:
            if i == n-1:
                return False
            i += 1
    return False

def vanish_on_right(i, n, s, tds):
    for t, d in tds:
        if s[i] != t:
            continue
        if d == 'L':
            if i == 0:
                return False 
            i -= 1
        else:
            if i == n-1:
                return True
            i += 1
    return False


n, q = map(int, input().split())
s = input()
tds = []
for _ in range(q):
    tds.append(tuple(input().split()))
if vanish_on_left(0, n, s, tds):
    if vanish_on_left(n-1, n, s, tds):
        print(0)
        sys.exit()
    l0, r0 = 1, n-1
    while l0 < r0:
        k = (l0 + r0) // 2
        if vanish_on_left(k, n, s, tds):
            l0 = k+1
        else:
            r0 = k
else:
    l0 = 0
if vanish_on_right(n-1, n, s, tds):
    if vanish_on_right(l0, n, s, tds):
        print(0)
        sys.exit()
    l1, r1 = l0, n-2
    while l1 < r1:
        k = (l1 + r1 + 1) // 2
        if vanish_on_right(k, n, s, tds):
            r1 = k-1
        else:
            l1 = k
else:
    l1 = n-1
print(l1 - l0 + 1)

Measured memory_bytes: 17840
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using vc = vector<char>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using stkll = vector<pll>;
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
#define rep(i, n) for (ll i = 0; i < (n); i++)
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
#ifndef ONLINE_JUDGE
    #define debug(x) cerr << #x << ": " << x << endl;
#else
    #define debug(x)
#endif

vll dp(220000, INF), ans(220000, 0), a(220000);
vvll g(220000);

void dfs(ll k, ll p = -1) {
    ll idx = lower_bound(dp.begin(), dp.end(), a[k]) - dp.begin();
    ll last = dp[idx];
    dp[idx] = a[k];
    ans[k] = lower_bound(dp.begin(), dp.end(), INF) - dp.begin();

    for(auto nv : g[k]) {
        if(nv == p) continue;
        dfs(nv, k);
    }
    dp[idx] = last;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    ll n;
    cin >> n;
    rep(i, n) cin >> a[i];
    rep(i, n-1) {
        ll x, y;
        cin >> x >> y;
        x--, y--;
        g[x].push_back(y);
        g[y].push_back(x);
    }

    dfs(0);
    rep(i, n) cout << ans[i] << endl;
}


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

int main(){
    int n;
    cin >> n;
    vector<int> a(n+1);
    for(int i = 1; i <= n; i++) cin >> a[i];
    
    int m = 0;
    vector<int> b(n+1, 0);
    for(int i = n; i >= 1; i--){
        int cnt = 0;
        int j = 2*i;
        for(int k = 3; j <= n; k++){
            cnt += b[j];
            j = i*k;
        }
        cnt %= 2;
        b[i] = cnt ^ a[i];
        if(b[i]) m++;
    }

    cout << m << endl;
    for(int i = 1; i <= n; i++){
        if(b[i] == 1) cout << i << ' ';
    }
}

Measured memory_bytes: 2432
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define REP(i,b) FOR(i,0,b)
#define MP make_pair
#define PB push_back

using ll=long long;
using pii=pair<int,int>;
using vi=vector<int>;

int read(){
	int i;
	scanf("%d",&i);
	return i;
}

pii f[19];

int main(){
	int n=read(),m=read(),k=read();
	REP(i,n)f[i].first=read();
	REP(i,n)f[i].second=read();
	sort(f,f+n,greater<pii>());
	int ans=0;
	FOR(bits,1,(1<<n)){
		int rem=m,s=0,w=0;
		REP(i,n)if((bits>>i)&1){
			if((++s)>k)
				break;
			int u=min(rem,f[i].second);
			w+=f[i].first*u;
			rem-=u;
		}
		ans=max(ans,w+rem);
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 3224
#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  int t = 0;
  
  cin >> s;
	
  for(char& c : s) {
    if (c == '1')
      t += 1;
    else
      t -= 1;
  }
  
  cout << s.size() - abs(t) << endl;
  
  return 0;
 }


Measured memory_bytes: 512
#include <cstdio>

typedef long long ll;
ll max(ll a,ll b){return a>b?a:b;}

int main()
{
    ll a,b,c,d;
    scanf("%lld%lld%lld%lld",&a,&b,&c,&d);
    printf("%lld\n",max(max(a*d,a*c),max(b*c,b*d)));
    return 0;
}

Measured memory_bytes: 1732
//i think this problem is not solvable and too lazy to understand solution
//so i make a copy......
#include<bits/stdc++.h>
using namespace std;
long double N, d1, x, ans;
int main() {
    cin >> N >> d1 >> x;
    for(int i = N; i >= 1; i--) {
        long double s = d1 * 2 * N + N * (2 * N - 1) * x;
        ans += s / 2 / N;
        s = s - (4 * d1 + 4 * N * x - 2 * x)  / 2 / N;
        d1 = ((2 * N - 2) * d1 + d1 + 2 * x + 3 * d1 + 3 * x) / 2 / N;
        N--;
        x = (s - 2 * N * d1) / N / (2 * N - 1);
    }
    printf("%.15lf", (double)ans);
    return 0;
}

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

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define rep2(i, a, b) for (ll i = (a); i < (b); i++)
#define chmax(x, v) do { x = max(x, v); } while (0)
#define chmin(x, v) do { x = min(x, v); } while (0)
typedef uint64_t ull;
typedef int64_t ll;
typedef std::pair<ll, ll> PLL;

using namespace std;

ll N, M;
const ll INF = 1e10;
vector<ll> memo(200000, INF);
vector<vector<ll>> edges(200000);

ll f(ll i) {
  if (memo[i] != INF)
    return memo[i];
  if (edges[i].size() == 0)
    return 0;
  ll res = -1;
  for (auto nxt : edges[i]) {
    chmax(res, f(nxt) + 1);
  }
  return memo[i] = res;
}

signed main() {
  cin >> N >> M;
  rep(i, M) {
    ll x, y;
    cin >> x >> y;
    x--; y--;
    edges[x].push_back(y);
  }
  ll ans = 0;
  rep(i, N) {
    chmax(ans, f(i));
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 11648
#include <bits/stdc++.h>
#define int long long int
#define gif(a,b) (a/b +(a%b?1:0))
#define pi 3.14159265358
#define watch(x) cout<<(#x)<<" is "<<(x)<<"\n";
#define float long double
using namespace std;

int32_t main()
{   
    cin.tie(NULL);
    std::ios::sync_with_stdio(false);
  	int y , m , d;
  	cin >> y >> m;
  	if( m%y == 0)
  		cout << y+m;
  	else
  		cout << m - y;
    return 0;
}


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

int main() {
    int n,g=0;
    cin >> n;
    string a,b,c;
    cin >> a >> b >> c;
    for (int i=0;i<n;i++) {
        set<int> s;
        s.insert(a[i]);
        s.insert(b[i]);
        s.insert(c[i]);
        g += s.size()-1;
    }
    cout << g << endl;
    return 0;
}

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

int main()
{
    string b;
    cin>>b;
    vector<char>v;
    for(int i=0; i<b.size(); i++)
    {
        if(b[i]=='0' || b[i]=='1')
        {
            v.push_back(b[i]);
        }
        else if(b[i]=='B')
        {
            if(v.size()!=0)
            {
                v.erase(v.begin()+v.size()-1);
            }
        }
    }
    for(int i=0; i<v.size(); i++)
    {
        cout<<v[i];
    }
    cout<<endl;
}


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

int main(){
  int n, m;
  cin >> n;
  vector<string> s(n); 
  vector<int> result(n, 1);
  
  for (int i = 0; i < n; i++){
    cin >> s.at(i);
  }
  
  cin >> m;
  vector<string> t(m);
  
  for (int i = 0; i < m; i++){
    cin >> t.at(i);
  }
  
  for (int i = 0; i < n; i++){
    for (int j = i+1; j < n; j++){
      if (s.at(i) == s.at(j))
        result.at(i)++;
    }
  }
  
  for (int i = 0; i < n; i++){
    for (int j = 0; j < m; j++){
      if (s.at(i) == t.at(j))
        result.at(i)--;
    }
  }
  
  sort(result.begin(), result.end());
  reverse(result.begin(), result.end());
  
  if (result.at(0) > 0)
    cout << result.at(0) << endl;
  else
    cout << 0 << endl;
}
  
  

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

int main() {
   string s, t; cin >> s >> t;
   int ans = 0;
   for (int i = 0; i < 3; i++) {
   if (s[i] == t[i]) ans++;
   }
   cout << ans << endl;
}


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

#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)

int main() {
    int n;cin>>n;
    int a[n];
    rep(i,n)cin>>a[i];
    sort(a,a+n);
    int ans = a[n-1]-a[0];

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a) for (int i = (int)0; i < (int)a; ++i)
#define rrep(i, a) for (int i = (int)a - 1; i >= 0; --i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define RREP(i, a, b) for (int i = (int)a - 1; i >= b; --i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define popcount __builtin_popcount
using ll = long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;

template <class T>
inline bool chmin(T &a, T b)
{
	if (a > b)
	{
		a = b;
		return true;
	}
	return false;
}
template <class T>
inline bool chmax(T &a, T b)
{
	if (a < b)
	{
		a = b;
		return true;
	}
	return false;
}

ll gcd(ll n, ll m)
{
	ll tmp;
	while (m != 0)
	{
		tmp = n % m;
		n = m;
		m = tmp;
	}
	return n;
}

ll lcm(ll n, ll m)
{
	return abs(n) / gcd(n, m) * abs(m); //gl=xy
}

using namespace std;

#define int ll
void solve()
{
	ll n,k;
	cin>>n>>k;
	vector<ll>p(n),c(n);
	rep(i,n){
		cin>>p[i];
		p[i]--;
	}
	rep(i,n)cin>>c[i];
	ll ans=-INF;
	rep(i,n){
		int cnt=k;
		ll res=0;
		vector<bool>used(n);
		int s=i;
		int nx=s;
		int loop=1;
		vector<ll>v(n),res_v(n);
		ll val=0;
		while(cnt>0){
			nx=p[nx];
			--cnt;
			if(used[nx]){
				loop=v[nx]-cnt;
				val=res-res_v[nx];
				++cnt;//移動回数として消費されない
				break;
			}
			res+=c[nx];
			chmax(ans,res);
			v[nx]=cnt;
			used[nx]=true;
		}
		if(val>0&&cnt>0){
			if(cnt/loop>=1)res+=(cnt/loop-1)*val,cnt=cnt%loop+loop;
			else res+=cnt/loop*val,cnt=cnt%loop;
			int pos=0;
			chmax(ans,res);
			while(cnt>0&&pos<=2*(loop+1)){
				++pos;
				res+=c[nx];
				chmax(ans,res);
				nx=p[nx];
				--cnt;
			}
		}
		else{
			int pos=0;
			while(cnt>0&&pos<=loop+1){
				++pos;
				res+=c[nx];
				chmax(ans,res);
				nx=p[nx];
				--cnt;
			}
		}
	}
	cout<<ans;
}
#undef int
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(15);
	solve();
	return 0;
}


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

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
        }

        public void Solve(ConsoleInput cin)
        {

            var a = cin.ReadInt;
            var b = cin.ReadInt;
            if (a * b % 2 == 0)
            {
                Console.WriteLine("Even");
            }
            else {
                Console.WriteLine("Odd");
            }
        }
    }

    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); } }
        public int ReadInt { get { return int.Parse(Read); } }
        public long ReadLong { get { return long.Parse(Read); } }
        public double ReadDouble { get { return double.Parse(Read); } }
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
    }
}




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

int k, x;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);
	cin >> k >> x;
	for(int i = x - k + 1; i <= x + k - 1; ++i) {
		cout << i << " ";
	}
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#define ll long long
const ll mod=1e9+7;
ll dp[2005]={0},n;
int main()
{
	scanf("%lld",&n);
	dp[0]=1;
	dp[1]=0;
	dp[2]=0;
	for(ll i=3;i<=n;i++)
	{
		for(ll j=3;i-j>=0;j++)
		{
			dp[i]+=dp[i-j];
			dp[i]%=mod;
		}
//	printf("%lld\n",dp[i]);
		
	}
	printf("%lld\n",dp[n]);
 } 

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

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

  int ans=0;
  for(int i=s.size()-2; i>0; i--){
    if((i+1)%2==1)continue;
    if(s.substr(0, (i+1)/2) == s.substr((i+1)/2, (i+1)/2)){
      ans=(i+1);
      break;
    }
  }

  cout<<ans<<endl;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline


n, d = map(int, input().split())

dd = d ** 2

cnt = 0
for i in range(n):
    x, y = map(int, input().split())
    x = abs(x)
    y = abs(y)
    if x > d or y >d:
        pass
    else:
        xx = x **2
        yy = y **2
        if dd >= xx + yy:
            cnt+=1
        else:
            pass
print(cnt)


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

int main(){
  int n;
  cin >> n;
  int res = 0;
  for(int i = 1; i<n; i++){
    if(n%i == 0) res += n/i-1;
    else res += n/i;
  }
  cout << res << endl;
}

Measured memory_bytes: 3636
//g++ t.cpp -o t && t < p.txt
//d>p.txt&&t<p.txt&&t2<p.txt

#include <iostream> // プログラムの耳と口
#include <vector> // 超有能配列秘書
#include <algorithm> // みんな大好きソートと二分探索
#include <queue> // きゅーちゃん、だいすき
#include <string> // to_string
#include <functional> // 関数を変数に入れる子
#include <set> // 値の取得・挿入・削除を高速に
#include <map> // setの妹 これまた優秀
#include <random> // 乱択さん
#include <ctime>
#include <bitset>

#define DB cerr<<"D"<<endl
using namespace std; using ll=long long; using ld=long double; const int INF=1e9; const ll LINF=1e18; const double dINF = 1e18; const ld ldINF = 1e18; const double EPS = 1e-6;
template<typename T, typename U, typename O> void caut(T a, U b, O c){cout<<"("<<a<<","<<b<<","<<c<<") ";} template<typename T, typename U> void caut(T a, U b){cout<<"("<<a<<","<<b<<") ";} template<typename T> void caut(T a){cout<<"("<<a<<") ";};
using P=pair<ll,ll>;
const ll M = 1e9+7;
ll mod_pow(ll x, ll a) { ll an = 1; while(a > 0) { if (a&1) an = an * x % M; x = x * x % M; a >>= 1;} return an;}
void add(ll& x, ll y) {x+=y; x%=M;}; void mul(ll& x, ll y) {x*=y; x%=M;}; template<typename T, typename U> void chmax(T& x, U y) {if (x<y) x=y;}; template<typename T, typename U> void chmin(T& x, U y) {if (x>y) x=y;}
bool vaild(int x, int y, int hh, int ww){return 0<=x&&x<hh&&0<=y&&y<ww;}
int keta(ll a) {int res=0; while(a>0) res+=a%10, a/=10; return res;}
const int up[]={1,-1,0,0}, lf[]={0,0,1,-1};
ll gcd(ll a, ll b) {if (b==0) return a; else return gcd(b, a%b);}

int main() {
  ll a,b,c,d; cin>>a>>b>>c>>d;
  ll an=a*c;
  chmax(an,a*d);
  chmax(an,b*c);
  chmax(an,b*d);
  cout<<an<<endl;
}
// ・配列の大きさok？　・priority_queueはgreater？　・debug消した？
// ・落ち着いて。提出まで4分待ってね……WJ……1/10……2/10……

// Thank you for making problems and running the contest


Measured memory_bytes: 3632
#include <iostream>
using namespace std;
#define ll long long
#define all(x) x.begin(),x.end()

int const N = 200001;

int main(){
    int a,b,c,k;
    scanf("%d%d%d%d", &a, &b, &c, &k);
    int o = min(k, a);
    k -= o; 
    int an = o;
    o = min(k, b);
    k -= o;
    o = min(c, k);
    k -= o; 
    an -= o;
    cout << an << "\n";
}


Measured memory_bytes: 3768
import math

def count_uneven_digit(N):
    n_digits = int(math.log10(N) + 1)
    
    diffs = 0
    if n_digits%2 != 0:
        diffs = 9*10**(n_digits-1) - N + 10**(n_digits - 1) - 1
    
    num_uneven_digitnums = [9*10**i for i in range(n_digits) if i % 2 == 0]
    return sum(num_uneven_digitnums) - diffs
  
  
N = int(input())

print(count_uneven_digit(N))

Measured memory_bytes: 3060
n,m = gets.split(" ").map{|e| e.to_i}
array = []
n.times do
  array << gets.split(" ").map{|e| e.to_i}
end

array.sort_by!{|a| a[0]}
sum = 0
loop do
  if m > array[0][1]
    sum += array[0][0]*array[0][1]
    m -= array[0][1]
    array.shift
  else
    sum += array[0][0]*m
    break
  end
end

puts sum

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

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

#define endl '\n'
#define int long long

const int N = 305;

int n;
int a[N], f[N];
bool vis[N][N][N];
double cache[N][N][N];

double dp(int a, int b, int c) {
	if(a < 0 || b < 0 || c < 0)
		return 0;
	if(a == 0 && b == 0 && c == 0) 
		return 0;
	double &ans = cache[a][b][c];
	if(vis[a][b][c]) 
		return ans;
	vis[a][b][c] = 1;
	ans = n + a * dp(a-1, b, c) + b * dp(a+1, b-1, c) + c * dp(a, b+1, c-1);
	ans /= (a + b + c);
	return ans;
}

int32_t main()
{
	IOS;

	cin >> n;
	for(int i = 1; i <= n; i ++)
		cin >> a[i], f[a[i]]++;
	double ans = dp(f[1], f[2], f[3]);
	cout << fixed << setprecision(12) << ans;

	return 0;
}

Measured memory_bytes: 246144
# include <iostream>
#include <string>

using namespace std;

int main() {
	string A, B;

	cin >> A >> B;

	if (A.size() == B.size()) {
		if (A[0] > B[0]) {
			cout << "GREATER" << endl;
		}
		else if (A[0] < B[0]) {
			cout << "LESS" << endl;
		}
		else {
			cout << "EQUAL" << endl;
		}
	}
	else if (A.size() > B.size()) {
		cout << "GREATER" << endl;
	}
	else {
		cout << "LESS" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Main main = new Main();
		main.run();
	}

	void run() {
		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		long A = 1;
		long B = 1;

		for (int i = 0; i < N; i++) {
			int T=sc.nextInt();
			int S=sc.nextInt();

			long n=Math.max((A+T-1)/T,(B+S-1)/S);

			A=n*T;
			B=n*S;


		}

		System.out.println(A+B);


	}

	//以下テンプレート

	public static int[] extgcd(int a, int b) {

		int x0 = 1;
		int x1 = 0;

		int y0 = 0;
		int y1 = 1;

		while (b != 0) {
			int q = a / b;
			int r = a % b;

			int x2 = x0 - q * x1;
			int y2 = y0 - q * y1;

			a = b;
			b = r;

			x0 = x1;
			x1 = x2;

			y0 = y1;
			y1 = y2;
		}

		return new int[] { a, x0, y0 };

	}

	static int gcd(int a, int b) {

		if (b == 0)
			return a;

		if (a < b) {
			int t = a;
			a = b;
			b = t;
		}

		return gcd(b, a % b);

	}

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

	static void swap(int[] a) {
		int t;

		t = a[0];
		a[0] = a[1];
		a[1] = t;

		return;
	}

	static <T> void output(List<T> list) {

		for (int i = 0; i < list.size(); i++) {
			System.out.print(list.get(i));

			if (i != list.size() - 1) {
				System.out.print(" ");
			} else {
				nl();
			}
		}

	}

	static void output(String[][] str) {

		for (int i = 0; i < str.length; i++) {
			for (int j = 0; j < str[i].length; j++) {
				print(str[i][j]);
			}

			nl();
		}

	}

	static void output(boolean flg, String Yes, String No) {

		if (flg) {
			pln(Yes);
		} else {
			pln(No);
		}

	}

	static void output(String[][] str, int digit) {

		String dig = "%" + String.valueOf(digit) + "s";

		for (int i = 0; i < str.length; i++) {
			for (int j = 0; j < str[i].length; j++) {
				System.out.printf(dig, str[i][j]);
			}
			nl();
		}

	}

	static void pln(String str) {
		System.out.println(str);
	}

	static void pln(int x) {
		System.out.println(x);
	}

	static void print(String str) {
		System.out.print(str);
	}

	static void print(int x) {
		System.out.print(x);
	}

	static void print(String str, int times) {
		for (int i = 0; i < times; i++) {
			print(str);
		}
	}

	static void print(int x, int times) {
		for (int i = 0; i < times; i++) {
			print(x);
		}
	}

	static void nl() {
		System.out.println();
	}

}


Measured memory_bytes: 27864
from math import hypot
p = [list(map(int, input().split())) for i in range(3)]
x1 = p[1][0] - p[0][0]
y1 = p[1][1] - p[0][1]
x2 = p[2][0] - p[0][0]
y2 = p[2][1] - p[0][1]
s2 = abs(x1*y2-x2*y1)
s = 0
m = 0
for i in range(3):
    x = p[i-1][0]-p[i][0]
    y = p[i-1][1]-p[i][1]
    l = hypot(x, y)
    s += l
    m = max(m, l)
r = s2/s
x = m*r/(2*r+m)
print(x)

Measured memory_bytes: 3188
#include<iostream>
using namespace std;
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cassert>

typedef double type_n;

struct Point{ type_n x, y; };

Point set_p(type_n a, type_n b)
{
    Point p;
    p.x = a; p.y = b;
    return p;
}

struct Vector{ type_n vx, vy; };

Vector set_v(const Point &p1, const Point &p2)
{
    Vector v;
    v.vx = p2.x - p1.x;
    v.vy = p2.y - p1.y;
    return v;
}

type_n cross(const Vector &V0, const Vector &V1)
{
    return (V0.vx * V1.vy) - (V0.vy * V1.vx);
}

type_n cross0(const Point &P0, const Point &P1)
{
    return (P0.x * P1.y) - (P0.y * P1.x);
}

type_n dist(const Point &p1, const Point &p2)
{
    return sqrt((p1.x - p2.x) * (p1.x - p2.x) + (p1.y - p2.y) * (p1.y - p2.y));
}

inline int sgn(const double x){ if(x != 0){ return (x > 0 ? 1 : -1); } return 0; }

Point intersection(const Point &P0, const Point &P1, const Point &P2, const Point &P3)
{
    // P0P1, P2P3, intersection point.
    Vector V01 = set_v(P0, P1), V23 = set_v(P2, P3);
    type_n Area = cross(V01, V23);
    assert(Area != 0);
    type_n a = cross0(P2, P3) / Area, b = cross0(P0, P1) / Area;
    type_n isx, isy;
    isx = a * (P1.x - P0.x) - b * (P3.x - P2.x);
    isy = a * (P1.y - P0.y) - b * (P3.y - P2.y);
    Point is = set_p(isx, isy);
    return is;
}

int main()
{
    int i, n;
    type_n *X, *Y;

    scanf("%d", &n);
    assert(n >= 3);
    X = new type_n [n + 1];
    Y = new type_n [n + 1];

    for(i = 0; i < n; i++){ scanf("%lf %lf", &X[i], &Y[i]); }
    X[n] = X[0], Y[n] = Y[0];

    int *A;
    A = new int [n + 1];

    Point *P;
    P = new Point [n + 3];  // n + 1, n + 2 is space, for intersection points.

    for(i = 0; i < n; i++){ P[i] = set_p(X[i], Y[i]); }
    P[n] = P[0];

    int q;
    scanf("%d", &q);
    int size; type_n left_sum;
    int *index;
    index = new int [n + 2];

    for(int k = 0; k < q; k++){

        type_n p1, p2, q1, q2;  // cut line.
        scanf("%lf %lf %lf %lf", &p1, &p2, &q1, &q2);
        type_n v1 = q1 - p1, v2 = q2 - p2;

        for(i = 0; i < n; i++){ A[i] = sgn(v1 * (Y[i] - p2) - v2 * (X[i] - p1)); }
        A[n] = A[0];  // is_leftside ? or rightside ?

        size = 0;
        Point Q = set_p(p1, p2), R = set_p(q1, q2);  // edges of line.

        for(i = 0; i < n; i++){
            if(A[i] >= 0){
                index[size] = i;  // uses leftside point.
                size++;
            }
            if(A[i] * A[i + 1] < 0){
                if(A[i] > 0){ index[size] = n + 1; }  // intersection points.
                else{ index[size] = n + 2; }
                P[index[size]] = intersection(P[i], P[i + 1], Q, R);
                size++;
            }
        }

        left_sum = 0;  // propeller integral.
        if(size > 2){
            Vector U = set_v(P[index[0]], P[index[1]]);
            for(i = 2; i < size; i++){
                Vector V = set_v(P[index[0]], P[index[i]]);
                left_sum += 0.5 * cross(U, V);
                U = V;
            }
        }
        printf("%.12f\n", left_sum);
    }

    delete [] X, delete [] Y, delete [] P;

    return 0;
}

Measured memory_bytes: 1252